15

当链接我用 AddressSanitizer 工具编译的代码时,我遇到了很多类似的错误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

一些错误示例

/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'

注意:我使用的是 NixOS 19.09 和 Clang 10。

4

3 回答 3

10

您应该使用编译标志-fsanitize=addresshttps ://github.com/google/sanitizers/wiki/AddressSanitizer

请注意-fsanitize=address= -lasan+ 一些附加选项。-lasanASan 开发人员不鼓励使用。

于 2018-05-03T20:48:16.057 回答
1

我不确定这是不是问题,但对我来说,添加-lasan到链接器选项足以让我的程序构建和运行。

于 2017-11-01T11:01:44.663 回答
-1

添加-static-libasan到链接器标志将解决这个问题。

于 2019-06-10T06:27:30.753 回答