Issue with dllexport/dllimport inline function

LIU Hao lh_mouse@126.com
Tue Oct 11 17:42:54 GMT 2022


在 2022-10-11 22:26, xclaesse@gmail.com 写道:
> #ifdef GLIB_COMPILATION
> #  define _GLIB_API _GLIB_EXPORT
> #  define GLIB_INLINE __attribute__((__dllexport__)) __attribute__((__gnu_inline__)) extern inline

This is not correct. Typically, `dllexport` indicates that 'I want an external definition' but 
`gnu_inline` indicates that 'I do not want an external definition', so it's a contradiction: you get 
either multiple definitions, or none (which causes undefined references).


To user code which imports such a function, it should be seen as

    ```
    __attribute__((__gnu_inline__))
    extern inline
    int g_strcmp0(const char*, const char*)
    ```

This has the desired effect: The function can be inlined where appropriate. And if not, a call to 
the external thunk is emitted; no weak definition is emitted in either case.


To the library itself which exports it, it should be seen as

    ```
    __attribute__((__dllexport__))
    extern inline
    int g_strcmp0(const char*, const char*)
    ```

There is no `gnu_inline` in this case. GCC always generates a COMDAT/weak/linkonce definition, which 
will not cause multiple definition errors.



-- 
Best regards,
LIU Hao

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20221012/678438ca/attachment-0001.sig>


More information about the Gcc mailing list