From: Justin Stitt <justinstitt@google.com>
To: Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>
Cc: linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
Kees Cook <keescook@chromium.org>,
Justin Stitt <justinstitt@google.com>
Subject: [PATCH RFC] init: fix -Wmissing-variable-declarations warning
Date: Tue, 29 Aug 2023 23:38:31 +0000 [thread overview]
Message-ID: <20230829-missingvardecl-init-main-c-v1-1-ddf0f1a71215@google.com> (raw)
Hi all,
I was looking to get some help on solving this -Wmissing-variable-declarations
warning as there is some hope to turn it on for W=1 soon [1].
When building x86/defconfig with Clang-18 I encounter the following warning:
| init/main.c:189:13: warning: no previous extern declaration for non-static variable 'envp_init' [-Wmissing-variable-declarations]
| 189 | const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
| | ^
| init/main.c:189:7: note: declare 'static' if the variable is not intended to be used outside of this translation unit
| 189 | const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
| | ^
It seems like the obvious solution is to just add the `static` keyword
and be done with it. I suspect, however, that it is not so simple for
the following reasons:
Firstly, `envp_init` is surrounded by two other variables that have been
explicitly marked as `static` which leads me to believe that this one
was intentionally _not_ marked as static for some reason:
| static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
| static const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
| static const char *panic_later, *panic_param;
Secondly, there exists this `extern` declaration for `envp_init`:
| init/do_mounts_initrd.c
| 90: extern char *envp_init[];
This one is tricky because it seems like I can rename (effectively
remove) this extern symbol entirely and still build a kernel image.
If it truly is the case that this extern declaration works then why does
Clang produce the warning at all?
FWIW, I've tried moving `extern char *envp_init[];` to top-level scope
inside of `do_mounts_initrd.c` which did _not_ work in fixing the
warning.
So all in all, it looks like just adding `static` fixes the warning
(which it does) but I am not sure about the other ramifications of this
patch especially considering the second point I brought up above
regarding the extern declaration already existing (but seemingly not
doing anything).
Any help here would be appreciated!
Link: https://github.com/ClangBuiltLinux/linux/issues/1920 [1]
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
init/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/init/main.c b/init/main.c
index ad920fac325c..9a473107bb8f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -186,7 +186,7 @@ static int __init set_reset_devices(char *str)
__setup("reset_devices", set_reset_devices);
static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
-const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
+static const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
static const char *panic_later, *panic_param;
static bool __init obsolete_checksetup(char *line)
---
base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230829-missingvardecl-init-main-c-1af2e128419e
Best regards,
--
Justin Stitt <justinstitt@google.com>
next reply other threads:[~2023-08-29 23:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 23:38 Justin Stitt [this message]
2023-08-31 21:19 ` [PATCH RFC] init: fix -Wmissing-variable-declarations warning Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230829-missingvardecl-init-main-c-v1-1-ddf0f1a71215@google.com \
--to=justinstitt@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=trix@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox