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