aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2018-08-10 16:21:37 +0000
committerStephen Hines <srhines@google.com>2018-09-09 23:33:33 -0700
commit5a7dea1cd9443cac2fc88e243a5b4500229d3d68 (patch)
tree504a905d3a39db572abba0801e7399db562aeaf8
parent5fe0d00d26b61b04e8b320f0a89773f912cb5c79 (diff)
downloadllvm-5a7dea1cd9443cac2fc88e243a5b4500229d3d68.tar.gz
[hwasan] Add -hwasan-with-ifunc flag.
Summary: Similar to asan's flag, it can be used to disable the use of ifunc to access hwasan shadow address. Reviewers: vitalybuka, kcc Subscribers: srhines, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D50544 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339447 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Instrumentation/HWAddressSanitizer.cpp25
-rw-r--r--test/Instrumentation/HWAddressSanitizer/with-ifunc.ll30
2 files changed, 49 insertions, 6 deletions
diff --git a/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index d62598bb5d4..bc690ccd5cd 100644
--- a/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -127,6 +127,11 @@ static cl::opt<unsigned long long> ClMappingOffset(
cl::desc("HWASan shadow mapping offset [EXPERIMENTAL]"), cl::Hidden,
cl::init(0));
+static cl::opt<bool>
+ ClWithIfunc("hwasan-with-ifunc",
+ cl::desc("Access dynamic shadow through an ifunc global on "
+ "platforms that support this"),
+ cl::Hidden, cl::init(false));
namespace {
/// An instrumentation pass implementing detection of addressability bugs
@@ -751,13 +756,21 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple) {
IsAndroid && !TargetTriple.isAndroidVersionLT(21);
Scale = kDefaultShadowScale;
+ const bool WithIfunc = ClWithIfunc.getNumOccurrences() > 0
+ ? ClWithIfunc
+ : IsAndroidWithIfuncSupport;
- if (ClEnableKhwasan || ClInstrumentWithCalls || !IsAndroidWithIfuncSupport)
+ if (ClMappingOffset.getNumOccurrences() > 0) {
+ InGlobal = false;
+ Offset = ClMappingOffset;
+ } else if (ClEnableKhwasan || ClInstrumentWithCalls) {
+ InGlobal = false;
Offset = 0;
- else
+ } else if (WithIfunc) {
+ InGlobal = true;
Offset = kDynamicShadowSentinel;
- if (ClMappingOffset.getNumOccurrences() > 0)
- Offset = ClMappingOffset;
-
- InGlobal = IsAndroidWithIfuncSupport;
+ } else {
+ InGlobal = false;
+ Offset = kDynamicShadowSentinel;
+ }
}
diff --git a/test/Instrumentation/HWAddressSanitizer/with-ifunc.ll b/test/Instrumentation/HWAddressSanitizer/with-ifunc.ll
new file mode 100644
index 00000000000..2f4abb49b29
--- /dev/null
+++ b/test/Instrumentation/HWAddressSanitizer/with-ifunc.ll
@@ -0,0 +1,30 @@
+; Test -hwasan-with-ifunc flag.
+;
+; RUN: opt -hwasan -S < %s | \
+; RUN: FileCheck %s --check-prefixes=CHECK,CHECK-IFUNC
+; RUN: opt -hwasan -S -hwasan-with-ifunc=0 < %s | \
+; RUN: FileCheck %s --check-prefixes=CHECK,CHECK-NOIFUNC
+; RUN: opt -hwasan -S -hwasan-with-ifunc=1 < %s | \
+; RUN: FileCheck %s --check-prefixes=CHECK,CHECK-IFUNC
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64--linux-android22"
+
+; CHECK-IFUNC: @__hwasan_shadow = external global [0 x i8]
+; CHECK-NOIFUNC: @__hwasan_shadow_memory_dynamic_address = external global i64
+
+define i32 @test_load(i32* %a) sanitize_hwaddress {
+; First instrumentation in the function must be to load the dynamic shadow
+; address into a local variable.
+; CHECK-LABEL: @test_load
+; CHECK: entry:
+
+; CHECK-IFUNC: %[[A:[^ ]*]] = call i64 asm "", "=r,0"([0 x i8]* @__hwasan_shadow)
+; CHECK-IFUNC: add i64 %{{.*}}, %[[A]]
+
+; CHECK-NOIFUNC: load i64, i64* @__hwasan_shadow_memory_dynamic_address
+
+entry:
+ %x = load i32, i32* %a, align 4
+ ret i32 %x
+}