Xref: utzoo comp.unix.wizards:23586 comp.lang.c:31318 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!mcsun!ukc!edcastle!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: OK, so why _does_ ld resolve text against data? Message-ID: <3274@skye.ed.ac.uk> Date: 23 Aug 90 15:07:37 GMT References: <1990Jul30.104726.22660@mtcchi.uucp> <37909@ucbvax.BERKELEY.EDU> <930@eplunix.UUCP> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 33 In article <930@eplunix.UUCP> das@eplunix.UUCP (David Steffens) writes: >This actually happened to one of our programmers (a good one, IMHO). >Should I call her "stupid" just because she doesn't know that "index" >is a _dirty name_ and might be used by some vendor in writing his library? A few points: - Having the linker refuse to resolve text references against data definitions (and vice versa) doesn't completely solve this problem. Suppose the programmer had written a procedure called "index"? - It's useful for the linker to resolve these references. Pointers to procedures are often passed around as data, and it's often useful to be able to execute code in the data segment. It might be reasonable for the linker to *warn* about the latter case, or require a flag. - A large part of the problem is that library procedures you call (which you probably know about) often call other ones (which you may not know about). I had to debug a program which had run quite happily until it was moved onto a machine which was a Sun yellow pages client, and suddenly getpwent() was calling select(), which the programmer had used as a variable name. The solution is for library routines to call other library routines under different names (eg ones starting with __). On the other hand, it can be useful to be able to replace a library routine and have other library routines use your version. -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin