From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754274AbcICPwC (ORCPT ); Sat, 3 Sep 2016 11:52:02 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36383 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753836AbcICPv5 (ORCPT ); Sat, 3 Sep 2016 11:51:57 -0400 Subject: Re: [PATCH 1/1] x86, relocs: add function attributes to die() To: Nilay Vaish References: <20160903145037.24685-1-nicolas.iooss_linux@m4x.org> Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86 , Linux Kernel list From: Nicolas Iooss Message-ID: <173b263e-76ff-c8c9-aff8-ee6097164f4c@m4x.org> Date: Sat, 3 Sep 2016 17:51:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/09/16 17:16, Nilay Vaish wrote: > On 3 September 2016 at 09:50, Nicolas Iooss wrote: >> >> 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. >> > > Nicolas, should not just changing the format specifiers fix the > problem? How do those type casts help? The problem is that I did not found a simple format which would make both arch/x86/tools/relocs_32.o and arch/x86/tools/relocs_64.o build without any warning. Here are the types: * 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). I though that casting everything to long integers was fine but now I have realized this does not take into account compiling relocs_64.c on a 32-bit host system (where HOSTCC compiles in 32-bit mode and long integers are 32-bit wide). A possible solution would be using format definitions from like PRIu32, PRIu64... in relocs.c depending on the file being compiled (relocs_32.c or relocs_64.c). What would you think of such a solution? -- Nicolas