Skip to content

Commit

Permalink
[NFC] [HWASan] make getAndroidSlotPtr function generic (llvm#86200)
Browse files Browse the repository at this point in the history
This is so we can use a different slot for stack MTE.
  • Loading branch information
fmayer authored Mar 26, 2024
1 parent b0b8b16 commit 880eb33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool isLifetimeIntrinsic(Value *V);
Value *readRegister(IRBuilder<> &IRB, StringRef Name);
Value *getFP(IRBuilder<> &IRB);
Value *getPC(const Triple &TargetTriple, IRBuilder<> &IRB);
Value *getAndroidSanitizerSlotPtr(IRBuilder<> &IRB);
Value *getAndroidSlotPtr(IRBuilder<> &IRB, int Slot);

} // namespace memtag
} // namespace llvm
Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,11 @@ Value *HWAddressSanitizer::untagPointer(IRBuilder<> &IRB, Value *PtrLong) {
}

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

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ Value *getFP(IRBuilder<> &IRB) {
IRB.getIntPtrTy(M->getDataLayout()));
}

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

} // namespace memtag
Expand Down

0 comments on commit 880eb33

Please sign in to comment.