xref: /dflybsd-src/contrib/binutils-2.27/ld/emultempl/elf-generic.em (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj# This shell script emits a C file. -*- C -*-
2*a9fa9459Szrj#   Copyright (C) 2006-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj#
4*a9fa9459Szrj# This file is part of the GNU Binutils.
5*a9fa9459Szrj#
6*a9fa9459Szrj# This program is free software; you can redistribute it and/or modify
7*a9fa9459Szrj# it under the terms of the GNU General Public License as published by
8*a9fa9459Szrj# the Free Software Foundation; either version 3 of the License, or
9*a9fa9459Szrj# (at your option) any later version.
10*a9fa9459Szrj#
11*a9fa9459Szrj# This program is distributed in the hope that it will be useful,
12*a9fa9459Szrj# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*a9fa9459Szrj# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*a9fa9459Szrj# GNU General Public License for more details.
15*a9fa9459Szrj#
16*a9fa9459Szrj# You should have received a copy of the GNU General Public License
17*a9fa9459Szrj# along with this program; if not, write to the Free Software
18*a9fa9459Szrj# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19*a9fa9459Szrj# MA 02110-1301, USA.
20*a9fa9459Szrj#
21*a9fa9459Szrj
22*a9fa9459Szrj# This file is sourced from elf32.em and from ELF targets that use
23*a9fa9459Szrj# generic.em.
24*a9fa9459Szrj#
25*a9fa9459Szrjfragment <<EOF
26*a9fa9459Szrj
27*a9fa9459Szrjstatic void
28*a9fa9459Szrjgld${EMULATION_NAME}_map_segments (bfd_boolean need_layout)
29*a9fa9459Szrj{
30*a9fa9459Szrj  int tries = 10;
31*a9fa9459Szrj
32*a9fa9459Szrj  do
33*a9fa9459Szrj    {
34*a9fa9459Szrj      lang_relax_sections (need_layout);
35*a9fa9459Szrj      need_layout = FALSE;
36*a9fa9459Szrj
37*a9fa9459Szrj      if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour
38*a9fa9459Szrj	  && !bfd_link_relocatable (&link_info))
39*a9fa9459Szrj	{
40*a9fa9459Szrj	  bfd_size_type phdr_size;
41*a9fa9459Szrj
42*a9fa9459Szrj	  phdr_size = elf_program_header_size (link_info.output_bfd);
43*a9fa9459Szrj	  /* If we don't have user supplied phdrs, throw away any
44*a9fa9459Szrj	     previous linker generated program headers.  */
45*a9fa9459Szrj	  if (lang_phdr_list == NULL)
46*a9fa9459Szrj	    elf_seg_map (link_info.output_bfd) = NULL;
47*a9fa9459Szrj	  if (!_bfd_elf_map_sections_to_segments (link_info.output_bfd,
48*a9fa9459Szrj						  &link_info))
49*a9fa9459Szrj	    einfo ("%F%P: map sections to segments failed: %E\n");
50*a9fa9459Szrj
51*a9fa9459Szrj	  if (phdr_size != elf_program_header_size (link_info.output_bfd))
52*a9fa9459Szrj	    {
53*a9fa9459Szrj	      if (tries > 6)
54*a9fa9459Szrj		/* The first few times we allow any change to
55*a9fa9459Szrj		   phdr_size .  */
56*a9fa9459Szrj		need_layout = TRUE;
57*a9fa9459Szrj	      else if (phdr_size
58*a9fa9459Szrj		       < elf_program_header_size (link_info.output_bfd))
59*a9fa9459Szrj		/* After that we only allow the size to grow.  */
60*a9fa9459Szrj		need_layout = TRUE;
61*a9fa9459Szrj	      else
62*a9fa9459Szrj		elf_program_header_size (link_info.output_bfd) = phdr_size;
63*a9fa9459Szrj	    }
64*a9fa9459Szrj	}
65*a9fa9459Szrj    }
66*a9fa9459Szrj  while (need_layout && --tries);
67*a9fa9459Szrj
68*a9fa9459Szrj  if (tries == 0)
69*a9fa9459Szrj    einfo (_("%P%F: looping in map_segments"));
70*a9fa9459Szrj}
71*a9fa9459SzrjEOF
72