[asan] Prevent rematerialization of &__asan_shadow.
ClosedPublic

Authored by eugenis on Tue, Nov 14, 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%.

Diff Detail

Repository
rL LLVM
eugenis created this revision.Tue, Nov 14, 1:25 PM
pcc added inline comments.Tue, Nov 14, 1:37 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
216 ↗(On Diff #122902)

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

eugenis added inline comments.Tue, Nov 14, 2:02 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
216 ↗(On Diff #122902)

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.Tue, Nov 14, 2:30 PM

LGTM

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
216 ↗(On Diff #122902)

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

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