1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 if [ -z "$MACHINE" ]; then
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
8 cat >e${EMULATION_NAME}.c <<EOF
9 /* This file is is generated by a shell script. DO NOT EDIT! */
11 /* Handle embedded relocs for MIPS.
12 Copyright 1994, 1995, 1997, 2000, 2002, 2003
13 Free Software Foundation, Inc.
14 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
16 This file is part of GLD, the Gnu Linker.
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 #define TARGET_IS_${EMULATION_NAME}
47 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
48 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
49 static void check_sections PARAMS ((bfd *, asection *, PTR));
50 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
51 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
54 gld${EMULATION_NAME}_before_parse()
56 #ifndef TARGET_ /* I.e., if not generic. */
57 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
60 ldfile_output_architecture = arch->arch;
61 ldfile_output_machine = arch->mach;
62 ldfile_output_machine_name = arch->printable_name;
65 ldfile_output_architecture = bfd_arch_${ARCH};
66 #endif /* not TARGET_ */
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. */
77 gld${EMULATION_NAME}_after_open ()
81 if (! command_line.embedded_relocs
82 || link_info.relocateable)
85 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
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");
94 datasec = bfd_get_section_by_name (abfd, ".sdata");
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)
107 relsec = bfd_make_section (abfd, ".rel.sdata");
109 || ! bfd_set_section_flags (abfd, relsec,
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");
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);
126 /* Check that of the data sections, only the .sdata section has
127 relocs. This is called via bfd_map_over_sections. */
130 check_sections (abfd, sec, sdatasec)
135 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
136 && sec != (asection *) sdatasec
137 && sec->reloc_count != 0)
138 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
139 abfd, bfd_get_section_name (abfd, sec));
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. */
147 gld${EMULATION_NAME}_after_allocation ()
151 if (! command_line.embedded_relocs
152 || link_info.relocateable)
155 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
157 asection *datasec, *relsec;
160 datasec = bfd_get_section_by_name (abfd, ".sdata");
162 if (datasec == NULL || datasec->reloc_count == 0)
165 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
166 ASSERT (relsec != NULL);
168 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
173 einfo ("%B%X: can not create runtime reloc information: %E\n",
176 einfo ("%X%B: can not create runtime reloc information: %s\n",
183 gld${EMULATION_NAME}_get_script(isfile)
187 if test -n "$COMPILE_IN"
189 # Scripts compiled in.
191 # sed commands to quote an ld script as a C string.
192 sc="-f stringify.sed"
194 cat >>e${EMULATION_NAME}.c <<EOF
198 if (link_info.relocateable && config.build_constructors)
201 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
202 echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
203 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
204 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
205 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
206 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
207 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
208 echo ' ; else return' >> e${EMULATION_NAME}.c
209 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
210 echo '; }' >> e${EMULATION_NAME}.c
213 # Scripts read from the filesystem.
215 cat >>e${EMULATION_NAME}.c <<EOF
219 if (link_info.relocateable && config.build_constructors)
220 return "ldscripts/${EMULATION_NAME}.xu";
221 else if (link_info.relocateable)
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";
228 return "ldscripts/${EMULATION_NAME}.x";
234 cat >>e${EMULATION_NAME}.c <<EOF
236 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
238 gld${EMULATION_NAME}_before_parse,
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,
251 NULL, /* create output section statements */
252 NULL, /* open dynamic archive */
253 NULL, /* place orphan */
254 NULL, /* set symbols */
255 NULL, /* parse args */
256 NULL, /* add_options */
257 NULL, /* handle_option */
258 NULL, /* unrecognized file */
259 NULL, /* list options */
260 NULL, /* recognized file */
261 NULL, /* find_potential_libraries */
262 NULL /* new_vers_pattern */