[net.lang.c] Appending to executables.

adam@lzmi.UUCP (10/17/84)

It is not true that one cannot write a Unix executable to which
additional functions can be appended at runtime. One of the uses of
shared memory, available in System V and V(2), is linking executables at
runtime. All you need to do is define the shared memory, then fork and
exec a process that copies some of its own functions into shared memory
and then goes to sleep.
					Adam Reed
					lzmi!adam

padpowell@wateng.UUCP (PAD Powell) (10/17/84)

In the past, I posted to net.sources a set of routines that allowed dynamic
loading of object code into an executable.  The technique requires:
1.  program must know or be able to find the name or the executing text (code)
	file.
2.  be supplied the names of the functions to be loaded.
3.  an object file or library containing functions.

It is done by:
1.  invoking ld with special flags that cause a file to be generated containing
	all the referenced functions.
2.  allocating memory using malloc(3) or sbrk(2) to hold the new functions
3.  reading the new functions into the allocated area.

If there is interest, I will repost to the net.  The current version is for
BSD4.2,  and needs only to be recompiled to run under BSD4.1, and to have
the loader output file format lookup routines modified to run under SV

Patrick Powell

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (10/19/84)

> It is not true that one cannot write a Unix executable to which
> additional functions can be appended at runtime. One of the uses of
> shared memory, available in System V and V(2), is linking executables at
> runtime. All you need to do is define the shared memory, then fork and
> exec a process that copies some of its own functions into shared memory
> and then goes to sleep.

Can we absolutely count on being able to read instruction space and
write another chunk of instruction space from a user process?

The above idea seems pretty kludgy.  Will the new memory management
system for future UNIX System V (or whatever) support a reasonable
solution to shared libraries, dynamic linking, etc.?

crm@duke.UUCP (Charlie Martin) (10/22/84)

I, for one, would be VERY interested in the appending-to-
executable-code routines.

Charlie Martin
(...mcnc!duke!crm)