From c937699735c836a3b990a60d16291e0c900bef5f Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 24 Jul 2017 15:31:13 -0400 Subject: [PATCH] Avoid a C++ runtime dependency. Short-term, we will need to use these macros and build without RTTI when defining any virtual base class. Long-term, it would be good to remove these constraints, but it will require some downstream work. Bug: 132 Change-Id: I3bc65bb12d7653978612b7d1bf06f772a2f3b1cd Reviewed-on: https://boringssl-review.googlesource.com/18344 Commit-Queue: David Benjamin Commit-Queue: Adam Langley Reviewed-by: Adam Langley --- CMakeLists.txt | 2 +- ssl/internal.h | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c2d5562..3f9a3da2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${C_CXX_FLAGS} -Wmissing-declarations -fno-exceptions") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${C_CXX_FLAGS} -Wmissing-declarations -fno-exceptions -fno-rtti") # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the # spelling for both and -Wmissing-declarations is some other warning. diff --git a/ssl/internal.h b/ssl/internal.h index fb02d35f..5a2e5609 100644 --- a/ssl/internal.h +++ b/ssl/internal.h @@ -144,6 +144,8 @@ #include +#include + #include #include @@ -217,6 +219,17 @@ UniquePtr MakeUnique(Args &&... args) { return UniquePtr(New(std::forward(args)...)); } +/* HAS_VIRTUAL_DESTRUCTOR should be declared in any base class which defines a + * virtual destructor. This avoids a dependency on |_ZdlPv| and prevents the + * class from being used with |delete|. */ +#define HAS_VIRTUAL_DESTRUCTOR \ + void operator delete(void *) { abort(); } + +/* PURE_VIRTUAL should be used instead of = 0 when defining pure-virtual + * functions. This avoids a dependency on |__cxa_pure_virtual| but loses + * compile-time checking. */ +#define PURE_VIRTUAL { abort(); } + /* Protocol versions. * @@ -753,17 +766,18 @@ int custom_ext_add_serverhello(SSL_HANDSHAKE *hs, CBB *extensions); class SSLKeyShare { public: virtual ~SSLKeyShare() {} + HAS_VIRTUAL_DESTRUCTOR /* Create returns a SSLKeyShare instance for use with group |group_id| or * nullptr on error. */ static UniquePtr Create(uint16_t group_id); /* GroupID returns the group ID. */ - virtual uint16_t GroupID() const = 0; + virtual uint16_t GroupID() const PURE_VIRTUAL; /* Offer generates a keypair and writes the public value to * |out_public_key|. It returns true on success and false on error. */ - virtual bool Offer(CBB *out_public_key) = 0; + virtual bool Offer(CBB *out_public_key) PURE_VIRTUAL; /* Accept performs a key exchange against the |peer_key| generated by |offer|. * On success, it returns true, writes the public value to |out_public_key|, @@ -790,7 +804,7 @@ class SSLKeyShare { * TODO(davidben): out_secret should be a smart pointer. */ virtual bool Finish(uint8_t **out_secret, size_t *out_secret_len, uint8_t *out_alert, const uint8_t *peer_key, - size_t peer_key_len) = 0; + size_t peer_key_len) PURE_VIRTUAL; }; /* ssl_nid_to_group_id looks up the group corresponding to |nid|. On success, it