diff options
author | Matt Davis <Matthew.Davis@sony.com> | 2019-02-27 18:39:17 +0000 |
---|---|---|
committer | Matt Davis <Matthew.Davis@sony.com> | 2019-02-27 18:39:17 +0000 |
commit | 7a24dbdfd31511d754be2a931c2fcd2b00a0fb4f (patch) | |
tree | a6d22eaf1f772b4e6953b25128c0dcc40e8ac8d2 /llvm/tools/llvm-readobj | |
parent | d89d6380558fff7a9e484ad34d2a1d0cd5dff809 (diff) | |
download | bcm5719-llvm-7a24dbdfd31511d754be2a931c2fcd2b00a0fb4f.tar.gz bcm5719-llvm-7a24dbdfd31511d754be2a931c2fcd2b00a0fb4f.zip |
[llvm-readobj] Print section type values for unknown sections.
Summary:
This patch displays a hexadecimal section value (Elf_Shdr::sh_type) or section-relative offset when printing unknown sections.
Here is a subset of the output (ignoring the fields following "Type" when dumping an ELF's GNU `--section-headers` table).
Section Headers:
```
[Nr] Name Type
[16] android_rel LOOS+0x1
[17] android_rela LOOS+0x2
[27] unknown 0x1000: <unknown>
[28] loos LOOS+0
[30] hios VERSYM
[31] loproc LOPROC+0
[33] hiproc LOPROC+0xFFFFFFF
[34] louser LOUSER+0
[36] hiuser LOUSER+0x7FFFFFFF
```
As a comparison, the previous output looked something like the above, but with a blank "Type" field:
```
[Nr] Name Type
[27] unknown
[28] loos
[30] hios VERSYM
[31] loproc
[33] hiproc
[34] louser
[36] hiuser
```
This fixes PR40773
Reviewers: jhenderson, rupprecht, Bigcheese
Reviewed By: jhenderson, rupprecht, Bigcheese
Subscribers: MaskRay, Bigcheese, srhines, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58701
llvm-svn: 355014
Diffstat (limited to 'llvm/tools/llvm-readobj')
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 21ab930024c..3597acfe061 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -2830,7 +2830,21 @@ template <class ELFT> void GNUStyle<ELFT>::printRelocations(const ELFO *Obj) { OS << "\nThere are no relocations in this file.\n"; } -std::string getSectionTypeString(unsigned Arch, unsigned Type) { +// Print the offset of a particular section from anyone of the ranges: +// [SHT_LOOS, SHT_HIOS], [SHT_LOPROC, SHT_HIPROC], [SHT_LOUSER, SHT_HIUSER]. +// If 'Type' does not fall within any of those ranges, then a string is +// returned as '<unknown>' followed by the type value. +static std::string getSectionTypeOffsetString(unsigned Type) { + if (Type >= SHT_LOOS && Type <= SHT_HIOS) + return "LOOS+0x" + to_hexString(Type - SHT_LOOS); + else if (Type >= SHT_LOPROC && Type <= SHT_HIPROC) + return "LOPROC+0x" + to_hexString(Type - SHT_LOPROC); + else if (Type >= SHT_LOUSER && Type <= SHT_HIUSER) + return "LOUSER+0x" + to_hexString(Type - SHT_LOUSER); + return "0x" + to_hexString(Type) + ": <unknown>"; +} + +static std::string getSectionTypeString(unsigned Arch, unsigned Type) { using namespace ELF; switch (Arch) { @@ -2903,6 +2917,10 @@ std::string getSectionTypeString(unsigned Arch, unsigned Type) { return "GROUP"; case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; + case SHT_ANDROID_REL: + return "ANDROID_REL"; + case SHT_ANDROID_RELA: + return "ANDROID_RELA"; case SHT_RELR: case SHT_ANDROID_RELR: return "RELR"; @@ -2926,7 +2944,7 @@ std::string getSectionTypeString(unsigned Arch, unsigned Type) { case SHT_GNU_versym: return "VERSYM"; default: - return ""; + return getSectionTypeOffsetString(Type); } return ""; } |