]>
Commit | Line | Data |
---|---|---|
20bccb34 NC |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
92b93329 | 3 | fragment <<EOF |
20bccb34 NC |
4 | /* This file is is generated by a shell script. DO NOT EDIT! */ |
5 | ||
6 | /* Handle embedded relocs for m68k. | |
219d1afa | 7 | Copyright (C) 2000-2018 Free Software Foundation, Inc. |
20bccb34 NC |
8 | Written by Michael Sokolov <msokolov@ivan.Harhan.ORG>, based on generic.em |
9 | by Steve Chamberlain <steve@cygnus.com>, embedded relocs code based on | |
e8044f35 | 10 | mipsecoff.em by Ian Lance Taylor <ian@cygnus.com> (now removed). |
20bccb34 | 11 | |
f96b4a7b NC |
12 | This file is part of the GNU Binutils. |
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 3 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 | |
26 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
27 | MA 02110-1301, USA. */ | |
20bccb34 NC |
28 | |
29 | #define TARGET_IS_${EMULATION_NAME} | |
30 | ||
20bccb34 | 31 | #include "sysdep.h" |
3db64b00 | 32 | #include "bfd.h" |
20bccb34 NC |
33 | #include "bfdlink.h" |
34 | ||
35 | #include "ld.h" | |
36 | #include "ldmain.h" | |
187ffe95 NC |
37 | #include "ldexp.h" |
38 | #include "ldlang.h" | |
20bccb34 | 39 | #include "ldfile.h" |
41392f03 | 40 | #include "ldemul.h" |
20bccb34 NC |
41 | #include "ldmisc.h" |
42 | ||
0c7a8e5a | 43 | static void check_sections (bfd *, asection *, void *); |
20bccb34 NC |
44 | |
45 | static void | |
0c7a8e5a | 46 | gld${EMULATION_NAME}_before_parse (void) |
20bccb34 NC |
47 | { |
48 | #ifndef TARGET_ /* I.e., if not generic. */ | |
5e2f1575 | 49 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
20bccb34 NC |
50 | #endif /* not TARGET_ */ |
51 | } | |
52 | ||
53 | /* This function is run after all the input files have been opened. | |
54 | We create a .emreloc section for each input file with a non zero | |
55 | .data 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. */ | |
58 | ||
59 | static void | |
0c7a8e5a | 60 | gld${EMULATION_NAME}_after_open (void) |
20bccb34 NC |
61 | { |
62 | bfd *abfd; | |
63 | ||
5c3049d2 AM |
64 | after_open_default (); |
65 | ||
20bccb34 | 66 | if (! command_line.embedded_relocs |
0e1862bb | 67 | || bfd_link_relocatable (&link_info)) |
20bccb34 NC |
68 | return; |
69 | ||
c72f2fb2 | 70 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) |
20bccb34 NC |
71 | { |
72 | asection *datasec; | |
73 | ||
74 | /* As first-order business, make sure that each input BFD is COFF. It | |
6c19b93b | 75 | better be, as we are directly calling a COFF backend function. */ |
20bccb34 | 76 | if (bfd_get_flavour (abfd) != bfd_target_coff_flavour) |
df5f2391 | 77 | einfo (_("%F%P: %pB: all input objects must be COFF " |
d003af55 | 78 | "for --embedded-relocs\n")); |
20bccb34 NC |
79 | |
80 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
81 | ||
82 | /* Note that we assume that the reloc_count field has already | |
6c19b93b AM |
83 | been set up. We could call bfd_get_reloc_upper_bound, but |
84 | that returns the size of a memory buffer rather than a reloc | |
85 | count. We do not want to call bfd_canonicalize_reloc, | |
86 | because although it would always work it would force us to | |
87 | read in the relocs into BFD canonical form, which would waste | |
88 | a significant amount of time and memory. */ | |
20bccb34 NC |
89 | if (datasec != NULL && datasec->reloc_count > 0) |
90 | { | |
91 | asection *relsec; | |
92 | ||
9795b468 AM |
93 | relsec = bfd_make_section_with_flags (abfd, ".emreloc", |
94 | (SEC_ALLOC | |
95 | | SEC_LOAD | |
96 | | SEC_HAS_CONTENTS | |
97 | | SEC_IN_MEMORY)); | |
20bccb34 | 98 | if (relsec == NULL |
20bccb34 NC |
99 | || ! bfd_set_section_alignment (abfd, relsec, 2) |
100 | || ! bfd_set_section_size (abfd, relsec, | |
101 | datasec->reloc_count * 12)) | |
df5f2391 | 102 | einfo (_("%F%P: %pB: can not create .emreloc section: %E\n")); |
20bccb34 NC |
103 | } |
104 | ||
105 | /* Double check that all other data sections are empty, as is | |
6c19b93b | 106 | required for embedded PIC code. */ |
1579bae1 | 107 | bfd_map_over_sections (abfd, check_sections, datasec); |
20bccb34 NC |
108 | } |
109 | } | |
110 | ||
111 | /* Check that of the data sections, only the .data section has | |
112 | relocs. This is called via bfd_map_over_sections. */ | |
113 | ||
114 | static void | |
0c7a8e5a | 115 | check_sections (bfd *abfd, asection *sec, void *datasec) |
20bccb34 NC |
116 | { |
117 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
0c7a8e5a | 118 | && sec != datasec |
20bccb34 | 119 | && sec->reloc_count != 0) |
df5f2391 | 120 | einfo (_("%X%P: %pB: section %s has relocs; can not use --embedded-relocs\n"), |
20bccb34 NC |
121 | abfd, bfd_get_section_name (abfd, sec)); |
122 | } | |
123 | ||
124 | /* This function is called after the section sizes and offsets have | |
125 | been set. If we are generating embedded relocs, it calls a special | |
126 | BFD backend routine to do the work. */ | |
127 | ||
128 | static void | |
0c7a8e5a | 129 | gld${EMULATION_NAME}_after_allocation (void) |
20bccb34 NC |
130 | { |
131 | bfd *abfd; | |
132 | ||
133 | if (! command_line.embedded_relocs | |
0e1862bb | 134 | || bfd_link_relocatable (&link_info)) |
20bccb34 NC |
135 | return; |
136 | ||
c72f2fb2 | 137 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) |
20bccb34 NC |
138 | { |
139 | asection *datasec, *relsec; | |
140 | char *errmsg; | |
141 | ||
142 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
143 | ||
144 | if (datasec == NULL || datasec->reloc_count == 0) | |
145 | continue; | |
146 | ||
147 | relsec = bfd_get_section_by_name (abfd, ".emreloc"); | |
148 | ASSERT (relsec != NULL); | |
149 | ||
150 | if (! bfd_m68k_coff_create_embedded_relocs (abfd, &link_info, | |
151 | datasec, relsec, | |
152 | &errmsg)) | |
153 | { | |
154 | if (errmsg == NULL) | |
df5f2391 | 155 | einfo (_("%X%P: %pB: can not create runtime reloc information: %E\n"), |
20bccb34 NC |
156 | abfd); |
157 | else | |
df5f2391 | 158 | einfo (_("%X%P: %pB: can not create runtime reloc information: %s\n"), |
20bccb34 NC |
159 | abfd, errmsg); |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | static char * | |
0c7a8e5a | 165 | gld${EMULATION_NAME}_get_script (int *isfile) |
20bccb34 NC |
166 | EOF |
167 | ||
7225345d | 168 | if test x"$COMPILE_IN" = xyes |
20bccb34 NC |
169 | then |
170 | # Scripts compiled in. | |
171 | ||
172 | # sed commands to quote an ld script as a C string. | |
173 | sc="-f stringify.sed" | |
174 | ||
92b93329 | 175 | fragment <<EOF |
0c7a8e5a | 176 | { |
20bccb34 NC |
177 | *isfile = 0; |
178 | ||
0e1862bb | 179 | if (bfd_link_relocatable (&link_info) && config.build_constructors) |
20bccb34 NC |
180 | return |
181 | EOF | |
b34976b6 | 182 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
0e1862bb | 183 | echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c |
b34976b6 AM |
184 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c |
185 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
186 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
187 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
188 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
189 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
190 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
191 | echo '; }' >> e${EMULATION_NAME}.c | |
20bccb34 NC |
192 | |
193 | else | |
194 | # Scripts read from the filesystem. | |
195 | ||
92b93329 | 196 | fragment <<EOF |
0c7a8e5a | 197 | { |
20bccb34 NC |
198 | *isfile = 1; |
199 | ||
0e1862bb | 200 | if (bfd_link_relocatable (&link_info) && config.build_constructors) |
20bccb34 | 201 | return "ldscripts/${EMULATION_NAME}.xu"; |
0e1862bb | 202 | else if (bfd_link_relocatable (&link_info)) |
20bccb34 NC |
203 | return "ldscripts/${EMULATION_NAME}.xr"; |
204 | else if (!config.text_read_only) | |
205 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
206 | else if (!config.magic_demand_paged) | |
207 | return "ldscripts/${EMULATION_NAME}.xn"; | |
208 | else | |
209 | return "ldscripts/${EMULATION_NAME}.x"; | |
210 | } | |
211 | EOF | |
212 | ||
213 | fi | |
214 | ||
92b93329 | 215 | fragment <<EOF |
20bccb34 | 216 | |
0c7a8e5a | 217 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
20bccb34 NC |
218 | { |
219 | gld${EMULATION_NAME}_before_parse, | |
220 | syslib_default, | |
221 | hll_default, | |
222 | after_parse_default, | |
5c3261b0 | 223 | after_check_relocs_default, |
20bccb34 NC |
224 | gld${EMULATION_NAME}_after_open, |
225 | gld${EMULATION_NAME}_after_allocation, | |
226 | set_output_arch_default, | |
227 | ldemul_default_target, | |
228 | before_allocation_default, | |
229 | gld${EMULATION_NAME}_get_script, | |
230 | "${EMULATION_NAME}", | |
231 | "${OUTPUT_FORMAT}", | |
1e035701 | 232 | finish_default, |
20bccb34 NC |
233 | NULL, /* create output section statements */ |
234 | NULL, /* open dynamic archive */ | |
235 | NULL, /* place orphan */ | |
236 | NULL, /* set symbols */ | |
237 | NULL, /* parse args */ | |
3bcf5557 AM |
238 | NULL, /* add_options */ |
239 | NULL, /* handle_option */ | |
20bccb34 NC |
240 | NULL, /* unrecognized file */ |
241 | NULL, /* list options */ | |
242 | NULL, /* recognized file */ | |
fac1652d | 243 | NULL, /* find_potential_libraries */ |
7a2f2d82 DD |
244 | NULL, /* new_vers_pattern */ |
245 | NULL /* extra_map_file_text */ | |
20bccb34 NC |
246 | }; |
247 | EOF |