Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix-wizards Subject: Re: ld and the -A option Message-ID: <4137@umcp-cs.UUCP> Date: Sat, 1-Nov-86 22:09:48 EST Article-I.D.: umcp-cs.4137 Posted: Sat Nov 1 22:09:48 1986 Date-Received: Mon, 3-Nov-86 22:27:38 EST References: <2517@gitpyr.gatech.EDU> Reply-To: chris@umcp-cs.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 55 In article <2517@gitpyr.gatech.EDU> allen@gitpyr.gatech.EDU (P. Allen Jensen) writes: >... Can anyone give me any documentation on how to make use of a >file generated using the -A option (eg for dynamic loading or >overlay loading)? Two years ago, padpowell@wateng (PAD Powell) posted a package that used `ld -A' for dynamic loading. I am not going to repost it. The idea, though, goes about like this: cc -o prog prog.c # note no `-s' ld -A prog -T newsubs.o -o tmp1 ; use nlist to find symbol addresses> ld -A tmp1 -T moresubs.o -o tmp2 ; use nlist to find symbol addresses> ld -A tmp2 -T yetmore.o -o tmp1 > `ld' can (should) be invoked directly from `prog'. The text addresses should be a suitable base address into which the new code can be read. `Suitable' is system dependent. 4BSD Vax Unix wants something that is a multiple of 1K. Other machines may require special system calls to make things text segments before they can be run. Other useful options are -N (keep ld from rounding up text and data segments to 1K---but beware more system dependencies) and -x (discard local symbols, e.g., those from `static' function declarations). The output files (tmp1 and tmp2) hold both the new code and the combined set of symbols from the new subroutines and the original program. After the three `ld' commands above, tmp1 has all symbols from prog, newsubs.o, moresubs.o, and yetmore.o. Once you have found symbol addresses with nlist, you can call the functions via C pointers: struct nlist nl[] = { { "_foo" }, }; ... nlist("tmp1", nl); if (nl[0].n_type == 0) whoops, could not find function foo (*(int (*)())nl[0].n_value)(arg1, arg2); /* call foo */ ... I am not sure if this is quite the same as what Patrick Powell's code does, but it is bound to be similar. Note that you need only two output files to keep symbols forever, although Franz Lisp uses a new one each time you call cfasl. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu