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 <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2017-07-24 15:31:13 -04:00
parent c642aca28f
commit c937699735
2 changed files with 18 additions and 4 deletions

View File

@ -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.

View File

@ -144,6 +144,8 @@
#include <openssl/base.h>
#include <stdlib.h>
#include <type_traits>
#include <utility>
@ -217,6 +219,17 @@ UniquePtr<T> MakeUnique(Args &&... args) {
return UniquePtr<T>(New<T>(std::forward<Args>(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<SSLKeyShare> 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