Index: llvm/lib/Object/ELF.cpp =================================================================== --- llvm/lib/Object/ELF.cpp +++ llvm/lib/Object/ELF.cpp @@ -477,7 +477,7 @@ #define PPC64_DYNAMIC_TAG(name, value) // Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. #define DYNAMIC_TAG_MARKER(name, value) -#define DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value) +#define DYNAMIC_TAG(name, value) case value: return #name; #include "llvm/BinaryFormat/DynamicTags.def" #undef DYNAMIC_TAG #undef AARCH64_DYNAMIC_TAG Index: llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test +++ llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test @@ -66,75 +66,75 @@ # LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [D] # LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [U] # LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [U] -# LLVM-NEXT: 0x0000000012345678 unknown 0x8765432187654321 -# LLVM-NEXT: 0x000000006ABCDEF0 unknown 0x9988776655443322 -# LLVM-NEXT: 0x0000000076543210 unknown 0x5555666677778888 +# LLVM-NEXT: 0x0000000012345678 0x12345678 0x8765432187654321 +# LLVM-NEXT: 0x000000006ABCDEF0 0x6abcdef0 0x9988776655443322 +# LLVM-NEXT: 0x0000000076543210 0x76543210 0x5555666677778888 # LLVM-NEXT: 0x0000000000000000 NULL 0x0 # LLVM-NEXT: ] # GNU: Dynamic section at offset {{.*}} contains 61 entries: -# GNU-NEXT: Tag Type Name/Value -# GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [D] -# GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes) -# GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000 -# GNU-NEXT: 0x0000000000000004 (HASH) 0x1000 -# GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000 -# GNU-NEXT: 0x0000000000000006 (SYMTAB) 0x1000 -# GNU-NEXT: 0x0000000000000007 (RELA) 0x1000 -# GNU-NEXT: 0x0000000000000008 (RELASZ) 16 (bytes) -# GNU-NEXT: 0x0000000000000009 (RELAENT) 1929 (bytes) -# GNU-NEXT: 0x000000000000000a (STRSZ) 16 (bytes) -# GNU-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes) -# GNU-NEXT: 0x000000000000000c (INIT) 0x1000 -# GNU-NEXT: 0x000000000000000d (FINI) 0x1000 -# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [U] -# GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [f] -# GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef -# GNU-NEXT: 0x0000000000000011 (REL) 0x1000 -# GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes) -# GNU-NEXT: 0x0000000000000013 (RELENT) 291 (bytes) -# GNU-NEXT: 0x0000000000000014 (PLTREL) RELA -# GNU-NEXT: 0x0000000000000015 (DEBUG) 0xfedcba0987654321 -# GNU-NEXT: 0x0000000000000016 (TEXTREL) 0x1122334455667788 -# GNU-NEXT: 0x0000000000000017 (JMPREL) 0x1000 -# GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x8877665544332211 -# GNU-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x1000 -# GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000 -# GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes) -# GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes) -# GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [w] -# GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}} -# GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000 -# GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes) -# GNU-NEXT: 0x0000000000000022 (SYMTAB_SHNDX) 0x1000 -# GNU-NEXT: 0x0000000000000023 (RELRSZ) 0x10 -# GNU-NEXT: 0x0000000000000024 (RELR) 0x1000 -# GNU-NEXT: 0x0000000000000025 (RELRENT) 0x4321 -# GNU-NEXT: 0x000000006000000f (ANDROID_REL) 0x1000 -# GNU-NEXT: 0x0000000060000010 (ANDROID_RELSZ) 16 (bytes) -# GNU-NEXT: 0x0000000060000011 (ANDROID_RELA) 0x1000 -# GNU-NEXT: 0x0000000060000012 (ANDROID_RELASZ) 16 (bytes) -# GNU-NEXT: 0x000000006fffe000 (ANDROID_RELR) 0x1000 -# GNU-NEXT: 0x000000006fffe001 (ANDROID_RELRSZ) 0x10 -# GNU-NEXT: 0x000000006fffe003 (ANDROID_RELRENT) 0x1234 -# GNU-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x1000 -# GNU-NEXT: 0x000000006ffffef6 (TLSDESC_PLT) 0x1000 -# GNU-NEXT: 0x000000006ffffef7 (TLSDESC_GOT) 0x1000 -# GNU-NEXT: 0x000000006ffffff9 (RELACOUNT) 0 -# GNU-NEXT: 0x000000006ffffffa (RELCOUNT) 0 -# GNU-NEXT: 0x000000006ffffffb (FLAGS_1) NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}} -# GNU-NEXT: 0x000000006ffffff0 (VERSYM) 0x1000 -# GNU-NEXT: 0x000000006ffffffc (VERDEF) 0x1000 -# GNU-NEXT: 0x000000006ffffffd (VERDEFNUM) 0 -# GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x1000 -# GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 0 -# GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [D] -# GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [U] -# GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [U] -# GNU-NEXT: 0x0000000012345678 (unknown) 0x8765432187654321 -# GNU-NEXT: 0x000000006abcdef0 (unknown) 0x9988776655443322 -# GNU-NEXT: 0x0000000076543210 (unknown) 0x5555666677778888 -# GNU-NEXT: 0x0000000000000000 (NULL) 0x0 +# GNU-NEXT: Tag Type Name/Value +# GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [D] +# GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000 +# GNU-NEXT: 0x0000000000000004 (HASH) 0x1000 +# GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000 +# GNU-NEXT: 0x0000000000000006 (SYMTAB) 0x1000 +# GNU-NEXT: 0x0000000000000007 (RELA) 0x1000 +# GNU-NEXT: 0x0000000000000008 (RELASZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000009 (RELAENT) 1929 (bytes) +# GNU-NEXT: 0x000000000000000a (STRSZ) 16 (bytes) +# GNU-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes) +# GNU-NEXT: 0x000000000000000c (INIT) 0x1000 +# GNU-NEXT: 0x000000000000000d (FINI) 0x1000 +# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [U] +# GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [f] +# GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef +# GNU-NEXT: 0x0000000000000011 (REL) 0x1000 +# GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000013 (RELENT) 291 (bytes) +# GNU-NEXT: 0x0000000000000014 (PLTREL) RELA +# GNU-NEXT: 0x0000000000000015 (DEBUG) 0xfedcba0987654321 +# GNU-NEXT: 0x0000000000000016 (TEXTREL) 0x1122334455667788 +# GNU-NEXT: 0x0000000000000017 (JMPREL) 0x1000 +# GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x8877665544332211 +# GNU-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x1000 +# GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000 +# GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes) +# GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes) +# GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [w] +# GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}} +# GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000 +# GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000022 (SYMTAB_SHNDX) 0x1000 +# GNU-NEXT: 0x0000000000000023 (RELRSZ) 0x10 +# GNU-NEXT: 0x0000000000000024 (RELR) 0x1000 +# GNU-NEXT: 0x0000000000000025 (RELRENT) 0x4321 +# GNU-NEXT: 0x000000006000000f (ANDROID_REL) 0x1000 +# GNU-NEXT: 0x0000000060000010 (ANDROID_RELSZ) 16 (bytes) +# GNU-NEXT: 0x0000000060000011 (ANDROID_RELA) 0x1000 +# GNU-NEXT: 0x0000000060000012 (ANDROID_RELASZ) 16 (bytes) +# GNU-NEXT: 0x000000006fffe000 (ANDROID_RELR) 0x1000 +# GNU-NEXT: 0x000000006fffe001 (ANDROID_RELRSZ) 0x10 +# GNU-NEXT: 0x000000006fffe003 (ANDROID_RELRENT) 0x1234 +# GNU-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x1000 +# GNU-NEXT: 0x000000006ffffef6 (TLSDESC_PLT) 0x1000 +# GNU-NEXT: 0x000000006ffffef7 (TLSDESC_GOT) 0x1000 +# GNU-NEXT: 0x000000006ffffff9 (RELACOUNT) 0 +# GNU-NEXT: 0x000000006ffffffa (RELCOUNT) 0 +# GNU-NEXT: 0x000000006ffffffb (FLAGS_1) NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}} +# GNU-NEXT: 0x000000006ffffff0 (VERSYM) 0x1000 +# GNU-NEXT: 0x000000006ffffffc (VERDEF) 0x1000 +# GNU-NEXT: 0x000000006ffffffd (VERDEFNUM) 0 +# GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x1000 +# GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 0 +# GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [D] +# GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [U] +# GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [U] +# GNU-NEXT: 0x0000000012345678 (0x12345678) 0x8765432187654321 +# GNU-NEXT: 0x000000006abcdef0 (0x6abcdef0) 0x9988776655443322 +# GNU-NEXT: 0x0000000076543210 (0x76543210) 0x5555666677778888 +# GNU-NEXT: 0x0000000000000000 (NULL) 0x0 --- !ELF FileHeader: Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -257,7 +257,7 @@ std::pair findDynamic(const ELFFile *Obj); void loadDynamicTable(const ELFFile *Obj); - void parseDynamicTable(); + void parseDynamicTable(const ELFFile *Obj); Expected getSymbolVersion(const Elf_Sym *symb, bool &IsDefault) const; @@ -1868,7 +1868,7 @@ if (!DynamicPhdr || !DynamicSec) { if ((DynamicPhdr && IsPhdrTableValid) || (DynamicSec && IsSecTableValid)) { DynamicTable = DynamicPhdr ? FromPhdr : FromSec; - parseDynamicTable(); + parseDynamicTable(Obj); } else { reportWarning(createError("no valid dynamic table was found"), ObjF->getFileName()); @@ -1909,7 +1909,7 @@ DynamicTable = FromSec; } - parseDynamicTable(); + parseDynamicTable(Obj); } template @@ -1975,82 +1975,13 @@ ELFDumperStyle.reset(new LLVMStyle(Writer, this)); } -static const char *getTypeString(unsigned Arch, uint64_t Type) { -#define DYNAMIC_TAG(n, v) - switch (Arch) { - - case EM_AARCH64: - switch (Type) { -#define AARCH64_DYNAMIC_TAG(name, value) \ - case DT_##name: \ - return #name; -#include "llvm/BinaryFormat/DynamicTags.def" -#undef AARCH64_DYNAMIC_TAG - } - break; - - case EM_HEXAGON: - switch (Type) { -#define HEXAGON_DYNAMIC_TAG(name, value) \ - case DT_##name: \ - return #name; -#include "llvm/BinaryFormat/DynamicTags.def" -#undef HEXAGON_DYNAMIC_TAG - } - break; - - case EM_MIPS: - switch (Type) { -#define MIPS_DYNAMIC_TAG(name, value) \ - case DT_##name: \ - return #name; -#include "llvm/BinaryFormat/DynamicTags.def" -#undef MIPS_DYNAMIC_TAG - } - break; - - case EM_PPC64: - switch (Type) { -#define PPC64_DYNAMIC_TAG(name, value) \ - case DT_##name: \ - return #name; -#include "llvm/BinaryFormat/DynamicTags.def" -#undef PPC64_DYNAMIC_TAG - } - break; - } -#undef DYNAMIC_TAG - switch (Type) { -// Now handle all dynamic tags except the architecture specific ones -#define AARCH64_DYNAMIC_TAG(name, value) -#define MIPS_DYNAMIC_TAG(name, value) -#define HEXAGON_DYNAMIC_TAG(name, value) -#define PPC64_DYNAMIC_TAG(name, value) -// Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. -#define DYNAMIC_TAG_MARKER(name, value) -#define DYNAMIC_TAG(name, value) \ - case DT_##name: \ - return #name; -#include "llvm/BinaryFormat/DynamicTags.def" -#undef DYNAMIC_TAG -#undef AARCH64_DYNAMIC_TAG -#undef MIPS_DYNAMIC_TAG -#undef HEXAGON_DYNAMIC_TAG -#undef PPC64_DYNAMIC_TAG -#undef DYNAMIC_TAG_MARKER - default: - return "unknown"; - } -} - -template void ELFDumper::parseDynamicTable() { +template +void ELFDumper::parseDynamicTable(const ELFFile *Obj) { auto toMappedAddr = [&](uint64_t Tag, uint64_t VAddr) -> const uint8_t * { auto MappedAddrOrError = ObjF->getELFFile()->toMappedAddr(VAddr); if (!MappedAddrOrError) { Error Err = - createError("Unable to parse DT_" + - Twine(getTypeString( - ObjF->getELFFile()->getHeader()->e_machine, Tag)) + + createError("Unable to parse DT_" + Obj->getDynamicTagAsString(Tag) + ": " + llvm::toString(MappedAddrOrError.takeError())); reportWarning(std::move(Err), ObjF->getFileName()); @@ -4061,9 +3992,8 @@ OS << " Tag Type Name/Value\n"; for (auto Entry : Table) { uintX_t Tag = Entry.getTag(); - std::string TypeString = std::string("(") + - getTypeString(Obj->getHeader()->e_machine, Tag) + - ")"; + std::string TypeString = + std::string("(") + Obj->getDynamicTagAsString(Tag).c_str() + ")"; OS << " " << format_hex(Tag, Is64 ? 18 : 10) << format(" %-20s ", TypeString.c_str()); this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal()); @@ -5866,12 +5796,10 @@ for (auto Entry : Table) { uintX_t Tag = Entry.getTag(); W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, true) << " " - << format("%-21s", - getTypeString(Obj->getHeader()->e_machine, Tag)); + << format("%-21s", Obj->getDynamicTagAsString(Tag).c_str()); this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal()); OS << "\n"; } - W.startLine() << "]\n"; }