Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting shared library symbol visibility on Solaris

With GCC (on Linux) I can easily limit the visibility of symbols in shared libraries.

What are my options on Solaris (10)?

Do these GCC features also work with GCC on Solaris (especially with a GCC that uses the Solaris linker/assembler)?

And does the Solaris Studio C-compiler/linker provide similar attributes/pragmas for controlling the visibility of symbols (i.e. for setting the default to hidden and explicitly marking symbols as visible)?

like image 244
maxschlepzig Avatar asked Jan 13 '23 07:01

maxschlepzig


1 Answers

Another option is to use version script files. This works on Linux, Solaris/GCC and Solaris/CC.

Example

Consider a shared library where only a function power3() should be globally available. It uses power2() which is defined in another translation unit and power2() should be hidden.

Following version script specifies this:

$ cat vscript
{
  global: power3;
  local: *;
};

You can use one file for linking on Linux and Solaris - Linux/Solaris seem to understand the same syntactic constructs.

Build commands

System            Compiler   Link command
―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Linux Fedora 17   gcc-4.7.2  cc -shared -Wl,--version-script,vscript -fpic -o libpower.so ...
Solaris 10        gcc-4.8*   gcc -shared -Wl,-M,vscript -fpic -o libpower.so ...
Solaris 10        cc 12.3    cc -shared -M vscript -fpic -o libpower.so ...

Note that the GCC on Solaris is configured to use ld/as from /usr/ccs/bin.

like image 101
maxschlepzig Avatar answered Jan 26 '23 02:01

maxschlepzig