For llvm-nm and Mach-O files that are fully stripped, special case a redacted LC_MAIN

As a further refinement on:

r328274 - For llvm-nm and Mach-O files also use function starts info in some cases when printing symbols

we want to special case a redacted LC_MAIN so it is easier to find.

rdar://38978929

llvm-svn: 328820
This commit is contained in:
Kevin Enderby 2018-03-29 20:04:29 +00:00
parent 943e12e1c5
commit d9911f6f7b
3 changed files with 17 additions and 2 deletions

View File

@ -2,6 +2,7 @@
# RUN: llvm-nm -no-dyldinfo %p/Inputs/Strip-ST.dylib.macho-x86_64 | FileCheck --check-prefix=NO-DYLDINFO %s
# RUN: llvm-nm -dyldinfo-only %p/Inputs/Strip-ST.dylib.macho-x86_64 | FileCheck --check-prefix=DYLDINFO-ONLY %s
# RUN: llvm-nm %p/Inputs/Strip-N.hello.exe.macho-x86_64 | FileCheck --check-prefix=FUNC-STARTS %s
# RUN: llvm-nm %p/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64 | FileCheck --check-prefix=LC-MAIN %s
# DEFAULT: 0000000000000f90 T __Bob_is_slow
# DEFAULT: 0000000000001008 D __T0ims_data
@ -24,3 +25,8 @@
# FUNC-STARTS: 0000000100000f30 T _main
# FUNC-STARTS: U _printf
# FUNC-STARTS: U dyld_stub_binder
# LC-MAIN: 0000000100000f50 t <redacted LC_MAIN>
# LC-MAIN: 0000000100000000 T __mh_execute_header
# LC-MAIN: U _printf
# LC-MAIN: U dyld_stub_binder

View File

@ -1588,8 +1588,10 @@ dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
}
}
// Trying adding symbol from the function starts table.
// Trying adding symbol from the function starts table and LC_MAIN entry
// point.
SmallVector<uint64_t, 8> FoundFns;
int64_t lc_main_offset = -1;
for (const auto &Command : MachO->load_commands()) {
if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) {
// We found a function starts segment, parse the addresses for
@ -1598,6 +1600,10 @@ dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
MachO->getLinkeditDataLoadCommand(Command);
MachO->ReadULEB128s(LLC.dataoff, FoundFns);
} else if (Command.C.cmd == MachO::LC_MAIN) {
MachO::entry_point_command LCmain =
MachO->getEntryPointCommand(Command);
lc_main_offset = LCmain.entryoff;
}
}
// See if these addresses are already in the symbol table.
@ -1647,7 +1653,10 @@ dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
F.NDesc = 0;
F.IndirectName = StringRef();
SymbolList.push_back(F);
FOS << "<redacted function " << f << ">";
if (FoundFns[f] == (uint64_t)lc_main_offset)
FOS << "<redacted LC_MAIN>";
else
FOS << "<redacted function " << f << ">";
FOS << '\0';
FunctionStartsAdded++;
}