1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
4 /* This file is is generated by a shell script. DO NOT EDIT! */
6 /* Handle embedded relocs for m68k.
7 Copyright 2000, 2002, 2003, 2004, 2005, 2007
8 Free Software Foundation, Inc.
9 Written by Michael Sokolov <msokolov@ivan.Harhan.ORG>, based on generic.em
10 by Steve Chamberlain <steve@cygnus.com>, embedded relocs code based on
11 mipsecoff.em by Ian Lance Taylor <ian@cygnus.com>.
13 This file is part of the GNU Binutils.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
28 MA 02110-1301, USA. */
30 #define TARGET_IS_${EMULATION_NAME}
44 static void check_sections (bfd *, asection *, void *);
47 gld${EMULATION_NAME}_before_parse (void)
49 #ifndef TARGET_ /* I.e., if not generic. */
50 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
51 #endif /* not TARGET_ */
54 /* This function is run after all the input files have been opened.
55 We create a .emreloc section for each input file with a non zero
56 .data section. The BFD backend will fill in these sections with
57 magic numbers which can be used to relocate the data section at run
61 gld${EMULATION_NAME}_after_open (void)
65 if (! command_line.embedded_relocs
66 || link_info.relocatable)
69 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
73 /* As first-order business, make sure that each input BFD is COFF. It
74 better be, as we are directly calling a COFF backend function. */
75 if (bfd_get_flavour (abfd) != bfd_target_coff_flavour)
76 einfo ("%F%B: all input objects must be COFF for --embedded-relocs\n");
78 datasec = bfd_get_section_by_name (abfd, ".data");
80 /* Note that we assume that the reloc_count field has already
81 been set up. We could call bfd_get_reloc_upper_bound, but
82 that returns the size of a memory buffer rather than a reloc
83 count. We do not want to call bfd_canonicalize_reloc,
84 because although it would always work it would force us to
85 read in the relocs into BFD canonical form, which would waste
86 a significant amount of time and memory. */
87 if (datasec != NULL && datasec->reloc_count > 0)
91 relsec = bfd_make_section (abfd, ".emreloc");
93 || ! bfd_set_section_flags (abfd, relsec,
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");
104 /* Double check that all other data sections are empty, as is
105 required for embedded PIC code. */
106 bfd_map_over_sections (abfd, check_sections, datasec);
110 /* Check that of the data sections, only the .data section has
111 relocs. This is called via bfd_map_over_sections. */
114 check_sections (bfd *abfd, asection *sec, void *datasec)
116 if ((bfd_get_section_flags (abfd, sec) & SEC_DATA)
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));
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. */
128 gld${EMULATION_NAME}_after_allocation (void)
132 if (! command_line.embedded_relocs
133 || link_info.relocatable)
136 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
138 asection *datasec, *relsec;
141 datasec = bfd_get_section_by_name (abfd, ".data");
143 if (datasec == NULL || datasec->reloc_count == 0)
146 relsec = bfd_get_section_by_name (abfd, ".emreloc");
147 ASSERT (relsec != NULL);
149 if (! bfd_m68k_coff_create_embedded_relocs (abfd, &link_info,
154 einfo ("%B%X: can not create runtime reloc information: %E\n",
157 einfo ("%X%B: can not create runtime reloc information: %s\n",
164 gld${EMULATION_NAME}_get_script (int *isfile)
167 if test -n "$COMPILE_IN"
169 # Scripts compiled in.
171 # sed commands to quote an ld script as a C string.
172 sc="-f stringify.sed"
178 if (link_info.relocatable && config.build_constructors)
181 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
182 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
183 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
184 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
185 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
186 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
187 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
188 echo ' ; else return' >> e${EMULATION_NAME}.c
189 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
190 echo '; }' >> e${EMULATION_NAME}.c
193 # Scripts read from the filesystem.
199 if (link_info.relocatable && config.build_constructors)
200 return "ldscripts/${EMULATION_NAME}.xu";
201 else if (link_info.relocatable)
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";
208 return "ldscripts/${EMULATION_NAME}.x";
216 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
218 gld${EMULATION_NAME}_before_parse,
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,
231 NULL, /* create output section statements */
232 NULL, /* open dynamic archive */
233 NULL, /* place orphan */
234 NULL, /* set symbols */
235 NULL, /* parse args */
236 NULL, /* add_options */
237 NULL, /* handle_option */
238 NULL, /* unrecognized file */
239 NULL, /* list options */
240 NULL, /* recognized file */
241 NULL, /* find_potential_libraries */
242 NULL /* new_vers_pattern */