Support arbitrary length fill patterns.
[platform/upstream/binutils.git] / ld / emultempl / ppc64elf.em
1 # This shell script emits a C file. -*- C -*-
2 #   Copyright 2002 Free Software Foundation, Inc.
3 #
4 # This file is part of GLD, the Gnu Linker.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #
20
21 # This file is sourced from elf32.em, and defines extra powerpc64-elf
22 # specific routines.
23 #
24 cat >>e${EMULATION_NAME}.c <<EOF
25
26 #include "elf64-ppc.h"
27
28 static int need_laying_out = 0;
29
30 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
31 static void gld${EMULATION_NAME}_finish PARAMS ((void));
32
33 /* Call the back-end function to set TOC base after we have placed all
34    the sections.  */
35 static void
36 gld${EMULATION_NAME}_after_allocation ()
37 {
38   if (!ppc64_elf_set_toc (output_bfd, &link_info))
39     einfo ("%X%P: can not set TOC base: %E\n");
40 }
41
42 /* Final emulation specific call.  PowerPC64 has 24 byte .plt entries,
43    and needs different call stubs for any entries that cross a 64k
44    boundary relative to the TOC.  That means we need to wait until all
45    sections have been laid out to initialise the stubs.  */
46
47 static void
48 gld${EMULATION_NAME}_finish ()
49 {
50   /* e_entry on PowerPC64 points to the function descriptor for
51      _start.  If _start is missing, default to the first function
52      descriptor in the .opd section.  */
53   entry_section = ".opd";
54
55   /* If generating a relocatable output file, then we don't have any
56      stubs.  */
57   if (link_info.relocateable)
58     return;
59
60   /* bfd_elf64_discard_info just plays with debugging sections,
61      ie. doesn't affect any code, so we can delay resizing the
62      sections.  It's likely we'll resize everything in the process of
63      adjusting stub sizes.  */
64   if (bfd_elf${ELFSIZE}_discard_info (output_bfd, &link_info))
65     need_laying_out = 1;
66
67   while (1)
68     {
69       /* Call into the BFD backend to do the real work.  */
70       if (! ppc64_elf_size_stubs (output_bfd, &link_info, &need_laying_out))
71         {
72           einfo ("%X%P: can not size stub section: %E\n");
73           return;
74         }
75
76       if (!need_laying_out)
77         break;
78
79       /* If we have changed the size of the stub section, then we need
80          to recalculate all the section offsets.  After this, we may
81          need to adjust the stub size again.  */
82       need_laying_out = 0;
83
84       lang_reset_memory_regions ();
85
86       /* Resize the sections.  */
87       lang_size_sections (stat_ptr->head, abs_output_section,
88                           &stat_ptr->head, 0, (bfd_vma) 0, NULL);
89
90       /* Recalculate TOC base.  */
91       ldemul_after_allocation ();
92
93       /* Do the assignments again.  */
94       lang_do_assignments (stat_ptr->head, abs_output_section,
95                            (fill_type *) 0, (bfd_vma) 0);
96     }
97
98   if (! ppc64_elf_build_stubs (output_bfd, &link_info))
99     einfo ("%X%P: can not build stubs: %E\n");
100 }
101 EOF
102
103 # Put these extra ppc64elf routines in ld_${EMULATION_NAME}_emulation
104 #
105 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
106 LDEMUL_FINISH=gld${EMULATION_NAME}_finish