]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
oss-fuzz: support i386 23550/head
authorEvgeny Vereshchagin <evvers@ya.ru>
Sun, 29 May 2022 06:52:54 +0000 (06:52 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Sun, 29 May 2022 09:32:00 +0000 (09:32 +0000)
Closes https://github.com/systemd/systemd/issues/23532

tools/oss-fuzz.sh

index 0e8f92937e6e7a545ed2b1e9080364f37c05b329..793411ed845de4da3906a802757c35eb9136aa89 100755 (executable)
@@ -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" \;