Skip to content

Commit 0bdfd5e

Browse files
xhochywesm
authored andcommitted
ARROW-538: [C++] Set up AddressSanitizer (ASAN) builds
Most of the infrastructure was already in place, only needed to fix the gtest build. We will now build with AddressSanitizer activated on OSX. Author: Uwe L. Korn <uwelk@xhochy.com> Closes apache#324 from xhochy/ARROW-538 and squashes the following commits: c2f8dda [Uwe L. Korn] Don't run AddressSanitizer on Travis f6b65e5 [Uwe L. Korn] Explicitly detected 3.6 8a20d91 [Uwe L. Korn] Log detected COMPILER_VERSION in error message acf3f69 [Uwe L. Korn] ARROW-538: [C++] Set up AddressSanitizer (ASAN) builds
1 parent 4440e40 commit 0bdfd5e

8 files changed

Lines changed: 43 additions & 7 deletions

File tree

cpp/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,12 @@ if(ARROW_BUILD_TESTS)
428428

429429
if("$ENV{GTEST_HOME}" STREQUAL "")
430430
if(APPLE)
431-
set(GTEST_CMAKE_CXX_FLAGS "-fPIC -std=c++11 -stdlib=libc++ -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-value -Wno-ignored-attributes")
431+
set(GTEST_CMAKE_CXX_FLAGS "-fPIC -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-value -Wno-ignored-attributes")
432432
else()
433433
set(GTEST_CMAKE_CXX_FLAGS "-fPIC")
434434
endif()
435+
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_BUILD_TYPE)
436+
set(GTEST_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}} ${GTEST_CMAKE_CXX_FLAGS}")
435437

436438
set(GTEST_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/googletest_ep-prefix/src/googletest_ep")
437439
set(GTEST_INCLUDE_DIR "${GTEST_PREFIX}/include")

cpp/build-support/run-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function setup_sanitizers() {
8282

8383
# Enable leak detection even under LLVM 3.4, where it was disabled by default.
8484
# This flag only takes effect when running an ASAN build.
85-
ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks=1"
86-
export ASAN_OPTIONS
85+
# ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks=1"
86+
# export ASAN_OPTIONS
8787

8888
# Set up suppressions for LeakSanitizer
8989
LSAN_OPTIONS="$LSAN_OPTIONS suppressions=$ROOT/build-support/lsan-suppressions.txt"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Workaround for a problem with gmock where a runtime error is caused by a call on a null pointer,
19+
# on a mocked object.
20+
# Seen error:
21+
# thirdparty/gmock-1.7.0/include/gmock/gmock-spec-builders.h:1529:12: runtime error: member call on null pointer of type 'testing::internal::ActionResultHolder<void>'
22+
fun:*testing*internal*InvokeWith*

cpp/cmake_modules/CompilerInfo.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang version.*")
3030
set(COMPILER_FAMILY "clang")
3131
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1"
3232
COMPILER_VERSION "${COMPILER_VERSION_FULL}")
33+
34+
# LLVM 3.6 on Mac OS X 10.9 and later
35+
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*based on LLVM 3\\.6\\..*")
36+
set(COMPILER_FAMILY "clang")
37+
set(COMPILER_VERSION "3.6.0svn")
38+
3339
# clang on Mac OS X 10.9 and later
3440
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*based on LLVM.*")
3541
set(COMPILER_FAMILY "clang")

cpp/cmake_modules/san-config.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ if ("${ARROW_USE_UBSAN}" OR "${ARROW_USE_ASAN}" OR "${ARROW_USE_TSAN}")
9494
# Require clang 3.4 or newer; clang 3.3 has issues with TSAN and pthread
9595
# symbol interception.
9696
if("${COMPILER_VERSION}" VERSION_LESS "3.4")
97-
message(SEND_ERROR "Must use clang 3.4 or newer to run a sanitizer build."
98-
" Try using clang from $NATIVE_TOOLCHAIN/")
97+
message(SEND_ERROR "Must use clang 3.4 or newer to run a sanitizer build."
98+
" Detected unsupported version ${COMPILER_VERSION}."
99+
" Try using clang from $NATIVE_TOOLCHAIN/.")
99100
endif()
100101
add_definitions("-fsanitize-blacklist=${BUILD_SUPPORT_DIR}/sanitize-blacklist.txt")
101102
else()

cpp/src/arrow/buffer-test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ TEST_F(TestBuffer, Resize) {
6767
}
6868

6969
TEST_F(TestBuffer, ResizeOOM) {
70+
// This test doesn't play nice with AddressSanitizer
71+
#ifndef ADDRESS_SANITIZER
7072
// realloc fails, even though there may be no explicit limit
7173
PoolBuffer buf;
7274
ASSERT_OK(buf.Resize(100));
7375
int64_t to_alloc = std::numeric_limits<int64_t>::max();
7476
ASSERT_RAISES(OutOfMemory, buf.Resize(to_alloc));
77+
#endif
7578
}
7679

7780
TEST_F(TestBuffer, EqualsWithSameContent) {

cpp/src/arrow/memory_pool-test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ TEST_F(TestDefaultMemoryPool, MemoryTracking) {
3232
}
3333

3434
TEST_F(TestDefaultMemoryPool, OOM) {
35+
#ifndef ADDRESS_SANITIZER
3536
this->TestOOM();
37+
#endif
3638
}
3739

3840
TEST_F(TestDefaultMemoryPool, Reallocate) {
@@ -41,7 +43,7 @@ TEST_F(TestDefaultMemoryPool, Reallocate) {
4143

4244
// Death tests and valgrind are known to not play well 100% of the time. See
4345
// googletest documentation
44-
#ifndef ARROW_VALGRIND
46+
#if !(defined(ARROW_VALGRIND) || defined(ADDRESS_SANITIZER))
4547

4648
TEST(DefaultMemoryPoolDeathTest, FreeLargeMemory) {
4749
MemoryPool* pool = default_memory_pool();

python/manylinux1/Dockerfile-x86_64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FROM quay.io/pypa/manylinux1_x86_64:latest
1616
RUN yum install -y flex openssl-devel
1717

1818
WORKDIR /
19-
RUN wget http://downloads.sourceforge.net/project/boost/boost/1.60.0/boost_1_60_0.tar.gz -O /boost_1_60_0.tar.gz
19+
RUN wget --no-check-certificate http://downloads.sourceforge.net/project/boost/boost/1.60.0/boost_1_60_0.tar.gz -O /boost_1_60_0.tar.gz
2020
RUN tar xf boost_1_60_0.tar.gz
2121
WORKDIR /boost_1_60_0
2222
RUN ./bootstrap.sh

0 commit comments

Comments
 (0)