Bug 1443 - /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
Summary: /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.17
: P2 critical
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-09 00:39 UTC by John David Anglin
Modified: 2005-10-11 02:57 UTC (History)
2 users (show)

See Also:
Host: hppa-unknown-gnu-linux
Target: hppa-unknown-gnu-linux
Build: hppa-unknown-gnu-linux
Last reconfirmed:


Attachments
ld-1443.tar.gz (677.59 KB, application/x-tar-gz)
2005-10-10 21:03 UTC, dave@hiauly1.hia.nrc.ca
Details
ld-1443m.tar.gz (1.42 KB, application/x-tar-gz)
2005-10-10 21:09 UTC, dave@hiauly1.hia.nrc.ca
Details
libc_nonshared.a (1.38 KB, application/octet-stream)
2005-10-10 21:33 UTC, dave@hiauly1.hia.nrc.ca
Details
crti.o (648 bytes, application/octet-stream)
2005-10-10 21:53 UTC, dave@hiauly1.hia.nrc.ca
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2005-10-09 00:39:40 UTC
This shows up in the ld testsuite:

/home/dave/binutils-2.16.91/objdir/ld/ld-new -m hppalinux  -o tmpdir/ld1 -dynami
c-linker /lib/ld.so.1 /usr/lib/crt1.o /usr/lib/crti.o /home/dave/opt/gnu/gcc/gcc
-4.0.2/lib/gcc/hppa-linux/4.0.2/crtbegin.o  tmpdir/ld-partial.o ../bfd/.libs/lib
bfd.a ../libiberty/libiberty.a   -L/usr/lib --start-group /home/dave/opt/gnu/gcc
/gcc-4.0.2/lib/gcc/hppa-linux/4.0.2/libgcc.a /home/dave/opt/gnu/gcc/gcc-4.0.2/li
b/gcc/hppa-linux/4.0.2/libgcc_eh.a -lc --end-group /home/dave/opt/gnu/gcc/gcc-4.
0.2/lib/gcc/hppa-linux/4.0.2/crtend.o /usr/lib/crtn.o
/lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/lib/libc.so.6: undefined reference to `__libc_stack_end@GLIBC_2.2'
FAIL: bootstrap

It has something to do with debian libc6 2.3.5-6.0.1.  I'm not seeing this
problem with 2.3.2.ds1-22.  It's not entirely reproducible (e.g., changing
GCC version sometimes causes the problem to go away).
Comment 1 John David Anglin 2005-10-09 02:15:24 UTC
For some reason, the symbols in /lib/ld.so.1 aren't being resolved.
Adding /lib/ld.so.1 to the link command resolves the symbols.  I see

Dynamic section at offset 0x140730 contains 24 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [ld.so.1]

in libc.so.6, so I'm not sure why the symbols aren't automatically
resolved.
Comment 2 H.J. Lu 2005-10-09 15:15:06 UTC
If you can provide all input files, I will try to take a look.
Comment 3 dave@hiauly1.hia.nrc.ca 2005-10-09 15:18:42 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> ------- Additional Comments From hjl at lucon dot org  2005-10-09 15:15 -------
> If you can provide all input files, I will try to take a look.

I'll try to do this tomorrow.  It's Thanksgiving holiday here today.

Dave
Comment 4 dave@hiauly1.hia.nrc.ca 2005-10-10 18:22:35 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> > ------- Additional Comments From hjl at lucon dot org  2005-10-09 15:15 -------
> > If you can provide all input files, I will try to take a look.
> 
> I'll try to do this tomorrow.  It's Thanksgiving holiday here today.

Thinking a bit more about this, I decided providing the files would be
a bit tricky as I need to provide the glibc shared libraries.  So, I
looked a bit more into what's going on.

When elf_add_dt_needed_tag is called for ld.so.1, DO_IT is false.

Looking at this bit of code:

      /* If this dynamic lib was specified on the command line with
	 --as-needed in effect, then we don't want to add a DT_NEEDED
	 tag unless the lib is actually used.  Similary for libs brought
	 in by another lib's DT_NEEDED.  When --no-add-needed is used
	 on a dynamic lib, we don't want to add a DT_NEEDED entry for
	 any dynamic library in DT_NEEDED tags in the dynamic lib at
	 all.  */
	 add_needed = (elf_dyn_lib_class (abfd)
		       & (DYN_AS_NEEDED | DYN_DT_NEEDED
			  | DYN_NO_NEEDED)) == 0;

I see:

(gdb) p *abfd
$17 = {id = 28, filename = 0xf5308 "/home/dave/opt/gnu/lib/ld.so.1",
  xvec = 0xb7c24, iostream = 0x0, iovec = 0xaa6ac, cacheable = 1,
  ...
(gdb) p abfd->tdata.elf_obj_data->dyn_lib_class
$18 = DYN_DT_NEEDED

So, add_needed is set to false.

Dave
Comment 5 John David Anglin 2005-10-10 19:01:03 UTC
I should add that these dynamic symbols are references to global objects:

   200: 00000000     4 OBJECT  GLOBAL DEFAULT  UND __libc_stack_end@GLIBC_2.2 (1
4)
   848: 00000000   168 OBJECT  GLOBAL DEFAULT  UND _rtld_global_ro@GLIBC_PRIVATE 
(15)
Comment 6 H.J. Lu 2005-10-10 19:21:13 UTC
This shouldn't be a problem since executable doesn't use any symbols in ld.so.
If you can provide a testcase, I will try to look into it.
Comment 7 H.J. Lu 2005-10-10 19:46:05 UTC
Can you show me your "readelf -d /lib/libc.so.6":

[hjl@gnu-13 glibc-nptl-4.0]$ readelf -d /lib/libc.so.6

Dynamic section at offset 0x126cfc contains 26 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [ld-linux.so.2]
 0x0000000e (SONAME)                     Library soname: [libc.so.6]
Comment 8 dave@hiauly1.hia.nrc.ca 2005-10-10 19:59:50 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> Can you show me your "readelf -d /lib/libc.so.6":

dave@gsyprf11:~/binutils-2.16.91/src/bfd$ readelf -d /lib/libc.so.6|less

Dynamic section at offset 0x140730 contains 24 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [ld.so.1]
 0x0000000e (SONAME)                     Library soname: [libc.so.6]
 0x0000000c (INIT)                       0x20474
 0x0000001a (FINI_ARRAY)                 0x14ea54
 0x0000001c (FINI_ARRAYSZ)               4 (bytes)
 0x00000004 (HASH)                       0x134
 0x00000005 (STRTAB)                     0xaf58
 0x00000006 (SYMTAB)                     0x30d8
 0x0000000a (STRSZ)                      20374 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000003 (PLTGOT)                     0x1544d4
 0x00000002 (PLTRELSZ)                   5256 (bytes)
 0x00000014 (PLTREL)                     RELA
 0x00000017 (JMPREL)                     0x1ead4
 0x00000007 (RELA)                       0x110ac
 0x00000008 (RELASZ)                     55848 (bytes)
 0x00000009 (RELAENT)                    12 (bytes)
 0x6ffffffc (VERDEF)                     0x10ec0
 0x6ffffffd (VERDEFNUM)                  13
 0x6ffffffe (VERNEED)                    0x1107c

Dave
Comment 9 H.J. Lu 2005-10-10 20:22:32 UTC
It looks OK. A testcase is needed.
Comment 10 dave@hiauly1.hia.nrc.ca 2005-10-10 20:28:36 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> It looks OK. A testcase is needed.

The following C file triggers the problem:

int main () { return 0; }

The link command is:

./ld-new --eh-frame-hdr -dynamic-linker /lib/ld.so.1 -o main /usr/lib/gcc/hppa-linux-gnu/4.0.1/../../../crt1.o /usr/lib/gcc/hppa-linux-gnu/4.0.1/../../../crti.o /usr/lib/gcc/hppa-linux-gnu/4.0.1/crtbegin.o -L/usr/lib/gcc/hppa-linux-gnu/4.0.1 -L/usr/lib/gcc/hppa-linux-gnu/4.0.1 -L/usr/lib/gcc/hppa-linux-gnu/4.0.1/../../.. main.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/hppa-linux-gnu/4.0.1/crtend.o /usr/lib/gcc/hppa-linux-gnu/4.0.1/../../../crtn.o

Dave
Comment 11 H.J. Lu 2005-10-10 20:30:49 UTC
Please provide all input files for me to reproduce it with a cross linker.
Comment 12 dave@hiauly1.hia.nrc.ca 2005-10-10 20:43:19 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> This shouldn't be a problem since executable doesn't use any symbols in ld.so.
> If you can provide a testcase, I will try to look into it.

I see the following comment in elf-hppa.h:

  /* HP's shared libraries have references to symbols that are not
     defined anywhere.  The generic ELF BFD linker code will complain
     about such symbols.

     So we detect the losing case and arrange for the flags on the symbol
     to indicate that it was never referenced.  This keeps the generic
     ELF BFD link code happy and appears to not create any secondary
     problems.  Ultimately we need a way to control the behavior of the
     generic ELF BFD link code better.  */
     elf_link_hash_traverse (elf_hash_table (info),
			     elf_hppa_unmark_useless_dynamic_symbols,
			     info);

However, the code is only used for elf64.  At the moment, I don't see
any code that unsets DYN_DT_NEEDED.  Possibly, the bug is that the
info field unresolved_syms_in_shared_libs should be set to RM_IGNORE.

Dave
Comment 13 dave@hiauly1.hia.nrc.ca 2005-10-10 21:03:48 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> Please provide all input files for me to reproduce it with a cross linker.

Attached.

Dave
Comment 14 dave@hiauly1.hia.nrc.ca 2005-10-10 21:03:48 UTC
Created attachment 693 [details]
ld-1443.tar.gz
Comment 15 dave@hiauly1.hia.nrc.ca 2005-10-10 21:09:13 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

On Mon, Oct 10, 2005 at 05:03:22PM -0400, John David Anglin wrote:
> > Please provide all input files for me to reproduce it with a cross linker.
> 
> Attached.

Oops, missed two files.

Dave
Comment 16 dave@hiauly1.hia.nrc.ca 2005-10-10 21:09:13 UTC
Created attachment 694 [details]
ld-1443m.tar.gz
Comment 17 H.J. Lu 2005-10-10 21:17:12 UTC
I also need /usr/lib/libc.so and the related files. Please do

# cat /usr/lib/libc.so

to see what they are.
Comment 18 dave@hiauly1.hia.nrc.ca 2005-10-10 21:33:59 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

On Mon, Oct 10, 2005 at 09:17:12PM -0000, hjl at lucon dot org wrote:
> 
> ------- Additional Comments From hjl at lucon dot org  2005-10-10 21:17 -------
> I also need /usr/lib/libc.so and the related files. Please do
> 
> # cat /usr/lib/libc.so

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-hppa-linux)
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )

Dave
Comment 19 dave@hiauly1.hia.nrc.ca 2005-10-10 21:33:59 UTC
Created attachment 695 [details]
libc_nonshared.a
Comment 20 H.J. Lu 2005-10-10 21:41:07 UTC
I also need /usr/lib/crti.o.
Comment 21 dave@hiauly1.hia.nrc.ca 2005-10-10 21:53:53 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

On Mon, Oct 10, 2005 at 09:41:08PM -0000, hjl at lucon dot org wrote:
> 
> ------- Additional Comments From hjl at lucon dot org  2005-10-10 21:41 -------
> I also need /usr/lib/crti.o.

Attached.

I have the feeling that the wrong bfd is being used for the DYN_DT_NEEDED
check in elf_link_check_versioned_symbol:

     abfd = h->root.u.undef.abfd;
     if ((abfd->flags & DYNAMIC) == 0
	 || (elf_dyn_lib_class (abfd) & DYN_DT_NEEDED) == 0)
       return FALSE;

libc.so.6 is DYN_NORMAL and ld.so.1 is DYN_DT_NEEDED.  We are checking
libc.so.6.

Dave
Comment 22 dave@hiauly1.hia.nrc.ca 2005-10-10 21:53:53 UTC
Created attachment 696 [details]
crti.o
Comment 23 H.J. Lu 2005-10-10 22:45:35 UTC
I can't duplicate your problem:

[hjl@gnu-13 hppa-3]$ make
./ld -o main --eh-frame-hdr -dynamic-linker /lib/ld.so.1 \
        crt1.o crti.o crtbegin.o main.o -lgcc --as-needed \
        -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s \
        --no-as-needed crtend.o crtn.o -L. -rpath-link .
[hjl@gnu-13 hppa-3]$ ./ld -V
GNU ld version 2.16.91 20051007
  Supported emulations:
   hppalinux
Comment 24 dave@hiauly1.hia.nrc.ca 2005-10-11 00:31:52 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> I can't duplicate your problem:

I was afraid of that.  As I indicated originally, the problem seemed
start file sensitive.

I have the following backtrace on the system that I consistently see
the problem:

(gdb) bt
#0  undefined_symbol (info=0xd727c,
    name=0x19a7e8 "_rtld_global_ro@GLIBC_PRIVATE", abfd=0x118448, section=0x0,
    address=0, error=-1074603408) at ../../src/ld/ldmain.c:1321
#1  0x000669cc in elf_link_output_extsym (h=0x1a05a8, data=0x19a7e8)
    at ../../src/bfd/elflink.c:6349
#2  0x0003d6f4 in bfd_hash_traverse (table=0xe5fc8,
    func=@0xd238a: 0x668d8 <elf_link_output_extsym>, info=0xbff2da70)
    at ../../src/bfd/hash.c:484
#3  0x0003dd20 in bfd_link_hash_traverse (table=0xd727c, func=0x19a7e8,
    info=0x118448) at ../../src/bfd/linker.c:610
#4  0x00069564 in bfd_elf_final_link (abfd=0xe3d80, info=0xd727c)
    at ../../src/bfd/elflink.c:8320
#5  0x0004e664 in elf32_hppa_final_link (abfd=0xe3d80, info=0x19a7e8)
    at ../../src/bfd/elf32-hppa.c:3100
#6  0x000283e4 in ldwrite () at ../../src/ld/ldwrite.c:554
#7  0x00025e50 in main (argc=24, argv=0xbff2d6bc) at ../../src/ld/ldmain.c:468

(gdb) p h->root.type
$49 = bfd_link_hash_undefined
(gdb) p h->ref_dynamic
$50 = 1
(gdb) p h->ref_regular
$51 = 0
(gdb) p finfo->info->unresolved_syms_in_shared_libs
$52 = RM_GENERATE_ERROR
(gdb) p finfo->info->shared
$53 = 0
(gdb) p finfo->info->relocatable
$55 = 0

Why is the default to generate errors for undefined symbols in shared
libraries that aren't referenced from the regular files?  Presumably,
when the shared libraries were linked, these references were resolved
or the link was done to ignore unresolved symbols.

Dave
Comment 25 H.J. Lu 2005-10-11 02:49:33 UTC
You need to find out why those symbols aren't defined, given that
ld.so.1 is loaded via DT_NEEDED in libc.so.6. I saw a few possibilities:

1. A bfd/ld bug which is platform dependent.
2. Different binutils sources.
3. Platform issue.

You can do a binary search on binutils in CVS to see which patch causes this
issue.
Comment 26 dave@hiauly1.hia.nrc.ca 2005-10-11 02:55:45 UTC
Subject: Re:  /lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'

> You need to find out why those symbols aren't defined, given that

I just found the problem.  It was an installation of an old libc6
that was causing an incorrect version of ld.so.1 to be found.
Thanks for the help.

Dave
Comment 27 John David Anglin 2005-10-11 02:57:04 UTC
Closing per comment #26.