greg@tasis.UUCP (09/29/87)
A question for the 4.2BSD gurus: Has anyone played around with (and got working) the -A flag with 'ld'? This flag (according to the manual) provides incremental loading and allows an object to be loaded into an already executing program. It doesn't seem to be well documented anywhere that I can find. Has anyone got a simple test program that uses this feature? Thanks, Greg Watson ACSnet: greg@tasis.utas.oz ARPA: greg%tasis.utas.oz@uunet.uu.net UUCP: {enea,hplabs,mcvax,uunet,ukc}!munnari!tasis.utas.oz!greg
alan@ecrcvax.UUCP (Alan P. Sexton) (10/05/87)
In article <465@tasis.utas.oz> greg@tasis.utas.oz (Greg Watson) writes: >A question for the 4.2BSD gurus: > >Has anyone played around with (and got working) the -A flag with 'ld'? >This flag (according to the manual) provides incremental loading and >allows an object to be loaded into an already executing program. > >It doesn't seem to be well documented anywhere that I can find. Has anyone >got a simple test program that uses this feature? > >Thanks, > >Greg Watson > #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # README # Makefile # main.c # tst.c # This archive created: Mon Oct 5 09:12:25 1987 export PATH; PATH=/bin:$PATH echo shar: extracting "'README'" '(316 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else sed 's/^X//' << \SHAR_EOF > 'README' XHow to do Dynamic loading in BSD4.[23] X XInstructions: X run make X run main X output should be similar to the following: X Xmain Xcurrend = 000033fc X/bin/ld -N -A main -T 33fc tst.o -o tmpfil -lc Xreadsize = 200 Xreadsize = 512, entry = 00000000, currend = 000033fc X XThis line was printed by a dynamically loaded subroutine SHAR_EOF if test 316 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 316 characters)' fi fi # end of overwriting check echo shar: extracting "'Makefile'" '(76 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' Xall: main tst.o X Xmain: main.c X cc -o main main.c X Xtst.o: tst.c X cc -c tst.c SHAR_EOF if test 76 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 76 characters)' fi fi # end of overwriting check echo shar: extracting "'main.c'" '(1201 characters)' if test -f 'main.c' then echo shar: will not over-write existing file "'main.c'" else sed 's/^X//' << \SHAR_EOF > 'main.c' X#include <stdio.h> X#include <a.out.h> X X#define round(x,s) ((((x)-1) & ~((s)-1)) + (s)) X Xextern char *sbrk() ; X Xmain() X{ X int i, fd, readsize ; X struct exec header ; X char buf[512], *currend ; X int (*f)() ; X X printf("main\n") ; X currend = sbrk(0) ; X printf("currend = %08x\n", currend) ; X sprintf(buf,"/bin/ld -N -A main -T %x tst.o -o tmpfil -lc", currend); X printf(buf) ; X putchar('\n') ; X if (i = system (buf)) X { X printf("error: system returned %x\n", i) ; X exit() ; X } X if ((fd = open("tmpfil", 0)) <0) X { X printf("can't open tmpfil\n") ; X exit() ; X } X if (read(fd, (char *)&header, sizeof(header)) <= 0) X { X printf (" error in reading header of new a.out\n") ; X exit() ; X } X readsize = round(header.a_text,4) + round(header.a_data,4); X readsize = round(readsize+header.a_bss, 512) ; X printf("readsize = %x\n", readsize) ; X if (sbrk(readsize) == 0) X { X printf("error: cannot sbrk %d bytes\n", readsize) ; X exit() ; X } X if (readsize != read(fd, currend, readsize)) X { X printf("error: cannot read %d bytes\n", readsize) ; X exit() ; X } X printf ("readsize = %d, entry = %08x, currend = %08x\n", X readsize, header.a_entry, currend) ; X f = (int (*)())(currend+header.a_entry) ; X (*f)() ; X} SHAR_EOF if test 1201 -ne "`wc -c < 'main.c'`" then echo shar: error transmitting "'main.c'" '(should have been 1201 characters)' fi fi # end of overwriting check echo shar: extracting "'tst.c'" '(84 characters)' if test -f 'tst.c' then echo shar: will not over-write existing file "'tst.c'" else sed 's/^X//' << \SHAR_EOF > 'tst.c' Xtry() X{ X printf("\nThis line was printed by a dynamically loaded subroutine\n") ; X} SHAR_EOF if test 84 -ne "`wc -c < 'tst.c'`" then echo shar: error transmitting "'tst.c'" '(should have been 84 characters)' fi fi # end of overwriting check # End of shell archive exit 0 -- Alan Sexton ECRC, Arabellastr 17, alan@ecrcvax.UUCP 8000 Muenchen 81, West Germany mcvax!unido!ecrcvax!alan tel. (089) 92699164
martin@iris.ucdavis.edu (Bruce K. Martin Jr.) (10/12/87)
>In article <465@tasis.utas.oz> greg@tasis.utas.oz (Greg Watson) writes: >A question for the 4.2BSD gurus: > >Has anyone played around with (and got working) the -A flag with 'ld'? >This flag (according to the manual) provides incremental loading and >allows an object to be loaded into an already executing program. On a very similiar note... I'm interested in writing a dynamic loader for COFF files (something very similiar to what ld -A does). Before I go off and re-invent the wheel, has anyone done something like this? thanks! ...bruce Bruce K. Martin, UC. Davis, Div. of Computer Science martin@iris.ucdavis.edu --or-- {ucbvax | lll-crg}!ucdavis!iris!martin