[PATCH 15/17] arch: fix asm-offsets.c building with -Wmissing-prototypes

From: Arnd Bergmann
Date: Thu Aug 10 2023 - 10:23:58 EST


From: Arnd Bergmann <arnd@xxxxxxxx>

When -Wmissing-prototypes is enabled, the some asm-offsets.c files fail
to build, even when this warning is disabled in the Makefile for normal
files:

arch/sparc/kernel/asm-offsets.c:22:5: error: no previous prototype for 'sparc32_foo' [-Werror=missing-prototypes]
arch/sparc/kernel/asm-offsets.c:48:5: error: no previous prototype for 'foo' [-Werror=missing-prototypes]

Address this by making use of the same trick we have on other architectures,
renaming the unused global function to main(), which has an implicit
prototype.

On loongarch, there are many functions in this file, so the trick does
not work, adding explicit declarations works around it in a slightly
more ugly way but is the best I could come up with here.

Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
arch/alpha/kernel/asm-offsets.c | 2 +-
arch/ia64/kernel/asm-offsets.c | 2 +-
arch/loongarch/kernel/asm-offsets.c | 12 ++++++++++++
arch/sparc/kernel/asm-offsets.c | 13 ++-----------
4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/arch/alpha/kernel/asm-offsets.c b/arch/alpha/kernel/asm-offsets.c
index b121294bee266..b87487e70488d 100644
--- a/arch/alpha/kernel/asm-offsets.c
+++ b/arch/alpha/kernel/asm-offsets.c
@@ -12,7 +12,7 @@
#include <linux/kbuild.h>
#include <asm/io.h>

-void foo(void)
+int main(void)
{
DEFINE(TI_TASK, offsetof(struct thread_info, task));
DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
diff --git a/arch/ia64/kernel/asm-offsets.c b/arch/ia64/kernel/asm-offsets.c
index be3b90fef2e92..62b9aaf10b3c0 100644
--- a/arch/ia64/kernel/asm-offsets.c
+++ b/arch/ia64/kernel/asm-offsets.c
@@ -20,7 +20,7 @@
#include "../kernel/sigframe.h"
#include "../kernel/fsyscall_gtod_data.h"

-void foo(void)
+int main(void)
{
DEFINE(IA64_TASK_SIZE, sizeof (struct task_struct));
DEFINE(IA64_THREAD_INFO_SIZE, sizeof (struct thread_info));
diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/asm-offsets.c
index 8da0726777edb..735115f8341c9 100644
--- a/arch/loongarch/kernel/asm-offsets.c
+++ b/arch/loongarch/kernel/asm-offsets.c
@@ -14,6 +14,7 @@
#include <asm/processor.h>
#include <asm/ftrace.h>

+void output_ptreg_defines(void);
void output_ptreg_defines(void)
{
COMMENT("LoongArch pt_regs offsets.");
@@ -61,6 +62,7 @@ void output_ptreg_defines(void)
BLANK();
}

+void output_task_defines(void);
void output_task_defines(void)
{
COMMENT("LoongArch task_struct offsets.");
@@ -76,6 +78,7 @@ void output_task_defines(void)
BLANK();
}

+void output_thread_info_defines(void);
void output_thread_info_defines(void)
{
COMMENT("LoongArch thread_info offsets.");
@@ -92,6 +95,7 @@ void output_thread_info_defines(void)
BLANK();
}

+void output_thread_defines(void);
void output_thread_defines(void)
{
COMMENT("LoongArch specific thread_struct offsets.");
@@ -128,6 +132,7 @@ void output_thread_defines(void)
BLANK();
}

+void output_thread_fpu_defines(void);
void output_thread_fpu_defines(void)
{
OFFSET(THREAD_FPR0, loongarch_fpu, fpr[0]);
@@ -169,6 +174,7 @@ void output_thread_fpu_defines(void)
BLANK();
}

+void output_thread_lbt_defines(void);
void output_thread_lbt_defines(void)
{
OFFSET(THREAD_SCR0, loongarch_lbt, scr0);
@@ -179,6 +185,7 @@ void output_thread_lbt_defines(void)
BLANK();
}

+void output_mm_defines(void);
void output_mm_defines(void)
{
COMMENT("Size of struct page");
@@ -211,6 +218,7 @@ void output_mm_defines(void)
BLANK();
}

+void output_sc_defines(void);
void output_sc_defines(void)
{
COMMENT("Linux sigcontext offsets.");
@@ -219,6 +227,7 @@ void output_sc_defines(void)
BLANK();
}

+void output_signal_defines(void);
void output_signal_defines(void)
{
COMMENT("Linux signal numbers.");
@@ -257,6 +266,7 @@ void output_signal_defines(void)
}

#ifdef CONFIG_SMP
+void output_smpboot_defines(void);
void output_smpboot_defines(void)
{
COMMENT("Linux smp cpu boot offsets.");
@@ -267,6 +277,7 @@ void output_smpboot_defines(void)
#endif

#ifdef CONFIG_HIBERNATION
+void output_pbe_defines(void);
void output_pbe_defines(void)
{
COMMENT("Linux struct pbe offsets.");
@@ -279,6 +290,7 @@ void output_pbe_defines(void)
#endif

#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+void output_fgraph_ret_regs_defines(void);
void output_fgraph_ret_regs_defines(void)
{
COMMENT("LoongArch fgraph_ret_regs offsets.");
diff --git a/arch/sparc/kernel/asm-offsets.c b/arch/sparc/kernel/asm-offsets.c
index 5784f2df489a4..4c8c9a6df2aa5 100644
--- a/arch/sparc/kernel/asm-offsets.c
+++ b/arch/sparc/kernel/asm-offsets.c
@@ -18,16 +18,12 @@

#include <asm/hibernate.h>

-#ifdef CONFIG_SPARC32
-int sparc32_foo(void)
+int main(void)
{
+#ifdef CONFIG_SPARC32
DEFINE(AOFF_thread_fork_kpsr,
offsetof(struct thread_struct, fork_kpsr));
- return 0;
-}
#else
-int sparc64_foo(void)
-{
#ifdef CONFIG_HIBERNATION
BLANK();
OFFSET(SC_REG_FP, saved_context, fp);
@@ -41,12 +37,7 @@ int sparc64_foo(void)
OFFSET(SC_REG_G5, saved_context, g5);
OFFSET(SC_REG_G6, saved_context, g6);
#endif
- return 0;
-}
#endif
-
-int foo(void)
-{
BLANK();
DEFINE(AOFF_task_thread, offsetof(struct task_struct, thread));
BLANK();
--
2.39.2