Commit | Line | Data |
---|---|---|
0752970e NC |
1 | # This shell script emits a C file. -*- C -*- |
2 | # Copyright (C) 2000 Free Software Foundation, Inc. | |
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. | |
20 | # | |
21 | ||
22 | # This file is sourced from elf32.em, and defines extra m68k ELF | |
23 | # specific routines. | |
24 | # | |
25 | cat >>e${EMULATION_NAME}.c <<EOF | |
26 | ||
27 | static void m68k_elf_after_open PARAMS((void)); | |
28 | static void check_sections PARAMS ((bfd *, asection *, PTR)); | |
29 | static void m68k_elf_after_allocation PARAMS ((void)); | |
30 | ||
31 | /* This function is run after all the input files have been opened. | |
32 | We create a .emreloc section for each input file with a non zero | |
33 | .data section. The BFD backend will fill in these sections with | |
34 | magic numbers which can be used to relocate the data section at run | |
35 | time. */ | |
36 | ||
37 | static void | |
38 | m68k_elf_after_open () | |
39 | { | |
40 | bfd *abfd; | |
41 | ||
42 | /* Call the standard elf routine. */ | |
43 | gld${EMULATION_NAME}_after_open (); | |
44 | ||
45 | if (! command_line.embedded_relocs | |
46 | || link_info.relocateable) | |
47 | return; | |
48 | ||
49 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
50 | { | |
51 | asection *datasec; | |
52 | ||
53 | /* As first-order business, make sure that each input BFD is ELF. It | |
54 | better be, as we are directly calling a ELF backend function. */ | |
55 | if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) | |
56 | einfo ("%F%B: all input objects must be ELF for --embedded-relocs\n"); | |
57 | ||
58 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
59 | ||
60 | /* Note that we assume that the reloc_count field has already | |
61 | been set up. We could call bfd_get_reloc_upper_bound, but | |
62 | that returns the size of a memory buffer rather than a reloc | |
63 | count. We do not want to call bfd_canonicalize_reloc, | |
64 | because although it would always work it would force us to | |
65 | read in the relocs into BFD canonical form, which would waste | |
66 | a significant amount of time and memory. */ | |
67 | if (datasec != NULL && datasec->reloc_count > 0) | |
68 | { | |
69 | asection *relsec; | |
70 | ||
71 | relsec = bfd_make_section (abfd, ".emreloc"); | |
72 | if (relsec == NULL | |
73 | || ! bfd_set_section_flags (abfd, relsec, | |
74 | (SEC_ALLOC | |
75 | | SEC_LOAD | |
76 | | SEC_HAS_CONTENTS | |
77 | | SEC_IN_MEMORY)) | |
78 | || ! bfd_set_section_alignment (abfd, relsec, 2) | |
79 | || ! bfd_set_section_size (abfd, relsec, | |
80 | datasec->reloc_count * 12)) | |
81 | einfo ("%F%B: can not create .emreloc section: %E\n"); | |
82 | } | |
83 | ||
84 | /* Double check that all other data sections are empty, as is | |
85 | required for embedded PIC code. */ | |
86 | bfd_map_over_sections (abfd, check_sections, (PTR) datasec); | |
87 | } | |
88 | } | |
89 | ||
90 | /* Check that of the data sections, only the .data section has | |
91 | relocs. This is called via bfd_map_over_sections. */ | |
92 | ||
93 | static void | |
94 | check_sections (abfd, sec, datasec) | |
95 | bfd *abfd; | |
96 | asection *sec; | |
97 | PTR datasec; | |
98 | { | |
99 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
100 | && sec != (asection *) datasec | |
101 | && sec->reloc_count != 0) | |
102 | einfo ("%B%X: section %s has relocs; can not use --embedded-relocs\n", | |
103 | abfd, bfd_get_section_name (abfd, sec)); | |
104 | } | |
105 | ||
106 | /* This function is called after the section sizes and offsets have | |
107 | been set. If we are generating embedded relocs, it calls a special | |
108 | BFD backend routine to do the work. */ | |
109 | ||
110 | static void | |
111 | m68k_elf_after_allocation () | |
112 | { | |
113 | bfd *abfd; | |
114 | ||
115 | /* Call the standard elf routine. */ | |
116 | gld${EMULATION_NAME}_before_allocation (); | |
117 | ||
118 | if (! command_line.embedded_relocs | |
119 | || link_info.relocateable) | |
120 | return; | |
121 | ||
122 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) | |
123 | { | |
124 | asection *datasec, *relsec; | |
125 | char *errmsg; | |
126 | ||
127 | datasec = bfd_get_section_by_name (abfd, ".data"); | |
128 | ||
129 | if (datasec == NULL || datasec->reloc_count == 0) | |
130 | continue; | |
131 | ||
132 | relsec = bfd_get_section_by_name (abfd, ".emreloc"); | |
133 | ASSERT (relsec != NULL); | |
134 | ||
135 | if (! bfd_m68k_elf32_create_embedded_relocs (abfd, &link_info, | |
136 | datasec, relsec, | |
137 | &errmsg)) | |
138 | { | |
139 | if (errmsg == NULL) | |
140 | einfo ("%B%X: can not create runtime reloc information: %E\n", | |
141 | abfd); | |
142 | else | |
143 | einfo ("%X%B: can not create runtime reloc information: %s\n", | |
144 | abfd, errmsg); | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | EOF | |
150 | ||
151 | # We have our own after_open and after_allocation functions, but they call | |
152 | # the standard routines, so give them a different name. | |
153 | LDEMUL_AFTER_OPEN=m68k_elf_after_open | |
154 | LDEMUL_AFTER_ALLOCATION=m68k_elf_after_allocation |