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