1 1.1 christos /* ADI Blackfin BFD support for 32-bit ELF. 2 1.1.1.11 christos Copyright (C) 2005-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of BFD, the Binary File Descriptor library. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program; if not, write to the Free Software 18 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 1.1 christos MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #include "sysdep.h" 22 1.1 christos #include "bfd.h" 23 1.1 christos #include "libbfd.h" 24 1.1 christos #include "elf-bfd.h" 25 1.1 christos #include "elf/bfin.h" 26 1.1 christos #include "dwarf2.h" 27 1.1 christos #include "hashtab.h" 28 1.1.1.9 christos #include "elf32-bfin.h" 29 1.1 christos 30 1.1 christos /* FUNCTION : bfin_pltpc_reloc 31 1.1 christos ABSTRACT : TODO : figure out how to handle pltpc relocs. */ 32 1.1 christos static bfd_reloc_status_type 33 1.1 christos bfin_pltpc_reloc ( 34 1.1 christos bfd *abfd ATTRIBUTE_UNUSED, 35 1.1 christos arelent *reloc_entry ATTRIBUTE_UNUSED, 36 1.1 christos asymbol *symbol ATTRIBUTE_UNUSED, 37 1.1.1.2 christos void * data ATTRIBUTE_UNUSED, 38 1.1 christos asection *input_section ATTRIBUTE_UNUSED, 39 1.1 christos bfd *output_bfd ATTRIBUTE_UNUSED, 40 1.1 christos char **error_message ATTRIBUTE_UNUSED) 41 1.1 christos { 42 1.1 christos bfd_reloc_status_type flag = bfd_reloc_ok; 43 1.1 christos return flag; 44 1.1 christos } 45 1.1 christos 46 1.1 christos 48 1.1 christos static bfd_reloc_status_type 49 1.1.1.8 christos bfin_pcrel24_reloc (bfd *abfd, 50 1.1.1.8 christos arelent *reloc_entry, 51 1.1.1.8 christos asymbol *symbol, 52 1.1.1.8 christos void * data, 53 1.1.1.8 christos asection *input_section, 54 1.1.1.8 christos bfd *output_bfd, 55 1.1 christos char **error_message ATTRIBUTE_UNUSED) 56 1.1 christos { 57 1.1 christos bfd_vma relocation; 58 1.1 christos bfd_size_type addr = reloc_entry->address; 59 1.1 christos bfd_vma output_base = 0; 60 1.1 christos reloc_howto_type *howto = reloc_entry->howto; 61 1.1.1.10 christos asection *output_section; 62 1.1 christos bool relocatable = (output_bfd != NULL); 63 1.1.1.10 christos 64 1.1 christos if (!bfd_reloc_offset_in_range (howto, abfd, input_section, addr - 2)) 65 1.1 christos return bfd_reloc_outofrange; 66 1.1 christos 67 1.1 christos if (bfd_is_und_section (symbol->section) 68 1.1 christos && (symbol->flags & BSF_WEAK) == 0 69 1.1 christos && !relocatable) 70 1.1 christos return bfd_reloc_undefined; 71 1.1 christos 72 1.1 christos if (bfd_is_com_section (symbol->section)) 73 1.1 christos relocation = 0; 74 1.1 christos else 75 1.1 christos relocation = symbol->value; 76 1.1 christos 77 1.1 christos output_section = symbol->section->output_section; 78 1.1 christos 79 1.1 christos if (relocatable) 80 1.1 christos output_base = 0; 81 1.1 christos else 82 1.1 christos output_base = output_section->vma; 83 1.1 christos 84 1.1 christos if (!relocatable || !strcmp (symbol->name, symbol->section->name)) 85 1.1 christos relocation += output_base + symbol->section->output_offset; 86 1.1 christos 87 1.1 christos if (!relocatable && !strcmp (symbol->name, symbol->section->name)) 88 1.1 christos relocation += reloc_entry->addend; 89 1.1 christos 90 1.1 christos relocation -= input_section->output_section->vma + input_section->output_offset; 91 1.1 christos relocation -= reloc_entry->address; 92 1.1 christos 93 1.1 christos if (howto->complain_on_overflow != complain_overflow_dont) 94 1.1 christos { 95 1.1 christos bfd_reloc_status_type status; 96 1.1 christos status = bfd_check_overflow (howto->complain_on_overflow, 97 1.1 christos howto->bitsize, 98 1.1 christos howto->rightshift, 99 1.1 christos bfd_arch_bits_per_address(abfd), 100 1.1 christos relocation); 101 1.1 christos if (status != bfd_reloc_ok) 102 1.1 christos return status; 103 1.1 christos } 104 1.1 christos 105 1.1 christos /* if rightshift is 1 and the number odd, return error. */ 106 1.1 christos if (howto->rightshift && (relocation & 0x01)) 107 1.1.1.7 christos { 108 1.1 christos _bfd_error_handler (_("relocation should be even number")); 109 1.1 christos return bfd_reloc_overflow; 110 1.1 christos } 111 1.1 christos 112 1.1 christos relocation >>= (bfd_vma) howto->rightshift; 113 1.1 christos /* Shift everything up to where it's going to be used. */ 114 1.1 christos 115 1.1 christos relocation <<= (bfd_vma) howto->bitpos; 116 1.1 christos 117 1.1 christos if (relocatable) 118 1.1 christos { 119 1.1 christos reloc_entry->address += input_section->output_offset; 120 1.1 christos reloc_entry->addend += symbol->section->output_offset; 121 1.1 christos } 122 1.1 christos 123 1.1 christos { 124 1.1 christos short x; 125 1.1 christos 126 1.1 christos /* We are getting reloc_entry->address 2 byte off from 127 1.1 christos the start of instruction. Assuming absolute postion 128 1.1 christos of the reloc data. But, following code had been written assuming 129 1.1 christos reloc address is starting at begining of instruction. 130 1.1 christos To compensate that I have increased the value of 131 1.1 christos relocation by 1 (effectively 2) and used the addr -2 instead of addr. */ 132 1.1 christos 133 1.1 christos relocation += 1; 134 1.1 christos x = bfd_get_16 (abfd, (bfd_byte *) data + addr - 2); 135 1.1 christos x = (x & 0xff00) | ((relocation >> 16) & 0xff); 136 1.1 christos bfd_put_16 (abfd, x, (unsigned char *) data + addr - 2); 137 1.1 christos 138 1.1 christos x = bfd_get_16 (abfd, (bfd_byte *) data + addr); 139 1.1 christos x = relocation & 0xFFFF; 140 1.1 christos bfd_put_16 (abfd, x, (unsigned char *) data + addr ); 141 1.1 christos } 142 1.1 christos return bfd_reloc_ok; 143 1.1 christos } 144 1.1 christos 145 1.1 christos static bfd_reloc_status_type 146 1.1.1.9 christos bfin_imm16_reloc (bfd *abfd, 147 1.1.1.9 christos arelent *reloc_entry, 148 1.1.1.9 christos asymbol *symbol, 149 1.1.1.9 christos void * data, 150 1.1.1.9 christos asection *input_section, 151 1.1.1.9 christos bfd *output_bfd, 152 1.1 christos char **error_message ATTRIBUTE_UNUSED) 153 1.1 christos { 154 1.1 christos bfd_vma relocation, x; 155 1.1 christos bfd_size_type reloc_addr = reloc_entry->address; 156 1.1 christos bfd_vma output_base = 0; 157 1.1 christos reloc_howto_type *howto = reloc_entry->howto; 158 1.1.1.10 christos asection *output_section; 159 1.1 christos bool relocatable = (output_bfd != NULL); 160 1.1 christos 161 1.1.1.10 christos /* Is the address of the relocation really within the section? */ 162 1.1 christos if (!bfd_reloc_offset_in_range (howto, abfd, input_section, reloc_addr)) 163 1.1 christos return bfd_reloc_outofrange; 164 1.1 christos 165 1.1 christos if (bfd_is_und_section (symbol->section) 166 1.1 christos && (symbol->flags & BSF_WEAK) == 0 167 1.1 christos && !relocatable) 168 1.1 christos return bfd_reloc_undefined; 169 1.1 christos 170 1.1 christos output_section = symbol->section->output_section; 171 1.1 christos relocation = symbol->value; 172 1.1 christos 173 1.1 christos /* Convert input-section-relative symbol value to absolute. */ 174 1.1 christos if (relocatable) 175 1.1 christos output_base = 0; 176 1.1 christos else 177 1.1 christos output_base = output_section->vma; 178 1.1 christos 179 1.1 christos if (!relocatable || !strcmp (symbol->name, symbol->section->name)) 180 1.1 christos relocation += output_base + symbol->section->output_offset; 181 1.1 christos 182 1.1 christos /* Add in supplied addend. */ 183 1.1 christos relocation += reloc_entry->addend; 184 1.1 christos 185 1.1 christos if (relocatable) 186 1.1 christos { 187 1.1 christos reloc_entry->address += input_section->output_offset; 188 1.1 christos reloc_entry->addend += symbol->section->output_offset; 189 1.1 christos } 190 1.1 christos else 191 1.1 christos { 192 1.1 christos reloc_entry->addend = 0; 193 1.1 christos } 194 1.1 christos 195 1.1 christos if (howto->complain_on_overflow != complain_overflow_dont) 196 1.1 christos { 197 1.1 christos bfd_reloc_status_type flag; 198 1.1 christos flag = bfd_check_overflow (howto->complain_on_overflow, 199 1.1 christos howto->bitsize, 200 1.1 christos howto->rightshift, 201 1.1 christos bfd_arch_bits_per_address(abfd), 202 1.1 christos relocation); 203 1.1 christos if (flag != bfd_reloc_ok) 204 1.1 christos return flag; 205 1.1 christos } 206 1.1 christos 207 1.1 christos /* Here the variable relocation holds the final address of the 208 1.1 christos symbol we are relocating against, plus any addend. */ 209 1.1 christos 210 1.1 christos relocation >>= (bfd_vma) howto->rightshift; 211 1.1 christos x = relocation; 212 1.1 christos bfd_put_16 (abfd, x, (unsigned char *) data + reloc_addr); 213 1.1 christos return bfd_reloc_ok; 214 1.1 christos } 215 1.1 christos 216 1.1 christos 217 1.1 christos static bfd_reloc_status_type 218 1.1.1.8 christos bfin_byte4_reloc (bfd *abfd, 219 1.1.1.8 christos arelent *reloc_entry, 220 1.1.1.8 christos asymbol *symbol, 221 1.1.1.8 christos void * data, 222 1.1.1.8 christos asection *input_section, 223 1.1.1.8 christos bfd *output_bfd, 224 1.1 christos char **error_message ATTRIBUTE_UNUSED) 225 1.1 christos { 226 1.1 christos bfd_vma relocation, x; 227 1.1 christos bfd_size_type addr = reloc_entry->address; 228 1.1 christos bfd_vma output_base = 0; 229 1.1.1.10 christos asection *output_section; 230 1.1 christos bool relocatable = (output_bfd != NULL); 231 1.1 christos 232 1.1.1.10 christos /* Is the address of the relocation really within the section? */ 233 1.1.1.10 christos if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, input_section, 234 1.1 christos addr)) 235 1.1 christos return bfd_reloc_outofrange; 236 1.1 christos 237 1.1 christos if (bfd_is_und_section (symbol->section) 238 1.1 christos && (symbol->flags & BSF_WEAK) == 0 239 1.1 christos && !relocatable) 240 1.1 christos return bfd_reloc_undefined; 241 1.1 christos 242 1.1 christos output_section = symbol->section->output_section; 243 1.1 christos relocation = symbol->value; 244 1.1 christos /* Convert input-section-relative symbol value to absolute. */ 245 1.1 christos if (relocatable) 246 1.1 christos output_base = 0; 247 1.1 christos else 248 1.1 christos output_base = output_section->vma; 249 1.1 christos 250 1.1 christos if ((symbol->name 251 1.1 christos && symbol->section->name 252 1.1 christos && !strcmp (symbol->name, symbol->section->name)) 253 1.1 christos || !relocatable) 254 1.1 christos { 255 1.1 christos relocation += output_base + symbol->section->output_offset; 256 1.1 christos } 257 1.1 christos 258 1.1 christos relocation += reloc_entry->addend; 259 1.1 christos 260 1.1 christos if (relocatable) 261 1.1 christos { 262 1.1 christos /* This output will be relocatable ... like ld -r. */ 263 1.1 christos reloc_entry->address += input_section->output_offset; 264 1.1 christos reloc_entry->addend += symbol->section->output_offset; 265 1.1 christos } 266 1.1 christos else 267 1.1 christos { 268 1.1 christos reloc_entry->addend = 0; 269 1.1 christos } 270 1.1 christos 271 1.1 christos /* Here the variable relocation holds the final address of the 272 1.1 christos symbol we are relocating against, plus any addend. */ 273 1.1 christos x = relocation & 0xFFFF0000; 274 1.1 christos x >>=16; 275 1.1 christos bfd_put_16 (abfd, x, (unsigned char *) data + addr + 2); 276 1.1 christos 277 1.1 christos x = relocation & 0x0000FFFF; 278 1.1 christos bfd_put_16 (abfd, x, (unsigned char *) data + addr); 279 1.1 christos return bfd_reloc_ok; 280 1.1 christos } 281 1.1 christos 282 1.1 christos /* bfin_bfd_reloc handles the blackfin arithmetic relocations. 283 1.1 christos Use this instead of bfd_perform_relocation. */ 284 1.1 christos static bfd_reloc_status_type 285 1.1 christos bfin_bfd_reloc (bfd *abfd, 286 1.1.1.9 christos arelent *reloc_entry, 287 1.1.1.9 christos asymbol *symbol, 288 1.1.1.9 christos void * data, 289 1.1.1.9 christos asection *input_section, 290 1.1.1.9 christos bfd *output_bfd, 291 1.1 christos char **error_message ATTRIBUTE_UNUSED) 292 1.1 christos { 293 1.1 christos bfd_vma relocation; 294 1.1 christos bfd_size_type addr = reloc_entry->address; 295 1.1 christos bfd_vma output_base = 0; 296 1.1 christos reloc_howto_type *howto = reloc_entry->howto; 297 1.1.1.10 christos asection *output_section; 298 1.1 christos bool relocatable = (output_bfd != NULL); 299 1.1 christos 300 1.1.1.10 christos /* Is the address of the relocation really within the section? */ 301 1.1 christos if (!bfd_reloc_offset_in_range (howto, abfd, input_section, addr)) 302 1.1 christos return bfd_reloc_outofrange; 303 1.1 christos 304 1.1 christos if (bfd_is_und_section (symbol->section) 305 1.1 christos && (symbol->flags & BSF_WEAK) == 0 306 1.1 christos && !relocatable) 307 1.1 christos return bfd_reloc_undefined; 308 1.1 christos 309 1.1 christos /* Get symbol value. (Common symbols are special.) */ 310 1.1 christos if (bfd_is_com_section (symbol->section)) 311 1.1 christos relocation = 0; 312 1.1 christos else 313 1.1 christos relocation = symbol->value; 314 1.1 christos 315 1.1 christos output_section = symbol->section->output_section; 316 1.1 christos 317 1.1 christos /* Convert input-section-relative symbol value to absolute. */ 318 1.1 christos if (relocatable) 319 1.1 christos output_base = 0; 320 1.1 christos else 321 1.1 christos output_base = output_section->vma; 322 1.1 christos 323 1.1 christos if (!relocatable || !strcmp (symbol->name, symbol->section->name)) 324 1.1 christos relocation += output_base + symbol->section->output_offset; 325 1.1 christos 326 1.1 christos if (!relocatable && !strcmp (symbol->name, symbol->section->name)) 327 1.1 christos { 328 1.1 christos /* Add in supplied addend. */ 329 1.1 christos relocation += reloc_entry->addend; 330 1.1 christos } 331 1.1 christos 332 1.1 christos /* Here the variable relocation holds the final address of the 333 1.1 christos symbol we are relocating against, plus any addend. */ 334 1.1.1.8 christos 335 1.1 christos if (howto->pc_relative) 336 1.1 christos { 337 1.1 christos relocation -= input_section->output_section->vma + input_section->output_offset; 338 1.1.1.8 christos 339 1.1.1.8 christos if (howto->pcrel_offset) 340 1.1 christos relocation -= reloc_entry->address; 341 1.1 christos } 342 1.1 christos 343 1.1 christos if (relocatable) 344 1.1 christos { 345 1.1 christos reloc_entry->address += input_section->output_offset; 346 1.1 christos reloc_entry->addend += symbol->section->output_offset; 347 1.1 christos } 348 1.1 christos 349 1.1 christos if (howto->complain_on_overflow != complain_overflow_dont) 350 1.1 christos { 351 1.1 christos bfd_reloc_status_type status; 352 1.1 christos 353 1.1.1.8 christos status = bfd_check_overflow (howto->complain_on_overflow, 354 1.1.1.8 christos howto->bitsize, 355 1.1.1.8 christos howto->rightshift, 356 1.1.1.8 christos bfd_arch_bits_per_address(abfd), 357 1.1 christos relocation); 358 1.1 christos if (status != bfd_reloc_ok) 359 1.1 christos return status; 360 1.1 christos } 361 1.1 christos 362 1.1 christos /* If rightshift is 1 and the number odd, return error. */ 363 1.1 christos if (howto->rightshift && (relocation & 0x01)) 364 1.1.1.7 christos { 365 1.1 christos _bfd_error_handler (_("relocation should be even number")); 366 1.1 christos return bfd_reloc_overflow; 367 1.1 christos } 368 1.1 christos 369 1.1 christos relocation >>= (bfd_vma) howto->rightshift; 370 1.1 christos 371 1.1 christos /* Shift everything up to where it's going to be used. */ 372 1.1 christos 373 1.1 christos relocation <<= (bfd_vma) howto->bitpos; 374 1.1 christos 375 1.1 christos #define DOIT(x) \ 376 1.1 christos x = ( (x & ~howto->dst_mask) | (relocation & howto->dst_mask)) 377 1.1 christos 378 1.1.1.10 christos /* handle 8 and 16 bit relocations here. */ 379 1.1 christos switch (bfd_get_reloc_size (howto)) 380 1.1.1.10 christos { 381 1.1 christos case 1: 382 1.1.1.8 christos { 383 1.1.1.8 christos char x = bfd_get_8 (abfd, (char *) data + addr); 384 1.1.1.8 christos DOIT (x); 385 1.1 christos bfd_put_8 (abfd, x, (unsigned char *) data + addr); 386 1.1 christos } 387 1.1 christos break; 388 1.1.1.10 christos 389 1.1 christos case 2: 390 1.1.1.8 christos { 391 1.1.1.8 christos unsigned short x = bfd_get_16 (abfd, (bfd_byte *) data + addr); 392 1.1.1.8 christos DOIT (x); 393 1.1 christos bfd_put_16 (abfd, (bfd_vma) x, (unsigned char *) data + addr); 394 1.1 christos } 395 1.1 christos break; 396 1.1 christos 397 1.1 christos default: 398 1.1 christos return bfd_reloc_other; 399 1.1 christos } 400 1.1 christos 401 1.1 christos return bfd_reloc_ok; 402 1.1 christos } 403 1.1 christos 404 1.1 christos /* HOWTO Table for blackfin. 405 1.1 christos Blackfin relocations are fairly complicated. 406 1.1 christos Some of the salient features are 407 1.1 christos a. Even numbered offsets. A number of (not all) relocations are 408 1.1 christos even numbered. This means that the rightmost bit is not stored. 409 1.1 christos Needs to right shift by 1 and check to see if value is not odd 410 1.1 christos b. A relocation can be an expression. An expression takes on 411 1.1 christos a variety of relocations arranged in a stack. 412 1.1 christos As a result, we cannot use the standard generic function as special 413 1.1 christos function. We will have our own, which is very similar to the standard 414 1.1 christos generic function except that it understands how to get the value from 415 1.1 christos the relocation stack. . */ 416 1.1 christos 417 1.1 christos #define BFIN_RELOC_MIN 0 418 1.1 christos #define BFIN_RELOC_MAX 0x21 419 1.1 christos #define BFIN_GNUEXT_RELOC_MIN 0x40 420 1.1 christos #define BFIN_GNUEXT_RELOC_MAX 0x43 421 1.1 christos #define BFIN_ARELOC_MIN 0xE0 422 1.1 christos #define BFIN_ARELOC_MAX 0xF3 423 1.1 christos 424 1.1 christos static reloc_howto_type bfin_howto_table [] = 425 1.1 christos { 426 1.1 christos /* This reloc does nothing. . */ 427 1.1 christos HOWTO (R_BFIN_UNUSED0, /* type. */ 428 1.1.1.10 christos 0, /* rightshift. */ 429 1.1.1.5 christos 0, /* size. */ 430 1.1.1.10 christos 0, /* bitsize. */ 431 1.1 christos false, /* pc_relative. */ 432 1.1.1.5 christos 0, /* bitpos. */ 433 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 434 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 435 1.1.1.10 christos "R_BFIN_UNUSED0", /* name. */ 436 1.1 christos false, /* partial_inplace. */ 437 1.1 christos 0, /* src_mask. */ 438 1.1.1.10 christos 0, /* dst_mask. */ 439 1.1 christos false), /* pcrel_offset. */ 440 1.1 christos 441 1.1 christos HOWTO (R_BFIN_PCREL5M2, /* type. */ 442 1.1.1.10 christos 1, /* rightshift. */ 443 1.1 christos 2, /* size. */ 444 1.1.1.10 christos 4, /* bitsize. */ 445 1.1 christos true, /* pc_relative. */ 446 1.1 christos 0, /* bitpos. */ 447 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 448 1.1 christos bfin_bfd_reloc, /* special_function. */ 449 1.1.1.10 christos "R_BFIN_PCREL5M2", /* name. */ 450 1.1 christos false, /* partial_inplace. */ 451 1.1 christos 0, /* src_mask. */ 452 1.1.1.10 christos 0x0000000F, /* dst_mask. */ 453 1.1 christos false), /* pcrel_offset. */ 454 1.1 christos 455 1.1 christos HOWTO (R_BFIN_UNUSED1, /* type. */ 456 1.1.1.10 christos 0, /* rightshift. */ 457 1.1.1.5 christos 0, /* size. */ 458 1.1.1.10 christos 0, /* bitsize. */ 459 1.1 christos false, /* pc_relative. */ 460 1.1.1.5 christos 0, /* bitpos. */ 461 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 462 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 463 1.1.1.10 christos "R_BFIN_UNUSED1", /* name. */ 464 1.1 christos false, /* partial_inplace. */ 465 1.1 christos 0, /* src_mask. */ 466 1.1.1.10 christos 0, /* dst_mask. */ 467 1.1 christos false), /* pcrel_offset. */ 468 1.1 christos 469 1.1 christos HOWTO (R_BFIN_PCREL10, /* type. */ 470 1.1.1.10 christos 1, /* rightshift. */ 471 1.1 christos 2, /* size. */ 472 1.1.1.10 christos 10, /* bitsize. */ 473 1.1 christos true, /* pc_relative. */ 474 1.1 christos 0, /* bitpos. */ 475 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 476 1.1 christos bfin_bfd_reloc, /* special_function. */ 477 1.1.1.10 christos "R_BFIN_PCREL10", /* name. */ 478 1.1 christos false, /* partial_inplace. */ 479 1.1 christos 0, /* src_mask. */ 480 1.1.1.10 christos 0x000003FF, /* dst_mask. */ 481 1.1 christos true), /* pcrel_offset. */ 482 1.1 christos 483 1.1 christos HOWTO (R_BFIN_PCREL12_JUMP, /* type. */ 484 1.1 christos 1, /* rightshift. */ 485 1.1 christos /* the offset is actually 13 bit 486 1.1 christos aligned on a word boundary so 487 1.1 christos only 12 bits have to be used. 488 1.1.1.10 christos Right shift the rightmost bit.. */ 489 1.1 christos 2, /* size. */ 490 1.1.1.10 christos 12, /* bitsize. */ 491 1.1 christos true, /* pc_relative. */ 492 1.1 christos 0, /* bitpos. */ 493 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 494 1.1 christos bfin_bfd_reloc, /* special_function. */ 495 1.1.1.10 christos "R_BFIN_PCREL12_JUMP", /* name. */ 496 1.1 christos false, /* partial_inplace. */ 497 1.1 christos 0, /* src_mask. */ 498 1.1.1.10 christos 0x0FFF, /* dst_mask. */ 499 1.1 christos true), /* pcrel_offset. */ 500 1.1 christos 501 1.1 christos HOWTO (R_BFIN_RIMM16, /* type. */ 502 1.1.1.10 christos 0, /* rightshift. */ 503 1.1 christos 2, /* size. */ 504 1.1.1.10 christos 16, /* bitsize. */ 505 1.1 christos false, /* pc_relative. */ 506 1.1 christos 0, /* bitpos. */ 507 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 508 1.1 christos bfin_imm16_reloc, /* special_function. */ 509 1.1.1.10 christos "R_BFIN_RIMM16", /* name. */ 510 1.1 christos false, /* partial_inplace. */ 511 1.1 christos 0, /* src_mask. */ 512 1.1.1.10 christos 0x0000FFFF, /* dst_mask. */ 513 1.1 christos true), /* pcrel_offset. */ 514 1.1 christos 515 1.1 christos HOWTO (R_BFIN_LUIMM16, /* type. */ 516 1.1.1.10 christos 0, /* rightshift. */ 517 1.1 christos 2, /* size. */ 518 1.1.1.10 christos 16, /* bitsize. */ 519 1.1 christos false, /* pc_relative. */ 520 1.1 christos 0, /* bitpos. */ 521 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 522 1.1 christos bfin_imm16_reloc, /* special_function. */ 523 1.1.1.10 christos "R_BFIN_LUIMM16", /* name. */ 524 1.1 christos false, /* partial_inplace. */ 525 1.1 christos 0, /* src_mask. */ 526 1.1.1.10 christos 0x0000FFFF, /* dst_mask. */ 527 1.1 christos true), /* pcrel_offset. */ 528 1.1 christos 529 1.1 christos HOWTO (R_BFIN_HUIMM16, /* type. */ 530 1.1.1.10 christos 16, /* rightshift. */ 531 1.1 christos 2, /* size. */ 532 1.1.1.10 christos 16, /* bitsize. */ 533 1.1 christos false, /* pc_relative. */ 534 1.1 christos 0, /* bitpos. */ 535 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 536 1.1 christos bfin_imm16_reloc, /* special_function. */ 537 1.1.1.10 christos "R_BFIN_HUIMM16", /* name. */ 538 1.1 christos false, /* partial_inplace. */ 539 1.1 christos 0, /* src_mask. */ 540 1.1.1.10 christos 0x0000FFFF, /* dst_mask. */ 541 1.1 christos true), /* pcrel_offset. */ 542 1.1 christos 543 1.1 christos HOWTO (R_BFIN_PCREL12_JUMP_S, /* type. */ 544 1.1.1.10 christos 1, /* rightshift. */ 545 1.1 christos 2, /* size. */ 546 1.1.1.10 christos 12, /* bitsize. */ 547 1.1 christos true, /* pc_relative. */ 548 1.1 christos 0, /* bitpos. */ 549 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 550 1.1 christos bfin_bfd_reloc, /* special_function. */ 551 1.1.1.10 christos "R_BFIN_PCREL12_JUMP_S", /* name. */ 552 1.1 christos false, /* partial_inplace. */ 553 1.1 christos 0, /* src_mask. */ 554 1.1.1.10 christos 0x00000FFF, /* dst_mask. */ 555 1.1 christos true), /* pcrel_offset. */ 556 1.1 christos 557 1.1.1.8 christos HOWTO (R_BFIN_PCREL24_JUMP_X, /* type. */ 558 1.1.1.10 christos 1, /* rightshift. */ 559 1.1.1.8 christos 4, /* size. */ 560 1.1.1.10 christos 24, /* bitsize. */ 561 1.1.1.8 christos true, /* pc_relative. */ 562 1.1.1.8 christos 0, /* bitpos. */ 563 1.1.1.8 christos complain_overflow_signed, /* complain_on_overflow. */ 564 1.1 christos bfin_pcrel24_reloc, /* special_function. */ 565 1.1.1.10 christos "R_BFIN_PCREL24_JUMP_X", /* name. */ 566 1.1 christos false, /* partial_inplace. */ 567 1.1 christos 0, /* src_mask. */ 568 1.1.1.10 christos 0x00FFFFFF, /* dst_mask. */ 569 1.1 christos true), /* pcrel_offset. */ 570 1.1 christos 571 1.1 christos HOWTO (R_BFIN_PCREL24, /* type. */ 572 1.1.1.10 christos 1, /* rightshift. */ 573 1.1 christos 4, /* size. */ 574 1.1.1.10 christos 24, /* bitsize. */ 575 1.1 christos true, /* pc_relative. */ 576 1.1 christos 0, /* bitpos. */ 577 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 578 1.1 christos bfin_pcrel24_reloc, /* special_function. */ 579 1.1.1.10 christos "R_BFIN_PCREL24", /* name. */ 580 1.1 christos false, /* partial_inplace. */ 581 1.1 christos 0, /* src_mask. */ 582 1.1.1.10 christos 0x00FFFFFF, /* dst_mask. */ 583 1.1 christos true), /* pcrel_offset. */ 584 1.1 christos 585 1.1 christos HOWTO (R_BFIN_UNUSEDB, /* type. */ 586 1.1.1.10 christos 0, /* rightshift. */ 587 1.1.1.5 christos 0, /* size. */ 588 1.1.1.10 christos 0, /* bitsize. */ 589 1.1 christos false, /* pc_relative. */ 590 1.1 christos 0, /* bitpos. */ 591 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 592 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 593 1.1.1.10 christos "R_BFIN_UNUSEDB", /* name. */ 594 1.1 christos false, /* partial_inplace. */ 595 1.1 christos 0, /* src_mask. */ 596 1.1.1.10 christos 0, /* dst_mask. */ 597 1.1 christos false), /* pcrel_offset. */ 598 1.1 christos 599 1.1 christos HOWTO (R_BFIN_UNUSEDC, /* type. */ 600 1.1.1.10 christos 0, /* rightshift. */ 601 1.1.1.5 christos 0, /* size. */ 602 1.1.1.10 christos 0, /* bitsize. */ 603 1.1 christos false, /* pc_relative. */ 604 1.1 christos 0, /* bitpos. */ 605 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 606 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 607 1.1.1.10 christos "R_BFIN_UNUSEDC", /* name. */ 608 1.1 christos false, /* partial_inplace. */ 609 1.1 christos 0, /* src_mask. */ 610 1.1.1.10 christos 0, /* dst_mask. */ 611 1.1 christos false), /* pcrel_offset. */ 612 1.1 christos 613 1.1 christos HOWTO (R_BFIN_PCREL24_JUMP_L, /* type. */ 614 1.1.1.10 christos 1, /* rightshift. */ 615 1.1 christos 4, /* size. */ 616 1.1.1.10 christos 24, /* bitsize. */ 617 1.1 christos true, /* pc_relative. */ 618 1.1 christos 0, /* bitpos. */ 619 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 620 1.1 christos bfin_pcrel24_reloc, /* special_function. */ 621 1.1.1.10 christos "R_BFIN_PCREL24_JUMP_L", /* name. */ 622 1.1 christos false, /* partial_inplace. */ 623 1.1 christos 0, /* src_mask. */ 624 1.1.1.10 christos 0x00FFFFFF, /* dst_mask. */ 625 1.1 christos true), /* pcrel_offset. */ 626 1.1 christos 627 1.1 christos HOWTO (R_BFIN_PCREL24_CALL_X, /* type. */ 628 1.1.1.10 christos 1, /* rightshift. */ 629 1.1 christos 4, /* size. */ 630 1.1.1.10 christos 24, /* bitsize. */ 631 1.1 christos true, /* pc_relative. */ 632 1.1 christos 0, /* bitpos. */ 633 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 634 1.1 christos bfin_pcrel24_reloc, /* special_function. */ 635 1.1.1.10 christos "R_BFIN_PCREL24_CALL_X", /* name. */ 636 1.1 christos false, /* partial_inplace. */ 637 1.1 christos 0, /* src_mask. */ 638 1.1.1.10 christos 0x00FFFFFF, /* dst_mask. */ 639 1.1 christos true), /* pcrel_offset. */ 640 1.1 christos 641 1.1 christos HOWTO (R_BFIN_VAR_EQ_SYMB, /* type. */ 642 1.1.1.10 christos 0, /* rightshift. */ 643 1.1 christos 4, /* size. */ 644 1.1.1.10 christos 32, /* bitsize. */ 645 1.1 christos false, /* pc_relative. */ 646 1.1 christos 0, /* bitpos. */ 647 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 648 1.1 christos bfin_bfd_reloc, /* special_function. */ 649 1.1.1.10 christos "R_BFIN_VAR_EQ_SYMB", /* name. */ 650 1.1 christos false, /* partial_inplace. */ 651 1.1 christos 0, /* src_mask. */ 652 1.1.1.10 christos 0, /* dst_mask. */ 653 1.1 christos false), /* pcrel_offset. */ 654 1.1 christos 655 1.1 christos HOWTO (R_BFIN_BYTE_DATA, /* type. */ 656 1.1.1.10 christos 0, /* rightshift. */ 657 1.1 christos 1, /* size. */ 658 1.1.1.10 christos 8, /* bitsize. */ 659 1.1 christos false, /* pc_relative. */ 660 1.1 christos 0, /* bitpos. */ 661 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 662 1.1 christos bfin_bfd_reloc, /* special_function. */ 663 1.1.1.10 christos "R_BFIN_BYTE_DATA", /* name. */ 664 1.1 christos false, /* partial_inplace. */ 665 1.1 christos 0, /* src_mask. */ 666 1.1.1.10 christos 0xFF, /* dst_mask. */ 667 1.1 christos true), /* pcrel_offset. */ 668 1.1 christos 669 1.1 christos HOWTO (R_BFIN_BYTE2_DATA, /* type. */ 670 1.1.1.10 christos 0, /* rightshift. */ 671 1.1 christos 2, /* size. */ 672 1.1.1.10 christos 16, /* bitsize. */ 673 1.1 christos false, /* pc_relative. */ 674 1.1 christos 0, /* bitpos. */ 675 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 676 1.1 christos bfin_bfd_reloc, /* special_function. */ 677 1.1.1.10 christos "R_BFIN_BYTE2_DATA", /* name. */ 678 1.1 christos false, /* partial_inplace. */ 679 1.1 christos 0, /* src_mask. */ 680 1.1.1.10 christos 0xFFFF, /* dst_mask. */ 681 1.1 christos true), /* pcrel_offset. */ 682 1.1 christos 683 1.1 christos HOWTO (R_BFIN_BYTE4_DATA, /* type. */ 684 1.1.1.10 christos 0, /* rightshift. */ 685 1.1 christos 4, /* size. */ 686 1.1.1.10 christos 32, /* bitsize. */ 687 1.1 christos false, /* pc_relative. */ 688 1.1 christos 0, /* bitpos. */ 689 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 690 1.1 christos bfin_byte4_reloc, /* special_function. */ 691 1.1.1.10 christos "R_BFIN_BYTE4_DATA", /* name. */ 692 1.1 christos false, /* partial_inplace. */ 693 1.1 christos 0, /* src_mask. */ 694 1.1.1.10 christos 0xFFFFFFFF, /* dst_mask. */ 695 1.1 christos true), /* pcrel_offset. */ 696 1.1 christos 697 1.1 christos HOWTO (R_BFIN_PCREL11, /* type. */ 698 1.1.1.10 christos 1, /* rightshift. */ 699 1.1 christos 2, /* size. */ 700 1.1.1.10 christos 10, /* bitsize. */ 701 1.1 christos true, /* pc_relative. */ 702 1.1 christos 0, /* bitpos. */ 703 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 704 1.1 christos bfin_bfd_reloc, /* special_function. */ 705 1.1.1.10 christos "R_BFIN_PCREL11", /* name. */ 706 1.1 christos false, /* partial_inplace. */ 707 1.1 christos 0, /* src_mask. */ 708 1.1.1.10 christos 0x000003FF, /* dst_mask. */ 709 1.1 christos false), /* pcrel_offset. */ 710 1.1 christos 711 1.1 christos 712 1.1 christos /* A 18-bit signed operand with the GOT offset for the address of 713 1.1.1.8 christos the symbol. */ 714 1.1 christos HOWTO (R_BFIN_GOT17M4, /* type */ 715 1.1.1.10 christos 2, /* rightshift */ 716 1.1 christos 2, /* size */ 717 1.1.1.10 christos 16, /* bitsize */ 718 1.1 christos false, /* pc_relative */ 719 1.1 christos 0, /* bitpos */ 720 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 721 1.1 christos bfd_elf_generic_reloc, /* special_function */ 722 1.1.1.10 christos "R_BFIN_GOT17M4", /* name */ 723 1.1.1.8 christos false, /* partial_inplace */ 724 1.1.1.8 christos 0xffff, /* src_mask */ 725 1.1.1.10 christos 0xffff, /* dst_mask */ 726 1.1 christos false), /* pcrel_offset */ 727 1.1 christos 728 1.1 christos /* The upper 16 bits of the GOT offset for the address of the 729 1.1.1.8 christos symbol. */ 730 1.1 christos HOWTO (R_BFIN_GOTHI, /* type */ 731 1.1.1.10 christos 0, /* rightshift */ 732 1.1 christos 2, /* size */ 733 1.1.1.10 christos 16, /* bitsize */ 734 1.1 christos false, /* pc_relative */ 735 1.1 christos 0, /* bitpos */ 736 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 737 1.1 christos bfd_elf_generic_reloc, /* special_function */ 738 1.1.1.10 christos "R_BFIN_GOTHI", /* name */ 739 1.1.1.8 christos false, /* partial_inplace */ 740 1.1 christos 0xffff, /* src_mask */ 741 1.1.1.10 christos 0xffff, /* dst_mask */ 742 1.1 christos false), /* pcrel_offset */ 743 1.1 christos 744 1.1 christos /* The lower 16 bits of the GOT offset for the address of the 745 1.1.1.8 christos symbol. */ 746 1.1 christos HOWTO (R_BFIN_GOTLO, /* type */ 747 1.1.1.10 christos 0, /* rightshift */ 748 1.1 christos 2, /* size */ 749 1.1.1.10 christos 16, /* bitsize */ 750 1.1 christos false, /* pc_relative */ 751 1.1 christos 0, /* bitpos */ 752 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 753 1.1 christos bfd_elf_generic_reloc, /* special_function */ 754 1.1.1.10 christos "R_BFIN_GOTLO", /* name */ 755 1.1 christos false, /* partial_inplace */ 756 1.1 christos 0xffff, /* src_mask */ 757 1.1.1.10 christos 0xffff, /* dst_mask */ 758 1.1 christos false), /* pcrel_offset */ 759 1.1 christos 760 1.1 christos /* The 32-bit address of the canonical descriptor of a function. */ 761 1.1 christos HOWTO (R_BFIN_FUNCDESC, /* type */ 762 1.1.1.10 christos 0, /* rightshift */ 763 1.1 christos 4, /* size */ 764 1.1.1.10 christos 32, /* bitsize */ 765 1.1 christos false, /* pc_relative */ 766 1.1 christos 0, /* bitpos */ 767 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 768 1.1 christos bfd_elf_generic_reloc, /* special_function */ 769 1.1.1.10 christos "R_BFIN_FUNCDESC", /* name */ 770 1.1 christos false, /* partial_inplace */ 771 1.1 christos 0xffffffff, /* src_mask */ 772 1.1.1.10 christos 0xffffffff, /* dst_mask */ 773 1.1 christos false), /* pcrel_offset */ 774 1.1 christos 775 1.1 christos /* A 12-bit signed operand with the GOT offset for the address of 776 1.1 christos canonical descriptor of a function. */ 777 1.1 christos HOWTO (R_BFIN_FUNCDESC_GOT17M4, /* type */ 778 1.1.1.10 christos 2, /* rightshift */ 779 1.1 christos 2, /* size */ 780 1.1.1.10 christos 16, /* bitsize */ 781 1.1 christos false, /* pc_relative */ 782 1.1 christos 0, /* bitpos */ 783 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 784 1.1 christos bfd_elf_generic_reloc, /* special_function */ 785 1.1.1.10 christos "R_BFIN_FUNCDESC_GOT17M4", /* name */ 786 1.1.1.8 christos false, /* partial_inplace */ 787 1.1.1.8 christos 0xffff, /* src_mask */ 788 1.1.1.10 christos 0xffff, /* dst_mask */ 789 1.1 christos false), /* pcrel_offset */ 790 1.1 christos 791 1.1 christos /* The upper 16 bits of the GOT offset for the address of the 792 1.1 christos canonical descriptor of a function. */ 793 1.1 christos HOWTO (R_BFIN_FUNCDESC_GOTHI, /* type */ 794 1.1.1.10 christos 0, /* rightshift */ 795 1.1 christos 2, /* size */ 796 1.1.1.10 christos 16, /* bitsize */ 797 1.1 christos false, /* pc_relative */ 798 1.1 christos 0, /* bitpos */ 799 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 800 1.1 christos bfd_elf_generic_reloc, /* special_function */ 801 1.1.1.10 christos "R_BFIN_FUNCDESC_GOTHI", /* name */ 802 1.1 christos false, /* partial_inplace */ 803 1.1 christos 0xffff, /* src_mask */ 804 1.1.1.10 christos 0xffff, /* dst_mask */ 805 1.1 christos false), /* pcrel_offset */ 806 1.1 christos 807 1.1 christos /* The lower 16 bits of the GOT offset for the address of the 808 1.1 christos canonical descriptor of a function. */ 809 1.1 christos HOWTO (R_BFIN_FUNCDESC_GOTLO, /* type */ 810 1.1.1.10 christos 0, /* rightshift */ 811 1.1 christos 2, /* size */ 812 1.1.1.10 christos 16, /* bitsize */ 813 1.1 christos false, /* pc_relative */ 814 1.1 christos 0, /* bitpos */ 815 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 816 1.1 christos bfd_elf_generic_reloc, /* special_function */ 817 1.1.1.10 christos "R_BFIN_FUNCDESC_GOTLO", /* name */ 818 1.1 christos false, /* partial_inplace */ 819 1.1 christos 0xffff, /* src_mask */ 820 1.1.1.10 christos 0xffff, /* dst_mask */ 821 1.1 christos false), /* pcrel_offset */ 822 1.1 christos 823 1.1 christos /* The 32-bit address of the canonical descriptor of a function. */ 824 1.1 christos HOWTO (R_BFIN_FUNCDESC_VALUE, /* type */ 825 1.1.1.10 christos 0, /* rightshift */ 826 1.1 christos 4, /* size */ 827 1.1.1.10 christos 64, /* bitsize */ 828 1.1 christos false, /* pc_relative */ 829 1.1 christos 0, /* bitpos */ 830 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */ 831 1.1 christos bfd_elf_generic_reloc, /* special_function */ 832 1.1.1.10 christos "R_BFIN_FUNCDESC_VALUE", /* name */ 833 1.1 christos false, /* partial_inplace */ 834 1.1 christos 0xffffffff, /* src_mask */ 835 1.1.1.10 christos 0xffffffff, /* dst_mask */ 836 1.1 christos false), /* pcrel_offset */ 837 1.1 christos 838 1.1 christos /* A 12-bit signed operand with the GOT offset for the address of 839 1.1 christos canonical descriptor of a function. */ 840 1.1 christos HOWTO (R_BFIN_FUNCDESC_GOTOFF17M4, /* type */ 841 1.1.1.10 christos 2, /* rightshift */ 842 1.1 christos 2, /* size */ 843 1.1.1.10 christos 16, /* bitsize */ 844 1.1 christos false, /* pc_relative */ 845 1.1 christos 0, /* bitpos */ 846 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 847 1.1 christos bfd_elf_generic_reloc, /* special_function */ 848 1.1.1.10 christos "R_BFIN_FUNCDESC_GOTOFF17M4", /* name */ 849 1.1.1.8 christos false, /* partial_inplace */ 850 1.1.1.8 christos 0xffff, /* src_mask */ 851 1.1.1.10 christos 0xffff, /* dst_mask */ 852 1.1 christos false), /* pcrel_offset */ 853 1.1 christos 854 1.1 christos /* The upper 16 bits of the GOT offset for the address of the 855 1.1 christos canonical descriptor of a function. */ 856 1.1 christos HOWTO (R_BFIN_FUNCDESC_GOTOFFHI, /* type */ 857 1.1.1.10 christos 0, /* rightshift */ 858 1.1 christos 2, /* size */ 859 1.1.1.10 christos 16, /* bitsize */ 860 1.1 christos false, /* pc_relative */ 861 1.1 christos 0, /* bitpos */ 862 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 863 1.1 christos bfd_elf_generic_reloc, /* special_function */ 864 1.1.1.10 christos "R_BFIN_FUNCDESC_GOTOFFHI", /* name */ 865 1.1 christos false, /* partial_inplace */ 866 1.1 christos 0xffff, /* src_mask */ 867 1.1.1.10 christos 0xffff, /* dst_mask */ 868 1.1 christos false), /* pcrel_offset */ 869 1.1 christos 870 1.1 christos /* The lower 16 bits of the GOT offset for the address of the 871 1.1 christos canonical descriptor of a function. */ 872 1.1 christos HOWTO (R_BFIN_FUNCDESC_GOTOFFLO, /* type */ 873 1.1.1.10 christos 0, /* rightshift */ 874 1.1 christos 2, /* size */ 875 1.1.1.10 christos 16, /* bitsize */ 876 1.1 christos false, /* pc_relative */ 877 1.1 christos 0, /* bitpos */ 878 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 879 1.1 christos bfd_elf_generic_reloc, /* special_function */ 880 1.1.1.10 christos "R_BFIN_FUNCDESC_GOTOFFLO", /* name */ 881 1.1 christos false, /* partial_inplace */ 882 1.1 christos 0xffff, /* src_mask */ 883 1.1.1.10 christos 0xffff, /* dst_mask */ 884 1.1 christos false), /* pcrel_offset */ 885 1.1 christos 886 1.1 christos /* A 12-bit signed operand with the GOT offset for the address of 887 1.1.1.8 christos the symbol. */ 888 1.1 christos HOWTO (R_BFIN_GOTOFF17M4, /* type */ 889 1.1.1.10 christos 2, /* rightshift */ 890 1.1 christos 2, /* size */ 891 1.1.1.10 christos 16, /* bitsize */ 892 1.1 christos false, /* pc_relative */ 893 1.1 christos 0, /* bitpos */ 894 1.1 christos complain_overflow_signed, /* complain_on_overflow */ 895 1.1 christos bfd_elf_generic_reloc, /* special_function */ 896 1.1.1.10 christos "R_BFIN_GOTOFF17M4", /* name */ 897 1.1.1.8 christos false, /* partial_inplace */ 898 1.1.1.8 christos 0xffff, /* src_mask */ 899 1.1.1.10 christos 0xffff, /* dst_mask */ 900 1.1 christos false), /* pcrel_offset */ 901 1.1 christos 902 1.1 christos /* The upper 16 bits of the GOT offset for the address of the 903 1.1.1.8 christos symbol. */ 904 1.1 christos HOWTO (R_BFIN_GOTOFFHI, /* type */ 905 1.1.1.10 christos 0, /* rightshift */ 906 1.1 christos 2, /* size */ 907 1.1.1.10 christos 16, /* bitsize */ 908 1.1 christos false, /* pc_relative */ 909 1.1 christos 0, /* bitpos */ 910 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 911 1.1 christos bfd_elf_generic_reloc, /* special_function */ 912 1.1.1.10 christos "R_BFIN_GOTOFFHI", /* name */ 913 1.1 christos false, /* partial_inplace */ 914 1.1 christos 0xffff, /* src_mask */ 915 1.1.1.10 christos 0xffff, /* dst_mask */ 916 1.1 christos false), /* pcrel_offset */ 917 1.1 christos 918 1.1 christos /* The lower 16 bits of the GOT offset for the address of the 919 1.1 christos symbol. */ 920 1.1 christos HOWTO (R_BFIN_GOTOFFLO, /* type */ 921 1.1.1.10 christos 0, /* rightshift */ 922 1.1 christos 2, /* size */ 923 1.1.1.10 christos 16, /* bitsize */ 924 1.1 christos false, /* pc_relative */ 925 1.1 christos 0, /* bitpos */ 926 1.1 christos complain_overflow_dont, /* complain_on_overflow */ 927 1.1 christos bfd_elf_generic_reloc, /* special_function */ 928 1.1.1.10 christos "R_BFIN_GOTOFFLO", /* name */ 929 1.1 christos false, /* partial_inplace */ 930 1.1 christos 0xffff, /* src_mask */ 931 1.1.1.10 christos 0xffff, /* dst_mask */ 932 1.1 christos false), /* pcrel_offset */ 933 1.1 christos }; 934 1.1 christos 935 1.1 christos static reloc_howto_type bfin_gnuext_howto_table [] = 936 1.1 christos { 937 1.1 christos HOWTO (R_BFIN_PLTPC, /* type. */ 938 1.1.1.10 christos 0, /* rightshift. */ 939 1.1 christos 2, /* size. */ 940 1.1.1.10 christos 16, /* bitsize. */ 941 1.1 christos false, /* pc_relative. */ 942 1.1 christos 0, /* bitpos. */ 943 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 944 1.1 christos bfin_pltpc_reloc, /* special_function. */ 945 1.1.1.10 christos "R_BFIN_PLTPC", /* name. */ 946 1.1 christos false, /* partial_inplace. */ 947 1.1 christos 0xffff, /* src_mask. */ 948 1.1.1.10 christos 0xffff, /* dst_mask. */ 949 1.1 christos false), /* pcrel_offset. */ 950 1.1 christos 951 1.1 christos HOWTO (R_BFIN_GOT, /* type. */ 952 1.1.1.10 christos 0, /* rightshift. */ 953 1.1 christos 2, /* size. */ 954 1.1.1.10 christos 16, /* bitsize. */ 955 1.1 christos false, /* pc_relative. */ 956 1.1 christos 0, /* bitpos. */ 957 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 958 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 959 1.1.1.10 christos "R_BFIN_GOT", /* name. */ 960 1.1 christos false, /* partial_inplace. */ 961 1.1 christos 0x7fff, /* src_mask. */ 962 1.1.1.10 christos 0x7fff, /* dst_mask. */ 963 1.1 christos false), /* pcrel_offset. */ 964 1.1 christos 965 1.1.1.8 christos /* GNU extension to record C++ vtable hierarchy. */ 966 1.1.1.8 christos HOWTO (R_BFIN_GNU_VTINHERIT, /* type. */ 967 1.1.1.10 christos 0, /* rightshift. */ 968 1.1.1.8 christos 4, /* size. */ 969 1.1.1.10 christos 0, /* bitsize. */ 970 1.1.1.8 christos false, /* pc_relative. */ 971 1.1.1.8 christos 0, /* bitpos. */ 972 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow. */ 973 1.1.1.8 christos NULL, /* special_function. */ 974 1.1.1.10 christos "R_BFIN_GNU_VTINHERIT", /* name. */ 975 1.1.1.8 christos false, /* partial_inplace. */ 976 1.1.1.8 christos 0, /* src_mask. */ 977 1.1.1.10 christos 0, /* dst_mask. */ 978 1.1 christos false), /* pcrel_offset. */ 979 1.1 christos 980 1.1 christos /* GNU extension to record C++ vtable member usage. */ 981 1.1.1.8 christos HOWTO (R_BFIN_GNU_VTENTRY, /* type. */ 982 1.1.1.10 christos 0, /* rightshift. */ 983 1.1.1.8 christos 4, /* size. */ 984 1.1.1.10 christos 0, /* bitsize. */ 985 1.1.1.8 christos false, /* pc_relative. */ 986 1.1.1.8 christos 0, /* bitpos. */ 987 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow. */ 988 1.1.1.8 christos _bfd_elf_rel_vtable_reloc_fn, /* special_function. */ 989 1.1.1.10 christos "R_BFIN_GNU_VTENTRY", /* name. */ 990 1.1.1.8 christos false, /* partial_inplace. */ 991 1.1.1.8 christos 0, /* src_mask. */ 992 1.1.1.10 christos 0, /* dst_mask. */ 993 1.1 christos false) /* pcrel_offset. */ 994 1.1 christos }; 995 1.1 christos 996 1.1 christos struct bfin_reloc_map 997 1.1.1.8 christos { 998 1.1 christos bfd_reloc_code_real_type bfd_reloc_val; 999 1.1 christos unsigned int bfin_reloc_val; 1000 1.1 christos }; 1001 1.1 christos 1002 1.1 christos static const struct bfin_reloc_map bfin_reloc_map [] = 1003 1.1 christos { 1004 1.1 christos { BFD_RELOC_NONE, R_BFIN_UNUSED0 }, 1005 1.1 christos { BFD_RELOC_BFIN_5_PCREL, R_BFIN_PCREL5M2 }, 1006 1.1 christos { BFD_RELOC_NONE, R_BFIN_UNUSED1 }, 1007 1.1 christos { BFD_RELOC_BFIN_10_PCREL, R_BFIN_PCREL10 }, 1008 1.1 christos { BFD_RELOC_BFIN_12_PCREL_JUMP, R_BFIN_PCREL12_JUMP }, 1009 1.1 christos { BFD_RELOC_BFIN_16_IMM, R_BFIN_RIMM16 }, 1010 1.1 christos { BFD_RELOC_BFIN_16_LOW, R_BFIN_LUIMM16 }, 1011 1.1 christos { BFD_RELOC_BFIN_16_HIGH, R_BFIN_HUIMM16 }, 1012 1.1 christos { BFD_RELOC_BFIN_12_PCREL_JUMP_S, R_BFIN_PCREL12_JUMP_S }, 1013 1.1 christos { BFD_RELOC_24_PCREL, R_BFIN_PCREL24 }, 1014 1.1 christos { BFD_RELOC_24_PCREL, R_BFIN_PCREL24 }, 1015 1.1 christos { BFD_RELOC_BFIN_24_PCREL_JUMP_L, R_BFIN_PCREL24_JUMP_L }, 1016 1.1 christos { BFD_RELOC_NONE, R_BFIN_UNUSEDB }, 1017 1.1 christos { BFD_RELOC_NONE, R_BFIN_UNUSEDC }, 1018 1.1 christos { BFD_RELOC_BFIN_24_PCREL_CALL_X, R_BFIN_PCREL24_CALL_X }, 1019 1.1 christos { BFD_RELOC_8, R_BFIN_BYTE_DATA }, 1020 1.1 christos { BFD_RELOC_16, R_BFIN_BYTE2_DATA }, 1021 1.1 christos { BFD_RELOC_32, R_BFIN_BYTE4_DATA }, 1022 1.1 christos { BFD_RELOC_BFIN_11_PCREL, R_BFIN_PCREL11 }, 1023 1.1 christos { BFD_RELOC_BFIN_GOT, R_BFIN_GOT }, 1024 1.1 christos { BFD_RELOC_BFIN_PLTPC, R_BFIN_PLTPC }, 1025 1.1 christos 1026 1.1 christos { BFD_RELOC_BFIN_GOT17M4, R_BFIN_GOT17M4 }, 1027 1.1 christos { BFD_RELOC_BFIN_GOTHI, R_BFIN_GOTHI }, 1028 1.1 christos { BFD_RELOC_BFIN_GOTLO, R_BFIN_GOTLO }, 1029 1.1 christos { BFD_RELOC_BFIN_FUNCDESC, R_BFIN_FUNCDESC }, 1030 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_GOT17M4, R_BFIN_FUNCDESC_GOT17M4 }, 1031 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_GOTHI, R_BFIN_FUNCDESC_GOTHI }, 1032 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_GOTLO, R_BFIN_FUNCDESC_GOTLO }, 1033 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_VALUE, R_BFIN_FUNCDESC_VALUE }, 1034 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_GOTOFF17M4, R_BFIN_FUNCDESC_GOTOFF17M4 }, 1035 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_GOTOFFHI, R_BFIN_FUNCDESC_GOTOFFHI }, 1036 1.1 christos { BFD_RELOC_BFIN_FUNCDESC_GOTOFFLO, R_BFIN_FUNCDESC_GOTOFFLO }, 1037 1.1 christos { BFD_RELOC_BFIN_GOTOFF17M4, R_BFIN_GOTOFF17M4 }, 1038 1.1 christos { BFD_RELOC_BFIN_GOTOFFHI, R_BFIN_GOTOFFHI }, 1039 1.1 christos { BFD_RELOC_BFIN_GOTOFFLO, R_BFIN_GOTOFFLO }, 1040 1.1 christos 1041 1.1 christos { BFD_RELOC_VTABLE_INHERIT, R_BFIN_GNU_VTINHERIT }, 1042 1.1 christos { BFD_RELOC_VTABLE_ENTRY, R_BFIN_GNU_VTENTRY }, 1043 1.1 christos }; 1044 1.1 christos 1045 1.1.1.10 christos 1046 1.1.1.8 christos static bool 1047 1.1.1.8 christos bfin_info_to_howto (bfd *abfd, 1048 1.1.1.8 christos arelent *cache_ptr, 1049 1.1 christos Elf_Internal_Rela *dst) 1050 1.1 christos { 1051 1.1 christos unsigned int r_type; 1052 1.1 christos 1053 1.1 christos r_type = ELF32_R_TYPE (dst->r_info); 1054 1.1 christos 1055 1.1 christos if (r_type <= BFIN_RELOC_MAX) 1056 1.1 christos cache_ptr->howto = &bfin_howto_table [r_type]; 1057 1.1 christos 1058 1.1 christos else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX) 1059 1.1 christos cache_ptr->howto = &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN]; 1060 1.1 christos 1061 1.1.1.8 christos else 1062 1.1.1.8 christos { 1063 1.1.1.8 christos /* xgettext:c-format */ 1064 1.1.1.8 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 1065 1.1.1.8 christos abfd, r_type); 1066 1.1.1.10 christos bfd_set_error (bfd_error_bad_value); 1067 1.1.1.8 christos return false; 1068 1.1.1.8 christos } 1069 1.1.1.10 christos 1070 1.1 christos return true; 1071 1.1 christos } 1072 1.1 christos 1073 1.1 christos /* Given a BFD reloc type, return the howto. */ 1074 1.1 christos static reloc_howto_type * 1075 1.1 christos bfin_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, 1076 1.1 christos bfd_reloc_code_real_type code) 1077 1.1 christos { 1078 1.1.1.5 christos unsigned int i; 1079 1.1 christos unsigned int r_type = (unsigned int) -1; 1080 1.1.1.5 christos 1081 1.1 christos for (i = sizeof (bfin_reloc_map) / sizeof (bfin_reloc_map[0]); i--;) 1082 1.1 christos if (bfin_reloc_map[i].bfd_reloc_val == code) 1083 1.1 christos r_type = bfin_reloc_map[i].bfin_reloc_val; 1084 1.1.1.5 christos 1085 1.1 christos if (r_type <= BFIN_RELOC_MAX) 1086 1.1 christos return &bfin_howto_table [r_type]; 1087 1.1 christos 1088 1.1 christos else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX) 1089 1.1 christos return &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN]; 1090 1.1 christos 1091 1.1 christos return (reloc_howto_type *) NULL; 1092 1.1 christos } 1093 1.1 christos 1094 1.1 christos static reloc_howto_type * 1095 1.1 christos bfin_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1096 1.1 christos const char *r_name) 1097 1.1 christos { 1098 1.1 christos unsigned int i; 1099 1.1 christos 1100 1.1 christos for (i = 0; 1101 1.1 christos i < (sizeof (bfin_howto_table) 1102 1.1 christos / sizeof (bfin_howto_table[0])); 1103 1.1 christos i++) 1104 1.1 christos if (bfin_howto_table[i].name != NULL 1105 1.1 christos && strcasecmp (bfin_howto_table[i].name, r_name) == 0) 1106 1.1 christos return &bfin_howto_table[i]; 1107 1.1 christos 1108 1.1 christos for (i = 0; 1109 1.1 christos i < (sizeof (bfin_gnuext_howto_table) 1110 1.1 christos / sizeof (bfin_gnuext_howto_table[0])); 1111 1.1 christos i++) 1112 1.1 christos if (bfin_gnuext_howto_table[i].name != NULL 1113 1.1 christos && strcasecmp (bfin_gnuext_howto_table[i].name, r_name) == 0) 1114 1.1 christos return &bfin_gnuext_howto_table[i]; 1115 1.1 christos 1116 1.1 christos return NULL; 1117 1.1 christos } 1118 1.1 christos 1119 1.1 christos /* Given a bfin relocation type, return the howto. */ 1120 1.1 christos static reloc_howto_type * 1121 1.1.1.2 christos bfin_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, 1122 1.1 christos unsigned int r_type) 1123 1.1 christos { 1124 1.1 christos if (r_type <= BFIN_RELOC_MAX) 1125 1.1 christos return &bfin_howto_table [r_type]; 1126 1.1 christos 1127 1.1 christos else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX) 1128 1.1 christos return &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN]; 1129 1.1 christos 1130 1.1 christos return (reloc_howto_type *) NULL; 1131 1.1 christos } 1132 1.1 christos 1133 1.1.1.10 christos /* Set by ld emulation if --code-in-l1. */ 1134 1.1 christos bool elf32_bfin_code_in_l1 = 0; 1135 1.1 christos 1136 1.1.1.10 christos /* Set by ld emulation if --data-in-l1. */ 1137 1.1 christos bool elf32_bfin_data_in_l1 = 0; 1138 1.1.1.10 christos 1139 1.1.1.9 christos static bool 1140 1.1 christos elf32_bfin_final_write_processing (bfd *abfd) 1141 1.1 christos { 1142 1.1 christos if (elf32_bfin_code_in_l1) 1143 1.1 christos elf_elfheader (abfd)->e_flags |= EF_BFIN_CODE_IN_L1; 1144 1.1 christos if (elf32_bfin_data_in_l1) 1145 1.1.1.9 christos elf_elfheader (abfd)->e_flags |= EF_BFIN_DATA_IN_L1; 1146 1.1 christos return _bfd_elf_final_write_processing (abfd); 1147 1.1 christos } 1148 1.1 christos 1149 1.1 christos /* Return TRUE if the name is a local label. 1150 1.1.1.10 christos bfin local labels begin with L$. */ 1151 1.1.1.2 christos static bool 1152 1.1 christos bfin_is_local_label_name (bfd *abfd, const char *label) 1153 1.1 christos { 1154 1.1.1.10 christos if (label[0] == 'L' && label[1] == '$' ) 1155 1.1 christos return true; 1156 1.1 christos 1157 1.1 christos return _bfd_elf_is_local_label_name (abfd, label); 1158 1.1 christos } 1159 1.1 christos 1160 1.1 christos /* Look through the relocs for a section during the first phase, and 1162 1.1 christos allocate space in the global offset table or procedure linkage 1163 1.1.1.10 christos table. */ 1164 1.1 christos 1165 1.1 christos static bool 1166 1.1 christos bfin_check_relocs (bfd * abfd, 1167 1.1.1.8 christos struct bfd_link_info *info, 1168 1.1 christos asection *sec, 1169 1.1 christos const Elf_Internal_Rela *relocs) 1170 1.1 christos { 1171 1.1 christos bfd *dynobj; 1172 1.1 christos Elf_Internal_Shdr *symtab_hdr; 1173 1.1 christos struct elf_link_hash_entry **sym_hashes; 1174 1.1 christos bfd_signed_vma *local_got_refcounts; 1175 1.1 christos const Elf_Internal_Rela *rel; 1176 1.1 christos const Elf_Internal_Rela *rel_end; 1177 1.1.1.2 christos asection *sgot; 1178 1.1.1.6 christos asection *srelgot; 1179 1.1.1.10 christos 1180 1.1 christos if (bfd_link_relocatable (info)) 1181 1.1 christos return true; 1182 1.1 christos 1183 1.1 christos dynobj = elf_hash_table (info)->dynobj; 1184 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1185 1.1 christos sym_hashes = elf_sym_hashes (abfd); 1186 1.1 christos local_got_refcounts = elf_local_got_refcounts (abfd); 1187 1.1 christos 1188 1.1 christos sgot = NULL; 1189 1.1 christos srelgot = NULL; 1190 1.1 christos 1191 1.1 christos rel_end = relocs + sec->reloc_count; 1192 1.1 christos for (rel = relocs; rel < rel_end; rel++) 1193 1.1 christos { 1194 1.1 christos unsigned long r_symndx; 1195 1.1 christos struct elf_link_hash_entry *h; 1196 1.1 christos 1197 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 1198 1.1 christos if (r_symndx < symtab_hdr->sh_info) 1199 1.1.1.3 christos h = NULL; 1200 1.1.1.3 christos else 1201 1.1.1.10 christos { 1202 1.1.1.10 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1203 1.1.1.10 christos while (h->root.type == bfd_link_hash_indirect 1204 1.1.1.3 christos || h->root.type == bfd_link_hash_warning) 1205 1.1 christos h = (struct elf_link_hash_entry *)h->root.u.i.link; 1206 1.1 christos } 1207 1.1 christos 1208 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 1209 1.1.1.8 christos { 1210 1.1.1.8 christos /* This relocation describes the C++ object vtable hierarchy. 1211 1.1.1.8 christos Reconstruct it for later use during GC. */ 1212 1.1.1.10 christos case R_BFIN_GNU_VTINHERIT: 1213 1.1.1.8 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 1214 1.1.1.8 christos return false; 1215 1.1.1.8 christos break; 1216 1.1.1.8 christos 1217 1.1.1.8 christos /* This relocation describes which C++ vtable entries 1218 1.1.1.9 christos are actually used. Record for later use during GC. */ 1219 1.1.1.10 christos case R_BFIN_GNU_VTENTRY: 1220 1.1.1.8 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 1221 1.1 christos return false; 1222 1.1 christos break; 1223 1.1 christos 1224 1.1 christos case R_BFIN_GOT: 1225 1.1 christos if (h != NULL 1226 1.1 christos && strcmp (h->root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0) 1227 1.1 christos break; 1228 1.1 christos /* Fall through. */ 1229 1.1 christos 1230 1.1 christos if (dynobj == NULL) 1231 1.1 christos { 1232 1.1 christos /* Create the .got section. */ 1233 1.1.1.10 christos elf_hash_table (info)->dynobj = dynobj = abfd; 1234 1.1 christos if (!_bfd_elf_create_got_section (dynobj, info)) 1235 1.1 christos return false; 1236 1.1.1.7 christos } 1237 1.1.1.7 christos 1238 1.1.1.7 christos sgot = elf_hash_table (info)->sgot; 1239 1.1 christos srelgot = elf_hash_table (info)->srelgot; 1240 1.1 christos BFD_ASSERT (sgot != NULL); 1241 1.1 christos 1242 1.1 christos if (h != NULL) 1243 1.1 christos { 1244 1.1 christos if (h->got.refcount == 0) 1245 1.1 christos { 1246 1.1 christos /* Make sure this symbol is output as a dynamic symbol. */ 1247 1.1 christos if (h->dynindx == -1 && !h->forced_local) 1248 1.1.1.10 christos { 1249 1.1 christos if (!bfd_elf_link_record_dynamic_symbol (info, h)) 1250 1.1 christos return false; 1251 1.1 christos } 1252 1.1 christos 1253 1.1 christos /* Allocate space in the .got section. */ 1254 1.1 christos sgot->size += 4; 1255 1.1 christos /* Allocate relocation space. */ 1256 1.1 christos srelgot->size += sizeof (Elf32_External_Rela); 1257 1.1 christos } 1258 1.1 christos h->got.refcount++; 1259 1.1 christos } 1260 1.1 christos else 1261 1.1 christos { 1262 1.1 christos /* This is a global offset table entry for a local symbol. */ 1263 1.1 christos if (local_got_refcounts == NULL) 1264 1.1 christos { 1265 1.1 christos bfd_size_type size; 1266 1.1 christos 1267 1.1 christos size = symtab_hdr->sh_info; 1268 1.1 christos size *= sizeof (bfd_signed_vma); 1269 1.1 christos local_got_refcounts = ((bfd_signed_vma *) 1270 1.1.1.10 christos bfd_zalloc (abfd, size)); 1271 1.1 christos if (local_got_refcounts == NULL) 1272 1.1 christos return false; 1273 1.1 christos elf_local_got_refcounts (abfd) = local_got_refcounts; 1274 1.1 christos } 1275 1.1 christos if (local_got_refcounts[r_symndx] == 0) 1276 1.1.1.6 christos { 1277 1.1 christos sgot->size += 4; 1278 1.1 christos if (bfd_link_pic (info)) 1279 1.1.1.8 christos { 1280 1.1.1.8 christos /* If we are generating a shared object, we need to 1281 1.1 christos output a R_68K_RELATIVE reloc so that the dynamic 1282 1.1 christos linker can adjust this GOT entry. */ 1283 1.1 christos srelgot->size += sizeof (Elf32_External_Rela); 1284 1.1 christos } 1285 1.1 christos } 1286 1.1 christos local_got_refcounts[r_symndx]++; 1287 1.1 christos } 1288 1.1 christos break; 1289 1.1 christos 1290 1.1 christos default: 1291 1.1 christos break; 1292 1.1 christos } 1293 1.1.1.10 christos } 1294 1.1 christos 1295 1.1 christos return true; 1296 1.1 christos } 1297 1.1.1.3 christos 1298 1.1.1.3 christos static enum elf_reloc_type_class 1299 1.1.1.3 christos elf32_bfin_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 1300 1.1 christos const asection *rel_sec ATTRIBUTE_UNUSED, 1301 1.1 christos const Elf_Internal_Rela * rela) 1302 1.1 christos { 1303 1.1 christos switch ((int) ELF32_R_TYPE (rela->r_info)) 1304 1.1 christos { 1305 1.1 christos default: 1306 1.1 christos return reloc_class_normal; 1307 1.1 christos } 1308 1.1 christos } 1309 1.1 christos 1310 1.1 christos static bfd_reloc_status_type 1312 1.1 christos bfin_final_link_relocate (Elf_Internal_Rela *rel, reloc_howto_type *howto, 1313 1.1 christos bfd *input_bfd, asection *input_section, 1314 1.1 christos bfd_byte *contents, bfd_vma address, 1315 1.1 christos bfd_vma value, bfd_vma addend) 1316 1.1 christos { 1317 1.1 christos int r_type = ELF32_R_TYPE (rel->r_info); 1318 1.1 christos 1319 1.1 christos if (r_type == R_BFIN_PCREL24 || r_type == R_BFIN_PCREL24_JUMP_L) 1320 1.1 christos { 1321 1.1.1.10 christos bfd_reloc_status_type r = bfd_reloc_ok; 1322 1.1.1.10 christos bfd_vma x; 1323 1.1.1.10 christos 1324 1.1 christos if (!bfd_reloc_offset_in_range (howto, input_bfd, input_section, 1325 1.1 christos address - 2)) 1326 1.1 christos return bfd_reloc_outofrange; 1327 1.1 christos 1328 1.1 christos value += addend; 1329 1.1 christos 1330 1.1 christos /* Perform usual pc-relative correction. */ 1331 1.1 christos value -= input_section->output_section->vma + input_section->output_offset; 1332 1.1 christos value -= address; 1333 1.1 christos 1334 1.1 christos /* We are getting reloc_entry->address 2 byte off from 1335 1.1 christos the start of instruction. Assuming absolute postion 1336 1.1 christos of the reloc data. But, following code had been written assuming 1337 1.1 christos reloc address is starting at begining of instruction. 1338 1.1 christos To compensate that I have increased the value of 1339 1.1 christos relocation by 1 (effectively 2) and used the addr -2 instead of addr. */ 1340 1.1 christos 1341 1.1 christos value += 2; 1342 1.1 christos address -= 2; 1343 1.1 christos 1344 1.1 christos if ((value & 0xFF000000) != 0 1345 1.1 christos && (value & 0xFF000000) != 0xFF000000) 1346 1.1 christos r = bfd_reloc_overflow; 1347 1.1 christos 1348 1.1 christos value >>= 1; 1349 1.1 christos 1350 1.1 christos x = bfd_get_16 (input_bfd, contents + address); 1351 1.1 christos x = (x & 0xff00) | ((value >> 16) & 0xff); 1352 1.1 christos bfd_put_16 (input_bfd, x, contents + address); 1353 1.1 christos 1354 1.1 christos x = bfd_get_16 (input_bfd, contents + address + 2); 1355 1.1 christos x = value & 0xFFFF; 1356 1.1 christos bfd_put_16 (input_bfd, x, contents + address + 2); 1357 1.1 christos return r; 1358 1.1 christos } 1359 1.1 christos 1360 1.1 christos return _bfd_final_link_relocate (howto, input_bfd, input_section, contents, 1361 1.1 christos rel->r_offset, value, addend); 1362 1.1.1.10 christos 1363 1.1 christos } 1364 1.1 christos 1365 1.1 christos static int 1366 1.1 christos bfin_relocate_section (bfd * output_bfd, 1367 1.1 christos struct bfd_link_info *info, 1368 1.1 christos bfd * input_bfd, 1369 1.1 christos asection * input_section, 1370 1.1 christos bfd_byte * contents, 1371 1.1 christos Elf_Internal_Rela * relocs, 1372 1.1 christos Elf_Internal_Sym * local_syms, 1373 1.1 christos asection ** local_sections) 1374 1.1 christos { 1375 1.1 christos bfd *dynobj; 1376 1.1 christos Elf_Internal_Shdr *symtab_hdr; 1377 1.1 christos struct elf_link_hash_entry **sym_hashes; 1378 1.1 christos bfd_vma *local_got_offsets; 1379 1.1 christos asection *sgot; 1380 1.1 christos Elf_Internal_Rela *rel; 1381 1.1 christos Elf_Internal_Rela *relend; 1382 1.1 christos int i = 0; 1383 1.1 christos 1384 1.1 christos dynobj = elf_hash_table (info)->dynobj; 1385 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 1386 1.1 christos sym_hashes = elf_sym_hashes (input_bfd); 1387 1.1 christos local_got_offsets = elf_local_got_offsets (input_bfd); 1388 1.1 christos 1389 1.1 christos sgot = NULL; 1390 1.1 christos 1391 1.1 christos rel = relocs; 1392 1.1 christos relend = relocs + input_section->reloc_count; 1393 1.1 christos for (; rel < relend; rel++, i++) 1394 1.1 christos { 1395 1.1 christos int r_type; 1396 1.1 christos reloc_howto_type *howto; 1397 1.1 christos unsigned long r_symndx; 1398 1.1 christos struct elf_link_hash_entry *h; 1399 1.1.1.10 christos Elf_Internal_Sym *sym; 1400 1.1 christos asection *sec; 1401 1.1 christos bfd_vma relocation = 0; 1402 1.1 christos bool unresolved_reloc; 1403 1.1 christos bfd_reloc_status_type r; 1404 1.1 christos bfd_vma address; 1405 1.1 christos 1406 1.1 christos r_type = ELF32_R_TYPE (rel->r_info); 1407 1.1.1.10 christos if (r_type < 0 || r_type >= 243) 1408 1.1 christos { 1409 1.1 christos bfd_set_error (bfd_error_bad_value); 1410 1.1 christos return false; 1411 1.1.1.8 christos } 1412 1.1 christos 1413 1.1 christos if (r_type == R_BFIN_GNU_VTENTRY 1414 1.1 christos || r_type == R_BFIN_GNU_VTINHERIT) 1415 1.1 christos continue; 1416 1.1 christos 1417 1.1 christos howto = bfin_reloc_type_lookup (input_bfd, r_type); 1418 1.1.1.10 christos if (howto == NULL) 1419 1.1 christos { 1420 1.1 christos bfd_set_error (bfd_error_bad_value); 1421 1.1 christos return false; 1422 1.1 christos } 1423 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 1424 1.1 christos 1425 1.1.1.10 christos h = NULL; 1426 1.1 christos sym = NULL; 1427 1.1 christos sec = NULL; 1428 1.1 christos unresolved_reloc = false; 1429 1.1 christos 1430 1.1 christos if (r_symndx < symtab_hdr->sh_info) 1431 1.1 christos { 1432 1.1 christos sym = local_syms + r_symndx; 1433 1.1 christos sec = local_sections[r_symndx]; 1434 1.1 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 1435 1.1.1.10 christos } 1436 1.1 christos else 1437 1.1 christos { 1438 1.1 christos bool warned, ignored; 1439 1.1 christos 1440 1.1.1.3 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 1441 1.1 christos r_symndx, symtab_hdr, sym_hashes, 1442 1.1 christos h, sec, relocation, 1443 1.1.1.2 christos unresolved_reloc, warned, ignored); 1444 1.1 christos } 1445 1.1.1.2 christos 1446 1.1 christos if (sec != NULL && discarded_section (sec)) 1447 1.1.1.6 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 1448 1.1 christos rel, 1, relend, howto, 0, contents); 1449 1.1 christos 1450 1.1 christos if (bfd_link_relocatable (info)) 1451 1.1 christos continue; 1452 1.1 christos 1453 1.1 christos address = rel->r_offset; 1454 1.1 christos 1455 1.1 christos /* Then, process normally. */ 1456 1.1 christos switch (r_type) 1457 1.1 christos { 1458 1.1 christos case R_BFIN_GNU_VTINHERIT: 1459 1.1 christos case R_BFIN_GNU_VTENTRY: 1460 1.1 christos return bfd_reloc_ok; 1461 1.1 christos 1462 1.1 christos case R_BFIN_GOT: 1463 1.1 christos /* Relocation is to the address of the entry for this symbol 1464 1.1 christos in the global offset table. */ 1465 1.1 christos if (h != NULL 1466 1.1 christos && strcmp (h->root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0) 1467 1.1 christos goto do_default; 1468 1.1 christos /* Fall through. */ 1469 1.1 christos /* Relocation is the offset of the entry for this symbol in 1470 1.1 christos the global offset table. */ 1471 1.1 christos 1472 1.1.1.7 christos { 1473 1.1 christos bfd_vma off; 1474 1.1.1.7 christos 1475 1.1.1.7 christos if (dynobj == NULL) 1476 1.1.1.7 christos { 1477 1.1.1.10 christos /* Create the .got section. */ 1478 1.1 christos elf_hash_table (info)->dynobj = dynobj = output_bfd; 1479 1.1 christos if (!_bfd_elf_create_got_section (dynobj, info)) 1480 1.1.1.7 christos return false; 1481 1.1.1.7 christos } 1482 1.1.1.7 christos 1483 1.1 christos sgot = elf_hash_table (info)->sgot; 1484 1.1 christos BFD_ASSERT (sgot != NULL); 1485 1.1.1.10 christos 1486 1.1 christos if (h != NULL) 1487 1.1 christos { 1488 1.1 christos bool dyn; 1489 1.1 christos 1490 1.1 christos off = h->got.offset; 1491 1.1.1.6 christos BFD_ASSERT (off != (bfd_vma) - 1); 1492 1.1.1.6 christos dyn = elf_hash_table (info)->dynamic_sections_created; 1493 1.1.1.6 christos 1494 1.1.1.6 christos if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 1495 1.1 christos bfd_link_pic (info), 1496 1.1 christos h) 1497 1.1 christos || (bfd_link_pic (info) 1498 1.1 christos && (info->symbolic 1499 1.1 christos || h->dynindx == -1 1500 1.1 christos || h->forced_local) 1501 1.1 christos && h->def_regular)) 1502 1.1 christos { 1503 1.1 christos /* This is actually a static link, or it is a 1504 1.1 christos -Bsymbolic link and the symbol is defined 1505 1.1 christos locally, or the symbol was forced to be local 1506 1.1 christos because of a version file.. We must initialize 1507 1.1 christos this entry in the global offset table. Since 1508 1.1 christos the offset must always be a multiple of 4, we 1509 1.1 christos use the least significant bit to record whether 1510 1.1 christos we have initialized it already. 1511 1.1 christos 1512 1.1 christos When doing a dynamic link, we create a .rela.got 1513 1.1 christos relocation entry to initialize the value. This 1514 1.1 christos is done in the finish_dynamic_symbol routine. */ 1515 1.1 christos if ((off & 1) != 0) 1516 1.1 christos off &= ~1; 1517 1.1 christos else 1518 1.1 christos { 1519 1.1 christos bfd_put_32 (output_bfd, relocation, 1520 1.1 christos sgot->contents + off); 1521 1.1 christos h->got.offset |= 1; 1522 1.1.1.10 christos } 1523 1.1 christos } 1524 1.1 christos else 1525 1.1 christos unresolved_reloc = false; 1526 1.1 christos } 1527 1.1 christos else 1528 1.1 christos { 1529 1.1 christos BFD_ASSERT (local_got_offsets != NULL); 1530 1.1 christos off = local_got_offsets[r_symndx]; 1531 1.1 christos BFD_ASSERT (off != (bfd_vma) - 1); 1532 1.1 christos 1533 1.1 christos /* The offset must always be a multiple of 4. We use 1534 1.1 christos the least significant bit to record whether we have 1535 1.1 christos already generated the necessary reloc. */ 1536 1.1 christos if ((off & 1) != 0) 1537 1.1 christos off &= ~1; 1538 1.1 christos else 1539 1.1.1.6 christos { 1540 1.1 christos bfd_put_32 (output_bfd, relocation, sgot->contents + off); 1541 1.1 christos 1542 1.1 christos if (bfd_link_pic (info)) 1543 1.1 christos { 1544 1.1 christos asection *s; 1545 1.1.1.7 christos Elf_Internal_Rela outrel; 1546 1.1 christos bfd_byte *loc; 1547 1.1 christos 1548 1.1 christos s = elf_hash_table (info)->srelgot; 1549 1.1 christos BFD_ASSERT (s != NULL); 1550 1.1 christos 1551 1.1 christos outrel.r_offset = (sgot->output_section->vma 1552 1.1 christos + sgot->output_offset + off); 1553 1.1 christos outrel.r_info = 1554 1.1 christos ELF32_R_INFO (0, R_BFIN_PCREL24); 1555 1.1 christos outrel.r_addend = relocation; 1556 1.1 christos loc = s->contents; 1557 1.1 christos loc += 1558 1.1 christos s->reloc_count++ * sizeof (Elf32_External_Rela); 1559 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 1560 1.1 christos } 1561 1.1 christos 1562 1.1 christos local_got_offsets[r_symndx] |= 1; 1563 1.1 christos } 1564 1.1 christos } 1565 1.1.1.8 christos 1566 1.1.1.8 christos relocation = sgot->output_offset + off; 1567 1.1 christos rel->r_addend = 0; 1568 1.1 christos /* bfin : preg = [preg + 17bitdiv4offset] relocation is div by 4. */ 1569 1.1 christos relocation /= 4; 1570 1.1 christos } 1571 1.1 christos goto do_default; 1572 1.1 christos 1573 1.1 christos default: 1574 1.1 christos do_default: 1575 1.1 christos r = bfin_final_link_relocate (rel, howto, input_bfd, input_section, 1576 1.1 christos contents, address, 1577 1.1 christos relocation, rel->r_addend); 1578 1.1 christos 1579 1.1 christos break; 1580 1.1.1.8 christos } 1581 1.1.1.8 christos 1582 1.1 christos /* Dynamic relocs are not propagated for SEC_DEBUGGING sections 1583 1.1.1.2 christos because such sections are not SEC_ALLOC and thus ld.so will 1584 1.1.1.2 christos not process them. */ 1585 1.1.1.2 christos if (unresolved_reloc 1586 1.1 christos && !((input_section->flags & SEC_DEBUGGING) != 0 && h->def_dynamic) 1587 1.1.1.7 christos && _bfd_elf_section_offset (output_bfd, info, input_section, 1588 1.1.1.7 christos rel->r_offset) != (bfd_vma) -1) 1589 1.1.1.8 christos { 1590 1.1.1.8 christos _bfd_error_handler 1591 1.1.1.8 christos /* xgettext:c-format */ 1592 1.1.1.8 christos (_("%pB(%pA+%#" PRIx64 "): " 1593 1.1.1.10 christos "unresolvable relocation against symbol `%s'"), 1594 1.1 christos input_bfd, input_section, (uint64_t) rel->r_offset, 1595 1.1 christos h->root.root.string); 1596 1.1 christos return false; 1597 1.1 christos } 1598 1.1 christos 1599 1.1 christos if (r != bfd_reloc_ok) 1600 1.1 christos { 1601 1.1 christos const char *name; 1602 1.1 christos 1603 1.1 christos if (h != NULL) 1604 1.1 christos name = h->root.root.string; 1605 1.1 christos else 1606 1.1 christos { 1607 1.1 christos name = bfd_elf_string_from_elf_section (input_bfd, 1608 1.1.1.10 christos symtab_hdr->sh_link, 1609 1.1 christos sym->st_name); 1610 1.1.1.9 christos if (name == NULL) 1611 1.1 christos return false; 1612 1.1 christos if (*name == '\0') 1613 1.1 christos name = bfd_section_name (sec); 1614 1.1.1.6 christos } 1615 1.1.1.6 christos 1616 1.1.1.6 christos if (r == bfd_reloc_overflow) 1617 1.1 christos (*info->callbacks->reloc_overflow) 1618 1.1 christos (info, (h ? &h->root : NULL), name, howto->name, 1619 1.1.1.7 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 1620 1.1.1.7 christos else 1621 1.1.1.8 christos { 1622 1.1.1.8 christos _bfd_error_handler 1623 1.1.1.8 christos /* xgettext:c-format */ 1624 1.1.1.10 christos (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"), 1625 1.1 christos input_bfd, input_section, (uint64_t) rel->r_offset, 1626 1.1 christos name, (int) r); 1627 1.1 christos return false; 1628 1.1 christos } 1629 1.1.1.10 christos } 1630 1.1 christos } 1631 1.1 christos 1632 1.1 christos return true; 1633 1.1 christos } 1634 1.1 christos 1635 1.1 christos static asection * 1636 1.1 christos bfin_gc_mark_hook (asection * sec, 1637 1.1.1.8 christos struct bfd_link_info *info, 1638 1.1 christos Elf_Internal_Rela * rel, 1639 1.1 christos struct elf_link_hash_entry *h, 1640 1.1 christos Elf_Internal_Sym * sym) 1641 1.1 christos { 1642 1.1 christos if (h != NULL) 1643 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 1644 1.1 christos { 1645 1.1 christos case R_BFIN_GNU_VTINHERIT: 1646 1.1 christos case R_BFIN_GNU_VTENTRY: 1647 1.1 christos return NULL; 1648 1.1 christos } 1649 1.1 christos 1650 1.1.1.4 christos return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 1651 1.1.1.4 christos } 1652 1.1 christos 1653 1.1 christos extern const bfd_target bfin_elf32_fdpic_vec; 1655 1.1 christos #define IS_FDPIC(bfd) ((bfd)->xvec == &bfin_elf32_fdpic_vec) 1656 1.1 christos 1657 1.1 christos /* An extension of the elf hash table data structure, 1658 1.1 christos containing some additional Blackfin-specific data. */ 1659 1.1 christos struct bfinfdpic_elf_link_hash_table 1660 1.1 christos { 1661 1.1 christos struct elf_link_hash_table elf; 1662 1.1 christos 1663 1.1 christos /* A pointer to the .rofixup section. */ 1664 1.1 christos asection *sgotfixup; 1665 1.1 christos /* GOT base offset. */ 1666 1.1 christos bfd_vma got0; 1667 1.1 christos /* Location of the first non-lazy PLT entry, i.e., the number of 1668 1.1 christos bytes taken by lazy PLT entries. */ 1669 1.1 christos bfd_vma plt0; 1670 1.1 christos /* A hash table holding information about which symbols were 1671 1.1 christos referenced with which PIC-related relocations. */ 1672 1.1 christos struct htab *relocs_info; 1673 1.1 christos /* Summary reloc information collected by 1674 1.1 christos _bfinfdpic_count_got_plt_entries. */ 1675 1.1 christos struct _bfinfdpic_dynamic_got_info *g; 1676 1.1.1.9 christos }; 1677 1.1.1.9 christos 1678 1.1.1.9 christos /* Get the Blackfin ELF linker hash table from a link_info structure. */ 1679 1.1.1.9 christos 1680 1.1 christos #define bfinfdpic_hash_table(p) \ 1681 1.1 christos ((is_elf_hash_table ((p)->hash) \ 1682 1.1.1.7 christos && elf_hash_table_id (elf_hash_table (p)) == BFIN_ELF_DATA) \ 1683 1.1 christos ? (struct bfinfdpic_elf_link_hash_table *) (p)->hash : NULL) 1684 1.1.1.7 christos 1685 1.1 christos #define bfinfdpic_got_section(info) \ 1686 1.1 christos (bfinfdpic_hash_table (info)->elf.sgot) 1687 1.1 christos #define bfinfdpic_gotrel_section(info) \ 1688 1.1.1.7 christos (bfinfdpic_hash_table (info)->elf.srelgot) 1689 1.1 christos #define bfinfdpic_gotfixup_section(info) \ 1690 1.1.1.7 christos (bfinfdpic_hash_table (info)->sgotfixup) 1691 1.1 christos #define bfinfdpic_plt_section(info) \ 1692 1.1 christos (bfinfdpic_hash_table (info)->elf.splt) 1693 1.1 christos #define bfinfdpic_pltrel_section(info) \ 1694 1.1 christos (bfinfdpic_hash_table (info)->elf.srelplt) 1695 1.1 christos #define bfinfdpic_relocs_info(info) \ 1696 1.1 christos (bfinfdpic_hash_table (info)->relocs_info) 1697 1.1 christos #define bfinfdpic_got_initial_offset(info) \ 1698 1.1 christos (bfinfdpic_hash_table (info)->got0) 1699 1.1 christos #define bfinfdpic_plt_initial_offset(info) \ 1700 1.1 christos (bfinfdpic_hash_table (info)->plt0) 1701 1.1 christos #define bfinfdpic_dynamic_got_plt_info(info) \ 1702 1.1 christos (bfinfdpic_hash_table (info)->g) 1703 1.1 christos 1704 1.1 christos /* The name of the dynamic interpreter. This is put in the .interp 1705 1.1 christos section. */ 1706 1.1 christos 1707 1.1 christos #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" 1708 1.1 christos 1709 1.1 christos #define DEFAULT_STACK_SIZE 0x20000 1710 1.1 christos 1711 1.1 christos /* This structure is used to collect the number of entries present in 1712 1.1 christos each addressable range of the got. */ 1713 1.1 christos struct _bfinfdpic_dynamic_got_info 1714 1.1 christos { 1715 1.1 christos /* Several bits of information about the current link. */ 1716 1.1 christos struct bfd_link_info *info; 1717 1.1 christos /* Total size needed for GOT entries within the 18- or 32-bit 1718 1.1 christos ranges. */ 1719 1.1 christos bfd_vma got17m4, gothilo; 1720 1.1 christos /* Total size needed for function descriptor entries within the 18- 1721 1.1 christos or 32-bit ranges. */ 1722 1.1 christos bfd_vma fd17m4, fdhilo; 1723 1.1 christos /* Total size needed function descriptor entries referenced in PLT 1724 1.1 christos entries, that would be profitable to place in offsets close to 1725 1.1 christos the PIC register. */ 1726 1.1 christos bfd_vma fdplt; 1727 1.1 christos /* Total size needed by lazy PLT entries. */ 1728 1.1 christos bfd_vma lzplt; 1729 1.1 christos /* Number of relocations carried over from input object files. */ 1730 1.1 christos unsigned long relocs; 1731 1.1 christos /* Number of fixups introduced by relocations in input object files. */ 1732 1.1 christos unsigned long fixups; 1733 1.1 christos }; 1734 1.1 christos 1735 1.1 christos /* Create a Blackfin ELF linker hash table. */ 1736 1.1 christos 1737 1.1.1.9 christos static struct bfd_link_hash_table * 1738 1.1 christos bfinfdpic_elf_link_hash_table_create (bfd *abfd) 1739 1.1.1.2 christos { 1740 1.1 christos struct bfinfdpic_elf_link_hash_table *ret; 1741 1.1 christos size_t amt = sizeof (struct bfinfdpic_elf_link_hash_table); 1742 1.1 christos 1743 1.1 christos ret = bfd_zmalloc (amt); 1744 1.1 christos if (ret == NULL) 1745 1.1.1.12 christos return NULL; 1746 1.1 christos 1747 1.1 christos if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, 1748 1.1 christos _bfd_elf_link_hash_newfunc, 1749 1.1 christos sizeof (struct elf_link_hash_entry))) 1750 1.1 christos { 1751 1.1 christos free (ret); 1752 1.1 christos return NULL; 1753 1.1 christos } 1754 1.1 christos 1755 1.1 christos return &ret->elf.root; 1756 1.1 christos } 1757 1.1 christos 1758 1.1 christos /* Decide whether a reference to a symbol can be resolved locally or 1759 1.1 christos not. If the symbol is protected, we want the local address, but 1760 1.1 christos its function descriptor must be assigned by the dynamic linker. */ 1761 1.1 christos #define BFINFDPIC_SYM_LOCAL(INFO, H) \ 1762 1.1 christos (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ 1763 1.1 christos || ! elf_hash_table (INFO)->dynamic_sections_created) 1764 1.1 christos #define BFINFDPIC_FUNCDESC_LOCAL(INFO, H) \ 1765 1.1 christos ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) 1766 1.1 christos 1767 1.1 christos /* This structure collects information on what kind of GOT, PLT or 1768 1.1 christos function descriptors are required by relocations that reference a 1769 1.1 christos certain symbol. */ 1770 1.1 christos struct bfinfdpic_relocs_info 1771 1.1 christos { 1772 1.1 christos /* The index of the symbol, as stored in the relocation r_info, if 1773 1.1 christos we have a local symbol; -1 otherwise. */ 1774 1.1 christos long symndx; 1775 1.1 christos union 1776 1.1 christos { 1777 1.1 christos /* The input bfd in which the symbol is defined, if it's a local 1778 1.1 christos symbol. */ 1779 1.1 christos bfd *abfd; 1780 1.1 christos /* If symndx == -1, the hash table entry corresponding to a global 1781 1.1 christos symbol (even if it turns out to bind locally, in which case it 1782 1.1 christos should ideally be replaced with section's symndx + addend). */ 1783 1.1 christos struct elf_link_hash_entry *h; 1784 1.1 christos } d; 1785 1.1 christos /* The addend of the relocation that references the symbol. */ 1786 1.1 christos bfd_vma addend; 1787 1.1 christos 1788 1.1 christos /* The fields above are used to identify an entry. The fields below 1789 1.1 christos contain information on how an entry is used and, later on, which 1790 1.1 christos locations it was assigned. */ 1791 1.1 christos /* The following 2 fields record whether the symbol+addend above was 1792 1.1 christos ever referenced with a GOT relocation. The 17M4 suffix indicates a 1793 1.1 christos GOT17M4 relocation; hilo is used for GOTLO/GOTHI pairs. */ 1794 1.1 christos unsigned got17m4; 1795 1.1 christos unsigned gothilo; 1796 1.1 christos /* Whether a FUNCDESC relocation references symbol+addend. */ 1797 1.1 christos unsigned fd; 1798 1.1 christos /* Whether a FUNCDESC_GOT relocation references symbol+addend. */ 1799 1.1 christos unsigned fdgot17m4; 1800 1.1 christos unsigned fdgothilo; 1801 1.1 christos /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */ 1802 1.1 christos unsigned fdgoff17m4; 1803 1.1 christos unsigned fdgoffhilo; 1804 1.1 christos /* Whether symbol+addend is referenced with GOTOFF17M4, GOTOFFLO or 1805 1.1 christos GOTOFFHI relocations. The addend doesn't really matter, since we 1806 1.1 christos envision that this will only be used to check whether the symbol 1807 1.1 christos is mapped to the same segment as the got. */ 1808 1.1 christos unsigned gotoff; 1809 1.1 christos /* Whether symbol+addend is referenced by a LABEL24 relocation. */ 1810 1.1 christos unsigned call; 1811 1.1 christos /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE 1812 1.1 christos relocation. */ 1813 1.1 christos unsigned sym; 1814 1.1 christos /* Whether we need a PLT entry for a symbol. Should be implied by 1815 1.1 christos something like: 1816 1.1 christos (call && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h)) */ 1817 1.1 christos unsigned plt:1; 1818 1.1.1.8 christos /* Whether a function descriptor should be created in this link unit 1819 1.1 christos for symbol+addend. Should be implied by something like: 1820 1.1 christos (plt || fdgotoff17m4 || fdgotofflohi 1821 1.1 christos || ((fd || fdgot17m4 || fdgothilo) 1822 1.1 christos && (symndx != -1 || BFINFDPIC_FUNCDESC_LOCAL (info, d.h)))) */ 1823 1.1 christos unsigned privfd:1; 1824 1.1 christos /* Whether a lazy PLT entry is needed for this symbol+addend. 1825 1.1 christos Should be implied by something like: 1826 1.1 christos (privfd && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h) 1827 1.1 christos && ! (info->flags & DF_BIND_NOW)) */ 1828 1.1 christos unsigned lazyplt:1; 1829 1.1 christos /* Whether we've already emitted GOT relocations and PLT entries as 1830 1.1 christos needed for this symbol. */ 1831 1.1 christos unsigned done:1; 1832 1.1 christos 1833 1.1 christos /* The number of R_BFIN_BYTE4_DATA, R_BFIN_FUNCDESC and R_BFIN_FUNCDESC_VALUE 1834 1.1 christos relocations referencing the symbol. */ 1835 1.1 christos unsigned relocs32, relocsfd, relocsfdv; 1836 1.1 christos 1837 1.1 christos /* The number of .rofixups entries and dynamic relocations allocated 1838 1.1 christos for this symbol, minus any that might have already been used. */ 1839 1.1 christos unsigned fixups, dynrelocs; 1840 1.1 christos 1841 1.1 christos /* The offsets of the GOT entries assigned to symbol+addend, to the 1842 1.1 christos function descriptor's address, and to a function descriptor, 1843 1.1 christos respectively. Should be zero if unassigned. The offsets are 1844 1.1 christos counted from the value that will be assigned to the PIC register, 1845 1.1 christos not from the beginning of the .got section. */ 1846 1.1 christos bfd_signed_vma got_entry, fdgot_entry, fd_entry; 1847 1.1 christos /* The offsets of the PLT entries assigned to symbol+addend, 1848 1.1 christos non-lazy and lazy, respectively. If unassigned, should be 1849 1.1 christos (bfd_vma)-1. */ 1850 1.1 christos bfd_vma plt_entry, lzplt_entry; 1851 1.1 christos }; 1852 1.1 christos 1853 1.1 christos /* Compute a hash with the key fields of an bfinfdpic_relocs_info entry. */ 1854 1.1 christos static hashval_t 1855 1.1 christos bfinfdpic_relocs_info_hash (const void *entry_) 1856 1.1 christos { 1857 1.1 christos const struct bfinfdpic_relocs_info *entry = entry_; 1858 1.1 christos 1859 1.1 christos return (entry->symndx == -1 1860 1.1 christos ? (long) entry->d.h->root.root.hash 1861 1.1 christos : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend; 1862 1.1 christos } 1863 1.1 christos 1864 1.1 christos /* Test whether the key fields of two bfinfdpic_relocs_info entries are 1865 1.1 christos identical. */ 1866 1.1 christos static int 1867 1.1 christos bfinfdpic_relocs_info_eq (const void *entry1, const void *entry2) 1868 1.1 christos { 1869 1.1 christos const struct bfinfdpic_relocs_info *e1 = entry1; 1870 1.1 christos const struct bfinfdpic_relocs_info *e2 = entry2; 1871 1.1 christos 1872 1.1 christos return e1->symndx == e2->symndx && e1->addend == e2->addend 1873 1.1 christos && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd); 1874 1.1 christos } 1875 1.1 christos 1876 1.1 christos /* Find or create an entry in a hash table HT that matches the key 1877 1.1 christos fields of the given ENTRY. If it's not found, memory for a new 1878 1.1 christos entry is allocated in ABFD's obstack. */ 1879 1.1 christos static struct bfinfdpic_relocs_info * 1880 1.1 christos bfinfdpic_relocs_info_find (struct htab *ht, 1881 1.1 christos bfd *abfd, 1882 1.1 christos const struct bfinfdpic_relocs_info *entry, 1883 1.1 christos enum insert_option insert) 1884 1.1 christos { 1885 1.1 christos struct bfinfdpic_relocs_info **loc; 1886 1.1 christos 1887 1.1 christos if (!ht) 1888 1.1 christos return NULL; 1889 1.1 christos 1890 1.1 christos loc = (struct bfinfdpic_relocs_info **) htab_find_slot (ht, entry, insert); 1891 1.1 christos 1892 1.1 christos if (! loc) 1893 1.1 christos return NULL; 1894 1.1 christos 1895 1.1 christos if (*loc) 1896 1.1 christos return *loc; 1897 1.1 christos 1898 1.1 christos *loc = bfd_zalloc (abfd, sizeof (**loc)); 1899 1.1 christos 1900 1.1 christos if (! *loc) 1901 1.1 christos return *loc; 1902 1.1 christos 1903 1.1 christos (*loc)->symndx = entry->symndx; 1904 1.1 christos (*loc)->d = entry->d; 1905 1.1 christos (*loc)->addend = entry->addend; 1906 1.1 christos (*loc)->plt_entry = (bfd_vma)-1; 1907 1.1 christos (*loc)->lzplt_entry = (bfd_vma)-1; 1908 1.1 christos 1909 1.1 christos return *loc; 1910 1.1 christos } 1911 1.1 christos 1912 1.1 christos /* Obtain the address of the entry in HT associated with H's symbol + 1913 1.1.1.2 christos addend, creating a new entry if none existed. ABFD is only used 1914 1.1.1.2 christos for memory allocation purposes. */ 1915 1.1.1.2 christos inline static struct bfinfdpic_relocs_info * 1916 1.1.1.2 christos bfinfdpic_relocs_info_for_global (struct htab *ht, 1917 1.1 christos bfd *abfd, 1918 1.1 christos struct elf_link_hash_entry *h, 1919 1.1 christos bfd_vma addend, 1920 1.1 christos enum insert_option insert) 1921 1.1 christos { 1922 1.1 christos struct bfinfdpic_relocs_info entry; 1923 1.1 christos 1924 1.1 christos entry.symndx = -1; 1925 1.1 christos entry.d.h = h; 1926 1.1 christos entry.addend = addend; 1927 1.1 christos 1928 1.1 christos return bfinfdpic_relocs_info_find (ht, abfd, &entry, insert); 1929 1.1 christos } 1930 1.1 christos 1931 1.1 christos /* Obtain the address of the entry in HT associated with the SYMNDXth 1932 1.1 christos local symbol of the input bfd ABFD, plus the addend, creating a new 1933 1.1 christos entry if none existed. */ 1934 1.1 christos inline static struct bfinfdpic_relocs_info * 1935 1.1 christos bfinfdpic_relocs_info_for_local (struct htab *ht, 1936 1.1 christos bfd *abfd, 1937 1.1 christos long symndx, 1938 1.1 christos bfd_vma addend, 1939 1.1 christos enum insert_option insert) 1940 1.1 christos { 1941 1.1 christos struct bfinfdpic_relocs_info entry; 1942 1.1 christos 1943 1.1 christos entry.symndx = symndx; 1944 1.1 christos entry.d.abfd = abfd; 1945 1.1 christos entry.addend = addend; 1946 1.1 christos 1947 1.1 christos return bfinfdpic_relocs_info_find (ht, abfd, &entry, insert); 1948 1.1 christos } 1949 1.1 christos 1950 1.1 christos /* Merge fields set by check_relocs() of two entries that end up being 1951 1.1.1.2 christos mapped to the same (presumably global) symbol. */ 1952 1.1 christos 1953 1.1 christos inline static void 1954 1.1 christos bfinfdpic_pic_merge_early_relocs_info (struct bfinfdpic_relocs_info *e2, 1955 1.1 christos struct bfinfdpic_relocs_info const *e1) 1956 1.1 christos { 1957 1.1 christos e2->got17m4 |= e1->got17m4; 1958 1.1 christos e2->gothilo |= e1->gothilo; 1959 1.1 christos e2->fd |= e1->fd; 1960 1.1 christos e2->fdgot17m4 |= e1->fdgot17m4; 1961 1.1 christos e2->fdgothilo |= e1->fdgothilo; 1962 1.1 christos e2->fdgoff17m4 |= e1->fdgoff17m4; 1963 1.1 christos e2->fdgoffhilo |= e1->fdgoffhilo; 1964 1.1 christos e2->gotoff |= e1->gotoff; 1965 1.1 christos e2->call |= e1->call; 1966 1.1 christos e2->sym |= e1->sym; 1967 1.1 christos } 1968 1.1 christos 1969 1.1 christos /* Every block of 65535 lazy PLT entries shares a single call to the 1970 1.1 christos resolver, inserted in the 32768th lazy PLT entry (i.e., entry # 1971 1.1 christos 32767, counting from 0). All other lazy PLT entries branch to it 1972 1.1 christos in a single instruction. */ 1973 1.1 christos 1974 1.1 christos #define LZPLT_RESOLVER_EXTRA 10 1975 1.1 christos #define LZPLT_NORMAL_SIZE 6 1976 1.1 christos #define LZPLT_ENTRIES 1362 1977 1.1 christos 1978 1.1 christos #define BFINFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) LZPLT_NORMAL_SIZE * LZPLT_ENTRIES + LZPLT_RESOLVER_EXTRA) 1979 1.1 christos #define BFINFDPIC_LZPLT_RESOLV_LOC (LZPLT_NORMAL_SIZE * LZPLT_ENTRIES / 2) 1980 1.1 christos 1981 1.1 christos /* Add a dynamic relocation to the SRELOC section. */ 1982 1.1 christos 1983 1.1 christos inline static bfd_vma 1984 1.1 christos _bfinfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset, 1985 1.1 christos int reloc_type, long dynindx, bfd_vma addend, 1986 1.1 christos struct bfinfdpic_relocs_info *entry) 1987 1.1 christos { 1988 1.1 christos Elf_Internal_Rela outrel; 1989 1.1 christos bfd_vma reloc_offset; 1990 1.1 christos 1991 1.1 christos outrel.r_offset = offset; 1992 1.1 christos outrel.r_info = ELF32_R_INFO (dynindx, reloc_type); 1993 1.1 christos outrel.r_addend = addend; 1994 1.1 christos 1995 1.1 christos reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel); 1996 1.1 christos BFD_ASSERT (reloc_offset < sreloc->size); 1997 1.1 christos bfd_elf32_swap_reloc_out (output_bfd, &outrel, 1998 1.1 christos sreloc->contents + reloc_offset); 1999 1.1 christos sreloc->reloc_count++; 2000 1.1 christos 2001 1.1 christos /* If the entry's index is zero, this relocation was probably to a 2002 1.1 christos linkonce section that got discarded. We reserved a dynamic 2003 1.1 christos relocation, but it was for another entry than the one we got at 2004 1.1 christos the time of emitting the relocation. Unfortunately there's no 2005 1.1 christos simple way for us to catch this situation, since the relocation 2006 1.1 christos is cleared right before calling relocate_section, at which point 2007 1.1 christos we no longer know what the relocation used to point to. */ 2008 1.1 christos if (entry->symndx) 2009 1.1 christos { 2010 1.1 christos BFD_ASSERT (entry->dynrelocs > 0); 2011 1.1 christos entry->dynrelocs--; 2012 1.1 christos } 2013 1.1 christos 2014 1.1 christos return reloc_offset; 2015 1.1 christos } 2016 1.1 christos 2017 1.1.1.2 christos /* Add a fixup to the ROFIXUP section. */ 2018 1.1 christos 2019 1.1 christos static bfd_vma 2020 1.1 christos _bfinfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset, 2021 1.1 christos struct bfinfdpic_relocs_info *entry) 2022 1.1 christos { 2023 1.1 christos bfd_vma fixup_offset; 2024 1.1 christos 2025 1.1 christos if (rofixup->flags & SEC_EXCLUDE) 2026 1.1 christos return -1; 2027 1.1 christos 2028 1.1 christos fixup_offset = rofixup->reloc_count * 4; 2029 1.1 christos if (rofixup->contents) 2030 1.1 christos { 2031 1.1 christos BFD_ASSERT (fixup_offset < rofixup->size); 2032 1.1 christos bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset); 2033 1.1 christos } 2034 1.1 christos rofixup->reloc_count++; 2035 1.1 christos 2036 1.1 christos if (entry && entry->symndx) 2037 1.1 christos { 2038 1.1 christos /* See discussion about symndx == 0 in _bfinfdpic_add_dyn_reloc 2039 1.1 christos above. */ 2040 1.1 christos BFD_ASSERT (entry->fixups > 0); 2041 1.1 christos entry->fixups--; 2042 1.1 christos } 2043 1.1 christos 2044 1.1 christos return fixup_offset; 2045 1.1 christos } 2046 1.1 christos 2047 1.1 christos /* Find the segment number in which OSEC, and output section, is 2048 1.1 christos located. */ 2049 1.1 christos 2050 1.1 christos static unsigned 2051 1.1 christos _bfinfdpic_osec_to_segment (bfd *output_bfd, asection *osec) 2052 1.1 christos { 2053 1.1 christos Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec); 2054 1.1.1.10 christos 2055 1.1 christos return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1; 2056 1.1 christos } 2057 1.1 christos 2058 1.1 christos inline static bool 2059 1.1 christos _bfinfdpic_osec_readonly_p (bfd *output_bfd, asection *osec) 2060 1.1 christos { 2061 1.1 christos unsigned seg = _bfinfdpic_osec_to_segment (output_bfd, osec); 2062 1.1 christos 2063 1.1 christos return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W); 2064 1.1 christos } 2065 1.1.1.10 christos 2066 1.1 christos /* Generate relocations for GOT entries, function descriptors, and 2067 1.1 christos code for PLT and lazy PLT entries. */ 2068 1.1 christos 2069 1.1 christos inline static bool 2070 1.1 christos _bfinfdpic_emit_got_relocs_plt_entries (struct bfinfdpic_relocs_info *entry, 2071 1.1 christos bfd *output_bfd, 2072 1.1 christos struct bfd_link_info *info, 2073 1.1.1.2 christos asection *sec, 2074 1.1 christos Elf_Internal_Sym *sym, 2075 1.1 christos bfd_vma addend) 2076 1.1 christos { 2077 1.1.1.10 christos bfd_vma fd_lazy_rel_offset = (bfd_vma) -1; 2078 1.1 christos int dynindx = -1; 2079 1.1 christos 2080 1.1 christos if (entry->done) 2081 1.1 christos return true; 2082 1.1 christos entry->done = 1; 2083 1.1 christos 2084 1.1 christos if (entry->got_entry || entry->fdgot_entry || entry->fd_entry) 2085 1.1 christos { 2086 1.1 christos /* If the symbol is dynamic, consider it for dynamic 2087 1.1 christos relocations, otherwise decay to section + offset. */ 2088 1.1 christos if (entry->symndx == -1 && entry->d.h->dynindx != -1) 2089 1.1 christos dynindx = entry->d.h->dynindx; 2090 1.1 christos else 2091 1.1 christos { 2092 1.1 christos if (sec 2093 1.1 christos && sec->output_section 2094 1.1 christos && ! bfd_is_abs_section (sec->output_section) 2095 1.1 christos && ! bfd_is_und_section (sec->output_section)) 2096 1.1 christos dynindx = elf_section_data (sec->output_section)->dynindx; 2097 1.1 christos else 2098 1.1 christos dynindx = 0; 2099 1.1 christos } 2100 1.1 christos } 2101 1.1 christos 2102 1.1 christos /* Generate relocation for GOT entry pointing to the symbol. */ 2103 1.1 christos if (entry->got_entry) 2104 1.1 christos { 2105 1.1 christos int idx = dynindx; 2106 1.1 christos bfd_vma ad = addend; 2107 1.1 christos 2108 1.1 christos /* If the symbol is dynamic but binds locally, use 2109 1.1 christos section+offset. */ 2110 1.1 christos if (sec && (entry->symndx != -1 2111 1.1 christos || BFINFDPIC_SYM_LOCAL (info, entry->d.h))) 2112 1.1 christos { 2113 1.1 christos if (entry->symndx == -1) 2114 1.1 christos ad += entry->d.h->root.u.def.value; 2115 1.1 christos else 2116 1.1 christos ad += sym->st_value; 2117 1.1 christos ad += sec->output_offset; 2118 1.1 christos if (sec->output_section && elf_section_data (sec->output_section)) 2119 1.1 christos idx = elf_section_data (sec->output_section)->dynindx; 2120 1.1 christos else 2121 1.1 christos idx = 0; 2122 1.1 christos } 2123 1.1.1.6 christos 2124 1.1 christos /* If we're linking an executable at a fixed address, we can 2125 1.1 christos omit the dynamic relocation as long as the symbol is local to 2126 1.1 christos this module. */ 2127 1.1 christos if (bfd_link_pde (info) 2128 1.1 christos && (entry->symndx != -1 2129 1.1 christos || BFINFDPIC_SYM_LOCAL (info, entry->d.h))) 2130 1.1 christos { 2131 1.1 christos if (sec) 2132 1.1 christos ad += sec->output_section->vma; 2133 1.1 christos if (entry->symndx != -1 2134 1.1 christos || entry->d.h->root.type != bfd_link_hash_undefweak) 2135 1.1 christos _bfinfdpic_add_rofixup (output_bfd, 2136 1.1 christos bfinfdpic_gotfixup_section (info), 2137 1.1 christos bfinfdpic_got_section (info)->output_section 2138 1.1 christos ->vma 2139 1.1 christos + bfinfdpic_got_section (info)->output_offset 2140 1.1 christos + bfinfdpic_got_initial_offset (info) 2141 1.1 christos + entry->got_entry, entry); 2142 1.1 christos } 2143 1.1 christos else 2144 1.1 christos _bfinfdpic_add_dyn_reloc (output_bfd, bfinfdpic_gotrel_section (info), 2145 1.1 christos _bfd_elf_section_offset 2146 1.1 christos (output_bfd, info, 2147 1.1 christos bfinfdpic_got_section (info), 2148 1.1 christos bfinfdpic_got_initial_offset (info) 2149 1.1 christos + entry->got_entry) 2150 1.1 christos + bfinfdpic_got_section (info) 2151 1.1 christos ->output_section->vma 2152 1.1 christos + bfinfdpic_got_section (info)->output_offset, 2153 1.1 christos R_BFIN_BYTE4_DATA, idx, ad, entry); 2154 1.1 christos 2155 1.1 christos bfd_put_32 (output_bfd, ad, 2156 1.1 christos bfinfdpic_got_section (info)->contents 2157 1.1 christos + bfinfdpic_got_initial_offset (info) 2158 1.1 christos + entry->got_entry); 2159 1.1 christos } 2160 1.1 christos 2161 1.1 christos /* Generate relocation for GOT entry pointing to a canonical 2162 1.1 christos function descriptor. */ 2163 1.1 christos if (entry->fdgot_entry) 2164 1.1 christos { 2165 1.1 christos int reloc, idx; 2166 1.1 christos bfd_vma ad = 0; 2167 1.1 christos 2168 1.1 christos if (! (entry->symndx == -1 2169 1.1 christos && entry->d.h->root.type == bfd_link_hash_undefweak 2170 1.1 christos && BFINFDPIC_SYM_LOCAL (info, entry->d.h))) 2171 1.1 christos { 2172 1.1 christos /* If the symbol is dynamic and there may be dynamic symbol 2173 1.1 christos resolution because we are, or are linked with, a shared 2174 1.1 christos library, emit a FUNCDESC relocation such that the dynamic 2175 1.1 christos linker will allocate the function descriptor. If the 2176 1.1 christos symbol needs a non-local function descriptor but binds 2177 1.1 christos locally (e.g., its visibility is protected, emit a 2178 1.1.1.6 christos dynamic relocation decayed to section+offset. */ 2179 1.1 christos if (entry->symndx == -1 2180 1.1 christos && ! BFINFDPIC_FUNCDESC_LOCAL (info, entry->d.h) 2181 1.1 christos && BFINFDPIC_SYM_LOCAL (info, entry->d.h) 2182 1.1 christos && !bfd_link_pde (info)) 2183 1.1 christos { 2184 1.1 christos reloc = R_BFIN_FUNCDESC; 2185 1.1 christos idx = elf_section_data (entry->d.h->root.u.def.section 2186 1.1 christos ->output_section)->dynindx; 2187 1.1 christos ad = entry->d.h->root.u.def.section->output_offset 2188 1.1 christos + entry->d.h->root.u.def.value; 2189 1.1 christos } 2190 1.1 christos else if (entry->symndx == -1 2191 1.1 christos && ! BFINFDPIC_FUNCDESC_LOCAL (info, entry->d.h)) 2192 1.1 christos { 2193 1.1.1.10 christos reloc = R_BFIN_FUNCDESC; 2194 1.1 christos idx = dynindx; 2195 1.1 christos ad = addend; 2196 1.1 christos if (ad) 2197 1.1 christos return false; 2198 1.1 christos } 2199 1.1 christos else 2200 1.1 christos { 2201 1.1 christos /* Otherwise, we know we have a private function descriptor, 2202 1.1 christos so reference it directly. */ 2203 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 2204 1.1 christos BFD_ASSERT (entry->privfd); 2205 1.1 christos reloc = R_BFIN_BYTE4_DATA; 2206 1.1 christos idx = elf_section_data (bfinfdpic_got_section (info) 2207 1.1 christos ->output_section)->dynindx; 2208 1.1 christos ad = bfinfdpic_got_section (info)->output_offset 2209 1.1 christos + bfinfdpic_got_initial_offset (info) + entry->fd_entry; 2210 1.1 christos } 2211 1.1 christos 2212 1.1 christos /* If there is room for dynamic symbol resolution, emit the 2213 1.1 christos dynamic relocation. However, if we're linking an 2214 1.1.1.6 christos executable at a fixed location, we won't have emitted a 2215 1.1 christos dynamic symbol entry for the got section, so idx will be 2216 1.1 christos zero, which means we can and should compute the address 2217 1.1 christos of the private descriptor ourselves. */ 2218 1.1 christos if (bfd_link_pde (info) 2219 1.1 christos && (entry->symndx != -1 2220 1.1 christos || BFINFDPIC_FUNCDESC_LOCAL (info, entry->d.h))) 2221 1.1 christos { 2222 1.1 christos ad += bfinfdpic_got_section (info)->output_section->vma; 2223 1.1 christos _bfinfdpic_add_rofixup (output_bfd, 2224 1.1 christos bfinfdpic_gotfixup_section (info), 2225 1.1 christos bfinfdpic_got_section (info) 2226 1.1 christos ->output_section->vma 2227 1.1 christos + bfinfdpic_got_section (info) 2228 1.1 christos ->output_offset 2229 1.1 christos + bfinfdpic_got_initial_offset (info) 2230 1.1 christos + entry->fdgot_entry, entry); 2231 1.1 christos } 2232 1.1 christos else 2233 1.1 christos _bfinfdpic_add_dyn_reloc (output_bfd, 2234 1.1 christos bfinfdpic_gotrel_section (info), 2235 1.1 christos _bfd_elf_section_offset 2236 1.1 christos (output_bfd, info, 2237 1.1 christos bfinfdpic_got_section (info), 2238 1.1 christos bfinfdpic_got_initial_offset (info) 2239 1.1 christos + entry->fdgot_entry) 2240 1.1 christos + bfinfdpic_got_section (info) 2241 1.1 christos ->output_section->vma 2242 1.1 christos + bfinfdpic_got_section (info) 2243 1.1 christos ->output_offset, 2244 1.1 christos reloc, idx, ad, entry); 2245 1.1 christos } 2246 1.1 christos 2247 1.1 christos bfd_put_32 (output_bfd, ad, 2248 1.1 christos bfinfdpic_got_section (info)->contents 2249 1.1 christos + bfinfdpic_got_initial_offset (info) 2250 1.1 christos + entry->fdgot_entry); 2251 1.1 christos } 2252 1.1 christos 2253 1.1 christos /* Generate relocation to fill in a private function descriptor in 2254 1.1 christos the GOT. */ 2255 1.1 christos if (entry->fd_entry) 2256 1.1 christos { 2257 1.1 christos int idx = dynindx; 2258 1.1 christos bfd_vma ad = addend; 2259 1.1 christos bfd_vma ofst; 2260 1.1 christos long lowword, highword; 2261 1.1 christos 2262 1.1 christos /* If the symbol is dynamic but binds locally, use 2263 1.1 christos section+offset. */ 2264 1.1 christos if (sec && (entry->symndx != -1 2265 1.1 christos || BFINFDPIC_SYM_LOCAL (info, entry->d.h))) 2266 1.1 christos { 2267 1.1 christos if (entry->symndx == -1) 2268 1.1 christos ad += entry->d.h->root.u.def.value; 2269 1.1 christos else 2270 1.1 christos ad += sym->st_value; 2271 1.1 christos ad += sec->output_offset; 2272 1.1 christos if (sec->output_section && elf_section_data (sec->output_section)) 2273 1.1 christos idx = elf_section_data (sec->output_section)->dynindx; 2274 1.1 christos else 2275 1.1 christos idx = 0; 2276 1.1 christos } 2277 1.1.1.6 christos 2278 1.1 christos /* If we're linking an executable at a fixed address, we can 2279 1.1 christos omit the dynamic relocation as long as the symbol is local to 2280 1.1 christos this module. */ 2281 1.1 christos if (bfd_link_pde (info) 2282 1.1 christos && (entry->symndx != -1 || BFINFDPIC_SYM_LOCAL (info, entry->d.h))) 2283 1.1 christos { 2284 1.1 christos if (sec) 2285 1.1 christos ad += sec->output_section->vma; 2286 1.1 christos ofst = 0; 2287 1.1 christos if (entry->symndx != -1 2288 1.1 christos || entry->d.h->root.type != bfd_link_hash_undefweak) 2289 1.1 christos { 2290 1.1 christos _bfinfdpic_add_rofixup (output_bfd, 2291 1.1 christos bfinfdpic_gotfixup_section (info), 2292 1.1 christos bfinfdpic_got_section (info) 2293 1.1 christos ->output_section->vma 2294 1.1 christos + bfinfdpic_got_section (info) 2295 1.1 christos ->output_offset 2296 1.1 christos + bfinfdpic_got_initial_offset (info) 2297 1.1 christos + entry->fd_entry, entry); 2298 1.1 christos _bfinfdpic_add_rofixup (output_bfd, 2299 1.1 christos bfinfdpic_gotfixup_section (info), 2300 1.1 christos bfinfdpic_got_section (info) 2301 1.1 christos ->output_section->vma 2302 1.1 christos + bfinfdpic_got_section (info) 2303 1.1 christos ->output_offset 2304 1.1 christos + bfinfdpic_got_initial_offset (info) 2305 1.1 christos + entry->fd_entry + 4, entry); 2306 1.1 christos } 2307 1.1 christos } 2308 1.1 christos else 2309 1.1 christos { 2310 1.1 christos ofst 2311 1.1 christos = _bfinfdpic_add_dyn_reloc (output_bfd, 2312 1.1 christos entry->lazyplt 2313 1.1 christos ? bfinfdpic_pltrel_section (info) 2314 1.1 christos : bfinfdpic_gotrel_section (info), 2315 1.1 christos _bfd_elf_section_offset 2316 1.1 christos (output_bfd, info, 2317 1.1 christos bfinfdpic_got_section (info), 2318 1.1 christos bfinfdpic_got_initial_offset (info) 2319 1.1 christos + entry->fd_entry) 2320 1.1 christos + bfinfdpic_got_section (info) 2321 1.1 christos ->output_section->vma 2322 1.1 christos + bfinfdpic_got_section (info) 2323 1.1 christos ->output_offset, 2324 1.1 christos R_BFIN_FUNCDESC_VALUE, idx, ad, entry); 2325 1.1.1.6 christos } 2326 1.1.1.6 christos 2327 1.1.1.6 christos /* If we've omitted the dynamic relocation, just emit the fixed 2328 1.1 christos addresses of the symbol and of the local GOT base offset. */ 2329 1.1 christos if (bfd_link_pde (info) 2330 1.1 christos && sec 2331 1.1 christos && sec->output_section) 2332 1.1 christos { 2333 1.1 christos lowword = ad; 2334 1.1 christos highword = bfinfdpic_got_section (info)->output_section->vma 2335 1.1 christos + bfinfdpic_got_section (info)->output_offset 2336 1.1 christos + bfinfdpic_got_initial_offset (info); 2337 1.1.1.10 christos } 2338 1.1 christos else if (entry->lazyplt) 2339 1.1 christos { 2340 1.1 christos if (ad) 2341 1.1 christos return false; 2342 1.1 christos 2343 1.1 christos fd_lazy_rel_offset = ofst; 2344 1.1 christos 2345 1.1 christos /* A function descriptor used for lazy or local resolving is 2346 1.1 christos initialized such that its high word contains the output 2347 1.1 christos section index in which the PLT entries are located, and 2348 1.1 christos the low word contains the address of the lazy PLT entry 2349 1.1 christos entry point, that must be within the memory region 2350 1.1 christos assigned to that section. */ 2351 1.1 christos lowword = entry->lzplt_entry + 4 2352 1.1 christos + bfinfdpic_plt_section (info)->output_offset 2353 1.1 christos + bfinfdpic_plt_section (info)->output_section->vma; 2354 1.1 christos highword = _bfinfdpic_osec_to_segment 2355 1.1 christos (output_bfd, bfinfdpic_plt_section (info)->output_section); 2356 1.1 christos } 2357 1.1 christos else 2358 1.1 christos { 2359 1.1 christos /* A function descriptor for a local function gets the index 2360 1.1 christos of the section. For a non-local function, it's 2361 1.1 christos disregarded. */ 2362 1.1 christos lowword = ad; 2363 1.1 christos if (sec == NULL 2364 1.1 christos || (entry->symndx == -1 && entry->d.h->dynindx != -1 2365 1.1 christos && entry->d.h->dynindx == idx)) 2366 1.1 christos highword = 0; 2367 1.1 christos else 2368 1.1 christos highword = _bfinfdpic_osec_to_segment 2369 1.1 christos (output_bfd, sec->output_section); 2370 1.1 christos } 2371 1.1 christos 2372 1.1 christos bfd_put_32 (output_bfd, lowword, 2373 1.1 christos bfinfdpic_got_section (info)->contents 2374 1.1 christos + bfinfdpic_got_initial_offset (info) 2375 1.1 christos + entry->fd_entry); 2376 1.1 christos bfd_put_32 (output_bfd, highword, 2377 1.1 christos bfinfdpic_got_section (info)->contents 2378 1.1 christos + bfinfdpic_got_initial_offset (info) 2379 1.1 christos + entry->fd_entry + 4); 2380 1.1 christos } 2381 1.1 christos 2382 1.1 christos /* Generate code for the PLT entry. */ 2383 1.1 christos if (entry->plt_entry != (bfd_vma) -1) 2384 1.1 christos { 2385 1.1 christos bfd_byte *plt_code = bfinfdpic_plt_section (info)->contents 2386 1.1 christos + entry->plt_entry; 2387 1.1 christos 2388 1.1 christos BFD_ASSERT (entry->fd_entry); 2389 1.1 christos 2390 1.1 christos /* Figure out what kind of PLT entry we need, depending on the 2391 1.1 christos location of the function descriptor within the GOT. */ 2392 1.1 christos if (entry->fd_entry >= -(1 << (18 - 1)) 2393 1.1 christos && entry->fd_entry + 4 < (1 << (18 - 1))) 2394 1.1 christos { 2395 1.1 christos /* P1 = [P3 + fd_entry]; P3 = [P3 + fd_entry + 4] */ 2396 1.1 christos bfd_put_32 (output_bfd, 2397 1.1 christos 0xe519 | ((entry->fd_entry << 14) & 0xFFFF0000), 2398 1.1 christos plt_code); 2399 1.1 christos bfd_put_32 (output_bfd, 2400 1.1 christos 0xe51b | (((entry->fd_entry + 4) << 14) & 0xFFFF0000), 2401 1.1 christos plt_code + 4); 2402 1.1 christos plt_code += 8; 2403 1.1 christos } 2404 1.1 christos else 2405 1.1 christos { 2406 1.1 christos /* P1.L = fd_entry; P1.H = fd_entry; 2407 1.1 christos P3 = P3 + P1; 2408 1.1 christos P1 = [P3]; 2409 1.1 christos P3 = [P3 + 4]; */ 2410 1.1 christos bfd_put_32 (output_bfd, 2411 1.1 christos 0xe109 | (entry->fd_entry << 16), 2412 1.1 christos plt_code); 2413 1.1 christos bfd_put_32 (output_bfd, 2414 1.1 christos 0xe149 | (entry->fd_entry & 0xFFFF0000), 2415 1.1 christos plt_code + 4); 2416 1.1 christos bfd_put_16 (output_bfd, 0x5ad9, plt_code + 8); 2417 1.1 christos bfd_put_16 (output_bfd, 0x9159, plt_code + 10); 2418 1.1 christos bfd_put_16 (output_bfd, 0xac5b, plt_code + 12); 2419 1.1 christos plt_code += 14; 2420 1.1 christos } 2421 1.1 christos /* JUMP (P1) */ 2422 1.1 christos bfd_put_16 (output_bfd, 0x0051, plt_code); 2423 1.1 christos } 2424 1.1 christos 2425 1.1 christos /* Generate code for the lazy PLT entry. */ 2426 1.1 christos if (entry->lzplt_entry != (bfd_vma) -1) 2427 1.1 christos { 2428 1.1 christos bfd_byte *lzplt_code = bfinfdpic_plt_section (info)->contents 2429 1.1 christos + entry->lzplt_entry; 2430 1.1 christos bfd_vma resolverStub_addr; 2431 1.1 christos 2432 1.1 christos bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code); 2433 1.1 christos lzplt_code += 4; 2434 1.1 christos 2435 1.1 christos resolverStub_addr = entry->lzplt_entry / BFINFDPIC_LZPLT_BLOCK_SIZE 2436 1.1 christos * BFINFDPIC_LZPLT_BLOCK_SIZE + BFINFDPIC_LZPLT_RESOLV_LOC; 2437 1.1 christos if (resolverStub_addr >= bfinfdpic_plt_initial_offset (info)) 2438 1.1 christos resolverStub_addr = bfinfdpic_plt_initial_offset (info) - LZPLT_NORMAL_SIZE - LZPLT_RESOLVER_EXTRA; 2439 1.1 christos 2440 1.1 christos if (entry->lzplt_entry == resolverStub_addr) 2441 1.1 christos { 2442 1.1 christos /* This is a lazy PLT entry that includes a resolver call. 2443 1.1 christos P2 = [P3]; 2444 1.1 christos R3 = [P3 + 4]; 2445 1.1 christos JUMP (P2); */ 2446 1.1 christos bfd_put_32 (output_bfd, 2447 1.1 christos 0xa05b915a, 2448 1.1 christos lzplt_code); 2449 1.1 christos bfd_put_16 (output_bfd, 0x0052, lzplt_code + 4); 2450 1.1 christos } 2451 1.1 christos else 2452 1.1 christos { 2453 1.1 christos /* JUMP.S resolverStub */ 2454 1.1 christos bfd_put_16 (output_bfd, 2455 1.1 christos 0x2000 2456 1.1 christos | (((resolverStub_addr - entry->lzplt_entry) 2457 1.1 christos / 2) & (((bfd_vma)1 << 12) - 1)), 2458 1.1.1.10 christos lzplt_code); 2459 1.1 christos } 2460 1.1 christos } 2461 1.1 christos 2462 1.1 christos return true; 2463 1.1 christos } 2464 1.1 christos 2465 1.1 christos /* Relocate an Blackfin ELF section. 2467 1.1 christos 2468 1.1 christos The RELOCATE_SECTION function is called by the new ELF backend linker 2469 1.1 christos to handle the relocations for a section. 2470 1.1 christos 2471 1.1 christos The relocs are always passed as Rela structures; if the section 2472 1.1 christos actually uses Rel structures, the r_addend field will always be 2473 1.1 christos zero. 2474 1.1 christos 2475 1.1 christos This function is responsible for adjusting the section contents as 2476 1.1 christos necessary, and (if using Rela relocs and generating a relocatable 2477 1.1 christos output file) adjusting the reloc addend as necessary. 2478 1.1 christos 2479 1.1 christos This function does not have to worry about setting the reloc 2480 1.1 christos address or the reloc symbol index. 2481 1.1 christos 2482 1.1 christos LOCAL_SYMS is a pointer to the swapped in local symbols. 2483 1.1 christos 2484 1.1 christos LOCAL_SECTIONS is an array giving the section in the input file 2485 1.1 christos corresponding to the st_shndx field of each local symbol. 2486 1.1 christos 2487 1.1 christos The global hash table entry for the global symbols can be found 2488 1.1 christos via elf_sym_hashes (input_bfd). 2489 1.1 christos 2490 1.1 christos When generating relocatable output, this function must handle 2491 1.1.1.10 christos STB_LOCAL/STT_SECTION symbols specially. The output symbol is 2492 1.1 christos going to be the section symbol corresponding to the output 2493 1.1 christos section, which means that the addend must be adjusted 2494 1.1 christos accordingly. */ 2495 1.1 christos 2496 1.1 christos static int 2497 1.1 christos bfinfdpic_relocate_section (bfd * output_bfd, 2498 1.1 christos struct bfd_link_info *info, 2499 1.1 christos bfd * input_bfd, 2500 1.1 christos asection * input_section, 2501 1.1 christos bfd_byte * contents, 2502 1.1 christos Elf_Internal_Rela * relocs, 2503 1.1 christos Elf_Internal_Sym * local_syms, 2504 1.1 christos asection ** local_sections) 2505 1.1 christos { 2506 1.1 christos Elf_Internal_Shdr *symtab_hdr; 2507 1.1.1.6 christos struct elf_link_hash_entry **sym_hashes; 2508 1.1 christos Elf_Internal_Rela *rel; 2509 1.1 christos Elf_Internal_Rela *relend; 2510 1.1 christos unsigned isec_segment, got_segment, plt_segment, 2511 1.1 christos check_segment[2]; 2512 1.1 christos int silence_segment_error = !bfd_link_pic (info); 2513 1.1 christos 2514 1.1 christos symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; 2515 1.1 christos sym_hashes = elf_sym_hashes (input_bfd); 2516 1.1 christos relend = relocs + input_section->reloc_count; 2517 1.1 christos 2518 1.1 christos isec_segment = _bfinfdpic_osec_to_segment (output_bfd, 2519 1.1 christos input_section->output_section); 2520 1.1 christos if (IS_FDPIC (output_bfd) && bfinfdpic_got_section (info)) 2521 1.1 christos got_segment = _bfinfdpic_osec_to_segment (output_bfd, 2522 1.1 christos bfinfdpic_got_section (info) 2523 1.1 christos ->output_section); 2524 1.1 christos else 2525 1.1 christos got_segment = -1; 2526 1.1 christos if (IS_FDPIC (output_bfd) && elf_hash_table (info)->dynamic_sections_created) 2527 1.1 christos plt_segment = _bfinfdpic_osec_to_segment (output_bfd, 2528 1.1 christos bfinfdpic_plt_section (info) 2529 1.1 christos ->output_section); 2530 1.1 christos else 2531 1.1 christos plt_segment = -1; 2532 1.1 christos 2533 1.1 christos for (rel = relocs; rel < relend; rel ++) 2534 1.1 christos { 2535 1.1 christos reloc_howto_type *howto; 2536 1.1 christos unsigned long r_symndx; 2537 1.1 christos Elf_Internal_Sym *sym; 2538 1.1 christos asection *sec; 2539 1.1 christos struct elf_link_hash_entry *h; 2540 1.1 christos bfd_vma relocation; 2541 1.1 christos bfd_reloc_status_type r; 2542 1.1 christos const char * name = NULL; 2543 1.1 christos int r_type; 2544 1.1 christos asection *osec; 2545 1.1 christos struct bfinfdpic_relocs_info *picrel; 2546 1.1 christos bfd_vma orig_addend = rel->r_addend; 2547 1.1 christos 2548 1.1 christos r_type = ELF32_R_TYPE (rel->r_info); 2549 1.1 christos 2550 1.1 christos if (r_type == R_BFIN_GNU_VTINHERIT 2551 1.1 christos || r_type == R_BFIN_GNU_VTENTRY) 2552 1.1 christos continue; 2553 1.1 christos 2554 1.1.1.10 christos r_symndx = ELF32_R_SYM (rel->r_info); 2555 1.1 christos howto = bfin_reloc_type_lookup (input_bfd, r_type); 2556 1.1 christos if (howto == NULL) 2557 1.1 christos { 2558 1.1 christos bfd_set_error (bfd_error_bad_value); 2559 1.1 christos return false; 2560 1.1.1.9 christos } 2561 1.1 christos 2562 1.1 christos h = NULL; 2563 1.1 christos sym = NULL; 2564 1.1 christos sec = NULL; 2565 1.1 christos picrel = NULL; 2566 1.1 christos 2567 1.1 christos if (r_symndx < symtab_hdr->sh_info) 2568 1.1 christos { 2569 1.1 christos sym = local_syms + r_symndx; 2570 1.1.1.9 christos osec = sec = local_sections [r_symndx]; 2571 1.1 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 2572 1.1 christos 2573 1.1 christos name = bfd_elf_string_from_elf_section 2574 1.1.1.10 christos (input_bfd, symtab_hdr->sh_link, sym->st_name); 2575 1.1.1.10 christos name = name == NULL ? bfd_section_name (sec) : name; 2576 1.1 christos } 2577 1.1 christos else 2578 1.1 christos { 2579 1.1 christos bool warned, ignored; 2580 1.1.1.3 christos bool unresolved_reloc; 2581 1.1 christos 2582 1.1 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 2583 1.1 christos r_symndx, symtab_hdr, sym_hashes, 2584 1.1.1.2 christos h, sec, relocation, 2585 1.1 christos unresolved_reloc, warned, ignored); 2586 1.1.1.2 christos osec = sec; 2587 1.1 christos } 2588 1.1.1.6 christos 2589 1.1 christos if (sec != NULL && discarded_section (sec)) 2590 1.1 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 2591 1.1 christos rel, 1, relend, howto, 0, contents); 2592 1.1 christos 2593 1.1 christos if (bfd_link_relocatable (info)) 2594 1.1 christos continue; 2595 1.1 christos 2596 1.1 christos if (h != NULL 2597 1.1 christos && (h->root.type == bfd_link_hash_defined 2598 1.1 christos || h->root.type == bfd_link_hash_defweak) 2599 1.1 christos && !BFINFDPIC_SYM_LOCAL (info, h)) 2600 1.1 christos { 2601 1.1 christos osec = sec = NULL; 2602 1.1 christos relocation = 0; 2603 1.1 christos } 2604 1.1 christos 2605 1.1 christos switch (r_type) 2606 1.1 christos { 2607 1.1.1.7 christos case R_BFIN_PCREL24: 2608 1.1 christos case R_BFIN_PCREL24_JUMP_L: 2609 1.1 christos case R_BFIN_BYTE4_DATA: 2610 1.1 christos if (! IS_FDPIC (output_bfd)) 2611 1.1 christos goto non_fdpic; 2612 1.1 christos /* Fall through. */ 2613 1.1 christos 2614 1.1 christos case R_BFIN_GOT17M4: 2615 1.1 christos case R_BFIN_GOTHI: 2616 1.1 christos case R_BFIN_GOTLO: 2617 1.1 christos case R_BFIN_FUNCDESC_GOT17M4: 2618 1.1 christos case R_BFIN_FUNCDESC_GOTHI: 2619 1.1 christos case R_BFIN_FUNCDESC_GOTLO: 2620 1.1 christos case R_BFIN_GOTOFF17M4: 2621 1.1 christos case R_BFIN_GOTOFFHI: 2622 1.1 christos case R_BFIN_GOTOFFLO: 2623 1.1.1.9 christos case R_BFIN_FUNCDESC_GOTOFF17M4: 2624 1.1.1.9 christos case R_BFIN_FUNCDESC_GOTOFFHI: 2625 1.1.1.9 christos case R_BFIN_FUNCDESC_GOTOFFLO: 2626 1.1 christos case R_BFIN_FUNCDESC: 2627 1.1 christos case R_BFIN_FUNCDESC_VALUE: 2628 1.1 christos if ((input_section->flags & SEC_ALLOC) == 0) 2629 1.1 christos break; 2630 1.1 christos 2631 1.1 christos if (h != NULL) 2632 1.1 christos picrel = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info 2633 1.1 christos (info), input_bfd, h, 2634 1.1 christos orig_addend, INSERT); 2635 1.1 christos else 2636 1.1 christos /* In order to find the entry we created before, we must 2637 1.1 christos use the original addend, not the one that may have been 2638 1.1.1.10 christos modified by _bfd_elf_rela_local_sym(). */ 2639 1.1 christos picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info 2640 1.1 christos (info), input_bfd, r_symndx, 2641 1.1 christos orig_addend, INSERT); 2642 1.1 christos if (! picrel) 2643 1.1 christos return false; 2644 1.1.1.7 christos 2645 1.1.1.7 christos if (!_bfinfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info, 2646 1.1.1.8 christos osec, sym, 2647 1.1.1.8 christos rel->r_addend)) 2648 1.1.1.8 christos { 2649 1.1.1.10 christos _bfd_error_handler 2650 1.1 christos /* xgettext:c-format */ 2651 1.1 christos (_("%pB: relocation at `%pA+%#" PRIx64 "' " 2652 1.1 christos "references symbol `%s' with nonzero addend"), 2653 1.1 christos input_bfd, input_section, (uint64_t) rel->r_offset, name); 2654 1.1 christos return false; 2655 1.1 christos 2656 1.1 christos } 2657 1.1 christos 2658 1.1.1.2 christos break; 2659 1.1.1.2 christos 2660 1.1.1.2 christos default: 2661 1.1 christos non_fdpic: 2662 1.1 christos picrel = NULL; 2663 1.1 christos if (h && ! BFINFDPIC_SYM_LOCAL (info, h) 2664 1.1 christos && _bfd_elf_section_offset (output_bfd, info, input_section, 2665 1.1.1.10 christos rel->r_offset) != (bfd_vma) -1) 2666 1.1 christos { 2667 1.1 christos info->callbacks->warning 2668 1.1 christos (info, _("relocation references symbol not defined in the module"), 2669 1.1 christos name, input_bfd, input_section, rel->r_offset); 2670 1.1 christos return false; 2671 1.1 christos } 2672 1.1 christos break; 2673 1.1 christos } 2674 1.1 christos 2675 1.1 christos switch (r_type) 2676 1.1 christos { 2677 1.1 christos case R_BFIN_PCREL24: 2678 1.1 christos case R_BFIN_PCREL24_JUMP_L: 2679 1.1 christos check_segment[0] = isec_segment; 2680 1.1 christos if (! IS_FDPIC (output_bfd)) 2681 1.1 christos check_segment[1] = isec_segment; 2682 1.1 christos else if (picrel->plt) 2683 1.1 christos { 2684 1.1 christos relocation = bfinfdpic_plt_section (info)->output_section->vma 2685 1.1 christos + bfinfdpic_plt_section (info)->output_offset 2686 1.1 christos + picrel->plt_entry; 2687 1.1 christos check_segment[1] = plt_segment; 2688 1.1 christos } 2689 1.1 christos /* We don't want to warn on calls to undefined weak symbols, 2690 1.1 christos as calls to them must be protected by non-NULL tests 2691 1.1 christos anyway, and unprotected calls would invoke undefined 2692 1.1 christos behavior. */ 2693 1.1 christos else if (picrel->symndx == -1 2694 1.1 christos && picrel->d.h->root.type == bfd_link_hash_undefweak) 2695 1.1 christos check_segment[1] = check_segment[0]; 2696 1.1 christos else 2697 1.1 christos check_segment[1] = sec 2698 1.1 christos ? _bfinfdpic_osec_to_segment (output_bfd, sec->output_section) 2699 1.1 christos : (unsigned)-1; 2700 1.1 christos break; 2701 1.1 christos 2702 1.1 christos case R_BFIN_GOT17M4: 2703 1.1 christos case R_BFIN_GOTHI: 2704 1.1 christos case R_BFIN_GOTLO: 2705 1.1 christos relocation = picrel->got_entry; 2706 1.1 christos check_segment[0] = check_segment[1] = got_segment; 2707 1.1 christos break; 2708 1.1 christos 2709 1.1 christos case R_BFIN_FUNCDESC_GOT17M4: 2710 1.1 christos case R_BFIN_FUNCDESC_GOTHI: 2711 1.1 christos case R_BFIN_FUNCDESC_GOTLO: 2712 1.1 christos relocation = picrel->fdgot_entry; 2713 1.1 christos check_segment[0] = check_segment[1] = got_segment; 2714 1.1 christos break; 2715 1.1 christos 2716 1.1 christos case R_BFIN_GOTOFFHI: 2717 1.1 christos case R_BFIN_GOTOFF17M4: 2718 1.1 christos case R_BFIN_GOTOFFLO: 2719 1.1 christos relocation -= bfinfdpic_got_section (info)->output_section->vma 2720 1.1 christos + bfinfdpic_got_section (info)->output_offset 2721 1.1 christos + bfinfdpic_got_initial_offset (info); 2722 1.1 christos check_segment[0] = got_segment; 2723 1.1 christos check_segment[1] = sec 2724 1.1 christos ? _bfinfdpic_osec_to_segment (output_bfd, sec->output_section) 2725 1.1 christos : (unsigned)-1; 2726 1.1 christos break; 2727 1.1 christos 2728 1.1 christos case R_BFIN_FUNCDESC_GOTOFF17M4: 2729 1.1 christos case R_BFIN_FUNCDESC_GOTOFFHI: 2730 1.1 christos case R_BFIN_FUNCDESC_GOTOFFLO: 2731 1.1.1.10 christos relocation = picrel->fd_entry; 2732 1.1.1.10 christos check_segment[0] = check_segment[1] = got_segment; 2733 1.1.1.10 christos break; 2734 1.1.1.10 christos 2735 1.1 christos case R_BFIN_FUNCDESC: 2736 1.1.1.10 christos if ((input_section->flags & SEC_ALLOC) != 0) 2737 1.1.1.10 christos { 2738 1.1.1.10 christos int dynindx; 2739 1.1.1.10 christos bfd_vma addend = rel->r_addend; 2740 1.1.1.10 christos 2741 1.1.1.10 christos if (! (h && h->root.type == bfd_link_hash_undefweak 2742 1.1.1.10 christos && BFINFDPIC_SYM_LOCAL (info, h))) 2743 1.1.1.10 christos { 2744 1.1.1.10 christos /* If the symbol is dynamic and there may be dynamic 2745 1.1.1.10 christos symbol resolution because we are or are linked with a 2746 1.1.1.10 christos shared library, emit a FUNCDESC relocation such that 2747 1.1.1.10 christos the dynamic linker will allocate the function 2748 1.1.1.10 christos descriptor. If the symbol needs a non-local function 2749 1.1.1.10 christos descriptor but binds locally (e.g., its visibility is 2750 1.1.1.10 christos protected, emit a dynamic relocation decayed to 2751 1.1.1.10 christos section+offset. */ 2752 1.1.1.10 christos if (h && ! BFINFDPIC_FUNCDESC_LOCAL (info, h) 2753 1.1.1.10 christos && BFINFDPIC_SYM_LOCAL (info, h) 2754 1.1.1.10 christos && !bfd_link_pde (info)) 2755 1.1.1.10 christos { 2756 1.1.1.10 christos dynindx = elf_section_data (h->root.u.def.section 2757 1.1.1.10 christos ->output_section)->dynindx; 2758 1.1.1.10 christos addend += h->root.u.def.section->output_offset 2759 1.1.1.10 christos + h->root.u.def.value; 2760 1.1.1.10 christos } 2761 1.1.1.10 christos else if (h && ! BFINFDPIC_FUNCDESC_LOCAL (info, h)) 2762 1.1.1.10 christos { 2763 1.1.1.10 christos if (addend) 2764 1.1.1.10 christos { 2765 1.1.1.10 christos info->callbacks->warning 2766 1.1.1.10 christos (info, _("R_BFIN_FUNCDESC references dynamic symbol with nonzero addend"), 2767 1.1.1.10 christos name, input_bfd, input_section, rel->r_offset); 2768 1.1.1.10 christos return false; 2769 1.1.1.10 christos } 2770 1.1.1.10 christos dynindx = h->dynindx; 2771 1.1.1.10 christos } 2772 1.1.1.10 christos else 2773 1.1.1.10 christos { 2774 1.1.1.10 christos /* Otherwise, we know we have a private function 2775 1.1.1.10 christos descriptor, so reference it directly. */ 2776 1.1.1.10 christos BFD_ASSERT (picrel->privfd); 2777 1.1.1.10 christos r_type = R_BFIN_BYTE4_DATA; 2778 1.1.1.10 christos dynindx = elf_section_data (bfinfdpic_got_section (info) 2779 1.1 christos ->output_section)->dynindx; 2780 1.1.1.10 christos addend = bfinfdpic_got_section (info)->output_offset 2781 1.1.1.10 christos + bfinfdpic_got_initial_offset (info) 2782 1.1.1.10 christos + picrel->fd_entry; 2783 1.1.1.10 christos } 2784 1.1.1.10 christos 2785 1.1.1.10 christos /* If there is room for dynamic symbol resolution, emit 2786 1.1.1.10 christos the dynamic relocation. However, if we're linking an 2787 1.1.1.10 christos executable at a fixed location, we won't have emitted a 2788 1.1.1.10 christos dynamic symbol entry for the got section, so idx will 2789 1.1.1.10 christos be zero, which means we can and should compute the 2790 1.1 christos address of the private descriptor ourselves. */ 2791 1.1.1.10 christos if (bfd_link_pde (info) 2792 1.1.1.10 christos && (!h || BFINFDPIC_FUNCDESC_LOCAL (info, h))) 2793 1.1.1.10 christos { 2794 1.1.1.10 christos bfd_vma offset; 2795 1.1.1.10 christos 2796 1.1.1.10 christos addend += bfinfdpic_got_section (info)->output_section->vma; 2797 1.1.1.10 christos if ((bfd_section_flags (input_section->output_section) 2798 1.1.1.10 christos & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 2799 1.1.1.10 christos { 2800 1.1.1.10 christos if (_bfinfdpic_osec_readonly_p (output_bfd, 2801 1.1.1.10 christos input_section 2802 1.1.1.10 christos ->output_section)) 2803 1.1.1.10 christos { 2804 1.1.1.10 christos info->callbacks->warning 2805 1.1.1.10 christos (info, 2806 1.1.1.10 christos _("cannot emit fixups in read-only section"), 2807 1.1.1.10 christos name, input_bfd, input_section, rel->r_offset); 2808 1.1.1.10 christos return false; 2809 1.1 christos } 2810 1.1.1.10 christos 2811 1.1.1.10 christos offset = _bfd_elf_section_offset 2812 1.1.1.10 christos (output_bfd, info, 2813 1.1.1.10 christos input_section, rel->r_offset); 2814 1.1.1.10 christos 2815 1.1.1.10 christos if (offset != (bfd_vma)-1) 2816 1.1.1.10 christos _bfinfdpic_add_rofixup (output_bfd, 2817 1.1.1.10 christos bfinfdpic_gotfixup_section 2818 1.1.1.10 christos (info), 2819 1.1.1.10 christos offset + input_section 2820 1.1.1.10 christos ->output_section->vma 2821 1.1.1.10 christos + input_section->output_offset, 2822 1.1.1.10 christos picrel); 2823 1.1.1.10 christos } 2824 1.1 christos } 2825 1.1.1.10 christos else if ((bfd_section_flags (input_section->output_section) 2826 1.1.1.10 christos & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 2827 1.1.1.10 christos { 2828 1.1.1.10 christos bfd_vma offset; 2829 1.1.1.10 christos 2830 1.1.1.10 christos if (_bfinfdpic_osec_readonly_p (output_bfd, 2831 1.1.1.10 christos input_section 2832 1.1.1.10 christos ->output_section)) 2833 1.1.1.10 christos { 2834 1.1.1.10 christos info->callbacks->warning 2835 1.1.1.10 christos (info, 2836 1.1.1.10 christos _("cannot emit dynamic relocations in read-only section"), 2837 1.1.1.10 christos name, input_bfd, input_section, rel->r_offset); 2838 1.1.1.10 christos return false; 2839 1.1.1.10 christos } 2840 1.1.1.10 christos offset = _bfd_elf_section_offset (output_bfd, info, 2841 1.1 christos input_section, rel->r_offset); 2842 1.1 christos 2843 1.1 christos if (offset != (bfd_vma)-1) 2844 1.1.1.10 christos _bfinfdpic_add_dyn_reloc (output_bfd, 2845 1.1.1.10 christos bfinfdpic_gotrel_section (info), 2846 1.1.1.10 christos offset + input_section 2847 1.1.1.10 christos ->output_section->vma 2848 1.1.1.10 christos + input_section->output_offset, 2849 1.1.1.10 christos r_type, 2850 1.1 christos dynindx, addend, picrel); 2851 1.1.1.10 christos } 2852 1.1.1.10 christos else 2853 1.1.1.10 christos addend += bfinfdpic_got_section (info)->output_section->vma; 2854 1.1.1.10 christos } 2855 1.1 christos 2856 1.1 christos /* We want the addend in-place because dynamic 2857 1.1 christos relocations are REL. Setting relocation to it should 2858 1.1 christos arrange for it to be installed. */ 2859 1.1 christos relocation = addend - rel->r_addend; 2860 1.1 christos } 2861 1.1 christos check_segment[0] = check_segment[1] = got_segment; 2862 1.1 christos break; 2863 1.1 christos 2864 1.1 christos case R_BFIN_BYTE4_DATA: 2865 1.1 christos if (! IS_FDPIC (output_bfd)) 2866 1.1 christos { 2867 1.1 christos check_segment[0] = check_segment[1] = -1; 2868 1.1 christos break; 2869 1.1 christos } 2870 1.1 christos /* Fall through. */ 2871 1.1 christos case R_BFIN_FUNCDESC_VALUE: 2872 1.1 christos { 2873 1.1 christos int dynindx; 2874 1.1 christos bfd_vma addend = rel->r_addend; 2875 1.1 christos bfd_vma offset; 2876 1.1 christos offset = _bfd_elf_section_offset (output_bfd, info, 2877 1.1 christos input_section, rel->r_offset); 2878 1.1 christos 2879 1.1 christos /* If the symbol is dynamic but binds locally, use 2880 1.1 christos section+offset. */ 2881 1.1 christos if (h && ! BFINFDPIC_SYM_LOCAL (info, h)) 2882 1.1 christos { 2883 1.1.1.10 christos if (addend && r_type == R_BFIN_FUNCDESC_VALUE) 2884 1.1 christos { 2885 1.1 christos info->callbacks->warning 2886 1.1 christos (info, _("R_BFIN_FUNCDESC_VALUE references dynamic symbol with nonzero addend"), 2887 1.1 christos name, input_bfd, input_section, rel->r_offset); 2888 1.1 christos return false; 2889 1.1 christos } 2890 1.1 christos dynindx = h->dynindx; 2891 1.1 christos } 2892 1.1 christos else 2893 1.1 christos { 2894 1.1 christos if (h) 2895 1.1 christos addend += h->root.u.def.value; 2896 1.1 christos else 2897 1.1 christos addend += sym->st_value; 2898 1.1 christos if (osec) 2899 1.1 christos addend += osec->output_offset; 2900 1.1 christos if (osec && osec->output_section 2901 1.1 christos && ! bfd_is_abs_section (osec->output_section) 2902 1.1 christos && ! bfd_is_und_section (osec->output_section)) 2903 1.1 christos dynindx = elf_section_data (osec->output_section)->dynindx; 2904 1.1 christos else 2905 1.1 christos dynindx = 0; 2906 1.1 christos } 2907 1.1.1.6 christos 2908 1.1 christos /* If we're linking an executable at a fixed address, we 2909 1.1 christos can omit the dynamic relocation as long as the symbol 2910 1.1 christos is defined in the current link unit (which is implied 2911 1.1 christos by its output section not being NULL). */ 2912 1.1 christos if (bfd_link_pde (info) 2913 1.1.1.9 christos && (!h || BFINFDPIC_SYM_LOCAL (info, h))) 2914 1.1 christos { 2915 1.1 christos if (osec) 2916 1.1 christos addend += osec->output_section->vma; 2917 1.1 christos if (IS_FDPIC (input_bfd) 2918 1.1 christos && (bfd_section_flags (input_section->output_section) 2919 1.1 christos & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 2920 1.1 christos { 2921 1.1 christos if (_bfinfdpic_osec_readonly_p (output_bfd, 2922 1.1 christos input_section 2923 1.1 christos ->output_section)) 2924 1.1.1.10 christos { 2925 1.1 christos info->callbacks->warning 2926 1.1 christos (info, 2927 1.1 christos _("cannot emit fixups in read-only section"), 2928 1.1 christos name, input_bfd, input_section, rel->r_offset); 2929 1.1 christos return false; 2930 1.1 christos } 2931 1.1 christos if (!h || h->root.type != bfd_link_hash_undefweak) 2932 1.1 christos { 2933 1.1 christos if (offset != (bfd_vma)-1) 2934 1.1 christos { 2935 1.1 christos _bfinfdpic_add_rofixup (output_bfd, 2936 1.1 christos bfinfdpic_gotfixup_section 2937 1.1 christos (info), 2938 1.1 christos offset + input_section 2939 1.1 christos ->output_section->vma 2940 1.1 christos + input_section->output_offset, 2941 1.1 christos picrel); 2942 1.1 christos 2943 1.1 christos if (r_type == R_BFIN_FUNCDESC_VALUE) 2944 1.1 christos _bfinfdpic_add_rofixup 2945 1.1 christos (output_bfd, 2946 1.1 christos bfinfdpic_gotfixup_section (info), 2947 1.1 christos offset + input_section->output_section->vma 2948 1.1 christos + input_section->output_offset + 4, picrel); 2949 1.1 christos } 2950 1.1.1.9 christos } 2951 1.1 christos } 2952 1.1 christos } 2953 1.1 christos else 2954 1.1 christos { 2955 1.1 christos if ((bfd_section_flags (input_section->output_section) 2956 1.1 christos & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 2957 1.1 christos { 2958 1.1 christos if (_bfinfdpic_osec_readonly_p (output_bfd, 2959 1.1 christos input_section 2960 1.1 christos ->output_section)) 2961 1.1.1.10 christos { 2962 1.1 christos info->callbacks->warning 2963 1.1 christos (info, 2964 1.1 christos _("cannot emit dynamic relocations in read-only section"), 2965 1.1 christos name, input_bfd, input_section, rel->r_offset); 2966 1.1 christos return false; 2967 1.1 christos } 2968 1.1 christos 2969 1.1 christos if (offset != (bfd_vma)-1) 2970 1.1 christos _bfinfdpic_add_dyn_reloc (output_bfd, 2971 1.1 christos bfinfdpic_gotrel_section (info), 2972 1.1 christos offset 2973 1.1 christos + input_section->output_section->vma 2974 1.1 christos + input_section->output_offset, 2975 1.1 christos r_type, dynindx, addend, picrel); 2976 1.1 christos } 2977 1.1 christos else if (osec) 2978 1.1 christos addend += osec->output_section->vma; 2979 1.1 christos /* We want the addend in-place because dynamic 2980 1.1 christos relocations are REL. Setting relocation to it 2981 1.1 christos should arrange for it to be installed. */ 2982 1.1 christos relocation = addend - rel->r_addend; 2983 1.1 christos } 2984 1.1 christos 2985 1.1.1.6 christos if (r_type == R_BFIN_FUNCDESC_VALUE) 2986 1.1 christos { 2987 1.1 christos /* If we've omitted the dynamic relocation, just emit 2988 1.1 christos the fixed addresses of the symbol and of the local 2989 1.1 christos GOT base offset. */ 2990 1.1 christos if (bfd_link_pde (info) 2991 1.1 christos && (!h || BFINFDPIC_SYM_LOCAL (info, h))) 2992 1.1 christos bfd_put_32 (output_bfd, 2993 1.1 christos bfinfdpic_got_section (info)->output_section->vma 2994 1.1 christos + bfinfdpic_got_section (info)->output_offset 2995 1.1 christos + bfinfdpic_got_initial_offset (info), 2996 1.1 christos contents + rel->r_offset + 4); 2997 1.1 christos else 2998 1.1 christos /* A function descriptor used for lazy or local 2999 1.1 christos resolving is initialized such that its high word 3000 1.1 christos contains the output section index in which the 3001 1.1 christos PLT entries are located, and the low word 3002 1.1 christos contains the offset of the lazy PLT entry entry 3003 1.1 christos point into that section. */ 3004 1.1 christos bfd_put_32 (output_bfd, 3005 1.1 christos h && ! BFINFDPIC_SYM_LOCAL (info, h) 3006 1.1 christos ? 0 3007 1.1 christos : _bfinfdpic_osec_to_segment (output_bfd, 3008 1.1 christos sec 3009 1.1 christos ->output_section), 3010 1.1 christos contents + rel->r_offset + 4); 3011 1.1 christos } 3012 1.1 christos } 3013 1.1 christos check_segment[0] = check_segment[1] = got_segment; 3014 1.1 christos break; 3015 1.1 christos 3016 1.1 christos default: 3017 1.1 christos check_segment[0] = isec_segment; 3018 1.1 christos check_segment[1] = sec 3019 1.1 christos ? _bfinfdpic_osec_to_segment (output_bfd, sec->output_section) 3020 1.1 christos : (unsigned)-1; 3021 1.1 christos break; 3022 1.1 christos } 3023 1.1 christos 3024 1.1 christos if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd)) 3025 1.1 christos { 3026 1.1 christos #if 1 /* If you take this out, remove the #error from fdpic-static-6.d 3027 1.1 christos in the ld testsuite. */ 3028 1.1.1.9 christos /* This helps catch problems in GCC while we can't do more 3029 1.1.1.9 christos than static linking. The idea is to test whether the 3030 1.1.1.9 christos input file basename is crt0.o only once. */ 3031 1.1.1.9 christos if (silence_segment_error == 1) 3032 1.1.1.9 christos silence_segment_error = 3033 1.1 christos (strlen (bfd_get_filename (input_bfd)) == 6 3034 1.1 christos && filename_cmp (bfd_get_filename (input_bfd), "crt0.o") == 0) 3035 1.1 christos || (strlen (bfd_get_filename (input_bfd)) > 6 3036 1.1 christos && filename_cmp (bfd_get_filename (input_bfd) 3037 1.1 christos + strlen (bfd_get_filename (input_bfd)) - 7, 3038 1.1 christos "/crt0.o") == 0) 3039 1.1 christos ? -1 : 0; 3040 1.1 christos #endif 3041 1.1 christos if (!silence_segment_error 3042 1.1 christos /* We don't want duplicate errors for undefined 3043 1.1.1.6 christos symbols. */ 3044 1.1 christos && !(picrel && picrel->symndx == -1 3045 1.1 christos && picrel->d.h->root.type == bfd_link_hash_undefined)) 3046 1.1 christos info->callbacks->warning 3047 1.1.1.6 christos (info, 3048 1.1.1.10 christos bfd_link_pic (info) 3049 1.1 christos ? _("relocations between different segments are not supported") 3050 1.1 christos : _("warning: relocation references a different segment"), 3051 1.1 christos name, input_bfd, input_section, rel->r_offset); 3052 1.1 christos if (!silence_segment_error && bfd_link_pic (info)) 3053 1.1 christos return false; 3054 1.1 christos elf_elfheader (output_bfd)->e_flags |= EF_BFIN_PIC; 3055 1.1 christos } 3056 1.1 christos 3057 1.1 christos switch (r_type) 3058 1.1 christos { 3059 1.1 christos case R_BFIN_GOTOFFHI: 3060 1.1 christos /* We need the addend to be applied before we shift the 3061 1.1 christos value right. */ 3062 1.1 christos relocation += rel->r_addend; 3063 1.1 christos /* Fall through. */ 3064 1.1 christos case R_BFIN_GOTHI: 3065 1.1 christos case R_BFIN_FUNCDESC_GOTHI: 3066 1.1 christos case R_BFIN_FUNCDESC_GOTOFFHI: 3067 1.1 christos relocation >>= 16; 3068 1.1 christos /* Fall through. */ 3069 1.1 christos 3070 1.1 christos case R_BFIN_GOTLO: 3071 1.1 christos case R_BFIN_FUNCDESC_GOTLO: 3072 1.1 christos case R_BFIN_GOTOFFLO: 3073 1.1 christos case R_BFIN_FUNCDESC_GOTOFFLO: 3074 1.1 christos relocation &= 0xffff; 3075 1.1 christos break; 3076 1.1 christos 3077 1.1 christos default: 3078 1.1 christos break; 3079 1.1 christos } 3080 1.1 christos 3081 1.1 christos switch (r_type) 3082 1.1 christos { 3083 1.1 christos case R_BFIN_PCREL24: 3084 1.1 christos case R_BFIN_PCREL24_JUMP_L: 3085 1.1 christos if (! IS_FDPIC (output_bfd) || ! picrel->plt) 3086 1.1 christos break; 3087 1.1 christos /* Fall through. */ 3088 1.1 christos 3089 1.1 christos /* When referencing a GOT entry, a function descriptor or a 3090 1.1 christos PLT, we don't want the addend to apply to the reference, 3091 1.1 christos but rather to the referenced symbol. The actual entry 3092 1.1 christos will have already been created taking the addend into 3093 1.1 christos account, so cancel it out here. */ 3094 1.1 christos case R_BFIN_GOT17M4: 3095 1.1 christos case R_BFIN_GOTHI: 3096 1.1 christos case R_BFIN_GOTLO: 3097 1.1 christos case R_BFIN_FUNCDESC_GOT17M4: 3098 1.1 christos case R_BFIN_FUNCDESC_GOTHI: 3099 1.1 christos case R_BFIN_FUNCDESC_GOTLO: 3100 1.1 christos case R_BFIN_FUNCDESC_GOTOFF17M4: 3101 1.1 christos case R_BFIN_FUNCDESC_GOTOFFHI: 3102 1.1 christos case R_BFIN_FUNCDESC_GOTOFFLO: 3103 1.1 christos /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF17M4 3104 1.1 christos here, since we do want to apply the addend to the others. 3105 1.1 christos Note that we've applied the addend to GOTOFFHI before we 3106 1.1 christos shifted it right. */ 3107 1.1 christos case R_BFIN_GOTOFFHI: 3108 1.1 christos relocation -= rel->r_addend; 3109 1.1 christos break; 3110 1.1 christos 3111 1.1 christos default: 3112 1.1 christos break; 3113 1.1 christos } 3114 1.1 christos 3115 1.1 christos r = bfin_final_link_relocate (rel, howto, input_bfd, input_section, 3116 1.1 christos contents, rel->r_offset, 3117 1.1 christos relocation, rel->r_addend); 3118 1.1 christos 3119 1.1 christos if (r != bfd_reloc_ok) 3120 1.1 christos { 3121 1.1.1.6 christos const char * msg = (const char *) NULL; 3122 1.1 christos 3123 1.1 christos switch (r) 3124 1.1 christos { 3125 1.1 christos case bfd_reloc_overflow: 3126 1.1 christos (*info->callbacks->reloc_overflow) 3127 1.1.1.6 christos (info, (h ? &h->root : NULL), name, howto->name, 3128 1.1.1.10 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 3129 1.1 christos break; 3130 1.1 christos 3131 1.1 christos case bfd_reloc_undefined: 3132 1.1 christos (*info->callbacks->undefined_symbol) 3133 1.1 christos (info, name, input_bfd, input_section, rel->r_offset, true); 3134 1.1 christos break; 3135 1.1 christos 3136 1.1 christos case bfd_reloc_outofrange: 3137 1.1 christos msg = _("internal error: out of range error"); 3138 1.1 christos break; 3139 1.1 christos 3140 1.1 christos case bfd_reloc_notsupported: 3141 1.1 christos msg = _("internal error: unsupported relocation error"); 3142 1.1 christos break; 3143 1.1 christos 3144 1.1 christos case bfd_reloc_dangerous: 3145 1.1 christos msg = _("internal error: dangerous relocation"); 3146 1.1 christos break; 3147 1.1 christos 3148 1.1 christos default: 3149 1.1.1.6 christos msg = _("internal error: unknown error"); 3150 1.1.1.6 christos break; 3151 1.1 christos } 3152 1.1 christos 3153 1.1 christos if (msg) 3154 1.1.1.10 christos (*info->callbacks->warning) (info, msg, name, input_bfd, 3155 1.1 christos input_section, rel->r_offset); 3156 1.1 christos } 3157 1.1 christos } 3158 1.1 christos 3159 1.1.1.10 christos return true; 3160 1.1 christos } 3161 1.1 christos 3162 1.1 christos /* We need dynamic symbols for every section, since segments can 3163 1.1 christos relocate independently. */ 3164 1.1 christos static bool 3165 1.1 christos _bfinfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED, 3166 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 3167 1.1 christos asection *p) 3168 1.1 christos { 3169 1.1 christos switch (elf_section_data (p)->this_hdr.sh_type) 3170 1.1 christos { 3171 1.1.1.10 christos case SHT_PROGBITS: 3172 1.1 christos case SHT_NOBITS: 3173 1.1 christos /* If sh_type is yet undecided, assume it could be 3174 1.1 christos SHT_PROGBITS/SHT_NOBITS. */ 3175 1.1 christos case SHT_NULL: 3176 1.1.1.10 christos return false; 3177 1.1 christos 3178 1.1 christos /* There shouldn't be section relative relocations 3179 1.1 christos against any other section. */ 3180 1.1 christos default: 3181 1.1 christos return true; 3182 1.1 christos } 3183 1.1 christos } 3184 1.1.1.10 christos 3185 1.1 christos /* Create a .got section, as well as its additional info field. This 3186 1.1 christos is almost entirely copied from 3187 1.1 christos elflink.c:_bfd_elf_create_got_section(). */ 3188 1.1 christos 3189 1.1 christos static bool 3190 1.1 christos _bfin_create_got_section (bfd *abfd, struct bfd_link_info *info) 3191 1.1 christos { 3192 1.1 christos flagword flags, pltflags; 3193 1.1 christos asection *s; 3194 1.1.1.7 christos struct elf_link_hash_entry *h; 3195 1.1.1.2 christos const struct elf_backend_data *bed = get_elf_backend_data (abfd); 3196 1.1.1.10 christos int ptralign; 3197 1.1 christos 3198 1.1 christos /* This function may be called more than once. */ 3199 1.1 christos s = elf_hash_table (info)->sgot; 3200 1.1 christos if (s != NULL) 3201 1.1 christos return true; 3202 1.1 christos 3203 1.1 christos /* Machine specific: although pointers are 32-bits wide, we want the 3204 1.1 christos GOT to be aligned to a 64-bit boundary, such that function 3205 1.1 christos descriptors in it can be accessed with 64-bit loads and 3206 1.1 christos stores. */ 3207 1.1 christos ptralign = 3; 3208 1.1.1.2 christos 3209 1.1.1.7 christos flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 3210 1.1 christos | SEC_LINKER_CREATED); 3211 1.1.1.9 christos pltflags = flags; 3212 1.1.1.10 christos 3213 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); 3214 1.1 christos elf_hash_table (info)->sgot = s; 3215 1.1 christos if (s == NULL 3216 1.1 christos || !bfd_set_section_alignment (s, ptralign)) 3217 1.1 christos return false; 3218 1.1 christos 3219 1.1 christos if (bed->want_got_sym) 3220 1.1 christos { 3221 1.1 christos /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got 3222 1.1 christos (or .got.plt) section. We don't do this in the linker script 3223 1.1.1.10 christos because we don't want to define the symbol if we are not creating 3224 1.1 christos a global offset table. */ 3225 1.1 christos h = _bfd_elf_define_linkage_sym (abfd, info, s, "__GLOBAL_OFFSET_TABLE_"); 3226 1.1 christos elf_hash_table (info)->hgot = h; 3227 1.1 christos if (h == NULL) 3228 1.1.1.10 christos return false; 3229 1.1 christos 3230 1.1 christos /* Machine-specific: we want the symbol for executables as 3231 1.1 christos well. */ 3232 1.1 christos if (! bfd_elf_link_record_dynamic_symbol (info, h)) 3233 1.1 christos return false; 3234 1.1 christos } 3235 1.1 christos 3236 1.1 christos /* The first bit of the global offset table is the header. */ 3237 1.1 christos s->size += bed->got_header_size; 3238 1.1 christos 3239 1.1 christos /* This is the machine-specific part. Create and initialize section 3240 1.1 christos data for the got. */ 3241 1.1 christos if (IS_FDPIC (abfd)) 3242 1.1 christos { 3243 1.1.1.10 christos bfinfdpic_relocs_info (info) = htab_try_create (1, 3244 1.1 christos bfinfdpic_relocs_info_hash, 3245 1.1.1.2 christos bfinfdpic_relocs_info_eq, 3246 1.1.1.2 christos (htab_del) NULL); 3247 1.1 christos if (! bfinfdpic_relocs_info (info)) 3248 1.1.1.9 christos return false; 3249 1.1.1.10 christos 3250 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rel.got", 3251 1.1 christos (flags | SEC_READONLY)); 3252 1.1 christos if (s == NULL 3253 1.1 christos || !bfd_set_section_alignment (s, 2)) 3254 1.1.1.2 christos return false; 3255 1.1.1.2 christos 3256 1.1 christos bfinfdpic_gotrel_section (info) = s; 3257 1.1.1.9 christos 3258 1.1.1.10 christos /* Machine-specific. */ 3259 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rofixup", 3260 1.1 christos (flags | SEC_READONLY)); 3261 1.1 christos if (s == NULL 3262 1.1 christos || !bfd_set_section_alignment (s, 2)) 3263 1.1 christos return false; 3264 1.1 christos 3265 1.1 christos bfinfdpic_gotfixup_section (info) = s; 3266 1.1 christos } 3267 1.1 christos 3268 1.1 christos pltflags |= SEC_CODE; 3269 1.1.1.2 christos if (bed->plt_not_loaded) 3270 1.1 christos pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); 3271 1.1.1.9 christos if (bed->plt_readonly) 3272 1.1.1.10 christos pltflags |= SEC_READONLY; 3273 1.1 christos 3274 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); 3275 1.1 christos if (s == NULL 3276 1.1 christos || !bfd_set_section_alignment (s, bed->plt_alignment)) 3277 1.1 christos return false; 3278 1.1 christos /* Blackfin-specific: remember it. */ 3279 1.1 christos bfinfdpic_plt_section (info) = s; 3280 1.1 christos 3281 1.1 christos if (bed->want_plt_sym) 3282 1.1 christos { 3283 1.1 christos /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the 3284 1.1.1.10 christos .plt section. */ 3285 1.1.1.10 christos struct bfd_link_hash_entry *bh = NULL; 3286 1.1 christos 3287 1.1 christos if (! (_bfd_generic_link_add_one_symbol 3288 1.1 christos (info, abfd, "__PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL, 3289 1.1 christos false, get_elf_backend_data (abfd)->collect, &bh))) 3290 1.1.1.6 christos return false; 3291 1.1 christos h = (struct elf_link_hash_entry *) bh; 3292 1.1.1.10 christos h->def_regular = 1; 3293 1.1 christos h->type = STT_OBJECT; 3294 1.1 christos 3295 1.1 christos if (! bfd_link_executable (info) 3296 1.1.1.2 christos && ! bfd_elf_link_record_dynamic_symbol (info, h)) 3297 1.1.1.2 christos return false; 3298 1.1 christos } 3299 1.1.1.9 christos 3300 1.1.1.10 christos /* Blackfin-specific: we want rel relocations for the plt. */ 3301 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rel.plt", 3302 1.1 christos flags | SEC_READONLY); 3303 1.1 christos if (s == NULL 3304 1.1.1.10 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 3305 1.1 christos return false; 3306 1.1 christos /* Blackfin-specific: remember it. */ 3307 1.1 christos bfinfdpic_pltrel_section (info) = s; 3308 1.1 christos 3309 1.1 christos return true; 3310 1.1.1.10 christos } 3311 1.1 christos 3312 1.1 christos /* Make sure the got and plt sections exist, and that our pointers in 3313 1.1 christos the link hash table point to them. */ 3314 1.1 christos 3315 1.1 christos static bool 3316 1.1 christos elf32_bfinfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) 3317 1.1 christos { 3318 1.1 christos /* This is mostly copied from 3319 1.1 christos elflink.c:_bfd_elf_create_dynamic_sections(). */ 3320 1.1 christos flagword flags; 3321 1.1 christos asection *s; 3322 1.1 christos const struct elf_backend_data *bed = get_elf_backend_data (abfd); 3323 1.1 christos 3324 1.1 christos flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 3325 1.1 christos | SEC_LINKER_CREATED); 3326 1.1 christos 3327 1.1.1.10 christos /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and 3328 1.1 christos .rel[a].bss sections. */ 3329 1.1 christos 3330 1.1 christos /* Blackfin-specific: we want to create the GOT in the Blackfin way. */ 3331 1.1 christos if (! _bfin_create_got_section (abfd, info)) 3332 1.1 christos return false; 3333 1.1 christos 3334 1.1 christos /* Blackfin-specific: make sure we created everything we wanted. */ 3335 1.1 christos BFD_ASSERT (bfinfdpic_got_section (info) && bfinfdpic_gotrel_section (info) 3336 1.1 christos /* && bfinfdpic_gotfixup_section (info) */ 3337 1.1 christos && bfinfdpic_plt_section (info) 3338 1.1 christos && bfinfdpic_pltrel_section (info)); 3339 1.1 christos 3340 1.1 christos if (bed->want_dynbss) 3341 1.1 christos { 3342 1.1 christos /* The .dynbss section is a place to put symbols which are defined 3343 1.1.1.2 christos by dynamic objects, are referenced by regular objects, and are 3344 1.1.1.2 christos not functions. We must allocate space for them in the process 3345 1.1 christos image and use a R_*_COPY reloc to tell the dynamic linker to 3346 1.1.1.10 christos initialize them at run time. The linker script puts the .dynbss 3347 1.1 christos section into the .bss section of the final image. */ 3348 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", 3349 1.1.1.2 christos SEC_ALLOC | SEC_LINKER_CREATED); 3350 1.1.1.2 christos if (s == NULL) 3351 1.1.1.2 christos return false; 3352 1.1.1.2 christos 3353 1.1.1.2 christos /* The .rel[a].bss section holds copy relocs. This section is not 3354 1.1.1.2 christos normally needed. We need to create it here, though, so that the 3355 1.1.1.2 christos linker will map it to an output section. We can't just create it 3356 1.1.1.2 christos only if we need it, because we will not know whether we need it 3357 1.1.1.2 christos until we have seen all the input files, and the first time the 3358 1.1.1.2 christos main linker code calls BFD after examining all the input files 3359 1.1.1.6 christos (size_dynamic_sections) the input sections have already been 3360 1.1 christos mapped to the output sections. If the section turns out not to 3361 1.1.1.2 christos be needed, we can discard it later. We will never need this 3362 1.1.1.2 christos section when generating a shared object, since they do not use 3363 1.1.1.2 christos copy relocs. */ 3364 1.1 christos if (! bfd_link_pic (info)) 3365 1.1.1.9 christos { 3366 1.1.1.10 christos s = bfd_make_section_anyway_with_flags (abfd, 3367 1.1 christos ".rela.bss", 3368 1.1 christos flags | SEC_READONLY); 3369 1.1 christos if (s == NULL 3370 1.1.1.10 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 3371 1.1 christos return false; 3372 1.1 christos } 3373 1.1 christos } 3374 1.1 christos 3375 1.1 christos return true; 3376 1.1 christos } 3377 1.1 christos 3378 1.1 christos /* Compute the total GOT size required by each symbol in each range. 3379 1.1 christos Symbols may require up to 4 words in the GOT: an entry pointing to 3380 1.1 christos the symbol, an entry pointing to its function descriptor, and a 3381 1.1 christos private function descriptors taking two words. */ 3382 1.1 christos 3383 1.1 christos static void 3384 1.1 christos _bfinfdpic_count_nontls_entries (struct bfinfdpic_relocs_info *entry, 3385 1.1 christos struct _bfinfdpic_dynamic_got_info *dinfo) 3386 1.1 christos { 3387 1.1 christos /* Allocate space for a GOT entry pointing to the symbol. */ 3388 1.1 christos if (entry->got17m4) 3389 1.1 christos dinfo->got17m4 += 4; 3390 1.1 christos else if (entry->gothilo) 3391 1.1 christos dinfo->gothilo += 4; 3392 1.1 christos else 3393 1.1 christos entry->relocs32--; 3394 1.1 christos entry->relocs32++; 3395 1.1 christos 3396 1.1 christos /* Allocate space for a GOT entry pointing to the function 3397 1.1 christos descriptor. */ 3398 1.1 christos if (entry->fdgot17m4) 3399 1.1 christos dinfo->got17m4 += 4; 3400 1.1 christos else if (entry->fdgothilo) 3401 1.1 christos dinfo->gothilo += 4; 3402 1.1 christos else 3403 1.1 christos entry->relocsfd--; 3404 1.1 christos entry->relocsfd++; 3405 1.1 christos 3406 1.1 christos /* Decide whether we need a PLT entry, a function descriptor in the 3407 1.1 christos GOT, and a lazy PLT entry for this symbol. */ 3408 1.1 christos entry->plt = entry->call 3409 1.1 christos && entry->symndx == -1 && ! BFINFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 3410 1.1 christos && elf_hash_table (dinfo->info)->dynamic_sections_created; 3411 1.1 christos entry->privfd = entry->plt 3412 1.1 christos || entry->fdgoff17m4 || entry->fdgoffhilo 3413 1.1 christos || ((entry->fd || entry->fdgot17m4 || entry->fdgothilo) 3414 1.1 christos && (entry->symndx != -1 3415 1.1 christos || BFINFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))); 3416 1.1 christos entry->lazyplt = entry->privfd 3417 1.1 christos && entry->symndx == -1 && ! BFINFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 3418 1.1 christos && ! (dinfo->info->flags & DF_BIND_NOW) 3419 1.1 christos && elf_hash_table (dinfo->info)->dynamic_sections_created; 3420 1.1 christos 3421 1.1 christos /* Allocate space for a function descriptor. */ 3422 1.1 christos if (entry->fdgoff17m4) 3423 1.1 christos dinfo->fd17m4 += 8; 3424 1.1 christos else if (entry->privfd && entry->plt) 3425 1.1 christos dinfo->fdplt += 8; 3426 1.1 christos else if (entry->privfd) 3427 1.1 christos dinfo->fdhilo += 8; 3428 1.1 christos else 3429 1.1 christos entry->relocsfdv--; 3430 1.1 christos entry->relocsfdv++; 3431 1.1 christos 3432 1.1 christos if (entry->lazyplt) 3433 1.1 christos dinfo->lzplt += LZPLT_NORMAL_SIZE; 3434 1.1 christos } 3435 1.1 christos 3436 1.1 christos /* Compute the number of dynamic relocations and fixups that a symbol 3437 1.1 christos requires, and add (or subtract) from the grand and per-symbol 3438 1.1.1.10 christos totals. */ 3439 1.1 christos 3440 1.1 christos static void 3441 1.1 christos _bfinfdpic_count_relocs_fixups (struct bfinfdpic_relocs_info *entry, 3442 1.1.1.6 christos struct _bfinfdpic_dynamic_got_info *dinfo, 3443 1.1 christos bool subtract) 3444 1.1 christos { 3445 1.1 christos bfd_vma relocs = 0, fixups = 0; 3446 1.1 christos 3447 1.1 christos if (!bfd_link_pde (dinfo->info)) 3448 1.1 christos relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv; 3449 1.1 christos else 3450 1.1 christos { 3451 1.1 christos if (entry->symndx != -1 || BFINFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)) 3452 1.1 christos { 3453 1.1 christos if (entry->symndx != -1 3454 1.1 christos || entry->d.h->root.type != bfd_link_hash_undefweak) 3455 1.1 christos fixups += entry->relocs32 + 2 * entry->relocsfdv; 3456 1.1 christos } 3457 1.1 christos else 3458 1.1 christos relocs += entry->relocs32 + entry->relocsfdv; 3459 1.1 christos 3460 1.1 christos if (entry->symndx != -1 3461 1.1 christos || BFINFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)) 3462 1.1 christos { 3463 1.1 christos if (entry->symndx != -1 3464 1.1 christos || entry->d.h->root.type != bfd_link_hash_undefweak) 3465 1.1 christos fixups += entry->relocsfd; 3466 1.1 christos } 3467 1.1 christos else 3468 1.1 christos relocs += entry->relocsfd; 3469 1.1 christos } 3470 1.1 christos 3471 1.1 christos if (subtract) 3472 1.1 christos { 3473 1.1 christos relocs = - relocs; 3474 1.1 christos fixups = - fixups; 3475 1.1 christos } 3476 1.1 christos 3477 1.1 christos entry->dynrelocs += relocs; 3478 1.1 christos entry->fixups += fixups; 3479 1.1 christos dinfo->relocs += relocs; 3480 1.1 christos dinfo->fixups += fixups; 3481 1.1 christos } 3482 1.1 christos 3483 1.1 christos /* Compute the total GOT and PLT size required by each symbol in each range. * 3484 1.1 christos Symbols may require up to 4 words in the GOT: an entry pointing to 3485 1.1 christos the symbol, an entry pointing to its function descriptor, and a 3486 1.1 christos private function descriptors taking two words. */ 3487 1.1 christos 3488 1.1 christos static int 3489 1.1 christos _bfinfdpic_count_got_plt_entries (void **entryp, void *dinfo_) 3490 1.1 christos { 3491 1.1.1.10 christos struct bfinfdpic_relocs_info *entry = *entryp; 3492 1.1 christos struct _bfinfdpic_dynamic_got_info *dinfo = dinfo_; 3493 1.1 christos 3494 1.1 christos _bfinfdpic_count_nontls_entries (entry, dinfo); 3495 1.1 christos 3496 1.1 christos _bfinfdpic_count_relocs_fixups (entry, dinfo, false); 3497 1.1 christos 3498 1.1 christos return 1; 3499 1.1 christos } 3500 1.1 christos 3501 1.1 christos /* This structure is used to assign offsets to got entries, function 3502 1.1 christos descriptors, plt entries and lazy plt entries. */ 3503 1.1 christos 3504 1.1 christos struct _bfinfdpic_dynamic_got_plt_info 3505 1.1 christos { 3506 1.1 christos /* Summary information collected with _bfinfdpic_count_got_plt_entries. */ 3507 1.1 christos struct _bfinfdpic_dynamic_got_info g; 3508 1.1 christos 3509 1.1 christos /* For each addressable range, we record a MAX (positive) and MIN 3510 1.1 christos (negative) value. CUR is used to assign got entries, and it's 3511 1.1 christos incremented from an initial positive value to MAX, then from MIN 3512 1.1 christos to FDCUR (unless FDCUR wraps around first). FDCUR is used to 3513 1.1 christos assign function descriptors, and it's decreased from an initial 3514 1.1 christos non-positive value to MIN, then from MAX down to CUR (unless CUR 3515 1.1 christos wraps around first). All of MIN, MAX, CUR and FDCUR always point 3516 1.1 christos to even words. ODD, if non-zero, indicates an odd word to be 3517 1.1 christos used for the next got entry, otherwise CUR is used and 3518 1.1 christos incremented by a pair of words, wrapping around when it reaches 3519 1.1 christos MAX. FDCUR is decremented (and wrapped) before the next function 3520 1.1 christos descriptor is chosen. FDPLT indicates the number of remaining 3521 1.1 christos slots that can be used for function descriptors used only by PLT 3522 1.1 christos entries. */ 3523 1.1 christos struct _bfinfdpic_dynamic_got_alloc_data 3524 1.1 christos { 3525 1.1 christos bfd_signed_vma max, cur, odd, fdcur, min; 3526 1.1 christos bfd_vma fdplt; 3527 1.1 christos } got17m4, gothilo; 3528 1.1 christos }; 3529 1.1 christos 3530 1.1 christos /* Determine the positive and negative ranges to be used by each 3531 1.1 christos offset range in the GOT. FDCUR and CUR, that must be aligned to a 3532 1.1 christos double-word boundary, are the minimum (negative) and maximum 3533 1.1 christos (positive) GOT offsets already used by previous ranges, except for 3534 1.1 christos an ODD entry that may have been left behind. GOT and FD indicate 3535 1.1 christos the size of GOT entries and function descriptors that must be 3536 1.1 christos placed within the range from -WRAP to WRAP. If there's room left, 3537 1.1 christos up to FDPLT bytes should be reserved for additional function 3538 1.1 christos descriptors. */ 3539 1.1 christos 3540 1.1 christos inline static bfd_signed_vma 3541 1.1 christos _bfinfdpic_compute_got_alloc_data (struct _bfinfdpic_dynamic_got_alloc_data *gad, 3542 1.1 christos bfd_signed_vma fdcur, 3543 1.1 christos bfd_signed_vma odd, 3544 1.1 christos bfd_signed_vma cur, 3545 1.1 christos bfd_vma got, 3546 1.1 christos bfd_vma fd, 3547 1.1 christos bfd_vma fdplt, 3548 1.1 christos bfd_vma wrap) 3549 1.1 christos { 3550 1.1 christos bfd_signed_vma wrapmin = -wrap; 3551 1.1 christos 3552 1.1 christos /* Start at the given initial points. */ 3553 1.1 christos gad->fdcur = fdcur; 3554 1.1 christos gad->cur = cur; 3555 1.1 christos 3556 1.1 christos /* If we had an incoming odd word and we have any got entries that 3557 1.1 christos are going to use it, consume it, otherwise leave gad->odd at 3558 1.1 christos zero. We might force gad->odd to zero and return the incoming 3559 1.1 christos odd such that it is used by the next range, but then GOT entries 3560 1.1 christos might appear to be out of order and we wouldn't be able to 3561 1.1 christos shorten the GOT by one word if it turns out to end with an 3562 1.1 christos unpaired GOT entry. */ 3563 1.1 christos if (odd && got) 3564 1.1 christos { 3565 1.1 christos gad->odd = odd; 3566 1.1 christos got -= 4; 3567 1.1 christos odd = 0; 3568 1.1 christos } 3569 1.1 christos else 3570 1.1 christos gad->odd = 0; 3571 1.1 christos 3572 1.1 christos /* If we're left with an unpaired GOT entry, compute its location 3573 1.1 christos such that we can return it. Otherwise, if got doesn't require an 3574 1.1 christos odd number of words here, either odd was already zero in the 3575 1.1 christos block above, or it was set to zero because got was non-zero, or 3576 1.1 christos got was already zero. In the latter case, we want the value of 3577 1.1 christos odd to carry over to the return statement, so we don't want to 3578 1.1 christos reset odd unless the condition below is true. */ 3579 1.1 christos if (got & 4) 3580 1.1 christos { 3581 1.1 christos odd = cur + got; 3582 1.1 christos got += 4; 3583 1.1 christos } 3584 1.1 christos 3585 1.1 christos /* Compute the tentative boundaries of this range. */ 3586 1.1 christos gad->max = cur + got; 3587 1.1 christos gad->min = fdcur - fd; 3588 1.1 christos gad->fdplt = 0; 3589 1.1 christos 3590 1.1 christos /* If function descriptors took too much space, wrap some of them 3591 1.1 christos around. */ 3592 1.1 christos if (gad->min < wrapmin) 3593 1.1 christos { 3594 1.1 christos gad->max += wrapmin - gad->min; 3595 1.1 christos gad->min = wrapmin; 3596 1.1 christos } 3597 1.1 christos /* If there is space left and we have function descriptors 3598 1.1 christos referenced in PLT entries that could take advantage of shorter 3599 1.1 christos offsets, place them here. */ 3600 1.1 christos else if (fdplt && gad->min > wrapmin) 3601 1.1 christos { 3602 1.1 christos bfd_vma fds; 3603 1.1 christos if ((bfd_vma) (gad->min - wrapmin) < fdplt) 3604 1.1 christos fds = gad->min - wrapmin; 3605 1.1 christos else 3606 1.1 christos fds = fdplt; 3607 1.1 christos 3608 1.1 christos fdplt -= fds; 3609 1.1 christos gad->min -= fds; 3610 1.1 christos gad->fdplt += fds; 3611 1.1 christos } 3612 1.1 christos 3613 1.1 christos /* If GOT entries took too much space, wrap some of them around. 3614 1.1 christos This may well cause gad->min to become lower than wrapmin. This 3615 1.1 christos will cause a relocation overflow later on, so we don't have to 3616 1.1 christos report it here . */ 3617 1.1 christos if ((bfd_vma) gad->max > wrap) 3618 1.1 christos { 3619 1.1 christos gad->min -= gad->max - wrap; 3620 1.1 christos gad->max = wrap; 3621 1.1 christos } 3622 1.1 christos /* If there is more space left, try to place some more function 3623 1.1 christos descriptors for PLT entries. */ 3624 1.1 christos else if (fdplt && (bfd_vma) gad->max < wrap) 3625 1.1 christos { 3626 1.1 christos bfd_vma fds; 3627 1.1 christos if ((bfd_vma) (wrap - gad->max) < fdplt) 3628 1.1 christos fds = wrap - gad->max; 3629 1.1 christos else 3630 1.1 christos fds = fdplt; 3631 1.1 christos 3632 1.1 christos fdplt -= fds; 3633 1.1 christos gad->max += fds; 3634 1.1 christos gad->fdplt += fds; 3635 1.1 christos } 3636 1.1 christos 3637 1.1 christos /* If odd was initially computed as an offset past the wrap point, 3638 1.1 christos wrap it around. */ 3639 1.1 christos if (odd > gad->max) 3640 1.1 christos odd = gad->min + odd - gad->max; 3641 1.1 christos 3642 1.1 christos /* _bfinfdpic_get_got_entry() below will always wrap gad->cur if needed 3643 1.1 christos before returning, so do it here too. This guarantees that, 3644 1.1 christos should cur and fdcur meet at the wrap point, they'll both be 3645 1.1 christos equal to min. */ 3646 1.1 christos if (gad->cur == gad->max) 3647 1.1 christos gad->cur = gad->min; 3648 1.1 christos 3649 1.1 christos return odd; 3650 1.1 christos } 3651 1.1 christos 3652 1.1 christos /* Compute the location of the next GOT entry, given the allocation 3653 1.1 christos data for a range. */ 3654 1.1 christos 3655 1.1 christos inline static bfd_signed_vma 3656 1.1 christos _bfinfdpic_get_got_entry (struct _bfinfdpic_dynamic_got_alloc_data *gad) 3657 1.1 christos { 3658 1.1 christos bfd_signed_vma ret; 3659 1.1 christos 3660 1.1 christos if (gad->odd) 3661 1.1 christos { 3662 1.1 christos /* If there was an odd word left behind, use it. */ 3663 1.1 christos ret = gad->odd; 3664 1.1 christos gad->odd = 0; 3665 1.1 christos } 3666 1.1 christos else 3667 1.1 christos { 3668 1.1 christos /* Otherwise, use the word pointed to by cur, reserve the next 3669 1.1 christos as an odd word, and skip to the next pair of words, possibly 3670 1.1 christos wrapping around. */ 3671 1.1 christos ret = gad->cur; 3672 1.1 christos gad->odd = gad->cur + 4; 3673 1.1 christos gad->cur += 8; 3674 1.1 christos if (gad->cur == gad->max) 3675 1.1 christos gad->cur = gad->min; 3676 1.1 christos } 3677 1.1 christos 3678 1.1 christos return ret; 3679 1.1 christos } 3680 1.1 christos 3681 1.1 christos /* Compute the location of the next function descriptor entry in the 3682 1.1 christos GOT, given the allocation data for a range. */ 3683 1.1 christos 3684 1.1 christos inline static bfd_signed_vma 3685 1.1 christos _bfinfdpic_get_fd_entry (struct _bfinfdpic_dynamic_got_alloc_data *gad) 3686 1.1 christos { 3687 1.1 christos /* If we're at the bottom, wrap around, and only then allocate the 3688 1.1 christos next pair of words. */ 3689 1.1 christos if (gad->fdcur == gad->min) 3690 1.1 christos gad->fdcur = gad->max; 3691 1.1 christos return gad->fdcur -= 8; 3692 1.1 christos } 3693 1.1 christos 3694 1.1 christos /* Assign GOT offsets for every GOT entry and function descriptor. 3695 1.1 christos Doing everything in a single pass is tricky. */ 3696 1.1 christos 3697 1.1 christos static int 3698 1.1 christos _bfinfdpic_assign_got_entries (void **entryp, void *info_) 3699 1.1 christos { 3700 1.1 christos struct bfinfdpic_relocs_info *entry = *entryp; 3701 1.1 christos struct _bfinfdpic_dynamic_got_plt_info *dinfo = info_; 3702 1.1 christos 3703 1.1 christos if (entry->got17m4) 3704 1.1 christos entry->got_entry = _bfinfdpic_get_got_entry (&dinfo->got17m4); 3705 1.1 christos else if (entry->gothilo) 3706 1.1 christos entry->got_entry = _bfinfdpic_get_got_entry (&dinfo->gothilo); 3707 1.1 christos 3708 1.1 christos if (entry->fdgot17m4) 3709 1.1 christos entry->fdgot_entry = _bfinfdpic_get_got_entry (&dinfo->got17m4); 3710 1.1 christos else if (entry->fdgothilo) 3711 1.1 christos entry->fdgot_entry = _bfinfdpic_get_got_entry (&dinfo->gothilo); 3712 1.1 christos 3713 1.1 christos if (entry->fdgoff17m4) 3714 1.1 christos entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->got17m4); 3715 1.1 christos else if (entry->plt && dinfo->got17m4.fdplt) 3716 1.1 christos { 3717 1.1 christos dinfo->got17m4.fdplt -= 8; 3718 1.1 christos entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->got17m4); 3719 1.1 christos } 3720 1.1 christos else if (entry->plt) 3721 1.1 christos { 3722 1.1 christos dinfo->gothilo.fdplt -= 8; 3723 1.1 christos entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->gothilo); 3724 1.1 christos } 3725 1.1 christos else if (entry->privfd) 3726 1.1 christos entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->gothilo); 3727 1.1 christos 3728 1.1 christos return 1; 3729 1.1 christos } 3730 1.1 christos 3731 1.1 christos /* Assign GOT offsets to private function descriptors used by PLT 3732 1.1 christos entries (or referenced by 32-bit offsets), as well as PLT entries 3733 1.1 christos and lazy PLT entries. */ 3734 1.1 christos 3735 1.1 christos static int 3736 1.1 christos _bfinfdpic_assign_plt_entries (void **entryp, void *info_) 3737 1.1 christos { 3738 1.1 christos struct bfinfdpic_relocs_info *entry = *entryp; 3739 1.1 christos struct _bfinfdpic_dynamic_got_plt_info *dinfo = info_; 3740 1.1 christos 3741 1.1 christos /* If this symbol requires a local function descriptor, allocate 3742 1.1 christos one. */ 3743 1.1 christos if (entry->privfd && entry->fd_entry == 0) 3744 1.1 christos { 3745 1.1 christos if (dinfo->got17m4.fdplt) 3746 1.1 christos { 3747 1.1 christos entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->got17m4); 3748 1.1 christos dinfo->got17m4.fdplt -= 8; 3749 1.1 christos } 3750 1.1 christos else 3751 1.1 christos { 3752 1.1 christos BFD_ASSERT (dinfo->gothilo.fdplt); 3753 1.1 christos entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->gothilo); 3754 1.1 christos dinfo->gothilo.fdplt -= 8; 3755 1.1 christos } 3756 1.1 christos } 3757 1.1 christos 3758 1.1 christos if (entry->plt) 3759 1.1 christos { 3760 1.1 christos int size; 3761 1.1 christos 3762 1.1 christos /* We use the section's raw size to mark the location of the 3763 1.1 christos next PLT entry. */ 3764 1.1 christos entry->plt_entry = bfinfdpic_plt_section (dinfo->g.info)->size; 3765 1.1 christos 3766 1.1 christos /* Figure out the length of this PLT entry based on the 3767 1.1 christos addressing mode we need to reach the function descriptor. */ 3768 1.1 christos BFD_ASSERT (entry->fd_entry); 3769 1.1 christos if (entry->fd_entry >= -(1 << (18 - 1)) 3770 1.1 christos && entry->fd_entry + 4 < (1 << (18 - 1))) 3771 1.1 christos size = 10; 3772 1.1 christos else 3773 1.1 christos size = 16; 3774 1.1 christos 3775 1.1 christos bfinfdpic_plt_section (dinfo->g.info)->size += size; 3776 1.1 christos } 3777 1.1 christos 3778 1.1 christos if (entry->lazyplt) 3779 1.1 christos { 3780 1.1 christos entry->lzplt_entry = dinfo->g.lzplt; 3781 1.1 christos dinfo->g.lzplt += LZPLT_NORMAL_SIZE; 3782 1.1 christos /* If this entry is the one that gets the resolver stub, account 3783 1.1 christos for the additional instruction. */ 3784 1.1 christos if (entry->lzplt_entry % BFINFDPIC_LZPLT_BLOCK_SIZE 3785 1.1 christos == BFINFDPIC_LZPLT_RESOLV_LOC) 3786 1.1 christos dinfo->g.lzplt += LZPLT_RESOLVER_EXTRA; 3787 1.1 christos } 3788 1.1 christos 3789 1.1 christos return 1; 3790 1.1 christos } 3791 1.1 christos 3792 1.1 christos /* Cancel out any effects of calling _bfinfdpic_assign_got_entries and 3793 1.1 christos _bfinfdpic_assign_plt_entries. */ 3794 1.1 christos 3795 1.1 christos static int 3796 1.1 christos _bfinfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED) 3797 1.1 christos { 3798 1.1 christos struct bfinfdpic_relocs_info *entry = *entryp; 3799 1.1 christos 3800 1.1 christos entry->got_entry = 0; 3801 1.1 christos entry->fdgot_entry = 0; 3802 1.1 christos entry->fd_entry = 0; 3803 1.1 christos entry->plt_entry = (bfd_vma)-1; 3804 1.1 christos entry->lzplt_entry = (bfd_vma)-1; 3805 1.1 christos 3806 1.1 christos return 1; 3807 1.1 christos } 3808 1.1 christos 3809 1.1 christos /* Follow indirect and warning hash entries so that each got entry 3810 1.1 christos points to the final symbol definition. P must point to a pointer 3811 1.1 christos to the hash table we're traversing. Since this traversal may 3812 1.1 christos modify the hash table, we set this pointer to NULL to indicate 3813 1.1 christos we've made a potentially-destructive change to the hash table, so 3814 1.1 christos the traversal must be restarted. */ 3815 1.1 christos static int 3816 1.1 christos _bfinfdpic_resolve_final_relocs_info (void **entryp, void *p) 3817 1.1 christos { 3818 1.1 christos struct bfinfdpic_relocs_info *entry = *entryp; 3819 1.1 christos htab_t *htab = p; 3820 1.1 christos 3821 1.1 christos if (entry->symndx == -1) 3822 1.1 christos { 3823 1.1 christos struct elf_link_hash_entry *h = entry->d.h; 3824 1.1 christos struct bfinfdpic_relocs_info *oentry; 3825 1.1 christos 3826 1.1 christos while (h->root.type == bfd_link_hash_indirect 3827 1.1 christos || h->root.type == bfd_link_hash_warning) 3828 1.1 christos h = (struct elf_link_hash_entry *)h->root.u.i.link; 3829 1.1 christos 3830 1.1 christos if (entry->d.h == h) 3831 1.1 christos return 1; 3832 1.1 christos 3833 1.1 christos oentry = bfinfdpic_relocs_info_for_global (*htab, 0, h, entry->addend, 3834 1.1 christos NO_INSERT); 3835 1.1 christos 3836 1.1 christos if (oentry) 3837 1.1 christos { 3838 1.1 christos /* Merge the two entries. */ 3839 1.1 christos bfinfdpic_pic_merge_early_relocs_info (oentry, entry); 3840 1.1 christos htab_clear_slot (*htab, entryp); 3841 1.1 christos return 1; 3842 1.1 christos } 3843 1.1 christos 3844 1.1 christos entry->d.h = h; 3845 1.1 christos 3846 1.1 christos /* If we can't find this entry with the new bfd hash, re-insert 3847 1.1 christos it, and get the traversal restarted. */ 3848 1.1 christos if (! htab_find (*htab, entry)) 3849 1.1 christos { 3850 1.1 christos htab_clear_slot (*htab, entryp); 3851 1.1 christos entryp = htab_find_slot (*htab, entry, INSERT); 3852 1.1 christos if (! *entryp) 3853 1.1 christos *entryp = entry; 3854 1.1 christos /* Abort the traversal, since the whole table may have 3855 1.1 christos moved, and leave it up to the parent to restart the 3856 1.1 christos process. */ 3857 1.1 christos *(htab_t *)p = NULL; 3858 1.1 christos return 0; 3859 1.1 christos } 3860 1.1 christos } 3861 1.1 christos 3862 1.1 christos return 1; 3863 1.1 christos } 3864 1.1.1.10 christos 3865 1.1 christos /* Compute the total size of the GOT, the PLT, the dynamic relocations 3866 1.1 christos section and the rofixup section. Assign locations for GOT and PLT 3867 1.1 christos entries. */ 3868 1.1 christos 3869 1.1 christos static bool 3870 1.1 christos _bfinfdpic_size_got_plt (bfd *output_bfd, 3871 1.1 christos struct _bfinfdpic_dynamic_got_plt_info *gpinfop) 3872 1.1 christos { 3873 1.1 christos bfd_signed_vma odd; 3874 1.1 christos bfd_vma limit; 3875 1.1 christos struct bfd_link_info *info = gpinfop->g.info; 3876 1.1 christos bfd *dynobj = elf_hash_table (info)->dynobj; 3877 1.1 christos 3878 1.1 christos memcpy (bfinfdpic_dynamic_got_plt_info (info), &gpinfop->g, 3879 1.1 christos sizeof (gpinfop->g)); 3880 1.1 christos 3881 1.1 christos odd = 12; 3882 1.1 christos /* Compute the total size taken by entries in the 18-bit range, 3883 1.1 christos to tell how many PLT function descriptors we can bring into it 3884 1.1 christos without causing it to overflow. */ 3885 1.1 christos limit = odd + gpinfop->g.got17m4 + gpinfop->g.fd17m4; 3886 1.1 christos if (limit < (bfd_vma)1 << 18) 3887 1.1 christos limit = ((bfd_vma)1 << 18) - limit; 3888 1.1 christos else 3889 1.1 christos limit = 0; 3890 1.1 christos if (gpinfop->g.fdplt < limit) 3891 1.1 christos limit = gpinfop->g.fdplt; 3892 1.1 christos 3893 1.1 christos /* Determine the ranges of GOT offsets that we can use for each 3894 1.1 christos range of addressing modes. */ 3895 1.1 christos odd = _bfinfdpic_compute_got_alloc_data (&gpinfop->got17m4, 3896 1.1 christos 0, 3897 1.1 christos odd, 3898 1.1 christos 16, 3899 1.1 christos gpinfop->g.got17m4, 3900 1.1 christos gpinfop->g.fd17m4, 3901 1.1 christos limit, 3902 1.1 christos (bfd_vma)1 << (18-1)); 3903 1.1 christos odd = _bfinfdpic_compute_got_alloc_data (&gpinfop->gothilo, 3904 1.1 christos gpinfop->got17m4.min, 3905 1.1 christos odd, 3906 1.1 christos gpinfop->got17m4.max, 3907 1.1 christos gpinfop->g.gothilo, 3908 1.1 christos gpinfop->g.fdhilo, 3909 1.1 christos gpinfop->g.fdplt - gpinfop->got17m4.fdplt, 3910 1.1 christos (bfd_vma)1 << (32-1)); 3911 1.1 christos 3912 1.1 christos /* Now assign (most) GOT offsets. */ 3913 1.1 christos htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_assign_got_entries, 3914 1.1 christos gpinfop); 3915 1.1 christos 3916 1.1 christos bfinfdpic_got_section (info)->size = gpinfop->gothilo.max 3917 1.1 christos - gpinfop->gothilo.min 3918 1.1 christos /* If an odd word is the last word of the GOT, we don't need this 3919 1.1 christos word to be part of the GOT. */ 3920 1.1 christos - (odd + 4 == gpinfop->gothilo.max ? 4 : 0); 3921 1.1 christos if (bfinfdpic_got_section (info)->size == 0) 3922 1.1 christos bfinfdpic_got_section (info)->flags |= SEC_EXCLUDE; 3923 1.1 christos else if (bfinfdpic_got_section (info)->size == 12 3924 1.1 christos && ! elf_hash_table (info)->dynamic_sections_created) 3925 1.1 christos { 3926 1.1 christos bfinfdpic_got_section (info)->flags |= SEC_EXCLUDE; 3927 1.1 christos bfinfdpic_got_section (info)->size = 0; 3928 1.1 christos } 3929 1.1 christos else 3930 1.1.1.10 christos { 3931 1.1 christos bfinfdpic_got_section (info)->contents = 3932 1.1 christos (bfd_byte *) bfd_zalloc (dynobj, 3933 1.1 christos bfinfdpic_got_section (info)->size); 3934 1.1 christos if (bfinfdpic_got_section (info)->contents == NULL) 3935 1.1 christos return false; 3936 1.1 christos } 3937 1.1 christos 3938 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 3939 1.1 christos /* Subtract the number of lzplt entries, since those will generate 3940 1.1 christos relocations in the pltrel section. */ 3941 1.1 christos bfinfdpic_gotrel_section (info)->size = 3942 1.1 christos (gpinfop->g.relocs - gpinfop->g.lzplt / LZPLT_NORMAL_SIZE) 3943 1.1 christos * get_elf_backend_data (output_bfd)->s->sizeof_rel; 3944 1.1 christos else 3945 1.1 christos BFD_ASSERT (gpinfop->g.relocs == 0); 3946 1.1 christos if (bfinfdpic_gotrel_section (info)->size == 0) 3947 1.1 christos bfinfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE; 3948 1.1 christos else 3949 1.1.1.10 christos { 3950 1.1 christos bfinfdpic_gotrel_section (info)->contents = 3951 1.1 christos (bfd_byte *) bfd_zalloc (dynobj, 3952 1.1 christos bfinfdpic_gotrel_section (info)->size); 3953 1.1 christos if (bfinfdpic_gotrel_section (info)->contents == NULL) 3954 1.1 christos return false; 3955 1.1 christos } 3956 1.1 christos 3957 1.1 christos bfinfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4; 3958 1.1 christos if (bfinfdpic_gotfixup_section (info)->size == 0) 3959 1.1 christos bfinfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE; 3960 1.1 christos else 3961 1.1.1.10 christos { 3962 1.1 christos bfinfdpic_gotfixup_section (info)->contents = 3963 1.1 christos (bfd_byte *) bfd_zalloc (dynobj, 3964 1.1 christos bfinfdpic_gotfixup_section (info)->size); 3965 1.1 christos if (bfinfdpic_gotfixup_section (info)->contents == NULL) 3966 1.1 christos return false; 3967 1.1 christos } 3968 1.1 christos 3969 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 3970 1.1 christos bfinfdpic_pltrel_section (info)->size = 3971 1.1 christos gpinfop->g.lzplt / LZPLT_NORMAL_SIZE * get_elf_backend_data (output_bfd)->s->sizeof_rel; 3972 1.1 christos if (bfinfdpic_pltrel_section (info)->size == 0) 3973 1.1 christos bfinfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE; 3974 1.1 christos else 3975 1.1.1.10 christos { 3976 1.1 christos bfinfdpic_pltrel_section (info)->contents = 3977 1.1 christos (bfd_byte *) bfd_zalloc (dynobj, 3978 1.1 christos bfinfdpic_pltrel_section (info)->size); 3979 1.1 christos if (bfinfdpic_pltrel_section (info)->contents == NULL) 3980 1.1 christos return false; 3981 1.1 christos } 3982 1.1 christos 3983 1.1 christos /* Add 4 bytes for every block of at most 65535 lazy PLT entries, 3984 1.1 christos such that there's room for the additional instruction needed to 3985 1.1 christos call the resolver. Since _bfinfdpic_assign_got_entries didn't 3986 1.1 christos account for them, our block size is 4 bytes smaller than the real 3987 1.1 christos block size. */ 3988 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 3989 1.1 christos { 3990 1.1 christos bfinfdpic_plt_section (info)->size = gpinfop->g.lzplt 3991 1.1 christos + ((gpinfop->g.lzplt + (BFINFDPIC_LZPLT_BLOCK_SIZE - 4) - LZPLT_NORMAL_SIZE) 3992 1.1 christos / (BFINFDPIC_LZPLT_BLOCK_SIZE - 4) * LZPLT_RESOLVER_EXTRA); 3993 1.1 christos } 3994 1.1 christos 3995 1.1 christos /* Reset it, such that _bfinfdpic_assign_plt_entries() can use it to 3996 1.1 christos actually assign lazy PLT entries addresses. */ 3997 1.1 christos gpinfop->g.lzplt = 0; 3998 1.1 christos 3999 1.1 christos /* Save information that we're going to need to generate GOT and PLT 4000 1.1 christos entries. */ 4001 1.1 christos bfinfdpic_got_initial_offset (info) = -gpinfop->gothilo.min; 4002 1.1 christos 4003 1.1 christos if (get_elf_backend_data (output_bfd)->want_got_sym) 4004 1.1 christos elf_hash_table (info)->hgot->root.u.def.value 4005 1.1 christos = bfinfdpic_got_initial_offset (info); 4006 1.1 christos 4007 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 4008 1.1 christos bfinfdpic_plt_initial_offset (info) = 4009 1.1 christos bfinfdpic_plt_section (info)->size; 4010 1.1 christos 4011 1.1 christos htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_assign_plt_entries, 4012 1.1 christos gpinfop); 4013 1.1 christos 4014 1.1 christos /* Allocate the PLT section contents only after 4015 1.1 christos _bfinfdpic_assign_plt_entries has a chance to add the size of the 4016 1.1 christos non-lazy PLT entries. */ 4017 1.1 christos if (bfinfdpic_plt_section (info)->size == 0) 4018 1.1 christos bfinfdpic_plt_section (info)->flags |= SEC_EXCLUDE; 4019 1.1 christos else 4020 1.1.1.10 christos { 4021 1.1 christos bfinfdpic_plt_section (info)->contents = 4022 1.1 christos (bfd_byte *) bfd_zalloc (dynobj, 4023 1.1.1.10 christos bfinfdpic_plt_section (info)->size); 4024 1.1 christos if (bfinfdpic_plt_section (info)->contents == NULL) 4025 1.1 christos return false; 4026 1.1 christos } 4027 1.1 christos 4028 1.1.1.10 christos return true; 4029 1.1.1.11 christos } 4030 1.1.1.11 christos 4031 1.1 christos /* Set the sizes of the dynamic sections. */ 4032 1.1 christos 4033 1.1 christos static bool 4034 1.1 christos elf32_bfinfdpic_late_size_sections (bfd *output_bfd, 4035 1.1 christos struct bfd_link_info *info) 4036 1.1 christos { 4037 1.1 christos struct elf_link_hash_table *htab; 4038 1.1 christos bfd *dynobj; 4039 1.1.1.11 christos asection *s; 4040 1.1.1.11 christos struct _bfinfdpic_dynamic_got_plt_info gpinfo; 4041 1.1 christos 4042 1.1 christos htab = elf_hash_table (info); 4043 1.1 christos dynobj = htab->dynobj; 4044 1.1 christos if (dynobj == NULL) 4045 1.1.1.6 christos return true; 4046 1.1 christos 4047 1.1.1.2 christos if (htab->dynamic_sections_created) 4048 1.1 christos { 4049 1.1 christos /* Set the contents of the .interp section to the interpreter. */ 4050 1.1 christos if (bfd_link_executable (info) && !info->nointerp) 4051 1.1 christos { 4052 1.1 christos s = bfd_get_linker_section (dynobj, ".interp"); 4053 1.1 christos BFD_ASSERT (s != NULL); 4054 1.1 christos s->size = sizeof ELF_DYNAMIC_INTERPRETER; 4055 1.1 christos s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; 4056 1.1 christos } 4057 1.1 christos } 4058 1.1 christos 4059 1.1 christos memset (&gpinfo, 0, sizeof (gpinfo)); 4060 1.1 christos gpinfo.g.info = info; 4061 1.1 christos 4062 1.1 christos for (;;) 4063 1.1 christos { 4064 1.1 christos htab_t relocs = bfinfdpic_relocs_info (info); 4065 1.1 christos 4066 1.1 christos htab_traverse (relocs, _bfinfdpic_resolve_final_relocs_info, &relocs); 4067 1.1 christos 4068 1.1 christos if (relocs == bfinfdpic_relocs_info (info)) 4069 1.1 christos break; 4070 1.1 christos } 4071 1.1 christos 4072 1.1 christos htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_count_got_plt_entries, 4073 1.1 christos &gpinfo.g); 4074 1.1 christos 4075 1.1.1.10 christos /* Allocate space to save the summary information, we're going to 4076 1.1 christos use it if we're doing relaxations. */ 4077 1.1.1.2 christos bfinfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g)); 4078 1.1 christos 4079 1.1 christos if (!_bfinfdpic_size_got_plt (output_bfd, &gpinfo)) 4080 1.1 christos return false; 4081 1.1.1.2 christos 4082 1.1 christos s = bfd_get_linker_section (dynobj, ".dynbss"); 4083 1.1 christos if (s && s->size == 0) 4084 1.1 christos s->flags |= SEC_EXCLUDE; 4085 1.1.1.10 christos 4086 1.1 christos s = bfd_get_linker_section (dynobj, ".rela.bss"); 4087 1.1 christos if (s && s->size == 0) 4088 1.1.1.10 christos s->flags |= SEC_EXCLUDE; 4089 1.1.1.11 christos 4090 1.1 christos return _bfd_elf_add_dynamic_tags (output_bfd, info, true); 4091 1.1 christos } 4092 1.1.1.6 christos 4093 1.1.1.2 christos static bool 4094 1.1.1.2 christos elf32_bfinfdpic_early_size_sections (bfd *output_bfd, 4095 1.1.1.10 christos struct bfd_link_info *info) 4096 1.1 christos { 4097 1.1.1.10 christos if (!bfd_link_relocatable (info) 4098 1.1 christos && !bfd_elf_stack_segment_size (output_bfd, info, 4099 1.1 christos "__stacksize", DEFAULT_STACK_SIZE)) 4100 1.1 christos return false; 4101 1.1 christos 4102 1.1.1.10 christos return true; 4103 1.1 christos } 4104 1.1.1.2 christos 4105 1.1.1.10 christos /* Check whether any of the relocations was optimized away, and 4106 1.1 christos subtract it from the relocation or fixup count. */ 4107 1.1 christos static bool 4108 1.1.1.10 christos _bfinfdpic_check_discarded_relocs (bfd *abfd, asection *sec, 4109 1.1 christos struct bfd_link_info *info, 4110 1.1 christos bool *changed) 4111 1.1 christos { 4112 1.1 christos Elf_Internal_Shdr *symtab_hdr; 4113 1.1.1.10 christos struct elf_link_hash_entry **sym_hashes; 4114 1.1 christos Elf_Internal_Rela *rel, *erel; 4115 1.1 christos 4116 1.1 christos if ((sec->flags & SEC_RELOC) == 0 4117 1.1 christos || sec->reloc_count == 0) 4118 1.1 christos return true; 4119 1.1 christos 4120 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4121 1.1 christos sym_hashes = elf_sym_hashes (abfd); 4122 1.1 christos 4123 1.1 christos rel = elf_section_data (sec)->relocs; 4124 1.1 christos 4125 1.1 christos /* Now examine each relocation. */ 4126 1.1 christos for (erel = rel + sec->reloc_count; rel < erel; rel++) 4127 1.1 christos { 4128 1.1 christos struct elf_link_hash_entry *h; 4129 1.1 christos unsigned long r_symndx; 4130 1.1 christos struct bfinfdpic_relocs_info *picrel; 4131 1.1 christos struct _bfinfdpic_dynamic_got_info *dinfo; 4132 1.1 christos 4133 1.1 christos if (ELF32_R_TYPE (rel->r_info) != R_BFIN_BYTE4_DATA 4134 1.1 christos && ELF32_R_TYPE (rel->r_info) != R_BFIN_FUNCDESC) 4135 1.1 christos continue; 4136 1.1 christos 4137 1.1 christos if (_bfd_elf_section_offset (sec->output_section->owner, 4138 1.1 christos info, sec, rel->r_offset) 4139 1.1 christos != (bfd_vma)-1) 4140 1.1 christos continue; 4141 1.1 christos 4142 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 4143 1.1 christos if (r_symndx < symtab_hdr->sh_info) 4144 1.1 christos h = NULL; 4145 1.1 christos else 4146 1.1 christos { 4147 1.1 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 4148 1.1 christos while (h->root.type == bfd_link_hash_indirect 4149 1.1 christos || h->root.type == bfd_link_hash_warning) 4150 1.1 christos h = (struct elf_link_hash_entry *)h->root.u.i.link; 4151 1.1 christos } 4152 1.1 christos 4153 1.1 christos if (h != NULL) 4154 1.1 christos picrel = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info), 4155 1.1 christos abfd, h, 4156 1.1 christos rel->r_addend, NO_INSERT); 4157 1.1 christos else 4158 1.1.1.10 christos picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info (info), 4159 1.1 christos abfd, r_symndx, 4160 1.1.1.10 christos rel->r_addend, NO_INSERT); 4161 1.1 christos 4162 1.1 christos if (! picrel) 4163 1.1.1.10 christos return false; 4164 1.1 christos 4165 1.1 christos *changed = true; 4166 1.1 christos dinfo = bfinfdpic_dynamic_got_plt_info (info); 4167 1.1 christos 4168 1.1.1.10 christos _bfinfdpic_count_relocs_fixups (picrel, dinfo, true); 4169 1.1 christos if (ELF32_R_TYPE (rel->r_info) == R_BFIN_BYTE4_DATA) 4170 1.1 christos picrel->relocs32--; 4171 1.1.1.10 christos else /* we know (ELF32_R_TYPE (rel->r_info) == R_BFIN_FUNCDESC) */ 4172 1.1 christos picrel->relocsfd--; 4173 1.1 christos _bfinfdpic_count_relocs_fixups (picrel, dinfo, false); 4174 1.1.1.10 christos } 4175 1.1 christos 4176 1.1 christos return true; 4177 1.1 christos } 4178 1.1 christos 4179 1.1.1.10 christos static bool 4180 1.1 christos bfinfdpic_elf_discard_info (bfd *ibfd, 4181 1.1 christos struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED, 4182 1.1 christos struct bfd_link_info *info) 4183 1.1 christos { 4184 1.1 christos bool changed = false; 4185 1.1.1.2 christos asection *s; 4186 1.1 christos bfd *obfd = NULL; 4187 1.1 christos 4188 1.1.1.10 christos /* Account for relaxation of .eh_frame section. */ 4189 1.1 christos for (s = ibfd->sections; s; s = s->next) 4190 1.1 christos if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME) 4191 1.1 christos { 4192 1.1 christos if (!_bfinfdpic_check_discarded_relocs (ibfd, s, info, &changed)) 4193 1.1 christos return false; 4194 1.1 christos obfd = s->output_section->owner; 4195 1.1 christos } 4196 1.1 christos 4197 1.1 christos if (changed) 4198 1.1 christos { 4199 1.1 christos struct _bfinfdpic_dynamic_got_plt_info gpinfo; 4200 1.1 christos 4201 1.1 christos memset (&gpinfo, 0, sizeof (gpinfo)); 4202 1.1 christos memcpy (&gpinfo.g, bfinfdpic_dynamic_got_plt_info (info), 4203 1.1 christos sizeof (gpinfo.g)); 4204 1.1 christos 4205 1.1 christos /* Clear GOT and PLT assignments. */ 4206 1.1.1.10 christos htab_traverse (bfinfdpic_relocs_info (info), 4207 1.1 christos _bfinfdpic_reset_got_plt_entries, 4208 1.1 christos NULL); 4209 1.1.1.10 christos 4210 1.1 christos if (!_bfinfdpic_size_got_plt (obfd, &gpinfo)) 4211 1.1 christos return false; 4212 1.1.1.10 christos } 4213 1.1 christos 4214 1.1 christos return true; 4215 1.1 christos } 4216 1.1 christos 4217 1.1 christos static bool 4218 1.1 christos elf32_bfinfdpic_finish_dynamic_sections (bfd *output_bfd, 4219 1.1 christos struct bfd_link_info *info) 4220 1.1 christos { 4221 1.1 christos bfd *dynobj; 4222 1.1 christos asection *sdyn; 4223 1.1 christos 4224 1.1.1.6 christos dynobj = elf_hash_table (info)->dynobj; 4225 1.1.1.6 christos 4226 1.1.1.6 christos if (bfinfdpic_got_section (info)) 4227 1.1.1.6 christos { 4228 1.1.1.6 christos BFD_ASSERT (bfinfdpic_gotrel_section (info)->size 4229 1.1.1.6 christos /* PR 17334: It appears that the GOT section can end up 4230 1.1.1.6 christos being bigger than the number of relocs. Presumably 4231 1.1 christos because some relocs have been deleted. A test case has 4232 1.1 christos yet to be generated for verify this, but in the meantime 4233 1.1 christos the test below has been changed from == to >= so that 4234 1.1 christos applications can continue to be built. */ 4235 1.1 christos >= (bfinfdpic_gotrel_section (info)->reloc_count 4236 1.1 christos * sizeof (Elf32_External_Rel))); 4237 1.1 christos 4238 1.1 christos if (bfinfdpic_gotfixup_section (info)) 4239 1.1 christos { 4240 1.1 christos struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot; 4241 1.1 christos bfd_vma got_value = hgot->root.u.def.value 4242 1.1 christos + hgot->root.u.def.section->output_section->vma 4243 1.1 christos + hgot->root.u.def.section->output_offset; 4244 1.1 christos 4245 1.1 christos _bfinfdpic_add_rofixup (output_bfd, bfinfdpic_gotfixup_section (info), 4246 1.1.1.7 christos got_value, 0); 4247 1.1 christos 4248 1.1.1.10 christos if (bfinfdpic_gotfixup_section (info)->size 4249 1.1 christos != (bfinfdpic_gotfixup_section (info)->reloc_count * 4)) 4250 1.1 christos { 4251 1.1 christos _bfd_error_handler 4252 1.1 christos ("LINKER BUG: .rofixup section size mismatch"); 4253 1.1 christos return false; 4254 1.1 christos } 4255 1.1 christos } 4256 1.1 christos } 4257 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 4258 1.1 christos { 4259 1.1.1.2 christos BFD_ASSERT (bfinfdpic_pltrel_section (info)->size 4260 1.1 christos == (bfinfdpic_pltrel_section (info)->reloc_count 4261 1.1 christos * sizeof (Elf32_External_Rel))); 4262 1.1 christos } 4263 1.1 christos 4264 1.1 christos sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 4265 1.1 christos 4266 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 4267 1.1 christos { 4268 1.1 christos Elf32_External_Dyn * dyncon; 4269 1.1 christos Elf32_External_Dyn * dynconend; 4270 1.1 christos 4271 1.1 christos BFD_ASSERT (sdyn != NULL); 4272 1.1 christos 4273 1.1 christos dyncon = (Elf32_External_Dyn *) sdyn->contents; 4274 1.1 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 4275 1.1 christos 4276 1.1 christos for (; dyncon < dynconend; dyncon++) 4277 1.1 christos { 4278 1.1 christos Elf_Internal_Dyn dyn; 4279 1.1 christos 4280 1.1 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 4281 1.1 christos 4282 1.1 christos switch (dyn.d_tag) 4283 1.1 christos { 4284 1.1 christos default: 4285 1.1 christos break; 4286 1.1 christos 4287 1.1 christos case DT_PLTGOT: 4288 1.1 christos dyn.d_un.d_ptr = bfinfdpic_got_section (info)->output_section->vma 4289 1.1 christos + bfinfdpic_got_section (info)->output_offset 4290 1.1 christos + bfinfdpic_got_initial_offset (info); 4291 1.1 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4292 1.1 christos break; 4293 1.1 christos 4294 1.1 christos case DT_JMPREL: 4295 1.1 christos dyn.d_un.d_ptr = bfinfdpic_pltrel_section (info) 4296 1.1 christos ->output_section->vma 4297 1.1 christos + bfinfdpic_pltrel_section (info)->output_offset; 4298 1.1 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4299 1.1 christos break; 4300 1.1 christos 4301 1.1 christos case DT_PLTRELSZ: 4302 1.1 christos dyn.d_un.d_val = bfinfdpic_pltrel_section (info)->size; 4303 1.1 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4304 1.1.1.10 christos break; 4305 1.1 christos } 4306 1.1 christos } 4307 1.1 christos } 4308 1.1 christos 4309 1.1 christos return true; 4310 1.1.1.10 christos } 4311 1.1.1.2 christos 4312 1.1.1.2 christos /* Adjust a symbol defined by a dynamic object and referenced by a 4313 1.1 christos regular object. */ 4314 1.1 christos 4315 1.1 christos static bool 4316 1.1 christos elf32_bfinfdpic_adjust_dynamic_symbol (struct bfd_link_info *info, 4317 1.1 christos struct elf_link_hash_entry *h) 4318 1.1 christos { 4319 1.1 christos bfd * dynobj; 4320 1.1.1.8 christos 4321 1.1 christos dynobj = elf_hash_table (info)->dynobj; 4322 1.1 christos 4323 1.1 christos /* Make sure we know what is going on here. */ 4324 1.1 christos BFD_ASSERT (dynobj != NULL 4325 1.1 christos && (h->is_weakalias 4326 1.1 christos || (h->def_dynamic 4327 1.1 christos && h->ref_regular 4328 1.1.1.8 christos && !h->def_regular))); 4329 1.1 christos 4330 1.1.1.8 christos /* If this is a weak symbol, and there is a real definition, the 4331 1.1.1.8 christos processor independent code will have arranged for us to see the 4332 1.1.1.8 christos real definition first, and we can just use the same value. */ 4333 1.1.1.8 christos if (h->is_weakalias) 4334 1.1 christos { 4335 1.1 christos struct elf_link_hash_entry *def = weakdef (h); 4336 1.1.1.10 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined); 4337 1.1 christos h->root.u.def.section = def->root.u.def.section; 4338 1.1 christos h->root.u.def.value = def->root.u.def.value; 4339 1.1 christos } 4340 1.1 christos 4341 1.1.1.10 christos return true; 4342 1.1 christos } 4343 1.1 christos 4344 1.1 christos /* Perform any actions needed for dynamic symbols. */ 4345 1.1 christos 4346 1.1 christos static bool 4347 1.1 christos elf32_bfinfdpic_finish_dynamic_symbol 4348 1.1.1.10 christos (bfd *output_bfd ATTRIBUTE_UNUSED, 4349 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 4350 1.1 christos struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, 4351 1.1 christos Elf_Internal_Sym *sym ATTRIBUTE_UNUSED) 4352 1.1 christos { 4353 1.1 christos return true; 4354 1.1.1.10 christos } 4355 1.1 christos 4356 1.1 christos /* Decide whether to attempt to turn absptr or lsda encodings in 4357 1.1 christos shared libraries into pcrel within the given input section. */ 4358 1.1 christos 4359 1.1 christos static bool 4360 1.1 christos bfinfdpic_elf_use_relative_eh_frame 4361 1.1.1.10 christos (bfd *input_bfd ATTRIBUTE_UNUSED, 4362 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 4363 1.1 christos asection *eh_frame_section ATTRIBUTE_UNUSED) 4364 1.1 christos { 4365 1.1 christos /* We can't use PC-relative encodings in FDPIC binaries, in general. */ 4366 1.1 christos return false; 4367 1.1 christos } 4368 1.1 christos 4369 1.1 christos /* Adjust the contents of an eh_frame_hdr section before they're output. */ 4370 1.1 christos 4371 1.1 christos static bfd_byte 4372 1.1 christos bfinfdpic_elf_encode_eh_address (bfd *abfd, 4373 1.1 christos struct bfd_link_info *info, 4374 1.1 christos asection *osec, bfd_vma offset, 4375 1.1 christos asection *loc_sec, bfd_vma loc_offset, 4376 1.1 christos bfd_vma *encoded) 4377 1.1 christos { 4378 1.1 christos struct elf_link_hash_entry *h; 4379 1.1 christos 4380 1.1 christos h = elf_hash_table (info)->hgot; 4381 1.1 christos BFD_ASSERT (h && h->root.type == bfd_link_hash_defined); 4382 1.1 christos 4383 1.1 christos if (! h || (_bfinfdpic_osec_to_segment (abfd, osec) 4384 1.1 christos == _bfinfdpic_osec_to_segment (abfd, loc_sec->output_section))) 4385 1.1 christos return _bfd_elf_encode_eh_address (abfd, info, osec, offset, 4386 1.1 christos loc_sec, loc_offset, encoded); 4387 1.1 christos 4388 1.1 christos BFD_ASSERT (_bfinfdpic_osec_to_segment (abfd, osec) 4389 1.1 christos == (_bfinfdpic_osec_to_segment 4390 1.1 christos (abfd, h->root.u.def.section->output_section))); 4391 1.1 christos 4392 1.1 christos *encoded = osec->vma + offset 4393 1.1 christos - (h->root.u.def.value 4394 1.1 christos + h->root.u.def.section->output_section->vma 4395 1.1 christos + h->root.u.def.section->output_offset); 4396 1.1 christos 4397 1.1 christos return DW_EH_PE_datarel | DW_EH_PE_sdata4; 4398 1.1 christos } 4399 1.1 christos 4400 1.1 christos 4401 1.1 christos 4402 1.1 christos /* Look through the relocs for a section during the first phase. 4403 1.1 christos 4404 1.1 christos Besides handling virtual table relocs for gc, we have to deal with 4405 1.1 christos all sorts of PIC-related relocations. We describe below the 4406 1.1 christos general plan on how to handle such relocations, even though we only 4407 1.1 christos collect information at this point, storing them in hash tables for 4408 1.1 christos perusal of later passes. 4409 1.1 christos 4410 1.1 christos 32 relocations are propagated to the linker output when creating 4411 1.1 christos position-independent output. LO16 and HI16 relocations are not 4412 1.1 christos supposed to be encountered in this case. 4413 1.1 christos 4414 1.1 christos LABEL16 should always be resolvable by the linker, since it's only 4415 1.1 christos used by branches. 4416 1.1 christos 4417 1.1 christos LABEL24, on the other hand, is used by calls. If it turns out that 4418 1.1 christos the target of a call is a dynamic symbol, a PLT entry must be 4419 1.1 christos created for it, which triggers the creation of a private function 4420 1.1 christos descriptor and, unless lazy binding is disabled, a lazy PLT entry. 4421 1.1 christos 4422 1.1 christos GPREL relocations require the referenced symbol to be in the same 4423 1.1 christos segment as _gp, but this can only be checked later. 4424 1.1 christos 4425 1.1 christos All GOT, GOTOFF and FUNCDESC relocations require a .got section to 4426 1.1 christos exist. LABEL24 might as well, since it may require a PLT entry, 4427 1.1 christos that will require a got. 4428 1.1 christos 4429 1.1 christos Non-FUNCDESC GOT relocations require a GOT entry to be created 4430 1.1 christos regardless of whether the symbol is dynamic. However, since a 4431 1.1 christos global symbol that turns out to not be exported may have the same 4432 1.1 christos address of a non-dynamic symbol, we don't assign GOT entries at 4433 1.1 christos this point, such that we can share them in this case. A relocation 4434 1.1 christos for the GOT entry always has to be created, be it to offset a 4435 1.1 christos private symbol by the section load address, be it to get the symbol 4436 1.1 christos resolved dynamically. 4437 1.1 christos 4438 1.1 christos FUNCDESC GOT relocations require a GOT entry to be created, and 4439 1.1 christos handled as if a FUNCDESC relocation was applied to the GOT entry in 4440 1.1 christos an object file. 4441 1.1 christos 4442 1.1 christos FUNCDESC relocations referencing a symbol that turns out to NOT be 4443 1.1 christos dynamic cause a private function descriptor to be created. The 4444 1.1 christos FUNCDESC relocation then decays to a 32 relocation that points at 4445 1.1 christos the private descriptor. If the symbol is dynamic, the FUNCDESC 4446 1.1 christos relocation is propagated to the linker output, such that the 4447 1.1 christos dynamic linker creates the canonical descriptor, pointing to the 4448 1.1 christos dynamically-resolved definition of the function. 4449 1.1 christos 4450 1.1 christos Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic 4451 1.1 christos symbols that are assigned to the same segment as the GOT, but we 4452 1.1 christos can only check this later, after we know the complete set of 4453 1.1 christos symbols defined and/or exported. 4454 1.1 christos 4455 1.1 christos FUNCDESC GOTOFF relocations require a function descriptor to be 4456 1.1 christos created and, unless lazy binding is disabled or the symbol is not 4457 1.1 christos dynamic, a lazy PLT entry. Since we can't tell at this point 4458 1.1 christos whether a symbol is going to be dynamic, we have to decide later 4459 1.1 christos whether to create a lazy PLT entry or bind the descriptor directly 4460 1.1 christos to the private function. 4461 1.1 christos 4462 1.1 christos FUNCDESC_VALUE relocations are not supposed to be present in object 4463 1.1 christos files, but they may very well be simply propagated to the linker 4464 1.1 christos output, since they have no side effect. 4465 1.1 christos 4466 1.1 christos 4467 1.1 christos A function descriptor always requires a FUNCDESC_VALUE relocation. 4468 1.1 christos Whether it's in .plt.rel or not depends on whether lazy binding is 4469 1.1 christos enabled and on whether the referenced symbol is dynamic. 4470 1.1 christos 4471 1.1 christos The existence of a lazy PLT requires the resolverStub lazy PLT 4472 1.1 christos entry to be present. 4473 1.1 christos 4474 1.1 christos 4475 1.1 christos As for assignment of GOT, PLT and lazy PLT entries, and private 4476 1.1 christos descriptors, we might do them all sequentially, but we can do 4477 1.1 christos better than that. For example, we can place GOT entries and 4478 1.1 christos private function descriptors referenced using 12-bit operands 4479 1.1 christos closer to the PIC register value, such that these relocations don't 4480 1.1 christos overflow. Those that are only referenced with LO16 relocations 4481 1.1 christos could come next, but we may as well place PLT-required function 4482 1.1 christos descriptors in the 12-bit range to make them shorter. Symbols 4483 1.1 christos referenced with LO16/HI16 may come next, but we may place 4484 1.1 christos additional function descriptors in the 16-bit range if we can 4485 1.1 christos reliably tell that we've already placed entries that are ever 4486 1.1 christos referenced with only LO16. PLT entries are therefore generated as 4487 1.1 christos small as possible, while not introducing relocation overflows in 4488 1.1 christos GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be 4489 1.1 christos generated before or after PLT entries, but not intermingled with 4490 1.1 christos them, such that we can have more lazy PLT entries in range for a 4491 1.1 christos branch to the resolverStub. The resolverStub should be emitted at 4492 1.1 christos the most distant location from the first lazy PLT entry such that 4493 1.1 christos it's still in range for a branch, or closer, if there isn't a need 4494 1.1 christos for so many lazy PLT entries. Additional lazy PLT entries may be 4495 1.1 christos emitted after the resolverStub, as long as branches are still in 4496 1.1 christos range. If the branch goes out of range, longer lazy PLT entries 4497 1.1 christos are emitted. 4498 1.1 christos 4499 1.1 christos We could further optimize PLT and lazy PLT entries by giving them 4500 1.1 christos priority in assignment to closer-to-gr17 locations depending on the 4501 1.1.1.10 christos number of occurrences of references to them (assuming a function 4502 1.1 christos that's called more often is more important for performance, so its 4503 1.1 christos PLT entry should be faster), or taking hints from the compiler. 4504 1.1 christos Given infinite time and money... :-) */ 4505 1.1 christos 4506 1.1 christos static bool 4507 1.1 christos bfinfdpic_check_relocs (bfd *abfd, struct bfd_link_info *info, 4508 1.1 christos asection *sec, const Elf_Internal_Rela *relocs) 4509 1.1 christos { 4510 1.1 christos Elf_Internal_Shdr *symtab_hdr; 4511 1.1 christos struct elf_link_hash_entry **sym_hashes; 4512 1.1.1.6 christos const Elf_Internal_Rela *rel; 4513 1.1.1.10 christos const Elf_Internal_Rela *rel_end; 4514 1.1 christos bfd *dynobj; 4515 1.1 christos struct bfinfdpic_relocs_info *picrel; 4516 1.1 christos 4517 1.1 christos if (bfd_link_relocatable (info)) 4518 1.1 christos return true; 4519 1.1 christos 4520 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4521 1.1 christos sym_hashes = elf_sym_hashes (abfd); 4522 1.1 christos 4523 1.1 christos dynobj = elf_hash_table (info)->dynobj; 4524 1.1 christos rel_end = relocs + sec->reloc_count; 4525 1.1 christos for (rel = relocs; rel < rel_end; rel++) 4526 1.1 christos { 4527 1.1.1.8 christos struct elf_link_hash_entry *h; 4528 1.1 christos unsigned long r_symndx; 4529 1.1.1.10 christos 4530 1.1.1.10 christos r_symndx = ELF32_R_SYM (rel->r_info); 4531 1.1.1.10 christos if (r_symndx < symtab_hdr->sh_info) 4532 1.1.1.10 christos h = NULL; 4533 1.1.1.10 christos else 4534 1.1.1.10 christos { 4535 1.1 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 4536 1.1 christos while (h->root.type == bfd_link_hash_indirect 4537 1.1 christos || h->root.type == bfd_link_hash_warning) 4538 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 4539 1.1 christos } 4540 1.1 christos 4541 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 4542 1.1 christos { 4543 1.1 christos case R_BFIN_GOT17M4: 4544 1.1 christos case R_BFIN_GOTHI: 4545 1.1 christos case R_BFIN_GOTLO: 4546 1.1 christos case R_BFIN_FUNCDESC_GOT17M4: 4547 1.1 christos case R_BFIN_FUNCDESC_GOTHI: 4548 1.1 christos case R_BFIN_FUNCDESC_GOTLO: 4549 1.1 christos case R_BFIN_GOTOFF17M4: 4550 1.1 christos case R_BFIN_GOTOFFHI: 4551 1.1 christos case R_BFIN_GOTOFFLO: 4552 1.1 christos case R_BFIN_FUNCDESC_GOTOFF17M4: 4553 1.1 christos case R_BFIN_FUNCDESC_GOTOFFHI: 4554 1.1 christos case R_BFIN_FUNCDESC_GOTOFFLO: 4555 1.1 christos case R_BFIN_FUNCDESC: 4556 1.1 christos case R_BFIN_FUNCDESC_VALUE: 4557 1.1 christos if (! IS_FDPIC (abfd)) 4558 1.1 christos goto bad_reloc; 4559 1.1 christos /* Fall through. */ 4560 1.1 christos case R_BFIN_PCREL24: 4561 1.1 christos case R_BFIN_PCREL24_JUMP_L: 4562 1.1.1.10 christos case R_BFIN_BYTE4_DATA: 4563 1.1 christos if (IS_FDPIC (abfd) && ! dynobj) 4564 1.1 christos { 4565 1.1 christos elf_hash_table (info)->dynobj = dynobj = abfd; 4566 1.1 christos if (! _bfin_create_got_section (abfd, info)) 4567 1.1 christos return false; 4568 1.1 christos } 4569 1.1 christos if (! IS_FDPIC (abfd)) 4570 1.1 christos { 4571 1.1 christos picrel = NULL; 4572 1.1 christos break; 4573 1.1 christos } 4574 1.1 christos if (h != NULL) 4575 1.1 christos { 4576 1.1 christos if (h->dynindx == -1) 4577 1.1 christos switch (ELF_ST_VISIBILITY (h->other)) 4578 1.1 christos { 4579 1.1 christos case STV_INTERNAL: 4580 1.1 christos case STV_HIDDEN: 4581 1.1 christos break; 4582 1.1 christos default: 4583 1.1 christos bfd_elf_link_record_dynamic_symbol (info, h); 4584 1.1 christos break; 4585 1.1 christos } 4586 1.1 christos picrel 4587 1.1 christos = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info), 4588 1.1 christos abfd, h, 4589 1.1 christos rel->r_addend, INSERT); 4590 1.1 christos } 4591 1.1.1.10 christos else 4592 1.1 christos picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info 4593 1.1 christos (info), abfd, r_symndx, 4594 1.1 christos rel->r_addend, INSERT); 4595 1.1 christos if (! picrel) 4596 1.1 christos return false; 4597 1.1 christos break; 4598 1.1 christos 4599 1.1 christos default: 4600 1.1.1.8 christos picrel = NULL; 4601 1.1 christos break; 4602 1.1 christos } 4603 1.1 christos 4604 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 4605 1.1 christos { 4606 1.1 christos case R_BFIN_PCREL24: 4607 1.1 christos case R_BFIN_PCREL24_JUMP_L: 4608 1.1 christos if (IS_FDPIC (abfd)) 4609 1.1.1.9 christos picrel->call++; 4610 1.1 christos break; 4611 1.1 christos 4612 1.1 christos case R_BFIN_FUNCDESC_VALUE: 4613 1.1 christos picrel->relocsfdv++; 4614 1.1 christos if (bfd_section_flags (sec) & SEC_ALLOC) 4615 1.1 christos picrel->relocs32--; 4616 1.1 christos /* Fall through. */ 4617 1.1 christos 4618 1.1.1.9 christos case R_BFIN_BYTE4_DATA: 4619 1.1 christos if (! IS_FDPIC (abfd)) 4620 1.1 christos break; 4621 1.1 christos 4622 1.1 christos picrel->sym++; 4623 1.1 christos if (bfd_section_flags (sec) & SEC_ALLOC) 4624 1.1 christos picrel->relocs32++; 4625 1.1 christos break; 4626 1.1 christos 4627 1.1 christos case R_BFIN_GOT17M4: 4628 1.1 christos picrel->got17m4++; 4629 1.1 christos break; 4630 1.1 christos 4631 1.1 christos case R_BFIN_GOTHI: 4632 1.1 christos case R_BFIN_GOTLO: 4633 1.1 christos picrel->gothilo++; 4634 1.1 christos break; 4635 1.1 christos 4636 1.1 christos case R_BFIN_FUNCDESC_GOT17M4: 4637 1.1 christos picrel->fdgot17m4++; 4638 1.1 christos break; 4639 1.1 christos 4640 1.1 christos case R_BFIN_FUNCDESC_GOTHI: 4641 1.1 christos case R_BFIN_FUNCDESC_GOTLO: 4642 1.1 christos picrel->fdgothilo++; 4643 1.1 christos break; 4644 1.1 christos 4645 1.1 christos case R_BFIN_GOTOFF17M4: 4646 1.1 christos case R_BFIN_GOTOFFHI: 4647 1.1 christos case R_BFIN_GOTOFFLO: 4648 1.1 christos picrel->gotoff++; 4649 1.1 christos break; 4650 1.1 christos 4651 1.1 christos case R_BFIN_FUNCDESC_GOTOFF17M4: 4652 1.1 christos picrel->fdgoff17m4++; 4653 1.1 christos break; 4654 1.1 christos 4655 1.1 christos case R_BFIN_FUNCDESC_GOTOFFHI: 4656 1.1 christos case R_BFIN_FUNCDESC_GOTOFFLO: 4657 1.1 christos picrel->fdgoffhilo++; 4658 1.1 christos break; 4659 1.1 christos 4660 1.1.1.8 christos case R_BFIN_FUNCDESC: 4661 1.1.1.8 christos picrel->fd++; 4662 1.1.1.8 christos picrel->relocsfd++; 4663 1.1.1.8 christos break; 4664 1.1.1.10 christos 4665 1.1.1.8 christos /* This relocation describes the C++ object vtable hierarchy. 4666 1.1.1.8 christos Reconstruct it for later use during GC. */ 4667 1.1.1.8 christos case R_BFIN_GNU_VTINHERIT: 4668 1.1.1.8 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 4669 1.1.1.8 christos return false; 4670 1.1.1.8 christos break; 4671 1.1.1.8 christos 4672 1.1.1.8 christos /* This relocation describes which C++ vtable entries are actually 4673 1.1.1.10 christos used. Record for later use during GC. */ 4674 1.1.1.8 christos case R_BFIN_GNU_VTENTRY: 4675 1.1 christos BFD_ASSERT (h != NULL); 4676 1.1 christos if (h != NULL 4677 1.1 christos && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 4678 1.1 christos return false; 4679 1.1 christos break; 4680 1.1 christos 4681 1.1 christos case R_BFIN_HUIMM16: 4682 1.1 christos case R_BFIN_LUIMM16: 4683 1.1 christos case R_BFIN_PCREL12_JUMP_S: 4684 1.1.1.7 christos case R_BFIN_PCREL10: 4685 1.1.1.7 christos break; 4686 1.1.1.8 christos 4687 1.1.1.8 christos default: 4688 1.1.1.10 christos bad_reloc: 4689 1.1.1.8 christos _bfd_error_handler 4690 1.1 christos /* xgettext:c-format */ 4691 1.1 christos (_("%pB: unsupported relocation type %#x"), 4692 1.1.1.10 christos abfd, (int) ELF32_R_TYPE (rel->r_info)); 4693 1.1 christos return false; 4694 1.1 christos } 4695 1.1 christos } 4696 1.1 christos 4697 1.1.1.10 christos return true; 4698 1.1 christos } 4699 1.1 christos 4700 1.1 christos /* Set the right machine number for a Blackfin ELF file. */ 4701 1.1 christos 4702 1.1 christos static bool 4703 1.1 christos elf32_bfin_object_p (bfd *abfd) 4704 1.1 christos { 4705 1.1.1.10 christos bfd_default_set_arch_mach (abfd, bfd_arch_bfin, 0); 4706 1.1 christos return (((elf_elfheader (abfd)->e_flags & EF_BFIN_FDPIC) != 0) 4707 1.1 christos == (IS_FDPIC (abfd))); 4708 1.1 christos } 4709 1.1.1.10 christos 4710 1.1.1.10 christos static bool 4711 1.1 christos elf32_bfin_set_private_flags (bfd * abfd, flagword flags) 4712 1.1 christos { 4713 1.1 christos elf_elfheader (abfd)->e_flags = flags; 4714 1.1.1.10 christos elf_flags_init (abfd) = true; 4715 1.1.1.2 christos return true; 4716 1.1 christos } 4717 1.1 christos 4718 1.1 christos /* Display the flags field. */ 4719 1.1 christos static bool 4720 1.1 christos elf32_bfin_print_private_bfd_data (bfd * abfd, void * ptr) 4721 1.1 christos { 4722 1.1 christos FILE *file = (FILE *) ptr; 4723 1.1 christos flagword flags; 4724 1.1 christos 4725 1.1 christos BFD_ASSERT (abfd != NULL && ptr != NULL); 4726 1.1 christos 4727 1.1 christos /* Print normal ELF private data. */ 4728 1.1 christos _bfd_elf_print_private_bfd_data (abfd, ptr); 4729 1.1 christos 4730 1.1 christos flags = elf_elfheader (abfd)->e_flags; 4731 1.1 christos 4732 1.1 christos /* xgettext:c-format */ 4733 1.1 christos fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); 4734 1.1 christos 4735 1.1 christos if (flags & EF_BFIN_PIC) 4736 1.1 christos fprintf (file, " -fpic"); 4737 1.1 christos 4738 1.1.1.10 christos if (flags & EF_BFIN_FDPIC) 4739 1.1 christos fprintf (file, " -mfdpic"); 4740 1.1 christos 4741 1.1 christos fputc ('\n', file); 4742 1.1 christos 4743 1.1 christos return true; 4744 1.1.1.10 christos } 4745 1.1.1.7 christos 4746 1.1 christos /* Merge backend specific data from an object file to the output 4747 1.1.1.7 christos object file when linking. */ 4748 1.1 christos 4749 1.1.1.10 christos static bool 4750 1.1 christos elf32_bfin_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) 4751 1.1.1.9 christos { 4752 1.1.1.9 christos bfd *obfd = info->output_bfd; 4753 1.1.1.10 christos flagword old_flags, new_flags; 4754 1.1.1.9 christos bool error = false; 4755 1.1 christos 4756 1.1 christos /* FIXME: What should be checked when linking shared libraries? */ 4757 1.1 christos if ((ibfd->flags & DYNAMIC) != 0) 4758 1.1 christos return true; 4759 1.1 christos 4760 1.1 christos new_flags = elf_elfheader (ibfd)->e_flags; 4761 1.1 christos old_flags = elf_elfheader (obfd)->e_flags; 4762 1.1 christos 4763 1.1 christos if (new_flags & EF_BFIN_FDPIC) 4764 1.1.1.7 christos new_flags &= ~EF_BFIN_PIC; 4765 1.1.1.8 christos 4766 1.1.1.7 christos #ifndef DEBUG 4767 1.1 christos if (0) 4768 1.1 christos #endif 4769 1.1 christos _bfd_error_handler 4770 1.1.1.10 christos ("old_flags = 0x%.8x, new_flags = 0x%.8x, init = %s, filename = %pB", 4771 1.1 christos old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", ibfd); 4772 1.1 christos 4773 1.1 christos if (!elf_flags_init (obfd)) /* First call, no flags set. */ 4774 1.1 christos { 4775 1.1 christos elf_flags_init (obfd) = true; 4776 1.1.1.10 christos elf_elfheader (obfd)->e_flags = new_flags; 4777 1.1 christos } 4778 1.1.1.7 christos 4779 1.1.1.8 christos if (((new_flags & EF_BFIN_FDPIC) == 0) != (! IS_FDPIC (obfd))) 4780 1.1.1.7 christos { 4781 1.1 christos error = true; 4782 1.1.1.7 christos if (IS_FDPIC (obfd)) 4783 1.1.1.8 christos _bfd_error_handler 4784 1.1.1.7 christos (_("%pB: cannot link non-fdpic object file into fdpic executable"), 4785 1.1 christos ibfd); 4786 1.1 christos else 4787 1.1 christos _bfd_error_handler 4788 1.1 christos (_("%pB: cannot link fdpic object file into non-fdpic executable"), 4789 1.1 christos ibfd); 4790 1.1 christos } 4791 1.1 christos 4792 1.1 christos if (error) 4793 1.1 christos bfd_set_error (bfd_error_bad_value); 4794 1.1 christos 4795 1.1 christos return !error; 4796 1.1 christos } 4797 1.1 christos 4798 1.1 christos /* bfin ELF linker hash entry. */ 4800 1.1 christos 4801 1.1 christos struct bfin_link_hash_entry 4802 1.1 christos { 4803 1.1 christos struct elf_link_hash_entry root; 4804 1.1 christos 4805 1.1 christos /* Number of PC relative relocs copied for this symbol. */ 4806 1.1 christos struct bfin_pcrel_relocs_copied *pcrel_relocs_copied; 4807 1.1 christos }; 4808 1.1 christos 4809 1.1 christos #define bfin_hash_entry(ent) ((struct bfin_link_hash_entry *) (ent)) 4810 1.1 christos 4811 1.1 christos static struct bfd_hash_entry * 4812 1.1 christos bfin_link_hash_newfunc (struct bfd_hash_entry *entry, 4813 1.1 christos struct bfd_hash_table *table, const char *string) 4814 1.1 christos { 4815 1.1 christos struct bfd_hash_entry *ret = entry; 4816 1.1 christos 4817 1.1 christos /* Allocate the structure if it has not already been allocated by a 4818 1.1 christos subclass. */ 4819 1.1 christos if (ret == NULL) 4820 1.1 christos ret = bfd_hash_allocate (table, sizeof (struct bfin_link_hash_entry)); 4821 1.1 christos if (ret == NULL) 4822 1.1 christos return ret; 4823 1.1 christos 4824 1.1 christos /* Call the allocation method of the superclass. */ 4825 1.1 christos ret = _bfd_elf_link_hash_newfunc (ret, table, string); 4826 1.1 christos if (ret != NULL) 4827 1.1 christos bfin_hash_entry (ret)->pcrel_relocs_copied = NULL; 4828 1.1 christos 4829 1.1 christos return ret; 4830 1.1 christos } 4831 1.1.1.9 christos 4832 1.1.1.9 christos /* Create an bfin ELF linker hash table. */ 4833 1.1 christos 4834 1.1.1.2 christos static struct bfd_link_hash_table * 4835 1.1 christos bfin_link_hash_table_create (bfd * abfd) 4836 1.1 christos { 4837 1.1 christos struct elf_link_hash_table *ret; 4838 1.1.1.9 christos size_t amt = sizeof (struct elf_link_hash_table); 4839 1.1.1.12 christos 4840 1.1 christos ret = bfd_zmalloc (amt); 4841 1.1 christos if (ret == NULL) 4842 1.1 christos return NULL; 4843 1.1 christos 4844 1.1 christos if (!_bfd_elf_link_hash_table_init (ret, abfd, bfin_link_hash_newfunc, 4845 1.1.1.9 christos sizeof (struct elf_link_hash_entry))) 4846 1.1 christos { 4847 1.1 christos free (ret); 4848 1.1 christos return NULL; 4849 1.1 christos } 4850 1.1 christos 4851 1.1 christos return &ret->root; 4852 1.1.1.10 christos } 4853 1.1 christos 4854 1.1.1.2 christos /* The size in bytes of an entry in the procedure linkage table. */ 4855 1.1 christos 4856 1.1 christos /* Finish up the dynamic sections. */ 4857 1.1 christos 4858 1.1 christos static bool 4859 1.1 christos bfin_finish_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, 4860 1.1 christos struct bfd_link_info *info) 4861 1.1.1.2 christos { 4862 1.1 christos bfd *dynobj; 4863 1.1 christos asection *sdyn; 4864 1.1 christos 4865 1.1 christos dynobj = elf_hash_table (info)->dynobj; 4866 1.1 christos 4867 1.1 christos sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 4868 1.1 christos 4869 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 4870 1.1 christos { 4871 1.1 christos Elf32_External_Dyn *dyncon, *dynconend; 4872 1.1 christos 4873 1.1 christos BFD_ASSERT (sdyn != NULL); 4874 1.1 christos 4875 1.1 christos dyncon = (Elf32_External_Dyn *) sdyn->contents; 4876 1.1 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 4877 1.1 christos for (; dyncon < dynconend; dyncon++) 4878 1.1 christos { 4879 1.1 christos Elf_Internal_Dyn dyn; 4880 1.1.1.10 christos 4881 1.1 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 4882 1.1 christos 4883 1.1 christos } 4884 1.1 christos 4885 1.1 christos } 4886 1.1.1.10 christos return true; 4887 1.1 christos } 4888 1.1.1.2 christos 4889 1.1.1.2 christos /* Finish up dynamic symbol handling. We set the contents of various 4890 1.1.1.2 christos dynamic sections here. */ 4891 1.1 christos 4892 1.1 christos static bool 4893 1.1 christos bfin_finish_dynamic_symbol (bfd * output_bfd, 4894 1.1 christos struct bfd_link_info *info, 4895 1.1 christos struct elf_link_hash_entry *h, 4896 1.1 christos Elf_Internal_Sym * sym) 4897 1.1 christos { 4898 1.1 christos if (h->got.offset != (bfd_vma) - 1) 4899 1.1 christos { 4900 1.1.1.8 christos asection *sgot; 4901 1.1 christos asection *srela; 4902 1.1.1.7 christos Elf_Internal_Rela rela; 4903 1.1.1.7 christos bfd_byte *loc; 4904 1.1 christos 4905 1.1 christos /* This symbol has an entry in the global offset table. 4906 1.1 christos Set it up. */ 4907 1.1 christos 4908 1.1 christos sgot = elf_hash_table (info)->sgot; 4909 1.1 christos srela = elf_hash_table (info)->srelgot; 4910 1.1 christos BFD_ASSERT (sgot != NULL && srela != NULL); 4911 1.1.1.8 christos 4912 1.1.1.8 christos rela.r_offset = (sgot->output_section->vma 4913 1.1.1.8 christos + sgot->output_offset 4914 1.1.1.8 christos + (h->got.offset & ~(bfd_vma) 1)); 4915 1.1.1.6 christos 4916 1.1 christos /* If this is a -Bsymbolic link, and the symbol is defined 4917 1.1 christos locally, we just want to emit a RELATIVE reloc. Likewise if 4918 1.1 christos the symbol was forced to be local because of a version file. 4919 1.1.1.11 christos The entry in the global offset table will already have been 4920 1.1 christos initialized in the relocate_section function. */ 4921 1.1 christos if (bfd_link_pic (info) 4922 1.1 christos && (info->symbolic 4923 1.1 christos || h->dynindx == -1 || h->forced_local) && h->def_regular) 4924 1.1 christos { 4925 1.1 christos _bfd_error_handler (_("*** check this relocation %s"), __func__); 4926 1.1 christos rela.r_info = ELF32_R_INFO (0, R_BFIN_PCREL24); 4927 1.1 christos rela.r_addend = bfd_get_signed_32 (output_bfd, 4928 1.1 christos (sgot->contents 4929 1.1 christos + 4930 1.1 christos (h->got. 4931 1.1 christos offset & ~(bfd_vma) 1))); 4932 1.1 christos } 4933 1.1 christos else 4934 1.1 christos { 4935 1.1 christos bfd_put_32 (output_bfd, (bfd_vma) 0, 4936 1.1 christos sgot->contents + (h->got.offset & ~(bfd_vma) 1)); 4937 1.1 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_BFIN_GOT); 4938 1.1 christos rela.r_addend = 0; 4939 1.1 christos } 4940 1.1 christos 4941 1.1 christos loc = srela->contents; 4942 1.1 christos loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); 4943 1.1 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 4944 1.1 christos } 4945 1.1 christos 4946 1.1 christos if (h->needs_copy) 4947 1.1 christos { 4948 1.1 christos BFD_ASSERT (0); 4949 1.1.1.10 christos } 4950 1.1 christos /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ 4951 1.1 christos if (strcmp (h->root.root.string, "__DYNAMIC") == 0 4952 1.1 christos || h == elf_hash_table (info)->hgot) 4953 1.1 christos sym->st_shndx = SHN_ABS; 4954 1.1 christos 4955 1.1 christos return true; 4956 1.1 christos } 4957 1.1 christos 4958 1.1.1.10 christos /* Adjust a symbol defined by a dynamic object and referenced by a 4959 1.1 christos regular object. The current definition is in some section of the 4960 1.1.1.2 christos dynamic object, but we're not including those sections. We have to 4961 1.1 christos change the definition to something the rest of the link can 4962 1.1 christos understand. */ 4963 1.1 christos 4964 1.1 christos static bool 4965 1.1 christos bfin_adjust_dynamic_symbol (struct bfd_link_info *info, 4966 1.1 christos struct elf_link_hash_entry *h) 4967 1.1 christos { 4968 1.1 christos bfd *dynobj; 4969 1.1 christos asection *s; 4970 1.1 christos unsigned int power_of_two; 4971 1.1.1.8 christos 4972 1.1 christos dynobj = elf_hash_table (info)->dynobj; 4973 1.1 christos 4974 1.1 christos /* Make sure we know what is going on here. */ 4975 1.1 christos BFD_ASSERT (dynobj != NULL 4976 1.1 christos && (h->needs_plt 4977 1.1 christos || h->is_weakalias 4978 1.1 christos || (h->def_dynamic && h->ref_regular && !h->def_regular))); 4979 1.1 christos 4980 1.1 christos /* If this is a function, put it in the procedure linkage table. We 4981 1.1 christos will fill in the contents of the procedure linkage table later, 4982 1.1 christos when we know the address of the .got section. */ 4983 1.1 christos if (h->type == STT_FUNC || h->needs_plt) 4984 1.1 christos { 4985 1.1.1.8 christos BFD_ASSERT(0); 4986 1.1 christos } 4987 1.1.1.8 christos 4988 1.1.1.8 christos /* If this is a weak symbol, and there is a real definition, the 4989 1.1.1.8 christos processor independent code will have arranged for us to see the 4990 1.1.1.8 christos real definition first, and we can just use the same value. */ 4991 1.1.1.10 christos if (h->is_weakalias) 4992 1.1 christos { 4993 1.1 christos struct elf_link_hash_entry *def = weakdef (h); 4994 1.1 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined); 4995 1.1 christos h->root.u.def.section = def->root.u.def.section; 4996 1.1 christos h->root.u.def.value = def->root.u.def.value; 4997 1.1 christos return true; 4998 1.1 christos } 4999 1.1 christos 5000 1.1 christos /* This is a reference to a symbol defined by a dynamic object which 5001 1.1.1.6 christos is not a function. */ 5002 1.1.1.10 christos 5003 1.1 christos /* If we are creating a shared library, we must presume that the 5004 1.1 christos only references to the symbol are via the global offset table. 5005 1.1 christos For such cases we need not do anything here; the relocations will 5006 1.1 christos be handled correctly by relocate_section. */ 5007 1.1 christos if (bfd_link_pic (info)) 5008 1.1 christos return true; 5009 1.1 christos 5010 1.1 christos /* We must allocate the symbol in our .dynbss section, which will 5011 1.1 christos become part of the .bss section of the executable. There will be 5012 1.1 christos an entry for this symbol in the .dynsym section. The dynamic 5013 1.1 christos object will contain position independent code, so all references 5014 1.1.1.2 christos from the dynamic object to this symbol will go through the global 5015 1.1 christos offset table. The dynamic linker will use the .dynsym entry to 5016 1.1 christos determine the address it must put in the global offset table, so 5017 1.1.1.6 christos both the dynamic object and the regular object will refer to the 5018 1.1.1.6 christos same memory location for the variable. */ 5019 1.1 christos 5020 1.1 christos s = bfd_get_linker_section (dynobj, ".dynbss"); 5021 1.1 christos BFD_ASSERT (s != NULL); 5022 1.1 christos 5023 1.1 christos #if 0 /* Bfin does not currently have a COPY reloc. */ 5024 1.1 christos /* We must generate a R_BFIN_COPY reloc to tell the dynamic linker to 5025 1.1 christos copy the initial value out of the dynamic object and into the 5026 1.1.1.2 christos runtime process image. We need to remember the offset into the 5027 1.1 christos .rela.bss section we are going to use. */ 5028 1.1 christos if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 5029 1.1 christos { 5030 1.1 christos asection *srel; 5031 1.1.1.6 christos 5032 1.1.1.6 christos srel = bfd_get_linker_section (dynobj, ".rela.bss"); 5033 1.1.1.6 christos BFD_ASSERT (srel != NULL); 5034 1.1.1.7 christos srel->size += sizeof (Elf32_External_Rela); 5035 1.1.1.10 christos h->needs_copy = 1; 5036 1.1.1.6 christos } 5037 1.1.1.6 christos #else 5038 1.1 christos if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 5039 1.1 christos { 5040 1.1 christos _bfd_error_handler (_("the bfin target does not currently support the generation of copy relocations")); 5041 1.1 christos return false; 5042 1.1 christos } 5043 1.1 christos #endif 5044 1.1 christos /* We need to figure out the alignment required for this symbol. I 5045 1.1 christos have no idea how ELF linkers handle this. */ 5046 1.1.1.9 christos power_of_two = bfd_log2 (h->size); 5047 1.1 christos if (power_of_two > 3) 5048 1.1.1.9 christos power_of_two = 3; 5049 1.1.1.10 christos 5050 1.1 christos /* Apply the required alignment. */ 5051 1.1 christos s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); 5052 1.1 christos if (power_of_two > bfd_section_alignment (s)) 5053 1.1 christos { 5054 1.1 christos if (!bfd_set_section_alignment (s, power_of_two)) 5055 1.1 christos return false; 5056 1.1 christos } 5057 1.1 christos 5058 1.1 christos /* Define the symbol as being at this point in the section. */ 5059 1.1.1.10 christos h->root.u.def.section = s; 5060 1.1 christos h->root.u.def.value = s->size; 5061 1.1 christos 5062 1.1 christos /* Increment the section size to make room for the symbol. */ 5063 1.1 christos s->size += h->size; 5064 1.1 christos 5065 1.1 christos return true; 5066 1.1 christos } 5067 1.1 christos 5068 1.1 christos /* The bfin linker needs to keep track of the number of relocs that it 5069 1.1 christos decides to copy in check_relocs for each symbol. This is so that it 5070 1.1 christos can discard PC relative relocs if it doesn't need them when linking 5071 1.1 christos with -Bsymbolic. We store the information in a field extending the 5072 1.1 christos regular ELF linker hash table. */ 5073 1.1 christos 5074 1.1 christos /* This structure keeps track of the number of PC relative relocs we have 5075 1.1 christos copied for a given symbol. */ 5076 1.1 christos 5077 1.1 christos struct bfin_pcrel_relocs_copied 5078 1.1 christos { 5079 1.1 christos /* Next section. */ 5080 1.1 christos struct bfin_pcrel_relocs_copied *next; 5081 1.1 christos /* A section in dynobj. */ 5082 1.1 christos asection *section; 5083 1.1 christos /* Number of relocs copied in this section. */ 5084 1.1 christos bfd_size_type count; 5085 1.1 christos }; 5086 1.1 christos 5087 1.1 christos /* This function is called via elf_link_hash_traverse if we are 5088 1.1 christos creating a shared object. In the -Bsymbolic case it discards the 5089 1.1 christos space allocated to copy PC relative relocs against symbols which 5090 1.1 christos are defined in regular objects. For the normal shared case, it 5091 1.1 christos discards space for pc-relative relocs that have become local due to 5092 1.1 christos symbol visibility changes. We allocated space for them in the 5093 1.1 christos check_relocs routine, but we won't fill them in in the 5094 1.1.1.10 christos relocate_section routine. 5095 1.1.1.2 christos 5096 1.1 christos We also check whether any of the remaining relocations apply 5097 1.1 christos against a readonly section, and set the DF_TEXTREL flag in this 5098 1.1 christos case. */ 5099 1.1 christos 5100 1.1 christos static bool 5101 1.1 christos bfin_discard_copies (struct elf_link_hash_entry *h, void * inf) 5102 1.1 christos { 5103 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *) inf; 5104 1.1 christos struct bfin_pcrel_relocs_copied *s; 5105 1.1 christos 5106 1.1 christos if (!h->def_regular || (!info->symbolic && !h->forced_local)) 5107 1.1 christos { 5108 1.1 christos if ((info->flags & DF_TEXTREL) == 0) 5109 1.1 christos { 5110 1.1 christos /* Look for relocations against read-only sections. */ 5111 1.1 christos for (s = bfin_hash_entry (h)->pcrel_relocs_copied; 5112 1.1 christos s != NULL; s = s->next) 5113 1.1 christos if ((s->section->flags & SEC_READONLY) != 0) 5114 1.1.1.10 christos { 5115 1.1 christos info->flags |= DF_TEXTREL; 5116 1.1 christos break; 5117 1.1 christos } 5118 1.1 christos } 5119 1.1 christos 5120 1.1 christos return true; 5121 1.1.1.10 christos } 5122 1.1 christos 5123 1.1 christos for (s = bfin_hash_entry (h)->pcrel_relocs_copied; 5124 1.1.1.10 christos s != NULL; s = s->next) 5125 1.1.1.11 christos s->section->size -= s->count * sizeof (Elf32_External_Rela); 5126 1.1.1.11 christos 5127 1.1 christos return true; 5128 1.1 christos } 5129 1.1 christos 5130 1.1.1.10 christos static bool 5131 1.1 christos bfin_late_size_sections (bfd * output_bfd ATTRIBUTE_UNUSED, 5132 1.1 christos struct bfd_link_info *info) 5133 1.1.1.11 christos { 5134 1.1.1.11 christos bfd *dynobj; 5135 1.1 christos asection *s; 5136 1.1 christos bool relocs; 5137 1.1 christos 5138 1.1 christos dynobj = elf_hash_table (info)->dynobj; 5139 1.1.1.8 christos if (dynobj == NULL) 5140 1.1 christos return true; 5141 1.1.1.2 christos 5142 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 5143 1.1 christos { 5144 1.1 christos /* Set the contents of the .interp section to the interpreter. */ 5145 1.1 christos if (bfd_link_executable (info) && !info->nointerp) 5146 1.1 christos { 5147 1.1 christos s = bfd_get_linker_section (dynobj, ".interp"); 5148 1.1 christos BFD_ASSERT (s != NULL); 5149 1.1 christos s->size = sizeof ELF_DYNAMIC_INTERPRETER; 5150 1.1.1.8 christos s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 5151 1.1.1.8 christos } 5152 1.1.1.8 christos } 5153 1.1.1.8 christos else 5154 1.1.1.7 christos { 5155 1.1 christos /* We may have created entries in the .rela.got section. 5156 1.1 christos However, if we are not creating the dynamic sections, we will 5157 1.1 christos not actually use these entries. Reset the size of .rela.got, 5158 1.1 christos which will cause it to get stripped from the output file 5159 1.1 christos below. */ 5160 1.1 christos s = elf_hash_table (info)->srelgot; 5161 1.1 christos if (s != NULL) 5162 1.1 christos s->size = 0; 5163 1.1 christos } 5164 1.1 christos 5165 1.1.1.6 christos /* If this is a -Bsymbolic shared link, then we need to discard all 5166 1.1 christos PC relative relocs against symbols defined in a regular object. 5167 1.1.1.2 christos For the normal shared case we discard the PC relative relocs 5168 1.1 christos against symbols that have become local due to visibility changes. 5169 1.1 christos We allocated space for them in the check_relocs routine, but we 5170 1.1 christos will not fill them in in the relocate_section routine. */ 5171 1.1 christos if (bfd_link_pic (info)) 5172 1.1.1.10 christos elf_link_hash_traverse (elf_hash_table (info), 5173 1.1 christos bfin_discard_copies, info); 5174 1.1 christos 5175 1.1 christos /* The check_relocs and adjust_dynamic_symbol entry points have 5176 1.1.1.10 christos determined the sizes of the various dynamic sections. Allocate 5177 1.1 christos memory for them. */ 5178 1.1 christos relocs = false; 5179 1.1 christos for (s = dynobj->sections; s != NULL; s = s->next) 5180 1.1 christos { 5181 1.1 christos const char *name; 5182 1.1.1.8 christos bool strip; 5183 1.1.1.9 christos 5184 1.1 christos if ((s->flags & SEC_LINKER_CREATED) == 0) 5185 1.1.1.10 christos continue; 5186 1.1 christos 5187 1.1.1.10 christos /* It's OK to base decisions on the section name, because none 5188 1.1 christos of the dynobj section names depend upon the input files. */ 5189 1.1 christos name = bfd_section_name (s); 5190 1.1 christos 5191 1.1 christos strip = false; 5192 1.1.1.8 christos 5193 1.1.1.8 christos if (startswith (name, ".rela")) 5194 1.1.1.8 christos { 5195 1.1.1.8 christos if (s->size == 0) 5196 1.1.1.8 christos { 5197 1.1.1.8 christos /* If we don't need this section, strip it from the 5198 1.1.1.8 christos output file. This is mostly to handle .rela.bss and 5199 1.1.1.8 christos .rela.plt. We must create both sections in 5200 1.1.1.10 christos create_dynamic_sections, because they must be created 5201 1.1 christos before the linker maps input sections to output 5202 1.1 christos sections. The linker does that before 5203 1.1 christos adjust_dynamic_symbol is called, and it is that 5204 1.1.1.10 christos function which decides whether anything needs to go 5205 1.1 christos into these sections. */ 5206 1.1 christos strip = true; 5207 1.1.1.8 christos } 5208 1.1 christos else 5209 1.1 christos { 5210 1.1 christos relocs = true; 5211 1.1.1.10 christos 5212 1.1 christos /* We use the reloc_count field as a counter if we need 5213 1.1 christos to copy relocs into the output file. */ 5214 1.1 christos s->reloc_count = 0; 5215 1.1 christos } 5216 1.1 christos } 5217 1.1 christos else if (! startswith (name, ".got")) 5218 1.1 christos { 5219 1.1 christos /* It's not one of our sections, so don't allocate space. */ 5220 1.1 christos continue; 5221 1.1 christos } 5222 1.1 christos 5223 1.1 christos if (strip) 5224 1.1 christos { 5225 1.1.1.8 christos s->flags |= SEC_EXCLUDE; 5226 1.1.1.8 christos continue; 5227 1.1.1.8 christos } 5228 1.1.1.8 christos 5229 1.1 christos /* Allocate memory for the section contents. */ 5230 1.1 christos /* FIXME: This should be a call to bfd_alloc not bfd_zalloc. 5231 1.1.1.10 christos Unused entries should be reclaimed before the section's contents 5232 1.1 christos are written out, but at the moment this does not happen. Thus in 5233 1.1 christos order to prevent writing out garbage, we initialise the section's 5234 1.1 christos contents to zero. */ 5235 1.1 christos s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); 5236 1.1 christos if (s->contents == NULL && s->size != 0) 5237 1.1.1.8 christos return false; 5238 1.1.1.8 christos } 5239 1.1.1.8 christos 5240 1.1.1.8 christos if (elf_hash_table (info)->dynamic_sections_created) 5241 1.1 christos { 5242 1.1 christos /* Add some entries to the .dynamic section. We fill in the 5243 1.1 christos values later, in bfin_finish_dynamic_sections, but we 5244 1.1.1.6 christos must add the entries now so that we get the correct size for 5245 1.1 christos the .dynamic section. The DT_DEBUG entry is filled in by the 5246 1.1 christos dynamic linker and used by the debugger. */ 5247 1.1.1.10 christos #define add_dynamic_entry(TAG, VAL) \ 5248 1.1 christos _bfd_elf_add_dynamic_entry (info, TAG, VAL) 5249 1.1 christos 5250 1.1 christos if (!bfd_link_pic (info)) 5251 1.1 christos { 5252 1.1 christos if (!add_dynamic_entry (DT_DEBUG, 0)) 5253 1.1 christos return false; 5254 1.1 christos } 5255 1.1 christos 5256 1.1 christos 5257 1.1.1.10 christos if (relocs) 5258 1.1 christos { 5259 1.1 christos if (!add_dynamic_entry (DT_RELA, 0) 5260 1.1 christos || !add_dynamic_entry (DT_RELASZ, 0) 5261 1.1 christos || !add_dynamic_entry (DT_RELAENT, 5262 1.1 christos sizeof (Elf32_External_Rela))) 5263 1.1.1.10 christos return false; 5264 1.1 christos } 5265 1.1 christos 5266 1.1 christos if ((info->flags & DF_TEXTREL) != 0) 5267 1.1 christos { 5268 1.1.1.10 christos if (!add_dynamic_entry (DT_TEXTREL, 0)) 5269 1.1 christos return false; 5270 1.1 christos } 5271 1.1 christos } 5272 1.1 christos #undef add_dynamic_entry 5273 1.1 christos 5274 1.1 christos return true; 5275 1.1 christos } 5276 1.1 christos 5277 1.1 christos /* Given a .data section and a .emreloc in-memory section, store 5279 1.1.1.2 christos relocation information into the .emreloc section which can be 5280 1.1.1.2 christos used at runtime to relocate the section. This is called by the 5281 1.1.1.2 christos linker when the --embedded-relocs switch is used. This is called 5282 1.1.1.2 christos after the add_symbols entry point has been called for all the 5283 1.1.1.2 christos objects, and before the final_link entry point is called. */ 5284 1.1 christos 5285 1.1 christos bool 5286 1.1 christos bfd_bfin_elf32_create_embedded_relocs (bfd *abfd, 5287 1.1 christos struct bfd_link_info *info, 5288 1.1 christos asection *datasec, 5289 1.1 christos asection *relsec, 5290 1.1 christos char **errmsg) 5291 1.1 christos { 5292 1.1.1.6 christos Elf_Internal_Shdr *symtab_hdr; 5293 1.1 christos Elf_Internal_Sym *isymbuf = NULL; 5294 1.1 christos Elf_Internal_Rela *internal_relocs = NULL; 5295 1.1 christos Elf_Internal_Rela *irel, *irelend; 5296 1.1 christos bfd_byte *p; 5297 1.1.1.10 christos bfd_size_type amt; 5298 1.1 christos 5299 1.1 christos BFD_ASSERT (! bfd_link_relocatable (info)); 5300 1.1 christos 5301 1.1 christos *errmsg = NULL; 5302 1.1 christos 5303 1.1.1.2 christos if (datasec->reloc_count == 0) 5304 1.1 christos return true; 5305 1.1 christos 5306 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 5307 1.1 christos 5308 1.1 christos /* Get a copy of the native relocations. */ 5309 1.1 christos internal_relocs = (_bfd_elf_link_read_relocs 5310 1.1 christos (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL, 5311 1.1 christos info->keep_memory)); 5312 1.1 christos if (internal_relocs == NULL) 5313 1.1 christos goto error_return; 5314 1.1 christos 5315 1.1 christos amt = (bfd_size_type) datasec->reloc_count * 12; 5316 1.1 christos relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt); 5317 1.1 christos if (relsec->contents == NULL) 5318 1.1 christos goto error_return; 5319 1.1 christos 5320 1.1 christos p = relsec->contents; 5321 1.1 christos 5322 1.1 christos irelend = internal_relocs + datasec->reloc_count; 5323 1.1 christos for (irel = internal_relocs; irel < irelend; irel++, p += 12) 5324 1.1 christos { 5325 1.1 christos asection *targetsec; 5326 1.1 christos 5327 1.1 christos /* We are going to write a four byte longword into the runtime 5328 1.1 christos reloc section. The longword will be the address in the data 5329 1.1.1.8 christos section which must be relocated. It is followed by the name 5330 1.1 christos of the target section NUL-padded or truncated to 8 5331 1.1 christos characters. */ 5332 1.1 christos 5333 1.1 christos /* We can only relocate absolute longword relocs at run time. */ 5334 1.1 christos if (ELF32_R_TYPE (irel->r_info) != (int) R_BFIN_BYTE4_DATA) 5335 1.1 christos { 5336 1.1 christos *errmsg = _("unsupported relocation type"); 5337 1.1 christos bfd_set_error (bfd_error_bad_value); 5338 1.1 christos goto error_return; 5339 1.1 christos } 5340 1.1 christos 5341 1.1 christos /* Get the target section referred to by the reloc. */ 5342 1.1 christos if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 5343 1.1 christos { 5344 1.1 christos /* A local symbol. */ 5345 1.1 christos Elf_Internal_Sym *isym; 5346 1.1 christos 5347 1.1 christos /* Read this BFD's local symbols if we haven't done so already. */ 5348 1.1 christos if (isymbuf == NULL) 5349 1.1 christos { 5350 1.1 christos isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 5351 1.1 christos if (isymbuf == NULL) 5352 1.1 christos isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 5353 1.1 christos symtab_hdr->sh_info, 0, 5354 1.1 christos NULL, NULL, NULL); 5355 1.1 christos if (isymbuf == NULL) 5356 1.1 christos goto error_return; 5357 1.1 christos } 5358 1.1 christos 5359 1.1 christos isym = isymbuf + ELF32_R_SYM (irel->r_info); 5360 1.1 christos targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 5361 1.1 christos } 5362 1.1 christos else 5363 1.1 christos { 5364 1.1 christos unsigned long indx; 5365 1.1 christos struct elf_link_hash_entry *h; 5366 1.1 christos 5367 1.1 christos /* An external symbol. */ 5368 1.1 christos indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; 5369 1.1 christos h = elf_sym_hashes (abfd)[indx]; 5370 1.1 christos BFD_ASSERT (h != NULL); 5371 1.1 christos if (h->root.type == bfd_link_hash_defined 5372 1.1 christos || h->root.type == bfd_link_hash_defweak) 5373 1.1 christos targetsec = h->root.u.def.section; 5374 1.1 christos else 5375 1.1 christos targetsec = NULL; 5376 1.1 christos } 5377 1.1.1.9 christos 5378 1.1 christos bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p); 5379 1.1.1.9 christos memset (p + 4, 0, 8); 5380 1.1 christos if (targetsec != NULL) 5381 1.1.1.10 christos strncpy ((char *) p + 4, targetsec->output_section->name, 8); 5382 1.1 christos } 5383 1.1.1.9 christos 5384 1.1.1.9 christos if (symtab_hdr->contents != (unsigned char *) isymbuf) 5385 1.1 christos free (isymbuf); 5386 1.1.1.9 christos if (elf_section_data (datasec)->relocs != internal_relocs) 5387 1.1 christos free (internal_relocs); 5388 1.1.1.10 christos return true; 5389 1.1 christos 5390 1.1 christos error_return: 5391 1.1 christos if (symtab_hdr->contents != (unsigned char *) isymbuf) 5392 1.1 christos free (isymbuf); 5393 1.1 christos if (elf_section_data (datasec)->relocs != internal_relocs) 5394 1.1 christos free (internal_relocs); 5395 1.1.1.8 christos return false; 5396 1.1 christos } 5397 1.1 christos 5398 1.1 christos struct bfd_elf_special_section const elf32_bfin_special_sections[] = 5399 1.1.1.4 christos { 5400 1.1 christos { ".l1.text", 8, -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR }, 5401 1.1 christos { ".l1.data", 8, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, 5402 1.1 christos { NULL, 0, 0, 0, 0 } 5403 1.1 christos }; 5404 1.1 christos 5405 1.1 christos 5406 1.1 christos #define TARGET_LITTLE_SYM bfin_elf32_vec 5408 1.1 christos #define TARGET_LITTLE_NAME "elf32-bfin" 5409 1.1 christos #define ELF_ARCH bfd_arch_bfin 5410 1.1 christos #define ELF_TARGET_ID BFIN_ELF_DATA 5411 1.1.1.8 christos #define ELF_MACHINE_CODE EM_BLACKFIN 5412 1.1 christos #define ELF_MAXPAGESIZE 0x1000 5413 1.1 christos #define elf_symbol_leading_char '_' 5414 1.1 christos 5415 1.1.1.8 christos #define bfd_elf32_bfd_reloc_type_lookup bfin_bfd_reloc_type_lookup 5416 1.1 christos #define bfd_elf32_bfd_reloc_name_lookup \ 5417 1.1 christos bfin_bfd_reloc_name_lookup 5418 1.1.1.8 christos #define elf_info_to_howto bfin_info_to_howto 5419 1.1 christos #define elf_info_to_howto_rel NULL 5420 1.1.1.8 christos #define elf_backend_object_p elf32_bfin_object_p 5421 1.1.1.8 christos 5422 1.1 christos #define bfd_elf32_bfd_is_local_label_name \ 5423 1.1.1.8 christos bfin_is_local_label_name 5424 1.1 christos 5425 1.1.1.8 christos #define elf_backend_create_dynamic_sections \ 5426 1.1.1.11 christos _bfd_elf_create_dynamic_sections 5427 1.1.1.8 christos #define bfd_elf32_bfd_link_hash_table_create \ 5428 1.1 christos bfin_link_hash_table_create 5429 1.1.1.8 christos #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link 5430 1.1 christos 5431 1.1.1.8 christos #define elf_backend_check_relocs bfin_check_relocs 5432 1.1.1.8 christos #define elf_backend_adjust_dynamic_symbol \ 5433 1.1 christos bfin_adjust_dynamic_symbol 5434 1.1.1.8 christos #define elf_backend_late_size_sections bfin_late_size_sections 5435 1.1 christos #define elf_backend_relocate_section bfin_relocate_section 5436 1.1.1.8 christos #define elf_backend_finish_dynamic_symbol \ 5437 1.1 christos bfin_finish_dynamic_symbol 5438 1.1.1.8 christos #define elf_backend_finish_dynamic_sections \ 5439 1.1 christos bfin_finish_dynamic_sections 5440 1.1.1.8 christos #define elf_backend_gc_mark_hook bfin_gc_mark_hook 5441 1.1.1.8 christos #define bfd_elf32_bfd_merge_private_bfd_data \ 5442 1.1.1.2 christos elf32_bfin_merge_private_bfd_data 5443 1.1 christos #define bfd_elf32_bfd_set_private_flags \ 5444 1.1 christos elf32_bfin_set_private_flags 5445 1.1 christos #define bfd_elf32_bfd_print_private_bfd_data \ 5446 1.1 christos elf32_bfin_print_private_bfd_data 5447 1.1 christos #define elf_backend_final_write_processing \ 5448 1.1 christos elf32_bfin_final_write_processing 5449 1.1.1.8 christos #define elf_backend_reloc_type_class elf32_bfin_reloc_type_class 5450 1.1.1.8 christos #define elf_backend_stack_align 8 5451 1.1 christos #define elf_backend_can_gc_sections 1 5452 1.1 christos #define elf_backend_special_sections elf32_bfin_special_sections 5453 1.1 christos #define elf_backend_can_refcount 1 5454 1.1 christos #define elf_backend_want_got_plt 0 5455 1.1.1.8 christos #define elf_backend_plt_readonly 1 5456 1.1 christos #define elf_backend_want_plt_sym 0 5457 1.1 christos #define elf_backend_got_header_size 12 5458 1.1 christos #define elf_backend_rela_normal 1 5459 1.1.1.8 christos 5460 1.1 christos #include "elf32-target.h" 5461 1.1 christos 5462 1.1.1.8 christos #undef TARGET_LITTLE_SYM 5463 1.1 christos #define TARGET_LITTLE_SYM bfin_elf32_fdpic_vec 5464 1.1 christos #undef TARGET_LITTLE_NAME 5465 1.1.1.8 christos #define TARGET_LITTLE_NAME "elf32-bfinfdpic" 5466 1.1 christos #undef elf32_bed 5467 1.1.1.8 christos #define elf32_bed elf32_bfinfdpic_bed 5468 1.1 christos 5469 1.1 christos #undef elf_backend_got_header_size 5470 1.1 christos #define elf_backend_got_header_size 0 5471 1.1 christos 5472 1.1.1.11 christos #undef elf_backend_relocate_section 5473 1.1.1.11 christos #define elf_backend_relocate_section bfinfdpic_relocate_section 5474 1.1.1.11 christos #undef elf_backend_check_relocs 5475 1.1 christos #define elf_backend_check_relocs bfinfdpic_check_relocs 5476 1.1 christos 5477 1.1 christos #undef bfd_elf32_bfd_link_hash_table_create 5478 1.1 christos #define bfd_elf32_bfd_link_hash_table_create \ 5479 1.1 christos bfinfdpic_elf_link_hash_table_create 5480 1.1 christos #undef elf_backend_early_size_sections 5481 1.1 christos #define elf_backend_early_size_sections \ 5482 1.1.1.11 christos elf32_bfinfdpic_early_size_sections 5483 1.1.1.11 christos 5484 1.1.1.11 christos #undef elf_backend_create_dynamic_sections 5485 1.1 christos #define elf_backend_create_dynamic_sections \ 5486 1.1 christos elf32_bfinfdpic_create_dynamic_sections 5487 1.1 christos #undef elf_backend_adjust_dynamic_symbol 5488 1.1 christos #define elf_backend_adjust_dynamic_symbol \ 5489 1.1 christos elf32_bfinfdpic_adjust_dynamic_symbol 5490 1.1 christos #undef elf_backend_late_size_sections 5491 1.1 christos #define elf_backend_late_size_sections \ 5492 1.1 christos elf32_bfinfdpic_late_size_sections 5493 1.1 christos #undef elf_backend_finish_dynamic_symbol 5494 1.1 christos #define elf_backend_finish_dynamic_symbol \ 5495 1.1 christos elf32_bfinfdpic_finish_dynamic_symbol 5496 1.1 christos #undef elf_backend_finish_dynamic_sections 5497 1.1 christos #define elf_backend_finish_dynamic_sections \ 5498 1.1 christos elf32_bfinfdpic_finish_dynamic_sections 5499 1.1 christos 5500 1.1 christos #undef elf_backend_discard_info 5501 1.1 christos #define elf_backend_discard_info \ 5502 1.1 christos bfinfdpic_elf_discard_info 5503 1.1 christos #undef elf_backend_can_make_relative_eh_frame 5504 1.1 christos #define elf_backend_can_make_relative_eh_frame \ 5505 1.1 christos bfinfdpic_elf_use_relative_eh_frame 5506 1.1.1.8 christos #undef elf_backend_can_make_lsda_relative_eh_frame 5507 1.1 christos #define elf_backend_can_make_lsda_relative_eh_frame \ 5508 1.1.1.8 christos bfinfdpic_elf_use_relative_eh_frame 5509 1.1 christos #undef elf_backend_encode_eh_address 5510 1.1 christos #define elf_backend_encode_eh_address \ 5511 1.1.1.8 christos bfinfdpic_elf_encode_eh_address 5512 1.1 christos 5513 1.1 christos #undef elf_backend_may_use_rel_p 5514 1.1 christos #define elf_backend_may_use_rel_p 1 5515 1.1 christos #undef elf_backend_may_use_rela_p 5516 1.1 christos #define elf_backend_may_use_rela_p 1 5517 /* We use REL for dynamic relocations only. */ 5518 #undef elf_backend_default_use_rela_p 5519 #define elf_backend_default_use_rela_p 1 5520 5521 #undef elf_backend_omit_section_dynsym 5522 #define elf_backend_omit_section_dynsym _bfinfdpic_link_omit_section_dynsym 5523 5524 #include "elf32-target.h" 5525