This is the mail archive of the binutils@sourceware.org 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: PR ld/12851: --gc-sections doesn't work on note sections


On Wed, Jun 8, 2011 at 5:25 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Jun 09, 2011 at 09:22:26AM +0930, Alan Modra wrote:
>> On Wed, Jun 08, 2011 at 01:10:14PM -0700, H.J. Lu wrote:
>> > SHT_NOTE sections are special. ?We check it in elf_gc_sweep. ?But
>> > we missed it in bfd_elf_gc_sections.
>>
>> I think your patch is going in the wrong directions. ?If we missed
>> anything in bfd_elf_gc_sections, it's that we keep note sections in
>> files for which all other sections are discarded.
>
> Actually, I think that
>
> ? ? ? ? ?else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
> ? ? ? ? ? ? ? ? ? || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0
> ? ? ? ? ? ? ? ? ? || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE)
> ? ? ? ? ? ?{
> ? ? ? ? ? ? ?/* Keep debug, special and SHT_NOTE sections. ?*/
> ? ? ? ? ? ? ?o->gc_mark = 1;
> ? ? ? ? ? ?}
>
> doesn't belong in elf_gc_sweep at all. ?It would be better to put code
> marking these sections in a default gc_mark_extra_sections.
>

To keep SHT_NOTE sections, we need to keep sections referenced
by SHT_NOTE sections. But

 /* Grovel through relocs to find out who stays ...  */
  gc_mark_hook = bed->gc_mark_hook;
  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    {
      asection *o;

      if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
        continue;

      for (o = sub->sections; o != NULL; o = o->next)
        if ((o->flags & (SEC_EXCLUDE | SEC_KEEP)) == SEC_KEEP && !o->gc_mark)
          if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
            return FALSE;
    }

doesn't check relocations in SHT_NOTE sections.  I don't know
how default gc_mark_extra_sections can fix.  Also when I add
debug and special sections, I get linker regressions.  It seems
that we want to keep debug and special sections, but not sections
referenced by them.

-- 
H.J.


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