From f7fe63c6b07ccc68ec0366d8509a71db21ded8bc Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Tue, 11 Aug 2020 00:11:52 +0200 Subject: [PATCH] LibC: Mark compilation-unit-only functions as static This enables a nice warning in case a function becomes dead code. For example with the unused function malloc_good_size() :^) I found these places by using -Wmissing-declarations. The Kernel still shows these issues, which I think are false-positives, but don't want to touch: - Libraries/LibC/crt0.cpp:41:5: int _start(int, char**, char**) Not sure how to handle this. - Libraries/LibC/cxxabi.cpp:48:5: int __cxa_atexit(AtExitFunction, void*, void*) - Libraries/LibC/cxxabi.cpp:58:6: void __cxa_finalize(void*) Not sure how to tell the compiler that the compiler is already using them. - Libraries/LibC/libcinit.cpp:36:6: void __libc_init() - Libraries/LibC/libcinit.cpp:55:19: void __stack_chk_fail() - Libraries/LibC/malloc.cpp:430:6: void __malloc_init() - Libraries/LibC/stdio.cpp:562:6: void __stdio_init() These are ninja-imported by other LibC functions. Maybe we should have some kind of "internals.h" header. --- Libraries/LibC/malloc.cpp | 9 --------- Libraries/LibC/scanf.cpp | 4 ++-- Libraries/LibC/termcap.cpp | 4 ++-- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp index 8d126b5b81..6971ead3ff 100644 --- a/Libraries/LibC/malloc.cpp +++ b/Libraries/LibC/malloc.cpp @@ -182,15 +182,6 @@ static BigAllocator* big_allocator_for_size(size_t size) extern "C" { -size_t malloc_good_size(size_t size) -{ - for (size_t i = 0; size_classes[i]; ++i) { - if (size < size_classes[i]) - return size_classes[i]; - } - return PAGE_ROUND_UP(size); -} - static void* os_alloc(size_t size, const char* name) { auto* ptr = serenity_mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_PURGEABLE, 0, 0, block_size, name); diff --git a/Libraries/LibC/scanf.cpp b/Libraries/LibC/scanf.cpp index 3f2cf97b7a..83a202f04a 100644 --- a/Libraries/LibC/scanf.cpp +++ b/Libraries/LibC/scanf.cpp @@ -61,7 +61,7 @@ static const char* determine_base(const char* p, int& base) static int _atob(unsigned long* vp, const char* p, int base) { unsigned long value, v1, v2; - const char *q; + const char* q; char tmp[20]; int digit; @@ -106,7 +106,7 @@ static int _atob(unsigned long* vp, const char* p, int base) return 1; } -int atob(unsigned int* vp, const char* p, int base) +static int atob(unsigned int* vp, const char* p, int base) { unsigned long v; diff --git a/Libraries/LibC/termcap.cpp b/Libraries/LibC/termcap.cpp index 94e6ddac1f..9e2b0047c6 100644 --- a/Libraries/LibC/termcap.cpp +++ b/Libraries/LibC/termcap.cpp @@ -24,8 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include #include #include @@ -54,7 +54,7 @@ int tgetent(char* bp, const char* name) static HashMap* caps = nullptr; -void ensure_caps() +static void ensure_caps() { if (caps) return;