Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC BPF support #164

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
timeout-minutes: 100
env:
ARTIFACTS_ARCHIVE: "vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst"

BUILD_BPF_GCC: ${{ inputs.arch == 'x86_64' && 'true' || '' }}
BPF_GCC_INSTALL_DIR: ${{ github.workspace }}/bpf-gcc

BPF_NEXT_BASE_BRANCH: 'master'
BPF_NEXT_FETCH_DEPTH: 64 # A bit of history is needed to facilitate incremental builds
BUILD_SCHED_EXT_SELFTESTS: ${{ inputs.arch == 'x86_64' || inputs.arch == 'aarch64' && 'true' || '' }}
Expand Down Expand Up @@ -107,11 +111,19 @@ jobs:
kbuild-output: ${{ env.KBUILD_OUTPUT }}
max-make-jobs: 32
llvm-version: ${{ inputs.llvm-version }}

- if: ${{ env.BUILD_BPF_GCC }}
name: Build GCC for BPF selftests
uses: ./build-bpf-gcc
with:
install-dir: ${{ env.BPF_GCC_INSTALL_DIR }}

- name: Build selftests/bpf
uses: ./build-selftests
env:
MAX_MAKE_JOBS: 32
RELEASE: ${{ inputs.release && '1' || '' }}
BPF_GCC: ${{ env.BUILD_BPF_GCC && env.BPF_GCC_INSTALL_DIR || '' }}
with:
arch: ${{ inputs.arch }}
kernel-root: ${{ env.KERNEL_ROOT }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- {"test": "test_progs_no_alu32", "continue_on_error": false, "timeout_minutes": 360}
- {"test": "test_verifier", "continue_on_error": false, "timeout_minutes": 360}
- {"test": "test_maps", "continue_on_error": false, "timeout_minutes": 360}
- {"test": "test_progs-bpf_gcc", "continue_on_error": false, "timeout_minutes": 360}
# Uncomment this to enable sched_ext selftests jobs
# - {"test": "sched_ext", "continue_on_error": false, "timeout_minutes": 360}
fail-fast: false
Expand Down
15 changes: 15 additions & 0 deletions build-bpf-gcc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build BPF GCC

This action grabs latest GCC 15 source code snapshot from
https://gcc.gnu.org/pub/gcc/snapshots, as well as most recent
binutils, and builds GCC for BPF backend and installs it into a
specified directory.

Resulting artifacts are cached with
[actions/cache](https://github.com/actions/cache), using snapshot
names as a key.

## Required inputs

* `install-dir` - Path to the directory where built binaries are going to be installed, or restored from cache.

28 changes: 28 additions & 0 deletions build-bpf-gcc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'Build BPF GCC'
description: 'Fetch latest GCC and binutils snapshots, bulid GCC and install into the target directory'
inputs:
install-dir:
description: "Path to the GCC installation directory"
required: true

runs:
using: "composite"
steps:

- name: Determine latest snapshots
id: latest-snapshots
shell: bash
run: ${GITHUB_ACTION_PATH}/latest-snapshots.sh

- uses: actions/cache@v4
id: cache
with:
path: ${{ inputs.install-dir }}
key: BPF-GCC-${{ steps.latest-snapshots.outputs.GCC_BASENAME }}-${{ steps.latest-snapshots.outputs.BINUTILS_BASENAME }}

- if: steps.cache.outputs.cache-hit != 'true'
name: Build BPF GCC
shell: bash
run: |
${GITHUB_ACTION_PATH}/build-and-install.sh ${{ inputs.install-dir }}

53 changes: 53 additions & 0 deletions build-bpf-gcc/build-and-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -euo pipefail

source ${GITHUB_ACTION_PATH}/../helpers.sh

INSTALLDIR=$(realpath $1)

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

foldable start download_tarballs "Downloading $BINUTILS_URL and $GCC_URL"

test -f $BINUTILS_TARBALL || wget -q $BINUTILS_URL
test -f $GCC_TARBALL || wget -q $GCC_URL

foldable end download_tarballs

foldable start build_binutils "Building $BINUTILS_BASENAME"

if [ ! -f "${INSTALLDIR}/${BINUTILS_BASENAME}.built" ]; then
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
cd -
fi

foldable end build_binutils

foldable start build_gcc "Building $GCC_BASENAME"

if [ ! -f "${INSTALLDIR}/${GCC_BASENAME}.built" ]; then
tar xJf $GCC_TARBALL
cd ${GCC_BASENAME}
./contrib/download_prerequisites
cd -
mkdir -p ${GCC_BASENAME}/build-bpf
cd ${GCC_BASENAME}/build-bpf
../configure --target=bpf-unknown-none --prefix=$INSTALLDIR
make -j$(nproc) && make install
touch ${INSTALLDIR}/${GCC_BASENAME}.built
cd -
fi

foldable end build_gcc

exit 0
25 changes: 25 additions & 0 deletions build-bpf-gcc/latest-snapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -euo pipefail

BINUTILS_TARBALL=`wget https://snapshots.sourceware.org/binutils/trunk/latest/src/sha512.sum -O - -o /dev/null | grep -E 'binutils-[0-9a-f.-]+.tar.xz' | sed -e 's/.*\(binutils-[^<]*\).*/\1/'`
GCC_TARBALL=`wget https://gcc.gnu.org/pub/gcc/snapshots/LATEST-15 -O - -o /dev/null | grep -E 'gcc-15-[0-9]+.tar.xz' | sed -e 's/.*\(gcc-15-[^<]*\).*/\1/'`

BINUTILS_URL="https://snapshots.sourceware.org/binutils/trunk/latest/src/$BINUTILS_TARBALL"
GCC_URL="https://gcc.gnu.org/pub/gcc/snapshots/LATEST-15/$GCC_TARBALL"

BINUTILS_BASENAME=$(basename $BINUTILS_TARBALL .tar.xz)
GCC_BASENAME=$(basename $GCC_TARBALL .tar.xz)

cat > ${GITHUB_ACTION_PATH}/.env <<EOF
BINUTILS_TARBALL=$BINUTILS_TARBALL
GCC_TARBALL=$GCC_TARBALL
BINUTILS_URL=$BINUTILS_URL
GCC_URL=$GCC_URL
BINUTILS_BASENAME=$BINUTILS_BASENAME
GCC_BASENAME=$GCC_BASENAME
EOF

echo "BINUTILS_BASENAME=${BINUTILS_BASENAME}" >> "$GITHUB_OUTPUT"
echo "GCC_BASENAME=${GCC_BASENAME}" >> "$GITHUB_OUTPUT"

exit 0
7 changes: 7 additions & 0 deletions build-selftests/build_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ if [[ $TOOLCHAIN = "llvm" ]]; then
TOOLCHAIN="llvm-$LLVM_VERSION"
fi

if [ -n "${BPF_GCC:-}" ]; then
BPF_GCC="${BPF_GCC}/bin/bpf-unknown-none-gcc"
else
BPF_GCC=
fi

foldable start build_selftests "Building selftests with $TOOLCHAIN"

MAKE_OPTS=$(cat <<EOF
ARCH=${ARCH}
BPF_GCC=${BPF_GCC}
CROSS_COMPILE=${CROSS_COMPILE}
CLANG=clang-${LLVM_VERSION}
LLC=llc-${LLVM_VERSION}
Expand Down
Loading
Loading