From 4f8d309118579ebb5d81f32dda102987799c3cf9 Mon Sep 17 00:00:00 2001 From: Matt Taylor Date: Wed, 3 Aug 2022 21:58:40 +0100 Subject: [PATCH] internal: use libsmarter --- meson.build | 13 +++++++++++-- options/internal/gcc-extra/cxxabi.cpp | 26 ++++++++++++++------------ subprojects/libsmarter.wrap | 4 ++++ 3 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 subprojects/libsmarter.wrap diff --git a/meson.build b/meson.build index 736db362c3..777f995881 100644 --- a/meson.build +++ b/meson.build @@ -53,11 +53,19 @@ if not headers_only libc_deps += frigg_dep rtdl_deps += frigg_dep + libsmarter_dep = dependency( + 'libsmarter', + default_options: [], + fallback: ['libsmarter', 'libsmarter_dep'], + ) + libc_deps += libsmarter_dep + rtdl_deps += libsmarter_dep + add_languages('c', 'cpp') c_compiler = meson.get_compiler('c') - add_project_arguments('-Wno-unused-function', '-D__MLIBC_BUILDING_MLIBC', language: ['c', 'cpp']) - add_project_arguments('-nostdinc', '-fno-builtin', language: ['c', 'cpp']) + add_project_arguments('-D__MLIBC_BUILDING_MLIBC', '-DLIBSMARTER_FORCE_FREESTANDING', language: ['c', 'cpp']) + add_project_arguments('-nostdinc', '-fno-builtin', '-Wno-unused-function', language: ['c', 'cpp']) add_project_arguments('-fno-rtti', '-fno-exceptions', language: 'cpp') add_project_link_arguments('-nostdlib', language: ['c', 'cpp']) @@ -259,6 +267,7 @@ endif rtdl_sources += [ 'options/internal/gcc/stack_protector.cpp', 'options/internal/gcc/guard-abi.cpp', + 'options/internal/gcc-extra/cxxabi.cpp', 'options/internal/generic/allocator.cpp', 'options/internal/generic/debug.cpp', 'options/internal/generic/ensure.cpp', diff --git a/options/internal/gcc-extra/cxxabi.cpp b/options/internal/gcc-extra/cxxabi.cpp index aa222a8353..a0582e5f2b 100644 --- a/options/internal/gcc-extra/cxxabi.cpp +++ b/options/internal/gcc-extra/cxxabi.cpp @@ -1,16 +1,18 @@ - -#include +#include // The cxxabi needs operator delete for *deleting* destructors, i.e., destructors that // are called by delete expressions. We never use such expressions in mlibc. // Note that G++ complains if we make the operator hidden, -// thus we use it's mangled name as a workaround. -#if defined(__clang__) - extern "C" [[gnu::visibility("hidden")]] void _ZdlPv() { // operator delete (void *, size_t) - __ensure(!"operator delete called! delete expressions cannot be used in mlibc."); - } -#else - extern "C" [[gnu::visibility("hidden")]] void _ZdlPvm() { // operator delete (void *, size_t) - __ensure(!"operator delete called! delete expressions cannot be used in mlibc."); - } -#endif \ No newline at end of file +// thus we use its mangled name as a workaround. + +extern "C" [[gnu::visibility("hidden")]] void *_Znwm(size_t size) { // operator new (size_t) + return getAllocator().allocate(size); +} + +extern "C" [[gnu::visibility("hidden")]] void _ZdlPv(void *ptr) { // operator delete (void *) + getAllocator().free(ptr); +} + +extern "C" [[gnu::visibility("hidden")]] void _ZdlPvm(void *ptr, size_t size) { // operator delete (void *, size_t) + getAllocator().deallocate(ptr, size); +} diff --git a/subprojects/libsmarter.wrap b/subprojects/libsmarter.wrap new file mode 100644 index 0000000000..ad7bc24c19 --- /dev/null +++ b/subprojects/libsmarter.wrap @@ -0,0 +1,4 @@ +[wrap-git] +directory = libsmarter +url = https://github.com/managarm/libsmarter.git +revision = master