Description
Bugzilla Link | 50446 |
Version | 12.0 |
OS | Linux |
Extended Description
When build LLVM 12 with GCC 9.3.0, and running "make check-lsan" on CentOS 7, I see these failures:
Failed Tests (2):
LeakSanitizer-AddressSanitizer-x86_64 :: TestCases/Linux/use_tls_dynamic.cpp
LeakSanitizer-Standalone-x86_64 :: TestCases/Linux/use_tls_dynamic.cpp
The failing step is this:
// RUN: %env_lsan_opts=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s
It is expecting the sanitizer to detect a memory leak. If I run the command by hand outside of llvm-lit, it does successfully report a memory leak:
$ env LSAN_OPTIONS=:detect_leaks=1:"suppressions=:report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0:use_tls=0" $PWD/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp
Test alloc: 0x61a000000600
=================================================================
==46854==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1048576 byte(s) in 1 object(s) allocated from:
#0 0x40ad05 (/home/bryanpkc/llvm/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp+0x40ad05)
#1 0x7fa51ee25f67 (/lib64/ld-linux-x86-64.so.2+0x11f67)
#2 0x7fa51c7fe713 (/home/bryanpkc/llvm/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp-so.so+0x713)
#3 0x42f40b (/home/bryanpkc/llvm/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp+0x42f40b)
#4 0x7fa51db4d3d4 (/lib64/libc.so.6+0x223d4)
Objects leaked above:
0x7fa51c6fe000 (1048576 bytes)
Indirect leak of 1337 byte(s) in 1 object(s) allocated from:
#0 0x40a5b0 (/home/bryanpkc/llvm/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp+0x40a5b0)
#1 0x42f3f7 (/home/bryanpkc/llvm/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp+0x42f3f7)
#2 0x7fa51db4d3d4 (/lib64/libc.so.6+0x223d4)
Objects leaked above:
0x61a000000600 (1337 bytes)
SUMMARY: LeakSanitizer: 1049913 byte(s) leaked in 2 allocation(s).
However, llvm-lit prepends ${LLVM_BINARY_DIR}/bin to the $PATH variable, and this changes the behaviour of the test:
$ env PATH=$PWD/build/bin:$PATH LSAN_OPTIONS=:detect_leaks=1:"suppressions=:report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0:use_tls=0" $PWD/build/projects/compiler-rt/test/lsan/X86_64LsanConfig/TestCases/Linux/Output/use_tls_dynamic.cpp.tmp
Test alloc: 0x61a000000600
Suppressions used:
count bytes template
1 1048576 tls_get_addr
The test case itself does not use $PATH or invokes any subprocess, and it isn't obvious how $PATH affect LSAN here.
The problem is not reproducible on Ubuntu 18.04.