Changeset 609 for branches/GNU/src/binutils/bfd/elf32-m68k.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf32-m68k.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Motorola 68k series support for 32-bit ELF 2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001 2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 3 3 Free Software Foundation, Inc. 4 4 5 This file is part of BFD, the Binary File Descriptor library.6 7 This program is free software; you can redistribute it and/or modify8 it under the terms of the GNU General Public License as published by9 the Free Software Foundation; either version 2 of the License, or10 (at your option) any later version.11 12 This program is distributed in the hope that it will be useful,13 but WITHOUT ANY WARRANTY; without even the implied warranty of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU General Public License for more details.16 17 You should have received a copy of the GNU General Public License18 along with this program; if not, write to the Free Software19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */5 This file is part of BFD, the Binary File Descriptor library. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 20 21 21 #include "bfd.h" … … 29 29 PARAMS ((bfd *, bfd_reloc_code_real_type)); 30 30 static void rtype_to_howto 31 PARAMS ((bfd *, arelent *, Elf 32_Internal_Rela *));31 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 32 32 static struct bfd_hash_entry *elf_m68k_link_hash_newfunc 33 33 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); 34 34 static struct bfd_link_hash_table *elf_m68k_link_hash_table_create 35 35 PARAMS ((bfd *)); 36 static b oolean elf_m68k_check_relocs36 static bfd_boolean elf_m68k_check_relocs 37 37 PARAMS ((bfd *, struct bfd_link_info *, asection *, 38 38 const Elf_Internal_Rela *)); 39 39 static asection *elf_m68k_gc_mark_hook 40 PARAMS (( bfd*, struct bfd_link_info *, Elf_Internal_Rela *,40 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 41 41 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 42 static b oolean elf_m68k_gc_sweep_hook42 static bfd_boolean elf_m68k_gc_sweep_hook 43 43 PARAMS ((bfd *, struct bfd_link_info *, asection *, 44 44 const Elf_Internal_Rela *)); 45 static b oolean elf_m68k_adjust_dynamic_symbol45 static bfd_boolean elf_m68k_adjust_dynamic_symbol 46 46 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); 47 static b oolean elf_m68k_size_dynamic_sections47 static bfd_boolean elf_m68k_size_dynamic_sections 48 48 PARAMS ((bfd *, struct bfd_link_info *)); 49 static boolean elf_m68k_relocate_section 49 static bfd_boolean elf_m68k_discard_copies 50 PARAMS ((struct elf_link_hash_entry *, PTR)); 51 static bfd_boolean elf_m68k_relocate_section 50 52 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 51 53 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 52 static b oolean elf_m68k_finish_dynamic_symbol54 static bfd_boolean elf_m68k_finish_dynamic_symbol 53 55 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, 54 56 Elf_Internal_Sym *)); 55 static b oolean elf_m68k_finish_dynamic_sections57 static bfd_boolean elf_m68k_finish_dynamic_sections 56 58 PARAMS ((bfd *, struct bfd_link_info *)); 57 59 58 static b oolean elf32_m68k_set_private_flags60 static bfd_boolean elf32_m68k_set_private_flags 59 61 PARAMS ((bfd *, flagword)); 60 static b oolean elf32_m68k_copy_private_bfd_data62 static bfd_boolean elf32_m68k_merge_private_bfd_data 61 63 PARAMS ((bfd *, bfd *)); 62 static boolean elf32_m68k_merge_private_bfd_data 63 PARAMS ((bfd *, bfd *)); 64 static boolean elf32_m68k_print_private_bfd_data 64 static bfd_boolean elf32_m68k_print_private_bfd_data 65 65 PARAMS ((bfd *, PTR)); 66 static enum elf_reloc_type_class elf32_m68k_reloc_type_class 67 PARAMS ((const Elf_Internal_Rela *)); 66 68 67 69 static reloc_howto_type howto_table[] = { 68 HOWTO(R_68K_NONE, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", false, 0, 0x00000000,false),69 HOWTO(R_68K_32, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", false, 0, 0xffffffff,false),70 HOWTO(R_68K_16, 0, 1,16, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", false, 0, 0x0000ffff,false),71 HOWTO(R_68K_8, 0, 0, 8, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", false, 0, 0x000000ff,false),72 HOWTO(R_68K_PC32, 0, 2,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", false, 0, 0xffffffff,true),73 HOWTO(R_68K_PC16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", false, 0, 0x0000ffff,true),74 HOWTO(R_68K_PC8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", false, 0, 0x000000ff,true),75 HOWTO(R_68K_GOT32, 0, 2,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", false, 0, 0xffffffff,true),76 HOWTO(R_68K_GOT16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", false, 0, 0x0000ffff,true),77 HOWTO(R_68K_GOT8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", false, 0, 0x000000ff,true),78 HOWTO(R_68K_GOT32O, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", false, 0, 0xffffffff,false),79 HOWTO(R_68K_GOT16O, 0, 1,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", false, 0, 0x0000ffff,false),80 HOWTO(R_68K_GOT8O, 0, 0, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", false, 0, 0x000000ff,false),81 HOWTO(R_68K_PLT32, 0, 2,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", false, 0, 0xffffffff,true),82 HOWTO(R_68K_PLT16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", false, 0, 0x0000ffff,true),83 HOWTO(R_68K_PLT8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", false, 0, 0x000000ff,true),84 HOWTO(R_68K_PLT32O, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", false, 0, 0xffffffff,false),85 HOWTO(R_68K_PLT16O, 0, 1,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", false, 0, 0x0000ffff,false),86 HOWTO(R_68K_PLT8O, 0, 0, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", false, 0, 0x000000ff,false),87 HOWTO(R_68K_COPY, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", false, 0, 0xffffffff,false),88 HOWTO(R_68K_GLOB_DAT, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", false, 0, 0xffffffff,false),89 HOWTO(R_68K_JMP_SLOT, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", false, 0, 0xffffffff,false),90 HOWTO(R_68K_RELATIVE, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", false, 0, 0xffffffff,false),91 /* GNU extension to record C++ vtable hierarchy */70 HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE), 71 HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE), 72 HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE), 73 HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE), 74 HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE), 75 HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE), 76 HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE), 77 HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE), 78 HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE), 79 HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE), 80 HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE), 81 HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE), 82 HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE), 83 HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE), 84 HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE), 85 HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE), 86 HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE), 87 HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE), 88 HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE), 89 HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE), 90 HOWTO(R_68K_GLOB_DAT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", FALSE, 0, 0xffffffff,FALSE), 91 HOWTO(R_68K_JMP_SLOT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", FALSE, 0, 0xffffffff,FALSE), 92 HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE), 93 /* GNU extension to record C++ vtable hierarchy. */ 92 94 HOWTO (R_68K_GNU_VTINHERIT, /* type */ 93 95 0, /* rightshift */ 94 96 2, /* size (0 = byte, 1 = short, 2 = long) */ 95 97 0, /* bitsize */ 96 false, /* pc_relative */98 FALSE, /* pc_relative */ 97 99 0, /* bitpos */ 98 100 complain_overflow_dont, /* complain_on_overflow */ 99 101 NULL, /* special_function */ 100 102 "R_68K_GNU_VTINHERIT", /* name */ 101 false, /* partial_inplace */103 FALSE, /* partial_inplace */ 102 104 0, /* src_mask */ 103 105 0, /* dst_mask */ 104 false),105 /* GNU extension to record C++ vtable member usage */106 FALSE), 107 /* GNU extension to record C++ vtable member usage. */ 106 108 HOWTO (R_68K_GNU_VTENTRY, /* type */ 107 109 0, /* rightshift */ 108 110 2, /* size (0 = byte, 1 = short, 2 = long) */ 109 111 0, /* bitsize */ 110 false, /* pc_relative */112 FALSE, /* pc_relative */ 111 113 0, /* bitpos */ 112 114 complain_overflow_dont, /* complain_on_overflow */ 113 115 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 114 116 "R_68K_GNU_VTENTRY", /* name */ 115 false, /* partial_inplace */117 FALSE, /* partial_inplace */ 116 118 0, /* src_mask */ 117 119 0, /* dst_mask */ 118 false),120 FALSE), 119 121 }; 120 122 … … 180 182 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup 181 183 #define ELF_ARCH bfd_arch_m68k 182 /* end code generated by elf.el */183 184 #define USE_RELA185 184 186 185 … … 276 275 }; 277 276 277 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent)) 278 278 279 /* m68k ELF linker hash table. */ 279 280 … … 281 282 { 282 283 struct elf_link_hash_table root; 284 285 /* Small local sym to section mapping cache. */ 286 struct sym_sec_cache sym_sec; 283 287 }; 284 285 /* Declare this now that the above structures are defined. */286 287 static boolean elf_m68k_discard_copies288 PARAMS ((struct elf_m68k_link_hash_entry *, PTR));289 290 /* Traverse an m68k ELF linker hash table. */291 292 #define elf_m68k_link_hash_traverse(table, func, info) \293 (elf_link_hash_traverse \294 (&(table)->root, \295 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \296 (info)))297 288 298 289 /* Get the m68k ELF linker hash table from a link_info structure. */ … … 309 300 const char *string; 310 301 { 311 struct elf_m68k_link_hash_entry *ret = 312 (struct elf_m68k_link_hash_entry *) entry; 302 struct bfd_hash_entry *ret = entry; 313 303 314 304 /* Allocate the structure if it has not already been allocated by a 315 305 subclass. */ 316 if (ret == (struct elf_m68k_link_hash_entry *) NULL) 317 ret = ((struct elf_m68k_link_hash_entry *) 318 bfd_hash_allocate (table, 319 sizeof (struct elf_m68k_link_hash_entry))); 320 if (ret == (struct elf_m68k_link_hash_entry *) NULL) 321 return (struct bfd_hash_entry *) ret; 306 if (ret == NULL) 307 ret = bfd_hash_allocate (table, 308 sizeof (struct elf_m68k_link_hash_entry)); 309 if (ret == NULL) 310 return ret; 322 311 323 312 /* Call the allocation method of the superclass. */ 324 ret = ((struct elf_m68k_link_hash_entry *) 325 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 326 table, string)); 327 if (ret != (struct elf_m68k_link_hash_entry *) NULL) 328 { 329 ret->pcrel_relocs_copied = NULL; 330 } 331 332 return (struct bfd_hash_entry *) ret; 313 ret = _bfd_elf_link_hash_newfunc (ret, table, string); 314 if (ret != NULL) 315 elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL; 316 317 return ret; 333 318 } 334 319 … … 340 325 { 341 326 struct elf_m68k_link_hash_table *ret; 342 343 ret = ((struct elf_m68k_link_hash_table *) 344 bfd_alloc (abfd, sizeof (struct elf_m68k_link_hash_table)));327 bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table); 328 329 ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt); 345 330 if (ret == (struct elf_m68k_link_hash_table *) NULL) 346 331 return NULL; … … 349 334 elf_m68k_link_hash_newfunc)) 350 335 { 351 bfd_release (abfd,ret);336 free (ret); 352 337 return NULL; 353 338 } 354 339 340 ret->sym_sec.abfd = NULL; 341 355 342 return &ret->root.root; 356 343 } 357 344 358 /* Keep m68k-specific flags in the ELF header */359 static b oolean345 /* Keep m68k-specific flags in the ELF header. */ 346 static bfd_boolean 360 347 elf32_m68k_set_private_flags (abfd, flags) 361 348 bfd *abfd; … … 363 350 { 364 351 elf_elfheader (abfd)->e_flags = flags; 365 elf_flags_init (abfd) = true; 366 return true; 367 } 368 369 /* Copy m68k-specific data from one module to another */ 370 static boolean 371 elf32_m68k_copy_private_bfd_data (ibfd, obfd) 372 bfd *ibfd; 373 bfd *obfd; 374 { 375 flagword in_flags; 376 377 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 378 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 379 return true; 380 381 in_flags = elf_elfheader (ibfd)->e_flags; 382 383 elf_elfheader (obfd)->e_flags = in_flags; 384 elf_flags_init (obfd) = true; 385 386 return true; 352 elf_flags_init (abfd) = TRUE; 353 return TRUE; 387 354 } 388 355 389 356 /* Merge backend specific data from an object file to the output 390 357 object file when linking. */ 391 static b oolean358 static bfd_boolean 392 359 elf32_m68k_merge_private_bfd_data (ibfd, obfd) 393 360 bfd *ibfd; … … 399 366 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour 400 367 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 401 return true;368 return TRUE; 402 369 403 370 in_flags = elf_elfheader (ibfd)->e_flags; … … 406 373 if (!elf_flags_init (obfd)) 407 374 { 408 elf_flags_init (obfd) = true;375 elf_flags_init (obfd) = TRUE; 409 376 elf_elfheader (obfd)->e_flags = in_flags; 410 377 } 411 378 412 return true;379 return TRUE; 413 380 } 414 381 415 /* Display the flags field */416 static b oolean382 /* Display the flags field. */ 383 static bfd_boolean 417 384 elf32_m68k_print_private_bfd_data (abfd, ptr) 418 385 bfd *abfd; … … 429 396 430 397 /* xgettext:c-format */ 431 fprintf (file, _ 398 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); 432 399 433 400 if (elf_elfheader (abfd)->e_flags & EF_CPU32) 434 fprintf (file, _ (" [cpu32]")); 401 fprintf (file, _(" [cpu32]")); 402 403 if (elf_elfheader (abfd)->e_flags & EF_M68000) 404 fprintf (file, _(" [m68000]")); 435 405 436 406 fputc ('\n', file); 437 407 438 return true;408 return TRUE; 439 409 } 440 410 /* Look through the relocs for a section during the first phase, and … … 442 412 table. */ 443 413 444 static b oolean414 static bfd_boolean 445 415 elf_m68k_check_relocs (abfd, info, sec, relocs) 446 416 bfd *abfd; … … 460 430 461 431 if (info->relocateable) 462 return true;432 return TRUE; 463 433 464 434 dynobj = elf_hash_table (info)->dynobj; … … 503 473 elf_hash_table (info)->dynobj = dynobj = abfd; 504 474 if (!_bfd_elf_create_got_section (dynobj, info)) 505 return false;475 return FALSE; 506 476 } 507 477 … … 528 498 | SEC_READONLY)) 529 499 || !bfd_set_section_alignment (dynobj, srelgot, 2)) 530 return false;500 return FALSE; 531 501 } 532 502 } … … 534 504 if (h != NULL) 535 505 { 536 if (h->got.refcount == -1)506 if (h->got.refcount == 0) 537 507 { 538 h->got.refcount = 1;539 540 508 /* Make sure this symbol is output as a dynamic symbol. */ 541 if (h->dynindx == -1) 509 if (h->dynindx == -1 510 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 542 511 { 543 512 if (!bfd_elf32_link_record_dynamic_symbol (info, h)) 544 return false;513 return FALSE; 545 514 } 546 515 … … 550 519 srelgot->_raw_size += sizeof (Elf32_External_Rela); 551 520 } 552 else 553 h->got.refcount++; 521 h->got.refcount++; 554 522 } 555 523 else … … 558 526 if (local_got_refcounts == NULL) 559 527 { 560 size_t size; 561 562 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma); 528 bfd_size_type size; 529 530 size = symtab_hdr->sh_info; 531 size *= sizeof (bfd_signed_vma); 563 532 local_got_refcounts = ((bfd_signed_vma *) 564 bfd_ alloc (abfd, size));533 bfd_zalloc (abfd, size)); 565 534 if (local_got_refcounts == NULL) 566 return false;535 return FALSE; 567 536 elf_local_got_refcounts (abfd) = local_got_refcounts; 568 memset (local_got_refcounts, -1, size);569 537 } 570 if (local_got_refcounts[r_symndx] == -1)538 if (local_got_refcounts[r_symndx] == 0) 571 539 { 572 local_got_refcounts[r_symndx] = 1;573 574 540 sgot->_raw_size += 4; 575 541 if (info->shared) … … 581 547 } 582 548 } 583 else 584 local_got_refcounts[r_symndx]++; 549 local_got_refcounts[r_symndx]++; 585 550 } 586 551 break; … … 602 567 603 568 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 604 if (h->plt.refcount == -1) 605 h->plt.refcount = 1; 606 else 607 h->plt.refcount++; 569 h->plt.refcount++; 608 570 break; 609 571 … … 619 581 it does make sense? */ 620 582 bfd_set_error (bfd_error_bad_value); 621 return false;583 return FALSE; 622 584 } 623 585 624 586 /* Make sure this symbol is output as a dynamic symbol. */ 625 if (h->dynindx == -1) 587 if (h->dynindx == -1 588 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 626 589 { 627 590 if (!bfd_elf32_link_record_dynamic_symbol (info, h)) 628 return false;591 return FALSE; 629 592 } 630 593 631 594 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 632 if (h->plt.refcount == -1) 633 h->plt.refcount = 1; 634 else 635 h->plt.refcount++; 595 h->plt.refcount++; 636 596 break; 637 597 … … 653 613 && h != NULL 654 614 && (!info->symbolic 615 || h->root.type == bfd_link_hash_defweak 655 616 || (h->elf_link_hash_flags 656 617 & ELF_LINK_HASH_DEF_REGULAR) == 0))) … … 661 622 it turns out to be a function defined by a dynamic 662 623 object. */ 663 if (h->plt.refcount == -1) 664 h->plt.refcount = 1; 665 else 666 h->plt.refcount++; 624 h->plt.refcount++; 667 625 } 668 626 break; … … 676 634 /* Make sure a plt entry is created for this symbol if it 677 635 turns out to be a function defined by a dynamic object. */ 678 if (h->plt.refcount == -1) 679 h->plt.refcount = 1; 680 else 681 h->plt.refcount++; 636 h->plt.refcount++; 682 637 } 683 638 … … 699 654 elf_section_data (sec)->rel_hdr.sh_name)); 700 655 if (name == NULL) 701 return false;656 return FALSE; 702 657 703 658 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 … … 718 673 | SEC_READONLY)) 719 674 || !bfd_set_section_alignment (dynobj, sreloc, 2)) 720 return false;675 return FALSE; 721 676 } 722 677 } 723 678 679 if (sec->flags & SEC_READONLY 680 /* Don't set DF_TEXTREL yet for PC relative 681 relocations, they might be discarded later. */ 682 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8 683 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 684 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)) 685 info->flags |= DF_TEXTREL; 686 724 687 sreloc->_raw_size += sizeof (Elf32_External_Rela); 725 688 726 /* If we are linking with -Bsymbolic, we count the number of 727 PC relative relocations we have entered for this symbol, 728 so that we can discard them again if the symbol is later 729 defined by a regular object. Note that this function is 730 only called if we are using an m68kelf linker hash table, 731 which means that h is really a pointer to an 689 /* We count the number of PC relative relocations we have 690 entered for this symbol, so that we can discard them 691 again if, in the -Bsymbolic case, the symbol is later 692 defined by a regular object, or, in the normal shared 693 case, the symbol is forced to be local. Note that this 694 function is only called if we are using an m68kelf linker 695 hash table, which means that h is really a pointer to an 732 696 elf_m68k_link_hash_entry. */ 733 if ((ELF32_R_TYPE (rel->r_info) == R_68K_PC8 734 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 735 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32) 736 && info->symbolic) 697 if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8 698 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 699 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32) 737 700 { 738 struct elf_m68k_link_hash_entry *eh;739 701 struct elf_m68k_pcrel_relocs_copied *p; 740 741 eh = (struct elf_m68k_link_hash_entry *) h; 742 743 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next) 702 struct elf_m68k_pcrel_relocs_copied **head; 703 704 if (h != NULL) 705 { 706 struct elf_m68k_link_hash_entry *eh 707 = elf_m68k_hash_entry (h); 708 head = &eh->pcrel_relocs_copied; 709 } 710 else 711 { 712 asection *s; 713 s = (bfd_section_from_r_symndx 714 (abfd, &elf_m68k_hash_table (info)->sym_sec, 715 sec, r_symndx)); 716 if (s == NULL) 717 return FALSE; 718 719 head = ((struct elf_m68k_pcrel_relocs_copied **) 720 &elf_section_data (s)->local_dynrel); 721 } 722 723 for (p = *head; p != NULL; p = p->next) 744 724 if (p->section == sreloc) 745 725 break; … … 748 728 { 749 729 p = ((struct elf_m68k_pcrel_relocs_copied *) 750 bfd_alloc (dynobj, sizeof *p));730 bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); 751 731 if (p == NULL) 752 return false;753 p->next = eh->pcrel_relocs_copied;754 eh->pcrel_relocs_copied = p;732 return FALSE; 733 p->next = *head; 734 *head = p; 755 735 p->section = sreloc; 756 736 p->count = 0; … … 767 747 case R_68K_GNU_VTINHERIT: 768 748 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 769 return false;749 return FALSE; 770 750 break; 771 751 … … 774 754 case R_68K_GNU_VTENTRY: 775 755 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 776 return false;756 return FALSE; 777 757 break; 778 758 … … 782 762 } 783 763 784 return true;764 return TRUE; 785 765 } 786 766 … … 789 769 790 770 static asection * 791 elf_m68k_gc_mark_hook ( abfd, info, rel, h, sym)792 bfd *abfd;771 elf_m68k_gc_mark_hook (sec, info, rel, h, sym) 772 asection *sec; 793 773 struct bfd_link_info *info ATTRIBUTE_UNUSED; 794 774 Elf_Internal_Rela *rel; … … 820 800 } 821 801 else 822 { 823 if (!(elf_bad_symtab (abfd) 824 && ELF_ST_BIND (sym->st_info) != STB_LOCAL) 825 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) 826 && sym->st_shndx != SHN_COMMON)) 827 { 828 return bfd_section_from_elf_index (abfd, sym->st_shndx); 829 } 830 } 802 return bfd_section_from_elf_index (sec->owner, sym->st_shndx); 831 803 832 804 return NULL; … … 835 807 /* Update the got entry reference counts for the section being removed. */ 836 808 837 static b oolean809 static bfd_boolean 838 810 elf_m68k_gc_sweep_hook (abfd, info, sec, relocs) 839 811 bfd *abfd; … … 858 830 dynobj = elf_hash_table (info)->dynobj; 859 831 if (dynobj == NULL) 860 return true;832 return TRUE; 861 833 862 834 sgot = bfd_get_section_by_name (dynobj, ".got"); … … 931 903 } 932 904 933 return true;905 return TRUE; 934 906 } 935 907 … … 940 912 understand. */ 941 913 942 static b oolean914 static bfd_boolean 943 915 elf_m68k_adjust_dynamic_symbol (info, h) 944 916 struct bfd_link_info *info; … … 983 955 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0); 984 956 h->plt.offset = (bfd_vma) -1; 985 return true;957 return TRUE; 986 958 } 987 959 … … 991 963 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 992 964 h->plt.offset = (bfd_vma) -1; 993 return true;965 return TRUE; 994 966 } 995 967 996 968 /* Make sure this symbol is output as a dynamic symbol. */ 997 if (h->dynindx == -1) 969 if (h->dynindx == -1 970 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 998 971 { 999 972 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 1000 return false;973 return FALSE; 1001 974 } 1002 975 … … 1036 1009 /* We also need to make an entry in the .got.plt section, which 1037 1010 will be placed in the .got section by the linker script. */ 1038 1039 1011 s = bfd_get_section_by_name (dynobj, ".got.plt"); 1040 1012 BFD_ASSERT (s != NULL); … … 1042 1014 1043 1015 /* We also need to make an entry in the .rela.plt section. */ 1044 1045 1016 s = bfd_get_section_by_name (dynobj, ".rela.plt"); 1046 1017 BFD_ASSERT (s != NULL); 1047 1018 s->_raw_size += sizeof (Elf32_External_Rela); 1048 1019 1049 return true;1020 return TRUE; 1050 1021 } 1051 1022 … … 1063 1034 h->root.u.def.section = h->weakdef->root.u.def.section; 1064 1035 h->root.u.def.value = h->weakdef->root.u.def.value; 1065 return true;1036 return TRUE; 1066 1037 } 1067 1038 … … 1074 1045 be handled correctly by relocate_section. */ 1075 1046 if (info->shared) 1076 return true;1047 return TRUE; 1077 1048 1078 1049 /* We must allocate the symbol in our .dynbss section, which will … … 1115 1086 { 1116 1087 if (!bfd_set_section_alignment (dynobj, s, power_of_two)) 1117 return false;1088 return FALSE; 1118 1089 } 1119 1090 … … 1125 1096 s->_raw_size += h->size; 1126 1097 1127 return true;1098 return TRUE; 1128 1099 } 1129 1100 1101 /* This is the condition under which elf_m68k_finish_dynamic_symbol 1102 will be called from elflink.h. If elflink.h doesn't call our 1103 finish_dynamic_symbol routine, we'll need to do something about 1104 initializing any .plt and .got entries in elf_m68k_relocate_section. */ 1105 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \ 1106 ((DYN) \ 1107 && ((SHARED) \ 1108 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ 1109 && ((H)->dynindx != -1 \ 1110 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) 1111 1130 1112 /* Set the sizes of the dynamic sections. */ 1131 1113 1132 static b oolean1114 static bfd_boolean 1133 1115 elf_m68k_size_dynamic_sections (output_bfd, info) 1134 bfd *output_bfd ;1116 bfd *output_bfd ATTRIBUTE_UNUSED; 1135 1117 struct bfd_link_info *info; 1136 1118 { 1137 1119 bfd *dynobj; 1138 1120 asection *s; 1139 boolean plt; 1140 boolean relocs; 1141 boolean reltext; 1121 bfd_boolean plt; 1122 bfd_boolean relocs; 1142 1123 1143 1124 dynobj = elf_hash_table (info)->dynobj; … … 1167 1148 } 1168 1149 1169 /* If this is a -Bsymbolic shared link, then we need to discard all PC 1170 relative relocs against symbols defined in a regular object. We 1171 allocated space for them in the check_relocs routine, but we will not 1172 fill them in in the relocate_section routine. */ 1173 if (info->shared && info->symbolic) 1174 elf_m68k_link_hash_traverse (elf_m68k_hash_table (info), 1175 elf_m68k_discard_copies, 1176 (PTR) NULL); 1150 /* If this is a -Bsymbolic shared link, then we need to discard all 1151 PC relative relocs against symbols defined in a regular object. 1152 For the normal shared case we discard the PC relative relocs 1153 against symbols that have become local due to visibility changes. 1154 We allocated space for them in the check_relocs routine, but we 1155 will not fill them in in the relocate_section routine. */ 1156 if (info->shared) 1157 elf_link_hash_traverse (elf_hash_table (info), 1158 elf_m68k_discard_copies, 1159 (PTR) info); 1177 1160 1178 1161 /* The check_relocs and adjust_dynamic_symbol entry points have 1179 1162 determined the sizes of the various dynamic sections. Allocate 1180 1163 memory for them. */ 1181 plt = false; 1182 relocs = false; 1183 reltext = false; 1164 plt = FALSE; 1165 relocs = FALSE; 1184 1166 for (s = dynobj->sections; s != NULL; s = s->next) 1185 1167 { 1186 1168 const char *name; 1187 b oolean strip;1169 bfd_boolean strip; 1188 1170 1189 1171 if ((s->flags & SEC_LINKER_CREATED) == 0) … … 1194 1176 name = bfd_get_section_name (dynobj, s); 1195 1177 1196 strip = false;1178 strip = FALSE; 1197 1179 1198 1180 if (strcmp (name, ".plt") == 0) … … 1202 1184 /* Strip this section if we don't need it; see the 1203 1185 comment below. */ 1204 strip = true;1186 strip = TRUE; 1205 1187 } 1206 1188 else 1207 1189 { 1208 1190 /* Remember whether there is a PLT. */ 1209 plt = true;1191 plt = TRUE; 1210 1192 } 1211 1193 } … … 1223 1205 function which decides whether anything needs to go 1224 1206 into these sections. */ 1225 strip = true;1207 strip = TRUE; 1226 1208 } 1227 1209 else 1228 1210 { 1229 asection *target; 1230 1231 /* Remember whether there are any reloc sections other 1232 than .rela.plt. */ 1233 if (strcmp (name, ".rela.plt") != 0) 1234 { 1235 const char *outname; 1236 1237 relocs = true; 1238 1239 /* If this relocation section applies to a read only 1240 section, then we probably need a DT_TEXTREL 1241 entry. .rela.plt is actually associated with 1242 .got.plt, which is never readonly. */ 1243 outname = bfd_get_section_name (output_bfd, 1244 s->output_section); 1245 target = bfd_get_section_by_name (output_bfd, outname + 5); 1246 if (target != NULL 1247 && (target->flags & SEC_READONLY) != 0 1248 && (target->flags & SEC_ALLOC) != 0) 1249 reltext = true; 1250 } 1211 relocs = TRUE; 1251 1212 1252 1213 /* We use the reloc_count field as a counter if we need … … 1275 1236 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); 1276 1237 if (s->contents == NULL && s->_raw_size != 0) 1277 return false;1238 return FALSE; 1278 1239 } 1279 1240 … … 1285 1246 the .dynamic section. The DT_DEBUG entry is filled in by the 1286 1247 dynamic linker and used by the debugger. */ 1248 #define add_dynamic_entry(TAG, VAL) \ 1249 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) 1250 1287 1251 if (!info->shared) 1288 1252 { 1289 if (! bfd_elf32_add_dynamic_entry (info,DT_DEBUG, 0))1290 return false;1253 if (!add_dynamic_entry (DT_DEBUG, 0)) 1254 return FALSE; 1291 1255 } 1292 1256 1293 1257 if (plt) 1294 1258 { 1295 if (! bfd_elf32_add_dynamic_entry (info,DT_PLTGOT, 0)1296 || ! bfd_elf32_add_dynamic_entry (info,DT_PLTRELSZ, 0)1297 || ! bfd_elf32_add_dynamic_entry (info,DT_PLTREL, DT_RELA)1298 || ! bfd_elf32_add_dynamic_entry (info,DT_JMPREL, 0))1299 return false;1259 if (!add_dynamic_entry (DT_PLTGOT, 0) 1260 || !add_dynamic_entry (DT_PLTRELSZ, 0) 1261 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 1262 || !add_dynamic_entry (DT_JMPREL, 0)) 1263 return FALSE; 1300 1264 } 1301 1265 1302 1266 if (relocs) 1303 1267 { 1304 if (!bfd_elf32_add_dynamic_entry (info, DT_RELA, 0) 1305 || !bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0) 1306 || !bfd_elf32_add_dynamic_entry (info, DT_RELAENT, 1307 sizeof (Elf32_External_Rela))) 1308 return false; 1309 } 1310 1311 if (reltext) 1312 { 1313 if (!bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0)) 1314 return false; 1315 info->flags |= DF_TEXTREL; 1268 if (!add_dynamic_entry (DT_RELA, 0) 1269 || !add_dynamic_entry (DT_RELASZ, 0) 1270 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) 1271 return FALSE; 1272 } 1273 1274 if ((info->flags & DF_TEXTREL) != 0) 1275 { 1276 if (!add_dynamic_entry (DT_TEXTREL, 0)) 1277 return FALSE; 1316 1278 } 1317 1279 } 1318 1319 return true; 1280 #undef add_dynamic_entry 1281 1282 return TRUE; 1320 1283 } 1321 1284 1322 /* This function is called via elf_m68k_link_hash_traverse if we are 1323 creating a shared object with -Bsymbolic. It discards the space 1324 allocated to copy PC relative relocs against symbols which are defined 1325 in regular objects. We allocated space for them in the check_relocs 1326 routine, but we won't fill them in in the relocate_section routine. */ 1327 1328 static boolean 1329 elf_m68k_discard_copies (h, ignore) 1330 struct elf_m68k_link_hash_entry *h; 1331 PTR ignore ATTRIBUTE_UNUSED; 1332 { 1285 /* This function is called via elf_link_hash_traverse if we are 1286 creating a shared object. In the -Bsymbolic case it discards the 1287 space allocated to copy PC relative relocs against symbols which 1288 are defined in regular objects. For the normal shared case, it 1289 discards space for pc-relative relocs that have become local due to 1290 symbol visibility changes. We allocated space for them in the 1291 check_relocs routine, but we won't fill them in in the 1292 relocate_section routine. 1293 1294 We also check whether any of the remaining relocations apply 1295 against a readonly section, and set the DF_TEXTREL flag in this 1296 case. */ 1297 1298 static bfd_boolean 1299 elf_m68k_discard_copies (h, inf) 1300 struct elf_link_hash_entry *h; 1301 PTR inf; 1302 { 1303 struct bfd_link_info *info = (struct bfd_link_info *) inf; 1333 1304 struct elf_m68k_pcrel_relocs_copied *s; 1334 1305 1335 /* We only discard relocs for symbols defined in a regular object. */ 1336 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 1337 return true; 1338 1339 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next) 1306 if (h->root.type == bfd_link_hash_warning) 1307 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1308 1309 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 1310 || (!info->symbolic 1311 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)) 1312 { 1313 if ((info->flags & DF_TEXTREL) == 0) 1314 { 1315 /* Look for relocations against read-only sections. */ 1316 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; 1317 s != NULL; 1318 s = s->next) 1319 if ((s->section->flags & SEC_READONLY) != 0) 1320 { 1321 info->flags |= DF_TEXTREL; 1322 break; 1323 } 1324 } 1325 1326 return TRUE; 1327 } 1328 1329 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; 1330 s != NULL; 1331 s = s->next) 1340 1332 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela); 1341 1333 1342 return true;1334 return TRUE; 1343 1335 } 1344 1336 1345 1337 /* Relocate an M68K ELF section. */ 1346 1338 1347 static b oolean1339 static bfd_boolean 1348 1340 elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, 1349 1341 contents, relocs, local_syms, local_sections) … … 1366 1358 Elf_Internal_Rela *rel; 1367 1359 Elf_Internal_Rela *relend; 1360 1361 if (info->relocateable) 1362 return TRUE; 1368 1363 1369 1364 dynobj = elf_hash_table (info)->dynobj; … … 1393 1388 { 1394 1389 bfd_set_error (bfd_error_bad_value); 1395 return false;1390 return FALSE; 1396 1391 } 1397 1392 howto = howto_table + r_type; … … 1399 1394 r_symndx = ELF32_R_SYM (rel->r_info); 1400 1395 1401 if (info->relocateable)1402 {1403 /* This is a relocateable link. We don't have to change1404 anything, unless the reloc is against a section symbol,1405 in which case we have to adjust according to where the1406 section symbol winds up in the output section. */1407 if (r_symndx < symtab_hdr->sh_info)1408 {1409 sym = local_syms + r_symndx;1410 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)1411 {1412 sec = local_sections[r_symndx];1413 rel->r_addend += sec->output_offset + sym->st_value;1414 }1415 }1416 1417 continue;1418 }1419 1420 /* This is a final link. */1421 1396 h = NULL; 1422 1397 sym = NULL; … … 1426 1401 sym = local_syms + r_symndx; 1427 1402 sec = local_sections[r_symndx]; 1428 relocation = (sec->output_section->vma 1429 + sec->output_offset 1430 + sym->st_value); 1403 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); 1431 1404 } 1432 1405 else … … 1456 1429 && strcmp (h->root.root.string, 1457 1430 "_GLOBAL_OFFSET_TABLE_") != 0)) 1458 && elf_hash_table (info)->dynamic_sections_created 1431 && (WILL_CALL_FINISH_DYNAMIC_SYMBOL 1432 (elf_hash_table (info)->dynamic_sections_created, 1433 info->shared, h)) 1459 1434 && (! info->shared 1460 || (! info->symbolic && h->dynindx != -1) 1435 || (! info->symbolic 1436 && h->dynindx != -1 1437 && (h->elf_link_hash_flags 1438 & ELF_LINK_FORCED_LOCAL) == 0) 1461 1439 || (h->elf_link_hash_flags 1462 1440 & ELF_LINK_HASH_DEF_REGULAR) == 0)) … … 1492 1470 else if (h->root.type == bfd_link_hash_undefweak) 1493 1471 relocation = 0; 1494 else if (info->shared && !info->symbolic1472 else if (info->shared 1495 1473 && !info->no_undefined 1496 1474 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) … … 1503 1481 (!info->shared || info->no_undefined 1504 1482 || ELF_ST_VISIBILITY (h->other))))) 1505 return false;1483 return FALSE; 1506 1484 relocation = 0; 1507 1485 } … … 1536 1514 if (h != NULL) 1537 1515 { 1516 bfd_boolean dyn; 1517 1538 1518 off = h->got.offset; 1539 1519 BFD_ASSERT (off != (bfd_vma) -1); 1540 1520 1541 if (!elf_hash_table (info)->dynamic_sections_created 1521 dyn = elf_hash_table (info)->dynamic_sections_created; 1522 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) 1542 1523 || (info->shared 1543 && (info->symbolic || h->dynindx == -1) 1544 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) 1524 && (info->symbolic 1525 || h->dynindx == -1 1526 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 1527 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) != 0) 1545 1528 { 1546 1529 /* This is actually a static link, or it is a … … 1584 1567 if (info->shared) 1585 1568 { 1586 asection *s relgot;1569 asection *s; 1587 1570 Elf_Internal_Rela outrel; 1588 1589 srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); 1590 BFD_ASSERT (srelgot != NULL); 1571 bfd_byte *loc; 1572 1573 s = bfd_get_section_by_name (dynobj, ".rela.got"); 1574 BFD_ASSERT (s != NULL); 1591 1575 1592 1576 outrel.r_offset = (sgot->output_section->vma … … 1595 1579 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); 1596 1580 outrel.r_addend = relocation; 1597 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 1598 (((Elf32_External_Rela *) 1599 srelgot->contents) 1600 + srelgot->reloc_count)); 1601 ++srelgot->reloc_count; 1581 loc = s->contents; 1582 loc += s->reloc_count++ * sizeof (Elf32_External_Rela); 1583 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 1602 1584 } 1603 1585 … … 1673 1655 case R_68K_PC16: 1674 1656 case R_68K_PC32: 1675 if (h == NULL) 1657 if (h == NULL 1658 || (info->shared 1659 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) 1676 1660 break; 1677 1661 /* Fall through. */ … … 1680 1664 case R_68K_32: 1681 1665 if (info->shared 1666 && r_symndx != 0 1682 1667 && (input_section->flags & SEC_ALLOC) != 0 1683 1668 && ((r_type != R_68K_PC8 … … 1689 1674 { 1690 1675 Elf_Internal_Rela outrel; 1691 boolean skip, relocate; 1676 bfd_byte *loc; 1677 bfd_boolean skip, relocate; 1692 1678 1693 1679 /* When generating a shared object, these relocations … … 1704 1690 elf_section_data (input_section)->rel_hdr.sh_name)); 1705 1691 if (name == NULL) 1706 return false;1692 return FALSE; 1707 1693 1708 1694 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 … … 1715 1701 } 1716 1702 1717 skip = false; 1718 1719 if (elf_section_data (input_section)->stab_info == NULL) 1720 outrel.r_offset = rel->r_offset; 1721 else 1722 { 1723 bfd_vma off; 1724 1725 off = (_bfd_stab_section_offset 1726 (output_bfd, &elf_hash_table (info)->stab_info, 1727 input_section, 1728 &elf_section_data (input_section)->stab_info, 1729 rel->r_offset)); 1730 if (off == (bfd_vma) -1) 1731 skip = true; 1732 outrel.r_offset = off; 1733 } 1734 1703 skip = FALSE; 1704 relocate = FALSE; 1705 1706 outrel.r_offset = 1707 _bfd_elf_section_offset (output_bfd, info, input_section, 1708 rel->r_offset); 1709 if (outrel.r_offset == (bfd_vma) -1) 1710 skip = TRUE; 1711 else if (outrel.r_offset == (bfd_vma) -2) 1712 skip = TRUE, relocate = TRUE; 1735 1713 outrel.r_offset += (input_section->output_section->vma 1736 1714 + input_section->output_offset); 1737 1715 1738 1716 if (skip) 1739 { 1740 memset (&outrel, 0, sizeof outrel); 1741 relocate = false; 1742 } 1717 memset (&outrel, 0, sizeof outrel); 1743 1718 /* h->dynindx may be -1 if the symbol was marked to 1744 1719 become local. */ … … 1749 1724 { 1750 1725 BFD_ASSERT (h->dynindx != -1); 1751 relocate = false;1752 1726 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); 1753 1727 outrel.r_addend = relocation + rel->r_addend; … … 1757 1731 if (r_type == R_68K_32) 1758 1732 { 1759 relocate = true;1733 relocate = TRUE; 1760 1734 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); 1761 1735 outrel.r_addend = relocation + rel->r_addend; … … 1779 1753 { 1780 1754 bfd_set_error (bfd_error_bad_value); 1781 return false;1755 return FALSE; 1782 1756 } 1783 1757 else … … 1790 1764 } 1791 1765 1792 relocate = false;1793 1766 outrel.r_info = ELF32_R_INFO (indx, r_type); 1794 1767 outrel.r_addend = relocation + rel->r_addend; … … 1796 1769 } 1797 1770 1798 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 1799 (((Elf32_External_Rela *) 1800 sreloc->contents) 1801 + sreloc->reloc_count)); 1802 ++sreloc->reloc_count; 1771 loc = sreloc->contents; 1772 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); 1773 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 1803 1774 1804 1775 /* This reloc will be computed at runtime, so there's no … … 1844 1815 sym->st_name); 1845 1816 if (name == NULL) 1846 return false;1817 return FALSE; 1847 1818 if (*name == '\0') 1848 1819 name = bfd_section_name (input_bfd, sec); … … 1851 1822 (info, name, howto->name, (bfd_vma) 0, 1852 1823 input_bfd, input_section, rel->r_offset))) 1853 return false;1824 return FALSE; 1854 1825 } 1855 1826 break; … … 1858 1829 } 1859 1830 1860 return true;1831 return TRUE; 1861 1832 } 1862 1833 … … 1864 1835 dynamic sections here. */ 1865 1836 1866 static b oolean1837 static bfd_boolean 1867 1838 elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) 1868 1839 bfd *output_bfd; … … 1884 1855 bfd_vma got_offset; 1885 1856 Elf_Internal_Rela rela; 1857 bfd_byte *loc; 1886 1858 1887 1859 /* This symbol has an entry in the procedure linkage table. Set … … 1956 1928 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT); 1957 1929 rela.r_addend = 0; 1958 bfd_elf32_swap_reloca_out (output_bfd, &rela, 1959 ((Elf32_External_Rela *) srela->contents 1960 + plt_index)); 1930 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); 1931 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1961 1932 1962 1933 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) … … 1973 1944 asection *srela; 1974 1945 Elf_Internal_Rela rela; 1946 bfd_byte *loc; 1975 1947 1976 1948 /* This symbol has an entry in the global offset table. Set it … … 1983 1955 rela.r_offset = (sgot->output_section->vma 1984 1956 + sgot->output_offset 1985 + (h->got.offset &~ 1));1957 + (h->got.offset &~ (bfd_vma) 1)); 1986 1958 1987 1959 /* If this is a -Bsymbolic link, and the symbol is defined … … 1991 1963 initialized in the relocate_section function. */ 1992 1964 if (info->shared 1993 && (info->symbolic || h->dynindx == -1) 1965 && (info->symbolic 1966 || h->dynindx == -1 1967 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 1994 1968 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) 1995 1969 { … … 1997 1971 rela.r_addend = bfd_get_signed_32 (output_bfd, 1998 1972 (sgot->contents 1999 + (h->got.offset & ~1)));1973 + (h->got.offset &~ (bfd_vma) 1))); 2000 1974 } 2001 1975 else 2002 1976 { 2003 1977 bfd_put_32 (output_bfd, (bfd_vma) 0, 2004 sgot->contents + (h->got.offset & ~1));1978 sgot->contents + (h->got.offset &~ (bfd_vma) 1)); 2005 1979 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT); 2006 1980 rela.r_addend = 0; 2007 1981 } 2008 1982 2009 bfd_elf32_swap_reloca_out (output_bfd, &rela, 2010 ((Elf32_External_Rela *) srela->contents 2011 + srela->reloc_count)); 2012 ++srela->reloc_count; 1983 loc = srela->contents; 1984 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); 1985 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 2013 1986 } 2014 1987 … … 2017 1990 asection *s; 2018 1991 Elf_Internal_Rela rela; 1992 bfd_byte *loc; 2019 1993 2020 1994 /* This symbol needs a copy reloc. Set it up. */ … … 2033 2007 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY); 2034 2008 rela.r_addend = 0; 2035 bfd_elf32_swap_reloca_out (output_bfd, &rela, 2036 ((Elf32_External_Rela *) s->contents 2037 + s->reloc_count)); 2038 ++s->reloc_count; 2009 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); 2010 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 2039 2011 } 2040 2012 … … 2044 2016 sym->st_shndx = SHN_ABS; 2045 2017 2046 return true;2018 return TRUE; 2047 2019 } 2048 2020 2049 2021 /* Finish up the dynamic sections. */ 2050 2022 2051 static b oolean2023 static bfd_boolean 2052 2024 elf_m68k_finish_dynamic_sections (output_bfd, info) 2053 2025 bfd *output_bfd; … … 2183 2155 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; 2184 2156 2185 return true;2157 return TRUE; 2186 2158 } 2187 2159 … … 2193 2165 objects, and before the final_link entry point is called. */ 2194 2166 2195 b oolean2167 bfd_boolean 2196 2168 bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) 2197 2169 bfd *abfd; … … 2202 2174 { 2203 2175 Elf_Internal_Shdr *symtab_hdr; 2204 Elf32_External_Sym *extsyms; 2205 Elf32_External_Sym *free_extsyms = NULL; 2206 Elf_Internal_Rela *internal_relocs; 2207 Elf_Internal_Rela *free_relocs = NULL; 2176 Elf_Internal_Sym *isymbuf = NULL; 2177 Elf_Internal_Rela *internal_relocs = NULL; 2208 2178 Elf_Internal_Rela *irel, *irelend; 2209 2179 bfd_byte *p; 2180 bfd_size_type amt; 2210 2181 2211 2182 BFD_ASSERT (! info->relocateable); … … 2214 2185 2215 2186 if (datasec->reloc_count == 0) 2216 return true;2187 return TRUE; 2217 2188 2218 2189 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 2219 /* Read this BFD's symbols if we haven't done so already, or get the cached2220 copy if it exists. */2221 if (symtab_hdr->contents != NULL)2222 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;2223 else2224 {2225 /* Go get them off disk. */2226 if (info->keep_memory)2227 extsyms = ((Elf32_External_Sym *)2228 bfd_alloc (abfd, symtab_hdr->sh_size));2229 else2230 extsyms = ((Elf32_External_Sym *)2231 bfd_malloc (symtab_hdr->sh_size));2232 if (extsyms == NULL)2233 goto error_return;2234 if (! info->keep_memory)2235 free_extsyms = extsyms;2236 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 02237 || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)2238 != symtab_hdr->sh_size))2239 goto error_return;2240 if (info->keep_memory)2241 symtab_hdr->contents = extsyms;2242 }2243 2190 2244 2191 /* Get a copy of the native relocations. */ … … 2248 2195 if (internal_relocs == NULL) 2249 2196 goto error_return; 2250 if (! info->keep_memory) 2251 free_relocs = internal_relocs; 2252 2253 relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12); 2197 2198 amt = (bfd_size_type) datasec->reloc_count * 12; 2199 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt); 2254 2200 if (relsec->contents == NULL) 2255 2201 goto error_return; … … 2279 2225 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 2280 2226 { 2281 Elf_Internal_Sym isym;2282 2283 2227 /* A local symbol. */ 2284 bfd_elf32_swap_symbol_in (abfd, 2285 extsyms + ELF32_R_SYM (irel->r_info), 2286 &isym); 2287 2288 targetsec = bfd_section_from_elf_index (abfd, isym.st_shndx); 2228 Elf_Internal_Sym *isym; 2229 2230 /* Read this BFD's local symbols if we haven't done so already. */ 2231 if (isymbuf == NULL) 2232 { 2233 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 2234 if (isymbuf == NULL) 2235 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 2236 symtab_hdr->sh_info, 0, 2237 NULL, NULL, NULL); 2238 if (isymbuf == NULL) 2239 goto error_return; 2240 } 2241 2242 isym = isymbuf + ELF32_R_SYM (irel->r_info); 2243 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 2289 2244 } 2290 2245 else … … 2310 2265 } 2311 2266 2312 if (free_extsyms != NULL) 2313 free (free_extsyms); 2314 if (free_relocs != NULL) 2315 free (free_relocs); 2316 return true; 2267 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) 2268 free (isymbuf); 2269 if (internal_relocs != NULL 2270 && elf_section_data (datasec)->relocs != internal_relocs) 2271 free (internal_relocs); 2272 return TRUE; 2317 2273 2318 2274 error_return: 2319 if (free_extsyms != NULL) 2320 free (free_extsyms); 2321 if (free_relocs != NULL) 2322 free (free_relocs); 2323 return false; 2275 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) 2276 free (isymbuf); 2277 if (internal_relocs != NULL 2278 && elf_section_data (datasec)->relocs != internal_relocs) 2279 free (internal_relocs); 2280 return FALSE; 2281 } 2282 2283 static enum elf_reloc_type_class 2284 elf32_m68k_reloc_type_class (rela) 2285 const Elf_Internal_Rela *rela; 2286 { 2287 switch ((int) ELF32_R_TYPE (rela->r_info)) 2288 { 2289 case R_68K_RELATIVE: 2290 return reloc_class_relative; 2291 case R_68K_JMP_SLOT: 2292 return reloc_class_plt; 2293 case R_68K_COPY: 2294 return reloc_class_copy; 2295 default: 2296 return reloc_class_normal; 2297 } 2324 2298 } 2325 2299 … … 2346 2320 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook 2347 2321 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook 2348 #define bfd_elf32_bfd_copy_private_bfd_data \2349 elf32_m68k_copy_private_bfd_data2350 2322 #define bfd_elf32_bfd_merge_private_bfd_data \ 2351 2323 elf32_m68k_merge_private_bfd_data … … 2354 2326 #define bfd_elf32_bfd_print_private_bfd_data \ 2355 2327 elf32_m68k_print_private_bfd_data 2328 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class 2356 2329 2357 2330 #define elf_backend_can_gc_sections 1 2331 #define elf_backend_can_refcount 1 2358 2332 #define elf_backend_want_got_plt 1 2359 2333 #define elf_backend_plt_readonly 1 2360 2334 #define elf_backend_want_plt_sym 0 2361 2335 #define elf_backend_got_header_size 12 2336 #define elf_backend_rela_normal 1 2362 2337 2363 2338 #include "elf32-target.h" -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.