This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Versioning mess proved!!!
- To: Geoff Keating <geoffk at cygnus dot com>,drepper at cygnus dot com
- Subject: Re: Versioning mess proved!!!
- From: Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>
- Date: Tue, 3 Oct 2000 17:28:36 +0200
- Cc: philb at gnu dot org,howarth at fuse dot net,libc-alpha at sourceware dot cygnus dot com,aj at suse dot de
- References: <39D50E20.263F646F@fuse.net> <m3wvfrkee6.fsf@otr.mynet.cygnus.com> <200010021911.MAA23539@geoffk.org>
On Mon, 02 Oct 2000, Geoff Keating wrote:
> > Cc: Franz.Sirl-kernel@lauterbach.com, philb@gnu.org, howarth@fuse.net,
> > libc-alpha@sourceware.cygnus.com, aj@suse.de
> > Reply-To: drepper@cygnus.com (Ulrich Drepper)
> > From: Ulrich Drepper <drepper@redhat.com>
> > Date: 01 Oct 2000 22:20:33 -0700
> > User-Agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Capitol Reef)
> >
> > Geoff Keating <geoffk@cygnus.com> writes:
> > > To fix this, the do_lookup routines in libc/elf/do-lookup.h need to be
> > > changed so that if this condition has not triggered:
> > >
> > > if (sym->st_value == 0 || /* No value. */
> > > (noplt && sym->st_shndx == SHN_UNDEF))
> > > continue;
> >
> > I don't like this a bit. This is a hack to work around a problem. It
> > seems to me that the PPC linker is broken. It works on other
> > architectures and such a test is just adding unnecessary work.
>
> Actually, weak symbols don't work at all in executables on x86, which
> is probably why x86 doesn't see this problem.
>
> Try this in bash:
>
> cat > tA.c <<END
> extern void foo(void) __attribute__((weak));
>
> int main(void)
> {
> printf ("%p\n", &foo);
> if (&foo)
> foo();
> return 0;
> }
> END
> cat > tB.c <<END
> void foo(void)
> {
> printf ("foo\n");
> }
> END
> gcc tA.c -o tA
> gcc -fpic -shared tB.c -o tB.so
> LD_PRELOAD=./tB.so ./tA
>
> you will see that (at least on my Red Hat 7 box thief) it prints
> (nil)
> despite foo() being defined. It doesn't matter if the executable is
> compiled with -fpic or not.
So, this inspired me to create a reproducable and independent testcase. With
the attached files try:
$ mkdir 213 22
$ gcc -fpic -shared tB-2.1.3.c tI.c -o 213/libtB.so
$ gcc -fpic -shared tB-2.2.c -o 22/libtB.so
$ gcc tA-22.c -L213 -ltB -o tA
$ LD_LIBRARY_PATH=./213/ LD_BIND_NOW=1 ./tA
0x10010818
$ LD_LIBRARY_PATH=./22/ LD_BIND_NOW=1 ./tA
0x10010818
Segmentation fault (core dumped)
The testcase works on both glibc-2.1.9x and gcc-2.1.3 systems and illustrates
the same fault I see with zlib, namely that during the execution the first
word of foo() gets relocated to an absolute branch to 0. This leads to a nice
segfault then.
Franz.
int main(void)
{
extern void foo (void) __attribute__ ((weak));
void (*foop) (void) = foo;
printf ("%p\n", foop);
if (foop)
foop();
return 0;
}
void init213 (void)
{
extern void foo (void);
foo();
}
void init22 (void)
{
extern void foo (void) __attribute__ ((weak));
void (*foop) (void) = foo;
if (foop)
foop();
}
void __attribute__ ((weak)) foo(void)
{
}