From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753600AbcICOvo (ORCPT ); Sat, 3 Sep 2016 10:51:44 -0400 Received: from mx1.polytechnique.org ([129.104.30.34]:44398 "EHLO mx1.polytechnique.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753231AbcICOvm (ORCPT ); Sat, 3 Sep 2016 10:51:42 -0400 From: Nicolas Iooss To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org Cc: linux-kernel@vger.kernel.org, Nicolas Iooss Subject: [PATCH 1/1] x86, relocs: add function attributes to die() Date: Sat, 3 Sep 2016 16:50:37 +0200 Message-Id: <20160903145037.24685-1-nicolas.iooss_linux@m4x.org> X-Mailer: git-send-email 2.9.3 X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sat Sep 3 16:51:37 2016 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.000000, queueID=0906F5646DF Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When building the kernel with clang and some warning flags, the compiler reports the following warning: arch/x86/tools/relocs.c:979:6: warning: variable 'do_reloc' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (!use_real_mode) ^~~~~~~~~~~~~~ arch/x86/tools/relocs.c:991:14: note: uninitialized use occurs here walk_relocs(do_reloc); ^~~~~~~~ arch/x86/tools/relocs.c:979:2: note: remove the 'if' if its condition is always true if (!use_real_mode) ^~~~~~~~~~~~~~~~~~~ arch/x86/tools/relocs.c:976:24: note: initialize the variable 'do_reloc' to silence this warning const char *symname); ^ = NULL This is obviously a false positive: whenever the 'if' condition is false, the program calls die(). Nevertheless the compiler did not know this call makes the program quit because this function did not have a noreturn attribute. Add it. While at it, add a printf attribute too to die() and constify the format parameter. This leads to some errors when compiling on x86_64: 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)); ^~~~~~~~~~~~~~~~~~~ To support both 32-bit and 64-bit modes, add casts to long types and use %lu and %ld to format the numbers. Signed-off-by: Nicolas Iooss --- arch/x86/tools/relocs.c | 28 ++++++++++++++-------------- arch/x86/tools/relocs.h | 3 ++- arch/x86/tools/relocs_common.c | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 0c2fae8d929d..88d9595ee4de 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 %lu failed: %s\n", + (unsigned long)ehdr.e_shoff, strerror(errno)); } for (i = 0; i < ehdr.e_shnum; i++) { struct section *sec = &secs[i]; @@ -431,12 +431,12 @@ 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", - sec->shdr.sh_size); + die("malloc of %lu bytes for strtab failed\n", + (unsigned long)sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %ld failed: %s\n", + (long)sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { @@ -456,12 +456,12 @@ 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", - sec->shdr.sh_size); + die("malloc of %lu bytes for symtab failed\n", + (unsigned long)sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %ld failed: %s\n", + (long)sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { @@ -489,12 +489,12 @@ 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", - sec->shdr.sh_size); + die("malloc of %lu bytes for relocs failed\n", + (unsigned long)sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %ld failed: %s\n", + (long)sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h index f59590645b68..6b7969719833 100644 --- a/arch/x86/tools/relocs.h +++ b/arch/x86/tools/relocs.h @@ -16,7 +16,8 @@ #include #include -void die(char *fmt, ...); +__attribute__((format(printf, 1, 2))) __attribute__((noreturn)) +void die(const char *fmt, ...); #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/arch/x86/tools/relocs_common.c b/arch/x86/tools/relocs_common.c index acab636bcb34..30adb44eff79 100644 --- a/arch/x86/tools/relocs_common.c +++ b/arch/x86/tools/relocs_common.c @@ -1,6 +1,6 @@ #include "relocs.h" -void die(char *fmt, ...) +void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); -- 2.9.3