home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp / 9820 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.6 KB

  1. Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!hpscdc!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!mjs
  2. From: mjs@hpfcso.FC.HP.COM (Marc Sabatella)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: Linker selection of symbols from shared-libs
  5. Message-ID: <7371271@hpfcso.FC.HP.COM>
  6. Date: 28 Aug 92 17:12:16 GMT
  7. References: <3270@tivoli.UUCP>
  8. Organization: Hewlett-Packard, Fort Collins, CO, USA
  9. Lines: 46
  10.  
  11. In comp.sys.hp, stuart@TIVOLI.COM (Stuart Jarriel) writes:
  12.  
  13. > Lets say I have a shared lib, libmine.sl, and there is a function in
  14. > libmine.sl called write().
  15. > So I build my program with:
  16. > cc program.c -o program -lmine
  17. > will program use the write in libc.sl or in libmine.sl?
  18. > (actually, the answer is libc.sl)
  19.  
  20. Actually, your program will use "write", but any libc routine that use "write"
  21. internally will use the libc "write".  This is ANSI-specificied behavior -
  22. since "write" is not reserved by ANSI, you are free to define it yourself, and
  23. this is not allowed by ANSI to interfere with the behavior of, say, fwrite().
  24. Every standard has their own set of reserved symbols.  Rather than try to
  25. support a different version of libc for every standard in existence, we elected
  26. to simply force all calls within libc to resolve internally by default, with
  27. the exception of malloc(), which is redefined so often we decided to allow it
  28. to work by default.  It is reserved by all standards, so any program that
  29. defines it is non-conforming, so we don't violate any standards by allowing the
  30. redefinition.
  31.  
  32. To override the default behavior, you need to call your function "_write"
  33. instead of "write".  If you do an "nm" on libc, you'll see there is a "write"
  34. and a "_write" (with extra underscores on 300/400's) with the same address, and
  35. that the "write" is marked "secondary".  This is so you can define your own
  36. "write" without causing a multiply-defined symbol error (secondary defnitions
  37. are ignored if a prior definition is seen).  Now libc routines such as "fwrite"
  38. will call your "_write".  If you want to define "write" as well, either make
  39. them aliases via some assembly twiddling, or simply have "write" turn around
  40. and call "_write".
  41.  
  42. This same advice holds for any libc symbol (other than malloc) you want to
  43. redefine in this manner.  You should "nm" first, though, to check the correct
  44. spelling of the aliased (primary) name - sometimes there are more underscores.
  45. For example, there was already an "_exit", so the primary name for "exit" is
  46. "__exit".
  47.  
  48. --------------
  49. Marc Sabatella (marc@hpmonk.fc.hp.com)
  50. Disclaimers:
  51.     2 + 2 = 3, for suitably small values of 2
  52.     Bill (H.) and Dave (P.) may not always agree with me
  53.