@@ -1128,7 +1128,8 @@ uint32_t RuntimeDyldELF::getMatchingLoRelocation(uint32_t RelType,
1128
1128
bool RuntimeDyldELF::resolveAArch64ShortBranch (
1129
1129
unsigned SectionID, relocation_iterator RelI,
1130
1130
const RelocationValueRef &Value) {
1131
- uint64_t Address;
1131
+ uint64_t TargetOffset;
1132
+ unsigned TargetSectionID;
1132
1133
if (Value.SymbolName ) {
1133
1134
auto Loc = GlobalSymbolTable.find (Value.SymbolName );
1134
1135
@@ -1137,23 +1138,32 @@ bool RuntimeDyldELF::resolveAArch64ShortBranch(
1137
1138
return false ;
1138
1139
1139
1140
const auto &SymInfo = Loc->second ;
1140
- Address =
1141
- uint64_t (Sections[ SymInfo.getSectionID ()]. getLoadAddressWithOffset (
1142
- SymInfo.getOffset ()) );
1141
+
1142
+ TargetSectionID = SymInfo.getSectionID ();
1143
+ TargetOffset = SymInfo.getOffset ();
1143
1144
} else {
1144
- Address = uint64_t (Sections[Value.SectionID ].getLoadAddress ());
1145
+ TargetSectionID = Value.SectionID ;
1146
+ TargetOffset = 0 ;
1145
1147
}
1146
- uint64_t Offset = RelI->getOffset ();
1147
- uint64_t SourceAddress = Sections[SectionID].getLoadAddressWithOffset (Offset);
1148
+
1149
+ // We don't actually know the load addresses at this point, so if the
1150
+ // branch is cross-section, we don't know exactly how far away it is.
1151
+ if (TargetSectionID != SectionID)
1152
+ return false ;
1153
+
1154
+ uint64_t SourceOffset = RelI->getOffset ();
1148
1155
1149
1156
// R_AARCH64_CALL26 requires immediate to be in range -2^27 <= imm < 2^27
1150
1157
// If distance between source and target is out of range then we should
1151
1158
// create thunk.
1152
- if (!isInt<28 >(Address + Value.Addend - SourceAddress ))
1159
+ if (!isInt<28 >(TargetOffset + Value.Addend - SourceOffset ))
1153
1160
return false ;
1154
1161
1155
- resolveRelocation (Sections[SectionID], Offset, Address, RelI->getType (),
1156
- Value.Addend );
1162
+ RelocationEntry RE (SectionID, SourceOffset, RelI->getType (), Value.Addend );
1163
+ if (Value.SymbolName )
1164
+ addRelocationForSymbol (RE, Value.SymbolName );
1165
+ else
1166
+ addRelocationForSection (RE, Value.SectionID );
1157
1167
1158
1168
return true ;
1159
1169
}
0 commit comments