elf32-or1k.c revision 1.6 1 1.1 christos /* Or1k-specific support for 32-bit ELF.
2 1.6 christos Copyright (C) 2001-2019 Free Software Foundation, Inc.
3 1.1 christos Contributed for OR32 by Johan Rydberg, jrydberg (at) opencores.org
4 1.1 christos
5 1.1 christos PIC parts added by Stefan Kristiansson, stefan.kristiansson (at) saunalahti.fi,
6 1.1 christos largely based on elf32-m32r.c and elf32-microblaze.c.
7 1.1 christos
8 1.1 christos This file is part of BFD, the Binary File Descriptor library.
9 1.1 christos
10 1.1 christos This program is free software; you can redistribute it and/or modify
11 1.1 christos it under the terms of the GNU General Public License as published by
12 1.1 christos the Free Software Foundation; either version 3 of the License, or
13 1.1 christos (at your option) any later version.
14 1.1 christos
15 1.1 christos This program is distributed in the hope that it will be useful,
16 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
17 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 1.1 christos GNU General Public License for more details.
19 1.1 christos
20 1.1 christos You should have received a copy of the GNU General Public License
21 1.1 christos along with this program; if not, see <http://www.gnu.org/licenses/>. */
22 1.1 christos
23 1.1 christos #include "sysdep.h"
24 1.1 christos #include "bfd.h"
25 1.1 christos #include "libbfd.h"
26 1.1 christos #include "elf-bfd.h"
27 1.1 christos #include "elf/or1k.h"
28 1.1 christos #include "libiberty.h"
29 1.1 christos
30 1.6 christos #define N_ONES(X) (((bfd_vma)2 << (X)) - 1)
31 1.1 christos
32 1.6 christos #define PLT_ENTRY_SIZE 16
33 1.6 christos
34 1.6 christos #define OR1K_MOVHI(D) (0x18000000 | (D << 21))
35 1.6 christos #define OR1K_ADRP(D) (0x08000000 | (D << 21))
36 1.6 christos #define OR1K_LWZ(D,A) (0x84000000 | (D << 21) | (A << 16))
37 1.6 christos #define OR1K_ORI0(D) (0xA8000000 | (D << 21))
38 1.6 christos #define OR1K_JR(B) (0x44000000 | (B << 11))
39 1.6 christos #define OR1K_NOP 0x15000000
40 1.1 christos
41 1.1 christos #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
42 1.1 christos
43 1.1 christos static reloc_howto_type or1k_elf_howto_table[] =
44 1.1 christos {
45 1.1 christos /* This reloc does nothing. */
46 1.6 christos HOWTO (R_OR1K_NONE, /* type */
47 1.6 christos 0, /* rightshift */
48 1.6 christos 3, /* size (0 = byte, 1 = short, 2 = long) */
49 1.6 christos 0, /* bitsize */
50 1.6 christos FALSE, /* pc_relative */
51 1.6 christos 0, /* bitpos */
52 1.6 christos complain_overflow_dont, /* complain_on_overflow */
53 1.6 christos bfd_elf_generic_reloc, /* special_function */
54 1.6 christos "R_OR1K_NONE", /* name */
55 1.6 christos FALSE, /* partial_inplace */
56 1.6 christos 0, /* src_mask */
57 1.6 christos 0, /* dst_mask */
58 1.6 christos FALSE), /* pcrel_offset */
59 1.1 christos
60 1.1 christos HOWTO (R_OR1K_32,
61 1.6 christos 0, /* rightshift */
62 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
63 1.6 christos 32, /* bitsize */
64 1.6 christos FALSE, /* pc_relative */
65 1.6 christos 0, /* bitpos */
66 1.6 christos complain_overflow_unsigned, /* complain_on_overflow */
67 1.6 christos bfd_elf_generic_reloc, /* special_function */
68 1.6 christos "R_OR1K_32", /* name */
69 1.6 christos FALSE, /* partial_inplace */
70 1.6 christos 0, /* src_mask */
71 1.6 christos 0xffffffff, /* dst_mask */
72 1.6 christos FALSE), /* pcrel_offset */
73 1.1 christos
74 1.1 christos HOWTO (R_OR1K_16,
75 1.6 christos 0, /* rightshift */
76 1.6 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
77 1.6 christos 16, /* bitsize */
78 1.6 christos FALSE, /* pc_relative */
79 1.6 christos 0, /* bitpos */
80 1.6 christos complain_overflow_unsigned, /* complain_on_overflow */
81 1.6 christos bfd_elf_generic_reloc, /* special_function */
82 1.6 christos "R_OR1K_16", /* name */
83 1.6 christos FALSE, /* partial_inplace */
84 1.6 christos 0, /* src_mask */
85 1.6 christos 0xffff, /* dst_mask */
86 1.6 christos FALSE), /* pcrel_offset */
87 1.1 christos
88 1.1 christos HOWTO (R_OR1K_8,
89 1.6 christos 0, /* rightshift */
90 1.6 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
91 1.6 christos 8, /* bitsize */
92 1.6 christos FALSE, /* pc_relative */
93 1.6 christos 0, /* bitpos */
94 1.6 christos complain_overflow_unsigned, /* complain_on_overflow */
95 1.6 christos bfd_elf_generic_reloc, /* special_function */
96 1.6 christos "R_OR1K_8", /* name */
97 1.6 christos FALSE, /* partial_inplace */
98 1.6 christos 0, /* src_mask */
99 1.6 christos 0xff, /* dst_mask */
100 1.6 christos FALSE), /* pcrel_offset */
101 1.1 christos
102 1.1 christos HOWTO (R_OR1K_LO_16_IN_INSN, /* type */
103 1.6 christos 0, /* rightshift */
104 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
105 1.6 christos 16, /* bitsize */
106 1.6 christos FALSE, /* pc_relative */
107 1.6 christos 0, /* bitpos */
108 1.6 christos complain_overflow_dont, /* complain_on_overflow */
109 1.6 christos bfd_elf_generic_reloc, /* special_function */
110 1.6 christos "R_OR1K_LO_16_IN_INSN", /* name */
111 1.6 christos FALSE, /* partial_inplace */
112 1.6 christos 0, /* src_mask */
113 1.6 christos 0x0000ffff, /* dst_mask */
114 1.6 christos FALSE), /* pcrel_offset */
115 1.1 christos
116 1.1 christos HOWTO (R_OR1K_HI_16_IN_INSN, /* type */
117 1.6 christos 16, /* rightshift */
118 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
119 1.6 christos 16, /* bitsize */
120 1.6 christos FALSE, /* pc_relative */
121 1.6 christos 0, /* bitpos */
122 1.6 christos complain_overflow_dont, /* complain_on_overflow */
123 1.6 christos bfd_elf_generic_reloc, /* special_function */
124 1.6 christos "R_OR1K_HI_16_IN_INSN", /* name */
125 1.6 christos FALSE, /* partial_inplace */
126 1.6 christos 0, /* src_mask */
127 1.6 christos 0x0000ffff, /* dst_mask */
128 1.6 christos FALSE), /* pcrel_offset */
129 1.1 christos
130 1.1 christos /* A PC relative 26 bit relocation, right shifted by 2. */
131 1.1 christos HOWTO (R_OR1K_INSN_REL_26, /* type */
132 1.6 christos 2, /* rightshift */
133 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
134 1.6 christos 26, /* bitsize */
135 1.6 christos TRUE, /* pc_relative */
136 1.6 christos 0, /* bitpos */
137 1.6 christos complain_overflow_signed, /* complain_on_overflow */
138 1.6 christos bfd_elf_generic_reloc, /* special_function */
139 1.6 christos "R_OR1K_INSN_REL_26", /* name */
140 1.6 christos FALSE, /* partial_inplace */
141 1.6 christos 0, /* src_mask */
142 1.6 christos 0x03ffffff, /* dst_mask */
143 1.6 christos TRUE), /* pcrel_offset */
144 1.1 christos
145 1.1 christos /* GNU extension to record C++ vtable hierarchy. */
146 1.1 christos HOWTO (R_OR1K_GNU_VTINHERIT, /* type */
147 1.6 christos 0, /* rightshift */
148 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
149 1.6 christos 0, /* bitsize */
150 1.6 christos FALSE, /* pc_relative */
151 1.6 christos 0, /* bitpos */
152 1.6 christos complain_overflow_dont, /* complain_on_overflow */
153 1.6 christos NULL, /* special_function */
154 1.6 christos "R_OR1K_GNU_VTINHERIT", /* name */
155 1.6 christos FALSE, /* partial_inplace */
156 1.6 christos 0, /* src_mask */
157 1.6 christos 0, /* dst_mask */
158 1.6 christos FALSE), /* pcrel_offset */
159 1.1 christos
160 1.1 christos /* GNU extension to record C++ vtable member usage. */
161 1.1 christos HOWTO (R_OR1K_GNU_VTENTRY, /* type */
162 1.6 christos 0, /* rightshift */
163 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
164 1.6 christos 0, /* bitsize */
165 1.6 christos FALSE, /* pc_relative */
166 1.6 christos 0, /* bitpos */
167 1.6 christos complain_overflow_dont, /* complain_on_overflow */
168 1.6 christos _bfd_elf_rel_vtable_reloc_fn, /* special_function */
169 1.6 christos "R_OR1K_GNU_VTENTRY", /* name */
170 1.6 christos FALSE, /* partial_inplace */
171 1.6 christos 0, /* src_mask */
172 1.6 christos 0, /* dst_mask */
173 1.6 christos FALSE), /* pcrel_offset */
174 1.1 christos
175 1.1 christos HOWTO (R_OR1K_32_PCREL,
176 1.6 christos 0, /* rightshift */
177 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
178 1.6 christos 32, /* bitsize */
179 1.6 christos TRUE, /* pc_relative */
180 1.6 christos 0, /* bitpos */
181 1.6 christos complain_overflow_signed, /* complain_on_overflow */
182 1.6 christos bfd_elf_generic_reloc, /* special_function */
183 1.6 christos "R_OR1K_32_PCREL", /* name */
184 1.6 christos FALSE, /* partial_inplace */
185 1.6 christos 0, /* src_mask */
186 1.6 christos 0xffffffff, /* dst_mask */
187 1.6 christos TRUE), /* pcrel_offset */
188 1.1 christos
189 1.1 christos HOWTO (R_OR1K_16_PCREL,
190 1.6 christos 0, /* rightshift */
191 1.6 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
192 1.6 christos 16, /* bitsize */
193 1.6 christos TRUE, /* pc_relative */
194 1.6 christos 0, /* bitpos */
195 1.6 christos complain_overflow_signed, /* complain_on_overflow */
196 1.6 christos bfd_elf_generic_reloc, /* special_function */
197 1.6 christos "R_OR1K_16_PCREL", /* name */
198 1.6 christos FALSE, /* partial_inplace */
199 1.6 christos 0, /* src_mask */
200 1.6 christos 0xffff, /* dst_mask */
201 1.6 christos TRUE), /* pcrel_offset */
202 1.1 christos
203 1.1 christos HOWTO (R_OR1K_8_PCREL,
204 1.6 christos 0, /* rightshift */
205 1.6 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
206 1.6 christos 8, /* bitsize */
207 1.6 christos TRUE, /* pc_relative */
208 1.6 christos 0, /* bitpos */
209 1.6 christos complain_overflow_signed, /* complain_on_overflow */
210 1.6 christos bfd_elf_generic_reloc, /* special_function */
211 1.6 christos "R_OR1K_8_PCREL", /* name */
212 1.6 christos FALSE, /* partial_inplace */
213 1.6 christos 0, /* src_mask */
214 1.6 christos 0xff, /* dst_mask */
215 1.6 christos TRUE), /* pcrel_offset */
216 1.6 christos
217 1.6 christos HOWTO (R_OR1K_GOTPC_HI16, /* Type. */
218 1.6 christos 16, /* Rightshift. */
219 1.6 christos 2, /* Size (0 = byte, 1 = short, 2 = long). */
220 1.6 christos 16, /* Bitsize. */
221 1.6 christos TRUE, /* PC_relative. */
222 1.6 christos 0, /* Bitpos. */
223 1.6 christos complain_overflow_dont, /* Complain on overflow. */
224 1.6 christos bfd_elf_generic_reloc, /* Special Function. */
225 1.6 christos "R_OR1K_GOTPC_HI16", /* Name. */
226 1.6 christos FALSE, /* Partial Inplace. */
227 1.6 christos 0, /* Source Mask. */
228 1.6 christos 0xffff, /* Dest Mask. */
229 1.6 christos TRUE), /* PC relative offset? */
230 1.6 christos
231 1.6 christos HOWTO (R_OR1K_GOTPC_LO16, /* Type. */
232 1.6 christos 0, /* Rightshift. */
233 1.6 christos 2, /* Size (0 = byte, 1 = short, 2 = long). */
234 1.6 christos 16, /* Bitsize. */
235 1.6 christos TRUE, /* PC_relative. */
236 1.6 christos 0, /* Bitpos. */
237 1.6 christos complain_overflow_dont, /* Complain on overflow. */
238 1.6 christos bfd_elf_generic_reloc, /* Special Function. */
239 1.6 christos "R_OR1K_GOTPC_LO16", /* Name. */
240 1.6 christos FALSE, /* Partial Inplace. */
241 1.6 christos 0, /* Source Mask. */
242 1.6 christos 0xffff, /* Dest Mask. */
243 1.6 christos TRUE), /* PC relative offset? */
244 1.6 christos
245 1.6 christos HOWTO (R_OR1K_GOT16, /* type */
246 1.6 christos 0, /* rightshift */
247 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
248 1.6 christos 16, /* bitsize */
249 1.6 christos FALSE, /* pc_relative */
250 1.6 christos 0, /* bitpos */
251 1.6 christos complain_overflow_signed, /* complain_on_overflow */
252 1.6 christos bfd_elf_generic_reloc, /* special_function */
253 1.6 christos "R_OR1K_GOT16", /* name */
254 1.6 christos FALSE, /* partial_inplace */
255 1.6 christos 0, /* src_mask */
256 1.6 christos 0xffff, /* dst_mask */
257 1.6 christos FALSE), /* pcrel_offset */
258 1.1 christos
259 1.1 christos /* A 26 bit PLT relocation. Shifted by 2. */
260 1.6 christos HOWTO (R_OR1K_PLT26, /* Type. */
261 1.6 christos 2, /* Rightshift. */
262 1.6 christos 2, /* Size (0 = byte, 1 = short, 2 = long). */
263 1.6 christos 26, /* Bitsize. */
264 1.6 christos TRUE, /* pc_relative. */
265 1.6 christos 0, /* Bitpos. */
266 1.6 christos complain_overflow_signed, /* Complain on overflow. */
267 1.6 christos bfd_elf_generic_reloc, /* Special Function. */
268 1.6 christos "R_OR1K_PLT26", /* Name. */
269 1.6 christos FALSE, /* Partial Inplace. */
270 1.6 christos 0, /* Source Mask. */
271 1.6 christos 0x03ffffff, /* Dest Mask. */
272 1.6 christos TRUE), /* PC relative offset? */
273 1.6 christos
274 1.6 christos HOWTO (R_OR1K_GOTOFF_HI16, /* type */
275 1.6 christos 16, /* rightshift */
276 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
277 1.6 christos 16, /* bitsize */
278 1.6 christos FALSE, /* pc_relative */
279 1.6 christos 0, /* bitpos */
280 1.6 christos complain_overflow_dont, /* complain_on_overflow */
281 1.6 christos bfd_elf_generic_reloc, /* special_function */
282 1.6 christos "R_OR1K_GOTOFF_HI16", /* name */
283 1.6 christos FALSE, /* partial_inplace */
284 1.6 christos 0x0, /* src_mask */
285 1.6 christos 0xffff, /* dst_mask */
286 1.6 christos FALSE), /* pcrel_offset */
287 1.6 christos
288 1.6 christos HOWTO (R_OR1K_GOTOFF_LO16, /* type */
289 1.6 christos 0, /* rightshift */
290 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
291 1.6 christos 16, /* bitsize */
292 1.6 christos FALSE, /* pc_relative */
293 1.6 christos 0, /* bitpos */
294 1.6 christos complain_overflow_dont, /* complain_on_overflow */
295 1.6 christos bfd_elf_generic_reloc, /* special_function */
296 1.6 christos "R_OR1K_GOTOFF_LO16", /* name */
297 1.6 christos FALSE, /* partial_inplace */
298 1.6 christos 0x0, /* src_mask */
299 1.6 christos 0xffff, /* dst_mask */
300 1.6 christos FALSE), /* pcrel_offset */
301 1.6 christos
302 1.6 christos HOWTO (R_OR1K_COPY, /* type */
303 1.6 christos 0, /* rightshift */
304 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
305 1.6 christos 32, /* bitsize */
306 1.6 christos FALSE, /* pc_relative */
307 1.6 christos 0, /* bitpos */
308 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
309 1.6 christos bfd_elf_generic_reloc, /* special_function */
310 1.6 christos "R_OR1K_COPY", /* name */
311 1.6 christos FALSE, /* partial_inplace */
312 1.6 christos 0xffffffff, /* src_mask */
313 1.6 christos 0xffffffff, /* dst_mask */
314 1.6 christos FALSE), /* pcrel_offset */
315 1.6 christos
316 1.6 christos HOWTO (R_OR1K_GLOB_DAT, /* type */
317 1.6 christos 0, /* rightshift */
318 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
319 1.6 christos 32, /* bitsize */
320 1.6 christos FALSE, /* pc_relative */
321 1.6 christos 0, /* bitpos */
322 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
323 1.6 christos bfd_elf_generic_reloc, /* special_function */
324 1.6 christos "R_OR1K_GLOB_DAT", /* name */
325 1.6 christos FALSE, /* partial_inplace */
326 1.6 christos 0xffffffff, /* src_mask */
327 1.6 christos 0xffffffff, /* dst_mask */
328 1.6 christos FALSE), /* pcrel_offset */
329 1.6 christos
330 1.6 christos HOWTO (R_OR1K_JMP_SLOT, /* type */
331 1.6 christos 0, /* rightshift */
332 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
333 1.6 christos 32, /* bitsize */
334 1.6 christos FALSE, /* pc_relative */
335 1.6 christos 0, /* bitpos */
336 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
337 1.6 christos bfd_elf_generic_reloc, /* special_function */
338 1.6 christos "R_OR1K_JMP_SLOT", /* name */
339 1.6 christos FALSE, /* partial_inplace */
340 1.6 christos 0xffffffff, /* src_mask */
341 1.6 christos 0xffffffff, /* dst_mask */
342 1.6 christos FALSE), /* pcrel_offset */
343 1.6 christos
344 1.6 christos HOWTO (R_OR1K_RELATIVE, /* type */
345 1.6 christos 0, /* rightshift */
346 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
347 1.6 christos 32, /* bitsize */
348 1.6 christos FALSE, /* pc_relative */
349 1.6 christos 0, /* bitpos */
350 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
351 1.6 christos bfd_elf_generic_reloc, /* special_function */
352 1.6 christos "R_OR1K_RELATIVE", /* name */
353 1.6 christos FALSE, /* partial_inplace */
354 1.6 christos 0xffffffff, /* src_mask */
355 1.6 christos 0xffffffff, /* dst_mask */
356 1.6 christos FALSE), /* pcrel_offset */
357 1.6 christos
358 1.6 christos HOWTO (R_OR1K_TLS_GD_HI16, /* type */
359 1.6 christos 16, /* rightshift */
360 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
361 1.6 christos 16, /* bitsize */
362 1.6 christos FALSE, /* pc_relative */
363 1.6 christos 0, /* bitpos */
364 1.6 christos complain_overflow_dont, /* complain_on_overflow */
365 1.6 christos bfd_elf_generic_reloc, /* special_function */
366 1.6 christos "R_OR1K_TLS_GD_HI16", /* name */
367 1.6 christos FALSE, /* partial_inplace */
368 1.6 christos 0x0, /* src_mask */
369 1.6 christos 0xffff, /* dst_mask */
370 1.6 christos FALSE), /* pcrel_offset */
371 1.6 christos
372 1.6 christos HOWTO (R_OR1K_TLS_GD_LO16, /* type */
373 1.6 christos 0, /* rightshift */
374 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
375 1.6 christos 16, /* bitsize */
376 1.6 christos FALSE, /* pc_relative */
377 1.6 christos 0, /* bitpos */
378 1.6 christos complain_overflow_dont, /* complain_on_overflow */
379 1.6 christos bfd_elf_generic_reloc, /* special_function */
380 1.6 christos "R_OR1K_TLS_GD_LO16", /* name */
381 1.6 christos FALSE, /* partial_inplace */
382 1.6 christos 0x0, /* src_mask */
383 1.6 christos 0xffff, /* dst_mask */
384 1.6 christos FALSE), /* pcrel_offset */
385 1.6 christos
386 1.6 christos HOWTO (R_OR1K_TLS_LDM_HI16, /* type */
387 1.6 christos 16, /* rightshift */
388 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
389 1.6 christos 16, /* bitsize */
390 1.6 christos FALSE, /* pc_relative */
391 1.6 christos 0, /* bitpos */
392 1.6 christos complain_overflow_dont, /* complain_on_overflow */
393 1.6 christos bfd_elf_generic_reloc, /* special_function */
394 1.6 christos "R_OR1K_TLS_LDM_HI16", /* name */
395 1.6 christos FALSE, /* partial_inplace */
396 1.6 christos 0x0, /* src_mask */
397 1.6 christos 0xffff, /* dst_mask */
398 1.6 christos FALSE), /* pcrel_offset */
399 1.6 christos
400 1.6 christos HOWTO (R_OR1K_TLS_LDM_LO16, /* type */
401 1.6 christos 0, /* rightshift */
402 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
403 1.6 christos 16, /* bitsize */
404 1.6 christos FALSE, /* pc_relative */
405 1.6 christos 0, /* bitpos */
406 1.6 christos complain_overflow_dont, /* complain_on_overflow */
407 1.6 christos bfd_elf_generic_reloc, /* special_function */
408 1.6 christos "R_OR1K_TLS_LDM_LO16", /* name */
409 1.6 christos FALSE, /* partial_inplace */
410 1.6 christos 0x0, /* src_mask */
411 1.6 christos 0xffff, /* dst_mask */
412 1.6 christos FALSE), /* pcrel_offset */
413 1.6 christos
414 1.6 christos HOWTO (R_OR1K_TLS_LDO_HI16, /* type */
415 1.6 christos 16, /* rightshift */
416 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
417 1.6 christos 16, /* bitsize */
418 1.6 christos FALSE, /* pc_relative */
419 1.6 christos 0, /* bitpos */
420 1.6 christos complain_overflow_dont, /* complain_on_overflow */
421 1.6 christos bfd_elf_generic_reloc, /* special_function */
422 1.6 christos "R_OR1K_TLS_LDO_HI16", /* name */
423 1.6 christos FALSE, /* partial_inplace */
424 1.6 christos 0x0, /* src_mask */
425 1.6 christos 0xffff, /* dst_mask */
426 1.6 christos FALSE), /* pcrel_offset */
427 1.6 christos
428 1.6 christos HOWTO (R_OR1K_TLS_LDO_LO16, /* type */
429 1.6 christos 0, /* rightshift */
430 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
431 1.6 christos 16, /* bitsize */
432 1.6 christos FALSE, /* pc_relative */
433 1.6 christos 0, /* bitpos */
434 1.6 christos complain_overflow_dont, /* complain_on_overflow */
435 1.6 christos bfd_elf_generic_reloc, /* special_function */
436 1.6 christos "R_OR1K_TLS_LDO_LO16", /* name */
437 1.6 christos FALSE, /* partial_inplace */
438 1.6 christos 0x0, /* src_mask */
439 1.6 christos 0xffff, /* dst_mask */
440 1.6 christos FALSE), /* pcrel_offset */
441 1.6 christos
442 1.6 christos HOWTO (R_OR1K_TLS_IE_HI16, /* type */
443 1.6 christos 16, /* rightshift */
444 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
445 1.6 christos 16, /* bitsize */
446 1.6 christos FALSE, /* pc_relative */
447 1.6 christos 0, /* bitpos */
448 1.6 christos complain_overflow_dont, /* complain_on_overflow */
449 1.6 christos bfd_elf_generic_reloc, /* special_function */
450 1.6 christos "R_OR1K_TLS_IE_HI16", /* name */
451 1.6 christos FALSE, /* partial_inplace */
452 1.6 christos 0x0, /* src_mask */
453 1.6 christos 0xffff, /* dst_mask */
454 1.6 christos FALSE), /* pcrel_offset */
455 1.6 christos
456 1.6 christos HOWTO (R_OR1K_TLS_IE_LO16, /* type */
457 1.6 christos 0, /* rightshift */
458 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
459 1.6 christos 16, /* bitsize */
460 1.6 christos FALSE, /* pc_relative */
461 1.6 christos 0, /* bitpos */
462 1.6 christos complain_overflow_dont, /* complain_on_overflow */
463 1.6 christos bfd_elf_generic_reloc, /* special_function */
464 1.6 christos "R_OR1K_TLS_IE_LO16", /* name */
465 1.6 christos FALSE, /* partial_inplace */
466 1.6 christos 0x0, /* src_mask */
467 1.6 christos 0xffff, /* dst_mask */
468 1.6 christos FALSE), /* pcrel_offset */
469 1.6 christos
470 1.6 christos HOWTO (R_OR1K_TLS_LE_HI16, /* type */
471 1.6 christos 16, /* rightshift */
472 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
473 1.6 christos 16, /* bitsize */
474 1.6 christos FALSE, /* pc_relative */
475 1.6 christos 0, /* bitpos */
476 1.6 christos complain_overflow_dont, /* complain_on_overflow */
477 1.6 christos bfd_elf_generic_reloc, /* special_function */
478 1.6 christos "R_OR1K_TLS_LE_HI16", /* name */
479 1.6 christos FALSE, /* partial_inplace */
480 1.6 christos 0x0, /* src_mask */
481 1.6 christos 0xffff, /* dst_mask */
482 1.6 christos FALSE), /* pcrel_offset */
483 1.6 christos
484 1.6 christos HOWTO (R_OR1K_TLS_LE_LO16, /* type */
485 1.6 christos 0, /* rightshift */
486 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
487 1.6 christos 16, /* bitsize */
488 1.6 christos FALSE, /* pc_relative */
489 1.6 christos 0, /* bitpos */
490 1.6 christos complain_overflow_dont, /* complain_on_overflow */
491 1.6 christos bfd_elf_generic_reloc, /* special_function */
492 1.6 christos "R_OR1K_TLS_LE_LO16", /* name */
493 1.6 christos FALSE, /* partial_inplace */
494 1.6 christos 0x0, /* src_mask */
495 1.6 christos 0xffff, /* dst_mask */
496 1.6 christos FALSE), /* pcrel_offset */
497 1.6 christos
498 1.6 christos HOWTO (R_OR1K_TLS_TPOFF, /* type */
499 1.6 christos 0, /* rightshift */
500 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
501 1.6 christos 32, /* bitsize */
502 1.6 christos FALSE, /* pc_relative */
503 1.6 christos 0, /* bitpos */
504 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
505 1.6 christos bfd_elf_generic_reloc, /* special_function */
506 1.6 christos "R_OR1K_TLS_TPOFF", /* name */
507 1.6 christos FALSE, /* partial_inplace */
508 1.6 christos 0xffffffff, /* src_mask */
509 1.6 christos 0xffffffff, /* dst_mask */
510 1.6 christos FALSE), /* pcrel_offset */
511 1.6 christos
512 1.6 christos HOWTO (R_OR1K_TLS_DTPOFF, /* type */
513 1.6 christos 0, /* rightshift */
514 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
515 1.6 christos 32, /* bitsize */
516 1.6 christos FALSE, /* pc_relative */
517 1.6 christos 0, /* bitpos */
518 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
519 1.6 christos bfd_elf_generic_reloc, /* special_function */
520 1.6 christos "R_OR1K_TLS_DTPOFF", /* name */
521 1.6 christos FALSE, /* partial_inplace */
522 1.6 christos 0xffffffff, /* src_mask */
523 1.6 christos 0xffffffff, /* dst_mask */
524 1.6 christos FALSE), /* pcrel_offset */
525 1.6 christos
526 1.6 christos HOWTO (R_OR1K_TLS_DTPMOD, /* type */
527 1.6 christos 0, /* rightshift */
528 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
529 1.6 christos 32, /* bitsize */
530 1.6 christos FALSE, /* pc_relative */
531 1.6 christos 0, /* bitpos */
532 1.6 christos complain_overflow_bitfield, /* complain_on_overflow */
533 1.6 christos bfd_elf_generic_reloc, /* special_function */
534 1.6 christos "R_OR1K_TLS_DTPMOD", /* name */
535 1.6 christos FALSE, /* partial_inplace */
536 1.6 christos 0xffffffff, /* src_mask */
537 1.6 christos 0xffffffff, /* dst_mask */
538 1.6 christos FALSE), /* pcrel_offset */
539 1.6 christos
540 1.6 christos HOWTO (R_OR1K_AHI16, /* type */
541 1.6 christos 16, /* rightshift */
542 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
543 1.6 christos 16, /* bitsize */
544 1.6 christos FALSE, /* pc_relative */
545 1.6 christos 0, /* bitpos */
546 1.6 christos complain_overflow_dont, /* complain_on_overflow */
547 1.6 christos bfd_elf_generic_reloc, /* special_function */
548 1.6 christos "R_OR1K_AHI16", /* name */
549 1.6 christos FALSE, /* partial_inplace */
550 1.6 christos 0x0, /* src_mask */
551 1.6 christos 0xffff, /* dst_mask */
552 1.6 christos FALSE), /* pcrel_offset */
553 1.6 christos
554 1.6 christos HOWTO (R_OR1K_GOTOFF_AHI16, /* type */
555 1.6 christos 16, /* rightshift */
556 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
557 1.6 christos 16, /* bitsize */
558 1.6 christos FALSE, /* pc_relative */
559 1.6 christos 0, /* bitpos */
560 1.6 christos complain_overflow_dont, /* complain_on_overflow */
561 1.6 christos bfd_elf_generic_reloc, /* special_function */
562 1.6 christos "R_OR1K_GOTOFF_AHI16", /* name */
563 1.6 christos FALSE, /* partial_inplace */
564 1.6 christos 0x0, /* src_mask */
565 1.6 christos 0xffff, /* dst_mask */
566 1.6 christos FALSE), /* pcrel_offset */
567 1.6 christos
568 1.6 christos HOWTO (R_OR1K_TLS_IE_AHI16, /* type */
569 1.6 christos 16, /* rightshift */
570 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
571 1.6 christos 16, /* bitsize */
572 1.6 christos FALSE, /* pc_relative */
573 1.6 christos 0, /* bitpos */
574 1.6 christos complain_overflow_dont, /* complain_on_overflow */
575 1.6 christos bfd_elf_generic_reloc, /* special_function */
576 1.6 christos "R_OR1K_TLS_IE_AHI16", /* name */
577 1.6 christos FALSE, /* partial_inplace */
578 1.6 christos 0x0, /* src_mask */
579 1.6 christos 0xffff, /* dst_mask */
580 1.6 christos FALSE), /* pcrel_offset */
581 1.6 christos
582 1.6 christos HOWTO (R_OR1K_TLS_LE_AHI16, /* type */
583 1.6 christos 16, /* rightshift */
584 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
585 1.6 christos 16, /* bitsize */
586 1.6 christos FALSE, /* pc_relative */
587 1.6 christos 0, /* bitpos */
588 1.6 christos complain_overflow_dont, /* complain_on_overflow */
589 1.6 christos bfd_elf_generic_reloc, /* special_function */
590 1.6 christos "R_OR1K_TLS_LE_AHI16", /* name */
591 1.6 christos FALSE, /* partial_inplace */
592 1.6 christos 0x0, /* src_mask */
593 1.6 christos 0xffff, /* dst_mask */
594 1.6 christos FALSE), /* pcrel_offset */
595 1.6 christos
596 1.6 christos HOWTO (R_OR1K_SLO16, /* type */
597 1.6 christos 0, /* rightshift */
598 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
599 1.6 christos 16, /* bitsize */
600 1.6 christos FALSE, /* pc_relative */
601 1.6 christos 0, /* bitpos */
602 1.6 christos complain_overflow_dont, /* complain_on_overflow */
603 1.6 christos bfd_elf_generic_reloc, /* special_function */
604 1.6 christos "R_OR1K_SLO16", /* name */
605 1.6 christos FALSE, /* partial_inplace */
606 1.6 christos 0x0, /* src_mask */
607 1.6 christos 0xffff, /* dst_mask */
608 1.6 christos FALSE), /* pcrel_offset */
609 1.6 christos
610 1.6 christos HOWTO (R_OR1K_GOTOFF_SLO16, /* type */
611 1.6 christos 0, /* rightshift */
612 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
613 1.6 christos 16, /* bitsize */
614 1.6 christos FALSE, /* pc_relative */
615 1.6 christos 0, /* bitpos */
616 1.6 christos complain_overflow_dont, /* complain_on_overflow */
617 1.6 christos bfd_elf_generic_reloc, /* special_function */
618 1.6 christos "R_OR1K_GOTOFF_SLO16", /* name */
619 1.6 christos FALSE, /* partial_inplace */
620 1.6 christos 0x0, /* src_mask */
621 1.6 christos 0xffff, /* dst_mask */
622 1.6 christos FALSE), /* pcrel_offset */
623 1.6 christos
624 1.6 christos HOWTO (R_OR1K_TLS_LE_SLO16, /* type */
625 1.6 christos 0, /* rightshift */
626 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
627 1.6 christos 16, /* bitsize */
628 1.6 christos FALSE, /* pc_relative */
629 1.6 christos 0, /* bitpos */
630 1.6 christos complain_overflow_dont, /* complain_on_overflow */
631 1.6 christos bfd_elf_generic_reloc, /* special_function */
632 1.6 christos "R_OR1K_TLS_LE_SLO16", /* name */
633 1.6 christos FALSE, /* partial_inplace */
634 1.6 christos 0x0, /* src_mask */
635 1.6 christos 0xffff, /* dst_mask */
636 1.6 christos FALSE), /* pcrel_offset */
637 1.6 christos
638 1.6 christos /* A page relative 21 bit relocation, right shifted by 13, aligned.
639 1.6 christos Note that this is *page* relative, not pc relative. The idea is
640 1.6 christos similar, but normally the section alignment is not such that the
641 1.6 christos assembler can infer a final value, which it attempts to do with
642 1.6 christos pc-relative relocations to local symbols. */
643 1.6 christos HOWTO (R_OR1K_PCREL_PG21, /* type */
644 1.6 christos 13, /* rightshift */
645 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
646 1.6 christos 21, /* bitsize */
647 1.6 christos FALSE, /* pc_relative */
648 1.6 christos 0, /* bitpos */
649 1.6 christos complain_overflow_signed, /* complain_on_overflow */
650 1.6 christos bfd_elf_generic_reloc, /* special_function */
651 1.6 christos "R_OR1K_PCREL_PG21", /* name */
652 1.6 christos FALSE, /* partial_inplace */
653 1.6 christos 0, /* src_mask */
654 1.6 christos 0x001fffff, /* dst_mask */
655 1.6 christos TRUE), /* pcrel_offset */
656 1.6 christos
657 1.6 christos HOWTO (R_OR1K_GOT_PG21, /* type */
658 1.6 christos 13, /* rightshift */
659 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
660 1.6 christos 21, /* bitsize */
661 1.6 christos FALSE, /* pc_relative */
662 1.6 christos 0, /* bitpos */
663 1.6 christos complain_overflow_signed, /* complain_on_overflow */
664 1.6 christos bfd_elf_generic_reloc, /* special_function */
665 1.6 christos "R_OR1K_GOT_PG21", /* name */
666 1.6 christos FALSE, /* partial_inplace */
667 1.6 christos 0, /* src_mask */
668 1.6 christos 0x001fffff, /* dst_mask */
669 1.6 christos TRUE), /* pcrel_offset */
670 1.6 christos
671 1.6 christos HOWTO (R_OR1K_TLS_GD_PG21, /* type */
672 1.6 christos 13, /* rightshift */
673 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
674 1.6 christos 21, /* bitsize */
675 1.6 christos FALSE, /* pc_relative */
676 1.6 christos 0, /* bitpos */
677 1.6 christos complain_overflow_signed, /* complain_on_overflow */
678 1.6 christos bfd_elf_generic_reloc, /* special_function */
679 1.6 christos "R_OR1K_TLS_GD_PG21", /* name */
680 1.6 christos FALSE, /* partial_inplace */
681 1.6 christos 0, /* src_mask */
682 1.6 christos 0x001fffff, /* dst_mask */
683 1.6 christos TRUE), /* pcrel_offset */
684 1.6 christos
685 1.6 christos HOWTO (R_OR1K_TLS_LDM_PG21, /* type */
686 1.6 christos 13, /* rightshift */
687 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
688 1.6 christos 21, /* bitsize */
689 1.6 christos FALSE, /* pc_relative */
690 1.6 christos 0, /* bitpos */
691 1.6 christos complain_overflow_signed, /* complain_on_overflow */
692 1.6 christos bfd_elf_generic_reloc, /* special_function */
693 1.6 christos "R_OR1K_TLS_LDM_PG21", /* name */
694 1.6 christos FALSE, /* partial_inplace */
695 1.6 christos 0, /* src_mask */
696 1.6 christos 0x001fffff, /* dst_mask */
697 1.6 christos TRUE), /* pcrel_offset */
698 1.6 christos
699 1.6 christos HOWTO (R_OR1K_TLS_IE_PG21, /* type */
700 1.6 christos 13, /* rightshift */
701 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
702 1.6 christos 21, /* bitsize */
703 1.6 christos FALSE, /* pc_relative */
704 1.6 christos 0, /* bitpos */
705 1.6 christos complain_overflow_signed, /* complain_on_overflow */
706 1.6 christos bfd_elf_generic_reloc, /* special_function */
707 1.6 christos "R_OR1K_TLS_IE_PG21", /* name */
708 1.6 christos FALSE, /* partial_inplace */
709 1.6 christos 0, /* src_mask */
710 1.6 christos 0x001fffff, /* dst_mask */
711 1.6 christos TRUE), /* pcrel_offset */
712 1.6 christos
713 1.6 christos HOWTO (R_OR1K_LO13, /* type */
714 1.6 christos 0, /* rightshift */
715 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
716 1.6 christos 16, /* bitsize */
717 1.6 christos FALSE, /* pc_relative */
718 1.6 christos 0, /* bitpos */
719 1.6 christos complain_overflow_dont, /* complain_on_overflow */
720 1.6 christos bfd_elf_generic_reloc, /* special_function */
721 1.6 christos "R_OR1K_LO13", /* name */
722 1.6 christos FALSE, /* partial_inplace */
723 1.6 christos 0x0, /* src_mask */
724 1.6 christos 0xffff, /* dst_mask */
725 1.6 christos FALSE), /* pcrel_offset */
726 1.6 christos
727 1.6 christos HOWTO (R_OR1K_GOT_LO13, /* type */
728 1.6 christos 0, /* rightshift */
729 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
730 1.6 christos 16, /* bitsize */
731 1.6 christos FALSE, /* pc_relative */
732 1.6 christos 0, /* bitpos */
733 1.6 christos complain_overflow_dont, /* complain_on_overflow */
734 1.6 christos bfd_elf_generic_reloc, /* special_function */
735 1.6 christos "R_OR1K_GOT_LO13", /* name */
736 1.6 christos FALSE, /* partial_inplace */
737 1.6 christos 0x0, /* src_mask */
738 1.6 christos 0xffff, /* dst_mask */
739 1.6 christos FALSE), /* pcrel_offset */
740 1.6 christos
741 1.6 christos HOWTO (R_OR1K_TLS_GD_LO13, /* type */
742 1.6 christos 0, /* rightshift */
743 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
744 1.6 christos 16, /* bitsize */
745 1.6 christos FALSE, /* pc_relative */
746 1.6 christos 0, /* bitpos */
747 1.6 christos complain_overflow_dont, /* complain_on_overflow */
748 1.6 christos bfd_elf_generic_reloc, /* special_function */
749 1.6 christos "R_OR1K_TLS_GD_LO13", /* name */
750 1.6 christos FALSE, /* partial_inplace */
751 1.6 christos 0x0, /* src_mask */
752 1.6 christos 0xffff, /* dst_mask */
753 1.6 christos FALSE), /* pcrel_offset */
754 1.6 christos
755 1.6 christos HOWTO (R_OR1K_TLS_LDM_LO13, /* type */
756 1.6 christos 0, /* rightshift */
757 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
758 1.6 christos 16, /* bitsize */
759 1.6 christos FALSE, /* pc_relative */
760 1.6 christos 0, /* bitpos */
761 1.6 christos complain_overflow_dont, /* complain_on_overflow */
762 1.6 christos bfd_elf_generic_reloc, /* special_function */
763 1.6 christos "R_OR1K_TLD_LDM_LO13", /* name */
764 1.6 christos FALSE, /* partial_inplace */
765 1.6 christos 0x0, /* src_mask */
766 1.6 christos 0xffff, /* dst_mask */
767 1.6 christos FALSE), /* pcrel_offset */
768 1.6 christos
769 1.6 christos HOWTO (R_OR1K_TLS_IE_LO13, /* type */
770 1.6 christos 0, /* rightshift */
771 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
772 1.6 christos 16, /* bitsize */
773 1.6 christos FALSE, /* pc_relative */
774 1.6 christos 0, /* bitpos */
775 1.6 christos complain_overflow_dont, /* complain_on_overflow */
776 1.6 christos bfd_elf_generic_reloc, /* special_function */
777 1.6 christos "R_OR1K_TLS_IE_LO13", /* name */
778 1.6 christos FALSE, /* partial_inplace */
779 1.6 christos 0x0, /* src_mask */
780 1.6 christos 0xffff, /* dst_mask */
781 1.6 christos FALSE), /* pcrel_offset */
782 1.6 christos
783 1.6 christos HOWTO (R_OR1K_SLO13, /* type */
784 1.6 christos 0, /* rightshift */
785 1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
786 1.6 christos 16, /* bitsize */
787 1.6 christos FALSE, /* pc_relative */
788 1.6 christos 0, /* bitpos */
789 1.6 christos complain_overflow_dont, /* complain_on_overflow */
790 1.6 christos bfd_elf_generic_reloc, /* special_function */
791 1.6 christos "R_OR1K_SLO13", /* name */
792 1.6 christos FALSE, /* partial_inplace */
793 1.6 christos 0x0, /* src_mask */
794 1.6 christos 0xffff, /* dst_mask */
795 1.6 christos FALSE), /* pcrel_offset */
796 1.6 christos
797 1.6 christos /* A 26 bit PLT relocation, using ADRP. Shifted by 2. */
798 1.6 christos HOWTO (R_OR1K_PLTA26, /* Type. */
799 1.6 christos 2, /* Rightshift. */
800 1.6 christos 2, /* Size (0 = byte, 1 = short, 2 = long). */
801 1.6 christos 26, /* Bitsize. */
802 1.6 christos TRUE, /* pc_relative. */
803 1.6 christos 0, /* Bitpos. */
804 1.6 christos complain_overflow_signed, /* Complain on overflow. */
805 1.6 christos bfd_elf_generic_reloc, /* Special Function. */
806 1.6 christos "R_OR1K_PLTA26", /* Name. */
807 1.6 christos FALSE, /* Partial Inplace. */
808 1.6 christos 0, /* Source Mask. */
809 1.6 christos 0x03ffffff, /* Dest Mask. */
810 1.6 christos TRUE), /* PC relative offset? */
811 1.1 christos };
812 1.1 christos
813 1.1 christos /* Map BFD reloc types to Or1k ELF reloc types. */
814 1.1 christos
815 1.1 christos struct or1k_reloc_map
816 1.1 christos {
817 1.1 christos bfd_reloc_code_real_type bfd_reloc_val;
818 1.1 christos unsigned int or1k_reloc_val;
819 1.1 christos };
820 1.1 christos
821 1.1 christos static const struct or1k_reloc_map or1k_reloc_map[] =
822 1.1 christos {
823 1.6 christos { BFD_RELOC_NONE, R_OR1K_NONE },
824 1.6 christos { BFD_RELOC_32, R_OR1K_32 },
825 1.6 christos { BFD_RELOC_16, R_OR1K_16 },
826 1.6 christos { BFD_RELOC_8, R_OR1K_8 },
827 1.6 christos { BFD_RELOC_LO16, R_OR1K_LO_16_IN_INSN },
828 1.6 christos { BFD_RELOC_HI16, R_OR1K_HI_16_IN_INSN },
829 1.6 christos { BFD_RELOC_HI16_S, R_OR1K_AHI16 },
830 1.6 christos { BFD_RELOC_OR1K_REL_26, R_OR1K_INSN_REL_26 },
831 1.6 christos { BFD_RELOC_VTABLE_ENTRY, R_OR1K_GNU_VTENTRY },
832 1.6 christos { BFD_RELOC_VTABLE_INHERIT, R_OR1K_GNU_VTINHERIT },
833 1.6 christos { BFD_RELOC_32_PCREL, R_OR1K_32_PCREL },
834 1.6 christos { BFD_RELOC_16_PCREL, R_OR1K_16_PCREL },
835 1.6 christos { BFD_RELOC_8_PCREL, R_OR1K_8_PCREL },
836 1.6 christos { BFD_RELOC_LO16_GOTOFF, R_OR1K_GOTOFF_LO16 },
837 1.6 christos { BFD_RELOC_HI16_GOTOFF, R_OR1K_GOTOFF_HI16 },
838 1.6 christos { BFD_RELOC_HI16_S_GOTOFF, R_OR1K_GOTOFF_AHI16 },
839 1.6 christos { BFD_RELOC_OR1K_GOTPC_HI16, R_OR1K_GOTPC_HI16 },
840 1.6 christos { BFD_RELOC_OR1K_GOTPC_LO16, R_OR1K_GOTPC_LO16 },
841 1.6 christos { BFD_RELOC_OR1K_GOT16, R_OR1K_GOT16 },
842 1.6 christos { BFD_RELOC_OR1K_PLT26, R_OR1K_PLT26 },
843 1.6 christos { BFD_RELOC_OR1K_GLOB_DAT, R_OR1K_GLOB_DAT },
844 1.6 christos { BFD_RELOC_OR1K_COPY, R_OR1K_COPY },
845 1.6 christos { BFD_RELOC_OR1K_JMP_SLOT, R_OR1K_JMP_SLOT },
846 1.6 christos { BFD_RELOC_OR1K_RELATIVE, R_OR1K_RELATIVE },
847 1.1 christos { BFD_RELOC_OR1K_TLS_GD_HI16, R_OR1K_TLS_GD_HI16 },
848 1.1 christos { BFD_RELOC_OR1K_TLS_GD_LO16, R_OR1K_TLS_GD_LO16 },
849 1.6 christos { BFD_RELOC_OR1K_TLS_LDM_HI16, R_OR1K_TLS_LDM_HI16 },
850 1.6 christos { BFD_RELOC_OR1K_TLS_LDM_LO16, R_OR1K_TLS_LDM_LO16 },
851 1.6 christos { BFD_RELOC_OR1K_TLS_LDO_HI16, R_OR1K_TLS_LDO_HI16 },
852 1.6 christos { BFD_RELOC_OR1K_TLS_LDO_LO16, R_OR1K_TLS_LDO_LO16 },
853 1.1 christos { BFD_RELOC_OR1K_TLS_IE_HI16, R_OR1K_TLS_IE_HI16 },
854 1.1 christos { BFD_RELOC_OR1K_TLS_IE_LO16, R_OR1K_TLS_IE_LO16 },
855 1.6 christos { BFD_RELOC_OR1K_TLS_IE_AHI16, R_OR1K_TLS_IE_AHI16 },
856 1.1 christos { BFD_RELOC_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_HI16 },
857 1.1 christos { BFD_RELOC_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_LO16 },
858 1.6 christos { BFD_RELOC_OR1K_TLS_LE_AHI16, R_OR1K_TLS_LE_AHI16 },
859 1.6 christos { BFD_RELOC_OR1K_SLO16, R_OR1K_SLO16 },
860 1.6 christos { BFD_RELOC_OR1K_GOTOFF_SLO16, R_OR1K_GOTOFF_SLO16 },
861 1.6 christos { BFD_RELOC_OR1K_TLS_LE_SLO16, R_OR1K_TLS_LE_SLO16 },
862 1.6 christos { BFD_RELOC_OR1K_PCREL_PG21, R_OR1K_PCREL_PG21 },
863 1.6 christos { BFD_RELOC_OR1K_GOT_PG21, R_OR1K_GOT_PG21 },
864 1.6 christos { BFD_RELOC_OR1K_TLS_GD_PG21, R_OR1K_TLS_GD_PG21 },
865 1.6 christos { BFD_RELOC_OR1K_TLS_LDM_PG21, R_OR1K_TLS_LDM_PG21 },
866 1.6 christos { BFD_RELOC_OR1K_TLS_IE_PG21, R_OR1K_TLS_IE_PG21 },
867 1.6 christos { BFD_RELOC_OR1K_LO13, R_OR1K_LO13 },
868 1.6 christos { BFD_RELOC_OR1K_GOT_LO13, R_OR1K_GOT_LO13 },
869 1.6 christos { BFD_RELOC_OR1K_TLS_GD_LO13, R_OR1K_TLS_GD_LO13 },
870 1.6 christos { BFD_RELOC_OR1K_TLS_LDM_LO13, R_OR1K_TLS_LDM_LO13 },
871 1.6 christos { BFD_RELOC_OR1K_TLS_IE_LO13, R_OR1K_TLS_IE_LO13 },
872 1.6 christos { BFD_RELOC_OR1K_SLO13, R_OR1K_SLO13 },
873 1.6 christos { BFD_RELOC_OR1K_PLTA26, R_OR1K_PLTA26 },
874 1.1 christos };
875 1.1 christos
876 1.1 christos #define TLS_UNKNOWN 0
877 1.1 christos #define TLS_NONE 1
878 1.6 christos #define TLS_GD 2
879 1.6 christos #define TLS_LD 3
880 1.6 christos #define TLS_IE 4
881 1.6 christos #define TLS_LE 5
882 1.1 christos
883 1.1 christos /* ELF linker hash entry. */
884 1.1 christos struct elf_or1k_link_hash_entry
885 1.1 christos {
886 1.1 christos struct elf_link_hash_entry root;
887 1.1 christos
888 1.1 christos /* Track dynamic relocs copied for this symbol. */
889 1.6 christos struct elf_dyn_relocs *dyn_relocs;
890 1.1 christos
891 1.1 christos /* Track type of TLS access. */
892 1.1 christos unsigned char tls_type;
893 1.1 christos };
894 1.1 christos
895 1.1 christos /* ELF object data. */
896 1.1 christos struct elf_or1k_obj_tdata
897 1.1 christos {
898 1.1 christos struct elf_obj_tdata root;
899 1.1 christos
900 1.1 christos /* tls_type for each local got entry. */
901 1.1 christos unsigned char *local_tls_type;
902 1.1 christos };
903 1.1 christos
904 1.1 christos #define elf_or1k_tdata(abfd) \
905 1.1 christos ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
906 1.1 christos
907 1.1 christos #define elf_or1k_local_tls_type(abfd) \
908 1.1 christos (elf_or1k_tdata (abfd)->local_tls_type)
909 1.1 christos
910 1.1 christos /* ELF linker hash table. */
911 1.1 christos struct elf_or1k_link_hash_table
912 1.1 christos {
913 1.1 christos struct elf_link_hash_table root;
914 1.1 christos
915 1.1 christos /* Small local sym to section mapping cache. */
916 1.1 christos struct sym_cache sym_sec;
917 1.6 christos
918 1.6 christos bfd_boolean saw_plta;
919 1.1 christos };
920 1.1 christos
921 1.1 christos /* Get the ELF linker hash table from a link_info structure. */
922 1.1 christos #define or1k_elf_hash_table(p) \
923 1.1 christos (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
924 1.1 christos == OR1K_ELF_DATA ? ((struct elf_or1k_link_hash_table *) ((p)->hash)) : NULL)
925 1.1 christos
926 1.1 christos static bfd_boolean
927 1.1 christos elf_or1k_mkobject (bfd *abfd)
928 1.1 christos {
929 1.1 christos return bfd_elf_allocate_object (abfd, sizeof (struct elf_or1k_obj_tdata),
930 1.6 christos OR1K_ELF_DATA);
931 1.1 christos }
932 1.1 christos
933 1.1 christos /* Create an entry in an or1k ELF linker hash table. */
934 1.1 christos
935 1.1 christos static struct bfd_hash_entry *
936 1.1 christos or1k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
937 1.6 christos struct bfd_hash_table *table,
938 1.6 christos const char *string)
939 1.1 christos {
940 1.1 christos struct elf_or1k_link_hash_entry *ret =
941 1.1 christos (struct elf_or1k_link_hash_entry *) entry;
942 1.1 christos
943 1.1 christos /* Allocate the structure if it has not already been allocated by a
944 1.1 christos subclass. */
945 1.1 christos if (ret == NULL)
946 1.1 christos ret = bfd_hash_allocate (table,
947 1.6 christos sizeof (struct elf_or1k_link_hash_entry));
948 1.1 christos if (ret == NULL)
949 1.1 christos return NULL;
950 1.1 christos
951 1.1 christos /* Call the allocation method of the superclass. */
952 1.1 christos ret = ((struct elf_or1k_link_hash_entry *)
953 1.6 christos _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
954 1.6 christos table, string));
955 1.1 christos if (ret != NULL)
956 1.1 christos {
957 1.1 christos struct elf_or1k_link_hash_entry *eh;
958 1.1 christos
959 1.1 christos eh = (struct elf_or1k_link_hash_entry *) ret;
960 1.1 christos eh->dyn_relocs = NULL;
961 1.1 christos eh->tls_type = TLS_UNKNOWN;
962 1.1 christos }
963 1.1 christos
964 1.1 christos return (struct bfd_hash_entry *) ret;
965 1.1 christos }
966 1.1 christos
967 1.1 christos /* Create an or1k ELF linker hash table. */
968 1.1 christos
969 1.1 christos static struct bfd_link_hash_table *
970 1.1 christos or1k_elf_link_hash_table_create (bfd *abfd)
971 1.1 christos {
972 1.1 christos struct elf_or1k_link_hash_table *ret;
973 1.1 christos bfd_size_type amt = sizeof (struct elf_or1k_link_hash_table);
974 1.1 christos
975 1.1 christos ret = bfd_zmalloc (amt);
976 1.1 christos if (ret == NULL)
977 1.1 christos return NULL;
978 1.1 christos
979 1.1 christos if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
980 1.6 christos or1k_elf_link_hash_newfunc,
981 1.6 christos sizeof (struct elf_or1k_link_hash_entry),
982 1.6 christos OR1K_ELF_DATA))
983 1.1 christos {
984 1.1 christos free (ret);
985 1.1 christos return NULL;
986 1.1 christos }
987 1.1 christos
988 1.1 christos return &ret->root.root;
989 1.1 christos }
990 1.1 christos
991 1.1 christos static reloc_howto_type *
992 1.1 christos or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
993 1.6 christos bfd_reloc_code_real_type bcode)
994 1.1 christos {
995 1.1 christos unsigned int i;
996 1.1 christos
997 1.6 christos for (i = 0; i < ARRAY_SIZE (or1k_reloc_map); i++)
998 1.6 christos if (or1k_reloc_map[i].bfd_reloc_val == bcode)
999 1.6 christos {
1000 1.6 christos unsigned int ocode = or1k_reloc_map[i].or1k_reloc_val;
1001 1.6 christos if (ocode < (unsigned int) R_OR1K_max)
1002 1.6 christos return &or1k_elf_howto_table[ocode];
1003 1.6 christos else
1004 1.6 christos break;
1005 1.6 christos }
1006 1.1 christos
1007 1.1 christos return NULL;
1008 1.1 christos }
1009 1.1 christos
1010 1.1 christos static reloc_howto_type *
1011 1.1 christos or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1012 1.1 christos const char *r_name)
1013 1.1 christos {
1014 1.1 christos unsigned int i;
1015 1.1 christos
1016 1.6 christos for (i = 0; i < R_OR1K_max; i++)
1017 1.1 christos if (or1k_elf_howto_table[i].name != NULL
1018 1.6 christos && strcasecmp (or1k_elf_howto_table[i].name, r_name) == 0)
1019 1.1 christos return &or1k_elf_howto_table[i];
1020 1.1 christos
1021 1.1 christos return NULL;
1022 1.1 christos }
1023 1.1 christos
1024 1.1 christos /* Set the howto pointer for an Or1k ELF reloc. */
1025 1.1 christos
1026 1.6 christos static bfd_boolean
1027 1.6 christos or1k_info_to_howto_rela (bfd * abfd,
1028 1.1 christos arelent * cache_ptr,
1029 1.1 christos Elf_Internal_Rela * dst)
1030 1.1 christos {
1031 1.1 christos unsigned int r_type;
1032 1.1 christos
1033 1.1 christos r_type = ELF32_R_TYPE (dst->r_info);
1034 1.1 christos if (r_type >= (unsigned int) R_OR1K_max)
1035 1.1 christos {
1036 1.5 christos /* xgettext:c-format */
1037 1.6 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1038 1.6 christos abfd, r_type);
1039 1.6 christos bfd_set_error (bfd_error_bad_value);
1040 1.6 christos return FALSE;
1041 1.1 christos }
1042 1.1 christos cache_ptr->howto = & or1k_elf_howto_table[r_type];
1043 1.6 christos return TRUE;
1044 1.1 christos }
1045 1.1 christos
1046 1.1 christos
1047 1.1 christos /* Return the relocation value for @tpoff relocations.. */
1048 1.1 christos static bfd_vma
1049 1.1 christos tpoff (struct bfd_link_info *info, bfd_vma address)
1050 1.1 christos {
1051 1.1 christos /* If tls_sec is NULL, we should have signalled an error already. */
1052 1.1 christos if (elf_hash_table (info)->tls_sec == NULL)
1053 1.1 christos return 0;
1054 1.1 christos
1055 1.1 christos /* The thread pointer on or1k stores the address after the TCB where
1056 1.1 christos the data is, just compute the difference. No need to compensate
1057 1.1 christos for the size of TCB. */
1058 1.1 christos return (address - elf_hash_table (info)->tls_sec->vma);
1059 1.1 christos }
1060 1.1 christos
1061 1.6 christos /* Like _bfd_final_link_relocate, but handles non-contiguous fields. */
1062 1.6 christos
1063 1.6 christos static bfd_reloc_status_type
1064 1.6 christos or1k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
1065 1.6 christos asection *input_section, bfd_byte *contents,
1066 1.6 christos bfd_vma offset, bfd_vma value)
1067 1.6 christos {
1068 1.6 christos bfd_reloc_status_type status = bfd_reloc_ok;
1069 1.6 christos int size = bfd_get_reloc_size (howto);
1070 1.6 christos bfd_vma x, place;
1071 1.6 christos
1072 1.6 christos /* Sanity check the address. */
1073 1.6 christos if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
1074 1.6 christos return bfd_reloc_outofrange;
1075 1.6 christos
1076 1.6 christos place = (input_section->output_section->vma
1077 1.6 christos + input_section->output_offset
1078 1.6 christos + (howto->pcrel_offset ? offset : 0));
1079 1.6 christos
1080 1.6 christos switch (howto->type)
1081 1.6 christos {
1082 1.6 christos case R_OR1K_AHI16:
1083 1.6 christos case R_OR1K_GOTOFF_AHI16:
1084 1.6 christos case R_OR1K_TLS_IE_AHI16:
1085 1.6 christos case R_OR1K_TLS_LE_AHI16:
1086 1.6 christos /* Adjust the operand to match with a signed LO16. */
1087 1.6 christos value += 0x8000;
1088 1.6 christos break;
1089 1.6 christos
1090 1.6 christos case R_OR1K_INSN_REL_26:
1091 1.6 christos value -= place;
1092 1.6 christos /* Diagnose mis-aligned branch targets. */
1093 1.6 christos if (value & 3)
1094 1.6 christos status = bfd_reloc_dangerous;
1095 1.6 christos break;
1096 1.6 christos
1097 1.6 christos case R_OR1K_PCREL_PG21:
1098 1.6 christos case R_OR1K_GOT_PG21:
1099 1.6 christos case R_OR1K_TLS_GD_PG21:
1100 1.6 christos case R_OR1K_TLS_LDM_PG21:
1101 1.6 christos case R_OR1K_TLS_IE_PG21:
1102 1.6 christos value = (value & -8192) - (place & -8192);
1103 1.6 christos break;
1104 1.6 christos
1105 1.6 christos case R_OR1K_LO13:
1106 1.6 christos case R_OR1K_GOT_LO13:
1107 1.6 christos case R_OR1K_TLS_GD_LO13:
1108 1.6 christos case R_OR1K_TLS_LDM_LO13:
1109 1.6 christos case R_OR1K_TLS_IE_LO13:
1110 1.6 christos case R_OR1K_SLO13:
1111 1.6 christos value &= 8191;
1112 1.6 christos break;
1113 1.6 christos
1114 1.6 christos default:
1115 1.6 christos if (howto->pc_relative)
1116 1.6 christos value -= place;
1117 1.6 christos break;
1118 1.6 christos }
1119 1.6 christos
1120 1.6 christos status = bfd_check_overflow (howto->complain_on_overflow,
1121 1.6 christos howto->bitsize,
1122 1.6 christos howto->rightshift,
1123 1.6 christos bfd_arch_bits_per_address (input_bfd),
1124 1.6 christos value);
1125 1.6 christos value >>= howto->rightshift;
1126 1.6 christos
1127 1.6 christos /* If we're overwriting the entire destination,
1128 1.6 christos then no need to read the current contents. */
1129 1.6 christos if (size == 0 || howto->dst_mask == N_ONES (size))
1130 1.6 christos x = 0;
1131 1.6 christos else
1132 1.6 christos {
1133 1.6 christos BFD_ASSERT (size == 4);
1134 1.6 christos x = bfd_get_32 (input_bfd, contents + offset);
1135 1.6 christos }
1136 1.6 christos
1137 1.6 christos switch (howto->type)
1138 1.6 christos {
1139 1.6 christos case R_OR1K_SLO16:
1140 1.6 christos case R_OR1K_GOTOFF_SLO16:
1141 1.6 christos case R_OR1K_TLS_LE_SLO16:
1142 1.6 christos case R_OR1K_SLO13:
1143 1.6 christos /* The split imm16 field used for stores. */
1144 1.6 christos x = (x & ~0x3e007ff) | ((value & 0xf800) << 10) | (value & 0x7ff);
1145 1.6 christos break;
1146 1.6 christos
1147 1.6 christos default:
1148 1.6 christos {
1149 1.6 christos bfd_vma fieldmask = howto->dst_mask;
1150 1.6 christos value <<= howto->bitpos;
1151 1.6 christos x = (x & ~fieldmask) | (value & fieldmask);
1152 1.6 christos }
1153 1.6 christos break;
1154 1.6 christos }
1155 1.6 christos
1156 1.6 christos /* Put the relocated value back in the object file. */
1157 1.6 christos switch (size)
1158 1.6 christos {
1159 1.6 christos case 0:
1160 1.6 christos break;
1161 1.6 christos case 1:
1162 1.6 christos bfd_put_8 (input_bfd, x, contents + offset);
1163 1.6 christos break;
1164 1.6 christos case 2:
1165 1.6 christos bfd_put_16 (input_bfd, x, contents + offset);
1166 1.6 christos break;
1167 1.6 christos case 4:
1168 1.6 christos bfd_put_32 (input_bfd, x, contents + offset);
1169 1.6 christos break;
1170 1.6 christos #ifdef BFD64
1171 1.6 christos case 8:
1172 1.6 christos bfd_put_64 (input_bfd, x, contents + offset);
1173 1.6 christos break;
1174 1.6 christos #endif
1175 1.6 christos default:
1176 1.6 christos _bfd_error_handler
1177 1.6 christos (_("%pB: Cannot handle relocation value size of %d"),
1178 1.6 christos input_bfd, size);
1179 1.6 christos abort ();
1180 1.6 christos }
1181 1.6 christos return status;
1182 1.6 christos }
1183 1.6 christos
1184 1.1 christos /* Relocate an Or1k ELF section.
1185 1.1 christos
1186 1.1 christos The RELOCATE_SECTION function is called by the new ELF backend linker
1187 1.1 christos to handle the relocations for a section.
1188 1.1 christos
1189 1.1 christos The relocs are always passed as Rela structures; if the section
1190 1.1 christos actually uses Rel structures, the r_addend field will always be
1191 1.1 christos zero.
1192 1.1 christos
1193 1.1 christos This function is responsible for adjusting the section contents as
1194 1.1 christos necessary, and (if using Rela relocs and generating a relocatable
1195 1.1 christos output file) adjusting the reloc addend as necessary.
1196 1.1 christos
1197 1.1 christos This function does not have to worry about setting the reloc
1198 1.1 christos address or the reloc symbol index.
1199 1.1 christos
1200 1.1 christos LOCAL_SYMS is a pointer to the swapped in local symbols.
1201 1.1 christos
1202 1.1 christos LOCAL_SECTIONS is an array giving the section in the input file
1203 1.1 christos corresponding to the st_shndx field of each local symbol.
1204 1.1 christos
1205 1.1 christos The global hash table entry for the global symbols can be found
1206 1.1 christos via elf_sym_hashes (input_bfd).
1207 1.1 christos
1208 1.1 christos When generating relocatable output, this function must handle
1209 1.1 christos STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1210 1.1 christos going to be the section symbol corresponding to the output
1211 1.1 christos section, which means that the addend must be adjusted
1212 1.1 christos accordingly. */
1213 1.1 christos
1214 1.1 christos static bfd_boolean
1215 1.1 christos or1k_elf_relocate_section (bfd *output_bfd,
1216 1.1 christos struct bfd_link_info *info,
1217 1.1 christos bfd *input_bfd,
1218 1.1 christos asection *input_section,
1219 1.1 christos bfd_byte *contents,
1220 1.1 christos Elf_Internal_Rela *relocs,
1221 1.1 christos Elf_Internal_Sym *local_syms,
1222 1.1 christos asection **local_sections)
1223 1.1 christos {
1224 1.1 christos Elf_Internal_Shdr *symtab_hdr;
1225 1.1 christos struct elf_link_hash_entry **sym_hashes;
1226 1.1 christos Elf_Internal_Rela *rel;
1227 1.1 christos Elf_Internal_Rela *relend;
1228 1.1 christos struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
1229 1.1 christos bfd *dynobj;
1230 1.1 christos asection *sreloc;
1231 1.1 christos bfd_vma *local_got_offsets;
1232 1.6 christos asection *sgot, *splt;
1233 1.6 christos bfd_vma plt_base, got_base, got_sym_value;
1234 1.6 christos bfd_boolean ret_val = TRUE;
1235 1.1 christos
1236 1.1 christos if (htab == NULL)
1237 1.1 christos return FALSE;
1238 1.1 christos
1239 1.1 christos dynobj = htab->root.dynobj;
1240 1.1 christos local_got_offsets = elf_local_got_offsets (input_bfd);
1241 1.1 christos
1242 1.1 christos sreloc = elf_section_data (input_section)->sreloc;
1243 1.1 christos
1244 1.6 christos splt = htab->root.splt;
1245 1.6 christos plt_base = 0;
1246 1.6 christos if (splt != NULL)
1247 1.6 christos plt_base = splt->output_section->vma + splt->output_offset;
1248 1.6 christos
1249 1.5 christos sgot = htab->root.sgot;
1250 1.6 christos got_sym_value = got_base = 0;
1251 1.6 christos if (sgot != NULL)
1252 1.6 christos {
1253 1.6 christos struct elf_link_hash_entry *hgot = htab->root.hgot;
1254 1.6 christos got_sym_value = (hgot->root.u.def.value
1255 1.6 christos + hgot->root.u.def.section->output_section->vma
1256 1.6 christos + hgot->root.u.def.section->output_offset);
1257 1.6 christos got_base = sgot->output_section->vma + sgot->output_offset;
1258 1.6 christos }
1259 1.1 christos
1260 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1261 1.1 christos sym_hashes = elf_sym_hashes (input_bfd);
1262 1.1 christos relend = relocs + input_section->reloc_count;
1263 1.1 christos
1264 1.1 christos for (rel = relocs; rel < relend; rel++)
1265 1.1 christos {
1266 1.1 christos reloc_howto_type *howto;
1267 1.1 christos unsigned long r_symndx;
1268 1.1 christos Elf_Internal_Sym *sym;
1269 1.1 christos asection *sec;
1270 1.1 christos struct elf_link_hash_entry *h;
1271 1.1 christos bfd_vma relocation;
1272 1.1 christos bfd_reloc_status_type r;
1273 1.1 christos const char *name = NULL;
1274 1.1 christos int r_type;
1275 1.1 christos
1276 1.1 christos r_type = ELF32_R_TYPE (rel->r_info);
1277 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info);
1278 1.1 christos
1279 1.1 christos if (r_type == R_OR1K_GNU_VTINHERIT
1280 1.6 christos || r_type == R_OR1K_GNU_VTENTRY)
1281 1.6 christos continue;
1282 1.1 christos
1283 1.1 christos if (r_type < 0 || r_type >= (int) R_OR1K_max)
1284 1.6 christos {
1285 1.6 christos _bfd_error_handler
1286 1.6 christos (_("%pB: unknown relocation type %d"),
1287 1.6 christos input_bfd, (int) r_type);
1288 1.6 christos bfd_set_error (bfd_error_bad_value);
1289 1.6 christos ret_val = FALSE;
1290 1.6 christos continue;
1291 1.6 christos }
1292 1.1 christos
1293 1.1 christos howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
1294 1.1 christos h = NULL;
1295 1.1 christos sym = NULL;
1296 1.1 christos sec = NULL;
1297 1.1 christos
1298 1.1 christos if (r_symndx < symtab_hdr->sh_info)
1299 1.6 christos {
1300 1.6 christos sym = local_syms + r_symndx;
1301 1.6 christos sec = local_sections[r_symndx];
1302 1.6 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1303 1.6 christos
1304 1.6 christos name = bfd_elf_string_from_elf_section
1305 1.6 christos (input_bfd, symtab_hdr->sh_link, sym->st_name);
1306 1.6 christos name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1307 1.6 christos }
1308 1.1 christos else
1309 1.6 christos {
1310 1.6 christos bfd_boolean unresolved_reloc, warned, ignored;
1311 1.1 christos
1312 1.6 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1313 1.6 christos r_symndx, symtab_hdr, sym_hashes,
1314 1.6 christos h, sec, relocation,
1315 1.6 christos unresolved_reloc, warned, ignored);
1316 1.6 christos name = h->root.root.string;
1317 1.6 christos }
1318 1.1 christos
1319 1.1 christos if (sec != NULL && discarded_section (sec))
1320 1.6 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1321 1.6 christos rel, 1, relend, howto, 0, contents);
1322 1.1 christos
1323 1.4 christos if (bfd_link_relocatable (info))
1324 1.6 christos continue;
1325 1.1 christos
1326 1.1 christos switch (howto->type)
1327 1.6 christos {
1328 1.6 christos case R_OR1K_PLT26:
1329 1.6 christos case R_OR1K_PLTA26:
1330 1.6 christos /* If the call is not local, redirect the branch to the PLT.
1331 1.6 christos Otherwise do nothing to send the branch to the symbol direct. */
1332 1.6 christos if (!SYMBOL_CALLS_LOCAL (info, h)
1333 1.6 christos && h->plt.offset != (bfd_vma) -1)
1334 1.6 christos relocation = plt_base + h->plt.offset;
1335 1.6 christos
1336 1.6 christos /* Addend should be zero. */
1337 1.6 christos if (rel->r_addend != 0)
1338 1.6 christos {
1339 1.6 christos _bfd_error_handler
1340 1.6 christos (_("%pB: addend should be zero for plt relocations"),
1341 1.6 christos input_bfd);
1342 1.6 christos bfd_set_error (bfd_error_bad_value);
1343 1.6 christos ret_val = FALSE;
1344 1.6 christos }
1345 1.6 christos break;
1346 1.6 christos
1347 1.6 christos case R_OR1K_GOT16:
1348 1.6 christos case R_OR1K_GOT_PG21:
1349 1.6 christos case R_OR1K_GOT_LO13:
1350 1.6 christos {
1351 1.6 christos bfd_vma off;
1352 1.6 christos
1353 1.6 christos /* Relocation is to the entry for this symbol
1354 1.6 christos in the global offset table. */
1355 1.6 christos BFD_ASSERT (sgot != NULL);
1356 1.6 christos if (h != NULL)
1357 1.6 christos {
1358 1.6 christos bfd_boolean dyn;
1359 1.1 christos
1360 1.6 christos off = h->got.offset;
1361 1.6 christos BFD_ASSERT (off != (bfd_vma) -1);
1362 1.1 christos
1363 1.6 christos dyn = htab->root.dynamic_sections_created;
1364 1.6 christos if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
1365 1.4 christos bfd_link_pic (info),
1366 1.4 christos h)
1367 1.6 christos || (bfd_link_pic (info)
1368 1.6 christos && SYMBOL_REFERENCES_LOCAL (info, h)))
1369 1.6 christos {
1370 1.6 christos /* This is actually a static link, or it is a -Bsymbolic
1371 1.6 christos link and the symbol is defined locally, or the symbol
1372 1.6 christos was forced to be local because of a version file.
1373 1.6 christos We must initialize this entry in the GOT. Since the
1374 1.6 christos offset must always be a multiple of 4, we use the least
1375 1.6 christos significant bit to record whether we have initialized
1376 1.6 christos it already.
1377 1.6 christos
1378 1.6 christos When doing a dynamic link, we create a .rela.got
1379 1.6 christos relocation entry to initialize the value. This
1380 1.6 christos is done in the finish_dynamic_symbol routine. */
1381 1.6 christos if ((off & 1) != 0)
1382 1.6 christos off &= ~1;
1383 1.6 christos else
1384 1.6 christos {
1385 1.6 christos /* Write entry in GOT. */
1386 1.6 christos bfd_put_32 (output_bfd, relocation,
1387 1.6 christos sgot->contents + off);
1388 1.6 christos /* Mark GOT entry as having been written. */
1389 1.6 christos h->got.offset |= 1;
1390 1.6 christos }
1391 1.6 christos }
1392 1.6 christos }
1393 1.6 christos else
1394 1.6 christos {
1395 1.6 christos bfd_byte *loc;
1396 1.6 christos
1397 1.6 christos BFD_ASSERT (local_got_offsets != NULL
1398 1.6 christos && local_got_offsets[r_symndx] != (bfd_vma) -1);
1399 1.6 christos
1400 1.6 christos /* Get offset into GOT table. */
1401 1.6 christos off = local_got_offsets[r_symndx];
1402 1.6 christos
1403 1.6 christos /* The offset must always be a multiple of 4. We use
1404 1.6 christos the least significant bit to record whether we have
1405 1.6 christos already processed this entry. */
1406 1.6 christos if ((off & 1) != 0)
1407 1.6 christos off &= ~1;
1408 1.6 christos else
1409 1.6 christos {
1410 1.6 christos /* Write entry in GOT. */
1411 1.6 christos bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1412 1.6 christos if (bfd_link_pic (info))
1413 1.6 christos {
1414 1.6 christos asection *srelgot;
1415 1.6 christos Elf_Internal_Rela outrel;
1416 1.6 christos
1417 1.6 christos /* We need to generate a R_OR1K_RELATIVE reloc
1418 1.6 christos for the dynamic linker. */
1419 1.6 christos srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1420 1.6 christos BFD_ASSERT (srelgot != NULL);
1421 1.6 christos
1422 1.6 christos outrel.r_offset = got_base + off;
1423 1.6 christos outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
1424 1.6 christos outrel.r_addend = relocation;
1425 1.6 christos loc = srelgot->contents;
1426 1.6 christos loc += (srelgot->reloc_count
1427 1.6 christos * sizeof (Elf32_External_Rela));
1428 1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
1429 1.6 christos ++srelgot->reloc_count;
1430 1.6 christos }
1431 1.6 christos local_got_offsets[r_symndx] |= 1;
1432 1.6 christos }
1433 1.6 christos }
1434 1.6 christos
1435 1.6 christos /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
1436 1.6 christos while the GOT16 reloc is GOT relative. */
1437 1.6 christos relocation = got_base + off;
1438 1.6 christos if (r_type == R_OR1K_GOT16)
1439 1.6 christos relocation -= got_sym_value;
1440 1.6 christos
1441 1.6 christos /* Addend should be zero. */
1442 1.6 christos if (rel->r_addend != 0)
1443 1.6 christos {
1444 1.6 christos _bfd_error_handler
1445 1.6 christos (_("%pB: addend should be zero for got relocations"),
1446 1.6 christos input_bfd);
1447 1.6 christos bfd_set_error (bfd_error_bad_value);
1448 1.6 christos ret_val = FALSE;
1449 1.6 christos }
1450 1.6 christos }
1451 1.6 christos break;
1452 1.6 christos
1453 1.6 christos case R_OR1K_GOTOFF_LO16:
1454 1.6 christos case R_OR1K_GOTOFF_HI16:
1455 1.6 christos case R_OR1K_GOTOFF_AHI16:
1456 1.6 christos case R_OR1K_GOTOFF_SLO16:
1457 1.6 christos /* Relocation is offset from GOT. */
1458 1.6 christos BFD_ASSERT (sgot != NULL);
1459 1.6 christos if (!SYMBOL_REFERENCES_LOCAL (info, h))
1460 1.6 christos {
1461 1.6 christos _bfd_error_handler
1462 1.6 christos (_("%pB: gotoff relocation against dynamic symbol %s"),
1463 1.6 christos input_bfd, h->root.root.string);
1464 1.6 christos ret_val = FALSE;
1465 1.6 christos bfd_set_error (bfd_error_bad_value);
1466 1.6 christos }
1467 1.6 christos relocation -= got_sym_value;
1468 1.6 christos break;
1469 1.6 christos
1470 1.6 christos case R_OR1K_INSN_REL_26:
1471 1.6 christos case R_OR1K_PCREL_PG21:
1472 1.6 christos case R_OR1K_LO13:
1473 1.6 christos case R_OR1K_SLO13:
1474 1.6 christos /* For a non-shared link, these will reference either the plt
1475 1.6 christos or a .dynbss copy of the symbol. */
1476 1.6 christos if (bfd_link_pic (info) && !SYMBOL_REFERENCES_LOCAL (info, h))
1477 1.6 christos {
1478 1.6 christos _bfd_error_handler
1479 1.6 christos (_("%pB: pc-relative relocation against dynamic symbol %s"),
1480 1.6 christos input_bfd, name);
1481 1.6 christos ret_val = FALSE;
1482 1.6 christos bfd_set_error (bfd_error_bad_value);
1483 1.6 christos }
1484 1.6 christos break;
1485 1.6 christos
1486 1.6 christos case R_OR1K_HI_16_IN_INSN:
1487 1.6 christos case R_OR1K_LO_16_IN_INSN:
1488 1.6 christos case R_OR1K_AHI16:
1489 1.6 christos case R_OR1K_SLO16:
1490 1.6 christos if (bfd_link_pic (info))
1491 1.6 christos {
1492 1.6 christos _bfd_error_handler
1493 1.6 christos (_("%pB: non-pic relocation against symbol %s"),
1494 1.6 christos input_bfd, name);
1495 1.6 christos ret_val = FALSE;
1496 1.6 christos bfd_set_error (bfd_error_bad_value);
1497 1.6 christos }
1498 1.6 christos break;
1499 1.6 christos
1500 1.6 christos case R_OR1K_32:
1501 1.6 christos /* R_OR1K_16? */
1502 1.6 christos {
1503 1.6 christos /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1504 1.6 christos from removed linkonce sections, or sections discarded by
1505 1.6 christos a linker script. */
1506 1.6 christos if (r_symndx == STN_UNDEF
1507 1.6 christos || (input_section->flags & SEC_ALLOC) == 0)
1508 1.6 christos break;
1509 1.6 christos
1510 1.6 christos /* Emit a direct relocation if the symbol is dynamic,
1511 1.6 christos or a RELATIVE reloc for shared objects. We can omit
1512 1.6 christos RELATIVE relocs to local undefweak symbols. */
1513 1.6 christos if (bfd_link_pic (info)
1514 1.6 christos ? (h == NULL
1515 1.6 christos || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1516 1.6 christos || h->root.type != bfd_link_hash_undefweak)
1517 1.6 christos : (h != NULL
1518 1.6 christos && h->dynindx != -1
1519 1.6 christos && !h->non_got_ref
1520 1.6 christos && ((h->def_dynamic && !h->def_regular)
1521 1.6 christos || h->root.type == bfd_link_hash_undefweak
1522 1.6 christos || h->root.type == bfd_link_hash_undefined)))
1523 1.6 christos {
1524 1.6 christos Elf_Internal_Rela outrel;
1525 1.6 christos bfd_byte *loc;
1526 1.6 christos bfd_boolean skip;
1527 1.6 christos
1528 1.6 christos /* When generating a shared object, these relocations
1529 1.6 christos are copied into the output file to be resolved at run
1530 1.6 christos time. */
1531 1.6 christos
1532 1.6 christos BFD_ASSERT (sreloc != NULL);
1533 1.6 christos
1534 1.6 christos skip = FALSE;
1535 1.6 christos
1536 1.6 christos outrel.r_offset =
1537 1.6 christos _bfd_elf_section_offset (output_bfd, info, input_section,
1538 1.6 christos rel->r_offset);
1539 1.6 christos if (outrel.r_offset == (bfd_vma) -1)
1540 1.6 christos skip = TRUE;
1541 1.6 christos else if (outrel.r_offset == (bfd_vma) -2)
1542 1.6 christos skip = TRUE;
1543 1.6 christos outrel.r_offset += (input_section->output_section->vma
1544 1.6 christos + input_section->output_offset);
1545 1.6 christos
1546 1.6 christos if (skip)
1547 1.6 christos memset (&outrel, 0, sizeof outrel);
1548 1.6 christos else if (SYMBOL_REFERENCES_LOCAL (info, h))
1549 1.6 christos {
1550 1.6 christos outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
1551 1.6 christos outrel.r_addend = relocation + rel->r_addend;
1552 1.6 christos }
1553 1.6 christos else
1554 1.6 christos {
1555 1.6 christos BFD_ASSERT (h->dynindx != -1);
1556 1.6 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1557 1.6 christos outrel.r_addend = rel->r_addend;
1558 1.6 christos }
1559 1.6 christos
1560 1.6 christos loc = sreloc->contents;
1561 1.6 christos loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1562 1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1563 1.6 christos break;
1564 1.6 christos }
1565 1.6 christos break;
1566 1.6 christos }
1567 1.6 christos
1568 1.6 christos case R_OR1K_TLS_LDM_HI16:
1569 1.6 christos case R_OR1K_TLS_LDM_LO16:
1570 1.6 christos case R_OR1K_TLS_LDM_PG21:
1571 1.6 christos case R_OR1K_TLS_LDM_LO13:
1572 1.6 christos case R_OR1K_TLS_LDO_HI16:
1573 1.6 christos case R_OR1K_TLS_LDO_LO16:
1574 1.6 christos /* TODO: implement support for local dynamic. */
1575 1.6 christos BFD_FAIL ();
1576 1.5 christos _bfd_error_handler
1577 1.6 christos (_("%pB: support for local dynamic not implemented"),
1578 1.6 christos input_bfd);
1579 1.6 christos bfd_set_error (bfd_error_bad_value);
1580 1.6 christos return FALSE;
1581 1.6 christos
1582 1.6 christos case R_OR1K_TLS_GD_HI16:
1583 1.6 christos case R_OR1K_TLS_GD_LO16:
1584 1.6 christos case R_OR1K_TLS_GD_PG21:
1585 1.6 christos case R_OR1K_TLS_GD_LO13:
1586 1.6 christos case R_OR1K_TLS_IE_HI16:
1587 1.6 christos case R_OR1K_TLS_IE_LO16:
1588 1.6 christos case R_OR1K_TLS_IE_PG21:
1589 1.6 christos case R_OR1K_TLS_IE_LO13:
1590 1.6 christos case R_OR1K_TLS_IE_AHI16:
1591 1.6 christos {
1592 1.6 christos bfd_vma gotoff;
1593 1.6 christos Elf_Internal_Rela rela;
1594 1.6 christos bfd_byte *loc;
1595 1.6 christos int dynamic;
1596 1.6 christos
1597 1.6 christos sreloc = bfd_get_section_by_name (dynobj, ".rela.got");
1598 1.6 christos
1599 1.6 christos /* Mark as TLS related GOT entry by setting
1600 1.6 christos bit 2 as well as bit 1. */
1601 1.6 christos if (h != NULL)
1602 1.6 christos {
1603 1.6 christos gotoff = h->got.offset;
1604 1.6 christos h->got.offset |= 3;
1605 1.6 christos }
1606 1.6 christos else
1607 1.6 christos {
1608 1.6 christos gotoff = local_got_offsets[r_symndx];
1609 1.6 christos local_got_offsets[r_symndx] |= 3;
1610 1.6 christos }
1611 1.6 christos
1612 1.6 christos /* Only process the relocation once. */
1613 1.6 christos if (gotoff & 1)
1614 1.6 christos {
1615 1.6 christos relocation = sgot->output_offset + (gotoff & ~3);
1616 1.6 christos break;
1617 1.6 christos }
1618 1.1 christos
1619 1.6 christos BFD_ASSERT (elf_hash_table (info)->hgot == NULL
1620 1.1 christos || elf_hash_table (info)->hgot->root.u.def.value == 0);
1621 1.1 christos
1622 1.6 christos /* Dynamic entries will require relocations. if we do not need
1623 1.6 christos them we will just use the default R_OR1K_NONE and
1624 1.6 christos not set anything. */
1625 1.6 christos dynamic = bfd_link_pic (info)
1626 1.1 christos || (sec && (sec->flags & SEC_ALLOC) != 0
1627 1.1 christos && h != NULL
1628 1.1 christos && (h->root.type == bfd_link_hash_defweak || !h->def_regular));
1629 1.1 christos
1630 1.6 christos /* Shared GD. */
1631 1.6 christos if (dynamic
1632 1.6 christos && (howto->type == R_OR1K_TLS_GD_HI16
1633 1.6 christos || howto->type == R_OR1K_TLS_GD_LO16
1634 1.6 christos || howto->type == R_OR1K_TLS_GD_PG21
1635 1.6 christos || howto->type == R_OR1K_TLS_GD_LO13))
1636 1.6 christos {
1637 1.6 christos int i;
1638 1.6 christos
1639 1.6 christos /* Add DTPMOD and DTPOFF GOT and rela entries. */
1640 1.6 christos for (i = 0; i < 2; ++i)
1641 1.6 christos {
1642 1.6 christos rela.r_offset = got_base + gotoff + i*4;
1643 1.6 christos if (h != NULL && h->dynindx != -1)
1644 1.6 christos {
1645 1.6 christos rela.r_info = ELF32_R_INFO (h->dynindx,
1646 1.6 christos (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
1647 1.6 christos rela.r_addend = 0;
1648 1.6 christos }
1649 1.6 christos else
1650 1.6 christos {
1651 1.6 christos rela.r_info = ELF32_R_INFO (0,
1652 1.6 christos (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
1653 1.6 christos rela.r_addend = tpoff (info, relocation);
1654 1.6 christos }
1655 1.6 christos
1656 1.6 christos loc = sreloc->contents;
1657 1.6 christos loc += sreloc->reloc_count++ *
1658 1.6 christos sizeof (Elf32_External_Rela);
1659 1.6 christos
1660 1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1661 1.6 christos bfd_put_32 (output_bfd, 0, sgot->contents + gotoff + i*4);
1662 1.6 christos }
1663 1.6 christos }
1664 1.6 christos /* Static GD. */
1665 1.6 christos else if (howto->type == R_OR1K_TLS_GD_HI16
1666 1.6 christos || howto->type == R_OR1K_TLS_GD_LO16
1667 1.6 christos || howto->type == R_OR1K_TLS_GD_PG21
1668 1.6 christos || howto->type == R_OR1K_TLS_GD_LO13)
1669 1.6 christos {
1670 1.6 christos bfd_put_32 (output_bfd, 1, sgot->contents + gotoff);
1671 1.6 christos bfd_put_32 (output_bfd, tpoff (info, relocation),
1672 1.6 christos sgot->contents + gotoff + 4);
1673 1.6 christos }
1674 1.6 christos /* Shared IE. */
1675 1.6 christos else if (dynamic)
1676 1.6 christos {
1677 1.6 christos /* Add TPOFF GOT and rela entries. */
1678 1.6 christos rela.r_offset = got_base + gotoff;
1679 1.6 christos if (h != NULL && h->dynindx != -1)
1680 1.6 christos {
1681 1.6 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
1682 1.6 christos rela.r_addend = 0;
1683 1.6 christos }
1684 1.6 christos else
1685 1.6 christos {
1686 1.6 christos rela.r_info = ELF32_R_INFO (0, R_OR1K_TLS_TPOFF);
1687 1.6 christos rela.r_addend = tpoff (info, relocation);
1688 1.6 christos }
1689 1.6 christos
1690 1.6 christos loc = sreloc->contents;
1691 1.6 christos loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1692 1.6 christos
1693 1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1694 1.6 christos bfd_put_32 (output_bfd, 0, sgot->contents + gotoff);
1695 1.6 christos }
1696 1.6 christos /* Static IE. */
1697 1.6 christos else
1698 1.6 christos {
1699 1.6 christos bfd_put_32 (output_bfd, tpoff (info, relocation),
1700 1.1 christos sgot->contents + gotoff);
1701 1.6 christos }
1702 1.6 christos
1703 1.6 christos /* The PG21 and LO13 relocs are pc-relative, while the
1704 1.6 christos rest are GOT relative. */
1705 1.6 christos relocation = got_base + gotoff;
1706 1.6 christos if (!(r_type == R_OR1K_TLS_GD_PG21
1707 1.6 christos || r_type == R_OR1K_TLS_GD_LO13
1708 1.6 christos || r_type == R_OR1K_TLS_IE_PG21
1709 1.6 christos || r_type == R_OR1K_TLS_IE_LO13))
1710 1.6 christos relocation -= got_sym_value;
1711 1.6 christos }
1712 1.6 christos break;
1713 1.6 christos
1714 1.6 christos case R_OR1K_TLS_LE_HI16:
1715 1.6 christos case R_OR1K_TLS_LE_LO16:
1716 1.6 christos case R_OR1K_TLS_LE_AHI16:
1717 1.6 christos case R_OR1K_TLS_LE_SLO16:
1718 1.6 christos /* Relocation is offset from TP. */
1719 1.6 christos relocation = tpoff (info, relocation);
1720 1.6 christos break;
1721 1.6 christos
1722 1.6 christos case R_OR1K_TLS_DTPMOD:
1723 1.6 christos case R_OR1K_TLS_DTPOFF:
1724 1.6 christos case R_OR1K_TLS_TPOFF:
1725 1.6 christos /* These are resolved dynamically on load and shouldn't
1726 1.6 christos be used as linker input. */
1727 1.6 christos BFD_FAIL ();
1728 1.5 christos _bfd_error_handler
1729 1.6 christos (_("%pB: will not resolve runtime TLS relocation"),
1730 1.6 christos input_bfd);
1731 1.6 christos bfd_set_error (bfd_error_bad_value);
1732 1.6 christos return FALSE;
1733 1.6 christos
1734 1.6 christos default:
1735 1.6 christos break;
1736 1.6 christos }
1737 1.6 christos
1738 1.6 christos r = or1k_final_link_relocate (howto, input_bfd, input_section, contents,
1739 1.6 christos rel->r_offset, relocation + rel->r_addend);
1740 1.1 christos
1741 1.1 christos if (r != bfd_reloc_ok)
1742 1.6 christos {
1743 1.6 christos const char *msg = NULL;
1744 1.1 christos
1745 1.6 christos switch (r)
1746 1.6 christos {
1747 1.6 christos case bfd_reloc_overflow:
1748 1.4 christos (*info->callbacks->reloc_overflow)
1749 1.6 christos (info, (h ? &h->root : NULL), name, howto->name,
1750 1.6 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1751 1.6 christos break;
1752 1.1 christos
1753 1.6 christos case bfd_reloc_undefined:
1754 1.4 christos (*info->callbacks->undefined_symbol)
1755 1.6 christos (info, name, input_bfd, input_section, rel->r_offset, TRUE);
1756 1.6 christos break;
1757 1.1 christos
1758 1.6 christos case bfd_reloc_outofrange:
1759 1.6 christos msg = _("internal error: out of range error");
1760 1.6 christos break;
1761 1.6 christos
1762 1.6 christos case bfd_reloc_notsupported:
1763 1.6 christos msg = _("internal error: unsupported relocation error");
1764 1.6 christos break;
1765 1.6 christos
1766 1.6 christos case bfd_reloc_dangerous:
1767 1.6 christos msg = _("internal error: dangerous relocation");
1768 1.6 christos break;
1769 1.6 christos
1770 1.6 christos default:
1771 1.6 christos msg = _("internal error: unknown error");
1772 1.6 christos break;
1773 1.6 christos }
1774 1.1 christos
1775 1.6 christos if (msg)
1776 1.4 christos (*info->callbacks->warning) (info, msg, name, input_bfd,
1777 1.4 christos input_section, rel->r_offset);
1778 1.6 christos }
1779 1.1 christos }
1780 1.1 christos
1781 1.6 christos return ret_val;
1782 1.1 christos }
1783 1.1 christos
1784 1.1 christos /* Return the section that should be marked against GC for a given
1785 1.1 christos relocation. */
1786 1.1 christos
1787 1.1 christos static asection *
1788 1.1 christos or1k_elf_gc_mark_hook (asection *sec,
1789 1.1 christos struct bfd_link_info *info,
1790 1.1 christos Elf_Internal_Rela *rel,
1791 1.1 christos struct elf_link_hash_entry *h,
1792 1.1 christos Elf_Internal_Sym *sym)
1793 1.1 christos {
1794 1.1 christos if (h != NULL)
1795 1.1 christos switch (ELF32_R_TYPE (rel->r_info))
1796 1.1 christos {
1797 1.1 christos case R_OR1K_GNU_VTINHERIT:
1798 1.1 christos case R_OR1K_GNU_VTENTRY:
1799 1.6 christos return NULL;
1800 1.1 christos }
1801 1.1 christos
1802 1.1 christos return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1803 1.1 christos }
1804 1.1 christos
1805 1.1 christos /* Look through the relocs for a section during the first phase. */
1806 1.1 christos
1807 1.1 christos static bfd_boolean
1808 1.1 christos or1k_elf_check_relocs (bfd *abfd,
1809 1.1 christos struct bfd_link_info *info,
1810 1.1 christos asection *sec,
1811 1.1 christos const Elf_Internal_Rela *relocs)
1812 1.1 christos {
1813 1.1 christos Elf_Internal_Shdr *symtab_hdr;
1814 1.1 christos struct elf_link_hash_entry **sym_hashes;
1815 1.1 christos const Elf_Internal_Rela *rel;
1816 1.1 christos
1817 1.1 christos const Elf_Internal_Rela *rel_end;
1818 1.1 christos struct elf_or1k_link_hash_table *htab;
1819 1.1 christos bfd *dynobj;
1820 1.1 christos asection *sreloc = NULL;
1821 1.1 christos
1822 1.4 christos if (bfd_link_relocatable (info))
1823 1.1 christos return TRUE;
1824 1.1 christos
1825 1.6 christos /* Don't do anything special with non-loaded, non-alloced sections.
1826 1.6 christos In particular, any relocs in such sections should not affect GOT
1827 1.6 christos and PLT reference counting (ie. we don't allow them to create GOT
1828 1.6 christos or PLT entries), there's no possibility or desire to optimize TLS
1829 1.6 christos relocs, and there's not much point in propagating relocs to shared
1830 1.6 christos libs that the dynamic linker won't relocate. */
1831 1.6 christos if ((sec->flags & SEC_ALLOC) == 0)
1832 1.6 christos return TRUE;
1833 1.6 christos
1834 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1835 1.1 christos sym_hashes = elf_sym_hashes (abfd);
1836 1.1 christos
1837 1.1 christos htab = or1k_elf_hash_table (info);
1838 1.1 christos if (htab == NULL)
1839 1.1 christos return FALSE;
1840 1.1 christos
1841 1.1 christos dynobj = htab->root.dynobj;
1842 1.1 christos
1843 1.1 christos rel_end = relocs + sec->reloc_count;
1844 1.1 christos for (rel = relocs; rel < rel_end; rel++)
1845 1.1 christos {
1846 1.1 christos struct elf_link_hash_entry *h;
1847 1.1 christos unsigned long r_symndx;
1848 1.1 christos unsigned char tls_type;
1849 1.6 christos int r_type;
1850 1.1 christos
1851 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info);
1852 1.1 christos if (r_symndx < symtab_hdr->sh_info)
1853 1.6 christos h = NULL;
1854 1.1 christos else
1855 1.6 christos {
1856 1.6 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1857 1.6 christos while (h->root.type == bfd_link_hash_indirect
1858 1.6 christos || h->root.type == bfd_link_hash_warning)
1859 1.6 christos h = (struct elf_link_hash_entry *) h->root.u.i.link;
1860 1.6 christos }
1861 1.6 christos
1862 1.6 christos r_type = ELF32_R_TYPE (rel->r_info);
1863 1.6 christos switch (r_type)
1864 1.6 christos {
1865 1.6 christos case R_OR1K_TLS_GD_HI16:
1866 1.6 christos case R_OR1K_TLS_GD_LO16:
1867 1.6 christos case R_OR1K_TLS_GD_PG21:
1868 1.6 christos case R_OR1K_TLS_GD_LO13:
1869 1.6 christos tls_type = TLS_GD;
1870 1.6 christos break;
1871 1.6 christos case R_OR1K_TLS_LDM_HI16:
1872 1.6 christos case R_OR1K_TLS_LDM_LO16:
1873 1.6 christos case R_OR1K_TLS_LDM_PG21:
1874 1.6 christos case R_OR1K_TLS_LDM_LO13:
1875 1.6 christos case R_OR1K_TLS_LDO_HI16:
1876 1.6 christos case R_OR1K_TLS_LDO_LO16:
1877 1.6 christos tls_type = TLS_LD;
1878 1.6 christos break;
1879 1.6 christos case R_OR1K_TLS_IE_HI16:
1880 1.6 christos case R_OR1K_TLS_IE_LO16:
1881 1.6 christos case R_OR1K_TLS_IE_PG21:
1882 1.6 christos case R_OR1K_TLS_IE_LO13:
1883 1.6 christos case R_OR1K_TLS_IE_AHI16:
1884 1.6 christos tls_type = TLS_IE;
1885 1.6 christos break;
1886 1.6 christos case R_OR1K_TLS_LE_HI16:
1887 1.6 christos case R_OR1K_TLS_LE_LO16:
1888 1.6 christos case R_OR1K_TLS_LE_AHI16:
1889 1.6 christos case R_OR1K_TLS_LE_SLO16:
1890 1.6 christos tls_type = TLS_LE;
1891 1.6 christos break;
1892 1.6 christos default:
1893 1.6 christos tls_type = TLS_NONE;
1894 1.6 christos }
1895 1.1 christos
1896 1.1 christos /* Record TLS type. */
1897 1.1 christos if (h != NULL)
1898 1.6 christos ((struct elf_or1k_link_hash_entry *) h)->tls_type = tls_type;
1899 1.1 christos else
1900 1.6 christos {
1901 1.6 christos unsigned char *local_tls_type;
1902 1.1 christos
1903 1.6 christos /* This is a TLS type record for a local symbol. */
1904 1.6 christos local_tls_type = (unsigned char *) elf_or1k_local_tls_type (abfd);
1905 1.6 christos if (local_tls_type == NULL)
1906 1.6 christos {
1907 1.6 christos bfd_size_type size;
1908 1.6 christos
1909 1.6 christos size = symtab_hdr->sh_info;
1910 1.6 christos local_tls_type = bfd_zalloc (abfd, size);
1911 1.6 christos if (local_tls_type == NULL)
1912 1.6 christos return FALSE;
1913 1.6 christos elf_or1k_local_tls_type (abfd) = local_tls_type;
1914 1.6 christos }
1915 1.6 christos local_tls_type[r_symndx] = tls_type;
1916 1.6 christos }
1917 1.6 christos
1918 1.6 christos switch (r_type)
1919 1.6 christos {
1920 1.6 christos /* This relocation describes the C++ object vtable hierarchy.
1921 1.6 christos Reconstruct it for later use during GC. */
1922 1.6 christos case R_OR1K_GNU_VTINHERIT:
1923 1.6 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1924 1.6 christos return FALSE;
1925 1.6 christos break;
1926 1.6 christos
1927 1.6 christos /* This relocation describes which C++ vtable entries are actually
1928 1.6 christos used. Record for later use during GC. */
1929 1.6 christos case R_OR1K_GNU_VTENTRY:
1930 1.6 christos BFD_ASSERT (h != NULL);
1931 1.6 christos if (h != NULL
1932 1.6 christos && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1933 1.6 christos return FALSE;
1934 1.6 christos break;
1935 1.6 christos
1936 1.6 christos /* This relocation requires .plt entry. */
1937 1.6 christos case R_OR1K_PLTA26:
1938 1.6 christos htab->saw_plta = TRUE;
1939 1.6 christos /* FALLTHRU */
1940 1.6 christos case R_OR1K_PLT26:
1941 1.6 christos if (h != NULL)
1942 1.6 christos {
1943 1.6 christos h->needs_plt = 1;
1944 1.6 christos h->plt.refcount += 1;
1945 1.6 christos }
1946 1.6 christos break;
1947 1.6 christos
1948 1.6 christos case R_OR1K_GOT16:
1949 1.6 christos case R_OR1K_GOT_PG21:
1950 1.6 christos case R_OR1K_GOT_LO13:
1951 1.6 christos case R_OR1K_TLS_GD_HI16:
1952 1.6 christos case R_OR1K_TLS_GD_LO16:
1953 1.6 christos case R_OR1K_TLS_GD_PG21:
1954 1.6 christos case R_OR1K_TLS_GD_LO13:
1955 1.6 christos case R_OR1K_TLS_IE_HI16:
1956 1.6 christos case R_OR1K_TLS_IE_LO16:
1957 1.6 christos case R_OR1K_TLS_IE_PG21:
1958 1.6 christos case R_OR1K_TLS_IE_LO13:
1959 1.6 christos case R_OR1K_TLS_IE_AHI16:
1960 1.6 christos if (h != NULL)
1961 1.6 christos h->got.refcount += 1;
1962 1.6 christos else
1963 1.6 christos {
1964 1.6 christos bfd_signed_vma *local_got_refcounts;
1965 1.6 christos
1966 1.6 christos /* This is a global offset table entry for a local symbol. */
1967 1.6 christos local_got_refcounts = elf_local_got_refcounts (abfd);
1968 1.6 christos if (local_got_refcounts == NULL)
1969 1.6 christos {
1970 1.6 christos bfd_size_type size;
1971 1.6 christos
1972 1.6 christos size = symtab_hdr->sh_info;
1973 1.6 christos size *= sizeof (bfd_signed_vma);
1974 1.6 christos local_got_refcounts = bfd_zalloc (abfd, size);
1975 1.6 christos if (local_got_refcounts == NULL)
1976 1.6 christos return FALSE;
1977 1.6 christos elf_local_got_refcounts (abfd) = local_got_refcounts;
1978 1.6 christos }
1979 1.6 christos local_got_refcounts[r_symndx] += 1;
1980 1.6 christos }
1981 1.6 christos /* FALLTHRU */
1982 1.6 christos
1983 1.6 christos case R_OR1K_GOTOFF_HI16:
1984 1.6 christos case R_OR1K_GOTOFF_LO16:
1985 1.6 christos case R_OR1K_GOTOFF_AHI16:
1986 1.6 christos case R_OR1K_GOTOFF_SLO16:
1987 1.6 christos if (htab->root.sgot == NULL)
1988 1.6 christos {
1989 1.6 christos if (dynobj == NULL)
1990 1.6 christos htab->root.dynobj = dynobj = abfd;
1991 1.6 christos if (!_bfd_elf_create_got_section (dynobj, info))
1992 1.6 christos return FALSE;
1993 1.6 christos }
1994 1.6 christos break;
1995 1.6 christos
1996 1.6 christos case R_OR1K_INSN_REL_26:
1997 1.6 christos case R_OR1K_HI_16_IN_INSN:
1998 1.6 christos case R_OR1K_LO_16_IN_INSN:
1999 1.6 christos case R_OR1K_AHI16:
2000 1.6 christos case R_OR1K_SLO16:
2001 1.6 christos case R_OR1K_32:
2002 1.6 christos case R_OR1K_PCREL_PG21:
2003 1.6 christos case R_OR1K_LO13:
2004 1.6 christos case R_OR1K_SLO13:
2005 1.6 christos {
2006 1.6 christos if (h != NULL && !bfd_link_pic (info))
2007 1.6 christos {
2008 1.6 christos /* We may need a copy reloc. */
2009 1.6 christos h->non_got_ref = 1;
2010 1.6 christos
2011 1.6 christos /* We may also need a .plt entry. */
2012 1.6 christos h->plt.refcount += 1;
2013 1.6 christos if (r_type != R_OR1K_INSN_REL_26)
2014 1.6 christos h->pointer_equality_needed = 1;
2015 1.6 christos }
2016 1.6 christos
2017 1.6 christos /* If we are creating a shared library, and this is a reloc
2018 1.6 christos against a global symbol, or a non PC relative reloc
2019 1.6 christos against a local symbol, then we need to copy the reloc
2020 1.6 christos into the shared library. However, if we are linking with
2021 1.6 christos -Bsymbolic, we do not need to copy a reloc against a
2022 1.6 christos global symbol which is defined in an object we are
2023 1.6 christos including in the link (i.e., DEF_REGULAR is set). At
2024 1.6 christos this point we have not seen all the input files, so it is
2025 1.6 christos possible that DEF_REGULAR is not set now but will be set
2026 1.6 christos later (it is never cleared). In case of a weak definition,
2027 1.6 christos DEF_REGULAR may be cleared later by a strong definition in
2028 1.6 christos a shared library. We account for that possibility below by
2029 1.6 christos storing information in the relocs_copied field of the hash
2030 1.6 christos table entry. A similar situation occurs when creating
2031 1.6 christos shared libraries and symbol visibility changes render the
2032 1.6 christos symbol local.
2033 1.6 christos
2034 1.6 christos If on the other hand, we are creating an executable, we
2035 1.6 christos may need to keep relocations for symbols satisfied by a
2036 1.6 christos dynamic library if we manage to avoid copy relocs for the
2037 1.6 christos symbol. */
2038 1.6 christos
2039 1.6 christos if ((bfd_link_pic (info)
2040 1.6 christos && (sec->flags & SEC_ALLOC) != 0
2041 1.6 christos && (r_type != R_OR1K_INSN_REL_26
2042 1.6 christos || (h != NULL
2043 1.6 christos && (!SYMBOLIC_BIND (info, h)
2044 1.6 christos || h->root.type == bfd_link_hash_defweak
2045 1.6 christos || !h->def_regular))))
2046 1.6 christos || (!bfd_link_pic (info)
2047 1.6 christos && (sec->flags & SEC_ALLOC) != 0
2048 1.6 christos && h != NULL
2049 1.6 christos && (h->root.type == bfd_link_hash_defweak
2050 1.6 christos || !h->def_regular)))
2051 1.6 christos {
2052 1.6 christos struct elf_dyn_relocs *p;
2053 1.6 christos struct elf_dyn_relocs **head;
2054 1.6 christos
2055 1.6 christos /* When creating a shared object, we must copy these
2056 1.6 christos relocs into the output file. We create a reloc
2057 1.6 christos section in dynobj and make room for the reloc. */
2058 1.6 christos if (sreloc == NULL)
2059 1.6 christos {
2060 1.6 christos const char *name;
2061 1.6 christos unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
2062 1.6 christos unsigned int shnam = _bfd_elf_single_rel_hdr (sec)->sh_name;
2063 1.6 christos
2064 1.6 christos name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
2065 1.6 christos if (name == NULL)
2066 1.6 christos return FALSE;
2067 1.6 christos
2068 1.6 christos if (strncmp (name, ".rela", 5) != 0
2069 1.6 christos || strcmp (bfd_get_section_name (abfd, sec),
2070 1.6 christos name + 5) != 0)
2071 1.6 christos {
2072 1.5 christos _bfd_error_handler
2073 1.5 christos /* xgettext:c-format */
2074 1.6 christos (_("%pB: bad relocation section name `%s\'"),
2075 1.6 christos abfd, name);
2076 1.6 christos }
2077 1.6 christos
2078 1.6 christos if (htab->root.dynobj == NULL)
2079 1.6 christos htab->root.dynobj = abfd;
2080 1.6 christos dynobj = htab->root.dynobj;
2081 1.6 christos
2082 1.6 christos sreloc = bfd_get_section_by_name (dynobj, name);
2083 1.6 christos if (sreloc == NULL)
2084 1.6 christos {
2085 1.6 christos sreloc = _bfd_elf_make_dynamic_reloc_section
2086 1.6 christos (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2087 1.6 christos
2088 1.6 christos if (sreloc == NULL)
2089 1.6 christos return FALSE;
2090 1.6 christos }
2091 1.6 christos elf_section_data (sec)->sreloc = sreloc;
2092 1.6 christos }
2093 1.6 christos
2094 1.6 christos /* If this is a global symbol, we count the number of
2095 1.6 christos relocations we need for this symbol. */
2096 1.6 christos if (h != NULL)
2097 1.6 christos head = &((struct elf_or1k_link_hash_entry *) h)->dyn_relocs;
2098 1.6 christos else
2099 1.6 christos {
2100 1.6 christos /* Track dynamic relocs needed for local syms too.
2101 1.6 christos We really need local syms available to do this
2102 1.6 christos easily. Oh well. */
2103 1.6 christos
2104 1.6 christos asection *s;
2105 1.6 christos Elf_Internal_Sym *isym;
2106 1.6 christos void *vpp;
2107 1.6 christos
2108 1.6 christos isym = bfd_sym_from_r_symndx (&htab->sym_sec,
2109 1.6 christos abfd, r_symndx);
2110 1.6 christos if (isym == NULL)
2111 1.6 christos return FALSE;
2112 1.6 christos
2113 1.6 christos s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2114 1.6 christos if (s == NULL)
2115 1.6 christos return FALSE;
2116 1.6 christos
2117 1.6 christos vpp = &elf_section_data (s)->local_dynrel;
2118 1.6 christos head = (struct elf_dyn_relocs **) vpp;
2119 1.6 christos }
2120 1.6 christos
2121 1.6 christos p = *head;
2122 1.6 christos if (p == NULL || p->sec != sec)
2123 1.6 christos {
2124 1.6 christos bfd_size_type amt = sizeof *p;
2125 1.6 christos p = ((struct elf_dyn_relocs *)
2126 1.6 christos bfd_alloc (htab->root.dynobj, amt));
2127 1.6 christos if (p == NULL)
2128 1.6 christos return FALSE;
2129 1.6 christos p->next = *head;
2130 1.6 christos *head = p;
2131 1.6 christos p->sec = sec;
2132 1.6 christos p->count = 0;
2133 1.6 christos p->pc_count = 0;
2134 1.6 christos }
2135 1.6 christos
2136 1.6 christos p->count += 1;
2137 1.6 christos if (r_type == R_OR1K_INSN_REL_26)
2138 1.6 christos p->pc_count += 1;
2139 1.6 christos }
2140 1.6 christos }
2141 1.6 christos break;
2142 1.6 christos }
2143 1.1 christos }
2144 1.1 christos
2145 1.1 christos return TRUE;
2146 1.1 christos }
2147 1.1 christos
2148 1.6 christos static void
2149 1.6 christos or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insn1,
2150 1.6 christos unsigned insn2, unsigned insn3, unsigned insnj)
2151 1.6 christos {
2152 1.6 christos unsigned nodelay = elf_elfheader (output_bfd)->e_flags & EF_OR1K_NODELAY;
2153 1.6 christos unsigned insn4;
2154 1.6 christos
2155 1.6 christos /* Honor the no-delay-slot setting. */
2156 1.6 christos if (insn3 == OR1K_NOP)
2157 1.6 christos {
2158 1.6 christos insn4 = insn3;
2159 1.6 christos if (nodelay)
2160 1.6 christos insn3 = insnj;
2161 1.6 christos else
2162 1.6 christos insn3 = insn2, insn2 = insnj;
2163 1.6 christos }
2164 1.6 christos else
2165 1.6 christos {
2166 1.6 christos if (nodelay)
2167 1.6 christos insn4 = insnj;
2168 1.6 christos else
2169 1.6 christos insn4 = insn3, insn3 = insnj;
2170 1.6 christos }
2171 1.6 christos
2172 1.6 christos bfd_put_32 (output_bfd, insn1, contents);
2173 1.6 christos bfd_put_32 (output_bfd, insn2, contents + 4);
2174 1.6 christos bfd_put_32 (output_bfd, insn3, contents + 8);
2175 1.6 christos bfd_put_32 (output_bfd, insn4, contents + 12);
2176 1.6 christos }
2177 1.6 christos
2178 1.1 christos /* Finish up the dynamic sections. */
2179 1.1 christos
2180 1.1 christos static bfd_boolean
2181 1.1 christos or1k_elf_finish_dynamic_sections (bfd *output_bfd,
2182 1.6 christos struct bfd_link_info *info)
2183 1.1 christos {
2184 1.1 christos bfd *dynobj;
2185 1.1 christos asection *sdyn, *sgot;
2186 1.1 christos struct elf_or1k_link_hash_table *htab;
2187 1.1 christos
2188 1.1 christos htab = or1k_elf_hash_table (info);
2189 1.1 christos if (htab == NULL)
2190 1.1 christos return FALSE;
2191 1.1 christos
2192 1.1 christos dynobj = htab->root.dynobj;
2193 1.1 christos
2194 1.5 christos sgot = htab->root.sgotplt;
2195 1.1 christos sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2196 1.1 christos
2197 1.1 christos if (htab->root.dynamic_sections_created)
2198 1.1 christos {
2199 1.1 christos asection *splt;
2200 1.1 christos Elf32_External_Dyn *dyncon, *dynconend;
2201 1.1 christos
2202 1.1 christos BFD_ASSERT (sgot != NULL && sdyn != NULL);
2203 1.1 christos
2204 1.1 christos dyncon = (Elf32_External_Dyn *) sdyn->contents;
2205 1.1 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
2206 1.1 christos
2207 1.1 christos for (; dyncon < dynconend; dyncon++)
2208 1.6 christos {
2209 1.6 christos Elf_Internal_Dyn dyn;
2210 1.6 christos asection *s;
2211 1.6 christos
2212 1.6 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2213 1.6 christos
2214 1.6 christos switch (dyn.d_tag)
2215 1.6 christos {
2216 1.6 christos default:
2217 1.6 christos continue;
2218 1.6 christos
2219 1.6 christos case DT_PLTGOT:
2220 1.6 christos s = htab->root.sgotplt;
2221 1.6 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2222 1.6 christos break;
2223 1.6 christos
2224 1.6 christos case DT_JMPREL:
2225 1.6 christos s = htab->root.srelplt;
2226 1.6 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2227 1.6 christos break;
2228 1.6 christos
2229 1.6 christos case DT_PLTRELSZ:
2230 1.6 christos s = htab->root.srelplt;
2231 1.6 christos dyn.d_un.d_val = s->size;
2232 1.6 christos break;
2233 1.6 christos }
2234 1.6 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2235 1.6 christos }
2236 1.1 christos
2237 1.1 christos
2238 1.1 christos /* Fill in the first entry in the procedure linkage table. */
2239 1.5 christos splt = htab->root.splt;
2240 1.1 christos if (splt && splt->size > 0)
2241 1.6 christos {
2242 1.6 christos unsigned plt0, plt1, plt2;
2243 1.6 christos bfd_vma got_addr = sgot->output_section->vma + sgot->output_offset;
2244 1.6 christos
2245 1.6 christos /* Note we force 16 byte alignment on the .got, so that
2246 1.6 christos the movhi/adrp can be shared between the two loads. */
2247 1.6 christos
2248 1.6 christos if (htab->saw_plta)
2249 1.6 christos {
2250 1.6 christos bfd_vma pc = splt->output_section->vma + splt->output_offset;
2251 1.6 christos unsigned pa = ((got_addr >> 13) - (pc >> 13)) & 0x1fffff;
2252 1.6 christos unsigned po = got_addr & 0x1fff;
2253 1.6 christos plt0 = OR1K_ADRP(12) | pa;
2254 1.6 christos plt1 = OR1K_LWZ(15,12) | (po + 8);
2255 1.6 christos plt2 = OR1K_LWZ(12,12) | (po + 4);
2256 1.6 christos }
2257 1.6 christos else if (bfd_link_pic (info))
2258 1.6 christos {
2259 1.6 christos plt0 = OR1K_LWZ(15, 16) | 8; /* .got+8 */
2260 1.6 christos plt1 = OR1K_LWZ(12, 16) | 4; /* .got+4 */
2261 1.6 christos plt2 = OR1K_NOP;
2262 1.6 christos }
2263 1.6 christos else
2264 1.6 christos {
2265 1.6 christos unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
2266 1.6 christos unsigned lo = got_addr & 0xffff;
2267 1.6 christos plt0 = OR1K_MOVHI(12) | ha;
2268 1.6 christos plt1 = OR1K_LWZ(15,12) | (lo + 8);
2269 1.6 christos plt2 = OR1K_LWZ(12,12) | (lo + 4);
2270 1.6 christos }
2271 1.1 christos
2272 1.6 christos or1k_write_plt_entry (output_bfd, splt->contents,
2273 1.6 christos plt0, plt1, plt2, OR1K_JR(15));
2274 1.6 christos
2275 1.6 christos elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
2276 1.6 christos }
2277 1.1 christos }
2278 1.1 christos
2279 1.1 christos /* Set the first entry in the global offset table to the address of
2280 1.1 christos the dynamic section. */
2281 1.1 christos if (sgot && sgot->size > 0)
2282 1.1 christos {
2283 1.1 christos if (sdyn == NULL)
2284 1.6 christos bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2285 1.1 christos else
2286 1.6 christos bfd_put_32 (output_bfd,
2287 1.6 christos sdyn->output_section->vma + sdyn->output_offset,
2288 1.6 christos sgot->contents);
2289 1.1 christos elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2290 1.1 christos }
2291 1.1 christos
2292 1.5 christos if (htab->root.sgot && htab->root.sgot->size > 0)
2293 1.5 christos elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize = 4;
2294 1.1 christos
2295 1.1 christos return TRUE;
2296 1.1 christos }
2297 1.1 christos
2298 1.1 christos /* Finish up dynamic symbol handling. We set the contents of various
2299 1.1 christos dynamic sections here. */
2300 1.1 christos
2301 1.1 christos static bfd_boolean
2302 1.1 christos or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
2303 1.6 christos struct bfd_link_info *info,
2304 1.6 christos struct elf_link_hash_entry *h,
2305 1.6 christos Elf_Internal_Sym *sym)
2306 1.1 christos {
2307 1.1 christos struct elf_or1k_link_hash_table *htab;
2308 1.1 christos bfd_byte *loc;
2309 1.1 christos
2310 1.1 christos htab = or1k_elf_hash_table (info);
2311 1.1 christos if (htab == NULL)
2312 1.1 christos return FALSE;
2313 1.1 christos
2314 1.1 christos if (h->plt.offset != (bfd_vma) -1)
2315 1.1 christos {
2316 1.6 christos unsigned int plt0, plt1, plt2;
2317 1.1 christos asection *splt;
2318 1.1 christos asection *sgot;
2319 1.1 christos asection *srela;
2320 1.6 christos bfd_vma plt_base_addr;
2321 1.6 christos bfd_vma plt_addr;
2322 1.1 christos bfd_vma plt_index;
2323 1.6 christos bfd_vma plt_reloc;
2324 1.6 christos bfd_vma got_base_addr;
2325 1.1 christos bfd_vma got_offset;
2326 1.1 christos bfd_vma got_addr;
2327 1.1 christos Elf_Internal_Rela rela;
2328 1.1 christos
2329 1.1 christos /* This symbol has an entry in the procedure linkage table. Set
2330 1.6 christos it up. */
2331 1.1 christos BFD_ASSERT (h->dynindx != -1);
2332 1.1 christos
2333 1.5 christos splt = htab->root.splt;
2334 1.5 christos sgot = htab->root.sgotplt;
2335 1.5 christos srela = htab->root.srelplt;
2336 1.1 christos BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
2337 1.1 christos
2338 1.6 christos plt_base_addr = splt->output_section->vma + splt->output_offset;
2339 1.6 christos got_base_addr = sgot->output_section->vma + sgot->output_offset;
2340 1.6 christos
2341 1.1 christos /* Get the index in the procedure linkage table which
2342 1.6 christos corresponds to this symbol. This is the index of this symbol
2343 1.6 christos in all the symbols for which we are making plt entries. The
2344 1.6 christos first entry in the procedure linkage table is reserved. */
2345 1.1 christos plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2346 1.6 christos plt_addr = plt_base_addr + h->plt.offset;
2347 1.6 christos plt_reloc = plt_index * sizeof (Elf32_External_Rela);
2348 1.1 christos
2349 1.1 christos /* Get the offset into the .got table of the entry that
2350 1.6 christos corresponds to this function. Each .got entry is 4 bytes.
2351 1.6 christos The first three are reserved. */
2352 1.1 christos got_offset = (plt_index + 3) * 4;
2353 1.6 christos got_addr = got_base_addr + got_offset;
2354 1.1 christos
2355 1.1 christos /* Fill in the entry in the procedure linkage table. */
2356 1.6 christos if (htab->saw_plta)
2357 1.6 christos {
2358 1.6 christos unsigned pa = ((got_addr >> 13) - (plt_addr >> 13)) & 0x1fffff;
2359 1.6 christos unsigned po = (got_addr & 0x1fff);
2360 1.6 christos plt0 = OR1K_ADRP(12) | pa;
2361 1.6 christos plt1 = OR1K_LWZ(12,12) | po;
2362 1.6 christos plt2 = OR1K_ORI0(11) | plt_reloc;
2363 1.6 christos }
2364 1.6 christos else if (bfd_link_pic (info))
2365 1.6 christos {
2366 1.6 christos plt0 = OR1K_LWZ(12,16) | got_offset;
2367 1.6 christos plt1 = OR1K_ORI0(11) | plt_reloc;
2368 1.6 christos plt2 = OR1K_NOP;
2369 1.6 christos }
2370 1.1 christos else
2371 1.6 christos {
2372 1.6 christos unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
2373 1.6 christos unsigned lo = got_addr & 0xffff;
2374 1.6 christos plt0 = OR1K_MOVHI(12) | ha;
2375 1.6 christos plt1 = OR1K_LWZ(12,12) | lo;
2376 1.6 christos plt2 = OR1K_ORI0(11) | plt_reloc;
2377 1.6 christos }
2378 1.6 christos
2379 1.6 christos or1k_write_plt_entry (output_bfd, splt->contents + h->plt.offset,
2380 1.6 christos plt0, plt1, plt2, OR1K_JR(12));
2381 1.1 christos
2382 1.1 christos /* Fill in the entry in the global offset table. */
2383 1.6 christos bfd_put_32 (output_bfd, plt_addr, sgot->contents + got_offset);
2384 1.1 christos
2385 1.1 christos /* Fill in the entry in the .rela.plt section. */
2386 1.6 christos rela.r_offset = got_addr;
2387 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_JMP_SLOT);
2388 1.1 christos rela.r_addend = 0;
2389 1.1 christos loc = srela->contents;
2390 1.1 christos loc += plt_index * sizeof (Elf32_External_Rela);
2391 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2392 1.1 christos
2393 1.1 christos if (!h->def_regular)
2394 1.6 christos {
2395 1.6 christos /* Mark the symbol as undefined, rather than as defined in
2396 1.6 christos the .plt section. Leave the value alone. */
2397 1.6 christos sym->st_shndx = SHN_UNDEF;
2398 1.6 christos }
2399 1.1 christos }
2400 1.1 christos
2401 1.1 christos if (h->got.offset != (bfd_vma) -1
2402 1.1 christos && (h->got.offset & 2) == 0) /* Homemade TLS check. */
2403 1.1 christos {
2404 1.1 christos asection *sgot;
2405 1.1 christos asection *srela;
2406 1.1 christos Elf_Internal_Rela rela;
2407 1.1 christos
2408 1.1 christos /* This symbol has an entry in the global offset table. Set it
2409 1.6 christos up. */
2410 1.5 christos sgot = htab->root.sgot;
2411 1.5 christos srela = htab->root.srelgot;
2412 1.1 christos BFD_ASSERT (sgot != NULL && srela != NULL);
2413 1.1 christos
2414 1.1 christos rela.r_offset = (sgot->output_section->vma
2415 1.6 christos + sgot->output_offset
2416 1.6 christos + (h->got.offset &~ 1));
2417 1.1 christos
2418 1.1 christos /* If this is a -Bsymbolic link, and the symbol is defined
2419 1.6 christos locally, we just want to emit a RELATIVE reloc. Likewise if
2420 1.6 christos the symbol was forced to be local because of a version file.
2421 1.6 christos The entry in the global offset table will already have been
2422 1.6 christos initialized in the relocate_section function. */
2423 1.4 christos if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
2424 1.6 christos {
2425 1.6 christos rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
2426 1.6 christos rela.r_addend = (h->root.u.def.value
2427 1.6 christos + h->root.u.def.section->output_section->vma
2428 1.6 christos + h->root.u.def.section->output_offset);
2429 1.6 christos }
2430 1.1 christos else
2431 1.6 christos {
2432 1.6 christos BFD_ASSERT ((h->got.offset & 1) == 0);
2433 1.6 christos bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
2434 1.6 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_GLOB_DAT);
2435 1.6 christos rela.r_addend = 0;
2436 1.6 christos }
2437 1.1 christos
2438 1.1 christos loc = srela->contents;
2439 1.1 christos loc += srela->reloc_count * sizeof (Elf32_External_Rela);
2440 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2441 1.1 christos ++srela->reloc_count;
2442 1.1 christos }
2443 1.1 christos
2444 1.1 christos if (h->needs_copy)
2445 1.1 christos {
2446 1.1 christos asection *s;
2447 1.1 christos Elf_Internal_Rela rela;
2448 1.1 christos
2449 1.1 christos /* This symbols needs a copy reloc. Set it up. */
2450 1.1 christos BFD_ASSERT (h->dynindx != -1
2451 1.6 christos && (h->root.type == bfd_link_hash_defined
2452 1.6 christos || h->root.type == bfd_link_hash_defweak));
2453 1.1 christos
2454 1.1 christos rela.r_offset = (h->root.u.def.value
2455 1.6 christos + h->root.u.def.section->output_section->vma
2456 1.6 christos + h->root.u.def.section->output_offset);
2457 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
2458 1.1 christos rela.r_addend = 0;
2459 1.5 christos if (h->root.u.def.section == htab->root.sdynrelro)
2460 1.5 christos s = htab->root.sreldynrelro;
2461 1.5 christos else
2462 1.5 christos s = htab->root.srelbss;
2463 1.5 christos loc = s->contents + s->reloc_count * sizeof (Elf32_External_Rela);
2464 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2465 1.1 christos ++s->reloc_count;
2466 1.1 christos }
2467 1.1 christos
2468 1.1 christos /* Mark some specially defined symbols as absolute. */
2469 1.1 christos if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2470 1.1 christos || h == htab->root.hgot)
2471 1.1 christos sym->st_shndx = SHN_ABS;
2472 1.1 christos
2473 1.1 christos return TRUE;
2474 1.1 christos }
2475 1.1 christos
2476 1.1 christos static enum elf_reloc_type_class
2477 1.1 christos or1k_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
2478 1.6 christos const asection *rel_sec ATTRIBUTE_UNUSED,
2479 1.6 christos const Elf_Internal_Rela *rela)
2480 1.1 christos {
2481 1.1 christos switch ((int) ELF32_R_TYPE (rela->r_info))
2482 1.1 christos {
2483 1.1 christos case R_OR1K_RELATIVE: return reloc_class_relative;
2484 1.1 christos case R_OR1K_JMP_SLOT: return reloc_class_plt;
2485 1.6 christos case R_OR1K_COPY: return reloc_class_copy;
2486 1.6 christos default: return reloc_class_normal;
2487 1.6 christos }
2488 1.6 christos }
2489 1.6 christos
2490 1.6 christos /* Find dynamic relocs for H that apply to read-only sections. */
2491 1.6 christos
2492 1.6 christos static asection *
2493 1.6 christos readonly_dynrelocs (struct elf_link_hash_entry *h)
2494 1.6 christos {
2495 1.6 christos struct elf_dyn_relocs *p;
2496 1.6 christos struct elf_or1k_link_hash_entry *eh = (struct elf_or1k_link_hash_entry *) h;
2497 1.6 christos
2498 1.6 christos for (p = eh->dyn_relocs; p != NULL; p = p->next)
2499 1.6 christos {
2500 1.6 christos asection *s = p->sec->output_section;
2501 1.6 christos
2502 1.6 christos if (s != NULL && (s->flags & SEC_READONLY) != 0)
2503 1.6 christos return p->sec;
2504 1.1 christos }
2505 1.6 christos return NULL;
2506 1.1 christos }
2507 1.1 christos
2508 1.1 christos /* Adjust a symbol defined by a dynamic object and referenced by a
2509 1.1 christos regular object. The current definition is in some section of the
2510 1.1 christos dynamic object, but we're not including those sections. We have to
2511 1.1 christos change the definition to something the rest of the link can
2512 1.1 christos understand. */
2513 1.1 christos
2514 1.1 christos static bfd_boolean
2515 1.1 christos or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2516 1.6 christos struct elf_link_hash_entry *h)
2517 1.1 christos {
2518 1.1 christos struct elf_or1k_link_hash_table *htab;
2519 1.1 christos bfd *dynobj;
2520 1.5 christos asection *s, *srel;
2521 1.1 christos
2522 1.1 christos dynobj = elf_hash_table (info)->dynobj;
2523 1.1 christos
2524 1.1 christos /* Make sure we know what is going on here. */
2525 1.1 christos BFD_ASSERT (dynobj != NULL
2526 1.6 christos && (h->needs_plt
2527 1.6 christos || h->is_weakalias
2528 1.6 christos || (h->def_dynamic
2529 1.6 christos && h->ref_regular
2530 1.6 christos && !h->def_regular)));
2531 1.1 christos
2532 1.1 christos /* If this is a function, put it in the procedure linkage table. We
2533 1.1 christos will fill in the contents of the procedure linkage table later,
2534 1.1 christos when we know the address of the .got section. */
2535 1.1 christos if (h->type == STT_FUNC
2536 1.1 christos || h->needs_plt)
2537 1.1 christos {
2538 1.4 christos if (! bfd_link_pic (info)
2539 1.6 christos && !h->def_dynamic
2540 1.6 christos && !h->ref_dynamic
2541 1.6 christos && h->root.type != bfd_link_hash_undefweak
2542 1.6 christos && h->root.type != bfd_link_hash_undefined)
2543 1.6 christos {
2544 1.6 christos /* This case can occur if we saw a PLT reloc in an input
2545 1.6 christos file, but the symbol was never referred to by a dynamic
2546 1.6 christos object. In such a case, we don't actually need to build
2547 1.6 christos a procedure linkage table, and we can just do a PCREL
2548 1.6 christos reloc instead. */
2549 1.6 christos h->plt.offset = (bfd_vma) -1;
2550 1.6 christos h->needs_plt = 0;
2551 1.6 christos }
2552 1.1 christos
2553 1.1 christos return TRUE;
2554 1.1 christos }
2555 1.1 christos else
2556 1.1 christos h->plt.offset = (bfd_vma) -1;
2557 1.1 christos
2558 1.1 christos /* If this is a weak symbol, and there is a real definition, the
2559 1.1 christos processor independent code will have arranged for us to see the
2560 1.1 christos real definition first, and we can just use the same value. */
2561 1.6 christos if (h->is_weakalias)
2562 1.1 christos {
2563 1.6 christos struct elf_link_hash_entry *def = weakdef (h);
2564 1.6 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2565 1.6 christos h->root.u.def.section = def->root.u.def.section;
2566 1.6 christos h->root.u.def.value = def->root.u.def.value;
2567 1.1 christos return TRUE;
2568 1.1 christos }
2569 1.1 christos
2570 1.1 christos /* This is a reference to a symbol defined by a dynamic object which
2571 1.1 christos is not a function. */
2572 1.1 christos
2573 1.1 christos /* If we are creating a shared library, we must presume that the
2574 1.1 christos only references to the symbol are via the global offset table.
2575 1.1 christos For such cases we need not do anything here; the relocations will
2576 1.1 christos be handled correctly by relocate_section. */
2577 1.4 christos if (bfd_link_pic (info))
2578 1.1 christos return TRUE;
2579 1.1 christos
2580 1.1 christos /* If there are no references to this symbol that do not use the
2581 1.1 christos GOT, we don't need to generate a copy reloc. */
2582 1.1 christos if (!h->non_got_ref)
2583 1.1 christos return TRUE;
2584 1.1 christos
2585 1.1 christos /* If -z nocopyreloc was given, we won't generate them either. */
2586 1.1 christos if (info->nocopyreloc)
2587 1.1 christos {
2588 1.1 christos h->non_got_ref = 0;
2589 1.1 christos return TRUE;
2590 1.1 christos }
2591 1.1 christos
2592 1.6 christos /* If we don't find any dynamic relocs in read-only sections, then
2593 1.6 christos we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2594 1.6 christos if (!readonly_dynrelocs (h))
2595 1.1 christos {
2596 1.1 christos h->non_got_ref = 0;
2597 1.1 christos return TRUE;
2598 1.1 christos }
2599 1.1 christos
2600 1.1 christos /* We must allocate the symbol in our .dynbss section, which will
2601 1.1 christos become part of the .bss section of the executable. There will be
2602 1.1 christos an entry for this symbol in the .dynsym section. The dynamic
2603 1.1 christos object will contain position independent code, so all references
2604 1.1 christos from the dynamic object to this symbol will go through the global
2605 1.1 christos offset table. The dynamic linker will use the .dynsym entry to
2606 1.1 christos determine the address it must put in the global offset table, so
2607 1.1 christos both the dynamic object and the regular object will refer to the
2608 1.1 christos same memory location for the variable. */
2609 1.1 christos
2610 1.1 christos htab = or1k_elf_hash_table (info);
2611 1.1 christos if (htab == NULL)
2612 1.1 christos return FALSE;
2613 1.1 christos
2614 1.1 christos /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
2615 1.1 christos to copy the initial value out of the dynamic object and into the
2616 1.1 christos runtime process image. We need to remember the offset into the
2617 1.1 christos .rela.bss section we are going to use. */
2618 1.5 christos if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2619 1.5 christos {
2620 1.5 christos s = htab->root.sdynrelro;
2621 1.5 christos srel = htab->root.sreldynrelro;
2622 1.5 christos }
2623 1.5 christos else
2624 1.5 christos {
2625 1.5 christos s = htab->root.sdynbss;
2626 1.5 christos srel = htab->root.srelbss;
2627 1.5 christos }
2628 1.1 christos if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2629 1.1 christos {
2630 1.1 christos srel->size += sizeof (Elf32_External_Rela);
2631 1.1 christos h->needs_copy = 1;
2632 1.1 christos }
2633 1.1 christos
2634 1.1 christos return _bfd_elf_adjust_dynamic_copy (info, h, s);
2635 1.1 christos }
2636 1.1 christos
2637 1.1 christos /* Allocate space in .plt, .got and associated reloc sections for
2638 1.1 christos dynamic relocs. */
2639 1.1 christos
2640 1.1 christos static bfd_boolean
2641 1.1 christos allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2642 1.1 christos {
2643 1.1 christos struct bfd_link_info *info;
2644 1.1 christos struct elf_or1k_link_hash_table *htab;
2645 1.1 christos struct elf_or1k_link_hash_entry *eh;
2646 1.6 christos struct elf_dyn_relocs *p;
2647 1.1 christos
2648 1.1 christos if (h->root.type == bfd_link_hash_indirect)
2649 1.1 christos return TRUE;
2650 1.1 christos
2651 1.1 christos info = (struct bfd_link_info *) inf;
2652 1.1 christos htab = or1k_elf_hash_table (info);
2653 1.1 christos if (htab == NULL)
2654 1.1 christos return FALSE;
2655 1.1 christos
2656 1.1 christos eh = (struct elf_or1k_link_hash_entry *) h;
2657 1.1 christos
2658 1.1 christos if (htab->root.dynamic_sections_created
2659 1.1 christos && h->plt.refcount > 0)
2660 1.1 christos {
2661 1.1 christos /* Make sure this symbol is output as a dynamic symbol.
2662 1.6 christos Undefined weak syms won't yet be marked as dynamic. */
2663 1.1 christos if (h->dynindx == -1
2664 1.6 christos && !h->forced_local)
2665 1.6 christos {
2666 1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
2667 1.6 christos return FALSE;
2668 1.6 christos }
2669 1.1 christos
2670 1.4 christos if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
2671 1.6 christos {
2672 1.6 christos asection *s = htab->root.splt;
2673 1.1 christos
2674 1.6 christos /* If this is the first .plt entry, make room for the special
2675 1.6 christos first entry. */
2676 1.6 christos if (s->size == 0)
2677 1.6 christos s->size = PLT_ENTRY_SIZE;
2678 1.6 christos
2679 1.6 christos h->plt.offset = s->size;
2680 1.6 christos
2681 1.6 christos /* If this symbol is not defined in a regular file, and we are
2682 1.6 christos not generating a shared library, then set the symbol to this
2683 1.6 christos location in the .plt. This is required to make function
2684 1.6 christos pointers compare as equal between the normal executable and
2685 1.6 christos the shared library. */
2686 1.6 christos if (! bfd_link_pic (info)
2687 1.6 christos && !h->def_regular)
2688 1.6 christos {
2689 1.6 christos h->root.u.def.section = s;
2690 1.6 christos h->root.u.def.value = h->plt.offset;
2691 1.6 christos }
2692 1.6 christos
2693 1.6 christos /* Make room for this entry. */
2694 1.6 christos s->size += PLT_ENTRY_SIZE;
2695 1.6 christos
2696 1.6 christos /* We also need to make an entry in the .got.plt section, which
2697 1.6 christos will be placed in the .got section by the linker script. */
2698 1.6 christos htab->root.sgotplt->size += 4;
2699 1.6 christos
2700 1.6 christos /* We also need to make an entry in the .rel.plt section. */
2701 1.6 christos htab->root.srelplt->size += sizeof (Elf32_External_Rela);
2702 1.6 christos }
2703 1.1 christos else
2704 1.6 christos {
2705 1.6 christos h->plt.offset = (bfd_vma) -1;
2706 1.6 christos h->needs_plt = 0;
2707 1.6 christos }
2708 1.1 christos }
2709 1.1 christos else
2710 1.1 christos {
2711 1.1 christos h->plt.offset = (bfd_vma) -1;
2712 1.1 christos h->needs_plt = 0;
2713 1.1 christos }
2714 1.1 christos
2715 1.1 christos if (h->got.refcount > 0)
2716 1.1 christos {
2717 1.1 christos asection *s;
2718 1.1 christos bfd_boolean dyn;
2719 1.1 christos unsigned char tls_type;
2720 1.1 christos
2721 1.1 christos /* Make sure this symbol is output as a dynamic symbol.
2722 1.6 christos Undefined weak syms won't yet be marked as dynamic. */
2723 1.1 christos if (h->dynindx == -1
2724 1.6 christos && !h->forced_local)
2725 1.6 christos {
2726 1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
2727 1.6 christos return FALSE;
2728 1.6 christos }
2729 1.1 christos
2730 1.5 christos s = htab->root.sgot;
2731 1.1 christos
2732 1.1 christos h->got.offset = s->size;
2733 1.1 christos
2734 1.1 christos tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
2735 1.1 christos
2736 1.1 christos /* TLS GD requires two GOT and two relocs. */
2737 1.1 christos if (tls_type == TLS_GD)
2738 1.6 christos s->size += 8;
2739 1.1 christos else
2740 1.6 christos s->size += 4;
2741 1.1 christos dyn = htab->root.dynamic_sections_created;
2742 1.4 christos if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
2743 1.6 christos {
2744 1.6 christos if (tls_type == TLS_GD)
2745 1.6 christos htab->root.srelgot->size += 2 * sizeof (Elf32_External_Rela);
2746 1.6 christos else
2747 1.6 christos htab->root.srelgot->size += sizeof (Elf32_External_Rela);
2748 1.6 christos }
2749 1.1 christos }
2750 1.1 christos else
2751 1.1 christos h->got.offset = (bfd_vma) -1;
2752 1.1 christos
2753 1.1 christos if (eh->dyn_relocs == NULL)
2754 1.1 christos return TRUE;
2755 1.1 christos
2756 1.1 christos /* In the shared -Bsymbolic case, discard space allocated for
2757 1.1 christos dynamic pc-relative relocs against symbols which turn out to be
2758 1.1 christos defined in regular objects. For the normal shared case, discard
2759 1.1 christos space for pc-relative relocs that have become local due to symbol
2760 1.1 christos visibility changes. */
2761 1.1 christos
2762 1.4 christos if (bfd_link_pic (info))
2763 1.1 christos {
2764 1.1 christos if (SYMBOL_CALLS_LOCAL (info, h))
2765 1.6 christos {
2766 1.6 christos struct elf_dyn_relocs **pp;
2767 1.1 christos
2768 1.6 christos for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
2769 1.6 christos {
2770 1.6 christos p->count -= p->pc_count;
2771 1.6 christos p->pc_count = 0;
2772 1.6 christos if (p->count == 0)
2773 1.6 christos *pp = p->next;
2774 1.6 christos else
2775 1.6 christos pp = &p->next;
2776 1.6 christos }
2777 1.6 christos }
2778 1.1 christos
2779 1.1 christos /* Also discard relocs on undefined weak syms with non-default
2780 1.6 christos visibility. */
2781 1.1 christos if (eh->dyn_relocs != NULL
2782 1.6 christos && h->root.type == bfd_link_hash_undefweak)
2783 1.6 christos {
2784 1.6 christos if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2785 1.6 christos eh->dyn_relocs = NULL;
2786 1.6 christos
2787 1.6 christos /* Make sure undefined weak symbols are output as a dynamic
2788 1.6 christos symbol in PIEs. */
2789 1.6 christos else if (h->dynindx == -1
2790 1.6 christos && !h->forced_local)
2791 1.6 christos {
2792 1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
2793 1.6 christos return FALSE;
2794 1.6 christos }
2795 1.6 christos }
2796 1.1 christos }
2797 1.1 christos else
2798 1.1 christos {
2799 1.1 christos /* For the non-shared case, discard space for relocs against
2800 1.6 christos symbols which turn out to need copy relocs or are not
2801 1.6 christos dynamic. */
2802 1.1 christos
2803 1.1 christos if (!h->non_got_ref
2804 1.6 christos && ((h->def_dynamic
2805 1.6 christos && !h->def_regular)
2806 1.6 christos || (htab->root.dynamic_sections_created
2807 1.6 christos && (h->root.type == bfd_link_hash_undefweak
2808 1.6 christos || h->root.type == bfd_link_hash_undefined))))
2809 1.6 christos {
2810 1.6 christos /* Make sure this symbol is output as a dynamic symbol.
2811 1.6 christos Undefined weak syms won't yet be marked as dynamic. */
2812 1.6 christos if (h->dynindx == -1
2813 1.6 christos && !h->forced_local)
2814 1.6 christos {
2815 1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
2816 1.6 christos return FALSE;
2817 1.6 christos }
2818 1.6 christos
2819 1.6 christos /* If that succeeded, we know we'll be keeping all the
2820 1.6 christos relocs. */
2821 1.6 christos if (h->dynindx != -1)
2822 1.6 christos goto keep;
2823 1.6 christos }
2824 1.1 christos
2825 1.1 christos eh->dyn_relocs = NULL;
2826 1.1 christos
2827 1.1 christos keep: ;
2828 1.1 christos }
2829 1.1 christos
2830 1.1 christos /* Finally, allocate space. */
2831 1.1 christos for (p = eh->dyn_relocs; p != NULL; p = p->next)
2832 1.1 christos {
2833 1.1 christos asection *sreloc = elf_section_data (p->sec)->sreloc;
2834 1.1 christos sreloc->size += p->count * sizeof (Elf32_External_Rela);
2835 1.1 christos }
2836 1.1 christos
2837 1.1 christos return TRUE;
2838 1.1 christos }
2839 1.1 christos
2840 1.6 christos /* Set DF_TEXTREL if we find any dynamic relocs that apply to
2841 1.6 christos read-only sections. */
2842 1.1 christos
2843 1.1 christos static bfd_boolean
2844 1.6 christos maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
2845 1.1 christos {
2846 1.6 christos asection *sec;
2847 1.6 christos
2848 1.6 christos if (h->root.type == bfd_link_hash_indirect)
2849 1.6 christos return TRUE;
2850 1.1 christos
2851 1.6 christos sec = readonly_dynrelocs (h);
2852 1.6 christos if (sec != NULL)
2853 1.1 christos {
2854 1.6 christos struct bfd_link_info *info = (struct bfd_link_info *) info_p;
2855 1.1 christos
2856 1.6 christos info->flags |= DF_TEXTREL;
2857 1.6 christos info->callbacks->minfo
2858 1.6 christos (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
2859 1.6 christos sec->owner, h->root.root.string, sec);
2860 1.1 christos
2861 1.6 christos /* Not an error, just cut short the traversal. */
2862 1.6 christos return FALSE;
2863 1.1 christos }
2864 1.1 christos return TRUE;
2865 1.1 christos }
2866 1.1 christos
2867 1.1 christos /* Set the sizes of the dynamic sections. */
2868 1.1 christos
2869 1.1 christos static bfd_boolean
2870 1.1 christos or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2871 1.6 christos struct bfd_link_info *info)
2872 1.1 christos {
2873 1.1 christos struct elf_or1k_link_hash_table *htab;
2874 1.1 christos bfd *dynobj;
2875 1.1 christos asection *s;
2876 1.1 christos bfd_boolean relocs;
2877 1.1 christos bfd *ibfd;
2878 1.1 christos
2879 1.1 christos htab = or1k_elf_hash_table (info);
2880 1.1 christos if (htab == NULL)
2881 1.1 christos return FALSE;
2882 1.1 christos
2883 1.1 christos dynobj = htab->root.dynobj;
2884 1.1 christos BFD_ASSERT (dynobj != NULL);
2885 1.1 christos
2886 1.1 christos if (htab->root.dynamic_sections_created)
2887 1.1 christos {
2888 1.1 christos /* Set the contents of the .interp section to the interpreter. */
2889 1.4 christos if (bfd_link_executable (info) && !info->nointerp)
2890 1.6 christos {
2891 1.6 christos s = bfd_get_section_by_name (dynobj, ".interp");
2892 1.6 christos BFD_ASSERT (s != NULL);
2893 1.6 christos s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2894 1.6 christos s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2895 1.6 christos }
2896 1.1 christos }
2897 1.1 christos
2898 1.1 christos /* Set up .got offsets for local syms, and space for local dynamic
2899 1.1 christos relocs. */
2900 1.1 christos for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2901 1.1 christos {
2902 1.1 christos bfd_signed_vma *local_got;
2903 1.1 christos bfd_signed_vma *end_local_got;
2904 1.1 christos bfd_size_type locsymcount;
2905 1.1 christos Elf_Internal_Shdr *symtab_hdr;
2906 1.1 christos unsigned char *local_tls_type;
2907 1.1 christos asection *srel;
2908 1.1 christos
2909 1.1 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2910 1.6 christos continue;
2911 1.1 christos
2912 1.1 christos for (s = ibfd->sections; s != NULL; s = s->next)
2913 1.6 christos {
2914 1.6 christos struct elf_dyn_relocs *p;
2915 1.1 christos
2916 1.6 christos for (p = ((struct elf_dyn_relocs *)
2917 1.6 christos elf_section_data (s)->local_dynrel);
2918 1.6 christos p != NULL;
2919 1.6 christos p = p->next)
2920 1.6 christos {
2921 1.6 christos if (! bfd_is_abs_section (p->sec)
2922 1.6 christos && bfd_is_abs_section (p->sec->output_section))
2923 1.6 christos {
2924 1.6 christos /* Input section has been discarded, either because
2925 1.6 christos it is a copy of a linkonce section or due to
2926 1.6 christos linker script /DISCARD/, so we'll be discarding
2927 1.6 christos the relocs too. */
2928 1.6 christos }
2929 1.6 christos else if (p->count != 0)
2930 1.6 christos {
2931 1.6 christos srel = elf_section_data (p->sec)->sreloc;
2932 1.6 christos srel->size += p->count * sizeof (Elf32_External_Rela);
2933 1.6 christos if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2934 1.6 christos info->flags |= DF_TEXTREL;
2935 1.6 christos }
2936 1.6 christos }
2937 1.6 christos }
2938 1.1 christos
2939 1.1 christos local_got = elf_local_got_refcounts (ibfd);
2940 1.1 christos if (!local_got)
2941 1.6 christos continue;
2942 1.1 christos
2943 1.1 christos symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2944 1.1 christos locsymcount = symtab_hdr->sh_info;
2945 1.1 christos end_local_got = local_got + locsymcount;
2946 1.5 christos s = htab->root.sgot;
2947 1.5 christos srel = htab->root.srelgot;
2948 1.1 christos local_tls_type = (unsigned char *) elf_or1k_local_tls_type (ibfd);
2949 1.1 christos for (; local_got < end_local_got; ++local_got)
2950 1.6 christos {
2951 1.6 christos if (*local_got > 0)
2952 1.6 christos {
2953 1.6 christos *local_got = s->size;
2954 1.6 christos
2955 1.6 christos /* TLS GD requires two GOT and two relocs. */
2956 1.6 christos if (local_tls_type != NULL && *local_tls_type == TLS_GD)
2957 1.6 christos s->size += 8;
2958 1.6 christos else
2959 1.6 christos s->size += 4;
2960 1.6 christos if (bfd_link_pic (info))
2961 1.6 christos {
2962 1.6 christos if (local_tls_type != NULL && *local_tls_type == TLS_GD)
2963 1.6 christos srel->size += 2 * sizeof (Elf32_External_Rela);
2964 1.6 christos else
2965 1.6 christos srel->size += sizeof (Elf32_External_Rela);
2966 1.6 christos }
2967 1.6 christos }
2968 1.6 christos else
2969 1.6 christos
2970 1.6 christos *local_got = (bfd_vma) -1;
2971 1.6 christos
2972 1.6 christos if (local_tls_type)
2973 1.6 christos ++local_tls_type;
2974 1.6 christos }
2975 1.1 christos }
2976 1.1 christos
2977 1.1 christos /* Allocate global sym .plt and .got entries, and space for global
2978 1.1 christos sym dynamic relocs. */
2979 1.1 christos elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
2980 1.1 christos
2981 1.1 christos /* We now have determined the sizes of the various dynamic sections.
2982 1.1 christos Allocate memory for them. */
2983 1.1 christos relocs = FALSE;
2984 1.1 christos for (s = dynobj->sections; s != NULL; s = s->next)
2985 1.1 christos {
2986 1.1 christos if ((s->flags & SEC_LINKER_CREATED) == 0)
2987 1.6 christos continue;
2988 1.1 christos
2989 1.5 christos if (s == htab->root.splt
2990 1.6 christos || s == htab->root.sgot
2991 1.6 christos || s == htab->root.sgotplt
2992 1.5 christos || s == htab->root.sdynbss
2993 1.5 christos || s == htab->root.sdynrelro)
2994 1.6 christos {
2995 1.6 christos /* Strip this section if we don't need it; see the
2996 1.6 christos comment below. */
2997 1.6 christos }
2998 1.1 christos else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2999 1.6 christos {
3000 1.6 christos if (s->size != 0 && s != htab->root.srelplt)
3001 1.6 christos relocs = TRUE;
3002 1.6 christos
3003 1.6 christos /* We use the reloc_count field as a counter if we need
3004 1.6 christos to copy relocs into the output file. */
3005 1.6 christos s->reloc_count = 0;
3006 1.6 christos }
3007 1.1 christos else
3008 1.6 christos /* It's not one of our sections, so don't allocate space. */
3009 1.6 christos continue;
3010 1.1 christos
3011 1.1 christos if (s->size == 0)
3012 1.6 christos {
3013 1.6 christos /* If we don't need this section, strip it from the
3014 1.6 christos output file. This is mostly to handle .rela.bss and
3015 1.6 christos .rela.plt. We must create both sections in
3016 1.6 christos create_dynamic_sections, because they must be created
3017 1.6 christos before the linker maps input sections to output
3018 1.6 christos sections. The linker does that before
3019 1.6 christos adjust_dynamic_symbol is called, and it is that
3020 1.6 christos function which decides whether anything needs to go
3021 1.6 christos into these sections. */
3022 1.6 christos s->flags |= SEC_EXCLUDE;
3023 1.6 christos continue;
3024 1.6 christos }
3025 1.1 christos
3026 1.1 christos if ((s->flags & SEC_HAS_CONTENTS) == 0)
3027 1.6 christos continue;
3028 1.1 christos
3029 1.1 christos /* Allocate memory for the section contents. We use bfd_zalloc
3030 1.6 christos here in case unused entries are not reclaimed before the
3031 1.6 christos section's contents are written out. This should not happen,
3032 1.6 christos but this way if it does, we get a R_OR1K_NONE reloc instead
3033 1.6 christos of garbage. */
3034 1.1 christos s->contents = bfd_zalloc (dynobj, s->size);
3035 1.1 christos
3036 1.1 christos if (s->contents == NULL)
3037 1.6 christos return FALSE;
3038 1.1 christos }
3039 1.1 christos
3040 1.1 christos if (htab->root.dynamic_sections_created)
3041 1.1 christos {
3042 1.1 christos /* Add some entries to the .dynamic section. We fill in the
3043 1.6 christos values later, in or1k_elf_finish_dynamic_sections, but we
3044 1.6 christos must add the entries now so that we get the correct size for
3045 1.6 christos the .dynamic section. The DT_DEBUG entry is filled in by the
3046 1.6 christos dynamic linker and used by the debugger. */
3047 1.1 christos #define add_dynamic_entry(TAG, VAL) \
3048 1.1 christos _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3049 1.1 christos
3050 1.4 christos if (bfd_link_executable (info))
3051 1.1 christos {
3052 1.6 christos if (! add_dynamic_entry (DT_DEBUG, 0))
3053 1.6 christos return FALSE;
3054 1.1 christos }
3055 1.1 christos
3056 1.5 christos if (htab->root.splt->size != 0)
3057 1.1 christos {
3058 1.6 christos if (! add_dynamic_entry (DT_PLTGOT, 0)
3059 1.6 christos || ! add_dynamic_entry (DT_PLTRELSZ, 0)
3060 1.6 christos || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
3061 1.6 christos || ! add_dynamic_entry (DT_JMPREL, 0))
3062 1.6 christos return FALSE;
3063 1.6 christos }
3064 1.1 christos
3065 1.1 christos if (relocs)
3066 1.1 christos {
3067 1.6 christos if (! add_dynamic_entry (DT_RELA, 0)
3068 1.6 christos || ! add_dynamic_entry (DT_RELASZ, 0)
3069 1.6 christos || ! add_dynamic_entry (DT_RELAENT,
3070 1.6 christos sizeof (Elf32_External_Rela)))
3071 1.6 christos return FALSE;
3072 1.6 christos
3073 1.6 christos /* If any dynamic relocs apply to a read-only section,
3074 1.6 christos then we need a DT_TEXTREL entry. */
3075 1.6 christos if ((info->flags & DF_TEXTREL) == 0)
3076 1.6 christos elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
3077 1.6 christos
3078 1.6 christos if ((info->flags & DF_TEXTREL) != 0)
3079 1.6 christos {
3080 1.6 christos if (! add_dynamic_entry (DT_TEXTREL, 0))
3081 1.6 christos return FALSE;
3082 1.6 christos }
3083 1.1 christos }
3084 1.1 christos }
3085 1.1 christos
3086 1.1 christos #undef add_dynamic_entry
3087 1.1 christos return TRUE;
3088 1.1 christos }
3089 1.1 christos
3090 1.1 christos /* Copy the extra info we tack onto an elf_link_hash_entry. */
3091 1.1 christos
3092 1.1 christos static void
3093 1.1 christos or1k_elf_copy_indirect_symbol (struct bfd_link_info *info,
3094 1.6 christos struct elf_link_hash_entry *dir,
3095 1.6 christos struct elf_link_hash_entry *ind)
3096 1.1 christos {
3097 1.1 christos struct elf_or1k_link_hash_entry * edir;
3098 1.1 christos struct elf_or1k_link_hash_entry * eind;
3099 1.1 christos
3100 1.1 christos edir = (struct elf_or1k_link_hash_entry *) dir;
3101 1.1 christos eind = (struct elf_or1k_link_hash_entry *) ind;
3102 1.1 christos
3103 1.1 christos if (eind->dyn_relocs != NULL)
3104 1.1 christos {
3105 1.1 christos if (edir->dyn_relocs != NULL)
3106 1.6 christos {
3107 1.6 christos struct elf_dyn_relocs **pp;
3108 1.6 christos struct elf_dyn_relocs *p;
3109 1.6 christos
3110 1.6 christos /* Add reloc counts against the indirect sym to the direct sym
3111 1.6 christos list. Merge any entries against the same section. */
3112 1.6 christos for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
3113 1.6 christos {
3114 1.6 christos struct elf_dyn_relocs *q;
3115 1.6 christos
3116 1.6 christos for (q = edir->dyn_relocs; q != NULL; q = q->next)
3117 1.6 christos if (q->sec == p->sec)
3118 1.6 christos {
3119 1.6 christos q->pc_count += p->pc_count;
3120 1.6 christos q->count += p->count;
3121 1.6 christos *pp = p->next;
3122 1.6 christos break;
3123 1.6 christos }
3124 1.6 christos if (q == NULL)
3125 1.6 christos pp = &p->next;
3126 1.6 christos }
3127 1.6 christos *pp = edir->dyn_relocs;
3128 1.6 christos }
3129 1.1 christos
3130 1.1 christos edir->dyn_relocs = eind->dyn_relocs;
3131 1.1 christos eind->dyn_relocs = NULL;
3132 1.1 christos }
3133 1.1 christos
3134 1.1 christos if (ind->root.type == bfd_link_hash_indirect)
3135 1.1 christos {
3136 1.1 christos if (dir->got.refcount <= 0)
3137 1.6 christos {
3138 1.6 christos edir->tls_type = eind->tls_type;
3139 1.6 christos eind->tls_type = TLS_UNKNOWN;
3140 1.6 christos }
3141 1.1 christos }
3142 1.1 christos
3143 1.1 christos _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3144 1.1 christos }
3145 1.1 christos
3146 1.1 christos /* Set the right machine number. */
3147 1.1 christos
3148 1.1 christos static bfd_boolean
3149 1.1 christos or1k_elf_object_p (bfd *abfd)
3150 1.1 christos {
3151 1.1 christos unsigned long mach = bfd_mach_or1k;
3152 1.1 christos
3153 1.1 christos if (elf_elfheader (abfd)->e_flags & EF_OR1K_NODELAY)
3154 1.1 christos mach = bfd_mach_or1knd;
3155 1.1 christos
3156 1.1 christos return bfd_default_set_arch_mach (abfd, bfd_arch_or1k, mach);
3157 1.1 christos }
3158 1.1 christos
3159 1.1 christos /* Store the machine number in the flags field. */
3160 1.1 christos
3161 1.1 christos static void
3162 1.1 christos or1k_elf_final_write_processing (bfd *abfd,
3163 1.1 christos bfd_boolean linker ATTRIBUTE_UNUSED)
3164 1.1 christos {
3165 1.1 christos switch (bfd_get_mach (abfd))
3166 1.1 christos {
3167 1.1 christos default:
3168 1.1 christos case bfd_mach_or1k:
3169 1.1 christos break;
3170 1.1 christos case bfd_mach_or1knd:
3171 1.1 christos elf_elfheader (abfd)->e_flags |= EF_OR1K_NODELAY;
3172 1.1 christos break;
3173 1.1 christos }
3174 1.1 christos }
3175 1.1 christos
3176 1.1 christos static bfd_boolean
3177 1.1 christos or1k_elf_set_private_flags (bfd *abfd, flagword flags)
3178 1.1 christos {
3179 1.1 christos BFD_ASSERT (!elf_flags_init (abfd)
3180 1.6 christos || elf_elfheader (abfd)->e_flags == flags);
3181 1.1 christos
3182 1.1 christos elf_elfheader (abfd)->e_flags = flags;
3183 1.1 christos elf_flags_init (abfd) = TRUE;
3184 1.1 christos return TRUE;
3185 1.1 christos }
3186 1.1 christos
3187 1.1 christos /* Make sure all input files are consistent with respect to
3188 1.1 christos EF_OR1K_NODELAY flag setting. */
3189 1.1 christos
3190 1.1 christos static bfd_boolean
3191 1.5 christos elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
3192 1.1 christos {
3193 1.5 christos bfd *obfd = info->output_bfd;
3194 1.1 christos flagword out_flags;
3195 1.1 christos flagword in_flags;
3196 1.1 christos
3197 1.1 christos in_flags = elf_elfheader (ibfd)->e_flags;
3198 1.1 christos out_flags = elf_elfheader (obfd)->e_flags;
3199 1.1 christos
3200 1.1 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3201 1.1 christos || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3202 1.1 christos return TRUE;
3203 1.1 christos
3204 1.1 christos if (!elf_flags_init (obfd))
3205 1.1 christos {
3206 1.1 christos elf_flags_init (obfd) = TRUE;
3207 1.1 christos elf_elfheader (obfd)->e_flags = in_flags;
3208 1.1 christos
3209 1.1 christos return TRUE;
3210 1.1 christos }
3211 1.1 christos
3212 1.1 christos if (in_flags == out_flags)
3213 1.1 christos return TRUE;
3214 1.1 christos
3215 1.1 christos if ((in_flags & EF_OR1K_NODELAY) != (out_flags & EF_OR1K_NODELAY))
3216 1.1 christos {
3217 1.5 christos _bfd_error_handler
3218 1.6 christos (_("%pB: %s flag mismatch with previous modules"),
3219 1.6 christos ibfd, "EF_OR1K_NODELAY");
3220 1.1 christos
3221 1.1 christos bfd_set_error (bfd_error_bad_value);
3222 1.1 christos return FALSE;
3223 1.1 christos }
3224 1.1 christos
3225 1.1 christos return TRUE;
3226 1.1 christos
3227 1.1 christos }
3228 1.1 christos
3229 1.6 christos /* Implement elf_backend_grok_prstatus:
3230 1.6 christos Support for core dump NOTE sections. */
3231 1.6 christos static bfd_boolean
3232 1.6 christos or1k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3233 1.6 christos {
3234 1.6 christos int offset;
3235 1.6 christos size_t size;
3236 1.6 christos
3237 1.6 christos switch (note->descsz)
3238 1.6 christos {
3239 1.6 christos default:
3240 1.6 christos return FALSE;
3241 1.6 christos
3242 1.6 christos case 212: /* Linux/OpenRISC */
3243 1.6 christos /* pr_cursig */
3244 1.6 christos elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
3245 1.6 christos
3246 1.6 christos /* pr_pid */
3247 1.6 christos elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
3248 1.6 christos
3249 1.6 christos /* pr_reg */
3250 1.6 christos offset = 72;
3251 1.6 christos size = 132;
3252 1.6 christos
3253 1.6 christos break;
3254 1.6 christos }
3255 1.6 christos
3256 1.6 christos /* Make a ".reg/999" section. */
3257 1.6 christos return _bfd_elfcore_make_pseudosection (abfd, ".reg",
3258 1.6 christos size, note->descpos + offset);
3259 1.6 christos }
3260 1.6 christos
3261 1.6 christos /* Implement elf_backend_grok_psinfo. */
3262 1.6 christos static bfd_boolean
3263 1.6 christos or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3264 1.6 christos {
3265 1.6 christos switch (note->descsz)
3266 1.6 christos {
3267 1.6 christos default:
3268 1.6 christos return FALSE;
3269 1.6 christos
3270 1.6 christos case 128: /* Linux/OpenRISC elf_prpsinfo */
3271 1.6 christos elf_tdata (abfd)->core->program
3272 1.6 christos = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
3273 1.6 christos elf_tdata (abfd)->core->command
3274 1.6 christos = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
3275 1.6 christos }
3276 1.6 christos
3277 1.6 christos return TRUE;
3278 1.6 christos }
3279 1.6 christos
3280 1.1 christos
3281 1.6 christos #define ELF_ARCH bfd_arch_or1k
3282 1.6 christos #define ELF_MACHINE_CODE EM_OR1K
3283 1.6 christos #define ELF_TARGET_ID OR1K_ELF_DATA
3284 1.6 christos #define ELF_MAXPAGESIZE 0x2000
3285 1.6 christos
3286 1.6 christos #define TARGET_BIG_SYM or1k_elf32_vec
3287 1.6 christos #define TARGET_BIG_NAME "elf32-or1k"
3288 1.6 christos
3289 1.6 christos #define elf_info_to_howto_rel NULL
3290 1.6 christos #define elf_info_to_howto or1k_info_to_howto_rela
3291 1.6 christos #define elf_backend_relocate_section or1k_elf_relocate_section
3292 1.6 christos #define elf_backend_gc_mark_hook or1k_elf_gc_mark_hook
3293 1.6 christos #define elf_backend_check_relocs or1k_elf_check_relocs
3294 1.6 christos #define elf_backend_reloc_type_class or1k_elf_reloc_type_class
3295 1.6 christos #define elf_backend_can_gc_sections 1
3296 1.6 christos #define elf_backend_rela_normal 1
3297 1.6 christos
3298 1.6 christos #define bfd_elf32_mkobject elf_or1k_mkobject
3299 1.1 christos
3300 1.1 christos #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
3301 1.1 christos #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
3302 1.1 christos #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
3303 1.1 christos #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
3304 1.1 christos
3305 1.6 christos #define elf_backend_object_p or1k_elf_object_p
3306 1.1 christos #define elf_backend_final_write_processing or1k_elf_final_write_processing
3307 1.6 christos #define elf_backend_can_refcount 1
3308 1.1 christos
3309 1.6 christos #define elf_backend_plt_readonly 1
3310 1.6 christos #define elf_backend_want_got_plt 1
3311 1.6 christos #define elf_backend_want_plt_sym 0
3312 1.6 christos #define elf_backend_got_header_size 12
3313 1.5 christos #define elf_backend_dtrel_excludes_plt 1
3314 1.5 christos #define elf_backend_want_dynrelro 1
3315 1.5 christos
3316 1.6 christos #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create
3317 1.6 christos #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol
3318 1.6 christos #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3319 1.6 christos #define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
3320 1.6 christos #define elf_backend_size_dynamic_sections or1k_elf_size_dynamic_sections
3321 1.6 christos #define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
3322 1.6 christos #define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
3323 1.6 christos
3324 1.6 christos #define elf_backend_grok_prstatus or1k_grok_prstatus
3325 1.6 christos #define elf_backend_grok_psinfo or1k_grok_psinfo
3326 1.1 christos
3327 1.1 christos #include "elf32-target.h"
3328