[David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections

David Mosberger davidm@napali.hpl.hp.com
Sat Mar 2 09:24:00 GMT 2002


>>>>> On Sat, 2 Mar 2002 20:49:31 +1030, Alan Modra <amodra@bigpond.net.au> said:

  Alan> On Sat, Mar 02, 2002 at 12:36:45AM -0800, H . J . Lu wrote:
  >>  .init_array, .fini_array and .preinit_array are new special
  >> sections.  We need to make sure their types and attributes are
  >> correct. Here is a patch.

  Alan> I like this, but there is a mistake in the following

  >> @@ -3370,18 +3371,27 @@ NAME(bfd_elf,size_dynamic_sections) (out
  >> return false; }
  >> 
  >> - for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
  >> - for (o = sub->sections; o != NULL; o = o->next) - { - /* yuck,
  >> more matching by name... */
  >> -
  >> - if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
  >> + for (sub = info->input_bfds; sub != NULL && initfini_array !=
  >> 3; + sub = sub->link_next) + for (o = sub->sections; o != NULL &&
  >> initfini_array != 3; + o = o->next) + switch (elf_section_data
  >> (o->output_section)->this_hdr.sh_type) + { + case
  >> SHT_PREINIT_ARRAY: need_preinit_array = 1; - if (strcmp
  >> (bfd_section_name (sub, o), ".init_array") == 0) +
  >> initfini_array++;

  Alan> Presumably, initfini_array is trying to cut short the section
  Alan> search after finding one of each of the section types.  I
  Alan> can't see anything in the ELF spec that precludes having, say,
  Alan> three SHT_PREINIT_ARRAY input sections.  Best get rid of
  Alan> initfini_array entirely.

The loop really only needs to determine whether any _input_ sections
contain the preinit/init/fini arrays.  You could use a bitmask and
stop the search as soon as all three array sections have occurred at
least once.

I considered doing that but opted not to do so for clarity and because
I wasn't sure how often preinit arrays will be used: if it turns out
that most executables do not use preinit arrays, then the optimization
won't be very useful.

  Alan> The other thing is that you'll need to extend your patch a
  Alan> little to handle these section types in bfd_section_from_shdr.

Also, note that elfxx-ia64.c already has code to set the section
types.  It's good if this can be moved to elf.c, but there is no point
in keeping two copies of this code.

	--david



More information about the Binutils mailing list