GNU ld -shared fails to link filtered symbols on Solaris

2006-11-28 Thread Martin Man

Hi all,

[ sorry for crossposting ]

I have investigated a little bit GNU ld problems on Solaris related to 
filter symbols and I seem to have identified one test case which fails 
under all circumstances. I'd like to get some advices on how to best 
proceed next.


The nice background info to the problem is at 
http://www.opensolaris.org/jive/thread.jspa?threadID=18778&tstart=45.


There seems to be a bug in GNU ld that does not link filter symbols 
properly. The expected behavior is to link in filter symbols as 
`undefined' thus leaving them for resolution at runtime. In certain 
cases, ld does not recognize filter symbols and links them into the 
resulting binary as absolute symbols at address 0x0.


This happens as I could observe when:

1. library that contains filtered symbols is mentioned at the ld 
commandline, i.e. -lpthread, -ldl, -lc

2. -Wl,-shared option is specified

I also know that the problem does not occur when -Wl,-shared is removed 
entirely, or replaced with -Wl,-E or -Wl,-Bdynamic, although I don't 
know how these differ.


There might be other circumstances where this bug exhibits itself, but 
this one is 100% reproducible, I have attached the simple test case + 
its output + version of the software used. The problematic system in 
question is Nexenta GNU Solaris alpha 6.



let me know what other information I can provide,
thanx,
Martin

--
http://martinman.net


binutils-bug.tar.gz
Description: GNU Zip compressed data
echo "Rebuilding bggy1..."
Rebuilding bggy1...
gcc -o bggy1 -shared -lpthread -ldl buggy.c
ldd bggy1
libpthread.so.1 =>   /lib/libpthread.so.1
libdl.so.1 =>/lib/libdl.so.1
libgcc_s.so.1 => /lib/libgcc_s.so.1
libc.so.1 => /lib/libc.so.1
libm.so.2 => /lib/libm.so.2
echo "The nm output of bggy1 should ideally not contain any Absolute symbols at 
address 0x"
The nm output of bggy1 should ideally not contain any Absolute symbols at 
address 0x
nm -D bggy1 | grep '\(pthr\|dlop\)'
 A dlopen
 A pthread_mutex_destroy
 A pthread_mutex_init
echo ""

echo "Rebuilding bggy2..."
Rebuilding bggy2...
gcc -o bggy2 -Wl,-shared -lpthread -ldl buggy.c
ldd bggy2
libpthread.so.1 =>   /lib/libpthread.so.1
libdl.so.1 =>/lib/libdl.so.1
libc.so.1 => /lib/libc.so.1
libm.so.2 => /lib/libm.so.2
echo "The nm output of bggy2 should ideally not contain any Absolute symbols at 
address 0x"
The nm output of bggy2 should ideally not contain any Absolute symbols at 
address 0x
nm -D bggy2 | grep '\(pthr\|dlop\)'
 A dlopen
 A pthread_mutex_destroy
 A pthread_mutex_init
echo ""

echo "Rebuilding bggy3..."
Rebuilding bggy3...
gcc -o bggy3 -Wl,-E -lpthread -ldl buggy.c
ldd bggy3
libpthread.so.1 =>   /lib/libpthread.so.1
libdl.so.1 =>/lib/libdl.so.1
libc.so.1 => /lib/libc.so.1
libm.so.2 => /lib/libm.so.2
echo "The nm output of bggy3 should ideally not contain any Absolute symbols at 
address 0x"
The nm output of bggy3 should ideally not contain any Absolute symbols at 
address 0x
nm -D bggy3 | grep '\(pthr\|dlop\)'
 U dlopen
 U pthread_mutex_destroy
 U pthread_mutex_init
echo ""

echo "Rebuilding bggy4..."
Rebuilding bggy4...
gcc -o bggy4  -lpthread -ldl buggy.c
ldd bggy4
libpthread.so.1 =>   /lib/libpthread.so.1
libdl.so.1 =>/lib/libdl.so.1
libc.so.1 => /lib/libc.so.1
libm.so.2 => /lib/libm.so.2
echo "The nm output of bggy4 should ideally not contain any Absolute symbols at 
address 0x"
The nm output of bggy4 should ideally not contain any Absolute symbols at 
address 0x
nm -D bggy4 | grep '\(pthr\|dlop\)'
 U dlopen
 U pthread_mutex_destroy
 U pthread_mutex_init
echo ""

echo "Rebuilding bggy5..."
Rebuilding bggy5...
gcc -o bggy5 -Wl,-Bdynamic -lpthread -ldl buggy.c
ldd bggy5
libpthread.so.1 =>   /lib/libpthread.so.1
libdl.so.1 =>/lib/libdl.so.1
libc.so.1 => /lib/libc.so.1
libm.so.2 => /lib/libm.so.2
echo "The nm output of bggy5 should ideally not contain any Absolute symbols at 
address 0x"
The nm output of bggy5 should ideally not contain any Absolute symbols at 
address 0x
nm -D bggy5 | grep '\(pthr\|dlop\)'
 U dlopen
 U pthread_mutex_destroy
 U pthread_mutex_init
echo ""

gcc (GCC) 4.0.3 (GNU_Solaris 4.0.3-1nexenta6)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

GNU ld version 2.16.91 20060118 NexentaOS GNU/OpenSolaris
Copyright 2005 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no wa

Re: [osol-discuss] Re: GNU ld -shared fails to link filtered symbols on Solaris

2006-11-28 Thread Martin Man

Rod Evans wrote:

Alan Modra wrote:


You seem to want some other sort of treatment of ABS symbols, as
needing .plt or .got entries, I presume.  I think that might be OK
too, but may require some redesign of GNU ld.  The trouble is that
GNU ld has just one ABS section internally.  That means that ABS
symbols are lumped together and lose their association with a
particular object file.  I'm reasonably certain that this will cause
you some trouble.


Well, I'm not very familiar with the gnu linker, but Martins experiments
seem to suggest that the treatment of an ABS definition is inconsistent -
sometimes they result in UNDEF references, other times ABS.


This is the point, under certain circumstances (-Wl,-shared) the 
absolute symbols are linked in as, well, absolute symbols, whereas 
without -Wl,-shared they are treated *properly* as undefs, despite the 
fact that they are indeed defined in the -lpthread or -ldl as absolute 
symbols.


Looks like inconsistency to me.


Martin might have to add some c stub functions to his builds so that
his libraries provide non-ABS filter symbols in the mean time.


This wouldn't help at all, since GNU linker would produce code which 
calls these stubs in the end, instead of redirecting to the filtee (I 
believe).


HTH,
Martin

P.S. so what should we do next?

--
http://martinman.net


___
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils