@@ -4141,10 +4141,10 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
4141
4141
4142
4142
// Keep track of section header entries attached to the corresponding section.
4143
4143
std::vector<std::pair<BinarySection *, ELFShdrTy>> OutputSections;
4144
- auto addSection = [&](const ELFShdrTy &Section, BinarySection * BinSec) {
4144
+ auto addSection = [&](const ELFShdrTy &Section, BinarySection & BinSec) {
4145
4145
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));
4148
4148
};
4149
4149
4150
4150
// Copy over entries for original allocatable sections using modified name.
@@ -4162,7 +4162,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
4162
4162
BinarySection *BinSec = BC->getSectionForSectionRef (SecRef);
4163
4163
assert (BinSec && " Matching BinarySection should exist." );
4164
4164
4165
- addSection (Section, BinSec);
4165
+ addSection (Section, * BinSec);
4166
4166
}
4167
4167
4168
4168
for (BinarySection &Section : BC->allocatableSections ()) {
@@ -4189,7 +4189,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
4189
4189
NewSection.sh_link = 0 ;
4190
4190
NewSection.sh_info = 0 ;
4191
4191
NewSection.sh_addralign = Section.getAlignment ();
4192
- addSection (NewSection, & Section);
4192
+ addSection (NewSection, Section);
4193
4193
}
4194
4194
4195
4195
// Sort all allocatable sections by their offset.
@@ -4203,19 +4203,19 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
4203
4203
for (auto &SectionKV : OutputSections) {
4204
4204
ELFShdrTy &Section = SectionKV.second ;
4205
4205
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)
4209
4208
continue ;
4210
4209
4210
+ // Note that address continuity is not guaranteed as sections could be
4211
+ // placed in different loadable segments.
4211
4212
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 ) {
4214
4215
outs () << " BOLT-INFO: adjusting size for section "
4215
4216
<< 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 ;
4219
4219
}
4220
4220
4221
4221
PrevSection = &Section;
@@ -4249,7 +4249,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
4249
4249
if (NewSection.sh_type == ELF::SHT_SYMTAB)
4250
4250
NewSection.sh_info = NumLocalSymbols;
4251
4251
4252
- addSection (NewSection, BinSec);
4252
+ addSection (NewSection, * BinSec);
4253
4253
4254
4254
LastFileOffset = BinSec->getOutputFileOffset ();
4255
4255
}
@@ -4274,7 +4274,7 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
4274
4274
NewSection.sh_info = 0 ;
4275
4275
NewSection.sh_addralign = Section.getAlignment ();
4276
4276
4277
- addSection (NewSection, & Section);
4277
+ addSection (NewSection, Section);
4278
4278
}
4279
4279
4280
4280
// Assign indices to sections.
0 commit comments