home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / linux / 8330 < prev    next >
Encoding:
Text File  |  1992-08-15  |  3.7 KB  |  78 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!wupost!gumby!yale!mintaka.lcs.mit.edu!hal.gnu.ai.mit.edu!ericy
  3. From: ericy@hal.gnu.ai.mit.edu (Eric Youngdale)
  4. Subject: Re: Jump Tables: A Mystery
  5. Message-ID: <1992Aug15.154100.29156@mintaka.lcs.mit.edu>
  6. Sender: news@mintaka.lcs.mit.edu
  7. Organization: /etc/organization
  8. References: <1992Aug15.085244.10732@nntp.hut.fi>
  9. Date: Sat, 15 Aug 1992 15:41:00 GMT
  10. Lines: 66
  11.  
  12. In article <1992Aug15.085244.10732@nntp.hut.fi> sakaria@vipunen.hut.fi (Sakari Aaltonen) writes:
  13. >
  14. >Several people responded to my recent whining about shared libraries
  15. >by mentioning "jump tables".
  16. >
  17. >Jump tables?
  18. >
  19. >Is there a book or an article that explains the structure of shared
  20. >libraries and of programs using them? I, too, would like to understand
  21. >jump tables. I just can't find anything on them in Tanenbaum.
  22.  
  23.     Think of it in the following way.  The sharable library is nothing
  24. more than some code that is guaranteed to be in a certain spot in virtual
  25. memory (actually, the way it is set up, the name of the sharable library is
  26. buried in your program startup code).  On linux, this address is the same for
  27. every process, so every process can share the code pages for the sharable
  28. libraries. 
  29.  
  30.     When you link your program to the sharable library, the linker resolves
  31. references to routines in the sharable library by using the actual addresses of
  32. the routines.  This by itself works just fine, except for the fact that
  33. when we update the library to fix bugs the addresses of the routines change
  34. and the executables will no longer work.  This means that you have to relink
  35. all of your programs.
  36.  
  37.     A jump table is just a series of jmp instructions, one right after
  38. another.  This is usually placed right at the beginning of the sharable image,
  39. and each jmp instruction jumps off to one of the routines in the sharable
  40. image.  The idea is that when a new version of the library comes out, that
  41. the jump table will still be in the same location in memory, and thus
  42. all of the references in your program to the sharable library will still
  43. effectively point to the correct routines.  Therefore you will still be able
  44. to run your program without having to relink it.
  45.  
  46.     The cost is the extra indirection of the jmp instruction.  The benefit
  47. is that you will not have to relink programs whenever you update the library.
  48. In the past we have not had the jump tables, and it basically meant having to
  49. keep the source code for *everything* on line, so that we could relink whenever
  50. a new library comes out.  It appears as if we are on the verge of relinking for
  51. the last time :-)
  52.  
  53. >My impression now is that shared libraries are something like MS-Windows
  54. >dynamic link libraries. "Dynamic" seems a good description, as a matter
  55. >of fact - code that is loaded into memory dynamically, at runtime.
  56. >
  57. >However, I think you can change MS-Windows DLL's as often as you like
  58. >without recompiling or relinking the programs that use the libraries.
  59. >You just have to keep the name of the DLL and the indexes of the functions
  60. >therein the same, because the calling programs refer to the functions by
  61. >library name (LINUX.DLL, say) and index (96, say). I don't know whether the
  62. >name of the function matters.
  63. >
  64. >Why can't shared libraries be like that?
  65.  
  66.     That sounds very much like a jump table to me.  The index is nothing
  67. more than the offset into the jump table, and you obviously need to know the
  68. library name.  The idea behind both the DLLs and the jump tables is that you
  69. can modify the library (i.e. fix bugs, add new functions, etc), without
  70. invalidating any executables that are linked to the library.
  71.  
  72. -Eric
  73. eric@tantalus.nrl.navy.mil
  74.  
  75. (My regular new server is down right now, so I am using this address for the
  76. time being).
  77.  
  78.