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