Mangling & Demangling: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Jhmaster2000 (talk | contribs) (made page) |
Jhmaster2000 (talk | contribs) (add _Complex (x) type modifier) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
For an explanation of what mangling and demangling are, refer to the [https://en.wikipedia.org/wiki/Name_mangling#C++ C++ section of the Wikipedia article on mangling]. |
For an explanation of what mangling and demangling are, refer to the [https://en.wikipedia.org/wiki/Name_mangling#C++ C++ section of the Wikipedia article on mangling]. |
||
Note that in the above linked article, most of the practical examples use the '''MSVC''' mangling scheme, which is not at all similar to the '''GHS''' ( |
Note that in the above linked article, most of the practical examples use the '''MSVC''' <small>(the Windows C++ compiler)</small> mangling scheme, which is not at all similar to the '''GHS''' <small>(the Wii U C++ compiler)</small> mangling scheme. |
||
For reference, in [https://en.wikipedia.org/wiki/Name_mangling#How_different_compilers_mangle_the_same_functions this table] on the same article, the closest matching one to '''GHS''' would be '''GCC 2.9.''x'''''. However they are not entirely equal. |
For reference, in [https://en.wikipedia.org/wiki/Name_mangling#How_different_compilers_mangle_the_same_functions this table] on the same article, the closest matching one to '''GHS''' would be '''GCC 2.9.''x'''''. However they are not entirely equal. |
||
Line 10: | Line 10: | ||
!Token (* = anything) |
!Token (* = anything) |
||
!Meaning |
!Meaning |
||
⚫ | |||
⚫ | |||
|Number representing the next number of "entries" (context dependent) |
|||
|- |
|- |
||
|<code>?</code> |
|<code>?</code> |
||
Line 22: | Line 25: | ||
|<code>{*,}</code> |
|<code>{*,}</code> |
||
|Required (at least 1) sequence of comma-separated variables |
|Required (at least 1) sequence of comma-separated variables |
||
⚫ | |||
⚫ | |||
|Required (at least 1) sequence of <code>::</code>-separated variables |
|||
|- |
|- |
||
|<code>{?:*}</code> |
|<code>{?:*}</code> |
||
Line 30: | Line 36: | ||
!Operator |
!Operator |
||
!Code |
!Code |
||
| rowspan=" |
| rowspan="26" | |
||
!Operator |
!Operator |
||
!Code |
!Code |
||
Line 89: | Line 95: | ||
|<code>eq</code> |
|<code>eq</code> |
||
|- |
|- |
||
|<code> |
|<code>[]</code> |
||
|<code> |
|<code>vc</code> |
||
|<code>!=</code> |
|<code>!=</code> |
||
|<code>ne</code> |
|<code>ne</code> |
||
Line 129: | Line 135: | ||
|<code>ls</code> |
|<code>ls</code> |
||
|- |
|- |
||
|<code> |
|<code>>?</code> |
||
|<code> |
|<code>mx</code> |
||
|<code>>>=</code> |
|<code>>>=</code> |
||
|<code>ars</code> |
|<code>ars</code> |
||
|- |
|- |
||
|<code><?</code> |
|||
⚫ | |||
|<code>mn</code> |
|||
⚫ | |||
|<code><<=</code> |
|<code><<=</code> |
||
|<code>als</code> |
|<code>als</code> |
||
|- |
|||
|<code>-></code> |
|||
|<code>rf</code> |
|||
|<code>->*</code> |
|||
|<code>rm</code> |
|||
|- |
|||
|<code>?</code> |
|||
|<code>qs</code> |
|||
|<code>__uuidof(</code> |
|||
|<code>uu</code> |
|||
|- |
|- |
||
|<code>cast</code> |
|<code>cast</code> |
||
|<code>cs</code> |
|<code>cs</code> |
||
|<code>__alignof__(</code> |
|||
|<code>af</code> |
|||
|- |
|||
|<code>sizeof(</code> |
|<code>sizeof(</code> |
||
|<code>sz</code> |
|<code>sz</code> |
||
⚫ | |||
|<code>builtin-operation</code> |
|<code>builtin-operation</code> |
||
|<code>bi</code> |
|<code>bi</code> |
||
|- |
|||
⚫ | |||
! colspan="5" |Generic Type Operator |
|||
⚫ | |||
|- |
|||
| colspan="2" |* = '''Any''' mangled type |
|||
ex: <code>opPv</code> -> <code>void*</code> |
|||
⚫ | |||
! colspan="2" |<code>op*</code> |
|||
|} |
|} |
||
{| class="wikitable mw-collapsible mw-collapsed" |
{| class="wikitable mw-collapsible mw-collapsed" |
||
Line 203: | Line 226: | ||
!Mangled Modifier |
!Mangled Modifier |
||
!Demangled Modifier (T = type the modifier is applied to) |
!Demangled Modifier (T = type the modifier is applied to) |
||
!Conditions |
|||
|- |
|- |
||
|<code>C</code> |
|<code>C</code> |
||
|<code>const T</code> |
|<code>const T</code> |
||
|Reusable, any number of times |
|||
|- |
|- |
||
|<code>P</code> |
|<code>P</code> |
||
|<code>T*</code> (pointer to type) |
|<code>T*</code> (pointer to type) |
||
|Reusable, any number of times |
|||
|- |
|- |
||
|<code>R</code> |
|<code>R</code> |
||
|<code>T&</code> (reference to type) |
|<code>T&</code> (reference to type) |
||
|Reusable, any number of times |
|||
|- |
|- |
||
|<code> |
|<code>V</code> |
||
|<code> |
|<code>volatile T</code> |
||
|Reusable, any number of times |
|||
|- |
|- |
||
|<code>U</code> |
|<code>U</code> |
||
|<code>unsigned T</code> |
|<code>unsigned T</code> |
||
|Must be the last modifier in a sequence. Mutually exclusive with <code>S</code> and <code>x</code> |
|||
|- |
|- |
||
|<code> |
|<code>S</code> |
||
|<code> |
|<code>signed T</code> |
||
|Must be the last modifier in a sequence. Mutually exclusive with <code>U</code> and <code>x</code> |
|||
|- |
|||
|<code>x</code> |
|||
|<code>_Complex T</code> |
|||
|Must be the last modifier in a sequence. Mutually exclusive with <code>S</code> and <code>U</code> |
|||
|} |
|} |
||
{| class="wikitable mw-collapsible mw-collapsed" |
{| class="wikitable mw-collapsible mw-collapsed" |
||
|+Function Modifiers (placed before the F token which starts the args list) |
|+Namespace/Class Function Modifiers (placed before the F token which starts the args list) |
||
!Mangled Modifier |
!Mangled Modifier |
||
!Demangled Modifier (T = the function the modifier is applied to) |
!Demangled Modifier (T = the function the modifier is applied to) |
||
Line 242: | Line 276: | ||
|<code>S</code> |
|<code>S</code> |
||
|<code>T()</code> |
|<code>T()</code> |
||
|<code>static</code> modifier, for some reason isn't shown by the demangler |
|<code>static</code> modifier, for some reason isn't shown by the demangler. Must be the first modifier in a sequence |
||
|- |
|- |
||
|<code>V</code> |
|<code>V</code> |
||
Line 280: | Line 314: | ||
|<code><nowiki>{funcName}__tm__?{_{templateTypes+}}__F{argTypes+}{_<returnType>}</nowiki></code> |
|<code><nowiki>{funcName}__tm__?{_{templateTypes+}}__F{argTypes+}{_<returnType>}</nowiki></code> |
||
|<code>{returnType} {funcName}<{templateTypes,}>({?:argTypes,})</code> |
|<code>{returnType} {funcName}<{templateTypes,}>({?:argTypes,})</code> |
||
|<code> |
|<code>foo__tm__3_bv__Fci_b</code> |
||
|<code>bool foo<T1, T2>(char, int) [with T1= |
|<code>bool foo<T1, T2>(char, int) [with T1=bool, T2=void]</code> |
||
|- |
|||
|Namespace |
|||
Function |
|||
|<code><nowiki>{funcName}__Q#_{NS+}{?:funcModifs}F{argTypes+}{?:_{returnType}}</nowiki></code> |
|||
|<code>{returnType} {NS::}::{funcName}({?:argTypes,})</code> |
|||
|<code>foo__Q1_3stdFci_b</code> |
|||
|<code>bool std::foo(char, int)</code> |
|||
|- |
|||
|Class |
|||
Function |
|||
|<code><nowiki>{funcName}__?{className}{?:funcModifs}F{argTypes+}{?:_{returnType}}</nowiki></code> |
|||
|<code>{returnType} {className}::{funcName}({?:argTypes,})</code> |
|||
|<code>bar__3FooFci_b</code> |
|||
|<code>bool Foo::bar(char, int)</code> |
|||
|- |
|- |
||
|Constructor |
|Constructor |
||
Line 294: | Line 342: | ||
|<code>__dt__3FooFci</code> |
|<code>__dt__3FooFci</code> |
||
|<code>Foo::~Foo(char, int)</code> |
|<code>Foo::~Foo(char, int)</code> |
||
|- |
|||
|Virtual Table |
|||
|<code>__vtbl__?{className}</code> |
|||
|<code>class {className} ...</code> <small>(Any Class Declaration)</small> |
|||
|<code>__vtbl__3Foo</code> |
|||
|<code>virtual function table for Foo</code> |
|||
|- |
|- |
||
|Static |
|Static |
||
Line 304: | Line 358: | ||
|Operator |
|Operator |
||
|<code><nowiki>__{operatorCode}__F{argTypes+}{?:_{returnType}}</nowiki></code> |
|<code><nowiki>__{operatorCode}__F{argTypes+}{?:_{returnType}}</nowiki></code> |
||
|<code>{returnType} operator |
|<code>{returnType} operator{operator}({?:argTypes,})</code> |
||
|<code>__nw__Fci_b</code> |
|<code>__nw__Fci_b</code> |
||
|<code>bool operator new(char, int)</code> |
|<code>bool operator new(char, int)</code> |
||
|} |
|} |
||
{{#css: |
|||
.wikitable > caption { |
|||
min-width: 700px; |
|||
} |
|||
}} |
|||
[[Category:Documentation]] |
[[Category:Documentation]] |
Latest revision as of 01:14, 10 May 2023
For an explanation of what mangling and demangling are, refer to the C++ section of the Wikipedia article on mangling.
Note that in the above linked article, most of the practical examples use the MSVC (the Windows C++ compiler) mangling scheme, which is not at all similar to the GHS (the Wii U C++ compiler) mangling scheme.
For reference, in this table on the same article, the closest matching one to GHS would be GCC 2.9.x. However they are not entirely equal.
For that reason, the goal of this page is to document the specific GHS mangling scheme and how to reverse (demangle) it.
Token (* = anything) | Meaning |
---|---|
#
|
Number representing the next number of "entries" (context dependent) |
?
|
Number representing the length of the next token |
{*}
|
Required placeholder string variable |
{*+}
|
Required (at least 1) sequence of variables |
{*,}
|
Required (at least 1) sequence of comma-separated variables |
{*::}
|
Required (at least 1) sequence of :: -separated variables
|
{?:*}
|
Optional segment |
Operator | Code | Operator | Code | |
---|---|---|---|---|
new
|
nw
|
new[]
|
nwa
| |
delete
|
dl
|
delete[]
|
dla
| |
++
|
pp
|
()
|
cl
| |
--
|
mm
|
,
|
cm
| |
+
|
pl
|
+=
|
apl
| |
-
|
mi
|
-=
|
ami
| |
*
|
ml
|
*=
|
amu
| |
/
|
dv
|
/=
|
adv
| |
&
|
ad
|
&&
|
aa
| |
|
|
or
|
||
|
oo
| |
=
|
as
|
==
|
eq
| |
[]
|
vc
|
!=
|
ne
| |
~
|
co
|
!
|
nt
| |
^
|
er
|
%
|
md
| |
^=
|
aer
|
%=
|
amd
| |
>=
|
ge
|
<=
|
le
| |
>
|
gt
|
<
|
lt
| |
&=
|
aad
|
>>
|
rs
| |
|=
|
aor
|
<<
|
ls
| |
>?
|
mx
|
>>=
|
ars
| |
<?
|
mn
|
<<=
|
als
| |
->
|
rf
|
->*
|
rm
| |
?
|
qs
|
__uuidof(
|
uu
| |
cast
|
cs
|
__alignof__(
|
af
| |
sizeof(
|
sz
|
builtin-operation
|
bi
| |
Generic Type Operator | ||||
* = Any mangled type
ex: |
op*
|
Mangled Type | Demangled Type | Valid Modifiers |
---|---|---|
b
|
bool
|
C V P R
|
c
|
char
|
C V P R S U
|
d
|
double
|
C V P R
|
f
|
float
|
C V P R
|
i
|
int
|
C V P R S U
|
l
|
long
|
C V P R S U
|
L
|
long long
|
C V P R S U
|
r
|
long double
|
C V P R
|
s
|
short
|
C V P R S U
|
v
|
void
|
C V P
|
w
|
wchar_t
|
C V P R
|
Mangled Modifier | Demangled Modifier (T = type the modifier is applied to) | Conditions |
---|---|---|
C
|
const T
|
Reusable, any number of times |
P
|
T* (pointer to type)
|
Reusable, any number of times |
R
|
T& (reference to type)
|
Reusable, any number of times |
V
|
volatile T
|
Reusable, any number of times |
U
|
unsigned T
|
Must be the last modifier in a sequence. Mutually exclusive with S and x
|
S
|
signed T
|
Must be the last modifier in a sequence. Mutually exclusive with U and x
|
x
|
_Complex T
|
Must be the last modifier in a sequence. Mutually exclusive with S and U
|
Mangled Modifier | Demangled Modifier (T = the function the modifier is applied to) | Description |
---|---|---|
C
|
T() const
|
const function
|
P
|
(*T)()
|
Function pointer (funcptr) |
R
|
(&T)()
|
Function reference (funcref) |
S
|
T()
|
static modifier, for some reason isn't shown by the demangler. Must be the first modifier in a sequence
|
V
|
T() volatile
|
volatile function
|
Mangled Modifier (# = digit, ? = number) | Description |
---|---|
J##J
|
Unknown |
Z?Z
|
Copy #-th template parameter in function arguments |
N##
|
Repeat (2nd #)-th function argument (1st #) times |
Item Type | Mangled Format | Source C++ Signature Format (Pre-mangle) | Mangled Example | Demangled Example |
---|---|---|---|---|
Basic
Function |
{funcName}__F{argTypes+}{?:_{returnType}}
|
{returnType} {funcName}({?:argTypes,})
|
foo__Fci_b
|
bool foo(char, int)
|
Templated
Function |
{funcName}__tm__?{_{templateTypes+}}__F{argTypes+}{_<returnType>}
|
{returnType} {funcName}<{templateTypes,}>({?:argTypes,})
|
foo__tm__3_bv__Fci_b
|
bool foo<T1, T2>(char, int) [with T1=bool, T2=void]
|
Namespace
Function |
{funcName}__Q#_{NS+}{?:funcModifs}F{argTypes+}{?:_{returnType}}
|
{returnType} {NS::}::{funcName}({?:argTypes,})
|
foo__Q1_3stdFci_b
|
bool std::foo(char, int)
|
Class
Function |
{funcName}__?{className}{?:funcModifs}F{argTypes+}{?:_{returnType}}
|
{returnType} {className}::{funcName}({?:argTypes,})
|
bar__3FooFci_b
|
bool Foo::bar(char, int)
|
Constructor | __ct__?{className}F{argTypes+}
|
{className}::{className}({?:argTypes,})
|
__ct__3FooFci
|
Foo::Foo(char, int)
|
Destructor | __dt__?{className}F{argTypes+}
|
{className}::~{className}({?:argTypes,})
|
__dt__3FooFci
|
Foo::~Foo(char, int)
|
Virtual Table | __vtbl__?{className}
|
class {className} ... (Any Class Declaration)
|
__vtbl__3Foo
|
virtual function table for Foo
|
Static
Member |
{memberName}__?{className}
|
{className}::{memberName}
|
bar__3Foo
|
Foo::bar
|
Operator | __{operatorCode}__F{argTypes+}{?:_{returnType}}
|
{returnType} operator{operator}({?:argTypes,})
|
__nw__Fci_b
|
bool operator new(char, int)
|