Index: llvm/include/llvm/BinaryFormat/ELF.h =================================================================== --- llvm/include/llvm/BinaryFormat/ELF.h +++ llvm/include/llvm/BinaryFormat/ELF.h @@ -107,13 +107,17 @@ unsigned char getDataEncoding() const { return e_ident[EI_DATA]; } }; -// File types +// File types. +// See current registered ELF types at: +// http://www.sco.com/developers/gabi/latest/ch4.eheader.html enum { ET_NONE = 0, // No file type ET_REL = 1, // Relocatable file ET_EXEC = 2, // Executable file ET_DYN = 3, // Shared object file ET_CORE = 4, // Core file + ET_LOOS = 0xfe00, // Beginning of operating system-specific codes + ET_HIOS = 0xfeff, // Operating system-specific ET_LOPROC = 0xff00, // Beginning of processor-specific codes ET_HIPROC = 0xffff // Processor-specific }; Index: llvm/test/tools/llvm-readobj/ELF/file-types.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/file-types.test +++ llvm/test/tools/llvm-readobj/ELF/file-types.test @@ -56,6 +56,17 @@ # GNU-CORE: ELF Header: # GNU-CORE: Type: CORE (Core file) +## Test what we dump for an arbitrary unknown ELF type. +# RUN: yaml2obj %s -DTYPE=0xFDFF -o %t.unknown +# RUN: llvm-readobj -h %t.unknown | FileCheck %s --match-full-lines --check-prefix LLVM-UNNKNOWN +# RUN: llvm-readelf -h %t.unknown | FileCheck %s --match-full-lines --check-prefix GNU-UNNKNOWN + +# LLVM-UNNKNOWN: ElfHeader { +# LLVM-UNNKNOWN: Type: 0xFDFF + +# GNU-UNNKNOWN: ELF Header: +# GNU-UNNKNOWN: Type: : fdff + # RUN: yaml2obj %s -DTYPE=0xfe00 -o %t6 # RUN: llvm-readobj -h %t6 | FileCheck %s --match-full-lines --check-prefix LLVM-LOOS # RUN: llvm-readelf -h %t6 | FileCheck %s --match-full-lines --check-prefix GNU-LOOS @@ -64,7 +75,7 @@ # LLVM-LOOS: Type: 0xFE00 # GNU-LOOS: ELF Header: -# GNU-LOOS: Type: fe00 +# GNU-LOOS: Type: OS Specific: (fe00) # RUN: yaml2obj %s -DTYPE=0xfeff -o %t7 # RUN: llvm-readobj -h %t7 | FileCheck %s --match-full-lines --check-prefix LLVM-HIOS @@ -74,7 +85,7 @@ # LLVM-HIOS: Type: 0xFEFF # GNU-HIOS: ELF Header: -# GNU-HIOS: Type: feff +# GNU-HIOS: Type: OS Specific: (feff) # RUN: yaml2obj %s -DTYPE=0xff00 -o %t8 # RUN: llvm-readobj -h %t8 | FileCheck %s --match-full-lines --check-prefix LLVM-LOPROC @@ -84,7 +95,7 @@ # LLVM-LOPROC: Type: 0xFF00 # GNU-LOPROC: ELF Header: -# GNU-LOPROC: Type: ff00 +# GNU-LOPROC: Type: Processor Specific: (ff00) # RUN: yaml2obj %s -DTYPE=0xffff -o %t9 # RUN: llvm-readobj -h %t9 | FileCheck %s --match-full-lines --check-prefix LLVM-HIPROC @@ -94,4 +105,4 @@ # LLVM-HIPROC: Type: 0xFFFF # GNU-HIPROC: ELF Header: -# GNU-HIPROC: Type: ffff +# GNU-HIPROC: Type: Processor Specific: (ffff) Index: llvm/test/tools/llvm-readobj/ELF/types.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/types.test +++ /dev/null @@ -1,65 +0,0 @@ -# Show that llvm-readobj can handle all standard ELF types. -# RUN: yaml2obj %s -DTYPE=ET_NONE -o %t.none -# RUN: llvm-readobj --file-headers %t.none | FileCheck %s --check-prefix=LLVM-NONE -# RUN: llvm-readelf --file-headers %t.none | FileCheck %s --check-prefix=GNU-NONE - -# LLVM-NONE: Type: None (0x0) -# GNU-NONE: Type: NONE (none) - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: [[TYPE]] - -# RUN: yaml2obj %s -DTYPE=ET_REL -o %t.rel -# RUN: llvm-readobj --file-headers %t.rel | FileCheck %s --check-prefix=LLVM-REL -# RUN: llvm-readelf --file-headers %t.rel | FileCheck %s --check-prefix=GNU-REL - -# LLVM-REL: Type: Relocatable (0x1) -# GNU-REL: Type: REL (Relocatable file) - -# RUN: yaml2obj %s -DTYPE=ET_EXEC -o %t.exec -# RUN: llvm-readobj --file-headers %t.exec | FileCheck %s --check-prefix=LLVM-EXEC -# RUN: llvm-readelf --file-headers %t.exec | FileCheck %s --check-prefix=GNU-EXEC - -# LLVM-EXEC: Type: Executable (0x2) -# GNU-EXEC: Type: EXEC (Executable file) - -# RUN: yaml2obj %s -DTYPE=ET_DYN -o %t.so -# RUN: llvm-readobj --file-headers %t.so | FileCheck %s --check-prefix=LLVM-SO -# RUN: llvm-readelf --file-headers %t.so | FileCheck %s --check-prefix=GNU-SO - -# LLVM-SO: Type: SharedObject (0x3) -# GNU-SO: Type: DYN (Shared object file) - -# RUN: yaml2obj %s -DTYPE=ET_CORE -o %t.core -# RUN: llvm-readobj --file-headers %t.core | FileCheck %s --check-prefix=LLVM-CORE -# RUN: llvm-readelf --file-headers %t.core | FileCheck %s --check-prefix=GNU-CORE - -# LLVM-CORE: Type: Core (0x4) -# GNU-CORE: Type: CORE (Core file) - -# Show that llvm-readobj can handle an unknown ELF type. -# RUN: yaml2obj %s -DTYPE=0x42 -o %t.unknown -# RUN: llvm-readobj --file-headers %t.unknown | FileCheck %s --check-prefix=LLVM-UNKNOWN -# RUN: llvm-readelf --file-headers %t.unknown | FileCheck %s --check-prefix=GNU-UNKNOWN - -# LLVM-UNKNOWN: Type: 0x42 -# GNU-UNKNOWN: Type: 42 - -# Show that llvm-readobj can handle an unknown OS-specific ELF type. -# RUN: yaml2obj %s -DTYPE=0xfe00 -o %t.os -# RUN: llvm-readobj --file-headers %t.os | FileCheck %s --check-prefix=LLVM-OS -# RUN: llvm-readelf --file-headers %t.os | FileCheck %s --check-prefix=GNU-OS - -# LLVM-OS: Type: 0xFE00 -# GNU-OS: Type: fe00 - -# Show that llvm-readobj can handle an unknown machine-specific ELF type. -# RUN: yaml2obj %s -DTYPE=0xff00 -o %t.proc -# RUN: llvm-readobj --file-headers %t.proc | FileCheck %s --check-prefix=LLVM-PROC -# RUN: llvm-readelf --file-headers %t.proc | FileCheck %s --check-prefix=GNU-PROC - -# LLVM-PROC: Type: 0xFF00 -# GNU-PROC: Type: ff00 Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3526,8 +3526,20 @@ printFields(OS, "OS/ABI:", Str); printFields(OS, "ABI Version:", std::to_string(e.e_ident[ELF::EI_ABIVERSION])); + Str = printEnum(e.e_type, makeArrayRef(ElfObjectFileType)); + if (e.e_type >= ET_LOPROC) { + Str = "Processor Specific: (" + Str + ")"; + } else if (e.e_type >= ET_LOOS) { + Str = "OS Specific: (" + Str + ")"; + } else if (makeArrayRef(ElfObjectFileType).end() == + llvm::find_if(ElfObjectFileType, + [&](const EnumEntry &E) { + return E.Value == e.e_type; + })) + Str = ": " + Str; printFields(OS, "Type:", Str); + Str = printEnum(e.e_machine, makeArrayRef(ElfMachineType)); printFields(OS, "Machine:", Str); Str = "0x" + to_hexString(e.e_version);