Feature #2859
open
Explicitly export public symbols
Added by Junxiao Shi over 9 years ago.
Updated about 3 years ago.
Description
(split from #2243-16)
Build the shared library with -fvisibility=hidden
and explicitly export every public symbol with a macro.
Benefits include faster library load time, smaller library size, and lower chance of symbol collisions.
- Blocked by Task #2243: Allow building of shared library added
- Subject changed from Explicitly export public types to Explicitly export public symbols
- Start date deleted (
06/07/2015)
This should be done in 3 steps:
- Define a macro, e.g.
#define NDN_CXX_EXPORT __attribute__((visibility("default")))
- Apply the above macro to every library symbol that we want to export (and that will define our public ABI)
- Add
-fvisibility=hidden
to the default CXXFLAGS for the library
- Description updated (diff)
- Description updated (diff)
Ad interim, we could consider adding flags such as -Bsymbolic-functions
, -fvisibility-inlines-hidden
, -fno-semantic-interposition
, and -fno-plt
.
Two very relevant articles (though pretty technical and not easy to read) are:
https://maskray.me/blog/2021-05-09-fno-semantic-interposition
https://maskray.me/blog/2021-05-16-elf-interposition-and-bsymbolic
Moreover, we should build all executables (including nfd, etc.) with -fPIE which has a number of benefits including performance. While on some linux distros gcc is configured to build PIE binaries by default, it's not necessarily the case on every distro or every ELF platform, so we should pass -fPIE explicitly to be safe.
Also available in: Atom
PDF