[PATCH] D28561: [ELF] - Move the addition of synthetics from addPredefinedSections()

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 06:16:07 PST 2017


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

These were 3 last synthetics that were added in addPredefinedSections() instead
of createSyntheticSections(). Now it is possible to move addition to correct common place.

Also patch fixes testcase which discards .shstrtab, what became possible after that patch.
(and did not work before)


https://reviews.llvm.org/D28561

Files:
  ELF/Writer.cpp
  test/ELF/linkerscript/sections.s


Index: test/ELF/linkerscript/sections.s
===================================================================
--- test/ELF/linkerscript/sections.s
+++ test/ELF/linkerscript/sections.s
@@ -66,22 +66,21 @@
 # SEC-SWAP-NAMES: 7 .shstrtab     0000003b {{[0-9a-f]*}}
 # SEC-SWAP-NAMES: 8 .strtab       00000008 {{[0-9a-f]*}}
 
-# .shstrtab from the input object file is discarded.
+# .shstrtab is discarded.
 # RUN: echo "SECTIONS { \
 # RUN:          /DISCARD/ : { *(.shstrtab) } }" > %t.script
 # RUN: ld.lld -o %t5 --script %t.script %t
 # RUN: llvm-objdump -section-headers %t5 | \
 # RUN:   FileCheck -check-prefix=SEC-DISCARD %s
 
 #             Idx Name          Size
-# SEC-DISCARD: 1 .text         0000000e {{[0-9a-f]*}} TEXT DATA
-# SEC-DISCARD: 2 .data         00000020 {{[0-9a-f]*}} DATA
-# SEC-DISCARD: 3 other         00000003 {{[0-9a-f]*}} DATA
-# SEC-DISCARD: 4 .bss          00000002 {{[0-9a-f]*}} BSS
-# SEC-DISCARD: 5 .comment      00000008 {{[0-9a-f]*}}
-# SEC-DISCARD: 6 .symtab       00000030 {{[0-9a-f]*}}
-# SEC-DISCARD: 7 .shstrtab     0000003b {{[0-9a-f]*}}
-# SEC-DISCARD: 8 .strtab       00000008 {{[0-9a-f]*}}
+# SEC-DISCARD: 1 <no-name>     0000000e {{[0-9a-f]*}} TEXT DATA
+# SEC-DISCARD: 2 <no-name>     00000020 {{[0-9a-f]*}} DATA
+# SEC-DISCARD: 3 <no-name>     00000003 {{[0-9a-f]*}} DATA
+# SEC-DISCARD: 4 <no-name>     00000002 {{[0-9a-f]*}} BSS
+# SEC-DISCARD: 5 <no-name>     00000008 {{[0-9a-f]*}}
+# SEC-DISCARD: 6 <no-name>     00000030 {{[0-9a-f]*}}
+# SEC-DISCARD: 7 <no-name>     00000008 {{[0-9a-f]*}}
 
 # Multiple SECTIONS command specifying additional input section descriptions
 # for the same output section description - input sections are merged into
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -377,6 +377,12 @@
     In<ELFT>::EhFrameHdr = make<EhFrameHeader<ELFT>>();
     Symtab<ELFT>::X->Sections.push_back(In<ELFT>::EhFrameHdr);
   }
+
+  if (In<ELFT>::SymTab)
+    Symtab<ELFT>::X->Sections.push_back(In<ELFT>::SymTab);
+  Symtab<ELFT>::X->Sections.push_back(In<ELFT>::ShStrTab);
+  if (In<ELFT>::StrTab)
+    Symtab<ELFT>::X->Sections.push_back(In<ELFT>::StrTab);
 }
 
 template <class ELFT>
@@ -1089,10 +1095,6 @@
   auto OS = dyn_cast_or_null<OutputSection<ELFT>>(findSection(".ARM.exidx"));
   if (OS && !OS->Sections.empty() && !Config->Relocatable)
     OS->addSection(make<ARMExidxSentinelSection<ELFT>>());
-
-  addInputSec(In<ELFT>::SymTab);
-  addInputSec(In<ELFT>::ShStrTab);
-  addInputSec(In<ELFT>::StrTab);
 }
 
 // The linker is expected to define SECNAME_start and SECNAME_end
@@ -1593,7 +1595,9 @@
   EHdr->e_phnum = Phdrs.size();
   EHdr->e_shentsize = sizeof(Elf_Shdr);
   EHdr->e_shnum = OutputSections.size() + 1;
-  EHdr->e_shstrndx = In<ELFT>::ShStrTab->OutSec->SectionIndex;
+  EHdr->e_shstrndx = In<ELFT>::ShStrTab->OutSec
+                         ? In<ELFT>::ShStrTab->OutSec->SectionIndex
+                         : SHN_UNDEF;
 
   if (Config->EMachine == EM_ARM)
     // We don't currently use any features incompatible with EF_ARM_EABI_VER5,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28561.83968.patch
Type: text/x-patch
Size: 3112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170111/3e64a647/attachment.bin>


More information about the llvm-commits mailing list