]>
Commit | Line | Data |
---|---|---|
dc5df17b ILT |
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! */ | |
5 | ||
6 | /* Handle embedded relocs for MIPS. | |
7 | Copyright 1994 Free Software Foundation, Inc. | |
8 | Written by Ian Lance Taylor <[email protected]> based on generic.em. | |
9 | ||
10 | This file is part of GLD, the Gnu Linker. | |
11 | ||
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. | |
16 | ||
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. | |
21 | ||
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. */ | |
25 | ||
26 | #define TARGET_IS_${EMULATION_NAME} | |
27 | ||
28 | #include "bfd.h" | |
29 | #include "sysdep.h" | |
30 | #include "bfdlink.h" | |
31 | ||
32 | #include "ld.h" | |
33 | #include "config.h" | |
34 | #include "ldmain.h" | |
35 | #include "ldemul.h" | |
36 | #include "ldfile.h" | |
37 | #include "ldmisc.h" | |
38 | ||
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)); | |
44 | ||
45 | static void | |
46 | gld${EMULATION_NAME}_before_parse() | |
47 | { | |
48 | #ifndef TARGET_ /* I.e., if not generic. */ | |
49 | ldfile_output_architecture = bfd_arch_${ARCH}; | |
50 | #endif /* not TARGET_ */ | |
51 | } | |
52 | ||
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. */ | |
59 | ||
60 | static void | |
61 | gld${EMULATION_NAME}_after_open () | |
62 | { | |
63 | bfd *abfd; | |
64 | ||
65 | if (! command_line.embedded_relocs | |
66 | || link_info.relocateable) | |
67 | return; | |
68 | ||
69 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
70 | { | |
71 | asection *datasec; | |
72 | ||
73 | datasec = bfd_get_section_by_name (abfd, ".sdata"); | |
74 | ||
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) | |
83 | { | |
84 | asection *relsec; | |
85 | ||
86 | relsec = bfd_make_section (abfd, ".rel.sdata"); | |
87 | if (relsec == NULL | |
88 | || ! bfd_set_section_flags (abfd, relsec, | |
89 | (SEC_ALLOC | |
90 | | SEC_LOAD | |
91 | | SEC_HAS_CONTENTS | |
92 | | SEC_IN_MEMORY)) | |
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"); | |
97 | } | |
98 | ||
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); | |
102 | } | |
103 | } | |
104 | ||
105 | /* Check that of the data sections, only the .sdata section has | |
106 | relocs. This is called via bfd_map_over_sections. */ | |
107 | ||
108 | static void | |
109 | check_sections (abfd, sec, sdatasec) | |
110 | bfd *abfd; | |
111 | asection *sec; | |
112 | PTR sdatasec; | |
113 | { | |
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)); | |
119 | } | |
120 | ||
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. */ | |
124 | ||
125 | static void | |
126 | gld${EMULATION_NAME}_after_allocation () | |
127 | { | |
128 | bfd *abfd; | |
129 | ||
130 | if (! command_line.embedded_relocs | |
131 | || link_info.relocateable) | |
132 | return; | |
133 | ||
134 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
135 | { | |
136 | asection *datasec, *relsec; | |
137 | char *errmsg; | |
138 | ||
139 | datasec = bfd_get_section_by_name (abfd, ".sdata"); | |
140 | ||
141 | if (datasec == NULL || datasec->reloc_count == 0) | |
142 | continue; | |
143 | ||
144 | relsec = bfd_get_section_by_name (abfd, ".rel.sdata"); | |
145 | ASSERT (relsec != NULL); | |
146 | ||
147 | if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info, | |
148 | datasec, relsec, | |
149 | &errmsg)) | |
150 | { | |
151 | if (errmsg == NULL) | |
152 | einfo ("%B%X: can not create runtime reloc information: %E", | |
153 | abfd); | |
154 | else | |
155 | einfo ("%X%B: can not create runtime reloc information: %s", | |
156 | abfd, errmsg); | |
157 | } | |
158 | } | |
159 | } | |
160 | ||
161 | static char * | |
162 | gld${EMULATION_NAME}_get_script(isfile) | |
163 | int *isfile; | |
164 | EOF | |
165 | ||
166 | if test -n "$COMPILE_IN" | |
167 | then | |
168 | # Scripts compiled in. | |
169 | ||
170 | # sed commands to quote an ld script as a C string. | |
171 | sc="-f ${srcdir}/emultempl/stringify.sed" | |
172 | ||
173 | cat >>e${EMULATION_NAME}.c <<EOF | |
174 | { | |
175 | *isfile = 0; | |
176 | ||
177 | if (link_info.relocateable == true && config.build_constructors == true) | |
178 | return | |
179 | EOF | |
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 | |
190 | ||
191 | else | |
192 | # Scripts read from the filesystem. | |
193 | ||
194 | cat >>e${EMULATION_NAME}.c <<EOF | |
195 | { | |
196 | *isfile = 1; | |
197 | ||
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"; | |
206 | else | |
207 | return "ldscripts/${EMULATION_NAME}.x"; | |
208 | } | |
209 | EOF | |
210 | ||
211 | fi | |
212 | ||
213 | cat >>e${EMULATION_NAME}.c <<EOF | |
214 | ||
215 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = | |
216 | { | |
217 | gld${EMULATION_NAME}_before_parse, | |
218 | syslib_default, | |
219 | hll_default, | |
220 | after_parse_default, | |
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, | |
227 | "${EMULATION_NAME}", | |
228 | "${OUTPUT_FORMAT}" | |
229 | }; | |
230 | EOF |