home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / aix / 12831 < prev    next >
Encoding:
Text File  |  1992-12-23  |  3.4 KB  |  105 lines

  1. Newsgroups: comp.unix.aix
  2. Path: sparky!uunet!spool.mu.edu!agate!linus!philabs!acheron!scifi!watson!yktnews!admin!flu!marc
  3. From: marc@watson.ibm.com (Marc Auslander)
  4. Subject: Re: problem load()-ing shared object
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <MARC.92Dec23155323@marc.watson.ibm.com>
  7. In-Reply-To: adennie@ibm3.hyperdesk.com's message of 21 Dec 92 22:41:04 GMT
  8. Date: Wed, 23 Dec 1992 20:53:23 GMT
  9. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  10. References: <609@bertha.HyperDesk.com>
  11. Nntp-Posting-Host: marc.watson.ibm.com
  12. Organization: IBM T.J. Watson Research Center, Hawthorne, New York
  13. Followup-To: comp.unix.aix
  14. Lines: 89
  15.  
  16. You can't easily is the simple answer.
  17.  
  18. There are two choice.  You can build an exports list that asserts that
  19. the symbols from the main program come from it, by putting the main
  20. programs path name in the front of the list.  You use this to build
  21. the shared library, then the shared library to build the main.  But
  22. now the library works with only one program.
  23.  
  24. Alternately, you can build an exports list that asserts that the main
  25. programs symbols will be resolved at run time.  You do this by
  26. starting the exports list with:
  27.  
  28. #!
  29.  
  30. Then, you use the exports list to build the shared library.  But now,
  31. your main program must issue the loadbind command using the main
  32. program as the exporter and the library as the importer to get the
  33. symbols bound.
  34.  
  35. The documentation contains details on both of these approaches.
  36.  
  37. In article <609@bertha.HyperDesk.com> adennie@ibm3.hyperdesk.com (Andy Dennie) writes:
  38.  
  39. >I've been playing around with shared objects on AIX 3.2, and although I
  40. >can successfully load and execute a simple function in a shared object,
  41. >I'm stumped on the following problem: how do you load a shared object
  42. >that contains references to globals defined in the program doing the
  43. >loading?  Below is a simple test case that illustrates the problem.
  44.  
  45. >Any help would be greatly appreciated!
  46.  
  47. >foo2.c contains:
  48. >----------------------------------------------------------------------
  49. >#include <errno.h>
  50. >#include <stdio.h>
  51. >#include <sys/ldr.h>
  52.  
  53. >char global_string[] = "hello, world\n";  /* here's the global */
  54.  
  55. >main() {
  56. >    int (*pfunc)() = load("bar.so", 0, (char*)NULL);
  57.  
  58. >    if (pfunc == 0) {
  59. >        printf("load failed, errno=%d\n", errno);
  60. >    }
  61. >}
  62. >----------------------------------------------------------------------
  63.  
  64.  
  65. >bar2.c contains:
  66. >----------------------------------------------------------------------
  67. >extern char *global_string;
  68.  
  69. >void bar () {
  70. >    printf("%s", global_string);
  71. >}
  72. >----------------------------------------------------------------------
  73.  
  74. >bar2.exp contains:
  75. >------------------
  76. >bar
  77. >------------------
  78.  
  79. >bar2.imp contains:
  80. >------------------
  81. >global_string
  82. >------------------
  83.  
  84. >% make foo2 bar2.so
  85. >        xlc -o foo2 -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE foo2.c
  86. >        xlc -o bar2.so -bM:SRE -bE:bar2.exp -bI:bar2.imp -e _nostart bar2.c
  87. >% foo2
  88. >load failed, errno=8
  89.  
  90.  
  91. >BTW, $LIBPATH contains the current directory, where bar2.so resides.  I
  92. >think I'm probably doing something wrong with bar2.imp.  I've tried
  93. >adding
  94.  
  95. >#!/pathname/of/foo
  96.  
  97. >to the beginning of it, but that didn't help.  I also tried creating a
  98. >foo2.exp file and linking foo2 with the -bE:foo2.exp switch (same
  99. >results).  Any ideas? 
  100. --
  101.  
  102.  
  103. Marc Auslander       (IBM)<marc@marc.watson.ibm.com>      914 784-6699
  104.                      (Internet)<marc@watson.ibm.com>
  105.