nick@mucs6.cs.man.ac.uk (Nick Filer) (09/06/90)
We have several libraries which have been in use for several years and are designed to be Inlib'ed rather than being stored in every binary file. Having moved to SR10.1 on our DN4000's we discovered that producing an inlib-able library using either "bind" or "ld" does not work as the library contains "absolute code". Has anybody out there managed to produce libraries of routines which can be inlib'ed on SR10. Both we and the HP Response Center (ref E1487117) in the UK have been trying to find a way. We have tried both SR10.1 and SR10.2 machines using both "bind" and "ld" with suitable incantations which either worked on previous versions (e.g. SR9.7) or are attempts to understand the manual pages. Below is a tiny C program which we have used to demonstrate the problem. Any help will be gratefully recieved. ---------------------------------------------------------------------- Dr Nick Filer Room: IT405 Department of Computer Science Telephone: +44-61-275-6171 University of Manchester FAX: +44-61-275-6280 Manchester M13 9PL Europe: nfiler@uk.ac.man.cs UK US: nfiler@cs.man.ac.uk ----------------------------------------------------------------------- /* Small C program designed to inlib hp_foo.c fails in final load as the library hp_foo.lib contains absolute code Tried using SR10.1 and SR10.2 BSD4.3 Ours is a DN4000 */ /* hp_foo.c */ #include <stdio.h> foo() { printf("In Foo\n"); } ===================================================================== /* hp_main.c */ #include <stdio.h> main() { printf("Starting\n"); foo(); printf("Finished\n"); } ======================================================================== # Makefile hp: hp_main.o hp_foo.lib ld -o hp hp_main.o -A inlib,hp_foo.lib hp_main.o : hp_main.c cc -c hp_main.c hp_foo.o : hp_foo.c cc -c hp_foo.c hp_foo.lib : hp_foo.o ld -r -o hp_foo.lib hp_foo.o ========================================================================= *** Commands *** cc -c hp_main.c cc -c hp_foo.c ld -r -o hp_foo.lib hp_foo.o ld -o hp hp_main.o -A inlib,hp_foo.lib # substituting "bind" in place of "ld" makes no difference. -- ---------------------------------------------------------------------- Dr Nick Filer Room: IT405 Department of Computer Science Telephone: +44-61-275-6171 University of Manchester FAX: +44-61-275-6280 Manchester M13 9PL Europe: nfiler@uk.ac.man.cs UK US: nfiler@cs.man.ac.uk -----------------------------------------------------------------------
lambert@spectrum.cs.unsw.oz.au (Tim Lambert) (09/07/90)
>>>>> On 6 Sep 90 05:44:04 GMT, nick@mucs6.cs.man.ac.uk (Nick Filer) said: > We have several libraries which have been in use for several years and > are designed to be Inlib'ed rather than being stored in every binary > file. Having moved to SR10.1 on our DN4000's we discovered that > producing an inlib-able library using either "bind" or "ld" does not > work as the library contains "absolute code". Yes, you have to tell the compiler to produce position independent code. And you have to tell ld to load it into "high" memory. And when compiling the main program, you should tell the compiler about the library. One of your make rules was correct :-) The manual that talks about creating shared libraries is more than a little obscure. Try using this makefile: ------------------------------------------------------- hp: hp_main.o hp_foo.lib ld -o hp hp_main.o -A inlib,hp_foo.lib hp_main.o : hp_main.c hp_foo.lib cc -c -W0,-inlib,hp_foo.lib hp_main.c hp_foo.o : hp_foo.c cc -c -W0,-pic hp_foo.c hp_foo.lib : hp_foo.o ld -r -a -A loadhigh -o hp_foo.lib hp_foo.o ------------------------------------------------------- Tim
wjw@eba.eb.ele.tue.nl (Willem Jan Withagen) (09/07/90)
In article <NICK.90Sep6144403@mucs6.cs.man.ac.uk> nick@mucs6.cs.man.ac.uk (Nick Filer) writes: >Has anybody out there managed to produce libraries of routines which >can be inlib'ed on SR10. Both we and the HP Response Center (ref >E1487117) in the UK have been trying to find a way. We have tried both >SR10.1 and SR10.2 machines using both "bind" and "ld" with suitable >incantations which either worked on previous versions (e.g. SR9.7) or >are attempts to understand the manual pages. I guess taht not everybody real a whole manual before the're going to (re)implement something they did before. But the answer is in the manual. But you have to know where to look! Since OS10.2 does a compiler generate absolute code, whilest it generated pic (position independant code) before we went to more *REAL* unix. And here's your problem, libraries for inlib require 'pic'-code. This is only one switch on the compile command, see the C-manual on page 6-39 Succes, Willem Jan Withagen. Eindhoven University of Technology DomainName: wjw@eb.ele.tue.nl Digital Systems Group, Room EH 10.10 BITNET: ELEBWJ@HEITUE5.BITNET P.O. 513 Tel: +31-40-473401 5600 MB Eindhoven The Netherlands
krowitz@RICHTER.MIT.EDU (David Krowitz) (09/07/90)
By default, the SR10 compilers produce "absolute code" (memory references that are to variables that are not on the stack are made to a fixed location rather than to a location relative to the program counter; and jump/branch instructions are made to fixed locations rather than relative to the program counter). You can produce position independent code by using the Apollo specific switch "-pic" when compiling your code. This is required for all code which is loadable at run time (ie. inlib libraries, device drivers, IOS type managers, etc). SR9.7 compilers always produced position independent code, which is supposedly slower than absolute code. We haven't seen any significant speed improvements, however. -- David Krowitz krowitz@richter.mit.edu (18.83.0.109) krowitz%richter.mit.edu@eddie.mit.edu krowitz%richter.mit.edu@mitvma.bitnet (in order of decreasing preference)
winters@hpfcbig.SDE.HP.COM (Daryl Winters) (09/08/90)
You need to compile using '-pic' (position independant code) in order to make a shared library. Make the following changes to your Makefile: ------------------------------------------------------------------------- # Makefile hp: hp_main.o hp_foo.lib ld -o hp hp_main.o -A inlib,hp_foo.lib hp_main.o : hp_main.c hp_foo.lib # -A inlib is needed to help the compiler generate pic calls cc -A inlib,hp_foo.lib -c hp_main.c hp_foo.o : hp_foo.c # -W0,-pic is needed in order to create pic code for the library cc -W0,-pic -c hp_foo.c hp_foo.lib : hp_foo.o # -r AND -a is needed in order to generate a relocatable shared library ld -r -a -o hp_foo.lib hp_foo.o ------------------------------------------------------------------------- It is the combination of -W0,-pic on the compile plus -r -a on the link which will permit you to create and access a shared library. Hope this helps, Daryl Winters (Just a Bozo)