Commit | Line | Data |
---|---|---|
0752970e | 1 | # This shell script emits a C file. -*- C -*- |
a2b64bed | 2 | # Copyright 2000, 2001 Free Software Foundation, Inc. |
0752970e NC |
3 | # Written by Michael Sokolov <msokolov@ivan.Harhan.ORG>, based on armelf.em |
4 | # | |
5 | # This file is part of GLD, the Gnu Linker. | |
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 | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
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 | |
19 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
0752970e | 20 | |
36bdbeec NC |
21 | # This file is sourced from elf32.em, and defines some extra routines for m68k |
22 | # embedded systems using ELF and for some other systems using m68k ELF. While | |
23 | # it is sourced from elf32.em for all m68k ELF configurations, here we include | |
24 | # only the features we want depending on the configuration. | |
25 | ||
26 | case ${target} in | |
27 | m68*-*-elf) | |
28 | echo "#define SUPPORT_EMBEDDED_RELOCS" >>e${EMULATION_NAME}.c | |
29 | ;; | |
30 | esac | |
31 | ||
0752970e NC |
32 | cat >>e${EMULATION_NAME}.c <<EOF |
33 | ||
36bdbeec NC |
34 | static void m68k_elf_after_open PARAMS ((void)); |
35 | #ifdef SUPPORT_EMBEDDED_RELOCS | |
0752970e | 36 | static void check_sections PARAMS ((bfd *, asection *, PTR)); |
36bdbeec | 37 | #endif |
0752970e NC |
38 | static void m68k_elf_after_allocation PARAMS ((void)); |
39 | ||
36bdbeec | 40 | /* This function is run after all the input files have been opened. */ |
0752970e NC |
41 | |
42 | static void | |
43 | m68k_elf_after_open () | |
44 | { | |
0752970e NC |
45 | /* Call the standard elf routine. */ |
46 | gld${EMULATION_NAME}_after_open (); | |
47 | ||
36bdbeec NC |
48 | #ifdef SUPPORT_EMBEDDED_RELOCS |
49 | if (command_line.embedded_relocs | |
50 | && (! link_info.relocateable)) | |
0752970e | 51 | { |
36bdbeec NC |
52 | bfd *abfd; |
53 | ||
54 | /* In the embedded relocs mode we create a .emreloc section for each | |
55 | input file with a nonzero .data section. The BFD backend will fill in | |
56 | these sections with magic numbers which can be used to relocate the | |
57 | data section at run time. */ | |
58 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
0752970e | 59 | { |
36bdbeec NC |
60 | asection *datasec; |
61 | ||
62 | /* As first-order business, make sure that each input BFD is either | |
63 | COFF or ELF. We need to call a special BFD backend function to | |
64 | generate the embedded relocs, and we have such functions only for | |
65 | COFF and ELF. */ | |
66 | if (bfd_get_flavour (abfd) != bfd_target_coff_flavour | |
67 | && bfd_get_flavour (abfd) != bfd_target_elf_flavour) | |
68 | einfo ("%F%B: all input objects must be COFF or ELF for --embedded-relocs\n"); | |
69 | ||
70 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
71 | ||
72 | /* Note that we assume that the reloc_count field has already | |
73 | been set up. We could call bfd_get_reloc_upper_bound, but | |
74 | that returns the size of a memory buffer rather than a reloc | |
75 | count. We do not want to call bfd_canonicalize_reloc, | |
76 | because although it would always work it would force us to | |
77 | read in the relocs into BFD canonical form, which would waste | |
78 | a significant amount of time and memory. */ | |
79 | if (datasec != NULL && datasec->reloc_count > 0) | |
80 | { | |
81 | asection *relsec; | |
82 | ||
83 | relsec = bfd_make_section (abfd, ".emreloc"); | |
84 | if (relsec == NULL | |
85 | || ! bfd_set_section_flags (abfd, relsec, | |
86 | (SEC_ALLOC | |
87 | | SEC_LOAD | |
88 | | SEC_HAS_CONTENTS | |
89 | | SEC_IN_MEMORY)) | |
90 | || ! bfd_set_section_alignment (abfd, relsec, 2) | |
91 | || ! bfd_set_section_size (abfd, relsec, | |
92 | datasec->reloc_count * 12)) | |
93 | einfo ("%F%B: can not create .emreloc section: %E\n"); | |
94 | } | |
95 | ||
96 | /* Double check that all other data sections are empty, as is | |
97 | required for embedded PIC code. */ | |
98 | bfd_map_over_sections (abfd, check_sections, (PTR) datasec); | |
0752970e | 99 | } |
0752970e | 100 | } |
36bdbeec | 101 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
0752970e NC |
102 | } |
103 | ||
36bdbeec | 104 | #ifdef SUPPORT_EMBEDDED_RELOCS |
0752970e NC |
105 | /* Check that of the data sections, only the .data section has |
106 | relocs. This is called via bfd_map_over_sections. */ | |
107 | ||
108 | static void | |
109 | check_sections (abfd, sec, datasec) | |
110 | bfd *abfd; | |
111 | asection *sec; | |
112 | PTR datasec; | |
113 | { | |
114 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
115 | && sec != (asection *) datasec | |
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 | ||
36bdbeec NC |
121 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
122 | ||
0752970e | 123 | /* This function is called after the section sizes and offsets have |
36bdbeec | 124 | been set. */ |
0752970e NC |
125 | |
126 | static void | |
127 | m68k_elf_after_allocation () | |
128 | { | |
0752970e | 129 | /* Call the standard elf routine. */ |
1c7566d1 | 130 | after_allocation_default (); |
0752970e | 131 | |
36bdbeec NC |
132 | #ifdef SUPPORT_EMBEDDED_RELOCS |
133 | if (command_line.embedded_relocs | |
134 | && (! link_info.relocateable)) | |
0752970e | 135 | { |
36bdbeec | 136 | bfd *abfd; |
0752970e | 137 | |
36bdbeec NC |
138 | /* If we are generating embedded relocs, call a special BFD backend |
139 | routine to do the work. */ | |
140 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
0752970e | 141 | { |
36bdbeec NC |
142 | asection *datasec, *relsec; |
143 | char *errmsg; | |
144 | ||
145 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
146 | ||
147 | if (datasec == NULL || datasec->reloc_count == 0) | |
148 | continue; | |
149 | ||
150 | relsec = bfd_get_section_by_name (abfd, ".emreloc"); | |
151 | ASSERT (relsec != NULL); | |
152 | ||
153 | if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) | |
154 | { | |
155 | if (! bfd_m68k_coff_create_embedded_relocs (abfd, &link_info, | |
156 | datasec, relsec, | |
157 | &errmsg)) | |
158 | { | |
159 | if (errmsg == NULL) | |
160 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
161 | abfd); | |
162 | else | |
163 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
164 | abfd, errmsg); | |
165 | } | |
166 | } | |
167 | else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | |
168 | { | |
169 | if (! bfd_m68k_elf32_create_embedded_relocs (abfd, &link_info, | |
170 | datasec, relsec, | |
171 | &errmsg)) | |
172 | { | |
173 | if (errmsg == NULL) | |
174 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
175 | abfd); | |
176 | else | |
177 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
178 | abfd, errmsg); | |
179 | } | |
180 | } | |
0752970e | 181 | else |
36bdbeec | 182 | abort (); |
0752970e NC |
183 | } |
184 | } | |
36bdbeec | 185 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
0752970e NC |
186 | } |
187 | ||
188 | EOF | |
189 | ||
190 | # We have our own after_open and after_allocation functions, but they call | |
191 | # the standard routines, so give them a different name. | |
192 | LDEMUL_AFTER_OPEN=m68k_elf_after_open | |
193 | LDEMUL_AFTER_ALLOCATION=m68k_elf_after_allocation |