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.
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 datasec = bfd_get_section_by_name (abfd, ".sdata");
74 /* Note that we assume that the reloc_count field has already
75 been set up. We could call bfd_get_reloc_upper_bound, but
76 that returns the size of a memory buffer rather than a reloc
77 count. We do not want to call bfd_canonicalize_reloc,
78 because although it would always work it would force us to
79 read in the relocs into BFD canonical form, which would waste
80 a significant amount of time and memory. */
81 if (datasec != NULL && datasec->reloc_count > 0)
85 relsec = bfd_make_section (abfd, ".rel.sdata");
87 || ! bfd_set_section_flags (abfd, relsec,
92 || ! bfd_set_section_alignment (abfd, relsec, 2)
93 || ! bfd_set_section_size (abfd, relsec,
94 datasec->reloc_count * 4))
95 einfo ("%F%B: can not create .rel.sdata section: %E\n");
98 /* Double check that all other data sections are empty, as is
99 required for embedded PIC code. */
100 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
104 /* Check that of the data sections, only the .sdata section has
105 relocs. This is called via bfd_map_over_sections. */
108 check_sections (abfd, sec, sdatasec)
113 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
114 && sec != (asection *) sdatasec
115 && sec->reloc_count != 0)
116 einfo ("%P%X: section %s has relocs; can not use --embedded-relocs\n",
117 abfd, bfd_get_section_name (abfd, sec));
120 /* This function is called after the section sizes and offsets have
121 been set. If we are generating embedded relocs, it calls a special
122 BFD backend routine to do the work. */
125 gld${EMULATION_NAME}_after_allocation ()
129 if (! command_line.embedded_relocs
130 || link_info.relocateable)
133 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
135 asection *datasec, *relsec;
138 datasec = bfd_get_section_by_name (abfd, ".sdata");
140 if (datasec == NULL || datasec->reloc_count == 0)
143 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
144 ASSERT (relsec != NULL);
146 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
151 einfo ("%B%X: can not create runtime reloc information: %E\n",
154 einfo ("%X%B: can not create runtime reloc information: %s\n",
161 gld${EMULATION_NAME}_get_script(isfile)
165 if test -n "$COMPILE_IN"
167 # Scripts compiled in.
169 # sed commands to quote an ld script as a C string.
170 sc="-f ${srcdir}/emultempl/stringify.sed"
172 cat >>e${EMULATION_NAME}.c <<EOF
176 if (link_info.relocateable == true && config.build_constructors == true)
179 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
180 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
181 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
182 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
183 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
184 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
185 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
186 echo ' ; else return' >> e${EMULATION_NAME}.c
187 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
188 echo '; }' >> e${EMULATION_NAME}.c
191 # Scripts read from the filesystem.
193 cat >>e${EMULATION_NAME}.c <<EOF
197 if (link_info.relocateable == true && config.build_constructors == true)
198 return "ldscripts/${EMULATION_NAME}.xu";
199 else if (link_info.relocateable == true)
200 return "ldscripts/${EMULATION_NAME}.xr";
201 else if (!config.text_read_only)
202 return "ldscripts/${EMULATION_NAME}.xbn";
203 else if (!config.magic_demand_paged)
204 return "ldscripts/${EMULATION_NAME}.xn";
206 return "ldscripts/${EMULATION_NAME}.x";
212 cat >>e${EMULATION_NAME}.c <<EOF
214 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
216 gld${EMULATION_NAME}_before_parse,
220 gld${EMULATION_NAME}_after_open,
221 gld${EMULATION_NAME}_after_allocation,
222 set_output_arch_default,
223 ldemul_default_target,
224 before_allocation_default,
225 gld${EMULATION_NAME}_get_script,