This is an archive of the discontinued LLVM Phabricator instance.

[asan] Use proper shadow offset for loongarch64 in instrumentation passes
ClosedPublic

Authored by tangyouling on Oct 29 2022, 1:54 AM.

Details

Summary

Instrumentation passes now use the proper shadow offset. There will be many
asan test failures without this patch. For example:

$ ./lib/asan/tests/LOONGARCH64LinuxConfig/Asan-loongarch64-calls-Test
AddressSanitizer:DEADLYSIGNAL
=================================================================
==651209==ERROR: AddressSanitizer: SEGV on unknown address 0x1ffffe2dfa9b (pc 0x5555585e151c bp 0x7ffffb9ec070 sp 0x7ffffb9ebfd0 T0)
==651209==The signal is caused by a UNKNOWN memory access.

Before the patch:

$ make check-asan
Testing Time: 36.13s
  Unsupported      : 205
  Passed           :  83
  Expectedly Failed:   1
  Failed           : 239

After the patch:

$ make check-asan
Testing Time: 58.98s
  Unsupported      : 205
  Passed           : 421
  Expectedly Failed:   1
  Failed           :  89

Depends on D137012

Diff Detail

Event Timeline

tangyouling created this revision.Oct 29 2022, 1:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2022, 1:54 AM
tangyouling requested review of this revision.Oct 29 2022, 1:54 AM
xen0n added inline comments.Oct 29 2022, 2:02 AM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
109

I might be missing on something, how is the offset value derived?

tangyouling added inline comments.Oct 29 2022, 2:05 AM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
109

I might be missing on something, how is the offset value derived?

in compiler-rt/lib/asan/asan_mapping.h,

// Default Linux/LoongArch64 (47-bit VMA) mapping:
// || `[0x500000000000, 0x7fffffffffff]` || HighMem    ||
// || `[0x4a0000000000, 0x4fffffffffff]` || HighShadow ||
// || `[0x480000000000, 0x49ffffffffff]` || ShadowGap  ||
// || `[0x400000000000, 0x47ffffffffff]` || LowShadow  ||
// || `[0x000000000000, 0x3fffffffffff]` || LowMem     ||

We're going to get an offset for LowShadow

xry111 added inline comments.Oct 29 2022, 2:23 AM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
579–580

"ppc64" -> "ppc64 and loongarch64"

585

Hmm, why is "!IsRISCV64" ever here? Shouldn't it be already excluded by !(Mapping.Offset & (Mapping.Offset - 1))?

But this is not related to our change anyway.

tangyouling added inline comments.Oct 30 2022, 6:05 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
579–580

"ppc64" -> "ppc64 and loongarch64"

OK.

585

Hmm, why is "!IsRISCV64" ever here? Shouldn't it be already excluded by !(Mapping.Offset & (Mapping.Offset - 1))?

But this is not related to our change anyway.

Feel unnecessary, Mapping.Offset is 0xd55550000 for RISCV64.

tangyouling retitled this revision from [LoongArch][ASAN] Instrumentation pass now uses proper shadow offset to [asan] Instrumentation pass now uses proper shadow offset.Oct 30 2022, 6:13 PM
tangyouling edited the summary of this revision. (Show Details)
tangyouling added a reviewer: Restricted Project.
tangyouling retitled this revision from [asan] Instrumentation pass now uses proper shadow offset to [asan] Instrumentation pass now uses proper shadow offset for loongarch64.Oct 30 2022, 6:32 PM
MaskRay accepted this revision.Oct 31 2022, 3:20 PM
This revision is now accepted and ready to land.Oct 31 2022, 3:20 PM

Add loongarch64 comment.

xen0n retitled this revision from [asan] Instrumentation pass now uses proper shadow offset for loongarch64 to [asan] Use proper shadow offset for loongarch64 in instrumentation passes.Oct 31 2022, 7:44 PM
xen0n edited the summary of this revision. (Show Details)
xen0n added a comment.Oct 31 2022, 7:47 PM

I've lightly edited the patch summary to fix some grammatical nits. Please check it out so you'll write better commit messages next time and not need such touching ;-)

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

Nit, since you've touched this line: not necessarily.

"necessary" --> "necessarily".

I've lightly edited the patch summary to fix some grammatical nits. Please check it out so you'll write better commit messages next time and not need such touching ;-)

Thanks :)

SixWeining accepted this revision.Nov 1 2022, 5:55 AM