Skip to content

Commit 8da0ce8

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

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

.github/workflows/stress.yml

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