2011-09-20 01:56:04 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2011-09-20 01:56:04 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
|
|
|
|
#define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
|
2011-09-20 01:56:04 +08:00
|
|
|
|
2016-01-26 23:09:42 +08:00
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
2011-09-20 01:56:04 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2015-12-29 21:41:02 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2011-09-20 01:56:04 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2016-05-18 01:10:12 +08:00
|
|
|
#include "llvm/Object/Archive.h"
|
2011-09-20 01:56:04 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2016-04-18 17:17:29 +08:00
|
|
|
class StringRef;
|
|
|
|
|
2012-12-06 04:12:35 +08:00
|
|
|
namespace object {
|
2019-01-18 19:33:26 +08:00
|
|
|
class ELFObjectFileBase;
|
2019-01-28 22:11:35 +08:00
|
|
|
class ELFSectionRef;
|
2019-01-18 19:33:26 +08:00
|
|
|
class MachOObjectFile;
|
|
|
|
class MachOUniversalBinary;
|
|
|
|
class RelocationRef;
|
2012-12-06 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2018-08-21 06:18:21 +08:00
|
|
|
extern cl::opt<bool> Demangle;
|
2011-09-20 01:56:04 +08:00
|
|
|
|
2019-01-18 19:33:26 +08:00
|
|
|
typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
|
|
|
|
|
Reland [llvm-objdump] Use a counter for llvm-objdump -h instead of the section index.
This relands r374931 (reverted in r375088). It fixes 32-bit builds by using the right format string specifier for uint64_t (PRIu64) instead of `%d`.
Original description:
When listing the index in `llvm-objdump -h`, use a zero-based counter instead of the actual section index (e.g. shdr->sh_index for ELF).
While this is effectively a noop for now (except one unit test for XCOFF), the index values will change in a future patch that filters certain sections out (e.g. symbol tables). See D68669 for more context. Note: the test case in `test/tools/llvm-objdump/X86/section-index.s` already covers the case of incrementing the section index counter when sections are skipped.
Reviewers: grimar, jhenderson, espindola
Reviewed By: grimar
Subscribers: emaste, sbc100, arichardson, aheejin, arphaman, seiya, llvm-commits, MaskRay
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68848
llvm-svn: 375178
2019-10-18 05:55:43 +08:00
|
|
|
/// A filtered iterator for SectionRefs that skips sections based on some given
|
|
|
|
/// predicate.
|
2019-01-18 19:33:26 +08:00
|
|
|
class SectionFilterIterator {
|
|
|
|
public:
|
|
|
|
SectionFilterIterator(FilterPredicate P,
|
|
|
|
llvm::object::section_iterator const &I,
|
|
|
|
llvm::object::section_iterator const &E)
|
|
|
|
: Predicate(std::move(P)), Iterator(I), End(E) {
|
|
|
|
ScanPredicate();
|
|
|
|
}
|
|
|
|
const llvm::object::SectionRef &operator*() const { return *Iterator; }
|
|
|
|
SectionFilterIterator &operator++() {
|
|
|
|
++Iterator;
|
|
|
|
ScanPredicate();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bool operator!=(SectionFilterIterator const &Other) const {
|
|
|
|
return Iterator != Other.Iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ScanPredicate() {
|
|
|
|
while (Iterator != End && !Predicate(*Iterator)) {
|
|
|
|
++Iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FilterPredicate Predicate;
|
|
|
|
llvm::object::section_iterator Iterator;
|
|
|
|
llvm::object::section_iterator End;
|
|
|
|
};
|
|
|
|
|
Reland [llvm-objdump] Use a counter for llvm-objdump -h instead of the section index.
This relands r374931 (reverted in r375088). It fixes 32-bit builds by using the right format string specifier for uint64_t (PRIu64) instead of `%d`.
Original description:
When listing the index in `llvm-objdump -h`, use a zero-based counter instead of the actual section index (e.g. shdr->sh_index for ELF).
While this is effectively a noop for now (except one unit test for XCOFF), the index values will change in a future patch that filters certain sections out (e.g. symbol tables). See D68669 for more context. Note: the test case in `test/tools/llvm-objdump/X86/section-index.s` already covers the case of incrementing the section index counter when sections are skipped.
Reviewers: grimar, jhenderson, espindola
Reviewed By: grimar
Subscribers: emaste, sbc100, arichardson, aheejin, arphaman, seiya, llvm-commits, MaskRay
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68848
llvm-svn: 375178
2019-10-18 05:55:43 +08:00
|
|
|
/// Creates an iterator range of SectionFilterIterators for a given Object and
|
|
|
|
/// predicate.
|
2019-01-18 19:33:26 +08:00
|
|
|
class SectionFilter {
|
|
|
|
public:
|
|
|
|
SectionFilter(FilterPredicate P, llvm::object::ObjectFile const &O)
|
|
|
|
: Predicate(std::move(P)), Object(O) {}
|
|
|
|
SectionFilterIterator begin() {
|
|
|
|
return SectionFilterIterator(Predicate, Object.section_begin(),
|
|
|
|
Object.section_end());
|
|
|
|
}
|
|
|
|
SectionFilterIterator end() {
|
|
|
|
return SectionFilterIterator(Predicate, Object.section_end(),
|
|
|
|
Object.section_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FilterPredicate Predicate;
|
|
|
|
llvm::object::ObjectFile const &Object;
|
|
|
|
};
|
|
|
|
|
2011-09-20 01:56:04 +08:00
|
|
|
// Various helper functions.
|
Reland [llvm-objdump] Use a counter for llvm-objdump -h instead of the section index.
This relands r374931 (reverted in r375088). It fixes 32-bit builds by using the right format string specifier for uint64_t (PRIu64) instead of `%d`.
Original description:
When listing the index in `llvm-objdump -h`, use a zero-based counter instead of the actual section index (e.g. shdr->sh_index for ELF).
While this is effectively a noop for now (except one unit test for XCOFF), the index values will change in a future patch that filters certain sections out (e.g. symbol tables). See D68669 for more context. Note: the test case in `test/tools/llvm-objdump/X86/section-index.s` already covers the case of incrementing the section index counter when sections are skipped.
Reviewers: grimar, jhenderson, espindola
Reviewed By: grimar
Subscribers: emaste, sbc100, arichardson, aheejin, arphaman, seiya, llvm-commits, MaskRay
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68848
llvm-svn: 375178
2019-10-18 05:55:43 +08:00
|
|
|
|
|
|
|
/// Creates a SectionFilter with a standard predicate that conditionally skips
|
|
|
|
/// sections when the --section objdump flag is provided.
|
|
|
|
///
|
|
|
|
/// Idx is an optional output parameter that keeps track of which section index
|
|
|
|
/// this is. This may be different than the actual section number, as some
|
|
|
|
/// sections may be filtered (e.g. symbol tables).
|
|
|
|
SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O,
|
|
|
|
uint64_t *Idx = nullptr);
|
2019-01-18 19:33:26 +08:00
|
|
|
|
2019-04-09 00:24:08 +08:00
|
|
|
Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
|
|
|
|
const object::RelocationRef &Rel,
|
|
|
|
llvm::SmallVectorImpl<char> &Result);
|
|
|
|
Error getWasmRelocationValueString(const object::WasmObjectFile *Obj,
|
|
|
|
const object::RelocationRef &RelRef,
|
|
|
|
llvm::SmallVectorImpl<char> &Result);
|
|
|
|
Error getMachORelocationValueString(const object::MachOObjectFile *Obj,
|
|
|
|
const object::RelocationRef &RelRef,
|
|
|
|
llvm::SmallVectorImpl<char> &Result);
|
2019-01-18 19:33:26 +08:00
|
|
|
|
2019-01-28 22:11:35 +08:00
|
|
|
uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec);
|
|
|
|
|
2019-01-15 17:19:18 +08:00
|
|
|
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
|
|
|
|
void parseInputMachO(StringRef Filename);
|
|
|
|
void parseInputMachO(object::MachOUniversalBinary *UB);
|
|
|
|
void printMachOUnwindInfo(const object::MachOObjectFile *O);
|
|
|
|
void printMachOExportsTrie(const object::MachOObjectFile *O);
|
|
|
|
void printMachORebaseTable(object::MachOObjectFile *O);
|
|
|
|
void printMachOBindTable(object::MachOObjectFile *O);
|
|
|
|
void printMachOLazyBindTable(object::MachOObjectFile *O);
|
|
|
|
void printMachOWeakBindTable(object::MachOObjectFile *O);
|
|
|
|
void printELFFileHeader(const object::ObjectFile *O);
|
2018-07-25 19:09:20 +08:00
|
|
|
void printELFDynamicSection(const object::ObjectFile *Obj);
|
2019-02-25 21:13:19 +08:00
|
|
|
void printELFSymbolVersionInfo(const object::ObjectFile *Obj);
|
2019-01-15 17:19:18 +08:00
|
|
|
void printMachOFileHeader(const object::ObjectFile *O);
|
|
|
|
void printMachOLoadCommands(const object::ObjectFile *O);
|
|
|
|
void printWasmFileHeader(const object::ObjectFile *O);
|
|
|
|
void printExportsTrie(const object::ObjectFile *O);
|
|
|
|
void printRebaseTable(object::ObjectFile *O);
|
|
|
|
void printBindTable(object::ObjectFile *O);
|
|
|
|
void printLazyBindTable(object::ObjectFile *O);
|
|
|
|
void printWeakBindTable(object::ObjectFile *O);
|
|
|
|
void printRawClangAST(const object::ObjectFile *O);
|
|
|
|
void printRelocations(const object::ObjectFile *O);
|
|
|
|
void printDynamicRelocations(const object::ObjectFile *O);
|
|
|
|
void printSectionHeaders(const object::ObjectFile *O);
|
|
|
|
void printSectionContents(const object::ObjectFile *O);
|
|
|
|
void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
|
2020-04-05 09:58:53 +08:00
|
|
|
StringRef ArchitectureName = StringRef(),
|
|
|
|
bool DumpDynamic = false);
|
|
|
|
void printSymbol(const object::ObjectFile *O, const object::SymbolRef &Symbol,
|
|
|
|
StringRef FileName, StringRef ArchiveName,
|
|
|
|
StringRef ArchitectureName, bool DumpDynamic);
|
2019-08-21 19:07:31 +08:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Twine Message);
|
2019-08-27 18:03:45 +08:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef FileName,
|
|
|
|
StringRef ArchiveName = "",
|
|
|
|
StringRef ArchitectureName = "");
|
2019-08-21 19:07:31 +08:00
|
|
|
void reportWarning(Twine Message, StringRef File);
|
2019-04-07 16:19:55 +08:00
|
|
|
|
|
|
|
template <typename T, typename... Ts>
|
|
|
|
T unwrapOrError(Expected<T> EO, Ts &&... Args) {
|
|
|
|
if (EO)
|
|
|
|
return std::move(*EO);
|
2019-08-21 19:07:31 +08:00
|
|
|
reportError(EO.takeError(), std::forward<Ts>(Args)...);
|
2019-04-07 16:19:55 +08:00
|
|
|
}
|
2011-09-20 01:56:04 +08:00
|
|
|
|
2019-08-20 21:19:16 +08:00
|
|
|
std::string getFileNameForError(const object::Archive::Child &C,
|
|
|
|
unsigned Index);
|
|
|
|
|
2013-09-28 05:04:00 +08:00
|
|
|
} // end namespace llvm
|
2011-09-20 01:56:04 +08:00
|
|
|
|
|
|
|
#endif
|