summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Object/ELF.h4
-rw-r--r--llvm/lib/Object/ELF.cpp6
-rw-r--r--llvm/test/tools/llvm-objdump/elf-dynamic-section.test3
-rw-r--r--llvm/tools/llvm-objdump/ELFDump.cpp11
4 files changed, 10 insertions, 14 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index 1ba32b4875c..a49f7128c64 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -114,8 +114,8 @@ public:
SmallVectorImpl<char> &Result) const;
uint32_t getRelativeRelocationType() const;
- const char *getDynamicTagAsString(unsigned Arch, uint64_t Type) const;
- const char *getDynamicTagAsString(uint64_t Type) const;
+ std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const;
+ std::string getDynamicTagAsString(uint64_t Type) const;
/// Get the symbol for a given relocation.
Expected<const Elf_Sym *> getRelocationSymbol(const Elf_Rel *Rel,
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 314be34ef59..dd8f3a9f331 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -424,7 +424,7 @@ ELFFile<ELFT>::android_relas(const Elf_Shdr *Sec) const {
}
template <class ELFT>
-const char *ELFFile<ELFT>::getDynamicTagAsString(unsigned Arch,
+std::string ELFFile<ELFT>::getDynamicTagAsString(unsigned Arch,
uint64_t Type) const {
#define DYNAMIC_STRINGIFY_ENUM(tag, value) \
case value: \
@@ -470,12 +470,12 @@ const char *ELFFile<ELFT>::getDynamicTagAsString(unsigned Arch,
#undef DYNAMIC_TAG_MARKER
#undef DYNAMIC_STRINGIFY_ENUM
default:
- return "unknown";
+ return "<unknown:>0x" + utohexstr(Type, true);
}
}
template <class ELFT>
-const char *ELFFile<ELFT>::getDynamicTagAsString(uint64_t Type) const {
+std::string ELFFile<ELFT>::getDynamicTagAsString(uint64_t Type) const {
return getDynamicTagAsString(getHeader()->e_machine, Type);
}
diff --git a/llvm/test/tools/llvm-objdump/elf-dynamic-section.test b/llvm/test/tools/llvm-objdump/elf-dynamic-section.test
index 0391ac719f3..b2154170941 100644
--- a/llvm/test/tools/llvm-objdump/elf-dynamic-section.test
+++ b/llvm/test/tools/llvm-objdump/elf-dynamic-section.test
@@ -58,6 +58,7 @@
# CHECK-NEXT: VERNEEDNUM 0x0000000000000000
# CHECK-NEXT: AUXILIARY D
# CHECK-NEXT: FILTER U
+# CHECK-NEXT: <unknown:>0x1234abcd 0x0000000000000001
--- !ELF
FileHeader:
@@ -188,6 +189,8 @@ Sections:
Value: 0x1
- Tag: DT_FILTER
Value: 0x3
+ - Tag: 0x1234abcd
+ Value: 0x1
- Tag: DT_NULL
Value: 0x0
ProgramHeaders:
diff --git a/llvm/tools/llvm-objdump/ELFDump.cpp b/llvm/tools/llvm-objdump/ELFDump.cpp
index 6734f7618e4..c358b428e47 100644
--- a/llvm/tools/llvm-objdump/ELFDump.cpp
+++ b/llvm/tools/llvm-objdump/ELFDump.cpp
@@ -176,15 +176,8 @@ void printDynamicSection(const ELFFile<ELFT> *Elf, StringRef Filename) {
if (Dyn.d_tag == ELF::DT_NULL)
continue;
- StringRef Str = StringRef(Elf->getDynamicTagAsString(Dyn.d_tag));
-
- if (Str.empty()) {
- std::string HexStr = utohexstr(static_cast<uint64_t>(Dyn.d_tag), true);
- outs() << format(" 0x%-19s", HexStr.c_str());
- } else {
- // We use "-21" in order to match GNU objdump's output.
- outs() << format(" %-21s", Str.data());
- }
+ std::string Str = Elf->getDynamicTagAsString(Dyn.d_tag);
+ outs() << format(" %-21s", Str.c_str());
const char *Fmt =
ELFT::Is64Bits ? "0x%016" PRIx64 "\n" : "0x%08" PRIx64 "\n";
OpenPOWER on IntegriCloud