llvm / llvm/llvm-project

[lsan] False leaks on glibc riscv64 since PR #120036: GetTls() no longer covers struct pthread

Open Beginner friendly
#216,580 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt:lsan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I was working on identifying why a new test in libcupsfilters 2.2.1 fails on Fedora 45 riscv64

The build log is here:
https://riscv-kojipkgs.fedoraproject.org/koji/buildinfo?buildID=124037
(see FAIL: cupsfilters/test-pclm-overflow.sh)

It appears that PR #120036 converted an `else if` to a pre-processor macro so that the necessary code for riscv64/glibc only runs on FreeBSD
```
# elif SANITIZER_FREEBSD
*size += 128; // RTLD_STATIC_TLS_EXTRA
# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64
const uptr pre_tcb_size = TlsPreTcbSize();
*addr -= pre_tcb_size;
*size += pre_tcb_size;
...
```

This landed in LLVM, GCC 16, and GCC 15.2
LLVM: (https://github.com/llvm/llvm-project/commit/801b519dfd01)
GCC 16: (https://github.com/gcc-mirror/gcc/commit/5111ea055f5699ad47605890fb45af5c3db1de4f)
GCC 15 branch (for 15.2): (https://github.com/gcc-mirror/gcc/commit/80f7f229883f)

But using a Fedora 42 mock buildroot with GCC downgraded to 15.1 (from https://riscv-kojipkgs.fedoraproject.org/koji/buildinfo?buildID=3557) I was able to see the test pass and the build complete.

The behavior can probably be repaired with something like:
```diff
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -630,6 +630,9 @@
*size += 1664;
# elif SANITIZER_FREEBSD
*size += 128; // RTLD_STATIC_TLS_EXTRA
+# endif
+
+# if SANITIZER_GLIBC || SANITIZER_FREEBSD
# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64
const uptr pre_tcb_size = TlsPreTcbSize();
*addr -= pre_tcb_size;
```

Contributor guide

Open the contributing guide

Research direction

Start in compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp and inspect GetTls() around the SANITIZER_FREEBSD and SANITIZER_RISCV64 guards, especially TlsPreTcbSize(). Use the Fedora riscv64 libcupsfilters failure as the reproduction context. Done means glibc riscv64 no longer reports the false leak and the cupsfilters test/build completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.