From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Richter Subject: [PATCH] perf build: Build error in libbpf missing initialization Date: Fri, 27 Jul 2018 10:21:26 +0200 Message-ID: <20180727082126.87530-1-tmricht@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: heiko.carstens@de.ibm.com, brueckner@linux.vnet.ibm.com, schwidefsky@de.ibm.com, jakub.kicinski@netronome.com, Thomas Richter To: daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Return-path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40166 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729445AbeG0JmW (ORCPT ); Fri, 27 Jul 2018 05:42:22 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6R8JR0Z049647 for ; Fri, 27 Jul 2018 04:21:36 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kfw67xjws-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Jul 2018 04:21:36 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 27 Jul 2018 09:21:34 +0100 Sender: netdev-owner@vger.kernel.org List-ID: In linux-next tree compiling the perf tool with additional make flags "EXTRA_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -O2" causes a compiler error. It is the warning 'variable may be used uninitialized' which is treated as error: I compile it using a FEDORA 28 installation, my gcc compiler version: gcc (GCC) 8.0.1 20180324 (Red Hat 8.0.1-0.20) The file that causes the error is tools/lib/bpf/libbpf.c Here is the error message: [root@p23lp27] # make V=1 EXTRA_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -O2" [...] Makefile.config:849: No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h' CC libbpf.o libbpf.c: In function ‘bpf_perf_event_read_simple’: libbpf.c:2342:6: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized] int ret; ^ cc1: all warnings being treated as errors mv: cannot stat './.libbpf.o.tmp': No such file or directory /home6/tmricht/linux-next/tools/build/Makefile.build:96: recipe for target 'libbpf.o' failed Fix this warning and add an addition check at the beginning of the while loop. Cc: Alexei Starovoitov Cc: Daniel Borkmann Suggested-by: Jakub Kicinski Signed-off-by: Thomas Richter --- tools/lib/bpf/libbpf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 73465caa33ba..66965ca96113 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2349,6 +2349,8 @@ bpf_perf_event_read_simple(void *mem, unsigned long size, begin = base + data_tail % size; end = base + data_head % size; + if (begin == end) + return LIBBPF_PERF_EVENT_ERROR; while (begin != end) { struct perf_event_header *ehdr; -- 2.16.4