[llvm] r355591 - [yaml2obj] - Allow producing ELFDATANONE ELFs
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 04:09:19 PST 2019
Author: grimar
Date: Thu Mar 7 04:09:19 2019
New Revision: 355591
URL: http://llvm.org/viewvc/llvm-project?rev=355591&view=rev
Log:
[yaml2obj] - Allow producing ELFDATANONE ELFs
I need this to remove a binary from LLD test suite.
The patch also simplifies the code a bit.
Differential revision: https://reviews.llvm.org/D59082
Added:
llvm/trunk/test/tools/yaml2obj/elf-header-elfdatanone.yaml
Modified:
llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Modified: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFYAML.cpp?rev=355591&r1=355590&r2=355591&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Thu Mar 7 04:09:19 2019
@@ -232,8 +232,9 @@ void ScalarEnumerationTraits<ELFYAML::EL
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.
+ // ELFDATANONE is an invalid data encoding, but we accept it because
+ // we want to be able to produce invalid binaries for the tests.
+ ECase(ELFDATANONE);
ECase(ELFDATA2LSB);
ECase(ELFDATA2MSB);
#undef ECase
Added: llvm/trunk/test/tools/yaml2obj/elf-header-elfdatanone.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-header-elfdatanone.yaml?rev=355591&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-header-elfdatanone.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/elf-header-elfdatanone.yaml Thu Mar 7 04:09:19 2019
@@ -0,0 +1,15 @@
+## We have a YAML file describing an invalid data type.
+## Check we are able to produce the invalid binary.
+
+# RUN: yaml2obj %s -o %t.o
+
+## Check that EI_DATA field is ELFDATANONE(0)
+# RUN: od -b %t.o +5 | FileCheck %s
+# CHECK: 0000005 000
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATANONE
+ Type: ET_REL
+ Machine: EM_X86_64
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=355591&r1=355590&r2=355591&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Thu Mar 7 04:09:19 2019
@@ -207,8 +207,7 @@ void ELFState<ELFT>::initELFHeader(Elf_E
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;
More information about the llvm-commits
mailing list