Skip to content

Commit 3c8560d

Browse files
usama54321DhruvSrivastavaX
authored andcommitted
[HWASan][bugfix] Fix kernel check in ShadowMapping::init (llvm#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.
1 parent aa58366 commit 3c8560d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ class HWAddressSanitizer {
419419
}
420420

421421
public:
422-
void init(Triple &TargetTriple, bool InstrumentWithCalls);
422+
void init(Triple &TargetTriple, bool InstrumentWithCalls,
423+
bool CompileKernel);
423424
Align getObjectAlignment() const { return Align(1ULL << Scale); }
424425
bool isInGlobal() const { return Kind == OffsetKind::kGlobal; }
425426
bool isInIfunc() const { return Kind == OffsetKind::kIfunc; }
@@ -642,7 +643,7 @@ void HWAddressSanitizer::initializeModule() {
642643
PointerTagShift = IsX86_64 ? 57 : 56;
643644
TagMaskByte = IsX86_64 ? 0x3F : 0xFF;
644645

645-
Mapping.init(TargetTriple, InstrumentWithCalls);
646+
Mapping.init(TargetTriple, InstrumentWithCalls, CompileKernel);
646647

647648
C = &(M.getContext());
648649
IRBuilder<> IRB(*C);
@@ -1874,7 +1875,8 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
18741875
}
18751876

18761877
void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
1877-
bool InstrumentWithCalls) {
1878+
bool InstrumentWithCalls,
1879+
bool CompileKernel) {
18781880
// Start with defaults.
18791881
Scale = kDefaultShadowScale;
18801882
Kind = OffsetKind::kTls;
@@ -1885,7 +1887,7 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
18851887
// Fuchsia is always PIE, which means that the beginning of the address
18861888
// space is always available.
18871889
SetFixed(0);
1888-
} else if (ClEnableKhwasan || InstrumentWithCalls) {
1890+
} else if (CompileKernel || InstrumentWithCalls) {
18891891
SetFixed(0);
18901892
WithFrameRecord = false;
18911893
}

0 commit comments

Comments
 (0)