-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[UBSAN] Undefined references with -Wl,--no-undefined
#60578
Comments
Isn't this |
I'm assuming it is the clang driver that is responsible for adding UBSAN libraries to the gold command line. Also, I should note that the problem does not reproduce with gcc 11.3 on the same system. It also uses gold. |
@llvm/issue-subscribers-clang-driver
When linking a shared library with `-Wl,--no-undefined` switch and UBSan enabled, the linking fails with unresolved references to UBSan symbols.
Here's a test case:
int test(int n)
{
return n + 10;
} Commands: clang++ -stdlib=libc++ -fsanitize=undefined -fno-sanitize-recover=undefined -o ubsan_unresolved_test.o -c ubsan_unresolved_test.cpp
clang++ -stdlib=libc++ -fsanitize=undefined -fuse-ld=gold -Wl,--no-undefined -shared -o ubsan_unresolved_test.so ubsan_unresolved_test.o Output: ubsan_unresolved_test.o:ubsan_unresolved_test.cpp:function test(int): error: undefined reference to '__ubsan_handle_add_overflow_abort'
clang: error: linker command failed with exit code 1 (use -v to see invocation) Clang version: $ clang -v
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@<!-- -->m64
Selected multilib: .;@<!-- -->m64 This is on Kubuntu 22.04, x86-64. The workaround is to add |
When linking a shared library with
-Wl,--no-undefined
switch and UBSan enabled, the linking fails with unresolved references to UBSan symbols.Here's a test case:
ubsan_unresolved_test.cpp
:Commands:
Output:
Clang version:
This is on Kubuntu 22.04, x86-64.
The workaround is to add
-lubsan
to the linker command line.The text was updated successfully, but these errors were encountered: