dynamic linking on sparc

Dave Jones megatest!djones at decwrl.dec.com
Sat May 13 06:02:16 AEST 1989


A few weeks ago, I posted some questions about dynamic linking on the
SPARC machine.  This is a follow-up.

The question is, "How does an executing program write some machine-code
into memory, then branch to it?"

If you can arrange for the code to acquire "execute-only" or "read-only"
status after it is properly munged, all the better, although that is not
strictly necessary.

This is the sort of thing typically done by a LISP compile/load/go loop,
for example, but it could apply to any language. (In my case, it's a
Pascal system which allows the user to type in statements interactively,
and to replace code-segments on the fly.) This has an obvious application
to debugging, but it is also useful in other less obvious ways.

I'm still getting mixed responses. One correspondent indicated that you
can still use ld -A in conjunction with sbrk(). (That worked on Sun3's.)

I find this difficult to credit, due to the SPARC machine's separate data
and instruction spaces. The problem is, after you have the memory all
loaded up with nicely relocated machine-code, how do you get the MMU to
believe it is in code-space, not data-space? (I find this "feature" of
separate code and data spaces to be more than a little bit irritating!)

Another correspondent mentions using "mmap" rather than "read" to get the
data into memory to begin with. This sounds like it is more on the track.
The program would read the file in, do any relocation necessary, write it
back to a file, then somehow use mmap to map that file in.  That would
work easily enough if the code were position-independent.  But if it were
not, the relocation phase would need to know where the mmap call would
eventually locate the file. I guess I need to know more about mmap. Can
anyone tell me what document describes mmap? I don't have any of the
manuals, but I'm willing to buy them.

The same correspondent mentions that Sun has plans to make their dynamic
link routine ld.so accessible to user programs through a procedural
interface. I'm not sure ld.so is general enough for my purposes, but it's
worth a look-see. Also not sure it's fast enough.  (On a Sun3/60, ld -A
takes about 6 sec, whereas my dynamic linker takes less than 50mS.)
Anyway, is it true that a procedural interface will be made available, and
if so when?

Finally, another writer says that he thinks gcc (Gnu's C++) uses dynamic
linking. I've looked at the sources I have on line, which are probably
quite old, and I've found nothing that looks like it does linking on the
fly. Can anyone comment?

Any help on this matter will be greatly appreciated.


	Thanks,



		Dave Jones
		Megatest Corp.
		880 Fox Lane
		San Jose, CA.
		95131

		(408) 437-9700 Ext 3227
		UUCP: {sun,decwrl,pyramid}!megatest!djones



More information about the Comp.sys.sun mailing list