[PATCH] D23571: [ELF] Linkerscript: never add same input section to output section

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 16 09:42:00 PDT 2016


evgeny777 created this revision.
evgeny777 added a reviewer: ruiu.
evgeny777 added subscribers: ikudrin, grimar, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.

Sometimes script contains the following:

```
.foo : {
   a.o(.foo)
   *(.foo)
}
```
This script must add .foo section from a.o first and all others after that
Without this patch .foo section from a.o will be added twice

Repository:
  rL LLVM

https://reviews.llvm.org/D23571

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/linkerscript-input-sec-dup.s

Index: test/ELF/linkerscript/linkerscript-input-sec-dup.s
===================================================================
--- test/ELF/linkerscript/linkerscript-input-sec-dup.s
+++ test/ELF/linkerscript/linkerscript-input-sec-dup.s
@@ -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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -284,7 +284,8 @@
       if (IsNew)
         OutputSections->push_back(OutSec);
       for (InputSectionBase<ELFT> *Sec : V)
-        OutSec->addSection(Sec);
+        if (!Sec->OutSec)
+          OutSec->addSection(Sec);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23571.68206.patch
Type: text/x-patch
Size: 1237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160816/11ebed02/attachment.bin>


More information about the llvm-commits mailing list