public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Pass section name to elf_backend_section_flags
@ 2004-04-23 20:27 H. J. Lu
  2004-04-26 12:13 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2004-04-23 20:27 UTC (permalink / raw)
  To: binutils

This patch removes one FIXME in ELF linker.


H.J.
-----
2004-04-23  H.J. Lu  <hongjiu.lu@intel.com>

	* elf-bfd.h (elf_backend_section_flags): Also take section
	name.
	* elf64-alpha.c (elf64_alpha_section_flags): Updated.
	* elfxx-ia64.c (elfNN_ia64_section_flags): Likewise.

	* elf.c (_bfd_elf_make_section_from_shdr): Pass section name
	to elf_backend_section_flags.

	* elf32-sh64.c (elf_backend_section_flags): New. Defined.
	(sh64_elf_set_mach_from_flags): Remove the kludge for .cranges
	section.
	(sh64_elf_section_flags): New. Set SEC_DEBUGGING for
	.cranges section.

--- bfd/elf-bfd.h.flags	2004-04-22 11:06:31.000000000 -0700
+++ bfd/elf-bfd.h	2004-04-23 11:32:09.000000000 -0700
@@ -597,7 +597,7 @@ struct elf_backend_data
   /* A function to convert machine dependent section header flags to
      BFD internal section header flags.  */
   bfd_boolean (*elf_backend_section_flags)
-    (flagword *, Elf_Internal_Shdr *);
+    (flagword *, Elf_Internal_Shdr *, const char *name);
 
   /* A function to handle unusual program segment types when creating BFD
      sections from ELF program segments.  */
--- bfd/elf.c.flags	2004-04-22 16:25:06.000000000 -0700
+++ bfd/elf.c	2004-04-23 11:34:43.000000000 -0700
@@ -726,7 +726,7 @@ _bfd_elf_make_section_from_shdr (bfd *ab
 
   bed = get_elf_backend_data (abfd);
   if (bed->elf_backend_section_flags)
-    if (! bed->elf_backend_section_flags (&flags, hdr))
+    if (! bed->elf_backend_section_flags (&flags, hdr, name))
       return FALSE;
 
   if (! bfd_set_section_flags (abfd, newsect, flags))
--- bfd/elf32-sh64.c.flags	2004-03-26 08:36:25.000000000 -0800
+++ bfd/elf32-sh64.c	2004-04-23 12:11:05.000000000 -0700
@@ -89,6 +89,7 @@ static void sh64_find_section_for_addres
 #define elf_backend_final_write_processing 	sh64_elf_final_write_processing
 #define elf_backend_section_from_shdr		sh64_backend_section_from_shdr
 #define elf_backend_special_sections		sh64_elf_special_sections
+#define elf_backend_section_flags		sh64_elf_section_flags
 
 #define bfd_elf32_new_section_hook		sh64_elf_new_section_hook
 
@@ -149,7 +150,6 @@ static bfd_boolean
 sh64_elf_set_mach_from_flags (bfd *abfd)
 {
   flagword flags = elf_elfheader (abfd)->e_flags;
-  asection *cranges;
 
   switch (flags & EF_SH_MACH_MASK)
     {
@@ -164,17 +164,16 @@ sh64_elf_set_mach_from_flags (bfd *abfd)
       return FALSE;
     }
 
-  /* We also need to set SEC_DEBUGGING on an incoming .cranges section.
-     We could have used elf_backend_section_flags if it had given us the
-     section name; the bfd_section member in the header argument is not
-     set at the point of the call.  FIXME: Find out whether that is by
-     undocumented design or a bug.  */
-  cranges = bfd_get_section_by_name (abfd, SH64_CRANGES_SECTION_NAME);
-  if (cranges != NULL
-      && ! bfd_set_section_flags (abfd, cranges,
-				  bfd_get_section_flags (abfd, cranges)
-				  | SEC_DEBUGGING))
-    return FALSE;
+  return TRUE;
+}
+
+static bfd_boolean
+sh64_elf_section_flags (flagword *flags,
+			Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED,
+			const char *name)
+{
+  if (strcmp (name, SH64_CRANGES_SECTION_NAME) == 0)
+    *flags |= SEC_DEBUGGING;
 
   return TRUE;
 }
--- bfd/elf64-alpha.c.flags	2004-03-27 17:39:09.000000000 -0800
+++ bfd/elf64-alpha.c	2004-04-23 11:49:05.000000000 -0700
@@ -74,8 +74,6 @@ static bfd_boolean elf64_alpha_object_p
   PARAMS ((bfd *));
 static bfd_boolean elf64_alpha_section_from_shdr
   PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
-static bfd_boolean elf64_alpha_section_flags
-  PARAMS ((flagword *, Elf_Internal_Shdr *));
 static bfd_boolean elf64_alpha_fake_sections
   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
 static bfd_boolean elf64_alpha_create_got_section
@@ -2313,9 +2311,8 @@ elf64_alpha_section_from_shdr (abfd, hdr
 /* Convert Alpha specific section flags to bfd internal section flags.  */
 
 static bfd_boolean
-elf64_alpha_section_flags (flags, hdr)
-     flagword *flags;
-     Elf_Internal_Shdr *hdr;
+elf64_alpha_section_flags (flagword *flags, Elf_Internal_Shdr *hdr,
+			   const char *name ATTRIBUTE_UNUSED)
 {
   if (hdr->sh_flags & SHF_ALPHA_GPREL)
     *flags |= SEC_SMALL_DATA;
--- bfd/elfxx-ia64.c.flags	2004-04-22 09:59:17.000000000 -0700
+++ bfd/elfxx-ia64.c	2004-04-23 11:46:50.000000000 -0700
@@ -195,8 +195,6 @@ static bfd_boolean is_unwind_section_nam
   PARAMS ((bfd *abfd, const char *));
 static bfd_boolean elfNN_ia64_section_from_shdr
   PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
-static bfd_boolean elfNN_ia64_section_flags
-  PARAMS ((flagword *, Elf_Internal_Shdr *));
 static bfd_boolean elfNN_ia64_fake_sections
   PARAMS ((bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec));
 static void elfNN_ia64_final_write_processing
@@ -1279,9 +1277,8 @@ elfNN_ia64_section_from_shdr (abfd, hdr,
    flag.  */
 
 static bfd_boolean
-elfNN_ia64_section_flags (flags, hdr)
-     flagword *flags;
-     Elf_Internal_Shdr *hdr;
+elfNN_ia64_section_flags (flagword *flags, Elf_Internal_Shdr *hdr,
+			  const char *name ATTRIBUTE_UNUSED)
 {
   if (hdr->sh_flags & SHF_IA_64_SHORT)
     *flags |= SEC_SMALL_DATA;

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

* Re: PATCH: Pass section name to elf_backend_section_flags
  2004-04-23 20:27 PATCH: Pass section name to elf_backend_section_flags H. J. Lu
@ 2004-04-26 12:13 ` Alan Modra
  2004-04-26 18:38   ` H. J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2004-04-26 12:13 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Fri, Apr 23, 2004 at 12:14:55PM -0700, H. J. Lu wrote:
> This patch removes one FIXME in ELF linker.

Thanks for looking at FIXMEs :)

> 	* elf-bfd.h (elf_backend_section_flags): Also take section
> 	name.
> 	* elf64-alpha.c (elf64_alpha_section_flags): Updated.
> 	* elfxx-ia64.c (elfNN_ia64_section_flags): Likewise.
> 
> 	* elf.c (_bfd_elf_make_section_from_shdr): Pass section name
> 	to elf_backend_section_flags.
> 
> 	* elf32-sh64.c (elf_backend_section_flags): New. Defined.
> 	(sh64_elf_set_mach_from_flags): Remove the kludge for .cranges
> 	section.
> 	(sh64_elf_section_flags): New. Set SEC_DEBUGGING for
> 	.cranges section.

I suggest instead that you move the assignment to hdr->bfd_section like
this:

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.221
diff -u -p -r1.221 elf.c
--- bfd/elf.c	22 Apr 2004 14:45:31 -0000	1.221
+++ bfd/elf.c	26 Apr 2004 11:44:12 -0000
@@ -652,6 +652,9 @@ _bfd_elf_make_section_from_shdr (bfd *ab
   if (newsect == NULL)
     return FALSE;
 
+  hdr->bfd_section = newsect;
+  elf_section_data (newsect)->this_hdr = *hdr;
+
   /* Always use the real type/flags.  */
   elf_section_type (newsect) = hdr->sh_type;
   elf_section_flags (newsect) = hdr->sh_flags;
@@ -797,9 +800,6 @@ _bfd_elf_make_section_from_shdr (bfd *ab
 	    }
 	}
     }
-
-  hdr->bfd_section = newsect;
-  elf_section_data (newsect)->this_hdr = *hdr;
 
   return TRUE;
 }

which makes the section name available to elf_backend_section_flags.
Also, make the hdr arg to elf_backend_section_flags const.  If testing
shows the patch is ok, consider this approach pre-approved for
mainline.  I've had a look at the effect of setting hdr->bfd_section
early, (ie. before we know the function is going to succeed) and can't
see any problem with doing that, or any need to clean up if we fail for
some reason.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Pass section name to elf_backend_section_flags
  2004-04-26 12:13 ` Alan Modra
@ 2004-04-26 18:38   ` H. J. Lu
  2004-04-27  3:28     ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2004-04-26 18:38 UTC (permalink / raw)
  To: binutils

On Mon, Apr 26, 2004 at 09:22:42PM +0930, Alan Modra wrote:
> On Fri, Apr 23, 2004 at 12:14:55PM -0700, H. J. Lu wrote:
> > This patch removes one FIXME in ELF linker.
> 
> Thanks for looking at FIXMEs :)
> 
> > 	* elf-bfd.h (elf_backend_section_flags): Also take section
> > 	name.
> > 	* elf64-alpha.c (elf64_alpha_section_flags): Updated.
> > 	* elfxx-ia64.c (elfNN_ia64_section_flags): Likewise.
> > 
> > 	* elf.c (_bfd_elf_make_section_from_shdr): Pass section name
> > 	to elf_backend_section_flags.
> > 
> > 	* elf32-sh64.c (elf_backend_section_flags): New. Defined.
> > 	(sh64_elf_set_mach_from_flags): Remove the kludge for .cranges
> > 	section.
> > 	(sh64_elf_section_flags): New. Set SEC_DEBUGGING for
> > 	.cranges section.
> 
> I suggest instead that you move the assignment to hdr->bfd_section like
> this:
> 

How about this patch?


H.J.
----
2004-04-26  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-sh64.c (elf_backend_section_flags): New. Defined.
	(sh64_elf_set_mach_from_flags): Remove the kludge for .cranges
	section.
	(sh64_elf_section_flags): New. Set SEC_DEBUGGING for
	.cranges section.

2004-04-26  Alan Modra  <amodra@bigpond.net.au>

	* elf.c (_bfd_elf_make_section_from_shdr): Set the bfd_section
	field before calling elf_backend_section_flags.

--- bfd/elf.c.section	2004-04-26 08:02:32.000000000 -0700
+++ bfd/elf.c	2004-04-26 08:02:56.000000000 -0700
@@ -652,6 +652,9 @@ _bfd_elf_make_section_from_shdr (bfd *ab
   if (newsect == NULL)
     return FALSE;
 
+  hdr->bfd_section = newsect;
+  elf_section_data (newsect)->this_hdr = *hdr;
+
   /* Always use the real type/flags.  */
   elf_section_type (newsect) = hdr->sh_type;
   elf_section_flags (newsect) = hdr->sh_flags;
@@ -798,9 +801,6 @@ _bfd_elf_make_section_from_shdr (bfd *ab
 	}
     }
 
-  hdr->bfd_section = newsect;
-  elf_section_data (newsect)->this_hdr = *hdr;
-
   return TRUE;
 }
 
--- bfd/elf32-sh64.c.flags	2004-03-26 08:36:25.000000000 -0800
+++ bfd/elf32-sh64.c	2004-04-26 08:12:09.000000000 -0700
@@ -89,6 +89,7 @@ static void sh64_find_section_for_addres
 #define elf_backend_final_write_processing 	sh64_elf_final_write_processing
 #define elf_backend_section_from_shdr		sh64_backend_section_from_shdr
 #define elf_backend_special_sections		sh64_elf_special_sections
+#define elf_backend_section_flags		sh64_elf_section_flags
 
 #define bfd_elf32_new_section_hook		sh64_elf_new_section_hook
 
@@ -149,7 +150,6 @@ static bfd_boolean
 sh64_elf_set_mach_from_flags (bfd *abfd)
 {
   flagword flags = elf_elfheader (abfd)->e_flags;
-  asection *cranges;
 
   switch (flags & EF_SH_MACH_MASK)
     {
@@ -164,18 +164,19 @@ sh64_elf_set_mach_from_flags (bfd *abfd)
       return FALSE;
     }
 
-  /* We also need to set SEC_DEBUGGING on an incoming .cranges section.
-     We could have used elf_backend_section_flags if it had given us the
-     section name; the bfd_section member in the header argument is not
-     set at the point of the call.  FIXME: Find out whether that is by
-     undocumented design or a bug.  */
-  cranges = bfd_get_section_by_name (abfd, SH64_CRANGES_SECTION_NAME);
-  if (cranges != NULL
-      && ! bfd_set_section_flags (abfd, cranges,
-				  bfd_get_section_flags (abfd, cranges)
-				  | SEC_DEBUGGING))
+  return TRUE;
+}
+
+static bfd_boolean
+sh64_elf_section_flags (flagword *flags,
+			Elf_Internal_Shdr *hdr)
+{
+  if (hdr->bfd_section == NULL)
     return FALSE;
 
+  if (strcmp (hdr->bfd_section->name, SH64_CRANGES_SECTION_NAME) == 0)
+    *flags |= SEC_DEBUGGING;
+
   return TRUE;
 }
 

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

* Re: PATCH: Pass section name to elf_backend_section_flags
  2004-04-26 18:38   ` H. J. Lu
@ 2004-04-27  3:28     ` Alan Modra
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2004-04-27  3:28 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Mon, Apr 26, 2004 at 08:29:01AM -0700, H. J. Lu wrote:
> How about this patch?

I did say to make the hdr arg to elf_backend_section_flags const.
There's a good reason to do so.

> --- bfd/elf.c.section	2004-04-26 08:02:32.000000000 -0700
> +++ bfd/elf.c	2004-04-26 08:02:56.000000000 -0700
> @@ -652,6 +652,9 @@ _bfd_elf_make_section_from_shdr (bfd *ab
>    if (newsect == NULL)
>      return FALSE;
>  
> +  hdr->bfd_section = newsect;
> +  elf_section_data (newsect)->this_hdr = *hdr;

We copy the hdr here, so we'd better make sure that nothing changes hdr
fields later.  Marking the pointer const in elf_backend_section_flags
should alert anyone wanting to change hdr fields in
elf_backend_section_flags that doing so is not a good idea.

I've committed the following patch, which also fixes some recent
carelessness.  Your sh patch is OK, with the obvious addition of
'const'.

	* elf64-alpha.c (elf64_alpha_read_ecoff_info): Don't assign
	structure field removed in 2004-04-24 patch.
	* elf64-sparc.c (sparc64_elf_plt_sym_val): Warning fix.

	* elf-bfd.h (struct elf_backend_data <elf_backend_section_flags>):
	Constify hdr arg.
	* elf32-arm.h (elf32_arm_section_flags): Likewise.
	* elf64-alpha.c (elf64_alpha_section_flags): Likewise.
	* elfxx-ia64.c (elfNN_ia64_section_flags): Likewise.
	* elf.c (_bfd_elf_make_section_from_shdr): Set the bfd_section
	field before calling elf_backend_section_flags.

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.137
diff -u -p -r1.137 elf-bfd.h
--- bfd/elf-bfd.h	22 Apr 2004 14:45:30 -0000	1.137
+++ bfd/elf-bfd.h	27 Apr 2004 03:07:38 -0000
@@ -597,7 +597,7 @@ struct elf_backend_data
   /* A function to convert machine dependent section header flags to
      BFD internal section header flags.  */
   bfd_boolean (*elf_backend_section_flags)
-    (flagword *, Elf_Internal_Shdr *);
+    (flagword *, const Elf_Internal_Shdr *);
 
   /* A function to handle unusual program segment types when creating BFD
      sections from ELF program segments.  */
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.221
diff -u -p -r1.221 elf.c
--- bfd/elf.c	22 Apr 2004 14:45:31 -0000	1.221
+++ bfd/elf.c	27 Apr 2004 03:07:40 -0000
@@ -652,6 +652,9 @@ _bfd_elf_make_section_from_shdr (bfd *ab
   if (newsect == NULL)
     return FALSE;
 
+  hdr->bfd_section = newsect;
+  elf_section_data (newsect)->this_hdr = *hdr;
+
   /* Always use the real type/flags.  */
   elf_section_type (newsect) = hdr->sh_type;
   elf_section_flags (newsect) = hdr->sh_flags;
@@ -797,9 +800,6 @@ _bfd_elf_make_section_from_shdr (bfd *ab
 	    }
 	}
     }
-
-  hdr->bfd_section = newsect;
-  elf_section_data (newsect)->this_hdr = *hdr;
 
   return TRUE;
 }
Index: bfd/elf32-arm.h
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.h,v
retrieving revision 1.130
diff -u -p -r1.130 elf32-arm.h
--- bfd/elf32-arm.h	23 Apr 2004 19:12:55 -0000	1.130
+++ bfd/elf32-arm.h	27 Apr 2004 03:07:41 -0000
@@ -4121,7 +4121,7 @@ elf32_arm_reloc_type_class (rela)
     }
 }
 
-static bfd_boolean elf32_arm_section_flags           PARAMS ((flagword *, Elf_Internal_Shdr *));
+static bfd_boolean elf32_arm_section_flags           PARAMS ((flagword *, const Elf_Internal_Shdr *));
 static void        elf32_arm_final_write_processing  PARAMS ((bfd *, bfd_boolean));
 
 /* Set the right machine number for an Arm ELF file.  */
@@ -4129,7 +4129,7 @@ static void        elf32_arm_final_write
 static bfd_boolean
 elf32_arm_section_flags (flags, hdr)
      flagword *flags;
-     Elf_Internal_Shdr *hdr;
+     const Elf_Internal_Shdr *hdr;
 {
   if (hdr->sh_type == SHT_NOTE)
     *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
Index: bfd/elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.117
diff -u -p -r1.117 elf64-alpha.c
--- bfd/elf64-alpha.c	27 Mar 2004 10:58:07 -0000	1.117
+++ bfd/elf64-alpha.c	27 Apr 2004 03:07:45 -0000
@@ -75,7 +75,7 @@ static bfd_boolean elf64_alpha_object_p
 static bfd_boolean elf64_alpha_section_from_shdr
   PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
 static bfd_boolean elf64_alpha_section_flags
-  PARAMS ((flagword *, Elf_Internal_Shdr *));
+  PARAMS ((flagword *, const Elf_Internal_Shdr *));
 static bfd_boolean elf64_alpha_fake_sections
   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
 static bfd_boolean elf64_alpha_create_got_section
@@ -2315,7 +2315,7 @@ elf64_alpha_section_from_shdr (abfd, hdr
 static bfd_boolean
 elf64_alpha_section_flags (flags, hdr)
      flagword *flags;
-     Elf_Internal_Shdr *hdr;
+     const Elf_Internal_Shdr *hdr;
 {
   if (hdr->sh_flags & SHF_ALPHA_GPREL)
     *flags |= SEC_SMALL_DATA;
@@ -2572,7 +2572,6 @@ elf64_alpha_read_ecoff_info (abfd, secti
 #undef READ
 
   debug->fdr = NULL;
-  debug->adjust = NULL;
 
   return TRUE;
 
Index: bfd/elf64-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sparc.c,v
retrieving revision 1.90
diff -u -p -r1.90 elf64-sparc.c
--- bfd/elf64-sparc.c	22 Apr 2004 14:45:31 -0000	1.90
+++ bfd/elf64-sparc.c	27 Apr 2004 03:07:47 -0000
@@ -3112,7 +3112,7 @@ sparc64_elf_object_p (abfd)
 
 static bfd_vma
 sparc64_elf_plt_sym_val (bfd_vma i, const asection *plt,
-			 const arelent *rel)
+			 const arelent *rel ATTRIBUTE_UNUSED)
 {
   bfd_vma j;
 
Index: bfd/elfxx-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-ia64.c,v
retrieving revision 1.125
diff -u -p -r1.125 elfxx-ia64.c
--- bfd/elfxx-ia64.c	6 Apr 2004 00:59:22 -0000	1.125
+++ bfd/elfxx-ia64.c	27 Apr 2004 03:07:49 -0000
@@ -186,7 +186,7 @@ static bfd_boolean is_unwind_section_nam
 static bfd_boolean elfNN_ia64_section_from_shdr
   PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
 static bfd_boolean elfNN_ia64_section_flags
-  PARAMS ((flagword *, Elf_Internal_Shdr *));
+  PARAMS ((flagword *, const Elf_Internal_Shdr *));
 static bfd_boolean elfNN_ia64_fake_sections
   PARAMS ((bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec));
 static void elfNN_ia64_final_write_processing
@@ -1271,7 +1271,7 @@ elfNN_ia64_section_from_shdr (abfd, hdr,
 static bfd_boolean
 elfNN_ia64_section_flags (flags, hdr)
      flagword *flags;
-     Elf_Internal_Shdr *hdr;
+     const Elf_Internal_Shdr *hdr;
 {
   if (hdr->sh_flags & SHF_IA_64_SHORT)
     *flags |= SEC_SMALL_DATA;

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

end of thread, other threads:[~2004-04-27  3:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-23 20:27 PATCH: Pass section name to elf_backend_section_flags H. J. Lu
2004-04-26 12:13 ` Alan Modra
2004-04-26 18:38   ` H. J. Lu
2004-04-27  3:28     ` 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).