blob: d39cc8361d238a94fcc194b61e9a47ebcd68877c [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.
Jim Apple117a5cc2017-03-29 20:39:36 -070018export CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined"
Jim Apple147c2842017-03-18 12:56:50 -070019# 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 $*