Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lld/ELF/LinkerScript.cpp
Show First 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | for (const SectionPattern &Pat : Cmd->SectionPatterns) { | ||||
sortInputSections(MutableArrayRef<InputSection *>(Ret).slice(SizeBefore), | sortInputSections(MutableArrayRef<InputSection *>(Ret).slice(SizeBefore), | ||||
Pat); | Pat); | ||||
} | } | ||||
return Ret; | return Ret; | ||||
} | } | ||||
void LinkerScript::discard(ArrayRef<InputSection *> V) { | void LinkerScript::discard(ArrayRef<InputSection *> V) { | ||||
for (InputSection *S : V) { | for (InputSection *S : V) { | ||||
if (S == In.ShStrTab || S == In.RelaDyn || S == In.RelrDyn) | if (S == In.ShStrTab || S == Main->RelaDyn || S == Main->RelrDyn) | ||||
error("discarding " + S->Name + " section is not allowed"); | error("discarding " + S->Name + " section is not allowed"); | ||||
// You can discard .hash and .gnu.hash sections by linker scripts. Since | // You can discard .hash and .gnu.hash sections by linker scripts. Since | ||||
// they are synthesized sections, we need to handle them differently than | // they are synthesized sections, we need to handle them differently than | ||||
// other regular sections. | // other regular sections. | ||||
if (S == In.GnuHashTab) | if (S == Main->GnuHashTab) | ||||
In.GnuHashTab = nullptr; | Main->GnuHashTab = nullptr; | ||||
if (S == In.HashTab) | if (S == Main->HashTab) | ||||
In.HashTab = nullptr; | Main->HashTab = nullptr; | ||||
S->Assigned = false; | S->Assigned = false; | ||||
S->markDead(); | S->markDead(); | ||||
discard(S->DependentSections); | discard(S->DependentSections); | ||||
} | } | ||||
} | } | ||||
std::vector<InputSection *> | std::vector<InputSection *> | ||||
▲ Show 20 Lines • Show All 465 Lines • ▼ Show 20 Lines | for (BaseCommand *&Cmd : SectionCommands) { | ||||
bool IsEmpty = getInputSections(Sec).empty(); | bool IsEmpty = getInputSections(Sec).empty(); | ||||
if (IsEmpty) | if (IsEmpty) | ||||
Sec->Flags = Flags & ((Sec->NonAlloc ? 0 : (uint64_t)SHF_ALLOC) | | Sec->Flags = Flags & ((Sec->NonAlloc ? 0 : (uint64_t)SHF_ALLOC) | | ||||
SHF_WRITE | SHF_EXECINSTR); | SHF_WRITE | SHF_EXECINSTR); | ||||
if (IsEmpty && isDiscardable(*Sec)) { | if (IsEmpty && isDiscardable(*Sec)) { | ||||
Sec->markDead(); | Sec->markDead(); | ||||
Cmd = nullptr; | Cmd = nullptr; | ||||
} else if (!Sec->isLive()) { | |||||
Sec->markLive(); | |||||
} | } | ||||
} | } | ||||
// It is common practice to use very generic linker scripts. So for any | // It is common practice to use very generic linker scripts. So for any | ||||
// given run some of the output sections in the script will be empty. | // given run some of the output sections in the script will be empty. | ||||
// We could create corresponding empty output sections, but that would | // We could create corresponding empty output sections, but that would | ||||
// clutter the output. | // clutter the output. | ||||
// We instead remove trivially empty sections. The bfd linker seems even | // We instead remove trivially empty sections. The bfd linker seems even | ||||
▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines |