[PATCH] D49619: [yaml2obj] Add default sh_entsize for dynamic sections

Paul Semel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 15:05:51 PDT 2018


paulsemel created this revision.
paulsemel added reviewers: echristo, kastiglione.
Herald added a subscriber: jakehehrlich.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D49619

Files:
  test/tools/yaml2obj/dynamic-section.yaml
  tools/yaml2obj/yaml2elf.cpp


Index: tools/yaml2obj/yaml2elf.cpp
===================================================================
--- tools/yaml2obj/yaml2elf.cpp
+++ tools/yaml2obj/yaml2elf.cpp
@@ -115,6 +115,7 @@
   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 @@
     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;
Index: test/tools/yaml2obj/dynamic-section.yaml
===================================================================
--- /dev/null
+++ test/tools/yaml2obj/dynamic-section.yaml
@@ -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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49619.156616.patch
Type: text/x-patch
Size: 1328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180720/24cc2e04/attachment.bin>


More information about the llvm-commits mailing list