From: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
To: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Cc: x86 <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 1/1] x86, relocs: add printf attribute to die()
Date: Tue, 28 Mar 2017 23:06:24 +0200 [thread overview]
Message-ID: <CAJfZ7=kzAgq57cvK+pj9G5yCmem3bnqFt_s0bo86ZYZbkNm_wA@mail.gmail.com> (raw)
In-Reply-To: <CAJfZ7=nVgswTB7JsoOWH5s3CeoMn31pLTbNoyn-htSWzXNxmRw@mail.gmail.com>
On Tue, Mar 7, 2017 at 1:37 PM, Nicolas Iooss
<nicolas.iooss_linux@m4x.org> wrote:
> On Tue, Mar 7, 2017 at 10:16 AM, Ingo Molnar <mingo@kernel.org> wrote:
>>
>> * Nicolas Iooss <nicolas.iooss_linux@m4x.org> wrote:
>>
>>> Adding such an attribute helps to detect errors in the format string at
>>> build time. After doing this, the compiler complains about some issues:
>>>
>>> arch/x86/tools/relocs.c:460:5: error: format specifies type 'int'
>>> but the argument has type 'Elf64_Xword' (aka 'unsigned long')
>>> [-Werror,-Wformat]
>>> sec->shdr.sh_size);
>>> ^~~~~~~~~~~~~~~~~
>>> arch/x86/tools/relocs.c:464:5: error: format specifies type 'int'
>>> but the argument has type 'Elf64_Off' (aka 'unsigned long')
>>> [-Werror,-Wformat]
>>> sec->shdr.sh_offset, strerror(errno));
>>> ^~~~~~~~~~~~~~~~~~~
>>>
>>> When relocs.c is included by relocs_32.c, sec->shdr.sh_size and
>>> sec->shdr.sh_offset are 32-bit unsigned integers. When the file is
>>> included by relocs_64.c, these expressions are 64-bit unsigned integers.
>>>
>>> Add casts to unsigned long long, which length is always 64-bit, and use
>>> %llu to format sec->shdr.sh_size and sec->shdr.sh_offset in relocs.c.
>>>
>>> While at it, constify the format attribute of die().
>>>
>>> Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
>>> ---
>>> arch/x86/tools/relocs.c | 31 +++++++++++++++++--------------
>>> arch/x86/tools/relocs.h | 3 ++-
>>> arch/x86/tools/relocs_common.c | 2 +-
>>> 3 files changed, 20 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
>>> index 73eb7fd4aec4..3cc02065c677 100644
>>> --- a/arch/x86/tools/relocs.c
>>> +++ b/arch/x86/tools/relocs.c
>>> @@ -397,8 +397,8 @@ static void read_shdrs(FILE *fp)
>>> ehdr.e_shnum);
>>> }
>>> if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) {
>>> - die("Seek to %d failed: %s\n",
>>> - ehdr.e_shoff, strerror(errno));
>>> + die("Seek to %llu failed: %s\n",
>>> + (unsigned long long)ehdr.e_shoff, strerror(errno));
>>
>> Isn't "(u64)" shorter to write?
>
> u64 does not seem to be defined in this file right now. Adding
> "#include <linux/types.h>" defines u64 and __u64 in the following way:
> - "typedef uint64_t u64;" from tools/include/linux/types.h
> - "typedef unsigned long long __u64;" from /usr/include/asm-generic/int-ll64.h
>
> uint64_t is unsigned long on x86-64 and gcc complains when using %llu
> on such a type, so using a cast to u64 forces using PRIu64 too.
>
> Nevertheless "(__u64)" is shorter than "(unsigned long long)" and
> seems to work fine in my quick tests because it is always unsigned
> long long (on both x86-32 and x86-64). Would you prefer to use this
> cast?
Hello,
After the question I had on the 4th revision of this patch, I have not
received any reply or comment for three weeks. What should I do in
order to get this merged?
Thanks,
Nicolas
next prev parent reply other threads:[~2017-03-28 21:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-05 14:12 [PATCH v4 1/1] x86, relocs: add printf attribute to die() Nicolas Iooss
2017-03-07 9:16 ` Ingo Molnar
2017-03-07 12:37 ` Nicolas Iooss
2017-03-28 21:06 ` Nicolas Iooss [this message]
2017-05-17 6:37 ` Nicolas Iooss
2017-05-27 19:28 ` Andy Shevchenko
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='CAJfZ7=kzAgq57cvK+pj9G5yCmem3bnqFt_s0bo86ZYZbkNm_wA@mail.gmail.com' \
--to=nicolas.iooss_linux@m4x.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@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).