summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct1
-rw-r--r--src/mongo/SConscript12
-rw-r--r--src/mongo/util/boost_assert_impl.cpp53
-rw-r--r--src/mongo/util/boost_assert_shim.cpp60
-rw-r--r--src/mongo/util/boost_assert_shim.h49
-rw-r--r--src/third_party/boost-1.70.0/SConscript58
6 files changed, 215 insertions, 18 deletions
diff --git a/SConstruct b/SConstruct
index a14cc81545e..3ceddb572fc 100644
--- a/SConstruct
+++ b/SConstruct
@@ -3288,6 +3288,7 @@ def doConfigure(myenv):
CPPDEFINES=[
"BOOST_SYSTEM_NO_DEPRECATED",
"BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS",
+ "BOOST_ENABLE_ASSERT_DEBUG_HANDLER",
"ABSL_FORCE_ALIGNED_ACCESS",
]
)
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index bc9a38c38cf..b53638e499b 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -115,6 +115,7 @@ env.Library(
'util/allocator.cpp',
'util/assert_util.cpp',
'util/base64.cpp',
+ 'util/boost_assert_impl.cpp',
'util/concurrency/idle_thread_block.cpp',
'util/concurrency/thread_name.cpp',
'util/duration.cpp',
@@ -150,6 +151,7 @@ env.Library(
'$BUILD_DIR/third_party/shim_fmt',
'$BUILD_DIR/third_party/shim_intel_decimal128',
'$BUILD_DIR/third_party/shim_pcrecpp',
+ 'boost_assert_shim',
'util/quick_exit',
],
LIBDEPS_PRIVATE=[
@@ -157,6 +159,16 @@ env.Library(
],
)
+# Shim library for boost to depend on
+env.Library(
+ target='boost_assert_shim',
+ source=[
+ 'util/boost_assert_shim.cpp'
+ ],
+ # NOTE: This library *must not* depend on any mongodb code
+ LIBDEPS=[],
+)
+
js_engine_ver = get_option("js-engine") if get_option("server-js") == "on" else "none"
# On windows, we need to escape the backslashes in the command-line
diff --git a/src/mongo/util/boost_assert_impl.cpp b/src/mongo/util/boost_assert_impl.cpp
new file mode 100644
index 00000000000..a541f7993da
--- /dev/null
+++ b/src/mongo/util/boost_assert_impl.cpp
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/util/assert_util.h"
+#include "mongo/util/boost_assert_shim.h"
+
+#if defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG)
+
+namespace mongo {
+struct BoostAssertImpl {
+ BoostAssertImpl() {
+ BoostAssertFuncs::global().assertFunc =
+ [](char const* expr, char const* function, char const* file, long line) {
+ invariantFailed(expr, file, line);
+ };
+
+ BoostAssertFuncs::global().assertMsgFunc = [](
+ char const* expr, char const* msg, char const* function, char const* file, long line) {
+ invariantFailedWithMsg(expr, msg, file, line);
+ };
+ }
+};
+
+BoostAssertImpl installBoostAssertCallbacks;
+} // namespace mongo
+
+#endif // BOOST_ENABLE_ASSERT_DEBUG_HANDLER && !NDEBUG
diff --git a/src/mongo/util/boost_assert_shim.cpp b/src/mongo/util/boost_assert_shim.cpp
new file mode 100644
index 00000000000..2214215cdd2
--- /dev/null
+++ b/src/mongo/util/boost_assert_shim.cpp
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "boost_assert_shim.h"
+
+#if defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG)
+
+#include <boost/assert.hpp>
+
+namespace mongo {
+BoostAssertFuncs& BoostAssertFuncs::global() {
+ static BoostAssertFuncs funcs;
+ return funcs;
+}
+} // namespace mongo
+
+namespace boost {
+void assertion_failed(char const* expr, char const* function, char const* file, long line) {
+ auto assertFunc = ::mongo::BoostAssertFuncs::global().assertFunc;
+ if (!assertFunc)
+ std::terminate();
+ assertFunc(expr, function, file, line);
+}
+
+void assertion_failed_msg(
+ char const* expr, char const* msg, char const* function, char const* file, long line) {
+ auto assertMsgFunc = ::mongo::BoostAssertFuncs::global().assertMsgFunc;
+ if (!assertMsgFunc)
+ std::terminate();
+ assertMsgFunc(expr, msg, function, file, line);
+}
+
+} // namespace boost
+#endif // BOOST_ENABLE_ASSERT_DEBUG_HANDLER && !NDEBUG
diff --git a/src/mongo/util/boost_assert_shim.h b/src/mongo/util/boost_assert_shim.h
new file mode 100644
index 00000000000..392672074c6
--- /dev/null
+++ b/src/mongo/util/boost_assert_shim.h
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#if defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG)
+#include <functional>
+
+namespace mongo {
+struct BoostAssertFuncs {
+ std::function<void(char const* expr, char const* function, char const* file, long line)>
+ assertFunc;
+ std::function<void(
+ char const* expr, char const* msg, char const* function, char const* file, long line)>
+ assertMsgFunc;
+
+ static BoostAssertFuncs& global();
+
+private:
+ BoostAssertFuncs() = default;
+};
+
+} // namespace mongo
+
+#endif // BOOST_ENABLE_ASSERT_DEBUG_HANDLER && !NDEBUG
diff --git a/src/third_party/boost-1.70.0/SConscript b/src/third_party/boost-1.70.0/SConscript
index 0a5abb6dc4c..abf73c7d95e 100644
--- a/src/third_party/boost-1.70.0/SConscript
+++ b/src/third_party/boost-1.70.0/SConscript
@@ -9,9 +9,19 @@ env = env.Clone()
if env.ToolchainIs('GCC'):
env.AppendUnique(CXXFLAGS=['-Wno-overloaded-virtual'])
-env.Library('boost_system', ['libs/system/src/error_code.cpp'])
+env.Library(
+ target='boost_system',
+ source=[
+ 'libs/system/src/error_code.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/boost_assert_shim',
+ ],
+)
-env.Library('boost_filesystem', [
+env.Library(
+ target='boost_filesystem',
+ source=[
'libs/filesystem/src/codecvt_error_category.cpp',
'libs/filesystem/src/operations.cpp',
'libs/filesystem/src/path.cpp',
@@ -20,12 +30,16 @@ env.Library('boost_filesystem', [
'libs/filesystem/src/unique_path.cpp',
'libs/filesystem/src/utf8_codecvt_facet.cpp',
'libs/filesystem/src/windows_file_codecvt.cpp',
- ],
- LIBDEPS=[
- 'boost_system',
- ])
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/boost_assert_shim',
+ 'boost_system',
+ ],
+)
-env.Library('boost_program_options', [
+env.Library(
+ target='boost_program_options',
+ source=[
'libs/program_options/src/cmdline.cpp',
'libs/program_options/src/config_file.cpp',
'libs/program_options/src/convert.cpp',
@@ -37,17 +51,25 @@ env.Library('boost_program_options', [
'libs/program_options/src/value_semantic.cpp',
'libs/program_options/src/variables_map.cpp',
'libs/program_options/src/winmain.cpp',
- ],
- # Because `::environ` is resolved in `/usr/lib/crt1.o` on FreeBSD, this library needs to be
- # marked `incomplete` on FreeBSD.
- LIBDEPS_TAGS=[] if not env.TargetOSIs('freebsd') else [
- 'illegal_cyclic_or_unresolved_dependencies_whitelisted',
- ])
+ ],
+ # Because `::environ` is resolved in `/usr/lib/crt1.o` on FreeBSD, this library needs to be
+ # marked `incomplete` on FreeBSD.
+ LIBDEPS_TAGS=[] if not env.TargetOSIs('freebsd') else [
+ 'illegal_cyclic_or_unresolved_dependencies_whitelisted',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/boost_assert_shim',
+ ],
+)
-env.Library('boost_iostreams', [
+env.Library(
+ target='boost_iostreams',
+ source=[
'libs/iostreams/src/file_descriptor.cpp',
'libs/iostreams/src/mapped_file.cpp',
- ],
- LIBDEPS=[
- 'boost_system',
- ])
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/boost_assert_shim',
+ 'boost_system',
+ ],
+)