1 1.1 christos /* TILEPro-specific support for 32-bit ELF. 2 1.11 christos Copyright (C) 2011-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of BFD, the Binary File Descriptor library. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program; if not, write to the Free Software 18 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 1.1 christos MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #include "sysdep.h" 22 1.1 christos #include "bfd.h" 23 1.1 christos #include "libbfd.h" 24 1.1 christos #include "elf-bfd.h" 25 1.1 christos #include "elf/tilepro.h" 26 1.1 christos #include "opcode/tilepro.h" 27 1.1 christos #include "libiberty.h" 28 1.1 christos #include "elf32-tilepro.h" 29 1.1 christos 30 1.1 christos #define TILEPRO_BYTES_PER_WORD 4 31 1.1 christos 32 1.1 christos static reloc_howto_type tilepro_elf_howto_table [] = 33 1.1 christos { 34 1.1 christos /* This reloc does nothing. */ 35 1.1 christos HOWTO (R_TILEPRO_NONE, /* type */ 36 1.1 christos 0, /* rightshift */ 37 1.10 christos 0, /* size */ 38 1.5 christos 0, /* bitsize */ 39 1.10 christos false, /* pc_relative */ 40 1.1 christos 0, /* bitpos */ 41 1.5 christos complain_overflow_dont, /* complain_on_overflow */ 42 1.1 christos bfd_elf_generic_reloc, /* special_function */ 43 1.1 christos "R_TILEPRO_NONE", /* name */ 44 1.10 christos false, /* partial_inplace */ 45 1.1 christos 0, /* src_mask */ 46 1.1 christos 0, /* dst_mask */ 47 1.10 christos false), /* pcrel_offset */ 48 1.1 christos 49 1.1 christos /* A 32 bit absolute relocation. */ 50 1.1 christos HOWTO (R_TILEPRO_32, /* type */ 51 1.1 christos 0, /* rightshift */ 52 1.10 christos 4, /* size */ 53 1.1 christos 32, /* bitsize */ 54 1.10 christos false, /* pc_relative */ 55 1.1 christos 0, /* bitpos */ 56 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 57 1.1 christos bfd_elf_generic_reloc, /* special_function */ 58 1.1 christos "R_TILEPRO_32", /* name */ 59 1.10 christos false, /* partial_inplace */ 60 1.1 christos 0, /* src_mask */ 61 1.1 christos 0xffffffff, /* dst_mask */ 62 1.10 christos false), /* pcrel_offset */ 63 1.1 christos 64 1.1 christos /* A 16 bit absolute relocation. */ 65 1.1 christos HOWTO (R_TILEPRO_16, /* type */ 66 1.1 christos 0, /* rightshift */ 67 1.10 christos 2, /* size */ 68 1.1 christos 16, /* bitsize */ 69 1.10 christos false, /* pc_relative */ 70 1.1 christos 0, /* bitpos */ 71 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 72 1.1 christos bfd_elf_generic_reloc, /* special_function */ 73 1.1 christos "R_TILEPRO_16", /* name */ 74 1.10 christos false, /* partial_inplace */ 75 1.1 christos 0, /* src_mask */ 76 1.1 christos 0xffff, /* dst_mask */ 77 1.10 christos false), /* pcrel_offset */ 78 1.1 christos 79 1.1 christos /* An 8 bit absolute relocation. */ 80 1.1 christos HOWTO (R_TILEPRO_8, /* type */ 81 1.1 christos 0, /* rightshift */ 82 1.10 christos 1, /* size */ 83 1.1 christos 8, /* bitsize */ 84 1.10 christos false, /* pc_relative */ 85 1.1 christos 0, /* bitpos */ 86 1.1 christos complain_overflow_unsigned, /* complain_on_overflow */ 87 1.1 christos bfd_elf_generic_reloc, /* special_function */ 88 1.1 christos "R_TILEPRO_8", /* name */ 89 1.10 christos false, /* partial_inplace */ 90 1.1 christos 0, /* src_mask */ 91 1.1 christos 0xff, /* dst_mask */ 92 1.10 christos false), /* pcrel_offset */ 93 1.1 christos 94 1.1 christos /* A 32 bit pc-relative relocation. */ 95 1.1 christos HOWTO (R_TILEPRO_32_PCREL,/* type */ 96 1.1 christos 0, /* rightshift */ 97 1.10 christos 4, /* size */ 98 1.1 christos 32, /* bitsize */ 99 1.10 christos true, /* pc_relative */ 100 1.1 christos 0, /* bitpos */ 101 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 102 1.1 christos bfd_elf_generic_reloc, /* special_function */ 103 1.1 christos "R_TILEPRO_32_PCREL", /* name */ 104 1.10 christos false, /* partial_inplace */ 105 1.1 christos 0, /* src_mask */ 106 1.1 christos 0xffffffff, /* dst_mask */ 107 1.10 christos true), /* pcrel_offset */ 108 1.1 christos 109 1.1 christos /* A 16 bit pc-relative relocation. */ 110 1.1 christos HOWTO (R_TILEPRO_16_PCREL,/* type */ 111 1.1 christos 0, /* rightshift */ 112 1.10 christos 2, /* size */ 113 1.1 christos 16, /* bitsize */ 114 1.10 christos true, /* pc_relative */ 115 1.1 christos 0, /* bitpos */ 116 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 117 1.1 christos bfd_elf_generic_reloc, /* special_function */ 118 1.1 christos "R_TILEPRO_16_PCREL", /* name */ 119 1.10 christos false, /* partial_inplace */ 120 1.1 christos 0, /* src_mask */ 121 1.1 christos 0xffff, /* dst_mask */ 122 1.10 christos true), /* pcrel_offset */ 123 1.1 christos 124 1.1 christos /* An 8 bit pc-relative relocation. */ 125 1.1 christos HOWTO (R_TILEPRO_8_PCREL, /* type */ 126 1.1 christos 0, /* rightshift */ 127 1.10 christos 1, /* size */ 128 1.1 christos 8, /* bitsize */ 129 1.10 christos true, /* pc_relative */ 130 1.1 christos 0, /* bitpos */ 131 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 132 1.1 christos bfd_elf_generic_reloc, /* special_function */ 133 1.1 christos "R_TILEPRO_8_PCREL",/* name */ 134 1.10 christos false, /* partial_inplace */ 135 1.1 christos 0, /* src_mask */ 136 1.1 christos 0xff, /* dst_mask */ 137 1.10 christos true), /* pcrel_offset */ 138 1.1 christos 139 1.1 christos /* A 16 bit relocation without overflow. */ 140 1.1 christos HOWTO (R_TILEPRO_LO16, /* type */ 141 1.1 christos 0, /* rightshift */ 142 1.10 christos 2, /* size */ 143 1.1 christos 16, /* bitsize */ 144 1.10 christos false, /* pc_relative */ 145 1.1 christos 0, /* bitpos */ 146 1.1 christos complain_overflow_dont,/* complain_on_overflow */ 147 1.1 christos bfd_elf_generic_reloc, /* special_function */ 148 1.1 christos "R_TILEPRO_LO16", /* name */ 149 1.10 christos false, /* partial_inplace */ 150 1.1 christos 0, /* src_mask */ 151 1.1 christos 0xffff, /* dst_mask */ 152 1.10 christos false), /* pcrel_offset */ 153 1.1 christos 154 1.1 christos /* The high order 16 bits of an address. */ 155 1.1 christos HOWTO (R_TILEPRO_HI16, /* type */ 156 1.1 christos 16, /* rightshift */ 157 1.10 christos 2, /* size */ 158 1.1 christos 16, /* bitsize */ 159 1.10 christos false, /* pc_relative */ 160 1.1 christos 0, /* bitpos */ 161 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 162 1.1 christos bfd_elf_generic_reloc, /* special_function */ 163 1.1 christos "R_TILEPRO_HI16", /* name */ 164 1.10 christos false, /* partial_inplace */ 165 1.1 christos 0, /* src_mask */ 166 1.1 christos 0xffff, /* dst_mask */ 167 1.10 christos false), /* pcrel_offset */ 168 1.1 christos 169 1.1 christos /* The high order 16 bits of an address, plus 1 if the contents of 170 1.1 christos the low 16 bits, treated as a signed number, is negative. */ 171 1.1 christos HOWTO (R_TILEPRO_HA16, /* type */ 172 1.1 christos 16, /* rightshift */ 173 1.10 christos 2, /* size */ 174 1.1 christos 16, /* bitsize */ 175 1.10 christos false, /* pc_relative */ 176 1.1 christos 0, /* bitpos */ 177 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 178 1.1 christos bfd_elf_generic_reloc, /* special_function */ 179 1.1 christos "R_TILEPRO_HA16", /* name */ 180 1.10 christos false, /* partial_inplace */ 181 1.1 christos 0, /* src_mask */ 182 1.1 christos 0xffff, /* dst_mask */ 183 1.10 christos false), /* pcrel_offset */ 184 1.1 christos 185 1.10 christos HOWTO (R_TILEPRO_COPY, /* type */ 186 1.1 christos 0, /* rightshift */ 187 1.10 christos 0, /* size */ 188 1.1 christos 0, /* bitsize */ 189 1.10 christos false, /* pc_relative */ 190 1.1 christos 0, /* bitpos */ 191 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 192 1.1 christos bfd_elf_generic_reloc, /* special_function */ 193 1.1 christos "R_TILEPRO_COPY", /* name */ 194 1.10 christos false, /* partial_inplace */ 195 1.1 christos 0, /* src_mask */ 196 1.1 christos 0, /* dst_mask */ 197 1.10 christos true), /* pcrel_offset */ 198 1.1 christos 199 1.1 christos HOWTO (R_TILEPRO_GLOB_DAT, /* type */ 200 1.1 christos 0, /* rightshift */ 201 1.10 christos 0, /* size */ 202 1.1 christos 0, /* bitsize */ 203 1.10 christos false, /* pc_relative */ 204 1.1 christos 0, /* bitpos */ 205 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 206 1.1 christos bfd_elf_generic_reloc, /* special_function */ 207 1.1 christos "R_TILEPRO_GLOB_DAT", /* name */ 208 1.10 christos false, /* partial_inplace */ 209 1.1 christos 0, /* src_mask */ 210 1.1 christos 0, /* dst_mask */ 211 1.10 christos true), /* pcrel_offset */ 212 1.1 christos 213 1.1 christos HOWTO (R_TILEPRO_JMP_SLOT, /* type */ 214 1.1 christos 0, /* rightshift */ 215 1.10 christos 0, /* size */ 216 1.1 christos 0, /* bitsize */ 217 1.10 christos false, /* pc_relative */ 218 1.1 christos 0, /* bitpos */ 219 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 220 1.1 christos bfd_elf_generic_reloc, /* special_function */ 221 1.1 christos "R_TILEPRO_JMP_SLOT", /* name */ 222 1.10 christos false, /* partial_inplace */ 223 1.1 christos 0, /* src_mask */ 224 1.1 christos 0, /* dst_mask */ 225 1.10 christos true), /* pcrel_offset */ 226 1.1 christos 227 1.1 christos HOWTO (R_TILEPRO_RELATIVE, /* type */ 228 1.1 christos 0, /* rightshift */ 229 1.10 christos 0, /* size */ 230 1.1 christos 0, /* bitsize */ 231 1.10 christos false, /* pc_relative */ 232 1.1 christos 0, /* bitpos */ 233 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 234 1.1 christos bfd_elf_generic_reloc, /* special_function */ 235 1.1 christos "R_TILEPRO_RELATIVE", /* name */ 236 1.10 christos false, /* partial_inplace */ 237 1.1 christos 0, /* src_mask */ 238 1.1 christos 0, /* dst_mask */ 239 1.10 christos true), /* pcrel_offset */ 240 1.1 christos 241 1.1 christos HOWTO (R_TILEPRO_BROFF_X1, /* type */ 242 1.1 christos TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */ 243 1.10 christos 4, /* size */ 244 1.1 christos 17, /* bitsize */ 245 1.10 christos true, /* pc_relative */ 246 1.1 christos 0, /* bitpos */ 247 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 248 1.1 christos bfd_elf_generic_reloc, /* special_function */ 249 1.1 christos "R_TILEPRO_BROFF_X1", /* name */ 250 1.10 christos false, /* partial_inplace */ 251 1.1 christos 0, /* src_mask */ 252 1.1 christos -1, /* dst_mask */ 253 1.10 christos true), /* pcrel_offset */ 254 1.1 christos 255 1.1 christos HOWTO (R_TILEPRO_JOFFLONG_X1, /* type */ 256 1.1 christos TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */ 257 1.10 christos 4, /* size */ 258 1.1 christos 29, /* bitsize */ 259 1.10 christos true, /* pc_relative */ 260 1.1 christos 0, /* bitpos */ 261 1.1 christos complain_overflow_signed,/* complain_on_overflow */ 262 1.1 christos bfd_elf_generic_reloc, /* special_function */ 263 1.1 christos "R_TILEPRO_JOFFLONG_X1", /* name */ 264 1.10 christos false, /* partial_inplace */ 265 1.1 christos 0, /* src_mask */ 266 1.1 christos -1, /* dst_mask */ 267 1.10 christos true), /* pcrel_offset */ 268 1.1 christos 269 1.1 christos HOWTO (R_TILEPRO_JOFFLONG_X1_PLT, /* type */ 270 1.1 christos TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */ 271 1.10 christos 4, /* size */ 272 1.1 christos 29, /* bitsize */ 273 1.10 christos true, /* pc_relative */ 274 1.1 christos 0, /* bitpos */ 275 1.1 christos complain_overflow_signed,/* complain_on_overflow */ 276 1.1 christos bfd_elf_generic_reloc, /* special_function */ 277 1.1 christos "R_TILEPRO_JOFFLONG_X1_PLT", /* name */ 278 1.10 christos false, /* partial_inplace */ 279 1.1 christos 0, /* src_mask */ 280 1.1 christos -1, /* dst_mask */ 281 1.10 christos true), /* pcrel_offset */ 282 1.1 christos 283 1.1 christos #define TILEPRO_IMM_HOWTO(name, size, bitsize) \ 284 1.10 christos HOWTO (name, 0, size, bitsize, false, 0, \ 285 1.8 christos complain_overflow_signed, bfd_elf_generic_reloc, \ 286 1.10 christos #name, false, 0, -1, false) 287 1.1 christos 288 1.1 christos #define TILEPRO_UIMM_HOWTO(name, size, bitsize) \ 289 1.10 christos HOWTO (name, 0, size, bitsize, false, 0, \ 290 1.8 christos complain_overflow_unsigned, bfd_elf_generic_reloc, \ 291 1.10 christos #name, false, 0, -1, false) 292 1.1 christos 293 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X0, 1, 8), 294 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y0, 1, 8), 295 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X1, 1, 8), 296 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y1, 1, 8), 297 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_MT_IMM15_X1, 2, 15), 298 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_MF_IMM15_X1, 2, 15), 299 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X0, 2, 16), 300 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X1, 2, 16), 301 1.1 christos 302 1.1 christos #define TILEPRO_IMM16_HOWTO(name, rshift) \ 303 1.10 christos HOWTO (name, rshift, 2, 16, false, 0, \ 304 1.8 christos complain_overflow_dont, bfd_elf_generic_reloc, \ 305 1.10 christos #name, false, 0, 0xffff, false) 306 1.1 christos 307 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_LO, 0), 308 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_LO, 0), 309 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_HI, 16), 310 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_HI, 16), 311 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_HA, 16), 312 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_HA, 16), 313 1.1 christos 314 1.1 christos /* PC-relative offsets. */ 315 1.1 christos 316 1.1 christos HOWTO (R_TILEPRO_IMM16_X0_PCREL, /* type */ 317 1.1 christos 0, /* rightshift */ 318 1.10 christos 2, /* size */ 319 1.1 christos 16, /* bitsize */ 320 1.10 christos true, /* pc_relative */ 321 1.1 christos 0, /* bitpos */ 322 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 323 1.1 christos bfd_elf_generic_reloc, /* special_function */ 324 1.1 christos "R_TILEPRO_IMM16_X0_PCREL",/* name */ 325 1.10 christos false, /* partial_inplace */ 326 1.1 christos 0, /* src_mask */ 327 1.1 christos -1, /* dst_mask */ 328 1.10 christos true), /* pcrel_offset */ 329 1.1 christos 330 1.1 christos HOWTO (R_TILEPRO_IMM16_X1_PCREL, /* type */ 331 1.1 christos 0, /* rightshift */ 332 1.10 christos 2, /* size */ 333 1.1 christos 16, /* bitsize */ 334 1.10 christos true, /* pc_relative */ 335 1.1 christos 0, /* bitpos */ 336 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 337 1.1 christos bfd_elf_generic_reloc, /* special_function */ 338 1.1 christos "R_TILEPRO_IMM16_X1_PCREL",/* name */ 339 1.10 christos false, /* partial_inplace */ 340 1.1 christos 0, /* src_mask */ 341 1.1 christos -1, /* dst_mask */ 342 1.10 christos true), /* pcrel_offset */ 343 1.1 christos 344 1.1 christos #define TILEPRO_IMM16_HOWTO_PCREL(name, rshift) \ 345 1.10 christos HOWTO (name, rshift, 2, 16, true, 0, \ 346 1.8 christos complain_overflow_dont, bfd_elf_generic_reloc, \ 347 1.10 christos #name, false, 0, 0xffff, true) 348 1.1 christos 349 1.1 christos TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X0_LO_PCREL, 0), 350 1.1 christos TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X1_LO_PCREL, 0), 351 1.1 christos TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X0_HI_PCREL, 16), 352 1.1 christos TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X1_HI_PCREL, 16), 353 1.1 christos TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X0_HA_PCREL, 16), 354 1.1 christos TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X1_HA_PCREL, 16), 355 1.1 christos 356 1.1 christos /* Byte offset into GOT for a particular symbol. */ 357 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X0_GOT, 2, 16), 358 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X1_GOT, 2, 16), 359 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_GOT_LO, 0), 360 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_GOT_LO, 0), 361 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_GOT_HI, 16), 362 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_GOT_HI, 16), 363 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_GOT_HA, 16), 364 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_GOT_HA, 16), 365 1.1 christos 366 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_MMSTART_X0, 1, 5), 367 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_MMEND_X0, 1, 5), 368 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_MMSTART_X1, 1, 5), 369 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_MMEND_X1, 1, 5), 370 1.10 christos 371 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_X0, 1, 5), 372 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_X1, 1, 5), 373 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_Y0, 1, 5), 374 1.10 christos TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_Y1, 1, 5), 375 1.1 christos 376 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_DEST_IMM8_X1, 1, 8), 377 1.1 christos 378 1.1 christos /* These relocs are currently not defined. */ 379 1.1 christos EMPTY_HOWTO (56), 380 1.1 christos EMPTY_HOWTO (57), 381 1.1 christos EMPTY_HOWTO (58), 382 1.1 christos EMPTY_HOWTO (59), 383 1.1 christos 384 1.1 christos HOWTO (R_TILEPRO_TLS_GD_CALL, /* type */ 385 1.1 christos TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */ 386 1.10 christos 4, /* size */ 387 1.1 christos 29, /* bitsize */ 388 1.10 christos true, /* pc_relative */ 389 1.1 christos 0, /* bitpos */ 390 1.1 christos complain_overflow_signed,/* complain_on_overflow */ 391 1.1 christos bfd_elf_generic_reloc, /* special_function */ 392 1.1 christos "R_TILEPRO_TLS_GD_CALL", /* name */ 393 1.10 christos false, /* partial_inplace */ 394 1.1 christos 0, /* src_mask */ 395 1.1 christos -1, /* dst_mask */ 396 1.10 christos true), /* pcrel_offset */ 397 1.1 christos 398 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X0_TLS_GD_ADD, 1, 8), 399 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X1_TLS_GD_ADD, 1, 8), 400 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y0_TLS_GD_ADD, 1, 8), 401 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y1_TLS_GD_ADD, 1, 8), 402 1.10 christos TILEPRO_IMM_HOWTO(R_TILEPRO_TLS_IE_LOAD, 1, 8), 403 1.1 christos 404 1.1 christos /* Offsets into the GOT of TLS Descriptors. */ 405 1.1 christos 406 1.1 christos HOWTO (R_TILEPRO_IMM16_X0_TLS_GD,/* type */ 407 1.1 christos 0, /* rightshift */ 408 1.10 christos 2, /* size */ 409 1.1 christos 16, /* bitsize */ 410 1.10 christos false, /* pc_relative */ 411 1.1 christos 0, /* bitpos */ 412 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 413 1.1 christos bfd_elf_generic_reloc, /* special_function */ 414 1.1 christos "R_TILEPRO_IMM16_X0_TLS_GD",/* name */ 415 1.10 christos false, /* partial_inplace */ 416 1.1 christos 0, /* src_mask */ 417 1.1 christos 0xffff, /* dst_mask */ 418 1.10 christos false), /* pcrel_offset */ 419 1.1 christos 420 1.1 christos HOWTO (R_TILEPRO_IMM16_X1_TLS_GD,/* type */ 421 1.1 christos 0, /* rightshift */ 422 1.10 christos 2, /* size */ 423 1.1 christos 16, /* bitsize */ 424 1.10 christos false, /* pc_relative */ 425 1.1 christos 0, /* bitpos */ 426 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 427 1.1 christos bfd_elf_generic_reloc, /* special_function */ 428 1.1 christos "R_TILEPRO_IMM16_X1_TLS_GD",/* name */ 429 1.10 christos false, /* partial_inplace */ 430 1.1 christos 0, /* src_mask */ 431 1.1 christos 0xffff, /* dst_mask */ 432 1.10 christos false), /* pcrel_offset */ 433 1.1 christos 434 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_GD_LO, 0), 435 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_GD_LO, 0), 436 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_GD_HI, 16), 437 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_GD_HI, 16), 438 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_GD_HA, 16), 439 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_GD_HA, 16), 440 1.1 christos 441 1.1 christos /* Offsets into the GOT of TLS Descriptors. */ 442 1.1 christos 443 1.1 christos HOWTO (R_TILEPRO_IMM16_X0_TLS_IE,/* type */ 444 1.1 christos 0, /* rightshift */ 445 1.10 christos 2, /* size */ 446 1.1 christos 16, /* bitsize */ 447 1.10 christos false, /* pc_relative */ 448 1.1 christos 0, /* bitpos */ 449 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 450 1.1 christos bfd_elf_generic_reloc, /* special_function */ 451 1.1 christos "R_TILEPRO_IMM16_X0_TLS_IE",/* name */ 452 1.10 christos false, /* partial_inplace */ 453 1.1 christos 0, /* src_mask */ 454 1.1 christos -1, /* dst_mask */ 455 1.10 christos true), /* pcrel_offset */ 456 1.1 christos 457 1.1 christos HOWTO (R_TILEPRO_IMM16_X1_TLS_IE,/* type */ 458 1.1 christos 0, /* rightshift */ 459 1.10 christos 2, /* size */ 460 1.1 christos 16, /* bitsize */ 461 1.10 christos false, /* pc_relative */ 462 1.1 christos 0, /* bitpos */ 463 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 464 1.1 christos bfd_elf_generic_reloc, /* special_function */ 465 1.1 christos "R_TILEPRO_IMM16_X1_TLS_IE",/* name */ 466 1.10 christos false, /* partial_inplace */ 467 1.1 christos 0, /* src_mask */ 468 1.1 christos -1, /* dst_mask */ 469 1.10 christos true), /* pcrel_offset */ 470 1.1 christos 471 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_IE_LO, 0), 472 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_IE_LO, 0), 473 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_IE_HI, 16), 474 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_IE_HI, 16), 475 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_IE_HA, 16), 476 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_IE_HA, 16), 477 1.1 christos 478 1.1 christos /* These are common with the Solaris TLS implementation. */ 479 1.10 christos HOWTO(R_TILEPRO_TLS_DTPMOD32, 0, 0, 0, false, 0, complain_overflow_dont, 480 1.8 christos bfd_elf_generic_reloc, "R_TILEPRO_TLS_DTPMOD32", 481 1.10 christos false, 0, 0, true), 482 1.10 christos HOWTO(R_TILEPRO_TLS_DTPOFF32, 0, 4, 32, false, 0, complain_overflow_bitfield, 483 1.8 christos bfd_elf_generic_reloc, "R_TILEPRO_TLS_DTPOFF32", 484 1.10 christos false, 0, 0xFFFFFFFF, true), 485 1.10 christos HOWTO(R_TILEPRO_TLS_TPOFF32, 0, 0, 0, false, 0, complain_overflow_dont, 486 1.8 christos bfd_elf_generic_reloc, "R_TILEPRO_TLS_TPOFF32", 487 1.10 christos false, 0, 0, true), 488 1.1 christos 489 1.1 christos HOWTO (R_TILEPRO_IMM16_X0_TLS_LE,/* type */ 490 1.1 christos 0, /* rightshift */ 491 1.10 christos 2, /* size */ 492 1.1 christos 16, /* bitsize */ 493 1.10 christos false, /* pc_relative */ 494 1.1 christos 0, /* bitpos */ 495 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 496 1.1 christos bfd_elf_generic_reloc, /* special_function */ 497 1.1 christos "R_TILEPRO_IMM16_X0_TLS_LE",/* name */ 498 1.10 christos false, /* partial_inplace */ 499 1.1 christos 0, /* src_mask */ 500 1.1 christos -1, /* dst_mask */ 501 1.10 christos true), /* pcrel_offset */ 502 1.1 christos 503 1.1 christos HOWTO (R_TILEPRO_IMM16_X1_TLS_LE,/* type */ 504 1.1 christos 0, /* rightshift */ 505 1.10 christos 2, /* size */ 506 1.1 christos 16, /* bitsize */ 507 1.10 christos false, /* pc_relative */ 508 1.1 christos 0, /* bitpos */ 509 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 510 1.1 christos bfd_elf_generic_reloc, /* special_function */ 511 1.1 christos "R_TILEPRO_IMM16_X1_TLS_LE",/* name */ 512 1.10 christos false, /* partial_inplace */ 513 1.1 christos 0, /* src_mask */ 514 1.1 christos -1, /* dst_mask */ 515 1.10 christos true), /* pcrel_offset */ 516 1.1 christos 517 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_LE_LO, 0), 518 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_LE_LO, 0), 519 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_LE_HI, 16), 520 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_LE_HI, 16), 521 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_LE_HA, 16), 522 1.1 christos TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_LE_HA, 16), 523 1.1 christos }; 524 1.1 christos 525 1.1 christos static reloc_howto_type tilepro_elf_howto_table2 [] = 526 1.1 christos { 527 1.1 christos /* GNU extension to record C++ vtable hierarchy */ 528 1.1 christos HOWTO (R_TILEPRO_GNU_VTINHERIT, /* type */ 529 1.8 christos 0, /* rightshift */ 530 1.10 christos 4, /* size */ 531 1.8 christos 0, /* bitsize */ 532 1.10 christos false, /* pc_relative */ 533 1.8 christos 0, /* bitpos */ 534 1.8 christos complain_overflow_dont, /* complain_on_overflow */ 535 1.8 christos NULL, /* special_function */ 536 1.8 christos "R_TILEPRO_GNU_VTINHERIT", /* name */ 537 1.10 christos false, /* partial_inplace */ 538 1.8 christos 0, /* src_mask */ 539 1.8 christos 0, /* dst_mask */ 540 1.10 christos false), /* pcrel_offset */ 541 1.1 christos 542 1.1 christos /* GNU extension to record C++ vtable member usage */ 543 1.8 christos HOWTO (R_TILEPRO_GNU_VTENTRY, /* type */ 544 1.8 christos 0, /* rightshift */ 545 1.10 christos 4, /* size */ 546 1.8 christos 0, /* bitsize */ 547 1.10 christos false, /* pc_relative */ 548 1.8 christos 0, /* bitpos */ 549 1.8 christos complain_overflow_dont, /* complain_on_overflow */ 550 1.8 christos _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 551 1.8 christos "R_TILEPRO_GNU_VTENTRY", /* name */ 552 1.10 christos false, /* partial_inplace */ 553 1.8 christos 0, /* src_mask */ 554 1.8 christos 0, /* dst_mask */ 555 1.10 christos false), /* pcrel_offset */ 556 1.1 christos 557 1.1 christos }; 558 1.1 christos 559 1.1 christos /* Map BFD reloc types to TILEPRO ELF reloc types. */ 561 1.1 christos 562 1.1 christos typedef struct tilepro_reloc_map 563 1.1 christos { 564 1.8 christos bfd_reloc_code_real_type bfd_reloc_val; 565 1.8 christos unsigned int tilepro_reloc_val; 566 1.1 christos reloc_howto_type * table; 567 1.1 christos } reloc_map; 568 1.1 christos 569 1.1 christos static const reloc_map tilepro_reloc_map [] = 570 1.1 christos { 571 1.1 christos #define TH_REMAP(bfd, tilepro) \ 572 1.1 christos { bfd, tilepro, tilepro_elf_howto_table }, 573 1.1 christos 574 1.8 christos /* Standard relocations. */ 575 1.8 christos TH_REMAP (BFD_RELOC_NONE, R_TILEPRO_NONE) 576 1.8 christos TH_REMAP (BFD_RELOC_32, R_TILEPRO_32) 577 1.8 christos TH_REMAP (BFD_RELOC_16, R_TILEPRO_16) 578 1.8 christos TH_REMAP (BFD_RELOC_8, R_TILEPRO_8) 579 1.8 christos TH_REMAP (BFD_RELOC_32_PCREL, R_TILEPRO_32_PCREL) 580 1.8 christos TH_REMAP (BFD_RELOC_16_PCREL, R_TILEPRO_16_PCREL) 581 1.8 christos TH_REMAP (BFD_RELOC_8_PCREL, R_TILEPRO_8_PCREL) 582 1.8 christos TH_REMAP (BFD_RELOC_LO16, R_TILEPRO_LO16) 583 1.8 christos TH_REMAP (BFD_RELOC_HI16, R_TILEPRO_HI16) 584 1.1 christos TH_REMAP (BFD_RELOC_HI16_S, R_TILEPRO_HA16) 585 1.1 christos 586 1.8 christos /* Custom relocations. */ 587 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_COPY, R_TILEPRO_COPY) 588 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_GLOB_DAT, R_TILEPRO_GLOB_DAT) 589 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_JMP_SLOT, R_TILEPRO_JMP_SLOT) 590 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_RELATIVE, R_TILEPRO_RELATIVE) 591 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_BROFF_X1, R_TILEPRO_BROFF_X1) 592 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_JOFFLONG_X1, R_TILEPRO_JOFFLONG_X1) 593 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_JOFFLONG_X1_PLT, R_TILEPRO_JOFFLONG_X1_PLT) 594 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X0, R_TILEPRO_IMM8_X0) 595 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y0, R_TILEPRO_IMM8_Y0) 596 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X1, R_TILEPRO_IMM8_X1) 597 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y1, R_TILEPRO_IMM8_Y1) 598 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_DEST_IMM8_X1, R_TILEPRO_DEST_IMM8_X1) 599 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_MT_IMM15_X1, R_TILEPRO_MT_IMM15_X1) 600 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_MF_IMM15_X1, R_TILEPRO_MF_IMM15_X1) 601 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0, R_TILEPRO_IMM16_X0) 602 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1, R_TILEPRO_IMM16_X1) 603 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_LO, R_TILEPRO_IMM16_X0_LO) 604 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_LO, R_TILEPRO_IMM16_X1_LO) 605 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HI, R_TILEPRO_IMM16_X0_HI) 606 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HI, R_TILEPRO_IMM16_X1_HI) 607 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HA, R_TILEPRO_IMM16_X0_HA) 608 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HA, R_TILEPRO_IMM16_X1_HA) 609 1.8 christos 610 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_PCREL, R_TILEPRO_IMM16_X0_PCREL) 611 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_PCREL, R_TILEPRO_IMM16_X1_PCREL) 612 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_LO_PCREL, R_TILEPRO_IMM16_X0_LO_PCREL) 613 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_LO_PCREL, R_TILEPRO_IMM16_X1_LO_PCREL) 614 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HI_PCREL, R_TILEPRO_IMM16_X0_HI_PCREL) 615 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HI_PCREL, R_TILEPRO_IMM16_X1_HI_PCREL) 616 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HA_PCREL, R_TILEPRO_IMM16_X0_HA_PCREL) 617 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HA_PCREL, R_TILEPRO_IMM16_X1_HA_PCREL) 618 1.1 christos 619 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT, R_TILEPRO_IMM16_X0_GOT) 620 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT, R_TILEPRO_IMM16_X1_GOT) 621 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT_LO, R_TILEPRO_IMM16_X0_GOT_LO) 622 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT_LO, R_TILEPRO_IMM16_X1_GOT_LO) 623 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT_HI, R_TILEPRO_IMM16_X0_GOT_HI) 624 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT_HI, R_TILEPRO_IMM16_X1_GOT_HI) 625 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT_HA, R_TILEPRO_IMM16_X0_GOT_HA) 626 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT_HA, R_TILEPRO_IMM16_X1_GOT_HA) 627 1.1 christos 628 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_MMSTART_X0, R_TILEPRO_MMSTART_X0) 629 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_MMEND_X0, R_TILEPRO_MMEND_X0) 630 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_MMSTART_X1, R_TILEPRO_MMSTART_X1) 631 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_MMEND_X1, R_TILEPRO_MMEND_X1) 632 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_X0, R_TILEPRO_SHAMT_X0) 633 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_X1, R_TILEPRO_SHAMT_X1) 634 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_Y0, R_TILEPRO_SHAMT_Y0) 635 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_Y1, R_TILEPRO_SHAMT_Y1) 636 1.8 christos 637 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_TLS_GD_CALL, R_TILEPRO_TLS_GD_CALL) 638 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X0_TLS_GD_ADD, R_TILEPRO_IMM8_X0_TLS_GD_ADD) 639 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X1_TLS_GD_ADD, R_TILEPRO_IMM8_X1_TLS_GD_ADD) 640 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y0_TLS_GD_ADD, R_TILEPRO_IMM8_Y0_TLS_GD_ADD) 641 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y1_TLS_GD_ADD, R_TILEPRO_IMM8_Y1_TLS_GD_ADD) 642 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_TLS_IE_LOAD, R_TILEPRO_TLS_IE_LOAD) 643 1.8 christos 644 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD, R_TILEPRO_IMM16_X0_TLS_GD) 645 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD, R_TILEPRO_IMM16_X1_TLS_GD) 646 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_LO, R_TILEPRO_IMM16_X0_TLS_GD_LO) 647 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_LO, R_TILEPRO_IMM16_X1_TLS_GD_LO) 648 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HI, R_TILEPRO_IMM16_X0_TLS_GD_HI) 649 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HI, R_TILEPRO_IMM16_X1_TLS_GD_HI) 650 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HA, R_TILEPRO_IMM16_X0_TLS_GD_HA) 651 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HA, R_TILEPRO_IMM16_X1_TLS_GD_HA) 652 1.8 christos 653 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE, R_TILEPRO_IMM16_X0_TLS_IE) 654 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE, R_TILEPRO_IMM16_X1_TLS_IE) 655 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_LO, R_TILEPRO_IMM16_X0_TLS_IE_LO) 656 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_LO, R_TILEPRO_IMM16_X1_TLS_IE_LO) 657 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HI, R_TILEPRO_IMM16_X0_TLS_IE_HI) 658 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HI, R_TILEPRO_IMM16_X1_TLS_IE_HI) 659 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HA, R_TILEPRO_IMM16_X0_TLS_IE_HA) 660 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HA, R_TILEPRO_IMM16_X1_TLS_IE_HA) 661 1.1 christos 662 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_TLS_DTPMOD32, R_TILEPRO_TLS_DTPMOD32) 663 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_TLS_DTPOFF32, R_TILEPRO_TLS_DTPOFF32) 664 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_TLS_TPOFF32, R_TILEPRO_TLS_TPOFF32) 665 1.8 christos 666 1.8 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE, R_TILEPRO_IMM16_X0_TLS_LE) 667 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE, R_TILEPRO_IMM16_X1_TLS_LE) 668 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_LO, R_TILEPRO_IMM16_X0_TLS_LE_LO) 669 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_LO, R_TILEPRO_IMM16_X1_TLS_LE_LO) 670 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_HI, R_TILEPRO_IMM16_X0_TLS_LE_HI) 671 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_HI, R_TILEPRO_IMM16_X1_TLS_LE_HI) 672 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_HA, R_TILEPRO_IMM16_X0_TLS_LE_HA) 673 1.1 christos TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_HA, R_TILEPRO_IMM16_X1_TLS_LE_HA) 674 1.1 christos 675 1.1 christos #undef TH_REMAP 676 1.1 christos 677 1.1 christos { BFD_RELOC_VTABLE_INHERIT, R_TILEPRO_GNU_VTINHERIT, tilepro_elf_howto_table2 }, 678 1.1 christos { BFD_RELOC_VTABLE_ENTRY, R_TILEPRO_GNU_VTENTRY, tilepro_elf_howto_table2 }, 679 1.1 christos }; 680 1.1 christos 681 1.1 christos 682 1.1 christos 683 1.1 christos /* TILEPRO ELF linker hash entry. */ 684 1.1 christos 685 1.1 christos struct tilepro_elf_link_hash_entry 686 1.1 christos { 687 1.1 christos struct elf_link_hash_entry elf; 688 1.1 christos 689 1.1 christos #define GOT_UNKNOWN 0 690 1.1 christos #define GOT_NORMAL 1 691 1.1 christos #define GOT_TLS_GD 2 692 1.1 christos #define GOT_TLS_IE 4 693 1.1 christos unsigned char tls_type; 694 1.1 christos }; 695 1.1 christos 696 1.1 christos #define tilepro_elf_hash_entry(ent) \ 697 1.1 christos ((struct tilepro_elf_link_hash_entry *)(ent)) 698 1.1 christos 699 1.1 christos struct _bfd_tilepro_elf_obj_tdata 700 1.1 christos { 701 1.1 christos struct elf_obj_tdata root; 702 1.1 christos 703 1.1 christos /* tls_type for each local got entry. */ 704 1.1 christos char *local_got_tls_type; 705 1.1 christos }; 706 1.1 christos 707 1.1 christos #define _bfd_tilepro_elf_tdata(abfd) \ 708 1.1 christos ((struct _bfd_tilepro_elf_obj_tdata *) (abfd)->tdata.any) 709 1.1 christos 710 1.1 christos #define _bfd_tilepro_elf_local_got_tls_type(abfd) \ 711 1.1 christos (_bfd_tilepro_elf_tdata (abfd)->local_got_tls_type) 712 1.1 christos 713 1.1 christos #define is_tilepro_elf(bfd) \ 714 1.1 christos (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ 715 1.1 christos && elf_tdata (bfd) != NULL \ 716 1.1 christos && elf_object_id (bfd) == TILEPRO_ELF_DATA) 717 1.1 christos 718 1.1 christos /* Allocate TILEPro ELF private object data. */ 719 1.10 christos 720 1.1 christos static bool 721 1.1 christos tilepro_elf_mkobject (bfd *abfd) 722 1.1 christos { 723 1.1 christos return bfd_elf_allocate_object (abfd, 724 1.1 christos sizeof (struct _bfd_tilepro_elf_obj_tdata), 725 1.1 christos TILEPRO_ELF_DATA); 726 1.1 christos } 727 1.1 christos 728 1.1 christos #include "elf/common.h" 729 1.1 christos #include "elf/internal.h" 730 1.1 christos 731 1.1 christos /* Get the Tilepro ELF linker hash table from a link_info structure. */ 732 1.9 christos #define tilepro_elf_hash_table(p) \ 733 1.9 christos ((is_elf_hash_table ((p)->hash) \ 734 1.9 christos && elf_hash_table_id (elf_hash_table (p)) == TILEPRO_ELF_DATA) \ 735 1.1 christos ? (struct elf_link_hash_table *) (p)->hash : NULL) 736 1.1 christos 737 1.1 christos static reloc_howto_type * 738 1.8 christos tilepro_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, 739 1.1 christos bfd_reloc_code_real_type code) 740 1.1 christos { 741 1.1 christos unsigned int i; 742 1.5 christos 743 1.1 christos for (i = ARRAY_SIZE (tilepro_reloc_map); i--;) 744 1.1 christos { 745 1.1 christos const reloc_map * entry; 746 1.1 christos 747 1.1 christos entry = tilepro_reloc_map + i; 748 1.1 christos 749 1.1 christos if (entry->bfd_reloc_val == code) 750 1.1 christos return entry->table + (entry->tilepro_reloc_val 751 1.1 christos - entry->table[0].type); 752 1.1 christos } 753 1.1 christos 754 1.1 christos return NULL; 755 1.1 christos } 756 1.1 christos 757 1.1 christos static reloc_howto_type * 758 1.1 christos tilepro_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 759 1.1 christos const char *r_name) 760 1.1 christos { 761 1.1 christos unsigned int i; 762 1.1 christos 763 1.1 christos for (i = 0; 764 1.8 christos i < (sizeof (tilepro_elf_howto_table) 765 1.1 christos / sizeof (tilepro_elf_howto_table[0])); 766 1.1 christos i++) 767 1.8 christos if (tilepro_elf_howto_table[i].name != NULL 768 1.1 christos && strcasecmp (tilepro_elf_howto_table[i].name, r_name) == 0) 769 1.1 christos return &tilepro_elf_howto_table[i]; 770 1.1 christos 771 1.1 christos return NULL; 772 1.1 christos } 773 1.1 christos 774 1.1 christos /* Set the howto pointer for an TILEPro ELF reloc. */ 775 1.10 christos 776 1.1 christos static bool 777 1.8 christos tilepro_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, 778 1.8 christos arelent * cache_ptr, 779 1.1 christos Elf_Internal_Rela * dst) 780 1.1 christos { 781 1.1 christos unsigned int r_type = ELF32_R_TYPE (dst->r_info); 782 1.1 christos 783 1.1 christos if (r_type <= (unsigned int) R_TILEPRO_IMM16_X1_TLS_LE_HA) 784 1.1 christos cache_ptr->howto = &tilepro_elf_howto_table [r_type]; 785 1.8 christos else if (r_type - R_TILEPRO_GNU_VTINHERIT 786 1.8 christos <= ((unsigned int) R_TILEPRO_GNU_VTENTRY 787 1.1 christos - (unsigned int) R_TILEPRO_GNU_VTINHERIT)) 788 1.1 christos cache_ptr->howto 789 1.1 christos = &tilepro_elf_howto_table2 [r_type - R_TILEPRO_GNU_VTINHERIT]; 790 1.8 christos else 791 1.8 christos { 792 1.8 christos /* xgettext:c-format */ 793 1.8 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 794 1.8 christos abfd, r_type); 795 1.10 christos bfd_set_error (bfd_error_bad_value); 796 1.8 christos return false; 797 1.10 christos } 798 1.1 christos return true; 799 1.1 christos } 800 1.1 christos 801 1.1 christos typedef tilepro_bundle_bits (*tilepro_create_func)(int); 802 1.1 christos 803 1.1 christos static const tilepro_create_func reloc_to_create_func[] = 804 1.1 christos { 805 1.1 christos /* The first fourteen relocation types don't correspond to operands */ 806 1.1 christos NULL, 807 1.1 christos NULL, 808 1.1 christos NULL, 809 1.1 christos NULL, 810 1.1 christos NULL, 811 1.1 christos NULL, 812 1.1 christos NULL, 813 1.1 christos NULL, 814 1.1 christos NULL, 815 1.1 christos NULL, 816 1.1 christos NULL, 817 1.1 christos NULL, 818 1.1 christos NULL, 819 1.1 christos NULL, 820 1.1 christos 821 1.1 christos /* The remaining relocations are used for immediate operands */ 822 1.1 christos create_BrOff_X1, 823 1.1 christos create_JOffLong_X1, 824 1.1 christos create_JOffLong_X1, 825 1.1 christos create_Imm8_X0, 826 1.1 christos create_Imm8_Y0, 827 1.1 christos create_Imm8_X1, 828 1.1 christos create_Imm8_Y1, 829 1.1 christos create_MT_Imm15_X1, 830 1.1 christos create_MF_Imm15_X1, 831 1.1 christos create_Imm16_X0, 832 1.1 christos create_Imm16_X1, 833 1.1 christos create_Imm16_X0, 834 1.1 christos create_Imm16_X1, 835 1.1 christos create_Imm16_X0, 836 1.1 christos create_Imm16_X1, 837 1.1 christos create_Imm16_X0, 838 1.1 christos create_Imm16_X1, 839 1.1 christos create_Imm16_X0, 840 1.1 christos create_Imm16_X1, 841 1.1 christos create_Imm16_X0, 842 1.1 christos create_Imm16_X1, 843 1.1 christos create_Imm16_X0, 844 1.1 christos create_Imm16_X1, 845 1.1 christos create_Imm16_X0, 846 1.1 christos create_Imm16_X1, 847 1.1 christos create_Imm16_X0, 848 1.1 christos create_Imm16_X1, 849 1.1 christos create_Imm16_X0, 850 1.1 christos create_Imm16_X1, 851 1.1 christos create_Imm16_X0, 852 1.1 christos create_Imm16_X1, 853 1.1 christos create_Imm16_X0, 854 1.1 christos create_Imm16_X1, 855 1.1 christos create_MMStart_X0, 856 1.1 christos create_MMEnd_X0, 857 1.1 christos create_MMStart_X1, 858 1.1 christos create_MMEnd_X1, 859 1.1 christos create_ShAmt_X0, 860 1.1 christos create_ShAmt_X1, 861 1.1 christos create_ShAmt_Y0, 862 1.1 christos create_ShAmt_Y1, 863 1.1 christos 864 1.1 christos create_Dest_Imm8_X1, 865 1.1 christos NULL, 866 1.1 christos NULL, 867 1.1 christos NULL, 868 1.1 christos NULL, 869 1.1 christos NULL, 870 1.1 christos NULL, 871 1.1 christos NULL, 872 1.1 christos NULL, 873 1.1 christos NULL, 874 1.1 christos NULL, 875 1.1 christos 876 1.1 christos create_Imm16_X0, 877 1.1 christos create_Imm16_X1, 878 1.1 christos create_Imm16_X0, 879 1.1 christos create_Imm16_X1, 880 1.1 christos create_Imm16_X0, 881 1.1 christos create_Imm16_X1, 882 1.1 christos create_Imm16_X0, 883 1.1 christos create_Imm16_X1, 884 1.1 christos create_Imm16_X0, 885 1.1 christos create_Imm16_X1, 886 1.1 christos create_Imm16_X0, 887 1.1 christos create_Imm16_X1, 888 1.1 christos create_Imm16_X0, 889 1.1 christos create_Imm16_X1, 890 1.1 christos create_Imm16_X0, 891 1.1 christos create_Imm16_X1, 892 1.1 christos 893 1.1 christos NULL, 894 1.1 christos NULL, 895 1.1 christos NULL, 896 1.1 christos 897 1.1 christos create_Imm16_X0, 898 1.1 christos create_Imm16_X1, 899 1.1 christos create_Imm16_X0, 900 1.1 christos create_Imm16_X1, 901 1.1 christos create_Imm16_X0, 902 1.1 christos create_Imm16_X1, 903 1.1 christos create_Imm16_X0, 904 1.1 christos create_Imm16_X1, 905 1.1 christos }; 906 1.1 christos 907 1.1 christos #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0]))) 908 1.1 christos 909 1.1 christos /* Support for core dump NOTE sections. */ 910 1.10 christos 911 1.1 christos static bool 912 1.1 christos tilepro_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 913 1.1 christos { 914 1.1 christos int offset; 915 1.1 christos size_t size; 916 1.1 christos 917 1.10 christos if (note->descsz != TILEPRO_PRSTATUS_SIZEOF) 918 1.1 christos return false; 919 1.1 christos 920 1.1 christos /* pr_cursig */ 921 1.1 christos elf_tdata (abfd)->core->signal = 922 1.1 christos bfd_get_16 (abfd, note->descdata + TILEPRO_PRSTATUS_OFFSET_PR_CURSIG); 923 1.1 christos 924 1.1 christos /* pr_pid */ 925 1.1 christos elf_tdata (abfd)->core->pid = 926 1.1 christos bfd_get_32 (abfd, note->descdata + TILEPRO_PRSTATUS_OFFSET_PR_PID); 927 1.1 christos 928 1.1 christos /* pr_reg */ 929 1.1 christos offset = TILEPRO_PRSTATUS_OFFSET_PR_REG; 930 1.1 christos size = TILEPRO_GREGSET_T_SIZE; 931 1.1 christos 932 1.1 christos /* Make a ".reg/999" section. */ 933 1.1 christos return _bfd_elfcore_make_pseudosection (abfd, ".reg", 934 1.1 christos size, note->descpos + offset); 935 1.1 christos } 936 1.10 christos 937 1.1 christos static bool 938 1.1 christos tilepro_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 939 1.1 christos { 940 1.10 christos if (note->descsz != TILEPRO_PRPSINFO_SIZEOF) 941 1.1 christos return false; 942 1.1 christos 943 1.1 christos elf_tdata (abfd)->core->program 944 1.1 christos = _bfd_elfcore_strndup (abfd, 945 1.1 christos note->descdata + TILEPRO_PRPSINFO_OFFSET_PR_FNAME, 946 1.1 christos 16); 947 1.1 christos elf_tdata (abfd)->core->command 948 1.1 christos = _bfd_elfcore_strndup (abfd, 949 1.1 christos note->descdata + TILEPRO_PRPSINFO_OFFSET_PR_PSARGS, 950 1.1 christos ELF_PR_PSARGS_SIZE); 951 1.1 christos 952 1.1 christos 953 1.1 christos /* Note that for some reason, a spurious space is tacked 954 1.1 christos onto the end of the args in some (at least one anyway) 955 1.1 christos implementations, so strip it off if it exists. */ 956 1.1 christos { 957 1.1 christos char *command = elf_tdata (abfd)->core->command; 958 1.1 christos int n = strlen (command); 959 1.1 christos 960 1.1 christos if (0 < n && command[n - 1] == ' ') 961 1.1 christos command[n - 1] = '\0'; 962 1.1 christos } 963 1.10 christos 964 1.1 christos return true; 965 1.1 christos } 966 1.1 christos 967 1.1 christos 968 1.1 christos static void 969 1.1 christos tilepro_elf_append_rela_32 (bfd *abfd, asection *s, Elf_Internal_Rela *rel) 970 1.1 christos { 971 1.1 christos Elf32_External_Rela *loc32; 972 1.1 christos 973 1.1 christos loc32 = (Elf32_External_Rela *) s->contents; 974 1.1 christos loc32 += s->reloc_count++; 975 1.1 christos bfd_elf32_swap_reloca_out (abfd, rel, (bfd_byte *) loc32); 976 1.1 christos } 977 1.1 christos 978 1.1 christos /* PLT/GOT stuff */ 979 1.1 christos 980 1.1 christos /* The procedure linkage table starts with the following header: 981 1.1 christos 982 1.8 christos { 983 1.1 christos rli r29, r29, 16 984 1.1 christos lwadd r28, r27, 4 985 1.8 christos } 986 1.1 christos lw r27, r27 987 1.8 christos { 988 1.8 christos info 10 ## SP not offset, return PC in LR 989 1.1 christos jr r27 990 1.1 christos } 991 1.1 christos 992 1.1 christos Subsequent entries are the following, jumping to the header at the end: 993 1.8 christos 994 1.1 christos lnk r28 995 1.1 christos 1: 996 1.1 christos { 997 1.1 christos auli r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET> 998 1.1 christos auli r27, r28, <_GLOBAL_OFFSET_TABLE_ - 1b> 999 1.1 christos } 1000 1.1 christos { 1001 1.1 christos addli r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET> 1002 1.1 christos addli r27, r27, <_GLOBAL_OFFSET_TABLE_ - 1b> 1003 1.1 christos } 1004 1.1 christos { 1005 1.8 christos auli r29, zero, MY_PLT_INDEX 1006 1.1 christos lw r28, r28 1007 1.1 christos } 1008 1.8 christos { 1009 1.8 christos info 10 ## SP not offset, return PC in LR 1010 1.1 christos jr r28 1011 1.1 christos } 1012 1.1 christos 1013 1.1 christos We initially store MY_PLT_INDEX in the high bits so that we can use the all 1014 1.1 christos 16 bits as an unsigned offset; if we use the low bits we would get an 1015 1.1 christos unwanted sign extension. The PLT header then rotates the index to get the 1016 1.1 christos right value, before calling the resolution routine. This computation can 1017 1.1 christos fit in unused bundle slots so it's free. 1018 1.1 christos 1019 1.1 christos This code sequence lets the code at at the start of the PLT determine 1020 1.1 christos which PLT entry was executed by examining 'r29'. 1021 1.1 christos 1022 1.1 christos Note that MY_PLT_INDEX skips over the header entries, so the first 1023 1.1 christos actual jump table entry has index zero. 1024 1.1 christos */ 1025 1.1 christos 1026 1.1 christos #define PLT_HEADER_SIZE_IN_BUNDLES 3 1027 1.1 christos #define PLT_ENTRY_SIZE_IN_BUNDLES 5 1028 1.1 christos 1029 1.1 christos #define PLT_HEADER_SIZE \ 1030 1.1 christos (PLT_HEADER_SIZE_IN_BUNDLES * TILEPRO_BUNDLE_SIZE_IN_BYTES) 1031 1.1 christos #define PLT_ENTRY_SIZE \ 1032 1.1 christos (PLT_ENTRY_SIZE_IN_BUNDLES * TILEPRO_BUNDLE_SIZE_IN_BYTES) 1033 1.1 christos 1034 1.1 christos /* The size in bytes of an entry in the global offset table. */ 1035 1.1 christos 1036 1.1 christos #define GOT_ENTRY_SIZE TILEPRO_BYTES_PER_WORD 1037 1.1 christos 1038 1.1 christos #define GOTPLT_HEADER_SIZE (2 * GOT_ENTRY_SIZE) 1039 1.1 christos 1040 1.1 christos 1041 1.1 christos static const bfd_byte 1042 1.1 christos tilepro_plt0_entry[PLT_HEADER_SIZE] = 1043 1.1 christos { 1044 1.1 christos 0x5d, 0x07, 0x03, 0x70, 1045 1.1 christos 0x6e, 0x23, 0xd0, 0x30, /* { rli r29, r29, 16 ; lwadd r28, r27, 4 } */ 1046 1.1 christos 0x00, 0x50, 0xba, 0x6d, 1047 1.1 christos 0x00, 0x08, 0x6d, 0xdc, /* { lw r27, r27 } */ 1048 1.1 christos 0xff, 0xaf, 0x10, 0x50, 1049 1.1 christos 0x60, 0x03, 0x18, 0x08, /* { info 10 ; jr r27 } */ 1050 1.1 christos }; 1051 1.1 christos 1052 1.1 christos static const bfd_byte 1053 1.1 christos tilepro_short_plt_entry[PLT_ENTRY_SIZE] = 1054 1.1 christos { 1055 1.1 christos 0x00, 0x50, 0x16, 0x70, 1056 1.1 christos 0x0e, 0x00, 0x1a, 0x08, /* { lnk r28 } */ 1057 1.1 christos 0x1c, 0x07, 0x00, 0xa0, 1058 1.1 christos 0x8d, 0x03, 0x00, 0x18, /* { addli r28, r28, 0 ; addli r27, r28, 0 } */ 1059 1.1 christos 0xdd, 0x0f, 0x00, 0x30, 1060 1.1 christos 0x8e, 0x73, 0x0b, 0x40, /* { auli r29, zero, 0 ; lw r28, r28 } */ 1061 1.1 christos 0xff, 0xaf, 0x10, 0x50, 1062 1.1 christos 0x80, 0x03, 0x18, 0x08, /* { info 10 ; jr r28 } */ 1063 1.1 christos 0x00, 0x00, 0x00, 0x00, 1064 1.1 christos 0x00, 0x00, 0x00, 0x00, 1065 1.1 christos }; 1066 1.1 christos 1067 1.1 christos static const bfd_byte 1068 1.1 christos tilepro_long_plt_entry[PLT_ENTRY_SIZE] = 1069 1.1 christos { 1070 1.1 christos 0x00, 0x50, 0x16, 0x70, 1071 1.1 christos 0x0e, 0x00, 0x1a, 0x08, /* { lnk r28 } */ 1072 1.1 christos 0x1c, 0x07, 0x00, 0xb0, 1073 1.1 christos 0x8d, 0x03, 0x00, 0x20, /* { auli r28, r28, 0 ; auli r27, r28, 0 } */ 1074 1.1 christos 0x1c, 0x07, 0x00, 0xa0, 1075 1.1 christos 0x6d, 0x03, 0x00, 0x18, /* { addli r28, r28, 0 ; addli r27, r27, 0 } */ 1076 1.1 christos 0xdd, 0x0f, 0x00, 0x30, 1077 1.1 christos 0x8e, 0x73, 0x0b, 0x40, /* { auli r29, zero, 0 ; lw r28, r28 } */ 1078 1.1 christos 0xff, 0xaf, 0x10, 0x50, 1079 1.1 christos 0x80, 0x03, 0x18, 0x08, /* { info 10 ; jr r28 } */ 1080 1.1 christos }; 1081 1.1 christos 1082 1.1 christos static bfd_vma 1083 1.1 christos tilepro_ha16(bfd_vma vma) 1084 1.1 christos { 1085 1.1 christos return ((vma >> 16) + ((vma >> 15) & 1)) & 0xffff; 1086 1.1 christos } 1087 1.1 christos 1088 1.1 christos static int 1089 1.1 christos tilepro_plt_entry_build (asection *splt, asection *sgotplt, bfd_vma offset, 1090 1.1 christos bfd_vma *r_offset) 1091 1.1 christos { 1092 1.1 christos int plt_index = (offset - PLT_ENTRY_SIZE) / PLT_ENTRY_SIZE; 1093 1.1 christos int got_offset = plt_index * GOT_ENTRY_SIZE + GOTPLT_HEADER_SIZE; 1094 1.1 christos tilepro_bundle_bits *pc; 1095 1.1 christos 1096 1.1 christos /* Compute the distance from the got entry to the lnk. */ 1097 1.1 christos bfd_signed_vma dist_got_entry = sgotplt->output_section->vma 1098 1.1 christos + sgotplt->output_offset 1099 1.1 christos + got_offset 1100 1.1 christos - splt->output_section->vma 1101 1.1 christos - splt->output_offset 1102 1.1 christos - offset 1103 1.1 christos - TILEPRO_BUNDLE_SIZE_IN_BYTES; 1104 1.1 christos 1105 1.1 christos /* Compute the distance to GOTPLT[0]. */ 1106 1.1 christos bfd_signed_vma dist_got0 = dist_got_entry - got_offset; 1107 1.1 christos 1108 1.10 christos /* Check whether we can use the short plt entry with 16-bit offset. */ 1109 1.1 christos bool short_plt_entry = 1110 1.1 christos (dist_got_entry <= 0x7fff && dist_got0 >= -0x8000); 1111 1.1 christos 1112 1.1 christos /* Copy the plt entry template. */ 1113 1.1 christos memcpy (splt->contents + offset, 1114 1.1 christos short_plt_entry ? tilepro_short_plt_entry : tilepro_long_plt_entry, 1115 1.1 christos PLT_ENTRY_SIZE); 1116 1.1 christos 1117 1.1 christos /* Write the immediate offsets. */ 1118 1.1 christos pc = (tilepro_bundle_bits *)(splt->contents + offset); 1119 1.1 christos pc++; 1120 1.1 christos 1121 1.1 christos if (!short_plt_entry) 1122 1.1 christos { 1123 1.1 christos /* { auli r28, r28, &GOTPLT[MY_GOT_INDEX] ; auli r27, r28, &GOTPLT[0] } */ 1124 1.1 christos *pc++ |= create_Imm16_X0 (tilepro_ha16 (dist_got_entry)) 1125 1.1 christos | create_Imm16_X1 (tilepro_ha16 (dist_got0)); 1126 1.1 christos } 1127 1.1 christos 1128 1.1 christos /* { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; addli r27, r28, &GOTPLT[0] } or 1129 1.1 christos { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; addli r27, r27, &GOTPLT[0] } */ 1130 1.1 christos *pc++ |= create_Imm16_X0 (dist_got_entry) 1131 1.1 christos | create_Imm16_X1 (dist_got0); 1132 1.1 christos 1133 1.1 christos /* { auli r29, zero, MY_PLT_INDEX ; lw r28, r28 } */ 1134 1.1 christos *pc |= create_Imm16_X0 (plt_index); 1135 1.1 christos 1136 1.1 christos /* Set the relocation offset. */ 1137 1.1 christos *r_offset = got_offset; 1138 1.1 christos 1139 1.1 christos return plt_index; 1140 1.1 christos } 1141 1.1 christos 1142 1.1 christos #define TILEPRO_ELF_RELA_BYTES (sizeof(Elf32_External_Rela)) 1143 1.1 christos 1144 1.1 christos 1145 1.1 christos /* Create an entry in an TILEPro ELF linker hash table. */ 1146 1.1 christos 1147 1.1 christos static struct bfd_hash_entry * 1148 1.1 christos link_hash_newfunc (struct bfd_hash_entry *entry, 1149 1.1 christos struct bfd_hash_table *table, const char *string) 1150 1.1 christos { 1151 1.1 christos /* Allocate the structure if it has not already been allocated by a 1152 1.1 christos subclass. */ 1153 1.1 christos if (entry == NULL) 1154 1.1 christos { 1155 1.8 christos entry = 1156 1.8 christos bfd_hash_allocate (table, 1157 1.1 christos sizeof (struct tilepro_elf_link_hash_entry)); 1158 1.1 christos if (entry == NULL) 1159 1.1 christos return entry; 1160 1.1 christos } 1161 1.1 christos 1162 1.1 christos /* Call the allocation method of the superclass. */ 1163 1.1 christos entry = _bfd_elf_link_hash_newfunc (entry, table, string); 1164 1.1 christos if (entry != NULL) 1165 1.1 christos { 1166 1.1 christos struct tilepro_elf_link_hash_entry *eh; 1167 1.1 christos 1168 1.1 christos eh = (struct tilepro_elf_link_hash_entry *) entry; 1169 1.1 christos eh->tls_type = GOT_UNKNOWN; 1170 1.1 christos } 1171 1.1 christos 1172 1.1 christos return entry; 1173 1.1 christos } 1174 1.1 christos 1175 1.1 christos /* Create a TILEPRO ELF linker hash table. */ 1176 1.1 christos 1177 1.1 christos static struct bfd_link_hash_table * 1178 1.1 christos tilepro_elf_link_hash_table_create (bfd *abfd) 1179 1.9 christos { 1180 1.9 christos struct elf_link_hash_table *ret; 1181 1.1 christos size_t amt = sizeof (struct elf_link_hash_table); 1182 1.9 christos 1183 1.1 christos ret = (struct elf_link_hash_table *) bfd_zmalloc (amt); 1184 1.1 christos if (ret == NULL) 1185 1.1 christos return NULL; 1186 1.9 christos 1187 1.1 christos if (!_bfd_elf_link_hash_table_init (ret, abfd, link_hash_newfunc, 1188 1.1 christos sizeof (struct tilepro_elf_link_hash_entry), 1189 1.1 christos TILEPRO_ELF_DATA)) 1190 1.1 christos { 1191 1.1 christos free (ret); 1192 1.1 christos return NULL; 1193 1.1 christos } 1194 1.9 christos 1195 1.1 christos return &ret->root; 1196 1.1 christos } 1197 1.1 christos 1198 1.1 christos /* Create the .got section. */ 1199 1.10 christos 1200 1.1 christos static bool 1201 1.1 christos tilepro_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) 1202 1.1 christos { 1203 1.1 christos flagword flags; 1204 1.1 christos asection *s, *s_got; 1205 1.1 christos struct elf_link_hash_entry *h; 1206 1.1 christos const struct elf_backend_data *bed = get_elf_backend_data (abfd); 1207 1.1 christos struct elf_link_hash_table *htab = elf_hash_table (info); 1208 1.1 christos 1209 1.7 christos /* This function may be called more than once. */ 1210 1.10 christos if (htab->sgot != NULL) 1211 1.1 christos return true; 1212 1.1 christos 1213 1.1 christos flags = bed->dynamic_sec_flags; 1214 1.1 christos 1215 1.1 christos s = bfd_make_section_with_flags (abfd, 1216 1.1 christos (bed->rela_plts_and_copies_p 1217 1.1 christos ? ".rela.got" : ".rel.got"), 1218 1.1 christos (bed->dynamic_sec_flags 1219 1.1 christos | SEC_READONLY)); 1220 1.9 christos if (s == NULL 1221 1.10 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 1222 1.1 christos return false; 1223 1.1 christos htab->srelgot = s; 1224 1.1 christos 1225 1.1 christos s = s_got = bfd_make_section_with_flags (abfd, ".got", flags); 1226 1.9 christos if (s == NULL 1227 1.10 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 1228 1.1 christos return false; 1229 1.1 christos htab->sgot = s; 1230 1.1 christos 1231 1.1 christos /* The first bit of the global offset table is the header. */ 1232 1.1 christos s->size += bed->got_header_size; 1233 1.1 christos 1234 1.1 christos if (bed->want_got_plt) 1235 1.1 christos { 1236 1.1 christos s = bfd_make_section_with_flags (abfd, ".got.plt", flags); 1237 1.9 christos if (s == NULL 1238 1.10 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 1239 1.1 christos return false; 1240 1.1 christos htab->sgotplt = s; 1241 1.1 christos 1242 1.1 christos /* Reserve room for the header. */ 1243 1.1 christos s->size += GOTPLT_HEADER_SIZE; 1244 1.1 christos } 1245 1.1 christos 1246 1.1 christos if (bed->want_got_sym) 1247 1.1 christos { 1248 1.1 christos /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got 1249 1.1 christos section. We don't do this in the linker script because we don't want 1250 1.1 christos to define the symbol if we are not creating a global offset 1251 1.1 christos table. */ 1252 1.1 christos h = _bfd_elf_define_linkage_sym (abfd, info, s_got, 1253 1.1 christos "_GLOBAL_OFFSET_TABLE_"); 1254 1.1 christos elf_hash_table (info)->hgot = h; 1255 1.10 christos if (h == NULL) 1256 1.1 christos return false; 1257 1.1 christos } 1258 1.10 christos 1259 1.1 christos return true; 1260 1.1 christos } 1261 1.1 christos 1262 1.1 christos /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and 1263 1.1 christos .rela.bss sections in DYNOBJ, and set up shortcuts to them in our 1264 1.1 christos hash table. */ 1265 1.10 christos 1266 1.1 christos static bool 1267 1.1 christos tilepro_elf_create_dynamic_sections (bfd *dynobj, 1268 1.1 christos struct bfd_link_info *info) 1269 1.1 christos { 1270 1.10 christos if (!tilepro_elf_create_got_section (dynobj, info)) 1271 1.1 christos return false; 1272 1.7 christos 1273 1.1 christos return _bfd_elf_create_dynamic_sections (dynobj, info); 1274 1.1 christos } 1275 1.1 christos 1276 1.1 christos /* Copy the extra info we tack onto an elf_link_hash_entry. */ 1277 1.1 christos 1278 1.1 christos static void 1279 1.1 christos tilepro_elf_copy_indirect_symbol (struct bfd_link_info *info, 1280 1.1 christos struct elf_link_hash_entry *dir, 1281 1.1 christos struct elf_link_hash_entry *ind) 1282 1.1 christos { 1283 1.1 christos struct tilepro_elf_link_hash_entry *edir, *eind; 1284 1.1 christos 1285 1.1 christos edir = (struct tilepro_elf_link_hash_entry *) dir; 1286 1.1 christos eind = (struct tilepro_elf_link_hash_entry *) ind; 1287 1.1 christos 1288 1.1 christos if (ind->root.type == bfd_link_hash_indirect 1289 1.1 christos && dir->got.refcount <= 0) 1290 1.1 christos { 1291 1.1 christos edir->tls_type = eind->tls_type; 1292 1.1 christos eind->tls_type = GOT_UNKNOWN; 1293 1.1 christos } 1294 1.1 christos _bfd_elf_link_hash_copy_indirect (info, dir, ind); 1295 1.1 christos } 1296 1.1 christos 1297 1.1 christos static int 1298 1.1 christos tilepro_tls_translate_to_le (int r_type) 1299 1.1 christos { 1300 1.1 christos switch (r_type) 1301 1.1 christos { 1302 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD: 1303 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE: 1304 1.1 christos return R_TILEPRO_IMM16_X0_TLS_LE; 1305 1.1 christos 1306 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD: 1307 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE: 1308 1.1 christos return R_TILEPRO_IMM16_X1_TLS_LE; 1309 1.1 christos 1310 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_LO: 1311 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_LO: 1312 1.1 christos return R_TILEPRO_IMM16_X0_TLS_LE_LO; 1313 1.1 christos 1314 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_LO: 1315 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_LO: 1316 1.1 christos return R_TILEPRO_IMM16_X1_TLS_LE_LO; 1317 1.1 christos 1318 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HI: 1319 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_HI: 1320 1.1 christos return R_TILEPRO_IMM16_X0_TLS_LE_HI; 1321 1.1 christos 1322 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_HI: 1323 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HI: 1324 1.1 christos return R_TILEPRO_IMM16_X1_TLS_LE_HI; 1325 1.1 christos 1326 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 1327 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 1328 1.1 christos return R_TILEPRO_IMM16_X0_TLS_LE_HA; 1329 1.1 christos 1330 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 1331 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 1332 1.1 christos return R_TILEPRO_IMM16_X1_TLS_LE_HA; 1333 1.1 christos } 1334 1.1 christos return r_type; 1335 1.1 christos } 1336 1.1 christos 1337 1.1 christos static int 1338 1.1 christos tilepro_tls_translate_to_ie (int r_type) 1339 1.1 christos { 1340 1.1 christos switch (r_type) 1341 1.1 christos { 1342 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD: 1343 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE: 1344 1.1 christos return R_TILEPRO_IMM16_X0_TLS_IE; 1345 1.1 christos 1346 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD: 1347 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE: 1348 1.1 christos return R_TILEPRO_IMM16_X1_TLS_IE; 1349 1.1 christos 1350 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_LO: 1351 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_LO: 1352 1.1 christos return R_TILEPRO_IMM16_X0_TLS_IE_LO; 1353 1.1 christos 1354 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_LO: 1355 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_LO: 1356 1.1 christos return R_TILEPRO_IMM16_X1_TLS_IE_LO; 1357 1.1 christos 1358 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HI: 1359 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_HI: 1360 1.1 christos return R_TILEPRO_IMM16_X0_TLS_IE_HI; 1361 1.1 christos 1362 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_HI: 1363 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HI: 1364 1.1 christos return R_TILEPRO_IMM16_X1_TLS_IE_HI; 1365 1.1 christos 1366 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 1367 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 1368 1.1 christos return R_TILEPRO_IMM16_X0_TLS_IE_HA; 1369 1.1 christos 1370 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 1371 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 1372 1.1 christos return R_TILEPRO_IMM16_X1_TLS_IE_HA; 1373 1.1 christos } 1374 1.1 christos return r_type; 1375 1.1 christos } 1376 1.1 christos 1377 1.1 christos static int 1378 1.1 christos tilepro_elf_tls_transition (struct bfd_link_info *info, int r_type, 1379 1.1 christos int is_local) 1380 1.8 christos { 1381 1.1 christos if (!bfd_link_executable (info)) 1382 1.1 christos return r_type; 1383 1.1 christos 1384 1.1 christos if (is_local) 1385 1.1 christos return tilepro_tls_translate_to_le (r_type); 1386 1.1 christos else 1387 1.1 christos return tilepro_tls_translate_to_ie (r_type); 1388 1.1 christos } 1389 1.1 christos 1390 1.1 christos /* Look through the relocs for a section during the first phase, and 1391 1.1 christos allocate space in the global offset table or procedure linkage 1392 1.1 christos table. */ 1393 1.10 christos 1394 1.1 christos static bool 1395 1.1 christos tilepro_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, 1396 1.1 christos asection *sec, const Elf_Internal_Rela *relocs) 1397 1.9 christos { 1398 1.1 christos struct elf_link_hash_table *htab; 1399 1.1 christos Elf_Internal_Shdr *symtab_hdr; 1400 1.1 christos struct elf_link_hash_entry **sym_hashes; 1401 1.1 christos const Elf_Internal_Rela *rel; 1402 1.1 christos const Elf_Internal_Rela *rel_end; 1403 1.1 christos asection *sreloc; 1404 1.1 christos int num_relocs; 1405 1.6 christos 1406 1.10 christos if (bfd_link_relocatable (info)) 1407 1.1 christos return true; 1408 1.1 christos 1409 1.1 christos htab = tilepro_elf_hash_table (info); 1410 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1411 1.1 christos sym_hashes = elf_sym_hashes (abfd); 1412 1.1 christos 1413 1.1 christos sreloc = NULL; 1414 1.1 christos 1415 1.1 christos num_relocs = sec->reloc_count; 1416 1.1 christos 1417 1.1 christos BFD_ASSERT (is_tilepro_elf (abfd) || num_relocs == 0); 1418 1.9 christos 1419 1.9 christos if (htab->dynobj == NULL) 1420 1.1 christos htab->dynobj = abfd; 1421 1.1 christos 1422 1.1 christos rel_end = relocs + num_relocs; 1423 1.1 christos for (rel = relocs; rel < rel_end; rel++) 1424 1.1 christos { 1425 1.8 christos unsigned int r_type; 1426 1.1 christos unsigned int r_symndx; 1427 1.1 christos struct elf_link_hash_entry *h; 1428 1.1 christos int tls_type; 1429 1.1 christos 1430 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 1431 1.1 christos r_type = ELF32_R_TYPE (rel->r_info); 1432 1.1 christos 1433 1.1 christos if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) 1434 1.7 christos { 1435 1.8 christos /* xgettext:c-format */ 1436 1.7 christos _bfd_error_handler (_("%pB: bad symbol index: %d"), 1437 1.10 christos abfd, r_symndx); 1438 1.1 christos return false; 1439 1.1 christos } 1440 1.1 christos 1441 1.1 christos if (r_symndx < symtab_hdr->sh_info) 1442 1.1 christos h = NULL; 1443 1.1 christos else 1444 1.1 christos { 1445 1.1 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1446 1.1 christos while (h->root.type == bfd_link_hash_indirect 1447 1.1 christos || h->root.type == bfd_link_hash_warning) 1448 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 1449 1.1 christos } 1450 1.1 christos 1451 1.1 christos r_type = tilepro_elf_tls_transition (info, r_type, h == NULL); 1452 1.1 christos switch (r_type) 1453 1.8 christos { 1454 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE: 1455 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE: 1456 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE_LO: 1457 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE_LO: 1458 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE_HI: 1459 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE_HI: 1460 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE_HA: 1461 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE_HA: 1462 1.1 christos if (!bfd_link_executable (info)) 1463 1.1 christos goto r_tilepro_plt32; 1464 1.1 christos break; 1465 1.8 christos 1466 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD: 1467 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD: 1468 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD_LO: 1469 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD_LO: 1470 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD_HI: 1471 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD_HI: 1472 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 1473 1.6 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 1474 1.1 christos BFD_ASSERT (bfd_link_pic (info)); 1475 1.8 christos tls_type = GOT_TLS_GD; 1476 1.1 christos goto have_got_reference; 1477 1.8 christos 1478 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE: 1479 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE: 1480 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_LO: 1481 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE_LO: 1482 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_HI: 1483 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE_HI: 1484 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 1485 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 1486 1.8 christos tls_type = GOT_TLS_IE; 1487 1.8 christos if (!bfd_link_executable (info)) 1488 1.8 christos info->flags |= DF_STATIC_TLS; 1489 1.8 christos goto have_got_reference; 1490 1.8 christos 1491 1.8 christos case R_TILEPRO_IMM16_X0_GOT: 1492 1.8 christos case R_TILEPRO_IMM16_X1_GOT: 1493 1.8 christos case R_TILEPRO_IMM16_X0_GOT_LO: 1494 1.8 christos case R_TILEPRO_IMM16_X1_GOT_LO: 1495 1.8 christos case R_TILEPRO_IMM16_X0_GOT_HI: 1496 1.8 christos case R_TILEPRO_IMM16_X1_GOT_HI: 1497 1.8 christos case R_TILEPRO_IMM16_X0_GOT_HA: 1498 1.8 christos case R_TILEPRO_IMM16_X1_GOT_HA: 1499 1.8 christos tls_type = GOT_NORMAL; 1500 1.1 christos /* Fall Through */ 1501 1.8 christos 1502 1.1 christos have_got_reference: 1503 1.1 christos /* This symbol requires a global offset table entry. */ 1504 1.8 christos { 1505 1.1 christos int old_tls_type; 1506 1.1 christos 1507 1.1 christos if (h != NULL) 1508 1.1 christos { 1509 1.1 christos h->got.refcount += 1; 1510 1.1 christos old_tls_type = tilepro_elf_hash_entry(h)->tls_type; 1511 1.1 christos } 1512 1.1 christos else 1513 1.1 christos { 1514 1.1 christos bfd_signed_vma *local_got_refcounts; 1515 1.1 christos 1516 1.1 christos /* This is a global offset table entry for a local symbol. */ 1517 1.1 christos local_got_refcounts = elf_local_got_refcounts (abfd); 1518 1.1 christos if (local_got_refcounts == NULL) 1519 1.1 christos { 1520 1.1 christos bfd_size_type size; 1521 1.1 christos 1522 1.1 christos size = symtab_hdr->sh_info; 1523 1.1 christos size *= (sizeof (bfd_signed_vma) + sizeof(char)); 1524 1.1 christos local_got_refcounts = ((bfd_signed_vma *) 1525 1.1 christos bfd_zalloc (abfd, size)); 1526 1.10 christos if (local_got_refcounts == NULL) 1527 1.1 christos return false; 1528 1.1 christos elf_local_got_refcounts (abfd) = local_got_refcounts; 1529 1.1 christos _bfd_tilepro_elf_local_got_tls_type (abfd) 1530 1.1 christos = (char *) (local_got_refcounts + symtab_hdr->sh_info); 1531 1.1 christos } 1532 1.1 christos local_got_refcounts[r_symndx] += 1; 1533 1.1 christos old_tls_type = 1534 1.1 christos _bfd_tilepro_elf_local_got_tls_type (abfd) [r_symndx]; 1535 1.1 christos } 1536 1.1 christos 1537 1.1 christos /* If a TLS symbol is accessed using IE at least once, 1538 1.1 christos there is no point to use dynamic model for it. */ 1539 1.1 christos if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN 1540 1.1 christos && (old_tls_type != GOT_TLS_GD 1541 1.1 christos || tls_type != GOT_TLS_IE)) 1542 1.1 christos { 1543 1.1 christos if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD) 1544 1.1 christos tls_type = old_tls_type; 1545 1.1 christos else 1546 1.7 christos { 1547 1.7 christos _bfd_error_handler 1548 1.8 christos /* xgettext:c-format */ 1549 1.1 christos (_("%pB: `%s' accessed both as normal and thread local symbol"), 1550 1.10 christos abfd, h ? h->root.root.string : "<local>"); 1551 1.1 christos return false; 1552 1.1 christos } 1553 1.1 christos } 1554 1.1 christos 1555 1.1 christos if (old_tls_type != tls_type) 1556 1.1 christos { 1557 1.1 christos if (h != NULL) 1558 1.1 christos tilepro_elf_hash_entry (h)->tls_type = tls_type; 1559 1.1 christos else 1560 1.1 christos _bfd_tilepro_elf_local_got_tls_type (abfd) [r_symndx] = 1561 1.1 christos tls_type; 1562 1.1 christos } 1563 1.1 christos } 1564 1.9 christos 1565 1.1 christos if (htab->sgot == NULL) 1566 1.9 christos { 1567 1.10 christos if (!tilepro_elf_create_got_section (htab->dynobj, info)) 1568 1.1 christos return false; 1569 1.1 christos } 1570 1.1 christos break; 1571 1.1 christos 1572 1.8 christos case R_TILEPRO_TLS_GD_CALL: 1573 1.1 christos if (!bfd_link_executable (info)) 1574 1.1 christos { 1575 1.1 christos /* These are basically R_TILEPRO_JOFFLONG_X1_PLT relocs 1576 1.1 christos against __tls_get_addr. */ 1577 1.1 christos struct bfd_link_hash_entry *bh = NULL; 1578 1.1 christos if (! _bfd_generic_link_add_one_symbol (info, abfd, 1579 1.1 christos "__tls_get_addr", 0, 1580 1.10 christos bfd_und_section_ptr, 0, 1581 1.1 christos NULL, false, false, 1582 1.10 christos &bh)) 1583 1.1 christos return false; 1584 1.1 christos h = (struct elf_link_hash_entry *) bh; 1585 1.1 christos } 1586 1.1 christos else 1587 1.1 christos break; 1588 1.1 christos /* Fall through */ 1589 1.8 christos 1590 1.1 christos case R_TILEPRO_JOFFLONG_X1_PLT: 1591 1.1 christos /* This symbol requires a procedure linkage table entry. We 1592 1.1 christos actually build the entry in adjust_dynamic_symbol, 1593 1.1 christos because this might be a case of linking PIC code without 1594 1.1 christos linking in any dynamic objects, in which case we don't 1595 1.1 christos need to generate a procedure linkage table after all. */ 1596 1.1 christos 1597 1.8 christos if (h != NULL) 1598 1.8 christos { 1599 1.8 christos h->needs_plt = 1; 1600 1.8 christos h->plt.refcount += 1; 1601 1.1 christos } 1602 1.1 christos break; 1603 1.8 christos 1604 1.8 christos case R_TILEPRO_32_PCREL: 1605 1.8 christos case R_TILEPRO_16_PCREL: 1606 1.8 christos case R_TILEPRO_8_PCREL: 1607 1.8 christos case R_TILEPRO_IMM16_X0_PCREL: 1608 1.8 christos case R_TILEPRO_IMM16_X1_PCREL: 1609 1.8 christos case R_TILEPRO_IMM16_X0_LO_PCREL: 1610 1.8 christos case R_TILEPRO_IMM16_X1_LO_PCREL: 1611 1.8 christos case R_TILEPRO_IMM16_X0_HI_PCREL: 1612 1.8 christos case R_TILEPRO_IMM16_X1_HI_PCREL: 1613 1.8 christos case R_TILEPRO_IMM16_X0_HA_PCREL: 1614 1.1 christos case R_TILEPRO_IMM16_X1_HA_PCREL: 1615 1.1 christos if (h != NULL) 1616 1.1 christos h->non_got_ref = 1; 1617 1.1 christos 1618 1.1 christos if (h != NULL 1619 1.1 christos && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 1620 1.1 christos break; 1621 1.1 christos /* Fall through. */ 1622 1.8 christos 1623 1.8 christos case R_TILEPRO_32: 1624 1.8 christos case R_TILEPRO_16: 1625 1.8 christos case R_TILEPRO_8: 1626 1.8 christos case R_TILEPRO_LO16: 1627 1.8 christos case R_TILEPRO_HI16: 1628 1.8 christos case R_TILEPRO_HA16: 1629 1.8 christos case R_TILEPRO_COPY: 1630 1.8 christos case R_TILEPRO_GLOB_DAT: 1631 1.8 christos case R_TILEPRO_JMP_SLOT: 1632 1.8 christos case R_TILEPRO_RELATIVE: 1633 1.8 christos case R_TILEPRO_BROFF_X1: 1634 1.8 christos case R_TILEPRO_JOFFLONG_X1: 1635 1.8 christos case R_TILEPRO_IMM8_X0: 1636 1.8 christos case R_TILEPRO_IMM8_Y0: 1637 1.8 christos case R_TILEPRO_IMM8_X1: 1638 1.8 christos case R_TILEPRO_IMM8_Y1: 1639 1.8 christos case R_TILEPRO_DEST_IMM8_X1: 1640 1.8 christos case R_TILEPRO_MT_IMM15_X1: 1641 1.8 christos case R_TILEPRO_MF_IMM15_X1: 1642 1.8 christos case R_TILEPRO_IMM16_X0: 1643 1.8 christos case R_TILEPRO_IMM16_X1: 1644 1.8 christos case R_TILEPRO_IMM16_X0_LO: 1645 1.8 christos case R_TILEPRO_IMM16_X1_LO: 1646 1.8 christos case R_TILEPRO_IMM16_X0_HI: 1647 1.8 christos case R_TILEPRO_IMM16_X1_HI: 1648 1.8 christos case R_TILEPRO_IMM16_X0_HA: 1649 1.8 christos case R_TILEPRO_IMM16_X1_HA: 1650 1.8 christos case R_TILEPRO_MMSTART_X0: 1651 1.8 christos case R_TILEPRO_MMEND_X0: 1652 1.8 christos case R_TILEPRO_MMSTART_X1: 1653 1.8 christos case R_TILEPRO_MMEND_X1: 1654 1.8 christos case R_TILEPRO_SHAMT_X0: 1655 1.8 christos case R_TILEPRO_SHAMT_X1: 1656 1.8 christos case R_TILEPRO_SHAMT_Y0: 1657 1.1 christos case R_TILEPRO_SHAMT_Y1: 1658 1.8 christos if (h != NULL) 1659 1.1 christos h->non_got_ref = 1; 1660 1.1 christos 1661 1.6 christos r_tilepro_plt32: 1662 1.1 christos if (h != NULL && !bfd_link_pic (info)) 1663 1.1 christos { 1664 1.1 christos /* We may need a .plt entry if the function this reloc 1665 1.1 christos refers to is in a shared lib. */ 1666 1.8 christos h->plt.refcount += 1; 1667 1.1 christos } 1668 1.1 christos 1669 1.1 christos /* If we are creating a shared library, and this is a reloc 1670 1.1 christos against a global symbol, or a non PC relative reloc 1671 1.1 christos against a local symbol, then we need to copy the reloc 1672 1.1 christos into the shared library. However, if we are linking with 1673 1.1 christos -Bsymbolic, we do not need to copy a reloc against a 1674 1.1 christos global symbol which is defined in an object we are 1675 1.1 christos including in the link (i.e., DEF_REGULAR is set). At 1676 1.1 christos this point we have not seen all the input files, so it is 1677 1.1 christos possible that DEF_REGULAR is not set now but will be set 1678 1.1 christos later (it is never cleared). In case of a weak definition, 1679 1.1 christos DEF_REGULAR may be cleared later by a strong definition in 1680 1.1 christos a shared library. We account for that possibility below by 1681 1.1 christos storing information in the relocs_copied field of the hash 1682 1.1 christos table entry. A similar situation occurs when creating 1683 1.1 christos shared libraries and symbol visibility changes render the 1684 1.1 christos symbol local. 1685 1.1 christos 1686 1.1 christos If on the other hand, we are creating an executable, we 1687 1.1 christos may need to keep relocations for symbols satisfied by a 1688 1.1 christos dynamic library if we manage to avoid copy relocs for the 1689 1.6 christos symbol. */ 1690 1.1 christos if ((bfd_link_pic (info) 1691 1.1 christos && (sec->flags & SEC_ALLOC) != 0 1692 1.1 christos && (! tilepro_elf_howto_table[r_type].pc_relative 1693 1.1 christos || (h != NULL 1694 1.1 christos && (! info->symbolic 1695 1.1 christos || h->root.type == bfd_link_hash_defweak 1696 1.6 christos || !h->def_regular)))) 1697 1.1 christos || (!bfd_link_pic (info) 1698 1.1 christos && (sec->flags & SEC_ALLOC) != 0 1699 1.1 christos && h != NULL 1700 1.1 christos && (h->root.type == bfd_link_hash_defweak 1701 1.1 christos || !h->def_regular))) 1702 1.8 christos { 1703 1.8 christos struct elf_dyn_relocs *p; 1704 1.1 christos struct elf_dyn_relocs **head; 1705 1.1 christos 1706 1.1 christos /* When creating a shared object, we must copy these 1707 1.1 christos relocs into the output file. We create a reloc 1708 1.1 christos section in dynobj and make room for the reloc. */ 1709 1.1 christos if (sreloc == NULL) 1710 1.1 christos { 1711 1.10 christos sreloc = _bfd_elf_make_dynamic_reloc_section 1712 1.1 christos (sec, htab->dynobj, 2, abfd, /*rela?*/ true); 1713 1.1 christos 1714 1.10 christos if (sreloc == NULL) 1715 1.1 christos return false; 1716 1.1 christos } 1717 1.1 christos 1718 1.1 christos /* If this is a global symbol, we count the number of 1719 1.1 christos relocations we need for this symbol. */ 1720 1.9 christos if (h != NULL) 1721 1.1 christos head = &h->dyn_relocs; 1722 1.1 christos else 1723 1.1 christos { 1724 1.1 christos /* Track dynamic relocs needed for local syms too. 1725 1.1 christos We really need local syms available to do this 1726 1.1 christos easily. Oh well. */ 1727 1.1 christos 1728 1.1 christos asection *s; 1729 1.1 christos void *vpp; 1730 1.1 christos Elf_Internal_Sym *isym; 1731 1.1 christos 1732 1.1 christos isym = bfd_sym_from_r_symndx (&htab->sym_cache, 1733 1.1 christos abfd, r_symndx); 1734 1.10 christos if (isym == NULL) 1735 1.1 christos return false; 1736 1.1 christos 1737 1.1 christos s = bfd_section_from_elf_index (abfd, isym->st_shndx); 1738 1.1 christos if (s == NULL) 1739 1.1 christos s = sec; 1740 1.1 christos 1741 1.8 christos vpp = &elf_section_data (s)->local_dynrel; 1742 1.1 christos head = (struct elf_dyn_relocs **) vpp; 1743 1.1 christos } 1744 1.1 christos 1745 1.1 christos p = *head; 1746 1.1 christos if (p == NULL || p->sec != sec) 1747 1.9 christos { 1748 1.8 christos size_t amt = sizeof *p; 1749 1.9 christos p = ((struct elf_dyn_relocs *) 1750 1.1 christos bfd_alloc (htab->dynobj, amt)); 1751 1.10 christos if (p == NULL) 1752 1.1 christos return false; 1753 1.1 christos p->next = *head; 1754 1.1 christos *head = p; 1755 1.1 christos p->sec = sec; 1756 1.1 christos p->count = 0; 1757 1.1 christos p->pc_count = 0; 1758 1.1 christos } 1759 1.1 christos 1760 1.1 christos p->count += 1; 1761 1.1 christos if (tilepro_elf_howto_table[r_type].pc_relative) 1762 1.1 christos p->pc_count += 1; 1763 1.1 christos } 1764 1.1 christos 1765 1.1 christos break; 1766 1.1 christos 1767 1.1 christos case R_TILEPRO_GNU_VTINHERIT: 1768 1.10 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 1769 1.1 christos return false; 1770 1.1 christos break; 1771 1.1 christos 1772 1.1 christos case R_TILEPRO_GNU_VTENTRY: 1773 1.10 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 1774 1.1 christos return false; 1775 1.1 christos break; 1776 1.1 christos 1777 1.1 christos default: 1778 1.1 christos break; 1779 1.1 christos } 1780 1.1 christos } 1781 1.10 christos 1782 1.1 christos return true; 1783 1.1 christos } 1784 1.1 christos 1785 1.1 christos 1786 1.1 christos static asection * 1788 1.8 christos tilepro_elf_gc_mark_hook (asection *sec, 1789 1.8 christos struct bfd_link_info *info, 1790 1.8 christos Elf_Internal_Rela *rel, 1791 1.1 christos struct elf_link_hash_entry *h, 1792 1.1 christos Elf_Internal_Sym *sym) 1793 1.1 christos { 1794 1.1 christos if (h != NULL) 1795 1.1 christos { 1796 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 1797 1.1 christos { 1798 1.1 christos case R_TILEPRO_GNU_VTINHERIT: 1799 1.1 christos case R_TILEPRO_GNU_VTENTRY: 1800 1.1 christos return NULL; 1801 1.1 christos } 1802 1.1 christos } 1803 1.6 christos 1804 1.6 christos /* FIXME: The test here, in check_relocs and in relocate_section 1805 1.1 christos dealing with TLS optimization, ought to be !bfd_link_executable (info). */ 1806 1.8 christos if (bfd_link_pic (info)) 1807 1.8 christos { 1808 1.1 christos struct bfd_link_hash_entry *bh; 1809 1.1 christos 1810 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 1811 1.1 christos { 1812 1.1 christos case R_TILEPRO_TLS_GD_CALL: 1813 1.1 christos /* This reloc implicitly references __tls_get_addr. We know 1814 1.1 christos another reloc will reference the same symbol as the one 1815 1.1 christos on this reloc, so the real symbol and section will be 1816 1.8 christos gc marked when processing the other reloc. That lets 1817 1.8 christos us handle __tls_get_addr here. */ 1818 1.8 christos bh = NULL; 1819 1.8 christos if (! _bfd_generic_link_add_one_symbol (info, sec->owner, 1820 1.10 christos "__tls_get_addr", 0, 1821 1.10 christos bfd_und_section_ptr, 1822 1.8 christos 0, NULL, false, 1823 1.8 christos false, &bh)) 1824 1.1 christos return NULL; 1825 1.1 christos h = (struct elf_link_hash_entry *) bh; 1826 1.8 christos BFD_ASSERT (h != NULL); 1827 1.8 christos h->mark = 1; 1828 1.1 christos if (h->is_weakalias) 1829 1.1 christos weakdef (h)->mark = 1; 1830 1.1 christos sym = NULL; 1831 1.1 christos } 1832 1.1 christos } 1833 1.1 christos 1834 1.1 christos return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 1835 1.1 christos } 1836 1.1 christos 1837 1.1 christos /* Adjust a symbol defined by a dynamic object and referenced by a 1838 1.1 christos regular object. The current definition is in some section of the 1839 1.1 christos dynamic object, but we're not including those sections. We have to 1840 1.1 christos change the definition to something the rest of the link can 1841 1.10 christos understand. */ 1842 1.1 christos 1843 1.1 christos static bool 1844 1.1 christos tilepro_elf_adjust_dynamic_symbol (struct bfd_link_info *info, 1845 1.9 christos struct elf_link_hash_entry *h) 1846 1.7 christos { 1847 1.1 christos struct elf_link_hash_table *htab; 1848 1.1 christos asection *s, *srel; 1849 1.1 christos 1850 1.1 christos htab = tilepro_elf_hash_table (info); 1851 1.1 christos BFD_ASSERT (htab != NULL); 1852 1.9 christos 1853 1.1 christos /* Make sure we know what is going on here. */ 1854 1.8 christos BFD_ASSERT (htab->dynobj != NULL 1855 1.1 christos && (h->needs_plt 1856 1.1 christos || h->is_weakalias 1857 1.1 christos || (h->def_dynamic 1858 1.1 christos && h->ref_regular 1859 1.1 christos && !h->def_regular))); 1860 1.1 christos 1861 1.1 christos /* If this is a function, put it in the procedure linkage table. We 1862 1.1 christos will fill in the contents of the procedure linkage table later 1863 1.1 christos (although we could actually do it here). */ 1864 1.1 christos if (h->type == STT_FUNC || h->needs_plt) 1865 1.1 christos { 1866 1.1 christos if (h->plt.refcount <= 0 1867 1.1 christos || SYMBOL_CALLS_LOCAL (info, h) 1868 1.1 christos || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 1869 1.1 christos && h->root.type == bfd_link_hash_undefweak)) 1870 1.8 christos { 1871 1.8 christos /* This case can occur if we saw a R_TILEPRO_JOFFLONG_X1_PLT 1872 1.8 christos reloc in an input file, but the symbol was never referred 1873 1.8 christos to by a dynamic object, or if all references were garbage 1874 1.8 christos collected. In such a case, we don't actually need to build 1875 1.1 christos a procedure linkage table, and we can just do a 1876 1.1 christos R_TILEPRO_JOFFLONG_X1 relocation instead. */ 1877 1.1 christos h->plt.offset = (bfd_vma) -1; 1878 1.1 christos h->needs_plt = 0; 1879 1.10 christos } 1880 1.1 christos 1881 1.1 christos return true; 1882 1.1 christos } 1883 1.1 christos else 1884 1.1 christos h->plt.offset = (bfd_vma) -1; 1885 1.1 christos 1886 1.1 christos /* If this is a weak symbol, and there is a real definition, the 1887 1.8 christos processor independent code will have arranged for us to see the 1888 1.1 christos real definition first, and we can just use the same value. */ 1889 1.8 christos if (h->is_weakalias) 1890 1.8 christos { 1891 1.8 christos struct elf_link_hash_entry *def = weakdef (h); 1892 1.8 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined); 1893 1.10 christos h->root.u.def.section = def->root.u.def.section; 1894 1.1 christos h->root.u.def.value = def->root.u.def.value; 1895 1.1 christos return true; 1896 1.1 christos } 1897 1.1 christos 1898 1.1 christos /* This is a reference to a symbol defined by a dynamic object which 1899 1.1 christos is not a function. */ 1900 1.1 christos 1901 1.1 christos /* If we are creating a shared library, we must presume that the 1902 1.1 christos only references to the symbol are via the global offset table. 1903 1.6 christos For such cases we need not do anything here; the relocations will 1904 1.10 christos be handled correctly by relocate_section. */ 1905 1.1 christos if (bfd_link_pic (info)) 1906 1.1 christos return true; 1907 1.1 christos 1908 1.1 christos /* If there are no references to this symbol that do not use the 1909 1.10 christos GOT, we don't need to generate a copy reloc. */ 1910 1.1 christos if (!h->non_got_ref) 1911 1.1 christos return true; 1912 1.1 christos 1913 1.1 christos /* If -z nocopyreloc was given, we won't generate them either. */ 1914 1.1 christos if (info->nocopyreloc) 1915 1.10 christos { 1916 1.1 christos h->non_got_ref = 0; 1917 1.1 christos return true; 1918 1.8 christos } 1919 1.1 christos 1920 1.9 christos /* If we don't find any dynamic relocs in read-only sections, then 1921 1.1 christos we'll be keeping the dynamic relocs and avoiding the copy reloc. */ 1922 1.1 christos if (!_bfd_elf_readonly_dynrelocs (h)) 1923 1.10 christos { 1924 1.1 christos h->non_got_ref = 0; 1925 1.1 christos return true; 1926 1.1 christos } 1927 1.1 christos 1928 1.1 christos /* We must allocate the symbol in our .dynbss section, which will 1929 1.1 christos become part of the .bss section of the executable. There will be 1930 1.1 christos an entry for this symbol in the .dynsym section. The dynamic 1931 1.1 christos object will contain position independent code, so all references 1932 1.1 christos from the dynamic object to this symbol will go through the global 1933 1.1 christos offset table. The dynamic linker will use the .dynsym entry to 1934 1.1 christos determine the address it must put in the global offset table, so 1935 1.1 christos both the dynamic object and the regular object will refer to the 1936 1.1 christos same memory location for the variable. */ 1937 1.1 christos 1938 1.1 christos /* We must generate a R_TILEPRO_COPY reloc to tell the dynamic linker 1939 1.1 christos to copy the initial value out of the dynamic object and into the 1940 1.7 christos runtime process image. We need to remember the offset into the 1941 1.7 christos .rel.bss section we are going to use. */ 1942 1.9 christos if ((h->root.u.def.section->flags & SEC_READONLY) != 0) 1943 1.9 christos { 1944 1.7 christos s = htab->sdynrelro; 1945 1.7 christos srel = htab->sreldynrelro; 1946 1.7 christos } 1947 1.9 christos else 1948 1.9 christos { 1949 1.7 christos s = htab->sdynbss; 1950 1.1 christos srel = htab->srelbss; 1951 1.1 christos } 1952 1.7 christos if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) 1953 1.1 christos { 1954 1.1 christos srel->size += TILEPRO_ELF_RELA_BYTES; 1955 1.1 christos h->needs_copy = 1; 1956 1.7 christos } 1957 1.1 christos 1958 1.1 christos return _bfd_elf_adjust_dynamic_copy (info, h, s); 1959 1.1 christos } 1960 1.1 christos 1961 1.1 christos /* Allocate space in .plt, .got and associated reloc sections for 1962 1.10 christos dynamic relocs. */ 1963 1.1 christos 1964 1.1 christos static bool 1965 1.1 christos allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) 1966 1.9 christos { 1967 1.8 christos struct bfd_link_info *info; 1968 1.1 christos struct elf_link_hash_table *htab; 1969 1.1 christos struct elf_dyn_relocs *p; 1970 1.10 christos 1971 1.1 christos if (h->root.type == bfd_link_hash_indirect) 1972 1.1 christos return true; 1973 1.1 christos 1974 1.1 christos info = (struct bfd_link_info *) inf; 1975 1.1 christos htab = tilepro_elf_hash_table (info); 1976 1.9 christos BFD_ASSERT (htab != NULL); 1977 1.1 christos 1978 1.1 christos if (htab->dynamic_sections_created 1979 1.1 christos && h->plt.refcount > 0) 1980 1.1 christos { 1981 1.1 christos /* Make sure this symbol is output as a dynamic symbol. 1982 1.1 christos Undefined weak syms won't yet be marked as dynamic. */ 1983 1.1 christos if (h->dynindx == -1 1984 1.1 christos && !h->forced_local) 1985 1.10 christos { 1986 1.1 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 1987 1.1 christos return false; 1988 1.6 christos } 1989 1.1 christos 1990 1.9 christos if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h)) 1991 1.1 christos { 1992 1.1 christos asection *s = htab->splt; 1993 1.1 christos 1994 1.1 christos /* Allocate room for the header. */ 1995 1.1 christos if (s->size == 0) 1996 1.1 christos { 1997 1.1 christos s->size = PLT_ENTRY_SIZE; 1998 1.8 christos } 1999 1.1 christos 2000 1.1 christos h->plt.offset = s->size; 2001 1.1 christos 2002 1.1 christos /* If this symbol is not defined in a regular file, and we are 2003 1.1 christos not generating a shared library, then set the symbol to this 2004 1.1 christos location in the .plt. This is required to make function 2005 1.6 christos pointers compare as equal between the normal executable and 2006 1.1 christos the shared library. */ 2007 1.1 christos if (! bfd_link_pic (info) 2008 1.1 christos && !h->def_regular) 2009 1.1 christos { 2010 1.1 christos h->root.u.def.section = s; 2011 1.1 christos h->root.u.def.value = h->plt.offset; 2012 1.1 christos } 2013 1.1 christos 2014 1.1 christos /* Make room for this entry. */ 2015 1.1 christos s->size += PLT_ENTRY_SIZE; 2016 1.9 christos 2017 1.1 christos /* We also need to make an entry in the .got.plt section. */ 2018 1.1 christos htab->sgotplt->size += GOT_ENTRY_SIZE; 2019 1.9 christos 2020 1.1 christos /* We also need to make an entry in the .rela.plt section. */ 2021 1.1 christos htab->srelplt->size += TILEPRO_ELF_RELA_BYTES; 2022 1.1 christos } 2023 1.1 christos else 2024 1.1 christos { 2025 1.1 christos h->plt.offset = (bfd_vma) -1; 2026 1.1 christos h->needs_plt = 0; 2027 1.1 christos } 2028 1.1 christos } 2029 1.1 christos else 2030 1.1 christos { 2031 1.1 christos h->plt.offset = (bfd_vma) -1; 2032 1.1 christos h->needs_plt = 0; 2033 1.1 christos } 2034 1.1 christos 2035 1.1 christos /* If a TLS_IE symbol is now local to the binary, make it a TLS_LE 2036 1.8 christos requiring no TLS entry. */ 2037 1.1 christos if (h->got.refcount > 0 2038 1.1 christos && bfd_link_executable (info) 2039 1.1 christos && h->dynindx == -1 2040 1.1 christos && tilepro_elf_hash_entry(h)->tls_type == GOT_TLS_IE) 2041 1.1 christos h->got.offset = (bfd_vma) -1; 2042 1.1 christos else if (h->got.refcount > 0) 2043 1.10 christos { 2044 1.1 christos asection *s; 2045 1.1 christos bool dyn; 2046 1.1 christos int tls_type = tilepro_elf_hash_entry(h)->tls_type; 2047 1.1 christos 2048 1.1 christos /* Make sure this symbol is output as a dynamic symbol. 2049 1.1 christos Undefined weak syms won't yet be marked as dynamic. */ 2050 1.1 christos if (h->dynindx == -1 2051 1.1 christos && !h->forced_local) 2052 1.10 christos { 2053 1.1 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 2054 1.1 christos return false; 2055 1.9 christos } 2056 1.1 christos 2057 1.1 christos s = htab->sgot; 2058 1.1 christos h->got.offset = s->size; 2059 1.1 christos s->size += TILEPRO_BYTES_PER_WORD; 2060 1.1 christos /* R_TILEPRO_IMM16_Xn_TLS_GD entries need 2 consecutive GOT slots. */ 2061 1.9 christos if (tls_type == GOT_TLS_GD) 2062 1.1 christos s->size += TILEPRO_BYTES_PER_WORD; 2063 1.1 christos dyn = htab->dynamic_sections_created; 2064 1.1 christos /* R_TILEPRO_IMM16_Xn_TLS_IE_xxx needs one dynamic relocation, 2065 1.1 christos R_TILEPRO_IMM16_Xn_TLS_GD_xxx needs two if local symbol and two if 2066 1.9 christos global. */ 2067 1.6 christos if (tls_type == GOT_TLS_GD || tls_type == GOT_TLS_IE) 2068 1.6 christos htab->srelgot->size += 2 * TILEPRO_ELF_RELA_BYTES; 2069 1.6 christos else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 2070 1.9 christos bfd_link_pic (info), 2071 1.1 christos h)) 2072 1.1 christos htab->srelgot->size += TILEPRO_ELF_RELA_BYTES; 2073 1.1 christos } 2074 1.1 christos else 2075 1.9 christos h->got.offset = (bfd_vma) -1; 2076 1.10 christos 2077 1.1 christos if (h->dyn_relocs == NULL) 2078 1.1 christos return true; 2079 1.1 christos 2080 1.1 christos /* In the shared -Bsymbolic case, discard space allocated for 2081 1.1 christos dynamic pc-relative relocs against symbols which turn out to be 2082 1.1 christos defined in regular objects. For the normal shared case, discard 2083 1.1 christos space for pc-relative relocs that have become local due to symbol 2084 1.6 christos visibility changes. */ 2085 1.1 christos 2086 1.1 christos if (bfd_link_pic (info)) 2087 1.1 christos { 2088 1.8 christos if (SYMBOL_CALLS_LOCAL (info, h)) 2089 1.1 christos { 2090 1.9 christos struct elf_dyn_relocs **pp; 2091 1.1 christos 2092 1.1 christos for (pp = &h->dyn_relocs; (p = *pp) != NULL; ) 2093 1.1 christos { 2094 1.1 christos p->count -= p->pc_count; 2095 1.1 christos p->pc_count = 0; 2096 1.1 christos if (p->count == 0) 2097 1.1 christos *pp = p->next; 2098 1.1 christos else 2099 1.1 christos pp = &p->next; 2100 1.1 christos } 2101 1.1 christos } 2102 1.1 christos 2103 1.9 christos /* Also discard relocs on undefined weak syms with non-default 2104 1.1 christos visibility. */ 2105 1.1 christos if (h->dyn_relocs != NULL 2106 1.8 christos && h->root.type == bfd_link_hash_undefweak) 2107 1.8 christos { 2108 1.9 christos if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 2109 1.1 christos || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) 2110 1.1 christos h->dyn_relocs = NULL; 2111 1.1 christos 2112 1.1 christos /* Make sure undefined weak symbols are output as a dynamic 2113 1.1 christos symbol in PIEs. */ 2114 1.1 christos else if (h->dynindx == -1 2115 1.1 christos && !h->forced_local) 2116 1.10 christos { 2117 1.1 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 2118 1.1 christos return false; 2119 1.1 christos } 2120 1.1 christos } 2121 1.1 christos } 2122 1.1 christos else 2123 1.1 christos { 2124 1.1 christos /* For the non-shared case, discard space for relocs against 2125 1.1 christos symbols which turn out to need copy relocs or are not 2126 1.1 christos dynamic. */ 2127 1.1 christos 2128 1.1 christos if (!h->non_got_ref 2129 1.9 christos && ((h->def_dynamic 2130 1.1 christos && !h->def_regular) 2131 1.1 christos || (htab->dynamic_sections_created 2132 1.1 christos && (h->root.type == bfd_link_hash_undefweak 2133 1.1 christos || h->root.type == bfd_link_hash_undefined)))) 2134 1.1 christos { 2135 1.1 christos /* Make sure this symbol is output as a dynamic symbol. 2136 1.1 christos Undefined weak syms won't yet be marked as dynamic. */ 2137 1.1 christos if (h->dynindx == -1 2138 1.1 christos && !h->forced_local) 2139 1.10 christos { 2140 1.1 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 2141 1.1 christos return false; 2142 1.1 christos } 2143 1.1 christos 2144 1.1 christos /* If that succeeded, we know we'll be keeping all the 2145 1.1 christos relocs. */ 2146 1.1 christos if (h->dynindx != -1) 2147 1.1 christos goto keep; 2148 1.9 christos } 2149 1.1 christos 2150 1.1 christos h->dyn_relocs = NULL; 2151 1.1 christos 2152 1.1 christos keep: ; 2153 1.1 christos } 2154 1.9 christos 2155 1.1 christos /* Finally, allocate space. */ 2156 1.1 christos for (p = h->dyn_relocs; p != NULL; p = p->next) 2157 1.1 christos { 2158 1.1 christos asection *sreloc = elf_section_data (p->sec)->sreloc; 2159 1.1 christos sreloc->size += p->count * TILEPRO_ELF_RELA_BYTES; 2160 1.10 christos } 2161 1.1 christos 2162 1.1 christos return true; 2163 1.1 christos } 2164 1.1 christos 2165 1.1 christos /* Return true if the dynamic symbol for a given section should be 2166 1.10 christos omitted when creating a shared library. */ 2167 1.1 christos 2168 1.1 christos static bool 2169 1.1 christos tilepro_elf_omit_section_dynsym (bfd *output_bfd, 2170 1.1 christos struct bfd_link_info *info, 2171 1.1 christos asection *p) 2172 1.1 christos { 2173 1.1 christos /* We keep the .got section symbol so that explicit relocations 2174 1.1 christos against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode 2175 1.10 christos can be turned into relocations against the .got symbol. */ 2176 1.1 christos if (strcmp (p->name, ".got") == 0) 2177 1.8 christos return false; 2178 1.1 christos 2179 1.1 christos return _bfd_elf_omit_section_dynsym_default (output_bfd, info, p); 2180 1.1 christos } 2181 1.1 christos 2182 1.1 christos /* Set the sizes of the dynamic sections. */ 2183 1.1 christos 2184 1.10 christos #define ELF32_DYNAMIC_INTERPRETER "/lib/ld.so.1" 2185 1.11 christos 2186 1.11 christos static bool 2187 1.1 christos tilepro_elf_late_size_sections (bfd *output_bfd, 2188 1.9 christos struct bfd_link_info *info) 2189 1.1 christos { 2190 1.1 christos struct elf_link_hash_table *htab; 2191 1.1 christos bfd *dynobj; 2192 1.1 christos asection *s; 2193 1.1 christos bfd *ibfd; 2194 1.1 christos 2195 1.9 christos htab = tilepro_elf_hash_table (info); 2196 1.11 christos BFD_ASSERT (htab != NULL); 2197 1.11 christos dynobj = htab->dynobj; 2198 1.1 christos if (dynobj == NULL) 2199 1.1 christos return true; 2200 1.1 christos 2201 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 2202 1.6 christos { 2203 1.1 christos /* Set the contents of the .interp section to the interpreter. */ 2204 1.1 christos if (bfd_link_executable (info) && !info->nointerp) 2205 1.1 christos { 2206 1.1 christos s = bfd_get_linker_section (dynobj, ".interp"); 2207 1.1 christos BFD_ASSERT (s != NULL); 2208 1.1 christos s->size = sizeof ELF32_DYNAMIC_INTERPRETER; 2209 1.1 christos s->contents = (unsigned char *) ELF32_DYNAMIC_INTERPRETER; 2210 1.1 christos } 2211 1.1 christos } 2212 1.1 christos 2213 1.3 christos /* Set up .got offsets for local syms, and space for local dynamic 2214 1.1 christos relocs. */ 2215 1.1 christos for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) 2216 1.1 christos { 2217 1.1 christos bfd_signed_vma *local_got; 2218 1.1 christos bfd_signed_vma *end_local_got; 2219 1.1 christos char *local_tls_type; 2220 1.1 christos bfd_size_type locsymcount; 2221 1.1 christos Elf_Internal_Shdr *symtab_hdr; 2222 1.1 christos asection *srel; 2223 1.1 christos 2224 1.1 christos if (! is_tilepro_elf (ibfd)) 2225 1.1 christos continue; 2226 1.1 christos 2227 1.8 christos for (s = ibfd->sections; s != NULL; s = s->next) 2228 1.1 christos { 2229 1.1 christos struct elf_dyn_relocs *p; 2230 1.1 christos 2231 1.1 christos for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) 2232 1.1 christos { 2233 1.1 christos if (!bfd_is_abs_section (p->sec) 2234 1.1 christos && bfd_is_abs_section (p->sec->output_section)) 2235 1.1 christos { 2236 1.1 christos /* Input section has been discarded, either because 2237 1.1 christos it is a copy of a linkonce section or due to 2238 1.1 christos linker script /DISCARD/, so we'll be discarding 2239 1.1 christos the relocs too. */ 2240 1.1 christos } 2241 1.1 christos else if (p->count != 0) 2242 1.1 christos { 2243 1.1 christos srel = elf_section_data (p->sec)->sreloc; 2244 1.8 christos srel->size += p->count * TILEPRO_ELF_RELA_BYTES; 2245 1.8 christos if ((p->sec->output_section->flags & SEC_READONLY) != 0) 2246 1.8 christos { 2247 1.8 christos info->flags |= DF_TEXTREL; 2248 1.8 christos 2249 1.8 christos info->callbacks->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"), 2250 1.1 christos p->sec->owner, p->sec); 2251 1.1 christos } 2252 1.1 christos } 2253 1.1 christos } 2254 1.1 christos } 2255 1.1 christos 2256 1.1 christos local_got = elf_local_got_refcounts (ibfd); 2257 1.1 christos if (!local_got) 2258 1.1 christos continue; 2259 1.1 christos 2260 1.1 christos symtab_hdr = &elf_symtab_hdr (ibfd); 2261 1.1 christos locsymcount = symtab_hdr->sh_info; 2262 1.9 christos end_local_got = local_got + locsymcount; 2263 1.9 christos local_tls_type = _bfd_tilepro_elf_local_got_tls_type (ibfd); 2264 1.1 christos s = htab->sgot; 2265 1.1 christos srel = htab->srelgot; 2266 1.1 christos for (; local_got < end_local_got; ++local_got, ++local_tls_type) 2267 1.1 christos { 2268 1.1 christos if (*local_got > 0) 2269 1.1 christos { 2270 1.1 christos *local_got = s->size; 2271 1.1 christos s->size += TILEPRO_BYTES_PER_WORD; 2272 1.6 christos if (*local_tls_type == GOT_TLS_GD) 2273 1.1 christos s->size += TILEPRO_BYTES_PER_WORD; 2274 1.1 christos if (bfd_link_pic (info) 2275 1.1 christos || *local_tls_type == GOT_TLS_GD 2276 1.1 christos || *local_tls_type == GOT_TLS_IE) 2277 1.1 christos srel->size += TILEPRO_ELF_RELA_BYTES; 2278 1.1 christos } 2279 1.1 christos else 2280 1.1 christos *local_got = (bfd_vma) -1; 2281 1.1 christos } 2282 1.1 christos } 2283 1.1 christos 2284 1.9 christos /* Allocate global sym .plt and .got entries, and space for global 2285 1.1 christos sym dynamic relocs. */ 2286 1.1 christos elf_link_hash_traverse (htab, allocate_dynrelocs, info); 2287 1.1 christos 2288 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 2289 1.1 christos { 2290 1.1 christos /* If the .got section is more than 0x8000 bytes, we add 2291 1.9 christos 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16 2292 1.1 christos bit relocations have a greater chance of working. */ 2293 1.1 christos if (htab->sgot->size >= 0x8000 2294 1.1 christos && elf_hash_table (info)->hgot->root.u.def.value == 0) 2295 1.1 christos elf_hash_table (info)->hgot->root.u.def.value = 0x8000; 2296 1.9 christos } 2297 1.1 christos 2298 1.1 christos if (htab->sgotplt) 2299 1.1 christos { 2300 1.1 christos struct elf_link_hash_entry *got; 2301 1.10 christos got = elf_link_hash_lookup (elf_hash_table (info), 2302 1.1 christos "_GLOBAL_OFFSET_TABLE_", 2303 1.1 christos false, false, false); 2304 1.8 christos 2305 1.1 christos /* Don't allocate .got.plt section if there are no GOT nor PLT 2306 1.1 christos entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */ 2307 1.9 christos if ((got == NULL 2308 1.1 christos || !got->ref_regular_nonweak) 2309 1.9 christos && (htab->sgotplt->size 2310 1.9 christos == GOTPLT_HEADER_SIZE) 2311 1.9 christos && (htab->splt == NULL 2312 1.9 christos || htab->splt->size == 0) 2313 1.1 christos && (htab->sgot == NULL 2314 1.9 christos || (htab->sgot->size 2315 1.1 christos == get_elf_backend_data (output_bfd)->got_header_size))) 2316 1.1 christos htab->sgotplt->size = 0; 2317 1.1 christos } 2318 1.1 christos 2319 1.1 christos /* The check_relocs and adjust_dynamic_symbol entry points have 2320 1.1 christos determined the sizes of the various dynamic sections. Allocate 2321 1.1 christos memory for them. */ 2322 1.1 christos for (s = dynobj->sections; s != NULL; s = s->next) 2323 1.1 christos { 2324 1.1 christos if ((s->flags & SEC_LINKER_CREATED) == 0) 2325 1.9 christos continue; 2326 1.9 christos 2327 1.9 christos if (s == htab->splt 2328 1.9 christos || s == htab->sgot 2329 1.9 christos || s == htab->sgotplt 2330 1.1 christos || s == htab->sdynbss 2331 1.1 christos || s == htab->sdynrelro) 2332 1.1 christos { 2333 1.1 christos /* Strip this section if we don't need it; see the 2334 1.10 christos comment below. */ 2335 1.1 christos } 2336 1.1 christos else if (startswith (s->name, ".rela")) 2337 1.1 christos { 2338 1.1 christos if (s->size != 0) 2339 1.1 christos { 2340 1.1 christos /* We use the reloc_count field as a counter if we need 2341 1.1 christos to copy relocs into the output file. */ 2342 1.1 christos s->reloc_count = 0; 2343 1.1 christos } 2344 1.1 christos } 2345 1.1 christos else 2346 1.1 christos { 2347 1.1 christos /* It's not one of our sections. */ 2348 1.1 christos continue; 2349 1.1 christos } 2350 1.1 christos 2351 1.1 christos if (s->size == 0) 2352 1.1 christos { 2353 1.1 christos /* If we don't need this section, strip it from the 2354 1.1 christos output file. This is mostly to handle .rela.bss and 2355 1.1 christos .rela.plt. We must create both sections in 2356 1.1 christos create_dynamic_sections, because they must be created 2357 1.1 christos before the linker maps input sections to output 2358 1.1 christos sections. The linker does that before 2359 1.1 christos adjust_dynamic_symbol is called, and it is that 2360 1.1 christos function which decides whether anything needs to go 2361 1.1 christos into these sections. */ 2362 1.1 christos s->flags |= SEC_EXCLUDE; 2363 1.1 christos continue; 2364 1.1 christos } 2365 1.1 christos 2366 1.1 christos if ((s->flags & SEC_HAS_CONTENTS) == 0) 2367 1.1 christos continue; 2368 1.1 christos 2369 1.1 christos /* Allocate memory for the section contents. Zero the memory 2370 1.1 christos for the benefit of .rela.plt, which has 4 unused entries 2371 1.1 christos at the beginning, and we don't want garbage. */ 2372 1.10 christos s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); 2373 1.1 christos if (s->contents == NULL) 2374 1.1 christos return false; 2375 1.10 christos } 2376 1.1 christos 2377 1.1 christos return _bfd_elf_add_dynamic_tags (output_bfd, info, true); 2378 1.1 christos } 2379 1.1 christos 2380 1.1 christos /* Return the base VMA address which should be subtracted from real addresses 2382 1.1 christos when resolving @dtpoff relocation. 2383 1.1 christos This is PT_TLS segment p_vaddr. */ 2384 1.1 christos 2385 1.1 christos static bfd_vma 2386 1.1 christos dtpoff_base (struct bfd_link_info *info) 2387 1.1 christos { 2388 1.1 christos /* If tls_sec is NULL, we should have signalled an error already. */ 2389 1.1 christos if (elf_hash_table (info)->tls_sec == NULL) 2390 1.1 christos return 0; 2391 1.1 christos return elf_hash_table (info)->tls_sec->vma; 2392 1.1 christos } 2393 1.1 christos 2394 1.1 christos /* Return the relocation value for R_TILEPRO_TLS_TPOFF32. */ 2395 1.1 christos 2396 1.1 christos static bfd_vma 2397 1.1 christos tpoff (struct bfd_link_info *info, bfd_vma address) 2398 1.1 christos { 2399 1.1 christos struct elf_link_hash_table *htab = elf_hash_table (info); 2400 1.1 christos 2401 1.1 christos /* If tls_sec is NULL, we should have signalled an error already. */ 2402 1.1 christos if (htab->tls_sec == NULL) 2403 1.1 christos return 0; 2404 1.1 christos 2405 1.1 christos return (address - htab->tls_sec->vma); 2406 1.1 christos } 2407 1.1 christos 2408 1.1 christos /* Replace the MASK bits in ADDR with those in INSN, for the next 2409 1.1 christos TILEPRO_BUNDLE_SIZE_IN_BYTES bytes. */ 2410 1.1 christos 2411 1.1 christos static void 2412 1.1 christos tilepro_replace_insn (bfd_byte *addr, const bfd_byte *mask, 2413 1.1 christos const bfd_byte *insn) 2414 1.1 christos { 2415 1.1 christos int i; 2416 1.1 christos for (i = 0; i < TILEPRO_BUNDLE_SIZE_IN_BYTES; i++) 2417 1.1 christos { 2418 1.1 christos addr[i] = (addr[i] & ~mask[i]) | (insn[i] & mask[i]); 2419 1.1 christos } 2420 1.1 christos } 2421 1.1 christos 2422 1.1 christos /* Mask to extract the bits corresponding to an instruction in a 2423 1.1 christos specific pipe of a bundle. */ 2424 1.1 christos static const bfd_byte insn_mask_X1[] = { 2425 1.1 christos 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x7f 2426 1.1 christos }; 2427 1.1 christos 2428 1.1 christos /* Mask to extract the bits corresponding to an instruction in a 2429 1.1 christos specific pipe of a bundle, minus the destination operand and the 2430 1.1 christos first source operand. */ 2431 1.1 christos static const bfd_byte insn_mask_X0_no_dest_no_srca[] = { 2432 1.1 christos 0x00, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00 2433 1.1 christos }; 2434 1.1 christos 2435 1.1 christos static const bfd_byte insn_mask_X1_no_dest_no_srca[] = { 2436 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x7f 2437 1.1 christos }; 2438 1.1 christos 2439 1.1 christos static const bfd_byte insn_mask_Y0_no_dest_no_srca[] = { 2440 1.1 christos 0x00, 0xf0, 0x0f, 0x78, 0x00, 0x00, 0x00, 0x00 2441 1.1 christos }; 2442 1.1 christos 2443 1.1 christos static const bfd_byte insn_mask_Y1_no_dest_no_srca[] = { 2444 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x78 2445 1.1 christos }; 2446 1.1 christos 2447 1.1 christos /* Mask to extract the first source operand of an instruction. */ 2448 1.1 christos static const bfd_byte srca_mask_X0[] = { 2449 1.1 christos 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 2450 1.1 christos }; 2451 1.1 christos 2452 1.1 christos static const bfd_byte srca_mask_X1[] = { 2453 1.1 christos 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00 2454 1.1 christos }; 2455 1.1 christos 2456 1.1 christos /* Various instructions synthesized to support tls references. */ 2457 1.1 christos 2458 1.1 christos /* move r0, r0 in the X1 pipe, used for tls le. */ 2459 1.1 christos static const bfd_byte insn_tls_le_move_X1[] = { 2460 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x33, 0x08 2461 1.1 christos }; 2462 1.1 christos 2463 1.1 christos /* move r0, zero in the X0 and X1 pipe, used for tls le. */ 2464 1.1 christos static const bfd_byte insn_tls_le_move_zero_X0X1[] = { 2465 1.1 christos 0xc0, 0xff, 0xcf, 0x00, 0xe0, 0xff, 0x33, 0x08 2466 1.1 christos }; 2467 1.1 christos 2468 1.1 christos /* lw r0, r0 in the X1 pipe, used for tls ie. */ 2469 1.1 christos static const bfd_byte insn_tls_ie_lw_X1[] = { 2470 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0b, 0x40 2471 1.1 christos }; 2472 1.1 christos 2473 1.1 christos /* add r0, r0, tp in various pipes, used for tls ie. */ 2474 1.1 christos static const bfd_byte insn_tls_ie_add_X0X1[] = { 2475 1.1 christos 0x00, 0x50, 0x0f, 0x00, 0x00, 0xa8, 0x07, 0x08 2476 1.1 christos }; 2477 1.1 christos static const bfd_byte insn_tls_ie_add_Y0Y1[] = { 2478 1.1 christos 0x00, 0x50, 0x03, 0x08, 0x00, 0xa8, 0x01, 0x8c 2479 1.1 christos }; 2480 1.1 christos 2481 1.1 christos /* move r0, r0 in various pipes, used for tls gd. */ 2482 1.1 christos static const bfd_byte insn_tls_gd_add_X0X1[] = { 2483 1.1 christos 0x00, 0xf0, 0xcf, 0x00, 0x00, 0xf8, 0x33, 0x08 2484 1.1 christos }; 2485 1.1 christos static const bfd_byte insn_tls_gd_add_Y0Y1[] = { 2486 1.1 christos 0x00, 0xf0, 0x0b, 0x18, 0x00, 0xf8, 0x05, 0x9c 2487 1.1 christos }; 2488 1.1 christos 2489 1.1 christos /* Relocate an TILEPRO ELF section. 2490 1.1 christos 2491 1.1 christos The RELOCATE_SECTION function is called by the new ELF backend linker 2492 1.1 christos to handle the relocations for a section. 2493 1.1 christos 2494 1.1 christos The relocs are always passed as Rela structures. 2495 1.1 christos 2496 1.1 christos This function is responsible for adjusting the section contents as 2497 1.1 christos necessary, and (if generating a relocatable output file) adjusting 2498 1.1 christos the reloc addend as necessary. 2499 1.1 christos 2500 1.1 christos This function does not have to worry about setting the reloc 2501 1.1 christos address or the reloc symbol index. 2502 1.1 christos 2503 1.1 christos LOCAL_SYMS is a pointer to the swapped in local symbols. 2504 1.1 christos 2505 1.1 christos LOCAL_SECTIONS is an array giving the section in the input file 2506 1.1 christos corresponding to the st_shndx field of each local symbol. 2507 1.1 christos 2508 1.1 christos The global hash table entry for the global symbols can be found 2509 1.1 christos via elf_sym_hashes (input_bfd). 2510 1.1 christos 2511 1.1 christos When generating relocatable output, this function must handle 2512 1.1 christos STB_LOCAL/STT_SECTION symbols specially. The output symbol is 2513 1.1 christos going to be the section symbol corresponding to the output 2514 1.10 christos section, which means that the addend must be adjusted 2515 1.1 christos accordingly. */ 2516 1.8 christos 2517 1.8 christos static int 2518 1.8 christos tilepro_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, 2519 1.8 christos bfd *input_bfd, asection *input_section, 2520 1.1 christos bfd_byte *contents, Elf_Internal_Rela *relocs, 2521 1.9 christos Elf_Internal_Sym *local_syms, 2522 1.1 christos asection **local_sections) 2523 1.1 christos { 2524 1.1 christos struct elf_link_hash_table *htab; 2525 1.1 christos Elf_Internal_Shdr *symtab_hdr; 2526 1.1 christos struct elf_link_hash_entry **sym_hashes; 2527 1.1 christos bfd_vma *local_got_offsets; 2528 1.1 christos bfd_vma got_base; 2529 1.1 christos asection *sreloc; 2530 1.1 christos Elf_Internal_Rela *rel; 2531 1.1 christos Elf_Internal_Rela *relend; 2532 1.1 christos int num_relocs; 2533 1.1 christos 2534 1.1 christos htab = tilepro_elf_hash_table (info); 2535 1.1 christos BFD_ASSERT (htab != NULL); 2536 1.1 christos symtab_hdr = &elf_symtab_hdr (input_bfd); 2537 1.1 christos sym_hashes = elf_sym_hashes (input_bfd); 2538 1.1 christos local_got_offsets = elf_local_got_offsets (input_bfd); 2539 1.1 christos 2540 1.1 christos if (elf_hash_table (info)->hgot == NULL) 2541 1.1 christos got_base = 0; 2542 1.1 christos else 2543 1.1 christos got_base = elf_hash_table (info)->hgot->root.u.def.value; 2544 1.1 christos 2545 1.1 christos sreloc = elf_section_data (input_section)->sreloc; 2546 1.1 christos 2547 1.1 christos rel = relocs; 2548 1.1 christos num_relocs = input_section->reloc_count; 2549 1.1 christos relend = relocs + num_relocs; 2550 1.10 christos for (; rel < relend; rel++) 2551 1.1 christos { 2552 1.1 christos int r_type, tls_type; 2553 1.1 christos bool is_tls_iele, is_tls_le; 2554 1.1 christos reloc_howto_type *howto; 2555 1.1 christos unsigned long r_symndx; 2556 1.1 christos struct elf_link_hash_entry *h; 2557 1.1 christos Elf_Internal_Sym *sym; 2558 1.1 christos tilepro_create_func create_func; 2559 1.1 christos asection *sec; 2560 1.1 christos bfd_vma relocation; 2561 1.10 christos bfd_reloc_status_type r; 2562 1.10 christos const char *name; 2563 1.10 christos bfd_vma off; 2564 1.1 christos bool is_plt = false; 2565 1.1 christos bool resolved_to_zero; 2566 1.1 christos bool unresolved_reloc; 2567 1.1 christos 2568 1.1 christos r_type = ELF32_R_TYPE (rel->r_info); 2569 1.1 christos if (r_type == R_TILEPRO_GNU_VTINHERIT 2570 1.1 christos || r_type == R_TILEPRO_GNU_VTENTRY) 2571 1.8 christos continue; 2572 1.1 christos 2573 1.1 christos if ((unsigned int)r_type >= NELEMS(tilepro_elf_howto_table)) 2574 1.1 christos return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); 2575 1.1 christos 2576 1.1 christos howto = tilepro_elf_howto_table + r_type; 2577 1.1 christos 2578 1.1 christos /* This is a final link. */ 2579 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 2580 1.10 christos h = NULL; 2581 1.1 christos sym = NULL; 2582 1.1 christos sec = NULL; 2583 1.1 christos unresolved_reloc = false; 2584 1.1 christos if (r_symndx < symtab_hdr->sh_info) 2585 1.1 christos { 2586 1.1 christos sym = local_syms + r_symndx; 2587 1.1 christos sec = local_sections[r_symndx]; 2588 1.1 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 2589 1.10 christos } 2590 1.10 christos else 2591 1.1 christos { 2592 1.1 christos bool warned ATTRIBUTE_UNUSED; 2593 1.1 christos bool ignored ATTRIBUTE_UNUSED; 2594 1.1 christos 2595 1.1 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 2596 1.1 christos r_symndx, symtab_hdr, sym_hashes, 2597 1.1 christos h, sec, relocation, 2598 1.1 christos unresolved_reloc, warned, ignored); 2599 1.1 christos if (warned) 2600 1.1 christos { 2601 1.1 christos /* To avoid generating warning messages about truncated 2602 1.1 christos relocations, set the relocation's address to be the same as 2603 1.1 christos the start of this section. */ 2604 1.1 christos if (input_section->output_section != NULL) 2605 1.1 christos relocation = input_section->output_section->vma; 2606 1.1 christos else 2607 1.1 christos relocation = 0; 2608 1.1 christos } 2609 1.1 christos } 2610 1.1 christos 2611 1.1 christos if (sec != NULL && discarded_section (sec)) 2612 1.6 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 2613 1.1 christos rel, 1, relend, howto, 0, contents); 2614 1.1 christos 2615 1.1 christos if (bfd_link_relocatable (info)) 2616 1.1 christos continue; 2617 1.1 christos 2618 1.1 christos if (h != NULL) 2619 1.1 christos name = h->root.root.string; 2620 1.1 christos else 2621 1.1 christos { 2622 1.9 christos name = (bfd_elf_string_from_elf_section 2623 1.1 christos (input_bfd, symtab_hdr->sh_link, sym->st_name)); 2624 1.1 christos if (name == NULL || *name == '\0') 2625 1.1 christos name = bfd_section_name (sec); 2626 1.1 christos } 2627 1.1 christos 2628 1.1 christos switch (r_type) 2629 1.1 christos { 2630 1.1 christos case R_TILEPRO_TLS_GD_CALL: 2631 1.1 christos case R_TILEPRO_IMM8_X0_TLS_GD_ADD: 2632 1.1 christos case R_TILEPRO_IMM8_Y0_TLS_GD_ADD: 2633 1.1 christos case R_TILEPRO_IMM8_X1_TLS_GD_ADD: 2634 1.1 christos case R_TILEPRO_IMM8_Y1_TLS_GD_ADD: 2635 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 2636 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 2637 1.1 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 2638 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 2639 1.1 christos tls_type = GOT_UNKNOWN; 2640 1.1 christos if (h == NULL && local_got_offsets) 2641 1.1 christos tls_type = 2642 1.1 christos _bfd_tilepro_elf_local_got_tls_type (input_bfd) [r_symndx]; 2643 1.8 christos else if (h != NULL) 2644 1.8 christos tls_type = tilepro_elf_hash_entry(h)->tls_type; 2645 1.1 christos 2646 1.1 christos is_tls_iele = (bfd_link_executable (info) || tls_type == GOT_TLS_IE); 2647 1.1 christos is_tls_le = is_tls_iele && (bfd_link_executable (info) 2648 1.1 christos && (h == NULL || h->dynindx == -1)); 2649 1.1 christos 2650 1.1 christos if (r_type == R_TILEPRO_TLS_GD_CALL) 2651 1.1 christos { 2652 1.1 christos if (is_tls_le) 2653 1.1 christos { 2654 1.1 christos /* GD -> LE */ 2655 1.1 christos tilepro_replace_insn (contents + rel->r_offset, 2656 1.1 christos insn_mask_X1, insn_tls_le_move_X1); 2657 1.1 christos continue; 2658 1.1 christos } 2659 1.1 christos else if (is_tls_iele) 2660 1.1 christos { 2661 1.1 christos /* GD -> IE */ 2662 1.1 christos tilepro_replace_insn (contents + rel->r_offset, 2663 1.1 christos insn_mask_X1, insn_tls_ie_lw_X1); 2664 1.1 christos continue; 2665 1.1 christos } 2666 1.10 christos 2667 1.10 christos /* GD -> GD */ 2668 1.1 christos h = (struct elf_link_hash_entry *) 2669 1.1 christos bfd_link_hash_lookup (info->hash, "__tls_get_addr", false, 2670 1.1 christos false, true); 2671 1.1 christos BFD_ASSERT (h != NULL); 2672 1.1 christos r_type = R_TILEPRO_JOFFLONG_X1_PLT; 2673 1.1 christos howto = tilepro_elf_howto_table + r_type; 2674 1.1 christos } 2675 1.1 christos else if (r_type == R_TILEPRO_IMM16_X0_TLS_GD_HA 2676 1.1 christos || r_type == R_TILEPRO_IMM16_X0_TLS_IE_HA) 2677 1.1 christos { 2678 1.1 christos if (is_tls_le) 2679 1.1 christos tilepro_replace_insn (contents + rel->r_offset, srca_mask_X0, 2680 1.1 christos insn_tls_le_move_zero_X0X1); 2681 1.1 christos } 2682 1.1 christos else if (r_type == R_TILEPRO_IMM16_X1_TLS_GD_HA 2683 1.1 christos || r_type == R_TILEPRO_IMM16_X1_TLS_IE_HA) 2684 1.1 christos { 2685 1.1 christos if (is_tls_le) 2686 1.1 christos tilepro_replace_insn (contents + rel->r_offset, srca_mask_X1, 2687 1.1 christos insn_tls_le_move_zero_X0X1); 2688 1.1 christos } 2689 1.1 christos else 2690 1.1 christos { 2691 1.1 christos const bfd_byte *mask = NULL; 2692 1.1 christos const bfd_byte *add_insn = NULL; 2693 1.1 christos 2694 1.1 christos switch (r_type) 2695 1.1 christos { 2696 1.1 christos case R_TILEPRO_IMM8_X0_TLS_GD_ADD: 2697 1.1 christos add_insn = is_tls_iele ? insn_tls_ie_add_X0X1 2698 1.1 christos : insn_tls_gd_add_X0X1; 2699 1.1 christos mask = insn_mask_X0_no_dest_no_srca; 2700 1.1 christos break; 2701 1.1 christos case R_TILEPRO_IMM8_X1_TLS_GD_ADD: 2702 1.1 christos add_insn = is_tls_iele ? insn_tls_ie_add_X0X1 2703 1.1 christos : insn_tls_gd_add_X0X1; 2704 1.1 christos mask = insn_mask_X1_no_dest_no_srca; 2705 1.1 christos break; 2706 1.1 christos case R_TILEPRO_IMM8_Y0_TLS_GD_ADD: 2707 1.1 christos add_insn = is_tls_iele ? insn_tls_ie_add_Y0Y1 2708 1.1 christos : insn_tls_gd_add_Y0Y1; 2709 1.1 christos mask = insn_mask_Y0_no_dest_no_srca; 2710 1.1 christos break; 2711 1.1 christos case R_TILEPRO_IMM8_Y1_TLS_GD_ADD: 2712 1.1 christos add_insn = is_tls_iele ? insn_tls_ie_add_Y0Y1 2713 1.1 christos : insn_tls_gd_add_Y0Y1; 2714 1.1 christos mask = insn_mask_Y1_no_dest_no_srca; 2715 1.1 christos break; 2716 1.1 christos } 2717 1.1 christos 2718 1.1 christos tilepro_replace_insn (contents + rel->r_offset, mask, add_insn); 2719 1.1 christos 2720 1.1 christos continue; 2721 1.8 christos } 2722 1.1 christos break; 2723 1.1 christos case R_TILEPRO_TLS_IE_LOAD: 2724 1.1 christos if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1)) 2725 1.1 christos /* IE -> LE */ 2726 1.1 christos tilepro_replace_insn (contents + rel->r_offset, 2727 1.1 christos insn_mask_X1_no_dest_no_srca, 2728 1.1 christos insn_tls_le_move_X1); 2729 1.1 christos else 2730 1.1 christos /* IE -> IE */ 2731 1.1 christos tilepro_replace_insn (contents + rel->r_offset, 2732 1.1 christos insn_mask_X1_no_dest_no_srca, 2733 1.1 christos insn_tls_ie_lw_X1); 2734 1.1 christos continue; 2735 1.1 christos break; 2736 1.1 christos default: 2737 1.8 christos break; 2738 1.8 christos } 2739 1.8 christos 2740 1.1 christos resolved_to_zero = (h != NULL 2741 1.1 christos && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); 2742 1.8 christos 2743 1.8 christos switch (r_type) 2744 1.8 christos { 2745 1.8 christos case R_TILEPRO_IMM16_X0_GOT: 2746 1.8 christos case R_TILEPRO_IMM16_X1_GOT: 2747 1.8 christos case R_TILEPRO_IMM16_X0_GOT_LO: 2748 1.8 christos case R_TILEPRO_IMM16_X1_GOT_LO: 2749 1.8 christos case R_TILEPRO_IMM16_X0_GOT_HI: 2750 1.1 christos case R_TILEPRO_IMM16_X1_GOT_HI: 2751 1.1 christos case R_TILEPRO_IMM16_X0_GOT_HA: 2752 1.9 christos case R_TILEPRO_IMM16_X1_GOT_HA: 2753 1.1 christos /* Relocation is to the entry for this symbol in the global 2754 1.1 christos offset table. */ 2755 1.1 christos if (htab->sgot == NULL) 2756 1.1 christos abort (); 2757 1.10 christos 2758 1.1 christos if (h != NULL) 2759 1.1 christos { 2760 1.1 christos bool dyn; 2761 1.1 christos 2762 1.1 christos off = h->got.offset; 2763 1.6 christos BFD_ASSERT (off != (bfd_vma) -1); 2764 1.6 christos dyn = elf_hash_table (info)->dynamic_sections_created; 2765 1.6 christos 2766 1.6 christos if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 2767 1.1 christos bfd_link_pic (info), 2768 1.1 christos h) 2769 1.1 christos || (bfd_link_pic (info) 2770 1.1 christos && SYMBOL_REFERENCES_LOCAL (info, h))) 2771 1.1 christos { 2772 1.1 christos /* This is actually a static link, or it is a 2773 1.1 christos -Bsymbolic link and the symbol is defined 2774 1.1 christos locally, or the symbol was forced to be local 2775 1.1 christos because of a version file. We must initialize 2776 1.1 christos this entry in the global offset table. Since the 2777 1.1 christos offset must always be a multiple 2778 1.1 christos of 4 for 32-bit, we use the least significant bit 2779 1.1 christos to record whether we have initialized it already. 2780 1.1 christos 2781 1.1 christos When doing a dynamic link, we create a .rela.got 2782 1.1 christos relocation entry to initialize the value. This 2783 1.1 christos is done in the finish_dynamic_symbol routine. */ 2784 1.1 christos if ((off & 1) != 0) 2785 1.1 christos off &= ~1; 2786 1.9 christos else 2787 1.1 christos { 2788 1.1 christos bfd_put_32 (output_bfd, relocation, 2789 1.1 christos htab->sgot->contents + off); 2790 1.1 christos h->got.offset |= 1; 2791 1.10 christos } 2792 1.1 christos } 2793 1.1 christos else 2794 1.1 christos unresolved_reloc = false; 2795 1.1 christos } 2796 1.1 christos else 2797 1.1 christos { 2798 1.1 christos BFD_ASSERT (local_got_offsets != NULL 2799 1.1 christos && local_got_offsets[r_symndx] != (bfd_vma) -1); 2800 1.1 christos 2801 1.8 christos off = local_got_offsets[r_symndx]; 2802 1.1 christos 2803 1.1 christos /* The offset must always be a multiple of 4 on 32-bit. 2804 1.1 christos We use the least significant bit to record 2805 1.1 christos whether we have already processed this entry. */ 2806 1.1 christos if ((off & 1) != 0) 2807 1.6 christos off &= ~1; 2808 1.1 christos else 2809 1.1 christos { 2810 1.1 christos if (bfd_link_pic (info)) 2811 1.1 christos { 2812 1.1 christos asection *s; 2813 1.1 christos Elf_Internal_Rela outrel; 2814 1.9 christos 2815 1.1 christos /* We need to generate a R_TILEPRO_RELATIVE reloc 2816 1.1 christos for the dynamic linker. */ 2817 1.9 christos s = htab->srelgot; 2818 1.9 christos BFD_ASSERT (s != NULL); 2819 1.1 christos 2820 1.1 christos outrel.r_offset = (htab->sgot->output_section->vma 2821 1.1 christos + htab->sgot->output_offset 2822 1.1 christos + off); 2823 1.1 christos outrel.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE); 2824 1.1 christos outrel.r_addend = relocation; 2825 1.1 christos relocation = 0; 2826 1.1 christos tilepro_elf_append_rela_32 (output_bfd, s, &outrel); 2827 1.9 christos } 2828 1.1 christos 2829 1.1 christos bfd_put_32 (output_bfd, relocation, 2830 1.1 christos htab->sgot->contents + off); 2831 1.1 christos local_got_offsets[r_symndx] |= 1; 2832 1.1 christos } 2833 1.1 christos } 2834 1.8 christos relocation = off - got_base; 2835 1.1 christos break; 2836 1.1 christos 2837 1.8 christos case R_TILEPRO_JOFFLONG_X1_PLT: 2838 1.1 christos /* Relocation is to the entry for this symbol in the 2839 1.9 christos procedure linkage table. */ 2840 1.1 christos BFD_ASSERT (h != NULL); 2841 1.1 christos 2842 1.1 christos if (h->plt.offset == (bfd_vma) -1 || htab->splt == NULL) 2843 1.1 christos { 2844 1.1 christos /* We didn't make a PLT entry for this symbol. This 2845 1.1 christos happens when statically linking PIC code, or when 2846 1.1 christos using -Bsymbolic. */ 2847 1.9 christos break; 2848 1.9 christos } 2849 1.1 christos 2850 1.10 christos relocation = (htab->splt->output_section->vma 2851 1.1 christos + htab->splt->output_offset 2852 1.1 christos + h->plt.offset); 2853 1.8 christos unresolved_reloc = false; 2854 1.8 christos break; 2855 1.8 christos 2856 1.8 christos case R_TILEPRO_32_PCREL: 2857 1.8 christos case R_TILEPRO_16_PCREL: 2858 1.8 christos case R_TILEPRO_8_PCREL: 2859 1.8 christos case R_TILEPRO_IMM16_X0_PCREL: 2860 1.8 christos case R_TILEPRO_IMM16_X1_PCREL: 2861 1.8 christos case R_TILEPRO_IMM16_X0_LO_PCREL: 2862 1.8 christos case R_TILEPRO_IMM16_X1_LO_PCREL: 2863 1.8 christos case R_TILEPRO_IMM16_X0_HI_PCREL: 2864 1.1 christos case R_TILEPRO_IMM16_X1_HI_PCREL: 2865 1.1 christos case R_TILEPRO_IMM16_X0_HA_PCREL: 2866 1.1 christos case R_TILEPRO_IMM16_X1_HA_PCREL: 2867 1.1 christos if (h != NULL 2868 1.8 christos && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 2869 1.8 christos break; 2870 1.8 christos /* Fall through. */ 2871 1.8 christos case R_TILEPRO_32: 2872 1.8 christos case R_TILEPRO_16: 2873 1.8 christos case R_TILEPRO_8: 2874 1.8 christos case R_TILEPRO_LO16: 2875 1.8 christos case R_TILEPRO_HI16: 2876 1.8 christos case R_TILEPRO_HA16: 2877 1.8 christos case R_TILEPRO_COPY: 2878 1.8 christos case R_TILEPRO_GLOB_DAT: 2879 1.8 christos case R_TILEPRO_JMP_SLOT: 2880 1.8 christos case R_TILEPRO_RELATIVE: 2881 1.8 christos case R_TILEPRO_BROFF_X1: 2882 1.8 christos case R_TILEPRO_JOFFLONG_X1: 2883 1.8 christos case R_TILEPRO_IMM8_X0: 2884 1.8 christos case R_TILEPRO_IMM8_Y0: 2885 1.8 christos case R_TILEPRO_IMM8_X1: 2886 1.8 christos case R_TILEPRO_IMM8_Y1: 2887 1.8 christos case R_TILEPRO_DEST_IMM8_X1: 2888 1.8 christos case R_TILEPRO_MT_IMM15_X1: 2889 1.8 christos case R_TILEPRO_MF_IMM15_X1: 2890 1.8 christos case R_TILEPRO_IMM16_X0: 2891 1.8 christos case R_TILEPRO_IMM16_X1: 2892 1.8 christos case R_TILEPRO_IMM16_X0_LO: 2893 1.8 christos case R_TILEPRO_IMM16_X1_LO: 2894 1.8 christos case R_TILEPRO_IMM16_X0_HI: 2895 1.8 christos case R_TILEPRO_IMM16_X1_HI: 2896 1.8 christos case R_TILEPRO_IMM16_X0_HA: 2897 1.8 christos case R_TILEPRO_IMM16_X1_HA: 2898 1.8 christos case R_TILEPRO_MMSTART_X0: 2899 1.8 christos case R_TILEPRO_MMEND_X0: 2900 1.8 christos case R_TILEPRO_MMSTART_X1: 2901 1.8 christos case R_TILEPRO_MMEND_X1: 2902 1.8 christos case R_TILEPRO_SHAMT_X0: 2903 1.1 christos case R_TILEPRO_SHAMT_X1: 2904 1.1 christos case R_TILEPRO_SHAMT_Y0: 2905 1.1 christos case R_TILEPRO_SHAMT_Y1: 2906 1.6 christos if ((input_section->flags & SEC_ALLOC) == 0) 2907 1.1 christos break; 2908 1.8 christos 2909 1.8 christos if ((bfd_link_pic (info) 2910 1.1 christos && (h == NULL 2911 1.1 christos || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 2912 1.1 christos && !resolved_to_zero) 2913 1.6 christos || h->root.type != bfd_link_hash_undefweak) 2914 1.1 christos && (! howto->pc_relative 2915 1.1 christos || !SYMBOL_CALLS_LOCAL (info, h))) 2916 1.1 christos || (!bfd_link_pic (info) 2917 1.1 christos && h != NULL 2918 1.1 christos && h->dynindx != -1 2919 1.1 christos && !h->non_got_ref 2920 1.1 christos && ((h->def_dynamic 2921 1.1 christos && !h->def_regular) 2922 1.1 christos || h->root.type == bfd_link_hash_undefweak 2923 1.10 christos || h->root.type == bfd_link_hash_undefined))) 2924 1.1 christos { 2925 1.1 christos Elf_Internal_Rela outrel; 2926 1.1 christos bool skip, relocate = false; 2927 1.1 christos 2928 1.1 christos /* When generating a shared object, these relocations 2929 1.1 christos are copied into the output file to be resolved at run 2930 1.1 christos time. */ 2931 1.10 christos 2932 1.1 christos BFD_ASSERT (sreloc != NULL); 2933 1.1 christos 2934 1.1 christos skip = false; 2935 1.1 christos 2936 1.1 christos outrel.r_offset = 2937 1.10 christos _bfd_elf_section_offset (output_bfd, info, input_section, 2938 1.1 christos rel->r_offset); 2939 1.10 christos if (outrel.r_offset == (bfd_vma) -1) 2940 1.1 christos skip = true; 2941 1.1 christos else if (outrel.r_offset == (bfd_vma) -2) 2942 1.1 christos skip = true, relocate = true; 2943 1.1 christos outrel.r_offset += (input_section->output_section->vma 2944 1.1 christos + input_section->output_offset); 2945 1.8 christos 2946 1.8 christos switch (r_type) 2947 1.8 christos { 2948 1.1 christos case R_TILEPRO_32_PCREL: 2949 1.1 christos case R_TILEPRO_16_PCREL: 2950 1.1 christos case R_TILEPRO_8_PCREL: 2951 1.1 christos /* If the symbol is not dynamic, we should not keep 2952 1.1 christos a dynamic relocation. But an .rela.* slot has been 2953 1.1 christos allocated for it, output R_TILEPRO_NONE. 2954 1.10 christos FIXME: Add code tracking needed dynamic relocs as 2955 1.1 christos e.g. i386 has. */ 2956 1.1 christos if (h->dynindx == -1) 2957 1.1 christos skip = true, relocate = true; 2958 1.1 christos break; 2959 1.1 christos } 2960 1.1 christos 2961 1.1 christos if (skip) 2962 1.1 christos memset (&outrel, 0, sizeof outrel); 2963 1.1 christos /* h->dynindx may be -1 if the symbol was marked to 2964 1.1 christos become local. */ 2965 1.6 christos else if (h != NULL && 2966 1.1 christos h->dynindx != -1 2967 1.1 christos && (! is_plt 2968 1.1 christos || !bfd_link_pic (info) 2969 1.1 christos || !SYMBOLIC_BIND (info, h) 2970 1.1 christos || !h->def_regular)) 2971 1.1 christos { 2972 1.1 christos BFD_ASSERT (h->dynindx != -1); 2973 1.1 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); 2974 1.1 christos outrel.r_addend = rel->r_addend; 2975 1.1 christos } 2976 1.1 christos else 2977 1.1 christos { 2978 1.1 christos if (r_type == R_TILEPRO_32) 2979 1.1 christos { 2980 1.1 christos outrel.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE); 2981 1.1 christos outrel.r_addend = relocation + rel->r_addend; 2982 1.1 christos } 2983 1.1 christos else 2984 1.1 christos { 2985 1.1 christos long indx; 2986 1.1 christos 2987 1.9 christos outrel.r_addend = relocation + rel->r_addend; 2988 1.1 christos 2989 1.1 christos if (is_plt) 2990 1.1 christos sec = htab->splt; 2991 1.1 christos 2992 1.1 christos if (bfd_is_abs_section (sec)) 2993 1.1 christos indx = 0; 2994 1.10 christos else if (sec == NULL || sec->owner == NULL) 2995 1.1 christos { 2996 1.1 christos bfd_set_error (bfd_error_bad_value); 2997 1.1 christos return false; 2998 1.1 christos } 2999 1.1 christos else 3000 1.1 christos { 3001 1.1 christos asection *osec; 3002 1.1 christos 3003 1.1 christos /* We are turning this relocation into one 3004 1.1 christos against a section symbol. It would be 3005 1.1 christos proper to subtract the symbol's value, 3006 1.1 christos osec->vma, from the emitted reloc addend, 3007 1.1 christos but ld.so expects buggy relocs. */ 3008 1.1 christos osec = sec->output_section; 3009 1.1 christos indx = elf_section_data (osec)->dynindx; 3010 1.9 christos 3011 1.1 christos if (indx == 0) 3012 1.1 christos { 3013 1.1 christos osec = htab->text_index_section; 3014 1.1 christos indx = elf_section_data (osec)->dynindx; 3015 1.1 christos } 3016 1.1 christos 3017 1.1 christos /* FIXME: we really should be able to link non-pic 3018 1.1 christos shared libraries. */ 3019 1.7 christos if (indx == 0) 3020 1.8 christos { 3021 1.1 christos BFD_FAIL (); 3022 1.1 christos _bfd_error_handler 3023 1.10 christos (_("%pB: probably compiled without -fPIC?"), 3024 1.1 christos input_bfd); 3025 1.1 christos bfd_set_error (bfd_error_bad_value); 3026 1.1 christos return false; 3027 1.1 christos } 3028 1.1 christos } 3029 1.1 christos 3030 1.1 christos outrel.r_info = ELF32_R_INFO (indx, r_type); 3031 1.1 christos } 3032 1.1 christos } 3033 1.1 christos 3034 1.1 christos tilepro_elf_append_rela_32 (output_bfd, sreloc, &outrel); 3035 1.1 christos 3036 1.1 christos /* This reloc will be computed at runtime, so there's no 3037 1.1 christos need to do anything now. */ 3038 1.1 christos if (! relocate) 3039 1.1 christos continue; 3040 1.8 christos } 3041 1.8 christos break; 3042 1.8 christos 3043 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE: 3044 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE: 3045 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE_LO: 3046 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE_LO: 3047 1.8 christos case R_TILEPRO_IMM16_X0_TLS_LE_HI: 3048 1.8 christos case R_TILEPRO_IMM16_X1_TLS_LE_HI: 3049 1.1 christos case R_TILEPRO_IMM16_X0_TLS_LE_HA: 3050 1.1 christos case R_TILEPRO_IMM16_X1_TLS_LE_HA: 3051 1.10 christos if (!bfd_link_executable (info)) 3052 1.1 christos { 3053 1.1 christos Elf_Internal_Rela outrel; 3054 1.10 christos bool skip; 3055 1.1 christos 3056 1.1 christos BFD_ASSERT (sreloc != NULL); 3057 1.1 christos skip = false; 3058 1.1 christos outrel.r_offset = 3059 1.10 christos _bfd_elf_section_offset (output_bfd, info, input_section, 3060 1.1 christos rel->r_offset); 3061 1.10 christos if (outrel.r_offset == (bfd_vma) -1) 3062 1.1 christos skip = true; 3063 1.1 christos else if (outrel.r_offset == (bfd_vma) -2) 3064 1.1 christos skip = true; 3065 1.1 christos outrel.r_offset += (input_section->output_section->vma 3066 1.1 christos + input_section->output_offset); 3067 1.1 christos if (skip) 3068 1.1 christos memset (&outrel, 0, sizeof outrel); 3069 1.1 christos else 3070 1.1 christos { 3071 1.1 christos outrel.r_info = ELF32_R_INFO (0, r_type); 3072 1.1 christos outrel.r_addend = relocation - dtpoff_base (info) 3073 1.1 christos + rel->r_addend; 3074 1.1 christos } 3075 1.1 christos 3076 1.1 christos tilepro_elf_append_rela_32 (output_bfd, sreloc, &outrel); 3077 1.1 christos continue; 3078 1.1 christos } 3079 1.8 christos relocation = tpoff (info, relocation); 3080 1.8 christos break; 3081 1.8 christos 3082 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD: 3083 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD: 3084 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD_LO: 3085 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD_LO: 3086 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD_HI: 3087 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD_HI: 3088 1.8 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 3089 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 3090 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE: 3091 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE: 3092 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_LO: 3093 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE_LO: 3094 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_HI: 3095 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HI: 3096 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 3097 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 3098 1.1 christos r_type = tilepro_elf_tls_transition (info, r_type, h == NULL); 3099 1.1 christos tls_type = GOT_UNKNOWN; 3100 1.1 christos if (h == NULL && local_got_offsets) 3101 1.1 christos tls_type 3102 1.1 christos = _bfd_tilepro_elf_local_got_tls_type (input_bfd) [r_symndx]; 3103 1.8 christos else if (h != NULL) 3104 1.8 christos { 3105 1.8 christos tls_type = tilepro_elf_hash_entry(h)->tls_type; 3106 1.1 christos if (bfd_link_executable (info) 3107 1.1 christos && h->dynindx == -1 3108 1.1 christos && tls_type == GOT_TLS_IE) 3109 1.1 christos r_type = tilepro_tls_translate_to_le (r_type); 3110 1.1 christos } 3111 1.1 christos if (tls_type == GOT_TLS_IE) 3112 1.1 christos r_type = tilepro_tls_translate_to_ie (r_type); 3113 1.1 christos 3114 1.1 christos if (r_type == R_TILEPRO_IMM16_X0_TLS_LE 3115 1.1 christos || r_type == R_TILEPRO_IMM16_X1_TLS_LE 3116 1.1 christos || r_type == R_TILEPRO_IMM16_X0_TLS_LE_LO 3117 1.1 christos || r_type == R_TILEPRO_IMM16_X1_TLS_LE_LO 3118 1.1 christos || r_type == R_TILEPRO_IMM16_X0_TLS_LE_HI 3119 1.1 christos || r_type == R_TILEPRO_IMM16_X1_TLS_LE_HI 3120 1.1 christos || r_type == R_TILEPRO_IMM16_X0_TLS_LE_HA 3121 1.1 christos || r_type == R_TILEPRO_IMM16_X1_TLS_LE_HA) 3122 1.1 christos { 3123 1.1 christos relocation = tpoff (info, relocation); 3124 1.1 christos break; 3125 1.1 christos } 3126 1.1 christos 3127 1.1 christos if (h != NULL) 3128 1.1 christos { 3129 1.1 christos off = h->got.offset; 3130 1.1 christos h->got.offset |= 1; 3131 1.1 christos } 3132 1.1 christos else 3133 1.1 christos { 3134 1.1 christos BFD_ASSERT (local_got_offsets != NULL); 3135 1.1 christos off = local_got_offsets[r_symndx]; 3136 1.9 christos local_got_offsets[r_symndx] |= 1; 3137 1.1 christos } 3138 1.1 christos 3139 1.1 christos if (htab->sgot == NULL) 3140 1.1 christos abort (); 3141 1.1 christos 3142 1.1 christos if ((off & 1) != 0) 3143 1.1 christos off &= ~1; 3144 1.1 christos else 3145 1.10 christos { 3146 1.1 christos Elf_Internal_Rela outrel; 3147 1.9 christos int indx = 0; 3148 1.1 christos bool need_relocs = false; 3149 1.1 christos 3150 1.1 christos if (htab->srelgot == NULL) 3151 1.1 christos abort (); 3152 1.10 christos 3153 1.9 christos if (h != NULL) 3154 1.1 christos { 3155 1.6 christos bool dyn; 3156 1.6 christos dyn = htab->dynamic_sections_created; 3157 1.6 christos 3158 1.6 christos if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 3159 1.1 christos bfd_link_pic (info), 3160 1.1 christos h) 3161 1.1 christos && (!bfd_link_pic (info) 3162 1.1 christos || !SYMBOL_REFERENCES_LOCAL (info, h))) 3163 1.1 christos { 3164 1.1 christos indx = h->dynindx; 3165 1.1 christos } 3166 1.8 christos } 3167 1.6 christos 3168 1.1 christos /* The GOT entries have not been initialized yet. Do it 3169 1.1 christos now, and emit any relocations. */ 3170 1.1 christos if ((bfd_link_pic (info) || indx != 0) 3171 1.10 christos && (h == NULL 3172 1.1 christos || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 3173 1.8 christos || h->root.type != bfd_link_hash_undefweak)) 3174 1.8 christos need_relocs = true; 3175 1.8 christos 3176 1.8 christos switch (r_type) 3177 1.8 christos { 3178 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE: 3179 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE: 3180 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_LO: 3181 1.8 christos case R_TILEPRO_IMM16_X1_TLS_IE_LO: 3182 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_HI: 3183 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HI: 3184 1.9 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 3185 1.9 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 3186 1.9 christos if (need_relocs) { 3187 1.8 christos bfd_put_32 (output_bfd, 0, htab->sgot->contents + off); 3188 1.1 christos outrel.r_offset = (htab->sgot->output_section->vma 3189 1.8 christos + htab->sgot->output_offset + off); 3190 1.1 christos outrel.r_addend = 0; 3191 1.9 christos if (indx == 0) 3192 1.1 christos outrel.r_addend = relocation - dtpoff_base (info); 3193 1.8 christos outrel.r_info = ELF32_R_INFO (indx, R_TILEPRO_TLS_TPOFF32); 3194 1.1 christos tilepro_elf_append_rela_32 (output_bfd, htab->srelgot, 3195 1.9 christos &outrel); 3196 1.8 christos } else { 3197 1.8 christos bfd_put_32 (output_bfd, tpoff (info, relocation), 3198 1.1 christos htab->sgot->contents + off); 3199 1.1 christos } 3200 1.1 christos break; 3201 1.1 christos 3202 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD: 3203 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD: 3204 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_LO: 3205 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_LO: 3206 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HI: 3207 1.1 christos case R_TILEPRO_IMM16_X1_TLS_GD_HI: 3208 1.9 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 3209 1.9 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 3210 1.8 christos if (need_relocs) { 3211 1.8 christos outrel.r_offset = (htab->sgot->output_section->vma 3212 1.9 christos + htab->sgot->output_offset + off); 3213 1.9 christos outrel.r_addend = 0; 3214 1.1 christos outrel.r_info = ELF32_R_INFO (indx, R_TILEPRO_TLS_DTPMOD32); 3215 1.1 christos bfd_put_32 (output_bfd, 0, htab->sgot->contents + off); 3216 1.8 christos tilepro_elf_append_rela_32 (output_bfd, htab->srelgot, 3217 1.8 christos &outrel); 3218 1.8 christos if (indx == 0) 3219 1.1 christos { 3220 1.9 christos BFD_ASSERT (! unresolved_reloc); 3221 1.1 christos bfd_put_32 (output_bfd, 3222 1.8 christos relocation - dtpoff_base (info), 3223 1.1 christos (htab->sgot->contents + off + 3224 1.8 christos TILEPRO_BYTES_PER_WORD)); 3225 1.8 christos } 3226 1.9 christos else 3227 1.1 christos { 3228 1.8 christos bfd_put_32 (output_bfd, 0, 3229 1.1 christos (htab->sgot->contents + off + 3230 1.1 christos TILEPRO_BYTES_PER_WORD)); 3231 1.8 christos outrel.r_info = ELF32_R_INFO (indx, 3232 1.9 christos R_TILEPRO_TLS_DTPOFF32); 3233 1.8 christos outrel.r_offset += TILEPRO_BYTES_PER_WORD; 3234 1.8 christos tilepro_elf_append_rela_32 (output_bfd, 3235 1.1 christos htab->srelgot, &outrel); 3236 1.1 christos } 3237 1.1 christos } 3238 1.8 christos 3239 1.8 christos else { 3240 1.8 christos /* If we are not emitting relocations for a 3241 1.8 christos general dynamic reference, then we must be in a 3242 1.1 christos static link or an executable link with the 3243 1.9 christos symbol binding locally. Mark it as belonging 3244 1.1 christos to module 1, the executable. */ 3245 1.9 christos bfd_put_32 (output_bfd, 1, 3246 1.1 christos htab->sgot->contents + off ); 3247 1.1 christos bfd_put_32 (output_bfd, relocation - dtpoff_base (info), 3248 1.8 christos htab->sgot->contents + off + 3249 1.8 christos TILEPRO_BYTES_PER_WORD); 3250 1.1 christos } 3251 1.1 christos break; 3252 1.1 christos } 3253 1.1 christos } 3254 1.1 christos 3255 1.1 christos if (off >= (bfd_vma) -2) 3256 1.10 christos abort (); 3257 1.1 christos 3258 1.1 christos relocation = off - got_base; 3259 1.1 christos unresolved_reloc = false; 3260 1.1 christos howto = tilepro_elf_howto_table + r_type; 3261 1.1 christos break; 3262 1.1 christos 3263 1.1 christos default: 3264 1.1 christos break; 3265 1.1 christos } 3266 1.1 christos 3267 1.1 christos /* Dynamic relocs are not propagated for SEC_DEBUGGING sections 3268 1.1 christos because such sections are not SEC_ALLOC and thus ld.so will 3269 1.1 christos not process them. */ 3270 1.1 christos if (unresolved_reloc 3271 1.1 christos && !((input_section->flags & SEC_DEBUGGING) != 0 3272 1.7 christos && h->def_dynamic) 3273 1.7 christos && _bfd_elf_section_offset (output_bfd, info, input_section, 3274 1.8 christos rel->r_offset) != (bfd_vma) -1) 3275 1.8 christos _bfd_error_handler 3276 1.1 christos /* xgettext:c-format */ 3277 1.1 christos (_("%pB(%pA+%#" PRIx64 "): " 3278 1.8 christos "unresolvable %s relocation against symbol `%s'"), 3279 1.1 christos input_bfd, 3280 1.1 christos input_section, 3281 1.1 christos (uint64_t) rel->r_offset, 3282 1.1 christos howto->name, 3283 1.1 christos h->root.root.string); 3284 1.1 christos 3285 1.1 christos r = bfd_reloc_continue; 3286 1.1 christos 3287 1.1 christos /* For the _HA types, we add 0x8000 so that if bit 15 is set, 3288 1.1 christos * we will increment bit 16. The howto->rightshift takes care 3289 1.1 christos * of the rest for us. */ 3290 1.1 christos switch (r_type) 3291 1.1 christos { 3292 1.1 christos case R_TILEPRO_HA16: 3293 1.1 christos case R_TILEPRO_IMM16_X0_HA: 3294 1.1 christos case R_TILEPRO_IMM16_X1_HA: 3295 1.1 christos case R_TILEPRO_IMM16_X0_HA_PCREL: 3296 1.1 christos case R_TILEPRO_IMM16_X1_HA_PCREL: 3297 1.1 christos case R_TILEPRO_IMM16_X0_GOT_HA: 3298 1.1 christos case R_TILEPRO_IMM16_X1_GOT_HA: 3299 1.1 christos case R_TILEPRO_IMM16_X0_TLS_GD_HA: 3300 1.8 christos case R_TILEPRO_IMM16_X1_TLS_GD_HA: 3301 1.8 christos case R_TILEPRO_IMM16_X0_TLS_IE_HA: 3302 1.1 christos case R_TILEPRO_IMM16_X1_TLS_IE_HA: 3303 1.1 christos relocation += 0x8000; 3304 1.1 christos break; 3305 1.1 christos } 3306 1.1 christos 3307 1.1 christos /* Get the operand creation function, if any. */ 3308 1.8 christos create_func = reloc_to_create_func[r_type]; 3309 1.8 christos if (create_func == NULL) 3310 1.8 christos { 3311 1.1 christos r = _bfd_final_link_relocate (howto, input_bfd, input_section, 3312 1.1 christos contents, rel->r_offset, 3313 1.1 christos relocation, rel->r_addend); 3314 1.8 christos } 3315 1.8 christos else 3316 1.8 christos { 3317 1.8 christos if (howto->pc_relative) 3318 1.8 christos { 3319 1.8 christos relocation -= 3320 1.8 christos input_section->output_section->vma + input_section->output_offset; 3321 1.8 christos if (howto->pcrel_offset) 3322 1.8 christos relocation -= rel->r_offset; 3323 1.8 christos } 3324 1.8 christos 3325 1.8 christos bfd_byte *data; 3326 1.8 christos 3327 1.8 christos /* Add the relocation addend if any to the final target value */ 3328 1.8 christos relocation += rel->r_addend; 3329 1.8 christos 3330 1.8 christos /* Do basic range checking */ 3331 1.8 christos r = bfd_check_overflow (howto->complain_on_overflow, 3332 1.8 christos howto->bitsize, 3333 1.8 christos howto->rightshift, 3334 1.8 christos 32, 3335 1.8 christos relocation); 3336 1.8 christos 3337 1.8 christos /* 3338 1.8 christos * Write the relocated value out into the raw section data. 3339 1.8 christos * Don't put a relocation out in the .rela section. 3340 1.8 christos */ 3341 1.8 christos tilepro_bundle_bits mask = create_func(-1); 3342 1.8 christos tilepro_bundle_bits value = create_func(relocation >> howto->rightshift); 3343 1.8 christos 3344 1.8 christos /* Only touch bytes while the mask is not 0, so we 3345 1.8 christos don't write to out of bounds memory if this is actually 3346 1.8 christos a 16-bit switch instruction. */ 3347 1.8 christos for (data = contents + rel->r_offset; mask != 0; data++) 3348 1.8 christos { 3349 1.8 christos bfd_byte byte_mask = (bfd_byte)mask; 3350 1.8 christos *data = (*data & ~byte_mask) | ((bfd_byte)value & byte_mask); 3351 1.1 christos mask >>= 8; 3352 1.1 christos value >>= 8; 3353 1.1 christos } 3354 1.1 christos } 3355 1.1 christos 3356 1.1 christos if (r != bfd_reloc_ok) 3357 1.1 christos { 3358 1.1 christos const char *msg = NULL; 3359 1.1 christos 3360 1.6 christos switch (r) 3361 1.1 christos { 3362 1.1 christos case bfd_reloc_overflow: 3363 1.1 christos (*info->callbacks->reloc_overflow) 3364 1.1 christos (info, (h ? &h->root : NULL), name, howto->name, 3365 1.1 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 3366 1.6 christos break; 3367 1.10 christos 3368 1.1 christos case bfd_reloc_undefined: 3369 1.1 christos (*info->callbacks->undefined_symbol) 3370 1.1 christos (info, name, input_bfd, input_section, rel->r_offset, true); 3371 1.1 christos break; 3372 1.1 christos 3373 1.1 christos case bfd_reloc_outofrange: 3374 1.1 christos msg = _("internal error: out of range error"); 3375 1.1 christos break; 3376 1.1 christos 3377 1.1 christos case bfd_reloc_notsupported: 3378 1.1 christos msg = _("internal error: unsupported relocation error"); 3379 1.1 christos break; 3380 1.1 christos 3381 1.1 christos case bfd_reloc_dangerous: 3382 1.1 christos msg = _("internal error: dangerous relocation"); 3383 1.1 christos break; 3384 1.1 christos 3385 1.1 christos default: 3386 1.1 christos msg = _("internal error: unknown error"); 3387 1.1 christos break; 3388 1.6 christos } 3389 1.6 christos 3390 1.1 christos if (msg) 3391 1.1 christos (*info->callbacks->warning) (info, msg, name, input_bfd, 3392 1.1 christos input_section, rel->r_offset); 3393 1.10 christos } 3394 1.1 christos } 3395 1.1 christos 3396 1.1 christos return true; 3397 1.1 christos } 3398 1.1 christos 3399 1.10 christos /* Finish up dynamic symbol handling. We set the contents of various 3400 1.1 christos dynamic sections here. */ 3401 1.1 christos 3402 1.1 christos static bool 3403 1.1 christos tilepro_elf_finish_dynamic_symbol (bfd *output_bfd, 3404 1.1 christos struct bfd_link_info *info, 3405 1.9 christos struct elf_link_hash_entry *h, 3406 1.1 christos Elf_Internal_Sym *sym) 3407 1.1 christos { 3408 1.1 christos struct elf_link_hash_table *htab; 3409 1.1 christos 3410 1.1 christos htab = tilepro_elf_hash_table (info); 3411 1.1 christos BFD_ASSERT (htab != NULL); 3412 1.1 christos 3413 1.1 christos if (h->plt.offset != (bfd_vma) -1) 3414 1.1 christos { 3415 1.1 christos asection *splt; 3416 1.1 christos asection *srela; 3417 1.1 christos asection *sgotplt; 3418 1.1 christos Elf_Internal_Rela rela; 3419 1.1 christos bfd_byte *loc; 3420 1.1 christos bfd_vma r_offset; 3421 1.1 christos 3422 1.1 christos int rela_index; 3423 1.1 christos 3424 1.1 christos /* This symbol has an entry in the PLT. Set it up. */ 3425 1.9 christos 3426 1.9 christos BFD_ASSERT (h->dynindx != -1); 3427 1.9 christos 3428 1.1 christos splt = htab->splt; 3429 1.1 christos srela = htab->srelplt; 3430 1.1 christos sgotplt = htab->sgotplt; 3431 1.1 christos 3432 1.1 christos if (splt == NULL || srela == NULL) 3433 1.1 christos abort (); 3434 1.1 christos 3435 1.1 christos /* Fill in the entry in the procedure linkage table. */ 3436 1.1 christos rela_index = tilepro_plt_entry_build (splt, sgotplt, h->plt.offset, 3437 1.1 christos &r_offset); 3438 1.1 christos 3439 1.1 christos /* Fill in the entry in the global offset table, which initially points 3440 1.1 christos to the beginning of the plt. */ 3441 1.1 christos bfd_put_32 (output_bfd, splt->output_section->vma + splt->output_offset, 3442 1.1 christos sgotplt->contents + r_offset); 3443 1.1 christos 3444 1.1 christos /* Fill in the entry in the .rela.plt section. */ 3445 1.1 christos rela.r_offset = (sgotplt->output_section->vma 3446 1.1 christos + sgotplt->output_offset 3447 1.1 christos + r_offset); 3448 1.1 christos rela.r_addend = 0; 3449 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_JMP_SLOT); 3450 1.1 christos 3451 1.1 christos loc = srela->contents + rela_index * sizeof (Elf32_External_Rela); 3452 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 3453 1.1 christos 3454 1.1 christos if (!h->def_regular) 3455 1.1 christos { 3456 1.1 christos /* Mark the symbol as undefined, rather than as defined in 3457 1.1 christos the .plt section. Leave the value alone. */ 3458 1.1 christos sym->st_shndx = SHN_UNDEF; 3459 1.1 christos /* If the symbol is weak, we do need to clear the value. 3460 1.1 christos Otherwise, the PLT entry would provide a definition for 3461 1.1 christos the symbol even if the symbol wasn't defined anywhere, 3462 1.1 christos and so the symbol would never be NULL. */ 3463 1.1 christos if (!h->ref_regular_nonweak) 3464 1.1 christos sym->st_value = 0; 3465 1.1 christos } 3466 1.1 christos } 3467 1.1 christos 3468 1.1 christos if (h->got.offset != (bfd_vma) -1 3469 1.1 christos && tilepro_elf_hash_entry(h)->tls_type != GOT_TLS_GD 3470 1.1 christos && tilepro_elf_hash_entry(h)->tls_type != GOT_TLS_IE) 3471 1.1 christos { 3472 1.1 christos asection *sgot; 3473 1.1 christos asection *srela; 3474 1.1 christos Elf_Internal_Rela rela; 3475 1.9 christos 3476 1.9 christos /* This symbol has an entry in the GOT. Set it up. */ 3477 1.1 christos 3478 1.1 christos sgot = htab->sgot; 3479 1.1 christos srela = htab->srelgot; 3480 1.1 christos BFD_ASSERT (sgot != NULL && srela != NULL); 3481 1.1 christos 3482 1.1 christos rela.r_offset = (sgot->output_section->vma 3483 1.1 christos + sgot->output_offset 3484 1.1 christos + (h->got.offset &~ (bfd_vma) 1)); 3485 1.1 christos 3486 1.1 christos /* If this is a -Bsymbolic link, and the symbol is defined 3487 1.1 christos locally, we just want to emit a RELATIVE reloc. Likewise if 3488 1.6 christos the symbol was forced to be local because of a version file. 3489 1.1 christos The entry in the global offset table will already have been 3490 1.1 christos initialized in the relocate_section function. */ 3491 1.1 christos if (bfd_link_pic (info) 3492 1.1 christos && (info->symbolic || h->dynindx == -1) 3493 1.1 christos && h->def_regular) 3494 1.1 christos { 3495 1.1 christos asection *sec = h->root.u.def.section; 3496 1.1 christos rela.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE); 3497 1.1 christos rela.r_addend = (h->root.u.def.value 3498 1.1 christos + sec->output_section->vma 3499 1.1 christos + sec->output_offset); 3500 1.1 christos } 3501 1.1 christos else 3502 1.1 christos { 3503 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_GLOB_DAT); 3504 1.1 christos rela.r_addend = 0; 3505 1.1 christos } 3506 1.1 christos 3507 1.1 christos bfd_put_32 (output_bfd, 0, 3508 1.1 christos sgot->contents + (h->got.offset & ~(bfd_vma) 1)); 3509 1.1 christos tilepro_elf_append_rela_32 (output_bfd, srela, &rela); 3510 1.1 christos } 3511 1.1 christos 3512 1.1 christos if (h->needs_copy) 3513 1.1 christos { 3514 1.1 christos asection *s; 3515 1.1 christos Elf_Internal_Rela rela; 3516 1.1 christos 3517 1.1 christos /* This symbols needs a copy reloc. Set it up. */ 3518 1.1 christos BFD_ASSERT (h->dynindx != -1); 3519 1.1 christos 3520 1.1 christos rela.r_offset = (h->root.u.def.value 3521 1.1 christos + h->root.u.def.section->output_section->vma 3522 1.9 christos + h->root.u.def.section->output_offset); 3523 1.9 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_COPY); 3524 1.7 christos rela.r_addend = 0; 3525 1.9 christos if (h->root.u.def.section == htab->sdynrelro) 3526 1.1 christos s = htab->sreldynrelro; 3527 1.1 christos else 3528 1.1 christos s = htab->srelbss; 3529 1.1 christos tilepro_elf_append_rela_32 (output_bfd, s, &rela); 3530 1.9 christos } 3531 1.9 christos 3532 1.1 christos /* Mark some specially defined symbols as absolute. */ 3533 1.1 christos if (h == htab->hdynamic 3534 1.10 christos || (h == htab->hgot || h == htab->hplt)) 3535 1.1 christos sym->st_shndx = SHN_ABS; 3536 1.1 christos 3537 1.1 christos return true; 3538 1.1 christos } 3539 1.10 christos 3540 1.1 christos /* Finish up the dynamic sections. */ 3541 1.1 christos 3542 1.1 christos static bool 3543 1.1 christos tilepro_finish_dyn (bfd *output_bfd, struct bfd_link_info *info, 3544 1.1 christos bfd *dynobj, asection *sdyn, 3545 1.9 christos asection *splt ATTRIBUTE_UNUSED) 3546 1.1 christos { 3547 1.1 christos Elf32_External_Dyn *dyncon, *dynconend; 3548 1.1 christos struct elf_link_hash_table *htab; 3549 1.1 christos 3550 1.1 christos htab = tilepro_elf_hash_table (info); 3551 1.1 christos BFD_ASSERT (htab != NULL); 3552 1.1 christos dyncon = (Elf32_External_Dyn *) sdyn->contents; 3553 1.1 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 3554 1.1 christos for (; dyncon < dynconend; dyncon++) 3555 1.1 christos { 3556 1.1 christos Elf_Internal_Dyn dyn; 3557 1.1 christos asection *s; 3558 1.1 christos 3559 1.1 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 3560 1.1 christos 3561 1.9 christos switch (dyn.d_tag) 3562 1.1 christos { 3563 1.1 christos case DT_PLTGOT: 3564 1.1 christos s = htab->sgotplt; 3565 1.9 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 3566 1.1 christos break; 3567 1.1 christos case DT_JMPREL: 3568 1.1 christos s = htab->srelplt; 3569 1.9 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 3570 1.1 christos break; 3571 1.1 christos case DT_PLTRELSZ: 3572 1.1 christos s = htab->srelplt; 3573 1.1 christos dyn.d_un.d_val = s->size; 3574 1.1 christos break; 3575 1.1 christos default: 3576 1.1 christos continue; 3577 1.1 christos } 3578 1.10 christos 3579 1.1 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 3580 1.1 christos } 3581 1.10 christos return true; 3582 1.1 christos } 3583 1.8 christos 3584 1.1 christos static bool 3585 1.1 christos tilepro_elf_finish_dynamic_sections (bfd *output_bfd, 3586 1.1 christos struct bfd_link_info *info) 3587 1.9 christos { 3588 1.1 christos bfd *dynobj; 3589 1.1 christos asection *sdyn; 3590 1.1 christos struct elf_link_hash_table *htab; 3591 1.9 christos 3592 1.1 christos htab = tilepro_elf_hash_table (info); 3593 1.1 christos BFD_ASSERT (htab != NULL); 3594 1.1 christos dynobj = htab->dynobj; 3595 1.1 christos 3596 1.1 christos sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 3597 1.1 christos 3598 1.10 christos if (elf_hash_table (info)->dynamic_sections_created) 3599 1.1 christos { 3600 1.9 christos asection *splt; 3601 1.1 christos bool ret; 3602 1.1 christos 3603 1.1 christos splt = htab->splt; 3604 1.1 christos BFD_ASSERT (splt != NULL && sdyn != NULL); 3605 1.8 christos 3606 1.1 christos ret = tilepro_finish_dyn (output_bfd, info, dynobj, sdyn, splt); 3607 1.1 christos 3608 1.1 christos if (!ret) 3609 1.1 christos return ret; 3610 1.1 christos 3611 1.1 christos /* Fill in the first entry in the procedure linkage table. */ 3612 1.1 christos if (splt->size > 0) 3613 1.1 christos { 3614 1.1 christos memcpy (splt->contents, tilepro_plt0_entry, PLT_HEADER_SIZE); 3615 1.1 christos memset (splt->contents + PLT_HEADER_SIZE, 0, 3616 1.1 christos PLT_ENTRY_SIZE - PLT_HEADER_SIZE); 3617 1.1 christos } 3618 1.1 christos 3619 1.1 christos if (elf_section_data (splt->output_section) != NULL) 3620 1.1 christos elf_section_data (splt->output_section)->this_hdr.sh_entsize 3621 1.9 christos = PLT_ENTRY_SIZE; 3622 1.1 christos } 3623 1.9 christos 3624 1.1 christos if (htab->sgotplt) 3625 1.7 christos { 3626 1.9 christos if (bfd_is_abs_section (htab->sgotplt->output_section)) 3627 1.10 christos { 3628 1.1 christos _bfd_error_handler 3629 1.1 christos (_("discarded output section: `%pA'"), htab->sgotplt); 3630 1.9 christos return false; 3631 1.1 christos } 3632 1.1 christos 3633 1.1 christos if (htab->sgotplt->size > 0) 3634 1.1 christos { 3635 1.9 christos /* Write the first two entries in .got.plt, needed for the dynamic 3636 1.1 christos linker. */ 3637 1.9 christos bfd_put_32 (output_bfd, (bfd_vma) -1, 3638 1.1 christos htab->sgotplt->contents); 3639 1.1 christos bfd_put_32 (output_bfd, (bfd_vma) 0, 3640 1.9 christos htab->sgotplt->contents + GOT_ENTRY_SIZE); 3641 1.1 christos } 3642 1.1 christos 3643 1.1 christos elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize 3644 1.9 christos = GOT_ENTRY_SIZE; 3645 1.1 christos } 3646 1.9 christos 3647 1.1 christos if (htab->sgot) 3648 1.1 christos { 3649 1.1 christos if (htab->sgot->size > 0) 3650 1.1 christos { 3651 1.1 christos /* Set the first entry in the global offset table to the address of 3652 1.1 christos the dynamic section. */ 3653 1.9 christos bfd_vma val = (sdyn ? 3654 1.1 christos sdyn->output_section->vma + sdyn->output_offset : 3655 1.1 christos 0); 3656 1.9 christos bfd_put_32 (output_bfd, val, htab->sgot->contents); 3657 1.1 christos } 3658 1.1 christos 3659 1.1 christos elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize 3660 1.10 christos = GOT_ENTRY_SIZE; 3661 1.1 christos } 3662 1.1 christos 3663 1.1 christos return true; 3664 1.1 christos } 3665 1.1 christos 3666 1.1 christos 3667 1.1 christos 3669 1.1 christos /* Return address for Ith PLT stub in section PLT, for relocation REL 3670 1.8 christos or (bfd_vma) -1 if it should not be included. */ 3671 1.1 christos 3672 1.1 christos static bfd_vma 3673 1.1 christos tilepro_elf_plt_sym_val (bfd_vma i, const asection *plt, 3674 1.1 christos const arelent *rel ATTRIBUTE_UNUSED) 3675 1.1 christos { 3676 1.1 christos return plt->vma + (i + 1) * PLT_ENTRY_SIZE; 3677 1.1 christos } 3678 1.1 christos 3679 1.1 christos static enum elf_reloc_type_class 3680 1.1 christos tilepro_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 3681 1.1 christos const asection *rel_sec ATTRIBUTE_UNUSED, 3682 1.1 christos const Elf_Internal_Rela *rela) 3683 1.1 christos { 3684 1.1 christos switch ((int) ELF32_R_TYPE (rela->r_info)) 3685 1.1 christos { 3686 1.1 christos case R_TILEPRO_RELATIVE: 3687 1.1 christos return reloc_class_relative; 3688 1.1 christos case R_TILEPRO_JMP_SLOT: 3689 1.1 christos return reloc_class_plt; 3690 1.1 christos case R_TILEPRO_COPY: 3691 1.1 christos return reloc_class_copy; 3692 1.1 christos default: 3693 1.1 christos return reloc_class_normal; 3694 1.1 christos } 3695 1.8 christos } 3696 1.1 christos 3697 1.1 christos static int 3698 1.1 christos tilepro_additional_program_headers (bfd *abfd, 3699 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED) 3700 1.1 christos { 3701 1.1 christos /* Each .intrpt section specified by the user adds another PT_LOAD 3702 1.1 christos header since the sections are discontiguous. */ 3703 1.1 christos static const char intrpt_sections[4][9] = 3704 1.1 christos { 3705 1.1 christos ".intrpt0", ".intrpt1", ".intrpt2", ".intrpt3" 3706 1.1 christos }; 3707 1.1 christos int count = 0; 3708 1.1 christos int i; 3709 1.1 christos 3710 1.1 christos for (i = 0; i < 4; i++) 3711 1.1 christos { 3712 1.1 christos asection *sec = bfd_get_section_by_name (abfd, intrpt_sections[i]); 3713 1.1 christos if (sec != NULL && (sec->flags & SEC_LOAD) != 0) 3714 1.1 christos ++count; 3715 1.1 christos } 3716 1.1 christos 3717 1.1 christos /* Add four "padding" headers in to leave room in case a custom linker 3718 1.1 christos script does something fancy. Otherwise ld complains that it ran 3719 1.1 christos out of program headers and refuses to link. */ 3720 1.1 christos count += 4; 3721 1.1 christos 3722 1.1 christos return count; 3723 1.1 christos } 3724 1.1 christos 3725 1.1 christos #define ELF_ARCH bfd_arch_tilepro 3726 1.1 christos #define ELF_TARGET_ID TILEPRO_ELF_DATA 3727 1.3 christos #define ELF_MACHINE_CODE EM_TILEPRO 3728 1.1 christos #define ELF_MAXPAGESIZE 0x10000 3729 1.1 christos #define ELF_COMMONPAGESIZE 0x10000 3730 1.1 christos 3731 1.1 christos #define TARGET_LITTLE_SYM tilepro_elf32_vec 3732 1.8 christos #define TARGET_LITTLE_NAME "elf32-tilepro" 3733 1.1 christos 3734 1.1 christos #define elf_backend_reloc_type_class tilepro_reloc_type_class 3735 1.1 christos 3736 1.1 christos #define bfd_elf32_bfd_reloc_name_lookup tilepro_reloc_name_lookup 3737 1.1 christos #define bfd_elf32_bfd_link_hash_table_create tilepro_elf_link_hash_table_create 3738 1.1 christos #define bfd_elf32_bfd_reloc_type_lookup tilepro_reloc_type_lookup 3739 1.1 christos 3740 1.1 christos #define elf_backend_copy_indirect_symbol tilepro_elf_copy_indirect_symbol 3741 1.11 christos #define elf_backend_create_dynamic_sections tilepro_elf_create_dynamic_sections 3742 1.1 christos #define elf_backend_check_relocs tilepro_elf_check_relocs 3743 1.1 christos #define elf_backend_adjust_dynamic_symbol tilepro_elf_adjust_dynamic_symbol 3744 1.1 christos #define elf_backend_omit_section_dynsym tilepro_elf_omit_section_dynsym 3745 1.1 christos #define elf_backend_late_size_sections tilepro_elf_late_size_sections 3746 1.1 christos #define elf_backend_relocate_section tilepro_elf_relocate_section 3747 1.8 christos #define elf_backend_finish_dynamic_symbol tilepro_elf_finish_dynamic_symbol 3748 1.8 christos #define elf_backend_finish_dynamic_sections tilepro_elf_finish_dynamic_sections 3749 1.8 christos #define elf_backend_gc_mark_hook tilepro_elf_gc_mark_hook 3750 1.8 christos #define elf_backend_plt_sym_val tilepro_elf_plt_sym_val 3751 1.1 christos #define elf_info_to_howto_rel NULL 3752 1.1 christos #define elf_info_to_howto tilepro_info_to_howto_rela 3753 1.1 christos #define elf_backend_grok_prstatus tilepro_elf_grok_prstatus 3754 1.1 christos #define elf_backend_grok_psinfo tilepro_elf_grok_psinfo 3755 1.1 christos #define elf_backend_additional_program_headers tilepro_additional_program_headers 3756 1.1 christos 3757 1.1 christos #define bfd_elf32_mkobject tilepro_elf_mkobject 3758 1.1 christos 3759 1.1 christos #define elf_backend_init_index_section _bfd_elf_init_1_index_section 3760 1.1 christos 3761 1.1 christos #define elf_backend_can_gc_sections 1 3762 1.1 christos #define elf_backend_can_refcount 1 3763 1.1 christos #define elf_backend_want_got_plt 1 3764 1.1 christos #define elf_backend_plt_readonly 1 3765 1.7 christos /* Align PLT mod 64 byte L2 line size. */ 3766 1.1 christos #define elf_backend_plt_alignment 6 3767 1.1 christos #define elf_backend_want_plt_sym 1 3768 1.1 christos #define elf_backend_got_header_size GOT_ENTRY_SIZE 3769 1.1 christos #define elf_backend_want_dynrelro 1 3770 #define elf_backend_rela_normal 1 3771 #define elf_backend_default_execstack 0 3772 3773 #include "elf32-target.h" 3774