<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 12, 2016 at 5:31 AM, Eugene Leviant 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: evgeny777<br>
Date: Wed Oct 12 07:31:34 2016<br>
New Revision: 284010<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284010&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=284010&view=rev</a><br>
Log:<br>
Alternative fix for reloc tareting discarded section<br>
<br>
r283984 introduced a problem of too many warning messages being shown<br>
when -ffunction-sections and -fdata-sections were used in conjunction<br>
with --gc-sections linker flag and debugging information present. This<br>
happens because lot of relocations from .debug_line section may become<br>
invalid in such case. The newer fix doesn't show any warning message but<br>
zeroes OutSec pointer in createInputSectionList() to avoid crash, when<br>
relocations are written<br>
<br>
Modified:<br>
    lld/trunk/ELF/LinkerScript.cpp<br>
    lld/trunk/ELF/Symbols.cpp<br>
    lld/trunk/test/ELF/<wbr>linkerscript/discard-section.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=284010&r1=284009&r2=284010&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.cpp?rev=284010&<wbr>r1=284009&r2=284010&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Wed Oct 12 07:31:34 2016<br>
@@ -239,6 +239,12 @@ LinkerScript<ELFT>::<wbr>createInputSectionLi<br>
       Ret.push_back(static_cast<<wbr>InputSectionBase<ELFT> *>(S));<br>
   }<br>
<br>
+  // After we created final list we should now set OutSec pointer to null,<br>
+  // instead of -1. Otherwise we may get a crash when writing relocs, in<br>
+  // case section is discarded by linker script<br>
+  for (InputSectionBase<ELFT> *S : Ret)<br>
+    S->OutSec = nullptr;<br>
</blockquote><div><br></div><div>I was thinking that it is an invariant that InputSection::OutSec always points to an output section if the input section is included in the output section, so I'm confused with this code and comment. How does it work?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+<br>
   return Ret;<br>
 }<br>
<br>
<br>
Modified: lld/trunk/ELF/Symbols.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=284010&r1=284009&r2=284010&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Symbols.<wbr>cpp?rev=284010&r1=284009&r2=<wbr>284010&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Symbols.cpp (original)<br>
+++ lld/trunk/ELF/Symbols.cpp Wed Oct 12 07:31:34 2016<br>
@@ -25,12 +25,6 @@ using namespace lld;<br>
 using namespace lld::elf;<br>
<br>
 template <class ELFT><br>
-static std::string getSectionName(<wbr>InputSectionBase<ELFT> *S) {<br>
-  StringRef Filename = S->getFile()->getName();<br>
-  return (sys::path::filename(Filename) + "(" + S->Name + ")").str();<br>
-}<br>
-<br>
-template <class ELFT><br>
 static typename ELFT::uint getSymVA(const SymbolBody &Body,<br>
                                     typename ELFT::uint &Addend) {<br>
   typedef typename ELFT::uint uintX_t;<br>
@@ -60,11 +54,6 @@ static typename ELFT::uint getSymVA(cons<br>
     if (!SC)<br>
       return D.Value;<br>
<br>
-    if (!SC->Live) {<br>
-      warn("relocation refers to discarded section '" + getSectionName(SC) + "'");<br>
-      return 0;<br>
-    }<br>
-<br>
     uintX_t Offset = D.Value;<br>
     if (D.isSection()) {<br>
       Offset += Addend;<br>
<br>
Modified: lld/trunk/test/ELF/<wbr>linkerscript/discard-section.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/discard-section.s?rev=284010&r1=284009&r2=284010&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/ELF/<wbr>linkerscript/discard-section.<wbr>s?rev=284010&r1=284009&r2=<wbr>284010&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/<wbr>linkerscript/discard-section.s (original)<br>
+++ lld/trunk/test/ELF/<wbr>linkerscript/discard-section.s Wed Oct 12 07:31:34 2016<br>
@@ -1,10 +1,9 @@<br>
 # REQUIRES: x86<br>
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
 # RUN: echo "SECTIONS { /DISCARD/ : { *(.aaa*) } }" > %t.script<br>
-# RUN: ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=WARN %s<br>
+# RUN: ld.lld -o %t1 --script %t.script %t<br>
 # RUN: llvm-objdump -section-headers %t1 | FileCheck %s<br>
<br>
-# WARN: relocation refers to discarded section {{.+}}(.aaa)<br>
 # CHECK-NOT: .aaa<br>
<br>
 .section .aaa,"a"<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>