Subject: Re: RFC: migration to a fully dynamically linked system
To: Todd Vierling <tv@wasabisystems.com>
From: Wolfgang Solfrank <ws@tools.de>
List: tech-userlevel
Date: 01/05/2002 10:14:51
Hi,

> : Hmm, did you actually try this?  I just did, and it worked like a charm.
> : I.e. both the main program and the dlopen()ed library function used the
> : same __sF[].
> 
> Then it's porbably likely that ld(1) picked the dynamic libc over the static
> one.

No, that's NOT likely.  I'd prefer if people would at least check what
the
system does (let alone imagine what could be changed to make it do what
we
want) before making blanket statements like this.

> Linking the library against -lc as a dependency, and then linking the
> program -nostdlib with crt0, libc.a, and libgcc.a (simulating static linking
> on a dynamic program), should do what I'm talking about.  In particular, the
> resultant binary should contain a data symbol for __sF, meaning that the
> binary has __sF inside it (rather than depending on the shared libc's).

The binary _does_ have __sF inside it, and yes, it's the binary's __sF
that
is used by the main program as well as by the dynamic object.

For your information, I'm including the sources of my test program
below.

Ciao,
Wolfgang
-- 
ws@TooLs.DE     Wolfgang Solfrank, TooLs GmbH 	+49-228-985800
--------------- cut --------------- cut --------------- cut
---------------
# 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
#       dyn.c
#       main.c
#
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
XCFLAGS=        -g -O2
XLDFLAGS= -Wl,-rpath -Wl,.
XLDLIBS=        /usr/lib/libc.a
X
Xall:   libdyn.so main
X
Xlibdyn.so:     dyn.o
X       ${LD} -o libdyn.so -shared -X dyn.o
X
Xdyn.o: dyn.c
X       ${CC} ${CFLAGS} -fpic -c dyn.c
X
Xclean:
X       rm -f *.o libdyn.so main
END-of-Makefile
echo x - dyn.c
sed 's/^X//' >dyn.c << 'END-of-dyn.c'
X#include <stdio.h>
X
Xvoid dyn(void)
X{
X       fprintf(stdout, "this is dyn\n");
X       printf("and now for something completely different!\n");
X}
END-of-dyn.c
echo x - main.c
sed 's/^X//' >main.c << 'END-of-main.c'
X#include <stdio.h>
X#include <dlfcn.h>
X
Xint
Xmain(void)
X{
X       void *dlh;
X       void (*dyn)(void);
X
X       fprintf(stdout, "this is main\n");
X       dlh = dlopen("libdyn.so", DL_LAZY);
X       dyn = dlsym(dlh, "dyn");
X       (*dyn)();
X       return 0;
X}
END-of-main.c
exit