summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/Writer.cpp')
-rw-r--r--lld/ELF/Writer.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 28036d3dbeb..799580d9a27 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1131,11 +1131,9 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
// list, but have them to simplify the code.
template <class ELFT> void Writer<ELFT>::fixHeaders() {
uintX_t BaseVA = ScriptConfig->DoLayout ? 0 : Target->getVAStart();
- Out<ELFT>::ElfHeader->setVA(BaseVA);
- Out<ELFT>::ElfHeader->setFileOffset(0);
+ Out<ELFT>::ElfHeader->setVA(BaseVA);
uintX_t Off = Out<ELFT>::ElfHeader->getSize();
- Out<ELFT>::ProgramHeaders->setVA(Off + BaseVA);
- Out<ELFT>::ProgramHeaders->setFileOffset(Off);
+ Out<ELFT>::ProgramHeaders->setVA(Off + BaseVA);
}
// Assign VAs (addresses at run-time) to output sections.
@@ -1183,19 +1181,24 @@ static uintX_t getFileAlignment(uintX_t Off, OutputSectionBase<ELFT> *Sec) {
// Assign file offsets to output sections.
template <class ELFT> void Writer<ELFT>::assignFileOffsets() {
- uintX_t Off =
- Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
+ uintX_t Off = 0;
- for (OutputSectionBase<ELFT> *Sec : OutputSections) {
+ auto Set = [&](OutputSectionBase<ELFT> *Sec) {
if (Sec->getType() == SHT_NOBITS) {
Sec->setFileOffset(Off);
- continue;
+ return;
}
Off = getFileAlignment<ELFT>(Off, Sec);
Sec->setFileOffset(Off);
Off += Sec->getSize();
- }
+ };
+
+ Set(Out<ELFT>::ElfHeader);
+ Set(Out<ELFT>::ProgramHeaders);
+ for (OutputSectionBase<ELFT> *Sec : OutputSections)
+ Set(Sec);
+
SectionHeaderOff = alignTo(Off, sizeof(uintX_t));
FileSize = SectionHeaderOff + (OutputSections.size() + 1) * sizeof(Elf_Shdr);
}
OpenPOWER on IntegriCloud