]> granicus.if.org Git - llvm/commitdiff
[yaml2obj] Add default sh_entsize for dynamic sections
authorPaul Semel <semelpaul@gmail.com>
Mon, 23 Jul 2018 18:49:04 +0000 (18:49 +0000)
committerPaul Semel <semelpaul@gmail.com>
Mon, 23 Jul 2018 18:49:04 +0000 (18:49 +0000)
Dynamic section holds a table, so the sh_entsize might be set. As the
dynamic section entry size never changes, we can default it to the size
of a dynamic entry.

Differential Revision: https://reviews.llvm.org/D49619

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337725 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/yaml2obj/dynamic-section.yaml [new file with mode: 0644]
tools/yaml2obj/yaml2elf.cpp

diff --git a/test/tools/yaml2obj/dynamic-section.yaml b/test/tools/yaml2obj/dynamic-section.yaml
new file mode 100644 (file)
index 0000000..39da5c1
--- /dev/null
@@ -0,0 +1,17 @@
+# Ensures that dynamic section has sh_entsize correctly set
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=SECTION
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_DYN
+  Machine:         EM_X86_64
+Sections:
+  - Name: .dynamic
+    Type: SHT_DYNAMIC
+    Flags: [ SHF_ALLOC, SHF_WRITE ]
+
+# SECTION: Name: .dynamic
+# SECTION: EntrySize: 16
index 4dc5215a1a522350d7783d1f650469117b15a509..7ca5ac206c9eb9ce97f4fcd16c53c53bc0d1c140 100644 (file)
@@ -115,6 +115,7 @@ class ELFState {
   typedef typename ELFT::Rel Elf_Rel;
   typedef typename ELFT::Rela Elf_Rela;
   typedef typename ELFT::Relr Elf_Relr;
+  typedef typename ELFT::Dyn Elf_Dyn;
 
   enum class SymtabType { Static, Dynamic };
 
@@ -462,6 +463,8 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
     OS.write(0);
   if (Section.Type == llvm::ELF::SHT_RELR)
     SHeader.sh_entsize = sizeof(Elf_Relr);
+  else if (Section.Type == llvm::ELF::SHT_DYNAMIC)
+    SHeader.sh_entsize = sizeof(Elf_Dyn);
   else
     SHeader.sh_entsize = 0;
   SHeader.sh_size = Section.Size;