From nobody Thu Apr 9 05:06:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23C7D3358B6; Wed, 11 Mar 2026 08:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773217854; cv=none; b=BHbZm3Cc1EowPXdyvBGO5KShqF8pI/ehpbnVr0LVg2hJNWY54Mnhg26Np9T+NLIkTLdqf2uM1gJfPncblehQ6KJtyIGJbbPlDQAu6nMly0lM91xC0NxFXjhdtmVZ4mTJtUHXcya/i242S2HF6Jz1WhU4InshdEJ1HBX9cra5T2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773217854; c=relaxed/simple; bh=lwUdbNhCM4sMoT9afn20u31yKY7rBPrK42zn1LVlLAo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lPubWw+eiLalaFIJqcUyaANhm+/R1EoXL4cbySS4yjb3uoyoq98nmf/xn7jZMycwHWTGcmMH+6AQYEFcNDKFYiO13rpyKzjV52Pl4exDcn9Vc45IdzlK4wLHAgfpAUSde5q04aq0qUz0OjuVebeP7UAKxHIsFANTJOSvkL1IX+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 59993169C; Wed, 11 Mar 2026 01:30:45 -0700 (PDT) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1661C3F73B; Wed, 11 Mar 2026 01:30:43 -0700 (PDT) From: Leo Yan Date: Wed, 11 Mar 2026 08:29:32 +0000 Subject: [PATCH v4 07/30] libbpf: Initialize CFLAGS before including Makefile.include Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-tools_build_fix_zero_init-v4-7-9e35bdb99cb3@arm.com> References: <20260311-tools_build_fix_zero_init-v4-0-9e35bdb99cb3@arm.com> In-Reply-To: <20260311-tools_build_fix_zero_init-v4-0-9e35bdb99cb3@arm.com> To: Arnaldo Carvalho de Melo , Ian Rogers , Namhyung Kim , James Clark , Kees Cook , Quentin Monnet , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Adrian Hunter , Masami Hiramatsu , William Breathitt Gray , Barry Song , Qinxin Xia , Bartosz Golaszewski , Kent Gibson , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Josh Poimboeuf , Robert Moore , Len Brown , Srinivas Pandruvada , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Mark Brown , Steven Rostedt , Gabriele Monaco , Shuah Khan , Jiri Kosina , Benjamin Tissoires Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773217789; l=2016; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=lwUdbNhCM4sMoT9afn20u31yKY7rBPrK42zn1LVlLAo=; b=GdKfa01WQ7EkzzQs+te2K50YYy3uDWjVtIqcP10O+ayAEW55IWUt0xlTbNxpXIDO2MzJ87s+m bTBGCOX5yjiAJkYH4vaiiMcN8JenuCarMb1LY19qZ+uUGkCcj54pZjb X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= tools/scripts/Makefile.include may expand EXTRA_CFLAGS in a future change. This could alter the initialization of CFLAGS, as the default options "-g -O2" would never be set once EXTRA_CFLAGS is expanded. Prepare for this by moving the CFLAGS initialization before including tools/scripts/Makefile.include, so it is not affected by the extended EXTRA_CFLAGS. Append EXTRA_CFLAGS to CFLAGS only after including Makefile.include and place it last so that the extra flags propagate properly and can override the default options. Signed-off-by: Leo Yan --- tools/lib/bpf/Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index b1fbd0211c5edde7be3d98630b16e53e028d9116..eca584fb061e16013e76827e420= 3f6be0477a73e 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -49,6 +49,14 @@ man_dir_SQ =3D '$(subst ','\'',$(man_dir))' export man_dir man_dir_SQ INSTALL export DESTDIR DESTDIR_SQ =20 +# Defer assigning EXTRA_CFLAGS to CFLAGS until after including +# tools/scripts/Makefile.include, as it may add flags to EXTRA_CFLAGS. +ifdef EXTRA_CFLAGS + CFLAGS :=3D +else + CFLAGS :=3D -g -O2 +endif + include $(srctree)/tools/scripts/Makefile.include =20 # copy a bit from Linux kbuild @@ -70,13 +78,6 @@ LIB_TARGET =3D libbpf.a libbpf.so.$(LIBBPF_VERSION) LIB_FILE =3D libbpf.a libbpf.so* PC_FILE =3D libbpf.pc =20 -# Set compile option CFLAGS -ifdef EXTRA_CFLAGS - CFLAGS :=3D $(EXTRA_CFLAGS) -else - CFLAGS :=3D -g -O2 -endif - # Append required CFLAGS override CFLAGS +=3D -std=3Dgnu89 override CFLAGS +=3D $(EXTRA_WARNINGS) -Wno-switch-enum @@ -84,6 +85,7 @@ override CFLAGS +=3D -Werror -Wall override CFLAGS +=3D $(INCLUDES) override CFLAGS +=3D -fvisibility=3Dhidden override CFLAGS +=3D -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64 +override CFLAGS +=3D $(EXTRA_CFLAGS) =20 # flags specific for shared library SHLIB_FLAGS :=3D -DSHARED -fPIC --=20 2.34.1