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.

2 Answers 2

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.

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.

1
  • 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 6, 2019 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.