Age | Commit message (Collapse) | Author | Files | Lines |
|
applies to allocated sections, and only sections in the same segment are checked.
PR 31450
|
|
|
|
|
|
environments.
PR 31527
|
|
VMA->LMA relationship does not match the relationship of earlier sections in the segment.
PR 31540
|
|
If we generate an object file using an assembler with the new
relocations added, and then linking those files with an older
linker, the link will still complete and the linked file will
be generated.
In this case we should report an error instead of continuing
the linking process.
|
|
|
|
|
|
|
|
|
|
In commit b86d3af60ffc and 0ab0435fe672 I fixed SIGBUS errors found by
oss-fuzz now that --with-mmap defaults to enabled. It turns out there
are further problems with the aout mmap code: aout_read_minisymbols
returns the external symbol array, which is later freed by nm.c. If
the array is mmaped you can't free it. Now this could be fixed by
making aout minisymbols an array of pointers, but I figure there's not
much point in expending effort on that. So delete the aout mmap
support along with bfdwin.c and get_section_contents_in_window.
|
|
Seen on mmix.
mmix +FAIL: ld-misc/defsym1
mmix +FAIL: sysroot-prefix common plain -Lpath, quoted
mmix +FAIL: sysroot-prefix common plain -Lpath, unquoted
mmix +FAIL: sysroot-prefix common full-path, quoted
mmix +FAIL: sysroot-prefix common full-path, unquoted
mmix +FAIL: sysroot-prefix common plain =-prefixed with empty, quoted
mmix +FAIL: sysroot-prefix common plain =-prefixed with empty, unquoted
mmix +FAIL: sysroot-prefix common plain $SYSROOT-prefixed with empty, quoted
mmix +FAIL: sysroot-prefix common plain $SYSROOT-prefixed with empty, unquoted
mmix +FAIL: sysroot-prefix common plain =-prefixed -Lpath, quoted
mmix +FAIL: sysroot-prefix common plain =-prefixed -Lpath, unquoted
mmix +FAIL: sysroot-prefix common plain $SYSROOT-prefixed -Lpath, quoted
mmix +FAIL: sysroot-prefix common plain $SYSROOT-prefixed -Lpath, unquoted
mmix +FAIL: sysroot-prefix common full-path =-prefixed without, quoted
mmix +FAIL: sysroot-prefix common full-path =-prefixed without, unquoted
mmix +FAIL: sysroot-prefix common full-path $SYSROOT-prefixed without, quoted
mmix +FAIL: sysroot-prefix common full-path $SYSROOT-prefixed without, unquoted
==3746597==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6070000007a0 at pc 0x56d87b0d1a40 bp 0x7fffb1629bf0 sp 0x7fffb1629be0
READ of size 8 at 0x6070000007a0 thread T0
#0 0x56d87b0d1a3f in elf_link_add_to_first_hash /home/alan/src/binutils-gdb/bfd/elflink.c:4312
mmix uses bfd_link_generic_hash_table.
* elflink.c (_bfd_elf_archive_symbol_lookup): Dont use first_hash
unless the hash table is bfd_link_elf_hash_table.
(elf_link_add_archive_symbols): Likewise.
|
|
Return malloced memory in *mmap_base so that _bfd_munmap_readonly_temporary
will free it.
* libbfd.c (_bfd_mmap_read_temporary): Return malloced memory
in *mmap_base.
|
|
Normally, the section contents is allocated by bfd_alloc which is freed
when the object is closed. But the .dynamic section contents is allocated
by bfd_realloc, which should be freed by calling free. Add a dynamic
field to elf_link_hash_table for the .dynamic section and free its
contents in _bfd_elf_link_hash_table_free.
* elf-bfd.h (elf_link_hash_table): Add dynamic.
* elflink.c (_bfd_elf_link_create_dynamic_sections): Set the
dynamic field in elf_link_hash_table.
(_bfd_elf_add_dynamic_entry): Use hash_table->dynamic.
(_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
(bfd_elf_add_dt_needed_tag): Likewise.
(elf_finalize_dynstr): Likewise.
(_bfd_elf_link_hash_table_free): Free htab->dynamic->contents.
(bfd_elf_final_link): Use htab->dynamic.
* elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): Use
htab->elf.dynamic.
|
|
Any of the calls to _bfd_delete_bfd in bfd_fopen will hit this.
* opncls.c (_bfd_delete_bfd): Check for non-NULL xvec before
accessing flavour.
|
|
|
|
When -fsanitize=address,undefined is used to build, the mmap configure
check failed with
=================================================================
==231796==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4096 byte(s) in 1 object(s) allocated from:
#0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x5750c7f6d72b in main /home/alan/build/gas-san/all/bfd/conftest.c:239
Direct leak of 4096 byte(s) in 1 object(s) allocated from:
#0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x5750c7f6d2e1 in main /home/alan/build/gas-san/all/bfd/conftest.c:190
SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).
Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP to avoid the sanitizer
configure check failure.
bfd/
* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.
binutils/
* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.
ld/
* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.
libctf/
* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.
libsframe/
* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.
|
|
|
|
Define _bfd_pagesize, _bfd_pagesize_m1 and _bfd_minimum_mmap_size only
if HAVE_MMAP is defined.
* libbfd-in.h (_bfd_pagesize): Declare only if HAVE_MMAP is
defined.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
* libbfd.c (_bfd_pagesize): Define only if HAVE_MMAP is defined.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(bfd_init_pagesize): Likewise.
* lynx-core.c (lynx_core_file_p): Replace _bfd_pagesize with
getpagesize.
|
|
Support zcmp extension push/pop/popret and popret zero instructions.
The `reg_list' is a list containing 1 to 13 registers, we can use:
"{ra}, {ra, s0}, {ra, s0-s1}, {ra, s0-s2} ... {ra, s0-sN}"
to present this feature.
Passed gcc/binutils regressions of riscv-gnu-toolchain.
Most of work was finished by Sinan Lin.
Co-Authored by: Charlie Keaney <charlie.keaney@embecosm.com>
Co-Authored by: Mary Bennett <mary.bennett@embecosm.com>
Co-Authored by: Nandni Jamnadas <nandni.jamnadas@embecosm.com>
Co-Authored by: Sinan Lin <sinan.lin@linux.alibaba.com>
Co-Authored by: Simon Cook <simon.cook@embecosm.com>
Co-Authored by: Shihua Liao <shihua@iscas.ac.cn>
Co-Authored by: Yulong Shi <yulong@iscas.ac.cn>
bfd/ChangeLog:
* elfxx-riscv.c (riscv_implicit_subset): Imply zca for zcmp.
(riscv_supported_std_z_ext): Added zcmp with version 1.0.
(riscv_parse_check_conflicts): Zcmp conflicts with d/zcd.
(riscv_multi_subset_supports): Handle zcmp.
(riscv_multi_subset_supports_ext): Ditto.
gas/ChangeLog:
* NEWS: Updated.
* config/tc-riscv.c (regno_to_reg_list): New function, used to map
register to reg_list number.
(reglist_lookup): Called reglist_lookup_internal. Return false if
reg_list number is zero, which is an invalid value.
(reglist_lookup_internal): Parse register list, and return the last
register by regno_to_reg_list.
(validate_riscv_insn): New operators.
(riscv_ip): Ditto.
* testsuite/gas/riscv/march-help.l: Updated.
* testsuite/gas/riscv/zcmp-push-pop-fail.d: New test.
* testsuite/gas/riscv/zcmp-push-pop-fail.l: New test.
* testsuite/gas/riscv/zcmp-push-pop-fail.s: New test.
* testsuite/gas/riscv/zcmp-push-pop.d: New test.
* testsuite/gas/riscv/zcmp-push-pop.s: New test.
include/ChangeLog:
* opcode/riscv-opc.h (MATCH/MASK_CM_PUSH): New macros for zcmp.
(MATCH/MASK_CM_POP): Ditto.
(MATCH/MASK_CM_POPRET): Ditto.
(MATCH/MASK_CM_POPRETZ): Ditto.
(DECLARE_INSN): New declarations for zcmp.
* opcode/riscv.h (EXTRACT/ENCODE/VALID_ZCMP_SPIMM): Handle spimm
operand for zcmp.
(OP_MASK_REG_LIST): Handle operand for zcmp register list.
(OP_SH_REG_LIST): Ditto.
(ZCMP_SP_ALIGNMENT): New argument, used in riscv_get_sp_base.
(X_S0, X_S1, X_S2, X_S10, X_S11): New register numbers.
(enum riscv_insn_class): Added INSN_CLASS_ZCMP.
(extern riscv_get_sp_base): Added.
opcodes/ChangeLog:
* riscv-dis.c (print_reg_list): New function, used to get zcmp
reg_list field.
(riscv_get_spimm): New function, used to get zcmp sp adjustment
immediate.
(print_insn_args): Handle new operands for zcmp.
* riscv-opc.c (riscv_get_sp_base): New function, used by gas and
objdump. Get sp base adjustment.
(riscv_opcodes): Added zcmp instructions.
|
|
Move .got .got.plt before .data so .got can be protected with -zrelro.
And the first two entries of .got.plt (_dl_runtime_resolve and link map)
are placed within the relro region.
|
|
All of bfdwin.c is wrapped in USE_MMAP. There isn't any point in
HAVE_MMAP tests inside USE_MMAP.
* bfdwin.c (bfd_free_window, bfd_get_file_window): Delete
HAVE_MMAP conditionals.
|
|
|
|
Commit 726d7d1ecf opened a hole that allowed a u.i.link loop to be
created, resulting in _bfd_generic_link_add_one_symbol never
returning. Fix that. Note that the MIND case handles two types of
redefinition. For a new indirect symbol we'll have string non-NULL.
For a new def, string will be NULL. So moving the string comparison
earlier would work. However, we've already looked up inh in the first
case so can dispense with name comparisons. Either way, for a new def
we'll get to the defweak test and possibly cycle. Which is what we
want here.
PR 31615
PR 26978
* linker.c (_bfd_generic_link_add_one_symbol <MIND>): Test for
exactly matching indirect symbols before cycling on a defweak.
|
|
|
|
|
|
* elflink.c (elf_link_add_object_symbols): Call bfd_malloc
instead of xmalloc.
|
|
Seen running "LTO 1" under valgrind.
==1443263== Invalid read of size 1
==1443263== at 0x484CFE4: strcmp (vg_replace_strmem.c:939)
==1443263== by 0x56E16C: bfd_hash_lookup (hash.c:564)
==1443263== by 0x5A3C8F: elf_link_add_to_first_hash (elflink.c:4316)
==1443263== by 0x5AE60F: elf_link_add_object_symbols (elflink.c:5663)
==1443263== by 0x5B0672: bfd_elf_link_add_symbols (elflink.c:6333)
==1443263== by 0x41448F: load_symbols (ldlang.c:3129)
==1443263== by 0x4149D8: open_input_bfds (ldlang.c:3621)
==1443263== by 0x414968: open_input_bfds (ldlang.c:3569)
==1443263== by 0x4166A2: lang_process (ldlang.c:8162)
==1443263== by 0x4194D5: main (ldmain.c:504)
==1443263== Address 0x525e230 is 192 bytes inside a block of size 4,064 free'd
==1443263== at 0x484810F: free (vg_replace_malloc.c:974)
==1443263== by 0x8D4D87: objalloc_free_block (objalloc.c:248)
==1443263== by 0x5AEACC: elf_link_add_object_symbols (elflink.c:5790)
==1443263== by 0x5B0672: bfd_elf_link_add_symbols (elflink.c:6333)
==1443263== by 0x41448F: load_symbols (ldlang.c:3129)
==1443263== by 0x4149D8: open_input_bfds (ldlang.c:3621)
==1443263== by 0x414968: open_input_bfds (ldlang.c:3569)
==1443263== by 0x4166A2: lang_process (ldlang.c:8162)
==1443263== by 0x4194D5: main (ldmain.c:504)
PR ld/31482
PR ld/31489
* elflink.c (elf_link_add_to_first_hash): Add "copy" param.
(elf_link_add_object_symbols): Flag that name must be copied
when appending version string to symbol name.
|
|
|
|
Add elf_link_first_hash_entry and use it for first_hash. Free first_hash
before freeing the main hash table.
PR ld/31482
PR ld/31489
* elf-bfd.h (elf_link_hash_table): Change first_hash to
bfd_hash_table.
* elflink.c (elf_link_first_hash_entry): New.
(elf_link_first_hash_newfunc): Likewise.
(elf_link_add_to_first_hash): Updated.
(elf_link_add_object_symbols): Initialize first_hash with
elf_link_first_hash_newfunc.
(elf_link_add_object_symbols): Updated.
(elf_link_add_archive_symbols): Likewise.
(_bfd_elf_link_hash_table_free): Free first_hash before freeing
the main hash table.
|
|
GCC doesn't put builtin function symbol references, which are defined in
the shared C library, in the IR symbol table. When linker rescans shared
objects and archives for newly added symbol references generated from the
IR inputs, it skips definitions of the builtin functions in shared
objects and archives.
Add first_hash to elf_link_hash_table to track unreferenced definitions
defined first in shared objects and archives. Always use them to resolve
any references.
bfd/
PR ld/31482
PR ld/31489
* elf-bfd.h (elf_link_hash_table): Add first_hash.
* elflink.c (elf_link_add_to_first_hash): New function.
(elf_link_add_object_symbols): Initialize first_hash for an IR
input. Always use the first definition in shared object. Add
the first unreferenced dynamic definition to first_hash.
(_bfd_elf_archive_symbol_lookup): Add the first unreferenced
definition to first_hash..
(elf_link_add_archive_symbols): Use the symbol definition in
archive if symbol is defined first in this archive.
(_bfd_elf_link_hash_table_free): Also free first_hash.
ld/
PR ld/31482
PR ld/31489
* testsuite/ld-plugin/lto.exp: Add PR ld/31482 and PR ld/31489
tests.
* testsuite/ld-elf/pr31482a-no-lto.c: New file.
* testsuite/ld-elf/pr31482b-no-lto.c: Likewise.
* testsuite/ld-elf/pr31482c-no-lto.c: Likewise.
* testsuite/ld-elf/pr31482d-no-lto.c: Likewise.
* testsuite/ld-plugin/pass1.out: Likewise.
* testsuite/ld-plugin/pr31482a.c: Likewise.
* testsuite/ld-plugin/pr31482b.c: Likewise.
* testsuite/ld-plugin/pr31482c.c: Likewise.
|
|
PR 31527
|
|
For some reason, these targets are missing although others from the
same family are present. This looks like an oversight.
This enables calling 'make install-dvi' from the top-level build
directory.
|
|
Munmap readonly memory after bfd_free_cached_info which may use munmapped
readonly memory.
PR ld/31608
* opncls.c (_bfd_delete_bfd): Munmap readonly memory after
bfd_free_cached_info.
|
|
|
|
Update bfd_mmap_local to return NULL if filesize < offset or filesize -
offset < rsize.
* libbfd.c (bfd_mmap_local): Validate offset and size against
the file size.
|
|
iovec->bmmap may return MAP_FAILED, which happens in GDB on objects with
iovec == opncls_iovec. Update _bfd_mmap_read_temporary to handle
iovec->bmmap failure.
* libbfd.c (_bfd_mmap_read_temporary): Handle iovec->bmmap
failure.
|
|
All the HI16 reloc howtos should have a rightshift of 16, and all the
LO16 relocs shouldn't complain on overflow. This was correct for
R_MIPS_LO16 and R_MIPS_LO16 (at least on the howto_table_rel entries),
and corresponding MIPS16, MICROMIPS and MIPS64 relocs, but not on many
other HI16 and LO16 relocs.
While we're at it, fix the HIGHER and HIGHEST rightshift too.
These changes are necessary to support addends outside the range
[0,32767] when those addends are stored in section contents. Note
that some of the reloc howtos changed here will always have zero
addends (GOT_HI16, CALL_HI16). Those don't really need changing, but
use what is clearly correct for hi16 relocs anyway.
PR 19977
* elf32-mips.c: Correct rightshift for HI16, HIGHER and HIGHEST
reloc howtos. Correct complain_on_overflow for LO16 relocs.
* elf64-mips.c: Likewise.
* elfn32-mips.c: Likewise.
|
|
mips64-linux-gnuabi64 +FAIL: GOT page 4 (two files)
mipsel-linux-gnu +FAIL: GOT page 4 (two files)
mipsisa32el-linux-gnu +FAIL: GOT page 4 (two files)
mips-linux-gnu +FAIL: GOT page 4 (two files)
powerpc64-freebsd +FAIL: relocatable relaxing large
powerpc64le-linux-gnu +FAIL: relocatable relaxing large
powerpc64-linux-gnu +FAIL: relocatable relaxing large
powerpc-eabisim +FAIL: relocatable relaxing large
powerpc-eabivle +FAIL: relocatable relaxing large
powerpc-freebsd +FAIL: relocatable relaxing large
powerpcle-elf +FAIL: relocatable relaxing large
powerpc-linux-gnu +FAIL: relocatable relaxing large
* elflink.c (bfd_elf_final_link): Heed bed->use_mmap when
sizing buffers, not just USE_MMAP.
|
|
I committed a broken patch.
* aoutx.h (aout_get_external_symbols): Remove wrong #else and
unneeded casts.
* pdp11.c (aout_get_external_symbols): Likewise.
|
|
Commit c6291d749aec introduced a number of errors, found by clang.
elf.c:456:7: error: variable 'alloc_ext_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (_bfd_mul_overflow (symcount, extsym_size, &amt))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elf.c:464:7: error: variable 'alloc_extshndx_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (bfd_seek (ibfd, pos, SEEK_SET) != 0
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elflink.c:2837:11: error: variable 'alloc1_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (internal_relocs == NULL)
^~~~~~~~~~~~~~~~~~~~~~~
elflink.c:12595:16: error: variable 'ext_size' set but not used [-Werror,-Wunused-but-set-variable]
size_t ext_size = 0;
* elf.c (bfd_elf_get_elf_syms): Fix use of uninitialised variables.
* elflink.c (_bfd_elf_link_info_read_relocs): Likewise.
(bfd_elf_final_link): Fix set but not used warning.
|
|
If mmap is used without sanity checking, then we'll get a SIGBUS if
an access is done to the mmap'd memory corresponding to a page past
end of file.
* aoutx.h (aout_get_external_symbols): Check that mmap regions
are within file contents. Catch stringsize overflow.
(some_aout_object_p): Don't clear already zeroed fields. Tidy.
* pdp11.c: As for aoutx.h. Copy some fixes too.
|
|
|
|
To copy input section contents, add _bfd_elf_link_mmap_section_contents
and _bfd_elf_link_munmap_section_contents to mmap in the input sections.
* elf-bfd.h (_bfd_elf_link_mmap_section_contents): New.
(_bfd_elf_link_munmap_section_contents): Likewise.
* elf.c (elf_mmap_section_contents): New.
(_bfd_elf_mmap_section_contents): Use it.
(_bfd_elf_link_mmap_section_contents): New.
(_bfd_elf_link_munmap_section_contents): Likewise.
* elflink.c (elf_link_input_bfd): Call
_bfd_elf_link_mmap_section_contents instead of
bfd_get_full_section_contents. Call
_bfd_elf_link_munmap_section_contents to munmap the section
contents.
(bfd_elf_final_link): When mmap is used, initialize
max_contents_size to _bfd_minimum_mmap_size and increase it
for compressed or linker created sections or sections whose
rawsize != size.
|
|
When --no-keep-memory is used, the symbol table and relocation info for
eh_frame are freed after they are retrieved for each text section in the
input object. If an input object has many text sections, the same data
is retrieved and freed many times which can take a very long time.
Update _bfd_elf_gc_mark to keep the symbol table and relocation info for
eh_frame to avoid it. Data to link the 3.5GB clang executable in LLVM
17 debug build on Linux/x86-64 with 32GB RAM is:
before after improvement
user 86.31 86.44 -0.2%
system 8.77 8.63 1.6%
total 95.58 96.81 -1.3%
maximum set(GB) 13.1 13.1 0%
page faults 3024752 3028699 -1.3%
and data to link the 275M cc1plus executable in GCC 14 stage 1 build is:
user 5.49 5.46 -0.5%
system 0.73 0.73 0%
total 6.26 6.25 0.3%
maximum set(MB) 964 964 0%
page faults 235173 235796 -0.3%
The memory usage impact is minimum and the link time of the Rust binary
in
https://sourceware.org/bugzilla/show_bug.cgi?id=31466
is reduced from 500+ seconds to 1.44 seconds, a 300x speedup.
PR ld/31466
* elflink.c (init_reloc_cookie): Add a bool argument, keep_memory,
for keeping memory. Always keep memory if keep_memory is true.
(init_reloc_cookie_rels): Likewise
(init_reloc_cookie_for_section): Add a bool argument for keeping
memory and pass it to init_reloc_cookie and
init_reloc_cookie_rels.
(_bfd_elf_gc_mark_reloc): Pass false to _bfd_elf_gc_mark.
(_bfd_elf_gc_mark): Pass true to init_reloc_cookie_for_section
for the eh_frame section. Pass false to
init_reloc_cookie_for_section for other sections.
(_bfd_elf_gc_mark_extra_sections): Add Add a bool argument for
keeping memory and pass it to _bfd_elf_gc_mark.
(bfd_elf_parse_eh_frame_entries): Pass false to init_reloc_cookie
and init_reloc_cookie_rels.
(bfd_elf_gc_sections): Pass false to init_reloc_cookie_for_section
and _bfd_elf_gc_mark.
(bfd_elf_discard_info): Pass false to
init_reloc_cookie_for_section and init_reloc_cookie.
|
|
During a "-j 8" LLVM 17 debug build on a machine with 32GB RAM and 16GB
swap, ld was killed by kernel because of out of memory:
[79437.949336] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-9.scope,task=ld,pid=797431,uid=1000
[79437.949349] Out of memory: Killed process 797431 (ld) total-vm:9219600kB, anon-rss:6558156kB, file-rss:1792kB, shmem-rss:0kB, UID:1000 pgtables:17552kB oom_score_adj:0
Don't cache symbol nor relocation tables if they are mapped in. 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 86.73 87.02 -0.3%
system 9.55 9.21 3.6%
total 100.40 97.66 0.7%
maximum set(GB) 17.34 13.14 24%
page faults 4047667 3042877 25%
and data to link the 275M cc1plus executable in GCC 14 stage 1 build is:
user 5.41 5.44 -0.5%
system 0.80 0.76 5%
total 6.25 6.26 -0.2%
maximum set(MB) 1323 968 27%
page faults 323451 236371 27%
These improve the overall system performance for parallel build by
reducing memory usage and page faults.
Also rename _bfd_link_keep_memory to _bfd_elf_link_keep_memory. Since
the --no-keep-memory linker option causes:
https://sourceware.org/bugzilla/show_bug.cgi?id=31458
this is opt-in by each backend.
bfd/
* elf32-i386.c (elf_i386_scan_relocs): Remove
_bfd_link_keep_memory.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
* elflink.c (_bfd_elf_link_keep_memory): New.
(_bfd_elf_link_iterate_on_relocs): Replace _bfd_link_keep_memory
with _bfd_elf_link_keep_memory.
(elf_link_add_object_symbols): Likewise.
(init_reloc_cookie): Likewise.
(init_reloc_cookie_rels): Likewise.
* libbfd-in.h (_bfd_link_keep_memory): Removed.
* linker.c (_bfd_link_keep_memory): Likewise.
* libbfd.h: Regenerated.
|
|
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.
|
|
Add _bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents.
A backend must opt-in to use mmap. It should replace
bfd_malloc_and_get_section -> _bfd_elf_mmap_section_contents
free -> _bfd_elf_munmap_section_contents
on section contents.
* compress.c (bfd_get_full_section_contents): Don't allocate
buffer if mmapped_p is true.
* elf-bfd.h (elf_backend_data): Add use_mmap.
(bfd_elf_section_data): Add contents_addr and contents_size.
(_bfd_elf_mmap_section_contents): New.
(_bfd_elf_munmap_section_contents): Likewise.
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
* elf-sframe.c (_bfd_elf_parse_sframe): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
(_bfd_elf_print_private_bfd_data): Likewise.
(_bfd_elf_mmap_section_contents): New.
(_bfd_elf_munmap_section_contents): Likewise.
* elf32-i386.c (elf_i386_scan_relocs): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
(elf_x86_64_get_synthetic_symtab): Likewise.
* elfcode.h (elf_checksum_contents): Likewise.
* elflink.c (elf_link_add_object_symbols): Likewise.
(bfd_elf_get_bfd_needed_list): Likewise.
* elfxx-target.h (elf_backend_use_mmap): New.
(elfNN_bed): Add elf_backend_use_mmap.
* elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
(_bfd_x86_elf_get_synthetic_symtab): Replace free with
_bfd_elf_munmap_section_contents.
* elfxx-x86.h (elf_backend_use_mmap): New.
* libbfd.c: Include "elf-bfd.h".
(_bfd_generic_get_section_contents): Call bfd_mmap_local for
mmapped_p.
* opncls.c (_bfd_delete_bfd): Also munmap ELF section contents.
* section.c (asection): Add mmapped_p.
(BFD_FAKE_SECTION): Updated.
(bfd_malloc_and_get_section): Add a sanity check for not
mmapped_p.
* bfd-in2.h: Regenerated.
|
|
There are many linker input files in LLVM debug build with huge string
sections. All these string sections can be treated as read-only. But
linker copies all of them into memory which consumes huge amount of
memory and slows down linker significantly.
Add _bfd_mmap_readonly_persistent and _bfd_mmap_readonly_temporary to
mmap in reado-only sections with size >= 4 * page size.
NB: All string sections in valid ELF inputs must be null terminated.
There is no need to terminate it again and string sections are mmapped
as read-only.
* bfd.c (bfd_mmapped_entry): New.
(bfd_mmapped): Likewise.
(bfd): Add mmapped.
* bfdwin.c (bfd_get_file_window): Use _bfd_pagesize.
* cache.c (cache_bmmap): Remove pagesize_m1 and use pagesize_m1
instead.
* elf.c (bfd_elf_get_str_section): Call
_bfd_mmap_readonly_persistent instead of _bfd_alloc_and_read.
Don't terminate the string section again.
(get_hash_table_data): Call _bfd_mmap_readonly_temporary and
_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
(_bfd_elf_get_dynamic_symbols): Call _bfd_mmap_readonly_persistent
instead of _bfd_alloc_and_read. Don't terminate the string
section again. Call _bfd_mmap_readonly_temporary and
_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
(_bfd_elf_slurp_version_tables): Call _bfd_mmap_readonly_temporary
and _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
* elflink.c (bfd_elf_link_record_dynamic_symbol): Use bfd_malloc
to get the unversioned symbol.
* libbfd-in.h (_bfd_pagesize): New.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(_bfd_mmap_readonly_persistent): Likewise.
(_bfd_mmap_readonly_temporary): Likewise.
(_bfd_munmap_readonly_temporary): Likewise.
* libbfd.c
(bfd_allocate_mmapped_page): New.
(_bfd_mmap_readonly_temporary): Likewise.
(_bfd_munmap_readonly_temporary): Likewise.
(_bfd_mmap_readonly_persistent): Likewise.
(_bfd_pagesize): Likewise.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(bfd_init_pagesize): Likewise.
* lynx-core.c (lynx_core_file_p): Use _bfd_pagesize.
* opncls.c (_bfd_delete_bfd): Munmap tracked mmapped memories.
* sysdep.h (MAP_ANONYMOUS): New. Define if undefined.
* bfd-in2.h: Regenerated.
* libbfd.h: Likewise.
|
|
|