From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754179AbdBAWmm (ORCPT ); Wed, 1 Feb 2017 17:42:42 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36772 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753299AbdBAWmk (ORCPT ); Wed, 1 Feb 2017 17:42:40 -0500 Subject: Re: [PATCH v3 1/1] x86, relocs: add printf attribute to die() To: Ingo Molnar References: <20161218194752.32367-1-nicolas.iooss_linux@m4x.org> <20170201090455.GA23627@gmail.com> Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org From: Nicolas Iooss Message-ID: <53bd203b-c006-fb7c-0bd6-54a6a926fd1e@m4x.org> Date: Wed, 1 Feb 2017 23:42:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <20170201090455.GA23627@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/02/17 10:04, Ingo Molnar wrote: > > * 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 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 >> --- >> 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