public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* memory usage with large debug sections
@ 2006-04-05  2:03 Kevin Nomura
  2006-04-10 17:10 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Nomura @ 2006-04-05  2:03 UTC (permalink / raw)
  To: binutils

Using 2.16.1.  I have a partially linked object ('file1') with a 
debug section ~600MB in size, and am trying to reduce the
memory taken by this:

	ld -Ur -o file2 file1

The debug section has the SEC_RELOC flag, so it causes 1.2 GB of
malloc in bfd_elf_final_link() here:

  if (max_external_reloc_size != 0)
    {
      finfo.external_relocs = bfd_malloc (max_external_reloc_size);
      if (finfo.external_relocs == NULL)
	goto error_return;
    }

  if (max_internal_reloc_count != 0)
    {
      amt = max_internal_reloc_count * bed->s->int_rels_per_ext_rel;
      amt *= sizeof (Elf_Internal_Rela);
      finfo.internal_relocs = bfd_malloc (amt);
      if (finfo.internal_relocs == NULL)
	goto error_return;
    }

These are where the sizes are set:

if ((sec->flags & SEC_RELOC) != 0)
{
	size_t ext_size;

	ext_size = elf_section_data (sec)->rel_hdr.sh_size;
	if (ext_size > max_external_reloc_size)
	max_external_reloc_size = ext_size;
	if (sec->reloc_count > max_internal_reloc_count)
	max_internal_reloc_count = sec->reloc_count;
}

Is it really the case that the size of a debug section has
to be used to calculate the malloc size for these relocation
structures?

Kevin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: memory usage with large debug sections
  2006-04-05  2:03 memory usage with large debug sections Kevin Nomura
@ 2006-04-10 17:10 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2006-04-10 17:10 UTC (permalink / raw)
  To: Kevin Nomura; +Cc: binutils

Hi Kevin,

> if ((sec->flags & SEC_RELOC) != 0)
> {
> 	size_t ext_size;
> 
> 	ext_size = elf_section_data (sec)->rel_hdr.sh_size;
> 	if (ext_size > max_external_reloc_size)
> 	max_external_reloc_size = ext_size;
> 	if (sec->reloc_count > max_internal_reloc_count)
> 	max_internal_reloc_count = sec->reloc_count;
> }
> 
> Is it really the case that the size of a debug section has
> to be used to calculate the malloc size for these relocation
> structures?

No, but this size is guaranteed to be safe - there can never be more 
relocs in a debug section than if the entire section held relocs and 
nothing else.

If you would like to try to improve this code you could write a function 
to count the number of relocs in the debug section and then use this 
figure in the malloc.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-04-10 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-05  2:03 memory usage with large debug sections Kevin Nomura
2006-04-10 17:10 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).