when linking an elf application or share library, I want to choose which symbols to export. By default, when linking an application no function symbol is exported and when linking a shared library all function symbols are exported. Is there any way to control which symbols to export? When linking an application, I can use -rdynamic
or -Wl,--export-dynamic
to get all symbols, and I can use -Wl,--dynamic-list <symfile>
to get only some symbols. However when linking a library, are those options ignored?
Asked
Active
Viewed 3,206 times
0

Kouros
- 341
- 5
- 19
-
Possible duplicate of [Limiting visibility of symbols when linking shared libraries](http://stackoverflow.com/questions/435352/limiting-visibility-of-symbols-when-linking-shared-libraries) – Employed Russian Jan 15 '16 at 04:59
2 Answers
4
Found out after testing a little:
for ELF applications, you can use
-rdynamic
or-Wl,--export-dynamic
to export all symbols, or you can use-Wl,--dynamic-list <sym-file>
to export only some symbols when linking your application throughgcc
.for ELF libraries, you can't use
-rdynamic
,-Wl,--export-dynamic
or-Wl,--dynamic-list <symfile>
, you must use-Wl,--version-script=<verfile>
when linking your library throughgcc
.
The version-script and the sym-file are almost the same, except that for sym-file you do not code a version and a scope. Documentation: gnu ld

Kouros
- 341
- 5
- 19
2
Is there any way to control which symbols to export?
The usual way to control symbol visibility in shared library is either
- Use linker script, as described here, or
- Use
__attribute__((visibility("default")))
on symbols you explicitly want to export and build with-fvisibility=hidden
(which will hide everything else).

Community
- 1
- 1

Employed Russian
- 199,314
- 34
- 295
- 362