public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)
@ 2002-07-03  5:14 ross.alexander
  2002-07-04  0:19 ` Alan Modra
  0 siblings, 1 reply; 12+ messages in thread
From: ross.alexander @ 2002-07-03  5:14 UTC (permalink / raw)
  To: law; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2456 bytes --]


HP have sent me a copy of ld64 with the bug fixed but here is the patch
anyway.

bfd/Changelog
      * elf.c (bfd_elf_get_bfd_needed_list): Current HP ld64 and existing
shared
      libraries erronously set sh_link in the .dynamic section to 0.  It
should be
      set to the index of the .dynstr section.  Should be fixed on ld
patches later
      than PHSS_26262 as HP has produced a site specific fix.

(See attached file: elf.c.patch)

---------------------------------------------------------------------------------

Ross Alexander                           "He knows no more about his
MIS - NEC Europe Limited            destiny than a tea leaf knows
Work ph: +44 20 8752 3394         the history of East India Company"


|---------+------------------------------>
|         |           Jeff Law           |
|         |           <law@porcupine.slc.|
|         |           redhat.com>        |
|         |                              |
|         |           02/07/2002 19:23   |
|         |           Please respond to  |
|         |           law                |
|         |                              |
|---------+------------------------------>
  >------------------------------------------------------------------------------------------------------------|
  |                                                                                                            |
  |       To:       ross.alexander@uk.neceur.com                                                               |
  |       cc:       binutils@sources.redhat.com                                                                |
  |       Subject:  Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)                  |
  >------------------------------------------------------------------------------------------------------------|




In message <OF57EE2279.B5306762-ON80256BEA.0056AFF9@uk.neceur.com>,
ross.alexan
der@uk.neceur.com writes:
  >
  > I don't mind producing a patch to create a workaround (it is very
straight
  > forward, for a change) or we could produce a program which 'corrects'
the
  > defective libraries.  However, because these are system libraries, a
lot
  > of people may be unwilling to go near then.
I suspect "fixing" the defective libraries won't be palatable to most
folks.  If we can engineer a clean workaround in bfd so that we can deal
with the broken libraries in a sane way that would probably be best.

jeff





[-- Attachment #2: elf.c.patch --]
[-- Type: application/octet-stream, Size: 602 bytes --]

*** binutils-020702/bfd/elf.c.orig	Tue Jul  2 05:31:22 2002
--- binutils-020702/bfd/elf.c	Wed Jul  3 12:07:33 2002
***************
*** 1568,1573 ****
--- 1568,1580 ----
  
    shlink = elf_elfsections (abfd)[elfsec]->sh_link;
  
+ /* HP ELF linker brokeness.  The sh_link on dynamic is set to 0. */
+   if (shlink == 0)
+     {
+       asection *dynstr = bfd_get_section_by_name(abfd, ".dynstr");
+       shlink = _bfd_elf_section_from_bfd_section (abfd, dynstr);
+     }
+ 
    extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
    swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
  

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)
  2002-07-03  5:14 hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section) ross.alexander
@ 2002-07-04  0:19 ` Alan Modra
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Modra @ 2002-07-04  0:19 UTC (permalink / raw)
  To: ross.alexander; +Cc: law, binutils

On Wed, Jul 03, 2002 at 12:35:04PM +0100, ross.alexander@uk.neceur.com wrote:
> 
> HP have sent me a copy of ld64 with the bug fixed but here is the patch
> anyway.
> 
> bfd/Changelog
>       * elf.c (bfd_elf_get_bfd_needed_list): Current HP ld64 and existing
> shared

Thanks.  I'm going to propose a different patch though, because I
noticed that we already do hpux fudges for this problem in
elflink.h:elf_link_add_object_symbols, and we also need to fix
elf.c:_bfd_elf_print_private_bfd_data.

Would you mind checking that the following does indeed cure the
hpux shared lib problem?

	* elflink.h (elf_link_add_object_symbols): Revert 1999-09-02 hpux
	fudge.
	* elf.c (bfd_section_from_shdr): Work around broken hpux shared
	libs here instead.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.151
diff -u -p -r1.151 elf.c
--- bfd/elf.c	2 Jul 2002 04:31:22 -0000	1.151
+++ bfd/elf.c	4 Jul 2002 04:49:34 -0000
@@ -1661,7 +1661,6 @@ bfd_section_from_shdr (abfd, shindex)
       return true;
 
     case SHT_PROGBITS:	/* Normal section with contents.  */
-    case SHT_DYNAMIC:	/* Dynamic linking information.  */
     case SHT_NOBITS:	/* .bss section.  */
     case SHT_HASH:	/* .hash section.  */
     case SHT_NOTE:	/* .note section.  */
@@ -1669,6 +1668,39 @@ bfd_section_from_shdr (abfd, shindex)
     case SHT_FINI_ARRAY:	/* .fini_array section.  */
     case SHT_PREINIT_ARRAY:	/* .preinit_array section.  */
       return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
+
+    case SHT_DYNAMIC:	/* Dynamic linking information.  */
+      if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
+	return false;
+      if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB)
+	{
+	  Elf_Internal_Shdr *dynsymhdr;
+
+	  /* The shared libraries distributed with hpux11 have a bogus
+	     sh_link field for the ".dynamic" section.  Find the
+	     string table for the ".dynsym" section instead.  */
+	  if (elf_dynsymtab (abfd) != 0)
+	    {
+	      dynsymhdr = elf_elfsections (abfd)[elf_dynsymtab (abfd)];
+	      hdr->sh_link = dynsymhdr->sh_link;
+	    }
+	  else
+	    {
+	      unsigned int i, num_sec;
+
+	      num_sec = elf_numsections (abfd);
+	      for (i = 1; i < num_sec; i++)
+		{
+		  dynsymhdr = elf_elfsections (abfd)[i];
+		  if (dynsymhdr->sh_type == SHT_DYNSYM)
+		    {
+		      hdr->sh_link = dynsymhdr->sh_link;
+		      break;
+		    }
+		}
+	    }
+	}
+      break;
 
     case SHT_SYMTAB:		/* A symbol table */
       if (elf_onesymtab (abfd) == shindex)
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.172
diff -u -p -r1.172 elflink.h
--- bfd/elflink.h	1 Jul 2002 08:06:46 -0000	1.172
+++ bfd/elflink.h	4 Jul 2002 04:49:40 -0000
@@ -1451,23 +1451,6 @@ elf_link_add_object_symbols (abfd, info)
 	    goto error_return;
 	  shlink = elf_elfsections (abfd)[elfsec]->sh_link;
 
-	  {
-	    /* The shared libraries distributed with hpux11 have a bogus
-	       sh_link field for the ".dynamic" section.  This code detects
-	       when SHLINK refers to a section that is not a string table
-	       and tries to find the string table for the ".dynsym" section
-	       instead.  */
-	    Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[shlink];
-	    if (shdr->sh_type != SHT_STRTAB)
-	      {
-		asection *ds = bfd_get_section_by_name (abfd, ".dynsym");
-		int elfdsec = _bfd_elf_section_from_bfd_section (abfd, ds);
-		if (elfdsec == -1)
-		  goto error_return;
-		shlink = elf_elfsections (abfd)[elfdsec]->sh_link;
-	      }
-	  }
-
 	  extdyn = dynbuf;
 	  extdynend = extdyn + s->_raw_size / sizeof (Elf_External_Dyn);
 	  rpath = 0;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)
  2002-07-04  4:18 ross.alexander
@ 2002-07-04  6:39 ` Alan Modra
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Modra @ 2002-07-04  6:39 UTC (permalink / raw)
  To: ross.alexander; +Cc: binutils

On Thu, Jul 04, 2002 at 11:42:58AM +0100, ross.alexander@uk.neceur.com wrote:
> 
> Many thanks.  That certain fixes the link problem I was having with X11.

Good.  As a bonus, "objcopy bad_lib new_lib" should fix the library
for you.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)
@ 2002-07-04  4:18 ross.alexander
  2002-07-04  6:39 ` Alan Modra
  0 siblings, 1 reply; 12+ messages in thread
From: ross.alexander @ 2002-07-04  4:18 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils


Alan,

Many thanks.  That certain fixes the link problem I was having with X11.
It works
with both the broken and fixed version of all the X11 libraries and the
program
(bitmap) runs fine.  I can't do too much testing with X11 because it
contains quite
a few sizeof(int) != sizeof(char*) problems.

Hopefully the HP site specific fix with come out as a standard HP patch
fairly soon.

Many thanks

Ross
---------------------------------------------------------------------------------

Ross Alexander                           "He knows no more about his
MIS - NEC Europe Limited            destiny than a tea leaf knows
Work ph: +44 20 8752 3394         the history of East India Company"


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)
  2002-07-03 12:45 John David Anglin
@ 2002-07-03 13:10 ` Jeff Law
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Law @ 2002-07-03 13:10 UTC (permalink / raw)
  To: John David Anglin; +Cc: binutils, ross.alexander, law

In message <200207031920.g63JKan2026562@hiauly1.hia.nrc.ca>, "John David Anglin
" writes:
 >The brokeness of the HP linker seems to have been previously discovered.
 >See code around line 1452 in elflink.h.  The test there tries to determine
 >if the SHLINK field refers to a section that is not a string table.
 >I guess the question is whether bogus values other than 0 can occur.
That code looks vaguely familiar.  Yup, I wrote it back in 1999 when doing
the original support for PA64 ELF.

Unfortunately, I don't recall the range of potential bogus values that might
appear in the SHLINK field of the .dynamic section.

If possible, we should use the same work-around in both hunks of code.
jeff

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)
@ 2002-07-03 12:45 John David Anglin
  2002-07-03 13:10 ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: John David Anglin @ 2002-07-03 12:45 UTC (permalink / raw)
  To: binutils; +Cc: ross.alexander, law

The brokeness of the HP linker seems to have been previously discovered.
See code around line 1452 in elflink.h.  The test there tries to determine
if the SHLINK field refers to a section that is not a string table.
I guess the question is whether bogus values other than 0 can occur.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic  section)
  2002-07-02  8:57 ross.alexander
@ 2002-07-02 11:20 ` Jeff Law
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Law @ 2002-07-02 11:20 UTC (permalink / raw)
  To: ross.alexander; +Cc: binutils

In message <OF57EE2279.B5306762-ON80256BEA.0056AFF9@uk.neceur.com>, ross.alexan
der@uk.neceur.com writes:
  >
  > I don't mind producing a patch to create a workaround (it is very straight
  > forward, for a change) or we could produce a program which 'corrects' the
  > defective libraries.  However, because these are system libraries, a lot
  > of people may be unwilling to go near then.
I suspect "fixing" the defective libraries won't be palatable to most 
folks.  If we can engineer a clean workaround in bfd so that we can deal
with the broken libraries in a sane way that would probably be best.

jeff

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)
@ 2002-07-02  8:57 ross.alexander
  2002-07-02 11:20 ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: ross.alexander @ 2002-07-02  8:57 UTC (permalink / raw)
  To: ross.alexander; +Cc: binutils


Alan & Jeff,

The good news is HP has recognised is as a defect and hopefully I will get
a
new version of ld.  However, all the current HP supplied libraries are
broken.

I don't mind producing a patch to create a workaround (it is very straight
forward,
for a change) or we could produce a program which 'corrects' the defective
libraries.  However, because these are system libraries, a lot of people
may
be unwilling to go near then.

Cheers,

Ross

---------------------------------------------------------------------------------

Ross Alexander                           "He knows no more about his
MIS - NEC Europe Limited            destiny than a tea leaf knows
Work ph: +44 20 8752 3394         the history of East India Company"


|---------+--------------------------------->
|         |           ross.alexander@uk.nece|
|         |           ur.com                |
|         |           Sent by:              |
|         |           binutils-owner@sources|
|         |           .redhat.com           |
|         |                                 |
|         |                                 |
|         |           01/07/2002 16:16      |
|         |                                 |
|---------+--------------------------------->
  >------------------------------------------------------------------------------------------------------------|
  |                                                                                                            |
  |       To:       Alan Modra <amodra@bigpond.net.au>                                                         |
  |       cc:       binutils@sources.redhat.com, binutils-owner@sources.redhat.com                             |
  |       Subject:  Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)                   |
  >------------------------------------------------------------------------------------------------------------|





Alan,

I will produce a patch within the next couple of days.  I'm currently
waiting
on a call with HP to check if it is a bug or a feature.  If I don't hear
back
from them in a couple of days then I'll submit that patch anyway.

I'm currently giving ld a good run compiling gtk+-2.0.  Afterward I'll test
perl5.8.

Cheers,

Ross

---------------------------------------------------------------------------------


Ross Alexander                           "He knows no more about his
MIS - NEC Europe Limited            destiny than a tea leaf knows
Work ph: +44 20 8752 3394         the history of East India Company"


|---------+--------------------------------->
|         |           Alan Modra            |
|         |           <amodra@bigpond.net.au|
|         |           >                     |
|         |           Sent by:              |
|         |           binutils-owner@sources|
|         |           .redhat.com           |
|         |                                 |
|         |                                 |
|         |           30/06/2002 12:12      |
|         |                                 |
|---------+--------------------------------->
  >
------------------------------------------------------------------------------------------------------------|

  |
|
  |       To:       ross.alexander@uk.neceur.com
|
  |       cc:       binutils@sources.redhat.com
|
  |       Subject:  Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect
.dynamic section)                   |
  >
------------------------------------------------------------------------------------------------------------|





On Fri, Jun 28, 2002 at 08:07:46PM +0100, ross.alexander@uk.neceur.com
wrote:
> bfd_elf_get_bfd_needed_list breaks.
[snip]
> 1) Check if shlink == 0 and pick up the ELF index of dynsym section
> explicitly.

I think this is reasonable, given that conforming objects will have a
non-zero sh_link.  Care to submit a patch and ChangeLog entry?

--
Alan Modra
IBM OzLabs - Linux Technology Centre










^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)
  2002-07-01  8:16 ross.alexander
@ 2002-07-01 16:18 ` Alan Modra
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Modra @ 2002-07-01 16:18 UTC (permalink / raw)
  To: ross.alexander; +Cc: binutils

On Mon, Jul 01, 2002 at 04:16:09PM +0100, ross.alexander@uk.neceur.com wrote:
> 
> I will produce a patch within the next couple of days.

Thanks.  No hurry.  Another solution occurred to me 5 seconds after
sending my previous email:  You could write a utility to fix the
broken HP shared libs.  Should be quite easy, especially if you steal
readelf.c code.

> On Fri, Jun 28, 2002 at 08:07:46PM +0100, ross.alexander@uk.neceur.com
> wrote:
> > bfd_elf_get_bfd_needed_list breaks.
> [snip]
> > 1) Check if shlink == 0 and pick up the ELF index of dynsym section
> > explicitly.
> 
> I think this is reasonable, given that conforming objects will have a
> non-zero sh_link.  Care to submit a patch and ChangeLog entry?

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)
@ 2002-07-01  8:16 ross.alexander
  2002-07-01 16:18 ` Alan Modra
  0 siblings, 1 reply; 12+ messages in thread
From: ross.alexander @ 2002-07-01  8:16 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, binutils-owner


Alan,

I will produce a patch within the next couple of days.  I'm currently
waiting
on a call with HP to check if it is a bug or a feature.  If I don't hear
back
from them in a couple of days then I'll submit that patch anyway.

I'm currently giving ld a good run compiling gtk+-2.0.  Afterward I'll test
perl5.8.

Cheers,

Ross

---------------------------------------------------------------------------------

Ross Alexander                           "He knows no more about his
MIS - NEC Europe Limited            destiny than a tea leaf knows
Work ph: +44 20 8752 3394         the history of East India Company"


|---------+--------------------------------->
|         |           Alan Modra            |
|         |           <amodra@bigpond.net.au|
|         |           >                     |
|         |           Sent by:              |
|         |           binutils-owner@sources|
|         |           .redhat.com           |
|         |                                 |
|         |                                 |
|         |           30/06/2002 12:12      |
|         |                                 |
|---------+--------------------------------->
  >------------------------------------------------------------------------------------------------------------|
  |                                                                                                            |
  |       To:       ross.alexander@uk.neceur.com                                                               |
  |       cc:       binutils@sources.redhat.com                                                                |
  |       Subject:  Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)                   |
  >------------------------------------------------------------------------------------------------------------|




On Fri, Jun 28, 2002 at 08:07:46PM +0100, ross.alexander@uk.neceur.com
wrote:
> bfd_elf_get_bfd_needed_list breaks.
[snip]
> 1) Check if shlink == 0 and pick up the ELF index of dynsym section
> explicitly.

I think this is reasonable, given that conforming objects will have a
non-zero sh_link.  Care to submit a patch and ChangeLog entry?

--
Alan Modra
IBM OzLabs - Linux Technology Centre





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)
  2002-06-28 12:07 ross.alexander
@ 2002-06-30  4:12 ` Alan Modra
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Modra @ 2002-06-30  4:12 UTC (permalink / raw)
  To: ross.alexander; +Cc: binutils

On Fri, Jun 28, 2002 at 08:07:46PM +0100, ross.alexander@uk.neceur.com wrote:
> bfd_elf_get_bfd_needed_list breaks.
[snip]
> 1) Check if shlink == 0 and pick up the ELF index of dynsym section
> explicitly.

I think this is reasonable, given that conforming objects will have a
non-zero sh_link.  Care to submit a patch and ChangeLog entry?

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 12+ messages in thread

* hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section)
@ 2002-06-28 12:07 ross.alexander
  2002-06-30  4:12 ` Alan Modra
  0 siblings, 1 reply; 12+ messages in thread
From: ross.alexander @ 2002-06-28 12:07 UTC (permalink / raw)
  To: binutils

HI all,

There is a major bug with HP ld produced shared libraries.

ralexand@styx 19:53:36 $/usr/ccs/bin/ld -b -o libtest2.sl test2.o
libtest1.sl +b $PWD
ralexand@styx 19:53:39 $readelf -W -S libtest2.sl  | more
There are 24 section headers, starting at offset 0x1448:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES
Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 ffffffffffffffff
000000 00      0   0  0
  [ 1] .dynamic          DYNAMIC         40000000000001c8 0001c8 000140 10
A  0   0  8
  [ 2] .dynsym           DYNSYM          4000000000000308 000308 0000a8 18
A  3   0  8
  [ 3] .dynstr           STRTAB          40000000000003b0 0003b0 00005e 00
A  0   0  1
  [ 4] .hash             HASH            4000000000000410 000410 000030 00
A  0   0  8

As you can see in the .dynamic section, the link is set to 0.  This means
bfd_elf_get_bfd_needed_list breaks.

1569: shlink = elf_elfsections (abfd)[elfsec]->sh_link;

There are two solutions.

1) Check if shlink == 0 and pick up the ELF index of dynsym section
explicitly.
This does work but could break lots of other implementations.

2) Get HP to fix their linker.  On page 9 of ELF-64 Object File Fromat,
V1.4 is
states the sh_link of SHT_DYNAMIC is "String table used by entries in this
section".
The problem is even if this gets fixed the existing HP libraries (eg X11 et
al) are
all broken.

Boo hoo,

Ross


---------------------------------------------------------------------------------

Ross Alexander                           "He knows no more about his
MIS - NEC Europe Limited            destiny than a tea leaf knows
Work ph: +44 20 8752 3394         the history of East India Company"


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-07-04 13:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-03  5:14 hppa64-hp-hpux11.00: HP ELF64 brokeness (incorrect .dynamic section) ross.alexander
2002-07-04  0:19 ` Alan Modra
  -- strict thread matches above, loose matches on Subject: below --
2002-07-04  4:18 ross.alexander
2002-07-04  6:39 ` Alan Modra
2002-07-03 12:45 John David Anglin
2002-07-03 13:10 ` Jeff Law
2002-07-02  8:57 ross.alexander
2002-07-02 11:20 ` Jeff Law
2002-07-01  8:16 ross.alexander
2002-07-01 16:18 ` Alan Modra
2002-06-28 12:07 ross.alexander
2002-06-30  4:12 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).