[libunwind] [libunwind] Fix EH frame handling on illumos. (PR #176988)
Joshua Carp via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 20 10:21:10 PST 2026
https://github.com/jmcarp created https://github.com/llvm/llvm-project/pull/176988
Illumos uses PT_SUNW_EH_FRAME and PT_SUNW_UNWIND program header types instead of PT_GNU_EH_FRAME for exception handling frames. This patch checks if the illumos headers are defined, and checks the appropriate fields in the ELF header if so.
FreeBSD defines PT_SUNW_UNWIND but not PT_SUNW_EH_FRAME for compatibility, so we check for both headers to avoid breaking FreeBSD builds.
Note: this is motivated by a project to [add support for illumos](https://github.com/ClickHouse/ClickHouse/issues/23777) to clickhouse. We initially sent this patch to [clickhouse's fork of llvm](https://github.com/ClickHouse/llvm-project/pull/63), but would like to upstream the change first to prevent clickhouse's fork from further diverging from this repo.
cc @rschu1ze
>From 22a19e6a1d031c17b26a991c111984f916dcec25 Mon Sep 17 00:00:00 2001
From: Josh Carp <jm.carp at gmail.com>
Date: Tue, 20 Jan 2026 18:08:57 +0000
Subject: [PATCH] [libunwind] Fix EH frame handling on illumos.
Illumos uses PT_SUNW_EH_FRAME and PT_SUNW_UNWIND program header types
instead of PT_GNU_EH_FRAME for exception handling frames. This patch
checks if the illumos headers are defined, and checks the appropriate
fields in the ELF header if so.
FreeBSD defines PT_SUNW_UNWIND but not PT_SUNW_EH_FRAME for compatibility,
so we check for both headers to avoid breaking FreeBSD builds.
---
libunwind/src/AddressSpace.hpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 52477b16b355a..9b9e1d0a13073 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_EH_FRAME) && defined(PT_SUNW_UNWIND)
+ // illumos/Solaris use PT_SUNW_EH_FRAME and PT_SUNW_UNWIND instead of PT_GNU_EH_FRAME.
+ // FreeBSD defines PT_SUNW_UNWIND but not PT_SUNW_EH_FRAME, so check for both.
+ if (phdr->p_type == PT_SUNW_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;
More information about the cfe-commits
mailing list