From 407cc21c32f1a867ca31beef45c51bf032328789 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Thu, 17 Jul 2014 22:47:16 +0000 Subject: [PATCH] Add printing of Mach-O stabs in llvm-nm. llvm-svn: 213327 --- llvm/include/llvm/Support/MachO.h | 4 +- llvm/test/Object/Inputs/macho-hello-g.macho-x86_64 | Bin 0 -> 8680 bytes llvm/test/Object/nm-trivial-object.test | 15 ++++ llvm/tools/llvm-nm/llvm-nm.cpp | 86 ++++++++++++++++++++- 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100755 llvm/test/Object/Inputs/macho-hello-g.macho-x86_64 diff --git a/llvm/include/llvm/Support/MachO.h b/llvm/include/llvm/Support/MachO.h index bd4dc2f..57d7dff 100644 --- a/llvm/include/llvm/Support/MachO.h +++ b/llvm/include/llvm/Support/MachO.h @@ -386,13 +386,15 @@ namespace llvm { enum StabType { // Constant values for the "n_type" field in llvm::MachO::nlist and - // llvm::MachO::nlist_64 when "(n_type & NlistMaskStab) != 0" + // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0" N_GSYM = 0x20u, N_FNAME = 0x22u, N_FUN = 0x24u, N_STSYM = 0x26u, N_LCSYM = 0x28u, N_BNSYM = 0x2Eu, + N_PC = 0x30u, + N_AST = 0x32u, N_OPT = 0x3Cu, N_RSYM = 0x40u, N_SLINE = 0x44u, diff --git a/llvm/test/Object/Inputs/macho-hello-g.macho-x86_64 b/llvm/test/Object/Inputs/macho-hello-g.macho-x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..41be03a0e2af2b39ede668c9860d8d70ee67b182 GIT binary patch literal 8680 zcmeHNO=uHA6rQzetF1N#5B{?iD^;QCK|#<%S{mG9(bl#iLK%~0YXY03BpXfDLZN!d zq1wCP#fulgt2aTx-aLvIPbv`VT%wVLft0BePQEDh<#88D&^?F`S`W?=6wB~*bLlfRS5Cc^>Bg(9ZFgBOUdGzsX3pg@`dY%IGoU? z@`e6-KACpCS+{_o=6t@&w_hb7Chu#qp}y&&U&!QcsDS2t4^+Ng%1^9ILvA>vEah%x zaw(a~&Ex~zct0Mge7xrr;=hTMZd%S15?Qw%)m&dy<=d;05aX==Unz5*EY4+!}i?^b&u|7r}hSx2bqy zJs;1pj@O^7k>QIM;zPsXGhsLF6PQv}#W0Uv*AYCo{S2_{Yqwzxxem<0C`I&RWE}aS z|0!?>#&Wk1vl!cKxOPsHDcIQ(wN`ye5t727;Pxmh?a_lsFz7bQ*&Mlm~sHh zIv(Er+&%iP|HZ?F$_WReJi9D{Pb>vnz5#}!TkQ%*wZCyrq>Vi+(C7zPXjh5^HXVZbo( ze=#uWR6aS2Uu|b;+a>J$P5dYKUzz{mR7&5S%4F54ym>CFT`;}~Jn@f}6=(6aJ@sn2 z*7KMqF|u@M3B$m6t!EzNa+=03pKG<6<9c4+zLhU{shz>s{DX8s^pRh0`Ste{Mk;@j zQh3du7#)}y31-u(F7^c1K({Xos~oW+9j$H4mNII?JtW)2tVNhh!+>GHFkl!k3>XFs z1BL;^fMLKeU>GnA7zX||2D*+!##nP#jLo^A87`CP52JZKRuIdg5b27^Su~*i86b!y z(U0FEvuWv;-RY9=qSu{Zcy~6D$%!7mooEry4>J}LUaWrTU>pA&GuHtyKqDZ=2E)_6}*}`wSiP1<6c{C6;0<is64Bit()) { + STE_64 = MachO->getSymbol64TableEntry(I->Symb); + NType = STE_64.n_type; + NSect = STE_64.n_sect; + NDesc = STE_64.n_desc; + } else { + STE = MachO->getSymbolTableEntry(I->Symb); + NType = STE.n_type; + NSect = STE.n_sect; + NDesc = STE.n_desc; + } + + char Str[18] = ""; + format("%02x", NSect).print(Str, sizeof(Str)); + outs() << ' ' << Str << ' '; + format("%04x", NDesc).print(Str, sizeof(Str)); + outs() << Str << ' '; + if (const char *stabString = getDarwinStabString(NType)) + format("%5.5s", stabString).print(Str, sizeof(Str)); + else + format(" %02x", NType).print(Str, sizeof(Str)); + outs() << Str; +} + static void sortAndPrintSymbolList(SymbolicFile *Obj, bool printName) { if (!NoSort) { if (NumericSort) @@ -532,7 +610,10 @@ static void sortAndPrintSymbolList(SymbolicFile *Obj, bool printName) { if (I->Size != UnknownAddressOrSize) outs() << ' '; } - outs() << I->TypeChar << " " << I->Name << "\n"; + outs() << I->TypeChar; + if (I->TypeChar == '-' && MachO) + darwinPrintStab(MachO, I); + outs() << " " << I->Name << "\n"; } else if (OutputFormat == sysv) { std::string PaddedName(I->Name); while (PaddedName.length() < 20) @@ -657,6 +738,9 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) { DataRefImpl Symb = I->getRawDataRefImpl(); uint8_t NType = getNType(Obj, Symb); + if (NType & MachO::N_STAB) + return '-'; + switch (NType & MachO::N_TYPE) { case MachO::N_ABS: return 's'; -- 2.7.4