From d9911f6f7baca75a9d51352bf9ef3718ee05cd82 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Thu, 29 Mar 2018 20:04:29 +0000 Subject: [PATCH] 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 --- .../X86/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64 | Bin 0 -> 8304 bytes llvm/test/tools/llvm-nm/X86/dyldinfo.test | 6 ++++++ llvm/tools/llvm-nm/llvm-nm.cpp | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100755 llvm/test/tools/llvm-nm/X86/Inputs/Strip-N.LC_MAIN.exe.macho-x86_64 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 index 0000000000000000000000000000000000000000..eaacd44ef0618098f1866f6ebd3c6e129c4502a4 GIT binary patch literal 8304 zcmeHM&ubGw7@erq+Ez_Z{??^fe;wKi9(rt~!7VMC+7^l+L(*(bV4K9vh9(EGSOoV_ z=%3)Zr{46YpiuRq7s0crR8a7yh?u^&JKOHYAK=A<%tyb>yl=jFGxKH^b~`V=efqIW zh{Sdw7Pbi?_Q6+o2ysUk_!Z(H+=NS+NnK1|O<%dpXxtKU_)A2d*GQCdGCe&RPx1RF z<1wKy<|f*dGeb((s=KTO*2a{zCEg)IBGF&G)P%1 z%@<2~SuD+#eH@?P1I5QZrxCYu1TDcY_jMgE<#1{;6=}i##r8Ga-^jk=%x!W@S+Zrd zF_$abvf?_whF)I0#e%9Kk+5epZV=7pE%0La~H*1&%xNprP1{8NO*>g zfTyB(1TZbc|PQP8u_2(OQ9+-9*&Up-)r*6IZGI0Fi*h*#htNZm6h$Z2ov%~kZ zA!ZDA8tY|0K8I1`ID>Gu@q8sZo?}{xt+6rwM5F3jbA1>3FppvmNwAY}j+Ze49nL5m z>I0}vE1(t73TOqi0$KsBfL1^&@Xr*OGQD@^;zz?=Y8%C%Yw7PC+PnGH^lG0?Z))B2 z)>g$jKiAGZ^U`m}lmKr5gX&?d0@>p0Ck5HozsS +# LC-MAIN: 0000000100000000 T __mh_execute_header +# LC-MAIN: U _printf +# LC-MAIN: U dyld_stub_binder diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index e494920018d2..4282a605c454 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -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 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 << ""; + if (FoundFns[f] == (uint64_t)lc_main_offset) + FOS << ""; + else + FOS << ""; FOS << '\0'; FunctionStartsAdded++; } -- 2.34.1