summaryrefslogtreecommitdiffstats
path: root/VISIBILITY
blob: 652ff13a40b4d649dceab75d185a1419fee33ac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
PLEASE READ ALL OF THIS FILE, ESPECIALLY IF YOU ARE DEFINING A NEW
PUBLIC HEADER IN LIBABIGAIL.

How symbols that are exported are controlled in libabigail
==========================================================

We try to limit the number of ELF symbols that are exported by the
libabigail.so shared library.  We call this, "symbol visibility control".

As GNU/Linux is our development platform, we control symbol visibility
by using the visibility support of the G++ compiler.

How to do so is properly explained at https://gcc.gnu.org/wiki/Visibility.

All symbols are hidden by default
=================================

When building translation units that make up the libabigail.so shared
library, G++ is invoked with the -fvisibility=hidden directive.  Which
instructs it to make symbols of functions and global variables
*locally* defined in the shared library, *NOT* exported (or global).

Exporting symbols of entities declared in public headers
========================================================

In a translation unit that is part of the libabigail.so shared
library, before including a header file that is a public libabigail
header (e.g, abg-ir.h), one need to declare:

    #include "abg-internal.h"
    ABG_BEGIN_EXPORT_DECLARATIONS

then all the public header files inclusion (using #include directives)
follow.  At the end of these public header files inclusion, one need
to declare:

    ABG_END_EXPORT_DECLARATIONS


The ABG_BEGIN_EXPORT_DECLARATIONS is a macro defined in abg-internal.h
which expands to:

    #pragma GCC visibility push(default)

This instructs G++ to export the symbol of all global functions and
variables definitions that are declared from that point on.

The ABG_END_EXPORT_DECLARATIONS is a macro defined in abg-internal.h
which expands to:

    #pragma GCC visibility pop

It instructs G++ to stop exporting symbols of global functions and
variable definition from that point on.

In practice, the pair ABG_BEGIN_EXPORT_DECLARATIONS,
ABG_END_EXPORT_DECLARATIONS allows us to only export symbols of
global functions and variables declared in the block denoted by these
two macros. Symbols of anything else that is declared outside of that block
are going to be hidden, thanks to the -fvisibility=hidden option
passed to G++.

So whenever you are defining a new header file with declarations that
ought to be part of the API of libabigail, the *definition* file which
defines the declarations of the header file must use
the ABG_BEGIN_EXPORT_DECLARATIONS and ABG_END_EXPORT_DECLARATIONS
macro to include the public header.