forked from OSchip/llvm-project
Move clearOutputSections earlier.
Now removeUnusedSyntheticSections operates entirely on the linker script. llvm-svn: 307043
This commit is contained in:
parent
bdfb3b1d5f
commit
c080ff64dc
|
|
@ -1132,7 +1132,7 @@ static void applySynthetic(const std::vector<SyntheticSection *> &Sections,
|
|||
// to make them visible from linkescript side. But not all sections are always
|
||||
// required to be in output. For example we don't need dynamic section content
|
||||
// sometimes. This function filters out such unused sections from the output.
|
||||
static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) {
|
||||
static void removeUnusedSyntheticSections() {
|
||||
// All input synthetic sections that can be empty are placed after
|
||||
// all regular ones. We iterate over them all and exit at first
|
||||
// non-synthetic.
|
||||
|
|
@ -1145,12 +1145,24 @@ static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) {
|
|||
continue;
|
||||
if ((SS == InX::Got || SS == InX::MipsGot) && ElfSym::GlobalOffsetTable)
|
||||
continue;
|
||||
OS->Sections.erase(std::find(OS->Sections.begin(), OS->Sections.end(), SS));
|
||||
SS->Live = false;
|
||||
|
||||
OutputSectionCommand *Cmd = Script->getCmd(OS);
|
||||
BaseCommand **Empty = nullptr;
|
||||
for (BaseCommand *&B : Cmd->Commands) {
|
||||
if (auto *ISD = dyn_cast<InputSectionDescription>(B)) {
|
||||
auto I = std::find(ISD->Sections.begin(), ISD->Sections.end(), SS);
|
||||
if (I != ISD->Sections.end())
|
||||
ISD->Sections.erase(I);
|
||||
if (ISD->Sections.empty())
|
||||
Empty = &B;
|
||||
}
|
||||
}
|
||||
if (Empty)
|
||||
Cmd->Commands.erase(std::vector<BaseCommand *>::iterator(Empty));
|
||||
|
||||
// If there are no other sections in the output section, remove it from the
|
||||
// output.
|
||||
if (OS->Sections.empty()) {
|
||||
V.erase(std::find(V.begin(), V.end(), OS));
|
||||
if (Cmd->Commands.empty()) {
|
||||
// Also remove script commands matching the output section.
|
||||
auto &Cmds = Script->Opt.Commands;
|
||||
auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) {
|
||||
|
|
@ -1227,9 +1239,9 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
|||
return;
|
||||
|
||||
addPredefinedSections();
|
||||
removeUnusedSyntheticSections(OutputSections);
|
||||
|
||||
clearOutputSections();
|
||||
removeUnusedSyntheticSections();
|
||||
|
||||
sortSections();
|
||||
|
||||
// Now that we have the final list, create a list of all the
|
||||
|
|
|
|||
Loading…
Reference in New Issue