public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] Make obj_sec_set_private_data into a format_ops member
       [not found] <00e801c66c8f$55c9f5e0$a501a8c0@CAM.ARTIMI.COM>
@ 2006-05-02  2:15 ` Alan Modra
  2006-05-02 10:19   ` Dave Korn
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2006-05-02  2:15 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

On Sun, Apr 30, 2006 at 08:50:29PM +0100, Dave Korn wrote:
>   Currently, obj_sec_set_private_data is an object-dependent #define, called
> in subseg_get, and used solely by the elf object format outputter to get the
> ELF bfd new section hook called at the appropriate time.  It is defined in
> obj-elf.h, which begins with this comment:

See http://sources.redhat.com/ml/binutils/2003-07/msg00502.html
I'm going to fix this properly.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* RE: [PATCH] Make obj_sec_set_private_data into a format_ops member
  2006-05-02  2:15 ` [PATCH] Make obj_sec_set_private_data into a format_ops member Alan Modra
@ 2006-05-02 10:19   ` Dave Korn
  2006-05-02 10:37     ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Dave Korn @ 2006-05-02 10:19 UTC (permalink / raw)
  To: 'Alan Modra'; +Cc: binutils

On 02 May 2006 03:15, Alan Modra wrote:

> On Sun, Apr 30, 2006 at 08:50:29PM +0100, Dave Korn wrote:
>>   Currently, obj_sec_set_private_data is an object-dependent #define,
>> called in subseg_get, and used solely by the elf object format outputter
>> to get the ELF bfd new section hook called at the appropriate time.  It is
>> defined in obj-elf.h, which begins with this comment:
> 
> See http://sources.redhat.com/ml/binutils/2003-07/msg00502.html
> I'm going to fix this properly.


  In non-multi-obj builds, all ELF targets call the bfd new section hook, and
all non-ELF targets do not do so.  In multi-obj, all targets call the bfd new
section hook regardless.  This is a discrepancy which should be resolved, and
I suggest that the way to resolve it is by making multi-obj do the same as the
individual non-multi-obj targetted builds would do, which is to call the bfd
new section hook only for ELF format objects and not for non-ELF format
objects.  It's certainly not necessary to call the hook for those other
formats, and indeed is not just superfluous but can also be actually
incorrect; for instance it leads to a null pointer dereference on cygwin.

  My patch preserves existing behaviour in non-multi-obj, fixes incorrect
behaviour in all non-elf multi-obj output, addresses a blocking issue in
getting cygwin multi-obj to work, and makes no odds to any future patch you
intend to produce in this area.  One of my crossbuilds failed and is currently
rerunning but the rest all produced no changes in the testsuite.  (BTW,
perhaps I should add an aout target to the set of crosses?)  I am also
proposing to submit further patches (either individually or en masse) that
would address the following non-multi-obj compatible macros which are
referenced in symbols.c:-

#ifdef obj_frob_label
  obj_frob_label (symbolP);
#endif

#ifdef obj_symbol_clone_hook
  obj_symbol_clone_hook (newsymP, orgsymP);
#endif

#ifdef obj_set_weak_hook
  obj_set_weak_hook (s);
#endif

#ifdef obj_clear_weak_hook
	  obj_clear_weak_hook (s);
#endif

..each of which AFAICT represents an undesirable interdependency between
symbol handling and object format that breaks multi-obj.

  What are your plans in this area?  Can I really not go ahead with these
patches without it interfering with your work?  It makes no difference to me
if I check it in one day and you completely replace it all with whatever
you've been putting together the next, but I would like to make progress with
--enable-targets=all for cygwin and even once the build errors relating to the
pe-coff weak name prefix variable are addressed, there are testsuite
regressions caused by crashes without this patch.  I've done my best to make
it as neutral and conservative as possible, there's no major refactoring going
on; are you sure you object?


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

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

* Re: [PATCH] Make obj_sec_set_private_data into a format_ops member
  2006-05-02 10:19   ` Dave Korn
@ 2006-05-02 10:37     ` Alan Modra
  2006-05-02 10:55       ` Dave Korn
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2006-05-02 10:37 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

On Tue, May 02, 2006 at 11:19:35AM +0100, Dave Korn wrote:
> objects.  It's certainly not necessary to call the hook for those other
> formats, and indeed is not just superfluous but can also be actually
> incorrect; for instance it leads to a null pointer dereference on cygwin.

How?

>   My patch preserves existing behaviour in non-multi-obj, fixes incorrect

Yeah, I know.  Your patch is good, but I'm going to rip out
obj_sec_set_private_data completely.  Here's a preview.  I haven't
finished a regression test yet, so things might need to change.
Especially if I run into your NULL deref.

Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.91
diff -u -p -r1.91 section.c
--- bfd/section.c	16 Mar 2006 12:20:16 -0000	1.91
+++ bfd/section.c	2 May 2006 06:58:14 -0000
@@ -964,7 +964,6 @@ DESCRIPTION
 asection *
 bfd_make_section_old_way (bfd *abfd, const char *name)
 {
-  struct section_hash_entry *sh;
   asection *newsect;
 
   if (abfd->output_has_begun)
@@ -974,30 +973,37 @@ bfd_make_section_old_way (bfd *abfd, con
     }
 
   if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
-    return bfd_abs_section_ptr;
-
-  if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
-    return bfd_com_section_ptr;
-
-  if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
-    return bfd_und_section_ptr;
-
-  if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
-    return bfd_ind_section_ptr;
+    newsect = bfd_abs_section_ptr;
+  else if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
+    newsect = bfd_com_section_ptr;
+  else if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
+    newsect = bfd_und_section_ptr;
+  else if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
+    newsect = bfd_ind_section_ptr;
+  else
+    {
+      struct section_hash_entry *sh;
 
-  sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
-  if (sh == NULL)
-    return NULL;
+      sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
+      if (sh == NULL)
+	return NULL;
 
-  newsect = &sh->section;
-  if (newsect->name != NULL)
-    {
-      /* Section already exists.  */
-      return newsect;
+      newsect = &sh->section;
+      if (newsect->name != NULL)
+	{
+	  /* Section already exists.  */
+	  return newsect;
+	}
+
+      newsect->name = name;
+      return bfd_section_init (abfd, newsect);
     }
 
-  newsect->name = name;
-  return bfd_section_init (abfd, newsect);
+  /* Call new_section_hook when "creating" the standard abs, com, und
+     and ind sections to tack on format specific section data.  */
+  if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
+    return NULL;
+  return newsect;
 }
 
 /*
Index: gas/config/obj-elf.h
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.h,v
retrieving revision 1.28
diff -u -p -r1.28 obj-elf.h
--- gas/config/obj-elf.h	20 Sep 2005 18:24:45 -0000	1.28
+++ gas/config/obj-elf.h	2 May 2006 06:58:20 -0000
@@ -134,13 +134,6 @@ int elf_s_get_other (symbolS *);
 
 extern asection *gdb_section;
 
-#ifndef obj_sec_set_private_data
-#define obj_sec_set_private_data(B, S) \
-  if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \
-    as_fatal (_("can't allocate ELF private section data: %s"),	\
-	      bfd_errmsg (bfd_get_error ()))
-#endif
-
 #ifndef obj_frob_file
 #define obj_frob_file  elf_frob_file
 #endif
Index: gas/subsegs.c
===================================================================
RCS file: /cvs/src/src/gas/subsegs.c,v
retrieving revision 1.28
diff -u -p -r1.28 subsegs.c
--- gas/subsegs.c	1 May 2006 05:41:40 -0000	1.28
+++ gas/subsegs.c	2 May 2006 06:58:18 -0000
@@ -244,10 +174,6 @@ subseg_get (const char *segname, int for
   else
     secptr = bfd_make_section_anyway (stdoutput, segname);
 
-#ifdef obj_sec_set_private_data
-  obj_sec_set_private_data (stdoutput, secptr);
-#endif
-
   seginfo = seg_info (secptr);
   if (! seginfo)
     {


-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* RE: [PATCH] Make obj_sec_set_private_data into a format_ops member
  2006-05-02 10:37     ` Alan Modra
@ 2006-05-02 10:55       ` Dave Korn
  2006-05-02 11:37         ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Dave Korn @ 2006-05-02 10:55 UTC (permalink / raw)
  To: 'Alan Modra'; +Cc: binutils

On 02 May 2006 11:37, Alan Modra wrote:

> On Tue, May 02, 2006 at 11:19:35AM +0100, Dave Korn wrote:
>> objects.  It's certainly not necessary to call the hook for those other
>> formats, and indeed is not just superfluous but can also be actually
>> incorrect; for instance it leads to a null pointer dereference on cygwin.
> 
> How?

  When creating the *ABS* section at startup (and presumably also when
creating the *UND* section, but this one crashes first!) we call subseg_get
which then (because of elf.h's definition of obj_sec_set_private_data) calls
coff_new_section_hook in bfd/coffcode.h, where we run into this line:

  coffsymbol (section->symbol)->native = native;

which dies because there isn't a corresponding combined_entry_type struct to
back the symbol.  You could fairly claim that this is a bfd bug for assuming
the pointer won't be null, or that gas is at fault for not creating a fake
internal symbol to back the fake bfd asymbol, but it's still a function call
that isn't made by the non-multi-obj coff targetted builds and that is made by
the multi-obj builds, and if multi-obj is really /really/ meant to be
behaviour-preserving and backward compatible then it should do the same things
to the same data in order to produce the same output and the simplest way of
guaranteeing that is not to have different function call graphs between the
two cases!

>>   My patch preserves existing behaviour in non-multi-obj, fixes incorrect
> 
> Yeah, I know.  Your patch is good, but I'm going to rip out
> obj_sec_set_private_data completely.  Here's a preview.  I haven't
> finished a regression test yet, so things might need to change.
> Especially if I run into your NULL deref.

  I suspect you may well do so on coff targets; and that leads on to larger
issues of regularising the way in which synthetic symbols (i.e. not backed by
a real target-dependent symbol structure with all the relevant internal data)
can be created, doesn't it?

  BTW, this issue aside, how about making the other macros I mentioned into
format ops?

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

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

* Re: [PATCH] Make obj_sec_set_private_data into a format_ops member
  2006-05-02 10:55       ` Dave Korn
@ 2006-05-02 11:37         ` Alan Modra
  2006-05-02 13:34           ` Dave Korn
  2006-05-03 14:20           ` Delete obj_sec_set_private_data Alan Modra
  0 siblings, 2 replies; 7+ messages in thread
From: Alan Modra @ 2006-05-02 11:37 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

On Tue, May 02, 2006 at 11:55:44AM +0100, Dave Korn wrote:
> On 02 May 2006 11:37, Alan Modra wrote:
> > Especially if I run into your NULL deref.
> 
>   I suspect you may well do so on coff targets;

Indeed, I did.  Fixing by creating new section syms.  Thanks for the
detailed explanation.

> and that leads on to larger
> issues of regularising the way in which synthetic symbols (i.e. not backed by
> a real target-dependent symbol structure with all the relevant internal data)
> can be created, doesn't it?

Yes.  These special sections have always been a pain, more so in the
past when they were const.

>   BTW, this issue aside, how about making the other macros I mentioned into
> format ops?

I think those make sense.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* RE: [PATCH] Make obj_sec_set_private_data into a format_ops member
  2006-05-02 11:37         ` Alan Modra
@ 2006-05-02 13:34           ` Dave Korn
  2006-05-03 14:20           ` Delete obj_sec_set_private_data Alan Modra
  1 sibling, 0 replies; 7+ messages in thread
From: Dave Korn @ 2006-05-02 13:34 UTC (permalink / raw)
  To: 'Alan Modra'; +Cc: binutils

On 02 May 2006 12:38, Alan Modra wrote:

> On Tue, May 02, 2006 at 11:55:44AM +0100, Dave Korn wrote:
>> On 02 May 2006 11:37, Alan Modra wrote:
>>> Especially if I run into your NULL deref.
>> 
>>   I suspect you may well do so on coff targets;
> 
> Indeed, I did.  Fixing by creating new section syms.  Thanks for the
> detailed explanation.

  Rightyo, since you're really that close to checking this in I may as well
wait for it.  Patch withdrawn.
 
>> and that leads on to larger
>> issues of regularising the way in which synthetic symbols (i.e. not backed
>> by a real target-dependent symbol structure with all the relevant internal
>> data) can be created, doesn't it?
> 
> Yes.  These special sections have always been a pain, more so in the
> past when they were const.
> 
>>   BTW, this issue aside, how about making the other macros I mentioned into
>> format ops?
> 
> I think those make sense.

  Would one big patch that adds them all at once be ok, or would you rather
separate patches for each one?  From the point of view of doing thorough
testing (meaning 16 or 20 or even more full builds and testruns taking many
hours and many gigs of diskspace) it would be an awful lot less effort if I
could test them all in one go together!

  BTW I'm currently testing cygwin native, and i386-elf-linux-gnu, arm-elf and
ppc-eabi as crosstargets.  I think maybe I should add an aout target and
perhaps an ecoff target too; do you have any suggestions for which would be
good choices (in terms of what targets are currently actively maintained and
have lots of users)?


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

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

* Delete obj_sec_set_private_data
  2006-05-02 11:37         ` Alan Modra
  2006-05-02 13:34           ` Dave Korn
@ 2006-05-03 14:20           ` Alan Modra
  1 sibling, 0 replies; 7+ messages in thread
From: Alan Modra @ 2006-05-03 14:20 UTC (permalink / raw)
  To: binutils

obj_sec_set_private_data was added a few years ago to add format
specific section data to the standard abs, com, und and ind sections.
While it would be possible for gas to do without the extra section data,
adding it simplifies code in gas, but as Dave Korn found, the place that
the elf_section_data is added isn't ideal.  This patch rids us of
obj_sec_set_private_data by setting up elf_section_data (and other
format specific section data) for gas when "creating" the standard
sections.  We also set up section symbols with the extra format specific
fields too.  That will allow a few more gas simplifications in a
followup patch.

bfd/
	* libbfd-in.h (_bfd_generic_new_section_hook): Declare.
	* section.c (bfd_abs_symbol, bfd_com_symbol): Delete.
	(bfd_und_symbol, bfd_ind_symbol): Delete.
	(BFD_FAKE_SECTION): Remove SYM_PTR param, set symbol_ptr_ptr to
	&SEC.symbol.
	(STD_SECTION): Adjust.
	(_bfd_generic_new_section_hook): New function, extracted from..
	(bfd_section_init): ..here.
	(bfd_make_section_old_way): Call new_section_hook for abs, com,
	und and ind sections.
	* elf.c (_bfd_elf_large_com_section): Adjust.
	* aoutx.h (new_section_hook): Call _bfd_generic_new_section_hook.
	* pdp11.c (new_section_hook): Likewise.
	* coffcode.h (coff_new_section_hook): Likewise.
	* ecoff.c (_bfd_ecoff_new_section_hook): Likewise.
	* elf.c (_bfd_elf_new_section_hook): Likewise.
	* vms.c (vms_new_section_hook): Likwise.
	* elf32-arm.c (elf32_arm_new_section_hook): Check used_by_bfd isn't
	already set.
	* elf32-sh64.c (sh64_elf_new_section_hook): Likewise.
	* elf32-xtensa.c (elf_xtensa_new_section_hook): Likewise.
	* elf64-mmix.c (mmix_elf_new_section_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_new_section_hook): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_new_section_hook): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_new_section_hook): Likewise.
	* ieee.c (ieee_new_section_hook): Likewise.  Call
	_bfd_generic_new_section_hook too.
	* mmo.c (mmo_new_section_hook): Likewise.
	* oasys.c (oasys_new_section_hook): Likewise.
	* som.c (som_new_section_hook): Likewise.
	* coff-w65.c (reloc_processing): Don't use bfd_abs_symbol.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
gas/
	* subsegs.c (subseg_get): Don't call obj_sec_set_private_data.
	* config/obj-elf.h (obj_sec_set_private_data): Delete.
	* config/tc-hppa.c (tc_gen_reloc): Don't use bfd_abs_symbol.
	* config/tc-mn10300.c (tc_gen_reloc): Likewise.

Index: bfd/aoutx.h
===================================================================
RCS file: /cvs/src/src/bfd/aoutx.h,v
retrieving revision 1.60
diff -u -p -r1.60 aoutx.h
--- bfd/aoutx.h	16 Mar 2006 12:20:15 -0000	1.60
+++ bfd/aoutx.h	3 May 2006 06:19:06 -0000
@@ -1193,26 +1193,21 @@ NAME (aout, new_section_hook) (bfd *abfd
 	{
 	  obj_textsec (abfd)= newsect;
 	  newsect->target_index = N_TEXT;
-	  return TRUE;
 	}
-
-      if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
+      else if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
 	{
 	  obj_datasec (abfd) = newsect;
 	  newsect->target_index = N_DATA;
-	  return TRUE;
 	}
-
-      if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
+      else if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
 	{
 	  obj_bsssec (abfd) = newsect;
 	  newsect->target_index = N_BSS;
-	  return TRUE;
 	}
     }
 
   /* We allow more than three sections internally.  */
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 bfd_boolean
Index: bfd/coff-w65.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-w65.c,v
retrieving revision 1.16
diff -u -p -r1.16 coff-w65.c
--- bfd/coff-w65.c	27 Dec 2005 03:06:27 -0000	1.16
+++ bfd/coff-w65.c	3 May 2006 06:19:09 -0000
@@ -1,6 +1,6 @@
 /* BFD back-end for WDC 65816 COFF binaries.
-   Copyright 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
-   Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+   2006 Free Software Foundation, Inc.
    Written by Steve Chamberlain, <sac@cygnus.com>.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -105,7 +105,7 @@ reloc_processing (relent, reloc, symbols
   if (((int) reloc->r_symndx) > 0)
     relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
   else
-    relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol);
+    relent->sym_ptr_ptr = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
 
   relent->addend = reloc->r_offset;
 
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.130
diff -u -p -r1.130 coffcode.h
--- bfd/coffcode.h	25 Oct 2005 17:40:09 -0000	1.130
+++ bfd/coffcode.h	3 May 2006 06:19:12 -0000
@@ -1,6 +1,6 @@
 /* Support for the generic parts of most COFF variants, for BFD.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005
+   2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -1560,6 +1560,10 @@ coff_new_section_hook (bfd * abfd, asect
     section->alignment_power = bfd_xcoff_data_align_power (abfd);
 #endif
 
+  /* Set up the section symbol.  */
+  if (!_bfd_generic_new_section_hook (abfd, section))
+    return FALSE;
+
   /* Allocate aux records for section symbols, to store size and
      related info.
 
Index: bfd/ecoff.c
===================================================================
RCS file: /cvs/src/src/bfd/ecoff.c,v
retrieving revision 1.50
diff -u -p -r1.50 ecoff.c
--- bfd/ecoff.c	16 Mar 2006 12:20:15 -0000	1.50
+++ bfd/ecoff.c	3 May 2006 06:19:16 -0000
@@ -140,8 +140,7 @@ _bfd_ecoff_mkobject_hook (bfd *abfd, voi
 /* Initialize a new section.  */
 
 bfd_boolean
-_bfd_ecoff_new_section_hook (bfd *abfd ATTRIBUTE_UNUSED,
-			     asection *section)
+_bfd_ecoff_new_section_hook (bfd *abfd, asection *section)
 {
   unsigned int i;
   static struct
@@ -181,7 +180,7 @@ _bfd_ecoff_new_section_hook (bfd *abfd A
      uncertain about .init on some systems and I don't know how shared
      libraries work.  */
 
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, section);
 }
 
 /* Determine the machine architecture and type.  This is called from
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.334
diff -u -p -r1.334 elf.c
--- bfd/elf.c	2 May 2006 10:01:56 -0000	1.334
+++ bfd/elf.c	3 May 2006 06:19:20 -0000
@@ -2502,7 +2502,7 @@ _bfd_elf_new_section_hook (bfd *abfd, as
 	}
     }
 
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, sec);
 }
 
 /* Create a new bfd section from an ELF program header.
@@ -8760,8 +8760,7 @@ done:
 /* It is only used by x86-64 so far.  */
 asection _bfd_elf_large_com_section
   = BFD_FAKE_SECTION (_bfd_elf_large_com_section,
-		      SEC_IS_COMMON, NULL, NULL, "LARGE_COMMON",
-		      0);
+		      SEC_IS_COMMON, NULL, "LARGE_COMMON", 0);
 
 /* Return TRUE if 2 section types are compatible.  */
 
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.72
diff -u -p -r1.72 elf32-arm.c
--- bfd/elf32-arm.c	2 May 2006 13:09:17 -0000	1.72
+++ bfd/elf32-arm.c	3 May 2006 06:19:24 -0000
@@ -7822,13 +7822,16 @@ elf32_arm_output_symbol_hook (struct bfd
 static bfd_boolean
 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
 {
-  _arm_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      _arm_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   record_section_with_arm_elf_section_data (sec);
 
Index: bfd/elf32-sh64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh64.c,v
retrieving revision 1.37
diff -u -p -r1.37 elf32-sh64.c
--- bfd/elf32-sh64.c	8 Jul 2005 00:26:45 -0000	1.37
+++ bfd/elf32-sh64.c	3 May 2006 06:19:25 -0000
@@ -1,5 +1,5 @@
 /* SuperH SH64-specific support for 32-bit ELF
-   Copyright 2000, 2001, 2002, 2003, 2004, 2005
+   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -115,13 +115,16 @@ static void sh64_find_section_for_addres
 static bfd_boolean
 sh64_elf_new_section_hook (bfd *abfd, asection *sec)
 {
-  struct _sh64_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct _sh64_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = (struct _sh64_elf_section_data *) bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
Index: bfd/elf32-xtensa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v
retrieving revision 1.64
diff -u -p -r1.64 elf32-xtensa.c
--- bfd/elf32-xtensa.c	14 Apr 2006 23:01:19 -0000	1.64
+++ bfd/elf32-xtensa.c	3 May 2006 06:19:30 -0000
@@ -1,5 +1,5 @@
 /* Xtensa-specific support for 32-bit ELF.
-   Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -5007,13 +5007,16 @@ struct elf_xtensa_section_data
 static bfd_boolean
 elf_xtensa_new_section_hook (bfd *abfd, asection *sec)
 {
-  struct elf_xtensa_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct elf_xtensa_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = (struct elf_xtensa_section_data *) bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = (void *) sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
Index: bfd/elf64-mmix.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-mmix.c,v
retrieving revision 1.47
diff -u -p -r1.47 elf64-mmix.c
--- bfd/elf64-mmix.c	17 Aug 2005 13:29:55 -0000	1.47
+++ bfd/elf64-mmix.c	3 May 2006 06:19:31 -0000
@@ -1,5 +1,6 @@
 /* MMIX-specific support for 64-bit ELF.
-   Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
    Contributed by Hans-Peter Nilsson <hp@bitrange.com>
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -860,13 +861,16 @@ mmix_elf_new_section_hook (abfd, sec)
      bfd *abfd;
      asection *sec;
 {
-  struct _mmix_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct _mmix_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = (struct _mmix_elf_section_data *) bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = (PTR) sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.235
diff -u -p -r1.235 elf64-ppc.c
--- bfd/elf64-ppc.c	16 Mar 2006 12:20:15 -0000	1.235
+++ bfd/elf64-ppc.c	3 May 2006 06:19:36 -0000
@@ -2550,13 +2550,16 @@ struct _ppc64_elf_section_data
 static bfd_boolean
 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
 {
-  struct _ppc64_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct _ppc64_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.166
diff -u -p -r1.166 elfxx-mips.c
--- bfd/elfxx-mips.c	2 May 2006 10:01:56 -0000	1.166
+++ bfd/elfxx-mips.c	3 May 2006 06:19:43 -0000
@@ -826,13 +826,16 @@ mips_elf_link_hash_newfunc (struct bfd_h
 bfd_boolean
 _bfd_mips_elf_new_section_hook (bfd *abfd, asection *sec)
 {
-  struct _mips_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct _mips_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.21
diff -u -p -r1.21 elfxx-sparc.c
--- bfd/elfxx-sparc.c	5 Apr 2006 12:41:57 -0000	1.21
+++ bfd/elfxx-sparc.c	3 May 2006 06:19:45 -0000
@@ -2434,13 +2434,16 @@ _bfd_sparc_elf_size_dynamic_sections (bf
 bfd_boolean
 _bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
 {
-  struct _bfd_sparc_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct _bfd_sparc_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = (struct _bfd_sparc_elf_section_data *) bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = (PTR) sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+	return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
Index: bfd/ieee.c
===================================================================
RCS file: /cvs/src/src/bfd/ieee.c,v
retrieving revision 1.53
diff -u -p -r1.53 ieee.c
--- bfd/ieee.c	6 Mar 2006 13:42:03 -0000	1.53
+++ bfd/ieee.c	3 May 2006 06:19:47 -0000
@@ -2014,12 +2014,15 @@ ieee_print_symbol (bfd *abfd,
 static bfd_boolean
 ieee_new_section_hook (bfd *abfd, asection *newsect)
 {
-  newsect->used_by_bfd = bfd_alloc (abfd, (bfd_size_type) sizeof (ieee_per_section_type));
   if (!newsect->used_by_bfd)
-    return FALSE;
+    {
+      newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type));
+      if (!newsect->used_by_bfd)
+	return FALSE;
+    }
   ieee_per_section (newsect)->data = NULL;
   ieee_per_section (newsect)->section = newsect;
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 static long
Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.64
diff -u -p -r1.64 libbfd-in.h
--- bfd/libbfd-in.h	25 Apr 2006 17:46:15 -0000	1.64
+++ bfd/libbfd-in.h	3 May 2006 06:19:47 -0000
@@ -217,8 +217,8 @@ int bfd_generic_stat_arch_elt
 
 #define _bfd_generic_close_and_cleanup bfd_true
 #define _bfd_generic_bfd_free_cached_info bfd_true
-#define _bfd_generic_new_section_hook \
-  ((bfd_boolean (*) (bfd *, asection *)) bfd_true)
+extern bfd_boolean _bfd_generic_new_section_hook
+  (bfd *, asection *);
 extern bfd_boolean _bfd_generic_get_section_contents
   (bfd *, asection *, void *, file_ptr, bfd_size_type);
 extern bfd_boolean _bfd_generic_get_section_contents_in_window
Index: bfd/mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.29
diff -u -p -r1.29 mmo.c
--- bfd/mmo.c	17 Aug 2005 13:29:55 -0000	1.29
+++ bfd/mmo.c	3 May 2006 06:19:50 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for mmo objects (MMIX-specific object-format).
-   Copyright 2001, 2002, 2003, 2004, 2005
+   Copyright 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
    Written by Hans-Peter Nilsson (hp@bitrange.com).
    Infrastructure and other bits originally copied from srec.c and
@@ -2007,19 +2007,21 @@ mmo_scan (bfd *abfd)
    we point out the shape of allocated section contents.  */
 
 static bfd_boolean
-mmo_new_section_hook (bfd *abfd ATTRIBUTE_UNUSED, asection *newsect)
+mmo_new_section_hook (bfd *abfd, asection *newsect)
 {
-  /* We zero-fill all fields and assume NULL is represented by an all
-     zero-bit pattern.  */
-  newsect->used_by_bfd =
-    bfd_zalloc (abfd, sizeof (struct mmo_section_data_struct));
-
   if (!newsect->used_by_bfd)
-    return FALSE;
+    {
+      /* We zero-fill all fields and assume NULL is represented by an all
+	 zero-bit pattern.  */
+      newsect->used_by_bfd
+	= bfd_zalloc (abfd, sizeof (struct mmo_section_data_struct));
+      if (!newsect->used_by_bfd)
+	return FALSE;
+    }
 
   /* Always align to at least 32-bit words.  */
   newsect->alignment_power = 2;
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 /* We already have section contents loaded for sections that have
Index: bfd/oasys.c
===================================================================
RCS file: /cvs/src/src/bfd/oasys.c,v
retrieving revision 1.33
diff -u -p -r1.33 oasys.c
--- bfd/oasys.c	6 Oct 2005 19:21:14 -0000	1.33
+++ bfd/oasys.c	3 May 2006 06:19:50 -0000
@@ -1,6 +1,6 @@
 /* BFD back-end for oasys objects.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001,
-   2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support, <sac@cygnus.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -685,9 +685,13 @@ oasys_print_symbol (bfd *abfd, void * af
 static bfd_boolean
 oasys_new_section_hook (bfd *abfd, asection *newsect)
 {
-  newsect->used_by_bfd = bfd_alloc (abfd, (bfd_size_type) sizeof (oasys_per_section_type));
   if (!newsect->used_by_bfd)
-    return FALSE;
+    {
+      newsect->used_by_bfd
+	= bfd_alloc (abfd, (bfd_size_type) sizeof (oasys_per_section_type));
+      if (!newsect->used_by_bfd)
+	return FALSE;
+    }
   oasys_per_section (newsect)->data = NULL;
   oasys_per_section (newsect)->section = newsect;
   oasys_per_section (newsect)->offset = 0;
@@ -697,7 +701,7 @@ oasys_new_section_hook (bfd *abfd, asect
   /* Turn the section string into an index.  */
   sscanf (newsect->name, "%u", &newsect->target_index);
 
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 
Index: bfd/pdp11.c
===================================================================
RCS file: /cvs/src/src/bfd/pdp11.c,v
retrieving revision 1.34
diff -u -p -r1.34 pdp11.c
--- bfd/pdp11.c	16 Mar 2006 12:20:16 -0000	1.34
+++ bfd/pdp11.c	3 May 2006 06:19:53 -0000
@@ -1111,32 +1111,27 @@ NAME (aout, new_section_hook) (bfd *abfd
   if (bfd_get_format (abfd) == bfd_object)
     {
       if (obj_textsec (abfd) == NULL
-	  && ! strcmp (newsect->name, ".text"))
+	  && !strcmp (newsect->name, ".text"))
 	{
 	  obj_textsec(abfd)= newsect;
 	  newsect->target_index = N_TEXT;
-	  return TRUE;
 	}
-
-    if (obj_datasec (abfd) == NULL
-	&& ! strcmp (newsect->name, ".data"))
-      {
-	obj_datasec (abfd) = newsect;
-	newsect->target_index = N_DATA;
-	return TRUE;
-      }
-
-    if (obj_bsssec (abfd) == NULL
-	&& !strcmp (newsect->name, ".bss"))
-      {
-	obj_bsssec (abfd) = newsect;
-	newsect->target_index = N_BSS;
-	return TRUE;
-      }
-  }
+      else if (obj_datasec (abfd) == NULL
+	       && !strcmp (newsect->name, ".data"))
+	{
+	  obj_datasec (abfd) = newsect;
+	  newsect->target_index = N_DATA;
+	}
+      else if (obj_bsssec (abfd) == NULL
+	       && !strcmp (newsect->name, ".bss"))
+	{
+	  obj_bsssec (abfd) = newsect;
+	  newsect->target_index = N_BSS;
+	}
+    }
 
   /* We allow more than three sections internally.  */
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 bfd_boolean
Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.91
diff -u -p -r1.91 section.c
--- bfd/section.c	16 Mar 2006 12:20:16 -0000	1.91
+++ bfd/section.c	3 May 2006 06:19:54 -0000
@@ -540,11 +540,6 @@ CODE_FRAGMENT
 .  || ((SEC) == bfd_com_section_ptr)		\
 .  || ((SEC) == bfd_ind_section_ptr))
 .
-.extern const struct bfd_symbol * const bfd_abs_symbol;
-.extern const struct bfd_symbol * const bfd_com_symbol;
-.extern const struct bfd_symbol * const bfd_und_symbol;
-.extern const struct bfd_symbol * const bfd_ind_symbol;
-.
 .{* Macros to handle insertion and deletion of a bfd's sections.  These
 .   only handle the list pointers, ie. do not adjust section_count,
 .   target_index etc.  *}
@@ -635,7 +630,7 @@ CODE_FRAGMENT
 .#define bfd_section_removed_from_list(ABFD, S) \
 .  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
 .
-.#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, SYM_PTR, NAME, IDX)		\
+.#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX)			\
 .  {* name, id,  index, next, prev, flags, user_set_vma,            *}	\
 .  { NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,				\
 .									\
@@ -666,11 +661,8 @@ CODE_FRAGMENT
 .  {* target_index, used_by_bfd, constructor_chain, owner,          *}	\
 .     0,            NULL,        NULL,              NULL,		\
 .									\
-.  {* symbol,                                                       *}	\
-.     (struct bfd_symbol *) SYM,					\
-.									\
-.  {* symbol_ptr_ptr,                                               *}	\
-.     (struct bfd_symbol **) SYM_PTR,					\
+.  {* symbol,                    symbol_ptr_ptr,                    *}	\
+.     (struct bfd_symbol *) SYM, &SEC.symbol,				\
 .									\
 .  {* map_head, map_tail                                            *}	\
 .     { NULL }, { NULL }						\
@@ -701,16 +693,14 @@ static const asymbol global_syms[] =
   GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, &bfd_ind_section)
 };
 
-#define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX)				\
-  const asymbol * const SYM = (asymbol *) &global_syms[IDX]; 		\
-  asection SEC = BFD_FAKE_SECTION(SEC, FLAGS, &global_syms[IDX], &SYM,	\
+#define STD_SECTION(SEC, FLAGS, NAME, IDX)				\
+  asection SEC = BFD_FAKE_SECTION(SEC, FLAGS, &global_syms[IDX],	\
 				  NAME, IDX)
 
-STD_SECTION (bfd_com_section, SEC_IS_COMMON, bfd_com_symbol,
-	     BFD_COM_SECTION_NAME, 0);
-STD_SECTION (bfd_und_section, 0, bfd_und_symbol, BFD_UND_SECTION_NAME, 1);
-STD_SECTION (bfd_abs_section, 0, bfd_abs_symbol, BFD_ABS_SECTION_NAME, 2);
-STD_SECTION (bfd_ind_section, 0, bfd_ind_symbol, BFD_IND_SECTION_NAME, 3);
+STD_SECTION (bfd_com_section, SEC_IS_COMMON, BFD_COM_SECTION_NAME, 0);
+STD_SECTION (bfd_und_section, 0, BFD_UND_SECTION_NAME, 1);
+STD_SECTION (bfd_abs_section, 0, BFD_ABS_SECTION_NAME, 2);
+STD_SECTION (bfd_ind_section, 0, BFD_IND_SECTION_NAME, 3);
 #undef STD_SECTION
 
 /* Initialize an entry in the section hash table.  */
@@ -743,23 +733,16 @@ bfd_section_hash_newfunc (struct bfd_has
   ((struct section_hash_entry *) \
    bfd_hash_lookup ((table), (string), (create), (copy)))
 
-/* Initializes a new section.  NEWSECT->NAME is already set.  */
+/* Create a symbol whose only job is to point to this section.  This
+   is useful for things like relocs which are relative to the base
+   of a section.  */
 
-static asection *
-bfd_section_init (bfd *abfd, asection *newsect)
+bfd_boolean
+_bfd_generic_new_section_hook (bfd *abfd, asection *newsect)
 {
-  static int section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */
-
-  newsect->id = section_id;
-  newsect->index = abfd->section_count;
-  newsect->owner = abfd;
-
-  /* Create a symbol whose only job is to point to this section.  This
-     is useful for things like relocs which are relative to the base
-     of a section.  */
   newsect->symbol = bfd_make_empty_symbol (abfd);
   if (newsect->symbol == NULL)
-    return NULL;
+    return FALSE;
 
   newsect->symbol->name = newsect->name;
   newsect->symbol->value = 0;
@@ -767,6 +750,19 @@ bfd_section_init (bfd *abfd, asection *n
   newsect->symbol->flags = BSF_SECTION_SYM;
 
   newsect->symbol_ptr_ptr = &newsect->symbol;
+  return TRUE;
+}
+
+/* Initializes a new section.  NEWSECT->NAME is already set.  */
+
+static asection *
+bfd_section_init (bfd *abfd, asection *newsect)
+{
+  static int section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */
+
+  newsect->id = section_id;
+  newsect->index = abfd->section_count;
+  newsect->owner = abfd;
 
   if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
     return NULL;
@@ -964,7 +960,6 @@ DESCRIPTION
 asection *
 bfd_make_section_old_way (bfd *abfd, const char *name)
 {
-  struct section_hash_entry *sh;
   asection *newsect;
 
   if (abfd->output_has_begun)
@@ -974,30 +969,38 @@ bfd_make_section_old_way (bfd *abfd, con
     }
 
   if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
-    return bfd_abs_section_ptr;
-
-  if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
-    return bfd_com_section_ptr;
-
-  if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
-    return bfd_und_section_ptr;
-
-  if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
-    return bfd_ind_section_ptr;
+    newsect = bfd_abs_section_ptr;
+  else if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
+    newsect = bfd_com_section_ptr;
+  else if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
+    newsect = bfd_und_section_ptr;
+  else if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
+    newsect = bfd_ind_section_ptr;
+  else
+    {
+      struct section_hash_entry *sh;
 
-  sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
-  if (sh == NULL)
-    return NULL;
+      sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
+      if (sh == NULL)
+	return NULL;
 
-  newsect = &sh->section;
-  if (newsect->name != NULL)
-    {
-      /* Section already exists.  */
-      return newsect;
+      newsect = &sh->section;
+      if (newsect->name != NULL)
+	{
+	  /* Section already exists.  */
+	  return newsect;
+	}
+
+      newsect->name = name;
+      return bfd_section_init (abfd, newsect);
     }
 
-  newsect->name = name;
-  return bfd_section_init (abfd, newsect);
+  /* Call new_section_hook when "creating" the standard abs, com, und
+     and ind sections to tack on format specific section data.
+     Also, create a proper section symbol.  */
+  if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
+    return NULL;
+  return newsect;
 }
 
 /*
Index: bfd/som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.59
diff -u -p -r1.59 som.c
--- bfd/som.c	20 Nov 2005 19:21:06 -0000	1.59
+++ bfd/som.c	3 May 2006 06:19:57 -0000
@@ -1,6 +1,6 @@
 /* bfd back-end for HP PA-RISC SOM objects.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005
+   2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
    Contributed by the Center for Software Science at the
@@ -4959,15 +4959,18 @@ extern const bfd_target som_vec;
 static bfd_boolean
 som_new_section_hook (bfd *abfd, asection *newsect)
 {
-  bfd_size_type amt = sizeof (struct som_section_data_struct);
-
-  newsect->used_by_bfd = bfd_zalloc (abfd, amt);
   if (!newsect->used_by_bfd)
-    return FALSE;
+    {
+      bfd_size_type amt = sizeof (struct som_section_data_struct);
+
+      newsect->used_by_bfd = bfd_zalloc (abfd, amt);
+      if (!newsect->used_by_bfd)
+	return FALSE;
+    }
   newsect->alignment_power = 3;
 
   /* We allow more than three sections internally.  */
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 /* Copy any private info we understand from the input symbol
Index: bfd/vms.c
===================================================================
RCS file: /cvs/src/src/bfd/vms.c,v
retrieving revision 1.38
diff -u -p -r1.38 vms.c
--- bfd/vms.c	16 Mar 2006 12:20:16 -0000	1.38
+++ bfd/vms.c	3 May 2006 06:19:58 -0000
@@ -487,7 +487,7 @@ vms_new_section_hook (bfd * abfd, asecti
   vms_debug (7, "%d: %s\n", section->index, section->name);
 #endif
 
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, section);
 }
 
 /* Read the contents of a section.
Index: gas/subsegs.c
===================================================================
RCS file: /cvs/src/src/gas/subsegs.c,v
retrieving revision 1.28
diff -u -p -r1.28 subsegs.c
--- gas/subsegs.c	1 May 2006 05:41:40 -0000	1.28
+++ gas/subsegs.c	3 May 2006 06:20:04 -0000
@@ -1,6 +1,6 @@
 /* subsegs.c - subsegments -
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -244,10 +166,6 @@ subseg_get (const char *segname, int for
   else
     secptr = bfd_make_section_anyway (stdoutput, segname);
 
-#ifdef obj_sec_set_private_data
-  obj_sec_set_private_data (stdoutput, secptr);
-#endif
-
   seginfo = seg_info (secptr);
   if (! seginfo)
     {
Index: gas/config/obj-elf.h
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.h,v
retrieving revision 1.29
diff -u -p -r1.29 obj-elf.h
--- gas/config/obj-elf.h	2 May 2006 04:21:39 -0000	1.29
+++ gas/config/obj-elf.h	3 May 2006 06:20:05 -0000
@@ -134,13 +134,6 @@ int elf_s_get_other (symbolS *);
 
 extern asection *gdb_section;
 
-#ifndef obj_sec_set_private_data
-#define obj_sec_set_private_data(B, S) \
-  if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \
-    as_fatal (_("can't allocate ELF private section data: %s"),	\
-	      bfd_errmsg (bfd_get_error ()))
-#endif
-
 #ifndef obj_frob_file
 #define obj_frob_file  elf_frob_file
 #endif
Index: gas/config/tc-hppa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.c,v
retrieving revision 1.129
diff -u -p -r1.129 tc-hppa.c
--- gas/config/tc-hppa.c	25 Nov 2005 02:08:22 -0000	1.129
+++ gas/config/tc-hppa.c	3 May 2006 06:20:09 -0000
@@ -1,6 +1,6 @@
 /* tc-hppa.c -- Assemble for the PA
    Copyright 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -4196,36 +4196,39 @@ tc_gen_reloc (section, fixp)
 	     of two symbols.  With that in mind we fill in all four
 	     relocs now and break out of the loop.  */
 	  assert (i == 1);
-	  relocs[0]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
-	  relocs[0]->howto =
-	    bfd_reloc_type_lookup (stdoutput,
-				   (bfd_reloc_code_real_type) *codes[0]);
+	  relocs[0]->sym_ptr_ptr
+	    = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
+	  relocs[0]->howto
+	    = bfd_reloc_type_lookup (stdoutput,
+				     (bfd_reloc_code_real_type) *codes[0]);
 	  relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
 	  relocs[0]->addend = 0;
 	  relocs[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
 	  *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
-	  relocs[1]->howto =
-	    bfd_reloc_type_lookup (stdoutput,
-				   (bfd_reloc_code_real_type) *codes[1]);
+	  relocs[1]->howto
+	    = bfd_reloc_type_lookup (stdoutput,
+				     (bfd_reloc_code_real_type) *codes[1]);
 	  relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
 	  relocs[1]->addend = 0;
 	  relocs[2]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
 	  *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
-	  relocs[2]->howto =
-	    bfd_reloc_type_lookup (stdoutput,
-				   (bfd_reloc_code_real_type) *codes[2]);
+	  relocs[2]->howto
+	    = bfd_reloc_type_lookup (stdoutput,
+				     (bfd_reloc_code_real_type) *codes[2]);
 	  relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
 	  relocs[2]->addend = 0;
-	  relocs[3]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
-	  relocs[3]->howto =
-	    bfd_reloc_type_lookup (stdoutput,
-				   (bfd_reloc_code_real_type) *codes[3]);
+	  relocs[3]->sym_ptr_ptr
+	    = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
+	  relocs[3]->howto
+	    = bfd_reloc_type_lookup (stdoutput,
+				     (bfd_reloc_code_real_type) *codes[3]);
 	  relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
 	  relocs[3]->addend = 0;
-	  relocs[4]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
-	  relocs[4]->howto =
-	    bfd_reloc_type_lookup (stdoutput,
-				   (bfd_reloc_code_real_type) *codes[4]);
+	  relocs[4]->sym_ptr_ptr
+	    = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
+	  relocs[4]->howto
+	    = bfd_reloc_type_lookup (stdoutput,
+				     (bfd_reloc_code_real_type) *codes[4]);
 	  relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
 	  relocs[4]->addend = 0;
 	  goto done;
Index: gas/config/tc-mn10300.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mn10300.c,v
retrieving revision 1.55
diff -u -p -r1.55 tc-mn10300.c
--- gas/config/tc-mn10300.c	11 Jan 2006 17:39:49 -0000	1.55
+++ gas/config/tc-mn10300.c	3 May 2006 06:20:10 -0000
@@ -2407,7 +2407,8 @@ tc_gen_reloc (seg, fixp)
 	      break;
 
 	    default:
-	      reloc->sym_ptr_ptr = (asymbol **) &bfd_abs_symbol;
+	      reloc->sym_ptr_ptr
+		= (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
 	      return reloc;
 	    }
 	}

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

end of thread, other threads:[~2006-05-03 14:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <00e801c66c8f$55c9f5e0$a501a8c0@CAM.ARTIMI.COM>
2006-05-02  2:15 ` [PATCH] Make obj_sec_set_private_data into a format_ops member Alan Modra
2006-05-02 10:19   ` Dave Korn
2006-05-02 10:37     ` Alan Modra
2006-05-02 10:55       ` Dave Korn
2006-05-02 11:37         ` Alan Modra
2006-05-02 13:34           ` Dave Korn
2006-05-03 14:20           ` Delete obj_sec_set_private_data 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).