Subject: Shared libs and Linux compat (was ARM Linux)
To: Peter Berg <Peter.Berg@ww.tu-freiberg.de>
From: Mark Brinicombe <amb@physig4.ph.kcl.ac.uk>
List: port-arm32
Date: 11/12/1996 12:23:48
>> He has shared libraries but only in a.out format, i.e. no
>> position-independent code and no ELF.
>
>Can someone explain me why this isn't possible under RiscBSD ?

'Proper' shared libraries require position independant code (The gcc -fpic
option). This means that one copy of the library is help in memory and each
executable is sees its own copy of the library at its own address.
This means that although the physical memory the code is held in is shared it
will be mapped at different virtual addresses for each process.
This means that the code cannot have any absolute references.
Normally (if you look at gcc assembly) variables in the data area are
referenced via a constant in the text area

e.g.

	.text

Lmyvariable:
	.word	_myvariable

_myfunc:
	ldr	r0, Lmyvariable
	ldr	r0, [r0]
	mov	pc, r14

	.data
_myvariable:
	.word	0x11223344

The .address of _myvariable for the .word instruction sorted out at link time.
This means that the library would need to be linked to a standard address and
everything would access the shared library from that address. This is the Linux
a.out approach to shared libraries as I understand it.
It means that every shared library needs to be given its own base address in
memory that will not clash with any other code so that it can be shared across
processes.

Using an -fpic approach the compile would not generate the above code but would
say instead use a register (a particular register is often reserved for this)
to reference a table to find the address of the varariable.
This way the text area does not have any addresses hardcoded at link time.

This second approach is the NetBSD approach to shared libraries and as yet is
not supported by NetBSD/arm32. The fixed address method is something that the
kernel team consider a 'hack' and decided to wait until a proper implementation
could be provided.

>But now nearly everything in Linux is ELF now and I know no BSD system which
>can handle ELF binaries.
Might I suggest NetBSD ... NetBSD has ELF support for those platform where ELF
versions of gcc exists.

>In general, it would be possible to make both systems a little bit more
>compatible, but therefore you must write some linux compat libs for BSD
As I think I may have mentioned in another posting NetBSD already has Linux
compat modules.

Cheers,
				Mark

-- 
Mark Brinicombe				amb@physig.ph.kcl.ac.uk
Research Associate			http://www.ph.kcl.ac.uk/~amb/
Department of Physics			tel: 0171 873 2894
King's College London			fax: 0171 873 2716