@@ -1021,24 +1021,25 @@ bool BinaryFunction::isZeroPaddingAt(uint64_t Offset) const {
10211021 return true ;
10221022}
10231023
1024- void BinaryFunction::handlePCRelOperand (MCInst &Instruction, uint64_t Address,
1025- uint64_t Size) {
1024+ Error BinaryFunction::handlePCRelOperand (MCInst &Instruction, uint64_t Address,
1025+ uint64_t Size) {
10261026 auto &MIB = BC.MIB ;
10271027 uint64_t TargetAddress = 0 ;
10281028 if (!MIB->evaluateMemOperandTarget (Instruction, TargetAddress, Address,
10291029 Size)) {
1030- errs () << " BOLT-ERROR: PC-relative operand can't be evaluated:\n " ;
1031- BC.InstPrinter ->printInst (&Instruction, 0 , " " , *BC.STI , errs ());
1032- errs () << ' \n ' ;
1033- Instruction.dump_pretty (errs (), BC.InstPrinter .get ());
1034- errs () << ' \n ' ;
1035- errs () << " BOLT-ERROR: cannot handle PC-relative operand at 0x"
1036- << Twine::utohexstr (Address) << " . Skipping function " << *this
1037- << " .\n " ;
1030+ std::string Msg;
1031+ raw_string_ostream SS (Msg);
1032+ SS << " BOLT-ERROR: PC-relative operand can't be evaluated:\n " ;
1033+ BC.InstPrinter ->printInst (&Instruction, 0 , " " , *BC.STI , SS);
1034+ SS << ' \n ' ;
1035+ Instruction.dump_pretty (SS, BC.InstPrinter .get ());
1036+ SS << ' \n ' ;
1037+ SS << " BOLT-ERROR: cannot handle PC-relative operand at 0x"
1038+ << Twine::utohexstr (Address) << " . Skipping function " << *this << " .\n " ;
10381039 if (BC.HasRelocations )
1039- exit ( 1 );
1040+ return createFatalBOLTError (Msg );
10401041 IsSimple = false ;
1041- return ;
1042+ return createNonFatalBOLTError (Msg) ;
10421043 }
10431044 if (TargetAddress == 0 && opts::Verbosity >= 1 ) {
10441045 outs () << " BOLT-INFO: PC-relative operand is zero in function " << *this
@@ -1054,6 +1055,7 @@ void BinaryFunction::handlePCRelOperand(MCInst &Instruction, uint64_t Address,
10541055 Instruction, TargetSymbol, static_cast <int64_t >(TargetOffset), &*BC.Ctx );
10551056 (void )ReplaceSuccess;
10561057 assert (ReplaceSuccess && " Failed to replace mem operand with symbol+off." );
1058+ return Error::success ();
10571059}
10581060
10591061MCSymbol *BinaryFunction::handleExternalReference (MCInst &Instruction,
@@ -1164,7 +1166,7 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction,
11641166 }
11651167}
11661168
1167- bool BinaryFunction::disassemble () {
1169+ Error BinaryFunction::disassemble () {
11681170 NamedRegionTimer T (" disassemble" , " Disassemble function" , " buildfuncs" ,
11691171 " Build Binary Functions" , opts::TimeBuild);
11701172 ErrorOr<ArrayRef<uint8_t >> ErrorOrFunctionData = getData ();
@@ -1332,8 +1334,19 @@ bool BinaryFunction::disassemble() {
13321334 if (MIB->isIndirectBranch (Instruction))
13331335 handleIndirectBranch (Instruction, Size, Offset);
13341336 // Indirect call. We only need to fix it if the operand is RIP-relative.
1335- if (IsSimple && MIB->hasPCRelOperand (Instruction))
1336- handlePCRelOperand (Instruction, AbsoluteInstrAddr, Size);
1337+ if (IsSimple && MIB->hasPCRelOperand (Instruction)) {
1338+ if (auto NewE = handleErrors (
1339+ handlePCRelOperand (Instruction, AbsoluteInstrAddr, Size),
1340+ [&](const BOLTError &E) -> Error {
1341+ if (E.isFatal ())
1342+ return Error (std::make_unique<BOLTError>(std::move (E)));
1343+ if (!E.getMessage ().empty ())
1344+ E.log (errs ());
1345+ return Error::success ();
1346+ })) {
1347+ return Error (std::move (NewE));
1348+ }
1349+ }
13371350
13381351 if (BC.isAArch64 ())
13391352 handleAArch64IndirectCall (Instruction, Offset);
@@ -1372,8 +1385,18 @@ bool BinaryFunction::disassemble() {
13721385 UsedReloc = true ;
13731386 }
13741387
1375- if (!BC.isRISCV () && MIB->hasPCRelOperand (Instruction) && !UsedReloc)
1376- handlePCRelOperand (Instruction, AbsoluteInstrAddr, Size);
1388+ if (!BC.isRISCV () && MIB->hasPCRelOperand (Instruction) && !UsedReloc) {
1389+ if (auto NewE = handleErrors (
1390+ handlePCRelOperand (Instruction, AbsoluteInstrAddr, Size),
1391+ [&](const BOLTError &E) -> Error {
1392+ if (E.isFatal ())
1393+ return Error (std::make_unique<BOLTError>(std::move (E)));
1394+ if (!E.getMessage ().empty ())
1395+ E.log (errs ());
1396+ return Error::success ();
1397+ }))
1398+ return Error (std::move (NewE));
1399+ }
13771400 }
13781401
13791402add_instruction:
@@ -1413,12 +1436,12 @@ bool BinaryFunction::disassemble() {
14131436
14141437 if (!IsSimple) {
14151438 clearList (Instructions);
1416- return false ;
1439+ return createNonFatalBOLTError ( " " ) ;
14171440 }
14181441
14191442 updateState (State::Disassembled);
14201443
1421- return true ;
1444+ return Error::success () ;
14221445}
14231446
14241447bool BinaryFunction::scanExternalRefs () {
@@ -1946,17 +1969,17 @@ void BinaryFunction::recomputeLandingPads() {
19461969 }
19471970}
19481971
1949- bool BinaryFunction::buildCFG (MCPlusBuilder::AllocatorIdTy AllocatorId) {
1972+ Error BinaryFunction::buildCFG (MCPlusBuilder::AllocatorIdTy AllocatorId) {
19501973 auto &MIB = BC.MIB ;
19511974
19521975 if (!isSimple ()) {
19531976 assert (!BC.HasRelocations &&
19541977 " cannot process file with non-simple function in relocs mode" );
1955- return false ;
1978+ return createNonFatalBOLTError ( " " ) ;
19561979 }
19571980
19581981 if (CurrentState != State::Disassembled)
1959- return false ;
1982+ return createNonFatalBOLTError ( " " ) ;
19601983
19611984 assert (BasicBlocks.empty () && " basic block list should be empty" );
19621985 assert ((Labels.find (getFirstInstructionOffset ()) != Labels.end ()) &&
@@ -2093,7 +2116,7 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
20932116
20942117 if (BasicBlocks.empty ()) {
20952118 setSimple (false );
2096- return false ;
2119+ return createNonFatalBOLTError ( " " ) ;
20972120 }
20982121
20992122 // Intermediate dump.
@@ -2204,7 +2227,7 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
22042227 clearList (ExternallyReferencedOffsets);
22052228 clearList (UnknownIndirectBranchOffsets);
22062229
2207- return true ;
2230+ return Error::success () ;
22082231}
22092232
22102233void BinaryFunction::postProcessCFG () {
0 commit comments