13

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?

yugr
  • 19,769
  • 3
  • 51
  • 96
intrigued_66
  • 16,082
  • 51
  • 118
  • 189
  • 13
    You also need `LDFLAGS=-fsanitize=address`. The sanitizer flags need to be passed to the linker as well – Justin May 30 '18 at 17:22
  • @Justin this alone didn't solve it (I haven't tried the below answer yet) – intrigued_66 May 31 '18 at 09:00
  • 1
    @Justin This should be the answer. – yugr May 31 '18 at 09:35
  • @mezamorphic Did you make sure to _link_ with `-fsanitize=address`? Use of `-lasan` is not recommended by Asan developers. – yugr May 31 '18 at 09:36
  • @mezamorphic Please check my answer to [50621054](https://stackoverflow.com/questions/50621054) and vote if it helps. We'll then be able to close as dup. – yugr May 31 '18 at 12:48
  • 2
    Possible duplicate of [Getting undefined symbol: \_\_asan\_memset when trying to use Clang address sanitizer](https://stackoverflow.com/questions/50621054/getting-undefined-symbol-asan-memset-when-trying-to-use-clang-address-sanitiz) – Anton Korobeynikov May 31 '18 at 15:44
  • 3
    I think it's not a dup: OP describes an issue when using `-fsanitize=address` in combination with `-fvisibility=hidden -fvisibility-inlines-hidden`. Nevertheless, at runtime the `LD_PRELOAD=libclang_rt.asan.so` is a valid work-around – Ax3l Feb 17 '19 at 11:15
  • Seems to be CMake script specific. Locally reproducing the issue, I can only see this when indeed `-fsanitize=address` is missing from the linker lines (I still see OPs issue in a larger project, even though my verbose make output includes this during link) – Ax3l Feb 17 '19 at 11:45

0 Answers0