tools+libluna: Make new and delete weak to avoid conflicts with libstdc++

Wasn't causing problems earlier, but when trying to rebuild the toolchain, it failed because of this.
This commit is contained in:
apio 2024-09-01 12:39:55 +02:00
parent abbfd5825f
commit 0abd9153ae
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 39 additions and 32 deletions

View File

@ -51,6 +51,9 @@ add_library(luna ${SOURCES})
target_compile_options(luna PRIVATE ${COMMON_FLAGS}) target_compile_options(luna PRIVATE ${COMMON_FLAGS})
target_include_directories(luna PUBLIC include/) target_include_directories(luna PUBLIC include/)
target_include_directories(luna PUBLIC ${LUNA_BASE}/usr/include) target_include_directories(luna PUBLIC ${LUNA_BASE}/usr/include)
if(DEFINED LIBC_BOOTSTRAP)
target_compile_definitions(luna PUBLIC LIBC_BOOTSTRAP)
endif()
if("${LUNA_ARCH}" MATCHES "x86_64") if("${LUNA_ARCH}" MATCHES "x86_64")
target_compile_options(luna-freestanding PRIVATE -mno-red-zone) target_compile_options(luna-freestanding PRIVATE -mno-red-zone)

View File

@ -420,35 +420,39 @@ void dump_heap_usage()
dbgln("-- Heap memory in use: %zu bytes", alloc_used); dbgln("-- Heap memory in use: %zu bytes", alloc_used);
} }
// Otherwise, this is defined in libstdc++. #if defined(USE_FREESTANDING) || defined(LIBC_BOOTSTRAP)
#ifdef USE_FREESTANDING #define WEAK
void* operator new(usize size, const std::nothrow_t&) noexcept #else
{ #define WEAK __attribute__((weak))
return malloc_impl(size, false, false).value_or(nullptr);
}
void* operator new[](usize size, const std::nothrow_t&) noexcept
{
return malloc_impl(size, false, false).value_or(nullptr);
}
void operator delete(void* p) noexcept
{
free_impl(p);
}
void operator delete[](void* p) noexcept
{
free_impl(p);
}
void operator delete(void* p, usize) noexcept
{
free_impl(p);
}
void operator delete[](void* p, usize) noexcept
{
free_impl(p);
}
#endif #endif
// If libstdc++ is linked, it should override these definitions.
void* WEAK operator new(usize size, const std::nothrow_t&) noexcept
{
return malloc_impl(size, false, false).value_or(nullptr);
}
void* WEAK operator new[](usize size, const std::nothrow_t&) noexcept
{
return malloc_impl(size, false, false).value_or(nullptr);
}
void WEAK operator delete(void* p) noexcept
{
free_impl(p);
}
void WEAK operator delete[](void* p) noexcept
{
free_impl(p);
}
void WEAK operator delete(void* p, usize) noexcept
{
free_impl(p);
}
void WEAK operator delete[](void* p, usize) noexcept
{
free_impl(p);
}

View File

@ -64,7 +64,7 @@ make install-gcc
make install-target-libgcc make install-target-libgcc
mkdir -p $LUNA_BUILD_DIR mkdir -p $LUNA_BUILD_DIR
cmake -S $LUNA_ROOT -B $LUNA_BUILD_DIR -G "$LUNA_CMAKE_GENERATOR_NAME" cmake -S $LUNA_ROOT -B $LUNA_BUILD_DIR -G "$LUNA_CMAKE_GENERATOR_NAME" -DLIBC_BOOTSTRAP=1
cmake --build $LUNA_BUILD_DIR --target libc cmake --build $LUNA_BUILD_DIR --target libc
make all-target-libstdc++-v3 CXXFLAGS_FOR_TARGET="-fno-exceptions" -j$(nproc) make all-target-libstdc++-v3 CXXFLAGS_FOR_TARGET="-fno-exceptions" -j$(nproc)