diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1531,7 +1531,13 @@ 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 --- /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 +}