From patchwork Thu Jan 23 20:10:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13948607 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8207C1ADC77; Thu, 23 Jan 2025 20:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737663092; cv=none; b=Vq4NGvu9nJLSg1BuViL532WyEhh4AwQ519Zn+HdaKIVEmhz0lMi7hS0bngqMn5DtMpQfonbdQA0y9P2gJyRiaNNrpZi17OknZGBHSFu3/74j9NN4tBprg+qt7CwFRzenUyh4DPd1ZEokdCJWMwfmfTatfIUADyPi1g0dEwl/lTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737663092; c=relaxed/simple; bh=tjNoJsUvnxlLj6FzN9eM7bOeqk7TAcjPVmF48ZpBBYw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GpB99vjHKJapioBdRHYfTtSxP2pBwJOT1h4i5QKCqTl6Gu0p0e8ldGwYGGFdBemcHTU2wFFd74BIACKetH0EXlogM4F0P1MSe56YtjFDD3zRVS0uCnsmdnlcEcCVHNudDcCrxBhrfC/nFfMG++ASUORBkBe3Fgdm+Apx3WNxsQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=HsaZvH4A; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="HsaZvH4A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1737663088; bh=tjNoJsUvnxlLj6FzN9eM7bOeqk7TAcjPVmF48ZpBBYw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HsaZvH4A6PQ+rI9W6UaPfGTVDSEKwyINxVLDEmykuzPyIRR9cQg+KG1vhe30+fZRM WOVMeaAqOc44LHPsTsGlJCcpZJk9cHS6jNVKZo3O5uxDNcV2+si3RnpYyRPnHsbwAc V3i+ljUxjH0m7WU7qadfoOE5qNlsM3rHbpcZyZU8= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 23 Jan 2025 21:10:42 +0100 Subject: [PATCH 1/3] tools/nolibc: add prototypes for non-static functions Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250123-nolibc-prototype-v1-1-e1afc5c1999a@weissschuh.net> References: <20250123-nolibc-prototype-v1-0-e1afc5c1999a@weissschuh.net> In-Reply-To: <20250123-nolibc-prototype-v1-0-e1afc5c1999a@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1737663088; l=5271; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=tjNoJsUvnxlLj6FzN9eM7bOeqk7TAcjPVmF48ZpBBYw=; b=Xamj1T9uNAj8hL/LJgpi8tfLZs7sBpq5miSl/LNyuxoyEbWy0Fx7yoqrUy9Ol4LrVqWGCSELS 6JJtQrnAa+oB9y8XId++qrRZGnO0YppvzuLQYNaiaQEJ7Piatcitq/O X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= With -Wmissing-prototypes the compiler will warn about non-static functions which don't have a prototype defined. This warning doesn't make much sense for nolibc itself but for user code it is still useful. To pacify the compiler add prototypes next to the function definitions, similar to how it is handled elsewhere in the kernel. Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/arch-mips.h | 1 + tools/include/nolibc/crt.h | 2 ++ tools/include/nolibc/signal.h | 1 + tools/include/nolibc/stackprotector.h | 2 ++ tools/include/nolibc/stdlib.h | 1 + tools/include/nolibc/string.h | 4 ++++ 6 files changed, 11 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 1791a8ce58da6f72d305498957aaad489d4c143c..753a8ed2cf695f0b5eac4b5e4d317fdb383ebf93 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -179,6 +179,7 @@ }) /* startup code, note that it's called __start on MIPS */ +void __start(void); void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void) { __asm__ volatile ( diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index bbcd5fd09806be67749118cbe1f3ed11adab1c4e..c4b10103bbec50f1a3a0a4562e34fdbd1b43ce6f 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -10,6 +10,7 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); +void _start(void); static void __stack_chk_init(void); static void exit(int); @@ -22,6 +23,7 @@ extern void (*const __init_array_end[])(int, char **, char**) __attribute__((wea extern void (*const __fini_array_start[])(void) __attribute__((weak)); extern void (*const __fini_array_end[])(void) __attribute__((weak)); +void _start_c(long *sp); __attribute__((weak,used)) void _start_c(long *sp) { diff --git a/tools/include/nolibc/signal.h b/tools/include/nolibc/signal.h index 137552216e46960dc8baa1e25759daa1f152c3c9..cdcc5904c51e93c524f9afc7d49a17feda3d9af2 100644 --- a/tools/include/nolibc/signal.h +++ b/tools/include/nolibc/signal.h @@ -13,6 +13,7 @@ #include "sys.h" /* This one is not marked static as it's needed by libgcc for divide by zero */ +int raise(int signal); __attribute__((weak,unused,section(".text.nolibc_raise"))) int raise(int signal) { diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h index 1d0d5259ec417ca7c853aba55519c65aa504b52b..c71a2c257177aac9dbf4541b2e104944efa2182c 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -18,6 +18,7 @@ * triggering stack protector errors themselves */ +void __stack_chk_fail(void); __attribute__((weak,used,noreturn,section(".text.nolibc_stack_chk"))) void __stack_chk_fail(void) { @@ -28,6 +29,7 @@ void __stack_chk_fail(void) for (;;); } +void __stack_chk_fail_local(void); __attribute__((weak,noreturn,section(".text.nolibc_stack_chk"))) void __stack_chk_fail_local(void) { diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 75aa273c23a6153db6a32facaea16457a522703b..86ad378ab1ea220559d5ab1adc4bb9972977ba9e 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -30,6 +30,7 @@ static __attribute__((unused)) char itoa_buffer[21]; */ /* must be exported, as it's used by libgcc for various divide functions */ +void abort(void); __attribute__((weak,unused,noreturn,section(".text.nolibc_abort"))) void abort(void) { diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index 9ec9c24f38c092dee93fab3762c579bffd35ce2f..ba84ab700e3001a7d105e1c9e40c01bf45db9d8c 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -32,6 +32,7 @@ int memcmp(const void *s1, const void *s2, size_t n) /* might be ignored by the compiler without -ffreestanding, then found as * missing. */ +void *memmove(void *dst, const void *src, size_t len); __attribute__((weak,unused,section(".text.nolibc_memmove"))) void *memmove(void *dst, const void *src, size_t len) { @@ -56,6 +57,7 @@ void *memmove(void *dst, const void *src, size_t len) #ifndef NOLIBC_ARCH_HAS_MEMCPY /* must be exported, as it's used by libgcc on ARM */ +void *memcpy(void *dst, const void *src, size_t len); __attribute__((weak,unused,section(".text.nolibc_memcpy"))) void *memcpy(void *dst, const void *src, size_t len) { @@ -73,6 +75,7 @@ void *memcpy(void *dst, const void *src, size_t len) /* might be ignored by the compiler without -ffreestanding, then found as * missing. */ +void *memset(void *dst, int b, size_t len); __attribute__((weak,unused,section(".text.nolibc_memset"))) void *memset(void *dst, int b, size_t len) { @@ -124,6 +127,7 @@ char *strcpy(char *dst, const char *src) * thus itself, hence the asm() statement below that's meant to disable this * confusing practice. */ +size_t strlen(const char *str); __attribute__((weak,unused,section(".text.nolibc_strlen"))) size_t strlen(const char *str) { From patchwork Thu Jan 23 20:10:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13948609 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FFE91ADC85; Thu, 23 Jan 2025 20:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737663093; cv=none; b=gjzqqpqhX2c05YzzlFJYee8xOQ5mRhYgWqGf0VJVw0WGWOu00PvujEkKF71gv422vCQmvR4WY+DC+SGV20lqCgsPXRZrNbc+mI0YNCrA1a0ehgyaObIBegI6tv+M3/UhTlYExQpjDH0J1EOF+l5HO44vonoVGUKmRRPT0mO8mTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737663093; c=relaxed/simple; bh=spnsUo7shJpfgJZ7NTyaOqYn6sFVn0aKxfiAKaNimHY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uXS7dIWKf+uJLfS8I2iLupFElbvAfyWXCHv1l87cKclVg3OuEwcKK1oaN6zStCsG41dfQ6ShcaoLE9hkPc+KOFW2X0GmkPuT1KjjQNr1bGr+BhR5c+Af539fW3ooVl/qIYbuEkAJ1RlRtFbyTJOnBtvEu3qW3tmb0XNh7uf8+EI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=lV1PeQYg; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="lV1PeQYg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1737663088; bh=spnsUo7shJpfgJZ7NTyaOqYn6sFVn0aKxfiAKaNimHY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lV1PeQYgnjec8omHBBQZFquKXLY616XCV20/JLlTwa+9BoF79JLDQSFwKIuhbIZJn +5NO7jNhTJrVJ9u1MDkuJv8wdDJ8dqDZVVGorrOXZC2oWsvpIq+rGRvq5O9grD1uTE p2oxU7bfhqH+2//MoC4mE8myDhIMljXUu9B42FNs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 23 Jan 2025 21:10:43 +0100 Subject: [PATCH 2/3] selftests/nolibc: ignore -Wmissing-prototypes Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250123-nolibc-prototype-v1-2-e1afc5c1999a@weissschuh.net> References: <20250123-nolibc-prototype-v1-0-e1afc5c1999a@weissschuh.net> In-Reply-To: <20250123-nolibc-prototype-v1-0-e1afc5c1999a@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1737663088; l=1256; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=spnsUo7shJpfgJZ7NTyaOqYn6sFVn0aKxfiAKaNimHY=; b=m7EmfQMJA0dxL338zOoCpCg0MlGmKLF98alMNzqsXp542ikV4HdW9mekHmEL4xESIkMNne3kQ kee4QPVKwRYCCgRNzXWBEdKv5SdZzt2j2PAgz5xlPEgvfTwWLZC0/s2 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= To make sure nolibc itself is compatible with -Wmissing-prototypes the compiler flag should be enabled when building nolibc-test. However some of its functions are non-static to ease debugging [0], triggering the compiler warning. Disable the warning inside nolibc-test while still enabling it for nolibc itself. [0] https://lore.kernel.org/lkml/ZMjM0UPRAqoC+goY@1wt.eu/ Signed-off-by: Thomas Weißschuh --- It's a bit iffy, but I only see three possibilities: 1) Make the functions static 2) Use #pragma 3) Add dummy prototypes 1) was NACK-ed before, so I used 2) --- tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 0e0e3b48a8c3a6802c6989954b6f3a7c7258db43..f162793b162f9b1ec687098b9094a6d247a53e99 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -43,6 +43,8 @@ #endif #endif +#pragma GCC diagnostic ignored "-Wmissing-prototypes" + #include "nolibc-test-linkage.h" /* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */ From patchwork Thu Jan 23 20:10:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13948608 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 820281ADC73; Thu, 23 Jan 2025 20:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737663093; cv=none; b=J+IYKV6gFwwITtgU68TK9M/r7nsRjV8ft4tT7+THr4CT6hs+G+fZuIywGC0rdGWJs0QAu1uahSsfLepCcCVEF+eKyvebU3wgbFDmhPPjvSNWhgpz2bOawrNffuebT8XKmI78Suuc7Lg8Bupf6WvnjbiudjPqFe55UE/Ly/u9P9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737663093; c=relaxed/simple; bh=6HSeKK6lLRgo8rYYH3goFTU1KE0Elskz+p5O1c5WWTI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qQhvpwlrq2ltyj0/NwPabcBl7DBtxjoWOOh7rebaAPD1XQZT/yDuf3xyyXdalnSEYA002mPShRoHVMXNX8TwvtdzV1nvrFSP3Cgn0yIhNJNdJvdSRDJUBcqPkURKDVNviDUAGWm1qF7+cMT49HMM2lSI3v70Z7H+fHvtjsT2BUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=nZf77Vtg; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="nZf77Vtg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1737663088; bh=6HSeKK6lLRgo8rYYH3goFTU1KE0Elskz+p5O1c5WWTI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nZf77Vtg94yN7woPJEDxqiNQi4dSBPDfeCmNskJrd5xoy1bUg74ytEOxWHABEoAr0 bjtDWCcuAG86dL2OuqDdfUrhA5cbjRjmaE6ECH5hYicK75pUNGteg8iRBQcF51/YL6 p3pu1MkNYzQ1zrz8ezzRbZ7MSpinYiQxKd0Bz3HY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 23 Jan 2025 21:10:44 +0100 Subject: [PATCH 3/3] selftests/nolibc: enable -Wmissing-prototypes Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250123-nolibc-prototype-v1-3-e1afc5c1999a@weissschuh.net> References: <20250123-nolibc-prototype-v1-0-e1afc5c1999a@weissschuh.net> In-Reply-To: <20250123-nolibc-prototype-v1-0-e1afc5c1999a@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1737663088; l=1054; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=6HSeKK6lLRgo8rYYH3goFTU1KE0Elskz+p5O1c5WWTI=; b=q8ThX0bGeKbhAaPOmGjOOaJ2vhPC4jEhWlUbF+kxDCrVM8ekvccjFWRHoB3DQVKtGJEyL16Wy wbH8FKltF84ApQzjKeDowpleG7kftcl0nHaW/hsWrrIfm4lNdJyM5r3 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= User code may want to use this compiler flag. Make sure it is supported by nolibc. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 7d14a7c0cb62608f328b251495264517d333db2e..f867ebe3474e0e9bfbe4a586bfe9832f51796673 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -164,7 +164,7 @@ CFLAGS_mips32le = -EL -mabi=32 -fPIC CFLAGS_mips32be = -EB -mabi=32 CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \ - $(call cc-option,-fno-stack-protector) \ + $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \ $(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA) LDFLAGS :=