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: elf_gc_sections and relocatable sections


Hi Earl,


The code fragment at elf_gc_sections() is key to resurrecting my
patch with 2.15.91.0.2:

  if (!get_elf_backend_data (abfd)->can_gc_sections
      || info->relocatable
      || info->emitrelocations
      || info->shared
      || !is_elf_hash_table (info->hash))
    {
      (*_bfd_error_handler)(_("Warning: gc-sections option ignored"));
      return TRUE;
    }


Can anyone shed any light as to why elf_gc_sections() cannot
proceed if info->relocatable or info->emitrelocations is set?

I think that for the info->emitrelocations case the theory is that if the user wants the relocations preserved then the linker does not know the exact purpose of the binary that it is creating. Therefore it is better to be paranoid and assume that the user might want the relocations in sections that would otherwise be removed via garbage collection.


As for info->relocatable I believe that you already covered that in your emails with Richard Henderson. The output of a relocatable link can be used as the input for another link, so unless the linker can definitely establish any and all entry points into the files being linked, it cannot determine which sections are unreferenced and hence can be discarded via garbage collection.

Possibly the simplest way around these problems is to add a new command line switch, eg --force-gc-sections which causes the garbage collection operation to happen despite the settings of other switches.

Cheers
  Nick


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