Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!eneevax!mimsy!oddjob!gargoyle!ihnp4!homxb!mtuxo!mtune!codas!cpsc6a!rtech!wrs!dg From: dg@wrs.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: near / far branches Message-ID: <420@wrs.UUCP> Date: Thu, 15-Oct-87 20:26:42 EDT Article-I.D.: wrs.420 Posted: Thu Oct 15 20:26:42 1987 Date-Received: Sun, 18-Oct-87 02:21:04 EDT References: <117@nusdhub.UUCP> Reply-To: dg@wrs.UUCP (David Goodenough) Organization: Wind River Systems, Emeryville, CA Lines: 52 In article <117@nusdhub.UUCP> rwhite@nusdhub.UUCP (Robert C. White Jr.) writes: > First, a linker is a "linking loader" and it's only REAL >purpose is to resolve refrences and setup dynamic relocation >information. ALL "short" jumps [add/subtract value from the >instruction pointer directly] are compleetly generated and closed >in the assembler. If there were to be an alteration in the size >of a block of code-text, the linker would have to "reassemble" the >code block to make up for the altered "short" jumps and such. In >order for the linker to do this it would either need the source >code, or it would have to take a stab at disassembeling the object >code and hope not to get it wrong. Not true - every (useful) assembler out there can generate information that a given word needs to be relocated in some way, so why not just have two types or relocation: far (for unresolved, long distance) and near (for resolved, short distance) > The assembler is designed to AUTOMATICALLY determine the >"near"ness or "far"ness of a refrence. This works beautfuly as >long as you act like a pascal programmer and only use backward >refrences. For the forward refrences you must use a keyword like >"near" or "far" or else take what you get, and hope what you get >is close enough to work. Wrong again - I have seen many assemblers in my time, and only one was a single pass animal (and it was a real sharp piece of software - had to maintain two symbol tables: one for defined labels, and another for unresolved references). Think about it for half a second, you have to do a second pass to resolve all the forward references anyway, so all you do is add a link field to your symbol table, linking the symbols together in address order, then whenever you munge a far / near branch, just run up the chain adjusting all the references (this actually requires a third pass or O N^2 time based on the number of symbols). > It should be obvious that the assemblers job is to assemble >and the linkers job is to link. Open to discussion, I added the -X flag to my assembler to do an assemble and link all in one go on a source - saves some time as I get away with three passes (two for the assembly and one for linkage) as opposed to four (two each for the separate assembly and linkage) -- dg@wrs.UUCP - David Goodenough ..... !rtech!--\ >--!wrs!dg ..... !sun!--/ +---+ | +-+-+ +-+-+ | +---+