Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demangling of C++ names of Linux Binaries does not work on Mac OS #43

Closed
cwgreene opened this issue Mar 22, 2017 · 3 comments
Closed

Demangling of C++ names of Linux Binaries does not work on Mac OS #43

cwgreene opened this issue Mar 22, 2017 · 3 comments

Comments

@cwgreene
Copy link

cwgreene commented Mar 22, 2017

Steps to reproduce:

Compare output of tests/testdata/linux-x86_64/oldbloaty.bin on Linux and Mac.

Linux:

     VM SIZE                                                                                        FILE SIZE
 --------------                                                                                  --------------
  20.0%  99.0Ki [Unmapped]                                                                        6.55Mi  94.4%
  62.1%   307Ki [Other]                                                                            308Ki   4.3%
   2.5%  12.3Ki re2::RE2::Match(re2::StringPiece const&, int, int, re2::RE2::Anchor, re2::String  12.3Ki   0.2%
   1.6%  7.83Ki re2::unicode_groups                                                               7.83Ki   0.1%
   1.5%  7.56Ki re2::NFA::Search                                                                  7.56Ki   0.1%
   1.2%  5.76Ki re2::BitState::TrySearch                                                          5.76Ki   0.1%
   1.0%  4.81Ki _dwarf_exec_frame_instr                                                           4.81Ki   0.1%
   0.9%  4.49Ki re2::DFA::DFA                                                                     4.49Ki   0.1%
   0.9%  4.34Ki re2::Regexp::Parse                                                                4.34Ki   0.1%
   0.8%  4.20Ki re2::RE2::Init                                                                    4.20Ki   0.1%
   0.8%  4.09Ki re2::Prog::IsOnePass                                                              4.09Ki   0.1%
   0.8%  4.04Ki re2::Compiler::PostVisit                                                          4.04Ki   0.1%
   0.8%  4.01Ki _dwarf_internal_srclines                                                          4.01Ki   0.1%
   0.8%  3.91Ki re2::Regexp::FactorAlternationRecursive                                           3.91Ki   0.1%
   0.8%  3.86Ki bool bloaty::(anonymous namespace)::ForEachElf<bloaty::(anonymous namespace)::Do  3.86Ki   0.1%
   0.8%  3.77Ki re2::DFA::RunStateOnByte                                                          3.77Ki   0.1%
   0.7%  3.68Ki re2::unicode_casefold                                                             3.68Ki   0.1%
   0.7%  3.40Ki re2::DFA::InlinedSearchLoop(re2::DFA::SearchParams*, bool, bool, bool) [clone .c  3.40Ki   0.0%
   0.7%  3.38Ki re2::DFA::InlinedSearchLoop(re2::DFA::SearchParams*, bool, bool, bool) [clone .c  3.38Ki   0.0%
   0.7%  3.35Ki re2::Regexp::Walker<int>::WalkInternal(re2::Regexp*, int, bool) [clone .constpro  3.35Ki   0.0%
   0.0%     165 [None]                                                                                 0   0.0%
 100.0%   495Ki TOTAL                                                                             6.93Mi 100.0%

Mac:

     VM SIZE                                                                                        FILE SIZE
 --------------                                                                                  --------------
  20.0%  99.0Ki [Unmapped]                                                                        6.55Mi  94.4%
  62.1%   307Ki [Other]                                                                            308Ki   4.3%
   2.5%  12.3Ki _ZNK3re23RE25MatchERKNS_11StringPieceEiiNS0_6AnchorEPS1_i                         12.3Ki   0.2%
   1.6%  7.83Ki _ZN3re214unicode_groupsE                                                          7.83Ki   0.1%
   1.5%  7.56Ki _ZN3re23NFA6SearchERKNS_11StringPieceES3_bbPS1_i                                  7.56Ki   0.1%
   1.2%  5.76Ki _ZN3re28BitState9TrySearchEiPKc                                                   5.76Ki   0.1%
   1.0%  4.81Ki _dwarf_exec_frame_instr                                                           4.81Ki   0.1%
   0.9%  4.49Ki _ZN3re23DFAC1EPNS_4ProgENS1_9MatchKindEl                                          4.49Ki   0.1%
   0.9%  4.34Ki _ZN3re26Regexp5ParseERKNS_11StringPieceENS0_10ParseFlagsEPNS_12RegexpStatusE      4.34Ki   0.1%
   0.8%  4.20Ki _ZN3re23RE24InitERKNS_11StringPieceERKNS0_7OptionsE                               4.20Ki   0.1%
   0.8%  4.09Ki _ZN3re24Prog9IsOnePassEv                                                          4.09Ki   0.1%
   0.8%  4.04Ki _ZN3re28Compiler9PostVisitEPNS_6RegexpENS_4FragES3_PS3_i                          4.04Ki   0.1%
   0.8%  4.01Ki _dwarf_internal_srclines                                                          4.01Ki   0.1%
   0.8%  3.91Ki _ZN3re26Regexp26FactorAlternationRecursiveEPPS0_iNS0_10ParseFlagsEi               3.91Ki   0.1%
   0.8%  3.86Ki _ZN6bloaty12_GLOBAL__N_110ForEachElfIZNS0_L17DoReadELFSectionsEPNS_9RangeSinkEbE  3.86Ki   0.1%
   0.8%  3.77Ki _ZN3re23DFA14RunStateOnByteEPNS0_5StateEi                                         3.77Ki   0.1%
   0.7%  3.68Ki _ZN3re216unicode_casefoldE                                                        3.68Ki   0.1%
   0.7%  3.40Ki _ZN3re23DFA17InlinedSearchLoopEPNS0_12SearchParamsEbbb.constprop.134              3.40Ki   0.0%
   0.7%  3.38Ki _ZN3re23DFA17InlinedSearchLoopEPNS0_12SearchParamsEbbb.constprop.133              3.38Ki   0.0%
   0.7%  3.35Ki _ZN3re26Regexp6WalkerIiE12WalkInternalEPS0_ib.constprop.183                       3.35Ki   0.0%
   0.0%     165 [None]                                                                                 0   0.0%
 100.0%   495Ki TOTAL                                                                             6.93Mi 100.0%

Note that mac binaries built on mac are unaffected.

Mac binaries (MachO) on linux, of course, can't be processed because bloaty uses otool to process MachO binaries.

@cwgreene cwgreene changed the title Demangling of C++ names does not work on mac for linux binaries Demangling of C++ names of Linux Binaries does not work on Mac OS Mar 22, 2017
@cwgreene
Copy link
Author

cwgreene commented Mar 22, 2017

So, bloaty shells out to c++filt. It appears that when you create a MachO binary (clang++ -c test.cc --target x86_64-pc-linux-macho), clang will generate an additional _ in the mangled name (huzzah for ABI inconsistency!).

So the quick hack is to set a flag on the binary, and if the binary is not MachO, pass in -n to c++filt.

Ubuntu:

$ c++filt --version 
GNU c++filt (GNU Binutils for Ubuntu) 2.24
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
$ c++filt --help
Usage: c++filt [options] [mangled names]
Options are:
  [-_|--strip-underscore]     Ignore first leading underscore
  [-n|--no-strip-underscore]  Do not ignore a leading underscore (default)
  [-p|--no-params]            Do not display function arguments
  [-i|--no-verbose]           Do not show implementation details (if any)
  [-t|--types]                Also attempt to demangle type encodings
  [-s|--format {none,auto,gnu,lucid,arm,hp,edg,gnu-v3,java,gnat}]
  [@]                   Read extra options from 
  [-h|--help]                 Display this information
  [-v|--version]              Show the version information
Demangled names are displayed to stdout.
If a name cannot be demangled it is just echoed to stdout.
If no names are provided on the command line, stdin is read.
Report bugs to .

On Mac:

$ c++filt --version
GNU c++filt 070207 20070207
Copyright 2005 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
$ c++filt --help
Usage: c++filt [options] [mangled names]
Options are:
  [-_|--strip-underscore]     Ignore first leading underscore (default)
  [-n|--no-strip-underscore]  Do not ignore a leading underscore
  [-p|--no-params]            Do not display function arguments
  [-i|--no-verbose]           Do not show implementation details (if any)
  [-t|--types]                Also attempt to demangle type encodings
  [-s|--format {none,auto,gnu,lucid,arm,hp,edg,gnu-v3,java,gnat}]
  [@]                   Read extra options from 
  [-h|--help]                 Display this information
  [-v|--version]              Show the version information
Demangled names are displayed to stdout.
If a name cannot be demangled it is just echoed to stdout.
If no names are provided on the command line, stdin is read.

@haberman
Copy link
Member

haberman commented Apr 6, 2017

Interesting. Since we are depending on a platform-specific tool, it makes sense to me that we pass it platform-specific flags. The knowledge that Linux binaries need the extra flag on OS X is pretty weird and arbitrary, but since a more principled solution is not presenting itself, let's go for the narrow/arbitrary solution for now.

@haberman
Copy link
Member

haberman commented Nov 9, 2017

This should be fixed by #78.

@haberman haberman closed this as completed Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants