lld: Put the header in the first PT_LOAD even if that PT_LOAD has a LMAExpr
The root problem is that we were creating a PT_LOAD just for the header. That was technically valid, but inconvenient: we should not be making the ELF discontinuous. The solution is to allow a section with LMAExpr to be added to a PT_LOAD if that PT_LOAD doesn't already have a LMAExpr. LLVM PR: 36017 Obtained from: LLVM r323625 by Rafael Espindola
This commit is contained in:
parent
2f81b33ec9
commit
717143875c
@ -822,6 +822,8 @@ void PhdrEntry::add(OutputSection *Sec) {
|
||||
p_align = std::max(p_align, Sec->Alignment);
|
||||
if (p_type == PT_LOAD)
|
||||
Sec->PtLoad = this;
|
||||
if (Sec->LMAExpr)
|
||||
ASectionHasLMA = true;
|
||||
}
|
||||
|
||||
// The beginning and the ending of .rel[a].plt section are marked
|
||||
@ -1626,8 +1628,9 @@ template <class ELFT> std::vector<PhdrEntry *> Writer<ELFT>::createPhdrs() {
|
||||
// different flags or is loaded at a discontiguous address using AT linker
|
||||
// script command.
|
||||
uint64_t NewFlags = computeFlags(Sec->getPhdrFlags());
|
||||
if (Sec->LMAExpr || Sec->MemRegion != Load->FirstSec->MemRegion ||
|
||||
Flags != NewFlags) {
|
||||
if ((Sec->LMAExpr && Load->ASectionHasLMA) ||
|
||||
Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags) {
|
||||
|
||||
Load = AddHdr(PT_LOAD, NewFlags);
|
||||
Flags = NewFlags;
|
||||
}
|
||||
|
@ -44,6 +44,11 @@ struct PhdrEntry {
|
||||
OutputSection *FirstSec = nullptr;
|
||||
OutputSection *LastSec = nullptr;
|
||||
bool HasLMA = false;
|
||||
|
||||
// True if any of the sections in this program header as a LMA specified via
|
||||
// linker script: AT(addr).
|
||||
bool ASectionHasLMA = false;
|
||||
|
||||
uint64_t LMAOffset = 0;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user