Section 7.7. Shared Libraries

team bbl


7.7. Shared Libraries

Most UNIX systems today support shared libraries. Arnold [1986] describes an early implementation under System V, and Gingell et al. [1987] describe a different implementation under SunOS. Shared libraries remove the common library routines from the executable file, instead maintaining a single copy of the library routine somewhere in memory that all processes reference. This reduces the size of each executable file but may add some runtime overhead, either when the program is first executed or the first time each shared library function is called. Another advantage of shared libraries is that library functions can be replaced with new versions without having to relink edit every program that uses the library. (This assumes that the number and type of arguments haven't changed.)

Different systems provide different ways for a program to say that it wants to use or not use the shared libraries. Options for the cc(1) and ld(1) commands are typical. As an example of the size differences, the following executable filethe classic hello.c programwas first created without shared libraries:

     $ cc -static hello1.c             prevent gcc from using shared libraries     $ ls -l a.out     -rwxrwxr-x 1 sar         475570 Feb 18 23:17 a.out     $ size a.out        text     data     bss     dec     hex    filename      375657     3780    3220  382657   5d6c1    a.out 

If we compile this program to use shared libraries, the text and data sizes of the executable file are greatly decreased:

     $ cc hello1.c                    gcc defaults to use shared libraries     $ ls -l a.out     -rwxrwxr-x 1 sar         11410 Feb 18 23:19 a.out     $ size a.out        text     data     bss   dec       hex    filename         872      256       4  1132       46c    a.out 

    team bbl



    Advanced Programming in the UNIX Environment
    Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
    ISBN: 0321525949
    EAN: 2147483647
    Year: 2005
    Pages: 370

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net