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

  1. Path: sparky!uunet!noc.near.net!bertha!ibm3.hyperdesk.com!adennie
  2. From: adennie@ibm3.hyperdesk.com (Andy Dennie)
  3. Newsgroups: comp.unix.aix
  4. Subject: problem load()-ing shared object
  5. Message-ID: <609@bertha.HyperDesk.com>
  6. Date: 21 Dec 92 22:41:04 GMT
  7. Sender: usenet@bertha.HyperDesk.com
  8. Reply-To: andy_d@hyperdesk.com
  9. Followup-To: comp.unix.aix
  10. Organization: HyperDesk Corporation, Westboro, MA
  11. Lines: 61
  12.  
  13. I've been playing around with shared objects on AIX 3.2, and although I
  14. can successfully load and execute a simple function in a shared object,
  15. I'm stumped on the following problem: how do you load a shared object
  16. that contains references to globals defined in the program doing the
  17. loading?  Below is a simple test case that illustrates the problem.
  18.  
  19. Any help would be greatly appreciated!
  20.  
  21. foo2.c contains:
  22. ----------------------------------------------------------------------
  23. #include <errno.h>
  24. #include <stdio.h>
  25. #include <sys/ldr.h>
  26.  
  27. char global_string[] = "hello, world\n";  /* here's the global */
  28.  
  29. main() {
  30.     int (*pfunc)() = load("bar.so", 0, (char*)NULL);
  31.  
  32.     if (pfunc == 0) {
  33.         printf("load failed, errno=%d\n", errno);
  34.     }
  35. }
  36. ----------------------------------------------------------------------
  37.  
  38.  
  39. bar2.c contains:
  40. ----------------------------------------------------------------------
  41. extern char *global_string;
  42.  
  43. void bar () {
  44.     printf("%s", global_string);
  45. }
  46. ----------------------------------------------------------------------
  47.  
  48. bar2.exp contains:
  49. ------------------
  50. bar
  51. ------------------
  52.  
  53. bar2.imp contains:
  54. ------------------
  55. global_string
  56. ------------------
  57.  
  58. % make foo2 bar2.so
  59.         xlc -o foo2 -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE foo2.c
  60.         xlc -o bar2.so -bM:SRE -bE:bar2.exp -bI:bar2.imp -e _nostart bar2.c
  61. % foo2
  62. load failed, errno=8
  63.  
  64.  
  65. BTW, $LIBPATH contains the current directory, where bar2.so resides.  I
  66. think I'm probably doing something wrong with bar2.imp.  I've tried
  67. adding
  68.  
  69. #!/pathname/of/foo
  70.  
  71. to the beginning of it, but that didn't help.  I also tried creating a
  72. foo2.exp file and linking foo2 with the -bE:foo2.exp switch (same
  73. results).  Any ideas? 
  74.