Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rice!sun-spots-request From: richard@aiai.edinburgh.ac.uk (Richard Tobin) Newsgroups: comp.sys.sun Subject: Re: Dynamic linking on SunOS 4.x Keywords: SunOS Message-ID: <6087@brazos.Rice.edu> Date: 26 Mar 90 16:38:18 GMT Sender: root@rice.edu Organization: Sun-Spots Lines: 37 Approved: Sun-Spots@rice.edu X-Refs: Original: v9n96, Replies: v9n93 X-Sun-Spots-Digest: Volume 9, Issue 93, message 6 > 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