This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Use _thread_db_sizeof_pthread to obtain struct pthread size
ClosedPublic

Authored by fweimer on Feb 4 2022, 8:38 AM.

Details

Summary

This symbol has been exported (as an internal GLIBC_PRIVATE symbol) from libc.so.6 starting with glibc 2.34. glibc uses it internally for its libthread_db implementation to enable thread debugging on GDB, so it is unlikely to go away for now.

Fixes #52989.

Diff Detail

Event Timeline

fweimer requested review of this revision.Feb 4 2022, 8:38 AM
fweimer created this revision.
Herald added a subscriber: Restricted Project. · View Herald TranscriptFeb 4 2022, 8:38 AM
MaskRay retitled this revision from Use _thread_db_sizeof_pthread to obtain struct pthread size to [sanitizer] Use _thread_db_sizeof_pthread to obtain struct pthread size.Feb 4 2022, 10:00 AM
MaskRay added a reviewer: Restricted Project.
fweimer updated this revision to Diff 406021.Feb 4 2022, 10:01 AM
fweimer edited the summary of this revision. (Show Details)Feb 4 2022, 10:12 AM
This revision is now accepted and ready to land.Feb 4 2022, 11:44 AM

Would someone please commit this patch for me? Thanks.

Would someone please commit this patch for me? Thanks.

I'd like a sanitizer maintainer (e.g. @vitalybuka) to have a look.

I personally tested this on x86-64 and aarch64 on glibc 2.33 (the _thread_db_sizeof_pthread code path is not taken).
Have you tested check-asan check-msan check-tsan check-lsan with glibc 2.34?

fweimer added a comment.EditedFeb 7 2022, 3:04 AM

Would someone please commit this patch for me? Thanks.

I'd like a sanitizer maintainer (e.g. @vitalybuka) to have a look.

Sorry for jumping the gun here. Phabricator told me that *This revision is now accepted and ready to land.*, so I assumed I was done.

I personally tested this on x86-64 and aarch64 on glibc 2.33 (the _thread_db_sizeof_pthread code path is not taken).
Have you tested check-asan check-msan check-tsan check-lsan with glibc 2.34?

I have checked that the correct path is taken on x86-64 on both glibc 2.28 and glibc 2.34. In the glibc 2.34 case, dlsym is used, and returns the same constant as the hard-coded one. I have since returned the lab machines, but I guess I can try once more and run those tests.

EDIT I see two test failures on glibc 2.34 (from Fedora 35), but they aren't regressions:

Failed Tests (2):
  AddressSanitizer-i386-linux :: TestCases/Linux/odr-vtable.cpp
  AddressSanitizer-i386-linux :: TestCases/strcat-overlap.cpp

Would someone please commit this patch for me? Thanks.

I'd like a sanitizer maintainer (e.g. @vitalybuka) to have a look.

Sorry for jumping the gun here. Phabricator told me that *This revision is now accepted and ready to land.*, so I assumed I was done.

Phabricator has loose permission management.
Anyone accepting the patch will make it green, unless there is a blocking reviewer.

What applies is this rule https://llvm.org/docs/CodeReview.html#lgtm-how-a-patch-is-accepted :

"Every patch should be reviewed by at least one technical expert in the areas of the project affected by the change."

From my observation, @vitalybuka usually wants to keep an eye on portability changes like this... So I think it's a good idea that he can take a look.
Also, we'd need this in release/14.x (14.0.0-rc1 is scheduled tomorrow?), so additional testing is definitely appreciated (as you have done below, thanks!)...

I personally tested this on x86-64 and aarch64 on glibc 2.33 (the _thread_db_sizeof_pthread code path is not taken).
Have you tested check-asan check-msan check-tsan check-lsan with glibc 2.34?

I have checked that the correct path is taken on x86-64 on both glibc 2.28 and glibc 2.34. In the glibc 2.34 case, dlsym is used, and returns the same constant as the hard-coded one. I have since returned the lab machines, but I guess I can try once more and run those tests.

EDIT I see two test failures on glibc 2.34 (from Fedora 35), but they aren't regressions:

Failed Tests (2):
  AddressSanitizer-i386-linux :: TestCases/Linux/odr-vtable.cpp
  AddressSanitizer-i386-linux :: TestCases/strcat-overlap.cpp
vitalybuka accepted this revision.Feb 8 2022, 12:37 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
297

if (psizeof)

MaskRay updated this revision to Diff 406941.Feb 8 2022, 12:43 PM

> if (psizeof)

remove unneeded formatting

This revision was landed with ongoing or failed builds.Feb 8 2022, 12:46 PM
This revision was automatically updated to reflect the committed changes.
paulkirth added a subscriber: paulkirth.EditedFeb 8 2022, 2:34 PM

We're seeing a breakage in Fuchsia's Clang canary builder on Linux that seem related to this change.

The error output is:

156/182] Checking TSan Go runtime...
FAILED: compiler-rt/lib/tsan/rtl/CMakeFiles/GotsanRuntimeCheck /b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/CMakeFiles/GotsanRuntimeCheck 
cd /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/tsan/go && env "CC=/b/s/w/ir/x/w/staging/llvm_build/./bin/clang " EXTRA_CFLAGS= IN_TMPDIR=1 SILENT=1 /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/tsan/rtl/../go/buildgo.sh
ld.lld: error: undefined symbol: dlsym
>>> referenced by gotsan.cpp
>>>               /tmp/gotsan.Irz2GAAcvm/race_linux_amd64.syso:(__sanitizer::ThreadDescriptorSize())
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

The builder can be found here: https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8822761889490955409/overview

If the problem is difficult to address, would you mind reverting until it can be fixed?

We're seeing a breakage in Fuchsia's Clang canary builder on Linux that seem related to this change.

The error output is:

156/182] Checking TSan Go runtime...
FAILED: compiler-rt/lib/tsan/rtl/CMakeFiles/GotsanRuntimeCheck /b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/CMakeFiles/GotsanRuntimeCheck 
cd /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/tsan/go && env "CC=/b/s/w/ir/x/w/staging/llvm_build/./bin/clang " EXTRA_CFLAGS= IN_TMPDIR=1 SILENT=1 /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/tsan/rtl/../go/buildgo.sh
ld.lld: error: undefined symbol: dlsym
>>> referenced by gotsan.cpp
>>>               /tmp/gotsan.Irz2GAAcvm/race_linux_amd64.syso:(__sanitizer::ThreadDescriptorSize())
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

The builder can be found here: https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8822761889490955409/overview

If the problem is difficult to address, would you mind reverting until it can be fixed?

Should be fixed by f0cdacd99bd41dbd778099dfe303ba92660826b3.
Looks like check-tsan passes even if I skip the entire thread stuff for the SANITIZER_GO code path...
(I know nearly nothing about the SANITIZER_GO code path)

Thanks for the quick fix. Looks like this is no longer an issue.