blob: 6db10f3d8dc9a50689eb9d2358aedc94eb8bc2a1 [file] [log] [blame]
Jim Apple147c2842017-03-18 12:56:50 -07001#!/bin/sh
2
3set -ex
4
5# Wraps autotools.sh, but each binary crashes if it exhibits undefined behavior. See
6# http://releases.llvm.org/3.8.0/tools/clang/docs/UndefinedBehaviorSanitizer.html
7
8# Install a more recent clang than default:
9sudo apt-get update
10sudo apt-get install -y --no-install-recommends clang-3.8 llvm-3.8-dev
11export CC=clang-3.8
12export CXX=clang++-3.8
13
14# Set the undefined behavior flags. This crashes on all undefined behavior except for
15# undefined casting, aka "vptr".
16#
17# TODO: fix undefined vptr behavior and turn this option back on.
18export CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined -fno-sanitize=vptr"
19# Builds without optimization and with debugging symbols for making crash reports more
20# readable.
21export CFLAGS="${CFLAGS} -O0 -ggdb3"
22export CXXFLAGS="${CFLAGS}"
23export UBSAN_OPTIONS=print_stacktrace=1
24
25# llvm-symbolizer must be on PATH, but the above installation instals a binary called
26# "llvm-symbolizer-3.8", not "llvm-symbolizer". This fixes that with a softlink in a new
27# directory.
28CLANG_PATH="$(mktemp -d)"
29trap "rm -rf ${CLANG_PATH}" EXIT
30ln -s "$(whereis llvm-symbolizer-3.8 | rev | cut -d ' ' -f 1 | rev)" \
31 "${CLANG_PATH}/llvm-symbolizer"
32export PATH="${CLANG_PATH}:${PATH}"
33llvm-symbolizer -version
34
35build/docker/scripts/autotools.sh $*