This is an archive of the discontinued LLVM Phabricator instance.

[ASan] Disable dynamic alloca and UAR detection in presence of returns_twice calls.
ClosedPublic

Authored by samsonov on Jul 24 2015, 2:09 PM.

Details

Summary

returns_twice (most importantly, setjmp) functions are
optimization-hostile: if local variable is promoted to register, and is
changed between setjmp() and longjmp() calls, this update will be
undone. This is the reason why "man setjmp" advises to mark all these
locals as "volatile".

This can not be enough for ASan, though: when it replaces static alloca
with dynamic one, optionally called if UAR mode is enabled, it adds a
whole lot of SSA values, and computations of local variable addresses,
that can involve virtual registers, and cause unexpected behavior, when
these registers are restored from buffer saved in setjmp.

To fix this, just disable dynamic alloca and UAR tricks whenever we see
a returns_twice call in the function.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 30605.Jul 24 2015, 2:09 PM
samsonov retitled this revision from to [ASan] Disable dynamic alloca and UAR detection in presence of returns_twice calls..
samsonov updated this object.
samsonov added a reviewer: rnk.
samsonov added subscribers: kcc, llvm-commits.
rnk added inline comments.Jul 27 2015, 11:42 AM
lib/Transforms/Instrumentation/AddressSanitizer.cpp
685

It is possible to invoke setjmp, so you should change this to visitCallSite(CallSite CS) to handle both.

samsonov updated this revision to Diff 30854.Jul 28 2015, 1:59 PM
  • Use "visitCallSite" to handle both call and invoke.
samsonov marked an inline comment as done.Jul 28 2015, 1:59 PM
samsonov added inline comments.
lib/Transforms/Instrumentation/AddressSanitizer.cpp
685

Done

kcc accepted this revision.Jul 29 2015, 11:21 AM
kcc added a reviewer: kcc.

LGTM

This revision is now accepted and ready to land.Jul 29 2015, 11:21 AM
This revision was automatically updated to reflect the committed changes.
samsonov marked an inline comment as done.