Commit | Line | Data |
---|---|---|
0752970e | 1 | # This shell script emits a C file. -*- C -*- |
1049f94e | 2 | # Copyright 2000, 2001, 2003 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 | |
75be928b | 19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 | 34 | #ifdef SUPPORT_EMBEDDED_RELOCS |
0c7a8e5a | 35 | static void check_sections (bfd *, asection *, void *); |
36bdbeec | 36 | #endif |
0752970e | 37 | |
36bdbeec | 38 | /* This function is run after all the input files have been opened. */ |
0752970e NC |
39 | |
40 | static void | |
0c7a8e5a | 41 | m68k_elf_after_open (void) |
0752970e | 42 | { |
0752970e NC |
43 | /* Call the standard elf routine. */ |
44 | gld${EMULATION_NAME}_after_open (); | |
45 | ||
36bdbeec NC |
46 | #ifdef SUPPORT_EMBEDDED_RELOCS |
47 | if (command_line.embedded_relocs | |
1049f94e | 48 | && (! link_info.relocatable)) |
0752970e | 49 | { |
36bdbeec NC |
50 | bfd *abfd; |
51 | ||
52 | /* In the embedded relocs mode we create a .emreloc section for each | |
53 | input file with a nonzero .data section. The BFD backend will fill in | |
54 | these sections with magic numbers which can be used to relocate the | |
55 | data section at run time. */ | |
56 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
0752970e | 57 | { |
36bdbeec NC |
58 | asection *datasec; |
59 | ||
60 | /* As first-order business, make sure that each input BFD is either | |
61 | COFF or ELF. We need to call a special BFD backend function to | |
62 | generate the embedded relocs, and we have such functions only for | |
63 | COFF and ELF. */ | |
64 | if (bfd_get_flavour (abfd) != bfd_target_coff_flavour | |
65 | && bfd_get_flavour (abfd) != bfd_target_elf_flavour) | |
66 | einfo ("%F%B: all input objects must be COFF or ELF for --embedded-relocs\n"); | |
67 | ||
68 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
69 | ||
70 | /* Note that we assume that the reloc_count field has already | |
71 | been set up. We could call bfd_get_reloc_upper_bound, but | |
72 | that returns the size of a memory buffer rather than a reloc | |
73 | count. We do not want to call bfd_canonicalize_reloc, | |
74 | because although it would always work it would force us to | |
75 | read in the relocs into BFD canonical form, which would waste | |
76 | a significant amount of time and memory. */ | |
77 | if (datasec != NULL && datasec->reloc_count > 0) | |
78 | { | |
79 | asection *relsec; | |
80 | ||
81 | relsec = bfd_make_section (abfd, ".emreloc"); | |
82 | if (relsec == NULL | |
83 | || ! bfd_set_section_flags (abfd, relsec, | |
84 | (SEC_ALLOC | |
85 | | SEC_LOAD | |
86 | | SEC_HAS_CONTENTS | |
87 | | SEC_IN_MEMORY)) | |
88 | || ! bfd_set_section_alignment (abfd, relsec, 2) | |
89 | || ! bfd_set_section_size (abfd, relsec, | |
90 | datasec->reloc_count * 12)) | |
91 | einfo ("%F%B: can not create .emreloc section: %E\n"); | |
92 | } | |
93 | ||
94 | /* Double check that all other data sections are empty, as is | |
95 | required for embedded PIC code. */ | |
1579bae1 | 96 | bfd_map_over_sections (abfd, check_sections, datasec); |
0752970e | 97 | } |
0752970e | 98 | } |
36bdbeec | 99 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
0752970e NC |
100 | } |
101 | ||
36bdbeec | 102 | #ifdef SUPPORT_EMBEDDED_RELOCS |
0752970e NC |
103 | /* Check that of the data sections, only the .data section has |
104 | relocs. This is called via bfd_map_over_sections. */ | |
105 | ||
106 | static void | |
1579bae1 | 107 | check_sections (bfd *abfd, asection *sec, void *datasec) |
0752970e NC |
108 | { |
109 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
1579bae1 | 110 | && sec != datasec |
0752970e NC |
111 | && sec->reloc_count != 0) |
112 | einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n", | |
113 | abfd, bfd_get_section_name (abfd, sec)); | |
114 | } | |
115 | ||
36bdbeec NC |
116 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
117 | ||
0752970e | 118 | /* This function is called after the section sizes and offsets have |
36bdbeec | 119 | been set. */ |
0752970e NC |
120 | |
121 | static void | |
0c7a8e5a | 122 | m68k_elf_after_allocation (void) |
0752970e | 123 | { |
0752970e | 124 | /* Call the standard elf routine. */ |
1c7566d1 | 125 | after_allocation_default (); |
0752970e | 126 | |
36bdbeec NC |
127 | #ifdef SUPPORT_EMBEDDED_RELOCS |
128 | if (command_line.embedded_relocs | |
1049f94e | 129 | && (! link_info.relocatable)) |
0752970e | 130 | { |
36bdbeec | 131 | bfd *abfd; |
0752970e | 132 | |
36bdbeec NC |
133 | /* If we are generating embedded relocs, call a special BFD backend |
134 | routine to do the work. */ | |
135 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
0752970e | 136 | { |
36bdbeec NC |
137 | asection *datasec, *relsec; |
138 | char *errmsg; | |
139 | ||
140 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
141 | ||
142 | if (datasec == NULL || datasec->reloc_count == 0) | |
143 | continue; | |
144 | ||
145 | relsec = bfd_get_section_by_name (abfd, ".emreloc"); | |
146 | ASSERT (relsec != NULL); | |
147 | ||
148 | if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) | |
149 | { | |
150 | if (! bfd_m68k_coff_create_embedded_relocs (abfd, &link_info, | |
151 | datasec, relsec, | |
152 | &errmsg)) | |
153 | { | |
154 | if (errmsg == NULL) | |
155 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
156 | abfd); | |
157 | else | |
158 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
159 | abfd, errmsg); | |
160 | } | |
161 | } | |
162 | else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | |
163 | { | |
164 | if (! bfd_m68k_elf32_create_embedded_relocs (abfd, &link_info, | |
165 | datasec, relsec, | |
166 | &errmsg)) | |
167 | { | |
168 | if (errmsg == NULL) | |
169 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
170 | abfd); | |
171 | else | |
172 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
173 | abfd, errmsg); | |
174 | } | |
175 | } | |
0752970e | 176 | else |
36bdbeec | 177 | abort (); |
0752970e NC |
178 | } |
179 | } | |
36bdbeec | 180 | #endif /* SUPPORT_EMBEDDED_RELOCS */ |
0752970e NC |
181 | } |
182 | ||
183 | EOF | |
184 | ||
185 | # We have our own after_open and after_allocation functions, but they call | |
186 | # the standard routines, so give them a different name. | |
187 | LDEMUL_AFTER_OPEN=m68k_elf_after_open | |
188 | LDEMUL_AFTER_ALLOCATION=m68k_elf_after_allocation |