summaryrefslogtreecommitdiff
path: root/cryptlib.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-12-03 06:33:15 -0500
committerJeffrey Walton <noloader@gmail.com>2018-12-03 06:33:15 -0500
commit6729b294103f169ca653386dd763aaaa55bf4409 (patch)
treedd223fa27611ab799d59a37bfd385186f4106236 /cryptlib.cpp
parent318d53f6f999a1c678aa07d7fe0ae7720da9be1d (diff)
downloadcryptopp-git-6729b294103f169ca653386dd763aaaa55bf4409.tar.gz
Move DEFAULT_CHANNEL and AAD_CHANNEL defs into cryptlib.cpp (GH #751)
The library used to provide DEFAULT_CHANNEL and AAD_CHANNEL this way. We experienced Static Initialization Order Fiasco crashes on occassion, so we moved them into cryptlib.h with internal linkage. The cost was, each translation unit got a copy of the strings which contributed to bloat. Issue 751 shows Clang compiles the global constructors for DEFAULT_CHANNEL and AAD_CHANNEL above the base ISA so we caught crashes on OS X with down-level hardware. We are now at a "pick your poison" point. We selected Static Initialization Order Fiasco because it seems to be less prevalent. Hat tip to the C++ Committee for allowing this problem to fester for three decades.
Diffstat (limited to 'cryptlib.cpp')
-rw-r--r--cryptlib.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/cryptlib.cpp b/cryptlib.cpp
index 81ff4b16..6399ec53 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -986,6 +986,42 @@ int LibraryVersion(CRYPTOPP_NOINLINE_DOTDOTDOT)
return CRYPTOPP_BUILD_VERSION;
}
+class NullNameValuePairs : public NameValuePairs
+{
+public:
+ NullNameValuePairs() {} // Clang complains a default ctor must be avilable
+ bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
+ {CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue); return false;}
+};
+
+#if HAVE_GCC_INIT_PRIORITY
+CRYPTOPP_COMPILE_ASSERT(CRYPTOPP_INIT_PRIORITY >= 101);
+const std::string DEFAULT_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 25))) = "";
+const std::string AAD_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 26))) = "AAD";
+const NullNameValuePairs s_nullNameValuePairs __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 27)));
+const NameValuePairs& g_nullNameValuePairs = s_nullNameValuePairs;
+#elif HAVE_MSC_INIT_PRIORITY
+#pragma warning(disable: 4073)
+#pragma init_seg(lib)
+const std::string DEFAULT_CHANNEL = "";
+const std::string AAD_CHANNEL = "AAD";
+const NullNameValuePairs s_nullNameValuePairs;
+const NameValuePairs& g_nullNameValuePairs = s_nullNameValuePairs;
+#pragma warning(default: 4073)
+#elif HAVE_XLC_INIT_PRIORITY
+#pragma priority(260)
+const std::string DEFAULT_CHANNEL = "";
+const std::string AAD_CHANNEL = "AAD";
+const NullNameValuePairs s_nullNameValuePairs;
+const NameValuePairs& g_nullNameValuePairs = s_nullNameValuePairs;
+#else
+static const std::string s1(""), s2("AAD");
+const std::string DEFAULT_CHANNEL = s1;
+const std::string AAD_CHANNEL = s2;
+const simple_ptr<NullNameValuePairs> s_pNullNameValuePairs(new NullNameValuePairs);
+const NameValuePairs &g_nullNameValuePairs = *s_pNullNameValuePairs.m_p;
+#endif
+
NAMESPACE_END // CryptoPP
#endif // CRYPTOPP_IMPORTS