bfd: Grow in-memory BFD buffers geometrically
memory_bwrite and memory_bseek grew the buffer in 128-byte steps, so
building a large in-memory BFD out of many small writes reallocated and
copied the whole buffer repeatedly. This made writing PDB streams
quadratic: linking a 235 MB executable with --pdb spent more than half
of its time in realloc.
Add a separate capacity field and grow the buffer by one eighth of its
capacity, with a minimum increase of 128 bytes. If the over-allocation
fails, retry with the exact required size.
While touching the line, switch a questionable EINVAL to ENOMEM in
memory_bseek().
bfd/
* libbfd-in.h (bfd_in_memory): Add capacity.
* libbfd.h: Regenerate.
* bfdio.c (memory_grow): New function.
(memory_bwrite, memory_bseek): Use it.
* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Initialize capacity.
* coff-bfd.c (import_make_member): Likewise.
* elfcode.h (NAME(_bfd_elf, bfd_from_remote_memory)): Likewise.
* opncls.c (bfd_make_writable): Likewise.
* peicode.h (pe_ILF_build_a_bfd): Likewise.
* xcofflink.c (bfd_xcoff_link_generate_rtinit): Likewise.
8 files changed