[BOLT] Refactor BOLT reserved space discovery (#90893)
Move code that checks for __bolt_reserved_{start,end} into a new
discoverBOLTReserved() function and call it from discoverFileObjects()
so that the reserved space info is accessible to passes. NFC for the
current set of binaries.
This commit is contained in:
@@ -1347,6 +1347,35 @@ void RewriteInstance::discoverFileObjects() {
|
||||
|
||||
registerFragments();
|
||||
FileSymbols.clear();
|
||||
|
||||
discoverBOLTReserved();
|
||||
}
|
||||
|
||||
void RewriteInstance::discoverBOLTReserved() {
|
||||
BinaryData *StartBD = BC->getBinaryDataByName(getBOLTReservedStart());
|
||||
BinaryData *EndBD = BC->getBinaryDataByName(getBOLTReservedEnd());
|
||||
if (!StartBD != !EndBD) {
|
||||
BC->errs() << "BOLT-ERROR: one of the symbols is missing from the binary: "
|
||||
<< getBOLTReservedStart() << ", " << getBOLTReservedEnd()
|
||||
<< '\n';
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!StartBD)
|
||||
return;
|
||||
|
||||
if (StartBD->getAddress() >= EndBD->getAddress()) {
|
||||
BC->errs() << "BOLT-ERROR: invalid reserved space boundaries\n";
|
||||
exit(1);
|
||||
}
|
||||
BC->BOLTReserved = AddressRange(StartBD->getAddress(), EndBD->getAddress());
|
||||
BC->outs() << "BOLT-INFO: using reserved space for allocating new sections\n";
|
||||
|
||||
PHDRTableOffset = 0;
|
||||
PHDRTableAddress = 0;
|
||||
NewTextSegmentAddress = 0;
|
||||
NewTextSegmentOffset = 0;
|
||||
NextAvailableAddress = BC->BOLTReserved.start();
|
||||
}
|
||||
|
||||
Error RewriteInstance::discoverRtFiniAddress() {
|
||||
@@ -3617,32 +3646,6 @@ void RewriteInstance::updateMetadata() {
|
||||
void RewriteInstance::mapFileSections(BOLTLinker::SectionMapper MapSection) {
|
||||
BC->deregisterUnusedSections();
|
||||
|
||||
// Check if the input has a space reserved for BOLT.
|
||||
BinaryData *StartBD = BC->getBinaryDataByName(getBOLTReservedStart());
|
||||
BinaryData *EndBD = BC->getBinaryDataByName(getBOLTReservedEnd());
|
||||
if (!StartBD != !EndBD) {
|
||||
BC->errs() << "BOLT-ERROR: one of the symbols is missing from the binary: "
|
||||
<< getBOLTReservedStart() << ", " << getBOLTReservedEnd()
|
||||
<< '\n';
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (StartBD) {
|
||||
if (StartBD->getAddress() >= EndBD->getAddress()) {
|
||||
BC->errs() << "BOLT-ERROR: invalid reserved space boundaries\n";
|
||||
exit(1);
|
||||
}
|
||||
BC->BOLTReserved = AddressRange(StartBD->getAddress(), EndBD->getAddress());
|
||||
BC->outs()
|
||||
<< "BOLT-INFO: using reserved space for allocating new sections\n";
|
||||
|
||||
PHDRTableOffset = 0;
|
||||
PHDRTableAddress = 0;
|
||||
NewTextSegmentAddress = 0;
|
||||
NewTextSegmentOffset = 0;
|
||||
NextAvailableAddress = BC->BOLTReserved.start();
|
||||
}
|
||||
|
||||
// If no new .eh_frame was written, remove relocated original .eh_frame.
|
||||
BinarySection *RelocatedEHFrameSection =
|
||||
getSection(".relocated" + getEHFrameSectionName());
|
||||
|
||||
Reference in New Issue
Block a user