• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 Google Inc.
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# Build native library.
19JVM_INCLUDES="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
20mkdir $OUT/native
21$CXX $CXXFLAGS $JVM_INCLUDES -fPIC -shared \
22    ExampleFuzzerNative.cpp -o $OUT/native/libnative.so
23
24BUILD_CLASSPATH=$JAZZER_API_PATH
25
26# All class files lie in the same directory as the fuzzer at runtime.
27RUNTIME_CLASSPATH=\$this_dir
28
29for fuzzer in $(find $SRC -name '*Fuzzer.java' -or -name '*FuzzerNative.java'); do
30  fuzzer_basename=$(basename -s .java $fuzzer)
31  javac -cp $BUILD_CLASSPATH $fuzzer
32  cp $SRC/$fuzzer_basename.class $OUT/
33
34  if [[ $fuzzer_basename == *FuzzerNative ]]; then
35    driver=jazzer_driver_with_sanitizer
36  else
37    driver=jazzer_driver
38  fi
39
40  cp default.options $OUT/"$fuzzer_basename".options
41  # Create execution wrapper.
42  echo "#!/bin/sh
43# LLVMFuzzerTestOneInput for fuzzer detection.
44this_dir=\$(dirname \"\$0\")
45LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir/native \
46ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \
47\$this_dir/$driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
48--cp=$RUNTIME_CLASSPATH \
49--target_class=$fuzzer_basename \
50--jvm_args=\"-Xmx2048m\" \
51\$@" > $OUT/$fuzzer_basename
52  chmod +x $OUT/$fuzzer_basename
53done
54