From 83aea14ed6118c810e4ed2966bc34db9b42cb049 Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Mon, 14 Dec 2020 18:04:45 +0300 Subject: [PATCH] [llvm-readelf] - Don't print OS/Processor specific prefix for known ELF file types. This is a change suggested in post commit comments for D93096 (https://reviews.llvm.org/D93096#2451796). Imagine we want to add a custom OS specific ELF file type. For that we can update the `ElfObjectFileType` array: ``` static const EnumEntry ElfObjectFileType[] = { ... {"Core", "CORE (Core file)", ELF::ET_CORE}, {"MyType", "MyType (my description)", 0xfe01}, }; ``` The current code then might print: ``` OS Specific: (MyType (my description)) ``` Though instead we probably would like to see a nicer output, e.g: ``` Type: MyType (my description) ``` To achieve that we can reorder the code slightly. It is impossible to add a test I think, because we have no custom values in the `ElfObjectFileType` array in LLVM. Differential revision: https://reviews.llvm.org/D93217 --- llvm/tools/llvm-readobj/ELFDumper.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 27222c5..c9ca221 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3528,16 +3528,17 @@ template void GNUStyle::printFileHeaders() { "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; + if (makeArrayRef(ElfObjectFileType).end() == + llvm::find_if(ElfObjectFileType, [&](const EnumEntry &E) { + return E.Value == e.e_type; + })) { + if (e.e_type >= ET_LOPROC) + Str = "Processor Specific: (" + Str + ")"; + else if (e.e_type >= ET_LOOS) + Str = "OS Specific: (" + Str + ")"; + else + Str = ": " + Str; + } printFields(OS, "Type:", Str); Str = printEnum(e.e_machine, makeArrayRef(ElfMachineType)); -- 2.7.4