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