[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

Nobody has claimed this yet.

Assessment

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

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.

Description

compiler-rt:lsan

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:

--- 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;
Dominant language
LLVM
Stars
40.6k
Forks
18.7k
Avg merge
18h 16m
Merged PRs (30d)
417

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from llvm/llvm-project

All issues in llvm/llvm-project

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.