[PATCH] D23405: [ELF] Do not add start and end symbols in case they are defined in linker script

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 02:50:26 PDT 2016


evgeny777 removed rL LLVM as the repository for this revision.
evgeny777 updated this revision to Diff 67811.
evgeny777 added a comment.

Addressed review comments


https://reviews.llvm.org/D23405

Files:
  ELF/Writer.cpp
  test/ELF/linkerscript/linkerscript-start-end.s

Index: test/ELF/linkerscript/linkerscript-start-end.s
===================================================================
--- test/ELF/linkerscript/linkerscript-start-end.s
+++ test/ELF/linkerscript/linkerscript-start-end.s
@@ -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
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -521,6 +521,15 @@
   return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
 }
 
+template <class ELFT>
+static Symbol *addRequiredSynthetic(StringRef Name,
+                                    OutputSectionBase<ELFT> *Sec,
+                                    typename ELFT::uint Val) {
+  SymbolBody *S = Symtab<ELFT>::X->find(Name);
+  return (!S || S->isUndefined() || S->isShared())
+             ? Symtab<ELFT>::X->addSynthetic(Name, Sec, Val)
+             : S->symbol();
+}
 // 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 +865,8 @@
   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);
+      addRequiredSynthetic(Start, OS, 0);
+      addRequiredSynthetic(End, OS, DefinedSynthetic<ELFT>::SectionEnd);
     } else {
       addOptionalSynthetic(Start, (OutputSectionBase<ELFT> *)nullptr, 0);
       addOptionalSynthetic(End, (OutputSectionBase<ELFT> *)nullptr, 0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23405.67811.patch
Type: text/x-patch
Size: 2048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160812/33c6c0c1/attachment.bin>


More information about the llvm-commits mailing list