1 | /* PowerPC-specific support for 32-bit ELF
|
---|
2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
|
---|
3 | Free Software Foundation, Inc.
|
---|
4 | Written by Ian Lance Taylor, Cygnus Support.
|
---|
5 |
|
---|
6 | This file is part of BFD, the Binary File Descriptor library.
|
---|
7 |
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 2 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program; if not, write to the Free Software
|
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
21 |
|
---|
22 | /* This file is based on a preliminary PowerPC ELF ABI. The
|
---|
23 | information may not match the final PowerPC ELF ABI. It includes
|
---|
24 | suggestions from the in-progress Embedded PowerPC ABI, and that
|
---|
25 | information may also not match. */
|
---|
26 |
|
---|
27 | #include "bfd.h"
|
---|
28 | #include "sysdep.h"
|
---|
29 | #include "bfdlink.h"
|
---|
30 | #include "libbfd.h"
|
---|
31 | #include "elf-bfd.h"
|
---|
32 | #include "elf/ppc.h"
|
---|
33 |
|
---|
34 | #define USE_RELA /* we want RELA relocations, not REL */
|
---|
35 |
|
---|
36 | static reloc_howto_type *ppc_elf_reloc_type_lookup
|
---|
37 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
|
---|
38 | static void ppc_elf_info_to_howto
|
---|
39 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
|
---|
40 | static void ppc_elf_howto_init PARAMS ((void));
|
---|
41 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
|
---|
42 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
---|
43 | static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
|
---|
44 | static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
|
---|
45 | static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
|
---|
46 |
|
---|
47 | static int ppc_elf_additional_program_headers PARAMS ((bfd *));
|
---|
48 | static boolean ppc_elf_modify_segment_map PARAMS ((bfd *));
|
---|
49 |
|
---|
50 | static boolean ppc_elf_create_dynamic_sections
|
---|
51 | PARAMS ((bfd *, struct bfd_link_info *));
|
---|
52 |
|
---|
53 | static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
|
---|
54 | Elf32_Internal_Shdr *,
|
---|
55 | char *));
|
---|
56 | static boolean ppc_elf_fake_sections
|
---|
57 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
|
---|
58 |
|
---|
59 | static elf_linker_section_t *ppc_elf_create_linker_section
|
---|
60 | PARAMS ((bfd *abfd,
|
---|
61 | struct bfd_link_info *info,
|
---|
62 | enum elf_linker_section_enum));
|
---|
63 |
|
---|
64 | static boolean ppc_elf_check_relocs PARAMS ((bfd *,
|
---|
65 | struct bfd_link_info *,
|
---|
66 | asection *,
|
---|
67 | const Elf_Internal_Rela *));
|
---|
68 |
|
---|
69 | static asection * ppc_elf_gc_mark_hook PARAMS ((bfd *abfd,
|
---|
70 | struct bfd_link_info *info,
|
---|
71 | Elf_Internal_Rela *rel,
|
---|
72 | struct elf_link_hash_entry *h,
|
---|
73 | Elf_Internal_Sym *sym));
|
---|
74 |
|
---|
75 | static boolean ppc_elf_gc_sweep_hook PARAMS ((bfd *abfd,
|
---|
76 | struct bfd_link_info *info,
|
---|
77 | asection *sec,
|
---|
78 | const Elf_Internal_Rela *relocs));
|
---|
79 |
|
---|
80 | static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
|
---|
81 | struct elf_link_hash_entry *));
|
---|
82 |
|
---|
83 | static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
|
---|
84 |
|
---|
85 | static boolean ppc_elf_relocate_section PARAMS ((bfd *,
|
---|
86 | struct bfd_link_info *info,
|
---|
87 | bfd *,
|
---|
88 | asection *,
|
---|
89 | bfd_byte *,
|
---|
90 | Elf_Internal_Rela *relocs,
|
---|
91 | Elf_Internal_Sym *local_syms,
|
---|
92 | asection **));
|
---|
93 |
|
---|
94 | static boolean ppc_elf_add_symbol_hook PARAMS ((bfd *,
|
---|
95 | struct bfd_link_info *,
|
---|
96 | const Elf_Internal_Sym *,
|
---|
97 | const char **,
|
---|
98 | flagword *,
|
---|
99 | asection **,
|
---|
100 | bfd_vma *));
|
---|
101 |
|
---|
102 | static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
|
---|
103 | struct bfd_link_info *,
|
---|
104 | struct elf_link_hash_entry *,
|
---|
105 | Elf_Internal_Sym *));
|
---|
106 |
|
---|
107 | static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
|
---|
108 |
|
---|
109 | #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
|
---|
110 | #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
|
---|
111 | #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
|
---|
112 |
|
---|
113 | /* The name of the dynamic interpreter. This is put in the .interp
|
---|
114 | section. */
|
---|
115 |
|
---|
116 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
|
---|
117 |
|
---|
118 | /* The size in bytes of an entry in the procedure linkage table. */
|
---|
119 | #define PLT_ENTRY_SIZE 12
|
---|
120 | /* The initial size of the plt reserved for the dynamic linker. */
|
---|
121 | #define PLT_INITIAL_ENTRY_SIZE 72
|
---|
122 | /* The size of the gap between entries in the PLT. */
|
---|
123 | #define PLT_SLOT_SIZE 8
|
---|
124 | /* The number of single-slot PLT entries (the rest use two slots). */
|
---|
125 | #define PLT_NUM_SINGLE_ENTRIES 8192
|
---|
126 |
|
---|
127 | /* Will references to this symbol always reference the symbol
|
---|
128 | in this object? */
|
---|
129 | #define SYMBOL_REFERENCES_LOCAL(INFO, H) \
|
---|
130 | ((! INFO->shared \
|
---|
131 | || INFO->symbolic \
|
---|
132 | || H->dynindx == -1 \
|
---|
133 | || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \
|
---|
134 | || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \
|
---|
135 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
|
---|
136 |
|
---|
137 | /* Will _calls_ to this symbol always call the version in this object? */
|
---|
138 | #define SYMBOL_CALLS_LOCAL(INFO, H) \
|
---|
139 | ((! INFO->shared \
|
---|
140 | || INFO->symbolic \
|
---|
141 | || H->dynindx == -1 \
|
---|
142 | || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \
|
---|
143 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
|
---|
144 | |
---|
145 |
|
---|
146 | static reloc_howto_type *ppc_elf_howto_table[(int) R_PPC_max];
|
---|
147 |
|
---|
148 | static reloc_howto_type ppc_elf_howto_raw[] = {
|
---|
149 | /* This reloc does nothing. */
|
---|
150 | HOWTO (R_PPC_NONE, /* type */
|
---|
151 | 0, /* rightshift */
|
---|
152 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
153 | 32, /* bitsize */
|
---|
154 | false, /* pc_relative */
|
---|
155 | 0, /* bitpos */
|
---|
156 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
157 | bfd_elf_generic_reloc, /* special_function */
|
---|
158 | "R_PPC_NONE", /* name */
|
---|
159 | false, /* partial_inplace */
|
---|
160 | 0, /* src_mask */
|
---|
161 | 0, /* dst_mask */
|
---|
162 | false), /* pcrel_offset */
|
---|
163 |
|
---|
164 | /* A standard 32 bit relocation. */
|
---|
165 | HOWTO (R_PPC_ADDR32, /* type */
|
---|
166 | 0, /* rightshift */
|
---|
167 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
168 | 32, /* bitsize */
|
---|
169 | false, /* pc_relative */
|
---|
170 | 0, /* bitpos */
|
---|
171 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
172 | bfd_elf_generic_reloc, /* special_function */
|
---|
173 | "R_PPC_ADDR32", /* name */
|
---|
174 | false, /* partial_inplace */
|
---|
175 | 0, /* src_mask */
|
---|
176 | 0xffffffff, /* dst_mask */
|
---|
177 | false), /* pcrel_offset */
|
---|
178 |
|
---|
179 | /* An absolute 26 bit branch; the lower two bits must be zero.
|
---|
180 | FIXME: we don't check that, we just clear them. */
|
---|
181 | HOWTO (R_PPC_ADDR24, /* type */
|
---|
182 | 0, /* rightshift */
|
---|
183 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
184 | 26, /* bitsize */
|
---|
185 | false, /* pc_relative */
|
---|
186 | 0, /* bitpos */
|
---|
187 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
188 | bfd_elf_generic_reloc, /* special_function */
|
---|
189 | "R_PPC_ADDR24", /* name */
|
---|
190 | false, /* partial_inplace */
|
---|
191 | 0, /* src_mask */
|
---|
192 | 0x3fffffc, /* dst_mask */
|
---|
193 | false), /* pcrel_offset */
|
---|
194 |
|
---|
195 | /* A standard 16 bit relocation. */
|
---|
196 | HOWTO (R_PPC_ADDR16, /* type */
|
---|
197 | 0, /* rightshift */
|
---|
198 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
199 | 16, /* bitsize */
|
---|
200 | false, /* pc_relative */
|
---|
201 | 0, /* bitpos */
|
---|
202 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
203 | bfd_elf_generic_reloc, /* special_function */
|
---|
204 | "R_PPC_ADDR16", /* name */
|
---|
205 | false, /* partial_inplace */
|
---|
206 | 0, /* src_mask */
|
---|
207 | 0xffff, /* dst_mask */
|
---|
208 | false), /* pcrel_offset */
|
---|
209 |
|
---|
210 | /* A 16 bit relocation without overflow. */
|
---|
211 | HOWTO (R_PPC_ADDR16_LO, /* type */
|
---|
212 | 0, /* rightshift */
|
---|
213 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
214 | 16, /* bitsize */
|
---|
215 | false, /* pc_relative */
|
---|
216 | 0, /* bitpos */
|
---|
217 | complain_overflow_dont,/* complain_on_overflow */
|
---|
218 | bfd_elf_generic_reloc, /* special_function */
|
---|
219 | "R_PPC_ADDR16_LO", /* name */
|
---|
220 | false, /* partial_inplace */
|
---|
221 | 0, /* src_mask */
|
---|
222 | 0xffff, /* dst_mask */
|
---|
223 | false), /* pcrel_offset */
|
---|
224 |
|
---|
225 | /* The high order 16 bits of an address. */
|
---|
226 | HOWTO (R_PPC_ADDR16_HI, /* type */
|
---|
227 | 16, /* rightshift */
|
---|
228 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
229 | 16, /* bitsize */
|
---|
230 | false, /* pc_relative */
|
---|
231 | 0, /* bitpos */
|
---|
232 | complain_overflow_dont, /* complain_on_overflow */
|
---|
233 | bfd_elf_generic_reloc, /* special_function */
|
---|
234 | "R_PPC_ADDR16_HI", /* name */
|
---|
235 | false, /* partial_inplace */
|
---|
236 | 0, /* src_mask */
|
---|
237 | 0xffff, /* dst_mask */
|
---|
238 | false), /* pcrel_offset */
|
---|
239 |
|
---|
240 | /* The high order 16 bits of an address, plus 1 if the contents of
|
---|
241 | the low 16 bits, treated as a signed number, is negative. */
|
---|
242 | HOWTO (R_PPC_ADDR16_HA, /* type */
|
---|
243 | 16, /* rightshift */
|
---|
244 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
245 | 16, /* bitsize */
|
---|
246 | false, /* pc_relative */
|
---|
247 | 0, /* bitpos */
|
---|
248 | complain_overflow_dont, /* complain_on_overflow */
|
---|
249 | ppc_elf_addr16_ha_reloc, /* special_function */
|
---|
250 | "R_PPC_ADDR16_HA", /* name */
|
---|
251 | false, /* partial_inplace */
|
---|
252 | 0, /* src_mask */
|
---|
253 | 0xffff, /* dst_mask */
|
---|
254 | false), /* pcrel_offset */
|
---|
255 |
|
---|
256 | /* An absolute 16 bit branch; the lower two bits must be zero.
|
---|
257 | FIXME: we don't check that, we just clear them. */
|
---|
258 | HOWTO (R_PPC_ADDR14, /* type */
|
---|
259 | 0, /* rightshift */
|
---|
260 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
261 | 16, /* bitsize */
|
---|
262 | false, /* pc_relative */
|
---|
263 | 0, /* bitpos */
|
---|
264 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
265 | bfd_elf_generic_reloc, /* special_function */
|
---|
266 | "R_PPC_ADDR14", /* name */
|
---|
267 | false, /* partial_inplace */
|
---|
268 | 0, /* src_mask */
|
---|
269 | 0xfffc, /* dst_mask */
|
---|
270 | false), /* pcrel_offset */
|
---|
271 |
|
---|
272 | /* An absolute 16 bit branch, for which bit 10 should be set to
|
---|
273 | indicate that the branch is expected to be taken. The lower two
|
---|
274 | bits must be zero. */
|
---|
275 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
|
---|
276 | 0, /* rightshift */
|
---|
277 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
278 | 16, /* bitsize */
|
---|
279 | false, /* pc_relative */
|
---|
280 | 0, /* bitpos */
|
---|
281 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
282 | bfd_elf_generic_reloc, /* special_function */
|
---|
283 | "R_PPC_ADDR14_BRTAKEN",/* name */
|
---|
284 | false, /* partial_inplace */
|
---|
285 | 0, /* src_mask */
|
---|
286 | 0xfffc, /* dst_mask */
|
---|
287 | false), /* pcrel_offset */
|
---|
288 |
|
---|
289 | /* An absolute 16 bit branch, for which bit 10 should be set to
|
---|
290 | indicate that the branch is not expected to be taken. The lower
|
---|
291 | two bits must be zero. */
|
---|
292 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
|
---|
293 | 0, /* rightshift */
|
---|
294 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
295 | 16, /* bitsize */
|
---|
296 | false, /* pc_relative */
|
---|
297 | 0, /* bitpos */
|
---|
298 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
299 | bfd_elf_generic_reloc, /* special_function */
|
---|
300 | "R_PPC_ADDR14_BRNTAKEN",/* name */
|
---|
301 | false, /* partial_inplace */
|
---|
302 | 0, /* src_mask */
|
---|
303 | 0xfffc, /* dst_mask */
|
---|
304 | false), /* pcrel_offset */
|
---|
305 |
|
---|
306 | /* A relative 26 bit branch; the lower two bits must be zero. */
|
---|
307 | HOWTO (R_PPC_REL24, /* type */
|
---|
308 | 0, /* rightshift */
|
---|
309 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
310 | 26, /* bitsize */
|
---|
311 | true, /* pc_relative */
|
---|
312 | 0, /* bitpos */
|
---|
313 | complain_overflow_signed, /* complain_on_overflow */
|
---|
314 | bfd_elf_generic_reloc, /* special_function */
|
---|
315 | "R_PPC_REL24", /* name */
|
---|
316 | false, /* partial_inplace */
|
---|
317 | 0, /* src_mask */
|
---|
318 | 0x3fffffc, /* dst_mask */
|
---|
319 | true), /* pcrel_offset */
|
---|
320 |
|
---|
321 | /* A relative 16 bit branch; the lower two bits must be zero. */
|
---|
322 | HOWTO (R_PPC_REL14, /* type */
|
---|
323 | 0, /* rightshift */
|
---|
324 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
325 | 16, /* bitsize */
|
---|
326 | true, /* pc_relative */
|
---|
327 | 0, /* bitpos */
|
---|
328 | complain_overflow_signed, /* complain_on_overflow */
|
---|
329 | bfd_elf_generic_reloc, /* special_function */
|
---|
330 | "R_PPC_REL14", /* name */
|
---|
331 | false, /* partial_inplace */
|
---|
332 | 0, /* src_mask */
|
---|
333 | 0xfffc, /* dst_mask */
|
---|
334 | true), /* pcrel_offset */
|
---|
335 |
|
---|
336 | /* A relative 16 bit branch. Bit 10 should be set to indicate that
|
---|
337 | the branch is expected to be taken. The lower two bits must be
|
---|
338 | zero. */
|
---|
339 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */
|
---|
340 | 0, /* rightshift */
|
---|
341 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
342 | 16, /* bitsize */
|
---|
343 | true, /* pc_relative */
|
---|
344 | 0, /* bitpos */
|
---|
345 | complain_overflow_signed, /* complain_on_overflow */
|
---|
346 | bfd_elf_generic_reloc, /* special_function */
|
---|
347 | "R_PPC_REL14_BRTAKEN", /* name */
|
---|
348 | false, /* partial_inplace */
|
---|
349 | 0, /* src_mask */
|
---|
350 | 0xfffc, /* dst_mask */
|
---|
351 | true), /* pcrel_offset */
|
---|
352 |
|
---|
353 | /* A relative 16 bit branch. Bit 10 should be set to indicate that
|
---|
354 | the branch is not expected to be taken. The lower two bits must
|
---|
355 | be zero. */
|
---|
356 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
|
---|
357 | 0, /* rightshift */
|
---|
358 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
359 | 16, /* bitsize */
|
---|
360 | true, /* pc_relative */
|
---|
361 | 0, /* bitpos */
|
---|
362 | complain_overflow_signed, /* complain_on_overflow */
|
---|
363 | bfd_elf_generic_reloc, /* special_function */
|
---|
364 | "R_PPC_REL14_BRNTAKEN",/* name */
|
---|
365 | false, /* partial_inplace */
|
---|
366 | 0, /* src_mask */
|
---|
367 | 0xfffc, /* dst_mask */
|
---|
368 | true), /* pcrel_offset */
|
---|
369 |
|
---|
370 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
|
---|
371 | symbol. */
|
---|
372 | HOWTO (R_PPC_GOT16, /* type */
|
---|
373 | 0, /* rightshift */
|
---|
374 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
375 | 16, /* bitsize */
|
---|
376 | false, /* pc_relative */
|
---|
377 | 0, /* bitpos */
|
---|
378 | complain_overflow_signed, /* complain_on_overflow */
|
---|
379 | bfd_elf_generic_reloc, /* special_function */
|
---|
380 | "R_PPC_GOT16", /* name */
|
---|
381 | false, /* partial_inplace */
|
---|
382 | 0, /* src_mask */
|
---|
383 | 0xffff, /* dst_mask */
|
---|
384 | false), /* pcrel_offset */
|
---|
385 |
|
---|
386 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
|
---|
387 | the symbol. */
|
---|
388 | HOWTO (R_PPC_GOT16_LO, /* type */
|
---|
389 | 0, /* rightshift */
|
---|
390 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
391 | 16, /* bitsize */
|
---|
392 | false, /* pc_relative */
|
---|
393 | 0, /* bitpos */
|
---|
394 | complain_overflow_dont, /* complain_on_overflow */
|
---|
395 | bfd_elf_generic_reloc, /* special_function */
|
---|
396 | "R_PPC_GOT16_LO", /* name */
|
---|
397 | false, /* partial_inplace */
|
---|
398 | 0, /* src_mask */
|
---|
399 | 0xffff, /* dst_mask */
|
---|
400 | false), /* pcrel_offset */
|
---|
401 |
|
---|
402 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
|
---|
403 | the symbol. */
|
---|
404 | HOWTO (R_PPC_GOT16_HI, /* type */
|
---|
405 | 16, /* rightshift */
|
---|
406 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
407 | 16, /* bitsize */
|
---|
408 | false, /* pc_relative */
|
---|
409 | 0, /* bitpos */
|
---|
410 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
411 | bfd_elf_generic_reloc, /* special_function */
|
---|
412 | "R_PPC_GOT16_HI", /* name */
|
---|
413 | false, /* partial_inplace */
|
---|
414 | 0, /* src_mask */
|
---|
415 | 0xffff, /* dst_mask */
|
---|
416 | false), /* pcrel_offset */
|
---|
417 |
|
---|
418 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
|
---|
419 | the symbol. */
|
---|
420 | HOWTO (R_PPC_GOT16_HA, /* type */
|
---|
421 | 16, /* rightshift */
|
---|
422 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
423 | 16, /* bitsize */
|
---|
424 | false, /* pc_relative */
|
---|
425 | 0, /* bitpos */
|
---|
426 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
427 | ppc_elf_addr16_ha_reloc, /* special_function */
|
---|
428 | "R_PPC_GOT16_HA", /* name */
|
---|
429 | false, /* partial_inplace */
|
---|
430 | 0, /* src_mask */
|
---|
431 | 0xffff, /* dst_mask */
|
---|
432 | false), /* pcrel_offset */
|
---|
433 |
|
---|
434 | /* Like R_PPC_REL24, but referring to the procedure linkage table
|
---|
435 | entry for the symbol. */
|
---|
436 | HOWTO (R_PPC_PLTREL24, /* type */
|
---|
437 | 0, /* rightshift */
|
---|
438 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
439 | 26, /* bitsize */
|
---|
440 | true, /* pc_relative */
|
---|
441 | 0, /* bitpos */
|
---|
442 | complain_overflow_signed, /* complain_on_overflow */
|
---|
443 | bfd_elf_generic_reloc, /* special_function */
|
---|
444 | "R_PPC_PLTREL24", /* name */
|
---|
445 | false, /* partial_inplace */
|
---|
446 | 0, /* src_mask */
|
---|
447 | 0x3fffffc, /* dst_mask */
|
---|
448 | true), /* pcrel_offset */
|
---|
449 |
|
---|
450 | /* This is used only by the dynamic linker. The symbol should exist
|
---|
451 | both in the object being run and in some shared library. The
|
---|
452 | dynamic linker copies the data addressed by the symbol from the
|
---|
453 | shared library into the object, because the object being
|
---|
454 | run has to have the data at some particular address. */
|
---|
455 | HOWTO (R_PPC_COPY, /* type */
|
---|
456 | 0, /* rightshift */
|
---|
457 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
458 | 32, /* bitsize */
|
---|
459 | false, /* pc_relative */
|
---|
460 | 0, /* bitpos */
|
---|
461 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
462 | bfd_elf_generic_reloc, /* special_function */
|
---|
463 | "R_PPC_COPY", /* name */
|
---|
464 | false, /* partial_inplace */
|
---|
465 | 0, /* src_mask */
|
---|
466 | 0, /* dst_mask */
|
---|
467 | false), /* pcrel_offset */
|
---|
468 |
|
---|
469 | /* Like R_PPC_ADDR32, but used when setting global offset table
|
---|
470 | entries. */
|
---|
471 | HOWTO (R_PPC_GLOB_DAT, /* type */
|
---|
472 | 0, /* rightshift */
|
---|
473 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
474 | 32, /* bitsize */
|
---|
475 | false, /* pc_relative */
|
---|
476 | 0, /* bitpos */
|
---|
477 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
478 | bfd_elf_generic_reloc, /* special_function */
|
---|
479 | "R_PPC_GLOB_DAT", /* name */
|
---|
480 | false, /* partial_inplace */
|
---|
481 | 0, /* src_mask */
|
---|
482 | 0xffffffff, /* dst_mask */
|
---|
483 | false), /* pcrel_offset */
|
---|
484 |
|
---|
485 | /* Marks a procedure linkage table entry for a symbol. */
|
---|
486 | HOWTO (R_PPC_JMP_SLOT, /* type */
|
---|
487 | 0, /* rightshift */
|
---|
488 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
489 | 32, /* bitsize */
|
---|
490 | false, /* pc_relative */
|
---|
491 | 0, /* bitpos */
|
---|
492 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
493 | bfd_elf_generic_reloc, /* special_function */
|
---|
494 | "R_PPC_JMP_SLOT", /* name */
|
---|
495 | false, /* partial_inplace */
|
---|
496 | 0, /* src_mask */
|
---|
497 | 0, /* dst_mask */
|
---|
498 | false), /* pcrel_offset */
|
---|
499 |
|
---|
500 | /* Used only by the dynamic linker. When the object is run, this
|
---|
501 | longword is set to the load address of the object, plus the
|
---|
502 | addend. */
|
---|
503 | HOWTO (R_PPC_RELATIVE, /* type */
|
---|
504 | 0, /* rightshift */
|
---|
505 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
506 | 32, /* bitsize */
|
---|
507 | false, /* pc_relative */
|
---|
508 | 0, /* bitpos */
|
---|
509 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
510 | bfd_elf_generic_reloc, /* special_function */
|
---|
511 | "R_PPC_RELATIVE", /* name */
|
---|
512 | false, /* partial_inplace */
|
---|
513 | 0, /* src_mask */
|
---|
514 | 0xffffffff, /* dst_mask */
|
---|
515 | false), /* pcrel_offset */
|
---|
516 |
|
---|
517 | /* Like R_PPC_REL24, but uses the value of the symbol within the
|
---|
518 | object rather than the final value. Normally used for
|
---|
519 | _GLOBAL_OFFSET_TABLE_. */
|
---|
520 | HOWTO (R_PPC_LOCAL24PC, /* type */
|
---|
521 | 0, /* rightshift */
|
---|
522 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
523 | 26, /* bitsize */
|
---|
524 | true, /* pc_relative */
|
---|
525 | 0, /* bitpos */
|
---|
526 | complain_overflow_signed, /* complain_on_overflow */
|
---|
527 | bfd_elf_generic_reloc, /* special_function */
|
---|
528 | "R_PPC_LOCAL24PC", /* name */
|
---|
529 | false, /* partial_inplace */
|
---|
530 | 0, /* src_mask */
|
---|
531 | 0x3fffffc, /* dst_mask */
|
---|
532 | true), /* pcrel_offset */
|
---|
533 |
|
---|
534 | /* Like R_PPC_ADDR32, but may be unaligned. */
|
---|
535 | HOWTO (R_PPC_UADDR32, /* type */
|
---|
536 | 0, /* rightshift */
|
---|
537 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
538 | 32, /* bitsize */
|
---|
539 | false, /* pc_relative */
|
---|
540 | 0, /* bitpos */
|
---|
541 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
542 | bfd_elf_generic_reloc, /* special_function */
|
---|
543 | "R_PPC_UADDR32", /* name */
|
---|
544 | false, /* partial_inplace */
|
---|
545 | 0, /* src_mask */
|
---|
546 | 0xffffffff, /* dst_mask */
|
---|
547 | false), /* pcrel_offset */
|
---|
548 |
|
---|
549 | /* Like R_PPC_ADDR16, but may be unaligned. */
|
---|
550 | HOWTO (R_PPC_UADDR16, /* type */
|
---|
551 | 0, /* rightshift */
|
---|
552 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
553 | 16, /* bitsize */
|
---|
554 | false, /* pc_relative */
|
---|
555 | 0, /* bitpos */
|
---|
556 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
557 | bfd_elf_generic_reloc, /* special_function */
|
---|
558 | "R_PPC_UADDR16", /* name */
|
---|
559 | false, /* partial_inplace */
|
---|
560 | 0, /* src_mask */
|
---|
561 | 0xffff, /* dst_mask */
|
---|
562 | false), /* pcrel_offset */
|
---|
563 |
|
---|
564 | /* 32-bit PC relative */
|
---|
565 | HOWTO (R_PPC_REL32, /* type */
|
---|
566 | 0, /* rightshift */
|
---|
567 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
568 | 32, /* bitsize */
|
---|
569 | true, /* pc_relative */
|
---|
570 | 0, /* bitpos */
|
---|
571 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
572 | bfd_elf_generic_reloc, /* special_function */
|
---|
573 | "R_PPC_REL32", /* name */
|
---|
574 | false, /* partial_inplace */
|
---|
575 | 0, /* src_mask */
|
---|
576 | 0xffffffff, /* dst_mask */
|
---|
577 | true), /* pcrel_offset */
|
---|
578 |
|
---|
579 | /* 32-bit relocation to the symbol's procedure linkage table.
|
---|
580 | FIXME: not supported. */
|
---|
581 | HOWTO (R_PPC_PLT32, /* type */
|
---|
582 | 0, /* rightshift */
|
---|
583 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
584 | 32, /* bitsize */
|
---|
585 | false, /* pc_relative */
|
---|
586 | 0, /* bitpos */
|
---|
587 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
588 | bfd_elf_generic_reloc, /* special_function */
|
---|
589 | "R_PPC_PLT32", /* name */
|
---|
590 | false, /* partial_inplace */
|
---|
591 | 0, /* src_mask */
|
---|
592 | 0, /* dst_mask */
|
---|
593 | false), /* pcrel_offset */
|
---|
594 |
|
---|
595 | /* 32-bit PC relative relocation to the symbol's procedure linkage table.
|
---|
596 | FIXME: not supported. */
|
---|
597 | HOWTO (R_PPC_PLTREL32, /* type */
|
---|
598 | 0, /* rightshift */
|
---|
599 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
600 | 32, /* bitsize */
|
---|
601 | true, /* pc_relative */
|
---|
602 | 0, /* bitpos */
|
---|
603 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
604 | bfd_elf_generic_reloc, /* special_function */
|
---|
605 | "R_PPC_PLTREL32", /* name */
|
---|
606 | false, /* partial_inplace */
|
---|
607 | 0, /* src_mask */
|
---|
608 | 0, /* dst_mask */
|
---|
609 | true), /* pcrel_offset */
|
---|
610 |
|
---|
611 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
|
---|
612 | the symbol. */
|
---|
613 | HOWTO (R_PPC_PLT16_LO, /* type */
|
---|
614 | 0, /* rightshift */
|
---|
615 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
616 | 16, /* bitsize */
|
---|
617 | false, /* pc_relative */
|
---|
618 | 0, /* bitpos */
|
---|
619 | complain_overflow_dont, /* complain_on_overflow */
|
---|
620 | bfd_elf_generic_reloc, /* special_function */
|
---|
621 | "R_PPC_PLT16_LO", /* name */
|
---|
622 | false, /* partial_inplace */
|
---|
623 | 0, /* src_mask */
|
---|
624 | 0xffff, /* dst_mask */
|
---|
625 | false), /* pcrel_offset */
|
---|
626 |
|
---|
627 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
|
---|
628 | the symbol. */
|
---|
629 | HOWTO (R_PPC_PLT16_HI, /* type */
|
---|
630 | 16, /* rightshift */
|
---|
631 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
632 | 16, /* bitsize */
|
---|
633 | false, /* pc_relative */
|
---|
634 | 0, /* bitpos */
|
---|
635 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
636 | bfd_elf_generic_reloc, /* special_function */
|
---|
637 | "R_PPC_PLT16_HI", /* name */
|
---|
638 | false, /* partial_inplace */
|
---|
639 | 0, /* src_mask */
|
---|
640 | 0xffff, /* dst_mask */
|
---|
641 | false), /* pcrel_offset */
|
---|
642 |
|
---|
643 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
|
---|
644 | the symbol. */
|
---|
645 | HOWTO (R_PPC_PLT16_HA, /* type */
|
---|
646 | 16, /* rightshift */
|
---|
647 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
648 | 16, /* bitsize */
|
---|
649 | false, /* pc_relative */
|
---|
650 | 0, /* bitpos */
|
---|
651 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
652 | ppc_elf_addr16_ha_reloc, /* special_function */
|
---|
653 | "R_PPC_PLT16_HA", /* name */
|
---|
654 | false, /* partial_inplace */
|
---|
655 | 0, /* src_mask */
|
---|
656 | 0xffff, /* dst_mask */
|
---|
657 | false), /* pcrel_offset */
|
---|
658 |
|
---|
659 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
|
---|
660 | small data items. */
|
---|
661 | HOWTO (R_PPC_SDAREL16, /* type */
|
---|
662 | 0, /* rightshift */
|
---|
663 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
664 | 16, /* bitsize */
|
---|
665 | false, /* pc_relative */
|
---|
666 | 0, /* bitpos */
|
---|
667 | complain_overflow_signed, /* complain_on_overflow */
|
---|
668 | bfd_elf_generic_reloc, /* special_function */
|
---|
669 | "R_PPC_SDAREL16", /* name */
|
---|
670 | false, /* partial_inplace */
|
---|
671 | 0, /* src_mask */
|
---|
672 | 0xffff, /* dst_mask */
|
---|
673 | false), /* pcrel_offset */
|
---|
674 |
|
---|
675 | /* 32-bit section relative relocation. */
|
---|
676 | HOWTO (R_PPC_SECTOFF, /* type */
|
---|
677 | 0, /* rightshift */
|
---|
678 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
679 | 32, /* bitsize */
|
---|
680 | true, /* pc_relative */
|
---|
681 | 0, /* bitpos */
|
---|
682 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
683 | bfd_elf_generic_reloc, /* special_function */
|
---|
684 | "R_PPC_SECTOFF", /* name */
|
---|
685 | false, /* partial_inplace */
|
---|
686 | 0, /* src_mask */
|
---|
687 | 0, /* dst_mask */
|
---|
688 | true), /* pcrel_offset */
|
---|
689 |
|
---|
690 | /* 16-bit lower half section relative relocation. */
|
---|
691 | HOWTO (R_PPC_SECTOFF_LO, /* type */
|
---|
692 | 0, /* rightshift */
|
---|
693 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
694 | 16, /* bitsize */
|
---|
695 | false, /* pc_relative */
|
---|
696 | 0, /* bitpos */
|
---|
697 | complain_overflow_dont, /* complain_on_overflow */
|
---|
698 | bfd_elf_generic_reloc, /* special_function */
|
---|
699 | "R_PPC_SECTOFF_LO", /* name */
|
---|
700 | false, /* partial_inplace */
|
---|
701 | 0, /* src_mask */
|
---|
702 | 0xffff, /* dst_mask */
|
---|
703 | false), /* pcrel_offset */
|
---|
704 |
|
---|
705 | /* 16-bit upper half section relative relocation. */
|
---|
706 | HOWTO (R_PPC_SECTOFF_HI, /* type */
|
---|
707 | 16, /* rightshift */
|
---|
708 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
709 | 16, /* bitsize */
|
---|
710 | false, /* pc_relative */
|
---|
711 | 0, /* bitpos */
|
---|
712 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
713 | bfd_elf_generic_reloc, /* special_function */
|
---|
714 | "R_PPC_SECTOFF_HI", /* name */
|
---|
715 | false, /* partial_inplace */
|
---|
716 | 0, /* src_mask */
|
---|
717 | 0xffff, /* dst_mask */
|
---|
718 | false), /* pcrel_offset */
|
---|
719 |
|
---|
720 | /* 16-bit upper half adjusted section relative relocation. */
|
---|
721 | HOWTO (R_PPC_SECTOFF_HA, /* type */
|
---|
722 | 16, /* rightshift */
|
---|
723 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
724 | 16, /* bitsize */
|
---|
725 | false, /* pc_relative */
|
---|
726 | 0, /* bitpos */
|
---|
727 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
728 | ppc_elf_addr16_ha_reloc, /* special_function */
|
---|
729 | "R_PPC_SECTOFF_HA", /* name */
|
---|
730 | false, /* partial_inplace */
|
---|
731 | 0, /* src_mask */
|
---|
732 | 0xffff, /* dst_mask */
|
---|
733 | false), /* pcrel_offset */
|
---|
734 |
|
---|
735 | /* The remaining relocs are from the Embedded ELF ABI, and are not
|
---|
736 | in the SVR4 ELF ABI. */
|
---|
737 |
|
---|
738 | /* 32 bit value resulting from the addend minus the symbol */
|
---|
739 | HOWTO (R_PPC_EMB_NADDR32, /* type */
|
---|
740 | 0, /* rightshift */
|
---|
741 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
742 | 32, /* bitsize */
|
---|
743 | false, /* pc_relative */
|
---|
744 | 0, /* bitpos */
|
---|
745 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
746 | bfd_elf_generic_reloc, /* special_function */
|
---|
747 | "R_PPC_EMB_NADDR32", /* name */
|
---|
748 | false, /* partial_inplace */
|
---|
749 | 0, /* src_mask */
|
---|
750 | 0xffffffff, /* dst_mask */
|
---|
751 | false), /* pcrel_offset */
|
---|
752 |
|
---|
753 | /* 16 bit value resulting from the addend minus the symbol */
|
---|
754 | HOWTO (R_PPC_EMB_NADDR16, /* type */
|
---|
755 | 0, /* rightshift */
|
---|
756 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
757 | 16, /* bitsize */
|
---|
758 | false, /* pc_relative */
|
---|
759 | 0, /* bitpos */
|
---|
760 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
761 | bfd_elf_generic_reloc, /* special_function */
|
---|
762 | "R_PPC_EMB_NADDR16", /* name */
|
---|
763 | false, /* partial_inplace */
|
---|
764 | 0, /* src_mask */
|
---|
765 | 0xffff, /* dst_mask */
|
---|
766 | false), /* pcrel_offset */
|
---|
767 |
|
---|
768 | /* 16 bit value resulting from the addend minus the symbol */
|
---|
769 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
|
---|
770 | 0, /* rightshift */
|
---|
771 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
772 | 16, /* bitsize */
|
---|
773 | false, /* pc_relative */
|
---|
774 | 0, /* bitpos */
|
---|
775 | complain_overflow_dont,/* complain_on_overflow */
|
---|
776 | bfd_elf_generic_reloc, /* special_function */
|
---|
777 | "R_PPC_EMB_ADDR16_LO", /* name */
|
---|
778 | false, /* partial_inplace */
|
---|
779 | 0, /* src_mask */
|
---|
780 | 0xffff, /* dst_mask */
|
---|
781 | false), /* pcrel_offset */
|
---|
782 |
|
---|
783 | /* The high order 16 bits of the addend minus the symbol */
|
---|
784 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
|
---|
785 | 16, /* rightshift */
|
---|
786 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
787 | 16, /* bitsize */
|
---|
788 | false, /* pc_relative */
|
---|
789 | 0, /* bitpos */
|
---|
790 | complain_overflow_dont, /* complain_on_overflow */
|
---|
791 | bfd_elf_generic_reloc, /* special_function */
|
---|
792 | "R_PPC_EMB_NADDR16_HI", /* name */
|
---|
793 | false, /* partial_inplace */
|
---|
794 | 0, /* src_mask */
|
---|
795 | 0xffff, /* dst_mask */
|
---|
796 | false), /* pcrel_offset */
|
---|
797 |
|
---|
798 | /* The high order 16 bits of the result of the addend minus the address,
|
---|
799 | plus 1 if the contents of the low 16 bits, treated as a signed number,
|
---|
800 | is negative. */
|
---|
801 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
|
---|
802 | 16, /* rightshift */
|
---|
803 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
804 | 16, /* bitsize */
|
---|
805 | false, /* pc_relative */
|
---|
806 | 0, /* bitpos */
|
---|
807 | complain_overflow_dont, /* complain_on_overflow */
|
---|
808 | ppc_elf_addr16_ha_reloc, /* special_function */
|
---|
809 | "R_PPC_EMB_NADDR16_HA", /* name */
|
---|
810 | false, /* partial_inplace */
|
---|
811 | 0, /* src_mask */
|
---|
812 | 0xffff, /* dst_mask */
|
---|
813 | false), /* pcrel_offset */
|
---|
814 |
|
---|
815 | /* 16 bit value resulting from allocating a 4 byte word to hold an
|
---|
816 | address in the .sdata section, and returning the offset from
|
---|
817 | _SDA_BASE_ for that relocation */
|
---|
818 | HOWTO (R_PPC_EMB_SDAI16, /* type */
|
---|
819 | 0, /* rightshift */
|
---|
820 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
821 | 16, /* bitsize */
|
---|
822 | false, /* pc_relative */
|
---|
823 | 0, /* bitpos */
|
---|
824 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
825 | bfd_elf_generic_reloc, /* special_function */
|
---|
826 | "R_PPC_EMB_SDAI16", /* name */
|
---|
827 | false, /* partial_inplace */
|
---|
828 | 0, /* src_mask */
|
---|
829 | 0xffff, /* dst_mask */
|
---|
830 | false), /* pcrel_offset */
|
---|
831 |
|
---|
832 | /* 16 bit value resulting from allocating a 4 byte word to hold an
|
---|
833 | address in the .sdata2 section, and returning the offset from
|
---|
834 | _SDA2_BASE_ for that relocation */
|
---|
835 | HOWTO (R_PPC_EMB_SDA2I16, /* type */
|
---|
836 | 0, /* rightshift */
|
---|
837 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
838 | 16, /* bitsize */
|
---|
839 | false, /* pc_relative */
|
---|
840 | 0, /* bitpos */
|
---|
841 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
842 | bfd_elf_generic_reloc, /* special_function */
|
---|
843 | "R_PPC_EMB_SDA2I16", /* name */
|
---|
844 | false, /* partial_inplace */
|
---|
845 | 0, /* src_mask */
|
---|
846 | 0xffff, /* dst_mask */
|
---|
847 | false), /* pcrel_offset */
|
---|
848 |
|
---|
849 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
|
---|
850 | small data items. */
|
---|
851 | HOWTO (R_PPC_EMB_SDA2REL, /* type */
|
---|
852 | 0, /* rightshift */
|
---|
853 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
854 | 16, /* bitsize */
|
---|
855 | false, /* pc_relative */
|
---|
856 | 0, /* bitpos */
|
---|
857 | complain_overflow_signed, /* complain_on_overflow */
|
---|
858 | bfd_elf_generic_reloc, /* special_function */
|
---|
859 | "R_PPC_EMB_SDA2REL", /* name */
|
---|
860 | false, /* partial_inplace */
|
---|
861 | 0, /* src_mask */
|
---|
862 | 0xffff, /* dst_mask */
|
---|
863 | false), /* pcrel_offset */
|
---|
864 |
|
---|
865 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
|
---|
866 | signed offset from the appropriate base, and filling in the register
|
---|
867 | field with the appropriate register (0, 2, or 13). */
|
---|
868 | HOWTO (R_PPC_EMB_SDA21, /* type */
|
---|
869 | 0, /* rightshift */
|
---|
870 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
871 | 16, /* bitsize */
|
---|
872 | false, /* pc_relative */
|
---|
873 | 0, /* bitpos */
|
---|
874 | complain_overflow_signed, /* complain_on_overflow */
|
---|
875 | bfd_elf_generic_reloc, /* special_function */
|
---|
876 | "R_PPC_EMB_SDA21", /* name */
|
---|
877 | false, /* partial_inplace */
|
---|
878 | 0, /* src_mask */
|
---|
879 | 0xffff, /* dst_mask */
|
---|
880 | false), /* pcrel_offset */
|
---|
881 |
|
---|
882 | /* Relocation not handled: R_PPC_EMB_MRKREF */
|
---|
883 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */
|
---|
884 | /* Relocation not handled: R_PPC_EMB_RELST_LO */
|
---|
885 | /* Relocation not handled: R_PPC_EMB_RELST_HI */
|
---|
886 | /* Relocation not handled: R_PPC_EMB_RELST_HA */
|
---|
887 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */
|
---|
888 |
|
---|
889 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
|
---|
890 | in the 16 bit signed offset from the appropriate base, and filling in the
|
---|
891 | register field with the appropriate register (0, 2, or 13). */
|
---|
892 | HOWTO (R_PPC_EMB_RELSDA, /* type */
|
---|
893 | 0, /* rightshift */
|
---|
894 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
895 | 16, /* bitsize */
|
---|
896 | true, /* pc_relative */
|
---|
897 | 0, /* bitpos */
|
---|
898 | complain_overflow_signed, /* complain_on_overflow */
|
---|
899 | bfd_elf_generic_reloc, /* special_function */
|
---|
900 | "R_PPC_EMB_RELSDA", /* name */
|
---|
901 | false, /* partial_inplace */
|
---|
902 | 0, /* src_mask */
|
---|
903 | 0xffff, /* dst_mask */
|
---|
904 | false), /* pcrel_offset */
|
---|
905 |
|
---|
906 | /* GNU extension to record C++ vtable hierarchy */
|
---|
907 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */
|
---|
908 | 0, /* rightshift */
|
---|
909 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
910 | 0, /* bitsize */
|
---|
911 | false, /* pc_relative */
|
---|
912 | 0, /* bitpos */
|
---|
913 | complain_overflow_dont, /* complain_on_overflow */
|
---|
914 | NULL, /* special_function */
|
---|
915 | "R_PPC_GNU_VTINHERIT", /* name */
|
---|
916 | false, /* partial_inplace */
|
---|
917 | 0, /* src_mask */
|
---|
918 | 0, /* dst_mask */
|
---|
919 | false), /* pcrel_offset */
|
---|
920 |
|
---|
921 | /* GNU extension to record C++ vtable member usage */
|
---|
922 | HOWTO (R_PPC_GNU_VTENTRY, /* type */
|
---|
923 | 0, /* rightshift */
|
---|
924 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
925 | 0, /* bitsize */
|
---|
926 | false, /* pc_relative */
|
---|
927 | 0, /* bitpos */
|
---|
928 | complain_overflow_dont, /* complain_on_overflow */
|
---|
929 | NULL, /* special_function */
|
---|
930 | "R_PPC_GNU_VTENTRY", /* name */
|
---|
931 | false, /* partial_inplace */
|
---|
932 | 0, /* src_mask */
|
---|
933 | 0, /* dst_mask */
|
---|
934 | false), /* pcrel_offset */
|
---|
935 |
|
---|
936 | /* Phony reloc to handle AIX style TOC entries */
|
---|
937 | HOWTO (R_PPC_TOC16, /* type */
|
---|
938 | 0, /* rightshift */
|
---|
939 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
940 | 16, /* bitsize */
|
---|
941 | false, /* pc_relative */
|
---|
942 | 0, /* bitpos */
|
---|
943 | complain_overflow_signed, /* complain_on_overflow */
|
---|
944 | bfd_elf_generic_reloc, /* special_function */
|
---|
945 | "R_PPC_TOC16", /* name */
|
---|
946 | false, /* partial_inplace */
|
---|
947 | 0, /* src_mask */
|
---|
948 | 0xffff, /* dst_mask */
|
---|
949 | false), /* pcrel_offset */
|
---|
950 | };
|
---|
951 | |
---|
952 |
|
---|
953 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
|
---|
954 |
|
---|
955 | static void
|
---|
956 | ppc_elf_howto_init ()
|
---|
957 | {
|
---|
958 | unsigned int i, type;
|
---|
959 |
|
---|
960 | for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
|
---|
961 | {
|
---|
962 | type = ppc_elf_howto_raw[i].type;
|
---|
963 | BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0]));
|
---|
964 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
|
---|
965 | }
|
---|
966 | }
|
---|
967 | |
---|
968 |
|
---|
969 | /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
|
---|
970 |
|
---|
971 | The MPC860, revision C0 or earlier contains a bug in the die.
|
---|
972 | If all of the following conditions are true, the next instruction
|
---|
973 | to be executed *may* be treated as a no-op.
|
---|
974 | 1/ A forward branch is executed.
|
---|
975 | 2/ The branch is predicted as not taken.
|
---|
976 | 3/ The branch is taken.
|
---|
977 | 4/ The branch is located in the last 5 words of a page.
|
---|
978 | (The EOP limit is 5 by default but may be specified as any value from 1-10.)
|
---|
979 |
|
---|
980 | Our software solution is to detect these problematic branches in a
|
---|
981 | linker pass and modify them as follows:
|
---|
982 | 1/ Unconditional branches - Since these are always predicted taken,
|
---|
983 | there is no problem and no action is required.
|
---|
984 | 2/ Conditional backward branches - No problem, no action required.
|
---|
985 | 3/ Conditional forward branches - Ensure that the "inverse prediction
|
---|
986 | bit" is set (ensure it is predicted taken).
|
---|
987 | 4/ Conditional register branches - Ensure that the "y bit" is set
|
---|
988 | (ensure it is predicted taken).
|
---|
989 | */
|
---|
990 |
|
---|
991 | /* Sort sections by address. */
|
---|
992 |
|
---|
993 | static int
|
---|
994 | ppc_elf_sort_rela (arg1, arg2)
|
---|
995 | const void *arg1;
|
---|
996 | const void *arg2;
|
---|
997 | {
|
---|
998 | const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1;
|
---|
999 | const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2;
|
---|
1000 |
|
---|
1001 | /* Sort by offset. */
|
---|
1002 | return ((*rela1)->r_offset - (*rela2)->r_offset);
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | static boolean
|
---|
1006 | ppc_elf_relax_section (abfd, isec, link_info, again)
|
---|
1007 | bfd *abfd;
|
---|
1008 | asection *isec;
|
---|
1009 | struct bfd_link_info *link_info;
|
---|
1010 | boolean *again;
|
---|
1011 | {
|
---|
1012 | #define PAGESIZE 0x1000
|
---|
1013 |
|
---|
1014 | bfd_byte *contents = NULL;
|
---|
1015 | bfd_byte *free_contents = NULL;
|
---|
1016 | Elf_Internal_Rela *internal_relocs = NULL;
|
---|
1017 | Elf_Internal_Rela *free_relocs = NULL;
|
---|
1018 | Elf_Internal_Rela **rela_comb = NULL;
|
---|
1019 | int comb_curr, comb_count;
|
---|
1020 |
|
---|
1021 | /* We never have to do this more than once per input section. */
|
---|
1022 | *again = false;
|
---|
1023 |
|
---|
1024 | /* If needed, initialize this section's cooked size. */
|
---|
1025 | if (isec->_cooked_size == 0)
|
---|
1026 | isec->_cooked_size = isec->_raw_size;
|
---|
1027 |
|
---|
1028 | /* We're only interested in text sections which overlap the
|
---|
1029 | troublesome area at the end of a page. */
|
---|
1030 | if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size)
|
---|
1031 | {
|
---|
1032 | bfd_vma dot, end_page, end_section;
|
---|
1033 | boolean section_modified;
|
---|
1034 |
|
---|
1035 | /* Get the section contents. */
|
---|
1036 | /* Get cached copy if it exists. */
|
---|
1037 | if (elf_section_data (isec)->this_hdr.contents != NULL)
|
---|
1038 | contents = elf_section_data (isec)->this_hdr.contents;
|
---|
1039 | else
|
---|
1040 | {
|
---|
1041 | /* Go get them off disk. */
|
---|
1042 | contents = (bfd_byte *) bfd_malloc (isec->_raw_size);
|
---|
1043 | if (contents == NULL)
|
---|
1044 | goto error_return;
|
---|
1045 | free_contents = contents;
|
---|
1046 |
|
---|
1047 | if (! bfd_get_section_contents (abfd, isec, contents,
|
---|
1048 | (file_ptr) 0, isec->_raw_size))
|
---|
1049 | goto error_return;
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | comb_curr = 0;
|
---|
1053 | comb_count = 0;
|
---|
1054 | if (isec->reloc_count)
|
---|
1055 | {
|
---|
1056 | unsigned n;
|
---|
1057 |
|
---|
1058 | /* Get a copy of the native relocations. */
|
---|
1059 | internal_relocs = _bfd_elf32_link_read_relocs (
|
---|
1060 | abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
|
---|
1061 | link_info->keep_memory);
|
---|
1062 | if (internal_relocs == NULL)
|
---|
1063 | goto error_return;
|
---|
1064 | if (! link_info->keep_memory)
|
---|
1065 | free_relocs = internal_relocs;
|
---|
1066 |
|
---|
1067 | /* Setup a faster access method for the reloc info we need. */
|
---|
1068 | rela_comb = (Elf_Internal_Rela**)
|
---|
1069 | bfd_malloc (isec->reloc_count*sizeof (Elf_Internal_Rela*));
|
---|
1070 | if (rela_comb == NULL)
|
---|
1071 | goto error_return;
|
---|
1072 | for (n = 0; n < isec->reloc_count; ++n)
|
---|
1073 | {
|
---|
1074 | long r_type;
|
---|
1075 |
|
---|
1076 | r_type = ELF32_R_TYPE (internal_relocs[n].r_info);
|
---|
1077 | if (r_type < 0 || r_type >= (int) R_PPC_max)
|
---|
1078 | goto error_return;
|
---|
1079 |
|
---|
1080 | /* Prologue constants are sometimes present in the ".text"
|
---|
1081 | sections and they can be identified by their associated relocation.
|
---|
1082 | We don't want to process those words and some others which
|
---|
1083 | can also be identified by their relocations. However, not all
|
---|
1084 | conditional branches will have a relocation so we will
|
---|
1085 | only ignore words that 1) have a reloc, and 2) the reloc
|
---|
1086 | is not applicable to a conditional branch.
|
---|
1087 | The array rela_comb is built here for use in the EOP scan loop. */
|
---|
1088 | switch (r_type)
|
---|
1089 | {
|
---|
1090 | case R_PPC_ADDR14_BRNTAKEN: /* absolute, predicted not taken */
|
---|
1091 | case R_PPC_REL14: /* relative cond. br. */
|
---|
1092 | case R_PPC_REL14_BRNTAKEN: /* rel. cond. br., predicted not taken */
|
---|
1093 | /* We should check the instruction. */
|
---|
1094 | break;
|
---|
1095 | default:
|
---|
1096 | /* The word is not a conditional branch - ignore it. */
|
---|
1097 | rela_comb[comb_count++] = &internal_relocs[n];
|
---|
1098 | break;
|
---|
1099 | }
|
---|
1100 | }
|
---|
1101 | if (comb_count > 1)
|
---|
1102 | qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela);
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | /* Enumerate each EOP region that overlaps this section. */
|
---|
1106 | end_section = isec->vma + isec->_cooked_size;
|
---|
1107 | dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1;
|
---|
1108 | dot -= link_info->mpc860c0;
|
---|
1109 | section_modified = false;
|
---|
1110 | if (dot < isec->vma) /* Increment the start position if this section */
|
---|
1111 | dot = isec->vma; /* begins in the middle of its first EOP region. */
|
---|
1112 | for (;
|
---|
1113 | dot < end_section;
|
---|
1114 | dot += PAGESIZE, end_page += PAGESIZE)
|
---|
1115 | {
|
---|
1116 |
|
---|
1117 | /* Check each word in this EOP region. */
|
---|
1118 | for (; dot < end_page; dot += 4)
|
---|
1119 | {
|
---|
1120 | bfd_vma isec_offset;
|
---|
1121 | unsigned long insn;
|
---|
1122 | boolean skip, modified;
|
---|
1123 |
|
---|
1124 | /* Don't process this word if there is a relocation for it and
|
---|
1125 | the relocation indicates the word is not a conditional branch. */
|
---|
1126 | skip = false;
|
---|
1127 | isec_offset = dot - isec->vma;
|
---|
1128 | for (; comb_curr<comb_count; ++comb_curr)
|
---|
1129 | {
|
---|
1130 | bfd_vma r_offset;
|
---|
1131 |
|
---|
1132 | r_offset = rela_comb[comb_curr]->r_offset;
|
---|
1133 | if (r_offset >= isec_offset)
|
---|
1134 | {
|
---|
1135 | if (r_offset == isec_offset) skip = true;
|
---|
1136 | break;
|
---|
1137 | }
|
---|
1138 | }
|
---|
1139 | if (skip) continue;
|
---|
1140 |
|
---|
1141 | /* Check the current word for a problematic conditional branch. */
|
---|
1142 | #define BO0(insn) ((insn) & 0x02000000)
|
---|
1143 | #define BO2(insn) ((insn) & 0x00800000)
|
---|
1144 | #define BO4(insn) ((insn) & 0x00200000)
|
---|
1145 | insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset);
|
---|
1146 | modified = false;
|
---|
1147 | if ((insn & 0xFc000000) == 0x40000000)
|
---|
1148 | {
|
---|
1149 | /* Instruction is BCx */
|
---|
1150 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
|
---|
1151 | {
|
---|
1152 | bfd_vma target;
|
---|
1153 | /* This branch is predicted as "normal".
|
---|
1154 | If this is a forward branch, it is problematic. */
|
---|
1155 |
|
---|
1156 | target = insn & 0x0000Fffc; /*extract*/
|
---|
1157 | target = (target ^ 0x8000) - 0x8000; /*sign extend*/
|
---|
1158 | if ((insn & 0x00000002) == 0)
|
---|
1159 | target += dot; /*convert to abs*/
|
---|
1160 | if (target > dot)
|
---|
1161 | {
|
---|
1162 | insn |= 0x00200000; /* set the prediction bit */
|
---|
1163 | modified = true;
|
---|
1164 | }
|
---|
1165 | }
|
---|
1166 | }
|
---|
1167 | else if ((insn & 0xFc00Fffe) == 0x4c000420)
|
---|
1168 | {
|
---|
1169 | /* Instruction is BCCTRx */
|
---|
1170 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
|
---|
1171 | {
|
---|
1172 | /* This branch is predicted as not-taken.
|
---|
1173 | If this is a forward branch, it is problematic.
|
---|
1174 | Since we can't tell statically if it will branch forward,
|
---|
1175 | always set the prediction bit. */
|
---|
1176 | insn |= 0x00200000; /* set the prediction bit */
|
---|
1177 | modified = true;
|
---|
1178 | }
|
---|
1179 | }
|
---|
1180 | else if ((insn & 0xFc00Fffe) == 0x4c000020)
|
---|
1181 | {
|
---|
1182 | /* Instruction is BCLRx */
|
---|
1183 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
|
---|
1184 | {
|
---|
1185 | /* This branch is predicted as not-taken.
|
---|
1186 | If this is a forward branch, it is problematic.
|
---|
1187 | Since we can't tell statically if it will branch forward,
|
---|
1188 | always set the prediction bit. */
|
---|
1189 | insn |= 0x00200000; /* set the prediction bit */
|
---|
1190 | modified = true;
|
---|
1191 | }
|
---|
1192 | }
|
---|
1193 | #undef BO0
|
---|
1194 | #undef BO2
|
---|
1195 | #undef BO4
|
---|
1196 | if (modified)
|
---|
1197 | {
|
---|
1198 | bfd_put_32 (abfd, insn, contents + isec_offset);
|
---|
1199 | section_modified = true;
|
---|
1200 | }
|
---|
1201 | }
|
---|
1202 | }
|
---|
1203 | if (section_modified)
|
---|
1204 | {
|
---|
1205 | elf_section_data (isec)->this_hdr.contents = contents;
|
---|
1206 | free_contents = NULL;
|
---|
1207 | }
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | if (rela_comb != NULL)
|
---|
1211 | {
|
---|
1212 | free (rela_comb);
|
---|
1213 | rela_comb = NULL;
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 | if (free_relocs != NULL)
|
---|
1217 | {
|
---|
1218 | free (free_relocs);
|
---|
1219 | free_relocs = NULL;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | if (free_contents != NULL)
|
---|
1223 | {
|
---|
1224 | if (! link_info->keep_memory)
|
---|
1225 | free (free_contents);
|
---|
1226 | else
|
---|
1227 | {
|
---|
1228 | /* Cache the section contents for elf_link_input_bfd. */
|
---|
1229 | elf_section_data (isec)->this_hdr.contents = contents;
|
---|
1230 | }
|
---|
1231 | free_contents = NULL;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | return true;
|
---|
1235 |
|
---|
1236 | error_return:
|
---|
1237 | if (rela_comb != NULL)
|
---|
1238 | free (rela_comb);
|
---|
1239 | if (free_relocs != NULL)
|
---|
1240 | free (free_relocs);
|
---|
1241 | if (free_contents != NULL)
|
---|
1242 | free (free_contents);
|
---|
1243 | return false;
|
---|
1244 | }
|
---|
1245 | |
---|
1246 |
|
---|
1247 | static reloc_howto_type *
|
---|
1248 | ppc_elf_reloc_type_lookup (abfd, code)
|
---|
1249 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1250 | bfd_reloc_code_real_type code;
|
---|
1251 | {
|
---|
1252 | enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
|
---|
1253 |
|
---|
1254 | if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
---|
1255 | /* Initialize howto table if needed. */
|
---|
1256 | ppc_elf_howto_init ();
|
---|
1257 |
|
---|
1258 | switch ((int) code)
|
---|
1259 | {
|
---|
1260 | default:
|
---|
1261 | return (reloc_howto_type *) NULL;
|
---|
1262 |
|
---|
1263 | case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
|
---|
1264 | case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
|
---|
1265 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
|
---|
1266 | case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
|
---|
1267 | case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
|
---|
1268 | case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
|
---|
1269 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
|
---|
1270 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
|
---|
1271 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
|
---|
1272 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
|
---|
1273 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
|
---|
1274 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
|
---|
1275 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
|
---|
1276 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
|
---|
1277 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
|
---|
1278 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
|
---|
1279 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
|
---|
1280 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
|
---|
1281 | case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
|
---|
1282 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
|
---|
1283 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
|
---|
1284 | case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
|
---|
1285 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
|
---|
1286 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
|
---|
1287 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
|
---|
1288 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
|
---|
1289 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
|
---|
1290 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
|
---|
1291 | case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
|
---|
1292 | case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
|
---|
1293 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
|
---|
1294 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
|
---|
1295 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
|
---|
1296 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
|
---|
1297 | case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
|
---|
1298 | case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break;
|
---|
1299 | case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break;
|
---|
1300 | case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break;
|
---|
1301 | case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break;
|
---|
1302 | case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break;
|
---|
1303 | case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break;
|
---|
1304 | case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break;
|
---|
1305 | case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break;
|
---|
1306 | case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break;
|
---|
1307 | case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break;
|
---|
1308 | case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break;
|
---|
1309 | case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break;
|
---|
1310 | case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break;
|
---|
1311 | case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break;
|
---|
1312 | case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break;
|
---|
1313 | case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break;
|
---|
1314 | case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC_GNU_VTINHERIT; break;
|
---|
1315 | case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC_GNU_VTENTRY; break;
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | return ppc_elf_howto_table[(int) ppc_reloc];
|
---|
1319 | };
|
---|
1320 |
|
---|
1321 | /* Set the howto pointer for a PowerPC ELF reloc. */
|
---|
1322 |
|
---|
1323 | static void
|
---|
1324 | ppc_elf_info_to_howto (abfd, cache_ptr, dst)
|
---|
1325 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1326 | arelent *cache_ptr;
|
---|
1327 | Elf32_Internal_Rela *dst;
|
---|
1328 | {
|
---|
1329 | if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
---|
1330 | /* Initialize howto table if needed. */
|
---|
1331 | ppc_elf_howto_init ();
|
---|
1332 |
|
---|
1333 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
|
---|
1334 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /* Handle the R_PPC_ADDR16_HA reloc. */
|
---|
1338 |
|
---|
1339 | static bfd_reloc_status_type
|
---|
1340 | ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
|
---|
1341 | output_bfd, error_message)
|
---|
1342 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1343 | arelent *reloc_entry;
|
---|
1344 | asymbol *symbol;
|
---|
1345 | PTR data ATTRIBUTE_UNUSED;
|
---|
1346 | asection *input_section;
|
---|
1347 | bfd *output_bfd;
|
---|
1348 | char **error_message ATTRIBUTE_UNUSED;
|
---|
1349 | {
|
---|
1350 | bfd_vma relocation;
|
---|
1351 |
|
---|
1352 | if (output_bfd != NULL)
|
---|
1353 | {
|
---|
1354 | reloc_entry->address += input_section->output_offset;
|
---|
1355 | return bfd_reloc_ok;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | if (reloc_entry->address > input_section->_cooked_size)
|
---|
1359 | return bfd_reloc_outofrange;
|
---|
1360 |
|
---|
1361 | if (bfd_is_com_section (symbol->section))
|
---|
1362 | relocation = 0;
|
---|
1363 | else
|
---|
1364 | relocation = symbol->value;
|
---|
1365 |
|
---|
1366 | relocation += symbol->section->output_section->vma;
|
---|
1367 | relocation += symbol->section->output_offset;
|
---|
1368 | relocation += reloc_entry->addend;
|
---|
1369 |
|
---|
1370 | reloc_entry->addend += (relocation & 0x8000) << 1;
|
---|
1371 |
|
---|
1372 | return bfd_reloc_continue;
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | /* Function to set whether a module needs the -mrelocatable bit set. */
|
---|
1376 |
|
---|
1377 | static boolean
|
---|
1378 | ppc_elf_set_private_flags (abfd, flags)
|
---|
1379 | bfd *abfd;
|
---|
1380 | flagword flags;
|
---|
1381 | {
|
---|
1382 | BFD_ASSERT (!elf_flags_init (abfd)
|
---|
1383 | || elf_elfheader (abfd)->e_flags == flags);
|
---|
1384 |
|
---|
1385 | elf_elfheader (abfd)->e_flags = flags;
|
---|
1386 | elf_flags_init (abfd) = true;
|
---|
1387 | return true;
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 | /* Copy backend specific data from one object module to another */
|
---|
1391 | static boolean
|
---|
1392 | ppc_elf_copy_private_bfd_data (ibfd, obfd)
|
---|
1393 | bfd *ibfd;
|
---|
1394 | bfd *obfd;
|
---|
1395 | {
|
---|
1396 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|
---|
1397 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
|
---|
1398 | return true;
|
---|
1399 |
|
---|
1400 | BFD_ASSERT (!elf_flags_init (obfd)
|
---|
1401 | || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
|
---|
1402 |
|
---|
1403 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
|
---|
1404 | elf_flags_init (obfd) = true;
|
---|
1405 | return true;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | /* Merge backend specific data from an object file to the output
|
---|
1409 | object file when linking */
|
---|
1410 | static boolean
|
---|
1411 | ppc_elf_merge_private_bfd_data (ibfd, obfd)
|
---|
1412 | bfd *ibfd;
|
---|
1413 | bfd *obfd;
|
---|
1414 | {
|
---|
1415 | flagword old_flags;
|
---|
1416 | flagword new_flags;
|
---|
1417 | boolean error;
|
---|
1418 |
|
---|
1419 | /* Check if we have the same endianess */
|
---|
1420 | if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
|
---|
1421 | return false;
|
---|
1422 |
|
---|
1423 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|
---|
1424 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
|
---|
1425 | return true;
|
---|
1426 |
|
---|
1427 | new_flags = elf_elfheader (ibfd)->e_flags;
|
---|
1428 | old_flags = elf_elfheader (obfd)->e_flags;
|
---|
1429 | if (!elf_flags_init (obfd)) /* First call, no flags set */
|
---|
1430 | {
|
---|
1431 | elf_flags_init (obfd) = true;
|
---|
1432 | elf_elfheader (obfd)->e_flags = new_flags;
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | else if (new_flags == old_flags) /* Compatible flags are ok */
|
---|
1436 | ;
|
---|
1437 |
|
---|
1438 | else /* Incompatible flags */
|
---|
1439 | {
|
---|
1440 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
|
---|
1441 | with either. */
|
---|
1442 | error = false;
|
---|
1443 | if ((new_flags & EF_PPC_RELOCATABLE) != 0
|
---|
1444 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
|
---|
1445 | {
|
---|
1446 | error = true;
|
---|
1447 | (*_bfd_error_handler)
|
---|
1448 | (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
|
---|
1449 | bfd_get_filename (ibfd));
|
---|
1450 | }
|
---|
1451 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
|
---|
1452 | && (old_flags & EF_PPC_RELOCATABLE) != 0)
|
---|
1453 | {
|
---|
1454 | error = true;
|
---|
1455 | (*_bfd_error_handler)
|
---|
1456 | (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
|
---|
1457 | bfd_get_filename (ibfd));
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | /* The output is -mrelocatable-lib iff both the input files are. */
|
---|
1461 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
|
---|
1462 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
|
---|
1463 |
|
---|
1464 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
|
---|
1465 | but each input file is either -mrelocatable or -mrelocatable-lib. */
|
---|
1466 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
|
---|
1467 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
|
---|
1468 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
|
---|
1469 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
|
---|
1470 |
|
---|
1471 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
|
---|
1472 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
|
---|
1473 |
|
---|
1474 | new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
|
---|
1475 | old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
|
---|
1476 |
|
---|
1477 | /* Warn about any other mismatches */
|
---|
1478 | if (new_flags != old_flags)
|
---|
1479 | {
|
---|
1480 | error = true;
|
---|
1481 | (*_bfd_error_handler)
|
---|
1482 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
|
---|
1483 | bfd_get_filename (ibfd), (long) new_flags, (long) old_flags);
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | if (error)
|
---|
1487 | {
|
---|
1488 | bfd_set_error (bfd_error_bad_value);
|
---|
1489 | return false;
|
---|
1490 | }
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | return true;
|
---|
1494 | }
|
---|
1495 | |
---|
1496 |
|
---|
1497 | /* Handle a PowerPC specific section when reading an object file. This
|
---|
1498 | is called when elfcode.h finds a section with an unknown type. */
|
---|
1499 |
|
---|
1500 | static boolean
|
---|
1501 | ppc_elf_section_from_shdr (abfd, hdr, name)
|
---|
1502 | bfd *abfd;
|
---|
1503 | Elf32_Internal_Shdr *hdr;
|
---|
1504 | char *name;
|
---|
1505 | {
|
---|
1506 | asection *newsect;
|
---|
1507 | flagword flags;
|
---|
1508 |
|
---|
1509 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
|
---|
1510 | return false;
|
---|
1511 |
|
---|
1512 | newsect = hdr->bfd_section;
|
---|
1513 | flags = bfd_get_section_flags (abfd, newsect);
|
---|
1514 | if (hdr->sh_flags & SHF_EXCLUDE)
|
---|
1515 | flags |= SEC_EXCLUDE;
|
---|
1516 |
|
---|
1517 | if (hdr->sh_type == SHT_ORDERED)
|
---|
1518 | flags |= SEC_SORT_ENTRIES;
|
---|
1519 |
|
---|
1520 | bfd_set_section_flags (abfd, newsect, flags);
|
---|
1521 | return true;
|
---|
1522 | }
|
---|
1523 | |
---|
1524 |
|
---|
1525 | /* Set up any other section flags and such that may be necessary. */
|
---|
1526 |
|
---|
1527 | static boolean
|
---|
1528 | ppc_elf_fake_sections (abfd, shdr, asect)
|
---|
1529 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1530 | Elf32_Internal_Shdr *shdr;
|
---|
1531 | asection *asect;
|
---|
1532 | {
|
---|
1533 | if ((asect->flags & SEC_EXCLUDE) != 0)
|
---|
1534 | shdr->sh_flags |= SHF_EXCLUDE;
|
---|
1535 |
|
---|
1536 | if ((asect->flags & SEC_SORT_ENTRIES) != 0)
|
---|
1537 | shdr->sh_type = SHT_ORDERED;
|
---|
1538 |
|
---|
1539 | return true;
|
---|
1540 | }
|
---|
1541 | |
---|
1542 |
|
---|
1543 | /* Create a special linker section */
|
---|
1544 | static elf_linker_section_t *
|
---|
1545 | ppc_elf_create_linker_section (abfd, info, which)
|
---|
1546 | bfd *abfd;
|
---|
1547 | struct bfd_link_info *info;
|
---|
1548 | enum elf_linker_section_enum which;
|
---|
1549 | {
|
---|
1550 | bfd *dynobj = elf_hash_table (info)->dynobj;
|
---|
1551 | elf_linker_section_t *lsect;
|
---|
1552 |
|
---|
1553 | /* Record the first bfd section that needs the special section */
|
---|
1554 | if (!dynobj)
|
---|
1555 | dynobj = elf_hash_table (info)->dynobj = abfd;
|
---|
1556 |
|
---|
1557 | /* If this is the first time, create the section */
|
---|
1558 | lsect = elf_linker_section (dynobj, which);
|
---|
1559 | if (!lsect)
|
---|
1560 | {
|
---|
1561 | elf_linker_section_t defaults;
|
---|
1562 | static elf_linker_section_t zero_section;
|
---|
1563 |
|
---|
1564 | defaults = zero_section;
|
---|
1565 | defaults.which = which;
|
---|
1566 | defaults.hole_written_p = false;
|
---|
1567 | defaults.alignment = 2;
|
---|
1568 |
|
---|
1569 | /* Both of these sections are (technically) created by the user
|
---|
1570 | putting data in them, so they shouldn't be marked
|
---|
1571 | SEC_LINKER_CREATED.
|
---|
1572 |
|
---|
1573 | The linker creates them so it has somewhere to attach their
|
---|
1574 | respective symbols. In fact, if they were empty it would
|
---|
1575 | be OK to leave the symbol set to 0 (or any random number), because
|
---|
1576 | the appropriate register should never be used. */
|
---|
1577 | defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
|
---|
1578 | | SEC_IN_MEMORY);
|
---|
1579 |
|
---|
1580 | switch (which)
|
---|
1581 | {
|
---|
1582 | default:
|
---|
1583 | (*_bfd_error_handler) (_("%s: Unknown special linker type %d"),
|
---|
1584 | bfd_get_filename (abfd),
|
---|
1585 | (int) which);
|
---|
1586 |
|
---|
1587 | bfd_set_error (bfd_error_bad_value);
|
---|
1588 | return (elf_linker_section_t *) 0;
|
---|
1589 |
|
---|
1590 | case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
|
---|
1591 | defaults.name = ".sdata";
|
---|
1592 | defaults.rel_name = ".rela.sdata";
|
---|
1593 | defaults.bss_name = ".sbss";
|
---|
1594 | defaults.sym_name = "_SDA_BASE_";
|
---|
1595 | defaults.sym_offset = 32768;
|
---|
1596 | break;
|
---|
1597 |
|
---|
1598 | case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
|
---|
1599 | defaults.name = ".sdata2";
|
---|
1600 | defaults.rel_name = ".rela.sdata2";
|
---|
1601 | defaults.bss_name = ".sbss2";
|
---|
1602 | defaults.sym_name = "_SDA2_BASE_";
|
---|
1603 | defaults.sym_offset = 32768;
|
---|
1604 | defaults.flags |= SEC_READONLY;
|
---|
1605 | break;
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 | return lsect;
|
---|
1612 | }
|
---|
1613 | |
---|
1614 |
|
---|
1615 | /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
|
---|
1616 | need to bump up the number of section headers. */
|
---|
1617 |
|
---|
1618 | static int
|
---|
1619 | ppc_elf_additional_program_headers (abfd)
|
---|
1620 | bfd *abfd;
|
---|
1621 | {
|
---|
1622 | asection *s;
|
---|
1623 | int ret;
|
---|
1624 |
|
---|
1625 | ret = 0;
|
---|
1626 |
|
---|
1627 | s = bfd_get_section_by_name (abfd, ".interp");
|
---|
1628 | if (s != NULL)
|
---|
1629 | ++ret;
|
---|
1630 |
|
---|
1631 | s = bfd_get_section_by_name (abfd, ".sbss2");
|
---|
1632 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
|
---|
1633 | ++ret;
|
---|
1634 |
|
---|
1635 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
|
---|
1636 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
|
---|
1637 | ++ret;
|
---|
1638 |
|
---|
1639 | return ret;
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 | /* Modify the segment map if needed. */
|
---|
1643 |
|
---|
1644 | static boolean
|
---|
1645 | ppc_elf_modify_segment_map (abfd)
|
---|
1646 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1647 | {
|
---|
1648 | return true;
|
---|
1649 | }
|
---|
1650 | |
---|
1651 |
|
---|
1652 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped
|
---|
1653 | to output sections (just like _bfd_elf_create_dynamic_sections has
|
---|
1654 | to create .dynbss and .rela.bss). */
|
---|
1655 |
|
---|
1656 | static boolean
|
---|
1657 | ppc_elf_create_dynamic_sections (abfd, info)
|
---|
1658 | bfd *abfd;
|
---|
1659 | struct bfd_link_info *info;
|
---|
1660 | {
|
---|
1661 | register asection *s;
|
---|
1662 | flagword flags;
|
---|
1663 |
|
---|
1664 | if (!_bfd_elf_create_dynamic_sections (abfd, info))
|
---|
1665 | return false;
|
---|
1666 |
|
---|
1667 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
|
---|
1668 | | SEC_LINKER_CREATED);
|
---|
1669 |
|
---|
1670 | s = bfd_make_section (abfd, ".dynsbss");
|
---|
1671 | if (s == NULL
|
---|
1672 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
|
---|
1673 | return false;
|
---|
1674 |
|
---|
1675 | if (! info->shared)
|
---|
1676 | {
|
---|
1677 | s = bfd_make_section (abfd, ".rela.sbss");
|
---|
1678 | if (s == NULL
|
---|
1679 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|
---|
1680 | || ! bfd_set_section_alignment (abfd, s, 2))
|
---|
1681 | return false;
|
---|
1682 | }
|
---|
1683 | return true;
|
---|
1684 | }
|
---|
1685 |
|
---|
1686 | /* Adjust a symbol defined by a dynamic object and referenced by a
|
---|
1687 | regular object. The current definition is in some section of the
|
---|
1688 | dynamic object, but we're not including those sections. We have to
|
---|
1689 | change the definition to something the rest of the link can
|
---|
1690 | understand. */
|
---|
1691 |
|
---|
1692 | static boolean
|
---|
1693 | ppc_elf_adjust_dynamic_symbol (info, h)
|
---|
1694 | struct bfd_link_info *info;
|
---|
1695 | struct elf_link_hash_entry *h;
|
---|
1696 | {
|
---|
1697 | bfd *dynobj = elf_hash_table (info)->dynobj;
|
---|
1698 | asection *s;
|
---|
1699 | unsigned int power_of_two;
|
---|
1700 | bfd_vma plt_offset;
|
---|
1701 |
|
---|
1702 | #ifdef DEBUG
|
---|
1703 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
|
---|
1704 | #endif
|
---|
1705 |
|
---|
1706 | /* Make sure we know what is going on here. */
|
---|
1707 | BFD_ASSERT (dynobj != NULL
|
---|
1708 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
|
---|
1709 | || h->weakdef != NULL
|
---|
1710 | || ((h->elf_link_hash_flags
|
---|
1711 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0
|
---|
1712 | && (h->elf_link_hash_flags
|
---|
1713 | & ELF_LINK_HASH_REF_REGULAR) != 0
|
---|
1714 | && (h->elf_link_hash_flags
|
---|
1715 | & ELF_LINK_HASH_DEF_REGULAR) == 0)));
|
---|
1716 |
|
---|
1717 | /* If this is a function, put it in the procedure linkage table. We
|
---|
1718 | will fill in the contents of the procedure linkage table later,
|
---|
1719 | when we know the address of the .got section. */
|
---|
1720 | if (h->type == STT_FUNC
|
---|
1721 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
|
---|
1722 | {
|
---|
1723 | if (! elf_hash_table (info)->dynamic_sections_created
|
---|
1724 | || SYMBOL_CALLS_LOCAL (info, h)
|
---|
1725 | || (info->shared && h->plt.refcount <= 0))
|
---|
1726 | {
|
---|
1727 | /* A PLT entry is not required/allowed when:
|
---|
1728 |
|
---|
1729 | 1. We are not using ld.so; because then the PLT entry
|
---|
1730 | can't be set up, so we can't use one.
|
---|
1731 |
|
---|
1732 | 2. We know for certain that a call to this symbol
|
---|
1733 | will go to this object.
|
---|
1734 |
|
---|
1735 | 3. GC has rendered the entry unused.
|
---|
1736 | Note, however, that in an executable all references to the
|
---|
1737 | symbol go to the PLT, so we can't turn it off in that case.
|
---|
1738 | ??? The correct thing to do here is to reference count
|
---|
1739 | all uses of the symbol, not just those to the GOT or PLT. */
|
---|
1740 | h->plt.offset = (bfd_vma) -1;
|
---|
1741 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
|
---|
1742 | return true;
|
---|
1743 | }
|
---|
1744 |
|
---|
1745 | /* Make sure this symbol is output as a dynamic symbol. */
|
---|
1746 | if (h->dynindx == -1)
|
---|
1747 | {
|
---|
1748 | if (! bfd_elf32_link_record_dynamic_symbol (info, h))
|
---|
1749 | return false;
|
---|
1750 | }
|
---|
1751 | BFD_ASSERT (h->dynindx != -1);
|
---|
1752 |
|
---|
1753 | s = bfd_get_section_by_name (dynobj, ".plt");
|
---|
1754 | BFD_ASSERT (s != NULL);
|
---|
1755 |
|
---|
1756 | /* If this is the first .plt entry, make room for the special
|
---|
1757 | first entry. */
|
---|
1758 | if (s->_raw_size == 0)
|
---|
1759 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
|
---|
1760 |
|
---|
1761 | /* The PowerPC PLT is actually composed of two parts, the first part
|
---|
1762 | is 2 words (for a load and a jump), and then there is a remaining
|
---|
1763 | word available at the end. */
|
---|
1764 | plt_offset = (PLT_INITIAL_ENTRY_SIZE
|
---|
1765 | + (PLT_SLOT_SIZE
|
---|
1766 | * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
|
---|
1767 | / PLT_ENTRY_SIZE)));
|
---|
1768 |
|
---|
1769 | /* If this symbol is not defined in a regular file, and we are
|
---|
1770 | not generating a shared library, then set the symbol to this
|
---|
1771 | location in the .plt. This is required to make function
|
---|
1772 | pointers compare as equal between the normal executable and
|
---|
1773 | the shared library. */
|
---|
1774 | if (! info->shared
|
---|
1775 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
---|
1776 | {
|
---|
1777 | h->root.u.def.section = s;
|
---|
1778 | h->root.u.def.value = plt_offset;
|
---|
1779 | }
|
---|
1780 |
|
---|
1781 | h->plt.offset = plt_offset;
|
---|
1782 |
|
---|
1783 | /* Make room for this entry. After the 8192nd entry, room
|
---|
1784 | for two entries is allocated. */
|
---|
1785 | if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
|
---|
1786 | >= PLT_NUM_SINGLE_ENTRIES)
|
---|
1787 | s->_raw_size += 2 * PLT_ENTRY_SIZE;
|
---|
1788 | else
|
---|
1789 | s->_raw_size += PLT_ENTRY_SIZE;
|
---|
1790 |
|
---|
1791 | /* We also need to make an entry in the .rela.plt section. */
|
---|
1792 | s = bfd_get_section_by_name (dynobj, ".rela.plt");
|
---|
1793 | BFD_ASSERT (s != NULL);
|
---|
1794 | s->_raw_size += sizeof (Elf32_External_Rela);
|
---|
1795 |
|
---|
1796 | return true;
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | /* If this is a weak symbol, and there is a real definition, the
|
---|
1800 | processor independent code will have arranged for us to see the
|
---|
1801 | real definition first, and we can just use the same value. */
|
---|
1802 | if (h->weakdef != NULL)
|
---|
1803 | {
|
---|
1804 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
|
---|
1805 | || h->weakdef->root.type == bfd_link_hash_defweak);
|
---|
1806 | h->root.u.def.section = h->weakdef->root.u.def.section;
|
---|
1807 | h->root.u.def.value = h->weakdef->root.u.def.value;
|
---|
1808 | return true;
|
---|
1809 | }
|
---|
1810 |
|
---|
1811 | /* This is a reference to a symbol defined by a dynamic object which
|
---|
1812 | is not a function. */
|
---|
1813 |
|
---|
1814 | /* If we are creating a shared library, we must presume that the
|
---|
1815 | only references to the symbol are via the global offset table.
|
---|
1816 | For such cases we need not do anything here; the relocations will
|
---|
1817 | be handled correctly by relocate_section. */
|
---|
1818 | if (info->shared)
|
---|
1819 | return true;
|
---|
1820 |
|
---|
1821 | /* We must allocate the symbol in our .dynbss section, which will
|
---|
1822 | become part of the .bss section of the executable. There will be
|
---|
1823 | an entry for this symbol in the .dynsym section. The dynamic
|
---|
1824 | object will contain position independent code, so all references
|
---|
1825 | from the dynamic object to this symbol will go through the global
|
---|
1826 | offset table. The dynamic linker will use the .dynsym entry to
|
---|
1827 | determine the address it must put in the global offset table, so
|
---|
1828 | both the dynamic object and the regular object will refer to the
|
---|
1829 | same memory location for the variable.
|
---|
1830 |
|
---|
1831 | Of course, if the symbol is sufficiently small, we must instead
|
---|
1832 | allocate it in .sbss. FIXME: It would be better to do this if and
|
---|
1833 | only if there were actually SDAREL relocs for that symbol. */
|
---|
1834 |
|
---|
1835 | if (h->size <= elf_gp_size (dynobj))
|
---|
1836 | s = bfd_get_section_by_name (dynobj, ".dynsbss");
|
---|
1837 | else
|
---|
1838 | s = bfd_get_section_by_name (dynobj, ".dynbss");
|
---|
1839 | BFD_ASSERT (s != NULL);
|
---|
1840 |
|
---|
1841 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
|
---|
1842 | copy the initial value out of the dynamic object and into the
|
---|
1843 | runtime process image. We need to remember the offset into the
|
---|
1844 | .rela.bss section we are going to use. */
|
---|
1845 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
|
---|
1846 | {
|
---|
1847 | asection *srel;
|
---|
1848 |
|
---|
1849 | if (h->size <= elf_gp_size (dynobj))
|
---|
1850 | srel = bfd_get_section_by_name (dynobj, ".rela.sbss");
|
---|
1851 | else
|
---|
1852 | srel = bfd_get_section_by_name (dynobj, ".rela.bss");
|
---|
1853 | BFD_ASSERT (srel != NULL);
|
---|
1854 | srel->_raw_size += sizeof (Elf32_External_Rela);
|
---|
1855 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
|
---|
1856 | }
|
---|
1857 |
|
---|
1858 | /* We need to figure out the alignment required for this symbol. I
|
---|
1859 | have no idea how ELF linkers handle this. */
|
---|
1860 | power_of_two = bfd_log2 (h->size);
|
---|
1861 | if (power_of_two > 4)
|
---|
1862 | power_of_two = 4;
|
---|
1863 |
|
---|
1864 | /* Apply the required alignment. */
|
---|
1865 | s->_raw_size = BFD_ALIGN (s->_raw_size,
|
---|
1866 | (bfd_size_type) (1 << power_of_two));
|
---|
1867 | if (power_of_two > bfd_get_section_alignment (dynobj, s))
|
---|
1868 | {
|
---|
1869 | if (! bfd_set_section_alignment (dynobj, s, power_of_two))
|
---|
1870 | return false;
|
---|
1871 | }
|
---|
1872 |
|
---|
1873 | /* Define the symbol as being at this point in the section. */
|
---|
1874 | h->root.u.def.section = s;
|
---|
1875 | h->root.u.def.value = s->_raw_size;
|
---|
1876 |
|
---|
1877 | /* Increment the section size to make room for the symbol. */
|
---|
1878 | s->_raw_size += h->size;
|
---|
1879 |
|
---|
1880 | return true;
|
---|
1881 | }
|
---|
1882 | |
---|
1883 |
|
---|
1884 | /* Set the sizes of the dynamic sections. */
|
---|
1885 |
|
---|
1886 | static boolean
|
---|
1887 | ppc_elf_size_dynamic_sections (output_bfd, info)
|
---|
1888 | bfd *output_bfd;
|
---|
1889 | struct bfd_link_info *info;
|
---|
1890 | {
|
---|
1891 | bfd *dynobj;
|
---|
1892 | asection *s;
|
---|
1893 | boolean plt;
|
---|
1894 | boolean relocs;
|
---|
1895 | boolean reltext;
|
---|
1896 |
|
---|
1897 | #ifdef DEBUG
|
---|
1898 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
|
---|
1899 | #endif
|
---|
1900 |
|
---|
1901 | dynobj = elf_hash_table (info)->dynobj;
|
---|
1902 | BFD_ASSERT (dynobj != NULL);
|
---|
1903 |
|
---|
1904 | if (elf_hash_table (info)->dynamic_sections_created)
|
---|
1905 | {
|
---|
1906 | /* Set the contents of the .interp section to the interpreter. */
|
---|
1907 | if (! info->shared)
|
---|
1908 | {
|
---|
1909 | s = bfd_get_section_by_name (dynobj, ".interp");
|
---|
1910 | BFD_ASSERT (s != NULL);
|
---|
1911 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
|
---|
1912 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
|
---|
1913 | }
|
---|
1914 | }
|
---|
1915 | else
|
---|
1916 | {
|
---|
1917 | /* We may have created entries in the .rela.got, .rela.sdata, and
|
---|
1918 | .rela.sdata2 sections. However, if we are not creating the
|
---|
1919 | dynamic sections, we will not actually use these entries. Reset
|
---|
1920 | the size of .rela.got, et al, which will cause it to get
|
---|
1921 | stripped from the output file below. */
|
---|
1922 | static char *rela_sections[] = { ".rela.got", ".rela.sdata",
|
---|
1923 | ".rela.sdata2", ".rela.sbss",
|
---|
1924 | (char *) 0 };
|
---|
1925 | char **p;
|
---|
1926 |
|
---|
1927 | for (p = rela_sections; *p != (char *) 0; p++)
|
---|
1928 | {
|
---|
1929 | s = bfd_get_section_by_name (dynobj, *p);
|
---|
1930 | if (s != NULL)
|
---|
1931 | s->_raw_size = 0;
|
---|
1932 | }
|
---|
1933 | }
|
---|
1934 |
|
---|
1935 | /* The check_relocs and adjust_dynamic_symbol entry points have
|
---|
1936 | determined the sizes of the various dynamic sections. Allocate
|
---|
1937 | memory for them. */
|
---|
1938 | plt = false;
|
---|
1939 | relocs = false;
|
---|
1940 | reltext = false;
|
---|
1941 | for (s = dynobj->sections; s != NULL; s = s->next)
|
---|
1942 | {
|
---|
1943 | const char *name;
|
---|
1944 | boolean strip;
|
---|
1945 |
|
---|
1946 | if ((s->flags & SEC_LINKER_CREATED) == 0)
|
---|
1947 | continue;
|
---|
1948 |
|
---|
1949 | /* It's OK to base decisions on the section name, because none
|
---|
1950 | of the dynobj section names depend upon the input files. */
|
---|
1951 | name = bfd_get_section_name (dynobj, s);
|
---|
1952 |
|
---|
1953 | strip = false;
|
---|
1954 |
|
---|
1955 | if (strcmp (name, ".plt") == 0)
|
---|
1956 | {
|
---|
1957 | if (s->_raw_size == 0)
|
---|
1958 | {
|
---|
1959 | /* Strip this section if we don't need it; see the
|
---|
1960 | comment below. */
|
---|
1961 | strip = true;
|
---|
1962 | }
|
---|
1963 | else
|
---|
1964 | {
|
---|
1965 | /* Remember whether there is a PLT. */
|
---|
1966 | plt = true;
|
---|
1967 | }
|
---|
1968 | }
|
---|
1969 | else if (strncmp (name, ".rela", 5) == 0)
|
---|
1970 | {
|
---|
1971 | if (s->_raw_size == 0)
|
---|
1972 | {
|
---|
1973 | /* If we don't need this section, strip it from the
|
---|
1974 | output file. This is mostly to handle .rela.bss and
|
---|
1975 | .rela.plt. We must create both sections in
|
---|
1976 | create_dynamic_sections, because they must be created
|
---|
1977 | before the linker maps input sections to output
|
---|
1978 | sections. The linker does that before
|
---|
1979 | adjust_dynamic_symbol is called, and it is that
|
---|
1980 | function which decides whether anything needs to go
|
---|
1981 | into these sections. */
|
---|
1982 | strip = true;
|
---|
1983 | }
|
---|
1984 | else
|
---|
1985 | {
|
---|
1986 | asection *target;
|
---|
1987 | const char *outname;
|
---|
1988 |
|
---|
1989 | /* Remember whether there are any relocation sections. */
|
---|
1990 | relocs = true;
|
---|
1991 |
|
---|
1992 | /* If this relocation section applies to a read only
|
---|
1993 | section, then we probably need a DT_TEXTREL entry. */
|
---|
1994 | outname = bfd_get_section_name (output_bfd,
|
---|
1995 | s->output_section);
|
---|
1996 | target = bfd_get_section_by_name (output_bfd, outname + 5);
|
---|
1997 | if (target != NULL
|
---|
1998 | && (target->flags & SEC_READONLY) != 0
|
---|
1999 | && (target->flags & SEC_ALLOC) != 0)
|
---|
2000 | reltext = true;
|
---|
2001 |
|
---|
2002 | /* We use the reloc_count field as a counter if we need
|
---|
2003 | to copy relocs into the output file. */
|
---|
2004 | s->reloc_count = 0;
|
---|
2005 | }
|
---|
2006 | }
|
---|
2007 | else if (strcmp (name, ".got") != 0
|
---|
2008 | && strcmp (name, ".sdata") != 0
|
---|
2009 | && strcmp (name, ".sdata2") != 0)
|
---|
2010 | {
|
---|
2011 | /* It's not one of our sections, so don't allocate space. */
|
---|
2012 | continue;
|
---|
2013 | }
|
---|
2014 |
|
---|
2015 | if (strip)
|
---|
2016 | {
|
---|
2017 | _bfd_strip_section_from_output (info, s);
|
---|
2018 | continue;
|
---|
2019 | }
|
---|
2020 |
|
---|
2021 | /* Allocate memory for the section contents. */
|
---|
2022 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
|
---|
2023 | if (s->contents == NULL && s->_raw_size != 0)
|
---|
2024 | return false;
|
---|
2025 | }
|
---|
2026 |
|
---|
2027 | if (elf_hash_table (info)->dynamic_sections_created)
|
---|
2028 | {
|
---|
2029 | /* Add some entries to the .dynamic section. We fill in the
|
---|
2030 | values later, in ppc_elf_finish_dynamic_sections, but we
|
---|
2031 | must add the entries now so that we get the correct size for
|
---|
2032 | the .dynamic section. The DT_DEBUG entry is filled in by the
|
---|
2033 | dynamic linker and used by the debugger. */
|
---|
2034 | if (! info->shared)
|
---|
2035 | {
|
---|
2036 | if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
|
---|
2037 | return false;
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | if (plt)
|
---|
2041 | {
|
---|
2042 | if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
|
---|
2043 | || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
|
---|
2044 | || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
|
---|
2045 | || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
|
---|
2046 | return false;
|
---|
2047 | }
|
---|
2048 |
|
---|
2049 | if (relocs)
|
---|
2050 | {
|
---|
2051 | if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
|
---|
2052 | || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
|
---|
2053 | || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
|
---|
2054 | sizeof (Elf32_External_Rela)))
|
---|
2055 | return false;
|
---|
2056 | }
|
---|
2057 |
|
---|
2058 | if (reltext)
|
---|
2059 | {
|
---|
2060 | if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
|
---|
2061 | return false;
|
---|
2062 | info->flags |= DF_TEXTREL;
|
---|
2063 | }
|
---|
2064 | }
|
---|
2065 |
|
---|
2066 | return true;
|
---|
2067 | }
|
---|
2068 | |
---|
2069 |
|
---|
2070 | /* Look through the relocs for a section during the first phase, and
|
---|
2071 | allocate space in the global offset table or procedure linkage
|
---|
2072 | table. */
|
---|
2073 |
|
---|
2074 | static boolean
|
---|
2075 | ppc_elf_check_relocs (abfd, info, sec, relocs)
|
---|
2076 | bfd *abfd;
|
---|
2077 | struct bfd_link_info *info;
|
---|
2078 | asection *sec;
|
---|
2079 | const Elf_Internal_Rela *relocs;
|
---|
2080 | {
|
---|
2081 | bfd *dynobj;
|
---|
2082 | Elf_Internal_Shdr *symtab_hdr;
|
---|
2083 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
|
---|
2084 | const Elf_Internal_Rela *rel;
|
---|
2085 | const Elf_Internal_Rela *rel_end;
|
---|
2086 | bfd_signed_vma *local_got_refcounts;
|
---|
2087 | elf_linker_section_t *sdata;
|
---|
2088 | elf_linker_section_t *sdata2;
|
---|
2089 | asection *sreloc;
|
---|
2090 | asection *sgot = NULL;
|
---|
2091 | asection *srelgot = NULL;
|
---|
2092 |
|
---|
2093 | if (info->relocateable)
|
---|
2094 | return true;
|
---|
2095 |
|
---|
2096 | #ifdef DEBUG
|
---|
2097 | fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
|
---|
2098 | bfd_get_section_name (abfd, sec),
|
---|
2099 | bfd_get_filename (abfd));
|
---|
2100 | #endif
|
---|
2101 |
|
---|
2102 | /* Create the linker generated sections all the time so that the
|
---|
2103 | special symbols are created. */
|
---|
2104 |
|
---|
2105 | if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
|
---|
2106 | {
|
---|
2107 | sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
|
---|
2108 | if (!sdata)
|
---|
2109 | return false;
|
---|
2110 | }
|
---|
2111 |
|
---|
2112 | if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
|
---|
2113 | {
|
---|
2114 | sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
|
---|
2115 | if (!sdata2)
|
---|
2116 | return false;
|
---|
2117 | }
|
---|
2118 |
|
---|
2119 | dynobj = elf_hash_table (info)->dynobj;
|
---|
2120 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
---|
2121 | local_got_refcounts = elf_local_got_refcounts (abfd);
|
---|
2122 |
|
---|
2123 | sym_hashes = elf_sym_hashes (abfd);
|
---|
2124 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
|
---|
2125 | if (!elf_bad_symtab (abfd))
|
---|
2126 | sym_hashes_end -= symtab_hdr->sh_info;
|
---|
2127 |
|
---|
2128 | sreloc = NULL;
|
---|
2129 |
|
---|
2130 | rel_end = relocs + sec->reloc_count;
|
---|
2131 | for (rel = relocs; rel < rel_end; rel++)
|
---|
2132 | {
|
---|
2133 | unsigned long r_symndx;
|
---|
2134 | struct elf_link_hash_entry *h;
|
---|
2135 |
|
---|
2136 | r_symndx = ELF32_R_SYM (rel->r_info);
|
---|
2137 | if (r_symndx < symtab_hdr->sh_info)
|
---|
2138 | h = NULL;
|
---|
2139 | else
|
---|
2140 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
2141 |
|
---|
2142 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
|
---|
2143 | This shows up in particular in an R_PPC_ADDR32 in the eabi
|
---|
2144 | startup code. */
|
---|
2145 | if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
|
---|
2146 | {
|
---|
2147 | if (sgot == NULL)
|
---|
2148 | {
|
---|
2149 | if (dynobj == NULL)
|
---|
2150 | elf_hash_table (info)->dynobj = dynobj = abfd;
|
---|
2151 | if (! _bfd_elf_create_got_section (dynobj, info))
|
---|
2152 | return false;
|
---|
2153 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2154 | BFD_ASSERT (sgot != NULL);
|
---|
2155 | }
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 | switch (ELF32_R_TYPE (rel->r_info))
|
---|
2159 | {
|
---|
2160 | /* GOT16 relocations */
|
---|
2161 | case R_PPC_GOT16:
|
---|
2162 | case R_PPC_GOT16_LO:
|
---|
2163 | case R_PPC_GOT16_HI:
|
---|
2164 | case R_PPC_GOT16_HA:
|
---|
2165 | /* This symbol requires a global offset table entry. */
|
---|
2166 |
|
---|
2167 | if (sgot == NULL)
|
---|
2168 | {
|
---|
2169 | if (dynobj == NULL)
|
---|
2170 | elf_hash_table (info)->dynobj = dynobj = abfd;
|
---|
2171 | if (! _bfd_elf_create_got_section (dynobj, info))
|
---|
2172 | return false;
|
---|
2173 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2174 | BFD_ASSERT (sgot != NULL);
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | if (srelgot == NULL
|
---|
2178 | && (h != NULL || info->shared))
|
---|
2179 | {
|
---|
2180 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
2181 | if (srelgot == NULL)
|
---|
2182 | {
|
---|
2183 | srelgot = bfd_make_section (dynobj, ".rela.got");
|
---|
2184 | if (srelgot == NULL
|
---|
2185 | || ! bfd_set_section_flags (dynobj, srelgot,
|
---|
2186 | (SEC_ALLOC
|
---|
2187 | | SEC_LOAD
|
---|
2188 | | SEC_HAS_CONTENTS
|
---|
2189 | | SEC_IN_MEMORY
|
---|
2190 | | SEC_LINKER_CREATED
|
---|
2191 | | SEC_READONLY))
|
---|
2192 | || ! bfd_set_section_alignment (dynobj, srelgot, 2))
|
---|
2193 | return false;
|
---|
2194 | }
|
---|
2195 | }
|
---|
2196 |
|
---|
2197 | if (h != NULL)
|
---|
2198 | {
|
---|
2199 | if (h->got.refcount == -1)
|
---|
2200 | {
|
---|
2201 | /* Make sure this symbol is output as a dynamic symbol. */
|
---|
2202 | if (h->dynindx == -1)
|
---|
2203 | if (!bfd_elf32_link_record_dynamic_symbol (info, h))
|
---|
2204 | return false;
|
---|
2205 |
|
---|
2206 | /* Allocate space in the .got. */
|
---|
2207 | sgot->_raw_size += 4;
|
---|
2208 | /* Allocate relocation space. */
|
---|
2209 | srelgot->_raw_size += sizeof (Elf32_External_Rela);
|
---|
2210 |
|
---|
2211 | h->got.refcount = 1;
|
---|
2212 | }
|
---|
2213 | else
|
---|
2214 | h->got.refcount++;
|
---|
2215 | }
|
---|
2216 | else
|
---|
2217 | {
|
---|
2218 | /* This is a global offset table entry for a local symbol. */
|
---|
2219 | if (local_got_refcounts == NULL)
|
---|
2220 | {
|
---|
2221 | size_t size;
|
---|
2222 |
|
---|
2223 | size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
|
---|
2224 | local_got_refcounts = (bfd_signed_vma *)
|
---|
2225 | bfd_alloc (abfd, size);
|
---|
2226 | if (local_got_refcounts == NULL)
|
---|
2227 | return false;
|
---|
2228 | elf_local_got_refcounts (abfd) = local_got_refcounts;
|
---|
2229 | memset (local_got_refcounts, -1, size);
|
---|
2230 | }
|
---|
2231 | if (local_got_refcounts[r_symndx] == -1)
|
---|
2232 | {
|
---|
2233 | sgot->_raw_size += 4;
|
---|
2234 |
|
---|
2235 | /* If we are generating a shared object, we need to
|
---|
2236 | output a R_PPC_RELATIVE reloc so that the
|
---|
2237 | dynamic linker can adjust this GOT entry. */
|
---|
2238 | if (info->shared)
|
---|
2239 | srelgot->_raw_size += sizeof (Elf32_External_Rela);
|
---|
2240 |
|
---|
2241 | local_got_refcounts[r_symndx] = 1;
|
---|
2242 | }
|
---|
2243 | else
|
---|
2244 | local_got_refcounts[r_symndx]++;
|
---|
2245 | }
|
---|
2246 | break;
|
---|
2247 |
|
---|
2248 | /* Indirect .sdata relocation */
|
---|
2249 | case R_PPC_EMB_SDAI16:
|
---|
2250 | if (info->shared)
|
---|
2251 | {
|
---|
2252 | ((*_bfd_error_handler)
|
---|
2253 | (_("%s: relocation %s cannot be used when making a shared object"),
|
---|
2254 | bfd_get_filename (abfd), "R_PPC_EMB_SDAI16"));
|
---|
2255 | return false;
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | if (srelgot == NULL && (h != NULL || info->shared))
|
---|
2259 | {
|
---|
2260 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
2261 | if (srelgot == NULL)
|
---|
2262 | {
|
---|
2263 | srelgot = bfd_make_section (dynobj, ".rela.got");
|
---|
2264 | if (srelgot == NULL
|
---|
2265 | || ! bfd_set_section_flags (dynobj, srelgot,
|
---|
2266 | (SEC_ALLOC
|
---|
2267 | | SEC_LOAD
|
---|
2268 | | SEC_HAS_CONTENTS
|
---|
2269 | | SEC_IN_MEMORY
|
---|
2270 | | SEC_LINKER_CREATED
|
---|
2271 | | SEC_READONLY))
|
---|
2272 | || ! bfd_set_section_alignment (dynobj, srelgot, 2))
|
---|
2273 | return false;
|
---|
2274 | }
|
---|
2275 | }
|
---|
2276 |
|
---|
2277 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
|
---|
2278 | return false;
|
---|
2279 |
|
---|
2280 | break;
|
---|
2281 |
|
---|
2282 | /* Indirect .sdata2 relocation */
|
---|
2283 | case R_PPC_EMB_SDA2I16:
|
---|
2284 | if (info->shared)
|
---|
2285 | {
|
---|
2286 | ((*_bfd_error_handler)
|
---|
2287 | (_("%s: relocation %s cannot be used when making a shared object"),
|
---|
2288 | bfd_get_filename (abfd), "R_PPC_EMB_SDA2I16"));
|
---|
2289 | return false;
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 | if (srelgot == NULL && (h != NULL || info->shared))
|
---|
2293 | {
|
---|
2294 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
2295 | if (srelgot == NULL)
|
---|
2296 | {
|
---|
2297 | srelgot = bfd_make_section (dynobj, ".rela.got");
|
---|
2298 | if (srelgot == NULL
|
---|
2299 | || ! bfd_set_section_flags (dynobj, srelgot,
|
---|
2300 | (SEC_ALLOC
|
---|
2301 | | SEC_LOAD
|
---|
2302 | | SEC_HAS_CONTENTS
|
---|
2303 | | SEC_IN_MEMORY
|
---|
2304 | | SEC_LINKER_CREATED
|
---|
2305 | | SEC_READONLY))
|
---|
2306 | || ! bfd_set_section_alignment (dynobj, srelgot, 2))
|
---|
2307 | return false;
|
---|
2308 | }
|
---|
2309 | }
|
---|
2310 |
|
---|
2311 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
|
---|
2312 | return false;
|
---|
2313 |
|
---|
2314 | break;
|
---|
2315 |
|
---|
2316 | case R_PPC_SDAREL16:
|
---|
2317 | case R_PPC_EMB_SDA2REL:
|
---|
2318 | case R_PPC_EMB_SDA21:
|
---|
2319 | if (info->shared)
|
---|
2320 | {
|
---|
2321 | ((*_bfd_error_handler)
|
---|
2322 | (_("%s: relocation %s cannot be used when making a shared object"),
|
---|
2323 | bfd_get_filename (abfd),
|
---|
2324 | ppc_elf_howto_table[(int) ELF32_R_TYPE (rel->r_info)]->name));
|
---|
2325 | return false;
|
---|
2326 | }
|
---|
2327 | break;
|
---|
2328 |
|
---|
2329 | case R_PPC_PLT32:
|
---|
2330 | case R_PPC_PLTREL24:
|
---|
2331 | case R_PPC_PLT16_LO:
|
---|
2332 | case R_PPC_PLT16_HI:
|
---|
2333 | case R_PPC_PLT16_HA:
|
---|
2334 | #ifdef DEBUG
|
---|
2335 | fprintf (stderr, "Reloc requires a PLT entry\n");
|
---|
2336 | #endif
|
---|
2337 | /* This symbol requires a procedure linkage table entry. We
|
---|
2338 | actually build the entry in adjust_dynamic_symbol,
|
---|
2339 | because this might be a case of linking PIC code without
|
---|
2340 | linking in any dynamic objects, in which case we don't
|
---|
2341 | need to generate a procedure linkage table after all. */
|
---|
2342 |
|
---|
2343 | if (h == NULL)
|
---|
2344 | {
|
---|
2345 | /* It does not make sense to have a procedure linkage
|
---|
2346 | table entry for a local symbol. */
|
---|
2347 | bfd_set_error (bfd_error_bad_value);
|
---|
2348 | return false;
|
---|
2349 | }
|
---|
2350 |
|
---|
2351 | /* Make sure this symbol is output as a dynamic symbol. */
|
---|
2352 | if (h->dynindx == -1)
|
---|
2353 | {
|
---|
2354 | if (! bfd_elf32_link_record_dynamic_symbol (info, h))
|
---|
2355 | return false;
|
---|
2356 | }
|
---|
2357 | if (h->plt.refcount == -1)
|
---|
2358 | {
|
---|
2359 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
---|
2360 | h->plt.refcount = 1;
|
---|
2361 | }
|
---|
2362 | else
|
---|
2363 | h->plt.refcount++;
|
---|
2364 | break;
|
---|
2365 |
|
---|
2366 | /* The following relocations don't need to propagate the
|
---|
2367 | relocation if linking a shared object since they are
|
---|
2368 | section relative. */
|
---|
2369 | case R_PPC_SECTOFF:
|
---|
2370 | case R_PPC_SECTOFF_LO:
|
---|
2371 | case R_PPC_SECTOFF_HI:
|
---|
2372 | case R_PPC_SECTOFF_HA:
|
---|
2373 | break;
|
---|
2374 |
|
---|
2375 | /* This refers only to functions defined in the shared library */
|
---|
2376 | case R_PPC_LOCAL24PC:
|
---|
2377 | break;
|
---|
2378 |
|
---|
2379 | /* This relocation describes the C++ object vtable hierarchy.
|
---|
2380 | Reconstruct it for later use during GC. */
|
---|
2381 | case R_PPC_GNU_VTINHERIT:
|
---|
2382 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
|
---|
2383 | return false;
|
---|
2384 | break;
|
---|
2385 |
|
---|
2386 | /* This relocation describes which C++ vtable entries are actually
|
---|
2387 | used. Record for later use during GC. */
|
---|
2388 | case R_PPC_GNU_VTENTRY:
|
---|
2389 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
|
---|
2390 | return false;
|
---|
2391 | break;
|
---|
2392 |
|
---|
2393 | /* When creating a shared object, we must copy these
|
---|
2394 | relocs into the output file. We create a reloc
|
---|
2395 | section in dynobj and make room for the reloc. */
|
---|
2396 | case R_PPC_REL24:
|
---|
2397 | case R_PPC_REL14:
|
---|
2398 | case R_PPC_REL14_BRTAKEN:
|
---|
2399 | case R_PPC_REL14_BRNTAKEN:
|
---|
2400 | case R_PPC_REL32:
|
---|
2401 | if (h == NULL
|
---|
2402 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
|
---|
2403 | || SYMBOL_REFERENCES_LOCAL (info, h))
|
---|
2404 | break;
|
---|
2405 | /* fall through */
|
---|
2406 |
|
---|
2407 | default:
|
---|
2408 | if (info->shared)
|
---|
2409 | {
|
---|
2410 | #ifdef DEBUG
|
---|
2411 | fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
|
---|
2412 | (h && h->root.root.string) ? h->root.root.string : "<unknown>");
|
---|
2413 | #endif
|
---|
2414 | if (sreloc == NULL)
|
---|
2415 | {
|
---|
2416 | const char *name;
|
---|
2417 |
|
---|
2418 | name = (bfd_elf_string_from_elf_section
|
---|
2419 | (abfd,
|
---|
2420 | elf_elfheader (abfd)->e_shstrndx,
|
---|
2421 | elf_section_data (sec)->rel_hdr.sh_name));
|
---|
2422 | if (name == NULL)
|
---|
2423 | return false;
|
---|
2424 |
|
---|
2425 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
---|
2426 | && strcmp (bfd_get_section_name (abfd, sec),
|
---|
2427 | name + 5) == 0);
|
---|
2428 |
|
---|
2429 | sreloc = bfd_get_section_by_name (dynobj, name);
|
---|
2430 | if (sreloc == NULL)
|
---|
2431 | {
|
---|
2432 | flagword flags;
|
---|
2433 |
|
---|
2434 | sreloc = bfd_make_section (dynobj, name);
|
---|
2435 | flags = (SEC_HAS_CONTENTS | SEC_READONLY
|
---|
2436 | | SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
---|
2437 | if ((sec->flags & SEC_ALLOC) != 0)
|
---|
2438 | flags |= SEC_ALLOC | SEC_LOAD;
|
---|
2439 | if (sreloc == NULL
|
---|
2440 | || ! bfd_set_section_flags (dynobj, sreloc, flags)
|
---|
2441 | || ! bfd_set_section_alignment (dynobj, sreloc, 2))
|
---|
2442 | return false;
|
---|
2443 | }
|
---|
2444 | }
|
---|
2445 |
|
---|
2446 | sreloc->_raw_size += sizeof (Elf32_External_Rela);
|
---|
2447 |
|
---|
2448 | /* FIXME: We should here do what the m68k and i386
|
---|
2449 | backends do: if the reloc is pc-relative, record it
|
---|
2450 | in case it turns out that the reloc is unnecessary
|
---|
2451 | because the symbol is forced local by versioning or
|
---|
2452 | we are linking with -Bdynamic. Fortunately this
|
---|
2453 | case is not frequent. */
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | break;
|
---|
2457 | }
|
---|
2458 | }
|
---|
2459 |
|
---|
2460 | return true;
|
---|
2461 | }
|
---|
2462 |
|
---|
2463 | /* Return the section that should be marked against GC for a given
|
---|
2464 | relocation. */
|
---|
2465 |
|
---|
2466 | static asection *
|
---|
2467 | ppc_elf_gc_mark_hook (abfd, info, rel, h, sym)
|
---|
2468 | bfd *abfd;
|
---|
2469 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
---|
2470 | Elf_Internal_Rela *rel;
|
---|
2471 | struct elf_link_hash_entry *h;
|
---|
2472 | Elf_Internal_Sym *sym;
|
---|
2473 | {
|
---|
2474 | if (h != NULL)
|
---|
2475 | {
|
---|
2476 | switch (ELF32_R_TYPE (rel->r_info))
|
---|
2477 | {
|
---|
2478 | case R_PPC_GNU_VTINHERIT:
|
---|
2479 | case R_PPC_GNU_VTENTRY:
|
---|
2480 | break;
|
---|
2481 |
|
---|
2482 | default:
|
---|
2483 | switch (h->root.type)
|
---|
2484 | {
|
---|
2485 | case bfd_link_hash_defined:
|
---|
2486 | case bfd_link_hash_defweak:
|
---|
2487 | return h->root.u.def.section;
|
---|
2488 |
|
---|
2489 | case bfd_link_hash_common:
|
---|
2490 | return h->root.u.c.p->section;
|
---|
2491 |
|
---|
2492 | default:
|
---|
2493 | break;
|
---|
2494 | }
|
---|
2495 | }
|
---|
2496 | }
|
---|
2497 | else
|
---|
2498 | {
|
---|
2499 | if (!(elf_bad_symtab (abfd)
|
---|
2500 | && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
|
---|
2501 | && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
|
---|
2502 | && sym->st_shndx != SHN_COMMON))
|
---|
2503 | {
|
---|
2504 | return bfd_section_from_elf_index (abfd, sym->st_shndx);
|
---|
2505 | }
|
---|
2506 | }
|
---|
2507 |
|
---|
2508 | return NULL;
|
---|
2509 | }
|
---|
2510 |
|
---|
2511 | /* Update the got entry reference counts for the section being removed. */
|
---|
2512 |
|
---|
2513 | static boolean
|
---|
2514 | ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
|
---|
2515 | bfd *abfd;
|
---|
2516 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
---|
2517 | asection *sec;
|
---|
2518 | const Elf_Internal_Rela *relocs;
|
---|
2519 | {
|
---|
2520 | Elf_Internal_Shdr *symtab_hdr;
|
---|
2521 | struct elf_link_hash_entry **sym_hashes;
|
---|
2522 | bfd_signed_vma *local_got_refcounts;
|
---|
2523 | const Elf_Internal_Rela *rel, *relend;
|
---|
2524 | unsigned long r_symndx;
|
---|
2525 | struct elf_link_hash_entry *h;
|
---|
2526 |
|
---|
2527 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
---|
2528 | sym_hashes = elf_sym_hashes (abfd);
|
---|
2529 | local_got_refcounts = elf_local_got_refcounts (abfd);
|
---|
2530 |
|
---|
2531 | relend = relocs + sec->reloc_count;
|
---|
2532 | for (rel = relocs; rel < relend; rel++)
|
---|
2533 | switch (ELF32_R_TYPE (rel->r_info))
|
---|
2534 | {
|
---|
2535 | case R_PPC_GOT16:
|
---|
2536 | case R_PPC_GOT16_LO:
|
---|
2537 | case R_PPC_GOT16_HI:
|
---|
2538 | case R_PPC_GOT16_HA:
|
---|
2539 | r_symndx = ELF32_R_SYM (rel->r_info);
|
---|
2540 | if (r_symndx >= symtab_hdr->sh_info)
|
---|
2541 | {
|
---|
2542 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
2543 | if (h->got.refcount > 0)
|
---|
2544 | h->got.refcount--;
|
---|
2545 | }
|
---|
2546 | else if (local_got_refcounts != NULL)
|
---|
2547 | {
|
---|
2548 | if (local_got_refcounts[r_symndx] > 0)
|
---|
2549 | local_got_refcounts[r_symndx]--;
|
---|
2550 | }
|
---|
2551 | break;
|
---|
2552 |
|
---|
2553 | case R_PPC_PLT32:
|
---|
2554 | case R_PPC_PLTREL24:
|
---|
2555 | case R_PPC_PLT16_LO:
|
---|
2556 | case R_PPC_PLT16_HI:
|
---|
2557 | case R_PPC_PLT16_HA:
|
---|
2558 | r_symndx = ELF32_R_SYM (rel->r_info);
|
---|
2559 | if (r_symndx >= symtab_hdr->sh_info)
|
---|
2560 | {
|
---|
2561 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
2562 | if (h->plt.refcount > 0)
|
---|
2563 | h->plt.refcount--;
|
---|
2564 | }
|
---|
2565 | break;
|
---|
2566 |
|
---|
2567 | default:
|
---|
2568 | break;
|
---|
2569 | }
|
---|
2570 |
|
---|
2571 | return true;
|
---|
2572 | }
|
---|
2573 | |
---|
2574 |
|
---|
2575 | /* Hook called by the linker routine which adds symbols from an object
|
---|
2576 | file. We use it to put .comm items in .sbss, and not .bss. */
|
---|
2577 |
|
---|
2578 | static boolean
|
---|
2579 | ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
|
---|
2580 | bfd *abfd;
|
---|
2581 | struct bfd_link_info *info;
|
---|
2582 | const Elf_Internal_Sym *sym;
|
---|
2583 | const char **namep ATTRIBUTE_UNUSED;
|
---|
2584 | flagword *flagsp ATTRIBUTE_UNUSED;
|
---|
2585 | asection **secp;
|
---|
2586 | bfd_vma *valp;
|
---|
2587 | {
|
---|
2588 | if (sym->st_shndx == SHN_COMMON
|
---|
2589 | && !info->relocateable
|
---|
2590 | && sym->st_size <= (bfd_vma) bfd_get_gp_size (abfd))
|
---|
2591 | {
|
---|
2592 | /* Common symbols less than or equal to -G nn bytes are automatically
|
---|
2593 | put into .sdata. */
|
---|
2594 | elf_linker_section_t *sdata
|
---|
2595 | = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
|
---|
2596 |
|
---|
2597 | if (!sdata->bss_section)
|
---|
2598 | {
|
---|
2599 | /* We don't go through bfd_make_section, because we don't
|
---|
2600 | want to attach this common section to DYNOBJ. The linker
|
---|
2601 | will move the symbols to the appropriate output section
|
---|
2602 | when it defines common symbols. */
|
---|
2603 | sdata->bss_section = ((asection *)
|
---|
2604 | bfd_zalloc (abfd, sizeof (asection)));
|
---|
2605 | if (sdata->bss_section == NULL)
|
---|
2606 | return false;
|
---|
2607 | sdata->bss_section->name = sdata->bss_name;
|
---|
2608 | sdata->bss_section->flags = SEC_IS_COMMON;
|
---|
2609 | sdata->bss_section->output_section = sdata->bss_section;
|
---|
2610 | sdata->bss_section->symbol =
|
---|
2611 | (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
|
---|
2612 | sdata->bss_section->symbol_ptr_ptr =
|
---|
2613 | (asymbol **) bfd_zalloc (abfd, sizeof (asymbol *));
|
---|
2614 | if (sdata->bss_section->symbol == NULL
|
---|
2615 | || sdata->bss_section->symbol_ptr_ptr == NULL)
|
---|
2616 | return false;
|
---|
2617 | sdata->bss_section->symbol->name = sdata->bss_name;
|
---|
2618 | sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
|
---|
2619 | sdata->bss_section->symbol->section = sdata->bss_section;
|
---|
2620 | *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol;
|
---|
2621 | }
|
---|
2622 |
|
---|
2623 | *secp = sdata->bss_section;
|
---|
2624 | *valp = sym->st_size;
|
---|
2625 | }
|
---|
2626 |
|
---|
2627 | return true;
|
---|
2628 | }
|
---|
2629 | |
---|
2630 |
|
---|
2631 | /* Finish up dynamic symbol handling. We set the contents of various
|
---|
2632 | dynamic sections here. */
|
---|
2633 |
|
---|
2634 | static boolean
|
---|
2635 | ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
|
---|
2636 | bfd *output_bfd;
|
---|
2637 | struct bfd_link_info *info;
|
---|
2638 | struct elf_link_hash_entry *h;
|
---|
2639 | Elf_Internal_Sym *sym;
|
---|
2640 | {
|
---|
2641 | bfd *dynobj;
|
---|
2642 |
|
---|
2643 | #ifdef DEBUG
|
---|
2644 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
|
---|
2645 | h->root.root.string);
|
---|
2646 | #endif
|
---|
2647 |
|
---|
2648 | dynobj = elf_hash_table (info)->dynobj;
|
---|
2649 | BFD_ASSERT (dynobj != NULL);
|
---|
2650 |
|
---|
2651 | if (h->plt.offset != (bfd_vma) -1)
|
---|
2652 | {
|
---|
2653 | asection *splt;
|
---|
2654 | asection *srela;
|
---|
2655 | Elf_Internal_Rela rela;
|
---|
2656 | bfd_vma reloc_index;
|
---|
2657 |
|
---|
2658 | #ifdef DEBUG
|
---|
2659 | fprintf (stderr, ", plt_offset = %d", h->plt.offset);
|
---|
2660 | #endif
|
---|
2661 |
|
---|
2662 | /* This symbol has an entry in the procedure linkage table. Set
|
---|
2663 | it up. */
|
---|
2664 |
|
---|
2665 | BFD_ASSERT (h->dynindx != -1);
|
---|
2666 |
|
---|
2667 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
---|
2668 | srela = bfd_get_section_by_name (dynobj, ".rela.plt");
|
---|
2669 | BFD_ASSERT (splt != NULL && srela != NULL);
|
---|
2670 |
|
---|
2671 | /* We don't need to fill in the .plt. The ppc dynamic linker
|
---|
2672 | will fill it in. */
|
---|
2673 |
|
---|
2674 | /* Fill in the entry in the .rela.plt section. */
|
---|
2675 | rela.r_offset = (splt->output_section->vma
|
---|
2676 | + splt->output_offset
|
---|
2677 | + h->plt.offset);
|
---|
2678 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
|
---|
2679 | rela.r_addend = 0;
|
---|
2680 |
|
---|
2681 | reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE;
|
---|
2682 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
|
---|
2683 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
|
---|
2684 | bfd_elf32_swap_reloca_out (output_bfd, &rela,
|
---|
2685 | ((Elf32_External_Rela *) srela->contents
|
---|
2686 | + reloc_index));
|
---|
2687 |
|
---|
2688 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
---|
2689 | {
|
---|
2690 | /* Mark the symbol as undefined, rather than as defined in
|
---|
2691 | the .plt section. Leave the value alone. */
|
---|
2692 | sym->st_shndx = SHN_UNDEF;
|
---|
2693 | /* If the symbol is weak, we do need to clear the value.
|
---|
2694 | Otherwise, the PLT entry would provide a definition for
|
---|
2695 | the symbol even if the symbol wasn't defined anywhere,
|
---|
2696 | and so the symbol would never be NULL. */
|
---|
2697 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
|
---|
2698 | == 0)
|
---|
2699 | sym->st_value = 0;
|
---|
2700 | }
|
---|
2701 | }
|
---|
2702 |
|
---|
2703 | if (h->got.offset != (bfd_vma) -1)
|
---|
2704 | {
|
---|
2705 | asection *sgot;
|
---|
2706 | asection *srela;
|
---|
2707 | Elf_Internal_Rela rela;
|
---|
2708 |
|
---|
2709 | /* This symbol has an entry in the global offset table. Set it
|
---|
2710 | up. */
|
---|
2711 |
|
---|
2712 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2713 | srela = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
2714 | BFD_ASSERT (sgot != NULL && srela != NULL);
|
---|
2715 |
|
---|
2716 | rela.r_offset = (sgot->output_section->vma
|
---|
2717 | + sgot->output_offset
|
---|
2718 | + (h->got.offset &~ 1));
|
---|
2719 |
|
---|
2720 | /* If this is a -Bsymbolic link, and the symbol is defined
|
---|
2721 | locally, we just want to emit a RELATIVE reloc. The entry in
|
---|
2722 | the global offset table will already have been initialized in
|
---|
2723 | the relocate_section function. */
|
---|
2724 | if (info->shared
|
---|
2725 | && SYMBOL_REFERENCES_LOCAL (info, h))
|
---|
2726 | {
|
---|
2727 | rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
|
---|
2728 | rela.r_addend = (h->root.u.def.value
|
---|
2729 | + h->root.u.def.section->output_section->vma
|
---|
2730 | + h->root.u.def.section->output_offset);
|
---|
2731 | }
|
---|
2732 | else
|
---|
2733 | {
|
---|
2734 | BFD_ASSERT ((h->got.offset & 1) == 0);
|
---|
2735 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
|
---|
2736 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT);
|
---|
2737 | rela.r_addend = 0;
|
---|
2738 | }
|
---|
2739 |
|
---|
2740 | bfd_elf32_swap_reloca_out (output_bfd, &rela,
|
---|
2741 | ((Elf32_External_Rela *) srela->contents
|
---|
2742 | + srela->reloc_count));
|
---|
2743 | ++srela->reloc_count;
|
---|
2744 | }
|
---|
2745 |
|
---|
2746 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
|
---|
2747 | {
|
---|
2748 | asection *s;
|
---|
2749 | Elf_Internal_Rela rela;
|
---|
2750 |
|
---|
2751 | /* This symbols needs a copy reloc. Set it up. */
|
---|
2752 |
|
---|
2753 | #ifdef DEBUG
|
---|
2754 | fprintf (stderr, ", copy");
|
---|
2755 | #endif
|
---|
2756 |
|
---|
2757 | BFD_ASSERT (h->dynindx != -1);
|
---|
2758 |
|
---|
2759 | if (h->size <= elf_gp_size (dynobj))
|
---|
2760 | s = bfd_get_section_by_name (h->root.u.def.section->owner,
|
---|
2761 | ".rela.sbss");
|
---|
2762 | else
|
---|
2763 | s = bfd_get_section_by_name (h->root.u.def.section->owner,
|
---|
2764 | ".rela.bss");
|
---|
2765 | BFD_ASSERT (s != NULL);
|
---|
2766 |
|
---|
2767 | rela.r_offset = (h->root.u.def.value
|
---|
2768 | + h->root.u.def.section->output_section->vma
|
---|
2769 | + h->root.u.def.section->output_offset);
|
---|
2770 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
|
---|
2771 | rela.r_addend = 0;
|
---|
2772 | bfd_elf32_swap_reloca_out (output_bfd, &rela,
|
---|
2773 | ((Elf32_External_Rela *) s->contents
|
---|
2774 | + s->reloc_count));
|
---|
2775 | ++s->reloc_count;
|
---|
2776 | }
|
---|
2777 |
|
---|
2778 | #ifdef DEBUG
|
---|
2779 | fprintf (stderr, "\n");
|
---|
2780 | #endif
|
---|
2781 |
|
---|
2782 | /* Mark some specially defined symbols as absolute. */
|
---|
2783 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0
|
---|
2784 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
|
---|
2785 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
|
---|
2786 | sym->st_shndx = SHN_ABS;
|
---|
2787 |
|
---|
2788 | return true;
|
---|
2789 | }
|
---|
2790 | |
---|
2791 |
|
---|
2792 | /* Finish up the dynamic sections. */
|
---|
2793 |
|
---|
2794 | static boolean
|
---|
2795 | ppc_elf_finish_dynamic_sections (output_bfd, info)
|
---|
2796 | bfd *output_bfd;
|
---|
2797 | struct bfd_link_info *info;
|
---|
2798 | {
|
---|
2799 | asection *sdyn;
|
---|
2800 | bfd *dynobj = elf_hash_table (info)->dynobj;
|
---|
2801 | asection *sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2802 |
|
---|
2803 | #ifdef DEBUG
|
---|
2804 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
|
---|
2805 | #endif
|
---|
2806 |
|
---|
2807 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
|
---|
2808 |
|
---|
2809 | if (elf_hash_table (info)->dynamic_sections_created)
|
---|
2810 | {
|
---|
2811 | asection *splt;
|
---|
2812 | Elf32_External_Dyn *dyncon, *dynconend;
|
---|
2813 |
|
---|
2814 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
---|
2815 | BFD_ASSERT (splt != NULL && sdyn != NULL);
|
---|
2816 |
|
---|
2817 | dyncon = (Elf32_External_Dyn *) sdyn->contents;
|
---|
2818 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
|
---|
2819 | for (; dyncon < dynconend; dyncon++)
|
---|
2820 | {
|
---|
2821 | Elf_Internal_Dyn dyn;
|
---|
2822 | const char *name;
|
---|
2823 | boolean size;
|
---|
2824 |
|
---|
2825 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
|
---|
2826 |
|
---|
2827 | switch (dyn.d_tag)
|
---|
2828 | {
|
---|
2829 | case DT_PLTGOT: name = ".plt"; size = false; break;
|
---|
2830 | case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
|
---|
2831 | case DT_JMPREL: name = ".rela.plt"; size = false; break;
|
---|
2832 | default: name = NULL; size = false; break;
|
---|
2833 | }
|
---|
2834 |
|
---|
2835 | if (name != NULL)
|
---|
2836 | {
|
---|
2837 | asection *s;
|
---|
2838 |
|
---|
2839 | s = bfd_get_section_by_name (output_bfd, name);
|
---|
2840 | if (s == NULL)
|
---|
2841 | dyn.d_un.d_val = 0;
|
---|
2842 | else
|
---|
2843 | {
|
---|
2844 | if (! size)
|
---|
2845 | dyn.d_un.d_ptr = s->vma;
|
---|
2846 | else
|
---|
2847 | {
|
---|
2848 | if (s->_cooked_size != 0)
|
---|
2849 | dyn.d_un.d_val = s->_cooked_size;
|
---|
2850 | else
|
---|
2851 | dyn.d_un.d_val = s->_raw_size;
|
---|
2852 | }
|
---|
2853 | }
|
---|
2854 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
|
---|
2855 | }
|
---|
2856 | }
|
---|
2857 | }
|
---|
2858 |
|
---|
2859 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
|
---|
2860 | easily find the address of the _GLOBAL_OFFSET_TABLE_. */
|
---|
2861 | if (sgot)
|
---|
2862 | {
|
---|
2863 | unsigned char *contents = sgot->contents;
|
---|
2864 | bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
|
---|
2865 |
|
---|
2866 | if (sdyn == NULL)
|
---|
2867 | bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
|
---|
2868 | else
|
---|
2869 | bfd_put_32 (output_bfd,
|
---|
2870 | sdyn->output_section->vma + sdyn->output_offset,
|
---|
2871 | contents+4);
|
---|
2872 |
|
---|
2873 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
|
---|
2874 | }
|
---|
2875 |
|
---|
2876 | return true;
|
---|
2877 | }
|
---|
2878 | |
---|
2879 |
|
---|
2880 | /* The RELOCATE_SECTION function is called by the ELF backend linker
|
---|
2881 | to handle the relocations for a section.
|
---|
2882 |
|
---|
2883 | The relocs are always passed as Rela structures; if the section
|
---|
2884 | actually uses Rel structures, the r_addend field will always be
|
---|
2885 | zero.
|
---|
2886 |
|
---|
2887 | This function is responsible for adjust the section contents as
|
---|
2888 | necessary, and (if using Rela relocs and generating a
|
---|
2889 | relocateable output file) adjusting the reloc addend as
|
---|
2890 | necessary.
|
---|
2891 |
|
---|
2892 | This function does not have to worry about setting the reloc
|
---|
2893 | address or the reloc symbol index.
|
---|
2894 |
|
---|
2895 | LOCAL_SYMS is a pointer to the swapped in local symbols.
|
---|
2896 |
|
---|
2897 | LOCAL_SECTIONS is an array giving the section in the input file
|
---|
2898 | corresponding to the st_shndx field of each local symbol.
|
---|
2899 |
|
---|
2900 | The global hash table entry for the global symbols can be found
|
---|
2901 | via elf_sym_hashes (input_bfd).
|
---|
2902 |
|
---|
2903 | When generating relocateable output, this function must handle
|
---|
2904 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is
|
---|
2905 | going to be the section symbol corresponding to the output
|
---|
2906 | section, which means that the addend must be adjusted
|
---|
2907 | accordingly. */
|
---|
2908 |
|
---|
2909 | static boolean
|
---|
2910 | ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
|
---|
2911 | contents, relocs, local_syms, local_sections)
|
---|
2912 | bfd *output_bfd;
|
---|
2913 | struct bfd_link_info *info;
|
---|
2914 | bfd *input_bfd;
|
---|
2915 | asection *input_section;
|
---|
2916 | bfd_byte *contents;
|
---|
2917 | Elf_Internal_Rela *relocs;
|
---|
2918 | Elf_Internal_Sym *local_syms;
|
---|
2919 | asection **local_sections;
|
---|
2920 | {
|
---|
2921 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
|
---|
2922 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
|
---|
2923 | bfd *dynobj = elf_hash_table (info)->dynobj;
|
---|
2924 | elf_linker_section_t *sdata = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA) : NULL;
|
---|
2925 | elf_linker_section_t *sdata2 = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA2) : NULL;
|
---|
2926 | Elf_Internal_Rela *rel = relocs;
|
---|
2927 | Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
|
---|
2928 | asection *sreloc = NULL;
|
---|
2929 | asection *splt;
|
---|
2930 | asection *sgot;
|
---|
2931 | bfd_vma *local_got_offsets;
|
---|
2932 | boolean ret = true;
|
---|
2933 | long insn;
|
---|
2934 |
|
---|
2935 | #ifdef DEBUG
|
---|
2936 | fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
|
---|
2937 | bfd_get_filename (input_bfd),
|
---|
2938 | bfd_section_name(input_bfd, input_section),
|
---|
2939 | (long) input_section->reloc_count,
|
---|
2940 | (info->relocateable) ? " (relocatable)" : "");
|
---|
2941 | #endif
|
---|
2942 |
|
---|
2943 | if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
---|
2944 | /* Initialize howto table if needed. */
|
---|
2945 | ppc_elf_howto_init ();
|
---|
2946 |
|
---|
2947 | local_got_offsets = elf_local_got_offsets (input_bfd);
|
---|
2948 |
|
---|
2949 | splt = sgot = NULL;
|
---|
2950 | if (dynobj != NULL)
|
---|
2951 | {
|
---|
2952 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
---|
2953 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2954 | }
|
---|
2955 |
|
---|
2956 | for (; rel < relend; rel++)
|
---|
2957 | {
|
---|
2958 | enum elf_ppc_reloc_type r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
|
---|
2959 | bfd_vma offset = rel->r_offset;
|
---|
2960 | bfd_vma addend = rel->r_addend;
|
---|
2961 | bfd_reloc_status_type r = bfd_reloc_other;
|
---|
2962 | Elf_Internal_Sym *sym = (Elf_Internal_Sym *) 0;
|
---|
2963 | asection *sec = (asection *) 0;
|
---|
2964 | struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) 0;
|
---|
2965 | const char *sym_name = (const char *) 0;
|
---|
2966 | reloc_howto_type *howto;
|
---|
2967 | unsigned long r_symndx;
|
---|
2968 | bfd_vma relocation;
|
---|
2969 | int will_become_local;
|
---|
2970 |
|
---|
2971 | /* Unknown relocation handling */
|
---|
2972 | if ((unsigned) r_type >= (unsigned) R_PPC_max
|
---|
2973 | || !ppc_elf_howto_table[(int) r_type])
|
---|
2974 | {
|
---|
2975 | (*_bfd_error_handler) (_("%s: unknown relocation type %d"),
|
---|
2976 | bfd_get_filename (input_bfd),
|
---|
2977 | (int) r_type);
|
---|
2978 |
|
---|
2979 | bfd_set_error (bfd_error_bad_value);
|
---|
2980 | ret = false;
|
---|
2981 | continue;
|
---|
2982 | }
|
---|
2983 |
|
---|
2984 | howto = ppc_elf_howto_table[(int) r_type];
|
---|
2985 | r_symndx = ELF32_R_SYM (rel->r_info);
|
---|
2986 |
|
---|
2987 | if (info->relocateable)
|
---|
2988 | {
|
---|
2989 | /* This is a relocateable link. We don't have to change
|
---|
2990 | anything, unless the reloc is against a section symbol,
|
---|
2991 | in which case we have to adjust according to where the
|
---|
2992 | section symbol winds up in the output section. */
|
---|
2993 | if (r_symndx < symtab_hdr->sh_info)
|
---|
2994 | {
|
---|
2995 | sym = local_syms + r_symndx;
|
---|
2996 | if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
|
---|
2997 | {
|
---|
2998 | sec = local_sections[r_symndx];
|
---|
2999 | addend = rel->r_addend += sec->output_offset + sym->st_value;
|
---|
3000 | }
|
---|
3001 | }
|
---|
3002 |
|
---|
3003 | #ifdef DEBUG
|
---|
3004 | fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
|
---|
3005 | howto->name,
|
---|
3006 | (int) r_type,
|
---|
3007 | r_symndx,
|
---|
3008 | (long) offset,
|
---|
3009 | (long) addend);
|
---|
3010 | #endif
|
---|
3011 | continue;
|
---|
3012 | }
|
---|
3013 |
|
---|
3014 | /* This is a final link. */
|
---|
3015 | if (r_symndx < symtab_hdr->sh_info)
|
---|
3016 | {
|
---|
3017 | sym = local_syms + r_symndx;
|
---|
3018 | sec = local_sections[r_symndx];
|
---|
3019 | sym_name = "<local symbol>";
|
---|
3020 |
|
---|
3021 | relocation = (sec->output_section->vma
|
---|
3022 | + sec->output_offset
|
---|
3023 | + sym->st_value);
|
---|
3024 | /* Relocs to local symbols are always resolved. */
|
---|
3025 | will_become_local = 1;
|
---|
3026 | }
|
---|
3027 | else
|
---|
3028 | {
|
---|
3029 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
3030 | while (h->root.type == bfd_link_hash_indirect
|
---|
3031 | || h->root.type == bfd_link_hash_warning)
|
---|
3032 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
---|
3033 | sym_name = h->root.root.string;
|
---|
3034 |
|
---|
3035 | /* Can this relocation be resolved immediately? */
|
---|
3036 | will_become_local = SYMBOL_REFERENCES_LOCAL (info, h);
|
---|
3037 |
|
---|
3038 | if (h->root.type == bfd_link_hash_defined
|
---|
3039 | || h->root.type == bfd_link_hash_defweak)
|
---|
3040 | {
|
---|
3041 | sec = h->root.u.def.section;
|
---|
3042 | if (((r_type == R_PPC_PLT32
|
---|
3043 | || r_type == R_PPC_PLTREL24)
|
---|
3044 | && splt != NULL
|
---|
3045 | && h->plt.offset != (bfd_vma) -1)
|
---|
3046 | || (r_type == R_PPC_LOCAL24PC
|
---|
3047 | && sec->output_section == NULL)
|
---|
3048 | || ((r_type == R_PPC_GOT16
|
---|
3049 | || r_type == R_PPC_GOT16_LO
|
---|
3050 | || r_type == R_PPC_GOT16_HI
|
---|
3051 | || r_type == R_PPC_GOT16_HA)
|
---|
3052 | && elf_hash_table (info)->dynamic_sections_created
|
---|
3053 | && (! info->shared || ! will_become_local))
|
---|
3054 | || (info->shared
|
---|
3055 | && ! will_become_local
|
---|
3056 | && ((input_section->flags & SEC_ALLOC) != 0
|
---|
3057 | /* Testing SEC_DEBUGGING here may be wrong.
|
---|
3058 | It's here to avoid a crash when
|
---|
3059 | generating a shared library with DWARF
|
---|
3060 | debugging information. */
|
---|
3061 | || ((input_section->flags & SEC_DEBUGGING) != 0
|
---|
3062 | && (h->elf_link_hash_flags
|
---|
3063 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
|
---|
3064 | && (r_type == R_PPC_ADDR32
|
---|
3065 | || r_type == R_PPC_ADDR24
|
---|
3066 | || r_type == R_PPC_ADDR16
|
---|
3067 | || r_type == R_PPC_ADDR16_LO
|
---|
3068 | || r_type == R_PPC_ADDR16_HI
|
---|
3069 | || r_type == R_PPC_ADDR16_HA
|
---|
3070 | || r_type == R_PPC_ADDR14
|
---|
3071 | || r_type == R_PPC_ADDR14_BRTAKEN
|
---|
3072 | || r_type == R_PPC_ADDR14_BRNTAKEN
|
---|
3073 | || r_type == R_PPC_COPY
|
---|
3074 | || r_type == R_PPC_GLOB_DAT
|
---|
3075 | || r_type == R_PPC_JMP_SLOT
|
---|
3076 | || r_type == R_PPC_UADDR32
|
---|
3077 | || r_type == R_PPC_UADDR16
|
---|
3078 | || r_type == R_PPC_SDAREL16
|
---|
3079 | || r_type == R_PPC_EMB_NADDR32
|
---|
3080 | || r_type == R_PPC_EMB_NADDR16
|
---|
3081 | || r_type == R_PPC_EMB_NADDR16_LO
|
---|
3082 | || r_type == R_PPC_EMB_NADDR16_HI
|
---|
3083 | || r_type == R_PPC_EMB_NADDR16_HA
|
---|
3084 | || r_type == R_PPC_EMB_SDAI16
|
---|
3085 | || r_type == R_PPC_EMB_SDA2I16
|
---|
3086 | || r_type == R_PPC_EMB_SDA2REL
|
---|
3087 | || r_type == R_PPC_EMB_SDA21
|
---|
3088 | || r_type == R_PPC_EMB_MRKREF
|
---|
3089 | || r_type == R_PPC_EMB_BIT_FLD
|
---|
3090 | || r_type == R_PPC_EMB_RELSDA
|
---|
3091 | || ((r_type == R_PPC_REL24
|
---|
3092 | || r_type == R_PPC_REL32
|
---|
3093 | || r_type == R_PPC_REL14
|
---|
3094 | || r_type == R_PPC_REL14_BRTAKEN
|
---|
3095 | || r_type == R_PPC_REL14_BRNTAKEN
|
---|
3096 | || r_type == R_PPC_RELATIVE)
|
---|
3097 | && strcmp (h->root.root.string,
|
---|
3098 | "_GLOBAL_OFFSET_TABLE_") != 0))))
|
---|
3099 | {
|
---|
3100 | /* In these cases, we don't need the relocation
|
---|
3101 | value. We check specially because in some
|
---|
3102 | obscure cases sec->output_section will be NULL. */
|
---|
3103 | relocation = 0;
|
---|
3104 | }
|
---|
3105 | else if (sec->output_section == NULL)
|
---|
3106 | {
|
---|
3107 | (*_bfd_error_handler)
|
---|
3108 | (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
|
---|
3109 | bfd_get_filename (input_bfd), h->root.root.string,
|
---|
3110 | bfd_get_section_name (input_bfd, input_section));
|
---|
3111 | relocation = 0;
|
---|
3112 | }
|
---|
3113 | else
|
---|
3114 | relocation = (h->root.u.def.value
|
---|
3115 | + sec->output_section->vma
|
---|
3116 | + sec->output_offset);
|
---|
3117 | }
|
---|
3118 | else if (h->root.type == bfd_link_hash_undefweak)
|
---|
3119 | relocation = 0;
|
---|
3120 | else if (info->shared && !info->symbolic && !info->no_undefined
|
---|
3121 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
|
---|
3122 | relocation = 0;
|
---|
3123 | else
|
---|
3124 | {
|
---|
3125 | if (! (*info->callbacks->undefined_symbol) (info,
|
---|
3126 | h->root.root.string,
|
---|
3127 | input_bfd,
|
---|
3128 | input_section,
|
---|
3129 | rel->r_offset,
|
---|
3130 | (!info->shared
|
---|
3131 | || info->no_undefined
|
---|
3132 | || ELF_ST_VISIBILITY (h->other))))
|
---|
3133 | return false;
|
---|
3134 | relocation = 0;
|
---|
3135 | }
|
---|
3136 | }
|
---|
3137 |
|
---|
3138 | switch ((int) r_type)
|
---|
3139 | {
|
---|
3140 | default:
|
---|
3141 | (*_bfd_error_handler) (_("%s: unknown relocation type %d for symbol %s"),
|
---|
3142 | bfd_get_filename (input_bfd),
|
---|
3143 | (int) r_type, sym_name);
|
---|
3144 |
|
---|
3145 | bfd_set_error (bfd_error_bad_value);
|
---|
3146 | ret = false;
|
---|
3147 | continue;
|
---|
3148 |
|
---|
3149 | /* Relocations that need no special processing. */
|
---|
3150 | case (int) R_PPC_LOCAL24PC:
|
---|
3151 | /* It makes no sense to point a local relocation
|
---|
3152 | at a symbol not in this object. */
|
---|
3153 | if (h != NULL
|
---|
3154 | && (h->root.type == bfd_link_hash_defined
|
---|
3155 | || h->root.type == bfd_link_hash_defweak)
|
---|
3156 | && sec->output_section == NULL)
|
---|
3157 | {
|
---|
3158 | if (! (*info->callbacks->undefined_symbol) (info,
|
---|
3159 | h->root.root.string,
|
---|
3160 | input_bfd,
|
---|
3161 | input_section,
|
---|
3162 | rel->r_offset,
|
---|
3163 | true))
|
---|
3164 | return false;
|
---|
3165 | continue;
|
---|
3166 | }
|
---|
3167 | break;
|
---|
3168 |
|
---|
3169 | /* Relocations that may need to be propagated if this is a shared
|
---|
3170 | object. */
|
---|
3171 | case (int) R_PPC_REL24:
|
---|
3172 | case (int) R_PPC_REL32:
|
---|
3173 | case (int) R_PPC_REL14:
|
---|
3174 | /* If these relocations are not to a named symbol, they can be
|
---|
3175 | handled right here, no need to bother the dynamic linker. */
|
---|
3176 | if (h == NULL
|
---|
3177 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
|
---|
3178 | || SYMBOL_REFERENCES_LOCAL (info, h))
|
---|
3179 | break;
|
---|
3180 | /* fall through */
|
---|
3181 |
|
---|
3182 | /* Relocations that always need to be propagated if this is a shared
|
---|
3183 | object. */
|
---|
3184 | case (int) R_PPC_NONE:
|
---|
3185 | case (int) R_PPC_ADDR32:
|
---|
3186 | case (int) R_PPC_ADDR24:
|
---|
3187 | case (int) R_PPC_ADDR16:
|
---|
3188 | case (int) R_PPC_ADDR16_LO:
|
---|
3189 | case (int) R_PPC_ADDR16_HI:
|
---|
3190 | case (int) R_PPC_ADDR16_HA:
|
---|
3191 | case (int) R_PPC_ADDR14:
|
---|
3192 | case (int) R_PPC_UADDR32:
|
---|
3193 | case (int) R_PPC_UADDR16:
|
---|
3194 | if (info->shared)
|
---|
3195 | {
|
---|
3196 | Elf_Internal_Rela outrel;
|
---|
3197 | boolean skip;
|
---|
3198 |
|
---|
3199 | #ifdef DEBUG
|
---|
3200 | fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
|
---|
3201 | (h && h->root.root.string) ? h->root.root.string : "<unknown>");
|
---|
3202 | #endif
|
---|
3203 |
|
---|
3204 | /* When generating a shared object, these relocations
|
---|
3205 | are copied into the output file to be resolved at run
|
---|
3206 | time. */
|
---|
3207 |
|
---|
3208 | if (sreloc == NULL)
|
---|
3209 | {
|
---|
3210 | const char *name;
|
---|
3211 |
|
---|
3212 | name = (bfd_elf_string_from_elf_section
|
---|
3213 | (input_bfd,
|
---|
3214 | elf_elfheader (input_bfd)->e_shstrndx,
|
---|
3215 | elf_section_data (input_section)->rel_hdr.sh_name));
|
---|
3216 | if (name == NULL)
|
---|
3217 | return false;
|
---|
3218 |
|
---|
3219 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
---|
3220 | && strcmp (bfd_get_section_name (input_bfd,
|
---|
3221 | input_section),
|
---|
3222 | name + 5) == 0);
|
---|
3223 |
|
---|
3224 | sreloc = bfd_get_section_by_name (dynobj, name);
|
---|
3225 | BFD_ASSERT (sreloc != NULL);
|
---|
3226 | }
|
---|
3227 |
|
---|
3228 | skip = false;
|
---|
3229 |
|
---|
3230 | if (elf_section_data (input_section)->stab_info == NULL)
|
---|
3231 | outrel.r_offset = rel->r_offset;
|
---|
3232 | else
|
---|
3233 | {
|
---|
3234 | bfd_vma off;
|
---|
3235 |
|
---|
3236 | off = (_bfd_stab_section_offset
|
---|
3237 | (output_bfd, &elf_hash_table (info)->stab_info,
|
---|
3238 | input_section,
|
---|
3239 | &elf_section_data (input_section)->stab_info,
|
---|
3240 | rel->r_offset));
|
---|
3241 | if (off == (bfd_vma) -1)
|
---|
3242 | skip = true;
|
---|
3243 | outrel.r_offset = off;
|
---|
3244 | }
|
---|
3245 |
|
---|
3246 | outrel.r_offset += (input_section->output_section->vma
|
---|
3247 | + input_section->output_offset);
|
---|
3248 |
|
---|
3249 | if (skip)
|
---|
3250 | memset (&outrel, 0, sizeof outrel);
|
---|
3251 | /* h->dynindx may be -1 if this symbol was marked to
|
---|
3252 | become local. */
|
---|
3253 | else if (! will_become_local)
|
---|
3254 | {
|
---|
3255 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
|
---|
3256 | outrel.r_addend = rel->r_addend;
|
---|
3257 | }
|
---|
3258 | else
|
---|
3259 | {
|
---|
3260 | if (r_type == R_PPC_ADDR32)
|
---|
3261 | {
|
---|
3262 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
|
---|
3263 | outrel.r_addend = relocation + rel->r_addend;
|
---|
3264 | }
|
---|
3265 | else
|
---|
3266 | {
|
---|
3267 | long indx;
|
---|
3268 |
|
---|
3269 | if (h == NULL)
|
---|
3270 | sec = local_sections[r_symndx];
|
---|
3271 | else
|
---|
3272 | {
|
---|
3273 | BFD_ASSERT (h->root.type == bfd_link_hash_defined
|
---|
3274 | || (h->root.type
|
---|
3275 | == bfd_link_hash_defweak));
|
---|
3276 | sec = h->root.u.def.section;
|
---|
3277 | }
|
---|
3278 | if (sec != NULL && bfd_is_abs_section (sec))
|
---|
3279 | indx = 0;
|
---|
3280 | else if (sec == NULL || sec->owner == NULL)
|
---|
3281 | {
|
---|
3282 | bfd_set_error (bfd_error_bad_value);
|
---|
3283 | return false;
|
---|
3284 | }
|
---|
3285 | else
|
---|
3286 | {
|
---|
3287 | asection *osec;
|
---|
3288 |
|
---|
3289 | osec = sec->output_section;
|
---|
3290 | indx = elf_section_data (osec)->dynindx;
|
---|
3291 | BFD_ASSERT (indx > 0);
|
---|
3292 | #ifdef DEBUG
|
---|
3293 | if (indx <= 0)
|
---|
3294 | {
|
---|
3295 | printf ("indx=%d section=%s flags=%08x name=%s\n",
|
---|
3296 | indx, osec->name, osec->flags,
|
---|
3297 | h->root.root.string);
|
---|
3298 | }
|
---|
3299 | #endif
|
---|
3300 | }
|
---|
3301 |
|
---|
3302 | outrel.r_info = ELF32_R_INFO (indx, r_type);
|
---|
3303 | outrel.r_addend = relocation + rel->r_addend;
|
---|
3304 | }
|
---|
3305 | }
|
---|
3306 |
|
---|
3307 | bfd_elf32_swap_reloca_out (output_bfd, &outrel,
|
---|
3308 | (((Elf32_External_Rela *)
|
---|
3309 | sreloc->contents)
|
---|
3310 | + sreloc->reloc_count));
|
---|
3311 | ++sreloc->reloc_count;
|
---|
3312 |
|
---|
3313 | /* This reloc will be computed at runtime, so there's no
|
---|
3314 | need to do anything now, unless this is a RELATIVE
|
---|
3315 | reloc in an unallocated section. */
|
---|
3316 | if (skip
|
---|
3317 | || (input_section->flags & SEC_ALLOC) != 0
|
---|
3318 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)
|
---|
3319 | continue;
|
---|
3320 | }
|
---|
3321 |
|
---|
3322 | /* Arithmetic adjust relocations that aren't going into a
|
---|
3323 | shared object. */
|
---|
3324 | if (r_type == R_PPC_ADDR16_HA
|
---|
3325 | /* It's just possible that this symbol is a weak symbol
|
---|
3326 | that's not actually defined anywhere. In that case,
|
---|
3327 | 'sec' would be NULL, and we should leave the symbol
|
---|
3328 | alone (it will be set to zero elsewhere in the link). */
|
---|
3329 | && sec != NULL)
|
---|
3330 | {
|
---|
3331 | addend += ((relocation + addend) & 0x8000) << 1;
|
---|
3332 | }
|
---|
3333 | break;
|
---|
3334 |
|
---|
3335 | /* branch taken prediction relocations */
|
---|
3336 | case (int) R_PPC_ADDR14_BRTAKEN:
|
---|
3337 | case (int) R_PPC_REL14_BRTAKEN:
|
---|
3338 | insn = bfd_get_32 (output_bfd, contents + offset);
|
---|
3339 | if ((relocation - offset) & 0x8000)
|
---|
3340 | insn &= ~BRANCH_PREDICT_BIT;
|
---|
3341 | else
|
---|
3342 | insn |= BRANCH_PREDICT_BIT;
|
---|
3343 | bfd_put_32 (output_bfd, insn, contents + offset);
|
---|
3344 | break;
|
---|
3345 |
|
---|
3346 | /* branch not taken predicition relocations */
|
---|
3347 | case (int) R_PPC_ADDR14_BRNTAKEN:
|
---|
3348 | case (int) R_PPC_REL14_BRNTAKEN:
|
---|
3349 | insn = bfd_get_32 (output_bfd, contents + offset);
|
---|
3350 | if ((relocation - offset) & 0x8000)
|
---|
3351 | insn |= BRANCH_PREDICT_BIT;
|
---|
3352 | else
|
---|
3353 | insn &= ~BRANCH_PREDICT_BIT;
|
---|
3354 | bfd_put_32 (output_bfd, insn, contents + offset);
|
---|
3355 | break;
|
---|
3356 |
|
---|
3357 | /* GOT16 relocations */
|
---|
3358 | case (int) R_PPC_GOT16:
|
---|
3359 | case (int) R_PPC_GOT16_LO:
|
---|
3360 | case (int) R_PPC_GOT16_HI:
|
---|
3361 | case (int) R_PPC_GOT16_HA:
|
---|
3362 | /* Relocation is to the entry for this symbol in the global
|
---|
3363 | offset table. */
|
---|
3364 | BFD_ASSERT (sgot != NULL);
|
---|
3365 |
|
---|
3366 | if (h != NULL)
|
---|
3367 | {
|
---|
3368 | bfd_vma off;
|
---|
3369 |
|
---|
3370 | off = h->got.offset;
|
---|
3371 | BFD_ASSERT (off != (bfd_vma) -1);
|
---|
3372 |
|
---|
3373 | if (! elf_hash_table (info)->dynamic_sections_created
|
---|
3374 | || (info->shared
|
---|
3375 | && SYMBOL_REFERENCES_LOCAL (info, h)))
|
---|
3376 | {
|
---|
3377 | /* This is actually a static link, or it is a
|
---|
3378 | -Bsymbolic link and the symbol is defined
|
---|
3379 | locally. We must initialize this entry in the
|
---|
3380 | global offset table. Since the offset must
|
---|
3381 | always be a multiple of 4, we use the least
|
---|
3382 | significant bit to record whether we have
|
---|
3383 | initialized it already.
|
---|
3384 |
|
---|
3385 | When doing a dynamic link, we create a .rela.got
|
---|
3386 | relocation entry to initialize the value. This
|
---|
3387 | is done in the finish_dynamic_symbol routine. */
|
---|
3388 | if ((off & 1) != 0)
|
---|
3389 | off &= ~1;
|
---|
3390 | else
|
---|
3391 | {
|
---|
3392 | bfd_put_32 (output_bfd, relocation,
|
---|
3393 | sgot->contents + off);
|
---|
3394 | h->got.offset |= 1;
|
---|
3395 | }
|
---|
3396 | }
|
---|
3397 |
|
---|
3398 | relocation = sgot->output_offset + off - 4;
|
---|
3399 | }
|
---|
3400 | else
|
---|
3401 | {
|
---|
3402 | bfd_vma off;
|
---|
3403 |
|
---|
3404 | BFD_ASSERT (local_got_offsets != NULL
|
---|
3405 | && local_got_offsets[r_symndx] != (bfd_vma) -1);
|
---|
3406 |
|
---|
3407 | off = local_got_offsets[r_symndx];
|
---|
3408 |
|
---|
3409 | /* The offset must always be a multiple of 4. We use
|
---|
3410 | the least significant bit to record whether we have
|
---|
3411 | already processed this entry. */
|
---|
3412 | if ((off & 1) != 0)
|
---|
3413 | off &= ~1;
|
---|
3414 | else
|
---|
3415 | {
|
---|
3416 | bfd_put_32 (output_bfd, relocation, sgot->contents + off);
|
---|
3417 |
|
---|
3418 | if (info->shared)
|
---|
3419 | {
|
---|
3420 | asection *srelgot;
|
---|
3421 | Elf_Internal_Rela outrel;
|
---|
3422 |
|
---|
3423 | /* We need to generate a R_PPC_RELATIVE reloc
|
---|
3424 | for the dynamic linker. */
|
---|
3425 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
3426 | BFD_ASSERT (srelgot != NULL);
|
---|
3427 |
|
---|
3428 | outrel.r_offset = (sgot->output_section->vma
|
---|
3429 | + sgot->output_offset
|
---|
3430 | + off);
|
---|
3431 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
|
---|
3432 | outrel.r_addend = relocation;
|
---|
3433 | bfd_elf32_swap_reloca_out (output_bfd, &outrel,
|
---|
3434 | (((Elf32_External_Rela *)
|
---|
3435 | srelgot->contents)
|
---|
3436 | + srelgot->reloc_count));
|
---|
3437 | ++srelgot->reloc_count;
|
---|
3438 | }
|
---|
3439 |
|
---|
3440 | local_got_offsets[r_symndx] |= 1;
|
---|
3441 | }
|
---|
3442 |
|
---|
3443 | relocation = sgot->output_offset + off - 4;
|
---|
3444 | }
|
---|
3445 | break;
|
---|
3446 |
|
---|
3447 | /* Indirect .sdata relocation */
|
---|
3448 | case (int) R_PPC_EMB_SDAI16:
|
---|
3449 | BFD_ASSERT (sdata != NULL);
|
---|
3450 | relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
|
---|
3451 | sdata, h, relocation, rel,
|
---|
3452 | R_PPC_RELATIVE);
|
---|
3453 | break;
|
---|
3454 |
|
---|
3455 | /* Indirect .sdata2 relocation */
|
---|
3456 | case (int) R_PPC_EMB_SDA2I16:
|
---|
3457 | BFD_ASSERT (sdata2 != NULL);
|
---|
3458 | relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
|
---|
3459 | sdata2, h, relocation, rel,
|
---|
3460 | R_PPC_RELATIVE);
|
---|
3461 | break;
|
---|
3462 |
|
---|
3463 | /* Handle the TOC16 reloc. We want to use the offset within the .got
|
---|
3464 | section, not the actual VMA. This is appropriate when generating
|
---|
3465 | an embedded ELF object, for which the .got section acts like the
|
---|
3466 | AIX .toc section. */
|
---|
3467 | case (int) R_PPC_TOC16: /* phony GOT16 relocations */
|
---|
3468 | BFD_ASSERT (sec != (asection *) 0);
|
---|
3469 | BFD_ASSERT (bfd_is_und_section (sec)
|
---|
3470 | || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
|
---|
3471 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
|
---|
3472 |
|
---|
3473 | addend -= sec->output_section->vma + sec->output_offset + 0x8000;
|
---|
3474 | break;
|
---|
3475 |
|
---|
3476 | case (int) R_PPC_PLTREL24:
|
---|
3477 | /* Relocation is to the entry for this symbol in the
|
---|
3478 | procedure linkage table. */
|
---|
3479 | BFD_ASSERT (h != NULL);
|
---|
3480 |
|
---|
3481 | if (h->plt.offset == (bfd_vma) -1
|
---|
3482 | || splt == NULL)
|
---|
3483 | {
|
---|
3484 | /* We didn't make a PLT entry for this symbol. This
|
---|
3485 | happens when statically linking PIC code, or when
|
---|
3486 | using -Bsymbolic. */
|
---|
3487 | break;
|
---|
3488 | }
|
---|
3489 |
|
---|
3490 | relocation = (splt->output_section->vma
|
---|
3491 | + splt->output_offset
|
---|
3492 | + h->plt.offset);
|
---|
3493 | break;
|
---|
3494 |
|
---|
3495 | /* relocate against _SDA_BASE_ */
|
---|
3496 | case (int) R_PPC_SDAREL16:
|
---|
3497 | {
|
---|
3498 | const char *name;
|
---|
3499 |
|
---|
3500 | BFD_ASSERT (sec != (asection *) 0);
|
---|
3501 | name = bfd_get_section_name (abfd, sec->output_section);
|
---|
3502 | if (strcmp (name, ".sdata") != 0
|
---|
3503 | && strcmp (name, ".sbss") != 0)
|
---|
3504 | {
|
---|
3505 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
|
---|
3506 | bfd_get_filename (input_bfd),
|
---|
3507 | sym_name,
|
---|
3508 | ppc_elf_howto_table[(int) r_type]->name,
|
---|
3509 | name);
|
---|
3510 | }
|
---|
3511 | addend -= (sdata->sym_hash->root.u.def.value
|
---|
3512 | + sdata->sym_hash->root.u.def.section->output_section->vma
|
---|
3513 | + sdata->sym_hash->root.u.def.section->output_offset);
|
---|
3514 | }
|
---|
3515 | break;
|
---|
3516 |
|
---|
3517 | /* relocate against _SDA2_BASE_ */
|
---|
3518 | case (int) R_PPC_EMB_SDA2REL:
|
---|
3519 | {
|
---|
3520 | const char *name;
|
---|
3521 |
|
---|
3522 | BFD_ASSERT (sec != (asection *) 0);
|
---|
3523 | name = bfd_get_section_name (abfd, sec->output_section);
|
---|
3524 | if (strcmp (name, ".sdata2") != 0 && strcmp (name, ".sbss2") != 0)
|
---|
3525 | {
|
---|
3526 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
|
---|
3527 | bfd_get_filename (input_bfd),
|
---|
3528 | sym_name,
|
---|
3529 | ppc_elf_howto_table[(int) r_type]->name,
|
---|
3530 | name);
|
---|
3531 |
|
---|
3532 | bfd_set_error (bfd_error_bad_value);
|
---|
3533 | ret = false;
|
---|
3534 | continue;
|
---|
3535 | }
|
---|
3536 | addend -= (sdata2->sym_hash->root.u.def.value
|
---|
3537 | + sdata2->sym_hash->root.u.def.section->output_section->vma
|
---|
3538 | + sdata2->sym_hash->root.u.def.section->output_offset);
|
---|
3539 | }
|
---|
3540 | break;
|
---|
3541 |
|
---|
3542 | /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
|
---|
3543 | case (int) R_PPC_EMB_SDA21:
|
---|
3544 | case (int) R_PPC_EMB_RELSDA:
|
---|
3545 | {
|
---|
3546 | const char *name;
|
---|
3547 | int reg;
|
---|
3548 |
|
---|
3549 | BFD_ASSERT (sec != (asection *) 0);
|
---|
3550 | name = bfd_get_section_name (abfd, sec->output_section);
|
---|
3551 | if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
|
---|
3552 | {
|
---|
3553 | reg = 13;
|
---|
3554 | addend -= (sdata->sym_hash->root.u.def.value
|
---|
3555 | + sdata->sym_hash->root.u.def.section->output_section->vma
|
---|
3556 | + sdata->sym_hash->root.u.def.section->output_offset);
|
---|
3557 | }
|
---|
3558 |
|
---|
3559 | else if (strcmp (name, ".sdata2") == 0
|
---|
3560 | || strcmp (name, ".sbss2") == 0)
|
---|
3561 | {
|
---|
3562 | reg = 2;
|
---|
3563 | addend -= (sdata2->sym_hash->root.u.def.value
|
---|
3564 | + sdata2->sym_hash->root.u.def.section->output_section->vma
|
---|
3565 | + sdata2->sym_hash->root.u.def.section->output_offset);
|
---|
3566 | }
|
---|
3567 |
|
---|
3568 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0
|
---|
3569 | || strcmp (name, ".PPC.EMB.sbss0") == 0)
|
---|
3570 | {
|
---|
3571 | reg = 0;
|
---|
3572 | }
|
---|
3573 |
|
---|
3574 | else
|
---|
3575 | {
|
---|
3576 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
|
---|
3577 | bfd_get_filename (input_bfd),
|
---|
3578 | sym_name,
|
---|
3579 | ppc_elf_howto_table[(int) r_type]->name,
|
---|
3580 | name);
|
---|
3581 |
|
---|
3582 | bfd_set_error (bfd_error_bad_value);
|
---|
3583 | ret = false;
|
---|
3584 | continue;
|
---|
3585 | }
|
---|
3586 |
|
---|
3587 | if (r_type == R_PPC_EMB_SDA21)
|
---|
3588 | { /* fill in register field */
|
---|
3589 | insn = bfd_get_32 (output_bfd, contents + offset);
|
---|
3590 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
|
---|
3591 | bfd_put_32 (output_bfd, insn, contents + offset);
|
---|
3592 | }
|
---|
3593 | }
|
---|
3594 | break;
|
---|
3595 |
|
---|
3596 | /* Relocate against the beginning of the section */
|
---|
3597 | case (int) R_PPC_SECTOFF:
|
---|
3598 | case (int) R_PPC_SECTOFF_LO:
|
---|
3599 | case (int) R_PPC_SECTOFF_HI:
|
---|
3600 | BFD_ASSERT (sec != (asection *) 0);
|
---|
3601 | addend -= sec->output_section->vma;
|
---|
3602 | break;
|
---|
3603 |
|
---|
3604 | case (int) R_PPC_SECTOFF_HA:
|
---|
3605 | BFD_ASSERT (sec != (asection *) 0);
|
---|
3606 | addend -= sec->output_section->vma;
|
---|
3607 | addend += ((relocation + addend) & 0x8000) << 1;
|
---|
3608 | break;
|
---|
3609 |
|
---|
3610 | /* Negative relocations */
|
---|
3611 | case (int) R_PPC_EMB_NADDR32:
|
---|
3612 | case (int) R_PPC_EMB_NADDR16:
|
---|
3613 | case (int) R_PPC_EMB_NADDR16_LO:
|
---|
3614 | case (int) R_PPC_EMB_NADDR16_HI:
|
---|
3615 | addend -= 2 * relocation;
|
---|
3616 | break;
|
---|
3617 |
|
---|
3618 | case (int) R_PPC_EMB_NADDR16_HA:
|
---|
3619 | addend -= 2 * relocation;
|
---|
3620 | addend += ((relocation + addend) & 0x8000) << 1;
|
---|
3621 | break;
|
---|
3622 |
|
---|
3623 | /* NOP relocation that prevents garbage collecting linkers from omitting a
|
---|
3624 | reference. */
|
---|
3625 | case (int) R_PPC_EMB_MRKREF:
|
---|
3626 | continue;
|
---|
3627 |
|
---|
3628 | case (int) R_PPC_COPY:
|
---|
3629 | case (int) R_PPC_GLOB_DAT:
|
---|
3630 | case (int) R_PPC_JMP_SLOT:
|
---|
3631 | case (int) R_PPC_RELATIVE:
|
---|
3632 | case (int) R_PPC_PLT32:
|
---|
3633 | case (int) R_PPC_PLTREL32:
|
---|
3634 | case (int) R_PPC_PLT16_LO:
|
---|
3635 | case (int) R_PPC_PLT16_HI:
|
---|
3636 | case (int) R_PPC_PLT16_HA:
|
---|
3637 | case (int) R_PPC_EMB_RELSEC16:
|
---|
3638 | case (int) R_PPC_EMB_RELST_LO:
|
---|
3639 | case (int) R_PPC_EMB_RELST_HI:
|
---|
3640 | case (int) R_PPC_EMB_RELST_HA:
|
---|
3641 | case (int) R_PPC_EMB_BIT_FLD:
|
---|
3642 | (*_bfd_error_handler) (_("%s: Relocation %s is not yet supported for symbol %s."),
|
---|
3643 | bfd_get_filename (input_bfd),
|
---|
3644 | ppc_elf_howto_table[(int) r_type]->name,
|
---|
3645 | sym_name);
|
---|
3646 |
|
---|
3647 | bfd_set_error (bfd_error_invalid_operation);
|
---|
3648 | ret = false;
|
---|
3649 | continue;
|
---|
3650 |
|
---|
3651 | case (int) R_PPC_GNU_VTINHERIT:
|
---|
3652 | case (int) R_PPC_GNU_VTENTRY:
|
---|
3653 | /* These are no-ops in the end. */
|
---|
3654 | continue;
|
---|
3655 | }
|
---|
3656 |
|
---|
3657 | #ifdef DEBUG
|
---|
3658 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
|
---|
3659 | howto->name,
|
---|
3660 | (int) r_type,
|
---|
3661 | sym_name,
|
---|
3662 | r_symndx,
|
---|
3663 | (long) offset,
|
---|
3664 | (long) addend);
|
---|
3665 | #endif
|
---|
3666 |
|
---|
3667 | r = _bfd_final_link_relocate (howto,
|
---|
3668 | input_bfd,
|
---|
3669 | input_section,
|
---|
3670 | contents,
|
---|
3671 | offset,
|
---|
3672 | relocation,
|
---|
3673 | addend);
|
---|
3674 |
|
---|
3675 | if (r == bfd_reloc_ok)
|
---|
3676 | ;
|
---|
3677 | else if (r == bfd_reloc_overflow)
|
---|
3678 | {
|
---|
3679 | const char *name;
|
---|
3680 |
|
---|
3681 | if (h != NULL)
|
---|
3682 | {
|
---|
3683 | if (h->root.type == bfd_link_hash_undefweak
|
---|
3684 | && howto->pc_relative)
|
---|
3685 | {
|
---|
3686 | /* Assume this is a call protected by other code that
|
---|
3687 | detect the symbol is undefined. If this is the case,
|
---|
3688 | we can safely ignore the overflow. If not, the
|
---|
3689 | program is hosed anyway, and a little warning isn't
|
---|
3690 | going to help. */
|
---|
3691 |
|
---|
3692 | continue;
|
---|
3693 | }
|
---|
3694 |
|
---|
3695 | name = h->root.root.string;
|
---|
3696 | }
|
---|
3697 | else
|
---|
3698 | {
|
---|
3699 | name = bfd_elf_string_from_elf_section (input_bfd,
|
---|
3700 | symtab_hdr->sh_link,
|
---|
3701 | sym->st_name);
|
---|
3702 | if (name == NULL)
|
---|
3703 | continue;
|
---|
3704 | if (*name == '\0')
|
---|
3705 | name = bfd_section_name (input_bfd, sec);
|
---|
3706 | }
|
---|
3707 |
|
---|
3708 | if (! (*info->callbacks->reloc_overflow) (info,
|
---|
3709 | name,
|
---|
3710 | howto->name,
|
---|
3711 | (bfd_vma) 0,
|
---|
3712 | input_bfd,
|
---|
3713 | input_section,
|
---|
3714 | offset))
|
---|
3715 | return false;
|
---|
3716 | }
|
---|
3717 | else
|
---|
3718 | ret = false;
|
---|
3719 | }
|
---|
3720 |
|
---|
3721 | #ifdef DEBUG
|
---|
3722 | fprintf (stderr, "\n");
|
---|
3723 | #endif
|
---|
3724 |
|
---|
3725 | return ret;
|
---|
3726 | }
|
---|
3727 | |
---|
3728 |
|
---|
3729 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
|
---|
3730 | #define TARGET_LITTLE_NAME "elf32-powerpcle"
|
---|
3731 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
|
---|
3732 | #define TARGET_BIG_NAME "elf32-powerpc"
|
---|
3733 | #define ELF_ARCH bfd_arch_powerpc
|
---|
3734 | #define ELF_MACHINE_CODE EM_PPC
|
---|
3735 | #define ELF_MAXPAGESIZE 0x10000
|
---|
3736 | #define elf_info_to_howto ppc_elf_info_to_howto
|
---|
3737 |
|
---|
3738 | #ifdef EM_CYGNUS_POWERPC
|
---|
3739 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
|
---|
3740 | #endif
|
---|
3741 |
|
---|
3742 | #ifdef EM_PPC_OLD
|
---|
3743 | #define ELF_MACHINE_ALT2 EM_PPC_OLD
|
---|
3744 | #endif
|
---|
3745 |
|
---|
3746 | #define elf_backend_plt_not_loaded 1
|
---|
3747 | #define elf_backend_got_symbol_offset 4
|
---|
3748 | #define elf_backend_can_gc_sections 1
|
---|
3749 | #define elf_backend_got_header_size 12
|
---|
3750 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
|
---|
3751 |
|
---|
3752 | #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
|
---|
3753 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
|
---|
3754 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
|
---|
3755 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
|
---|
3756 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
|
---|
3757 | #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
|
---|
3758 |
|
---|
3759 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
|
---|
3760 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
|
---|
3761 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
|
---|
3762 | #define elf_backend_relocate_section ppc_elf_relocate_section
|
---|
3763 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
|
---|
3764 | #define elf_backend_check_relocs ppc_elf_check_relocs
|
---|
3765 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
|
---|
3766 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
|
---|
3767 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
|
---|
3768 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
|
---|
3769 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
|
---|
3770 | #define elf_backend_fake_sections ppc_elf_fake_sections
|
---|
3771 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
|
---|
3772 | #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
|
---|
3773 |
|
---|
3774 | #include "elf32-target.h"
|
---|