[ELF] Extract allocateHeaders() from assignAddresses()
The allocateHeaders() function is called at the end of assignAddresses(), it decides whether the ELF header and program header table can be allocated to a PT_LOAD program header. As the function alters state, it prevents assignAddresses() from being called multiple times. This change splits out the call to allocateHeaders() from assignAddresses() this will permit assignAddresses() to be called while processing range extension thunks without trying to allocateHeaders(). Differential Revision: https://reviews.llvm.org/D34344 llvm-svn: 307131
This commit is contained in:
parent
040c0f96cc
commit
5aedebff38
|
@ -783,10 +783,14 @@ void LinkerScript::processNonSectionCommands() {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
allocateHeaders(std::vector<PhdrEntry> &Phdrs,
|
||||
ArrayRef<OutputSectionCommand *> OutputSectionCommands,
|
||||
uint64_t Min) {
|
||||
void LinkerScript::allocateHeaders(std::vector<PhdrEntry> &Phdrs) {
|
||||
uint64_t Min = std::numeric_limits<uint64_t>::max();
|
||||
for (OutputSectionCommand *Cmd : OutputSectionCommands) {
|
||||
OutputSection *Sec = Cmd->Sec;
|
||||
if (Sec->Flags & SHF_ALLOC)
|
||||
Min = std::min<uint64_t>(Min, Sec->Addr);
|
||||
}
|
||||
|
||||
auto FirstPTLoad = llvm::find_if(
|
||||
Phdrs, [](const PhdrEntry &E) { return E.p_type == PT_LOAD; });
|
||||
if (FirstPTLoad == Phdrs.end())
|
||||
|
@ -826,7 +830,7 @@ allocateHeaders(std::vector<PhdrEntry> &Phdrs,
|
|||
Phdrs.erase(PhdrI);
|
||||
}
|
||||
|
||||
void LinkerScript::assignAddresses(std::vector<PhdrEntry> &Phdrs) {
|
||||
void LinkerScript::assignAddresses() {
|
||||
// Assign addresses as instructed by linker script SECTIONS sub-commands.
|
||||
Dot = 0;
|
||||
ErrorOnMissingSection = true;
|
||||
|
@ -846,15 +850,6 @@ void LinkerScript::assignAddresses(std::vector<PhdrEntry> &Phdrs) {
|
|||
auto *Cmd = cast<OutputSectionCommand>(Base);
|
||||
assignOffsets(Cmd);
|
||||
}
|
||||
|
||||
uint64_t MinVA = std::numeric_limits<uint64_t>::max();
|
||||
for (OutputSectionCommand *Cmd : OutputSectionCommands) {
|
||||
OutputSection *Sec = Cmd->Sec;
|
||||
if (Sec->Flags & SHF_ALLOC)
|
||||
MinVA = std::min<uint64_t>(MinVA, Sec->Addr);
|
||||
}
|
||||
|
||||
allocateHeaders(Phdrs, OutputSectionCommands, MinVA);
|
||||
}
|
||||
|
||||
// Creates program headers as instructed by PHDRS linker script command.
|
||||
|
|
|
@ -281,8 +281,8 @@ public:
|
|||
void assignOffsets(OutputSectionCommand *Cmd);
|
||||
void createOrphanCommands();
|
||||
void processNonSectionCommands();
|
||||
void assignAddresses(std::vector<PhdrEntry> &Phdrs);
|
||||
|
||||
void assignAddresses();
|
||||
void allocateHeaders(std::vector<PhdrEntry> &Phdrs);
|
||||
void addSymbol(SymbolAssignment *Cmd);
|
||||
void processCommands(OutputSectionFactory &Factory);
|
||||
|
||||
|
|
|
@ -217,7 +217,8 @@ template <class ELFT> void Writer<ELFT>::run() {
|
|||
OutputSectionCommands.begin(), OutputSectionCommands.end(),
|
||||
[](OutputSectionCommand *Cmd) { Cmd->maybeCompress<ELFT>(); });
|
||||
|
||||
Script->assignAddresses(Phdrs);
|
||||
Script->assignAddresses();
|
||||
Script->allocateHeaders(Phdrs);
|
||||
|
||||
// Remove empty PT_LOAD to avoid causing the dynamic linker to try to mmap a
|
||||
// 0 sized region. This has to be done late since only after assignAddresses
|
||||
|
|
Loading…
Reference in New Issue