[BOLT] Free more memory in BinaryFunction::releaseCFG()

Summary:
Free more lists in BinaryFunction::releaseCFG().

Release BinaryFunction::Relocations after disassembly.

Do not populate BinaryFunction::MoveRelocations as we are not using them
currently.

Also remove PCRelativeRelocationOffsets that weren't used.

(cherry picked from FBD18413256)
This commit is contained in:
Maksim Panchenko 2019-11-08 14:41:31 -08:00
parent d5ddb320ef
commit 72b52edcbb
3 changed files with 19 additions and 25 deletions

View File

@ -661,11 +661,6 @@ void BinaryFunction::printRelocations(raw_ostream &OS,
Sep = ", ";
++RI;
}
auto PI = PCRelativeRelocationOffsets.lower_bound(Offset);
if (PI != PCRelativeRelocationOffsets.end() && *PI < Offset + Size) {
OS << Sep << "(pcrel)";
}
}
IndirectBranchType
@ -1232,10 +1227,6 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
addRelocation(getAddress() + RelOffset, TargetSymbol, RelType,
-RelSize, 0);
}
auto OI = PCRelativeRelocationOffsets.find(RelOffset);
if (OI != PCRelativeRelocationOffsets.end()) {
PCRelativeRelocationOffsets.erase(OI);
}
}
}
}
@ -1353,6 +1344,8 @@ add_instruction:
addInstruction(Offset, std::move(Instruction));
}
clearList(Relocations);
updateState(State::Disassembled);
postProcessEntryPoints();

View File

@ -482,9 +482,6 @@ private:
/// Map of relocations used for moving the function body as it is.
std::map<uint64_t, Relocation> MoveRelocations;
/// Offsets in function that should have PC-relative relocation.
std::set<uint64_t> PCRelativeRelocationOffsets;
/// Offsets in function that are data values in a constant island identified
/// after disassembling
std::map<uint64_t, MCSymbol *> IslandOffsets;
@ -1191,17 +1188,11 @@ public:
default:
llvm_unreachable("unexpected relocation type in code");
}
MoveRelocations[Offset] =
Relocation{Offset, Symbol, RelType, Addend, Value};
}
/// Register a fact that we should have a PC-relative relocation at a given
/// address in a function. During disassembly we have to make sure we create
/// relocation at that location.
void addPCRelativeRelocationAddress(uint64_t Address) {
assert(containsAddress(Address, /*UseMaxSize=*/ true) &&
"address is outside of the function");
PCRelativeRelocationOffsets.emplace(Address - getAddress());
// FIXME: if we ever find a use for MoveRelocations, this is the place to
// initialize those:
// MoveRelocations[Offset] =
// Relocation{Offset, Symbol, RelType, Addend, Value};
}
/// Get data used by this function.
@ -2360,6 +2351,18 @@ public:
for (auto BB : DeletedBasicBlocks) {
BB->releaseCFG();
}
clearList(CallSites);
clearList(ColdCallSites);
clearList(LSDATypeTable);
clearList(MoveRelocations);
clearList(LabelToBB);
clearList(Labels);
clearList(FrameInstructions);
clearList(FrameRestoreEquivalents);
}
};

View File

@ -2249,9 +2249,7 @@ void RewriteInstance::readRelocations(const SectionRef &Section,
// Just register the fact that we have PC-relative relocation at a given
// address. The actual referenced label/address cannot be determined
// from linker data alone.
if (IsFromCode) {
ContainingBF->addPCRelativeRelocationAddress(Rel.getOffset());
} else {
if (!IsFromCode) {
BC->addPCRelativeDataRelocation(Rel.getOffset(), Rel.getType(),
ExtractedValue);
}