1 |
6 |
jlechner |
/* PowerPC-specific support for 32-bit ELF
|
2 |
|
|
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
|
3 |
|
|
2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
4 |
|
|
Written by Ian Lance Taylor, Cygnus Support.
|
5 |
|
|
|
6 |
|
|
This file is part of BFD, the Binary File Descriptor library.
|
7 |
|
|
|
8 |
|
|
This program is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
11 |
|
|
(at your option) any later version.
|
12 |
|
|
|
13 |
|
|
This program is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with this program; if not, write to the
|
20 |
|
|
Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
|
21 |
|
|
Boston, MA 02110-1301, USA. */
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* This file is based on a preliminary PowerPC ELF ABI. The
|
25 |
|
|
information may not match the final PowerPC ELF ABI. It includes
|
26 |
|
|
suggestions from the in-progress Embedded PowerPC ABI, and that
|
27 |
|
|
information may also not match. */
|
28 |
|
|
|
29 |
|
|
#include "sysdep.h"
|
30 |
|
|
#include <stdarg.h>
|
31 |
|
|
#include "bfd.h"
|
32 |
|
|
#include "bfdlink.h"
|
33 |
|
|
#include "libbfd.h"
|
34 |
|
|
#include "elf-bfd.h"
|
35 |
|
|
#include "elf/ppc.h"
|
36 |
|
|
#include "elf32-ppc.h"
|
37 |
|
|
#include "elf-vxworks.h"
|
38 |
|
|
|
39 |
|
|
/* RELA relocations are used here. */
|
40 |
|
|
|
41 |
|
|
static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
|
42 |
|
|
(bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
|
43 |
|
|
static bfd_reloc_status_type ppc_elf_unhandled_reloc
|
44 |
|
|
(bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
|
45 |
|
|
|
46 |
|
|
/* Branch prediction bit for branch taken relocs. */
|
47 |
|
|
#define BRANCH_PREDICT_BIT 0x200000
|
48 |
|
|
/* Mask to set RA in memory instructions. */
|
49 |
|
|
#define RA_REGISTER_MASK 0x001f0000
|
50 |
|
|
/* Value to shift register by to insert RA. */
|
51 |
|
|
#define RA_REGISTER_SHIFT 16
|
52 |
|
|
|
53 |
|
|
/* The name of the dynamic interpreter. This is put in the .interp
|
54 |
|
|
section. */
|
55 |
|
|
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
|
56 |
|
|
|
57 |
|
|
/* For old-style PLT. */
|
58 |
|
|
/* The number of single-slot PLT entries (the rest use two slots). */
|
59 |
|
|
#define PLT_NUM_SINGLE_ENTRIES 8192
|
60 |
|
|
|
61 |
|
|
/* For new-style .glink and .plt. */
|
62 |
|
|
#define GLINK_PLTRESOLVE 16*4
|
63 |
|
|
#define GLINK_ENTRY_SIZE 4*4
|
64 |
|
|
|
65 |
|
|
/* VxWorks uses its own plt layout, filled in by the static linker. */
|
66 |
|
|
|
67 |
|
|
/* The standard VxWorks PLT entry. */
|
68 |
|
|
#define VXWORKS_PLT_ENTRY_SIZE 32
|
69 |
|
|
static const bfd_vma ppc_elf_vxworks_plt_entry
|
70 |
|
|
[VXWORKS_PLT_ENTRY_SIZE / 4] =
|
71 |
|
|
{
|
72 |
|
|
0x3d800000, /* lis r12,0 */
|
73 |
|
|
0x818c0000, /* lwz r12,0(r12) */
|
74 |
|
|
0x7d8903a6, /* mtctr r12 */
|
75 |
|
|
0x4e800420, /* bctr */
|
76 |
|
|
0x39600000, /* li r11,0 */
|
77 |
|
|
0x48000000, /* b 14 <.PLT0resolve+0x4> */
|
78 |
|
|
0x60000000, /* nop */
|
79 |
|
|
0x60000000, /* nop */
|
80 |
|
|
};
|
81 |
|
|
static const bfd_vma ppc_elf_vxworks_pic_plt_entry
|
82 |
|
|
[VXWORKS_PLT_ENTRY_SIZE / 4] =
|
83 |
|
|
{
|
84 |
|
|
0x3d9e0000, /* addis r12,r30,0 */
|
85 |
|
|
0x818c0000, /* lwz r12,0(r12) */
|
86 |
|
|
0x7d8903a6, /* mtctr r12 */
|
87 |
|
|
0x4e800420, /* bctr */
|
88 |
|
|
0x39600000, /* li r11,0 */
|
89 |
|
|
0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
|
90 |
|
|
0x60000000, /* nop */
|
91 |
|
|
0x60000000, /* nop */
|
92 |
|
|
};
|
93 |
|
|
|
94 |
|
|
/* The initial VxWorks PLT entry. */
|
95 |
|
|
#define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
|
96 |
|
|
static const bfd_vma ppc_elf_vxworks_plt0_entry
|
97 |
|
|
[VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
|
98 |
|
|
{
|
99 |
|
|
0x3d800000, /* lis r12,0 */
|
100 |
|
|
0x398c0000, /* addi r12,r12,0 */
|
101 |
|
|
0x800c0008, /* lwz r0,8(r12) */
|
102 |
|
|
0x7c0903a6, /* mtctr r0 */
|
103 |
|
|
0x818c0004, /* lwz r12,4(r12) */
|
104 |
|
|
0x4e800420, /* bctr */
|
105 |
|
|
0x60000000, /* nop */
|
106 |
|
|
0x60000000, /* nop */
|
107 |
|
|
};
|
108 |
|
|
static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
|
109 |
|
|
[VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
|
110 |
|
|
{
|
111 |
|
|
0x819e0008, /* lwz r12,8(r30) */
|
112 |
|
|
0x7d8903a6, /* mtctr r12 */
|
113 |
|
|
0x819e0004, /* lwz r12,4(r30) */
|
114 |
|
|
0x4e800420, /* bctr */
|
115 |
|
|
0x60000000, /* nop */
|
116 |
|
|
0x60000000, /* nop */
|
117 |
|
|
0x60000000, /* nop */
|
118 |
|
|
0x60000000, /* nop */
|
119 |
|
|
};
|
120 |
|
|
|
121 |
|
|
/* For executables, we have some additional relocations in
|
122 |
|
|
.rela.plt.unloaded, for the kernel loader. */
|
123 |
|
|
|
124 |
|
|
/* The number of non-JMP_SLOT relocations per PLT0 slot. */
|
125 |
|
|
#define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
|
126 |
|
|
/* The number of relocations in the PLTResolve slot. */
|
127 |
|
|
#define VXWORKS_PLTRESOLVE_RELOCS 2
|
128 |
|
|
/* The number of relocations in the PLTResolve slot when when creating
|
129 |
|
|
a shared library. */
|
130 |
|
|
#define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
|
131 |
|
|
|
132 |
|
|
/* Some instructions. */
|
133 |
|
|
#define ADDIS_11_11 0x3d6b0000
|
134 |
|
|
#define ADDIS_11_30 0x3d7e0000
|
135 |
|
|
#define ADDIS_12_12 0x3d8c0000
|
136 |
|
|
#define ADDI_11_11 0x396b0000
|
137 |
|
|
#define ADD_0_11_11 0x7c0b5a14
|
138 |
|
|
#define ADD_11_0_11 0x7d605a14
|
139 |
|
|
#define B 0x48000000
|
140 |
|
|
#define BCL_20_31 0x429f0005
|
141 |
|
|
#define BCTR 0x4e800420
|
142 |
|
|
#define LIS_11 0x3d600000
|
143 |
|
|
#define LIS_12 0x3d800000
|
144 |
|
|
#define LWZU_0_12 0x840c0000
|
145 |
|
|
#define LWZ_0_12 0x800c0000
|
146 |
|
|
#define LWZ_11_11 0x816b0000
|
147 |
|
|
#define LWZ_11_30 0x817e0000
|
148 |
|
|
#define LWZ_12_12 0x818c0000
|
149 |
|
|
#define MFLR_0 0x7c0802a6
|
150 |
|
|
#define MFLR_12 0x7d8802a6
|
151 |
|
|
#define MTCTR_0 0x7c0903a6
|
152 |
|
|
#define MTCTR_11 0x7d6903a6
|
153 |
|
|
#define MTLR_0 0x7c0803a6
|
154 |
|
|
#define NOP 0x60000000
|
155 |
|
|
#define SUB_11_11_12 0x7d6c5850
|
156 |
|
|
|
157 |
|
|
/* Offset of tp and dtp pointers from start of TLS block. */
|
158 |
|
|
#define TP_OFFSET 0x7000
|
159 |
|
|
#define DTP_OFFSET 0x8000
|
160 |
|
|
|
161 |
|
|
/* The value of a defined global symbol. */
|
162 |
|
|
#define SYM_VAL(SYM) \
|
163 |
|
|
((SYM)->root.u.def.section->output_section->vma \
|
164 |
|
|
+ (SYM)->root.u.def.section->output_offset \
|
165 |
|
|
+ (SYM)->root.u.def.value)
|
166 |
|
|
|
167 |
|
|
static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
|
168 |
|
|
|
169 |
|
|
static reloc_howto_type ppc_elf_howto_raw[] = {
|
170 |
|
|
/* This reloc does nothing. */
|
171 |
|
|
HOWTO (R_PPC_NONE, /* type */
|
172 |
|
|
0, /* rightshift */
|
173 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
174 |
|
|
32, /* bitsize */
|
175 |
|
|
FALSE, /* pc_relative */
|
176 |
|
|
0, /* bitpos */
|
177 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
178 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
179 |
|
|
"R_PPC_NONE", /* name */
|
180 |
|
|
FALSE, /* partial_inplace */
|
181 |
|
|
0, /* src_mask */
|
182 |
|
|
0, /* dst_mask */
|
183 |
|
|
FALSE), /* pcrel_offset */
|
184 |
|
|
|
185 |
|
|
/* A standard 32 bit relocation. */
|
186 |
|
|
HOWTO (R_PPC_ADDR32, /* type */
|
187 |
|
|
0, /* rightshift */
|
188 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
189 |
|
|
32, /* bitsize */
|
190 |
|
|
FALSE, /* pc_relative */
|
191 |
|
|
0, /* bitpos */
|
192 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
193 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
194 |
|
|
"R_PPC_ADDR32", /* name */
|
195 |
|
|
FALSE, /* partial_inplace */
|
196 |
|
|
0, /* src_mask */
|
197 |
|
|
0xffffffff, /* dst_mask */
|
198 |
|
|
FALSE), /* pcrel_offset */
|
199 |
|
|
|
200 |
|
|
/* An absolute 26 bit branch; the lower two bits must be zero.
|
201 |
|
|
FIXME: we don't check that, we just clear them. */
|
202 |
|
|
HOWTO (R_PPC_ADDR24, /* type */
|
203 |
|
|
0, /* rightshift */
|
204 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
205 |
|
|
26, /* bitsize */
|
206 |
|
|
FALSE, /* pc_relative */
|
207 |
|
|
0, /* bitpos */
|
208 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
209 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
210 |
|
|
"R_PPC_ADDR24", /* name */
|
211 |
|
|
FALSE, /* partial_inplace */
|
212 |
|
|
0, /* src_mask */
|
213 |
|
|
0x3fffffc, /* dst_mask */
|
214 |
|
|
FALSE), /* pcrel_offset */
|
215 |
|
|
|
216 |
|
|
/* A standard 16 bit relocation. */
|
217 |
|
|
HOWTO (R_PPC_ADDR16, /* type */
|
218 |
|
|
0, /* rightshift */
|
219 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
220 |
|
|
16, /* bitsize */
|
221 |
|
|
FALSE, /* pc_relative */
|
222 |
|
|
0, /* bitpos */
|
223 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
224 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
225 |
|
|
"R_PPC_ADDR16", /* name */
|
226 |
|
|
FALSE, /* partial_inplace */
|
227 |
|
|
0, /* src_mask */
|
228 |
|
|
0xffff, /* dst_mask */
|
229 |
|
|
FALSE), /* pcrel_offset */
|
230 |
|
|
|
231 |
|
|
/* A 16 bit relocation without overflow. */
|
232 |
|
|
HOWTO (R_PPC_ADDR16_LO, /* type */
|
233 |
|
|
0, /* rightshift */
|
234 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
235 |
|
|
16, /* bitsize */
|
236 |
|
|
FALSE, /* pc_relative */
|
237 |
|
|
0, /* bitpos */
|
238 |
|
|
complain_overflow_dont,/* complain_on_overflow */
|
239 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
240 |
|
|
"R_PPC_ADDR16_LO", /* name */
|
241 |
|
|
FALSE, /* partial_inplace */
|
242 |
|
|
0, /* src_mask */
|
243 |
|
|
0xffff, /* dst_mask */
|
244 |
|
|
FALSE), /* pcrel_offset */
|
245 |
|
|
|
246 |
|
|
/* The high order 16 bits of an address. */
|
247 |
|
|
HOWTO (R_PPC_ADDR16_HI, /* type */
|
248 |
|
|
16, /* rightshift */
|
249 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
250 |
|
|
16, /* bitsize */
|
251 |
|
|
FALSE, /* pc_relative */
|
252 |
|
|
0, /* bitpos */
|
253 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
254 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
255 |
|
|
"R_PPC_ADDR16_HI", /* name */
|
256 |
|
|
FALSE, /* partial_inplace */
|
257 |
|
|
0, /* src_mask */
|
258 |
|
|
0xffff, /* dst_mask */
|
259 |
|
|
FALSE), /* pcrel_offset */
|
260 |
|
|
|
261 |
|
|
/* The high order 16 bits of an address, plus 1 if the contents of
|
262 |
|
|
the low 16 bits, treated as a signed number, is negative. */
|
263 |
|
|
HOWTO (R_PPC_ADDR16_HA, /* type */
|
264 |
|
|
16, /* rightshift */
|
265 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
266 |
|
|
16, /* bitsize */
|
267 |
|
|
FALSE, /* pc_relative */
|
268 |
|
|
0, /* bitpos */
|
269 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
270 |
|
|
ppc_elf_addr16_ha_reloc, /* special_function */
|
271 |
|
|
"R_PPC_ADDR16_HA", /* name */
|
272 |
|
|
FALSE, /* partial_inplace */
|
273 |
|
|
0, /* src_mask */
|
274 |
|
|
0xffff, /* dst_mask */
|
275 |
|
|
FALSE), /* pcrel_offset */
|
276 |
|
|
|
277 |
|
|
/* An absolute 16 bit branch; the lower two bits must be zero.
|
278 |
|
|
FIXME: we don't check that, we just clear them. */
|
279 |
|
|
HOWTO (R_PPC_ADDR14, /* type */
|
280 |
|
|
0, /* rightshift */
|
281 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
282 |
|
|
16, /* bitsize */
|
283 |
|
|
FALSE, /* pc_relative */
|
284 |
|
|
0, /* bitpos */
|
285 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
286 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
287 |
|
|
"R_PPC_ADDR14", /* name */
|
288 |
|
|
FALSE, /* partial_inplace */
|
289 |
|
|
0, /* src_mask */
|
290 |
|
|
0xfffc, /* dst_mask */
|
291 |
|
|
FALSE), /* pcrel_offset */
|
292 |
|
|
|
293 |
|
|
/* An absolute 16 bit branch, for which bit 10 should be set to
|
294 |
|
|
indicate that the branch is expected to be taken. The lower two
|
295 |
|
|
bits must be zero. */
|
296 |
|
|
HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
|
297 |
|
|
0, /* rightshift */
|
298 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
299 |
|
|
16, /* bitsize */
|
300 |
|
|
FALSE, /* pc_relative */
|
301 |
|
|
0, /* bitpos */
|
302 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
303 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
304 |
|
|
"R_PPC_ADDR14_BRTAKEN",/* name */
|
305 |
|
|
FALSE, /* partial_inplace */
|
306 |
|
|
0, /* src_mask */
|
307 |
|
|
0xfffc, /* dst_mask */
|
308 |
|
|
FALSE), /* pcrel_offset */
|
309 |
|
|
|
310 |
|
|
/* An absolute 16 bit branch, for which bit 10 should be set to
|
311 |
|
|
indicate that the branch is not expected to be taken. The lower
|
312 |
|
|
two bits must be zero. */
|
313 |
|
|
HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
|
314 |
|
|
0, /* rightshift */
|
315 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
316 |
|
|
16, /* bitsize */
|
317 |
|
|
FALSE, /* pc_relative */
|
318 |
|
|
0, /* bitpos */
|
319 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
320 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
321 |
|
|
"R_PPC_ADDR14_BRNTAKEN",/* name */
|
322 |
|
|
FALSE, /* partial_inplace */
|
323 |
|
|
0, /* src_mask */
|
324 |
|
|
0xfffc, /* dst_mask */
|
325 |
|
|
FALSE), /* pcrel_offset */
|
326 |
|
|
|
327 |
|
|
/* A relative 26 bit branch; the lower two bits must be zero. */
|
328 |
|
|
HOWTO (R_PPC_REL24, /* type */
|
329 |
|
|
0, /* rightshift */
|
330 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
331 |
|
|
26, /* bitsize */
|
332 |
|
|
TRUE, /* pc_relative */
|
333 |
|
|
0, /* bitpos */
|
334 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
335 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
336 |
|
|
"R_PPC_REL24", /* name */
|
337 |
|
|
FALSE, /* partial_inplace */
|
338 |
|
|
0, /* src_mask */
|
339 |
|
|
0x3fffffc, /* dst_mask */
|
340 |
|
|
TRUE), /* pcrel_offset */
|
341 |
|
|
|
342 |
|
|
/* A relative 16 bit branch; the lower two bits must be zero. */
|
343 |
|
|
HOWTO (R_PPC_REL14, /* type */
|
344 |
|
|
0, /* rightshift */
|
345 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
346 |
|
|
16, /* bitsize */
|
347 |
|
|
TRUE, /* pc_relative */
|
348 |
|
|
0, /* bitpos */
|
349 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
350 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
351 |
|
|
"R_PPC_REL14", /* name */
|
352 |
|
|
FALSE, /* partial_inplace */
|
353 |
|
|
0, /* src_mask */
|
354 |
|
|
0xfffc, /* dst_mask */
|
355 |
|
|
TRUE), /* pcrel_offset */
|
356 |
|
|
|
357 |
|
|
/* A relative 16 bit branch. Bit 10 should be set to indicate that
|
358 |
|
|
the branch is expected to be taken. The lower two bits must be
|
359 |
|
|
zero. */
|
360 |
|
|
HOWTO (R_PPC_REL14_BRTAKEN, /* type */
|
361 |
|
|
0, /* rightshift */
|
362 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
363 |
|
|
16, /* bitsize */
|
364 |
|
|
TRUE, /* pc_relative */
|
365 |
|
|
0, /* bitpos */
|
366 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
367 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
368 |
|
|
"R_PPC_REL14_BRTAKEN", /* name */
|
369 |
|
|
FALSE, /* partial_inplace */
|
370 |
|
|
0, /* src_mask */
|
371 |
|
|
0xfffc, /* dst_mask */
|
372 |
|
|
TRUE), /* pcrel_offset */
|
373 |
|
|
|
374 |
|
|
/* A relative 16 bit branch. Bit 10 should be set to indicate that
|
375 |
|
|
the branch is not expected to be taken. The lower two bits must
|
376 |
|
|
be zero. */
|
377 |
|
|
HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
|
378 |
|
|
0, /* rightshift */
|
379 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
380 |
|
|
16, /* bitsize */
|
381 |
|
|
TRUE, /* pc_relative */
|
382 |
|
|
0, /* bitpos */
|
383 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
384 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
385 |
|
|
"R_PPC_REL14_BRNTAKEN",/* name */
|
386 |
|
|
FALSE, /* partial_inplace */
|
387 |
|
|
0, /* src_mask */
|
388 |
|
|
0xfffc, /* dst_mask */
|
389 |
|
|
TRUE), /* pcrel_offset */
|
390 |
|
|
|
391 |
|
|
/* Like R_PPC_ADDR16, but referring to the GOT table entry for the
|
392 |
|
|
symbol. */
|
393 |
|
|
HOWTO (R_PPC_GOT16, /* type */
|
394 |
|
|
0, /* rightshift */
|
395 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
396 |
|
|
16, /* bitsize */
|
397 |
|
|
FALSE, /* pc_relative */
|
398 |
|
|
0, /* bitpos */
|
399 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
400 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
401 |
|
|
"R_PPC_GOT16", /* name */
|
402 |
|
|
FALSE, /* partial_inplace */
|
403 |
|
|
0, /* src_mask */
|
404 |
|
|
0xffff, /* dst_mask */
|
405 |
|
|
FALSE), /* pcrel_offset */
|
406 |
|
|
|
407 |
|
|
/* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
|
408 |
|
|
the symbol. */
|
409 |
|
|
HOWTO (R_PPC_GOT16_LO, /* type */
|
410 |
|
|
0, /* rightshift */
|
411 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
412 |
|
|
16, /* bitsize */
|
413 |
|
|
FALSE, /* pc_relative */
|
414 |
|
|
0, /* bitpos */
|
415 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
416 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
417 |
|
|
"R_PPC_GOT16_LO", /* name */
|
418 |
|
|
FALSE, /* partial_inplace */
|
419 |
|
|
0, /* src_mask */
|
420 |
|
|
0xffff, /* dst_mask */
|
421 |
|
|
FALSE), /* pcrel_offset */
|
422 |
|
|
|
423 |
|
|
/* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
|
424 |
|
|
the symbol. */
|
425 |
|
|
HOWTO (R_PPC_GOT16_HI, /* type */
|
426 |
|
|
16, /* rightshift */
|
427 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
428 |
|
|
16, /* bitsize */
|
429 |
|
|
FALSE, /* pc_relative */
|
430 |
|
|
0, /* bitpos */
|
431 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
432 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
433 |
|
|
"R_PPC_GOT16_HI", /* name */
|
434 |
|
|
FALSE, /* partial_inplace */
|
435 |
|
|
0, /* src_mask */
|
436 |
|
|
0xffff, /* dst_mask */
|
437 |
|
|
FALSE), /* pcrel_offset */
|
438 |
|
|
|
439 |
|
|
/* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
|
440 |
|
|
the symbol. */
|
441 |
|
|
HOWTO (R_PPC_GOT16_HA, /* type */
|
442 |
|
|
16, /* rightshift */
|
443 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
444 |
|
|
16, /* bitsize */
|
445 |
|
|
FALSE, /* pc_relative */
|
446 |
|
|
0, /* bitpos */
|
447 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
448 |
|
|
ppc_elf_addr16_ha_reloc, /* special_function */
|
449 |
|
|
"R_PPC_GOT16_HA", /* name */
|
450 |
|
|
FALSE, /* partial_inplace */
|
451 |
|
|
0, /* src_mask */
|
452 |
|
|
0xffff, /* dst_mask */
|
453 |
|
|
FALSE), /* pcrel_offset */
|
454 |
|
|
|
455 |
|
|
/* Like R_PPC_REL24, but referring to the procedure linkage table
|
456 |
|
|
entry for the symbol. */
|
457 |
|
|
HOWTO (R_PPC_PLTREL24, /* type */
|
458 |
|
|
0, /* rightshift */
|
459 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
460 |
|
|
26, /* bitsize */
|
461 |
|
|
TRUE, /* pc_relative */
|
462 |
|
|
0, /* bitpos */
|
463 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
464 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
465 |
|
|
"R_PPC_PLTREL24", /* name */
|
466 |
|
|
FALSE, /* partial_inplace */
|
467 |
|
|
0, /* src_mask */
|
468 |
|
|
0x3fffffc, /* dst_mask */
|
469 |
|
|
TRUE), /* pcrel_offset */
|
470 |
|
|
|
471 |
|
|
/* This is used only by the dynamic linker. The symbol should exist
|
472 |
|
|
both in the object being run and in some shared library. The
|
473 |
|
|
dynamic linker copies the data addressed by the symbol from the
|
474 |
|
|
shared library into the object, because the object being
|
475 |
|
|
run has to have the data at some particular address. */
|
476 |
|
|
HOWTO (R_PPC_COPY, /* type */
|
477 |
|
|
0, /* rightshift */
|
478 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
479 |
|
|
32, /* bitsize */
|
480 |
|
|
FALSE, /* pc_relative */
|
481 |
|
|
0, /* bitpos */
|
482 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
483 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
484 |
|
|
"R_PPC_COPY", /* name */
|
485 |
|
|
FALSE, /* partial_inplace */
|
486 |
|
|
0, /* src_mask */
|
487 |
|
|
0, /* dst_mask */
|
488 |
|
|
FALSE), /* pcrel_offset */
|
489 |
|
|
|
490 |
|
|
/* Like R_PPC_ADDR32, but used when setting global offset table
|
491 |
|
|
entries. */
|
492 |
|
|
HOWTO (R_PPC_GLOB_DAT, /* type */
|
493 |
|
|
0, /* rightshift */
|
494 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
495 |
|
|
32, /* bitsize */
|
496 |
|
|
FALSE, /* pc_relative */
|
497 |
|
|
0, /* bitpos */
|
498 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
499 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
500 |
|
|
"R_PPC_GLOB_DAT", /* name */
|
501 |
|
|
FALSE, /* partial_inplace */
|
502 |
|
|
0, /* src_mask */
|
503 |
|
|
0xffffffff, /* dst_mask */
|
504 |
|
|
FALSE), /* pcrel_offset */
|
505 |
|
|
|
506 |
|
|
/* Marks a procedure linkage table entry for a symbol. */
|
507 |
|
|
HOWTO (R_PPC_JMP_SLOT, /* type */
|
508 |
|
|
0, /* rightshift */
|
509 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
510 |
|
|
32, /* bitsize */
|
511 |
|
|
FALSE, /* pc_relative */
|
512 |
|
|
0, /* bitpos */
|
513 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
514 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
515 |
|
|
"R_PPC_JMP_SLOT", /* name */
|
516 |
|
|
FALSE, /* partial_inplace */
|
517 |
|
|
0, /* src_mask */
|
518 |
|
|
0, /* dst_mask */
|
519 |
|
|
FALSE), /* pcrel_offset */
|
520 |
|
|
|
521 |
|
|
/* Used only by the dynamic linker. When the object is run, this
|
522 |
|
|
longword is set to the load address of the object, plus the
|
523 |
|
|
addend. */
|
524 |
|
|
HOWTO (R_PPC_RELATIVE, /* type */
|
525 |
|
|
0, /* rightshift */
|
526 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
527 |
|
|
32, /* bitsize */
|
528 |
|
|
FALSE, /* pc_relative */
|
529 |
|
|
0, /* bitpos */
|
530 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
531 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
532 |
|
|
"R_PPC_RELATIVE", /* name */
|
533 |
|
|
FALSE, /* partial_inplace */
|
534 |
|
|
0, /* src_mask */
|
535 |
|
|
0xffffffff, /* dst_mask */
|
536 |
|
|
FALSE), /* pcrel_offset */
|
537 |
|
|
|
538 |
|
|
/* Like R_PPC_REL24, but uses the value of the symbol within the
|
539 |
|
|
object rather than the final value. Normally used for
|
540 |
|
|
_GLOBAL_OFFSET_TABLE_. */
|
541 |
|
|
HOWTO (R_PPC_LOCAL24PC, /* type */
|
542 |
|
|
0, /* rightshift */
|
543 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
544 |
|
|
26, /* bitsize */
|
545 |
|
|
TRUE, /* pc_relative */
|
546 |
|
|
0, /* bitpos */
|
547 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
548 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
549 |
|
|
"R_PPC_LOCAL24PC", /* name */
|
550 |
|
|
FALSE, /* partial_inplace */
|
551 |
|
|
0, /* src_mask */
|
552 |
|
|
0x3fffffc, /* dst_mask */
|
553 |
|
|
TRUE), /* pcrel_offset */
|
554 |
|
|
|
555 |
|
|
/* Like R_PPC_ADDR32, but may be unaligned. */
|
556 |
|
|
HOWTO (R_PPC_UADDR32, /* type */
|
557 |
|
|
0, /* rightshift */
|
558 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
559 |
|
|
32, /* bitsize */
|
560 |
|
|
FALSE, /* pc_relative */
|
561 |
|
|
0, /* bitpos */
|
562 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
563 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
564 |
|
|
"R_PPC_UADDR32", /* name */
|
565 |
|
|
FALSE, /* partial_inplace */
|
566 |
|
|
0, /* src_mask */
|
567 |
|
|
0xffffffff, /* dst_mask */
|
568 |
|
|
FALSE), /* pcrel_offset */
|
569 |
|
|
|
570 |
|
|
/* Like R_PPC_ADDR16, but may be unaligned. */
|
571 |
|
|
HOWTO (R_PPC_UADDR16, /* type */
|
572 |
|
|
0, /* rightshift */
|
573 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
574 |
|
|
16, /* bitsize */
|
575 |
|
|
FALSE, /* pc_relative */
|
576 |
|
|
0, /* bitpos */
|
577 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
578 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
579 |
|
|
"R_PPC_UADDR16", /* name */
|
580 |
|
|
FALSE, /* partial_inplace */
|
581 |
|
|
0, /* src_mask */
|
582 |
|
|
0xffff, /* dst_mask */
|
583 |
|
|
FALSE), /* pcrel_offset */
|
584 |
|
|
|
585 |
|
|
/* 32-bit PC relative */
|
586 |
|
|
HOWTO (R_PPC_REL32, /* type */
|
587 |
|
|
0, /* rightshift */
|
588 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
589 |
|
|
32, /* bitsize */
|
590 |
|
|
TRUE, /* pc_relative */
|
591 |
|
|
0, /* bitpos */
|
592 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
593 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
594 |
|
|
"R_PPC_REL32", /* name */
|
595 |
|
|
FALSE, /* partial_inplace */
|
596 |
|
|
0, /* src_mask */
|
597 |
|
|
0xffffffff, /* dst_mask */
|
598 |
|
|
TRUE), /* pcrel_offset */
|
599 |
|
|
|
600 |
|
|
/* 32-bit relocation to the symbol's procedure linkage table.
|
601 |
|
|
FIXME: not supported. */
|
602 |
|
|
HOWTO (R_PPC_PLT32, /* type */
|
603 |
|
|
0, /* rightshift */
|
604 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
605 |
|
|
32, /* bitsize */
|
606 |
|
|
FALSE, /* pc_relative */
|
607 |
|
|
0, /* bitpos */
|
608 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
609 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
610 |
|
|
"R_PPC_PLT32", /* name */
|
611 |
|
|
FALSE, /* partial_inplace */
|
612 |
|
|
0, /* src_mask */
|
613 |
|
|
0, /* dst_mask */
|
614 |
|
|
FALSE), /* pcrel_offset */
|
615 |
|
|
|
616 |
|
|
/* 32-bit PC relative relocation to the symbol's procedure linkage table.
|
617 |
|
|
FIXME: not supported. */
|
618 |
|
|
HOWTO (R_PPC_PLTREL32, /* type */
|
619 |
|
|
0, /* rightshift */
|
620 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
621 |
|
|
32, /* bitsize */
|
622 |
|
|
TRUE, /* pc_relative */
|
623 |
|
|
0, /* bitpos */
|
624 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
625 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
626 |
|
|
"R_PPC_PLTREL32", /* name */
|
627 |
|
|
FALSE, /* partial_inplace */
|
628 |
|
|
0, /* src_mask */
|
629 |
|
|
0, /* dst_mask */
|
630 |
|
|
TRUE), /* pcrel_offset */
|
631 |
|
|
|
632 |
|
|
/* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
|
633 |
|
|
the symbol. */
|
634 |
|
|
HOWTO (R_PPC_PLT16_LO, /* type */
|
635 |
|
|
0, /* rightshift */
|
636 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
637 |
|
|
16, /* bitsize */
|
638 |
|
|
FALSE, /* pc_relative */
|
639 |
|
|
0, /* bitpos */
|
640 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
641 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
642 |
|
|
"R_PPC_PLT16_LO", /* name */
|
643 |
|
|
FALSE, /* partial_inplace */
|
644 |
|
|
0, /* src_mask */
|
645 |
|
|
0xffff, /* dst_mask */
|
646 |
|
|
FALSE), /* pcrel_offset */
|
647 |
|
|
|
648 |
|
|
/* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
|
649 |
|
|
the symbol. */
|
650 |
|
|
HOWTO (R_PPC_PLT16_HI, /* type */
|
651 |
|
|
16, /* rightshift */
|
652 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
653 |
|
|
16, /* bitsize */
|
654 |
|
|
FALSE, /* pc_relative */
|
655 |
|
|
0, /* bitpos */
|
656 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
657 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
658 |
|
|
"R_PPC_PLT16_HI", /* name */
|
659 |
|
|
FALSE, /* partial_inplace */
|
660 |
|
|
0, /* src_mask */
|
661 |
|
|
0xffff, /* dst_mask */
|
662 |
|
|
FALSE), /* pcrel_offset */
|
663 |
|
|
|
664 |
|
|
/* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
|
665 |
|
|
the symbol. */
|
666 |
|
|
HOWTO (R_PPC_PLT16_HA, /* type */
|
667 |
|
|
16, /* rightshift */
|
668 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
669 |
|
|
16, /* bitsize */
|
670 |
|
|
FALSE, /* pc_relative */
|
671 |
|
|
0, /* bitpos */
|
672 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
673 |
|
|
ppc_elf_addr16_ha_reloc, /* special_function */
|
674 |
|
|
"R_PPC_PLT16_HA", /* name */
|
675 |
|
|
FALSE, /* partial_inplace */
|
676 |
|
|
0, /* src_mask */
|
677 |
|
|
0xffff, /* dst_mask */
|
678 |
|
|
FALSE), /* pcrel_offset */
|
679 |
|
|
|
680 |
|
|
/* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
|
681 |
|
|
small data items. */
|
682 |
|
|
HOWTO (R_PPC_SDAREL16, /* type */
|
683 |
|
|
0, /* rightshift */
|
684 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
685 |
|
|
16, /* bitsize */
|
686 |
|
|
FALSE, /* pc_relative */
|
687 |
|
|
0, /* bitpos */
|
688 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
689 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
690 |
|
|
"R_PPC_SDAREL16", /* name */
|
691 |
|
|
FALSE, /* partial_inplace */
|
692 |
|
|
0, /* src_mask */
|
693 |
|
|
0xffff, /* dst_mask */
|
694 |
|
|
FALSE), /* pcrel_offset */
|
695 |
|
|
|
696 |
|
|
/* 16-bit section relative relocation. */
|
697 |
|
|
HOWTO (R_PPC_SECTOFF, /* type */
|
698 |
|
|
0, /* rightshift */
|
699 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
700 |
|
|
16, /* bitsize */
|
701 |
|
|
FALSE, /* pc_relative */
|
702 |
|
|
0, /* bitpos */
|
703 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
704 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
705 |
|
|
"R_PPC_SECTOFF", /* name */
|
706 |
|
|
FALSE, /* partial_inplace */
|
707 |
|
|
0, /* src_mask */
|
708 |
|
|
0xffff, /* dst_mask */
|
709 |
|
|
FALSE), /* pcrel_offset */
|
710 |
|
|
|
711 |
|
|
/* 16-bit lower half section relative relocation. */
|
712 |
|
|
HOWTO (R_PPC_SECTOFF_LO, /* type */
|
713 |
|
|
0, /* rightshift */
|
714 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
715 |
|
|
16, /* bitsize */
|
716 |
|
|
FALSE, /* pc_relative */
|
717 |
|
|
0, /* bitpos */
|
718 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
719 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
720 |
|
|
"R_PPC_SECTOFF_LO", /* name */
|
721 |
|
|
FALSE, /* partial_inplace */
|
722 |
|
|
0, /* src_mask */
|
723 |
|
|
0xffff, /* dst_mask */
|
724 |
|
|
FALSE), /* pcrel_offset */
|
725 |
|
|
|
726 |
|
|
/* 16-bit upper half section relative relocation. */
|
727 |
|
|
HOWTO (R_PPC_SECTOFF_HI, /* type */
|
728 |
|
|
16, /* rightshift */
|
729 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
730 |
|
|
16, /* bitsize */
|
731 |
|
|
FALSE, /* pc_relative */
|
732 |
|
|
0, /* bitpos */
|
733 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
734 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
735 |
|
|
"R_PPC_SECTOFF_HI", /* name */
|
736 |
|
|
FALSE, /* partial_inplace */
|
737 |
|
|
0, /* src_mask */
|
738 |
|
|
0xffff, /* dst_mask */
|
739 |
|
|
FALSE), /* pcrel_offset */
|
740 |
|
|
|
741 |
|
|
/* 16-bit upper half adjusted section relative relocation. */
|
742 |
|
|
HOWTO (R_PPC_SECTOFF_HA, /* type */
|
743 |
|
|
16, /* rightshift */
|
744 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
745 |
|
|
16, /* bitsize */
|
746 |
|
|
FALSE, /* pc_relative */
|
747 |
|
|
0, /* bitpos */
|
748 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
749 |
|
|
ppc_elf_addr16_ha_reloc, /* special_function */
|
750 |
|
|
"R_PPC_SECTOFF_HA", /* name */
|
751 |
|
|
FALSE, /* partial_inplace */
|
752 |
|
|
0, /* src_mask */
|
753 |
|
|
0xffff, /* dst_mask */
|
754 |
|
|
FALSE), /* pcrel_offset */
|
755 |
|
|
|
756 |
|
|
/* Marker reloc for TLS. */
|
757 |
|
|
HOWTO (R_PPC_TLS,
|
758 |
|
|
0, /* rightshift */
|
759 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
760 |
|
|
32, /* bitsize */
|
761 |
|
|
FALSE, /* pc_relative */
|
762 |
|
|
0, /* bitpos */
|
763 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
764 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
765 |
|
|
"R_PPC_TLS", /* name */
|
766 |
|
|
FALSE, /* partial_inplace */
|
767 |
|
|
0, /* src_mask */
|
768 |
|
|
0, /* dst_mask */
|
769 |
|
|
FALSE), /* pcrel_offset */
|
770 |
|
|
|
771 |
|
|
/* Computes the load module index of the load module that contains the
|
772 |
|
|
definition of its TLS sym. */
|
773 |
|
|
HOWTO (R_PPC_DTPMOD32,
|
774 |
|
|
0, /* rightshift */
|
775 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
776 |
|
|
32, /* bitsize */
|
777 |
|
|
FALSE, /* pc_relative */
|
778 |
|
|
0, /* bitpos */
|
779 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
780 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
781 |
|
|
"R_PPC_DTPMOD32", /* name */
|
782 |
|
|
FALSE, /* partial_inplace */
|
783 |
|
|
0, /* src_mask */
|
784 |
|
|
0xffffffff, /* dst_mask */
|
785 |
|
|
FALSE), /* pcrel_offset */
|
786 |
|
|
|
787 |
|
|
/* Computes a dtv-relative displacement, the difference between the value
|
788 |
|
|
of sym+add and the base address of the thread-local storage block that
|
789 |
|
|
contains the definition of sym, minus 0x8000. */
|
790 |
|
|
HOWTO (R_PPC_DTPREL32,
|
791 |
|
|
0, /* rightshift */
|
792 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
793 |
|
|
32, /* bitsize */
|
794 |
|
|
FALSE, /* pc_relative */
|
795 |
|
|
0, /* bitpos */
|
796 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
797 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
798 |
|
|
"R_PPC_DTPREL32", /* name */
|
799 |
|
|
FALSE, /* partial_inplace */
|
800 |
|
|
0, /* src_mask */
|
801 |
|
|
0xffffffff, /* dst_mask */
|
802 |
|
|
FALSE), /* pcrel_offset */
|
803 |
|
|
|
804 |
|
|
/* A 16 bit dtprel reloc. */
|
805 |
|
|
HOWTO (R_PPC_DTPREL16,
|
806 |
|
|
0, /* rightshift */
|
807 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
808 |
|
|
16, /* bitsize */
|
809 |
|
|
FALSE, /* pc_relative */
|
810 |
|
|
0, /* bitpos */
|
811 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
812 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
813 |
|
|
"R_PPC_DTPREL16", /* name */
|
814 |
|
|
FALSE, /* partial_inplace */
|
815 |
|
|
0, /* src_mask */
|
816 |
|
|
0xffff, /* dst_mask */
|
817 |
|
|
FALSE), /* pcrel_offset */
|
818 |
|
|
|
819 |
|
|
/* Like DTPREL16, but no overflow. */
|
820 |
|
|
HOWTO (R_PPC_DTPREL16_LO,
|
821 |
|
|
0, /* rightshift */
|
822 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
823 |
|
|
16, /* bitsize */
|
824 |
|
|
FALSE, /* pc_relative */
|
825 |
|
|
0, /* bitpos */
|
826 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
827 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
828 |
|
|
"R_PPC_DTPREL16_LO", /* name */
|
829 |
|
|
FALSE, /* partial_inplace */
|
830 |
|
|
0, /* src_mask */
|
831 |
|
|
0xffff, /* dst_mask */
|
832 |
|
|
FALSE), /* pcrel_offset */
|
833 |
|
|
|
834 |
|
|
/* Like DTPREL16_LO, but next higher group of 16 bits. */
|
835 |
|
|
HOWTO (R_PPC_DTPREL16_HI,
|
836 |
|
|
16, /* rightshift */
|
837 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
838 |
|
|
16, /* bitsize */
|
839 |
|
|
FALSE, /* pc_relative */
|
840 |
|
|
0, /* bitpos */
|
841 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
842 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
843 |
|
|
"R_PPC_DTPREL16_HI", /* name */
|
844 |
|
|
FALSE, /* partial_inplace */
|
845 |
|
|
0, /* src_mask */
|
846 |
|
|
0xffff, /* dst_mask */
|
847 |
|
|
FALSE), /* pcrel_offset */
|
848 |
|
|
|
849 |
|
|
/* Like DTPREL16_HI, but adjust for low 16 bits. */
|
850 |
|
|
HOWTO (R_PPC_DTPREL16_HA,
|
851 |
|
|
16, /* rightshift */
|
852 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
853 |
|
|
16, /* bitsize */
|
854 |
|
|
FALSE, /* pc_relative */
|
855 |
|
|
0, /* bitpos */
|
856 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
857 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
858 |
|
|
"R_PPC_DTPREL16_HA", /* name */
|
859 |
|
|
FALSE, /* partial_inplace */
|
860 |
|
|
0, /* src_mask */
|
861 |
|
|
0xffff, /* dst_mask */
|
862 |
|
|
FALSE), /* pcrel_offset */
|
863 |
|
|
|
864 |
|
|
/* Computes a tp-relative displacement, the difference between the value of
|
865 |
|
|
sym+add and the value of the thread pointer (r13). */
|
866 |
|
|
HOWTO (R_PPC_TPREL32,
|
867 |
|
|
0, /* rightshift */
|
868 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
869 |
|
|
32, /* bitsize */
|
870 |
|
|
FALSE, /* pc_relative */
|
871 |
|
|
0, /* bitpos */
|
872 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
873 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
874 |
|
|
"R_PPC_TPREL32", /* name */
|
875 |
|
|
FALSE, /* partial_inplace */
|
876 |
|
|
0, /* src_mask */
|
877 |
|
|
0xffffffff, /* dst_mask */
|
878 |
|
|
FALSE), /* pcrel_offset */
|
879 |
|
|
|
880 |
|
|
/* A 16 bit tprel reloc. */
|
881 |
|
|
HOWTO (R_PPC_TPREL16,
|
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 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
889 |
|
|
"R_PPC_TPREL16", /* name */
|
890 |
|
|
FALSE, /* partial_inplace */
|
891 |
|
|
0, /* src_mask */
|
892 |
|
|
0xffff, /* dst_mask */
|
893 |
|
|
FALSE), /* pcrel_offset */
|
894 |
|
|
|
895 |
|
|
/* Like TPREL16, but no overflow. */
|
896 |
|
|
HOWTO (R_PPC_TPREL16_LO,
|
897 |
|
|
0, /* rightshift */
|
898 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
899 |
|
|
16, /* bitsize */
|
900 |
|
|
FALSE, /* pc_relative */
|
901 |
|
|
0, /* bitpos */
|
902 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
903 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
904 |
|
|
"R_PPC_TPREL16_LO", /* name */
|
905 |
|
|
FALSE, /* partial_inplace */
|
906 |
|
|
0, /* src_mask */
|
907 |
|
|
0xffff, /* dst_mask */
|
908 |
|
|
FALSE), /* pcrel_offset */
|
909 |
|
|
|
910 |
|
|
/* Like TPREL16_LO, but next higher group of 16 bits. */
|
911 |
|
|
HOWTO (R_PPC_TPREL16_HI,
|
912 |
|
|
16, /* rightshift */
|
913 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
914 |
|
|
16, /* bitsize */
|
915 |
|
|
FALSE, /* pc_relative */
|
916 |
|
|
0, /* bitpos */
|
917 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
918 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
919 |
|
|
"R_PPC_TPREL16_HI", /* name */
|
920 |
|
|
FALSE, /* partial_inplace */
|
921 |
|
|
0, /* src_mask */
|
922 |
|
|
0xffff, /* dst_mask */
|
923 |
|
|
FALSE), /* pcrel_offset */
|
924 |
|
|
|
925 |
|
|
/* Like TPREL16_HI, but adjust for low 16 bits. */
|
926 |
|
|
HOWTO (R_PPC_TPREL16_HA,
|
927 |
|
|
16, /* rightshift */
|
928 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
929 |
|
|
16, /* bitsize */
|
930 |
|
|
FALSE, /* pc_relative */
|
931 |
|
|
0, /* bitpos */
|
932 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
933 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
934 |
|
|
"R_PPC_TPREL16_HA", /* name */
|
935 |
|
|
FALSE, /* partial_inplace */
|
936 |
|
|
0, /* src_mask */
|
937 |
|
|
0xffff, /* dst_mask */
|
938 |
|
|
FALSE), /* pcrel_offset */
|
939 |
|
|
|
940 |
|
|
/* Allocates two contiguous entries in the GOT to hold a tls_index structure,
|
941 |
|
|
with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
|
942 |
|
|
to the first entry. */
|
943 |
|
|
HOWTO (R_PPC_GOT_TLSGD16,
|
944 |
|
|
0, /* rightshift */
|
945 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
946 |
|
|
16, /* bitsize */
|
947 |
|
|
FALSE, /* pc_relative */
|
948 |
|
|
0, /* bitpos */
|
949 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
950 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
951 |
|
|
"R_PPC_GOT_TLSGD16", /* name */
|
952 |
|
|
FALSE, /* partial_inplace */
|
953 |
|
|
0, /* src_mask */
|
954 |
|
|
0xffff, /* dst_mask */
|
955 |
|
|
FALSE), /* pcrel_offset */
|
956 |
|
|
|
957 |
|
|
/* Like GOT_TLSGD16, but no overflow. */
|
958 |
|
|
HOWTO (R_PPC_GOT_TLSGD16_LO,
|
959 |
|
|
0, /* rightshift */
|
960 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
961 |
|
|
16, /* bitsize */
|
962 |
|
|
FALSE, /* pc_relative */
|
963 |
|
|
0, /* bitpos */
|
964 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
965 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
966 |
|
|
"R_PPC_GOT_TLSGD16_LO", /* name */
|
967 |
|
|
FALSE, /* partial_inplace */
|
968 |
|
|
0, /* src_mask */
|
969 |
|
|
0xffff, /* dst_mask */
|
970 |
|
|
FALSE), /* pcrel_offset */
|
971 |
|
|
|
972 |
|
|
/* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
|
973 |
|
|
HOWTO (R_PPC_GOT_TLSGD16_HI,
|
974 |
|
|
16, /* rightshift */
|
975 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
976 |
|
|
16, /* bitsize */
|
977 |
|
|
FALSE, /* pc_relative */
|
978 |
|
|
0, /* bitpos */
|
979 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
980 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
981 |
|
|
"R_PPC_GOT_TLSGD16_HI", /* name */
|
982 |
|
|
FALSE, /* partial_inplace */
|
983 |
|
|
0, /* src_mask */
|
984 |
|
|
0xffff, /* dst_mask */
|
985 |
|
|
FALSE), /* pcrel_offset */
|
986 |
|
|
|
987 |
|
|
/* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
|
988 |
|
|
HOWTO (R_PPC_GOT_TLSGD16_HA,
|
989 |
|
|
16, /* rightshift */
|
990 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
991 |
|
|
16, /* bitsize */
|
992 |
|
|
FALSE, /* pc_relative */
|
993 |
|
|
0, /* bitpos */
|
994 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
995 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
996 |
|
|
"R_PPC_GOT_TLSGD16_HA", /* name */
|
997 |
|
|
FALSE, /* partial_inplace */
|
998 |
|
|
0, /* src_mask */
|
999 |
|
|
0xffff, /* dst_mask */
|
1000 |
|
|
FALSE), /* pcrel_offset */
|
1001 |
|
|
|
1002 |
|
|
/* Allocates two contiguous entries in the GOT to hold a tls_index structure,
|
1003 |
|
|
with values (sym+add)@dtpmod and zero, and computes the offset to the
|
1004 |
|
|
first entry. */
|
1005 |
|
|
HOWTO (R_PPC_GOT_TLSLD16,
|
1006 |
|
|
0, /* rightshift */
|
1007 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1008 |
|
|
16, /* bitsize */
|
1009 |
|
|
FALSE, /* pc_relative */
|
1010 |
|
|
0, /* bitpos */
|
1011 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1012 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1013 |
|
|
"R_PPC_GOT_TLSLD16", /* name */
|
1014 |
|
|
FALSE, /* partial_inplace */
|
1015 |
|
|
0, /* src_mask */
|
1016 |
|
|
0xffff, /* dst_mask */
|
1017 |
|
|
FALSE), /* pcrel_offset */
|
1018 |
|
|
|
1019 |
|
|
/* Like GOT_TLSLD16, but no overflow. */
|
1020 |
|
|
HOWTO (R_PPC_GOT_TLSLD16_LO,
|
1021 |
|
|
0, /* rightshift */
|
1022 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1023 |
|
|
16, /* bitsize */
|
1024 |
|
|
FALSE, /* pc_relative */
|
1025 |
|
|
0, /* bitpos */
|
1026 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1027 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1028 |
|
|
"R_PPC_GOT_TLSLD16_LO", /* name */
|
1029 |
|
|
FALSE, /* partial_inplace */
|
1030 |
|
|
0, /* src_mask */
|
1031 |
|
|
0xffff, /* dst_mask */
|
1032 |
|
|
FALSE), /* pcrel_offset */
|
1033 |
|
|
|
1034 |
|
|
/* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
|
1035 |
|
|
HOWTO (R_PPC_GOT_TLSLD16_HI,
|
1036 |
|
|
16, /* rightshift */
|
1037 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1038 |
|
|
16, /* bitsize */
|
1039 |
|
|
FALSE, /* pc_relative */
|
1040 |
|
|
0, /* bitpos */
|
1041 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1042 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1043 |
|
|
"R_PPC_GOT_TLSLD16_HI", /* name */
|
1044 |
|
|
FALSE, /* partial_inplace */
|
1045 |
|
|
0, /* src_mask */
|
1046 |
|
|
0xffff, /* dst_mask */
|
1047 |
|
|
FALSE), /* pcrel_offset */
|
1048 |
|
|
|
1049 |
|
|
/* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
|
1050 |
|
|
HOWTO (R_PPC_GOT_TLSLD16_HA,
|
1051 |
|
|
16, /* rightshift */
|
1052 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1053 |
|
|
16, /* bitsize */
|
1054 |
|
|
FALSE, /* pc_relative */
|
1055 |
|
|
0, /* bitpos */
|
1056 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1057 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1058 |
|
|
"R_PPC_GOT_TLSLD16_HA", /* name */
|
1059 |
|
|
FALSE, /* partial_inplace */
|
1060 |
|
|
0, /* src_mask */
|
1061 |
|
|
0xffff, /* dst_mask */
|
1062 |
|
|
FALSE), /* pcrel_offset */
|
1063 |
|
|
|
1064 |
|
|
/* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
|
1065 |
|
|
the offset to the entry. */
|
1066 |
|
|
HOWTO (R_PPC_GOT_DTPREL16,
|
1067 |
|
|
0, /* rightshift */
|
1068 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1069 |
|
|
16, /* bitsize */
|
1070 |
|
|
FALSE, /* pc_relative */
|
1071 |
|
|
0, /* bitpos */
|
1072 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1073 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1074 |
|
|
"R_PPC_GOT_DTPREL16", /* name */
|
1075 |
|
|
FALSE, /* partial_inplace */
|
1076 |
|
|
0, /* src_mask */
|
1077 |
|
|
0xffff, /* dst_mask */
|
1078 |
|
|
FALSE), /* pcrel_offset */
|
1079 |
|
|
|
1080 |
|
|
/* Like GOT_DTPREL16, but no overflow. */
|
1081 |
|
|
HOWTO (R_PPC_GOT_DTPREL16_LO,
|
1082 |
|
|
0, /* rightshift */
|
1083 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1084 |
|
|
16, /* bitsize */
|
1085 |
|
|
FALSE, /* pc_relative */
|
1086 |
|
|
0, /* bitpos */
|
1087 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1088 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1089 |
|
|
"R_PPC_GOT_DTPREL16_LO", /* name */
|
1090 |
|
|
FALSE, /* partial_inplace */
|
1091 |
|
|
0, /* src_mask */
|
1092 |
|
|
0xffff, /* dst_mask */
|
1093 |
|
|
FALSE), /* pcrel_offset */
|
1094 |
|
|
|
1095 |
|
|
/* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
|
1096 |
|
|
HOWTO (R_PPC_GOT_DTPREL16_HI,
|
1097 |
|
|
16, /* rightshift */
|
1098 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1099 |
|
|
16, /* bitsize */
|
1100 |
|
|
FALSE, /* pc_relative */
|
1101 |
|
|
0, /* bitpos */
|
1102 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1103 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1104 |
|
|
"R_PPC_GOT_DTPREL16_HI", /* name */
|
1105 |
|
|
FALSE, /* partial_inplace */
|
1106 |
|
|
0, /* src_mask */
|
1107 |
|
|
0xffff, /* dst_mask */
|
1108 |
|
|
FALSE), /* pcrel_offset */
|
1109 |
|
|
|
1110 |
|
|
/* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
|
1111 |
|
|
HOWTO (R_PPC_GOT_DTPREL16_HA,
|
1112 |
|
|
16, /* rightshift */
|
1113 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1114 |
|
|
16, /* bitsize */
|
1115 |
|
|
FALSE, /* pc_relative */
|
1116 |
|
|
0, /* bitpos */
|
1117 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1118 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1119 |
|
|
"R_PPC_GOT_DTPREL16_HA", /* name */
|
1120 |
|
|
FALSE, /* partial_inplace */
|
1121 |
|
|
0, /* src_mask */
|
1122 |
|
|
0xffff, /* dst_mask */
|
1123 |
|
|
FALSE), /* pcrel_offset */
|
1124 |
|
|
|
1125 |
|
|
/* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
|
1126 |
|
|
offset to the entry. */
|
1127 |
|
|
HOWTO (R_PPC_GOT_TPREL16,
|
1128 |
|
|
0, /* rightshift */
|
1129 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1130 |
|
|
16, /* bitsize */
|
1131 |
|
|
FALSE, /* pc_relative */
|
1132 |
|
|
0, /* bitpos */
|
1133 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1134 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1135 |
|
|
"R_PPC_GOT_TPREL16", /* name */
|
1136 |
|
|
FALSE, /* partial_inplace */
|
1137 |
|
|
0, /* src_mask */
|
1138 |
|
|
0xffff, /* dst_mask */
|
1139 |
|
|
FALSE), /* pcrel_offset */
|
1140 |
|
|
|
1141 |
|
|
/* Like GOT_TPREL16, but no overflow. */
|
1142 |
|
|
HOWTO (R_PPC_GOT_TPREL16_LO,
|
1143 |
|
|
0, /* rightshift */
|
1144 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1145 |
|
|
16, /* bitsize */
|
1146 |
|
|
FALSE, /* pc_relative */
|
1147 |
|
|
0, /* bitpos */
|
1148 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1149 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1150 |
|
|
"R_PPC_GOT_TPREL16_LO", /* name */
|
1151 |
|
|
FALSE, /* partial_inplace */
|
1152 |
|
|
0, /* src_mask */
|
1153 |
|
|
0xffff, /* dst_mask */
|
1154 |
|
|
FALSE), /* pcrel_offset */
|
1155 |
|
|
|
1156 |
|
|
/* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
|
1157 |
|
|
HOWTO (R_PPC_GOT_TPREL16_HI,
|
1158 |
|
|
16, /* rightshift */
|
1159 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1160 |
|
|
16, /* bitsize */
|
1161 |
|
|
FALSE, /* pc_relative */
|
1162 |
|
|
0, /* bitpos */
|
1163 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1164 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1165 |
|
|
"R_PPC_GOT_TPREL16_HI", /* name */
|
1166 |
|
|
FALSE, /* partial_inplace */
|
1167 |
|
|
0, /* src_mask */
|
1168 |
|
|
0xffff, /* dst_mask */
|
1169 |
|
|
FALSE), /* pcrel_offset */
|
1170 |
|
|
|
1171 |
|
|
/* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
|
1172 |
|
|
HOWTO (R_PPC_GOT_TPREL16_HA,
|
1173 |
|
|
16, /* rightshift */
|
1174 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1175 |
|
|
16, /* bitsize */
|
1176 |
|
|
FALSE, /* pc_relative */
|
1177 |
|
|
0, /* bitpos */
|
1178 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1179 |
|
|
ppc_elf_unhandled_reloc, /* special_function */
|
1180 |
|
|
"R_PPC_GOT_TPREL16_HA", /* name */
|
1181 |
|
|
FALSE, /* partial_inplace */
|
1182 |
|
|
0, /* src_mask */
|
1183 |
|
|
0xffff, /* dst_mask */
|
1184 |
|
|
FALSE), /* pcrel_offset */
|
1185 |
|
|
|
1186 |
|
|
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
1187 |
|
|
in the SVR4 ELF ABI. */
|
1188 |
|
|
|
1189 |
|
|
/* 32 bit value resulting from the addend minus the symbol. */
|
1190 |
|
|
HOWTO (R_PPC_EMB_NADDR32, /* type */
|
1191 |
|
|
0, /* rightshift */
|
1192 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
1193 |
|
|
32, /* bitsize */
|
1194 |
|
|
FALSE, /* pc_relative */
|
1195 |
|
|
0, /* bitpos */
|
1196 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
1197 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1198 |
|
|
"R_PPC_EMB_NADDR32", /* name */
|
1199 |
|
|
FALSE, /* partial_inplace */
|
1200 |
|
|
0, /* src_mask */
|
1201 |
|
|
0xffffffff, /* dst_mask */
|
1202 |
|
|
FALSE), /* pcrel_offset */
|
1203 |
|
|
|
1204 |
|
|
/* 16 bit value resulting from the addend minus the symbol. */
|
1205 |
|
|
HOWTO (R_PPC_EMB_NADDR16, /* type */
|
1206 |
|
|
0, /* rightshift */
|
1207 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1208 |
|
|
16, /* bitsize */
|
1209 |
|
|
FALSE, /* pc_relative */
|
1210 |
|
|
0, /* bitpos */
|
1211 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
1212 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1213 |
|
|
"R_PPC_EMB_NADDR16", /* name */
|
1214 |
|
|
FALSE, /* partial_inplace */
|
1215 |
|
|
0, /* src_mask */
|
1216 |
|
|
0xffff, /* dst_mask */
|
1217 |
|
|
FALSE), /* pcrel_offset */
|
1218 |
|
|
|
1219 |
|
|
/* 16 bit value resulting from the addend minus the symbol. */
|
1220 |
|
|
HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
|
1221 |
|
|
0, /* rightshift */
|
1222 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1223 |
|
|
16, /* bitsize */
|
1224 |
|
|
FALSE, /* pc_relative */
|
1225 |
|
|
0, /* bitpos */
|
1226 |
|
|
complain_overflow_dont,/* complain_on_overflow */
|
1227 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1228 |
|
|
"R_PPC_EMB_ADDR16_LO", /* name */
|
1229 |
|
|
FALSE, /* partial_inplace */
|
1230 |
|
|
0, /* src_mask */
|
1231 |
|
|
0xffff, /* dst_mask */
|
1232 |
|
|
FALSE), /* pcrel_offset */
|
1233 |
|
|
|
1234 |
|
|
/* The high order 16 bits of the addend minus the symbol. */
|
1235 |
|
|
HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
|
1236 |
|
|
16, /* rightshift */
|
1237 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1238 |
|
|
16, /* bitsize */
|
1239 |
|
|
FALSE, /* pc_relative */
|
1240 |
|
|
0, /* bitpos */
|
1241 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1242 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1243 |
|
|
"R_PPC_EMB_NADDR16_HI", /* name */
|
1244 |
|
|
FALSE, /* partial_inplace */
|
1245 |
|
|
0, /* src_mask */
|
1246 |
|
|
0xffff, /* dst_mask */
|
1247 |
|
|
FALSE), /* pcrel_offset */
|
1248 |
|
|
|
1249 |
|
|
/* The high order 16 bits of the result of the addend minus the address,
|
1250 |
|
|
plus 1 if the contents of the low 16 bits, treated as a signed number,
|
1251 |
|
|
is negative. */
|
1252 |
|
|
HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
|
1253 |
|
|
16, /* rightshift */
|
1254 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1255 |
|
|
16, /* bitsize */
|
1256 |
|
|
FALSE, /* pc_relative */
|
1257 |
|
|
0, /* bitpos */
|
1258 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1259 |
|
|
ppc_elf_addr16_ha_reloc, /* special_function */
|
1260 |
|
|
"R_PPC_EMB_NADDR16_HA", /* name */
|
1261 |
|
|
FALSE, /* partial_inplace */
|
1262 |
|
|
0, /* src_mask */
|
1263 |
|
|
0xffff, /* dst_mask */
|
1264 |
|
|
FALSE), /* pcrel_offset */
|
1265 |
|
|
|
1266 |
|
|
/* 16 bit value resulting from allocating a 4 byte word to hold an
|
1267 |
|
|
address in the .sdata section, and returning the offset from
|
1268 |
|
|
_SDA_BASE_ for that relocation. */
|
1269 |
|
|
HOWTO (R_PPC_EMB_SDAI16, /* type */
|
1270 |
|
|
0, /* rightshift */
|
1271 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1272 |
|
|
16, /* bitsize */
|
1273 |
|
|
FALSE, /* pc_relative */
|
1274 |
|
|
0, /* bitpos */
|
1275 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
1276 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1277 |
|
|
"R_PPC_EMB_SDAI16", /* name */
|
1278 |
|
|
FALSE, /* partial_inplace */
|
1279 |
|
|
0, /* src_mask */
|
1280 |
|
|
0xffff, /* dst_mask */
|
1281 |
|
|
FALSE), /* pcrel_offset */
|
1282 |
|
|
|
1283 |
|
|
/* 16 bit value resulting from allocating a 4 byte word to hold an
|
1284 |
|
|
address in the .sdata2 section, and returning the offset from
|
1285 |
|
|
_SDA2_BASE_ for that relocation. */
|
1286 |
|
|
HOWTO (R_PPC_EMB_SDA2I16, /* type */
|
1287 |
|
|
0, /* rightshift */
|
1288 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1289 |
|
|
16, /* bitsize */
|
1290 |
|
|
FALSE, /* pc_relative */
|
1291 |
|
|
0, /* bitpos */
|
1292 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
1293 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1294 |
|
|
"R_PPC_EMB_SDA2I16", /* name */
|
1295 |
|
|
FALSE, /* partial_inplace */
|
1296 |
|
|
0, /* src_mask */
|
1297 |
|
|
0xffff, /* dst_mask */
|
1298 |
|
|
FALSE), /* pcrel_offset */
|
1299 |
|
|
|
1300 |
|
|
/* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
|
1301 |
|
|
small data items. */
|
1302 |
|
|
HOWTO (R_PPC_EMB_SDA2REL, /* type */
|
1303 |
|
|
0, /* rightshift */
|
1304 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1305 |
|
|
16, /* bitsize */
|
1306 |
|
|
FALSE, /* pc_relative */
|
1307 |
|
|
0, /* bitpos */
|
1308 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1309 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1310 |
|
|
"R_PPC_EMB_SDA2REL", /* name */
|
1311 |
|
|
FALSE, /* partial_inplace */
|
1312 |
|
|
0, /* src_mask */
|
1313 |
|
|
0xffff, /* dst_mask */
|
1314 |
|
|
FALSE), /* pcrel_offset */
|
1315 |
|
|
|
1316 |
|
|
/* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
|
1317 |
|
|
signed offset from the appropriate base, and filling in the register
|
1318 |
|
|
field with the appropriate register (0, 2, or 13). */
|
1319 |
|
|
HOWTO (R_PPC_EMB_SDA21, /* type */
|
1320 |
|
|
0, /* rightshift */
|
1321 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
1322 |
|
|
16, /* bitsize */
|
1323 |
|
|
FALSE, /* pc_relative */
|
1324 |
|
|
0, /* bitpos */
|
1325 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1326 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1327 |
|
|
"R_PPC_EMB_SDA21", /* name */
|
1328 |
|
|
FALSE, /* partial_inplace */
|
1329 |
|
|
0, /* src_mask */
|
1330 |
|
|
0xffff, /* dst_mask */
|
1331 |
|
|
FALSE), /* pcrel_offset */
|
1332 |
|
|
|
1333 |
|
|
/* Relocation not handled: R_PPC_EMB_MRKREF */
|
1334 |
|
|
/* Relocation not handled: R_PPC_EMB_RELSEC16 */
|
1335 |
|
|
/* Relocation not handled: R_PPC_EMB_RELST_LO */
|
1336 |
|
|
/* Relocation not handled: R_PPC_EMB_RELST_HI */
|
1337 |
|
|
/* Relocation not handled: R_PPC_EMB_RELST_HA */
|
1338 |
|
|
/* Relocation not handled: R_PPC_EMB_BIT_FLD */
|
1339 |
|
|
|
1340 |
|
|
/* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
|
1341 |
|
|
in the 16 bit signed offset from the appropriate base, and filling in the
|
1342 |
|
|
register field with the appropriate register (0, 2, or 13). */
|
1343 |
|
|
HOWTO (R_PPC_EMB_RELSDA, /* type */
|
1344 |
|
|
0, /* rightshift */
|
1345 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1346 |
|
|
16, /* bitsize */
|
1347 |
|
|
TRUE, /* pc_relative */
|
1348 |
|
|
0, /* bitpos */
|
1349 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1350 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1351 |
|
|
"R_PPC_EMB_RELSDA", /* name */
|
1352 |
|
|
FALSE, /* partial_inplace */
|
1353 |
|
|
0, /* src_mask */
|
1354 |
|
|
0xffff, /* dst_mask */
|
1355 |
|
|
FALSE), /* pcrel_offset */
|
1356 |
|
|
|
1357 |
|
|
/* A 16 bit relative relocation. */
|
1358 |
|
|
HOWTO (R_PPC_REL16, /* type */
|
1359 |
|
|
0, /* rightshift */
|
1360 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1361 |
|
|
16, /* bitsize */
|
1362 |
|
|
TRUE, /* pc_relative */
|
1363 |
|
|
0, /* bitpos */
|
1364 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
1365 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1366 |
|
|
"R_PPC_REL16", /* name */
|
1367 |
|
|
FALSE, /* partial_inplace */
|
1368 |
|
|
0, /* src_mask */
|
1369 |
|
|
0xffff, /* dst_mask */
|
1370 |
|
|
TRUE), /* pcrel_offset */
|
1371 |
|
|
|
1372 |
|
|
/* A 16 bit relative relocation without overflow. */
|
1373 |
|
|
HOWTO (R_PPC_REL16_LO, /* type */
|
1374 |
|
|
0, /* rightshift */
|
1375 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1376 |
|
|
16, /* bitsize */
|
1377 |
|
|
TRUE, /* pc_relative */
|
1378 |
|
|
0, /* bitpos */
|
1379 |
|
|
complain_overflow_dont,/* complain_on_overflow */
|
1380 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1381 |
|
|
"R_PPC_REL16_LO", /* name */
|
1382 |
|
|
FALSE, /* partial_inplace */
|
1383 |
|
|
0, /* src_mask */
|
1384 |
|
|
0xffff, /* dst_mask */
|
1385 |
|
|
TRUE), /* pcrel_offset */
|
1386 |
|
|
|
1387 |
|
|
/* The high order 16 bits of a relative address. */
|
1388 |
|
|
HOWTO (R_PPC_REL16_HI, /* type */
|
1389 |
|
|
16, /* rightshift */
|
1390 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1391 |
|
|
16, /* bitsize */
|
1392 |
|
|
TRUE, /* pc_relative */
|
1393 |
|
|
0, /* bitpos */
|
1394 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1395 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1396 |
|
|
"R_PPC_REL16_HI", /* name */
|
1397 |
|
|
FALSE, /* partial_inplace */
|
1398 |
|
|
0, /* src_mask */
|
1399 |
|
|
0xffff, /* dst_mask */
|
1400 |
|
|
TRUE), /* pcrel_offset */
|
1401 |
|
|
|
1402 |
|
|
/* The high order 16 bits of a relative address, plus 1 if the contents of
|
1403 |
|
|
the low 16 bits, treated as a signed number, is negative. */
|
1404 |
|
|
HOWTO (R_PPC_REL16_HA, /* type */
|
1405 |
|
|
16, /* rightshift */
|
1406 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1407 |
|
|
16, /* bitsize */
|
1408 |
|
|
TRUE, /* pc_relative */
|
1409 |
|
|
0, /* bitpos */
|
1410 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1411 |
|
|
ppc_elf_addr16_ha_reloc, /* special_function */
|
1412 |
|
|
"R_PPC_REL16_HA", /* name */
|
1413 |
|
|
FALSE, /* partial_inplace */
|
1414 |
|
|
0, /* src_mask */
|
1415 |
|
|
0xffff, /* dst_mask */
|
1416 |
|
|
TRUE), /* pcrel_offset */
|
1417 |
|
|
|
1418 |
|
|
/* GNU extension to record C++ vtable hierarchy. */
|
1419 |
|
|
HOWTO (R_PPC_GNU_VTINHERIT, /* type */
|
1420 |
|
|
0, /* rightshift */
|
1421 |
|
|
0, /* size (0 = byte, 1 = short, 2 = long) */
|
1422 |
|
|
0, /* bitsize */
|
1423 |
|
|
FALSE, /* pc_relative */
|
1424 |
|
|
0, /* bitpos */
|
1425 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1426 |
|
|
NULL, /* special_function */
|
1427 |
|
|
"R_PPC_GNU_VTINHERIT", /* name */
|
1428 |
|
|
FALSE, /* partial_inplace */
|
1429 |
|
|
0, /* src_mask */
|
1430 |
|
|
0, /* dst_mask */
|
1431 |
|
|
FALSE), /* pcrel_offset */
|
1432 |
|
|
|
1433 |
|
|
/* GNU extension to record C++ vtable member usage. */
|
1434 |
|
|
HOWTO (R_PPC_GNU_VTENTRY, /* type */
|
1435 |
|
|
0, /* rightshift */
|
1436 |
|
|
0, /* size (0 = byte, 1 = short, 2 = long) */
|
1437 |
|
|
0, /* bitsize */
|
1438 |
|
|
FALSE, /* pc_relative */
|
1439 |
|
|
0, /* bitpos */
|
1440 |
|
|
complain_overflow_dont, /* complain_on_overflow */
|
1441 |
|
|
NULL, /* special_function */
|
1442 |
|
|
"R_PPC_GNU_VTENTRY", /* name */
|
1443 |
|
|
FALSE, /* partial_inplace */
|
1444 |
|
|
0, /* src_mask */
|
1445 |
|
|
0, /* dst_mask */
|
1446 |
|
|
FALSE), /* pcrel_offset */
|
1447 |
|
|
|
1448 |
|
|
/* Phony reloc to handle AIX style TOC entries. */
|
1449 |
|
|
HOWTO (R_PPC_TOC16, /* type */
|
1450 |
|
|
0, /* rightshift */
|
1451 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
1452 |
|
|
16, /* bitsize */
|
1453 |
|
|
FALSE, /* pc_relative */
|
1454 |
|
|
0, /* bitpos */
|
1455 |
|
|
complain_overflow_signed, /* complain_on_overflow */
|
1456 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
1457 |
|
|
"R_PPC_TOC16", /* name */
|
1458 |
|
|
FALSE, /* partial_inplace */
|
1459 |
|
|
0, /* src_mask */
|
1460 |
|
|
0xffff, /* dst_mask */
|
1461 |
|
|
FALSE), /* pcrel_offset */
|
1462 |
|
|
};
|
1463 |
|
|
|
1464 |
|
|
/* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
|
1465 |
|
|
|
1466 |
|
|
static void
|
1467 |
|
|
ppc_elf_howto_init (void)
|
1468 |
|
|
{
|
1469 |
|
|
unsigned int i, type;
|
1470 |
|
|
|
1471 |
|
|
for (i = 0;
|
1472 |
|
|
i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
|
1473 |
|
|
i++)
|
1474 |
|
|
{
|
1475 |
|
|
type = ppc_elf_howto_raw[i].type;
|
1476 |
|
|
if (type >= (sizeof (ppc_elf_howto_table)
|
1477 |
|
|
/ sizeof (ppc_elf_howto_table[0])))
|
1478 |
|
|
abort ();
|
1479 |
|
|
ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
|
1480 |
|
|
}
|
1481 |
|
|
}
|
1482 |
|
|
|
1483 |
|
|
static reloc_howto_type *
|
1484 |
|
|
ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
|
1485 |
|
|
bfd_reloc_code_real_type code)
|
1486 |
|
|
{
|
1487 |
|
|
enum elf_ppc_reloc_type r;
|
1488 |
|
|
|
1489 |
|
|
/* Initialize howto table if not already done. */
|
1490 |
|
|
if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
1491 |
|
|
ppc_elf_howto_init ();
|
1492 |
|
|
|
1493 |
|
|
switch (code)
|
1494 |
|
|
{
|
1495 |
|
|
default:
|
1496 |
|
|
return NULL;
|
1497 |
|
|
|
1498 |
|
|
case BFD_RELOC_NONE: r = R_PPC_NONE; break;
|
1499 |
|
|
case BFD_RELOC_32: r = R_PPC_ADDR32; break;
|
1500 |
|
|
case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
|
1501 |
|
|
case BFD_RELOC_16: r = R_PPC_ADDR16; break;
|
1502 |
|
|
case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
|
1503 |
|
|
case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
|
1504 |
|
|
case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
|
1505 |
|
|
case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
|
1506 |
|
|
case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
|
1507 |
|
|
case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
|
1508 |
|
|
case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
|
1509 |
|
|
case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
|
1510 |
|
|
case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
|
1511 |
|
|
case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
|
1512 |
|
|
case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
|
1513 |
|
|
case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
|
1514 |
|
|
case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
|
1515 |
|
|
case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
|
1516 |
|
|
case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
|
1517 |
|
|
case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
|
1518 |
|
|
case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
|
1519 |
|
|
case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
|
1520 |
|
|
case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
|
1521 |
|
|
case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
|
1522 |
|
|
case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
|
1523 |
|
|
case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
|
1524 |
|
|
case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
|
1525 |
|
|
case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
|
1526 |
|
|
case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
|
1527 |
|
|
case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
|
1528 |
|
|
case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
|
1529 |
|
|
case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
|
1530 |
|
|
case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
|
1531 |
|
|
case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
|
1532 |
|
|
case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
|
1533 |
|
|
case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
|
1534 |
|
|
case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
|
1535 |
|
|
case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
|
1536 |
|
|
case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
|
1537 |
|
|
case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
|
1538 |
|
|
case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
|
1539 |
|
|
case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
|
1540 |
|
|
case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
|
1541 |
|
|
case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
|
1542 |
|
|
case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
|
1543 |
|
|
case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
|
1544 |
|
|
case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
|
1545 |
|
|
case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
|
1546 |
|
|
case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
|
1547 |
|
|
case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
|
1548 |
|
|
case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
|
1549 |
|
|
case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
|
1550 |
|
|
case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
|
1551 |
|
|
case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
|
1552 |
|
|
case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
|
1553 |
|
|
case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
|
1554 |
|
|
case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
|
1555 |
|
|
case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
|
1556 |
|
|
case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
|
1557 |
|
|
case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
|
1558 |
|
|
case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
|
1559 |
|
|
case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
|
1560 |
|
|
case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
|
1561 |
|
|
case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
|
1562 |
|
|
case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
|
1563 |
|
|
case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
|
1564 |
|
|
case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
|
1565 |
|
|
case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
|
1566 |
|
|
case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
|
1567 |
|
|
case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
|
1568 |
|
|
case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
|
1569 |
|
|
case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
|
1570 |
|
|
case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
|
1571 |
|
|
case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
|
1572 |
|
|
case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
|
1573 |
|
|
case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
|
1574 |
|
|
case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
|
1575 |
|
|
case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
|
1576 |
|
|
case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
|
1577 |
|
|
case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
|
1578 |
|
|
case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
|
1579 |
|
|
case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
|
1580 |
|
|
case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
|
1581 |
|
|
case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
|
1582 |
|
|
case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
|
1583 |
|
|
}
|
1584 |
|
|
|
1585 |
|
|
return ppc_elf_howto_table[r];
|
1586 |
|
|
};
|
1587 |
|
|
|
1588 |
|
|
static reloc_howto_type *
|
1589 |
|
|
ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
|
1590 |
|
|
const char *r_name)
|
1591 |
|
|
{
|
1592 |
|
|
unsigned int i;
|
1593 |
|
|
|
1594 |
|
|
for (i = 0;
|
1595 |
|
|
i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
|
1596 |
|
|
i++)
|
1597 |
|
|
if (ppc_elf_howto_raw[i].name != NULL
|
1598 |
|
|
&& strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
|
1599 |
|
|
return &ppc_elf_howto_raw[i];
|
1600 |
|
|
|
1601 |
|
|
return NULL;
|
1602 |
|
|
}
|
1603 |
|
|
|
1604 |
|
|
/* Set the howto pointer for a PowerPC ELF reloc. */
|
1605 |
|
|
|
1606 |
|
|
static void
|
1607 |
|
|
ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
|
1608 |
|
|
arelent *cache_ptr,
|
1609 |
|
|
Elf_Internal_Rela *dst)
|
1610 |
|
|
{
|
1611 |
|
|
/* Initialize howto table if not already done. */
|
1612 |
|
|
if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
1613 |
|
|
ppc_elf_howto_init ();
|
1614 |
|
|
|
1615 |
|
|
BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
|
1616 |
|
|
cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
|
1617 |
|
|
|
1618 |
|
|
/* Just because the above assert didn't trigger doesn't mean that
|
1619 |
|
|
ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
|
1620 |
|
|
if (!cache_ptr->howto)
|
1621 |
|
|
{
|
1622 |
|
|
(*_bfd_error_handler) (_("%B: invalid relocation type %d"),
|
1623 |
|
|
abfd, ELF32_R_TYPE (dst->r_info));
|
1624 |
|
|
bfd_set_error (bfd_error_bad_value);
|
1625 |
|
|
|
1626 |
|
|
cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
|
1627 |
|
|
}
|
1628 |
|
|
}
|
1629 |
|
|
|
1630 |
|
|
/* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
|
1631 |
|
|
|
1632 |
|
|
static bfd_reloc_status_type
|
1633 |
|
|
ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
|
1634 |
|
|
arelent *reloc_entry,
|
1635 |
|
|
asymbol *symbol,
|
1636 |
|
|
void *data ATTRIBUTE_UNUSED,
|
1637 |
|
|
asection *input_section,
|
1638 |
|
|
bfd *output_bfd,
|
1639 |
|
|
char **error_message ATTRIBUTE_UNUSED)
|
1640 |
|
|
{
|
1641 |
|
|
bfd_vma relocation;
|
1642 |
|
|
|
1643 |
|
|
if (output_bfd != NULL)
|
1644 |
|
|
{
|
1645 |
|
|
reloc_entry->address += input_section->output_offset;
|
1646 |
|
|
return bfd_reloc_ok;
|
1647 |
|
|
}
|
1648 |
|
|
|
1649 |
|
|
if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
|
1650 |
|
|
return bfd_reloc_outofrange;
|
1651 |
|
|
|
1652 |
|
|
if (bfd_is_com_section (symbol->section))
|
1653 |
|
|
relocation = 0;
|
1654 |
|
|
else
|
1655 |
|
|
relocation = symbol->value;
|
1656 |
|
|
|
1657 |
|
|
relocation += symbol->section->output_section->vma;
|
1658 |
|
|
relocation += symbol->section->output_offset;
|
1659 |
|
|
relocation += reloc_entry->addend;
|
1660 |
|
|
if (reloc_entry->howto->pc_relative)
|
1661 |
|
|
relocation -= reloc_entry->address;
|
1662 |
|
|
|
1663 |
|
|
reloc_entry->addend += (relocation & 0x8000) << 1;
|
1664 |
|
|
|
1665 |
|
|
return bfd_reloc_continue;
|
1666 |
|
|
}
|
1667 |
|
|
|
1668 |
|
|
static bfd_reloc_status_type
|
1669 |
|
|
ppc_elf_unhandled_reloc (bfd *abfd,
|
1670 |
|
|
arelent *reloc_entry,
|
1671 |
|
|
asymbol *symbol,
|
1672 |
|
|
void *data,
|
1673 |
|
|
asection *input_section,
|
1674 |
|
|
bfd *output_bfd,
|
1675 |
|
|
char **error_message)
|
1676 |
|
|
{
|
1677 |
|
|
/* If this is a relocatable link (output_bfd test tells us), just
|
1678 |
|
|
call the generic function. Any adjustment will be done at final
|
1679 |
|
|
link time. */
|
1680 |
|
|
if (output_bfd != NULL)
|
1681 |
|
|
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
|
1682 |
|
|
input_section, output_bfd, error_message);
|
1683 |
|
|
|
1684 |
|
|
if (error_message != NULL)
|
1685 |
|
|
{
|
1686 |
|
|
static char buf[60];
|
1687 |
|
|
sprintf (buf, _("generic linker can't handle %s"),
|
1688 |
|
|
reloc_entry->howto->name);
|
1689 |
|
|
*error_message = buf;
|
1690 |
|
|
}
|
1691 |
|
|
return bfd_reloc_dangerous;
|
1692 |
|
|
}
|
1693 |
|
|
|
1694 |
|
|
/* Sections created by the linker. */
|
1695 |
|
|
|
1696 |
|
|
typedef struct elf_linker_section
|
1697 |
|
|
{
|
1698 |
|
|
/* Pointer to the bfd section. */
|
1699 |
|
|
asection *section;
|
1700 |
|
|
/* Section name. */
|
1701 |
|
|
const char *name;
|
1702 |
|
|
/* Associated bss section name. */
|
1703 |
|
|
const char *bss_name;
|
1704 |
|
|
/* Associated symbol name. */
|
1705 |
|
|
const char *sym_name;
|
1706 |
|
|
/* Associated symbol. */
|
1707 |
|
|
struct elf_link_hash_entry *sym;
|
1708 |
|
|
} elf_linker_section_t;
|
1709 |
|
|
|
1710 |
|
|
/* Linked list of allocated pointer entries. This hangs off of the
|
1711 |
|
|
symbol lists, and provides allows us to return different pointers,
|
1712 |
|
|
based on different addend's. */
|
1713 |
|
|
|
1714 |
|
|
typedef struct elf_linker_section_pointers
|
1715 |
|
|
{
|
1716 |
|
|
/* next allocated pointer for this symbol */
|
1717 |
|
|
struct elf_linker_section_pointers *next;
|
1718 |
|
|
/* offset of pointer from beginning of section */
|
1719 |
|
|
bfd_vma offset;
|
1720 |
|
|
/* addend used */
|
1721 |
|
|
bfd_vma addend;
|
1722 |
|
|
/* which linker section this is */
|
1723 |
|
|
elf_linker_section_t *lsect;
|
1724 |
|
|
} elf_linker_section_pointers_t;
|
1725 |
|
|
|
1726 |
|
|
struct ppc_elf_obj_tdata
|
1727 |
|
|
{
|
1728 |
|
|
struct elf_obj_tdata elf;
|
1729 |
|
|
|
1730 |
|
|
/* A mapping from local symbols to offsets into the various linker
|
1731 |
|
|
sections added. This is index by the symbol index. */
|
1732 |
|
|
elf_linker_section_pointers_t **linker_section_pointers;
|
1733 |
|
|
|
1734 |
|
|
/* Flags used to auto-detect plt type. */
|
1735 |
|
|
unsigned int makes_plt_call : 1;
|
1736 |
|
|
unsigned int has_rel16 : 1;
|
1737 |
|
|
};
|
1738 |
|
|
|
1739 |
|
|
#define ppc_elf_tdata(bfd) \
|
1740 |
|
|
((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
|
1741 |
|
|
|
1742 |
|
|
#define elf_local_ptr_offsets(bfd) \
|
1743 |
|
|
(ppc_elf_tdata (bfd)->linker_section_pointers)
|
1744 |
|
|
|
1745 |
|
|
#define is_ppc_elf(bfd) \
|
1746 |
|
|
(bfd_get_flavour (bfd) == bfd_target_elf_flavour \
|
1747 |
|
|
&& elf_object_id (bfd) == PPC32_ELF_TDATA)
|
1748 |
|
|
|
1749 |
|
|
/* Override the generic function because we store some extras. */
|
1750 |
|
|
|
1751 |
|
|
static bfd_boolean
|
1752 |
|
|
ppc_elf_mkobject (bfd *abfd)
|
1753 |
|
|
{
|
1754 |
|
|
return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata),
|
1755 |
|
|
PPC32_ELF_TDATA);
|
1756 |
|
|
}
|
1757 |
|
|
|
1758 |
|
|
/* Fix bad default arch selected for a 32 bit input bfd when the
|
1759 |
|
|
default is 64 bit. */
|
1760 |
|
|
|
1761 |
|
|
static bfd_boolean
|
1762 |
|
|
ppc_elf_object_p (bfd *abfd)
|
1763 |
|
|
{
|
1764 |
|
|
if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
|
1765 |
|
|
{
|
1766 |
|
|
Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
|
1767 |
|
|
|
1768 |
|
|
if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
|
1769 |
|
|
{
|
1770 |
|
|
/* Relies on arch after 64 bit default being 32 bit default. */
|
1771 |
|
|
abfd->arch_info = abfd->arch_info->next;
|
1772 |
|
|
BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
|
1773 |
|
|
}
|
1774 |
|
|
}
|
1775 |
|
|
return TRUE;
|
1776 |
|
|
}
|
1777 |
|
|
|
1778 |
|
|
/* Function to set whether a module needs the -mrelocatable bit set. */
|
1779 |
|
|
|
1780 |
|
|
static bfd_boolean
|
1781 |
|
|
ppc_elf_set_private_flags (bfd *abfd, flagword flags)
|
1782 |
|
|
{
|
1783 |
|
|
BFD_ASSERT (!elf_flags_init (abfd)
|
1784 |
|
|
|| elf_elfheader (abfd)->e_flags == flags);
|
1785 |
|
|
|
1786 |
|
|
elf_elfheader (abfd)->e_flags = flags;
|
1787 |
|
|
elf_flags_init (abfd) = TRUE;
|
1788 |
|
|
return TRUE;
|
1789 |
|
|
}
|
1790 |
|
|
|
1791 |
|
|
/* Support for core dump NOTE sections. */
|
1792 |
|
|
|
1793 |
|
|
static bfd_boolean
|
1794 |
|
|
ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
|
1795 |
|
|
{
|
1796 |
|
|
int offset;
|
1797 |
|
|
unsigned int size;
|
1798 |
|
|
|
1799 |
|
|
switch (note->descsz)
|
1800 |
|
|
{
|
1801 |
|
|
default:
|
1802 |
|
|
return FALSE;
|
1803 |
|
|
|
1804 |
|
|
case 268: /* Linux/PPC. */
|
1805 |
|
|
/* pr_cursig */
|
1806 |
|
|
elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
|
1807 |
|
|
|
1808 |
|
|
/* pr_pid */
|
1809 |
|
|
elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
|
1810 |
|
|
|
1811 |
|
|
/* pr_reg */
|
1812 |
|
|
offset = 72;
|
1813 |
|
|
size = 192;
|
1814 |
|
|
|
1815 |
|
|
break;
|
1816 |
|
|
}
|
1817 |
|
|
|
1818 |
|
|
/* Make a ".reg/999" section. */
|
1819 |
|
|
return _bfd_elfcore_make_pseudosection (abfd, ".reg",
|
1820 |
|
|
size, note->descpos + offset);
|
1821 |
|
|
}
|
1822 |
|
|
|
1823 |
|
|
static bfd_boolean
|
1824 |
|
|
ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
|
1825 |
|
|
{
|
1826 |
|
|
switch (note->descsz)
|
1827 |
|
|
{
|
1828 |
|
|
default:
|
1829 |
|
|
return FALSE;
|
1830 |
|
|
|
1831 |
|
|
case 128: /* Linux/PPC elf_prpsinfo. */
|
1832 |
|
|
elf_tdata (abfd)->core_program
|
1833 |
|
|
= _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
|
1834 |
|
|
elf_tdata (abfd)->core_command
|
1835 |
|
|
= _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
|
1836 |
|
|
}
|
1837 |
|
|
|
1838 |
|
|
/* Note that for some reason, a spurious space is tacked
|
1839 |
|
|
onto the end of the args in some (at least one anyway)
|
1840 |
|
|
implementations, so strip it off if it exists. */
|
1841 |
|
|
|
1842 |
|
|
{
|
1843 |
|
|
char *command = elf_tdata (abfd)->core_command;
|
1844 |
|
|
int n = strlen (command);
|
1845 |
|
|
|
1846 |
|
|
if (0 < n && command[n - 1] == ' ')
|
1847 |
|
|
command[n - 1] = '\0';
|
1848 |
|
|
}
|
1849 |
|
|
|
1850 |
|
|
return TRUE;
|
1851 |
|
|
}
|
1852 |
|
|
|
1853 |
|
|
static char *
|
1854 |
|
|
ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
|
1855 |
|
|
{
|
1856 |
|
|
switch (note_type)
|
1857 |
|
|
{
|
1858 |
|
|
default:
|
1859 |
|
|
return NULL;
|
1860 |
|
|
|
1861 |
|
|
case NT_PRPSINFO:
|
1862 |
|
|
{
|
1863 |
|
|
char data[128];
|
1864 |
|
|
va_list ap;
|
1865 |
|
|
|
1866 |
|
|
va_start (ap, note_type);
|
1867 |
|
|
memset (data, 0, 32);
|
1868 |
|
|
strncpy (data + 32, va_arg (ap, const char *), 16);
|
1869 |
|
|
strncpy (data + 48, va_arg (ap, const char *), 80);
|
1870 |
|
|
va_end (ap);
|
1871 |
|
|
return elfcore_write_note (abfd, buf, bufsiz,
|
1872 |
|
|
"CORE", note_type, data, sizeof (data));
|
1873 |
|
|
}
|
1874 |
|
|
|
1875 |
|
|
case NT_PRSTATUS:
|
1876 |
|
|
{
|
1877 |
|
|
char data[268];
|
1878 |
|
|
va_list ap;
|
1879 |
|
|
long pid;
|
1880 |
|
|
int cursig;
|
1881 |
|
|
const void *greg;
|
1882 |
|
|
|
1883 |
|
|
va_start (ap, note_type);
|
1884 |
|
|
memset (data, 0, 72);
|
1885 |
|
|
pid = va_arg (ap, long);
|
1886 |
|
|
bfd_put_32 (abfd, pid, data + 24);
|
1887 |
|
|
cursig = va_arg (ap, int);
|
1888 |
|
|
bfd_put_16 (abfd, cursig, data + 12);
|
1889 |
|
|
greg = va_arg (ap, const void *);
|
1890 |
|
|
memcpy (data + 72, greg, 192);
|
1891 |
|
|
memset (data + 264, 0, 4);
|
1892 |
|
|
va_end (ap);
|
1893 |
|
|
return elfcore_write_note (abfd, buf, bufsiz,
|
1894 |
|
|
"CORE", note_type, data, sizeof (data));
|
1895 |
|
|
}
|
1896 |
|
|
}
|
1897 |
|
|
}
|
1898 |
|
|
|
1899 |
|
|
/* Return address for Ith PLT stub in section PLT, for relocation REL
|
1900 |
|
|
or (bfd_vma) -1 if it should not be included. */
|
1901 |
|
|
|
1902 |
|
|
static bfd_vma
|
1903 |
|
|
ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
|
1904 |
|
|
const asection *plt ATTRIBUTE_UNUSED,
|
1905 |
|
|
const arelent *rel)
|
1906 |
|
|
{
|
1907 |
|
|
return rel->address;
|
1908 |
|
|
}
|
1909 |
|
|
|
1910 |
|
|
/* Handle a PowerPC specific section when reading an object file. This
|
1911 |
|
|
is called when bfd_section_from_shdr finds a section with an unknown
|
1912 |
|
|
type. */
|
1913 |
|
|
|
1914 |
|
|
static bfd_boolean
|
1915 |
|
|
ppc_elf_section_from_shdr (bfd *abfd,
|
1916 |
|
|
Elf_Internal_Shdr *hdr,
|
1917 |
|
|
const char *name,
|
1918 |
|
|
int shindex)
|
1919 |
|
|
{
|
1920 |
|
|
asection *newsect;
|
1921 |
|
|
flagword flags;
|
1922 |
|
|
|
1923 |
|
|
if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
|
1924 |
|
|
return FALSE;
|
1925 |
|
|
|
1926 |
|
|
newsect = hdr->bfd_section;
|
1927 |
|
|
flags = bfd_get_section_flags (abfd, newsect);
|
1928 |
|
|
if (hdr->sh_flags & SHF_EXCLUDE)
|
1929 |
|
|
flags |= SEC_EXCLUDE;
|
1930 |
|
|
|
1931 |
|
|
if (hdr->sh_type == SHT_ORDERED)
|
1932 |
|
|
flags |= SEC_SORT_ENTRIES;
|
1933 |
|
|
|
1934 |
|
|
bfd_set_section_flags (abfd, newsect, flags);
|
1935 |
|
|
return TRUE;
|
1936 |
|
|
}
|
1937 |
|
|
|
1938 |
|
|
/* Set up any other section flags and such that may be necessary. */
|
1939 |
|
|
|
1940 |
|
|
static bfd_boolean
|
1941 |
|
|
ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
|
1942 |
|
|
Elf_Internal_Shdr *shdr,
|
1943 |
|
|
asection *asect)
|
1944 |
|
|
{
|
1945 |
|
|
if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE)
|
1946 |
|
|
shdr->sh_flags |= SHF_EXCLUDE;
|
1947 |
|
|
|
1948 |
|
|
if ((asect->flags & SEC_SORT_ENTRIES) != 0)
|
1949 |
|
|
shdr->sh_type = SHT_ORDERED;
|
1950 |
|
|
|
1951 |
|
|
return TRUE;
|
1952 |
|
|
}
|
1953 |
|
|
|
1954 |
|
|
/* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
|
1955 |
|
|
need to bump up the number of section headers. */
|
1956 |
|
|
|
1957 |
|
|
static int
|
1958 |
|
|
ppc_elf_additional_program_headers (bfd *abfd,
|
1959 |
|
|
struct bfd_link_info *info ATTRIBUTE_UNUSED)
|
1960 |
|
|
{
|
1961 |
|
|
asection *s;
|
1962 |
|
|
int ret = 0;
|
1963 |
|
|
|
1964 |
|
|
s = bfd_get_section_by_name (abfd, ".sbss2");
|
1965 |
|
|
if (s != NULL && (s->flags & SEC_ALLOC) != 0)
|
1966 |
|
|
++ret;
|
1967 |
|
|
|
1968 |
|
|
s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
|
1969 |
|
|
if (s != NULL && (s->flags & SEC_ALLOC) != 0)
|
1970 |
|
|
++ret;
|
1971 |
|
|
|
1972 |
|
|
return ret;
|
1973 |
|
|
}
|
1974 |
|
|
|
1975 |
|
|
/* Add extra PPC sections -- Note, for now, make .sbss2 and
|
1976 |
|
|
.PPC.EMB.sbss0 a normal section, and not a bss section so
|
1977 |
|
|
that the linker doesn't crater when trying to make more than
|
1978 |
|
|
2 sections. */
|
1979 |
|
|
|
1980 |
|
|
static const struct bfd_elf_special_section ppc_elf_special_sections[] =
|
1981 |
|
|
{
|
1982 |
|
|
{ STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
|
1983 |
|
|
{ STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
|
1984 |
|
|
{ STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC },
|
1985 |
|
|
{ STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
|
1986 |
|
|
{ STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC },
|
1987 |
|
|
{ STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC },
|
1988 |
|
|
{ STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 },
|
1989 |
|
|
{ STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC },
|
1990 |
|
|
{ STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC },
|
1991 |
|
|
{ NULL, 0, 0, 0, 0 }
|
1992 |
|
|
};
|
1993 |
|
|
|
1994 |
|
|
/* This is what we want for new plt/got. */
|
1995 |
|
|
static struct bfd_elf_special_section ppc_alt_plt =
|
1996 |
|
|
{ STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC };
|
1997 |
|
|
|
1998 |
|
|
static const struct bfd_elf_special_section *
|
1999 |
|
|
ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
|
2000 |
|
|
{
|
2001 |
|
|
const struct bfd_elf_special_section *ssect;
|
2002 |
|
|
|
2003 |
|
|
/* See if this is one of the special sections. */
|
2004 |
|
|
if (sec->name == NULL)
|
2005 |
|
|
return NULL;
|
2006 |
|
|
|
2007 |
|
|
ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections,
|
2008 |
|
|
sec->use_rela_p);
|
2009 |
|
|
if (ssect != NULL)
|
2010 |
|
|
{
|
2011 |
|
|
if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0)
|
2012 |
|
|
ssect = &ppc_alt_plt;
|
2013 |
|
|
return ssect;
|
2014 |
|
|
}
|
2015 |
|
|
|
2016 |
|
|
return _bfd_elf_get_sec_type_attr (abfd, sec);
|
2017 |
|
|
}
|
2018 |
|
|
|
2019 |
|
|
/* Very simple linked list structure for recording apuinfo values. */
|
2020 |
|
|
typedef struct apuinfo_list
|
2021 |
|
|
{
|
2022 |
|
|
struct apuinfo_list *next;
|
2023 |
|
|
unsigned long value;
|
2024 |
|
|
}
|
2025 |
|
|
apuinfo_list;
|
2026 |
|
|
|
2027 |
|
|
static apuinfo_list *head;
|
2028 |
|
|
|
2029 |
|
|
|
2030 |
|
|
static void
|
2031 |
|
|
apuinfo_list_init (void)
|
2032 |
|
|
{
|
2033 |
|
|
head = NULL;
|
2034 |
|
|
}
|
2035 |
|
|
|
2036 |
|
|
static void
|
2037 |
|
|
apuinfo_list_add (unsigned long value)
|
2038 |
|
|
{
|
2039 |
|
|
apuinfo_list *entry = head;
|
2040 |
|
|
|
2041 |
|
|
while (entry != NULL)
|
2042 |
|
|
{
|
2043 |
|
|
if (entry->value == value)
|
2044 |
|
|
return;
|
2045 |
|
|
entry = entry->next;
|
2046 |
|
|
}
|
2047 |
|
|
|
2048 |
|
|
entry = bfd_malloc (sizeof (* entry));
|
2049 |
|
|
if (entry == NULL)
|
2050 |
|
|
return;
|
2051 |
|
|
|
2052 |
|
|
entry->value = value;
|
2053 |
|
|
entry->next = head;
|
2054 |
|
|
head = entry;
|
2055 |
|
|
}
|
2056 |
|
|
|
2057 |
|
|
static unsigned
|
2058 |
|
|
apuinfo_list_length (void)
|
2059 |
|
|
{
|
2060 |
|
|
apuinfo_list *entry;
|
2061 |
|
|
unsigned long count;
|
2062 |
|
|
|
2063 |
|
|
for (entry = head, count = 0;
|
2064 |
|
|
entry;
|
2065 |
|
|
entry = entry->next)
|
2066 |
|
|
++ count;
|
2067 |
|
|
|
2068 |
|
|
return count;
|
2069 |
|
|
}
|
2070 |
|
|
|
2071 |
|
|
static inline unsigned long
|
2072 |
|
|
apuinfo_list_element (unsigned long number)
|
2073 |
|
|
{
|
2074 |
|
|
apuinfo_list * entry;
|
2075 |
|
|
|
2076 |
|
|
for (entry = head;
|
2077 |
|
|
entry && number --;
|
2078 |
|
|
entry = entry->next)
|
2079 |
|
|
;
|
2080 |
|
|
|
2081 |
|
|
return entry ? entry->value : 0;
|
2082 |
|
|
}
|
2083 |
|
|
|
2084 |
|
|
static void
|
2085 |
|
|
apuinfo_list_finish (void)
|
2086 |
|
|
{
|
2087 |
|
|
apuinfo_list *entry;
|
2088 |
|
|
|
2089 |
|
|
for (entry = head; entry;)
|
2090 |
|
|
{
|
2091 |
|
|
apuinfo_list *next = entry->next;
|
2092 |
|
|
free (entry);
|
2093 |
|
|
entry = next;
|
2094 |
|
|
}
|
2095 |
|
|
|
2096 |
|
|
head = NULL;
|
2097 |
|
|
}
|
2098 |
|
|
|
2099 |
|
|
#define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
|
2100 |
|
|
#define APUINFO_LABEL "APUinfo"
|
2101 |
|
|
|
2102 |
|
|
/* Scan the input BFDs and create a linked list of
|
2103 |
|
|
the APUinfo values that will need to be emitted. */
|
2104 |
|
|
|
2105 |
|
|
static void
|
2106 |
|
|
ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
|
2107 |
|
|
{
|
2108 |
|
|
bfd *ibfd;
|
2109 |
|
|
asection *asec;
|
2110 |
|
|
char *buffer;
|
2111 |
|
|
unsigned num_input_sections;
|
2112 |
|
|
bfd_size_type output_section_size;
|
2113 |
|
|
unsigned i;
|
2114 |
|
|
unsigned num_entries;
|
2115 |
|
|
unsigned long offset;
|
2116 |
|
|
unsigned long length;
|
2117 |
|
|
const char *error_message = NULL;
|
2118 |
|
|
|
2119 |
|
|
if (link_info == NULL)
|
2120 |
|
|
return;
|
2121 |
|
|
|
2122 |
|
|
/* Scan the input bfds, looking for apuinfo sections. */
|
2123 |
|
|
num_input_sections = 0;
|
2124 |
|
|
output_section_size = 0;
|
2125 |
|
|
|
2126 |
|
|
for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
|
2127 |
|
|
{
|
2128 |
|
|
asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
|
2129 |
|
|
if (asec)
|
2130 |
|
|
{
|
2131 |
|
|
++ num_input_sections;
|
2132 |
|
|
output_section_size += asec->size;
|
2133 |
|
|
}
|
2134 |
|
|
}
|
2135 |
|
|
|
2136 |
|
|
/* We need at least one input sections
|
2137 |
|
|
in order to make merging worthwhile. */
|
2138 |
|
|
if (num_input_sections < 1)
|
2139 |
|
|
return;
|
2140 |
|
|
|
2141 |
|
|
/* Just make sure that the output section exists as well. */
|
2142 |
|
|
asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
|
2143 |
|
|
if (asec == NULL)
|
2144 |
|
|
return;
|
2145 |
|
|
|
2146 |
|
|
/* Allocate a buffer for the contents of the input sections. */
|
2147 |
|
|
buffer = bfd_malloc (output_section_size);
|
2148 |
|
|
if (buffer == NULL)
|
2149 |
|
|
return;
|
2150 |
|
|
|
2151 |
|
|
offset = 0;
|
2152 |
|
|
apuinfo_list_init ();
|
2153 |
|
|
|
2154 |
|
|
/* Read in the input sections contents. */
|
2155 |
|
|
for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
|
2156 |
|
|
{
|
2157 |
|
|
unsigned long datum;
|
2158 |
|
|
char *ptr;
|
2159 |
|
|
|
2160 |
|
|
asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
|
2161 |
|
|
if (asec == NULL)
|
2162 |
|
|
continue;
|
2163 |
|
|
|
2164 |
|
|
length = asec->size;
|
2165 |
|
|
if (length < 24)
|
2166 |
|
|
{
|
2167 |
|
|
error_message = _("corrupt or empty %s section in %B");
|
2168 |
|
|
goto fail;
|
2169 |
|
|
}
|
2170 |
|
|
|
2171 |
|
|
if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
|
2172 |
|
|
|| (bfd_bread (buffer + offset, length, ibfd) != length))
|
2173 |
|
|
{
|
2174 |
|
|
error_message = _("unable to read in %s section from %B");
|
2175 |
|
|
goto fail;
|
2176 |
|
|
}
|
2177 |
|
|
|
2178 |
|
|
/* Process the contents of the section. */
|
2179 |
|
|
ptr = buffer + offset;
|
2180 |
|
|
error_message = _("corrupt %s section in %B");
|
2181 |
|
|
|
2182 |
|
|
/* Verify the contents of the header. Note - we have to
|
2183 |
|
|
extract the values this way in order to allow for a
|
2184 |
|
|
host whose endian-ness is different from the target. */
|
2185 |
|
|
datum = bfd_get_32 (ibfd, ptr);
|
2186 |
|
|
if (datum != sizeof APUINFO_LABEL)
|
2187 |
|
|
goto fail;
|
2188 |
|
|
|
2189 |
|
|
datum = bfd_get_32 (ibfd, ptr + 8);
|
2190 |
|
|
if (datum != 0x2)
|
2191 |
|
|
goto fail;
|
2192 |
|
|
|
2193 |
|
|
if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
|
2194 |
|
|
goto fail;
|
2195 |
|
|
|
2196 |
|
|
/* Get the number of bytes used for apuinfo entries. */
|
2197 |
|
|
datum = bfd_get_32 (ibfd, ptr + 4);
|
2198 |
|
|
if (datum + 20 != length)
|
2199 |
|
|
goto fail;
|
2200 |
|
|
|
2201 |
|
|
/* Make sure that we do not run off the end of the section. */
|
2202 |
|
|
if (offset + length > output_section_size)
|
2203 |
|
|
goto fail;
|
2204 |
|
|
|
2205 |
|
|
/* Scan the apuinfo section, building a list of apuinfo numbers. */
|
2206 |
|
|
for (i = 0; i < datum; i += 4)
|
2207 |
|
|
apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i));
|
2208 |
|
|
|
2209 |
|
|
/* Update the offset. */
|
2210 |
|
|
offset += length;
|
2211 |
|
|
}
|
2212 |
|
|
|
2213 |
|
|
error_message = NULL;
|
2214 |
|
|
|
2215 |
|
|
/* Compute the size of the output section. */
|
2216 |
|
|
num_entries = apuinfo_list_length ();
|
2217 |
|
|
output_section_size = 20 + num_entries * 4;
|
2218 |
|
|
|
2219 |
|
|
asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
|
2220 |
|
|
|
2221 |
|
|
if (! bfd_set_section_size (abfd, asec, output_section_size))
|
2222 |
|
|
ibfd = abfd,
|
2223 |
|
|
error_message = _("warning: unable to set size of %s section in %B");
|
2224 |
|
|
|
2225 |
|
|
fail:
|
2226 |
|
|
free (buffer);
|
2227 |
|
|
|
2228 |
|
|
if (error_message)
|
2229 |
|
|
(*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
|
2230 |
|
|
}
|
2231 |
|
|
|
2232 |
|
|
/* Prevent the output section from accumulating the input sections'
|
2233 |
|
|
contents. We have already stored this in our linked list structure. */
|
2234 |
|
|
|
2235 |
|
|
static bfd_boolean
|
2236 |
|
|
ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
|
2237 |
|
|
struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
|
2238 |
|
|
asection *asec,
|
2239 |
|
|
bfd_byte *contents ATTRIBUTE_UNUSED)
|
2240 |
|
|
{
|
2241 |
|
|
return (apuinfo_list_length ()
|
2242 |
|
|
&& strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
|
2243 |
|
|
}
|
2244 |
|
|
|
2245 |
|
|
/* Finally we can generate the output section. */
|
2246 |
|
|
|
2247 |
|
|
static void
|
2248 |
|
|
ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
|
2249 |
|
|
{
|
2250 |
|
|
bfd_byte *buffer;
|
2251 |
|
|
asection *asec;
|
2252 |
|
|
unsigned i;
|
2253 |
|
|
unsigned num_entries;
|
2254 |
|
|
bfd_size_type length;
|
2255 |
|
|
|
2256 |
|
|
asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
|
2257 |
|
|
if (asec == NULL)
|
2258 |
|
|
return;
|
2259 |
|
|
|
2260 |
|
|
if (apuinfo_list_length () == 0)
|
2261 |
|
|
return;
|
2262 |
|
|
|
2263 |
|
|
length = asec->size;
|
2264 |
|
|
if (length < 20)
|
2265 |
|
|
return;
|
2266 |
|
|
|
2267 |
|
|
buffer = bfd_malloc (length);
|
2268 |
|
|
if (buffer == NULL)
|
2269 |
|
|
{
|
2270 |
|
|
(*_bfd_error_handler)
|
2271 |
|
|
(_("failed to allocate space for new APUinfo section."));
|
2272 |
|
|
return;
|
2273 |
|
|
}
|
2274 |
|
|
|
2275 |
|
|
/* Create the apuinfo header. */
|
2276 |
|
|
num_entries = apuinfo_list_length ();
|
2277 |
|
|
bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
|
2278 |
|
|
bfd_put_32 (abfd, num_entries * 4, buffer + 4);
|
2279 |
|
|
bfd_put_32 (abfd, 0x2, buffer + 8);
|
2280 |
|
|
strcpy ((char *) buffer + 12, APUINFO_LABEL);
|
2281 |
|
|
|
2282 |
|
|
length = 20;
|
2283 |
|
|
for (i = 0; i < num_entries; i++)
|
2284 |
|
|
{
|
2285 |
|
|
bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
|
2286 |
|
|
length += 4;
|
2287 |
|
|
}
|
2288 |
|
|
|
2289 |
|
|
if (length != asec->size)
|
2290 |
|
|
(*_bfd_error_handler) (_("failed to compute new APUinfo section."));
|
2291 |
|
|
|
2292 |
|
|
if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
|
2293 |
|
|
(*_bfd_error_handler) (_("failed to install new APUinfo section."));
|
2294 |
|
|
|
2295 |
|
|
free (buffer);
|
2296 |
|
|
|
2297 |
|
|
apuinfo_list_finish ();
|
2298 |
|
|
}
|
2299 |
|
|
|
2300 |
|
|
static bfd_boolean
|
2301 |
|
|
is_pic_glink_stub (bfd *abfd, asection *glink, bfd_vma off)
|
2302 |
|
|
{
|
2303 |
|
|
bfd_byte buf[16];
|
2304 |
|
|
unsigned int insn;
|
2305 |
|
|
|
2306 |
|
|
if (!bfd_get_section_contents (abfd, glink, buf, off, 16))
|
2307 |
|
|
return FALSE;
|
2308 |
|
|
|
2309 |
|
|
insn = bfd_get_32 (abfd, buf);
|
2310 |
|
|
if ((insn & 0xffff0000) == LWZ_11_30
|
2311 |
|
|
&& bfd_get_32 (abfd, buf + 4) == MTCTR_11
|
2312 |
|
|
&& bfd_get_32 (abfd, buf + 8) == BCTR)
|
2313 |
|
|
return TRUE;
|
2314 |
|
|
|
2315 |
|
|
if ((insn & 0xffff0000) == ADDIS_11_30
|
2316 |
|
|
&& (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11
|
2317 |
|
|
&& bfd_get_32 (abfd, buf + 8) == MTCTR_11
|
2318 |
|
|
&& bfd_get_32 (abfd, buf + 12) == BCTR)
|
2319 |
|
|
return TRUE;
|
2320 |
|
|
return FALSE;
|
2321 |
|
|
}
|
2322 |
|
|
|
2323 |
|
|
static bfd_boolean
|
2324 |
|
|
section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
|
2325 |
|
|
{
|
2326 |
|
|
bfd_vma vma = *(bfd_vma *) ptr;
|
2327 |
|
|
return ((section->flags & SEC_ALLOC) != 0
|
2328 |
|
|
&& section->vma <= vma
|
2329 |
|
|
&& vma < section->vma + section->size);
|
2330 |
|
|
}
|
2331 |
|
|
|
2332 |
|
|
static long
|
2333 |
|
|
ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms,
|
2334 |
|
|
long dynsymcount, asymbol **dynsyms,
|
2335 |
|
|
asymbol **ret)
|
2336 |
|
|
{
|
2337 |
|
|
bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
|
2338 |
|
|
asection *plt, *relplt, *dynamic, *glink;
|
2339 |
|
|
bfd_vma glink_vma = 0;
|
2340 |
|
|
bfd_vma resolv_vma = 0;
|
2341 |
|
|
bfd_vma stub_vma;
|
2342 |
|
|
asymbol *s;
|
2343 |
|
|
arelent *p;
|
2344 |
|
|
long count, i;
|
2345 |
|
|
size_t size;
|
2346 |
|
|
char *names;
|
2347 |
|
|
bfd_byte buf[4];
|
2348 |
|
|
|
2349 |
|
|
*ret = NULL;
|
2350 |
|
|
|
2351 |
|
|
if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
|
2352 |
|
|
return 0;
|
2353 |
|
|
|
2354 |
|
|
if (dynsymcount <= 0)
|
2355 |
|
|
return 0;
|
2356 |
|
|
|
2357 |
|
|
relplt = bfd_get_section_by_name (abfd, ".rela.plt");
|
2358 |
|
|
if (relplt == NULL)
|
2359 |
|
|
return 0;
|
2360 |
|
|
|
2361 |
|
|
plt = bfd_get_section_by_name (abfd, ".plt");
|
2362 |
|
|
if (plt == NULL)
|
2363 |
|
|
return 0;
|
2364 |
|
|
|
2365 |
|
|
/* Call common code to handle old-style executable PLTs. */
|
2366 |
|
|
if (elf_section_flags (plt) & SHF_EXECINSTR)
|
2367 |
|
|
return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms,
|
2368 |
|
|
dynsymcount, dynsyms, ret);
|
2369 |
|
|
|
2370 |
|
|
/* If this object was prelinked, the prelinker stored the address
|
2371 |
|
|
of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
|
2372 |
|
|
dynamic = bfd_get_section_by_name (abfd, ".dynamic");
|
2373 |
|
|
if (dynamic != NULL)
|
2374 |
|
|
{
|
2375 |
|
|
bfd_byte *dynbuf, *extdyn, *extdynend;
|
2376 |
|
|
size_t extdynsize;
|
2377 |
|
|
void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
|
2378 |
|
|
|
2379 |
|
|
if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
|
2380 |
|
|
return -1;
|
2381 |
|
|
|
2382 |
|
|
extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
|
2383 |
|
|
swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
|
2384 |
|
|
|
2385 |
|
|
extdyn = dynbuf;
|
2386 |
|
|
extdynend = extdyn + dynamic->size;
|
2387 |
|
|
for (; extdyn < extdynend; extdyn += extdynsize)
|
2388 |
|
|
{
|
2389 |
|
|
Elf_Internal_Dyn dyn;
|
2390 |
|
|
(*swap_dyn_in) (abfd, extdyn, &dyn);
|
2391 |
|
|
|
2392 |
|
|
if (dyn.d_tag == DT_NULL)
|
2393 |
|
|
break;
|
2394 |
|
|
|
2395 |
|
|
if (dyn.d_tag == DT_PPC_GOT)
|
2396 |
|
|
{
|
2397 |
|
|
unsigned int g_o_t = dyn.d_un.d_val;
|
2398 |
|
|
asection *got = bfd_get_section_by_name (abfd, ".got");
|
2399 |
|
|
if (got != NULL
|
2400 |
|
|
&& bfd_get_section_contents (abfd, got, buf,
|
2401 |
|
|
g_o_t - got->vma + 4, 4))
|
2402 |
|
|
glink_vma = bfd_get_32 (abfd, buf);
|
2403 |
|
|
break;
|
2404 |
|
|
}
|
2405 |
|
|
}
|
2406 |
|
|
free (dynbuf);
|
2407 |
|
|
}
|
2408 |
|
|
|
2409 |
|
|
/* Otherwise we read the first plt entry. */
|
2410 |
|
|
if (glink_vma == 0)
|
2411 |
|
|
{
|
2412 |
|
|
if (bfd_get_section_contents (abfd, plt, buf, 0, 4))
|
2413 |
|
|
glink_vma = bfd_get_32 (abfd, buf);
|
2414 |
|
|
}
|
2415 |
|
|
|
2416 |
|
|
if (glink_vma == 0)
|
2417 |
|
|
return 0;
|
2418 |
|
|
|
2419 |
|
|
/* The .glink section usually does not survive the final
|
2420 |
|
|
link; search for the section (usually .text) where the
|
2421 |
|
|
glink stubs now reside. */
|
2422 |
|
|
glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma);
|
2423 |
|
|
if (glink == NULL)
|
2424 |
|
|
return 0;
|
2425 |
|
|
|
2426 |
|
|
/* Determine glink PLT resolver by reading the relative branch
|
2427 |
|
|
from the first glink stub. */
|
2428 |
|
|
if (bfd_get_section_contents (abfd, glink, buf,
|
2429 |
|
|
glink_vma - glink->vma, 4))
|
2430 |
|
|
{
|
2431 |
|
|
unsigned int insn = bfd_get_32 (abfd, buf);
|
2432 |
|
|
|
2433 |
|
|
/* The first glink stub may either branch to the resolver ... */
|
2434 |
|
|
insn ^= B;
|
2435 |
|
|
if ((insn & ~0x3fffffc) == 0)
|
2436 |
|
|
resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000;
|
2437 |
|
|
|
2438 |
|
|
/* ... or fall through a bunch of NOPs. */
|
2439 |
|
|
else if ((insn ^ B ^ NOP) == 0)
|
2440 |
|
|
for (i = 4;
|
2441 |
|
|
bfd_get_section_contents (abfd, glink, buf,
|
2442 |
|
|
glink_vma - glink->vma + i, 4);
|
2443 |
|
|
i += 4)
|
2444 |
|
|
if (bfd_get_32 (abfd, buf) != NOP)
|
2445 |
|
|
{
|
2446 |
|
|
resolv_vma = glink_vma + i;
|
2447 |
|
|
break;
|
2448 |
|
|
}
|
2449 |
|
|
}
|
2450 |
|
|
|
2451 |
|
|
count = relplt->size / sizeof (Elf32_External_Rela);
|
2452 |
|
|
stub_vma = glink_vma - (bfd_vma) count * 16;
|
2453 |
|
|
/* If the stubs are those for -shared/-pie then we might have
|
2454 |
|
|
multiple stubs for each plt entry. If that is the case then
|
2455 |
|
|
there is no way to associate stubs with their plt entries short
|
2456 |
|
|
of figuring out the GOT pointer value used in the stub. */
|
2457 |
|
|
if (!bfd_get_section_contents (abfd, glink, buf,
|
2458 |
|
|
stub_vma - glink->vma, 4)
|
2459 |
|
|
|| ((bfd_get_32 (abfd, buf) & 0xffff0000) != LIS_11
|
2460 |
|
|
&& is_pic_glink_stub (abfd, glink, stub_vma - glink->vma - 16)))
|
2461 |
|
|
return 0;
|
2462 |
|
|
|
2463 |
|
|
slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
|
2464 |
|
|
if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
|
2465 |
|
|
return -1;
|
2466 |
|
|
|
2467 |
|
|
size = count * sizeof (asymbol);
|
2468 |
|
|
p = relplt->relocation;
|
2469 |
|
|
for (i = 0; i < count; i++, p++)
|
2470 |
|
|
size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
|
2471 |
|
|
|
2472 |
|
|
size += sizeof (asymbol) + sizeof ("__glink");
|
2473 |
|
|
|
2474 |
|
|
if (resolv_vma)
|
2475 |
|
|
size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
|
2476 |
|
|
|
2477 |
|
|
s = *ret = bfd_malloc (size);
|
2478 |
|
|
if (s == NULL)
|
2479 |
|
|
return -1;
|
2480 |
|
|
|
2481 |
|
|
names = (char *) (s + count + 1 + (resolv_vma != 0));
|
2482 |
|
|
p = relplt->relocation;
|
2483 |
|
|
for (i = 0; i < count; i++, p++)
|
2484 |
|
|
{
|
2485 |
|
|
size_t len;
|
2486 |
|
|
|
2487 |
|
|
*s = **p->sym_ptr_ptr;
|
2488 |
|
|
/* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
|
2489 |
|
|
we are defining a symbol, ensure one of them is set. */
|
2490 |
|
|
if ((s->flags & BSF_LOCAL) == 0)
|
2491 |
|
|
s->flags |= BSF_GLOBAL;
|
2492 |
|
|
s->flags |= BSF_SYNTHETIC;
|
2493 |
|
|
s->section = glink;
|
2494 |
|
|
s->value = stub_vma - glink->vma;
|
2495 |
|
|
s->name = names;
|
2496 |
|
|
s->udata.p = NULL;
|
2497 |
|
|
len = strlen ((*p->sym_ptr_ptr)->name);
|
2498 |
|
|
memcpy (names, (*p->sym_ptr_ptr)->name, len);
|
2499 |
|
|
names += len;
|
2500 |
|
|
memcpy (names, "@plt", sizeof ("@plt"));
|
2501 |
|
|
names += sizeof ("@plt");
|
2502 |
|
|
++s;
|
2503 |
|
|
stub_vma += 16;
|
2504 |
|
|
}
|
2505 |
|
|
|
2506 |
|
|
/* Add a symbol at the start of the glink branch table. */
|
2507 |
|
|
memset (s, 0, sizeof *s);
|
2508 |
|
|
s->the_bfd = abfd;
|
2509 |
|
|
s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
|
2510 |
|
|
s->section = glink;
|
2511 |
|
|
s->value = glink_vma - glink->vma;
|
2512 |
|
|
s->name = names;
|
2513 |
|
|
memcpy (names, "__glink", sizeof ("__glink"));
|
2514 |
|
|
names += sizeof ("__glink");
|
2515 |
|
|
s++;
|
2516 |
|
|
count++;
|
2517 |
|
|
|
2518 |
|
|
if (resolv_vma)
|
2519 |
|
|
{
|
2520 |
|
|
/* Add a symbol for the glink PLT resolver. */
|
2521 |
|
|
memset (s, 0, sizeof *s);
|
2522 |
|
|
s->the_bfd = abfd;
|
2523 |
|
|
s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
|
2524 |
|
|
s->section = glink;
|
2525 |
|
|
s->value = resolv_vma - glink->vma;
|
2526 |
|
|
s->name = names;
|
2527 |
|
|
memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
|
2528 |
|
|
names += sizeof ("__glink_PLTresolve");
|
2529 |
|
|
s++;
|
2530 |
|
|
count++;
|
2531 |
|
|
}
|
2532 |
|
|
|
2533 |
|
|
return count;
|
2534 |
|
|
}
|
2535 |
|
|
|
2536 |
|
|
/* The following functions are specific to the ELF linker, while
|
2537 |
|
|
functions above are used generally. They appear in this file more
|
2538 |
|
|
or less in the order in which they are called. eg.
|
2539 |
|
|
ppc_elf_check_relocs is called early in the link process,
|
2540 |
|
|
ppc_elf_finish_dynamic_sections is one of the last functions
|
2541 |
|
|
called. */
|
2542 |
|
|
|
2543 |
|
|
/* The PPC linker needs to keep track of the number of relocs that it
|
2544 |
|
|
decides to copy as dynamic relocs in check_relocs for each symbol.
|
2545 |
|
|
This is so that it can later discard them if they are found to be
|
2546 |
|
|
unnecessary. We store the information in a field extending the
|
2547 |
|
|
regular ELF linker hash table. */
|
2548 |
|
|
|
2549 |
|
|
struct ppc_elf_dyn_relocs
|
2550 |
|
|
{
|
2551 |
|
|
struct ppc_elf_dyn_relocs *next;
|
2552 |
|
|
|
2553 |
|
|
/* The input section of the reloc. */
|
2554 |
|
|
asection *sec;
|
2555 |
|
|
|
2556 |
|
|
/* Total number of relocs copied for the input section. */
|
2557 |
|
|
bfd_size_type count;
|
2558 |
|
|
|
2559 |
|
|
/* Number of pc-relative relocs copied for the input section. */
|
2560 |
|
|
bfd_size_type pc_count;
|
2561 |
|
|
};
|
2562 |
|
|
|
2563 |
|
|
/* Track PLT entries needed for a given symbol. We might need more
|
2564 |
|
|
than one glink entry per symbol. */
|
2565 |
|
|
struct plt_entry
|
2566 |
|
|
{
|
2567 |
|
|
struct plt_entry *next;
|
2568 |
|
|
|
2569 |
|
|
/* -fPIC uses multiple GOT sections, one per file, called ".got2".
|
2570 |
|
|
This field stores the offset into .got2 used to initialise the
|
2571 |
|
|
GOT pointer reg. It will always be at least 32768 (and for
|
2572 |
|
|
current gcc this is the only offset used). */
|
2573 |
|
|
bfd_vma addend;
|
2574 |
|
|
|
2575 |
|
|
/* The .got2 section. */
|
2576 |
|
|
asection *sec;
|
2577 |
|
|
|
2578 |
|
|
/* PLT refcount or offset. */
|
2579 |
|
|
union
|
2580 |
|
|
{
|
2581 |
|
|
bfd_signed_vma refcount;
|
2582 |
|
|
bfd_vma offset;
|
2583 |
|
|
} plt;
|
2584 |
|
|
|
2585 |
|
|
/* .glink stub offset. */
|
2586 |
|
|
bfd_vma glink_offset;
|
2587 |
|
|
};
|
2588 |
|
|
|
2589 |
|
|
/* Of those relocs that might be copied as dynamic relocs, this function
|
2590 |
|
|
selects those that must be copied when linking a shared library,
|
2591 |
|
|
even when the symbol is local. */
|
2592 |
|
|
|
2593 |
|
|
static int
|
2594 |
|
|
must_be_dyn_reloc (struct bfd_link_info *info,
|
2595 |
|
|
enum elf_ppc_reloc_type r_type)
|
2596 |
|
|
{
|
2597 |
|
|
switch (r_type)
|
2598 |
|
|
{
|
2599 |
|
|
default:
|
2600 |
|
|
return 1;
|
2601 |
|
|
|
2602 |
|
|
case R_PPC_REL24:
|
2603 |
|
|
case R_PPC_REL14:
|
2604 |
|
|
case R_PPC_REL14_BRTAKEN:
|
2605 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
2606 |
|
|
case R_PPC_REL32:
|
2607 |
|
|
return 0;
|
2608 |
|
|
|
2609 |
|
|
case R_PPC_TPREL32:
|
2610 |
|
|
case R_PPC_TPREL16:
|
2611 |
|
|
case R_PPC_TPREL16_LO:
|
2612 |
|
|
case R_PPC_TPREL16_HI:
|
2613 |
|
|
case R_PPC_TPREL16_HA:
|
2614 |
|
|
return !info->executable;
|
2615 |
|
|
}
|
2616 |
|
|
}
|
2617 |
|
|
|
2618 |
|
|
/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
|
2619 |
|
|
copying dynamic variables from a shared lib into an app's dynbss
|
2620 |
|
|
section, and instead use a dynamic relocation to point into the
|
2621 |
|
|
shared lib. */
|
2622 |
|
|
#define ELIMINATE_COPY_RELOCS 1
|
2623 |
|
|
|
2624 |
|
|
/* PPC ELF linker hash entry. */
|
2625 |
|
|
|
2626 |
|
|
struct ppc_elf_link_hash_entry
|
2627 |
|
|
{
|
2628 |
|
|
struct elf_link_hash_entry elf;
|
2629 |
|
|
|
2630 |
|
|
/* If this symbol is used in the linker created sections, the processor
|
2631 |
|
|
specific backend uses this field to map the field into the offset
|
2632 |
|
|
from the beginning of the section. */
|
2633 |
|
|
elf_linker_section_pointers_t *linker_section_pointer;
|
2634 |
|
|
|
2635 |
|
|
/* Track dynamic relocs copied for this symbol. */
|
2636 |
|
|
struct ppc_elf_dyn_relocs *dyn_relocs;
|
2637 |
|
|
|
2638 |
|
|
/* Contexts in which symbol is used in the GOT (or TOC).
|
2639 |
|
|
TLS_GD .. TLS_TLS bits are or'd into the mask as the
|
2640 |
|
|
corresponding relocs are encountered during check_relocs.
|
2641 |
|
|
tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
|
2642 |
|
|
indicate the corresponding GOT entry type is not needed. */
|
2643 |
|
|
#define TLS_GD 1 /* GD reloc. */
|
2644 |
|
|
#define TLS_LD 2 /* LD reloc. */
|
2645 |
|
|
#define TLS_TPREL 4 /* TPREL reloc, => IE. */
|
2646 |
|
|
#define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
|
2647 |
|
|
#define TLS_TLS 16 /* Any TLS reloc. */
|
2648 |
|
|
#define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
|
2649 |
|
|
char tls_mask;
|
2650 |
|
|
|
2651 |
|
|
/* Nonzero if we have seen a small data relocation referring to this
|
2652 |
|
|
symbol. */
|
2653 |
|
|
unsigned char has_sda_refs;
|
2654 |
|
|
};
|
2655 |
|
|
|
2656 |
|
|
#define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
|
2657 |
|
|
|
2658 |
|
|
/* PPC ELF linker hash table. */
|
2659 |
|
|
|
2660 |
|
|
struct ppc_elf_link_hash_table
|
2661 |
|
|
{
|
2662 |
|
|
struct elf_link_hash_table elf;
|
2663 |
|
|
|
2664 |
|
|
/* Short-cuts to get to dynamic linker sections. */
|
2665 |
|
|
asection *got;
|
2666 |
|
|
asection *relgot;
|
2667 |
|
|
asection *glink;
|
2668 |
|
|
asection *plt;
|
2669 |
|
|
asection *relplt;
|
2670 |
|
|
asection *dynbss;
|
2671 |
|
|
asection *relbss;
|
2672 |
|
|
asection *dynsbss;
|
2673 |
|
|
asection *relsbss;
|
2674 |
|
|
elf_linker_section_t sdata[2];
|
2675 |
|
|
asection *sbss;
|
2676 |
|
|
|
2677 |
|
|
/* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
|
2678 |
|
|
asection *srelplt2;
|
2679 |
|
|
|
2680 |
|
|
/* The .got.plt section (VxWorks only)*/
|
2681 |
|
|
asection *sgotplt;
|
2682 |
|
|
|
2683 |
|
|
/* Shortcut to __tls_get_addr. */
|
2684 |
|
|
struct elf_link_hash_entry *tls_get_addr;
|
2685 |
|
|
|
2686 |
|
|
/* The bfd that forced an old-style PLT. */
|
2687 |
|
|
bfd *old_bfd;
|
2688 |
|
|
|
2689 |
|
|
/* TLS local dynamic got entry handling. */
|
2690 |
|
|
union {
|
2691 |
|
|
bfd_signed_vma refcount;
|
2692 |
|
|
bfd_vma offset;
|
2693 |
|
|
} tlsld_got;
|
2694 |
|
|
|
2695 |
|
|
/* Offset of PltResolve function in glink. */
|
2696 |
|
|
bfd_vma glink_pltresolve;
|
2697 |
|
|
|
2698 |
|
|
/* Size of reserved GOT entries. */
|
2699 |
|
|
unsigned int got_header_size;
|
2700 |
|
|
/* Non-zero if allocating the header left a gap. */
|
2701 |
|
|
unsigned int got_gap;
|
2702 |
|
|
|
2703 |
|
|
/* The type of PLT we have chosen to use. */
|
2704 |
|
|
enum ppc_elf_plt_type plt_type;
|
2705 |
|
|
|
2706 |
|
|
/* Set if we should emit symbols for stubs. */
|
2707 |
|
|
unsigned int emit_stub_syms:1;
|
2708 |
|
|
|
2709 |
|
|
/* True if the target system is VxWorks. */
|
2710 |
|
|
unsigned int is_vxworks:1;
|
2711 |
|
|
|
2712 |
|
|
/* The size of PLT entries. */
|
2713 |
|
|
int plt_entry_size;
|
2714 |
|
|
/* The distance between adjacent PLT slots. */
|
2715 |
|
|
int plt_slot_size;
|
2716 |
|
|
/* The size of the first PLT entry. */
|
2717 |
|
|
int plt_initial_entry_size;
|
2718 |
|
|
|
2719 |
|
|
/* Small local sym to section mapping cache. */
|
2720 |
|
|
struct sym_sec_cache sym_sec;
|
2721 |
|
|
};
|
2722 |
|
|
|
2723 |
|
|
/* Get the PPC ELF linker hash table from a link_info structure. */
|
2724 |
|
|
|
2725 |
|
|
#define ppc_elf_hash_table(p) \
|
2726 |
|
|
((struct ppc_elf_link_hash_table *) (p)->hash)
|
2727 |
|
|
|
2728 |
|
|
/* Create an entry in a PPC ELF linker hash table. */
|
2729 |
|
|
|
2730 |
|
|
static struct bfd_hash_entry *
|
2731 |
|
|
ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
|
2732 |
|
|
struct bfd_hash_table *table,
|
2733 |
|
|
const char *string)
|
2734 |
|
|
{
|
2735 |
|
|
/* Allocate the structure if it has not already been allocated by a
|
2736 |
|
|
subclass. */
|
2737 |
|
|
if (entry == NULL)
|
2738 |
|
|
{
|
2739 |
|
|
entry = bfd_hash_allocate (table,
|
2740 |
|
|
sizeof (struct ppc_elf_link_hash_entry));
|
2741 |
|
|
if (entry == NULL)
|
2742 |
|
|
return entry;
|
2743 |
|
|
}
|
2744 |
|
|
|
2745 |
|
|
/* Call the allocation method of the superclass. */
|
2746 |
|
|
entry = _bfd_elf_link_hash_newfunc (entry, table, string);
|
2747 |
|
|
if (entry != NULL)
|
2748 |
|
|
{
|
2749 |
|
|
ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
|
2750 |
|
|
ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
|
2751 |
|
|
ppc_elf_hash_entry (entry)->tls_mask = 0;
|
2752 |
|
|
}
|
2753 |
|
|
|
2754 |
|
|
return entry;
|
2755 |
|
|
}
|
2756 |
|
|
|
2757 |
|
|
/* Create a PPC ELF linker hash table. */
|
2758 |
|
|
|
2759 |
|
|
static struct bfd_link_hash_table *
|
2760 |
|
|
ppc_elf_link_hash_table_create (bfd *abfd)
|
2761 |
|
|
{
|
2762 |
|
|
struct ppc_elf_link_hash_table *ret;
|
2763 |
|
|
|
2764 |
|
|
ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
|
2765 |
|
|
if (ret == NULL)
|
2766 |
|
|
return NULL;
|
2767 |
|
|
|
2768 |
|
|
if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
|
2769 |
|
|
ppc_elf_link_hash_newfunc,
|
2770 |
|
|
sizeof (struct ppc_elf_link_hash_entry)))
|
2771 |
|
|
{
|
2772 |
|
|
free (ret);
|
2773 |
|
|
return NULL;
|
2774 |
|
|
}
|
2775 |
|
|
|
2776 |
|
|
ret->elf.init_plt_refcount.refcount = 0;
|
2777 |
|
|
ret->elf.init_plt_refcount.glist = NULL;
|
2778 |
|
|
ret->elf.init_plt_offset.offset = 0;
|
2779 |
|
|
ret->elf.init_plt_offset.glist = NULL;
|
2780 |
|
|
|
2781 |
|
|
ret->sdata[0].name = ".sdata";
|
2782 |
|
|
ret->sdata[0].sym_name = "_SDA_BASE_";
|
2783 |
|
|
ret->sdata[0].bss_name = ".sbss";
|
2784 |
|
|
|
2785 |
|
|
ret->sdata[1].name = ".sdata2";
|
2786 |
|
|
ret->sdata[1].sym_name = "_SDA2_BASE_";
|
2787 |
|
|
ret->sdata[1].bss_name = ".sbss2";
|
2788 |
|
|
|
2789 |
|
|
ret->plt_entry_size = 12;
|
2790 |
|
|
ret->plt_slot_size = 8;
|
2791 |
|
|
ret->plt_initial_entry_size = 72;
|
2792 |
|
|
|
2793 |
|
|
return &ret->elf.root;
|
2794 |
|
|
}
|
2795 |
|
|
|
2796 |
|
|
/* Create .got and the related sections. */
|
2797 |
|
|
|
2798 |
|
|
static bfd_boolean
|
2799 |
|
|
ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
|
2800 |
|
|
{
|
2801 |
|
|
struct ppc_elf_link_hash_table *htab;
|
2802 |
|
|
asection *s;
|
2803 |
|
|
flagword flags;
|
2804 |
|
|
|
2805 |
|
|
if (!_bfd_elf_create_got_section (abfd, info))
|
2806 |
|
|
return FALSE;
|
2807 |
|
|
|
2808 |
|
|
htab = ppc_elf_hash_table (info);
|
2809 |
|
|
htab->got = s = bfd_get_section_by_name (abfd, ".got");
|
2810 |
|
|
if (s == NULL)
|
2811 |
|
|
abort ();
|
2812 |
|
|
|
2813 |
|
|
if (htab->is_vxworks)
|
2814 |
|
|
{
|
2815 |
|
|
htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt");
|
2816 |
|
|
if (!htab->sgotplt)
|
2817 |
|
|
abort ();
|
2818 |
|
|
}
|
2819 |
|
|
else
|
2820 |
|
|
{
|
2821 |
|
|
/* The powerpc .got has a blrl instruction in it. Mark it
|
2822 |
|
|
executable. */
|
2823 |
|
|
flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
|
2824 |
|
|
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
2825 |
|
|
if (!bfd_set_section_flags (abfd, s, flags))
|
2826 |
|
|
return FALSE;
|
2827 |
|
|
}
|
2828 |
|
|
|
2829 |
|
|
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
|
2830 |
|
|
| SEC_LINKER_CREATED | SEC_READONLY);
|
2831 |
|
|
htab->relgot = bfd_make_section_with_flags (abfd, ".rela.got", flags);
|
2832 |
|
|
if (!htab->relgot
|
2833 |
|
|
|| ! bfd_set_section_alignment (abfd, htab->relgot, 2))
|
2834 |
|
|
return FALSE;
|
2835 |
|
|
|
2836 |
|
|
return TRUE;
|
2837 |
|
|
}
|
2838 |
|
|
|
2839 |
|
|
/* We have to create .dynsbss and .rela.sbss here so that they get mapped
|
2840 |
|
|
to output sections (just like _bfd_elf_create_dynamic_sections has
|
2841 |
|
|
to create .dynbss and .rela.bss). */
|
2842 |
|
|
|
2843 |
|
|
static bfd_boolean
|
2844 |
|
|
ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
|
2845 |
|
|
{
|
2846 |
|
|
struct ppc_elf_link_hash_table *htab;
|
2847 |
|
|
asection *s;
|
2848 |
|
|
flagword flags;
|
2849 |
|
|
|
2850 |
|
|
htab = ppc_elf_hash_table (info);
|
2851 |
|
|
|
2852 |
|
|
if (htab->got == NULL
|
2853 |
|
|
&& !ppc_elf_create_got (abfd, info))
|
2854 |
|
|
return FALSE;
|
2855 |
|
|
|
2856 |
|
|
if (!_bfd_elf_create_dynamic_sections (abfd, info))
|
2857 |
|
|
return FALSE;
|
2858 |
|
|
|
2859 |
|
|
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
|
2860 |
|
|
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
2861 |
|
|
|
2862 |
|
|
s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags | SEC_CODE);
|
2863 |
|
|
htab->glink = s;
|
2864 |
|
|
if (s == NULL
|
2865 |
|
|
|| !bfd_set_section_alignment (abfd, s, 4))
|
2866 |
|
|
return FALSE;
|
2867 |
|
|
|
2868 |
|
|
htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
|
2869 |
|
|
s = bfd_make_section_with_flags (abfd, ".dynsbss",
|
2870 |
|
|
SEC_ALLOC | SEC_LINKER_CREATED);
|
2871 |
|
|
htab->dynsbss = s;
|
2872 |
|
|
if (s == NULL)
|
2873 |
|
|
return FALSE;
|
2874 |
|
|
|
2875 |
|
|
if (! info->shared)
|
2876 |
|
|
{
|
2877 |
|
|
htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
|
2878 |
|
|
s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags);
|
2879 |
|
|
htab->relsbss = s;
|
2880 |
|
|
if (s == NULL
|
2881 |
|
|
|| ! bfd_set_section_alignment (abfd, s, 2))
|
2882 |
|
|
return FALSE;
|
2883 |
|
|
}
|
2884 |
|
|
|
2885 |
|
|
if (htab->is_vxworks
|
2886 |
|
|
&& !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
|
2887 |
|
|
return FALSE;
|
2888 |
|
|
|
2889 |
|
|
htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
|
2890 |
|
|
htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
|
2891 |
|
|
if (s == NULL)
|
2892 |
|
|
abort ();
|
2893 |
|
|
|
2894 |
|
|
flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
|
2895 |
|
|
if (htab->plt_type == PLT_VXWORKS)
|
2896 |
|
|
/* The VxWorks PLT is a loaded section with contents. */
|
2897 |
|
|
flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
|
2898 |
|
|
return bfd_set_section_flags (abfd, s, flags);
|
2899 |
|
|
}
|
2900 |
|
|
|
2901 |
|
|
/* Copy the extra info we tack onto an elf_link_hash_entry. */
|
2902 |
|
|
|
2903 |
|
|
static void
|
2904 |
|
|
ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
|
2905 |
|
|
struct elf_link_hash_entry *dir,
|
2906 |
|
|
struct elf_link_hash_entry *ind)
|
2907 |
|
|
{
|
2908 |
|
|
struct ppc_elf_link_hash_entry *edir, *eind;
|
2909 |
|
|
|
2910 |
|
|
edir = (struct ppc_elf_link_hash_entry *) dir;
|
2911 |
|
|
eind = (struct ppc_elf_link_hash_entry *) ind;
|
2912 |
|
|
|
2913 |
|
|
if (eind->dyn_relocs != NULL)
|
2914 |
|
|
{
|
2915 |
|
|
if (edir->dyn_relocs != NULL)
|
2916 |
|
|
{
|
2917 |
|
|
struct ppc_elf_dyn_relocs **pp;
|
2918 |
|
|
struct ppc_elf_dyn_relocs *p;
|
2919 |
|
|
|
2920 |
|
|
/* Add reloc counts against the indirect sym to the direct sym
|
2921 |
|
|
list. Merge any entries against the same section. */
|
2922 |
|
|
for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
|
2923 |
|
|
{
|
2924 |
|
|
struct ppc_elf_dyn_relocs *q;
|
2925 |
|
|
|
2926 |
|
|
for (q = edir->dyn_relocs; q != NULL; q = q->next)
|
2927 |
|
|
if (q->sec == p->sec)
|
2928 |
|
|
{
|
2929 |
|
|
q->pc_count += p->pc_count;
|
2930 |
|
|
q->count += p->count;
|
2931 |
|
|
*pp = p->next;
|
2932 |
|
|
break;
|
2933 |
|
|
}
|
2934 |
|
|
if (q == NULL)
|
2935 |
|
|
pp = &p->next;
|
2936 |
|
|
}
|
2937 |
|
|
*pp = edir->dyn_relocs;
|
2938 |
|
|
}
|
2939 |
|
|
|
2940 |
|
|
edir->dyn_relocs = eind->dyn_relocs;
|
2941 |
|
|
eind->dyn_relocs = NULL;
|
2942 |
|
|
}
|
2943 |
|
|
|
2944 |
|
|
edir->tls_mask |= eind->tls_mask;
|
2945 |
|
|
edir->has_sda_refs |= eind->has_sda_refs;
|
2946 |
|
|
|
2947 |
|
|
/* If called to transfer flags for a weakdef during processing
|
2948 |
|
|
of elf_adjust_dynamic_symbol, don't copy non_got_ref.
|
2949 |
|
|
We clear it ourselves for ELIMINATE_COPY_RELOCS. */
|
2950 |
|
|
if (!(ELIMINATE_COPY_RELOCS
|
2951 |
|
|
&& eind->elf.root.type != bfd_link_hash_indirect
|
2952 |
|
|
&& edir->elf.dynamic_adjusted))
|
2953 |
|
|
edir->elf.non_got_ref |= eind->elf.non_got_ref;
|
2954 |
|
|
|
2955 |
|
|
edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
|
2956 |
|
|
edir->elf.ref_regular |= eind->elf.ref_regular;
|
2957 |
|
|
edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
|
2958 |
|
|
edir->elf.needs_plt |= eind->elf.needs_plt;
|
2959 |
|
|
edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
|
2960 |
|
|
|
2961 |
|
|
/* If we were called to copy over info for a weak sym, that's all. */
|
2962 |
|
|
if (eind->elf.root.type != bfd_link_hash_indirect)
|
2963 |
|
|
return;
|
2964 |
|
|
|
2965 |
|
|
/* Copy over the GOT refcount entries that we may have already seen to
|
2966 |
|
|
the symbol which just became indirect. */
|
2967 |
|
|
edir->elf.got.refcount += eind->elf.got.refcount;
|
2968 |
|
|
eind->elf.got.refcount = 0;
|
2969 |
|
|
|
2970 |
|
|
/* And plt entries. */
|
2971 |
|
|
if (eind->elf.plt.plist != NULL)
|
2972 |
|
|
{
|
2973 |
|
|
if (edir->elf.plt.plist != NULL)
|
2974 |
|
|
{
|
2975 |
|
|
struct plt_entry **entp;
|
2976 |
|
|
struct plt_entry *ent;
|
2977 |
|
|
|
2978 |
|
|
for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
|
2979 |
|
|
{
|
2980 |
|
|
struct plt_entry *dent;
|
2981 |
|
|
|
2982 |
|
|
for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
|
2983 |
|
|
if (dent->sec == ent->sec && dent->addend == ent->addend)
|
2984 |
|
|
{
|
2985 |
|
|
dent->plt.refcount += ent->plt.refcount;
|
2986 |
|
|
*entp = ent->next;
|
2987 |
|
|
break;
|
2988 |
|
|
}
|
2989 |
|
|
if (dent == NULL)
|
2990 |
|
|
entp = &ent->next;
|
2991 |
|
|
}
|
2992 |
|
|
*entp = edir->elf.plt.plist;
|
2993 |
|
|
}
|
2994 |
|
|
|
2995 |
|
|
edir->elf.plt.plist = eind->elf.plt.plist;
|
2996 |
|
|
eind->elf.plt.plist = NULL;
|
2997 |
|
|
}
|
2998 |
|
|
|
2999 |
|
|
if (eind->elf.dynindx != -1)
|
3000 |
|
|
{
|
3001 |
|
|
if (edir->elf.dynindx != -1)
|
3002 |
|
|
_bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
|
3003 |
|
|
edir->elf.dynstr_index);
|
3004 |
|
|
edir->elf.dynindx = eind->elf.dynindx;
|
3005 |
|
|
edir->elf.dynstr_index = eind->elf.dynstr_index;
|
3006 |
|
|
eind->elf.dynindx = -1;
|
3007 |
|
|
eind->elf.dynstr_index = 0;
|
3008 |
|
|
}
|
3009 |
|
|
}
|
3010 |
|
|
|
3011 |
|
|
/* Hook called by the linker routine which adds symbols from an object
|
3012 |
|
|
file. We use it to put .comm items in .sbss, and not .bss. */
|
3013 |
|
|
|
3014 |
|
|
static bfd_boolean
|
3015 |
|
|
ppc_elf_add_symbol_hook (bfd *abfd,
|
3016 |
|
|
struct bfd_link_info *info,
|
3017 |
|
|
Elf_Internal_Sym *sym,
|
3018 |
|
|
const char **namep ATTRIBUTE_UNUSED,
|
3019 |
|
|
flagword *flagsp ATTRIBUTE_UNUSED,
|
3020 |
|
|
asection **secp,
|
3021 |
|
|
bfd_vma *valp)
|
3022 |
|
|
{
|
3023 |
|
|
if (sym->st_shndx == SHN_COMMON
|
3024 |
|
|
&& !info->relocatable
|
3025 |
|
|
&& is_ppc_elf (info->output_bfd)
|
3026 |
|
|
&& sym->st_size <= elf_gp_size (abfd))
|
3027 |
|
|
{
|
3028 |
|
|
/* Common symbols less than or equal to -G nn bytes are automatically
|
3029 |
|
|
put into .sbss. */
|
3030 |
|
|
struct ppc_elf_link_hash_table *htab;
|
3031 |
|
|
|
3032 |
|
|
htab = ppc_elf_hash_table (info);
|
3033 |
|
|
if (htab->sbss == NULL)
|
3034 |
|
|
{
|
3035 |
|
|
flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
|
3036 |
|
|
|
3037 |
|
|
if (!htab->elf.dynobj)
|
3038 |
|
|
htab->elf.dynobj = abfd;
|
3039 |
|
|
|
3040 |
|
|
htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
|
3041 |
|
|
".sbss",
|
3042 |
|
|
flags);
|
3043 |
|
|
if (htab->sbss == NULL)
|
3044 |
|
|
return FALSE;
|
3045 |
|
|
}
|
3046 |
|
|
|
3047 |
|
|
*secp = htab->sbss;
|
3048 |
|
|
*valp = sym->st_size;
|
3049 |
|
|
}
|
3050 |
|
|
|
3051 |
|
|
return TRUE;
|
3052 |
|
|
}
|
3053 |
|
|
|
3054 |
|
|
static bfd_boolean
|
3055 |
|
|
create_sdata_sym (struct ppc_elf_link_hash_table *htab,
|
3056 |
|
|
elf_linker_section_t *lsect)
|
3057 |
|
|
{
|
3058 |
|
|
lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
|
3059 |
|
|
TRUE, FALSE, TRUE);
|
3060 |
|
|
if (lsect->sym == NULL)
|
3061 |
|
|
return FALSE;
|
3062 |
|
|
if (lsect->sym->root.type == bfd_link_hash_new)
|
3063 |
|
|
lsect->sym->non_elf = 0;
|
3064 |
|
|
lsect->sym->ref_regular = 1;
|
3065 |
|
|
return TRUE;
|
3066 |
|
|
}
|
3067 |
|
|
|
3068 |
|
|
/* Create a special linker section. */
|
3069 |
|
|
|
3070 |
|
|
static bfd_boolean
|
3071 |
|
|
ppc_elf_create_linker_section (bfd *abfd,
|
3072 |
|
|
struct bfd_link_info *info,
|
3073 |
|
|
flagword flags,
|
3074 |
|
|
elf_linker_section_t *lsect)
|
3075 |
|
|
{
|
3076 |
|
|
struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
|
3077 |
|
|
asection *s;
|
3078 |
|
|
|
3079 |
|
|
flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
|
3080 |
|
|
| SEC_LINKER_CREATED);
|
3081 |
|
|
|
3082 |
|
|
/* Record the first bfd that needs the special sections. */
|
3083 |
|
|
if (!htab->elf.dynobj)
|
3084 |
|
|
htab->elf.dynobj = abfd;
|
3085 |
|
|
|
3086 |
|
|
s = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
|
3087 |
|
|
lsect->name,
|
3088 |
|
|
flags);
|
3089 |
|
|
if (s == NULL
|
3090 |
|
|
|| !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
|
3091 |
|
|
return FALSE;
|
3092 |
|
|
lsect->section = s;
|
3093 |
|
|
|
3094 |
|
|
return create_sdata_sym (htab, lsect);
|
3095 |
|
|
}
|
3096 |
|
|
|
3097 |
|
|
/* Find a linker generated pointer with a given addend and type. */
|
3098 |
|
|
|
3099 |
|
|
static elf_linker_section_pointers_t *
|
3100 |
|
|
elf_find_pointer_linker_section
|
3101 |
|
|
(elf_linker_section_pointers_t *linker_pointers,
|
3102 |
|
|
bfd_vma addend,
|
3103 |
|
|
elf_linker_section_t *lsect)
|
3104 |
|
|
{
|
3105 |
|
|
for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
|
3106 |
|
|
if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
|
3107 |
|
|
return linker_pointers;
|
3108 |
|
|
|
3109 |
|
|
return NULL;
|
3110 |
|
|
}
|
3111 |
|
|
|
3112 |
|
|
/* Allocate a pointer to live in a linker created section. */
|
3113 |
|
|
|
3114 |
|
|
static bfd_boolean
|
3115 |
|
|
elf_create_pointer_linker_section (bfd *abfd,
|
3116 |
|
|
elf_linker_section_t *lsect,
|
3117 |
|
|
struct elf_link_hash_entry *h,
|
3118 |
|
|
const Elf_Internal_Rela *rel)
|
3119 |
|
|
{
|
3120 |
|
|
elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
|
3121 |
|
|
elf_linker_section_pointers_t *linker_section_ptr;
|
3122 |
|
|
unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
|
3123 |
|
|
bfd_size_type amt;
|
3124 |
|
|
|
3125 |
|
|
BFD_ASSERT (lsect != NULL);
|
3126 |
|
|
|
3127 |
|
|
/* Is this a global symbol? */
|
3128 |
|
|
if (h != NULL)
|
3129 |
|
|
{
|
3130 |
|
|
struct ppc_elf_link_hash_entry *eh;
|
3131 |
|
|
|
3132 |
|
|
/* Has this symbol already been allocated? If so, our work is done. */
|
3133 |
|
|
eh = (struct ppc_elf_link_hash_entry *) h;
|
3134 |
|
|
if (elf_find_pointer_linker_section (eh->linker_section_pointer,
|
3135 |
|
|
rel->r_addend,
|
3136 |
|
|
lsect))
|
3137 |
|
|
return TRUE;
|
3138 |
|
|
|
3139 |
|
|
ptr_linker_section_ptr = &eh->linker_section_pointer;
|
3140 |
|
|
}
|
3141 |
|
|
else
|
3142 |
|
|
{
|
3143 |
|
|
BFD_ASSERT (is_ppc_elf (abfd));
|
3144 |
|
|
|
3145 |
|
|
/* Allocation of a pointer to a local symbol. */
|
3146 |
|
|
elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
|
3147 |
|
|
|
3148 |
|
|
/* Allocate a table to hold the local symbols if first time. */
|
3149 |
|
|
if (!ptr)
|
3150 |
|
|
{
|
3151 |
|
|
unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info;
|
3152 |
|
|
|
3153 |
|
|
amt = num_symbols;
|
3154 |
|
|
amt *= sizeof (elf_linker_section_pointers_t *);
|
3155 |
|
|
ptr = bfd_zalloc (abfd, amt);
|
3156 |
|
|
|
3157 |
|
|
if (!ptr)
|
3158 |
|
|
return FALSE;
|
3159 |
|
|
|
3160 |
|
|
elf_local_ptr_offsets (abfd) = ptr;
|
3161 |
|
|
}
|
3162 |
|
|
|
3163 |
|
|
/* Has this symbol already been allocated? If so, our work is done. */
|
3164 |
|
|
if (elf_find_pointer_linker_section (ptr[r_symndx],
|
3165 |
|
|
rel->r_addend,
|
3166 |
|
|
lsect))
|
3167 |
|
|
return TRUE;
|
3168 |
|
|
|
3169 |
|
|
ptr_linker_section_ptr = &ptr[r_symndx];
|
3170 |
|
|
}
|
3171 |
|
|
|
3172 |
|
|
/* Allocate space for a pointer in the linker section, and allocate
|
3173 |
|
|
a new pointer record from internal memory. */
|
3174 |
|
|
BFD_ASSERT (ptr_linker_section_ptr != NULL);
|
3175 |
|
|
amt = sizeof (elf_linker_section_pointers_t);
|
3176 |
|
|
linker_section_ptr = bfd_alloc (abfd, amt);
|
3177 |
|
|
|
3178 |
|
|
if (!linker_section_ptr)
|
3179 |
|
|
return FALSE;
|
3180 |
|
|
|
3181 |
|
|
linker_section_ptr->next = *ptr_linker_section_ptr;
|
3182 |
|
|
linker_section_ptr->addend = rel->r_addend;
|
3183 |
|
|
linker_section_ptr->lsect = lsect;
|
3184 |
|
|
*ptr_linker_section_ptr = linker_section_ptr;
|
3185 |
|
|
|
3186 |
|
|
linker_section_ptr->offset = lsect->section->size;
|
3187 |
|
|
lsect->section->size += 4;
|
3188 |
|
|
|
3189 |
|
|
#ifdef DEBUG
|
3190 |
|
|
fprintf (stderr,
|
3191 |
|
|
"Create pointer in linker section %s, offset = %ld, section size = %ld\n",
|
3192 |
|
|
lsect->name, (long) linker_section_ptr->offset,
|
3193 |
|
|
(long) lsect->section->size);
|
3194 |
|
|
#endif
|
3195 |
|
|
|
3196 |
|
|
return TRUE;
|
3197 |
|
|
}
|
3198 |
|
|
|
3199 |
|
|
static bfd_boolean
|
3200 |
|
|
update_local_sym_info (bfd *abfd,
|
3201 |
|
|
Elf_Internal_Shdr *symtab_hdr,
|
3202 |
|
|
unsigned long r_symndx,
|
3203 |
|
|
int tls_type)
|
3204 |
|
|
{
|
3205 |
|
|
bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
|
3206 |
|
|
char *local_got_tls_masks;
|
3207 |
|
|
|
3208 |
|
|
if (local_got_refcounts == NULL)
|
3209 |
|
|
{
|
3210 |
|
|
bfd_size_type size = symtab_hdr->sh_info;
|
3211 |
|
|
|
3212 |
|
|
size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
|
3213 |
|
|
local_got_refcounts = bfd_zalloc (abfd, size);
|
3214 |
|
|
if (local_got_refcounts == NULL)
|
3215 |
|
|
return FALSE;
|
3216 |
|
|
elf_local_got_refcounts (abfd) = local_got_refcounts;
|
3217 |
|
|
}
|
3218 |
|
|
|
3219 |
|
|
local_got_refcounts[r_symndx] += 1;
|
3220 |
|
|
local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
|
3221 |
|
|
local_got_tls_masks[r_symndx] |= tls_type;
|
3222 |
|
|
return TRUE;
|
3223 |
|
|
}
|
3224 |
|
|
|
3225 |
|
|
static bfd_boolean
|
3226 |
|
|
update_plt_info (bfd *abfd, struct elf_link_hash_entry *h,
|
3227 |
|
|
asection *sec, bfd_vma addend)
|
3228 |
|
|
{
|
3229 |
|
|
struct plt_entry *ent;
|
3230 |
|
|
|
3231 |
|
|
if (addend < 32768)
|
3232 |
|
|
sec = NULL;
|
3233 |
|
|
for (ent = h->plt.plist; ent != NULL; ent = ent->next)
|
3234 |
|
|
if (ent->sec == sec && ent->addend == addend)
|
3235 |
|
|
break;
|
3236 |
|
|
if (ent == NULL)
|
3237 |
|
|
{
|
3238 |
|
|
bfd_size_type amt = sizeof (*ent);
|
3239 |
|
|
ent = bfd_alloc (abfd, amt);
|
3240 |
|
|
if (ent == NULL)
|
3241 |
|
|
return FALSE;
|
3242 |
|
|
ent->next = h->plt.plist;
|
3243 |
|
|
ent->sec = sec;
|
3244 |
|
|
ent->addend = addend;
|
3245 |
|
|
ent->plt.refcount = 0;
|
3246 |
|
|
h->plt.plist = ent;
|
3247 |
|
|
}
|
3248 |
|
|
ent->plt.refcount += 1;
|
3249 |
|
|
return TRUE;
|
3250 |
|
|
}
|
3251 |
|
|
|
3252 |
|
|
static struct plt_entry *
|
3253 |
|
|
find_plt_ent (struct elf_link_hash_entry *h, asection *sec, bfd_vma addend)
|
3254 |
|
|
{
|
3255 |
|
|
struct plt_entry *ent;
|
3256 |
|
|
|
3257 |
|
|
if (addend < 32768)
|
3258 |
|
|
sec = NULL;
|
3259 |
|
|
for (ent = h->plt.plist; ent != NULL; ent = ent->next)
|
3260 |
|
|
if (ent->sec == sec && ent->addend == addend)
|
3261 |
|
|
break;
|
3262 |
|
|
return ent;
|
3263 |
|
|
}
|
3264 |
|
|
|
3265 |
|
|
static void
|
3266 |
|
|
bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
|
3267 |
|
|
{
|
3268 |
|
|
(*_bfd_error_handler)
|
3269 |
|
|
(_("%B: relocation %s cannot be used when making a shared object"),
|
3270 |
|
|
abfd,
|
3271 |
|
|
ppc_elf_howto_table[r_type]->name);
|
3272 |
|
|
bfd_set_error (bfd_error_bad_value);
|
3273 |
|
|
}
|
3274 |
|
|
|
3275 |
|
|
/* Look through the relocs for a section during the first phase, and
|
3276 |
|
|
allocate space in the global offset table or procedure linkage
|
3277 |
|
|
table. */
|
3278 |
|
|
|
3279 |
|
|
static bfd_boolean
|
3280 |
|
|
ppc_elf_check_relocs (bfd *abfd,
|
3281 |
|
|
struct bfd_link_info *info,
|
3282 |
|
|
asection *sec,
|
3283 |
|
|
const Elf_Internal_Rela *relocs)
|
3284 |
|
|
{
|
3285 |
|
|
struct ppc_elf_link_hash_table *htab;
|
3286 |
|
|
Elf_Internal_Shdr *symtab_hdr;
|
3287 |
|
|
struct elf_link_hash_entry **sym_hashes;
|
3288 |
|
|
const Elf_Internal_Rela *rel;
|
3289 |
|
|
const Elf_Internal_Rela *rel_end;
|
3290 |
|
|
asection *got2, *sreloc;
|
3291 |
|
|
|
3292 |
|
|
if (info->relocatable)
|
3293 |
|
|
return TRUE;
|
3294 |
|
|
|
3295 |
|
|
/* Don't do anything special with non-loaded, non-alloced sections.
|
3296 |
|
|
In particular, any relocs in such sections should not affect GOT
|
3297 |
|
|
and PLT reference counting (ie. we don't allow them to create GOT
|
3298 |
|
|
or PLT entries), there's no possibility or desire to optimize TLS
|
3299 |
|
|
relocs, and there's not much point in propagating relocs to shared
|
3300 |
|
|
libs that the dynamic linker won't relocate. */
|
3301 |
|
|
if ((sec->flags & SEC_ALLOC) == 0)
|
3302 |
|
|
return TRUE;
|
3303 |
|
|
|
3304 |
|
|
#ifdef DEBUG
|
3305 |
|
|
_bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
|
3306 |
|
|
sec, abfd);
|
3307 |
|
|
#endif
|
3308 |
|
|
|
3309 |
|
|
BFD_ASSERT (is_ppc_elf (abfd));
|
3310 |
|
|
|
3311 |
|
|
/* Initialize howto table if not already done. */
|
3312 |
|
|
if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
3313 |
|
|
ppc_elf_howto_init ();
|
3314 |
|
|
|
3315 |
|
|
htab = ppc_elf_hash_table (info);
|
3316 |
|
|
symtab_hdr = &elf_symtab_hdr (abfd);
|
3317 |
|
|
sym_hashes = elf_sym_hashes (abfd);
|
3318 |
|
|
got2 = bfd_get_section_by_name (abfd, ".got2");
|
3319 |
|
|
sreloc = NULL;
|
3320 |
|
|
|
3321 |
|
|
rel_end = relocs + sec->reloc_count;
|
3322 |
|
|
for (rel = relocs; rel < rel_end; rel++)
|
3323 |
|
|
{
|
3324 |
|
|
unsigned long r_symndx;
|
3325 |
|
|
enum elf_ppc_reloc_type r_type;
|
3326 |
|
|
struct elf_link_hash_entry *h;
|
3327 |
|
|
int tls_type = 0;
|
3328 |
|
|
|
3329 |
|
|
r_symndx = ELF32_R_SYM (rel->r_info);
|
3330 |
|
|
if (r_symndx < symtab_hdr->sh_info)
|
3331 |
|
|
h = NULL;
|
3332 |
|
|
else
|
3333 |
|
|
{
|
3334 |
|
|
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
3335 |
|
|
while (h->root.type == bfd_link_hash_indirect
|
3336 |
|
|
|| h->root.type == bfd_link_hash_warning)
|
3337 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
3338 |
|
|
}
|
3339 |
|
|
|
3340 |
|
|
/* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
|
3341 |
|
|
This shows up in particular in an R_PPC_ADDR32 in the eabi
|
3342 |
|
|
startup code. */
|
3343 |
|
|
if (h != NULL
|
3344 |
|
|
&& htab->got == NULL
|
3345 |
|
|
&& strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
|
3346 |
|
|
{
|
3347 |
|
|
if (htab->elf.dynobj == NULL)
|
3348 |
|
|
htab->elf.dynobj = abfd;
|
3349 |
|
|
if (!ppc_elf_create_got (htab->elf.dynobj, info))
|
3350 |
|
|
return FALSE;
|
3351 |
|
|
BFD_ASSERT (h == htab->elf.hgot);
|
3352 |
|
|
}
|
3353 |
|
|
|
3354 |
|
|
r_type = ELF32_R_TYPE (rel->r_info);
|
3355 |
|
|
switch (r_type)
|
3356 |
|
|
{
|
3357 |
|
|
case R_PPC_GOT_TLSLD16:
|
3358 |
|
|
case R_PPC_GOT_TLSLD16_LO:
|
3359 |
|
|
case R_PPC_GOT_TLSLD16_HI:
|
3360 |
|
|
case R_PPC_GOT_TLSLD16_HA:
|
3361 |
|
|
tls_type = TLS_TLS | TLS_LD;
|
3362 |
|
|
goto dogottls;
|
3363 |
|
|
|
3364 |
|
|
case R_PPC_GOT_TLSGD16:
|
3365 |
|
|
case R_PPC_GOT_TLSGD16_LO:
|
3366 |
|
|
case R_PPC_GOT_TLSGD16_HI:
|
3367 |
|
|
case R_PPC_GOT_TLSGD16_HA:
|
3368 |
|
|
tls_type = TLS_TLS | TLS_GD;
|
3369 |
|
|
goto dogottls;
|
3370 |
|
|
|
3371 |
|
|
case R_PPC_GOT_TPREL16:
|
3372 |
|
|
case R_PPC_GOT_TPREL16_LO:
|
3373 |
|
|
case R_PPC_GOT_TPREL16_HI:
|
3374 |
|
|
case R_PPC_GOT_TPREL16_HA:
|
3375 |
|
|
if (!info->executable)
|
3376 |
|
|
info->flags |= DF_STATIC_TLS;
|
3377 |
|
|
tls_type = TLS_TLS | TLS_TPREL;
|
3378 |
|
|
goto dogottls;
|
3379 |
|
|
|
3380 |
|
|
case R_PPC_GOT_DTPREL16:
|
3381 |
|
|
case R_PPC_GOT_DTPREL16_LO:
|
3382 |
|
|
case R_PPC_GOT_DTPREL16_HI:
|
3383 |
|
|
case R_PPC_GOT_DTPREL16_HA:
|
3384 |
|
|
tls_type = TLS_TLS | TLS_DTPREL;
|
3385 |
|
|
dogottls:
|
3386 |
|
|
sec->has_tls_reloc = 1;
|
3387 |
|
|
/* Fall thru */
|
3388 |
|
|
|
3389 |
|
|
/* GOT16 relocations */
|
3390 |
|
|
case R_PPC_GOT16:
|
3391 |
|
|
case R_PPC_GOT16_LO:
|
3392 |
|
|
case R_PPC_GOT16_HI:
|
3393 |
|
|
case R_PPC_GOT16_HA:
|
3394 |
|
|
/* This symbol requires a global offset table entry. */
|
3395 |
|
|
if (htab->got == NULL)
|
3396 |
|
|
{
|
3397 |
|
|
if (htab->elf.dynobj == NULL)
|
3398 |
|
|
htab->elf.dynobj = abfd;
|
3399 |
|
|
if (!ppc_elf_create_got (htab->elf.dynobj, info))
|
3400 |
|
|
return FALSE;
|
3401 |
|
|
}
|
3402 |
|
|
if (h != NULL)
|
3403 |
|
|
{
|
3404 |
|
|
h->got.refcount += 1;
|
3405 |
|
|
ppc_elf_hash_entry (h)->tls_mask |= tls_type;
|
3406 |
|
|
}
|
3407 |
|
|
else
|
3408 |
|
|
/* This is a global offset table entry for a local symbol. */
|
3409 |
|
|
if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
|
3410 |
|
|
return FALSE;
|
3411 |
|
|
break;
|
3412 |
|
|
|
3413 |
|
|
/* Indirect .sdata relocation. */
|
3414 |
|
|
case R_PPC_EMB_SDAI16:
|
3415 |
|
|
if (info->shared)
|
3416 |
|
|
{
|
3417 |
|
|
bad_shared_reloc (abfd, r_type);
|
3418 |
|
|
return FALSE;
|
3419 |
|
|
}
|
3420 |
|
|
if (htab->sdata[0].section == NULL
|
3421 |
|
|
&& !ppc_elf_create_linker_section (abfd, info, 0,
|
3422 |
|
|
&htab->sdata[0]))
|
3423 |
|
|
return FALSE;
|
3424 |
|
|
if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
|
3425 |
|
|
h, rel))
|
3426 |
|
|
return FALSE;
|
3427 |
|
|
if (h != NULL)
|
3428 |
|
|
{
|
3429 |
|
|
ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
|
3430 |
|
|
h->non_got_ref = TRUE;
|
3431 |
|
|
}
|
3432 |
|
|
break;
|
3433 |
|
|
|
3434 |
|
|
/* Indirect .sdata2 relocation. */
|
3435 |
|
|
case R_PPC_EMB_SDA2I16:
|
3436 |
|
|
if (info->shared)
|
3437 |
|
|
{
|
3438 |
|
|
bad_shared_reloc (abfd, r_type);
|
3439 |
|
|
return FALSE;
|
3440 |
|
|
}
|
3441 |
|
|
if (htab->sdata[1].section == NULL
|
3442 |
|
|
&& !ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
|
3443 |
|
|
&htab->sdata[1]))
|
3444 |
|
|
return FALSE;
|
3445 |
|
|
if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
|
3446 |
|
|
h, rel))
|
3447 |
|
|
return FALSE;
|
3448 |
|
|
if (h != NULL)
|
3449 |
|
|
{
|
3450 |
|
|
ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
|
3451 |
|
|
h->non_got_ref = TRUE;
|
3452 |
|
|
}
|
3453 |
|
|
break;
|
3454 |
|
|
|
3455 |
|
|
case R_PPC_SDAREL16:
|
3456 |
|
|
if (info->shared)
|
3457 |
|
|
{
|
3458 |
|
|
bad_shared_reloc (abfd, r_type);
|
3459 |
|
|
return FALSE;
|
3460 |
|
|
}
|
3461 |
|
|
if (htab->sdata[0].sym == NULL
|
3462 |
|
|
&& !create_sdata_sym (htab, &htab->sdata[0]))
|
3463 |
|
|
return FALSE;
|
3464 |
|
|
if (h != NULL)
|
3465 |
|
|
{
|
3466 |
|
|
ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
|
3467 |
|
|
h->non_got_ref = TRUE;
|
3468 |
|
|
}
|
3469 |
|
|
break;
|
3470 |
|
|
|
3471 |
|
|
case R_PPC_EMB_SDA2REL:
|
3472 |
|
|
if (info->shared)
|
3473 |
|
|
{
|
3474 |
|
|
bad_shared_reloc (abfd, r_type);
|
3475 |
|
|
return FALSE;
|
3476 |
|
|
}
|
3477 |
|
|
if (htab->sdata[1].sym == NULL
|
3478 |
|
|
&& !create_sdata_sym (htab, &htab->sdata[1]))
|
3479 |
|
|
return FALSE;
|
3480 |
|
|
if (h != NULL)
|
3481 |
|
|
{
|
3482 |
|
|
ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
|
3483 |
|
|
h->non_got_ref = TRUE;
|
3484 |
|
|
}
|
3485 |
|
|
break;
|
3486 |
|
|
|
3487 |
|
|
case R_PPC_EMB_SDA21:
|
3488 |
|
|
case R_PPC_EMB_RELSDA:
|
3489 |
|
|
if (info->shared)
|
3490 |
|
|
{
|
3491 |
|
|
bad_shared_reloc (abfd, r_type);
|
3492 |
|
|
return FALSE;
|
3493 |
|
|
}
|
3494 |
|
|
if (htab->sdata[0].sym == NULL
|
3495 |
|
|
&& !create_sdata_sym (htab, &htab->sdata[0]))
|
3496 |
|
|
return FALSE;
|
3497 |
|
|
if (htab->sdata[1].sym == NULL
|
3498 |
|
|
&& !create_sdata_sym (htab, &htab->sdata[1]))
|
3499 |
|
|
return FALSE;
|
3500 |
|
|
if (h != NULL)
|
3501 |
|
|
{
|
3502 |
|
|
ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
|
3503 |
|
|
h->non_got_ref = TRUE;
|
3504 |
|
|
}
|
3505 |
|
|
break;
|
3506 |
|
|
|
3507 |
|
|
case R_PPC_EMB_NADDR32:
|
3508 |
|
|
case R_PPC_EMB_NADDR16:
|
3509 |
|
|
case R_PPC_EMB_NADDR16_LO:
|
3510 |
|
|
case R_PPC_EMB_NADDR16_HI:
|
3511 |
|
|
case R_PPC_EMB_NADDR16_HA:
|
3512 |
|
|
if (info->shared)
|
3513 |
|
|
{
|
3514 |
|
|
bad_shared_reloc (abfd, r_type);
|
3515 |
|
|
return FALSE;
|
3516 |
|
|
}
|
3517 |
|
|
if (h != NULL)
|
3518 |
|
|
h->non_got_ref = TRUE;
|
3519 |
|
|
break;
|
3520 |
|
|
|
3521 |
|
|
case R_PPC_PLT32:
|
3522 |
|
|
case R_PPC_PLTREL24:
|
3523 |
|
|
case R_PPC_PLTREL32:
|
3524 |
|
|
case R_PPC_PLT16_LO:
|
3525 |
|
|
case R_PPC_PLT16_HI:
|
3526 |
|
|
case R_PPC_PLT16_HA:
|
3527 |
|
|
#ifdef DEBUG
|
3528 |
|
|
fprintf (stderr, "Reloc requires a PLT entry\n");
|
3529 |
|
|
#endif
|
3530 |
|
|
/* This symbol requires a procedure linkage table entry. We
|
3531 |
|
|
actually build the entry in finish_dynamic_symbol,
|
3532 |
|
|
because this might be a case of linking PIC code without
|
3533 |
|
|
linking in any dynamic objects, in which case we don't
|
3534 |
|
|
need to generate a procedure linkage table after all. */
|
3535 |
|
|
|
3536 |
|
|
if (h == NULL)
|
3537 |
|
|
{
|
3538 |
|
|
/* It does not make sense to have a procedure linkage
|
3539 |
|
|
table entry for a local symbol. */
|
3540 |
|
|
(*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against "
|
3541 |
|
|
"local symbol"),
|
3542 |
|
|
abfd,
|
3543 |
|
|
sec,
|
3544 |
|
|
(long) rel->r_offset,
|
3545 |
|
|
ppc_elf_howto_table[r_type]->name);
|
3546 |
|
|
bfd_set_error (bfd_error_bad_value);
|
3547 |
|
|
return FALSE;
|
3548 |
|
|
}
|
3549 |
|
|
else
|
3550 |
|
|
{
|
3551 |
|
|
bfd_vma addend = 0;
|
3552 |
|
|
|
3553 |
|
|
if (r_type == R_PPC_PLTREL24)
|
3554 |
|
|
{
|
3555 |
|
|
ppc_elf_tdata (abfd)->makes_plt_call = 1;
|
3556 |
|
|
addend = rel->r_addend;
|
3557 |
|
|
}
|
3558 |
|
|
h->needs_plt = 1;
|
3559 |
|
|
if (!update_plt_info (abfd, h, got2, addend))
|
3560 |
|
|
return FALSE;
|
3561 |
|
|
}
|
3562 |
|
|
break;
|
3563 |
|
|
|
3564 |
|
|
/* The following relocations don't need to propagate the
|
3565 |
|
|
relocation if linking a shared object since they are
|
3566 |
|
|
section relative. */
|
3567 |
|
|
case R_PPC_SECTOFF:
|
3568 |
|
|
case R_PPC_SECTOFF_LO:
|
3569 |
|
|
case R_PPC_SECTOFF_HI:
|
3570 |
|
|
case R_PPC_SECTOFF_HA:
|
3571 |
|
|
case R_PPC_DTPREL16:
|
3572 |
|
|
case R_PPC_DTPREL16_LO:
|
3573 |
|
|
case R_PPC_DTPREL16_HI:
|
3574 |
|
|
case R_PPC_DTPREL16_HA:
|
3575 |
|
|
case R_PPC_TOC16:
|
3576 |
|
|
break;
|
3577 |
|
|
|
3578 |
|
|
case R_PPC_REL16:
|
3579 |
|
|
case R_PPC_REL16_LO:
|
3580 |
|
|
case R_PPC_REL16_HI:
|
3581 |
|
|
case R_PPC_REL16_HA:
|
3582 |
|
|
ppc_elf_tdata (abfd)->has_rel16 = 1;
|
3583 |
|
|
break;
|
3584 |
|
|
|
3585 |
|
|
/* These are just markers. */
|
3586 |
|
|
case R_PPC_TLS:
|
3587 |
|
|
case R_PPC_EMB_MRKREF:
|
3588 |
|
|
case R_PPC_NONE:
|
3589 |
|
|
case R_PPC_max:
|
3590 |
|
|
break;
|
3591 |
|
|
|
3592 |
|
|
/* These should only appear in dynamic objects. */
|
3593 |
|
|
case R_PPC_COPY:
|
3594 |
|
|
case R_PPC_GLOB_DAT:
|
3595 |
|
|
case R_PPC_JMP_SLOT:
|
3596 |
|
|
case R_PPC_RELATIVE:
|
3597 |
|
|
break;
|
3598 |
|
|
|
3599 |
|
|
/* These aren't handled yet. We'll report an error later. */
|
3600 |
|
|
case R_PPC_ADDR30:
|
3601 |
|
|
case R_PPC_EMB_RELSEC16:
|
3602 |
|
|
case R_PPC_EMB_RELST_LO:
|
3603 |
|
|
case R_PPC_EMB_RELST_HI:
|
3604 |
|
|
case R_PPC_EMB_RELST_HA:
|
3605 |
|
|
case R_PPC_EMB_BIT_FLD:
|
3606 |
|
|
break;
|
3607 |
|
|
|
3608 |
|
|
/* This refers only to functions defined in the shared library. */
|
3609 |
|
|
case R_PPC_LOCAL24PC:
|
3610 |
|
|
if (h && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
|
3611 |
|
|
{
|
3612 |
|
|
htab->plt_type = PLT_OLD;
|
3613 |
|
|
htab->old_bfd = abfd;
|
3614 |
|
|
}
|
3615 |
|
|
break;
|
3616 |
|
|
|
3617 |
|
|
/* This relocation describes the C++ object vtable hierarchy.
|
3618 |
|
|
Reconstruct it for later use during GC. */
|
3619 |
|
|
case R_PPC_GNU_VTINHERIT:
|
3620 |
|
|
if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
|
3621 |
|
|
return FALSE;
|
3622 |
|
|
break;
|
3623 |
|
|
|
3624 |
|
|
/* This relocation describes which C++ vtable entries are actually
|
3625 |
|
|
used. Record for later use during GC. */
|
3626 |
|
|
case R_PPC_GNU_VTENTRY:
|
3627 |
|
|
BFD_ASSERT (h != NULL);
|
3628 |
|
|
if (h != NULL
|
3629 |
|
|
&& !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
|
3630 |
|
|
return FALSE;
|
3631 |
|
|
break;
|
3632 |
|
|
|
3633 |
|
|
/* We shouldn't really be seeing these. */
|
3634 |
|
|
case R_PPC_TPREL32:
|
3635 |
|
|
case R_PPC_TPREL16:
|
3636 |
|
|
case R_PPC_TPREL16_LO:
|
3637 |
|
|
case R_PPC_TPREL16_HI:
|
3638 |
|
|
case R_PPC_TPREL16_HA:
|
3639 |
|
|
if (!info->executable)
|
3640 |
|
|
info->flags |= DF_STATIC_TLS;
|
3641 |
|
|
goto dodyn;
|
3642 |
|
|
|
3643 |
|
|
/* Nor these. */
|
3644 |
|
|
case R_PPC_DTPMOD32:
|
3645 |
|
|
case R_PPC_DTPREL32:
|
3646 |
|
|
goto dodyn;
|
3647 |
|
|
|
3648 |
|
|
case R_PPC_REL32:
|
3649 |
|
|
if (h == NULL
|
3650 |
|
|
&& got2 != NULL
|
3651 |
|
|
&& (sec->flags & SEC_CODE) != 0
|
3652 |
|
|
&& (info->shared || info->pie)
|
3653 |
|
|
&& htab->plt_type == PLT_UNSET)
|
3654 |
|
|
{
|
3655 |
|
|
/* Old -fPIC gcc code has .long LCTOC1-LCFx just before
|
3656 |
|
|
the start of a function, which assembles to a REL32
|
3657 |
|
|
reference to .got2. If we detect one of these, then
|
3658 |
|
|
force the old PLT layout because the linker cannot
|
3659 |
|
|
reliably deduce the GOT pointer value needed for
|
3660 |
|
|
PLT call stubs. */
|
3661 |
|
|
asection *s;
|
3662 |
|
|
|
3663 |
|
|
s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
|
3664 |
|
|
r_symndx);
|
3665 |
|
|
if (s == got2)
|
3666 |
|
|
{
|
3667 |
|
|
htab->plt_type = PLT_OLD;
|
3668 |
|
|
htab->old_bfd = abfd;
|
3669 |
|
|
}
|
3670 |
|
|
}
|
3671 |
|
|
if (h == NULL || h == htab->elf.hgot)
|
3672 |
|
|
break;
|
3673 |
|
|
/* fall through */
|
3674 |
|
|
|
3675 |
|
|
case R_PPC_ADDR32:
|
3676 |
|
|
case R_PPC_ADDR16:
|
3677 |
|
|
case R_PPC_ADDR16_LO:
|
3678 |
|
|
case R_PPC_ADDR16_HI:
|
3679 |
|
|
case R_PPC_ADDR16_HA:
|
3680 |
|
|
case R_PPC_UADDR32:
|
3681 |
|
|
case R_PPC_UADDR16:
|
3682 |
|
|
if (h != NULL && !info->shared)
|
3683 |
|
|
{
|
3684 |
|
|
/* We may need a plt entry if the symbol turns out to be
|
3685 |
|
|
a function defined in a dynamic object. */
|
3686 |
|
|
if (!update_plt_info (abfd, h, NULL, 0))
|
3687 |
|
|
return FALSE;
|
3688 |
|
|
|
3689 |
|
|
/* We may need a copy reloc too. */
|
3690 |
|
|
h->non_got_ref = 1;
|
3691 |
|
|
h->pointer_equality_needed = 1;
|
3692 |
|
|
}
|
3693 |
|
|
goto dodyn;
|
3694 |
|
|
|
3695 |
|
|
case R_PPC_REL24:
|
3696 |
|
|
case R_PPC_REL14:
|
3697 |
|
|
case R_PPC_REL14_BRTAKEN:
|
3698 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
3699 |
|
|
if (h == NULL)
|
3700 |
|
|
break;
|
3701 |
|
|
if (h == htab->elf.hgot)
|
3702 |
|
|
{
|
3703 |
|
|
if (htab->plt_type == PLT_UNSET)
|
3704 |
|
|
{
|
3705 |
|
|
htab->plt_type = PLT_OLD;
|
3706 |
|
|
htab->old_bfd = abfd;
|
3707 |
|
|
}
|
3708 |
|
|
break;
|
3709 |
|
|
}
|
3710 |
|
|
/* fall through */
|
3711 |
|
|
|
3712 |
|
|
case R_PPC_ADDR24:
|
3713 |
|
|
case R_PPC_ADDR14:
|
3714 |
|
|
case R_PPC_ADDR14_BRTAKEN:
|
3715 |
|
|
case R_PPC_ADDR14_BRNTAKEN:
|
3716 |
|
|
if (h != NULL && !info->shared)
|
3717 |
|
|
{
|
3718 |
|
|
/* We may need a plt entry if the symbol turns out to be
|
3719 |
|
|
a function defined in a dynamic object. */
|
3720 |
|
|
if (!update_plt_info (abfd, h, NULL, 0))
|
3721 |
|
|
return FALSE;
|
3722 |
|
|
break;
|
3723 |
|
|
}
|
3724 |
|
|
|
3725 |
|
|
dodyn:
|
3726 |
|
|
/* If we are creating a shared library, and this is a reloc
|
3727 |
|
|
against a global symbol, or a non PC relative reloc
|
3728 |
|
|
against a local symbol, then we need to copy the reloc
|
3729 |
|
|
into the shared library. However, if we are linking with
|
3730 |
|
|
-Bsymbolic, we do not need to copy a reloc against a
|
3731 |
|
|
global symbol which is defined in an object we are
|
3732 |
|
|
including in the link (i.e., DEF_REGULAR is set). At
|
3733 |
|
|
this point we have not seen all the input files, so it is
|
3734 |
|
|
possible that DEF_REGULAR is not set now but will be set
|
3735 |
|
|
later (it is never cleared). In case of a weak definition,
|
3736 |
|
|
DEF_REGULAR may be cleared later by a strong definition in
|
3737 |
|
|
a shared library. We account for that possibility below by
|
3738 |
|
|
storing information in the dyn_relocs field of the hash
|
3739 |
|
|
table entry. A similar situation occurs when creating
|
3740 |
|
|
shared libraries and symbol visibility changes render the
|
3741 |
|
|
symbol local.
|
3742 |
|
|
|
3743 |
|
|
If on the other hand, we are creating an executable, we
|
3744 |
|
|
may need to keep relocations for symbols satisfied by a
|
3745 |
|
|
dynamic library if we manage to avoid copy relocs for the
|
3746 |
|
|
symbol. */
|
3747 |
|
|
if ((info->shared
|
3748 |
|
|
&& (must_be_dyn_reloc (info, r_type)
|
3749 |
|
|
|| (h != NULL
|
3750 |
|
|
&& (! info->symbolic
|
3751 |
|
|
|| h->root.type == bfd_link_hash_defweak
|
3752 |
|
|
|| !h->def_regular))))
|
3753 |
|
|
|| (ELIMINATE_COPY_RELOCS
|
3754 |
|
|
&& !info->shared
|
3755 |
|
|
&& h != NULL
|
3756 |
|
|
&& (h->root.type == bfd_link_hash_defweak
|
3757 |
|
|
|| !h->def_regular)))
|
3758 |
|
|
{
|
3759 |
|
|
struct ppc_elf_dyn_relocs *p;
|
3760 |
|
|
struct ppc_elf_dyn_relocs **head;
|
3761 |
|
|
|
3762 |
|
|
#ifdef DEBUG
|
3763 |
|
|
fprintf (stderr,
|
3764 |
|
|
"ppc_elf_check_relocs needs to "
|
3765 |
|
|
"create relocation for %s\n",
|
3766 |
|
|
(h && h->root.root.string
|
3767 |
|
|
? h->root.root.string : "<unknown>"));
|
3768 |
|
|
#endif
|
3769 |
|
|
if (sreloc == NULL)
|
3770 |
|
|
{
|
3771 |
|
|
const char *name;
|
3772 |
|
|
|
3773 |
|
|
name = (bfd_elf_string_from_elf_section
|
3774 |
|
|
(abfd,
|
3775 |
|
|
elf_elfheader (abfd)->e_shstrndx,
|
3776 |
|
|
elf_section_data (sec)->rel_hdr.sh_name));
|
3777 |
|
|
if (name == NULL)
|
3778 |
|
|
return FALSE;
|
3779 |
|
|
|
3780 |
|
|
BFD_ASSERT (CONST_STRNEQ (name, ".rela")
|
3781 |
|
|
&& strcmp (bfd_get_section_name (abfd, sec),
|
3782 |
|
|
name + 5) == 0);
|
3783 |
|
|
|
3784 |
|
|
if (htab->elf.dynobj == NULL)
|
3785 |
|
|
htab->elf.dynobj = abfd;
|
3786 |
|
|
sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
|
3787 |
|
|
if (sreloc == NULL)
|
3788 |
|
|
{
|
3789 |
|
|
flagword flags;
|
3790 |
|
|
|
3791 |
|
|
flags = (SEC_HAS_CONTENTS | SEC_READONLY
|
3792 |
|
|
| SEC_IN_MEMORY | SEC_LINKER_CREATED
|
3793 |
|
|
| SEC_ALLOC | SEC_LOAD);
|
3794 |
|
|
sreloc = bfd_make_section_with_flags (htab->elf.dynobj,
|
3795 |
|
|
name,
|
3796 |
|
|
flags);
|
3797 |
|
|
if (sreloc == NULL
|
3798 |
|
|
|| ! bfd_set_section_alignment (htab->elf.dynobj,
|
3799 |
|
|
sreloc, 2))
|
3800 |
|
|
return FALSE;
|
3801 |
|
|
}
|
3802 |
|
|
elf_section_data (sec)->sreloc = sreloc;
|
3803 |
|
|
}
|
3804 |
|
|
|
3805 |
|
|
/* If this is a global symbol, we count the number of
|
3806 |
|
|
relocations we need for this symbol. */
|
3807 |
|
|
if (h != NULL)
|
3808 |
|
|
{
|
3809 |
|
|
head = &ppc_elf_hash_entry (h)->dyn_relocs;
|
3810 |
|
|
}
|
3811 |
|
|
else
|
3812 |
|
|
{
|
3813 |
|
|
/* Track dynamic relocs needed for local syms too.
|
3814 |
|
|
We really need local syms available to do this
|
3815 |
|
|
easily. Oh well. */
|
3816 |
|
|
|
3817 |
|
|
asection *s;
|
3818 |
|
|
void *vpp;
|
3819 |
|
|
|
3820 |
|
|
s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
|
3821 |
|
|
sec, r_symndx);
|
3822 |
|
|
if (s == NULL)
|
3823 |
|
|
return FALSE;
|
3824 |
|
|
|
3825 |
|
|
vpp = &elf_section_data (s)->local_dynrel;
|
3826 |
|
|
head = (struct ppc_elf_dyn_relocs **) vpp;
|
3827 |
|
|
}
|
3828 |
|
|
|
3829 |
|
|
p = *head;
|
3830 |
|
|
if (p == NULL || p->sec != sec)
|
3831 |
|
|
{
|
3832 |
|
|
p = bfd_alloc (htab->elf.dynobj, sizeof *p);
|
3833 |
|
|
if (p == NULL)
|
3834 |
|
|
return FALSE;
|
3835 |
|
|
p->next = *head;
|
3836 |
|
|
*head = p;
|
3837 |
|
|
p->sec = sec;
|
3838 |
|
|
p->count = 0;
|
3839 |
|
|
p->pc_count = 0;
|
3840 |
|
|
}
|
3841 |
|
|
|
3842 |
|
|
p->count += 1;
|
3843 |
|
|
if (!must_be_dyn_reloc (info, r_type))
|
3844 |
|
|
p->pc_count += 1;
|
3845 |
|
|
}
|
3846 |
|
|
|
3847 |
|
|
break;
|
3848 |
|
|
}
|
3849 |
|
|
}
|
3850 |
|
|
|
3851 |
|
|
return TRUE;
|
3852 |
|
|
}
|
3853 |
|
|
|
3854 |
|
|
|
3855 |
|
|
/* Merge object attributes from IBFD into OBFD. Raise an error if
|
3856 |
|
|
there are conflicting attributes. */
|
3857 |
|
|
static bfd_boolean
|
3858 |
|
|
ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
|
3859 |
|
|
{
|
3860 |
|
|
obj_attribute *in_attr, *in_attrs;
|
3861 |
|
|
obj_attribute *out_attr, *out_attrs;
|
3862 |
|
|
|
3863 |
|
|
if (!elf_known_obj_attributes_proc (obfd)[0].i)
|
3864 |
|
|
{
|
3865 |
|
|
/* This is the first object. Copy the attributes. */
|
3866 |
|
|
_bfd_elf_copy_obj_attributes (ibfd, obfd);
|
3867 |
|
|
|
3868 |
|
|
/* Use the Tag_null value to indicate the attributes have been
|
3869 |
|
|
initialized. */
|
3870 |
|
|
elf_known_obj_attributes_proc (obfd)[0].i = 1;
|
3871 |
|
|
|
3872 |
|
|
return TRUE;
|
3873 |
|
|
}
|
3874 |
|
|
|
3875 |
|
|
in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
|
3876 |
|
|
out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
|
3877 |
|
|
|
3878 |
|
|
/* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
|
3879 |
|
|
non-conflicting ones. */
|
3880 |
|
|
in_attr = &in_attrs[Tag_GNU_Power_ABI_FP];
|
3881 |
|
|
out_attr = &out_attrs[Tag_GNU_Power_ABI_FP];
|
3882 |
|
|
if (in_attr->i != out_attr->i)
|
3883 |
|
|
{
|
3884 |
|
|
out_attr->type = 1;
|
3885 |
|
|
if (out_attr->i == 0)
|
3886 |
|
|
out_attr->i = in_attr->i;
|
3887 |
|
|
else if (in_attr->i == 0)
|
3888 |
|
|
;
|
3889 |
|
|
else if (out_attr->i == 1 && in_attr->i == 2)
|
3890 |
|
|
_bfd_error_handler
|
3891 |
|
|
(_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
|
3892 |
|
|
else if (out_attr->i == 1 && in_attr->i == 3)
|
3893 |
|
|
_bfd_error_handler
|
3894 |
|
|
(_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
|
3895 |
|
|
obfd, ibfd);
|
3896 |
|
|
else if (out_attr->i == 3 && in_attr->i == 1)
|
3897 |
|
|
_bfd_error_handler
|
3898 |
|
|
(_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
|
3899 |
|
|
ibfd, obfd);
|
3900 |
|
|
else if (out_attr->i == 3 && in_attr->i == 2)
|
3901 |
|
|
_bfd_error_handler
|
3902 |
|
|
(_("Warning: %B uses soft float, %B uses single-precision hard float"),
|
3903 |
|
|
ibfd, obfd);
|
3904 |
|
|
else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3))
|
3905 |
|
|
_bfd_error_handler
|
3906 |
|
|
(_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
|
3907 |
|
|
else if (in_attr->i > 3)
|
3908 |
|
|
_bfd_error_handler
|
3909 |
|
|
(_("Warning: %B uses unknown floating point ABI %d"), ibfd,
|
3910 |
|
|
in_attr->i);
|
3911 |
|
|
else
|
3912 |
|
|
_bfd_error_handler
|
3913 |
|
|
(_("Warning: %B uses unknown floating point ABI %d"), obfd,
|
3914 |
|
|
out_attr->i);
|
3915 |
|
|
}
|
3916 |
|
|
|
3917 |
|
|
/* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
|
3918 |
|
|
merge non-conflicting ones. */
|
3919 |
|
|
in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector];
|
3920 |
|
|
out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector];
|
3921 |
|
|
if (in_attr->i != out_attr->i)
|
3922 |
|
|
{
|
3923 |
|
|
const char *in_abi = NULL, *out_abi = NULL;
|
3924 |
|
|
|
3925 |
|
|
switch (in_attr->i)
|
3926 |
|
|
{
|
3927 |
|
|
case 1: in_abi = "generic"; break;
|
3928 |
|
|
case 2: in_abi = "AltiVec"; break;
|
3929 |
|
|
case 3: in_abi = "SPE"; break;
|
3930 |
|
|
}
|
3931 |
|
|
|
3932 |
|
|
switch (out_attr->i)
|
3933 |
|
|
{
|
3934 |
|
|
case 1: out_abi = "generic"; break;
|
3935 |
|
|
case 2: out_abi = "AltiVec"; break;
|
3936 |
|
|
case 3: out_abi = "SPE"; break;
|
3937 |
|
|
}
|
3938 |
|
|
|
3939 |
|
|
out_attr->type = 1;
|
3940 |
|
|
if (out_attr->i == 0)
|
3941 |
|
|
out_attr->i = in_attr->i;
|
3942 |
|
|
else if (in_attr->i == 0)
|
3943 |
|
|
;
|
3944 |
|
|
/* For now, allow generic to transition to AltiVec or SPE
|
3945 |
|
|
without a warning. If GCC marked files with their stack
|
3946 |
|
|
alignment and used don't-care markings for files which are
|
3947 |
|
|
not affected by the vector ABI, we could warn about this
|
3948 |
|
|
case too. */
|
3949 |
|
|
else if (out_attr->i == 1)
|
3950 |
|
|
out_attr->i = in_attr->i;
|
3951 |
|
|
else if (in_attr->i == 1)
|
3952 |
|
|
;
|
3953 |
|
|
else if (in_abi == NULL)
|
3954 |
|
|
_bfd_error_handler
|
3955 |
|
|
(_("Warning: %B uses unknown vector ABI %d"), ibfd,
|
3956 |
|
|
in_attr->i);
|
3957 |
|
|
else if (out_abi == NULL)
|
3958 |
|
|
_bfd_error_handler
|
3959 |
|
|
(_("Warning: %B uses unknown vector ABI %d"), obfd,
|
3960 |
|
|
in_attr->i);
|
3961 |
|
|
else
|
3962 |
|
|
_bfd_error_handler
|
3963 |
|
|
(_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
|
3964 |
|
|
ibfd, obfd, in_abi, out_abi);
|
3965 |
|
|
}
|
3966 |
|
|
|
3967 |
|
|
/* Merge Tag_compatibility attributes and any common GNU ones. */
|
3968 |
|
|
_bfd_elf_merge_object_attributes (ibfd, obfd);
|
3969 |
|
|
|
3970 |
|
|
return TRUE;
|
3971 |
|
|
}
|
3972 |
|
|
|
3973 |
|
|
/* Merge backend specific data from an object file to the output
|
3974 |
|
|
object file when linking. */
|
3975 |
|
|
|
3976 |
|
|
static bfd_boolean
|
3977 |
|
|
ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
|
3978 |
|
|
{
|
3979 |
|
|
flagword old_flags;
|
3980 |
|
|
flagword new_flags;
|
3981 |
|
|
bfd_boolean error;
|
3982 |
|
|
|
3983 |
|
|
if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd))
|
3984 |
|
|
return TRUE;
|
3985 |
|
|
|
3986 |
|
|
/* Check if we have the same endianess. */
|
3987 |
|
|
if (! _bfd_generic_verify_endian_match (ibfd, obfd))
|
3988 |
|
|
return FALSE;
|
3989 |
|
|
|
3990 |
|
|
if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
|
3991 |
|
|
return FALSE;
|
3992 |
|
|
|
3993 |
|
|
new_flags = elf_elfheader (ibfd)->e_flags;
|
3994 |
|
|
old_flags = elf_elfheader (obfd)->e_flags;
|
3995 |
|
|
if (!elf_flags_init (obfd))
|
3996 |
|
|
{
|
3997 |
|
|
/* First call, no flags set. */
|
3998 |
|
|
elf_flags_init (obfd) = TRUE;
|
3999 |
|
|
elf_elfheader (obfd)->e_flags = new_flags;
|
4000 |
|
|
}
|
4001 |
|
|
|
4002 |
|
|
/* Compatible flags are ok. */
|
4003 |
|
|
else if (new_flags == old_flags)
|
4004 |
|
|
;
|
4005 |
|
|
|
4006 |
|
|
/* Incompatible flags. */
|
4007 |
|
|
else
|
4008 |
|
|
{
|
4009 |
|
|
/* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
|
4010 |
|
|
to be linked with either. */
|
4011 |
|
|
error = FALSE;
|
4012 |
|
|
if ((new_flags & EF_PPC_RELOCATABLE) != 0
|
4013 |
|
|
&& (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
|
4014 |
|
|
{
|
4015 |
|
|
error = TRUE;
|
4016 |
|
|
(*_bfd_error_handler)
|
4017 |
|
|
(_("%B: compiled with -mrelocatable and linked with "
|
4018 |
|
|
"modules compiled normally"), ibfd);
|
4019 |
|
|
}
|
4020 |
|
|
else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
|
4021 |
|
|
&& (old_flags & EF_PPC_RELOCATABLE) != 0)
|
4022 |
|
|
{
|
4023 |
|
|
error = TRUE;
|
4024 |
|
|
(*_bfd_error_handler)
|
4025 |
|
|
(_("%B: compiled normally and linked with "
|
4026 |
|
|
"modules compiled with -mrelocatable"), ibfd);
|
4027 |
|
|
}
|
4028 |
|
|
|
4029 |
|
|
/* The output is -mrelocatable-lib iff both the input files are. */
|
4030 |
|
|
if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
|
4031 |
|
|
elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
|
4032 |
|
|
|
4033 |
|
|
/* The output is -mrelocatable iff it can't be -mrelocatable-lib,
|
4034 |
|
|
but each input file is either -mrelocatable or -mrelocatable-lib. */
|
4035 |
|
|
if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
|
4036 |
|
|
&& (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
|
4037 |
|
|
&& (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
|
4038 |
|
|
elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
|
4039 |
|
|
|
4040 |
|
|
/* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
|
4041 |
|
|
any module uses it. */
|
4042 |
|
|
elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
|
4043 |
|
|
|
4044 |
|
|
new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
|
4045 |
|
|
old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
|
4046 |
|
|
|
4047 |
|
|
/* Warn about any other mismatches. */
|
4048 |
|
|
if (new_flags != old_flags)
|
4049 |
|
|
{
|
4050 |
|
|
error = TRUE;
|
4051 |
|
|
(*_bfd_error_handler)
|
4052 |
|
|
(_("%B: uses different e_flags (0x%lx) fields "
|
4053 |
|
|
"than previous modules (0x%lx)"),
|
4054 |
|
|
ibfd, (long) new_flags, (long) old_flags);
|
4055 |
|
|
}
|
4056 |
|
|
|
4057 |
|
|
if (error)
|
4058 |
|
|
{
|
4059 |
|
|
bfd_set_error (bfd_error_bad_value);
|
4060 |
|
|
return FALSE;
|
4061 |
|
|
}
|
4062 |
|
|
}
|
4063 |
|
|
|
4064 |
|
|
return TRUE;
|
4065 |
|
|
}
|
4066 |
|
|
|
4067 |
|
|
/* Choose which PLT scheme to use, and set .plt flags appropriately.
|
4068 |
|
|
Returns -1 on error, 0 for old PLT, 1 for new PLT. */
|
4069 |
|
|
int
|
4070 |
|
|
ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
|
4071 |
|
|
struct bfd_link_info *info,
|
4072 |
|
|
enum ppc_elf_plt_type plt_style,
|
4073 |
|
|
int emit_stub_syms)
|
4074 |
|
|
{
|
4075 |
|
|
struct ppc_elf_link_hash_table *htab;
|
4076 |
|
|
flagword flags;
|
4077 |
|
|
|
4078 |
|
|
htab = ppc_elf_hash_table (info);
|
4079 |
|
|
|
4080 |
|
|
if (htab->plt_type == PLT_UNSET)
|
4081 |
|
|
{
|
4082 |
|
|
if (plt_style == PLT_OLD)
|
4083 |
|
|
htab->plt_type = PLT_OLD;
|
4084 |
|
|
else
|
4085 |
|
|
{
|
4086 |
|
|
bfd *ibfd;
|
4087 |
|
|
enum ppc_elf_plt_type plt_type = plt_style;
|
4088 |
|
|
|
4089 |
|
|
/* Look through the reloc flags left by ppc_elf_check_relocs.
|
4090 |
|
|
Use the old style bss plt if a file makes plt calls
|
4091 |
|
|
without using the new relocs, and if ld isn't given
|
4092 |
|
|
--secure-plt and we never see REL16 relocs. */
|
4093 |
|
|
if (plt_type == PLT_UNSET)
|
4094 |
|
|
plt_type = PLT_OLD;
|
4095 |
|
|
for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next)
|
4096 |
|
|
if (is_ppc_elf (ibfd))
|
4097 |
|
|
{
|
4098 |
|
|
if (ppc_elf_tdata (ibfd)->has_rel16)
|
4099 |
|
|
plt_type = PLT_NEW;
|
4100 |
|
|
else if (ppc_elf_tdata (ibfd)->makes_plt_call)
|
4101 |
|
|
{
|
4102 |
|
|
plt_type = PLT_OLD;
|
4103 |
|
|
htab->old_bfd = ibfd;
|
4104 |
|
|
break;
|
4105 |
|
|
}
|
4106 |
|
|
}
|
4107 |
|
|
htab->plt_type = plt_type;
|
4108 |
|
|
}
|
4109 |
|
|
}
|
4110 |
|
|
if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW)
|
4111 |
|
|
info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd);
|
4112 |
|
|
|
4113 |
|
|
htab->emit_stub_syms = emit_stub_syms;
|
4114 |
|
|
|
4115 |
|
|
BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
|
4116 |
|
|
|
4117 |
|
|
if (htab->plt_type == PLT_NEW)
|
4118 |
|
|
{
|
4119 |
|
|
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
|
4120 |
|
|
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
4121 |
|
|
|
4122 |
|
|
/* The new PLT is a loaded section. */
|
4123 |
|
|
if (htab->plt != NULL
|
4124 |
|
|
&& !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
|
4125 |
|
|
return -1;
|
4126 |
|
|
|
4127 |
|
|
/* The new GOT is not executable. */
|
4128 |
|
|
if (htab->got != NULL
|
4129 |
|
|
&& !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
|
4130 |
|
|
return -1;
|
4131 |
|
|
}
|
4132 |
|
|
else
|
4133 |
|
|
{
|
4134 |
|
|
/* Stop an unused .glink section from affecting .text alignment. */
|
4135 |
|
|
if (htab->glink != NULL
|
4136 |
|
|
&& !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
|
4137 |
|
|
return -1;
|
4138 |
|
|
}
|
4139 |
|
|
return htab->plt_type == PLT_NEW;
|
4140 |
|
|
}
|
4141 |
|
|
|
4142 |
|
|
/* Return the section that should be marked against GC for a given
|
4143 |
|
|
relocation. */
|
4144 |
|
|
|
4145 |
|
|
static asection *
|
4146 |
|
|
ppc_elf_gc_mark_hook (asection *sec,
|
4147 |
|
|
struct bfd_link_info *info,
|
4148 |
|
|
Elf_Internal_Rela *rel,
|
4149 |
|
|
struct elf_link_hash_entry *h,
|
4150 |
|
|
Elf_Internal_Sym *sym)
|
4151 |
|
|
{
|
4152 |
|
|
if (h != NULL)
|
4153 |
|
|
switch (ELF32_R_TYPE (rel->r_info))
|
4154 |
|
|
{
|
4155 |
|
|
case R_PPC_GNU_VTINHERIT:
|
4156 |
|
|
case R_PPC_GNU_VTENTRY:
|
4157 |
|
|
return NULL;
|
4158 |
|
|
}
|
4159 |
|
|
|
4160 |
|
|
return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
|
4161 |
|
|
}
|
4162 |
|
|
|
4163 |
|
|
/* Update the got, plt and dynamic reloc reference counts for the
|
4164 |
|
|
section being removed. */
|
4165 |
|
|
|
4166 |
|
|
static bfd_boolean
|
4167 |
|
|
ppc_elf_gc_sweep_hook (bfd *abfd,
|
4168 |
|
|
struct bfd_link_info *info,
|
4169 |
|
|
asection *sec,
|
4170 |
|
|
const Elf_Internal_Rela *relocs)
|
4171 |
|
|
{
|
4172 |
|
|
struct ppc_elf_link_hash_table *htab;
|
4173 |
|
|
Elf_Internal_Shdr *symtab_hdr;
|
4174 |
|
|
struct elf_link_hash_entry **sym_hashes;
|
4175 |
|
|
bfd_signed_vma *local_got_refcounts;
|
4176 |
|
|
const Elf_Internal_Rela *rel, *relend;
|
4177 |
|
|
asection *got2;
|
4178 |
|
|
|
4179 |
|
|
if (info->relocatable)
|
4180 |
|
|
return TRUE;
|
4181 |
|
|
|
4182 |
|
|
if ((sec->flags & SEC_ALLOC) == 0)
|
4183 |
|
|
return TRUE;
|
4184 |
|
|
|
4185 |
|
|
elf_section_data (sec)->local_dynrel = NULL;
|
4186 |
|
|
|
4187 |
|
|
htab = ppc_elf_hash_table (info);
|
4188 |
|
|
symtab_hdr = &elf_symtab_hdr (abfd);
|
4189 |
|
|
sym_hashes = elf_sym_hashes (abfd);
|
4190 |
|
|
local_got_refcounts = elf_local_got_refcounts (abfd);
|
4191 |
|
|
got2 = bfd_get_section_by_name (abfd, ".got2");
|
4192 |
|
|
|
4193 |
|
|
relend = relocs + sec->reloc_count;
|
4194 |
|
|
for (rel = relocs; rel < relend; rel++)
|
4195 |
|
|
{
|
4196 |
|
|
unsigned long r_symndx;
|
4197 |
|
|
enum elf_ppc_reloc_type r_type;
|
4198 |
|
|
struct elf_link_hash_entry *h = NULL;
|
4199 |
|
|
|
4200 |
|
|
r_symndx = ELF32_R_SYM (rel->r_info);
|
4201 |
|
|
if (r_symndx >= symtab_hdr->sh_info)
|
4202 |
|
|
{
|
4203 |
|
|
struct ppc_elf_dyn_relocs **pp, *p;
|
4204 |
|
|
struct ppc_elf_link_hash_entry *eh;
|
4205 |
|
|
|
4206 |
|
|
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
4207 |
|
|
while (h->root.type == bfd_link_hash_indirect
|
4208 |
|
|
|| h->root.type == bfd_link_hash_warning)
|
4209 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
4210 |
|
|
eh = (struct ppc_elf_link_hash_entry *) h;
|
4211 |
|
|
|
4212 |
|
|
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
|
4213 |
|
|
if (p->sec == sec)
|
4214 |
|
|
{
|
4215 |
|
|
/* Everything must go for SEC. */
|
4216 |
|
|
*pp = p->next;
|
4217 |
|
|
break;
|
4218 |
|
|
}
|
4219 |
|
|
}
|
4220 |
|
|
|
4221 |
|
|
r_type = ELF32_R_TYPE (rel->r_info);
|
4222 |
|
|
switch (r_type)
|
4223 |
|
|
{
|
4224 |
|
|
case R_PPC_GOT_TLSLD16:
|
4225 |
|
|
case R_PPC_GOT_TLSLD16_LO:
|
4226 |
|
|
case R_PPC_GOT_TLSLD16_HI:
|
4227 |
|
|
case R_PPC_GOT_TLSLD16_HA:
|
4228 |
|
|
case R_PPC_GOT_TLSGD16:
|
4229 |
|
|
case R_PPC_GOT_TLSGD16_LO:
|
4230 |
|
|
case R_PPC_GOT_TLSGD16_HI:
|
4231 |
|
|
case R_PPC_GOT_TLSGD16_HA:
|
4232 |
|
|
case R_PPC_GOT_TPREL16:
|
4233 |
|
|
case R_PPC_GOT_TPREL16_LO:
|
4234 |
|
|
case R_PPC_GOT_TPREL16_HI:
|
4235 |
|
|
case R_PPC_GOT_TPREL16_HA:
|
4236 |
|
|
case R_PPC_GOT_DTPREL16:
|
4237 |
|
|
case R_PPC_GOT_DTPREL16_LO:
|
4238 |
|
|
case R_PPC_GOT_DTPREL16_HI:
|
4239 |
|
|
case R_PPC_GOT_DTPREL16_HA:
|
4240 |
|
|
case R_PPC_GOT16:
|
4241 |
|
|
case R_PPC_GOT16_LO:
|
4242 |
|
|
case R_PPC_GOT16_HI:
|
4243 |
|
|
case R_PPC_GOT16_HA:
|
4244 |
|
|
if (h != NULL)
|
4245 |
|
|
{
|
4246 |
|
|
if (h->got.refcount > 0)
|
4247 |
|
|
h->got.refcount--;
|
4248 |
|
|
}
|
4249 |
|
|
else if (local_got_refcounts != NULL)
|
4250 |
|
|
{
|
4251 |
|
|
if (local_got_refcounts[r_symndx] > 0)
|
4252 |
|
|
local_got_refcounts[r_symndx]--;
|
4253 |
|
|
}
|
4254 |
|
|
break;
|
4255 |
|
|
|
4256 |
|
|
case R_PPC_REL24:
|
4257 |
|
|
case R_PPC_REL14:
|
4258 |
|
|
case R_PPC_REL14_BRTAKEN:
|
4259 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
4260 |
|
|
case R_PPC_REL32:
|
4261 |
|
|
if (h == NULL || h == htab->elf.hgot)
|
4262 |
|
|
break;
|
4263 |
|
|
/* Fall thru */
|
4264 |
|
|
|
4265 |
|
|
case R_PPC_ADDR32:
|
4266 |
|
|
case R_PPC_ADDR24:
|
4267 |
|
|
case R_PPC_ADDR16:
|
4268 |
|
|
case R_PPC_ADDR16_LO:
|
4269 |
|
|
case R_PPC_ADDR16_HI:
|
4270 |
|
|
case R_PPC_ADDR16_HA:
|
4271 |
|
|
case R_PPC_ADDR14:
|
4272 |
|
|
case R_PPC_ADDR14_BRTAKEN:
|
4273 |
|
|
case R_PPC_ADDR14_BRNTAKEN:
|
4274 |
|
|
case R_PPC_UADDR32:
|
4275 |
|
|
case R_PPC_UADDR16:
|
4276 |
|
|
if (info->shared)
|
4277 |
|
|
break;
|
4278 |
|
|
|
4279 |
|
|
case R_PPC_PLT32:
|
4280 |
|
|
case R_PPC_PLTREL24:
|
4281 |
|
|
case R_PPC_PLTREL32:
|
4282 |
|
|
case R_PPC_PLT16_LO:
|
4283 |
|
|
case R_PPC_PLT16_HI:
|
4284 |
|
|
case R_PPC_PLT16_HA:
|
4285 |
|
|
if (h != NULL)
|
4286 |
|
|
{
|
4287 |
|
|
bfd_vma addend = r_type == R_PPC_PLTREL24 ? rel->r_addend : 0;
|
4288 |
|
|
struct plt_entry *ent = find_plt_ent (h, got2, addend);
|
4289 |
|
|
if (ent->plt.refcount > 0)
|
4290 |
|
|
ent->plt.refcount -= 1;
|
4291 |
|
|
}
|
4292 |
|
|
break;
|
4293 |
|
|
|
4294 |
|
|
default:
|
4295 |
|
|
break;
|
4296 |
|
|
}
|
4297 |
|
|
}
|
4298 |
|
|
return TRUE;
|
4299 |
|
|
}
|
4300 |
|
|
|
4301 |
|
|
/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
|
4302 |
|
|
|
4303 |
|
|
asection *
|
4304 |
|
|
ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
|
4305 |
|
|
{
|
4306 |
|
|
struct ppc_elf_link_hash_table *htab;
|
4307 |
|
|
|
4308 |
|
|
htab = ppc_elf_hash_table (info);
|
4309 |
|
|
if (htab->plt_type == PLT_NEW
|
4310 |
|
|
&& htab->plt != NULL
|
4311 |
|
|
&& htab->plt->output_section != NULL)
|
4312 |
|
|
{
|
4313 |
|
|
elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
|
4314 |
|
|
elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
|
4315 |
|
|
}
|
4316 |
|
|
|
4317 |
|
|
htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
|
4318 |
|
|
FALSE, FALSE, TRUE);
|
4319 |
|
|
return _bfd_elf_tls_setup (obfd, info);
|
4320 |
|
|
}
|
4321 |
|
|
|
4322 |
|
|
/* Run through all the TLS relocs looking for optimization
|
4323 |
|
|
opportunities. */
|
4324 |
|
|
|
4325 |
|
|
bfd_boolean
|
4326 |
|
|
ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
|
4327 |
|
|
struct bfd_link_info *info)
|
4328 |
|
|
{
|
4329 |
|
|
bfd *ibfd;
|
4330 |
|
|
asection *sec;
|
4331 |
|
|
struct ppc_elf_link_hash_table *htab;
|
4332 |
|
|
int pass;
|
4333 |
|
|
|
4334 |
|
|
if (info->relocatable || !info->executable)
|
4335 |
|
|
return TRUE;
|
4336 |
|
|
|
4337 |
|
|
htab = ppc_elf_hash_table (info);
|
4338 |
|
|
/* Make two passes through the relocs. First time check that tls
|
4339 |
|
|
relocs involved in setting up a tls_get_addr call are indeed
|
4340 |
|
|
followed by such a call. If they are not, exclude them from
|
4341 |
|
|
the optimizations done on the second pass. */
|
4342 |
|
|
for (pass = 0; pass < 2; ++pass)
|
4343 |
|
|
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
|
4344 |
|
|
{
|
4345 |
|
|
Elf_Internal_Sym *locsyms = NULL;
|
4346 |
|
|
Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
|
4347 |
|
|
|
4348 |
|
|
for (sec = ibfd->sections; sec != NULL; sec = sec->next)
|
4349 |
|
|
if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
|
4350 |
|
|
{
|
4351 |
|
|
Elf_Internal_Rela *relstart, *rel, *relend;
|
4352 |
|
|
|
4353 |
|
|
/* Read the relocations. */
|
4354 |
|
|
relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
|
4355 |
|
|
info->keep_memory);
|
4356 |
|
|
if (relstart == NULL)
|
4357 |
|
|
return FALSE;
|
4358 |
|
|
|
4359 |
|
|
relend = relstart + sec->reloc_count;
|
4360 |
|
|
for (rel = relstart; rel < relend; rel++)
|
4361 |
|
|
{
|
4362 |
|
|
enum elf_ppc_reloc_type r_type;
|
4363 |
|
|
unsigned long r_symndx;
|
4364 |
|
|
struct elf_link_hash_entry *h = NULL;
|
4365 |
|
|
char *tls_mask;
|
4366 |
|
|
char tls_set, tls_clear;
|
4367 |
|
|
bfd_boolean is_local;
|
4368 |
|
|
int expecting_tls_get_addr;
|
4369 |
|
|
bfd_signed_vma *got_count;
|
4370 |
|
|
|
4371 |
|
|
r_symndx = ELF32_R_SYM (rel->r_info);
|
4372 |
|
|
if (r_symndx >= symtab_hdr->sh_info)
|
4373 |
|
|
{
|
4374 |
|
|
struct elf_link_hash_entry **sym_hashes;
|
4375 |
|
|
|
4376 |
|
|
sym_hashes = elf_sym_hashes (ibfd);
|
4377 |
|
|
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
4378 |
|
|
while (h->root.type == bfd_link_hash_indirect
|
4379 |
|
|
|| h->root.type == bfd_link_hash_warning)
|
4380 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
4381 |
|
|
}
|
4382 |
|
|
|
4383 |
|
|
expecting_tls_get_addr = 0;
|
4384 |
|
|
is_local = FALSE;
|
4385 |
|
|
if (h == NULL
|
4386 |
|
|
|| !h->def_dynamic)
|
4387 |
|
|
is_local = TRUE;
|
4388 |
|
|
|
4389 |
|
|
r_type = ELF32_R_TYPE (rel->r_info);
|
4390 |
|
|
switch (r_type)
|
4391 |
|
|
{
|
4392 |
|
|
case R_PPC_GOT_TLSLD16:
|
4393 |
|
|
case R_PPC_GOT_TLSLD16_LO:
|
4394 |
|
|
expecting_tls_get_addr = 1;
|
4395 |
|
|
/* Fall thru */
|
4396 |
|
|
|
4397 |
|
|
case R_PPC_GOT_TLSLD16_HI:
|
4398 |
|
|
case R_PPC_GOT_TLSLD16_HA:
|
4399 |
|
|
/* These relocs should never be against a symbol
|
4400 |
|
|
defined in a shared lib. Leave them alone if
|
4401 |
|
|
that turns out to be the case. */
|
4402 |
|
|
if (!is_local)
|
4403 |
|
|
continue;
|
4404 |
|
|
|
4405 |
|
|
/* LD -> LE */
|
4406 |
|
|
tls_set = 0;
|
4407 |
|
|
tls_clear = TLS_LD;
|
4408 |
|
|
break;
|
4409 |
|
|
|
4410 |
|
|
case R_PPC_GOT_TLSGD16:
|
4411 |
|
|
case R_PPC_GOT_TLSGD16_LO:
|
4412 |
|
|
expecting_tls_get_addr = 1;
|
4413 |
|
|
/* Fall thru */
|
4414 |
|
|
|
4415 |
|
|
case R_PPC_GOT_TLSGD16_HI:
|
4416 |
|
|
case R_PPC_GOT_TLSGD16_HA:
|
4417 |
|
|
if (is_local)
|
4418 |
|
|
/* GD -> LE */
|
4419 |
|
|
tls_set = 0;
|
4420 |
|
|
else
|
4421 |
|
|
/* GD -> IE */
|
4422 |
|
|
tls_set = TLS_TLS | TLS_TPRELGD;
|
4423 |
|
|
tls_clear = TLS_GD;
|
4424 |
|
|
break;
|
4425 |
|
|
|
4426 |
|
|
case R_PPC_GOT_TPREL16:
|
4427 |
|
|
case R_PPC_GOT_TPREL16_LO:
|
4428 |
|
|
case R_PPC_GOT_TPREL16_HI:
|
4429 |
|
|
case R_PPC_GOT_TPREL16_HA:
|
4430 |
|
|
if (is_local)
|
4431 |
|
|
{
|
4432 |
|
|
/* IE -> LE */
|
4433 |
|
|
tls_set = 0;
|
4434 |
|
|
tls_clear = TLS_TPREL;
|
4435 |
|
|
break;
|
4436 |
|
|
}
|
4437 |
|
|
else
|
4438 |
|
|
continue;
|
4439 |
|
|
|
4440 |
|
|
default:
|
4441 |
|
|
continue;
|
4442 |
|
|
}
|
4443 |
|
|
|
4444 |
|
|
if (pass == 0)
|
4445 |
|
|
{
|
4446 |
|
|
if (!expecting_tls_get_addr)
|
4447 |
|
|
continue;
|
4448 |
|
|
|
4449 |
|
|
if (rel + 1 < relend)
|
4450 |
|
|
{
|
4451 |
|
|
enum elf_ppc_reloc_type r_type2;
|
4452 |
|
|
unsigned long r_symndx2;
|
4453 |
|
|
struct elf_link_hash_entry *h2;
|
4454 |
|
|
|
4455 |
|
|
/* The next instruction should be a call to
|
4456 |
|
|
__tls_get_addr. Peek at the reloc to be sure. */
|
4457 |
|
|
r_type2 = ELF32_R_TYPE (rel[1].r_info);
|
4458 |
|
|
r_symndx2 = ELF32_R_SYM (rel[1].r_info);
|
4459 |
|
|
if (r_symndx2 >= symtab_hdr->sh_info
|
4460 |
|
|
&& (r_type2 == R_PPC_REL14
|
4461 |
|
|
|| r_type2 == R_PPC_REL14_BRTAKEN
|
4462 |
|
|
|| r_type2 == R_PPC_REL14_BRNTAKEN
|
4463 |
|
|
|| r_type2 == R_PPC_REL24
|
4464 |
|
|
|| r_type2 == R_PPC_PLTREL24))
|
4465 |
|
|
{
|
4466 |
|
|
struct elf_link_hash_entry **sym_hashes;
|
4467 |
|
|
|
4468 |
|
|
sym_hashes = elf_sym_hashes (ibfd);
|
4469 |
|
|
h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
|
4470 |
|
|
while (h2->root.type == bfd_link_hash_indirect
|
4471 |
|
|
|| h2->root.type == bfd_link_hash_warning)
|
4472 |
|
|
h2 = ((struct elf_link_hash_entry *)
|
4473 |
|
|
h2->root.u.i.link);
|
4474 |
|
|
if (h2 == htab->tls_get_addr)
|
4475 |
|
|
continue;
|
4476 |
|
|
}
|
4477 |
|
|
}
|
4478 |
|
|
|
4479 |
|
|
/* Uh oh, we didn't find the expected call. We
|
4480 |
|
|
could just mark this symbol to exclude it
|
4481 |
|
|
from tls optimization but it's safer to skip
|
4482 |
|
|
the entire section. */
|
4483 |
|
|
sec->has_tls_reloc = 0;
|
4484 |
|
|
break;
|
4485 |
|
|
}
|
4486 |
|
|
|
4487 |
|
|
if (h != NULL)
|
4488 |
|
|
{
|
4489 |
|
|
tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
|
4490 |
|
|
got_count = &h->got.refcount;
|
4491 |
|
|
}
|
4492 |
|
|
else
|
4493 |
|
|
{
|
4494 |
|
|
Elf_Internal_Sym *sym;
|
4495 |
|
|
bfd_signed_vma *lgot_refs;
|
4496 |
|
|
char *lgot_masks;
|
4497 |
|
|
|
4498 |
|
|
if (locsyms == NULL)
|
4499 |
|
|
{
|
4500 |
|
|
locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
|
4501 |
|
|
if (locsyms == NULL)
|
4502 |
|
|
locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
|
4503 |
|
|
symtab_hdr->sh_info,
|
4504 |
|
|
0, NULL, NULL, NULL);
|
4505 |
|
|
if (locsyms == NULL)
|
4506 |
|
|
{
|
4507 |
|
|
if (elf_section_data (sec)->relocs != relstart)
|
4508 |
|
|
free (relstart);
|
4509 |
|
|
return FALSE;
|
4510 |
|
|
}
|
4511 |
|
|
}
|
4512 |
|
|
sym = locsyms + r_symndx;
|
4513 |
|
|
lgot_refs = elf_local_got_refcounts (ibfd);
|
4514 |
|
|
if (lgot_refs == NULL)
|
4515 |
|
|
abort ();
|
4516 |
|
|
lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
|
4517 |
|
|
tls_mask = &lgot_masks[r_symndx];
|
4518 |
|
|
got_count = &lgot_refs[r_symndx];
|
4519 |
|
|
}
|
4520 |
|
|
|
4521 |
|
|
if (tls_set == 0)
|
4522 |
|
|
{
|
4523 |
|
|
/* We managed to get rid of a got entry. */
|
4524 |
|
|
if (*got_count > 0)
|
4525 |
|
|
*got_count -= 1;
|
4526 |
|
|
}
|
4527 |
|
|
|
4528 |
|
|
if (expecting_tls_get_addr)
|
4529 |
|
|
{
|
4530 |
|
|
struct plt_entry *ent;
|
4531 |
|
|
|
4532 |
|
|
ent = find_plt_ent (htab->tls_get_addr, NULL, 0);
|
4533 |
|
|
if (ent != NULL && ent->plt.refcount > 0)
|
4534 |
|
|
ent->plt.refcount -= 1;
|
4535 |
|
|
}
|
4536 |
|
|
|
4537 |
|
|
*tls_mask |= tls_set;
|
4538 |
|
|
*tls_mask &= ~tls_clear;
|
4539 |
|
|
}
|
4540 |
|
|
|
4541 |
|
|
if (elf_section_data (sec)->relocs != relstart)
|
4542 |
|
|
free (relstart);
|
4543 |
|
|
}
|
4544 |
|
|
|
4545 |
|
|
if (locsyms != NULL
|
4546 |
|
|
&& (symtab_hdr->contents != (unsigned char *) locsyms))
|
4547 |
|
|
{
|
4548 |
|
|
if (!info->keep_memory)
|
4549 |
|
|
free (locsyms);
|
4550 |
|
|
else
|
4551 |
|
|
symtab_hdr->contents = (unsigned char *) locsyms;
|
4552 |
|
|
}
|
4553 |
|
|
}
|
4554 |
|
|
return TRUE;
|
4555 |
|
|
}
|
4556 |
|
|
|
4557 |
|
|
/* Return true if we have dynamic relocs that apply to read-only sections. */
|
4558 |
|
|
|
4559 |
|
|
static bfd_boolean
|
4560 |
|
|
readonly_dynrelocs (struct elf_link_hash_entry *h)
|
4561 |
|
|
{
|
4562 |
|
|
struct ppc_elf_dyn_relocs *p;
|
4563 |
|
|
|
4564 |
|
|
for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
|
4565 |
|
|
{
|
4566 |
|
|
asection *s = p->sec->output_section;
|
4567 |
|
|
|
4568 |
|
|
if (s != NULL
|
4569 |
|
|
&& ((s->flags & (SEC_READONLY | SEC_ALLOC))
|
4570 |
|
|
== (SEC_READONLY | SEC_ALLOC)))
|
4571 |
|
|
return TRUE;
|
4572 |
|
|
}
|
4573 |
|
|
return FALSE;
|
4574 |
|
|
}
|
4575 |
|
|
|
4576 |
|
|
/* Adjust a symbol defined by a dynamic object and referenced by a
|
4577 |
|
|
regular object. The current definition is in some section of the
|
4578 |
|
|
dynamic object, but we're not including those sections. We have to
|
4579 |
|
|
change the definition to something the rest of the link can
|
4580 |
|
|
understand. */
|
4581 |
|
|
|
4582 |
|
|
static bfd_boolean
|
4583 |
|
|
ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
|
4584 |
|
|
struct elf_link_hash_entry *h)
|
4585 |
|
|
{
|
4586 |
|
|
struct ppc_elf_link_hash_table *htab;
|
4587 |
|
|
asection *s;
|
4588 |
|
|
|
4589 |
|
|
#ifdef DEBUG
|
4590 |
|
|
fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
|
4591 |
|
|
h->root.root.string);
|
4592 |
|
|
#endif
|
4593 |
|
|
|
4594 |
|
|
/* Make sure we know what is going on here. */
|
4595 |
|
|
htab = ppc_elf_hash_table (info);
|
4596 |
|
|
BFD_ASSERT (htab->elf.dynobj != NULL
|
4597 |
|
|
&& (h->needs_plt
|
4598 |
|
|
|| h->u.weakdef != NULL
|
4599 |
|
|
|| (h->def_dynamic
|
4600 |
|
|
&& h->ref_regular
|
4601 |
|
|
&& !h->def_regular)));
|
4602 |
|
|
|
4603 |
|
|
/* Deal with function syms. */
|
4604 |
|
|
if (h->type == STT_FUNC
|
4605 |
|
|
|| h->needs_plt)
|
4606 |
|
|
{
|
4607 |
|
|
/* Clear procedure linkage table information for any symbol that
|
4608 |
|
|
won't need a .plt entry. */
|
4609 |
|
|
struct plt_entry *ent;
|
4610 |
|
|
for (ent = h->plt.plist; ent != NULL; ent = ent->next)
|
4611 |
|
|
if (ent->plt.refcount > 0)
|
4612 |
|
|
break;
|
4613 |
|
|
if (ent == NULL
|
4614 |
|
|
|| SYMBOL_CALLS_LOCAL (info, h)
|
4615 |
|
|
|| (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
|
4616 |
|
|
&& h->root.type == bfd_link_hash_undefweak))
|
4617 |
|
|
{
|
4618 |
|
|
/* A PLT entry is not required/allowed when:
|
4619 |
|
|
|
4620 |
|
|
1. We are not using ld.so; because then the PLT entry
|
4621 |
|
|
can't be set up, so we can't use one. In this case,
|
4622 |
|
|
ppc_elf_adjust_dynamic_symbol won't even be called.
|
4623 |
|
|
|
4624 |
|
|
2. GC has rendered the entry unused.
|
4625 |
|
|
|
4626 |
|
|
3. We know for certain that a call to this symbol
|
4627 |
|
|
will go to this object, or will remain undefined. */
|
4628 |
|
|
h->plt.plist = NULL;
|
4629 |
|
|
h->needs_plt = 0;
|
4630 |
|
|
}
|
4631 |
|
|
else
|
4632 |
|
|
{
|
4633 |
|
|
/* After adjust_dynamic_symbol, non_got_ref set means that
|
4634 |
|
|
dyn_relocs for this symbol should be discarded.
|
4635 |
|
|
If we get here we know we are making a PLT entry for this
|
4636 |
|
|
symbol, and in an executable we'd normally resolve
|
4637 |
|
|
relocations against this symbol to the PLT entry. Allow
|
4638 |
|
|
dynamic relocs if the reference is weak, and the dynamic
|
4639 |
|
|
relocs will not cause text relocation. */
|
4640 |
|
|
if (!h->ref_regular_nonweak
|
4641 |
|
|
&& h->non_got_ref
|
4642 |
|
|
&& !htab->is_vxworks
|
4643 |
|
|
&& !ppc_elf_hash_entry (h)->has_sda_refs
|
4644 |
|
|
&& !readonly_dynrelocs (h))
|
4645 |
|
|
h->non_got_ref = 0;
|
4646 |
|
|
}
|
4647 |
|
|
return TRUE;
|
4648 |
|
|
}
|
4649 |
|
|
else
|
4650 |
|
|
h->plt.plist = NULL;
|
4651 |
|
|
|
4652 |
|
|
/* If this is a weak symbol, and there is a real definition, the
|
4653 |
|
|
processor independent code will have arranged for us to see the
|
4654 |
|
|
real definition first, and we can just use the same value. */
|
4655 |
|
|
if (h->u.weakdef != NULL)
|
4656 |
|
|
{
|
4657 |
|
|
BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
|
4658 |
|
|
|| h->u.weakdef->root.type == bfd_link_hash_defweak);
|
4659 |
|
|
h->root.u.def.section = h->u.weakdef->root.u.def.section;
|
4660 |
|
|
h->root.u.def.value = h->u.weakdef->root.u.def.value;
|
4661 |
|
|
if (ELIMINATE_COPY_RELOCS)
|
4662 |
|
|
h->non_got_ref = h->u.weakdef->non_got_ref;
|
4663 |
|
|
return TRUE;
|
4664 |
|
|
}
|
4665 |
|
|
|
4666 |
|
|
/* This is a reference to a symbol defined by a dynamic object which
|
4667 |
|
|
is not a function. */
|
4668 |
|
|
|
4669 |
|
|
/* If we are creating a shared library, we must presume that the
|
4670 |
|
|
only references to the symbol are via the global offset table.
|
4671 |
|
|
For such cases we need not do anything here; the relocations will
|
4672 |
|
|
be handled correctly by relocate_section. */
|
4673 |
|
|
if (info->shared)
|
4674 |
|
|
return TRUE;
|
4675 |
|
|
|
4676 |
|
|
/* If there are no references to this symbol that do not use the
|
4677 |
|
|
GOT, we don't need to generate a copy reloc. */
|
4678 |
|
|
if (!h->non_got_ref)
|
4679 |
|
|
return TRUE;
|
4680 |
|
|
|
4681 |
|
|
/* If we didn't find any dynamic relocs in read-only sections, then
|
4682 |
|
|
we'll be keeping the dynamic relocs and avoiding the copy reloc.
|
4683 |
|
|
We can't do this if there are any small data relocations. This
|
4684 |
|
|
doesn't work on VxWorks, where we can not have dynamic
|
4685 |
|
|
relocations (other than copy and jump slot relocations) in an
|
4686 |
|
|
executable. */
|
4687 |
|
|
if (ELIMINATE_COPY_RELOCS
|
4688 |
|
|
&& !ppc_elf_hash_entry (h)->has_sda_refs
|
4689 |
|
|
&& !htab->is_vxworks
|
4690 |
|
|
&& !h->def_regular
|
4691 |
|
|
&& !readonly_dynrelocs (h))
|
4692 |
|
|
{
|
4693 |
|
|
h->non_got_ref = 0;
|
4694 |
|
|
return TRUE;
|
4695 |
|
|
}
|
4696 |
|
|
|
4697 |
|
|
if (h->size == 0)
|
4698 |
|
|
{
|
4699 |
|
|
(*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
|
4700 |
|
|
h->root.root.string);
|
4701 |
|
|
return TRUE;
|
4702 |
|
|
}
|
4703 |
|
|
|
4704 |
|
|
/* We must allocate the symbol in our .dynbss section, which will
|
4705 |
|
|
become part of the .bss section of the executable. There will be
|
4706 |
|
|
an entry for this symbol in the .dynsym section. The dynamic
|
4707 |
|
|
object will contain position independent code, so all references
|
4708 |
|
|
from the dynamic object to this symbol will go through the global
|
4709 |
|
|
offset table. The dynamic linker will use the .dynsym entry to
|
4710 |
|
|
determine the address it must put in the global offset table, so
|
4711 |
|
|
both the dynamic object and the regular object will refer to the
|
4712 |
|
|
same memory location for the variable.
|
4713 |
|
|
|
4714 |
|
|
Of course, if the symbol is referenced using SDAREL relocs, we
|
4715 |
|
|
must instead allocate it in .sbss. */
|
4716 |
|
|
|
4717 |
|
|
if (ppc_elf_hash_entry (h)->has_sda_refs)
|
4718 |
|
|
s = htab->dynsbss;
|
4719 |
|
|
else
|
4720 |
|
|
s = htab->dynbss;
|
4721 |
|
|
BFD_ASSERT (s != NULL);
|
4722 |
|
|
|
4723 |
|
|
/* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
|
4724 |
|
|
copy the initial value out of the dynamic object and into the
|
4725 |
|
|
runtime process image. We need to remember the offset into the
|
4726 |
|
|
.rela.bss section we are going to use. */
|
4727 |
|
|
if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
|
4728 |
|
|
{
|
4729 |
|
|
asection *srel;
|
4730 |
|
|
|
4731 |
|
|
if (ppc_elf_hash_entry (h)->has_sda_refs)
|
4732 |
|
|
srel = htab->relsbss;
|
4733 |
|
|
else
|
4734 |
|
|
srel = htab->relbss;
|
4735 |
|
|
BFD_ASSERT (srel != NULL);
|
4736 |
|
|
srel->size += sizeof (Elf32_External_Rela);
|
4737 |
|
|
h->needs_copy = 1;
|
4738 |
|
|
}
|
4739 |
|
|
|
4740 |
|
|
return _bfd_elf_adjust_dynamic_copy (h, s);
|
4741 |
|
|
}
|
4742 |
|
|
|
4743 |
|
|
/* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
|
4744 |
|
|
xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
|
4745 |
|
|
specifying the addend on the plt relocation. For -fpic code, the sym
|
4746 |
|
|
is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
|
4747 |
|
|
xxxxxxxx.got2.plt_pic32.<callee>. */
|
4748 |
|
|
|
4749 |
|
|
static bfd_boolean
|
4750 |
|
|
add_stub_sym (struct plt_entry *ent,
|
4751 |
|
|
struct elf_link_hash_entry *h,
|
4752 |
|
|
struct bfd_link_info *info)
|
4753 |
|
|
{
|
4754 |
|
|
struct elf_link_hash_entry *sh;
|
4755 |
|
|
size_t len1, len2, len3;
|
4756 |
|
|
char *name;
|
4757 |
|
|
const char *stub;
|
4758 |
|
|
struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
|
4759 |
|
|
|
4760 |
|
|
if (info->shared || info->pie)
|
4761 |
|
|
stub = ".plt_pic32.";
|
4762 |
|
|
else
|
4763 |
|
|
stub = ".plt_call32.";
|
4764 |
|
|
|
4765 |
|
|
len1 = strlen (h->root.root.string);
|
4766 |
|
|
len2 = strlen (stub);
|
4767 |
|
|
len3 = 0;
|
4768 |
|
|
if (ent->sec)
|
4769 |
|
|
len3 = strlen (ent->sec->name);
|
4770 |
|
|
name = bfd_malloc (len1 + len2 + len3 + 9);
|
4771 |
|
|
if (name == NULL)
|
4772 |
|
|
return FALSE;
|
4773 |
|
|
sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
|
4774 |
|
|
if (ent->sec)
|
4775 |
|
|
memcpy (name + 8, ent->sec->name, len3);
|
4776 |
|
|
memcpy (name + 8 + len3, stub, len2);
|
4777 |
|
|
memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
|
4778 |
|
|
sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
|
4779 |
|
|
if (sh == NULL)
|
4780 |
|
|
return FALSE;
|
4781 |
|
|
if (sh->root.type == bfd_link_hash_new)
|
4782 |
|
|
{
|
4783 |
|
|
sh->root.type = bfd_link_hash_defined;
|
4784 |
|
|
sh->root.u.def.section = htab->glink;
|
4785 |
|
|
sh->root.u.def.value = ent->glink_offset;
|
4786 |
|
|
sh->ref_regular = 1;
|
4787 |
|
|
sh->def_regular = 1;
|
4788 |
|
|
sh->ref_regular_nonweak = 1;
|
4789 |
|
|
sh->forced_local = 1;
|
4790 |
|
|
sh->non_elf = 0;
|
4791 |
|
|
}
|
4792 |
|
|
return TRUE;
|
4793 |
|
|
}
|
4794 |
|
|
|
4795 |
|
|
/* Allocate NEED contiguous space in .got, and return the offset.
|
4796 |
|
|
Handles allocation of the got header when crossing 32k. */
|
4797 |
|
|
|
4798 |
|
|
static bfd_vma
|
4799 |
|
|
allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
|
4800 |
|
|
{
|
4801 |
|
|
bfd_vma where;
|
4802 |
|
|
unsigned int max_before_header;
|
4803 |
|
|
|
4804 |
|
|
if (htab->plt_type == PLT_VXWORKS)
|
4805 |
|
|
{
|
4806 |
|
|
where = htab->got->size;
|
4807 |
|
|
htab->got->size += need;
|
4808 |
|
|
}
|
4809 |
|
|
else
|
4810 |
|
|
{
|
4811 |
|
|
max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
|
4812 |
|
|
if (need <= htab->got_gap)
|
4813 |
|
|
{
|
4814 |
|
|
where = max_before_header - htab->got_gap;
|
4815 |
|
|
htab->got_gap -= need;
|
4816 |
|
|
}
|
4817 |
|
|
else
|
4818 |
|
|
{
|
4819 |
|
|
if (htab->got->size + need > max_before_header
|
4820 |
|
|
&& htab->got->size <= max_before_header)
|
4821 |
|
|
{
|
4822 |
|
|
htab->got_gap = max_before_header - htab->got->size;
|
4823 |
|
|
htab->got->size = max_before_header + htab->got_header_size;
|
4824 |
|
|
}
|
4825 |
|
|
where = htab->got->size;
|
4826 |
|
|
htab->got->size += need;
|
4827 |
|
|
}
|
4828 |
|
|
}
|
4829 |
|
|
return where;
|
4830 |
|
|
}
|
4831 |
|
|
|
4832 |
|
|
/* Allocate space in associated reloc sections for dynamic relocs. */
|
4833 |
|
|
|
4834 |
|
|
static bfd_boolean
|
4835 |
|
|
allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
|
4836 |
|
|
{
|
4837 |
|
|
struct bfd_link_info *info = inf;
|
4838 |
|
|
struct ppc_elf_link_hash_entry *eh;
|
4839 |
|
|
struct ppc_elf_link_hash_table *htab;
|
4840 |
|
|
struct ppc_elf_dyn_relocs *p;
|
4841 |
|
|
|
4842 |
|
|
if (h->root.type == bfd_link_hash_indirect)
|
4843 |
|
|
return TRUE;
|
4844 |
|
|
|
4845 |
|
|
if (h->root.type == bfd_link_hash_warning)
|
4846 |
|
|
/* When warning symbols are created, they **replace** the "real"
|
4847 |
|
|
entry in the hash table, thus we never get to see the real
|
4848 |
|
|
symbol in a hash traversal. So look at it now. */
|
4849 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
4850 |
|
|
|
4851 |
|
|
htab = ppc_elf_hash_table (info);
|
4852 |
|
|
if (htab->elf.dynamic_sections_created)
|
4853 |
|
|
{
|
4854 |
|
|
struct plt_entry *ent;
|
4855 |
|
|
bfd_boolean doneone = FALSE;
|
4856 |
|
|
bfd_vma plt_offset = 0, glink_offset = 0;
|
4857 |
|
|
|
4858 |
|
|
for (ent = h->plt.plist; ent != NULL; ent = ent->next)
|
4859 |
|
|
if (ent->plt.refcount > 0)
|
4860 |
|
|
{
|
4861 |
|
|
/* Make sure this symbol is output as a dynamic symbol. */
|
4862 |
|
|
if (h->dynindx == -1
|
4863 |
|
|
&& !h->forced_local)
|
4864 |
|
|
{
|
4865 |
|
|
if (! bfd_elf_link_record_dynamic_symbol (info, h))
|
4866 |
|
|
return FALSE;
|
4867 |
|
|
}
|
4868 |
|
|
|
4869 |
|
|
if (info->shared
|
4870 |
|
|
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
|
4871 |
|
|
{
|
4872 |
|
|
asection *s = htab->plt;
|
4873 |
|
|
|
4874 |
|
|
if (htab->plt_type == PLT_NEW)
|
4875 |
|
|
{
|
4876 |
|
|
if (!doneone)
|
4877 |
|
|
{
|
4878 |
|
|
plt_offset = s->size;
|
4879 |
|
|
s->size += 4;
|
4880 |
|
|
}
|
4881 |
|
|
ent->plt.offset = plt_offset;
|
4882 |
|
|
|
4883 |
|
|
s = htab->glink;
|
4884 |
|
|
if (!doneone || info->shared || info->pie)
|
4885 |
|
|
{
|
4886 |
|
|
glink_offset = s->size;
|
4887 |
|
|
s->size += GLINK_ENTRY_SIZE;
|
4888 |
|
|
}
|
4889 |
|
|
if (!doneone
|
4890 |
|
|
&& !info->shared
|
4891 |
|
|
&& h->def_dynamic
|
4892 |
|
|
&& !h->def_regular)
|
4893 |
|
|
{
|
4894 |
|
|
h->root.u.def.section = s;
|
4895 |
|
|
h->root.u.def.value = glink_offset;
|
4896 |
|
|
}
|
4897 |
|
|
ent->glink_offset = glink_offset;
|
4898 |
|
|
|
4899 |
|
|
if (htab->emit_stub_syms
|
4900 |
|
|
&& !add_stub_sym (ent, h, info))
|
4901 |
|
|
return FALSE;
|
4902 |
|
|
}
|
4903 |
|
|
else
|
4904 |
|
|
{
|
4905 |
|
|
if (!doneone)
|
4906 |
|
|
{
|
4907 |
|
|
/* If this is the first .plt entry, make room
|
4908 |
|
|
for the special first entry. */
|
4909 |
|
|
if (s->size == 0)
|
4910 |
|
|
s->size += htab->plt_initial_entry_size;
|
4911 |
|
|
|
4912 |
|
|
/* The PowerPC PLT is actually composed of two
|
4913 |
|
|
parts, the first part is 2 words (for a load
|
4914 |
|
|
and a jump), and then there is a remaining
|
4915 |
|
|
word available at the end. */
|
4916 |
|
|
plt_offset = (htab->plt_initial_entry_size
|
4917 |
|
|
+ (htab->plt_slot_size
|
4918 |
|
|
* ((s->size
|
4919 |
|
|
- htab->plt_initial_entry_size)
|
4920 |
|
|
/ htab->plt_entry_size)));
|
4921 |
|
|
|
4922 |
|
|
/* If this symbol is not defined in a regular
|
4923 |
|
|
file, and we are not generating a shared
|
4924 |
|
|
library, then set the symbol to this location
|
4925 |
|
|
in the .plt. This is required to make
|
4926 |
|
|
function pointers compare as equal between
|
4927 |
|
|
the normal executable and the shared library. */
|
4928 |
|
|
if (! info->shared
|
4929 |
|
|
&& h->def_dynamic
|
4930 |
|
|
&& !h->def_regular)
|
4931 |
|
|
{
|
4932 |
|
|
h->root.u.def.section = s;
|
4933 |
|
|
h->root.u.def.value = plt_offset;
|
4934 |
|
|
}
|
4935 |
|
|
|
4936 |
|
|
/* Make room for this entry. */
|
4937 |
|
|
s->size += htab->plt_entry_size;
|
4938 |
|
|
/* After the 8192nd entry, room for two entries
|
4939 |
|
|
is allocated. */
|
4940 |
|
|
if (htab->plt_type == PLT_OLD
|
4941 |
|
|
&& (s->size - htab->plt_initial_entry_size)
|
4942 |
|
|
/ htab->plt_entry_size
|
4943 |
|
|
> PLT_NUM_SINGLE_ENTRIES)
|
4944 |
|
|
s->size += htab->plt_entry_size;
|
4945 |
|
|
}
|
4946 |
|
|
ent->plt.offset = plt_offset;
|
4947 |
|
|
}
|
4948 |
|
|
|
4949 |
|
|
/* We also need to make an entry in the .rela.plt section. */
|
4950 |
|
|
if (!doneone)
|
4951 |
|
|
{
|
4952 |
|
|
htab->relplt->size += sizeof (Elf32_External_Rela);
|
4953 |
|
|
|
4954 |
|
|
if (htab->plt_type == PLT_VXWORKS)
|
4955 |
|
|
{
|
4956 |
|
|
/* Allocate space for the unloaded relocations. */
|
4957 |
|
|
if (!info->shared)
|
4958 |
|
|
{
|
4959 |
|
|
if (ent->plt.offset
|
4960 |
|
|
== (bfd_vma) htab->plt_initial_entry_size)
|
4961 |
|
|
{
|
4962 |
|
|
htab->srelplt2->size
|
4963 |
|
|
+= sizeof (Elf32_External_Rela)
|
4964 |
|
|
* VXWORKS_PLTRESOLVE_RELOCS;
|
4965 |
|
|
}
|
4966 |
|
|
|
4967 |
|
|
htab->srelplt2->size
|
4968 |
|
|
+= sizeof (Elf32_External_Rela)
|
4969 |
|
|
* VXWORKS_PLT_NON_JMP_SLOT_RELOCS;
|
4970 |
|
|
}
|
4971 |
|
|
|
4972 |
|
|
/* Every PLT entry has an associated GOT entry in
|
4973 |
|
|
.got.plt. */
|
4974 |
|
|
htab->sgotplt->size += 4;
|
4975 |
|
|
}
|
4976 |
|
|
doneone = TRUE;
|
4977 |
|
|
}
|
4978 |
|
|
}
|
4979 |
|
|
else
|
4980 |
|
|
ent->plt.offset = (bfd_vma) -1;
|
4981 |
|
|
}
|
4982 |
|
|
else
|
4983 |
|
|
ent->plt.offset = (bfd_vma) -1;
|
4984 |
|
|
|
4985 |
|
|
if (!doneone)
|
4986 |
|
|
{
|
4987 |
|
|
h->plt.plist = NULL;
|
4988 |
|
|
h->needs_plt = 0;
|
4989 |
|
|
}
|
4990 |
|
|
}
|
4991 |
|
|
else
|
4992 |
|
|
{
|
4993 |
|
|
h->plt.plist = NULL;
|
4994 |
|
|
h->needs_plt = 0;
|
4995 |
|
|
}
|
4996 |
|
|
|
4997 |
|
|
eh = (struct ppc_elf_link_hash_entry *) h;
|
4998 |
|
|
if (eh->elf.got.refcount > 0)
|
4999 |
|
|
{
|
5000 |
|
|
bfd_boolean dyn;
|
5001 |
|
|
unsigned int need;
|
5002 |
|
|
|
5003 |
|
|
/* Make sure this symbol is output as a dynamic symbol. */
|
5004 |
|
|
if (eh->elf.dynindx == -1
|
5005 |
|
|
&& !eh->elf.forced_local
|
5006 |
|
|
&& htab->elf.dynamic_sections_created)
|
5007 |
|
|
{
|
5008 |
|
|
if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
|
5009 |
|
|
return FALSE;
|
5010 |
|
|
}
|
5011 |
|
|
|
5012 |
|
|
need = 0;
|
5013 |
|
|
if ((eh->tls_mask & TLS_TLS) != 0)
|
5014 |
|
|
{
|
5015 |
|
|
if ((eh->tls_mask & TLS_LD) != 0)
|
5016 |
|
|
{
|
5017 |
|
|
if (!eh->elf.def_dynamic)
|
5018 |
|
|
/* We'll just use htab->tlsld_got.offset. This should
|
5019 |
|
|
always be the case. It's a little odd if we have
|
5020 |
|
|
a local dynamic reloc against a non-local symbol. */
|
5021 |
|
|
htab->tlsld_got.refcount += 1;
|
5022 |
|
|
else
|
5023 |
|
|
need += 8;
|
5024 |
|
|
}
|
5025 |
|
|
if ((eh->tls_mask & TLS_GD) != 0)
|
5026 |
|
|
need += 8;
|
5027 |
|
|
if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
|
5028 |
|
|
need += 4;
|
5029 |
|
|
if ((eh->tls_mask & TLS_DTPREL) != 0)
|
5030 |
|
|
need += 4;
|
5031 |
|
|
}
|
5032 |
|
|
else
|
5033 |
|
|
need += 4;
|
5034 |
|
|
if (need == 0)
|
5035 |
|
|
eh->elf.got.offset = (bfd_vma) -1;
|
5036 |
|
|
else
|
5037 |
|
|
{
|
5038 |
|
|
eh->elf.got.offset = allocate_got (htab, need);
|
5039 |
|
|
dyn = htab->elf.dynamic_sections_created;
|
5040 |
|
|
if ((info->shared
|
5041 |
|
|
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
|
5042 |
|
|
&& (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
|
5043 |
|
|
|| eh->elf.root.type != bfd_link_hash_undefweak))
|
5044 |
|
|
{
|
5045 |
|
|
/* All the entries we allocated need relocs.
|
5046 |
|
|
Except LD only needs one. */
|
5047 |
|
|
if ((eh->tls_mask & TLS_LD) != 0
|
5048 |
|
|
&& eh->elf.def_dynamic)
|
5049 |
|
|
need -= 4;
|
5050 |
|
|
htab->relgot->size += need * (sizeof (Elf32_External_Rela) / 4);
|
5051 |
|
|
}
|
5052 |
|
|
}
|
5053 |
|
|
}
|
5054 |
|
|
else
|
5055 |
|
|
eh->elf.got.offset = (bfd_vma) -1;
|
5056 |
|
|
|
5057 |
|
|
if (eh->dyn_relocs == NULL
|
5058 |
|
|
|| !htab->elf.dynamic_sections_created)
|
5059 |
|
|
return TRUE;
|
5060 |
|
|
|
5061 |
|
|
/* In the shared -Bsymbolic case, discard space allocated for
|
5062 |
|
|
dynamic pc-relative relocs against symbols which turn out to be
|
5063 |
|
|
defined in regular objects. For the normal shared case, discard
|
5064 |
|
|
space for relocs that have become local due to symbol visibility
|
5065 |
|
|
changes. */
|
5066 |
|
|
|
5067 |
|
|
if (info->shared)
|
5068 |
|
|
{
|
5069 |
|
|
/* Relocs that use pc_count are those that appear on a call insn,
|
5070 |
|
|
or certain REL relocs (see must_be_dyn_reloc) that can be
|
5071 |
|
|
generated via assembly. We want calls to protected symbols to
|
5072 |
|
|
resolve directly to the function rather than going via the plt.
|
5073 |
|
|
If people want function pointer comparisons to work as expected
|
5074 |
|
|
then they should avoid writing weird assembly. */
|
5075 |
|
|
if (SYMBOL_CALLS_LOCAL (info, h))
|
5076 |
|
|
{
|
5077 |
|
|
struct ppc_elf_dyn_relocs **pp;
|
5078 |
|
|
|
5079 |
|
|
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
|
5080 |
|
|
{
|
5081 |
|
|
p->count -= p->pc_count;
|
5082 |
|
|
p->pc_count = 0;
|
5083 |
|
|
if (p->count == 0)
|
5084 |
|
|
*pp = p->next;
|
5085 |
|
|
else
|
5086 |
|
|
pp = &p->next;
|
5087 |
|
|
}
|
5088 |
|
|
}
|
5089 |
|
|
|
5090 |
|
|
if (htab->is_vxworks)
|
5091 |
|
|
{
|
5092 |
|
|
struct ppc_elf_dyn_relocs **pp;
|
5093 |
|
|
|
5094 |
|
|
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
|
5095 |
|
|
{
|
5096 |
|
|
if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
|
5097 |
|
|
*pp = p->next;
|
5098 |
|
|
else
|
5099 |
|
|
pp = &p->next;
|
5100 |
|
|
}
|
5101 |
|
|
}
|
5102 |
|
|
|
5103 |
|
|
/* Discard relocs on undefined symbols that must be local. */
|
5104 |
|
|
if (eh->dyn_relocs != NULL
|
5105 |
|
|
&& h->root.type == bfd_link_hash_undefined
|
5106 |
|
|
&& (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
|
5107 |
|
|
|| ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
|
5108 |
|
|
eh->dyn_relocs = NULL;
|
5109 |
|
|
|
5110 |
|
|
/* Also discard relocs on undefined weak syms with non-default
|
5111 |
|
|
visibility. */
|
5112 |
|
|
if (eh->dyn_relocs != NULL
|
5113 |
|
|
&& h->root.type == bfd_link_hash_undefweak)
|
5114 |
|
|
{
|
5115 |
|
|
if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
|
5116 |
|
|
eh->dyn_relocs = NULL;
|
5117 |
|
|
|
5118 |
|
|
/* Make sure undefined weak symbols are output as a dynamic
|
5119 |
|
|
symbol in PIEs. */
|
5120 |
|
|
else if (h->dynindx == -1
|
5121 |
|
|
&& !h->forced_local)
|
5122 |
|
|
{
|
5123 |
|
|
if (! bfd_elf_link_record_dynamic_symbol (info, h))
|
5124 |
|
|
return FALSE;
|
5125 |
|
|
}
|
5126 |
|
|
}
|
5127 |
|
|
}
|
5128 |
|
|
else if (ELIMINATE_COPY_RELOCS)
|
5129 |
|
|
{
|
5130 |
|
|
/* For the non-shared case, discard space for relocs against
|
5131 |
|
|
symbols which turn out to need copy relocs or are not
|
5132 |
|
|
dynamic. */
|
5133 |
|
|
|
5134 |
|
|
if (!h->non_got_ref
|
5135 |
|
|
&& !h->def_regular)
|
5136 |
|
|
{
|
5137 |
|
|
/* Make sure this symbol is output as a dynamic symbol.
|
5138 |
|
|
Undefined weak syms won't yet be marked as dynamic. */
|
5139 |
|
|
if (h->dynindx == -1
|
5140 |
|
|
&& !h->forced_local)
|
5141 |
|
|
{
|
5142 |
|
|
if (! bfd_elf_link_record_dynamic_symbol (info, h))
|
5143 |
|
|
return FALSE;
|
5144 |
|
|
}
|
5145 |
|
|
|
5146 |
|
|
/* If that succeeded, we know we'll be keeping all the
|
5147 |
|
|
relocs. */
|
5148 |
|
|
if (h->dynindx != -1)
|
5149 |
|
|
goto keep;
|
5150 |
|
|
}
|
5151 |
|
|
|
5152 |
|
|
eh->dyn_relocs = NULL;
|
5153 |
|
|
|
5154 |
|
|
keep: ;
|
5155 |
|
|
}
|
5156 |
|
|
|
5157 |
|
|
/* Finally, allocate space. */
|
5158 |
|
|
for (p = eh->dyn_relocs; p != NULL; p = p->next)
|
5159 |
|
|
{
|
5160 |
|
|
asection *sreloc = elf_section_data (p->sec)->sreloc;
|
5161 |
|
|
sreloc->size += p->count * sizeof (Elf32_External_Rela);
|
5162 |
|
|
}
|
5163 |
|
|
|
5164 |
|
|
return TRUE;
|
5165 |
|
|
}
|
5166 |
|
|
|
5167 |
|
|
/* Set DF_TEXTREL if we find any dynamic relocs that apply to
|
5168 |
|
|
read-only sections. */
|
5169 |
|
|
|
5170 |
|
|
static bfd_boolean
|
5171 |
|
|
maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
|
5172 |
|
|
{
|
5173 |
|
|
if (h->root.type == bfd_link_hash_indirect)
|
5174 |
|
|
return TRUE;
|
5175 |
|
|
|
5176 |
|
|
if (h->root.type == bfd_link_hash_warning)
|
5177 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
5178 |
|
|
|
5179 |
|
|
if (readonly_dynrelocs (h))
|
5180 |
|
|
{
|
5181 |
|
|
((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
|
5182 |
|
|
|
5183 |
|
|
/* Not an error, just cut short the traversal. */
|
5184 |
|
|
return FALSE;
|
5185 |
|
|
}
|
5186 |
|
|
return TRUE;
|
5187 |
|
|
}
|
5188 |
|
|
|
5189 |
|
|
/* Set the sizes of the dynamic sections. */
|
5190 |
|
|
|
5191 |
|
|
static bfd_boolean
|
5192 |
|
|
ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
|
5193 |
|
|
struct bfd_link_info *info)
|
5194 |
|
|
{
|
5195 |
|
|
struct ppc_elf_link_hash_table *htab;
|
5196 |
|
|
asection *s;
|
5197 |
|
|
bfd_boolean relocs;
|
5198 |
|
|
bfd *ibfd;
|
5199 |
|
|
|
5200 |
|
|
#ifdef DEBUG
|
5201 |
|
|
fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
|
5202 |
|
|
#endif
|
5203 |
|
|
|
5204 |
|
|
htab = ppc_elf_hash_table (info);
|
5205 |
|
|
BFD_ASSERT (htab->elf.dynobj != NULL);
|
5206 |
|
|
|
5207 |
|
|
if (elf_hash_table (info)->dynamic_sections_created)
|
5208 |
|
|
{
|
5209 |
|
|
/* Set the contents of the .interp section to the interpreter. */
|
5210 |
|
|
if (info->executable)
|
5211 |
|
|
{
|
5212 |
|
|
s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
|
5213 |
|
|
BFD_ASSERT (s != NULL);
|
5214 |
|
|
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
|
5215 |
|
|
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
|
5216 |
|
|
}
|
5217 |
|
|
}
|
5218 |
|
|
|
5219 |
|
|
if (htab->plt_type == PLT_OLD)
|
5220 |
|
|
htab->got_header_size = 16;
|
5221 |
|
|
else if (htab->plt_type == PLT_NEW)
|
5222 |
|
|
htab->got_header_size = 12;
|
5223 |
|
|
|
5224 |
|
|
/* Set up .got offsets for local syms, and space for local dynamic
|
5225 |
|
|
relocs. */
|
5226 |
|
|
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
|
5227 |
|
|
{
|
5228 |
|
|
bfd_signed_vma *local_got;
|
5229 |
|
|
bfd_signed_vma *end_local_got;
|
5230 |
|
|
char *lgot_masks;
|
5231 |
|
|
bfd_size_type locsymcount;
|
5232 |
|
|
Elf_Internal_Shdr *symtab_hdr;
|
5233 |
|
|
|
5234 |
|
|
if (!is_ppc_elf (ibfd))
|
5235 |
|
|
continue;
|
5236 |
|
|
|
5237 |
|
|
for (s = ibfd->sections; s != NULL; s = s->next)
|
5238 |
|
|
{
|
5239 |
|
|
struct ppc_elf_dyn_relocs *p;
|
5240 |
|
|
|
5241 |
|
|
for (p = ((struct ppc_elf_dyn_relocs *)
|
5242 |
|
|
elf_section_data (s)->local_dynrel);
|
5243 |
|
|
p != NULL;
|
5244 |
|
|
p = p->next)
|
5245 |
|
|
{
|
5246 |
|
|
if (!bfd_is_abs_section (p->sec)
|
5247 |
|
|
&& bfd_is_abs_section (p->sec->output_section))
|
5248 |
|
|
{
|
5249 |
|
|
/* Input section has been discarded, either because
|
5250 |
|
|
it is a copy of a linkonce section or due to
|
5251 |
|
|
linker script /DISCARD/, so we'll be discarding
|
5252 |
|
|
the relocs too. */
|
5253 |
|
|
}
|
5254 |
|
|
else if (htab->is_vxworks
|
5255 |
|
|
&& strcmp (p->sec->output_section->name,
|
5256 |
|
|
".tls_vars") == 0)
|
5257 |
|
|
{
|
5258 |
|
|
/* Relocations in vxworks .tls_vars sections are
|
5259 |
|
|
handled specially by the loader. */
|
5260 |
|
|
}
|
5261 |
|
|
else if (p->count != 0)
|
5262 |
|
|
{
|
5263 |
|
|
elf_section_data (p->sec)->sreloc->size
|
5264 |
|
|
+= p->count * sizeof (Elf32_External_Rela);
|
5265 |
|
|
if ((p->sec->output_section->flags
|
5266 |
|
|
& (SEC_READONLY | SEC_ALLOC))
|
5267 |
|
|
== (SEC_READONLY | SEC_ALLOC))
|
5268 |
|
|
info->flags |= DF_TEXTREL;
|
5269 |
|
|
}
|
5270 |
|
|
}
|
5271 |
|
|
}
|
5272 |
|
|
|
5273 |
|
|
local_got = elf_local_got_refcounts (ibfd);
|
5274 |
|
|
if (!local_got)
|
5275 |
|
|
continue;
|
5276 |
|
|
|
5277 |
|
|
symtab_hdr = &elf_symtab_hdr (ibfd);
|
5278 |
|
|
locsymcount = symtab_hdr->sh_info;
|
5279 |
|
|
end_local_got = local_got + locsymcount;
|
5280 |
|
|
lgot_masks = (char *) end_local_got;
|
5281 |
|
|
for (; local_got < end_local_got; ++local_got, ++lgot_masks)
|
5282 |
|
|
if (*local_got > 0)
|
5283 |
|
|
{
|
5284 |
|
|
unsigned int need = 0;
|
5285 |
|
|
if ((*lgot_masks & TLS_TLS) != 0)
|
5286 |
|
|
{
|
5287 |
|
|
if ((*lgot_masks & TLS_GD) != 0)
|
5288 |
|
|
need += 8;
|
5289 |
|
|
if ((*lgot_masks & TLS_LD) != 0)
|
5290 |
|
|
htab->tlsld_got.refcount += 1;
|
5291 |
|
|
if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
|
5292 |
|
|
need += 4;
|
5293 |
|
|
if ((*lgot_masks & TLS_DTPREL) != 0)
|
5294 |
|
|
need += 4;
|
5295 |
|
|
}
|
5296 |
|
|
else
|
5297 |
|
|
need += 4;
|
5298 |
|
|
if (need == 0)
|
5299 |
|
|
*local_got = (bfd_vma) -1;
|
5300 |
|
|
else
|
5301 |
|
|
{
|
5302 |
|
|
*local_got = allocate_got (htab, need);
|
5303 |
|
|
if (info->shared)
|
5304 |
|
|
htab->relgot->size += (need
|
5305 |
|
|
* (sizeof (Elf32_External_Rela) / 4));
|
5306 |
|
|
}
|
5307 |
|
|
}
|
5308 |
|
|
else
|
5309 |
|
|
*local_got = (bfd_vma) -1;
|
5310 |
|
|
}
|
5311 |
|
|
|
5312 |
|
|
/* Allocate space for global sym dynamic relocs. */
|
5313 |
|
|
elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
|
5314 |
|
|
|
5315 |
|
|
if (htab->tlsld_got.refcount > 0)
|
5316 |
|
|
{
|
5317 |
|
|
htab->tlsld_got.offset = allocate_got (htab, 8);
|
5318 |
|
|
if (info->shared)
|
5319 |
|
|
htab->relgot->size += sizeof (Elf32_External_Rela);
|
5320 |
|
|
}
|
5321 |
|
|
else
|
5322 |
|
|
htab->tlsld_got.offset = (bfd_vma) -1;
|
5323 |
|
|
|
5324 |
|
|
if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
|
5325 |
|
|
{
|
5326 |
|
|
unsigned int g_o_t = 32768;
|
5327 |
|
|
|
5328 |
|
|
/* If we haven't allocated the header, do so now. When we get here,
|
5329 |
|
|
for old plt/got the got size will be 0 to 32764 (not allocated),
|
5330 |
|
|
or 32780 to 65536 (header allocated). For new plt/got, the
|
5331 |
|
|
corresponding ranges are 0 to 32768 and 32780 to 65536. */
|
5332 |
|
|
if (htab->got->size <= 32768)
|
5333 |
|
|
{
|
5334 |
|
|
g_o_t = htab->got->size;
|
5335 |
|
|
if (htab->plt_type == PLT_OLD)
|
5336 |
|
|
g_o_t += 4;
|
5337 |
|
|
htab->got->size += htab->got_header_size;
|
5338 |
|
|
}
|
5339 |
|
|
|
5340 |
|
|
htab->elf.hgot->root.u.def.value = g_o_t;
|
5341 |
|
|
}
|
5342 |
|
|
|
5343 |
|
|
if (htab->glink != NULL && htab->glink->size != 0)
|
5344 |
|
|
{
|
5345 |
|
|
htab->glink_pltresolve = htab->glink->size;
|
5346 |
|
|
/* Space for the branch table. */
|
5347 |
|
|
htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
|
5348 |
|
|
/* Pad out to align the start of PLTresolve. */
|
5349 |
|
|
htab->glink->size += -htab->glink->size & 15;
|
5350 |
|
|
htab->glink->size += GLINK_PLTRESOLVE;
|
5351 |
|
|
|
5352 |
|
|
if (htab->emit_stub_syms)
|
5353 |
|
|
{
|
5354 |
|
|
struct elf_link_hash_entry *sh;
|
5355 |
|
|
sh = elf_link_hash_lookup (&htab->elf, "__glink",
|
5356 |
|
|
TRUE, FALSE, FALSE);
|
5357 |
|
|
if (sh == NULL)
|
5358 |
|
|
return FALSE;
|
5359 |
|
|
if (sh->root.type == bfd_link_hash_new)
|
5360 |
|
|
{
|
5361 |
|
|
sh->root.type = bfd_link_hash_defined;
|
5362 |
|
|
sh->root.u.def.section = htab->glink;
|
5363 |
|
|
sh->root.u.def.value = htab->glink_pltresolve;
|
5364 |
|
|
sh->ref_regular = 1;
|
5365 |
|
|
sh->def_regular = 1;
|
5366 |
|
|
sh->ref_regular_nonweak = 1;
|
5367 |
|
|
sh->forced_local = 1;
|
5368 |
|
|
sh->non_elf = 0;
|
5369 |
|
|
}
|
5370 |
|
|
sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
|
5371 |
|
|
TRUE, FALSE, FALSE);
|
5372 |
|
|
if (sh == NULL)
|
5373 |
|
|
return FALSE;
|
5374 |
|
|
if (sh->root.type == bfd_link_hash_new)
|
5375 |
|
|
{
|
5376 |
|
|
sh->root.type = bfd_link_hash_defined;
|
5377 |
|
|
sh->root.u.def.section = htab->glink;
|
5378 |
|
|
sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
|
5379 |
|
|
sh->ref_regular = 1;
|
5380 |
|
|
sh->def_regular = 1;
|
5381 |
|
|
sh->ref_regular_nonweak = 1;
|
5382 |
|
|
sh->forced_local = 1;
|
5383 |
|
|
sh->non_elf = 0;
|
5384 |
|
|
}
|
5385 |
|
|
}
|
5386 |
|
|
}
|
5387 |
|
|
|
5388 |
|
|
/* We've now determined the sizes of the various dynamic sections.
|
5389 |
|
|
Allocate memory for them. */
|
5390 |
|
|
relocs = FALSE;
|
5391 |
|
|
for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
|
5392 |
|
|
{
|
5393 |
|
|
bfd_boolean strip_section = TRUE;
|
5394 |
|
|
|
5395 |
|
|
if ((s->flags & SEC_LINKER_CREATED) == 0)
|
5396 |
|
|
continue;
|
5397 |
|
|
|
5398 |
|
|
if (s == htab->plt
|
5399 |
|
|
|| s == htab->glink
|
5400 |
|
|
|| s == htab->got
|
5401 |
|
|
|| s == htab->sgotplt
|
5402 |
|
|
|| s == htab->sbss
|
5403 |
|
|
|| s == htab->dynbss
|
5404 |
|
|
|| s == htab->dynsbss)
|
5405 |
|
|
{
|
5406 |
|
|
/* We'd like to strip these sections if they aren't needed, but if
|
5407 |
|
|
we've exported dynamic symbols from them we must leave them.
|
5408 |
|
|
It's too late to tell BFD to get rid of the symbols. */
|
5409 |
|
|
if ((s == htab->plt || s == htab->got) && htab->elf.hplt != NULL)
|
5410 |
|
|
strip_section = FALSE;
|
5411 |
|
|
/* Strip this section if we don't need it; see the
|
5412 |
|
|
comment below. */
|
5413 |
|
|
}
|
5414 |
|
|
else if (s == htab->sdata[0].section
|
5415 |
|
|
|| s == htab->sdata[1].section)
|
5416 |
|
|
{
|
5417 |
|
|
/* Strip these too. */
|
5418 |
|
|
}
|
5419 |
|
|
else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
|
5420 |
|
|
{
|
5421 |
|
|
if (s->size != 0)
|
5422 |
|
|
{
|
5423 |
|
|
/* Remember whether there are any relocation sections. */
|
5424 |
|
|
relocs = TRUE;
|
5425 |
|
|
|
5426 |
|
|
/* We use the reloc_count field as a counter if we need
|
5427 |
|
|
to copy relocs into the output file. */
|
5428 |
|
|
s->reloc_count = 0;
|
5429 |
|
|
}
|
5430 |
|
|
}
|
5431 |
|
|
else
|
5432 |
|
|
{
|
5433 |
|
|
/* It's not one of our sections, so don't allocate space. */
|
5434 |
|
|
continue;
|
5435 |
|
|
}
|
5436 |
|
|
|
5437 |
|
|
if (s->size == 0 && strip_section)
|
5438 |
|
|
{
|
5439 |
|
|
/* If we don't need this section, strip it from the
|
5440 |
|
|
output file. This is mostly to handle .rela.bss and
|
5441 |
|
|
.rela.plt. We must create both sections in
|
5442 |
|
|
create_dynamic_sections, because they must be created
|
5443 |
|
|
before the linker maps input sections to output
|
5444 |
|
|
sections. The linker does that before
|
5445 |
|
|
adjust_dynamic_symbol is called, and it is that
|
5446 |
|
|
function which decides whether anything needs to go
|
5447 |
|
|
into these sections. */
|
5448 |
|
|
s->flags |= SEC_EXCLUDE;
|
5449 |
|
|
continue;
|
5450 |
|
|
}
|
5451 |
|
|
|
5452 |
|
|
if ((s->flags & SEC_HAS_CONTENTS) == 0)
|
5453 |
|
|
continue;
|
5454 |
|
|
|
5455 |
|
|
/* Allocate memory for the section contents. */
|
5456 |
|
|
s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
|
5457 |
|
|
if (s->contents == NULL)
|
5458 |
|
|
return FALSE;
|
5459 |
|
|
}
|
5460 |
|
|
|
5461 |
|
|
if (htab->elf.dynamic_sections_created)
|
5462 |
|
|
{
|
5463 |
|
|
/* Add some entries to the .dynamic section. We fill in the
|
5464 |
|
|
values later, in ppc_elf_finish_dynamic_sections, but we
|
5465 |
|
|
must add the entries now so that we get the correct size for
|
5466 |
|
|
the .dynamic section. The DT_DEBUG entry is filled in by the
|
5467 |
|
|
dynamic linker and used by the debugger. */
|
5468 |
|
|
#define add_dynamic_entry(TAG, VAL) \
|
5469 |
|
|
_bfd_elf_add_dynamic_entry (info, TAG, VAL)
|
5470 |
|
|
|
5471 |
|
|
if (info->executable)
|
5472 |
|
|
{
|
5473 |
|
|
if (!add_dynamic_entry (DT_DEBUG, 0))
|
5474 |
|
|
return FALSE;
|
5475 |
|
|
}
|
5476 |
|
|
|
5477 |
|
|
if (htab->plt != NULL && htab->plt->size != 0)
|
5478 |
|
|
{
|
5479 |
|
|
if (!add_dynamic_entry (DT_PLTGOT, 0)
|
5480 |
|
|
|| !add_dynamic_entry (DT_PLTRELSZ, 0)
|
5481 |
|
|
|| !add_dynamic_entry (DT_PLTREL, DT_RELA)
|
5482 |
|
|
|| !add_dynamic_entry (DT_JMPREL, 0))
|
5483 |
|
|
return FALSE;
|
5484 |
|
|
}
|
5485 |
|
|
|
5486 |
|
|
if (htab->glink != NULL && htab->glink->size != 0)
|
5487 |
|
|
{
|
5488 |
|
|
if (!add_dynamic_entry (DT_PPC_GOT, 0))
|
5489 |
|
|
return FALSE;
|
5490 |
|
|
}
|
5491 |
|
|
|
5492 |
|
|
if (relocs)
|
5493 |
|
|
{
|
5494 |
|
|
if (!add_dynamic_entry (DT_RELA, 0)
|
5495 |
|
|
|| !add_dynamic_entry (DT_RELASZ, 0)
|
5496 |
|
|
|| !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
|
5497 |
|
|
return FALSE;
|
5498 |
|
|
}
|
5499 |
|
|
|
5500 |
|
|
/* If any dynamic relocs apply to a read-only section, then we
|
5501 |
|
|
need a DT_TEXTREL entry. */
|
5502 |
|
|
if ((info->flags & DF_TEXTREL) == 0)
|
5503 |
|
|
elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel,
|
5504 |
|
|
info);
|
5505 |
|
|
|
5506 |
|
|
if ((info->flags & DF_TEXTREL) != 0)
|
5507 |
|
|
{
|
5508 |
|
|
if (!add_dynamic_entry (DT_TEXTREL, 0))
|
5509 |
|
|
return FALSE;
|
5510 |
|
|
}
|
5511 |
|
|
if (htab->is_vxworks
|
5512 |
|
|
&& !elf_vxworks_add_dynamic_entries (output_bfd, info))
|
5513 |
|
|
return FALSE;
|
5514 |
|
|
}
|
5515 |
|
|
#undef add_dynamic_entry
|
5516 |
|
|
|
5517 |
|
|
return TRUE;
|
5518 |
|
|
}
|
5519 |
|
|
|
5520 |
|
|
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
|
5521 |
|
|
|
5522 |
|
|
static bfd_boolean
|
5523 |
|
|
ppc_elf_hash_symbol (struct elf_link_hash_entry *h)
|
5524 |
|
|
{
|
5525 |
|
|
if (h->plt.plist != NULL
|
5526 |
|
|
&& !h->def_regular
|
5527 |
|
|
&& (!h->pointer_equality_needed
|
5528 |
|
|
|| !h->ref_regular_nonweak))
|
5529 |
|
|
return FALSE;
|
5530 |
|
|
|
5531 |
|
|
return _bfd_elf_hash_symbol (h);
|
5532 |
|
|
}
|
5533 |
|
|
|
5534 |
|
|
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
5535 |
|
|
|
5536 |
|
|
static const int shared_stub_entry[] =
|
5537 |
|
|
{
|
5538 |
|
|
0x7c0802a6, /* mflr 0 */
|
5539 |
|
|
0x429f0005, /* bcl 20, 31, .Lxxx */
|
5540 |
|
|
0x7d6802a6, /* mflr 11 */
|
5541 |
|
|
0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
|
5542 |
|
|
0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
|
5543 |
|
|
0x7c0803a6, /* mtlr 0 */
|
5544 |
|
|
0x7d6903a6, /* mtctr 11 */
|
5545 |
|
|
0x4e800420, /* bctr */
|
5546 |
|
|
};
|
5547 |
|
|
|
5548 |
|
|
static const int stub_entry[] =
|
5549 |
|
|
{
|
5550 |
|
|
0x3d600000, /* lis 11,xxx@ha */
|
5551 |
|
|
0x396b0000, /* addi 11,11,xxx@l */
|
5552 |
|
|
0x7d6903a6, /* mtctr 11 */
|
5553 |
|
|
0x4e800420, /* bctr */
|
5554 |
|
|
};
|
5555 |
|
|
|
5556 |
|
|
static bfd_boolean
|
5557 |
|
|
ppc_elf_relax_section (bfd *abfd,
|
5558 |
|
|
asection *isec,
|
5559 |
|
|
struct bfd_link_info *link_info,
|
5560 |
|
|
bfd_boolean *again)
|
5561 |
|
|
{
|
5562 |
|
|
struct one_fixup
|
5563 |
|
|
{
|
5564 |
|
|
struct one_fixup *next;
|
5565 |
|
|
asection *tsec;
|
5566 |
|
|
bfd_vma toff;
|
5567 |
|
|
bfd_vma trampoff;
|
5568 |
|
|
};
|
5569 |
|
|
|
5570 |
|
|
Elf_Internal_Shdr *symtab_hdr;
|
5571 |
|
|
bfd_byte *contents = NULL;
|
5572 |
|
|
Elf_Internal_Sym *isymbuf = NULL;
|
5573 |
|
|
Elf_Internal_Rela *internal_relocs = NULL;
|
5574 |
|
|
Elf_Internal_Rela *irel, *irelend;
|
5575 |
|
|
struct one_fixup *fixups = NULL;
|
5576 |
|
|
bfd_boolean changed;
|
5577 |
|
|
struct ppc_elf_link_hash_table *htab;
|
5578 |
|
|
bfd_size_type trampoff;
|
5579 |
|
|
asection *got2;
|
5580 |
|
|
|
5581 |
|
|
*again = FALSE;
|
5582 |
|
|
|
5583 |
|
|
/* Nothing to do if there are no relocations, and no need to do
|
5584 |
|
|
anything with non-alloc sections. */
|
5585 |
|
|
if ((isec->flags & SEC_ALLOC) == 0
|
5586 |
|
|
|| (isec->flags & SEC_RELOC) == 0
|
5587 |
|
|
|| isec->reloc_count == 0)
|
5588 |
|
|
return TRUE;
|
5589 |
|
|
|
5590 |
|
|
trampoff = (isec->size + 3) & (bfd_vma) -4;
|
5591 |
|
|
/* Space for a branch around any trampolines. */
|
5592 |
|
|
trampoff += 4;
|
5593 |
|
|
|
5594 |
|
|
symtab_hdr = &elf_symtab_hdr (abfd);
|
5595 |
|
|
|
5596 |
|
|
/* Get a copy of the native relocations. */
|
5597 |
|
|
internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
|
5598 |
|
|
link_info->keep_memory);
|
5599 |
|
|
if (internal_relocs == NULL)
|
5600 |
|
|
goto error_return;
|
5601 |
|
|
|
5602 |
|
|
htab = ppc_elf_hash_table (link_info);
|
5603 |
|
|
got2 = bfd_get_section_by_name (abfd, ".got2");
|
5604 |
|
|
|
5605 |
|
|
irelend = internal_relocs + isec->reloc_count;
|
5606 |
|
|
for (irel = internal_relocs; irel < irelend; irel++)
|
5607 |
|
|
{
|
5608 |
|
|
unsigned long r_type = ELF32_R_TYPE (irel->r_info);
|
5609 |
|
|
bfd_vma symaddr, reladdr, toff, roff;
|
5610 |
|
|
asection *tsec;
|
5611 |
|
|
struct one_fixup *f;
|
5612 |
|
|
size_t insn_offset = 0;
|
5613 |
|
|
bfd_vma max_branch_offset, val;
|
5614 |
|
|
bfd_byte *hit_addr;
|
5615 |
|
|
unsigned long t0;
|
5616 |
|
|
unsigned char sym_type;
|
5617 |
|
|
|
5618 |
|
|
switch (r_type)
|
5619 |
|
|
{
|
5620 |
|
|
case R_PPC_REL24:
|
5621 |
|
|
case R_PPC_LOCAL24PC:
|
5622 |
|
|
case R_PPC_PLTREL24:
|
5623 |
|
|
max_branch_offset = 1 << 25;
|
5624 |
|
|
break;
|
5625 |
|
|
|
5626 |
|
|
case R_PPC_REL14:
|
5627 |
|
|
case R_PPC_REL14_BRTAKEN:
|
5628 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
5629 |
|
|
max_branch_offset = 1 << 15;
|
5630 |
|
|
break;
|
5631 |
|
|
|
5632 |
|
|
default:
|
5633 |
|
|
continue;
|
5634 |
|
|
}
|
5635 |
|
|
|
5636 |
|
|
/* Get the value of the symbol referred to by the reloc. */
|
5637 |
|
|
if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
|
5638 |
|
|
{
|
5639 |
|
|
/* A local symbol. */
|
5640 |
|
|
Elf_Internal_Sym *isym;
|
5641 |
|
|
|
5642 |
|
|
/* Read this BFD's local symbols. */
|
5643 |
|
|
if (isymbuf == NULL)
|
5644 |
|
|
{
|
5645 |
|
|
isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
|
5646 |
|
|
if (isymbuf == NULL)
|
5647 |
|
|
isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
|
5648 |
|
|
symtab_hdr->sh_info, 0,
|
5649 |
|
|
NULL, NULL, NULL);
|
5650 |
|
|
if (isymbuf == 0)
|
5651 |
|
|
goto error_return;
|
5652 |
|
|
}
|
5653 |
|
|
isym = isymbuf + ELF32_R_SYM (irel->r_info);
|
5654 |
|
|
if (isym->st_shndx == SHN_UNDEF)
|
5655 |
|
|
continue; /* We can't do anything with undefined symbols. */
|
5656 |
|
|
else if (isym->st_shndx == SHN_ABS)
|
5657 |
|
|
tsec = bfd_abs_section_ptr;
|
5658 |
|
|
else if (isym->st_shndx == SHN_COMMON)
|
5659 |
|
|
tsec = bfd_com_section_ptr;
|
5660 |
|
|
else
|
5661 |
|
|
tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
|
5662 |
|
|
|
5663 |
|
|
toff = isym->st_value;
|
5664 |
|
|
sym_type = ELF_ST_TYPE (isym->st_info);
|
5665 |
|
|
}
|
5666 |
|
|
else
|
5667 |
|
|
{
|
5668 |
|
|
/* Global symbol handling. */
|
5669 |
|
|
unsigned long indx;
|
5670 |
|
|
struct elf_link_hash_entry *h;
|
5671 |
|
|
|
5672 |
|
|
indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
|
5673 |
|
|
h = elf_sym_hashes (abfd)[indx];
|
5674 |
|
|
|
5675 |
|
|
while (h->root.type == bfd_link_hash_indirect
|
5676 |
|
|
|| h->root.type == bfd_link_hash_warning)
|
5677 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
5678 |
|
|
|
5679 |
|
|
tsec = NULL;
|
5680 |
|
|
toff = 0;
|
5681 |
|
|
if (r_type == R_PPC_PLTREL24
|
5682 |
|
|
&& htab->plt != NULL)
|
5683 |
|
|
{
|
5684 |
|
|
struct plt_entry *ent = find_plt_ent (h, got2, irel->r_addend);
|
5685 |
|
|
|
5686 |
|
|
if (ent != NULL)
|
5687 |
|
|
{
|
5688 |
|
|
if (htab->plt_type == PLT_NEW)
|
5689 |
|
|
{
|
5690 |
|
|
tsec = htab->glink;
|
5691 |
|
|
toff = ent->glink_offset;
|
5692 |
|
|
}
|
5693 |
|
|
else
|
5694 |
|
|
{
|
5695 |
|
|
tsec = htab->plt;
|
5696 |
|
|
toff = ent->plt.offset;
|
5697 |
|
|
}
|
5698 |
|
|
}
|
5699 |
|
|
}
|
5700 |
|
|
if (tsec != NULL)
|
5701 |
|
|
;
|
5702 |
|
|
else if (h->root.type == bfd_link_hash_defined
|
5703 |
|
|
|| h->root.type == bfd_link_hash_defweak)
|
5704 |
|
|
{
|
5705 |
|
|
tsec = h->root.u.def.section;
|
5706 |
|
|
toff = h->root.u.def.value;
|
5707 |
|
|
}
|
5708 |
|
|
else
|
5709 |
|
|
continue;
|
5710 |
|
|
|
5711 |
|
|
sym_type = h->type;
|
5712 |
|
|
}
|
5713 |
|
|
|
5714 |
|
|
/* If the branch and target are in the same section, you have
|
5715 |
|
|
no hope of adding stubs. We'll error out later should the
|
5716 |
|
|
branch overflow. */
|
5717 |
|
|
if (tsec == isec)
|
5718 |
|
|
continue;
|
5719 |
|
|
|
5720 |
|
|
/* There probably isn't any reason to handle symbols in
|
5721 |
|
|
SEC_MERGE sections; SEC_MERGE doesn't seem a likely
|
5722 |
|
|
attribute for a code section, and we are only looking at
|
5723 |
|
|
branches. However, implement it correctly here as a
|
5724 |
|
|
reference for other target relax_section functions. */
|
5725 |
|
|
if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
|
5726 |
|
|
{
|
5727 |
|
|
/* At this stage in linking, no SEC_MERGE symbol has been
|
5728 |
|
|
adjusted, so all references to such symbols need to be
|
5729 |
|
|
passed through _bfd_merged_section_offset. (Later, in
|
5730 |
|
|
relocate_section, all SEC_MERGE symbols *except* for
|
5731 |
|
|
section symbols have been adjusted.)
|
5732 |
|
|
|
5733 |
|
|
gas may reduce relocations against symbols in SEC_MERGE
|
5734 |
|
|
sections to a relocation against the section symbol when
|
5735 |
|
|
the original addend was zero. When the reloc is against
|
5736 |
|
|
a section symbol we should include the addend in the
|
5737 |
|
|
offset passed to _bfd_merged_section_offset, since the
|
5738 |
|
|
location of interest is the original symbol. On the
|
5739 |
|
|
other hand, an access to "sym+addend" where "sym" is not
|
5740 |
|
|
a section symbol should not include the addend; Such an
|
5741 |
|
|
access is presumed to be an offset from "sym"; The
|
5742 |
|
|
location of interest is just "sym". */
|
5743 |
|
|
if (sym_type == STT_SECTION)
|
5744 |
|
|
toff += irel->r_addend;
|
5745 |
|
|
|
5746 |
|
|
toff = _bfd_merged_section_offset (abfd, &tsec,
|
5747 |
|
|
elf_section_data (tsec)->sec_info,
|
5748 |
|
|
toff);
|
5749 |
|
|
|
5750 |
|
|
if (sym_type != STT_SECTION)
|
5751 |
|
|
toff += irel->r_addend;
|
5752 |
|
|
}
|
5753 |
|
|
/* PLTREL24 addends are special. */
|
5754 |
|
|
else if (r_type != R_PPC_PLTREL24)
|
5755 |
|
|
toff += irel->r_addend;
|
5756 |
|
|
|
5757 |
|
|
/* Attempted -shared link of non-pic code loses. */
|
5758 |
|
|
if (tsec->output_section == NULL)
|
5759 |
|
|
continue;
|
5760 |
|
|
|
5761 |
|
|
symaddr = tsec->output_section->vma + tsec->output_offset + toff;
|
5762 |
|
|
|
5763 |
|
|
roff = irel->r_offset;
|
5764 |
|
|
reladdr = isec->output_section->vma + isec->output_offset + roff;
|
5765 |
|
|
|
5766 |
|
|
/* If the branch is in range, no need to do anything. */
|
5767 |
|
|
if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
|
5768 |
|
|
continue;
|
5769 |
|
|
|
5770 |
|
|
/* Look for an existing fixup to this address. */
|
5771 |
|
|
for (f = fixups; f ; f = f->next)
|
5772 |
|
|
if (f->tsec == tsec && f->toff == toff)
|
5773 |
|
|
break;
|
5774 |
|
|
|
5775 |
|
|
if (f == NULL)
|
5776 |
|
|
{
|
5777 |
|
|
size_t size;
|
5778 |
|
|
unsigned long stub_rtype;
|
5779 |
|
|
|
5780 |
|
|
val = trampoff - roff;
|
5781 |
|
|
if (val >= max_branch_offset)
|
5782 |
|
|
/* Oh dear, we can't reach a trampoline. Don't try to add
|
5783 |
|
|
one. We'll report an error later. */
|
5784 |
|
|
continue;
|
5785 |
|
|
|
5786 |
|
|
if (link_info->shared)
|
5787 |
|
|
{
|
5788 |
|
|
size = 4 * ARRAY_SIZE (shared_stub_entry);
|
5789 |
|
|
insn_offset = 12;
|
5790 |
|
|
stub_rtype = R_PPC_RELAX32PC;
|
5791 |
|
|
}
|
5792 |
|
|
else
|
5793 |
|
|
{
|
5794 |
|
|
size = 4 * ARRAY_SIZE (stub_entry);
|
5795 |
|
|
insn_offset = 0;
|
5796 |
|
|
stub_rtype = R_PPC_RELAX32;
|
5797 |
|
|
}
|
5798 |
|
|
|
5799 |
|
|
if (R_PPC_RELAX32_PLT - R_PPC_RELAX32
|
5800 |
|
|
!= R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC)
|
5801 |
|
|
abort ();
|
5802 |
|
|
if (tsec == htab->plt
|
5803 |
|
|
|| tsec == htab->glink)
|
5804 |
|
|
stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32;
|
5805 |
|
|
|
5806 |
|
|
/* Hijack the old relocation. Since we need two
|
5807 |
|
|
relocations for this use a "composite" reloc. */
|
5808 |
|
|
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
|
5809 |
|
|
stub_rtype);
|
5810 |
|
|
irel->r_offset = trampoff + insn_offset;
|
5811 |
|
|
if (r_type == R_PPC_PLTREL24)
|
5812 |
|
|
irel->r_addend = 0;
|
5813 |
|
|
|
5814 |
|
|
/* Record the fixup so we don't do it again this section. */
|
5815 |
|
|
f = bfd_malloc (sizeof (*f));
|
5816 |
|
|
f->next = fixups;
|
5817 |
|
|
f->tsec = tsec;
|
5818 |
|
|
f->toff = toff;
|
5819 |
|
|
f->trampoff = trampoff;
|
5820 |
|
|
fixups = f;
|
5821 |
|
|
|
5822 |
|
|
trampoff += size;
|
5823 |
|
|
}
|
5824 |
|
|
else
|
5825 |
|
|
{
|
5826 |
|
|
val = f->trampoff - roff;
|
5827 |
|
|
if (val >= max_branch_offset)
|
5828 |
|
|
continue;
|
5829 |
|
|
|
5830 |
|
|
/* Nop out the reloc, since we're finalizing things here. */
|
5831 |
|
|
irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
|
5832 |
|
|
}
|
5833 |
|
|
|
5834 |
|
|
/* Get the section contents. */
|
5835 |
|
|
if (contents == NULL)
|
5836 |
|
|
{
|
5837 |
|
|
/* Get cached copy if it exists. */
|
5838 |
|
|
if (elf_section_data (isec)->this_hdr.contents != NULL)
|
5839 |
|
|
contents = elf_section_data (isec)->this_hdr.contents;
|
5840 |
|
|
else
|
5841 |
|
|
{
|
5842 |
|
|
/* Go get them off disk. */
|
5843 |
|
|
if (!bfd_malloc_and_get_section (abfd, isec, &contents))
|
5844 |
|
|
goto error_return;
|
5845 |
|
|
}
|
5846 |
|
|
}
|
5847 |
|
|
|
5848 |
|
|
/* Fix up the existing branch to hit the trampoline. */
|
5849 |
|
|
hit_addr = contents + roff;
|
5850 |
|
|
switch (r_type)
|
5851 |
|
|
{
|
5852 |
|
|
case R_PPC_REL24:
|
5853 |
|
|
case R_PPC_LOCAL24PC:
|
5854 |
|
|
case R_PPC_PLTREL24:
|
5855 |
|
|
t0 = bfd_get_32 (abfd, hit_addr);
|
5856 |
|
|
t0 &= ~0x3fffffc;
|
5857 |
|
|
t0 |= val & 0x3fffffc;
|
5858 |
|
|
bfd_put_32 (abfd, t0, hit_addr);
|
5859 |
|
|
break;
|
5860 |
|
|
|
5861 |
|
|
case R_PPC_REL14:
|
5862 |
|
|
case R_PPC_REL14_BRTAKEN:
|
5863 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
5864 |
|
|
t0 = bfd_get_32 (abfd, hit_addr);
|
5865 |
|
|
t0 &= ~0xfffc;
|
5866 |
|
|
t0 |= val & 0xfffc;
|
5867 |
|
|
bfd_put_32 (abfd, t0, hit_addr);
|
5868 |
|
|
break;
|
5869 |
|
|
}
|
5870 |
|
|
}
|
5871 |
|
|
|
5872 |
|
|
/* Write out the trampolines. */
|
5873 |
|
|
changed = fixups != NULL;
|
5874 |
|
|
if (fixups != NULL)
|
5875 |
|
|
{
|
5876 |
|
|
const int *stub;
|
5877 |
|
|
bfd_byte *dest;
|
5878 |
|
|
bfd_vma val;
|
5879 |
|
|
int i, size;
|
5880 |
|
|
|
5881 |
|
|
do
|
5882 |
|
|
{
|
5883 |
|
|
struct one_fixup *f = fixups;
|
5884 |
|
|
fixups = fixups->next;
|
5885 |
|
|
free (f);
|
5886 |
|
|
}
|
5887 |
|
|
while (fixups);
|
5888 |
|
|
|
5889 |
|
|
contents = bfd_realloc_or_free (contents, trampoff);
|
5890 |
|
|
if (contents == NULL)
|
5891 |
|
|
goto error_return;
|
5892 |
|
|
|
5893 |
|
|
isec->size = (isec->size + 3) & (bfd_vma) -4;
|
5894 |
|
|
/* Branch around the trampolines. */
|
5895 |
|
|
val = B + trampoff - isec->size;
|
5896 |
|
|
dest = contents + isec->size;
|
5897 |
|
|
isec->size = trampoff;
|
5898 |
|
|
bfd_put_32 (abfd, val, dest);
|
5899 |
|
|
dest += 4;
|
5900 |
|
|
|
5901 |
|
|
if (link_info->shared)
|
5902 |
|
|
{
|
5903 |
|
|
stub = shared_stub_entry;
|
5904 |
|
|
size = ARRAY_SIZE (shared_stub_entry);
|
5905 |
|
|
}
|
5906 |
|
|
else
|
5907 |
|
|
{
|
5908 |
|
|
stub = stub_entry;
|
5909 |
|
|
size = ARRAY_SIZE (stub_entry);
|
5910 |
|
|
}
|
5911 |
|
|
|
5912 |
|
|
i = 0;
|
5913 |
|
|
while (dest < contents + trampoff)
|
5914 |
|
|
{
|
5915 |
|
|
bfd_put_32 (abfd, stub[i], dest);
|
5916 |
|
|
i++;
|
5917 |
|
|
if (i == size)
|
5918 |
|
|
i = 0;
|
5919 |
|
|
dest += 4;
|
5920 |
|
|
}
|
5921 |
|
|
BFD_ASSERT (i == 0);
|
5922 |
|
|
}
|
5923 |
|
|
|
5924 |
|
|
if (isymbuf != NULL
|
5925 |
|
|
&& symtab_hdr->contents != (unsigned char *) isymbuf)
|
5926 |
|
|
{
|
5927 |
|
|
if (! link_info->keep_memory)
|
5928 |
|
|
free (isymbuf);
|
5929 |
|
|
else
|
5930 |
|
|
{
|
5931 |
|
|
/* Cache the symbols for elf_link_input_bfd. */
|
5932 |
|
|
symtab_hdr->contents = (unsigned char *) isymbuf;
|
5933 |
|
|
}
|
5934 |
|
|
}
|
5935 |
|
|
|
5936 |
|
|
if (contents != NULL
|
5937 |
|
|
&& elf_section_data (isec)->this_hdr.contents != contents)
|
5938 |
|
|
{
|
5939 |
|
|
if (!changed && !link_info->keep_memory)
|
5940 |
|
|
free (contents);
|
5941 |
|
|
else
|
5942 |
|
|
{
|
5943 |
|
|
/* Cache the section contents for elf_link_input_bfd. */
|
5944 |
|
|
elf_section_data (isec)->this_hdr.contents = contents;
|
5945 |
|
|
}
|
5946 |
|
|
}
|
5947 |
|
|
|
5948 |
|
|
if (elf_section_data (isec)->relocs != internal_relocs)
|
5949 |
|
|
{
|
5950 |
|
|
if (!changed)
|
5951 |
|
|
free (internal_relocs);
|
5952 |
|
|
else
|
5953 |
|
|
elf_section_data (isec)->relocs = internal_relocs;
|
5954 |
|
|
}
|
5955 |
|
|
|
5956 |
|
|
*again = changed;
|
5957 |
|
|
return TRUE;
|
5958 |
|
|
|
5959 |
|
|
error_return:
|
5960 |
|
|
if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
|
5961 |
|
|
free (isymbuf);
|
5962 |
|
|
if (contents != NULL
|
5963 |
|
|
&& elf_section_data (isec)->this_hdr.contents != contents)
|
5964 |
|
|
free (contents);
|
5965 |
|
|
if (internal_relocs != NULL
|
5966 |
|
|
&& elf_section_data (isec)->relocs != internal_relocs)
|
5967 |
|
|
free (internal_relocs);
|
5968 |
|
|
return FALSE;
|
5969 |
|
|
}
|
5970 |
|
|
|
5971 |
|
|
/* What to do when ld finds relocations against symbols defined in
|
5972 |
|
|
discarded sections. */
|
5973 |
|
|
|
5974 |
|
|
static unsigned int
|
5975 |
|
|
ppc_elf_action_discarded (asection *sec)
|
5976 |
|
|
{
|
5977 |
|
|
if (strcmp (".fixup", sec->name) == 0)
|
5978 |
|
|
return 0;
|
5979 |
|
|
|
5980 |
|
|
if (strcmp (".got2", sec->name) == 0)
|
5981 |
|
|
return 0;
|
5982 |
|
|
|
5983 |
|
|
return _bfd_elf_default_action_discarded (sec);
|
5984 |
|
|
}
|
5985 |
|
|
|
5986 |
|
|
/* Fill in the address for a pointer generated in a linker section. */
|
5987 |
|
|
|
5988 |
|
|
static bfd_vma
|
5989 |
|
|
elf_finish_pointer_linker_section (bfd *input_bfd,
|
5990 |
|
|
elf_linker_section_t *lsect,
|
5991 |
|
|
struct elf_link_hash_entry *h,
|
5992 |
|
|
bfd_vma relocation,
|
5993 |
|
|
const Elf_Internal_Rela *rel)
|
5994 |
|
|
{
|
5995 |
|
|
elf_linker_section_pointers_t *linker_section_ptr;
|
5996 |
|
|
|
5997 |
|
|
BFD_ASSERT (lsect != NULL);
|
5998 |
|
|
|
5999 |
|
|
if (h != NULL)
|
6000 |
|
|
{
|
6001 |
|
|
/* Handle global symbol. */
|
6002 |
|
|
struct ppc_elf_link_hash_entry *eh;
|
6003 |
|
|
|
6004 |
|
|
eh = (struct ppc_elf_link_hash_entry *) h;
|
6005 |
|
|
BFD_ASSERT (eh->elf.def_regular);
|
6006 |
|
|
linker_section_ptr = eh->linker_section_pointer;
|
6007 |
|
|
}
|
6008 |
|
|
else
|
6009 |
|
|
{
|
6010 |
|
|
/* Handle local symbol. */
|
6011 |
|
|
unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
|
6012 |
|
|
|
6013 |
|
|
BFD_ASSERT (is_ppc_elf (input_bfd));
|
6014 |
|
|
BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
|
6015 |
|
|
linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
|
6016 |
|
|
}
|
6017 |
|
|
|
6018 |
|
|
linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
|
6019 |
|
|
rel->r_addend,
|
6020 |
|
|
lsect);
|
6021 |
|
|
BFD_ASSERT (linker_section_ptr != NULL);
|
6022 |
|
|
|
6023 |
|
|
/* Offset will always be a multiple of four, so use the bottom bit
|
6024 |
|
|
as a "written" flag. */
|
6025 |
|
|
if ((linker_section_ptr->offset & 1) == 0)
|
6026 |
|
|
{
|
6027 |
|
|
bfd_put_32 (lsect->section->owner,
|
6028 |
|
|
relocation + linker_section_ptr->addend,
|
6029 |
|
|
lsect->section->contents + linker_section_ptr->offset);
|
6030 |
|
|
linker_section_ptr->offset += 1;
|
6031 |
|
|
}
|
6032 |
|
|
|
6033 |
|
|
relocation = (lsect->section->output_offset
|
6034 |
|
|
+ linker_section_ptr->offset - 1
|
6035 |
|
|
- 0x8000);
|
6036 |
|
|
|
6037 |
|
|
#ifdef DEBUG
|
6038 |
|
|
fprintf (stderr,
|
6039 |
|
|
"Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
|
6040 |
|
|
lsect->name, (long) relocation, (long) relocation);
|
6041 |
|
|
#endif
|
6042 |
|
|
|
6043 |
|
|
/* Subtract out the addend, because it will get added back in by the normal
|
6044 |
|
|
processing. */
|
6045 |
|
|
return relocation - linker_section_ptr->addend;
|
6046 |
|
|
}
|
6047 |
|
|
|
6048 |
|
|
/* The RELOCATE_SECTION function is called by the ELF backend linker
|
6049 |
|
|
to handle the relocations for a section.
|
6050 |
|
|
|
6051 |
|
|
The relocs are always passed as Rela structures; if the section
|
6052 |
|
|
actually uses Rel structures, the r_addend field will always be
|
6053 |
|
|
zero.
|
6054 |
|
|
|
6055 |
|
|
This function is responsible for adjust the section contents as
|
6056 |
|
|
necessary, and (if using Rela relocs and generating a
|
6057 |
|
|
relocatable output file) adjusting the reloc addend as
|
6058 |
|
|
necessary.
|
6059 |
|
|
|
6060 |
|
|
This function does not have to worry about setting the reloc
|
6061 |
|
|
address or the reloc symbol index.
|
6062 |
|
|
|
6063 |
|
|
LOCAL_SYMS is a pointer to the swapped in local symbols.
|
6064 |
|
|
|
6065 |
|
|
LOCAL_SECTIONS is an array giving the section in the input file
|
6066 |
|
|
corresponding to the st_shndx field of each local symbol.
|
6067 |
|
|
|
6068 |
|
|
The global hash table entry for the global symbols can be found
|
6069 |
|
|
via elf_sym_hashes (input_bfd).
|
6070 |
|
|
|
6071 |
|
|
When generating relocatable output, this function must handle
|
6072 |
|
|
STB_LOCAL/STT_SECTION symbols specially. The output symbol is
|
6073 |
|
|
going to be the section symbol corresponding to the output
|
6074 |
|
|
section, which means that the addend must be adjusted
|
6075 |
|
|
accordingly. */
|
6076 |
|
|
|
6077 |
|
|
static bfd_boolean
|
6078 |
|
|
ppc_elf_relocate_section (bfd *output_bfd,
|
6079 |
|
|
struct bfd_link_info *info,
|
6080 |
|
|
bfd *input_bfd,
|
6081 |
|
|
asection *input_section,
|
6082 |
|
|
bfd_byte *contents,
|
6083 |
|
|
Elf_Internal_Rela *relocs,
|
6084 |
|
|
Elf_Internal_Sym *local_syms,
|
6085 |
|
|
asection **local_sections)
|
6086 |
|
|
{
|
6087 |
|
|
Elf_Internal_Shdr *symtab_hdr;
|
6088 |
|
|
struct elf_link_hash_entry **sym_hashes;
|
6089 |
|
|
struct ppc_elf_link_hash_table *htab;
|
6090 |
|
|
Elf_Internal_Rela *rel;
|
6091 |
|
|
Elf_Internal_Rela *relend;
|
6092 |
|
|
Elf_Internal_Rela outrel;
|
6093 |
|
|
bfd_byte *loc;
|
6094 |
|
|
asection *got2, *sreloc = NULL;
|
6095 |
|
|
bfd_vma *local_got_offsets;
|
6096 |
|
|
bfd_boolean ret = TRUE;
|
6097 |
|
|
bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
|
6098 |
|
|
bfd_boolean is_vxworks_tls;
|
6099 |
|
|
|
6100 |
|
|
#ifdef DEBUG
|
6101 |
|
|
_bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
|
6102 |
|
|
"%ld relocations%s",
|
6103 |
|
|
input_bfd, input_section,
|
6104 |
|
|
(long) input_section->reloc_count,
|
6105 |
|
|
(info->relocatable) ? " (relocatable)" : "");
|
6106 |
|
|
#endif
|
6107 |
|
|
|
6108 |
|
|
got2 = bfd_get_section_by_name (input_bfd, ".got2");
|
6109 |
|
|
|
6110 |
|
|
/* Initialize howto table if not already done. */
|
6111 |
|
|
if (!ppc_elf_howto_table[R_PPC_ADDR32])
|
6112 |
|
|
ppc_elf_howto_init ();
|
6113 |
|
|
|
6114 |
|
|
htab = ppc_elf_hash_table (info);
|
6115 |
|
|
local_got_offsets = elf_local_got_offsets (input_bfd);
|
6116 |
|
|
symtab_hdr = &elf_symtab_hdr (input_bfd);
|
6117 |
|
|
sym_hashes = elf_sym_hashes (input_bfd);
|
6118 |
|
|
/* We have to handle relocations in vxworks .tls_vars sections
|
6119 |
|
|
specially, because the dynamic loader is 'weird'. */
|
6120 |
|
|
is_vxworks_tls = (htab->is_vxworks && info->shared
|
6121 |
|
|
&& !strcmp (input_section->output_section->name,
|
6122 |
|
|
".tls_vars"));
|
6123 |
|
|
rel = relocs;
|
6124 |
|
|
relend = relocs + input_section->reloc_count;
|
6125 |
|
|
for (; rel < relend; rel++)
|
6126 |
|
|
{
|
6127 |
|
|
enum elf_ppc_reloc_type r_type;
|
6128 |
|
|
bfd_vma addend;
|
6129 |
|
|
bfd_reloc_status_type r;
|
6130 |
|
|
Elf_Internal_Sym *sym;
|
6131 |
|
|
asection *sec;
|
6132 |
|
|
struct elf_link_hash_entry *h;
|
6133 |
|
|
const char *sym_name;
|
6134 |
|
|
reloc_howto_type *howto;
|
6135 |
|
|
unsigned long r_symndx;
|
6136 |
|
|
bfd_vma relocation;
|
6137 |
|
|
bfd_vma branch_bit, insn, from;
|
6138 |
|
|
bfd_boolean unresolved_reloc;
|
6139 |
|
|
bfd_boolean warned;
|
6140 |
|
|
unsigned int tls_type, tls_mask, tls_gd;
|
6141 |
|
|
|
6142 |
|
|
r_type = ELF32_R_TYPE (rel->r_info);
|
6143 |
|
|
sym = NULL;
|
6144 |
|
|
sec = NULL;
|
6145 |
|
|
h = NULL;
|
6146 |
|
|
unresolved_reloc = FALSE;
|
6147 |
|
|
warned = FALSE;
|
6148 |
|
|
r_symndx = ELF32_R_SYM (rel->r_info);
|
6149 |
|
|
|
6150 |
|
|
if (r_symndx < symtab_hdr->sh_info)
|
6151 |
|
|
{
|
6152 |
|
|
sym = local_syms + r_symndx;
|
6153 |
|
|
sec = local_sections[r_symndx];
|
6154 |
|
|
sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
|
6155 |
|
|
|
6156 |
|
|
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
|
6157 |
|
|
}
|
6158 |
|
|
else
|
6159 |
|
|
{
|
6160 |
|
|
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
|
6161 |
|
|
r_symndx, symtab_hdr, sym_hashes,
|
6162 |
|
|
h, sec, relocation,
|
6163 |
|
|
unresolved_reloc, warned);
|
6164 |
|
|
|
6165 |
|
|
sym_name = h->root.root.string;
|
6166 |
|
|
}
|
6167 |
|
|
|
6168 |
|
|
if (sec != NULL && elf_discarded_section (sec))
|
6169 |
|
|
{
|
6170 |
|
|
/* For relocs against symbols from removed linkonce sections,
|
6171 |
|
|
or sections discarded by a linker script, we just want the
|
6172 |
|
|
section contents zeroed. Avoid any special processing. */
|
6173 |
|
|
howto = NULL;
|
6174 |
|
|
if (r_type < R_PPC_max)
|
6175 |
|
|
howto = ppc_elf_howto_table[r_type];
|
6176 |
|
|
_bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
|
6177 |
|
|
rel->r_info = 0;
|
6178 |
|
|
rel->r_addend = 0;
|
6179 |
|
|
continue;
|
6180 |
|
|
}
|
6181 |
|
|
|
6182 |
|
|
if (info->relocatable)
|
6183 |
|
|
{
|
6184 |
|
|
if (got2 != NULL
|
6185 |
|
|
&& r_type == R_PPC_PLTREL24
|
6186 |
|
|
&& rel->r_addend >= 32768)
|
6187 |
|
|
{
|
6188 |
|
|
/* R_PPC_PLTREL24 is rather special. If non-zero, the
|
6189 |
|
|
addend specifies the GOT pointer offset within .got2. */
|
6190 |
|
|
rel->r_addend += got2->output_offset;
|
6191 |
|
|
}
|
6192 |
|
|
continue;
|
6193 |
|
|
}
|
6194 |
|
|
|
6195 |
|
|
/* TLS optimizations. Replace instruction sequences and relocs
|
6196 |
|
|
based on information we collected in tls_optimize. We edit
|
6197 |
|
|
RELOCS so that --emit-relocs will output something sensible
|
6198 |
|
|
for the final instruction stream. */
|
6199 |
|
|
tls_mask = 0;
|
6200 |
|
|
tls_gd = 0;
|
6201 |
|
|
if (IS_PPC_TLS_RELOC (r_type))
|
6202 |
|
|
{
|
6203 |
|
|
if (h != NULL)
|
6204 |
|
|
tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
|
6205 |
|
|
else if (local_got_offsets != NULL)
|
6206 |
|
|
{
|
6207 |
|
|
char *lgot_masks;
|
6208 |
|
|
lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
|
6209 |
|
|
tls_mask = lgot_masks[r_symndx];
|
6210 |
|
|
}
|
6211 |
|
|
}
|
6212 |
|
|
|
6213 |
|
|
/* Ensure reloc mapping code below stays sane. */
|
6214 |
|
|
if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
|
6215 |
|
|
|| (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
|
6216 |
|
|
|| (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
|
6217 |
|
|
|| (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
|
6218 |
|
|
|| (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
|
6219 |
|
|
|| (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
|
6220 |
|
|
|| (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
|
6221 |
|
|
|| (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
|
6222 |
|
|
abort ();
|
6223 |
|
|
switch (r_type)
|
6224 |
|
|
{
|
6225 |
|
|
default:
|
6226 |
|
|
break;
|
6227 |
|
|
|
6228 |
|
|
case R_PPC_GOT_TPREL16:
|
6229 |
|
|
case R_PPC_GOT_TPREL16_LO:
|
6230 |
|
|
if (tls_mask != 0
|
6231 |
|
|
&& (tls_mask & TLS_TPREL) == 0)
|
6232 |
|
|
{
|
6233 |
|
|
bfd_vma insn;
|
6234 |
|
|
insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
|
6235 |
|
|
insn &= 31 << 21;
|
6236 |
|
|
insn |= 0x3c020000; /* addis 0,2,0 */
|
6237 |
|
|
bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
|
6238 |
|
|
r_type = R_PPC_TPREL16_HA;
|
6239 |
|
|
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
|
6240 |
|
|
}
|
6241 |
|
|
break;
|
6242 |
|
|
|
6243 |
|
|
case R_PPC_TLS:
|
6244 |
|
|
if (tls_mask != 0
|
6245 |
|
|
&& (tls_mask & TLS_TPREL) == 0)
|
6246 |
|
|
{
|
6247 |
|
|
bfd_vma insn, rtra;
|
6248 |
|
|
insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
|
6249 |
|
|
if ((insn & ((31 << 26) | (31 << 11)))
|
6250 |
|
|
== ((31 << 26) | (2 << 11)))
|
6251 |
|
|
rtra = insn & ((1 << 26) - (1 << 16));
|
6252 |
|
|
else if ((insn & ((31 << 26) | (31 << 16)))
|
6253 |
|
|
== ((31 << 26) | (2 << 16)))
|
6254 |
|
|
rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
|
6255 |
|
|
else
|
6256 |
|
|
abort ();
|
6257 |
|
|
if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
|
6258 |
|
|
/* add -> addi. */
|
6259 |
|
|
insn = 14 << 26;
|
6260 |
|
|
else if ((insn & (31 << 1)) == 23 << 1
|
6261 |
|
|
&& ((insn & (31 << 6)) < 14 << 6
|
6262 |
|
|
|| ((insn & (31 << 6)) >= 16 << 6
|
6263 |
|
|
&& (insn & (31 << 6)) < 24 << 6)))
|
6264 |
|
|
/* load and store indexed -> dform. */
|
6265 |
|
|
insn = (32 | ((insn >> 6) & 31)) << 26;
|
6266 |
|
|
else if ((insn & (31 << 1)) == 21 << 1
|
6267 |
|
|
&& (insn & (0x1a << 6)) == 0)
|
6268 |
|
|
/* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
|
6269 |
|
|
insn = (((58 | ((insn >> 6) & 4)) << 26)
|
6270 |
|
|
| ((insn >> 6) & 1));
|
6271 |
|
|
else if ((insn & (31 << 1)) == 21 << 1
|
6272 |
|
|
&& (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
|
6273 |
|
|
/* lwax -> lwa. */
|
6274 |
|
|
insn = (58 << 26) | 2;
|
6275 |
|
|
else
|
6276 |
|
|
abort ();
|
6277 |
|
|
insn |= rtra;
|
6278 |
|
|
bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
|
6279 |
|
|
r_type = R_PPC_TPREL16_LO;
|
6280 |
|
|
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
|
6281 |
|
|
|
6282 |
|
|
/* Was PPC_TLS which sits on insn boundary, now
|
6283 |
|
|
PPC_TPREL16_LO which is at low-order half-word. */
|
6284 |
|
|
rel->r_offset += d_offset;
|
6285 |
|
|
}
|
6286 |
|
|
break;
|
6287 |
|
|
|
6288 |
|
|
case R_PPC_GOT_TLSGD16_HI:
|
6289 |
|
|
case R_PPC_GOT_TLSGD16_HA:
|
6290 |
|
|
tls_gd = TLS_TPRELGD;
|
6291 |
|
|
if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
|
6292 |
|
|
goto tls_gdld_hi;
|
6293 |
|
|
break;
|
6294 |
|
|
|
6295 |
|
|
case R_PPC_GOT_TLSLD16_HI:
|
6296 |
|
|
case R_PPC_GOT_TLSLD16_HA:
|
6297 |
|
|
if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
|
6298 |
|
|
{
|
6299 |
|
|
tls_gdld_hi:
|
6300 |
|
|
if ((tls_mask & tls_gd) != 0)
|
6301 |
|
|
r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
|
6302 |
|
|
+ R_PPC_GOT_TPREL16);
|
6303 |
|
|
else
|
6304 |
|
|
{
|
6305 |
|
|
bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
|
6306 |
|
|
rel->r_offset -= d_offset;
|
6307 |
|
|
r_type = R_PPC_NONE;
|
6308 |
|
|
}
|
6309 |
|
|
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
|
6310 |
|
|
}
|
6311 |
|
|
break;
|
6312 |
|
|
|
6313 |
|
|
case R_PPC_GOT_TLSGD16:
|
6314 |
|
|
case R_PPC_GOT_TLSGD16_LO:
|
6315 |
|
|
tls_gd = TLS_TPRELGD;
|
6316 |
|
|
if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
|
6317 |
|
|
goto tls_ldgd_opt;
|
6318 |
|
|
break;
|
6319 |
|
|
|
6320 |
|
|
case R_PPC_GOT_TLSLD16:
|
6321 |
|
|
case R_PPC_GOT_TLSLD16_LO:
|
6322 |
|
|
if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
|
6323 |
|
|
{
|
6324 |
|
|
bfd_vma insn1, insn2;
|
6325 |
|
|
bfd_vma offset;
|
6326 |
|
|
|
6327 |
|
|
tls_ldgd_opt:
|
6328 |
|
|
offset = rel[1].r_offset;
|
6329 |
|
|
insn1 = bfd_get_32 (output_bfd,
|
6330 |
|
|
contents + rel->r_offset - d_offset);
|
6331 |
|
|
if ((tls_mask & tls_gd) != 0)
|
6332 |
|
|
{
|
6333 |
|
|
/* IE */
|
6334 |
|
|
insn1 &= (1 << 26) - 1;
|
6335 |
|
|
insn1 |= 32 << 26; /* lwz */
|
6336 |
|
|
insn2 = 0x7c631214; /* add 3,3,2 */
|
6337 |
|
|
rel[1].r_info
|
6338 |
|
|
= ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info), R_PPC_NONE);
|
6339 |
|
|
rel[1].r_addend = 0;
|
6340 |
|
|
r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
|
6341 |
|
|
+ R_PPC_GOT_TPREL16);
|
6342 |
|
|
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
|
6343 |
|
|
}
|
6344 |
|
|
else
|
6345 |
|
|
{
|
6346 |
|
|
/* LE */
|
6347 |
|
|
insn1 = 0x3c620000; /* addis 3,2,0 */
|
6348 |
|
|
insn2 = 0x38630000; /* addi 3,3,0 */
|
6349 |
|
|
if (tls_gd == 0)
|
6350 |
|
|
{
|
6351 |
|
|
/* Was an LD reloc. */
|
6352 |
|
|
for (r_symndx = 0;
|
6353 |
|
|
r_symndx < symtab_hdr->sh_info;
|
6354 |
|
|
r_symndx++)
|
6355 |
|
|
if (local_sections[r_symndx] == sec)
|
6356 |
|
|
break;
|
6357 |
|
|
if (r_symndx >= symtab_hdr->sh_info)
|
6358 |
|
|
r_symndx = 0;
|
6359 |
|
|
rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
|
6360 |
|
|
if (r_symndx != 0)
|
6361 |
|
|
rel->r_addend -= (local_syms[r_symndx].st_value
|
6362 |
|
|
+ sec->output_offset
|
6363 |
|
|
+ sec->output_section->vma);
|
6364 |
|
|
}
|
6365 |
|
|
r_type = R_PPC_TPREL16_HA;
|
6366 |
|
|
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
|
6367 |
|
|
rel[1].r_info = ELF32_R_INFO (r_symndx,
|
6368 |
|
|
R_PPC_TPREL16_LO);
|
6369 |
|
|
rel[1].r_offset += d_offset;
|
6370 |
|
|
rel[1].r_addend = rel->r_addend;
|
6371 |
|
|
}
|
6372 |
|
|
bfd_put_32 (output_bfd, insn1,
|
6373 |
|
|
contents + rel->r_offset - d_offset);
|
6374 |
|
|
bfd_put_32 (output_bfd, insn2, contents + offset);
|
6375 |
|
|
if (tls_gd == 0)
|
6376 |
|
|
{
|
6377 |
|
|
/* We changed the symbol on an LD reloc. Start over
|
6378 |
|
|
in order to get h, sym, sec etc. right. */
|
6379 |
|
|
rel--;
|
6380 |
|
|
continue;
|
6381 |
|
|
}
|
6382 |
|
|
}
|
6383 |
|
|
break;
|
6384 |
|
|
}
|
6385 |
|
|
|
6386 |
|
|
/* Handle other relocations that tweak non-addend part of insn. */
|
6387 |
|
|
branch_bit = 0;
|
6388 |
|
|
switch (r_type)
|
6389 |
|
|
{
|
6390 |
|
|
default:
|
6391 |
|
|
break;
|
6392 |
|
|
|
6393 |
|
|
/* Branch taken prediction relocations. */
|
6394 |
|
|
case R_PPC_ADDR14_BRTAKEN:
|
6395 |
|
|
case R_PPC_REL14_BRTAKEN:
|
6396 |
|
|
branch_bit = BRANCH_PREDICT_BIT;
|
6397 |
|
|
/* Fall thru */
|
6398 |
|
|
|
6399 |
|
|
/* Branch not taken prediction relocations. */
|
6400 |
|
|
case R_PPC_ADDR14_BRNTAKEN:
|
6401 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
6402 |
|
|
insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
|
6403 |
|
|
insn &= ~BRANCH_PREDICT_BIT;
|
6404 |
|
|
insn |= branch_bit;
|
6405 |
|
|
|
6406 |
|
|
from = (rel->r_offset
|
6407 |
|
|
+ input_section->output_offset
|
6408 |
|
|
+ input_section->output_section->vma);
|
6409 |
|
|
|
6410 |
|
|
/* Invert 'y' bit if not the default. */
|
6411 |
|
|
if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
|
6412 |
|
|
insn ^= BRANCH_PREDICT_BIT;
|
6413 |
|
|
|
6414 |
|
|
bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
|
6415 |
|
|
break;
|
6416 |
|
|
}
|
6417 |
|
|
|
6418 |
|
|
addend = rel->r_addend;
|
6419 |
|
|
tls_type = 0;
|
6420 |
|
|
howto = NULL;
|
6421 |
|
|
if (r_type < R_PPC_max)
|
6422 |
|
|
howto = ppc_elf_howto_table[r_type];
|
6423 |
|
|
switch (r_type)
|
6424 |
|
|
{
|
6425 |
|
|
default:
|
6426 |
|
|
(*_bfd_error_handler)
|
6427 |
|
|
(_("%B: unknown relocation type %d for symbol %s"),
|
6428 |
|
|
input_bfd, (int) r_type, sym_name);
|
6429 |
|
|
|
6430 |
|
|
bfd_set_error (bfd_error_bad_value);
|
6431 |
|
|
ret = FALSE;
|
6432 |
|
|
continue;
|
6433 |
|
|
|
6434 |
|
|
case R_PPC_NONE:
|
6435 |
|
|
case R_PPC_TLS:
|
6436 |
|
|
case R_PPC_EMB_MRKREF:
|
6437 |
|
|
case R_PPC_GNU_VTINHERIT:
|
6438 |
|
|
case R_PPC_GNU_VTENTRY:
|
6439 |
|
|
continue;
|
6440 |
|
|
|
6441 |
|
|
/* GOT16 relocations. Like an ADDR16 using the symbol's
|
6442 |
|
|
address in the GOT as relocation value instead of the
|
6443 |
|
|
symbol's value itself. Also, create a GOT entry for the
|
6444 |
|
|
symbol and put the symbol value there. */
|
6445 |
|
|
case R_PPC_GOT_TLSGD16:
|
6446 |
|
|
case R_PPC_GOT_TLSGD16_LO:
|
6447 |
|
|
case R_PPC_GOT_TLSGD16_HI:
|
6448 |
|
|
case R_PPC_GOT_TLSGD16_HA:
|
6449 |
|
|
tls_type = TLS_TLS | TLS_GD;
|
6450 |
|
|
goto dogot;
|
6451 |
|
|
|
6452 |
|
|
case R_PPC_GOT_TLSLD16:
|
6453 |
|
|
case R_PPC_GOT_TLSLD16_LO:
|
6454 |
|
|
case R_PPC_GOT_TLSLD16_HI:
|
6455 |
|
|
case R_PPC_GOT_TLSLD16_HA:
|
6456 |
|
|
tls_type = TLS_TLS | TLS_LD;
|
6457 |
|
|
goto dogot;
|
6458 |
|
|
|
6459 |
|
|
case R_PPC_GOT_TPREL16:
|
6460 |
|
|
case R_PPC_GOT_TPREL16_LO:
|
6461 |
|
|
case R_PPC_GOT_TPREL16_HI:
|
6462 |
|
|
case R_PPC_GOT_TPREL16_HA:
|
6463 |
|
|
tls_type = TLS_TLS | TLS_TPREL;
|
6464 |
|
|
goto dogot;
|
6465 |
|
|
|
6466 |
|
|
case R_PPC_GOT_DTPREL16:
|
6467 |
|
|
case R_PPC_GOT_DTPREL16_LO:
|
6468 |
|
|
case R_PPC_GOT_DTPREL16_HI:
|
6469 |
|
|
case R_PPC_GOT_DTPREL16_HA:
|
6470 |
|
|
tls_type = TLS_TLS | TLS_DTPREL;
|
6471 |
|
|
goto dogot;
|
6472 |
|
|
|
6473 |
|
|
case R_PPC_GOT16:
|
6474 |
|
|
case R_PPC_GOT16_LO:
|
6475 |
|
|
case R_PPC_GOT16_HI:
|
6476 |
|
|
case R_PPC_GOT16_HA:
|
6477 |
|
|
dogot:
|
6478 |
|
|
{
|
6479 |
|
|
/* Relocation is to the entry for this symbol in the global
|
6480 |
|
|
offset table. */
|
6481 |
|
|
bfd_vma off;
|
6482 |
|
|
bfd_vma *offp;
|
6483 |
|
|
unsigned long indx;
|
6484 |
|
|
|
6485 |
|
|
if (htab->got == NULL)
|
6486 |
|
|
abort ();
|
6487 |
|
|
|
6488 |
|
|
indx = 0;
|
6489 |
|
|
if (tls_type == (TLS_TLS | TLS_LD)
|
6490 |
|
|
&& (h == NULL
|
6491 |
|
|
|| !h->def_dynamic))
|
6492 |
|
|
offp = &htab->tlsld_got.offset;
|
6493 |
|
|
else if (h != NULL)
|
6494 |
|
|
{
|
6495 |
|
|
bfd_boolean dyn;
|
6496 |
|
|
dyn = htab->elf.dynamic_sections_created;
|
6497 |
|
|
if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
|
6498 |
|
|
|| (info->shared
|
6499 |
|
|
&& SYMBOL_REFERENCES_LOCAL (info, h)))
|
6500 |
|
|
/* This is actually a static link, or it is a
|
6501 |
|
|
-Bsymbolic link and the symbol is defined
|
6502 |
|
|
locally, or the symbol was forced to be local
|
6503 |
|
|
because of a version file. */
|
6504 |
|
|
;
|
6505 |
|
|
else
|
6506 |
|
|
{
|
6507 |
|
|
indx = h->dynindx;
|
6508 |
|
|
unresolved_reloc = FALSE;
|
6509 |
|
|
}
|
6510 |
|
|
offp = &h->got.offset;
|
6511 |
|
|
}
|
6512 |
|
|
else
|
6513 |
|
|
{
|
6514 |
|
|
if (local_got_offsets == NULL)
|
6515 |
|
|
abort ();
|
6516 |
|
|
offp = &local_got_offsets[r_symndx];
|
6517 |
|
|
}
|
6518 |
|
|
|
6519 |
|
|
/* The offset must always be a multiple of 4. We use the
|
6520 |
|
|
least significant bit to record whether we have already
|
6521 |
|
|
processed this entry. */
|
6522 |
|
|
off = *offp;
|
6523 |
|
|
if ((off & 1) != 0)
|
6524 |
|
|
off &= ~1;
|
6525 |
|
|
else
|
6526 |
|
|
{
|
6527 |
|
|
unsigned int tls_m = (tls_mask
|
6528 |
|
|
& (TLS_LD | TLS_GD | TLS_DTPREL
|
6529 |
|
|
| TLS_TPREL | TLS_TPRELGD));
|
6530 |
|
|
|
6531 |
|
|
if (offp == &htab->tlsld_got.offset)
|
6532 |
|
|
tls_m = TLS_LD;
|
6533 |
|
|
else if (h == NULL
|
6534 |
|
|
|| !h->def_dynamic)
|
6535 |
|
|
tls_m &= ~TLS_LD;
|
6536 |
|
|
|
6537 |
|
|
/* We might have multiple got entries for this sym.
|
6538 |
|
|
Initialize them all. */
|
6539 |
|
|
do
|
6540 |
|
|
{
|
6541 |
|
|
int tls_ty = 0;
|
6542 |
|
|
|
6543 |
|
|
if ((tls_m & TLS_LD) != 0)
|
6544 |
|
|
{
|
6545 |
|
|
tls_ty = TLS_TLS | TLS_LD;
|
6546 |
|
|
tls_m &= ~TLS_LD;
|
6547 |
|
|
}
|
6548 |
|
|
else if ((tls_m & TLS_GD) != 0)
|
6549 |
|
|
{
|
6550 |
|
|
tls_ty = TLS_TLS | TLS_GD;
|
6551 |
|
|
tls_m &= ~TLS_GD;
|
6552 |
|
|
}
|
6553 |
|
|
else if ((tls_m & TLS_DTPREL) != 0)
|
6554 |
|
|
{
|
6555 |
|
|
tls_ty = TLS_TLS | TLS_DTPREL;
|
6556 |
|
|
tls_m &= ~TLS_DTPREL;
|
6557 |
|
|
}
|
6558 |
|
|
else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
|
6559 |
|
|
{
|
6560 |
|
|
tls_ty = TLS_TLS | TLS_TPREL;
|
6561 |
|
|
tls_m = 0;
|
6562 |
|
|
}
|
6563 |
|
|
|
6564 |
|
|
/* Generate relocs for the dynamic linker. */
|
6565 |
|
|
if ((info->shared || indx != 0)
|
6566 |
|
|
&& (offp == &htab->tlsld_got.offset
|
6567 |
|
|
|| h == NULL
|
6568 |
|
|
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|
6569 |
|
|
|| h->root.type != bfd_link_hash_undefweak))
|
6570 |
|
|
{
|
6571 |
|
|
outrel.r_offset = (htab->got->output_section->vma
|
6572 |
|
|
+ htab->got->output_offset
|
6573 |
|
|
+ off);
|
6574 |
|
|
outrel.r_addend = 0;
|
6575 |
|
|
if (tls_ty & (TLS_LD | TLS_GD))
|
6576 |
|
|
{
|
6577 |
|
|
outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
|
6578 |
|
|
if (tls_ty == (TLS_TLS | TLS_GD))
|
6579 |
|
|
{
|
6580 |
|
|
loc = htab->relgot->contents;
|
6581 |
|
|
loc += (htab->relgot->reloc_count++
|
6582 |
|
|
* sizeof (Elf32_External_Rela));
|
6583 |
|
|
bfd_elf32_swap_reloca_out (output_bfd,
|
6584 |
|
|
&outrel, loc);
|
6585 |
|
|
outrel.r_offset += 4;
|
6586 |
|
|
outrel.r_info
|
6587 |
|
|
= ELF32_R_INFO (indx, R_PPC_DTPREL32);
|
6588 |
|
|
}
|
6589 |
|
|
}
|
6590 |
|
|
else if (tls_ty == (TLS_TLS | TLS_DTPREL))
|
6591 |
|
|
outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
|
6592 |
|
|
else if (tls_ty == (TLS_TLS | TLS_TPREL))
|
6593 |
|
|
outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
|
6594 |
|
|
else if (indx == 0)
|
6595 |
|
|
outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
|
6596 |
|
|
else
|
6597 |
|
|
outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
|
6598 |
|
|
if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD))
|
6599 |
|
|
{
|
6600 |
|
|
outrel.r_addend += relocation;
|
6601 |
|
|
if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
|
6602 |
|
|
outrel.r_addend -= htab->elf.tls_sec->vma;
|
6603 |
|
|
}
|
6604 |
|
|
loc = htab->relgot->contents;
|
6605 |
|
|
loc += (htab->relgot->reloc_count++
|
6606 |
|
|
* sizeof (Elf32_External_Rela));
|
6607 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
|
6608 |
|
|
}
|
6609 |
|
|
|
6610 |
|
|
/* Init the .got section contents if we're not
|
6611 |
|
|
emitting a reloc. */
|
6612 |
|
|
else
|
6613 |
|
|
{
|
6614 |
|
|
bfd_vma value = relocation;
|
6615 |
|
|
|
6616 |
|
|
if (tls_ty == (TLS_TLS | TLS_LD))
|
6617 |
|
|
value = 1;
|
6618 |
|
|
else if (tls_ty != 0)
|
6619 |
|
|
{
|
6620 |
|
|
value -= htab->elf.tls_sec->vma + DTP_OFFSET;
|
6621 |
|
|
if (tls_ty == (TLS_TLS | TLS_TPREL))
|
6622 |
|
|
value += DTP_OFFSET - TP_OFFSET;
|
6623 |
|
|
|
6624 |
|
|
if (tls_ty == (TLS_TLS | TLS_GD))
|
6625 |
|
|
{
|
6626 |
|
|
bfd_put_32 (output_bfd, value,
|
6627 |
|
|
htab->got->contents + off + 4);
|
6628 |
|
|
value = 1;
|
6629 |
|
|
}
|
6630 |
|
|
}
|
6631 |
|
|
bfd_put_32 (output_bfd, value,
|
6632 |
|
|
htab->got->contents + off);
|
6633 |
|
|
}
|
6634 |
|
|
|
6635 |
|
|
off += 4;
|
6636 |
|
|
if (tls_ty & (TLS_LD | TLS_GD))
|
6637 |
|
|
off += 4;
|
6638 |
|
|
}
|
6639 |
|
|
while (tls_m != 0);
|
6640 |
|
|
|
6641 |
|
|
off = *offp;
|
6642 |
|
|
*offp = off | 1;
|
6643 |
|
|
}
|
6644 |
|
|
|
6645 |
|
|
if (off >= (bfd_vma) -2)
|
6646 |
|
|
abort ();
|
6647 |
|
|
|
6648 |
|
|
if ((tls_type & TLS_TLS) != 0)
|
6649 |
|
|
{
|
6650 |
|
|
if (tls_type != (TLS_TLS | TLS_LD))
|
6651 |
|
|
{
|
6652 |
|
|
if ((tls_mask & TLS_LD) != 0
|
6653 |
|
|
&& !(h == NULL
|
6654 |
|
|
|| !h->def_dynamic))
|
6655 |
|
|
off += 8;
|
6656 |
|
|
if (tls_type != (TLS_TLS | TLS_GD))
|
6657 |
|
|
{
|
6658 |
|
|
if ((tls_mask & TLS_GD) != 0)
|
6659 |
|
|
off += 8;
|
6660 |
|
|
if (tls_type != (TLS_TLS | TLS_DTPREL))
|
6661 |
|
|
{
|
6662 |
|
|
if ((tls_mask & TLS_DTPREL) != 0)
|
6663 |
|
|
off += 4;
|
6664 |
|
|
}
|
6665 |
|
|
}
|
6666 |
|
|
}
|
6667 |
|
|
}
|
6668 |
|
|
|
6669 |
|
|
relocation = (htab->got->output_section->vma
|
6670 |
|
|
+ htab->got->output_offset
|
6671 |
|
|
+ off
|
6672 |
|
|
- SYM_VAL (htab->elf.hgot));
|
6673 |
|
|
|
6674 |
|
|
/* Addends on got relocations don't make much sense.
|
6675 |
|
|
x+off@got is actually x@got+off, and since the got is
|
6676 |
|
|
generated by a hash table traversal, the value in the
|
6677 |
|
|
got at entry m+n bears little relation to the entry m. */
|
6678 |
|
|
if (addend != 0)
|
6679 |
|
|
(*_bfd_error_handler)
|
6680 |
|
|
(_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
|
6681 |
|
|
input_bfd,
|
6682 |
|
|
input_section,
|
6683 |
|
|
(long) rel->r_offset,
|
6684 |
|
|
howto->name,
|
6685 |
|
|
sym_name);
|
6686 |
|
|
}
|
6687 |
|
|
break;
|
6688 |
|
|
|
6689 |
|
|
/* Relocations that need no special processing. */
|
6690 |
|
|
case R_PPC_LOCAL24PC:
|
6691 |
|
|
/* It makes no sense to point a local relocation
|
6692 |
|
|
at a symbol not in this object. */
|
6693 |
|
|
if (unresolved_reloc)
|
6694 |
|
|
{
|
6695 |
|
|
if (! (*info->callbacks->undefined_symbol) (info,
|
6696 |
|
|
h->root.root.string,
|
6697 |
|
|
input_bfd,
|
6698 |
|
|
input_section,
|
6699 |
|
|
rel->r_offset,
|
6700 |
|
|
TRUE))
|
6701 |
|
|
return FALSE;
|
6702 |
|
|
continue;
|
6703 |
|
|
}
|
6704 |
|
|
break;
|
6705 |
|
|
|
6706 |
|
|
case R_PPC_DTPREL16:
|
6707 |
|
|
case R_PPC_DTPREL16_LO:
|
6708 |
|
|
case R_PPC_DTPREL16_HI:
|
6709 |
|
|
case R_PPC_DTPREL16_HA:
|
6710 |
|
|
addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
|
6711 |
|
|
break;
|
6712 |
|
|
|
6713 |
|
|
/* Relocations that may need to be propagated if this is a shared
|
6714 |
|
|
object. */
|
6715 |
|
|
case R_PPC_TPREL16:
|
6716 |
|
|
case R_PPC_TPREL16_LO:
|
6717 |
|
|
case R_PPC_TPREL16_HI:
|
6718 |
|
|
case R_PPC_TPREL16_HA:
|
6719 |
|
|
addend -= htab->elf.tls_sec->vma + TP_OFFSET;
|
6720 |
|
|
/* The TPREL16 relocs shouldn't really be used in shared
|
6721 |
|
|
libs as they will result in DT_TEXTREL being set, but
|
6722 |
|
|
support them anyway. */
|
6723 |
|
|
goto dodyn;
|
6724 |
|
|
|
6725 |
|
|
case R_PPC_TPREL32:
|
6726 |
|
|
addend -= htab->elf.tls_sec->vma + TP_OFFSET;
|
6727 |
|
|
goto dodyn;
|
6728 |
|
|
|
6729 |
|
|
case R_PPC_DTPREL32:
|
6730 |
|
|
addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
|
6731 |
|
|
goto dodyn;
|
6732 |
|
|
|
6733 |
|
|
case R_PPC_DTPMOD32:
|
6734 |
|
|
relocation = 1;
|
6735 |
|
|
addend = 0;
|
6736 |
|
|
goto dodyn;
|
6737 |
|
|
|
6738 |
|
|
case R_PPC_REL16:
|
6739 |
|
|
case R_PPC_REL16_LO:
|
6740 |
|
|
case R_PPC_REL16_HI:
|
6741 |
|
|
case R_PPC_REL16_HA:
|
6742 |
|
|
break;
|
6743 |
|
|
|
6744 |
|
|
case R_PPC_REL32:
|
6745 |
|
|
if (h == NULL || h == htab->elf.hgot)
|
6746 |
|
|
break;
|
6747 |
|
|
/* fall through */
|
6748 |
|
|
|
6749 |
|
|
case R_PPC_ADDR32:
|
6750 |
|
|
case R_PPC_ADDR16:
|
6751 |
|
|
case R_PPC_ADDR16_LO:
|
6752 |
|
|
case R_PPC_ADDR16_HI:
|
6753 |
|
|
case R_PPC_ADDR16_HA:
|
6754 |
|
|
case R_PPC_UADDR32:
|
6755 |
|
|
case R_PPC_UADDR16:
|
6756 |
|
|
goto dodyn;
|
6757 |
|
|
|
6758 |
|
|
case R_PPC_REL24:
|
6759 |
|
|
case R_PPC_REL14:
|
6760 |
|
|
case R_PPC_REL14_BRTAKEN:
|
6761 |
|
|
case R_PPC_REL14_BRNTAKEN:
|
6762 |
|
|
/* If these relocations are not to a named symbol, they can be
|
6763 |
|
|
handled right here, no need to bother the dynamic linker. */
|
6764 |
|
|
if (SYMBOL_CALLS_LOCAL (info, h)
|
6765 |
|
|
|| h == htab->elf.hgot)
|
6766 |
|
|
break;
|
6767 |
|
|
/* fall through */
|
6768 |
|
|
|
6769 |
|
|
case R_PPC_ADDR24:
|
6770 |
|
|
case R_PPC_ADDR14:
|
6771 |
|
|
case R_PPC_ADDR14_BRTAKEN:
|
6772 |
|
|
case R_PPC_ADDR14_BRNTAKEN:
|
6773 |
|
|
if (h != NULL && !info->shared)
|
6774 |
|
|
break;
|
6775 |
|
|
/* fall through */
|
6776 |
|
|
|
6777 |
|
|
dodyn:
|
6778 |
|
|
if ((input_section->flags & SEC_ALLOC) == 0
|
6779 |
|
|
|| is_vxworks_tls)
|
6780 |
|
|
break;
|
6781 |
|
|
|
6782 |
|
|
if ((info->shared
|
6783 |
|
|
&& !(h != NULL
|
6784 |
|
|
&& ((h->root.type == bfd_link_hash_undefined
|
6785 |
|
|
&& (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
|
6786 |
|
|
|| ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
|
6787 |
|
|
|| (h->root.type == bfd_link_hash_undefweak
|
6788 |
|
|
&& ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)))
|
6789 |
|
|
&& (must_be_dyn_reloc (info, r_type)
|
6790 |
|
|
|| !SYMBOL_CALLS_LOCAL (info, h)))
|
6791 |
|
|
|| (ELIMINATE_COPY_RELOCS
|
6792 |
|
|
&& !info->shared
|
6793 |
|
|
&& h != NULL
|
6794 |
|
|
&& h->dynindx != -1
|
6795 |
|
|
&& !h->non_got_ref
|
6796 |
|
|
&& !h->def_regular))
|
6797 |
|
|
{
|
6798 |
|
|
int skip;
|
6799 |
|
|
|
6800 |
|
|
#ifdef DEBUG
|
6801 |
|
|
fprintf (stderr, "ppc_elf_relocate_section needs to "
|
6802 |
|
|
"create relocation for %s\n",
|
6803 |
|
|
(h && h->root.root.string
|
6804 |
|
|
? h->root.root.string : "<unknown>"));
|
6805 |
|
|
#endif
|
6806 |
|
|
|
6807 |
|
|
/* When generating a shared object, these relocations
|
6808 |
|
|
are copied into the output file to be resolved at run
|
6809 |
|
|
time. */
|
6810 |
|
|
if (sreloc == NULL)
|
6811 |
|
|
{
|
6812 |
|
|
const char *name;
|
6813 |
|
|
|
6814 |
|
|
name = (bfd_elf_string_from_elf_section
|
6815 |
|
|
(input_bfd,
|
6816 |
|
|
elf_elfheader (input_bfd)->e_shstrndx,
|
6817 |
|
|
elf_section_data (input_section)->rel_hdr.sh_name));
|
6818 |
|
|
if (name == NULL)
|
6819 |
|
|
return FALSE;
|
6820 |
|
|
|
6821 |
|
|
BFD_ASSERT (CONST_STRNEQ (name, ".rela")
|
6822 |
|
|
&& strcmp (bfd_get_section_name (input_bfd,
|
6823 |
|
|
input_section),
|
6824 |
|
|
name + 5) == 0);
|
6825 |
|
|
|
6826 |
|
|
sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
|
6827 |
|
|
BFD_ASSERT (sreloc != NULL);
|
6828 |
|
|
}
|
6829 |
|
|
|
6830 |
|
|
skip = 0;
|
6831 |
|
|
outrel.r_offset =
|
6832 |
|
|
_bfd_elf_section_offset (output_bfd, info, input_section,
|
6833 |
|
|
rel->r_offset);
|
6834 |
|
|
if (outrel.r_offset == (bfd_vma) -1
|
6835 |
|
|
|| outrel.r_offset == (bfd_vma) -2)
|
6836 |
|
|
skip = (int) outrel.r_offset;
|
6837 |
|
|
outrel.r_offset += (input_section->output_section->vma
|
6838 |
|
|
+ input_section->output_offset);
|
6839 |
|
|
|
6840 |
|
|
if (skip)
|
6841 |
|
|
memset (&outrel, 0, sizeof outrel);
|
6842 |
|
|
else if ((h != NULL
|
6843 |
|
|
&& (h->root.type == bfd_link_hash_undefined
|
6844 |
|
|
|| h->root.type == bfd_link_hash_undefweak))
|
6845 |
|
|
|| !SYMBOL_REFERENCES_LOCAL (info, h))
|
6846 |
|
|
{
|
6847 |
|
|
unresolved_reloc = FALSE;
|
6848 |
|
|
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
|
6849 |
|
|
outrel.r_addend = rel->r_addend;
|
6850 |
|
|
}
|
6851 |
|
|
else
|
6852 |
|
|
{
|
6853 |
|
|
outrel.r_addend = relocation + rel->r_addend;
|
6854 |
|
|
|
6855 |
|
|
if (r_type == R_PPC_ADDR32)
|
6856 |
|
|
outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
|
6857 |
|
|
else
|
6858 |
|
|
{
|
6859 |
|
|
long indx = 0;
|
6860 |
|
|
|
6861 |
|
|
if (r_symndx == 0 || bfd_is_abs_section (sec))
|
6862 |
|
|
;
|
6863 |
|
|
else if (sec == NULL || sec->owner == NULL)
|
6864 |
|
|
{
|
6865 |
|
|
bfd_set_error (bfd_error_bad_value);
|
6866 |
|
|
ret = FALSE;
|
6867 |
|
|
}
|
6868 |
|
|
else
|
6869 |
|
|
{
|
6870 |
|
|
asection *osec;
|
6871 |
|
|
|
6872 |
|
|
/* We are turning this relocation into one
|
6873 |
|
|
against a section symbol. It would be
|
6874 |
|
|
proper to subtract the symbol's value,
|
6875 |
|
|
osec->vma, from the emitted reloc addend,
|
6876 |
|
|
but ld.so expects buggy relocs. */
|
6877 |
|
|
osec = sec->output_section;
|
6878 |
|
|
indx = elf_section_data (osec)->dynindx;
|
6879 |
|
|
if (indx == 0)
|
6880 |
|
|
{
|
6881 |
|
|
osec = htab->elf.text_index_section;
|
6882 |
|
|
indx = elf_section_data (osec)->dynindx;
|
6883 |
|
|
}
|
6884 |
|
|
BFD_ASSERT (indx != 0);
|
6885 |
|
|
#ifdef DEBUG
|
6886 |
|
|
if (indx == 0)
|
6887 |
|
|
printf ("indx=%ld section=%s flags=%08x name=%s\n",
|
6888 |
|
|
indx, osec->name, osec->flags,
|
6889 |
|
|
h->root.root.string);
|
6890 |
|
|
#endif
|
6891 |
|
|
}
|
6892 |
|
|
|
6893 |
|
|
outrel.r_info = ELF32_R_INFO (indx, r_type);
|
6894 |
|
|
}
|
6895 |
|
|
}
|
6896 |
|
|
|
6897 |
|
|
loc = sreloc->contents;
|
6898 |
|
|
loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
|
6899 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
|
6900 |
|
|
|
6901 |
|
|
if (skip == -1)
|
6902 |
|
|
continue;
|
6903 |
|
|
|
6904 |
|
|
/* This reloc will be computed at runtime. We clear the memory
|
6905 |
|
|
so that it contains predictable value. */
|
6906 |
|
|
if (! skip
|
6907 |
|
|
&& ((input_section->flags & SEC_ALLOC) != 0
|
6908 |
|
|
|| ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
|
6909 |
|
|
{
|
6910 |
|
|
relocation = howto->pc_relative ? outrel.r_offset : 0;
|
6911 |
|
|
addend = 0;
|
6912 |
|
|
break;
|
6913 |
|
|
}
|
6914 |
|
|
}
|
6915 |
|
|
break;
|
6916 |
|
|
|
6917 |
|
|
case R_PPC_RELAX32PC_PLT:
|
6918 |
|
|
case R_PPC_RELAX32_PLT:
|
6919 |
|
|
{
|
6920 |
|
|
struct plt_entry *ent = find_plt_ent (h, got2, addend);
|
6921 |
|
|
|
6922 |
|
|
if (htab->plt_type == PLT_NEW)
|
6923 |
|
|
relocation = (htab->glink->output_section->vma
|
6924 |
|
|
+ htab->glink->output_offset
|
6925 |
|
|
+ ent->glink_offset);
|
6926 |
|
|
else
|
6927 |
|
|
relocation = (htab->plt->output_section->vma
|
6928 |
|
|
+ htab->plt->output_offset
|
6929 |
|
|
+ ent->plt.offset);
|
6930 |
|
|
}
|
6931 |
|
|
if (r_type == R_PPC_RELAX32_PLT)
|
6932 |
|
|
goto relax32;
|
6933 |
|
|
/* Fall thru */
|
6934 |
|
|
|
6935 |
|
|
case R_PPC_RELAX32PC:
|
6936 |
|
|
relocation -= (input_section->output_section->vma
|
6937 |
|
|
+ input_section->output_offset
|
6938 |
|
|
+ rel->r_offset - 4);
|
6939 |
|
|
/* Fall thru */
|
6940 |
|
|
|
6941 |
|
|
case R_PPC_RELAX32:
|
6942 |
|
|
relax32:
|
6943 |
|
|
{
|
6944 |
|
|
unsigned long t0;
|
6945 |
|
|
unsigned long t1;
|
6946 |
|
|
|
6947 |
|
|
t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
|
6948 |
|
|
t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
|
6949 |
|
|
|
6950 |
|
|
/* We're clearing the bits for R_PPC_ADDR16_HA
|
6951 |
|
|
and R_PPC_ADDR16_LO here. */
|
6952 |
|
|
t0 &= ~0xffff;
|
6953 |
|
|
t1 &= ~0xffff;
|
6954 |
|
|
|
6955 |
|
|
/* t0 is HA, t1 is LO */
|
6956 |
|
|
relocation += addend;
|
6957 |
|
|
t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
|
6958 |
|
|
t1 |= relocation & 0xffff;
|
6959 |
|
|
|
6960 |
|
|
bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
|
6961 |
|
|
bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
|
6962 |
|
|
}
|
6963 |
|
|
continue;
|
6964 |
|
|
|
6965 |
|
|
/* Indirect .sdata relocation. */
|
6966 |
|
|
case R_PPC_EMB_SDAI16:
|
6967 |
|
|
BFD_ASSERT (htab->sdata[0].section != NULL);
|
6968 |
|
|
relocation
|
6969 |
|
|
= elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
|
6970 |
|
|
h, relocation, rel);
|
6971 |
|
|
break;
|
6972 |
|
|
|
6973 |
|
|
/* Indirect .sdata2 relocation. */
|
6974 |
|
|
case R_PPC_EMB_SDA2I16:
|
6975 |
|
|
BFD_ASSERT (htab->sdata[1].section != NULL);
|
6976 |
|
|
relocation
|
6977 |
|
|
= elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
|
6978 |
|
|
h, relocation, rel);
|
6979 |
|
|
break;
|
6980 |
|
|
|
6981 |
|
|
/* Handle the TOC16 reloc. We want to use the offset within the .got
|
6982 |
|
|
section, not the actual VMA. This is appropriate when generating
|
6983 |
|
|
an embedded ELF object, for which the .got section acts like the
|
6984 |
|
|
AIX .toc section. */
|
6985 |
|
|
case R_PPC_TOC16: /* phony GOT16 relocations */
|
6986 |
|
|
if (sec == NULL || sec->output_section == NULL)
|
6987 |
|
|
{
|
6988 |
|
|
unresolved_reloc = TRUE;
|
6989 |
|
|
break;
|
6990 |
|
|
}
|
6991 |
|
|
BFD_ASSERT (strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
|
6992 |
|
|
|| strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
|
6993 |
|
|
|
6994 |
|
|
addend -= sec->output_section->vma + sec->output_offset + 0x8000;
|
6995 |
|
|
break;
|
6996 |
|
|
|
6997 |
|
|
case R_PPC_PLTREL24:
|
6998 |
|
|
/* Relocation is to the entry for this symbol in the
|
6999 |
|
|
procedure linkage table. */
|
7000 |
|
|
{
|
7001 |
|
|
struct plt_entry *ent = find_plt_ent (h, got2, addend);
|
7002 |
|
|
|
7003 |
|
|
addend = 0;
|
7004 |
|
|
if (ent == NULL
|
7005 |
|
|
|| htab->plt == NULL)
|
7006 |
|
|
{
|
7007 |
|
|
/* We didn't make a PLT entry for this symbol. This
|
7008 |
|
|
happens when statically linking PIC code, or when
|
7009 |
|
|
using -Bsymbolic. */
|
7010 |
|
|
break;
|
7011 |
|
|
}
|
7012 |
|
|
|
7013 |
|
|
unresolved_reloc = FALSE;
|
7014 |
|
|
if (htab->plt_type == PLT_NEW)
|
7015 |
|
|
relocation = (htab->glink->output_section->vma
|
7016 |
|
|
+ htab->glink->output_offset
|
7017 |
|
|
+ ent->glink_offset);
|
7018 |
|
|
else
|
7019 |
|
|
relocation = (htab->plt->output_section->vma
|
7020 |
|
|
+ htab->plt->output_offset
|
7021 |
|
|
+ ent->plt.offset);
|
7022 |
|
|
}
|
7023 |
|
|
break;
|
7024 |
|
|
|
7025 |
|
|
/* Relocate against _SDA_BASE_. */
|
7026 |
|
|
case R_PPC_SDAREL16:
|
7027 |
|
|
{
|
7028 |
|
|
const char *name;
|
7029 |
|
|
|
7030 |
|
|
if (sec == NULL || sec->output_section == NULL)
|
7031 |
|
|
{
|
7032 |
|
|
unresolved_reloc = TRUE;
|
7033 |
|
|
break;
|
7034 |
|
|
}
|
7035 |
|
|
|
7036 |
|
|
name = bfd_get_section_name (abfd, sec->output_section);
|
7037 |
|
|
if (! ((CONST_STRNEQ (name, ".sdata")
|
7038 |
|
|
&& (name[6] == 0 || name[6] == '.'))
|
7039 |
|
|
|| (CONST_STRNEQ (name, ".sbss")
|
7040 |
|
|
&& (name[5] == 0 || name[5] == '.'))))
|
7041 |
|
|
{
|
7042 |
|
|
(*_bfd_error_handler)
|
7043 |
|
|
(_("%B: the target (%s) of a %s relocation is "
|
7044 |
|
|
"in the wrong output section (%s)"),
|
7045 |
|
|
input_bfd,
|
7046 |
|
|
sym_name,
|
7047 |
|
|
howto->name,
|
7048 |
|
|
name);
|
7049 |
|
|
}
|
7050 |
|
|
addend -= SYM_VAL (htab->sdata[0].sym);
|
7051 |
|
|
}
|
7052 |
|
|
break;
|
7053 |
|
|
|
7054 |
|
|
/* Relocate against _SDA2_BASE_. */
|
7055 |
|
|
case R_PPC_EMB_SDA2REL:
|
7056 |
|
|
{
|
7057 |
|
|
const char *name;
|
7058 |
|
|
|
7059 |
|
|
if (sec == NULL || sec->output_section == NULL)
|
7060 |
|
|
{
|
7061 |
|
|
unresolved_reloc = TRUE;
|
7062 |
|
|
break;
|
7063 |
|
|
}
|
7064 |
|
|
|
7065 |
|
|
name = bfd_get_section_name (abfd, sec->output_section);
|
7066 |
|
|
if (! (CONST_STRNEQ (name, ".sdata2")
|
7067 |
|
|
|| CONST_STRNEQ (name, ".sbss2")))
|
7068 |
|
|
{
|
7069 |
|
|
(*_bfd_error_handler)
|
7070 |
|
|
(_("%B: the target (%s) of a %s relocation is "
|
7071 |
|
|
"in the wrong output section (%s)"),
|
7072 |
|
|
input_bfd,
|
7073 |
|
|
sym_name,
|
7074 |
|
|
howto->name,
|
7075 |
|
|
name);
|
7076 |
|
|
|
7077 |
|
|
bfd_set_error (bfd_error_bad_value);
|
7078 |
|
|
ret = FALSE;
|
7079 |
|
|
continue;
|
7080 |
|
|
}
|
7081 |
|
|
addend -= SYM_VAL (htab->sdata[1].sym);
|
7082 |
|
|
}
|
7083 |
|
|
break;
|
7084 |
|
|
|
7085 |
|
|
/* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
|
7086 |
|
|
case R_PPC_EMB_SDA21:
|
7087 |
|
|
case R_PPC_EMB_RELSDA:
|
7088 |
|
|
{
|
7089 |
|
|
const char *name;
|
7090 |
|
|
int reg;
|
7091 |
|
|
|
7092 |
|
|
if (sec == NULL || sec->output_section == NULL)
|
7093 |
|
|
{
|
7094 |
|
|
unresolved_reloc = TRUE;
|
7095 |
|
|
break;
|
7096 |
|
|
}
|
7097 |
|
|
|
7098 |
|
|
name = bfd_get_section_name (abfd, sec->output_section);
|
7099 |
|
|
if (((CONST_STRNEQ (name, ".sdata")
|
7100 |
|
|
&& (name[6] == 0 || name[6] == '.'))
|
7101 |
|
|
|| (CONST_STRNEQ (name, ".sbss")
|
7102 |
|
|
&& (name[5] == 0 || name[5] == '.'))))
|
7103 |
|
|
{
|
7104 |
|
|
reg = 13;
|
7105 |
|
|
addend -= SYM_VAL (htab->sdata[0].sym);
|
7106 |
|
|
}
|
7107 |
|
|
else if (CONST_STRNEQ (name, ".sdata2")
|
7108 |
|
|
|| CONST_STRNEQ (name, ".sbss2"))
|
7109 |
|
|
{
|
7110 |
|
|
reg = 2;
|
7111 |
|
|
addend -= SYM_VAL (htab->sdata[1].sym);
|
7112 |
|
|
}
|
7113 |
|
|
else if (strcmp (name, ".PPC.EMB.sdata0") == 0
|
7114 |
|
|
|| strcmp (name, ".PPC.EMB.sbss0") == 0)
|
7115 |
|
|
{
|
7116 |
|
|
reg = 0;
|
7117 |
|
|
}
|
7118 |
|
|
else
|
7119 |
|
|
{
|
7120 |
|
|
(*_bfd_error_handler)
|
7121 |
|
|
(_("%B: the target (%s) of a %s relocation is "
|
7122 |
|
|
"in the wrong output section (%s)"),
|
7123 |
|
|
input_bfd,
|
7124 |
|
|
sym_name,
|
7125 |
|
|
howto->name,
|
7126 |
|
|
name);
|
7127 |
|
|
|
7128 |
|
|
bfd_set_error (bfd_error_bad_value);
|
7129 |
|
|
ret = FALSE;
|
7130 |
|
|
continue;
|
7131 |
|
|
}
|
7132 |
|
|
|
7133 |
|
|
if (r_type == R_PPC_EMB_SDA21)
|
7134 |
|
|
{ /* fill in register field */
|
7135 |
|
|
insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
|
7136 |
|
|
insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
|
7137 |
|
|
bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
|
7138 |
|
|
}
|
7139 |
|
|
}
|
7140 |
|
|
break;
|
7141 |
|
|
|
7142 |
|
|
/* Relocate against the beginning of the section. */
|
7143 |
|
|
case R_PPC_SECTOFF:
|
7144 |
|
|
case R_PPC_SECTOFF_LO:
|
7145 |
|
|
case R_PPC_SECTOFF_HI:
|
7146 |
|
|
case R_PPC_SECTOFF_HA:
|
7147 |
|
|
if (sec == NULL || sec->output_section == NULL)
|
7148 |
|
|
{
|
7149 |
|
|
unresolved_reloc = TRUE;
|
7150 |
|
|
break;
|
7151 |
|
|
}
|
7152 |
|
|
addend -= sec->output_section->vma;
|
7153 |
|
|
break;
|
7154 |
|
|
|
7155 |
|
|
/* Negative relocations. */
|
7156 |
|
|
case R_PPC_EMB_NADDR32:
|
7157 |
|
|
case R_PPC_EMB_NADDR16:
|
7158 |
|
|
case R_PPC_EMB_NADDR16_LO:
|
7159 |
|
|
case R_PPC_EMB_NADDR16_HI:
|
7160 |
|
|
case R_PPC_EMB_NADDR16_HA:
|
7161 |
|
|
addend -= 2 * relocation;
|
7162 |
|
|
break;
|
7163 |
|
|
|
7164 |
|
|
case R_PPC_COPY:
|
7165 |
|
|
case R_PPC_GLOB_DAT:
|
7166 |
|
|
case R_PPC_JMP_SLOT:
|
7167 |
|
|
case R_PPC_RELATIVE:
|
7168 |
|
|
case R_PPC_PLT32:
|
7169 |
|
|
case R_PPC_PLTREL32:
|
7170 |
|
|
case R_PPC_PLT16_LO:
|
7171 |
|
|
case R_PPC_PLT16_HI:
|
7172 |
|
|
case R_PPC_PLT16_HA:
|
7173 |
|
|
case R_PPC_ADDR30:
|
7174 |
|
|
case R_PPC_EMB_RELSEC16:
|
7175 |
|
|
case R_PPC_EMB_RELST_LO:
|
7176 |
|
|
case R_PPC_EMB_RELST_HI:
|
7177 |
|
|
case R_PPC_EMB_RELST_HA:
|
7178 |
|
|
case R_PPC_EMB_BIT_FLD:
|
7179 |
|
|
(*_bfd_error_handler)
|
7180 |
|
|
(_("%B: relocation %s is not yet supported for symbol %s."),
|
7181 |
|
|
input_bfd,
|
7182 |
|
|
howto->name,
|
7183 |
|
|
sym_name);
|
7184 |
|
|
|
7185 |
|
|
bfd_set_error (bfd_error_invalid_operation);
|
7186 |
|
|
ret = FALSE;
|
7187 |
|
|
continue;
|
7188 |
|
|
}
|
7189 |
|
|
|
7190 |
|
|
/* Do any further special processing. */
|
7191 |
|
|
switch (r_type)
|
7192 |
|
|
{
|
7193 |
|
|
default:
|
7194 |
|
|
break;
|
7195 |
|
|
|
7196 |
|
|
case R_PPC_ADDR16_HA:
|
7197 |
|
|
case R_PPC_REL16_HA:
|
7198 |
|
|
case R_PPC_SECTOFF_HA:
|
7199 |
|
|
case R_PPC_TPREL16_HA:
|
7200 |
|
|
case R_PPC_DTPREL16_HA:
|
7201 |
|
|
case R_PPC_EMB_NADDR16_HA:
|
7202 |
|
|
case R_PPC_EMB_RELST_HA:
|
7203 |
|
|
/* It's just possible that this symbol is a weak symbol
|
7204 |
|
|
that's not actually defined anywhere. In that case,
|
7205 |
|
|
'sec' would be NULL, and we should leave the symbol
|
7206 |
|
|
alone (it will be set to zero elsewhere in the link). */
|
7207 |
|
|
if (sec == NULL)
|
7208 |
|
|
break;
|
7209 |
|
|
/* Fall thru */
|
7210 |
|
|
|
7211 |
|
|
case R_PPC_PLT16_HA:
|
7212 |
|
|
case R_PPC_GOT16_HA:
|
7213 |
|
|
case R_PPC_GOT_TLSGD16_HA:
|
7214 |
|
|
case R_PPC_GOT_TLSLD16_HA:
|
7215 |
|
|
case R_PPC_GOT_TPREL16_HA:
|
7216 |
|
|
case R_PPC_GOT_DTPREL16_HA:
|
7217 |
|
|
/* Add 0x10000 if sign bit in 0:15 is set.
|
7218 |
|
|
Bits 0:15 are not used. */
|
7219 |
|
|
addend += 0x8000;
|
7220 |
|
|
break;
|
7221 |
|
|
}
|
7222 |
|
|
|
7223 |
|
|
#ifdef DEBUG
|
7224 |
|
|
fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
|
7225 |
|
|
"offset = %ld, addend = %ld\n",
|
7226 |
|
|
howto->name,
|
7227 |
|
|
(int) r_type,
|
7228 |
|
|
sym_name,
|
7229 |
|
|
r_symndx,
|
7230 |
|
|
(long) rel->r_offset,
|
7231 |
|
|
(long) addend);
|
7232 |
|
|
#endif
|
7233 |
|
|
|
7234 |
|
|
if (unresolved_reloc
|
7235 |
|
|
&& !((input_section->flags & SEC_DEBUGGING) != 0
|
7236 |
|
|
&& h->def_dynamic))
|
7237 |
|
|
{
|
7238 |
|
|
(*_bfd_error_handler)
|
7239 |
|
|
(_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
|
7240 |
|
|
input_bfd,
|
7241 |
|
|
input_section,
|
7242 |
|
|
(long) rel->r_offset,
|
7243 |
|
|
howto->name,
|
7244 |
|
|
sym_name);
|
7245 |
|
|
ret = FALSE;
|
7246 |
|
|
}
|
7247 |
|
|
|
7248 |
|
|
r = _bfd_final_link_relocate (howto,
|
7249 |
|
|
input_bfd,
|
7250 |
|
|
input_section,
|
7251 |
|
|
contents,
|
7252 |
|
|
rel->r_offset,
|
7253 |
|
|
relocation,
|
7254 |
|
|
addend);
|
7255 |
|
|
|
7256 |
|
|
if (r != bfd_reloc_ok)
|
7257 |
|
|
{
|
7258 |
|
|
if (r == bfd_reloc_overflow)
|
7259 |
|
|
{
|
7260 |
|
|
if (warned)
|
7261 |
|
|
continue;
|
7262 |
|
|
if (h != NULL
|
7263 |
|
|
&& h->root.type == bfd_link_hash_undefweak
|
7264 |
|
|
&& howto->pc_relative)
|
7265 |
|
|
{
|
7266 |
|
|
/* Assume this is a call protected by other code that
|
7267 |
|
|
detect the symbol is undefined. If this is the case,
|
7268 |
|
|
we can safely ignore the overflow. If not, the
|
7269 |
|
|
program is hosed anyway, and a little warning isn't
|
7270 |
|
|
going to help. */
|
7271 |
|
|
|
7272 |
|
|
continue;
|
7273 |
|
|
}
|
7274 |
|
|
|
7275 |
|
|
if (! (*info->callbacks->reloc_overflow) (info,
|
7276 |
|
|
(h ? &h->root : NULL),
|
7277 |
|
|
sym_name,
|
7278 |
|
|
howto->name,
|
7279 |
|
|
rel->r_addend,
|
7280 |
|
|
input_bfd,
|
7281 |
|
|
input_section,
|
7282 |
|
|
rel->r_offset))
|
7283 |
|
|
return FALSE;
|
7284 |
|
|
}
|
7285 |
|
|
else
|
7286 |
|
|
{
|
7287 |
|
|
(*_bfd_error_handler)
|
7288 |
|
|
(_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
|
7289 |
|
|
input_bfd, input_section,
|
7290 |
|
|
(long) rel->r_offset, howto->name, sym_name, (int) r);
|
7291 |
|
|
ret = FALSE;
|
7292 |
|
|
}
|
7293 |
|
|
}
|
7294 |
|
|
}
|
7295 |
|
|
|
7296 |
|
|
#ifdef DEBUG
|
7297 |
|
|
fprintf (stderr, "\n");
|
7298 |
|
|
#endif
|
7299 |
|
|
|
7300 |
|
|
return ret;
|
7301 |
|
|
}
|
7302 |
|
|
|
7303 |
|
|
#define PPC_LO(v) ((v) & 0xffff)
|
7304 |
|
|
#define PPC_HI(v) (((v) >> 16) & 0xffff)
|
7305 |
|
|
#define PPC_HA(v) PPC_HI ((v) + 0x8000)
|
7306 |
|
|
|
7307 |
|
|
/* Finish up dynamic symbol handling. We set the contents of various
|
7308 |
|
|
dynamic sections here. */
|
7309 |
|
|
|
7310 |
|
|
static bfd_boolean
|
7311 |
|
|
ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
|
7312 |
|
|
struct bfd_link_info *info,
|
7313 |
|
|
struct elf_link_hash_entry *h,
|
7314 |
|
|
Elf_Internal_Sym *sym)
|
7315 |
|
|
{
|
7316 |
|
|
struct ppc_elf_link_hash_table *htab;
|
7317 |
|
|
struct plt_entry *ent;
|
7318 |
|
|
bfd_boolean doneone;
|
7319 |
|
|
|
7320 |
|
|
#ifdef DEBUG
|
7321 |
|
|
fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
|
7322 |
|
|
h->root.root.string);
|
7323 |
|
|
#endif
|
7324 |
|
|
|
7325 |
|
|
htab = ppc_elf_hash_table (info);
|
7326 |
|
|
BFD_ASSERT (htab->elf.dynobj != NULL);
|
7327 |
|
|
|
7328 |
|
|
doneone = FALSE;
|
7329 |
|
|
for (ent = h->plt.plist; ent != NULL; ent = ent->next)
|
7330 |
|
|
if (ent->plt.offset != (bfd_vma) -1)
|
7331 |
|
|
{
|
7332 |
|
|
if (!doneone)
|
7333 |
|
|
{
|
7334 |
|
|
Elf_Internal_Rela rela;
|
7335 |
|
|
bfd_byte *loc;
|
7336 |
|
|
bfd_vma reloc_index;
|
7337 |
|
|
|
7338 |
|
|
if (htab->plt_type == PLT_NEW)
|
7339 |
|
|
reloc_index = ent->plt.offset / 4;
|
7340 |
|
|
else
|
7341 |
|
|
{
|
7342 |
|
|
reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
|
7343 |
|
|
/ htab->plt_slot_size);
|
7344 |
|
|
if (reloc_index > PLT_NUM_SINGLE_ENTRIES
|
7345 |
|
|
&& htab->plt_type == PLT_OLD)
|
7346 |
|
|
reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
|
7347 |
|
|
}
|
7348 |
|
|
|
7349 |
|
|
/* This symbol has an entry in the procedure linkage table.
|
7350 |
|
|
Set it up. */
|
7351 |
|
|
if (htab->plt_type == PLT_VXWORKS)
|
7352 |
|
|
{
|
7353 |
|
|
bfd_vma got_offset;
|
7354 |
|
|
const bfd_vma *plt_entry;
|
7355 |
|
|
|
7356 |
|
|
/* The first three entries in .got.plt are reserved. */
|
7357 |
|
|
got_offset = (reloc_index + 3) * 4;
|
7358 |
|
|
|
7359 |
|
|
/* Use the right PLT. */
|
7360 |
|
|
plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry
|
7361 |
|
|
: ppc_elf_vxworks_plt_entry;
|
7362 |
|
|
|
7363 |
|
|
/* Fill in the .plt on VxWorks. */
|
7364 |
|
|
if (info->shared)
|
7365 |
|
|
{
|
7366 |
|
|
bfd_put_32 (output_bfd,
|
7367 |
|
|
plt_entry[0] | PPC_HA (got_offset),
|
7368 |
|
|
htab->plt->contents + ent->plt.offset + 0);
|
7369 |
|
|
bfd_put_32 (output_bfd,
|
7370 |
|
|
plt_entry[1] | PPC_LO (got_offset),
|
7371 |
|
|
htab->plt->contents + ent->plt.offset + 4);
|
7372 |
|
|
}
|
7373 |
|
|
else
|
7374 |
|
|
{
|
7375 |
|
|
bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot);
|
7376 |
|
|
|
7377 |
|
|
bfd_put_32 (output_bfd,
|
7378 |
|
|
plt_entry[0] | PPC_HA (got_loc),
|
7379 |
|
|
htab->plt->contents + ent->plt.offset + 0);
|
7380 |
|
|
bfd_put_32 (output_bfd,
|
7381 |
|
|
plt_entry[1] | PPC_LO (got_loc),
|
7382 |
|
|
htab->plt->contents + ent->plt.offset + 4);
|
7383 |
|
|
}
|
7384 |
|
|
|
7385 |
|
|
bfd_put_32 (output_bfd, plt_entry[2],
|
7386 |
|
|
htab->plt->contents + ent->plt.offset + 8);
|
7387 |
|
|
bfd_put_32 (output_bfd, plt_entry[3],
|
7388 |
|
|
htab->plt->contents + ent->plt.offset + 12);
|
7389 |
|
|
|
7390 |
|
|
/* This instruction is an immediate load. The value loaded is
|
7391 |
|
|
the byte offset of the R_PPC_JMP_SLOT relocation from the
|
7392 |
|
|
start of the .rela.plt section. The value is stored in the
|
7393 |
|
|
low-order 16 bits of the load instruction. */
|
7394 |
|
|
/* NOTE: It appears that this is now an index rather than a
|
7395 |
|
|
prescaled offset. */
|
7396 |
|
|
bfd_put_32 (output_bfd,
|
7397 |
|
|
plt_entry[4] | reloc_index,
|
7398 |
|
|
htab->plt->contents + ent->plt.offset + 16);
|
7399 |
|
|
/* This instruction is a PC-relative branch whose target is
|
7400 |
|
|
the start of the PLT section. The address of this branch
|
7401 |
|
|
instruction is 20 bytes beyond the start of this PLT entry.
|
7402 |
|
|
The address is encoded in bits 6-29, inclusive. The value
|
7403 |
|
|
stored is right-shifted by two bits, permitting a 26-bit
|
7404 |
|
|
offset. */
|
7405 |
|
|
bfd_put_32 (output_bfd,
|
7406 |
|
|
(plt_entry[5]
|
7407 |
|
|
| (-(ent->plt.offset + 20) & 0x03fffffc)),
|
7408 |
|
|
htab->plt->contents + ent->plt.offset + 20);
|
7409 |
|
|
bfd_put_32 (output_bfd, plt_entry[6],
|
7410 |
|
|
htab->plt->contents + ent->plt.offset + 24);
|
7411 |
|
|
bfd_put_32 (output_bfd, plt_entry[7],
|
7412 |
|
|
htab->plt->contents + ent->plt.offset + 28);
|
7413 |
|
|
|
7414 |
|
|
/* Fill in the GOT entry corresponding to this PLT slot with
|
7415 |
|
|
the address immediately after the the "bctr" instruction
|
7416 |
|
|
in this PLT entry. */
|
7417 |
|
|
bfd_put_32 (output_bfd, (htab->plt->output_section->vma
|
7418 |
|
|
+ htab->plt->output_offset
|
7419 |
|
|
+ ent->plt.offset + 16),
|
7420 |
|
|
htab->sgotplt->contents + got_offset);
|
7421 |
|
|
|
7422 |
|
|
if (!info->shared)
|
7423 |
|
|
{
|
7424 |
|
|
/* Fill in a couple of entries in .rela.plt.unloaded. */
|
7425 |
|
|
loc = htab->srelplt2->contents
|
7426 |
|
|
+ ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index
|
7427 |
|
|
* VXWORKS_PLT_NON_JMP_SLOT_RELOCS)
|
7428 |
|
|
* sizeof (Elf32_External_Rela));
|
7429 |
|
|
|
7430 |
|
|
/* Provide the @ha relocation for the first instruction. */
|
7431 |
|
|
rela.r_offset = (htab->plt->output_section->vma
|
7432 |
|
|
+ htab->plt->output_offset
|
7433 |
|
|
+ ent->plt.offset + 2);
|
7434 |
|
|
rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
|
7435 |
|
|
R_PPC_ADDR16_HA);
|
7436 |
|
|
rela.r_addend = got_offset;
|
7437 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7438 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7439 |
|
|
|
7440 |
|
|
/* Provide the @l relocation for the second instruction. */
|
7441 |
|
|
rela.r_offset = (htab->plt->output_section->vma
|
7442 |
|
|
+ htab->plt->output_offset
|
7443 |
|
|
+ ent->plt.offset + 6);
|
7444 |
|
|
rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
|
7445 |
|
|
R_PPC_ADDR16_LO);
|
7446 |
|
|
rela.r_addend = got_offset;
|
7447 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7448 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7449 |
|
|
|
7450 |
|
|
/* Provide a relocation for the GOT entry corresponding to this
|
7451 |
|
|
PLT slot. Point it at the middle of the .plt entry. */
|
7452 |
|
|
rela.r_offset = (htab->sgotplt->output_section->vma
|
7453 |
|
|
+ htab->sgotplt->output_offset
|
7454 |
|
|
+ got_offset);
|
7455 |
|
|
rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
|
7456 |
|
|
R_PPC_ADDR32);
|
7457 |
|
|
rela.r_addend = ent->plt.offset + 16;
|
7458 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7459 |
|
|
}
|
7460 |
|
|
|
7461 |
|
|
/* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
|
7462 |
|
|
In particular, the offset for the relocation is not the
|
7463 |
|
|
address of the PLT entry for this function, as specified
|
7464 |
|
|
by the ABI. Instead, the offset is set to the address of
|
7465 |
|
|
the GOT slot for this function. See EABI 4.4.4.1. */
|
7466 |
|
|
rela.r_offset = (htab->sgotplt->output_section->vma
|
7467 |
|
|
+ htab->sgotplt->output_offset
|
7468 |
|
|
+ got_offset);
|
7469 |
|
|
|
7470 |
|
|
}
|
7471 |
|
|
else
|
7472 |
|
|
{
|
7473 |
|
|
rela.r_offset = (htab->plt->output_section->vma
|
7474 |
|
|
+ htab->plt->output_offset
|
7475 |
|
|
+ ent->plt.offset);
|
7476 |
|
|
if (htab->plt_type == PLT_OLD)
|
7477 |
|
|
{
|
7478 |
|
|
/* We don't need to fill in the .plt. The ppc dynamic
|
7479 |
|
|
linker will fill it in. */
|
7480 |
|
|
}
|
7481 |
|
|
else
|
7482 |
|
|
{
|
7483 |
|
|
bfd_vma val = (htab->glink_pltresolve + ent->plt.offset
|
7484 |
|
|
+ htab->glink->output_section->vma
|
7485 |
|
|
+ htab->glink->output_offset);
|
7486 |
|
|
bfd_put_32 (output_bfd, val,
|
7487 |
|
|
htab->plt->contents + ent->plt.offset);
|
7488 |
|
|
}
|
7489 |
|
|
}
|
7490 |
|
|
|
7491 |
|
|
/* Fill in the entry in the .rela.plt section. */
|
7492 |
|
|
rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
|
7493 |
|
|
rela.r_addend = 0;
|
7494 |
|
|
|
7495 |
|
|
loc = (htab->relplt->contents
|
7496 |
|
|
+ reloc_index * sizeof (Elf32_External_Rela));
|
7497 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7498 |
|
|
|
7499 |
|
|
if (!h->def_regular)
|
7500 |
|
|
{
|
7501 |
|
|
/* Mark the symbol as undefined, rather than as
|
7502 |
|
|
defined in the .plt section. Leave the value if
|
7503 |
|
|
there were any relocations where pointer equality
|
7504 |
|
|
matters (this is a clue for the dynamic linker, to
|
7505 |
|
|
make function pointer comparisons work between an
|
7506 |
|
|
application and shared library), otherwise set it
|
7507 |
|
|
to zero. */
|
7508 |
|
|
sym->st_shndx = SHN_UNDEF;
|
7509 |
|
|
if (!h->pointer_equality_needed)
|
7510 |
|
|
sym->st_value = 0;
|
7511 |
|
|
else if (!h->ref_regular_nonweak)
|
7512 |
|
|
{
|
7513 |
|
|
/* This breaks function pointer comparisons, but
|
7514 |
|
|
that is better than breaking tests for a NULL
|
7515 |
|
|
function pointer. */
|
7516 |
|
|
sym->st_value = 0;
|
7517 |
|
|
}
|
7518 |
|
|
}
|
7519 |
|
|
doneone = TRUE;
|
7520 |
|
|
}
|
7521 |
|
|
|
7522 |
|
|
if (htab->plt_type == PLT_NEW)
|
7523 |
|
|
{
|
7524 |
|
|
bfd_vma plt;
|
7525 |
|
|
unsigned char *p;
|
7526 |
|
|
|
7527 |
|
|
plt = (ent->plt.offset
|
7528 |
|
|
+ htab->plt->output_section->vma
|
7529 |
|
|
+ htab->plt->output_offset);
|
7530 |
|
|
p = (unsigned char *) htab->glink->contents + ent->glink_offset;
|
7531 |
|
|
|
7532 |
|
|
if (info->shared || info->pie)
|
7533 |
|
|
{
|
7534 |
|
|
bfd_vma got = 0;
|
7535 |
|
|
|
7536 |
|
|
if (ent->addend >= 32768)
|
7537 |
|
|
got = (ent->addend
|
7538 |
|
|
+ ent->sec->output_section->vma
|
7539 |
|
|
+ ent->sec->output_offset);
|
7540 |
|
|
else if (htab->elf.hgot != NULL)
|
7541 |
|
|
got = SYM_VAL (htab->elf.hgot);
|
7542 |
|
|
|
7543 |
|
|
plt -= got;
|
7544 |
|
|
|
7545 |
|
|
if (plt + 0x8000 < 0x10000)
|
7546 |
|
|
{
|
7547 |
|
|
bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p);
|
7548 |
|
|
p += 4;
|
7549 |
|
|
bfd_put_32 (output_bfd, MTCTR_11, p);
|
7550 |
|
|
p += 4;
|
7551 |
|
|
bfd_put_32 (output_bfd, BCTR, p);
|
7552 |
|
|
p += 4;
|
7553 |
|
|
bfd_put_32 (output_bfd, NOP, p);
|
7554 |
|
|
p += 4;
|
7555 |
|
|
}
|
7556 |
|
|
else
|
7557 |
|
|
{
|
7558 |
|
|
bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p);
|
7559 |
|
|
p += 4;
|
7560 |
|
|
bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
|
7561 |
|
|
p += 4;
|
7562 |
|
|
bfd_put_32 (output_bfd, MTCTR_11, p);
|
7563 |
|
|
p += 4;
|
7564 |
|
|
bfd_put_32 (output_bfd, BCTR, p);
|
7565 |
|
|
p += 4;
|
7566 |
|
|
}
|
7567 |
|
|
}
|
7568 |
|
|
else
|
7569 |
|
|
{
|
7570 |
|
|
bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p);
|
7571 |
|
|
p += 4;
|
7572 |
|
|
bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
|
7573 |
|
|
p += 4;
|
7574 |
|
|
bfd_put_32 (output_bfd, MTCTR_11, p);
|
7575 |
|
|
p += 4;
|
7576 |
|
|
bfd_put_32 (output_bfd, BCTR, p);
|
7577 |
|
|
p += 4;
|
7578 |
|
|
|
7579 |
|
|
/* We only need one non-PIC glink stub. */
|
7580 |
|
|
break;
|
7581 |
|
|
}
|
7582 |
|
|
}
|
7583 |
|
|
else
|
7584 |
|
|
break;
|
7585 |
|
|
}
|
7586 |
|
|
|
7587 |
|
|
if (h->needs_copy)
|
7588 |
|
|
{
|
7589 |
|
|
asection *s;
|
7590 |
|
|
Elf_Internal_Rela rela;
|
7591 |
|
|
bfd_byte *loc;
|
7592 |
|
|
|
7593 |
|
|
/* This symbols needs a copy reloc. Set it up. */
|
7594 |
|
|
|
7595 |
|
|
#ifdef DEBUG
|
7596 |
|
|
fprintf (stderr, ", copy");
|
7597 |
|
|
#endif
|
7598 |
|
|
|
7599 |
|
|
BFD_ASSERT (h->dynindx != -1);
|
7600 |
|
|
|
7601 |
|
|
if (ppc_elf_hash_entry (h)->has_sda_refs)
|
7602 |
|
|
s = htab->relsbss;
|
7603 |
|
|
else
|
7604 |
|
|
s = htab->relbss;
|
7605 |
|
|
BFD_ASSERT (s != NULL);
|
7606 |
|
|
|
7607 |
|
|
rela.r_offset = SYM_VAL (h);
|
7608 |
|
|
rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
|
7609 |
|
|
rela.r_addend = 0;
|
7610 |
|
|
loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
|
7611 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7612 |
|
|
}
|
7613 |
|
|
|
7614 |
|
|
#ifdef DEBUG
|
7615 |
|
|
fprintf (stderr, "\n");
|
7616 |
|
|
#endif
|
7617 |
|
|
|
7618 |
|
|
/* Mark some specially defined symbols as absolute. */
|
7619 |
|
|
if (strcmp (h->root.root.string, "_DYNAMIC") == 0
|
7620 |
|
|
|| (!htab->is_vxworks
|
7621 |
|
|
&& (h == htab->elf.hgot
|
7622 |
|
|
|| strcmp (h->root.root.string,
|
7623 |
|
|
"_PROCEDURE_LINKAGE_TABLE_") == 0)))
|
7624 |
|
|
sym->st_shndx = SHN_ABS;
|
7625 |
|
|
|
7626 |
|
|
return TRUE;
|
7627 |
|
|
}
|
7628 |
|
|
|
7629 |
|
|
static enum elf_reloc_type_class
|
7630 |
|
|
ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
|
7631 |
|
|
{
|
7632 |
|
|
switch (ELF32_R_TYPE (rela->r_info))
|
7633 |
|
|
{
|
7634 |
|
|
case R_PPC_RELATIVE:
|
7635 |
|
|
return reloc_class_relative;
|
7636 |
|
|
case R_PPC_REL24:
|
7637 |
|
|
case R_PPC_ADDR24:
|
7638 |
|
|
case R_PPC_JMP_SLOT:
|
7639 |
|
|
return reloc_class_plt;
|
7640 |
|
|
case R_PPC_COPY:
|
7641 |
|
|
return reloc_class_copy;
|
7642 |
|
|
default:
|
7643 |
|
|
return reloc_class_normal;
|
7644 |
|
|
}
|
7645 |
|
|
}
|
7646 |
|
|
|
7647 |
|
|
/* Finish up the dynamic sections. */
|
7648 |
|
|
|
7649 |
|
|
static bfd_boolean
|
7650 |
|
|
ppc_elf_finish_dynamic_sections (bfd *output_bfd,
|
7651 |
|
|
struct bfd_link_info *info)
|
7652 |
|
|
{
|
7653 |
|
|
asection *sdyn;
|
7654 |
|
|
asection *splt;
|
7655 |
|
|
struct ppc_elf_link_hash_table *htab;
|
7656 |
|
|
bfd_vma got;
|
7657 |
|
|
bfd *dynobj;
|
7658 |
|
|
bfd_boolean ret = TRUE;
|
7659 |
|
|
|
7660 |
|
|
#ifdef DEBUG
|
7661 |
|
|
fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
|
7662 |
|
|
#endif
|
7663 |
|
|
|
7664 |
|
|
htab = ppc_elf_hash_table (info);
|
7665 |
|
|
dynobj = elf_hash_table (info)->dynobj;
|
7666 |
|
|
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
|
7667 |
|
|
if (htab->is_vxworks)
|
7668 |
|
|
splt = bfd_get_section_by_name (dynobj, ".plt");
|
7669 |
|
|
else
|
7670 |
|
|
splt = NULL;
|
7671 |
|
|
|
7672 |
|
|
got = 0;
|
7673 |
|
|
if (htab->elf.hgot != NULL)
|
7674 |
|
|
got = SYM_VAL (htab->elf.hgot);
|
7675 |
|
|
|
7676 |
|
|
if (htab->elf.dynamic_sections_created)
|
7677 |
|
|
{
|
7678 |
|
|
Elf32_External_Dyn *dyncon, *dynconend;
|
7679 |
|
|
|
7680 |
|
|
BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
|
7681 |
|
|
|
7682 |
|
|
dyncon = (Elf32_External_Dyn *) sdyn->contents;
|
7683 |
|
|
dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
|
7684 |
|
|
for (; dyncon < dynconend; dyncon++)
|
7685 |
|
|
{
|
7686 |
|
|
Elf_Internal_Dyn dyn;
|
7687 |
|
|
asection *s;
|
7688 |
|
|
|
7689 |
|
|
bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
|
7690 |
|
|
|
7691 |
|
|
switch (dyn.d_tag)
|
7692 |
|
|
{
|
7693 |
|
|
case DT_PLTGOT:
|
7694 |
|
|
if (htab->is_vxworks)
|
7695 |
|
|
s = htab->sgotplt;
|
7696 |
|
|
else
|
7697 |
|
|
s = htab->plt;
|
7698 |
|
|
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
|
7699 |
|
|
break;
|
7700 |
|
|
|
7701 |
|
|
case DT_PLTRELSZ:
|
7702 |
|
|
dyn.d_un.d_val = htab->relplt->size;
|
7703 |
|
|
break;
|
7704 |
|
|
|
7705 |
|
|
case DT_JMPREL:
|
7706 |
|
|
s = htab->relplt;
|
7707 |
|
|
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
|
7708 |
|
|
break;
|
7709 |
|
|
|
7710 |
|
|
case DT_PPC_GOT:
|
7711 |
|
|
dyn.d_un.d_ptr = got;
|
7712 |
|
|
break;
|
7713 |
|
|
|
7714 |
|
|
case DT_RELASZ:
|
7715 |
|
|
if (htab->is_vxworks)
|
7716 |
|
|
{
|
7717 |
|
|
if (htab->relplt)
|
7718 |
|
|
dyn.d_un.d_ptr -= htab->relplt->size;
|
7719 |
|
|
break;
|
7720 |
|
|
}
|
7721 |
|
|
continue;
|
7722 |
|
|
|
7723 |
|
|
default:
|
7724 |
|
|
if (htab->is_vxworks
|
7725 |
|
|
&& elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
|
7726 |
|
|
break;
|
7727 |
|
|
continue;
|
7728 |
|
|
}
|
7729 |
|
|
|
7730 |
|
|
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
|
7731 |
|
|
}
|
7732 |
|
|
}
|
7733 |
|
|
|
7734 |
|
|
if (htab->got != NULL)
|
7735 |
|
|
{
|
7736 |
|
|
if (htab->elf.hgot->root.u.def.section == htab->got
|
7737 |
|
|
|| htab->elf.hgot->root.u.def.section == htab->sgotplt)
|
7738 |
|
|
{
|
7739 |
|
|
unsigned char *p = htab->elf.hgot->root.u.def.section->contents;
|
7740 |
|
|
|
7741 |
|
|
p += htab->elf.hgot->root.u.def.value;
|
7742 |
|
|
if (htab->plt_type == PLT_OLD)
|
7743 |
|
|
{
|
7744 |
|
|
/* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
|
7745 |
|
|
so that a function can easily find the address of
|
7746 |
|
|
_GLOBAL_OFFSET_TABLE_. */
|
7747 |
|
|
BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4
|
7748 |
|
|
< htab->elf.hgot->root.u.def.section->size);
|
7749 |
|
|
bfd_put_32 (output_bfd, 0x4e800021, p - 4);
|
7750 |
|
|
}
|
7751 |
|
|
|
7752 |
|
|
if (sdyn != NULL)
|
7753 |
|
|
{
|
7754 |
|
|
bfd_vma val = sdyn->output_section->vma + sdyn->output_offset;
|
7755 |
|
|
BFD_ASSERT (htab->elf.hgot->root.u.def.value
|
7756 |
|
|
< htab->elf.hgot->root.u.def.section->size);
|
7757 |
|
|
bfd_put_32 (output_bfd, val, p);
|
7758 |
|
|
}
|
7759 |
|
|
}
|
7760 |
|
|
else
|
7761 |
|
|
{
|
7762 |
|
|
(*_bfd_error_handler) (_("%s not defined in linker created %s"),
|
7763 |
|
|
htab->elf.hgot->root.root.string,
|
7764 |
|
|
(htab->sgotplt != NULL
|
7765 |
|
|
? htab->sgotplt->name : htab->got->name));
|
7766 |
|
|
bfd_set_error (bfd_error_bad_value);
|
7767 |
|
|
ret = FALSE;
|
7768 |
|
|
}
|
7769 |
|
|
|
7770 |
|
|
elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
|
7771 |
|
|
}
|
7772 |
|
|
|
7773 |
|
|
/* Fill in the first entry in the VxWorks procedure linkage table. */
|
7774 |
|
|
if (splt && splt->size > 0)
|
7775 |
|
|
{
|
7776 |
|
|
/* Use the right PLT. */
|
7777 |
|
|
static const bfd_vma *plt_entry = NULL;
|
7778 |
|
|
plt_entry = info->shared ?
|
7779 |
|
|
ppc_elf_vxworks_pic_plt0_entry : ppc_elf_vxworks_plt0_entry;
|
7780 |
|
|
|
7781 |
|
|
if (!info->shared)
|
7782 |
|
|
{
|
7783 |
|
|
bfd_vma got_value = SYM_VAL (htab->elf.hgot);
|
7784 |
|
|
|
7785 |
|
|
bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value),
|
7786 |
|
|
splt->contents + 0);
|
7787 |
|
|
bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value),
|
7788 |
|
|
splt->contents + 4);
|
7789 |
|
|
}
|
7790 |
|
|
else
|
7791 |
|
|
{
|
7792 |
|
|
bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0);
|
7793 |
|
|
bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4);
|
7794 |
|
|
}
|
7795 |
|
|
bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8);
|
7796 |
|
|
bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12);
|
7797 |
|
|
bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16);
|
7798 |
|
|
bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20);
|
7799 |
|
|
bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
|
7800 |
|
|
bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
|
7801 |
|
|
|
7802 |
|
|
if (! info->shared)
|
7803 |
|
|
{
|
7804 |
|
|
Elf_Internal_Rela rela;
|
7805 |
|
|
bfd_byte *loc;
|
7806 |
|
|
|
7807 |
|
|
loc = htab->srelplt2->contents;
|
7808 |
|
|
|
7809 |
|
|
/* Output the @ha relocation for the first instruction. */
|
7810 |
|
|
rela.r_offset = (htab->plt->output_section->vma
|
7811 |
|
|
+ htab->plt->output_offset
|
7812 |
|
|
+ 2);
|
7813 |
|
|
rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
|
7814 |
|
|
rela.r_addend = 0;
|
7815 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7816 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7817 |
|
|
|
7818 |
|
|
/* Output the @l relocation for the second instruction. */
|
7819 |
|
|
rela.r_offset = (htab->plt->output_section->vma
|
7820 |
|
|
+ htab->plt->output_offset
|
7821 |
|
|
+ 6);
|
7822 |
|
|
rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
|
7823 |
|
|
rela.r_addend = 0;
|
7824 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
|
7825 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7826 |
|
|
|
7827 |
|
|
/* Fix up the remaining relocations. They may have the wrong
|
7828 |
|
|
symbol index for _G_O_T_ or _P_L_T_ depending on the order
|
7829 |
|
|
in which symbols were output. */
|
7830 |
|
|
while (loc < htab->srelplt2->contents + htab->srelplt2->size)
|
7831 |
|
|
{
|
7832 |
|
|
Elf_Internal_Rela rel;
|
7833 |
|
|
|
7834 |
|
|
bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
|
7835 |
|
|
rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
|
7836 |
|
|
bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
|
7837 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7838 |
|
|
|
7839 |
|
|
bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
|
7840 |
|
|
rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
|
7841 |
|
|
bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
|
7842 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7843 |
|
|
|
7844 |
|
|
bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
|
7845 |
|
|
rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
|
7846 |
|
|
bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
|
7847 |
|
|
loc += sizeof (Elf32_External_Rela);
|
7848 |
|
|
}
|
7849 |
|
|
}
|
7850 |
|
|
}
|
7851 |
|
|
|
7852 |
|
|
if (htab->glink != NULL && htab->glink->contents != NULL)
|
7853 |
|
|
{
|
7854 |
|
|
unsigned char *p;
|
7855 |
|
|
unsigned char *endp;
|
7856 |
|
|
bfd_vma res0;
|
7857 |
|
|
unsigned int i;
|
7858 |
|
|
|
7859 |
|
|
/*
|
7860 |
|
|
* PIC glink code is the following:
|
7861 |
|
|
*
|
7862 |
|
|
* # ith PLT code stub.
|
7863 |
|
|
* addis 11,30,(plt+(i-1)*4-got)@ha
|
7864 |
|
|
* lwz 11,(plt+(i-1)*4-got)@l(11)
|
7865 |
|
|
* mtctr 11
|
7866 |
|
|
* bctr
|
7867 |
|
|
*
|
7868 |
|
|
* # A table of branches, one for each plt entry.
|
7869 |
|
|
* # The idea is that the plt call stub loads ctr and r11 with these
|
7870 |
|
|
* # addresses, so (r11 - res_0) gives the plt index * 4.
|
7871 |
|
|
* res_0: b PLTresolve
|
7872 |
|
|
* res_1: b PLTresolve
|
7873 |
|
|
* .
|
7874 |
|
|
* # Some number of entries towards the end can be nops
|
7875 |
|
|
* res_n_m3: nop
|
7876 |
|
|
* res_n_m2: nop
|
7877 |
|
|
* res_n_m1:
|
7878 |
|
|
*
|
7879 |
|
|
* PLTresolve:
|
7880 |
|
|
* addis 11,11,(1f-res_0)@ha
|
7881 |
|
|
* mflr 0
|
7882 |
|
|
* bcl 20,31,1f
|
7883 |
|
|
* 1: addi 11,11,(1b-res_0)@l
|
7884 |
|
|
* mflr 12
|
7885 |
|
|
* mtlr 0
|
7886 |
|
|
* sub 11,11,12 # r11 = index * 4
|
7887 |
|
|
* addis 12,12,(got+4-1b)@ha
|
7888 |
|
|
* lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
|
7889 |
|
|
* lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
|
7890 |
|
|
* mtctr 0
|
7891 |
|
|
* add 0,11,11
|
7892 |
|
|
* add 11,0,11 # r11 = index * 12 = reloc offset.
|
7893 |
|
|
* bctr
|
7894 |
|
|
*/
|
7895 |
|
|
static const unsigned int pic_plt_resolve[] =
|
7896 |
|
|
{
|
7897 |
|
|
ADDIS_11_11,
|
7898 |
|
|
MFLR_0,
|
7899 |
|
|
BCL_20_31,
|
7900 |
|
|
ADDI_11_11,
|
7901 |
|
|
MFLR_12,
|
7902 |
|
|
MTLR_0,
|
7903 |
|
|
SUB_11_11_12,
|
7904 |
|
|
ADDIS_12_12,
|
7905 |
|
|
LWZ_0_12,
|
7906 |
|
|
LWZ_12_12,
|
7907 |
|
|
MTCTR_0,
|
7908 |
|
|
ADD_0_11_11,
|
7909 |
|
|
ADD_11_0_11,
|
7910 |
|
|
BCTR,
|
7911 |
|
|
NOP,
|
7912 |
|
|
NOP
|
7913 |
|
|
};
|
7914 |
|
|
|
7915 |
|
|
/*
|
7916 |
|
|
* Non-PIC glink code is a little simpler.
|
7917 |
|
|
*
|
7918 |
|
|
* # ith PLT code stub.
|
7919 |
|
|
* lis 11,(plt+(i-1)*4)@ha
|
7920 |
|
|
* lwz 11,(plt+(i-1)*4)@l(11)
|
7921 |
|
|
* mtctr 11
|
7922 |
|
|
* bctr
|
7923 |
|
|
*
|
7924 |
|
|
* The branch table is the same, then comes
|
7925 |
|
|
*
|
7926 |
|
|
* PLTresolve:
|
7927 |
|
|
* lis 12,(got+4)@ha
|
7928 |
|
|
* addis 11,11,(-res_0)@ha
|
7929 |
|
|
* lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
|
7930 |
|
|
* addi 11,11,(-res_0)@l # r11 = index * 4
|
7931 |
|
|
* mtctr 0
|
7932 |
|
|
* add 0,11,11
|
7933 |
|
|
* lwz 12,(got+8)@l(12) # got[2] contains the map address
|
7934 |
|
|
* add 11,0,11 # r11 = index * 12 = reloc offset.
|
7935 |
|
|
* bctr
|
7936 |
|
|
*/
|
7937 |
|
|
static const unsigned int plt_resolve[] =
|
7938 |
|
|
{
|
7939 |
|
|
LIS_12,
|
7940 |
|
|
ADDIS_11_11,
|
7941 |
|
|
LWZ_0_12,
|
7942 |
|
|
ADDI_11_11,
|
7943 |
|
|
MTCTR_0,
|
7944 |
|
|
ADD_0_11_11,
|
7945 |
|
|
LWZ_12_12,
|
7946 |
|
|
ADD_11_0_11,
|
7947 |
|
|
BCTR,
|
7948 |
|
|
NOP,
|
7949 |
|
|
NOP,
|
7950 |
|
|
NOP,
|
7951 |
|
|
NOP,
|
7952 |
|
|
NOP,
|
7953 |
|
|
NOP,
|
7954 |
|
|
NOP
|
7955 |
|
|
};
|
7956 |
|
|
|
7957 |
|
|
if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4)
|
7958 |
|
|
abort ();
|
7959 |
|
|
if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4)
|
7960 |
|
|
abort ();
|
7961 |
|
|
|
7962 |
|
|
/* Build the branch table, one for each plt entry (less one),
|
7963 |
|
|
and perhaps some padding. */
|
7964 |
|
|
p = htab->glink->contents;
|
7965 |
|
|
p += htab->glink_pltresolve;
|
7966 |
|
|
endp = htab->glink->contents;
|
7967 |
|
|
endp += htab->glink->size - GLINK_PLTRESOLVE;
|
7968 |
|
|
while (p < endp - 8 * 4)
|
7969 |
|
|
{
|
7970 |
|
|
bfd_put_32 (output_bfd, B + endp - p, p);
|
7971 |
|
|
p += 4;
|
7972 |
|
|
}
|
7973 |
|
|
while (p < endp)
|
7974 |
|
|
{
|
7975 |
|
|
bfd_put_32 (output_bfd, NOP, p);
|
7976 |
|
|
p += 4;
|
7977 |
|
|
}
|
7978 |
|
|
|
7979 |
|
|
res0 = (htab->glink_pltresolve
|
7980 |
|
|
+ htab->glink->output_section->vma
|
7981 |
|
|
+ htab->glink->output_offset);
|
7982 |
|
|
|
7983 |
|
|
/* Last comes the PLTresolve stub. */
|
7984 |
|
|
if (info->shared || info->pie)
|
7985 |
|
|
{
|
7986 |
|
|
bfd_vma bcl;
|
7987 |
|
|
|
7988 |
|
|
for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++)
|
7989 |
|
|
{
|
7990 |
|
|
bfd_put_32 (output_bfd, pic_plt_resolve[i], p);
|
7991 |
|
|
p += 4;
|
7992 |
|
|
}
|
7993 |
|
|
p -= 4 * ARRAY_SIZE (pic_plt_resolve);
|
7994 |
|
|
|
7995 |
|
|
bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4
|
7996 |
|
|
+ htab->glink->output_section->vma
|
7997 |
|
|
+ htab->glink->output_offset);
|
7998 |
|
|
|
7999 |
|
|
bfd_put_32 (output_bfd,
|
8000 |
|
|
ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4);
|
8001 |
|
|
bfd_put_32 (output_bfd,
|
8002 |
|
|
ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4);
|
8003 |
|
|
bfd_put_32 (output_bfd,
|
8004 |
|
|
ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4);
|
8005 |
|
|
if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl))
|
8006 |
|
|
{
|
8007 |
|
|
bfd_put_32 (output_bfd,
|
8008 |
|
|
LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
|
8009 |
|
|
bfd_put_32 (output_bfd,
|
8010 |
|
|
LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4);
|
8011 |
|
|
}
|
8012 |
|
|
else
|
8013 |
|
|
{
|
8014 |
|
|
bfd_put_32 (output_bfd,
|
8015 |
|
|
LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
|
8016 |
|
|
bfd_put_32 (output_bfd,
|
8017 |
|
|
LWZ_12_12 + 4, p + 9*4);
|
8018 |
|
|
}
|
8019 |
|
|
}
|
8020 |
|
|
else
|
8021 |
|
|
{
|
8022 |
|
|
for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
|
8023 |
|
|
{
|
8024 |
|
|
bfd_put_32 (output_bfd, plt_resolve[i], p);
|
8025 |
|
|
p += 4;
|
8026 |
|
|
}
|
8027 |
|
|
p -= 4 * ARRAY_SIZE (plt_resolve);
|
8028 |
|
|
|
8029 |
|
|
bfd_put_32 (output_bfd,
|
8030 |
|
|
LIS_12 + PPC_HA (got + 4), p + 0*4);
|
8031 |
|
|
bfd_put_32 (output_bfd,
|
8032 |
|
|
ADDIS_11_11 + PPC_HA (-res0), p + 1*4);
|
8033 |
|
|
bfd_put_32 (output_bfd,
|
8034 |
|
|
ADDI_11_11 + PPC_LO (-res0), p + 3*4);
|
8035 |
|
|
if (PPC_HA (got + 4) == PPC_HA (got + 8))
|
8036 |
|
|
{
|
8037 |
|
|
bfd_put_32 (output_bfd,
|
8038 |
|
|
LWZ_0_12 + PPC_LO (got + 4), p + 2*4);
|
8039 |
|
|
bfd_put_32 (output_bfd,
|
8040 |
|
|
LWZ_12_12 + PPC_LO (got + 8), p + 6*4);
|
8041 |
|
|
}
|
8042 |
|
|
else
|
8043 |
|
|
{
|
8044 |
|
|
bfd_put_32 (output_bfd,
|
8045 |
|
|
LWZU_0_12 + PPC_LO (got + 4), p + 2*4);
|
8046 |
|
|
bfd_put_32 (output_bfd,
|
8047 |
|
|
LWZ_12_12 + 4, p + 6*4);
|
8048 |
|
|
}
|
8049 |
|
|
}
|
8050 |
|
|
}
|
8051 |
|
|
|
8052 |
|
|
return ret;
|
8053 |
|
|
}
|
8054 |
|
|
|
8055 |
|
|
#define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
|
8056 |
|
|
#define TARGET_LITTLE_NAME "elf32-powerpcle"
|
8057 |
|
|
#define TARGET_BIG_SYM bfd_elf32_powerpc_vec
|
8058 |
|
|
#define TARGET_BIG_NAME "elf32-powerpc"
|
8059 |
|
|
#define ELF_ARCH bfd_arch_powerpc
|
8060 |
|
|
#define ELF_MACHINE_CODE EM_PPC
|
8061 |
|
|
#ifdef __QNXTARGET__
|
8062 |
|
|
#define ELF_MAXPAGESIZE 0x1000
|
8063 |
|
|
#else
|
8064 |
|
|
#define ELF_MAXPAGESIZE 0x10000
|
8065 |
|
|
#endif
|
8066 |
|
|
#define ELF_MINPAGESIZE 0x1000
|
8067 |
|
|
#define ELF_COMMONPAGESIZE 0x1000
|
8068 |
|
|
#define elf_info_to_howto ppc_elf_info_to_howto
|
8069 |
|
|
|
8070 |
|
|
#ifdef EM_CYGNUS_POWERPC
|
8071 |
|
|
#define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
|
8072 |
|
|
#endif
|
8073 |
|
|
|
8074 |
|
|
#ifdef EM_PPC_OLD
|
8075 |
|
|
#define ELF_MACHINE_ALT2 EM_PPC_OLD
|
8076 |
|
|
#endif
|
8077 |
|
|
|
8078 |
|
|
#define elf_backend_plt_not_loaded 1
|
8079 |
|
|
#define elf_backend_can_gc_sections 1
|
8080 |
|
|
#define elf_backend_can_refcount 1
|
8081 |
|
|
#define elf_backend_rela_normal 1
|
8082 |
|
|
|
8083 |
|
|
#define bfd_elf32_mkobject ppc_elf_mkobject
|
8084 |
|
|
#define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
|
8085 |
|
|
#define bfd_elf32_bfd_relax_section ppc_elf_relax_section
|
8086 |
|
|
#define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
|
8087 |
|
|
#define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
|
8088 |
|
|
#define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
|
8089 |
|
|
#define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
|
8090 |
|
|
#define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
|
8091 |
|
|
|
8092 |
|
|
#define elf_backend_object_p ppc_elf_object_p
|
8093 |
|
|
#define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
|
8094 |
|
|
#define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
|
8095 |
|
|
#define elf_backend_section_from_shdr ppc_elf_section_from_shdr
|
8096 |
|
|
#define elf_backend_relocate_section ppc_elf_relocate_section
|
8097 |
|
|
#define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
|
8098 |
|
|
#define elf_backend_check_relocs ppc_elf_check_relocs
|
8099 |
|
|
#define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
|
8100 |
|
|
#define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
|
8101 |
|
|
#define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
|
8102 |
|
|
#define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
|
8103 |
|
|
#define elf_backend_hash_symbol ppc_elf_hash_symbol
|
8104 |
|
|
#define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
|
8105 |
|
|
#define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
|
8106 |
|
|
#define elf_backend_fake_sections ppc_elf_fake_sections
|
8107 |
|
|
#define elf_backend_additional_program_headers ppc_elf_additional_program_headers
|
8108 |
|
|
#define elf_backend_grok_prstatus ppc_elf_grok_prstatus
|
8109 |
|
|
#define elf_backend_grok_psinfo ppc_elf_grok_psinfo
|
8110 |
|
|
#define elf_backend_write_core_note ppc_elf_write_core_note
|
8111 |
|
|
#define elf_backend_reloc_type_class ppc_elf_reloc_type_class
|
8112 |
|
|
#define elf_backend_begin_write_processing ppc_elf_begin_write_processing
|
8113 |
|
|
#define elf_backend_final_write_processing ppc_elf_final_write_processing
|
8114 |
|
|
#define elf_backend_write_section ppc_elf_write_section
|
8115 |
|
|
#define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
|
8116 |
|
|
#define elf_backend_plt_sym_val ppc_elf_plt_sym_val
|
8117 |
|
|
#define elf_backend_action_discarded ppc_elf_action_discarded
|
8118 |
|
|
#define elf_backend_init_index_section _bfd_elf_init_1_index_section
|
8119 |
|
|
|
8120 |
|
|
#include "elf32-target.h"
|
8121 |
|
|
|
8122 |
|
|
/* VxWorks Target */
|
8123 |
|
|
|
8124 |
|
|
#undef TARGET_LITTLE_SYM
|
8125 |
|
|
#undef TARGET_LITTLE_NAME
|
8126 |
|
|
|
8127 |
|
|
#undef TARGET_BIG_SYM
|
8128 |
|
|
#define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
|
8129 |
|
|
#undef TARGET_BIG_NAME
|
8130 |
|
|
#define TARGET_BIG_NAME "elf32-powerpc-vxworks"
|
8131 |
|
|
|
8132 |
|
|
/* VxWorks uses the elf default section flags for .plt. */
|
8133 |
|
|
static const struct bfd_elf_special_section *
|
8134 |
|
|
ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
|
8135 |
|
|
{
|
8136 |
|
|
if (sec->name == NULL)
|
8137 |
|
|
return NULL;
|
8138 |
|
|
|
8139 |
|
|
if (strcmp (sec->name, ".plt") == 0)
|
8140 |
|
|
return _bfd_elf_get_sec_type_attr (abfd, sec);
|
8141 |
|
|
|
8142 |
|
|
return ppc_elf_get_sec_type_attr (abfd, sec);
|
8143 |
|
|
}
|
8144 |
|
|
|
8145 |
|
|
/* Like ppc_elf_link_hash_table_create, but overrides
|
8146 |
|
|
appropriately for VxWorks. */
|
8147 |
|
|
static struct bfd_link_hash_table *
|
8148 |
|
|
ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
|
8149 |
|
|
{
|
8150 |
|
|
struct bfd_link_hash_table *ret;
|
8151 |
|
|
|
8152 |
|
|
ret = ppc_elf_link_hash_table_create (abfd);
|
8153 |
|
|
if (ret)
|
8154 |
|
|
{
|
8155 |
|
|
struct ppc_elf_link_hash_table *htab
|
8156 |
|
|
= (struct ppc_elf_link_hash_table *)ret;
|
8157 |
|
|
htab->is_vxworks = 1;
|
8158 |
|
|
htab->plt_type = PLT_VXWORKS;
|
8159 |
|
|
htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
|
8160 |
|
|
htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
|
8161 |
|
|
htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
|
8162 |
|
|
}
|
8163 |
|
|
return ret;
|
8164 |
|
|
}
|
8165 |
|
|
|
8166 |
|
|
/* Tweak magic VxWorks symbols as they are loaded. */
|
8167 |
|
|
static bfd_boolean
|
8168 |
|
|
ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
|
8169 |
|
|
struct bfd_link_info *info,
|
8170 |
|
|
Elf_Internal_Sym *sym,
|
8171 |
|
|
const char **namep ATTRIBUTE_UNUSED,
|
8172 |
|
|
flagword *flagsp ATTRIBUTE_UNUSED,
|
8173 |
|
|
asection **secp,
|
8174 |
|
|
bfd_vma *valp)
|
8175 |
|
|
{
|
8176 |
|
|
if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
|
8177 |
|
|
valp))
|
8178 |
|
|
return FALSE;
|
8179 |
|
|
|
8180 |
|
|
return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
|
8181 |
|
|
}
|
8182 |
|
|
|
8183 |
|
|
static void
|
8184 |
|
|
ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
|
8185 |
|
|
{
|
8186 |
|
|
ppc_elf_final_write_processing(abfd, linker);
|
8187 |
|
|
elf_vxworks_final_write_processing(abfd, linker);
|
8188 |
|
|
}
|
8189 |
|
|
|
8190 |
|
|
/* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
|
8191 |
|
|
define it. */
|
8192 |
|
|
#undef elf_backend_want_plt_sym
|
8193 |
|
|
#define elf_backend_want_plt_sym 1
|
8194 |
|
|
#undef elf_backend_want_got_plt
|
8195 |
|
|
#define elf_backend_want_got_plt 1
|
8196 |
|
|
#undef elf_backend_got_symbol_offset
|
8197 |
|
|
#define elf_backend_got_symbol_offset 0
|
8198 |
|
|
#undef elf_backend_plt_not_loaded
|
8199 |
|
|
#define elf_backend_plt_not_loaded 0
|
8200 |
|
|
#undef elf_backend_plt_readonly
|
8201 |
|
|
#define elf_backend_plt_readonly 1
|
8202 |
|
|
#undef elf_backend_got_header_size
|
8203 |
|
|
#define elf_backend_got_header_size 12
|
8204 |
|
|
|
8205 |
|
|
#undef bfd_elf32_get_synthetic_symtab
|
8206 |
|
|
|
8207 |
|
|
#undef bfd_elf32_bfd_link_hash_table_create
|
8208 |
|
|
#define bfd_elf32_bfd_link_hash_table_create \
|
8209 |
|
|
ppc_elf_vxworks_link_hash_table_create
|
8210 |
|
|
#undef elf_backend_add_symbol_hook
|
8211 |
|
|
#define elf_backend_add_symbol_hook \
|
8212 |
|
|
ppc_elf_vxworks_add_symbol_hook
|
8213 |
|
|
#undef elf_backend_link_output_symbol_hook
|
8214 |
|
|
#define elf_backend_link_output_symbol_hook \
|
8215 |
|
|
elf_vxworks_link_output_symbol_hook
|
8216 |
|
|
#undef elf_backend_final_write_processing
|
8217 |
|
|
#define elf_backend_final_write_processing \
|
8218 |
|
|
ppc_elf_vxworks_final_write_processing
|
8219 |
|
|
#undef elf_backend_get_sec_type_attr
|
8220 |
|
|
#define elf_backend_get_sec_type_attr \
|
8221 |
|
|
ppc_elf_vxworks_get_sec_type_attr
|
8222 |
|
|
#undef elf_backend_emit_relocs
|
8223 |
|
|
#define elf_backend_emit_relocs \
|
8224 |
|
|
elf_vxworks_emit_relocs
|
8225 |
|
|
|
8226 |
|
|
#undef elf32_bed
|
8227 |
|
|
#define elf32_bed ppc_elf_vxworks_bed
|
8228 |
|
|
|
8229 |
|
|
#include "elf32-target.h"
|