[llvm] 621e2de - Add a (nonfunctional) -dyld_info flag to llvm-objdump.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 22 11:06:40 PST 2022
Author: Adrian Prantl
Date: 2022-02-22T11:06:27-08:00
New Revision: 621e2de138f70e175512c18d9f358666de93e838
URL: https://github.com/llvm/llvm-project/commit/621e2de138f70e175512c18d9f358666de93e838
DIFF: https://github.com/llvm/llvm-project/commit/621e2de138f70e175512c18d9f358666de93e838.diff
LOG: Add a (nonfunctional) -dyld_info flag to llvm-objdump.
Darwin otool implements this flag as a one-stop solution for
displaying bind and rebase info. As I am working on upstreaming
chained fixup support this command will be useful to write testcases.
Differential Revision: https://reviews.llvm.org/D113573
Added:
llvm/test/tools/llvm-objdump/MachO/dyld_info.test
Modified:
llvm/docs/CommandGuide/llvm-objdump.rst
llvm/tools/llvm-objdump/MachODump.cpp
llvm/tools/llvm-objdump/MachODump.h
llvm/tools/llvm-objdump/ObjdumpOpts.td
llvm/tools/llvm-objdump/OtoolOpts.td
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst
index cbc525fba8a6..5ee4b83f3fe5 100644
--- a/llvm/docs/CommandGuide/llvm-objdump.rst
+++ b/llvm/docs/CommandGuide/llvm-objdump.rst
@@ -302,6 +302,11 @@ MACH-O ONLY OPTIONS AND COMMANDS
Disassemble just the specified symbol's instructions.
+.. option:: --dyld_info
+
+ Print bind and rebase information used by dyld to resolve external
+ references in a final linked binary.
+
.. option:: --dylibs-used
Display the shared libraries used for linked files.
diff --git a/llvm/test/tools/llvm-objdump/MachO/dyld_info.test b/llvm/test/tools/llvm-objdump/MachO/dyld_info.test
new file mode 100644
index 000000000000..35642acb060b
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/MachO/dyld_info.test
@@ -0,0 +1,7 @@
+RUN: llvm-objdump --macho --dyld_info %p/Inputs/bind.macho-x86_64 \
+RUN: | FileCheck %s --match-full-lines --strict-whitespace \
+RUN: --implicit-check-not={{.}}
+
+CHECK:{{.*}}bind.macho-x86_64:
+CHECK-NEXT:dyld information:
+CHECK-NEXT:[not yet implemented].
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index c785c6cfaa89..f55e6314c0d2 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -81,6 +81,7 @@ bool objdump::DataInCode;
bool objdump::FunctionStarts;
bool objdump::LinkOptHints;
bool objdump::InfoPlist;
+bool objdump::DyldInfo;
bool objdump::DylibsUsed;
bool objdump::DylibId;
bool objdump::Verbose;
@@ -111,6 +112,7 @@ void objdump::parseMachOOptions(const llvm::opt::InputArgList &InputArgs) {
FunctionStarts = InputArgs.hasArg(OBJDUMP_function_starts);
LinkOptHints = InputArgs.hasArg(OBJDUMP_link_opt_hints);
InfoPlist = InputArgs.hasArg(OBJDUMP_info_plist);
+ DyldInfo = InputArgs.hasArg(OBJDUMP_dyld_info);
DylibsUsed = InputArgs.hasArg(OBJDUMP_dylibs_used);
DylibId = InputArgs.hasArg(OBJDUMP_dylib_id);
Verbose = !InputArgs.hasArg(OBJDUMP_non_verbose);
@@ -1182,6 +1184,11 @@ static void PrintLinkOptHints(MachOObjectFile *O) {
}
}
+static void PrintDyldInfo(MachOObjectFile *O) {
+ outs() << "dyld information:\n";
+ outs() << "[not yet implemented].\n";
+}
+
static void PrintDylibs(MachOObjectFile *O, bool JustId) {
unsigned Index = 0;
for (const auto &Load : O->load_commands()) {
@@ -1900,8 +1907,8 @@ static void ProcessMachO(StringRef Name, MachOObjectFile *MachOOF,
// UniversalHeaders or ArchiveHeaders.
if (Disassemble || Relocations || PrivateHeaders || ExportsTrie || Rebase ||
Bind || SymbolTable || LazyBind || WeakBind || IndirectSymbols ||
- DataInCode || FunctionStarts || LinkOptHints || DylibsUsed || DylibId ||
- Rpaths || ObjcMetaData || (!FilterSections.empty())) {
+ DataInCode || FunctionStarts || LinkOptHints || DyldInfo || DylibsUsed ||
+ DylibId || Rpaths || ObjcMetaData || (!FilterSections.empty())) {
if (LeadingHeaders) {
outs() << Name;
if (!ArchiveMemberName.empty())
@@ -1970,6 +1977,8 @@ static void ProcessMachO(StringRef Name, MachOObjectFile *MachOOF,
DumpSectionContents(FileName, MachOOF, Verbose);
if (InfoPlist)
DumpInfoPlistSectionContents(FileName, MachOOF);
+ if (DyldInfo)
+ PrintDyldInfo(MachOOF);
if (DylibsUsed)
PrintDylibs(MachOOF, false);
if (DylibId)
diff --git a/llvm/tools/llvm-objdump/MachODump.h b/llvm/tools/llvm-objdump/MachODump.h
index 7568062bd6b0..12783e15b425 100644
--- a/llvm/tools/llvm-objdump/MachODump.h
+++ b/llvm/tools/llvm-objdump/MachODump.h
@@ -36,6 +36,7 @@ void parseMachOOptions(const llvm::opt::InputArgList &InputArgs);
extern bool Bind;
extern bool DataInCode;
extern std::string DisSymName;
+extern bool DyldInfo;
extern bool DylibId;
extern bool DylibsUsed;
extern bool ExportsTrie;
diff --git a/llvm/tools/llvm-objdump/ObjdumpOpts.td b/llvm/tools/llvm-objdump/ObjdumpOpts.td
index 9f27a6cdf163..5b35ada6e124 100644
--- a/llvm/tools/llvm-objdump/ObjdumpOpts.td
+++ b/llvm/tools/llvm-objdump/ObjdumpOpts.td
@@ -296,6 +296,12 @@ def info_plist : Flag<["--"], "info-plist">,
"Mach-O objects (requires --macho)">,
Group<grp_mach_o>;
+def dyld_info : Flag<["--"], "dyld_info">,
+ HelpText<"Print bind and rebase information used by dyld to resolve "
+ "external references in a final linked binary "
+ "(requires --macho)">,
+ Group<grp_mach_o>;
+
def dylibs_used : Flag<["--"], "dylibs-used">,
HelpText<"Print the shared libraries used for linked "
"Mach-O files (requires --macho)">,
diff --git a/llvm/tools/llvm-objdump/OtoolOpts.td b/llvm/tools/llvm-objdump/OtoolOpts.td
index 61ea701ed75d..e8bef284c0e9 100644
--- a/llvm/tools/llvm-objdump/OtoolOpts.td
+++ b/llvm/tools/llvm-objdump/OtoolOpts.td
@@ -47,7 +47,6 @@ def X : Flag<["-"], "X">, HelpText<"omit leading addresses or headers">;
// -addr_slide=arg
// -function_offsets
-
// Obsolete and unsupported:
def grp_obsolete : OptionGroup<"kind">,
HelpText<"Obsolete and unsupported flags">;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 4cb226b79525..1b9da92eb3b3 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2760,11 +2760,11 @@ int main(int argc, char **argv) {
!DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
!Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&
!DynamicSymbolTable && !UnwindInfo && !FaultMapSection &&
- !(MachOOpt &&
- (Bind || DataInCode || DylibId || DylibsUsed || ExportsTrie ||
- FirstPrivateHeader || FunctionStarts || IndirectSymbols || InfoPlist ||
- LazyBind || LinkOptHints || ObjcMetaData || Rebase || Rpaths ||
- UniversalHeaders || WeakBind || !FilterSections.empty()))) {
+ !(MachOOpt && (Bind || DataInCode || DyldInfo || DylibId || DylibsUsed ||
+ ExportsTrie || FirstPrivateHeader || FunctionStarts ||
+ IndirectSymbols || InfoPlist || LazyBind || LinkOptHints ||
+ ObjcMetaData || Rebase || Rpaths || UniversalHeaders ||
+ WeakBind || !FilterSections.empty()))) {
T->printHelp(ToolName);
return 2;
}
More information about the llvm-commits
mailing list