[llvm] r355262 - [llvm-objdump] Should print unknown d_tag in hex format
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 20:20:28 PST 2019
Author: higuoxing
Date: Fri Mar 1 20:20:28 2019
New Revision: 355262
URL: http://llvm.org/viewvc/llvm-project?rev=355262&view=rev
Log:
[llvm-objdump] Should print unknown d_tag in hex format
Summary:
Currently, `llvm-objdump` prints "unknown" instead of d_tag value in hex format. Because getDynamicTagAsString returns "unknown" rather than empty
string.
Reviewers: grimar, jhenderson
Reviewed By: jhenderson
Subscribers: rupprecht, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58763
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/lib/Object/ELF.cpp
llvm/trunk/test/tools/llvm-objdump/elf-dynamic-section.test
llvm/trunk/tools/llvm-objdump/ELFDump.cpp
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=355262&r1=355261&r2=355262&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Fri Mar 1 20:20:28 2019
@@ -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,
Modified: llvm/trunk/lib/Object/ELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELF.cpp?rev=355262&r1=355261&r2=355262&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELF.cpp (original)
+++ llvm/trunk/lib/Object/ELF.cpp Fri Mar 1 20:20:28 2019
@@ -424,7 +424,7 @@ ELFFile<ELFT>::android_relas(const Elf_S
}
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>::getDynamicTag
#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);
}
Modified: llvm/trunk/test/tools/llvm-objdump/elf-dynamic-section.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/elf-dynamic-section.test?rev=355262&r1=355261&r2=355262&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/elf-dynamic-section.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/elf-dynamic-section.test Fri Mar 1 20:20:28 2019
@@ -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:
Modified: llvm/trunk/tools/llvm-objdump/ELFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/ELFDump.cpp?rev=355262&r1=355261&r2=355262&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/ELFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/ELFDump.cpp Fri Mar 1 20:20:28 2019
@@ -176,15 +176,8 @@ void printDynamicSection(const ELFFile<E
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";
More information about the llvm-commits
mailing list