-
Notifications
You must be signed in to change notification settings - Fork 16k
[libunwind] Fix EH frame handling on illumos. #176988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-libunwind Author: Joshua Carp (jmcarp) ChangesIllumos 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 to clickhouse. We initially sent this patch to clickhouse's fork of llvm, but would like to upstream the change first to prevent clickhouse's fork from further diverging from this repo. cc @rschu1ze Full diff: https://github.com/llvm/llvm-project/pull/176988.diff 1 Files Affected:
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;
|
libunwind/src/AddressSpace.hpp
Outdated
| #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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe major BSD, including FreeBSD, all use PT_GNU_EH_FRAME. The comment should be removed.
I think you just need to check one constant. PT_SUNW_EH_FRAME
(PT_SUNW_UNWIND, if defined, has the same value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, consider removing the source change and adding a cmake -D like Haiku did in https://reviews.llvm.org/D157866
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I'm misunderstanding, but I think PT_SUNW_EH_FRAME and PT_SUNW_UNWIND refer to different values. From the illumos source:
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
So I think we need to check both values on illumos, and the cmake change wouldn't be enough. I updated the patch to fix the comment. Let me know if I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping, when you have time.
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
22a19e6 to
0c3f6a5
Compare
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 to clickhouse. We initially sent this patch to clickhouse's fork of llvm, but would like to upstream the change first to prevent clickhouse's fork from further diverging from this repo.
cc @rschu1ze