[PATCH] D50235: [yaml2obj] - Add a support for changing EntSize.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 3 03:08:36 PDT 2018


grimar created this revision.
grimar added reviewers: pcc, jakehehrlich, sanjoy, kastiglione.

I was trying to add a test case for LLD and found that it
is impossible to set sh_entsize via yaml.
The patch implements the missing part.

I am sorry, I do not know who is appropriate reviewer fo that,
so added people who seems was involved in recent changes to yaml2obj.


https://reviews.llvm.org/D50235

Files:
  include/llvm/ObjectYAML/ELFYAML.h
  lib/ObjectYAML/ELFYAML.cpp
  test/tools/yaml2obj/elf-ent-size.yaml
  tools/yaml2obj/yaml2elf.cpp


Index: tools/yaml2obj/yaml2elf.cpp
===================================================================
--- tools/yaml2obj/yaml2elf.cpp
+++ tools/yaml2obj/yaml2elf.cpp
@@ -461,7 +461,9 @@
   Section.Content.writeAsBinary(OS);
   for (auto i = Section.Content.binary_size(); i < Section.Size; ++i)
     OS.write(0);
-  if (Section.Type == llvm::ELF::SHT_RELR)
+  if (Section.EntSize != 0)
+    SHeader.sh_entsize = Section.EntSize;
+  else 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);
Index: test/tools/yaml2obj/elf-ent-size.yaml
===================================================================
--- test/tools/yaml2obj/elf-ent-size.yaml
+++ test/tools/yaml2obj/elf-ent-size.yaml
@@ -0,0 +1,36 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  OSABI:           ELFOSABI_FREEBSD
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Type:            SHT_PROGBITS
+    Name:            .strings
+    Flags:           [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
+    AddressAlign:    0x04
+    Content:         "FFFFFFFFFFFFFFFF"
+    EntSize:         0x1
+
+## Check we were able to set entry size for .strings
+# CHECK:      Section {
+# CHECK:        Index: 1
+# CHECK-NEXT:   Name: .strings
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:     SHF_MERGE
+# CHECK-NEXT:     SHF_STRINGS
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address:
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize: 1
+# CHECK-NEXT: }
Index: lib/ObjectYAML/ELFYAML.cpp
===================================================================
--- lib/ObjectYAML/ELFYAML.cpp
+++ lib/ObjectYAML/ELFYAML.cpp
@@ -816,6 +816,7 @@
   IO.mapOptional("Address", Section.Address, Hex64(0));
   IO.mapOptional("Link", Section.Link, StringRef());
   IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
+  IO.mapOptional("EntSize", Section.EntSize, Hex64(0));
   IO.mapOptional("Info", Section.Info, StringRef());
 }
 
Index: include/llvm/ObjectYAML/ELFYAML.h
===================================================================
--- include/llvm/ObjectYAML/ELFYAML.h
+++ include/llvm/ObjectYAML/ELFYAML.h
@@ -123,6 +123,7 @@
   StringRef Link;
   StringRef Info;
   llvm::yaml::Hex64 AddressAlign;
+  llvm::yaml::Hex64 EntSize;
 
   Section(SectionKind Kind) : Kind(Kind) {}
   virtual ~Section();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50235.158960.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180803/1af995d1/attachment.bin>


More information about the llvm-commits mailing list