Shared library performance on SUN.
Hi All,
Please suggest some ways to improve shared library performance on SUN. I am mainly intrested in bringing down the system usage time when a application is run on SUN.
- Any compiler flags that give a better performance with shared libraries.
- Any particular settings that reduce time to access code in a shared library(some thing like setting lib perms as 555 in HP)
- Any other suggestions.
Thanks and Regards,
Shiv
[467 byte] By [
aparam] at [2007-11-26 10:26:37]

# 1
On SPARC, you have two ways to generate PIC (position-independent code): the -KPIC option ("big pic") and -Kpic ("little pic").
As explained in the Option Reference in the C++ Users Guide, you get better run-time performance with little pic, but the number of external symbols you can have in the shared library is limited. The simplest way to find out whether you can use -Kpic is to recompile the entire library using -Kpic and see if you get a linker complaint. (The linker will not create a shared library using little pic if there are too many global symbols.)
The remaining ways to improve performance have to do with the way your design your code and build the library.
1. Do not put global data into the shared library. The global data will be copy-relocated, and all references to it (inside and outside the library) will be indirect via the GOT.
2. Make sure there are no relocations against the text segment. They force copy-relocation of text (program) segments, which you really do not want. Build the library with the "-z text" option to cause the linker to complain about text relocations.
3. Hide all functions that are not in the external interface. The more global symbols you have, the longer it takes to load a shared library, and the less likely it is that you can use little pic on SPARC. All references to global functions are indirect via the PLT.
One way to restrict the number of global symbols is via a linker mapfile. Refer to the Linker and Libraries Guide for details.
A nicer way using Sun C++ is to use the linker scoping options of the compiler.You then do not need a linker mapfile. Refer to the C++ Users Guide, section 4.1 "Linker Scoping" for details. Quick-start guide:
3a. Use the option -xldscope=hidden on the CC command lines used to build the library components.
3b. For each function (and data object, if any) that you want to be visible outside the library, add the __global specifier.
4. If you have a group of shared libraries that are always used together, make them into one library, and repeat step 3.