[comp.unix.programmer] Dynamic Loading

hallett@enterprise.positron.gemed.ge.com (Jeff Hallett x5163 ) (09/07/90)

Hi folks.

I'm interested in doing something funky.  I have a shell running that
basically interprets user commands and then calls a procedure to
handle the command.  Each command is self-contained.  Now, I want to
allow a user to add commands.  The mechanism I would like to try is to
have the user create a .o file with the compiled code in it, then,
when he enters his command into the shell, have the shell load the .o
file and execute the code in it.  The only problem is that I don't
have a clue where to look to figure out how to do this.

If anyone has an answer or a better idea, I'd love to hear about it.
Please send email and I'll post summaries.

Thanks.

--
	     Jeffrey A. Hallett, PET Software Engineering
      GE Medical Systems, W641, PO Box 414, Milwaukee, WI  53201
	    (414) 548-5163 : EMAIL -  hallettJ@gemed.ge.com
	     "Keep that sense of humor.  It's critical."

devil@techunix.BITNET (Gil Tene) (09/08/90)

In article <HALLETT.90Sep6142725@enterprise.positron.gemed.ge.com> hallettJ@geme
d.ge.com writes:
>
>I'm interested in doing something funky.  I have a shell running that
>basically interprets user commands and then calls a procedure to
>handle the command.  Each command is self-contained.  Now, I want to
>allow a user to add commands.  The mechanism I would like to try is to
>have the user create a .o file with the compiled code in it, then,
>when he enters his command into the shell, have the shell load the .o
>file and execute the code in it.  The only problem is that I don't
>have a clue where to look to figure out how to do this.
>

Look up the "-A" option in the ld(1) man page. This option lets
you take a .o file, and link it to an existing a.out format file
(executable). The result is a code file that you can load into
memory, and jump into. I have some example code (not well commented)
that does this, if you are interested.

Beware : some unix systems DO NOT have this feature. I am sure it
works in BSD and SunOS, but I have checked DG/UX on an Aviion
(as an example), and it has no -A option to ld.

BTW : This ld -A option is called "incremental" loading. "Dynamic"
loading is a term used concerning run-time and shared library loads.
(At least that's the BSD and SunOS terminology).

Hope this helps,

Gil.
--
--------------------------------------------------------------------
| Gil Tene                      "Some days it just doesn't pay     |
| devil@techunix.technion.ac.il   to go to sleep in the morning."  |
--------------------------------------------------------------------

guy@auspex.auspex.com (Guy Harris) (09/10/90)

>Beware : some unix systems DO NOT have this feature. I am sure it
>works in BSD and SunOS, but I have checked DG/UX on an Aviion
>(as an example), and it has no -A option to ld.
>
>BTW : This ld -A option is called "incremental" loading. "Dynamic"
>loading is a term used concerning run-time and shared library loads.
>(At least that's the BSD and SunOS terminology).

Well, SunOS terminology, anyway; current BSD releases don't have that
flavor of dynamic loading.  If the original poster has a system that
*does* have that flavor of dynamic loading (SunOS 4.1 - 4.0 has most of
it, but doesn't have the run-time part; System V Release 4; AIX 3.x;
Apollo Domain/OS; possibly others), he probably wants to use that
instead of dinking around with "ld -A" and one of the large collection
of routines to load "ld -A"ed files....

eric@egsner.cirr.com (Eric Schnoebelen) (09/11/90)

In article <9769@discus.technion.ac.il> 
	devil%techunix.bitnet@lilac.berkeley.edu (Gil Tene) writes:
- In article <HALLETT.90Sep6142725@enterprise.positron.gemed.ge.com> 
-		hallettJ@gemed.ge.com writes:
- >
- >	[Wants to link in objects on the fly]
- 
- Look up the "-A" option in the ld(1) man page.  [...]
- 
- Beware : some unix systems DO NOT have this feature. I am sure it
- works in BSD and SunOS, but I have checked DG/UX on an Aviion
- (as an example), and it has no -A option to ld.

        And some systems use the -A flag for something completely
different.  An example is the ConvexOS loader, which uses -A for a
compiler only type of switch.  ConvexOS is nominally BSD, but the object
format is now a COFF like thing, as opposed the original BSD a.out
format.

        From my other experiences, System V (at least releases 2 and 3+)
don't support ld -A at all.

-- 
Eric Schnoebelen		eric@cirr.com		schnoebe@convex.com
    "This is an important announcement.  This is flight 121 to Los Angeles.
    If your travel plans today do not include Los Angeles, now would be a
    perfect time to disembark." - _So_Long_And_Thanks_For_All_The_Fish_

guy@auspex.auspex.com (Guy Harris) (09/13/90)

>        From my other experiences, System V (at least releases 2 and 3+)
>don't support ld -A at all.

I doubt S5R4 does, either, but then it has "dlopen()"/"dlsym()"/etc.
which gives you a built-in dynamic linking mechanism (which "ld -A" does
NOT - you have to write the "load the file" code yourself, or pick up
one of the already-written versions floating around).

net@tub.UUCP (Oliver Laumann) (09/16/90)

In the recently announced release 1.2 of the Elk Scheme implementation
you find a function that dynamically loads object files by means of
incremental linking (see file src/load.c in the distribution).
It works under 4.3BSD, Ultrix on the DECStation 3100 (ECOFF format),
NEWS-OS (Sony RISC), HP-UX on the HP9000/3xx, SunOS, and probably others
(but not under System V).

Regards,
--
Oliver Laumann     net@TUB.BITNET     net@tub.cs.tu-berlin.de     net@tub.UUCP