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