2022-07-22 00:12:14 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2022 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2022-08-11 22:28:24 +00:00
|
|
|
# The MESON_* variables are passed to meson to build dbus-broker itself and the original
|
|
|
|
# variables are used to build the fuzz target without meson to make the script compatible
|
|
|
|
# with fuzz-introspector. Once the fuzz target is built with meson as well the MESON_*
|
|
|
|
# variables can be safely removed and CFLAGS/CXXFLAGS/LDFLAGS can be tweaked directly
|
|
|
|
# instead: https://github.com/google/oss-fuzz/pull/7583#issuecomment-1104011067
|
|
|
|
MESON_CFLAGS=${CFLAGS:-}
|
|
|
|
MESON_CXXFLAGS=${CXXFLAGS:-}
|
|
|
|
MESON_LDFLAGS=${LDFLAGS:-}
|
|
|
|
|
2022-07-23 16:09:06 +00:00
|
|
|
if [[ "$SANITIZER" == introspector ]]; then
|
2022-08-11 22:28:24 +00:00
|
|
|
MESON_CFLAGS="${MESON_CFLAGS//-fuse-ld=gold/ }"
|
|
|
|
MESON_CXXFLAGS="${MESON_CXXFLAGS//-fuse-ld=gold/ }"
|
|
|
|
MESON_LDFLAGS="${MESON_LDFLAGS//-fuse-ld=gold/ }"
|
|
|
|
MESON_LDFLAGS+=" -flto"
|
|
|
|
export CC_LD=gold
|
|
|
|
export CXX_LD=gold
|
2022-07-23 16:09:06 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-22 00:12:14 +00:00
|
|
|
apt-get update -y
|
|
|
|
|
|
|
|
if [[ "$ARCHITECTURE" == i386 ]]; then
|
|
|
|
apt-get install -y pkg-config:i386
|
|
|
|
else
|
|
|
|
apt-get install -y pkg-config
|
|
|
|
fi
|
|
|
|
|
2022-07-22 12:40:03 +00:00
|
|
|
if [[ "$SANITIZER" == undefined ]]; then
|
|
|
|
additional_ubsan_checks=alignment
|
|
|
|
UBSAN_FLAGS="-fsanitize=$additional_ubsan_checks -fno-sanitize-recover=$additional_ubsan_checks"
|
|
|
|
CFLAGS+=" $UBSAN_FLAGS"
|
|
|
|
CXXFLAGS+=" $UBSAN_FLAGS"
|
2022-09-14 09:16:54 +00:00
|
|
|
MESON_CFLAGS+=" $UBSAN_FLAGS"
|
|
|
|
MESON_CXXFLAGS+=" $UBSAN_FLAGS"
|
2022-07-22 12:40:03 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-22 00:12:14 +00:00
|
|
|
pip3 install meson ninja
|
|
|
|
|
2022-08-11 22:28:24 +00:00
|
|
|
if ! CFLAGS="$MESON_CFLAGS" CXXFLAGS="$MESON_CXXFLAGS" LDFLAGS="$MESON_LDFLAGS" meson -Db_lundef=false -Dlauncher=false build; then
|
2022-07-23 16:09:06 +00:00
|
|
|
cat build/meson-logs/meson-log.txt
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-07-22 00:12:14 +00:00
|
|
|
ninja -C ./build -v
|
2022-08-02 14:41:44 +00:00
|
|
|
$CC $CFLAGS -c -o fuzz-message.o -Isrc -I subprojects/libcstdaux-*/src -std=c11 -D_GNU_SOURCE "$SRC/fuzz-message.c"
|
2022-07-22 00:12:14 +00:00
|
|
|
$CXX $CXXFLAGS -o "$OUT/fuzz-message" \
|
|
|
|
fuzz-message.o \
|
|
|
|
build/src/libbus-static.a \
|
2022-08-02 14:41:44 +00:00
|
|
|
build/subprojects/libcdvar-*/src/libcdvar-*.a \
|
|
|
|
build/subprojects/libcutf8-*/src/libcutf8-*.a \
|
2022-07-22 00:12:14 +00:00
|
|
|
$LIB_FUZZING_ENGINE
|