Commit | Line | Data |
---|---|---|
0752970e | 1 | # This shell script emits a C file. -*- C -*- |
aa820537 AM |
2 | # Copyright 2000, 2001, 2003, 2005, 2007, 2008, 2009 |
3 | # Free Software Foundation, Inc. | |
0752970e NC |
4 | # Written by Michael Sokolov <msokolov@ivan.Harhan.ORG>, based on armelf.em |
5 | # | |
f96b4a7b | 6 | # This file is part of the GNU Binutils. |
0752970e NC |
7 | # |
8 | # This program is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
f96b4a7b | 10 | # the Free Software Foundation; either version 3 of the License, or |
0752970e NC |
11 | # (at your option) any later version. |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
f96b4a7b NC |
20 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | # MA 02110-1301, USA. | |
22 | ||
0752970e | 23 | |
36bdbeec NC |
24 | # This file is sourced from elf32.em, and defines some extra routines for m68k |
25 | # embedded systems using ELF and for some other systems using m68k ELF. While | |
26 | # it is sourced from elf32.em for all m68k ELF configurations, here we include | |
27 | # only the features we want depending on the configuration. | |
28 | ||
29 | case ${target} in | |
30 | m68*-*-elf) | |
31 | echo "#define SUPPORT_EMBEDDED_RELOCS" >>e${EMULATION_NAME}.c | |
32 | ;; | |
33 | esac | |
34 | ||
7fb9f789 NC |
35 | case ${target} in |
36 | *-linux*) | |
37 | # Don't use multi-GOT by default due to glibc linker's assumption | |
38 | # that GOT pointer points to GOT[0]. | |
39 | # got_handling_target_default=GOT_HANDLING_MULTIGOT | |
40 | got_handling_target_default=GOT_HANDLING_SINGLE | |
41 | ;; | |
42 | *) | |
43 | got_handling_target_default=GOT_HANDLING_SINGLE | |
44 | ;; | |
45 | esac | |
46 | ||
92b93329 | 47 | fragment <<EOF |
0752970e | 48 | |
7fb9f789 NC |
49 | #define GOT_HANDLING_SINGLE (0) |
50 | #define GOT_HANDLING_NEGATIVE (1) | |
51 | #define GOT_HANDLING_MULTIGOT (2) | |
52 | #define GOT_HANDLING_TARGET_DEFAULT ${got_handling_target_default} | |
53 | ||
54 | /* How to generate GOT. */ | |
55 | static int got_handling = GOT_HANDLING_DEFAULT; | |
56 | ||
36bdbeec | 57 | #ifdef SUPPORT_EMBEDDED_RELOCS |
0c7a8e5a | 58 | static void check_sections (bfd *, asection *, void *); |
36bdbeec | 59 | #endif |
0752970e | 60 | |
36bdbeec | 61 | /* This function is run after all the input files have been opened. */ |
0752970e NC |
62 | |
63 | static void | |
0c7a8e5a | 64 | m68k_elf_after_open (void) |
0752970e | 65 | { |
0752970e NC |
66 | /* Call the standard elf routine. */ |
67 | gld${EMULATION_NAME}_after_open (); | |
68 | ||
36bdbeec NC |
69 | #ifdef SUPPORT_EMBEDDED_RELOCS |
70 | if (command_line.embedded_relocs | |
1049f94e | 71 | && (! link_info.relocatable)) |
0752970e | 72 | { |
36bdbeec NC |
73 | bfd *abfd; |
74 | ||
75 | /* In the embedded relocs mode we create a .emreloc section for each | |
76 | input file with a nonzero .data section. The BFD backend will fill in | |
77 | these sections with magic numbers which can be used to relocate the | |
78 | data section at run time. */ | |
79 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
0752970e | 80 | { |
36bdbeec NC |
81 | asection *datasec; |
82 | ||
83 | /* As first-order business, make sure that each input BFD is either | |
84 | COFF or ELF. We need to call a special BFD backend function to | |
85 | generate the embedded relocs, and we have such functions only for | |
86 | COFF and ELF. */ | |
87 | if (bfd_get_flavour (abfd) != bfd_target_coff_flavour | |
88 | && bfd_get_flavour (abfd) != bfd_target_elf_flavour) | |
89 | einfo ("%F%B: all input objects must be COFF or ELF for --embedded-relocs\n"); | |
90 | ||
91 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
92 | ||
93 | /* Note that we assume that the reloc_count field has already | |
94 | been set up. We could call bfd_get_reloc_upper_bound, but | |
95 | that returns the size of a memory buffer rather than a reloc | |
96 | count. We do not want to call bfd_canonicalize_reloc, | |
97 | because although it would always work it would force us to | |
98 | read in the relocs into BFD canonical form, which would waste | |
99 | a significant amount of time and memory. */ | |
100 | if (datasec != NULL && datasec->reloc_count > 0) | |
101 | { | |
102 | asection *relsec; | |
103 | ||
9795b468 AM |
104 | relsec = bfd_make_section_with_flags (abfd, ".emreloc", |
105 | (SEC_ALLOC | |
106 | | SEC_LOAD | |
107 | | SEC_HAS_CONTENTS | |
108 | | SEC_IN_MEMORY)); | |
36bdbeec | 109 | if (relsec == NULL |
36bdbeec NC |
110 | || ! bfd_set_section_alignment (abfd, relsec, 2) |
111 | || ! bfd_set_section_size (abfd, relsec, | |
112 | datasec->reloc_count * 12)) | |
113 | einfo ("%F%B: can not create .emreloc section: %E\n"); | |
114 | } | |
115 | ||
116 | /* Double check that all other data sections are empty, as is | |
117 | required for embedded PIC code. */ | |
1579bae1 | 118 | bfd_map_over_sections (abfd, check_sections, datasec); |
0752970e | 119 | } |
0752970e | 120 | } |
36bdbeec | 121 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
0752970e NC |
122 | } |
123 | ||
36bdbeec | 124 | #ifdef SUPPORT_EMBEDDED_RELOCS |
0752970e NC |
125 | /* Check that of the data sections, only the .data section has |
126 | relocs. This is called via bfd_map_over_sections. */ | |
127 | ||
128 | static void | |
1579bae1 | 129 | check_sections (bfd *abfd, asection *sec, void *datasec) |
0752970e NC |
130 | { |
131 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
1579bae1 | 132 | && sec != datasec |
0752970e NC |
133 | && sec->reloc_count != 0) |
134 | einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n", | |
135 | abfd, bfd_get_section_name (abfd, sec)); | |
136 | } | |
137 | ||
36bdbeec NC |
138 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
139 | ||
0752970e | 140 | /* This function is called after the section sizes and offsets have |
36bdbeec | 141 | been set. */ |
0752970e NC |
142 | |
143 | static void | |
0c7a8e5a | 144 | m68k_elf_after_allocation (void) |
0752970e | 145 | { |
0752970e | 146 | /* Call the standard elf routine. */ |
eaeb0a9d | 147 | gld${EMULATION_NAME}_after_allocation (); |
0752970e | 148 | |
36bdbeec NC |
149 | #ifdef SUPPORT_EMBEDDED_RELOCS |
150 | if (command_line.embedded_relocs | |
1049f94e | 151 | && (! link_info.relocatable)) |
0752970e | 152 | { |
36bdbeec | 153 | bfd *abfd; |
0752970e | 154 | |
36bdbeec NC |
155 | /* If we are generating embedded relocs, call a special BFD backend |
156 | routine to do the work. */ | |
157 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
0752970e | 158 | { |
36bdbeec NC |
159 | asection *datasec, *relsec; |
160 | char *errmsg; | |
161 | ||
162 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
163 | ||
164 | if (datasec == NULL || datasec->reloc_count == 0) | |
165 | continue; | |
166 | ||
167 | relsec = bfd_get_section_by_name (abfd, ".emreloc"); | |
168 | ASSERT (relsec != NULL); | |
169 | ||
170 | if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) | |
171 | { | |
172 | if (! bfd_m68k_coff_create_embedded_relocs (abfd, &link_info, | |
173 | datasec, relsec, | |
174 | &errmsg)) | |
175 | { | |
176 | if (errmsg == NULL) | |
177 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
178 | abfd); | |
179 | else | |
180 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
181 | abfd, errmsg); | |
182 | } | |
183 | } | |
184 | else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | |
185 | { | |
186 | if (! bfd_m68k_elf32_create_embedded_relocs (abfd, &link_info, | |
187 | datasec, relsec, | |
188 | &errmsg)) | |
189 | { | |
190 | if (errmsg == NULL) | |
191 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
192 | abfd); | |
193 | else | |
194 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
195 | abfd, errmsg); | |
196 | } | |
197 | } | |
0752970e | 198 | else |
36bdbeec | 199 | abort (); |
0752970e NC |
200 | } |
201 | } | |
36bdbeec | 202 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
0752970e NC |
203 | } |
204 | ||
7fb9f789 NC |
205 | /* This is a convenient point to tell BFD about target specific flags. |
206 | After the output has been created, but before inputs are read. */ | |
207 | ||
208 | static void | |
209 | elf_m68k_create_output_section_statements (void) | |
210 | { | |
211 | bfd_elf_m68k_set_target_options (&link_info, got_handling); | |
212 | } | |
213 | ||
0752970e NC |
214 | EOF |
215 | ||
7fb9f789 NC |
216 | # Define some shell vars to insert bits of code into the standard elf |
217 | # parse_args and list_options functions. | |
218 | # | |
219 | PARSE_AND_LIST_PROLOGUE=' | |
220 | #define OPTION_GOT 301 | |
221 | ' | |
222 | ||
223 | PARSE_AND_LIST_LONGOPTS=' | |
224 | { "got", required_argument, NULL, OPTION_GOT}, | |
225 | ' | |
226 | ||
227 | PARSE_AND_LIST_OPTIONS=' | |
228 | fprintf (file, _(" --got=<type> Specify GOT handling scheme\n")); | |
229 | ' | |
230 | ||
231 | PARSE_AND_LIST_ARGS_CASES=' | |
232 | case OPTION_GOT: | |
233 | if (strcmp (optarg, "target") == 0) | |
234 | got_handling = GOT_HANDLING_TARGET_DEFAULT; | |
235 | else if (strcmp (optarg, "single") == 0) | |
236 | got_handling = 0; | |
237 | else if (strcmp (optarg, "negative") == 0) | |
238 | got_handling = 1; | |
239 | else if (strcmp (optarg, "multigot") == 0) | |
240 | got_handling = 2; | |
241 | else | |
242 | einfo (_("Unrecognized --got argument '\''%s'\''.\n"), optarg); | |
243 | break; | |
244 | ' | |
245 | ||
0752970e NC |
246 | # We have our own after_open and after_allocation functions, but they call |
247 | # the standard routines, so give them a different name. | |
248 | LDEMUL_AFTER_OPEN=m68k_elf_after_open | |
249 | LDEMUL_AFTER_ALLOCATION=m68k_elf_after_allocation | |
7fb9f789 | 250 | LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=elf_m68k_create_output_section_statements |