From b22f5ed5fb6bba2326beb4dd511e535928b894f1 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 29 May 2022 06:52:54 +0000 Subject: oss-fuzz: support i386 Closes https://github.com/systemd/systemd/issues/23532 --- tools/oss-fuzz.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tools') 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" \; -- cgit v1.2.1