Issue 161676
Summary [LLDB][Windows] Handle C calling convention mangling
Labels lldb, platform:windows
Assignees
Reporter Nerixyz
    On Windows, C functions can be mangled/decorated based on the calling convention. See [Microsoft docs](https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names#FormatC). A complication is that this is dependent on the environment (32 vs. 64 bit). Take the following example:

```cpp
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 (32 bit) | Mangled Name (64 bit) |
|---|---|---|
| `FuncCCall` | `_FuncCCall` | `FuncCCall` |
| `FuncStdCall` | `_FuncStdCall@0` | `FuncStdCall` |
| `FuncFastCall` | `@FuncFastCall@0` | `FuncFastCall` |
| `FuncVectorCall` | `FuncVectorCall@@0` | `FuncVectorCall@@0` |

Additionally, `FuncCCall` shows up as `FuncCCall` on 32 bit 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 https://github.com/llvm/llvm-project/pull/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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to