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