This is an archive of the discontinued LLVM Phabricator instance.

[asan] Fix an OS X startup crash when an empty section is present
ClosedPublic

Authored by kubamracek on Jul 4 2015, 3:08 AM.

Details

Reviewers
glider
samsonov
Summary

On OS X, when the main instrumented binary contains a custom section with zero length, ASan will crash (assert failure) early in the initialization. This can be reproduced with a linker option -sectcreate mysegment mysection /dev/null. Running such a binary with ASan produces just:

$ ./a.out
==38355==AddressSanitizer CHECK failed: .../llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc:258 "((start1 <= end1)) != (0)" (0x0, 0x0)

There seems to be an off-by-one bug in MemoryRangeIsAvailable, this patch fixes it and adds a regression test.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 29048.Jul 4 2015, 3:08 AM
kubamracek retitled this revision from to [asan] Fix an OS X startup crash when an empty section is present.
kubamracek updated this object.
kubamracek added reviewers: glider, samsonov.
kubamracek added subscribers: samsonov, glider.
samsonov added inline comments.Jul 6 2015, 9:40 AM
lib/sanitizer_common/sanitizer_posix.cc
275

This is incorrect. IntervalsAreSeparate and MemoryRangeIsAvailable assume that start and end are inclusive (just audit its code and uses).
You need a special case for zero-size interval.

kubamracek updated this revision to Diff 29101.Jul 6 2015, 9:48 AM

Second take on the fix.

samsonov accepted this revision.Jul 6 2015, 9:55 AM
samsonov edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jul 6 2015, 9:55 AM
kubamracek closed this revision.Jul 6 2015, 10:17 AM

Landed in r241474.