[yaml2obj/obj2yaml] - Support dumping/parsing ABI version.

These tools were assuming ABI version is 0,
that is not always true.

Patch teaches them to work with that field.

Differential revision: https://reviews.llvm.org/D55884

llvm-svn: 349737
This commit is contained in:
George Rimar 2018-12-20 10:43:49 +00:00
parent e254706bcb
commit c6cce39124
5 changed files with 20 additions and 1 deletions

View File

@ -68,6 +68,7 @@ struct FileHeader {
ELF_ELFCLASS Class;
ELF_ELFDATA Data;
ELF_ELFOSABI OSABI;
llvm::yaml::Hex8 ABIVersion;
ELF_ET Type;
ELF_EM Machine;
ELF_EF Flags;

View File

@ -753,6 +753,7 @@ void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
IO.mapRequired("Class", FileHdr.Class);
IO.mapRequired("Data", FileHdr.Data);
IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0));
IO.mapRequired("Type", FileHdr.Type);
IO.mapRequired("Machine", FileHdr.Machine);
IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));

View File

@ -0,0 +1,16 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj -file-headers %t | FileCheck %s --check-prefix=FROMYAML
# RUN: obj2yaml %t | FileCheck %s --check-prefix=TOYAML
## Check we are able to parse/emit the ABI version with yaml2obj/obj2yaml.
# FROMYAML: ABIVersion: 5
# TOYAML: ABIVersion: 0x05
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
ABIVersion: 0x05

View File

@ -114,6 +114,7 @@ template <class ELFT> ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
Y->Header.Class = ELFYAML::ELF_ELFCLASS(Obj.getHeader()->getFileClass());
Y->Header.Data = ELFYAML::ELF_ELFDATA(Obj.getHeader()->getDataEncoding());
Y->Header.OSABI = Obj.getHeader()->e_ident[ELF::EI_OSABI];
Y->Header.ABIVersion = Obj.getHeader()->e_ident[ELF::EI_ABIVERSION];
Y->Header.Type = Obj.getHeader()->e_type;
Y->Header.Machine = Obj.getHeader()->e_machine;
Y->Header.Flags = Obj.getHeader()->e_flags;

View File

@ -196,7 +196,7 @@ void ELFState<ELFT>::initELFHeader(Elf_Ehdr &Header) {
Header.e_ident[EI_DATA] = IsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
Header.e_ident[EI_VERSION] = EV_CURRENT;
Header.e_ident[EI_OSABI] = Doc.Header.OSABI;
Header.e_ident[EI_ABIVERSION] = 0;
Header.e_ident[EI_ABIVERSION] = Doc.Header.ABIVersion;
Header.e_type = Doc.Header.Type;
Header.e_machine = Doc.Header.Machine;
Header.e_version = EV_CURRENT;