[libunwind] [libunwind][AIX] Call dlclose only when dlsym() fails (PR #112768)
Xing Xue via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 12:39:04 PDT 2024
https://github.com/xingxue-ibm created https://github.com/llvm/llvm-project/pull/112768
The personality routine `__xlcxx_personality_v0` in `libc++abi` is hard-coded in the unwinder as the handler for EH in applications generated by the legacy IBM C++ compiler. The symbol is resolved dynamically using `dlopen` to avoid a hard dependency of `libunwind` on `libc++abi` for cases such as non-C++ applications. However, `dlclose` was incorrectly called after `dlsym` succeeded, potentially invalidating the function pointer obtained from `dlsym` when the memory allocated for the `dlopen` is reclaimed. This PR changes to call `dlclose` only when `dlsym` fails.
>From 2bb223edb6a3a7766606f5c7e6c0aa3fa3e09a63 Mon Sep 17 00:00:00 2001
From: Xing Xue <xingxue at outlook.com>
Date: Thu, 17 Oct 2024 14:59:40 -0400
Subject: [PATCH] Call dlclose() only when dlsym() fails.
---
libunwind/src/UnwindCursor.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 2a3aba28fb6ca5..9f3ffd19e1746a 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -2151,8 +2151,8 @@ bool UnwindCursor<A, R>::getInfoFromTBTable(pint_t pc, R ®isters) {
if (xlcPersonalityV0 == NULL) {
_LIBUNWIND_TRACE_UNWINDING("dlsym() failed with errno=%d\n", errno);
assert(0 && "dlsym() failed");
+ dlclose(libHandle);
}
- dlclose(libHandle);
errno = saveErrno;
}
xlcPersonalityV0InitLock.unlock();
More information about the cfe-commits
mailing list