@@ -775,13 +775,13 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
775
775
Labels[0 ] = Ctx->createTempSymbol (" BB0" , false );
776
776
addEntryPointAtOffset (0 );
777
777
778
- auto handleRIPOperand =
778
+ auto handlePCRelOperand =
779
779
[&](MCInst &Instruction, uint64_t Address, uint64_t Size) {
780
780
uint64_t TargetAddress{0 };
781
781
MCSymbol *TargetSymbol{nullptr };
782
782
if (!MIA->evaluateMemOperandTarget (Instruction, TargetAddress, Address,
783
783
Size)) {
784
- errs () << " BOLT-ERROR: rip -relative operand can't be evaluated:\n " ;
784
+ errs () << " BOLT-ERROR: PC -relative operand can't be evaluated:\n " ;
785
785
BC.InstPrinter ->printInst (&Instruction, errs (), " " , *BC.STI );
786
786
errs () << ' \n ' ;
787
787
Instruction.dump_pretty (errs (), BC.InstPrinter .get ());
@@ -790,7 +790,7 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
790
790
}
791
791
if (TargetAddress == 0 ) {
792
792
if (opts::Verbosity >= 1 ) {
793
- outs () << " BOLT-INFO: rip -relative operand is zero in function "
793
+ outs () << " BOLT-INFO: PC -relative operand is zero in function "
794
794
<< *this << " .\n " ;
795
795
}
796
796
}
@@ -816,8 +816,11 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
816
816
if (!TargetSymbol)
817
817
TargetSymbol = BC.getOrCreateGlobalSymbol (TargetAddress, " DATAat" );
818
818
MIA->replaceMemOperandDisp (
819
- Instruction, MCOperand::createExpr (MCSymbolRefExpr::create (
820
- TargetSymbol, MCSymbolRefExpr::VK_None, *BC.Ctx )));
819
+ Instruction, MCOperand::createExpr (BC.MIA ->getTargetExprFor (
820
+ Instruction,
821
+ MCSymbolRefExpr::create (
822
+ TargetSymbol, MCSymbolRefExpr::VK_None, *BC.Ctx ),
823
+ *BC.Ctx )));
821
824
return true ;
822
825
};
823
826
@@ -954,7 +957,7 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
954
957
// Assign proper opcode for tail calls, so that they could be
955
958
// treated as calls.
956
959
if (!IsCall) {
957
- if (!MIA->convertJmpToTailCall (Instruction)) {
960
+ if (!MIA->convertJmpToTailCall (Instruction, BC. Ctx . get () )) {
958
961
assert (IsCondBranch && " unknown tail call instruction" );
959
962
if (opts::Verbosity >= 2 ) {
960
963
errs () << " BOLT-WARNING: conditional tail call detected in "
@@ -1007,12 +1010,7 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
1007
1010
// Add taken branch info.
1008
1011
TakenBranches.emplace_back (Offset, TargetAddress - getAddress ());
1009
1012
}
1010
- Instruction.clear ();
1011
- Instruction.addOperand (
1012
- MCOperand::createExpr (
1013
- MCSymbolRefExpr::create (TargetSymbol,
1014
- MCSymbolRefExpr::VK_None,
1015
- *Ctx)));
1013
+ BC.MIA ->replaceBranchTarget (Instruction, TargetSymbol, &*Ctx);
1016
1014
1017
1015
// Record call offset for profile matching.
1018
1016
if (IsCall) {
@@ -1036,7 +1034,8 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
1036
1034
llvm_unreachable (" unexpected result" );
1037
1035
case IndirectBranchType::POSSIBLE_TAIL_CALL:
1038
1036
{
1039
- auto Result = MIA->convertJmpToTailCall (Instruction);
1037
+ auto Result =
1038
+ MIA->convertJmpToTailCall (Instruction, BC.Ctx .get ());
1040
1039
(void )Result;
1041
1040
assert (Result);
1042
1041
}
@@ -1053,8 +1052,8 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
1053
1052
};
1054
1053
}
1055
1054
// Indirect call. We only need to fix it if the operand is RIP-relative
1056
- if (IsSimple && MIA->hasRIPOperand (Instruction)) {
1057
- if (!handleRIPOperand (Instruction, AbsoluteInstrAddr, Size)) {
1055
+ if (IsSimple && MIA->hasPCRelOperand (Instruction)) {
1056
+ if (!handlePCRelOperand (Instruction, AbsoluteInstrAddr, Size)) {
1058
1057
errs () << " BOLT-ERROR: cannot handle RIP operand at 0x"
1059
1058
<< Twine::utohexstr (AbsoluteInstrAddr)
1060
1059
<< " . Skipping function " << *this << " .\n " ;
@@ -1065,8 +1064,8 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
1065
1064
}
1066
1065
}
1067
1066
} else {
1068
- if (MIA->hasRIPOperand (Instruction)) {
1069
- if (!handleRIPOperand (Instruction, AbsoluteInstrAddr, Size)) {
1067
+ if (MIA->hasPCRelOperand (Instruction)) {
1068
+ if (!handlePCRelOperand (Instruction, AbsoluteInstrAddr, Size)) {
1070
1069
errs () << " BOLT-ERROR: cannot handle RIP operand at 0x"
1071
1070
<< Twine::utohexstr (AbsoluteInstrAddr)
1072
1071
<< " . Skipping function " << *this << " .\n " ;
@@ -1152,7 +1151,7 @@ bool BinaryFunction::postProcessIndirectBranches() {
1152
1151
// If there's an indirect branch in a single-block function -
1153
1152
// it must be a tail call.
1154
1153
if (layout_size () == 1 ) {
1155
- BC.MIA ->convertJmpToTailCall (Instr);
1154
+ BC.MIA ->convertJmpToTailCall (Instr, BC. Ctx . get () );
1156
1155
return true ;
1157
1156
}
1158
1157
@@ -1231,7 +1230,7 @@ bool BinaryFunction::postProcessIndirectBranches() {
1231
1230
}
1232
1231
return false ;
1233
1232
}
1234
- BC.MIA ->convertJmpToTailCall (Instr);
1233
+ BC.MIA ->convertJmpToTailCall (Instr, BC. Ctx . get () );
1235
1234
}
1236
1235
}
1237
1236
return true ;
0 commit comments