From 12dedc7e2e51390fdf2caec3700e75db19be1cd4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 28 Oct 2025 18:31:39 +0100 Subject: kstd: don't rely on newlib --- libs/kstd/CMakeLists.txt | 8 ++++++++ libs/kstd/include/kstd/bits/os.hpp | 2 ++ libs/kstd/src/bits/os.cpp | 10 ++++++++++ libs/kstd/src/cstdlib.cpp | 18 ++++++++++++++++++ libs/kstd/src/cstring.cpp | 10 ++++++++++ 5 files changed, 48 insertions(+) create mode 100644 libs/kstd/src/bits/os.cpp create mode 100644 libs/kstd/src/cstdlib.cpp create mode 100644 libs/kstd/src/cstring.cpp (limited to 'libs') diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index ac9e78f..666a5d7 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -2,6 +2,9 @@ add_library("kstd" STATIC) add_library("libs::kstd" ALIAS "kstd") target_sources("kstd" PRIVATE + "src/bits/os.cpp" + "src/cstdlib.cpp" + "src/cstring.cpp" "src/mutex.cpp" ) @@ -23,3 +26,8 @@ target_sources("kstd" PUBLIC target_include_directories("kstd" PUBLIC "include" ) + +target_link_options("kstd" INTERFACE + "-Wl,--undefined=abort" + "-Wl,--undefined=strlen" +) \ No newline at end of file diff --git a/libs/kstd/include/kstd/bits/os.hpp b/libs/kstd/include/kstd/bits/os.hpp index 0425b88..7f5fcc8 100644 --- a/libs/kstd/include/kstd/bits/os.hpp +++ b/libs/kstd/include/kstd/bits/os.hpp @@ -6,6 +6,8 @@ namespace kstd::os { + auto abort() -> bool; + [[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void; } diff --git a/libs/kstd/src/bits/os.cpp b/libs/kstd/src/bits/os.cpp new file mode 100644 index 0000000..fb64202 --- /dev/null +++ b/libs/kstd/src/bits/os.cpp @@ -0,0 +1,10 @@ +#include "kstd/bits/os.hpp" + +namespace kstd::os +{ + [[gnu::weak]] + auto abort() -> bool + { + return false; + } +} // namespace kstd::os \ No newline at end of file diff --git a/libs/kstd/src/cstdlib.cpp b/libs/kstd/src/cstdlib.cpp new file mode 100644 index 0000000..8fb5f63 --- /dev/null +++ b/libs/kstd/src/cstdlib.cpp @@ -0,0 +1,18 @@ +#include "kstd/bits/os.hpp" + +namespace kstd +{ + + extern "C" + { + [[noreturn]] auto abort() -> void + { + if (!kstd::os::abort()) + { + os::panic("System abort handler returned."); + } + __builtin_trap(); + } + } + +} // namespace kstd \ No newline at end of file diff --git a/libs/kstd/src/cstring.cpp b/libs/kstd/src/cstring.cpp new file mode 100644 index 0000000..5419b7d --- /dev/null +++ b/libs/kstd/src/cstring.cpp @@ -0,0 +1,10 @@ +#include +#include + +extern "C" +{ + auto strlen(const char * string) -> std::size_t + { + return std::distance(string, std::ranges::find(string, nullptr, '\0')); + } +} -- cgit v1.2.3