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