mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 10:58:11 +08:00
[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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user