diff --git a/llvm/test/Object/elf-unknown-type.test b/llvm/test/Object/elf-unknown-type.test deleted file mode 100644 --- a/llvm/test/Object/elf-unknown-type.test +++ /dev/null @@ -1,10 +0,0 @@ -# RUN: yaml2obj %s | llvm-readobj --file-headers - | FileCheck %s - -!ELF -FileHeader: !FileHeader - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: 42 - Machine: EM_X86_64 - -# CHECK: Type: 0x2A diff --git a/llvm/test/tools/llvm-readobj/ELF/file-types.test b/llvm/test/tools/llvm-readobj/ELF/file-types.test --- a/llvm/test/tools/llvm-readobj/ELF/file-types.test +++ b/llvm/test/tools/llvm-readobj/ELF/file-types.test @@ -62,7 +62,7 @@ # RUN: llvm-readelf -h %t.unknown | FileCheck %s --match-full-lines --check-prefix GNU-UNNKNOWN # LLVM-UNNKNOWN: ElfHeader { -# LLVM-UNNKNOWN: Type: 0xFDFF +# LLVM-UNNKNOWN: Type: Unknown (0xFDFF) # GNU-UNNKNOWN: ELF Header: # GNU-UNNKNOWN: Type: : fdff @@ -72,7 +72,7 @@ # RUN: llvm-readelf -h %t6 | FileCheck %s --match-full-lines --check-prefix GNU-LOOS # LLVM-LOOS: ElfHeader { -# LLVM-LOOS: Type: 0xFE00 +# LLVM-LOOS: Type: OS Specific (0xFE00) # GNU-LOOS: ELF Header: # GNU-LOOS: Type: OS Specific: (fe00) @@ -82,7 +82,7 @@ # RUN: llvm-readelf -h %t7 | FileCheck %s --match-full-lines --check-prefix GNU-HIOS # LLVM-HIOS: ElfHeader { -# LLVM-HIOS: Type: 0xFEFF +# LLVM-HIOS: Type: OS Specific (0xFEFF) # GNU-HIOS: ELF Header: # GNU-HIOS: Type: OS Specific: (feff) @@ -92,7 +92,7 @@ # RUN: llvm-readelf -h %t8 | FileCheck %s --match-full-lines --check-prefix GNU-LOPROC # LLVM-LOPROC: ElfHeader { -# LLVM-LOPROC: Type: 0xFF00 +# LLVM-LOPROC: Type: Processor Specific (0xFF00) # GNU-LOPROC: ELF Header: # GNU-LOPROC: Type: Processor Specific: (ff00) @@ -102,7 +102,7 @@ # RUN: llvm-readelf -h %t9 | FileCheck %s --match-full-lines --check-prefix GNU-HIPROC # LLVM-HIPROC: ElfHeader { -# LLVM-HIPROC: Type: 0xFFFF +# LLVM-HIPROC: Type: Processor Specific (0xFFFF) # GNU-HIPROC: ELF Header: # GNU-HIPROC: Type: Processor Specific: (ffff) diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3515,6 +3515,15 @@ to_string((*ArrOrErr)[0].sh_link) + ")"; } +static const EnumEntry *getObjectFileEnumEntry(unsigned Type) { + auto It = llvm::find_if(ElfObjectFileType, [&](const EnumEntry &E) { + return E.Value == Type; + }); + if (It != makeArrayRef(ElfObjectFileType).end()) + return It; + return nullptr; +} + template void GNUStyle::printFileHeaders() { const Elf_Ehdr &e = this->Obj.getHeader(); OS << "ELF Header:\n"; @@ -3539,17 +3548,15 @@ printFields(OS, "ABI Version:", std::to_string(e.e_ident[ELF::EI_ABIVERSION])); - Str = printEnum(e.e_type, makeArrayRef(ElfObjectFileType)); - if (makeArrayRef(ElfObjectFileType).end() == - llvm::find_if(ElfObjectFileType, [&](const EnumEntry &E) { - return E.Value == e.e_type; - })) { + if (const EnumEntry *E = getObjectFileEnumEntry(e.e_type)) { + Str = E->AltName.str(); + } else { if (e.e_type >= ET_LOPROC) - Str = "Processor Specific: (" + Str + ")"; + Str = "Processor Specific: (" + to_hexString(e.e_type, false) + ")"; else if (e.e_type >= ET_LOOS) - Str = "OS Specific: (" + Str + ")"; + Str = "OS Specific: (" + to_hexString(e.e_type, false) + ")"; else - Str = ": " + Str; + Str = ": " + to_hexString(e.e_type, false); } printFields(OS, "Type:", Str); @@ -6343,7 +6350,19 @@ W.printBinary("Unused", makeArrayRef(E.e_ident).slice(ELF::EI_PAD)); } - W.printEnum("Type", E.e_type, makeArrayRef(ElfObjectFileType)); + std::string TypeStr; + if (const EnumEntry *Ent = getObjectFileEnumEntry(E.e_type)) { + TypeStr = Ent->Name.str(); + } else { + if (E.e_type >= ET_LOPROC) + TypeStr = "Processor Specific"; + else if (E.e_type >= ET_LOOS) + TypeStr = "OS Specific"; + else + TypeStr = "Unknown"; + } + W.printString("Type", TypeStr + " (0x" + to_hexString(E.e_type) + ")"); + W.printEnum("Machine", E.e_machine, makeArrayRef(ElfMachineType)); W.printNumber("Version", E.e_version); W.printHex("Entry", E.e_entry);