View Issue Details

IDProjectCategoryView StatusLast Update
0000494GCC - GNU C CompilerBugpublic2011-12-04 08:09
ReporterdmikAssigned Topsmedley 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000494: __stdcall function names are C++-mangled
DescriptionThis is wrong since (according to the original MSDN specification the name is decorated with the underscore nad suffixed with '@N' where N is the number of bytes in the argument list.

E.g. void __stdcall foo(int a) should get a "_foo@4" name in both C and C++ mode while it gets "__Z3fooi@4" in C++ mode instead.

Note that IBM VAC behaves the MS-compatible way and doesn't mangle __stdcall names too.

Another difference is that vararg functions like void __stdcall bar(...) will still get a '@N' suffix (where N is the number of non-vararg bytes) while according to the spec __stdcall should be equal to __cdecl in this case (i.e. the above example should give "_bar", not "_bar@0" as it gives now).

The problem exists in all versions of GCC for OS/2 (3.x and 4.x).

TagsNo tags attached.



2011-10-29 08:46

administrator   ~0002024

How does cygwin behave?


2011-10-29 19:18

administrator   ~0002025

OK - for emx - emx_c_set_decl_assembler_name() in emx.c does the name mangling

This is emx specific.

For other platforms, TARGET_MANGLE_DECL_ASSEMBLER_NAME can be defined (and is on windows) to perform the adjustments required for things like stdcall or fastcall


2011-10-29 19:31

administrator   ~0002026

ok so I have some ideas now on how to better replicate the mingw / cygwin behaviour - and also simplify the gcc diffs


2011-10-29 21:25

reporter   ~0002027

I haven't checked cygwin but I believe it behaves correctly. Which means there should be a corresponding codepath in the GCC sources. Could you please commit your fixes to this issue to github so that I could see them as well?

If I come with some patches on my side, I will commit them there too. Therefore we will be able to review each other.


2011-10-30 01:27

reporter   ~0002029

I think this should relate to the OS/2-specific _Optlink modifier as well: IBM VAC seems to suppress mangling for it too.


2011-10-30 11:02

administrator   ~0002030

_optlink isn't currently supported as the patches from 3.3.x can't be applied cleanly and I don't understand them well enough to try and implement them

When I have real patches that work, not just ideas, I'll commit


2011-11-04 03:44

reporter   ~0002033

One more interesting observation. Sometimes, declaring the function with extern "C" is enough to workaround the problem and get the C++ mangling disabled, sometimes the definition also needs to be placed within extern "C" {} in order to achieve that. The randomness of this behavior reminds me of the similar randomness with _System underscores as described in 0000474... Note that I use the test build of GCC 4.4.6 from that ticket here.


2011-11-04 04:04

reporter   ~0002034

In other words, if both the declaration (with extern "C") and the definition (without extern "C") are in the same source file, it works. If the declaration (with extern "C") is in a separate header, it doesn't (in 90% of cases, there are a few where it works). Really strange; I always thought the header is a big macro, nothing more (WRT the compilation of the translation unit).


2011-11-04 04:39

reporter   ~0002035

The _Pascal cconv should behave like _System in terms of mangling, i.e. no leading underscore.


2011-11-05 11:02

administrator   ~0002036

Per jabber conversation, mingw appears to behave in the same manner as the emx port.


2011-11-23 04:14

reporter   ~0002053

I did some more tests. The native MS complier does *not* suppress C++ mangling for __stdcall -- a regular extern "C" is necessary for that. What it does however is it treats a __stdcall declaration with ... (varargs) as __cdecl -- GCC is unaware of that and this is what needs to be fixed.


2011-11-23 04:46

reporter   ~0002054

Fuck fuck fuck fuck. Killed my comment again. Lame Mantis author.

Checked the native IBM compiler, and according to that, any explicit cconv specification (checked _System, _Optlink __cdecl and __stdcall) automatically assumes extern "C" and disables C++ mangling.

I really wonder who should we be compatible with... Ideally it would be nice to have an option. I will check how hard it is.


2011-11-23 06:27

administrator   ~0002055

It's actually a PHP issue with session authentication - nothing to do with mantis


2011-11-23 06:34

administrator   ~0002056

I bumped up session.gc_maxlifetime to 24 hrs in php.ini - will hopefully help


2011-11-24 04:38

reporter   ~0002057

Ah, okay, lame me then. Sorry, author.

I made it behave the IBM VAC way here: That is, extern "C" is implied for all listed calling conventions even when they are used in C++ code.

If we ever find out that we need MSVC-like behavior, we will introduce a target-specific command line option that will switch between these two behaviors.


2011-11-24 22:11

reporter   ~0002058

It turns out that the code from winnt.c already handles varargs properly and disables the @NN mangling for them. They only case when it doesn't work is this declaration:

  int foo(...)

i.e. a function with only variable arguments. According to the C standard, this is not legal (at least one fixed argument must be present since otherwise it's impossible for the function itself to get access to the arguments). However, GCC allows for this notation and only seems to treat this function as not having a prototype (which leads the @0 suffix to be added as if it were a function taking no arguments).

I don't know if the above is fully correct, but anyway I don't feel like I want (or we need) to alter this behavior.

Therefore, this ticket must be considered as resolved as everything mentioned in the description works now.


2011-11-29 09:13

reporter   ~0002059

BTW, I've fixed the optlink calling convention here

I didn't do full testing (the convention seems to be very complex to test it w/o a comprehensive test case) so probably some weird cases (like integer arguments alternating the aggregate ones) will not work correctly. But I checked simple test cases (the ones turned out to be present in wgss and odin) and they do work.


2011-11-29 20:11

reporter   ~0002060

JFTR, this also fixed regparm(N) cconv which was broken by the merge of the old EMX code too.


2011-12-04 08:09

administrator   ~0002062

Fixed by Dmik

Issue History

Date Modified Username Field Change
2011-10-28 22:33 dmik New Issue
2011-10-29 08:46 psmedley Note Added: 0002024
2011-10-29 19:18 psmedley Note Added: 0002025
2011-10-29 19:31 psmedley Note Added: 0002026
2011-10-29 21:25 dmik Note Added: 0002027
2011-10-30 01:27 dmik Note Added: 0002029
2011-10-30 11:02 psmedley Note Added: 0002030
2011-11-04 03:44 dmik Note Added: 0002033
2011-11-04 04:04 dmik Note Added: 0002034
2011-11-04 04:39 dmik Note Added: 0002035
2011-11-05 11:02 psmedley Note Added: 0002036
2011-11-23 04:14 dmik Note Added: 0002053
2011-11-23 04:46 dmik Note Added: 0002054
2011-11-23 06:27 psmedley Note Added: 0002055
2011-11-23 06:34 psmedley Note Added: 0002056
2011-11-24 04:38 dmik Note Added: 0002057
2011-11-24 22:11 dmik Note Added: 0002058
2011-11-29 09:13 dmik Note Added: 0002059
2011-11-29 20:11 dmik Note Added: 0002060
2011-12-04 08:09 psmedley Note Added: 0002062
2011-12-04 08:09 psmedley Status new => resolved
2011-12-04 08:09 psmedley Resolution open => fixed
2011-12-04 08:09 psmedley Assigned To => psmedley