Skip to content
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

asan lib should be transitive #26

Open
giraldeau opened this issue Mar 19, 2019 · 0 comments
Open

asan lib should be transitive #26

giraldeau opened this issue Mar 19, 2019 · 0 comments

Comments

@giraldeau
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant