elf-generic.em revision 214571
175115Sfenner# This shell script emits a C file. -*- C -*- 275115Sfenner# Copyright 2006 Free Software Foundation, Inc. 375115Sfenner# 475115Sfenner# This file is part of GLD, the Gnu Linker. 575115Sfenner# 675115Sfenner# This program is free software; you can redistribute it and/or modify 775115Sfenner# it under the terms of the GNU General Public License as published by 875115Sfenner# the Free Software Foundation; either version 2 of the License, or 975115Sfenner# (at your option) any later version. 1075115Sfenner# 1175115Sfenner# This program is distributed in the hope that it will be useful, 1275115Sfenner# but WITHOUT ANY WARRANTY; without even the implied warranty of 13127668Sbms# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14190207Srpaulo# GNU General Public License for more details. 1575115Sfenner# 1675115Sfenner# You should have received a copy of the GNU General Public License 1775115Sfenner# along with this program; if not, write to the Free Software Foundation, Inc., 1875115Sfenner# 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 1975115Sfenner# 2075115Sfenner 21127668Sbms# This file is sourced from elf32.em and from ELF targets that use 2275115Sfenner# generic.em. 2375115Sfenner# 2475115Sfennercat >>e${EMULATION_NAME}.c <<EOF 2575115Sfenner 2675115Sfennerstatic void 2775115Sfennergld${EMULATION_NAME}_map_segments (bfd_boolean need_layout) 2875115Sfenner{ 2975115Sfenner int tries = 10; 3075115Sfenner 31168371Sthompsa do 32168371Sthompsa { 33168371Sthompsa if (need_layout) 34168371Sthompsa { 35168371Sthompsa lang_reset_memory_regions (); 36168371Sthompsa 37168371Sthompsa /* Resize the sections. */ 38168371Sthompsa lang_size_sections (NULL, TRUE); 39168371Sthompsa 40168371Sthompsa /* Redo special stuff. */ 41168371Sthompsa ldemul_after_allocation (); 42168371Sthompsa 43168371Sthompsa /* Do the assignments again. */ 44168371Sthompsa lang_do_assignments (); 45168371Sthompsa 46168371Sthompsa need_layout = FALSE; 47168371Sthompsa } 48168371Sthompsa 49168371Sthompsa if (output_bfd->xvec->flavour == bfd_target_elf_flavour 50168371Sthompsa && !link_info.relocatable) 51168371Sthompsa { 52168371Sthompsa bfd_size_type phdr_size; 53168371Sthompsa 54168371Sthompsa phdr_size = elf_tdata (output_bfd)->program_header_size; 55251158Sdelphij /* If we don't have user supplied phdrs, throw away any 56168371Sthompsa previous linker generated program headers. */ 57168371Sthompsa if (lang_phdr_list == NULL) 58168371Sthompsa elf_tdata (output_bfd)->segment_map = NULL; 59168371Sthompsa if (!_bfd_elf_map_sections_to_segments (output_bfd, &link_info)) 60168371Sthompsa einfo ("%F%P: map sections to segments failed: %E\n"); 61251158Sdelphij 62168371Sthompsa if (phdr_size != elf_tdata (output_bfd)->program_header_size) 63168371Sthompsa { 64168371Sthompsa if (tries > 6) 65168371Sthompsa /* The first few times we allow any change to 66168371Sthompsa phdr_size . */ 67168371Sthompsa need_layout = TRUE; 68168371Sthompsa else if (phdr_size < elf_tdata (output_bfd)->program_header_size) 69168371Sthompsa /* After that we only allow the size to grow. */ 70168371Sthompsa need_layout = TRUE; 71168371Sthompsa else 72168371Sthompsa elf_tdata (output_bfd)->program_header_size = phdr_size; 73168371Sthompsa } 74168371Sthompsa } 75168371Sthompsa } 76168371Sthompsa while (need_layout && --tries); 77168371Sthompsa 78168371Sthompsa if (tries == 0) 79168371Sthompsa einfo (_("%P%F: looping in map_segments")); 80168371Sthompsa} 81168371SthompsaEOF 82168371Sthompsa