[vm] Native API DL: dllexport on Windows

`DART_EXTERN` in `dart_api_dl.h` was missing `__declspec(dllexport)` on
Windows, causing `Dart_InitializeApiDL` to not be visible.

Using `DART_EXPORT` instead doesn't work because the definitions added
by `DART_API_ALL_DL_SYMBOLS` do not support having a 'used' attribute.

Instead, define a `DART_EXPORT_DL` for these which is identical but
without the 'used' attribute.

Note that the precompiler `DART_SHARED_LIB` macro must be defined for
`__declspec(dllexport)` to be part of `DART_EXPORT`/`DART_EXPORT_DL`.

Also fixes `#define DART_EXTERN_C` to be `extern` in C. Without this,
the linker will see duplicate symbols for things `DART_EXPORT`ed when
the `dart_api_dl.h` is included in C files.

TEST=SDK build on all OSes

Change-Id: I0af1d46d22409599203d9be310d54bd16c6a5b59
Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try,dart-sdk-mac-arm64-try,dart-sdk-mac-try,dart-sdk-win-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215550
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Daco Harkes
2021-10-06 07:42:44 +00:00
committed by commit-bot@chromium.org
parent 3171c7cc0e
commit 862e473c2e
2 changed files with 34 additions and 11 deletions
+1 -1
View File
@@ -28,7 +28,7 @@
#ifdef __cplusplus
#define DART_EXTERN_C extern "C"
#else
#define DART_EXTERN_C
#define DART_EXTERN_C extern
#endif
#if defined(__CYGWIN__)
+33 -10
View File
@@ -22,13 +22,7 @@
* `Dart_InitializeApiDL` with `NativeApi.initializeApiDLData`.
*/
#ifdef __cplusplus
#define DART_EXTERN extern "C"
#else
#define DART_EXTERN extern
#endif
DART_EXTERN intptr_t Dart_InitializeApiDL(void* data);
DART_EXPORT intptr_t Dart_InitializeApiDL(void* data);
// ============================================================================
// IMPORTANT! Never update these signatures without properly updating
@@ -114,14 +108,43 @@ typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id,
// End of verbatim copy.
// ============================================================================
// Copy of definition of DART_EXPORT without 'used' attribute.
//
// The 'used' attribute cannot be used with DART_API_ALL_DL_SYMBOLS because
// they are not function declarations, but variable declarations with a
// function pointer type.
//
// The function pointer variables are initialized with the addresses of the
// functions in the VM. If we were to use function declarations instead, we
// would need to forward the call to the VM adding indirection.
#if defined(__CYGWIN__)
#error Tool chain and platform not supported.
#elif defined(_WIN32)
#if defined(DART_SHARED_LIB)
#define DART_EXPORT_DL DART_EXTERN_C __declspec(dllexport)
#else
#define DART_EXPORT_DL DART_EXTERN_C
#endif
#else
#if __GNUC__ >= 4
#if defined(DART_SHARED_LIB)
#define DART_EXPORT_DL DART_EXTERN_C __attribute__((visibility("default")))
#else
#define DART_EXPORT_DL DART_EXTERN_C
#endif
#else
#error Tool chain not supported.
#endif
#endif
#define DART_API_DL_DECLARATIONS(name, R, A) \
typedef R(*name##_Type) A; \
DART_EXTERN name##_Type name##_DL;
DART_EXPORT_DL name##_Type name##_DL;
DART_API_ALL_DL_SYMBOLS(DART_API_DL_DECLARATIONS)
#undef DART_API_DL_DEFINITIONS
#undef DART_API_DL_DECLARATIONS
#undef DART_EXTERN
#undef DART_EXPORT_DL
#endif /* RUNTIME_INCLUDE_DART_API_DL_H_ */ /* NOLINT */