[llvm] [HWASan][bugfix] Fix kernel check in ShadowMapping::init (PR #142226)
Usama Hameed via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 15:33:34 PDT 2025
https://github.com/usama54321 created https://github.com/llvm/llvm-project/pull/142226
The function currently checks for the command line argument only to check if compiling for kernel. This is incorrect as the setting can also be passed programatically.
>From 2ceff796262d7df63e6804c4150795ba29e41a6d Mon Sep 17 00:00:00 2001
From: usama <u_hameed at apple.com>
Date: Fri, 30 May 2025 15:31:25 -0700
Subject: [PATCH] [HWASan][bugfix] Fix kernel check in ShadowMapping::init
The function currently checks for the command line argument only to
check if compiling for kernel. This is incorrect as the setting can also
be passed programatically.
---
.../Transforms/Instrumentation/HWAddressSanitizer.cpp | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index e81a725c62ead..77db686f8229c 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -419,7 +419,8 @@ class HWAddressSanitizer {
}
public:
- void init(Triple &TargetTriple, bool InstrumentWithCalls);
+ void init(Triple &TargetTriple, bool InstrumentWithCalls,
+ bool CompileKernel);
Align getObjectAlignment() const { return Align(1ULL << Scale); }
bool isInGlobal() const { return Kind == OffsetKind::kGlobal; }
bool isInIfunc() const { return Kind == OffsetKind::kIfunc; }
@@ -642,7 +643,7 @@ void HWAddressSanitizer::initializeModule() {
PointerTagShift = IsX86_64 ? 57 : 56;
TagMaskByte = IsX86_64 ? 0x3F : 0xFF;
- Mapping.init(TargetTriple, InstrumentWithCalls);
+ Mapping.init(TargetTriple, InstrumentWithCalls, CompileKernel);
C = &(M.getContext());
IRBuilder<> IRB(*C);
@@ -1874,7 +1875,8 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
}
void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
- bool InstrumentWithCalls) {
+ bool InstrumentWithCalls,
+ bool CompileKernel) {
// Start with defaults.
Scale = kDefaultShadowScale;
Kind = OffsetKind::kTls;
@@ -1885,7 +1887,7 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
// Fuchsia is always PIE, which means that the beginning of the address
// space is always available.
SetFixed(0);
- } else if (ClEnableKhwasan || InstrumentWithCalls) {
+ } else if (CompileKernel || InstrumentWithCalls) {
SetFixed(0);
WithFrameRecord = false;
}
More information about the llvm-commits
mailing list