Dynamic linking on SunOS 4.x
Richard Tobin
richard at aiai.edinburgh.ac.uk
Tue Mar 27 02:38:18 AEST 1990
> I am looking for information on how to do "dynamic linking" under SunOS.
It's a pity that there aren't standard Unix library functions for this.
Basically, this is what you do:
(1) Decide the address at which you want to load the code. Unfortunately
you do not yet know the size of the code, so if the address depends on
this (as it might if you're using malloc to get the space) you may have to
do two passes (yuk).
(2) Run /bin/ld to link the executable corresponding to the running
program with the .o file containing the function you want to load (and any
libraries it needs). You give ld the "-A" flag, which makes the resulting
.o file contain only the new code (ie not the stuff that was already
running). You also use the "-T" flag to specify the address you chose in
step (1).
(3) Now you read the header of the new .o file to find out how big the
text and data of the new code are.
(4) Read in the text and data from the new .o file.
(5) Use the nm library function to find the addresses of the new functions
you want to call from the new .o file.
If you want to load in functions that reference previously-loaded
functions, it may be possible to link against the .o file produced by the
previous load, but I haven't tried this.
>I thought shared libraries (.so) were the answer
No, shared libraries are the problem. You must link your original program
with -Bstatic so that the dynamic link works. (Actually, it's possible to
avoid this, but it may not be worth the effort especially if you're
interested in other versions of Unix.)
-- Richard
More information about the Comp.sys.sun
mailing list