@@ -4141,10 +4141,10 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
41414141
41424142 // Keep track of section header entries attached to the corresponding section.
41434143 std::vector<std::pair<BinarySection *, ELFShdrTy>> OutputSections;
4144- auto addSection = [&](const ELFShdrTy &Section, BinarySection * BinSec) {
4144+ auto addSection = [&](const ELFShdrTy &Section, BinarySection & BinSec) {
41454145 ELFShdrTy NewSection = Section;
4146- NewSection.sh_name = SHStrTab.getOffset (BinSec-> getOutputName ());
4147- OutputSections.emplace_back (BinSec, std::move (NewSection));
4146+ NewSection.sh_name = SHStrTab.getOffset (BinSec. getOutputName ());
4147+ OutputSections.emplace_back (& BinSec, std::move (NewSection));
41484148 };
41494149
41504150 // Copy over entries for original allocatable sections using modified name.
@@ -4162,7 +4162,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
41624162 BinarySection *BinSec = BC->getSectionForSectionRef (SecRef);
41634163 assert (BinSec && " Matching BinarySection should exist." );
41644164
4165- addSection (Section, BinSec);
4165+ addSection (Section, * BinSec);
41664166 }
41674167
41684168 for (BinarySection &Section : BC->allocatableSections ()) {
@@ -4189,7 +4189,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
41894189 NewSection.sh_link = 0 ;
41904190 NewSection.sh_info = 0 ;
41914191 NewSection.sh_addralign = Section.getAlignment ();
4192- addSection (NewSection, & Section);
4192+ addSection (NewSection, Section);
41934193 }
41944194
41954195 // Sort all allocatable sections by their offset.
@@ -4203,19 +4203,19 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
42034203 for (auto &SectionKV : OutputSections) {
42044204 ELFShdrTy &Section = SectionKV.second ;
42054205
4206- // TBSS section does not take file or memory space. Ignore it for layout
4207- // purposes.
4208- if (Section.sh_type == ELF::SHT_NOBITS && (Section.sh_flags & ELF::SHF_TLS))
4206+ // Ignore TLS sections as they don't take any space in the file.
4207+ if (Section.sh_type == ELF::SHT_NOBITS)
42094208 continue ;
42104209
4210+ // Note that address continuity is not guaranteed as sections could be
4211+ // placed in different loadable segments.
42114212 if (PrevSection &&
4212- PrevSection->sh_addr + PrevSection->sh_size > Section.sh_addr ) {
4213- if (opts::Verbosity > 1 )
4213+ PrevSection->sh_offset + PrevSection->sh_size > Section.sh_offset ) {
4214+ if (opts::Verbosity > 1 ) {
42144215 outs () << " BOLT-INFO: adjusting size for section "
42154216 << PrevBinSec->getOutputName () << ' \n ' ;
4216- PrevSection->sh_size = Section.sh_addr > PrevSection->sh_addr
4217- ? Section.sh_addr - PrevSection->sh_addr
4218- : 0 ;
4217+ }
4218+ PrevSection->sh_size = Section.sh_offset - PrevSection->sh_offset ;
42194219 }
42204220
42214221 PrevSection = &Section;
@@ -4249,7 +4249,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
42494249 if (NewSection.sh_type == ELF::SHT_SYMTAB)
42504250 NewSection.sh_info = NumLocalSymbols;
42514251
4252- addSection (NewSection, BinSec);
4252+ addSection (NewSection, * BinSec);
42534253
42544254 LastFileOffset = BinSec->getOutputFileOffset ();
42554255 }
@@ -4274,7 +4274,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
42744274 NewSection.sh_info = 0 ;
42754275 NewSection.sh_addralign = Section.getAlignment ();
42764276
4277- addSection (NewSection, & Section);
4277+ addSection (NewSection, Section);
42784278 }
42794279
42804280 // Assign indices to sections.
0 commit comments