dev-util/bpftool: Sync with Gentoo

It's from Gentoo commit 53d1b62c00f7a1b4be97077e1b5d0e01ec397c7e.
This commit is contained in:
Flatcar Buildbot 2025-05-05 07:07:58 +00:00 committed by Krzesimir Nowak
parent d60f17f0f0
commit e7dedb7984
15 changed files with 76 additions and 928 deletions

View File

@ -1,7 +1 @@
DIST bpftool-7.4.0.tar.gz 472915 BLAKE2B ae7b6bc6cb742712981ba8972bcecccc63d440b2a77c5a14f91ba5106c013774313d65fd3f42b843ba4027ab17cf9d44d256270f7f8ad11907714f16f3149078 SHA512 08a3095b37a9b897400f2be7dbb9de10d129ae4eef193d03955fdf84017cd3a5d7419e856aa68a425e609419868e8b1dd5409b4f218cc24feeb059c1898cdff4
DIST bpftool-libbpf-v7.5.0-sources.tar.gz 1510032 BLAKE2B cc9beac4034317f89ae3c1088d1b1a1948778bcdb51d7ed7f566e4e5ab720c1128ca467d51d0bc3ffe7b1f69800249362baef5dfaf858275050f96b744fdbca6 SHA512 db12c305b77fea3689dbc1ce94527f0f21fa9de21fcdb36385e3fe492137335bb393f90e456c06601495ccc984230a531c432709db6514b545e0aeeda7ca3c99 DIST bpftool-libbpf-v7.5.0-sources.tar.gz 1510032 BLAKE2B cc9beac4034317f89ae3c1088d1b1a1948778bcdb51d7ed7f566e4e5ab720c1128ca467d51d0bc3ffe7b1f69800249362baef5dfaf858275050f96b744fdbca6 SHA512 db12c305b77fea3689dbc1ce94527f0f21fa9de21fcdb36385e3fe492137335bb393f90e456c06601495ccc984230a531c432709db6514b545e0aeeda7ca3c99
DIST libbpf-1.4.7.tar.gz 1016441 BLAKE2B 10be52c7e97b2f08edd33cb263c4737bb52edfd2226f0c5b86d4f95b584b81f8f6b1ede469e9ad6c231e55b6d6b9a038160662606c3f30dc79b1336aaaa90e74 SHA512 f09ff28ac75b0d0c1bfe7d233aee6a00e5c21f185646b2afe11b7bd048d74962f893237437dd81a762768f9235b9f2a2a33cb297201b2aa3e98f7c6f58e5b365
DIST linux-6.8.tar.xz 142502100 BLAKE2B c6f17f816cea16e629f63e9379b98888713f57b2c5173306926471f139a9d612a0c74e119341f8075390e55e203d787d9edeb4ad5a064b18870f6f0f7ffaafb2 SHA512 5c4eb4aa1d3f7d1ea01c0f7ddeadacdece6e144fd4bdfc16b2b925d3e10dc04de3a6db69320b79a96c3560052616f001d2c09e7a1bb4f7b731e2380a7ecce068
DIST linux-6.9.tar.xz 144034416 BLAKE2B 4cf86c3cfe6e6534745d42dfaeca59b17ea1168c4e8b615c80e6d8aac735f11283cd85fa992b440b5d4452917e94b9f08397a64af0be5894e3df23c68892377e SHA512 fed3b4cd1fbfb4d94618587c1934273d2ecc8b6e42a3d586ff8a5f24980be930f2ef803aa2923ca3bfa5e4e619f967f3af315368f24fa76f610b10443624a579
DIST patch-6.8.2.xz 247244 BLAKE2B a85078230548543c38550a5546689d0b44a54208cdad591ab34e10dec9348ce2f74e45bf85f373b14977d40556067e2e2c17ac4b6791fbb8aaba98feccd3cdac SHA512 a8e32b89f7680670c69c62f356846bb65b57614f979114627a9a2f945d7dc97c921d30197dffa993e5b18e499ba8c7196046ffdf0e721528a5378d1ee65a9ba5
DIST patch-6.9.2.xz 16184 BLAKE2B 8a37e96c253b55b57c86f1654f2ea8bf65af96b1b38213e90032cb918bb8eea992d6ddbfa6a6774a229ab2e2288ab57bdb6cbad6e7e393c123f24850e06847c9 SHA512 a27af24f0caaa5de3811b6db5acc2d72b96df9ebb5c44bad99a949d871fb06c6ffd2be10cfc35b246d430c7be2291701f802aed47eaa8818ad12b8818a60f3ec

View File

@ -1,123 +0,0 @@
# Copyright 2021-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{10..12} )
inherit estack linux-info optfeature python-any-r1 bash-completion-r1 toolchain-funcs
MY_PV="${PV/_/-}"
MY_PV="${MY_PV/-pre/-git}"
DESCRIPTION="Tool for inspection and simple manipulation of eBPF programs and maps"
HOMEPAGE="https://kernel.org/"
LINUX_V="${PV:0:1}.x"
LINUX_VER=$(ver_cut 1-2)
LINUX_PATCH=patch-${PV}.xz
SRC_URI="https://www.kernel.org/pub/linux/kernel/v${LINUX_V}/${LINUX_PATCH}"
LINUX_SOURCES="linux-${LINUX_VER}.tar.xz"
SRC_URI+=" https://www.kernel.org/pub/linux/kernel/v${LINUX_V}/${LINUX_SOURCES}"
S_K="${WORKDIR}/linux-${LINUX_VER}"
S="${S_K}/tools/bpf/bpftool"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64 arm arm64 ~loong ppc ppc64 ~riscv x86"
IUSE="caps +llvm"
RDEPEND="
sys-libs/binutils-libs:=
sys-libs/zlib:=
virtual/libelf:=
caps? ( sys-libs/libcap:= )
llvm? ( llvm-core/llvm:= )
"
DEPEND="
${RDEPEND}
>=sys-kernel/linux-headers-5.8
"
BDEPEND="
${LINUX_PATCH+dev-util/patchutils}
${PYTHON_DEPS}
app-arch/tar
dev-python/docutils
"
CONFIG_CHECK="~DEBUG_INFO_BTF"
# src_unpack and src_prepare are copied from dev-util/perf since
# it's building from the same tarball, please keep it in sync with perf
src_unpack() {
local paths=(
tools/bpf kernel/bpf
tools/{arch,build,include,lib,perf,scripts} {scripts,include,lib} "arch/*/lib"
)
# We expect the tar implementation to support the -j and --wildcards option
echo ">>> Unpacking ${LINUX_SOURCES} (${paths[*]}) to ${PWD}"
gtar --wildcards -xpf "${DISTDIR}"/${LINUX_SOURCES} \
"${paths[@]/#/linux-${LINUX_VER}/}" || die
if [[ -n ${LINUX_PATCH} ]] ; then
eshopts_push -o noglob
ebegin "Filtering partial source patch"
filterdiff -p1 ${paths[@]/#/-i } -z "${DISTDIR}"/${LINUX_PATCH} \
> ${P}.patch
eend $? || die "filterdiff failed"
eshopts_pop
fi
local a
for a in ${A}; do
[[ ${a} == ${LINUX_SOURCES} ]] && continue
[[ ${a} == ${LINUX_PATCH} ]] && continue
unpack ${a}
done
}
src_prepare() {
default
if [[ -n ${LINUX_PATCH} ]] ; then
pushd "${S_K}" >/dev/null || die
eapply "${WORKDIR}"/${P}.patch
popd || die
fi
# Use rst2man or rst2man.py depending on which one exists (#930076)
type -P rst2man >/dev/null || sed -i -e 's/rst2man/rst2man.py/g' Documentation/Makefile || die
# remove -Werror (bug 887981)
sed -i -e 's/\-Werror//g' ../../lib/bpf/Makefile || die
}
bpftool_make() {
local arch=$(tc-arch-kernel)
tc-export AR CC LD
emake V=1 VF=1 \
HOSTCC="$(tc-getBUILD_CC)" HOSTLD="$(tc-getBUILD_LD)" \
EXTRA_CFLAGS="${CFLAGS}" ARCH="${arch}" BPFTOOL_VERSION="${MY_PV}" \
prefix="${EPREFIX}"/usr \
bash_compdir="$(get_bashcompdir)" \
feature-libcap="$(usex caps 1 0)" \
feature-llvm="$(usex llvm 1 0)" \
"$@"
}
src_compile() {
bpftool_make
bpftool_make -C Documentation
}
src_install() {
bpftool_make DESTDIR="${D}" install
bpftool_make mandir="${ED}"/usr/share/man -C Documentation install
}
pkg_postinst() {
optfeature "clang-bpf-co-re support" llvm-core/clang[llvm_targets_BPF]
}

View File

@ -1,123 +0,0 @@
# Copyright 2021-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{10..12} )
inherit estack linux-info optfeature python-any-r1 bash-completion-r1 toolchain-funcs
MY_PV="${PV/_/-}"
MY_PV="${MY_PV/-pre/-git}"
DESCRIPTION="Tool for inspection and simple manipulation of eBPF programs and maps"
HOMEPAGE="https://kernel.org/"
LINUX_V="${PV:0:1}.x"
LINUX_VER=$(ver_cut 1-2)
LINUX_PATCH=patch-${PV}.xz
SRC_URI="https://www.kernel.org/pub/linux/kernel/v${LINUX_V}/${LINUX_PATCH}"
LINUX_SOURCES="linux-${LINUX_VER}.tar.xz"
SRC_URI+=" https://www.kernel.org/pub/linux/kernel/v${LINUX_V}/${LINUX_SOURCES}"
S_K="${WORKDIR}/linux-${LINUX_VER}"
S="${S_K}/tools/bpf/bpftool"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64 arm arm64 ~loong ppc ppc64 ~riscv x86"
IUSE="caps +llvm"
RDEPEND="
sys-libs/binutils-libs:=
sys-libs/zlib:=
virtual/libelf:=
caps? ( sys-libs/libcap:= )
llvm? ( llvm-core/llvm:= )
"
DEPEND="
${RDEPEND}
>=sys-kernel/linux-headers-5.8
"
BDEPEND="
${LINUX_PATCH+dev-util/patchutils}
${PYTHON_DEPS}
app-arch/tar
dev-python/docutils
"
CONFIG_CHECK="~DEBUG_INFO_BTF"
# src_unpack and src_prepare are copied from dev-util/perf since
# it's building from the same tarball, please keep it in sync with perf
src_unpack() {
local paths=(
kernel/bpf tools/{arch,bpf,build,include,lib,perf,scripts}
scripts include lib "arch/*/include" "arch/*/lib" "arch/*/tools"
)
# We expect the tar implementation to support the -j and --wildcards option
echo ">>> Unpacking ${LINUX_SOURCES} (${paths[*]}) to ${PWD}"
gtar --wildcards -xpf "${DISTDIR}"/${LINUX_SOURCES} \
"${paths[@]/#/linux-${LINUX_VER}/}" || die
if [[ -n ${LINUX_PATCH} ]] ; then
eshopts_push -o noglob
ebegin "Filtering partial source patch"
filterdiff -p1 ${paths[@]/#/-i } -z "${DISTDIR}"/${LINUX_PATCH} \
> ${P}.patch
eend $? || die "filterdiff failed"
eshopts_pop
fi
local a
for a in ${A}; do
[[ ${a} == ${LINUX_SOURCES} ]] && continue
[[ ${a} == ${LINUX_PATCH} ]] && continue
unpack ${a}
done
}
src_prepare() {
default
if [[ -n ${LINUX_PATCH} ]] ; then
pushd "${S_K}" >/dev/null || die
eapply "${WORKDIR}"/${P}.patch
popd || die
fi
# Use rst2man or rst2man.py depending on which one exists (#930076)
type -P rst2man >/dev/null || sed -i -e 's/rst2man/rst2man.py/g' Documentation/Makefile || die
# remove -Werror (bug 887981)
sed -i -e 's/\-Werror//g' ../../lib/bpf/Makefile || die
}
bpftool_make() {
local arch=$(tc-arch-kernel)
tc-export AR CC LD
emake V=1 VF=1 \
HOSTCC="$(tc-getBUILD_CC)" HOSTLD="$(tc-getBUILD_LD)" \
EXTRA_CFLAGS="${CFLAGS}" ARCH="${arch}" BPFTOOL_VERSION="${MY_PV}" \
prefix="${EPREFIX}"/usr \
bash_compdir="$(get_bashcompdir)" \
feature-libcap="$(usex caps 1 0)" \
feature-llvm="$(usex llvm 1 0)" \
"$@"
}
src_compile() {
bpftool_make
bpftool_make -C Documentation
}
src_install() {
bpftool_make DESTDIR="${D}" install
bpftool_make mandir="${ED}"/usr/share/man -C Documentation install
}
pkg_postinst() {
optfeature "clang-bpf-co-re support" llvm-core/clang[llvm_targets_BPF]
}

View File

@ -1,130 +0,0 @@
# Copyright 2021-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
LLVM_COMPAT=( {15..19} )
LLVM_OPTIONAL=1
PYTHON_COMPAT=( python3_{10..13} )
inherit bash-completion-r1 linux-info llvm-r1 python-any-r1 toolchain-funcs
DESCRIPTION="Tool for inspection and simple manipulation of eBPF programs and maps"
HOMEPAGE="https://github.com/libbpf/bpftool"
if [[ ${PV} == *9999* ]] ; then
inherit git-r3
EGIT_REPO_URI="https://github.com/libbpf/bpftool.git"
EGIT_SUBMODULES=(libbpf)
else
# bpftool typically vendors whatever libbpf is current at the time
# of a release, while libbpf publishes minor updates more frequently.
# Uncomment the following to bundle an updated libbpf e.g. in case of
# security or crasher bugs in libbpf and to keep the two synchronized.
# This allows us to quickly update the vendored lib with a revbump.
# Currently bpftool-x.y vendors libbpf-1.y; DO NOT mix different y versions.
# See the libbpf repo (https://github.com/libbpf/libbpf) for possible updates.
LIBBPF_VERSION=1.4.7
if [[ ! -z ${LIBBPF_VERSION} ]] ; then
SRC_URI="https://github.com/libbpf/bpftool/archive/refs/tags/v${PV}.tar.gz -> bpftool-${PV}.tar.gz
https://github.com/libbpf/libbpf/archive/refs/tags/v${LIBBPF_VERSION}.tar.gz
-> libbpf-${LIBBPF_VERSION}.tar.gz"
else
# use tarball with bundled libbpf
SRC_URI="https://github.com/libbpf/bpftool/releases/download/v${PV}/bpftool-libbpf-v${PV}-sources.tar.gz"
S="${WORKDIR}/bpftool-libbpf-v${PV}-sources"
fi
KEYWORDS="amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~x86"
fi
LICENSE="|| ( GPL-2 BSD-2 )"
SLOT="0"
IUSE="caps llvm"
REQUIRED_USE="llvm? ( ${LLVM_REQUIRED_USE} )"
RDEPEND="
caps? ( sys-libs/libcap:= )
llvm? ( $(llvm_gen_dep 'llvm-core/llvm:${LLVM_SLOT}') )
!llvm? ( sys-libs/binutils-libs:= )
sys-libs/zlib:=
virtual/libelf:=
"
DEPEND="
${RDEPEND}
>=sys-kernel/linux-headers-5.8
"
BDEPEND="
${PYTHON_DEPS}
app-arch/tar
dev-python/docutils
$(llvm_gen_dep 'llvm-core/clang:${LLVM_SLOT}[llvm_targets_BPF]')
"
CONFIG_CHECK="~DEBUG_INFO_BTF"
PATCHES=(
"${FILESDIR}"/7.4-001-mount-bpffs-on-provided-dir-instead-of-parent-dir.patch
"${FILESDIR}"/7.4-002-set-DESTDIR-to-empty-when-building-libbpf.patch
"${FILESDIR}"/7.4-003-fix-typo-in-usage-help.patch
"${FILESDIR}"/7.4-004-fix-the-wrong-format-specifier.patch
"${FILESDIR}"/7.4-005-fix-undefined-behavior-caused-by-shifting-into-the-sign-bit.patch
"${FILESDIR}"/7.4-006-fix-undefined-behavior-in-qsort.patch
"${FILESDIR}"/7.4-007-define-PACKAGE-at-build-time-when-trying-to-detect-libbfd.patch
"${FILESDIR}"/7.4-008-always-disable-unused-CLI-arguments-warning-for-feature-probe.patch
)
pkg_setup() {
python-any-r1_pkg_setup
use llvm && llvm-r1_pkg_setup
}
src_prepare() {
default
# prepare libbpf if necessary
if [[ ! -z ${LIBBPF_VERSION} ]] ; then
rm -rf libbpf || die
ln -s "${WORKDIR}/libbpf-${LIBBPF_VERSION}" libbpf || die
fi
# remove -Werror from libbpf (bug 887981)
sed -i -e 's/\-Werror//g' libbpf/src/Makefile || die
# remove -Werror from bpftool feature detection
sed -i -e 's/-Werror//g' src/Makefile.feature || die
# remove hardcoded/unhelpful flags from bpftool
sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die
# Use rst2man or rst2man.py depending on which one exists (#930076)
type -P rst2man >/dev/null || sed -i -e 's/rst2man/rst2man.py/g' docs/Makefile || die
}
bpftool_make() {
tc-export AR CC LD
emake \
ARCH="$(tc-arch-kernel)" \
CLANG="$(get_llvm_prefix -b)/bin/clang" \
HOSTAR="$(tc-getBUILD_AR)" \
HOSTCC="$(tc-getBUILD_CC)" \
HOSTLD="$(tc-getBUILD_LD)" \
bash_compdir="$(get_bashcompdir)" \
feature-libcap="$(usex caps 1 0)" \
feature-llvm="$(usex llvm 1 0)" \
prefix="${EPREFIX}"/usr \
V=1 \
"$@"
}
src_compile() {
bpftool_make -C src
bpftool_make -C docs
}
src_install() {
bpftool_make DESTDIR="${D}" -C src install
bpftool_make mandir="${ED}"/usr/share/man -C docs install
}

View File

@ -5,7 +5,7 @@ EAPI=8
LLVM_COMPAT=( {15..20} ) LLVM_COMPAT=( {15..20} )
LLVM_OPTIONAL=1 LLVM_OPTIONAL=1
PYTHON_COMPAT=( python3_{10..13} ) PYTHON_COMPAT=( python3_{11..13} )
inherit bash-completion-r1 linux-info llvm-r1 python-any-r1 toolchain-funcs inherit bash-completion-r1 linux-info llvm-r1 python-any-r1 toolchain-funcs
@ -65,6 +65,8 @@ BDEPEND="
CONFIG_CHECK="~DEBUG_INFO_BTF" CONFIG_CHECK="~DEBUG_INFO_BTF"
PATCHES=( "${FILESDIR}/7.5.0-setting-error-code-in-do_loader.patch" )
pkg_setup() { pkg_setup() {
python-any-r1_pkg_setup python-any-r1_pkg_setup
use llvm && llvm-r1_pkg_setup use llvm && llvm-r1_pkg_setup
@ -88,7 +90,20 @@ src_prepare() {
# remove hardcoded/unhelpful flags from bpftool # remove hardcoded/unhelpful flags from bpftool
sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die
# always build bpf bits with std=gnu11 for kernel compatibility (bug 955156)
sed -i 's/-fno-stack-protector/& -std=gnu11/g' src/Makefile || die
if ! use clang; then if ! use clang; then
# make people aware of what they are doing
ewarn "Using bpf-toolchain instead of clang due to USE=-clang."
ewarn "Please report any odd behaviours you observe, since using gcc for BPF"
ewarn "is still under development in both the Linux kernel and gcc itself."
# prevent attribute warning about preserve_access_index
# since gcc does not support '#pragma clang attribute push':
# https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=675b4e2
sed -i 's/std=gnu11/& -DBPF_NO_PRESERVE_ACCESS_INDEX/g' src/Makefile || die
# remove bpf target & add assembly annotations to fix CO-RE feature detection # remove bpf target & add assembly annotations to fix CO-RE feature detection
sed -i -e 's/-target bpf/-dA/' src/Makefile.feature || die sed -i -e 's/-target bpf/-dA/' src/Makefile.feature || die

View File

@ -1,11 +1,11 @@
# Copyright 2021-2024 Gentoo Authors # Copyright 2021-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
EAPI=8 EAPI=8
LLVM_COMPAT=( {15..20} ) LLVM_COMPAT=( {15..20} )
LLVM_OPTIONAL=1 LLVM_OPTIONAL=1
PYTHON_COMPAT=( python3_{10..13} ) PYTHON_COMPAT=( python3_{11..13} )
inherit bash-completion-r1 linux-info llvm-r1 python-any-r1 toolchain-funcs inherit bash-completion-r1 linux-info llvm-r1 python-any-r1 toolchain-funcs
@ -88,7 +88,20 @@ src_prepare() {
# remove hardcoded/unhelpful flags from bpftool # remove hardcoded/unhelpful flags from bpftool
sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die
# always build bpf bits with std=gnu11 for kernel compatibility (bug 955156)
sed -i 's/-fno-stack-protector/& -std=gnu11/g' src/Makefile || die
if ! use clang; then if ! use clang; then
# make people aware of what they are doing
ewarn "Using bpf-toolchain instead of clang due to USE=-clang."
ewarn "Please report any odd behaviours you observe, since using gcc for BPF"
ewarn "is still under development in both the Linux kernel and gcc itself."
# prevent attribute warning about preserve_access_index
# since gcc does not support '#pragma clang attribute push':
# https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=675b4e2
sed -i 's/std=gnu11/& -DBPF_NO_PRESERVE_ACCESS_INDEX/g' src/Makefile || die
# remove bpf target & add assembly annotations to fix CO-RE feature detection # remove bpf target & add assembly annotations to fix CO-RE feature detection
sed -i -e 's/-target bpf/-dA/' src/Makefile.feature || die sed -i -e 's/-target bpf/-dA/' src/Makefile.feature || die

View File

@ -1,255 +0,0 @@
From 54bcb7c7fecb33d40266223d4bba49ad38e59ee3 Mon Sep 17 00:00:00 2001
From: Sahil Siddiq <icegambit91@gmail.com>
Date: Fri, 5 Apr 2024 00:52:19 +0530
Subject: [PATCH] bpftool: Mount bpffs on provided dir instead of parent dir
When pinning programs/objects under PATH (eg: during "bpftool prog
loadall") the bpffs is mounted on the parent dir of PATH in the
following situations:
- the given dir exists but it is not bpffs.
- the given dir doesn't exist and the parent dir is not bpffs.
Mounting on the parent dir can also have the unintentional side-
effect of hiding other files located under the parent dir.
If the given dir exists but is not bpffs, then the bpffs should
be mounted on the given dir and not its parent dir.
Similarly, if the given dir doesn't exist and its parent dir is not
bpffs, then the given dir should be created and the bpffs should be
mounted on this new dir.
Fixes: 2a36c26fe3b8 ("bpftool: Support bpffs mountpoint as pin path for prog loadall")
Signed-off-by: Sahil Siddiq <icegambit91@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/2da44d24-74ae-a564-1764-afccf395eeec@isovalent.com/T/#t
Link: https://lore.kernel.org/bpf/20240404192219.52373-1-icegambit91@gmail.com
Closes: https://github.com/libbpf/bpftool/issues/100
Changes since v1:
- Split "mount_bpffs_for_pin" into two functions.
This is done to improve maintainability and readability.
Changes since v2:
- mount_bpffs_for_pin: rename to "create_and_mount_bpffs_dir".
- mount_bpffs_given_file: rename to "mount_bpffs_given_file".
- create_and_mount_bpffs_dir:
- introduce "dir_exists" boolean.
- remove new dir if "mnt_fs" fails.
- improve error handling and error messages.
Changes since v3:
- Rectify function name.
- Improve error messages and formatting.
- mount_bpffs_for_file:
- Check if dir exists before block_mount check.
Changes since v4:
- Use strdup instead of strcpy.
- create_and_mount_bpffs_dir:
- Use S_IRWXU instead of 0700.
- Improve error handling and formatting.
---
src/common.c | 96 ++++++++++++++++++++++++++++++++++++++++++------
src/iter.c | 2 +-
src/main.h | 3 +-
src/prog.c | 5 ++-
src/struct_ops.c | 2 +-
5 files changed, 92 insertions(+), 16 deletions(-)
diff --git a/src/common.c b/src/common.c
index cc6e6aae..958e92ac 100644
--- a/src/common.c
+++ b/src/common.c
@@ -244,29 +244,101 @@ int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type)
return fd;
}
-int mount_bpffs_for_pin(const char *name, bool is_dir)
+int create_and_mount_bpffs_dir(const char *dir_name)
{
char err_str[ERR_MAX_LEN];
- char *file;
- char *dir;
+ bool dir_exists;
int err = 0;
- if (is_dir && is_bpffs(name))
+ if (is_bpffs(dir_name))
return err;
- file = malloc(strlen(name) + 1);
- if (!file) {
+ dir_exists = access(dir_name, F_OK) == 0;
+
+ if (!dir_exists) {
+ char *temp_name;
+ char *parent_name;
+
+ temp_name = strdup(dir_name);
+ if (!temp_name) {
+ p_err("mem alloc failed");
+ return -1;
+ }
+
+ parent_name = dirname(temp_name);
+
+ if (is_bpffs(parent_name)) {
+ /* nothing to do if already mounted */
+ free(temp_name);
+ return err;
+ }
+
+ if (access(parent_name, F_OK) == -1) {
+ p_err("can't create dir '%s' to pin BPF object: parent dir '%s' doesn't exist",
+ dir_name, parent_name);
+ free(temp_name);
+ return -1;
+ }
+
+ free(temp_name);
+ }
+
+ if (block_mount) {
+ p_err("no BPF file system found, not mounting it due to --nomount option");
+ return -1;
+ }
+
+ if (!dir_exists) {
+ err = mkdir(dir_name, S_IRWXU);
+ if (err) {
+ p_err("failed to create dir '%s': %s", dir_name, strerror(errno));
+ return err;
+ }
+ }
+
+ err = mnt_fs(dir_name, "bpf", err_str, ERR_MAX_LEN);
+ if (err) {
+ err_str[ERR_MAX_LEN - 1] = '\0';
+ p_err("can't mount BPF file system on given dir '%s': %s",
+ dir_name, err_str);
+
+ if (!dir_exists)
+ rmdir(dir_name);
+ }
+
+ return err;
+}
+
+int mount_bpffs_for_file(const char *file_name)
+{
+ char err_str[ERR_MAX_LEN];
+ char *temp_name;
+ char *dir;
+ int err = 0;
+
+ if (access(file_name, F_OK) != -1) {
+ p_err("can't pin BPF object: path '%s' already exists", file_name);
+ return -1;
+ }
+
+ temp_name = strdup(file_name);
+ if (!temp_name) {
p_err("mem alloc failed");
return -1;
}
- strcpy(file, name);
- dir = dirname(file);
+ dir = dirname(temp_name);
if (is_bpffs(dir))
/* nothing to do if already mounted */
goto out_free;
+ if (access(dir, F_OK) == -1) {
+ p_err("can't pin BPF object: dir '%s' doesn't exist", dir);
+ err = -1;
+ goto out_free;
+ }
+
if (block_mount) {
p_err("no BPF file system found, not mounting it due to --nomount option");
err = -1;
@@ -276,12 +348,12 @@ int mount_bpffs_for_pin(const char *name, bool is_dir)
err = mnt_fs(dir, "bpf", err_str, ERR_MAX_LEN);
if (err) {
err_str[ERR_MAX_LEN - 1] = '\0';
- p_err("can't mount BPF file system to pin the object (%s): %s",
- name, err_str);
+ p_err("can't mount BPF file system to pin the object '%s': %s",
+ file_name, err_str);
}
out_free:
- free(file);
+ free(temp_name);
return err;
}
@@ -289,7 +361,7 @@ int do_pin_fd(int fd, const char *name)
{
int err;
- err = mount_bpffs_for_pin(name, false);
+ err = mount_bpffs_for_file(name);
if (err)
return err;
diff --git a/src/iter.c b/src/iter.c
index 6b0e5202..5c39c2ed 100644
--- a/src/iter.c
+++ b/src/iter.c
@@ -76,7 +76,7 @@ static int do_pin(int argc, char **argv)
goto close_obj;
}
- err = mount_bpffs_for_pin(path, false);
+ err = mount_bpffs_for_file(path);
if (err)
goto close_link;
diff --git a/src/main.h b/src/main.h
index b8bb08d1..9eb764fe 100644
--- a/src/main.h
+++ b/src/main.h
@@ -142,7 +142,8 @@ const char *get_fd_type_name(enum bpf_obj_type type);
char *get_fdinfo(int fd, const char *key);
int open_obj_pinned(const char *path, bool quiet);
int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type);
-int mount_bpffs_for_pin(const char *name, bool is_dir);
+int mount_bpffs_for_file(const char *file_name);
+int create_and_mount_bpffs_dir(const char *dir_name);
int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(int *, char ***));
int do_pin_fd(int fd, const char *name);
diff --git a/src/prog.c b/src/prog.c
index 9cb42a33..4c4cf16a 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -1778,7 +1778,10 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
goto err_close_obj;
}
- err = mount_bpffs_for_pin(pinfile, !first_prog_only);
+ if (first_prog_only)
+ err = mount_bpffs_for_file(pinfile);
+ else
+ err = create_and_mount_bpffs_dir(pinfile);
if (err)
goto err_close_obj;
diff --git a/src/struct_ops.c b/src/struct_ops.c
index d573f264..aa43dead 100644
--- a/src/struct_ops.c
+++ b/src/struct_ops.c
@@ -515,7 +515,7 @@ static int do_register(int argc, char **argv)
if (argc == 1)
linkdir = GET_ARG();
- if (linkdir && mount_bpffs_for_pin(linkdir, true)) {
+ if (linkdir && create_and_mount_bpffs_dir(linkdir)) {
p_err("can't mount bpffs for pinning");
return -1;
}

View File

@ -1,38 +0,0 @@
From 06c61eccd3b8a6ff3df3e451a2a93058913124fc Mon Sep 17 00:00:00 2001
From: jinzhiguang <jinzhiguang@kylinos.cn>
Date: Sun, 7 Apr 2024 16:54:33 +0800
Subject: [PATCH] mirror: Set DESTDIR to empty when building libbpf
If a value is assigned to the variable DESTDIR when compiling bpftool,
this variable will be passed to libbpf's Makefile.
In this case, libbpf's header files will be installed in an unexpected
directory, causing bpftool to be unable to find the header files.
Signed-off-by: jinzhiguang <jinzhiguang@kylinos.cn>
---
src/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Makefile b/src/Makefile
index a3bc6a0..d48d22f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -42,7 +42,7 @@ $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DI
$(LIBBPF): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_OUTPUT)
$(Q)$(MAKE) -C $(BPF_DIR) OBJDIR=$(patsubst %/,%,$(LIBBPF_OUTPUT)) \
- PREFIX=$(LIBBPF_DESTDIR:/=) $(LIBBPF) install_headers
+ DESTDIR="" PREFIX=$(LIBBPF_DESTDIR:/=) $(LIBBPF) install_headers
$(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_HDRS_DIR)
$(call QUIET_INSTALL, $@)
@@ -50,7 +50,7 @@ $(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_HDRS_
$(LIBBPF_BOOTSTRAP): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_BOOTSTRAP_OUTPUT)
$(Q)$(MAKE) -C $(BPF_DIR) OBJDIR=$(patsubst %/,%,$(LIBBPF_BOOTSTRAP_OUTPUT)) \
- PREFIX=$(LIBBPF_BOOTSTRAP_DESTDIR:/=) \
+ DESTDIR="" PREFIX=$(LIBBPF_BOOTSTRAP_DESTDIR:/=) \
ARCH= CROSS_COMPILE= CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" $@ install_headers
$(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BOOTSTRAP_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_BOOTSTRAP_HDRS_DIR)

View File

@ -1,30 +0,0 @@
From a44a93bb7ed0d8e62220b534df92ea2a678fb4b7 Mon Sep 17 00:00:00 2001
From: Donald Hunter <donald.hunter@gmail.com>
Date: Wed, 17 Jul 2024 14:45:08 +0100
Subject: [PATCH] bpftool: Fix typo in usage help
The usage help for "bpftool prog help" contains a ° instead of the _
symbol for cgroup/sendmsg_unix. Fix the typo.
Fixes: 8b3cba987e6d ("bpftool: Add support for cgroup unix socket address hooks")
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240717134508.77488-1-donald.hunter@gmail.com
---
src/prog.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/prog.c b/src/prog.c
index 40ea743..2ff949e 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -2489,7 +2489,7 @@ static int do_help(int argc, char **argv)
" cgroup/connect_unix | cgroup/getpeername4 | cgroup/getpeername6 |\n"
" cgroup/getpeername_unix | cgroup/getsockname4 | cgroup/getsockname6 |\n"
" cgroup/getsockname_unix | cgroup/sendmsg4 | cgroup/sendmsg6 |\n"
- " cgroup/sendmsg°unix | cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/recvmsg_unix |\n"
+ " cgroup/sendmsg_unix | cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/recvmsg_unix |\n"
" cgroup/getsockopt | cgroup/setsockopt | cgroup/sock_release |\n"
" struct_ops | fentry | fexit | freplace | sk_lookup }\n"
" ATTACH_TYPE := { sk_msg_verdict | sk_skb_verdict | sk_skb_stream_verdict |\n"

View File

@ -1,38 +0,0 @@
From cb035aad23cf92254d8d3c7631e5b642e6805bd1 Mon Sep 17 00:00:00 2001
From: Zhu Jun <zhujun2@cmss.chinamobile.com>
Date: Wed, 24 Jul 2024 04:11:20 -0700
Subject: [PATCH] tools/bpf: Fix the wrong format specifier
The format specifier of "unsigned int" in printf() should be "%u", not
"%d".
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240724111120.11625-1-zhujun2@cmss.chinamobile.com
---
src/xlated_dumper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/xlated_dumper.c b/src/xlated_dumper.c
index 567f56d..d009434 100644
--- a/src/xlated_dumper.c
+++ b/src/xlated_dumper.c
@@ -349,7 +349,7 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len,
double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW);
- printf("% 4d: ", i);
+ printf("%4u: ", i);
print_bpf_insn(&cbs, insn + i, true);
if (opcodes) {
@@ -415,7 +415,7 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end,
}
}
- printf("%d: ", insn_off);
+ printf("%u: ", insn_off);
print_bpf_insn(&cbs, cur, true);
if (opcodes) {

View File

@ -1,47 +0,0 @@
From a0f887bbdc525006f7662f4a83e240f2c46d3418 Mon Sep 17 00:00:00 2001
From: Kuan-Wei Chiu <visitorckw@gmail.com>
Date: Sun, 8 Sep 2024 22:00:09 +0800
Subject: [PATCH] bpftool: Fix undefined behavior caused by shifting into the sign bit
Replace shifts of '1' with '1U' in bitwise operations within
__show_dev_tc_bpf() to prevent undefined behavior caused by shifting
into the sign bit of a signed integer. By using '1U', the operations
are explicitly performed on unsigned integers, avoiding potential
integer overflow or sign-related issues.
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240908140009.3149781-1-visitorckw@gmail.com
---
src/net.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/net.c b/src/net.c
index 2a51f1c..3c50fc6 100644
--- a/src/net.c
+++ b/src/net.c
@@ -486,9 +486,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev,
if (prog_flags[i] || json_output) {
NET_START_ARRAY("prog_flags", "%s ");
for (j = 0; prog_flags[i] && j < 32; j++) {
- if (!(prog_flags[i] & (1 << j)))
+ if (!(prog_flags[i] & (1U << j)))
continue;
- NET_DUMP_UINT_ONLY(1 << j);
+ NET_DUMP_UINT_ONLY(1U << j);
}
NET_END_ARRAY("");
}
@@ -497,9 +497,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev,
if (link_flags[i] || json_output) {
NET_START_ARRAY("link_flags", "%s ");
for (j = 0; link_flags[i] && j < 32; j++) {
- if (!(link_flags[i] & (1 << j)))
+ if (!(link_flags[i] & (1U << j)))
continue;
- NET_DUMP_UINT_ONLY(1 << j);
+ NET_DUMP_UINT_ONLY(1U << j);
}
NET_END_ARRAY("");
}

View File

@ -1,49 +0,0 @@
From 37e304df400c69347189449b38864705cc88b987 Mon Sep 17 00:00:00 2001
From: Kuan-Wei Chiu <visitorckw@gmail.com>
Date: Tue, 10 Sep 2024 23:02:07 +0800
Subject: [PATCH] bpftool: Fix undefined behavior in qsort(NULL, 0, ...)
When netfilter has no entry to display, qsort is called with
qsort(NULL, 0, ...). This results in undefined behavior, as UBSan
reports:
net.c:827:2: runtime error: null pointer passed as argument 1, which is declared to never be null
Although the C standard does not explicitly state whether calling qsort
with a NULL pointer when the size is 0 constitutes undefined behavior,
Section 7.1.4 of the C standard (Use of library functions) mentions:
"Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow: If an argument to a
function has an invalid value (such as a value outside the domain of
the function, or a pointer outside the address space of the program, or
a null pointer, or a pointer to non-modifiable storage when the
corresponding parameter is not const-qualified) or a type (after
promotion) not expected by a function with variable number of
arguments, the behavior is undefined."
To avoid this, add an early return when nf_link_info is NULL to prevent
calling qsort with a NULL pointer.
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240910150207.3179306-1-visitorckw@gmail.com
---
src/net.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/net.c b/src/net.c
index 3c50fc6..d2242d9 100644
--- a/src/net.c
+++ b/src/net.c
@@ -880,6 +880,9 @@ static void show_link_netfilter(void)
nf_link_count++;
}
+ if (!nf_link_info)
+ return;
+
qsort(nf_link_info, nf_link_count, sizeof(*nf_link_info), netfilter_link_compar);
for (id = 0; id < nf_link_count; id++) {

View File

@ -1,48 +0,0 @@
From bf9e0609acb97d73a7ebf3e8910b0119cd943dfb Mon Sep 17 00:00:00 2001
From: Quentin Monnet <qmo@kernel.org>
Date: Mon, 14 Oct 2024 17:43:25 +0100
Subject: [PATCH] mirror: Define PACKAGE at build time when trying to detect libbfd
Feature detection from the Makefile.feature for libbfd (with the
different variants of the probe) may fail on some systems where the
bfd.h and dis-asm.h headers expect the PACKAGE or PACKAGE_VERSION macros
to be defined [0]. In the kernel tree, feature detection addresses it by
defining the PACKAGE macro when invoking the compiler [1]. Add a similar
definition for the mirror repository.
Note that this issue has remained undetected for a while. This is
because the bfd.h included in some distributions (Debian/Ubuntu, for
example) does not contain the inclusion guard [2].
[0] https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/bfd-in.h;h=04e65aad5f0c235a5013513c545e57a01e96541f;hb=binutils-2_43_1#l27
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/build/feature/Makefile?h=v6.11#n114
[2] https://git.launchpad.net/ubuntu/+source/binutils/tree/debian/rules?h=applied/2.43.1-5#n1031
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: Quentin Monnet <qmo@kernel.org>
---
src/Makefile.feature | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Makefile.feature b/src/Makefile.feature
index 131c67e..90f9e7c 100644
--- a/src/Makefile.feature
+++ b/src/Makefile.feature
@@ -45,7 +45,7 @@ LIBBFD_PROBE += ' bfd_demangle(0, 0, 0);'
LIBBFD_PROBE += ' return 0;'
LIBBFD_PROBE += '}'
LIBBFD_PROBE_CMD = printf '%b\n' $(LIBBFD_PROBE) | \
- $(CC) $(CFLAGS) -Wall -Werror -x c - $(1) -o /dev/null >/dev/null
+ $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - $(1) -o /dev/null >/dev/null
define libbfd_build
$(call detect,$(LIBBFD_PROBE_CMD))
@@ -78,7 +78,7 @@ DISASSEMBLER_PROBE += ' return 0;'
DISASSEMBLER_PROBE += '}'
DISASSEMBLER_PROBE_CMD = printf '%b\n' $(1) | \
- $(CC) $(CFLAGS) -Wall -Werror -x c - -lbfd -lopcodes -S -o - >/dev/null
+ $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - -lbfd -lopcodes -S -o - >/dev/null
define disassembler_build
$(call detect,$(DISASSEMBLER_PROBE_CMD))
endef

View File

@ -1,38 +0,0 @@
From 3be8ac358900c5f57028b2b6501407a14167a9bb Mon Sep 17 00:00:00 2001
From: Quentin Monnet <qmo@kernel.org>
Date: Thu, 17 Oct 2024 11:22:14 +0100
Subject: [PATCH] mirror: Always disable unused CLI arguments warning for feature probe
In commit 8a2d7d510ccd ("mirror: Fix features detection for building
with clang") we prevented clang to error out when encountering unused
command-line arguments in the feature probes, because we do add unused
arguments for some of the probes when retrieving arguments from
llvm-config, and we don't want probes to fail because of that.
At the time, the issue was apparent for the LLVM-based disassembler, so
we added -Wno-unused-command-line-argument when $(LLVM) was enabled,
only. We missed the case when we're building bpftool with clang instead
of gcc, without building the LLVM disassembler. Let's disable the
warning unconditionally instead to fix this case.
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: Quentin Monnet <qmo@kernel.org>
---
src/Makefile.feature | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/Makefile.feature b/src/Makefile.feature
index 90f9e7c..b08e7b9 100644
--- a/src/Makefile.feature
+++ b/src/Makefile.feature
@@ -4,9 +4,7 @@ pound := \#
CFLAGS_BACKUP := $(CFLAGS)
CFLAGS := $(EXTRA_CFLAGS)
-ifneq ($(LLVM),)
- CFLAGS += -Wno-unused-command-line-argument
-endif
+CFLAGS += -Wno-unused-command-line-argument
ifeq ($(V),1)
LOG=$(warning $(1))

View File

@ -0,0 +1,45 @@
Patch from: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=02a4694107b4c830d4bd6d194e98b3ac0bc86f29
Adapted patch prefix to match the GH mirror sources.
From 91588da58ed38e4ec870d479ab2d9467288893d2 Mon Sep 17 00:00:00 2001
From: Sasha Levin <sashal@kernel.org>
Date: Tue, 11 Mar 2025 12:12:37 +0900
Subject: bpf: bpftool: Setting error code in do_loader()
From: Sewon Nam <swnam0729@gmail.com>
[ Upstream commit 02a4694107b4c830d4bd6d194e98b3ac0bc86f29 ]
We are missing setting error code in do_loader() when
bpf_object__open_file() fails. This means the command's exit status code
will be successful, even though the operation failed. So make sure to
return the correct error code. To maintain consistency with other
locations where bpf_object__open_file() is called, return -1.
[0] Closes: https://github.com/libbpf/bpftool/issues/156
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Sewon Nam <swnam0729@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Quentin Monnet <qmo@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/d3b5b4b4-19bb-4619-b4dd-86c958c4a367@stanley.mountain/t/#u
Link: https://lore.kernel.org/bpf/20250311031238.14865-1-swnam0729@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/bpf/bpftool/prog.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index e71be67f1d865..52ffb74ae4e89 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -1928,6 +1928,7 @@ static int do_loader(int argc, char **argv)
obj = bpf_object__open_file(file, &open_opts);
if (!obj) {
+ err = -1;
p_err("failed to open object file");
goto err_close_obj;
}