From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755471AbdCGNUK (ORCPT ); Tue, 7 Mar 2017 08:20:10 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34063 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755144AbdCGNTd (ORCPT ); Tue, 7 Mar 2017 08:19:33 -0500 Date: Tue, 7 Mar 2017 10:16:11 +0100 From: Ingo Molnar To: Nicolas Iooss Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/1] x86, relocs: add printf attribute to die() Message-ID: <20170307091611.GA9795@gmail.com> References: <20170305141242.17499-1-nicolas.iooss_linux@m4x.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170305141242.17499-1-nicolas.iooss_linux@m4x.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Nicolas Iooss 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 > --- > 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? Thanks, Ingo