Skip to content

Commit fa4d186

Browse files
committed
[ELF] Move PhdrEntry to SyntheticSections
The next change will change Partition::phdrs to a unique_ptr vector, which requires PhdrEntry to be a complete type. And make OutputSection::getLMA out-of-line, since it should not include either SyntheticSections.h or Writer.h.
1 parent c6bce68 commit fa4d186

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

lld/ELF/OutputSections.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ OutputSection::OutputSection(Ctx &ctx, StringRef name, uint32_t type,
7272
/*info=*/0, /*link=*/0),
7373
ctx(ctx) {}
7474

75+
uint64_t OutputSection::getLMA() const {
76+
return ptLoad ? addr + ptLoad->lmaOffset : addr;
77+
}
78+
7579
// We allow sections of types listed below to merged into a
7680
// single progbits section. This is typically done by linker
7781
// scripts. Merging nobits and progbits will force disk space

lld/ELF/OutputSections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class OutputSection final : public SectionBase {
4141
return s->kind() == SectionBase::Output;
4242
}
4343

44-
uint64_t getLMA() const { return ptLoad ? addr + ptLoad->lmaOffset : addr; }
44+
uint64_t getLMA() const;
4545
template <typename ELFT> void writeHeaderTo(typename ELFT::Shdr *sHdr);
4646

4747
Ctx &ctx;

lld/ELF/SyntheticSections.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,31 @@ Defined *addSyntheticLocal(Ctx &ctx, StringRef name, uint8_t type,
14391439

14401440
void addVerneed(Ctx &, Symbol &ss);
14411441

1442+
// This describes a program header entry.
1443+
// Each contains type, access flags and range of output sections that will be
1444+
// placed in it.
1445+
struct PhdrEntry {
1446+
PhdrEntry(Ctx &ctx, unsigned type, unsigned flags)
1447+
: p_align(type == llvm::ELF::PT_LOAD ? ctx.arg.maxPageSize : 0),
1448+
p_type(type), p_flags(flags) {}
1449+
void add(OutputSection *sec);
1450+
1451+
uint64_t p_paddr = 0;
1452+
uint64_t p_vaddr = 0;
1453+
uint64_t p_memsz = 0;
1454+
uint64_t p_filesz = 0;
1455+
uint64_t p_offset = 0;
1456+
uint32_t p_align = 0;
1457+
uint32_t p_type = 0;
1458+
uint32_t p_flags = 0;
1459+
1460+
OutputSection *firstSec = nullptr;
1461+
OutputSection *lastSec = nullptr;
1462+
bool hasLMA = false;
1463+
1464+
uint64_t lmaOffset = 0;
1465+
};
1466+
14421467
// Linker generated per-partition sections.
14431468
struct Partition {
14441469
Ctx &ctx;

lld/ELF/Writer.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,12 @@
1010
#define LLD_ELF_WRITER_H
1111

1212
#include "Config.h"
13-
#include "llvm/ADT/StringRef.h"
14-
#include <cstdint>
1513

1614
namespace lld::elf {
17-
class InputFile;
1815
class OutputSection;
1916
void copySectionsIntoPartitions(Ctx &ctx);
2017
template <class ELFT> void writeResult(Ctx &ctx);
2118

22-
// This describes a program header entry.
23-
// Each contains type, access flags and range of output sections that will be
24-
// placed in it.
25-
struct PhdrEntry {
26-
PhdrEntry(Ctx &ctx, unsigned type, unsigned flags)
27-
: p_align(type == llvm::ELF::PT_LOAD ? ctx.arg.maxPageSize : 0),
28-
p_type(type), p_flags(flags) {}
29-
void add(OutputSection *sec);
30-
31-
uint64_t p_paddr = 0;
32-
uint64_t p_vaddr = 0;
33-
uint64_t p_memsz = 0;
34-
uint64_t p_filesz = 0;
35-
uint64_t p_offset = 0;
36-
uint32_t p_align = 0;
37-
uint32_t p_type = 0;
38-
uint32_t p_flags = 0;
39-
40-
OutputSection *firstSec = nullptr;
41-
OutputSection *lastSec = nullptr;
42-
bool hasLMA = false;
43-
44-
uint64_t lmaOffset = 0;
45-
};
46-
4719
void addReservedSymbols(Ctx &ctx);
4820
bool includeInSymtab(Ctx &, const Symbol &);
4921
unsigned getSectionRank(Ctx &, OutputSection &osec);

0 commit comments

Comments
 (0)