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