[PATCH] D93217: [llvm-readelf] - Don't OS/Processor specific prefix for known ELF file types.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 14 07:16:54 PST 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added a subscriber: rupprecht.
grimar requested review of this revision.
Herald added a project: LLVM.
This is a change suggested in post commit comments for
D93096 <https://reviews.llvm.org/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<unsigned> 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.
https://reviews.llvm.org/D93217
Files:
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3528,16 +3528,17 @@
"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<unsigned> &E) {
- return E.Value == e.e_type;
- }))
- Str = "<unknown>: " + Str;
+ if (makeArrayRef(ElfObjectFileType).end() ==
+ llvm::find_if(ElfObjectFileType, [&](const EnumEntry<unsigned> &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 = "<unknown>: " + Str;
+ }
printFields(OS, "Type:", Str);
Str = printEnum(e.e_machine, makeArrayRef(ElfMachineType));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93217.311581.patch
Type: text/x-patch
Size: 1293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201214/ae90c766/attachment.bin>
More information about the llvm-commits
mailing list