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

feat: support CORE and non-CORE mode in one #532

Merged
merged 14 commits into from
Apr 29, 2024
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
9 changes: 8 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ jobs:
- name: Install Compilers
run: |
sudo apt-get update
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-12 clang-12 linux-tools-common linux-tools-generic flex bison
kernel_ver=`uname -r | cut -d'-' -f 1`
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-12 clang-12 linux-tools-common linux-tools-generic flex bison gcc-aarch64-linux-gnu libssl-dev linux-source-${kernel_ver}
for tool in "clang" "llc" "llvm-strip"
do
sudo rm -f /usr/bin/$tool
sudo ln -s /usr/bin/$tool-12 /usr/bin/$tool
done
cd /usr/src
sudo tar -xf linux-source-${kernel_ver}.tar.bz2
cd /usr/src/linux-source-${kernel_ver}
test -f .config || sudo make oldconfig
sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- prepare V=0
ls -al /usr/src/linux-source-${kernel_ver}
shell: bash
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
45 changes: 31 additions & 14 deletions .github/workflows/go-c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Compilers
run: |
sudo apt-get update
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-9 clang-9 linux-tools-common linux-tools-generic gcc
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-9 clang-9 linux-tools-common linux-tools-generic gcc gcc-aarch64-linux-gnu libssl-dev
for tool in "clang" "llc" "llvm-strip"
do
sudo rm -f /usr/bin/$tool
Expand Down Expand Up @@ -60,12 +60,19 @@ jobs:
- name: Install Compilers
run: |
sudo apt-get update
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-14 clang-14 linux-tools-common linux-tools-generic gcc gcc-aarch64-linux-gnu
kernel_ver=`uname -r | cut -d'-' -f 1`
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-14 clang-14 flex bison linux-tools-common linux-tools-generic gcc gcc-aarch64-linux-gnu libssl-dev linux-source-${kernel_ver}
for tool in "clang" "llc" "llvm-strip"
do
sudo rm -f /usr/bin/$tool
sudo ln -s /usr/bin/$tool-14 /usr/bin/$tool
done
cd /usr/src
sudo tar -xf linux-source-${kernel_ver}.tar.bz2
cd /usr/src/linux-source-${kernel_ver}
test -f .config || sudo make oldconfig
sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- prepare V=0
ls -al /usr/src/linux-source-${kernel_ver}
shell: bash
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -95,6 +102,11 @@ jobs:
make clean
CROSS_ARCH=arm64 make env
CROSS_ARCH=arm64 make -j8
- name: Build non-CO-RE (Cross-Compilation)
run: |
make clean
CROSS_ARCH=arm64 make env
CROSS_ARCH=arm64 make nocore -j8
- name: Test
run: go test -v -race ./...

Expand Down Expand Up @@ -160,10 +172,18 @@ jobs:
install: |
uname -a
apt-get update
apt-get install --yes wget git build-essential pkgconf libelf-dev llvm-12 clang-12 linux-tools-generic linux-tools-common flex bison file gcc-x86-64-linux-gnu
kernel_ver=`uname -r | cut -d'-' -f 1`
apt-get install --yes wget git build-essential pkgconf libelf-dev llvm-12 clang-12 linux-tools-generic linux-tools-common flex bison file gcc-x86-64-linux-gnu libssl-dev bc linux-source-${kernel_ver}
wget https://go.dev/dl/go1.21.0.linux-arm64.tar.gz
rm -rf /usr/local/go
tar -C /usr/local -xzf go1.21.0.linux-arm64.tar.gz
cd /usr/src
tar -xf linux-source-${kernel_ver}.tar.bz2
cd /usr/src/linux-source-${kernel_ver}
test -f .config || make oldconfig > /dev/null
make ARCH=x86 CROSS_COMPILE=x86_64-linux-gnu- prepare V=0 > /dev/null
make prepare V=0 > /dev/null
ls -al /usr/src/linux-source-${kernel_ver}
# Produce a binary artifact and place it in the mounted volume
run: |
uname -a
Expand All @@ -183,20 +203,17 @@ jobs:
cat /proc/1/sched
git config --global --add safe.directory /source_code
cd /source_code
echo "-------------------start: Build CO-RE Linux -------------------"
make env
kernel_ver=`uname -r | cut -d'-' -f 1`
echo "-------------------start: Build CO-RE Linux (include non-CO-RE)-------------------"
KERN_HEADERS=/usr/src/linux-source-${kernel_ver} make env
make clean
make
KERN_HEADERS=/usr/src/linux-source-${kernel_ver} make
bin/ecapture -v
echo "-------------------start: Build CO-RE (Cross-Compilation) Linux -------------------"
echo "-------------------start: Build non-CO-RE (Cross-Compilation) Linux -------------------"
make clean
CROSS_ARCH=amd64 make env
CROSS_ARCH=amd64 make -j8
echo "-------------------start: Build non-CO-RE Android -------------------"
make clean
make env
ANDROID=1 make -j2

KERN_HEADERS=/usr/src/linux-source-${kernel_ver} CROSS_ARCH=amd64 make env
KERN_HEADERS=/usr/src/linux-source-${kernel_ver} CROSS_ARCH=amd64 make nocore -j8
file bin/ecapture
- name: Show the artifact
# Items placed in /artifacts in the container will be in
# ${PWD}/artifacts on the host.
Expand Down
220 changes: 34 additions & 186 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,37 @@ on:

jobs:

build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Get the version
id: get_tags
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
shell: bash
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21.0'
- name: Install Compilers
run: |
sudo apt-get update
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-9 clang-9 linux-tools-common linux-tools-generic
for tool in "clang" "llc" "llvm-strip"
do
sudo rm -f /usr/bin/$tool
sudo ln -s /usr/bin/$tool-9 /usr/bin/$tool
done
shell: bash
- name: authenticate
run: |
gh auth login --with-token <<<'${{ secrets.GITHUB_TOKEN }}'
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v1
with:
configuration: "configuration.json"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Write File
uses: DamianReeves/[email protected]
with:
path: ./bin/release_notes.txt
contents: |
${{ steps.github_release.outputs.changelog }}
write-mode: append
- name: Release
run: |
make env
make -f builder/Makefile.release release SNAPSHOT_VERSION=${{ steps.get_tags.outputs.VERSION }}

build-on-ubuntu2204-arm64:
build-on-ubuntu2204:
runs-on: ubuntu-22.04
name: build on ubuntu-22.04 arm64
# Run steps on a matrix of 3 arch/distro combinations
strategy:
matrix:
include:
- arch: aarch64
distro: ubuntu22.04
name: build on ubuntu-22.04 x86_64
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.21.0'
- name: Install Compilers
run: |
sudo apt-get update
kernel_ver=`uname -r | cut -d'-' -f 1`
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm-14 clang-14 linux-tools-common linux-tools-generic gcc gcc-aarch64-linux-gnu linux-source-${kernel_ver}
for tool in "clang" "llc" "llvm-strip"
do
sudo rm -f /usr/bin/$tool
sudo ln -s /usr/bin/$tool-14 /usr/bin/$tool
done
cd /usr/src
sudo tar -xf linux-source-${kernel_ver}.tar.bz2
cd /usr/src/linux-source-${kernel_ver}
test -f .config || sudo make oldconfig
sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- prepare V=0
ls -al /usr/src/linux-source-${kernel_ver}
shell: bash
- uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
set-safe-directory: '/source_code'
- name: Get the version
id: get_tags
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
shell: bash
- name: authenticate
run: |
gh auth login --with-token <<<'${{ secrets.GITHUB_TOKEN }}'
- name: Branch Name
run: |
echo running on branch ${{ github.ref_name }}
echo checkout directory ${GITHUB_WORKSPACE}
echo PWD directory ${PWD}
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v1
Expand All @@ -94,125 +51,16 @@ jobs:
contents: |
${{ steps.github_release.outputs.changelog }}
write-mode: append
- uses: uraimo/run-on-arch-action@v2
name: Build artifact
id: build
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}

# Not required, but speeds up builds
githubToken: ${{ github.token }}

# Create an artifacts directory
setup: |
mkdir -p "${PWD}/artifacts"

# Mount the artifacts directory as /artifacts in the container
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
--volume "${GITHUB_WORKSPACE}:/source_code"

# Pass some environment variables to the container
env: | # YAML, but pipe character is necessary
artifact_name: ecapture-${{ steps.get_tags.outputs.VERSION }}

# The shell to run commands with in the container
shell: /bin/sh

# Install some dependencies in the container. This speeds up builds if
# you are also using githubToken. Any dependencies installed here will
# be part of the container image that gets cached, so subsequent
# builds don't have to re-install them. The image layer is cached
# publicly in your project's package repository, so it is vital that
# no secrets are present in the container state or logs.
install: |
uname -a
apt-get update
apt-get install --yes wget git build-essential pkgconf libelf-dev llvm-12 clang-12 linux-tools-generic linux-tools-common flex bison file gcc-x86-64-linux-gnu
wget https://go.dev/dl/go1.21.0.linux-arm64.tar.gz
rm -rf /usr/local/go
tar -C /usr/local -xzf go1.21.0.linux-arm64.tar.gz
# Produce a binary artifact and place it in the mounted volume
run: |
uname -a
date
export PATH=/usr/local/go/bin:$PATH:/usr/local/bin
echo $PATH
for tool in "clang" "llc" "llvm-strip"
do
rm -f /usr/bin/$tool
ln -s /usr/bin/$tool-12 /usr/bin/$tool
done
clang --version
which bpftool
git config --global --add safe.directory /source_code
cd /source_code
echo "-------------------end: Create ecapture.tar.gz of Linux -------------------"
make env
make clean
make
echo "-------------------ecapture --help-------------------"
bin/ecapture -v
echo "-------------------create tar.gz file-------------------"
UNAME_M=`uname -m`
OUTPUT_DIR="./bin"
SNAPSHOT_VERSION=${{ steps.get_tags.outputs.VERSION }}
echo "#${SNAPSHOT_VERSION}#"
if [ -z "${SNAPSHOT_VERSION}" ]; then
SNAPSHOT_VERSION="v0.0.0"
fi
TAR_DIR=ecapture-${SNAPSHOT_VERSION}-linux-${UNAME_M}
RELEASE_NOTES=${OUTPUT_DIR}/release_notes.txt
OUT_ARCHIVE=${OUTPUT_DIR}/${artifact_name}-linux-${{ matrix.arch }}.tar.gz
mkdir -p ${TAR_DIR}
cp LICENSE ${TAR_DIR}/LICENSE
cp CHANGELOG.md ${TAR_DIR}/CHANGELOG.md
cp README.md ${TAR_DIR}/README.md
cp README_CN.md ${TAR_DIR}/README_CN.md
cp ${OUTPUT_DIR}/ecapture ${TAR_DIR}/ecapture
cp ${OUTPUT_DIR}/release_notes.txt ${TAR_DIR}/release_notes.txt
tar -czf ${OUT_ARCHIVE} ${TAR_DIR}
cp ${OUT_ARCHIVE} "/artifacts/"
echo "-------------------end: Create ecapture.tar.gz of Linux -------------------"
echo "-------------------start: Create ecapture.tar.gz of Android kernel CO:RE -------------------"
make env
make clean
ANDROID=1 make
echo "-------------------ecapture --help-------------------"
echo "bin/ecapture -v"
echo "-------------------create tar.gz file-------------------"
UNAME_M=`uname -m`
OUTPUT_DIR="./bin"
SNAPSHOT_VERSION=${{ steps.get_tags.outputs.VERSION }}
echo "#${SNAPSHOT_VERSION}#"
if [ -z "${SNAPSHOT_VERSION}" ]; then
SNAPSHOT_VERSION="0.0.0"
fi
TAR_DIR=ecapture-${SNAPSHOT_VERSION}-android_core-${UNAME_M}
RELEASE_NOTES=${OUTPUT_DIR}/release_notes.txt
OUT_ARCHIVE=${OUTPUT_DIR}/${artifact_name}-android-${{ matrix.arch }}.tar.gz
mkdir -p ${TAR_DIR}
cp LICENSE ${TAR_DIR}/LICENSE
cp CHANGELOG.md ${TAR_DIR}/CHANGELOG.md
cp README.md ${TAR_DIR}/README.md
cp README_CN.md ${TAR_DIR}/README_CN.md
cp ${OUTPUT_DIR}/ecapture ${TAR_DIR}/ecapture
cp ${OUTPUT_DIR}/release_notes.txt ${TAR_DIR}/release_notes.txt
tar -czf ${OUT_ARCHIVE} ${TAR_DIR}
cp ${OUT_ARCHIVE} "/artifacts/"
echo "-------------------end: Create ecapture.tar.gz of Android kernel CO:RE -------------------"
echo "Produced artifact at /artifacts/${artifact_name}"

- name: Upload artifacts
# Items placed in /artifacts in the container will be in
# ${PWD}/artifacts on the host.
# gh command help: https://cli.github.com/manual/gh_release_download
- name: Release amd64
run: |
make clean
make env
make -f builder/Makefile.release release SNAPSHOT_VERSION=${{ steps.get_tags.outputs.VERSION }}
- name: Release arm64 (CROSS COMPILATION)
run: |
make clean
make env
CROSS_ARCH=arm64 make -f builder/Makefile.release release SNAPSHOT_VERSION=${{ steps.get_tags.outputs.VERSION }}
- name: Publish
run: |
ls -al "${PWD}/artifacts"
cd "${PWD}/artifacts"
gh release download ${{ steps.get_tags.outputs.VERSION }} -p "checksum-${{ steps.get_tags.outputs.VERSION }}.txt"
sha256sum ecapture-*.tar.gz >> checksum-${{ steps.get_tags.outputs.VERSION }}.txt
files=($(ls ecapture-*.tar.gz checksum-${{ steps.get_tags.outputs.VERSION }}.txt))
echo "-------------------upload files: ${files[@]} -------------------"
gh release upload ${{ steps.get_tags.outputs.VERSION }} "${files[@]}" --clobber
make -f builder/Makefile.release publish SNAPSHOT_VERSION=${{ steps.get_tags.outputs.VERSION }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# Dependency directories (remove the comment below to include it)
# vendor/
/assets/ebpf_probe.go
/assets/ebpf_probe_core.go
/assets/ebpf_probe_noncore.go

# VSCode
.vscode/settings.json
Expand Down
Loading
Loading