Skip to content

Commit 85ccfb5

Browse files
authored
[HWASan] [NFC] pull logic to get sanitizer ptr out of hwasan (#86024)
Also some drive by cleanup removing an unnnecessary argument and a redundant condition.
1 parent 536cb1f commit 85ccfb5

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ bool isLifetimeIntrinsic(Value *V);
8484
Value *readRegister(IRBuilder<> &IRB, StringRef Name);
8585
Value *getFP(IRBuilder<> &IRB);
8686
Value *getPC(const Triple &TargetTriple, IRBuilder<> &IRB);
87+
Value *getAndroidSanitizerSlotPtr(IRBuilder<> &IRB);
8788

8889
} // namespace memtag
8990
} // namespace llvm

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class HWAddressSanitizer {
363363
Value *getAllocaTag(IRBuilder<> &IRB, Value *StackTag, unsigned AllocaNo);
364364
Value *getUARTag(IRBuilder<> &IRB);
365365

366-
Value *getHwasanThreadSlotPtr(IRBuilder<> &IRB, Type *Ty);
366+
Value *getHwasanThreadSlotPtr(IRBuilder<> &IRB);
367367
Value *applyTagMask(IRBuilder<> &IRB, Value *OldTag);
368368
unsigned retagMask(unsigned AllocaNo);
369369

@@ -1219,20 +1219,10 @@ Value *HWAddressSanitizer::untagPointer(IRBuilder<> &IRB, Value *PtrLong) {
12191219
return UntaggedPtrLong;
12201220
}
12211221

1222-
Value *HWAddressSanitizer::getHwasanThreadSlotPtr(IRBuilder<> &IRB, Type *Ty) {
1223-
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1224-
if (TargetTriple.isAArch64() && TargetTriple.isAndroid()) {
1225-
// Android provides a fixed TLS slot for sanitizers. See TLS_SLOT_SANITIZER
1226-
// in Bionic's libc/private/bionic_tls.h.
1227-
Function *ThreadPointerFunc =
1228-
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
1229-
return IRB.CreateConstGEP1_32(Int8Ty, IRB.CreateCall(ThreadPointerFunc),
1230-
0x30);
1231-
}
1232-
if (ThreadPtrGlobal)
1233-
return ThreadPtrGlobal;
1234-
1235-
return nullptr;
1222+
Value *HWAddressSanitizer::getHwasanThreadSlotPtr(IRBuilder<> &IRB) {
1223+
if (TargetTriple.isAArch64() && TargetTriple.isAndroid())
1224+
return memtag::getAndroidSanitizerSlotPtr(IRB);
1225+
return ThreadPtrGlobal;
12361226
}
12371227

12381228
Value *HWAddressSanitizer::getCachedFP(IRBuilder<> &IRB) {
@@ -1271,7 +1261,7 @@ void HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord) {
12711261

12721262
auto getThreadLongMaybeUntagged = [&]() {
12731263
if (!SlotPtr)
1274-
SlotPtr = getHwasanThreadSlotPtr(IRB, IntptrTy);
1264+
SlotPtr = getHwasanThreadSlotPtr(IRB);
12751265
if (!ThreadLong)
12761266
ThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
12771267
// Extract the address field from ThreadLong. Unnecessary on AArch64 with

llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,15 @@ Value *getFP(IRBuilder<> &IRB) {
273273
IRB.getIntPtrTy(M->getDataLayout()));
274274
}
275275

276+
Value *getAndroidSanitizerSlotPtr(IRBuilder<> &IRB) {
277+
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
278+
// Android provides a fixed TLS slot for sanitizers. See TLS_SLOT_SANITIZER
279+
// in Bionic's libc/private/bionic_tls.h.
280+
Function *ThreadPointerFunc =
281+
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
282+
return IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
283+
IRB.CreateCall(ThreadPointerFunc), 0x30);
284+
}
285+
276286
} // namespace memtag
277287
} // namespace llvm

0 commit comments

Comments
 (0)