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