From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01E9315CD7E for ; Tue, 6 Jan 2026 22:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767739945; cv=none; b=Q7PynOUmY04N3hGQ2PxbpLow8BG7dymwT/Wb56yJwvqQ2ex/EATTJWeZpaCb8qTzG+EQ5jK36VuOn45A/BuU0xLnMpdxPlX6vx5ITucX0bZOBAmIhmFhz+iXIUaNPhAsN4MeBnzSt7LkARLMTcPPhd3mamCrOWycxlEOnUkMu9w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767739945; c=relaxed/simple; bh=1I9PhPhwjz4zpv/lwxWy0m5qsgaDYe1kMeNdZHDdqvo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=i2GUaI2DOIMWUU5oijksN0TEZIYnxb7nFAonCuRl6d6yyMMAoGIRIgDgJONul0kaWfKtZoCMLKm7W1bK8v12y4ewOtyqA76pU9YZcYUsNa8xiBuMGvPrKaAPCl8GmjmD1ZZLAtGFRbXHnbHFjMkvsJcNIwFObddMHi5vRsZ1vac= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FO6F7gDI; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FO6F7gDI" Message-ID: <55a1fc6b-5129-4017-af17-e0476626b1b1@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767739941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XXmV/ni98VprxjTHfbU5Ht4acAC5wfPvoZyvlG/xTzg=; b=FO6F7gDI/9h0xNZLkenSrXomTM/eRP8O+lkwptlFvrDrkQH3wnQShoqLrA27Ym14+vPDAd 8WntSO9d0bJ5Ju4mxTh3nm6hBbZRTXoXzWTiJBvtcGTNWq7YbzQP1By9yVtucc8MFsfwa+ ZDz+bTknIFfRI3XUdt3tVd+zXcHY0UE= Date: Tue, 6 Jan 2026 14:51:43 -0800 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v2] scripts/gen-btf.sh: Ensure initial object in gen_btf_o is ELF with correct endianness To: Nathan Chancellor , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Yonghong Song Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev References: <20260106-fix-gen-btf-sh-lto-v2-1-01d3e1c241c4@kernel.org> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ihor Solodrai In-Reply-To: <20260106-fix-gen-btf-sh-lto-v2-1-01d3e1c241c4@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 1/6/26 2:44 PM, Nathan Chancellor wrote: > After commit 600605853f87 ("scripts/gen-btf.sh: Fix .btf.o generation > when compiling for RISCV"), there is an error from llvm-objcopy when > CONFIG_LTO_CLANG is enabled: > > llvm-objcopy: error: '.tmp_vmlinux1.btf.o': The file was not recognized as a valid object file > Failed to generate BTF for vmlinux > > KBUILD_CFLAGS includes CC_FLAGS_LTO, which makes clang emit an LLVM IR > object, rather than an ELF one as expected by llvm-objcopy. > > Most areas of the kernel deal with this by filtering out CC_FLAGS_LTO > from KBUILD_CFLAGS for the particular object or directory but this is > not so easy to do in bash. Just include '-fno-lto' after KBUILD_CFLAGS > to ensure an ELF object is consistently created as the initial .o file. > > Additionally, while there is no reported or discovered bug yet, the > absence of KBUILD_CPPFLAGS from this command could result in incorrect > endianness because KBUILD_CPPFLAGS typically contains '-mbig-endian' and > '-mlittle-endian' so that biendian toolchains can be used. Include it in > this ${CC} command to hopefully limit necessary changes to this command > for the foreseeable future. > > Fixes: 600605853f87 ("scripts/gen-btf.sh: Fix .btf.o generation when compiling for RISCV") > Signed-off-by: Nathan Chancellor > --- > Changes in v2: > - Conservatively include KBUILD_CPPFLAGS as well, as it contains > endianness flags for some targets. > - Link to v1: https://patch.msgid.link/20260105-fix-gen-btf-sh-lto-v1-1-18052ea055a9@kernel.org > --- > scripts/gen-btf.sh | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh > index d6457661b9b6..be21ccee3487 100755 > --- a/scripts/gen-btf.sh > +++ b/scripts/gen-btf.sh > @@ -87,7 +87,7 @@ gen_btf_o() > # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all > # deletes all symbols including __start_BTF and __stop_BTF, which will > # be redefined in the linker script. > - echo "" | ${CC} ${CLANG_FLAGS} ${KBUILD_CFLAGS} -c -x c -o ${btf_data} - > + echo "" | ${CC} ${CLANG_FLAGS} ${KBUILD_CPPFLAGS} ${KBUILD_CFLAGS} -fno-lto -c -x c -o ${btf_data} - Acked-by: Ihor Solodrai Thank you! > ${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF \ > --set-section-flags .BTF=alloc,readonly ${btf_data} > ${OBJCOPY} --only-section=.BTF --strip-all ${btf_data} > > --- > base-commit: a069190b590e108223cd841a1c2d0bfb92230ecc > change-id: 20260105-fix-gen-btf-sh-lto-007fe4908070 > > Best regards, > -- > Nathan Chancellor >