This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Compare against the alignment of the latter range trying to find consecutive TLS blocks in GetStaticTlsBoundary
ClosedPublic

Authored by xry111 on Jul 5 2022, 2:11 AM.

Details

Summary

On a mips64el-linux-gnu system, the dynamic linker arranges TLS blocks
like:

[0] 0xfff7fe9680..0xfff7fe9684, align = 0x4
[1] 0xfff7fe9688..0xfff7fe96a8, align = 0x8
[2] 0xfff7fe96c0..0xfff7fe9e60, align = 0x40
[3] 0xfff7fe9e60..0xfff7fe9ef8, align = 0x8

Note that the dynamic linker can only put [1] at 0xfff7fe9688, not
0xfff7fe9684 or it will be misaligned. But we were comparing the
distance between two blocks with the alignment of the previous range,
causing GetStaticTlsBoundary fail to merge the consecutive blocks.

Compare against the alignment of the latter range to fix the issue.

Diff Detail

Event Timeline

xry111 created this revision.Jul 5 2022, 2:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2022, 2:11 AM
xry111 requested review of this revision.Jul 5 2022, 2:11 AM
Herald added a subscriber: Restricted Project. · View Herald TranscriptJul 5 2022, 2:11 AM

@xry111 Thanks for this! Since the implementation of TLS in glibc may differ in various versions (but should be very constant after ~2.19), is there anything here that depends on the glibc version?

xry111 added a comment.Jul 5 2022, 2:33 AM

@xry111 Thanks for this! Since the implementation of TLS in glibc may differ in various versions (but should be very constant after ~2.19), is there anything here that depends on the glibc version?

I'm not sure. I'm using Glibc-2.35 and the arrangement I've mentioned in the commit message caused 4 test failures running GCC thread sanitizer testsuite, but @dmilosevic141 cannot reproduce the failure. So I guess it's related to glibc version. Or maybe it's related to kernel page size (mine is 16KB) or something.

MaskRay accepted this revision.Jul 16 2022, 9:23 PM
This revision is now accepted and ready to land.Jul 16 2022, 9:23 PM

For https://sourceware.org/bugzilla/show_bug.cgi?id=16291 (feature request: provide simpler ways to compute stack and tls boundaries), I created an implementation https://sourceware.org/pipermail/libc-alpha/2021-September/131388.html but the patch is stuck. Someone may leave a comment on https://sourceware.org/bugzilla/show_bug.cgi?id=16291 to hopefully make the patch forward.