x86, relocs: add printf attribute to die()
PATCH v3 1/1 x86, relocs: add printf attribute to die()
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().
---
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(-)
arch/x86/tools/relocs.c +7 -7
@@ -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" , ehdr.e_shoff,strerror (errno)); }for (i =0 ; i < ehdr.e_shnum; i++) {
@@ -431,11 +431,11 @@ static void read_strtabs(FILE *fp) } sec->strtab =malloc (sec->shdr.sh_size);if (!sec->strtab) { -die ("malloc of %d bytes for strtab failed\n" , +die ("malloc of %" PRIuELF" bytes for strtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)
@@ -456,11 +456,11 @@ static void read_symtabs(FILE *fp) } sec->symtab =malloc (sec->shdr.sh_size);if (!sec->symtab) { -die ("malloc of %d bytes for symtab failed\n" , +die ("malloc of %" PRIuELF" bytes for symtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)
@@ -489,11 +489,11 @@ static void read_relocs(FILE *fp) } sec->reltab =malloc (sec->shdr.sh_size);if (!sec->reltab) { -die ("malloc of %d bytes for relocs failed\n" , +die ("malloc of %" PRIuELF" bytes for relocs failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)
arch/x86/tools/relocs.h +2 -1
@@ -16,7 +16,8 @@#include <regex.h> #include <tools/le_byteshift.h> -void die (char *fmt, ...) __attribute__((noreturn)); +void die (const char *fmt, ...) __attribute__((noreturn)) + __attribute__((format (printf,1 ,2 )));#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))
arch/x86/tools/relocs_32.c +3 -0
@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF32_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF32_ST_VISIBILITY(o) +/* printf format for Elf32_Off */ +#define PRIuELF PRIu32 +#include "relocs.c"
arch/x86/tools/relocs_64.c +3 -0
@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF64_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF64_ST_VISIBILITY(o) +/* printf format for Elf64_Off */ +#define PRIuELF PRIu64 +#include "relocs.c"
arch/x86/tools/relocs_common.c +1 -1
@@ -1,6 +1,6 @@#include "relocs.h" -void die (char *fmt, ...) +void die (const char *fmt, ...) {va_list ap;va_start (ap, fmt);
Signature · 1 line
2.11.0
Hello,
As I have not received any comment on the patch I sent in December, I am wondering whether I did anything wrong with it. How can I get it queued for the next merge window?
Thanks,
Nicolas
Quoted 146 lines · Nicolas Iooss
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.cis included byrelocs_32.c,sec->shdr.sh_sizeandsec->shdr.sh_offsetare 32-bit unsigned integers. When the file is included byrelocs_64.c, these expressions are 64-bit unsigned integers.Introduce a PRIuELF macro to define the right format to use when printing
sh_sizeandsh_offsetvalues.While at it, constify the format attribute of
die().Signed-off-by Nicolas Iooss <[email protected]>---
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: Annotatedie()with noreturn to fix build warning on clang") introduced the noreturn attribute todie(), 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(-)arch/x86/tools/relocs.c +7
-7@@ -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" , ehdr.e_shoff,strerror (errno)); }for (i =0 ; i < ehdr.e_shnum; i++) {@@ -431,11 +431,11 @@ static void read_strtabs(FILE *fp) } sec->strtab =malloc (sec->shdr.sh_size);if (!sec->strtab) { -die ("malloc of %d bytes for strtab failed\n" , +die ("malloc of %" PRIuELF" bytes for strtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)@@ -456,11 +456,11 @@ static void read_symtabs(FILE *fp) } sec->symtab =malloc (sec->shdr.sh_size);if (!sec->symtab) { -die ("malloc of %d bytes for symtab failed\n" , +die ("malloc of %" PRIuELF" bytes for symtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)@@ -489,11 +489,11 @@ static void read_relocs(FILE *fp) } sec->reltab =malloc (sec->shdr.sh_size);if (!sec->reltab) { -die ("malloc of %d bytes for relocs failed\n" , +die ("malloc of %" PRIuELF" bytes for relocs failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)arch/x86/tools/relocs.h +2
-1@@ -16,7 +16,8 @@#include <regex.h> #include <tools/le_byteshift.h> -void die (char *fmt, ...) __attribute__((noreturn)); +void die (const char *fmt, ...) __attribute__((noreturn)) + __attribute__((format (printf,1 ,2 )));#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))arch/x86/tools/relocs_32.c +3
-0@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF32_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF32_ST_VISIBILITY(o) +/* printf format for Elf32_Off */ +#define PRIuELF PRIu32 +#include "relocs.c" arch/x86/tools/relocs_64.c +3
-0@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF64_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF64_ST_VISIBILITY(o) +/* printf format for Elf64_Off */ +#define PRIuELF PRIu64 +#include "relocs.c" arch/x86/tools/relocs_common.c +1
-1@@ -1,6 +1,6 @@#include "relocs.h" -void die (char *fmt, ...) +void die (const char *fmt, ...) {va_list ap;va_start (ap, fmt);
[email protected]
reviewerQuoted 157 lines · Nicolas Iooss
Hello,
As I have not received any comment on the patch I sent in December, I am
wondering whether I did anything wrong with it. How can I get it queued for the next merge window?Thanks,
NicolasQuoted 1 line · Nicolas Iooss
Adding such an attribute helps to detect errors in the format string
at
Quoted 1 line
build time. After doing this, the compiler complains about such
issues:
Quoted 10 lines
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));
Quoted 5 lines
^~~~~~~~~~~~~~~~~~~When
relocs.cis included byrelocs_32.c,sec->shdr.sh_sizeandsec->shdr.sh_offsetare 32-bit unsigned integers. When the file is included byrelocs_64.c, these expressions are 64-bit unsignedintegers.
Quoted 6 lines
Introduce a PRIuELF macro to define the right format to use when printing
sh_sizeandsh_offsetvalues.While at it, constify the format attribute of
die().Quoted 7 lines
Signed-off-by Nicolas Iooss <[email protected]>---
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: Annotatedie()with noreturn tofix
Review
Quoted 104 lines
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(-)arch/x86/tools/relocs.c +7
-7@@ -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" , ehdr.e_shoff,strerror (errno)); }for (i =0 ; i < ehdr.e_shnum; i++) {@@ -431,11 +431,11 @@ static void read_strtabs(FILE *fp) } sec->strtab =malloc (sec->shdr.sh_size);if (!sec->strtab) { -die ("malloc of %d bytes for strtab failed\n" , +die ("malloc of %" PRIuELF" bytes for strtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)@@ -456,11 +456,11 @@ static void read_symtabs(FILE *fp) } sec->symtab =malloc (sec->shdr.sh_size);if (!sec->symtab) { -die ("malloc of %d bytes for symtab failed\n" , +die ("malloc of %" PRIuELF" bytes for symtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)@@ -489,11 +489,11 @@ static void read_relocs(FILE *fp) } sec->reltab =malloc (sec->shdr.sh_size);if (!sec->reltab) { -die ("malloc of %d bytes for relocs failed\n" , +die ("malloc of %" PRIuELF" bytes for relocs failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)arch/x86/tools/relocs.h +2
-1@@ -16,7 +16,8 @@#include <regex.h> #include <tools/le_byteshift.h> -void die (char *fmt, ...) __attribute__((noreturn)); +void die (const char *fmt, ...) __attribute__((noreturn)) + __attribute__((format (printf,1 ,2 )));#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))arch/x86/tools/relocs_32.c +3
-0@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF32_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF32_ST_VISIBILITY(o) +/* printf format for Elf32_Off */ +#define PRIuELF PRIu32 +#include "relocs.c" arch/x86/tools/relocs_64.c +3
-0@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF64_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF64_ST_VISIBILITY(o) +/* printf format for Elf64_Off */ +#define PRIuELF PRIu64 +#include "relocs.c" (quoted diff) +0
-0
b/arch/x86/tools/relocs_common.cQuoted 6 lines
index
acab636bcb34..30adb44eff79100644arch/x86/tools/relocs_common.c +0
-0@@ -1,6 +1,6 @@#include "relocs.h"
Quoted 6 lines
arch/x86/tools/relocs_common.c line 6
Quoted 6 lines
arch/x86/tools/relocs_common.c +1
-1-void die (char *fmt, ...) +void die (const char *fmt, ...) {va_list ap;va_start (ap, fmt);
Both are wrong... either PRIu64 or add a cast.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Quoted 158 lines · On 02/02/17 02:39, [email protected] wrote:
Quoted 157 lines · Nicolas Iooss
Hello,
As I have not received any comment on the patch I sent in December, I am
wondering whether I did anything wrong with it. How can I get it queued for the next merge window?Thanks,
NicolasQuoted 1 line · Nicolas Iooss
Adding such an attribute helps to detect errors in the format string
at
Quoted 1 line
build time. After doing this, the compiler complains about such
issues:
Quoted 10 lines
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));
Quoted 5 lines
^~~~~~~~~~~~~~~~~~~When
relocs.cis included byrelocs_32.c,sec->shdr.sh_sizeandsec->shdr.sh_offsetare 32-bit unsigned integers. When the file is included byrelocs_64.c, these expressions are 64-bit unsignedintegers.
Quoted 6 lines
Introduce a PRIuELF macro to define the right format to use when printing
sh_sizeandsh_offsetvalues.While at it, constify the format attribute of
die().Quoted 7 lines
Signed-off-by Nicolas Iooss <[email protected]>---
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: Annotatedie()with noreturn tofix
Review
Quoted 104 lines
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(-)arch/x86/tools/relocs.c +7
-7@@ -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" , ehdr.e_shoff,strerror (errno)); }for (i =0 ; i < ehdr.e_shnum; i++) {@@ -431,11 +431,11 @@ static void read_strtabs(FILE *fp) } sec->strtab =malloc (sec->shdr.sh_size);if (!sec->strtab) { -die ("malloc of %d bytes for strtab failed\n" , +die ("malloc of %" PRIuELF" bytes for strtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)@@ -456,11 +456,11 @@ static void read_symtabs(FILE *fp) } sec->symtab =malloc (sec->shdr.sh_size);if (!sec->symtab) { -die ("malloc of %d bytes for symtab failed\n" , +die ("malloc of %" PRIuELF" bytes for symtab failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)@@ -489,11 +489,11 @@ static void read_relocs(FILE *fp) } sec->reltab =malloc (sec->shdr.sh_size);if (!sec->reltab) { -die ("malloc of %d bytes for relocs failed\n" , +die ("malloc of %" PRIuELF" bytes for relocs failed\n" , sec->shdr.sh_size); }if (fseek (fp, sec->shdr.sh_offset,SEEK_SET ) <0 ) { -die ("Seek to %d failed: %s\n" , +die ("Seek to %" PRIuELF" failed: %s\n" , sec->shdr.sh_offset,strerror (errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)arch/x86/tools/relocs.h +2
-1@@ -16,7 +16,8 @@#include <regex.h> #include <tools/le_byteshift.h> -void die (char *fmt, ...) __attribute__((noreturn)); +void die (const char *fmt, ...) __attribute__((noreturn)) + __attribute__((format (printf,1 ,2 )));#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))arch/x86/tools/relocs_32.c +3
-0@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF32_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF32_ST_VISIBILITY(o) +/* printf format for Elf32_Off */ +#define PRIuELF PRIu32 +#include "relocs.c" arch/x86/tools/relocs_64.c +3
-0@@ -14,4 +14,7 @@#define ELF_ST_BIND (o) ELF64_ST_BIND(o)#define ELF_ST_VISIBILITY (o) ELF64_ST_VISIBILITY(o) +/* printf format for Elf64_Off */ +#define PRIuELF PRIu64 +#include "relocs.c" (quoted diff) +0
-0
b/arch/x86/tools/relocs_common.cQuoted 6 lines
index
acab636bcb34..30adb44eff79100644arch/x86/tools/relocs_common.c +0
-0@@ -1,6 +1,6 @@#include "relocs.h"
Quoted 8 lines
Quoted 6 lines
arch/x86/tools/relocs_common.c line 6
Quoted 6 lines
arch/x86/tools/relocs_common.c +1
-1-void die (char *fmt, ...) +void die (const char *fmt, ...) {va_list ap;va_start (ap, fmt);Both are wrong... either PRIu64 or add a cast.
I described in a previous email (https://lkml.org/lkml/2016/9/3/200) the types which are used. Here is a part of this email:
* When compiling relocs_32.c, sec->shdr.sh_size is of type Elf32_Word (unsigned int) and sec->shdr.sh_offset is Elf32_Off (unsigned int).
* When compiling relocs_64.c, sec->shdr.sh_size is Elf64_Xword (long long unsigned int when the compiler is in 32-bit mode, long unsigned int in 64-bit mode) and sec->shdr.sh_offset is Elf64_Off (same real type as sec->shdr.sh_size).
With this in mind, would you accept a patch which casts everything to 64-bit integers (uint64_t) and uses PRIu64 (which is %llu on 32-bit x86 and %lu on 64-bit x86)?
Nicolas
Quoted 45 lines · Nicolas Iooss
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.cis included byrelocs_32.c,sec->shdr.sh_sizeandsec->shdr.sh_offsetare 32-bit unsigned integers. When the file is included byrelocs_64.c, these expressions are 64-bit unsigned integers.Introduce a PRIuELF macro to define the right format to use when printing
sh_sizeandsh_offsetvalues.While at it, constify the format attribute of
die().Signed-off-by Nicolas Iooss <[email protected]>---
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: Annotatedie()with noreturn to fix build warning on clang") introduced the noreturn attribute todie(), 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(-)arch/x86/tools/relocs.c +0
-0
arch/x86/tools/relocs.c static void read_shdrs(FILE *fp) · line 400
Quoted 5 lines
arch/x86/tools/relocs.c +1
-1@@ -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
Quoted 43 lines · Ingo Molnar
Quoted 40 lines · Nicolas Iooss
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.cis included byrelocs_32.c,sec->shdr.sh_sizeandsec->shdr.sh_offsetare 32-bit unsigned integers. When the file is included byrelocs_64.c, these expressions are 64-bit unsigned integers.Introduce a PRIuELF macro to define the right format to use when printing
sh_sizeandsh_offsetvalues.While at it, constify the format attribute of
die().Signed-off-by Nicolas Iooss <[email protected]>---
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: Annotatedie()with noreturn to fix build warning on clang") introduced the noreturn attribute todie(), 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(-)
Quoted 12 lines
arch/x86/tools/relocs.c static void read_shdrs(FILE *fp) · line 400
Quoted 10 lines
arch/x86/tools/relocs.c +1
-1@@ -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
Quoted 5 lines · Nicolas Iooss
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
[email protected]
reviewerQuoted 14 lines · Ingo Molnar
Quoted 3 lines · Nicolas Iooss
With %Ld, my compiler (gcc 6.3.1 on
x86_64) complains:
arch/x86/tools/relocs.c:400:7: error: format ‘%Ld’ expects argumentof
Quoted 2 lines
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
__u64Elf64_Off;
Quoted 7 lines
Even user-space has it as a pure 64-bit type:
/usr/include/elf.h:typedef
uint64_tElf64_Off;Thanks,
Ingo
uint64_t is unsigned long on x86-64.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Quoted 17 lines · * [email protected] <[email protected]> wrote:
Quoted 16 lines · Ingo Molnar
Quoted 3 lines · Nicolas Iooss
With %Ld, my compiler (gcc 6.3.1 on
x86_64) complains:
arch/x86/tools/relocs.c:400:7: error: format ‘%Ld’ expects argumentof
Quoted 2 lines
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
__u64Elf64_Off;Even user-space has it as a pure 64-bit type:
Quoted 7 lines
Quoted 5 lines
/usr/include/elf.h:typedef
uint64_tElf64_Off;Thanks,
Ingo
uint64_tis unsigned long on x86-64.
Sight, which is a big, lame mistake, because it forces such crap like "PRIu64" uglies...
Thanks,
Ingo