Bug 34166 - -fleading-underscore duplicate underscore in some template cases
Summary: -fleading-underscore duplicate underscore in some template cases
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-20 20:04 UTC by stephane hockenhull
Modified: 2007-11-28 22:34 UTC (History)
1 user (show)

See Also:
Host: i386-linux-elf
Target: i386-unknown-elf
Build: i386-linux-elf
Known to work:
Known to fail:
Last reconfirmed:


Attachments
.ii file that produce error (55.39 KB, text/plain)
2007-11-21 18:02 UTC, stephane hockenhull
Details

Note You need to log in before you can comment on or make changes to this bug.
Description stephane hockenhull 2007-11-20 20:04:35 UTC
we get duplicate underscore prefixes on std::string template function calls generated when using -fleading-underscore

the .stabs entries are fine ("_ZNSs7reserveEm") but the generated assembler code calls "__ZNSs7reserveEm" with two underscores instead
so the linker gives us a undefined symbol "__ZNSs7reserveEm" error

we tried with -O2, -O1, and -O0 and get the same result

other templates compile fine
------------------------------
Using built-in specs.
Target: i386-unknown-elf
Configured with: ../configure --with-mpfr-dir=../../mpfr-2.2.1/ --target=i386-unknown-elf --prefix=/home/shockenhull/bin/i386-unknown-elf --enable-targets=all
Thread model: single
gcc version 4.1.1
Linux shockenhull 2.6.16.13-4-smp #1 SMP Wed May 3 04:53:23 UTC 2006 i686 athlon i386 GNU/Linux

-------------------------------------------

i386-unknown-elf-g++ -c -fleading-underscore -g -O0 -D__cpluscplus -D__CYGWIN__ -I../externals/include/w32api -D__cdecl= -Ddllimport= -DDECLSPEC_NORETURN=  --save-temps -DTARGET_WIN32 -DTARGET_OS="WIN32" -DPRAY_WINDOWS_DOESNT_CRASH=1 -DTARGET_IA32 -DTARGET_CPU="IA32" -D__cdecl= -D__declspec= -Ddllimport= -D__INSIDE_CYGWIN__ -Wno-pmf-conversions -I../ -I../../../ -I/home/shockenhull/projects/sqrlen/base   -I/home/shockenhull/projects/sqrlen/base/win32   -I/home/shockenhull/projects/sqrlen/base/ia32   -I../externals/include -I../../../src -I/home/shockenhull/projects/sqrlen/drivers/video_out -I/home/shockenhull/projects/sqrlen/drivers/video_out/win32_gl_hack -I/home/shockenhull/projects/sqrlen/drivers/pc_misc/xml -I/home/shockenhull/projects/sqrlen/drivers/pc_misc/ministring -I/home/shockenhull/projects/sqrlen/drivers/fs  -I/home/shockenhull/projects/sqrlen/drivers/fs/win32 -include windef.h  -o pc_misc/xml/test.o /home/shockenhull/projects/sqrlen/drivers/pc_misc/xml/test.cpp

-----------------------------------------------------------
#include <stdio.h>
#include <string>

void bob(void)
{
	std::string s;
	s = "biby";
	s.replace(1, 4, "ob");
	printf("%s\n", s.c_str());
}

-----------------------------------------------------------

I have the the test.ii file but it is 424KiB so I cannot post it here.
please email me for the file, I will email it back.
Comment 1 stephane hockenhull 2007-11-21 18:02:57 UTC
Created attachment 14598 [details]
.ii file that produce error
Comment 2 stephane hockenhull 2007-11-23 20:21:12 UTC
this bug seem to be related to the fact that std::string's name mangling is optimized by shortening it to a special encoding which might bypass the underscore prefix option

is there an option to disable the special case encoding for std::string ?
Comment 3 stephane hockenhull 2007-11-28 22:23:02 UTC
the problem is in the pre-compiled c++ library

work around:

using option -D_GLIBCXX_EXTERN_TEMPLATE=0 
disable pre-compiled templates in the c++ headers and force correct instanciation when -fleading-underscore is used

thanks to Andrew Pinski for pointing to the "extern template" feature.

maybe overriding the platform's defaut underscore prefix should define _GLIBCXX_EXTERN_TEMPLATE=0 if not overriden explicitly so the glitch wont come up?

Comment 4 Andrew Pinski 2007-11-28 22:34:14 UTC
This is not a bug since you did not compile libstdc++ with -fleading-underscore.  There are some headers with extern template.