https://github.com/jmcarp updated 
https://github.com/llvm/llvm-project/pull/176988

>From 0c3f6a528d166d5ebd81fed7ff7ffc2b68f82457 Mon Sep 17 00:00:00 2001
From: Josh Carp <[email protected]>
Date: Wed, 21 Jan 2026 23:19:16 +0000
Subject: [PATCH] [libunwind] Handle PT_SUNW_UNWIND for illumos.

Check both PT_GNU_EH_FRAME and PT_SUNW_UNWIND if the latter is defined.
Illumos uses both headers to access EH data. Note that PT_GNU_EH_FRAME
is aliased to PT_SUNW_EH_FRAME, so we don't need to check
PT_SUNW_EH_FRAME separately.

>From illumos-gate sys/elf.h [1]:

  PT_SUNW_UNWIND and PT_SUNW_EH_FRAME perform the same function,
  providing access to the .eh_frame_hdr section of the object.
  PT_SUNW_UNWIND is the original value, while PT_SUNW_EH_FRAME is
  required by the amd64 psABI. The Solaris link-editor (ld) tags output
  objects with PT_SUNW_UNWIND, but the Solaris runtime linker (ld.so.1)
  will accept and use either value.

  #define PT_SUNW_UNWIND    0x6464e550
  #define PT_SUNW_EH_FRAME  0x6474e550
  #define PT_GNU_EH_FRAME   PT_SUNW_EH_FRAME

This patch makes libunwind also check for PT_SUNW_UNWIND when available,
enabling correct unwinding for binaries linked with either linker.

[1]: 
https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/sys/elf.h#L432-L442
---
 libunwind/src/AddressSpace.hpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 52477b16b355a..7bb85bd6c2abf 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -424,7 +424,13 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, 
size_t image_base,
 static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base,
                                       dl_iterate_cb_data *cbdata) {
 #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
+#if defined(PT_SUNW_UNWIND)
+  // illumos uses both PT_GNU_EH_FRAME and PT_SUNW_UNWIND to access EH state;
+  // check both if PT_SUNW_UNWIND is defined.
+  if (phdr->p_type == PT_GNU_EH_FRAME || phdr->p_type == PT_SUNW_UNWIND) {
+#else
   if (phdr->p_type == PT_GNU_EH_FRAME) {
+#endif
     EHHeaderParser<LocalAddressSpace>::EHHeaderInfo hdrInfo;
     uintptr_t eh_frame_hdr_start = image_base + phdr->p_vaddr;
     cbdata->sects->dwarf_index_section = eh_frame_hdr_start;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to