From 2368d2708965e77e39b3e8ae9def9a1d43a5a685 Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Mon, 14 Dec 2020 13:09:36 -0300 Subject: eina: Use EXPORTAPI for macro EINA_MODINFO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The EINA_MODINFO must export the symbols in the current module, and it is not used for importing symbols so we can use EXPORTAPI to export without needing to know what is being built. Patch from a series of patches to rename EAPI symbols to specific library DSOs. = The Rationale = This patch is from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))`. However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why LIBAPI is the only solution that works for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette Co-authored-by: Lucas Cavalcante de Sousa Co-authored-by: Ricardo Campos --- src/lib/eina/eina_inline_modinfo.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/eina/eina_inline_modinfo.x b/src/lib/eina/eina_inline_modinfo.x index a53de0a4a8..e3b5066301 100644 --- a/src/lib/eina/eina_inline_modinfo.x +++ b/src/lib/eina/eina_inline_modinfo.x @@ -24,7 +24,7 @@ #define __EINA_MODULE_UNIQUE_ID(id) _EINA_MODINFO_CONCAT(__EINA_MODULE_UNIQUE_ID_, id) #define _EINA_MODINFO(name, info) \ - EAPI const char __EINA_MODULE_UNIQUE_ID(name)[] \ +EXPORTAPI const char __EINA_MODULE_UNIQUE_ID(name)[] \ __attribute__((__used__)) __attribute__((unused, aligned(1))) = info; #define EINA_MODINFO(tag, info) _EINA_MODINFO(tag, info) -- cgit v1.2.1