Skip to content

Commit 3313f28

Browse files
committed
Revert "[MTE] add stack frame history buffer"
This reverts commit 1f67f34.
1 parent 1f67f34 commit 3313f28

File tree

3 files changed

+2
-134
lines changed

3 files changed

+2
-134
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,8 +2500,7 @@ AArch64FrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
25002500
return resolveFrameIndexReference(
25012501
MF, FI, FrameReg,
25022502
/*PreferFP=*/
2503-
MF.getFunction().hasFnAttribute(Attribute::SanitizeHWAddress) ||
2504-
MF.getFunction().hasFnAttribute(Attribute::SanitizeMemTag),
2503+
MF.getFunction().hasFnAttribute(Attribute::SanitizeHWAddress),
25052504
/*ForSimm=*/false);
25062505
}
25072506

llvm/lib/Target/AArch64/AArch64StackTagging.cpp

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "AArch64InstrInfo.h"
1212
#include "AArch64Subtarget.h"
1313
#include "AArch64TargetMachine.h"
14-
#include "llvm/ADT/APInt.h"
1514
#include "llvm/ADT/MapVector.h"
1615
#include "llvm/ADT/SmallVector.h"
1716
#include "llvm/ADT/Statistic.h"
@@ -22,7 +21,6 @@
2221
#include "llvm/Analysis/ScalarEvolution.h"
2322
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
2423
#include "llvm/Analysis/StackSafetyAnalysis.h"
25-
#include "llvm/BinaryFormat/Dwarf.h"
2624
#include "llvm/CodeGen/LiveRegUnits.h"
2725
#include "llvm/CodeGen/MachineBasicBlock.h"
2826
#include "llvm/CodeGen/MachineFunction.h"
@@ -84,26 +82,6 @@ static cl::opt<size_t> ClMaxLifetimes(
8482
cl::desc("How many lifetime ends to handle for a single alloca."),
8583
cl::Optional);
8684

87-
// Mode for selecting how to insert frame record info into the stack ring
88-
// buffer.
89-
enum RecordStackHistoryMode {
90-
// Do not record frame record info.
91-
none,
92-
93-
// Insert instructions into the prologue for storing into the stack ring
94-
// buffer directly.
95-
instr,
96-
};
97-
98-
static cl::opt<RecordStackHistoryMode> ClRecordStackHistory(
99-
"stack-tagging-record-stack-history",
100-
cl::desc("Record stack frames with tagged allocations in a thread-local "
101-
"ring buffer"),
102-
cl::values(clEnumVal(none, "Do not record stack ring history"),
103-
clEnumVal(instr, "Insert instructions into the prologue for "
104-
"storing into the stack ring buffer")),
105-
cl::Hidden, cl::init(none));
106-
10785
static const Align kTagGranuleSize = Align(16);
10886

10987
namespace {
@@ -331,7 +309,6 @@ class AArch64StackTagging : public FunctionPass {
331309
uint64_t Size, InitializerBuilder &IB);
332310

333311
Instruction *insertBaseTaggedPointer(
334-
const Module &M,
335312
const MapVector<AllocaInst *, memtag::AllocaInfo> &Allocas,
336313
const DominatorTree *DT);
337314
bool runOnFunction(Function &F) override;
@@ -460,7 +437,6 @@ void AArch64StackTagging::untagAlloca(AllocaInst *AI, Instruction *InsertBefore,
460437
}
461438

462439
Instruction *AArch64StackTagging::insertBaseTaggedPointer(
463-
const Module &M,
464440
const MapVector<AllocaInst *, memtag::AllocaInfo> &AllocasToInstrument,
465441
const DominatorTree *DT) {
466442
BasicBlock *PrologueBB = nullptr;
@@ -482,41 +458,6 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
482458
Instruction *Base =
483459
IRB.CreateCall(IRG_SP, {Constant::getNullValue(IRB.getInt64Ty())});
484460
Base->setName("basetag");
485-
auto TargetTriple = Triple(M.getTargetTriple());
486-
// This is not a stable ABI for now, so only allow in dev builds with API
487-
// level 10000.
488-
// The ThreadLong format is the same as with HWASan, but the entries for
489-
// stack MTE take two slots (16 bytes).
490-
if (ClRecordStackHistory == instr && TargetTriple.isAndroid() &&
491-
TargetTriple.isAArch64() && !TargetTriple.isAndroidVersionLT(10000) &&
492-
!AllocasToInstrument.empty()) {
493-
constexpr int StackMteSlot = -3;
494-
constexpr uint64_t TagMask = 0xFULL << 56;
495-
496-
auto *IntptrTy = IRB.getIntPtrTy(M.getDataLayout());
497-
Value *SlotPtr = memtag::getAndroidSlotPtr(IRB, StackMteSlot);
498-
auto *ThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
499-
Value *TaggedFP = IRB.CreateOr(
500-
memtag::getFP(IRB),
501-
IRB.CreateAnd(IRB.CreatePtrToInt(Base, IntptrTy), TagMask));
502-
Value *PC = memtag::getPC(TargetTriple, IRB);
503-
Value *RecordPtr = IRB.CreateIntToPtr(ThreadLong, IRB.getPtrTy(0));
504-
IRB.CreateStore(PC, RecordPtr);
505-
IRB.CreateStore(TaggedFP, IRB.CreateConstGEP1_64(IntptrTy, RecordPtr, 1));
506-
// Update the ring buffer. Top byte of ThreadLong defines the size of the
507-
// buffer in pages, it must be a power of two, and the start of the buffer
508-
// must be aligned by twice that much. Therefore wrap around of the ring
509-
// buffer is simply Addr &= ~((ThreadLong >> 56) << 12).
510-
// The use of AShr instead of LShr is due to
511-
// https://bugs.llvm.org/show_bug.cgi?id=39030
512-
// Runtime library makes sure not to use the highest bit.
513-
Value *WrapMask = IRB.CreateXor(
514-
IRB.CreateShl(IRB.CreateAShr(ThreadLong, 56), 12, "", true, true),
515-
ConstantInt::get(IntptrTy, (uint64_t)-1));
516-
Value *ThreadLongNew = IRB.CreateAnd(
517-
IRB.CreateAdd(ThreadLong, ConstantInt::get(IntptrTy, 16)), WrapMask);
518-
IRB.CreateStore(ThreadLongNew, SlotPtr);
519-
}
520461
return Base;
521462
}
522463

@@ -572,8 +513,7 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
572513
SetTagFunc =
573514
Intrinsic::getDeclaration(F->getParent(), Intrinsic::aarch64_settag);
574515

575-
Instruction *Base =
576-
insertBaseTaggedPointer(*Fn.getParent(), SInfo.AllocasToInstrument, DT);
516+
Instruction *Base = insertBaseTaggedPointer(SInfo.AllocasToInstrument, DT);
577517

578518
int NextTag = 0;
579519
for (auto &I : SInfo.AllocasToInstrument) {
@@ -635,8 +575,6 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
635575
for (auto *II : Info.LifetimeEnd)
636576
II->eraseFromParent();
637577
}
638-
639-
memtag::annotateDebugRecords(Info, static_cast<unsigned long>(Tag));
640578
}
641579

642580
// If we have instrumented at least one alloca, all unrecognized lifetime

llvm/test/CodeGen/AArch64/stack-tagging-prologue.ll

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)