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