diff options
author | Alan Modra <amodra@gmail.com> | 2019-09-09 23:07:35 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-09-11 13:44:22 +0930 |
commit | d871d478061f10b0879c688e2fa941407e9137aa (patch) | |
tree | 4f564ccc452de8255f2eecfecfb931de03ad2093 /ld/ldelfgen.c | |
parent | cb7f4b298e5e0a3ab4fb6b13aa89e970478597bc (diff) | |
download | gdb-d871d478061f10b0879c688e2fa941407e9137aa.zip gdb-d871d478061f10b0879c688e2fa941407e9137aa.tar.gz gdb-d871d478061f10b0879c688e2fa941407e9137aa.tar.bz2 |
Move elf32.em and elf-generic.em functions
Many ELF linker targets support multiple "emulations" and thus have
multiple copies of elf32.em being compiled and linked into ld. This
patch moves much of elf32.em and elf-generic.em into files which will
be compiled just once, resulting in a 20% decrease in ld size for
--enable-targets=all.
* Makefile.am (ALL_EMUL_EXTRA_OFILES): Add ldelf and ldelfgen.
(CFILES, HFILES, EXTRA_ld_new_SOURCES): Likewise.
* configure.tgt: Formatting.
(targ_extra_ofiles): Init to ldelf.o ldelfgen.o, reset to just
ldelfgen.o for generic ELF targets, and empty for non-ELF.
* emultempl/aarch64elf.em (gldaarch64_layout_sections_again): Use
ldelf_map_segments.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, aarch64_for_each_input_file_wrapper),
(aarch64_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/alphaelf.em (alpha_after_parse): Use ldelf_map_segments.
* emultempl/armelf.em (gldarm_layout_sections_again): Likewise.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, arm_for_each_input_file_wrapper),
(arm_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/cr16elf.em (cr16elf_after_parse): Use ldelf_map_segments.
* emultempl/crxelf.em (crxelf_after_parse): Likewise. Delete
declaration.
* emultempl/cskyelf.em (gldcsky_layout_sections_again): Use
ldelf_map_segments.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, csky_for_each_input_file_wrapper),
(csky_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/genelf.em: Include ldelfgen.h.
(gld${EMULATION_NAME}_before_allocation): Use ldelf_map_segments.
* emultempl/hppaelf.em (hppaelf_after_parse): Likewise.
(hppaelf_layout_sections_again): Likewise.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, hppa_for_each_input_file_wrapper),
(hppa_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/ia64elf.em (ia64elf_after_parse): Use ldelf_map_segments.
* emultempl/m68hc1xelf.em (real_func),
(m68hc11_for_each_input_file_wrapper),
(m68hc11_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/metagelf.em (metagelf_layout_sections_again): Use
ldelf_map_segments.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, metag_for_each_input_file_wrapper),
(metag_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/mipself.em (real_func),
(mips_for_each_input_file_wrapper),
(mips_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/mmo.em: Don't include elf-bfd.h, do include ldelfgen.h.
(gld${EMULATION_NAME}_after_allocation): Use ldelf_map_segments.
* emultempl/nds32elf.em (nds32_elf_after_parse): Use ldelf_after_parse.
(nds32_elf_after_allocation): Comment fix.
* emultempl/nios2elf.em (nios2elf_layout_sections_again): Use
ldelf_map_segments.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, nios2_for_each_input_file_wrapper),
(nios2_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
* emultempl/ppc32elf.em (gld${EMULATION_NAME}_load_symbols): Delete
declaration.
(ppc_recognized_file): Call ldelf_load_symbols.
* emultempl/ppc64elf.em (ppc_layout_sections_again): Likewise.
(gld${EMULATION_NAME}_after_allocation): Likewise.
(real_func, ppc_for_each_input_file_wrapper),
(ppc_lang_for_each_input_file): Delete.
(lang_for_each_input_file): Don't define.
(gld${EMULATION_NAME}_load_symbols): Don't declare.
(ppc64_recognized_file): Call ldelf_load_symbols.
* emultempl/riscvelf.em (gld${EMULATION_NAME}_after_allocation):
Use ldelf_map_segments.
* emultempl/spuelf.em (spu_place_special_section): Use
ldelf_place_orphan.
* emultempl/tic6xdsbt.em (gld${EMULATION_NAME}_after_allocation):
Use ldelf_map_segments.
* emultempl/vms.em: Include ldelfgen.h.
(gld${EMULATION_NAME}_after_allocation): Use ldelf_map_segments.
* emultempl/elf32.em: Remove unnecessary headers, include ldelf.h
and ldelfgen.h. Move much of file content to..
* ldelf.c: ..here. New file.
* ldelf.h: New file.
* emultempl/elf-generic.em: Move gld${EMULATION_NAME}_map_segments..
* ldelfgen.c: ..to here.
* ldelfgen.h: New file.
* ldlang.c (lang_for_each_input_file): Adjust to only call func
on real files.
(lang_for_each_file): Likewise.
* po/SRC-POTFILES.in: Regenerate.
* Makefile.in: Regenerate.
Diffstat (limited to 'ld/ldelfgen.c')
-rw-r--r-- | ld/ldelfgen.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ld/ldelfgen.c b/ld/ldelfgen.c new file mode 100644 index 0000000..98bcecd --- /dev/null +++ b/ld/ldelfgen.c @@ -0,0 +1,74 @@ +/* Emulation code used by all ELF targets. + Copyright (C) 1991-2019 Free Software Foundation, Inc. + + This file is part of the GNU Binutils. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include "sysdep.h" +#include "bfd.h" +#include "ld.h" +#include "ldmain.h" +#include "ldmisc.h" +#include "ldexp.h" +#include "ldlang.h" +#include "elf-bfd.h" +#include "ldelfgen.h" + +void +ldelf_map_segments (bfd_boolean need_layout) +{ + int tries = 10; + + do + { + lang_relax_sections (need_layout); + need_layout = FALSE; + + if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour + && !bfd_link_relocatable (&link_info)) + { + bfd_size_type phdr_size; + + phdr_size = elf_program_header_size (link_info.output_bfd); + /* If we don't have user supplied phdrs, throw away any + previous linker generated program headers. */ + if (lang_phdr_list == NULL) + elf_seg_map (link_info.output_bfd) = NULL; + if (!_bfd_elf_map_sections_to_segments (link_info.output_bfd, + &link_info)) + einfo (_("%F%P: map sections to segments failed: %E\n")); + + if (phdr_size != elf_program_header_size (link_info.output_bfd)) + { + if (tries > 6) + /* The first few times we allow any change to + phdr_size . */ + need_layout = TRUE; + else if (phdr_size + < elf_program_header_size (link_info.output_bfd)) + /* After that we only allow the size to grow. */ + need_layout = TRUE; + else + elf_program_header_size (link_info.output_bfd) = phdr_size; + } + } + } + while (need_layout && --tries); + + if (tries == 0) + einfo (_("%F%P: looping in map_segments")); +} |