forked from apache/thrift
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
THRIFT-2026: Eliminate some undefined behavior in C/C++
Clients: glib, C++ Patch: Jim Apple <jbapple-impala@apache.org> This closes apache#1214 This patch fixes some undefined behavior were found using Clang's UndefinedBehaviorSanitizer (UBSan). To check for undefined behavior, run /build/docker/scripts/ubsan.sh. This is run during CI builds, as well. The examples of the types of undefined behavior fixed in this commit are: 1. Enumerations exhibit undefined behavior when they have values outside of a range dependent on the values of their enumerators, as specified in C++14's chapter 7.2 ("Enumeration declarations"), paragraph 8. 2. Left shift of negative values, used in zigzag encoding, is undefined behavior. See 5.8 ("Shift operators"), paragraph 2 for C++ and 6.5.7 ("Bitwise shift operators"), paragraph 4 for C99 and C11.
- Loading branch information
1 parent
6c08ac7
commit 147c284
Showing
7 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
# Wraps autotools.sh, but each binary crashes if it exhibits undefined behavior. See | ||
# http://releases.llvm.org/3.8.0/tools/clang/docs/UndefinedBehaviorSanitizer.html | ||
|
||
# Install a more recent clang than default: | ||
sudo apt-get update | ||
sudo apt-get install -y --no-install-recommends clang-3.8 llvm-3.8-dev | ||
export CC=clang-3.8 | ||
export CXX=clang++-3.8 | ||
|
||
# Set the undefined behavior flags. This crashes on all undefined behavior except for | ||
# undefined casting, aka "vptr". | ||
# | ||
# TODO: fix undefined vptr behavior and turn this option back on. | ||
export CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined -fno-sanitize=vptr" | ||
# Builds without optimization and with debugging symbols for making crash reports more | ||
# readable. | ||
export CFLAGS="${CFLAGS} -O0 -ggdb3" | ||
export CXXFLAGS="${CFLAGS}" | ||
export UBSAN_OPTIONS=print_stacktrace=1 | ||
|
||
# llvm-symbolizer must be on PATH, but the above installation instals a binary called | ||
# "llvm-symbolizer-3.8", not "llvm-symbolizer". This fixes that with a softlink in a new | ||
# directory. | ||
CLANG_PATH="$(mktemp -d)" | ||
trap "rm -rf ${CLANG_PATH}" EXIT | ||
ln -s "$(whereis llvm-symbolizer-3.8 | rev | cut -d ' ' -f 1 | rev)" \ | ||
"${CLANG_PATH}/llvm-symbolizer" | ||
export PATH="${CLANG_PATH}:${PATH}" | ||
llvm-symbolizer -version | ||
|
||
build/docker/scripts/autotools.sh $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters