https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81079
Martin Liška <marxin at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> --- (In reply to d25fe0be@ from comment #0) > When object files (compiled separately) are linked together using GCC, even > if -static-libxsan is specifed, the corresponding libraries seems not to be > linked, resulting in undefined references to __ubsan_xxx / ... . > > It seems that -static-libxsan is suppressed by the absence of -fsanitize=xxx. > > lsan seems not to suffer from this though. > Hi. It's documented pretty well: ``` -static-libasan When the -fsanitize=address option is used to link a program, the GCC driver automatically links against libasan. If libasan is available as a shared library, and the -static option is not used, then this links against the shared version of libasan. The -static-libasan option directs the GCC driver to link libasan statically, without necessarily linking other libraries statically. ``` Thus one needs to use -fsanitize=x in linking. I also verified and liblsan behaves the same. Problem is that liblasan does not contain a symbol that will cause an unresolved symbol. But: $ cat pr81079.cpp #include <stdlib.h> const int &f() { return {}; } int main() { int *a = (int*)malloc (123); f(); } $ g++ pr81079.cpp -std=c++11 -c -fsanitize=leak $ g++ pr81079.o -std=c++11 && ./a.out [no output] while: $ g++ pr81079.o -std=c++11 -fsanitize=leak && ./a.out ================================================================= ==7875==ERROR: LeakSanitizer: detected memory leaks Direct leak of 123 byte(s) in 1 object(s) allocated from: #0 0x2aeb4c5d15a6 in malloc (/usr/lib64/liblsan.so.0+0xd5a6) #1 0x40062a in main (/home/marxin/Programming/testcases/a.out+0x40062a) #2 0x2aeb4dd39469 in __libc_start_main (/lib64/libc.so.6+0x20469) SUMMARY: LeakSanitizer: 123 byte(s) leaked in 1 allocation(s). That said, I'm closing that as invalid.