1e01aa904Sopenharmony_ciPLEASE READ ALL OF THIS FILE, ESPECIALLY IF YOU ARE DEFINING A NEW 2e01aa904Sopenharmony_ciPUBLIC HEADER IN LIBABIGAIL. 3e01aa904Sopenharmony_ci 4e01aa904Sopenharmony_ciHow symbols that are exported are controlled in libabigail 5e01aa904Sopenharmony_ci========================================================== 6e01aa904Sopenharmony_ci 7e01aa904Sopenharmony_ciWe try to limit the number of ELF symbols that are exported by the 8e01aa904Sopenharmony_cilibabigail.so shared library. We call this, "symbol visibility control". 9e01aa904Sopenharmony_ci 10e01aa904Sopenharmony_ciAs GNU/Linux is our development platform, we control symbol visibility 11e01aa904Sopenharmony_ciby using the visibility support of the G++ compiler. 12e01aa904Sopenharmony_ci 13e01aa904Sopenharmony_ciHow to do so is properly explained at https://gcc.gnu.org/wiki/Visibility. 14e01aa904Sopenharmony_ci 15e01aa904Sopenharmony_ciAll symbols are hidden by default 16e01aa904Sopenharmony_ci================================= 17e01aa904Sopenharmony_ci 18e01aa904Sopenharmony_ciWhen building translation units that make up the libabigail.so shared 19e01aa904Sopenharmony_cilibrary, G++ is invoked with the -fvisibility=hidden directive. Which 20e01aa904Sopenharmony_ciinstructs it to make symbols of functions and global variables 21e01aa904Sopenharmony_ci*locally* defined in the shared library, *NOT* exported (or global). 22e01aa904Sopenharmony_ci 23e01aa904Sopenharmony_ciExporting symbols of entities declared in public headers 24e01aa904Sopenharmony_ci======================================================== 25e01aa904Sopenharmony_ci 26e01aa904Sopenharmony_ciIn a translation unit that is part of the libabigail.so shared 27e01aa904Sopenharmony_cilibrary, before including a header file that is a public libabigail 28e01aa904Sopenharmony_ciheader (e.g, abg-ir.h), one need to declare: 29e01aa904Sopenharmony_ci 30e01aa904Sopenharmony_ci #include "abg-internal.h" 31e01aa904Sopenharmony_ci ABG_BEGIN_EXPORT_DECLARATIONS 32e01aa904Sopenharmony_ci 33e01aa904Sopenharmony_cithen all the public header files inclusion (using #include directives) 34e01aa904Sopenharmony_cifollow. At the end of these public header files inclusion, one need 35e01aa904Sopenharmony_cito declare: 36e01aa904Sopenharmony_ci 37e01aa904Sopenharmony_ci ABG_END_EXPORT_DECLARATIONS 38e01aa904Sopenharmony_ci 39e01aa904Sopenharmony_ci 40e01aa904Sopenharmony_ciThe ABG_BEGIN_EXPORT_DECLARATIONS is a macro defined in abg-internal.h 41e01aa904Sopenharmony_ciwhich expands to: 42e01aa904Sopenharmony_ci 43e01aa904Sopenharmony_ci #pragma GCC visibility push(default) 44e01aa904Sopenharmony_ci 45e01aa904Sopenharmony_ciThis instructs G++ to export the symbol of all global functions and 46e01aa904Sopenharmony_civariables definitions that are declared from that point on. 47e01aa904Sopenharmony_ci 48e01aa904Sopenharmony_ciThe ABG_END_EXPORT_DECLARATIONS is a macro defined in abg-internal.h 49e01aa904Sopenharmony_ciwhich expands to: 50e01aa904Sopenharmony_ci 51e01aa904Sopenharmony_ci #pragma GCC visibility pop 52e01aa904Sopenharmony_ci 53e01aa904Sopenharmony_ciIt instructs G++ to stop exporting symbols of global functions and 54e01aa904Sopenharmony_civariable definition from that point on. 55e01aa904Sopenharmony_ci 56e01aa904Sopenharmony_ciIn practice, the pair ABG_BEGIN_EXPORT_DECLARATIONS, 57e01aa904Sopenharmony_ciABG_END_EXPORT_DECLARATIONS allows us to only export symbols of 58e01aa904Sopenharmony_ciglobal functions and variables declared in the block denoted by these 59e01aa904Sopenharmony_citwo macros. Symbols of anything else that is declared outside of that block 60e01aa904Sopenharmony_ciare going to be hidden, thanks to the -fvisibility=hidden option 61e01aa904Sopenharmony_cipassed to G++. 62e01aa904Sopenharmony_ci 63e01aa904Sopenharmony_ciSo whenever you are defining a new header file with declarations that 64e01aa904Sopenharmony_ciought to be part of the API of libabigail, the *definition* file which 65e01aa904Sopenharmony_cidefines the declarations of the header file must use 66e01aa904Sopenharmony_cithe ABG_BEGIN_EXPORT_DECLARATIONS and ABG_END_EXPORT_DECLARATIONS 67e01aa904Sopenharmony_cimacro to include the public header. 68