]>
Commit | Line | Data |
---|---|---|
bcbe2c71 | 1 | /* PowerPC-specific support for 32-bit ELF |
71897943 | 2 | Copyright 1994, 1995, 1996 Free Software Foundation, Inc. |
bcbe2c71 MM |
3 | Written by Ian Lance Taylor, Cygnus Support. |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
dd82c578 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bcbe2c71 MM |
20 | |
21 | /* This file is based on a preliminary PowerPC ELF ABI. The | |
22 | information may not match the final PowerPC ELF ABI. It includes | |
23 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
24 | information may also not match. */ | |
25 | ||
26 | #include "bfd.h" | |
27 | #include "sysdep.h" | |
ede4eed4 | 28 | #include "bfdlink.h" |
bcbe2c71 | 29 | #include "libbfd.h" |
08556813 | 30 | #include "elf-bfd.h" |
ede4eed4 | 31 | #include "elf/ppc.h" |
bcbe2c71 | 32 | |
08556813 MM |
33 | #define USE_RELA /* we want RELA relocations, not REL */ |
34 | ||
35 | /* PowerPC relocations defined by the ABIs */ | |
36 | enum ppc_reloc_type | |
37 | { | |
38 | R_PPC_NONE = 0, | |
39 | R_PPC_ADDR32 = 1, | |
40 | R_PPC_ADDR24 = 2, | |
41 | R_PPC_ADDR16 = 3, | |
42 | R_PPC_ADDR16_LO = 4, | |
43 | R_PPC_ADDR16_HI = 5, | |
44 | R_PPC_ADDR16_HA = 6, | |
45 | R_PPC_ADDR14 = 7, | |
46 | R_PPC_ADDR14_BRTAKEN = 8, | |
47 | R_PPC_ADDR14_BRNTAKEN = 9, | |
48 | R_PPC_REL24 = 10, | |
49 | R_PPC_REL14 = 11, | |
50 | R_PPC_REL14_BRTAKEN = 12, | |
51 | R_PPC_REL14_BRNTAKEN = 13, | |
52 | R_PPC_GOT16 = 14, | |
53 | R_PPC_GOT16_LO = 15, | |
54 | R_PPC_GOT16_HI = 16, | |
55 | R_PPC_GOT16_HA = 17, | |
56 | R_PPC_PLTREL24 = 18, | |
57 | R_PPC_COPY = 19, | |
58 | R_PPC_GLOB_DAT = 20, | |
59 | R_PPC_JMP_SLOT = 21, | |
60 | R_PPC_RELATIVE = 22, | |
61 | R_PPC_LOCAL24PC = 23, | |
62 | R_PPC_UADDR32 = 24, | |
63 | R_PPC_UADDR16 = 25, | |
64 | R_PPC_REL32 = 26, | |
65 | R_PPC_PLT32 = 27, | |
66 | R_PPC_PLTREL32 = 28, | |
67 | R_PPC_PLT16_LO = 29, | |
68 | R_PPC_PLT16_HI = 30, | |
69 | R_PPC_PLT16_HA = 31, | |
70 | R_PPC_SDAREL16 = 32, | |
71 | R_PPC_SECTOFF = 33, | |
72 | R_PPC_SECTOFF_LO = 34, | |
73 | R_PPC_SECTOFF_HI = 35, | |
74 | R_PPC_SECTOFF_HA = 36, | |
75 | ||
76 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
77 | in the SVR4 ELF ABI. */ | |
78 | R_PPC_EMB_NADDR32 = 101, | |
79 | R_PPC_EMB_NADDR16 = 102, | |
80 | R_PPC_EMB_NADDR16_LO = 103, | |
81 | R_PPC_EMB_NADDR16_HI = 104, | |
82 | R_PPC_EMB_NADDR16_HA = 105, | |
83 | R_PPC_EMB_SDAI16 = 106, | |
84 | R_PPC_EMB_SDA2I16 = 107, | |
85 | R_PPC_EMB_SDA2REL = 108, | |
86 | R_PPC_EMB_SDA21 = 109, | |
87 | R_PPC_EMB_MRKREF = 110, | |
88 | R_PPC_EMB_RELSEC16 = 111, | |
89 | R_PPC_EMB_RELST_LO = 112, | |
90 | R_PPC_EMB_RELST_HI = 113, | |
91 | R_PPC_EMB_RELST_HA = 114, | |
92 | R_PPC_EMB_BIT_FLD = 115, | |
93 | R_PPC_EMB_RELSDA = 116, | |
94 | ||
95 | /* This is a phony reloc to handle any old fashioned TOC16 references | |
96 | that may still be in object files. */ | |
97 | R_PPC_TOC16 = 255, | |
98 | ||
99 | R_PPC_max | |
100 | }; | |
101 | ||
ede4eed4 | 102 | static reloc_howto_type *ppc_elf_reloc_type_lookup |
bcbe2c71 | 103 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); |
ede4eed4 | 104 | static void ppc_elf_info_to_howto |
bcbe2c71 | 105 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst)); |
ede4eed4 KR |
106 | static void ppc_elf_howto_init PARAMS ((void)); |
107 | static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword)); | |
108 | static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *)); | |
109 | static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *)); | |
110 | ||
83f4323e MM |
111 | static boolean ppc_elf_section_from_shdr PARAMS ((bfd *, |
112 | Elf32_Internal_Shdr *, | |
113 | char *)); | |
114 | ||
1c3a295b MM |
115 | static bfd *ppc_elf_create_dynamic_sections PARAMS ((bfd *abfd, |
116 | struct bfd_link_info *info)); | |
117 | ||
08556813 MM |
118 | static boolean ppc_elf_check_relocs PARAMS ((bfd *, |
119 | struct bfd_link_info *, | |
120 | asection *, | |
121 | const Elf_Internal_Rela *)); | |
122 | ||
123 | static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *, | |
124 | struct elf_link_hash_entry *)); | |
125 | ||
126 | static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR)); | |
127 | ||
128 | static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *)); | |
129 | ||
ede4eed4 KR |
130 | static boolean ppc_elf_relocate_section PARAMS ((bfd *, |
131 | struct bfd_link_info *info, | |
132 | bfd *, | |
133 | asection *, | |
134 | bfd_byte *, | |
135 | Elf_Internal_Rela *relocs, | |
136 | Elf_Internal_Sym *local_syms, | |
137 | asection **)); | |
bcbe2c71 | 138 | |
08556813 MM |
139 | static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *, |
140 | struct bfd_link_info *, | |
141 | struct elf_link_hash_entry *, | |
142 | Elf_Internal_Sym *)); | |
bcbe2c71 | 143 | |
08556813 | 144 | static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *)); |
bcbe2c71 | 145 | |
08556813 MM |
146 | #define BRANCH_PREDICT_BIT 0x200000 |
147 | ||
148 | /* The name of the dynamic interpreter. This is put in the .interp | |
149 | section. */ | |
150 | ||
151 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
bcbe2c71 | 152 | |
ede4eed4 KR |
153 | \f |
154 | static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ]; | |
155 | ||
156 | static reloc_howto_type ppc_elf_howto_raw[] = | |
bcbe2c71 MM |
157 | { |
158 | /* This reloc does nothing. */ | |
08556813 MM |
159 | HOWTO (R_PPC_NONE, /* type */ |
160 | 0, /* rightshift */ | |
161 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
162 | 32, /* bitsize */ | |
163 | false, /* pc_relative */ | |
164 | 0, /* bitpos */ | |
bcbe2c71 | 165 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 166 | bfd_elf_generic_reloc, /* special_function */ |
08556813 MM |
167 | "R_PPC_NONE", /* name */ |
168 | false, /* partial_inplace */ | |
169 | 0, /* src_mask */ | |
170 | 0, /* dst_mask */ | |
171 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
172 | |
173 | /* A standard 32 bit relocation. */ | |
08556813 MM |
174 | HOWTO (R_PPC_ADDR32, /* type */ |
175 | 0, /* rightshift */ | |
176 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
177 | 32, /* bitsize */ | |
178 | false, /* pc_relative */ | |
179 | 0, /* bitpos */ | |
bcbe2c71 | 180 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 181 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 182 | "R_PPC_ADDR32", /* name */ |
08556813 MM |
183 | false, /* partial_inplace */ |
184 | 0, /* src_mask */ | |
185 | 0xffffffff, /* dst_mask */ | |
186 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
187 | |
188 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
189 | FIXME: we don't check that, we just clear them. */ | |
08556813 MM |
190 | HOWTO (R_PPC_ADDR24, /* type */ |
191 | 0, /* rightshift */ | |
192 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
193 | 26, /* bitsize */ | |
194 | false, /* pc_relative */ | |
195 | 0, /* bitpos */ | |
bcbe2c71 | 196 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 197 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 198 | "R_PPC_ADDR24", /* name */ |
08556813 MM |
199 | false, /* partial_inplace */ |
200 | 0, /* src_mask */ | |
201 | 0x3fffffc, /* dst_mask */ | |
202 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
203 | |
204 | /* A standard 16 bit relocation. */ | |
08556813 MM |
205 | HOWTO (R_PPC_ADDR16, /* type */ |
206 | 0, /* rightshift */ | |
207 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
208 | 16, /* bitsize */ | |
209 | false, /* pc_relative */ | |
210 | 0, /* bitpos */ | |
bcbe2c71 | 211 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 212 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 213 | "R_PPC_ADDR16", /* name */ |
08556813 MM |
214 | false, /* partial_inplace */ |
215 | 0, /* src_mask */ | |
216 | 0xffff, /* dst_mask */ | |
217 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
218 | |
219 | /* A 16 bit relocation without overflow. */ | |
08556813 MM |
220 | HOWTO (R_PPC_ADDR16_LO, /* type */ |
221 | 0, /* rightshift */ | |
222 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
223 | 16, /* bitsize */ | |
224 | false, /* pc_relative */ | |
225 | 0, /* bitpos */ | |
bcbe2c71 | 226 | complain_overflow_dont,/* complain_on_overflow */ |
bd2d10c0 | 227 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 228 | "R_PPC_ADDR16_LO", /* name */ |
08556813 MM |
229 | false, /* partial_inplace */ |
230 | 0, /* src_mask */ | |
231 | 0xffff, /* dst_mask */ | |
232 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
233 | |
234 | /* The high order 16 bits of an address. */ | |
08556813 MM |
235 | HOWTO (R_PPC_ADDR16_HI, /* type */ |
236 | 16, /* rightshift */ | |
237 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
238 | 16, /* bitsize */ | |
239 | false, /* pc_relative */ | |
240 | 0, /* bitpos */ | |
bcbe2c71 | 241 | complain_overflow_dont, /* complain_on_overflow */ |
bd2d10c0 | 242 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 243 | "R_PPC_ADDR16_HI", /* name */ |
08556813 MM |
244 | false, /* partial_inplace */ |
245 | 0, /* src_mask */ | |
246 | 0xffff, /* dst_mask */ | |
247 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
248 | |
249 | /* The high order 16 bits of an address, plus 1 if the contents of | |
08556813 MM |
250 | the low 16 bits, treated as a signed number, is negative. */ |
251 | HOWTO (R_PPC_ADDR16_HA, /* type */ | |
252 | 16, /* rightshift */ | |
253 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
254 | 16, /* bitsize */ | |
255 | false, /* pc_relative */ | |
256 | 0, /* bitpos */ | |
bcbe2c71 | 257 | complain_overflow_dont, /* complain_on_overflow */ |
07a159db | 258 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 259 | "R_PPC_ADDR16_HA", /* name */ |
08556813 MM |
260 | false, /* partial_inplace */ |
261 | 0, /* src_mask */ | |
262 | 0xffff, /* dst_mask */ | |
263 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
264 | |
265 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
266 | FIXME: we don't check that, we just clear them. */ | |
08556813 MM |
267 | HOWTO (R_PPC_ADDR14, /* type */ |
268 | 0, /* rightshift */ | |
269 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
270 | 16, /* bitsize */ | |
271 | false, /* pc_relative */ | |
272 | 0, /* bitpos */ | |
bcbe2c71 | 273 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 274 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 275 | "R_PPC_ADDR14", /* name */ |
08556813 MM |
276 | false, /* partial_inplace */ |
277 | 0, /* src_mask */ | |
278 | 0xfffc, /* dst_mask */ | |
279 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
280 | |
281 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
08556813 MM |
282 | indicate that the branch is expected to be taken. The lower two |
283 | bits must be zero. */ | |
284 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ | |
285 | 0, /* rightshift */ | |
286 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
287 | 16, /* bitsize */ | |
288 | false, /* pc_relative */ | |
289 | 0, /* bitpos */ | |
bcbe2c71 | 290 | complain_overflow_bitfield, /* complain_on_overflow */ |
07a159db | 291 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 292 | "R_PPC_ADDR14_BRTAKEN",/* name */ |
08556813 MM |
293 | false, /* partial_inplace */ |
294 | 0, /* src_mask */ | |
295 | 0xfffc, /* dst_mask */ | |
296 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
297 | |
298 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
299 | indicate that the branch is not expected to be taken. The lower | |
300 | two bits must be zero. */ | |
301 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
08556813 MM |
302 | 0, /* rightshift */ |
303 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
304 | 16, /* bitsize */ | |
305 | false, /* pc_relative */ | |
306 | 0, /* bitpos */ | |
bcbe2c71 | 307 | complain_overflow_bitfield, /* complain_on_overflow */ |
07a159db | 308 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 309 | "R_PPC_ADDR14_BRNTAKEN",/* name */ |
08556813 MM |
310 | false, /* partial_inplace */ |
311 | 0, /* src_mask */ | |
312 | 0xfffc, /* dst_mask */ | |
313 | false), /* pcrel_offset */ | |
314 | ||
315 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
316 | HOWTO (R_PPC_REL24, /* type */ | |
317 | 0, /* rightshift */ | |
318 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
319 | 26, /* bitsize */ | |
320 | true, /* pc_relative */ | |
321 | 0, /* bitpos */ | |
bcbe2c71 | 322 | complain_overflow_signed, /* complain_on_overflow */ |
bd2d10c0 | 323 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 324 | "R_PPC_REL24", /* name */ |
08556813 MM |
325 | false, /* partial_inplace */ |
326 | 0, /* src_mask */ | |
327 | 0x3fffffc, /* dst_mask */ | |
328 | true), /* pcrel_offset */ | |
329 | ||
330 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
331 | HOWTO (R_PPC_REL14, /* type */ | |
332 | 0, /* rightshift */ | |
333 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
334 | 16, /* bitsize */ | |
335 | true, /* pc_relative */ | |
336 | 0, /* bitpos */ | |
bcbe2c71 | 337 | complain_overflow_signed, /* complain_on_overflow */ |
bd2d10c0 | 338 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 339 | "R_PPC_REL14", /* name */ |
08556813 MM |
340 | false, /* partial_inplace */ |
341 | 0, /* src_mask */ | |
342 | 0xfffc, /* dst_mask */ | |
343 | true), /* pcrel_offset */ | |
bcbe2c71 | 344 | |
08556813 | 345 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
bcbe2c71 MM |
346 | the branch is expected to be taken. The lower two bits must be |
347 | zero. */ | |
08556813 MM |
348 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ |
349 | 0, /* rightshift */ | |
350 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
351 | 16, /* bitsize */ | |
352 | true, /* pc_relative */ | |
353 | 0, /* bitpos */ | |
bcbe2c71 | 354 | complain_overflow_signed, /* complain_on_overflow */ |
07a159db | 355 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 356 | "R_PPC_REL14_BRTAKEN", /* name */ |
08556813 MM |
357 | false, /* partial_inplace */ |
358 | 0, /* src_mask */ | |
359 | 0xfffc, /* dst_mask */ | |
360 | true), /* pcrel_offset */ | |
bcbe2c71 | 361 | |
08556813 | 362 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
bcbe2c71 MM |
363 | the branch is not expected to be taken. The lower two bits must |
364 | be zero. */ | |
08556813 MM |
365 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ |
366 | 0, /* rightshift */ | |
367 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
368 | 16, /* bitsize */ | |
369 | true, /* pc_relative */ | |
370 | 0, /* bitpos */ | |
bcbe2c71 | 371 | complain_overflow_signed, /* complain_on_overflow */ |
07a159db | 372 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 373 | "R_PPC_REL14_BRNTAKEN",/* name */ |
08556813 MM |
374 | false, /* partial_inplace */ |
375 | 0, /* src_mask */ | |
376 | 0xfffc, /* dst_mask */ | |
377 | true), /* pcrel_offset */ | |
bcbe2c71 MM |
378 | |
379 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
380 | symbol. */ | |
08556813 MM |
381 | HOWTO (R_PPC_GOT16, /* type */ |
382 | 0, /* rightshift */ | |
383 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
384 | 16, /* bitsize */ | |
385 | false, /* pc_relative */ | |
386 | 0, /* bitpos */ | |
ede4eed4 | 387 | complain_overflow_signed, /* complain_on_overflow */ |
07a159db | 388 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 389 | "R_PPC_GOT16", /* name */ |
08556813 MM |
390 | false, /* partial_inplace */ |
391 | 0, /* src_mask */ | |
392 | 0xffff, /* dst_mask */ | |
393 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
394 | |
395 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
396 | the symbol. */ | |
08556813 MM |
397 | HOWTO (R_PPC_GOT16_LO, /* type */ |
398 | 0, /* rightshift */ | |
399 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
400 | 16, /* bitsize */ | |
401 | false, /* pc_relative */ | |
402 | 0, /* bitpos */ | |
bcbe2c71 | 403 | complain_overflow_bitfield, /* complain_on_overflow */ |
07a159db | 404 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 405 | "R_PPC_GOT16_LO", /* name */ |
08556813 MM |
406 | false, /* partial_inplace */ |
407 | 0, /* src_mask */ | |
408 | 0xffff, /* dst_mask */ | |
409 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
410 | |
411 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
412 | the symbol. */ | |
08556813 MM |
413 | HOWTO (R_PPC_GOT16_HI, /* type */ |
414 | 16, /* rightshift */ | |
415 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
416 | 16, /* bitsize */ | |
417 | false, /* pc_relative */ | |
418 | 0, /* bitpos */ | |
bcbe2c71 | 419 | complain_overflow_bitfield, /* complain_on_overflow */ |
07a159db | 420 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 421 | "R_PPC_GOT16_HI", /* name */ |
08556813 MM |
422 | false, /* partial_inplace */ |
423 | 0, /* src_mask */ | |
424 | 0xffff, /* dst_mask */ | |
425 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
426 | |
427 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
08556813 MM |
428 | the symbol. FIXME: Not supported. */ |
429 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
430 | 0, /* rightshift */ | |
431 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
432 | 16, /* bitsize */ | |
433 | false, /* pc_relative */ | |
434 | 0, /* bitpos */ | |
bcbe2c71 | 435 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 436 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 437 | "R_PPC_GOT16_HA", /* name */ |
08556813 MM |
438 | false, /* partial_inplace */ |
439 | 0, /* src_mask */ | |
440 | 0xffff, /* dst_mask */ | |
441 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
442 | |
443 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
444 | entry for the symbol. FIXME: Not supported. */ | |
02f85cda | 445 | HOWTO (R_PPC_PLTREL24, /* type */ |
08556813 MM |
446 | 0, /* rightshift */ |
447 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
448 | 26, /* bitsize */ | |
449 | true, /* pc_relative */ | |
450 | 0, /* bitpos */ | |
451 | complain_overflow_signed, /* complain_on_overflow */ | |
bd2d10c0 | 452 | bfd_elf_generic_reloc, /* special_function */ |
02f85cda | 453 | "R_PPC_PLTREL24", /* name */ |
08556813 MM |
454 | false, /* partial_inplace */ |
455 | 0, /* src_mask */ | |
456 | 0x3fffffc, /* dst_mask */ | |
457 | true), /* pcrel_offset */ | |
bcbe2c71 MM |
458 | |
459 | /* This is used only by the dynamic linker. The symbol should exist | |
460 | both in the object being run and in some shared library. The | |
461 | dynamic linker copies the data addressed by the symbol from the | |
462 | shared library into the object. I have no idea what the purpose | |
463 | of this is. */ | |
08556813 MM |
464 | HOWTO (R_PPC_COPY, /* type */ |
465 | 0, /* rightshift */ | |
466 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
467 | 32, /* bitsize */ | |
468 | false, /* pc_relative */ | |
469 | 0, /* bitpos */ | |
bcbe2c71 | 470 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 471 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 472 | "R_PPC_COPY", /* name */ |
08556813 MM |
473 | false, /* partial_inplace */ |
474 | 0, /* src_mask */ | |
475 | 0, /* dst_mask */ | |
476 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
477 | |
478 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
479 | entries. */ | |
08556813 MM |
480 | HOWTO (R_PPC_GLOB_DAT, /* type */ |
481 | 0, /* rightshift */ | |
482 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
483 | 32, /* bitsize */ | |
484 | false, /* pc_relative */ | |
485 | 0, /* bitpos */ | |
bcbe2c71 | 486 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 487 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 488 | "R_PPC_GLOB_DAT", /* name */ |
08556813 MM |
489 | false, /* partial_inplace */ |
490 | 0, /* src_mask */ | |
491 | 0xffffffff, /* dst_mask */ | |
492 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
493 | |
494 | /* Marks a procedure linkage table entry for a symbol. */ | |
08556813 MM |
495 | HOWTO (R_PPC_JMP_SLOT, /* type */ |
496 | 0, /* rightshift */ | |
497 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
498 | 32, /* bitsize */ | |
499 | false, /* pc_relative */ | |
500 | 0, /* bitpos */ | |
bcbe2c71 | 501 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 502 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 503 | "R_PPC_JMP_SLOT", /* name */ |
08556813 MM |
504 | false, /* partial_inplace */ |
505 | 0, /* src_mask */ | |
506 | 0, /* dst_mask */ | |
507 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
508 | |
509 | /* Used only by the dynamic linker. When the object is run, this | |
510 | longword is set to the load address of the object, plus the | |
511 | addend. */ | |
08556813 MM |
512 | HOWTO (R_PPC_RELATIVE, /* type */ |
513 | 0, /* rightshift */ | |
514 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
515 | 32, /* bitsize */ | |
516 | false, /* pc_relative */ | |
517 | 0, /* bitpos */ | |
bcbe2c71 | 518 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 519 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 520 | "R_PPC_RELATIVE", /* name */ |
08556813 MM |
521 | false, /* partial_inplace */ |
522 | 0, /* src_mask */ | |
523 | 0xffffffff, /* dst_mask */ | |
524 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
525 | |
526 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
527 | object rather than the final value. Normally used for | |
528 | _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */ | |
08556813 MM |
529 | HOWTO (R_PPC_LOCAL24PC, /* type */ |
530 | 0, /* rightshift */ | |
531 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
532 | 26, /* bitsize */ | |
533 | true, /* pc_relative */ | |
534 | 0, /* bitpos */ | |
bcbe2c71 | 535 | complain_overflow_signed, /* complain_on_overflow */ |
bd2d10c0 | 536 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 537 | "R_PPC_LOCAL24PC", /* name */ |
08556813 MM |
538 | false, /* partial_inplace */ |
539 | 0, /* src_mask */ | |
540 | 0x3fffffc, /* dst_mask */ | |
541 | true), /* pcrel_offset */ | |
bcbe2c71 MM |
542 | |
543 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
08556813 MM |
544 | HOWTO (R_PPC_UADDR32, /* type */ |
545 | 0, /* rightshift */ | |
546 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
547 | 32, /* bitsize */ | |
548 | false, /* pc_relative */ | |
549 | 0, /* bitpos */ | |
bcbe2c71 | 550 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 551 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 552 | "R_PPC_UADDR32", /* name */ |
08556813 MM |
553 | false, /* partial_inplace */ |
554 | 0, /* src_mask */ | |
555 | 0xffffffff, /* dst_mask */ | |
556 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
557 | |
558 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
08556813 MM |
559 | HOWTO (R_PPC_UADDR16, /* type */ |
560 | 0, /* rightshift */ | |
561 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
562 | 16, /* bitsize */ | |
563 | false, /* pc_relative */ | |
564 | 0, /* bitpos */ | |
bcbe2c71 | 565 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 566 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 567 | "R_PPC_UADDR16", /* name */ |
08556813 MM |
568 | false, /* partial_inplace */ |
569 | 0, /* src_mask */ | |
570 | 0xffff, /* dst_mask */ | |
571 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
572 | |
573 | /* 32-bit PC relative */ | |
574 | HOWTO (R_PPC_REL32, /* type */ | |
08556813 MM |
575 | 0, /* rightshift */ |
576 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
577 | 32, /* bitsize */ | |
578 | true, /* pc_relative */ | |
579 | 0, /* bitpos */ | |
bcbe2c71 | 580 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 581 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 582 | "R_PPC_REL32", /* name */ |
08556813 MM |
583 | false, /* partial_inplace */ |
584 | 0, /* src_mask */ | |
585 | 0xffffffff, /* dst_mask */ | |
bcbe2c71 MM |
586 | true), /* pcrel_offset */ |
587 | ||
588 | /* 32-bit relocation to the symbol's procedure linkage table. | |
589 | FIXEME: not supported. */ | |
590 | HOWTO (R_PPC_PLT32, /* type */ | |
08556813 MM |
591 | 0, /* rightshift */ |
592 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
593 | 32, /* bitsize */ | |
594 | false, /* pc_relative */ | |
595 | 0, /* bitpos */ | |
bcbe2c71 | 596 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 597 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 598 | "R_PPC_PLT32", /* name */ |
08556813 MM |
599 | false, /* partial_inplace */ |
600 | 0, /* src_mask */ | |
601 | 0, /* dst_mask */ | |
602 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
603 | |
604 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
605 | FIXEME: not supported. */ | |
606 | HOWTO (R_PPC_PLTREL32, /* type */ | |
08556813 MM |
607 | 0, /* rightshift */ |
608 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
609 | 32, /* bitsize */ | |
610 | true, /* pc_relative */ | |
611 | 0, /* bitpos */ | |
bcbe2c71 | 612 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 613 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 614 | "R_PPC_PLTREL32", /* name */ |
08556813 MM |
615 | false, /* partial_inplace */ |
616 | 0, /* src_mask */ | |
617 | 0, /* dst_mask */ | |
bcbe2c71 MM |
618 | true), /* pcrel_offset */ |
619 | ||
620 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
621 | the symbol. */ | |
08556813 MM |
622 | HOWTO (R_PPC_PLT16_LO, /* type */ |
623 | 0, /* rightshift */ | |
624 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
625 | 16, /* bitsize */ | |
626 | false, /* pc_relative */ | |
627 | 0, /* bitpos */ | |
bcbe2c71 | 628 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 629 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 630 | "R_PPC_PLT16_LO", /* name */ |
08556813 MM |
631 | false, /* partial_inplace */ |
632 | 0, /* src_mask */ | |
633 | 0xffff, /* dst_mask */ | |
634 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
635 | |
636 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
637 | the symbol. */ | |
08556813 MM |
638 | HOWTO (R_PPC_PLT16_HI, /* type */ |
639 | 16, /* rightshift */ | |
640 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
641 | 16, /* bitsize */ | |
642 | false, /* pc_relative */ | |
643 | 0, /* bitpos */ | |
bcbe2c71 | 644 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 645 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 646 | "R_PPC_PLT16_HI", /* name */ |
08556813 MM |
647 | false, /* partial_inplace */ |
648 | 0, /* src_mask */ | |
649 | 0xffff, /* dst_mask */ | |
650 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
651 | |
652 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
08556813 MM |
653 | the symbol. FIXME: Not supported. */ |
654 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
655 | 0, /* rightshift */ | |
656 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
657 | 16, /* bitsize */ | |
658 | false, /* pc_relative */ | |
659 | 0, /* bitpos */ | |
bcbe2c71 | 660 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 661 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 662 | "R_PPC_PLT16_HA", /* name */ |
08556813 MM |
663 | false, /* partial_inplace */ |
664 | 0, /* src_mask */ | |
665 | 0xffff, /* dst_mask */ | |
666 | false), /* pcrel_offset */ | |
bcbe2c71 | 667 | |
4500a112 | 668 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with |
bd2d10c0 | 669 | small data items. FIXME: Not supported. */ |
02f85cda | 670 | HOWTO (R_PPC_SDAREL16, /* type */ |
08556813 MM |
671 | 0, /* rightshift */ |
672 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
673 | 16, /* bitsize */ | |
674 | false, /* pc_relative */ | |
675 | 0, /* bitpos */ | |
dd82c578 | 676 | complain_overflow_signed, /* complain_on_overflow */ |
07a159db | 677 | bfd_elf_generic_reloc, /* special_function */ |
02f85cda | 678 | "R_PPC_SDAREL16", /* name */ |
08556813 MM |
679 | false, /* partial_inplace */ |
680 | 0, /* src_mask */ | |
681 | 0xffff, /* dst_mask */ | |
682 | false), /* pcrel_offset */ | |
bcbe2c71 | 683 | |
bcbe2c71 MM |
684 | /* 32-bit section relative relocation. FIXME: not supported. */ |
685 | HOWTO (R_PPC_SECTOFF, /* type */ | |
08556813 MM |
686 | 0, /* rightshift */ |
687 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
688 | 32, /* bitsize */ | |
689 | true, /* pc_relative */ | |
690 | 0, /* bitpos */ | |
bcbe2c71 | 691 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 692 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 693 | "R_PPC_SECTOFF", /* name */ |
08556813 MM |
694 | false, /* partial_inplace */ |
695 | 0, /* src_mask */ | |
696 | 0, /* dst_mask */ | |
bcbe2c71 MM |
697 | true), /* pcrel_offset */ |
698 | ||
699 | /* 16-bit lower half section relative relocation. FIXME: not supported. */ | |
08556813 MM |
700 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
701 | 0, /* rightshift */ | |
702 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
703 | 16, /* bitsize */ | |
704 | false, /* pc_relative */ | |
705 | 0, /* bitpos */ | |
bcbe2c71 | 706 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 707 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 708 | "R_PPC_SECTOFF_LO", /* name */ |
08556813 MM |
709 | false, /* partial_inplace */ |
710 | 0, /* src_mask */ | |
711 | 0xffff, /* dst_mask */ | |
712 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
713 | |
714 | /* 16-bit upper half section relative relocation. FIXME: not supported. */ | |
715 | HOWTO (R_PPC_SECTOFF_HI, /* type */ | |
08556813 MM |
716 | 16, /* rightshift */ |
717 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
718 | 16, /* bitsize */ | |
719 | false, /* pc_relative */ | |
720 | 0, /* bitpos */ | |
bcbe2c71 | 721 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 722 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 723 | "R_PPC_SECTOFF_HI", /* name */ |
08556813 MM |
724 | false, /* partial_inplace */ |
725 | 0, /* src_mask */ | |
726 | 0xffff, /* dst_mask */ | |
727 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
728 | |
729 | /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */ | |
730 | HOWTO (R_PPC_SECTOFF_HA, /* type */ | |
08556813 MM |
731 | 0, /* rightshift */ |
732 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
733 | 16, /* bitsize */ | |
734 | false, /* pc_relative */ | |
735 | 0, /* bitpos */ | |
bcbe2c71 | 736 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 737 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 738 | "R_PPC_SECTOFF_HA", /* name */ |
08556813 MM |
739 | false, /* partial_inplace */ |
740 | 0, /* src_mask */ | |
741 | 0xffff, /* dst_mask */ | |
742 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
743 | |
744 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
745 | in the SVR4 ELF ABI. */ | |
746 | ||
747 | /* 32 bit value resulting from the addend minus the symbol */ | |
748 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
08556813 MM |
749 | 0, /* rightshift */ |
750 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
751 | 32, /* bitsize */ | |
752 | false, /* pc_relative */ | |
753 | 0, /* bitpos */ | |
bcbe2c71 | 754 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 755 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 756 | "R_PPC_EMB_NADDR32", /* name */ |
08556813 MM |
757 | false, /* partial_inplace */ |
758 | 0, /* src_mask */ | |
759 | 0xffffffff, /* dst_mask */ | |
760 | false), /* pcrel_offset */ | |
bcbe2c71 | 761 | |
4500a112 | 762 | /* 16 bit value resulting from the addend minus the symbol */ |
bcbe2c71 | 763 | HOWTO (R_PPC_EMB_NADDR16, /* type */ |
08556813 MM |
764 | 0, /* rightshift */ |
765 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
766 | 16, /* bitsize */ | |
767 | false, /* pc_relative */ | |
768 | 0, /* bitpos */ | |
bcbe2c71 | 769 | complain_overflow_bitfield, /* complain_on_overflow */ |
bd2d10c0 | 770 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 771 | "R_PPC_EMB_NADDR16", /* name */ |
08556813 MM |
772 | false, /* partial_inplace */ |
773 | 0, /* src_mask */ | |
774 | 0xffff, /* dst_mask */ | |
775 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
776 | |
777 | /* 16 bit value resulting from the addend minus the symbol */ | |
778 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
08556813 MM |
779 | 0, /* rightshift */ |
780 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
781 | 16, /* bitsize */ | |
782 | false, /* pc_relative */ | |
783 | 0, /* bitpos */ | |
bcbe2c71 | 784 | complain_overflow_dont,/* complain_on_overflow */ |
bd2d10c0 | 785 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 786 | "R_PPC_EMB_ADDR16_LO", /* name */ |
08556813 MM |
787 | false, /* partial_inplace */ |
788 | 0, /* src_mask */ | |
789 | 0xffff, /* dst_mask */ | |
790 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
791 | |
792 | /* The high order 16 bits of the addend minus the symbol */ | |
793 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
08556813 MM |
794 | 16, /* rightshift */ |
795 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
796 | 16, /* bitsize */ | |
797 | false, /* pc_relative */ | |
798 | 0, /* bitpos */ | |
bcbe2c71 | 799 | complain_overflow_dont, /* complain_on_overflow */ |
bd2d10c0 | 800 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 801 | "R_PPC_EMB_NADDR16_HI", /* name */ |
08556813 MM |
802 | false, /* partial_inplace */ |
803 | 0, /* src_mask */ | |
804 | 0xffff, /* dst_mask */ | |
805 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
806 | |
807 | /* The high order 16 bits of the result of the addend minus the address, | |
808 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
809 | is negative. */ | |
810 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
08556813 MM |
811 | 16, /* rightshift */ |
812 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
813 | 16, /* bitsize */ | |
814 | false, /* pc_relative */ | |
815 | 0, /* bitpos */ | |
bcbe2c71 | 816 | complain_overflow_dont, /* complain_on_overflow */ |
bd2d10c0 | 817 | bfd_elf_generic_reloc, /* special_function */ |
bcbe2c71 | 818 | "R_PPC_EMB_NADDR16_HA", /* name */ |
08556813 MM |
819 | false, /* partial_inplace */ |
820 | 0, /* src_mask */ | |
821 | 0xffff, /* dst_mask */ | |
822 | false), /* pcrel_offset */ | |
823 | ||
4500a112 MM |
824 | /* 16 bit value resulting from allocating a 4 byte word to hold an |
825 | address in the .sdata section, and returning the offset from | |
826 | _SDA_BASE_ for that relocation */ | |
827 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
828 | 0, /* rightshift */ | |
829 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
830 | 16, /* bitsize */ | |
831 | false, /* pc_relative */ | |
832 | 0, /* bitpos */ | |
833 | complain_overflow_bitfield, /* complain_on_overflow */ | |
834 | bfd_elf_generic_reloc, /* special_function */ | |
835 | "R_PPC_EMB_SDAI16", /* name */ | |
836 | false, /* partial_inplace */ | |
837 | 0, /* src_mask */ | |
838 | 0xffff, /* dst_mask */ | |
839 | false), /* pcrel_offset */ | |
840 | ||
841 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
842 | address in the .sdata2 section, and returning the offset from | |
843 | _SDA2_BASE_ for that relocation */ | |
844 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
845 | 0, /* rightshift */ | |
846 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
847 | 16, /* bitsize */ | |
848 | false, /* pc_relative */ | |
849 | 0, /* bitpos */ | |
850 | complain_overflow_bitfield, /* complain_on_overflow */ | |
851 | bfd_elf_generic_reloc, /* special_function */ | |
852 | "R_PPC_EMB_SDA2I16", /* name */ | |
853 | false, /* partial_inplace */ | |
854 | 0, /* src_mask */ | |
855 | 0xffff, /* dst_mask */ | |
856 | false), /* pcrel_offset */ | |
857 | ||
858 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
859 | small data items. FIXME: Not supported. */ | |
860 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
861 | 0, /* rightshift */ | |
862 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
863 | 16, /* bitsize */ | |
864 | false, /* pc_relative */ | |
865 | 0, /* bitpos */ | |
866 | complain_overflow_signed, /* complain_on_overflow */ | |
867 | bfd_elf_generic_reloc, /* special_function */ | |
868 | "R_PPC_EMB_SDA2REL", /* name */ | |
869 | false, /* partial_inplace */ | |
870 | 0, /* src_mask */ | |
871 | 0xffff, /* dst_mask */ | |
872 | false), /* pcrel_offset */ | |
873 | ||
874 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
875 | signed offset from the appropriate base, and filling in the register | |
876 | field with the appropriate register (0, 2, or 13). */ | |
877 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
878 | 0, /* rightshift */ | |
879 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
880 | 16, /* bitsize */ | |
881 | false, /* pc_relative */ | |
882 | 0, /* bitpos */ | |
883 | complain_overflow_signed, /* complain_on_overflow */ | |
884 | bfd_elf_generic_reloc, /* special_function */ | |
885 | "R_PPC_EMB_SDA21", /* name */ | |
886 | false, /* partial_inplace */ | |
887 | 0, /* src_mask */ | |
888 | 0xffff, /* dst_mask */ | |
889 | false), /* pcrel_offset */ | |
890 | ||
891 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
892 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
893 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
894 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
895 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
896 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
897 | ||
898 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
899 | in the 16 bit signed offset from the appropriate base, and filling in the | |
900 | register field with the appropriate register (0, 2, or 13). */ | |
901 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
902 | 0, /* rightshift */ | |
903 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
904 | 16, /* bitsize */ | |
905 | true, /* pc_relative */ | |
906 | 0, /* bitpos */ | |
907 | complain_overflow_signed, /* complain_on_overflow */ | |
908 | bfd_elf_generic_reloc, /* special_function */ | |
909 | "R_PPC_EMB_RELSDA", /* name */ | |
910 | false, /* partial_inplace */ | |
911 | 0, /* src_mask */ | |
912 | 0xffff, /* dst_mask */ | |
913 | false), /* pcrel_offset */ | |
914 | ||
08556813 MM |
915 | /* Phony reloc to handle AIX style TOC entries */ |
916 | HOWTO (R_PPC_TOC16, /* type */ | |
917 | 0, /* rightshift */ | |
918 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
919 | 16, /* bitsize */ | |
920 | false, /* pc_relative */ | |
921 | 0, /* bitpos */ | |
922 | complain_overflow_signed, /* complain_on_overflow */ | |
07a159db | 923 | bfd_elf_generic_reloc, /* special_function */ |
08556813 MM |
924 | "R_PPC_TOC16", /* name */ |
925 | false, /* partial_inplace */ | |
926 | 0, /* src_mask */ | |
927 | 0xffff, /* dst_mask */ | |
928 | false), /* pcrel_offset */ | |
bcbe2c71 MM |
929 | }; |
930 | ||
ede4eed4 KR |
931 | \f |
932 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
933 | ||
934 | static void | |
935 | ppc_elf_howto_init () | |
936 | { | |
937 | unsigned int i, type; | |
938 | ||
939 | for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++) | |
940 | { | |
941 | type = ppc_elf_howto_raw[i].type; | |
942 | BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0])); | |
943 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
944 | } | |
945 | } | |
946 | ||
947 | \f | |
948 | static reloc_howto_type * | |
949 | ppc_elf_reloc_type_lookup (abfd, code) | |
950 | bfd *abfd; | |
951 | bfd_reloc_code_real_type code; | |
952 | { | |
08556813 | 953 | enum ppc_reloc_type ppc_reloc = R_PPC_NONE; |
02f85cda | 954 | |
ede4eed4 KR |
955 | if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */ |
956 | ppc_elf_howto_init (); | |
957 | ||
958 | switch ((int)code) | |
959 | { | |
02f85cda MM |
960 | default: |
961 | return (reloc_howto_type *)NULL; | |
962 | ||
963 | case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break; | |
964 | case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break; | |
965 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break; | |
966 | case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break; | |
967 | case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break; | |
968 | case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break; | |
969 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break; | |
970 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break; | |
971 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break; | |
972 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break; | |
973 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break; | |
974 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break; | |
975 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break; | |
976 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break; | |
08556813 | 977 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break; |
02f85cda MM |
978 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break; |
979 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break; | |
980 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break; | |
981 | case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break; | |
982 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break; | |
983 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break; | |
984 | case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break; | |
985 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break; | |
986 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break; | |
987 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break; | |
988 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break; | |
989 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break; | |
990 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break; | |
991 | case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break; | |
992 | case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break; | |
993 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break; | |
994 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break; | |
995 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break; | |
996 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break; | |
08556813 | 997 | case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break; |
4500a112 MM |
998 | case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break; |
999 | case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break; | |
1000 | case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break; | |
1001 | case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break; | |
1002 | case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break; | |
1003 | case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break; | |
1004 | case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break; | |
1005 | case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break; | |
1006 | case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break; | |
1007 | case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break; | |
1008 | case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break; | |
1009 | case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break; | |
1010 | case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break; | |
1011 | case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break; | |
1012 | case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break; | |
1013 | case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break; | |
ede4eed4 KR |
1014 | } |
1015 | ||
02f85cda | 1016 | return ppc_elf_howto_table[ (int)ppc_reloc ]; |
ede4eed4 KR |
1017 | }; |
1018 | ||
1019 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
1020 | ||
1021 | static void | |
1022 | ppc_elf_info_to_howto (abfd, cache_ptr, dst) | |
1023 | bfd *abfd; | |
1024 | arelent *cache_ptr; | |
1025 | Elf32_Internal_Rela *dst; | |
1026 | { | |
1027 | if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */ | |
1028 | ppc_elf_howto_init (); | |
1029 | ||
1030 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
1031 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
1032 | } | |
1033 | ||
1034 | /* Function to set whether a module needs the -mrelocatable bit set. */ | |
1035 | ||
1036 | static boolean | |
1037 | ppc_elf_set_private_flags (abfd, flags) | |
1038 | bfd *abfd; | |
1039 | flagword flags; | |
1040 | { | |
761f377f | 1041 | BFD_ASSERT (!elf_flags_init (abfd) |
ede4eed4 KR |
1042 | || elf_elfheader (abfd)->e_flags == flags); |
1043 | ||
1044 | elf_elfheader (abfd)->e_flags = flags; | |
761f377f | 1045 | elf_flags_init (abfd) = true; |
ede4eed4 KR |
1046 | return true; |
1047 | } | |
1048 | ||
1049 | /* Copy backend specific data from one object module to another */ | |
1050 | static boolean | |
1051 | ppc_elf_copy_private_bfd_data (ibfd, obfd) | |
1052 | bfd *ibfd; | |
1053 | bfd *obfd; | |
1054 | { | |
1055 | /* This function is selected based on the input vector. We only | |
1056 | want to copy information over if the output BFD also uses Elf | |
1057 | format. */ | |
1058 | if (bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
1059 | return true; | |
1060 | ||
761f377f | 1061 | BFD_ASSERT (!elf_flags_init (obfd) |
ede4eed4 KR |
1062 | || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags); |
1063 | ||
1064 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; | |
761f377f | 1065 | elf_flags_init (obfd) = true; |
ede4eed4 KR |
1066 | return true; |
1067 | } | |
1068 | ||
1069 | /* Merge backend specific data from an object file to the output | |
1070 | object file when linking */ | |
1071 | static boolean | |
1072 | ppc_elf_merge_private_bfd_data (ibfd, obfd) | |
1073 | bfd *ibfd; | |
1074 | bfd *obfd; | |
1075 | { | |
1076 | flagword old_flags; | |
1077 | flagword new_flags; | |
08556813 | 1078 | boolean error; |
ede4eed4 KR |
1079 | |
1080 | /* Check if we have the same endianess */ | |
07a159db MM |
1081 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder |
1082 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) | |
ede4eed4 | 1083 | { |
7a7fbffb | 1084 | (*_bfd_error_handler) |
07a159db | 1085 | ("%s: compiled for a %s endian system and target is %s endian", |
7a7fbffb | 1086 | bfd_get_filename (ibfd), |
08556813 MM |
1087 | bfd_big_endian (ibfd) ? "big" : "little", |
1088 | bfd_big_endian (obfd) ? "big" : "little"); | |
ede4eed4 KR |
1089 | |
1090 | bfd_set_error (bfd_error_wrong_format); | |
1091 | return false; | |
1092 | } | |
1093 | ||
1094 | /* This function is selected based on the input vector. We only | |
1095 | want to copy information over if the output BFD also uses Elf | |
1096 | format. */ | |
1097 | if (bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
1098 | return true; | |
1099 | ||
1100 | new_flags = elf_elfheader (ibfd)->e_flags; | |
1101 | old_flags = elf_elfheader (obfd)->e_flags; | |
761f377f | 1102 | if (!elf_flags_init (obfd)) /* First call, no flags set */ |
ede4eed4 | 1103 | { |
761f377f | 1104 | elf_flags_init (obfd) = true; |
ede4eed4 KR |
1105 | elf_elfheader (obfd)->e_flags = new_flags; |
1106 | } | |
1107 | ||
1108 | else if (new_flags == old_flags) /* Compatible flags are ok */ | |
1109 | ; | |
1110 | ||
1111 | else /* Incompatible flags */ | |
1112 | { | |
dd82c578 MM |
1113 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked |
1114 | with either. */ | |
08556813 | 1115 | error = false; |
dd82c578 MM |
1116 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 |
1117 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
ede4eed4 | 1118 | { |
08556813 | 1119 | error = true; |
7a7fbffb | 1120 | (*_bfd_error_handler) |
07a159db | 1121 | ("%s: compiled with -mrelocatable and linked with modules compiled normally", |
7a7fbffb | 1122 | bfd_get_filename (ibfd)); |
ede4eed4 | 1123 | } |
08eb30b6 | 1124 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 |
dd82c578 | 1125 | && (old_flags & EF_PPC_RELOCATABLE) != 0) |
ede4eed4 | 1126 | { |
08556813 | 1127 | error = true; |
7a7fbffb | 1128 | (*_bfd_error_handler) |
07a159db | 1129 | ("%s: compiled normally and linked with modules compiled with -mrelocatable", |
7a7fbffb | 1130 | bfd_get_filename (ibfd)); |
ede4eed4 | 1131 | } |
dd82c578 MM |
1132 | else if ((new_flags & EF_PPC_RELOCATABLE_LIB) != 0) |
1133 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE_LIB; | |
1134 | ||
1135 | new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB); | |
1136 | old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB); | |
ede4eed4 KR |
1137 | |
1138 | /* Warn about eabi vs. V.4 mismatch */ | |
1139 | if ((new_flags & EF_PPC_EMB) != 0 && (old_flags & EF_PPC_EMB) == 0) | |
1140 | { | |
1141 | new_flags &= ~EF_PPC_EMB; | |
08556813 | 1142 | error = true; |
7a7fbffb | 1143 | (*_bfd_error_handler) |
07a159db | 1144 | ("%s: compiled for the eabi and linked with modules compiled for System V", |
7a7fbffb | 1145 | bfd_get_filename (ibfd)); |
ede4eed4 KR |
1146 | } |
1147 | else if ((new_flags & EF_PPC_EMB) == 0 && (old_flags & EF_PPC_EMB) != 0) | |
1148 | { | |
1149 | old_flags &= ~EF_PPC_EMB; | |
08556813 | 1150 | error = true; |
7a7fbffb | 1151 | (*_bfd_error_handler) |
07a159db | 1152 | ("%s: compiled for System V and linked with modules compiled for eabi", |
7a7fbffb | 1153 | bfd_get_filename (ibfd)); |
ede4eed4 KR |
1154 | } |
1155 | ||
1156 | /* Warn about any other mismatches */ | |
1157 | if (new_flags != old_flags) | |
08556813 MM |
1158 | { |
1159 | error = true; | |
1160 | (*_bfd_error_handler) | |
07a159db | 1161 | ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)", |
08556813 MM |
1162 | bfd_get_filename (ibfd), (long)new_flags, (long)old_flags); |
1163 | } | |
ede4eed4 | 1164 | |
08556813 MM |
1165 | if (error) |
1166 | { | |
1167 | bfd_set_error (bfd_error_bad_value); | |
1168 | return false; | |
1169 | } | |
ede4eed4 KR |
1170 | } |
1171 | ||
1172 | return true; | |
1173 | } | |
1174 | ||
83f4323e MM |
1175 | \f |
1176 | /* Handle a PowerPC specific section when reading an object file. This | |
1177 | is called when elfcode.h finds a section with an unknown type. */ | |
1178 | ||
1179 | static boolean | |
1180 | ppc_elf_section_from_shdr (abfd, hdr, name) | |
1181 | bfd *abfd; | |
1182 | Elf32_Internal_Shdr *hdr; | |
1183 | char *name; | |
1184 | { | |
1185 | asection *newsect; | |
1186 | flagword flags; | |
1187 | ||
1188 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | |
1189 | return false; | |
1190 | ||
1191 | newsect = hdr->bfd_section; | |
1192 | flags = bfd_get_section_flags (abfd, newsect); | |
1193 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1194 | flags |= SEC_EXCLUDE; | |
1195 | ||
1196 | if (hdr->sh_type == SHT_ORDERED) | |
1197 | flags |= SEC_SORT_ENTRIES; | |
1198 | ||
1199 | bfd_set_section_flags (abfd, newsect, flags); | |
1200 | return true; | |
1201 | } | |
1202 | ||
57081126 MM |
1203 | \f |
1204 | /* Set up any other section flags and such that may be necessary. */ | |
1205 | ||
1206 | boolean | |
1207 | ppc_elf_fake_sections (abfd, shdr, asect) | |
1208 | bfd *abfd; | |
1209 | Elf32_Internal_Shdr *shdr; | |
1210 | asection *asect; | |
1211 | { | |
1212 | if ((asect->flags & SEC_EXCLUDE) != 0) | |
1213 | shdr->sh_flags |= SHF_EXCLUDE; | |
1214 | ||
1215 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
1216 | shdr->sh_type = SHT_ORDERED; | |
1217 | } | |
1218 | ||
1c3a295b MM |
1219 | \f |
1220 | /* Create the PowerPC dynamic sections */ | |
1221 | ||
1222 | static bfd * | |
1223 | ppc_elf_create_dynamic_sections (abfd, info) | |
1224 | bfd *abfd; | |
1225 | struct bfd_link_info *info; | |
1226 | { | |
1227 | struct elf_link_hash_entry *h; | |
1228 | struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
1229 | ||
1230 | /* Create the .got section. */ | |
1231 | if (! _bfd_elf_create_got_section (abfd, info)) | |
1232 | return (bfd *)0; | |
1233 | ||
1234 | /* Also create the .got.neg section where we put negative offsets */ | |
1235 | if (bfd_get_section_by_name (abfd, ".got.neg") == NULL) | |
1236 | { | |
1237 | asection *s = bfd_make_section (abfd, ".got.neg"); | |
1238 | if (s == NULL | |
1239 | || !bfd_set_section_flags (abfd, s, | |
1240 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY) | |
1241 | || !bfd_set_section_alignment (abfd, s, 2)) | |
1242 | return (bfd *)0; | |
1243 | } | |
1244 | ||
1245 | elf_hash_table (info)->dynobj = abfd; | |
1246 | return abfd; | |
1247 | } | |
1248 | ||
08556813 MM |
1249 | \f |
1250 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
1251 | regular object. The current definition is in some section of the | |
1252 | dynamic object, but we're not including those sections. We have to | |
1253 | change the definition to something the rest of the link can | |
1254 | understand. */ | |
1255 | ||
1256 | static boolean | |
1257 | ppc_elf_adjust_dynamic_symbol (info, h) | |
1258 | struct bfd_link_info *info; | |
1259 | struct elf_link_hash_entry *h; | |
1260 | { | |
1261 | #ifdef DEBUG | |
1262 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called\n"); | |
1263 | #endif | |
1264 | return true; | |
1265 | } | |
1266 | ||
1267 | \f | |
1268 | /* Increment the index of a dynamic symbol by a given amount. Called | |
1269 | via elf_link_hash_traverse. */ | |
1270 | ||
1271 | static boolean | |
1272 | ppc_elf_adjust_dynindx (h, cparg) | |
1273 | struct elf_link_hash_entry *h; | |
1274 | PTR cparg; | |
1275 | { | |
1276 | int *cp = (int *) cparg; | |
1277 | ||
1278 | #ifdef DEBUG | |
1279 | fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp); | |
1280 | #endif | |
1281 | ||
1282 | if (h->dynindx != -1) | |
1283 | h->dynindx += *cp; | |
1284 | ||
1285 | return true; | |
1286 | } | |
1287 | ||
1288 | \f | |
1289 | /* Set the sizes of the dynamic sections. */ | |
1290 | ||
1291 | static boolean | |
1292 | ppc_elf_size_dynamic_sections (output_bfd, info) | |
1293 | bfd *output_bfd; | |
1294 | struct bfd_link_info *info; | |
1295 | { | |
1296 | bfd *dynobj; | |
1297 | asection *s; | |
1298 | boolean reltext; | |
1299 | boolean relplt; | |
1300 | ||
1301 | #ifdef DEBUG | |
1302 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); | |
1303 | #endif | |
1304 | ||
1305 | dynobj = elf_hash_table (info)->dynobj; | |
1306 | BFD_ASSERT (dynobj != NULL); | |
1307 | ||
1308 | if (elf_hash_table (info)->dynamic_sections_created) | |
1309 | { | |
1310 | /* Set the contents of the .interp section to the interpreter. */ | |
1311 | if (! info->shared) | |
1312 | { | |
1313 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
1314 | BFD_ASSERT (s != NULL); | |
1315 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
1316 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
1317 | } | |
1318 | ||
1319 | /* Make space for the trailing nop in .plt. */ | |
1320 | s = bfd_get_section_by_name (dynobj, ".plt"); | |
1321 | BFD_ASSERT (s != NULL); | |
1322 | if (s->_raw_size > 0) | |
1323 | s->_raw_size += 4; | |
1324 | } | |
1325 | else | |
1326 | { | |
1327 | /* We may have created entries in the .rela.got section. | |
1328 | However, if we are not creating the dynamic sections, we will | |
1329 | not actually use these entries. Reset the size of .rela.got, | |
1330 | which will cause it to get stripped from the output file | |
1331 | below. */ | |
1332 | s = bfd_get_section_by_name (dynobj, ".rela.got"); | |
1333 | if (s != NULL) | |
1334 | s->_raw_size = 0; | |
1c3a295b MM |
1335 | |
1336 | /* Ditto for .rela.got.neg */ | |
1337 | s = bfd_get_section_by_name (dynobj, ".rela.got.neg"); | |
1338 | if (s != NULL) | |
1339 | s->_raw_size = 0; | |
08556813 MM |
1340 | } |
1341 | ||
1342 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
1343 | determined the sizes of the various dynamic sections. Allocate | |
1344 | memory for them. */ | |
1345 | reltext = false; | |
1346 | relplt = false; | |
1347 | for (s = dynobj->sections; s != NULL; s = s->next) | |
1348 | { | |
1349 | const char *name; | |
1350 | boolean strip; | |
1351 | ||
1352 | if ((s->flags & SEC_IN_MEMORY) == 0) | |
1353 | continue; | |
1354 | ||
1355 | /* It's OK to base decisions on the section name, because none | |
1356 | of the dynobj section names depend upon the input files. */ | |
1357 | name = bfd_get_section_name (dynobj, s); | |
1358 | ||
1359 | strip = false; | |
1360 | ||
1361 | if (strncmp (name, ".rela", 5) == 0) | |
1362 | { | |
1363 | if (s->_raw_size == 0) | |
1364 | { | |
1365 | /* If we don't need this section, strip it from the | |
1366 | output file. This is to handle .rela.bss and | |
1367 | .rel.plt. We must create it in | |
1368 | create_dynamic_sections, because it must be created | |
1369 | before the linker maps input sections to output | |
1370 | sections. The linker does that before | |
1371 | adjust_dynamic_symbol is called, and it is that | |
1372 | function which decides whether anything needs to go | |
1373 | into these sections. */ | |
1374 | strip = true; | |
1375 | } | |
1376 | else | |
1377 | { | |
1378 | asection *target; | |
1379 | ||
1380 | /* If this relocation section applies to a read only | |
1381 | section, then we probably need a DT_TEXTREL entry. */ | |
1382 | target = bfd_get_section_by_name (output_bfd, name + 5); | |
1383 | if (target != NULL | |
1384 | && (target->flags & SEC_READONLY) != 0) | |
1385 | reltext = true; | |
1386 | ||
1387 | if (strcmp (name, ".rela.plt") == 0) | |
1388 | relplt = true; | |
1389 | ||
1390 | /* We use the reloc_count field as a counter if we need | |
1391 | to copy relocs into the output file. */ | |
1392 | s->reloc_count = 0; | |
1393 | } | |
1394 | } | |
1395 | else if (strcmp (name, ".plt") != 0 | |
1c3a295b MM |
1396 | && strcmp (name, ".got") != 0 |
1397 | && strcmp (name, ".got.neg") != 0) | |
08556813 MM |
1398 | { |
1399 | /* It's not one of our sections, so don't allocate space. */ | |
1400 | continue; | |
1401 | } | |
1402 | ||
1403 | if (strip) | |
1404 | { | |
1405 | asection **spp; | |
1406 | ||
1407 | for (spp = &s->output_section->owner->sections; | |
1408 | *spp != s->output_section; | |
1409 | spp = &(*spp)->next) | |
1410 | ; | |
1411 | *spp = s->output_section->next; | |
1412 | --s->output_section->owner->section_count; | |
1413 | ||
1414 | continue; | |
1415 | } | |
1416 | ||
1417 | /* Allocate memory for the section contents. */ | |
1418 | s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size); | |
1419 | if (s->contents == NULL && s->_raw_size != 0) | |
1420 | return false; | |
1421 | } | |
1422 | ||
1423 | if (elf_hash_table (info)->dynamic_sections_created) | |
1424 | { | |
1425 | /* Add some entries to the .dynamic section. We fill in the | |
1426 | values later, in ppc_elf_finish_dynamic_sections, but we | |
1427 | must add the entries now so that we get the correct size for | |
1428 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
1429 | dynamic linker and used by the debugger. */ | |
1430 | if (! info->shared) | |
1431 | { | |
1432 | if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0)) | |
1433 | return false; | |
1434 | } | |
1435 | ||
1436 | if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)) | |
1437 | return false; | |
1438 | ||
1439 | if (relplt) | |
1440 | { | |
1441 | if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0) | |
1442 | || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA) | |
1443 | || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0)) | |
1444 | return false; | |
1445 | } | |
1446 | ||
1447 | if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0) | |
1448 | || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0) | |
1449 | || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT, | |
1450 | sizeof (Elf32_External_Rela))) | |
1451 | return false; | |
1452 | ||
1453 | if (reltext) | |
1454 | { | |
1455 | if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0)) | |
1456 | return false; | |
1457 | } | |
1458 | } | |
1459 | ||
1460 | /* If we are generating a shared library, we generate a section | |
1461 | symbol for each output section. These are local symbols, which | |
1462 | means that they must come first in the dynamic symbol table. | |
1463 | That means we must increment the dynamic symbol index of every | |
1464 | other dynamic symbol. */ | |
1465 | if (info->shared) | |
1466 | { | |
1467 | int c, i; | |
1468 | ||
1469 | c = bfd_count_sections (output_bfd); | |
1470 | elf_link_hash_traverse (elf_hash_table (info), | |
1471 | ppc_elf_adjust_dynindx, | |
1472 | (PTR) &c); | |
1473 | elf_hash_table (info)->dynsymcount += c; | |
1474 | ||
1475 | for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++) | |
1476 | { | |
1477 | elf_section_data (s)->dynindx = i; | |
1478 | /* These symbols will have no names, so we don't need to | |
1479 | fiddle with dynstr_index. */ | |
1480 | } | |
1481 | } | |
1482 | ||
1483 | return true; | |
1484 | } | |
1485 | ||
1486 | \f | |
1487 | /* Look through the relocs for a section during the first phase, and | |
1488 | allocate space in the global offset table or procedure linkage | |
1489 | table. */ | |
1490 | ||
1491 | static boolean | |
1492 | ppc_elf_check_relocs (abfd, info, sec, relocs) | |
1493 | bfd *abfd; | |
1494 | struct bfd_link_info *info; | |
1495 | asection *sec; | |
1496 | const Elf_Internal_Rela *relocs; | |
1497 | { | |
1498 | bfd *dynobj; | |
1499 | Elf_Internal_Shdr *symtab_hdr; | |
1500 | struct elf_link_hash_entry **sym_hashes; | |
1501 | bfd_vma *local_got_offsets; | |
1502 | const Elf_Internal_Rela *rel; | |
1503 | const Elf_Internal_Rela *rel_end; | |
1504 | asection *sgot; | |
1c3a295b | 1505 | asection *sgot_neg; |
08556813 | 1506 | asection *srelgot; |
1c3a295b | 1507 | asection *srelgot_neg; |
08556813 MM |
1508 | asection *sreloc; |
1509 | ||
1510 | if (info->relocateable) | |
1511 | return true; | |
1512 | ||
1513 | #ifdef DEBUG | |
1514 | fprintf (stderr, "ppc_elf_check_relocs called for section %s\n", sec->name); | |
1515 | #endif | |
1516 | ||
1517 | dynobj = elf_hash_table (info)->dynobj; | |
1518 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
1519 | sym_hashes = elf_sym_hashes (abfd); | |
1520 | local_got_offsets = elf_local_got_offsets (abfd); | |
1521 | ||
1522 | sgot = NULL; | |
1523 | srelgot = NULL; | |
1524 | sreloc = NULL; | |
1525 | ||
1526 | rel_end = relocs + sec->reloc_count; | |
1527 | for (rel = relocs; rel < rel_end; rel++) | |
1528 | { | |
1529 | unsigned long r_symndx; | |
1530 | struct elf_link_hash_entry *h; | |
1531 | ||
1532 | r_symndx = ELF32_R_SYM (rel->r_info); | |
1533 | if (r_symndx < symtab_hdr->sh_info) | |
1534 | h = NULL; | |
1535 | else | |
1536 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1537 | ||
1538 | switch (ELF32_R_TYPE (rel->r_info)) | |
1539 | { | |
1540 | case R_PPC_GOT16: | |
1541 | case R_PPC_GOT16_LO: | |
1542 | case R_PPC_GOT16_HI: | |
1543 | case R_PPC_GOT16_HA: | |
1544 | #ifdef DEBUG | |
1545 | fprintf (stderr, "Reloc requires a GOT entry\n"); | |
1546 | #endif | |
1547 | /* This symbol requires a global offset table entry. */ | |
1548 | ||
1549 | if (dynobj == NULL) | |
1550 | { | |
1c3a295b MM |
1551 | dynobj = ppc_elf_create_dynamic_sections (abfd, info); |
1552 | if (!dynobj) | |
08556813 MM |
1553 | return false; |
1554 | } | |
1555 | ||
1556 | if (sgot == NULL) | |
1557 | { | |
1558 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
1c3a295b MM |
1559 | sgot_neg = bfd_get_section_by_name (dynobj, ".got.neg"); |
1560 | BFD_ASSERT (sgot != NULL && sgot_neg != NULL); | |
08556813 MM |
1561 | } |
1562 | ||
1563 | if (srelgot == NULL | |
1564 | && (h != NULL || info->shared)) | |
1565 | { | |
1566 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
1567 | if (srelgot == NULL) | |
1568 | { | |
1569 | srelgot = bfd_make_section (dynobj, ".rela.got"); | |
1570 | if (srelgot == NULL | |
1571 | || ! bfd_set_section_flags (dynobj, srelgot, | |
1572 | (SEC_ALLOC | |
1573 | | SEC_LOAD | |
1574 | | SEC_HAS_CONTENTS | |
1575 | | SEC_IN_MEMORY | |
1576 | | SEC_READONLY)) | |
1577 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | |
1578 | return false; | |
1579 | } | |
1c3a295b MM |
1580 | |
1581 | srelgot_neg = bfd_get_section_by_name (dynobj, ".rela.got.neg"); | |
1582 | if (srelgot_neg == NULL) | |
1583 | { | |
1584 | srelgot_neg = bfd_make_section (dynobj, ".rela.got.neg"); | |
1585 | if (srelgot == NULL | |
1586 | || ! bfd_set_section_flags (dynobj, srelgot_neg, | |
1587 | (SEC_ALLOC | |
1588 | | SEC_LOAD | |
1589 | | SEC_HAS_CONTENTS | |
1590 | | SEC_IN_MEMORY | |
1591 | | SEC_READONLY)) | |
1592 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | |
1593 | return false; | |
1594 | } | |
08556813 MM |
1595 | } |
1596 | ||
1597 | if (h != NULL) | |
1598 | { | |
1599 | if (h->got_offset != (bfd_vma) -1) | |
1600 | { | |
1601 | /* We have already allocated space in the .got. */ | |
1602 | break; | |
1603 | } | |
1604 | h->got_offset = sgot->_raw_size; | |
1605 | ||
1606 | /* Make sure this symbol is output as a dynamic symbol. */ | |
1607 | if (h->dynindx == -1) | |
1608 | { | |
1609 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
1610 | return false; | |
1611 | } | |
1612 | ||
1613 | srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
1614 | } | |
1615 | else | |
1616 | { | |
1617 | /* This is a global offset table entry for a local | |
1618 | symbol. */ | |
1619 | if (local_got_offsets == NULL) | |
1620 | { | |
1621 | size_t size; | |
1622 | register unsigned int i; | |
1623 | ||
1624 | size = symtab_hdr->sh_info * sizeof (bfd_vma); | |
1625 | local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size); | |
1626 | if (local_got_offsets == NULL) | |
1627 | return false; | |
1628 | elf_local_got_offsets (abfd) = local_got_offsets; | |
1629 | for (i = 0; i < symtab_hdr->sh_info; i++) | |
1630 | local_got_offsets[i] = (bfd_vma) -1; | |
1631 | } | |
1632 | if (local_got_offsets[r_symndx] != (bfd_vma) -1) | |
1633 | { | |
1634 | /* We have already allocated space in the .got. */ | |
1635 | break; | |
1636 | } | |
1637 | local_got_offsets[r_symndx] = sgot->_raw_size; | |
1638 | ||
1639 | if (info->shared) | |
1640 | { | |
1641 | /* If we are generating a shared object, we need to | |
07a159db | 1642 | output a R_PPC_RELATIVE reloc so that the |
08556813 MM |
1643 | dynamic linker can adjust this GOT entry. */ |
1644 | srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
1645 | } | |
1646 | } | |
1647 | ||
1648 | sgot->_raw_size += 4; | |
1649 | ||
1650 | break; | |
1651 | ||
1652 | case R_PPC_PLT32: | |
1653 | case R_PPC_PLTREL24: | |
1654 | case R_PPC_PLT16_LO: | |
1655 | case R_PPC_PLT16_HI: | |
1656 | case R_PPC_PLT16_HA: | |
1657 | #ifdef DEBUG | |
1658 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
1659 | #endif | |
1660 | /* This symbol requires a procedure linkage table entry. We | |
1661 | actually build the entry in adjust_dynamic_symbol, | |
1662 | because this might be a case of linking PIC code without | |
1663 | linking in any dynamic objects, in which case we don't | |
1664 | need to generate a procedure linkage table after all. */ | |
1665 | ||
1666 | if (h == NULL) | |
1667 | { | |
1668 | /* It does not make sense to have a procedure linkage | |
1669 | table entry for a local symbol. */ | |
1670 | bfd_set_error (bfd_error_bad_value); | |
1671 | return false; | |
1672 | } | |
1673 | ||
1674 | /* Make sure this symbol is output as a dynamic symbol. */ | |
1675 | if (h->dynindx == -1) | |
1676 | { | |
1677 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
1678 | return false; | |
1679 | } | |
1680 | ||
1681 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
1682 | break; | |
1683 | ||
1684 | #if 0 | |
1685 | case R_SPARC_PC10: | |
1686 | case R_SPARC_PC22: | |
1687 | if (h != NULL | |
1688 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
1689 | break; | |
1690 | /* Fall through. */ | |
1691 | case R_SPARC_DISP8: | |
1692 | case R_SPARC_DISP16: | |
1693 | case R_SPARC_DISP32: | |
1694 | case R_SPARC_WDISP30: | |
1695 | case R_SPARC_WDISP22: | |
1696 | if (h == NULL) | |
1697 | break; | |
1698 | /* Fall through. */ | |
1699 | case R_SPARC_8: | |
1700 | case R_SPARC_16: | |
1701 | case R_SPARC_32: | |
1702 | case R_SPARC_HI22: | |
1703 | case R_SPARC_22: | |
1704 | case R_SPARC_13: | |
1705 | case R_SPARC_LO10: | |
1706 | case R_SPARC_UA32: | |
1707 | if (info->shared | |
1708 | && (sec->flags & SEC_ALLOC) != 0) | |
1709 | { | |
1710 | /* When creating a shared object, we must copy these | |
1711 | relocs into the output file. We create a reloc | |
1712 | section in dynobj and make room for the reloc. */ | |
1713 | if (sreloc == NULL) | |
1714 | { | |
1715 | const char *name; | |
1716 | ||
1717 | name = (bfd_elf_string_from_elf_section | |
1718 | (abfd, | |
1719 | elf_elfheader (abfd)->e_shstrndx, | |
1720 | elf_section_data (sec)->rel_hdr.sh_name)); | |
1721 | if (name == NULL) | |
1722 | return false; | |
1723 | ||
1724 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
1725 | && strcmp (bfd_get_section_name (abfd, sec), | |
1726 | name + 5) == 0); | |
1727 | ||
1728 | sreloc = bfd_get_section_by_name (dynobj, name); | |
1729 | if (sreloc == NULL) | |
1730 | { | |
1731 | sreloc = bfd_make_section (dynobj, name); | |
1732 | if (sreloc == NULL | |
1733 | || ! bfd_set_section_flags (dynobj, sreloc, | |
1734 | (SEC_ALLOC | |
1735 | | SEC_LOAD | |
1736 | | SEC_HAS_CONTENTS | |
1737 | | SEC_IN_MEMORY | |
1738 | | SEC_READONLY)) | |
1739 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) | |
1740 | return false; | |
1741 | } | |
1742 | } | |
1743 | ||
1744 | sreloc->_raw_size += sizeof (Elf32_External_Rela); | |
1745 | } | |
1746 | ||
1747 | break; | |
1748 | #endif | |
1749 | ||
1750 | default: | |
1751 | break; | |
1752 | } | |
1753 | } | |
1754 | ||
1755 | return true; | |
1756 | } | |
1757 | ||
1758 | \f | |
1759 | /* Finish up dynamic symbol handling. We set the contents of various | |
1760 | dynamic sections here. */ | |
1761 | ||
1762 | static boolean | |
1763 | ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym) | |
1764 | bfd *output_bfd; | |
1765 | struct bfd_link_info *info; | |
1766 | struct elf_link_hash_entry *h; | |
1767 | Elf_Internal_Sym *sym; | |
1768 | { | |
1769 | bfd *dynobj; | |
1770 | ||
1771 | #ifdef DEBUG | |
1772 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called\n"); | |
1773 | #endif | |
1774 | ||
1775 | dynobj = elf_hash_table (info)->dynobj; | |
1776 | ||
1777 | if (h->plt_offset != (bfd_vma) -1) | |
1778 | { | |
1779 | asection *splt; | |
1780 | asection *srela; | |
1781 | Elf_Internal_Rela rela; | |
1782 | ||
1783 | /* This symbol has an entry in the procedure linkage table. Set | |
1784 | it up. */ | |
1785 | ||
1786 | BFD_ASSERT (h->dynindx != -1); | |
1787 | ||
1788 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1789 | srela = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
1790 | BFD_ASSERT (splt != NULL && srela != NULL); | |
1791 | ||
1792 | /* Fill in the entry in the procedure linkage table. */ | |
1793 | #if 0 | |
1794 | bfd_put_32 (output_bfd, | |
1795 | PLT_ENTRY_WORD0 + h->plt_offset, | |
1796 | splt->contents + h->plt_offset); | |
1797 | bfd_put_32 (output_bfd, | |
1798 | (PLT_ENTRY_WORD1 | |
1799 | + (((- (h->plt_offset + 4)) >> 2) & 0x3fffff)), | |
1800 | splt->contents + h->plt_offset + 4); | |
1801 | bfd_put_32 (output_bfd, PLT_ENTRY_WORD2, | |
1802 | splt->contents + h->plt_offset + 8); | |
1803 | ||
1804 | /* Fill in the entry in the .rela.plt section. */ | |
1805 | rela.r_offset = (splt->output_section->vma | |
1806 | + splt->output_offset | |
1807 | + h->plt_offset); | |
1808 | rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT); | |
1809 | rela.r_addend = 0; | |
1810 | bfd_elf32_swap_reloca_out (output_bfd, &rela, | |
1811 | ((Elf32_External_Rela *) srela->contents | |
1812 | + h->plt_offset / PLT_ENTRY_SIZE - 4)); | |
1813 | #endif | |
1814 | ||
1815 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1816 | { | |
1817 | /* Mark the symbol as undefined, rather than as defined in | |
1818 | the .plt section. Leave the value alone. */ | |
1819 | sym->st_shndx = SHN_UNDEF; | |
1820 | } | |
1821 | } | |
1822 | ||
1823 | if (h->got_offset != (bfd_vma) -1) | |
1824 | { | |
1825 | asection *sgot; | |
1826 | asection *srela; | |
1827 | Elf_Internal_Rela rela; | |
1828 | ||
1829 | /* This symbol has an entry in the global offset table. Set it | |
1830 | up. */ | |
1831 | ||
1832 | BFD_ASSERT (h->dynindx != -1); | |
1833 | ||
1834 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
1835 | srela = bfd_get_section_by_name (dynobj, ".rela.got"); | |
1836 | BFD_ASSERT (sgot != NULL && srela != NULL); | |
1837 | ||
1838 | rela.r_offset = (sgot->output_section->vma | |
1839 | + sgot->output_offset | |
1840 | + (h->got_offset &~ 1)); | |
1841 | ||
1842 | /* If this is a -Bsymbolic link, and the symbol is defined | |
1843 | locally, we just want to emit a RELATIVE reloc. The entry in | |
1844 | the global offset table will already have been initialized in | |
1845 | the relocate_section function. */ | |
1846 | if (info->shared | |
1847 | && info->symbolic | |
1848 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
1849 | rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
1850 | else | |
1851 | { | |
1852 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got_offset); | |
1853 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT); | |
1854 | } | |
1855 | ||
1856 | rela.r_addend = 0; | |
1857 | bfd_elf32_swap_reloca_out (output_bfd, &rela, | |
1858 | ((Elf32_External_Rela *) srela->contents | |
1859 | + srela->reloc_count)); | |
1860 | ++srela->reloc_count; | |
1861 | } | |
1862 | ||
1863 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
1864 | { | |
1865 | asection *s; | |
1866 | Elf_Internal_Rela rela; | |
1867 | ||
1868 | /* This symbols needs a copy reloc. Set it up. */ | |
1869 | ||
1870 | BFD_ASSERT (h->dynindx != -1); | |
1871 | ||
1872 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
1873 | ".rela.bss"); | |
1874 | BFD_ASSERT (s != NULL); | |
1875 | ||
1876 | rela.r_offset = (h->root.u.def.value | |
1877 | + h->root.u.def.section->output_section->vma | |
1878 | + h->root.u.def.section->output_offset); | |
1879 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); | |
1880 | rela.r_addend = 0; | |
1881 | bfd_elf32_swap_reloca_out (output_bfd, &rela, | |
1882 | ((Elf32_External_Rela *) s->contents | |
1883 | + s->reloc_count)); | |
1884 | ++s->reloc_count; | |
1885 | } | |
1886 | ||
1887 | /* Mark some specially defined symbols as absolute. */ | |
1888 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
1889 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 | |
1890 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) | |
1891 | sym->st_shndx = SHN_ABS; | |
1892 | ||
1893 | return true; | |
1894 | } | |
1895 | ||
1896 | \f | |
1897 | /* Finish up the dynamic sections. */ | |
1898 | ||
1899 | static boolean | |
1900 | ppc_elf_finish_dynamic_sections (output_bfd, info) | |
1901 | bfd *output_bfd; | |
1902 | struct bfd_link_info *info; | |
1903 | { | |
1904 | bfd *dynobj; | |
1905 | asection *sdyn; | |
1906 | asection *sgot; | |
1907 | ||
1908 | #ifdef DEBUG | |
1909 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
1910 | #endif | |
1911 | ||
1912 | dynobj = elf_hash_table (info)->dynobj; | |
1913 | ||
1914 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
1915 | ||
1916 | if (elf_hash_table (info)->dynamic_sections_created) | |
1917 | { | |
1918 | asection *splt; | |
1919 | Elf32_External_Dyn *dyncon, *dynconend; | |
1920 | ||
1921 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1922 | BFD_ASSERT (splt != NULL && sdyn != NULL); | |
1923 | ||
1924 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
1925 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
1926 | for (; dyncon < dynconend; dyncon++) | |
1927 | { | |
1928 | Elf_Internal_Dyn dyn; | |
1929 | const char *name; | |
1930 | boolean size; | |
1931 | ||
1932 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
1933 | ||
1934 | switch (dyn.d_tag) | |
1935 | { | |
1936 | case DT_PLTGOT: name = ".plt"; size = false; break; | |
1937 | case DT_PLTRELSZ: name = ".rela.plt"; size = true; break; | |
1938 | case DT_JMPREL: name = ".rela.plt"; size = false; break; | |
1939 | default: name = NULL; size = false; break; | |
1940 | } | |
1941 | ||
1942 | if (name != NULL) | |
1943 | { | |
1944 | asection *s; | |
1945 | ||
1946 | s = bfd_get_section_by_name (output_bfd, name); | |
1947 | if (s == NULL) | |
1948 | dyn.d_un.d_val = 0; | |
1949 | else | |
1950 | { | |
1951 | if (! size) | |
1952 | dyn.d_un.d_ptr = s->vma; | |
1953 | else | |
1954 | { | |
1955 | if (s->_cooked_size != 0) | |
1956 | dyn.d_un.d_val = s->_cooked_size; | |
1957 | else | |
1958 | dyn.d_un.d_val = s->_raw_size; | |
1959 | } | |
1960 | } | |
1961 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
1962 | } | |
1963 | } | |
1964 | ||
1965 | /* Clear the first four entries in the procedure linkage table, | |
1966 | and put a nop in the last four bytes. */ | |
1967 | #if 0 | |
1968 | if (splt->_raw_size > 0) | |
1969 | { | |
1970 | memset (splt->contents, 0, 4 * PLT_ENTRY_SIZE); | |
1971 | bfd_put_32 (output_bfd, SPARC_NOP, | |
1972 | splt->contents + splt->_raw_size - 4); | |
1973 | } | |
1974 | ||
1975 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = | |
1976 | PLT_ENTRY_SIZE; | |
1977 | #endif | |
1978 | } | |
1979 | ||
1980 | /* Set the first entry in the global offset table to the address of | |
1981 | the dynamic section. */ | |
1982 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
1983 | BFD_ASSERT (sgot != NULL); | |
1984 | if (sgot->_raw_size > 0) | |
1985 | { | |
1986 | if (sdyn == NULL) | |
1987 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
1988 | else | |
1989 | bfd_put_32 (output_bfd, | |
1990 | sdyn->output_section->vma + sdyn->output_offset, | |
1991 | sgot->contents); | |
1992 | } | |
1993 | ||
1994 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; | |
1995 | ||
1996 | if (info->shared) | |
1997 | { | |
1998 | asection *sdynsym; | |
1999 | asection *s; | |
2000 | Elf_Internal_Sym sym; | |
2001 | ||
2002 | /* Set up the section symbols for the output sections. */ | |
2003 | ||
2004 | sdynsym = bfd_get_section_by_name (dynobj, ".dynsym"); | |
2005 | BFD_ASSERT (sdynsym != NULL); | |
2006 | ||
2007 | sym.st_size = 0; | |
2008 | sym.st_name = 0; | |
2009 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); | |
2010 | sym.st_other = 0; | |
2011 | ||
2012 | for (s = output_bfd->sections; s != NULL; s = s->next) | |
2013 | { | |
2014 | int indx; | |
2015 | ||
2016 | sym.st_value = s->vma; | |
2017 | ||
2018 | indx = elf_section_data (s)->this_idx; | |
2019 | BFD_ASSERT (indx > 0); | |
2020 | sym.st_shndx = indx; | |
2021 | ||
2022 | bfd_elf32_swap_symbol_out (output_bfd, &sym, | |
2023 | (PTR) (((Elf32_External_Sym *) | |
2024 | sdynsym->contents) | |
2025 | + elf_section_data (s)->dynindx)); | |
2026 | } | |
2027 | ||
2028 | /* Set the sh_info field of the output .dynsym section to the | |
2029 | index of the first global symbol. */ | |
2030 | elf_section_data (sdynsym->output_section)->this_hdr.sh_info = | |
2031 | bfd_count_sections (output_bfd) + 1; | |
2032 | } | |
2033 | ||
2034 | return true; | |
2035 | } | |
2036 | ||
ede4eed4 KR |
2037 | \f |
2038 | /* The RELOCATE_SECTION function is called by the ELF backend linker | |
2039 | to handle the relocations for a section. | |
bcbe2c71 | 2040 | |
ede4eed4 KR |
2041 | The relocs are always passed as Rela structures; if the section |
2042 | actually uses Rel structures, the r_addend field will always be | |
2043 | zero. | |
bcbe2c71 | 2044 | |
ede4eed4 KR |
2045 | This function is responsible for adjust the section contents as |
2046 | necessary, and (if using Rela relocs and generating a | |
2047 | relocateable output file) adjusting the reloc addend as | |
2048 | necessary. | |
bcbe2c71 | 2049 | |
ede4eed4 KR |
2050 | This function does not have to worry about setting the reloc |
2051 | address or the reloc symbol index. | |
2052 | ||
2053 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
2054 | ||
2055 | LOCAL_SECTIONS is an array giving the section in the input file | |
2056 | corresponding to the st_shndx field of each local symbol. | |
2057 | ||
2058 | The global hash table entry for the global symbols can be found | |
2059 | via elf_sym_hashes (input_bfd). | |
2060 | ||
2061 | When generating relocateable output, this function must handle | |
2062 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
2063 | going to be the section symbol corresponding to the output | |
2064 | section, which means that the addend must be adjusted | |
2065 | accordingly. */ | |
2066 | ||
2067 | static boolean | |
2068 | ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section, | |
2069 | contents, relocs, local_syms, local_sections) | |
2070 | bfd *output_bfd; | |
2071 | struct bfd_link_info *info; | |
2072 | bfd *input_bfd; | |
2073 | asection *input_section; | |
2074 | bfd_byte *contents; | |
2075 | Elf_Internal_Rela *relocs; | |
2076 | Elf_Internal_Sym *local_syms; | |
2077 | asection **local_sections; | |
bcbe2c71 | 2078 | { |
08556813 | 2079 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
ede4eed4 | 2080 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); |
08556813 MM |
2081 | bfd *dynobj = elf_hash_table (info)->dynobj; |
2082 | bfd_vma *local_got_offsets = elf_local_got_offsets (input_bfd); | |
07a159db MM |
2083 | asection *sgot = (asection *)0; |
2084 | Elf_Internal_Rela *rel = relocs; | |
2085 | Elf_Internal_Rela *relend = relocs + input_section->reloc_count; | |
2086 | boolean ret = true; | |
08556813 | 2087 | long insn; |
ede4eed4 KR |
2088 | |
2089 | #ifdef DEBUG | |
2090 | fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n", | |
2091 | bfd_get_filename (input_bfd), | |
2092 | bfd_section_name(input_bfd, input_section), | |
2093 | (long)input_section->reloc_count, | |
2094 | (info->relocateable) ? " (relocatable)" : ""); | |
2095 | #endif | |
2096 | ||
2097 | if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */ | |
2098 | ppc_elf_howto_init (); | |
bcbe2c71 | 2099 | |
ede4eed4 | 2100 | for (; rel < relend; rel++) |
bcbe2c71 | 2101 | { |
07a159db MM |
2102 | enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info); |
2103 | bfd_vma offset = rel->r_offset; | |
2104 | bfd_vma addend = rel->r_addend; | |
2105 | bfd_reloc_status_type r = bfd_reloc_other; | |
2106 | Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0; | |
2107 | asection *sec = (asection *)0; | |
2108 | struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0; | |
ede4eed4 KR |
2109 | reloc_howto_type *howto; |
2110 | unsigned long r_symndx; | |
2111 | bfd_vma relocation; | |
2112 | ||
2113 | /* Unknown relocation handling */ | |
2114 | if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type]) | |
2115 | { | |
1c3a295b MM |
2116 | (*_bfd_error_handler) ("%s: unknown relocation type %d", |
2117 | bfd_get_filename (input_bfd), | |
2118 | (int)r_type); | |
ede4eed4 KR |
2119 | |
2120 | bfd_set_error (bfd_error_bad_value); | |
2121 | ret = false; | |
2122 | continue; | |
2123 | } | |
2124 | ||
2125 | howto = ppc_elf_howto_table[(int)r_type]; | |
2126 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2127 | ||
2128 | if (info->relocateable) | |
2129 | { | |
2130 | /* This is a relocateable link. We don't have to change | |
2131 | anything, unless the reloc is against a section symbol, | |
2132 | in which case we have to adjust according to where the | |
2133 | section symbol winds up in the output section. */ | |
2134 | if (r_symndx < symtab_hdr->sh_info) | |
2135 | { | |
2136 | sym = local_syms + r_symndx; | |
2137 | if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
2138 | { | |
2139 | sec = local_sections[r_symndx]; | |
2140 | addend = rel->r_addend += sec->output_offset + sym->st_value; | |
2141 | } | |
2142 | } | |
2143 | ||
2144 | #ifdef DEBUG | |
2145 | fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n", | |
2146 | howto->name, | |
2147 | (int)r_type, | |
2148 | r_symndx, | |
2149 | (long)offset, | |
2150 | (long)addend); | |
2151 | #endif | |
2152 | continue; | |
2153 | } | |
2154 | ||
2155 | /* This is a final link. */ | |
ede4eed4 KR |
2156 | if (r_symndx < symtab_hdr->sh_info) |
2157 | { | |
2158 | sym = local_syms + r_symndx; | |
2159 | sec = local_sections[r_symndx]; | |
2160 | relocation = (sec->output_section->vma | |
2161 | + sec->output_offset | |
2162 | + sym->st_value); | |
2163 | } | |
2164 | else | |
2165 | { | |
2166 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2167 | if (h->root.type == bfd_link_hash_defined | |
2168 | || h->root.type == bfd_link_hash_defweak) | |
2169 | { | |
2170 | sec = h->root.u.def.section; | |
2171 | relocation = (h->root.u.def.value | |
2172 | + sec->output_section->vma | |
2173 | + sec->output_offset); | |
2174 | } | |
2175 | else if (h->root.type == bfd_link_hash_undefweak) | |
2176 | relocation = 0; | |
2177 | else if (info->shared) | |
2178 | relocation = 0; | |
2179 | else | |
2180 | { | |
2181 | (*info->callbacks->undefined_symbol)(info, | |
2182 | h->root.root.string, | |
2183 | input_bfd, | |
2184 | input_section, | |
2185 | rel->r_offset); | |
2186 | ret = false; | |
2187 | continue; | |
2188 | } | |
2189 | } | |
2190 | ||
2191 | switch ((int)r_type) | |
2192 | { | |
2193 | default: | |
1c3a295b MM |
2194 | (*_bfd_error_handler) ("%s: unknown relocation type %d", |
2195 | bfd_get_filename (input_bfd), | |
2196 | (int)r_type); | |
2197 | ||
2198 | bfd_set_error (bfd_error_bad_value); | |
2199 | ret = false; | |
2200 | continue; | |
2201 | ||
2202 | case R_PPC_NONE: /* relocations that need no special processing */ | |
2203 | case R_PPC_ADDR32: | |
2204 | case R_PPC_ADDR24: | |
2205 | case R_PPC_ADDR16: | |
2206 | case R_PPC_ADDR16_LO: | |
2207 | case R_PPC_ADDR16_HI: | |
2208 | case R_PPC_ADDR14: | |
2209 | case R_PPC_REL24: | |
2210 | case R_PPC_REL14: | |
2211 | case R_PPC_UADDR32: | |
2212 | case R_PPC_UADDR16: | |
2213 | case R_PPC_REL32: | |
ede4eed4 KR |
2214 | break; |
2215 | ||
07a159db | 2216 | case (int)R_PPC_ADDR14_BRTAKEN: /* branch taken prediction relocations */ |
08556813 | 2217 | case (int)R_PPC_REL14_BRTAKEN: |
07a159db MM |
2218 | insn = bfd_get_32 (output_bfd, contents + offset); |
2219 | if ((relocation - offset) & 0x8000) | |
2220 | insn &= ~BRANCH_PREDICT_BIT; | |
2221 | else | |
2222 | insn |= BRANCH_PREDICT_BIT; | |
2223 | bfd_put_32 (output_bfd, insn, contents + offset); | |
2224 | break; | |
2225 | ||
2226 | case (int)R_PPC_ADDR14_BRNTAKEN: /* branch not taken predicition relocations */ | |
08556813 | 2227 | case (int)R_PPC_REL14_BRNTAKEN: |
08556813 | 2228 | insn = bfd_get_32 (output_bfd, contents + offset); |
07a159db MM |
2229 | if ((relocation - offset) & 0x8000) |
2230 | insn |= BRANCH_PREDICT_BIT; | |
2231 | else | |
2232 | insn &= ~BRANCH_PREDICT_BIT; | |
08556813 MM |
2233 | bfd_put_32 (output_bfd, insn, contents + offset); |
2234 | break; | |
2235 | ||
2236 | case (int)R_PPC_GOT16: /* GOT16 relocations */ | |
ede4eed4 KR |
2237 | case (int)R_PPC_GOT16_LO: |
2238 | case (int)R_PPC_GOT16_HI: | |
1c3a295b MM |
2239 | case (int)R_PPC_GOT16_HA: |
2240 | #ifdef DEBUG | |
07a159db | 2241 | fprintf (stderr, "GOT relocations in section %s from section %s\n", input_section->name, sec->name); |
1c3a295b MM |
2242 | #endif |
2243 | if (dynobj == NULL) | |
2244 | { | |
2245 | dynobj = ppc_elf_create_dynamic_sections (output_bfd, info); | |
2246 | if (!dynobj) | |
2247 | { | |
2248 | ret = false; | |
2249 | continue; | |
2250 | } | |
2251 | } | |
2252 | ||
ede4eed4 | 2253 | BFD_ASSERT (sec != (asection *)0); |
07a159db MM |
2254 | if (!sgot) |
2255 | { | |
2256 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2257 | BFD_ASSERT (sgot != NULL); | |
2258 | } | |
2259 | ||
2260 | if (h != NULL) | |
2261 | { | |
2262 | bfd_vma off; | |
2263 | ||
2264 | off = h->got_offset; | |
2265 | BFD_ASSERT (off != (bfd_vma) -1); | |
2266 | ||
2267 | if (! elf_hash_table (info)->dynamic_sections_created | |
2268 | || (info->shared | |
2269 | && info->symbolic | |
2270 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) | |
2271 | { | |
2272 | /* This is actually a static link, or it is a | |
2273 | -Bsymbolic link and the symbol is defined | |
2274 | locally. We must initialize this entry in the | |
2275 | global offset table. Since the offset must | |
2276 | always be a multiple of 4, we use the least | |
2277 | significant bit to record whether we have | |
2278 | initialized it already. | |
2279 | ||
2280 | When doing a dynamic link, we create a .rela.got | |
2281 | relocation entry to initialize the value. This | |
2282 | is done in the finish_dynamic_symbol routine. */ | |
2283 | if ((off & 1) != 0) | |
2284 | off &= ~1; | |
2285 | else | |
2286 | { | |
2287 | bfd_put_32 (output_bfd, relocation, | |
2288 | sgot->contents + off); | |
2289 | h->got_offset |= 1; | |
2290 | } | |
2291 | } | |
2292 | ||
2293 | relocation = sgot->output_offset + off; | |
2294 | } | |
2295 | else | |
2296 | { | |
2297 | bfd_vma off; | |
2298 | ||
2299 | BFD_ASSERT (local_got_offsets != NULL | |
2300 | && local_got_offsets[r_symndx] != (bfd_vma) -1); | |
2301 | ||
2302 | off = local_got_offsets[r_symndx]; | |
2303 | ||
2304 | /* The offset must always be a multiple of 4. We use | |
2305 | the least significant bit to record whether we have | |
2306 | already processed this entry. */ | |
2307 | if ((off & 1) != 0) | |
2308 | off &= ~1; | |
2309 | else | |
2310 | { | |
2311 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); | |
2312 | ||
2313 | if (info->shared) | |
2314 | { | |
2315 | asection *srelgot; | |
2316 | Elf_Internal_Rela outrel; | |
2317 | ||
1c3a295b | 2318 | /* We need to generate a R_PPC_RELATIVE reloc |
07a159db MM |
2319 | for the dynamic linker. */ |
2320 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
2321 | BFD_ASSERT (srelgot != NULL); | |
2322 | ||
2323 | outrel.r_offset = (sgot->output_section->vma | |
2324 | + sgot->output_offset | |
2325 | + off); | |
2326 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
2327 | outrel.r_addend = 0; | |
2328 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, | |
2329 | (((Elf32_External_Rela *) | |
2330 | srelgot->contents) | |
2331 | + srelgot->reloc_count)); | |
2332 | ++srelgot->reloc_count; | |
2333 | } | |
2334 | ||
2335 | local_got_offsets[r_symndx] |= 1; | |
2336 | } | |
2337 | ||
2338 | relocation = sgot->output_offset + off; | |
2339 | } | |
2340 | ||
ede4eed4 KR |
2341 | break; |
2342 | ||
07a159db MM |
2343 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
2344 | section, not the actual VMA. This is appropriate when generating | |
2345 | an embedded ELF object, for which the .got section acts like the | |
2346 | AIX .toc section. */ | |
08556813 MM |
2347 | case (int)R_PPC_TOC16: /* phony GOT16 relocations */ |
2348 | BFD_ASSERT (sec != (asection *)0); | |
07a159db MM |
2349 | BFD_ASSERT (bfd_is_und_section (sec) |
2350 | || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
bd2d10c0 | 2351 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0) |
07a159db MM |
2352 | |
2353 | addend -= sec->output_section->vma + 0x8000; | |
08556813 MM |
2354 | break; |
2355 | ||
2356 | case (int)R_PPC_ADDR16_HA: /* arithmetic adjust relocations */ | |
ede4eed4 | 2357 | BFD_ASSERT (sec != (asection *)0); |
07a159db | 2358 | addend += ((relocation + addend) & 0x8000) << 1; |
ede4eed4 | 2359 | break; |
1c3a295b | 2360 | |
bd2d10c0 MM |
2361 | case R_PPC_SDAREL16: /* relocate against _SDA_BASE_ */ |
2362 | BFD_ASSERT (sec != (asection *)0); | |
2363 | if (strcmp (bfd_get_section_name (abfd, sec), ".sdata") != 0 | |
2364 | && strcmp (bfd_get_section_name (abfd, sec), ".sbss") != 0) | |
2365 | { | |
2366 | (*_bfd_error_handler) ("%s: The target of R_PPC_SDAREL16 relocations must be in section .sdata or .sbss not %s", | |
2367 | bfd_get_filename (input_bfd), | |
2368 | bfd_get_section_name (abfd, sec)); | |
2369 | ||
2370 | bfd_set_error (bfd_error_bad_value); | |
2371 | ret = false; | |
2372 | continue; | |
2373 | } | |
2374 | goto unsupported; | |
2375 | ||
2376 | case R_PPC_EMB_SDA2REL: | |
2377 | BFD_ASSERT (sec != (asection *)0); | |
2378 | if (strcmp (bfd_get_section_name (abfd, sec), ".sdata2") != 0 | |
2379 | && strcmp (bfd_get_section_name (abfd, sec), ".sbss2") != 0) | |
2380 | { | |
2381 | (*_bfd_error_handler) ("%s: The target of R_PPC_SDA2REL16 relocations must be in section .sdata2 or .sbss2 not %s", | |
2382 | bfd_get_filename (input_bfd), | |
2383 | bfd_get_section_name (abfd, sec)); | |
2384 | ||
2385 | bfd_set_error (bfd_error_bad_value); | |
2386 | ret = false; | |
2387 | continue; | |
2388 | } | |
2389 | goto unsupported; | |
2390 | ||
2391 | ||
1c3a295b MM |
2392 | case R_PPC_PLTREL24: |
2393 | case R_PPC_COPY: | |
2394 | case R_PPC_GLOB_DAT: | |
2395 | case R_PPC_JMP_SLOT: | |
2396 | case R_PPC_RELATIVE: | |
2397 | case R_PPC_LOCAL24PC: | |
2398 | case R_PPC_PLT32: | |
2399 | case R_PPC_PLTREL32: | |
2400 | case R_PPC_PLT16_LO: | |
2401 | case R_PPC_PLT16_HI: | |
2402 | case R_PPC_PLT16_HA: | |
1c3a295b MM |
2403 | case R_PPC_SECTOFF: |
2404 | case R_PPC_SECTOFF_LO: | |
2405 | case R_PPC_SECTOFF_HI: | |
2406 | case R_PPC_SECTOFF_HA: | |
2407 | case R_PPC_EMB_NADDR32: | |
2408 | case R_PPC_EMB_NADDR16: | |
2409 | case R_PPC_EMB_NADDR16_LO: | |
2410 | case R_PPC_EMB_NADDR16_HI: | |
2411 | case R_PPC_EMB_NADDR16_HA: | |
2412 | case R_PPC_EMB_SDAI16: | |
2413 | case R_PPC_EMB_SDA2I16: | |
1c3a295b MM |
2414 | case R_PPC_EMB_SDA21: |
2415 | case R_PPC_EMB_MRKREF: | |
2416 | case R_PPC_EMB_RELSEC16: | |
2417 | case R_PPC_EMB_RELST_LO: | |
2418 | case R_PPC_EMB_RELST_HI: | |
2419 | case R_PPC_EMB_RELST_HA: | |
2420 | case R_PPC_EMB_BIT_FLD: | |
2421 | case R_PPC_EMB_RELSDA: | |
bd2d10c0 | 2422 | unsupported: |
1c3a295b MM |
2423 | (*_bfd_error_handler) ("%s: Relocation %s is not yet supported.", |
2424 | bfd_get_filename (input_bfd), | |
2425 | ppc_elf_howto_table[ (int)r_type ]->name); | |
2426 | ||
2427 | bfd_set_error (bfd_error_bad_value); | |
2428 | ret = false; | |
2429 | continue; | |
ede4eed4 KR |
2430 | } |
2431 | ||
2432 | ||
2433 | #ifdef DEBUG | |
2434 | fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n", | |
2435 | howto->name, | |
2436 | (int)r_type, | |
2437 | r_symndx, | |
2438 | (long)offset, | |
2439 | (long)addend); | |
2440 | #endif | |
2441 | ||
2442 | r = _bfd_final_link_relocate (howto, | |
2443 | input_bfd, | |
2444 | input_section, | |
2445 | contents, | |
2446 | offset, | |
2447 | relocation, | |
2448 | addend); | |
2449 | ||
2450 | if (r != bfd_reloc_ok) | |
2451 | { | |
2452 | ret = false; | |
2453 | switch (r) | |
2454 | { | |
2455 | default: | |
2456 | break; | |
2457 | ||
2458 | case bfd_reloc_overflow: | |
2459 | { | |
2460 | const char *name; | |
2461 | ||
2462 | if (h != NULL) | |
2463 | name = h->root.root.string; | |
2464 | else | |
2465 | { | |
2466 | name = bfd_elf_string_from_elf_section (input_bfd, | |
2467 | symtab_hdr->sh_link, | |
2468 | sym->st_name); | |
2469 | if (name == NULL) | |
2470 | break; | |
2471 | ||
2472 | if (*name == '\0') | |
2473 | name = bfd_section_name (input_bfd, sec); | |
2474 | } | |
2475 | ||
2476 | (*info->callbacks->reloc_overflow)(info, | |
2477 | name, | |
2478 | howto->name, | |
2479 | (bfd_vma) 0, | |
2480 | input_bfd, | |
2481 | input_section, | |
2482 | offset); | |
2483 | } | |
2484 | break; | |
2485 | ||
2486 | } | |
2487 | } | |
bcbe2c71 MM |
2488 | } |
2489 | ||
bcbe2c71 | 2490 | |
ede4eed4 KR |
2491 | #ifdef DEBUG |
2492 | fprintf (stderr, "\n"); | |
2493 | #endif | |
bcbe2c71 | 2494 | |
ede4eed4 | 2495 | return ret; |
bcbe2c71 MM |
2496 | } |
2497 | ||
57081126 | 2498 | \f |
ede4eed4 KR |
2499 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
2500 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
bcbe2c71 MM |
2501 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec |
2502 | #define TARGET_BIG_NAME "elf32-powerpc" | |
2503 | #define ELF_ARCH bfd_arch_powerpc | |
2504 | #define ELF_MACHINE_CODE EM_PPC | |
2505 | #define ELF_MAXPAGESIZE 0x10000 | |
ede4eed4 | 2506 | #define elf_info_to_howto ppc_elf_info_to_howto |
bcbe2c71 MM |
2507 | |
2508 | #ifdef EM_CYGNUS_POWERPC | |
2509 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
2510 | #endif | |
2511 | ||
2512 | #ifdef EM_PPC_OLD | |
2513 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
2514 | #endif | |
2515 | ||
ede4eed4 KR |
2516 | #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data |
2517 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data | |
2518 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags | |
2519 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup | |
83f4323e | 2520 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr |
ede4eed4 | 2521 | #define elf_backend_relocate_section ppc_elf_relocate_section |
08556813 MM |
2522 | #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections |
2523 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
2524 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol | |
2525 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
2526 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol | |
2527 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
57081126 | 2528 | #define elf_backend_fake_sections ppc_elf_fake_sections |
ede4eed4 | 2529 | |
bcbe2c71 | 2530 | #include "elf32-target.h" |