Skip to content

Commit 451f5ea

Browse files
committed
github: ci: SUpport PIE
Link: #28 Signed-off-by: Rong Tao <[email protected]>
1 parent ecc1b88 commit 451f5ea

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

.github/include/ci.sh

+45-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,51 @@ set -e
33

44
BUILD_DIR="build-ci"
55

6-
cmake -B ${BUILD_DIR}
6+
PIE=
7+
8+
__usage__()
9+
{
10+
echo -e "
11+
github-ci [options]
12+
13+
--pie=[ON|OFF]
14+
15+
-h, --help
16+
" | more
17+
18+
exit ${1-0}
19+
}
20+
21+
TEMP=$(getopt \
22+
--options h \
23+
--long pie: \
24+
--long help \
25+
-n github-ci -- "$@")
26+
27+
test $? != 0 && __usage__ 1
28+
29+
eval set -- "$TEMP"
30+
31+
while true; do
32+
case $1 in
33+
--pie)
34+
shift
35+
PIE=$1
36+
shift
37+
;;
38+
-h|--help)
39+
shift
40+
__usage__
41+
;;
42+
--)
43+
shift
44+
break
45+
;;
46+
esac
47+
done
48+
49+
cmake -B ${BUILD_DIR} ${PIE:+-DCONFIG_BUILD_PIE_EXE=${PIE}}
50+
751
tree -d ${BUILD_DIR}
852
make -C ${BUILD_DIR} -j$(nproc)
953
sudo make -C ${BUILD_DIR} install

.github/include/sysinfo.sh

+4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ set -ex
44
cat /etc/os-release
55
systemd-detect-virt || true
66
uname -a
7+
free -g
8+
nproc
9+
lscpu
710
# Fedora base container doesn't contain ip command.
811
ip addr || true
912
gcc --version
13+
ldconfig --version
1014
echo cwd=$PWD
1115
ls -al

.github/workflows/ci.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ permissions:
99
jobs:
1010
test_ulpatch:
1111
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
1214
steps:
1315
- uses: actions/checkout@v4
1416
- name: Install dependencies
@@ -25,8 +27,10 @@ jobs:
2527
test_ulpatch_fedora:
2628
runs-on: ubuntu-latest
2729
strategy:
30+
fail-fast: false
2831
matrix:
2932
fedora-version: [38, 41]
33+
pie: [OFF, ON]
3034
container:
3135
image: "fedora:${{matrix.fedora-version}}"
3236
# These options are required to be able to run lldb inside the container
@@ -40,16 +44,16 @@ jobs:
4044
sudo dnf install -y binutils-devel capstone-devel cmake \
4145
elfutils-devel elfutils-libelf-devel gcc gcc-c++ \
4246
glibc-devel libunwind-devel tree util-linux rpm-build \
43-
git dnf-plugins-core
47+
git dnf-plugins-core procps-ng
4448
sudo dnf builddep -y ulpatch.spec
4549
- name: System info
4650
run: ./.github/include/sysinfo.sh
4751
- name: Build binary
48-
run: ./.github/include/ci.sh
52+
run: ./.github/include/ci.sh --pie=${{matrix.pie}}
4953
- name: Running ulpatch_test
5054
run: ulpatch_test
5155
- name: Build RPMS
5256
working-directory: /workdir/ulpatch/
5357
run: |
5458
./archive.sh
55-
./rpmbuild.sh
59+
./rpmbuild.sh --pie ${{matrix.pie}}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build
22
build
3+
build-ci
34
CMakeCache.txt
45
CMakeFiles
56
cmake_install.cmake

rpmbuild.sh

+13
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ set -e
44
# Use half of CPU cores
55
np=$(( $(nproc) / 2 ))
66

7+
pie=
78
without_capstone=
89
without_libunwind=
910
nodebuginfo=
1011

1112
__usage__() {
1213
echo -e "
14+
--pie [ON|OFF]
15+
1316
--without-capstone build without capstone
1417
--without-libunwind build without libunwind
1518
@@ -21,6 +24,7 @@ __usage__() {
2124

2225
TEMP=$( getopt --options h \
2326
--long help \
27+
--long pie: \
2428
--long without-capstone \
2529
--long without-libunwind \
2630
--long nodebuginfo \
@@ -35,6 +39,11 @@ while true ; do
3539
shift
3640
__usage__
3741
;;
42+
--pie)
43+
shift
44+
pie=$1
45+
shift
46+
;;
3847
--without-capstone)
3948
shift
4049
without_capstone=YES
@@ -54,11 +63,15 @@ while true ; do
5463
esac
5564
done
5665

66+
PIE=
67+
[[ ${pie} == ON ]] && PIE=ON
68+
5769
rpmbuild -ba \
5870
--define "_topdir $PWD" \
5971
--define "_sourcedir $PWD" \
6072
--define "_smp_mflags -j${np}" \
6173
${without_capstone:+--without capstone} \
6274
${without_libunwind:+--without libunwind} \
6375
${nodebuginfo:+--nodebuginfo} \
76+
${PIE:+--define "pie 1"} \
6477
ulpatch.spec

ulpatch.spec

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
%define with_capstone 0%{?!_without_capstone:1}
1818
%define with_libunwind 0%{?!_without_libunwind:1}
1919

20+
# Compile executions as PIE or not
21+
%define build_pie 0%{?pie}
22+
2023
Name: ulpatch
2124
# The version number must be consistent with the CMakeLists.txt in the
2225
# top-level directory.
2326
Version: 0.5.12
24-
Release: 2%{?dist}
27+
Release: 3%{?dist}
2528
Summary: Userspace Live Patch Toolset
2629

2730
License: GPL-2.0 or later
@@ -115,6 +118,9 @@ cmake -DCMAKE_BUILD_TYPE=Release \
115118
%if "%{toolchain}" == "clang"
116119
-DCMAKE_C_COMPILER=clang \
117120
%endif
121+
%if %{build_pie}
122+
-DCONFIG_BUILD_PIE_EXE=ON \
123+
%endif
118124
%if !%{?with_ulftrace}
119125
-DCONFIG_BUILD_ULFTRACE=OFF \
120126
%endif
@@ -183,6 +189,6 @@ popd
183189
%{_datadir}/ulpatch/ulpatches/printf.ulp
184190

185191
%changelog
186-
* Thu Jan 02 2025 Rong Tao <[email protected]> - 0.5.12-2
192+
* Thu Jan 02 2025 Rong Tao <[email protected]> - 0.5.12-3
187193
- Not release yet.
188194

0 commit comments

Comments
 (0)