-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
On Windows, C functions can be mangled/decorated based on the calling convention. See Microsoft docs. A complication is that this is dependent on the environment (x86 vs. amd64 vs. ARM). Take the following example:
extern "C" {
int /* __cdecl (default) */ FuncCCall() { return 0; }
int __stdcall FuncStdCall() { return 0; }
int __fastcall FuncFastCall() { return 0; }
int __vectorcall FuncVectorCall() { return 0; }
}
Function Name | Mangled Name (x86) | Mangled Name (amd64/x86_64) | Mangled Name (ARM) |
---|---|---|---|
FuncCCall |
_FuncCCall |
FuncCCall |
FuncCCall |
FuncStdCall |
_FuncStdCall@0 |
FuncStdCall |
FuncStdCall |
FuncFastCall |
@FuncFastCall@0 |
FuncFastCall |
FuncFastCall |
FuncVectorCall |
FuncVectorCall@@0 |
FuncVectorCall@@0 |
FuncVectorCall |
Additionally, FuncCCall
shows up as FuncCCall
on x86 when using DWARF (instead of _FuncCCall
):
0x0000009c: DW_TAG_subprogram
DW_AT_low_pc (0x00000000)
DW_AT_high_pc (0x00000007)
DW_AT_frame_base (DW_OP_reg5 EBP)
DW_AT_name ("CFuncCCall")
DW_AT_decl_file ("/app/example.cpp")
DW_AT_decl_line (2)
DW_AT_type (0x00000041 "int")
DW_AT_external (true)
From https://godbolt.org/z/TzcqWPd8j (see also discussion in #160930).
On PDB, in the publics stream, however, the "true" mangled name (_FuncCCall
) shows.
As of (PR TBD), the native PDB plugin will strip the leading underscore from the function symbol to match DWARF.
We should still strip these pre-/suffixes somewhere, because currently, functions will show up with the mangled name. Note that the mangling might be nested. For example, on x86, __Z7recursei
is a __cdecl
function (leading underscore) and the rest is a mangled itanium name.