-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Description
Build fails at link time if a static library is compiled with address sanitizer, but the executable using the library is not. Example:
add_library(foo STATIC foo.cpp)
add_sanitizers(foo)
add_executable(main main.cpp)
target_link_libraries(main foo)
Link-time error:
[ 75%] Linking CXX static library libfoo.a
[ 75%] Built target foo
[ 87%] Linking CXX executable main
libfoo.a(foo.cpp.o): In function `foo()':
sanitizers-cmake/tests/foo.cpp:2: undefined reference to `__asan_option_detect_stack_use_after_return'
The link succeed using SHARED library type, but fails at runtime. The asan wrapper script is mandatory in that situation.
./tests/main
==72769==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
../cmake/asan-wrapper ./tests/main
==72780==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffef9eff968 at pc 0x7fdd7696791c bp 0x7ffef9eff910 sp 0x7ffef9eff900
However, when the final executable is itself sanitizer-enabled, then this situation does not occur and everything works just fine, both with static and shared library.
Maybe one solution would be to import asan library and add it to the INTERFACE_LINK_LIBRARIES of targets using a sanitizer.
IohannRabesonIohannRabeson
Metadata
Metadata
Assignees
Labels
No labels