1214571Sdim# This shell script emits a C file. -*- C -*- 2214571Sdim# Copyright 2006 Free Software Foundation, Inc. 3214571Sdim# 4214571Sdim# This file is part of GLD, the Gnu Linker. 5214571Sdim# 6214571Sdim# This program is free software; you can redistribute it and/or modify 7214571Sdim# it under the terms of the GNU General Public License as published by 8214571Sdim# the Free Software Foundation; either version 2 of the License, or 9214571Sdim# (at your option) any later version. 10214571Sdim# 11214571Sdim# This program is distributed in the hope that it will be useful, 12214571Sdim# but WITHOUT ANY WARRANTY; without even the implied warranty of 13214571Sdim# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14214571Sdim# GNU General Public License for more details. 15214571Sdim# 16214571Sdim# You should have received a copy of the GNU General Public License 17214571Sdim# along with this program; if not, write to the Free Software Foundation, Inc., 18214571Sdim# 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 19214571Sdim# 20214571Sdim 21214571Sdim# This file is sourced from elf32.em and from ELF targets that use 22214571Sdim# generic.em. 23214571Sdim# 24214571Sdimcat >>e${EMULATION_NAME}.c <<EOF 25214571Sdim 26214571Sdimstatic void 27214571Sdimgld${EMULATION_NAME}_map_segments (bfd_boolean need_layout) 28214571Sdim{ 29214571Sdim int tries = 10; 30214571Sdim 31214571Sdim do 32214571Sdim { 33214571Sdim if (need_layout) 34214571Sdim { 35214571Sdim lang_reset_memory_regions (); 36214571Sdim 37214571Sdim /* Resize the sections. */ 38214571Sdim lang_size_sections (NULL, TRUE); 39214571Sdim 40214571Sdim /* Redo special stuff. */ 41214571Sdim ldemul_after_allocation (); 42214571Sdim 43214571Sdim /* Do the assignments again. */ 44214571Sdim lang_do_assignments (); 45214571Sdim 46214571Sdim need_layout = FALSE; 47214571Sdim } 48214571Sdim 49214571Sdim if (output_bfd->xvec->flavour == bfd_target_elf_flavour 50214571Sdim && !link_info.relocatable) 51214571Sdim { 52214571Sdim bfd_size_type phdr_size; 53214571Sdim 54214571Sdim phdr_size = elf_tdata (output_bfd)->program_header_size; 55214571Sdim /* If we don't have user supplied phdrs, throw away any 56214571Sdim previous linker generated program headers. */ 57214571Sdim if (lang_phdr_list == NULL) 58214571Sdim elf_tdata (output_bfd)->segment_map = NULL; 59214571Sdim if (!_bfd_elf_map_sections_to_segments (output_bfd, &link_info)) 60214571Sdim einfo ("%F%P: map sections to segments failed: %E\n"); 61214571Sdim 62214571Sdim if (phdr_size != elf_tdata (output_bfd)->program_header_size) 63214571Sdim { 64214571Sdim if (tries > 6) 65214571Sdim /* The first few times we allow any change to 66214571Sdim phdr_size . */ 67214571Sdim need_layout = TRUE; 68214571Sdim else if (phdr_size < elf_tdata (output_bfd)->program_header_size) 69214571Sdim /* After that we only allow the size to grow. */ 70214571Sdim need_layout = TRUE; 71214571Sdim else 72214571Sdim elf_tdata (output_bfd)->program_header_size = phdr_size; 73214571Sdim } 74214571Sdim } 75214571Sdim } 76214571Sdim while (need_layout && --tries); 77214571Sdim 78214571Sdim if (tries == 0) 79214571Sdim einfo (_("%P%F: looping in map_segments")); 80214571Sdim} 81214571SdimEOF 82