Skip to content

Commit 0f9e307

Browse files
committed
Add stress test to patch all binaries in the machine
1 parent 27cbc89 commit 0f9e307

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

.github/workflows/stress.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Stress tests
2+
on: workflow_dispatch
3+
4+
jobs:
5+
build_tarballs:
6+
name: Build tarballs
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
- uses: cachix/install-nix-action@v20
12+
- name: Build tarballs
13+
run: |
14+
nix build -L .#hydraJobs.tarball
15+
install -D ./result/tarballs/*.tar.bz2 ./dist/patchelf-$(cat version).tar.bz2
16+
install -D ./result/tarballs/*.tar.gz ./dist/patchelf-$(cat version).tar.gz
17+
- uses: actions/upload-artifact@v3
18+
with:
19+
name: patchelf
20+
path: dist/*
21+
22+
build_musl:
23+
name: Build static musl binaries
24+
needs: [build_tarballs]
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
platform: ["amd64", "i386", "ppc64le", "arm64v8", "arm32v7", "s390x", "riscv64"]
30+
steps:
31+
- name: Set up QEMU
32+
if: matrix.platform != 'amd64'
33+
uses: docker/setup-qemu-action@v2
34+
35+
- uses: actions/download-artifact@v3
36+
with:
37+
name: patchelf
38+
path: dist
39+
- name: Build binaries
40+
env:
41+
CXXFLAGS: "-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security -O2 -static"
42+
run: |
43+
cat <<EOF > build.sh
44+
set -e
45+
set -x
46+
apk add build-base
47+
tar -xf dist/*.tar.bz2
48+
rm -f dist/*
49+
cd patchelf-*
50+
./configure --prefix /patchelf
51+
make check STRESS=1 || (cat tests/test-suite.log; exit 1)
52+
make install-strip
53+
cd -
54+
tar -czf ./dist/patchelf-\$(cat patchelf-*/version)-\$(uname -m).tar.gz -C /patchelf .
55+
EOF
56+
57+
if [ "${{ matrix.platform }}" == "i386" ]; then
58+
ENTRYPOINT=linux32
59+
else
60+
ENTRYPOINT=
61+
fi
62+
docker run -e CXXFLAGS -v $(pwd):/gha ${{ matrix.platform }}/alpine:edge ${ENTRYPOINT} sh -ec "cd /gha && sh ./build.sh"

tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ src_TESTS = \
4949
modify-execstack.sh \
5050
rename-dynamic-symbols.sh \
5151
overlapping-segments-after-rounding.sh \
52+
stress.sh \
5253
empty-note.sh
5354

5455
build_TESTS = \

tests/stress.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /bin/sh -e
2+
3+
[ "$STRESS" = "1" ] || exit 0
4+
5+
SCRATCH=scratch/$(basename "$0" .sh)
6+
PATCHELF=$(readlink -f "../src/patchelf")
7+
8+
rm -rf "${SCRATCH}"
9+
mkdir -p "${SCRATCH}"
10+
cd "${SCRATCH}"
11+
12+
for lib in /usr/lib*/*.so* /usr/bin/* /usr/libexec/*
13+
do
14+
if file "$lib" | grep -q -e "ELF.*dynamically"
15+
then
16+
echo "==============================================================="
17+
echo "#### Copying"
18+
echo "$lib"
19+
echo "$(file $lib)"
20+
blib="$(basename "$lib")"
21+
cp "$lib" "$blib"
22+
echo "#### chmod"
23+
chmod +w "$blib"
24+
25+
echo "#### readelf before"
26+
readelf -L "$blib" > /dev/null 2> re_before || echo
27+
echo "#### ldd before"
28+
ldd "$blib" | sed 's/0x.*//g' > ldd_before
29+
30+
echo "#### get rpath"
31+
new_rpath="$(${PATCHELF} --print-rpath "$blib"):XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
32+
echo "#### new rpath: $new_rpath"
33+
${PATCHELF} --force-rpath --set-rpath "$new_rpath" "$blib"
34+
35+
echo "#### readelf after"
36+
readelf -L "$blib" > /dev/null 2> re_after || echo
37+
echo "#### ldd after"
38+
ldd "$blib" | sed 's/0x.*//g' > ldd_after
39+
40+
diff re_before re_after
41+
diff ldd_before ldd_after
42+
43+
rm "$blib"
44+
fi
45+
done

0 commit comments

Comments
 (0)