我在 ubuntu 18.04 中使用了 clang-10。
我试图用内存清理器构建共享库。
#include <stdio.h>
int foo(int argc, char** argv) {
int* a = new int[10];
a[5] = 0;
if (a[argc])
printf("xx\n");
return 0;
}
构建的对象:
clang++ -c foo.cpp -o foo.o -fsanitize=memory -fPIC
然后我尝试将它链接到共享库:
clang++ -Wl,--no-undefined -shared -Wl,-soname,libFoo.so -o libFoo.so foo.o
在此命令之后,我得到了错误输出:
foo.o: In function `foo(int, char**)':
foo.cpp:(.text+0xf): undefined reference to `__msan_param_tls'
foo.cpp:(.text+0x68): undefined reference to `__msan_retval_tls'
foo.cpp:(.text+0xc9): undefined reference to `__msan_warning_noreturn'
foo.cpp:(.text+0x126): undefined reference to `__msan_warning_noreturn'
foo.cpp:(.text+0x168): undefined reference to `__msan_warning_noreturn'
foo.cpp:(.text+0x17f): undefined reference to `__msan_param_tls'
foo.cpp:(.text+0x18e): undefined reference to `__msan_va_arg_overflow_size_tls'
foo.cpp:(.text+0x19d): undefined reference to `__msan_retval_tls'
foo.cpp:(.text+0x1bb): undefined reference to `__msan_retval_tls'
foo.o: In function `msan.module_ctor':
foo.cpp:(.text+0x1d2): undefined reference to `__msan_init'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
.so
使用内存清理器构建文件的正确命令是什么?