[libunwind] [libunwind] Add unw_strerror function (PR #129084)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 09:13:10 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libunwind

Author: Tristan Ross (RossComputerGuy)

<details>
<summary>Changes</summary>

Original implementation comes from https://github.com/reckenrode/nixpkgs/commit/099adeef42048d853df03f181103c6985c356d21 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
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)",

``````````

</details>


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


More information about the cfe-commits mailing list