This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR ld/5789: Linker doesn't check weak and hidden symbols


On Thu, Feb 28, 2008 at 07:02:57AM -0800, H.J. Lu wrote:
> On Thu, Feb 28, 2008 at 12:35 AM, Alan Modra <amodra@bigpond.net.au> wrote:
> > On Sat, Feb 23, 2008 at 04:11:11PM -0800, H.J. Lu wrote:
> >  >       PR ld/5789
> >  >       * elflink.c (_bfd_elf_symbol_refs_local_p): Always return true
> >  >       for hidden and local symbols.
> >
> >  HJ, I think this part of your change is correct, but it breaks the ld
> >  visibility tests.  Which means the tests are wrong and need fixing
> >  too.
> 
> I tried it on Linux/ia32, Linux/Intel64 and Linux/ia64. There are no
> testsuite failures in binutils.

I see these on powerpc-linux with gcc-3.4.5
FAIL: visibility (hidden_undef) (non PIC)
FAIL: visibility (hidden_undef) (non PIC, load offset)
FAIL: visibility (hidden_undef) (PIC main, non PIC so)

>From ld.log:
gcc  -B/home/alan/build/ppc/bin/ld/tmpdir/gas/ -I/src/binutils-current/ld/testsuite/ld-elfvsb -g -O -fno-inline -msecure-plt   -L/home/alan/build/ppc/bin/./ld -g -g -O -fno-inline -msecure-plt  -DHIDDEN_UNDEF_TEST -c /src/binutils-current/ld/testsuite/ld-elfvsb/sh1.c -o tmpdir/sh1np.o
gcc  -B/home/alan/build/ppc/bin/ld/tmpdir/gas/ -I/src/binutils-current/ld/testsuite/ld-elfvsb -g -O -fno-inline -msecure-plt   -L/home/alan/build/ppc/bin/./ld -g -g -O -fno-inline -msecure-plt  -DHIDDEN_UNDEF_TEST -c /src/binutils-current/ld/testsuite/ld-elfvsb/sh2.c -o tmpdir/sh2np.o
gcc -L/home/alan/build/ppc/bin/./ld -B/home/alan/build/ppc/bin/ld/tmpdir/ld/ -L/usr/local/powerpc-linux/lib -L/usr/local/lib -L/lib -L/usr/lib  -o tmpdir/vnp.so -shared  tmpdir/sh1np.o tmpdir/sh2np.o
tmpdir/sh1np.o: In function `visibility_checkfunptr':
/src/binutils-current/ld/testsuite/ld-elfvsb/sh1.c:226: undefined reference to `visibility'
tmpdir/sh1np.o: In function `visibility_check':
/src/binutils-current/ld/testsuite/ld-elfvsb/sh1.c:242: undefined reference to `visibility'
tmpdir/sh1np.o: In function `visibility_funptr':
/src/binutils-current/ld/testsuite/ld-elfvsb/sh1.c:256: undefined reference to `visibility'
/home/alan/build/ppc/bin/ld/tmpdir/ld/ld: final link failed: Bad value
collect2: ld returned 1 exit status

In sh1.c
#if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
#ifdef WEAK_TEST
#pragma weak visibility
#endif
extern int visibility ();
#else
int
visibility ()
{
  return 2;
}
#endif
...
#if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
asm (".hidden visibility");
asm (".hidden visibility_var");
#else
#if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
asm (".protected visibility");
asm (".protected visibility_var");
#endif
#endif

There is no definition of "visibility" in sh2.c, so "visibility" is
indeed undefined and hidden.  It is also not weak.  Checking the
object files confirm this.  I reckon that such a reference ought to
cause a link error, as it does on powerpc.  A pass on the targets you
tested (I saw the same result on x86-linux) means we have other bugs
to fix on those targets.

If I use gcc-4.3.0, then I only see the sh1.c:256 error.  On
investigating why that is so, I found that ld was reaching
elf32-ppc.c:6539 (which is a bug) and returning immediately from
relocate_section, so you don't see the other link errors.  gcc-4.3.0
emits the relocs in a different order.  This is also why you don't see
link errors with "visibility_var" on powerpc.

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]