1 1.1 christos /* Motorola 68k series support for 32-bit ELF 2 1.1.1.13 christos Copyright (C) 1993-2025 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of BFD, the Binary File Descriptor library. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program; if not, write to the Free Software 18 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 1.1 christos MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #include "sysdep.h" 22 1.1 christos #include "bfd.h" 23 1.1 christos #include "bfdlink.h" 24 1.1 christos #include "libbfd.h" 25 1.1 christos #include "elf-bfd.h" 26 1.1 christos #include "elf/m68k.h" 27 1.1 christos #include "opcode/m68k.h" 28 1.1.1.9 christos #include "cpu-m68k.h" 29 1.1.1.9 christos #include "elf32-m68k.h" 30 1.1 christos 31 1.1.1.10 christos static bool 32 1.1.1.2 christos elf_m68k_discard_copies (struct elf_link_hash_entry *, void *); 33 1.1 christos 34 1.1.1.2 christos static reloc_howto_type howto_table[] = 35 1.1.1.2 christos { 36 1.1.1.10 christos HOWTO(R_68K_NONE, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", false, 0, 0x00000000,false), 37 1.1.1.10 christos HOWTO(R_68K_32, 0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", false, 0, 0xffffffff,false), 38 1.1.1.10 christos HOWTO(R_68K_16, 0, 2,16, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", false, 0, 0x0000ffff,false), 39 1.1.1.10 christos HOWTO(R_68K_8, 0, 1, 8, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", false, 0, 0x000000ff,false), 40 1.1.1.10 christos HOWTO(R_68K_PC32, 0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", false, 0, 0xffffffff,true), 41 1.1.1.10 christos HOWTO(R_68K_PC16, 0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", false, 0, 0x0000ffff,true), 42 1.1.1.10 christos HOWTO(R_68K_PC8, 0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", false, 0, 0x000000ff,true), 43 1.1.1.10 christos HOWTO(R_68K_GOT32, 0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", false, 0, 0xffffffff,true), 44 1.1.1.10 christos HOWTO(R_68K_GOT16, 0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", false, 0, 0x0000ffff,true), 45 1.1.1.10 christos HOWTO(R_68K_GOT8, 0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", false, 0, 0x000000ff,true), 46 1.1.1.10 christos HOWTO(R_68K_GOT32O, 0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", false, 0, 0xffffffff,false), 47 1.1.1.10 christos HOWTO(R_68K_GOT16O, 0, 2,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", false, 0, 0x0000ffff,false), 48 1.1.1.10 christos HOWTO(R_68K_GOT8O, 0, 1, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", false, 0, 0x000000ff,false), 49 1.1.1.10 christos HOWTO(R_68K_PLT32, 0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", false, 0, 0xffffffff,true), 50 1.1.1.10 christos HOWTO(R_68K_PLT16, 0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", false, 0, 0x0000ffff,true), 51 1.1.1.10 christos HOWTO(R_68K_PLT8, 0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", false, 0, 0x000000ff,true), 52 1.1.1.10 christos HOWTO(R_68K_PLT32O, 0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", false, 0, 0xffffffff,false), 53 1.1.1.10 christos HOWTO(R_68K_PLT16O, 0, 2,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", false, 0, 0x0000ffff,false), 54 1.1.1.10 christos HOWTO(R_68K_PLT8O, 0, 1, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", false, 0, 0x000000ff,false), 55 1.1.1.10 christos HOWTO(R_68K_COPY, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", false, 0, 0xffffffff,false), 56 1.1.1.10 christos HOWTO(R_68K_GLOB_DAT, 0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", false, 0, 0xffffffff,false), 57 1.1.1.10 christos HOWTO(R_68K_JMP_SLOT, 0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", false, 0, 0xffffffff,false), 58 1.1.1.10 christos HOWTO(R_68K_RELATIVE, 0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", false, 0, 0xffffffff,false), 59 1.1 christos /* GNU extension to record C++ vtable hierarchy. */ 60 1.1 christos HOWTO (R_68K_GNU_VTINHERIT, /* type */ 61 1.1 christos 0, /* rightshift */ 62 1.1.1.10 christos 4, /* size */ 63 1.1 christos 0, /* bitsize */ 64 1.1.1.10 christos false, /* pc_relative */ 65 1.1 christos 0, /* bitpos */ 66 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 67 1.1 christos NULL, /* special_function */ 68 1.1 christos "R_68K_GNU_VTINHERIT", /* name */ 69 1.1.1.10 christos false, /* partial_inplace */ 70 1.1 christos 0, /* src_mask */ 71 1.1 christos 0, /* dst_mask */ 72 1.1.1.10 christos false), 73 1.1 christos /* GNU extension to record C++ vtable member usage. */ 74 1.1 christos HOWTO (R_68K_GNU_VTENTRY, /* type */ 75 1.1 christos 0, /* rightshift */ 76 1.1.1.10 christos 4, /* size */ 77 1.1 christos 0, /* bitsize */ 78 1.1.1.10 christos false, /* pc_relative */ 79 1.1 christos 0, /* bitpos */ 80 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 81 1.1 christos _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 82 1.1 christos "R_68K_GNU_VTENTRY", /* name */ 83 1.1.1.10 christos false, /* partial_inplace */ 84 1.1 christos 0, /* src_mask */ 85 1.1 christos 0, /* dst_mask */ 86 1.1.1.10 christos false), 87 1.1 christos 88 1.1 christos /* TLS general dynamic variable reference. */ 89 1.1 christos HOWTO (R_68K_TLS_GD32, /* type */ 90 1.1 christos 0, /* rightshift */ 91 1.1.1.10 christos 4, /* size */ 92 1.1 christos 32, /* bitsize */ 93 1.1.1.10 christos false, /* pc_relative */ 94 1.1 christos 0, /* bitpos */ 95 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 96 1.1 christos bfd_elf_generic_reloc, /* special_function */ 97 1.1 christos "R_68K_TLS_GD32", /* name */ 98 1.1.1.10 christos false, /* partial_inplace */ 99 1.1 christos 0, /* src_mask */ 100 1.1 christos 0xffffffff, /* dst_mask */ 101 1.1.1.10 christos false), /* pcrel_offset */ 102 1.1 christos 103 1.1 christos HOWTO (R_68K_TLS_GD16, /* type */ 104 1.1 christos 0, /* rightshift */ 105 1.1.1.10 christos 2, /* size */ 106 1.1 christos 16, /* bitsize */ 107 1.1.1.10 christos false, /* pc_relative */ 108 1.1 christos 0, /* bitpos */ 109 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 110 1.1 christos bfd_elf_generic_reloc, /* special_function */ 111 1.1 christos "R_68K_TLS_GD16", /* name */ 112 1.1.1.10 christos false, /* partial_inplace */ 113 1.1 christos 0, /* src_mask */ 114 1.1 christos 0x0000ffff, /* dst_mask */ 115 1.1.1.10 christos false), /* pcrel_offset */ 116 1.1 christos 117 1.1 christos HOWTO (R_68K_TLS_GD8, /* type */ 118 1.1 christos 0, /* rightshift */ 119 1.1.1.10 christos 1, /* size */ 120 1.1 christos 8, /* bitsize */ 121 1.1.1.10 christos false, /* pc_relative */ 122 1.1 christos 0, /* bitpos */ 123 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 124 1.1 christos bfd_elf_generic_reloc, /* special_function */ 125 1.1 christos "R_68K_TLS_GD8", /* name */ 126 1.1.1.10 christos false, /* partial_inplace */ 127 1.1 christos 0, /* src_mask */ 128 1.1 christos 0x000000ff, /* dst_mask */ 129 1.1.1.10 christos false), /* pcrel_offset */ 130 1.1 christos 131 1.1 christos /* TLS local dynamic variable reference. */ 132 1.1 christos HOWTO (R_68K_TLS_LDM32, /* type */ 133 1.1 christos 0, /* rightshift */ 134 1.1.1.10 christos 4, /* size */ 135 1.1 christos 32, /* bitsize */ 136 1.1.1.10 christos false, /* pc_relative */ 137 1.1 christos 0, /* bitpos */ 138 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 139 1.1 christos bfd_elf_generic_reloc, /* special_function */ 140 1.1 christos "R_68K_TLS_LDM32", /* name */ 141 1.1.1.10 christos false, /* partial_inplace */ 142 1.1 christos 0, /* src_mask */ 143 1.1 christos 0xffffffff, /* dst_mask */ 144 1.1.1.10 christos false), /* pcrel_offset */ 145 1.1 christos 146 1.1 christos HOWTO (R_68K_TLS_LDM16, /* type */ 147 1.1 christos 0, /* rightshift */ 148 1.1.1.10 christos 2, /* size */ 149 1.1 christos 16, /* bitsize */ 150 1.1.1.10 christos false, /* pc_relative */ 151 1.1 christos 0, /* bitpos */ 152 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 153 1.1 christos bfd_elf_generic_reloc, /* special_function */ 154 1.1 christos "R_68K_TLS_LDM16", /* name */ 155 1.1.1.10 christos false, /* partial_inplace */ 156 1.1 christos 0, /* src_mask */ 157 1.1 christos 0x0000ffff, /* dst_mask */ 158 1.1.1.10 christos false), /* pcrel_offset */ 159 1.1 christos 160 1.1 christos HOWTO (R_68K_TLS_LDM8, /* type */ 161 1.1 christos 0, /* rightshift */ 162 1.1.1.10 christos 1, /* size */ 163 1.1 christos 8, /* bitsize */ 164 1.1.1.10 christos false, /* pc_relative */ 165 1.1 christos 0, /* bitpos */ 166 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 167 1.1 christos bfd_elf_generic_reloc, /* special_function */ 168 1.1 christos "R_68K_TLS_LDM8", /* name */ 169 1.1.1.10 christos false, /* partial_inplace */ 170 1.1 christos 0, /* src_mask */ 171 1.1 christos 0x000000ff, /* dst_mask */ 172 1.1.1.10 christos false), /* pcrel_offset */ 173 1.1 christos 174 1.1 christos HOWTO (R_68K_TLS_LDO32, /* type */ 175 1.1 christos 0, /* rightshift */ 176 1.1.1.10 christos 4, /* size */ 177 1.1 christos 32, /* bitsize */ 178 1.1.1.10 christos false, /* pc_relative */ 179 1.1 christos 0, /* bitpos */ 180 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 181 1.1 christos bfd_elf_generic_reloc, /* special_function */ 182 1.1 christos "R_68K_TLS_LDO32", /* name */ 183 1.1.1.10 christos false, /* partial_inplace */ 184 1.1 christos 0, /* src_mask */ 185 1.1 christos 0xffffffff, /* dst_mask */ 186 1.1.1.10 christos false), /* pcrel_offset */ 187 1.1 christos 188 1.1 christos HOWTO (R_68K_TLS_LDO16, /* type */ 189 1.1 christos 0, /* rightshift */ 190 1.1.1.10 christos 2, /* size */ 191 1.1 christos 16, /* bitsize */ 192 1.1.1.10 christos false, /* pc_relative */ 193 1.1 christos 0, /* bitpos */ 194 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 195 1.1 christos bfd_elf_generic_reloc, /* special_function */ 196 1.1 christos "R_68K_TLS_LDO16", /* name */ 197 1.1.1.10 christos false, /* partial_inplace */ 198 1.1 christos 0, /* src_mask */ 199 1.1 christos 0x0000ffff, /* dst_mask */ 200 1.1.1.10 christos false), /* pcrel_offset */ 201 1.1 christos 202 1.1 christos HOWTO (R_68K_TLS_LDO8, /* type */ 203 1.1 christos 0, /* rightshift */ 204 1.1.1.10 christos 1, /* size */ 205 1.1 christos 8, /* bitsize */ 206 1.1.1.10 christos false, /* pc_relative */ 207 1.1 christos 0, /* bitpos */ 208 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 209 1.1 christos bfd_elf_generic_reloc, /* special_function */ 210 1.1 christos "R_68K_TLS_LDO8", /* name */ 211 1.1.1.10 christos false, /* partial_inplace */ 212 1.1 christos 0, /* src_mask */ 213 1.1 christos 0x000000ff, /* dst_mask */ 214 1.1.1.10 christos false), /* pcrel_offset */ 215 1.1 christos 216 1.1 christos /* TLS initial execution variable reference. */ 217 1.1 christos HOWTO (R_68K_TLS_IE32, /* type */ 218 1.1 christos 0, /* rightshift */ 219 1.1.1.10 christos 4, /* size */ 220 1.1 christos 32, /* bitsize */ 221 1.1.1.10 christos false, /* pc_relative */ 222 1.1 christos 0, /* bitpos */ 223 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 224 1.1 christos bfd_elf_generic_reloc, /* special_function */ 225 1.1 christos "R_68K_TLS_IE32", /* name */ 226 1.1.1.10 christos false, /* partial_inplace */ 227 1.1 christos 0, /* src_mask */ 228 1.1 christos 0xffffffff, /* dst_mask */ 229 1.1.1.10 christos false), /* pcrel_offset */ 230 1.1 christos 231 1.1 christos HOWTO (R_68K_TLS_IE16, /* type */ 232 1.1 christos 0, /* rightshift */ 233 1.1.1.10 christos 2, /* size */ 234 1.1 christos 16, /* bitsize */ 235 1.1.1.10 christos false, /* pc_relative */ 236 1.1 christos 0, /* bitpos */ 237 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 238 1.1 christos bfd_elf_generic_reloc, /* special_function */ 239 1.1 christos "R_68K_TLS_IE16", /* name */ 240 1.1.1.10 christos false, /* partial_inplace */ 241 1.1 christos 0, /* src_mask */ 242 1.1 christos 0x0000ffff, /* dst_mask */ 243 1.1.1.10 christos false), /* pcrel_offset */ 244 1.1 christos 245 1.1 christos HOWTO (R_68K_TLS_IE8, /* type */ 246 1.1 christos 0, /* rightshift */ 247 1.1.1.10 christos 1, /* size */ 248 1.1 christos 8, /* bitsize */ 249 1.1.1.10 christos false, /* pc_relative */ 250 1.1 christos 0, /* bitpos */ 251 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 252 1.1 christos bfd_elf_generic_reloc, /* special_function */ 253 1.1 christos "R_68K_TLS_IE8", /* name */ 254 1.1.1.10 christos false, /* partial_inplace */ 255 1.1 christos 0, /* src_mask */ 256 1.1 christos 0x000000ff, /* dst_mask */ 257 1.1.1.10 christos false), /* pcrel_offset */ 258 1.1 christos 259 1.1 christos /* TLS local execution variable reference. */ 260 1.1 christos HOWTO (R_68K_TLS_LE32, /* type */ 261 1.1 christos 0, /* rightshift */ 262 1.1.1.10 christos 4, /* size */ 263 1.1 christos 32, /* bitsize */ 264 1.1.1.10 christos false, /* pc_relative */ 265 1.1 christos 0, /* bitpos */ 266 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 267 1.1 christos bfd_elf_generic_reloc, /* special_function */ 268 1.1 christos "R_68K_TLS_LE32", /* name */ 269 1.1.1.10 christos false, /* partial_inplace */ 270 1.1 christos 0, /* src_mask */ 271 1.1 christos 0xffffffff, /* dst_mask */ 272 1.1.1.10 christos false), /* pcrel_offset */ 273 1.1 christos 274 1.1 christos HOWTO (R_68K_TLS_LE16, /* type */ 275 1.1 christos 0, /* rightshift */ 276 1.1.1.10 christos 2, /* size */ 277 1.1 christos 16, /* bitsize */ 278 1.1.1.10 christos false, /* pc_relative */ 279 1.1 christos 0, /* bitpos */ 280 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 281 1.1 christos bfd_elf_generic_reloc, /* special_function */ 282 1.1 christos "R_68K_TLS_LE16", /* name */ 283 1.1.1.10 christos false, /* partial_inplace */ 284 1.1 christos 0, /* src_mask */ 285 1.1 christos 0x0000ffff, /* dst_mask */ 286 1.1.1.10 christos false), /* pcrel_offset */ 287 1.1 christos 288 1.1 christos HOWTO (R_68K_TLS_LE8, /* type */ 289 1.1 christos 0, /* rightshift */ 290 1.1.1.10 christos 1, /* size */ 291 1.1 christos 8, /* bitsize */ 292 1.1.1.10 christos false, /* pc_relative */ 293 1.1 christos 0, /* bitpos */ 294 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 295 1.1 christos bfd_elf_generic_reloc, /* special_function */ 296 1.1 christos "R_68K_TLS_LE8", /* name */ 297 1.1.1.10 christos false, /* partial_inplace */ 298 1.1 christos 0, /* src_mask */ 299 1.1 christos 0x000000ff, /* dst_mask */ 300 1.1.1.10 christos false), /* pcrel_offset */ 301 1.1 christos 302 1.1 christos /* TLS GD/LD dynamic relocations. */ 303 1.1 christos HOWTO (R_68K_TLS_DTPMOD32, /* type */ 304 1.1 christos 0, /* rightshift */ 305 1.1.1.10 christos 4, /* size */ 306 1.1 christos 32, /* bitsize */ 307 1.1.1.10 christos false, /* pc_relative */ 308 1.1 christos 0, /* bitpos */ 309 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 310 1.1 christos bfd_elf_generic_reloc, /* special_function */ 311 1.1 christos "R_68K_TLS_DTPMOD32", /* name */ 312 1.1.1.10 christos false, /* partial_inplace */ 313 1.1 christos 0, /* src_mask */ 314 1.1 christos 0xffffffff, /* dst_mask */ 315 1.1.1.10 christos false), /* pcrel_offset */ 316 1.1 christos 317 1.1 christos HOWTO (R_68K_TLS_DTPREL32, /* type */ 318 1.1 christos 0, /* rightshift */ 319 1.1.1.10 christos 4, /* size */ 320 1.1 christos 32, /* bitsize */ 321 1.1.1.10 christos false, /* pc_relative */ 322 1.1 christos 0, /* bitpos */ 323 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 324 1.1 christos bfd_elf_generic_reloc, /* special_function */ 325 1.1 christos "R_68K_TLS_DTPREL32", /* name */ 326 1.1.1.10 christos false, /* partial_inplace */ 327 1.1 christos 0, /* src_mask */ 328 1.1 christos 0xffffffff, /* dst_mask */ 329 1.1.1.10 christos false), /* pcrel_offset */ 330 1.1 christos 331 1.1 christos HOWTO (R_68K_TLS_TPREL32, /* type */ 332 1.1 christos 0, /* rightshift */ 333 1.1.1.10 christos 4, /* size */ 334 1.1 christos 32, /* bitsize */ 335 1.1.1.10 christos false, /* pc_relative */ 336 1.1 christos 0, /* bitpos */ 337 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 338 1.1 christos bfd_elf_generic_reloc, /* special_function */ 339 1.1 christos "R_68K_TLS_TPREL32", /* name */ 340 1.1.1.10 christos false, /* partial_inplace */ 341 1.1 christos 0, /* src_mask */ 342 1.1 christos 0xffffffff, /* dst_mask */ 343 1.1.1.10 christos false), /* pcrel_offset */ 344 1.1 christos }; 345 1.1 christos 346 1.1.1.10 christos static bool 347 1.1 christos rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) 348 1.1 christos { 349 1.1 christos unsigned int indx = ELF32_R_TYPE (dst->r_info); 350 1.1 christos 351 1.1 christos if (indx >= (unsigned int) R_68K_max) 352 1.1 christos { 353 1.1.1.7 christos /* xgettext:c-format */ 354 1.1.1.8 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 355 1.1.1.8 christos abfd, indx); 356 1.1.1.8 christos bfd_set_error (bfd_error_bad_value); 357 1.1.1.10 christos return false; 358 1.1 christos } 359 1.1 christos cache_ptr->howto = &howto_table[indx]; 360 1.1.1.10 christos return true; 361 1.1 christos } 362 1.1 christos 363 1.1 christos #define elf_info_to_howto rtype_to_howto 364 1.1 christos 365 1.1 christos static const struct 366 1.1 christos { 367 1.1 christos bfd_reloc_code_real_type bfd_val; 368 1.1 christos int elf_val; 369 1.1 christos } 370 1.1 christos reloc_map[] = 371 1.1 christos { 372 1.1 christos { BFD_RELOC_NONE, R_68K_NONE }, 373 1.1 christos { BFD_RELOC_32, R_68K_32 }, 374 1.1 christos { BFD_RELOC_16, R_68K_16 }, 375 1.1 christos { BFD_RELOC_8, R_68K_8 }, 376 1.1 christos { BFD_RELOC_32_PCREL, R_68K_PC32 }, 377 1.1 christos { BFD_RELOC_16_PCREL, R_68K_PC16 }, 378 1.1 christos { BFD_RELOC_8_PCREL, R_68K_PC8 }, 379 1.1 christos { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 }, 380 1.1 christos { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 }, 381 1.1 christos { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 }, 382 1.1 christos { BFD_RELOC_32_GOTOFF, R_68K_GOT32O }, 383 1.1 christos { BFD_RELOC_16_GOTOFF, R_68K_GOT16O }, 384 1.1 christos { BFD_RELOC_8_GOTOFF, R_68K_GOT8O }, 385 1.1 christos { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 }, 386 1.1 christos { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 }, 387 1.1 christos { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 }, 388 1.1 christos { BFD_RELOC_32_PLTOFF, R_68K_PLT32O }, 389 1.1 christos { BFD_RELOC_16_PLTOFF, R_68K_PLT16O }, 390 1.1 christos { BFD_RELOC_8_PLTOFF, R_68K_PLT8O }, 391 1.1 christos { BFD_RELOC_NONE, R_68K_COPY }, 392 1.1 christos { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT }, 393 1.1 christos { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT }, 394 1.1 christos { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE }, 395 1.1 christos { BFD_RELOC_CTOR, R_68K_32 }, 396 1.1 christos { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT }, 397 1.1 christos { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY }, 398 1.1 christos { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 }, 399 1.1 christos { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 }, 400 1.1 christos { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 }, 401 1.1 christos { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 }, 402 1.1 christos { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 }, 403 1.1 christos { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 }, 404 1.1 christos { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 }, 405 1.1 christos { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 }, 406 1.1 christos { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 }, 407 1.1 christos { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 }, 408 1.1 christos { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 }, 409 1.1 christos { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 }, 410 1.1 christos { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 }, 411 1.1 christos { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 }, 412 1.1 christos { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 }, 413 1.1 christos }; 414 1.1 christos 415 1.1 christos static reloc_howto_type * 416 1.1.1.2 christos reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 417 1.1.1.2 christos bfd_reloc_code_real_type code) 418 1.1 christos { 419 1.1 christos unsigned int i; 420 1.1 christos for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++) 421 1.1 christos { 422 1.1 christos if (reloc_map[i].bfd_val == code) 423 1.1 christos return &howto_table[reloc_map[i].elf_val]; 424 1.1 christos } 425 1.1 christos return 0; 426 1.1 christos } 427 1.1 christos 428 1.1 christos static reloc_howto_type * 429 1.1 christos reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) 430 1.1 christos { 431 1.1 christos unsigned int i; 432 1.1 christos 433 1.1 christos for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++) 434 1.1 christos if (howto_table[i].name != NULL 435 1.1 christos && strcasecmp (howto_table[i].name, r_name) == 0) 436 1.1 christos return &howto_table[i]; 437 1.1 christos 438 1.1 christos return NULL; 439 1.1 christos } 440 1.1 christos 441 1.1 christos #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup 442 1.1 christos #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup 443 1.1 christos #define ELF_ARCH bfd_arch_m68k 444 1.1 christos #define ELF_TARGET_ID M68K_ELF_DATA 445 1.1 christos 446 1.1 christos /* Functions for the m68k ELF linker. */ 448 1.1 christos 449 1.1 christos /* The name of the dynamic interpreter. This is put in the .interp 450 1.1 christos section. */ 451 1.1 christos 452 1.1 christos #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" 453 1.1 christos 454 1.1 christos /* Describes one of the various PLT styles. */ 455 1.1 christos 456 1.1 christos struct elf_m68k_plt_info 457 1.1 christos { 458 1.1 christos /* The size of each PLT entry. */ 459 1.1 christos bfd_vma size; 460 1.1 christos 461 1.1 christos /* The template for the first PLT entry. */ 462 1.1 christos const bfd_byte *plt0_entry; 463 1.1 christos 464 1.1 christos /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations. 465 1.1 christos The comments by each member indicate the value that the relocation 466 1.1 christos is against. */ 467 1.1 christos struct { 468 1.1 christos unsigned int got4; /* .got + 4 */ 469 1.1 christos unsigned int got8; /* .got + 8 */ 470 1.1 christos } plt0_relocs; 471 1.1 christos 472 1.1 christos /* The template for a symbol's PLT entry. */ 473 1.1 christos const bfd_byte *symbol_entry; 474 1.1 christos 475 1.1 christos /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations. 476 1.1 christos The comments by each member indicate the value that the relocation 477 1.1 christos is against. */ 478 1.1 christos struct { 479 1.1 christos unsigned int got; /* the symbol's .got.plt entry */ 480 1.1 christos unsigned int plt; /* .plt */ 481 1.1 christos } symbol_relocs; 482 1.1 christos 483 1.1 christos /* The offset of the resolver stub from the start of SYMBOL_ENTRY. 484 1.1 christos The stub starts with "move.l #relocoffset,%d0". */ 485 1.1 christos bfd_vma symbol_resolve_entry; 486 1.1 christos }; 487 1.1 christos 488 1.1 christos /* The size in bytes of an entry in the procedure linkage table. */ 489 1.1 christos 490 1.1 christos #define PLT_ENTRY_SIZE 20 491 1.1 christos 492 1.1 christos /* The first entry in a procedure linkage table looks like this. See 493 1.1 christos the SVR4 ABI m68k supplement to see how this works. */ 494 1.1 christos 495 1.1 christos static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] = 496 1.1 christos { 497 1.1 christos 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ 498 1.1 christos 0, 0, 0, 2, /* + (.got + 4) - . */ 499 1.1 christos 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */ 500 1.1 christos 0, 0, 0, 2, /* + (.got + 8) - . */ 501 1.1 christos 0, 0, 0, 0 /* pad out to 20 bytes. */ 502 1.1 christos }; 503 1.1 christos 504 1.1 christos /* Subsequent entries in a procedure linkage table look like this. */ 505 1.1 christos 506 1.1 christos static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] = 507 1.1 christos { 508 1.1 christos 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */ 509 1.1 christos 0, 0, 0, 2, /* + (.got.plt entry) - . */ 510 1.1 christos 0x2f, 0x3c, /* move.l #offset,-(%sp) */ 511 1.1 christos 0, 0, 0, 0, /* + reloc index */ 512 1.1 christos 0x60, 0xff, /* bra.l .plt */ 513 1.1 christos 0, 0, 0, 0 /* + .plt - . */ 514 1.1 christos }; 515 1.1.1.7 christos 516 1.1.1.7 christos static const struct elf_m68k_plt_info elf_m68k_plt_info = 517 1.1 christos { 518 1.1 christos PLT_ENTRY_SIZE, 519 1.1 christos elf_m68k_plt0_entry, { 4, 12 }, 520 1.1 christos elf_m68k_plt_entry, { 4, 16 }, 8 521 1.1 christos }; 522 1.1 christos 523 1.1 christos #define ISAB_PLT_ENTRY_SIZE 24 524 1.1 christos 525 1.1 christos static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] = 526 1.1.1.8 christos { 527 1.1.1.8 christos 0x20, 0x3c, /* move.l #offset,%d0 */ 528 1.1 christos 0, 0, 0, 0, /* + (.got + 4) - . */ 529 1.1.1.8 christos 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */ 530 1.1.1.8 christos 0x20, 0x3c, /* move.l #offset,%d0 */ 531 1.1 christos 0, 0, 0, 0, /* + (.got + 8) - . */ 532 1.1.1.8 christos 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ 533 1.1 christos 0x4e, 0xd0, /* jmp (%a0) */ 534 1.1 christos 0x4e, 0x71 /* nop */ 535 1.1 christos }; 536 1.1 christos 537 1.1 christos /* Subsequent entries in a procedure linkage table look like this. */ 538 1.1 christos 539 1.1 christos static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] = 540 1.1.1.8 christos { 541 1.1.1.8 christos 0x20, 0x3c, /* move.l #offset,%d0 */ 542 1.1 christos 0, 0, 0, 0, /* + (.got.plt entry) - . */ 543 1.1.1.8 christos 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ 544 1.1.1.8 christos 0x4e, 0xd0, /* jmp (%a0) */ 545 1.1.1.8 christos 0x2f, 0x3c, /* move.l #offset,-(%sp) */ 546 1.1.1.8 christos 0, 0, 0, 0, /* + reloc index */ 547 1.1.1.8 christos 0x60, 0xff, /* bra.l .plt */ 548 1.1 christos 0, 0, 0, 0 /* + .plt - . */ 549 1.1 christos }; 550 1.1.1.7 christos 551 1.1.1.7 christos static const struct elf_m68k_plt_info elf_isab_plt_info = 552 1.1 christos { 553 1.1 christos ISAB_PLT_ENTRY_SIZE, 554 1.1 christos elf_isab_plt0_entry, { 2, 12 }, 555 1.1 christos elf_isab_plt_entry, { 2, 20 }, 12 556 1.1 christos }; 557 1.1 christos 558 1.1 christos #define ISAC_PLT_ENTRY_SIZE 24 559 1.1 christos 560 1.1 christos static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] = 561 1.1 christos { 562 1.1 christos 0x20, 0x3c, /* move.l #offset,%d0 */ 563 1.1 christos 0, 0, 0, 0, /* replaced with .got + 4 - . */ 564 1.1 christos 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */ 565 1.1 christos 0x20, 0x3c, /* move.l #offset,%d0 */ 566 1.1 christos 0, 0, 0, 0, /* replaced with .got + 8 - . */ 567 1.1 christos 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ 568 1.1 christos 0x4e, 0xd0, /* jmp (%a0) */ 569 1.1 christos 0x4e, 0x71 /* nop */ 570 1.1 christos }; 571 1.1 christos 572 1.1 christos /* Subsequent entries in a procedure linkage table look like this. */ 573 1.1 christos 574 1.1 christos static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] = 575 1.1 christos { 576 1.1 christos 0x20, 0x3c, /* move.l #offset,%d0 */ 577 1.1 christos 0, 0, 0, 0, /* replaced with (.got entry) - . */ 578 1.1 christos 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ 579 1.1 christos 0x4e, 0xd0, /* jmp (%a0) */ 580 1.1 christos 0x2f, 0x3c, /* move.l #offset,-(%sp) */ 581 1.1 christos 0, 0, 0, 0, /* replaced with offset into relocation table */ 582 1.1.1.8 christos 0x61, 0xff, /* bsr.l .plt */ 583 1.1 christos 0, 0, 0, 0 /* replaced with .plt - . */ 584 1.1 christos }; 585 1.1.1.7 christos 586 1.1.1.7 christos static const struct elf_m68k_plt_info elf_isac_plt_info = 587 1.1 christos { 588 1.1 christos ISAC_PLT_ENTRY_SIZE, 589 1.1 christos elf_isac_plt0_entry, { 2, 12}, 590 1.1 christos elf_isac_plt_entry, { 2, 20 }, 12 591 1.1 christos }; 592 1.1 christos 593 1.1 christos #define CPU32_PLT_ENTRY_SIZE 24 594 1.1 christos /* Procedure linkage table entries for the cpu32 */ 595 1.1 christos static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] = 596 1.1 christos { 597 1.1.1.8 christos 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ 598 1.1 christos 0, 0, 0, 2, /* + (.got + 4) - . */ 599 1.1.1.8 christos 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ 600 1.1.1.8 christos 0, 0, 0, 2, /* + (.got + 8) - . */ 601 1.1.1.8 christos 0x4e, 0xd1, /* jmp %a1@ */ 602 1.1 christos 0, 0, 0, 0, /* pad out to 24 bytes. */ 603 1.1 christos 0, 0 604 1.1 christos }; 605 1.1 christos 606 1.1 christos static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] = 607 1.1 christos { 608 1.1.1.8 christos 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ 609 1.1.1.8 christos 0, 0, 0, 2, /* + (.got.plt entry) - . */ 610 1.1.1.8 christos 0x4e, 0xd1, /* jmp %a1@ */ 611 1.1.1.8 christos 0x2f, 0x3c, /* move.l #offset,-(%sp) */ 612 1.1.1.8 christos 0, 0, 0, 0, /* + reloc index */ 613 1.1.1.8 christos 0x60, 0xff, /* bra.l .plt */ 614 1.1 christos 0, 0, 0, 0, /* + .plt - . */ 615 1.1 christos 0, 0 616 1.1 christos }; 617 1.1.1.7 christos 618 1.1.1.7 christos static const struct elf_m68k_plt_info elf_cpu32_plt_info = 619 1.1 christos { 620 1.1 christos CPU32_PLT_ENTRY_SIZE, 621 1.1 christos elf_cpu32_plt0_entry, { 4, 12 }, 622 1.1 christos elf_cpu32_plt_entry, { 4, 18 }, 10 623 1.1 christos }; 624 1.1 christos 625 1.1 christos /* The m68k linker needs to keep track of the number of relocs that it 626 1.1 christos decides to copy in check_relocs for each symbol. This is so that it 627 1.1 christos can discard PC relative relocs if it doesn't need them when linking 628 1.1 christos with -Bsymbolic. We store the information in a field extending the 629 1.1 christos regular ELF linker hash table. */ 630 1.1 christos 631 1.1 christos /* This structure keeps track of the number of PC relative relocs we have 632 1.1 christos copied for a given symbol. */ 633 1.1 christos 634 1.1 christos struct elf_m68k_pcrel_relocs_copied 635 1.1 christos { 636 1.1 christos /* Next section. */ 637 1.1 christos struct elf_m68k_pcrel_relocs_copied *next; 638 1.1 christos /* A section in dynobj. */ 639 1.1 christos asection *section; 640 1.1 christos /* Number of relocs copied in this section. */ 641 1.1 christos bfd_size_type count; 642 1.1 christos }; 643 1.1 christos 644 1.1 christos /* Forward declaration. */ 645 1.1 christos struct elf_m68k_got_entry; 646 1.1 christos 647 1.1 christos /* m68k ELF linker hash entry. */ 648 1.1 christos 649 1.1 christos struct elf_m68k_link_hash_entry 650 1.1 christos { 651 1.1 christos struct elf_link_hash_entry root; 652 1.1 christos 653 1.1 christos /* Number of PC relative relocs copied for this symbol. */ 654 1.1 christos struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied; 655 1.1 christos 656 1.1 christos /* Key to got_entries. */ 657 1.1 christos unsigned long got_entry_key; 658 1.1 christos 659 1.1 christos /* List of GOT entries for this symbol. This list is build during 660 1.1 christos offset finalization and is used within elf_m68k_finish_dynamic_symbol 661 1.1 christos to traverse all GOT entries for a particular symbol. 662 1.1 christos 663 1.1 christos ??? We could've used root.got.glist field instead, but having 664 1.1 christos a separate field is cleaner. */ 665 1.1 christos struct elf_m68k_got_entry *glist; 666 1.1 christos }; 667 1.1 christos 668 1.1 christos #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent)) 669 1.1 christos 670 1.1 christos /* Key part of GOT entry in hashtable. */ 671 1.1 christos struct elf_m68k_got_entry_key 672 1.1 christos { 673 1.1 christos /* BFD in which this symbol was defined. NULL for global symbols. */ 674 1.1 christos const bfd *bfd; 675 1.1 christos 676 1.1 christos /* Symbol index. Either local symbol index or h->got_entry_key. */ 677 1.1 christos unsigned long symndx; 678 1.1 christos 679 1.1 christos /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32}, 680 1.1 christos R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}. 681 1.1 christos 682 1.1 christos From perspective of hashtable key, only elf_m68k_got_reloc_type (type) 683 1.1 christos matters. That is, we distinguish between, say, R_68K_GOT16O 684 1.1 christos and R_68K_GOT32O when allocating offsets, but they are considered to be 685 1.1 christos the same when searching got->entries. */ 686 1.1 christos enum elf_m68k_reloc_type type; 687 1.1 christos }; 688 1.1 christos 689 1.1 christos /* Size of the GOT offset suitable for relocation. */ 690 1.1 christos enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST }; 691 1.1 christos 692 1.1 christos /* Entry of the GOT. */ 693 1.1 christos struct elf_m68k_got_entry 694 1.1 christos { 695 1.1 christos /* GOT entries are put into a got->entries hashtable. This is the key. */ 696 1.1 christos struct elf_m68k_got_entry_key key_; 697 1.1 christos 698 1.1 christos /* GOT entry data. We need s1 before offset finalization and s2 after. */ 699 1.1 christos union 700 1.1 christos { 701 1.1 christos struct 702 1.1.1.8 christos { 703 1.1 christos /* Number of times this entry is referenced. */ 704 1.1 christos bfd_vma refcount; 705 1.1 christos } s1; 706 1.1 christos 707 1.1 christos struct 708 1.1 christos { 709 1.1.1.8 christos /* Offset from the start of .got section. To calculate offset relative 710 1.1 christos to GOT pointer one should subtract got->offset from this value. */ 711 1.1 christos bfd_vma offset; 712 1.1 christos 713 1.1 christos /* Pointer to the next GOT entry for this global symbol. 714 1.1 christos Symbols have at most one entry in one GOT, but might 715 1.1 christos have entries in more than one GOT. 716 1.1 christos Root of this list is h->glist. 717 1.1 christos NULL for local symbols. */ 718 1.1 christos struct elf_m68k_got_entry *next; 719 1.1 christos } s2; 720 1.1 christos } u; 721 1.1 christos }; 722 1.1 christos 723 1.1 christos /* Return representative type for relocation R_TYPE. 724 1.1 christos This is used to avoid enumerating many relocations in comparisons, 725 1.1 christos switches etc. */ 726 1.1 christos 727 1.1 christos static enum elf_m68k_reloc_type 728 1.1 christos elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type) 729 1.1 christos { 730 1.1 christos switch (r_type) 731 1.1 christos { 732 1.1 christos /* In most cases R_68K_GOTx relocations require the very same 733 1.1 christos handling as R_68K_GOT32O relocation. In cases when we need 734 1.1 christos to distinguish between the two, we use explicitly compare against 735 1.1 christos r_type. */ 736 1.1 christos case R_68K_GOT32: 737 1.1 christos case R_68K_GOT16: 738 1.1 christos case R_68K_GOT8: 739 1.1 christos case R_68K_GOT32O: 740 1.1 christos case R_68K_GOT16O: 741 1.1 christos case R_68K_GOT8O: 742 1.1 christos return R_68K_GOT32O; 743 1.1 christos 744 1.1 christos case R_68K_TLS_GD32: 745 1.1 christos case R_68K_TLS_GD16: 746 1.1 christos case R_68K_TLS_GD8: 747 1.1 christos return R_68K_TLS_GD32; 748 1.1 christos 749 1.1 christos case R_68K_TLS_LDM32: 750 1.1 christos case R_68K_TLS_LDM16: 751 1.1 christos case R_68K_TLS_LDM8: 752 1.1 christos return R_68K_TLS_LDM32; 753 1.1 christos 754 1.1 christos case R_68K_TLS_IE32: 755 1.1 christos case R_68K_TLS_IE16: 756 1.1 christos case R_68K_TLS_IE8: 757 1.1 christos return R_68K_TLS_IE32; 758 1.1 christos 759 1.1.1.10 christos default: 760 1.1 christos BFD_ASSERT (false); 761 1.1 christos return 0; 762 1.1 christos } 763 1.1 christos } 764 1.1 christos 765 1.1 christos /* Return size of the GOT entry offset for relocation R_TYPE. */ 766 1.1 christos 767 1.1 christos static enum elf_m68k_got_offset_size 768 1.1 christos elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type) 769 1.1 christos { 770 1.1 christos switch (r_type) 771 1.1 christos { 772 1.1 christos case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8: 773 1.1 christos case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32: 774 1.1 christos case R_68K_TLS_IE32: 775 1.1 christos return R_32; 776 1.1 christos 777 1.1 christos case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16: 778 1.1 christos case R_68K_TLS_IE16: 779 1.1 christos return R_16; 780 1.1 christos 781 1.1 christos case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8: 782 1.1 christos case R_68K_TLS_IE8: 783 1.1 christos return R_8; 784 1.1 christos 785 1.1.1.10 christos default: 786 1.1 christos BFD_ASSERT (false); 787 1.1 christos return 0; 788 1.1 christos } 789 1.1 christos } 790 1.1 christos 791 1.1 christos /* Return number of GOT entries we need to allocate in GOT for 792 1.1 christos relocation R_TYPE. */ 793 1.1 christos 794 1.1 christos static bfd_vma 795 1.1 christos elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type) 796 1.1 christos { 797 1.1 christos switch (elf_m68k_reloc_got_type (r_type)) 798 1.1 christos { 799 1.1 christos case R_68K_GOT32O: 800 1.1 christos case R_68K_TLS_IE32: 801 1.1 christos return 1; 802 1.1 christos 803 1.1 christos case R_68K_TLS_GD32: 804 1.1 christos case R_68K_TLS_LDM32: 805 1.1 christos return 2; 806 1.1 christos 807 1.1.1.10 christos default: 808 1.1 christos BFD_ASSERT (false); 809 1.1 christos return 0; 810 1.1 christos } 811 1.1 christos } 812 1.1 christos 813 1.1 christos /* Return TRUE if relocation R_TYPE is a TLS one. */ 814 1.1.1.10 christos 815 1.1 christos static bool 816 1.1 christos elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type) 817 1.1 christos { 818 1.1 christos switch (r_type) 819 1.1 christos { 820 1.1 christos case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8: 821 1.1 christos case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8: 822 1.1 christos case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8: 823 1.1 christos case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8: 824 1.1 christos case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8: 825 1.1.1.10 christos case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32: 826 1.1 christos return true; 827 1.1 christos 828 1.1.1.10 christos default: 829 1.1 christos return false; 830 1.1 christos } 831 1.1 christos } 832 1.1 christos 833 1.1 christos /* Data structure representing a single GOT. */ 834 1.1 christos struct elf_m68k_got 835 1.1 christos { 836 1.1 christos /* Hashtable of 'struct elf_m68k_got_entry's. 837 1.1 christos Starting size of this table is the maximum number of 838 1.1 christos R_68K_GOT8O entries. */ 839 1.1 christos htab_t entries; 840 1.1 christos 841 1.1 christos /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require 842 1.1 christos several GOT slots. 843 1.1 christos 844 1.1 christos n_slots[R_8] is the count of R_8 slots in this GOT. 845 1.1 christos n_slots[R_16] is the cumulative count of R_8 and R_16 slots 846 1.1 christos in this GOT. 847 1.1 christos n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots 848 1.1 christos in this GOT. This is the total number of slots. */ 849 1.1 christos bfd_vma n_slots[R_LAST]; 850 1.1 christos 851 1.1 christos /* Number of local (entry->key_.h == NULL) slots in this GOT. 852 1.1 christos This is only used to properly calculate size of .rela.got section; 853 1.1 christos see elf_m68k_partition_multi_got. */ 854 1.1 christos bfd_vma local_n_slots; 855 1.1 christos 856 1.1 christos /* Offset of this GOT relative to beginning of .got section. */ 857 1.1 christos bfd_vma offset; 858 1.1 christos }; 859 1.1 christos 860 1.1 christos /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */ 861 1.1 christos struct elf_m68k_bfd2got_entry 862 1.1 christos { 863 1.1 christos /* BFD. */ 864 1.1 christos const bfd *bfd; 865 1.1 christos 866 1.1 christos /* Assigned GOT. Before partitioning multi-GOT each BFD has its own 867 1.1 christos GOT structure. After partitioning several BFD's might [and often do] 868 1.1 christos share a single GOT. */ 869 1.1 christos struct elf_m68k_got *got; 870 1.1 christos }; 871 1.1 christos 872 1.1 christos /* The main data structure holding all the pieces. */ 873 1.1 christos struct elf_m68k_multi_got 874 1.1 christos { 875 1.1 christos /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry 876 1.1 christos here, then it doesn't need a GOT (this includes the case of a BFD 877 1.1 christos having an empty GOT). 878 1.1 christos 879 1.1 christos ??? This hashtable can be replaced by an array indexed by bfd->id. */ 880 1.1 christos htab_t bfd2got; 881 1.1 christos 882 1.1 christos /* Next symndx to assign a global symbol. 883 1.1 christos h->got_entry_key is initialized from this counter. */ 884 1.1 christos unsigned long global_symndx; 885 1.1 christos }; 886 1.1 christos 887 1.1 christos /* m68k ELF linker hash table. */ 888 1.1 christos 889 1.1 christos struct elf_m68k_link_hash_table 890 1.1 christos { 891 1.1 christos struct elf_link_hash_table root; 892 1.1 christos 893 1.1 christos /* The PLT format used by this link, or NULL if the format has not 894 1.1 christos yet been chosen. */ 895 1.1 christos const struct elf_m68k_plt_info *plt_info; 896 1.1 christos 897 1.1 christos /* True, if GP is loaded within each function which uses it. 898 1.1.1.10 christos Set to TRUE when GOT negative offsets or multi-GOT is enabled. */ 899 1.1 christos bool local_gp_p; 900 1.1 christos 901 1.1.1.10 christos /* Switch controlling use of negative offsets to double the size of GOTs. */ 902 1.1 christos bool use_neg_got_offsets_p; 903 1.1 christos 904 1.1.1.10 christos /* Switch controlling generation of multiple GOTs. */ 905 1.1 christos bool allow_multigot_p; 906 1.1 christos 907 1.1 christos /* Multi-GOT data structure. */ 908 1.1 christos struct elf_m68k_multi_got multi_got_; 909 1.1 christos }; 910 1.1 christos 911 1.1 christos /* Get the m68k ELF linker hash table from a link_info structure. */ 912 1.1 christos 913 1.1.1.9 christos #define elf_m68k_hash_table(p) \ 914 1.1.1.9 christos ((is_elf_hash_table ((p)->hash) \ 915 1.1.1.9 christos && elf_hash_table_id (elf_hash_table (p)) == M68K_ELF_DATA) \ 916 1.1 christos ? (struct elf_m68k_link_hash_table *) (p)->hash : NULL) 917 1.1 christos 918 1.1 christos /* Shortcut to multi-GOT data. */ 919 1.1 christos #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_) 920 1.1 christos 921 1.1 christos /* Create an entry in an m68k ELF linker hash table. */ 922 1.1 christos 923 1.1 christos static struct bfd_hash_entry * 924 1.1 christos elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry, 925 1.1 christos struct bfd_hash_table *table, 926 1.1 christos const char *string) 927 1.1 christos { 928 1.1 christos struct bfd_hash_entry *ret = entry; 929 1.1 christos 930 1.1 christos /* Allocate the structure if it has not already been allocated by a 931 1.1 christos subclass. */ 932 1.1 christos if (ret == NULL) 933 1.1 christos ret = bfd_hash_allocate (table, 934 1.1 christos sizeof (struct elf_m68k_link_hash_entry)); 935 1.1 christos if (ret == NULL) 936 1.1 christos return ret; 937 1.1 christos 938 1.1 christos /* Call the allocation method of the superclass. */ 939 1.1 christos ret = _bfd_elf_link_hash_newfunc (ret, table, string); 940 1.1 christos if (ret != NULL) 941 1.1 christos { 942 1.1 christos elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL; 943 1.1 christos elf_m68k_hash_entry (ret)->got_entry_key = 0; 944 1.1 christos elf_m68k_hash_entry (ret)->glist = NULL; 945 1.1 christos } 946 1.1 christos 947 1.1 christos return ret; 948 1.1 christos } 949 1.1.1.4 christos 950 1.1.1.4 christos /* Destroy an m68k ELF linker hash table. */ 951 1.1.1.4 christos 952 1.1.1.4 christos static void 953 1.1.1.4 christos elf_m68k_link_hash_table_free (bfd *obfd) 954 1.1.1.4 christos { 955 1.1.1.4 christos struct elf_m68k_link_hash_table *htab; 956 1.1.1.4 christos 957 1.1.1.4 christos htab = (struct elf_m68k_link_hash_table *) obfd->link.hash; 958 1.1.1.4 christos 959 1.1.1.4 christos if (htab->multi_got_.bfd2got != NULL) 960 1.1.1.4 christos { 961 1.1.1.4 christos htab_delete (htab->multi_got_.bfd2got); 962 1.1.1.4 christos htab->multi_got_.bfd2got = NULL; 963 1.1.1.4 christos } 964 1.1.1.4 christos _bfd_elf_link_hash_table_free (obfd); 965 1.1.1.4 christos } 966 1.1 christos 967 1.1 christos /* Create an m68k ELF linker hash table. */ 968 1.1 christos 969 1.1 christos static struct bfd_link_hash_table * 970 1.1 christos elf_m68k_link_hash_table_create (bfd *abfd) 971 1.1 christos { 972 1.1.1.9 christos struct elf_m68k_link_hash_table *ret; 973 1.1 christos size_t amt = sizeof (struct elf_m68k_link_hash_table); 974 1.1.1.2 christos 975 1.1 christos ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt); 976 1.1 christos if (ret == (struct elf_m68k_link_hash_table *) NULL) 977 1.1 christos return NULL; 978 1.1 christos 979 1.1 christos if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, 980 1.1.1.12 christos elf_m68k_link_hash_newfunc, 981 1.1 christos sizeof (struct elf_m68k_link_hash_entry))) 982 1.1 christos { 983 1.1 christos free (ret); 984 1.1 christos return NULL; 985 1.1.1.4 christos } 986 1.1 christos ret->root.root.hash_table_free = elf_m68k_link_hash_table_free; 987 1.1 christos 988 1.1 christos ret->multi_got_.global_symndx = 1; 989 1.1 christos 990 1.1 christos return &ret->root.root; 991 1.1 christos } 992 1.1 christos 993 1.1 christos /* Set the right machine number. */ 994 1.1.1.10 christos 995 1.1 christos static bool 996 1.1 christos elf32_m68k_object_p (bfd *abfd) 997 1.1 christos { 998 1.1 christos unsigned int mach = 0; 999 1.1 christos unsigned features = 0; 1000 1.1 christos flagword eflags = elf_elfheader (abfd)->e_flags; 1001 1.1 christos 1002 1.1 christos if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) 1003 1.1 christos features |= m68000; 1004 1.1 christos else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) 1005 1.1 christos features |= cpu32; 1006 1.1 christos else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) 1007 1.1 christos features |= fido_a; 1008 1.1 christos else 1009 1.1 christos { 1010 1.1 christos switch (eflags & EF_M68K_CF_ISA_MASK) 1011 1.1 christos { 1012 1.1 christos case EF_M68K_CF_ISA_A_NODIV: 1013 1.1 christos features |= mcfisa_a; 1014 1.1 christos break; 1015 1.1 christos case EF_M68K_CF_ISA_A: 1016 1.1 christos features |= mcfisa_a|mcfhwdiv; 1017 1.1 christos break; 1018 1.1 christos case EF_M68K_CF_ISA_A_PLUS: 1019 1.1 christos features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp; 1020 1.1 christos break; 1021 1.1 christos case EF_M68K_CF_ISA_B_NOUSP: 1022 1.1 christos features |= mcfisa_a|mcfisa_b|mcfhwdiv; 1023 1.1 christos break; 1024 1.1 christos case EF_M68K_CF_ISA_B: 1025 1.1 christos features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp; 1026 1.1 christos break; 1027 1.1 christos case EF_M68K_CF_ISA_C: 1028 1.1 christos features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp; 1029 1.1 christos break; 1030 1.1 christos case EF_M68K_CF_ISA_C_NODIV: 1031 1.1 christos features |= mcfisa_a|mcfisa_c|mcfusp; 1032 1.1 christos break; 1033 1.1 christos } 1034 1.1 christos switch (eflags & EF_M68K_CF_MAC_MASK) 1035 1.1 christos { 1036 1.1 christos case EF_M68K_CF_MAC: 1037 1.1 christos features |= mcfmac; 1038 1.1 christos break; 1039 1.1 christos case EF_M68K_CF_EMAC: 1040 1.1 christos features |= mcfemac; 1041 1.1 christos break; 1042 1.1 christos } 1043 1.1 christos if (eflags & EF_M68K_CF_FLOAT) 1044 1.1 christos features |= cfloat; 1045 1.1 christos } 1046 1.1 christos 1047 1.1 christos mach = bfd_m68k_features_to_mach (features); 1048 1.1 christos bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach); 1049 1.1.1.10 christos 1050 1.1 christos return true; 1051 1.1 christos } 1052 1.1 christos 1053 1.1 christos /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag 1054 1.1 christos field based on the machine number. */ 1055 1.1.1.10 christos 1056 1.1.1.9 christos static bool 1057 1.1 christos elf_m68k_final_write_processing (bfd *abfd) 1058 1.1 christos { 1059 1.1 christos int mach = bfd_get_mach (abfd); 1060 1.1 christos unsigned long e_flags = elf_elfheader (abfd)->e_flags; 1061 1.1 christos 1062 1.1 christos if (!e_flags) 1063 1.1 christos { 1064 1.1 christos unsigned int arch_mask; 1065 1.1 christos 1066 1.1 christos arch_mask = bfd_m68k_mach_to_features (mach); 1067 1.1 christos 1068 1.1 christos if (arch_mask & m68000) 1069 1.1 christos e_flags = EF_M68K_M68000; 1070 1.1 christos else if (arch_mask & cpu32) 1071 1.1 christos e_flags = EF_M68K_CPU32; 1072 1.1 christos else if (arch_mask & fido_a) 1073 1.1 christos e_flags = EF_M68K_FIDO; 1074 1.1 christos else 1075 1.1 christos { 1076 1.1 christos switch (arch_mask 1077 1.1 christos & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp)) 1078 1.1 christos { 1079 1.1 christos case mcfisa_a: 1080 1.1 christos e_flags |= EF_M68K_CF_ISA_A_NODIV; 1081 1.1 christos break; 1082 1.1 christos case mcfisa_a | mcfhwdiv: 1083 1.1 christos e_flags |= EF_M68K_CF_ISA_A; 1084 1.1 christos break; 1085 1.1 christos case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp: 1086 1.1 christos e_flags |= EF_M68K_CF_ISA_A_PLUS; 1087 1.1 christos break; 1088 1.1 christos case mcfisa_a | mcfisa_b | mcfhwdiv: 1089 1.1 christos e_flags |= EF_M68K_CF_ISA_B_NOUSP; 1090 1.1 christos break; 1091 1.1 christos case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp: 1092 1.1 christos e_flags |= EF_M68K_CF_ISA_B; 1093 1.1 christos break; 1094 1.1 christos case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp: 1095 1.1 christos e_flags |= EF_M68K_CF_ISA_C; 1096 1.1 christos break; 1097 1.1 christos case mcfisa_a | mcfisa_c | mcfusp: 1098 1.1 christos e_flags |= EF_M68K_CF_ISA_C_NODIV; 1099 1.1 christos break; 1100 1.1 christos } 1101 1.1 christos if (arch_mask & mcfmac) 1102 1.1 christos e_flags |= EF_M68K_CF_MAC; 1103 1.1 christos else if (arch_mask & mcfemac) 1104 1.1 christos e_flags |= EF_M68K_CF_EMAC; 1105 1.1 christos if (arch_mask & cfloat) 1106 1.1 christos e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E; 1107 1.1 christos } 1108 1.1 christos elf_elfheader (abfd)->e_flags = e_flags; 1109 1.1.1.9 christos } 1110 1.1 christos return _bfd_elf_final_write_processing (abfd); 1111 1.1 christos } 1112 1.1 christos 1113 1.1 christos /* Keep m68k-specific flags in the ELF header. */ 1114 1.1.1.10 christos 1115 1.1.1.2 christos static bool 1116 1.1 christos elf32_m68k_set_private_flags (bfd *abfd, flagword flags) 1117 1.1 christos { 1118 1.1.1.10 christos elf_elfheader (abfd)->e_flags = flags; 1119 1.1.1.10 christos elf_flags_init (abfd) = true; 1120 1.1 christos return true; 1121 1.1 christos } 1122 1.1.1.9 christos 1123 1.1.1.9 christos /* Merge object attributes from IBFD into OBFD. Warn if 1124 1.1.1.10 christos there are conflicting attributes. */ 1125 1.1.1.9 christos static bool 1126 1.1.1.9 christos m68k_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info) 1127 1.1.1.9 christos { 1128 1.1.1.9 christos bfd *obfd = info->output_bfd; 1129 1.1.1.9 christos obj_attribute *in_attr, *in_attrs; 1130 1.1.1.10 christos obj_attribute *out_attr, *out_attrs; 1131 1.1.1.9 christos bool ret = true; 1132 1.1.1.9 christos 1133 1.1.1.9 christos in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; 1134 1.1.1.9 christos out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; 1135 1.1.1.9 christos 1136 1.1.1.9 christos in_attr = &in_attrs[Tag_GNU_M68K_ABI_FP]; 1137 1.1.1.9 christos out_attr = &out_attrs[Tag_GNU_M68K_ABI_FP]; 1138 1.1.1.9 christos 1139 1.1.1.9 christos if (in_attr->i != out_attr->i) 1140 1.1.1.9 christos { 1141 1.1.1.9 christos int in_fp = in_attr->i & 3; 1142 1.1.1.9 christos int out_fp = out_attr->i & 3; 1143 1.1.1.9 christos static bfd *last_fp; 1144 1.1.1.9 christos 1145 1.1.1.9 christos if (in_fp == 0) 1146 1.1.1.9 christos ; 1147 1.1.1.9 christos else if (out_fp == 0) 1148 1.1.1.9 christos { 1149 1.1.1.9 christos out_attr->type = ATTR_TYPE_FLAG_INT_VAL; 1150 1.1.1.9 christos out_attr->i ^= in_fp; 1151 1.1.1.9 christos last_fp = ibfd; 1152 1.1.1.9 christos } 1153 1.1.1.9 christos else if (out_fp == 1 && in_fp == 2) 1154 1.1.1.9 christos { 1155 1.1.1.9 christos _bfd_error_handler 1156 1.1.1.9 christos /* xgettext:c-format */ 1157 1.1.1.9 christos (_("%pB uses hard float, %pB uses soft float"), 1158 1.1.1.10 christos last_fp, ibfd); 1159 1.1.1.9 christos ret = false; 1160 1.1.1.9 christos } 1161 1.1.1.9 christos else if (out_fp == 2 && in_fp == 1) 1162 1.1.1.9 christos { 1163 1.1.1.9 christos _bfd_error_handler 1164 1.1.1.9 christos /* xgettext:c-format */ 1165 1.1.1.9 christos (_("%pB uses hard float, %pB uses soft float"), 1166 1.1.1.10 christos ibfd, last_fp); 1167 1.1.1.9 christos ret = false; 1168 1.1.1.9 christos } 1169 1.1.1.9 christos } 1170 1.1.1.9 christos 1171 1.1.1.9 christos if (!ret) 1172 1.1.1.9 christos { 1173 1.1.1.9 christos out_attr->type = ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_ERROR; 1174 1.1.1.10 christos bfd_set_error (bfd_error_bad_value); 1175 1.1.1.9 christos return false; 1176 1.1.1.9 christos } 1177 1.1.1.9 christos 1178 1.1.1.9 christos /* Merge Tag_compatibility attributes and any common GNU ones. */ 1179 1.1.1.9 christos return _bfd_elf_merge_object_attributes (ibfd, info); 1180 1.1.1.9 christos } 1181 1.1 christos 1182 1.1 christos /* Merge backend specific data from an object file to the output 1183 1.1.1.10 christos object file when linking. */ 1184 1.1.1.7 christos static bool 1185 1.1 christos elf32_m68k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) 1186 1.1.1.7 christos { 1187 1.1 christos bfd *obfd = info->output_bfd; 1188 1.1 christos flagword out_flags; 1189 1.1 christos flagword in_flags; 1190 1.1 christos flagword out_isa; 1191 1.1 christos flagword in_isa; 1192 1.1 christos const bfd_arch_info_type *arch_info; 1193 1.1.1.9 christos 1194 1.1 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 1195 1.1.1.9 christos || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 1196 1.1.1.9 christos /* PR 24523: For non-ELF files do not try to merge any private 1197 1.1.1.10 christos data, but also do not prevent the link from succeeding. */ 1198 1.1 christos return true; 1199 1.1 christos 1200 1.1 christos /* Get the merged machine. This checks for incompatibility between 1201 1.1 christos Coldfire & non-Coldfire flags, incompability between different 1202 1.1.1.10 christos Coldfire ISAs, and incompability between different MAC types. */ 1203 1.1 christos arch_info = bfd_arch_get_compatible (ibfd, obfd, false); 1204 1.1.1.10 christos if (!arch_info) 1205 1.1 christos return false; 1206 1.1 christos 1207 1.1 christos bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach); 1208 1.1.1.9 christos 1209 1.1.1.10 christos if (!m68k_elf_merge_obj_attributes (ibfd, info)) 1210 1.1.1.9 christos return false; 1211 1.1 christos 1212 1.1 christos in_flags = elf_elfheader (ibfd)->e_flags; 1213 1.1 christos if (!elf_flags_init (obfd)) 1214 1.1.1.10 christos { 1215 1.1 christos elf_flags_init (obfd) = true; 1216 1.1 christos out_flags = in_flags; 1217 1.1 christos } 1218 1.1 christos else 1219 1.1 christos { 1220 1.1 christos out_flags = elf_elfheader (obfd)->e_flags; 1221 1.1 christos unsigned int variant_mask; 1222 1.1 christos 1223 1.1 christos if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) 1224 1.1 christos variant_mask = 0; 1225 1.1 christos else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) 1226 1.1 christos variant_mask = 0; 1227 1.1 christos else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) 1228 1.1 christos variant_mask = 0; 1229 1.1 christos else 1230 1.1 christos variant_mask = EF_M68K_CF_ISA_MASK; 1231 1.1 christos 1232 1.1 christos in_isa = (in_flags & variant_mask); 1233 1.1 christos out_isa = (out_flags & variant_mask); 1234 1.1 christos if (in_isa > out_isa) 1235 1.1 christos out_flags ^= in_isa ^ out_isa; 1236 1.1 christos if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32 1237 1.1 christos && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) 1238 1.1 christos || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO 1239 1.1 christos && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)) 1240 1.1 christos out_flags = EF_M68K_FIDO; 1241 1.1 christos else 1242 1.1 christos out_flags |= in_flags ^ in_isa; 1243 1.1 christos } 1244 1.1 christos elf_elfheader (obfd)->e_flags = out_flags; 1245 1.1.1.10 christos 1246 1.1 christos return true; 1247 1.1 christos } 1248 1.1 christos 1249 1.1 christos /* Display the flags field. */ 1250 1.1.1.10 christos 1251 1.1 christos static bool 1252 1.1 christos elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr) 1253 1.1 christos { 1254 1.1 christos FILE *file = (FILE *) ptr; 1255 1.1 christos flagword eflags = elf_elfheader (abfd)->e_flags; 1256 1.1 christos 1257 1.1 christos BFD_ASSERT (abfd != NULL && ptr != NULL); 1258 1.1 christos 1259 1.1 christos /* Print normal ELF private data. */ 1260 1.1 christos _bfd_elf_print_private_bfd_data (abfd, ptr); 1261 1.1 christos 1262 1.1 christos /* Ignore init flag - it may not be set, despite the flags field containing valid data. */ 1263 1.1 christos 1264 1.1 christos /* xgettext:c-format */ 1265 1.1 christos fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); 1266 1.1 christos 1267 1.1 christos if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) 1268 1.1 christos fprintf (file, " [m68000]"); 1269 1.1 christos else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) 1270 1.1 christos fprintf (file, " [cpu32]"); 1271 1.1 christos else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) 1272 1.1 christos fprintf (file, " [fido]"); 1273 1.1 christos else 1274 1.1 christos { 1275 1.1 christos if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E) 1276 1.1 christos fprintf (file, " [cfv4e]"); 1277 1.1 christos 1278 1.1 christos if (eflags & EF_M68K_CF_ISA_MASK) 1279 1.1 christos { 1280 1.1 christos char const *isa = _("unknown"); 1281 1.1 christos char const *mac = _("unknown"); 1282 1.1 christos char const *additional = ""; 1283 1.1 christos 1284 1.1 christos switch (eflags & EF_M68K_CF_ISA_MASK) 1285 1.1 christos { 1286 1.1 christos case EF_M68K_CF_ISA_A_NODIV: 1287 1.1 christos isa = "A"; 1288 1.1 christos additional = " [nodiv]"; 1289 1.1 christos break; 1290 1.1 christos case EF_M68K_CF_ISA_A: 1291 1.1 christos isa = "A"; 1292 1.1 christos break; 1293 1.1 christos case EF_M68K_CF_ISA_A_PLUS: 1294 1.1 christos isa = "A+"; 1295 1.1 christos break; 1296 1.1 christos case EF_M68K_CF_ISA_B_NOUSP: 1297 1.1 christos isa = "B"; 1298 1.1 christos additional = " [nousp]"; 1299 1.1 christos break; 1300 1.1 christos case EF_M68K_CF_ISA_B: 1301 1.1 christos isa = "B"; 1302 1.1 christos break; 1303 1.1 christos case EF_M68K_CF_ISA_C: 1304 1.1 christos isa = "C"; 1305 1.1 christos break; 1306 1.1 christos case EF_M68K_CF_ISA_C_NODIV: 1307 1.1 christos isa = "C"; 1308 1.1 christos additional = " [nodiv]"; 1309 1.1 christos break; 1310 1.1 christos } 1311 1.1 christos fprintf (file, " [isa %s]%s", isa, additional); 1312 1.1 christos 1313 1.1 christos if (eflags & EF_M68K_CF_FLOAT) 1314 1.1 christos fprintf (file, " [float]"); 1315 1.1 christos 1316 1.1 christos switch (eflags & EF_M68K_CF_MAC_MASK) 1317 1.1 christos { 1318 1.1 christos case 0: 1319 1.1 christos mac = NULL; 1320 1.1 christos break; 1321 1.1 christos case EF_M68K_CF_MAC: 1322 1.1 christos mac = "mac"; 1323 1.1 christos break; 1324 1.1 christos case EF_M68K_CF_EMAC: 1325 1.1 christos mac = "emac"; 1326 1.1 christos break; 1327 1.1 christos case EF_M68K_CF_EMAC_B: 1328 1.1 christos mac = "emac_b"; 1329 1.1 christos break; 1330 1.1 christos } 1331 1.1 christos if (mac) 1332 1.1 christos fprintf (file, " [%s]", mac); 1333 1.1 christos } 1334 1.1 christos } 1335 1.1 christos 1336 1.1 christos fputc ('\n', file); 1337 1.1.1.10 christos 1338 1.1 christos return true; 1339 1.1 christos } 1340 1.1 christos 1341 1.1 christos /* Multi-GOT support implementation design: 1342 1.1 christos 1343 1.1 christos Multi-GOT starts in check_relocs hook. There we scan all 1344 1.1 christos relocations of a BFD and build a local GOT (struct elf_m68k_got) 1345 1.1 christos for it. If a single BFD appears to require too many GOT slots with 1346 1.1 christos R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification 1347 1.1 christos to user. 1348 1.1 christos After check_relocs has been invoked for each input BFD, we have 1349 1.1 christos constructed a GOT for each input BFD. 1350 1.1 christos 1351 1.1 christos To minimize total number of GOTs required for a particular output BFD 1352 1.1 christos (as some environments support only 1 GOT per output object) we try 1353 1.1 christos to merge some of the GOTs to share an offset space. Ideally [and in most 1354 1.1 christos cases] we end up with a single GOT. In cases when there are too many 1355 1.1 christos restricted relocations (e.g., R_68K_GOT16O relocations) we end up with 1356 1.1 christos several GOTs, assuming the environment can handle them. 1357 1.1 christos 1358 1.1 christos Partitioning is done in elf_m68k_partition_multi_got. We start with 1359 1.1 christos an empty GOT and traverse bfd2got hashtable putting got_entries from 1360 1.1 christos local GOTs to the new 'big' one. We do that by constructing an 1361 1.1 christos intermediate GOT holding all the entries the local GOT has and the big 1362 1.1 christos GOT lacks. Then we check if there is room in the big GOT to accomodate 1363 1.1 christos all the entries from diff. On success we add those entries to the big 1364 1.1 christos GOT; on failure we start the new 'big' GOT and retry the adding of 1365 1.1 christos entries from the local GOT. Note that this retry will always succeed as 1366 1.1 christos each local GOT doesn't overflow the limits. After partitioning we 1367 1.1 christos end up with each bfd assigned one of the big GOTs. GOT entries in the 1368 1.1 christos big GOTs are initialized with GOT offsets. Note that big GOTs are 1369 1.1 christos positioned consequently in program space and represent a single huge GOT 1370 1.1 christos to the outside world. 1371 1.1 christos 1372 1.1 christos After that we get to elf_m68k_relocate_section. There we 1373 1.1 christos adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol 1374 1.1 christos relocations to refer to appropriate [assigned to current input_bfd] 1375 1.1 christos big GOT. 1376 1.1 christos 1377 1.1 christos Notes: 1378 1.1 christos 1379 1.1 christos GOT entry type: We have several types of GOT entries. 1380 1.1 christos * R_8 type is used in entries for symbols that have at least one 1381 1.1 christos R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40 1382 1.1 christos such entries in one GOT. 1383 1.1 christos * R_16 type is used in entries for symbols that have at least one 1384 1.1 christos R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations. 1385 1.1 christos We can have at most 0x4000 such entries in one GOT. 1386 1.1 christos * R_32 type is used in all other cases. We can have as many 1387 1.1 christos such entries in one GOT as we'd like. 1388 1.1 christos When counting relocations we have to include the count of the smaller 1389 1.1 christos ranged relocations in the counts of the larger ranged ones in order 1390 1.1 christos to correctly detect overflow. 1391 1.1 christos 1392 1.1 christos Sorting the GOT: In each GOT starting offsets are assigned to 1393 1.1 christos R_8 entries, which are followed by R_16 entries, and 1394 1.1 christos R_32 entries go at the end. See finalize_got_offsets for details. 1395 1.1 christos 1396 1.1 christos Negative GOT offsets: To double usable offset range of GOTs we use 1397 1.1 christos negative offsets. As we assign entries with GOT offsets relative to 1398 1.1 christos start of .got section, the offset values are positive. They become 1399 1.1 christos negative only in relocate_section where got->offset value is 1400 1.1 christos subtracted from them. 1401 1.1 christos 1402 1.1 christos 3 special GOT entries: There are 3 special GOT entries used internally 1403 1.1 christos by loader. These entries happen to be placed to .got.plt section, 1404 1.1 christos so we don't do anything about them in multi-GOT support. 1405 1.1 christos 1406 1.1 christos Memory management: All data except for hashtables 1407 1.1 christos multi_got->bfd2got and got->entries are allocated on 1408 1.1 christos elf_hash_table (info)->dynobj bfd (for this reason we pass 'info' 1409 1.1 christos to most functions), so we don't need to care to free them. At the 1410 1.1 christos moment of allocation hashtables are being linked into main data 1411 1.1 christos structure (multi_got), all pieces of which are reachable from 1412 1.1 christos elf_m68k_multi_got (info). We deallocate them in 1413 1.1 christos elf_m68k_link_hash_table_free. */ 1414 1.1 christos 1415 1.1 christos /* Initialize GOT. */ 1416 1.1 christos 1417 1.1 christos static void 1418 1.1 christos elf_m68k_init_got (struct elf_m68k_got *got) 1419 1.1 christos { 1420 1.1 christos got->entries = NULL; 1421 1.1 christos got->n_slots[R_8] = 0; 1422 1.1 christos got->n_slots[R_16] = 0; 1423 1.1 christos got->n_slots[R_32] = 0; 1424 1.1 christos got->local_n_slots = 0; 1425 1.1 christos got->offset = (bfd_vma) -1; 1426 1.1 christos } 1427 1.1 christos 1428 1.1 christos /* Destruct GOT. */ 1429 1.1 christos 1430 1.1 christos static void 1431 1.1 christos elf_m68k_clear_got (struct elf_m68k_got *got) 1432 1.1 christos { 1433 1.1 christos if (got->entries != NULL) 1434 1.1 christos { 1435 1.1 christos htab_delete (got->entries); 1436 1.1 christos got->entries = NULL; 1437 1.1 christos } 1438 1.1 christos } 1439 1.1 christos 1440 1.1 christos /* Create and empty GOT structure. INFO is the context where memory 1441 1.1 christos should be allocated. */ 1442 1.1 christos 1443 1.1 christos static struct elf_m68k_got * 1444 1.1 christos elf_m68k_create_empty_got (struct bfd_link_info *info) 1445 1.1 christos { 1446 1.1 christos struct elf_m68k_got *got; 1447 1.1 christos 1448 1.1 christos got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got)); 1449 1.1 christos if (got == NULL) 1450 1.1 christos return NULL; 1451 1.1 christos 1452 1.1 christos elf_m68k_init_got (got); 1453 1.1 christos 1454 1.1 christos return got; 1455 1.1 christos } 1456 1.1 christos 1457 1.1 christos /* Initialize KEY. */ 1458 1.1 christos 1459 1.1 christos static void 1460 1.1 christos elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key, 1461 1.1 christos struct elf_link_hash_entry *h, 1462 1.1 christos const bfd *abfd, unsigned long symndx, 1463 1.1 christos enum elf_m68k_reloc_type reloc_type) 1464 1.1 christos { 1465 1.1 christos if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32) 1466 1.1 christos /* All TLS_LDM relocations share a single GOT entry. */ 1467 1.1 christos { 1468 1.1 christos key->bfd = NULL; 1469 1.1 christos key->symndx = 0; 1470 1.1 christos } 1471 1.1 christos else if (h != NULL) 1472 1.1 christos /* Global symbols are identified with their got_entry_key. */ 1473 1.1 christos { 1474 1.1 christos key->bfd = NULL; 1475 1.1 christos key->symndx = elf_m68k_hash_entry (h)->got_entry_key; 1476 1.1 christos BFD_ASSERT (key->symndx != 0); 1477 1.1 christos } 1478 1.1 christos else 1479 1.1 christos /* Local symbols are identified by BFD they appear in and symndx. */ 1480 1.1 christos { 1481 1.1 christos key->bfd = abfd; 1482 1.1 christos key->symndx = symndx; 1483 1.1 christos } 1484 1.1 christos 1485 1.1 christos key->type = reloc_type; 1486 1.1 christos } 1487 1.1 christos 1488 1.1 christos /* Calculate hash of got_entry. 1489 1.1 christos ??? Is it good? */ 1490 1.1 christos 1491 1.1 christos static hashval_t 1492 1.1 christos elf_m68k_got_entry_hash (const void *_entry) 1493 1.1 christos { 1494 1.1 christos const struct elf_m68k_got_entry_key *key; 1495 1.1 christos 1496 1.1 christos key = &((const struct elf_m68k_got_entry *) _entry)->key_; 1497 1.1 christos 1498 1.1 christos return (key->symndx 1499 1.1 christos + (key->bfd != NULL ? (int) key->bfd->id : -1) 1500 1.1 christos + elf_m68k_reloc_got_type (key->type)); 1501 1.1 christos } 1502 1.1 christos 1503 1.1 christos /* Check if two got entries are equal. */ 1504 1.1 christos 1505 1.1 christos static int 1506 1.1 christos elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2) 1507 1.1 christos { 1508 1.1 christos const struct elf_m68k_got_entry_key *key1; 1509 1.1 christos const struct elf_m68k_got_entry_key *key2; 1510 1.1 christos 1511 1.1 christos key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_; 1512 1.1 christos key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_; 1513 1.1 christos 1514 1.1 christos return (key1->bfd == key2->bfd 1515 1.1 christos && key1->symndx == key2->symndx 1516 1.1 christos && (elf_m68k_reloc_got_type (key1->type) 1517 1.1 christos == elf_m68k_reloc_got_type (key2->type))); 1518 1.1 christos } 1519 1.1 christos 1520 1.1 christos /* When using negative offsets, we allocate one extra R_8, one extra R_16 1521 1.1 christos and one extra R_32 slots to simplify handling of 2-slot entries during 1522 1.1 christos offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */ 1523 1.1 christos 1524 1.1 christos /* Maximal number of R_8 slots in a single GOT. */ 1525 1.1 christos #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \ 1526 1.1 christos (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \ 1527 1.1 christos ? (0x40 - 1) \ 1528 1.1 christos : 0x20) 1529 1.1 christos 1530 1.1 christos /* Maximal number of R_8 and R_16 slots in a single GOT. */ 1531 1.1 christos #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \ 1532 1.1 christos (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \ 1533 1.1 christos ? (0x4000 - 2) \ 1534 1.1 christos : 0x2000) 1535 1.1 christos 1536 1.1 christos /* SEARCH - simply search the hashtable, don't insert new entries or fail when 1537 1.1 christos the entry cannot be found. 1538 1.1 christos FIND_OR_CREATE - search for an existing entry, but create new if there's 1539 1.1 christos no such. 1540 1.1 christos MUST_FIND - search for an existing entry and assert that it exist. 1541 1.1 christos MUST_CREATE - assert that there's no such entry and create new one. */ 1542 1.1 christos enum elf_m68k_get_entry_howto 1543 1.1 christos { 1544 1.1 christos SEARCH, 1545 1.1 christos FIND_OR_CREATE, 1546 1.1 christos MUST_FIND, 1547 1.1 christos MUST_CREATE 1548 1.1 christos }; 1549 1.1 christos 1550 1.1 christos /* Get or create (depending on HOWTO) entry with KEY in GOT. 1551 1.1 christos INFO is context in which memory should be allocated (can be NULL if 1552 1.1 christos HOWTO is SEARCH or MUST_FIND). */ 1553 1.1 christos 1554 1.1 christos static struct elf_m68k_got_entry * 1555 1.1 christos elf_m68k_get_got_entry (struct elf_m68k_got *got, 1556 1.1 christos const struct elf_m68k_got_entry_key *key, 1557 1.1 christos enum elf_m68k_get_entry_howto howto, 1558 1.1 christos struct bfd_link_info *info) 1559 1.1 christos { 1560 1.1 christos struct elf_m68k_got_entry entry_; 1561 1.1 christos struct elf_m68k_got_entry *entry; 1562 1.1 christos void **ptr; 1563 1.1 christos 1564 1.1 christos BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND)); 1565 1.1 christos 1566 1.1 christos if (got->entries == NULL) 1567 1.1 christos /* This is the first entry in ABFD. Initialize hashtable. */ 1568 1.1 christos { 1569 1.1 christos if (howto == SEARCH) 1570 1.1 christos return NULL; 1571 1.1 christos 1572 1.1 christos got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT 1573 1.1 christos (info), 1574 1.1 christos elf_m68k_got_entry_hash, 1575 1.1 christos elf_m68k_got_entry_eq, NULL); 1576 1.1 christos if (got->entries == NULL) 1577 1.1 christos { 1578 1.1 christos bfd_set_error (bfd_error_no_memory); 1579 1.1 christos return NULL; 1580 1.1 christos } 1581 1.1 christos } 1582 1.1 christos 1583 1.1.1.9 christos entry_.key_ = *key; 1584 1.1.1.9 christos ptr = htab_find_slot (got->entries, &entry_, 1585 1.1.1.9 christos (howto == SEARCH || howto == MUST_FIND ? NO_INSERT 1586 1.1 christos : INSERT)); 1587 1.1 christos if (ptr == NULL) 1588 1.1 christos { 1589 1.1 christos if (howto == SEARCH) 1590 1.1 christos /* Entry not found. */ 1591 1.1 christos return NULL; 1592 1.1.1.9 christos 1593 1.1.1.9 christos if (howto == MUST_FIND) 1594 1.1.1.9 christos abort (); 1595 1.1 christos 1596 1.1 christos /* We're out of memory. */ 1597 1.1 christos bfd_set_error (bfd_error_no_memory); 1598 1.1 christos return NULL; 1599 1.1 christos } 1600 1.1 christos 1601 1.1 christos if (*ptr == NULL) 1602 1.1 christos /* We didn't find the entry and we're asked to create a new one. */ 1603 1.1.1.9 christos { 1604 1.1.1.9 christos if (howto == MUST_FIND) 1605 1.1.1.9 christos abort (); 1606 1.1.1.9 christos 1607 1.1 christos BFD_ASSERT (howto != SEARCH); 1608 1.1 christos 1609 1.1 christos entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)); 1610 1.1 christos if (entry == NULL) 1611 1.1 christos return NULL; 1612 1.1 christos 1613 1.1 christos /* Initialize new entry. */ 1614 1.1 christos entry->key_ = *key; 1615 1.1 christos 1616 1.1 christos entry->u.s1.refcount = 0; 1617 1.1 christos 1618 1.1 christos /* Mark the entry as not initialized. */ 1619 1.1 christos entry->key_.type = R_68K_max; 1620 1.1 christos 1621 1.1 christos *ptr = entry; 1622 1.1 christos } 1623 1.1 christos else 1624 1.1 christos /* We found the entry. */ 1625 1.1 christos { 1626 1.1 christos BFD_ASSERT (howto != MUST_CREATE); 1627 1.1 christos 1628 1.1 christos entry = *ptr; 1629 1.1 christos } 1630 1.1 christos 1631 1.1 christos return entry; 1632 1.1 christos } 1633 1.1 christos 1634 1.1 christos /* Update GOT counters when merging entry of WAS type with entry of NEW type. 1635 1.1 christos Return the value to which ENTRY's type should be set. */ 1636 1.1 christos 1637 1.1 christos static enum elf_m68k_reloc_type 1638 1.1 christos elf_m68k_update_got_entry_type (struct elf_m68k_got *got, 1639 1.1 christos enum elf_m68k_reloc_type was, 1640 1.1 christos enum elf_m68k_reloc_type new_reloc) 1641 1.1 christos { 1642 1.1 christos enum elf_m68k_got_offset_size was_size; 1643 1.1 christos enum elf_m68k_got_offset_size new_size; 1644 1.1 christos bfd_vma n_slots; 1645 1.1 christos 1646 1.1 christos if (was == R_68K_max) 1647 1.1 christos /* The type of the entry is not initialized yet. */ 1648 1.1 christos { 1649 1.1 christos /* Update all got->n_slots counters, including n_slots[R_32]. */ 1650 1.1 christos was_size = R_LAST; 1651 1.1 christos 1652 1.1 christos was = new_reloc; 1653 1.1 christos } 1654 1.1 christos else 1655 1.1 christos { 1656 1.1 christos /* !!! We, probably, should emit an error rather then fail on assert 1657 1.1 christos in such a case. */ 1658 1.1 christos BFD_ASSERT (elf_m68k_reloc_got_type (was) 1659 1.1 christos == elf_m68k_reloc_got_type (new_reloc)); 1660 1.1 christos 1661 1.1 christos was_size = elf_m68k_reloc_got_offset_size (was); 1662 1.1 christos } 1663 1.1 christos 1664 1.1 christos new_size = elf_m68k_reloc_got_offset_size (new_reloc); 1665 1.1 christos n_slots = elf_m68k_reloc_got_n_slots (new_reloc); 1666 1.1 christos 1667 1.1 christos while (was_size > new_size) 1668 1.1 christos { 1669 1.1 christos --was_size; 1670 1.1 christos got->n_slots[was_size] += n_slots; 1671 1.1 christos } 1672 1.1 christos 1673 1.1 christos if (new_reloc > was) 1674 1.1 christos /* Relocations are ordered from bigger got offset size to lesser, 1675 1.1 christos so choose the relocation type with lesser offset size. */ 1676 1.1 christos was = new_reloc; 1677 1.1 christos 1678 1.1 christos return was; 1679 1.1 christos } 1680 1.1 christos 1681 1.1 christos /* Add new or update existing entry to GOT. 1682 1.1 christos H, ABFD, TYPE and SYMNDX is data for the entry. 1683 1.1 christos INFO is a context where memory should be allocated. */ 1684 1.1 christos 1685 1.1 christos static struct elf_m68k_got_entry * 1686 1.1 christos elf_m68k_add_entry_to_got (struct elf_m68k_got *got, 1687 1.1 christos struct elf_link_hash_entry *h, 1688 1.1 christos const bfd *abfd, 1689 1.1 christos enum elf_m68k_reloc_type reloc_type, 1690 1.1 christos unsigned long symndx, 1691 1.1 christos struct bfd_link_info *info) 1692 1.1 christos { 1693 1.1 christos struct elf_m68k_got_entry_key key_; 1694 1.1 christos struct elf_m68k_got_entry *entry; 1695 1.1 christos 1696 1.1 christos if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0) 1697 1.1 christos elf_m68k_hash_entry (h)->got_entry_key 1698 1.1 christos = elf_m68k_multi_got (info)->global_symndx++; 1699 1.1 christos 1700 1.1 christos elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type); 1701 1.1 christos 1702 1.1 christos entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info); 1703 1.1 christos if (entry == NULL) 1704 1.1 christos return NULL; 1705 1.1 christos 1706 1.1 christos /* Determine entry's type and update got->n_slots counters. */ 1707 1.1 christos entry->key_.type = elf_m68k_update_got_entry_type (got, 1708 1.1 christos entry->key_.type, 1709 1.1 christos reloc_type); 1710 1.1 christos 1711 1.1 christos /* Update refcount. */ 1712 1.1 christos ++entry->u.s1.refcount; 1713 1.1 christos 1714 1.1 christos if (entry->u.s1.refcount == 1) 1715 1.1 christos /* We see this entry for the first time. */ 1716 1.1 christos { 1717 1.1 christos if (entry->key_.bfd != NULL) 1718 1.1 christos got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type); 1719 1.1 christos } 1720 1.1 christos 1721 1.1 christos BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots); 1722 1.1 christos 1723 1.1 christos if ((got->n_slots[R_8] 1724 1.1 christos > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) 1725 1.1 christos || (got->n_slots[R_16] 1726 1.1 christos > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))) 1727 1.1 christos /* This BFD has too many relocation. */ 1728 1.1 christos { 1729 1.1.1.7 christos if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) 1730 1.1.1.8 christos /* xgettext:c-format */ 1731 1.1.1.8 christos _bfd_error_handler (_("%pB: GOT overflow: " 1732 1.1.1.7 christos "number of relocations with 8-bit " 1733 1.1.1.7 christos "offset > %d"), 1734 1.1.1.7 christos abfd, 1735 1.1 christos ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)); 1736 1.1.1.7 christos else 1737 1.1.1.8 christos /* xgettext:c-format */ 1738 1.1.1.8 christos _bfd_error_handler (_("%pB: GOT overflow: " 1739 1.1.1.7 christos "number of relocations with 8- or 16-bit " 1740 1.1.1.7 christos "offset > %d"), 1741 1.1.1.7 christos abfd, 1742 1.1 christos ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)); 1743 1.1 christos 1744 1.1 christos return NULL; 1745 1.1 christos } 1746 1.1 christos 1747 1.1 christos return entry; 1748 1.1 christos } 1749 1.1 christos 1750 1.1 christos /* Compute the hash value of the bfd in a bfd2got hash entry. */ 1751 1.1 christos 1752 1.1 christos static hashval_t 1753 1.1 christos elf_m68k_bfd2got_entry_hash (const void *entry) 1754 1.1 christos { 1755 1.1 christos const struct elf_m68k_bfd2got_entry *e; 1756 1.1 christos 1757 1.1 christos e = (const struct elf_m68k_bfd2got_entry *) entry; 1758 1.1 christos 1759 1.1 christos return e->bfd->id; 1760 1.1 christos } 1761 1.1 christos 1762 1.1 christos /* Check whether two hash entries have the same bfd. */ 1763 1.1 christos 1764 1.1 christos static int 1765 1.1 christos elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2) 1766 1.1 christos { 1767 1.1 christos const struct elf_m68k_bfd2got_entry *e1; 1768 1.1 christos const struct elf_m68k_bfd2got_entry *e2; 1769 1.1 christos 1770 1.1 christos e1 = (const struct elf_m68k_bfd2got_entry *) entry1; 1771 1.1 christos e2 = (const struct elf_m68k_bfd2got_entry *) entry2; 1772 1.1 christos 1773 1.1 christos return e1->bfd == e2->bfd; 1774 1.1 christos } 1775 1.1 christos 1776 1.1 christos /* Destruct a bfd2got entry. */ 1777 1.1 christos 1778 1.1 christos static void 1779 1.1 christos elf_m68k_bfd2got_entry_del (void *_entry) 1780 1.1 christos { 1781 1.1 christos struct elf_m68k_bfd2got_entry *entry; 1782 1.1 christos 1783 1.1 christos entry = (struct elf_m68k_bfd2got_entry *) _entry; 1784 1.1 christos 1785 1.1 christos BFD_ASSERT (entry->got != NULL); 1786 1.1 christos elf_m68k_clear_got (entry->got); 1787 1.1 christos } 1788 1.1 christos 1789 1.1 christos /* Find existing or create new (depending on HOWTO) bfd2got entry in 1790 1.1 christos MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where 1791 1.1 christos memory should be allocated. */ 1792 1.1 christos 1793 1.1 christos static struct elf_m68k_bfd2got_entry * 1794 1.1 christos elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got, 1795 1.1 christos const bfd *abfd, 1796 1.1 christos enum elf_m68k_get_entry_howto howto, 1797 1.1 christos struct bfd_link_info *info) 1798 1.1 christos { 1799 1.1 christos struct elf_m68k_bfd2got_entry entry_; 1800 1.1 christos void **ptr; 1801 1.1 christos struct elf_m68k_bfd2got_entry *entry; 1802 1.1 christos 1803 1.1 christos BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND)); 1804 1.1 christos 1805 1.1 christos if (multi_got->bfd2got == NULL) 1806 1.1 christos /* This is the first GOT. Initialize bfd2got. */ 1807 1.1 christos { 1808 1.1 christos if (howto == SEARCH) 1809 1.1 christos return NULL; 1810 1.1 christos 1811 1.1 christos multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash, 1812 1.1 christos elf_m68k_bfd2got_entry_eq, 1813 1.1 christos elf_m68k_bfd2got_entry_del); 1814 1.1 christos if (multi_got->bfd2got == NULL) 1815 1.1 christos { 1816 1.1 christos bfd_set_error (bfd_error_no_memory); 1817 1.1 christos return NULL; 1818 1.1 christos } 1819 1.1 christos } 1820 1.1 christos 1821 1.1.1.9 christos entry_.bfd = abfd; 1822 1.1.1.9 christos ptr = htab_find_slot (multi_got->bfd2got, &entry_, 1823 1.1.1.9 christos (howto == SEARCH || howto == MUST_FIND ? NO_INSERT 1824 1.1 christos : INSERT)); 1825 1.1 christos if (ptr == NULL) 1826 1.1 christos { 1827 1.1 christos if (howto == SEARCH) 1828 1.1 christos /* Entry not found. */ 1829 1.1 christos return NULL; 1830 1.1.1.9 christos 1831 1.1.1.9 christos if (howto == MUST_FIND) 1832 1.1.1.9 christos abort (); 1833 1.1 christos 1834 1.1 christos /* We're out of memory. */ 1835 1.1 christos bfd_set_error (bfd_error_no_memory); 1836 1.1 christos return NULL; 1837 1.1 christos } 1838 1.1 christos 1839 1.1 christos if (*ptr == NULL) 1840 1.1 christos /* Entry was not found. Create new one. */ 1841 1.1.1.9 christos { 1842 1.1.1.9 christos if (howto == MUST_FIND) 1843 1.1.1.9 christos abort (); 1844 1.1.1.9 christos 1845 1.1 christos BFD_ASSERT (howto != SEARCH); 1846 1.1 christos 1847 1.1 christos entry = ((struct elf_m68k_bfd2got_entry *) 1848 1.1 christos bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry))); 1849 1.1 christos if (entry == NULL) 1850 1.1 christos return NULL; 1851 1.1 christos 1852 1.1 christos entry->bfd = abfd; 1853 1.1 christos 1854 1.1 christos entry->got = elf_m68k_create_empty_got (info); 1855 1.1 christos if (entry->got == NULL) 1856 1.1 christos return NULL; 1857 1.1 christos 1858 1.1 christos *ptr = entry; 1859 1.1 christos } 1860 1.1 christos else 1861 1.1 christos { 1862 1.1 christos BFD_ASSERT (howto != MUST_CREATE); 1863 1.1 christos 1864 1.1 christos /* Return existing entry. */ 1865 1.1 christos entry = *ptr; 1866 1.1 christos } 1867 1.1 christos 1868 1.1 christos return entry; 1869 1.1 christos } 1870 1.1 christos 1871 1.1 christos struct elf_m68k_can_merge_gots_arg 1872 1.1 christos { 1873 1.1 christos /* A current_got that we constructing a DIFF against. */ 1874 1.1 christos struct elf_m68k_got *big; 1875 1.1 christos 1876 1.1 christos /* GOT holding entries not present or that should be changed in 1877 1.1 christos BIG. */ 1878 1.1 christos struct elf_m68k_got *diff; 1879 1.1 christos 1880 1.1 christos /* Context where to allocate memory. */ 1881 1.1 christos struct bfd_link_info *info; 1882 1.1 christos 1883 1.1.1.10 christos /* Error flag. */ 1884 1.1 christos bool error_p; 1885 1.1 christos }; 1886 1.1 christos 1887 1.1 christos /* Process a single entry from the small GOT to see if it should be added 1888 1.1 christos or updated in the big GOT. */ 1889 1.1 christos 1890 1.1 christos static int 1891 1.1 christos elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg) 1892 1.1 christos { 1893 1.1 christos const struct elf_m68k_got_entry *entry1; 1894 1.1 christos struct elf_m68k_can_merge_gots_arg *arg; 1895 1.1 christos const struct elf_m68k_got_entry *entry2; 1896 1.1 christos enum elf_m68k_reloc_type type; 1897 1.1 christos 1898 1.1 christos entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr; 1899 1.1 christos arg = (struct elf_m68k_can_merge_gots_arg *) _arg; 1900 1.1 christos 1901 1.1 christos entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL); 1902 1.1 christos 1903 1.1 christos if (entry2 != NULL) 1904 1.1 christos /* We found an existing entry. Check if we should update it. */ 1905 1.1 christos { 1906 1.1 christos type = elf_m68k_update_got_entry_type (arg->diff, 1907 1.1 christos entry2->key_.type, 1908 1.1 christos entry1->key_.type); 1909 1.1 christos 1910 1.1 christos if (type == entry2->key_.type) 1911 1.1 christos /* ENTRY1 doesn't update data in ENTRY2. Skip it. 1912 1.1 christos To skip creation of difference entry we use the type, 1913 1.1 christos which we won't see in GOT entries for sure. */ 1914 1.1 christos type = R_68K_max; 1915 1.1 christos } 1916 1.1 christos else 1917 1.1 christos /* We didn't find the entry. Add entry1 to DIFF. */ 1918 1.1 christos { 1919 1.1 christos BFD_ASSERT (entry1->key_.type != R_68K_max); 1920 1.1 christos 1921 1.1 christos type = elf_m68k_update_got_entry_type (arg->diff, 1922 1.1 christos R_68K_max, entry1->key_.type); 1923 1.1 christos 1924 1.1 christos if (entry1->key_.bfd != NULL) 1925 1.1 christos arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type); 1926 1.1 christos } 1927 1.1 christos 1928 1.1 christos if (type != R_68K_max) 1929 1.1 christos /* Create an entry in DIFF. */ 1930 1.1 christos { 1931 1.1 christos struct elf_m68k_got_entry *entry; 1932 1.1 christos 1933 1.1 christos entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE, 1934 1.1 christos arg->info); 1935 1.1 christos if (entry == NULL) 1936 1.1.1.10 christos { 1937 1.1 christos arg->error_p = true; 1938 1.1 christos return 0; 1939 1.1 christos } 1940 1.1 christos 1941 1.1 christos entry->key_.type = type; 1942 1.1 christos } 1943 1.1 christos 1944 1.1 christos return 1; 1945 1.1 christos } 1946 1.1 christos 1947 1.1 christos /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it. 1948 1.1 christos Construct DIFF GOT holding the entries which should be added or updated 1949 1.1 christos in BIG GOT to accumulate information from SMALL. 1950 1.1 christos INFO is the context where memory should be allocated. */ 1951 1.1.1.10 christos 1952 1.1 christos static bool 1953 1.1 christos elf_m68k_can_merge_gots (struct elf_m68k_got *big, 1954 1.1 christos const struct elf_m68k_got *small, 1955 1.1 christos struct bfd_link_info *info, 1956 1.1 christos struct elf_m68k_got *diff) 1957 1.1 christos { 1958 1.1 christos struct elf_m68k_can_merge_gots_arg arg_; 1959 1.1 christos 1960 1.1 christos BFD_ASSERT (small->offset == (bfd_vma) -1); 1961 1.1 christos 1962 1.1 christos arg_.big = big; 1963 1.1 christos arg_.diff = diff; 1964 1.1.1.10 christos arg_.info = info; 1965 1.1 christos arg_.error_p = false; 1966 1.1 christos htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_); 1967 1.1 christos if (arg_.error_p) 1968 1.1 christos { 1969 1.1.1.10 christos diff->offset = 0; 1970 1.1 christos return false; 1971 1.1 christos } 1972 1.1 christos 1973 1.1 christos /* Check for overflow. */ 1974 1.1 christos if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8] 1975 1.1 christos > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) 1976 1.1 christos || (big->n_slots[R_16] + arg_.diff->n_slots[R_16] 1977 1.1.1.10 christos > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))) 1978 1.1 christos return false; 1979 1.1.1.10 christos 1980 1.1 christos return true; 1981 1.1 christos } 1982 1.1 christos 1983 1.1 christos struct elf_m68k_merge_gots_arg 1984 1.1 christos { 1985 1.1 christos /* The BIG got. */ 1986 1.1 christos struct elf_m68k_got *big; 1987 1.1 christos 1988 1.1 christos /* Context where memory should be allocated. */ 1989 1.1 christos struct bfd_link_info *info; 1990 1.1 christos 1991 1.1.1.10 christos /* Error flag. */ 1992 1.1 christos bool error_p; 1993 1.1 christos }; 1994 1.1 christos 1995 1.1 christos /* Process a single entry from DIFF got. Add or update corresponding 1996 1.1 christos entry in the BIG got. */ 1997 1.1 christos 1998 1.1 christos static int 1999 1.1 christos elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg) 2000 1.1 christos { 2001 1.1 christos const struct elf_m68k_got_entry *from; 2002 1.1 christos struct elf_m68k_merge_gots_arg *arg; 2003 1.1 christos struct elf_m68k_got_entry *to; 2004 1.1 christos 2005 1.1 christos from = (const struct elf_m68k_got_entry *) *entry_ptr; 2006 1.1 christos arg = (struct elf_m68k_merge_gots_arg *) _arg; 2007 1.1 christos 2008 1.1 christos to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE, 2009 1.1 christos arg->info); 2010 1.1 christos if (to == NULL) 2011 1.1.1.10 christos { 2012 1.1 christos arg->error_p = true; 2013 1.1 christos return 0; 2014 1.1 christos } 2015 1.1 christos 2016 1.1 christos BFD_ASSERT (to->u.s1.refcount == 0); 2017 1.1 christos /* All we need to merge is TYPE. */ 2018 1.1 christos to->key_.type = from->key_.type; 2019 1.1 christos 2020 1.1 christos return 1; 2021 1.1 christos } 2022 1.1 christos 2023 1.1 christos /* Merge data from DIFF to BIG. INFO is context where memory should be 2024 1.1 christos allocated. */ 2025 1.1.1.10 christos 2026 1.1 christos static bool 2027 1.1 christos elf_m68k_merge_gots (struct elf_m68k_got *big, 2028 1.1 christos struct elf_m68k_got *diff, 2029 1.1 christos struct bfd_link_info *info) 2030 1.1 christos { 2031 1.1 christos if (diff->entries != NULL) 2032 1.1 christos /* DIFF is not empty. Merge it into BIG GOT. */ 2033 1.1 christos { 2034 1.1 christos struct elf_m68k_merge_gots_arg arg_; 2035 1.1 christos 2036 1.1 christos /* Merge entries. */ 2037 1.1 christos arg_.big = big; 2038 1.1.1.10 christos arg_.info = info; 2039 1.1 christos arg_.error_p = false; 2040 1.1 christos htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_); 2041 1.1.1.10 christos if (arg_.error_p) 2042 1.1 christos return false; 2043 1.1 christos 2044 1.1 christos /* Merge counters. */ 2045 1.1 christos big->n_slots[R_8] += diff->n_slots[R_8]; 2046 1.1 christos big->n_slots[R_16] += diff->n_slots[R_16]; 2047 1.1 christos big->n_slots[R_32] += diff->n_slots[R_32]; 2048 1.1 christos big->local_n_slots += diff->local_n_slots; 2049 1.1 christos } 2050 1.1 christos else 2051 1.1 christos /* DIFF is empty. */ 2052 1.1 christos { 2053 1.1 christos BFD_ASSERT (diff->n_slots[R_8] == 0); 2054 1.1 christos BFD_ASSERT (diff->n_slots[R_16] == 0); 2055 1.1 christos BFD_ASSERT (diff->n_slots[R_32] == 0); 2056 1.1 christos BFD_ASSERT (diff->local_n_slots == 0); 2057 1.1 christos } 2058 1.1 christos 2059 1.1 christos BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p 2060 1.1 christos || ((big->n_slots[R_8] 2061 1.1 christos <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) 2062 1.1 christos && (big->n_slots[R_16] 2063 1.1 christos <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))); 2064 1.1.1.10 christos 2065 1.1 christos return true; 2066 1.1 christos } 2067 1.1 christos 2068 1.1 christos struct elf_m68k_finalize_got_offsets_arg 2069 1.1 christos { 2070 1.1 christos /* Ranges of the offsets for GOT entries. 2071 1.1 christos R_x entries receive offsets between offset1[R_x] and offset2[R_x]. 2072 1.1 christos R_x is R_8, R_16 and R_32. */ 2073 1.1 christos bfd_vma *offset1; 2074 1.1 christos bfd_vma *offset2; 2075 1.1 christos 2076 1.1 christos /* Mapping from global symndx to global symbols. 2077 1.1 christos This is used to build lists of got entries for global symbols. */ 2078 1.1 christos struct elf_m68k_link_hash_entry **symndx2h; 2079 1.1 christos 2080 1.1 christos bfd_vma n_ldm_entries; 2081 1.1 christos }; 2082 1.1 christos 2083 1.1 christos /* Assign ENTRY an offset. Build list of GOT entries for global symbols 2084 1.1 christos along the way. */ 2085 1.1 christos 2086 1.1 christos static int 2087 1.1 christos elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg) 2088 1.1 christos { 2089 1.1 christos struct elf_m68k_got_entry *entry; 2090 1.1 christos struct elf_m68k_finalize_got_offsets_arg *arg; 2091 1.1 christos 2092 1.1 christos enum elf_m68k_got_offset_size got_offset_size; 2093 1.1 christos bfd_vma entry_size; 2094 1.1 christos 2095 1.1 christos entry = (struct elf_m68k_got_entry *) *entry_ptr; 2096 1.1 christos arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg; 2097 1.1 christos 2098 1.1 christos /* This should be a fresh entry created in elf_m68k_can_merge_gots. */ 2099 1.1 christos BFD_ASSERT (entry->u.s1.refcount == 0); 2100 1.1 christos 2101 1.1 christos /* Get GOT offset size for the entry . */ 2102 1.1 christos got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type); 2103 1.1 christos 2104 1.1 christos /* Calculate entry size in bytes. */ 2105 1.1 christos entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type); 2106 1.1 christos 2107 1.1 christos /* Check if we should switch to negative range of the offsets. */ 2108 1.1 christos if (arg->offset1[got_offset_size] + entry_size 2109 1.1 christos > arg->offset2[got_offset_size]) 2110 1.1 christos { 2111 1.1 christos /* Verify that this is the only switch to negative range for 2112 1.1 christos got_offset_size. If this assertion fails, then we've miscalculated 2113 1.1 christos range for got_offset_size entries in 2114 1.1 christos elf_m68k_finalize_got_offsets. */ 2115 1.1 christos BFD_ASSERT (arg->offset2[got_offset_size] 2116 1.1 christos != arg->offset2[-(int) got_offset_size - 1]); 2117 1.1 christos 2118 1.1 christos /* Switch. */ 2119 1.1 christos arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1]; 2120 1.1 christos arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1]; 2121 1.1 christos 2122 1.1 christos /* Verify that now we have enough room for the entry. */ 2123 1.1 christos BFD_ASSERT (arg->offset1[got_offset_size] + entry_size 2124 1.1 christos <= arg->offset2[got_offset_size]); 2125 1.1 christos } 2126 1.1 christos 2127 1.1 christos /* Assign offset to entry. */ 2128 1.1 christos entry->u.s2.offset = arg->offset1[got_offset_size]; 2129 1.1 christos arg->offset1[got_offset_size] += entry_size; 2130 1.1 christos 2131 1.1 christos if (entry->key_.bfd == NULL) 2132 1.1 christos /* Hook up this entry into the list of got_entries of H. */ 2133 1.1 christos { 2134 1.1 christos struct elf_m68k_link_hash_entry *h; 2135 1.1 christos 2136 1.1 christos h = arg->symndx2h[entry->key_.symndx]; 2137 1.1 christos if (h != NULL) 2138 1.1 christos { 2139 1.1 christos entry->u.s2.next = h->glist; 2140 1.1 christos h->glist = entry; 2141 1.1 christos } 2142 1.1 christos else 2143 1.1 christos /* This should be the entry for TLS_LDM relocation then. */ 2144 1.1 christos { 2145 1.1 christos BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type) 2146 1.1 christos == R_68K_TLS_LDM32) 2147 1.1 christos && entry->key_.symndx == 0); 2148 1.1 christos 2149 1.1 christos ++arg->n_ldm_entries; 2150 1.1 christos } 2151 1.1 christos } 2152 1.1 christos else 2153 1.1 christos /* This entry is for local symbol. */ 2154 1.1 christos entry->u.s2.next = NULL; 2155 1.1 christos 2156 1.1 christos return 1; 2157 1.1 christos } 2158 1.1 christos 2159 1.1 christos /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we 2160 1.1 christos should use negative offsets. 2161 1.1 christos Build list of GOT entries for global symbols along the way. 2162 1.1 christos SYMNDX2H is mapping from global symbol indices to actual 2163 1.1 christos global symbols. 2164 1.1 christos Return offset at which next GOT should start. */ 2165 1.1 christos 2166 1.1 christos static void 2167 1.1.1.10 christos elf_m68k_finalize_got_offsets (struct elf_m68k_got *got, 2168 1.1 christos bool use_neg_got_offsets_p, 2169 1.1 christos struct elf_m68k_link_hash_entry **symndx2h, 2170 1.1 christos bfd_vma *final_offset, bfd_vma *n_ldm_entries) 2171 1.1 christos { 2172 1.1 christos struct elf_m68k_finalize_got_offsets_arg arg_; 2173 1.1 christos bfd_vma offset1_[2 * R_LAST]; 2174 1.1 christos bfd_vma offset2_[2 * R_LAST]; 2175 1.1 christos int i; 2176 1.1 christos bfd_vma start_offset; 2177 1.1 christos 2178 1.1 christos BFD_ASSERT (got->offset != (bfd_vma) -1); 2179 1.1 christos 2180 1.1 christos /* We set entry offsets relative to the .got section (and not the 2181 1.1 christos start of a particular GOT), so that we can use them in 2182 1.1 christos finish_dynamic_symbol without needing to know the GOT which they come 2183 1.1 christos from. */ 2184 1.1 christos 2185 1.1 christos /* Put offset1 in the middle of offset1_, same for offset2. */ 2186 1.1 christos arg_.offset1 = offset1_ + R_LAST; 2187 1.1 christos arg_.offset2 = offset2_ + R_LAST; 2188 1.1 christos 2189 1.1 christos start_offset = got->offset; 2190 1.1 christos 2191 1.1 christos if (use_neg_got_offsets_p) 2192 1.1 christos /* Setup both negative and positive ranges for R_8, R_16 and R_32. */ 2193 1.1 christos i = -(int) R_32 - 1; 2194 1.1 christos else 2195 1.1 christos /* Setup positives ranges for R_8, R_16 and R_32. */ 2196 1.1 christos i = (int) R_8; 2197 1.1 christos 2198 1.1 christos for (; i <= (int) R_32; ++i) 2199 1.1 christos { 2200 1.1 christos int j; 2201 1.1 christos size_t n; 2202 1.1 christos 2203 1.1 christos /* Set beginning of the range of offsets I. */ 2204 1.1 christos arg_.offset1[i] = start_offset; 2205 1.1 christos 2206 1.1 christos /* Calculate number of slots that require I offsets. */ 2207 1.1 christos j = (i >= 0) ? i : -i - 1; 2208 1.1 christos n = (j >= 1) ? got->n_slots[j - 1] : 0; 2209 1.1 christos n = got->n_slots[j] - n; 2210 1.1 christos 2211 1.1 christos if (use_neg_got_offsets_p && n != 0) 2212 1.1 christos { 2213 1.1 christos if (i < 0) 2214 1.1 christos /* We first fill the positive side of the range, so we might 2215 1.1 christos end up with one empty slot at that side when we can't fit 2216 1.1 christos whole 2-slot entry. Account for that at negative side of 2217 1.1 christos the interval with one additional entry. */ 2218 1.1 christos n = n / 2 + 1; 2219 1.1 christos else 2220 1.1 christos /* When the number of slots is odd, make positive side of the 2221 1.1 christos range one entry bigger. */ 2222 1.1 christos n = (n + 1) / 2; 2223 1.1 christos } 2224 1.1 christos 2225 1.1 christos /* N is the number of slots that require I offsets. 2226 1.1 christos Calculate length of the range for I offsets. */ 2227 1.1 christos n = 4 * n; 2228 1.1 christos 2229 1.1 christos /* Set end of the range. */ 2230 1.1 christos arg_.offset2[i] = start_offset + n; 2231 1.1 christos 2232 1.1 christos start_offset = arg_.offset2[i]; 2233 1.1 christos } 2234 1.1 christos 2235 1.1 christos if (!use_neg_got_offsets_p) 2236 1.1 christos /* Make sure that if we try to switch to negative offsets in 2237 1.1 christos elf_m68k_finalize_got_offsets_1, the assert therein will catch 2238 1.1 christos the bug. */ 2239 1.1 christos for (i = R_8; i <= R_32; ++i) 2240 1.1 christos arg_.offset2[-i - 1] = arg_.offset2[i]; 2241 1.1 christos 2242 1.1 christos /* Setup got->offset. offset1[R_8] is either in the middle or at the 2243 1.1 christos beginning of GOT depending on use_neg_got_offsets_p. */ 2244 1.1 christos got->offset = arg_.offset1[R_8]; 2245 1.1 christos 2246 1.1 christos arg_.symndx2h = symndx2h; 2247 1.1 christos arg_.n_ldm_entries = 0; 2248 1.1 christos 2249 1.1 christos /* Assign offsets. */ 2250 1.1 christos htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_); 2251 1.1 christos 2252 1.1 christos /* Check offset ranges we have actually assigned. */ 2253 1.1 christos for (i = (int) R_8; i <= (int) R_32; ++i) 2254 1.1 christos BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4); 2255 1.1 christos 2256 1.1 christos *final_offset = start_offset; 2257 1.1 christos *n_ldm_entries = arg_.n_ldm_entries; 2258 1.1 christos } 2259 1.1 christos 2260 1.1 christos struct elf_m68k_partition_multi_got_arg 2261 1.1 christos { 2262 1.1 christos /* The GOT we are adding entries to. Aka big got. */ 2263 1.1 christos struct elf_m68k_got *current_got; 2264 1.1 christos 2265 1.1 christos /* Offset to assign the next CURRENT_GOT. */ 2266 1.1 christos bfd_vma offset; 2267 1.1 christos 2268 1.1 christos /* Context where memory should be allocated. */ 2269 1.1 christos struct bfd_link_info *info; 2270 1.1 christos 2271 1.1 christos /* Total number of slots in the .got section. 2272 1.1 christos This is used to calculate size of the .got and .rela.got sections. */ 2273 1.1 christos bfd_vma n_slots; 2274 1.1 christos 2275 1.1 christos /* Difference in numbers of allocated slots in the .got section 2276 1.1 christos and necessary relocations in the .rela.got section. 2277 1.1 christos This is used to calculate size of the .rela.got section. */ 2278 1.1 christos bfd_vma slots_relas_diff; 2279 1.1 christos 2280 1.1.1.10 christos /* Error flag. */ 2281 1.1 christos bool error_p; 2282 1.1 christos 2283 1.1 christos /* Mapping from global symndx to global symbols. 2284 1.1 christos This is used to build lists of got entries for global symbols. */ 2285 1.1 christos struct elf_m68k_link_hash_entry **symndx2h; 2286 1.1 christos }; 2287 1.1 christos 2288 1.1 christos static void 2289 1.1 christos elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg) 2290 1.1 christos { 2291 1.1 christos bfd_vma n_ldm_entries; 2292 1.1 christos 2293 1.1 christos elf_m68k_finalize_got_offsets (arg->current_got, 2294 1.1 christos (elf_m68k_hash_table (arg->info) 2295 1.1 christos ->use_neg_got_offsets_p), 2296 1.1 christos arg->symndx2h, 2297 1.1 christos &arg->offset, &n_ldm_entries); 2298 1.1 christos 2299 1.1 christos arg->n_slots += arg->current_got->n_slots[R_32]; 2300 1.1.1.6 christos 2301 1.1 christos if (!bfd_link_pic (arg->info)) 2302 1.1 christos /* If we are generating a shared object, we need to 2303 1.1 christos output a R_68K_RELATIVE reloc so that the dynamic 2304 1.1 christos linker can adjust this GOT entry. Overwise we 2305 1.1 christos don't need space in .rela.got for local symbols. */ 2306 1.1 christos arg->slots_relas_diff += arg->current_got->local_n_slots; 2307 1.1 christos 2308 1.1 christos /* @LDM relocations require a 2-slot GOT entry, but only 2309 1.1 christos one relocation. Account for that. */ 2310 1.1 christos arg->slots_relas_diff += n_ldm_entries; 2311 1.1 christos 2312 1.1 christos BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots); 2313 1.1 christos } 2314 1.1 christos 2315 1.1 christos 2316 1.1 christos /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT 2317 1.1 christos or start a new CURRENT_GOT. */ 2318 1.1 christos 2319 1.1 christos static int 2320 1.1 christos elf_m68k_partition_multi_got_1 (void **_entry, void *_arg) 2321 1.1 christos { 2322 1.1 christos struct elf_m68k_bfd2got_entry *entry; 2323 1.1 christos struct elf_m68k_partition_multi_got_arg *arg; 2324 1.1 christos struct elf_m68k_got *got; 2325 1.1 christos struct elf_m68k_got diff_; 2326 1.1 christos struct elf_m68k_got *diff; 2327 1.1 christos 2328 1.1 christos entry = (struct elf_m68k_bfd2got_entry *) *_entry; 2329 1.1 christos arg = (struct elf_m68k_partition_multi_got_arg *) _arg; 2330 1.1 christos 2331 1.1 christos got = entry->got; 2332 1.1 christos BFD_ASSERT (got != NULL); 2333 1.1 christos BFD_ASSERT (got->offset == (bfd_vma) -1); 2334 1.1 christos 2335 1.1 christos diff = NULL; 2336 1.1 christos 2337 1.1 christos if (arg->current_got != NULL) 2338 1.1 christos /* Construct diff. */ 2339 1.1 christos { 2340 1.1 christos diff = &diff_; 2341 1.1 christos elf_m68k_init_got (diff); 2342 1.1 christos 2343 1.1 christos if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff)) 2344 1.1 christos { 2345 1.1 christos if (diff->offset == 0) 2346 1.1 christos /* Offset set to 0 in the diff_ indicates an error. */ 2347 1.1.1.10 christos { 2348 1.1 christos arg->error_p = true; 2349 1.1 christos goto final_return; 2350 1.1 christos } 2351 1.1 christos 2352 1.1 christos if (elf_m68k_hash_table (arg->info)->allow_multigot_p) 2353 1.1 christos { 2354 1.1 christos elf_m68k_clear_got (diff); 2355 1.1 christos /* Schedule to finish up current_got and start new one. */ 2356 1.1 christos diff = NULL; 2357 1.1 christos } 2358 1.1 christos /* else 2359 1.1 christos Merge GOTs no matter what. If big GOT overflows, 2360 1.1 christos we'll fail in relocate_section due to truncated relocations. 2361 1.1 christos 2362 1.1 christos ??? May be fail earlier? E.g., in can_merge_gots. */ 2363 1.1 christos } 2364 1.1 christos } 2365 1.1 christos else 2366 1.1 christos /* Diff of got against empty current_got is got itself. */ 2367 1.1 christos { 2368 1.1 christos /* Create empty current_got to put subsequent GOTs to. */ 2369 1.1 christos arg->current_got = elf_m68k_create_empty_got (arg->info); 2370 1.1 christos if (arg->current_got == NULL) 2371 1.1.1.10 christos { 2372 1.1 christos arg->error_p = true; 2373 1.1 christos goto final_return; 2374 1.1 christos } 2375 1.1 christos 2376 1.1 christos arg->current_got->offset = arg->offset; 2377 1.1 christos 2378 1.1 christos diff = got; 2379 1.1 christos } 2380 1.1 christos 2381 1.1 christos if (diff != NULL) 2382 1.1 christos { 2383 1.1 christos if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info)) 2384 1.1.1.10 christos { 2385 1.1 christos arg->error_p = true; 2386 1.1 christos goto final_return; 2387 1.1 christos } 2388 1.1 christos 2389 1.1 christos /* Now we can free GOT. */ 2390 1.1 christos elf_m68k_clear_got (got); 2391 1.1 christos 2392 1.1 christos entry->got = arg->current_got; 2393 1.1 christos } 2394 1.1 christos else 2395 1.1 christos { 2396 1.1 christos /* Finish up current_got. */ 2397 1.1 christos elf_m68k_partition_multi_got_2 (arg); 2398 1.1 christos 2399 1.1 christos /* Schedule to start a new current_got. */ 2400 1.1 christos arg->current_got = NULL; 2401 1.1 christos 2402 1.1 christos /* Retry. */ 2403 1.1 christos if (!elf_m68k_partition_multi_got_1 (_entry, _arg)) 2404 1.1 christos { 2405 1.1 christos BFD_ASSERT (arg->error_p); 2406 1.1 christos goto final_return; 2407 1.1 christos } 2408 1.1 christos } 2409 1.1 christos 2410 1.1 christos final_return: 2411 1.1 christos if (diff != NULL) 2412 1.1 christos elf_m68k_clear_got (diff); 2413 1.1.1.8 christos 2414 1.1 christos return !arg->error_p; 2415 1.1 christos } 2416 1.1 christos 2417 1.1 christos /* Helper function to build symndx2h mapping. */ 2418 1.1.1.10 christos 2419 1.1 christos static bool 2420 1.1 christos elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h, 2421 1.1 christos void *_arg) 2422 1.1 christos { 2423 1.1 christos struct elf_m68k_link_hash_entry *h; 2424 1.1 christos 2425 1.1 christos h = elf_m68k_hash_entry (_h); 2426 1.1 christos 2427 1.1 christos if (h->got_entry_key != 0) 2428 1.1 christos /* H has at least one entry in the GOT. */ 2429 1.1 christos { 2430 1.1 christos struct elf_m68k_partition_multi_got_arg *arg; 2431 1.1 christos 2432 1.1 christos arg = (struct elf_m68k_partition_multi_got_arg *) _arg; 2433 1.1 christos 2434 1.1 christos BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL); 2435 1.1 christos arg->symndx2h[h->got_entry_key] = h; 2436 1.1 christos } 2437 1.1.1.10 christos 2438 1.1 christos return true; 2439 1.1 christos } 2440 1.1 christos 2441 1.1 christos /* Merge GOTs of some BFDs, assign offsets to GOT entries and build 2442 1.1 christos lists of GOT entries for global symbols. 2443 1.1 christos Calculate sizes of .got and .rela.got sections. */ 2444 1.1.1.10 christos 2445 1.1 christos static bool 2446 1.1 christos elf_m68k_partition_multi_got (struct bfd_link_info *info) 2447 1.1 christos { 2448 1.1 christos struct elf_m68k_multi_got *multi_got; 2449 1.1 christos struct elf_m68k_partition_multi_got_arg arg_; 2450 1.1 christos 2451 1.1 christos multi_got = elf_m68k_multi_got (info); 2452 1.1 christos 2453 1.1 christos arg_.current_got = NULL; 2454 1.1 christos arg_.offset = 0; 2455 1.1 christos arg_.info = info; 2456 1.1 christos arg_.n_slots = 0; 2457 1.1.1.10 christos arg_.slots_relas_diff = 0; 2458 1.1 christos arg_.error_p = false; 2459 1.1 christos 2460 1.1 christos if (multi_got->bfd2got != NULL) 2461 1.1 christos { 2462 1.1 christos /* Initialize symndx2h mapping. */ 2463 1.1 christos { 2464 1.1 christos arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx 2465 1.1 christos * sizeof (*arg_.symndx2h)); 2466 1.1.1.10 christos if (arg_.symndx2h == NULL) 2467 1.1 christos return false; 2468 1.1 christos 2469 1.1 christos elf_link_hash_traverse (elf_hash_table (info), 2470 1.1 christos elf_m68k_init_symndx2h_1, &arg_); 2471 1.1 christos } 2472 1.1 christos 2473 1.1 christos /* Partition. */ 2474 1.1 christos htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1, 2475 1.1 christos &arg_); 2476 1.1 christos if (arg_.error_p) 2477 1.1 christos { 2478 1.1 christos free (arg_.symndx2h); 2479 1.1 christos arg_.symndx2h = NULL; 2480 1.1.1.10 christos 2481 1.1 christos return false; 2482 1.1 christos } 2483 1.1 christos 2484 1.1 christos /* Finish up last current_got. */ 2485 1.1 christos elf_m68k_partition_multi_got_2 (&arg_); 2486 1.1 christos 2487 1.1 christos free (arg_.symndx2h); 2488 1.1 christos } 2489 1.1 christos 2490 1.1 christos if (elf_hash_table (info)->dynobj != NULL) 2491 1.1 christos /* Set sizes of .got and .rela.got sections. */ 2492 1.1 christos { 2493 1.1 christos asection *s; 2494 1.1.1.7 christos 2495 1.1 christos s = elf_hash_table (info)->sgot; 2496 1.1 christos if (s != NULL) 2497 1.1 christos s->size = arg_.offset; 2498 1.1 christos else 2499 1.1 christos BFD_ASSERT (arg_.offset == 0); 2500 1.1 christos 2501 1.1 christos BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots); 2502 1.1 christos arg_.n_slots -= arg_.slots_relas_diff; 2503 1.1.1.7 christos 2504 1.1 christos s = elf_hash_table (info)->srelgot; 2505 1.1 christos if (s != NULL) 2506 1.1 christos s->size = arg_.n_slots * sizeof (Elf32_External_Rela); 2507 1.1 christos else 2508 1.1 christos BFD_ASSERT (arg_.n_slots == 0); 2509 1.1 christos } 2510 1.1 christos else 2511 1.1 christos BFD_ASSERT (multi_got->bfd2got == NULL); 2512 1.1.1.10 christos 2513 1.1 christos return true; 2514 1.1 christos } 2515 1.1 christos 2516 1.1 christos /* Copy any information related to dynamic linking from a pre-existing 2517 1.1 christos symbol to a newly created symbol. Also called to copy flags and 2518 1.1 christos other back-end info to a weakdef, in which case the symbol is not 2519 1.1 christos newly created and plt/got refcounts and dynamic indices should not 2520 1.1 christos be copied. */ 2521 1.1 christos 2522 1.1 christos static void 2523 1.1 christos elf_m68k_copy_indirect_symbol (struct bfd_link_info *info, 2524 1.1 christos struct elf_link_hash_entry *_dir, 2525 1.1 christos struct elf_link_hash_entry *_ind) 2526 1.1 christos { 2527 1.1 christos struct elf_m68k_link_hash_entry *dir; 2528 1.1 christos struct elf_m68k_link_hash_entry *ind; 2529 1.1 christos 2530 1.1 christos _bfd_elf_link_hash_copy_indirect (info, _dir, _ind); 2531 1.1 christos 2532 1.1 christos if (_ind->root.type != bfd_link_hash_indirect) 2533 1.1 christos return; 2534 1.1 christos 2535 1.1 christos dir = elf_m68k_hash_entry (_dir); 2536 1.1 christos ind = elf_m68k_hash_entry (_ind); 2537 1.1 christos 2538 1.1 christos /* Any absolute non-dynamic relocations against an indirect or weak 2539 1.1 christos definition will be against the target symbol. */ 2540 1.1 christos _dir->non_got_ref |= _ind->non_got_ref; 2541 1.1 christos 2542 1.1 christos /* We might have a direct symbol already having entries in the GOTs. 2543 1.1 christos Update its key only in case indirect symbol has GOT entries and 2544 1.1 christos assert that both indirect and direct symbols don't have GOT entries 2545 1.1 christos at the same time. */ 2546 1.1 christos if (ind->got_entry_key != 0) 2547 1.1 christos { 2548 1.1 christos BFD_ASSERT (dir->got_entry_key == 0); 2549 1.1 christos /* Assert that GOTs aren't partioned yet. */ 2550 1.1 christos BFD_ASSERT (ind->glist == NULL); 2551 1.1 christos 2552 1.1 christos dir->got_entry_key = ind->got_entry_key; 2553 1.1 christos ind->got_entry_key = 0; 2554 1.1 christos } 2555 1.1 christos } 2556 1.1 christos 2557 1.1 christos /* Look through the relocs for a section during the first phase, and 2558 1.1 christos allocate space in the global offset table or procedure linkage 2559 1.1 christos table. */ 2560 1.1.1.10 christos 2561 1.1.1.2 christos static bool 2562 1.1.1.2 christos elf_m68k_check_relocs (bfd *abfd, 2563 1.1.1.2 christos struct bfd_link_info *info, 2564 1.1.1.2 christos asection *sec, 2565 1.1 christos const Elf_Internal_Rela *relocs) 2566 1.1 christos { 2567 1.1 christos bfd *dynobj; 2568 1.1 christos Elf_Internal_Shdr *symtab_hdr; 2569 1.1 christos struct elf_link_hash_entry **sym_hashes; 2570 1.1 christos const Elf_Internal_Rela *rel; 2571 1.1 christos const Elf_Internal_Rela *rel_end; 2572 1.1 christos asection *sreloc; 2573 1.1 christos struct elf_m68k_got *got; 2574 1.1.1.6 christos 2575 1.1.1.10 christos if (bfd_link_relocatable (info)) 2576 1.1 christos return true; 2577 1.1 christos 2578 1.1 christos dynobj = elf_hash_table (info)->dynobj; 2579 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 2580 1.1 christos sym_hashes = elf_sym_hashes (abfd); 2581 1.1 christos 2582 1.1 christos sreloc = NULL; 2583 1.1 christos 2584 1.1 christos got = NULL; 2585 1.1 christos 2586 1.1 christos rel_end = relocs + sec->reloc_count; 2587 1.1 christos for (rel = relocs; rel < rel_end; rel++) 2588 1.1 christos { 2589 1.1 christos unsigned long r_symndx; 2590 1.1 christos struct elf_link_hash_entry *h; 2591 1.1 christos 2592 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 2593 1.1 christos 2594 1.1 christos if (r_symndx < symtab_hdr->sh_info) 2595 1.1 christos h = NULL; 2596 1.1 christos else 2597 1.1 christos { 2598 1.1 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 2599 1.1 christos while (h->root.type == bfd_link_hash_indirect 2600 1.1 christos || h->root.type == bfd_link_hash_warning) 2601 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 2602 1.1 christos } 2603 1.1 christos 2604 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 2605 1.1 christos { 2606 1.1 christos case R_68K_GOT8: 2607 1.1 christos case R_68K_GOT16: 2608 1.1 christos case R_68K_GOT32: 2609 1.1 christos if (h != NULL 2610 1.1 christos && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 2611 1.1 christos break; 2612 1.1 christos /* Fall through. */ 2613 1.1 christos 2614 1.1 christos /* Relative GOT relocations. */ 2615 1.1 christos case R_68K_GOT8O: 2616 1.1 christos case R_68K_GOT16O: 2617 1.1 christos case R_68K_GOT32O: 2618 1.1 christos /* Fall through. */ 2619 1.1 christos 2620 1.1 christos /* TLS relocations. */ 2621 1.1 christos case R_68K_TLS_GD8: 2622 1.1 christos case R_68K_TLS_GD16: 2623 1.1 christos case R_68K_TLS_GD32: 2624 1.1 christos case R_68K_TLS_LDM8: 2625 1.1 christos case R_68K_TLS_LDM16: 2626 1.1 christos case R_68K_TLS_LDM32: 2627 1.1 christos case R_68K_TLS_IE8: 2628 1.1 christos case R_68K_TLS_IE16: 2629 1.1 christos case R_68K_TLS_IE32: 2630 1.1 christos 2631 1.1 christos case R_68K_TLS_TPREL32: 2632 1.1 christos case R_68K_TLS_DTPREL32: 2633 1.1 christos 2634 1.1.1.6 christos if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32 2635 1.1 christos && bfd_link_pic (info)) 2636 1.1 christos /* Do the special chorus for libraries with static TLS. */ 2637 1.1 christos info->flags |= DF_STATIC_TLS; 2638 1.1 christos 2639 1.1 christos /* This symbol requires a global offset table entry. */ 2640 1.1 christos 2641 1.1 christos if (dynobj == NULL) 2642 1.1 christos { 2643 1.1 christos /* Create the .got section. */ 2644 1.1 christos elf_hash_table (info)->dynobj = dynobj = abfd; 2645 1.1.1.10 christos if (!_bfd_elf_create_got_section (dynobj, info)) 2646 1.1 christos return false; 2647 1.1 christos } 2648 1.1 christos 2649 1.1 christos if (got == NULL) 2650 1.1 christos { 2651 1.1 christos struct elf_m68k_bfd2got_entry *bfd2got_entry; 2652 1.1 christos 2653 1.1 christos bfd2got_entry 2654 1.1 christos = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), 2655 1.1 christos abfd, FIND_OR_CREATE, info); 2656 1.1.1.10 christos if (bfd2got_entry == NULL) 2657 1.1 christos return false; 2658 1.1 christos 2659 1.1 christos got = bfd2got_entry->got; 2660 1.1 christos BFD_ASSERT (got != NULL); 2661 1.1 christos } 2662 1.1 christos 2663 1.1 christos { 2664 1.1 christos struct elf_m68k_got_entry *got_entry; 2665 1.1 christos 2666 1.1 christos /* Add entry to got. */ 2667 1.1 christos got_entry = elf_m68k_add_entry_to_got (got, h, abfd, 2668 1.1 christos ELF32_R_TYPE (rel->r_info), 2669 1.1 christos r_symndx, info); 2670 1.1.1.10 christos if (got_entry == NULL) 2671 1.1 christos return false; 2672 1.1 christos 2673 1.1 christos if (got_entry->u.s1.refcount == 1) 2674 1.1 christos { 2675 1.1 christos /* Make sure this symbol is output as a dynamic symbol. */ 2676 1.1 christos if (h != NULL 2677 1.1 christos && h->dynindx == -1 2678 1.1 christos && !h->forced_local) 2679 1.1 christos { 2680 1.1.1.10 christos if (!bfd_elf_link_record_dynamic_symbol (info, h)) 2681 1.1 christos return false; 2682 1.1 christos } 2683 1.1 christos } 2684 1.1 christos } 2685 1.1 christos 2686 1.1 christos break; 2687 1.1 christos 2688 1.1 christos case R_68K_PLT8: 2689 1.1 christos case R_68K_PLT16: 2690 1.1 christos case R_68K_PLT32: 2691 1.1 christos /* This symbol requires a procedure linkage table entry. We 2692 1.1.1.8 christos actually build the entry in adjust_dynamic_symbol, 2693 1.1.1.8 christos because this might be a case of linking PIC code which is 2694 1.1.1.8 christos never referenced by a dynamic object, in which case we 2695 1.1.1.8 christos don't need to generate a procedure linkage table entry 2696 1.1 christos after all. */ 2697 1.1 christos 2698 1.1 christos /* If this is a local symbol, we resolve it directly without 2699 1.1 christos creating a procedure linkage table entry. */ 2700 1.1 christos if (h == NULL) 2701 1.1 christos continue; 2702 1.1 christos 2703 1.1 christos h->needs_plt = 1; 2704 1.1 christos h->plt.refcount++; 2705 1.1 christos break; 2706 1.1 christos 2707 1.1 christos case R_68K_PLT8O: 2708 1.1 christos case R_68K_PLT16O: 2709 1.1 christos case R_68K_PLT32O: 2710 1.1 christos /* This symbol requires a procedure linkage table entry. */ 2711 1.1 christos 2712 1.1 christos if (h == NULL) 2713 1.1 christos { 2714 1.1 christos /* It does not make sense to have this relocation for a 2715 1.1 christos local symbol. FIXME: does it? How to handle it if 2716 1.1 christos it does make sense? */ 2717 1.1.1.10 christos bfd_set_error (bfd_error_bad_value); 2718 1.1 christos return false; 2719 1.1 christos } 2720 1.1 christos 2721 1.1 christos /* Make sure this symbol is output as a dynamic symbol. */ 2722 1.1 christos if (h->dynindx == -1 2723 1.1 christos && !h->forced_local) 2724 1.1 christos { 2725 1.1.1.10 christos if (!bfd_elf_link_record_dynamic_symbol (info, h)) 2726 1.1 christos return false; 2727 1.1 christos } 2728 1.1 christos 2729 1.1 christos h->needs_plt = 1; 2730 1.1 christos h->plt.refcount++; 2731 1.1 christos break; 2732 1.1 christos 2733 1.1 christos case R_68K_PC8: 2734 1.1 christos case R_68K_PC16: 2735 1.1 christos case R_68K_PC32: 2736 1.1 christos /* If we are creating a shared library and this is not a local 2737 1.1 christos symbol, we need to copy the reloc into the shared library. 2738 1.1 christos However when linking with -Bsymbolic and this is a global 2739 1.1 christos symbol which is defined in an object we are including in the 2740 1.1 christos link (i.e., DEF_REGULAR is set), then we can resolve the 2741 1.1 christos reloc directly. At this point we have not seen all the input 2742 1.1 christos files, so it is possible that DEF_REGULAR is not set now but 2743 1.1 christos will be set later (it is never cleared). We account for that 2744 1.1 christos possibility below by storing information in the 2745 1.1.1.6 christos pcrel_relocs_copied field of the hash table entry. */ 2746 1.1 christos if (!(bfd_link_pic (info) 2747 1.1 christos && (sec->flags & SEC_ALLOC) != 0 2748 1.1.1.6 christos && h != NULL 2749 1.1 christos && (!SYMBOLIC_BIND (info, h) 2750 1.1 christos || h->root.type == bfd_link_hash_defweak 2751 1.1 christos || !h->def_regular))) 2752 1.1 christos { 2753 1.1 christos if (h != NULL) 2754 1.1 christos { 2755 1.1 christos /* Make sure a plt entry is created for this symbol if 2756 1.1 christos it turns out to be a function defined by a dynamic 2757 1.1 christos object. */ 2758 1.1 christos h->plt.refcount++; 2759 1.1 christos } 2760 1.1 christos break; 2761 1.1 christos } 2762 1.1 christos /* Fall through. */ 2763 1.1 christos case R_68K_8: 2764 1.1 christos case R_68K_16: 2765 1.1.1.2 christos case R_68K_32: 2766 1.1.1.2 christos /* We don't need to handle relocs into sections not going into 2767 1.1.1.2 christos the "real" output. */ 2768 1.1.1.2 christos if ((sec->flags & SEC_ALLOC) == 0) 2769 1.1.1.2 christos break; 2770 1.1 christos 2771 1.1 christos if (h != NULL) 2772 1.1 christos { 2773 1.1 christos /* Make sure a plt entry is created for this symbol if it 2774 1.1 christos turns out to be a function defined by a dynamic object. */ 2775 1.1 christos h->plt.refcount++; 2776 1.1.1.6 christos 2777 1.1 christos if (bfd_link_executable (info)) 2778 1.1 christos /* This symbol needs a non-GOT reference. */ 2779 1.1 christos h->non_got_ref = 1; 2780 1.1 christos } 2781 1.1 christos 2782 1.1 christos /* If we are creating a shared library, we need to copy the 2783 1.1.1.8 christos reloc into the shared library. */ 2784 1.1.1.8 christos if (bfd_link_pic (info) 2785 1.1.1.8 christos && (h == NULL 2786 1.1 christos || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) 2787 1.1 christos { 2788 1.1 christos /* When creating a shared object, we must copy these 2789 1.1 christos reloc types into the output file. We create a reloc 2790 1.1 christos section in dynobj and make room for this reloc. */ 2791 1.1 christos if (sreloc == NULL) 2792 1.1 christos { 2793 1.1.1.10 christos sreloc = _bfd_elf_make_dynamic_reloc_section 2794 1.1 christos (sec, dynobj, 2, abfd, /*rela?*/ true); 2795 1.1 christos 2796 1.1.1.10 christos if (sreloc == NULL) 2797 1.1 christos return false; 2798 1.1 christos } 2799 1.1 christos 2800 1.1 christos if (sec->flags & SEC_READONLY 2801 1.1 christos /* Don't set DF_TEXTREL yet for PC relative 2802 1.1 christos relocations, they might be discarded later. */ 2803 1.1 christos && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8 2804 1.1 christos || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 2805 1.1 christos || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)) 2806 1.1 christos info->flags |= DF_TEXTREL; 2807 1.1 christos 2808 1.1 christos sreloc->size += sizeof (Elf32_External_Rela); 2809 1.1 christos 2810 1.1 christos /* We count the number of PC relative relocations we have 2811 1.1 christos entered for this symbol, so that we can discard them 2812 1.1 christos again if, in the -Bsymbolic case, the symbol is later 2813 1.1 christos defined by a regular object, or, in the normal shared 2814 1.1 christos case, the symbol is forced to be local. Note that this 2815 1.1 christos function is only called if we are using an m68kelf linker 2816 1.1 christos hash table, which means that h is really a pointer to an 2817 1.1 christos elf_m68k_link_hash_entry. */ 2818 1.1 christos if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8 2819 1.1 christos || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 2820 1.1 christos || ELF32_R_TYPE (rel->r_info) == R_68K_PC32) 2821 1.1 christos { 2822 1.1 christos struct elf_m68k_pcrel_relocs_copied *p; 2823 1.1 christos struct elf_m68k_pcrel_relocs_copied **head; 2824 1.1 christos 2825 1.1 christos if (h != NULL) 2826 1.1 christos { 2827 1.1 christos struct elf_m68k_link_hash_entry *eh 2828 1.1 christos = elf_m68k_hash_entry (h); 2829 1.1 christos head = &eh->pcrel_relocs_copied; 2830 1.1 christos } 2831 1.1 christos else 2832 1.1 christos { 2833 1.1 christos asection *s; 2834 1.1 christos void *vpp; 2835 1.1 christos Elf_Internal_Sym *isym; 2836 1.1.1.9 christos 2837 1.1 christos isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->root.sym_cache, 2838 1.1 christos abfd, r_symndx); 2839 1.1.1.10 christos if (isym == NULL) 2840 1.1 christos return false; 2841 1.1 christos 2842 1.1 christos s = bfd_section_from_elf_index (abfd, isym->st_shndx); 2843 1.1 christos if (s == NULL) 2844 1.1 christos s = sec; 2845 1.1 christos 2846 1.1 christos vpp = &elf_section_data (s)->local_dynrel; 2847 1.1 christos head = (struct elf_m68k_pcrel_relocs_copied **) vpp; 2848 1.1 christos } 2849 1.1 christos 2850 1.1 christos for (p = *head; p != NULL; p = p->next) 2851 1.1 christos if (p->section == sreloc) 2852 1.1 christos break; 2853 1.1 christos 2854 1.1 christos if (p == NULL) 2855 1.1 christos { 2856 1.1 christos p = ((struct elf_m68k_pcrel_relocs_copied *) 2857 1.1 christos bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); 2858 1.1.1.10 christos if (p == NULL) 2859 1.1 christos return false; 2860 1.1 christos p->next = *head; 2861 1.1 christos *head = p; 2862 1.1 christos p->section = sreloc; 2863 1.1 christos p->count = 0; 2864 1.1 christos } 2865 1.1 christos 2866 1.1 christos ++p->count; 2867 1.1 christos } 2868 1.1 christos } 2869 1.1 christos 2870 1.1 christos break; 2871 1.1 christos 2872 1.1 christos /* This relocation describes the C++ object vtable hierarchy. 2873 1.1 christos Reconstruct it for later use during GC. */ 2874 1.1 christos case R_68K_GNU_VTINHERIT: 2875 1.1.1.10 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 2876 1.1 christos return false; 2877 1.1 christos break; 2878 1.1 christos 2879 1.1 christos /* This relocation describes which C++ vtable entries are actually 2880 1.1 christos used. Record for later use during GC. */ 2881 1.1.1.9 christos case R_68K_GNU_VTENTRY: 2882 1.1.1.10 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 2883 1.1 christos return false; 2884 1.1 christos break; 2885 1.1 christos 2886 1.1 christos default: 2887 1.1 christos break; 2888 1.1 christos } 2889 1.1 christos } 2890 1.1.1.10 christos 2891 1.1 christos return true; 2892 1.1 christos } 2893 1.1 christos 2894 1.1 christos /* Return the section that should be marked against GC for a given 2895 1.1 christos relocation. */ 2896 1.1 christos 2897 1.1 christos static asection * 2898 1.1 christos elf_m68k_gc_mark_hook (asection *sec, 2899 1.1 christos struct bfd_link_info *info, 2900 1.1 christos Elf_Internal_Rela *rel, 2901 1.1 christos struct elf_link_hash_entry *h, 2902 1.1 christos Elf_Internal_Sym *sym) 2903 1.1 christos { 2904 1.1 christos if (h != NULL) 2905 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 2906 1.1 christos { 2907 1.1 christos case R_68K_GNU_VTINHERIT: 2908 1.1 christos case R_68K_GNU_VTENTRY: 2909 1.1 christos return NULL; 2910 1.1 christos } 2911 1.1 christos 2912 1.1 christos return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 2913 1.1 christos } 2914 1.1 christos 2915 1.1 christos /* Return the type of PLT associated with OUTPUT_BFD. */ 2917 1.1 christos 2918 1.1 christos static const struct elf_m68k_plt_info * 2919 1.1 christos elf_m68k_get_plt_info (bfd *output_bfd) 2920 1.1 christos { 2921 1.1 christos unsigned int features; 2922 1.1 christos 2923 1.1 christos features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd)); 2924 1.1 christos if (features & cpu32) 2925 1.1 christos return &elf_cpu32_plt_info; 2926 1.1 christos if (features & mcfisa_b) 2927 1.1 christos return &elf_isab_plt_info; 2928 1.1 christos if (features & mcfisa_c) 2929 1.1 christos return &elf_isac_plt_info; 2930 1.1 christos return &elf_m68k_plt_info; 2931 1.1 christos } 2932 1.1 christos 2933 1.1 christos /* This function is called after all the input files have been read, 2934 1.1 christos and the input sections have been assigned to output sections. 2935 1.1.1.10 christos It's a convenient place to determine the PLT style. */ 2936 1.1.1.11 christos 2937 1.1 christos static bool 2938 1.1 christos elf_m68k_early_size_sections (bfd *output_bfd, struct bfd_link_info *info) 2939 1.1 christos { 2940 1.1 christos /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got 2941 1.1.1.10 christos sections. */ 2942 1.1 christos if (!elf_m68k_partition_multi_got (info)) 2943 1.1 christos return false; 2944 1.1.1.10 christos 2945 1.1 christos elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd); 2946 1.1 christos return true; 2947 1.1 christos } 2948 1.1 christos 2949 1.1 christos /* Adjust a symbol defined by a dynamic object and referenced by a 2950 1.1 christos regular object. The current definition is in some section of the 2951 1.1 christos dynamic object, but we're not including those sections. We have to 2952 1.1 christos change the definition to something the rest of the link can 2953 1.1.1.10 christos understand. */ 2954 1.1.1.2 christos 2955 1.1.1.2 christos static bool 2956 1.1 christos elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info, 2957 1.1 christos struct elf_link_hash_entry *h) 2958 1.1 christos { 2959 1.1 christos struct elf_m68k_link_hash_table *htab; 2960 1.1 christos bfd *dynobj; 2961 1.1 christos asection *s; 2962 1.1.1.7 christos 2963 1.1 christos htab = elf_m68k_hash_table (info); 2964 1.1 christos dynobj = htab->root.dynobj; 2965 1.1 christos 2966 1.1 christos /* Make sure we know what is going on here. */ 2967 1.1.1.8 christos BFD_ASSERT (dynobj != NULL 2968 1.1 christos && (h->needs_plt 2969 1.1 christos || h->is_weakalias 2970 1.1 christos || (h->def_dynamic 2971 1.1 christos && h->ref_regular 2972 1.1 christos && !h->def_regular))); 2973 1.1 christos 2974 1.1 christos /* If this is a function, put it in the procedure linkage table. We 2975 1.1 christos will fill in the contents of the procedure linkage table later, 2976 1.1 christos when we know the address of the .got section. */ 2977 1.1 christos if (h->type == STT_FUNC 2978 1.1 christos || h->needs_plt) 2979 1.1.1.8 christos { 2980 1.1.1.8 christos if ((h->plt.refcount <= 0 2981 1.1.1.8 christos || SYMBOL_CALLS_LOCAL (info, h) 2982 1.1 christos || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 2983 1.1 christos || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) 2984 1.1 christos && h->root.type == bfd_link_hash_undefweak)) 2985 1.1 christos /* We must always create the plt entry if it was referenced 2986 1.1 christos by a PLTxxO relocation. In this case we already recorded 2987 1.1 christos it as a dynamic symbol. */ 2988 1.1 christos && h->dynindx == -1) 2989 1.1 christos { 2990 1.1 christos /* This case can occur if we saw a PLTxx reloc in an input 2991 1.1 christos file, but the symbol was never referred to by a dynamic 2992 1.1 christos object, or if all references were garbage collected. In 2993 1.1 christos such a case, we don't actually need to build a procedure 2994 1.1 christos linkage table, and we can just do a PCxx reloc instead. */ 2995 1.1.1.10 christos h->plt.offset = (bfd_vma) -1; 2996 1.1 christos h->needs_plt = 0; 2997 1.1 christos return true; 2998 1.1 christos } 2999 1.1 christos 3000 1.1 christos /* Make sure this symbol is output as a dynamic symbol. */ 3001 1.1 christos if (h->dynindx == -1 3002 1.1 christos && !h->forced_local) 3003 1.1.1.10 christos { 3004 1.1 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 3005 1.1 christos return false; 3006 1.1.1.7 christos } 3007 1.1 christos 3008 1.1 christos s = htab->root.splt; 3009 1.1 christos BFD_ASSERT (s != NULL); 3010 1.1 christos 3011 1.1 christos /* If this is the first .plt entry, make room for the special 3012 1.1 christos first entry. */ 3013 1.1 christos if (s->size == 0) 3014 1.1 christos s->size = htab->plt_info->size; 3015 1.1 christos 3016 1.1 christos /* If this symbol is not defined in a regular file, and we are 3017 1.1 christos not generating a shared library, then set the symbol to this 3018 1.1 christos location in the .plt. This is required to make function 3019 1.1.1.6 christos pointers compare as equal between the normal executable and 3020 1.1 christos the shared library. */ 3021 1.1 christos if (!bfd_link_pic (info) 3022 1.1 christos && !h->def_regular) 3023 1.1 christos { 3024 1.1 christos h->root.u.def.section = s; 3025 1.1 christos h->root.u.def.value = s->size; 3026 1.1 christos } 3027 1.1 christos 3028 1.1 christos h->plt.offset = s->size; 3029 1.1 christos 3030 1.1 christos /* Make room for this entry. */ 3031 1.1 christos s->size += htab->plt_info->size; 3032 1.1 christos 3033 1.1.1.7 christos /* We also need to make an entry in the .got.plt section, which 3034 1.1 christos will be placed in the .got section by the linker script. */ 3035 1.1 christos s = htab->root.sgotplt; 3036 1.1 christos BFD_ASSERT (s != NULL); 3037 1.1 christos s->size += 4; 3038 1.1.1.7 christos 3039 1.1 christos /* We also need to make an entry in the .rela.plt section. */ 3040 1.1 christos s = htab->root.srelplt; 3041 1.1 christos BFD_ASSERT (s != NULL); 3042 1.1.1.10 christos s->size += sizeof (Elf32_External_Rela); 3043 1.1 christos 3044 1.1 christos return true; 3045 1.1 christos } 3046 1.1 christos 3047 1.1 christos /* Reinitialize the plt offset now that it is not used as a reference 3048 1.1 christos count any more. */ 3049 1.1 christos h->plt.offset = (bfd_vma) -1; 3050 1.1 christos 3051 1.1 christos /* If this is a weak symbol, and there is a real definition, the 3052 1.1.1.8 christos processor independent code will have arranged for us to see the 3053 1.1 christos real definition first, and we can just use the same value. */ 3054 1.1.1.8 christos if (h->is_weakalias) 3055 1.1.1.8 christos { 3056 1.1.1.8 christos struct elf_link_hash_entry *def = weakdef (h); 3057 1.1.1.8 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined); 3058 1.1.1.10 christos h->root.u.def.section = def->root.u.def.section; 3059 1.1 christos h->root.u.def.value = def->root.u.def.value; 3060 1.1 christos return true; 3061 1.1 christos } 3062 1.1 christos 3063 1.1 christos /* This is a reference to a symbol defined by a dynamic object which 3064 1.1 christos is not a function. */ 3065 1.1 christos 3066 1.1 christos /* If we are creating a shared library, we must presume that the 3067 1.1 christos only references to the symbol are via the global offset table. 3068 1.1.1.6 christos For such cases we need not do anything here; the relocations will 3069 1.1.1.10 christos be handled correctly by relocate_section. */ 3070 1.1 christos if (bfd_link_pic (info)) 3071 1.1 christos return true; 3072 1.1 christos 3073 1.1 christos /* If there are no references to this symbol that do not use the 3074 1.1.1.10 christos GOT, we don't need to generate a copy reloc. */ 3075 1.1 christos if (!h->non_got_ref) 3076 1.1 christos return true; 3077 1.1 christos 3078 1.1 christos /* We must allocate the symbol in our .dynbss section, which will 3079 1.1 christos become part of the .bss section of the executable. There will be 3080 1.1 christos an entry for this symbol in the .dynsym section. The dynamic 3081 1.1 christos object will contain position independent code, so all references 3082 1.1 christos from the dynamic object to this symbol will go through the global 3083 1.1 christos offset table. The dynamic linker will use the .dynsym entry to 3084 1.1 christos determine the address it must put in the global offset table, so 3085 1.1 christos both the dynamic object and the regular object will refer to the 3086 1.1.1.2 christos same memory location for the variable. */ 3087 1.1 christos 3088 1.1 christos s = bfd_get_linker_section (dynobj, ".dynbss"); 3089 1.1 christos BFD_ASSERT (s != NULL); 3090 1.1 christos 3091 1.1 christos /* We must generate a R_68K_COPY reloc to tell the dynamic linker to 3092 1.1 christos copy the initial value out of the dynamic object and into the 3093 1.1.1.2 christos runtime process image. We need to remember the offset into the 3094 1.1 christos .rela.bss section we are going to use. */ 3095 1.1 christos if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) 3096 1.1 christos { 3097 1.1.1.2 christos asection *srel; 3098 1.1 christos 3099 1.1 christos srel = bfd_get_linker_section (dynobj, ".rela.bss"); 3100 1.1 christos BFD_ASSERT (srel != NULL); 3101 1.1 christos srel->size += sizeof (Elf32_External_Rela); 3102 1.1 christos h->needs_copy = 1; 3103 1.1.1.4 christos } 3104 1.1 christos 3105 1.1 christos return _bfd_elf_adjust_dynamic_copy (info, h, s); 3106 1.1 christos } 3107 1.1 christos 3108 1.1.1.10 christos /* Set the sizes of the dynamic sections. */ 3109 1.1.1.11 christos 3110 1.1.1.11 christos static bool 3111 1.1 christos elf_m68k_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 3112 1.1 christos struct bfd_link_info *info) 3113 1.1 christos { 3114 1.1.1.10 christos bfd *dynobj; 3115 1.1 christos asection *s; 3116 1.1 christos bool relocs; 3117 1.1.1.11 christos 3118 1.1.1.11 christos dynobj = elf_hash_table (info)->dynobj; 3119 1.1 christos if (dynobj == NULL) 3120 1.1 christos return true; 3121 1.1 christos 3122 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 3123 1.1.1.6 christos { 3124 1.1 christos /* Set the contents of the .interp section to the interpreter. */ 3125 1.1.1.2 christos if (bfd_link_executable (info) && !info->nointerp) 3126 1.1 christos { 3127 1.1 christos s = bfd_get_linker_section (dynobj, ".interp"); 3128 1.1 christos BFD_ASSERT (s != NULL); 3129 1.1.1.13 christos s->size = sizeof ELF_DYNAMIC_INTERPRETER; 3130 1.1 christos s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 3131 1.1 christos s->alloced = 1; 3132 1.1 christos } 3133 1.1 christos } 3134 1.1 christos else 3135 1.1 christos { 3136 1.1 christos /* We may have created entries in the .rela.got section. 3137 1.1 christos However, if we are not creating the dynamic sections, we will 3138 1.1 christos not actually use these entries. Reset the size of .rela.got, 3139 1.1.1.7 christos which will cause it to get stripped from the output file 3140 1.1 christos below. */ 3141 1.1 christos s = elf_hash_table (info)->srelgot; 3142 1.1 christos if (s != NULL) 3143 1.1 christos s->size = 0; 3144 1.1 christos } 3145 1.1 christos 3146 1.1 christos /* If this is a -Bsymbolic shared link, then we need to discard all 3147 1.1 christos PC relative relocs against symbols defined in a regular object. 3148 1.1 christos For the normal shared case we discard the PC relative relocs 3149 1.1 christos against symbols that have become local due to visibility changes. 3150 1.1.1.6 christos We allocated space for them in the check_relocs routine, but we 3151 1.1 christos will not fill them in in the relocate_section routine. */ 3152 1.1 christos if (bfd_link_pic (info)) 3153 1.1.1.2 christos elf_link_hash_traverse (elf_hash_table (info), 3154 1.1 christos elf_m68k_discard_copies, 3155 1.1 christos info); 3156 1.1 christos 3157 1.1 christos /* The check_relocs and adjust_dynamic_symbol entry points have 3158 1.1.1.10 christos determined the sizes of the various dynamic sections. Allocate 3159 1.1 christos memory for them. */ 3160 1.1 christos relocs = false; 3161 1.1 christos for (s = dynobj->sections; s != NULL; s = s->next) 3162 1.1 christos { 3163 1.1 christos const char *name; 3164 1.1 christos 3165 1.1 christos if ((s->flags & SEC_LINKER_CREATED) == 0) 3166 1.1 christos continue; 3167 1.1 christos 3168 1.1.1.9 christos /* It's OK to base decisions on the section name, because none 3169 1.1 christos of the dynobj section names depend upon the input files. */ 3170 1.1 christos name = bfd_section_name (s); 3171 1.1 christos 3172 1.1 christos if (strcmp (name, ".plt") == 0) 3173 1.1.1.9 christos { 3174 1.1 christos /* Remember whether there is a PLT. */ 3175 1.1.1.10 christos ; 3176 1.1 christos } 3177 1.1 christos else if (startswith (name, ".rela")) 3178 1.1 christos { 3179 1.1.1.10 christos if (s->size != 0) 3180 1.1 christos { 3181 1.1 christos relocs = true; 3182 1.1 christos 3183 1.1 christos /* We use the reloc_count field as a counter if we need 3184 1.1 christos to copy relocs into the output file. */ 3185 1.1 christos s->reloc_count = 0; 3186 1.1.1.10 christos } 3187 1.1 christos } 3188 1.1 christos else if (! startswith (name, ".got") 3189 1.1 christos && strcmp (name, ".dynbss") != 0) 3190 1.1 christos { 3191 1.1 christos /* It's not one of our sections, so don't allocate space. */ 3192 1.1 christos continue; 3193 1.1 christos } 3194 1.1 christos 3195 1.1 christos if (s->size == 0) 3196 1.1 christos { 3197 1.1 christos /* If we don't need this section, strip it from the 3198 1.1 christos output file. This is mostly to handle .rela.bss and 3199 1.1 christos .rela.plt. We must create both sections in 3200 1.1 christos create_dynamic_sections, because they must be created 3201 1.1 christos before the linker maps input sections to output 3202 1.1 christos sections. The linker does that before 3203 1.1 christos adjust_dynamic_symbol is called, and it is that 3204 1.1 christos function which decides whether anything needs to go 3205 1.1 christos into these sections. */ 3206 1.1 christos s->flags |= SEC_EXCLUDE; 3207 1.1 christos continue; 3208 1.1 christos } 3209 1.1 christos 3210 1.1 christos if ((s->flags & SEC_HAS_CONTENTS) == 0) 3211 1.1 christos continue; 3212 1.1 christos 3213 1.1 christos /* Allocate memory for the section contents. */ 3214 1.1 christos /* FIXME: This should be a call to bfd_alloc not bfd_zalloc. 3215 1.1 christos Unused entries should be reclaimed before the section's contents 3216 1.1 christos are written out, but at the moment this does not happen. Thus in 3217 1.1 christos order to prevent writing out garbage, we initialise the section's 3218 1.1 christos contents to zero. */ 3219 1.1.1.10 christos s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); 3220 1.1.1.13 christos if (s->contents == NULL) 3221 1.1 christos return false; 3222 1.1 christos s->alloced = 1; 3223 1.1.1.9 christos } 3224 1.1 christos 3225 1.1 christos return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs); 3226 1.1 christos } 3227 1.1 christos 3228 1.1 christos /* This function is called via elf_link_hash_traverse if we are 3229 1.1 christos creating a shared object. In the -Bsymbolic case it discards the 3230 1.1 christos space allocated to copy PC relative relocs against symbols which 3231 1.1 christos are defined in regular objects. For the normal shared case, it 3232 1.1 christos discards space for pc-relative relocs that have become local due to 3233 1.1 christos symbol visibility changes. We allocated space for them in the 3234 1.1 christos check_relocs routine, but we won't fill them in in the 3235 1.1 christos relocate_section routine. 3236 1.1 christos 3237 1.1 christos We also check whether any of the remaining relocations apply 3238 1.1 christos against a readonly section, and set the DF_TEXTREL flag in this 3239 1.1.1.10 christos case. */ 3240 1.1.1.2 christos 3241 1.1.1.2 christos static bool 3242 1.1 christos elf_m68k_discard_copies (struct elf_link_hash_entry *h, 3243 1.1 christos void * inf) 3244 1.1 christos { 3245 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *) inf; 3246 1.1 christos struct elf_m68k_pcrel_relocs_copied *s; 3247 1.1 christos 3248 1.1 christos if (!SYMBOL_CALLS_LOCAL (info, h)) 3249 1.1 christos { 3250 1.1 christos if ((info->flags & DF_TEXTREL) == 0) 3251 1.1 christos { 3252 1.1 christos /* Look for relocations against read-only sections. */ 3253 1.1 christos for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; 3254 1.1 christos s != NULL; 3255 1.1 christos s = s->next) 3256 1.1 christos if ((s->section->flags & SEC_READONLY) != 0) 3257 1.1 christos { 3258 1.1 christos info->flags |= DF_TEXTREL; 3259 1.1 christos break; 3260 1.1 christos } 3261 1.1.1.2 christos } 3262 1.1.1.2 christos 3263 1.1.1.2 christos /* Make sure undefined weak symbols are output as a dynamic symbol 3264 1.1.1.2 christos in PIEs. */ 3265 1.1.1.2 christos if (h->non_got_ref 3266 1.1.1.2 christos && h->root.type == bfd_link_hash_undefweak 3267 1.1.1.2 christos && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 3268 1.1.1.2 christos && h->dynindx == -1 3269 1.1.1.2 christos && !h->forced_local) 3270 1.1.1.10 christos { 3271 1.1.1.2 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 3272 1.1.1.2 christos return false; 3273 1.1.1.10 christos } 3274 1.1 christos 3275 1.1 christos return true; 3276 1.1 christos } 3277 1.1 christos 3278 1.1 christos for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; 3279 1.1 christos s != NULL; 3280 1.1 christos s = s->next) 3281 1.1.1.10 christos s->section->size -= s->count * sizeof (Elf32_External_Rela); 3282 1.1 christos 3283 1.1 christos return true; 3284 1.1 christos } 3285 1.1 christos 3286 1.1 christos 3287 1.1 christos /* Install relocation RELA. */ 3288 1.1 christos 3289 1.1 christos static void 3290 1.1 christos elf_m68k_install_rela (bfd *output_bfd, 3291 1.1 christos asection *srela, 3292 1.1 christos Elf_Internal_Rela *rela) 3293 1.1 christos { 3294 1.1 christos bfd_byte *loc; 3295 1.1 christos 3296 1.1 christos loc = srela->contents; 3297 1.1 christos loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); 3298 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, rela, loc); 3299 1.1 christos } 3300 1.1 christos 3301 1.1 christos /* Find the base offsets for thread-local storage in this object, 3302 1.1 christos for GD/LD and IE/LE respectively. */ 3303 1.1 christos 3304 1.1 christos #define DTP_OFFSET 0x8000 3305 1.1 christos #define TP_OFFSET 0x7000 3306 1.1 christos 3307 1.1 christos static bfd_vma 3308 1.1 christos dtpoff_base (struct bfd_link_info *info) 3309 1.1 christos { 3310 1.1 christos /* If tls_sec is NULL, we should have signalled an error already. */ 3311 1.1 christos if (elf_hash_table (info)->tls_sec == NULL) 3312 1.1 christos return 0; 3313 1.1 christos return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET; 3314 1.1 christos } 3315 1.1 christos 3316 1.1 christos static bfd_vma 3317 1.1 christos tpoff_base (struct bfd_link_info *info) 3318 1.1 christos { 3319 1.1 christos /* If tls_sec is NULL, we should have signalled an error already. */ 3320 1.1 christos if (elf_hash_table (info)->tls_sec == NULL) 3321 1.1 christos return 0; 3322 1.1 christos return elf_hash_table (info)->tls_sec->vma + TP_OFFSET; 3323 1.1 christos } 3324 1.1 christos 3325 1.1 christos /* Output necessary relocation to handle a symbol during static link. 3326 1.1 christos This function is called from elf_m68k_relocate_section. */ 3327 1.1 christos 3328 1.1 christos static void 3329 1.1 christos elf_m68k_init_got_entry_static (struct bfd_link_info *info, 3330 1.1 christos bfd *output_bfd, 3331 1.1 christos enum elf_m68k_reloc_type r_type, 3332 1.1 christos asection *sgot, 3333 1.1 christos bfd_vma got_entry_offset, 3334 1.1 christos bfd_vma relocation) 3335 1.1 christos { 3336 1.1 christos switch (elf_m68k_reloc_got_type (r_type)) 3337 1.1 christos { 3338 1.1 christos case R_68K_GOT32O: 3339 1.1 christos bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset); 3340 1.1 christos break; 3341 1.1 christos 3342 1.1 christos case R_68K_TLS_GD32: 3343 1.1 christos /* We know the offset within the module, 3344 1.1 christos put it into the second GOT slot. */ 3345 1.1 christos bfd_put_32 (output_bfd, relocation - dtpoff_base (info), 3346 1.1 christos sgot->contents + got_entry_offset + 4); 3347 1.1 christos /* FALLTHRU */ 3348 1.1 christos 3349 1.1 christos case R_68K_TLS_LDM32: 3350 1.1 christos /* Mark it as belonging to module 1, the executable. */ 3351 1.1 christos bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset); 3352 1.1 christos break; 3353 1.1 christos 3354 1.1 christos case R_68K_TLS_IE32: 3355 1.1 christos bfd_put_32 (output_bfd, relocation - tpoff_base (info), 3356 1.1 christos sgot->contents + got_entry_offset); 3357 1.1 christos break; 3358 1.1.1.10 christos 3359 1.1 christos default: 3360 1.1 christos BFD_ASSERT (false); 3361 1.1 christos } 3362 1.1 christos } 3363 1.1 christos 3364 1.1 christos /* Output necessary relocation to handle a local symbol 3365 1.1 christos during dynamic link. 3366 1.1 christos This function is called either from elf_m68k_relocate_section 3367 1.1 christos or from elf_m68k_finish_dynamic_symbol. */ 3368 1.1 christos 3369 1.1 christos static void 3370 1.1 christos elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info, 3371 1.1 christos bfd *output_bfd, 3372 1.1 christos enum elf_m68k_reloc_type r_type, 3373 1.1 christos asection *sgot, 3374 1.1 christos bfd_vma got_entry_offset, 3375 1.1 christos bfd_vma relocation, 3376 1.1 christos asection *srela) 3377 1.1 christos { 3378 1.1 christos Elf_Internal_Rela outrel; 3379 1.1 christos 3380 1.1 christos switch (elf_m68k_reloc_got_type (r_type)) 3381 1.1 christos { 3382 1.1 christos case R_68K_GOT32O: 3383 1.1 christos /* Emit RELATIVE relocation to initialize GOT slot 3384 1.1 christos at run-time. */ 3385 1.1 christos outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); 3386 1.1 christos outrel.r_addend = relocation; 3387 1.1 christos break; 3388 1.1 christos 3389 1.1 christos case R_68K_TLS_GD32: 3390 1.1 christos /* We know the offset within the module, 3391 1.1 christos put it into the second GOT slot. */ 3392 1.1 christos bfd_put_32 (output_bfd, relocation - dtpoff_base (info), 3393 1.1 christos sgot->contents + got_entry_offset + 4); 3394 1.1 christos /* FALLTHRU */ 3395 1.1 christos 3396 1.1 christos case R_68K_TLS_LDM32: 3397 1.1 christos /* We don't know the module number, 3398 1.1 christos create a relocation for it. */ 3399 1.1 christos outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32); 3400 1.1 christos outrel.r_addend = 0; 3401 1.1 christos break; 3402 1.1 christos 3403 1.1 christos case R_68K_TLS_IE32: 3404 1.1 christos /* Emit TPREL relocation to initialize GOT slot 3405 1.1 christos at run-time. */ 3406 1.1 christos outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32); 3407 1.1 christos outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma; 3408 1.1 christos break; 3409 1.1.1.10 christos 3410 1.1 christos default: 3411 1.1 christos BFD_ASSERT (false); 3412 1.1 christos } 3413 1.1 christos 3414 1.1 christos /* Offset of the GOT entry. */ 3415 1.1 christos outrel.r_offset = (sgot->output_section->vma 3416 1.1 christos + sgot->output_offset 3417 1.1 christos + got_entry_offset); 3418 1.1 christos 3419 1.1 christos /* Install one of the above relocations. */ 3420 1.1 christos elf_m68k_install_rela (output_bfd, srela, &outrel); 3421 1.1 christos 3422 1.1 christos bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset); 3423 1.1 christos } 3424 1.1 christos 3425 1.1.1.10 christos /* Relocate an M68K ELF section. */ 3426 1.1.1.2 christos 3427 1.1.1.2 christos static int 3428 1.1.1.2 christos elf_m68k_relocate_section (bfd *output_bfd, 3429 1.1.1.2 christos struct bfd_link_info *info, 3430 1.1.1.2 christos bfd *input_bfd, 3431 1.1.1.2 christos asection *input_section, 3432 1.1.1.2 christos bfd_byte *contents, 3433 1.1.1.2 christos Elf_Internal_Rela *relocs, 3434 1.1 christos Elf_Internal_Sym *local_syms, 3435 1.1 christos asection **local_sections) 3436 1.1 christos { 3437 1.1 christos Elf_Internal_Shdr *symtab_hdr; 3438 1.1 christos struct elf_link_hash_entry **sym_hashes; 3439 1.1 christos asection *sgot; 3440 1.1 christos asection *splt; 3441 1.1 christos asection *sreloc; 3442 1.1 christos asection *srela; 3443 1.1 christos struct elf_m68k_got *got; 3444 1.1 christos Elf_Internal_Rela *rel; 3445 1.1 christos Elf_Internal_Rela *relend; 3446 1.1 christos 3447 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3448 1.1 christos sym_hashes = elf_sym_hashes (input_bfd); 3449 1.1 christos 3450 1.1 christos sgot = NULL; 3451 1.1 christos splt = NULL; 3452 1.1 christos sreloc = NULL; 3453 1.1 christos srela = NULL; 3454 1.1 christos 3455 1.1 christos got = NULL; 3456 1.1 christos 3457 1.1 christos rel = relocs; 3458 1.1 christos relend = relocs + input_section->reloc_count; 3459 1.1 christos for (; rel < relend; rel++) 3460 1.1 christos { 3461 1.1 christos int r_type; 3462 1.1 christos reloc_howto_type *howto; 3463 1.1 christos unsigned long r_symndx; 3464 1.1 christos struct elf_link_hash_entry *h; 3465 1.1 christos Elf_Internal_Sym *sym; 3466 1.1.1.10 christos asection *sec; 3467 1.1 christos bfd_vma relocation; 3468 1.1.1.10 christos bool unresolved_reloc; 3469 1.1 christos bfd_reloc_status_type r; 3470 1.1 christos bool resolved_to_zero; 3471 1.1 christos 3472 1.1 christos r_type = ELF32_R_TYPE (rel->r_info); 3473 1.1 christos if (r_type < 0 || r_type >= (int) R_68K_max) 3474 1.1.1.10 christos { 3475 1.1 christos bfd_set_error (bfd_error_bad_value); 3476 1.1 christos return false; 3477 1.1 christos } 3478 1.1 christos howto = howto_table + r_type; 3479 1.1 christos 3480 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 3481 1.1 christos 3482 1.1 christos h = NULL; 3483 1.1.1.10 christos sym = NULL; 3484 1.1 christos sec = NULL; 3485 1.1 christos unresolved_reloc = false; 3486 1.1 christos 3487 1.1 christos if (r_symndx < symtab_hdr->sh_info) 3488 1.1 christos { 3489 1.1 christos sym = local_syms + r_symndx; 3490 1.1 christos sec = local_sections[r_symndx]; 3491 1.1 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 3492 1.1 christos } 3493 1.1.1.10 christos else 3494 1.1 christos { 3495 1.1 christos bool warned, ignored; 3496 1.1 christos 3497 1.1 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 3498 1.1.1.3 christos r_symndx, symtab_hdr, sym_hashes, 3499 1.1 christos h, sec, relocation, 3500 1.1 christos unresolved_reloc, warned, ignored); 3501 1.1.1.2 christos } 3502 1.1 christos 3503 1.1.1.13 christos if (sec != NULL && discarded_section (sec)) 3504 1.1.1.13 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 3505 1.1 christos rel, 1, relend, R_68K_NONE, 3506 1.1.1.6 christos howto, 0, contents); 3507 1.1 christos 3508 1.1 christos if (bfd_link_relocatable (info)) 3509 1.1.1.8 christos continue; 3510 1.1.1.8 christos 3511 1.1.1.8 christos resolved_to_zero = (h != NULL 3512 1.1 christos && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); 3513 1.1 christos 3514 1.1 christos switch (r_type) 3515 1.1 christos { 3516 1.1 christos case R_68K_GOT8: 3517 1.1 christos case R_68K_GOT16: 3518 1.1 christos case R_68K_GOT32: 3519 1.1 christos /* Relocation is to the address of the entry for this symbol 3520 1.1 christos in the global offset table. */ 3521 1.1 christos if (h != NULL 3522 1.1 christos && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 3523 1.1 christos { 3524 1.1 christos if (elf_m68k_hash_table (info)->local_gp_p) 3525 1.1 christos { 3526 1.1 christos bfd_vma sgot_output_offset; 3527 1.1.1.7 christos bfd_vma got_offset; 3528 1.1 christos 3529 1.1.1.7 christos sgot = elf_hash_table (info)->sgot; 3530 1.1 christos 3531 1.1.1.7 christos if (sgot != NULL) 3532 1.1.1.7 christos sgot_output_offset = sgot->output_offset; 3533 1.1.1.7 christos else 3534 1.1.1.7 christos /* In this case we have a reference to 3535 1.1.1.7 christos _GLOBAL_OFFSET_TABLE_, but the GOT itself is 3536 1.1.1.7 christos empty. 3537 1.1 christos ??? Issue a warning? */ 3538 1.1 christos sgot_output_offset = 0; 3539 1.1 christos 3540 1.1 christos if (got == NULL) 3541 1.1 christos { 3542 1.1 christos struct elf_m68k_bfd2got_entry *bfd2got_entry; 3543 1.1 christos 3544 1.1 christos bfd2got_entry 3545 1.1 christos = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), 3546 1.1 christos input_bfd, SEARCH, NULL); 3547 1.1 christos 3548 1.1 christos if (bfd2got_entry != NULL) 3549 1.1 christos { 3550 1.1 christos got = bfd2got_entry->got; 3551 1.1 christos BFD_ASSERT (got != NULL); 3552 1.1 christos 3553 1.1 christos got_offset = got->offset; 3554 1.1 christos } 3555 1.1 christos else 3556 1.1 christos /* In this case we have a reference to 3557 1.1 christos _GLOBAL_OFFSET_TABLE_, but no other references 3558 1.1 christos accessing any GOT entries. 3559 1.1 christos ??? Issue a warning? */ 3560 1.1 christos got_offset = 0; 3561 1.1 christos } 3562 1.1 christos else 3563 1.1 christos got_offset = got->offset; 3564 1.1 christos 3565 1.1 christos /* Adjust GOT pointer to point to the GOT 3566 1.1 christos assigned to input_bfd. */ 3567 1.1 christos rel->r_addend += sgot_output_offset + got_offset; 3568 1.1 christos } 3569 1.1 christos else 3570 1.1 christos BFD_ASSERT (got == NULL || got->offset == 0); 3571 1.1 christos 3572 1.1 christos break; 3573 1.1 christos } 3574 1.1 christos /* Fall through. */ 3575 1.1 christos case R_68K_GOT8O: 3576 1.1 christos case R_68K_GOT16O: 3577 1.1 christos case R_68K_GOT32O: 3578 1.1 christos 3579 1.1 christos case R_68K_TLS_LDM32: 3580 1.1 christos case R_68K_TLS_LDM16: 3581 1.1 christos case R_68K_TLS_LDM8: 3582 1.1 christos 3583 1.1 christos case R_68K_TLS_GD8: 3584 1.1 christos case R_68K_TLS_GD16: 3585 1.1 christos case R_68K_TLS_GD32: 3586 1.1 christos 3587 1.1 christos case R_68K_TLS_IE8: 3588 1.1 christos case R_68K_TLS_IE16: 3589 1.1 christos case R_68K_TLS_IE32: 3590 1.1 christos 3591 1.1 christos /* Relocation is the offset of the entry for this symbol in 3592 1.1 christos the global offset table. */ 3593 1.1 christos 3594 1.1 christos { 3595 1.1 christos struct elf_m68k_got_entry_key key_; 3596 1.1 christos bfd_vma *off_ptr; 3597 1.1.1.7 christos bfd_vma off; 3598 1.1.1.7 christos 3599 1.1 christos sgot = elf_hash_table (info)->sgot; 3600 1.1 christos BFD_ASSERT (sgot != NULL); 3601 1.1.1.9 christos 3602 1.1.1.9 christos if (got == NULL) 3603 1.1.1.9 christos got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), 3604 1.1 christos input_bfd, MUST_FIND, 3605 1.1 christos NULL)->got; 3606 1.1 christos 3607 1.1 christos /* Get GOT offset for this symbol. */ 3608 1.1 christos elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx, 3609 1.1 christos r_type); 3610 1.1 christos off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND, 3611 1.1 christos NULL)->u.s2.offset; 3612 1.1 christos off = *off_ptr; 3613 1.1 christos 3614 1.1 christos /* The offset must always be a multiple of 4. We use 3615 1.1 christos the least significant bit to record whether we have 3616 1.1 christos already generated the necessary reloc. */ 3617 1.1 christos if ((off & 1) != 0) 3618 1.1 christos off &= ~1; 3619 1.1 christos else 3620 1.1 christos { 3621 1.1 christos if (h != NULL 3622 1.1 christos /* @TLSLDM relocations are bounded to the module, in 3623 1.1 christos which the symbol is defined -- not to the symbol 3624 1.1 christos itself. */ 3625 1.1.1.10 christos && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32) 3626 1.1 christos { 3627 1.1 christos bool dyn; 3628 1.1.1.6 christos 3629 1.1.1.6 christos dyn = elf_hash_table (info)->dynamic_sections_created; 3630 1.1.1.6 christos if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 3631 1.1.1.6 christos bfd_link_pic (info), 3632 1.1 christos h) 3633 1.1.1.8 christos || (bfd_link_pic (info) 3634 1.1.1.8 christos && SYMBOL_REFERENCES_LOCAL (info, h)) 3635 1.1 christos || ((ELF_ST_VISIBILITY (h->other) 3636 1.1 christos || resolved_to_zero) 3637 1.1 christos && h->root.type == bfd_link_hash_undefweak)) 3638 1.1 christos { 3639 1.1 christos /* This is actually a static link, or it is a 3640 1.1 christos -Bsymbolic link and the symbol is defined 3641 1.1 christos locally, or the symbol was forced to be local 3642 1.1 christos because of a version file. We must initialize 3643 1.1 christos this entry in the global offset table. Since 3644 1.1 christos the offset must always be a multiple of 4, we 3645 1.1 christos use the least significant bit to record whether 3646 1.1 christos we have initialized it already. 3647 1.1 christos 3648 1.1 christos When doing a dynamic link, we create a .rela.got 3649 1.1 christos relocation entry to initialize the value. This 3650 1.1 christos is done in the finish_dynamic_symbol routine. */ 3651 1.1 christos 3652 1.1 christos elf_m68k_init_got_entry_static (info, 3653 1.1 christos output_bfd, 3654 1.1 christos r_type, 3655 1.1 christos sgot, 3656 1.1 christos off, 3657 1.1 christos relocation); 3658 1.1 christos 3659 1.1 christos *off_ptr |= 1; 3660 1.1.1.10 christos } 3661 1.1 christos else 3662 1.1.1.6 christos unresolved_reloc = false; 3663 1.1 christos } 3664 1.1 christos else if (bfd_link_pic (info)) /* && h == NULL */ 3665 1.1.1.7 christos /* Process local symbol during dynamic link. */ 3666 1.1.1.7 christos { 3667 1.1 christos srela = elf_hash_table (info)->srelgot; 3668 1.1 christos BFD_ASSERT (srela != NULL); 3669 1.1 christos 3670 1.1 christos elf_m68k_init_got_entry_local_shared (info, 3671 1.1 christos output_bfd, 3672 1.1 christos r_type, 3673 1.1 christos sgot, 3674 1.1 christos off, 3675 1.1 christos relocation, 3676 1.1 christos srela); 3677 1.1 christos 3678 1.1.1.6 christos *off_ptr |= 1; 3679 1.1 christos } 3680 1.1 christos else /* h == NULL && !bfd_link_pic (info) */ 3681 1.1 christos { 3682 1.1 christos elf_m68k_init_got_entry_static (info, 3683 1.1 christos output_bfd, 3684 1.1 christos r_type, 3685 1.1 christos sgot, 3686 1.1 christos off, 3687 1.1 christos relocation); 3688 1.1 christos 3689 1.1 christos *off_ptr |= 1; 3690 1.1 christos } 3691 1.1 christos } 3692 1.1 christos 3693 1.1 christos /* We don't use elf_m68k_reloc_got_type in the condition below 3694 1.1 christos because this is the only place where difference between 3695 1.1 christos R_68K_GOTx and R_68K_GOTxO relocations matters. */ 3696 1.1 christos if (r_type == R_68K_GOT32O 3697 1.1 christos || r_type == R_68K_GOT16O 3698 1.1 christos || r_type == R_68K_GOT8O 3699 1.1 christos || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32 3700 1.1 christos || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32 3701 1.1 christos || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32) 3702 1.1 christos { 3703 1.1 christos /* GOT pointer is adjusted to point to the start/middle 3704 1.1 christos of local GOT. Adjust the offset accordingly. */ 3705 1.1 christos BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p 3706 1.1 christos || off >= got->offset); 3707 1.1 christos 3708 1.1 christos if (elf_m68k_hash_table (info)->local_gp_p) 3709 1.1 christos relocation = off - got->offset; 3710 1.1 christos else 3711 1.1 christos { 3712 1.1 christos BFD_ASSERT (got->offset == 0); 3713 1.1 christos relocation = sgot->output_offset + off; 3714 1.1 christos } 3715 1.1 christos 3716 1.1 christos /* This relocation does not use the addend. */ 3717 1.1 christos rel->r_addend = 0; 3718 1.1 christos } 3719 1.1 christos else 3720 1.1 christos relocation = (sgot->output_section->vma + sgot->output_offset 3721 1.1 christos + off); 3722 1.1 christos } 3723 1.1 christos break; 3724 1.1 christos 3725 1.1 christos case R_68K_TLS_LDO32: 3726 1.1 christos case R_68K_TLS_LDO16: 3727 1.1 christos case R_68K_TLS_LDO8: 3728 1.1 christos relocation -= dtpoff_base (info); 3729 1.1 christos break; 3730 1.1 christos 3731 1.1 christos case R_68K_TLS_LE32: 3732 1.1.1.6 christos case R_68K_TLS_LE16: 3733 1.1 christos case R_68K_TLS_LE8: 3734 1.1.1.7 christos if (bfd_link_dll (info)) 3735 1.1.1.7 christos { 3736 1.1.1.8 christos _bfd_error_handler 3737 1.1.1.8 christos /* xgettext:c-format */ 3738 1.1.1.8 christos (_("%pB(%pA+%#" PRIx64 "): " 3739 1.1.1.8 christos "%s relocation not permitted in shared object"), 3740 1.1 christos input_bfd, input_section, (uint64_t) rel->r_offset, 3741 1.1.1.10 christos howto->name); 3742 1.1 christos 3743 1.1 christos return false; 3744 1.1 christos } 3745 1.1 christos else 3746 1.1 christos relocation -= tpoff_base (info); 3747 1.1 christos 3748 1.1 christos break; 3749 1.1 christos 3750 1.1 christos case R_68K_PLT8: 3751 1.1 christos case R_68K_PLT16: 3752 1.1 christos case R_68K_PLT32: 3753 1.1 christos /* Relocation is to the entry for this symbol in the 3754 1.1 christos procedure linkage table. */ 3755 1.1 christos 3756 1.1 christos /* Resolve a PLTxx reloc against a local symbol directly, 3757 1.1 christos without using the procedure linkage table. */ 3758 1.1 christos if (h == NULL) 3759 1.1 christos break; 3760 1.1 christos 3761 1.1 christos if (h->plt.offset == (bfd_vma) -1 3762 1.1 christos || !elf_hash_table (info)->dynamic_sections_created) 3763 1.1 christos { 3764 1.1 christos /* We didn't make a PLT entry for this symbol. This 3765 1.1 christos happens when statically linking PIC code, or when 3766 1.1 christos using -Bsymbolic. */ 3767 1.1 christos break; 3768 1.1.1.7 christos } 3769 1.1.1.7 christos 3770 1.1 christos splt = elf_hash_table (info)->splt; 3771 1.1 christos BFD_ASSERT (splt != NULL); 3772 1.1 christos 3773 1.1 christos relocation = (splt->output_section->vma 3774 1.1.1.10 christos + splt->output_offset 3775 1.1 christos + h->plt.offset); 3776 1.1 christos unresolved_reloc = false; 3777 1.1 christos break; 3778 1.1 christos 3779 1.1 christos case R_68K_PLT8O: 3780 1.1 christos case R_68K_PLT16O: 3781 1.1 christos case R_68K_PLT32O: 3782 1.1 christos /* Relocation is the offset of the entry for this symbol in 3783 1.1 christos the procedure linkage table. */ 3784 1.1.1.7 christos BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1); 3785 1.1.1.7 christos 3786 1.1 christos splt = elf_hash_table (info)->splt; 3787 1.1 christos BFD_ASSERT (splt != NULL); 3788 1.1.1.10 christos 3789 1.1 christos relocation = h->plt.offset; 3790 1.1 christos unresolved_reloc = false; 3791 1.1 christos 3792 1.1 christos /* This relocation does not use the addend. */ 3793 1.1 christos rel->r_addend = 0; 3794 1.1 christos 3795 1.1 christos break; 3796 1.1 christos 3797 1.1 christos case R_68K_8: 3798 1.1 christos case R_68K_16: 3799 1.1 christos case R_68K_32: 3800 1.1 christos case R_68K_PC8: 3801 1.1.1.6 christos case R_68K_PC16: 3802 1.1 christos case R_68K_PC32: 3803 1.1 christos if (bfd_link_pic (info) 3804 1.1 christos && r_symndx != STN_UNDEF 3805 1.1.1.8 christos && (input_section->flags & SEC_ALLOC) != 0 3806 1.1.1.8 christos && (h == NULL 3807 1.1 christos || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 3808 1.1 christos && !resolved_to_zero) 3809 1.1 christos || h->root.type != bfd_link_hash_undefweak) 3810 1.1 christos && ((r_type != R_68K_PC8 3811 1.1 christos && r_type != R_68K_PC16 3812 1.1 christos && r_type != R_68K_PC32) 3813 1.1 christos || !SYMBOL_CALLS_LOCAL (info, h))) 3814 1.1 christos { 3815 1.1.1.10 christos Elf_Internal_Rela outrel; 3816 1.1 christos bfd_byte *loc; 3817 1.1 christos bool skip, relocate; 3818 1.1 christos 3819 1.1 christos /* When generating a shared object, these relocations 3820 1.1 christos are copied into the output file to be resolved at run 3821 1.1.1.10 christos time. */ 3822 1.1.1.10 christos 3823 1.1 christos skip = false; 3824 1.1 christos relocate = false; 3825 1.1 christos 3826 1.1 christos outrel.r_offset = 3827 1.1 christos _bfd_elf_section_offset (output_bfd, info, input_section, 3828 1.1.1.10 christos rel->r_offset); 3829 1.1 christos if (outrel.r_offset == (bfd_vma) -1) 3830 1.1.1.10 christos skip = true; 3831 1.1 christos else if (outrel.r_offset == (bfd_vma) -2) 3832 1.1 christos skip = true, relocate = true; 3833 1.1 christos outrel.r_offset += (input_section->output_section->vma 3834 1.1 christos + input_section->output_offset); 3835 1.1 christos 3836 1.1 christos if (skip) 3837 1.1 christos memset (&outrel, 0, sizeof outrel); 3838 1.1 christos else if (h != NULL 3839 1.1 christos && h->dynindx != -1 3840 1.1 christos && (r_type == R_68K_PC8 3841 1.1.1.6 christos || r_type == R_68K_PC16 3842 1.1.1.6 christos || r_type == R_68K_PC32 3843 1.1 christos || !bfd_link_pic (info) 3844 1.1 christos || !SYMBOLIC_BIND (info, h) 3845 1.1 christos || !h->def_regular)) 3846 1.1 christos { 3847 1.1 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); 3848 1.1 christos outrel.r_addend = rel->r_addend; 3849 1.1 christos } 3850 1.1 christos else 3851 1.1 christos { 3852 1.1 christos /* This symbol is local, or marked to become local. */ 3853 1.1 christos outrel.r_addend = relocation + rel->r_addend; 3854 1.1 christos 3855 1.1.1.10 christos if (r_type == R_68K_32) 3856 1.1 christos { 3857 1.1 christos relocate = true; 3858 1.1 christos outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); 3859 1.1 christos } 3860 1.1 christos else 3861 1.1 christos { 3862 1.1 christos long indx; 3863 1.1 christos 3864 1.1 christos if (bfd_is_abs_section (sec)) 3865 1.1 christos indx = 0; 3866 1.1 christos else if (sec == NULL || sec->owner == NULL) 3867 1.1.1.10 christos { 3868 1.1 christos bfd_set_error (bfd_error_bad_value); 3869 1.1 christos return false; 3870 1.1 christos } 3871 1.1 christos else 3872 1.1 christos { 3873 1.1 christos asection *osec; 3874 1.1 christos 3875 1.1 christos /* We are turning this relocation into one 3876 1.1 christos against a section symbol. It would be 3877 1.1 christos proper to subtract the symbol's value, 3878 1.1 christos osec->vma, from the emitted reloc addend, 3879 1.1 christos but ld.so expects buggy relocs. */ 3880 1.1 christos osec = sec->output_section; 3881 1.1 christos indx = elf_section_data (osec)->dynindx; 3882 1.1 christos if (indx == 0) 3883 1.1 christos { 3884 1.1 christos struct elf_link_hash_table *htab; 3885 1.1 christos htab = elf_hash_table (info); 3886 1.1 christos osec = htab->text_index_section; 3887 1.1 christos indx = elf_section_data (osec)->dynindx; 3888 1.1 christos } 3889 1.1 christos BFD_ASSERT (indx != 0); 3890 1.1 christos } 3891 1.1 christos 3892 1.1 christos outrel.r_info = ELF32_R_INFO (indx, r_type); 3893 1.1 christos } 3894 1.1 christos } 3895 1.1 christos 3896 1.1 christos sreloc = elf_section_data (input_section)->sreloc; 3897 1.1 christos if (sreloc == NULL) 3898 1.1 christos abort (); 3899 1.1 christos 3900 1.1 christos loc = sreloc->contents; 3901 1.1 christos loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); 3902 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 3903 1.1.1.8 christos 3904 1.1.1.8 christos /* This reloc will be computed at runtime, so there's no 3905 1.1.1.8 christos need to do anything now, except for R_68K_32 3906 1.1 christos relocations that have been turned into 3907 1.1 christos R_68K_RELATIVE. */ 3908 1.1 christos if (!relocate) 3909 1.1 christos continue; 3910 1.1 christos } 3911 1.1 christos 3912 1.1 christos break; 3913 1.1 christos 3914 1.1 christos case R_68K_GNU_VTINHERIT: 3915 1.1 christos case R_68K_GNU_VTENTRY: 3916 1.1 christos /* These are no-ops in the end. */ 3917 1.1 christos continue; 3918 1.1 christos 3919 1.1 christos default: 3920 1.1 christos break; 3921 1.1 christos } 3922 1.1 christos 3923 1.1 christos /* Dynamic relocs are not propagated for SEC_DEBUGGING sections 3924 1.1 christos because such sections are not SEC_ALLOC and thus ld.so will 3925 1.1 christos not process them. */ 3926 1.1.1.2 christos if (unresolved_reloc 3927 1.1.1.2 christos && !((input_section->flags & SEC_DEBUGGING) != 0 3928 1.1.1.2 christos && h->def_dynamic) 3929 1.1 christos && _bfd_elf_section_offset (output_bfd, info, input_section, 3930 1.1.1.7 christos rel->r_offset) != (bfd_vma) -1) 3931 1.1.1.7 christos { 3932 1.1.1.8 christos _bfd_error_handler 3933 1.1.1.8 christos /* xgettext:c-format */ 3934 1.1 christos (_("%pB(%pA+%#" PRIx64 "): " 3935 1.1 christos "unresolvable %s relocation against symbol `%s'"), 3936 1.1.1.8 christos input_bfd, 3937 1.1 christos input_section, 3938 1.1 christos (uint64_t) rel->r_offset, 3939 1.1.1.10 christos howto->name, 3940 1.1 christos h->root.root.string); 3941 1.1 christos return false; 3942 1.1 christos } 3943 1.1 christos 3944 1.1 christos if (r_symndx != STN_UNDEF 3945 1.1 christos && r_type != R_68K_NONE 3946 1.1 christos && (h == NULL 3947 1.1 christos || h->root.type == bfd_link_hash_defined 3948 1.1 christos || h->root.type == bfd_link_hash_defweak)) 3949 1.1 christos { 3950 1.1 christos char sym_type; 3951 1.1 christos 3952 1.1 christos sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type; 3953 1.1 christos 3954 1.1 christos if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS)) 3955 1.1 christos { 3956 1.1 christos const char *name; 3957 1.1 christos 3958 1.1 christos if (h != NULL) 3959 1.1 christos name = h->root.root.string; 3960 1.1 christos else 3961 1.1 christos { 3962 1.1 christos name = (bfd_elf_string_from_elf_section 3963 1.1.1.9 christos (input_bfd, symtab_hdr->sh_link, sym->st_name)); 3964 1.1 christos if (name == NULL || *name == '\0') 3965 1.1 christos name = bfd_section_name (sec); 3966 1.1.1.7 christos } 3967 1.1 christos 3968 1.1.1.7 christos _bfd_error_handler 3969 1.1.1.8 christos ((sym_type == STT_TLS 3970 1.1.1.7 christos /* xgettext:c-format */ 3971 1.1.1.8 christos ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s") 3972 1.1 christos /* xgettext:c-format */ 3973 1.1 christos : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")), 3974 1.1.1.8 christos input_bfd, 3975 1.1 christos input_section, 3976 1.1 christos (uint64_t) rel->r_offset, 3977 1.1 christos howto->name, 3978 1.1 christos name); 3979 1.1 christos } 3980 1.1 christos } 3981 1.1 christos 3982 1.1 christos r = _bfd_final_link_relocate (howto, input_bfd, input_section, 3983 1.1 christos contents, rel->r_offset, 3984 1.1 christos relocation, rel->r_addend); 3985 1.1 christos 3986 1.1 christos if (r != bfd_reloc_ok) 3987 1.1 christos { 3988 1.1 christos const char *name; 3989 1.1 christos 3990 1.1 christos if (h != NULL) 3991 1.1 christos name = h->root.root.string; 3992 1.1 christos else 3993 1.1 christos { 3994 1.1 christos name = bfd_elf_string_from_elf_section (input_bfd, 3995 1.1 christos symtab_hdr->sh_link, 3996 1.1.1.10 christos sym->st_name); 3997 1.1 christos if (name == NULL) 3998 1.1.1.9 christos return false; 3999 1.1 christos if (*name == '\0') 4000 1.1 christos name = bfd_section_name (sec); 4001 1.1 christos } 4002 1.1.1.6 christos 4003 1.1.1.6 christos if (r == bfd_reloc_overflow) 4004 1.1.1.6 christos (*info->callbacks->reloc_overflow) 4005 1.1 christos (info, (h ? &h->root : NULL), name, howto->name, 4006 1.1 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 4007 1.1.1.7 christos else 4008 1.1.1.7 christos { 4009 1.1.1.8 christos _bfd_error_handler 4010 1.1 christos /* xgettext:c-format */ 4011 1.1.1.8 christos (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"), 4012 1.1.1.10 christos input_bfd, input_section, 4013 1.1 christos (uint64_t) rel->r_offset, name, (int) r); 4014 1.1 christos return false; 4015 1.1 christos } 4016 1.1 christos } 4017 1.1.1.10 christos } 4018 1.1 christos 4019 1.1 christos return true; 4020 1.1 christos } 4021 1.1 christos 4022 1.1 christos /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET 4023 1.1 christos into section SEC. */ 4024 1.1 christos 4025 1.1 christos static void 4026 1.1 christos elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value) 4027 1.1 christos { 4028 1.1 christos /* Make VALUE PC-relative. */ 4029 1.1 christos value -= sec->output_section->vma + offset; 4030 1.1 christos 4031 1.1 christos /* Apply any in-place addend. */ 4032 1.1 christos value += bfd_get_32 (sec->owner, sec->contents + offset); 4033 1.1 christos 4034 1.1 christos bfd_put_32 (sec->owner, value, sec->contents + offset); 4035 1.1 christos } 4036 1.1 christos 4037 1.1 christos /* Finish up dynamic symbol handling. We set the contents of various 4038 1.1.1.10 christos dynamic sections here. */ 4039 1.1.1.2 christos 4040 1.1.1.2 christos static bool 4041 1.1.1.2 christos elf_m68k_finish_dynamic_symbol (bfd *output_bfd, 4042 1.1.1.2 christos struct bfd_link_info *info, 4043 1.1 christos struct elf_link_hash_entry *h, 4044 1.1 christos Elf_Internal_Sym *sym) 4045 1.1 christos { 4046 1.1 christos bfd *dynobj; 4047 1.1 christos 4048 1.1 christos dynobj = elf_hash_table (info)->dynobj; 4049 1.1 christos 4050 1.1 christos if (h->plt.offset != (bfd_vma) -1) 4051 1.1 christos { 4052 1.1 christos const struct elf_m68k_plt_info *plt_info; 4053 1.1 christos asection *splt; 4054 1.1 christos asection *sgot; 4055 1.1 christos asection *srela; 4056 1.1 christos bfd_vma plt_index; 4057 1.1 christos bfd_vma got_offset; 4058 1.1 christos Elf_Internal_Rela rela; 4059 1.1 christos bfd_byte *loc; 4060 1.1 christos 4061 1.1 christos /* This symbol has an entry in the procedure linkage table. Set 4062 1.1 christos it up. */ 4063 1.1 christos 4064 1.1 christos BFD_ASSERT (h->dynindx != -1); 4065 1.1.1.7 christos 4066 1.1.1.7 christos plt_info = elf_m68k_hash_table (info)->plt_info; 4067 1.1.1.7 christos splt = elf_hash_table (info)->splt; 4068 1.1 christos sgot = elf_hash_table (info)->sgotplt; 4069 1.1 christos srela = elf_hash_table (info)->srelplt; 4070 1.1 christos BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); 4071 1.1 christos 4072 1.1 christos /* Get the index in the procedure linkage table which 4073 1.1 christos corresponds to this symbol. This is the index of this symbol 4074 1.1 christos in all the symbols for which we are making plt entries. The 4075 1.1 christos first entry in the procedure linkage table is reserved. */ 4076 1.1 christos plt_index = (h->plt.offset / plt_info->size) - 1; 4077 1.1 christos 4078 1.1 christos /* Get the offset into the .got table of the entry that 4079 1.1 christos corresponds to this function. Each .got entry is 4 bytes. 4080 1.1 christos The first three are reserved. */ 4081 1.1 christos got_offset = (plt_index + 3) * 4; 4082 1.1 christos 4083 1.1 christos memcpy (splt->contents + h->plt.offset, 4084 1.1 christos plt_info->symbol_entry, 4085 1.1 christos plt_info->size); 4086 1.1 christos 4087 1.1 christos elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got, 4088 1.1 christos (sgot->output_section->vma 4089 1.1 christos + sgot->output_offset 4090 1.1 christos + got_offset)); 4091 1.1 christos 4092 1.1 christos bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), 4093 1.1 christos splt->contents 4094 1.1 christos + h->plt.offset 4095 1.1 christos + plt_info->symbol_resolve_entry + 2); 4096 1.1 christos 4097 1.1 christos elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt, 4098 1.1 christos splt->output_section->vma); 4099 1.1 christos 4100 1.1 christos /* Fill in the entry in the global offset table. */ 4101 1.1 christos bfd_put_32 (output_bfd, 4102 1.1 christos (splt->output_section->vma 4103 1.1 christos + splt->output_offset 4104 1.1 christos + h->plt.offset 4105 1.1 christos + plt_info->symbol_resolve_entry), 4106 1.1 christos sgot->contents + got_offset); 4107 1.1 christos 4108 1.1 christos /* Fill in the entry in the .rela.plt section. */ 4109 1.1 christos rela.r_offset = (sgot->output_section->vma 4110 1.1 christos + sgot->output_offset 4111 1.1 christos + got_offset); 4112 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT); 4113 1.1 christos rela.r_addend = 0; 4114 1.1 christos loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); 4115 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 4116 1.1 christos 4117 1.1 christos if (!h->def_regular) 4118 1.1 christos { 4119 1.1 christos /* Mark the symbol as undefined, rather than as defined in 4120 1.1 christos the .plt section. Leave the value alone. */ 4121 1.1 christos sym->st_shndx = SHN_UNDEF; 4122 1.1 christos } 4123 1.1 christos } 4124 1.1 christos 4125 1.1 christos if (elf_m68k_hash_entry (h)->glist != NULL) 4126 1.1 christos { 4127 1.1 christos asection *sgot; 4128 1.1 christos asection *srela; 4129 1.1 christos struct elf_m68k_got_entry *got_entry; 4130 1.1 christos 4131 1.1 christos /* This symbol has an entry in the global offset table. Set it 4132 1.1.1.7 christos up. */ 4133 1.1.1.7 christos 4134 1.1 christos sgot = elf_hash_table (info)->sgot; 4135 1.1 christos srela = elf_hash_table (info)->srelgot; 4136 1.1 christos BFD_ASSERT (sgot != NULL && srela != NULL); 4137 1.1 christos 4138 1.1 christos got_entry = elf_m68k_hash_entry (h)->glist; 4139 1.1 christos 4140 1.1 christos while (got_entry != NULL) 4141 1.1 christos { 4142 1.1 christos enum elf_m68k_reloc_type r_type; 4143 1.1 christos bfd_vma got_entry_offset; 4144 1.1 christos 4145 1.1 christos r_type = got_entry->key_.type; 4146 1.1 christos got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1; 4147 1.1 christos 4148 1.1 christos /* If this is a -Bsymbolic link, and the symbol is defined 4149 1.1 christos locally, we just want to emit a RELATIVE reloc. Likewise if 4150 1.1 christos the symbol was forced to be local because of a version file. 4151 1.1.1.6 christos The entry in the global offset table already have been 4152 1.1 christos initialized in the relocate_section function. */ 4153 1.1 christos if (bfd_link_pic (info) 4154 1.1 christos && SYMBOL_REFERENCES_LOCAL (info, h)) 4155 1.1 christos { 4156 1.1 christos bfd_vma relocation; 4157 1.1 christos 4158 1.1 christos relocation = bfd_get_signed_32 (output_bfd, 4159 1.1 christos (sgot->contents 4160 1.1 christos + got_entry_offset)); 4161 1.1 christos 4162 1.1 christos /* Undo TP bias. */ 4163 1.1 christos switch (elf_m68k_reloc_got_type (r_type)) 4164 1.1 christos { 4165 1.1 christos case R_68K_GOT32O: 4166 1.1 christos case R_68K_TLS_LDM32: 4167 1.1 christos break; 4168 1.1 christos 4169 1.1 christos case R_68K_TLS_GD32: 4170 1.1 christos /* The value for this relocation is actually put in 4171 1.1 christos the second GOT slot. */ 4172 1.1 christos relocation = bfd_get_signed_32 (output_bfd, 4173 1.1 christos (sgot->contents 4174 1.1 christos + got_entry_offset + 4)); 4175 1.1 christos relocation += dtpoff_base (info); 4176 1.1 christos break; 4177 1.1 christos 4178 1.1 christos case R_68K_TLS_IE32: 4179 1.1 christos relocation += tpoff_base (info); 4180 1.1 christos break; 4181 1.1.1.10 christos 4182 1.1 christos default: 4183 1.1 christos BFD_ASSERT (false); 4184 1.1 christos } 4185 1.1 christos 4186 1.1 christos elf_m68k_init_got_entry_local_shared (info, 4187 1.1 christos output_bfd, 4188 1.1 christos r_type, 4189 1.1 christos sgot, 4190 1.1 christos got_entry_offset, 4191 1.1 christos relocation, 4192 1.1 christos srela); 4193 1.1 christos } 4194 1.1 christos else 4195 1.1 christos { 4196 1.1 christos Elf_Internal_Rela rela; 4197 1.1 christos 4198 1.1 christos /* Put zeros to GOT slots that will be initialized 4199 1.1 christos at run-time. */ 4200 1.1 christos { 4201 1.1 christos bfd_vma n_slots; 4202 1.1 christos 4203 1.1 christos n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type); 4204 1.1 christos while (n_slots--) 4205 1.1 christos bfd_put_32 (output_bfd, (bfd_vma) 0, 4206 1.1 christos (sgot->contents + got_entry_offset 4207 1.1 christos + 4 * n_slots)); 4208 1.1 christos } 4209 1.1 christos 4210 1.1 christos rela.r_addend = 0; 4211 1.1 christos rela.r_offset = (sgot->output_section->vma 4212 1.1 christos + sgot->output_offset 4213 1.1 christos + got_entry_offset); 4214 1.1 christos 4215 1.1 christos switch (elf_m68k_reloc_got_type (r_type)) 4216 1.1 christos { 4217 1.1 christos case R_68K_GOT32O: 4218 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT); 4219 1.1 christos elf_m68k_install_rela (output_bfd, srela, &rela); 4220 1.1 christos break; 4221 1.1 christos 4222 1.1 christos case R_68K_TLS_GD32: 4223 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32); 4224 1.1 christos elf_m68k_install_rela (output_bfd, srela, &rela); 4225 1.1 christos 4226 1.1 christos rela.r_offset += 4; 4227 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32); 4228 1.1 christos elf_m68k_install_rela (output_bfd, srela, &rela); 4229 1.1 christos break; 4230 1.1 christos 4231 1.1 christos case R_68K_TLS_IE32: 4232 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32); 4233 1.1 christos elf_m68k_install_rela (output_bfd, srela, &rela); 4234 1.1 christos break; 4235 1.1.1.10 christos 4236 1.1 christos default: 4237 1.1 christos BFD_ASSERT (false); 4238 1.1 christos break; 4239 1.1 christos } 4240 1.1 christos } 4241 1.1 christos 4242 1.1 christos got_entry = got_entry->u.s2.next; 4243 1.1 christos } 4244 1.1 christos } 4245 1.1 christos 4246 1.1 christos if (h->needs_copy) 4247 1.1 christos { 4248 1.1 christos asection *s; 4249 1.1 christos Elf_Internal_Rela rela; 4250 1.1 christos bfd_byte *loc; 4251 1.1 christos 4252 1.1 christos /* This symbol needs a copy reloc. Set it up. */ 4253 1.1 christos 4254 1.1 christos BFD_ASSERT (h->dynindx != -1 4255 1.1 christos && (h->root.type == bfd_link_hash_defined 4256 1.1.1.2 christos || h->root.type == bfd_link_hash_defweak)); 4257 1.1 christos 4258 1.1 christos s = bfd_get_linker_section (dynobj, ".rela.bss"); 4259 1.1 christos BFD_ASSERT (s != NULL); 4260 1.1 christos 4261 1.1 christos rela.r_offset = (h->root.u.def.value 4262 1.1 christos + h->root.u.def.section->output_section->vma 4263 1.1 christos + h->root.u.def.section->output_offset); 4264 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY); 4265 1.1 christos rela.r_addend = 0; 4266 1.1 christos loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); 4267 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 4268 1.1.1.10 christos } 4269 1.1 christos 4270 1.1 christos return true; 4271 1.1 christos } 4272 1.1 christos 4273 1.1.1.10 christos /* Finish up the dynamic sections. */ 4274 1.1.1.2 christos 4275 1.1 christos static bool 4276 1.1 christos elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) 4277 1.1 christos { 4278 1.1 christos bfd *dynobj; 4279 1.1 christos asection *sgot; 4280 1.1 christos asection *sdyn; 4281 1.1 christos 4282 1.1.1.7 christos dynobj = elf_hash_table (info)->dynobj; 4283 1.1 christos 4284 1.1.1.2 christos sgot = elf_hash_table (info)->sgotplt; 4285 1.1 christos BFD_ASSERT (sgot != NULL); 4286 1.1 christos sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 4287 1.1 christos 4288 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 4289 1.1 christos { 4290 1.1 christos asection *splt; 4291 1.1.1.7 christos Elf32_External_Dyn *dyncon, *dynconend; 4292 1.1 christos 4293 1.1 christos splt = elf_hash_table (info)->splt; 4294 1.1 christos BFD_ASSERT (splt != NULL && sdyn != NULL); 4295 1.1 christos 4296 1.1 christos dyncon = (Elf32_External_Dyn *) sdyn->contents; 4297 1.1 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 4298 1.1 christos for (; dyncon < dynconend; dyncon++) 4299 1.1 christos { 4300 1.1 christos Elf_Internal_Dyn dyn; 4301 1.1 christos asection *s; 4302 1.1 christos 4303 1.1 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 4304 1.1 christos 4305 1.1 christos switch (dyn.d_tag) 4306 1.1 christos { 4307 1.1 christos default: 4308 1.1 christos break; 4309 1.1.1.7 christos 4310 1.1 christos case DT_PLTGOT: 4311 1.1 christos s = elf_hash_table (info)->sgotplt; 4312 1.1.1.7 christos goto get_vma; 4313 1.1 christos case DT_JMPREL: 4314 1.1.1.6 christos s = elf_hash_table (info)->srelplt; 4315 1.1 christos get_vma: 4316 1.1 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 4317 1.1 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4318 1.1 christos break; 4319 1.1.1.7 christos 4320 1.1 christos case DT_PLTRELSZ: 4321 1.1 christos s = elf_hash_table (info)->srelplt; 4322 1.1 christos dyn.d_un.d_val = s->size; 4323 1.1 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4324 1.1 christos break; 4325 1.1 christos } 4326 1.1 christos } 4327 1.1 christos 4328 1.1 christos /* Fill in the first entry in the procedure linkage table. */ 4329 1.1 christos if (splt->size > 0) 4330 1.1 christos { 4331 1.1 christos const struct elf_m68k_plt_info *plt_info; 4332 1.1 christos 4333 1.1 christos plt_info = elf_m68k_hash_table (info)->plt_info; 4334 1.1 christos memcpy (splt->contents, plt_info->plt0_entry, plt_info->size); 4335 1.1 christos 4336 1.1 christos elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4, 4337 1.1 christos (sgot->output_section->vma 4338 1.1 christos + sgot->output_offset 4339 1.1 christos + 4)); 4340 1.1 christos 4341 1.1 christos elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8, 4342 1.1 christos (sgot->output_section->vma 4343 1.1 christos + sgot->output_offset 4344 1.1 christos + 8)); 4345 1.1 christos 4346 1.1 christos elf_section_data (splt->output_section)->this_hdr.sh_entsize 4347 1.1 christos = plt_info->size; 4348 1.1 christos } 4349 1.1 christos } 4350 1.1 christos 4351 1.1 christos /* Fill in the first three entries in the global offset table. */ 4352 1.1 christos if (sgot->size > 0) 4353 1.1 christos { 4354 1.1 christos if (sdyn == NULL) 4355 1.1 christos bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); 4356 1.1 christos else 4357 1.1 christos bfd_put_32 (output_bfd, 4358 1.1 christos sdyn->output_section->vma + sdyn->output_offset, 4359 1.1 christos sgot->contents); 4360 1.1 christos bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); 4361 1.1 christos bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); 4362 1.1 christos } 4363 1.1 christos 4364 1.1.1.10 christos elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; 4365 1.1 christos 4366 1.1 christos return true; 4367 1.1 christos } 4368 1.1 christos 4369 1.1 christos /* Given a .data section and a .emreloc in-memory section, store 4370 1.1 christos relocation information into the .emreloc section which can be 4371 1.1 christos used at runtime to relocate the section. This is called by the 4372 1.1 christos linker when the --embedded-relocs switch is used. This is called 4373 1.1 christos after the add_symbols entry point has been called for all the 4374 1.1.1.10 christos objects, and before the final_link entry point is called. */ 4375 1.1.1.6 christos 4376 1.1.1.6 christos bool 4377 1.1.1.6 christos bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info, 4378 1.1 christos asection *datasec, asection *relsec, 4379 1.1 christos char **errmsg) 4380 1.1 christos { 4381 1.1 christos Elf_Internal_Shdr *symtab_hdr; 4382 1.1 christos Elf_Internal_Sym *isymbuf = NULL; 4383 1.1 christos Elf_Internal_Rela *internal_relocs = NULL; 4384 1.1 christos Elf_Internal_Rela *irel, *irelend; 4385 1.1 christos bfd_byte *p; 4386 1.1.1.6 christos bfd_size_type amt; 4387 1.1 christos 4388 1.1 christos BFD_ASSERT (! bfd_link_relocatable (info)); 4389 1.1 christos 4390 1.1 christos *errmsg = NULL; 4391 1.1.1.10 christos 4392 1.1 christos if (datasec->reloc_count == 0) 4393 1.1 christos return true; 4394 1.1 christos 4395 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4396 1.1 christos 4397 1.1.1.2 christos /* Get a copy of the native relocations. */ 4398 1.1 christos internal_relocs = (_bfd_elf_link_read_relocs 4399 1.1 christos (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL, 4400 1.1 christos info->keep_memory)); 4401 1.1 christos if (internal_relocs == NULL) 4402 1.1 christos goto error_return; 4403 1.1 christos 4404 1.1 christos amt = (bfd_size_type) datasec->reloc_count * 12; 4405 1.1 christos relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt); 4406 1.1.1.13 christos if (relsec->contents == NULL) 4407 1.1 christos goto error_return; 4408 1.1 christos relsec->alloced = 1; 4409 1.1 christos 4410 1.1 christos p = relsec->contents; 4411 1.1 christos 4412 1.1 christos irelend = internal_relocs + datasec->reloc_count; 4413 1.1 christos for (irel = internal_relocs; irel < irelend; irel++, p += 12) 4414 1.1 christos { 4415 1.1 christos asection *targetsec; 4416 1.1 christos 4417 1.1 christos /* We are going to write a four byte longword into the runtime 4418 1.1 christos reloc section. The longword will be the address in the data 4419 1.1 christos section which must be relocated. It is followed by the name 4420 1.1 christos of the target section NUL-padded or truncated to 8 4421 1.1 christos characters. */ 4422 1.1 christos 4423 1.1 christos /* We can only relocate absolute longword relocs at run time. */ 4424 1.1.1.8 christos if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32) 4425 1.1 christos { 4426 1.1 christos *errmsg = _("unsupported relocation type"); 4427 1.1 christos bfd_set_error (bfd_error_bad_value); 4428 1.1 christos goto error_return; 4429 1.1 christos } 4430 1.1 christos 4431 1.1 christos /* Get the target section referred to by the reloc. */ 4432 1.1 christos if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 4433 1.1 christos { 4434 1.1 christos /* A local symbol. */ 4435 1.1 christos Elf_Internal_Sym *isym; 4436 1.1 christos 4437 1.1 christos /* Read this BFD's local symbols if we haven't done so already. */ 4438 1.1 christos if (isymbuf == NULL) 4439 1.1 christos { 4440 1.1 christos isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 4441 1.1 christos if (isymbuf == NULL) 4442 1.1 christos isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 4443 1.1 christos symtab_hdr->sh_info, 0, 4444 1.1 christos NULL, NULL, NULL); 4445 1.1 christos if (isymbuf == NULL) 4446 1.1 christos goto error_return; 4447 1.1 christos } 4448 1.1 christos 4449 1.1 christos isym = isymbuf + ELF32_R_SYM (irel->r_info); 4450 1.1 christos targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 4451 1.1 christos } 4452 1.1 christos else 4453 1.1 christos { 4454 1.1 christos unsigned long indx; 4455 1.1 christos struct elf_link_hash_entry *h; 4456 1.1 christos 4457 1.1 christos /* An external symbol. */ 4458 1.1 christos indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; 4459 1.1 christos h = elf_sym_hashes (abfd)[indx]; 4460 1.1 christos BFD_ASSERT (h != NULL); 4461 1.1 christos if (h->root.type == bfd_link_hash_defined 4462 1.1 christos || h->root.type == bfd_link_hash_defweak) 4463 1.1 christos targetsec = h->root.u.def.section; 4464 1.1 christos else 4465 1.1 christos targetsec = NULL; 4466 1.1 christos } 4467 1.1 christos 4468 1.1 christos bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p); 4469 1.1 christos memset (p + 4, 0, 8); 4470 1.1 christos if (targetsec != NULL) 4471 1.1 christos strncpy ((char *) p + 4, targetsec->output_section->name, 8); 4472 1.1.1.9 christos } 4473 1.1 christos 4474 1.1.1.9 christos if (symtab_hdr->contents != (unsigned char *) isymbuf) 4475 1.1 christos free (isymbuf); 4476 1.1.1.10 christos if (elf_section_data (datasec)->relocs != internal_relocs) 4477 1.1 christos free (internal_relocs); 4478 1.1.1.9 christos return true; 4479 1.1.1.9 christos 4480 1.1 christos error_return: 4481 1.1.1.9 christos if (symtab_hdr->contents != (unsigned char *) isymbuf) 4482 1.1 christos free (isymbuf); 4483 1.1.1.10 christos if (elf_section_data (datasec)->relocs != internal_relocs) 4484 1.1 christos free (internal_relocs); 4485 1.1 christos return false; 4486 1.1 christos } 4487 1.1 christos 4488 1.1 christos /* Set target options. */ 4489 1.1 christos 4490 1.1 christos void 4491 1.1 christos bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling) 4492 1.1.1.10 christos { 4493 1.1.1.10 christos struct elf_m68k_link_hash_table *htab; 4494 1.1.1.10 christos bool use_neg_got_offsets_p; 4495 1.1 christos bool allow_multigot_p; 4496 1.1 christos bool local_gp_p; 4497 1.1 christos 4498 1.1 christos switch (got_handling) 4499 1.1 christos { 4500 1.1.1.10 christos case 0: 4501 1.1.1.10 christos /* --got=single. */ 4502 1.1.1.10 christos local_gp_p = false; 4503 1.1 christos use_neg_got_offsets_p = false; 4504 1.1 christos allow_multigot_p = false; 4505 1.1 christos break; 4506 1.1 christos 4507 1.1.1.10 christos case 1: 4508 1.1.1.10 christos /* --got=negative. */ 4509 1.1.1.10 christos local_gp_p = true; 4510 1.1 christos use_neg_got_offsets_p = true; 4511 1.1 christos allow_multigot_p = false; 4512 1.1 christos break; 4513 1.1 christos 4514 1.1.1.10 christos case 2: 4515 1.1.1.10 christos /* --got=multigot. */ 4516 1.1.1.10 christos local_gp_p = true; 4517 1.1 christos use_neg_got_offsets_p = true; 4518 1.1 christos allow_multigot_p = true; 4519 1.1 christos break; 4520 1.1.1.10 christos 4521 1.1 christos default: 4522 1.1 christos BFD_ASSERT (false); 4523 1.1 christos return; 4524 1.1 christos } 4525 1.1 christos 4526 1.1 christos htab = elf_m68k_hash_table (info); 4527 1.1 christos if (htab != NULL) 4528 1.1 christos { 4529 1.1 christos htab->local_gp_p = local_gp_p; 4530 1.1 christos htab->use_neg_got_offsets_p = use_neg_got_offsets_p; 4531 1.1 christos htab->allow_multigot_p = allow_multigot_p; 4532 1.1 christos } 4533 1.1 christos } 4534 1.1.1.3 christos 4535 1.1.1.3 christos static enum elf_reloc_type_class 4536 1.1.1.3 christos elf32_m68k_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 4537 1.1 christos const asection *rel_sec ATTRIBUTE_UNUSED, 4538 1.1 christos const Elf_Internal_Rela *rela) 4539 1.1 christos { 4540 1.1 christos switch ((int) ELF32_R_TYPE (rela->r_info)) 4541 1.1 christos { 4542 1.1 christos case R_68K_RELATIVE: 4543 1.1 christos return reloc_class_relative; 4544 1.1 christos case R_68K_JMP_SLOT: 4545 1.1 christos return reloc_class_plt; 4546 1.1 christos case R_68K_COPY: 4547 1.1 christos return reloc_class_copy; 4548 1.1 christos default: 4549 1.1 christos return reloc_class_normal; 4550 1.1 christos } 4551 1.1 christos } 4552 1.1 christos 4553 1.1 christos /* Return address for Ith PLT stub in section PLT, for relocation REL 4554 1.1 christos or (bfd_vma) -1 if it should not be included. */ 4555 1.1 christos 4556 1.1 christos static bfd_vma 4557 1.1 christos elf_m68k_plt_sym_val (bfd_vma i, const asection *plt, 4558 1.1 christos const arelent *rel ATTRIBUTE_UNUSED) 4559 1.1 christos { 4560 1.1 christos return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size; 4561 1.1.1.2 christos } 4562 1.1.1.2 christos 4563 1.1.1.10 christos /* Support for core dump NOTE sections. */ 4564 1.1.1.2 christos 4565 1.1.1.2 christos static bool 4566 1.1.1.2 christos elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 4567 1.1.1.2 christos { 4568 1.1.1.2 christos int offset; 4569 1.1.1.2 christos size_t size; 4570 1.1.1.2 christos 4571 1.1.1.2 christos switch (note->descsz) 4572 1.1.1.10 christos { 4573 1.1.1.2 christos default: 4574 1.1.1.2 christos return false; 4575 1.1.1.2 christos 4576 1.1.1.2 christos case 154: /* Linux/m68k */ 4577 1.1.1.2 christos /* pr_cursig */ 4578 1.1.1.2 christos elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); 4579 1.1.1.2 christos 4580 1.1.1.2 christos /* pr_pid */ 4581 1.1.1.2 christos elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22); 4582 1.1.1.2 christos 4583 1.1.1.2 christos /* pr_reg */ 4584 1.1.1.2 christos offset = 70; 4585 1.1.1.2 christos size = 80; 4586 1.1.1.2 christos 4587 1.1.1.2 christos break; 4588 1.1.1.2 christos } 4589 1.1.1.2 christos 4590 1.1.1.2 christos /* Make a ".reg/999" section. */ 4591 1.1.1.2 christos return _bfd_elfcore_make_pseudosection (abfd, ".reg", 4592 1.1.1.2 christos size, note->descpos + offset); 4593 1.1.1.10 christos } 4594 1.1.1.2 christos 4595 1.1.1.2 christos static bool 4596 1.1.1.2 christos elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 4597 1.1.1.2 christos { 4598 1.1.1.2 christos switch (note->descsz) 4599 1.1.1.10 christos { 4600 1.1.1.2 christos default: 4601 1.1.1.2 christos return false; 4602 1.1.1.2 christos 4603 1.1.1.2 christos case 124: /* Linux/m68k elf_prpsinfo. */ 4604 1.1.1.2 christos elf_tdata (abfd)->core->pid 4605 1.1.1.2 christos = bfd_get_32 (abfd, note->descdata + 12); 4606 1.1.1.2 christos elf_tdata (abfd)->core->program 4607 1.1.1.2 christos = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); 4608 1.1.1.2 christos elf_tdata (abfd)->core->command 4609 1.1.1.2 christos = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); 4610 1.1.1.2 christos } 4611 1.1.1.2 christos 4612 1.1.1.2 christos /* Note that for some reason, a spurious space is tacked 4613 1.1.1.2 christos onto the end of the args in some (at least one anyway) 4614 1.1.1.2 christos implementations, so strip it off if it exists. */ 4615 1.1.1.2 christos { 4616 1.1.1.2 christos char *command = elf_tdata (abfd)->core->command; 4617 1.1.1.2 christos int n = strlen (command); 4618 1.1.1.2 christos 4619 1.1.1.2 christos if (n > 0 && command[n - 1] == ' ') 4620 1.1.1.2 christos command[n - 1] = '\0'; 4621 1.1.1.10 christos } 4622 1.1.1.2 christos 4623 1.1.1.2 christos return true; 4624 1.1.1.4 christos } 4625 1.1 christos 4626 1.1 christos #define TARGET_BIG_SYM m68k_elf32_vec 4627 1.1 christos #define TARGET_BIG_NAME "elf32-m68k" 4628 1.1 christos #define ELF_MACHINE_CODE EM_68K 4629 1.1 christos #define ELF_MAXPAGESIZE 0x2000 4630 1.1 christos #define elf_backend_create_dynamic_sections \ 4631 1.1 christos _bfd_elf_create_dynamic_sections 4632 1.1 christos #define bfd_elf32_bfd_link_hash_table_create \ 4633 1.1 christos elf_m68k_link_hash_table_create 4634 1.1 christos #define bfd_elf32_bfd_final_link bfd_elf_final_link 4635 1.1.1.11 christos 4636 1.1.1.11 christos #define elf_backend_check_relocs elf_m68k_check_relocs 4637 1.1 christos #define elf_backend_early_size_sections \ 4638 1.1 christos elf_m68k_early_size_sections 4639 1.1.1.11 christos #define elf_backend_adjust_dynamic_symbol \ 4640 1.1 christos elf_m68k_adjust_dynamic_symbol 4641 1.1 christos #define elf_backend_late_size_sections elf_m68k_late_size_sections 4642 1.1 christos #define elf_backend_final_write_processing elf_m68k_final_write_processing 4643 1.1 christos #define elf_backend_init_index_section _bfd_elf_init_1_index_section 4644 1.1 christos #define elf_backend_relocate_section elf_m68k_relocate_section 4645 1.1 christos #define elf_backend_finish_dynamic_symbol \ 4646 1.1 christos elf_m68k_finish_dynamic_symbol 4647 1.1 christos #define elf_backend_finish_dynamic_sections \ 4648 1.1 christos elf_m68k_finish_dynamic_sections 4649 1.1 christos #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook 4650 1.1.1.8 christos #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol 4651 1.1 christos #define bfd_elf32_bfd_merge_private_bfd_data \ 4652 1.1.1.8 christos elf32_m68k_merge_private_bfd_data 4653 1.1 christos #define bfd_elf32_bfd_set_private_flags \ 4654 1.1.1.8 christos elf32_m68k_set_private_flags 4655 1.1 christos #define bfd_elf32_bfd_print_private_bfd_data \ 4656 1.1 christos elf32_m68k_print_private_bfd_data 4657 1.1 christos #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class 4658 1.1.1.2 christos #define elf_backend_plt_sym_val elf_m68k_plt_sym_val 4659 1.1.1.2 christos #define elf_backend_object_p elf32_m68k_object_p 4660 1.1 christos #define elf_backend_grok_prstatus elf_m68k_grok_prstatus 4661 1.1 christos #define elf_backend_grok_psinfo elf_m68k_grok_psinfo 4662 1.1 christos 4663 1.1 christos #define elf_backend_can_gc_sections 1 4664 1.1 christos #define elf_backend_can_refcount 1 4665 1.1 christos #define elf_backend_want_got_plt 1 4666 1.1 christos #define elf_backend_plt_readonly 1 4667 1.1 christos #define elf_backend_want_plt_sym 0 4668 1.1.1.7 christos #define elf_backend_got_header_size 12 4669 1.1 christos #define elf_backend_rela_normal 1 4670 1.1.1.10 christos #define elf_backend_dtrel_excludes_plt 1 4671 1.1.1.8 christos 4672 1.1 christos #define elf_backend_linux_prpsinfo32_ugid16 true 4673 4674 #include "elf32-target.h" 4675