@@ -1021,24 +1021,25 @@ bool BinaryFunction::isZeroPaddingAt(uint64_t Offset) const {
1021
1021
return true ;
1022
1022
}
1023
1023
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 ) {
1026
1026
auto &MIB = BC.MIB ;
1027
1027
uint64_t TargetAddress = 0 ;
1028
1028
if (!MIB->evaluateMemOperandTarget (Instruction, TargetAddress, Address,
1029
1029
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 " ;
1038
1039
if (BC.HasRelocations )
1039
- exit ( 1 );
1040
+ return createFatalBOLTError (Msg );
1040
1041
IsSimple = false ;
1041
- return ;
1042
+ return createNonFatalBOLTError (Msg) ;
1042
1043
}
1043
1044
if (TargetAddress == 0 && opts::Verbosity >= 1 ) {
1044
1045
outs () << " BOLT-INFO: PC-relative operand is zero in function " << *this
@@ -1054,6 +1055,7 @@ void BinaryFunction::handlePCRelOperand(MCInst &Instruction, uint64_t Address,
1054
1055
Instruction, TargetSymbol, static_cast <int64_t >(TargetOffset), &*BC.Ctx );
1055
1056
(void )ReplaceSuccess;
1056
1057
assert (ReplaceSuccess && " Failed to replace mem operand with symbol+off." );
1058
+ return Error::success ();
1057
1059
}
1058
1060
1059
1061
MCSymbol *BinaryFunction::handleExternalReference (MCInst &Instruction,
@@ -1164,7 +1166,7 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction,
1164
1166
}
1165
1167
}
1166
1168
1167
- bool BinaryFunction::disassemble () {
1169
+ Error BinaryFunction::disassemble () {
1168
1170
NamedRegionTimer T (" disassemble" , " Disassemble function" , " buildfuncs" ,
1169
1171
" Build Binary Functions" , opts::TimeBuild);
1170
1172
ErrorOr<ArrayRef<uint8_t >> ErrorOrFunctionData = getData ();
@@ -1332,8 +1334,19 @@ bool BinaryFunction::disassemble() {
1332
1334
if (MIB->isIndirectBranch (Instruction))
1333
1335
handleIndirectBranch (Instruction, Size , Offset);
1334
1336
// 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
+ }
1337
1350
1338
1351
if (BC.isAArch64 ())
1339
1352
handleAArch64IndirectCall (Instruction, Offset);
@@ -1372,8 +1385,18 @@ bool BinaryFunction::disassemble() {
1372
1385
UsedReloc = true ;
1373
1386
}
1374
1387
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
+ }
1377
1400
}
1378
1401
1379
1402
add_instruction:
@@ -1413,12 +1436,12 @@ bool BinaryFunction::disassemble() {
1413
1436
1414
1437
if (!IsSimple) {
1415
1438
clearList (Instructions);
1416
- return false ;
1439
+ return createNonFatalBOLTError ( " " ) ;
1417
1440
}
1418
1441
1419
1442
updateState (State::Disassembled);
1420
1443
1421
- return true ;
1444
+ return Error::success () ;
1422
1445
}
1423
1446
1424
1447
bool BinaryFunction::scanExternalRefs () {
@@ -1946,17 +1969,17 @@ void BinaryFunction::recomputeLandingPads() {
1946
1969
}
1947
1970
}
1948
1971
1949
- bool BinaryFunction::buildCFG (MCPlusBuilder::AllocatorIdTy AllocatorId) {
1972
+ Error BinaryFunction::buildCFG (MCPlusBuilder::AllocatorIdTy AllocatorId) {
1950
1973
auto &MIB = BC.MIB ;
1951
1974
1952
1975
if (!isSimple ()) {
1953
1976
assert (!BC.HasRelocations &&
1954
1977
" cannot process file with non-simple function in relocs mode" );
1955
- return false ;
1978
+ return createNonFatalBOLTError ( " " ) ;
1956
1979
}
1957
1980
1958
1981
if (CurrentState != State::Disassembled)
1959
- return false ;
1982
+ return createNonFatalBOLTError ( " " ) ;
1960
1983
1961
1984
assert (BasicBlocks.empty () && " basic block list should be empty" );
1962
1985
assert ((Labels.find (getFirstInstructionOffset ()) != Labels.end ()) &&
@@ -2093,7 +2116,7 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
2093
2116
2094
2117
if (BasicBlocks.empty ()) {
2095
2118
setSimple (false );
2096
- return false ;
2119
+ return createNonFatalBOLTError ( " " ) ;
2097
2120
}
2098
2121
2099
2122
// Intermediate dump.
@@ -2204,7 +2227,7 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
2204
2227
clearList (ExternallyReferencedOffsets);
2205
2228
clearList (UnknownIndirectBranchOffsets);
2206
2229
2207
- return true ;
2230
+ return Error::success () ;
2208
2231
}
2209
2232
2210
2233
void BinaryFunction::postProcessCFG () {
0 commit comments