This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Make obj_sec_set_private_data into a format_ops member
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