I'm trying to compile C++ using clang's address sanitizer to output the sanitize results within a core dump, so I added:
CXXFLAGS += -fsanitize=address
to have the compiler options:
/opt/llvm-3.8.0/bin/clang++ \
--gcc-toolchain=/opt/gcc-5.2.0 -fsanitize=address -DLINUX \
-DLINUX64 -DTB_USE_RCU -DURCU_INLINE_SMALL_FUNCTIONS \
-DU_USING_ICU_NAMESPACE=0 -DNDEBUG -D_POSIX_PTHREAD_SEMANTICS \
-fPIC -D_GNU_SOURCE -DTB_USE_RCU -DTB_USE_RCU \
-D_GLIBCXX_USE_CXX11_ABI=0 -m64 --gcc-toolchain=/opt/gcc-5.2.0 \
-flto=full -std=gnu++14 -D_GLIBCXX_DEPRECATED= -pipe \
-fno-omit-frame-pointer -ffast-math -fno-finite-math-only \
-pthread -march=core2 -mtune=corei7 -g -O3 -Qunused-arguments \
-fnon-call-exceptions -fvisibility=hidden \
-fvisibility-inlines-hidden -Wall -Wextra -Wshadow \
-Wpointer-arith -Wno-self-assign -Wno-unused-function \
-Wno-gnu-empty-initializer -Wno-unused-parameter \
-Wno-ignored-qualifiers -Wno-mismatched-tags \
-Wno-unused-local-typedef -Wno-parentheses-equality \
-Wno-unused-private-field -Wno-missing-field-initializers \
-Wno-missing-braces -Werror=return-type \
-Werror=overloaded-virtual -c MyClass.cpp -o MyClass.o
but I get the error:
undefined symbol: __asan_option_detect_stack_use_after_return
What's the simplest way to resolve this?
LDFLAGS=-fsanitize=address. The sanitizer flags need to be passed to the linker as well-fsanitize=addressin combination with-fvisibility=hidden -fvisibility-inlines-hidden. Nevertheless, at runtime theLD_PRELOAD=libclang_rt.asan.sois a valid work-around