lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGG=3QVh+m00OirP0wLb1VzkO+Z6J4Cur+65x+oi4ZuQ1eHTYg@mail.gmail.com>
Date:   Wed, 30 Aug 2023 13:03:46 -0700
From:   Bill Wendling <morbo@...gle.com>
To:     Justin Stitt <justinstitt@...gle.com>
Cc:     Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Tom Rix <trix@...hat.com>, Jens Axboe <axboe@...nel.dk>,
        Peter Zijlstra <peterz@...radead.org>,
        "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
        linux-kernel@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH] init: fix -Wmissing-variable-declarations clang warning

On Wed, Aug 30, 2023 at 12:47 PM Justin Stitt <justinstitt@...gle.com> wrote:
>
> 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, };
>
> Move the extern declaration to a header file so that the compiler can find it
> when compiling init/main.c.
>
> Add `const` qualifier to extern declaration so that the types match and
> we follow the One-Definition Rule (ODR).
>
I'm not sure the lack of a "const" has anything to do with the ODR.
C's type system isn't nearly as strict as C++'s. :-) That said, adding
"const" is definitely correct.

-bw

> Link: https://github.com/ClangBuiltLinux/linux/issues/1920
> Signed-off-by: Justin Stitt <justinstitt@...gle.com>
> ---
> Note: build-tested only.
>
> There's a previous RFC [1] wherein the kernel test robot reported some
> build errors which lead me to creating this patch which both fixes the
> errors as well as the -Wmissing-variable-declarations warning.
>
> [1]: https://lore.kernel.org/all/20230829-missingvardecl-init-main-c-v1-1-ddf0f1a71215@google.com/
>
> Also, get_maintainer.pl had a hard time finding folks to Cc here, not sure why.
> ---
>  include/linux/initrd.h  | 2 ++
>  init/do_mounts_initrd.c | 1 -
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/initrd.h b/include/linux/initrd.h
> index f1a1f4c92ded..0114f1acbb45 100644
> --- a/include/linux/initrd.h
> +++ b/include/linux/initrd.h
> @@ -34,4 +34,6 @@ extern unsigned long __initramfs_size;
>
>  void console_on_rootfs(void);
>
> +extern const char *envp_init[];
> +
>  #endif /* __LINUX_INITRD_H */
> diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
> index 425f4bcf4b77..b35c1b0babc2 100644
> --- a/init/do_mounts_initrd.c
> +++ b/init/do_mounts_initrd.c
> @@ -87,7 +87,6 @@ static void __init handle_initrd(char *root_device_name)
>  {
>         struct subprocess_info *info;
>         static char *argv[] = { "linuxrc", NULL, };
> -       extern char *envp_init[];
>         int error;
>
>         pr_warn("using deprecated initrd support, will be removed in 2021.\n");
>
> ---
> base-commit: 706a741595047797872e669b3101429ab8d378ef
> change-id: 20230830-missingvardecl2-init-main-c-93dc1013ff8a
>
> Best regards,
> --
> Justin Stitt <justinstitt@...gle.com>
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ