Skip to content

Commit 4ace9bd

Browse files
author
Alexander Yermolovich
committed
moved reloc checking code, and changed elf object from assert to return error
1 parent d393b5e commit 4ace9bd

File tree

3 files changed

+92
-127
lines changed

3 files changed

+92
-127
lines changed

bolt/include/bolt/Passes/IdenticalCodeFolding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class IdenticalCodeFolding : public BinaryFunctionPass {
4545
Error markFunctionsUnsafeToFold(BinaryContext &BC);
4646
/// Process relocations in the .data section to identify function
4747
/// references.
48-
void processDataRelocations(BinaryContext &BC,
49-
const SectionRef &SecRefRelData);
48+
Error processDataRelocations(BinaryContext &BC,
49+
const SectionRef &SecRefRelData);
5050
};
5151

5252
} // namespace bolt

bolt/lib/Passes/IdenticalCodeFolding.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ typedef std::unordered_map<BinaryFunction *, std::vector<BinaryFunction *>,
340340
namespace llvm {
341341
namespace bolt {
342342

343-
void IdenticalCodeFolding::processDataRelocations(
343+
Error IdenticalCodeFolding::processDataRelocations(
344344
BinaryContext &BC, const SectionRef &SecRefRelData) {
345345
for (const RelocationRef &Rel : SecRefRelData.relocations()) {
346346
symbol_iterator SymbolIter = Rel.getSymbol();
@@ -351,39 +351,35 @@ void IdenticalCodeFolding::processDataRelocations(
351351
const uint64_t SymbolAddress = cantFail(Symbol.getAddress());
352352
const ELFObjectFileBase *ELFObj = dyn_cast<ELFObjectFileBase>(OwningObj);
353353
if (!ELFObj)
354-
llvm_unreachable("Only ELFObjectFileBase is supported");
354+
return createFatalBOLTError(
355+
Twine("BOLT-ERROR: Only ELFObjectFileBase is supported"));
355356
const int64_t Addend = getRelocationAddend(ELFObj, Rel);
356357
BinaryFunction *BF = BC.getBinaryFunctionAtAddress(SymbolAddress + Addend);
357358
if (!BF)
358359
continue;
359360
BF->setUnsafeICF();
360361
}
362+
return Error::success();
361363
}
362364

363365
Error IdenticalCodeFolding::markFunctionsUnsafeToFold(BinaryContext &BC) {
364-
Error ErrorStatus = Error::success();
365-
if (!BC.HasRelocations)
366-
ErrorStatus = joinErrors(
367-
std::move(ErrorStatus),
368-
createFatalBOLTError(Twine("BOLT-ERROR: Binary built without "
369-
"relocations. Safe ICF is not supported")));
370-
if (ErrorStatus)
371-
return ErrorStatus;
372366
ErrorOr<BinarySection &> SecRelData = BC.getUniqueSectionByName(".rela.data");
373367
if (SecRelData) {
374368
SectionRef SecRefRelData = SecRelData->getSectionRef();
375-
processDataRelocations(BC, SecRefRelData);
369+
Error ErrorStatus = processDataRelocations(BC, SecRefRelData);
370+
if (ErrorStatus)
371+
return ErrorStatus;
376372
}
377373

378374
ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
379-
if (BF.getState() == BinaryFunction::State::CFG) {
380-
for (const BinaryBasicBlock *BB : BF.getLayout().blocks())
381-
for (const MCInst &Inst : *BB)
382-
BC.processInstructionForFuncReferences(Inst);
383-
}
375+
for (const BinaryBasicBlock *BB : BF.getLayout().blocks())
376+
for (const MCInst &Inst : *BB)
377+
BC.processInstructionForFuncReferences(Inst);
384378
};
385379
ParallelUtilities::PredicateTy SkipFunc =
386-
[&](const BinaryFunction &BF) -> bool { return (bool)ErrorStatus; };
380+
[&](const BinaryFunction &BF) -> bool {
381+
return BF.getState() != BinaryFunction::State::CFG;
382+
};
387383
ParallelUtilities::runOnEachFunction(
388384
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
389385
SkipFunc, "markUnsafe", /*ForceSequential*/ false, 2);
@@ -396,7 +392,7 @@ Error IdenticalCodeFolding::markFunctionsUnsafeToFold(BinaryContext &BC) {
396392
<< '\n';
397393
}
398394
});
399-
return ErrorStatus;
395+
return Error::success();
400396
}
401397

402398
Error IdenticalCodeFolding::runOnFunctions(BinaryContext &BC) {

0 commit comments

Comments
 (0)