This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Fix glibc sparc build and add GetTls support
ClosedPublic

Authored by MaskRay on Apr 20 2021, 2:59 PM.

Details

Summary

sanitizer_linux_libcdep.cpp doesn't build for Linux sparc (with minimum support
but can build) after D98926. I wasn't aware because the file didn't mention
__sparc__.

While here, add the relevant support since it does not add complexity
(the D99566 approach). Adds an explicit #error for unsupported
non-Android Linux and FreeBSD architectures.

ThreadDescriptorSize is only used by lsan to scan thread-specific data keys in
the thread control block.

On TLS Variant II architectures (i386/x86_64/s390/sparc), our dl_iterate_phdr
based approach can cover the region from the first byte of the static TLS block
(static TLS surplus) to the thread pointer.
We just need to extend the range to include the first few members of struct
pthread. offsetof(struct pthread, specific_used) satisfies the requirement and
has not changed since 2007-05-10. We don't need to update ThreadDescriptorSize
for each glibc version.

Technically we could use the 524/1552 for x86_64 as well but there is potential
risk that large applications with thousands of shared object dependency may
dislike the time complexity increase if there are many threads, so I don't make
the simplification for now.

Diff Detail

Event Timeline

MaskRay created this revision.Apr 20 2021, 2:59 PM
MaskRay requested review of this revision.Apr 20 2021, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 2:59 PM

@glaubitz I submitted https://cfarm.tetaneutral.net/users/new/ but am waiting for the approval, so I haven't tested this on sparc, just think it should theoretically work.

@glaubitz I submitted https://cfarm.tetaneutral.net/users/new/ but am waiting for the approval, so I haven't tested this on sparc, just think it should theoretically work.

I'm already testing it. Thanks for whipping up a patch so quickly!

Sanitizers run on NetBSD/sparc64.

MaskRay retitled this revision from [sanitizer] Fix sparc build and add GetTls support to [sanitizer] Fix glibc sparc build and add GetTls support.Apr 20 2021, 3:39 PM
glaubitz accepted this revision.Apr 20 2021, 3:40 PM

I could find out quickly whether the ThreadDescriptorSize for SPARC is correct but otherwise LGTM.

It also fixes the build for me.

This revision is now accepted and ready to land.Apr 20 2021, 3:40 PM
MaskRay updated this revision to Diff 339061.Apr 20 2021, 5:41 PM

Delete #if

This revision was landed with ongoing or failed builds.Apr 20 2021, 5:42 PM
This revision was automatically updated to reflect the committed changes.