public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Question about an elf.c change
@ 2002-01-16 12:45 Steve Ellcey
  2002-01-16 17:08 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Ellcey @ 2002-01-16 12:45 UTC (permalink / raw)
  To: amodra, binutils


I would like to have a change checked in to bfd/elf.c to fix a
regression (for my HP-UX IA64 platform) that was introduced with version
1.112 of elf.c made by amodra.

For my HP-UX IA64 vector I have a special version of
elf_backend_section_from_bfd_section that returns SHN_IA_64_ANSI_COMMON
instead of SHN_COMMON if bfd_is_com_section() is true.  This used to
work because in elf.c (_bfd_elf_section_from_bfd_section) we called the
special version of the elf_backend_section_from_bfd_section routine
before doing:

  if (bfd_is_com_section (asect))
    return SHN_COMMON;

Now, we do this test before calling the platform specific
elf_backend_section_from_bfd_section function and I get SHN_COMMON
instead of the SHN_IA_64_ANSI_COMMON that I want.

Is the following patch (move the abs/com/undef tests later in the
routine) considered acceptable in order to fix this.  I am not sure
what, if any, complications there may be in doing the various checks in
_bfd_elf_section_from_bfd_section in any particular order.

Steve Ellcey
sje@cup.hp.com


2002-01-16  Steve Ellcey  <sje@cup.hp.com>

        * elf.c (_bfd_elf_section_from_bfd_section): Do platform
	specific section checks before generic ones.

--- elf.c.orig	Wed Jan 16 10:42:17 2002
+++ elf.c	Wed Jan 16 10:45:35 2002
@@ -4044,13 +4044,6 @@ _bfd_elf_section_from_bfd_section (abfd,
       && elf_section_data (asect)->this_idx != 0)
     return elf_section_data (asect)->this_idx;
 
-  if (bfd_is_abs_section (asect))
-    return SHN_ABS;
-  if (bfd_is_com_section (asect))
-    return SHN_COMMON;
-  if (bfd_is_und_section (asect))
-    return SHN_UNDEF;
-
   for (index = 1; index < maxindex; index++)
     {
       hdr = i_shdrp[index];
@@ -4074,6 +4067,13 @@ _bfd_elf_section_from_bfd_section (abfd,
 	    return retval;
 	}
     }
+
+  if (bfd_is_abs_section (asect))
+    return SHN_ABS;
+  if (bfd_is_com_section (asect))
+    return SHN_COMMON;
+  if (bfd_is_und_section (asect))
+    return SHN_UNDEF;
 
   bfd_set_error (bfd_error_nonrepresentable_section);
 

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

* Re: Question about an elf.c change
  2002-01-16 12:45 Question about an elf.c change Steve Ellcey
@ 2002-01-16 17:08 ` Alan Modra
  2002-01-17  8:03   ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2002-01-16 17:08 UTC (permalink / raw)
  To: Steve Ellcey; +Cc: binutils

On Wed, Jan 16, 2002 at 11:03:43AM -0800, Steve Ellcey wrote:
> 
> 2002-01-16  Steve Ellcey  <sje@cup.hp.com>
> 
>         * elf.c (_bfd_elf_section_from_bfd_section): Do platform
> 	specific section checks before generic ones.
> 
> --- elf.c.orig	Wed Jan 16 10:42:17 2002
> +++ elf.c	Wed Jan 16 10:45:35 2002
> @@ -4044,13 +4044,6 @@ _bfd_elf_section_from_bfd_section (abfd,
>        && elf_section_data (asect)->this_idx != 0)
>      return elf_section_data (asect)->this_idx;
>  
> -  if (bfd_is_abs_section (asect))
> -    return SHN_ABS;
> -  if (bfd_is_com_section (asect))
> -    return SHN_COMMON;
> -  if (bfd_is_und_section (asect))
> -    return SHN_UNDEF;
> -
>    for (index = 1; index < maxindex; index++)
>      {
>        hdr = i_shdrp[index];
> @@ -4074,6 +4067,13 @@ _bfd_elf_section_from_bfd_section (abfd,
>  	    return retval;
>  	}
>      }
> +
> +  if (bfd_is_abs_section (asect))
> +    return SHN_ABS;
> +  if (bfd_is_com_section (asect))
> +    return SHN_COMMON;
> +  if (bfd_is_und_section (asect))
> +    return SHN_UNDEF;
>  
>    bfd_set_error (bfd_error_nonrepresentable_section);

This is OK.  The reason I moved the bfd_is_*_section tests was for
efficiency, in order to avoid scanning sections when possible.

Hmm, now that I look at it again, I see no reason why
bed->elf_backend_section_from_bfd_section is called from inside a
loop.  None of the backends use the hdr arg.  I might make a
slightly more comprehensive patch.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: Question about an elf.c change
  2002-01-16 17:08 ` Alan Modra
@ 2002-01-17  8:03   ` Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2002-01-17  8:03 UTC (permalink / raw)
  To: Steve Ellcey, binutils

On Thu, Jan 17, 2002 at 11:33:40AM +1030, Alan Modra wrote:
> 
> Hmm, now that I look at it again, I see no reason why
> bed->elf_backend_section_from_bfd_section is called from inside a
> loop.  None of the backends use the hdr arg.  I might make a
> slightly more comprehensive patch.

Done.  If ever a backend needs to look at the elf headers, it can
rummage through the list itself.

bfd/ChangeLog
	* elf-bfd.h (elf_backend_data <elf_backend_section_from_bfd_section>):
	Remove "Elf_Internal_Shdr *" param.
	(_bfd_mips_elf_section_from_bfd_section): Ditto.
	* elf32-mips.c (_bfd_mips_elf_section_from_bfd_section): Ditto.
	* elf32-m32r.c (_bfd_m32r_elf_section_from_bfd_section): Ditto.
	* elf32-v850.c (v850_elf_section_from_bfd_section): Ditto.
	* elf64-mmix.c (mmix_elf_section_from_bfd_section): Ditto.
	* elfxx-ia64.c (elfNN_hpux_backend_section_from_bfd_section): Ditto.
	* elf.c (_bfd_elf_section_from_bfd_section): Allow backend
	function to override special sections.  Remove hdr arg from
	backend call, and don't loop.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.64
diff -u -p -r1.64 elf-bfd.h
--- elf-bfd.h	2002/01/10 23:05:21	1.64
+++ elf-bfd.h	2002/01/17 11:26:18
@@ -493,7 +493,7 @@ struct elf_backend_data
      section, *RETVAL should be left unchanged.  If it is not a normal
      ELF section *RETVAL should be set to the SHN_xxxx index.  */
   boolean (*elf_backend_section_from_bfd_section)
-    PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *retval));
+    PARAMS ((bfd *, asection *, int *retval));
 
   /* If this field is not NULL, it is called by the add_symbols phase
      of a link just before adding a symbol to the global linker hash
@@ -1541,7 +1541,7 @@ extern boolean _bfd_mips_elf_section_fro
 extern boolean _bfd_mips_elf_fake_sections
   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
 extern boolean _bfd_mips_elf_section_from_bfd_section
-  PARAMS ((bfd *, Elf_Internal_Shdr *, asection *, int *));
+  PARAMS ((bfd *, asection *, int *));
 extern boolean _bfd_mips_elf_section_processing
   PARAMS ((bfd *, Elf_Internal_Shdr *));
 extern void _bfd_mips_elf_symbol_processing
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.122
diff -c -p -r1.122 elf.c
*** elf.c	2002/01/15 12:52:14	1.122
--- elf.c	2002/01/17 12:54:05
*************** _bfd_elf_section_from_bfd_section (abfd,
*** 4050,4099 ****
       bfd *abfd;
       struct sec *asect;
  {
!   struct elf_backend_data *bed = get_elf_backend_data (abfd);
!   Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
    int index;
-   Elf_Internal_Shdr *hdr;
-   int maxindex = elf_numsections (abfd);
  
    if (elf_section_data (asect) != NULL
        && elf_section_data (asect)->this_idx != 0)
      return elf_section_data (asect)->this_idx;
  
    if (bfd_is_abs_section (asect))
!     return SHN_ABS;
!   if (bfd_is_com_section (asect))
!     return SHN_COMMON;
!   if (bfd_is_und_section (asect))
!     return SHN_UNDEF;
! 
!   for (index = 1; index < maxindex; index++)
      {
!       hdr = i_shdrp[index];
!       if (hdr != NULL && hdr->bfd_section == asect)
! 	return index;
      }
  
    if (bed->elf_backend_section_from_bfd_section)
      {
!       for (index = 0; index < maxindex; index++)
! 	{
! 	  int retval;
  
! 	  hdr = i_shdrp[index];
! 	  if (hdr == NULL)
! 	    continue;
! 
! 	  retval = index;
! 	  if ((*bed->elf_backend_section_from_bfd_section)
! 	      (abfd, hdr, asect, &retval))
! 	    return retval;
! 	}
      }
  
!   bfd_set_error (bfd_error_nonrepresentable_section);
  
!   return SHN_BAD;
  }
  
  /* Given a BFD symbol, return the index in the ELF symbol table, or -1
--- 4050,4096 ----
       bfd *abfd;
       struct sec *asect;
  {
!   struct elf_backend_data *bed;
    int index;
  
    if (elf_section_data (asect) != NULL
        && elf_section_data (asect)->this_idx != 0)
      return elf_section_data (asect)->this_idx;
  
    if (bfd_is_abs_section (asect))
!     index = SHN_ABS;
!   else if (bfd_is_com_section (asect))
!     index = SHN_COMMON;
!   else if (bfd_is_und_section (asect))
!     index = SHN_UNDEF;
!   else
      {
!       Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
!       int maxindex = elf_numsections (abfd);
! 
!       for (index = 1; index < maxindex; index++)
! 	{
! 	  Elf_Internal_Shdr *hdr = i_shdrp[index];
! 
! 	  if (hdr != NULL && hdr->bfd_section == asect)
! 	    return index;
! 	}
!       index = -1;
      }
  
+   bed = get_elf_backend_data (abfd);
    if (bed->elf_backend_section_from_bfd_section)
      {
!       int retval = index;
  
!       if ((*bed->elf_backend_section_from_bfd_section) (abfd, asect, &retval))
! 	return retval;
      }
  
!   if (index == -1)
!     bfd_set_error (bfd_error_nonrepresentable_section);
  
!   return index;
  }
  
  /* Given a BFD symbol, return the index in the ELF symbol table, or -1
Index: bfd/elf32-m32r.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m32r.c,v
retrieving revision 1.20
diff -u -p -r1.20 elf32-m32r.c
--- elf32-m32r.c	2001/12/18 17:59:58	1.20
+++ elf32-m32r.c	2002/01/17 11:26:26
@@ -45,7 +45,7 @@ static reloc_howto_type *bfd_elf32_bfd_r
 static void m32r_info_to_howto_rel
   PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
 boolean _bfd_m32r_elf_section_from_bfd_section
-  PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
+  PARAMS ((bfd *, asection *, int *));
 void _bfd_m32r_elf_symbol_processing
   PARAMS ((bfd *, asymbol *));
 static boolean m32r_elf_add_symbol_hook
@@ -765,9 +765,8 @@ m32r_info_to_howto_rel (abfd, cache_ptr,
    index.  */
 
 boolean
-_bfd_m32r_elf_section_from_bfd_section (abfd, hdr, sec, retval)
+_bfd_m32r_elf_section_from_bfd_section (abfd, sec, retval)
      bfd *abfd ATTRIBUTE_UNUSED;
-     Elf32_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
      asection *sec;
      int *retval;
 {
Index: bfd/elf32-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-mips.c,v
retrieving revision 1.136
diff -u -p -r1.136 elf32-mips.c
--- elf32-mips.c	2002/01/17 08:19:08	1.136
+++ elf32-mips.c	2002/01/17 11:26:34
@@ -3585,9 +3585,8 @@ _bfd_mips_elf_fake_sections (abfd, hdr, 
    the .scommon section.  */
 
 boolean
-_bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
+_bfd_mips_elf_section_from_bfd_section (abfd, sec, retval)
      bfd *abfd ATTRIBUTE_UNUSED;
-     Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
      asection *sec;
      int *retval;
 {
Index: bfd/elf32-v850.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-v850.c,v
retrieving revision 1.19
diff -u -p -r1.19 elf32-v850.c
--- elf32-v850.c	2001/12/18 17:59:59	1.19
+++ elf32-v850.c	2002/01/17 11:26:38
@@ -69,7 +69,7 @@ static boolean v850_elf_merge_private_bf
 static boolean v850_elf_print_private_bfd_data
   PARAMS ((bfd *, PTR));
 static boolean v850_elf_section_from_bfd_section
-  PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
+  PARAMS ((bfd *, asection *, int *));
 static void v850_elf_symbol_processing
   PARAMS ((bfd *, asymbol *));
 static boolean v850_elf_add_symbol_hook
@@ -1930,9 +1930,8 @@ static asymbol * v850_elf_zcom_symbol_pt
    corresponding ELF section index.  */
 
 static boolean
-v850_elf_section_from_bfd_section (abfd, hdr, sec, retval)
+v850_elf_section_from_bfd_section (abfd, sec, retval)
      bfd *                 abfd ATTRIBUTE_UNUSED;
-     Elf32_Internal_Shdr * hdr ATTRIBUTE_UNUSED;
      asection *            sec;
      int *                 retval;
 {
Index: bfd/elf64-mmix.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-mmix.c,v
retrieving revision 1.5
diff -u -p -r1.5 elf64-mmix.c
--- elf64-mmix.c	2002/01/05 13:11:31	1.5
+++ elf64-mmix.c	2002/01/17 11:26:39
@@ -77,7 +77,7 @@ static bfd_reloc_status_type mmix_elf_pe
   PARAMS ((asection *, reloc_howto_type *, PTR, bfd_vma, bfd_vma));
 
 static boolean mmix_elf_section_from_bfd_section
-  PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *, int *));
+  PARAMS ((bfd *, asection *, int *));
 
 static boolean mmix_elf_add_symbol_hook
   PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
@@ -1557,9 +1557,8 @@ mmix_elf_symbol_processing (abfd, asym)
    index.  */
 
 static boolean
-mmix_elf_section_from_bfd_section (abfd, hdr, sec, retval)
+mmix_elf_section_from_bfd_section (abfd, sec, retval)
      bfd *                 abfd ATTRIBUTE_UNUSED;
-     Elf64_Internal_Shdr * hdr ATTRIBUTE_UNUSED;
      asection *            sec;
      int *                 retval;
 {
Index: bfd/elfxx-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-ia64.c,v
retrieving revision 1.40
diff -u -p -r1.40 elfxx-ia64.c
--- elfxx-ia64.c	2002/01/06 11:14:19	1.40
+++ elfxx-ia64.c	2002/01/17 11:26:43
@@ -312,7 +312,7 @@ static boolean elfNN_ia64_hpux_vec
 static void elfNN_hpux_post_process_headers
   PARAMS ((bfd *abfd, struct bfd_link_info *info));
 boolean elfNN_hpux_backend_section_from_bfd_section
-  PARAMS ((bfd *abfd, ElfNN_Internal_Shdr *hdr, asection *sec, int *retval));
+  PARAMS ((bfd *abfd, asection *sec, int *retval));
 \f
 /* ia64-specific relocation */
 
@@ -4481,9 +4481,8 @@ elfNN_hpux_post_process_headers (abfd, i
 }
 
 boolean
-elfNN_hpux_backend_section_from_bfd_section (abfd, hdr, sec, retval)
+elfNN_hpux_backend_section_from_bfd_section (abfd, sec, retval)
 	bfd *abfd ATTRIBUTE_UNUSED;
-	Elf32_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
 	asection *sec;
 	int *retval;
 {

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

end of thread, other threads:[~2002-01-17 13:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-16 12:45 Question about an elf.c change Steve Ellcey
2002-01-16 17:08 ` Alan Modra
2002-01-17  8:03   ` 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).