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