Skip to content

Commit 0673642

Browse files
authored
[hwasan] Replace "-hwasan-with-ifunc" and "-hwasan-with-tls" options (#109619)
Relationship between "-hwasan-mapping-offset", "-hwasan-with-ifunc", and "-hwasan-with-tls" can be to hard to understand. Now we will have "-hwasan-mapping-offset", presense of which will imply fixed shadow. If "-hwasan-mapping-offset-dynamic" will set one of 3 available dynamic shadows. As-is "-hwasan-mapping-offset" has precedence over "-hwasan-mapping-offset-dynamic". In follow up patches we need to use the one with last occurrence.
1 parent 0062975 commit 0673642

File tree

6 files changed

+30
-35
lines changed

6 files changed

+30
-35
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ static const size_t kDefaultShadowScale = 4;
8686

8787
static const unsigned kShadowBaseAlignment = 32;
8888

89+
namespace {
90+
enum class OffsetKind {
91+
kFixed = 0,
92+
kGlobal,
93+
kIfunc,
94+
kTls,
95+
};
96+
}
97+
8998
static cl::opt<std::string>
9099
ClMemoryAccessCallbackPrefix("hwasan-memory-access-callback-prefix",
91100
cl::desc("Prefix for memory access callbacks"),
@@ -169,19 +178,14 @@ static cl::opt<bool>
169178
static cl::opt<uint64_t>
170179
ClMappingOffset("hwasan-mapping-offset",
171180
cl::desc("HWASan shadow mapping offset [EXPERIMENTAL]"),
172-
cl::Hidden, cl::init(0));
181+
cl::Hidden);
173182

174-
static cl::opt<bool>
175-
ClWithIfunc("hwasan-with-ifunc",
176-
cl::desc("Access dynamic shadow through an ifunc global on "
177-
"platforms that support this"),
178-
cl::Hidden, cl::init(false));
179-
180-
static cl::opt<bool> ClWithTls(
181-
"hwasan-with-tls",
182-
cl::desc("Access dynamic shadow through an thread-local pointer on "
183-
"platforms that support this"),
184-
cl::Hidden, cl::init(true));
183+
static cl::opt<OffsetKind> ClMappingOffsetDynamic(
184+
"hwasan-mapping-offset-dynamic",
185+
cl::desc("HWASan shadow mapping dynamic offset location"), cl::Hidden,
186+
cl::values(clEnumValN(OffsetKind::kGlobal, "global", "Use global"),
187+
clEnumValN(OffsetKind::kIfunc, "ifunc", "Use ifunc global"),
188+
clEnumValN(OffsetKind::kTls, "tls", "Use TLS")));
185189

186190
static cl::opt<int> ClHotPercentileCutoff("hwasan-percentile-cutoff-hot",
187191
cl::desc("Hot percentile cuttoff."));
@@ -398,12 +402,6 @@ class HWAddressSanitizer {
398402
/// If WithFrameRecord is true, then __hwasan_tls will be used to access the
399403
/// ring buffer for storing stack allocations on targets that support it.
400404
class ShadowMapping {
401-
enum class OffsetKind {
402-
kFixed = 0,
403-
kGlobal,
404-
kIfunc,
405-
kTls,
406-
};
407405
OffsetKind Kind;
408406
uint64_t Offset;
409407
uint8_t Scale;
@@ -1940,11 +1938,8 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
19401938
} else if (ClEnableKhwasan || InstrumentWithCalls) {
19411939
SetFixed(0);
19421940
WithFrameRecord = false;
1943-
} else if (ClWithIfunc) {
1944-
Kind = OffsetKind::kIfunc;
1945-
WithFrameRecord = false;
1946-
} else if (!ClWithTls) {
1947-
Kind = OffsetKind::kGlobal;
1948-
WithFrameRecord = false;
1941+
} else if (ClMappingOffsetDynamic.getNumOccurrences() > 0) {
1942+
Kind = ClMappingOffsetDynamic;
1943+
WithFrameRecord = isInTls();
19491944
}
19501945
}

llvm/test/Instrumentation/HWAddressSanitizer/RISCV/alloca.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; Test alloca instrumentation. Command line includes check-globals so that
33
; changes to debug-info are detectable.
44
;
5-
; RUN: opt < %s -passes=hwasan -hwasan-with-ifunc=1 -S | FileCheck %s --check-prefixes=DYNAMIC-SHADOW
5+
; RUN: opt < %s -passes=hwasan -hwasan-mapping-offset-dynamic=ifunc -S | FileCheck %s --check-prefixes=DYNAMIC-SHADOW
66
; RUN: opt < %s -passes=hwasan -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=ZERO-BASED-SHADOW
77

88
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"

llvm/test/Instrumentation/HWAddressSanitizer/RISCV/basic.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
; RUN: opt < %s -passes=hwasan -S | FileCheck %s
55
; RUN: opt < %s -passes=hwasan -hwasan-inline-fast-path-checks=0 -S | FileCheck %s --check-prefixes=NOFASTPATH
66
; RUN: opt < %s -passes=hwasan -hwasan-inline-fast-path-checks=1 -S | FileCheck %s --check-prefixes=FASTPATH
7-
; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=ABORT-DYNAMIC-SHADOW
8-
; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=RECOVER-DYNAMIC-SHADOW
7+
; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-mapping-offset-dynamic=ifunc -S | FileCheck %s --check-prefixes=ABORT-DYNAMIC-SHADOW
8+
; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-mapping-offset-dynamic=ifunc -S | FileCheck %s --check-prefixes=RECOVER-DYNAMIC-SHADOW
99
; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=ABORT-ZERO-BASED-SHADOW
1010
; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=RECOVER-ZERO-BASED-SHADOW
1111

llvm/test/Instrumentation/HWAddressSanitizer/alloca.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
; Test alloca instrumentation. Command line includes check-globals so that
33
; changes to debug-info are detectable.
44
;
5-
; RUN: opt < %s -passes=hwasan -hwasan-with-ifunc=1 -S | FileCheck %s --check-prefixes=DYNAMIC-SHADOW
5+
; RUN: opt < %s -passes=hwasan -hwasan-mapping-offset-dynamic=ifunc -S | FileCheck %s --check-prefixes=DYNAMIC-SHADOW
66
; RUN: opt < %s -passes=hwasan -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=ZERO-BASED-SHADOW
77

8-
; RUN: opt < %s -passes=hwasan -hwasan-with-ifunc=1 -S --try-experimental-debuginfo-iterators | FileCheck %s --check-prefixes=DYNAMIC-SHADOW
8+
; RUN: opt < %s -passes=hwasan -hwasan-mapping-offset-dynamic=ifunc -S --try-experimental-debuginfo-iterators | FileCheck %s --check-prefixes=DYNAMIC-SHADOW
99
; RUN: opt < %s -passes=hwasan -hwasan-mapping-offset=0 -S --try-experimental-debuginfo-iterators | FileCheck %s --check-prefixes=ZERO-BASED-SHADOW
1010

1111
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"

llvm/test/Instrumentation/HWAddressSanitizer/basic.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
; RUN: opt < %s -passes=hwasan -S | FileCheck %s
55
; RUN: opt < %s -passes=hwasan -hwasan-inline-fast-path-checks=0 -S | FileCheck %s --check-prefixes=NOFASTPATH
66
; RUN: opt < %s -passes=hwasan -hwasan-inline-fast-path-checks=1 -S | FileCheck %s --check-prefixes=FASTPATH
7-
; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=ABORT-DYNAMIC-SHADOW
8-
; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=RECOVER-DYNAMIC-SHADOW
7+
; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-mapping-offset-dynamic=ifunc -S | FileCheck %s --check-prefixes=ABORT-DYNAMIC-SHADOW
8+
; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-mapping-offset-dynamic=ifunc -S | FileCheck %s --check-prefixes=RECOVER-DYNAMIC-SHADOW
99
; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=ABORT-ZERO-BASED-SHADOW
1010
; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=RECOVER-ZERO-BASED-SHADOW
1111

llvm/test/Instrumentation/HWAddressSanitizer/prologue.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
;
44
; RUN: opt -passes=hwasan -S < %s | \
55
; RUN: FileCheck %s
6-
; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=0 -hwasan-with-tls=1 -hwasan-record-stack-history=instr < %s | \
6+
; RUN: opt -passes=hwasan -S -hwasan-mapping-offset-dynamic=tls -hwasan-record-stack-history=instr < %s | \
77
; RUN: FileCheck %s --check-prefixes=NOIFUNC-TLS-HISTORY
8-
; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=0 -hwasan-with-tls=1 -hwasan-record-stack-history=none < %s | \
8+
; RUN: opt -passes=hwasan -S -hwasan-mapping-offset-dynamic=tls -hwasan-record-stack-history=none < %s | \
99
; RUN: FileCheck %s --check-prefixes=NOIFUNC-TLS-NOHISTORY
10-
; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=0 -hwasan-with-tls=0 < %s | \
10+
; RUN: opt -passes=hwasan -S -hwasan-mapping-offset-dynamic=global < %s | \
1111
; RUN: FileCheck %s --check-prefixes=NOIFUNC-NOTLS
12-
; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=1 -hwasan-with-tls=0 < %s | \
12+
; RUN: opt -passes=hwasan -S -hwasan-mapping-offset-dynamic=ifunc < %s | \
1313
; RUN: FileCheck %s --check-prefixes=IFUNC-NOTLS
1414
; RUN: opt -passes=hwasan -S -mtriple=aarch64-fuchsia < %s | \
1515
; RUN: FileCheck %s --check-prefixes=FUCHSIA

0 commit comments

Comments
 (0)