From: Masami Hiramatsu <mhiramat@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Oleksandr Natalenko <oleksandr@redhat.com>,
linux-mm@kvack.org, Arnaldo Carvalho de Melo <acme@redhat.com>,
Will Deacon <will@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Song Liu <songliubraving@fb.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
Marc Zyngier <maz@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kallsyms: work around bogus -Wrestrict warning
Date: Wed, 8 Jan 2020 10:26:02 +0900 [thread overview]
Message-ID: <20200108102602.43d4c5433eb495cdbf387e9b@kernel.org> (raw)
In-Reply-To: <20200107214042.855757-1-arnd@arndb.de>
Hi Arnd,
On Tue, 7 Jan 2020 22:40:26 +0100
Arnd Bergmann <arnd@arndb.de> wrote:
> gcc -O3 produces some really odd warnings for this file:
>
> kernel/kallsyms.c: In function 'sprint_symbol':
> kernel/kallsyms.c:369:3: error: 'strcpy' source argument is the same as destination [-Werror=restrict]
> strcpy(buffer, name);
> ^~~~~~~~~~~~~~~~~~~~
> kernel/kallsyms.c: In function 'sprint_symbol_no_offset':
> kernel/kallsyms.c:369:3: error: 'strcpy' source argument is the same as destination [-Werror=restrict]
> strcpy(buffer, name);
> ^~~~~~~~~~~~~~~~~~~~
> kernel/kallsyms.c: In function 'sprint_backtrace':
> kernel/kallsyms.c:369:3: error: 'strcpy' source argument is the same as destination [-Werror=restrict]
> strcpy(buffer, name);
> ^~~~~~~~~~~~~~~~~~~~
>
> This obviously cannot be since it is preceded by an 'if (name != buffer)'
> check.
Hmm, this looks like a bug in gcc.
>
> Using sprintf() instead of strcpy() is a bit wasteful but is
> the best workaround I could come up with.
>
> Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> kernel/kallsyms.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> index d812b90f4c86..726b8eeb223e 100644
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c
> @@ -366,7 +366,7 @@ static int __sprint_symbol(char *buffer, unsigned long address,
> return sprintf(buffer, "0x%lx", address - symbol_offset);
>
> if (name != buffer)
> - strcpy(buffer, name);
> + sprintf(buffer, "%s", name);
BTW, this seems not happen. kallsyms_lookup() (and it's subfunctions)
always stores the result into buffer unless name == NULL.
Maybe we can remove these 2 lines?
(and add a comment line for kallsyms_lookup() so that it guarantees the
symbol name always stored in namebuf argument)
Thank you,
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2020-01-08 1:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 21:40 [PATCH] kallsyms: work around bogus -Wrestrict warning Arnd Bergmann
2020-01-07 22:25 ` Andrew Morton
2020-01-08 9:23 ` Oleksandr Natalenko
2020-01-08 1:26 ` Masami Hiramatsu [this message]
2020-01-09 22:02 ` Andrew Morton
2020-01-09 22:18 ` Arnd Bergmann
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=20200108102602.43d4c5433eb495cdbf387e9b@kernel.org \
--to=mhiramat@kernel.org \
--cc=acme@redhat.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maz@kernel.org \
--cc=oleksandr@redhat.com \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).