Skip to content

Conversation

@RossComputerGuy
Copy link
Member

Original implementation comes from reckenrode/nixpkgs@099adee with permission from @reckenrode

This implements the unw_strerror function which the other libunwind implements. Many packages, notable Xorg ones, use the strerror function from libunwind. When trying to link with the LLVM one, this causes a missing symbol error. By implementing this function, we are compatible with the non-LLVM libunwind.

@RossComputerGuy RossComputerGuy requested a review from a team as a code owner February 27, 2025 17:12
@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2025

@llvm/pr-subscribers-libunwind

Author: Tristan Ross (RossComputerGuy)

Changes

Original implementation comes from reckenrode/nixpkgs@099adee with permission from @reckenrode

This implements the unw_strerror function which the other libunwind implements. Many packages, notable Xorg ones, use the strerror function from libunwind. When trying to link with the LLVM one, this causes a missing symbol error. By implementing this function, we are compatible with the non-LLVM libunwind.


Full diff: https://github.com/llvm/llvm-project/pull/129084.diff

2 Files Affected:

  • (modified) libunwind/include/libunwind.h (+2)
  • (modified) libunwind/src/libunwind.cpp (+35)
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h index b2dae8feed9a3..839aa3dcf31c5 100644 --- a/libunwind/include/libunwind.h +++ b/libunwind/include/libunwind.h @@ -131,6 +131,8 @@ extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL; extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL; //extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*); +extern const char *unw_strerror(int) LIBUNWIND_AVAIL; + extern unw_addr_space_t unw_local_addr_space; #ifdef __cplusplus diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index cf39ec5f7dbdf..5bb40ff795bb9 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -260,6 +260,41 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { } _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) +_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) { + switch (error_code) { + case UNW_ESUCCESS: + return "no error"; + case UNW_EUNSPEC: + return "unspecified (general) error"; + case UNW_ENOMEM: + return "out of memory"; + case UNW_EBADREG: + return "bad register number"; + case UNW_EREADONLYREG: + return "attempt to write read-only register"; + case UNW_ESTOPUNWIND: + return "stop unwinding"; + case UNW_EINVALIDIP: + return "invalid IP"; + case UNW_EBADFRAME: + return "bad frame"; + case UNW_EINVAL: + return "unsupported operation or bad value"; + case UNW_EBADVERSION: + return "unwind info has unsupported version"; + case UNW_ENOINFO: + return "no unwind info found"; +#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) + case UNW_ECROSSRASIGNING: + return "cross unwind with return address signing"; +#endif + default: + return "unknown error occurred"; + } +} +} +_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror) + #ifdef _AIX _LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) { _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)", 
@RossComputerGuy RossComputerGuy force-pushed the feat/libunwind-strerror branch 3 times, most recently from 144809d to b976a98 Compare February 27, 2025 17:37
@github-actions
Copy link

github-actions bot commented Feb 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Co-authored-by: Randy Eckenrode <randy@largeandhighquality.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants