https://sourceware.org/bugzilla/show_bug.cgi?id=25940
Bug ID: 25940 Summary: ld.bfd, clang’s ubsan, shared libraries, and virtual tables do not work together Product: binutils Version: 2.35 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: dilyan.palauzov at aegee dot org Target Milestone: --- I have ld.bfd 2.34.50.20200506, ld.gold 2.34.50.20200506, gcc/g++ 9.3.1 20200506, ld.lld 10.0.0, clang(++) 10.0.0, z.cpp: #include <stdio.h> #include <stdbool.h> #include <string> struct x { std::string x; }; struct z: virtual x { z() { bool b = 99; printf("a %i\n", b); } }; extern "C" { void y(); } void y() { const x x1 = z(); } and a.c: void y(); int main() { y(); } With --- CLANG --- > clang++ -shared -fsanitize=address,undefined z.cpp -fpic -o libz.so > nm -D libz.so|grep san < U __asan_init < U __asan_option_detect_stack_use_after_return < U __asan_register_globals < U __asan_report_load8 < U __asan_report_store8 < U __asan_stack_malloc_2 < U __asan_unregister_globals < U __asan_version_mismatch_check_v8 < U __ubsan_handle_dynamic_type_cache_miss < U __ubsan_handle_load_invalid_value < U __ubsan_handle_type_mismatch_v1 < U __ubsan_vptr_type_cache > clang -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=bfd < /usr/local/bin/ld.bfd: ./libz.so: undefined reference to `__ubsan_vptr_type_cache' < /usr/local/bin/ld.bfd: ./libz.so: undefined reference to `__ubsan_handle_dynamic_type_cache_miss' < clang-10: error: linker command failed with exit code 1 (use -v to see invocation) But if I remove the class conversions from z.cpp, then libz.so does not contains __ubsan_vptr_type_cache as Undefined symbol, while it contains __ubsan_handle_load_invalid_value, and then the linking clang+ld.bfd does work > clang -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=bfd -lubsan < (No error, no warning) > LD_LIBRARY_PATH=. ./b < a 1 > clang -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=gold < /usr/local/bin/ld.gold: warning: Cannot export local symbol '__asan_extra_spill_area' > LD_LIBRARY_PATH=. ./b < ./b: symbol lookup error: ./libz.so: undefined symbol: __ubsan_vptr_type_cache > clang -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=gold -lubsan < /usr/local/bin/ld.gold: warning: Cannot export local symbol '__asan_extra_spill_area' > LD_LIBRARY_PATH=. ./b < a 1 > clang -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=lld < (No error, no warning) > LD_LIBRARY_PATH=. ./b < ./b: symbol lookup error: ./libz.so: undefined symbol: __ubsan_vptr_type_cache > clang -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=lld -lubsan < (No error, no warning) > LD_LIBRARY_PATH=. ./b < a 1 --- GCC --- > g++ -shared -fsanitize=address,undefined z.cpp -fpic -o libz.so > nm -D libz.so|grep san < U __asan_handle_no_return < U __asan_init < U __asan_option_detect_stack_use_after_return < U __asan_register_globals < U __asan_report_load8 < U __asan_report_store8 < U __asan_stack_malloc_2 < U __asan_unregister_globals < U __asan_version_mismatch_check_v8 < U __ubsan_handle_dynamic_type_cache_miss < U __ubsan_handle_pointer_overflow < U __ubsan_handle_type_mismatch_v1 < U __ubsan_vptr_type_cache > gcc -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=bfd < (No error, no warning) > LD_LIBRARY_PATH=. ./b < a 1 > gcc -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=gold < (No error, no warning) > LD_LIBRARY_PATH=. ./b < a 1 > gcc -fsanitize=address,undefined -o b b.c -L. -lz -fuse-ld=lld < (No error, no warning) > LD_LIBRARY_PATH=. ./b < a 1 • Why does clang+ld.bfd produce an error when using ubsan with class conversions? • Why do I have to add in clang+ld.bfd -lubsan to get rid of the warning? • Why does clang+ld.bfd does not produce an error when ubsan does no class conversions? • Why does clang+ld.gold produce a warning? Note that I have LLVMGold.so in /usr/local/lib, but not in /usr/local/lib/bfd-plugins. It is therefore not used by the linker (and this LLVMGold.so is for LLVM 8, as I forgot te complice LLVM 10 with the linker plugin). -- You are receiving this mail because: You are on the CC list for the bug.