[lld] r279036 - [ELF] Don't add input sections twice when linker script is used

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 00:27:38 PDT 2016


Author: evgeny777
Date: Thu Aug 18 02:27:37 2016
New Revision: 279036

URL: http://llvm.org/viewvc/llvm-project?rev=279036&view=rev
Log:
[ELF] Don't add input sections twice when linker script is used

Added:
    lld/trunk/test/ELF/linkerscript/linkerscript-input-sec-dup.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=279036&r1=279035&r2=279036&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Aug 18 02:27:37 2016
@@ -284,7 +284,8 @@ void LinkerScript<ELFT>::createSections(
       if (IsNew)
         OutputSections->push_back(OutSec);
       for (InputSectionBase<ELFT> *Sec : V)
-        OutSec->addSection(Sec);
+        if (!Sec->OutSec)
+          OutSec->addSection(Sec);
     }
   }
 

Added: lld/trunk/test/ELF/linkerscript/linkerscript-input-sec-dup.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-input-sec-dup.s?rev=279036&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-input-sec-dup.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-input-sec-dup.s Thu Aug 18 02:27:37 2016
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: echo "SECTIONS {.foo : { *(.foo) *(.foo) } }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+# CHECK:      Sections:
+# CHECK-NEXT: Idx Name          Size      Address          Type
+# CHECK-NEXT:   0               00000000 0000000000000000
+# CHECK-NEXT:   1 .foo          00000004 0000000000000120 DATA
+# CHECK-NEXT:   2 .text         00000001 0000000000000124 TEXT DATA
+
+.global _start
+_start:
+ nop
+
+.section .foo,"a"
+ .long 0




More information about the llvm-commits mailing list