Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Motorola 68k series support for 32-bit ELF |
b2a8e766 | 2 | Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
ab96bf03 | 3 | 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
252b5132 | 4 | |
ae9a127f | 5 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 6 | |
ae9a127f NC |
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. | |
252b5132 | 11 | |
ae9a127f NC |
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. | |
252b5132 | 16 | |
ae9a127f NC |
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 | |
3e110533 | 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
20 | |
21 | #include "bfd.h" | |
22 | #include "sysdep.h" | |
23 | #include "bfdlink.h" | |
24 | #include "libbfd.h" | |
25 | #include "elf-bfd.h" | |
26 | #include "elf/m68k.h" | |
266abb8f | 27 | #include "opcode/m68k.h" |
252b5132 RH |
28 | |
29 | static reloc_howto_type *reloc_type_lookup | |
30 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
31 | static void rtype_to_howto | |
947216bf | 32 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
252b5132 RH |
33 | static struct bfd_hash_entry *elf_m68k_link_hash_newfunc |
34 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
35 | static struct bfd_link_hash_table *elf_m68k_link_hash_table_create | |
36 | PARAMS ((bfd *)); | |
b34976b6 | 37 | static bfd_boolean elf_m68k_check_relocs |
252b5132 RH |
38 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
39 | const Elf_Internal_Rela *)); | |
b34976b6 | 40 | static bfd_boolean elf_m68k_adjust_dynamic_symbol |
252b5132 | 41 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); |
b34976b6 | 42 | static bfd_boolean elf_m68k_size_dynamic_sections |
252b5132 | 43 | PARAMS ((bfd *, struct bfd_link_info *)); |
0cca5f05 AS |
44 | static bfd_boolean elf_m68k_discard_copies |
45 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
b34976b6 | 46 | static bfd_boolean elf_m68k_relocate_section |
252b5132 RH |
47 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
48 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
b34976b6 | 49 | static bfd_boolean elf_m68k_finish_dynamic_symbol |
252b5132 RH |
50 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
51 | Elf_Internal_Sym *)); | |
b34976b6 | 52 | static bfd_boolean elf_m68k_finish_dynamic_sections |
252b5132 RH |
53 | PARAMS ((bfd *, struct bfd_link_info *)); |
54 | ||
b34976b6 | 55 | static bfd_boolean elf32_m68k_set_private_flags |
9e1281c7 | 56 | PARAMS ((bfd *, flagword)); |
b34976b6 | 57 | static bfd_boolean elf32_m68k_merge_private_bfd_data |
9e1281c7 | 58 | PARAMS ((bfd *, bfd *)); |
b34976b6 | 59 | static bfd_boolean elf32_m68k_print_private_bfd_data |
9e1281c7 | 60 | PARAMS ((bfd *, PTR)); |
aa91b392 | 61 | static enum elf_reloc_type_class elf32_m68k_reloc_type_class |
f51e552e | 62 | PARAMS ((const Elf_Internal_Rela *)); |
9e1281c7 | 63 | |
252b5132 | 64 | static reloc_howto_type howto_table[] = { |
b34976b6 AM |
65 | HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE), |
66 | HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE), | |
67 | HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE), | |
68 | HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE), | |
69 | HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE), | |
70 | HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE), | |
71 | HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE), | |
72 | HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE), | |
73 | HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE), | |
74 | HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE), | |
75 | HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE), | |
76 | HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE), | |
77 | HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE), | |
78 | HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE), | |
79 | HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE), | |
80 | HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE), | |
81 | HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE), | |
82 | HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE), | |
83 | HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE), | |
84 | HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE), | |
85 | HOWTO(R_68K_GLOB_DAT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", FALSE, 0, 0xffffffff,FALSE), | |
86 | HOWTO(R_68K_JMP_SLOT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", FALSE, 0, 0xffffffff,FALSE), | |
87 | HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE), | |
ae9a127f | 88 | /* GNU extension to record C++ vtable hierarchy. */ |
252b5132 RH |
89 | HOWTO (R_68K_GNU_VTINHERIT, /* type */ |
90 | 0, /* rightshift */ | |
91 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
92 | 0, /* bitsize */ | |
b34976b6 | 93 | FALSE, /* pc_relative */ |
252b5132 RH |
94 | 0, /* bitpos */ |
95 | complain_overflow_dont, /* complain_on_overflow */ | |
96 | NULL, /* special_function */ | |
97 | "R_68K_GNU_VTINHERIT", /* name */ | |
b34976b6 | 98 | FALSE, /* partial_inplace */ |
252b5132 RH |
99 | 0, /* src_mask */ |
100 | 0, /* dst_mask */ | |
b34976b6 | 101 | FALSE), |
ae9a127f | 102 | /* GNU extension to record C++ vtable member usage. */ |
252b5132 RH |
103 | HOWTO (R_68K_GNU_VTENTRY, /* type */ |
104 | 0, /* rightshift */ | |
105 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
106 | 0, /* bitsize */ | |
b34976b6 | 107 | FALSE, /* pc_relative */ |
252b5132 RH |
108 | 0, /* bitpos */ |
109 | complain_overflow_dont, /* complain_on_overflow */ | |
110 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
111 | "R_68K_GNU_VTENTRY", /* name */ | |
b34976b6 | 112 | FALSE, /* partial_inplace */ |
252b5132 RH |
113 | 0, /* src_mask */ |
114 | 0, /* dst_mask */ | |
b34976b6 | 115 | FALSE), |
252b5132 RH |
116 | }; |
117 | ||
118 | static void | |
119 | rtype_to_howto (abfd, cache_ptr, dst) | |
121089cb | 120 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
121 | arelent *cache_ptr; |
122 | Elf_Internal_Rela *dst; | |
123 | { | |
124 | BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K_max); | |
125 | cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)]; | |
126 | } | |
127 | ||
128 | #define elf_info_to_howto rtype_to_howto | |
129 | ||
130 | static const struct | |
131 | { | |
132 | bfd_reloc_code_real_type bfd_val; | |
133 | int elf_val; | |
134 | } reloc_map[] = { | |
135 | { BFD_RELOC_NONE, R_68K_NONE }, | |
136 | { BFD_RELOC_32, R_68K_32 }, | |
137 | { BFD_RELOC_16, R_68K_16 }, | |
138 | { BFD_RELOC_8, R_68K_8 }, | |
139 | { BFD_RELOC_32_PCREL, R_68K_PC32 }, | |
140 | { BFD_RELOC_16_PCREL, R_68K_PC16 }, | |
141 | { BFD_RELOC_8_PCREL, R_68K_PC8 }, | |
142 | { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 }, | |
143 | { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 }, | |
144 | { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 }, | |
145 | { BFD_RELOC_32_GOTOFF, R_68K_GOT32O }, | |
146 | { BFD_RELOC_16_GOTOFF, R_68K_GOT16O }, | |
147 | { BFD_RELOC_8_GOTOFF, R_68K_GOT8O }, | |
148 | { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 }, | |
149 | { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 }, | |
150 | { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 }, | |
151 | { BFD_RELOC_32_PLTOFF, R_68K_PLT32O }, | |
152 | { BFD_RELOC_16_PLTOFF, R_68K_PLT16O }, | |
153 | { BFD_RELOC_8_PLTOFF, R_68K_PLT8O }, | |
154 | { BFD_RELOC_NONE, R_68K_COPY }, | |
155 | { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT }, | |
156 | { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT }, | |
157 | { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE }, | |
158 | { BFD_RELOC_CTOR, R_68K_32 }, | |
159 | { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT }, | |
160 | { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY }, | |
161 | }; | |
162 | ||
163 | static reloc_howto_type * | |
164 | reloc_type_lookup (abfd, code) | |
121089cb | 165 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
166 | bfd_reloc_code_real_type code; |
167 | { | |
168 | unsigned int i; | |
169 | for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++) | |
170 | { | |
171 | if (reloc_map[i].bfd_val == code) | |
172 | return &howto_table[reloc_map[i].elf_val]; | |
173 | } | |
174 | return 0; | |
175 | } | |
176 | ||
177 | #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup | |
178 | #define ELF_ARCH bfd_arch_m68k | |
252b5132 RH |
179 | \f |
180 | /* Functions for the m68k ELF linker. */ | |
181 | ||
182 | /* The name of the dynamic interpreter. This is put in the .interp | |
183 | section. */ | |
184 | ||
185 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" | |
186 | ||
cc3e26be RS |
187 | /* Describes one of the various PLT styles. */ |
188 | ||
189 | struct elf_m68k_plt_info | |
190 | { | |
191 | /* The size of each PLT entry. */ | |
192 | bfd_vma size; | |
193 | ||
194 | /* The template for the first PLT entry. */ | |
195 | const bfd_byte *plt0_entry; | |
196 | ||
197 | /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations. | |
198 | The comments by each member indicate the value that the relocation | |
199 | is against. */ | |
200 | struct { | |
201 | unsigned int got4; /* .got + 4 */ | |
202 | unsigned int got8; /* .got + 8 */ | |
203 | } plt0_relocs; | |
204 | ||
205 | /* The template for a symbol's PLT entry. */ | |
206 | const bfd_byte *symbol_entry; | |
207 | ||
208 | /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations. | |
209 | The comments by each member indicate the value that the relocation | |
210 | is against. */ | |
211 | struct { | |
212 | unsigned int got; /* the symbol's .got.plt entry */ | |
213 | unsigned int plt; /* .plt */ | |
214 | } symbol_relocs; | |
215 | ||
216 | /* The offset of the resolver stub from the start of SYMBOL_ENTRY. | |
217 | The stub starts with "move.l #relocoffset,%d0". */ | |
218 | bfd_vma symbol_resolve_entry; | |
219 | }; | |
220 | ||
252b5132 RH |
221 | /* The size in bytes of an entry in the procedure linkage table. */ |
222 | ||
223 | #define PLT_ENTRY_SIZE 20 | |
224 | ||
225 | /* The first entry in a procedure linkage table looks like this. See | |
226 | the SVR4 ABI m68k supplement to see how this works. */ | |
227 | ||
228 | static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] = | |
229 | { | |
230 | 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ | |
cc3e26be | 231 | 0, 0, 0, 2, /* + (.got + 4) - . */ |
252b5132 | 232 | 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */ |
cc3e26be | 233 | 0, 0, 0, 2, /* + (.got + 8) - . */ |
252b5132 RH |
234 | 0, 0, 0, 0 /* pad out to 20 bytes. */ |
235 | }; | |
236 | ||
237 | /* Subsequent entries in a procedure linkage table look like this. */ | |
238 | ||
239 | static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] = | |
240 | { | |
241 | 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */ | |
cc3e26be | 242 | 0, 0, 0, 2, /* + (.got.plt entry) - . */ |
252b5132 | 243 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
cc3e26be | 244 | 0, 0, 0, 0, /* + reloc index */ |
252b5132 | 245 | 0x60, 0xff, /* bra.l .plt */ |
cc3e26be | 246 | 0, 0, 0, 0 /* + .plt - . */ |
252b5132 RH |
247 | }; |
248 | ||
cc3e26be RS |
249 | static const struct elf_m68k_plt_info elf_m68k_plt_info = { |
250 | PLT_ENTRY_SIZE, | |
251 | elf_m68k_plt0_entry, { 4, 12 }, | |
252 | elf_m68k_plt_entry, { 4, 16 }, 8 | |
253 | }; | |
238d258f | 254 | |
cc3e26be | 255 | #define ISAB_PLT_ENTRY_SIZE 24 |
238d258f | 256 | |
cc3e26be | 257 | static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] = |
238d258f | 258 | { |
cc3e26be RS |
259 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
260 | 0, 0, 0, 0, /* + (.got + 4) - . */ | |
261 | 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */ | |
262 | 0x20, 0x3c, /* move.l #offset,%d0 */ | |
263 | 0, 0, 0, 0, /* + (.got + 8) - . */ | |
264 | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ | |
238d258f NC |
265 | 0x4e, 0xd0, /* jmp (%a0) */ |
266 | 0x4e, 0x71 /* nop */ | |
267 | }; | |
268 | ||
269 | /* Subsequent entries in a procedure linkage table look like this. */ | |
270 | ||
cc3e26be | 271 | static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] = |
238d258f | 272 | { |
cc3e26be RS |
273 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
274 | 0, 0, 0, 0, /* + (.got.plt entry) - . */ | |
275 | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ | |
238d258f NC |
276 | 0x4e, 0xd0, /* jmp (%a0) */ |
277 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ | |
cc3e26be | 278 | 0, 0, 0, 0, /* + reloc index */ |
238d258f | 279 | 0x60, 0xff, /* bra.l .plt */ |
cc3e26be | 280 | 0, 0, 0, 0 /* + .plt - . */ |
238d258f NC |
281 | }; |
282 | ||
cc3e26be RS |
283 | static const struct elf_m68k_plt_info elf_isab_plt_info = { |
284 | ISAB_PLT_ENTRY_SIZE, | |
285 | elf_isab_plt0_entry, { 2, 12 }, | |
286 | elf_isab_plt_entry, { 2, 20 }, 12 | |
287 | }; | |
9e1281c7 | 288 | |
cc3e26be | 289 | #define CPU32_PLT_ENTRY_SIZE 24 |
9e1281c7 | 290 | /* Procedure linkage table entries for the cpu32 */ |
cc3e26be | 291 | static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] = |
9e1281c7 | 292 | { |
6091b433 | 293 | 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ |
cc3e26be | 294 | 0, 0, 0, 2, /* + (.got + 4) - . */ |
6091b433 | 295 | 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ |
cc3e26be | 296 | 0, 0, 0, 2, /* + (.got + 8) - . */ |
6091b433 | 297 | 0x4e, 0xd1, /* jmp %a1@ */ |
9e1281c7 CM |
298 | 0, 0, 0, 0, /* pad out to 24 bytes. */ |
299 | 0, 0 | |
300 | }; | |
301 | ||
cc3e26be | 302 | static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] = |
9e1281c7 | 303 | { |
1ca42bad | 304 | 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ |
cc3e26be | 305 | 0, 0, 0, 2, /* + (.got.plt entry) - . */ |
1ca42bad | 306 | 0x4e, 0xd1, /* jmp %a1@ */ |
9e1281c7 | 307 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
cc3e26be | 308 | 0, 0, 0, 0, /* + reloc index */ |
9e1281c7 | 309 | 0x60, 0xff, /* bra.l .plt */ |
cc3e26be | 310 | 0, 0, 0, 0, /* + .plt - . */ |
9e1281c7 CM |
311 | 0, 0 |
312 | }; | |
313 | ||
cc3e26be RS |
314 | static const struct elf_m68k_plt_info elf_cpu32_plt_info = { |
315 | CPU32_PLT_ENTRY_SIZE, | |
316 | elf_cpu32_plt0_entry, { 4, 12 }, | |
317 | elf_cpu32_plt_entry, { 4, 18 }, 10 | |
318 | }; | |
319 | ||
252b5132 RH |
320 | /* The m68k linker needs to keep track of the number of relocs that it |
321 | decides to copy in check_relocs for each symbol. This is so that it | |
322 | can discard PC relative relocs if it doesn't need them when linking | |
323 | with -Bsymbolic. We store the information in a field extending the | |
324 | regular ELF linker hash table. */ | |
325 | ||
326 | /* This structure keeps track of the number of PC relative relocs we have | |
327 | copied for a given symbol. */ | |
328 | ||
329 | struct elf_m68k_pcrel_relocs_copied | |
330 | { | |
331 | /* Next section. */ | |
332 | struct elf_m68k_pcrel_relocs_copied *next; | |
333 | /* A section in dynobj. */ | |
334 | asection *section; | |
335 | /* Number of relocs copied in this section. */ | |
336 | bfd_size_type count; | |
337 | }; | |
338 | ||
339 | /* m68k ELF linker hash entry. */ | |
340 | ||
341 | struct elf_m68k_link_hash_entry | |
342 | { | |
343 | struct elf_link_hash_entry root; | |
344 | ||
345 | /* Number of PC relative relocs copied for this symbol. */ | |
346 | struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied; | |
347 | }; | |
348 | ||
0cca5f05 AS |
349 | #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent)) |
350 | ||
252b5132 RH |
351 | /* m68k ELF linker hash table. */ |
352 | ||
353 | struct elf_m68k_link_hash_table | |
354 | { | |
355 | struct elf_link_hash_table root; | |
b6152c34 AS |
356 | |
357 | /* Small local sym to section mapping cache. */ | |
358 | struct sym_sec_cache sym_sec; | |
cc3e26be RS |
359 | |
360 | /* The PLT format used by this link, or NULL if the format has not | |
361 | yet been chosen. */ | |
362 | const struct elf_m68k_plt_info *plt_info; | |
252b5132 RH |
363 | }; |
364 | ||
252b5132 RH |
365 | /* Get the m68k ELF linker hash table from a link_info structure. */ |
366 | ||
367 | #define elf_m68k_hash_table(p) \ | |
368 | ((struct elf_m68k_link_hash_table *) (p)->hash) | |
369 | ||
370 | /* Create an entry in an m68k ELF linker hash table. */ | |
371 | ||
372 | static struct bfd_hash_entry * | |
373 | elf_m68k_link_hash_newfunc (entry, table, string) | |
374 | struct bfd_hash_entry *entry; | |
375 | struct bfd_hash_table *table; | |
376 | const char *string; | |
377 | { | |
0cca5f05 | 378 | struct bfd_hash_entry *ret = entry; |
252b5132 RH |
379 | |
380 | /* Allocate the structure if it has not already been allocated by a | |
381 | subclass. */ | |
0cca5f05 AS |
382 | if (ret == NULL) |
383 | ret = bfd_hash_allocate (table, | |
384 | sizeof (struct elf_m68k_link_hash_entry)); | |
385 | if (ret == NULL) | |
386 | return ret; | |
252b5132 RH |
387 | |
388 | /* Call the allocation method of the superclass. */ | |
0cca5f05 AS |
389 | ret = _bfd_elf_link_hash_newfunc (ret, table, string); |
390 | if (ret != NULL) | |
391 | elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL; | |
252b5132 | 392 | |
0cca5f05 | 393 | return ret; |
252b5132 RH |
394 | } |
395 | ||
396 | /* Create an m68k ELF linker hash table. */ | |
397 | ||
398 | static struct bfd_link_hash_table * | |
399 | elf_m68k_link_hash_table_create (abfd) | |
400 | bfd *abfd; | |
401 | { | |
402 | struct elf_m68k_link_hash_table *ret; | |
dc810e39 | 403 | bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table); |
252b5132 | 404 | |
e2d34d7d | 405 | ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt); |
252b5132 RH |
406 | if (ret == (struct elf_m68k_link_hash_table *) NULL) |
407 | return NULL; | |
408 | ||
66eb6687 AM |
409 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, |
410 | elf_m68k_link_hash_newfunc, | |
411 | sizeof (struct elf_m68k_link_hash_entry))) | |
252b5132 | 412 | { |
e2d34d7d | 413 | free (ret); |
252b5132 RH |
414 | return NULL; |
415 | } | |
416 | ||
b6152c34 | 417 | ret->sym_sec.abfd = NULL; |
cc3e26be | 418 | ret->plt_info = NULL; |
b6152c34 | 419 | |
252b5132 RH |
420 | return &ret->root.root; |
421 | } | |
422 | ||
266abb8f NS |
423 | /* Set the right machine number. */ |
424 | ||
425 | static bfd_boolean | |
426 | elf32_m68k_object_p (bfd *abfd) | |
427 | { | |
428 | unsigned int mach = 0; | |
429 | unsigned features = 0; | |
430 | flagword eflags = elf_elfheader (abfd)->e_flags; | |
431 | ||
425c6cb0 | 432 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
266abb8f | 433 | features |= m68000; |
425c6cb0 | 434 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
3bdcfdf4 KH |
435 | features |= cpu32; |
436 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
437 | features |= fido_a; | |
425c6cb0 | 438 | else |
266abb8f | 439 | { |
c694fd50 | 440 | switch (eflags & EF_M68K_CF_ISA_MASK) |
266abb8f | 441 | { |
c694fd50 | 442 | case EF_M68K_CF_ISA_A_NODIV: |
266abb8f NS |
443 | features |= mcfisa_a; |
444 | break; | |
c694fd50 | 445 | case EF_M68K_CF_ISA_A: |
0b2e31dc NS |
446 | features |= mcfisa_a|mcfhwdiv; |
447 | break; | |
c694fd50 | 448 | case EF_M68K_CF_ISA_A_PLUS: |
0b2e31dc NS |
449 | features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp; |
450 | break; | |
c694fd50 | 451 | case EF_M68K_CF_ISA_B_NOUSP: |
0b2e31dc NS |
452 | features |= mcfisa_a|mcfisa_b|mcfhwdiv; |
453 | break; | |
c694fd50 | 454 | case EF_M68K_CF_ISA_B: |
0b2e31dc NS |
455 | features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp; |
456 | break; | |
266abb8f | 457 | } |
c694fd50 | 458 | switch (eflags & EF_M68K_CF_MAC_MASK) |
266abb8f | 459 | { |
c694fd50 | 460 | case EF_M68K_CF_MAC: |
266abb8f NS |
461 | features |= mcfmac; |
462 | break; | |
c694fd50 | 463 | case EF_M68K_CF_EMAC: |
266abb8f NS |
464 | features |= mcfemac; |
465 | break; | |
466 | } | |
c694fd50 | 467 | if (eflags & EF_M68K_CF_FLOAT) |
266abb8f NS |
468 | features |= cfloat; |
469 | } | |
470 | ||
471 | mach = bfd_m68k_features_to_mach (features); | |
472 | bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach); | |
473 | ||
474 | return TRUE; | |
475 | } | |
476 | ||
ae9a127f | 477 | /* Keep m68k-specific flags in the ELF header. */ |
b34976b6 | 478 | static bfd_boolean |
9e1281c7 CM |
479 | elf32_m68k_set_private_flags (abfd, flags) |
480 | bfd *abfd; | |
481 | flagword flags; | |
482 | { | |
483 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
484 | elf_flags_init (abfd) = TRUE; |
485 | return TRUE; | |
9e1281c7 CM |
486 | } |
487 | ||
9e1281c7 CM |
488 | /* Merge backend specific data from an object file to the output |
489 | object file when linking. */ | |
b34976b6 | 490 | static bfd_boolean |
9e1281c7 CM |
491 | elf32_m68k_merge_private_bfd_data (ibfd, obfd) |
492 | bfd *ibfd; | |
493 | bfd *obfd; | |
494 | { | |
495 | flagword out_flags; | |
496 | flagword in_flags; | |
a9d34880 RS |
497 | flagword out_isa; |
498 | flagword in_isa; | |
499 | const bfd_arch_info_type *arch_info; | |
266abb8f | 500 | |
9e1281c7 CM |
501 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
502 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
266abb8f NS |
503 | return FALSE; |
504 | ||
a9d34880 RS |
505 | /* Get the merged machine. This checks for incompatibility between |
506 | Coldfire & non-Coldfire flags, incompability between different | |
507 | Coldfire ISAs, and incompability between different MAC types. */ | |
508 | arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE); | |
509 | if (!arch_info) | |
510 | return FALSE; | |
9e1281c7 | 511 | |
a9d34880 RS |
512 | bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach); |
513 | ||
514 | in_flags = elf_elfheader (ibfd)->e_flags; | |
9e1281c7 CM |
515 | if (!elf_flags_init (obfd)) |
516 | { | |
b34976b6 | 517 | elf_flags_init (obfd) = TRUE; |
266abb8f NS |
518 | out_flags = in_flags; |
519 | } | |
520 | else | |
521 | { | |
a9d34880 | 522 | out_flags = elf_elfheader (obfd)->e_flags; |
425c6cb0 KH |
523 | unsigned int variant_mask; |
524 | ||
525 | if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) | |
526 | variant_mask = 0; | |
527 | else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) | |
3bdcfdf4 KH |
528 | variant_mask = 0; |
529 | else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
530 | variant_mask = 0; | |
425c6cb0 KH |
531 | else |
532 | variant_mask = EF_M68K_CF_ISA_MASK; | |
533 | ||
534 | in_isa = (in_flags & variant_mask); | |
535 | out_isa = (out_flags & variant_mask); | |
a9d34880 RS |
536 | if (in_isa > out_isa) |
537 | out_flags ^= in_isa ^ out_isa; | |
3bdcfdf4 KH |
538 | if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32 |
539 | && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
540 | || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO | |
541 | && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)) | |
542 | out_flags = EF_M68K_FIDO; | |
543 | else | |
a9d34880 | 544 | out_flags |= in_flags ^ in_isa; |
9e1281c7 | 545 | } |
266abb8f | 546 | elf_elfheader (obfd)->e_flags = out_flags; |
9e1281c7 | 547 | |
b34976b6 | 548 | return TRUE; |
9e1281c7 CM |
549 | } |
550 | ||
ae9a127f | 551 | /* Display the flags field. */ |
b34976b6 | 552 | static bfd_boolean |
9e1281c7 CM |
553 | elf32_m68k_print_private_bfd_data (abfd, ptr) |
554 | bfd *abfd; | |
555 | PTR ptr; | |
556 | { | |
557 | FILE *file = (FILE *) ptr; | |
266abb8f | 558 | flagword eflags = elf_elfheader (abfd)->e_flags; |
9e1281c7 CM |
559 | |
560 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
561 | ||
562 | /* Print normal ELF private data. */ | |
563 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
564 | ||
565 | /* Ignore init flag - it may not be set, despite the flags field containing valid data. */ | |
566 | ||
567 | /* xgettext:c-format */ | |
517662d4 | 568 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
9e1281c7 | 569 | |
425c6cb0 | 570 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
266abb8f | 571 | fprintf (file, " [m68000]"); |
425c6cb0 | 572 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
3bdcfdf4 KH |
573 | fprintf (file, " [cpu32]"); |
574 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
575 | fprintf (file, " [fido]"); | |
425c6cb0 | 576 | else |
266abb8f | 577 | { |
425c6cb0 KH |
578 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E) |
579 | fprintf (file, " [cfv4e]"); | |
580 | ||
581 | if (eflags & EF_M68K_CF_ISA_MASK) | |
266abb8f | 582 | { |
425c6cb0 KH |
583 | char const *isa = _("unknown"); |
584 | char const *mac = _("unknown"); | |
585 | char const *additional = ""; | |
586 | ||
587 | switch (eflags & EF_M68K_CF_ISA_MASK) | |
588 | { | |
589 | case EF_M68K_CF_ISA_A_NODIV: | |
590 | isa = "A"; | |
591 | additional = " [nodiv]"; | |
592 | break; | |
593 | case EF_M68K_CF_ISA_A: | |
594 | isa = "A"; | |
595 | break; | |
596 | case EF_M68K_CF_ISA_A_PLUS: | |
597 | isa = "A+"; | |
598 | break; | |
599 | case EF_M68K_CF_ISA_B_NOUSP: | |
600 | isa = "B"; | |
601 | additional = " [nousp]"; | |
602 | break; | |
603 | case EF_M68K_CF_ISA_B: | |
604 | isa = "B"; | |
605 | break; | |
606 | } | |
607 | fprintf (file, " [isa %s]%s", isa, additional); | |
608 | if (eflags & EF_M68K_CF_FLOAT) | |
609 | fprintf (file, " [float]"); | |
610 | switch (eflags & EF_M68K_CF_MAC_MASK) | |
611 | { | |
612 | case 0: | |
613 | mac = NULL; | |
614 | break; | |
615 | case EF_M68K_CF_MAC: | |
616 | mac = "mac"; | |
617 | break; | |
618 | case EF_M68K_CF_EMAC: | |
619 | mac = "emac"; | |
620 | break; | |
621 | } | |
622 | if (mac) | |
623 | fprintf (file, " [%s]", mac); | |
266abb8f | 624 | } |
266abb8f NS |
625 | } |
626 | ||
9e1281c7 CM |
627 | fputc ('\n', file); |
628 | ||
b34976b6 | 629 | return TRUE; |
9e1281c7 | 630 | } |
252b5132 RH |
631 | /* Look through the relocs for a section during the first phase, and |
632 | allocate space in the global offset table or procedure linkage | |
633 | table. */ | |
634 | ||
b34976b6 | 635 | static bfd_boolean |
252b5132 RH |
636 | elf_m68k_check_relocs (abfd, info, sec, relocs) |
637 | bfd *abfd; | |
638 | struct bfd_link_info *info; | |
639 | asection *sec; | |
640 | const Elf_Internal_Rela *relocs; | |
641 | { | |
642 | bfd *dynobj; | |
643 | Elf_Internal_Shdr *symtab_hdr; | |
644 | struct elf_link_hash_entry **sym_hashes; | |
645 | bfd_signed_vma *local_got_refcounts; | |
646 | const Elf_Internal_Rela *rel; | |
647 | const Elf_Internal_Rela *rel_end; | |
648 | asection *sgot; | |
649 | asection *srelgot; | |
650 | asection *sreloc; | |
651 | ||
1049f94e | 652 | if (info->relocatable) |
b34976b6 | 653 | return TRUE; |
252b5132 RH |
654 | |
655 | dynobj = elf_hash_table (info)->dynobj; | |
656 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
657 | sym_hashes = elf_sym_hashes (abfd); | |
658 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
659 | ||
660 | sgot = NULL; | |
661 | srelgot = NULL; | |
662 | sreloc = NULL; | |
663 | ||
664 | rel_end = relocs + sec->reloc_count; | |
665 | for (rel = relocs; rel < rel_end; rel++) | |
666 | { | |
667 | unsigned long r_symndx; | |
668 | struct elf_link_hash_entry *h; | |
669 | ||
670 | r_symndx = ELF32_R_SYM (rel->r_info); | |
671 | ||
672 | if (r_symndx < symtab_hdr->sh_info) | |
673 | h = NULL; | |
674 | else | |
973a3492 L |
675 | { |
676 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
677 | while (h->root.type == bfd_link_hash_indirect | |
678 | || h->root.type == bfd_link_hash_warning) | |
679 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
680 | } | |
252b5132 RH |
681 | |
682 | switch (ELF32_R_TYPE (rel->r_info)) | |
683 | { | |
684 | case R_68K_GOT8: | |
685 | case R_68K_GOT16: | |
686 | case R_68K_GOT32: | |
687 | if (h != NULL | |
688 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
689 | break; | |
690 | /* Fall through. */ | |
691 | case R_68K_GOT8O: | |
692 | case R_68K_GOT16O: | |
693 | case R_68K_GOT32O: | |
694 | /* This symbol requires a global offset table entry. */ | |
695 | ||
696 | if (dynobj == NULL) | |
697 | { | |
698 | /* Create the .got section. */ | |
699 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
700 | if (!_bfd_elf_create_got_section (dynobj, info)) | |
b34976b6 | 701 | return FALSE; |
252b5132 RH |
702 | } |
703 | ||
704 | if (sgot == NULL) | |
705 | { | |
706 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
707 | BFD_ASSERT (sgot != NULL); | |
708 | } | |
709 | ||
710 | if (srelgot == NULL | |
711 | && (h != NULL || info->shared)) | |
712 | { | |
713 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
714 | if (srelgot == NULL) | |
715 | { | |
3496cb2a L |
716 | srelgot = bfd_make_section_with_flags (dynobj, |
717 | ".rela.got", | |
718 | (SEC_ALLOC | |
719 | | SEC_LOAD | |
720 | | SEC_HAS_CONTENTS | |
721 | | SEC_IN_MEMORY | |
722 | | SEC_LINKER_CREATED | |
723 | | SEC_READONLY)); | |
252b5132 | 724 | if (srelgot == NULL |
252b5132 | 725 | || !bfd_set_section_alignment (dynobj, srelgot, 2)) |
b34976b6 | 726 | return FALSE; |
252b5132 RH |
727 | } |
728 | } | |
729 | ||
730 | if (h != NULL) | |
731 | { | |
51b64d56 | 732 | if (h->got.refcount == 0) |
252b5132 | 733 | { |
252b5132 | 734 | /* Make sure this symbol is output as a dynamic symbol. */ |
b6152c34 | 735 | if (h->dynindx == -1 |
f5385ebf | 736 | && !h->forced_local) |
252b5132 | 737 | { |
c152c796 | 738 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 739 | return FALSE; |
252b5132 RH |
740 | } |
741 | ||
742 | /* Allocate space in the .got section. */ | |
eea6121a | 743 | sgot->size += 4; |
252b5132 | 744 | /* Allocate relocation space. */ |
eea6121a | 745 | srelgot->size += sizeof (Elf32_External_Rela); |
252b5132 | 746 | } |
51b64d56 | 747 | h->got.refcount++; |
252b5132 RH |
748 | } |
749 | else | |
750 | { | |
751 | /* This is a global offset table entry for a local symbol. */ | |
752 | if (local_got_refcounts == NULL) | |
753 | { | |
dc810e39 | 754 | bfd_size_type size; |
252b5132 | 755 | |
dc810e39 AM |
756 | size = symtab_hdr->sh_info; |
757 | size *= sizeof (bfd_signed_vma); | |
252b5132 | 758 | local_got_refcounts = ((bfd_signed_vma *) |
51b64d56 | 759 | bfd_zalloc (abfd, size)); |
252b5132 | 760 | if (local_got_refcounts == NULL) |
b34976b6 | 761 | return FALSE; |
252b5132 | 762 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 763 | } |
51b64d56 | 764 | if (local_got_refcounts[r_symndx] == 0) |
252b5132 | 765 | { |
eea6121a | 766 | sgot->size += 4; |
252b5132 RH |
767 | if (info->shared) |
768 | { | |
769 | /* If we are generating a shared object, we need to | |
770 | output a R_68K_RELATIVE reloc so that the dynamic | |
771 | linker can adjust this GOT entry. */ | |
eea6121a | 772 | srelgot->size += sizeof (Elf32_External_Rela); |
252b5132 RH |
773 | } |
774 | } | |
51b64d56 | 775 | local_got_refcounts[r_symndx]++; |
252b5132 RH |
776 | } |
777 | break; | |
778 | ||
779 | case R_68K_PLT8: | |
780 | case R_68K_PLT16: | |
781 | case R_68K_PLT32: | |
782 | /* This symbol requires a procedure linkage table entry. We | |
783 | actually build the entry in adjust_dynamic_symbol, | |
784 | because this might be a case of linking PIC code which is | |
785 | never referenced by a dynamic object, in which case we | |
786 | don't need to generate a procedure linkage table entry | |
787 | after all. */ | |
788 | ||
789 | /* If this is a local symbol, we resolve it directly without | |
790 | creating a procedure linkage table entry. */ | |
791 | if (h == NULL) | |
792 | continue; | |
793 | ||
f5385ebf | 794 | h->needs_plt = 1; |
51b64d56 | 795 | h->plt.refcount++; |
252b5132 RH |
796 | break; |
797 | ||
798 | case R_68K_PLT8O: | |
799 | case R_68K_PLT16O: | |
800 | case R_68K_PLT32O: | |
801 | /* This symbol requires a procedure linkage table entry. */ | |
802 | ||
803 | if (h == NULL) | |
804 | { | |
805 | /* It does not make sense to have this relocation for a | |
806 | local symbol. FIXME: does it? How to handle it if | |
807 | it does make sense? */ | |
808 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 809 | return FALSE; |
252b5132 RH |
810 | } |
811 | ||
812 | /* Make sure this symbol is output as a dynamic symbol. */ | |
b6152c34 | 813 | if (h->dynindx == -1 |
f5385ebf | 814 | && !h->forced_local) |
252b5132 | 815 | { |
c152c796 | 816 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 817 | return FALSE; |
252b5132 RH |
818 | } |
819 | ||
f5385ebf | 820 | h->needs_plt = 1; |
51b64d56 | 821 | h->plt.refcount++; |
252b5132 RH |
822 | break; |
823 | ||
824 | case R_68K_PC8: | |
825 | case R_68K_PC16: | |
826 | case R_68K_PC32: | |
827 | /* If we are creating a shared library and this is not a local | |
828 | symbol, we need to copy the reloc into the shared library. | |
829 | However when linking with -Bsymbolic and this is a global | |
830 | symbol which is defined in an object we are including in the | |
831 | link (i.e., DEF_REGULAR is set), then we can resolve the | |
832 | reloc directly. At this point we have not seen all the input | |
833 | files, so it is possible that DEF_REGULAR is not set now but | |
834 | will be set later (it is never cleared). We account for that | |
835 | possibility below by storing information in the | |
836 | pcrel_relocs_copied field of the hash table entry. */ | |
837 | if (!(info->shared | |
838 | && (sec->flags & SEC_ALLOC) != 0 | |
839 | && h != NULL | |
840 | && (!info->symbolic | |
b6152c34 | 841 | || h->root.type == bfd_link_hash_defweak |
f5385ebf | 842 | || !h->def_regular))) |
252b5132 RH |
843 | { |
844 | if (h != NULL) | |
845 | { | |
846 | /* Make sure a plt entry is created for this symbol if | |
847 | it turns out to be a function defined by a dynamic | |
848 | object. */ | |
51b64d56 | 849 | h->plt.refcount++; |
252b5132 RH |
850 | } |
851 | break; | |
852 | } | |
853 | /* Fall through. */ | |
854 | case R_68K_8: | |
855 | case R_68K_16: | |
856 | case R_68K_32: | |
857 | if (h != NULL) | |
858 | { | |
859 | /* Make sure a plt entry is created for this symbol if it | |
860 | turns out to be a function defined by a dynamic object. */ | |
51b64d56 | 861 | h->plt.refcount++; |
252b5132 RH |
862 | } |
863 | ||
864 | /* If we are creating a shared library, we need to copy the | |
865 | reloc into the shared library. */ | |
866 | if (info->shared | |
867 | && (sec->flags & SEC_ALLOC) != 0) | |
868 | { | |
869 | /* When creating a shared object, we must copy these | |
870 | reloc types into the output file. We create a reloc | |
871 | section in dynobj and make room for this reloc. */ | |
872 | if (sreloc == NULL) | |
873 | { | |
874 | const char *name; | |
875 | ||
876 | name = (bfd_elf_string_from_elf_section | |
877 | (abfd, | |
878 | elf_elfheader (abfd)->e_shstrndx, | |
879 | elf_section_data (sec)->rel_hdr.sh_name)); | |
880 | if (name == NULL) | |
b34976b6 | 881 | return FALSE; |
252b5132 | 882 | |
0112cd26 | 883 | BFD_ASSERT (CONST_STRNEQ (name, ".rela") |
252b5132 RH |
884 | && strcmp (bfd_get_section_name (abfd, sec), |
885 | name + 5) == 0); | |
886 | ||
887 | sreloc = bfd_get_section_by_name (dynobj, name); | |
888 | if (sreloc == NULL) | |
889 | { | |
3496cb2a L |
890 | sreloc = bfd_make_section_with_flags (dynobj, |
891 | name, | |
892 | (SEC_ALLOC | |
893 | | SEC_LOAD | |
894 | | SEC_HAS_CONTENTS | |
895 | | SEC_IN_MEMORY | |
896 | | SEC_LINKER_CREATED | |
897 | | SEC_READONLY)); | |
252b5132 | 898 | if (sreloc == NULL |
252b5132 | 899 | || !bfd_set_section_alignment (dynobj, sreloc, 2)) |
b34976b6 | 900 | return FALSE; |
252b5132 | 901 | } |
d2ff124f | 902 | elf_section_data (sec)->sreloc = sreloc; |
252b5132 RH |
903 | } |
904 | ||
3e829b4a AS |
905 | if (sec->flags & SEC_READONLY |
906 | /* Don't set DF_TEXTREL yet for PC relative | |
907 | relocations, they might be discarded later. */ | |
908 | && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8 | |
909 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 | |
910 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)) | |
911 | info->flags |= DF_TEXTREL; | |
912 | ||
eea6121a | 913 | sreloc->size += sizeof (Elf32_External_Rela); |
252b5132 | 914 | |
b6152c34 AS |
915 | /* We count the number of PC relative relocations we have |
916 | entered for this symbol, so that we can discard them | |
917 | again if, in the -Bsymbolic case, the symbol is later | |
918 | defined by a regular object, or, in the normal shared | |
919 | case, the symbol is forced to be local. Note that this | |
920 | function is only called if we are using an m68kelf linker | |
921 | hash table, which means that h is really a pointer to an | |
252b5132 | 922 | elf_m68k_link_hash_entry. */ |
b6152c34 AS |
923 | if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8 |
924 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 | |
925 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC32) | |
252b5132 | 926 | { |
252b5132 | 927 | struct elf_m68k_pcrel_relocs_copied *p; |
b6152c34 AS |
928 | struct elf_m68k_pcrel_relocs_copied **head; |
929 | ||
930 | if (h != NULL) | |
931 | { | |
932 | struct elf_m68k_link_hash_entry *eh | |
0cca5f05 | 933 | = elf_m68k_hash_entry (h); |
b6152c34 AS |
934 | head = &eh->pcrel_relocs_copied; |
935 | } | |
936 | else | |
937 | { | |
938 | asection *s; | |
6edfbbad DJ |
939 | void *vpp; |
940 | ||
b6152c34 AS |
941 | s = (bfd_section_from_r_symndx |
942 | (abfd, &elf_m68k_hash_table (info)->sym_sec, | |
943 | sec, r_symndx)); | |
944 | if (s == NULL) | |
945 | return FALSE; | |
252b5132 | 946 | |
6edfbbad DJ |
947 | vpp = &elf_section_data (s)->local_dynrel; |
948 | head = (struct elf_m68k_pcrel_relocs_copied **) vpp; | |
b6152c34 | 949 | } |
252b5132 | 950 | |
b6152c34 | 951 | for (p = *head; p != NULL; p = p->next) |
252b5132 RH |
952 | if (p->section == sreloc) |
953 | break; | |
954 | ||
955 | if (p == NULL) | |
956 | { | |
957 | p = ((struct elf_m68k_pcrel_relocs_copied *) | |
dc810e39 | 958 | bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); |
252b5132 | 959 | if (p == NULL) |
b34976b6 | 960 | return FALSE; |
b6152c34 AS |
961 | p->next = *head; |
962 | *head = p; | |
252b5132 RH |
963 | p->section = sreloc; |
964 | p->count = 0; | |
965 | } | |
966 | ||
967 | ++p->count; | |
968 | } | |
969 | } | |
970 | ||
971 | break; | |
972 | ||
973 | /* This relocation describes the C++ object vtable hierarchy. | |
974 | Reconstruct it for later use during GC. */ | |
975 | case R_68K_GNU_VTINHERIT: | |
c152c796 | 976 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 977 | return FALSE; |
252b5132 RH |
978 | break; |
979 | ||
980 | /* This relocation describes which C++ vtable entries are actually | |
981 | used. Record for later use during GC. */ | |
982 | case R_68K_GNU_VTENTRY: | |
c152c796 | 983 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 984 | return FALSE; |
252b5132 RH |
985 | break; |
986 | ||
987 | default: | |
988 | break; | |
989 | } | |
990 | } | |
991 | ||
b34976b6 | 992 | return TRUE; |
252b5132 RH |
993 | } |
994 | ||
995 | /* Return the section that should be marked against GC for a given | |
996 | relocation. */ | |
997 | ||
998 | static asection * | |
07adf181 AM |
999 | elf_m68k_gc_mark_hook (asection *sec, |
1000 | struct bfd_link_info *info, | |
1001 | Elf_Internal_Rela *rel, | |
1002 | struct elf_link_hash_entry *h, | |
1003 | Elf_Internal_Sym *sym) | |
252b5132 RH |
1004 | { |
1005 | if (h != NULL) | |
07adf181 AM |
1006 | switch (ELF32_R_TYPE (rel->r_info)) |
1007 | { | |
1008 | case R_68K_GNU_VTINHERIT: | |
1009 | case R_68K_GNU_VTENTRY: | |
1010 | return NULL; | |
1011 | } | |
1012 | ||
1013 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
252b5132 RH |
1014 | } |
1015 | ||
1016 | /* Update the got entry reference counts for the section being removed. */ | |
1017 | ||
b34976b6 | 1018 | static bfd_boolean |
07adf181 AM |
1019 | elf_m68k_gc_sweep_hook (bfd *abfd, |
1020 | struct bfd_link_info *info, | |
1021 | asection *sec, | |
1022 | const Elf_Internal_Rela *relocs) | |
252b5132 RH |
1023 | { |
1024 | Elf_Internal_Shdr *symtab_hdr; | |
1025 | struct elf_link_hash_entry **sym_hashes; | |
1026 | bfd_signed_vma *local_got_refcounts; | |
1027 | const Elf_Internal_Rela *rel, *relend; | |
252b5132 | 1028 | bfd *dynobj; |
dd5724d5 AM |
1029 | asection *sgot; |
1030 | asection *srelgot; | |
252b5132 | 1031 | |
252b5132 | 1032 | dynobj = elf_hash_table (info)->dynobj; |
dd5724d5 | 1033 | if (dynobj == NULL) |
b34976b6 | 1034 | return TRUE; |
dd5724d5 | 1035 | |
4f075348 KH |
1036 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
1037 | sym_hashes = elf_sym_hashes (abfd); | |
1038 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
1039 | ||
dd5724d5 AM |
1040 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
1041 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
252b5132 RH |
1042 | |
1043 | relend = relocs + sec->reloc_count; | |
1044 | for (rel = relocs; rel < relend; rel++) | |
1045 | { | |
4f075348 | 1046 | unsigned long r_symndx; |
3eb128b2 AM |
1047 | struct elf_link_hash_entry *h = NULL; |
1048 | ||
1049 | r_symndx = ELF32_R_SYM (rel->r_info); | |
1050 | if (r_symndx >= symtab_hdr->sh_info) | |
1051 | { | |
1052 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1053 | while (h->root.type == bfd_link_hash_indirect | |
1054 | || h->root.type == bfd_link_hash_warning) | |
1055 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
1056 | } | |
4f075348 | 1057 | |
252b5132 RH |
1058 | switch (ELF32_R_TYPE (rel->r_info)) |
1059 | { | |
1060 | case R_68K_GOT8: | |
1061 | case R_68K_GOT16: | |
1062 | case R_68K_GOT32: | |
1063 | case R_68K_GOT8O: | |
1064 | case R_68K_GOT16O: | |
1065 | case R_68K_GOT32O: | |
3eb128b2 | 1066 | if (h != NULL) |
252b5132 | 1067 | { |
252b5132 RH |
1068 | if (h->got.refcount > 0) |
1069 | { | |
1070 | --h->got.refcount; | |
1071 | if (h->got.refcount == 0) | |
1072 | { | |
1073 | /* We don't need the .got entry any more. */ | |
eea6121a AM |
1074 | sgot->size -= 4; |
1075 | srelgot->size -= sizeof (Elf32_External_Rela); | |
252b5132 RH |
1076 | } |
1077 | } | |
1078 | } | |
dd5724d5 | 1079 | else if (local_got_refcounts != NULL) |
252b5132 RH |
1080 | { |
1081 | if (local_got_refcounts[r_symndx] > 0) | |
1082 | { | |
1083 | --local_got_refcounts[r_symndx]; | |
1084 | if (local_got_refcounts[r_symndx] == 0) | |
1085 | { | |
1086 | /* We don't need the .got entry any more. */ | |
eea6121a | 1087 | sgot->size -= 4; |
252b5132 | 1088 | if (info->shared) |
eea6121a | 1089 | srelgot->size -= sizeof (Elf32_External_Rela); |
252b5132 RH |
1090 | } |
1091 | } | |
1092 | } | |
1093 | break; | |
1094 | ||
1095 | case R_68K_PLT8: | |
1096 | case R_68K_PLT16: | |
1097 | case R_68K_PLT32: | |
1098 | case R_68K_PLT8O: | |
1099 | case R_68K_PLT16O: | |
1100 | case R_68K_PLT32O: | |
1101 | case R_68K_PC8: | |
1102 | case R_68K_PC16: | |
1103 | case R_68K_PC32: | |
1104 | case R_68K_8: | |
1105 | case R_68K_16: | |
1106 | case R_68K_32: | |
3eb128b2 | 1107 | if (h != NULL) |
252b5132 | 1108 | { |
252b5132 RH |
1109 | if (h->plt.refcount > 0) |
1110 | --h->plt.refcount; | |
1111 | } | |
1112 | break; | |
1113 | ||
1114 | default: | |
1115 | break; | |
1116 | } | |
1117 | } | |
1118 | ||
b34976b6 | 1119 | return TRUE; |
252b5132 | 1120 | } |
cc3e26be RS |
1121 | \f |
1122 | /* Return the type of PLT associated with OUTPUT_BFD. */ | |
1123 | ||
1124 | static const struct elf_m68k_plt_info * | |
1125 | elf_m68k_get_plt_info (bfd *output_bfd) | |
1126 | { | |
1127 | unsigned int features; | |
1128 | ||
1129 | features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd)); | |
1130 | if (features & cpu32) | |
1131 | return &elf_cpu32_plt_info; | |
1132 | if (features & mcfisa_b) | |
1133 | return &elf_isab_plt_info; | |
1134 | return &elf_m68k_plt_info; | |
1135 | } | |
1136 | ||
1137 | /* This function is called after all the input files have been read, | |
1138 | and the input sections have been assigned to output sections. | |
1139 | It's a convenient place to determine the PLT style. */ | |
1140 | ||
1141 | static bfd_boolean | |
1142 | elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info) | |
1143 | { | |
1144 | elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd); | |
1145 | return TRUE; | |
1146 | } | |
252b5132 | 1147 | |
252b5132 RH |
1148 | /* Adjust a symbol defined by a dynamic object and referenced by a |
1149 | regular object. The current definition is in some section of the | |
1150 | dynamic object, but we're not including those sections. We have to | |
1151 | change the definition to something the rest of the link can | |
1152 | understand. */ | |
1153 | ||
b34976b6 | 1154 | static bfd_boolean |
252b5132 RH |
1155 | elf_m68k_adjust_dynamic_symbol (info, h) |
1156 | struct bfd_link_info *info; | |
1157 | struct elf_link_hash_entry *h; | |
1158 | { | |
cc3e26be | 1159 | struct elf_m68k_link_hash_table *htab; |
252b5132 RH |
1160 | bfd *dynobj; |
1161 | asection *s; | |
1162 | unsigned int power_of_two; | |
1163 | ||
cc3e26be | 1164 | htab = elf_m68k_hash_table (info); |
252b5132 RH |
1165 | dynobj = elf_hash_table (info)->dynobj; |
1166 | ||
1167 | /* Make sure we know what is going on here. */ | |
1168 | BFD_ASSERT (dynobj != NULL | |
f5385ebf | 1169 | && (h->needs_plt |
f6e332e6 | 1170 | || h->u.weakdef != NULL |
f5385ebf AM |
1171 | || (h->def_dynamic |
1172 | && h->ref_regular | |
1173 | && !h->def_regular))); | |
252b5132 RH |
1174 | |
1175 | /* If this is a function, put it in the procedure linkage table. We | |
1176 | will fill in the contents of the procedure linkage table later, | |
1177 | when we know the address of the .got section. */ | |
1178 | if (h->type == STT_FUNC | |
f5385ebf | 1179 | || h->needs_plt) |
252b5132 | 1180 | { |
9dfe8738 AS |
1181 | if ((h->plt.refcount <= 0 |
1182 | || SYMBOL_CALLS_LOCAL (info, h) | |
1183 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
1184 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
1185 | /* We must always create the plt entry if it was referenced |
1186 | by a PLTxxO relocation. In this case we already recorded | |
1187 | it as a dynamic symbol. */ | |
1188 | && h->dynindx == -1) | |
1189 | { | |
1190 | /* This case can occur if we saw a PLTxx reloc in an input | |
1191 | file, but the symbol was never referred to by a dynamic | |
9dfe8738 AS |
1192 | object, or if all references were garbage collected. In |
1193 | such a case, we don't actually need to build a procedure | |
1194 | linkage table, and we can just do a PCxx reloc instead. */ | |
252b5132 | 1195 | h->plt.offset = (bfd_vma) -1; |
f5385ebf | 1196 | h->needs_plt = 0; |
b34976b6 | 1197 | return TRUE; |
252b5132 RH |
1198 | } |
1199 | ||
1200 | /* Make sure this symbol is output as a dynamic symbol. */ | |
b6152c34 | 1201 | if (h->dynindx == -1 |
f5385ebf | 1202 | && !h->forced_local) |
252b5132 | 1203 | { |
c152c796 | 1204 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 1205 | return FALSE; |
252b5132 RH |
1206 | } |
1207 | ||
1208 | s = bfd_get_section_by_name (dynobj, ".plt"); | |
1209 | BFD_ASSERT (s != NULL); | |
1210 | ||
1211 | /* If this is the first .plt entry, make room for the special | |
1212 | first entry. */ | |
eea6121a | 1213 | if (s->size == 0) |
cc3e26be | 1214 | s->size = htab->plt_info->size; |
252b5132 RH |
1215 | |
1216 | /* If this symbol is not defined in a regular file, and we are | |
1217 | not generating a shared library, then set the symbol to this | |
1218 | location in the .plt. This is required to make function | |
1219 | pointers compare as equal between the normal executable and | |
1220 | the shared library. */ | |
1221 | if (!info->shared | |
f5385ebf | 1222 | && !h->def_regular) |
252b5132 RH |
1223 | { |
1224 | h->root.u.def.section = s; | |
eea6121a | 1225 | h->root.u.def.value = s->size; |
252b5132 RH |
1226 | } |
1227 | ||
eea6121a | 1228 | h->plt.offset = s->size; |
252b5132 RH |
1229 | |
1230 | /* Make room for this entry. */ | |
cc3e26be | 1231 | s->size += htab->plt_info->size; |
252b5132 RH |
1232 | |
1233 | /* We also need to make an entry in the .got.plt section, which | |
1234 | will be placed in the .got section by the linker script. */ | |
252b5132 RH |
1235 | s = bfd_get_section_by_name (dynobj, ".got.plt"); |
1236 | BFD_ASSERT (s != NULL); | |
eea6121a | 1237 | s->size += 4; |
252b5132 RH |
1238 | |
1239 | /* We also need to make an entry in the .rela.plt section. */ | |
252b5132 RH |
1240 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); |
1241 | BFD_ASSERT (s != NULL); | |
eea6121a | 1242 | s->size += sizeof (Elf32_External_Rela); |
252b5132 | 1243 | |
b34976b6 | 1244 | return TRUE; |
252b5132 RH |
1245 | } |
1246 | ||
1247 | /* Reinitialize the plt offset now that it is not used as a reference | |
1248 | count any more. */ | |
1249 | h->plt.offset = (bfd_vma) -1; | |
1250 | ||
1251 | /* If this is a weak symbol, and there is a real definition, the | |
1252 | processor independent code will have arranged for us to see the | |
1253 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 1254 | if (h->u.weakdef != NULL) |
252b5132 | 1255 | { |
f6e332e6 AM |
1256 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
1257 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
1258 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
1259 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 1260 | return TRUE; |
252b5132 RH |
1261 | } |
1262 | ||
1263 | /* This is a reference to a symbol defined by a dynamic object which | |
1264 | is not a function. */ | |
1265 | ||
1266 | /* If we are creating a shared library, we must presume that the | |
1267 | only references to the symbol are via the global offset table. | |
1268 | For such cases we need not do anything here; the relocations will | |
1269 | be handled correctly by relocate_section. */ | |
1270 | if (info->shared) | |
b34976b6 | 1271 | return TRUE; |
252b5132 | 1272 | |
909272ee AM |
1273 | if (h->size == 0) |
1274 | { | |
1275 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
1276 | h->root.root.string); | |
1277 | return TRUE; | |
1278 | } | |
1279 | ||
252b5132 RH |
1280 | /* We must allocate the symbol in our .dynbss section, which will |
1281 | become part of the .bss section of the executable. There will be | |
1282 | an entry for this symbol in the .dynsym section. The dynamic | |
1283 | object will contain position independent code, so all references | |
1284 | from the dynamic object to this symbol will go through the global | |
1285 | offset table. The dynamic linker will use the .dynsym entry to | |
1286 | determine the address it must put in the global offset table, so | |
1287 | both the dynamic object and the regular object will refer to the | |
1288 | same memory location for the variable. */ | |
1289 | ||
1290 | s = bfd_get_section_by_name (dynobj, ".dynbss"); | |
1291 | BFD_ASSERT (s != NULL); | |
1292 | ||
1293 | /* We must generate a R_68K_COPY reloc to tell the dynamic linker to | |
1294 | copy the initial value out of the dynamic object and into the | |
1295 | runtime process image. We need to remember the offset into the | |
1296 | .rela.bss section we are going to use. */ | |
1297 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
1298 | { | |
1299 | asection *srel; | |
1300 | ||
1301 | srel = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
1302 | BFD_ASSERT (srel != NULL); | |
eea6121a | 1303 | srel->size += sizeof (Elf32_External_Rela); |
f5385ebf | 1304 | h->needs_copy = 1; |
252b5132 RH |
1305 | } |
1306 | ||
1307 | /* We need to figure out the alignment required for this symbol. I | |
1308 | have no idea how ELF linkers handle this. */ | |
1309 | power_of_two = bfd_log2 (h->size); | |
1310 | if (power_of_two > 3) | |
1311 | power_of_two = 3; | |
1312 | ||
1313 | /* Apply the required alignment. */ | |
eea6121a | 1314 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
1315 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
1316 | { | |
1317 | if (!bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 1318 | return FALSE; |
252b5132 RH |
1319 | } |
1320 | ||
1321 | /* Define the symbol as being at this point in the section. */ | |
1322 | h->root.u.def.section = s; | |
eea6121a | 1323 | h->root.u.def.value = s->size; |
252b5132 RH |
1324 | |
1325 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 1326 | s->size += h->size; |
252b5132 | 1327 | |
b34976b6 | 1328 | return TRUE; |
252b5132 RH |
1329 | } |
1330 | ||
1331 | /* Set the sizes of the dynamic sections. */ | |
1332 | ||
b34976b6 | 1333 | static bfd_boolean |
252b5132 | 1334 | elf_m68k_size_dynamic_sections (output_bfd, info) |
aa91b392 | 1335 | bfd *output_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1336 | struct bfd_link_info *info; |
1337 | { | |
1338 | bfd *dynobj; | |
1339 | asection *s; | |
b34976b6 AM |
1340 | bfd_boolean plt; |
1341 | bfd_boolean relocs; | |
252b5132 RH |
1342 | |
1343 | dynobj = elf_hash_table (info)->dynobj; | |
1344 | BFD_ASSERT (dynobj != NULL); | |
1345 | ||
1346 | if (elf_hash_table (info)->dynamic_sections_created) | |
1347 | { | |
1348 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 1349 | if (info->executable) |
252b5132 RH |
1350 | { |
1351 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
1352 | BFD_ASSERT (s != NULL); | |
eea6121a | 1353 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
1354 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
1355 | } | |
1356 | } | |
1357 | else | |
1358 | { | |
1359 | /* We may have created entries in the .rela.got section. | |
1360 | However, if we are not creating the dynamic sections, we will | |
1361 | not actually use these entries. Reset the size of .rela.got, | |
1362 | which will cause it to get stripped from the output file | |
1363 | below. */ | |
1364 | s = bfd_get_section_by_name (dynobj, ".rela.got"); | |
1365 | if (s != NULL) | |
eea6121a | 1366 | s->size = 0; |
252b5132 RH |
1367 | } |
1368 | ||
b6152c34 AS |
1369 | /* If this is a -Bsymbolic shared link, then we need to discard all |
1370 | PC relative relocs against symbols defined in a regular object. | |
1371 | For the normal shared case we discard the PC relative relocs | |
1372 | against symbols that have become local due to visibility changes. | |
1373 | We allocated space for them in the check_relocs routine, but we | |
1374 | will not fill them in in the relocate_section routine. */ | |
1375 | if (info->shared) | |
0cca5f05 AS |
1376 | elf_link_hash_traverse (elf_hash_table (info), |
1377 | elf_m68k_discard_copies, | |
1378 | (PTR) info); | |
252b5132 RH |
1379 | |
1380 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
1381 | determined the sizes of the various dynamic sections. Allocate | |
1382 | memory for them. */ | |
b34976b6 AM |
1383 | plt = FALSE; |
1384 | relocs = FALSE; | |
252b5132 RH |
1385 | for (s = dynobj->sections; s != NULL; s = s->next) |
1386 | { | |
1387 | const char *name; | |
252b5132 RH |
1388 | |
1389 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
1390 | continue; | |
1391 | ||
1392 | /* It's OK to base decisions on the section name, because none | |
1393 | of the dynobj section names depend upon the input files. */ | |
1394 | name = bfd_get_section_name (dynobj, s); | |
1395 | ||
252b5132 RH |
1396 | if (strcmp (name, ".plt") == 0) |
1397 | { | |
c456f082 AM |
1398 | /* Remember whether there is a PLT. */ |
1399 | plt = s->size != 0; | |
252b5132 | 1400 | } |
0112cd26 | 1401 | else if (CONST_STRNEQ (name, ".rela")) |
252b5132 | 1402 | { |
c456f082 | 1403 | if (s->size != 0) |
252b5132 | 1404 | { |
b34976b6 | 1405 | relocs = TRUE; |
252b5132 RH |
1406 | |
1407 | /* We use the reloc_count field as a counter if we need | |
1408 | to copy relocs into the output file. */ | |
1409 | s->reloc_count = 0; | |
1410 | } | |
1411 | } | |
0112cd26 | 1412 | else if (! CONST_STRNEQ (name, ".got") |
c456f082 | 1413 | && strcmp (name, ".dynbss") != 0) |
252b5132 RH |
1414 | { |
1415 | /* It's not one of our sections, so don't allocate space. */ | |
1416 | continue; | |
1417 | } | |
1418 | ||
c456f082 | 1419 | if (s->size == 0) |
252b5132 | 1420 | { |
c456f082 AM |
1421 | /* If we don't need this section, strip it from the |
1422 | output file. This is mostly to handle .rela.bss and | |
1423 | .rela.plt. We must create both sections in | |
1424 | create_dynamic_sections, because they must be created | |
1425 | before the linker maps input sections to output | |
1426 | sections. The linker does that before | |
1427 | adjust_dynamic_symbol is called, and it is that | |
1428 | function which decides whether anything needs to go | |
1429 | into these sections. */ | |
8423293d | 1430 | s->flags |= SEC_EXCLUDE; |
252b5132 RH |
1431 | continue; |
1432 | } | |
1433 | ||
c456f082 AM |
1434 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
1435 | continue; | |
1436 | ||
252b5132 | 1437 | /* Allocate memory for the section contents. */ |
7a9af8c4 NC |
1438 | /* FIXME: This should be a call to bfd_alloc not bfd_zalloc. |
1439 | Unused entries should be reclaimed before the section's contents | |
1440 | are written out, but at the moment this does not happen. Thus in | |
1441 | order to prevent writing out garbage, we initialise the section's | |
1442 | contents to zero. */ | |
eea6121a | 1443 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
c456f082 | 1444 | if (s->contents == NULL) |
b34976b6 | 1445 | return FALSE; |
252b5132 RH |
1446 | } |
1447 | ||
1448 | if (elf_hash_table (info)->dynamic_sections_created) | |
1449 | { | |
1450 | /* Add some entries to the .dynamic section. We fill in the | |
1451 | values later, in elf_m68k_finish_dynamic_sections, but we | |
1452 | must add the entries now so that we get the correct size for | |
1453 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
1454 | dynamic linker and used by the debugger. */ | |
dc810e39 | 1455 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 1456 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 1457 | |
252b5132 RH |
1458 | if (!info->shared) |
1459 | { | |
dc810e39 | 1460 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 1461 | return FALSE; |
252b5132 RH |
1462 | } |
1463 | ||
1464 | if (plt) | |
1465 | { | |
dc810e39 AM |
1466 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
1467 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
1468 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
1469 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 1470 | return FALSE; |
252b5132 RH |
1471 | } |
1472 | ||
1473 | if (relocs) | |
1474 | { | |
dc810e39 AM |
1475 | if (!add_dynamic_entry (DT_RELA, 0) |
1476 | || !add_dynamic_entry (DT_RELASZ, 0) | |
1477 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
b34976b6 | 1478 | return FALSE; |
252b5132 RH |
1479 | } |
1480 | ||
aa91b392 | 1481 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 1482 | { |
dc810e39 | 1483 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 1484 | return FALSE; |
252b5132 RH |
1485 | } |
1486 | } | |
dc810e39 | 1487 | #undef add_dynamic_entry |
252b5132 | 1488 | |
b34976b6 | 1489 | return TRUE; |
252b5132 RH |
1490 | } |
1491 | ||
0cca5f05 | 1492 | /* This function is called via elf_link_hash_traverse if we are |
b6152c34 AS |
1493 | creating a shared object. In the -Bsymbolic case it discards the |
1494 | space allocated to copy PC relative relocs against symbols which | |
3e829b4a | 1495 | are defined in regular objects. For the normal shared case, it |
b6152c34 AS |
1496 | discards space for pc-relative relocs that have become local due to |
1497 | symbol visibility changes. We allocated space for them in the | |
1498 | check_relocs routine, but we won't fill them in in the | |
3e829b4a AS |
1499 | relocate_section routine. |
1500 | ||
1501 | We also check whether any of the remaining relocations apply | |
1502 | against a readonly section, and set the DF_TEXTREL flag in this | |
1503 | case. */ | |
252b5132 | 1504 | |
b34976b6 | 1505 | static bfd_boolean |
b6152c34 | 1506 | elf_m68k_discard_copies (h, inf) |
0cca5f05 | 1507 | struct elf_link_hash_entry *h; |
b6152c34 | 1508 | PTR inf; |
252b5132 | 1509 | { |
b6152c34 | 1510 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
252b5132 RH |
1511 | struct elf_m68k_pcrel_relocs_copied *s; |
1512 | ||
0cca5f05 AS |
1513 | if (h->root.type == bfd_link_hash_warning) |
1514 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
e92d460e | 1515 | |
f5385ebf | 1516 | if (!h->def_regular |
b6152c34 | 1517 | || (!info->symbolic |
f5385ebf | 1518 | && !h->forced_local)) |
3e829b4a AS |
1519 | { |
1520 | if ((info->flags & DF_TEXTREL) == 0) | |
1521 | { | |
1522 | /* Look for relocations against read-only sections. */ | |
0cca5f05 AS |
1523 | for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; |
1524 | s != NULL; | |
1525 | s = s->next) | |
3e829b4a AS |
1526 | if ((s->section->flags & SEC_READONLY) != 0) |
1527 | { | |
1528 | info->flags |= DF_TEXTREL; | |
1529 | break; | |
1530 | } | |
1531 | } | |
0cca5f05 | 1532 | |
3e829b4a AS |
1533 | return TRUE; |
1534 | } | |
252b5132 | 1535 | |
0cca5f05 AS |
1536 | for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; |
1537 | s != NULL; | |
1538 | s = s->next) | |
eea6121a | 1539 | s->section->size -= s->count * sizeof (Elf32_External_Rela); |
252b5132 | 1540 | |
b34976b6 | 1541 | return TRUE; |
252b5132 RH |
1542 | } |
1543 | ||
1544 | /* Relocate an M68K ELF section. */ | |
1545 | ||
b34976b6 | 1546 | static bfd_boolean |
252b5132 RH |
1547 | elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, |
1548 | contents, relocs, local_syms, local_sections) | |
1549 | bfd *output_bfd; | |
1550 | struct bfd_link_info *info; | |
1551 | bfd *input_bfd; | |
1552 | asection *input_section; | |
1553 | bfd_byte *contents; | |
1554 | Elf_Internal_Rela *relocs; | |
1555 | Elf_Internal_Sym *local_syms; | |
1556 | asection **local_sections; | |
1557 | { | |
1558 | bfd *dynobj; | |
1559 | Elf_Internal_Shdr *symtab_hdr; | |
1560 | struct elf_link_hash_entry **sym_hashes; | |
1561 | bfd_vma *local_got_offsets; | |
1562 | asection *sgot; | |
1563 | asection *splt; | |
1564 | asection *sreloc; | |
1565 | Elf_Internal_Rela *rel; | |
1566 | Elf_Internal_Rela *relend; | |
1567 | ||
1568 | dynobj = elf_hash_table (info)->dynobj; | |
1569 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
1570 | sym_hashes = elf_sym_hashes (input_bfd); | |
1571 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
1572 | ||
1573 | sgot = NULL; | |
1574 | splt = NULL; | |
1575 | sreloc = NULL; | |
1576 | ||
1577 | rel = relocs; | |
1578 | relend = relocs + input_section->reloc_count; | |
1579 | for (; rel < relend; rel++) | |
1580 | { | |
1581 | int r_type; | |
1582 | reloc_howto_type *howto; | |
1583 | unsigned long r_symndx; | |
1584 | struct elf_link_hash_entry *h; | |
1585 | Elf_Internal_Sym *sym; | |
1586 | asection *sec; | |
1587 | bfd_vma relocation; | |
44f745a6 | 1588 | bfd_boolean unresolved_reloc; |
252b5132 RH |
1589 | bfd_reloc_status_type r; |
1590 | ||
1591 | r_type = ELF32_R_TYPE (rel->r_info); | |
1592 | if (r_type < 0 || r_type >= (int) R_68K_max) | |
1593 | { | |
1594 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1595 | return FALSE; |
252b5132 RH |
1596 | } |
1597 | howto = howto_table + r_type; | |
1598 | ||
1599 | r_symndx = ELF32_R_SYM (rel->r_info); | |
1600 | ||
252b5132 RH |
1601 | h = NULL; |
1602 | sym = NULL; | |
1603 | sec = NULL; | |
44f745a6 | 1604 | unresolved_reloc = FALSE; |
560e09e9 | 1605 | |
252b5132 RH |
1606 | if (r_symndx < symtab_hdr->sh_info) |
1607 | { | |
1608 | sym = local_syms + r_symndx; | |
1609 | sec = local_sections[r_symndx]; | |
8517fae7 | 1610 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
252b5132 RH |
1611 | } |
1612 | else | |
1613 | { | |
560e09e9 NC |
1614 | bfd_boolean warned; |
1615 | ||
b2a8e766 AM |
1616 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
1617 | r_symndx, symtab_hdr, sym_hashes, | |
1618 | h, sec, relocation, | |
1619 | unresolved_reloc, warned); | |
252b5132 RH |
1620 | } |
1621 | ||
ab96bf03 AM |
1622 | if (sec != NULL && elf_discarded_section (sec)) |
1623 | { | |
1624 | /* For relocs against symbols from removed linkonce sections, | |
1625 | or sections discarded by a linker script, we just want the | |
1626 | section contents zeroed. Avoid any special processing. */ | |
1627 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
1628 | rel->r_info = 0; | |
1629 | rel->r_addend = 0; | |
1630 | continue; | |
1631 | } | |
1632 | ||
1633 | if (info->relocatable) | |
1634 | continue; | |
1635 | ||
252b5132 RH |
1636 | switch (r_type) |
1637 | { | |
1638 | case R_68K_GOT8: | |
1639 | case R_68K_GOT16: | |
1640 | case R_68K_GOT32: | |
1641 | /* Relocation is to the address of the entry for this symbol | |
1642 | in the global offset table. */ | |
1643 | if (h != NULL | |
1644 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
1645 | break; | |
1646 | /* Fall through. */ | |
1647 | case R_68K_GOT8O: | |
1648 | case R_68K_GOT16O: | |
1649 | case R_68K_GOT32O: | |
1650 | /* Relocation is the offset of the entry for this symbol in | |
1651 | the global offset table. */ | |
1652 | ||
1653 | { | |
1654 | bfd_vma off; | |
1655 | ||
1656 | if (sgot == NULL) | |
1657 | { | |
1658 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
1659 | BFD_ASSERT (sgot != NULL); | |
1660 | } | |
1661 | ||
1662 | if (h != NULL) | |
1663 | { | |
a5ad465a AS |
1664 | bfd_boolean dyn; |
1665 | ||
252b5132 RH |
1666 | off = h->got.offset; |
1667 | BFD_ASSERT (off != (bfd_vma) -1); | |
1668 | ||
a5ad465a AS |
1669 | dyn = elf_hash_table (info)->dynamic_sections_created; |
1670 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
252b5132 | 1671 | || (info->shared |
a5ad465a AS |
1672 | && (info->symbolic |
1673 | || h->dynindx == -1 | |
f5385ebf AM |
1674 | || h->forced_local) |
1675 | && h->def_regular)) | |
252b5132 RH |
1676 | { |
1677 | /* This is actually a static link, or it is a | |
1678 | -Bsymbolic link and the symbol is defined | |
1679 | locally, or the symbol was forced to be local | |
1680 | because of a version file.. We must initialize | |
1681 | this entry in the global offset table. Since | |
1682 | the offset must always be a multiple of 4, we | |
1683 | use the least significant bit to record whether | |
1684 | we have initialized it already. | |
1685 | ||
1686 | When doing a dynamic link, we create a .rela.got | |
1687 | relocation entry to initialize the value. This | |
1688 | is done in the finish_dynamic_symbol routine. */ | |
1689 | if ((off & 1) != 0) | |
1690 | off &= ~1; | |
1691 | else | |
1692 | { | |
1693 | bfd_put_32 (output_bfd, relocation, | |
1694 | sgot->contents + off); | |
1695 | h->got.offset |= 1; | |
1696 | } | |
1697 | } | |
44f745a6 AS |
1698 | else |
1699 | unresolved_reloc = FALSE; | |
252b5132 RH |
1700 | } |
1701 | else | |
1702 | { | |
1703 | BFD_ASSERT (local_got_offsets != NULL | |
1704 | && local_got_offsets[r_symndx] != (bfd_vma) -1); | |
1705 | ||
1706 | off = local_got_offsets[r_symndx]; | |
1707 | ||
1708 | /* The offset must always be a multiple of 4. We use | |
1709 | the least significant bit to record whether we have | |
1710 | already generated the necessary reloc. */ | |
1711 | if ((off & 1) != 0) | |
1712 | off &= ~1; | |
1713 | else | |
1714 | { | |
1715 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); | |
1716 | ||
1717 | if (info->shared) | |
1718 | { | |
947216bf | 1719 | asection *s; |
252b5132 | 1720 | Elf_Internal_Rela outrel; |
947216bf | 1721 | bfd_byte *loc; |
252b5132 | 1722 | |
947216bf AM |
1723 | s = bfd_get_section_by_name (dynobj, ".rela.got"); |
1724 | BFD_ASSERT (s != NULL); | |
252b5132 RH |
1725 | |
1726 | outrel.r_offset = (sgot->output_section->vma | |
1727 | + sgot->output_offset | |
1728 | + off); | |
1729 | outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); | |
1730 | outrel.r_addend = relocation; | |
947216bf AM |
1731 | loc = s->contents; |
1732 | loc += s->reloc_count++ * sizeof (Elf32_External_Rela); | |
1733 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 RH |
1734 | } |
1735 | ||
1736 | local_got_offsets[r_symndx] |= 1; | |
1737 | } | |
1738 | } | |
1739 | ||
1740 | relocation = sgot->output_offset + off; | |
1741 | if (r_type == R_68K_GOT8O | |
1742 | || r_type == R_68K_GOT16O | |
1743 | || r_type == R_68K_GOT32O) | |
1744 | { | |
1745 | /* This relocation does not use the addend. */ | |
1746 | rel->r_addend = 0; | |
1747 | } | |
1748 | else | |
1749 | relocation += sgot->output_section->vma; | |
1750 | } | |
1751 | break; | |
1752 | ||
1753 | case R_68K_PLT8: | |
1754 | case R_68K_PLT16: | |
1755 | case R_68K_PLT32: | |
1756 | /* Relocation is to the entry for this symbol in the | |
1757 | procedure linkage table. */ | |
1758 | ||
1759 | /* Resolve a PLTxx reloc against a local symbol directly, | |
1760 | without using the procedure linkage table. */ | |
1761 | if (h == NULL) | |
1762 | break; | |
1763 | ||
1764 | if (h->plt.offset == (bfd_vma) -1 | |
1765 | || !elf_hash_table (info)->dynamic_sections_created) | |
1766 | { | |
1767 | /* We didn't make a PLT entry for this symbol. This | |
1768 | happens when statically linking PIC code, or when | |
1769 | using -Bsymbolic. */ | |
1770 | break; | |
1771 | } | |
1772 | ||
1773 | if (splt == NULL) | |
1774 | { | |
1775 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1776 | BFD_ASSERT (splt != NULL); | |
1777 | } | |
1778 | ||
1779 | relocation = (splt->output_section->vma | |
1780 | + splt->output_offset | |
1781 | + h->plt.offset); | |
44f745a6 | 1782 | unresolved_reloc = FALSE; |
252b5132 RH |
1783 | break; |
1784 | ||
1785 | case R_68K_PLT8O: | |
1786 | case R_68K_PLT16O: | |
1787 | case R_68K_PLT32O: | |
1788 | /* Relocation is the offset of the entry for this symbol in | |
1789 | the procedure linkage table. */ | |
1790 | BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1); | |
1791 | ||
1792 | if (splt == NULL) | |
1793 | { | |
1794 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1795 | BFD_ASSERT (splt != NULL); | |
1796 | } | |
1797 | ||
1798 | relocation = h->plt.offset; | |
44f745a6 | 1799 | unresolved_reloc = FALSE; |
252b5132 RH |
1800 | |
1801 | /* This relocation does not use the addend. */ | |
1802 | rel->r_addend = 0; | |
1803 | ||
1804 | break; | |
1805 | ||
1806 | case R_68K_PC8: | |
1807 | case R_68K_PC16: | |
1808 | case R_68K_PC32: | |
b6152c34 AS |
1809 | if (h == NULL |
1810 | || (info->shared | |
f5385ebf | 1811 | && h->forced_local)) |
252b5132 RH |
1812 | break; |
1813 | /* Fall through. */ | |
1814 | case R_68K_8: | |
1815 | case R_68K_16: | |
1816 | case R_68K_32: | |
1817 | if (info->shared | |
ec338859 | 1818 | && r_symndx != 0 |
252b5132 | 1819 | && (input_section->flags & SEC_ALLOC) != 0 |
d2ff124f AS |
1820 | && (h == NULL |
1821 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
1822 | || h->root.type != bfd_link_hash_undefweak) | |
252b5132 RH |
1823 | && ((r_type != R_68K_PC8 |
1824 | && r_type != R_68K_PC16 | |
1825 | && r_type != R_68K_PC32) | |
d2ff124f AS |
1826 | || (h != NULL |
1827 | && h->dynindx != -1 | |
1828 | && (!info->symbolic | |
f5385ebf | 1829 | || !h->def_regular)))) |
252b5132 RH |
1830 | { |
1831 | Elf_Internal_Rela outrel; | |
947216bf | 1832 | bfd_byte *loc; |
b34976b6 | 1833 | bfd_boolean skip, relocate; |
252b5132 RH |
1834 | |
1835 | /* When generating a shared object, these relocations | |
1836 | are copied into the output file to be resolved at run | |
1837 | time. */ | |
1838 | ||
b34976b6 AM |
1839 | skip = FALSE; |
1840 | relocate = FALSE; | |
252b5132 | 1841 | |
c629eae0 JJ |
1842 | outrel.r_offset = |
1843 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
1844 | rel->r_offset); | |
1845 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 1846 | skip = TRUE; |
0bb2d96a | 1847 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 1848 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
1849 | outrel.r_offset += (input_section->output_section->vma |
1850 | + input_section->output_offset); | |
1851 | ||
1852 | if (skip) | |
0bb2d96a | 1853 | memset (&outrel, 0, sizeof outrel); |
252b5132 | 1854 | else if (h != NULL |
d2ff124f AS |
1855 | && h->dynindx != -1 |
1856 | && (r_type == R_68K_PC8 | |
1857 | || r_type == R_68K_PC16 | |
1858 | || r_type == R_68K_PC32 | |
1859 | || !info->shared | |
1860 | || !info->symbolic | |
f5385ebf | 1861 | || !h->def_regular)) |
252b5132 | 1862 | { |
252b5132 | 1863 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
d2ff124f | 1864 | outrel.r_addend = rel->r_addend; |
252b5132 RH |
1865 | } |
1866 | else | |
1867 | { | |
d2ff124f | 1868 | /* This symbol is local, or marked to become local. */ |
74541ad4 AM |
1869 | outrel.r_addend = relocation + rel->r_addend; |
1870 | ||
252b5132 RH |
1871 | if (r_type == R_68K_32) |
1872 | { | |
b34976b6 | 1873 | relocate = TRUE; |
252b5132 | 1874 | outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); |
252b5132 RH |
1875 | } |
1876 | else | |
1877 | { | |
1878 | long indx; | |
1879 | ||
8517fae7 | 1880 | if (bfd_is_abs_section (sec)) |
252b5132 RH |
1881 | indx = 0; |
1882 | else if (sec == NULL || sec->owner == NULL) | |
1883 | { | |
1884 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1885 | return FALSE; |
252b5132 RH |
1886 | } |
1887 | else | |
1888 | { | |
1889 | asection *osec; | |
1890 | ||
74541ad4 AM |
1891 | /* We are turning this relocation into one |
1892 | against a section symbol. It would be | |
1893 | proper to subtract the symbol's value, | |
1894 | osec->vma, from the emitted reloc addend, | |
1895 | but ld.so expects buggy relocs. */ | |
252b5132 RH |
1896 | osec = sec->output_section; |
1897 | indx = elf_section_data (osec)->dynindx; | |
74541ad4 AM |
1898 | if (indx == 0) |
1899 | { | |
1900 | struct elf_link_hash_table *htab; | |
1901 | htab = elf_hash_table (info); | |
1902 | osec = htab->text_index_section; | |
1903 | indx = elf_section_data (osec)->dynindx; | |
1904 | } | |
1905 | BFD_ASSERT (indx != 0); | |
252b5132 RH |
1906 | } |
1907 | ||
252b5132 | 1908 | outrel.r_info = ELF32_R_INFO (indx, r_type); |
252b5132 RH |
1909 | } |
1910 | } | |
1911 | ||
d2ff124f AS |
1912 | sreloc = elf_section_data (input_section)->sreloc; |
1913 | if (sreloc == NULL) | |
1914 | abort (); | |
1915 | ||
947216bf AM |
1916 | loc = sreloc->contents; |
1917 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
1918 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 RH |
1919 | |
1920 | /* This reloc will be computed at runtime, so there's no | |
1921 | need to do anything now, except for R_68K_32 | |
1922 | relocations that have been turned into | |
1923 | R_68K_RELATIVE. */ | |
1924 | if (!relocate) | |
1925 | continue; | |
1926 | } | |
1927 | ||
1928 | break; | |
1929 | ||
1930 | case R_68K_GNU_VTINHERIT: | |
1931 | case R_68K_GNU_VTENTRY: | |
1932 | /* These are no-ops in the end. */ | |
1933 | continue; | |
1934 | ||
1935 | default: | |
1936 | break; | |
1937 | } | |
1938 | ||
44f745a6 AS |
1939 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
1940 | because such sections are not SEC_ALLOC and thus ld.so will | |
1941 | not process them. */ | |
1942 | if (unresolved_reloc | |
1943 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
f5385ebf | 1944 | && h->def_dynamic)) |
44f745a6 AS |
1945 | { |
1946 | (*_bfd_error_handler) | |
843fe662 | 1947 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
d003868e AM |
1948 | input_bfd, |
1949 | input_section, | |
44f745a6 | 1950 | (long) rel->r_offset, |
843fe662 | 1951 | howto->name, |
44f745a6 AS |
1952 | h->root.root.string); |
1953 | return FALSE; | |
1954 | } | |
1955 | ||
252b5132 RH |
1956 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
1957 | contents, rel->r_offset, | |
1958 | relocation, rel->r_addend); | |
1959 | ||
1960 | if (r != bfd_reloc_ok) | |
1961 | { | |
44f745a6 AS |
1962 | const char *name; |
1963 | ||
1964 | if (h != NULL) | |
1965 | name = h->root.root.string; | |
1966 | else | |
252b5132 | 1967 | { |
44f745a6 AS |
1968 | name = bfd_elf_string_from_elf_section (input_bfd, |
1969 | symtab_hdr->sh_link, | |
1970 | sym->st_name); | |
1971 | if (name == NULL) | |
1972 | return FALSE; | |
1973 | if (*name == '\0') | |
1974 | name = bfd_section_name (input_bfd, sec); | |
1975 | } | |
252b5132 | 1976 | |
44f745a6 AS |
1977 | if (r == bfd_reloc_overflow) |
1978 | { | |
1979 | if (!(info->callbacks->reloc_overflow | |
dfeffb9f L |
1980 | (info, (h ? &h->root : NULL), name, howto->name, |
1981 | (bfd_vma) 0, input_bfd, input_section, | |
1982 | rel->r_offset))) | |
44f745a6 AS |
1983 | return FALSE; |
1984 | } | |
1985 | else | |
1986 | { | |
1987 | (*_bfd_error_handler) | |
d003868e AM |
1988 | (_("%B(%A+0x%lx): reloc against `%s': error %d"), |
1989 | input_bfd, input_section, | |
44f745a6 AS |
1990 | (long) rel->r_offset, name, (int) r); |
1991 | return FALSE; | |
252b5132 RH |
1992 | } |
1993 | } | |
1994 | } | |
1995 | ||
b34976b6 | 1996 | return TRUE; |
252b5132 RH |
1997 | } |
1998 | ||
cc3e26be RS |
1999 | /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET |
2000 | into section SEC. */ | |
2001 | ||
2002 | static void | |
2003 | elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value) | |
2004 | { | |
2005 | /* Make VALUE PC-relative. */ | |
2006 | value -= sec->output_section->vma + offset; | |
2007 | ||
2008 | /* Apply any in-place addend. */ | |
2009 | value += bfd_get_32 (sec->owner, sec->contents + offset); | |
2010 | ||
2011 | bfd_put_32 (sec->owner, value, sec->contents + offset); | |
2012 | } | |
2013 | ||
252b5132 RH |
2014 | /* Finish up dynamic symbol handling. We set the contents of various |
2015 | dynamic sections here. */ | |
2016 | ||
b34976b6 | 2017 | static bfd_boolean |
252b5132 RH |
2018 | elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) |
2019 | bfd *output_bfd; | |
2020 | struct bfd_link_info *info; | |
2021 | struct elf_link_hash_entry *h; | |
2022 | Elf_Internal_Sym *sym; | |
2023 | { | |
2024 | bfd *dynobj; | |
2025 | ||
2026 | dynobj = elf_hash_table (info)->dynobj; | |
2027 | ||
2028 | if (h->plt.offset != (bfd_vma) -1) | |
2029 | { | |
cc3e26be | 2030 | const struct elf_m68k_plt_info *plt_info; |
252b5132 RH |
2031 | asection *splt; |
2032 | asection *sgot; | |
2033 | asection *srela; | |
2034 | bfd_vma plt_index; | |
2035 | bfd_vma got_offset; | |
2036 | Elf_Internal_Rela rela; | |
947216bf | 2037 | bfd_byte *loc; |
252b5132 RH |
2038 | |
2039 | /* This symbol has an entry in the procedure linkage table. Set | |
2040 | it up. */ | |
2041 | ||
2042 | BFD_ASSERT (h->dynindx != -1); | |
2043 | ||
cc3e26be | 2044 | plt_info = elf_m68k_hash_table (info)->plt_info; |
252b5132 RH |
2045 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
2046 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
2047 | srela = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
2048 | BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); | |
2049 | ||
2050 | /* Get the index in the procedure linkage table which | |
2051 | corresponds to this symbol. This is the index of this symbol | |
2052 | in all the symbols for which we are making plt entries. The | |
2053 | first entry in the procedure linkage table is reserved. */ | |
cc3e26be | 2054 | plt_index = (h->plt.offset / plt_info->size) - 1; |
252b5132 RH |
2055 | |
2056 | /* Get the offset into the .got table of the entry that | |
2057 | corresponds to this function. Each .got entry is 4 bytes. | |
2058 | The first three are reserved. */ | |
2059 | got_offset = (plt_index + 3) * 4; | |
2060 | ||
cc3e26be RS |
2061 | memcpy (splt->contents + h->plt.offset, |
2062 | plt_info->symbol_entry, | |
2063 | plt_info->size); | |
2064 | ||
2065 | elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got, | |
2066 | (sgot->output_section->vma | |
2067 | + sgot->output_offset | |
2068 | + got_offset)); | |
252b5132 RH |
2069 | |
2070 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), | |
cc3e26be RS |
2071 | splt->contents |
2072 | + h->plt.offset | |
2073 | + plt_info->symbol_resolve_entry + 2); | |
2074 | ||
2075 | elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt, | |
2076 | splt->output_section->vma); | |
252b5132 RH |
2077 | |
2078 | /* Fill in the entry in the global offset table. */ | |
2079 | bfd_put_32 (output_bfd, | |
2080 | (splt->output_section->vma | |
2081 | + splt->output_offset | |
2082 | + h->plt.offset | |
cc3e26be | 2083 | + plt_info->symbol_resolve_entry), |
252b5132 RH |
2084 | sgot->contents + got_offset); |
2085 | ||
2086 | /* Fill in the entry in the .rela.plt section. */ | |
2087 | rela.r_offset = (sgot->output_section->vma | |
2088 | + sgot->output_offset | |
2089 | + got_offset); | |
2090 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT); | |
2091 | rela.r_addend = 0; | |
947216bf AM |
2092 | loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); |
2093 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 | 2094 | |
f5385ebf | 2095 | if (!h->def_regular) |
252b5132 RH |
2096 | { |
2097 | /* Mark the symbol as undefined, rather than as defined in | |
2098 | the .plt section. Leave the value alone. */ | |
2099 | sym->st_shndx = SHN_UNDEF; | |
2100 | } | |
2101 | } | |
2102 | ||
2103 | if (h->got.offset != (bfd_vma) -1) | |
2104 | { | |
2105 | asection *sgot; | |
2106 | asection *srela; | |
2107 | Elf_Internal_Rela rela; | |
947216bf | 2108 | bfd_byte *loc; |
252b5132 RH |
2109 | |
2110 | /* This symbol has an entry in the global offset table. Set it | |
2111 | up. */ | |
2112 | ||
2113 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2114 | srela = bfd_get_section_by_name (dynobj, ".rela.got"); | |
2115 | BFD_ASSERT (sgot != NULL && srela != NULL); | |
2116 | ||
2117 | rela.r_offset = (sgot->output_section->vma | |
2118 | + sgot->output_offset | |
dc810e39 | 2119 | + (h->got.offset &~ (bfd_vma) 1)); |
252b5132 RH |
2120 | |
2121 | /* If this is a -Bsymbolic link, and the symbol is defined | |
2122 | locally, we just want to emit a RELATIVE reloc. Likewise if | |
2123 | the symbol was forced to be local because of a version file. | |
2124 | The entry in the global offset table will already have been | |
2125 | initialized in the relocate_section function. */ | |
2126 | if (info->shared | |
a5ad465a AS |
2127 | && (info->symbolic |
2128 | || h->dynindx == -1 | |
f5385ebf AM |
2129 | || h->forced_local) |
2130 | && h->def_regular) | |
252b5132 RH |
2131 | { |
2132 | rela.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); | |
2133 | rela.r_addend = bfd_get_signed_32 (output_bfd, | |
2134 | (sgot->contents | |
dc810e39 | 2135 | + (h->got.offset &~ (bfd_vma) 1))); |
252b5132 RH |
2136 | } |
2137 | else | |
2138 | { | |
2139 | bfd_put_32 (output_bfd, (bfd_vma) 0, | |
dc810e39 | 2140 | sgot->contents + (h->got.offset &~ (bfd_vma) 1)); |
252b5132 RH |
2141 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT); |
2142 | rela.r_addend = 0; | |
2143 | } | |
2144 | ||
947216bf AM |
2145 | loc = srela->contents; |
2146 | loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); | |
2147 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 RH |
2148 | } |
2149 | ||
f5385ebf | 2150 | if (h->needs_copy) |
252b5132 RH |
2151 | { |
2152 | asection *s; | |
2153 | Elf_Internal_Rela rela; | |
947216bf | 2154 | bfd_byte *loc; |
252b5132 RH |
2155 | |
2156 | /* This symbol needs a copy reloc. Set it up. */ | |
2157 | ||
2158 | BFD_ASSERT (h->dynindx != -1 | |
2159 | && (h->root.type == bfd_link_hash_defined | |
2160 | || h->root.type == bfd_link_hash_defweak)); | |
2161 | ||
2162 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
2163 | ".rela.bss"); | |
2164 | BFD_ASSERT (s != NULL); | |
2165 | ||
2166 | rela.r_offset = (h->root.u.def.value | |
2167 | + h->root.u.def.section->output_section->vma | |
2168 | + h->root.u.def.section->output_offset); | |
2169 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY); | |
2170 | rela.r_addend = 0; | |
947216bf AM |
2171 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
2172 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 RH |
2173 | } |
2174 | ||
2175 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |
2176 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
22edb2f1 | 2177 | || h == elf_hash_table (info)->hgot) |
252b5132 RH |
2178 | sym->st_shndx = SHN_ABS; |
2179 | ||
b34976b6 | 2180 | return TRUE; |
252b5132 RH |
2181 | } |
2182 | ||
2183 | /* Finish up the dynamic sections. */ | |
2184 | ||
b34976b6 | 2185 | static bfd_boolean |
252b5132 RH |
2186 | elf_m68k_finish_dynamic_sections (output_bfd, info) |
2187 | bfd *output_bfd; | |
2188 | struct bfd_link_info *info; | |
2189 | { | |
2190 | bfd *dynobj; | |
2191 | asection *sgot; | |
2192 | asection *sdyn; | |
2193 | ||
2194 | dynobj = elf_hash_table (info)->dynobj; | |
2195 | ||
2196 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
2197 | BFD_ASSERT (sgot != NULL); | |
2198 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
2199 | ||
2200 | if (elf_hash_table (info)->dynamic_sections_created) | |
2201 | { | |
2202 | asection *splt; | |
2203 | Elf32_External_Dyn *dyncon, *dynconend; | |
2204 | ||
2205 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
2206 | BFD_ASSERT (splt != NULL && sdyn != NULL); | |
2207 | ||
2208 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 2209 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
252b5132 RH |
2210 | for (; dyncon < dynconend; dyncon++) |
2211 | { | |
2212 | Elf_Internal_Dyn dyn; | |
2213 | const char *name; | |
2214 | asection *s; | |
2215 | ||
2216 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
2217 | ||
2218 | switch (dyn.d_tag) | |
2219 | { | |
2220 | default: | |
2221 | break; | |
2222 | ||
2223 | case DT_PLTGOT: | |
2224 | name = ".got"; | |
2225 | goto get_vma; | |
2226 | case DT_JMPREL: | |
2227 | name = ".rela.plt"; | |
2228 | get_vma: | |
2229 | s = bfd_get_section_by_name (output_bfd, name); | |
2230 | BFD_ASSERT (s != NULL); | |
2231 | dyn.d_un.d_ptr = s->vma; | |
2232 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
2233 | break; | |
2234 | ||
2235 | case DT_PLTRELSZ: | |
2236 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); | |
2237 | BFD_ASSERT (s != NULL); | |
eea6121a | 2238 | dyn.d_un.d_val = s->size; |
252b5132 RH |
2239 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
2240 | break; | |
2241 | ||
2242 | case DT_RELASZ: | |
2243 | /* The procedure linkage table relocs (DT_JMPREL) should | |
2244 | not be included in the overall relocs (DT_RELA). | |
2245 | Therefore, we override the DT_RELASZ entry here to | |
2246 | make it not include the JMPREL relocs. Since the | |
2247 | linker script arranges for .rela.plt to follow all | |
2248 | other relocation sections, we don't have to worry | |
2249 | about changing the DT_RELA entry. */ | |
2250 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); | |
2251 | if (s != NULL) | |
eea6121a | 2252 | dyn.d_un.d_val -= s->size; |
252b5132 RH |
2253 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
2254 | break; | |
2255 | } | |
2256 | } | |
2257 | ||
2258 | /* Fill in the first entry in the procedure linkage table. */ | |
eea6121a | 2259 | if (splt->size > 0) |
252b5132 | 2260 | { |
cc3e26be RS |
2261 | const struct elf_m68k_plt_info *plt_info; |
2262 | ||
2263 | plt_info = elf_m68k_hash_table (info)->plt_info; | |
2264 | memcpy (splt->contents, plt_info->plt0_entry, plt_info->size); | |
2265 | ||
2266 | elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4, | |
2267 | (sgot->output_section->vma | |
2268 | + sgot->output_offset | |
2269 | + 4)); | |
2270 | ||
2271 | elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8, | |
2272 | (sgot->output_section->vma | |
2273 | + sgot->output_offset | |
2274 | + 8)); | |
2275 | ||
2276 | elf_section_data (splt->output_section)->this_hdr.sh_entsize | |
2277 | = plt_info->size; | |
252b5132 | 2278 | } |
252b5132 RH |
2279 | } |
2280 | ||
2281 | /* Fill in the first three entries in the global offset table. */ | |
eea6121a | 2282 | if (sgot->size > 0) |
252b5132 RH |
2283 | { |
2284 | if (sdyn == NULL) | |
2285 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
2286 | else | |
2287 | bfd_put_32 (output_bfd, | |
2288 | sdyn->output_section->vma + sdyn->output_offset, | |
2289 | sgot->contents); | |
2290 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
2291 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
2292 | } | |
2293 | ||
2294 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; | |
2295 | ||
b34976b6 | 2296 | return TRUE; |
252b5132 RH |
2297 | } |
2298 | ||
0752970e NC |
2299 | /* Given a .data section and a .emreloc in-memory section, store |
2300 | relocation information into the .emreloc section which can be | |
2301 | used at runtime to relocate the section. This is called by the | |
2302 | linker when the --embedded-relocs switch is used. This is called | |
2303 | after the add_symbols entry point has been called for all the | |
2304 | objects, and before the final_link entry point is called. */ | |
2305 | ||
b34976b6 | 2306 | bfd_boolean |
0752970e NC |
2307 | bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) |
2308 | bfd *abfd; | |
2309 | struct bfd_link_info *info; | |
2310 | asection *datasec; | |
2311 | asection *relsec; | |
2312 | char **errmsg; | |
2313 | { | |
2314 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc AM |
2315 | Elf_Internal_Sym *isymbuf = NULL; |
2316 | Elf_Internal_Rela *internal_relocs = NULL; | |
0752970e NC |
2317 | Elf_Internal_Rela *irel, *irelend; |
2318 | bfd_byte *p; | |
dc810e39 | 2319 | bfd_size_type amt; |
0752970e | 2320 | |
1049f94e | 2321 | BFD_ASSERT (! info->relocatable); |
0752970e NC |
2322 | |
2323 | *errmsg = NULL; | |
2324 | ||
2325 | if (datasec->reloc_count == 0) | |
b34976b6 | 2326 | return TRUE; |
0752970e NC |
2327 | |
2328 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
9ad5cbcf | 2329 | |
0752970e | 2330 | /* Get a copy of the native relocations. */ |
45d6a902 | 2331 | internal_relocs = (_bfd_elf_link_read_relocs |
0752970e NC |
2332 | (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
2333 | info->keep_memory)); | |
2334 | if (internal_relocs == NULL) | |
2335 | goto error_return; | |
0752970e | 2336 | |
dc810e39 AM |
2337 | amt = (bfd_size_type) datasec->reloc_count * 12; |
2338 | relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt); | |
0752970e NC |
2339 | if (relsec->contents == NULL) |
2340 | goto error_return; | |
2341 | ||
2342 | p = relsec->contents; | |
2343 | ||
2344 | irelend = internal_relocs + datasec->reloc_count; | |
2345 | for (irel = internal_relocs; irel < irelend; irel++, p += 12) | |
2346 | { | |
2347 | asection *targetsec; | |
2348 | ||
2349 | /* We are going to write a four byte longword into the runtime | |
2350 | reloc section. The longword will be the address in the data | |
2351 | section which must be relocated. It is followed by the name | |
2352 | of the target section NUL-padded or truncated to 8 | |
2353 | characters. */ | |
2354 | ||
2355 | /* We can only relocate absolute longword relocs at run time. */ | |
2356 | if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32) | |
2357 | { | |
2358 | *errmsg = _("unsupported reloc type"); | |
2359 | bfd_set_error (bfd_error_bad_value); | |
2360 | goto error_return; | |
2361 | } | |
2362 | ||
2363 | /* Get the target section referred to by the reloc. */ | |
2364 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) | |
2365 | { | |
0752970e | 2366 | /* A local symbol. */ |
6cdc0ccc AM |
2367 | Elf_Internal_Sym *isym; |
2368 | ||
2369 | /* Read this BFD's local symbols if we haven't done so already. */ | |
2370 | if (isymbuf == NULL) | |
2371 | { | |
2372 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
2373 | if (isymbuf == NULL) | |
2374 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
2375 | symtab_hdr->sh_info, 0, | |
2376 | NULL, NULL, NULL); | |
2377 | if (isymbuf == NULL) | |
2378 | goto error_return; | |
2379 | } | |
0752970e | 2380 | |
6cdc0ccc AM |
2381 | isym = isymbuf + ELF32_R_SYM (irel->r_info); |
2382 | targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
0752970e NC |
2383 | } |
2384 | else | |
2385 | { | |
2386 | unsigned long indx; | |
2387 | struct elf_link_hash_entry *h; | |
2388 | ||
2389 | /* An external symbol. */ | |
2390 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; | |
2391 | h = elf_sym_hashes (abfd)[indx]; | |
2392 | BFD_ASSERT (h != NULL); | |
2393 | if (h->root.type == bfd_link_hash_defined | |
2394 | || h->root.type == bfd_link_hash_defweak) | |
2395 | targetsec = h->root.u.def.section; | |
2396 | else | |
2397 | targetsec = NULL; | |
2398 | } | |
2399 | ||
2400 | bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p); | |
2401 | memset (p + 4, 0, 8); | |
2402 | if (targetsec != NULL) | |
f075ee0c | 2403 | strncpy ((char *) p + 4, targetsec->output_section->name, 8); |
0752970e | 2404 | } |
c3668558 | 2405 | |
6cdc0ccc AM |
2406 | if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) |
2407 | free (isymbuf); | |
2408 | if (internal_relocs != NULL | |
2409 | && elf_section_data (datasec)->relocs != internal_relocs) | |
2410 | free (internal_relocs); | |
b34976b6 | 2411 | return TRUE; |
0752970e NC |
2412 | |
2413 | error_return: | |
6cdc0ccc AM |
2414 | if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) |
2415 | free (isymbuf); | |
2416 | if (internal_relocs != NULL | |
2417 | && elf_section_data (datasec)->relocs != internal_relocs) | |
2418 | free (internal_relocs); | |
b34976b6 | 2419 | return FALSE; |
0752970e NC |
2420 | } |
2421 | ||
aa91b392 | 2422 | static enum elf_reloc_type_class |
f51e552e AM |
2423 | elf32_m68k_reloc_type_class (rela) |
2424 | const Elf_Internal_Rela *rela; | |
aa91b392 | 2425 | { |
f51e552e | 2426 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
aa91b392 AS |
2427 | { |
2428 | case R_68K_RELATIVE: | |
2429 | return reloc_class_relative; | |
2430 | case R_68K_JMP_SLOT: | |
2431 | return reloc_class_plt; | |
2432 | case R_68K_COPY: | |
2433 | return reloc_class_copy; | |
2434 | default: | |
2435 | return reloc_class_normal; | |
2436 | } | |
2437 | } | |
2438 | ||
1715e0e3 AS |
2439 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
2440 | or (bfd_vma) -1 if it should not be included. */ | |
2441 | ||
2442 | static bfd_vma | |
2443 | elf_m68k_plt_sym_val (bfd_vma i, const asection *plt, | |
2444 | const arelent *rel ATTRIBUTE_UNUSED) | |
2445 | { | |
cc3e26be | 2446 | return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size; |
1715e0e3 AS |
2447 | } |
2448 | ||
252b5132 RH |
2449 | #define TARGET_BIG_SYM bfd_elf32_m68k_vec |
2450 | #define TARGET_BIG_NAME "elf32-m68k" | |
2451 | #define ELF_MACHINE_CODE EM_68K | |
2452 | #define ELF_MAXPAGESIZE 0x2000 | |
2453 | #define elf_backend_create_dynamic_sections \ | |
2454 | _bfd_elf_create_dynamic_sections | |
2455 | #define bfd_elf32_bfd_link_hash_table_create \ | |
2456 | elf_m68k_link_hash_table_create | |
c152c796 | 2457 | #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link |
252b5132 RH |
2458 | |
2459 | #define elf_backend_check_relocs elf_m68k_check_relocs | |
cc3e26be RS |
2460 | #define elf_backend_always_size_sections \ |
2461 | elf_m68k_always_size_sections | |
252b5132 RH |
2462 | #define elf_backend_adjust_dynamic_symbol \ |
2463 | elf_m68k_adjust_dynamic_symbol | |
2464 | #define elf_backend_size_dynamic_sections \ | |
2465 | elf_m68k_size_dynamic_sections | |
74541ad4 | 2466 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
252b5132 RH |
2467 | #define elf_backend_relocate_section elf_m68k_relocate_section |
2468 | #define elf_backend_finish_dynamic_symbol \ | |
2469 | elf_m68k_finish_dynamic_symbol | |
2470 | #define elf_backend_finish_dynamic_sections \ | |
2471 | elf_m68k_finish_dynamic_sections | |
2472 | #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook | |
2473 | #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook | |
9e1281c7 CM |
2474 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
2475 | elf32_m68k_merge_private_bfd_data | |
2476 | #define bfd_elf32_bfd_set_private_flags \ | |
2477 | elf32_m68k_set_private_flags | |
2478 | #define bfd_elf32_bfd_print_private_bfd_data \ | |
2479 | elf32_m68k_print_private_bfd_data | |
aa91b392 | 2480 | #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class |
1715e0e3 | 2481 | #define elf_backend_plt_sym_val elf_m68k_plt_sym_val |
266abb8f | 2482 | #define elf_backend_object_p elf32_m68k_object_p |
9e1281c7 | 2483 | |
252b5132 | 2484 | #define elf_backend_can_gc_sections 1 |
51b64d56 | 2485 | #define elf_backend_can_refcount 1 |
252b5132 RH |
2486 | #define elf_backend_want_got_plt 1 |
2487 | #define elf_backend_plt_readonly 1 | |
2488 | #define elf_backend_want_plt_sym 0 | |
2489 | #define elf_backend_got_header_size 12 | |
b491616a | 2490 | #define elf_backend_rela_normal 1 |
252b5132 RH |
2491 | |
2492 | #include "elf32-target.h" |