@@ -3628,13 +3628,19 @@ void RewriteInstance::mapFileSections(BOLTLinker::SectionMapper MapSection) {
3628
3628
}
3629
3629
3630
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
+
3631
3639
PHDRTableOffset = 0 ;
3632
3640
PHDRTableAddress = 0 ;
3633
3641
NewTextSegmentAddress = 0 ;
3634
3642
NewTextSegmentOffset = 0 ;
3635
- NextAvailableAddress = StartBD->getAddress ();
3636
- BC->outs ()
3637
- << " BOLT-INFO: using reserved space for allocating new sections\n " ;
3643
+ NextAvailableAddress = BC->BOLTReserved .start ();
3638
3644
}
3639
3645
3640
3646
// If no new .eh_frame was written, remove relocated original .eh_frame.
@@ -3657,12 +3663,12 @@ void RewriteInstance::mapFileSections(BOLTLinker::SectionMapper MapSection) {
3657
3663
// Map the rest of the sections.
3658
3664
mapAllocatableSections (MapSection);
3659
3665
3660
- if (StartBD ) {
3661
- const uint64_t ReservedSpace = EndBD-> getAddress () - StartBD-> getAddress ();
3662
- const uint64_t AllocatedSize = NextAvailableAddress - StartBD-> getAddress ();
3663
- if (ReservedSpace < AllocatedSize) {
3664
- BC->errs () << " BOLT-ERROR: reserved space (" << ReservedSpace << " byte "
3665
- << (ReservedSpace == 1 ? " " : " s" )
3666
+ if (!BC-> BOLTReserved . empty () ) {
3667
+ const uint64_t AllocatedSize =
3668
+ NextAvailableAddress - BC-> BOLTReserved . start ();
3669
+ if (BC-> BOLTReserved . size () < AllocatedSize) {
3670
+ BC->errs () << " BOLT-ERROR: reserved space (" << BC-> BOLTReserved . size ()
3671
+ << " byte " << (BC-> BOLTReserved . size () == 1 ? " " : " s" )
3666
3672
<< " ) is smaller than required for new allocations ("
3667
3673
<< AllocatedSize << " bytes)\n " ;
3668
3674
exit (1 );
@@ -5852,13 +5858,11 @@ void RewriteInstance::writeEHFrameHeader() {
5852
5858
5853
5859
NextAvailableAddress += EHFrameHdrSec.getOutputSize ();
5854
5860
5855
- if (const BinaryData *ReservedEnd =
5856
- BC->getBinaryDataByName (getBOLTReservedEnd ())) {
5857
- if (NextAvailableAddress > ReservedEnd->getAddress ()) {
5858
- BC->errs () << " BOLT-ERROR: unable to fit " << getEHFrameHdrSectionName ()
5859
- << " into reserved space\n " ;
5860
- exit (1 );
5861
- }
5861
+ if (!BC->BOLTReserved .empty () &&
5862
+ (NextAvailableAddress > BC->BOLTReserved .end ())) {
5863
+ BC->errs () << " BOLT-ERROR: unable to fit " << getEHFrameHdrSectionName ()
5864
+ << " into reserved space\n " ;
5865
+ exit (1 );
5862
5866
}
5863
5867
5864
5868
// Merge new .eh_frame with the relocated original so that gdb can locate all
@@ -5892,7 +5896,7 @@ uint64_t RewriteInstance::getNewValueForSymbol(const StringRef Name) {
5892
5896
5893
5897
uint64_t RewriteInstance::getFileOffsetForAddress (uint64_t Address) const {
5894
5898
// Check if it's possibly part of the new segment.
5895
- if (Address >= NewTextSegmentAddress)
5899
+ if (NewTextSegmentAddress && Address >= NewTextSegmentAddress)
5896
5900
return Address - NewTextSegmentAddress + NewTextSegmentOffset;
5897
5901
5898
5902
// Find an existing segment that matches the address.
0 commit comments