poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Symbols export control in libpoke


From: Tim Rühsen
Subject: Re: Symbols export control in libpoke
Date: Sun, 25 Oct 2020 12:33:53 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

Hi,

just saw this "by accident" :-)

I am totally off from reading mailing lists as my current job doesn't leave me much time - but somehow this came to my eyes.

On 25.10.20 12:19, Mohammad-Reza Nabipoor via poke-devel wrote:
Hi, Jose.

On Sun, Oct 25, 2020 at 11:47:35AM +0100, Jose E. Marchesi wrote:

Hi people!

Right now we control which symbols get exported in libpoke by annotating
function declarations with the "hidden" attribute, like in:

   pkl_compiler pkl_new (pvm vm, const char *rt_path)
     __attribute__ ((visibility ("hidden")));

This works, but it is cumbersome to maintain and also error-prone: it is
easy to forget to annotate new functions.

Some time ago Tim Ruehsen suggested to use a different strategy: to pass
a flag to GCC so it marks all symbols to have hidden visibility by
default, and then to annotate the function declarations in
libpoke/libpoke.h.

I think the later approach is preferable.
Opinions?


I agree.

I think we can have a macro like this:

```c
#define LIBPOKE_API __attribute__ ((visibility ("default")))
```

and mark all the public functions with this macro.

Also we can have a list of all public functions in a separate file and add
a testcase to check the `libpoke.so` against that file.
This way maintaining a stable API is much simpler and less error-prone.
Adding/removing of symbols is also explicit.

Good suggestion from Mohammad-Reza, such a link-time test prevents forgetting to tag functions with LIBPOKE_API.

Also, the gnulib module 'lib-symbol-visibility' should be added to bootstrap.conf.
Then, as an example from the wget2 project:

// see https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html
#if defined BUILDING_LIBWGET && HAVE_VISIBILITY
#       define WGETAPI __attribute__ ((__visibility__("default")))
#elif defined BUILDING_LIBWGET && defined _MSC_VER && !defined LIBWGET_STATIC
#       define WGETAPI __declspec(dllexport)
#elif defined _MSC_VER && !defined LIBWGET_STATIC
#       define WGETAPI __declspec(dllimport)
#else
#       define WGETAPI
#endif

Possibly looks a bit over-engineered. Despite from caring for MSC, which you might want to remove, you can also see the handling of a static build. You would use -DBUILDING_LIBWGET in the Makefile.am for the library (libraries !?), but not when you build poke itself.

(Hiding again behind a wall of work and hoping to someday get more time to join again with all you awesome people here !)

Regards, Tim

Attachment: OpenPGP_0x08302DB6A2670428.asc
Description: application/pgp-keys

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]