Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit dba0a79

Browse files
author
George Rimar
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355591 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 81cf489 commit dba0a79

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/ObjectYAML/ELFYAML.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
232232
void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
233233
IO &IO, ELFYAML::ELF_ELFDATA &Value) {
234234
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
235-
// Since the semantics of ELFDATANONE is "invalid", just don't accept it
236-
// here.
235+
// ELFDATANONE is an invalid data encoding, but we accept it because
236+
// we want to be able to produce invalid binaries for the tests.
237+
ECase(ELFDATANONE);
237238
ECase(ELFDATA2LSB);
238239
ECase(ELFDATA2MSB);
239240
#undef ECase
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## We have a YAML file describing an invalid data type.
2+
## Check we are able to produce the invalid binary.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
## Check that EI_DATA field is ELFDATANONE(0)
7+
# RUN: od -b %t.o +5 | FileCheck %s
8+
# CHECK: 0000005 000
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATANONE
14+
Type: ET_REL
15+
Machine: EM_X86_64

tools/yaml2obj/yaml2elf.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ void ELFState<ELFT>::initELFHeader(Elf_Ehdr &Header) {
207207
Header.e_ident[EI_MAG2] = 'L';
208208
Header.e_ident[EI_MAG3] = 'F';
209209
Header.e_ident[EI_CLASS] = ELFT::Is64Bits ? ELFCLASS64 : ELFCLASS32;
210-
bool IsLittleEndian = ELFT::TargetEndianness == support::little;
211-
Header.e_ident[EI_DATA] = IsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
210+
Header.e_ident[EI_DATA] = Doc.Header.Data;
212211
Header.e_ident[EI_VERSION] = EV_CURRENT;
213212
Header.e_ident[EI_OSABI] = Doc.Header.OSABI;
214213
Header.e_ident[EI_ABIVERSION] = Doc.Header.ABIVersion;

0 commit comments

Comments
 (0)