* emultempl/aix.em: Convert to C90, remove unnecessary prototypes
[deliverable/binutils-gdb.git] / ld / emultempl / mipsecoff.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
0c7a8e5a 3if [ -z "$MACHINE" ]; then
86af25fe
L
4 OUTPUT_ARCH=${ARCH}
5else
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
7fi
252b5132
RH
8cat >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.
3bcf5557
AM
12 Copyright 1994, 1995, 1997, 2000, 2002, 2003
13 Free Software Foundation, Inc.
252b5132
RH
14 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
15
16This file is part of GLD, the Gnu Linker.
17
18This program is free software; you can redistribute it and/or modify
19it under the terms of the GNU General Public License as published by
20the Free Software Foundation; either version 2 of the License, or
21(at your option) any later version.
22
23This program is distributed in the hope that it will be useful,
24but WITHOUT ANY WARRANTY; without even the implied warranty of
25MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26GNU General Public License for more details.
27
28You should have received a copy of the GNU General Public License
29along with this program; if not, write to the Free Software
30Foundation, 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"
252b5132
RH
40#include "ldmisc.h"
41
b71e2778
AM
42#include "ldexp.h"
43#include "ldlang.h"
44#include "ldfile.h"
45#include "ldemul.h"
46
0c7a8e5a 47static void check_sections (bfd *, asection *, void *);
252b5132
RH
48
49static void
0c7a8e5a 50gld${EMULATION_NAME}_before_parse (void)
252b5132
RH
51{
52#ifndef TARGET_ /* I.e., if not generic. */
86af25fe
L
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};
252b5132
RH
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
72static void
0c7a8e5a 73gld${EMULATION_NAME}_after_open (void)
252b5132
RH
74{
75 bfd *abfd;
76
77 if (! command_line.embedded_relocs
1049f94e 78 || link_info.relocatable)
252b5132
RH
79 return;
80
81 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
82 {
83 asection *datasec;
84
57a6fd07
DB
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
252b5132
RH
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. */
0c7a8e5a 118 bfd_map_over_sections (abfd, check_sections, datasec);
252b5132
RH
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
125static void
0c7a8e5a 126check_sections (bfd *abfd, asection *sec, void *sdatasec)
252b5132
RH
127{
128 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
0c7a8e5a 129 && sec != sdatasec
252b5132 130 && sec->reloc_count != 0)
57a6fd07 131 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
252b5132
RH
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
139static void
0c7a8e5a 140gld${EMULATION_NAME}_after_allocation (void)
252b5132
RH
141{
142 bfd *abfd;
143
144 if (! command_line.embedded_relocs
1049f94e 145 || link_info.relocatable)
252b5132
RH
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
175static char *
0c7a8e5a 176gld${EMULATION_NAME}_get_script (int *isfile)
252b5132
RH
177EOF
178
179if test -n "$COMPILE_IN"
180then
181# Scripts compiled in.
182
183# sed commands to quote an ld script as a C string.
597e2591 184sc="-f stringify.sed"
252b5132
RH
185
186cat >>e${EMULATION_NAME}.c <<EOF
0c7a8e5a 187{
252b5132
RH
188 *isfile = 0;
189
1049f94e 190 if (link_info.relocatable && config.build_constructors)
252b5132
RH
191 return
192EOF
b34976b6 193sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 194echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
195sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
196echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
197sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
198echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
199sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
200echo ' ; else return' >> e${EMULATION_NAME}.c
201sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
202echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
203
204else
205# Scripts read from the filesystem.
206
207cat >>e${EMULATION_NAME}.c <<EOF
0c7a8e5a 208{
252b5132
RH
209 *isfile = 1;
210
1049f94e 211 if (link_info.relocatable && config.build_constructors)
252b5132 212 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 213 else if (link_info.relocatable)
252b5132
RH
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}
222EOF
223
224fi
225
226cat >>e${EMULATION_NAME}.c <<EOF
227
0c7a8e5a 228struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132
RH
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}",
e1c47aa4
AM
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 */
3bcf5557
AM
248 NULL, /* add_options */
249 NULL, /* handle_option */
e1c47aa4
AM
250 NULL, /* unrecognized file */
251 NULL, /* list options */
40d109bf 252 NULL, /* recognized file */
fac1652d
AM
253 NULL, /* find_potential_libraries */
254 NULL /* new_vers_pattern */
252b5132
RH
255};
256EOF
This page took 0.189724 seconds and 4 git commands to generate.