9

When using c++ template, and especially tuples, I often get very long mangled names like

_ZN11__sanitizer13InternalAllocEmPNS_28SizeClassAllocatorLocalCacheINS_20SizeClassAllocator32ILm0ELy140737488355328ELm0ENS_12SizeClassMapILm3ELm4ELm8ELm17ELm64ELm14EEELm20ENS_15TwoLevelByteMapILy32768ELy4096ENS_20NoOpMapUnmapCallbackEEES5_EEEEm

This is obviously fine in nominal case, and ease debugging but, when I use large tuples of custom types (with large namespaces) this ends up with very huge binaries just because of mangled names; Some tools (like valgrind) even have a symbol name maximum length that make analysis almost impossible.

I was wondering if there is a way to ask g++/clang++ to use a custom mangling function (say md5) so that the very long symbol becomes 5c66b1073e1b453900bd7d32cb79fc0e which is way shorter.

OznOg
  • 4,440
  • 2
  • 26
  • 35

2 Answers2

2

The absence of this innovation in any important C++ implementation is accounted for by the fact that a C++ compiler's name-mangling protocol is part of its ABI and can't be the user's choice at the same time.

Notoriously, C++ code compiled with GCC is not interoperable with code compiled with Microsoft compilers because, inter alia, they use different name-mangling protocols. And the fact that they do use different name-mangling protocols, and cannot be directed to use the same one, guarantees that subtler ABI incompatibilities will not survive an attempted linkage.

The constancy of the C++ compiler's name-mangling protocol is also assumed in other toolchain utilities, e.g. binutils nm, objdump.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
1

I don't know of any way to replace symbols entirely. But you can strip the binaries with -s to remove all symbols from it. This can reduce the size of your shipped binaries, but can of course not be used with debugging.

N00byEdge
  • 1,106
  • 7
  • 18
  • Actually I would like the compiler not to generate such big symbols as it may take a long time to write on file system things I would stip away later. BTW, choosing the mangling is not really about striping, IMHO – OznOg Feb 06 '19 at 15:03