Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/include/openssl/aead.h b/include/openssl/aead.h
index af31554..f19344e 100644
--- a/include/openssl/aead.h
+++ b/include/openssl/aead.h
@@ -425,7 +425,7 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
using ScopedEVP_AEAD_CTX =
internal::StackAllocated<EVP_AEAD_CTX, void, EVP_AEAD_CTX_zero,
@@ -433,7 +433,7 @@
BORINGSSL_MAKE_DELETER(EVP_AEAD_CTX, EVP_AEAD_CTX_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/asn1.h b/include/openssl/asn1.h
index f7b6b86..46e5f53 100644
--- a/include/openssl/asn1.h
+++ b/include/openssl/asn1.h
@@ -875,13 +875,13 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(ASN1_OBJECT, ASN1_OBJECT_free)
BORINGSSL_MAKE_DELETER(ASN1_STRING, ASN1_STRING_free)
BORINGSSL_MAKE_DELETER(ASN1_TYPE, ASN1_TYPE_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} /* extern C++ */
diff --git a/include/openssl/base.h b/include/openssl/base.h
index aa1be1f..f86968b 100644
--- a/include/openssl/base.h
+++ b/include/openssl/base.h
@@ -71,6 +71,10 @@
#include <openssl/is_boringssl.h>
#include <openssl/opensslconf.h>
+#if defined(BORINGSSL_PREFIX)
+#include <boringssl_prefix_symbols.h>
+#endif
+
#if defined(__cplusplus)
extern "C" {
#endif
@@ -366,6 +370,19 @@
#endif
#if !defined(BORINGSSL_NO_CXX)
+
+#if defined(BORINGSSL_PREFIX)
+#define BSSL_NAMESPACE_BEGIN \
+ namespace bssl { \
+ inline namespace BORINGSSL_PREFIX {
+#define BSSL_NAMESPACE_END \
+ } \
+ }
+#else
+#define BSSL_NAMESPACE_BEGIN namespace bssl {
+#define BSSL_NAMESPACE_END }
+#endif
+
extern "C++" {
#include <memory>
@@ -387,7 +404,7 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
namespace internal {
@@ -464,7 +481,7 @@
return UpRef(ptr.get()); \
}
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index dcf8ab7..2e056a1 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -894,12 +894,12 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(BIO, BIO_free)
BORINGSSL_MAKE_UP_REF(BIO, BIO_up_ref)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/bn.h b/include/openssl/bn.h
index 82195ed..251c717 100644
--- a/include/openssl/bn.h
+++ b/include/openssl/bn.h
@@ -987,7 +987,7 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(BIGNUM, BN_free)
BORINGSSL_MAKE_DELETER(BN_CTX, BN_CTX_free)
@@ -1005,7 +1005,7 @@
BN_CTXScope &operator=(BN_CTXScope &) = delete;
};
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/buf.h b/include/openssl/buf.h
index 3f961b8..10a555f 100644
--- a/include/openssl/buf.h
+++ b/include/openssl/buf.h
@@ -124,11 +124,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(BUF_MEM, BUF_MEM_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h
index 3057604..1400f2e 100644
--- a/include/openssl/bytestring.h
+++ b/include/openssl/bytestring.h
@@ -491,11 +491,11 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
using ScopedCBB = internal::StackAllocated<CBB, void, CBB_zero, CBB_cleanup>;
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/cipher.h b/include/openssl/cipher.h
index b8d4e52..5963413 100644
--- a/include/openssl/cipher.h
+++ b/include/openssl/cipher.h
@@ -571,7 +571,7 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(EVP_CIPHER_CTX, EVP_CIPHER_CTX_free)
@@ -579,7 +579,7 @@
internal::StackAllocated<EVP_CIPHER_CTX, int, EVP_CIPHER_CTX_init,
EVP_CIPHER_CTX_cleanup>;
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/cmac.h b/include/openssl/cmac.h
index 5e9f3d0..3e8cf92 100644
--- a/include/openssl/cmac.h
+++ b/include/openssl/cmac.h
@@ -78,11 +78,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(CMAC_CTX, CMAC_CTX_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/conf.h b/include/openssl/conf.h
index 4ffce37..07e34ee 100644
--- a/include/openssl/conf.h
+++ b/include/openssl/conf.h
@@ -162,11 +162,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(CONF, NCONF_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/curve25519.h b/include/openssl/curve25519.h
index 332215b..a455389 100644
--- a/include/openssl/curve25519.h
+++ b/include/openssl/curve25519.h
@@ -188,11 +188,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(SPAKE2_CTX, SPAKE2_CTX_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/dh.h b/include/openssl/dh.h
index ae24c25..7188790 100644
--- a/include/openssl/dh.h
+++ b/include/openssl/dh.h
@@ -278,11 +278,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(DH, DH_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/digest.h b/include/openssl/digest.h
index 4a2b710..1a1ca29 100644
--- a/include/openssl/digest.h
+++ b/include/openssl/digest.h
@@ -295,7 +295,7 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(EVP_MD_CTX, EVP_MD_CTX_free)
@@ -303,7 +303,7 @@
internal::StackAllocated<EVP_MD_CTX, int, EVP_MD_CTX_init,
EVP_MD_CTX_cleanup>;
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/dsa.h b/include/openssl/dsa.h
index a5fa767..70cde7b 100644
--- a/include/openssl/dsa.h
+++ b/include/openssl/dsa.h
@@ -417,12 +417,12 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(DSA, DSA_free)
BORINGSSL_MAKE_DELETER(DSA_SIG, DSA_SIG_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/ec.h b/include/openssl/ec.h
index dbb72ab..41a9c34 100644
--- a/include/openssl/ec.h
+++ b/include/openssl/ec.h
@@ -357,12 +357,12 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(EC_POINT, EC_POINT_free)
BORINGSSL_MAKE_DELETER(EC_GROUP, EC_GROUP_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/ec_key.h b/include/openssl/ec_key.h
index 6944049..7e9e4e8 100644
--- a/include/openssl/ec_key.h
+++ b/include/openssl/ec_key.h
@@ -336,11 +336,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(EC_KEY, EC_KEY_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/ecdsa.h b/include/openssl/ecdsa.h
index ff326ab..d4d353e 100644
--- a/include/openssl/ecdsa.h
+++ b/include/openssl/ecdsa.h
@@ -179,11 +179,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(ECDSA_SIG, ECDSA_SIG_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/engine.h b/include/openssl/engine.h
index 595e53c..9d45952 100644
--- a/include/openssl/engine.h
+++ b/include/openssl/engine.h
@@ -94,11 +94,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(ENGINE, ENGINE_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index 9b00a07..45e1b6d 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -870,13 +870,13 @@
} // extern C
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(EVP_PKEY, EVP_PKEY_free)
BORINGSSL_MAKE_UP_REF(EVP_PKEY, EVP_PKEY_up_ref)
BORINGSSL_MAKE_DELETER(EVP_PKEY_CTX, EVP_PKEY_CTX_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/hmac.h b/include/openssl/hmac.h
index 977dea6..b5d1e42 100644
--- a/include/openssl/hmac.h
+++ b/include/openssl/hmac.h
@@ -169,14 +169,14 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(HMAC_CTX, HMAC_CTX_free)
using ScopedHMAC_CTX =
internal::StackAllocated<HMAC_CTX, void, HMAC_CTX_init, HMAC_CTX_cleanup>;
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/mem.h b/include/openssl/mem.h
index 7d7087e..9f9c00d 100644
--- a/include/openssl/mem.h
+++ b/include/openssl/mem.h
@@ -142,12 +142,12 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(char, OPENSSL_free)
BORINGSSL_MAKE_DELETER(uint8_t, OPENSSL_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/pkcs7.h b/include/openssl/pkcs7.h
index 52b649c..cb6155f 100644
--- a/include/openssl/pkcs7.h
+++ b/include/openssl/pkcs7.h
@@ -199,11 +199,11 @@
} // extern C
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(PKCS7, PKCS7_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
#endif
diff --git a/include/openssl/pkcs8.h b/include/openssl/pkcs8.h
index 9a66dd0..ee48f19 100644
--- a/include/openssl/pkcs8.h
+++ b/include/openssl/pkcs8.h
@@ -215,12 +215,12 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(PKCS12, PKCS12_free)
BORINGSSL_MAKE_DELETER(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/pool.h b/include/openssl/pool.h
index 1259f4a..0e4bdd5 100644
--- a/include/openssl/pool.h
+++ b/include/openssl/pool.h
@@ -87,13 +87,13 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_free)
BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER, CRYPTO_BUFFER_free)
BORINGSSL_MAKE_UP_REF(CRYPTO_BUFFER, CRYPTO_BUFFER_up_ref)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/rsa.h b/include/openssl/rsa.h
index 47e2d34..8098c48 100644
--- a/include/openssl/rsa.h
+++ b/include/openssl/rsa.h
@@ -723,11 +723,11 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(RSA, RSA_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/span.h b/include/openssl/span.h
index 5ed96b7..298a722 100644
--- a/include/openssl/span.h
+++ b/include/openssl/span.h
@@ -25,7 +25,7 @@
#include <cstdlib>
#include <type_traits>
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
template <typename T>
class Span;
@@ -190,7 +190,7 @@
return MakeConstSpan(c.data(), c.size());
}
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h
index 5546f4e..0d5a444 100644
--- a/include/openssl/ssl.h
+++ b/include/openssl/ssl.h
@@ -4383,6 +4383,10 @@
#define SSL_CTRL_SET_TMP_RSA doesnt_exist
#define SSL_CTRL_SET_TMP_RSA_CB doesnt_exist
+// |BORINGSSL_PREFIX| already makes each of these symbols into macros, so there
+// is no need to define conflicting macros.
+#if !defined(BORINGSSL_PREFIX)
+
#define DTLSv1_get_timeout DTLSv1_get_timeout
#define DTLSv1_handle_timeout DTLSv1_handle_timeout
#define SSL_CTX_add0_chain_cert SSL_CTX_add0_chain_cert
@@ -4452,6 +4456,8 @@
#define SSL_set_tmp_rsa SSL_set_tmp_rsa
#define SSL_total_renegotiations SSL_total_renegotiations
+#endif // !defined(BORINGSSL_PREFIX)
+
#if defined(__cplusplus)
} // extern C
@@ -4460,7 +4466,7 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(SSL, SSL_free)
BORINGSSL_MAKE_DELETER(SSL_CTX, SSL_CTX_free)
@@ -4572,7 +4578,7 @@
OPENSSL_EXPORT bool SSL_serialize_handback(const SSL *ssl, CBB *out);
OPENSSL_EXPORT bool SSL_apply_handback(SSL *ssl, Span<const uint8_t> handback);
-} // namespace bssl
+BSSL_NAMESPACE_END
} // extern C++
diff --git a/include/openssl/stack.h b/include/openssl/stack.h
index a1cca59..15b6adf 100644
--- a/include/openssl/stack.h
+++ b/include/openssl/stack.h
@@ -219,17 +219,17 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
namespace internal {
template <typename T>
struct StackTraits {};
}
-}
+BSSL_NAMESPACE_END
}
#define BORINGSSL_DEFINE_STACK_TRAITS(name, type, is_const) \
extern "C++" { \
- namespace bssl { \
+ BSSL_NAMESPACE_BEGIN \
namespace internal { \
template <> \
struct StackTraits<STACK_OF(name)> { \
@@ -238,7 +238,7 @@
static constexpr bool kIsConst = is_const; \
}; \
} \
- } \
+ BSSL_NAMESPACE_END \
}
#else
@@ -393,7 +393,7 @@
#include <type_traits>
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
namespace internal {
@@ -474,7 +474,7 @@
return true;
}
-} // namespace bssl
+BSSL_NAMESPACE_END
// Define begin() and end() for stack types so C++ range for loops work.
template <typename Stack>
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
index eeab5ec..72f7314 100644
--- a/include/openssl/x509.h
+++ b/include/openssl/x509.h
@@ -1129,7 +1129,7 @@
#if !defined(BORINGSSL_NO_CXX)
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(NETSCAPE_SPKI, NETSCAPE_SPKI_free)
BORINGSSL_MAKE_DELETER(RSA_PSS_PARAMS, RSA_PSS_PARAMS_free)
@@ -1158,7 +1158,7 @@
internal::StackAllocated<X509_STORE_CTX, void, X509_STORE_CTX_zero,
X509_STORE_CTX_cleanup>;
-} // namespace bssl
+BSSL_NAMESPACE_END
} /* extern C++ */
#endif /* !BORINGSSL_NO_CXX */
diff --git a/include/openssl/x509v3.h b/include/openssl/x509v3.h
index 1af439d..53e20a0 100644
--- a/include/openssl/x509v3.h
+++ b/include/openssl/x509v3.h
@@ -751,7 +751,7 @@
extern "C++" {
-namespace bssl {
+BSSL_NAMESPACE_BEGIN
BORINGSSL_MAKE_DELETER(ACCESS_DESCRIPTION, ACCESS_DESCRIPTION_free)
BORINGSSL_MAKE_DELETER(AUTHORITY_KEYID, AUTHORITY_KEYID_free)
@@ -760,7 +760,7 @@
BORINGSSL_MAKE_DELETER(GENERAL_NAME, GENERAL_NAME_free)
BORINGSSL_MAKE_DELETER(POLICYINFO, POLICYINFO_free)
-} // namespace bssl
+BSSL_NAMESPACE_END
} /* extern C++ */
#endif