<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 2, 2017 at 3:26 PM, Rui Ueyama 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: ruiu<br>
Date: Thu Feb  2 17:26:12 2017<br>
New Revision: 293963<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=293963&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=293963&view=rev</a><br>
Log:<br>
Update comments.<br>
<br>
Modified:<br>
    lld/trunk/ELF/LinkerScript.cpp<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=293963&r1=293962&r2=293963&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.cpp?rev=293963&<wbr>r1=293962&r2=293963&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Thu Feb  2 17:26:12 2017<br>
@@ -696,9 +696,28 @@ static bool shouldSkip(const BaseCommand<br>
   return Assign->Name != ".";<br>
 }<br>
<br>
-// Orphan sections are sections present in the input files which are not<br>
-// explicitly placed into the output file by the linker script. This just<br>
-// places them in the order already decided in OutputSections.<br>
+// Orphan sections are sections present in the input files which are<br>
+// not explicitly placed into the output file by the linker script.<br>
+//<br>
+// When the control reaches this function, Opt.Commands contains<br>
+// output section commands for non-orphan sections only. This function<br>
+// adds new elements for orphan sections to Opt.Commands so that all<br>
+// sections are explicitly handled by Opt.Commands.<br>
+//<br>
+// Writer<ELFT>::sortSections has already sorted output sections.<br>
+// What we need to do is to scan OutputSections vector and<br>
+// Opt.Commands in parallel to find orphan sections. If there is an<br>
+// output section that doesn't have a corresponding entry in<br>
+// Opt.Commands, we will insert a new entry to Opt.Commands.<br>
+//<br>
+// There is some ambiguity as to where exactly a new entry should be<br>
+// inserted, because Opt.Commands contains not only output section<br>
+// commands but other types of commands such as symbol assignment<br>
+// expressions. There's no correct answer here due to the lack of the<br>
+// formal specification of the linker script. We use heuristics to<br>
+// determine whether a new output command should be added before or<br>
+// after another commands. For the details, look at shouldSkip<br>
+// function.<br></blockquote><div><br></div><div>Can you mention compatibility with BFD/gold? IIRC orphan section handling was one of the issues with linking a working FreeBSD kernel. Also IIRC the GNU linkers actually have a well-defined default behavior (See --orphan-handling=MODE in <a href="https://sourceware.org/binutils/docs/ld/Options.html#Options">https://sourceware.org/binutils/docs/ld/Options.html#Options</a> and <a href="https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections">https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections</a>)</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 template <class ELFT> void LinkerScript<ELFT>::<wbr>placeOrphanSections() {<br>
   // The OutputSections are already in the correct order.<br>
   // This loops creates or moves commands as needed so that they are in the<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></div>