Project

General

Profile

Actions

Feature #2859

open

Explicitly export public symbols

Added by Junxiao Shi over 9 years ago. Updated about 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Build
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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.


Related issues 1 (0 open1 closed)

Blocked by ndn-cxx - Task #2243: Allow building of shared libraryClosedAlex Afanasyev

Actions
Actions #1

Updated by Junxiao Shi over 9 years ago

  • Blocked by Task #2243: Allow building of shared library added
Actions #2

Updated by Davide Pesavento over 9 years ago

  • 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:

  1. Define a macro, e.g. #define NDN_CXX_EXPORT __attribute__((visibility("default")))
  2. Apply the above macro to every library symbol that we want to export (and that will define our public ABI)
  3. Add -fvisibility=hidden to the default CXXFLAGS for the library
Actions #3

Updated by Davide Pesavento over 9 years ago

Also note that -fvisibility=hidden makes -fvisibility-inlines-hidden redundant.

Further reading: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html

Actions #4

Updated by Junxiao Shi over 9 years ago

  • Description updated (diff)
Actions #5

Updated by Davide Pesavento over 3 years ago

  • Description updated (diff)
Actions #6

Updated by Davide Pesavento about 3 years ago

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.

Actions

Also available in: Atom PDF