On 27 November 2007 17:35, Stephane Hockenhull wrote: > On Tuesday 27 November 2007 11:09, you wrote: >> On 27 November 2007 15:49, Stephane Hockenhull wrote:
>>> on the win32 platform all C symbols requires a leading underscore >> >> Yes, that is the case on almost all platforms. >> >> And the compiler *automatically* puts leading underscores on symbols on >> all those platforms already. >> >> So the question remains: why are you using -fleading-underscores? >>> everything works fine until we start using std::string objects, there is >>> a bug with the special case name mangling. >>> >>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34166 >> >> Yes, but as you yourself explain, the symbols already have leading >> underscores, and when you use -fleading-underscore, because it fails to >> consistently add *extra* underscores. > > no, the symbol have a first underscore because that's how G++ mangles them, > it ALWAYS add 1 underscore (without -fleading-underscore) and some other > characters. > > without -fleading-underscore for example "strstr" is called "strstr" but > win32 libraries need "_strstr" so -fleading-underscore must be used You are simply wrong about this. Let me demonstrate: /tmp/lundersc $ cat test.cpp extern "C" char *strstr (const char *, const char *); void strtest (void) { strstr ("foo", "foobar"); } /tmp/lundersc $ g++ --save-temps -g -O0 -fno-builtin -c test.cpp -o test.o /tmp/lundersc $ grep strstr test.s call _strstr .def _strstr; .scl 3; .type 32; .endef /tmp/lundersc $ As you see, all the reference the compiler generates to strstr are already prefixed by an underscore, with no need for any special flags. > with -fleading-underscore gcc/g++ adds an underscore to ALL symbols, > including mangled ones, therefore it need TWO underscores for mangled names > and ONE underscore for normal identifiers. Given that you have misunderstood the starting point, your conclusion here is wrong. *All* names, whether mangled or non-mangled, are given an underscore by the compiler. This underscore is concealed at the C and C++ level and is visible and relevant only in the assembler level. > which g++ does right 99.9% of the time, but it only does it halfway to > std::string. > > it tries to call it as "__ZNSs7replaceEmmPKc" > but it instanciate it as "_ZNSs7replaceEmmPKc" > > which is clearly a bug Yes, that bit is, but then again, you should not be using -fleading-underscore in the first place, and if you think you do need to do so, there is something more fundamental wrong in your setup. Are you sure you're even using a win32 version of the compiler? > I just need to know where in the code this boolean option is located and > where the mangling is done so I can patch it up. No, you do not. You have misdiagnosed the problem and obtained an incorrect solution. Have you read the manual? When it explains -fleading-underscores, it explicitly states: " Not all targets provide complete support for this switch. " The x86 is one of those targets. It does not provide complete support for this switch, but then again, there is not and has never been any need for this switch on the x86. > joking aside, we need to generate ELF object files for running on windows. OK, you are now attempting something very very wrong indeed. The win32 version of the assembler will not generate ELF files, and even if it did, windows cannot make any use of the ELF format, it uses PE-COFF. And the output file format has absolutely nothing to do with whether or not the symbols have leading underscores, so claiming that you have to use -fleading-underscores because you need to generate ELF files is a non-sequitur. So: You do not need to use -fleading-underscores, if you think you do then /something else/ is going wrong already, and you are just making it worse for yourself because -fleading-underscores is not supported on x86/win32 and the use of it is giving you *additional problems* on top of the problem you already have, and you have a mistaken notion that any of this has anything to do with ELF or non-ELF. What is the *real* problem? What is it that convinced you that you needed to use -fleading-underscores in the first place? Because whatever it was, it has a different and better solution - one that works, not one that breaks even worse. cheers, DaveK -- Can't think of a witty .sigline today....