[Updated: 04/07/2006] Much accurate information is available in a better format at:
Reducing Symbol Scope with Sun Studio C/C++__________________
The alternative to link-editor's -Bsymbolic is the compiler driver's -xldscope=symbolic flag. Sun ONE Studio 8 (aka S1S8) introducted a new flag -xldscope={global|symbolic|hidden} for specifying the appropriate linker scoping within the source program
"global" will be assumed as the value for -xldscope if none were specified. The interpretation for the value "global" from Sun's official documentation is as follows:
Symbol definitions have global linker scoping and is the least restrictive linker scoping. All references to the symbol bind to the definition in the first dynamic load module that defines the symbol. This linker scoping is the current linker scoping for extern symbols
The value "symbolic" will be interpreted as follows:
Symbol definitions have symbolic linker scoping and is more restrictive than global linker scoping. All references to the symbol from within the dynamic load module being linked bind to the symbol defined within the module. Outside of the module, the symbol appears as though it were global. This linker scoping corresponds to the linker option -Bsymbolic. Although you cannot use -Bsymbolic with C++ libraries, you can use the __symbolic specifier without causing problems
Time to re-compile & build our libhidden with the new compiler flag -xldscope=symbolic
bpte4500s001:/sunbuild1/giri/testcases/symbol-hiding/%CC -xldscope=symbolic -c hidden.c
bpte4500s001:/sunbuild1/giri/testcases/symbol-hiding/%CC -G -xldscope=symbolic -o libhidden.so hidden.o
bpte4500s001:/sunbuild1/giri/testcases/symbol-hiding/%CC -o driver -lgeneric -lhidden driver.c
bpte4500s001:/sunbuild1/giri/testcases/symbol-hiding/%./driver
lname = mandalika
age = 35
first char = c
It works!!
Simple; ain't it?
bpte4500s001:/sunbuild1/giri/testcases/symbol-hiding/%elfdump -C -s libhidden.so
Symbol Table: .dynsym
index value size type bind oth ver shndx name
[3] 0x00010870 0x00000004 OBJT GLOB P 0 .data age
[12] 0x00000598 0x00000020 FUNC GLOB P 0 .text char firstchar(char*)
[15] 0x00000558 0x0000002c FUNC GLOB P 0 .text char*lastname(char*)
[19] 0x00000518 0x0000002c FUNC GLOB P 0 .text int addtentomyage(int)
[20] 0x000005c8 0x00000038 FUNC GLOB P 0 .text int agefunc()
All the symbols of libhidden are still "global" (GLOB) & Protected (P)
What are the advantages & disadvantages of having all symbols in default (global) scope?
(to be continued ..)