summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2020-09-01 13:06:46 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-02 03:02:47 +0000
commitb478d31b7dd7b73a965ef48a3a242e9b2c2d4d9a (patch)
tree65576bc681d099800dcc9da38afeed46afd912de /src
parent762d65bb4685589a47f0a6b750222e6b4d774f57 (diff)
downloadmongo-b478d31b7dd7b73a965ef48a3a242e9b2c2d4d9a.tar.gz
SERVER-27507 Add basic visibility support and a test
Diffstat (limited to 'src')
-rw-r--r--src/mongo/platform/SConscript80
-rw-r--r--src/mongo/platform/visibility.h62
-rw-r--r--src/mongo/platform/visibility_test1.cpp39
-rw-r--r--src/mongo/platform/visibility_test2.cpp39
-rw-r--r--src/mongo/platform/visibility_test_lib1.cpp55
-rw-r--r--src/mongo/platform/visibility_test_lib1.h50
-rw-r--r--src/mongo/platform/visibility_test_lib2.cpp55
-rw-r--r--src/mongo/platform/visibility_test_lib2.h49
-rw-r--r--src/mongo/platform/visibility_test_libcommon.cpp53
-rw-r--r--src/mongo/platform/visibility_test_libcommon.h41
10 files changed, 522 insertions, 1 deletions
diff --git a/src/mongo/platform/SConscript b/src/mongo/platform/SConscript
index 648445c0746..e898e9642e7 100644
--- a/src/mongo/platform/SConscript
+++ b/src/mongo/platform/SConscript
@@ -1,6 +1,10 @@
# -*- mode: python -*-
-Import("env")
+Import([
+ "env",
+ "get_option",
+])
+
env = env.Clone()
env.CppUnitTest(
target='platform_test',
@@ -29,3 +33,77 @@ env.Benchmark(
],
)
+if not get_option("link-model") == "dynamic":
+ Return()
+
+env.Library(
+ target="visibility_test_libcommon",
+ source=[
+ "visibility_test_libcommon.cpp",
+ ],
+ LIBDEPS=[],
+ DISABLE_ALLOCATOR_SHIM_INJECTION=True,
+ MONGO_API_NAME="visibility_test_libcommon",
+)
+
+env.Library(
+ target="visibility_test_lib1",
+ source=[
+ "visibility_test_lib1.cpp"
+ ],
+ LIBDEPS=[],
+ LIBDEPS_PRIVATE=[
+ "visibility_test_libcommon",
+ ],
+ DISABLE_ALLOCATOR_SHIM_INJECTION=True,
+ MONGO_API_NAME="visibility_test_lib1",
+)
+
+env.Library(
+ target="visibility_test_lib2",
+ source=[
+ "visibility_test_lib2.cpp"
+ ],
+ LIBDEPS=[
+ "visibility_test_lib1",
+ ],
+ LIBDEPS_PRIVATE=[
+ "visibility_test_libcommon",
+ ],
+ DISABLE_ALLOCATOR_SHIM_INJECTION=True,
+ MONGO_API_NAME="visibility_test_lib2",
+)
+
+visibility_test1 = env.Program(
+ target="visibility_test1",
+ source=[
+ "visibility_test1.cpp",
+ ],
+ LIBDEPS=[
+ "visibility_test_lib1",
+ ],
+ DISABLE_ALLOCATOR_SHIM_INJECTION=True,
+ AIB_COMPONENT="visibility-test",
+ AIB_COMPONENTS_EXTRA=[
+ "unittests",
+ "tests",
+ ],
+)
+env.RegisterTest("$UNITTEST_LIST", visibility_test1[0])
+
+visibility_test2 = env.Program(
+ target="visibility_test2",
+ source=[
+ "visibility_test2.cpp",
+ ],
+ LIBDEPS=[
+ "visibility_test_lib2",
+ ],
+ DISABLE_ALLOCATOR_SHIM_INJECTION=True,
+ AIB_COMPONENT="visibility-test",
+ AIB_COMPONENTS_EXTRA=[
+ "unittests",
+ "tests",
+ ],
+)
+env.RegisterTest("$UNITTEST_LIST", visibility_test2[0])
diff --git a/src/mongo/platform/visibility.h b/src/mongo/platform/visibility.h
new file mode 100644
index 00000000000..b251ab705e0
--- /dev/null
+++ b/src/mongo/platform/visibility.h
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2020-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.
+ */
+
+#pragma once
+
+#if !defined(MONGO_USE_VISIBILITY)
+
+#define MONGO_VISIBILITY_PUBLIC()
+#define MONGO_VISIBILITY_PRIVATE()
+#define MONGO_PRIVATE
+#define MONGO_API(LIB)
+
+#else
+
+#if defined(_MSC_VER)
+
+#include <boost/preprocessor/control/iif.hpp>
+#include <boost/vmd/is_number.hpp>
+
+#define MONGO_DLLEXPORT() __declspec(dllexport)
+#define MONGO_DLLIMPORT() __declspec(dllimport)
+#define MONGO_PRIVATE
+#define MONGO_API_IMPL2(COND) BOOST_PP_IIF(COND, MONGO_DLLEXPORT, MONGO_DLLIMPORT)()
+#define MONGO_API_IMPL(ARG) MONGO_API_IMPL2(BOOST_VMD_IS_NUMBER(ARG))
+#define MONGO_API(LIB) MONGO_API_IMPL(MONGO_API_##LIB)
+
+#else
+
+#define MONGO_VISIBILITY_PUBLIC() __attribute__((visibility("default")))
+#define MONGO_VISIBILITY_PRIVATE() __attribute__((visibility("hidden")))
+#define MONGO_PRIVATE MONGO_VISIBILITY_PRIVATE()
+#define MONGO_API(LIB) MONGO_VISIBILITY_PUBLIC()
+
+#endif
+
+#endif
diff --git a/src/mongo/platform/visibility_test1.cpp b/src/mongo/platform/visibility_test1.cpp
new file mode 100644
index 00000000000..33341d8a5e0
--- /dev/null
+++ b/src/mongo/platform/visibility_test1.cpp
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2020-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/platform/basic.h"
+
+#include "mongo/platform/visibility_test_lib1.h"
+
+#include <cstdlib>
+
+int main(int argc, char* argv[]) {
+ mongo::visibility_test_lib1::Base b("hello");
+ return (b.name() == "hello") ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/src/mongo/platform/visibility_test2.cpp b/src/mongo/platform/visibility_test2.cpp
new file mode 100644
index 00000000000..baf69b36412
--- /dev/null
+++ b/src/mongo/platform/visibility_test2.cpp
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2020-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/platform/basic.h"
+
+#include "mongo/platform/visibility_test_lib2.h"
+
+#include <cstdlib>
+
+int main(int argc, char* argv[]) {
+ mongo::visibility_test_lib2::Derived d("hello", argc);
+ return (d.value() == argc) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/src/mongo/platform/visibility_test_lib1.cpp b/src/mongo/platform/visibility_test_lib1.cpp
new file mode 100644
index 00000000000..073f743c2af
--- /dev/null
+++ b/src/mongo/platform/visibility_test_lib1.cpp
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2020-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/platform/basic.h"
+
+#include "mongo/platform/visibility_test_lib1.h"
+
+#include <stdexcept>
+
+#include "mongo/platform/visibility_test_libcommon.h"
+
+namespace mongo {
+namespace visibility_test_lib1 {
+
+Base::Base(const std::string& name) : _name(name) {
+ _validate(_name);
+}
+
+std::string_view Base::name() const {
+ return _name;
+}
+
+void Base::_validate(std::string_view name) {
+ if (!visibility_test_libcommon::validate(name))
+ throw std::logic_error("Invalid name");
+}
+
+} // namespace visibility_test_lib1
+} // namespace mongo
diff --git a/src/mongo/platform/visibility_test_lib1.h b/src/mongo/platform/visibility_test_lib1.h
new file mode 100644
index 00000000000..d35ff10e4e6
--- /dev/null
+++ b/src/mongo/platform/visibility_test_lib1.h
@@ -0,0 +1,50 @@
+/**
+ * Copyright (C) 2020-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 <string>
+#include <string_view>
+
+#include "mongo/platform/visibility.h"
+
+namespace mongo {
+namespace visibility_test_lib1 {
+
+class MONGO_API(visibility_test_lib1) Base {
+public:
+ explicit Base(const std::string& name);
+ std::string_view name() const;
+
+private:
+ MONGO_PRIVATE static void _validate(std::string_view);
+
+ std::string _name;
+};
+
+} // namespace visibility_test_lib1
+} // namespace mongo
diff --git a/src/mongo/platform/visibility_test_lib2.cpp b/src/mongo/platform/visibility_test_lib2.cpp
new file mode 100644
index 00000000000..0fc9d9d9f65
--- /dev/null
+++ b/src/mongo/platform/visibility_test_lib2.cpp
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2020-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/platform/basic.h"
+
+#include "mongo/platform/visibility_test_lib2.h"
+
+#include <stdexcept>
+
+#include "mongo/platform/visibility_test_libcommon.h"
+
+namespace mongo {
+namespace visibility_test_lib2 {
+
+Derived::Derived(const std::string& name, double value) : Base(name), _value(value) {
+ _validate(_value);
+}
+
+double Derived::value() const {
+ return _value;
+}
+
+void Derived::_validate(double value) {
+ if (!visibility_test_libcommon::validate(value))
+ throw std::logic_error("Invalid value");
+}
+
+} // namespace visibility_test_lib2
+} // namespace mongo
diff --git a/src/mongo/platform/visibility_test_lib2.h b/src/mongo/platform/visibility_test_lib2.h
new file mode 100644
index 00000000000..94143460cec
--- /dev/null
+++ b/src/mongo/platform/visibility_test_lib2.h
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2020-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/platform/visibility.h"
+#include "mongo/platform/visibility_test_lib1.h"
+
+namespace mongo {
+namespace visibility_test_lib2 {
+
+class MONGO_API(visibility_test_lib2) Derived : public visibility_test_lib1::Base {
+public:
+ explicit Derived(const std::string& name, double value);
+ double value() const;
+
+private:
+ MONGO_PRIVATE static void _validate(double);
+
+ double _value;
+};
+
+} // namespace visibility_test_lib2
+} // namespace mongo
diff --git a/src/mongo/platform/visibility_test_libcommon.cpp b/src/mongo/platform/visibility_test_libcommon.cpp
new file mode 100644
index 00000000000..112554a4a99
--- /dev/null
+++ b/src/mongo/platform/visibility_test_libcommon.cpp
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2020-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/platform/basic.h"
+
+#include "mongo/platform/visibility_test_libcommon.h"
+
+#include <stdexcept>
+
+namespace mongo {
+namespace visibility_test_libcommon {
+
+namespace {
+const std::string_view kInvalidStringView = "invalid";
+const double kInvalidDouble = -1;
+} // namespace
+
+bool validate(std::string_view data) {
+ return data != kInvalidStringView;
+}
+
+bool validate(double data) {
+ return data != kInvalidDouble;
+}
+
+} // namespace visibility_test_libcommon
+} // namespace mongo
diff --git a/src/mongo/platform/visibility_test_libcommon.h b/src/mongo/platform/visibility_test_libcommon.h
new file mode 100644
index 00000000000..feb77f996fb
--- /dev/null
+++ b/src/mongo/platform/visibility_test_libcommon.h
@@ -0,0 +1,41 @@
+/**
+ * Copyright (C) 2020-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 <string_view>
+
+#include "mongo/platform/visibility.h"
+
+namespace mongo {
+namespace visibility_test_libcommon {
+
+MONGO_API(visibility_test_libcommon) bool validate(std::string_view data);
+MONGO_API(visibility_test_libcommon) bool validate(double data);
+
+} // namespace visibility_test_libcommon
+} // namespace mongo