-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
precompile_centipede
executable file
·49 lines (42 loc) · 1.92 KB
/
precompile_centipede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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.
#
################################################################################
echo -n "Precompiling centipede"
# Build Centipede with bazel.
cd "$SRC/fuzztest/centipede/"
apt-get update && apt-get install libssl-dev -y
unset CXXFLAGS CFLAGS
# We need to use an older version of BAZEL because fuzztest relies on WORKSPACE
# Ref: https://github.com/google/oss-fuzz/pull/12838#issue-2733821058
export USE_BAZEL_VERSION=7.4.0
echo 'build --cxxopt=-stdlib=libc++ --linkopt=-lc++' >> /tmp/centipede.bazelrc
bazel --bazelrc=/tmp/centipede.bazelrc build -c opt :all
unset USE_BAZEL_VERSION
# Prepare the weak symbols:
# This is necessary because we compile the target binary and the intermediate
# auxiliary binaries with the same cflags. The auxiliary binaries do not need
# data-flow tracing flags, but will still throw errors when they cannot find
# the corresponding functions.
# The weak symbols provides fake implementations for intermediate binaries.
$CXX "$SRC/fuzztest/centipede/weak_sancov_stubs.cc" -c -o "$SRC/fuzztest/centipede/weak.o"
echo 'Removing extra stuff leftover to avoid bloating image.'
rm -rf /clang-*.tgz /clang
BAZEL_BIN_REAL_DIR=$(readlink -f $CENTIPEDE_BIN_DIR)
rm -rf $CENTIPEDE_BIN_DIR
mkdir -p $CENTIPEDE_BIN_DIR
mv $BAZEL_BIN_REAL_DIR/centipede/{centipede,libcentipede_runner.pic.a} $CENTIPEDE_BIN_DIR
rm -rf /root/.cache
echo 'Done.'