SPRUI04F july 2015 – april 2023
The examples in this section illustrate the demangling process.
This example shows a sample C++ program. In this example, the linknames of all the functions are mangled; that is, their signature information is encoded into their names.
class banana {
public:
int calories(void);
banana();
~banana();
};
int calories_in_a_banana(void)
{
banana x;
return x.calories();
}
The resulting assembly that is output by the compiler is as follows.
_calories_in_a_banana__Fv:
;** ----------------------------------------------------------------------*
CALL .S1 ___ct__6bananaFv
STW .D2T2 B3,*SP--(16)
MVKL .S2 RL0,B3
MVKH .S2 RL0,B3
ADD .S1X 8,SP,A4
NOP 1
RL0: ; CALL OCCURS
CALL .S1 _calories__6bananaFv
MVKL .S2 RL1,B3
ADD .S1X 8,SP,A4
MVKH .S2 RL1,B3
NOP 2
RL1: ; CALL OCCURS
CALL .S1 ___dt__6bananaFv
STW .D2T1 A4,*+SP(4)
ADD .S1X 8,SP,A4
MVKL .S2 RL2,B3
MVK .S2 0x2,B4
MVKH .S2 RL2,B3
RL2: ; CALL OCCURS
LDW .D2T1 *+SP(4),A4
LDW .D2T2 *++SP(16),B3
NOP 4
RET .S2 B3
NOP 5
; BRANCH OCCURS
Executing the C++ name demangler will demangle all names that it believes to be mangled. Enter:
dem6x calories_in_a_banana.asm
The result after running the C++ name demangler is as follows. The linknames in _ZN6bananaC1Ev, _ZN6banana8caloriesEv, and _ZN6bananaD1Ev are demangled.
calories_in_a_banana():
;** ----------------------------------------------------------------------*
CALL .S1 banana::banana()
STW .D2T2 B3,*SP--(16)
MVKL .S2 RL0,B3
MVKH .S2 RL0,B3
ADD .S1X 8,SP,A4
NOP 1
RL0: ; CALL OCCURS
CALL .S1 banana::calories()
MVKL .S2 RL1,B3
ADD . S1X 8,SP,A4
MVKH .S2 RL1,B3
NOP 2
RL1: ; CALL OCCURS
CALL .S1 banana::~banana()
STW .D2T1 A4,*+SP(4)
ADD .S1X 8,SP,A4
MVKL .S2 RL2,B3
MVK . S2 0x2,B4
MVKH . S2 RL2,B3
RL2: ; CALL OCCURS
LDW .D2T1 *+SP(4),A4
LDW .D2T2 *++SP(16),B3
NOP 4
RET .S2 B3
NOP 5
; BRANCH OCCURS