Professional Documents
Culture Documents
Ulrich Drepper
Enclose code which is used multiple times in different programs Enable dynamically loading additional functionality which
Properties of DSOs
Use of special compiler and linker options Some source code is inherently position dependent and needs to be rewritten for maximum performance
Optimize performance:
Minimize resource usage Minimize load times Minimize runtime overhead when using DSO
Each DSO has to be separately mapped into the process' address space Before first use, DSO must be adjusted for the chosen load address Symbols are searched for in many places for by name Calls which could cross DSO boundaries are indirect Variables which might be in another DSO are accessed indirectly
Use as few DSOs as possible. All code which is always used together should be in one DSO Write code which is inherently position independent to reduce relocation time
Each array element needs a relocation Array not read-only Relocations need memory at runtime
Avoid lookup by name when the definition is known to be local to the DSO:
Either do not export the symbol in the first place Or use a local alias to avoid the name lookup To reduce symbol table size and possibility of hash collision To reduce binary size (fewer strings etc)
Understand symbol lookup, global namespace, ... Identify symbols which are meant to be used from the outside Instruct linker to avoid exporting symbols not on the list Cleanup source code
Maintaining Compatibility
Programs using a DSO might be around forever Really incompatible DSO versions must not clash: identified by SONAME (simple string) Better: avoiding incompatibility
Good interface design (not discussed here) Use symbol versioning to provide multiple independent versions concurrently
intget_number(void){ return2; }
Applications linked against old DSO keep running Applications linked against new DSO will start using new definition Limitations:
Only executables and DSOs can be protected Data structure changes need to be handled separately, too
Additional Reading
http://people.redhat.com/drepper/dsohowto.pdf
Questions?