home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.aix
- Path: sparky!uunet!spool.mu.edu!agate!linus!philabs!acheron!scifi!watson!yktnews!admin!flu!marc
- From: marc@watson.ibm.com (Marc Auslander)
- Subject: Re: problem load()-ing shared object
- Sender: news@watson.ibm.com (NNTP News Poster)
- Message-ID: <MARC.92Dec23155323@marc.watson.ibm.com>
- In-Reply-To: adennie@ibm3.hyperdesk.com's message of 21 Dec 92 22:41:04 GMT
- Date: Wed, 23 Dec 1992 20:53:23 GMT
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <609@bertha.HyperDesk.com>
- Nntp-Posting-Host: marc.watson.ibm.com
- Organization: IBM T.J. Watson Research Center, Hawthorne, New York
- Followup-To: comp.unix.aix
- Lines: 89
-
- You can't easily is the simple answer.
-
- There are two choice. You can build an exports list that asserts that
- the symbols from the main program come from it, by putting the main
- programs path name in the front of the list. You use this to build
- the shared library, then the shared library to build the main. But
- now the library works with only one program.
-
- Alternately, you can build an exports list that asserts that the main
- programs symbols will be resolved at run time. You do this by
- starting the exports list with:
-
- #!
-
- Then, you use the exports list to build the shared library. But now,
- your main program must issue the loadbind command using the main
- program as the exporter and the library as the importer to get the
- symbols bound.
-
- The documentation contains details on both of these approaches.
-
- In article <609@bertha.HyperDesk.com> adennie@ibm3.hyperdesk.com (Andy Dennie) writes:
-
- >I've been playing around with shared objects on AIX 3.2, and although I
- >can successfully load and execute a simple function in a shared object,
- >I'm stumped on the following problem: how do you load a shared object
- >that contains references to globals defined in the program doing the
- >loading? Below is a simple test case that illustrates the problem.
-
- >Any help would be greatly appreciated!
-
- >foo2.c contains:
- >----------------------------------------------------------------------
- >#include <errno.h>
- >#include <stdio.h>
- >#include <sys/ldr.h>
-
- >char global_string[] = "hello, world\n"; /* here's the global */
-
- >main() {
- > int (*pfunc)() = load("bar.so", 0, (char*)NULL);
-
- > if (pfunc == 0) {
- > printf("load failed, errno=%d\n", errno);
- > }
- >}
- >----------------------------------------------------------------------
-
-
- >bar2.c contains:
- >----------------------------------------------------------------------
- >extern char *global_string;
-
- >void bar () {
- > printf("%s", global_string);
- >}
- >----------------------------------------------------------------------
-
- >bar2.exp contains:
- >------------------
- >bar
- >------------------
-
- >bar2.imp contains:
- >------------------
- >global_string
- >------------------
-
- >% make foo2 bar2.so
- > xlc -o foo2 -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE foo2.c
- > xlc -o bar2.so -bM:SRE -bE:bar2.exp -bI:bar2.imp -e _nostart bar2.c
- >% foo2
- >load failed, errno=8
-
-
- >BTW, $LIBPATH contains the current directory, where bar2.so resides. I
- >think I'm probably doing something wrong with bar2.imp. I've tried
- >adding
-
- >#!/pathname/of/foo
-
- >to the beginning of it, but that didn't help. I also tried creating a
- >foo2.exp file and linking foo2 with the -bE:foo2.exp switch (same
- >results). Any ideas?
- --
-
-
- Marc Auslander (IBM)<marc@marc.watson.ibm.com> 914 784-6699
- (Internet)<marc@watson.ibm.com>
-