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)?
Another option is to use version script files. This works on Linux, Solaris/GCC and Solaris/CC.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With