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 check_sections (bfd *, asection *, void *);
50 gld${EMULATION_NAME}_before_parse (void)
52 #ifndef TARGET_ /* I.e., if not generic. */
53 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
56 ldfile_output_architecture = arch->arch;
57 ldfile_output_machine = arch->mach;
58 ldfile_output_machine_name = arch->printable_name;
61 ldfile_output_architecture = bfd_arch_${ARCH};
62 #endif /* not TARGET_ */
65 /* This function is run after all the input files have been opened.
66 We create a .rel.sdata section for each input file with a non zero
67 .sdata section. The BFD backend will fill in these sections with
68 magic numbers which can be used to relocate the data section at run
69 time. This will only do the right thing if all the input files
70 have been compiled using -membedded-pic. */
73 gld${EMULATION_NAME}_after_open (void)
77 if (! command_line.embedded_relocs
78 || link_info.relocatable)
81 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
85 /* As first-order business, make sure that each input BFD is ECOFF. It
86 better be, as we are directly calling an ECOFF backend function. */
87 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour)
88 einfo ("%F%B: all input objects must be ECOFF for --embedded-relocs\n");
90 datasec = bfd_get_section_by_name (abfd, ".sdata");
92 /* Note that we assume that the reloc_count field has already
93 been set up. We could call bfd_get_reloc_upper_bound, but
94 that returns the size of a memory buffer rather than a reloc
95 count. We do not want to call bfd_canonicalize_reloc,
96 because although it would always work it would force us to
97 read in the relocs into BFD canonical form, which would waste
98 a significant amount of time and memory. */
99 if (datasec != NULL && datasec->reloc_count > 0)
103 relsec = bfd_make_section (abfd, ".rel.sdata");
105 || ! bfd_set_section_flags (abfd, relsec,
110 || ! bfd_set_section_alignment (abfd, relsec, 2)
111 || ! bfd_set_section_size (abfd, relsec,
112 datasec->reloc_count * 4))
113 einfo ("%F%B: can not create .rel.sdata section: %E\n");
116 /* Double check that all other data sections are empty, as is
117 required for embedded PIC code. */
118 bfd_map_over_sections (abfd, check_sections, datasec);
122 /* Check that of the data sections, only the .sdata section has
123 relocs. This is called via bfd_map_over_sections. */
126 check_sections (bfd *abfd, asection *sec, void *sdatasec)
128 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
130 && sec->reloc_count != 0)
131 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
132 abfd, bfd_get_section_name (abfd, sec));
135 /* This function is called after the section sizes and offsets have
136 been set. If we are generating embedded relocs, it calls a special
137 BFD backend routine to do the work. */
140 gld${EMULATION_NAME}_after_allocation (void)
144 if (! command_line.embedded_relocs
145 || link_info.relocatable)
148 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
150 asection *datasec, *relsec;
153 datasec = bfd_get_section_by_name (abfd, ".sdata");
155 if (datasec == NULL || datasec->reloc_count == 0)
158 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
159 ASSERT (relsec != NULL);
161 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
166 einfo ("%B%X: can not create runtime reloc information: %E\n",
169 einfo ("%X%B: can not create runtime reloc information: %s\n",
176 gld${EMULATION_NAME}_get_script (int *isfile)
179 if test -n "$COMPILE_IN"
181 # Scripts compiled in.
183 # sed commands to quote an ld script as a C string.
184 sc="-f stringify.sed"
186 cat >>e${EMULATION_NAME}.c <<EOF
190 if (link_info.relocatable && config.build_constructors)
193 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
194 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
195 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
196 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
197 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
198 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
199 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
200 echo ' ; else return' >> e${EMULATION_NAME}.c
201 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
202 echo '; }' >> e${EMULATION_NAME}.c
205 # Scripts read from the filesystem.
207 cat >>e${EMULATION_NAME}.c <<EOF
211 if (link_info.relocatable && config.build_constructors)
212 return "ldscripts/${EMULATION_NAME}.xu";
213 else if (link_info.relocatable)
214 return "ldscripts/${EMULATION_NAME}.xr";
215 else if (!config.text_read_only)
216 return "ldscripts/${EMULATION_NAME}.xbn";
217 else if (!config.magic_demand_paged)
218 return "ldscripts/${EMULATION_NAME}.xn";
220 return "ldscripts/${EMULATION_NAME}.x";
226 cat >>e${EMULATION_NAME}.c <<EOF
228 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
230 gld${EMULATION_NAME}_before_parse,
234 gld${EMULATION_NAME}_after_open,
235 gld${EMULATION_NAME}_after_allocation,
236 set_output_arch_default,
237 ldemul_default_target,
238 before_allocation_default,
239 gld${EMULATION_NAME}_get_script,
243 NULL, /* create output section statements */
244 NULL, /* open dynamic archive */
245 NULL, /* place orphan */
246 NULL, /* set symbols */
247 NULL, /* parse args */
248 NULL, /* add_options */
249 NULL, /* handle_option */
250 NULL, /* unrecognized file */
251 NULL, /* list options */
252 NULL, /* recognized file */
253 NULL, /* find_potential_libraries */
254 NULL /* new_vers_pattern */