* Makefile.in (ALLDEPFILES): Remove sparc-linux-nat.c and
[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 check_sections (bfd *, asection *, void *);
48
49 static void
50 gld${EMULATION_NAME}_before_parse (void)
51 {
52 #ifndef TARGET_ /* I.e., if not generic. */
53 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
54 if (arch)
55 {
56 ldfile_output_architecture = arch->arch;
57 ldfile_output_machine = arch->mach;
58 ldfile_output_machine_name = arch->printable_name;
59 }
60 else
61 ldfile_output_architecture = bfd_arch_${ARCH};
62 #endif /* not TARGET_ */
63 }
64
65 /* This function is run after all the input files have been opened.
66 We create a .rel.sdata section for each input file with a non zero
67 .sdata section. The BFD backend will fill in these sections with
68 magic numbers which can be used to relocate the data section at run
69 time. This will only do the right thing if all the input files
70 have been compiled using -membedded-pic. */
71
72 static void
73 gld${EMULATION_NAME}_after_open (void)
74 {
75 bfd *abfd;
76
77 if (! command_line.embedded_relocs
78 || link_info.relocatable)
79 return;
80
81 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
82 {
83 asection *datasec;
84
85 /* As first-order business, make sure that each input BFD is ECOFF. It
86 better be, as we are directly calling an ECOFF backend function. */
87 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour)
88 einfo ("%F%B: all input objects must be ECOFF for --embedded-relocs\n");
89
90 datasec = bfd_get_section_by_name (abfd, ".sdata");
91
92 /* Note that we assume that the reloc_count field has already
93 been set up. We could call bfd_get_reloc_upper_bound, but
94 that returns the size of a memory buffer rather than a reloc
95 count. We do not want to call bfd_canonicalize_reloc,
96 because although it would always work it would force us to
97 read in the relocs into BFD canonical form, which would waste
98 a significant amount of time and memory. */
99 if (datasec != NULL && datasec->reloc_count > 0)
100 {
101 asection *relsec;
102
103 relsec = bfd_make_section (abfd, ".rel.sdata");
104 if (relsec == NULL
105 || ! bfd_set_section_flags (abfd, relsec,
106 (SEC_ALLOC
107 | SEC_LOAD
108 | SEC_HAS_CONTENTS
109 | SEC_IN_MEMORY))
110 || ! bfd_set_section_alignment (abfd, relsec, 2)
111 || ! bfd_set_section_size (abfd, relsec,
112 datasec->reloc_count * 4))
113 einfo ("%F%B: can not create .rel.sdata section: %E\n");
114 }
115
116 /* Double check that all other data sections are empty, as is
117 required for embedded PIC code. */
118 bfd_map_over_sections (abfd, check_sections, datasec);
119 }
120 }
121
122 /* Check that of the data sections, only the .sdata section has
123 relocs. This is called via bfd_map_over_sections. */
124
125 static void
126 check_sections (bfd *abfd, asection *sec, void *sdatasec)
127 {
128 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
129 && sec != sdatasec
130 && sec->reloc_count != 0)
131 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
132 abfd, bfd_get_section_name (abfd, sec));
133 }
134
135 /* This function is called after the section sizes and offsets have
136 been set. If we are generating embedded relocs, it calls a special
137 BFD backend routine to do the work. */
138
139 static void
140 gld${EMULATION_NAME}_after_allocation (void)
141 {
142 bfd *abfd;
143
144 if (! command_line.embedded_relocs
145 || link_info.relocatable)
146 return;
147
148 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
149 {
150 asection *datasec, *relsec;
151 char *errmsg;
152
153 datasec = bfd_get_section_by_name (abfd, ".sdata");
154
155 if (datasec == NULL || datasec->reloc_count == 0)
156 continue;
157
158 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
159 ASSERT (relsec != NULL);
160
161 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
162 datasec, relsec,
163 &errmsg))
164 {
165 if (errmsg == NULL)
166 einfo ("%B%X: can not create runtime reloc information: %E\n",
167 abfd);
168 else
169 einfo ("%X%B: can not create runtime reloc information: %s\n",
170 abfd, errmsg);
171 }
172 }
173 }
174
175 static char *
176 gld${EMULATION_NAME}_get_script (int *isfile)
177 EOF
178
179 if test -n "$COMPILE_IN"
180 then
181 # Scripts compiled in.
182
183 # sed commands to quote an ld script as a C string.
184 sc="-f stringify.sed"
185
186 cat >>e${EMULATION_NAME}.c <<EOF
187 {
188 *isfile = 0;
189
190 if (link_info.relocatable && config.build_constructors)
191 return
192 EOF
193 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
194 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
195 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
196 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
197 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
198 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
199 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
200 echo ' ; else return' >> e${EMULATION_NAME}.c
201 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
202 echo '; }' >> e${EMULATION_NAME}.c
203
204 else
205 # Scripts read from the filesystem.
206
207 cat >>e${EMULATION_NAME}.c <<EOF
208 {
209 *isfile = 1;
210
211 if (link_info.relocatable && config.build_constructors)
212 return "ldscripts/${EMULATION_NAME}.xu";
213 else if (link_info.relocatable)
214 return "ldscripts/${EMULATION_NAME}.xr";
215 else if (!config.text_read_only)
216 return "ldscripts/${EMULATION_NAME}.xbn";
217 else if (!config.magic_demand_paged)
218 return "ldscripts/${EMULATION_NAME}.xn";
219 else
220 return "ldscripts/${EMULATION_NAME}.x";
221 }
222 EOF
223
224 fi
225
226 cat >>e${EMULATION_NAME}.c <<EOF
227
228 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
229 {
230 gld${EMULATION_NAME}_before_parse,
231 syslib_default,
232 hll_default,
233 after_parse_default,
234 gld${EMULATION_NAME}_after_open,
235 gld${EMULATION_NAME}_after_allocation,
236 set_output_arch_default,
237 ldemul_default_target,
238 before_allocation_default,
239 gld${EMULATION_NAME}_get_script,
240 "${EMULATION_NAME}",
241 "${OUTPUT_FORMAT}",
242 NULL, /* finish */
243 NULL, /* create output section statements */
244 NULL, /* open dynamic archive */
245 NULL, /* place orphan */
246 NULL, /* set symbols */
247 NULL, /* parse args */
248 NULL, /* add_options */
249 NULL, /* handle_option */
250 NULL, /* unrecognized file */
251 NULL, /* list options */
252 NULL, /* recognized file */
253 NULL, /* find_potential_libraries */
254 NULL /* new_vers_pattern */
255 };
256 EOF
This page took 0.034537 seconds and 4 git commands to generate.