Skip to content

Commit 880eb33

Browse files
authored
[NFC] [HWASan] make getAndroidSlotPtr function generic (#86200)
This is so we can use a different slot for stack MTE.
1 parent b0b8b16 commit 880eb33

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +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);
87+
Value *getAndroidSlotPtr(IRBuilder<> &IRB, int Slot);
8888

8989
} // namespace memtag
9090
} // namespace llvm

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,11 @@ Value *HWAddressSanitizer::untagPointer(IRBuilder<> &IRB, Value *PtrLong) {
12221222
}
12231223

12241224
Value *HWAddressSanitizer::getHwasanThreadSlotPtr(IRBuilder<> &IRB) {
1225+
// Android provides a fixed TLS slot for sanitizers. See TLS_SLOT_SANITIZER
1226+
// in Bionic's libc/platform/bionic/tls_defines.h.
1227+
constexpr int SanitizerSlot = 6;
12251228
if (TargetTriple.isAArch64() && TargetTriple.isAndroid())
1226-
return memtag::getAndroidSanitizerSlotPtr(IRB);
1229+
return memtag::getAndroidSlotPtr(IRB, SanitizerSlot);
12271230
return ThreadPtrGlobal;
12281231
}
12291232

llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

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

276-
Value *getAndroidSanitizerSlotPtr(IRBuilder<> &IRB) {
276+
Value *getAndroidSlotPtr(IRBuilder<> &IRB, int Slot) {
277277
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
278278
// Android provides a fixed TLS slot for sanitizers. See TLS_SLOT_SANITIZER
279279
// in Bionic's libc/private/bionic_tls.h.
280280
Function *ThreadPointerFunc =
281281
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
282282
return IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
283-
IRB.CreateCall(ThreadPointerFunc), 0x30);
283+
IRB.CreateCall(ThreadPointerFunc), 8 * Slot);
284284
}
285285

286286
} // namespace memtag

0 commit comments

Comments
 (0)