Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933920AbcLTJbE (ORCPT ); Tue, 20 Dec 2016 04:31:04 -0500 Received: from terminus.zytor.com ([198.137.202.10]:41444 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933700AbcLTJbA (ORCPT ); Tue, 20 Dec 2016 04:31:00 -0500 Subject: Re: [tip:x86/urgent] x86/tools: Fix gcc-7 warning in relocs.c To: markus@trippelsdorf.de, tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, linux-tip-commits@vger.kernel.org References: <20161215124513.GA289@x4> From: "H. Peter Anvin" Message-ID: Date: Tue, 20 Dec 2016 01:30:48 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2324 Lines: 66 I'd strongly prefer a non-data-dependent solution, specifically adding at the top of sort_relocs(): if (!r->count) return; However, by my reading of the C and POSIX standards, this is a gcc error: qsort() should do nothing if the count is zero. -hpa On 12/19/16 02:56, tip-bot for Markus Trippelsdorf wrote: > Commit-ID: 7ebb916782949621ff6819acf373a06902df7679 > Gitweb: http://git.kernel.org/tip/7ebb916782949621ff6819acf373a06902df7679 > Author: Markus Trippelsdorf > AuthorDate: Thu, 15 Dec 2016 13:45:13 +0100 > Committer: Thomas Gleixner > CommitDate: Mon, 19 Dec 2016 11:50:24 +0100 > > x86/tools: Fix gcc-7 warning in relocs.c > > gcc-7 warns: > > In file included from arch/x86/tools/relocs_64.c:17:0: > arch/x86/tools/relocs.c: In function ‘process_64’: > arch/x86/tools/relocs.c:953:2: warning: argument 1 null where non-null expected [-Wnonnull] > qsort(r->offset, r->count, sizeof(r->offset[0]), cmp_relocs); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In file included from arch/x86/tools/relocs.h:6:0, > from arch/x86/tools/relocs_64.c:1: > /usr/include/stdlib.h:741:13: note: in a call to function ‘qsort’ declared here > extern void qsort > > This happens because relocs16 is not used for ELF_BITS == 64, > so there is no point in trying to sort it. > > Make the sort_relocs(&relocs16) call 32bit only. > > Signed-off-by: Markus Trippelsdorf > Link: http://lkml.kernel.org/r/20161215124513.GA289@x4 > Signed-off-by: Thomas Gleixner > > --- > arch/x86/tools/relocs.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c > index 0c2fae8..73eb7fd 100644 > --- a/arch/x86/tools/relocs.c > +++ b/arch/x86/tools/relocs.c > @@ -992,11 +992,12 @@ static void emit_relocs(int as_text, int use_real_mode) > die("Segment relocations found but --realmode not specified\n"); > > /* Order the relocations for more efficient processing */ > - sort_relocs(&relocs16); > sort_relocs(&relocs32); > #if ELF_BITS == 64 > sort_relocs(&relocs32neg); > sort_relocs(&relocs64); > +#else > + sort_relocs(&relocs16); > #endif > > /* Print the relocations */ > s