diff options
author | Andy Schwerin <schwerin@10gen.com> | 2013-12-05 14:52:36 -0500 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2013-12-09 14:37:40 -0500 |
commit | 3100d120989881a47b9efbaaad5aec49980301d4 (patch) | |
tree | 03f76a37ed5cde3f0c1b51073ff00e4853a4c5f7 /src | |
parent | 86848b30c3014247ab27fdff38ffaa36c1baa2fa (diff) | |
download | mongo-3100d120989881a47b9efbaaad5aec49980301d4.tar.gz |
SERVER-3364 Add macros for putting visibility and calling convention declarations on declarations.
Also SERVER-5650.
MONGO_COMPILER_API_EXPORT Puts the "export visibility" declaration on a type,
function or variable.
MONGO_COMPILER_API_IMPORT Puts the "import from library" declaration on a type,
function or variable.
MONGO_COMPILER_API_CALLING_CONVENTION Labels a function declaration with its
calling convention.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/platform/compiler.h | 36 | ||||
-rw-r--r-- | src/mongo/platform/compiler_gcc.h | 20 | ||||
-rw-r--r-- | src/mongo/platform/compiler_msvc.h | 12 |
3 files changed, 67 insertions, 1 deletions
diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h index 9bb166e8f60..7a0a18495b4 100644 --- a/src/mongo/platform/compiler.h +++ b/src/mongo/platform/compiler.h @@ -27,7 +27,7 @@ * Instructs the compiler that the decorated function will not return through the normal return * path. * - * Correct: void MONGO_COMPILER_NORETURN myAbortFunction(); + * Correct: MONGO_COMPILER_NORETURN void myAbortFunction(); * * * MONGO_COMPILER_VARIABLE_UNUSED @@ -71,6 +71,40 @@ * * Incorrect: * int MONGO_COMPILER_ALIGN_VARIABLE(16) a, b; + * + * + * MONGO_COMPILER_API_EXPORT + * + * Instructs the compiler to label the given type, variable or function as part of the + * exported interface of the library object under construction. + * + * Correct: + * MONGO_COMPILER_API_EXPORT int globalSwitch; + * class MONGO_COMPILER_API_EXPORT ExportedType { ... }; + * MONGO_COMPILER_API_EXPORT SomeType exportedFunction(...); + * + * NOTE: Rather than using this macro directly, one typically declares another macro named for the + * library, which is conditionally defined to either MONGO_COMIPLER_API_EXPORT or + * MONGO_COMPILER_API_IMPORT based on whether the compiler is currently building the library or + * building an object that depends on the library, respectively. For example, MONGO_CLIENT_API + * might be defined to MONGO_COMPILER_API_EXPORT when building the MongoDB shared library, and to + * MONGO_COMPILER_API_IMPORT when building an application that links against the shared library. + * + * + * MONGO_COMPILER_API_IMPORT + * + * Instructs the compiler to label the given type, variable or function as imported + * from another library, and not part of the library object under construction. + * + * Same correct/incorrect usage as for MONGO_COMPILER_API_EXPORT. + * + * + * MONGO_COMPILER_API_CALLING_CONVENTION + * + * Explicitly decorates a function declaration the api calling convention used for + * shared libraries. + * + * Same correct/incorrect usage as for MONGO_COMPILER_API_EXPORT. */ #if defined(_MSC_VER) diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h index 84d2a8f52d5..14540c13eb3 100644 --- a/src/mongo/platform/compiler_gcc.h +++ b/src/mongo/platform/compiler_gcc.h @@ -29,3 +29,23 @@ #define MONGO_COMPILER_ALIGN_TYPE(ALIGNMENT) __attribute__(( __aligned__(ALIGNMENT) )) #define MONGO_COMPILER_ALIGN_VARIABLE(ALIGNMENT) __attribute__(( __aligned__(ALIGNMENT) )) + +// NOTE(schwerin): These visibility and calling-convention macro definitions assume we're not using +// GCC/CLANG to target native Windows. If/when we decide to do such targeting, we'll need to change +// compiler flags on Windows to make sure we use an appropriate calling convention, and configure +// MONGO_COMPILER_API_EXPORT, MONGO_COMPILER_API_IMPORT and MONGO_COMPILER_API_CALLING_CONVENTION +// correctly. I believe "correctly" is the following: +// +// #ifdef _WIN32 +// #define MONGO_COMIPLER_API_EXPORT __attribute__(( __dllexport__ )) +// #define MONGO_COMPILER_API_IMPORT __attribute__(( __dllimport__ )) +// #ifdef _M_IX86 +// #define MONGO_COMPILER_API_CALLING_CONVENTION __attribute__((__cdecl__)) +// #else +// #define MONGO_COMPILER_API_CALLING_CONVENTION +// #endif +// #else ... fall through to the definitions below. + +#define MONGO_COMPILER_API_EXPORT __attribute__(( __visibility__("default") )) +#define MONGO_COMPILER_API_IMPORT +#define MONGO_COMPILER_API_CALLING_CONVENTION diff --git a/src/mongo/platform/compiler_msvc.h b/src/mongo/platform/compiler_msvc.h index a2207009785..1155e7d6edd 100644 --- a/src/mongo/platform/compiler_msvc.h +++ b/src/mongo/platform/compiler_msvc.h @@ -29,3 +29,15 @@ #define MONGO_COMPILER_ALIGN_TYPE(ALIGNMENT) __declspec( align( ALIGNMENT ) ) #define MONGO_COMPILER_ALIGN_VARIABLE(ALIGNMENT) __declspec( align( ALIGNMENT ) ) + +#define MONGO_COMPILER_API_EXPORT __declspec(dllexport) +#define MONGO_COMPILER_API_IMPORT __declspec(dllimport) + +#ifdef _M_IX86 +// 32-bit x86 supports multiple of calling conventions. We build supporting the cdecl convention +// (most common). By labeling our exported and imported functions as such, we do a small favor to +// 32-bit Windows developers. +#define MONGO_COMPILER_API_CALLING_CONVENTION __cdecl +#else +#define MONGO_COMPILER_API_CALLING_CONVENTION +#endif |