Skip to content

Commit e5181e9

Browse files
MONGOCRYPT-731 re-enable ASan tasks (#926)
* relocate misplaced comment. Remove the comment from the YAML folded line to fix applying environment variables. * suppress leak in dlerror. To ignore a "Indirect leak" reported on Ubuntu 22.04 arm64. Assumed not to be an issue in libmongocrypt. * remove unused `build-and-test-asan-s390x` * document purpose of `build-and-test-asan-mac` * set `ENABLE_EXTRA_ALIGNMENT=OFF` for imported libbson. Fixes observed errors on older ASan with older gcc. * print around tests in `pkgconfig-tests.sh` and `linker-tests.sh`. To help identify a failing test. * fix leaks in `_test_mc_FLE2TagAndEncryptedMetadataBlock_validate` * document fix of disabled extra alignment. This may impact downstream consumers. Example: build with imported libbson, then load a different libbson at runtime. This was the case in the pkgconfig tests. Disabling alignment was the default in 1.11 and accidentally changed in 1.12.0. * apply `ENABLE_EXTRA_ALIGNMENT=OFF` in common CMake args for tests. The `macos-1100` distro appears to have a system install of libbson with extra alignment enabled. libmongocrypt detects the system install and defaults to enable extra alignment to try to agree. This commit sets `ENABLE_EXTRA_ALIGNMENT=OFF` for both libbson and libmongocrypt to ensure agreement. * disable extra alignment in `linker-tests.sh` To match libbson recommendeded defaults. --------- Co-authored-by: Ezra Chung <[email protected]>
1 parent a2818d3 commit e5181e9

File tree

7 files changed

+52
-29
lines changed

7 files changed

+52
-29
lines changed

.evergreen/config.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,10 @@ tasks:
403403
- func: "fetch source"
404404
- func: "build and test"
405405
vars:
406+
# Add detect_odr_violation=0 to ASAN_OPTIONS to ignore odr-violation in IntelDFP symbol: __dpml_bid_globals_table
406407
compile_env: >-
407408
${compile_env|}
408409
LIBMONGOCRYPT_EXTRA_CFLAGS="-fsanitize=address -pthread"
409-
# Add detect_odr_violation=0 to ASAN_OPTIONS to ignore odr-violation in IntelDFP symbol: __dpml_bid_globals_table
410410
ASAN_OPTIONS="detect_leaks=1 detect_odr_violation=0"
411411
412412
- name: build-and-test-ubsan
@@ -424,13 +424,7 @@ tasks:
424424
commands:
425425
- func: "fetch source"
426426
- func: "build and test"
427-
vars:
428-
compile_env: ${compile_env|} LIBMONGOCRYPT_EXTRA_CFLAGS="-fsanitize=address"
429-
430-
- name: build-and-test-asan-s390x
431-
commands:
432-
- func: "fetch source"
433-
- func: "build and test"
427+
# Exclude leak detection. clang on macos-11-amd64 reports: "detect_leaks is not supported on this platform"
434428
vars:
435429
compile_env: ${compile_env|} LIBMONGOCRYPT_EXTRA_CFLAGS="-fsanitize=address"
436430

.evergreen/linker-tests.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ linker_tests_deps_root="$EVG_DIR/linker_tests_deps"
2525
rm -rf -- "$linker_tests_root"
2626
mkdir -p "$linker_tests_root"/{install,libmongocrypt-cmake-build,app-cmake-build}
2727

28-
# Make libbson1
28+
echo "Make libbson1 ..."
2929
run_chdir "$linker_tests_root" bash "$EVG_DIR/prep_c_driver_source.sh"
3030
MONGOC_DIR="$linker_tests_root/mongo-c-driver"
3131

@@ -40,8 +40,11 @@ if [ "${MACOS_UNIVERSAL-}" = "ON" ]; then
4040
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'"
4141
fi
4242

43+
# Disable extra alignment in libbson and libmongocrypt to ensure agreement.
44+
# libmongocrypt disables by default, but may enable if a system install of libbson is detected with extra alignment.
4345
common_cmake_args=(
4446
$ADDITIONAL_CMAKE_FLAGS
47+
-DENABLE_EXTRA_ALIGNMENT=OFF
4548
-DCMAKE_BUILD_TYPE=RelWithDebInfo
4649
)
4750

@@ -69,15 +72,17 @@ run_cmake \
6972
"-H$SRC_PATH" \
7073
"-B$BUILD_PATH"
7174
run_cmake --build "$BUILD_PATH" --target install --config RelWithDebInfo
75+
echo "Make libbson1 ... done"
7276

73-
# Prepare libbson2
77+
echo "Prepare libbson2 ..."
7478
run_chdir "$MONGOC_DIR" git reset --hard
7579
run_chdir "$MONGOC_DIR" git apply --ignore-whitespace "$linker_tests_deps_root/bson_patches/libbson2.patch"
7680
# Apply patch to fix compile on RHEL 6.2. TODO: try to remove once RHEL 6.2 is dropped (MONGOCRYPT-688).
7781
run_chdir "$MONGOC_DIR" git apply "$LIBMONGOCRYPT_DIR/etc/libbson-remove-GCC-diagnostic-pragma.patch"
7882
LIBBSON2_SRC_DIR="$MONGOC_DIR"
83+
echo "Prepare libbson2 ... done"
7984

80-
# Build libmongocrypt, static linking against libbson2
85+
echo "Build libmongocrypt, static linking against libbson2 ..."
8186
BUILD_DIR="$linker_tests_root/libmongocrypt-cmake-build"
8287
LMC_INSTALL_PATH="$linker_tests_root/install/libmongocrypt"
8388
SRC_PATH="$LIBMONGOCRYPT_DIR"
@@ -88,8 +93,9 @@ run_cmake \
8893
"-H$SRC_PATH" \
8994
"-B$BUILD_DIR"
9095
run_cmake --build "$BUILD_DIR" --target install --config RelWithDebInfo
96+
echo "Build libmongocrypt, static linking against libbson2 ... done"
9197

92-
echo "Test case: Modelling libmongoc's use"
98+
echo "Test case: Model libmongoc's use ..."
9399
# app links against libbson1.so
94100
# app links against libmongocrypt.so
95101
BUILD_DIR="$linker_tests_root/app-cmake-build"
@@ -118,4 +124,5 @@ check_output () {
118124
echo "ok"
119125
}
120126
check_output ".calling bson_malloc0..from libbson1..calling mongocrypt_binary_new..from libbson2."
127+
echo "Test case: Model libmongoc's use ... done"
121128
exit 0

.evergreen/pkgconfig-tests.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ if [ "$MACOS_UNIVERSAL" = "ON" ]; then
2525
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'"
2626
fi
2727

28+
# Disable extra alignment in libbson and libmongocrypt to ensure agreement.
29+
# libmongocrypt disables by default, but may enable if a system install of libbson is detected with extra alignment.
2830
common_cmake_args=(
2931
-DCMAKE_BUILD_TYPE=RelWithDebInfo
32+
-DENABLE_EXTRA_ALIGNMENT=OFF
3033
$ADDITIONAL_CMAKE_FLAGS
3134
)
3235

@@ -40,6 +43,7 @@ if is_true USE_NINJA; then
4043
bash "$EVG_DIR/ensure-ninja.sh"
4144
fi
4245

46+
echo "Building libbson ..."
4347
libbson_install_dir="$pkgconfig_tests_root/install/libbson"
4448
build_dir="$mongoc_src_dir/_build"
4549
run_cmake -DENABLE_MONGOC=OFF \
@@ -49,8 +53,9 @@ run_cmake -DENABLE_MONGOC=OFF \
4953
-B"$build_dir"
5054
run_cmake --build "$build_dir" --target install --config RelWithDebInfo
5155
libbson_pkg_config_path="$(native_path "$(dirname "$(find "$libbson_install_dir" -name libbson-1.0.pc)")")"
56+
echo "Building libbson ... done"
5257

53-
# Build libmongocrypt, static linking against libbson and configured for the PPA
58+
echo "Build libmongocrypt, static linking against libbson and configured for the PPA ..."
5459
mongocrypt_install_dir="$pkgconfig_tests_root/install/libmongocrypt"
5560
build_dir=$pkgconfig_tests_root/mongocrypt-build
5661
run_cmake -DUSE_SHARED_LIBBSON=OFF \
@@ -60,92 +65,103 @@ run_cmake -DUSE_SHARED_LIBBSON=OFF \
6065
-H"$LIBMONGOCRYPT_DIR" \
6166
-B"$build_dir"
6267
run_cmake --build "$build_dir" --target install --config RelWithDebInfo
68+
echo "Build libmongocrypt, static linking against libbson and configured for the PPA ... done"
6369

6470
# To validate the pkg-config scripts, we don't want the libbson script to be visible
6571
mongocrypt_pkg_config_path="$(native_path "$(dirname "$(find "$mongocrypt_install_dir" -name libmongocrypt.pc)")")"
6672

6773
export PKG_CONFIG_PATH
6874
PKG_CONFIG_PATH="$mongocrypt_pkg_config_path:$libbson_pkg_config_path"
6975

70-
echo "Validating pkg-config scripts"
76+
echo "Validating pkg-config scripts ..."
7177
pkg-config --debug --print-errors --exists libmongocrypt-static
7278
pkg-config --debug --print-errors --exists libmongocrypt
79+
echo "Validating pkg-config scripts ... done"
7380

74-
# Build example-state-machine, static linking against libmongocrypt
81+
echo "Build example-state-machine, static linking against libmongocrypt ..."
7582
gcc $(pkg-config --cflags libmongocrypt-static libbson-static-1.0) \
7683
-o "$pkgconfig_tests_root/example-state-machine" \
7784
"$LIBMONGOCRYPT_DIR/test/example-state-machine.c" \
7885
$(pkg-config --libs libmongocrypt-static)
7986
run_chdir "$LIBMONGOCRYPT_DIR" "$pkgconfig_tests_root/example-state-machine"
87+
echo "Build example-state-machine, static linking against libmongocrypt ... done"
8088

81-
# Build example-no-bson, static linking against libmongocrypt
89+
echo "Build example-no-bson, static linking against libmongocrypt ..."
8290
gcc $(pkg-config --cflags libmongocrypt-static) \
8391
-o "$pkgconfig_tests_root/example-no-bson" \
8492
"$LIBMONGOCRYPT_DIR/test/example-no-bson.c" \
8593
$(pkg-config --libs libmongocrypt-static)
8694
command "$pkgconfig_tests_root/example-no-bson"
95+
echo "Build example-no-bson, static linking against libmongocrypt ... done"
8796

88-
# Build example-state-machine, dynamic linking against libmongocrypt
97+
echo "Build example-state-machine, dynamic linking against libmongocrypt ..."
8998
gcc $(pkg-config --cflags libmongocrypt libbson-static-1.0) \
9099
-o "$pkgconfig_tests_root/example-state-machine" \
91100
"$LIBMONGOCRYPT_DIR/test/example-state-machine.c" \
92101
$(pkg-config --libs libmongocrypt)
93102
run_chdir "$LIBMONGOCRYPT_DIR" \
94103
env LD_LIBRARY_PATH="$mongocrypt_install_dir/lib:$mongocrypt_install_dir/lib64" \
95104
"$pkgconfig_tests_root/example-state-machine"
105+
echo "Build example-state-machine, dynamic linking against libmongocrypt ... done"
96106

97-
# Build example-no-bson, dynamic linking against libmongocrypt
107+
echo "Build example-no-bson, dynamic linking against libmongocrypt ..."
98108
gcc $(pkg-config --cflags libmongocrypt) \
99109
-o "$pkgconfig_tests_root/example-no-bson" \
100110
"$LIBMONGOCRYPT_DIR/test/example-no-bson.c" \
101111
$(pkg-config --libs libmongocrypt)
102112
env LD_LIBRARY_PATH="$mongocrypt_install_dir/lib:$mongocrypt_install_dir/lib64" \
103113
"$pkgconfig_tests_root/example-no-bson"
114+
echo "Build example-no-bson, dynamic linking against libmongocrypt ... done"
104115

105116
# Clean up prior to next execution
106117
rm -r "$mongocrypt_install_dir"
107118

108-
# Build libmongocrypt, dynamic linking against libbson
119+
echo "Build libmongocrypt, dynamic linking against libbson ..."
109120
run_cmake -DUSE_SHARED_LIBBSON=ON \
110121
-DENABLE_BUILD_FOR_PPA=OFF \
111122
"${common_cmake_args[@]}" \
112123
-DCMAKE_INSTALL_PREFIX="$mongocrypt_install_dir" \
113124
-H"$LIBMONGOCRYPT_DIR" \
114125
-B"$build_dir"
115126
run_cmake --build "$build_dir" --target install --config RelWithDebInfo
127+
echo "Build libmongocrypt, dynamic linking against libbson ... done"
116128

117-
# Build example-state-machine, static linking against libmongocrypt
129+
echo "Build example-state-machine, static linking against libmongocrypt ..."
118130
gcc $(pkg-config --cflags libmongocrypt-static libbson-static-1.0) \
119131
-o "$pkgconfig_tests_root/example-state-machine" \
120132
"$LIBMONGOCRYPT_DIR/test/example-state-machine.c" \
121133
$(pkg-config --libs libmongocrypt-static)
122134
run_chdir "$LIBMONGOCRYPT_DIR" \
123135
env LD_LIBRARY_PATH="$libbson_install_dir/lib:/$libbson_install_dir/lib64" \
124136
"$pkgconfig_tests_root/example-state-machine"
137+
echo "Build example-state-machine, static linking against libmongocrypt ..."
125138

126-
# Build example-no-bson, static linking against libmongocrypt
139+
echo "Build example-no-bson, static linking against libmongocrypt ..."
127140
gcc $(pkg-config --cflags libmongocrypt-static) \
128141
-o "$pkgconfig_tests_root/example-no-bson" \
129142
"$LIBMONGOCRYPT_DIR/test/example-no-bson.c" \
130143
$(pkg-config --libs libmongocrypt-static)
131144
env LD_LIBRARY_PATH="$libbson_install_dir/lib:/$libbson_install_dir/lib64" \
132145
"$pkgconfig_tests_root/example-no-bson"
146+
echo "Build example-no-bson, static linking against libmongocrypt ... done"
133147

134-
# Build example-state-machine, dynamic linking against libmongocrypt
148+
echo "Build example-state-machine, dynamic linking against libmongocrypt ..."
135149
gcc $(pkg-config --cflags libmongocrypt libbson-static-1.0) \
136150
-o "$pkgconfig_tests_root/example-state-machine" \
137151
"$LIBMONGOCRYPT_DIR/test/example-state-machine.c" \
138152
$(pkg-config --libs libmongocrypt)
139153
run_chdir "$LIBMONGOCRYPT_DIR" \
140154
env LD_LIBRARY_PATH="$mongocrypt_install_dir/lib:$mongocrypt_install_dir/lib64:$libbson_install_dir/lib:$libbson_install_dir/lib64" \
141155
"$pkgconfig_tests_root/example-state-machine"
156+
echo "Build example-state-machine, dynamic linking against libmongocrypt ... done"
142157

143-
# Build example-no-bson, dynamic linking against libmongocrypt
158+
echo "Build example-no-bson, dynamic linking against libmongocrypt ..."
144159
gcc $(pkg-config --cflags libmongocrypt) \
145160
-o "$pkgconfig_tests_root/example-no-bson" \
146161
"$LIBMONGOCRYPT_DIR/test/example-no-bson.c" \
147162
$(pkg-config --libs libmongocrypt)
148163
env LD_LIBRARY_PATH="$mongocrypt_install_dir/lib:$mongocrypt_install_dir/lib64:$libbson_install_dir/lib:$libbson_install_dir/lib64" \
149164
"$pkgconfig_tests_root/example-no-bson"
165+
echo "Build example-no-bson, dynamic linking against libmongocrypt ... done"
150166

151167
echo "pkg-config tests PASS"

.lsan-suppressions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ leak:ccrng_cryptographic_generate
33
leak:CRYPTO_zalloc
44
# Ignore leak reported in dlopen error.
55
leak:_dlerror_run
6+
leak:_dlerror

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ChangeLog
22
## 1.13.0 (Not yet released)
3+
### Fixed
4+
- Restore default behavior to disable extra alignment when importing libbson. This was the default behavior in 1.11. This can be overridden by setting the CMake option `ENABLE_EXTRA_ALIGNMENT=ON`.
35
### Removed
46
- Support for macOS versions older than 11. libmongocrypt is supported and tested with macOS 11+.
57

@@ -9,6 +11,8 @@
911
- Add opt-in retry behavior for KMS operations (`mongocrypt_setopt_retry_kms`)
1012
### Removed
1113
- libmongocrypt is no longer published in the MongoDB package repository for RHEL 6. libmongocrypt may instead be built from source on RHEL 6, but support for RHEL 6 will be dropped in a future release.
14+
### Notes
15+
- This release unintentionally changes the default behavior of extra alignment with importing libbson. See 1.13.0 release notes.
1216

1317
## 1.11.0
1418
### New features

cmake/ImportBSON.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ cmake_push_check_state ()
5656
# extra-alignment enabled. We want to match that setting as our default, for convenience
5757
# purposes only.
5858
find_path (SYSTEM_BSON_INCLUDE_DIR bson/bson.h PATH_SUFFIXES libbson-1.0)
59+
set (_extra_alignment_default OFF)
5960
if (SYSTEM_BSON_INCLUDE_DIR AND NOT DEFINED ENABLE_EXTRA_ALIGNMENT)
6061
set (CMAKE_REQUIRED_INCLUDES "${SYSTEM_BSON_INCLUDE_DIR}")
61-
set (_extra_alignment_default OFF)
6262
check_c_source_compiles ([[
6363
#include <bson/bson.h>
6464
@@ -140,10 +140,8 @@ function (_import_bson)
140140
set (ENABLE_SNAPPY OFF CACHE BOOL "Toggle snappy for the mongoc subproject (not required by libmongocrypt)")
141141
# Disable deprecated automatic init and cleanup. (May be overridden by the user)
142142
set (ENABLE_AUTOMATIC_INIT_AND_CLEANUP OFF CACHE BOOL "Enable automatic init and cleanup (GCC only)")
143-
if (DEFINED _extra_alignment_default)
144-
# Disable over-alignment of bson types. (May be overridden by the user)
145-
set (ENABLE_EXTRA_ALIGNMENT ${_extra_alignment_default} CACHE BOOL "Toggle extra alignment of bson_t")
146-
endif ()
143+
# Disable over-alignment of bson types. (May be overridden by the user)
144+
set (ENABLE_EXTRA_ALIGNMENT ${_extra_alignment_default} CACHE BOOL "Toggle extra alignment of bson_t")
147145
# We don't want the subproject to find libmongocrypt
148146
set (ENABLE_CLIENT_SIDE_ENCRYPTION OFF CACHE BOOL "Disable client-side encryption for the libmongoc subproject")
149147
# Clear `BUILD_VERSION` so C driver does not use a `BUILD_VERSION` meant for libmongocrypt.

test/test-mc-fle2-tag-and-encrypted-metadata-block.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ static void _test_mc_FLE2TagAndEncryptedMetadataBlock_validate(_mongocrypt_teste
7878

7979
// Metadata block should be valid.
8080
ASSERT(mc_FLE2TagAndEncryptedMetadataBlock_validate(&metadata, status));
81+
_mongocrypt_buffer_cleanup(&input);
82+
mc_FLE2TagAndEncryptedMetadataBlock_cleanup(&metadata);
83+
mongocrypt_status_destroy(status);
8184
}
8285

8386
#undef TEST_TAG_AND_ENCRYPTED_METADATA_BLOCK
8487

8588
void _mongocrypt_tester_install_fle2_tag_and_encrypted_metadata_block(_mongocrypt_tester_t *tester) {
8689
INSTALL_TEST(_test_mc_FLE2TagAndEncryptedMetadataBlock_roundtrip);
8790
INSTALL_TEST(_test_mc_FLE2TagAndEncryptedMetadataBlock_validate);
88-
}
91+
}

0 commit comments

Comments
 (0)