• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2018 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# Ignore memory leaks from python scripts invoked in the build
19export ASAN_OPTIONS="detect_leaks=0"
20export MSAN_OPTIONS="halt_on_error=0:exitcode=0:report_umrs=0"
21
22# Remove -pthread from CFLAGS, this trips up ./configure
23# which thinks pthreads are available without any CLI flags
24CFLAGS=${CFLAGS//"-pthread"/}
25
26FLAGS=()
27case $SANITIZER in
28  address)
29    FLAGS+=("--with-address-sanitizer")
30    ;;
31  memory)
32    FLAGS+=("--with-memory-sanitizer")
33    # installing ensurepip takes a while with MSAN instrumentation, so
34    # we disable it here
35    FLAGS+=("--without-ensurepip")
36    ;;
37  undefined)
38    FLAGS+=("--with-undefined-behavior-sanitizer")
39    ;;
40esac
41
42pushd $SRC/Python-3.8.3/
43if [ -e $OUT/sanpy/cflags -a "$(cat $OUT/sanpy/cflags)" = "${CFLAGS}" ] ; then
44    echo 'Python cflags unchanged, no need to rebuild'
45else
46    rm -rf $OUT/sanpy
47    ./configure "${FLAGS[@]:-}" \
48                --prefix=$OUT/sanpy CFLAGS="${CFLAGS}" LINKCC="${CXX}" \
49                LDFLAGS="${CXXFLAGS}"
50    grep -v HAVE_GETC_UNLOCKED < pyconfig.h > tmp && mv tmp pyconfig.h
51    make && make install
52    echo "${CFLAGS}" > $OUT/sanpy/cflags
53fi
54popd
55
56cd contrib/fuzz
57make clean oss-fuzz PYTHON_CONFIG=$OUT/sanpy/bin/python3.8-config PYTHON_CONFIG_FLAGS="--ldflags --embed"
58