Skip to content

Instantly share code, notes, and snippets.

@Simon-L
Created June 9, 2022 00:24
Show Gist options
  • Select an option

  • Save Simon-L/319200437ebb5402bb43f76e39169a9a to your computer and use it in GitHub Desktop.

Select an option

Save Simon-L/319200437ebb5402bb43f76e39169a9a to your computer and use it in GitHub Desktop.
__cxa_pure_virtual

Compile: g++ -std=c++11 -fPIC -fno-gnu-unique -MMD -MP -g -O3 -march=nehalem -funsafe-math-optimizations -fno-omit-frame-pointer -o purevirtual main.cpp -static-libstdc++ -static-libgcc
Try it on your x64 host? Segfault!
Remove the static linking? It catches pure virtual call!

Useful read? https://stackoverflow.com/a/14082540

Result on arm64:

box64 ./purevirtual
Dynarec for ARM64, with extension: ASIMD AES CRC32 PMULL PageSize:4096
Box64 with Dynarec v0.1.9 1057b88 built on Jun  8 2022 02:27:46
Using default BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/
Using default BOX64_PATH: ./:bin/
Counted 36 Env var
Looking for ./purevirtual
Using native(wrapped) libc.so.6
Using native(wrapped) ld-linux-x86-64.so.2
Using native(wrapped) libpthread.so.0
Using native(wrapped) librt.so.1
Error: PltResolver: Symbol __cxa_pure_virtual(ver 1: __cxa_pure_virtual) not found, cannot apply R_X86_64_JUMP_SLOT 0xffffa5234018 (0xffffa5231036) in /home/xox/purevirtual
// g++ -std=c++11 -fPIC -fno-gnu-unique -MMD -MP -g -O3 -march=nehalem -funsafe-math-optimizations -fno-omit-frame-pointer -o purevirtual main.cpp -static-libstdc++ -static-libgcc
// https://stackoverflow.com/a/99575
class Base
{
public:
Base() { reallyDoIt(); }
void reallyDoIt() { doIt(); } // DON'T DO THIS
virtual void doIt() = 0;
};
class Derived : public Base
{
void doIt() {}
};
int main(void)
{
Derived d; // This will cause "pure virtual function call" error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment