|
| 1 | +#!/bin/bash -eux |
| 2 | +# Copyright 2025 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +################################################################################ |
| 17 | + |
| 18 | +OSS_FUZZ_BUILD_DIR="./build-oss-fuzz/" |
| 19 | +cd $OSS_FUZZ_BUILD_DIR |
| 20 | + |
| 21 | +# Prepare third party libraries directory |
| 22 | +DEST_DIR=$OUT |
| 23 | +mkdir -p "$DEST_DIR/lib/" |
| 24 | + |
| 25 | +# Build fuzzing harnesses and libs |
| 26 | +make "-j$(nproc)" qemu-fuzz-i386 V=1 |
| 27 | + |
| 28 | +# Install data files |
| 29 | +make install DESTDIR=$DEST_DIR/qemu-bundle |
| 30 | +rm -rf $DEST_DIR/qemu-bundle/opt/qemu-oss-fuzz/bin |
| 31 | +rm -rf $DEST_DIR/qemu-bundle/opt/qemu-oss-fuzz/libexec |
| 32 | + |
| 33 | + |
| 34 | +# Copy over the librarise needed by the fuzzer. |
| 35 | +# These are the libraries copied from https://github.com/qemu/qemu/blob/88b1716a407459c8189473e4667653cb8e4c3df7/scripts/oss-fuzz/build.sh#L78 |
| 36 | +# We do it this way, to avoid calling `configure`, which is called twice in the |
| 37 | +# build.sh. |
| 38 | +# Configure poses problems because it relies on network activity and also |
| 39 | +# performance is a lot better without configure. |
| 40 | +cp /lib/x86_64-linux-gnu/libstdc++.so.6 /out/lib/ |
| 41 | +cp /lib/x86_64-linux-gnu/libpixman-1.so.0 /out/lib/ |
| 42 | +cp /lib/x86_64-linux-gnu/libz.so.1 /out/lib/ |
| 43 | +cp /lib/x86_64-linux-gnu/libfdt.so.1 /out/lib/ |
| 44 | +cp /lib/x86_64-linux-gnu/libgio-2.0.so.0 /out/lib/ |
| 45 | +cp /lib/x86_64-linux-gnu/libgobject-2.0.so.0 /out/lib/ |
| 46 | +cp /lib/x86_64-linux-gnu/libglib-2.0.so.0 /out/lib/ |
| 47 | +cp /lib/x86_64-linux-gnu/libslirp.so.0 /out/lib/ |
| 48 | +cp /lib/x86_64-linux-gnu/libutil.so.1 /out/lib/ |
| 49 | +cp /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 /out/lib/ |
| 50 | +cp /lib/x86_64-linux-gnu/libm.so.6 /out/lib/ |
| 51 | +cp /lib/x86_64-linux-gnu/libpthread.so.0 /out/lib/ |
| 52 | +cp /lib/x86_64-linux-gnu/librt.so.1 /out/lib/ |
| 53 | +cp /lib/x86_64-linux-gnu/libdl.so.2 /out/lib/ |
| 54 | +cp /lib/x86_64-linux-gnu/libresolv.so.2 /out/lib/ |
| 55 | +cp /lib/x86_64-linux-gnu/libgcc_s.so.1 /out/lib/ |
| 56 | +cp /lib/x86_64-linux-gnu/libc.so.6 /out/lib/ |
| 57 | +cp /lib/x86_64-linux-gnu/libffi.so.7 /out/lib/ |
| 58 | + |
| 59 | +export ASAN_OPTIONS=detect_leaks=0 |
| 60 | +targets=$(./qemu-fuzz-i386 | grep generic-fuzz | awk '$1 ~ /\*/ {print $2}') |
| 61 | +base_copy="$DEST_DIR/qemu-fuzz-i386-target-$(echo "$targets" | head -n 1)" |
| 62 | + |
| 63 | +cp "./qemu-fuzz-i386" "$base_copy" |
| 64 | + |
| 65 | +# Generate the actual fuzzing harnesses |
| 66 | +for target in $(echo "$targets" | tail -n +2); |
| 67 | +do |
| 68 | + # Skip generic harness. |
| 69 | + if [[ $target == "generic-fuzz-"* ]]; then |
| 70 | + ln $base_copy \ |
| 71 | + "$DEST_DIR/qemu-fuzz-i386-target-$target" |
| 72 | + fi |
| 73 | +done |
0 commit comments