Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9cd218e

Browse files
authored
[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.
1 parent 99b4532 commit 9cd218e

2 files changed

Lines changed: 33 additions & 26 deletions

File tree

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class RewriteInstance {
9797
/// from meta data in the file.
9898
void discoverFileObjects();
9999

100+
/// Check if the input binary has a space reserved for BOLT and use it for new
101+
/// section allocations if found.
102+
void discoverBOLTReserved();
103+
100104
/// Check whether we should use DT_FINI or DT_FINI_ARRAY for instrumentation.
101105
/// DT_FINI is preferred; DT_FINI_ARRAY is only used when no DT_FINI entry was
102106
/// found.

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,35 @@ void RewriteInstance::discoverFileObjects() {
13471347

13481348
registerFragments();
13491349
FileSymbols.clear();
1350+
1351+
discoverBOLTReserved();
1352+
}
1353+
1354+
void RewriteInstance::discoverBOLTReserved() {
1355+
BinaryData *StartBD = BC->getBinaryDataByName(getBOLTReservedStart());
1356+
BinaryData *EndBD = BC->getBinaryDataByName(getBOLTReservedEnd());
1357+
if (!StartBD != !EndBD) {
1358+
BC->errs() << "BOLT-ERROR: one of the symbols is missing from the binary: "
1359+
<< getBOLTReservedStart() << ", " << getBOLTReservedEnd()
1360+
<< '\n';
1361+
exit(1);
1362+
}
1363+
1364+
if (!StartBD)
1365+
return;
1366+
1367+
if (StartBD->getAddress() >= EndBD->getAddress()) {
1368+
BC->errs() << "BOLT-ERROR: invalid reserved space boundaries\n";
1369+
exit(1);
1370+
}
1371+
BC->BOLTReserved = AddressRange(StartBD->getAddress(), EndBD->getAddress());
1372+
BC->outs() << "BOLT-INFO: using reserved space for allocating new sections\n";
1373+
1374+
PHDRTableOffset = 0;
1375+
PHDRTableAddress = 0;
1376+
NewTextSegmentAddress = 0;
1377+
NewTextSegmentOffset = 0;
1378+
NextAvailableAddress = BC->BOLTReserved.start();
13501379
}
13511380

13521381
Error RewriteInstance::discoverRtFiniAddress() {
@@ -3617,32 +3646,6 @@ void RewriteInstance::updateMetadata() {
36173646
void RewriteInstance::mapFileSections(BOLTLinker::SectionMapper MapSection) {
36183647
BC->deregisterUnusedSections();
36193648

3620-
// Check if the input has a space reserved for BOLT.
3621-
BinaryData *StartBD = BC->getBinaryDataByName(getBOLTReservedStart());
3622-
BinaryData *EndBD = BC->getBinaryDataByName(getBOLTReservedEnd());
3623-
if (!StartBD != !EndBD) {
3624-
BC->errs() << "BOLT-ERROR: one of the symbols is missing from the binary: "
3625-
<< getBOLTReservedStart() << ", " << getBOLTReservedEnd()
3626-
<< '\n';
3627-
exit(1);
3628-
}
3629-
3630-
if (StartBD) {
3631-
if (StartBD->getAddress() >= EndBD->getAddress()) {
3632-
BC->errs() << "BOLT-ERROR: invalid reserved space boundaries\n";
3633-
exit(1);
3634-
}
3635-
BC->BOLTReserved = AddressRange(StartBD->getAddress(), EndBD->getAddress());
3636-
BC->outs()
3637-
<< "BOLT-INFO: using reserved space for allocating new sections\n";
3638-
3639-
PHDRTableOffset = 0;
3640-
PHDRTableAddress = 0;
3641-
NewTextSegmentAddress = 0;
3642-
NewTextSegmentOffset = 0;
3643-
NextAvailableAddress = BC->BOLTReserved.start();
3644-
}
3645-
36463649
// If no new .eh_frame was written, remove relocated original .eh_frame.
36473650
BinarySection *RelocatedEHFrameSection =
36483651
getSection(".relocated" + getEHFrameSectionName());

0 commit comments

Comments
 (0)