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
This commit is contained in:
Adrian Prantl 2021-11-09 16:00:29 -08:00
parent de2cc2a002
commit 621e2de138
7 changed files with 35 additions and 8 deletions

View File

@ -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.

View File

@ -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].

View File

@ -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)

View File

@ -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;

View File

@ -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)">,

View File

@ -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">;

View File

@ -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;
}