Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 14 additions & 33 deletions bolt/lib/Passes/BinaryPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,50 +582,31 @@ bool CheckLargeFunctions::shouldOptimize(const BinaryFunction &BF) const {
}

void LowerAnnotations::runOnFunctions(BinaryContext &BC) {
// Convert GnuArgsSize annotations into CFIs.
for (BinaryFunction *BF : BC.getAllBinaryFunctions()) {
for (FunctionFragment &FF : BF->getLayout().fragments()) {
// Reset at the start of the new fragment.
int64_t CurrentGnuArgsSize = 0;

for (BinaryBasicBlock *const BB : FF) {
for (auto II = BB->begin(); II != BB->end(); ++II) {

// Convert GnuArgsSize annotations into CFIs.
if (BF->usesGnuArgsSize() && BC.MIB->isInvoke(*II)) {
const int64_t NewGnuArgsSize = BC.MIB->getGnuArgsSize(*II);
assert(NewGnuArgsSize >= 0 &&
"Expected non-negative GNU_args_size.");
if (NewGnuArgsSize != CurrentGnuArgsSize) {
auto InsertII = BF->addCFIInstruction(
BB, II,
MCCFIInstruction::createGnuArgsSize(nullptr, NewGnuArgsSize));
CurrentGnuArgsSize = NewGnuArgsSize;
II = std::next(InsertII);
}
}

// Preserve selected annotations and strip the rest.
std::optional<uint32_t> Offset = BF->requiresAddressTranslation()
? BC.MIB->getOffset(*II)
: std::nullopt;
std::optional<uint32_t> Size = BC.MIB->getSize(*II);
MCSymbol *Label = BC.MIB->getLabel(*II);

BC.MIB->stripAnnotations(*II);

if (Offset)
BC.MIB->setOffset(*II, *Offset);
if (Size)
BC.MIB->setSize(*II, *Size);
if (Label)
BC.MIB->setLabel(*II, Label);
if (!BF->usesGnuArgsSize() || !BC.MIB->isInvoke(*II))
continue;

const int64_t NewGnuArgsSize = BC.MIB->getGnuArgsSize(*II);
assert(NewGnuArgsSize >= 0 && "Expected non-negative GNU_args_size.");
if (NewGnuArgsSize == CurrentGnuArgsSize)
continue;

auto InsertII = BF->addCFIInstruction(
BB, II,
MCCFIInstruction::createGnuArgsSize(nullptr, NewGnuArgsSize));
CurrentGnuArgsSize = NewGnuArgsSize;
II = std::next(InsertII);
}
}
}
}

// Release all memory taken by annotations
BC.MIB->freeAnnotations();
}

// Check for dirty state in MCSymbol objects that might be a consequence
Expand Down