From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeffrey A Law To: binutils@sourceware.cygnus.com Cc: drepper@cygnus.com Subject: Dealing with broken ELF libraries Date: Wed, 01 Sep 1999 15:47:00 -0000 Message-id: <23914.936225419@upchuck.cygnus.com> X-SW-Source: 1999-09/msg00003.html Ho hum. In typical fashion HP made some goof's in their ELF implementation which apparently nobody's noticed because nobody else in their right mind is writing ELF tools to work on hpux11 :-) Can someone spot the bug in these two header dumps? readelf -S libc.so There are 42 section headers, starting at offset 0x1227b8: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 ffffffff 000000 00 0 0 0 [ 1] .dynamic DYNAMIC 000011c8 0001c8 000150 10 A 0 0 8 [ 2] .dynsym DYNSYM 00001318 000318 00a050 18 A 3 0 8 [ 3] .dynstr STRTAB 0000b368 00a368 00482f 00 A 0 0 1 [ ... ] [law@portal /scr/hp-elf-native/ld/test] readelf -S libdl.so There are 35 section headers, starting at offset 0x51c8: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 ffffffff 000000 00 0 0 0 [ 1] .dynamic DYNAMIC 000011c8 0001c8 000120 10 A 0 0 8 [ 2] .dynsym DYNSYM 000012e8 0002e8 000360 18 A 3 0 8 [ 3] .dynstr STRTAB 00001648 000648 000203 00 A 0 0 1 Stumped? The link for the .dynamic field points back to section #0 instead of pointing to section #3. Opps. This causes gld/bfd some problems: elflink.c::elf_link_add_object_symbols s = bfd_get_section_by_name (abfd, ".dynamic"); [ ... blah blah blah ... ] elfsec = _bfd_elf_section_from_bfd_section (abfd, s); if (elfsec == -1) goto error_return; link = elf_elfsections (abfd)[elfsec]->sh_link; So we get a link of 0. Of course section #0 is not a string table. This causes grief later when we do something like call bfd_elf_string_from_elf_section. So what do y'all think the best workaround might be? Yes, I know HP should fix their tools & libraries, but the libraries with the bogus link fields are fairly widespread already. And while HP may fix their tools, all the existing sites lose if we can't find a good workaround. We might be able to do something like recognize that LINK refers to a section that is not of type STRTAB (and then fall back to looking for .dynsym's string table). Other options? jeff