[clang] [compiler-rt] [compiler-rt] Support `-shared-libsan` for Offload UBSan (PR #226551)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 19:15:34 PDT 2026
================
@@ -96,20 +103,17 @@ static void BindRealDlsym();
// OpenMP and sometimes HIP access HSA through 'dlsym' so we need to intercept
// it here if we want to reliably override its definitions.
INTERCEPTOR(void *, dlsym, void *Handle, const char *Name) {
- Initialize();
BindRealDlsym();
- // This interceptor interferes with the order of 'RTLD_NEXT'. Force a tail
- // call to bypass this process in the stack.
- if (Handle == RTLD_NEXT) [[clang::musttail]]
+ // glibc resolves 'RTLD_NEXT' and 'RTLD_DEFAULT' relative to the caller's
+ // scope and attributes the new dependency to it. Tail call to preserve it.
+ void *Wrapper = Name ? WrapperFor(Name) : nullptr;
+ if (Handle == RTLD_NEXT || !Wrapper) [[clang::musttail]]
return REAL(dlsym)(Handle, Name);
+ Initialize();
void *Sym = REAL(dlsym)(Handle, Name);
----------------
yxsamliu wrote:
With shared UBSan loaded first, an `RTLD_LOCAL` plugin’s `dlsym(RTLD_DEFAULT, "hsa_init")` may return UBSan’s wrapper. When called, that wrapper may be unable to find the real HSA function in the plugin’s local dependency, causing the plugin to fail. Could we add a test for this case if feasible? A fake HSA library might allow a test without a GPU.
https://github.com/llvm/llvm-project/pull/226551
More information about the llvm-commits
mailing list