]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - bfd/elf.c
elf: Use mmap to map in symbol and relocation tables
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 3 Mar 2024 16:44:01 +0000 (08:44 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 3 Apr 2024 16:11:03 +0000 (09:11 -0700)
commitc6291d749aece753ae8dcba0a5baff2fe9598541
tree27b0044bd8d5574abfd069e7c62ac704f75efe62
parent584b30e4b3538a64d38bc1da9cfa09fc9355378a
elf: Use mmap to map in symbol and relocation tables

Add _bfd_mmap_read_temporary to mmap in symbol tables and relocations
whose sizes >= 4 * page size.  For the final link, allocate an external
relocation buffer of 4 * page size to avoid using mmap and munmap on
smaller relocation sections.  Since _bfd_mmap_read_temporary allocates
buffer as needed, its callers don't need to.

When mmap is used to map in all ELF sections, data to link the 3.5GB
clang executable in LLVM 17 debug build on Linux/x86-64 with 32GB RAM
is:

stdio mmap improvement
user 84.79 85.27 -0.5%
system 10.95 9.09 17%
total 97.91 94.90 3%
page faults 4837944 4033778 17%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build
is:

user 5.31 5.33 -0.4%
system 0.86 0.76 12%
total 6.19 6.13 1%
page faults 361273 322491 11%

* elf.c (bfd_elf_get_elf_syms): Don't allocate buffer for external
symbol table.  Replace bfd_read with _bfd_mmap_read_temporary.
* elflink.c (elf_link_read_relocs_from_section): Add 2 arguments
to return mmap memory address and size.
(_bfd_elf_link_info_read_relocs): Don't allocate buffer for
external relocation information.  Replace bfd_read with
_bfd_mmap_read_temporary.
(bfd_elf_final_link): Cache external relocations up to
_bfd_minimum_mmap_size bytes when mmap is used.
* libbfd.c (_bfd_mmap_read_temporary): New.
* libbfd-in.h (_bfd_mmap_read_temporary): Likewise.
* libbfd.h: Regenerated.
bfd/elf.c
bfd/elflink.c
bfd/libbfd-in.h
bfd/libbfd.c
bfd/libbfd.h