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 MIPS.
7 Copyright 1994, 95, 97, 1999 Free Software Foundation, Inc.
8 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
10 This file is part of GLD, the Gnu Linker.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #define TARGET_IS_${EMULATION_NAME}
38 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
39 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
40 static void check_sections PARAMS ((bfd *, asection *, PTR));
41 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
42 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
45 gld${EMULATION_NAME}_before_parse()
47 #ifndef TARGET_ /* I.e., if not generic. */
48 ldfile_output_architecture = bfd_arch_${ARCH};
49 #endif /* not TARGET_ */
52 /* This function is run after all the input files have been opened.
53 We create a .rel.sdata section for each input file with a non zero
54 .sdata section. The BFD backend will fill in these sections with
55 magic numbers which can be used to relocate the data section at run
56 time. This will only do the right thing if all the input files
57 have been compiled using -membedded-pic. */
60 gld${EMULATION_NAME}_after_open ()
64 if (! command_line.embedded_relocs
65 || link_info.relocateable)
68 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
72 /* As first-order business, make sure that each input BFD is ECOFF. It
73 better be, as we are directly calling an ECOFF backend function. */
74 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour)
75 einfo ("%F%B: all input objects must be ECOFF for --embedded-relocs\n");
77 datasec = bfd_get_section_by_name (abfd, ".sdata");
79 /* Note that we assume that the reloc_count field has already
80 been set up. We could call bfd_get_reloc_upper_bound, but
81 that returns the size of a memory buffer rather than a reloc
82 count. We do not want to call bfd_canonicalize_reloc,
83 because although it would always work it would force us to
84 read in the relocs into BFD canonical form, which would waste
85 a significant amount of time and memory. */
86 if (datasec != NULL && datasec->reloc_count > 0)
90 relsec = bfd_make_section (abfd, ".rel.sdata");
92 || ! bfd_set_section_flags (abfd, relsec,
97 || ! bfd_set_section_alignment (abfd, relsec, 2)
98 || ! bfd_set_section_size (abfd, relsec,
99 datasec->reloc_count * 4))
100 einfo ("%F%B: can not create .rel.sdata section: %E\n");
103 /* Double check that all other data sections are empty, as is
104 required for embedded PIC code. */
105 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
109 /* Check that of the data sections, only the .sdata section has
110 relocs. This is called via bfd_map_over_sections. */
113 check_sections (abfd, sec, sdatasec)
118 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
119 && sec != (asection *) sdatasec
120 && sec->reloc_count != 0)
121 einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n",
122 abfd, bfd_get_section_name (abfd, sec));
125 /* This function is called after the section sizes and offsets have
126 been set. If we are generating embedded relocs, it calls a special
127 BFD backend routine to do the work. */
130 gld${EMULATION_NAME}_after_allocation ()
134 if (! command_line.embedded_relocs
135 || link_info.relocateable)
138 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
140 asection *datasec, *relsec;
143 datasec = bfd_get_section_by_name (abfd, ".sdata");
145 if (datasec == NULL || datasec->reloc_count == 0)
148 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
149 ASSERT (relsec != NULL);
151 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
156 einfo ("%B%X: can not create runtime reloc information: %E\n",
159 einfo ("%X%B: can not create runtime reloc information: %s\n",
166 gld${EMULATION_NAME}_get_script(isfile)
170 if test -n "$COMPILE_IN"
172 # Scripts compiled in.
174 # sed commands to quote an ld script as a C string.
175 sc="-f stringify.sed"
177 cat >>e${EMULATION_NAME}.c <<EOF
181 if (link_info.relocateable == true && config.build_constructors == true)
184 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
185 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
186 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
187 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
188 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
189 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
190 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
191 echo ' ; else return' >> e${EMULATION_NAME}.c
192 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
193 echo '; }' >> e${EMULATION_NAME}.c
196 # Scripts read from the filesystem.
198 cat >>e${EMULATION_NAME}.c <<EOF
202 if (link_info.relocateable == true && config.build_constructors == true)
203 return "ldscripts/${EMULATION_NAME}.xu";
204 else if (link_info.relocateable == true)
205 return "ldscripts/${EMULATION_NAME}.xr";
206 else if (!config.text_read_only)
207 return "ldscripts/${EMULATION_NAME}.xbn";
208 else if (!config.magic_demand_paged)
209 return "ldscripts/${EMULATION_NAME}.xn";
211 return "ldscripts/${EMULATION_NAME}.x";
217 cat >>e${EMULATION_NAME}.c <<EOF
219 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
221 gld${EMULATION_NAME}_before_parse,
225 gld${EMULATION_NAME}_after_open,
226 gld${EMULATION_NAME}_after_allocation,
227 set_output_arch_default,
228 ldemul_default_target,
229 before_allocation_default,
230 gld${EMULATION_NAME}_get_script,
234 NULL, /* create output section statements */
235 NULL, /* open dynamic archive */
236 NULL, /* place orphan */
237 NULL, /* set symbols */
238 NULL, /* parse args */
239 NULL, /* unrecognized file */
240 NULL, /* list options */
241 NULL, /* recognized file */
242 NULL /* find_potential_libraries */