Remove some forward declarations in ldemul.h and ldfile.h, and
[deliverable/binutils-gdb.git] / ld / emultempl / mipsecoff.em
1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >e${EMULATION_NAME}.c <<EOF
4 /* This file is is generated by a shell script. DO NOT EDIT! */
5
6 /* Handle embedded relocs for MIPS.
7 Copyright 1994, 95, 97, 99, 2000 Free Software Foundation, Inc.
8 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
9
10 This file is part of GLD, the Gnu Linker.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25
26 #define TARGET_IS_${EMULATION_NAME}
27
28 #include "bfd.h"
29 #include "sysdep.h"
30 #include "bfdlink.h"
31
32 #include "ld.h"
33 #include "ldmain.h"
34 #include "ldmisc.h"
35
36 #include "ldexp.h"
37 #include "ldlang.h"
38 #include "ldfile.h"
39 #include "ldemul.h"
40
41 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
42 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
43 static void check_sections PARAMS ((bfd *, asection *, PTR));
44 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
45 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
46
47 static void
48 gld${EMULATION_NAME}_before_parse()
49 {
50 #ifndef TARGET_ /* I.e., if not generic. */
51 ldfile_output_architecture = bfd_arch_${ARCH};
52 #endif /* not TARGET_ */
53 }
54
55 /* This function is run after all the input files have been opened.
56 We create a .rel.sdata section for each input file with a non zero
57 .sdata section. The BFD backend will fill in these sections with
58 magic numbers which can be used to relocate the data section at run
59 time. This will only do the right thing if all the input files
60 have been compiled using -membedded-pic. */
61
62 static void
63 gld${EMULATION_NAME}_after_open ()
64 {
65 bfd *abfd;
66
67 if (! command_line.embedded_relocs
68 || link_info.relocateable)
69 return;
70
71 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
72 {
73 asection *datasec;
74
75 /* As first-order business, make sure that each input BFD is ECOFF. It
76 better be, as we are directly calling an ECOFF backend function. */
77 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour)
78 einfo ("%F%B: all input objects must be ECOFF for --embedded-relocs\n");
79
80 datasec = bfd_get_section_by_name (abfd, ".sdata");
81
82 /* Note that we assume that the reloc_count field has already
83 been set up. We could call bfd_get_reloc_upper_bound, but
84 that returns the size of a memory buffer rather than a reloc
85 count. We do not want to call bfd_canonicalize_reloc,
86 because although it would always work it would force us to
87 read in the relocs into BFD canonical form, which would waste
88 a significant amount of time and memory. */
89 if (datasec != NULL && datasec->reloc_count > 0)
90 {
91 asection *relsec;
92
93 relsec = bfd_make_section (abfd, ".rel.sdata");
94 if (relsec == NULL
95 || ! bfd_set_section_flags (abfd, relsec,
96 (SEC_ALLOC
97 | SEC_LOAD
98 | SEC_HAS_CONTENTS
99 | SEC_IN_MEMORY))
100 || ! bfd_set_section_alignment (abfd, relsec, 2)
101 || ! bfd_set_section_size (abfd, relsec,
102 datasec->reloc_count * 4))
103 einfo ("%F%B: can not create .rel.sdata section: %E\n");
104 }
105
106 /* Double check that all other data sections are empty, as is
107 required for embedded PIC code. */
108 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
109 }
110 }
111
112 /* Check that of the data sections, only the .sdata section has
113 relocs. This is called via bfd_map_over_sections. */
114
115 static void
116 check_sections (abfd, sec, sdatasec)
117 bfd *abfd;
118 asection *sec;
119 PTR sdatasec;
120 {
121 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
122 && sec != (asection *) sdatasec
123 && sec->reloc_count != 0)
124 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
125 abfd, bfd_get_section_name (abfd, sec));
126 }
127
128 /* This function is called after the section sizes and offsets have
129 been set. If we are generating embedded relocs, it calls a special
130 BFD backend routine to do the work. */
131
132 static void
133 gld${EMULATION_NAME}_after_allocation ()
134 {
135 bfd *abfd;
136
137 if (! command_line.embedded_relocs
138 || link_info.relocateable)
139 return;
140
141 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
142 {
143 asection *datasec, *relsec;
144 char *errmsg;
145
146 datasec = bfd_get_section_by_name (abfd, ".sdata");
147
148 if (datasec == NULL || datasec->reloc_count == 0)
149 continue;
150
151 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
152 ASSERT (relsec != NULL);
153
154 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
155 datasec, relsec,
156 &errmsg))
157 {
158 if (errmsg == NULL)
159 einfo ("%B%X: can not create runtime reloc information: %E\n",
160 abfd);
161 else
162 einfo ("%X%B: can not create runtime reloc information: %s\n",
163 abfd, errmsg);
164 }
165 }
166 }
167
168 static char *
169 gld${EMULATION_NAME}_get_script(isfile)
170 int *isfile;
171 EOF
172
173 if test -n "$COMPILE_IN"
174 then
175 # Scripts compiled in.
176
177 # sed commands to quote an ld script as a C string.
178 sc="-f stringify.sed"
179
180 cat >>e${EMULATION_NAME}.c <<EOF
181 {
182 *isfile = 0;
183
184 if (link_info.relocateable == true && config.build_constructors == true)
185 return
186 EOF
187 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
188 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
189 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
190 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
191 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
192 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
193 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
194 echo ' ; else return' >> e${EMULATION_NAME}.c
195 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
196 echo '; }' >> e${EMULATION_NAME}.c
197
198 else
199 # Scripts read from the filesystem.
200
201 cat >>e${EMULATION_NAME}.c <<EOF
202 {
203 *isfile = 1;
204
205 if (link_info.relocateable == true && config.build_constructors == true)
206 return "ldscripts/${EMULATION_NAME}.xu";
207 else if (link_info.relocateable == true)
208 return "ldscripts/${EMULATION_NAME}.xr";
209 else if (!config.text_read_only)
210 return "ldscripts/${EMULATION_NAME}.xbn";
211 else if (!config.magic_demand_paged)
212 return "ldscripts/${EMULATION_NAME}.xn";
213 else
214 return "ldscripts/${EMULATION_NAME}.x";
215 }
216 EOF
217
218 fi
219
220 cat >>e${EMULATION_NAME}.c <<EOF
221
222 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
223 {
224 gld${EMULATION_NAME}_before_parse,
225 syslib_default,
226 hll_default,
227 after_parse_default,
228 gld${EMULATION_NAME}_after_open,
229 gld${EMULATION_NAME}_after_allocation,
230 set_output_arch_default,
231 ldemul_default_target,
232 before_allocation_default,
233 gld${EMULATION_NAME}_get_script,
234 "${EMULATION_NAME}",
235 "${OUTPUT_FORMAT}",
236 NULL, /* finish */
237 NULL, /* create output section statements */
238 NULL, /* open dynamic archive */
239 NULL, /* place orphan */
240 NULL, /* set symbols */
241 NULL, /* parse args */
242 NULL, /* unrecognized file */
243 NULL, /* list options */
244 NULL, /* recognized file */
245 NULL /* find_potential_libraries */
246 };
247 EOF
This page took 0.050733 seconds and 5 git commands to generate.