home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / bsd / 5602 < prev    next >
Encoding:
Text File  |  1992-09-12  |  6.9 KB  |  141 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!rpi!usenet.coe.montana.edu!news.u.washington.edu!serval!yoda.eecs.wsu.edu!hlu
  3. From: hlu@yoda.eecs.wsu.edu (H.J. Lu)
  4. Subject: Re: Shared Libs for X11?, was Re: 386bsd -- The New Newsgroup
  5. Message-ID: <1992Sep12.170425.23299@serval.net.wsu.edu>
  6. Keywords: shared libraries X X11
  7. Sender: news@serval.net.wsu.edu (USENET News System)
  8. Organization: Washington State University
  9. References: <18iprpINNg6e@agate.berkeley.edu> <1992Sep8.200625.2894@socrates.umd.edu> <veit.716026274@du9ds3> <18lkkkINN14d@agate.berkeley.edu> <veit.716107923@du9ds3> <7dnL02y821gh01@JUTS.ccc.amdahl.com> <veit.716291291@du9ds3>
  10. Date: Sat, 12 Sep 92 17:04:25 GMT
  11. Lines: 128
  12.  
  13. In article <veit.716291291@du9ds3> veit@du9ds3.uni-duisburg.de writes:
  14. >In <7dnL02y821gh01@JUTS.ccc.amdahl.com> gab10@griffincd.amdahl.com (Gary A Browning) writes:
  15. >>In article <veit.716107923@du9ds3>, veit@du9ds3.uni-duisburg.de (Holger
  16. >>Veit) writes:
  17. >[...]
  18. >>I just finished installing X and noticed that most binaries are several times
  19. >>larger than expected due to the lack of shared libraries.  I caught an article
  20. >>posted here a few days back that quickly described the SysVr3 approach of using
  21. >>fixed addresses for the libraries and the Sun/SysVr4 approach of using position
  22. >>independent code.
  23. >
  24. >>I tend to dislike the SysVr3 method since I got the impression that the source
  25. >>code had to be written differently (though I am not sure why).  I also noted
  26. >>that the GCC-2.2.2 compiler I just got compiled can produce PIC code which
  27. >>would be one of the major hurdles for the SysVr4 method.
  28. >
  29. >I don't like the fixed-address idea either, since it causes trouble with
  30. >applications that rely on the addresses. If someone wants to have some special 
  31. >library as shared he has to allocate some address for it. This will make this
  32. >space unavailable for others who wanted to use the same address and will cause
  33. >complex incompatibilities. It is, however, very simple to implement, and does
  34. >work if there is the intent to have one (forever fixed) set of standard
  35. >shared libraries. I looked at the Linux code and found it done exactly this
  36. >way, and it is recommended there to relink the object files on every new 
  37. >system.
  38. >
  39.  
  40. [....]
  41.  
  42. That will be the old news for Linux starting this Sunday. As a matter
  43. of fact, I have beening using the new scheme for a while. I fixed a bug
  44. in libc.a and made a new shared image. Then I did
  45.  
  46. ln -sf /lib/libc.so.4.1 /lib/libc.so.4
  47.  
  48. That fixed `date' without ever touching it. Here is the short
  49. note I wrote for the shared lib under Linux. I like it since it
  50. is simple. It requires almost no changes to GNU binutils 1.9 except for
  51. bug fixes. No gcc changes are needed. The kernel support is minimal.
  52.  
  53. A related issue, is there a good, simple way to resolve the global
  54. data without relinking the executables? Their addresses are very likely
  55. to change if the library codes are not written for the shared
  56. libraries.
  57.  
  58. H.J.
  59. -----
  60. The shared library under Linux started at 0.12. Peter MacDonald
  61. collaborating with Linus made the first generation of shared library,
  62. which is the base of the current classic shared library.
  63.  
  64. The kernel support of shared library under Linux is system call
  65.  
  66. extern int uselib (const char *__filename);
  67.  
  68. which loads an executable image with fixed entry point into memory,
  69. just like the ordinary executables.
  70.  
  71. In crt0.s, a function which can find out if and which shared images
  72. are needed and loads them is invoked before `main ()' is called if
  73. necessary. David Engel and I developed a way to tell the loader which
  74. shared images have to be loaded, utilizing the similar technique used
  75. in global constructor in g++ 2.x with the help from GNU binary
  76. utilities.
  77.  
  78. In the classic Linux shared library, we build a big executable image 
  79. for several libraries and make sure no external variables outside of
  80. the participating libraries are referenced. Then we can get the
  81. absolute addresses of all the global variables defined in the
  82. libraries used to build that executable image. After that, we make a
  83. stub library for each participating library which just has the
  84. absolute addresses of all the global variable in it.
  85.  
  86. For each shared image, there must be one and only one file, usually
  87. called, __shared.o, which defines a global variable containing
  88. version, name and entry point of the shared image, and a dummy global
  89. data. Among those libraries used to build the shared image, there must
  90. be one library which will always be referenced whenever any other
  91. library is referenced. We put `__shared.o' into the stub library for
  92. that library and add a declaration for the dummy global data defined
  93. in `__shared.o' which will make sure `__shared.o' will always be linked
  94. in when any participating libraries are linked.
  95.  
  96. In gcc 2.2.2d, jump table, developed by David Engel, was introduced in 
  97. the shared library. At the beginning of each shared image, there is
  98. a table in which every library function has a fixed entry address and
  99. the instruction at that address is a jump which will lead to the
  100. real library function. So we can change the library function without
  101. changing the corresponding entry address of the jump table. For the
  102. global data we put them at the beginning of data section of the shared
  103. image. We have to separate them from text code and link them in fixed
  104. order. It is very hard to maintain the same addresses for the global
  105. data when library is changed. After the global data are set up properly
  106. and some spaces are left for possible future changes (that is a very
  107. tough procedure.), it isn't too difficult to maintain.
  108.  
  109. In the current implementation, only libc.a, libcurses.a, libdbm.a,
  110. libtermcap.a and libm.a are built with jump table. The global data in
  111. X11 libraries are too complicated to make jump table such that their
  112. addresses won't change when there is a change in X11 libraries. It's
  113. not apparent yet that the benefits gained from a jump table version of
  114. the X libraries would offset the effort required to set it up and
  115. maintain it unless we get some cooperation from X Consortium, which
  116. is very unlikely. But they are linked with jump table version of
  117. libc.a and libm.a. That means they don't have to be relinked when
  118. there is a modification in libc.a or libm.a.
  119.  
  120. There are some guidelines for writing codes suitable for building the
  121. shared library with jump table.
  122.  
  123. 1. Never, ever allow library users to access global data directly.
  124.    Always, always make them go through access functions.  That way,
  125.    you are free to change the internal implementation, but can
  126.    easily provide backward compatibility by simply replacing the
  127.    access functions.
  128.  
  129. 2. If you do have to define some global data for library users to
  130.    access, put them into a separate file. Never mix them with other
  131.    library code. Also make sure the relative locations of the global
  132.    data will not change very often. One solution is leave some spaces
  133.    for them to grow.
  134.  
  135.  
  136. H.J. Lu
  137. hlu@eecs.wsu.edu
  138. 09/01/92
  139.  
  140.  
  141.