* emulparams/elf64alpha.sh (EXTRA_EM_FILE): Define.
[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.
86af25fe
L
3if [ -z "$MACHINE" ]; then
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
252b5132
RH
47static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
48static void gld${EMULATION_NAME}_after_open PARAMS ((void));
49static void check_sections PARAMS ((bfd *, asection *, PTR));
50static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
51static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
52
53static void
54gld${EMULATION_NAME}_before_parse()
55{
56#ifndef TARGET_ /* I.e., if not generic. */
86af25fe
L
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};
252b5132
RH
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
76static void
77gld${EMULATION_NAME}_after_open ()
78{
79 bfd *abfd;
80
81 if (! command_line.embedded_relocs
82 || link_info.relocateable)
83 return;
84
85 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
86 {
87 asection *datasec;
88
57a6fd07
DB
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
252b5132
RH
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
129static void
130check_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)
57a6fd07 138 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
252b5132
RH
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
146static void
147gld${EMULATION_NAME}_after_allocation ()
148{
149 bfd *abfd;
150
151 if (! command_line.embedded_relocs
152 || link_info.relocateable)
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
182static char *
183gld${EMULATION_NAME}_get_script(isfile)
184 int *isfile;
185EOF
186
187if test -n "$COMPILE_IN"
188then
189# Scripts compiled in.
190
191# sed commands to quote an ld script as a C string.
597e2591 192sc="-f stringify.sed"
252b5132
RH
193
194cat >>e${EMULATION_NAME}.c <<EOF
195{
196 *isfile = 0;
197
b34976b6 198 if (link_info.relocateable && config.build_constructors)
252b5132
RH
199 return
200EOF
b34976b6
AM
201sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
202echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
203sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
204echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
205sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
206echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
207sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
208echo ' ; else return' >> e${EMULATION_NAME}.c
209sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
210echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
211
212else
213# Scripts read from the filesystem.
214
215cat >>e${EMULATION_NAME}.c <<EOF
216{
217 *isfile = 1;
218
b34976b6 219 if (link_info.relocateable && config.build_constructors)
252b5132 220 return "ldscripts/${EMULATION_NAME}.xu";
b34976b6 221 else if (link_info.relocateable)
252b5132
RH
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}
230EOF
231
232fi
233
234cat >>e${EMULATION_NAME}.c <<EOF
235
236struct 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}",
e1c47aa4
AM
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 */
3bcf5557
AM
256 NULL, /* add_options */
257 NULL, /* handle_option */
e1c47aa4
AM
258 NULL, /* unrecognized file */
259 NULL, /* list options */
40d109bf 260 NULL, /* recognized file */
fac1652d
AM
261 NULL, /* find_potential_libraries */
262 NULL /* new_vers_pattern */
252b5132
RH
263};
264EOF
This page took 0.15744 seconds and 4 git commands to generate.