[PATCH] x86-64: Allocate input section memory if needed

H.J. Lu hjl.tools@gmail.com
Wed Dec 28 17:23:21 GMT 2022
On Tue, Dec 27, 2022 at 5:16 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Dec 27, 2022 at 11:47:56AM -0800, H.J. Lu via Binutils wrote:
> > +                       /* Cache the section contents for
> > +                          elf_link_input_bfd.  */
> > +                       elf_section_data (sec)->this_hdr.contents
> > +                         = contents;
>
> You shouldn't really be caching unaltered section contents when
> !info->keep_memory.  I'm not saying the patch is wrong, but please fix
> this when you have some time.
>
> --
> Alan Modra
> Australia Development Lab, IBM

elf_x86_64_scan_relocs has

  if (elf_section_data (sec)->this_hdr.contents != contents)
    {
      if (!converted && !_bfd_link_keep_memory (info))
        free (contents);
      else
        {
          /* Cache the section contents for elf_link_input_bfd if any
             load is converted or --no-keep-memory isn't used.  */
          elf_section_data (sec)->this_hdr.contents = contents;
          info->cache_size += sec->size;
        }
    }

Are you suggesting that it should be

  if (elf_section_data (sec)->this_hdr.contents != contents)
    {
      if (!converted)
        free (contents);
      else
        {
          /* Cache the section contents for elf_link_input_bfd if any
             load is converted.  */
          elf_section_data (sec)->this_hdr.contents = contents;
          info->cache_size += sec->size;
        }
    }

Thanks.

--
H.J.


More information about the Binutils mailing list