1 1.1 skrll /* FRV-specific support for 32-bit ELF. 2 1.1.1.12 christos Copyright (C) 2002-2026 Free Software Foundation, Inc. 3 1.1 skrll 4 1.1 skrll This file is part of BFD, the Binary File Descriptor library. 5 1.1 skrll 6 1.1 skrll This program is free software; you can redistribute it and/or modify 7 1.1 skrll it under the terms of the GNU General Public License as published by 8 1.1 skrll the Free Software Foundation; either version 3 of the License, or 9 1.1 skrll (at your option) any later version. 10 1.1 skrll 11 1.1 skrll This program is distributed in the hope that it will be useful, 12 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 skrll GNU General Public License for more details. 15 1.1 skrll 16 1.1 skrll You should have received a copy of the GNU General Public License 17 1.1 skrll along with this program; if not, write to the Free Software 18 1.1 skrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 1.1 skrll MA 02110-1301, USA. */ 20 1.1 skrll 21 1.1 skrll #include "sysdep.h" 22 1.1 skrll #include "bfd.h" 23 1.1 skrll #include "libbfd.h" 24 1.1 skrll #include "elf-bfd.h" 25 1.1 skrll #include "elf/frv.h" 26 1.1.1.2 christos #include "dwarf2.h" 27 1.1 skrll #include "hashtab.h" 28 1.1.1.7 christos #include "libiberty.h" 29 1.1 skrll 30 1.1 skrll /* Forward declarations. */ 31 1.1.1.3 christos 32 1.1 skrll 33 1.1 skrll static reloc_howto_type elf32_frv_howto_table [] = 34 1.1 skrll { 35 1.1 skrll /* This reloc does nothing. */ 36 1.1 skrll HOWTO (R_FRV_NONE, /* type */ 37 1.1 skrll 0, /* rightshift */ 38 1.1.1.9 christos 0, /* size */ 39 1.1.1.4 christos 0, /* bitsize */ 40 1.1.1.9 christos false, /* pc_relative */ 41 1.1 skrll 0, /* bitpos */ 42 1.1.1.4 christos complain_overflow_dont, /* complain_on_overflow */ 43 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 44 1.1 skrll "R_FRV_NONE", /* name */ 45 1.1.1.9 christos false, /* partial_inplace */ 46 1.1 skrll 0, /* src_mask */ 47 1.1 skrll 0, /* dst_mask */ 48 1.1.1.9 christos false), /* pcrel_offset */ 49 1.1 skrll 50 1.1 skrll /* A 32 bit absolute relocation. */ 51 1.1 skrll HOWTO (R_FRV_32, /* type */ 52 1.1 skrll 0, /* rightshift */ 53 1.1.1.9 christos 4, /* size */ 54 1.1 skrll 32, /* bitsize */ 55 1.1.1.9 christos false, /* pc_relative */ 56 1.1 skrll 0, /* bitpos */ 57 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 58 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 59 1.1 skrll "R_FRV_32", /* name */ 60 1.1.1.9 christos false, /* partial_inplace */ 61 1.1 skrll 0xffffffff, /* src_mask */ 62 1.1 skrll 0xffffffff, /* dst_mask */ 63 1.1.1.9 christos false), /* pcrel_offset */ 64 1.1 skrll 65 1.1 skrll /* A 16 bit pc-relative relocation. */ 66 1.1 skrll HOWTO (R_FRV_LABEL16, /* type */ 67 1.1 skrll 2, /* rightshift */ 68 1.1.1.9 christos 4, /* size */ 69 1.1 skrll 16, /* bitsize */ 70 1.1.1.9 christos true, /* pc_relative */ 71 1.1 skrll 0, /* bitpos */ 72 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 73 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 74 1.1 skrll "R_FRV_LABEL16", /* name */ 75 1.1.1.9 christos false, /* partial_inplace */ 76 1.1 skrll 0xffff, /* src_mask */ 77 1.1 skrll 0xffff, /* dst_mask */ 78 1.1.1.9 christos true), /* pcrel_offset */ 79 1.1 skrll 80 1.1 skrll /* A 24-bit pc-relative relocation. */ 81 1.1 skrll HOWTO (R_FRV_LABEL24, /* type */ 82 1.1 skrll 2, /* rightshift */ 83 1.1.1.9 christos 4, /* size */ 84 1.1 skrll 26, /* bitsize */ 85 1.1.1.9 christos true, /* pc_relative */ 86 1.1 skrll 0, /* bitpos */ 87 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 88 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 89 1.1 skrll "R_FRV_LABEL24", /* name */ 90 1.1.1.9 christos false, /* partial_inplace */ 91 1.1 skrll 0x7e03ffff, /* src_mask */ 92 1.1 skrll 0x7e03ffff, /* dst_mask */ 93 1.1.1.9 christos true), /* pcrel_offset */ 94 1.1 skrll 95 1.1 skrll HOWTO (R_FRV_LO16, /* type */ 96 1.1 skrll 0, /* rightshift */ 97 1.1.1.9 christos 4, /* size */ 98 1.1 skrll 16, /* bitsize */ 99 1.1.1.9 christos false, /* pc_relative */ 100 1.1 skrll 0, /* bitpos */ 101 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 102 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 103 1.1 skrll "R_FRV_LO16", /* name */ 104 1.1.1.9 christos false, /* partial_inplace */ 105 1.1 skrll 0xffff, /* src_mask */ 106 1.1 skrll 0xffff, /* dst_mask */ 107 1.1.1.9 christos false), /* pcrel_offset */ 108 1.1 skrll 109 1.1 skrll HOWTO (R_FRV_HI16, /* type */ 110 1.1 skrll 0, /* rightshift */ 111 1.1.1.9 christos 4, /* size */ 112 1.1 skrll 16, /* bitsize */ 113 1.1.1.9 christos false, /* pc_relative */ 114 1.1 skrll 0, /* bitpos */ 115 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 116 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 117 1.1 skrll "R_FRV_HI16", /* name */ 118 1.1.1.9 christos false, /* partial_inplace */ 119 1.1 skrll 0xffff, /* src_mask */ 120 1.1 skrll 0xffff, /* dst_mask */ 121 1.1.1.9 christos false), /* pcrel_offset */ 122 1.1 skrll 123 1.1 skrll HOWTO (R_FRV_GPREL12, /* type */ 124 1.1 skrll 0, /* rightshift */ 125 1.1.1.9 christos 4, /* size */ 126 1.1 skrll 12, /* bitsize */ 127 1.1.1.9 christos false, /* pc_relative */ 128 1.1 skrll 0, /* bitpos */ 129 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 130 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 131 1.1 skrll "R_FRV_GPREL12", /* name */ 132 1.1.1.9 christos false, /* partial_inplace */ 133 1.1 skrll 0xfff, /* src_mask */ 134 1.1 skrll 0xfff, /* dst_mask */ 135 1.1.1.9 christos false), /* pcrel_offset */ 136 1.1 skrll 137 1.1 skrll HOWTO (R_FRV_GPRELU12, /* type */ 138 1.1 skrll 0, /* rightshift */ 139 1.1.1.9 christos 4, /* size */ 140 1.1 skrll 12, /* bitsize */ 141 1.1.1.9 christos false, /* pc_relative */ 142 1.1 skrll 0, /* bitpos */ 143 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 144 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 145 1.1 skrll "R_FRV_GPRELU12", /* name */ 146 1.1.1.9 christos false, /* partial_inplace */ 147 1.1 skrll 0xfff, /* src_mask */ 148 1.1 skrll 0x3f03f, /* dst_mask */ 149 1.1.1.9 christos false), /* pcrel_offset */ 150 1.1 skrll 151 1.1 skrll HOWTO (R_FRV_GPREL32, /* type */ 152 1.1 skrll 0, /* rightshift */ 153 1.1.1.9 christos 4, /* size */ 154 1.1 skrll 32, /* bitsize */ 155 1.1.1.9 christos false, /* pc_relative */ 156 1.1 skrll 0, /* bitpos */ 157 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 158 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 159 1.1 skrll "R_FRV_GPREL32", /* name */ 160 1.1.1.9 christos false, /* partial_inplace */ 161 1.1 skrll 0xffffffff, /* src_mask */ 162 1.1 skrll 0xffffffff, /* dst_mask */ 163 1.1.1.9 christos false), /* pcrel_offset */ 164 1.1 skrll 165 1.1 skrll HOWTO (R_FRV_GPRELHI, /* type */ 166 1.1 skrll 0, /* rightshift */ 167 1.1.1.9 christos 4, /* size */ 168 1.1 skrll 16, /* bitsize */ 169 1.1.1.9 christos false, /* pc_relative */ 170 1.1 skrll 0, /* bitpos */ 171 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 172 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 173 1.1 skrll "R_FRV_GPRELHI", /* name */ 174 1.1.1.9 christos false, /* partial_inplace */ 175 1.1 skrll 0xffff, /* src_mask */ 176 1.1 skrll 0xffff, /* dst_mask */ 177 1.1.1.9 christos false), /* pcrel_offset */ 178 1.1 skrll 179 1.1 skrll HOWTO (R_FRV_GPRELLO, /* type */ 180 1.1 skrll 0, /* rightshift */ 181 1.1.1.9 christos 4, /* size */ 182 1.1 skrll 16, /* bitsize */ 183 1.1.1.9 christos false, /* pc_relative */ 184 1.1 skrll 0, /* bitpos */ 185 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 186 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 187 1.1 skrll "R_FRV_GPRELLO", /* name */ 188 1.1.1.9 christos false, /* partial_inplace */ 189 1.1 skrll 0xffff, /* src_mask */ 190 1.1 skrll 0xffff, /* dst_mask */ 191 1.1.1.9 christos false), /* pcrel_offset */ 192 1.1 skrll 193 1.1 skrll /* A 12-bit signed operand with the GOT offset for the address of 194 1.1 skrll the symbol. */ 195 1.1 skrll HOWTO (R_FRV_GOT12, /* type */ 196 1.1 skrll 0, /* rightshift */ 197 1.1.1.9 christos 4, /* size */ 198 1.1 skrll 12, /* bitsize */ 199 1.1.1.9 christos false, /* pc_relative */ 200 1.1 skrll 0, /* bitpos */ 201 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 202 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 203 1.1 skrll "R_FRV_GOT12", /* name */ 204 1.1.1.9 christos false, /* partial_inplace */ 205 1.1 skrll 0xfff, /* src_mask */ 206 1.1 skrll 0xfff, /* dst_mask */ 207 1.1.1.9 christos false), /* pcrel_offset */ 208 1.1 skrll 209 1.1 skrll /* The upper 16 bits of the GOT offset for the address of the 210 1.1 skrll symbol. */ 211 1.1 skrll HOWTO (R_FRV_GOTHI, /* type */ 212 1.1 skrll 0, /* rightshift */ 213 1.1.1.9 christos 4, /* size */ 214 1.1 skrll 16, /* bitsize */ 215 1.1.1.9 christos false, /* pc_relative */ 216 1.1 skrll 0, /* bitpos */ 217 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 218 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 219 1.1 skrll "R_FRV_GOTHI", /* name */ 220 1.1.1.9 christos false, /* partial_inplace */ 221 1.1 skrll 0xffff, /* src_mask */ 222 1.1 skrll 0xffff, /* dst_mask */ 223 1.1.1.9 christos false), /* pcrel_offset */ 224 1.1 skrll 225 1.1 skrll /* The lower 16 bits of the GOT offset for the address of the 226 1.1 skrll symbol. */ 227 1.1 skrll HOWTO (R_FRV_GOTLO, /* type */ 228 1.1 skrll 0, /* rightshift */ 229 1.1.1.9 christos 4, /* size */ 230 1.1 skrll 16, /* bitsize */ 231 1.1.1.9 christos false, /* pc_relative */ 232 1.1 skrll 0, /* bitpos */ 233 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 234 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 235 1.1 skrll "R_FRV_GOTLO", /* name */ 236 1.1.1.9 christos false, /* partial_inplace */ 237 1.1 skrll 0xffff, /* src_mask */ 238 1.1 skrll 0xffff, /* dst_mask */ 239 1.1.1.9 christos false), /* pcrel_offset */ 240 1.1 skrll 241 1.1 skrll /* The 32-bit address of the canonical descriptor of a function. */ 242 1.1 skrll HOWTO (R_FRV_FUNCDESC, /* type */ 243 1.1 skrll 0, /* rightshift */ 244 1.1.1.9 christos 4, /* size */ 245 1.1 skrll 32, /* bitsize */ 246 1.1.1.9 christos false, /* pc_relative */ 247 1.1 skrll 0, /* bitpos */ 248 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 249 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 250 1.1 skrll "R_FRV_FUNCDESC", /* name */ 251 1.1.1.9 christos false, /* partial_inplace */ 252 1.1 skrll 0xffffffff, /* src_mask */ 253 1.1 skrll 0xffffffff, /* dst_mask */ 254 1.1.1.9 christos false), /* pcrel_offset */ 255 1.1 skrll 256 1.1 skrll /* A 12-bit signed operand with the GOT offset for the address of 257 1.1 skrll canonical descriptor of a function. */ 258 1.1 skrll HOWTO (R_FRV_FUNCDESC_GOT12, /* type */ 259 1.1 skrll 0, /* rightshift */ 260 1.1.1.9 christos 4, /* size */ 261 1.1 skrll 12, /* bitsize */ 262 1.1.1.9 christos false, /* pc_relative */ 263 1.1 skrll 0, /* bitpos */ 264 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 265 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 266 1.1 skrll "R_FRV_FUNCDESC_GOT12", /* name */ 267 1.1.1.9 christos false, /* partial_inplace */ 268 1.1 skrll 0xfff, /* src_mask */ 269 1.1 skrll 0xfff, /* dst_mask */ 270 1.1.1.9 christos false), /* pcrel_offset */ 271 1.1 skrll 272 1.1 skrll /* The upper 16 bits of the GOT offset for the address of the 273 1.1 skrll canonical descriptor of a function. */ 274 1.1 skrll HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */ 275 1.1 skrll 0, /* rightshift */ 276 1.1.1.9 christos 4, /* size */ 277 1.1 skrll 16, /* bitsize */ 278 1.1.1.9 christos false, /* pc_relative */ 279 1.1 skrll 0, /* bitpos */ 280 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 281 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 282 1.1 skrll "R_FRV_FUNCDESC_GOTHI", /* name */ 283 1.1.1.9 christos false, /* partial_inplace */ 284 1.1 skrll 0xffff, /* src_mask */ 285 1.1 skrll 0xffff, /* dst_mask */ 286 1.1.1.9 christos false), /* pcrel_offset */ 287 1.1 skrll 288 1.1 skrll /* The lower 16 bits of the GOT offset for the address of the 289 1.1 skrll canonical descriptor of a function. */ 290 1.1 skrll HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */ 291 1.1 skrll 0, /* rightshift */ 292 1.1.1.9 christos 4, /* size */ 293 1.1 skrll 16, /* bitsize */ 294 1.1.1.9 christos false, /* pc_relative */ 295 1.1 skrll 0, /* bitpos */ 296 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 297 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 298 1.1 skrll "R_FRV_FUNCDESC_GOTLO", /* name */ 299 1.1.1.9 christos false, /* partial_inplace */ 300 1.1 skrll 0xffff, /* src_mask */ 301 1.1 skrll 0xffff, /* dst_mask */ 302 1.1.1.9 christos false), /* pcrel_offset */ 303 1.1 skrll 304 1.1 skrll /* The 64-bit descriptor of a function. */ 305 1.1 skrll HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ 306 1.1 skrll 0, /* rightshift */ 307 1.1.1.9 christos 4, /* size */ 308 1.1 skrll 64, /* bitsize */ 309 1.1.1.9 christos false, /* pc_relative */ 310 1.1 skrll 0, /* bitpos */ 311 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 312 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 313 1.1 skrll "R_FRV_FUNCDESC_VALUE", /* name */ 314 1.1.1.9 christos false, /* partial_inplace */ 315 1.1 skrll 0xffffffff, /* src_mask */ 316 1.1 skrll 0xffffffff, /* dst_mask */ 317 1.1.1.9 christos false), /* pcrel_offset */ 318 1.1 skrll 319 1.1 skrll /* A 12-bit signed operand with the GOT offset for the address of 320 1.1 skrll canonical descriptor of a function. */ 321 1.1 skrll HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */ 322 1.1 skrll 0, /* rightshift */ 323 1.1.1.9 christos 4, /* size */ 324 1.1 skrll 12, /* bitsize */ 325 1.1.1.9 christos false, /* pc_relative */ 326 1.1 skrll 0, /* bitpos */ 327 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 328 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 329 1.1 skrll "R_FRV_FUNCDESC_GOTOFF12", /* name */ 330 1.1.1.9 christos false, /* partial_inplace */ 331 1.1 skrll 0xfff, /* src_mask */ 332 1.1 skrll 0xfff, /* dst_mask */ 333 1.1.1.9 christos false), /* pcrel_offset */ 334 1.1 skrll 335 1.1 skrll /* The upper 16 bits of the GOT offset for the address of the 336 1.1 skrll canonical descriptor of a function. */ 337 1.1 skrll HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */ 338 1.1 skrll 0, /* rightshift */ 339 1.1.1.9 christos 4, /* size */ 340 1.1 skrll 16, /* bitsize */ 341 1.1.1.9 christos false, /* pc_relative */ 342 1.1 skrll 0, /* bitpos */ 343 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 344 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 345 1.1 skrll "R_FRV_FUNCDESC_GOTOFFHI", /* name */ 346 1.1.1.9 christos false, /* partial_inplace */ 347 1.1 skrll 0xffff, /* src_mask */ 348 1.1 skrll 0xffff, /* dst_mask */ 349 1.1.1.9 christos false), /* pcrel_offset */ 350 1.1 skrll 351 1.1 skrll /* The lower 16 bits of the GOT offset for the address of the 352 1.1 skrll canonical descriptor of a function. */ 353 1.1 skrll HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */ 354 1.1 skrll 0, /* rightshift */ 355 1.1.1.9 christos 4, /* size */ 356 1.1 skrll 16, /* bitsize */ 357 1.1.1.9 christos false, /* pc_relative */ 358 1.1 skrll 0, /* bitpos */ 359 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 360 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 361 1.1 skrll "R_FRV_FUNCDESC_GOTOFFLO", /* name */ 362 1.1.1.9 christos false, /* partial_inplace */ 363 1.1 skrll 0xffff, /* src_mask */ 364 1.1 skrll 0xffff, /* dst_mask */ 365 1.1.1.9 christos false), /* pcrel_offset */ 366 1.1 skrll 367 1.1 skrll /* A 12-bit signed operand with the GOT offset for the address of 368 1.1 skrll the symbol. */ 369 1.1 skrll HOWTO (R_FRV_GOTOFF12, /* type */ 370 1.1 skrll 0, /* rightshift */ 371 1.1.1.9 christos 4, /* size */ 372 1.1 skrll 12, /* bitsize */ 373 1.1.1.9 christos false, /* pc_relative */ 374 1.1 skrll 0, /* bitpos */ 375 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 376 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 377 1.1 skrll "R_FRV_GOTOFF12", /* name */ 378 1.1.1.9 christos false, /* partial_inplace */ 379 1.1 skrll 0xfff, /* src_mask */ 380 1.1 skrll 0xfff, /* dst_mask */ 381 1.1.1.9 christos false), /* pcrel_offset */ 382 1.1 skrll 383 1.1 skrll /* The upper 16 bits of the GOT offset for the address of the 384 1.1 skrll symbol. */ 385 1.1 skrll HOWTO (R_FRV_GOTOFFHI, /* type */ 386 1.1 skrll 0, /* rightshift */ 387 1.1.1.9 christos 4, /* size */ 388 1.1 skrll 16, /* bitsize */ 389 1.1.1.9 christos false, /* pc_relative */ 390 1.1 skrll 0, /* bitpos */ 391 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 392 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 393 1.1 skrll "R_FRV_GOTOFFHI", /* name */ 394 1.1.1.9 christos false, /* partial_inplace */ 395 1.1 skrll 0xffff, /* src_mask */ 396 1.1 skrll 0xffff, /* dst_mask */ 397 1.1.1.9 christos false), /* pcrel_offset */ 398 1.1 skrll 399 1.1 skrll /* The lower 16 bits of the GOT offset for the address of the 400 1.1 skrll symbol. */ 401 1.1 skrll HOWTO (R_FRV_GOTOFFLO, /* type */ 402 1.1 skrll 0, /* rightshift */ 403 1.1.1.9 christos 4, /* size */ 404 1.1 skrll 16, /* bitsize */ 405 1.1.1.9 christos false, /* pc_relative */ 406 1.1 skrll 0, /* bitpos */ 407 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 408 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 409 1.1 skrll "R_FRV_GOTOFFLO", /* name */ 410 1.1.1.9 christos false, /* partial_inplace */ 411 1.1 skrll 0xffff, /* src_mask */ 412 1.1 skrll 0xffff, /* dst_mask */ 413 1.1.1.9 christos false), /* pcrel_offset */ 414 1.1 skrll 415 1.1 skrll /* A 24-bit pc-relative relocation referencing the TLS PLT entry for 416 1.1 skrll a thread-local symbol. If the symbol number is 0, it refers to 417 1.1 skrll the module. */ 418 1.1 skrll HOWTO (R_FRV_GETTLSOFF, /* type */ 419 1.1 skrll 2, /* rightshift */ 420 1.1.1.9 christos 4, /* size */ 421 1.1 skrll 26, /* bitsize */ 422 1.1.1.9 christos true, /* pc_relative */ 423 1.1 skrll 0, /* bitpos */ 424 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 425 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 426 1.1 skrll "R_FRV_GETTLSOFF", /* name */ 427 1.1.1.9 christos false, /* partial_inplace */ 428 1.1 skrll 0x7e03ffff, /* src_mask */ 429 1.1 skrll 0x7e03ffff, /* dst_mask */ 430 1.1.1.9 christos true), /* pcrel_offset */ 431 1.1 skrll 432 1.1 skrll /* A 64-bit TLS descriptor for a symbol. This relocation is only 433 1.1 skrll valid as a REL, dynamic relocation. */ 434 1.1 skrll HOWTO (R_FRV_TLSDESC_VALUE, /* type */ 435 1.1 skrll 0, /* rightshift */ 436 1.1.1.9 christos 4, /* size */ 437 1.1 skrll 64, /* bitsize */ 438 1.1.1.9 christos false, /* pc_relative */ 439 1.1 skrll 0, /* bitpos */ 440 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 441 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 442 1.1 skrll "R_FRV_TLSDESC_VALUE", /* name */ 443 1.1.1.9 christos false, /* partial_inplace */ 444 1.1 skrll 0xffffffff, /* src_mask */ 445 1.1 skrll 0xffffffff, /* dst_mask */ 446 1.1.1.9 christos false), /* pcrel_offset */ 447 1.1 skrll 448 1.1 skrll /* A 12-bit signed operand with the GOT offset for the TLS 449 1.1 skrll descriptor of the symbol. */ 450 1.1 skrll HOWTO (R_FRV_GOTTLSDESC12, /* type */ 451 1.1 skrll 0, /* rightshift */ 452 1.1.1.9 christos 4, /* size */ 453 1.1 skrll 12, /* bitsize */ 454 1.1.1.9 christos false, /* pc_relative */ 455 1.1 skrll 0, /* bitpos */ 456 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 457 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 458 1.1 skrll "R_FRV_GOTTLSDESC12", /* name */ 459 1.1.1.9 christos false, /* partial_inplace */ 460 1.1 skrll 0xfff, /* src_mask */ 461 1.1 skrll 0xfff, /* dst_mask */ 462 1.1.1.9 christos false), /* pcrel_offset */ 463 1.1 skrll 464 1.1 skrll /* The upper 16 bits of the GOT offset for the TLS descriptor of the 465 1.1 skrll symbol. */ 466 1.1 skrll HOWTO (R_FRV_GOTTLSDESCHI, /* type */ 467 1.1 skrll 0, /* rightshift */ 468 1.1.1.9 christos 4, /* size */ 469 1.1 skrll 16, /* bitsize */ 470 1.1.1.9 christos false, /* pc_relative */ 471 1.1 skrll 0, /* bitpos */ 472 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 473 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 474 1.1 skrll "R_FRV_GOTTLSDESCHI", /* name */ 475 1.1.1.9 christos false, /* partial_inplace */ 476 1.1 skrll 0xffff, /* src_mask */ 477 1.1 skrll 0xffff, /* dst_mask */ 478 1.1.1.9 christos false), /* pcrel_offset */ 479 1.1 skrll 480 1.1 skrll /* The lower 16 bits of the GOT offset for the TLS descriptor of the 481 1.1 skrll symbol. */ 482 1.1 skrll HOWTO (R_FRV_GOTTLSDESCLO, /* type */ 483 1.1 skrll 0, /* rightshift */ 484 1.1.1.9 christos 4, /* size */ 485 1.1 skrll 16, /* bitsize */ 486 1.1.1.9 christos false, /* pc_relative */ 487 1.1 skrll 0, /* bitpos */ 488 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 489 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 490 1.1 skrll "R_FRV_GOTTLSDESCLO", /* name */ 491 1.1.1.9 christos false, /* partial_inplace */ 492 1.1 skrll 0xffff, /* src_mask */ 493 1.1 skrll 0xffff, /* dst_mask */ 494 1.1.1.9 christos false), /* pcrel_offset */ 495 1.1 skrll 496 1.1 skrll /* A 12-bit signed operand with the offset from the module base 497 1.1 skrll address to the thread-local symbol address. */ 498 1.1 skrll HOWTO (R_FRV_TLSMOFF12, /* type */ 499 1.1 skrll 0, /* rightshift */ 500 1.1.1.9 christos 4, /* size */ 501 1.1 skrll 12, /* bitsize */ 502 1.1.1.9 christos false, /* pc_relative */ 503 1.1 skrll 0, /* bitpos */ 504 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 505 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 506 1.1 skrll "R_FRV_TLSMOFF12", /* name */ 507 1.1.1.9 christos false, /* partial_inplace */ 508 1.1 skrll 0xfff, /* src_mask */ 509 1.1 skrll 0xfff, /* dst_mask */ 510 1.1.1.9 christos false), /* pcrel_offset */ 511 1.1 skrll 512 1.1 skrll /* The upper 16 bits of the offset from the module base address to 513 1.1 skrll the thread-local symbol address. */ 514 1.1 skrll HOWTO (R_FRV_TLSMOFFHI, /* type */ 515 1.1 skrll 0, /* rightshift */ 516 1.1.1.9 christos 4, /* size */ 517 1.1 skrll 16, /* bitsize */ 518 1.1.1.9 christos false, /* pc_relative */ 519 1.1 skrll 0, /* bitpos */ 520 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 521 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 522 1.1 skrll "R_FRV_TLSMOFFHI", /* name */ 523 1.1.1.9 christos false, /* partial_inplace */ 524 1.1 skrll 0xffff, /* src_mask */ 525 1.1 skrll 0xffff, /* dst_mask */ 526 1.1.1.9 christos false), /* pcrel_offset */ 527 1.1 skrll 528 1.1 skrll /* The lower 16 bits of the offset from the module base address to 529 1.1 skrll the thread-local symbol address. */ 530 1.1 skrll HOWTO (R_FRV_TLSMOFFLO, /* type */ 531 1.1 skrll 0, /* rightshift */ 532 1.1.1.9 christos 4, /* size */ 533 1.1 skrll 16, /* bitsize */ 534 1.1.1.9 christos false, /* pc_relative */ 535 1.1 skrll 0, /* bitpos */ 536 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 537 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 538 1.1 skrll "R_FRV_TLSMOFFLO", /* name */ 539 1.1.1.9 christos false, /* partial_inplace */ 540 1.1 skrll 0xffff, /* src_mask */ 541 1.1 skrll 0xffff, /* dst_mask */ 542 1.1.1.9 christos false), /* pcrel_offset */ 543 1.1 skrll 544 1.1 skrll /* A 12-bit signed operand with the GOT offset for the TLSOFF entry 545 1.1 skrll for a symbol. */ 546 1.1 skrll HOWTO (R_FRV_GOTTLSOFF12, /* type */ 547 1.1 skrll 0, /* rightshift */ 548 1.1.1.9 christos 4, /* size */ 549 1.1 skrll 12, /* bitsize */ 550 1.1.1.9 christos false, /* pc_relative */ 551 1.1 skrll 0, /* bitpos */ 552 1.1 skrll complain_overflow_signed, /* complain_on_overflow */ 553 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 554 1.1 skrll "R_FRV_GOTTLSOFF12", /* name */ 555 1.1.1.9 christos false, /* partial_inplace */ 556 1.1 skrll 0xfff, /* src_mask */ 557 1.1 skrll 0xfff, /* dst_mask */ 558 1.1.1.9 christos false), /* pcrel_offset */ 559 1.1 skrll 560 1.1 skrll /* The upper 16 bits of the GOT offset for the TLSOFF entry for a 561 1.1 skrll symbol. */ 562 1.1 skrll HOWTO (R_FRV_GOTTLSOFFHI, /* type */ 563 1.1 skrll 0, /* rightshift */ 564 1.1.1.9 christos 4, /* size */ 565 1.1 skrll 16, /* bitsize */ 566 1.1.1.9 christos false, /* pc_relative */ 567 1.1 skrll 0, /* bitpos */ 568 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 569 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 570 1.1 skrll "R_FRV_GOTTLSOFFHI", /* name */ 571 1.1.1.9 christos false, /* partial_inplace */ 572 1.1 skrll 0xffff, /* src_mask */ 573 1.1 skrll 0xffff, /* dst_mask */ 574 1.1.1.9 christos false), /* pcrel_offset */ 575 1.1 skrll 576 1.1 skrll /* The lower 16 bits of the GOT offset for the TLSOFF entry for a 577 1.1 skrll symbol. */ 578 1.1 skrll HOWTO (R_FRV_GOTTLSOFFLO, /* type */ 579 1.1 skrll 0, /* rightshift */ 580 1.1.1.9 christos 4, /* size */ 581 1.1 skrll 16, /* bitsize */ 582 1.1.1.9 christos false, /* pc_relative */ 583 1.1 skrll 0, /* bitpos */ 584 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 585 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 586 1.1 skrll "R_FRV_GOTTLSOFFLO", /* name */ 587 1.1.1.9 christos false, /* partial_inplace */ 588 1.1 skrll 0xffff, /* src_mask */ 589 1.1 skrll 0xffff, /* dst_mask */ 590 1.1.1.9 christos false), /* pcrel_offset */ 591 1.1 skrll 592 1.1 skrll /* The 32-bit offset from the thread pointer (not the module base 593 1.1 skrll address) to a thread-local symbol. */ 594 1.1 skrll HOWTO (R_FRV_TLSOFF, /* type */ 595 1.1 skrll 0, /* rightshift */ 596 1.1.1.9 christos 4, /* size */ 597 1.1 skrll 32, /* bitsize */ 598 1.1.1.9 christos false, /* pc_relative */ 599 1.1 skrll 0, /* bitpos */ 600 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 601 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 602 1.1 skrll "R_FRV_TLSOFF", /* name */ 603 1.1.1.9 christos false, /* partial_inplace */ 604 1.1 skrll 0xffffffff, /* src_mask */ 605 1.1 skrll 0xffffffff, /* dst_mask */ 606 1.1.1.9 christos false), /* pcrel_offset */ 607 1.1 skrll 608 1.1 skrll /* An annotation for linker relaxation, that denotes the 609 1.1 skrll symbol+addend whose TLS descriptor is referenced by the sum of 610 1.1 skrll the two input registers of an ldd instruction. */ 611 1.1 skrll HOWTO (R_FRV_TLSDESC_RELAX, /* type */ 612 1.1 skrll 0, /* rightshift */ 613 1.1.1.9 christos 4, /* size */ 614 1.1 skrll 0, /* bitsize */ 615 1.1.1.9 christos false, /* pc_relative */ 616 1.1 skrll 0, /* bitpos */ 617 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 618 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 619 1.1 skrll "R_FRV_TLSDESC_RELAX", /* name */ 620 1.1.1.9 christos false, /* partial_inplace */ 621 1.1 skrll 0, /* src_mask */ 622 1.1 skrll 0, /* dst_mask */ 623 1.1.1.9 christos false), /* pcrel_offset */ 624 1.1 skrll 625 1.1 skrll /* An annotation for linker relaxation, that denotes the 626 1.1 skrll symbol+addend whose TLS resolver entry point is given by the sum 627 1.1 skrll of the two register operands of an calll instruction. */ 628 1.1 skrll HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */ 629 1.1 skrll 0, /* rightshift */ 630 1.1.1.9 christos 4, /* size */ 631 1.1 skrll 0, /* bitsize */ 632 1.1.1.9 christos false, /* pc_relative */ 633 1.1 skrll 0, /* bitpos */ 634 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 635 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 636 1.1 skrll "R_FRV_GETTLSOFF_RELAX", /* name */ 637 1.1.1.9 christos false, /* partial_inplace */ 638 1.1 skrll 0, /* src_mask */ 639 1.1 skrll 0, /* dst_mask */ 640 1.1.1.9 christos false), /* pcrel_offset */ 641 1.1 skrll 642 1.1 skrll /* An annotation for linker relaxation, that denotes the 643 1.1 skrll symbol+addend whose TLS offset GOT entry is given by the sum of 644 1.1 skrll the two input registers of an ld instruction. */ 645 1.1 skrll HOWTO (R_FRV_TLSOFF_RELAX, /* type */ 646 1.1 skrll 0, /* rightshift */ 647 1.1.1.9 christos 4, /* size */ 648 1.1 skrll 0, /* bitsize */ 649 1.1.1.9 christos false, /* pc_relative */ 650 1.1 skrll 0, /* bitpos */ 651 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 652 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 653 1.1 skrll "R_FRV_TLSOFF_RELAX", /* name */ 654 1.1.1.9 christos false, /* partial_inplace */ 655 1.1 skrll 0, /* src_mask */ 656 1.1 skrll 0, /* dst_mask */ 657 1.1.1.9 christos false), /* pcrel_offset */ 658 1.1 skrll 659 1.1 skrll /* A 32-bit offset from the module base address to 660 1.1 skrll the thread-local symbol address. */ 661 1.1 skrll HOWTO (R_FRV_TLSMOFF, /* type */ 662 1.1 skrll 0, /* rightshift */ 663 1.1.1.9 christos 4, /* size */ 664 1.1 skrll 32, /* bitsize */ 665 1.1.1.9 christos false, /* pc_relative */ 666 1.1 skrll 0, /* bitpos */ 667 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 668 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 669 1.1 skrll "R_FRV_TLSMOFF", /* name */ 670 1.1.1.9 christos false, /* partial_inplace */ 671 1.1 skrll 0xffffffff, /* src_mask */ 672 1.1 skrll 0xffffffff, /* dst_mask */ 673 1.1.1.9 christos false), /* pcrel_offset */ 674 1.1 skrll }; 675 1.1 skrll 676 1.1 skrll /* GNU extension to record C++ vtable hierarchy. */ 677 1.1 skrll static reloc_howto_type elf32_frv_vtinherit_howto = 678 1.1 skrll HOWTO (R_FRV_GNU_VTINHERIT, /* type */ 679 1.1 skrll 0, /* rightshift */ 680 1.1.1.9 christos 4, /* size */ 681 1.1 skrll 0, /* bitsize */ 682 1.1.1.9 christos false, /* pc_relative */ 683 1.1 skrll 0, /* bitpos */ 684 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 685 1.1 skrll NULL, /* special_function */ 686 1.1 skrll "R_FRV_GNU_VTINHERIT", /* name */ 687 1.1.1.9 christos false, /* partial_inplace */ 688 1.1 skrll 0, /* src_mask */ 689 1.1 skrll 0, /* dst_mask */ 690 1.1.1.9 christos false); /* pcrel_offset */ 691 1.1 skrll 692 1.1 skrll /* GNU extension to record C++ vtable member usage. */ 693 1.1 skrll static reloc_howto_type elf32_frv_vtentry_howto = 694 1.1 skrll HOWTO (R_FRV_GNU_VTENTRY, /* type */ 695 1.1 skrll 0, /* rightshift */ 696 1.1.1.9 christos 4, /* size */ 697 1.1 skrll 0, /* bitsize */ 698 1.1.1.9 christos false, /* pc_relative */ 699 1.1 skrll 0, /* bitpos */ 700 1.1 skrll complain_overflow_dont, /* complain_on_overflow */ 701 1.1 skrll _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 702 1.1 skrll "R_FRV_GNU_VTENTRY", /* name */ 703 1.1.1.9 christos false, /* partial_inplace */ 704 1.1 skrll 0, /* src_mask */ 705 1.1 skrll 0, /* dst_mask */ 706 1.1.1.9 christos false); /* pcrel_offset */ 707 1.1 skrll 708 1.1 skrll /* The following 3 relocations are REL. The only difference to the 709 1.1.1.9 christos entries in the table above are that partial_inplace is true. */ 710 1.1 skrll static reloc_howto_type elf32_frv_rel_32_howto = 711 1.1 skrll HOWTO (R_FRV_32, /* type */ 712 1.1 skrll 0, /* rightshift */ 713 1.1.1.9 christos 4, /* size */ 714 1.1 skrll 32, /* bitsize */ 715 1.1.1.9 christos false, /* pc_relative */ 716 1.1 skrll 0, /* bitpos */ 717 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 718 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 719 1.1 skrll "R_FRV_32", /* name */ 720 1.1.1.9 christos true, /* partial_inplace */ 721 1.1 skrll 0xffffffff, /* src_mask */ 722 1.1 skrll 0xffffffff, /* dst_mask */ 723 1.1.1.9 christos false); /* pcrel_offset */ 724 1.1 skrll 725 1.1 skrll static reloc_howto_type elf32_frv_rel_funcdesc_howto = 726 1.1 skrll HOWTO (R_FRV_FUNCDESC, /* type */ 727 1.1 skrll 0, /* rightshift */ 728 1.1.1.9 christos 4, /* size */ 729 1.1 skrll 32, /* bitsize */ 730 1.1.1.9 christos false, /* pc_relative */ 731 1.1 skrll 0, /* bitpos */ 732 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 733 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 734 1.1 skrll "R_FRV_FUNCDESC", /* name */ 735 1.1.1.9 christos true, /* partial_inplace */ 736 1.1 skrll 0xffffffff, /* src_mask */ 737 1.1 skrll 0xffffffff, /* dst_mask */ 738 1.1.1.9 christos false); /* pcrel_offset */ 739 1.1 skrll 740 1.1 skrll static reloc_howto_type elf32_frv_rel_funcdesc_value_howto = 741 1.1 skrll HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ 742 1.1 skrll 0, /* rightshift */ 743 1.1.1.9 christos 4, /* size */ 744 1.1 skrll 64, /* bitsize */ 745 1.1.1.9 christos false, /* pc_relative */ 746 1.1 skrll 0, /* bitpos */ 747 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 748 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 749 1.1 skrll "R_FRV_FUNCDESC_VALUE", /* name */ 750 1.1.1.9 christos true, /* partial_inplace */ 751 1.1 skrll 0xffffffff, /* src_mask */ 752 1.1 skrll 0xffffffff, /* dst_mask */ 753 1.1.1.9 christos false); /* pcrel_offset */ 754 1.1 skrll 755 1.1 skrll static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto = 756 1.1 skrll /* A 64-bit TLS descriptor for a symbol. The first word resolves to 757 1.1 skrll an entry point, and the second resolves to a special argument. 758 1.1 skrll If the symbol turns out to be in static TLS, the entry point is a 759 1.1 skrll return instruction, and the special argument is the TLS offset 760 1.1 skrll for the symbol. If it's in dynamic TLS, the entry point is a TLS 761 1.1 skrll offset resolver, and the special argument is a pointer to a data 762 1.1 skrll structure allocated by the dynamic loader, containing the GOT 763 1.1 skrll address for the offset resolver, the module id, the offset within 764 1.1 skrll the module, and anything else the TLS offset resolver might need 765 1.1 skrll to determine the TLS offset for the symbol in the running 766 1.1 skrll thread. */ 767 1.1 skrll HOWTO (R_FRV_TLSDESC_VALUE, /* type */ 768 1.1 skrll 0, /* rightshift */ 769 1.1.1.9 christos 4, /* size */ 770 1.1 skrll 64, /* bitsize */ 771 1.1.1.9 christos false, /* pc_relative */ 772 1.1 skrll 0, /* bitpos */ 773 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 774 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 775 1.1 skrll "R_FRV_TLSDESC_VALUE", /* name */ 776 1.1.1.9 christos true, /* partial_inplace */ 777 1.1 skrll 0xffffffff, /* src_mask */ 778 1.1 skrll 0xffffffff, /* dst_mask */ 779 1.1.1.9 christos false); /* pcrel_offset */ 780 1.1 skrll 781 1.1 skrll static reloc_howto_type elf32_frv_rel_tlsoff_howto = 782 1.1 skrll /* The 32-bit offset from the thread pointer (not the module base 783 1.1 skrll address) to a thread-local symbol. */ 784 1.1 skrll HOWTO (R_FRV_TLSOFF, /* type */ 785 1.1 skrll 0, /* rightshift */ 786 1.1.1.9 christos 4, /* size */ 787 1.1 skrll 32, /* bitsize */ 788 1.1.1.9 christos false, /* pc_relative */ 789 1.1 skrll 0, /* bitpos */ 790 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */ 791 1.1 skrll bfd_elf_generic_reloc, /* special_function */ 792 1.1 skrll "R_FRV_TLSOFF", /* name */ 793 1.1.1.9 christos true, /* partial_inplace */ 794 1.1 skrll 0xffffffff, /* src_mask */ 795 1.1 skrll 0xffffffff, /* dst_mask */ 796 1.1.1.9 christos false); /* pcrel_offset */ 797 1.1 skrll 798 1.1 skrll 799 1.1 skrll 800 1.1.1.4 christos extern const bfd_target frv_elf32_fdpic_vec; 802 1.1 skrll #define IS_FDPIC(bfd) ((bfd)->xvec == &frv_elf32_fdpic_vec) 803 1.1 skrll 804 1.1 skrll /* An extension of the elf hash table data structure, containing some 805 1.1 skrll additional FRV-specific data. */ 806 1.1 skrll struct frvfdpic_elf_link_hash_table 807 1.1 skrll { 808 1.1 skrll struct elf_link_hash_table elf; 809 1.1 skrll 810 1.1 skrll /* A pointer to the .rofixup section. */ 811 1.1 skrll asection *sgotfixup; 812 1.1 skrll /* GOT base offset. */ 813 1.1 skrll bfd_vma got0; 814 1.1 skrll /* Location of the first non-lazy PLT entry, i.e., the number of 815 1.1 skrll bytes taken by lazy PLT entries. If locally-bound TLS 816 1.1 skrll descriptors require a ret instruction, it will be placed at this 817 1.1 skrll offset. */ 818 1.1 skrll bfd_vma plt0; 819 1.1 skrll /* A hash table holding information about which symbols were 820 1.1 skrll referenced with which PIC-related relocations. */ 821 1.1 skrll struct htab *relocs_info; 822 1.1 skrll /* Summary reloc information collected by 823 1.1 skrll _frvfdpic_count_got_plt_entries. */ 824 1.1 skrll struct _frvfdpic_dynamic_got_info *g; 825 1.1 skrll }; 826 1.1 skrll 827 1.1 skrll /* Get the FRV ELF linker hash table from a link_info structure. */ 828 1.1.1.2 christos 829 1.1.1.9 christos #define frvfdpic_hash_table(p) \ 830 1.1.1.9 christos ((is_elf_hash_table ((p)->hash) \ 831 1.1.1.9 christos && elf_hash_table_id (elf_hash_table (p)) == FRV_ELF_DATA) \ 832 1.1 skrll ? (struct frvfdpic_elf_link_hash_table *) (p)->hash : NULL) 833 1.1 skrll 834 1.1.1.6 christos #define frvfdpic_got_section(info) \ 835 1.1 skrll (frvfdpic_hash_table (info)->elf.sgot) 836 1.1.1.6 christos #define frvfdpic_gotrel_section(info) \ 837 1.1 skrll (frvfdpic_hash_table (info)->elf.srelgot) 838 1.1 skrll #define frvfdpic_gotfixup_section(info) \ 839 1.1 skrll (frvfdpic_hash_table (info)->sgotfixup) 840 1.1.1.6 christos #define frvfdpic_plt_section(info) \ 841 1.1 skrll (frvfdpic_hash_table (info)->elf.splt) 842 1.1.1.6 christos #define frvfdpic_pltrel_section(info) \ 843 1.1 skrll (frvfdpic_hash_table (info)->elf.srelplt) 844 1.1 skrll #define frvfdpic_relocs_info(info) \ 845 1.1 skrll (frvfdpic_hash_table (info)->relocs_info) 846 1.1 skrll #define frvfdpic_got_initial_offset(info) \ 847 1.1 skrll (frvfdpic_hash_table (info)->got0) 848 1.1 skrll #define frvfdpic_plt_initial_offset(info) \ 849 1.1 skrll (frvfdpic_hash_table (info)->plt0) 850 1.1 skrll #define frvfdpic_dynamic_got_plt_info(info) \ 851 1.1 skrll (frvfdpic_hash_table (info)->g) 852 1.1 skrll 853 1.1 skrll /* Currently it's the same, but if some day we have a reason to change 854 1.1 skrll it, we'd better be using a different macro. 855 1.1 skrll 856 1.1 skrll FIXME: if there's any TLS PLT entry that uses local-exec or 857 1.1 skrll initial-exec models, we could use the ret at the end of any of them 858 1.1 skrll instead of adding one more. */ 859 1.1 skrll #define frvfdpic_plt_tls_ret_offset(info) \ 860 1.1 skrll (frvfdpic_plt_initial_offset (info)) 861 1.1 skrll 862 1.1 skrll /* The name of the dynamic interpreter. This is put in the .interp 863 1.1 skrll section. */ 864 1.1 skrll 865 1.1 skrll #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" 866 1.1 skrll 867 1.1 skrll #define DEFAULT_STACK_SIZE 0x20000 868 1.1 skrll 869 1.1 skrll /* This structure is used to collect the number of entries present in 870 1.1 skrll each addressable range of the got. */ 871 1.1 skrll struct _frvfdpic_dynamic_got_info 872 1.1 skrll { 873 1.1 skrll /* Several bits of information about the current link. */ 874 1.1 skrll struct bfd_link_info *info; 875 1.1 skrll /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit 876 1.1 skrll ranges. */ 877 1.1 skrll bfd_vma got12, gotlos, gothilo; 878 1.1 skrll /* Total GOT size needed for function descriptor entries within the 12-, 879 1.1 skrll 16- or 32-bit ranges. */ 880 1.1 skrll bfd_vma fd12, fdlos, fdhilo; 881 1.1 skrll /* Total GOT size needed by function descriptor entries referenced 882 1.1 skrll in PLT entries, that would be profitable to place in offsets 883 1.1 skrll close to the PIC register. */ 884 1.1 skrll bfd_vma fdplt; 885 1.1 skrll /* Total PLT size needed by lazy PLT entries. */ 886 1.1 skrll bfd_vma lzplt; 887 1.1 skrll /* Total GOT size needed for TLS descriptor entries within the 12-, 888 1.1 skrll 16- or 32-bit ranges. */ 889 1.1 skrll bfd_vma tlsd12, tlsdlos, tlsdhilo; 890 1.1 skrll /* Total GOT size needed by TLS descriptors referenced in PLT 891 1.1 skrll entries, that would be profitable to place in offers close to the 892 1.1 skrll PIC register. */ 893 1.1 skrll bfd_vma tlsdplt; 894 1.1 skrll /* Total PLT size needed by TLS lazy PLT entries. */ 895 1.1 skrll bfd_vma tlslzplt; 896 1.1 skrll /* Number of relocations carried over from input object files. */ 897 1.1 skrll unsigned long relocs; 898 1.1 skrll /* Number of fixups introduced by relocations in input object files. */ 899 1.1 skrll unsigned long fixups; 900 1.1 skrll /* The number of fixups that reference the ret instruction added to 901 1.1 skrll the PLT for locally-resolved TLS descriptors. */ 902 1.1 skrll unsigned long tls_ret_refs; 903 1.1 skrll }; 904 1.1 skrll 905 1.1 skrll /* This structure is used to assign offsets to got entries, function 906 1.1 skrll descriptors, plt entries and lazy plt entries. */ 907 1.1 skrll 908 1.1 skrll struct _frvfdpic_dynamic_got_plt_info 909 1.1 skrll { 910 1.1 skrll /* Summary information collected with _frvfdpic_count_got_plt_entries. */ 911 1.1 skrll struct _frvfdpic_dynamic_got_info g; 912 1.1 skrll 913 1.1 skrll /* For each addressable range, we record a MAX (positive) and MIN 914 1.1 skrll (negative) value. CUR is used to assign got entries, and it's 915 1.1 skrll incremented from an initial positive value to MAX, then from MIN 916 1.1 skrll to FDCUR (unless FDCUR wraps around first). FDCUR is used to 917 1.1 skrll assign function descriptors, and it's decreased from an initial 918 1.1 skrll non-positive value to MIN, then from MAX down to CUR (unless CUR 919 1.1 skrll wraps around first). All of MIN, MAX, CUR and FDCUR always point 920 1.1 skrll to even words. ODD, if non-zero, indicates an odd word to be 921 1.1 skrll used for the next got entry, otherwise CUR is used and 922 1.1 skrll incremented by a pair of words, wrapping around when it reaches 923 1.1 skrll MAX. FDCUR is decremented (and wrapped) before the next function 924 1.1 skrll descriptor is chosen. FDPLT indicates the number of remaining 925 1.1 skrll slots that can be used for function descriptors used only by PLT 926 1.1 skrll entries. 927 1.1 skrll 928 1.1 skrll TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR 929 1.1 skrll starts as MAX, and grows up to TMAX, then wraps around to TMIN 930 1.1 skrll and grows up to MIN. TLSDPLT indicates the number of remaining 931 1.1 skrll slots that can be used for TLS descriptors used only by TLS PLT 932 1.1 skrll entries. */ 933 1.1 skrll struct _frvfdpic_dynamic_got_alloc_data 934 1.1 skrll { 935 1.1 skrll bfd_signed_vma max, cur, odd, fdcur, min; 936 1.1 skrll bfd_signed_vma tmax, tcur, tmin; 937 1.1 skrll bfd_vma fdplt, tlsdplt; 938 1.1 skrll } got12, gotlos, gothilo; 939 1.1 skrll }; 940 1.1 skrll 941 1.1 skrll /* Create an FRV ELF linker hash table. */ 942 1.1 skrll 943 1.1 skrll static struct bfd_link_hash_table * 944 1.1 skrll frvfdpic_elf_link_hash_table_create (bfd *abfd) 945 1.1 skrll { 946 1.1.1.9 christos struct frvfdpic_elf_link_hash_table *ret; 947 1.1 skrll size_t amt = sizeof (struct frvfdpic_elf_link_hash_table); 948 1.1.1.4 christos 949 1.1 skrll ret = bfd_zmalloc (amt); 950 1.1 skrll if (ret == NULL) 951 1.1 skrll return NULL; 952 1.1 skrll 953 1.1 skrll if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, 954 1.1.1.11 christos _bfd_elf_link_hash_newfunc, 955 1.1 skrll sizeof (struct elf_link_hash_entry))) 956 1.1 skrll { 957 1.1 skrll free (ret); 958 1.1 skrll return NULL; 959 1.1 skrll } 960 1.1 skrll 961 1.1 skrll return &ret->elf.root; 962 1.1 skrll } 963 1.1 skrll 964 1.1 skrll /* Decide whether a reference to a symbol can be resolved locally or 965 1.1 skrll not. If the symbol is protected, we want the local address, but 966 1.1 skrll its function descriptor must be assigned by the dynamic linker. */ 967 1.1 skrll #define FRVFDPIC_SYM_LOCAL(INFO, H) \ 968 1.1 skrll (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ 969 1.1 skrll || ! elf_hash_table (INFO)->dynamic_sections_created) 970 1.1 skrll #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \ 971 1.1 skrll ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) 972 1.1 skrll 973 1.1 skrll /* This structure collects information on what kind of GOT, PLT or 974 1.1 skrll function descriptors are required by relocations that reference a 975 1.1 skrll certain symbol. */ 976 1.1 skrll struct frvfdpic_relocs_info 977 1.1 skrll { 978 1.1 skrll /* The index of the symbol, as stored in the relocation r_info, if 979 1.1 skrll we have a local symbol; -1 otherwise. */ 980 1.1 skrll long symndx; 981 1.1 skrll union 982 1.1 skrll { 983 1.1 skrll /* The input bfd in which the symbol is defined, if it's a local 984 1.1 skrll symbol. */ 985 1.1 skrll bfd *abfd; 986 1.1 skrll /* If symndx == -1, the hash table entry corresponding to a global 987 1.1 skrll symbol (even if it turns out to bind locally, in which case it 988 1.1 skrll should ideally be replaced with section's symndx + addend). */ 989 1.1 skrll struct elf_link_hash_entry *h; 990 1.1 skrll } d; 991 1.1 skrll /* The addend of the relocation that references the symbol. */ 992 1.1 skrll bfd_vma addend; 993 1.1 skrll 994 1.1 skrll /* The fields above are used to identify an entry. The fields below 995 1.1 skrll contain information on how an entry is used and, later on, which 996 1.1 skrll locations it was assigned. */ 997 1.1 skrll /* The following 3 fields record whether the symbol+addend above was 998 1.1 skrll ever referenced with a GOT relocation. The 12 suffix indicates a 999 1.1 skrll GOT12 relocation; los is used for GOTLO relocations that are not 1000 1.1 skrll matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI 1001 1.1 skrll pairs. */ 1002 1.1 skrll unsigned got12:1; 1003 1.1 skrll unsigned gotlos:1; 1004 1.1 skrll unsigned gothilo:1; 1005 1.1 skrll /* Whether a FUNCDESC relocation references symbol+addend. */ 1006 1.1 skrll unsigned fd:1; 1007 1.1 skrll /* Whether a FUNCDESC_GOT relocation references symbol+addend. */ 1008 1.1 skrll unsigned fdgot12:1; 1009 1.1 skrll unsigned fdgotlos:1; 1010 1.1 skrll unsigned fdgothilo:1; 1011 1.1 skrll /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */ 1012 1.1 skrll unsigned fdgoff12:1; 1013 1.1 skrll unsigned fdgofflos:1; 1014 1.1 skrll unsigned fdgoffhilo:1; 1015 1.1 skrll /* Whether a GETTLSOFF relocation references symbol+addend. */ 1016 1.1 skrll unsigned tlsplt:1; 1017 1.1 skrll /* FIXME: we should probably add tlspltdesc, tlspltoff and 1018 1.1 skrll tlspltimm, to tell what kind of TLS PLT entry we're generating. 1019 1.1 skrll We might instead just pre-compute flags telling whether the 1020 1.1 skrll object is suitable for local exec, initial exec or general 1021 1.1 skrll dynamic addressing, and use that all over the place. We could 1022 1.1 skrll also try to do a better job of merging TLSOFF and TLSDESC entries 1023 1.1 skrll in main executables, but perhaps we can get rid of TLSDESC 1024 1.1 skrll entirely in them instead. */ 1025 1.1 skrll /* Whether a GOTTLSDESC relocation references symbol+addend. */ 1026 1.1 skrll unsigned tlsdesc12:1; 1027 1.1 skrll unsigned tlsdesclos:1; 1028 1.1 skrll unsigned tlsdeschilo:1; 1029 1.1 skrll /* Whether a GOTTLSOFF relocation references symbol+addend. */ 1030 1.1 skrll unsigned tlsoff12:1; 1031 1.1 skrll unsigned tlsofflos:1; 1032 1.1 skrll unsigned tlsoffhilo:1; 1033 1.1 skrll /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or 1034 1.1 skrll GOTOFFHI relocations. The addend doesn't really matter, since we 1035 1.1 skrll envision that this will only be used to check whether the symbol 1036 1.1 skrll is mapped to the same segment as the got. */ 1037 1.1 skrll unsigned gotoff:1; 1038 1.1 skrll /* Whether symbol+addend is referenced by a LABEL24 relocation. */ 1039 1.1 skrll unsigned call:1; 1040 1.1 skrll /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE 1041 1.1 skrll relocation. */ 1042 1.1 skrll unsigned sym:1; 1043 1.1 skrll /* Whether we need a PLT entry for a symbol. Should be implied by 1044 1.1 skrll something like: 1045 1.1 skrll (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */ 1046 1.1 skrll unsigned plt:1; 1047 1.1 skrll /* Whether a function descriptor should be created in this link unit 1048 1.1 skrll for symbol+addend. Should be implied by something like: 1049 1.1 skrll (plt || fdgotoff12 || fdgotofflos || fdgotofflohi 1050 1.1.1.6 christos || ((fd || fdgot12 || fdgotlos || fdgothilo) 1051 1.1 skrll && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */ 1052 1.1 skrll unsigned privfd:1; 1053 1.1 skrll /* Whether a lazy PLT entry is needed for this symbol+addend. 1054 1.1 skrll Should be implied by something like: 1055 1.1 skrll (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h) 1056 1.1 skrll && ! (info->flags & DF_BIND_NOW)) */ 1057 1.1 skrll unsigned lazyplt:1; 1058 1.1 skrll /* Whether we've already emitted GOT relocations and PLT entries as 1059 1.1 skrll needed for this symbol. */ 1060 1.1 skrll unsigned done:1; 1061 1.1 skrll 1062 1.1 skrll /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and 1063 1.1 skrll R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing 1064 1.1 skrll symbol+addend. */ 1065 1.1 skrll unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff; 1066 1.1 skrll 1067 1.1 skrll /* The number of .rofixups entries and dynamic relocations allocated 1068 1.1 skrll for this symbol, minus any that might have already been used. */ 1069 1.1 skrll unsigned fixups, dynrelocs; 1070 1.1 skrll 1071 1.1 skrll /* The offsets of the GOT entries assigned to symbol+addend, to the 1072 1.1 skrll function descriptor's address, and to a function descriptor, 1073 1.1 skrll respectively. Should be zero if unassigned. The offsets are 1074 1.1 skrll counted from the value that will be assigned to the PIC register, 1075 1.1 skrll not from the beginning of the .got section. */ 1076 1.1 skrll bfd_signed_vma got_entry, fdgot_entry, fd_entry; 1077 1.1 skrll /* The offsets of the PLT entries assigned to symbol+addend, 1078 1.1 skrll non-lazy and lazy, respectively. If unassigned, should be 1079 1.1 skrll (bfd_vma)-1. */ 1080 1.1 skrll bfd_vma plt_entry, lzplt_entry; 1081 1.1 skrll /* The offsets of the GOT entries for TLS offset and TLS descriptor. */ 1082 1.1 skrll bfd_signed_vma tlsoff_entry, tlsdesc_entry; 1083 1.1 skrll /* The offset of the TLS offset PLT entry. */ 1084 1.1 skrll bfd_vma tlsplt_entry; 1085 1.1 skrll }; 1086 1.1 skrll 1087 1.1 skrll /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */ 1088 1.1 skrll static hashval_t 1089 1.1 skrll frvfdpic_relocs_info_hash (const void *entry_) 1090 1.1 skrll { 1091 1.1 skrll const struct frvfdpic_relocs_info *entry = entry_; 1092 1.1 skrll 1093 1.1 skrll return (entry->symndx == -1 1094 1.1 skrll ? (long) entry->d.h->root.root.hash 1095 1.1 skrll : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend; 1096 1.1 skrll } 1097 1.1 skrll 1098 1.1 skrll /* Test whether the key fields of two frvfdpic_relocs_info entries are 1099 1.1 skrll identical. */ 1100 1.1 skrll static int 1101 1.1 skrll frvfdpic_relocs_info_eq (const void *entry1, const void *entry2) 1102 1.1 skrll { 1103 1.1 skrll const struct frvfdpic_relocs_info *e1 = entry1; 1104 1.1 skrll const struct frvfdpic_relocs_info *e2 = entry2; 1105 1.1 skrll 1106 1.1 skrll return e1->symndx == e2->symndx && e1->addend == e2->addend 1107 1.1 skrll && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd); 1108 1.1 skrll } 1109 1.1 skrll 1110 1.1 skrll /* Find or create an entry in a hash table HT that matches the key 1111 1.1 skrll fields of the given ENTRY. If it's not found, memory for a new 1112 1.1 skrll entry is allocated in ABFD's obstack. */ 1113 1.1 skrll static struct frvfdpic_relocs_info * 1114 1.1 skrll frvfdpic_relocs_info_find (struct htab *ht, 1115 1.1 skrll bfd *abfd, 1116 1.1 skrll const struct frvfdpic_relocs_info *entry, 1117 1.1 skrll enum insert_option insert) 1118 1.1 skrll { 1119 1.1 skrll struct frvfdpic_relocs_info **loc = 1120 1.1 skrll (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert); 1121 1.1 skrll 1122 1.1 skrll if (! loc) 1123 1.1 skrll return NULL; 1124 1.1 skrll 1125 1.1 skrll if (*loc) 1126 1.1 skrll return *loc; 1127 1.1 skrll 1128 1.1 skrll *loc = bfd_zalloc (abfd, sizeof (**loc)); 1129 1.1 skrll 1130 1.1 skrll if (! *loc) 1131 1.1 skrll return *loc; 1132 1.1 skrll 1133 1.1 skrll (*loc)->symndx = entry->symndx; 1134 1.1 skrll (*loc)->d = entry->d; 1135 1.1 skrll (*loc)->addend = entry->addend; 1136 1.1 skrll (*loc)->plt_entry = (bfd_vma)-1; 1137 1.1 skrll (*loc)->lzplt_entry = (bfd_vma)-1; 1138 1.1 skrll (*loc)->tlsplt_entry = (bfd_vma)-1; 1139 1.1 skrll 1140 1.1 skrll return *loc; 1141 1.1 skrll } 1142 1.1 skrll 1143 1.1 skrll /* Obtain the address of the entry in HT associated with H's symbol + 1144 1.1 skrll addend, creating a new entry if none existed. ABFD is only used 1145 1.1 skrll for memory allocation purposes. */ 1146 1.1 skrll inline static struct frvfdpic_relocs_info * 1147 1.1 skrll frvfdpic_relocs_info_for_global (struct htab *ht, 1148 1.1 skrll bfd *abfd, 1149 1.1 skrll struct elf_link_hash_entry *h, 1150 1.1 skrll bfd_vma addend, 1151 1.1 skrll enum insert_option insert) 1152 1.1 skrll { 1153 1.1 skrll struct frvfdpic_relocs_info entry; 1154 1.1 skrll 1155 1.1 skrll entry.symndx = -1; 1156 1.1 skrll entry.d.h = h; 1157 1.1 skrll entry.addend = addend; 1158 1.1 skrll 1159 1.1 skrll return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); 1160 1.1 skrll } 1161 1.1 skrll 1162 1.1 skrll /* Obtain the address of the entry in HT associated with the SYMNDXth 1163 1.1 skrll local symbol of the input bfd ABFD, plus the addend, creating a new 1164 1.1 skrll entry if none existed. */ 1165 1.1 skrll inline static struct frvfdpic_relocs_info * 1166 1.1 skrll frvfdpic_relocs_info_for_local (struct htab *ht, 1167 1.1 skrll bfd *abfd, 1168 1.1 skrll long symndx, 1169 1.1 skrll bfd_vma addend, 1170 1.1 skrll enum insert_option insert) 1171 1.1 skrll { 1172 1.1 skrll struct frvfdpic_relocs_info entry; 1173 1.1 skrll 1174 1.1 skrll entry.symndx = symndx; 1175 1.1 skrll entry.d.abfd = abfd; 1176 1.1 skrll entry.addend = addend; 1177 1.1 skrll 1178 1.1 skrll return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); 1179 1.1 skrll } 1180 1.1 skrll 1181 1.1 skrll /* Merge fields set by check_relocs() of two entries that end up being 1182 1.1 skrll mapped to the same (presumably global) symbol. */ 1183 1.1 skrll 1184 1.1 skrll inline static void 1185 1.1 skrll frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2, 1186 1.1 skrll struct frvfdpic_relocs_info const *e1) 1187 1.1 skrll { 1188 1.1 skrll e2->got12 |= e1->got12; 1189 1.1 skrll e2->gotlos |= e1->gotlos; 1190 1.1 skrll e2->gothilo |= e1->gothilo; 1191 1.1 skrll e2->fd |= e1->fd; 1192 1.1 skrll e2->fdgot12 |= e1->fdgot12; 1193 1.1 skrll e2->fdgotlos |= e1->fdgotlos; 1194 1.1 skrll e2->fdgothilo |= e1->fdgothilo; 1195 1.1 skrll e2->fdgoff12 |= e1->fdgoff12; 1196 1.1 skrll e2->fdgofflos |= e1->fdgofflos; 1197 1.1 skrll e2->fdgoffhilo |= e1->fdgoffhilo; 1198 1.1 skrll e2->tlsplt |= e1->tlsplt; 1199 1.1 skrll e2->tlsdesc12 |= e1->tlsdesc12; 1200 1.1 skrll e2->tlsdesclos |= e1->tlsdesclos; 1201 1.1 skrll e2->tlsdeschilo |= e1->tlsdeschilo; 1202 1.1 skrll e2->tlsoff12 |= e1->tlsoff12; 1203 1.1 skrll e2->tlsofflos |= e1->tlsofflos; 1204 1.1 skrll e2->tlsoffhilo |= e1->tlsoffhilo; 1205 1.1 skrll e2->gotoff |= e1->gotoff; 1206 1.1 skrll e2->call |= e1->call; 1207 1.1 skrll e2->sym |= e1->sym; 1208 1.1 skrll } 1209 1.1 skrll 1210 1.1 skrll /* Every block of 65535 lazy PLT entries shares a single call to the 1211 1.1 skrll resolver, inserted in the 32768th lazy PLT entry (i.e., entry # 1212 1.1 skrll 32767, counting from 0). All other lazy PLT entries branch to it 1213 1.1 skrll in a single instruction. */ 1214 1.1 skrll 1215 1.1 skrll #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4) 1216 1.1 skrll #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767) 1217 1.1 skrll 1218 1.1 skrll /* Add a dynamic relocation to the SRELOC section. */ 1219 1.1 skrll 1220 1.1 skrll inline static bfd_vma 1221 1.1 skrll _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset, 1222 1.1 skrll int reloc_type, long dynindx, bfd_vma addend, 1223 1.1 skrll struct frvfdpic_relocs_info *entry) 1224 1.1 skrll { 1225 1.1 skrll Elf_Internal_Rela outrel; 1226 1.1 skrll bfd_vma reloc_offset; 1227 1.1 skrll 1228 1.1 skrll outrel.r_offset = offset; 1229 1.1 skrll outrel.r_info = ELF32_R_INFO (dynindx, reloc_type); 1230 1.1 skrll outrel.r_addend = addend; 1231 1.1 skrll 1232 1.1 skrll reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel); 1233 1.1 skrll BFD_ASSERT (reloc_offset < sreloc->size); 1234 1.1 skrll bfd_elf32_swap_reloc_out (output_bfd, &outrel, 1235 1.1 skrll sreloc->contents + reloc_offset); 1236 1.1 skrll sreloc->reloc_count++; 1237 1.1 skrll 1238 1.1 skrll /* If the entry's index is zero, this relocation was probably to a 1239 1.1 skrll linkonce section that got discarded. We reserved a dynamic 1240 1.1 skrll relocation, but it was for another entry than the one we got at 1241 1.1 skrll the time of emitting the relocation. Unfortunately there's no 1242 1.1 skrll simple way for us to catch this situation, since the relocation 1243 1.1 skrll is cleared right before calling relocate_section, at which point 1244 1.1 skrll we no longer know what the relocation used to point to. */ 1245 1.1 skrll if (entry->symndx) 1246 1.1 skrll { 1247 1.1 skrll BFD_ASSERT (entry->dynrelocs > 0); 1248 1.1 skrll entry->dynrelocs--; 1249 1.1 skrll } 1250 1.1 skrll 1251 1.1 skrll return reloc_offset; 1252 1.1 skrll } 1253 1.1 skrll 1254 1.1 skrll /* Add a fixup to the ROFIXUP section. */ 1255 1.1 skrll 1256 1.1 skrll static bfd_vma 1257 1.1 skrll _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset, 1258 1.1 skrll struct frvfdpic_relocs_info *entry) 1259 1.1 skrll { 1260 1.1 skrll bfd_vma fixup_offset; 1261 1.1 skrll 1262 1.1 skrll if (rofixup->flags & SEC_EXCLUDE) 1263 1.1 skrll return -1; 1264 1.1 skrll 1265 1.1 skrll fixup_offset = rofixup->reloc_count * 4; 1266 1.1 skrll if (rofixup->contents) 1267 1.1 skrll { 1268 1.1 skrll BFD_ASSERT (fixup_offset < rofixup->size); 1269 1.1 skrll bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset); 1270 1.1 skrll } 1271 1.1 skrll rofixup->reloc_count++; 1272 1.1 skrll 1273 1.1 skrll if (entry && entry->symndx) 1274 1.1 skrll { 1275 1.1 skrll /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc 1276 1.1 skrll above. */ 1277 1.1 skrll BFD_ASSERT (entry->fixups > 0); 1278 1.1 skrll entry->fixups--; 1279 1.1 skrll } 1280 1.1 skrll 1281 1.1 skrll return fixup_offset; 1282 1.1 skrll } 1283 1.1 skrll 1284 1.1 skrll /* Find the segment number in which OSEC, and output section, is 1285 1.1 skrll located. */ 1286 1.1 skrll 1287 1.1 skrll static unsigned 1288 1.1 skrll _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec) 1289 1.1 skrll { 1290 1.1 skrll Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec); 1291 1.1 skrll 1292 1.1 skrll return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1; 1293 1.1 skrll } 1294 1.1.1.9 christos 1295 1.1 skrll inline static bool 1296 1.1 skrll _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec) 1297 1.1 skrll { 1298 1.1 skrll unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec); 1299 1.1 skrll 1300 1.1 skrll return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W); 1301 1.1 skrll } 1302 1.1 skrll 1303 1.1 skrll #define FRVFDPIC_TLS_BIAS (2048 - 16) 1304 1.1 skrll 1305 1.1 skrll /* Return the base VMA address which should be subtracted from real addresses 1306 1.1 skrll when resolving TLSMOFF relocation. 1307 1.1 skrll This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */ 1308 1.1 skrll 1309 1.1 skrll static bfd_vma 1310 1.1 skrll tls_biased_base (struct bfd_link_info *info) 1311 1.1 skrll { 1312 1.1 skrll /* If tls_sec is NULL, we should have signalled an error already. */ 1313 1.1 skrll if (elf_hash_table (info)->tls_sec == NULL) 1314 1.1 skrll return FRVFDPIC_TLS_BIAS; 1315 1.1 skrll return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS; 1316 1.1 skrll } 1317 1.1 skrll 1318 1.1 skrll /* Generate relocations for GOT entries, function descriptors, and 1319 1.1 skrll code for PLT and lazy PLT entries. */ 1320 1.1.1.9 christos 1321 1.1 skrll inline static bool 1322 1.1 skrll _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry, 1323 1.1 skrll bfd *output_bfd, 1324 1.1 skrll struct bfd_link_info *info, 1325 1.1 skrll asection *sec, 1326 1.1 skrll Elf_Internal_Sym *sym, 1327 1.1 skrll bfd_vma addend) 1328 1.1 skrll 1329 1.1 skrll { 1330 1.1 skrll bfd_vma fd_lazy_rel_offset = (bfd_vma)-1; 1331 1.1 skrll int dynindx = -1; 1332 1.1 skrll 1333 1.1.1.9 christos if (entry->done) 1334 1.1 skrll return true; 1335 1.1 skrll entry->done = 1; 1336 1.1 skrll 1337 1.1 skrll if (entry->got_entry || entry->fdgot_entry || entry->fd_entry 1338 1.1 skrll || entry->tlsoff_entry || entry->tlsdesc_entry) 1339 1.1 skrll { 1340 1.1 skrll /* If the symbol is dynamic, consider it for dynamic 1341 1.1 skrll relocations, otherwise decay to section + offset. */ 1342 1.1 skrll if (entry->symndx == -1 && entry->d.h->dynindx != -1) 1343 1.1 skrll dynindx = entry->d.h->dynindx; 1344 1.1 skrll else 1345 1.1 skrll { 1346 1.1 skrll if (sec 1347 1.1 skrll && sec->output_section 1348 1.1 skrll && ! bfd_is_abs_section (sec->output_section) 1349 1.1 skrll && ! bfd_is_und_section (sec->output_section)) 1350 1.1 skrll dynindx = elf_section_data (sec->output_section)->dynindx; 1351 1.1 skrll else 1352 1.1 skrll dynindx = 0; 1353 1.1 skrll } 1354 1.1 skrll } 1355 1.1 skrll 1356 1.1 skrll /* Generate relocation for GOT entry pointing to the symbol. */ 1357 1.1 skrll if (entry->got_entry) 1358 1.1 skrll { 1359 1.1 skrll int idx = dynindx; 1360 1.1 skrll bfd_vma ad = addend; 1361 1.1 skrll 1362 1.1 skrll /* If the symbol is dynamic but binds locally, use 1363 1.1 skrll section+offset. */ 1364 1.1 skrll if (sec && (entry->symndx != -1 1365 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1366 1.1 skrll { 1367 1.1 skrll if (entry->symndx == -1) 1368 1.1 skrll ad += entry->d.h->root.u.def.value; 1369 1.1 skrll else 1370 1.1 skrll ad += sym->st_value; 1371 1.1 skrll ad += sec->output_offset; 1372 1.1 skrll if (sec->output_section && elf_section_data (sec->output_section)) 1373 1.1 skrll idx = elf_section_data (sec->output_section)->dynindx; 1374 1.1 skrll else 1375 1.1 skrll idx = 0; 1376 1.1 skrll } 1377 1.1 skrll 1378 1.1 skrll /* If we're linking an executable at a fixed address, we can 1379 1.1 skrll omit the dynamic relocation as long as the symbol is local to 1380 1.1.1.4 christos this module. */ 1381 1.1 skrll if (bfd_link_pde (info) 1382 1.1 skrll && (entry->symndx != -1 1383 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1384 1.1 skrll { 1385 1.1 skrll if (sec) 1386 1.1 skrll ad += sec->output_section->vma; 1387 1.1 skrll if (entry->symndx != -1 1388 1.1 skrll || entry->d.h->root.type != bfd_link_hash_undefweak) 1389 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 1390 1.1 skrll frvfdpic_gotfixup_section (info), 1391 1.1 skrll frvfdpic_got_section (info)->output_section 1392 1.1 skrll ->vma 1393 1.1 skrll + frvfdpic_got_section (info)->output_offset 1394 1.1 skrll + frvfdpic_got_initial_offset (info) 1395 1.1 skrll + entry->got_entry, entry); 1396 1.1 skrll } 1397 1.1 skrll else 1398 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), 1399 1.1 skrll _bfd_elf_section_offset 1400 1.1 skrll (output_bfd, info, 1401 1.1 skrll frvfdpic_got_section (info), 1402 1.1 skrll frvfdpic_got_initial_offset (info) 1403 1.1 skrll + entry->got_entry) 1404 1.1 skrll + frvfdpic_got_section (info) 1405 1.1 skrll ->output_section->vma 1406 1.1 skrll + frvfdpic_got_section (info)->output_offset, 1407 1.1 skrll R_FRV_32, idx, ad, entry); 1408 1.1 skrll 1409 1.1 skrll bfd_put_32 (output_bfd, ad, 1410 1.1 skrll frvfdpic_got_section (info)->contents 1411 1.1 skrll + frvfdpic_got_initial_offset (info) 1412 1.1 skrll + entry->got_entry); 1413 1.1 skrll } 1414 1.1 skrll 1415 1.1 skrll /* Generate relocation for GOT entry pointing to a canonical 1416 1.1 skrll function descriptor. */ 1417 1.1 skrll if (entry->fdgot_entry) 1418 1.1 skrll { 1419 1.1 skrll int reloc, idx; 1420 1.1 skrll bfd_vma ad = 0; 1421 1.1 skrll 1422 1.1 skrll if (! (entry->symndx == -1 1423 1.1 skrll && entry->d.h->root.type == bfd_link_hash_undefweak 1424 1.1 skrll && FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1425 1.1 skrll { 1426 1.1 skrll /* If the symbol is dynamic and there may be dynamic symbol 1427 1.1 skrll resolution because we are, or are linked with, a shared 1428 1.1 skrll library, emit a FUNCDESC relocation such that the dynamic 1429 1.1 skrll linker will allocate the function descriptor. If the 1430 1.1 skrll symbol needs a non-local function descriptor but binds 1431 1.1 skrll locally (e.g., its visibility is protected, emit a 1432 1.1 skrll dynamic relocation decayed to section+offset. */ 1433 1.1 skrll if (entry->symndx == -1 1434 1.1 skrll && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h) 1435 1.1.1.4 christos && FRVFDPIC_SYM_LOCAL (info, entry->d.h) 1436 1.1 skrll && !bfd_link_pde (info)) 1437 1.1 skrll { 1438 1.1 skrll reloc = R_FRV_FUNCDESC; 1439 1.1 skrll idx = elf_section_data (entry->d.h->root.u.def.section 1440 1.1 skrll ->output_section)->dynindx; 1441 1.1 skrll ad = entry->d.h->root.u.def.section->output_offset 1442 1.1 skrll + entry->d.h->root.u.def.value; 1443 1.1 skrll } 1444 1.1 skrll else if (entry->symndx == -1 1445 1.1 skrll && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)) 1446 1.1 skrll { 1447 1.1 skrll reloc = R_FRV_FUNCDESC; 1448 1.1 skrll idx = dynindx; 1449 1.1 skrll ad = addend; 1450 1.1 skrll if (ad) 1451 1.1 skrll { 1452 1.1 skrll (*info->callbacks->reloc_dangerous) 1453 1.1 skrll (info, _("relocation requires zero addend"), 1454 1.1 skrll elf_hash_table (info)->dynobj, 1455 1.1 skrll frvfdpic_got_section (info), 1456 1.1.1.9 christos entry->fdgot_entry); 1457 1.1 skrll return false; 1458 1.1 skrll } 1459 1.1 skrll } 1460 1.1 skrll else 1461 1.1 skrll { 1462 1.1 skrll /* Otherwise, we know we have a private function descriptor, 1463 1.1 skrll so reference it directly. */ 1464 1.1 skrll if (elf_hash_table (info)->dynamic_sections_created) 1465 1.1 skrll BFD_ASSERT (entry->privfd); 1466 1.1 skrll reloc = R_FRV_32; 1467 1.1 skrll idx = elf_section_data (frvfdpic_got_section (info) 1468 1.1 skrll ->output_section)->dynindx; 1469 1.1 skrll ad = frvfdpic_got_section (info)->output_offset 1470 1.1 skrll + frvfdpic_got_initial_offset (info) + entry->fd_entry; 1471 1.1 skrll } 1472 1.1 skrll 1473 1.1 skrll /* If there is room for dynamic symbol resolution, emit the 1474 1.1 skrll dynamic relocation. However, if we're linking an 1475 1.1 skrll executable at a fixed location, we won't have emitted a 1476 1.1 skrll dynamic symbol entry for the got section, so idx will be 1477 1.1 skrll zero, which means we can and should compute the address 1478 1.1.1.4 christos of the private descriptor ourselves. */ 1479 1.1 skrll if (bfd_link_pde (info) 1480 1.1 skrll && (entry->symndx != -1 1481 1.1 skrll || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))) 1482 1.1 skrll { 1483 1.1 skrll ad += frvfdpic_got_section (info)->output_section->vma; 1484 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 1485 1.1 skrll frvfdpic_gotfixup_section (info), 1486 1.1 skrll frvfdpic_got_section (info) 1487 1.1 skrll ->output_section->vma 1488 1.1 skrll + frvfdpic_got_section (info) 1489 1.1 skrll ->output_offset 1490 1.1 skrll + frvfdpic_got_initial_offset (info) 1491 1.1 skrll + entry->fdgot_entry, entry); 1492 1.1 skrll } 1493 1.1 skrll else 1494 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, 1495 1.1 skrll frvfdpic_gotrel_section (info), 1496 1.1 skrll _bfd_elf_section_offset 1497 1.1 skrll (output_bfd, info, 1498 1.1 skrll frvfdpic_got_section (info), 1499 1.1 skrll frvfdpic_got_initial_offset (info) 1500 1.1 skrll + entry->fdgot_entry) 1501 1.1 skrll + frvfdpic_got_section (info) 1502 1.1 skrll ->output_section->vma 1503 1.1 skrll + frvfdpic_got_section (info) 1504 1.1 skrll ->output_offset, 1505 1.1 skrll reloc, idx, ad, entry); 1506 1.1 skrll } 1507 1.1 skrll 1508 1.1 skrll bfd_put_32 (output_bfd, ad, 1509 1.1 skrll frvfdpic_got_section (info)->contents 1510 1.1 skrll + frvfdpic_got_initial_offset (info) 1511 1.1 skrll + entry->fdgot_entry); 1512 1.1 skrll } 1513 1.1 skrll 1514 1.1 skrll /* Generate relocation to fill in a private function descriptor in 1515 1.1 skrll the GOT. */ 1516 1.1 skrll if (entry->fd_entry) 1517 1.1 skrll { 1518 1.1 skrll int idx = dynindx; 1519 1.1 skrll bfd_vma ad = addend; 1520 1.1 skrll bfd_vma ofst; 1521 1.1 skrll long lowword, highword; 1522 1.1 skrll 1523 1.1 skrll /* If the symbol is dynamic but binds locally, use 1524 1.1 skrll section+offset. */ 1525 1.1 skrll if (sec && (entry->symndx != -1 1526 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1527 1.1 skrll { 1528 1.1 skrll if (entry->symndx == -1) 1529 1.1 skrll ad += entry->d.h->root.u.def.value; 1530 1.1 skrll else 1531 1.1 skrll ad += sym->st_value; 1532 1.1 skrll ad += sec->output_offset; 1533 1.1 skrll if (sec->output_section && elf_section_data (sec->output_section)) 1534 1.1 skrll idx = elf_section_data (sec->output_section)->dynindx; 1535 1.1 skrll else 1536 1.1 skrll idx = 0; 1537 1.1 skrll } 1538 1.1 skrll 1539 1.1 skrll /* If we're linking an executable at a fixed address, we can 1540 1.1 skrll omit the dynamic relocation as long as the symbol is local to 1541 1.1.1.4 christos this module. */ 1542 1.1 skrll if (bfd_link_pde (info) 1543 1.1 skrll && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1544 1.1 skrll { 1545 1.1 skrll if (sec) 1546 1.1 skrll ad += sec->output_section->vma; 1547 1.1 skrll ofst = 0; 1548 1.1 skrll if (entry->symndx != -1 1549 1.1 skrll || entry->d.h->root.type != bfd_link_hash_undefweak) 1550 1.1 skrll { 1551 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 1552 1.1 skrll frvfdpic_gotfixup_section (info), 1553 1.1 skrll frvfdpic_got_section (info) 1554 1.1 skrll ->output_section->vma 1555 1.1 skrll + frvfdpic_got_section (info) 1556 1.1 skrll ->output_offset 1557 1.1 skrll + frvfdpic_got_initial_offset (info) 1558 1.1 skrll + entry->fd_entry, entry); 1559 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 1560 1.1 skrll frvfdpic_gotfixup_section (info), 1561 1.1 skrll frvfdpic_got_section (info) 1562 1.1 skrll ->output_section->vma 1563 1.1 skrll + frvfdpic_got_section (info) 1564 1.1 skrll ->output_offset 1565 1.1 skrll + frvfdpic_got_initial_offset (info) 1566 1.1 skrll + entry->fd_entry + 4, entry); 1567 1.1 skrll } 1568 1.1 skrll } 1569 1.1 skrll else 1570 1.1 skrll { 1571 1.1 skrll ofst = 1572 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, 1573 1.1 skrll entry->lazyplt 1574 1.1 skrll ? frvfdpic_pltrel_section (info) 1575 1.1 skrll : frvfdpic_gotrel_section (info), 1576 1.1 skrll _bfd_elf_section_offset 1577 1.1 skrll (output_bfd, info, 1578 1.1 skrll frvfdpic_got_section (info), 1579 1.1 skrll frvfdpic_got_initial_offset (info) 1580 1.1 skrll + entry->fd_entry) 1581 1.1 skrll + frvfdpic_got_section (info) 1582 1.1 skrll ->output_section->vma 1583 1.1 skrll + frvfdpic_got_section (info) 1584 1.1 skrll ->output_offset, 1585 1.1 skrll R_FRV_FUNCDESC_VALUE, idx, ad, entry); 1586 1.1 skrll } 1587 1.1 skrll 1588 1.1 skrll /* If we've omitted the dynamic relocation, just emit the fixed 1589 1.1.1.4 christos addresses of the symbol and of the local GOT base offset. */ 1590 1.1.1.4 christos if (bfd_link_pde (info) 1591 1.1.1.4 christos && sec 1592 1.1 skrll && sec->output_section) 1593 1.1 skrll { 1594 1.1 skrll lowword = ad; 1595 1.1 skrll highword = frvfdpic_got_section (info)->output_section->vma 1596 1.1 skrll + frvfdpic_got_section (info)->output_offset 1597 1.1 skrll + frvfdpic_got_initial_offset (info); 1598 1.1 skrll } 1599 1.1 skrll else if (entry->lazyplt) 1600 1.1 skrll { 1601 1.1 skrll if (ad) 1602 1.1 skrll { 1603 1.1 skrll (*info->callbacks->reloc_dangerous) 1604 1.1 skrll (info, _("relocation requires zero addend"), 1605 1.1 skrll elf_hash_table (info)->dynobj, 1606 1.1 skrll frvfdpic_got_section (info), 1607 1.1.1.9 christos entry->fd_entry); 1608 1.1 skrll return false; 1609 1.1 skrll } 1610 1.1 skrll 1611 1.1 skrll fd_lazy_rel_offset = ofst; 1612 1.1 skrll 1613 1.1 skrll /* A function descriptor used for lazy or local resolving is 1614 1.1 skrll initialized such that its high word contains the output 1615 1.1 skrll section index in which the PLT entries are located, and 1616 1.1 skrll the low word contains the address of the lazy PLT entry 1617 1.1 skrll entry point, that must be within the memory region 1618 1.1 skrll assigned to that section. */ 1619 1.1 skrll lowword = entry->lzplt_entry + 4 1620 1.1 skrll + frvfdpic_plt_section (info)->output_offset 1621 1.1 skrll + frvfdpic_plt_section (info)->output_section->vma; 1622 1.1 skrll highword = _frvfdpic_osec_to_segment 1623 1.1 skrll (output_bfd, frvfdpic_plt_section (info)->output_section); 1624 1.1 skrll } 1625 1.1 skrll else 1626 1.1 skrll { 1627 1.1 skrll /* A function descriptor for a local function gets the index 1628 1.1 skrll of the section. For a non-local function, it's 1629 1.1 skrll disregarded. */ 1630 1.1 skrll lowword = ad; 1631 1.1 skrll if (sec == NULL 1632 1.1 skrll || (entry->symndx == -1 && entry->d.h->dynindx != -1 1633 1.1 skrll && entry->d.h->dynindx == idx)) 1634 1.1 skrll highword = 0; 1635 1.1 skrll else 1636 1.1 skrll highword = _frvfdpic_osec_to_segment 1637 1.1 skrll (output_bfd, sec->output_section); 1638 1.1 skrll } 1639 1.1 skrll 1640 1.1 skrll bfd_put_32 (output_bfd, lowword, 1641 1.1 skrll frvfdpic_got_section (info)->contents 1642 1.1 skrll + frvfdpic_got_initial_offset (info) 1643 1.1 skrll + entry->fd_entry); 1644 1.1 skrll bfd_put_32 (output_bfd, highword, 1645 1.1 skrll frvfdpic_got_section (info)->contents 1646 1.1 skrll + frvfdpic_got_initial_offset (info) 1647 1.1 skrll + entry->fd_entry + 4); 1648 1.1 skrll } 1649 1.1 skrll 1650 1.1 skrll /* Generate code for the PLT entry. */ 1651 1.1 skrll if (entry->plt_entry != (bfd_vma) -1) 1652 1.1 skrll { 1653 1.1 skrll bfd_byte *plt_code = frvfdpic_plt_section (info)->contents 1654 1.1 skrll + entry->plt_entry; 1655 1.1 skrll 1656 1.1 skrll BFD_ASSERT (entry->fd_entry); 1657 1.1 skrll 1658 1.1 skrll /* Figure out what kind of PLT entry we need, depending on the 1659 1.1 skrll location of the function descriptor within the GOT. */ 1660 1.1 skrll if (entry->fd_entry >= -(1 << (12 - 1)) 1661 1.1 skrll && entry->fd_entry < (1 << (12 - 1))) 1662 1.1 skrll { 1663 1.1 skrll /* lddi @(gr15, fd_entry), gr14 */ 1664 1.1 skrll bfd_put_32 (output_bfd, 1665 1.1 skrll 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)), 1666 1.1 skrll plt_code); 1667 1.1 skrll plt_code += 4; 1668 1.1 skrll } 1669 1.1 skrll else 1670 1.1 skrll { 1671 1.1 skrll if (entry->fd_entry >= -(1 << (16 - 1)) 1672 1.1 skrll && entry->fd_entry < (1 << (16 - 1))) 1673 1.1 skrll { 1674 1.1 skrll /* setlos lo(fd_entry), gr14 */ 1675 1.1 skrll bfd_put_32 (output_bfd, 1676 1.1 skrll 0x9cfc0000 1677 1.1 skrll | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), 1678 1.1 skrll plt_code); 1679 1.1 skrll plt_code += 4; 1680 1.1 skrll } 1681 1.1 skrll else 1682 1.1 skrll { 1683 1.1 skrll /* sethi.p hi(fd_entry), gr14 1684 1.1 skrll setlo lo(fd_entry), gr14 */ 1685 1.1 skrll bfd_put_32 (output_bfd, 1686 1.1 skrll 0x1cf80000 1687 1.1 skrll | ((entry->fd_entry >> 16) 1688 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 1689 1.1 skrll plt_code); 1690 1.1 skrll plt_code += 4; 1691 1.1 skrll bfd_put_32 (output_bfd, 1692 1.1 skrll 0x9cf40000 1693 1.1 skrll | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), 1694 1.1 skrll plt_code); 1695 1.1 skrll plt_code += 4; 1696 1.1 skrll } 1697 1.1 skrll /* ldd @(gr14,gr15),gr14 */ 1698 1.1 skrll bfd_put_32 (output_bfd, 0x9c08e14f, plt_code); 1699 1.1 skrll plt_code += 4; 1700 1.1 skrll } 1701 1.1 skrll /* jmpl @(gr14,gr0) */ 1702 1.1 skrll bfd_put_32 (output_bfd, 0x8030e000, plt_code); 1703 1.1 skrll } 1704 1.1 skrll 1705 1.1 skrll /* Generate code for the lazy PLT entry. */ 1706 1.1 skrll if (entry->lzplt_entry != (bfd_vma) -1) 1707 1.1 skrll { 1708 1.1 skrll bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents 1709 1.1 skrll + entry->lzplt_entry; 1710 1.1 skrll bfd_vma resolverStub_addr; 1711 1.1 skrll 1712 1.1 skrll bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code); 1713 1.1 skrll lzplt_code += 4; 1714 1.1 skrll 1715 1.1 skrll resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE 1716 1.1 skrll * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC; 1717 1.1 skrll if (resolverStub_addr >= frvfdpic_plt_initial_offset (info)) 1718 1.1 skrll resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12; 1719 1.1 skrll 1720 1.1 skrll if (entry->lzplt_entry == resolverStub_addr) 1721 1.1 skrll { 1722 1.1 skrll /* This is a lazy PLT entry that includes a resolver call. */ 1723 1.1 skrll /* ldd @(gr15,gr0), gr4 1724 1.1 skrll jmpl @(gr4,gr0) */ 1725 1.1 skrll bfd_put_32 (output_bfd, 0x8808f140, lzplt_code); 1726 1.1 skrll bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4); 1727 1.1 skrll } 1728 1.1 skrll else 1729 1.1 skrll { 1730 1.1 skrll /* bra resolverStub */ 1731 1.1 skrll bfd_put_32 (output_bfd, 1732 1.1 skrll 0xc01a0000 1733 1.1 skrll | (((resolverStub_addr - entry->lzplt_entry) 1734 1.1 skrll / 4) & (((bfd_vma)1 << 16) - 1)), 1735 1.1 skrll lzplt_code); 1736 1.1 skrll } 1737 1.1 skrll } 1738 1.1 skrll 1739 1.1 skrll /* Generate relocation for GOT entry holding the TLS offset. */ 1740 1.1 skrll if (entry->tlsoff_entry) 1741 1.1 skrll { 1742 1.1 skrll int idx = dynindx; 1743 1.1 skrll bfd_vma ad = addend; 1744 1.1 skrll 1745 1.1 skrll if (entry->symndx != -1 1746 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h)) 1747 1.1 skrll { 1748 1.1 skrll /* If the symbol is dynamic but binds locally, use 1749 1.1 skrll section+offset. */ 1750 1.1 skrll if (sec) 1751 1.1 skrll { 1752 1.1 skrll if (entry->symndx == -1) 1753 1.1 skrll ad += entry->d.h->root.u.def.value; 1754 1.1 skrll else 1755 1.1 skrll ad += sym->st_value; 1756 1.1 skrll ad += sec->output_offset; 1757 1.1 skrll if (sec->output_section 1758 1.1 skrll && elf_section_data (sec->output_section)) 1759 1.1 skrll idx = elf_section_data (sec->output_section)->dynindx; 1760 1.1 skrll else 1761 1.1 skrll idx = 0; 1762 1.1 skrll } 1763 1.1 skrll } 1764 1.1 skrll 1765 1.1 skrll /* *ABS*+addend is special for TLS relocations, use only the 1766 1.1.1.4 christos addend. */ 1767 1.1 skrll if (bfd_link_executable (info) 1768 1.1 skrll && idx == 0 1769 1.1 skrll && (bfd_is_abs_section (sec) 1770 1.1 skrll || bfd_is_und_section (sec))) 1771 1.1 skrll ; 1772 1.1 skrll /* If we're linking an executable, we can entirely omit the 1773 1.1.1.4 christos dynamic relocation if the symbol is local to this module. */ 1774 1.1 skrll else if (bfd_link_executable (info) 1775 1.1 skrll && (entry->symndx != -1 1776 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1777 1.1 skrll { 1778 1.1 skrll if (sec) 1779 1.1 skrll ad += sec->output_section->vma - tls_biased_base (info); 1780 1.1 skrll } 1781 1.1 skrll else 1782 1.1 skrll { 1783 1.1 skrll if (idx == 0 1784 1.1 skrll && (bfd_is_abs_section (sec) 1785 1.1 skrll || bfd_is_und_section (sec))) 1786 1.1 skrll { 1787 1.1 skrll if (! elf_hash_table (info)->tls_sec) 1788 1.1 skrll { 1789 1.1 skrll (*info->callbacks->undefined_symbol) 1790 1.1.1.9 christos (info, "TLS section", elf_hash_table (info)->dynobj, 1791 1.1.1.9 christos frvfdpic_got_section (info), entry->tlsoff_entry, true); 1792 1.1 skrll return false; 1793 1.1 skrll } 1794 1.1 skrll idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; 1795 1.1 skrll ad += FRVFDPIC_TLS_BIAS; 1796 1.1 skrll } 1797 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), 1798 1.1 skrll _bfd_elf_section_offset 1799 1.1 skrll (output_bfd, info, 1800 1.1 skrll frvfdpic_got_section (info), 1801 1.1 skrll frvfdpic_got_initial_offset (info) 1802 1.1 skrll + entry->tlsoff_entry) 1803 1.1 skrll + frvfdpic_got_section (info) 1804 1.1 skrll ->output_section->vma 1805 1.1 skrll + frvfdpic_got_section (info) 1806 1.1 skrll ->output_offset, 1807 1.1 skrll R_FRV_TLSOFF, idx, ad, entry); 1808 1.1 skrll } 1809 1.1 skrll 1810 1.1 skrll bfd_put_32 (output_bfd, ad, 1811 1.1 skrll frvfdpic_got_section (info)->contents 1812 1.1 skrll + frvfdpic_got_initial_offset (info) 1813 1.1 skrll + entry->tlsoff_entry); 1814 1.1 skrll } 1815 1.1 skrll 1816 1.1 skrll if (entry->tlsdesc_entry) 1817 1.1 skrll { 1818 1.1 skrll int idx = dynindx; 1819 1.1 skrll bfd_vma ad = addend; 1820 1.1 skrll 1821 1.1 skrll /* If the symbol is dynamic but binds locally, use 1822 1.1 skrll section+offset. */ 1823 1.1 skrll if (sec && (entry->symndx != -1 1824 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1825 1.1 skrll { 1826 1.1 skrll if (entry->symndx == -1) 1827 1.1 skrll ad += entry->d.h->root.u.def.value; 1828 1.1 skrll else 1829 1.1 skrll ad += sym->st_value; 1830 1.1 skrll ad += sec->output_offset; 1831 1.1 skrll if (sec->output_section && elf_section_data (sec->output_section)) 1832 1.1 skrll idx = elf_section_data (sec->output_section)->dynindx; 1833 1.1 skrll else 1834 1.1 skrll idx = 0; 1835 1.1 skrll } 1836 1.1 skrll 1837 1.1 skrll /* If we didn't set up a TLS offset entry, but we're linking an 1838 1.1 skrll executable and the symbol binds locally, we can use the 1839 1.1.1.4 christos module offset in the TLS descriptor in relaxations. */ 1840 1.1 skrll if (bfd_link_executable (info) && ! entry->tlsoff_entry) 1841 1.1 skrll entry->tlsoff_entry = entry->tlsdesc_entry + 4; 1842 1.1.1.4 christos 1843 1.1 skrll if (bfd_link_pde (info) 1844 1.1 skrll && ((idx == 0 1845 1.1 skrll && (bfd_is_abs_section (sec) 1846 1.1 skrll || bfd_is_und_section (sec))) 1847 1.1 skrll || entry->symndx != -1 1848 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1849 1.1 skrll { 1850 1.1 skrll /* *ABS*+addend is special for TLS relocations, use only the 1851 1.1 skrll addend for the TLS offset, and take the module id as 1852 1.1 skrll 0. */ 1853 1.1 skrll if (idx == 0 1854 1.1 skrll && (bfd_is_abs_section (sec) 1855 1.1 skrll || bfd_is_und_section (sec))) 1856 1.1 skrll ; 1857 1.1 skrll /* For other TLS symbols that bind locally, add the section 1858 1.1 skrll TLS offset to the addend. */ 1859 1.1 skrll else if (sec) 1860 1.1 skrll ad += sec->output_section->vma - tls_biased_base (info); 1861 1.1 skrll 1862 1.1 skrll bfd_put_32 (output_bfd, 1863 1.1 skrll frvfdpic_plt_section (info)->output_section->vma 1864 1.1 skrll + frvfdpic_plt_section (info)->output_offset 1865 1.1 skrll + frvfdpic_plt_tls_ret_offset (info), 1866 1.1 skrll frvfdpic_got_section (info)->contents 1867 1.1 skrll + frvfdpic_got_initial_offset (info) 1868 1.1 skrll + entry->tlsdesc_entry); 1869 1.1 skrll 1870 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 1871 1.1 skrll frvfdpic_gotfixup_section (info), 1872 1.1 skrll frvfdpic_got_section (info) 1873 1.1 skrll ->output_section->vma 1874 1.1 skrll + frvfdpic_got_section (info) 1875 1.1 skrll ->output_offset 1876 1.1 skrll + frvfdpic_got_initial_offset (info) 1877 1.1 skrll + entry->tlsdesc_entry, entry); 1878 1.1 skrll 1879 1.1 skrll BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs); 1880 1.1 skrll 1881 1.1 skrll /* We've used one of the reserved fixups, so discount it so 1882 1.1 skrll that we can check at the end that we've used them 1883 1.1 skrll all. */ 1884 1.1 skrll frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--; 1885 1.1 skrll 1886 1.1 skrll /* While at that, make sure the ret instruction makes to the 1887 1.1 skrll right location in the PLT. We could do it only when we 1888 1.1 skrll got to 0, but since the check at the end will only print 1889 1.1 skrll a warning, make sure we have the ret in place in case the 1890 1.1 skrll warning is missed. */ 1891 1.1 skrll bfd_put_32 (output_bfd, 0xc03a4000, 1892 1.1 skrll frvfdpic_plt_section (info)->contents 1893 1.1 skrll + frvfdpic_plt_tls_ret_offset (info)); 1894 1.1 skrll } 1895 1.1 skrll else 1896 1.1 skrll { 1897 1.1 skrll if (idx == 0 1898 1.1 skrll && (bfd_is_abs_section (sec) 1899 1.1 skrll || bfd_is_und_section (sec))) 1900 1.1 skrll { 1901 1.1 skrll if (! elf_hash_table (info)->tls_sec) 1902 1.1 skrll { 1903 1.1 skrll (*info->callbacks->undefined_symbol) 1904 1.1.1.9 christos (info, "TLS section", elf_hash_table (info)->dynobj, 1905 1.1.1.9 christos frvfdpic_got_section (info), entry->tlsdesc_entry, true); 1906 1.1 skrll return false; 1907 1.1 skrll } 1908 1.1 skrll idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; 1909 1.1 skrll ad += FRVFDPIC_TLS_BIAS; 1910 1.1 skrll } 1911 1.1 skrll 1912 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), 1913 1.1 skrll _bfd_elf_section_offset 1914 1.1 skrll (output_bfd, info, 1915 1.1 skrll frvfdpic_got_section (info), 1916 1.1 skrll frvfdpic_got_initial_offset (info) 1917 1.1 skrll + entry->tlsdesc_entry) 1918 1.1 skrll + frvfdpic_got_section (info) 1919 1.1 skrll ->output_section->vma 1920 1.1 skrll + frvfdpic_got_section (info) 1921 1.1 skrll ->output_offset, 1922 1.1 skrll R_FRV_TLSDESC_VALUE, idx, ad, entry); 1923 1.1 skrll 1924 1.1 skrll bfd_put_32 (output_bfd, 0, 1925 1.1 skrll frvfdpic_got_section (info)->contents 1926 1.1 skrll + frvfdpic_got_initial_offset (info) 1927 1.1 skrll + entry->tlsdesc_entry); 1928 1.1 skrll } 1929 1.1 skrll 1930 1.1 skrll bfd_put_32 (output_bfd, ad, 1931 1.1 skrll frvfdpic_got_section (info)->contents 1932 1.1 skrll + frvfdpic_got_initial_offset (info) 1933 1.1 skrll + entry->tlsdesc_entry + 4); 1934 1.1 skrll } 1935 1.1 skrll 1936 1.1 skrll /* Generate code for the get-TLS-offset PLT entry. */ 1937 1.1 skrll if (entry->tlsplt_entry != (bfd_vma) -1) 1938 1.1 skrll { 1939 1.1 skrll bfd_byte *plt_code = frvfdpic_plt_section (info)->contents 1940 1.1 skrll + entry->tlsplt_entry; 1941 1.1.1.4 christos 1942 1.1 skrll if (bfd_link_executable (info) 1943 1.1 skrll && (entry->symndx != -1 1944 1.1 skrll || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1945 1.1 skrll { 1946 1.1 skrll int idx = dynindx; 1947 1.1 skrll bfd_vma ad = addend; 1948 1.1 skrll 1949 1.1 skrll /* sec may be NULL when referencing an undefweak symbol 1950 1.1 skrll while linking a static executable. */ 1951 1.1 skrll if (!sec) 1952 1.1 skrll { 1953 1.1 skrll BFD_ASSERT (entry->symndx == -1 1954 1.1 skrll && entry->d.h->root.type == bfd_link_hash_undefweak); 1955 1.1 skrll } 1956 1.1 skrll else 1957 1.1 skrll { 1958 1.1 skrll if (entry->symndx == -1) 1959 1.1 skrll ad += entry->d.h->root.u.def.value; 1960 1.1 skrll else 1961 1.1 skrll ad += sym->st_value; 1962 1.1 skrll ad += sec->output_offset; 1963 1.1 skrll if (sec->output_section 1964 1.1 skrll && elf_section_data (sec->output_section)) 1965 1.1 skrll idx = elf_section_data (sec->output_section)->dynindx; 1966 1.1 skrll else 1967 1.1 skrll idx = 0; 1968 1.1 skrll } 1969 1.1 skrll 1970 1.1 skrll /* *ABS*+addend is special for TLS relocations, use only the 1971 1.1 skrll addend for the TLS offset, and take the module id as 1972 1.1 skrll 0. */ 1973 1.1 skrll if (idx == 0 1974 1.1 skrll && (bfd_is_abs_section (sec) 1975 1.1 skrll || bfd_is_und_section (sec))) 1976 1.1 skrll ; 1977 1.1 skrll /* For other TLS symbols that bind locally, add the section 1978 1.1 skrll TLS offset to the addend. */ 1979 1.1 skrll else if (sec) 1980 1.1 skrll ad += sec->output_section->vma - tls_biased_base (info); 1981 1.1 skrll 1982 1.1 skrll if ((bfd_signed_vma)ad >= -(1 << (16 - 1)) 1983 1.1 skrll && (bfd_signed_vma)ad < (1 << (16 - 1))) 1984 1.1 skrll { 1985 1.1 skrll /* setlos lo(ad), gr9 */ 1986 1.1 skrll bfd_put_32 (output_bfd, 1987 1.1 skrll 0x92fc0000 1988 1.1 skrll | (ad 1989 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 1990 1.1 skrll plt_code); 1991 1.1 skrll plt_code += 4; 1992 1.1 skrll } 1993 1.1 skrll else 1994 1.1 skrll { 1995 1.1 skrll /* sethi.p hi(ad), gr9 1996 1.1 skrll setlo lo(ad), gr9 */ 1997 1.1 skrll bfd_put_32 (output_bfd, 1998 1.1 skrll 0x12f80000 1999 1.1 skrll | ((ad >> 16) 2000 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2001 1.1 skrll plt_code); 2002 1.1 skrll plt_code += 4; 2003 1.1 skrll bfd_put_32 (output_bfd, 2004 1.1 skrll 0x92f40000 2005 1.1 skrll | (ad 2006 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2007 1.1 skrll plt_code); 2008 1.1 skrll plt_code += 4; 2009 1.1 skrll } 2010 1.1 skrll /* ret */ 2011 1.1 skrll bfd_put_32 (output_bfd, 0xc03a4000, plt_code); 2012 1.1 skrll } 2013 1.1 skrll else if (entry->tlsoff_entry) 2014 1.1 skrll { 2015 1.1 skrll /* Figure out what kind of PLT entry we need, depending on the 2016 1.1 skrll location of the TLS descriptor within the GOT. */ 2017 1.1 skrll if (entry->tlsoff_entry >= -(1 << (12 - 1)) 2018 1.1 skrll && entry->tlsoff_entry < (1 << (12 - 1))) 2019 1.1 skrll { 2020 1.1 skrll /* ldi @(gr15, tlsoff_entry), gr9 */ 2021 1.1 skrll bfd_put_32 (output_bfd, 2022 1.1 skrll 0x92c8f000 | (entry->tlsoff_entry 2023 1.1 skrll & ((1 << 12) - 1)), 2024 1.1 skrll plt_code); 2025 1.1 skrll plt_code += 4; 2026 1.1 skrll } 2027 1.1 skrll else 2028 1.1 skrll { 2029 1.1 skrll if (entry->tlsoff_entry >= -(1 << (16 - 1)) 2030 1.1 skrll && entry->tlsoff_entry < (1 << (16 - 1))) 2031 1.1 skrll { 2032 1.1 skrll /* setlos lo(tlsoff_entry), gr8 */ 2033 1.1 skrll bfd_put_32 (output_bfd, 2034 1.1 skrll 0x90fc0000 2035 1.1 skrll | (entry->tlsoff_entry 2036 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2037 1.1 skrll plt_code); 2038 1.1 skrll plt_code += 4; 2039 1.1 skrll } 2040 1.1 skrll else 2041 1.1 skrll { 2042 1.1 skrll /* sethi.p hi(tlsoff_entry), gr8 2043 1.1 skrll setlo lo(tlsoff_entry), gr8 */ 2044 1.1 skrll bfd_put_32 (output_bfd, 2045 1.1 skrll 0x10f80000 2046 1.1 skrll | ((entry->tlsoff_entry >> 16) 2047 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2048 1.1 skrll plt_code); 2049 1.1 skrll plt_code += 4; 2050 1.1 skrll bfd_put_32 (output_bfd, 2051 1.1 skrll 0x90f40000 2052 1.1 skrll | (entry->tlsoff_entry 2053 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2054 1.1 skrll plt_code); 2055 1.1 skrll plt_code += 4; 2056 1.1 skrll } 2057 1.1 skrll /* ld @(gr15,gr8),gr9 */ 2058 1.1 skrll bfd_put_32 (output_bfd, 0x9008f108, plt_code); 2059 1.1 skrll plt_code += 4; 2060 1.1 skrll } 2061 1.1 skrll /* ret */ 2062 1.1 skrll bfd_put_32 (output_bfd, 0xc03a4000, plt_code); 2063 1.1 skrll } 2064 1.1 skrll else 2065 1.1 skrll { 2066 1.1 skrll BFD_ASSERT (entry->tlsdesc_entry); 2067 1.1 skrll 2068 1.1 skrll /* Figure out what kind of PLT entry we need, depending on the 2069 1.1 skrll location of the TLS descriptor within the GOT. */ 2070 1.1 skrll if (entry->tlsdesc_entry >= -(1 << (12 - 1)) 2071 1.1 skrll && entry->tlsdesc_entry < (1 << (12 - 1))) 2072 1.1 skrll { 2073 1.1 skrll /* lddi @(gr15, tlsdesc_entry), gr8 */ 2074 1.1 skrll bfd_put_32 (output_bfd, 2075 1.1 skrll 0x90ccf000 | (entry->tlsdesc_entry 2076 1.1 skrll & ((1 << 12) - 1)), 2077 1.1 skrll plt_code); 2078 1.1 skrll plt_code += 4; 2079 1.1 skrll } 2080 1.1 skrll else 2081 1.1 skrll { 2082 1.1 skrll if (entry->tlsdesc_entry >= -(1 << (16 - 1)) 2083 1.1 skrll && entry->tlsdesc_entry < (1 << (16 - 1))) 2084 1.1 skrll { 2085 1.1 skrll /* setlos lo(tlsdesc_entry), gr8 */ 2086 1.1 skrll bfd_put_32 (output_bfd, 2087 1.1 skrll 0x90fc0000 2088 1.1 skrll | (entry->tlsdesc_entry 2089 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2090 1.1 skrll plt_code); 2091 1.1 skrll plt_code += 4; 2092 1.1 skrll } 2093 1.1 skrll else 2094 1.1 skrll { 2095 1.1 skrll /* sethi.p hi(tlsdesc_entry), gr8 2096 1.1 skrll setlo lo(tlsdesc_entry), gr8 */ 2097 1.1 skrll bfd_put_32 (output_bfd, 2098 1.1 skrll 0x10f80000 2099 1.1 skrll | ((entry->tlsdesc_entry >> 16) 2100 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2101 1.1 skrll plt_code); 2102 1.1 skrll plt_code += 4; 2103 1.1 skrll bfd_put_32 (output_bfd, 2104 1.1 skrll 0x90f40000 2105 1.1 skrll | (entry->tlsdesc_entry 2106 1.1 skrll & (((bfd_vma)1 << 16) - 1)), 2107 1.1 skrll plt_code); 2108 1.1 skrll plt_code += 4; 2109 1.1 skrll } 2110 1.1 skrll /* ldd @(gr15,gr8),gr8 */ 2111 1.1 skrll bfd_put_32 (output_bfd, 0x9008f148, plt_code); 2112 1.1 skrll plt_code += 4; 2113 1.1 skrll } 2114 1.1 skrll /* jmpl @(gr8,gr0) */ 2115 1.1 skrll bfd_put_32 (output_bfd, 0x80308000, plt_code); 2116 1.1 skrll } 2117 1.1 skrll } 2118 1.1.1.9 christos 2119 1.1 skrll return true; 2120 1.1 skrll } 2121 1.1 skrll 2122 1.1 skrll /* Handle an FRV small data reloc. */ 2123 1.1 skrll 2124 1.1.1.3 christos static bfd_reloc_status_type 2125 1.1.1.3 christos elf32_frv_relocate_gprel12 (struct bfd_link_info *info, 2126 1.1.1.3 christos bfd *input_bfd, 2127 1.1.1.3 christos asection *input_section, 2128 1.1.1.3 christos Elf_Internal_Rela *relocation, 2129 1.1.1.3 christos bfd_byte *contents, 2130 1.1 skrll bfd_vma value) 2131 1.1 skrll { 2132 1.1 skrll bfd_vma insn; 2133 1.1 skrll bfd_vma gp; 2134 1.1 skrll struct bfd_link_hash_entry *h; 2135 1.1.1.9 christos 2136 1.1 skrll h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true); 2137 1.1 skrll 2138 1.1 skrll gp = (h->u.def.value 2139 1.1 skrll + h->u.def.section->output_section->vma 2140 1.1 skrll + h->u.def.section->output_offset); 2141 1.1 skrll 2142 1.1 skrll value -= input_section->output_section->vma; 2143 1.1 skrll value -= (gp - input_section->output_section->vma); 2144 1.1 skrll 2145 1.1 skrll insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2146 1.1 skrll 2147 1.1 skrll value += relocation->r_addend; 2148 1.1 skrll 2149 1.1 skrll if ((long) value > 0x7ff || (long) value < -0x800) 2150 1.1 skrll return bfd_reloc_overflow; 2151 1.1 skrll 2152 1.1 skrll bfd_put_32 (input_bfd, 2153 1.1 skrll (insn & 0xfffff000) | (value & 0xfff), 2154 1.1 skrll contents + relocation->r_offset); 2155 1.1 skrll 2156 1.1 skrll return bfd_reloc_ok; 2157 1.1 skrll } 2158 1.1 skrll 2159 1.1 skrll /* Handle an FRV small data reloc. for the u12 field. */ 2160 1.1 skrll 2161 1.1.1.3 christos static bfd_reloc_status_type 2162 1.1.1.3 christos elf32_frv_relocate_gprelu12 (struct bfd_link_info *info, 2163 1.1.1.3 christos bfd *input_bfd, 2164 1.1.1.3 christos asection *input_section, 2165 1.1.1.3 christos Elf_Internal_Rela *relocation, 2166 1.1.1.3 christos bfd_byte *contents, 2167 1.1 skrll bfd_vma value) 2168 1.1 skrll { 2169 1.1 skrll bfd_vma insn; 2170 1.1 skrll bfd_vma gp; 2171 1.1 skrll struct bfd_link_hash_entry *h; 2172 1.1 skrll bfd_vma mask; 2173 1.1.1.9 christos 2174 1.1 skrll h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true); 2175 1.1 skrll 2176 1.1 skrll gp = (h->u.def.value 2177 1.1 skrll + h->u.def.section->output_section->vma 2178 1.1 skrll + h->u.def.section->output_offset); 2179 1.1 skrll 2180 1.1 skrll value -= input_section->output_section->vma; 2181 1.1 skrll value -= (gp - input_section->output_section->vma); 2182 1.1 skrll 2183 1.1 skrll insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2184 1.1 skrll 2185 1.1 skrll value += relocation->r_addend; 2186 1.1 skrll 2187 1.1 skrll if ((long) value > 0x7ff || (long) value < -0x800) 2188 1.1 skrll return bfd_reloc_overflow; 2189 1.1 skrll 2190 1.1 skrll /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */ 2191 1.1 skrll mask = 0x3f03f; 2192 1.1 skrll insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f); 2193 1.1 skrll 2194 1.1 skrll bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); 2195 1.1 skrll 2196 1.1 skrll return bfd_reloc_ok; 2197 1.1 skrll } 2198 1.1 skrll 2199 1.1 skrll /* Handle an FRV ELF HI16 reloc. */ 2200 1.1 skrll 2201 1.1.1.3 christos static bfd_reloc_status_type 2202 1.1.1.3 christos elf32_frv_relocate_hi16 (bfd *input_bfd, 2203 1.1.1.3 christos Elf_Internal_Rela *relhi, 2204 1.1.1.3 christos bfd_byte *contents, 2205 1.1 skrll bfd_vma value) 2206 1.1 skrll { 2207 1.1 skrll bfd_vma insn; 2208 1.1 skrll 2209 1.1 skrll insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); 2210 1.1 skrll 2211 1.1 skrll value += relhi->r_addend; 2212 1.1 skrll value = ((value >> 16) & 0xffff); 2213 1.1 skrll 2214 1.1 skrll insn = (insn & 0xffff0000) | value; 2215 1.1 skrll 2216 1.1 skrll if ((long) value > 0xffff || (long) value < -0x10000) 2217 1.1 skrll return bfd_reloc_overflow; 2218 1.1 skrll 2219 1.1 skrll bfd_put_32 (input_bfd, insn, contents + relhi->r_offset); 2220 1.1 skrll return bfd_reloc_ok; 2221 1.1 skrll 2222 1.1 skrll } 2223 1.1.1.3 christos static bfd_reloc_status_type 2224 1.1.1.3 christos elf32_frv_relocate_lo16 (bfd *input_bfd, 2225 1.1.1.3 christos Elf_Internal_Rela *rello, 2226 1.1.1.3 christos bfd_byte *contents, 2227 1.1 skrll bfd_vma value) 2228 1.1 skrll { 2229 1.1 skrll bfd_vma insn; 2230 1.1 skrll 2231 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rello->r_offset); 2232 1.1 skrll 2233 1.1 skrll value += rello->r_addend; 2234 1.1 skrll value = value & 0xffff; 2235 1.1 skrll 2236 1.1 skrll insn = (insn & 0xffff0000) | value; 2237 1.1 skrll 2238 1.1 skrll if ((long) value > 0xffff || (long) value < -0x10000) 2239 1.1 skrll return bfd_reloc_overflow; 2240 1.1 skrll 2241 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rello->r_offset); 2242 1.1 skrll return bfd_reloc_ok; 2243 1.1 skrll } 2244 1.1 skrll 2245 1.1 skrll /* Perform the relocation for the CALL label24 instruction. */ 2246 1.1 skrll 2247 1.1.1.3 christos static bfd_reloc_status_type 2248 1.1.1.3 christos elf32_frv_relocate_label24 (bfd *input_bfd, 2249 1.1.1.3 christos asection *input_section, 2250 1.1.1.3 christos Elf_Internal_Rela *rello, 2251 1.1.1.3 christos bfd_byte *contents, 2252 1.1 skrll bfd_vma value) 2253 1.1 skrll { 2254 1.1 skrll bfd_vma insn; 2255 1.1 skrll bfd_vma label6; 2256 1.1 skrll bfd_vma label18; 2257 1.1 skrll 2258 1.1 skrll /* The format for the call instruction is: 2259 1.1 skrll 2260 1.1 skrll 0 000000 0001111 000000000000000000 2261 1.1 skrll label6 opcode label18 2262 1.1 skrll 2263 1.1 skrll The branch calculation is: pc + (4*label24) 2264 1.1 skrll where label24 is the concatenation of label6 and label18. */ 2265 1.1 skrll 2266 1.1 skrll /* Grab the instruction. */ 2267 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rello->r_offset); 2268 1.1 skrll 2269 1.1 skrll value -= input_section->output_section->vma + input_section->output_offset; 2270 1.1 skrll value -= rello->r_offset; 2271 1.1 skrll value += rello->r_addend; 2272 1.1 skrll 2273 1.1 skrll value = value >> 2; 2274 1.1 skrll 2275 1.1 skrll label6 = value & 0xfc0000; 2276 1.1 skrll label6 = label6 << 7; 2277 1.1 skrll 2278 1.1 skrll label18 = value & 0x3ffff; 2279 1.1 skrll 2280 1.1 skrll insn = insn & 0x803c0000; 2281 1.1 skrll insn = insn | label6; 2282 1.1 skrll insn = insn | label18; 2283 1.1 skrll 2284 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rello->r_offset); 2285 1.1 skrll 2286 1.1 skrll return bfd_reloc_ok; 2287 1.1 skrll } 2288 1.1 skrll 2289 1.1.1.3 christos static bfd_reloc_status_type 2290 1.1.1.3 christos elf32_frv_relocate_gprelhi (struct bfd_link_info *info, 2291 1.1.1.3 christos bfd *input_bfd, 2292 1.1.1.3 christos asection *input_section, 2293 1.1.1.3 christos Elf_Internal_Rela *relocation, 2294 1.1.1.3 christos bfd_byte *contents, 2295 1.1 skrll bfd_vma value) 2296 1.1 skrll { 2297 1.1 skrll bfd_vma insn; 2298 1.1 skrll bfd_vma gp; 2299 1.1 skrll struct bfd_link_hash_entry *h; 2300 1.1.1.9 christos 2301 1.1 skrll h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true); 2302 1.1 skrll 2303 1.1.1.6 christos gp = (h->u.def.value 2304 1.1.1.6 christos + h->u.def.section->output_section->vma 2305 1.1 skrll + h->u.def.section->output_offset); 2306 1.1 skrll 2307 1.1 skrll value -= input_section->output_section->vma; 2308 1.1 skrll value -= (gp - input_section->output_section->vma); 2309 1.1 skrll value += relocation->r_addend; 2310 1.1 skrll value = ((value >> 16) & 0xffff); 2311 1.1 skrll 2312 1.1 skrll if ((long) value > 0xffff || (long) value < -0x10000) 2313 1.1 skrll return bfd_reloc_overflow; 2314 1.1 skrll 2315 1.1 skrll insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2316 1.1 skrll insn = (insn & 0xffff0000) | value; 2317 1.1 skrll 2318 1.1 skrll bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); 2319 1.1 skrll return bfd_reloc_ok; 2320 1.1 skrll } 2321 1.1 skrll 2322 1.1.1.3 christos static bfd_reloc_status_type 2323 1.1.1.3 christos elf32_frv_relocate_gprello (struct bfd_link_info *info, 2324 1.1.1.3 christos bfd *input_bfd, 2325 1.1.1.3 christos asection *input_section, 2326 1.1.1.3 christos Elf_Internal_Rela *relocation, 2327 1.1.1.3 christos bfd_byte *contents, 2328 1.1 skrll bfd_vma value) 2329 1.1 skrll { 2330 1.1 skrll bfd_vma insn; 2331 1.1 skrll bfd_vma gp; 2332 1.1 skrll struct bfd_link_hash_entry *h; 2333 1.1.1.9 christos 2334 1.1 skrll h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true); 2335 1.1 skrll 2336 1.1.1.6 christos gp = (h->u.def.value 2337 1.1.1.6 christos + h->u.def.section->output_section->vma 2338 1.1 skrll + h->u.def.section->output_offset); 2339 1.1 skrll 2340 1.1 skrll value -= input_section->output_section->vma; 2341 1.1 skrll value -= (gp - input_section->output_section->vma); 2342 1.1 skrll value += relocation->r_addend; 2343 1.1 skrll value = value & 0xffff; 2344 1.1 skrll 2345 1.1 skrll if ((long) value > 0xffff || (long) value < -0x10000) 2346 1.1 skrll return bfd_reloc_overflow; 2347 1.1 skrll 2348 1.1 skrll insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2349 1.1 skrll insn = (insn & 0xffff0000) | value; 2350 1.1 skrll 2351 1.1 skrll bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); 2352 1.1 skrll 2353 1.1 skrll return bfd_reloc_ok; 2354 1.1 skrll } 2355 1.1 skrll 2356 1.1.1.3 christos static reloc_howto_type * 2357 1.1.1.3 christos frv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 2358 1.1 skrll bfd_reloc_code_real_type code) 2359 1.1 skrll { 2360 1.1 skrll switch (code) 2361 1.1 skrll { 2362 1.1 skrll default: 2363 1.1 skrll break; 2364 1.1 skrll 2365 1.1 skrll case BFD_RELOC_NONE: 2366 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_NONE]; 2367 1.1 skrll 2368 1.1 skrll case BFD_RELOC_32: 2369 1.1 skrll if (elf_elfheader (abfd)->e_type == ET_EXEC 2370 1.1 skrll || elf_elfheader (abfd)->e_type == ET_DYN) 2371 1.1 skrll return &elf32_frv_rel_32_howto; 2372 1.1 skrll /* Fall through. */ 2373 1.1 skrll case BFD_RELOC_CTOR: 2374 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_32]; 2375 1.1 skrll 2376 1.1 skrll case BFD_RELOC_FRV_LABEL16: 2377 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_LABEL16]; 2378 1.1 skrll 2379 1.1 skrll case BFD_RELOC_FRV_LABEL24: 2380 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_LABEL24]; 2381 1.1 skrll 2382 1.1 skrll case BFD_RELOC_FRV_LO16: 2383 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_LO16]; 2384 1.1 skrll 2385 1.1 skrll case BFD_RELOC_FRV_HI16: 2386 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_HI16]; 2387 1.1 skrll 2388 1.1 skrll case BFD_RELOC_FRV_GPREL12: 2389 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GPREL12]; 2390 1.1 skrll 2391 1.1 skrll case BFD_RELOC_FRV_GPRELU12: 2392 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12]; 2393 1.1 skrll 2394 1.1 skrll case BFD_RELOC_FRV_GPREL32: 2395 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GPREL32]; 2396 1.1 skrll 2397 1.1 skrll case BFD_RELOC_FRV_GPRELHI: 2398 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI]; 2399 1.1 skrll 2400 1.1 skrll case BFD_RELOC_FRV_GPRELLO: 2401 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO]; 2402 1.1 skrll 2403 1.1 skrll case BFD_RELOC_FRV_GOT12: 2404 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOT12]; 2405 1.1 skrll 2406 1.1 skrll case BFD_RELOC_FRV_GOTHI: 2407 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTHI]; 2408 1.1 skrll 2409 1.1 skrll case BFD_RELOC_FRV_GOTLO: 2410 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTLO]; 2411 1.1 skrll 2412 1.1 skrll case BFD_RELOC_FRV_FUNCDESC: 2413 1.1 skrll if (elf_elfheader (abfd)->e_type == ET_EXEC 2414 1.1 skrll || elf_elfheader (abfd)->e_type == ET_DYN) 2415 1.1 skrll return &elf32_frv_rel_funcdesc_howto; 2416 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC]; 2417 1.1 skrll 2418 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_GOT12: 2419 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12]; 2420 1.1 skrll 2421 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_GOTHI: 2422 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI]; 2423 1.1 skrll 2424 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_GOTLO: 2425 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO]; 2426 1.1 skrll 2427 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_VALUE: 2428 1.1 skrll if (elf_elfheader (abfd)->e_type == ET_EXEC 2429 1.1 skrll || elf_elfheader (abfd)->e_type == ET_DYN) 2430 1.1 skrll return &elf32_frv_rel_funcdesc_value_howto; 2431 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE]; 2432 1.1 skrll 2433 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_GOTOFF12: 2434 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12]; 2435 1.1 skrll 2436 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI: 2437 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI]; 2438 1.1 skrll 2439 1.1 skrll case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO: 2440 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO]; 2441 1.1 skrll 2442 1.1 skrll case BFD_RELOC_FRV_GOTOFF12: 2443 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12]; 2444 1.1 skrll 2445 1.1 skrll case BFD_RELOC_FRV_GOTOFFHI: 2446 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI]; 2447 1.1 skrll 2448 1.1 skrll case BFD_RELOC_FRV_GOTOFFLO: 2449 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO]; 2450 1.1 skrll 2451 1.1 skrll case BFD_RELOC_FRV_GETTLSOFF: 2452 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF]; 2453 1.1 skrll 2454 1.1 skrll case BFD_RELOC_FRV_TLSDESC_VALUE: 2455 1.1 skrll if (elf_elfheader (abfd)->e_type == ET_EXEC 2456 1.1 skrll || elf_elfheader (abfd)->e_type == ET_DYN) 2457 1.1 skrll return &elf32_frv_rel_tlsdesc_value_howto; 2458 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE]; 2459 1.1 skrll 2460 1.1 skrll case BFD_RELOC_FRV_GOTTLSDESC12: 2461 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12]; 2462 1.1 skrll 2463 1.1 skrll case BFD_RELOC_FRV_GOTTLSDESCHI: 2464 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI]; 2465 1.1 skrll 2466 1.1 skrll case BFD_RELOC_FRV_GOTTLSDESCLO: 2467 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO]; 2468 1.1 skrll 2469 1.1 skrll case BFD_RELOC_FRV_TLSMOFF12: 2470 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12]; 2471 1.1 skrll 2472 1.1 skrll case BFD_RELOC_FRV_TLSMOFFHI: 2473 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI]; 2474 1.1 skrll 2475 1.1 skrll case BFD_RELOC_FRV_TLSMOFFLO: 2476 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO]; 2477 1.1 skrll 2478 1.1 skrll case BFD_RELOC_FRV_GOTTLSOFF12: 2479 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12]; 2480 1.1 skrll 2481 1.1 skrll case BFD_RELOC_FRV_GOTTLSOFFHI: 2482 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI]; 2483 1.1 skrll 2484 1.1 skrll case BFD_RELOC_FRV_GOTTLSOFFLO: 2485 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO]; 2486 1.1 skrll 2487 1.1 skrll case BFD_RELOC_FRV_TLSOFF: 2488 1.1 skrll if (elf_elfheader (abfd)->e_type == ET_EXEC 2489 1.1 skrll || elf_elfheader (abfd)->e_type == ET_DYN) 2490 1.1 skrll return &elf32_frv_rel_tlsoff_howto; 2491 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF]; 2492 1.1 skrll 2493 1.1 skrll case BFD_RELOC_FRV_TLSDESC_RELAX: 2494 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX]; 2495 1.1 skrll 2496 1.1 skrll case BFD_RELOC_FRV_GETTLSOFF_RELAX: 2497 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX]; 2498 1.1 skrll 2499 1.1 skrll case BFD_RELOC_FRV_TLSOFF_RELAX: 2500 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX]; 2501 1.1 skrll 2502 1.1 skrll case BFD_RELOC_FRV_TLSMOFF: 2503 1.1 skrll return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF]; 2504 1.1 skrll 2505 1.1 skrll case BFD_RELOC_VTABLE_INHERIT: 2506 1.1 skrll return &elf32_frv_vtinherit_howto; 2507 1.1 skrll 2508 1.1 skrll case BFD_RELOC_VTABLE_ENTRY: 2509 1.1 skrll return &elf32_frv_vtentry_howto; 2510 1.1 skrll } 2511 1.1 skrll 2512 1.1 skrll return NULL; 2513 1.1 skrll } 2514 1.1 skrll 2515 1.1 skrll static reloc_howto_type * 2516 1.1 skrll frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) 2517 1.1 skrll { 2518 1.1 skrll unsigned int i; 2519 1.1 skrll 2520 1.1 skrll for (i = 0; 2521 1.1 skrll i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]); 2522 1.1 skrll i++) 2523 1.1 skrll if (elf32_frv_howto_table[i].name != NULL 2524 1.1 skrll && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0) 2525 1.1 skrll return &elf32_frv_howto_table[i]; 2526 1.1 skrll 2527 1.1 skrll if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0) 2528 1.1 skrll return &elf32_frv_vtinherit_howto; 2529 1.1 skrll if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0) 2530 1.1 skrll return &elf32_frv_vtentry_howto; 2531 1.1 skrll 2532 1.1 skrll return NULL; 2533 1.1 skrll } 2534 1.1 skrll 2535 1.1 skrll /* Set the howto pointer for an FRV ELF reloc. */ 2536 1.1.1.9 christos 2537 1.1.1.3 christos static bool 2538 1.1.1.3 christos frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, 2539 1.1.1.3 christos arelent *cache_ptr, 2540 1.1 skrll Elf_Internal_Rela *dst) 2541 1.1 skrll { 2542 1.1 skrll unsigned int r_type; 2543 1.1 skrll 2544 1.1 skrll r_type = ELF32_R_TYPE (dst->r_info); 2545 1.1 skrll switch (r_type) 2546 1.1 skrll { 2547 1.1 skrll case R_FRV_GNU_VTINHERIT: 2548 1.1 skrll cache_ptr->howto = &elf32_frv_vtinherit_howto; 2549 1.1 skrll break; 2550 1.1 skrll 2551 1.1 skrll case R_FRV_GNU_VTENTRY: 2552 1.1 skrll cache_ptr->howto = &elf32_frv_vtentry_howto; 2553 1.1 skrll break; 2554 1.1 skrll 2555 1.1.1.7 christos default: 2556 1.1.1.4 christos if (r_type >= ARRAY_SIZE (elf32_frv_howto_table)) 2557 1.1.1.6 christos { 2558 1.1.1.7 christos /* xgettext:c-format */ 2559 1.1.1.7 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 2560 1.1.1.7 christos abfd, r_type); 2561 1.1.1.9 christos bfd_set_error (bfd_error_bad_value); 2562 1.1.1.4 christos return false; 2563 1.1 skrll } 2564 1.1 skrll cache_ptr->howto = & elf32_frv_howto_table [r_type]; 2565 1.1 skrll break; 2566 1.1.1.9 christos } 2567 1.1 skrll return true; 2568 1.1 skrll } 2569 1.1 skrll 2570 1.1.1.7 christos /* Set the howto pointer for an FRV ELF REL reloc. */ 2571 1.1.1.9 christos 2572 1.1 skrll static bool 2573 1.1 skrll frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, 2574 1.1 skrll arelent *cache_ptr, Elf_Internal_Rela *dst) 2575 1.1 skrll { 2576 1.1 skrll unsigned int r_type; 2577 1.1 skrll 2578 1.1 skrll r_type = ELF32_R_TYPE (dst->r_info); 2579 1.1 skrll switch (r_type) 2580 1.1 skrll { 2581 1.1 skrll case R_FRV_32: 2582 1.1 skrll cache_ptr->howto = &elf32_frv_rel_32_howto; 2583 1.1 skrll break; 2584 1.1 skrll 2585 1.1 skrll case R_FRV_FUNCDESC: 2586 1.1 skrll cache_ptr->howto = &elf32_frv_rel_funcdesc_howto; 2587 1.1 skrll break; 2588 1.1 skrll 2589 1.1 skrll case R_FRV_FUNCDESC_VALUE: 2590 1.1 skrll cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto; 2591 1.1 skrll break; 2592 1.1 skrll 2593 1.1 skrll case R_FRV_TLSDESC_VALUE: 2594 1.1 skrll cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto; 2595 1.1 skrll break; 2596 1.1 skrll 2597 1.1 skrll case R_FRV_TLSOFF: 2598 1.1 skrll cache_ptr->howto = &elf32_frv_rel_tlsoff_howto; 2599 1.1 skrll break; 2600 1.1 skrll 2601 1.1 skrll default: 2602 1.1.1.9 christos cache_ptr->howto = NULL; 2603 1.1 skrll return false; 2604 1.1.1.9 christos } 2605 1.1 skrll return true; 2606 1.1 skrll } 2607 1.1 skrll 2608 1.1 skrll /* Perform a single relocation. By default we use the standard BFD 2610 1.1 skrll routines, but a few relocs, we have to do them ourselves. */ 2611 1.1.1.3 christos 2612 1.1.1.3 christos static bfd_reloc_status_type 2613 1.1.1.3 christos frv_final_link_relocate (reloc_howto_type *howto, 2614 1.1.1.3 christos bfd *input_bfd, 2615 1.1.1.3 christos asection *input_section, 2616 1.1.1.3 christos bfd_byte *contents, 2617 1.1 skrll Elf_Internal_Rela *rel, 2618 1.1 skrll bfd_vma relocation) 2619 1.1 skrll { 2620 1.1 skrll return _bfd_final_link_relocate (howto, input_bfd, input_section, 2621 1.1 skrll contents, rel->r_offset, relocation, 2622 1.1 skrll rel->r_addend); 2623 1.1 skrll } 2624 1.1 skrll 2625 1.1 skrll 2626 1.1 skrll /* Relocate an FRV ELF section. 2628 1.1 skrll 2629 1.1 skrll The RELOCATE_SECTION function is called by the new ELF backend linker 2630 1.1 skrll to handle the relocations for a section. 2631 1.1 skrll 2632 1.1 skrll The relocs are always passed as Rela structures; if the section 2633 1.1 skrll actually uses Rel structures, the r_addend field will always be 2634 1.1 skrll zero. 2635 1.1 skrll 2636 1.1 skrll This function is responsible for adjusting the section contents as 2637 1.1 skrll necessary, and (if using Rela relocs and generating a relocatable 2638 1.1 skrll output file) adjusting the reloc addend as necessary. 2639 1.1 skrll 2640 1.1 skrll This function does not have to worry about setting the reloc 2641 1.1 skrll address or the reloc symbol index. 2642 1.1 skrll 2643 1.1 skrll LOCAL_SYMS is a pointer to the swapped in local symbols. 2644 1.1 skrll 2645 1.1 skrll LOCAL_SECTIONS is an array giving the section in the input file 2646 1.1 skrll corresponding to the st_shndx field of each local symbol. 2647 1.1 skrll 2648 1.1 skrll The global hash table entry for the global symbols can be found 2649 1.1 skrll via elf_sym_hashes (input_bfd). 2650 1.1 skrll 2651 1.1 skrll When generating relocatable output, this function must handle 2652 1.1 skrll STB_LOCAL/STT_SECTION symbols specially. The output symbol is 2653 1.1 skrll going to be the section symbol corresponding to the output 2654 1.1.1.9 christos section, which means that the addend must be adjusted 2655 1.1.1.3 christos accordingly. */ 2656 1.1.1.3 christos 2657 1.1.1.3 christos static int 2658 1.1.1.3 christos elf32_frv_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, 2659 1.1.1.3 christos struct bfd_link_info *info, 2660 1.1.1.3 christos bfd *input_bfd, 2661 1.1.1.3 christos asection *input_section, 2662 1.1.1.3 christos bfd_byte *contents, 2663 1.1 skrll Elf_Internal_Rela *relocs, 2664 1.1 skrll Elf_Internal_Sym *local_syms, 2665 1.1 skrll asection **local_sections) 2666 1.1 skrll { 2667 1.1 skrll Elf_Internal_Shdr *symtab_hdr; 2668 1.1 skrll struct elf_link_hash_entry **sym_hashes; 2669 1.1 skrll Elf_Internal_Rela *rel; 2670 1.1.1.4 christos Elf_Internal_Rela *relend; 2671 1.1 skrll unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment, 2672 1.1 skrll check_segment[2]; 2673 1.1 skrll int silence_segment_error = !bfd_link_pic (info); 2674 1.1 skrll unsigned long insn; 2675 1.1 skrll 2676 1.1 skrll symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; 2677 1.1 skrll sym_hashes = elf_sym_hashes (input_bfd); 2678 1.1 skrll relend = relocs + input_section->reloc_count; 2679 1.1 skrll 2680 1.1 skrll isec_segment = _frvfdpic_osec_to_segment (output_bfd, 2681 1.1 skrll input_section->output_section); 2682 1.1 skrll if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info)) 2683 1.1 skrll got_segment = _frvfdpic_osec_to_segment (output_bfd, 2684 1.1 skrll frvfdpic_got_section (info) 2685 1.1 skrll ->output_section); 2686 1.1 skrll else 2687 1.1 skrll got_segment = -1; 2688 1.1 skrll if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info)) 2689 1.1 skrll gprel_segment = _frvfdpic_osec_to_segment (output_bfd, 2690 1.1 skrll frvfdpic_gotfixup_section (info) 2691 1.1 skrll ->output_section); 2692 1.1 skrll else 2693 1.1 skrll gprel_segment = -1; 2694 1.1 skrll if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info)) 2695 1.1 skrll plt_segment = _frvfdpic_osec_to_segment (output_bfd, 2696 1.1 skrll frvfdpic_plt_section (info) 2697 1.1 skrll ->output_section); 2698 1.1 skrll else 2699 1.1 skrll plt_segment = -1; 2700 1.1 skrll if (elf_hash_table (info)->tls_sec) 2701 1.1 skrll tls_segment = _frvfdpic_osec_to_segment (output_bfd, 2702 1.1 skrll elf_hash_table (info)->tls_sec); 2703 1.1 skrll else 2704 1.1 skrll tls_segment = -1; 2705 1.1 skrll 2706 1.1 skrll for (rel = relocs; rel < relend; rel ++) 2707 1.1 skrll { 2708 1.1 skrll reloc_howto_type *howto; 2709 1.1 skrll unsigned long r_symndx; 2710 1.1 skrll Elf_Internal_Sym *sym; 2711 1.1 skrll asection *sec; 2712 1.1.1.2 christos struct elf_link_hash_entry *h; 2713 1.1 skrll bfd_vma relocation; 2714 1.1 skrll bfd_reloc_status_type r; 2715 1.1.1.9 christos const char *name; 2716 1.1 skrll int r_type; 2717 1.1 skrll asection *osec; 2718 1.1 skrll struct frvfdpic_relocs_info *picrel = NULL; 2719 1.1 skrll bfd_vma orig_addend = rel->r_addend; 2720 1.1 skrll 2721 1.1 skrll r_type = ELF32_R_TYPE (rel->r_info); 2722 1.1 skrll 2723 1.1 skrll if ( r_type == R_FRV_GNU_VTINHERIT 2724 1.1 skrll || r_type == R_FRV_GNU_VTENTRY) 2725 1.1 skrll continue; 2726 1.1 skrll 2727 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info); 2728 1.1 skrll howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info); 2729 1.1 skrll h = NULL; 2730 1.1 skrll sym = NULL; 2731 1.1 skrll sec = NULL; 2732 1.1 skrll 2733 1.1 skrll if (r_symndx < symtab_hdr->sh_info) 2734 1.1 skrll { 2735 1.1 skrll sym = local_syms + r_symndx; 2736 1.1 skrll osec = sec = local_sections [r_symndx]; 2737 1.1 skrll relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 2738 1.1.1.2 christos 2739 1.1.1.8 christos name = bfd_elf_string_from_elf_section 2740 1.1 skrll (input_bfd, symtab_hdr->sh_link, sym->st_name); 2741 1.1 skrll if (name == NULL || name[0] == 0) 2742 1.1 skrll name = bfd_section_name (sec); 2743 1.1.1.9 christos } 2744 1.1.1.9 christos else 2745 1.1 skrll { 2746 1.1 skrll bool warned, ignored; 2747 1.1 skrll bool unresolved_reloc; 2748 1.1 skrll 2749 1.1.1.4 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 2750 1.1 skrll r_symndx, symtab_hdr, sym_hashes, 2751 1.1.1.2 christos h, sec, relocation, 2752 1.1 skrll unresolved_reloc, warned, ignored); 2753 1.1 skrll osec = sec; 2754 1.1.1.3 christos name = h->root.root.string; 2755 1.1.1.2 christos } 2756 1.1.1.12 christos 2757 1.1.1.12 christos if (sec != NULL && discarded_section (sec)) 2758 1.1 skrll RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 2759 1.1.1.4 christos rel, 1, relend, R_FRV_NONE, 2760 1.1 skrll howto, 0, contents); 2761 1.1 skrll 2762 1.1 skrll if (bfd_link_relocatable (info)) 2763 1.1 skrll continue; 2764 1.1 skrll 2765 1.1 skrll if (r_type != R_FRV_TLSMOFF 2766 1.1 skrll && h != NULL 2767 1.1 skrll && (h->root.type == bfd_link_hash_defined 2768 1.1 skrll || h->root.type == bfd_link_hash_defweak) 2769 1.1 skrll && !FRVFDPIC_SYM_LOCAL (info, h)) 2770 1.1 skrll { 2771 1.1 skrll osec = sec = NULL; 2772 1.1 skrll relocation = 0; 2773 1.1 skrll } 2774 1.1 skrll 2775 1.1 skrll switch (r_type) 2776 1.1 skrll { 2777 1.1 skrll case R_FRV_LABEL24: 2778 1.1.1.6 christos case R_FRV_32: 2779 1.1 skrll if (! IS_FDPIC (output_bfd)) 2780 1.1 skrll goto non_fdpic; 2781 1.1 skrll /* Fall through. */ 2782 1.1 skrll 2783 1.1 skrll case R_FRV_GOT12: 2784 1.1 skrll case R_FRV_GOTHI: 2785 1.1 skrll case R_FRV_GOTLO: 2786 1.1 skrll case R_FRV_FUNCDESC_GOT12: 2787 1.1 skrll case R_FRV_FUNCDESC_GOTHI: 2788 1.1 skrll case R_FRV_FUNCDESC_GOTLO: 2789 1.1 skrll case R_FRV_GOTOFF12: 2790 1.1 skrll case R_FRV_GOTOFFHI: 2791 1.1 skrll case R_FRV_GOTOFFLO: 2792 1.1 skrll case R_FRV_FUNCDESC_GOTOFF12: 2793 1.1 skrll case R_FRV_FUNCDESC_GOTOFFHI: 2794 1.1 skrll case R_FRV_FUNCDESC_GOTOFFLO: 2795 1.1 skrll case R_FRV_FUNCDESC: 2796 1.1 skrll case R_FRV_FUNCDESC_VALUE: 2797 1.1 skrll case R_FRV_GETTLSOFF: 2798 1.1 skrll case R_FRV_TLSDESC_VALUE: 2799 1.1 skrll case R_FRV_GOTTLSDESC12: 2800 1.1 skrll case R_FRV_GOTTLSDESCHI: 2801 1.1 skrll case R_FRV_GOTTLSDESCLO: 2802 1.1 skrll case R_FRV_TLSMOFF12: 2803 1.1 skrll case R_FRV_TLSMOFFHI: 2804 1.1 skrll case R_FRV_TLSMOFFLO: 2805 1.1 skrll case R_FRV_GOTTLSOFF12: 2806 1.1 skrll case R_FRV_GOTTLSOFFHI: 2807 1.1 skrll case R_FRV_GOTTLSOFFLO: 2808 1.1 skrll case R_FRV_TLSOFF: 2809 1.1 skrll case R_FRV_TLSDESC_RELAX: 2810 1.1.1.9 christos case R_FRV_GETTLSOFF_RELAX: 2811 1.1.1.9 christos case R_FRV_TLSOFF_RELAX: 2812 1.1.1.9 christos case R_FRV_TLSMOFF: 2813 1.1 skrll if ((input_section->flags & SEC_ALLOC) == 0) 2814 1.1 skrll break; 2815 1.1 skrll 2816 1.1 skrll if (h != NULL) 2817 1.1 skrll picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info 2818 1.1 skrll (info), input_bfd, h, 2819 1.1 skrll orig_addend, INSERT); 2820 1.1 skrll else 2821 1.1 skrll /* In order to find the entry we created before, we must 2822 1.1 skrll use the original addend, not the one that may have been 2823 1.1 skrll modified by _bfd_elf_rela_local_sym(). */ 2824 1.1 skrll picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info 2825 1.1.1.9 christos (info), input_bfd, r_symndx, 2826 1.1 skrll orig_addend, INSERT); 2827 1.1 skrll if (! picrel) 2828 1.1 skrll return false; 2829 1.1 skrll 2830 1.1 skrll if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info, 2831 1.1.1.3 christos osec, sym, 2832 1.1.1.6 christos rel->r_addend)) 2833 1.1.1.3 christos { 2834 1.1.1.3 christos info->callbacks->einfo 2835 1.1 skrll /* xgettext:c-format */ 2836 1.1.1.9 christos (_("%H: relocation to `%s+%v'" 2837 1.1 skrll " may have caused the error above\n"), 2838 1.1 skrll input_bfd, input_section, rel->r_offset, name, rel->r_addend); 2839 1.1 skrll return false; 2840 1.1 skrll } 2841 1.1 skrll 2842 1.1 skrll break; 2843 1.1 skrll 2844 1.1.1.3 christos default: 2845 1.1.1.3 christos non_fdpic: 2846 1.1.1.3 christos picrel = NULL; 2847 1.1.1.3 christos if (h 2848 1.1.1.3 christos && ! FRVFDPIC_SYM_LOCAL (info, h) 2849 1.1.1.3 christos && _bfd_elf_section_offset (output_bfd, info, input_section, 2850 1.1.1.3 christos rel->r_offset) != (bfd_vma) -1) 2851 1.1.1.3 christos { 2852 1.1.1.3 christos info->callbacks->einfo 2853 1.1.1.9 christos (_("%H: relocation references symbol" 2854 1.1 skrll " not defined in the module\n"), 2855 1.1 skrll input_bfd, input_section, rel->r_offset); 2856 1.1 skrll return false; 2857 1.1 skrll } 2858 1.1 skrll break; 2859 1.1 skrll } 2860 1.1 skrll 2861 1.1 skrll switch (r_type) 2862 1.1 skrll { 2863 1.1 skrll case R_FRV_GETTLSOFF: 2864 1.1 skrll case R_FRV_TLSDESC_VALUE: 2865 1.1 skrll case R_FRV_GOTTLSDESC12: 2866 1.1 skrll case R_FRV_GOTTLSDESCHI: 2867 1.1 skrll case R_FRV_GOTTLSDESCLO: 2868 1.1 skrll case R_FRV_TLSMOFF12: 2869 1.1 skrll case R_FRV_TLSMOFFHI: 2870 1.1 skrll case R_FRV_TLSMOFFLO: 2871 1.1 skrll case R_FRV_GOTTLSOFF12: 2872 1.1 skrll case R_FRV_GOTTLSOFFHI: 2873 1.1 skrll case R_FRV_GOTTLSOFFLO: 2874 1.1 skrll case R_FRV_TLSOFF: 2875 1.1 skrll case R_FRV_TLSDESC_RELAX: 2876 1.1 skrll case R_FRV_GETTLSOFF_RELAX: 2877 1.1 skrll case R_FRV_TLSOFF_RELAX: 2878 1.1 skrll case R_FRV_TLSMOFF: 2879 1.1 skrll if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec))) 2880 1.1 skrll relocation += tls_biased_base (info); 2881 1.1 skrll break; 2882 1.1 skrll 2883 1.1 skrll default: 2884 1.1 skrll break; 2885 1.1 skrll } 2886 1.1 skrll 2887 1.1 skrll /* Try to apply TLS relaxations. */ 2888 1.1 skrll if (1) 2889 1.1 skrll switch (r_type) 2890 1.1.1.4 christos { 2891 1.1 skrll 2892 1.1 skrll #define LOCAL_EXEC_P(info, picrel) \ 2893 1.1.1.4 christos (bfd_link_executable (info) \ 2894 1.1 skrll && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h))) 2895 1.1 skrll #define INITIAL_EXEC_P(info, picrel) \ 2896 1.1 skrll ((bfd_link_executable (info)|| (info)->flags & DF_STATIC_TLS) \ 2897 1.1 skrll && (picrel)->tlsoff_entry) 2898 1.1 skrll 2899 1.1 skrll #define IN_RANGE_FOR_OFST12_P(value) \ 2900 1.1 skrll ((bfd_vma)((value) + 2048) < (bfd_vma)4096) 2901 1.1 skrll #define IN_RANGE_FOR_SETLOS_P(value) \ 2902 1.1 skrll ((bfd_vma)((value) + 32768) < (bfd_vma)65536) 2903 1.1 skrll #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \ 2904 1.1 skrll (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info))) 2905 1.1 skrll 2906 1.1 skrll #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ 2907 1.1 skrll (LOCAL_EXEC_P ((info), (picrel)) \ 2908 1.1 skrll && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) 2909 1.1 skrll #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \ 2910 1.1 skrll (INITIAL_EXEC_P ((info), (picrel)) \ 2911 1.1 skrll && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry)) 2912 1.1 skrll 2913 1.1 skrll #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \ 2914 1.1 skrll (LOCAL_EXEC_P ((info), (picrel))) 2915 1.1 skrll #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \ 2916 1.1 skrll (INITIAL_EXEC_P ((info), (picrel))) 2917 1.1 skrll 2918 1.1 skrll #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ 2919 1.1 skrll (LOCAL_EXEC_P ((info), (picrel)) \ 2920 1.1 skrll && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) 2921 1.1 skrll 2922 1.1 skrll case R_FRV_GETTLSOFF: 2923 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2924 1.1 skrll 2925 1.1.1.3 christos /* Is this a call instruction? */ 2926 1.1.1.3 christos if ((insn & (unsigned long)0x01fc0000) != 0x003c0000) 2927 1.1.1.3 christos { 2928 1.1.1.9 christos info->callbacks->einfo 2929 1.1 skrll (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"), 2930 1.1 skrll input_bfd, input_section, rel->r_offset); 2931 1.1 skrll return false; 2932 1.1 skrll } 2933 1.1 skrll 2934 1.1 skrll if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel, 2935 1.1 skrll relocation + rel->r_addend)) 2936 1.1 skrll { 2937 1.1 skrll /* Replace the call instruction (except the packing bit) 2938 1.1 skrll with setlos #tlsmofflo(symbol+offset), gr9. */ 2939 1.1 skrll insn &= (unsigned long)0x80000000; 2940 1.1 skrll insn |= (unsigned long)0x12fc0000; 2941 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2942 1.1 skrll 2943 1.1 skrll r_type = R_FRV_TLSMOFFLO; 2944 1.1 skrll howto = elf32_frv_howto_table + r_type; 2945 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2946 1.1 skrll } 2947 1.1 skrll 2948 1.1 skrll else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel)) 2949 1.1 skrll { 2950 1.1 skrll /* Replace the call instruction (except the packing bit) 2951 1.1 skrll with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */ 2952 1.1 skrll insn &= (unsigned long)0x80000000; 2953 1.1 skrll insn |= (unsigned long)0x12c8f000; 2954 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2955 1.1 skrll 2956 1.1 skrll r_type = R_FRV_GOTTLSOFF12; 2957 1.1 skrll howto = elf32_frv_howto_table + r_type; 2958 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2959 1.1 skrll } 2960 1.1 skrll 2961 1.1 skrll break; 2962 1.1 skrll 2963 1.1 skrll case R_FRV_GOTTLSDESC12: 2964 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2965 1.1 skrll 2966 1.1.1.3 christos /* Is this an lddi instruction? */ 2967 1.1.1.3 christos if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000) 2968 1.1.1.3 christos { 2969 1.1.1.3 christos info->callbacks->einfo 2970 1.1.1.9 christos (_("%H: R_FRV_GOTTLSDESC12" 2971 1.1 skrll " not applied to an lddi instruction\n"), 2972 1.1 skrll input_bfd, input_section, rel->r_offset); 2973 1.1 skrll return false; 2974 1.1 skrll } 2975 1.1 skrll 2976 1.1 skrll if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 2977 1.1 skrll relocation + rel->r_addend) 2978 1.1 skrll && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 2979 1.1 skrll info)) 2980 1.1 skrll { 2981 1.1 skrll /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC 2982 1.1 skrll with setlos #tlsmofflo(symbol+offset), gr<C+1>. 2983 1.1 skrll Preserve the packing bit. */ 2984 1.1 skrll insn = (insn & (unsigned long)0x80000000) 2985 1.1 skrll | ((insn + (unsigned long)0x02000000) 2986 1.1 skrll & (unsigned long)0x7e000000); 2987 1.1 skrll insn |= (unsigned long)0x00fc0000; 2988 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2989 1.1 skrll 2990 1.1 skrll r_type = R_FRV_TLSMOFFLO; 2991 1.1 skrll howto = elf32_frv_howto_table + r_type; 2992 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2993 1.1 skrll } 2994 1.1 skrll 2995 1.1 skrll else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 2996 1.1 skrll relocation + rel->r_addend)) 2997 1.1 skrll { 2998 1.1 skrll /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC 2999 1.1 skrll with sethi #tlsmoffhi(symbol+offset), gr<C+1>. 3000 1.1 skrll Preserve the packing bit. */ 3001 1.1 skrll insn = (insn & (unsigned long)0x80000000) 3002 1.1 skrll | ((insn + (unsigned long)0x02000000) 3003 1.1 skrll & (unsigned long)0x7e000000); 3004 1.1 skrll insn |= (unsigned long)0x00f80000; 3005 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3006 1.1 skrll 3007 1.1 skrll r_type = R_FRV_TLSMOFFHI; 3008 1.1 skrll howto = elf32_frv_howto_table + r_type; 3009 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3010 1.1 skrll } 3011 1.1 skrll 3012 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3013 1.1 skrll { 3014 1.1 skrll /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC 3015 1.1 skrll with ldi @(grB, #gottlsoff12(symbol+offset), 3016 1.1 skrll gr<C+1>. Preserve the packing bit. If gottlsoff12 3017 1.1 skrll overflows, we'll error out, but that's sort-of ok, 3018 1.1 skrll since we'd started with gottlsdesc12, that's actually 3019 1.1 skrll more demanding. Compiling with -fPIE instead of 3020 1.1 skrll -fpie would fix it; linking with --relax should fix 3021 1.1 skrll it as well. */ 3022 1.1 skrll insn = (insn & (unsigned long)0x80cbf000) 3023 1.1 skrll | ((insn + (unsigned long)0x02000000) 3024 1.1 skrll & (unsigned long)0x7e000000); 3025 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3026 1.1 skrll 3027 1.1 skrll r_type = R_FRV_GOTTLSOFF12; 3028 1.1 skrll howto = elf32_frv_howto_table + r_type; 3029 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3030 1.1 skrll } 3031 1.1 skrll 3032 1.1 skrll break; 3033 1.1 skrll 3034 1.1 skrll case R_FRV_GOTTLSDESCHI: 3035 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3036 1.1 skrll 3037 1.1.1.3 christos /* Is this a sethi instruction? */ 3038 1.1.1.3 christos if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) 3039 1.1.1.3 christos { 3040 1.1.1.3 christos info->callbacks->einfo 3041 1.1.1.9 christos (_("%H: R_FRV_GOTTLSDESCHI" 3042 1.1 skrll " not applied to a sethi instruction\n"), 3043 1.1 skrll input_bfd, input_section, rel->r_offset); 3044 1.1 skrll return false; 3045 1.1 skrll } 3046 1.1 skrll 3047 1.1 skrll if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3048 1.1 skrll relocation + rel->r_addend) 3049 1.1 skrll || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3050 1.1 skrll && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))) 3051 1.1 skrll { 3052 1.1 skrll /* Replace sethi with a nop. Preserve the packing bit. */ 3053 1.1 skrll insn &= (unsigned long)0x80000000; 3054 1.1 skrll insn |= (unsigned long)0x00880000; 3055 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3056 1.1 skrll 3057 1.1 skrll /* Nothing to relocate. */ 3058 1.1 skrll continue; 3059 1.1 skrll } 3060 1.1 skrll 3061 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3062 1.1 skrll { 3063 1.1 skrll /* Simply decay GOTTLSDESC to GOTTLSOFF. */ 3064 1.1 skrll r_type = R_FRV_GOTTLSOFFHI; 3065 1.1 skrll howto = elf32_frv_howto_table + r_type; 3066 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3067 1.1 skrll } 3068 1.1 skrll 3069 1.1 skrll break; 3070 1.1 skrll 3071 1.1 skrll case R_FRV_GOTTLSDESCLO: 3072 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3073 1.1 skrll 3074 1.1.1.3 christos /* Is this a setlo or setlos instruction? */ 3075 1.1.1.3 christos if ((insn & (unsigned long)0x01f70000) != 0x00f40000) 3076 1.1.1.3 christos { 3077 1.1.1.3 christos info->callbacks->einfo 3078 1.1.1.9 christos (_("%H: R_FRV_GOTTLSDESCLO" 3079 1.1 skrll " not applied to a setlo or setlos instruction\n"), 3080 1.1 skrll input_bfd, input_section, rel->r_offset); 3081 1.1 skrll return false; 3082 1.1 skrll } 3083 1.1 skrll 3084 1.1 skrll if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3085 1.1 skrll relocation + rel->r_addend) 3086 1.1 skrll || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3087 1.1 skrll && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) 3088 1.1 skrll { 3089 1.1 skrll /* Replace setlo/setlos with a nop. Preserve the 3090 1.1 skrll packing bit. */ 3091 1.1 skrll insn &= (unsigned long)0x80000000; 3092 1.1 skrll insn |= (unsigned long)0x00880000; 3093 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3094 1.1 skrll 3095 1.1 skrll /* Nothing to relocate. */ 3096 1.1 skrll continue; 3097 1.1 skrll } 3098 1.1 skrll 3099 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3100 1.1 skrll { 3101 1.1 skrll /* If the corresponding sethi (if it exists) decayed 3102 1.1 skrll to a nop, make sure this becomes (or already is) a 3103 1.1 skrll setlos, not setlo. */ 3104 1.1 skrll if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)) 3105 1.1 skrll { 3106 1.1 skrll insn |= (unsigned long)0x00080000; 3107 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3108 1.1 skrll } 3109 1.1 skrll 3110 1.1 skrll /* Simply decay GOTTLSDESC to GOTTLSOFF. */ 3111 1.1 skrll r_type = R_FRV_GOTTLSOFFLO; 3112 1.1 skrll howto = elf32_frv_howto_table + r_type; 3113 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3114 1.1 skrll } 3115 1.1 skrll 3116 1.1 skrll break; 3117 1.1 skrll 3118 1.1 skrll case R_FRV_TLSDESC_RELAX: 3119 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3120 1.1 skrll 3121 1.1.1.3 christos /* Is this an ldd instruction? */ 3122 1.1.1.3 christos if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140) 3123 1.1.1.3 christos { 3124 1.1.1.3 christos info->callbacks->einfo 3125 1.1.1.9 christos (_("%H: R_FRV_TLSDESC_RELAX" 3126 1.1 skrll " not applied to an ldd instruction\n"), 3127 1.1 skrll input_bfd, input_section, rel->r_offset); 3128 1.1 skrll return false; 3129 1.1 skrll } 3130 1.1 skrll 3131 1.1 skrll if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3132 1.1 skrll relocation + rel->r_addend) 3133 1.1 skrll && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3134 1.1 skrll info)) 3135 1.1 skrll { 3136 1.1 skrll /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3137 1.1 skrll with setlos #tlsmofflo(symbol+offset), gr<C+1>. 3138 1.1 skrll Preserve the packing bit. */ 3139 1.1 skrll insn = (insn & (unsigned long)0x80000000) 3140 1.1 skrll | ((insn + (unsigned long)0x02000000) 3141 1.1 skrll & (unsigned long)0x7e000000); 3142 1.1 skrll insn |= (unsigned long)0x00fc0000; 3143 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3144 1.1 skrll 3145 1.1 skrll r_type = R_FRV_TLSMOFFLO; 3146 1.1 skrll howto = elf32_frv_howto_table + r_type; 3147 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3148 1.1 skrll } 3149 1.1 skrll 3150 1.1 skrll else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3151 1.1 skrll relocation + rel->r_addend)) 3152 1.1 skrll { 3153 1.1 skrll /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3154 1.1 skrll with sethi #tlsmoffhi(symbol+offset), gr<C+1>. 3155 1.1 skrll Preserve the packing bit. */ 3156 1.1 skrll insn = (insn & (unsigned long)0x80000000) 3157 1.1 skrll | ((insn + (unsigned long)0x02000000) 3158 1.1 skrll & (unsigned long)0x7e000000); 3159 1.1 skrll insn |= (unsigned long)0x00f80000; 3160 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3161 1.1 skrll 3162 1.1 skrll r_type = R_FRV_TLSMOFFHI; 3163 1.1 skrll howto = elf32_frv_howto_table + r_type; 3164 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3165 1.1 skrll } 3166 1.1 skrll 3167 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3168 1.1 skrll && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) 3169 1.1 skrll { 3170 1.1 skrll /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3171 1.1 skrll with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>. 3172 1.1 skrll Preserve the packing bit. */ 3173 1.1 skrll insn = (insn & (unsigned long)0x8003f000) 3174 1.1 skrll | (unsigned long)0x00c80000 3175 1.1 skrll | ((insn + (unsigned long)0x02000000) 3176 1.1 skrll & (unsigned long)0x7e000000); 3177 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3178 1.1 skrll 3179 1.1 skrll r_type = R_FRV_GOTTLSOFF12; 3180 1.1 skrll howto = elf32_frv_howto_table + r_type; 3181 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3182 1.1 skrll } 3183 1.1 skrll 3184 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3185 1.1 skrll { 3186 1.1 skrll /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3187 1.1 skrll with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>. 3188 1.1 skrll Preserve the packing bit. */ 3189 1.1 skrll insn = (insn & (unsigned long)0x81ffffbf) 3190 1.1 skrll | ((insn + (unsigned long)0x02000000) 3191 1.1 skrll & (unsigned long)0x7e000000); 3192 1.1.1.6 christos bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3193 1.1.1.6 christos 3194 1.1 skrll /* #tlsoff(symbol+offset) is just a relaxation 3195 1.1 skrll annotation, so there's nothing left to 3196 1.1 skrll relocate. */ 3197 1.1 skrll continue; 3198 1.1 skrll } 3199 1.1 skrll 3200 1.1 skrll break; 3201 1.1 skrll 3202 1.1 skrll case R_FRV_GETTLSOFF_RELAX: 3203 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3204 1.1 skrll 3205 1.1.1.3 christos /* Is this a calll or callil instruction? */ 3206 1.1.1.3 christos if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000) 3207 1.1.1.3 christos { 3208 1.1.1.3 christos info->callbacks->einfo 3209 1.1.1.9 christos (_("%H: R_FRV_GETTLSOFF_RELAX" 3210 1.1 skrll " not applied to a calll instruction\n"), 3211 1.1 skrll input_bfd, input_section, rel->r_offset); 3212 1.1 skrll return false; 3213 1.1 skrll } 3214 1.1 skrll 3215 1.1 skrll if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3216 1.1 skrll relocation + rel->r_addend) 3217 1.1 skrll && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3218 1.1 skrll info)) 3219 1.1 skrll { 3220 1.1 skrll /* Replace calll with a nop. Preserve the packing bit. */ 3221 1.1 skrll insn &= (unsigned long)0x80000000; 3222 1.1 skrll insn |= (unsigned long)0x00880000; 3223 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3224 1.1 skrll 3225 1.1 skrll /* Nothing to relocate. */ 3226 1.1 skrll continue; 3227 1.1 skrll } 3228 1.1 skrll 3229 1.1 skrll else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3230 1.1 skrll relocation + rel->r_addend)) 3231 1.1 skrll { 3232 1.1 skrll /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9. 3233 1.1 skrll Preserve the packing bit. */ 3234 1.1 skrll insn &= (unsigned long)0x80000000; 3235 1.1 skrll insn |= (unsigned long)0x12f40000; 3236 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3237 1.1 skrll 3238 1.1 skrll r_type = R_FRV_TLSMOFFLO; 3239 1.1 skrll howto = elf32_frv_howto_table + r_type; 3240 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3241 1.1 skrll } 3242 1.1 skrll 3243 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3244 1.1 skrll { 3245 1.1 skrll /* Replace calll with a nop. Preserve the packing bit. */ 3246 1.1 skrll insn &= (unsigned long)0x80000000; 3247 1.1 skrll insn |= (unsigned long)0x00880000; 3248 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3249 1.1 skrll 3250 1.1 skrll /* Nothing to relocate. */ 3251 1.1 skrll continue; 3252 1.1 skrll } 3253 1.1 skrll 3254 1.1 skrll break; 3255 1.1 skrll 3256 1.1 skrll case R_FRV_GOTTLSOFF12: 3257 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3258 1.1 skrll 3259 1.1.1.3 christos /* Is this an ldi instruction? */ 3260 1.1.1.3 christos if ((insn & (unsigned long)0x01fc0000) != 0x00c80000) 3261 1.1.1.3 christos { 3262 1.1.1.3 christos info->callbacks->einfo 3263 1.1.1.9 christos (_("%H: R_FRV_GOTTLSOFF12" 3264 1.1 skrll " not applied to an ldi instruction\n"), 3265 1.1 skrll input_bfd, input_section, rel->r_offset); 3266 1.1 skrll return false; 3267 1.1 skrll } 3268 1.1 skrll 3269 1.1 skrll if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3270 1.1 skrll relocation + rel->r_addend)) 3271 1.1 skrll { 3272 1.1 skrll /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC 3273 1.1 skrll with setlos #tlsmofflo(symbol+offset), grC. 3274 1.1 skrll Preserve the packing bit. */ 3275 1.1 skrll insn &= (unsigned long)0xfe000000; 3276 1.1 skrll insn |= (unsigned long)0x00fc0000; 3277 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3278 1.1 skrll 3279 1.1 skrll r_type = R_FRV_TLSMOFFLO; 3280 1.1 skrll howto = elf32_frv_howto_table + r_type; 3281 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3282 1.1 skrll } 3283 1.1 skrll 3284 1.1 skrll break; 3285 1.1 skrll 3286 1.1 skrll case R_FRV_GOTTLSOFFHI: 3287 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3288 1.1 skrll 3289 1.1.1.3 christos /* Is this a sethi instruction? */ 3290 1.1.1.3 christos if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) 3291 1.1.1.3 christos { 3292 1.1.1.3 christos info->callbacks->einfo 3293 1.1.1.9 christos (_("%H: R_FRV_GOTTLSOFFHI" 3294 1.1 skrll " not applied to a sethi instruction\n"), 3295 1.1 skrll input_bfd, input_section, rel->r_offset); 3296 1.1 skrll return false; 3297 1.1 skrll } 3298 1.1 skrll 3299 1.1 skrll if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3300 1.1 skrll relocation + rel->r_addend) 3301 1.1 skrll || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3302 1.1 skrll && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) 3303 1.1 skrll { 3304 1.1 skrll /* Replace sethi with a nop. Preserve the packing bit. */ 3305 1.1 skrll insn &= (unsigned long)0x80000000; 3306 1.1 skrll insn |= (unsigned long)0x00880000; 3307 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3308 1.1 skrll 3309 1.1 skrll /* Nothing to relocate. */ 3310 1.1 skrll continue; 3311 1.1 skrll } 3312 1.1 skrll 3313 1.1 skrll break; 3314 1.1 skrll 3315 1.1 skrll case R_FRV_GOTTLSOFFLO: 3316 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3317 1.1 skrll 3318 1.1.1.3 christos /* Is this a setlo or setlos instruction? */ 3319 1.1.1.3 christos if ((insn & (unsigned long)0x01f70000) != 0x00f40000) 3320 1.1.1.3 christos { 3321 1.1.1.3 christos info->callbacks->einfo 3322 1.1.1.9 christos (_("%H: R_FRV_GOTTLSOFFLO" 3323 1.1 skrll " not applied to a setlo or setlos instruction\n"), 3324 1.1 skrll input_bfd, input_section, rel->r_offset); 3325 1.1 skrll return false; 3326 1.1 skrll } 3327 1.1 skrll 3328 1.1 skrll if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3329 1.1 skrll relocation + rel->r_addend) 3330 1.1 skrll || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3331 1.1 skrll && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) 3332 1.1 skrll { 3333 1.1 skrll /* Replace setlo/setlos with a nop. Preserve the 3334 1.1 skrll packing bit. */ 3335 1.1 skrll insn &= (unsigned long)0x80000000; 3336 1.1 skrll insn |= (unsigned long)0x00880000; 3337 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3338 1.1 skrll 3339 1.1 skrll /* Nothing to relocate. */ 3340 1.1 skrll continue; 3341 1.1 skrll } 3342 1.1 skrll 3343 1.1 skrll break; 3344 1.1 skrll 3345 1.1 skrll case R_FRV_TLSOFF_RELAX: 3346 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3347 1.1 skrll 3348 1.1.1.3 christos /* Is this an ld instruction? */ 3349 1.1.1.3 christos if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100) 3350 1.1.1.3 christos { 3351 1.1.1.3 christos info->callbacks->einfo 3352 1.1.1.9 christos (_("%H: R_FRV_TLSOFF_RELAX" 3353 1.1 skrll " not applied to an ld instruction\n"), 3354 1.1 skrll input_bfd, input_section, rel->r_offset); 3355 1.1 skrll return false; 3356 1.1 skrll } 3357 1.1 skrll 3358 1.1 skrll if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3359 1.1 skrll relocation + rel->r_addend)) 3360 1.1 skrll { 3361 1.1 skrll /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC 3362 1.1 skrll with setlos #tlsmofflo(symbol+offset), grC. 3363 1.1 skrll Preserve the packing bit. */ 3364 1.1 skrll insn &= (unsigned long)0xfe000000; 3365 1.1 skrll insn |= (unsigned long)0x00fc0000; 3366 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3367 1.1 skrll 3368 1.1 skrll r_type = R_FRV_TLSMOFFLO; 3369 1.1 skrll howto = elf32_frv_howto_table + r_type; 3370 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3371 1.1 skrll } 3372 1.1 skrll 3373 1.1 skrll else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3374 1.1 skrll && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) 3375 1.1 skrll { 3376 1.1 skrll /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC 3377 1.1.1.4 christos with ldi @(grB, #gottlsoff12(symbol+offset), grC. 3378 1.1 skrll Preserve the packing bit. */ 3379 1.1 skrll insn = (insn & (unsigned long)0xfe03f000) 3380 1.1 skrll | (unsigned long)0x00c80000; 3381 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3382 1.1 skrll 3383 1.1 skrll r_type = R_FRV_GOTTLSOFF12; 3384 1.1 skrll howto = elf32_frv_howto_table + r_type; 3385 1.1 skrll rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3386 1.1 skrll } 3387 1.1 skrll 3388 1.1 skrll break; 3389 1.1 skrll 3390 1.1 skrll case R_FRV_TLSMOFFHI: 3391 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3392 1.1 skrll 3393 1.1.1.3 christos /* Is this a sethi instruction? */ 3394 1.1.1.3 christos if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) 3395 1.1.1.3 christos { 3396 1.1.1.3 christos info->callbacks->einfo 3397 1.1.1.9 christos (_("%H: R_FRV_TLSMOFFHI" 3398 1.1 skrll " not applied to a sethi instruction\n"), 3399 1.1 skrll input_bfd, input_section, rel->r_offset); 3400 1.1 skrll return false; 3401 1.1 skrll } 3402 1.1 skrll 3403 1.1 skrll if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3404 1.1 skrll info)) 3405 1.1 skrll { 3406 1.1 skrll /* Replace sethi with a nop. Preserve the packing bit. */ 3407 1.1 skrll insn &= (unsigned long)0x80000000; 3408 1.1 skrll insn |= (unsigned long)0x00880000; 3409 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3410 1.1 skrll 3411 1.1 skrll /* Nothing to relocate. */ 3412 1.1 skrll continue; 3413 1.1 skrll } 3414 1.1 skrll 3415 1.1 skrll break; 3416 1.1 skrll 3417 1.1 skrll case R_FRV_TLSMOFFLO: 3418 1.1 skrll insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3419 1.1 skrll 3420 1.1.1.3 christos /* Is this a setlo or setlos instruction? */ 3421 1.1.1.3 christos if ((insn & (unsigned long)0x01f70000) != 0x00f40000) 3422 1.1.1.3 christos { 3423 1.1.1.3 christos info->callbacks->einfo 3424 1.1.1.9 christos (_("R_FRV_TLSMOFFLO" 3425 1.1 skrll " not applied to a setlo or setlos instruction\n"), 3426 1.1 skrll input_bfd, input_section, rel->r_offset); 3427 1.1 skrll return false; 3428 1.1 skrll } 3429 1.1 skrll 3430 1.1 skrll if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3431 1.1 skrll info)) 3432 1.1 skrll /* If the corresponding sethi (if it exists) decayed 3433 1.1 skrll to a nop, make sure this becomes (or already is) a 3434 1.1 skrll setlos, not setlo. */ 3435 1.1 skrll { 3436 1.1 skrll insn |= (unsigned long)0x00080000; 3437 1.1 skrll bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3438 1.1 skrll } 3439 1.1 skrll 3440 1.1 skrll break; 3441 1.1 skrll 3442 1.1 skrll /* 3443 1.1 skrll There's nothing to relax in these: 3444 1.1 skrll R_FRV_TLSDESC_VALUE 3445 1.1 skrll R_FRV_TLSOFF 3446 1.1 skrll R_FRV_TLSMOFF12 3447 1.1 skrll R_FRV_TLSMOFFHI 3448 1.1 skrll R_FRV_TLSMOFFLO 3449 1.1 skrll R_FRV_TLSMOFF 3450 1.1 skrll */ 3451 1.1 skrll 3452 1.1 skrll default: 3453 1.1 skrll break; 3454 1.1 skrll } 3455 1.1 skrll 3456 1.1 skrll switch (r_type) 3457 1.1 skrll { 3458 1.1 skrll case R_FRV_LABEL24: 3459 1.1 skrll check_segment[0] = isec_segment; 3460 1.1 skrll if (! IS_FDPIC (output_bfd)) 3461 1.1 skrll check_segment[1] = isec_segment; 3462 1.1 skrll else if (picrel->plt) 3463 1.1 skrll { 3464 1.1 skrll relocation = frvfdpic_plt_section (info)->output_section->vma 3465 1.1 skrll + frvfdpic_plt_section (info)->output_offset 3466 1.1 skrll + picrel->plt_entry; 3467 1.1 skrll check_segment[1] = plt_segment; 3468 1.1 skrll } 3469 1.1 skrll /* We don't want to warn on calls to undefined weak symbols, 3470 1.1 skrll as calls to them must be protected by non-NULL tests 3471 1.1 skrll anyway, and unprotected calls would invoke undefined 3472 1.1 skrll behavior. */ 3473 1.1 skrll else if (picrel->symndx == -1 3474 1.1 skrll && picrel->d.h->root.type == bfd_link_hash_undefweak) 3475 1.1 skrll check_segment[1] = check_segment[0]; 3476 1.1 skrll else 3477 1.1 skrll check_segment[1] = sec 3478 1.1 skrll ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3479 1.1 skrll : (unsigned)-1; 3480 1.1 skrll break; 3481 1.1 skrll 3482 1.1 skrll case R_FRV_GOT12: 3483 1.1 skrll case R_FRV_GOTHI: 3484 1.1 skrll case R_FRV_GOTLO: 3485 1.1 skrll relocation = picrel->got_entry; 3486 1.1 skrll check_segment[0] = check_segment[1] = got_segment; 3487 1.1 skrll break; 3488 1.1 skrll 3489 1.1 skrll case R_FRV_FUNCDESC_GOT12: 3490 1.1 skrll case R_FRV_FUNCDESC_GOTHI: 3491 1.1 skrll case R_FRV_FUNCDESC_GOTLO: 3492 1.1 skrll relocation = picrel->fdgot_entry; 3493 1.1 skrll check_segment[0] = check_segment[1] = got_segment; 3494 1.1 skrll break; 3495 1.1 skrll 3496 1.1 skrll case R_FRV_GOTOFFHI: 3497 1.1 skrll case R_FRV_GOTOFF12: 3498 1.1 skrll case R_FRV_GOTOFFLO: 3499 1.1 skrll relocation -= frvfdpic_got_section (info)->output_section->vma 3500 1.1 skrll + frvfdpic_got_section (info)->output_offset 3501 1.1 skrll + frvfdpic_got_initial_offset (info); 3502 1.1 skrll check_segment[0] = got_segment; 3503 1.1 skrll check_segment[1] = sec 3504 1.1 skrll ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3505 1.1 skrll : (unsigned)-1; 3506 1.1 skrll break; 3507 1.1 skrll 3508 1.1 skrll case R_FRV_FUNCDESC_GOTOFF12: 3509 1.1 skrll case R_FRV_FUNCDESC_GOTOFFHI: 3510 1.1 skrll case R_FRV_FUNCDESC_GOTOFFLO: 3511 1.1 skrll relocation = picrel->fd_entry; 3512 1.1 skrll check_segment[0] = check_segment[1] = got_segment; 3513 1.1 skrll break; 3514 1.1 skrll 3515 1.1 skrll case R_FRV_FUNCDESC: 3516 1.1 skrll { 3517 1.1 skrll int dynindx; 3518 1.1 skrll bfd_vma addend = rel->r_addend; 3519 1.1 skrll 3520 1.1 skrll if (! (h && h->root.type == bfd_link_hash_undefweak 3521 1.1 skrll && FRVFDPIC_SYM_LOCAL (info, h))) 3522 1.1 skrll { 3523 1.1 skrll /* If the symbol is dynamic and there may be dynamic 3524 1.1 skrll symbol resolution because we are or are linked with a 3525 1.1 skrll shared library, emit a FUNCDESC relocation such that 3526 1.1 skrll the dynamic linker will allocate the function 3527 1.1 skrll descriptor. If the symbol needs a non-local function 3528 1.1 skrll descriptor but binds locally (e.g., its visibility is 3529 1.1 skrll protected, emit a dynamic relocation decayed to 3530 1.1.1.4 christos section+offset. */ 3531 1.1 skrll if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h) 3532 1.1 skrll && FRVFDPIC_SYM_LOCAL (info, h) 3533 1.1 skrll && !bfd_link_pde (info)) 3534 1.1 skrll { 3535 1.1 skrll dynindx = elf_section_data (h->root.u.def.section 3536 1.1 skrll ->output_section)->dynindx; 3537 1.1 skrll addend += h->root.u.def.section->output_offset 3538 1.1 skrll + h->root.u.def.value; 3539 1.1 skrll } 3540 1.1 skrll else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)) 3541 1.1.1.3 christos { 3542 1.1.1.7 christos if (addend) 3543 1.1.1.3 christos { 3544 1.1.1.7 christos info->callbacks->einfo 3545 1.1.1.7 christos (_("%H: %s references dynamic symbol" 3546 1.1.1.9 christos " with nonzero addend\n"), 3547 1.1 skrll input_bfd, input_section, rel->r_offset, 3548 1.1 skrll "R_FRV_FUNCDESC"); 3549 1.1 skrll return false; 3550 1.1 skrll } 3551 1.1 skrll dynindx = h->dynindx; 3552 1.1 skrll } 3553 1.1 skrll else 3554 1.1 skrll { 3555 1.1 skrll /* Otherwise, we know we have a private function 3556 1.1 skrll descriptor, so reference it directly. */ 3557 1.1 skrll BFD_ASSERT (picrel->privfd); 3558 1.1 skrll r_type = R_FRV_32; 3559 1.1 skrll dynindx = elf_section_data (frvfdpic_got_section (info) 3560 1.1 skrll ->output_section)->dynindx; 3561 1.1 skrll addend = frvfdpic_got_section (info)->output_offset 3562 1.1 skrll + frvfdpic_got_initial_offset (info) 3563 1.1 skrll + picrel->fd_entry; 3564 1.1 skrll } 3565 1.1 skrll 3566 1.1 skrll /* If there is room for dynamic symbol resolution, emit 3567 1.1 skrll the dynamic relocation. However, if we're linking an 3568 1.1 skrll executable at a fixed location, we won't have emitted a 3569 1.1.1.4 christos dynamic symbol entry for the got section, so idx will 3570 1.1 skrll be zero, which means we can and should compute the 3571 1.1 skrll address of the private descriptor ourselves. */ 3572 1.1 skrll if (bfd_link_pde (info) 3573 1.1.1.8 christos && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h))) 3574 1.1 skrll { 3575 1.1 skrll addend += frvfdpic_got_section (info)->output_section->vma; 3576 1.1 skrll if ((bfd_section_flags (input_section->output_section) 3577 1.1 skrll & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3578 1.1 skrll { 3579 1.1 skrll bfd_vma offset; 3580 1.1 skrll 3581 1.1 skrll if (_frvfdpic_osec_readonly_p (output_bfd, 3582 1.1.1.3 christos input_section 3583 1.1.1.3 christos ->output_section)) 3584 1.1.1.3 christos { 3585 1.1.1.3 christos info->callbacks->einfo 3586 1.1.1.9 christos (_("%H: cannot emit fixups" 3587 1.1 skrll " in read-only section\n"), 3588 1.1 skrll input_bfd, input_section, rel->r_offset); 3589 1.1 skrll return false; 3590 1.1 skrll } 3591 1.1 skrll 3592 1.1 skrll offset = _bfd_elf_section_offset 3593 1.1 skrll (output_bfd, info, 3594 1.1 skrll input_section, rel->r_offset); 3595 1.1 skrll 3596 1.1 skrll if (offset != (bfd_vma)-1) 3597 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 3598 1.1 skrll frvfdpic_gotfixup_section 3599 1.1 skrll (info), 3600 1.1 skrll offset + input_section 3601 1.1 skrll ->output_section->vma 3602 1.1 skrll + input_section->output_offset, 3603 1.1.1.8 christos picrel); 3604 1.1 skrll } 3605 1.1 skrll } 3606 1.1 skrll else if ((bfd_section_flags (input_section->output_section) 3607 1.1 skrll & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3608 1.1 skrll { 3609 1.1 skrll bfd_vma offset; 3610 1.1 skrll 3611 1.1 skrll if (_frvfdpic_osec_readonly_p (output_bfd, 3612 1.1.1.3 christos input_section 3613 1.1.1.3 christos ->output_section)) 3614 1.1.1.3 christos { 3615 1.1.1.3 christos info->callbacks->einfo 3616 1.1.1.9 christos (_("%H: cannot emit dynamic relocations" 3617 1.1 skrll " in read-only section\n"), 3618 1.1 skrll input_bfd, input_section, rel->r_offset); 3619 1.1 skrll return false; 3620 1.1 skrll } 3621 1.1 skrll 3622 1.1 skrll offset = _bfd_elf_section_offset 3623 1.1 skrll (output_bfd, info, 3624 1.1 skrll input_section, rel->r_offset); 3625 1.1 skrll 3626 1.1 skrll if (offset != (bfd_vma)-1) 3627 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, 3628 1.1 skrll frvfdpic_gotrel_section (info), 3629 1.1 skrll offset + input_section 3630 1.1 skrll ->output_section->vma 3631 1.1 skrll + input_section->output_offset, 3632 1.1 skrll r_type, dynindx, addend, picrel); 3633 1.1 skrll } 3634 1.1 skrll else 3635 1.1 skrll addend += frvfdpic_got_section (info)->output_section->vma; 3636 1.1 skrll } 3637 1.1 skrll 3638 1.1 skrll /* We want the addend in-place because dynamic 3639 1.1 skrll relocations are REL. Setting relocation to it should 3640 1.1 skrll arrange for it to be installed. */ 3641 1.1 skrll relocation = addend - rel->r_addend; 3642 1.1 skrll } 3643 1.1 skrll check_segment[0] = check_segment[1] = got_segment; 3644 1.1 skrll break; 3645 1.1 skrll 3646 1.1 skrll case R_FRV_32: 3647 1.1 skrll if (! IS_FDPIC (output_bfd)) 3648 1.1 skrll { 3649 1.1 skrll check_segment[0] = check_segment[1] = -1; 3650 1.1 skrll break; 3651 1.1 skrll } 3652 1.1 skrll /* Fall through. */ 3653 1.1 skrll case R_FRV_FUNCDESC_VALUE: 3654 1.1 skrll { 3655 1.1 skrll int dynindx; 3656 1.1 skrll bfd_vma addend = rel->r_addend; 3657 1.1 skrll 3658 1.1 skrll /* If the symbol is dynamic but binds locally, use 3659 1.1 skrll section+offset. */ 3660 1.1 skrll if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) 3661 1.1.1.3 christos { 3662 1.1.1.7 christos if (addend && r_type == R_FRV_FUNCDESC_VALUE) 3663 1.1.1.7 christos { 3664 1.1.1.7 christos info->callbacks->einfo 3665 1.1.1.7 christos (_("%H: %s references dynamic symbol" 3666 1.1.1.9 christos " with nonzero addend\n"), 3667 1.1 skrll input_bfd, input_section, rel->r_offset, 3668 1.1 skrll "R_FRV_FUNCDESC_VALUE"); 3669 1.1 skrll return false; 3670 1.1 skrll } 3671 1.1 skrll dynindx = h->dynindx; 3672 1.1 skrll } 3673 1.1 skrll else 3674 1.1 skrll { 3675 1.1 skrll if (h) 3676 1.1 skrll addend += h->root.u.def.value; 3677 1.1 skrll else 3678 1.1 skrll addend += sym->st_value; 3679 1.1 skrll if (osec) 3680 1.1 skrll addend += osec->output_offset; 3681 1.1 skrll if (osec && osec->output_section 3682 1.1 skrll && ! bfd_is_abs_section (osec->output_section) 3683 1.1 skrll && ! bfd_is_und_section (osec->output_section)) 3684 1.1 skrll dynindx = elf_section_data (osec->output_section)->dynindx; 3685 1.1 skrll else 3686 1.1 skrll dynindx = 0; 3687 1.1 skrll } 3688 1.1 skrll 3689 1.1 skrll /* If we're linking an executable at a fixed address, we 3690 1.1.1.4 christos can omit the dynamic relocation as long as the symbol 3691 1.1 skrll is defined in the current link unit (which is implied 3692 1.1 skrll by its output section not being NULL). */ 3693 1.1 skrll if (bfd_link_pde (info) 3694 1.1 skrll && (!h || FRVFDPIC_SYM_LOCAL (info, h))) 3695 1.1 skrll { 3696 1.1.1.8 christos if (osec) 3697 1.1 skrll addend += osec->output_section->vma; 3698 1.1 skrll if (IS_FDPIC (input_bfd) 3699 1.1 skrll && (bfd_section_flags (input_section->output_section) 3700 1.1 skrll & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3701 1.1 skrll { 3702 1.1 skrll if (_frvfdpic_osec_readonly_p (output_bfd, 3703 1.1.1.3 christos input_section 3704 1.1.1.3 christos ->output_section)) 3705 1.1.1.3 christos { 3706 1.1.1.9 christos info->callbacks->einfo 3707 1.1 skrll (_("%H: cannot emit fixups in read-only section\n"), 3708 1.1 skrll input_bfd, input_section, rel->r_offset); 3709 1.1 skrll return false; 3710 1.1 skrll } 3711 1.1 skrll if (!h || h->root.type != bfd_link_hash_undefweak) 3712 1.1 skrll { 3713 1.1 skrll bfd_vma offset = _bfd_elf_section_offset 3714 1.1 skrll (output_bfd, info, 3715 1.1 skrll input_section, rel->r_offset); 3716 1.1 skrll 3717 1.1 skrll if (offset != (bfd_vma)-1) 3718 1.1 skrll { 3719 1.1 skrll _frvfdpic_add_rofixup (output_bfd, 3720 1.1 skrll frvfdpic_gotfixup_section 3721 1.1 skrll (info), 3722 1.1 skrll offset + input_section 3723 1.1 skrll ->output_section->vma 3724 1.1 skrll + input_section->output_offset, 3725 1.1 skrll picrel); 3726 1.1 skrll if (r_type == R_FRV_FUNCDESC_VALUE) 3727 1.1 skrll _frvfdpic_add_rofixup 3728 1.1 skrll (output_bfd, 3729 1.1 skrll frvfdpic_gotfixup_section (info), 3730 1.1 skrll offset 3731 1.1 skrll + input_section->output_section->vma 3732 1.1 skrll + input_section->output_offset + 4, picrel); 3733 1.1 skrll } 3734 1.1 skrll } 3735 1.1 skrll } 3736 1.1.1.8 christos } 3737 1.1 skrll else 3738 1.1 skrll { 3739 1.1 skrll if ((bfd_section_flags (input_section->output_section) 3740 1.1 skrll & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3741 1.1 skrll { 3742 1.1 skrll bfd_vma offset; 3743 1.1 skrll 3744 1.1 skrll if (_frvfdpic_osec_readonly_p (output_bfd, 3745 1.1.1.3 christos input_section 3746 1.1.1.3 christos ->output_section)) 3747 1.1.1.3 christos { 3748 1.1.1.3 christos info->callbacks->einfo 3749 1.1.1.9 christos (_("%H: cannot emit dynamic relocations" 3750 1.1 skrll " in read-only section\n"), 3751 1.1 skrll input_bfd, input_section, rel->r_offset); 3752 1.1 skrll return false; 3753 1.1 skrll } 3754 1.1 skrll 3755 1.1 skrll offset = _bfd_elf_section_offset 3756 1.1 skrll (output_bfd, info, 3757 1.1 skrll input_section, rel->r_offset); 3758 1.1 skrll 3759 1.1 skrll if (offset != (bfd_vma)-1) 3760 1.1 skrll _frvfdpic_add_dyn_reloc (output_bfd, 3761 1.1 skrll frvfdpic_gotrel_section (info), 3762 1.1 skrll offset + input_section 3763 1.1 skrll ->output_section->vma 3764 1.1 skrll + input_section->output_offset, 3765 1.1 skrll r_type, dynindx, addend, picrel); 3766 1.1 skrll } 3767 1.1 skrll else if (osec) 3768 1.1 skrll addend += osec->output_section->vma; 3769 1.1 skrll /* We want the addend in-place because dynamic 3770 1.1 skrll relocations are REL. Setting relocation to it 3771 1.1 skrll should arrange for it to be installed. */ 3772 1.1 skrll relocation = addend - rel->r_addend; 3773 1.1 skrll } 3774 1.1 skrll 3775 1.1 skrll if (r_type == R_FRV_FUNCDESC_VALUE) 3776 1.1 skrll { 3777 1.1.1.4 christos /* If we've omitted the dynamic relocation, just emit 3778 1.1 skrll the fixed addresses of the symbol and of the local 3779 1.1 skrll GOT base offset. */ 3780 1.1 skrll if (bfd_link_pde (info) 3781 1.1 skrll && (!h || FRVFDPIC_SYM_LOCAL (info, h))) 3782 1.1 skrll bfd_put_32 (output_bfd, 3783 1.1 skrll frvfdpic_got_section (info)->output_section->vma 3784 1.1 skrll + frvfdpic_got_section (info)->output_offset 3785 1.1 skrll + frvfdpic_got_initial_offset (info), 3786 1.1 skrll contents + rel->r_offset + 4); 3787 1.1 skrll else 3788 1.1 skrll /* A function descriptor used for lazy or local 3789 1.1 skrll resolving is initialized such that its high word 3790 1.1 skrll contains the output section index in which the 3791 1.1 skrll PLT entries are located, and the low word 3792 1.1 skrll contains the offset of the lazy PLT entry entry 3793 1.1 skrll point into that section. */ 3794 1.1 skrll bfd_put_32 (output_bfd, 3795 1.1 skrll h && ! FRVFDPIC_SYM_LOCAL (info, h) 3796 1.1 skrll ? 0 3797 1.1 skrll : _frvfdpic_osec_to_segment (output_bfd, 3798 1.1 skrll sec 3799 1.1 skrll ->output_section), 3800 1.1 skrll contents + rel->r_offset + 4); 3801 1.1 skrll } 3802 1.1 skrll } 3803 1.1 skrll check_segment[0] = check_segment[1] = got_segment; 3804 1.1 skrll break; 3805 1.1 skrll 3806 1.1 skrll case R_FRV_GPREL12: 3807 1.1 skrll case R_FRV_GPRELU12: 3808 1.1 skrll case R_FRV_GPREL32: 3809 1.1 skrll case R_FRV_GPRELHI: 3810 1.1 skrll case R_FRV_GPRELLO: 3811 1.1 skrll check_segment[0] = gprel_segment; 3812 1.1 skrll check_segment[1] = sec 3813 1.1 skrll ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3814 1.1 skrll : (unsigned)-1; 3815 1.1 skrll break; 3816 1.1 skrll 3817 1.1 skrll case R_FRV_GETTLSOFF: 3818 1.1 skrll relocation = frvfdpic_plt_section (info)->output_section->vma 3819 1.1 skrll + frvfdpic_plt_section (info)->output_offset 3820 1.1 skrll + picrel->tlsplt_entry; 3821 1.1 skrll BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1 3822 1.1 skrll && picrel->tlsdesc_entry); 3823 1.1 skrll check_segment[0] = isec_segment; 3824 1.1 skrll check_segment[1] = plt_segment; 3825 1.1 skrll break; 3826 1.1 skrll 3827 1.1 skrll case R_FRV_GOTTLSDESC12: 3828 1.1 skrll case R_FRV_GOTTLSDESCHI: 3829 1.1 skrll case R_FRV_GOTTLSDESCLO: 3830 1.1 skrll BFD_ASSERT (picrel->tlsdesc_entry); 3831 1.1 skrll relocation = picrel->tlsdesc_entry; 3832 1.1 skrll check_segment[0] = tls_segment; 3833 1.1 skrll check_segment[1] = sec 3834 1.1 skrll && ! bfd_is_abs_section (sec) 3835 1.1 skrll && ! bfd_is_und_section (sec) 3836 1.1 skrll ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3837 1.1 skrll : tls_segment; 3838 1.1 skrll break; 3839 1.1 skrll 3840 1.1 skrll case R_FRV_TLSMOFF12: 3841 1.1 skrll case R_FRV_TLSMOFFHI: 3842 1.1 skrll case R_FRV_TLSMOFFLO: 3843 1.1 skrll case R_FRV_TLSMOFF: 3844 1.1 skrll check_segment[0] = tls_segment; 3845 1.1 skrll if (! sec) 3846 1.1 skrll check_segment[1] = -1; 3847 1.1 skrll else if (bfd_is_abs_section (sec) 3848 1.1 skrll || bfd_is_und_section (sec)) 3849 1.1 skrll { 3850 1.1 skrll relocation = 0; 3851 1.1 skrll check_segment[1] = tls_segment; 3852 1.1 skrll } 3853 1.1 skrll else if (sec->output_section) 3854 1.1 skrll { 3855 1.1 skrll relocation -= tls_biased_base (info); 3856 1.1 skrll check_segment[1] = 3857 1.1 skrll _frvfdpic_osec_to_segment (output_bfd, sec->output_section); 3858 1.1 skrll } 3859 1.1 skrll else 3860 1.1 skrll check_segment[1] = -1; 3861 1.1 skrll break; 3862 1.1 skrll 3863 1.1 skrll case R_FRV_GOTTLSOFF12: 3864 1.1 skrll case R_FRV_GOTTLSOFFHI: 3865 1.1 skrll case R_FRV_GOTTLSOFFLO: 3866 1.1 skrll BFD_ASSERT (picrel->tlsoff_entry); 3867 1.1 skrll relocation = picrel->tlsoff_entry; 3868 1.1 skrll check_segment[0] = tls_segment; 3869 1.1 skrll check_segment[1] = sec 3870 1.1 skrll && ! bfd_is_abs_section (sec) 3871 1.1 skrll && ! bfd_is_und_section (sec) 3872 1.1 skrll ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3873 1.1 skrll : tls_segment; 3874 1.1 skrll break; 3875 1.1 skrll 3876 1.1 skrll case R_FRV_TLSDESC_VALUE: 3877 1.1 skrll case R_FRV_TLSOFF: 3878 1.1 skrll /* These shouldn't be present in input object files. */ 3879 1.1 skrll check_segment[0] = check_segment[1] = isec_segment; 3880 1.1 skrll break; 3881 1.1 skrll 3882 1.1 skrll case R_FRV_TLSDESC_RELAX: 3883 1.1 skrll case R_FRV_GETTLSOFF_RELAX: 3884 1.1 skrll case R_FRV_TLSOFF_RELAX: 3885 1.1 skrll /* These are just annotations for relaxation, nothing to do 3886 1.1 skrll here. */ 3887 1.1 skrll continue; 3888 1.1 skrll 3889 1.1 skrll default: 3890 1.1 skrll check_segment[0] = isec_segment; 3891 1.1 skrll check_segment[1] = sec 3892 1.1 skrll ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3893 1.1 skrll : (unsigned)-1; 3894 1.1 skrll break; 3895 1.1 skrll } 3896 1.1 skrll 3897 1.1 skrll if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd)) 3898 1.1 skrll { 3899 1.1 skrll /* If you take this out, remove the #error from fdpic-static-6.d 3900 1.1 skrll in the ld testsuite. */ 3901 1.1 skrll /* This helps catch problems in GCC while we can't do more 3902 1.1 skrll than static linking. The idea is to test whether the 3903 1.1.1.9 christos input file basename is crt0.o only once. */ 3904 1.1.1.9 christos if (silence_segment_error == 1) 3905 1.1.1.9 christos silence_segment_error = 3906 1.1.1.9 christos (strlen (bfd_get_filename (input_bfd)) == 6 3907 1.1.1.9 christos && filename_cmp (bfd_get_filename (input_bfd), "crt0.o") == 0) 3908 1.1 skrll || (strlen (bfd_get_filename (input_bfd)) > 6 3909 1.1 skrll && filename_cmp (bfd_get_filename (input_bfd) 3910 1.1 skrll + strlen (bfd_get_filename (input_bfd)) - 7, 3911 1.1 skrll "/crt0.o") == 0) 3912 1.1 skrll ? -1 : 0; 3913 1.1 skrll if (!silence_segment_error 3914 1.1 skrll /* We don't want duplicate errors for undefined 3915 1.1 skrll symbols. */ 3916 1.1.1.3 christos && !(picrel && picrel->symndx == -1 3917 1.1.1.6 christos && picrel->d.h->root.type == bfd_link_hash_undefined)) 3918 1.1.1.3 christos { 3919 1.1.1.3 christos info->callbacks->einfo 3920 1.1 skrll /* xgettext:c-format */ 3921 1.1.1.4 christos (_("%H: reloc against `%s' references a different segment\n"), 3922 1.1.1.9 christos input_bfd, input_section, rel->r_offset, name); 3923 1.1 skrll } 3924 1.1 skrll if (!silence_segment_error && bfd_link_pic (info)) 3925 1.1 skrll return false; 3926 1.1 skrll elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC; 3927 1.1 skrll } 3928 1.1 skrll 3929 1.1 skrll switch (r_type) 3930 1.1 skrll { 3931 1.1 skrll case R_FRV_GOTOFFHI: 3932 1.1 skrll case R_FRV_TLSMOFFHI: 3933 1.1 skrll /* We need the addend to be applied before we shift the 3934 1.1 skrll value right. */ 3935 1.1 skrll relocation += rel->r_addend; 3936 1.1 skrll /* Fall through. */ 3937 1.1 skrll case R_FRV_GOTHI: 3938 1.1 skrll case R_FRV_FUNCDESC_GOTHI: 3939 1.1 skrll case R_FRV_FUNCDESC_GOTOFFHI: 3940 1.1 skrll case R_FRV_GOTTLSOFFHI: 3941 1.1 skrll case R_FRV_GOTTLSDESCHI: 3942 1.1 skrll relocation >>= 16; 3943 1.1 skrll /* Fall through. */ 3944 1.1 skrll 3945 1.1 skrll case R_FRV_GOTLO: 3946 1.1 skrll case R_FRV_FUNCDESC_GOTLO: 3947 1.1 skrll case R_FRV_GOTOFFLO: 3948 1.1 skrll case R_FRV_FUNCDESC_GOTOFFLO: 3949 1.1 skrll case R_FRV_GOTTLSOFFLO: 3950 1.1 skrll case R_FRV_GOTTLSDESCLO: 3951 1.1 skrll case R_FRV_TLSMOFFLO: 3952 1.1 skrll relocation &= 0xffff; 3953 1.1 skrll break; 3954 1.1 skrll 3955 1.1 skrll default: 3956 1.1 skrll break; 3957 1.1 skrll } 3958 1.1 skrll 3959 1.1 skrll switch (r_type) 3960 1.1 skrll { 3961 1.1 skrll case R_FRV_LABEL24: 3962 1.1 skrll if (! IS_FDPIC (output_bfd) || ! picrel->plt) 3963 1.1 skrll break; 3964 1.1 skrll /* Fall through. */ 3965 1.1 skrll 3966 1.1 skrll /* When referencing a GOT entry, a function descriptor or a 3967 1.1 skrll PLT, we don't want the addend to apply to the reference, 3968 1.1 skrll but rather to the referenced symbol. The actual entry 3969 1.1 skrll will have already been created taking the addend into 3970 1.1 skrll account, so cancel it out here. */ 3971 1.1 skrll case R_FRV_GOT12: 3972 1.1 skrll case R_FRV_GOTHI: 3973 1.1 skrll case R_FRV_GOTLO: 3974 1.1 skrll case R_FRV_FUNCDESC_GOT12: 3975 1.1 skrll case R_FRV_FUNCDESC_GOTHI: 3976 1.1 skrll case R_FRV_FUNCDESC_GOTLO: 3977 1.1 skrll case R_FRV_FUNCDESC_GOTOFF12: 3978 1.1 skrll case R_FRV_FUNCDESC_GOTOFFHI: 3979 1.1 skrll case R_FRV_FUNCDESC_GOTOFFLO: 3980 1.1 skrll case R_FRV_GETTLSOFF: 3981 1.1 skrll case R_FRV_GOTTLSDESC12: 3982 1.1 skrll case R_FRV_GOTTLSDESCHI: 3983 1.1 skrll case R_FRV_GOTTLSDESCLO: 3984 1.1 skrll case R_FRV_GOTTLSOFF12: 3985 1.1 skrll case R_FRV_GOTTLSOFFHI: 3986 1.1 skrll case R_FRV_GOTTLSOFFLO: 3987 1.1 skrll /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12 3988 1.1 skrll here, since we do want to apply the addend to the others. 3989 1.1 skrll Note that we've applied the addend to GOTOFFHI before we 3990 1.1 skrll shifted it right. */ 3991 1.1 skrll case R_FRV_GOTOFFHI: 3992 1.1 skrll case R_FRV_TLSMOFFHI: 3993 1.1 skrll relocation -= rel->r_addend; 3994 1.1 skrll break; 3995 1.1 skrll 3996 1.1 skrll default: 3997 1.1 skrll break; 3998 1.1 skrll } 3999 1.1 skrll 4000 1.1 skrll if (r_type == R_FRV_HI16) 4001 1.1 skrll r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation); 4002 1.1 skrll 4003 1.1 skrll else if (r_type == R_FRV_LO16) 4004 1.1 skrll r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation); 4005 1.1 skrll 4006 1.1 skrll else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF) 4007 1.1 skrll r = elf32_frv_relocate_label24 (input_bfd, input_section, rel, 4008 1.1 skrll contents, relocation); 4009 1.1 skrll 4010 1.1 skrll else if (r_type == R_FRV_GPREL12) 4011 1.1 skrll r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel, 4012 1.1 skrll contents, relocation); 4013 1.1 skrll 4014 1.1 skrll else if (r_type == R_FRV_GPRELU12) 4015 1.1 skrll r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel, 4016 1.1 skrll contents, relocation); 4017 1.1 skrll 4018 1.1 skrll else if (r_type == R_FRV_GPRELLO) 4019 1.1 skrll r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel, 4020 1.1 skrll contents, relocation); 4021 1.1 skrll 4022 1.1 skrll else if (r_type == R_FRV_GPRELHI) 4023 1.1 skrll r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel, 4024 1.1 skrll contents, relocation); 4025 1.1 skrll 4026 1.1 skrll else if (r_type == R_FRV_TLSOFF 4027 1.1 skrll || r_type == R_FRV_TLSDESC_VALUE) 4028 1.1 skrll r = bfd_reloc_notsupported; 4029 1.1 skrll 4030 1.1 skrll else 4031 1.1 skrll r = frv_final_link_relocate (howto, input_bfd, input_section, contents, 4032 1.1 skrll rel, relocation); 4033 1.1 skrll 4034 1.1 skrll if (r != bfd_reloc_ok) 4035 1.1 skrll { 4036 1.1 skrll const char * msg = (const char *) NULL; 4037 1.1 skrll 4038 1.1.1.5 christos switch (r) 4039 1.1 skrll { 4040 1.1 skrll case bfd_reloc_overflow: 4041 1.1 skrll (*info->callbacks->reloc_overflow) 4042 1.1 skrll (info, (h ? &h->root : NULL), name, howto->name, 4043 1.1 skrll (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 4044 1.1.1.5 christos break; 4045 1.1.1.9 christos 4046 1.1 skrll case bfd_reloc_undefined: 4047 1.1 skrll (*info->callbacks->undefined_symbol) 4048 1.1 skrll (info, name, input_bfd, input_section, rel->r_offset, true); 4049 1.1 skrll break; 4050 1.1 skrll 4051 1.1 skrll case bfd_reloc_outofrange: 4052 1.1 skrll msg = _("internal error: out of range error"); 4053 1.1 skrll break; 4054 1.1 skrll 4055 1.1 skrll case bfd_reloc_notsupported: 4056 1.1 skrll msg = _("internal error: unsupported relocation error"); 4057 1.1 skrll break; 4058 1.1 skrll 4059 1.1 skrll case bfd_reloc_dangerous: 4060 1.1 skrll msg = _("internal error: dangerous relocation"); 4061 1.1 skrll break; 4062 1.1 skrll 4063 1.1 skrll default: 4064 1.1 skrll msg = _("internal error: unknown error"); 4065 1.1 skrll break; 4066 1.1 skrll } 4067 1.1.1.3 christos 4068 1.1.1.6 christos if (msg) 4069 1.1.1.3 christos { 4070 1.1.1.3 christos info->callbacks->einfo 4071 1.1.1.9 christos /* xgettext:c-format */ 4072 1.1 skrll (_("%H: reloc against `%s': %s\n"), 4073 1.1 skrll input_bfd, input_section, rel->r_offset, name, msg); 4074 1.1 skrll return false; 4075 1.1 skrll } 4076 1.1.1.9 christos } 4077 1.1 skrll } 4078 1.1 skrll 4079 1.1 skrll return true; 4080 1.1 skrll } 4081 1.1 skrll 4082 1.1 skrll /* Return the section that should be marked against GC for a given 4084 1.1 skrll relocation. */ 4085 1.1.1.12 christos 4086 1.1 skrll static asection * 4087 1.1.1.12 christos elf32_frv_gc_mark_hook (asection *sec, 4088 1.1 skrll struct bfd_link_info *info, 4089 1.1 skrll struct elf_reloc_cookie *cookie, 4090 1.1.1.12 christos struct elf_link_hash_entry *h, 4091 1.1 skrll unsigned int symndx) 4092 1.1 skrll { 4093 1.1 skrll if (h != NULL) 4094 1.1 skrll switch (ELF32_R_TYPE (cookie->rel->r_info)) 4095 1.1 skrll { 4096 1.1 skrll case R_FRV_GNU_VTINHERIT: 4097 1.1.1.12 christos case R_FRV_GNU_VTENTRY: 4098 1.1 skrll return NULL; 4099 1.1 skrll } 4100 1.1 skrll 4101 1.1 skrll return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx); 4102 1.1 skrll } 4103 1.1.1.9 christos 4104 1.1.1.3 christos /* Hook called by the linker routine which adds symbols from an object 4106 1.1.1.3 christos file. We use it to put .comm items in .scomm, and not .comm. */ 4107 1.1.1.3 christos 4108 1.1.1.3 christos static bool 4109 1.1.1.3 christos elf32_frv_add_symbol_hook (bfd *abfd, 4110 1.1.1.3 christos struct bfd_link_info *info, 4111 1.1 skrll Elf_Internal_Sym *sym, 4112 1.1 skrll const char **namep ATTRIBUTE_UNUSED, 4113 1.1.1.4 christos flagword *flagsp ATTRIBUTE_UNUSED, 4114 1.1 skrll asection **secp, 4115 1.1 skrll bfd_vma *valp) 4116 1.1 skrll { 4117 1.1 skrll if (sym->st_shndx == SHN_COMMON 4118 1.1 skrll && !bfd_link_relocatable (info) 4119 1.1 skrll && (int)sym->st_size <= (int)bfd_get_gp_size (abfd)) 4120 1.1 skrll { 4121 1.1 skrll /* Common symbols less than or equal to -G nn bytes are 4122 1.1 skrll automatically put into .sbss. */ 4123 1.1 skrll 4124 1.1 skrll asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); 4125 1.1 skrll 4126 1.1.1.9 christos if (scomm == NULL) 4127 1.1 skrll { 4128 1.1 skrll scomm = bfd_make_section_with_flags (abfd, ".scommon", 4129 1.1.1.9 christos (SEC_ALLOC 4130 1.1 skrll | SEC_IS_COMMON 4131 1.1 skrll | SEC_SMALL_DATA 4132 1.1 skrll | SEC_LINKER_CREATED)); 4133 1.1 skrll if (scomm == NULL) 4134 1.1 skrll return false; 4135 1.1 skrll } 4136 1.1.1.9 christos 4137 1.1 skrll *secp = scomm; 4138 1.1 skrll *valp = sym->st_size; 4139 1.1 skrll } 4140 1.1 skrll 4141 1.1.1.9 christos return true; 4142 1.1 skrll } 4143 1.1 skrll 4144 1.1 skrll /* We need dynamic symbols for every section, since segments can 4145 1.1 skrll relocate independently. */ 4146 1.1 skrll static bool 4147 1.1 skrll _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED, 4148 1.1 skrll struct bfd_link_info *info 4149 1.1 skrll ATTRIBUTE_UNUSED, 4150 1.1 skrll asection *p ATTRIBUTE_UNUSED) 4151 1.1 skrll { 4152 1.1 skrll switch (elf_section_data (p)->this_hdr.sh_type) 4153 1.1 skrll { 4154 1.1.1.9 christos case SHT_PROGBITS: 4155 1.1 skrll case SHT_NOBITS: 4156 1.1 skrll /* If sh_type is yet undecided, assume it could be 4157 1.1 skrll SHT_PROGBITS/SHT_NOBITS. */ 4158 1.1 skrll case SHT_NULL: 4159 1.1.1.9 christos return false; 4160 1.1 skrll 4161 1.1 skrll /* There shouldn't be section relative relocations 4162 1.1 skrll against any other section. */ 4163 1.1 skrll default: 4164 1.1 skrll return true; 4165 1.1 skrll } 4166 1.1 skrll } 4167 1.1.1.9 christos 4168 1.1 skrll /* Create a .got section, as well as its additional info field. This 4169 1.1 skrll is almost entirely copied from 4170 1.1 skrll elflink.c:_bfd_elf_create_got_section(). */ 4171 1.1 skrll 4172 1.1 skrll static bool 4173 1.1 skrll _frv_create_got_section (bfd *abfd, struct bfd_link_info *info) 4174 1.1.1.12 christos { 4175 1.1 skrll flagword flags, pltflags; 4176 1.1 skrll asection *s; 4177 1.1 skrll struct elf_link_hash_entry *h; 4178 1.1 skrll struct bfd_link_hash_entry *bh; 4179 1.1.1.6 christos elf_backend_data *bed = get_elf_backend_data (abfd); 4180 1.1.1.3 christos int ptralign; 4181 1.1.1.9 christos int offset; 4182 1.1 skrll 4183 1.1 skrll /* This function may be called more than once. */ 4184 1.1 skrll s = elf_hash_table (info)->sgot; 4185 1.1 skrll if (s != NULL) 4186 1.1 skrll return true; 4187 1.1 skrll 4188 1.1 skrll /* Machine specific: although pointers are 32-bits wide, we want the 4189 1.1 skrll GOT to be aligned to a 64-bit boundary, such that function 4190 1.1 skrll descriptors in it can be accessed with 64-bit loads and 4191 1.1 skrll stores. */ 4192 1.1 skrll ptralign = 3; 4193 1.1.1.3 christos 4194 1.1.1.6 christos flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 4195 1.1 skrll | SEC_LINKER_CREATED); 4196 1.1.1.8 christos pltflags = flags; 4197 1.1.1.9 christos 4198 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); 4199 1.1 skrll elf_hash_table (info)->sgot = s; 4200 1.1 skrll if (s == NULL 4201 1.1 skrll || !bfd_set_section_alignment (s, ptralign)) 4202 1.1 skrll return false; 4203 1.1 skrll 4204 1.1 skrll if (bed->want_got_sym) 4205 1.1 skrll { 4206 1.1 skrll /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got 4207 1.1 skrll (or .got.plt) section. We don't do this in the linker script 4208 1.1.1.9 christos because we don't want to define the symbol if we are not creating 4209 1.1 skrll a global offset table. */ 4210 1.1 skrll h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); 4211 1.1 skrll elf_hash_table (info)->hgot = h; 4212 1.1 skrll if (h == NULL) 4213 1.1.1.9 christos return false; 4214 1.1 skrll 4215 1.1 skrll /* Machine-specific: we want the symbol for executables as 4216 1.1 skrll well. */ 4217 1.1 skrll if (! bfd_elf_link_record_dynamic_symbol (info, h)) 4218 1.1 skrll return false; 4219 1.1 skrll } 4220 1.1 skrll 4221 1.1 skrll /* The first bit of the global offset table is the header. */ 4222 1.1 skrll s->size += bed->got_header_size; 4223 1.1 skrll 4224 1.1 skrll /* This is the machine-specific part. Create and initialize section 4225 1.1 skrll data for the got. */ 4226 1.1 skrll if (IS_FDPIC (abfd)) 4227 1.1 skrll { 4228 1.1.1.9 christos frvfdpic_relocs_info (info) = htab_try_create (1, 4229 1.1 skrll frvfdpic_relocs_info_hash, 4230 1.1.1.3 christos frvfdpic_relocs_info_eq, 4231 1.1.1.3 christos (htab_del) NULL); 4232 1.1.1.6 christos if (! frvfdpic_relocs_info (info)) 4233 1.1 skrll return false; 4234 1.1.1.8 christos 4235 1.1.1.9 christos s = bfd_make_section_anyway_with_flags (abfd, ".rel.got", 4236 1.1 skrll (flags | SEC_READONLY)); 4237 1.1 skrll elf_hash_table (info)->srelgot = s; 4238 1.1.1.3 christos if (s == NULL 4239 1.1.1.3 christos || !bfd_set_section_alignment (s, 2)) 4240 1.1 skrll return false; 4241 1.1.1.8 christos 4242 1.1.1.9 christos /* Machine-specific. */ 4243 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".rofixup", 4244 1.1 skrll (flags | SEC_READONLY)); 4245 1.1 skrll if (s == NULL 4246 1.1 skrll || !bfd_set_section_alignment (s, 2)) 4247 1.1 skrll return false; 4248 1.1 skrll 4249 1.1 skrll frvfdpic_gotfixup_section (info) = s; 4250 1.1 skrll offset = -2048; 4251 1.1 skrll flags = BSF_GLOBAL; 4252 1.1 skrll } 4253 1.1 skrll else 4254 1.1 skrll { 4255 1.1 skrll offset = 2048; 4256 1.1 skrll flags = BSF_GLOBAL | BSF_WEAK; 4257 1.1 skrll } 4258 1.1 skrll 4259 1.1.1.9 christos /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it 4260 1.1 skrll turns out that we're linking with a different linker script, the 4261 1.1.1.9 christos linker script will override it. */ 4262 1.1 skrll bh = NULL; 4263 1.1 skrll if (!(_bfd_generic_link_add_one_symbol 4264 1.1 skrll (info, abfd, "_gp", flags, s, offset, (const char *) NULL, false, 4265 1.1 skrll bed->collect, &bh))) 4266 1.1 skrll return false; 4267 1.1 skrll h = (struct elf_link_hash_entry *) bh; 4268 1.1 skrll h->def_regular = 1; 4269 1.1.1.9 christos h->type = STT_OBJECT; 4270 1.1 skrll /* h->other = STV_HIDDEN; */ /* Should we? */ 4271 1.1 skrll 4272 1.1.1.9 christos /* Machine-specific: we want the symbol for executables as well. */ 4273 1.1 skrll if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h)) 4274 1.1 skrll return false; 4275 1.1 skrll 4276 1.1 skrll if (!IS_FDPIC (abfd)) 4277 1.1 skrll return true; 4278 1.1 skrll 4279 1.1 skrll /* FDPIC supports Thread Local Storage, and this may require a 4280 1.1 skrll procedure linkage table for TLS PLT entries. */ 4281 1.1 skrll 4282 1.1 skrll /* This is mostly copied from 4283 1.1 skrll elflink.c:_bfd_elf_create_dynamic_sections(). */ 4284 1.1 skrll 4285 1.1 skrll flags = pltflags; 4286 1.1 skrll pltflags |= SEC_CODE; 4287 1.1.1.3 christos if (bed->plt_not_loaded) 4288 1.1 skrll pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); 4289 1.1.1.8 christos if (bed->plt_readonly) 4290 1.1.1.9 christos pltflags |= SEC_READONLY; 4291 1.1 skrll 4292 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); 4293 1.1 skrll if (s == NULL 4294 1.1 skrll || !bfd_set_section_alignment (s, bed->plt_alignment)) 4295 1.1 skrll return false; 4296 1.1 skrll /* FRV-specific: remember it. */ 4297 1.1 skrll frvfdpic_plt_section (info) = s; 4298 1.1 skrll 4299 1.1 skrll /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the 4300 1.1 skrll .plt section. */ 4301 1.1 skrll if (bed->want_plt_sym) 4302 1.1.1.9 christos { 4303 1.1 skrll h = _bfd_elf_define_linkage_sym (abfd, info, s, 4304 1.1 skrll "_PROCEDURE_LINKAGE_TABLE_"); 4305 1.1 skrll elf_hash_table (info)->hplt = h; 4306 1.1.1.3 christos if (h == NULL) 4307 1.1.1.3 christos return false; 4308 1.1 skrll } 4309 1.1.1.8 christos 4310 1.1.1.9 christos /* FRV-specific: we want rel relocations for the plt. */ 4311 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".rel.plt", 4312 1.1 skrll flags | SEC_READONLY); 4313 1.1 skrll if (s == NULL 4314 1.1.1.9 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 4315 1.1 skrll return false; 4316 1.1 skrll /* FRV-specific: remember it. */ 4317 1.1 skrll frvfdpic_pltrel_section (info) = s; 4318 1.1 skrll 4319 1.1 skrll return true; 4320 1.1.1.9 christos } 4321 1.1 skrll 4322 1.1 skrll /* Make sure the got and plt sections exist, and that our pointers in 4323 1.1 skrll the link hash table point to them. */ 4324 1.1 skrll 4325 1.1 skrll static bool 4326 1.1 skrll elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) 4327 1.1.1.12 christos { 4328 1.1 skrll /* This is mostly copied from 4329 1.1 skrll elflink.c:_bfd_elf_create_dynamic_sections(). */ 4330 1.1 skrll flagword flags; 4331 1.1 skrll asection *s; 4332 1.1 skrll elf_backend_data *bed = get_elf_backend_data (abfd); 4333 1.1 skrll 4334 1.1 skrll flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 4335 1.1 skrll | SEC_LINKER_CREATED); 4336 1.1 skrll 4337 1.1 skrll /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and 4338 1.1.1.9 christos .rel[a].bss sections. */ 4339 1.1 skrll 4340 1.1 skrll /* FRV-specific: we want to create the GOT and the PLT in the FRV 4341 1.1 skrll way. */ 4342 1.1 skrll if (! _frv_create_got_section (abfd, info)) 4343 1.1 skrll return false; 4344 1.1 skrll 4345 1.1 skrll /* FRV-specific: make sure we created everything we wanted. */ 4346 1.1 skrll BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info) 4347 1.1 skrll && frvfdpic_gotfixup_section (info) 4348 1.1 skrll && frvfdpic_plt_section (info) 4349 1.1 skrll && frvfdpic_pltrel_section (info)); 4350 1.1 skrll 4351 1.1 skrll if (bed->want_dynbss) 4352 1.1 skrll { 4353 1.1 skrll /* The .dynbss section is a place to put symbols which are defined 4354 1.1.1.3 christos by dynamic objects, are referenced by regular objects, and are 4355 1.1.1.3 christos not functions. We must allocate space for them in the process 4356 1.1 skrll image and use a R_*_COPY reloc to tell the dynamic linker to 4357 1.1.1.9 christos initialize them at run time. The linker script puts the .dynbss 4358 1.1 skrll section into the .bss section of the final image. */ 4359 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", 4360 1.1 skrll SEC_ALLOC | SEC_LINKER_CREATED); 4361 1.1 skrll if (s == NULL) 4362 1.1 skrll return false; 4363 1.1 skrll 4364 1.1 skrll /* The .rel[a].bss section holds copy relocs. This section is not 4365 1.1 skrll normally needed. We need to create it here, though, so that the 4366 1.1 skrll linker will map it to an output section. We can't just create it 4367 1.1 skrll only if we need it, because we will not know whether we need it 4368 1.1 skrll until we have seen all the input files, and the first time the 4369 1.1 skrll main linker code calls BFD after examining all the input files 4370 1.1.1.4 christos (size_dynamic_sections) the input sections have already been 4371 1.1 skrll mapped to the output sections. If the section turns out not to 4372 1.1.1.3 christos be needed, we can discard it later. We will never need this 4373 1.1.1.3 christos section when generating a shared object, since they do not use 4374 1.1.1.3 christos copy relocs. */ 4375 1.1.1.3 christos if (! bfd_link_pic (info)) 4376 1.1 skrll { 4377 1.1.1.8 christos s = bfd_make_section_anyway_with_flags (abfd, 4378 1.1.1.9 christos (bed->default_use_rela_p 4379 1.1 skrll ? ".rela.bss" : ".rel.bss"), 4380 1.1 skrll flags | SEC_READONLY); 4381 1.1 skrll if (s == NULL 4382 1.1.1.9 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 4383 1.1 skrll return false; 4384 1.1 skrll } 4385 1.1 skrll } 4386 1.1 skrll 4387 1.1 skrll return true; 4388 1.1 skrll } 4389 1.1 skrll 4390 1.1 skrll /* Compute the total GOT and PLT size required by each symbol in each 4391 1.1 skrll range. Symbols may require up to 4 words in the GOT: an entry 4392 1.1 skrll pointing to the symbol, an entry pointing to its function 4393 1.1 skrll descriptor, and a private function descriptors taking two 4394 1.1 skrll words. */ 4395 1.1 skrll 4396 1.1 skrll static void 4397 1.1 skrll _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry, 4398 1.1 skrll struct _frvfdpic_dynamic_got_info *dinfo) 4399 1.1 skrll { 4400 1.1 skrll /* Allocate space for a GOT entry pointing to the symbol. */ 4401 1.1 skrll if (entry->got12) 4402 1.1 skrll dinfo->got12 += 4; 4403 1.1 skrll else if (entry->gotlos) 4404 1.1 skrll dinfo->gotlos += 4; 4405 1.1 skrll else if (entry->gothilo) 4406 1.1 skrll dinfo->gothilo += 4; 4407 1.1 skrll else 4408 1.1 skrll entry->relocs32--; 4409 1.1 skrll entry->relocs32++; 4410 1.1 skrll 4411 1.1 skrll /* Allocate space for a GOT entry pointing to the function 4412 1.1 skrll descriptor. */ 4413 1.1 skrll if (entry->fdgot12) 4414 1.1 skrll dinfo->got12 += 4; 4415 1.1 skrll else if (entry->fdgotlos) 4416 1.1 skrll dinfo->gotlos += 4; 4417 1.1 skrll else if (entry->fdgothilo) 4418 1.1 skrll dinfo->gothilo += 4; 4419 1.1 skrll else 4420 1.1 skrll entry->relocsfd--; 4421 1.1 skrll entry->relocsfd++; 4422 1.1 skrll 4423 1.1 skrll /* Decide whether we need a PLT entry, a function descriptor in the 4424 1.1 skrll GOT, and a lazy PLT entry for this symbol. */ 4425 1.1 skrll entry->plt = entry->call 4426 1.1 skrll && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 4427 1.1 skrll && elf_hash_table (dinfo->info)->dynamic_sections_created; 4428 1.1 skrll entry->privfd = entry->plt 4429 1.1 skrll || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo 4430 1.1 skrll || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo) 4431 1.1 skrll && (entry->symndx != -1 4432 1.1 skrll || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))); 4433 1.1 skrll entry->lazyplt = entry->privfd 4434 1.1 skrll && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 4435 1.1 skrll && ! (dinfo->info->flags & DF_BIND_NOW) 4436 1.1 skrll && elf_hash_table (dinfo->info)->dynamic_sections_created; 4437 1.1 skrll 4438 1.1 skrll /* Allocate space for a function descriptor. */ 4439 1.1 skrll if (entry->fdgoff12) 4440 1.1 skrll dinfo->fd12 += 8; 4441 1.1 skrll else if (entry->fdgofflos) 4442 1.1 skrll dinfo->fdlos += 8; 4443 1.1 skrll else if (entry->privfd && entry->plt) 4444 1.1 skrll dinfo->fdplt += 8; 4445 1.1 skrll else if (entry->privfd) 4446 1.1 skrll dinfo->fdhilo += 8; 4447 1.1 skrll else 4448 1.1 skrll entry->relocsfdv--; 4449 1.1 skrll entry->relocsfdv++; 4450 1.1 skrll 4451 1.1 skrll if (entry->lazyplt) 4452 1.1 skrll dinfo->lzplt += 8; 4453 1.1 skrll } 4454 1.1 skrll 4455 1.1 skrll /* Compute the total GOT size required by each TLS symbol in each 4456 1.1 skrll range. Symbols may require up to 5 words in the GOT: an entry 4457 1.1 skrll holding the TLS offset for the symbol, and an entry with a full TLS 4458 1.1.1.9 christos descriptor taking 4 words. */ 4459 1.1 skrll 4460 1.1 skrll static void 4461 1.1 skrll _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry, 4462 1.1 skrll struct _frvfdpic_dynamic_got_info *dinfo, 4463 1.1 skrll bool subtract) 4464 1.1 skrll { 4465 1.1 skrll const int l = subtract ? -1 : 1; 4466 1.1 skrll 4467 1.1 skrll /* Allocate space for a GOT entry with the TLS offset of the 4468 1.1 skrll symbol. */ 4469 1.1 skrll if (entry->tlsoff12) 4470 1.1 skrll dinfo->got12 += 4 * l; 4471 1.1 skrll else if (entry->tlsofflos) 4472 1.1 skrll dinfo->gotlos += 4 * l; 4473 1.1 skrll else if (entry->tlsoffhilo) 4474 1.1 skrll dinfo->gothilo += 4 * l; 4475 1.1 skrll else 4476 1.1 skrll entry->relocstlsoff -= l; 4477 1.1 skrll entry->relocstlsoff += l; 4478 1.1 skrll 4479 1.1 skrll /* If there's any TLSOFF relocation, mark the output file as not 4480 1.1 skrll suitable for dlopening. This mark will remain even if we relax 4481 1.1 skrll all such relocations, but this is not a problem, since we'll only 4482 1.1 skrll do so for executables, and we definitely don't want anyone 4483 1.1 skrll dlopening executables. */ 4484 1.1 skrll if (entry->relocstlsoff) 4485 1.1 skrll dinfo->info->flags |= DF_STATIC_TLS; 4486 1.1 skrll 4487 1.1 skrll /* Allocate space for a TLS descriptor. */ 4488 1.1 skrll if (entry->tlsdesc12) 4489 1.1 skrll dinfo->tlsd12 += 8 * l; 4490 1.1 skrll else if (entry->tlsdesclos) 4491 1.1 skrll dinfo->tlsdlos += 8 * l; 4492 1.1 skrll else if (entry->tlsplt) 4493 1.1 skrll dinfo->tlsdplt += 8 * l; 4494 1.1 skrll else if (entry->tlsdeschilo) 4495 1.1 skrll dinfo->tlsdhilo += 8 * l; 4496 1.1 skrll else 4497 1.1 skrll entry->relocstlsd -= l; 4498 1.1 skrll entry->relocstlsd += l; 4499 1.1 skrll } 4500 1.1 skrll 4501 1.1 skrll /* Compute the number of dynamic relocations and fixups that a symbol 4502 1.1 skrll requires, and add (or subtract) from the grand and per-symbol 4503 1.1.1.9 christos totals. */ 4504 1.1 skrll 4505 1.1 skrll static void 4506 1.1 skrll _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry, 4507 1.1.1.4 christos struct _frvfdpic_dynamic_got_info *dinfo, 4508 1.1 skrll bool subtract) 4509 1.1 skrll { 4510 1.1 skrll bfd_vma relocs = 0, fixups = 0, tlsrets = 0; 4511 1.1 skrll 4512 1.1 skrll if (!bfd_link_pde (dinfo->info)) 4513 1.1 skrll { 4514 1.1 skrll relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv 4515 1.1 skrll + entry->relocstlsd; 4516 1.1 skrll 4517 1.1 skrll /* In the executable, TLS relocations to symbols that bind 4518 1.1 skrll locally (including those that resolve to global TLS offsets) 4519 1.1.1.4 christos are resolved immediately, without any need for fixups or 4520 1.1 skrll dynamic relocations. In shared libraries, however, we must 4521 1.1 skrll emit dynamic relocations even for local symbols, because we 4522 1.1 skrll don't know the module id the library is going to get at 4523 1.1 skrll run-time, nor its TLS base offset. */ 4524 1.1 skrll if (!bfd_link_executable (dinfo->info) 4525 1.1 skrll || (entry->symndx == -1 4526 1.1 skrll && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) 4527 1.1 skrll relocs += entry->relocstlsoff; 4528 1.1 skrll } 4529 1.1 skrll else 4530 1.1 skrll { 4531 1.1 skrll if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)) 4532 1.1 skrll { 4533 1.1 skrll if (entry->symndx != -1 4534 1.1 skrll || entry->d.h->root.type != bfd_link_hash_undefweak) 4535 1.1 skrll fixups += entry->relocs32 + 2 * entry->relocsfdv; 4536 1.1 skrll fixups += entry->relocstlsd; 4537 1.1 skrll tlsrets += entry->relocstlsd; 4538 1.1 skrll } 4539 1.1 skrll else 4540 1.1 skrll { 4541 1.1 skrll relocs += entry->relocs32 + entry->relocsfdv 4542 1.1 skrll + entry->relocstlsoff + entry->relocstlsd; 4543 1.1 skrll } 4544 1.1 skrll 4545 1.1 skrll if (entry->symndx != -1 4546 1.1 skrll || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)) 4547 1.1 skrll { 4548 1.1 skrll if (entry->symndx != -1 4549 1.1 skrll || entry->d.h->root.type != bfd_link_hash_undefweak) 4550 1.1 skrll fixups += entry->relocsfd; 4551 1.1 skrll } 4552 1.1 skrll else 4553 1.1 skrll relocs += entry->relocsfd; 4554 1.1 skrll } 4555 1.1 skrll 4556 1.1 skrll if (subtract) 4557 1.1 skrll { 4558 1.1 skrll relocs = - relocs; 4559 1.1 skrll fixups = - fixups; 4560 1.1 skrll tlsrets = - tlsrets; 4561 1.1 skrll } 4562 1.1 skrll 4563 1.1 skrll entry->dynrelocs += relocs; 4564 1.1 skrll entry->fixups += fixups; 4565 1.1 skrll dinfo->relocs += relocs; 4566 1.1 skrll dinfo->fixups += fixups; 4567 1.1 skrll dinfo->tls_ret_refs += tlsrets; 4568 1.1 skrll } 4569 1.1 skrll 4570 1.1 skrll /* Look for opportunities to relax TLS relocations. We can assume 4571 1.1 skrll we're linking the main executable or a static-tls library, since 4572 1.1 skrll otherwise we wouldn't have got here. When relaxing, we have to 4573 1.1 skrll first undo any previous accounting of TLS uses of fixups, dynamic 4574 1.1.1.9 christos relocations, GOT and PLT entries. */ 4575 1.1 skrll 4576 1.1.1.9 christos static void 4577 1.1 skrll _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry, 4578 1.1.1.4 christos struct _frvfdpic_dynamic_got_info *dinfo, 4579 1.1 skrll bool relaxing) 4580 1.1 skrll { 4581 1.1 skrll bool changed = ! relaxing; 4582 1.1 skrll 4583 1.1 skrll BFD_ASSERT (bfd_link_executable (dinfo->info) 4584 1.1 skrll || (dinfo->info->flags & DF_STATIC_TLS)); 4585 1.1.1.9 christos 4586 1.1.1.9 christos if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo) 4587 1.1.1.9 christos { 4588 1.1 skrll if (! changed) 4589 1.1 skrll { 4590 1.1 skrll _frvfdpic_count_relocs_fixups (entry, dinfo, true); 4591 1.1 skrll _frvfdpic_count_tls_entries (entry, dinfo, true); 4592 1.1 skrll changed = true; 4593 1.1 skrll } 4594 1.1 skrll 4595 1.1 skrll /* When linking an executable, we can always decay GOTTLSDESC to 4596 1.1 skrll TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise. 4597 1.1.1.4 christos When linking a static-tls shared library, using TLSMOFF is 4598 1.1 skrll not an option, but we can still use GOTTLSOFF. When decaying 4599 1.1 skrll to GOTTLSOFF, we must keep the GOT entry in range. We know 4600 1.1 skrll it has to fit because we'll be trading the 4 words of hte TLS 4601 1.1 skrll descriptor for a single word in the same range. */ 4602 1.1 skrll if (! bfd_link_executable (dinfo->info) 4603 1.1 skrll || (entry->symndx == -1 4604 1.1 skrll && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) 4605 1.1 skrll { 4606 1.1 skrll entry->tlsoff12 |= entry->tlsdesc12; 4607 1.1 skrll entry->tlsofflos |= entry->tlsdesclos; 4608 1.1 skrll entry->tlsoffhilo |= entry->tlsdeschilo; 4609 1.1 skrll } 4610 1.1 skrll 4611 1.1 skrll entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0; 4612 1.1 skrll } 4613 1.1 skrll 4614 1.1 skrll /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the 4615 1.1 skrll main executable. We have to check whether the symbol's TLSOFF is 4616 1.1 skrll in range for a setlos. For symbols with a hash entry, we can 4617 1.1 skrll determine exactly what to do; for others locals, we don't have 4618 1.1 skrll addresses handy, so we use the size of the TLS section as an 4619 1.1 skrll approximation. If we get it wrong, we'll retain a GOT entry 4620 1.1 skrll holding the TLS offset (without dynamic relocations or fixups), 4621 1.1.1.4 christos but we'll still optimize away the loads from it. Since TLS sizes 4622 1.1 skrll are generally very small, it's probably not worth attempting to 4623 1.1 skrll do better than this. */ 4624 1.1 skrll if ((entry->tlsplt 4625 1.1 skrll || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo) 4626 1.1 skrll && bfd_link_executable (dinfo->info) && relaxing 4627 1.1 skrll && ((entry->symndx == -1 4628 1.1 skrll && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 4629 1.1 skrll /* The above may hold for an undefweak TLS symbol, so make 4630 1.1 skrll sure we don't have this case before accessing def.value 4631 1.1 skrll and def.section. */ 4632 1.1 skrll && (entry->d.h->root.type == bfd_link_hash_undefweak 4633 1.1 skrll || (bfd_vma)(entry->d.h->root.u.def.value 4634 1.1 skrll + (entry->d.h->root.u.def.section 4635 1.1 skrll ->output_section->vma) 4636 1.1 skrll + entry->d.h->root.u.def.section->output_offset 4637 1.1.1.4 christos + entry->addend 4638 1.1 skrll - tls_biased_base (dinfo->info) 4639 1.1 skrll + 32768) < (bfd_vma)65536)) 4640 1.1 skrll || (entry->symndx != -1 4641 1.1.1.9 christos && (elf_hash_table (dinfo->info)->tls_sec->size 4642 1.1.1.9 christos + entry->addend < 32768 + FRVFDPIC_TLS_BIAS)))) 4643 1.1.1.9 christos { 4644 1.1 skrll if (! changed) 4645 1.1 skrll { 4646 1.1 skrll _frvfdpic_count_relocs_fixups (entry, dinfo, true); 4647 1.1 skrll _frvfdpic_count_tls_entries (entry, dinfo, true); 4648 1.1 skrll changed = true; 4649 1.1 skrll } 4650 1.1 skrll 4651 1.1 skrll entry->tlsplt = 4652 1.1 skrll entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0; 4653 1.1 skrll } 4654 1.1 skrll 4655 1.1 skrll /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already 4656 1.1 skrll have a #gottlsoff12 relocation for this entry, or if we can fit 4657 1.1 skrll one more in the 12-bit (and 16-bit) ranges. */ 4658 1.1 skrll if (entry->tlsplt 4659 1.1 skrll && (entry->tlsoff12 4660 1.1 skrll || (relaxing 4661 1.1 skrll && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4 4662 1.1 skrll && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 4663 1.1.1.9 christos + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos 4664 1.1.1.9 christos <= 65536 - 12 - 4)))) 4665 1.1.1.9 christos { 4666 1.1 skrll if (! changed) 4667 1.1 skrll { 4668 1.1 skrll _frvfdpic_count_relocs_fixups (entry, dinfo, true); 4669 1.1 skrll _frvfdpic_count_tls_entries (entry, dinfo, true); 4670 1.1 skrll changed = true; 4671 1.1 skrll } 4672 1.1 skrll 4673 1.1 skrll entry->tlsoff12 = 1; 4674 1.1.1.9 christos entry->tlsplt = 0; 4675 1.1.1.9 christos } 4676 1.1 skrll 4677 1.1 skrll if (changed) 4678 1.1 skrll { 4679 1.1 skrll _frvfdpic_count_tls_entries (entry, dinfo, false); 4680 1.1 skrll _frvfdpic_count_relocs_fixups (entry, dinfo, false); 4681 1.1 skrll } 4682 1.1 skrll 4683 1.1 skrll return; 4684 1.1 skrll } 4685 1.1 skrll 4686 1.1 skrll /* Compute the total GOT and PLT size required by each symbol in each range. * 4687 1.1 skrll Symbols may require up to 4 words in the GOT: an entry pointing to 4688 1.1 skrll the symbol, an entry pointing to its function descriptor, and a 4689 1.1 skrll private function descriptors taking two words. */ 4690 1.1 skrll 4691 1.1 skrll static int 4692 1.1 skrll _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_) 4693 1.1 skrll { 4694 1.1.1.4 christos struct frvfdpic_relocs_info *entry = *entryp; 4695 1.1.1.4 christos struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; 4696 1.1.1.9 christos 4697 1.1 skrll _frvfdpic_count_nontls_entries (entry, dinfo); 4698 1.1 skrll 4699 1.1.1.9 christos if (bfd_link_executable (dinfo->info) 4700 1.1.1.9 christos || (dinfo->info->flags & DF_STATIC_TLS)) 4701 1.1 skrll _frvfdpic_relax_tls_entries (entry, dinfo, false); 4702 1.1 skrll else 4703 1.1 skrll { 4704 1.1 skrll _frvfdpic_count_tls_entries (entry, dinfo, false); 4705 1.1 skrll _frvfdpic_count_relocs_fixups (entry, dinfo, false); 4706 1.1 skrll } 4707 1.1 skrll 4708 1.1 skrll return 1; 4709 1.1 skrll } 4710 1.1 skrll 4711 1.1 skrll /* Determine the positive and negative ranges to be used by each 4712 1.1 skrll offset range in the GOT. FDCUR and CUR, that must be aligned to a 4713 1.1 skrll double-word boundary, are the minimum (negative) and maximum 4714 1.1 skrll (positive) GOT offsets already used by previous ranges, except for 4715 1.1 skrll an ODD entry that may have been left behind. GOT and FD indicate 4716 1.1 skrll the size of GOT entries and function descriptors that must be 4717 1.1 skrll placed within the range from -WRAP to WRAP. If there's room left, 4718 1.1 skrll up to FDPLT bytes should be reserved for additional function 4719 1.1 skrll descriptors. */ 4720 1.1 skrll 4721 1.1 skrll inline static bfd_signed_vma 4722 1.1 skrll _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad, 4723 1.1 skrll bfd_signed_vma fdcur, 4724 1.1 skrll bfd_signed_vma odd, 4725 1.1 skrll bfd_signed_vma cur, 4726 1.1 skrll bfd_vma got, 4727 1.1 skrll bfd_vma fd, 4728 1.1 skrll bfd_vma fdplt, 4729 1.1 skrll bfd_vma tlsd, 4730 1.1 skrll bfd_vma tlsdplt, 4731 1.1 skrll bfd_vma wrap) 4732 1.1 skrll { 4733 1.1 skrll bfd_signed_vma wrapmin = -wrap; 4734 1.1 skrll const bfd_vma tdescsz = 8; 4735 1.1 skrll 4736 1.1 skrll /* Start at the given initial points. */ 4737 1.1 skrll gad->fdcur = fdcur; 4738 1.1 skrll gad->cur = cur; 4739 1.1 skrll 4740 1.1 skrll /* If we had an incoming odd word and we have any got entries that 4741 1.1 skrll are going to use it, consume it, otherwise leave gad->odd at 4742 1.1 skrll zero. We might force gad->odd to zero and return the incoming 4743 1.1 skrll odd such that it is used by the next range, but then GOT entries 4744 1.1 skrll might appear to be out of order and we wouldn't be able to 4745 1.1 skrll shorten the GOT by one word if it turns out to end with an 4746 1.1 skrll unpaired GOT entry. */ 4747 1.1 skrll if (odd && got) 4748 1.1 skrll { 4749 1.1 skrll gad->odd = odd; 4750 1.1 skrll got -= 4; 4751 1.1 skrll odd = 0; 4752 1.1 skrll } 4753 1.1 skrll else 4754 1.1 skrll gad->odd = 0; 4755 1.1 skrll 4756 1.1 skrll /* If we're left with an unpaired GOT entry, compute its location 4757 1.1 skrll such that we can return it. Otherwise, if got doesn't require an 4758 1.1 skrll odd number of words here, either odd was already zero in the 4759 1.1 skrll block above, or it was set to zero because got was non-zero, or 4760 1.1 skrll got was already zero. In the latter case, we want the value of 4761 1.1 skrll odd to carry over to the return statement, so we don't want to 4762 1.1 skrll reset odd unless the condition below is true. */ 4763 1.1 skrll if (got & 4) 4764 1.1 skrll { 4765 1.1 skrll odd = cur + got; 4766 1.1 skrll got += 4; 4767 1.1 skrll } 4768 1.1 skrll 4769 1.1 skrll /* Compute the tentative boundaries of this range. */ 4770 1.1 skrll gad->max = cur + got; 4771 1.1 skrll gad->min = fdcur - fd; 4772 1.1 skrll gad->fdplt = 0; 4773 1.1 skrll 4774 1.1 skrll /* If function descriptors took too much space, wrap some of them 4775 1.1 skrll around. */ 4776 1.1 skrll if (gad->min < wrapmin) 4777 1.1 skrll { 4778 1.1 skrll gad->max += wrapmin - gad->min; 4779 1.1 skrll gad->tmin = gad->min = wrapmin; 4780 1.1 skrll } 4781 1.1 skrll 4782 1.1 skrll /* If GOT entries took too much space, wrap some of them around. 4783 1.1 skrll This may well cause gad->min to become lower than wrapmin. This 4784 1.1 skrll will cause a relocation overflow later on, so we don't have to 4785 1.1 skrll report it here . */ 4786 1.1 skrll if ((bfd_vma) gad->max > wrap) 4787 1.1 skrll { 4788 1.1 skrll gad->min -= gad->max - wrap; 4789 1.1 skrll gad->max = wrap; 4790 1.1 skrll } 4791 1.1 skrll 4792 1.1 skrll /* Add TLS descriptors. */ 4793 1.1 skrll gad->tmax = gad->max + tlsd; 4794 1.1 skrll gad->tmin = gad->min; 4795 1.1 skrll gad->tlsdplt = 0; 4796 1.1 skrll 4797 1.1 skrll /* If TLS descriptors took too much space, wrap an integral number 4798 1.1 skrll of them around. */ 4799 1.1 skrll if ((bfd_vma) gad->tmax > wrap) 4800 1.1 skrll { 4801 1.1 skrll bfd_vma wrapsize = gad->tmax - wrap; 4802 1.1 skrll 4803 1.1 skrll wrapsize += tdescsz / 2; 4804 1.1 skrll wrapsize &= ~ tdescsz / 2; 4805 1.1 skrll 4806 1.1 skrll gad->tmin -= wrapsize; 4807 1.1 skrll gad->tmax -= wrapsize; 4808 1.1 skrll } 4809 1.1 skrll 4810 1.1 skrll /* If there is space left and we have function descriptors 4811 1.1 skrll referenced in PLT entries that could take advantage of shorter 4812 1.1 skrll offsets, place them now. */ 4813 1.1 skrll if (fdplt && gad->tmin > wrapmin) 4814 1.1 skrll { 4815 1.1 skrll bfd_vma fds; 4816 1.1 skrll 4817 1.1 skrll if ((bfd_vma) (gad->tmin - wrapmin) < fdplt) 4818 1.1 skrll fds = gad->tmin - wrapmin; 4819 1.1 skrll else 4820 1.1 skrll fds = fdplt; 4821 1.1 skrll 4822 1.1 skrll fdplt -= fds; 4823 1.1 skrll gad->min -= fds; 4824 1.1 skrll gad->tmin -= fds; 4825 1.1 skrll gad->fdplt += fds; 4826 1.1 skrll } 4827 1.1 skrll 4828 1.1 skrll /* If there is more space left, try to place some more function 4829 1.1 skrll descriptors for PLT entries. */ 4830 1.1 skrll if (fdplt && (bfd_vma) gad->tmax < wrap) 4831 1.1 skrll { 4832 1.1 skrll bfd_vma fds; 4833 1.1 skrll 4834 1.1 skrll if ((bfd_vma) (wrap - gad->tmax) < fdplt) 4835 1.1 skrll fds = wrap - gad->tmax; 4836 1.1 skrll else 4837 1.1 skrll fds = fdplt; 4838 1.1 skrll 4839 1.1 skrll fdplt -= fds; 4840 1.1 skrll gad->max += fds; 4841 1.1 skrll gad->tmax += fds; 4842 1.1 skrll gad->fdplt += fds; 4843 1.1 skrll } 4844 1.1 skrll 4845 1.1 skrll /* If there is space left and we have TLS descriptors referenced in 4846 1.1 skrll PLT entries that could take advantage of shorter offsets, place 4847 1.1 skrll them now. */ 4848 1.1 skrll if (tlsdplt && gad->tmin > wrapmin) 4849 1.1 skrll { 4850 1.1 skrll bfd_vma tlsds; 4851 1.1 skrll 4852 1.1 skrll if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt) 4853 1.1 skrll tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2); 4854 1.1 skrll else 4855 1.1 skrll tlsds = tlsdplt; 4856 1.1 skrll 4857 1.1 skrll tlsdplt -= tlsds; 4858 1.1 skrll gad->tmin -= tlsds; 4859 1.1 skrll gad->tlsdplt += tlsds; 4860 1.1 skrll } 4861 1.1 skrll 4862 1.1 skrll /* If there is more space left, try to place some more TLS 4863 1.1 skrll descriptors for PLT entries. Although we could try to fit an 4864 1.1 skrll additional TLS descriptor with half of it just before before the 4865 1.1 skrll wrap point and another right past the wrap point, this might 4866 1.1 skrll cause us to run out of space for the next region, so don't do 4867 1.1 skrll it. */ 4868 1.1 skrll if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2) 4869 1.1 skrll { 4870 1.1 skrll bfd_vma tlsds; 4871 1.1 skrll 4872 1.1 skrll if ((bfd_vma) (wrap - gad->tmax) < tlsdplt) 4873 1.1 skrll tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2); 4874 1.1 skrll else 4875 1.1 skrll tlsds = tlsdplt; 4876 1.1 skrll 4877 1.1 skrll tlsdplt -= tlsds; 4878 1.1 skrll gad->tmax += tlsds; 4879 1.1 skrll gad->tlsdplt += tlsds; 4880 1.1 skrll } 4881 1.1 skrll 4882 1.1 skrll /* If odd was initially computed as an offset past the wrap point, 4883 1.1 skrll wrap it around. */ 4884 1.1 skrll if (odd > gad->max) 4885 1.1 skrll odd = gad->min + odd - gad->max; 4886 1.1 skrll 4887 1.1 skrll /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed 4888 1.1 skrll before returning, so do it here too. This guarantees that, 4889 1.1 skrll should cur and fdcur meet at the wrap point, they'll both be 4890 1.1 skrll equal to min. */ 4891 1.1 skrll if (gad->cur == gad->max) 4892 1.1 skrll gad->cur = gad->min; 4893 1.1 skrll 4894 1.1 skrll /* Ditto for _frvfdpic_get_tlsdesc_entry(). */ 4895 1.1 skrll gad->tcur = gad->max; 4896 1.1 skrll if (gad->tcur == gad->tmax) 4897 1.1 skrll gad->tcur = gad->tmin; 4898 1.1 skrll 4899 1.1 skrll return odd; 4900 1.1 skrll } 4901 1.1 skrll 4902 1.1 skrll /* Compute the location of the next GOT entry, given the allocation 4903 1.1 skrll data for a range. */ 4904 1.1 skrll 4905 1.1 skrll inline static bfd_signed_vma 4906 1.1 skrll _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) 4907 1.1 skrll { 4908 1.1 skrll bfd_signed_vma ret; 4909 1.1 skrll 4910 1.1 skrll if (gad->odd) 4911 1.1 skrll { 4912 1.1 skrll /* If there was an odd word left behind, use it. */ 4913 1.1 skrll ret = gad->odd; 4914 1.1 skrll gad->odd = 0; 4915 1.1 skrll } 4916 1.1 skrll else 4917 1.1 skrll { 4918 1.1 skrll /* Otherwise, use the word pointed to by cur, reserve the next 4919 1.1 skrll as an odd word, and skip to the next pair of words, possibly 4920 1.1 skrll wrapping around. */ 4921 1.1 skrll ret = gad->cur; 4922 1.1 skrll gad->odd = gad->cur + 4; 4923 1.1 skrll gad->cur += 8; 4924 1.1 skrll if (gad->cur == gad->max) 4925 1.1 skrll gad->cur = gad->min; 4926 1.1 skrll } 4927 1.1 skrll 4928 1.1 skrll return ret; 4929 1.1 skrll } 4930 1.1 skrll 4931 1.1 skrll /* Compute the location of the next function descriptor entry in the 4932 1.1 skrll GOT, given the allocation data for a range. */ 4933 1.1 skrll 4934 1.1 skrll inline static bfd_signed_vma 4935 1.1 skrll _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) 4936 1.1 skrll { 4937 1.1 skrll /* If we're at the bottom, wrap around, and only then allocate the 4938 1.1 skrll next pair of words. */ 4939 1.1 skrll if (gad->fdcur == gad->min) 4940 1.1 skrll gad->fdcur = gad->max; 4941 1.1 skrll return gad->fdcur -= 8; 4942 1.1 skrll } 4943 1.1 skrll 4944 1.1 skrll /* Compute the location of the next TLS descriptor entry in the GOT, 4945 1.1 skrll given the allocation data for a range. */ 4946 1.1 skrll inline static bfd_signed_vma 4947 1.1 skrll _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) 4948 1.1 skrll { 4949 1.1 skrll bfd_signed_vma ret; 4950 1.1 skrll 4951 1.1 skrll ret = gad->tcur; 4952 1.1 skrll 4953 1.1 skrll gad->tcur += 8; 4954 1.1 skrll 4955 1.1 skrll /* If we're at the top of the region, wrap around to the bottom. */ 4956 1.1 skrll if (gad->tcur == gad->tmax) 4957 1.1 skrll gad->tcur = gad->tmin; 4958 1.1 skrll 4959 1.1 skrll return ret; 4960 1.1 skrll } 4961 1.1 skrll 4962 1.1 skrll /* Assign GOT offsets for every GOT entry and function descriptor. 4963 1.1 skrll Doing everything in a single pass is tricky. */ 4964 1.1 skrll 4965 1.1 skrll static int 4966 1.1 skrll _frvfdpic_assign_got_entries (void **entryp, void *info_) 4967 1.1 skrll { 4968 1.1 skrll struct frvfdpic_relocs_info *entry = *entryp; 4969 1.1 skrll struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; 4970 1.1 skrll 4971 1.1 skrll if (entry->got12) 4972 1.1 skrll entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12); 4973 1.1 skrll else if (entry->gotlos) 4974 1.1 skrll entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); 4975 1.1 skrll else if (entry->gothilo) 4976 1.1 skrll entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); 4977 1.1 skrll 4978 1.1 skrll if (entry->fdgot12) 4979 1.1 skrll entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12); 4980 1.1 skrll else if (entry->fdgotlos) 4981 1.1 skrll entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); 4982 1.1 skrll else if (entry->fdgothilo) 4983 1.1 skrll entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); 4984 1.1 skrll 4985 1.1 skrll if (entry->fdgoff12) 4986 1.1 skrll entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); 4987 1.1 skrll else if (entry->plt && dinfo->got12.fdplt) 4988 1.1 skrll { 4989 1.1 skrll dinfo->got12.fdplt -= 8; 4990 1.1 skrll entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); 4991 1.1 skrll } 4992 1.1 skrll else if (entry->fdgofflos) 4993 1.1 skrll entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); 4994 1.1 skrll else if (entry->plt && dinfo->gotlos.fdplt) 4995 1.1 skrll { 4996 1.1 skrll dinfo->gotlos.fdplt -= 8; 4997 1.1 skrll entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); 4998 1.1 skrll } 4999 1.1 skrll else if (entry->plt) 5000 1.1 skrll { 5001 1.1 skrll dinfo->gothilo.fdplt -= 8; 5002 1.1 skrll entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); 5003 1.1 skrll } 5004 1.1 skrll else if (entry->privfd) 5005 1.1 skrll entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); 5006 1.1 skrll 5007 1.1 skrll if (entry->tlsoff12) 5008 1.1 skrll entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12); 5009 1.1 skrll else if (entry->tlsofflos) 5010 1.1 skrll entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); 5011 1.1 skrll else if (entry->tlsoffhilo) 5012 1.1 skrll entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); 5013 1.1 skrll 5014 1.1 skrll if (entry->tlsdesc12) 5015 1.1 skrll entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); 5016 1.1 skrll else if (entry->tlsplt && dinfo->got12.tlsdplt) 5017 1.1 skrll { 5018 1.1 skrll dinfo->got12.tlsdplt -= 8; 5019 1.1 skrll entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); 5020 1.1 skrll } 5021 1.1 skrll else if (entry->tlsdesclos) 5022 1.1 skrll entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); 5023 1.1 skrll else if (entry->tlsplt && dinfo->gotlos.tlsdplt) 5024 1.1 skrll { 5025 1.1 skrll dinfo->gotlos.tlsdplt -= 8; 5026 1.1 skrll entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); 5027 1.1 skrll } 5028 1.1 skrll else if (entry->tlsplt) 5029 1.1 skrll { 5030 1.1 skrll dinfo->gothilo.tlsdplt -= 8; 5031 1.1 skrll entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); 5032 1.1 skrll } 5033 1.1 skrll else if (entry->tlsdeschilo) 5034 1.1 skrll entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); 5035 1.1 skrll 5036 1.1 skrll return 1; 5037 1.1 skrll } 5038 1.1 skrll 5039 1.1 skrll /* Assign GOT offsets to private function descriptors used by PLT 5040 1.1 skrll entries (or referenced by 32-bit offsets), as well as PLT entries 5041 1.1 skrll and lazy PLT entries. */ 5042 1.1 skrll 5043 1.1 skrll static int 5044 1.1 skrll _frvfdpic_assign_plt_entries (void **entryp, void *info_) 5045 1.1 skrll { 5046 1.1 skrll struct frvfdpic_relocs_info *entry = *entryp; 5047 1.1 skrll struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; 5048 1.1 skrll 5049 1.1 skrll if (entry->privfd) 5050 1.1 skrll BFD_ASSERT (entry->fd_entry); 5051 1.1 skrll 5052 1.1 skrll if (entry->plt) 5053 1.1 skrll { 5054 1.1 skrll int size; 5055 1.1 skrll 5056 1.1 skrll /* We use the section's raw size to mark the location of the 5057 1.1 skrll next PLT entry. */ 5058 1.1 skrll entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size; 5059 1.1 skrll 5060 1.1 skrll /* Figure out the length of this PLT entry based on the 5061 1.1 skrll addressing mode we need to reach the function descriptor. */ 5062 1.1 skrll BFD_ASSERT (entry->fd_entry); 5063 1.1 skrll if (entry->fd_entry >= -(1 << (12 - 1)) 5064 1.1 skrll && entry->fd_entry < (1 << (12 - 1))) 5065 1.1 skrll size = 8; 5066 1.1 skrll else if (entry->fd_entry >= -(1 << (16 - 1)) 5067 1.1 skrll && entry->fd_entry < (1 << (16 - 1))) 5068 1.1 skrll size = 12; 5069 1.1 skrll else 5070 1.1 skrll size = 16; 5071 1.1 skrll 5072 1.1 skrll frvfdpic_plt_section (dinfo->g.info)->size += size; 5073 1.1 skrll } 5074 1.1 skrll 5075 1.1 skrll if (entry->lazyplt) 5076 1.1 skrll { 5077 1.1 skrll entry->lzplt_entry = dinfo->g.lzplt; 5078 1.1 skrll dinfo->g.lzplt += 8; 5079 1.1 skrll /* If this entry is the one that gets the resolver stub, account 5080 1.1 skrll for the additional instruction. */ 5081 1.1 skrll if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE 5082 1.1 skrll == FRVFDPIC_LZPLT_RESOLV_LOC) 5083 1.1 skrll dinfo->g.lzplt += 4; 5084 1.1 skrll } 5085 1.1 skrll 5086 1.1 skrll if (entry->tlsplt) 5087 1.1 skrll { 5088 1.1.1.4 christos int size; 5089 1.1 skrll 5090 1.1 skrll entry->tlsplt_entry 5091 1.1 skrll = frvfdpic_plt_section (dinfo->g.info)->size; 5092 1.1 skrll 5093 1.1 skrll if (bfd_link_executable (dinfo->g.info) 5094 1.1 skrll && (entry->symndx != -1 5095 1.1 skrll || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h))) 5096 1.1 skrll { 5097 1.1 skrll if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1)) 5098 1.1 skrll /* FIXME: here we use the size of the TLS section 5099 1.1 skrll as an upper bound for the value of the TLS 5100 1.1 skrll symbol, because we may not know the exact value 5101 1.1 skrll yet. If we get it wrong, we'll just waste a 5102 1.1 skrll word in the PLT, and we should never get even 5103 1.1 skrll close to 32 KiB of TLS anyway. */ 5104 1.1 skrll && elf_hash_table (dinfo->g.info)->tls_sec 5105 1.1 skrll && (elf_hash_table (dinfo->g.info)->tls_sec->size 5106 1.1 skrll + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1)))) 5107 1.1 skrll size = 8; 5108 1.1 skrll else 5109 1.1 skrll size = 12; 5110 1.1 skrll } 5111 1.1 skrll else if (entry->tlsoff_entry) 5112 1.1 skrll { 5113 1.1 skrll if (entry->tlsoff_entry >= -(1 << (12 - 1)) 5114 1.1 skrll && entry->tlsoff_entry < (1 << (12 - 1))) 5115 1.1 skrll size = 8; 5116 1.1 skrll else if (entry->tlsoff_entry >= -(1 << (16 - 1)) 5117 1.1 skrll && entry->tlsoff_entry < (1 << (16 - 1))) 5118 1.1 skrll size = 12; 5119 1.1 skrll else 5120 1.1 skrll size = 16; 5121 1.1 skrll } 5122 1.1 skrll else 5123 1.1 skrll { 5124 1.1 skrll BFD_ASSERT (entry->tlsdesc_entry); 5125 1.1 skrll 5126 1.1 skrll if (entry->tlsdesc_entry >= -(1 << (12 - 1)) 5127 1.1 skrll && entry->tlsdesc_entry < (1 << (12 - 1))) 5128 1.1 skrll size = 8; 5129 1.1 skrll else if (entry->tlsdesc_entry >= -(1 << (16 - 1)) 5130 1.1 skrll && entry->tlsdesc_entry < (1 << (16 - 1))) 5131 1.1 skrll size = 12; 5132 1.1 skrll else 5133 1.1 skrll size = 16; 5134 1.1 skrll } 5135 1.1 skrll 5136 1.1 skrll frvfdpic_plt_section (dinfo->g.info)->size += size; 5137 1.1 skrll } 5138 1.1 skrll 5139 1.1 skrll return 1; 5140 1.1 skrll } 5141 1.1 skrll 5142 1.1 skrll /* Cancel out any effects of calling _frvfdpic_assign_got_entries and 5143 1.1 skrll _frvfdpic_assign_plt_entries. */ 5144 1.1 skrll 5145 1.1 skrll static int 5146 1.1 skrll _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED) 5147 1.1 skrll { 5148 1.1 skrll struct frvfdpic_relocs_info *entry = *entryp; 5149 1.1 skrll 5150 1.1 skrll entry->got_entry = 0; 5151 1.1 skrll entry->fdgot_entry = 0; 5152 1.1 skrll entry->fd_entry = 0; 5153 1.1 skrll entry->plt_entry = (bfd_vma)-1; 5154 1.1 skrll entry->lzplt_entry = (bfd_vma)-1; 5155 1.1 skrll entry->tlsoff_entry = 0; 5156 1.1 skrll entry->tlsdesc_entry = 0; 5157 1.1 skrll entry->tlsplt_entry = (bfd_vma)-1; 5158 1.1 skrll 5159 1.1 skrll return 1; 5160 1.1 skrll } 5161 1.1 skrll 5162 1.1 skrll /* Follow indirect and warning hash entries so that each got entry 5163 1.1 skrll points to the final symbol definition. P must point to a pointer 5164 1.1 skrll to the hash table we're traversing. Since this traversal may 5165 1.1 skrll modify the hash table, we set this pointer to NULL to indicate 5166 1.1 skrll we've made a potentially-destructive change to the hash table, so 5167 1.1 skrll the traversal must be restarted. */ 5168 1.1 skrll static int 5169 1.1 skrll _frvfdpic_resolve_final_relocs_info (void **entryp, void *p) 5170 1.1 skrll { 5171 1.1 skrll struct frvfdpic_relocs_info *entry = *entryp; 5172 1.1 skrll htab_t *htab = p; 5173 1.1 skrll 5174 1.1 skrll if (entry->symndx == -1) 5175 1.1 skrll { 5176 1.1 skrll struct elf_link_hash_entry *h = entry->d.h; 5177 1.1 skrll struct frvfdpic_relocs_info *oentry; 5178 1.1 skrll 5179 1.1 skrll while (h->root.type == bfd_link_hash_indirect 5180 1.1 skrll || h->root.type == bfd_link_hash_warning) 5181 1.1 skrll h = (struct elf_link_hash_entry *)h->root.u.i.link; 5182 1.1 skrll 5183 1.1 skrll if (entry->d.h == h) 5184 1.1 skrll return 1; 5185 1.1 skrll 5186 1.1 skrll oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend, 5187 1.1 skrll NO_INSERT); 5188 1.1 skrll 5189 1.1 skrll if (oentry) 5190 1.1 skrll { 5191 1.1 skrll /* Merge the two entries. */ 5192 1.1 skrll frvfdpic_pic_merge_early_relocs_info (oentry, entry); 5193 1.1 skrll htab_clear_slot (*htab, entryp); 5194 1.1 skrll return 1; 5195 1.1 skrll } 5196 1.1 skrll 5197 1.1 skrll entry->d.h = h; 5198 1.1 skrll 5199 1.1 skrll /* If we can't find this entry with the new bfd hash, re-insert 5200 1.1 skrll it, and get the traversal restarted. */ 5201 1.1 skrll if (! htab_find (*htab, entry)) 5202 1.1 skrll { 5203 1.1 skrll htab_clear_slot (*htab, entryp); 5204 1.1 skrll entryp = htab_find_slot (*htab, entry, INSERT); 5205 1.1 skrll if (! *entryp) 5206 1.1 skrll *entryp = entry; 5207 1.1 skrll /* Abort the traversal, since the whole table may have 5208 1.1 skrll moved, and leave it up to the parent to restart the 5209 1.1 skrll process. */ 5210 1.1 skrll *(htab_t *)p = NULL; 5211 1.1 skrll return 0; 5212 1.1 skrll } 5213 1.1 skrll } 5214 1.1 skrll 5215 1.1 skrll return 1; 5216 1.1 skrll } 5217 1.1.1.9 christos 5218 1.1 skrll /* Compute the total size of the GOT, the PLT, the dynamic relocations 5219 1.1 skrll section and the rofixup section. Assign locations for GOT and PLT 5220 1.1 skrll entries. */ 5221 1.1 skrll 5222 1.1 skrll static bool 5223 1.1 skrll _frvfdpic_size_got_plt (bfd *output_bfd, 5224 1.1 skrll struct _frvfdpic_dynamic_got_plt_info *gpinfop) 5225 1.1 skrll { 5226 1.1 skrll bfd_signed_vma odd; 5227 1.1 skrll bfd_vma limit, tlslimit; 5228 1.1 skrll struct bfd_link_info *info = gpinfop->g.info; 5229 1.1 skrll bfd *dynobj = elf_hash_table (info)->dynobj; 5230 1.1 skrll 5231 1.1 skrll memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g, 5232 1.1 skrll sizeof (gpinfop->g)); 5233 1.1 skrll 5234 1.1 skrll odd = 12; 5235 1.1 skrll /* Compute the total size taken by entries in the 12-bit and 16-bit 5236 1.1 skrll ranges, to tell how many PLT function descriptors we can bring 5237 1.1 skrll into the 12-bit range without causing the 16-bit range to 5238 1.1 skrll overflow. */ 5239 1.1 skrll limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos 5240 1.1 skrll + gpinfop->g.fd12 + gpinfop->g.fdlos 5241 1.1 skrll + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos; 5242 1.1 skrll if (limit < (bfd_vma)1 << 16) 5243 1.1 skrll limit = ((bfd_vma)1 << 16) - limit; 5244 1.1 skrll else 5245 1.1 skrll limit = 0; 5246 1.1 skrll if (gpinfop->g.fdplt < limit) 5247 1.1 skrll { 5248 1.1 skrll tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8; 5249 1.1 skrll limit = gpinfop->g.fdplt; 5250 1.1 skrll } 5251 1.1 skrll else 5252 1.1 skrll tlslimit = 0; 5253 1.1 skrll if (gpinfop->g.tlsdplt < tlslimit) 5254 1.1 skrll tlslimit = gpinfop->g.tlsdplt; 5255 1.1 skrll 5256 1.1 skrll /* Determine the ranges of GOT offsets that we can use for each 5257 1.1 skrll range of addressing modes. */ 5258 1.1 skrll odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12, 5259 1.1 skrll 0, 5260 1.1 skrll odd, 5261 1.1 skrll 16, 5262 1.1 skrll gpinfop->g.got12, 5263 1.1 skrll gpinfop->g.fd12, 5264 1.1 skrll limit, 5265 1.1 skrll gpinfop->g.tlsd12, 5266 1.1 skrll tlslimit, 5267 1.1 skrll (bfd_vma)1 << (12-1)); 5268 1.1 skrll odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos, 5269 1.1 skrll gpinfop->got12.tmin, 5270 1.1 skrll odd, 5271 1.1 skrll gpinfop->got12.tmax, 5272 1.1 skrll gpinfop->g.gotlos, 5273 1.1 skrll gpinfop->g.fdlos, 5274 1.1 skrll gpinfop->g.fdplt 5275 1.1 skrll - gpinfop->got12.fdplt, 5276 1.1 skrll gpinfop->g.tlsdlos, 5277 1.1 skrll gpinfop->g.tlsdplt 5278 1.1 skrll - gpinfop->got12.tlsdplt, 5279 1.1 skrll (bfd_vma)1 << (16-1)); 5280 1.1 skrll odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo, 5281 1.1 skrll gpinfop->gotlos.tmin, 5282 1.1 skrll odd, 5283 1.1 skrll gpinfop->gotlos.tmax, 5284 1.1 skrll gpinfop->g.gothilo, 5285 1.1 skrll gpinfop->g.fdhilo, 5286 1.1 skrll gpinfop->g.fdplt 5287 1.1 skrll - gpinfop->got12.fdplt 5288 1.1 skrll - gpinfop->gotlos.fdplt, 5289 1.1 skrll gpinfop->g.tlsdhilo, 5290 1.1 skrll gpinfop->g.tlsdplt 5291 1.1 skrll - gpinfop->got12.tlsdplt 5292 1.1 skrll - gpinfop->gotlos.tlsdplt, 5293 1.1 skrll (bfd_vma)1 << (32-1)); 5294 1.1 skrll 5295 1.1 skrll /* Now assign (most) GOT offsets. */ 5296 1.1 skrll htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries, 5297 1.1 skrll gpinfop); 5298 1.1 skrll 5299 1.1 skrll frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax 5300 1.1 skrll - gpinfop->gothilo.tmin 5301 1.1 skrll /* If an odd word is the last word of the GOT, we don't need this 5302 1.1 skrll word to be part of the GOT. */ 5303 1.1 skrll - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0); 5304 1.1 skrll if (frvfdpic_got_section (info)->size == 0) 5305 1.1 skrll frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; 5306 1.1 skrll else if (frvfdpic_got_section (info)->size == 12 5307 1.1 skrll && ! elf_hash_table (info)->dynamic_sections_created) 5308 1.1 skrll { 5309 1.1 skrll frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; 5310 1.1 skrll frvfdpic_got_section (info)->size = 0; 5311 1.1 skrll } 5312 1.1 skrll /* This will be non-NULL during relaxation. The assumption is that 5313 1.1 skrll the size of one of these sections will never grow, only shrink, 5314 1.1 skrll so we can use the larger buffer we allocated before. */ 5315 1.1 skrll else if (frvfdpic_got_section (info)->contents == NULL) 5316 1.1.1.9 christos { 5317 1.1.1.11 christos frvfdpic_got_section (info)->contents = 5318 1.1 skrll (bfd_byte *) bfd_zalloc (dynobj, 5319 1.1 skrll frvfdpic_got_section (info)->size); 5320 1.1 skrll if (frvfdpic_got_section (info)->contents == NULL) 5321 1.1 skrll return false; 5322 1.1 skrll frvfdpic_got_section (info)->alloced = 1; 5323 1.1 skrll } 5324 1.1 skrll 5325 1.1 skrll if (frvfdpic_gotrel_section (info)) 5326 1.1 skrll /* Subtract the number of lzplt entries, since those will generate 5327 1.1 skrll relocations in the pltrel section. */ 5328 1.1 skrll frvfdpic_gotrel_section (info)->size = 5329 1.1 skrll (gpinfop->g.relocs - gpinfop->g.lzplt / 8) 5330 1.1 skrll * get_elf_backend_data (output_bfd)->s->sizeof_rel; 5331 1.1 skrll else 5332 1.1 skrll BFD_ASSERT (gpinfop->g.relocs == 0); 5333 1.1 skrll if (frvfdpic_gotrel_section (info)->size == 0) 5334 1.1 skrll frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE; 5335 1.1 skrll else if (frvfdpic_gotrel_section (info)->contents == NULL) 5336 1.1.1.9 christos { 5337 1.1.1.11 christos frvfdpic_gotrel_section (info)->contents = 5338 1.1 skrll (bfd_byte *) bfd_zalloc (dynobj, 5339 1.1 skrll frvfdpic_gotrel_section (info)->size); 5340 1.1 skrll if (frvfdpic_gotrel_section (info)->contents == NULL) 5341 1.1 skrll return false; 5342 1.1 skrll frvfdpic_gotrel_section (info)->alloced = 1; 5343 1.1 skrll } 5344 1.1 skrll 5345 1.1 skrll frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4; 5346 1.1 skrll if (frvfdpic_gotfixup_section (info)->size == 0) 5347 1.1 skrll frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE; 5348 1.1 skrll else if (frvfdpic_gotfixup_section (info)->contents == NULL) 5349 1.1.1.9 christos { 5350 1.1.1.11 christos frvfdpic_gotfixup_section (info)->contents = 5351 1.1 skrll (bfd_byte *) bfd_zalloc (dynobj, 5352 1.1 skrll frvfdpic_gotfixup_section (info)->size); 5353 1.1 skrll if (frvfdpic_gotfixup_section (info)->contents == NULL) 5354 1.1 skrll return false; 5355 1.1 skrll frvfdpic_gotfixup_section (info)->alloced = 1; 5356 1.1 skrll } 5357 1.1 skrll 5358 1.1 skrll if (frvfdpic_pltrel_section (info)) 5359 1.1 skrll { 5360 1.1 skrll frvfdpic_pltrel_section (info)->size = 5361 1.1 skrll gpinfop->g.lzplt / 8 5362 1.1 skrll * get_elf_backend_data (output_bfd)->s->sizeof_rel; 5363 1.1 skrll if (frvfdpic_pltrel_section (info)->size == 0) 5364 1.1 skrll frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE; 5365 1.1 skrll else if (frvfdpic_pltrel_section (info)->contents == NULL) 5366 1.1.1.9 christos { 5367 1.1.1.11 christos frvfdpic_pltrel_section (info)->contents = 5368 1.1 skrll (bfd_byte *) bfd_zalloc (dynobj, 5369 1.1 skrll frvfdpic_pltrel_section (info)->size); 5370 1.1 skrll if (frvfdpic_pltrel_section (info)->contents == NULL) 5371 1.1 skrll return false; 5372 1.1 skrll frvfdpic_pltrel_section (info)->alloced = 1; 5373 1.1 skrll } 5374 1.1 skrll } 5375 1.1 skrll 5376 1.1 skrll /* Add 4 bytes for every block of at most 65535 lazy PLT entries, 5377 1.1 skrll such that there's room for the additional instruction needed to 5378 1.1 skrll call the resolver. Since _frvfdpic_assign_got_entries didn't 5379 1.1 skrll account for them, our block size is 4 bytes smaller than the real 5380 1.1 skrll block size. */ 5381 1.1 skrll if (frvfdpic_plt_section (info)) 5382 1.1 skrll { 5383 1.1 skrll frvfdpic_plt_section (info)->size = gpinfop->g.lzplt 5384 1.1 skrll + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8) 5385 1.1 skrll / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4); 5386 1.1 skrll } 5387 1.1 skrll 5388 1.1 skrll /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to 5389 1.1 skrll actually assign lazy PLT entries addresses. */ 5390 1.1 skrll gpinfop->g.lzplt = 0; 5391 1.1 skrll 5392 1.1 skrll /* Save information that we're going to need to generate GOT and PLT 5393 1.1 skrll entries. */ 5394 1.1 skrll frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin; 5395 1.1 skrll 5396 1.1 skrll if (get_elf_backend_data (output_bfd)->want_got_sym) 5397 1.1 skrll elf_hash_table (info)->hgot->root.u.def.value 5398 1.1 skrll = frvfdpic_got_initial_offset (info); 5399 1.1 skrll 5400 1.1 skrll if (frvfdpic_plt_section (info)) 5401 1.1 skrll frvfdpic_plt_initial_offset (info) = 5402 1.1 skrll frvfdpic_plt_section (info)->size; 5403 1.1 skrll 5404 1.1 skrll /* Allocate a ret statement at plt_initial_offset, to be used by 5405 1.1 skrll locally-resolved TLS descriptors. */ 5406 1.1 skrll if (gpinfop->g.tls_ret_refs) 5407 1.1 skrll frvfdpic_plt_section (info)->size += 4; 5408 1.1 skrll 5409 1.1 skrll htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries, 5410 1.1 skrll gpinfop); 5411 1.1 skrll 5412 1.1 skrll /* Allocate the PLT section contents only after 5413 1.1 skrll _frvfdpic_assign_plt_entries has a chance to add the size of the 5414 1.1 skrll non-lazy PLT entries. */ 5415 1.1 skrll if (frvfdpic_plt_section (info)) 5416 1.1 skrll { 5417 1.1 skrll if (frvfdpic_plt_section (info)->size == 0) 5418 1.1 skrll frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE; 5419 1.1 skrll else if (frvfdpic_plt_section (info)->contents == NULL) 5420 1.1.1.9 christos { 5421 1.1.1.11 christos frvfdpic_plt_section (info)->contents = 5422 1.1 skrll (bfd_byte *) bfd_zalloc (dynobj, 5423 1.1 skrll frvfdpic_plt_section (info)->size); 5424 1.1 skrll if (frvfdpic_plt_section (info)->contents == NULL) 5425 1.1.1.9 christos return false; 5426 1.1 skrll frvfdpic_plt_section (info)->alloced = 1; 5427 1.1 skrll } 5428 1.1 skrll } 5429 1.1 skrll 5430 1.1.1.9 christos return true; 5431 1.1.1.11 christos } 5432 1.1.1.11 christos 5433 1.1 skrll /* Set the sizes of the dynamic sections. */ 5434 1.1 skrll 5435 1.1 skrll static bool 5436 1.1 skrll elf32_frvfdpic_late_size_sections (bfd *output_bfd, 5437 1.1 skrll struct bfd_link_info *info) 5438 1.1 skrll { 5439 1.1.1.11 christos bfd *dynobj; 5440 1.1.1.11 christos asection *s; 5441 1.1 skrll struct _frvfdpic_dynamic_got_plt_info gpinfo; 5442 1.1 skrll 5443 1.1 skrll dynobj = elf_hash_table (info)->dynobj; 5444 1.1 skrll if (dynobj == NULL) 5445 1.1.1.4 christos return true; 5446 1.1 skrll 5447 1.1.1.12 christos if (elf_hash_table (info)->dynamic_sections_created) 5448 1.1 skrll { 5449 1.1 skrll /* Set the contents of the .interp section to the interpreter. */ 5450 1.1 skrll if (bfd_link_executable (info) && !info->nointerp) 5451 1.1.1.11 christos { 5452 1.1 skrll s = elf_hash_table (info)->interp; 5453 1.1 skrll BFD_ASSERT (s != NULL); 5454 1.1 skrll s->size = sizeof ELF_DYNAMIC_INTERPRETER; 5455 1.1 skrll s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; 5456 1.1 skrll s->alloced = 1; 5457 1.1 skrll } 5458 1.1 skrll } 5459 1.1 skrll 5460 1.1 skrll memset (&gpinfo, 0, sizeof (gpinfo)); 5461 1.1 skrll gpinfo.g.info = info; 5462 1.1 skrll 5463 1.1 skrll for (;;) 5464 1.1 skrll { 5465 1.1 skrll htab_t relocs = frvfdpic_relocs_info (info); 5466 1.1 skrll 5467 1.1 skrll htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs); 5468 1.1 skrll 5469 1.1 skrll if (relocs == frvfdpic_relocs_info (info)) 5470 1.1 skrll break; 5471 1.1 skrll } 5472 1.1 skrll 5473 1.1 skrll htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries, 5474 1.1 skrll &gpinfo.g); 5475 1.1 skrll 5476 1.1.1.9 christos /* Allocate space to save the summary information, we're going to 5477 1.1 skrll use it if we're doing relaxations. */ 5478 1.1.1.9 christos frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g)); 5479 1.1 skrll 5480 1.1 skrll if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo)) 5481 1.1.1.9 christos return false; 5482 1.1.1.11 christos 5483 1.1.1.11 christos return _bfd_elf_add_dynamic_tags (output_bfd, info, true); 5484 1.1 skrll } 5485 1.1.1.4 christos 5486 1.1.1.4 christos static bool 5487 1.1.1.4 christos elf32_frvfdpic_early_size_sections (bfd *output_bfd, 5488 1.1.1.9 christos struct bfd_link_info *info) 5489 1.1 skrll { 5490 1.1.1.9 christos if (!bfd_link_relocatable (info) 5491 1.1 skrll && !bfd_elf_stack_segment_size (output_bfd, info, 5492 1.1 skrll "__stacksize", DEFAULT_STACK_SIZE)) 5493 1.1 skrll return false; 5494 1.1 skrll 5495 1.1.1.9 christos return true; 5496 1.1 skrll } 5497 1.1 skrll 5498 1.1.1.9 christos /* Check whether any of the relocations was optimized away, and 5499 1.1 skrll subtract it from the relocation or fixup count. */ 5500 1.1 skrll static bool 5501 1.1 skrll _frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec, 5502 1.1 skrll struct bfd_link_info *info, 5503 1.1 skrll bool *changed) 5504 1.1 skrll { 5505 1.1 skrll Elf_Internal_Shdr *symtab_hdr; 5506 1.1.1.9 christos struct elf_link_hash_entry **sym_hashes; 5507 1.1 skrll Elf_Internal_Rela *rel, *erel; 5508 1.1 skrll 5509 1.1 skrll if ((sec->flags & SEC_RELOC) == 0 5510 1.1 skrll || sec->reloc_count == 0) 5511 1.1 skrll return true; 5512 1.1 skrll 5513 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 5514 1.1 skrll sym_hashes = elf_sym_hashes (abfd); 5515 1.1 skrll 5516 1.1 skrll rel = elf_section_data (sec)->relocs; 5517 1.1 skrll 5518 1.1 skrll /* Now examine each relocation. */ 5519 1.1 skrll for (erel = rel + sec->reloc_count; rel < erel; rel++) 5520 1.1 skrll { 5521 1.1 skrll struct elf_link_hash_entry *h; 5522 1.1 skrll unsigned long r_symndx; 5523 1.1 skrll struct frvfdpic_relocs_info *picrel; 5524 1.1 skrll struct _frvfdpic_dynamic_got_info *dinfo; 5525 1.1 skrll 5526 1.1 skrll if (ELF32_R_TYPE (rel->r_info) != R_FRV_32 5527 1.1 skrll && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC) 5528 1.1 skrll continue; 5529 1.1 skrll 5530 1.1 skrll if (_bfd_elf_section_offset (sec->output_section->owner, 5531 1.1 skrll info, sec, rel->r_offset) 5532 1.1 skrll != (bfd_vma)-1) 5533 1.1 skrll continue; 5534 1.1 skrll 5535 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info); 5536 1.1 skrll if (r_symndx < symtab_hdr->sh_info) 5537 1.1 skrll h = NULL; 5538 1.1 skrll else 5539 1.1 skrll { 5540 1.1 skrll h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 5541 1.1 skrll while (h->root.type == bfd_link_hash_indirect 5542 1.1 skrll || h->root.type == bfd_link_hash_warning) 5543 1.1 skrll h = (struct elf_link_hash_entry *)h->root.u.i.link; 5544 1.1 skrll } 5545 1.1 skrll 5546 1.1 skrll if (h != NULL) 5547 1.1 skrll picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), 5548 1.1 skrll abfd, h, 5549 1.1 skrll rel->r_addend, NO_INSERT); 5550 1.1 skrll else 5551 1.1.1.9 christos picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info), 5552 1.1 skrll abfd, r_symndx, 5553 1.1.1.9 christos rel->r_addend, NO_INSERT); 5554 1.1 skrll 5555 1.1 skrll if (! picrel) 5556 1.1.1.9 christos return false; 5557 1.1 skrll 5558 1.1 skrll *changed = true; 5559 1.1 skrll dinfo = frvfdpic_dynamic_got_plt_info (info); 5560 1.1 skrll 5561 1.1.1.9 christos _frvfdpic_count_relocs_fixups (picrel, dinfo, true); 5562 1.1 skrll if (ELF32_R_TYPE (rel->r_info) == R_FRV_32) 5563 1.1 skrll picrel->relocs32--; 5564 1.1.1.9 christos else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */ 5565 1.1 skrll picrel->relocsfd--; 5566 1.1 skrll _frvfdpic_count_relocs_fixups (picrel, dinfo, false); 5567 1.1.1.9 christos } 5568 1.1 skrll 5569 1.1 skrll return true; 5570 1.1 skrll } 5571 1.1 skrll 5572 1.1.1.9 christos static bool 5573 1.1 skrll frvfdpic_elf_discard_info (bfd *ibfd, 5574 1.1 skrll struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED, 5575 1.1 skrll struct bfd_link_info *info) 5576 1.1 skrll { 5577 1.1 skrll bool changed = false; 5578 1.1.1.3 christos asection *s; 5579 1.1 skrll bfd *obfd = NULL; 5580 1.1 skrll 5581 1.1.1.9 christos /* Account for relaxation of .eh_frame section. */ 5582 1.1 skrll for (s = ibfd->sections; s; s = s->next) 5583 1.1 skrll if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME) 5584 1.1 skrll { 5585 1.1 skrll if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed)) 5586 1.1 skrll return false; 5587 1.1 skrll obfd = s->output_section->owner; 5588 1.1 skrll } 5589 1.1 skrll 5590 1.1 skrll if (changed) 5591 1.1 skrll { 5592 1.1 skrll struct _frvfdpic_dynamic_got_plt_info gpinfo; 5593 1.1 skrll 5594 1.1 skrll memset (&gpinfo, 0, sizeof (gpinfo)); 5595 1.1 skrll memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), 5596 1.1 skrll sizeof (gpinfo.g)); 5597 1.1 skrll 5598 1.1 skrll /* Clear GOT and PLT assignments. */ 5599 1.1.1.9 christos htab_traverse (frvfdpic_relocs_info (info), 5600 1.1 skrll _frvfdpic_reset_got_plt_entries, 5601 1.1 skrll NULL); 5602 1.1.1.9 christos 5603 1.1 skrll if (!_frvfdpic_size_got_plt (obfd, &gpinfo)) 5604 1.1 skrll return false; 5605 1.1 skrll } 5606 1.1 skrll 5607 1.1 skrll return true; 5608 1.1 skrll } 5609 1.1 skrll 5610 1.1 skrll /* Look for opportunities to relax TLS relocations. We can assume 5611 1.1 skrll we're linking the main executable or a static-tls library, since 5612 1.1 skrll otherwise we wouldn't have got here. */ 5613 1.1 skrll 5614 1.1 skrll static int 5615 1.1.1.9 christos _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_) 5616 1.1 skrll { 5617 1.1 skrll struct frvfdpic_relocs_info *entry = *entryp; 5618 1.1 skrll struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; 5619 1.1 skrll 5620 1.1.1.9 christos _frvfdpic_relax_tls_entries (entry, dinfo, true); 5621 1.1 skrll 5622 1.1.1.9 christos return 1; 5623 1.1 skrll } 5624 1.1 skrll 5625 1.1 skrll static bool 5626 1.1.1.4 christos elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, 5627 1.1.1.11 christos struct bfd_link_info *info, bool *again) 5628 1.1.1.11 christos { 5629 1.1.1.2 christos struct _frvfdpic_dynamic_got_plt_info gpinfo; 5630 1.1 skrll 5631 1.1.1.9 christos if (bfd_link_relocatable (info)) 5632 1.1 skrll info->callbacks->fatal 5633 1.1 skrll (_("%P: --relax and -r may not be used together\n")); 5634 1.1 skrll 5635 1.1.1.9 christos /* If we return early, we didn't change anything. */ 5636 1.1 skrll *again = false; 5637 1.1 skrll 5638 1.1 skrll /* We'll do our thing when requested to relax the GOT section. */ 5639 1.1.1.4 christos if (sec != frvfdpic_got_section (info)) 5640 1.1.1.9 christos return true; 5641 1.1 skrll 5642 1.1 skrll /* We can only relax when linking the main executable or a library 5643 1.1 skrll that can't be dlopened. */ 5644 1.1 skrll if (! bfd_link_executable (info) && ! (info->flags & DF_STATIC_TLS)) 5645 1.1 skrll return true; 5646 1.1.1.9 christos 5647 1.1 skrll /* If there isn't a TLS section for this binary, we can't do 5648 1.1 skrll anything about its TLS relocations (it probably doesn't have 5649 1.1 skrll any. */ 5650 1.1 skrll if (elf_hash_table (info)->tls_sec == NULL) 5651 1.1 skrll return true; 5652 1.1 skrll 5653 1.1 skrll memset (&gpinfo, 0, sizeof (gpinfo)); 5654 1.1 skrll memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g)); 5655 1.1 skrll 5656 1.1 skrll /* Now look for opportunities to relax, adjusting the GOT usage 5657 1.1 skrll as needed. */ 5658 1.1 skrll htab_traverse (frvfdpic_relocs_info (info), 5659 1.1 skrll _frvfdpic_relax_got_plt_entries, 5660 1.1 skrll &gpinfo.g); 5661 1.1 skrll 5662 1.1 skrll /* If we changed anything, reset and re-assign GOT and PLT entries. */ 5663 1.1 skrll if (memcmp (frvfdpic_dynamic_got_plt_info (info), 5664 1.1 skrll &gpinfo.g, sizeof (gpinfo.g)) != 0) 5665 1.1 skrll { 5666 1.1 skrll /* Clear GOT and PLT assignments. */ 5667 1.1 skrll htab_traverse (frvfdpic_relocs_info (info), 5668 1.1 skrll _frvfdpic_reset_got_plt_entries, 5669 1.1 skrll NULL); 5670 1.1.1.9 christos 5671 1.1 skrll /* The owner of the TLS section is the output bfd. There should 5672 1.1 skrll be a better way to get to it. */ 5673 1.1 skrll if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner, 5674 1.1 skrll &gpinfo)) 5675 1.1 skrll return false; 5676 1.1 skrll 5677 1.1 skrll /* Repeat until we don't make any further changes. We could fail to 5678 1.1.1.9 christos introduce changes in a round if, for example, the 12-bit range is 5679 1.1 skrll full, but we later release some space by getting rid of TLS 5680 1.1 skrll descriptors in it. We have to repeat the whole process because 5681 1.1.1.9 christos we might have changed the size of a section processed before this 5682 1.1 skrll one. */ 5683 1.1 skrll *again = true; 5684 1.1 skrll } 5685 1.1 skrll 5686 1.1.1.9 christos return true; 5687 1.1 skrll } 5688 1.1.1.12 christos 5689 1.1.1.12 christos /* Fill in code and data in dynamic sections. */ 5690 1.1 skrll 5691 1.1 skrll static bool 5692 1.1.1.9 christos elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 5693 1.1 skrll struct bfd_link_info *info ATTRIBUTE_UNUSED, 5694 1.1 skrll bfd_byte *buf ATTRIBUTE_UNUSED) 5695 1.1.1.9 christos { 5696 1.1 skrll /* Nothing to be done for non-FDPIC. */ 5697 1.1.1.12 christos return true; 5698 1.1.1.12 christos } 5699 1.1 skrll 5700 1.1 skrll static bool 5701 1.1 skrll elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd, 5702 1.1 skrll struct bfd_link_info *info, 5703 1.1 skrll bfd_byte *buf ATTRIBUTE_UNUSED) 5704 1.1 skrll { 5705 1.1 skrll bfd *dynobj; 5706 1.1 skrll asection *sdyn; 5707 1.1 skrll 5708 1.1 skrll dynobj = elf_hash_table (info)->dynobj; 5709 1.1 skrll 5710 1.1 skrll if (frvfdpic_dynamic_got_plt_info (info)) 5711 1.1 skrll { 5712 1.1 skrll BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0); 5713 1.1 skrll } 5714 1.1 skrll if (frvfdpic_got_section (info)) 5715 1.1 skrll { 5716 1.1 skrll BFD_ASSERT (frvfdpic_gotrel_section (info)->size 5717 1.1 skrll == (frvfdpic_gotrel_section (info)->reloc_count 5718 1.1 skrll * sizeof (Elf32_External_Rel))); 5719 1.1 skrll 5720 1.1 skrll if (frvfdpic_gotfixup_section (info)) 5721 1.1 skrll { 5722 1.1 skrll struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot; 5723 1.1 skrll bfd_vma got_value = hgot->root.u.def.value 5724 1.1 skrll + hgot->root.u.def.section->output_section->vma 5725 1.1 skrll + hgot->root.u.def.section->output_offset; 5726 1.1 skrll struct bfd_link_hash_entry *hend; 5727 1.1 skrll 5728 1.1 skrll _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info), 5729 1.1 skrll got_value, 0); 5730 1.1.1.3 christos 5731 1.1.1.3 christos if (frvfdpic_gotfixup_section (info)->size 5732 1.1.1.9 christos != (frvfdpic_gotfixup_section (info)->reloc_count * 4)) 5733 1.1 skrll { 5734 1.1 skrll error: 5735 1.1 skrll info->callbacks->einfo 5736 1.1.1.9 christos ("LINKER BUG: .rofixup section size mismatch\n"); 5737 1.1 skrll return false; 5738 1.1 skrll } 5739 1.1.1.2 christos 5740 1.1.1.2 christos hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__", 5741 1.1 skrll false, false, true); 5742 1.1 skrll if (hend 5743 1.1 skrll && (hend->type == bfd_link_hash_defined 5744 1.1 skrll || hend->type == bfd_link_hash_defweak) 5745 1.1 skrll && hend->u.def.section->output_section != NULL) 5746 1.1 skrll { 5747 1.1 skrll bfd_vma value = 5748 1.1 skrll frvfdpic_gotfixup_section (info)->output_section->vma 5749 1.1 skrll + frvfdpic_gotfixup_section (info)->output_offset 5750 1.1 skrll + frvfdpic_gotfixup_section (info)->size 5751 1.1 skrll - hend->u.def.section->output_section->vma 5752 1.1 skrll - hend->u.def.section->output_offset; 5753 1.1 skrll BFD_ASSERT (hend->u.def.value == value); 5754 1.1 skrll if (hend->u.def.value != value) 5755 1.1 skrll goto error; 5756 1.1 skrll } 5757 1.1 skrll } 5758 1.1 skrll } 5759 1.1 skrll if (frvfdpic_pltrel_section (info)) 5760 1.1 skrll { 5761 1.1 skrll BFD_ASSERT (frvfdpic_pltrel_section (info)->size 5762 1.1 skrll == (frvfdpic_pltrel_section (info)->reloc_count 5763 1.1 skrll * sizeof (Elf32_External_Rel))); 5764 1.1 skrll } 5765 1.1 skrll 5766 1.1 skrll 5767 1.1.1.3 christos if (elf_hash_table (info)->dynamic_sections_created) 5768 1.1 skrll { 5769 1.1 skrll Elf32_External_Dyn * dyncon; 5770 1.1 skrll Elf32_External_Dyn * dynconend; 5771 1.1 skrll 5772 1.1 skrll sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 5773 1.1 skrll 5774 1.1 skrll BFD_ASSERT (sdyn != NULL); 5775 1.1 skrll 5776 1.1 skrll dyncon = (Elf32_External_Dyn *) sdyn->contents; 5777 1.1 skrll dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 5778 1.1 skrll 5779 1.1 skrll for (; dyncon < dynconend; dyncon++) 5780 1.1 skrll { 5781 1.1 skrll Elf_Internal_Dyn dyn; 5782 1.1 skrll 5783 1.1 skrll bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 5784 1.1 skrll 5785 1.1 skrll switch (dyn.d_tag) 5786 1.1 skrll { 5787 1.1 skrll default: 5788 1.1 skrll break; 5789 1.1 skrll 5790 1.1 skrll case DT_PLTGOT: 5791 1.1 skrll dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma 5792 1.1 skrll + frvfdpic_got_section (info)->output_offset 5793 1.1 skrll + frvfdpic_got_initial_offset (info); 5794 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 5795 1.1 skrll break; 5796 1.1 skrll 5797 1.1 skrll case DT_JMPREL: 5798 1.1 skrll dyn.d_un.d_ptr = frvfdpic_pltrel_section (info) 5799 1.1 skrll ->output_section->vma 5800 1.1 skrll + frvfdpic_pltrel_section (info)->output_offset; 5801 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 5802 1.1 skrll break; 5803 1.1 skrll 5804 1.1 skrll case DT_PLTRELSZ: 5805 1.1 skrll dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size; 5806 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 5807 1.1.1.9 christos break; 5808 1.1 skrll } 5809 1.1 skrll } 5810 1.1 skrll } 5811 1.1 skrll 5812 1.1 skrll return true; 5813 1.1.1.9 christos } 5814 1.1 skrll 5815 1.1 skrll /* Adjust a symbol defined by a dynamic object and referenced by a 5816 1.1 skrll regular object. */ 5817 1.1 skrll 5818 1.1 skrll static bool 5819 1.1 skrll elf32_frvfdpic_adjust_dynamic_symbol 5820 1.1 skrll (struct bfd_link_info *info ATTRIBUTE_UNUSED, 5821 1.1 skrll struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) 5822 1.1 skrll { 5823 1.1 skrll bfd * dynobj; 5824 1.1.1.6 christos 5825 1.1 skrll dynobj = elf_hash_table (info)->dynobj; 5826 1.1 skrll 5827 1.1 skrll /* Make sure we know what is going on here. */ 5828 1.1 skrll BFD_ASSERT (dynobj != NULL 5829 1.1 skrll && (h->is_weakalias 5830 1.1 skrll || (h->def_dynamic 5831 1.1 skrll && h->ref_regular 5832 1.1.1.6 christos && !h->def_regular))); 5833 1.1 skrll 5834 1.1.1.6 christos /* If this is a weak symbol, and there is a real definition, the 5835 1.1.1.6 christos processor independent code will have arranged for us to see the 5836 1.1.1.6 christos real definition first, and we can just use the same value. */ 5837 1.1.1.6 christos if (h->is_weakalias) 5838 1.1.1.9 christos { 5839 1.1 skrll struct elf_link_hash_entry *def = weakdef (h); 5840 1.1 skrll BFD_ASSERT (def->root.type == bfd_link_hash_defined); 5841 1.1.1.9 christos h->root.u.def.section = def->root.u.def.section; 5842 1.1 skrll h->root.u.def.value = def->root.u.def.value; 5843 1.1 skrll return true; 5844 1.1 skrll } 5845 1.1 skrll 5846 1.1.1.9 christos return true; 5847 1.1 skrll } 5848 1.1 skrll 5849 1.1 skrll /* Perform any actions needed for dynamic symbols. */ 5850 1.1 skrll 5851 1.1 skrll static bool 5852 1.1 skrll elf32_frvfdpic_finish_dynamic_symbol 5853 1.1.1.9 christos (bfd *output_bfd ATTRIBUTE_UNUSED, 5854 1.1 skrll struct bfd_link_info *info ATTRIBUTE_UNUSED, 5855 1.1 skrll struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, 5856 1.1 skrll Elf_Internal_Sym *sym ATTRIBUTE_UNUSED) 5857 1.1 skrll { 5858 1.1 skrll return true; 5859 1.1.1.9 christos } 5860 1.1 skrll 5861 1.1 skrll /* Decide whether to attempt to turn absptr or lsda encodings in 5862 1.1 skrll shared libraries into pcrel within the given input section. */ 5863 1.1 skrll 5864 1.1 skrll static bool 5865 1.1 skrll frvfdpic_elf_use_relative_eh_frame 5866 1.1.1.9 christos (bfd *input_bfd ATTRIBUTE_UNUSED, 5867 1.1 skrll struct bfd_link_info *info ATTRIBUTE_UNUSED, 5868 1.1 skrll asection *eh_frame_section ATTRIBUTE_UNUSED) 5869 1.1 skrll { 5870 1.1 skrll /* We can't use PC-relative encodings in FDPIC binaries, in general. */ 5871 1.1 skrll return false; 5872 1.1 skrll } 5873 1.1 skrll 5874 1.1 skrll /* Adjust the contents of an eh_frame_hdr section before they're output. */ 5875 1.1 skrll 5876 1.1 skrll static bfd_byte 5877 1.1 skrll frvfdpic_elf_encode_eh_address (bfd *abfd, 5878 1.1 skrll struct bfd_link_info *info, 5879 1.1 skrll asection *osec, bfd_vma offset, 5880 1.1 skrll asection *loc_sec, bfd_vma loc_offset, 5881 1.1 skrll bfd_vma *encoded) 5882 1.1 skrll { 5883 1.1 skrll struct elf_link_hash_entry *h; 5884 1.1 skrll 5885 1.1 skrll h = elf_hash_table (info)->hgot; 5886 1.1 skrll BFD_ASSERT (h && h->root.type == bfd_link_hash_defined); 5887 1.1 skrll 5888 1.1 skrll if (! h || (_frvfdpic_osec_to_segment (abfd, osec) 5889 1.1 skrll == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section))) 5890 1.1 skrll return _bfd_elf_encode_eh_address (abfd, info, osec, offset, 5891 1.1 skrll loc_sec, loc_offset, encoded); 5892 1.1 skrll 5893 1.1 skrll BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec) 5894 1.1 skrll == (_frvfdpic_osec_to_segment 5895 1.1 skrll (abfd, h->root.u.def.section->output_section))); 5896 1.1 skrll 5897 1.1 skrll *encoded = osec->vma + offset 5898 1.1 skrll - (h->root.u.def.value 5899 1.1 skrll + h->root.u.def.section->output_section->vma 5900 1.1 skrll + h->root.u.def.section->output_offset); 5901 1.1 skrll 5902 1.1 skrll return DW_EH_PE_datarel | DW_EH_PE_sdata4; 5903 1.1 skrll } 5904 1.1 skrll 5905 1.1 skrll /* Look through the relocs for a section during the first phase. 5906 1.1 skrll 5907 1.1 skrll Besides handling virtual table relocs for gc, we have to deal with 5908 1.1 skrll all sorts of PIC-related relocations. We describe below the 5909 1.1 skrll general plan on how to handle such relocations, even though we only 5910 1.1 skrll collect information at this point, storing them in hash tables for 5911 1.1 skrll perusal of later passes. 5912 1.1 skrll 5913 1.1 skrll 32 relocations are propagated to the linker output when creating 5914 1.1 skrll position-independent output. LO16 and HI16 relocations are not 5915 1.1 skrll supposed to be encountered in this case. 5916 1.1 skrll 5917 1.1 skrll LABEL16 should always be resolvable by the linker, since it's only 5918 1.1 skrll used by branches. 5919 1.1 skrll 5920 1.1 skrll LABEL24, on the other hand, is used by calls. If it turns out that 5921 1.1 skrll the target of a call is a dynamic symbol, a PLT entry must be 5922 1.1 skrll created for it, which triggers the creation of a private function 5923 1.1 skrll descriptor and, unless lazy binding is disabled, a lazy PLT entry. 5924 1.1 skrll 5925 1.1 skrll GPREL relocations require the referenced symbol to be in the same 5926 1.1 skrll segment as _gp, but this can only be checked later. 5927 1.1 skrll 5928 1.1 skrll All GOT, GOTOFF and FUNCDESC relocations require a .got section to 5929 1.1 skrll exist. LABEL24 might as well, since it may require a PLT entry, 5930 1.1 skrll that will require a got. 5931 1.1 skrll 5932 1.1 skrll Non-FUNCDESC GOT relocations require a GOT entry to be created 5933 1.1 skrll regardless of whether the symbol is dynamic. However, since a 5934 1.1 skrll global symbol that turns out to not be exported may have the same 5935 1.1 skrll address of a non-dynamic symbol, we don't assign GOT entries at 5936 1.1 skrll this point, such that we can share them in this case. A relocation 5937 1.1 skrll for the GOT entry always has to be created, be it to offset a 5938 1.1 skrll private symbol by the section load address, be it to get the symbol 5939 1.1 skrll resolved dynamically. 5940 1.1 skrll 5941 1.1 skrll FUNCDESC GOT relocations require a GOT entry to be created, and 5942 1.1 skrll handled as if a FUNCDESC relocation was applied to the GOT entry in 5943 1.1 skrll an object file. 5944 1.1 skrll 5945 1.1 skrll FUNCDESC relocations referencing a symbol that turns out to NOT be 5946 1.1 skrll dynamic cause a private function descriptor to be created. The 5947 1.1 skrll FUNCDESC relocation then decays to a 32 relocation that points at 5948 1.1 skrll the private descriptor. If the symbol is dynamic, the FUNCDESC 5949 1.1 skrll relocation is propagated to the linker output, such that the 5950 1.1 skrll dynamic linker creates the canonical descriptor, pointing to the 5951 1.1 skrll dynamically-resolved definition of the function. 5952 1.1 skrll 5953 1.1 skrll Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic 5954 1.1 skrll symbols that are assigned to the same segment as the GOT, but we 5955 1.1 skrll can only check this later, after we know the complete set of 5956 1.1 skrll symbols defined and/or exported. 5957 1.1 skrll 5958 1.1 skrll FUNCDESC GOTOFF relocations require a function descriptor to be 5959 1.1 skrll created and, unless lazy binding is disabled or the symbol is not 5960 1.1 skrll dynamic, a lazy PLT entry. Since we can't tell at this point 5961 1.1 skrll whether a symbol is going to be dynamic, we have to decide later 5962 1.1 skrll whether to create a lazy PLT entry or bind the descriptor directly 5963 1.1 skrll to the private function. 5964 1.1 skrll 5965 1.1 skrll FUNCDESC_VALUE relocations are not supposed to be present in object 5966 1.1 skrll files, but they may very well be simply propagated to the linker 5967 1.1 skrll output, since they have no side effect. 5968 1.1 skrll 5969 1.1 skrll 5970 1.1 skrll A function descriptor always requires a FUNCDESC_VALUE relocation. 5971 1.1 skrll Whether it's in .plt.rel or not depends on whether lazy binding is 5972 1.1 skrll enabled and on whether the referenced symbol is dynamic. 5973 1.1 skrll 5974 1.1 skrll The existence of a lazy PLT requires the resolverStub lazy PLT 5975 1.1 skrll entry to be present. 5976 1.1 skrll 5977 1.1 skrll 5978 1.1 skrll As for assignment of GOT, PLT and lazy PLT entries, and private 5979 1.1 skrll descriptors, we might do them all sequentially, but we can do 5980 1.1 skrll better than that. For example, we can place GOT entries and 5981 1.1 skrll private function descriptors referenced using 12-bit operands 5982 1.1 skrll closer to the PIC register value, such that these relocations don't 5983 1.1 skrll overflow. Those that are only referenced with LO16 relocations 5984 1.1 skrll could come next, but we may as well place PLT-required function 5985 1.1 skrll descriptors in the 12-bit range to make them shorter. Symbols 5986 1.1 skrll referenced with LO16/HI16 may come next, but we may place 5987 1.1 skrll additional function descriptors in the 16-bit range if we can 5988 1.1 skrll reliably tell that we've already placed entries that are ever 5989 1.1 skrll referenced with only LO16. PLT entries are therefore generated as 5990 1.1 skrll small as possible, while not introducing relocation overflows in 5991 1.1 skrll GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be 5992 1.1 skrll generated before or after PLT entries, but not intermingled with 5993 1.1 skrll them, such that we can have more lazy PLT entries in range for a 5994 1.1 skrll branch to the resolverStub. The resolverStub should be emitted at 5995 1.1 skrll the most distant location from the first lazy PLT entry such that 5996 1.1 skrll it's still in range for a branch, or closer, if there isn't a need 5997 1.1 skrll for so many lazy PLT entries. Additional lazy PLT entries may be 5998 1.1 skrll emitted after the resolverStub, as long as branches are still in 5999 1.1 skrll range. If the branch goes out of range, longer lazy PLT entries 6000 1.1 skrll are emitted. 6001 1.1 skrll 6002 1.1 skrll We could further optimize PLT and lazy PLT entries by giving them 6003 1.1 skrll priority in assignment to closer-to-gr17 locations depending on the 6004 1.1.1.9 christos number of occurrences of references to them (assuming a function 6005 1.1.1.3 christos that's called more often is more important for performance, so its 6006 1.1.1.3 christos PLT entry should be faster), or taking hints from the compiler. 6007 1.1.1.3 christos Given infinite time and money... :-) */ 6008 1.1.1.3 christos 6009 1.1 skrll static bool 6010 1.1 skrll elf32_frv_check_relocs (bfd *abfd, 6011 1.1 skrll struct bfd_link_info *info, 6012 1.1 skrll asection *sec, 6013 1.1 skrll const Elf_Internal_Rela *relocs) 6014 1.1 skrll { 6015 1.1 skrll Elf_Internal_Shdr *symtab_hdr; 6016 1.1 skrll struct elf_link_hash_entry **sym_hashes; 6017 1.1.1.4 christos const Elf_Internal_Rela *rel; 6018 1.1.1.9 christos const Elf_Internal_Rela *rel_end; 6019 1.1 skrll bfd *dynobj; 6020 1.1 skrll struct frvfdpic_relocs_info *picrel; 6021 1.1 skrll 6022 1.1 skrll if (bfd_link_relocatable (info)) 6023 1.1 skrll return true; 6024 1.1 skrll 6025 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 6026 1.1 skrll sym_hashes = elf_sym_hashes (abfd); 6027 1.1 skrll 6028 1.1 skrll dynobj = elf_hash_table (info)->dynobj; 6029 1.1 skrll rel_end = relocs + sec->reloc_count; 6030 1.1 skrll for (rel = relocs; rel < rel_end; rel++) 6031 1.1 skrll { 6032 1.1.1.6 christos struct elf_link_hash_entry *h; 6033 1.1 skrll unsigned long r_symndx; 6034 1.1 skrll 6035 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info); 6036 1.1 skrll if (r_symndx < symtab_hdr->sh_info) 6037 1.1 skrll h = NULL; 6038 1.1 skrll else 6039 1.1 skrll { 6040 1.1 skrll h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 6041 1.1 skrll while (h->root.type == bfd_link_hash_indirect 6042 1.1 skrll || h->root.type == bfd_link_hash_warning) 6043 1.1 skrll h = (struct elf_link_hash_entry *) h->root.u.i.link; 6044 1.1 skrll } 6045 1.1 skrll 6046 1.1 skrll switch (ELF32_R_TYPE (rel->r_info)) 6047 1.1 skrll { 6048 1.1 skrll case R_FRV_GETTLSOFF: 6049 1.1 skrll case R_FRV_TLSDESC_VALUE: 6050 1.1 skrll case R_FRV_GOTTLSDESC12: 6051 1.1 skrll case R_FRV_GOTTLSDESCHI: 6052 1.1 skrll case R_FRV_GOTTLSDESCLO: 6053 1.1 skrll case R_FRV_GOTTLSOFF12: 6054 1.1 skrll case R_FRV_GOTTLSOFFHI: 6055 1.1 skrll case R_FRV_GOTTLSOFFLO: 6056 1.1 skrll case R_FRV_TLSOFF: 6057 1.1 skrll case R_FRV_GOT12: 6058 1.1 skrll case R_FRV_GOTHI: 6059 1.1 skrll case R_FRV_GOTLO: 6060 1.1 skrll case R_FRV_FUNCDESC_GOT12: 6061 1.1 skrll case R_FRV_FUNCDESC_GOTHI: 6062 1.1 skrll case R_FRV_FUNCDESC_GOTLO: 6063 1.1 skrll case R_FRV_GOTOFF12: 6064 1.1 skrll case R_FRV_GOTOFFHI: 6065 1.1 skrll case R_FRV_GOTOFFLO: 6066 1.1 skrll case R_FRV_FUNCDESC_GOTOFF12: 6067 1.1 skrll case R_FRV_FUNCDESC_GOTOFFHI: 6068 1.1 skrll case R_FRV_FUNCDESC_GOTOFFLO: 6069 1.1 skrll case R_FRV_FUNCDESC: 6070 1.1 skrll case R_FRV_FUNCDESC_VALUE: 6071 1.1 skrll case R_FRV_TLSMOFF12: 6072 1.1 skrll case R_FRV_TLSMOFFHI: 6073 1.1 skrll case R_FRV_TLSMOFFLO: 6074 1.1 skrll case R_FRV_TLSMOFF: 6075 1.1 skrll if (! IS_FDPIC (abfd)) 6076 1.1 skrll goto bad_reloc; 6077 1.1 skrll /* Fall through. */ 6078 1.1 skrll case R_FRV_GPREL12: 6079 1.1 skrll case R_FRV_GPRELU12: 6080 1.1 skrll case R_FRV_GPRELHI: 6081 1.1 skrll case R_FRV_GPRELLO: 6082 1.1 skrll case R_FRV_LABEL24: 6083 1.1.1.9 christos case R_FRV_32: 6084 1.1 skrll if (! dynobj) 6085 1.1 skrll { 6086 1.1 skrll elf_hash_table (info)->dynobj = dynobj = abfd; 6087 1.1 skrll if (! _frv_create_got_section (abfd, info)) 6088 1.1 skrll return false; 6089 1.1 skrll } 6090 1.1 skrll if (! IS_FDPIC (abfd)) 6091 1.1 skrll { 6092 1.1 skrll picrel = NULL; 6093 1.1 skrll break; 6094 1.1 skrll } 6095 1.1 skrll if (h != NULL) 6096 1.1 skrll { 6097 1.1 skrll if (h->dynindx == -1) 6098 1.1 skrll switch (ELF_ST_VISIBILITY (h->other)) 6099 1.1 skrll { 6100 1.1 skrll case STV_INTERNAL: 6101 1.1 skrll case STV_HIDDEN: 6102 1.1 skrll break; 6103 1.1 skrll default: 6104 1.1 skrll bfd_elf_link_record_dynamic_symbol (info, h); 6105 1.1 skrll break; 6106 1.1 skrll } 6107 1.1 skrll picrel 6108 1.1 skrll = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), 6109 1.1 skrll abfd, h, 6110 1.1 skrll rel->r_addend, INSERT); 6111 1.1 skrll } 6112 1.1.1.9 christos else 6113 1.1 skrll picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info 6114 1.1 skrll (info), abfd, r_symndx, 6115 1.1 skrll rel->r_addend, INSERT); 6116 1.1 skrll if (! picrel) 6117 1.1 skrll return false; 6118 1.1 skrll break; 6119 1.1 skrll 6120 1.1 skrll default: 6121 1.1.1.6 christos picrel = NULL; 6122 1.1 skrll break; 6123 1.1 skrll } 6124 1.1 skrll 6125 1.1 skrll switch (ELF32_R_TYPE (rel->r_info)) 6126 1.1 skrll { 6127 1.1 skrll case R_FRV_LABEL24: 6128 1.1 skrll if (IS_FDPIC (abfd)) 6129 1.1.1.8 christos picrel->call = 1; 6130 1.1 skrll break; 6131 1.1 skrll 6132 1.1 skrll case R_FRV_FUNCDESC_VALUE: 6133 1.1 skrll picrel->relocsfdv++; 6134 1.1 skrll if (bfd_section_flags (sec) & SEC_ALLOC) 6135 1.1 skrll picrel->relocs32--; 6136 1.1 skrll /* Fall through. */ 6137 1.1 skrll 6138 1.1.1.8 christos case R_FRV_32: 6139 1.1 skrll if (! IS_FDPIC (abfd)) 6140 1.1 skrll break; 6141 1.1 skrll 6142 1.1 skrll picrel->sym = 1; 6143 1.1 skrll if (bfd_section_flags (sec) & SEC_ALLOC) 6144 1.1 skrll picrel->relocs32++; 6145 1.1 skrll break; 6146 1.1 skrll 6147 1.1 skrll case R_FRV_GOT12: 6148 1.1 skrll picrel->got12 = 1; 6149 1.1 skrll break; 6150 1.1 skrll 6151 1.1 skrll case R_FRV_GOTHI: 6152 1.1 skrll case R_FRV_GOTLO: 6153 1.1 skrll picrel->gothilo = 1; 6154 1.1 skrll break; 6155 1.1 skrll 6156 1.1 skrll case R_FRV_FUNCDESC_GOT12: 6157 1.1 skrll picrel->fdgot12 = 1; 6158 1.1 skrll break; 6159 1.1 skrll 6160 1.1 skrll case R_FRV_FUNCDESC_GOTHI: 6161 1.1 skrll case R_FRV_FUNCDESC_GOTLO: 6162 1.1 skrll picrel->fdgothilo = 1; 6163 1.1 skrll break; 6164 1.1 skrll 6165 1.1 skrll case R_FRV_GOTOFF12: 6166 1.1 skrll case R_FRV_GOTOFFHI: 6167 1.1 skrll case R_FRV_GOTOFFLO: 6168 1.1 skrll picrel->gotoff = 1; 6169 1.1 skrll break; 6170 1.1 skrll 6171 1.1 skrll case R_FRV_FUNCDESC_GOTOFF12: 6172 1.1 skrll picrel->fdgoff12 = 1; 6173 1.1 skrll break; 6174 1.1 skrll 6175 1.1 skrll case R_FRV_FUNCDESC_GOTOFFHI: 6176 1.1 skrll case R_FRV_FUNCDESC_GOTOFFLO: 6177 1.1 skrll picrel->fdgoffhilo = 1; 6178 1.1 skrll break; 6179 1.1 skrll 6180 1.1 skrll case R_FRV_FUNCDESC: 6181 1.1 skrll picrel->fd = 1; 6182 1.1 skrll picrel->relocsfd++; 6183 1.1 skrll break; 6184 1.1 skrll 6185 1.1 skrll case R_FRV_GETTLSOFF: 6186 1.1 skrll picrel->tlsplt = 1; 6187 1.1 skrll break; 6188 1.1 skrll 6189 1.1 skrll case R_FRV_TLSDESC_VALUE: 6190 1.1 skrll picrel->relocstlsd++; 6191 1.1 skrll goto bad_reloc; 6192 1.1 skrll 6193 1.1 skrll case R_FRV_GOTTLSDESC12: 6194 1.1 skrll picrel->tlsdesc12 = 1; 6195 1.1 skrll break; 6196 1.1 skrll 6197 1.1 skrll case R_FRV_GOTTLSDESCHI: 6198 1.1 skrll case R_FRV_GOTTLSDESCLO: 6199 1.1 skrll picrel->tlsdeschilo = 1; 6200 1.1 skrll break; 6201 1.1 skrll 6202 1.1 skrll case R_FRV_TLSMOFF12: 6203 1.1 skrll case R_FRV_TLSMOFFHI: 6204 1.1 skrll case R_FRV_TLSMOFFLO: 6205 1.1 skrll case R_FRV_TLSMOFF: 6206 1.1 skrll break; 6207 1.1 skrll 6208 1.1 skrll case R_FRV_GOTTLSOFF12: 6209 1.1 skrll picrel->tlsoff12 = 1; 6210 1.1 skrll info->flags |= DF_STATIC_TLS; 6211 1.1 skrll break; 6212 1.1 skrll 6213 1.1 skrll case R_FRV_GOTTLSOFFHI: 6214 1.1 skrll case R_FRV_GOTTLSOFFLO: 6215 1.1 skrll picrel->tlsoffhilo = 1; 6216 1.1 skrll info->flags |= DF_STATIC_TLS; 6217 1.1 skrll break; 6218 1.1 skrll 6219 1.1.1.6 christos case R_FRV_TLSOFF: 6220 1.1.1.6 christos picrel->relocstlsoff++; 6221 1.1.1.6 christos info->flags |= DF_STATIC_TLS; 6222 1.1.1.6 christos goto bad_reloc; 6223 1.1.1.9 christos 6224 1.1.1.6 christos /* This relocation describes the C++ object vtable hierarchy. 6225 1.1.1.6 christos Reconstruct it for later use during GC. */ 6226 1.1.1.6 christos case R_FRV_GNU_VTINHERIT: 6227 1.1.1.6 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 6228 1.1.1.6 christos return false; 6229 1.1.1.8 christos break; 6230 1.1.1.9 christos 6231 1.1.1.6 christos /* This relocation describes which C++ vtable entries are actually 6232 1.1 skrll used. Record for later use during GC. */ 6233 1.1 skrll case R_FRV_GNU_VTENTRY: 6234 1.1 skrll if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 6235 1.1 skrll return false; 6236 1.1 skrll break; 6237 1.1 skrll 6238 1.1 skrll case R_FRV_LABEL16: 6239 1.1 skrll case R_FRV_LO16: 6240 1.1 skrll case R_FRV_HI16: 6241 1.1 skrll case R_FRV_GPREL12: 6242 1.1 skrll case R_FRV_GPRELU12: 6243 1.1 skrll case R_FRV_GPREL32: 6244 1.1 skrll case R_FRV_GPRELHI: 6245 1.1 skrll case R_FRV_GPRELLO: 6246 1.1 skrll case R_FRV_TLSDESC_RELAX: 6247 1.1 skrll case R_FRV_GETTLSOFF_RELAX: 6248 1.1.1.7 christos case R_FRV_TLSOFF_RELAX: 6249 1.1.1.7 christos break; 6250 1.1.1.7 christos 6251 1.1.1.9 christos default: 6252 1.1.1.6 christos bad_reloc: 6253 1.1 skrll /* xgettext:c-format */ 6254 1.1 skrll _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 6255 1.1.1.9 christos abfd, (unsigned int) ELF32_R_TYPE (rel->r_info)); 6256 1.1 skrll return false; 6257 1.1 skrll } 6258 1.1 skrll } 6259 1.1 skrll 6260 1.1 skrll return true; 6261 1.1 skrll } 6262 1.1.1.3 christos 6263 1.1 skrll 6264 1.1 skrll /* Return the machine subcode from the ELF e_flags header. */ 6266 1.1 skrll 6267 1.1 skrll static int 6268 1.1 skrll elf32_frv_machine (bfd *abfd) 6269 1.1 skrll { 6270 1.1 skrll switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK) 6271 1.1 skrll { 6272 1.1 skrll default: break; 6273 1.1 skrll case EF_FRV_CPU_FR550: return bfd_mach_fr550; 6274 1.1 skrll case EF_FRV_CPU_FR500: return bfd_mach_fr500; 6275 1.1 skrll case EF_FRV_CPU_FR450: return bfd_mach_fr450; 6276 1.1 skrll case EF_FRV_CPU_FR405: return bfd_mach_fr400; 6277 1.1 skrll case EF_FRV_CPU_FR400: return bfd_mach_fr400; 6278 1.1 skrll case EF_FRV_CPU_FR300: return bfd_mach_fr300; 6279 1.1 skrll case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple; 6280 1.1 skrll case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat; 6281 1.1 skrll } 6282 1.1.1.9 christos 6283 1.1.1.3 christos return bfd_mach_frv; 6284 1.1 skrll } 6285 1.1 skrll 6286 1.1 skrll /* Set the right machine number for a FRV ELF file. */ 6287 1.1 skrll 6288 1.1 skrll static bool 6289 1.1 skrll elf32_frv_object_p (bfd *abfd) 6290 1.1 skrll { 6291 1.1 skrll bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd)); 6292 1.1.1.9 christos return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0) 6293 1.1.1.3 christos == (IS_FDPIC (abfd))); 6294 1.1 skrll } 6295 1.1 skrll 6296 1.1.1.9 christos /* Function to set the ELF flag bits. */ 6298 1.1 skrll 6299 1.1 skrll static bool 6300 1.1 skrll frv_elf_set_private_flags (bfd *abfd, flagword flags) 6301 1.1 skrll { 6302 1.1 skrll elf_elfheader (abfd)->e_flags = flags; 6303 1.1.1.9 christos elf_flags_init (abfd) = true; 6304 1.1 skrll return true; 6305 1.1 skrll } 6306 1.1 skrll 6307 1.1.1.9 christos /* Return true if the architecture described by elf header flag 6308 1.1 skrll EXTENSION is an extension of the architecture described by BASE. */ 6309 1.1 skrll 6310 1.1 skrll static bool 6311 1.1 skrll frv_elf_arch_extension_p (flagword base, flagword extension) 6312 1.1 skrll { 6313 1.1 skrll if (base == extension) 6314 1.1.1.9 christos return true; 6315 1.1 skrll 6316 1.1 skrll /* CPU_GENERIC code can be merged with code for a specific 6317 1.1 skrll architecture, in which case the result is marked as being 6318 1.1.1.9 christos for the specific architecture. Everything is therefore 6319 1.1 skrll an extension of CPU_GENERIC. */ 6320 1.1 skrll if (base == EF_FRV_CPU_GENERIC) 6321 1.1 skrll return true; 6322 1.1.1.9 christos 6323 1.1 skrll if (extension == EF_FRV_CPU_FR450) 6324 1.1.1.9 christos if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405) 6325 1.1 skrll return true; 6326 1.1 skrll 6327 1.1 skrll if (extension == EF_FRV_CPU_FR405) 6328 1.1 skrll if (base == EF_FRV_CPU_FR400) 6329 1.1 skrll return true; 6330 1.1.1.9 christos 6331 1.1.1.6 christos return false; 6332 1.1 skrll } 6333 1.1.1.6 christos 6334 1.1 skrll /* Merge backend specific data from an object file to the output 6335 1.1 skrll object file when linking. */ 6336 1.1.1.9 christos 6337 1.1 skrll static bool 6338 1.1 skrll frv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) 6339 1.1 skrll { 6340 1.1.1.9 christos bfd *obfd = info->output_bfd; 6341 1.1.1.9 christos flagword old_flags, old_partial; 6342 1.1.1.9 christos flagword new_flags, new_partial; 6343 1.1.1.9 christos bool error = false; 6344 1.1.1.12 christos char new_opt[80]; 6345 1.1.1.12 christos char old_opt[80]; 6346 1.1.1.12 christos 6347 1.1 skrll /* FIXME: What should be checked when linking shared libraries? */ 6348 1.1 skrll if ((ibfd->flags & DYNAMIC) != 0) 6349 1.1 skrll return true; 6350 1.1 skrll 6351 1.1 skrll if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 6352 1.1 skrll return true; 6353 1.1 skrll 6354 1.1 skrll new_opt[0] = old_opt[0] = '\0'; 6355 1.1.1.6 christos new_flags = elf_elfheader (ibfd)->e_flags; 6356 1.1.1.6 christos old_flags = elf_elfheader (obfd)->e_flags; 6357 1.1.1.6 christos 6358 1.1.1.6 christos if (new_flags & EF_FRV_FDPIC) 6359 1.1 skrll new_flags &= ~EF_FRV_PIC; 6360 1.1 skrll 6361 1.1 skrll #ifdef DEBUG 6362 1.1 skrll _bfd_error_handler 6363 1.1.1.9 christos ("old_flags = 0x%.8x, new_flags = 0x%.8x, init = %s, filename = %s", 6364 1.1 skrll old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", 6365 1.1 skrll bfd_get_filename (ibfd)); 6366 1.1 skrll #endif 6367 1.1 skrll 6368 1.1 skrll if (!elf_flags_init (obfd)) /* First call, no flags set. */ 6369 1.1 skrll { 6370 1.1 skrll elf_flags_init (obfd) = true; 6371 1.1 skrll old_flags = new_flags; 6372 1.1 skrll } 6373 1.1.1.6 christos 6374 1.1 skrll else if (new_flags == old_flags) /* Compatible flags are ok. */ 6375 1.1 skrll ; 6376 1.1 skrll 6377 1.1 skrll else /* Possibly incompatible flags. */ 6378 1.1 skrll { 6379 1.1 skrll /* Warn if different # of gprs are used. Note, 0 means nothing is 6380 1.1 skrll said about the size of gprs. */ 6381 1.1 skrll new_partial = (new_flags & EF_FRV_GPR_MASK); 6382 1.1 skrll old_partial = (old_flags & EF_FRV_GPR_MASK); 6383 1.1 skrll if (new_partial == old_partial) 6384 1.1 skrll ; 6385 1.1 skrll 6386 1.1 skrll else if (new_partial == 0) 6387 1.1 skrll ; 6388 1.1 skrll 6389 1.1 skrll else if (old_partial == 0) 6390 1.1 skrll old_flags |= new_partial; 6391 1.1 skrll 6392 1.1 skrll else 6393 1.1 skrll { 6394 1.1 skrll switch (new_partial) 6395 1.1 skrll { 6396 1.1 skrll default: strcat (new_opt, " -mgpr-??"); break; 6397 1.1 skrll case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break; 6398 1.1 skrll case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break; 6399 1.1 skrll } 6400 1.1 skrll 6401 1.1 skrll switch (old_partial) 6402 1.1 skrll { 6403 1.1.1.6 christos default: strcat (old_opt, " -mgpr-??"); break; 6404 1.1 skrll case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break; 6405 1.1 skrll case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break; 6406 1.1 skrll } 6407 1.1 skrll } 6408 1.1 skrll 6409 1.1 skrll /* Warn if different # of fprs are used. Note, 0 means nothing is 6410 1.1 skrll said about the size of fprs. */ 6411 1.1 skrll new_partial = (new_flags & EF_FRV_FPR_MASK); 6412 1.1 skrll old_partial = (old_flags & EF_FRV_FPR_MASK); 6413 1.1 skrll if (new_partial == old_partial) 6414 1.1 skrll ; 6415 1.1 skrll 6416 1.1 skrll else if (new_partial == 0) 6417 1.1 skrll ; 6418 1.1 skrll 6419 1.1 skrll else if (old_partial == 0) 6420 1.1 skrll old_flags |= new_partial; 6421 1.1 skrll 6422 1.1 skrll else 6423 1.1 skrll { 6424 1.1 skrll switch (new_partial) 6425 1.1 skrll { 6426 1.1 skrll default: strcat (new_opt, " -mfpr-?"); break; 6427 1.1 skrll case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break; 6428 1.1 skrll case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break; 6429 1.1 skrll case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break; 6430 1.1 skrll } 6431 1.1 skrll 6432 1.1 skrll switch (old_partial) 6433 1.1 skrll { 6434 1.1 skrll default: strcat (old_opt, " -mfpr-?"); break; 6435 1.1.1.6 christos case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break; 6436 1.1 skrll case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break; 6437 1.1 skrll case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break; 6438 1.1 skrll } 6439 1.1 skrll } 6440 1.1 skrll 6441 1.1 skrll /* Warn if different dword support was used. Note, 0 means nothing is 6442 1.1 skrll said about the dword support. */ 6443 1.1 skrll new_partial = (new_flags & EF_FRV_DWORD_MASK); 6444 1.1 skrll old_partial = (old_flags & EF_FRV_DWORD_MASK); 6445 1.1 skrll if (new_partial == old_partial) 6446 1.1 skrll ; 6447 1.1 skrll 6448 1.1 skrll else if (new_partial == 0) 6449 1.1 skrll ; 6450 1.1 skrll 6451 1.1 skrll else if (old_partial == 0) 6452 1.1 skrll old_flags |= new_partial; 6453 1.1 skrll 6454 1.1 skrll else 6455 1.1 skrll { 6456 1.1 skrll switch (new_partial) 6457 1.1 skrll { 6458 1.1 skrll default: strcat (new_opt, " -mdword-?"); break; 6459 1.1 skrll case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break; 6460 1.1 skrll case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break; 6461 1.1 skrll } 6462 1.1 skrll 6463 1.1 skrll switch (old_partial) 6464 1.1 skrll { 6465 1.1 skrll default: strcat (old_opt, " -mdword-?"); break; 6466 1.1 skrll case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break; 6467 1.1 skrll case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break; 6468 1.1 skrll } 6469 1.1 skrll } 6470 1.1 skrll 6471 1.1 skrll /* Or in flags that accumulate (ie, if one module uses it, mark that the 6472 1.1 skrll feature is used. */ 6473 1.1 skrll old_flags |= new_flags & (EF_FRV_DOUBLE 6474 1.1 skrll | EF_FRV_MEDIA 6475 1.1 skrll | EF_FRV_MULADD 6476 1.1 skrll | EF_FRV_NON_PIC_RELOCS); 6477 1.1 skrll 6478 1.1 skrll /* If any module was compiled without -G0, clear the G0 bit. */ 6479 1.1 skrll old_flags = ((old_flags & ~ EF_FRV_G0) 6480 1.1.1.6 christos | (old_flags & new_flags & EF_FRV_G0)); 6481 1.1 skrll 6482 1.1 skrll /* If any module was compiled without -mnopack, clear the mnopack bit. */ 6483 1.1 skrll old_flags = ((old_flags & ~ EF_FRV_NOPACK) 6484 1.1 skrll | (old_flags & new_flags & EF_FRV_NOPACK)); 6485 1.1 skrll 6486 1.1 skrll /* We don't have to do anything if the pic flags are the same, or the new 6487 1.1.1.6 christos module(s) were compiled with -mlibrary-pic. */ 6488 1.1 skrll new_partial = (new_flags & EF_FRV_PIC_FLAGS); 6489 1.1 skrll old_partial = (old_flags & EF_FRV_PIC_FLAGS); 6490 1.1 skrll if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0)) 6491 1.1 skrll ; 6492 1.1 skrll 6493 1.1 skrll /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic 6494 1.1 skrll flags if any from the new module. */ 6495 1.1 skrll else if ((old_partial & EF_FRV_LIBPIC) != 0) 6496 1.1.1.6 christos old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial; 6497 1.1 skrll 6498 1.1 skrll /* If we have mixtures of -fpic and -fPIC, or in both bits. */ 6499 1.1 skrll else if (new_partial != 0 && old_partial != 0) 6500 1.1 skrll old_flags |= new_partial; 6501 1.1 skrll 6502 1.1 skrll /* One module was compiled for pic and the other was not, see if we have 6503 1.1 skrll had any relocations that are not pic-safe. */ 6504 1.1 skrll else 6505 1.1.1.9 christos { 6506 1.1.1.6 christos if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0) 6507 1.1.1.6 christos old_flags |= new_partial; 6508 1.1.1.7 christos else 6509 1.1.1.6 christos { 6510 1.1.1.6 christos old_flags &= ~ EF_FRV_PIC_FLAGS; 6511 1.1 skrll #ifndef FRV_NO_PIC_ERROR 6512 1.1 skrll error = true; 6513 1.1 skrll _bfd_error_handler 6514 1.1 skrll /* xgettext:c-format */ 6515 1.1 skrll (_("%pB: compiled with %s and linked with modules" 6516 1.1 skrll " that use non-pic relocations"), 6517 1.1 skrll ibfd, (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic"); 6518 1.1 skrll #endif 6519 1.1 skrll } 6520 1.1 skrll } 6521 1.1 skrll 6522 1.1 skrll /* Warn if different cpu is used (allow a specific cpu to override 6523 1.1 skrll the generic cpu). */ 6524 1.1 skrll new_partial = (new_flags & EF_FRV_CPU_MASK); 6525 1.1 skrll old_partial = (old_flags & EF_FRV_CPU_MASK); 6526 1.1 skrll if (frv_elf_arch_extension_p (new_partial, old_partial)) 6527 1.1 skrll ; 6528 1.1 skrll 6529 1.1 skrll else if (frv_elf_arch_extension_p (old_partial, new_partial)) 6530 1.1 skrll old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial; 6531 1.1 skrll 6532 1.1 skrll else 6533 1.1 skrll { 6534 1.1 skrll switch (new_partial) 6535 1.1 skrll { 6536 1.1 skrll default: strcat (new_opt, " -mcpu=?"); break; 6537 1.1 skrll case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break; 6538 1.1 skrll case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break; 6539 1.1 skrll case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break; 6540 1.1 skrll case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break; 6541 1.1 skrll case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break; 6542 1.1 skrll case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break; 6543 1.1 skrll case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break; 6544 1.1 skrll case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break; 6545 1.1 skrll case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break; 6546 1.1 skrll } 6547 1.1 skrll 6548 1.1 skrll switch (old_partial) 6549 1.1 skrll { 6550 1.1 skrll default: strcat (old_opt, " -mcpu=?"); break; 6551 1.1 skrll case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break; 6552 1.1 skrll case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break; 6553 1.1 skrll case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break; 6554 1.1 skrll case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break; 6555 1.1 skrll case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break; 6556 1.1 skrll case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break; 6557 1.1 skrll case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break; 6558 1.1 skrll case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break; 6559 1.1.1.9 christos case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break; 6560 1.1.1.6 christos } 6561 1.1.1.6 christos } 6562 1.1.1.7 christos 6563 1.1.1.6 christos /* Print out any mismatches from above. */ 6564 1.1 skrll if (new_opt[0]) 6565 1.1 skrll { 6566 1.1 skrll error = true; 6567 1.1 skrll _bfd_error_handler 6568 1.1 skrll /* xgettext:c-format */ 6569 1.1 skrll (_("%pB: compiled with %s and linked with modules compiled with %s"), 6570 1.1 skrll ibfd, new_opt, old_opt); 6571 1.1 skrll } 6572 1.1.1.9 christos 6573 1.1.1.6 christos /* Warn about any other mismatches */ 6574 1.1.1.6 christos new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS); 6575 1.1.1.7 christos old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS); 6576 1.1.1.6 christos if (new_partial != old_partial) 6577 1.1.1.6 christos { 6578 1.1 skrll old_flags |= new_partial; 6579 1.1 skrll error = true; 6580 1.1 skrll _bfd_error_handler 6581 1.1 skrll /* xgettext:c-format */ 6582 1.1 skrll (_("%pB: uses different unknown e_flags (%#x) fields" 6583 1.1 skrll " than previous modules (%#x)"), 6584 1.1 skrll ibfd, new_partial, old_partial); 6585 1.1 skrll } 6586 1.1 skrll } 6587 1.1 skrll 6588 1.1 skrll /* If the cpu is -mcpu=simple, then set the -mnopack bit. */ 6589 1.1 skrll if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE) 6590 1.1 skrll old_flags |= EF_FRV_NOPACK; 6591 1.1 skrll 6592 1.1 skrll /* Update the old flags now with changes made above. */ 6593 1.1 skrll old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK; 6594 1.1.1.9 christos elf_elfheader (obfd)->e_flags = old_flags; 6595 1.1 skrll if (old_partial != (old_flags & EF_FRV_CPU_MASK)) 6596 1.1.1.6 christos bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd)); 6597 1.1.1.7 christos 6598 1.1.1.6 christos if (((new_flags & EF_FRV_FDPIC) == 0) 6599 1.1 skrll != (! IS_FDPIC (ibfd))) 6600 1.1.1.6 christos { 6601 1.1.1.7 christos error = true; 6602 1.1.1.6 christos if (IS_FDPIC (obfd)) 6603 1.1 skrll _bfd_error_handler 6604 1.1 skrll (_("%pB: cannot link non-fdpic object file into fdpic executable"), 6605 1.1 skrll ibfd); 6606 1.1 skrll else 6607 1.1 skrll _bfd_error_handler 6608 1.1 skrll (_("%pB: cannot link fdpic object file into non-fdpic executable"), 6609 1.1 skrll ibfd); 6610 1.1 skrll } 6611 1.1 skrll 6612 1.1.1.9 christos if (error) 6613 1.1.1.3 christos bfd_set_error (bfd_error_bad_value); 6614 1.1 skrll 6615 1.1 skrll return !error; 6616 1.1 skrll } 6617 1.1 skrll 6618 1.1 skrll 6619 1.1 skrll static bool 6621 1.1 skrll frv_elf_print_private_bfd_data (bfd *abfd, void * ptr) 6622 1.1 skrll { 6623 1.1 skrll FILE *file = (FILE *) ptr; 6624 1.1 skrll flagword flags; 6625 1.1 skrll 6626 1.1 skrll BFD_ASSERT (abfd != NULL && ptr != NULL); 6627 1.1 skrll 6628 1.1 skrll /* Print normal ELF private data. */ 6629 1.1 skrll _bfd_elf_print_private_bfd_data (abfd, ptr); 6630 1.1 skrll 6631 1.1 skrll flags = elf_elfheader (abfd)->e_flags; 6632 1.1 skrll fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags); 6633 1.1 skrll 6634 1.1 skrll switch (flags & EF_FRV_CPU_MASK) 6635 1.1 skrll { 6636 1.1 skrll default: break; 6637 1.1 skrll case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break; 6638 1.1 skrll case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break; 6639 1.1 skrll case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break; 6640 1.1 skrll case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break; 6641 1.1 skrll case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break; 6642 1.1 skrll case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break; 6643 1.1 skrll case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break; 6644 1.1 skrll case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break; 6645 1.1 skrll } 6646 1.1 skrll 6647 1.1 skrll switch (flags & EF_FRV_GPR_MASK) 6648 1.1 skrll { 6649 1.1 skrll default: break; 6650 1.1 skrll case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break; 6651 1.1 skrll case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break; 6652 1.1 skrll } 6653 1.1 skrll 6654 1.1 skrll switch (flags & EF_FRV_FPR_MASK) 6655 1.1 skrll { 6656 1.1 skrll default: break; 6657 1.1 skrll case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break; 6658 1.1 skrll case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break; 6659 1.1 skrll case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break; 6660 1.1 skrll } 6661 1.1 skrll 6662 1.1 skrll switch (flags & EF_FRV_DWORD_MASK) 6663 1.1 skrll { 6664 1.1 skrll default: break; 6665 1.1 skrll case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break; 6666 1.1 skrll case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break; 6667 1.1 skrll } 6668 1.1 skrll 6669 1.1 skrll if (flags & EF_FRV_DOUBLE) 6670 1.1 skrll fprintf (file, " -mdouble"); 6671 1.1 skrll 6672 1.1 skrll if (flags & EF_FRV_MEDIA) 6673 1.1 skrll fprintf (file, " -mmedia"); 6674 1.1 skrll 6675 1.1 skrll if (flags & EF_FRV_MULADD) 6676 1.1 skrll fprintf (file, " -mmuladd"); 6677 1.1 skrll 6678 1.1 skrll if (flags & EF_FRV_PIC) 6679 1.1 skrll fprintf (file, " -fpic"); 6680 1.1 skrll 6681 1.1 skrll if (flags & EF_FRV_BIGPIC) 6682 1.1 skrll fprintf (file, " -fPIC"); 6683 1.1 skrll 6684 1.1 skrll if (flags & EF_FRV_LIBPIC) 6685 1.1 skrll fprintf (file, " -mlibrary-pic"); 6686 1.1 skrll 6687 1.1 skrll if (flags & EF_FRV_FDPIC) 6688 1.1 skrll fprintf (file, " -mfdpic"); 6689 1.1.1.9 christos 6690 1.1 skrll if (flags & EF_FRV_NON_PIC_RELOCS) 6691 1.1 skrll fprintf (file, " non-pic relocations"); 6692 1.1 skrll 6693 1.1 skrll if (flags & EF_FRV_G0) 6694 1.1 skrll fprintf (file, " -G0"); 6695 1.1.1.9 christos 6696 1.1 skrll fputc ('\n', file); 6697 1.1 skrll return true; 6698 1.1 skrll } 6699 1.1 skrll 6700 1.1 skrll 6701 1.1 skrll /* Support for core dump NOTE sections. */ 6703 1.1 skrll 6704 1.1.1.9 christos static bool 6705 1.1 skrll elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 6706 1.1 skrll { 6707 1.1.1.6 christos int offset; 6708 1.1 skrll unsigned int raw_size; 6709 1.1 skrll 6710 1.1.1.4 christos switch (note->descsz) 6711 1.1 skrll { 6712 1.1.1.4 christos default: 6713 1.1 skrll return false; 6714 1.1 skrll 6715 1.1.1.4 christos /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other 6716 1.1 skrll hardcoded offsets and sizes listed below (and contained within 6717 1.1 skrll this lexical block) refer to fields in the target's elf_prstatus 6718 1.1 skrll struct. */ 6719 1.1 skrll case 268: 6720 1.1 skrll /* `pr_cursig' is at offset 12. */ 6721 1.1 skrll elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); 6722 1.1 skrll 6723 1.1 skrll /* `pr_pid' is at offset 24. */ 6724 1.1 skrll elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); 6725 1.1 skrll 6726 1.1.1.4 christos /* `pr_reg' is at offset 72. */ 6727 1.1 skrll offset = 72; 6728 1.1 skrll 6729 1.1 skrll /* Most grok_prstatus implementations set `raw_size' to the size 6730 1.1 skrll of the pr_reg field. For Linux/FRV, we set `raw_size' to be 6731 1.1 skrll the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap' 6732 1.1 skrll and `pr_interp_fdpic_loadmap', both of which (by design) 6733 1.1 skrll immediately follow `pr_reg'. This will allow these fields to 6734 1.1 skrll be viewed by GDB as registers. 6735 1.1 skrll 6736 1.1 skrll `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and 6737 1.1 skrll `pr_interp_fdpic_loadmap' are 4 bytes each. */ 6738 1.1 skrll raw_size = 184 + 4 + 4; 6739 1.1.1.9 christos 6740 1.1 skrll break; 6741 1.1 skrll } 6742 1.1 skrll 6743 1.1 skrll /* Make a ".reg/999" section. */ 6744 1.1 skrll return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size, 6745 1.1.1.9 christos note->descpos + offset); 6746 1.1 skrll } 6747 1.1 skrll 6748 1.1 skrll static bool 6749 1.1 skrll elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 6750 1.1 skrll { 6751 1.1.1.4 christos switch (note->descsz) 6752 1.1 skrll { 6753 1.1 skrll default: 6754 1.1 skrll return false; 6755 1.1.1.4 christos 6756 1.1 skrll /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */ 6757 1.1 skrll case 124: 6758 1.1 skrll 6759 1.1 skrll /* `pr_fname' is found at offset 28 and is 16 bytes long. */ 6760 1.1 skrll elf_tdata (abfd)->core->program 6761 1.1 skrll = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); 6762 1.1 skrll 6763 1.1 skrll /* `pr_psargs' is found at offset 44 and is 80 bytes long. */ 6764 1.1.1.4 christos elf_tdata (abfd)->core->command 6765 1.1 skrll = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); 6766 1.1 skrll } 6767 1.1 skrll 6768 1.1 skrll /* Note that for some reason, a spurious space is tacked 6769 1.1 skrll onto the end of the args in some (at least one anyway) 6770 1.1 skrll implementations, so strip it off if it exists. */ 6771 1.1.1.9 christos 6772 1.1 skrll { 6773 1.1 skrll char *command = elf_tdata (abfd)->core->command; 6774 1.1 skrll int n = strlen (command); 6775 1.1 skrll 6776 1.1 skrll if (0 < n && command[n - 1] == ' ') 6777 1.1.1.6 christos command[n - 1] = '\0'; 6778 1.1 skrll } 6779 1.1 skrll 6780 1.1 skrll return true; 6781 1.1 skrll } 6782 1.1 skrll #define ELF_ARCH bfd_arch_frv 6783 1.1.1.6 christos #define ELF_MACHINE_CODE EM_CYGNUS_FRV 6784 1.1 skrll #define ELF_MAXPAGESIZE 0x1000 6785 1.1.1.6 christos 6786 1.1 skrll #define TARGET_BIG_SYM frv_elf32_vec 6787 1.1.1.4 christos #define TARGET_BIG_NAME "elf32-frv" 6788 1.1 skrll 6789 1.1 skrll #define elf_info_to_howto frv_info_to_howto_rela 6790 1.1 skrll #define elf_backend_relocate_section elf32_frv_relocate_section 6791 1.1 skrll #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook 6792 1.1 skrll #define elf_backend_check_relocs elf32_frv_check_relocs 6793 1.1 skrll #define elf_backend_object_p elf32_frv_object_p 6794 1.1 skrll #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook 6795 1.1 skrll 6796 1.1 skrll #define elf_backend_stack_align 8 6797 1.1 skrll #define elf_backend_can_gc_sections 1 6798 1.1 skrll #define elf_backend_rela_normal 1 6799 1.1 skrll 6800 1.1 skrll #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup 6801 1.1 skrll #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup 6802 1.1 skrll #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags 6803 1.1 skrll #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data 6804 1.1 skrll #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data 6805 1.1 skrll 6806 1.1 skrll #define elf_backend_want_got_sym 1 6807 1.1 skrll #define elf_backend_got_header_size 0 6808 1.1 skrll #define elf_backend_want_got_plt 0 6809 1.1 skrll #define elf_backend_plt_readonly 1 6810 1.1.1.9 christos #define elf_backend_want_plt_sym 0 6811 1.1.1.6 christos #define elf_backend_plt_header_size 0 6812 1.1 skrll 6813 1.1 skrll #define elf_backend_finish_dynamic_sections \ 6814 1.1.1.6 christos elf32_frv_finish_dynamic_sections 6815 1.1.1.6 christos 6816 1.1 skrll #define elf_backend_grok_prstatus elf32_frv_grok_prstatus 6817 1.1 skrll #define elf_backend_grok_psinfo elf32_frv_grok_psinfo 6818 1.1 skrll 6819 1.1 skrll #define elf_backend_linux_prpsinfo32_ugid16 true 6820 1.1.1.6 christos 6821 1.1 skrll #include "elf32-target.h" 6822 1.1 skrll 6823 1.1 skrll #undef ELF_TARGET_ID 6824 1.1 skrll #define ELF_TARGET_ID FRV_ELF_DATA 6825 1.1 skrll #undef ELF_MAXPAGESIZE 6826 1.1 skrll #define ELF_MAXPAGESIZE 0x4000 6827 1.1 skrll 6828 1.1 skrll #undef TARGET_BIG_SYM 6829 1.1 skrll #define TARGET_BIG_SYM frv_elf32_fdpic_vec 6830 1.1 skrll #undef TARGET_BIG_NAME 6831 1.1 skrll #define TARGET_BIG_NAME "elf32-frvfdpic" 6832 1.1.1.11 christos #undef elf32_bed 6833 1.1.1.11 christos #define elf32_bed elf32_frvfdpic_bed 6834 1.1.1.11 christos 6835 1.1 skrll #undef elf_info_to_howto_rel 6836 1.1 skrll #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel 6837 1.1 skrll 6838 1.1 skrll #undef bfd_elf32_bfd_link_hash_table_create 6839 1.1 skrll #define bfd_elf32_bfd_link_hash_table_create \ 6840 1.1 skrll frvfdpic_elf_link_hash_table_create 6841 1.1 skrll #undef elf_backend_early_size_sections 6842 1.1.1.11 christos #define elf_backend_early_size_sections \ 6843 1.1.1.11 christos elf32_frvfdpic_early_size_sections 6844 1.1.1.11 christos 6845 1.1 skrll #undef elf_backend_create_dynamic_sections 6846 1.1 skrll #define elf_backend_create_dynamic_sections \ 6847 1.1 skrll elf32_frvfdpic_create_dynamic_sections 6848 1.1 skrll #undef elf_backend_adjust_dynamic_symbol 6849 1.1 skrll #define elf_backend_adjust_dynamic_symbol \ 6850 1.1 skrll elf32_frvfdpic_adjust_dynamic_symbol 6851 1.1 skrll #undef elf_backend_late_size_sections 6852 1.1 skrll #define elf_backend_late_size_sections \ 6853 1.1 skrll elf32_frvfdpic_late_size_sections 6854 1.1 skrll #undef bfd_elf32_bfd_relax_section 6855 1.1 skrll #define bfd_elf32_bfd_relax_section \ 6856 1.1 skrll elf32_frvfdpic_relax_section 6857 1.1 skrll #undef elf_backend_finish_dynamic_symbol 6858 1.1 skrll #define elf_backend_finish_dynamic_symbol \ 6859 1.1 skrll elf32_frvfdpic_finish_dynamic_symbol 6860 1.1 skrll #undef elf_backend_finish_dynamic_sections 6861 1.1 skrll #define elf_backend_finish_dynamic_sections \ 6862 1.1 skrll elf32_frvfdpic_finish_dynamic_sections 6863 1.1 skrll 6864 1.1 skrll #undef elf_backend_discard_info 6865 1.1 skrll #define elf_backend_discard_info \ 6866 1.1 skrll frvfdpic_elf_discard_info 6867 1.1 skrll #undef elf_backend_can_make_relative_eh_frame 6868 1.1 skrll #define elf_backend_can_make_relative_eh_frame \ 6869 1.1.1.6 christos frvfdpic_elf_use_relative_eh_frame 6870 1.1 skrll #undef elf_backend_can_make_lsda_relative_eh_frame 6871 1.1.1.6 christos #define elf_backend_can_make_lsda_relative_eh_frame \ 6872 1.1 skrll frvfdpic_elf_use_relative_eh_frame 6873 1.1 skrll #undef elf_backend_encode_eh_address 6874 1.1.1.6 christos #define elf_backend_encode_eh_address \ 6875 1.1 skrll frvfdpic_elf_encode_eh_address 6876 1.1 skrll 6877 1.1 skrll #undef elf_backend_may_use_rel_p 6878 1.1 skrll #define elf_backend_may_use_rel_p 1 6879 1.1 skrll #undef elf_backend_may_use_rela_p 6880 #define elf_backend_may_use_rela_p 1 6881 /* We use REL for dynamic relocations only. */ 6882 #undef elf_backend_default_use_rela_p 6883 #define elf_backend_default_use_rela_p 1 6884 6885 #undef elf_backend_omit_section_dynsym 6886 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym 6887 6888 #include "elf32-target.h" 6889