summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2022-05-29 06:52:54 +0000
committerEvgeny Vereshchagin <evvers@ya.ru>2022-05-29 09:32:00 +0000
commitb22f5ed5fb6bba2326beb4dd511e535928b894f1 (patch)
treef4289e666383d3df587030071829e958d5fad6b7 /tools
parent61ad4f25ed38064f487ae2213abbc4b4b1cc54f8 (diff)
downloadsystemd-b22f5ed5fb6bba2326beb4dd511e535928b894f1.tar.gz
oss-fuzz: support i386
Closes https://github.com/systemd/systemd/issues/23532
Diffstat (limited to 'tools')
-rwxr-xr-xtools/oss-fuzz.sh22
1 files changed, 21 insertions, 1 deletions
diff --git a/tools/oss-fuzz.sh b/tools/oss-fuzz.sh
index 0e8f92937e..793411ed84 100755
--- a/tools/oss-fuzz.sh
+++ b/tools/oss-fuzz.sh
@@ -34,9 +34,13 @@ else
apt-get update
apt-get install -y gperf m4 gettext python3-pip \
- libcap-dev libmount-dev libkmod-dev \
+ libcap-dev libmount-dev \
pkg-config wget python3-jinja2 zipmerge
+ if [[ "$ARCHITECTURE" == i386 ]]; then
+ apt-get install -y pkg-config:i386 libcap-dev:i386 libmount-dev:i386
+ fi
+
# gnu-efi is installed here to enable -Dgnu-efi behind which fuzz-bcd
# is hidden. It isn't linked against efi. It doesn't
# even include "efi.h" because "bcd.c" can work in "unit test" mode
@@ -105,6 +109,22 @@ install -Dt "$OUT/src/shared/" \
"$build"/src/shared/libsystemd-shared-*.so \
"$build"/src/core/libsystemd-core-*.so
+# Most i386 libraries have to be brought to the runtime environment somehow. Ideally they
+# should be linked statically but since it isn't possible another way to keep them close
+# to the fuzz targets is used here. The dependencies are copied to "$OUT/src/shared" and
+# then `rpath` is tweaked to make it possible for the linker to find them there. "$OUT/src/shared"
+# is chosen because the runtime search path of all the fuzz targets already points to it
+# to load "libsystemd-shared" and "libsystemd-core". Stuff like that should be avoided on
+# x86_64 because it tends to break coverage reports, fuzz-introspector, CIFuzz and so on.
+if [[ "$ARCHITECTURE" == i386 ]]; then
+ for lib_path in $(ldd "$OUT"/src/shared/libsystemd-shared-*.so | perl -lne 'print $1 if m{=>\s+(/lib\S+)}'); do
+ lib_name=$(basename "$lib_path")
+ cp "$lib_path" "$OUT/src/shared"
+ patchelf --set-rpath \$ORIGIN "$OUT/src/shared/$lib_name"
+ done
+ patchelf --set-rpath \$ORIGIN "$OUT"/src/shared/libsystemd-shared-*.so
+fi
+
wget -O "$OUT/fuzz-json.dict" https://raw.githubusercontent.com/rc0r/afl-fuzz/master/dictionaries/json.dict
find "$build" -maxdepth 1 -type f -executable -name "fuzz-*" -exec mv {} "$OUT" \;