diff options
author | Matt Davis <Matthew.Davis@sony.com> | 2019-02-05 21:01:01 +0000 |
---|---|---|
committer | Matt Davis <Matthew.Davis@sony.com> | 2019-02-05 21:01:01 +0000 |
commit | 0d0e9c08a49d4314c5c484ab91f3956f3daac0f4 (patch) | |
tree | e62ca5b9b70ef30d3742475a9b648e090d94f538 /llvm/tools/llvm-readobj/ELFDumper.cpp | |
parent | 315056692d67792221810af0adea146a674af151 (diff) | |
download | bcm5719-llvm-0d0e9c08a49d4314c5c484ab91f3956f3daac0f4.tar.gz bcm5719-llvm-0d0e9c08a49d4314c5c484ab91f3956f3daac0f4.zip |
[llvm-readobj] Display sections that do not belong to a segment in the section-mapping
Summary:
The following patch adds the "None" line to the section to segment mapping dump.
That line lists the sections that do not belong to any segment.
I realize that this change differs from GNU readelf which does not display the latter information.
I'd rather not add this "feature" under a command line option. I think that might introduce confusion, since users would have to
make an additional decision as to if they want to see all of the section-to-segment map or just a subset of it.
Another option is to only print the "None" line if the `--section-mapping` option is passed; however,
that might also introduce some confusion, because the section-to-segment map would be different between`--program-headers`
and the `--section-mapping` output. While the difference is just the "None" line, it seems that if we choose to display
the segment-to-section mapping, then we should always display the whole map including the sections
that do not belong to segments.
```
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .gnu.hash
03 .init_array .fini_array .dynamic
04 .dynamic
05 .note.ABI-tag
06 .eh_frame_hdr
07
08 .init_array .fini_array .dynamic .got
None .comment .symtab .strtab .shstrtab <--- THIS LINE
```
Reviewers: grimar, rupprecht, jhenderson, espindola
Reviewed By: rupprecht
Subscribers: khemant, emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D57700
llvm-svn: 353217
Diffstat (limited to 'llvm/tools/llvm-readobj/ELFDumper.cpp')
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 1757fd6cce5..2c9b159575b 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -19,6 +19,7 @@ #include "llvm-readobj.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" @@ -3316,6 +3317,7 @@ void GNUStyle<ELFT>::printProgramHeaders(const ELFO *Obj) { template <class ELFT> void GNUStyle<ELFT>::printSectionMapping(const ELFO *Obj) { OS << "\n Section to Segment mapping:\n Segment Sections...\n"; + DenseSet<const Elf_Shdr *> BelongsToSegment; int Phnum = 0; for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) { std::string Sections; @@ -3330,12 +3332,25 @@ void GNUStyle<ELFT>::printSectionMapping(const ELFO *Obj) { Phdr.p_type != ELF::PT_TLS; if (!TbssInNonTLS && checkTLSSections(Phdr, Sec) && checkoffsets(Phdr, Sec) && checkVMA(Phdr, Sec) && - checkPTDynamic(Phdr, Sec) && (Sec.sh_type != ELF::SHT_NULL)) + checkPTDynamic(Phdr, Sec) && (Sec.sh_type != ELF::SHT_NULL)) { Sections += unwrapOrError(Obj->getSectionName(&Sec)).str() + " "; + BelongsToSegment.insert(&Sec); + } } OS << Sections << "\n"; OS.flush(); } + + // Display sections that do not belong to a segment. + std::string Sections; + for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { + if (BelongsToSegment.find(&Sec) == BelongsToSegment.end()) + Sections += unwrapOrError(Obj->getSectionName(&Sec)).str() + ' '; + } + if (!Sections.empty()) { + OS << " None " << Sections << '\n'; + OS.flush(); + } } template <class ELFT> |