]>
Commit | Line | Data |
---|---|---|
20bccb34 NC |
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 m68k. | |
8423293d | 7 | Copyright 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
20bccb34 NC |
8 | Written by Michael Sokolov <[email protected]>, based on generic.em |
9 | by Steve Chamberlain <[email protected]>, embedded relocs code based on | |
10 | mipsecoff.em by Ian Lance Taylor <[email protected]>. | |
11 | ||
12 | This file is part of GLD, the Gnu Linker. | |
13 | ||
14 | This program is free software; you can redistribute it and/or modify | |
15 | it under the terms of the GNU General Public License as published by | |
16 | the Free Software Foundation; either version 2 of the License, or | |
17 | (at your option) any later version. | |
18 | ||
19 | This program is distributed in the hope that it will be useful, | |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | GNU General Public License for more details. | |
23 | ||
24 | You should have received a copy of the GNU General Public License | |
25 | along with this program; if not, write to the Free Software | |
75be928b | 26 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
20bccb34 NC |
27 | |
28 | #define TARGET_IS_${EMULATION_NAME} | |
29 | ||
30 | #include "bfd.h" | |
31 | #include "sysdep.h" | |
32 | #include "bfdlink.h" | |
33 | ||
34 | #include "ld.h" | |
35 | #include "ldmain.h" | |
187ffe95 NC |
36 | #include "ldexp.h" |
37 | #include "ldlang.h" | |
20bccb34 | 38 | #include "ldfile.h" |
41392f03 | 39 | #include "ldemul.h" |
20bccb34 NC |
40 | #include "ldmisc.h" |
41 | ||
0c7a8e5a | 42 | static void check_sections (bfd *, asection *, void *); |
20bccb34 NC |
43 | |
44 | static void | |
0c7a8e5a | 45 | gld${EMULATION_NAME}_before_parse (void) |
20bccb34 NC |
46 | { |
47 | #ifndef TARGET_ /* I.e., if not generic. */ | |
5e2f1575 | 48 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
20bccb34 NC |
49 | #endif /* not TARGET_ */ |
50 | } | |
51 | ||
52 | /* This function is run after all the input files have been opened. | |
53 | We create a .emreloc section for each input file with a non zero | |
54 | .data 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. */ | |
57 | ||
58 | static void | |
0c7a8e5a | 59 | gld${EMULATION_NAME}_after_open (void) |
20bccb34 NC |
60 | { |
61 | bfd *abfd; | |
62 | ||
63 | if (! command_line.embedded_relocs | |
1049f94e | 64 | || link_info.relocatable) |
20bccb34 NC |
65 | return; |
66 | ||
67 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
68 | { | |
69 | asection *datasec; | |
70 | ||
71 | /* As first-order business, make sure that each input BFD is COFF. It | |
72 | better be, as we are directly calling a COFF backend function. */ | |
73 | if (bfd_get_flavour (abfd) != bfd_target_coff_flavour) | |
74 | einfo ("%F%B: all input objects must be COFF for --embedded-relocs\n"); | |
75 | ||
76 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
77 | ||
78 | /* Note that we assume that the reloc_count field has already | |
79 | been set up. We could call bfd_get_reloc_upper_bound, but | |
80 | that returns the size of a memory buffer rather than a reloc | |
81 | count. We do not want to call bfd_canonicalize_reloc, | |
82 | because although it would always work it would force us to | |
83 | read in the relocs into BFD canonical form, which would waste | |
84 | a significant amount of time and memory. */ | |
85 | if (datasec != NULL && datasec->reloc_count > 0) | |
86 | { | |
87 | asection *relsec; | |
88 | ||
89 | relsec = bfd_make_section (abfd, ".emreloc"); | |
90 | if (relsec == NULL | |
91 | || ! bfd_set_section_flags (abfd, relsec, | |
92 | (SEC_ALLOC | |
93 | | SEC_LOAD | |
94 | | SEC_HAS_CONTENTS | |
95 | | SEC_IN_MEMORY)) | |
96 | || ! bfd_set_section_alignment (abfd, relsec, 2) | |
97 | || ! bfd_set_section_size (abfd, relsec, | |
98 | datasec->reloc_count * 12)) | |
99 | einfo ("%F%B: can not create .emreloc section: %E\n"); | |
100 | } | |
101 | ||
102 | /* Double check that all other data sections are empty, as is | |
103 | required for embedded PIC code. */ | |
1579bae1 | 104 | bfd_map_over_sections (abfd, check_sections, datasec); |
20bccb34 NC |
105 | } |
106 | } | |
107 | ||
108 | /* Check that of the data sections, only the .data section has | |
109 | relocs. This is called via bfd_map_over_sections. */ | |
110 | ||
111 | static void | |
0c7a8e5a | 112 | check_sections (bfd *abfd, asection *sec, void *datasec) |
20bccb34 NC |
113 | { |
114 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
0c7a8e5a | 115 | && sec != datasec |
20bccb34 NC |
116 | && sec->reloc_count != 0) |
117 | einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n", | |
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 | |
0c7a8e5a | 126 | gld${EMULATION_NAME}_after_allocation (void) |
20bccb34 NC |
127 | { |
128 | bfd *abfd; | |
129 | ||
130 | if (! command_line.embedded_relocs | |
1049f94e | 131 | || link_info.relocatable) |
20bccb34 NC |
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, ".data"); | |
140 | ||
141 | if (datasec == NULL || datasec->reloc_count == 0) | |
142 | continue; | |
143 | ||
144 | relsec = bfd_get_section_by_name (abfd, ".emreloc"); | |
145 | ASSERT (relsec != NULL); | |
146 | ||
147 | if (! bfd_m68k_coff_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\n", | |
153 | abfd); | |
154 | else | |
155 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
156 | abfd, errmsg); | |
157 | } | |
158 | } | |
159 | } | |
160 | ||
161 | static char * | |
0c7a8e5a | 162 | gld${EMULATION_NAME}_get_script (int *isfile) |
20bccb34 NC |
163 | EOF |
164 | ||
165 | if test -n "$COMPILE_IN" | |
166 | then | |
167 | # Scripts compiled in. | |
168 | ||
169 | # sed commands to quote an ld script as a C string. | |
170 | sc="-f stringify.sed" | |
171 | ||
172 | cat >>e${EMULATION_NAME}.c <<EOF | |
0c7a8e5a | 173 | { |
20bccb34 NC |
174 | *isfile = 0; |
175 | ||
1049f94e | 176 | if (link_info.relocatable && config.build_constructors) |
20bccb34 NC |
177 | return |
178 | EOF | |
b34976b6 | 179 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
1049f94e | 180 | echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c |
b34976b6 AM |
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 | |
20bccb34 NC |
189 | |
190 | else | |
191 | # Scripts read from the filesystem. | |
192 | ||
193 | cat >>e${EMULATION_NAME}.c <<EOF | |
0c7a8e5a | 194 | { |
20bccb34 NC |
195 | *isfile = 1; |
196 | ||
1049f94e | 197 | if (link_info.relocatable && config.build_constructors) |
20bccb34 | 198 | return "ldscripts/${EMULATION_NAME}.xu"; |
1049f94e | 199 | else if (link_info.relocatable) |
20bccb34 NC |
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"; | |
205 | else | |
206 | return "ldscripts/${EMULATION_NAME}.x"; | |
207 | } | |
208 | EOF | |
209 | ||
210 | fi | |
211 | ||
212 | cat >>e${EMULATION_NAME}.c <<EOF | |
213 | ||
0c7a8e5a | 214 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
20bccb34 NC |
215 | { |
216 | gld${EMULATION_NAME}_before_parse, | |
217 | syslib_default, | |
218 | hll_default, | |
219 | after_parse_default, | |
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, | |
5e797c2c | 225 | do_assignments_default, |
20bccb34 NC |
226 | gld${EMULATION_NAME}_get_script, |
227 | "${EMULATION_NAME}", | |
228 | "${OUTPUT_FORMAT}", | |
229 | NULL, /* finish */ | |
230 | NULL, /* create output section statements */ | |
231 | NULL, /* open dynamic archive */ | |
232 | NULL, /* place orphan */ | |
233 | NULL, /* set symbols */ | |
234 | NULL, /* parse args */ | |
3bcf5557 AM |
235 | NULL, /* add_options */ |
236 | NULL, /* handle_option */ | |
20bccb34 NC |
237 | NULL, /* unrecognized file */ |
238 | NULL, /* list options */ | |
239 | NULL, /* recognized file */ | |
fac1652d AM |
240 | NULL, /* find_potential_libraries */ |
241 | NULL /* new_vers_pattern */ | |
20bccb34 NC |
242 | }; |
243 | EOF |