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 Free Software Foundation, Inc.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #define TARGET_IS_${EMULATION_NAME}
39 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
40 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
41 static void check_sections PARAMS ((bfd *, asection *, PTR));
42 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
43 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
46 gld${EMULATION_NAME}_before_parse()
48 #ifndef TARGET_ /* I.e., if not generic. */
49 ldfile_output_architecture = bfd_arch_${ARCH};
50 #endif /* not TARGET_ */
53 /* This function is run after all the input files have been opened.
54 We create a .rel.sdata section for each input file with a non zero
55 .sdata section. The BFD backend will fill in these sections with
56 magic numbers which can be used to relocate the data section at run
57 time. This will only do the right thing if all the input files
58 have been compiled using -membedded-pic. */
61 gld${EMULATION_NAME}_after_open ()
65 if (! command_line.embedded_relocs
66 || link_info.relocateable)
69 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
73 datasec = bfd_get_section_by_name (abfd, ".sdata");
75 /* Note that we assume that the reloc_count field has already
76 been set up. We could call bfd_get_reloc_upper_bound, but
77 that returns the size of a memory buffer rather than a reloc
78 count. We do not want to call bfd_canonicalize_reloc,
79 because although it would always work it would force us to
80 read in the relocs into BFD canonical form, which would waste
81 a significant amount of time and memory. */
82 if (datasec != NULL && datasec->reloc_count > 0)
86 relsec = bfd_make_section (abfd, ".rel.sdata");
88 || ! bfd_set_section_flags (abfd, relsec,
93 || ! bfd_set_section_alignment (abfd, relsec, 2)
94 || ! bfd_set_section_size (abfd, relsec,
95 datasec->reloc_count * 4))
96 einfo ("%F%B: can not create .rel.sdata section: %E");
99 /* Double check that all other data sections are empty, as is
100 required for embedded PIC code. */
101 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
105 /* Check that of the data sections, only the .sdata section has
106 relocs. This is called via bfd_map_over_sections. */
109 check_sections (abfd, sec, sdatasec)
114 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
115 && sec != (asection *) sdatasec
116 && sec->reloc_count != 0)
117 einfo ("%F%X: section %s has relocs; can not use --embedded-relocs",
118 abfd, bfd_get_section_name (abfd, sec));
121 /* This function is called after the section sizes and offsets have
122 been set. If we are generating embedded relocs, it calls a special
123 BFD backend routine to do the work. */
126 gld${EMULATION_NAME}_after_allocation ()
130 if (! command_line.embedded_relocs
131 || link_info.relocateable)
134 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
136 asection *datasec, *relsec;
139 datasec = bfd_get_section_by_name (abfd, ".sdata");
141 if (datasec == NULL || datasec->reloc_count == 0)
144 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
145 ASSERT (relsec != NULL);
147 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
152 einfo ("%B%X: can not create runtime reloc information: %E",
155 einfo ("%X%B: can not create runtime reloc information: %s",
162 gld${EMULATION_NAME}_get_script(isfile)
166 if test -n "$COMPILE_IN"
168 # Scripts compiled in.
170 # sed commands to quote an ld script as a C string.
171 sc="-f ${srcdir}/emultempl/stringify.sed"
173 cat >>e${EMULATION_NAME}.c <<EOF
177 if (link_info.relocateable == true && config.build_constructors == true)
180 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
181 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
182 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
183 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
184 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
185 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
186 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
187 echo ' ; else return' >> e${EMULATION_NAME}.c
188 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
189 echo '; }' >> e${EMULATION_NAME}.c
192 # Scripts read from the filesystem.
194 cat >>e${EMULATION_NAME}.c <<EOF
198 if (link_info.relocateable == true && config.build_constructors == true)
199 return "ldscripts/${EMULATION_NAME}.xu";
200 else if (link_info.relocateable == true)
201 return "ldscripts/${EMULATION_NAME}.xr";
202 else if (!config.text_read_only)
203 return "ldscripts/${EMULATION_NAME}.xbn";
204 else if (!config.magic_demand_paged)
205 return "ldscripts/${EMULATION_NAME}.xn";
207 return "ldscripts/${EMULATION_NAME}.x";
213 cat >>e${EMULATION_NAME}.c <<EOF
215 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
217 gld${EMULATION_NAME}_before_parse,
221 gld${EMULATION_NAME}_after_open,
222 gld${EMULATION_NAME}_after_allocation,
223 set_output_arch_default,
224 ldemul_default_target,
225 before_allocation_default,
226 gld${EMULATION_NAME}_get_script,