This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add bfd_get_section_by_name_if


On Fri, Apr 30, 2004 at 10:44:10AM -0700, H. J. Lu wrote:
> +DESCRIPTION
> +	Call the provided function @var{func} for each section
> +	attached to the BFD @var{abfd} whose name matches @var{name},
[snip]

> +  sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
> +  for (; sh != NULL; sh = (struct section_hash_entry *) sh->root.next)
> +    if ((*operation) (abfd, &sh->section, user_storage))
> +      break;

This doesn't work as advertised.  sh->root.next chains entries with the
same *index*, not necessarily the same string or even the same hash.

  sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
  if (sh == NULL)
    return NULL;
  hash = sh->root.hash;
  do
    {
      if ((*operation) (abfd, &sh->section, user_storage))
	return &sh->section;
      sh = (struct section_hash_entry *) sh->root.next;
    }
  while (sh != NULL && sh->root.hash == hash
	 && strcmp (sh->root.string, name) == 0);
  return NULL;

OK with the above change, assuming it compiles. ;-)

Oh, and I see I made an error in my bfd_make_section_anyway change.

	* section.c (bfd_make_section_anyway): Copy the whole
	bfd_hash_entry, not just "next" from existing entry.

Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.69
diff -u -p -r1.69 section.c
--- bfd/section.c	30 Apr 2004 15:01:15 -0000	1.69
+++ bfd/section.c	1 May 2004 14:12:08 -0000
@@ -955,7 +955,7 @@ bfd_make_section_anyway (bfd *abfd, cons
       if (new_sh == NULL)
 	return NULL;
 
-      new_sh->root.next = sh->root.next;
+      new_sh->root = sh->root;
       sh->root.next = &new_sh->root;
       newsect = &new_sh->section;
     }

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]