@@ -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
13521381Error RewriteInstance::discoverRtFiniAddress () {
@@ -3617,32 +3646,6 @@ void RewriteInstance::updateMetadata() {
36173646void 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