Undefined reference to operator delete

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
8infy
Member
Member
Posts: 185
Joined: Sun Apr 05, 2020 1:01 pm

Undefined reference to operator delete

Post by 8infy »

I made a simple logger for my OS to make the debugging process easier. (I'm at a stage where I don't even have the IDT set up for all IRQs and exceptions, let alone new and delete)

Whenever I try to add a virtual destructor it results in an undefined reference to operator delete.
I can obviously add a stub, but why does it even need operator delete here? What is it trying to delete?
It compiles and links successfully when I remove the virtual destructor (which is also fine I guess).

https://prnt.sc/sj41qh
Image

https://prnt.sc/sj4165
Image

EDIT: I added a stub and it's not actually getting called ever, im confused :?
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: Undefined reference to operator delete

Post by Octocontrabass »

This link may help.

In short, the ABI requires the compiler to generate that function call for all virtual destructors, but it will only be called if you use new/delete to create/destroy an object of that class. Since you're not going to do that, it should never be called.

Since it should never be called, your stub operator delete can call your kernel's panic handler to halt and inform you that something bad happened.
8infy
Member
Member
Posts: 185
Joined: Sun Apr 05, 2020 1:01 pm

Re: Undefined reference to operator delete

Post by 8infy »

Octocontrabass wrote:This link may help.

In short, the ABI requires the compiler to generate that function call for all virtual destructors, but it will only be called if you use new/delete to create/destroy an object of that class. Since you're not going to do that, it should never be called.

Since it should never be called, your stub operator delete can call your kernel's panic handler to halt and inform you that something bad happened.
Oh, great! :) thanks!
Post Reply