@@ -340,7 +340,7 @@ typedef std::unordered_map<BinaryFunction *, std::vector<BinaryFunction *>,
340340namespace llvm {
341341namespace 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
363365Error 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
402398Error IdenticalCodeFolding::runOnFunctions (BinaryContext &BC) {
0 commit comments