Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cs.utexas.edu!pp!cadillac!beihl From: beihl@cadillac.CAD.MCC.COM (Gary Beihl) Newsgroups: comp.sys.apollo Subject: Dynamic loading summarized Message-ID: <685@cadillac.CAD.MCC.COM> Date: 3 Jan 89 15:20:46 GMT Organization: MCC VLSI-CAD Program, Austin, TX Lines: 40 Thanks to those who responded to my recent inquiry regarding dynamic loading. What follows is a summary of what I've learned. It is indeed possible to dynamically load .o files under the Apollo version of BSD Unix (SR10.0). There are a few gotchas however, which keep us from using it in our application. First, the .o file to be loaded has to be compiled with the "-pic" (position-independent code) option. This can be done under BSD by specifying -W0,-pic to /bin/cc. I believe some performance penalty is paid when using this option due to an extra level of indirection. Second, use the loader_$load() call to access the system loader. With the proper setting of options to this function, one can lookup symbols and execute functions in the new code. The rub comes when the new object tries to reference symbols in the original executable. You can't (by default). It was suggested to me that I redefine main() to be a stub which dynamically loads the entire program, thus making all symbols known. Unfortunately, this means everything must be compiled with -W0,-pic. The loader kept telling me there was some part of my main program requiring linking (I assume this meant not compiled with -pic). The `file' command does not distinguish -pic from normal code. Perhaps some of the system libraries were being complained about. I *did* compile all the application code with -pic. It seems to me that a better solution to this problem is to have an incremental option on the linker. The BSD interface does not provide one. Perhaps it's possible under AEGIS. I don't think so. Incremental linking eliminates the need for position independent code, since the code can be custom-relocated to the virtual address specified by the loading application. -- Gary Beihl (beihl@mcc.com)