This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Fix sem_init_glibc.cc test on __HAVE_64B_ATOMIC arches.
ClosedPublic

Authored by koriakin on Apr 7 2016, 3:10 AM.

Details

Reviewers
samsonov
eugenis
Summary

Starting with 2.21, glibc can use one of 2 layouts for semaphores:
architectures that don't HAVE_64B_ATOMIC use an uint32_t field
with semaphore value, then a private field, then a waiting thread
count field - this is the layout currently assumed by the test.
However,
HAVE_64B_ATOMIC arches use a fused uint64_t field that
contains the value in low bits and waiting thread count in high bits,
followed by a private field.

This resulted in taking private field from the wrong offset on 64-bit
atomic platforms (the test still passed, but didn't actually test
the private field). On big-endian platforms, this resulted in a fail,
since the first 4 bytes overlay the thread count field, and not
the value field.

Found while porting ASan to s390x.

Diff Detail

Event Timeline

koriakin retitled this revision from to [sanitizer] Fix sem_init_glibc.cc test on __HAVE_64B_ATOMIC arches..
koriakin updated this object.
koriakin added reviewers: samsonov, eugenis.
koriakin set the repository for this revision to rL LLVM.
koriakin added a project: Restricted Project.
koriakin added a subscriber: llvm-commits.
eugenis accepted this revision.Apr 7 2016, 11:45 AM
eugenis edited edge metadata.

LGTM

This revision is now accepted and ready to land.Apr 7 2016, 11:45 AM

Thanks. I don't have SVN write access, could you commit it for me?

This breaks linux/x86_64 with
sem_init_glibc.cc:36: int main(): Assertion `a == 42' failed.

Failing Tests (4):

SanitizerCommon-asan-x86_64-Linux :: Linux/sem_init_glibc.cc
SanitizerCommon-lsan-x86_64-Linux :: Linux/sem_init_glibc.cc
SanitizerCommon-msan-x86_64-Linux :: Linux/sem_init_glibc.cc
SanitizerCommon-tsan-x86_64-Linux :: Linux/sem_init_glibc.cc
koriakin updated this object.
koriakin edited edge metadata.
koriakin removed rL LLVM as the repository for this revision.

Whoops, it seems the new layout is only used in glibc >= 2.21. I assume you've tested on an older glibc?

I've added a __GLIBC_PREREQ test for that. In theory, we should be using the runtime version of the library, and not the version of headers, but it shouldn't matter since the program is compiled immediately before use. What do you think?

Yes, I've got glibc 2.19.
I think this is fine in a test.

eugenis closed this revision.Apr 7 2016, 1:32 PM

r265715