[PATCH] D59082: [yaml2obj] - Allow producing ELFDATANONE ELFs

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 02:10:06 PST 2019


grimar created this revision.
grimar added a reviewer: jhenderson.
Herald added a subscriber: jakehehrlich.

I need this to remove a binary from LLD test suite.
The patch also simplifies the code a bit.


https://reviews.llvm.org/D59082

Files:
  lib/ObjectYAML/ELFYAML.cpp
  test/tools/yaml2obj/elf-header-data.yaml
  tools/yaml2obj/yaml2elf.cpp


Index: tools/yaml2obj/yaml2elf.cpp
===================================================================
--- tools/yaml2obj/yaml2elf.cpp
+++ tools/yaml2obj/yaml2elf.cpp
@@ -207,8 +207,7 @@
   Header.e_ident[EI_MAG2] = 'L';
   Header.e_ident[EI_MAG3] = 'F';
   Header.e_ident[EI_CLASS] = ELFT::Is64Bits ? ELFCLASS64 : ELFCLASS32;
-  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
-  Header.e_ident[EI_DATA] = IsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
+  Header.e_ident[EI_DATA] = Doc.Header.Data;
   Header.e_ident[EI_VERSION] = EV_CURRENT;
   Header.e_ident[EI_OSABI] = Doc.Header.OSABI;
   Header.e_ident[EI_ABIVERSION] = Doc.Header.ABIVersion;
Index: test/tools/yaml2obj/elf-header-data.yaml
===================================================================
--- /dev/null
+++ test/tools/yaml2obj/elf-header-data.yaml
@@ -0,0 +1,16 @@
+# We have a YAML describing an invalid data type.
+# Check we are able to produce the invalid binary.
+
+# RUN: yaml2obj %s -o %t.o
+
+# Both llvm-readobj and obj2yaml currently recognize that the object is invalid.
+# RUN: not llvm-readobj -file-headers %t.o 2>&1 | FileCheck %s
+# RUN: not obj2yaml %t.o 2>&1 | FileCheck %s
+# CHECK: Error reading file: {{.*}}.o: Invalid ELF data
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATANONE
+  Type:            ET_REL
+  Machine:         EM_X86_64
Index: lib/ObjectYAML/ELFYAML.cpp
===================================================================
--- lib/ObjectYAML/ELFYAML.cpp
+++ lib/ObjectYAML/ELFYAML.cpp
@@ -232,8 +232,9 @@
 void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
     IO &IO, ELFYAML::ELF_ELFDATA &Value) {
 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
-  // Since the semantics of ELFDATANONE is "invalid", just don't accept it
-  // here.
+  // The Semantics of ELFDATANONE is "invalid", but we accept it because
+  // want to be able to produce "invalid" binaries for the tests.
+  ECase(ELFDATANONE);
   ECase(ELFDATA2LSB);
   ECase(ELFDATA2MSB);
 #undef ECase


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59082.189667.patch
Type: text/x-patch
Size: 2040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190307/d466a1ae/attachment-0001.bin>


More information about the llvm-commits mailing list