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