This is an archive of the discontinued LLVM Phabricator instance.

[asan] Fix shadow load alignment for unaligned 128-bit load/store
ClosedPublic

Authored by MaskRay on Jun 11 2023, 6:38 PM.

Details

Summary

When a 128-bit load/store is aligned by 8, we incorrectly emit load i16, ptr ..., align 2
while the shadow memory address may not be aligned by 2.

This manifests as possibly-misaligned shadow memory load with -mstrict-align,
e.g. clang --target=aarch64-linux -O2 -mstrict-align -fsanitize=address

__attribute__((noinline)) void foo(unsigned long *ptr) {
  ptr[0] = 3;
  ptr[1] = 3;
}
// ldrh    w8, [x9, x8]  // the shadow memory load may not be aligned by 2

Infer the shadow memory alignment from the load/store alignment to set the
correct alignment. The generated code now uses two ldrb and one orr.

Fix https://github.com/llvm/llvm-project/issues/63258

Diff Detail

Event Timeline

MaskRay created this revision.Jun 11 2023, 6:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2023, 6:38 PM
MaskRay requested review of this revision.Jun 11 2023, 6:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2023, 6:38 PM
MaskRay updated this revision to Diff 530385.Jun 11 2023, 10:29 PM
MaskRay edited the summary of this revision. (Show Details)

improve code

vit9696 accepted this revision.Jun 12 2023, 4:23 AM
vit9696 added a subscriber: vit9696.

Hi @MaskRay, I applied your patch on top of 15.0.7 and can confirm that it does fix the immediate issue. I will perform more extensive tests as time permits.

Thank you for such a instant patch :-)

This revision is now accepted and ready to land.Jun 12 2023, 4:23 AM
This revision was landed with ongoing or failed builds.Jun 14 2023, 1:17 PM
This revision was automatically updated to reflect the committed changes.
MaskRay edited the summary of this revision. (Show Details)Jun 14 2023, 1:30 PM