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 Free Software Foundation, Inc.
13 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
15 This file is part of GLD, the Gnu Linker.
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #define TARGET_IS_${EMULATION_NAME}
46 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
47 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
48 static void check_sections PARAMS ((bfd *, asection *, PTR));
49 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
50 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
53 gld${EMULATION_NAME}_before_parse()
55 #ifndef TARGET_ /* I.e., if not generic. */
56 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
59 ldfile_output_architecture = arch->arch;
60 ldfile_output_machine = arch->mach;
61 ldfile_output_machine_name = arch->printable_name;
64 ldfile_output_architecture = bfd_arch_${ARCH};
65 #endif /* not TARGET_ */
68 /* This function is run after all the input files have been opened.
69 We create a .rel.sdata section for each input file with a non zero
70 .sdata section. The BFD backend will fill in these sections with
71 magic numbers which can be used to relocate the data section at run
72 time. This will only do the right thing if all the input files
73 have been compiled using -membedded-pic. */
76 gld${EMULATION_NAME}_after_open ()
80 if (! command_line.embedded_relocs
81 || link_info.relocateable)
84 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
88 /* As first-order business, make sure that each input BFD is ECOFF. It
89 better be, as we are directly calling an ECOFF backend function. */
90 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour)
91 einfo ("%F%B: all input objects must be ECOFF for --embedded-relocs\n");
93 datasec = bfd_get_section_by_name (abfd, ".sdata");
95 /* Note that we assume that the reloc_count field has already
96 been set up. We could call bfd_get_reloc_upper_bound, but
97 that returns the size of a memory buffer rather than a reloc
98 count. We do not want to call bfd_canonicalize_reloc,
99 because although it would always work it would force us to
100 read in the relocs into BFD canonical form, which would waste
101 a significant amount of time and memory. */
102 if (datasec != NULL && datasec->reloc_count > 0)
106 relsec = bfd_make_section (abfd, ".rel.sdata");
108 || ! bfd_set_section_flags (abfd, relsec,
113 || ! bfd_set_section_alignment (abfd, relsec, 2)
114 || ! bfd_set_section_size (abfd, relsec,
115 datasec->reloc_count * 4))
116 einfo ("%F%B: can not create .rel.sdata section: %E\n");
119 /* Double check that all other data sections are empty, as is
120 required for embedded PIC code. */
121 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
125 /* Check that of the data sections, only the .sdata section has
126 relocs. This is called via bfd_map_over_sections. */
129 check_sections (abfd, sec, sdatasec)
134 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
135 && sec != (asection *) sdatasec
136 && sec->reloc_count != 0)
137 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
138 abfd, bfd_get_section_name (abfd, sec));
141 /* This function is called after the section sizes and offsets have
142 been set. If we are generating embedded relocs, it calls a special
143 BFD backend routine to do the work. */
146 gld${EMULATION_NAME}_after_allocation ()
150 if (! command_line.embedded_relocs
151 || link_info.relocateable)
154 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
156 asection *datasec, *relsec;
159 datasec = bfd_get_section_by_name (abfd, ".sdata");
161 if (datasec == NULL || datasec->reloc_count == 0)
164 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
165 ASSERT (relsec != NULL);
167 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
172 einfo ("%B%X: can not create runtime reloc information: %E\n",
175 einfo ("%X%B: can not create runtime reloc information: %s\n",
182 gld${EMULATION_NAME}_get_script(isfile)
186 if test -n "$COMPILE_IN"
188 # Scripts compiled in.
190 # sed commands to quote an ld script as a C string.
191 sc="-f stringify.sed"
193 cat >>e${EMULATION_NAME}.c <<EOF
197 if (link_info.relocateable == true && config.build_constructors == true)
200 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
201 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
202 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
203 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
204 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
205 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
206 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
207 echo ' ; else return' >> e${EMULATION_NAME}.c
208 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
209 echo '; }' >> e${EMULATION_NAME}.c
212 # Scripts read from the filesystem.
214 cat >>e${EMULATION_NAME}.c <<EOF
218 if (link_info.relocateable == true && config.build_constructors == true)
219 return "ldscripts/${EMULATION_NAME}.xu";
220 else if (link_info.relocateable == true)
221 return "ldscripts/${EMULATION_NAME}.xr";
222 else if (!config.text_read_only)
223 return "ldscripts/${EMULATION_NAME}.xbn";
224 else if (!config.magic_demand_paged)
225 return "ldscripts/${EMULATION_NAME}.xn";
227 return "ldscripts/${EMULATION_NAME}.x";
233 cat >>e${EMULATION_NAME}.c <<EOF
235 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
237 gld${EMULATION_NAME}_before_parse,
241 gld${EMULATION_NAME}_after_open,
242 gld${EMULATION_NAME}_after_allocation,
243 set_output_arch_default,
244 ldemul_default_target,
245 before_allocation_default,
246 gld${EMULATION_NAME}_get_script,
250 NULL, /* create output section statements */
251 NULL, /* open dynamic archive */
252 NULL, /* place orphan */
253 NULL, /* set symbols */
254 NULL, /* parse args */
255 NULL, /* unrecognized file */
256 NULL, /* list options */
257 NULL, /* recognized file */
258 NULL, /* find_potential_libraries */
259 NULL /* new_vers_pattern */