This is an archive of the discontinued LLVM Phabricator instance.

[llvm][hwasan] Decouple use of the TLS global for getting the shadow base and using the frame record feature
ClosedPublic

Authored by leonardchan on Jun 7 2021, 2:00 PM.

Details

Summary

This allows for using the frame record feature (which uses __hwasan_tls) independently from however the user wants to access the shadow base, which prior was only usable if shadow wasn't accessed through the TLS variable or ifuncs.

Frame recording can be explicitly set according to ShadowMapping::WithFrameRecord in ShadowMapping::init. Currently, it is only enabled on Fuchsia and if TLS is used, so this should mimic the old behavior.

Added an extra case to prologue.ll that covers this new case.

Diff Detail

Event Timeline

leonardchan created this revision.Jun 7 2021, 2:00 PM
leonardchan requested review of this revision.Jun 7 2021, 2:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2021, 2:00 PM
leonardchan retitled this revision from [compiler-rt][hwasan] Decouple use of the TLS global for getting the shadow base and using the frame record feature to [llvm][hwasan] Decouple use of the TLS global for getting the shadow base and using the frame record feature .Jun 7 2021, 3:38 PM
leonardchan removed a subscriber: cfe-commits.
vitalybuka accepted this revision.Jun 8 2021, 10:19 AM
vitalybuka added 1 blocking reviewer(s): eugenis.
eugenis added inline comments.
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
1050

I think this will break Linux kernel build.
They use -fsanitize=kernel-hwaddress with one of

-hwasan-instrument-with-calls=1

or

-hwasan-mapping-offset=

The assumption here is that InTls == 0 means there is no thread slot, and therefore no frame recording.

leonardchan added inline comments.Jun 8 2021, 12:20 PM
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
1050

Perhaps we could set the default value of -hwasan-record-stack-history to false so users who don't expect frame recording don't suddenly see TLS being used? It would mean people who do use frame recording won't see it anymore and will need to manually add -hwasan-record-stack-history=1, but maybe that won't break existing users.

eugenis added inline comments.Jun 8 2021, 12:34 PM
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
1050

These are internal compiler flags, they should not have users, ideally. The right thing should happen based on -fsanitize flag and the target triple, and the right thing in this case is to enable frame recording on supported platforms.

I'd rather put this check under InTls, or add something like ShadowMapping::WithFrameRecord and make the decision in ShadowMapping::init.

leonardchan edited the summary of this revision. (Show Details)
leonardchan added inline comments.
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
1050

Updated to add ShadowMapping::WithFrameRecord.

eugenis accepted this revision.Jun 9 2021, 12:26 PM

LGTM with a nit

llvm/test/Instrumentation/HWAddressSanitizer/prologue.ll
30

CHECK-ZERO-OFFSET is never used

This revision is now accepted and ready to land.Jun 9 2021, 12:26 PM
leonardchan added inline comments.
llvm/test/Instrumentation/HWAddressSanitizer/prologue.ll
30

Woops. Meant to add a RUN case for testing a fuchsia target which should use this. Updated.

This revision was landed with ongoing or failed builds.Jun 9 2021, 12:55 PM
This revision was automatically updated to reflect the committed changes.