[llvm] [BOLT][BTI] Refactor: move applyBTIFixup under MCPlusBuilder (PR #177164)
Gergely Bálint via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 23 08:11:07 PST 2026
bgergely0 wrote:
thanks for taking a look @yavtuk!
I think that during passes, we generally have access to the BC. When we pass the BC as a param to a MIB function, it is to get the function based on the symbol:
```c++
void applyBTIFixupToSymbol(BinaryContext &BC, const MCSymbol *TargetSymbol,
MCInst &Call) override {
BinaryFunction *TargetFunction = BC.getFunctionForSymbol(TargetSymbol);
...
```
What you are suggesting is to move the usesBTI check inside these functions? So the usage would be e.g.:
```c++
static void relaxStubToLongJmp(BinaryBasicBlock &StubBB, const MCSymbol *Tgt) {
const BinaryContext &BC = StubBB.getFunction()->getBinaryContext();
InstructionListType Seq;
BC.MIB->createLongJmp(Seq, Tgt, BC.Ctx.get());
StubBB.clear();
StubBB.addInstructions(Seq.begin(), Seq.end());
BC.MIB->applyBTIFixupToTarget(StubBB);
}
```
and inside the function, we would return early if BTI is off, like so:
```c++
void applyBTIFixupToSymbol(BinaryContext &BC, const MCSymbol *TargetSymbol,
MCInst &Call) override {
if(!usesBTI)
return;
...
```
I think this is a reasonable idea, although not sure if a string-based storage of the feature is the best. I'll look a bit more into this SubtargetFeatures.
https://github.com/llvm/llvm-project/pull/177164
More information about the llvm-commits
mailing list