Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .mci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ variables:

## cdriver configure flags
cdriver_configure_flags:
linux_cdriver_configure_flags: &linux_cdriver_configure_flags --enable-ssl --enable-sasl
linux_cdriver_configure_flags: &linux_cdriver_configure_flags --enable-ssl --enable-sasl --with-gnu-ld CFLAGS=-fno-omit-frame-pointer
osx_cdriver_configure_flags: &osx_cdriver_configure_flags --enable-ssl --enable-sasl

## cmake flag variables
cmake_flags:
ubuntu_cmake_flags: &ubuntu_cmake_flags -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wno-attributes -Werror -Wno-error=missing-field-initializers"
osx_cmake_flags: &osx_cmake_flags -DCMAKE_CXX_FLAGS="-stdlib=libc++ -Wall -Wextra -Wno-attributes -Werror -Wno-error=missing-field-initializers" -DBSONCXX_POLY_USE_BOOST=ON
asan_cmake_flags: &asan_cmake_flags -DCMAKE_CXX_FLAGS="-fsanitize=address -O1 -fno-omit-frame-pointer -Wall -Wextra -Wno-attributes -Werror -Wno-error=missing-field-initializers -Wno-error=maybe-uninitialized"
ubsan_cmake_flags: &ubsan_cmake_flags -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_CXX_FLAGS="-fsanitize=undefined -g -fno-omit-frame-pointer -fsanitize-blacklist=$(pwd)/../etc/ubsan.blacklist -fno-sanitize-recover -Wall -Wextra -Wno-attributes -Werror -Wno-error=missing-field-initializers"
ubuntu_cmake_flags: &ubuntu_cmake_flags -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -Wno-error=missing-field-initializers"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify the following:

  • Do we want -Wno-attributes?
  • Do we need -Wno-error=missing-field-initializers?
  • Do the defaults for these change flags over the different compiler versions we're building with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Re -Wno-attributes: I'm not sure why it was here, but, empirically, it seems not needed, so I removed it.
  • We do seem to need the one about missing field initializers, since the 14.04 GCC seems to have a bug.
  • I'm not sure about the defaults, but I'd expect no. Ideally, we would not build with the -Wno-error=missing-field-initializers, because I'd like to have that warning. But we seem to get false positives with it on 14.04 GCC.

osx_cmake_flags: &osx_cmake_flags -DCMAKE_CXX_FLAGS="-stdlib=libc++ -Wall -Wextra -Werror" -DBSONCXX_POLY_USE_BOOST=ON
asan_cmake_flags: &asan_cmake_flags -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -fsanitize=address -O1 -g -fno-omit-frame-pointer -Wall -Wextra -Werror"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions:

  • What are the version numbers for the old and new versions of the gcc toolchain (the one we were using and the one we will be using, respectively)?
  • From reading https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html, I'm guessing that you're setting _GLIBCXX_USE_CXX11_ABI to zero to fix linker errors when linking against a third-party library that the driver depends on. Which library, out of curiosity, if you know offhand? Relatedly, do most C++ library packages that ship with Ubuntu 16.04 link against the old ABI or the new ABI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • From distrowatch, 14.10 used GCC 4.9.1, and 16.4 uses GCC 5.3.1.
  • Actually, I'm setting that because what we are doing here is using clang to build against libstdc++. The clang versions on these systems does not understand the attributes that newer libstdc++ uses to tag the ABI, so we need to force our view of the libstdc++ headers to be the old ABI.

ubsan_cmake_flags: &ubsan_cmake_flags -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -fsanitize=undefined -fsanitize-blacklist=$(pwd)/../etc/ubsan.blacklist -fno-sanitize-recover=undefined -O1 -g -fno-omit-frame-pointer -Wall -Wextra -Werror"

## test parameters
test_params:
asan_test_params: &asan_test_params ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.5 ASAN_OPTIONS="detect_leaks=1"
ubsan_test_params: &ubsan_test_params UBSAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer UBSAN_OPTIONS="print_stacktrace=1"
asan_test_params: &asan_test_params PATH="/usr/lib/llvm-3.8/bin" ASAN_OPTIONS="detect_leaks=1"
ubsan_test_params: &ubsan_test_params PATH="usr/lib/llvm-3.8/bin" UBSAN_OPTIONS="print_stacktrace=1"
valgrind_test_params: &valgrind_test_params valgrind --leak-check=full --track-origins=yes --num-callers=50 --error-exitcode=1 --error-limit=no --read-var-info=yes --suppressions=../etc/memcheck.suppressions


Expand Down Expand Up @@ -79,7 +79,7 @@ functions:
cd mongo-c-driver
git checkout 1.3.4
rm -rf /data/tmp/c-driver-install
./autogen.sh --prefix="/data/tmp/c-driver-install" --enable-tests=no --enable-examples=no --with-libbson=bundled --disable-extra-align ${cdriver_configure_flags}
./autogen.sh --prefix="/data/tmp/c-driver-install" --enable-tests=no --enable-examples=no --with-libbson=bundled --disable-extra-align --enable-debug --enable-optimizations --disable-shm-counters --disable-static --disable-dependency-tracking --with-pic --disable-automatic-init-and-cleanup ${cdriver_configure_flags}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this change is mostly to increase diagnosability of C driver issues during test failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly, yes. Also to make sure that we control the behavior of cleanup programmatically. And a few flags to make the C driver build smaller and leaner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disable-automatic-init-and-cleanup turns off mongoc's use of gcc's constructor/destructor attributes, so that cleanup happens only when we call it, not at some indeterminate time (possibly before we call it, leading to a runtime exception when we call it again).

make ${compile_concurrency}
make install

Expand Down Expand Up @@ -200,8 +200,8 @@ buildvariants:
tasks:
- name: compile_and_test

- name: ubuntu1410-debug-valgrind
display_name: "Valgrind Ubuntu 14.10 Debug"
- name: ubuntu1604-debug-valgrind
display_name: "Valgrind Ubuntu 16.04 Debug"
expansions:
build_type: "Debug"
source: *ubuntu_source
Expand All @@ -212,12 +212,12 @@ buildvariants:
cmake_flags: *ubuntu_cmake_flags
test_params: *valgrind_test_params
run_on:
- ubuntu1410-build
- ubuntu1604-build
tasks:
- name: compile_and_test

- name: ubuntu1410-debug-asan
display_name: "ASAN Ubuntu 14.10 Debug"
- name: ubuntu1604-debug-asan
display_name: "ASAN Ubuntu 16.04 Debug"
expansions:
build_type: "Debug"
source: *ubuntu_source
Expand All @@ -228,12 +228,12 @@ buildvariants:
cmake_flags: *asan_cmake_flags
test_params: *asan_test_params
run_on:
- ubuntu1410-build
- ubuntu1604-build
tasks:
- name: compile_and_test

- name: ubuntu1410-debug-ubsan
display_name: "UBSAN Ubuntu 14.10 Debug"
- name: ubuntu1604-debug-ubsan
display_name: "UBSAN Ubuntu 16.04 Debug"
expansions:
build_type: "Debug"
source: *ubuntu_source
Expand All @@ -244,6 +244,6 @@ buildvariants:
cmake_flags: *ubsan_cmake_flags
test_params: *ubsan_test_params
run_on:
- ubuntu1410-build
- ubuntu1604-build
tasks:
- name: compile_and_test
12 changes: 12 additions & 0 deletions src/mongocxx/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

#include <mongocxx/config/private/prelude.hpp>

#if !defined(__has_feature)
#define __has_feature(x) 0
#endif

namespace mongocxx {
MONGOCXX_INLINE_NAMESPACE_BEGIN

Expand Down Expand Up @@ -96,7 +100,15 @@ class instance::impl {
if (_user_logger) {
libmongoc::log_set_handler(null_log_handler, nullptr);
}

// Under ASAN, we don't want to clean up libmongoc, because it causes libraries to become
// unloaded, and then ASAN sees non-rooted allocations that it consideres leaks. These are
// also inscrutable, because the stack refers into an unloaded library, which ASAN can't
// report. Note that this only works if we have built mongoc so that it doesn't do its
// unfortunate automatic invocation of 'cleanup'.
#if !__has_feature(address_sanitizer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if there are any related C driver feature requests we could make, such that we would be able to get rid of this #if were they to be implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I think what is happening is that the cleanup routines for one of the libraries that the C driver is calling is itself dlclose'ing some other library. We aren't actually building the C driver under ASAN, either. Perhaps we should? But not in this ticket.

libmongoc::cleanup();
#endif
}

const std::unique_ptr<logger> _user_logger;
Expand Down
2 changes: 1 addition & 1 deletion src/mongocxx/test/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TEST_CASE(
ssl_opts.crl_file(crl_file);
ssl_opts.allow_invalid_certificates(allow_invalid_certificates);

::mongoc_ssl_opt_t interposed = {0};
::mongoc_ssl_opt_t interposed = {};

client_pool_set_ssl_opts->interpose(
[&](::mongoc_client_pool_t*, const ::mongoc_ssl_opt_t* opts) {
Expand Down