Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1571346 > unrolled thread

Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die()

Started byIngo Molnar <mingo@kernel.org>
First post2017-02-01 10:10 +0100
Last post2017-02-02 20:40 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die() Ingo Molnar <mingo@kernel.org> - 2017-02-01 10:10 +0100
    Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die() Nicolas Iooss <nicolas.iooss_linux@m4x.org> - 2017-02-01 23:50 +0100
      Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die() Ingo Molnar <mingo@kernel.org> - 2017-02-02 08:20 +0100
        Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die() hpa@zytor.com - 2017-02-02 08:50 +0100
          Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die() Ingo Molnar <mingo@kernel.org> - 2017-02-02 20:40 +0100

#1571346 — Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die()

FromIngo Molnar <mingo@kernel.org>
Date2017-02-01 10:10 +0100
SubjectRe: [PATCH v3 1/1] x86, relocs: add printf attribute to die()
Message-ID<t5Z5p-3VC-43@gated-at.bofh.it>
* 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 such 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.
> 
> Introduce a PRIuELF macro to define the right format to use when
> printing sh_size and sh_offset values.
> 
> While at it, constify the format attribute of die().
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
> ---
> I sent the first versions of this patch in September (cf.
> https://patchwork.kernel.org/patch/9312665/) but it has not been
> applied.
> 
> As commit adee8705d251 ("x86/build: Annotate die() with noreturn to fix
> build warning on clang") introduced the noreturn attribute to die(),
> this patch now only adds the printf attribute.
> 
>  arch/x86/tools/relocs.c        | 14 +++++++-------
>  arch/x86/tools/relocs.h        |  3 ++-
>  arch/x86/tools/relocs_32.c     |  3 +++
>  arch/x86/tools/relocs_64.c     |  3 +++
>  arch/x86/tools/relocs_common.c |  2 +-
>  5 files changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
> index 0c2fae8d929d..4cad603b8d58 100644
> --- a/arch/x86/tools/relocs.c
> +++ b/arch/x86/tools/relocs.c
> @@ -397,7 +397,7 @@ 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",
> +		die("Seek to %"PRIuELF" failed: %s\n",

Doesn't a simple "%Ld" work as well?

Thanks,

	Ingo

[toc] | [next] | [standalone]


#1572033

FromNicolas Iooss <nicolas.iooss_linux@m4x.org>
Date2017-02-01 23:50 +0100
Message-ID<t6bSW-3Oo-7@gated-at.bofh.it>
In reply to#1571346
On 01/02/17 10:04, Ingo Molnar 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 such 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.
>>
>> Introduce a PRIuELF macro to define the right format to use when
>> printing sh_size and sh_offset values.
>>
>> While at it, constify the format attribute of die().
>>
>> Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
>> ---
>> I sent the first versions of this patch in September (cf.
>> https://patchwork.kernel.org/patch/9312665/) but it has not been
>> applied.
>>
>> As commit adee8705d251 ("x86/build: Annotate die() with noreturn to fix
>> build warning on clang") introduced the noreturn attribute to die(),
>> this patch now only adds the printf attribute.
>>
>>  arch/x86/tools/relocs.c        | 14 +++++++-------
>>  arch/x86/tools/relocs.h        |  3 ++-
>>  arch/x86/tools/relocs_32.c     |  3 +++
>>  arch/x86/tools/relocs_64.c     |  3 +++
>>  arch/x86/tools/relocs_common.c |  2 +-
>>  5 files changed, 16 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
>> index 0c2fae8d929d..4cad603b8d58 100644
>> --- a/arch/x86/tools/relocs.c
>> +++ b/arch/x86/tools/relocs.c
>> @@ -397,7 +397,7 @@ 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",
>> +		die("Seek to %"PRIuELF" failed: %s\n",
> 
> Doesn't a simple "%Ld" work as well?

With %Ld, my compiler (gcc 6.3.1 on x86_64) complains:

arch/x86/tools/relocs.c:400:7: error: format ‘%Ld’ expects argument of
type ‘long long int’, but argument 2 has type ‘Elf64_Off {aka long
unsigned int}’ [-Werror=format=]

Thanks,
Nicolas

[toc] | [prev] | [next] | [standalone]


#1572166

FromIngo Molnar <mingo@kernel.org>
Date2017-02-02 08:20 +0100
Message-ID<t6jQt-Iw-9@gated-at.bofh.it>
In reply to#1572033
* Nicolas Iooss <nicolas.iooss_linux@m4x.org> wrote:

> With %Ld, my compiler (gcc 6.3.1 on x86_64) complains:
> 
> arch/x86/tools/relocs.c:400:7: error: format ‘%Ld’ expects argument of
> type ‘long long int’, but argument 2 has type ‘Elf64_Off {aka long
> unsigned int}’ [-Werror=format=]

How did it pick up that type as an 'unsigned long'? We have:

  include/uapi/linux/elf.h:typedef __u64  Elf64_Off;

Even user-space has it as a pure 64-bit type:

  /usr/include/elf.h:typedef uint64_t Elf64_Off;

Thanks,

	Ingo

[toc] | [prev] | [next] | [standalone]


#1572180

Fromhpa@zytor.com
Date2017-02-02 08:50 +0100
Message-ID<t6kjw-SI-11@gated-at.bofh.it>
In reply to#1572166
On February 1, 2017 11:16:00 PM PST, Ingo Molnar <mingo@kernel.org> wrote:
>
>* Nicolas Iooss <nicolas.iooss_linux@m4x.org> wrote:
>
>> With %Ld, my compiler (gcc 6.3.1 on x86_64) complains:
>> 
>> arch/x86/tools/relocs.c:400:7: error: format ‘%Ld’ expects argument
>of
>> type ‘long long int’, but argument 2 has type ‘Elf64_Off {aka long
>> unsigned int}’ [-Werror=format=]
>
>How did it pick up that type as an 'unsigned long'? We have:
>
>  include/uapi/linux/elf.h:typedef __u64  Elf64_Off;
>
>Even user-space has it as a pure 64-bit type:
>
>  /usr/include/elf.h:typedef uint64_t Elf64_Off;
>
>Thanks,
>
>	Ingo

uint64_t is unsigned long on x86-64.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

[toc] | [prev] | [next] | [standalone]


#1572703

FromIngo Molnar <mingo@kernel.org>
Date2017-02-02 20:40 +0100
Message-ID<t6voB-8cY-15@gated-at.bofh.it>
In reply to#1572180
* hpa@zytor.com <hpa@zytor.com> wrote:

> On February 1, 2017 11:16:00 PM PST, Ingo Molnar <mingo@kernel.org> wrote:
> >
> >* Nicolas Iooss <nicolas.iooss_linux@m4x.org> wrote:
> >
> >> With %Ld, my compiler (gcc 6.3.1 on x86_64) complains:
> >> 
> >> arch/x86/tools/relocs.c:400:7: error: format ‘%Ld’ expects argument
> >of
> >> type ‘long long int’, but argument 2 has type ‘Elf64_Off {aka long
> >> unsigned int}’ [-Werror=format=]
> >
> >How did it pick up that type as an 'unsigned long'? We have:
> >
> >  include/uapi/linux/elf.h:typedef __u64  Elf64_Off;
> >
> >Even user-space has it as a pure 64-bit type:
> >
> >  /usr/include/elf.h:typedef uint64_t Elf64_Off;
> >
> >Thanks,
> >
> >	Ingo
> 
> uint64_t is unsigned long on x86-64.

Sight, which is a big, lame mistake, because it forces such crap like "PRIu64" 
uglies...

Thanks,

	Ingo

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web