This is an archive of the discontinued LLVM Phabricator instance.

[asan] Prevent rematerialization of &__asan_shadow.
ClosedPublic

Authored by eugenis on Nov 14 2017, 1:25 PM.

Details

Summary

In the mode when ASan shadow base is computed as the address of an
external global (__asan_shadow, currently on android/arm32 only),
regalloc prefers to rematerialize this value to save register spills.
Even in -Os. On arm32 it is rather expensive (2 loads + 1 constant
pool entry).

This changes adds an inline asm in the function prologue to suppress
this behavior. It reduces AsanTest binary size by 7%.

Event Timeline

eugenis created this revision.Nov 14 2017, 1:25 PM
pcc added inline comments.Nov 14 2017, 1:37 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
216

Does this need to be a flag? Could we instead do this only on arm32?

eugenis added inline comments.Nov 14 2017, 2:02 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
216

Flag is useful for benchmarking and also as a way to disable this feature if something goes wrong. We already do this only on android/arm32.

pcc accepted this revision.Nov 14 2017, 2:30 PM

LGTM

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
216

Please at least remember to remove this flag once you know that it works well.

This revision is now accepted and ready to land.Nov 14 2017, 2:30 PM
This revision was automatically updated to reflect the committed changes.