mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[BOLT] Fix -simplify-rodata-loads wrt data chunks with relocs
Summary: The pass was previously copying data that would change after layout because it had a relocation at the copied address. (cherry picked from FBD6541334)
This commit is contained in:
committed by
Maksim Panchenko
parent
85f5f4fb63
commit
660daac2d0
@@ -525,6 +525,22 @@ void BinaryContext::removeRelocationAt(uint64_t Address) {
|
||||
Relocations.erase(RelocI);
|
||||
}
|
||||
|
||||
const Relocation *BinaryContext::getRelocationAt(uint64_t Address) {
|
||||
auto ContainingSection = getSectionForAddress(Address);
|
||||
assert(ContainingSection && "cannot find section for address");
|
||||
auto RI = SectionRelocations.find(*ContainingSection);
|
||||
if (RI == SectionRelocations.end())
|
||||
return nullptr;
|
||||
|
||||
auto &Relocations = RI->second;
|
||||
auto RelocI = Relocations.find(
|
||||
Relocation{Address - ContainingSection->getAddress(), 0, 0, 0, 0});
|
||||
if (RelocI == Relocations.end())
|
||||
return nullptr;
|
||||
|
||||
return &*RelocI;
|
||||
}
|
||||
|
||||
size_t Relocation::getSizeForType(uint64_t Type) {
|
||||
switch (Type) {
|
||||
default:
|
||||
|
||||
@@ -301,6 +301,10 @@ public:
|
||||
/// Remove registered relocation at a given \p Address.
|
||||
void removeRelocationAt(uint64_t Address);
|
||||
|
||||
/// Return a relocation registered at a given \p Address, or nullptr if there
|
||||
/// is no relocation at such address.
|
||||
const Relocation *getRelocationAt(uint64_t Address);
|
||||
|
||||
const BinaryFunction *getFunctionForSymbol(const MCSymbol *Symbol) const {
|
||||
auto BFI = SymbolToFunctionMap.find(Symbol);
|
||||
return BFI == SymbolToFunctionMap.end() ? nullptr : BFI->second;
|
||||
|
||||
@@ -1146,6 +1146,10 @@ bool SimplifyRODataLoads::simplifyRODataLoads(
|
||||
SectionRef DataSection = DataSectionOrErr.get();
|
||||
if (!DataSection.isReadOnly())
|
||||
continue;
|
||||
|
||||
if (BC.getRelocationAt(TargetAddress))
|
||||
continue;
|
||||
|
||||
uint32_t Offset = TargetAddress - DataSection.getAddress();
|
||||
StringRef ConstantData;
|
||||
if (std::error_code EC = DataSection.getContents(ConstantData)) {
|
||||
|
||||
Reference in New Issue
Block a user