This is an archive of the discontinued LLVM Phabricator instance.

Disable interception of sigaltstack on i386 macOS.
ClosedPublic

Authored by delcypher on Jun 26 2020, 4:40 PM.

Details

Summary

28c91219c7e introduced an interceptor for sigaltstack. It turns out this
broke setjmp on i386 macOS. This is because the implementation of setjmp on
i386 macOS is written in assembly and makes the assumption that the call to
sigaltstack does not clobber any registers. Presumably that assumption was
made because it's a system call. In particular setjmp assumes that before
and after the call that %ecx will contain a pointer the jmp_buf. The
current interceptor breaks this assumption because it's written in C++ and
%ecx is not a calle-saved register. This could be fixed by writing a
trampoline interceptor to the existing interceptor in assembly that
ensures all the registers are preserved. However, this is a lot of work
for very little gain. Instead this patch just disables the interceptor
on i386 macOS.

For other Darwin architectures it currently appears to be safe to intercept
sigaltstack using the current implementation because:

  • setjmp for x86_64 saves the pointer jmp_buf to the stack before calling sigaltstack.
  • setjmp for armv7/arm64/arm64_32/arm64e appears to not call sigaltstack at all.

This patch should unbreak (once they are re-enabled) the following
tests:

AddressSanitizer-Unit :: ./Asan-i386-calls-Test/AddressSanitizer.LongJmpTest
AddressSanitizer-Unit :: ./Asan-i386-calls-Test/AddressSanitizer.SigLongJmpTest
AddressSanitizer-Unit :: ./Asan-i386-inline-Test/AddressSanitizer.LongJmpTest
AddressSanitizer-Unit :: ./Asan-i386-inline-Test/AddressSanitizer.SigLongJmpTest
AddressSanitizer-i386-darwin :: TestCases/longjmp.cpp

This patch introduces a SANITIZER_I386 macro for convenience.

rdar://problem/62141412

Diff Detail

Event Timeline

delcypher created this revision.Jun 26 2020, 4:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2020, 4:40 PM
Herald added subscribers: Restricted Project, kristof.beyls. · View Herald Transcript
delcypher edited the summary of this revision. (Show Details)Jun 26 2020, 5:00 PM
yln accepted this revision.Jun 29 2020, 9:26 AM

Thanks!

This revision is now accepted and ready to land.Jun 29 2020, 9:26 AM
This revision was automatically updated to reflect the committed changes.