https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77489
Bug ID: 77489 Summary: Invalid mangling of static local variables Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: Tom.Aernoudt at synopsys dot com Target Milestone: --- Created attachment 39566 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39566&action=edit testcase According to the Itanium C++ ABI '5.1.6 Scope Encoding', the discriminator of static local variables should be mangled as follows: <discriminator> := _ <non-negative number> # when number < 10 := __ <non-negative number> _ # when number >= 10 But gcc always mangles it as follows: <discriminator> := _ <non-negative number> The attached testcase can be used to reproduce the issue: > g++ testcase.cc -o testcase.o -c > nm testcase.o | grep localVar 0000000000000000 b _ZZ3foovE8localVar 0000000000000000 d _ZZ3foovE8localVar_0 0000000000000004 d _ZZ3foovE8localVar_1 0000000000000028 d _ZZ3foovE8localVar_10 000000000000002c d _ZZ3foovE8localVar_11 0000000000000008 d _ZZ3foovE8localVar_2 000000000000000c d _ZZ3foovE8localVar_3 0000000000000010 d _ZZ3foovE8localVar_4 0000000000000014 d _ZZ3foovE8localVar_5 0000000000000018 d _ZZ3foovE8localVar_6 000000000000001c d _ZZ3foovE8localVar_7 0000000000000020 d _ZZ3foovE8localVar_8 0000000000000024 d _ZZ3foovE8localVar_9 _ZZ3foovE8localVar_10 and _ZZ3foovE8localVar_11 should be mangled as _ZZ3foovE8localVar__10_ and _ZZ3foovE8localVar__11_ according to the C++ ABI. Tested with gcc 5.2: > g++ -v Using built-in specs. COLLECT_GCC=/depot/gcc-5.2.0/bin/g++ COLLECT_LTO_WRAPPER=/depotbld/RHEL6.6/gcc-5.2.0/bin/../libexec/gcc/x86_64-redhat-linux/5.2.0/lto-wrapper Target: x86_64-redhat-linux Configured with: /remote/depotsrc/depotsrc/src/gcc-5.2.0/configure --prefix=/depot/gcc-5.2.0 --enable-bootstrap --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,fortran --disable-libgcj --with-cpu=generic --build=x86_64-redhat-linux Thread model: posix gcc version 5.2.0 (GCC) It looks like the master branch of gcc still has the issue, cfr cp/mangle.c:1906: static void write_discriminator (const int discriminator) { /* If discriminator is zero, don't write anything. Otherwise... */ if (discriminator > 0) { write_char ('_'); write_unsigned_number (discriminator - 1); } }