public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes
@ 2025-01-23 20:10 Thomas Weißschuh
  2025-01-23 20:10 ` [PATCH 1/3] tools/nolibc: add prototypes for non-static functions Thomas Weißschuh
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-01-23 20:10 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

Make nolibc compatible with -Wmissing-prototypes

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (3):
      tools/nolibc: add prototypes for non-static functions
      selftests/nolibc: ignore -Wmissing-prototypes
      selftests/nolibc: enable -Wmissing-prototypes

 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 ++++
 tools/testing/selftests/nolibc/Makefile      | 2 +-
 tools/testing/selftests/nolibc/nolibc-test.c | 2 ++
 8 files changed, 14 insertions(+), 1 deletion(-)
---
base-commit: d0d106a2bd21499901299160744e5fe9f4c83ddb
change-id: 20250123-nolibc-prototype-0477bb05c808

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] tools/nolibc: add prototypes for non-static functions
  2025-01-23 20:10 [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Thomas Weißschuh
@ 2025-01-23 20:10 ` Thomas Weißschuh
  2025-01-23 20:10 ` [PATCH 2/3] selftests/nolibc: ignore -Wmissing-prototypes Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-01-23 20:10 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

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 <linux@weissschuh.net>
---
 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)
 {

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] selftests/nolibc: ignore -Wmissing-prototypes
  2025-01-23 20:10 [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Thomas Weißschuh
  2025-01-23 20:10 ` [PATCH 1/3] tools/nolibc: add prototypes for non-static functions Thomas Weißschuh
@ 2025-01-23 20:10 ` Thomas Weißschuh
  2025-01-23 20:10 ` [PATCH 3/3] selftests/nolibc: enable -Wmissing-prototypes Thomas Weißschuh
  2025-01-24  6:49 ` [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Willy Tarreau
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-01-23 20:10 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

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 <linux@weissschuh.net>

---
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 */

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] selftests/nolibc: enable -Wmissing-prototypes
  2025-01-23 20:10 [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Thomas Weißschuh
  2025-01-23 20:10 ` [PATCH 1/3] tools/nolibc: add prototypes for non-static functions Thomas Weißschuh
  2025-01-23 20:10 ` [PATCH 2/3] selftests/nolibc: ignore -Wmissing-prototypes Thomas Weißschuh
@ 2025-01-23 20:10 ` Thomas Weißschuh
  2025-01-24  6:49 ` [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Willy Tarreau
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-01-23 20:10 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

User code may want to use this compiler flag.
Make sure it is supported by nolibc.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 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 :=
 

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes
  2025-01-23 20:10 [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2025-01-23 20:10 ` [PATCH 3/3] selftests/nolibc: enable -Wmissing-prototypes Thomas Weißschuh
@ 2025-01-24  6:49 ` Willy Tarreau
  3 siblings, 0 replies; 5+ messages in thread
From: Willy Tarreau @ 2025-01-24  6:49 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Shuah Khan, linux-kernel, linux-kselftest

On Thu, Jan 23, 2025 at 09:10:41PM +0100, Thomas Weißschuh wrote:
> Make nolibc compatible with -Wmissing-prototypes

Nice, ack for all the series:

  Acked-by: Willy Tarreau <w@1wt.eu>

Thank you Thomas,
Willy

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-24  6:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-23 20:10 [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Thomas Weißschuh
2025-01-23 20:10 ` [PATCH 1/3] tools/nolibc: add prototypes for non-static functions Thomas Weißschuh
2025-01-23 20:10 ` [PATCH 2/3] selftests/nolibc: ignore -Wmissing-prototypes Thomas Weißschuh
2025-01-23 20:10 ` [PATCH 3/3] selftests/nolibc: enable -Wmissing-prototypes Thomas Weißschuh
2025-01-24  6:49 ` [PATCH 0/3] tools/nolibc: compatibility with -Wmissing-prototypes Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox