For llvm-nm and Mach-O files that are fully stripped, special case a redacted LC_MAIN
authorKevin Enderby <enderby@apple.com>
Thu, 29 Mar 2018 20:04:29 +0000 (20:04 +0000)
committerKevin Enderby <enderby@apple.com>
Thu, 29 Mar 2018 20:04:29 +0000 (20:04 +0000)
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

llvm/test/tools/llvm-nm/X86/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64 [new file with mode: 0755]
llvm/test/tools/llvm-nm/X86/dyldinfo.test
llvm/tools/llvm-nm/llvm-nm.cpp

diff --git a/llvm/test/tools/llvm-nm/X86/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64 b/llvm/test/tools/llvm-nm/X86/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64
new file mode 100755 (executable)
index 0000000..eaacd44
Binary files /dev/null and b/llvm/test/tools/llvm-nm/X86/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64 differ
index 483dd21..90e652f 100644 (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
index e494920..4282a60 100644 (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++;
         }