Skip to content

Commit

Permalink
build-bpf-gcc: use foldable helper function for logging
Browse files Browse the repository at this point in the history
Also:
  * update relevant temp patches in ci/diffs
  * update DENYLIST.test_progs-bpf_gcc
  • Loading branch information
theihor committed Jan 8, 2025
1 parent 0d4971a commit 6f035d7
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 1,090 deletions.
6 changes: 1 addition & 5 deletions build-bpf-gcc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ runs:

- if: steps.cache.outputs.cache-hit != 'true'
name: Build BPF GCC
env:
LOGFILE: /tmp/build-bpf-gcc.log
shell: bash
run: |
${GITHUB_ACTION_PATH}/build-and-install.sh ${{ inputs.install-dir }} \
|| { cat $LOGFILE; exit 1; }
${GITHUB_ACTION_PATH}/build-and-install.sh ${{ inputs.install-dir }}
58 changes: 31 additions & 27 deletions build-bpf-gcc/build-and-install.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
#!/bin/bash
set -euo pipefail

source $(cd $(dirname $0) && pwd)/helpers.sh

INSTALLDIR=$(realpath $1)
LOGFILE=${LOGFILE:-build-bpf-gcc.log}

source ${GITHUB_ACTION_PATH}/.env
if [ -f ${GITHUB_ACTION_PATH}/.env ]; then
source ${GITHUB_ACTION_PATH}/.env
else
echo "${GITHUB_ACTION_PATH}/.env is not found, supposed to be produced by latest-snapshots.sh"
exit 1
fi

test -f $BINUTILS_TARBALL || {
echo -n "Fetching $BINUTILS_URL... ";
wget -o /dev/null $BINUTILS_URL || { echo -e "\nerror: could not fetch $BINUTILS_URL"; exit 1; };
echo done;
}
test -f $BINUTILS_TARBALL || wget $BINUTILS_URL
test -f $GCC_TARBALL || wget $GCC_URL

test -f $GCC_TARBALL || {
echo -n "Fetching $GCC_URL... ";
wget -o /dev/null $GCC_URL || { echo -e "\nerror: could not fetch $GCC_URL"; exit 1; };
echo done;
}
foldable start build_binutils "Building $BINUTILS_BASENAME"

if [ ! -f "${INSTALLDIR}/${BINUTILS_BASENAME}.built" ]; then
echo -n "Building and installing $BINUTILS_BASENAME... ";
(tar xJf $BINUTILS_TARBALL;
cd ${BINUTILS_BASENAME};
mkdir build-bpf;
cd build-bpf && ../configure --target=bpf-unknown-none --prefix=$INSTALLDIR && make -j $(nproc) && make install && touch ${INSTALLDIR}/${BINUTILS_BASENAME}.built;
) 2>&1 | tee -a $LOGFILE || { echo -e "\nerror: building $BINUTILS_TARBALL"; exit 1; }
echo done
tar xJf $BINUTILS_TARBALL
mkdir -p ${BINUTILS_BASENAME}/build-bpf
cd ${BINUTILS_BASENAME}/build-bpf
../configure --target=bpf-unknown-none --prefix=$INSTALLDIR
make -j$(nproc) && make install
touch ${INSTALLDIR}/${BINUTILS_BASENAME}.built
fi

foldable end build_binutils "Building $BINUTILS_BASENAME"

foldable start build_gcc "Building $GCC_BASENAME"

if [ ! -f "${INSTALLDIR}/${GCC_BASENAME}.built" ]; then
echo -n "Building and installing $GCC_BASENAME... ";
(tar xJf $GCC_TARBALL;
cd ${GCC_BASENAME};
./contrib/download_prerequisites
mkdir build-bpf;
cd build-bpf && ../configure --target=bpf-unknown-none --prefix=$INSTALLDIR && make -j $(nproc) && make install && touch ${INSTALLDIR}/${GCC_BASENAME}.built;
) 2>&1 | tee -a $LOGFILE || { echo -e "\nerror: building $GCC_TARBALL"; exit 1; }
echo done
tar xJf $GCC_TARBALL
cd ${GCC_BASENAME}
./contrib/download_prerequisites
mkdir build-bpf
cd build-bpf
../configure --target=bpf-unknown-none --prefix=$INSTALLDIR
make -j $(nproc) && make install
touch ${INSTALLDIR}/${GCC_BASENAME}.built
fi

foldable end build_gcc "Building $GCC_BASENAME"

exit 0
40 changes: 0 additions & 40 deletions ci/diffs/0599-selftests-bpf-GCC-BPF-build.patch

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 60e8f5f5f5f581d7f168dd63ca08b5753856ac04 Mon Sep 17 00:00:00 2001
From: Ihor Solodrai <[email protected]>
Date: Mon, 6 Jan 2025 20:27:18 +0000
Subject: [PATCH] selftests/bpf: add -std=gnu11 to BPF_CFLAGS and CFLAGS

Latest versions of GCC BPF use C23 standard by default. This causes
compilation errors in vmlinux.h due to bool types declarations.

Add -std=gnu11 to BPF_CFLAGS and CFLAGS. This aligns with the version
of the standard used when building the kernel currently [1].

For more details see the discussions at [2] and [3].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile#n465
[2] https://lore.kernel.org/bpf/EYcXjcKDCJY7Yb0GGtAAb7nLKPEvrgWdvWpuNzXm2qi6rYMZDixKv5KwfVVMBq17V55xyC-A1wIjrqG3aw-Imqudo9q9X7D7nLU2gWgbN0w=@pm.me/
[3] https://lore.kernel.org/bpf/[email protected]/

CC: Jose E. Marchesi <[email protected]>
Signed-off-by: Ihor Solodrai <[email protected]>
---
tools/testing/selftests/bpf/Makefile | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index d5be2f94deef..ea9cee5de0f8 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -41,7 +41,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
endif

-CFLAGS += -g $(OPT_FLAGS) -rdynamic \
+CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11 \
-Wall -Werror -fno-omit-frame-pointer \
$(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
@@ -447,6 +447,7 @@ CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
-I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
-I$(abspath $(OUTPUT)/../usr/include) \
+ -std=gnu11 \
-fno-strict-aliasing \
-Wno-compare-distinct-pointer-types
# TODO: enable me -Wsign-compare
@@ -787,9 +788,12 @@ $(OUTPUT)/xdp_features: xdp_features.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xdp
$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@

# Make sure we are able to include and link libbpf against c++.
+CXXFLAGS += $(CFLAGS)
+CXXFLAGS := $(subst -D_GNU_SOURCE=,,$(CXXFLAGS))
+CXXFLAGS := $(subst -std=gnu11,-std=gnu++11,$(CXXFLAGS))
$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
$(call msg,CXX,,$@)
- $(Q)$(CXX) $(subst -D_GNU_SOURCE=,,$(CFLAGS)) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
+ $(Q)$(CXX) $(CXXFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@

# Benchmark runner
$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h $(BPFOBJ)
--
2.47.1

Loading

0 comments on commit 6f035d7

Please sign in to comment.