From 510f295124f7c8e51ec66f59be61a9e9aa8f9d25 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Tue, 21 Apr 2026 23:21:47 +0800 Subject: feat: add minimal C++ ABI stubs for freestanding kernel --- na/lib/cxx_abi.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 na/lib/cxx_abi.cc (limited to 'na/lib/cxx_abi.cc') diff --git a/na/lib/cxx_abi.cc b/na/lib/cxx_abi.cc new file mode 100644 index 0000000..1ad9d4d --- /dev/null +++ b/na/lib/cxx_abi.cc @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (C) 2026 Richard Qin */ + +/* + * cxx_abi.cc — Minimal C++ ABI stubs for freestanding kernel + * + * Provides symbols that the compiler/linker expects from the C++ + * runtime library. All error paths are fatal (kernel_panic). + * + * Reference: docs/specs/cpp_runtime.md + */ + +#include + +/* Pure virtual function call trap. + * Generated by the compiler in vtable entries for pure virtual methods. + * Reaching this means a derived class failed to implement a pure virtual. */ +extern "C" void __cxa_pure_virtual() +{ + kernel_panic("pure virtual function call"); +} + +/* Global destructor registration. + * The kernel does not support global object destruction — all global + * objects use Placement New with explicit lifetime management. + * If the compiler emits a call to this, it indicates a code violation. */ +extern "C" int __cxa_atexit(void (*)(void*), void*, void*) +{ + kernel_panic("__cxa_atexit called in kernel"); + return 0; // unreachable +} + +/* DSO handle — required by __cxa_atexit ABI. + * The kernel is statically linked; this symbol just needs to exist. */ +extern "C" { +void* __dso_handle __attribute__((visibility("hidden"))) = nullptr; +} -- cgit v1.2.3