diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 07892bdc854bd..04761f0d89f0b 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1531,7 +1531,13 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() { void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple, bool InstrumentWithCalls) { Scale = kDefaultShadowScale; - if (ClMappingOffset.getNumOccurrences() > 0) { + if (TargetTriple.isOSFuchsia()) { + // Fuchsia is always PIE, which means that the beginning of the address + // space is always available. + InGlobal = false; + InTls = false; + Offset = 0; + } else if (ClMappingOffset.getNumOccurrences() > 0) { InGlobal = false; InTls = false; Offset = ClMappingOffset; diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/fuchsia.ll b/llvm/test/Instrumentation/HWAddressSanitizer/fuchsia.ll new file mode 100644 index 0000000000000..9005830008359 --- /dev/null +++ b/llvm/test/Instrumentation/HWAddressSanitizer/fuchsia.ll @@ -0,0 +1,9 @@ +; Check HWASan shadow mapping on Fuchsia. +; RUN: opt -hwasan -S -mtriple=aarch64-unknown-fuchsia < %s | FileCheck %s + +define i32 @test_load(i32* %a) sanitize_hwaddress { +; CHECK: %.hwasan.shadow = call i8* asm "", "=r,0"(i8* null) +entry: + %x = load i32, i32* %a, align 4 + ret i32 %x +}