undefined reference to '_asan_init_v4' when compiling

vamshi picture vamshi · Feb 27, 2017 · Viewed 18.8k times · Source

When linking my code compiled with the AddressSanitizer tool, I'm getting many errors of the kind undefined reference to '_asan_init_v4'.

clang -fPIC -g -fno-omit-frame-pointer -DNDEBUG -Wl,-z,defs \
  -shared -Wl,-soname,libqpid-dispatch.so -o libqpid-dispatch.so \
  CMakeFiles/qpid-dispatch.dir/alloc_pool.c.o \
  CMakeFiles/qpid-dispatch.dir/amqp.c.o \
  [...]
  -lpthread -lrt -ldl -lpython3.7m -lwebsockets -fsanitize=address

Some examples of the errors

/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: CMakeFiles/qpid-dispatch.dir/http-libwebsockets.c.o: in function `qd_http_server_free':
/home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:824: undefined reference to `__ubsan_handle_type_mismatch_v1'
/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: /home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:825: undefined reference to `__ubsan_handle_type_mismatch_v1'
/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: /home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:825: undefined reference to `__ubsan_handle_type_mismatch_v1'
/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: /home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:825: undefined reference to `__ubsan_handle_type_mismatch_v1'
/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: /home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:825: undefined reference to `__ubsan_handle_type_mismatch_v1'
/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: /home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:825: undefined reference to `__asan_report_load8'
/nix/store/1zf4cnaaidjajwb4gx4mnkqc5dypkcdy-binutils-2.31.1/bin/ld: /home/jdanek/repos/qpid/qpid-dispatch/src/http-libwebsockets.c:825: undefined reference to `__asan_report_load8'

Note: I am using NixOS 19.09 and Clang 10.

Answer

BoltzmannBrain picture BoltzmannBrain · May 3, 2018

You should be using the compile flag -fsanitize=address: https://github.com/google/sanitizers/wiki/AddressSanitizer

Note that -fsanitize=address = -lasan + some add'l options. And using -lasan has been discouraged by ASan developers.