2015-07-21 13:42:38 +00:00
|
|
|
//===-- ObjDumper.h ---------------------------------------------*- C++ -*-===//
|
2013-04-03 18:31:38 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-04-03 18:31:38 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
|
|
|
|
#define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
|
2013-04-03 18:31:38 +00:00
|
|
|
|
2014-03-06 05:51:42 +00:00
|
|
|
#include <memory>
|
2014-06-12 17:38:55 +00:00
|
|
|
#include <system_error>
|
2014-03-06 05:51:42 +00:00
|
|
|
|
2018-06-15 14:15:02 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-07-18 18:00:41 +00:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
[llvm-readobj] Add a flag to dump just the section-to-segment mapping.
Summary:
The following patch introduces a new function `printSectionMapping` which is responsible for dumping just the section-to-segment mapping.
This patch also introduces a n option `-section-mapping` that outputs that mapping without the program headers.
Previously, this functionality was controlled by `printProgramHeaders`, and the output from `-program-headers` has not been changed. I am happy to change the option name, I copied the name that was displayed when outputting the mapping table.
Reviewers: khemant, jhenderson, grimar, rupprecht
Reviewed By: jhenderson, grimar, rupprecht
Subscribers: rupprecht, jhenderson, llvm-commits
Differential Revision: https://reviews.llvm.org/D57365
llvm-svn: 352896
2019-02-01 18:51:10 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2018-06-15 14:15:02 +00:00
|
|
|
|
2013-04-03 18:31:38 +00:00
|
|
|
namespace llvm {
|
|
|
|
namespace object {
|
2015-08-28 10:27:50 +00:00
|
|
|
class COFFImportFile;
|
|
|
|
class ObjectFile;
|
2020-08-27 15:20:13 +00:00
|
|
|
class XCOFFObjectFile;
|
|
|
|
class ELFObjectFileBase;
|
2013-04-03 18:31:38 +00:00
|
|
|
}
|
2016-05-14 00:02:53 +00:00
|
|
|
namespace codeview {
|
2019-02-07 15:24:18 +00:00
|
|
|
class GlobalTypeTableBuilder;
|
2017-11-30 18:39:50 +00:00
|
|
|
class MergingTypeTableBuilder;
|
2019-02-07 15:24:18 +00:00
|
|
|
} // namespace codeview
|
2013-04-03 18:31:38 +00:00
|
|
|
|
2016-05-03 00:28:04 +00:00
|
|
|
class ScopedPrinter;
|
2013-04-03 18:31:38 +00:00
|
|
|
|
|
|
|
class ObjDumper {
|
|
|
|
public:
|
2016-05-03 00:28:04 +00:00
|
|
|
ObjDumper(ScopedPrinter &Writer);
|
2013-04-03 18:31:38 +00:00
|
|
|
virtual ~ObjDumper();
|
|
|
|
|
|
|
|
virtual void printFileHeaders() = 0;
|
[llvm-readelf] Make llvm-readelf more compatible with GNU readelf.
Summary:
This change adds a bunch of options that GNU readelf supports. There is one breaking change when invoked as `llvm-readobj`, and three breaking changes when invoked as `llvm-readelf`:
- Add --all (implies --file-header, --program-headers, etc.)
- [Breaking] -a is --all instead of --arm-attributes
- Add --file-header as an alias for --file-headers
- Replace --sections with --sections-headers, keeping --sections as an alias for it
- Add --relocs as an alias for --relocations
- Add --dynamic as an alias for --dynamic-table
- Add --segments as an alias for --program-headers
- Add --section-groups as an alias for --elf-section-groups
- Add --dyn-syms as an alias for --dyn-symbols
- Add --syms as an alias for --symbols
- Add --histogram as an alias for --elf-hash-histogram
- [Breaking] When invoked as `llvm-readelf`, -s is --symbols instead of --sections
- [Breaking] When invoked as `llvm-readelf`, -t is no longer an alias for --symbols
Reviewers: MaskRay, phosek, mcgrathr, jhenderson
Reviewed By: MaskRay, jhenderson
Subscribers: sbc100, aheejin, edd, jhenderson, silvas, echristo, compnerd, kristina, javed.absar, kristof.beyls, llvm-commits, Bigcheese
Differential Revision: https://reviews.llvm.org/D54124
llvm-svn: 346685
2018-11-12 18:02:38 +00:00
|
|
|
virtual void printSectionHeaders() = 0;
|
2013-04-03 18:31:38 +00:00
|
|
|
virtual void printRelocations() = 0;
|
2019-01-23 16:15:39 +00:00
|
|
|
virtual void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) {
|
|
|
|
if (PrintSymbols)
|
|
|
|
printSymbols();
|
|
|
|
if (PrintDynamicSymbols)
|
|
|
|
printDynamicSymbols();
|
|
|
|
}
|
[llvm-readobj] Add a flag to dump just the section-to-segment mapping.
Summary:
The following patch introduces a new function `printSectionMapping` which is responsible for dumping just the section-to-segment mapping.
This patch also introduces a n option `-section-mapping` that outputs that mapping without the program headers.
Previously, this functionality was controlled by `printProgramHeaders`, and the output from `-program-headers` has not been changed. I am happy to change the option name, I copied the name that was displayed when outputting the mapping table.
Reviewers: khemant, jhenderson, grimar, rupprecht
Reviewed By: jhenderson, grimar, rupprecht
Subscribers: rupprecht, jhenderson, llvm-commits
Differential Revision: https://reviews.llvm.org/D57365
llvm-svn: 352896
2019-02-01 18:51:10 +00:00
|
|
|
virtual void printProgramHeaders(bool PrintProgramHeaders,
|
|
|
|
cl::boolOrDefault PrintSectionMapping) {
|
|
|
|
if (PrintProgramHeaders)
|
|
|
|
printProgramHeaders();
|
|
|
|
if (PrintSectionMapping == cl::BOU_TRUE)
|
|
|
|
printSectionMapping();
|
|
|
|
}
|
|
|
|
|
2013-04-03 18:31:38 +00:00
|
|
|
virtual void printUnwindInfo() = 0;
|
|
|
|
|
|
|
|
// Only implemented for ELF at this time.
|
2019-11-25 13:04:58 +00:00
|
|
|
virtual void printDependentLibs() {}
|
2015-06-25 21:47:32 +00:00
|
|
|
virtual void printDynamicRelocations() { }
|
2013-04-03 18:31:38 +00:00
|
|
|
virtual void printDynamicTable() { }
|
|
|
|
virtual void printNeededLibraries() { }
|
2018-07-11 10:00:29 +00:00
|
|
|
virtual void printSectionAsHex(StringRef SectionName) {}
|
2015-07-09 22:32:24 +00:00
|
|
|
virtual void printHashTable() { }
|
2020-05-13 12:06:01 +00:00
|
|
|
virtual void printGnuHashTable(const object::ObjectFile *Obj) {}
|
[llvm-readelf]Revert --dyn-symbols behaviour to make it GNU compatible, and add new --hash-symbols switch for old behaviour
In r287786, the behaviour of --dyn-symbols in llvm-readelf (but not
llvm-readobj) was changed to print the dynamic symbols as derived from
the hash table, rather than to print the dynamic symbol table contents
directly. The original change was initially submitted without review,
and some comments were made on the commit mailing list implying that the
new behavious is GNU compatible. I argue that it is not:
1) It does not include a null symbol.
2) It prints the symbols based on an order derived from the hash
table.
3) It prints an extra column indicating which bucket it came from.
This could break parsers that expect a fixed number of columns,
with the first column being the symbol index.
4) If the input happens to have both .hash and .gnu.hash section, it
prints interpretations of them both, resulting in most symbols
being printed twice.
5) There is no way of just printing the raw dynamic symbol table,
because --symbols also prints the static symbol table.
This patch reverts the --dyn-symbols behaviour back to its old behaviour
of just printing the contents of the dynamic symbol table, similar to
what is printed by --symbols. As the hashed interpretation is still
desirable to validate the hash table, it puts it under a new switch
"--hash-symbols". This is a no-op on all output forms except for GNU
output style for ELF. If there is no hash table, it does nothing,
unlike the previous behaviour which printed the raw dynamic symbol
table, since the raw dynsym is available under --dyn-symbols.
The yaml input for the test is based on that in
test/tools/llvm-readobj/demangle.test, but stripped down to the bare
minimum to provide a valid dynamic symbol.
Note: some LLD tests needed updating. I will commit a separate patch for
those.
Reviewed by: grimar, rupprecht
Differential Revision: https://reviews.llvm.org/D56910
llvm-svn: 351789
2019-01-22 09:35:35 +00:00
|
|
|
virtual void printHashSymbols() {}
|
2015-07-21 13:48:41 +00:00
|
|
|
virtual void printLoadName() {}
|
2015-10-16 23:19:01 +00:00
|
|
|
virtual void printVersionInfo() {}
|
2016-01-26 19:46:39 +00:00
|
|
|
virtual void printGroupSections() {}
|
2020-05-26 10:58:20 +00:00
|
|
|
virtual void printHashHistograms() {}
|
[MC] Add assembler support for .cg_profile.
Object FIle Representation
At codegen time this is emitted into the ELF file a pair of symbol indices and a weight. In assembly it looks like:
.cg_profile a, b, 32
.cg_profile freq, a, 11
.cg_profile freq, b, 20
When writing an ELF file these are put into a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight).
Differential Revision: https://reviews.llvm.org/D44965
llvm-svn: 333823
2018-06-02 16:33:01 +00:00
|
|
|
virtual void printCGProfile() {}
|
2018-07-17 22:17:18 +00:00
|
|
|
virtual void printAddrsig() {}
|
2016-08-30 18:52:02 +00:00
|
|
|
virtual void printNotes() {}
|
2018-01-30 16:29:29 +00:00
|
|
|
virtual void printELFLinkerOptions() {}
|
2019-08-05 22:47:07 +00:00
|
|
|
virtual void printStackSizes() {}
|
2019-10-04 11:59:06 +00:00
|
|
|
virtual void printArchSpecificInfo() { }
|
2014-06-18 08:47:09 +00:00
|
|
|
|
2014-10-02 17:02:18 +00:00
|
|
|
// Only implemented for PE/COFF.
|
|
|
|
virtual void printCOFFImports() { }
|
2015-01-03 21:35:09 +00:00
|
|
|
virtual void printCOFFExports() { }
|
2014-10-07 19:37:52 +00:00
|
|
|
virtual void printCOFFDirectives() { }
|
2014-11-19 00:18:07 +00:00
|
|
|
virtual void printCOFFBaseReloc() { }
|
2016-06-02 17:10:43 +00:00
|
|
|
virtual void printCOFFDebugDirectory() { }
|
2017-04-27 19:38:38 +00:00
|
|
|
virtual void printCOFFResources() {}
|
2017-06-22 01:10:29 +00:00
|
|
|
virtual void printCOFFLoadConfig() { }
|
2015-12-16 18:28:12 +00:00
|
|
|
virtual void printCodeViewDebugInfo() { }
|
2017-11-30 18:39:50 +00:00
|
|
|
virtual void
|
|
|
|
mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
|
2019-02-07 15:24:18 +00:00
|
|
|
llvm::codeview::MergingTypeTableBuilder &CVTypes,
|
|
|
|
llvm::codeview::GlobalTypeTableBuilder &GlobalCVIDs,
|
|
|
|
llvm::codeview::GlobalTypeTableBuilder &GlobalCVTypes,
|
|
|
|
bool GHash) {}
|
2014-10-02 17:02:18 +00:00
|
|
|
|
2015-08-21 20:28:30 +00:00
|
|
|
// Only implemented for MachO.
|
|
|
|
virtual void printMachODataInCode() { }
|
2015-08-27 15:11:32 +00:00
|
|
|
virtual void printMachOVersionMin() { }
|
2015-08-31 19:32:31 +00:00
|
|
|
virtual void printMachODysymtab() { }
|
2015-09-02 16:24:24 +00:00
|
|
|
virtual void printMachOSegment() { }
|
2015-09-03 18:10:28 +00:00
|
|
|
virtual void printMachOIndirectSymbols() { }
|
2015-09-09 00:21:18 +00:00
|
|
|
virtual void printMachOLinkerOptions() { }
|
2015-08-21 20:28:30 +00:00
|
|
|
|
2015-06-26 23:56:53 +00:00
|
|
|
virtual void printStackMap() const = 0;
|
|
|
|
|
2019-06-18 14:01:03 +00:00
|
|
|
void printSectionsAsString(const object::ObjectFile *Obj,
|
|
|
|
ArrayRef<std::string> Sections);
|
|
|
|
void printSectionsAsHex(const object::ObjectFile *Obj,
|
|
|
|
ArrayRef<std::string> Sections);
|
2018-07-18 18:00:41 +00:00
|
|
|
|
2013-04-03 18:31:38 +00:00
|
|
|
protected:
|
2016-05-03 00:28:04 +00:00
|
|
|
ScopedPrinter &W;
|
2019-01-23 16:15:39 +00:00
|
|
|
|
|
|
|
private:
|
[llvm-readobj] Add a flag to dump just the section-to-segment mapping.
Summary:
The following patch introduces a new function `printSectionMapping` which is responsible for dumping just the section-to-segment mapping.
This patch also introduces a n option `-section-mapping` that outputs that mapping without the program headers.
Previously, this functionality was controlled by `printProgramHeaders`, and the output from `-program-headers` has not been changed. I am happy to change the option name, I copied the name that was displayed when outputting the mapping table.
Reviewers: khemant, jhenderson, grimar, rupprecht
Reviewed By: jhenderson, grimar, rupprecht
Subscribers: rupprecht, jhenderson, llvm-commits
Differential Revision: https://reviews.llvm.org/D57365
llvm-svn: 352896
2019-02-01 18:51:10 +00:00
|
|
|
virtual void printSymbols() {}
|
|
|
|
virtual void printDynamicSymbols() {}
|
|
|
|
virtual void printProgramHeaders() {}
|
|
|
|
virtual void printSectionMapping() {}
|
2013-04-03 18:31:38 +00:00
|
|
|
};
|
|
|
|
|
2020-08-27 15:20:13 +00:00
|
|
|
std::unique_ptr<ObjDumper> createCOFFDumper(const object::COFFObjectFile &Obj,
|
|
|
|
ScopedPrinter &Writer);
|
2013-04-03 18:31:38 +00:00
|
|
|
|
2020-08-27 15:20:13 +00:00
|
|
|
std::unique_ptr<ObjDumper> createELFDumper(const object::ELFObjectFileBase &Obj,
|
|
|
|
ScopedPrinter &Writer);
|
2013-04-03 18:31:38 +00:00
|
|
|
|
2020-08-27 15:20:13 +00:00
|
|
|
std::unique_ptr<ObjDumper> createMachODumper(const object::MachOObjectFile &Obj,
|
|
|
|
ScopedPrinter &Writer);
|
2013-04-03 18:31:38 +00:00
|
|
|
|
2020-08-27 15:20:13 +00:00
|
|
|
std::unique_ptr<ObjDumper> createWasmDumper(const object::WasmObjectFile &Obj,
|
|
|
|
ScopedPrinter &Writer);
|
2017-01-30 23:30:52 +00:00
|
|
|
|
2020-08-27 15:20:13 +00:00
|
|
|
std::unique_ptr<ObjDumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj,
|
|
|
|
ScopedPrinter &Writer);
|
2019-05-03 12:57:07 +00:00
|
|
|
|
2018-01-10 00:14:19 +00:00
|
|
|
void dumpCOFFImportFile(const object::COFFImportFile *File,
|
|
|
|
ScopedPrinter &Writer);
|
2015-08-28 10:27:50 +00:00
|
|
|
|
2019-02-07 15:24:18 +00:00
|
|
|
void dumpCodeViewMergedTypes(ScopedPrinter &Writer,
|
|
|
|
ArrayRef<ArrayRef<uint8_t>> IpiRecords,
|
|
|
|
ArrayRef<ArrayRef<uint8_t>> TpiRecords);
|
2016-05-14 00:02:53 +00:00
|
|
|
|
2013-04-03 18:31:38 +00:00
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif
|