1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >e${EMULATION_NAME}.c <<EOF
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 Free Software Foundation, Inc.
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>.
12 This file is part of GLD, the Gnu Linker.
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 2 of the License, or
17 (at your option) any later version.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #define TARGET_IS_${EMULATION_NAME}
40 static void check_sections (bfd *, asection *, void *);
43 gld${EMULATION_NAME}_before_parse (void)
45 #ifndef TARGET_ /* I.e., if not generic. */
46 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
47 #endif /* not TARGET_ */
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
57 gld${EMULATION_NAME}_after_open (void)
61 if (! command_line.embedded_relocs
62 || link_info.relocatable)
65 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
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");
74 datasec = bfd_get_section_by_name (abfd, ".data");
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)
87 relsec = bfd_make_section (abfd, ".emreloc");
89 || ! bfd_set_section_flags (abfd, relsec,
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");
100 /* Double check that all other data sections are empty, as is
101 required for embedded PIC code. */
102 bfd_map_over_sections (abfd, check_sections, datasec);
106 /* Check that of the data sections, only the .data section has
107 relocs. This is called via bfd_map_over_sections. */
110 check_sections (bfd *abfd, asection *sec, void *datasec)
112 if ((bfd_get_section_flags (abfd, sec) & SEC_DATA)
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));
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. */
124 gld${EMULATION_NAME}_after_allocation (void)
128 if (! command_line.embedded_relocs
129 || link_info.relocatable)
132 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
134 asection *datasec, *relsec;
137 datasec = bfd_get_section_by_name (abfd, ".data");
139 if (datasec == NULL || datasec->reloc_count == 0)
142 relsec = bfd_get_section_by_name (abfd, ".emreloc");
143 ASSERT (relsec != NULL);
145 if (! bfd_m68k_coff_create_embedded_relocs (abfd, &link_info,
150 einfo ("%B%X: can not create runtime reloc information: %E\n",
153 einfo ("%X%B: can not create runtime reloc information: %s\n",
160 gld${EMULATION_NAME}_get_script (int *isfile)
163 if test -n "$COMPILE_IN"
165 # Scripts compiled in.
167 # sed commands to quote an ld script as a C string.
168 sc="-f stringify.sed"
170 cat >>e${EMULATION_NAME}.c <<EOF
174 if (link_info.relocatable && config.build_constructors)
177 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
178 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
179 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
180 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
181 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
182 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
183 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
184 echo ' ; else return' >> e${EMULATION_NAME}.c
185 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
186 echo '; }' >> e${EMULATION_NAME}.c
189 # Scripts read from the filesystem.
191 cat >>e${EMULATION_NAME}.c <<EOF
195 if (link_info.relocatable && config.build_constructors)
196 return "ldscripts/${EMULATION_NAME}.xu";
197 else if (link_info.relocatable)
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";
204 return "ldscripts/${EMULATION_NAME}.x";
210 cat >>e${EMULATION_NAME}.c <<EOF
212 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
214 gld${EMULATION_NAME}_before_parse,
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,
227 NULL, /* create output section statements */
228 NULL, /* open dynamic archive */
229 NULL, /* place orphan */
230 NULL, /* set symbols */
231 NULL, /* parse args */
232 NULL, /* add_options */
233 NULL, /* handle_option */
234 NULL, /* unrecognized file */
235 NULL, /* list options */
236 NULL, /* recognized file */
237 NULL, /* find_potential_libraries */
238 NULL /* new_vers_pattern */