[lld] r278657 - [ELF] Do not add start and end symbols in case they are already defined

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 00:24:21 PDT 2016


Author: evgeny777
Date: Mon Aug 15 02:24:20 2016
New Revision: 278657

URL: http://llvm.org/viewvc/llvm-project?rev=278657&view=rev
Log:
[ELF] Do not add start and end symbols in case they are already defined

Added:
    lld/trunk/test/ELF/linkerscript/linkerscript-start-end.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=278657&r1=278656&r2=278657&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 15 02:24:20 2016
@@ -521,6 +521,13 @@ static Symbol *addOptionalSynthetic(Stri
   return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
 }
 
+template <class ELFT>
+static void addSynthetic(StringRef Name, OutputSectionBase<ELFT> *Sec,
+                                 typename ELFT::uint Val) {
+  SymbolBody *S = Symtab<ELFT>::X->find(Name);
+  if (!S || S->isUndefined() || S->isShared())
+    Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
+}
 // The beginning and the ending of .rel[a].plt section are marked
 // with __rel[a]_iplt_{start,end} symbols if it is a statically linked
 // executable. The runtime needs these symbols in order to resolve
@@ -856,9 +863,8 @@ template <class ELFT> void Writer<ELFT>:
   auto Define = [&](StringRef Start, StringRef End,
                     OutputSectionBase<ELFT> *OS) {
     if (OS) {
-      Symtab<ELFT>::X->addSynthetic(Start, OS, 0);
-      Symtab<ELFT>::X->addSynthetic(End, OS,
-                                    DefinedSynthetic<ELFT>::SectionEnd);
+      addSynthetic(Start, OS, 0);
+      addSynthetic(End, OS, DefinedSynthetic<ELFT>::SectionEnd);
     } else {
       addOptionalSynthetic(Start, (OutputSectionBase<ELFT> *)nullptr, 0);
       addOptionalSynthetic(End, (OutputSectionBase<ELFT> *)nullptr, 0);

Added: lld/trunk/test/ELF/linkerscript/linkerscript-start-end.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-start-end.s?rev=278657&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-start-end.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-start-end.s Mon Aug 15 02:24:20 2016
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { \
+# RUN:      .init_array : { \
+# RUN:        __init_array_start = .; \
+# RUN:        *(.init_array) \
+# RUN:        __init_array_end = .; } }" > %t.script
+# RUN: ld.lld %t.o -script %t.script -o %t 2>&1
+
+.globl _start
+.text
+_start:
+  nop
+
+.section .init_array, "aw"
+  .quad 0




More information about the llvm-commits mailing list