<div dir="ltr">Thanks! This is a nice change. I wonder if we could remove dead sections from the list as well. This will remove all "S->Live" checks, but it might slows it down a little bit because we have to shift section pointers in the vector.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 8, 2016 at 10:23 AM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Tue Nov 8 12:23:02 2016<br>
New Revision: 286261<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=286261&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=286261&view=rev</a><br>
Log:<br>
Don't add null and discarded sections to the global list.<br>
<br>
Avoids having to skip them multiple times.<br>
<br>
Modified:<br>
lld/trunk/ELF/Driver.cpp<br>
lld/trunk/ELF/ICF.cpp<br>
lld/trunk/ELF/LinkerScript.cpp<br>
lld/trunk/ELF/MarkLive.cpp<br>
lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=286261&r1=286260&r2=286261&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Driver.<wbr>cpp?rev=286261&r1=286260&r2=<wbr>286261&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Tue Nov 8 12:23:02 2016<br>
@@ -761,7 +761,8 @@ template <class ELFT> void LinkerDriver:<br>
// Aggregate all input sections into one place.<br>
for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())<br>
for (InputSectionBase<ELFT> *S : F->getSections())<br>
- Symtab.Sections.push_back(S);<br>
+ if (S && S != &InputSection<ELFT>::<wbr>Discarded)<br>
+ Symtab.Sections.push_back(S);<br>
for (BinaryFile *F : Symtab.getBinaryFiles())<br>
for (InputSectionData *S : F->getSections())<br>
Symtab.Sections.push_back(<wbr>cast<InputSection<ELFT>>(S));<br>
@@ -775,7 +776,7 @@ template <class ELFT> void LinkerDriver:<br>
// MergeInputSection::<wbr>splitIntoPieces needs to be called before<br>
// any call of MergeInputSection::getOffset. Do that.<br>
for (InputSectionBase<ELFT> *S : Symtab.Sections) {<br>
- if (!S || S == &InputSection<ELFT>::Discarded || !S->Live)<br>
+ if (!S->Live)<br>
continue;<br>
if (S->Compressed)<br>
S->uncompress();<br>
<br>
Modified: lld/trunk/ELF/ICF.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=286261&r1=286260&r2=286261&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/ICF.cpp?<wbr>rev=286261&r1=286260&r2=<wbr>286261&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/ICF.cpp (original)<br>
+++ lld/trunk/ELF/ICF.cpp Tue Nov 8 12:23:02 2016<br>
@@ -128,7 +128,7 @@ template <class ELFT> uint64_t ICF<ELFT><br>
<br>
// Returns true if Sec is subject of ICF.<br>
template <class ELFT> bool ICF<ELFT>::isEligible(<wbr>InputSectionBase<ELFT> *Sec) {<br>
- if (!Sec || Sec == &InputSection<ELFT>::Discarded || !Sec->Live)<br>
+ if (!Sec->Live)<br>
return false;<br>
auto *S = dyn_cast<InputSection<ELFT>>(<wbr>Sec);<br>
if (!S)<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=286261&r1=286260&r2=286261&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.cpp?rev=286261&<wbr>r1=286260&r2=286261&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Tue Nov 8 12:23:02 2016<br>
@@ -117,10 +117,6 @@ bool BytesDataCommand::classof(<wbr>const Bas<br>
return C->Kind == BytesDataKind;<br>
}<br>
<br>
-template <class ELFT> static bool isDiscarded(InputSectionBase<<wbr>ELFT> *S) {<br>
- return !S || !S->Live;<br>
-}<br>
-<br>
template <class ELFT> LinkerScript<ELFT>::<wbr>LinkerScript() = default;<br>
template <class ELFT> LinkerScript<ELFT>::~<wbr>LinkerScript() = default;<br>
<br>
@@ -195,7 +191,7 @@ void LinkerScript<ELFT>::<wbr>computeInputSec<br>
size_t SizeBefore = I->Sections.size();<br>
<br>
for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections) {<br>
- if (isDiscarded(S) || S->OutSec)<br>
+ if (!S->Live || S->OutSec)<br>
continue;<br>
<br>
StringRef Filename;<br>
@@ -368,7 +364,7 @@ void LinkerScript<ELFT>::<wbr>createSections(<br>
<br>
// Add orphan sections.<br>
for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections)<br>
- if (!isDiscarded(S) && !S->OutSec)<br>
+ if (S->Live && !S->OutSec)<br>
addSection(Factory, S, getOutputSectionName(S->Name))<wbr>;<br>
}<br>
<br>
<br>
Modified: lld/trunk/ELF/MarkLive.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=286261&r1=286260&r2=286261&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>MarkLive.cpp?rev=286261&r1=<wbr>286260&r2=286261&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/MarkLive.cpp (original)<br>
+++ lld/trunk/ELF/MarkLive.cpp Tue Nov 8 12:23:02 2016<br>
@@ -239,8 +239,6 @@ template <class ELFT> void elf::markLive<br>
// Preserve special sections and those which are specified in linker<br>
// script KEEP command.<br>
for (InputSectionBase<ELFT> *Sec : Symtab<ELFT>::X->Sections) {<br>
- if (!Sec || Sec == &InputSection<ELFT>::<wbr>Discarded)<br>
- continue;<br>
// .eh_frame is always marked as live now, but also it can reference to<br>
// sections that contain personality. We preserve all non-text sections<br>
// referred by .eh_frame here.<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=286261&r1=286260&r2=286261&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Writer.<wbr>cpp?rev=286261&r1=286260&r2=<wbr>286261&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Tue Nov 8 12:23:02 2016<br>
@@ -118,8 +118,7 @@ StringRef elf::getOutputSectionName(Stri<br>
}<br>
<br>
template <class ELFT> void elf::reportDiscarded(<wbr>InputSectionBase<ELFT> *IS) {<br>
- if (!Config->PrintGcSections || !IS || IS == &InputSection<ELFT>::Discarded ||<br>
- IS->Live)<br>
+ if (!Config->PrintGcSections)<br>
return;<br>
errs() << "removing unused section from '" << IS->Name << "' in file '"<br>
<< IS->getFile()->getName() << "'\n";<br>
@@ -512,10 +511,6 @@ static bool compareSections(const Output<br>
return compareSectionsNonScript(A, B);<br>
}<br>
<br>
-template <class ELFT> static bool isDiscarded(InputSectionBase<<wbr>ELFT> *S) {<br>
- return !S || S == &InputSection<ELFT>::Discarded || !S->Live;<br>
-}<br>
-<br>
// Program header entry<br>
template <class ELFT><br>
PhdrEntry<ELFT>::PhdrEntry(<wbr>unsigned Type, unsigned Flags) {<br>
@@ -653,7 +648,7 @@ void Writer<ELFT>::forEachRelSec(<br>
std::function<void(<wbr>InputSectionBase<ELFT> &, const typename ELFT::Shdr &)><br>
Fn) {<br>
for (InputSectionBase<ELFT> *IS : Symtab<ELFT>::X->Sections) {<br>
- if (isDiscarded(IS))<br>
+ if (!IS->Live)<br>
continue;<br>
// Scan all relocations. Each relocation goes through a series<br>
// of tests to determine if it needs special treatment, such as<br>
@@ -675,7 +670,7 @@ void Writer<ELFT>::forEachRelSec(<br>
<br>
template <class ELFT><br>
void Writer<ELFT>::addInputSec(<wbr>InputSectionBase<ELFT> *IS) {<br>
- if (isDiscarded(IS)) {<br>
+ if (!IS->Live) {<br>
reportDiscarded(IS);<br>
return;<br>
}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>