Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Apr 1995 01:58:46 -0700
From:      "Jordan K. Hubbard" <jkh@morton.cdrom.com>
To:        current@freefall.cdrom.com
Subject:   Argh!  Another side-effect of Nate's changes?
Message-ID:  <199504070858.BAA03743@morton.cdrom.com>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199504070858.BAA03743>