18

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?

8
  • 18
    You also need LDFLAGS=-fsanitize=address. The sanitizer flags need to be passed to the linker as well Commented May 30, 2018 at 17:22
  • @Justin this alone didn't solve it (I haven't tried the below answer yet) Commented May 31, 2018 at 9:00
  • 1
    @Justin This should be the answer. Commented May 31, 2018 at 9:35
  • 2
    Possible duplicate of Getting undefined symbol: __asan_memset when trying to use Clang address sanitizer Commented May 31, 2018 at 15:44
  • 5
    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 Commented Feb 17, 2019 at 11:15

1 Answer 1

0

The executable need to link against the static ASAN library, should be done by, looks like you are using ld rather than clang for linking job. Check here.

-fsanitize=address -static-libasan

If you use cmake, it will be look like:

CXXFLAGS += -fsanitize=address -static-libasan
LDFLAGS += -fsanitize=address -static-libasan

Refer to this blog.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.