Skip to content

Commit

Permalink
github: ci: SUpport PIE
Browse files Browse the repository at this point in the history
Link: #28
Signed-off-by: Rong Tao <rongtao@cestc.cn>
  • Loading branch information
Rtoax committed Jan 2, 2025
1 parent ecc1b88 commit 451f5ea
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
46 changes: 45 additions & 1 deletion .github/include/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,51 @@ set -e

BUILD_DIR="build-ci"

cmake -B ${BUILD_DIR}
PIE=

__usage__()
{
echo -e "
github-ci [options]
--pie=[ON|OFF]
-h, --help
" | more

exit ${1-0}
}

TEMP=$(getopt \
--options h \
--long pie: \
--long help \
-n github-ci -- "$@")

test $? != 0 && __usage__ 1

eval set -- "$TEMP"

while true; do
case $1 in
--pie)
shift
PIE=$1
shift
;;
-h|--help)
shift
__usage__
;;
--)
shift
break
;;
esac
done

cmake -B ${BUILD_DIR} ${PIE:+-DCONFIG_BUILD_PIE_EXE=${PIE}}

tree -d ${BUILD_DIR}
make -C ${BUILD_DIR} -j$(nproc)
sudo make -C ${BUILD_DIR} install
Expand Down
4 changes: 4 additions & 0 deletions .github/include/sysinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ set -ex
cat /etc/os-release
systemd-detect-virt || true
uname -a
free -g
nproc
lscpu
# Fedora base container doesn't contain ip command.
ip addr || true
gcc --version
ldconfig --version
echo cwd=$PWD
ls -al
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ permissions:
jobs:
test_ulpatch:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Install dependencies
Expand All @@ -25,8 +27,10 @@ jobs:
test_ulpatch_fedora:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
fedora-version: [38, 41]
pie: [OFF, ON]
container:
image: "fedora:${{matrix.fedora-version}}"
# These options are required to be able to run lldb inside the container
Expand All @@ -40,16 +44,16 @@ jobs:
sudo dnf install -y binutils-devel capstone-devel cmake \
elfutils-devel elfutils-libelf-devel gcc gcc-c++ \
glibc-devel libunwind-devel tree util-linux rpm-build \
git dnf-plugins-core
git dnf-plugins-core procps-ng
sudo dnf builddep -y ulpatch.spec
- name: System info
run: ./.github/include/sysinfo.sh
- name: Build binary
run: ./.github/include/ci.sh
run: ./.github/include/ci.sh --pie=${{matrix.pie}}
- name: Running ulpatch_test
run: ulpatch_test
- name: Build RPMS
working-directory: /workdir/ulpatch/
run: |
./archive.sh
./rpmbuild.sh
./rpmbuild.sh --pie ${{matrix.pie}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Build
build
build-ci
CMakeCache.txt
CMakeFiles
cmake_install.cmake
Expand Down
13 changes: 13 additions & 0 deletions rpmbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ set -e
# Use half of CPU cores
np=$(( $(nproc) / 2 ))

pie=
without_capstone=
without_libunwind=
nodebuginfo=

__usage__() {
echo -e "
--pie [ON|OFF]
--without-capstone build without capstone
--without-libunwind build without libunwind
Expand All @@ -21,6 +24,7 @@ __usage__() {

TEMP=$( getopt --options h \
--long help \
--long pie: \
--long without-capstone \
--long without-libunwind \
--long nodebuginfo \
Expand All @@ -35,6 +39,11 @@ while true ; do
shift
__usage__
;;
--pie)
shift
pie=$1
shift
;;
--without-capstone)
shift
without_capstone=YES
Expand All @@ -54,11 +63,15 @@ while true ; do
esac
done

PIE=
[[ ${pie} == ON ]] && PIE=ON

rpmbuild -ba \
--define "_topdir $PWD" \
--define "_sourcedir $PWD" \
--define "_smp_mflags -j${np}" \
${without_capstone:+--without capstone} \
${without_libunwind:+--without libunwind} \
${nodebuginfo:+--nodebuginfo} \
${PIE:+--define "pie 1"} \
ulpatch.spec
10 changes: 8 additions & 2 deletions ulpatch.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
%define with_capstone 0%{?!_without_capstone:1}
%define with_libunwind 0%{?!_without_libunwind:1}

# Compile executions as PIE or not
%define build_pie 0%{?pie}

Name: ulpatch
# The version number must be consistent with the CMakeLists.txt in the
# top-level directory.
Version: 0.5.12
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Userspace Live Patch Toolset

License: GPL-2.0 or later
Expand Down Expand Up @@ -115,6 +118,9 @@ cmake -DCMAKE_BUILD_TYPE=Release \
%if "%{toolchain}" == "clang"
-DCMAKE_C_COMPILER=clang \
%endif
%if %{build_pie}
-DCONFIG_BUILD_PIE_EXE=ON \
%endif
%if !%{?with_ulftrace}
-DCONFIG_BUILD_ULFTRACE=OFF \
%endif
Expand Down Expand Up @@ -183,6 +189,6 @@ popd
%{_datadir}/ulpatch/ulpatches/printf.ulp

%changelog
* Thu Jan 02 2025 Rong Tao <rtoax@foxmail.com> - 0.5.12-2
* Thu Jan 02 2025 Rong Tao <rtoax@foxmail.com> - 0.5.12-3
- Not release yet.

0 comments on commit 451f5ea

Please sign in to comment.