8

I'm new to assembly and I'm trying to figure out how C++ handles dynamic dispatch in assembly.

When looking through assembly code, I saw that there were 2 unusual calls:

call _Znwm
call _ZdlPv

These did not have a subroutine that I could trace them to. From examining the code, Znwm seemed to return the address of the object when its constructor was called, but I'm not sure about that. ZdlPv was in a block of code that could never be reached (it was jumped over). C++:

Fruit * f;
f = new Apple();

x86:

# BB#1:
    mov eax, 8
    mov edi, eax
    call    _Znwm
    mov rdi, rax
    mov rcx, rax
.Ltmp6:
    mov qword ptr [rbp - 48], rdi # 8-byte Spill
    mov rdi, rax
    mov qword ptr [rbp - 56], rcx # 8-byte Spill
    call    _ZN5AppleC2Ev

Any advice would be appreciated. Thanks.

user2999870
  • 345
  • 4
  • 12
  • 2
    `_Znwm` is `operator new`. `_ZdlPv` is `operator delete`. See [online demangler](https://demangler.com/) or `c++filt` for local. – Jester Nov 16 '17 at 19:42
  • 1
    @jester: even short answers are answers. Comments can't be accepted causing the question to stay unanswered. – MSalters Nov 16 '17 at 21:40

1 Answers1

17

_Znwm is operator new.
_ZdlPv is operator delete.

Manu Evans
  • 1,088
  • 2
  • 9
  • 25