From owner-freebsd-current Fri Apr 7 01:59:15 1995 Return-Path: current-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id BAA28808 for current-outgoing; Fri, 7 Apr 1995 01:59:15 -0700 Received: from morton.cdrom.com (morton.cdrom.com [192.216.222.17]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id BAA28798 for ; Fri, 7 Apr 1995 01:59:09 -0700 Received: (from jkh@localhost) by morton.cdrom.com (8.6.11/8.6.9) id BAA03743 for current@freefall; Fri, 7 Apr 1995 01:58:46 -0700 Date: Fri, 7 Apr 1995 01:58:46 -0700 From: "Jordan K. Hubbard" Message-Id: <199504070858.BAA03743@morton.cdrom.com> To: current@freefall.cdrom.com Subject: Argh! Another side-effect of Nate's changes? Sender: current-owner@FreeBSD.org Precedence: bulk Unpack the following somewhere and run driver, then driver.broken. The only difference between the two is that they're linked dynamic and static. I really *need* this example to work static! Can someone suggest anything? Is this outside the realm of possibility simply due to the way shared library symbol resolution works? You'd think that dlopen() would (should) work irrespective of the calling program's own link preference! Jordan # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # Makefile # driver.c # lib.c # echo x - Makefile sed 's/^X//' >Makefile << 'END-of-Makefile' Xall: lib.so driver.c X cc driver.c -g -O -o driver X cc -static driver.c -g -O -o driver.broken X Xlib.so: X cc -O -c -fpic lib.c X ld -Bshareable -o lib.so lib.o X Xclean: X rm -f *.o *.so driver driver.broken END-of-Makefile echo x - driver.c sed 's/^X//' >driver.c << 'END-of-driver.c' Xvoid Xfunky_chicken(char *arg) X{ X printf("C'mon and %s!\n", arg); X} X Xvoid Xsuicide(char *arg) X{ X printf("The end is nigh, so we %s.\n", arg); X} X Xmain(int ac, char **av) X{ X void *handle; X int (*ptr)(int, char **); X char *name; X X if (ac > 1) X name = av[1]; X else X name = "lib.so"; X printf("main: Loading %s:\n", name); X handle = (void *)dlopen(name); X if (!handle) { X printf("main: Load of %s failed!\n", name); X return -1; X } X else X printf("main: Load of %s successfull!\n", name); X ptr = (int (*)(int, char **))dlsym(handle, "_run"); X if (ptr) { X printf("main: Run entrypoint found for %s - invoking.\n", name); X (*ptr)(--ac, ++av); X } X printf("main: Shutting down handle for %s\n", name); X dlclose(handle); X printf("main: Terminating the program\n"); X return 0; X} END-of-driver.c echo x - lib.c sed 's/^X//' >lib.c << 'END-of-lib.c' X/* This modules init function */ Xvoid Xinit(void) X{ X printf("lib: I am alive!\n"); X funky_chicken("shout"); X funky_chicken("sing"); X funky_chicken("dance like a lunatic"); X} X Xint Xrun(int argc, char **argv) X{ X printf("lib: in run code, argc = %d\n", argc); X} X Xvoid Xfini(void) X{ X printf("lib: Aiua! I am dead!\n"); X suicide("dance the tango"); X suicide("curl up our legs like dying insects"); X} X END-of-lib.c exit