Changeset 609 for branches/GNU/src/binutils/bfd/elf.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* ELF executable support for BFD. 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 3 Free Software Foundation, Inc. 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 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 21 /* 22 23 SECTION 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 3 2003 Free Software Foundation, Inc. 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 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 21 /* SECTION 22 24 23 ELF backends 25 24 … … 30 29 Documentation of the internals of the support code still needs 31 30 to be written. The code is changing quickly enough that we 32 haven't bothered yet. 33 */ 31 haven't bothered yet. */ 34 32 35 33 /* For sparc64-cross-sparc32. */ … … 41 39 #define ARCH_SIZE 0 42 40 #include "elf-bfd.h" 41 #include "libiberty.h" 43 42 44 43 static INLINE struct elf_segment_map *make_mapping 45 PARAMS ((bfd *, asection **, unsigned int, unsigned int, boolean)); 46 static boolean map_sections_to_segments PARAMS ((bfd *)); 47 static int elf_sort_sections PARAMS ((const PTR, const PTR)); 48 static boolean assign_file_positions_for_segments PARAMS ((bfd *)); 49 static boolean assign_file_positions_except_relocs PARAMS ((bfd *)); 50 static boolean prep_headers PARAMS ((bfd *)); 51 static boolean swap_out_syms PARAMS ((bfd *, struct bfd_strtab_hash **, int)); 52 static boolean copy_private_bfd_data PARAMS ((bfd *, bfd *)); 53 static char *elf_read PARAMS ((bfd *, long, unsigned int)); 54 static void elf_fake_sections PARAMS ((bfd *, asection *, PTR)); 55 static boolean assign_section_numbers PARAMS ((bfd *)); 56 static INLINE int sym_is_global PARAMS ((bfd *, asymbol *)); 57 static boolean elf_map_symbols PARAMS ((bfd *)); 58 static bfd_size_type get_program_header_size PARAMS ((bfd *)); 59 static boolean elfcore_read_notes PARAMS ((bfd *, bfd_vma, bfd_vma)); 60 static boolean elf_find_function PARAMS ((bfd *, asection *, 61 asymbol **, 62 bfd_vma, const char **, 63 const char **)); 44 PARAMS ((bfd *, asection **, unsigned int, unsigned int, bfd_boolean)); 45 static bfd_boolean map_sections_to_segments 46 PARAMS ((bfd *)); 47 static int elf_sort_sections 48 PARAMS ((const PTR, const PTR)); 49 static bfd_boolean assign_file_positions_for_segments 50 PARAMS ((bfd *)); 51 static bfd_boolean assign_file_positions_except_relocs 52 PARAMS ((bfd *)); 53 static bfd_boolean prep_headers 54 PARAMS ((bfd *)); 55 static bfd_boolean swap_out_syms 56 PARAMS ((bfd *, struct bfd_strtab_hash **, int)); 57 static bfd_boolean copy_private_bfd_data 58 PARAMS ((bfd *, bfd *)); 59 static char *elf_read 60 PARAMS ((bfd *, file_ptr, bfd_size_type)); 61 static const char *group_signature 62 PARAMS ((bfd *, Elf_Internal_Shdr *)); 63 static bfd_boolean setup_group 64 PARAMS ((bfd *, Elf_Internal_Shdr *, asection *)); 65 static void merge_sections_remove_hook 66 PARAMS ((bfd *, asection *)); 67 static void elf_fake_sections 68 PARAMS ((bfd *, asection *, PTR)); 69 static bfd_boolean assign_section_numbers 70 PARAMS ((bfd *)); 71 static INLINE int sym_is_global 72 PARAMS ((bfd *, asymbol *)); 73 static bfd_boolean elf_map_symbols 74 PARAMS ((bfd *)); 75 static bfd_size_type get_program_header_size 76 PARAMS ((bfd *)); 77 static bfd_boolean elfcore_read_notes 78 PARAMS ((bfd *, file_ptr, bfd_size_type)); 79 static bfd_boolean elf_find_function 80 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **, 81 const char **)); 82 static int elfcore_make_pid 83 PARAMS ((bfd *)); 84 static bfd_boolean elfcore_maybe_make_sect 85 PARAMS ((bfd *, char *, asection *)); 86 static bfd_boolean elfcore_make_note_pseudosection 87 PARAMS ((bfd *, char *, Elf_Internal_Note *)); 88 static bfd_boolean elfcore_grok_prfpreg 89 PARAMS ((bfd *, Elf_Internal_Note *)); 90 static bfd_boolean elfcore_grok_prxfpreg 91 PARAMS ((bfd *, Elf_Internal_Note *)); 92 static bfd_boolean elfcore_grok_note 93 PARAMS ((bfd *, Elf_Internal_Note *)); 94 static bfd_boolean elfcore_netbsd_get_lwpid 95 PARAMS ((Elf_Internal_Note *, int *)); 96 static bfd_boolean elfcore_grok_netbsd_procinfo 97 PARAMS ((bfd *, Elf_Internal_Note *)); 98 static bfd_boolean elfcore_grok_netbsd_note 99 PARAMS ((bfd *, Elf_Internal_Note *)); 100 static bfd_boolean elfcore_grok_nto_gregs 101 PARAMS ((bfd *, Elf_Internal_Note *, pid_t)); 102 static bfd_boolean elfcore_grok_nto_status 103 PARAMS ((bfd *, Elf_Internal_Note *, pid_t *)); 104 static bfd_boolean elfcore_grok_nto_note 105 PARAMS ((bfd *, Elf_Internal_Note *)); 64 106 65 107 /* Swap version information in and out. The version information is … … 75 117 Elf_Internal_Verdef *dst; 76 118 { 77 dst->vd_version = bfd_h_get_16 (abfd, src->vd_version);78 dst->vd_flags = bfd_h_get_16 (abfd, src->vd_flags);79 dst->vd_ndx = bfd_h_get_16 (abfd, src->vd_ndx);80 dst->vd_cnt = bfd_h_get_16 (abfd, src->vd_cnt);81 dst->vd_hash = bfd_h_get_32 (abfd, src->vd_hash);82 dst->vd_aux = bfd_h_get_32 (abfd, src->vd_aux);83 dst->vd_next = bfd_h_get_32 (abfd, src->vd_next);119 dst->vd_version = H_GET_16 (abfd, src->vd_version); 120 dst->vd_flags = H_GET_16 (abfd, src->vd_flags); 121 dst->vd_ndx = H_GET_16 (abfd, src->vd_ndx); 122 dst->vd_cnt = H_GET_16 (abfd, src->vd_cnt); 123 dst->vd_hash = H_GET_32 (abfd, src->vd_hash); 124 dst->vd_aux = H_GET_32 (abfd, src->vd_aux); 125 dst->vd_next = H_GET_32 (abfd, src->vd_next); 84 126 } 85 127 … … 92 134 Elf_External_Verdef *dst; 93 135 { 94 bfd_h_put_16 (abfd, src->vd_version, dst->vd_version);95 bfd_h_put_16 (abfd, src->vd_flags, dst->vd_flags);96 bfd_h_put_16 (abfd, src->vd_ndx, dst->vd_ndx);97 bfd_h_put_16 (abfd, src->vd_cnt, dst->vd_cnt);98 bfd_h_put_32 (abfd, src->vd_hash, dst->vd_hash);99 bfd_h_put_32 (abfd, src->vd_aux, dst->vd_aux);100 bfd_h_put_32 (abfd, src->vd_next, dst->vd_next);136 H_PUT_16 (abfd, src->vd_version, dst->vd_version); 137 H_PUT_16 (abfd, src->vd_flags, dst->vd_flags); 138 H_PUT_16 (abfd, src->vd_ndx, dst->vd_ndx); 139 H_PUT_16 (abfd, src->vd_cnt, dst->vd_cnt); 140 H_PUT_32 (abfd, src->vd_hash, dst->vd_hash); 141 H_PUT_32 (abfd, src->vd_aux, dst->vd_aux); 142 H_PUT_32 (abfd, src->vd_next, dst->vd_next); 101 143 } 102 144 … … 109 151 Elf_Internal_Verdaux *dst; 110 152 { 111 dst->vda_name = bfd_h_get_32 (abfd, src->vda_name);112 dst->vda_next = bfd_h_get_32 (abfd, src->vda_next);153 dst->vda_name = H_GET_32 (abfd, src->vda_name); 154 dst->vda_next = H_GET_32 (abfd, src->vda_next); 113 155 } 114 156 … … 121 163 Elf_External_Verdaux *dst; 122 164 { 123 bfd_h_put_32 (abfd, src->vda_name, dst->vda_name);124 bfd_h_put_32 (abfd, src->vda_next, dst->vda_next);165 H_PUT_32 (abfd, src->vda_name, dst->vda_name); 166 H_PUT_32 (abfd, src->vda_next, dst->vda_next); 125 167 } 126 168 … … 133 175 Elf_Internal_Verneed *dst; 134 176 { 135 dst->vn_version = bfd_h_get_16 (abfd, src->vn_version);136 dst->vn_cnt = bfd_h_get_16 (abfd, src->vn_cnt);137 dst->vn_file = bfd_h_get_32 (abfd, src->vn_file);138 dst->vn_aux = bfd_h_get_32 (abfd, src->vn_aux);139 dst->vn_next = bfd_h_get_32 (abfd, src->vn_next);177 dst->vn_version = H_GET_16 (abfd, src->vn_version); 178 dst->vn_cnt = H_GET_16 (abfd, src->vn_cnt); 179 dst->vn_file = H_GET_32 (abfd, src->vn_file); 180 dst->vn_aux = H_GET_32 (abfd, src->vn_aux); 181 dst->vn_next = H_GET_32 (abfd, src->vn_next); 140 182 } 141 183 … … 148 190 Elf_External_Verneed *dst; 149 191 { 150 bfd_h_put_16 (abfd, src->vn_version, dst->vn_version);151 bfd_h_put_16 (abfd, src->vn_cnt, dst->vn_cnt);152 bfd_h_put_32 (abfd, src->vn_file, dst->vn_file);153 bfd_h_put_32 (abfd, src->vn_aux, dst->vn_aux);154 bfd_h_put_32 (abfd, src->vn_next, dst->vn_next);192 H_PUT_16 (abfd, src->vn_version, dst->vn_version); 193 H_PUT_16 (abfd, src->vn_cnt, dst->vn_cnt); 194 H_PUT_32 (abfd, src->vn_file, dst->vn_file); 195 H_PUT_32 (abfd, src->vn_aux, dst->vn_aux); 196 H_PUT_32 (abfd, src->vn_next, dst->vn_next); 155 197 } 156 198 … … 163 205 Elf_Internal_Vernaux *dst; 164 206 { 165 dst->vna_hash = bfd_h_get_32 (abfd, src->vna_hash);166 dst->vna_flags = bfd_h_get_16 (abfd, src->vna_flags);167 dst->vna_other = bfd_h_get_16 (abfd, src->vna_other);168 dst->vna_name = bfd_h_get_32 (abfd, src->vna_name);169 dst->vna_next = bfd_h_get_32 (abfd, src->vna_next);207 dst->vna_hash = H_GET_32 (abfd, src->vna_hash); 208 dst->vna_flags = H_GET_16 (abfd, src->vna_flags); 209 dst->vna_other = H_GET_16 (abfd, src->vna_other); 210 dst->vna_name = H_GET_32 (abfd, src->vna_name); 211 dst->vna_next = H_GET_32 (abfd, src->vna_next); 170 212 } 171 213 … … 178 220 Elf_External_Vernaux *dst; 179 221 { 180 bfd_h_put_32 (abfd, src->vna_hash, dst->vna_hash);181 bfd_h_put_16 (abfd, src->vna_flags, dst->vna_flags);182 bfd_h_put_16 (abfd, src->vna_other, dst->vna_other);183 bfd_h_put_32 (abfd, src->vna_name, dst->vna_name);184 bfd_h_put_32 (abfd, src->vna_next, dst->vna_next);222 H_PUT_32 (abfd, src->vna_hash, dst->vna_hash); 223 H_PUT_16 (abfd, src->vna_flags, dst->vna_flags); 224 H_PUT_16 (abfd, src->vna_other, dst->vna_other); 225 H_PUT_32 (abfd, src->vna_name, dst->vna_name); 226 H_PUT_32 (abfd, src->vna_next, dst->vna_next); 185 227 } 186 228 … … 193 235 Elf_Internal_Versym *dst; 194 236 { 195 dst->vs_vers = bfd_h_get_16 (abfd, src->vs_vers);237 dst->vs_vers = H_GET_16 (abfd, src->vs_vers); 196 238 } 197 239 … … 204 246 Elf_External_Versym *dst; 205 247 { 206 bfd_h_put_16 (abfd, src->vs_vers, dst->vs_vers);248 H_PUT_16 (abfd, src->vs_vers, dst->vs_vers); 207 249 } 208 250 … … 230 272 } 231 273 } 232 return h ;274 return h & 0xffffffff; 233 275 } 234 276 … … 240 282 elf_read (abfd, offset, size) 241 283 bfd *abfd; 242 longoffset;243 unsigned intsize;284 file_ptr offset; 285 bfd_size_type size; 244 286 { 245 287 char *buf; … … 247 289 if ((buf = bfd_alloc (abfd, size)) == NULL) 248 290 return NULL; 249 if (bfd_seek (abfd, offset, SEEK_SET) == -1)291 if (bfd_seek (abfd, offset, SEEK_SET) != 0) 250 292 return NULL; 251 if (bfd_ read ((PTR) buf, size, 1, abfd) != size)293 if (bfd_bread ((PTR) buf, size, abfd) != size) 252 294 { 253 295 if (bfd_get_error () != bfd_error_system_call) … … 258 300 } 259 301 260 b oolean302 bfd_boolean 261 303 bfd_elf_mkobject (abfd) 262 304 bfd *abfd; … … 264 306 /* This just does initialization. */ 265 307 /* coff_mkobject zalloc's space for tdata.coff_obj_data ... */ 266 elf_tdata (abfd) = (struct elf_obj_tdata *)267 bfd_zalloc (abfd, sizeof (struct elf_obj_tdata));308 bfd_size_type amt = sizeof (struct elf_obj_tdata); 309 elf_tdata (abfd) = (struct elf_obj_tdata *) bfd_zalloc (abfd, amt); 268 310 if (elf_tdata (abfd) == 0) 269 return false;311 return FALSE; 270 312 /* Since everything is done at close time, do we need any 271 313 initialization? */ 272 314 273 return true;274 } 275 276 b oolean315 return TRUE; 316 } 317 318 bfd_boolean 277 319 bfd_elf_mkcorefile (abfd) 278 320 bfd *abfd; … … 289 331 Elf_Internal_Shdr **i_shdrp; 290 332 char *shstrtab = NULL; 291 unsigned intoffset;292 unsigned intshstrtabsize;333 file_ptr offset; 334 bfd_size_type shstrtabsize; 293 335 294 336 i_shdrp = elf_elfsections (abfd); … … 329 371 (*_bfd_error_handler) 330 372 (_("%s: invalid string offset %u >= %lu for section `%s'"), 331 bfd_ get_filename (abfd), strindex, (unsigned long) hdr->sh_size,373 bfd_archive_filename (abfd), strindex, (unsigned long) hdr->sh_size, 332 374 ((shindex == elf_elfheader(abfd)->e_shstrndx 333 375 && strindex == hdr->sh_name) … … 340 382 } 341 383 384 /* Read and convert symbols to internal format. 385 SYMCOUNT specifies the number of symbols to read, starting from 386 symbol SYMOFFSET. If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF 387 are non-NULL, they are used to store the internal symbols, external 388 symbols, and symbol section index extensions, respectively. */ 389 390 Elf_Internal_Sym * 391 bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, symoffset, 392 intsym_buf, extsym_buf, extshndx_buf) 393 bfd *ibfd; 394 Elf_Internal_Shdr *symtab_hdr; 395 size_t symcount; 396 size_t symoffset; 397 Elf_Internal_Sym *intsym_buf; 398 PTR extsym_buf; 399 Elf_External_Sym_Shndx *extshndx_buf; 400 { 401 Elf_Internal_Shdr *shndx_hdr; 402 PTR alloc_ext; 403 const bfd_byte *esym; 404 Elf_External_Sym_Shndx *alloc_extshndx; 405 Elf_External_Sym_Shndx *shndx; 406 Elf_Internal_Sym *isym; 407 Elf_Internal_Sym *isymend; 408 struct elf_backend_data *bed; 409 size_t extsym_size; 410 bfd_size_type amt; 411 file_ptr pos; 412 413 if (symcount == 0) 414 return intsym_buf; 415 416 /* Normal syms might have section extension entries. */ 417 shndx_hdr = NULL; 418 if (symtab_hdr == &elf_tdata (ibfd)->symtab_hdr) 419 shndx_hdr = &elf_tdata (ibfd)->symtab_shndx_hdr; 420 421 /* Read the symbols. */ 422 alloc_ext = NULL; 423 alloc_extshndx = NULL; 424 bed = get_elf_backend_data (ibfd); 425 extsym_size = bed->s->sizeof_sym; 426 amt = symcount * extsym_size; 427 pos = symtab_hdr->sh_offset + symoffset * extsym_size; 428 if (extsym_buf == NULL) 429 { 430 alloc_ext = bfd_malloc (amt); 431 extsym_buf = alloc_ext; 432 } 433 if (extsym_buf == NULL 434 || bfd_seek (ibfd, pos, SEEK_SET) != 0 435 || bfd_bread (extsym_buf, amt, ibfd) != amt) 436 { 437 intsym_buf = NULL; 438 goto out; 439 } 440 441 if (shndx_hdr == NULL || shndx_hdr->sh_size == 0) 442 extshndx_buf = NULL; 443 else 444 { 445 amt = symcount * sizeof (Elf_External_Sym_Shndx); 446 pos = shndx_hdr->sh_offset + symoffset * sizeof (Elf_External_Sym_Shndx); 447 if (extshndx_buf == NULL) 448 { 449 alloc_extshndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt); 450 extshndx_buf = alloc_extshndx; 451 } 452 if (extshndx_buf == NULL 453 || bfd_seek (ibfd, pos, SEEK_SET) != 0 454 || bfd_bread (extshndx_buf, amt, ibfd) != amt) 455 { 456 intsym_buf = NULL; 457 goto out; 458 } 459 } 460 461 if (intsym_buf == NULL) 462 { 463 bfd_size_type amt = symcount * sizeof (Elf_Internal_Sym); 464 intsym_buf = (Elf_Internal_Sym *) bfd_malloc (amt); 465 if (intsym_buf == NULL) 466 goto out; 467 } 468 469 /* Convert the symbols to internal form. */ 470 isymend = intsym_buf + symcount; 471 for (esym = extsym_buf, isym = intsym_buf, shndx = extshndx_buf; 472 isym < isymend; 473 esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL) 474 (*bed->s->swap_symbol_in) (ibfd, esym, (const PTR) shndx, isym); 475 476 out: 477 if (alloc_ext != NULL) 478 free (alloc_ext); 479 if (alloc_extshndx != NULL) 480 free (alloc_extshndx); 481 482 return intsym_buf; 483 } 484 485 /* Look up a symbol name. */ 486 const char * 487 bfd_elf_local_sym_name (abfd, isym) 488 bfd *abfd; 489 Elf_Internal_Sym *isym; 490 { 491 unsigned int iname = isym->st_name; 492 unsigned int shindex = elf_tdata (abfd)->symtab_hdr.sh_link; 493 if (iname == 0 && ELF_ST_TYPE (isym->st_info) == STT_SECTION) 494 { 495 iname = elf_elfsections (abfd)[isym->st_shndx]->sh_name; 496 shindex = elf_elfheader (abfd)->e_shstrndx; 497 } 498 499 return bfd_elf_string_from_elf_section (abfd, shindex, iname); 500 } 501 502 /* Elf_Internal_Shdr->contents is an array of these for SHT_GROUP 503 sections. The first element is the flags, the rest are section 504 pointers. */ 505 506 typedef union elf_internal_group { 507 Elf_Internal_Shdr *shdr; 508 unsigned int flags; 509 } Elf_Internal_Group; 510 511 /* Return the name of the group signature symbol. Why isn't the 512 signature just a string? */ 513 514 static const char * 515 group_signature (abfd, ghdr) 516 bfd *abfd; 517 Elf_Internal_Shdr *ghdr; 518 { 519 Elf_Internal_Shdr *hdr; 520 unsigned char esym[sizeof (Elf64_External_Sym)]; 521 Elf_External_Sym_Shndx eshndx; 522 Elf_Internal_Sym isym; 523 524 /* First we need to ensure the symbol table is available. */ 525 if (! bfd_section_from_shdr (abfd, ghdr->sh_link)) 526 return NULL; 527 528 /* Go read the symbol. */ 529 hdr = &elf_tdata (abfd)->symtab_hdr; 530 if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info, 531 &isym, esym, &eshndx) == NULL) 532 return NULL; 533 534 return bfd_elf_local_sym_name (abfd, &isym); 535 } 536 537 /* Set next_in_group list pointer, and group name for NEWSECT. */ 538 539 static bfd_boolean 540 setup_group (abfd, hdr, newsect) 541 bfd *abfd; 542 Elf_Internal_Shdr *hdr; 543 asection *newsect; 544 { 545 unsigned int num_group = elf_tdata (abfd)->num_group; 546 547 /* If num_group is zero, read in all SHT_GROUP sections. The count 548 is set to -1 if there are no SHT_GROUP sections. */ 549 if (num_group == 0) 550 { 551 unsigned int i, shnum; 552 553 /* First count the number of groups. If we have a SHT_GROUP 554 section with just a flag word (ie. sh_size is 4), ignore it. */ 555 shnum = elf_numsections (abfd); 556 num_group = 0; 557 for (i = 0; i < shnum; i++) 558 { 559 Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i]; 560 if (shdr->sh_type == SHT_GROUP && shdr->sh_size >= 8) 561 num_group += 1; 562 } 563 564 if (num_group == 0) 565 num_group = (unsigned) -1; 566 elf_tdata (abfd)->num_group = num_group; 567 568 if (num_group > 0) 569 { 570 /* We keep a list of elf section headers for group sections, 571 so we can find them quickly. */ 572 bfd_size_type amt = num_group * sizeof (Elf_Internal_Shdr *); 573 elf_tdata (abfd)->group_sect_ptr = bfd_alloc (abfd, amt); 574 if (elf_tdata (abfd)->group_sect_ptr == NULL) 575 return FALSE; 576 577 num_group = 0; 578 for (i = 0; i < shnum; i++) 579 { 580 Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i]; 581 if (shdr->sh_type == SHT_GROUP && shdr->sh_size >= 8) 582 { 583 unsigned char *src; 584 Elf_Internal_Group *dest; 585 586 /* Add to list of sections. */ 587 elf_tdata (abfd)->group_sect_ptr[num_group] = shdr; 588 num_group += 1; 589 590 /* Read the raw contents. */ 591 BFD_ASSERT (sizeof (*dest) >= 4); 592 amt = shdr->sh_size * sizeof (*dest) / 4; 593 shdr->contents = bfd_alloc (abfd, amt); 594 if (shdr->contents == NULL 595 || bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0 596 || (bfd_bread (shdr->contents, shdr->sh_size, abfd) 597 != shdr->sh_size)) 598 return FALSE; 599 600 /* Translate raw contents, a flag word followed by an 601 array of elf section indices all in target byte order, 602 to the flag word followed by an array of elf section 603 pointers. */ 604 src = shdr->contents + shdr->sh_size; 605 dest = (Elf_Internal_Group *) (shdr->contents + amt); 606 while (1) 607 { 608 unsigned int idx; 609 610 src -= 4; 611 --dest; 612 idx = H_GET_32 (abfd, src); 613 if (src == shdr->contents) 614 { 615 dest->flags = idx; 616 if (shdr->bfd_section != NULL && (idx & GRP_COMDAT)) 617 shdr->bfd_section->flags 618 |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; 619 break; 620 } 621 if (idx >= shnum) 622 { 623 ((*_bfd_error_handler) 624 (_("%s: invalid SHT_GROUP entry"), 625 bfd_archive_filename (abfd))); 626 idx = 0; 627 } 628 dest->shdr = elf_elfsections (abfd)[idx]; 629 } 630 } 631 } 632 } 633 } 634 635 if (num_group != (unsigned) -1) 636 { 637 unsigned int i; 638 639 for (i = 0; i < num_group; i++) 640 { 641 Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i]; 642 Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents; 643 unsigned int n_elt = shdr->sh_size / 4; 644 645 /* Look through this group's sections to see if current 646 section is a member. */ 647 while (--n_elt != 0) 648 if ((++idx)->shdr == hdr) 649 { 650 asection *s = NULL; 651 652 /* We are a member of this group. Go looking through 653 other members to see if any others are linked via 654 next_in_group. */ 655 idx = (Elf_Internal_Group *) shdr->contents; 656 n_elt = shdr->sh_size / 4; 657 while (--n_elt != 0) 658 if ((s = (++idx)->shdr->bfd_section) != NULL 659 && elf_next_in_group (s) != NULL) 660 break; 661 if (n_elt != 0) 662 { 663 /* Snarf the group name from other member, and 664 insert current section in circular list. */ 665 elf_group_name (newsect) = elf_group_name (s); 666 elf_next_in_group (newsect) = elf_next_in_group (s); 667 elf_next_in_group (s) = newsect; 668 } 669 else 670 { 671 const char *gname; 672 673 gname = group_signature (abfd, shdr); 674 if (gname == NULL) 675 return FALSE; 676 elf_group_name (newsect) = gname; 677 678 /* Start a circular list with one element. */ 679 elf_next_in_group (newsect) = newsect; 680 } 681 682 /* If the group section has been created, point to the 683 new member. */ 684 if (shdr->bfd_section != NULL) 685 elf_next_in_group (shdr->bfd_section) = newsect; 686 687 i = num_group - 1; 688 break; 689 } 690 } 691 } 692 693 if (elf_group_name (newsect) == NULL) 694 { 695 (*_bfd_error_handler) (_("%s: no group info for section %s"), 696 bfd_archive_filename (abfd), newsect->name); 697 } 698 return TRUE; 699 } 700 701 bfd_boolean 702 bfd_elf_discard_group (abfd, group) 703 bfd *abfd ATTRIBUTE_UNUSED; 704 asection *group; 705 { 706 asection *first = elf_next_in_group (group); 707 asection *s = first; 708 709 while (s != NULL) 710 { 711 s->output_section = bfd_abs_section_ptr; 712 s = elf_next_in_group (s); 713 /* These lists are circular. */ 714 if (s == first) 715 break; 716 } 717 return TRUE; 718 } 719 342 720 /* Make a BFD section from an ELF section. We store a pointer to the 343 721 BFD section in the bfd_section field of the header. */ 344 722 345 b oolean723 bfd_boolean 346 724 _bfd_elf_make_section_from_shdr (abfd, hdr, name) 347 725 bfd *abfd; … … 357 735 BFD_ASSERT (strcmp (name, 358 736 bfd_get_section_name (abfd, hdr->bfd_section)) == 0); 359 return true;737 return TRUE; 360 738 } 361 739 362 740 newsect = bfd_make_section_anyway (abfd, name); 363 741 if (newsect == NULL) 364 return false;742 return FALSE; 365 743 366 744 newsect->filepos = hdr->sh_offset; … … 369 747 || ! bfd_set_section_size (abfd, newsect, hdr->sh_size) 370 748 || ! bfd_set_section_alignment (abfd, newsect, 371 bfd_log2 ( hdr->sh_addralign)))372 return false;749 bfd_log2 ((bfd_vma) hdr->sh_addralign))) 750 return FALSE; 373 751 374 752 flags = SEC_NO_FLAGS; 375 753 if (hdr->sh_type != SHT_NOBITS) 376 754 flags |= SEC_HAS_CONTENTS; 755 if (hdr->sh_type == SHT_GROUP) 756 flags |= SEC_GROUP | SEC_EXCLUDE; 377 757 if ((hdr->sh_flags & SHF_ALLOC) != 0) 378 758 { … … 387 767 else if ((flags & SEC_LOAD) != 0) 388 768 flags |= SEC_DATA; 769 if ((hdr->sh_flags & SHF_MERGE) != 0) 770 { 771 flags |= SEC_MERGE; 772 newsect->entsize = hdr->sh_entsize; 773 if ((hdr->sh_flags & SHF_STRINGS) != 0) 774 flags |= SEC_STRINGS; 775 } 776 if (hdr->sh_flags & SHF_GROUP) 777 if (!setup_group (abfd, hdr, newsect)) 778 return FALSE; 779 if ((hdr->sh_flags & SHF_TLS) != 0) 780 flags |= SEC_THREAD_LOCAL; 389 781 390 782 /* The debugging sections appear to be recognized only by name, not … … 400 792 int i; 401 793 402 for (i = sizeof (debug_sec_names) / sizeof (debug_sec_names[0]); i--;)794 for (i = ARRAY_SIZE (debug_sec_names); i--;) 403 795 if (strncmp (name, debug_sec_names[i], strlen (debug_sec_names[i])) == 0) 404 796 break; … … 414 806 are permitted. The GNU linker extension is to actually discard 415 807 all but one of the sections. */ 416 if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0) 808 if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0 809 && elf_next_in_group (newsect) == NULL) 417 810 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; 418 811 … … 420 813 if (bed->elf_backend_section_flags) 421 814 if (! bed->elf_backend_section_flags (&flags, hdr)) 422 return false;815 return FALSE; 423 816 424 817 if (! bfd_set_section_flags (abfd, newsect, flags)) 425 return false;818 return FALSE; 426 819 427 820 if ((flags & SEC_ALLOC) != 0) … … 444 837 for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++) 445 838 { 839 /* This section is part of this segment if its file 840 offset plus size lies within the segment's memory 841 span and, if the section is loaded, the extent of the 842 loaded data lies within the extent of the segment. 843 844 Note - we used to check the p_paddr field as well, and 845 refuse to set the LMA if it was 0. This is wrong 846 though, as a perfectly valid initialised segment can 847 have a p_paddr of zero. Some architectures, eg ARM, 848 place special significance on the address 0 and 849 executables need to be able to have a segment which 850 covers this address. */ 446 851 if (phdr->p_type == PT_LOAD 447 && phdr->p_vaddr != phdr->p_paddr 448 && phdr->p_vaddr <= hdr->sh_addr 449 && (phdr->p_vaddr + phdr->p_memsz 450 >= hdr->sh_addr + hdr->sh_size) 852 && (bfd_vma) hdr->sh_offset >= phdr->p_offset 853 && (hdr->sh_offset + hdr->sh_size 854 <= phdr->p_offset + phdr->p_memsz) 451 855 && ((flags & SEC_LOAD) == 0 452 || (phdr->p_offset <= (bfd_vma) hdr->sh_offset 453 && (phdr->p_offset + phdr->p_filesz 454 >= hdr->sh_offset + hdr->sh_size)))) 856 || (hdr->sh_offset + hdr->sh_size 857 <= phdr->p_offset + phdr->p_filesz))) 455 858 { 456 newsect->lma += phdr->p_paddr - phdr->p_vaddr; 457 break; 859 if ((flags & SEC_LOAD) == 0) 860 newsect->lma = (phdr->p_paddr 861 + hdr->sh_addr - phdr->p_vaddr); 862 else 863 /* We used to use the same adjustment for SEC_LOAD 864 sections, but that doesn't work if the segment 865 is packed with code from multiple VMAs. 866 Instead we calculate the section LMA based on 867 the segment LMA. It is assumed that the 868 segment will contain sections with contiguous 869 LMAs, even if the VMAs are not. */ 870 newsect->lma = (phdr->p_paddr 871 + hdr->sh_offset - phdr->p_offset); 872 873 /* With contiguous segments, we can't tell from file 874 offsets whether a section with zero size should 875 be placed at the end of one segment or the 876 beginning of the next. Decide based on vaddr. */ 877 if (hdr->sh_addr >= phdr->p_vaddr 878 && (hdr->sh_addr + hdr->sh_size 879 <= phdr->p_vaddr + phdr->p_memsz)) 880 break; 458 881 } 459 882 } … … 464 887 elf_section_data (newsect)->this_hdr = *hdr; 465 888 466 return true;889 return TRUE; 467 890 } 468 891 … … 495 918 if (i_shdrp != NULL) 496 919 { 497 shstrtab = bfd_elf_get_str_section 498 (abfd,elf_elfheader (abfd)->e_shstrndx);920 shstrtab = bfd_elf_get_str_section (abfd, 921 elf_elfheader (abfd)->e_shstrndx); 499 922 if (shstrtab != NULL) 500 923 { 501 max = elf_ elfheader (abfd)->e_shnum;924 max = elf_numsections (abfd); 502 925 for (i = 1; i < max; i++) 503 926 if (!strcmp (&shstrtab[i_shdrp[i]->sh_name], name)) … … 553 976 554 977 978 /* Make sure sec_info_type is cleared if sec_info is cleared too. */ 979 980 static void 981 merge_sections_remove_hook (abfd, sec) 982 bfd *abfd ATTRIBUTE_UNUSED; 983 asection *sec; 984 { 985 BFD_ASSERT (sec->sec_info_type == ELF_INFO_TYPE_MERGE); 986 sec->sec_info_type = ELF_INFO_TYPE_NONE; 987 } 988 989 /* Finish SHF_MERGE section merging. */ 990 991 bfd_boolean 992 _bfd_elf_merge_sections (abfd, info) 993 bfd *abfd; 994 struct bfd_link_info *info; 995 { 996 if (!is_elf_hash_table (info)) 997 return FALSE; 998 if (elf_hash_table (info)->merge_info) 999 _bfd_merge_sections (abfd, elf_hash_table (info)->merge_info, 1000 merge_sections_remove_hook); 1001 return TRUE; 1002 } 1003 1004 void 1005 _bfd_elf_link_just_syms (sec, info) 1006 asection *sec; 1007 struct bfd_link_info *info; 1008 { 1009 sec->output_section = bfd_abs_section_ptr; 1010 sec->output_offset = sec->vma; 1011 if (!is_elf_hash_table (info)) 1012 return; 1013 1014 sec->sec_info_type = ELF_INFO_TYPE_JUST_SYMS; 1015 } 1016 1017 1018 /* Copy the program header and other data from one object module to 1019 another. */ 1020 1021 bfd_boolean 1022 _bfd_elf_copy_private_bfd_data (ibfd, obfd) 1023 bfd *ibfd; 1024 bfd *obfd; 1025 { 1026 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 1027 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 1028 return TRUE; 1029 1030 BFD_ASSERT (!elf_flags_init (obfd) 1031 || (elf_elfheader (obfd)->e_flags 1032 == elf_elfheader (ibfd)->e_flags)); 1033 1034 elf_gp (obfd) = elf_gp (ibfd); 1035 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; 1036 elf_flags_init (obfd) = TRUE; 1037 return TRUE; 1038 } 1039 555 1040 /* Print out the program headers. */ 556 1041 557 b oolean1042 bfd_boolean 558 1043 _bfd_elf_print_private_bfd_data (abfd, farg) 559 1044 bfd *abfd; … … 574 1059 for (i = 0; i < c; i++, p++) 575 1060 { 576 const char * s;1061 const char *pt; 577 1062 char buf[20]; 578 1063 579 1064 switch (p->p_type) 580 1065 { 581 case PT_NULL: s = "NULL"; break; 582 case PT_LOAD: s = "LOAD"; break; 583 case PT_DYNAMIC: s = "DYNAMIC"; break; 584 case PT_INTERP: s = "INTERP"; break; 585 case PT_NOTE: s = "NOTE"; break; 586 case PT_SHLIB: s = "SHLIB"; break; 587 case PT_PHDR: s = "PHDR"; break; 588 default: sprintf (buf, "0x%lx", p->p_type); s = buf; break; 1066 case PT_NULL: pt = "NULL"; break; 1067 case PT_LOAD: pt = "LOAD"; break; 1068 case PT_DYNAMIC: pt = "DYNAMIC"; break; 1069 case PT_INTERP: pt = "INTERP"; break; 1070 case PT_NOTE: pt = "NOTE"; break; 1071 case PT_SHLIB: pt = "SHLIB"; break; 1072 case PT_PHDR: pt = "PHDR"; break; 1073 case PT_TLS: pt = "TLS"; break; 1074 case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break; 1075 default: sprintf (buf, "0x%lx", p->p_type); pt = buf; break; 589 1076 } 590 fprintf (f, "%8s off 0x", s);591 fprintf_vma (f, p->p_offset);1077 fprintf (f, "%8s off 0x", pt); 1078 bfd_fprintf_vma (abfd, f, p->p_offset); 592 1079 fprintf (f, " vaddr 0x"); 593 fprintf_vma (f, p->p_vaddr);1080 bfd_fprintf_vma (abfd, f, p->p_vaddr); 594 1081 fprintf (f, " paddr 0x"); 595 fprintf_vma (f, p->p_paddr);1082 bfd_fprintf_vma (abfd, f, p->p_paddr); 596 1083 fprintf (f, " align 2**%u\n", bfd_log2 (p->p_align)); 597 1084 fprintf (f, " filesz 0x"); 598 fprintf_vma (f, p->p_filesz);1085 bfd_fprintf_vma (abfd, f, p->p_filesz); 599 1086 fprintf (f, " memsz 0x"); 600 fprintf_vma (f, p->p_memsz);1087 bfd_fprintf_vma (abfd, f, p->p_memsz); 601 1088 fprintf (f, " flags %c%c%c", 602 1089 (p->p_flags & PF_R) != 0 ? 'r' : '-', 603 1090 (p->p_flags & PF_W) != 0 ? 'w' : '-', 604 1091 (p->p_flags & PF_X) != 0 ? 'x' : '-'); 605 if ((p->p_flags &~ ( PF_R | PF_W | PF_X)) != 0)606 fprintf (f, " %lx", p->p_flags &~ ( PF_R | PF_W | PF_X));1092 if ((p->p_flags &~ (unsigned) (PF_R | PF_W | PF_X)) != 0) 1093 fprintf (f, " %lx", p->p_flags &~ (unsigned) (PF_R | PF_W | PF_X)); 607 1094 fprintf (f, "\n"); 608 1095 } … … 613 1100 { 614 1101 int elfsec; 615 unsigned long link;1102 unsigned long shlink; 616 1103 bfd_byte *extdyn, *extdynend; 617 1104 size_t extdynsize; … … 630 1117 if (elfsec == -1) 631 1118 goto error_return; 632 link = elf_elfsections (abfd)[elfsec]->sh_link;1119 shlink = elf_elfsections (abfd)[elfsec]->sh_link; 633 1120 634 1121 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; … … 642 1129 const char *name; 643 1130 char ab[20]; 644 b oolean stringp;1131 bfd_boolean stringp; 645 1132 646 1133 (*swap_dyn_in) (abfd, (PTR) extdyn, &dyn); … … 649 1136 break; 650 1137 651 stringp = false;1138 stringp = FALSE; 652 1139 switch (dyn.d_tag) 653 1140 { … … 657 1144 break; 658 1145 659 case DT_NEEDED: name = "NEEDED"; stringp = true; break;1146 case DT_NEEDED: name = "NEEDED"; stringp = TRUE; break; 660 1147 case DT_PLTRELSZ: name = "PLTRELSZ"; break; 661 1148 case DT_PLTGOT: name = "PLTGOT"; break; … … 670 1157 case DT_INIT: name = "INIT"; break; 671 1158 case DT_FINI: name = "FINI"; break; 672 case DT_SONAME: name = "SONAME"; stringp = true; break;673 case DT_RPATH: name = "RPATH"; stringp = true; break;1159 case DT_SONAME: name = "SONAME"; stringp = TRUE; break; 1160 case DT_RPATH: name = "RPATH"; stringp = TRUE; break; 674 1161 case DT_SYMBOLIC: name = "SYMBOLIC"; break; 675 1162 case DT_REL: name = "REL"; break; … … 685 1172 case DT_INIT_ARRAYSZ: name = "INIT_ARRAYSZ"; break; 686 1173 case DT_FINI_ARRAYSZ: name = "FINI_ARRAYSZ"; break; 687 case DT_RUNPATH: name = "RUNPATH"; stringp = true; break;1174 case DT_RUNPATH: name = "RUNPATH"; stringp = TRUE; break; 688 1175 case DT_FLAGS: name = "FLAGS"; break; 689 1176 case DT_PREINIT_ARRAY: name = "PREINIT_ARRAY"; break; … … 697 1184 case DT_SYMINSZ: name = "SYMINSZ"; break; 698 1185 case DT_SYMINENT: name = "SYMINENT"; break; 699 case DT_CONFIG: name = "CONFIG"; stringp = true; break;700 case DT_DEPAUDIT: name = "DEPAUDIT"; stringp = true; break;701 case DT_AUDIT: name = "AUDIT"; stringp = true; break;1186 case DT_CONFIG: name = "CONFIG"; stringp = TRUE; break; 1187 case DT_DEPAUDIT: name = "DEPAUDIT"; stringp = TRUE; break; 1188 case DT_AUDIT: name = "AUDIT"; stringp = TRUE; break; 702 1189 case DT_PLTPAD: name = "PLTPAD"; break; 703 1190 case DT_MOVETAB: name = "MOVETAB"; break; … … 711 1198 case DT_VERNEED: name = "VERNEED"; break; 712 1199 case DT_VERNEEDNUM: name = "VERNEEDNUM"; break; 713 case DT_AUXILIARY: name = "AUXILIARY"; stringp = true; break;1200 case DT_AUXILIARY: name = "AUXILIARY"; stringp = TRUE; break; 714 1201 case DT_USED: name = "USED"; break; 715 case DT_FILTER: name = "FILTER"; stringp = true; break;1202 case DT_FILTER: name = "FILTER"; stringp = TRUE; break; 716 1203 } 717 1204 … … 722 1209 { 723 1210 const char *string; 724 725 string = bfd_elf_string_from_elf_section (abfd, link, 726 dyn.d_un.d_val);1211 unsigned int tagv = dyn.d_un.d_val; 1212 1213 string = bfd_elf_string_from_elf_section (abfd, shlink, tagv); 727 1214 if (string == NULL) 728 1215 goto error_return; … … 740 1227 { 741 1228 if (! _bfd_elf_slurp_version_tables (abfd)) 742 return false;1229 return FALSE; 743 1230 } 744 1231 … … 782 1269 } 783 1270 784 return true;1271 return TRUE; 785 1272 786 1273 error_return: 787 1274 if (dynbuf != NULL) 788 1275 free (dynbuf); 789 return false;1276 return FALSE; 790 1277 } 791 1278 … … 807 1294 case bfd_print_symbol_more: 808 1295 fprintf (file, "elf "); 809 fprintf_vma (file, symbol->value);1296 bfd_fprintf_vma (abfd, file, symbol->value); 810 1297 fprintf (file, " %lx", (long) symbol->flags); 811 1298 break; … … 816 1303 struct elf_backend_data *bed; 817 1304 unsigned char st_other; 1305 bfd_vma val; 818 1306 819 1307 section_name = symbol->section ? symbol->section->name : "(*none*)"; … … 826 1314 { 827 1315 name = symbol->name; 828 bfd_print_symbol_vandf ( (PTR) file, symbol);1316 bfd_print_symbol_vandf (abfd, (PTR) file, symbol); 829 1317 } 830 1318 … … 834 1322 For other symbols, we have no specified alignment, and 835 1323 we've printed the address; now print the size. */ 836 fprintf_vma (file, 837 (bfd_is_com_section (symbol->section) 838 ? ((elf_symbol_type *) symbol)->internal_elf_sym.st_value 839 : ((elf_symbol_type *) symbol)->internal_elf_sym.st_size)); 1324 if (bfd_is_com_section (symbol->section)) 1325 val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_value; 1326 else 1327 val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_size; 1328 bfd_fprintf_vma (abfd, file, val); 840 1329 841 1330 /* If we have version information, print it. */ … … 920 1409 const char *string; 921 1410 { 922 struct elf_link_hash_entry *ret = (struct elf_link_hash_entry *) entry;923 924 1411 /* Allocate the structure if it has not already been allocated by a 925 1412 subclass. */ 926 if (ret == (struct elf_link_hash_entry *) NULL) 927 ret = ((struct elf_link_hash_entry *) 928 bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry))); 929 if (ret == (struct elf_link_hash_entry *) NULL) 930 return (struct bfd_hash_entry *) ret; 1413 if (entry == NULL) 1414 { 1415 entry = bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry)); 1416 if (entry == NULL) 1417 return entry; 1418 } 931 1419 932 1420 /* Call the allocation method of the superclass. */ 933 ret = ((struct elf_link_hash_entry *) 934 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret, 935 table, string)); 936 if (ret != (struct elf_link_hash_entry *) NULL) 937 { 1421 entry = _bfd_link_hash_newfunc (entry, table, string); 1422 if (entry != NULL) 1423 { 1424 struct elf_link_hash_entry *ret = (struct elf_link_hash_entry *) entry; 1425 struct elf_link_hash_table *htab = (struct elf_link_hash_table *) table; 1426 938 1427 /* Set local fields. */ 939 1428 ret->indx = -1; 940 ret->size = 0;941 1429 ret->dynindx = -1; 942 1430 ret->dynstr_index = 0; 1431 ret->elf_hash_value = 0; 943 1432 ret->weakdef = NULL; 944 ret->got.offset = (bfd_vma) -1; 945 ret->plt.offset = (bfd_vma) -1; 946 ret->linker_section_pointer = (elf_linker_section_pointers_t *)0; 1433 ret->linker_section_pointer = NULL; 947 1434 ret->verinfo.verdef = NULL; 1435 ret->vtable_entries_size = 0; 948 1436 ret->vtable_entries_used = NULL; 949 ret->vtable_entries_size = 0;950 1437 ret->vtable_parent = NULL; 1438 ret->got = htab->init_refcount; 1439 ret->plt = htab->init_refcount; 1440 ret->size = 0; 951 1441 ret->type = STT_NOTYPE; 952 1442 ret->other = 0; … … 958 1448 } 959 1449 960 return (struct bfd_hash_entry *) ret;1450 return entry; 961 1451 } 962 1452 963 1453 /* Copy data from an indirect symbol to its direct symbol, hiding the 964 old indirect symbol. */1454 old indirect symbol. Also used for copying flags to a weakdef. */ 965 1455 966 1456 void 967 _bfd_elf_link_hash_copy_indirect (dir, ind) 1457 _bfd_elf_link_hash_copy_indirect (bed, dir, ind) 1458 struct elf_backend_data *bed; 968 1459 struct elf_link_hash_entry *dir, *ind; 969 1460 { 1461 bfd_signed_vma tmp; 1462 bfd_signed_vma lowest_valid = bed->can_refcount; 1463 970 1464 /* Copy down any references that we may have already seen to the 971 1465 symbol which just became indirect. */ … … 978 1472 | ELF_LINK_NON_GOT_REF)); 979 1473 980 /* Copy over the global and procedure linkage table offset entries. 1474 if (ind->root.type != bfd_link_hash_indirect) 1475 return; 1476 1477 /* Copy over the global and procedure linkage table refcount entries. 981 1478 These may have been already set up by a check_relocs routine. */ 982 if (dir->got.offset == (bfd_vma) -1) 983 { 984 dir->got.offset = ind->got.offset; 985 ind->got.offset = (bfd_vma) -1; 986 } 987 BFD_ASSERT (ind->got.offset == (bfd_vma) -1); 988 989 if (dir->plt.offset == (bfd_vma) -1) 990 { 991 dir->plt.offset = ind->plt.offset; 992 ind->plt.offset = (bfd_vma) -1; 993 } 994 BFD_ASSERT (ind->plt.offset == (bfd_vma) -1); 1479 tmp = dir->got.refcount; 1480 if (tmp < lowest_valid) 1481 { 1482 dir->got.refcount = ind->got.refcount; 1483 ind->got.refcount = tmp; 1484 } 1485 else 1486 BFD_ASSERT (ind->got.refcount < lowest_valid); 1487 1488 tmp = dir->plt.refcount; 1489 if (tmp < lowest_valid) 1490 { 1491 dir->plt.refcount = ind->plt.refcount; 1492 ind->plt.refcount = tmp; 1493 } 1494 else 1495 BFD_ASSERT (ind->plt.refcount < lowest_valid); 995 1496 996 1497 if (dir->dynindx == -1) … … 1001 1502 ind->dynstr_index = 0; 1002 1503 } 1003 BFD_ASSERT (ind->dynindx == -1); 1504 else 1505 BFD_ASSERT (ind->dynindx == -1); 1004 1506 } 1005 1507 1006 1508 void 1007 _bfd_elf_link_hash_hide_symbol (info, h )1008 struct bfd_link_info *info ATTRIBUTE_UNUSED;1509 _bfd_elf_link_hash_hide_symbol (info, h, force_local) 1510 struct bfd_link_info *info; 1009 1511 struct elf_link_hash_entry *h; 1010 { 1512 bfd_boolean force_local; 1513 { 1514 h->plt = elf_hash_table (info)->init_offset; 1011 1515 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 1012 h->plt.offset = (bfd_vma) -1; 1013 if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 1014 h->dynindx = -1; 1516 if (force_local) 1517 { 1518 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 1519 if (h->dynindx != -1) 1520 { 1521 h->dynindx = -1; 1522 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, 1523 h->dynstr_index); 1524 } 1525 } 1015 1526 } 1016 1527 1017 1528 /* Initialize an ELF linker hash table. */ 1018 1529 1019 b oolean1530 bfd_boolean 1020 1531 _bfd_elf_link_hash_table_init (table, abfd, newfunc) 1021 1532 struct elf_link_hash_table *table; 1022 1533 bfd *abfd; 1023 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *, 1024 struct bfd_hash_table *, 1025 const char *)); 1026 { 1027 table->dynamic_sections_created = false; 1534 struct bfd_hash_entry *(*newfunc) 1535 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, 1536 const char *)); 1537 { 1538 bfd_boolean ret; 1539 1540 table->dynamic_sections_created = FALSE; 1028 1541 table->dynobj = NULL; 1542 /* Make sure can_refcount is extended to the width and signedness of 1543 init_refcount before we subtract one from it. */ 1544 table->init_refcount.refcount = get_elf_backend_data (abfd)->can_refcount; 1545 table->init_refcount.refcount -= 1; 1546 table->init_offset.offset = -(bfd_vma) 1; 1029 1547 /* The first dynamic symbol is a dummy. */ 1030 1548 table->dynsymcount = 1; … … 1032 1550 table->bucketcount = 0; 1033 1551 table->needed = NULL; 1034 table->runpath = NULL;1035 1552 table->hgot = NULL; 1036 1553 table->stab_info = NULL; 1554 table->merge_info = NULL; 1555 memset (&table->eh_info, 0, sizeof (table->eh_info)); 1037 1556 table->dynlocal = NULL; 1038 return _bfd_link_hash_table_init (&table->root, abfd, newfunc); 1557 table->runpath = NULL; 1558 table->tls_segment = NULL; 1559 table->loaded = NULL; 1560 1561 ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc); 1562 table->root.type = bfd_link_elf_hash_table; 1563 1564 return ret; 1039 1565 } 1040 1566 … … 1046 1572 { 1047 1573 struct elf_link_hash_table *ret; 1048 1049 ret = ((struct elf_link_hash_table *) 1050 bfd_alloc (abfd, sizeof (struct elf_link_hash_table)));1574 bfd_size_type amt = sizeof (struct elf_link_hash_table); 1575 1576 ret = (struct elf_link_hash_table *) bfd_malloc (amt); 1051 1577 if (ret == (struct elf_link_hash_table *) NULL) 1052 1578 return NULL; … … 1054 1580 if (! _bfd_elf_link_hash_table_init (ret, abfd, _bfd_elf_link_hash_newfunc)) 1055 1581 { 1056 bfd_release (abfd,ret);1582 free (ret); 1057 1583 return NULL; 1058 1584 } … … 1094 1620 struct bfd_link_info *info; 1095 1621 { 1096 if ( info->hash->creator->flavour != bfd_target_elf_flavour)1622 if (! is_elf_hash_table (info)) 1097 1623 return NULL; 1098 1624 return elf_hash_table (info)->needed; … … 1107 1633 struct bfd_link_info *info; 1108 1634 { 1109 if ( info->hash->creator->flavour != bfd_target_elf_flavour)1635 if (! is_elf_hash_table (info)) 1110 1636 return NULL; 1111 1637 return elf_hash_table (info)->runpath; … … 1129 1655 the ELF linker emulation code. */ 1130 1656 1131 b oolean1657 bfd_boolean 1132 1658 bfd_elf_get_bfd_needed_list (abfd, pneeded) 1133 1659 bfd *abfd; … … 1137 1663 bfd_byte *dynbuf = NULL; 1138 1664 int elfsec; 1139 unsigned long link;1665 unsigned long shlink; 1140 1666 bfd_byte *extdyn, *extdynend; 1141 1667 size_t extdynsize; … … 1146 1672 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour 1147 1673 || bfd_get_format (abfd) != bfd_object) 1148 return true;1674 return TRUE; 1149 1675 1150 1676 s = bfd_get_section_by_name (abfd, ".dynamic"); 1151 1677 if (s == NULL || s->_raw_size == 0) 1152 return true;1678 return TRUE; 1153 1679 1154 1680 dynbuf = (bfd_byte *) bfd_malloc (s->_raw_size); … … 1164 1690 goto error_return; 1165 1691 1166 link = elf_elfsections (abfd)[elfsec]->sh_link;1692 shlink = elf_elfsections (abfd)[elfsec]->sh_link; 1167 1693 1168 1694 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; … … 1184 1710 const char *string; 1185 1711 struct bfd_link_needed_list *l; 1186 1187 string = bfd_elf_string_from_elf_section (abfd, link, 1188 dyn.d_un.d_val); 1712 unsigned int tagv = dyn.d_un.d_val; 1713 bfd_size_type amt; 1714 1715 string = bfd_elf_string_from_elf_section (abfd, shlink, tagv); 1189 1716 if (string == NULL) 1190 1717 goto error_return; 1191 1718 1192 l = (struct bfd_link_needed_list *) bfd_alloc (abfd, sizeof *l); 1719 amt = sizeof *l; 1720 l = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt); 1193 1721 if (l == NULL) 1194 1722 goto error_return; … … 1203 1731 free (dynbuf); 1204 1732 1205 return true;1733 return TRUE; 1206 1734 1207 1735 error_return: 1208 1736 if (dynbuf != NULL) 1209 1737 free (dynbuf); 1210 return false;1738 return FALSE; 1211 1739 } 1212 1740 … … 1224 1752 bfd_size_type loc; 1225 1753 1226 loc = _bfd_stringtab_add (ret, "", true, false);1754 loc = _bfd_stringtab_add (ret, "", TRUE, FALSE); 1227 1755 BFD_ASSERT (loc == 0 || loc == (bfd_size_type) -1); 1228 1756 if (loc == (bfd_size_type) -1) … … 1240 1768 /* Create a new bfd section from an ELF section header. */ 1241 1769 1242 b oolean1770 bfd_boolean 1243 1771 bfd_section_from_shdr (abfd, shindex) 1244 1772 bfd *abfd; … … 1248 1776 Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd); 1249 1777 struct elf_backend_data *bed = get_elf_backend_data (abfd); 1250 c har *name;1778 const char *name; 1251 1779 1252 1780 name = elf_string_from_elf_strtab (abfd, hdr->sh_name); … … 1256 1784 case SHT_NULL: 1257 1785 /* Inactive section. Throw it away. */ 1258 return true;1786 return TRUE; 1259 1787 1260 1788 case SHT_PROGBITS: /* Normal section with contents. */ 1261 case SHT_DYNAMIC: /* Dynamic linking information. */1262 1789 case SHT_NOBITS: /* .bss section. */ 1263 1790 case SHT_HASH: /* .hash section. */ 1264 1791 case SHT_NOTE: /* .note section. */ 1792 case SHT_INIT_ARRAY: /* .init_array section. */ 1793 case SHT_FINI_ARRAY: /* .fini_array section. */ 1794 case SHT_PREINIT_ARRAY: /* .preinit_array section. */ 1265 1795 return _bfd_elf_make_section_from_shdr (abfd, hdr, name); 1796 1797 case SHT_DYNAMIC: /* Dynamic linking information. */ 1798 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) 1799 return FALSE; 1800 if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB) 1801 { 1802 Elf_Internal_Shdr *dynsymhdr; 1803 1804 /* The shared libraries distributed with hpux11 have a bogus 1805 sh_link field for the ".dynamic" section. Find the 1806 string table for the ".dynsym" section instead. */ 1807 if (elf_dynsymtab (abfd) != 0) 1808 { 1809 dynsymhdr = elf_elfsections (abfd)[elf_dynsymtab (abfd)]; 1810 hdr->sh_link = dynsymhdr->sh_link; 1811 } 1812 else 1813 { 1814 unsigned int i, num_sec; 1815 1816 num_sec = elf_numsections (abfd); 1817 for (i = 1; i < num_sec; i++) 1818 { 1819 dynsymhdr = elf_elfsections (abfd)[i]; 1820 if (dynsymhdr->sh_type == SHT_DYNSYM) 1821 { 1822 hdr->sh_link = dynsymhdr->sh_link; 1823 break; 1824 } 1825 } 1826 } 1827 } 1828 break; 1266 1829 1267 1830 case SHT_SYMTAB: /* A symbol table */ 1268 1831 if (elf_onesymtab (abfd) == shindex) 1269 return true;1832 return TRUE; 1270 1833 1271 1834 BFD_ASSERT (hdr->sh_entsize == bed->s->sizeof_sym); … … 1285 1848 && (abfd->flags & DYNAMIC) != 0 1286 1849 && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) 1287 return false;1288 1289 return true;1850 return FALSE; 1851 1852 return TRUE; 1290 1853 1291 1854 case SHT_DYNSYM: /* A dynamic symbol table */ 1292 1855 if (elf_dynsymtab (abfd) == shindex) 1293 return true;1856 return TRUE; 1294 1857 1295 1858 BFD_ASSERT (hdr->sh_entsize == bed->s->sizeof_sym); … … 1304 1867 return _bfd_elf_make_section_from_shdr (abfd, hdr, name); 1305 1868 1869 case SHT_SYMTAB_SHNDX: /* Symbol section indices when >64k sections */ 1870 if (elf_symtab_shndx (abfd) == shindex) 1871 return TRUE; 1872 1873 /* Get the associated symbol table. */ 1874 if (! bfd_section_from_shdr (abfd, hdr->sh_link) 1875 || hdr->sh_link != elf_onesymtab (abfd)) 1876 return FALSE; 1877 1878 elf_symtab_shndx (abfd) = shindex; 1879 elf_tdata (abfd)->symtab_shndx_hdr = *hdr; 1880 elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->symtab_shndx_hdr; 1881 return TRUE; 1882 1306 1883 case SHT_STRTAB: /* A string table */ 1307 1884 if (hdr->bfd_section != NULL) 1308 return true;1885 return TRUE; 1309 1886 if (ehdr->e_shstrndx == shindex) 1310 1887 { 1311 1888 elf_tdata (abfd)->shstrtab_hdr = *hdr; 1312 1889 elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr; 1313 return true;1890 return TRUE; 1314 1891 } 1315 1892 { 1316 unsigned int i; 1317 1318 for (i = 1; i < ehdr->e_shnum; i++) 1893 unsigned int i, num_sec; 1894 1895 num_sec = elf_numsections (abfd); 1896 for (i = 1; i < num_sec; i++) 1319 1897 { 1320 1898 Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i]; … … 1322 1900 { 1323 1901 if (! bfd_section_from_shdr (abfd, i)) 1324 return false;1902 return FALSE; 1325 1903 if (elf_onesymtab (abfd) == i) 1326 1904 { … … 1328 1906 elf_elfsections (abfd)[shindex] = 1329 1907 &elf_tdata (abfd)->strtab_hdr; 1330 return true;1908 return TRUE; 1331 1909 } 1332 1910 if (elf_dynsymtab (abfd) == i) … … 1362 1940 asection *target_sect; 1363 1941 Elf_Internal_Shdr *hdr2; 1942 unsigned int num_sec = elf_numsections (abfd); 1364 1943 1365 1944 /* Check for a bogus link to avoid crashing. */ 1366 if (hdr->sh_link >= ehdr->e_shnum) 1945 if ((hdr->sh_link >= SHN_LORESERVE && hdr->sh_link <= SHN_HIRESERVE) 1946 || hdr->sh_link >= num_sec) 1367 1947 { 1368 1948 ((*_bfd_error_handler) 1369 1949 (_("%s: invalid link %lu for reloc section %s (index %u)"), 1370 bfd_ get_filename (abfd), hdr->sh_link, name, shindex));1950 bfd_archive_filename (abfd), hdr->sh_link, name, shindex)); 1371 1951 return _bfd_elf_make_section_from_shdr (abfd, hdr, name); 1372 1952 } … … 1382 1962 && elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_DYNSYM) 1383 1963 { 1384 int scan;1964 unsigned int scan; 1385 1965 int found; 1386 1966 1387 1967 found = 0; 1388 for (scan = 1; scan < ehdr->e_shnum; scan++)1968 for (scan = 1; scan < num_sec; scan++) 1389 1969 { 1390 1970 if (elf_elfsections (abfd)[scan]->sh_type == SHT_SYMTAB … … 1406 1986 if (elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB 1407 1987 && ! bfd_section_from_shdr (abfd, hdr->sh_link)) 1408 return false;1988 return FALSE; 1409 1989 1410 1990 /* If this reloc section does not use the main symbol table we … … 1418 1998 1419 1999 if (! bfd_section_from_shdr (abfd, hdr->sh_info)) 1420 return false;2000 return FALSE; 1421 2001 target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info); 1422 2002 if (target_sect == NULL) 1423 return false;2003 return FALSE; 1424 2004 1425 2005 if ((target_sect->flags & SEC_RELOC) == 0 … … 1428 2008 else 1429 2009 { 2010 bfd_size_type amt; 1430 2011 BFD_ASSERT (elf_section_data (target_sect)->rel_hdr2 == NULL); 1431 hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, sizeof (*hdr2)); 2012 amt = sizeof (*hdr2); 2013 hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt); 1432 2014 elf_section_data (target_sect)->rel_hdr2 = hdr2; 1433 2015 } … … 1441 2023 its relocations are of the REL or RELA variety. */ 1442 2024 if (hdr->sh_size != 0) 1443 elf_section_data (target_sect)->use_rela_p 1444 = (hdr->sh_type == SHT_RELA); 2025 target_sect->use_rela_p = hdr->sh_type == SHT_RELA; 1445 2026 abfd->flags |= HAS_RELOC; 1446 return true;2027 return TRUE; 1447 2028 } 1448 2029 break; … … 1467 2048 1468 2049 case SHT_SHLIB: 1469 return true; 2050 return TRUE; 2051 2052 case SHT_GROUP: 2053 /* We need a BFD section for objcopy and relocatable linking, 2054 and it's handy to have the signature available as the section 2055 name. */ 2056 name = group_signature (abfd, hdr); 2057 if (name == NULL) 2058 return FALSE; 2059 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name)) 2060 return FALSE; 2061 if (hdr->contents != NULL) 2062 { 2063 Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents; 2064 unsigned int n_elt = hdr->sh_size / 4; 2065 asection *s; 2066 2067 if (idx->flags & GRP_COMDAT) 2068 hdr->bfd_section->flags 2069 |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; 2070 2071 while (--n_elt != 0) 2072 if ((s = (++idx)->shdr->bfd_section) != NULL 2073 && elf_next_in_group (s) != NULL) 2074 { 2075 elf_next_in_group (hdr->bfd_section) = s; 2076 break; 2077 } 2078 } 2079 break; 1470 2080 1471 2081 default: … … 1478 2088 } 1479 2089 1480 return true; 2090 return TRUE; 2091 } 2092 2093 /* Return the section for the local symbol specified by ABFD, R_SYMNDX. 2094 Return SEC for sections that have no elf section, and NULL on error. */ 2095 2096 asection * 2097 bfd_section_from_r_symndx (abfd, cache, sec, r_symndx) 2098 bfd *abfd; 2099 struct sym_sec_cache *cache; 2100 asection *sec; 2101 unsigned long r_symndx; 2102 { 2103 Elf_Internal_Shdr *symtab_hdr; 2104 unsigned char esym[sizeof (Elf64_External_Sym)]; 2105 Elf_External_Sym_Shndx eshndx; 2106 Elf_Internal_Sym isym; 2107 unsigned int ent = r_symndx % LOCAL_SYM_CACHE_SIZE; 2108 2109 if (cache->abfd == abfd && cache->indx[ent] == r_symndx) 2110 return cache->sec[ent]; 2111 2112 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 2113 if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx, 2114 &isym, esym, &eshndx) == NULL) 2115 return NULL; 2116 2117 if (cache->abfd != abfd) 2118 { 2119 memset (cache->indx, -1, sizeof (cache->indx)); 2120 cache->abfd = abfd; 2121 } 2122 cache->indx[ent] = r_symndx; 2123 cache->sec[ent] = sec; 2124 if (isym.st_shndx < SHN_LORESERVE || isym.st_shndx > SHN_HIRESERVE) 2125 { 2126 asection *s; 2127 s = bfd_section_from_elf_index (abfd, isym.st_shndx); 2128 if (s != NULL) 2129 cache->sec[ent] = s; 2130 } 2131 return cache->sec[ent]; 1481 2132 } 1482 2133 … … 1489 2140 unsigned int index; 1490 2141 { 1491 BFD_ASSERT (index > 0 && index < SHN_LORESERVE); 1492 if (index >= elf_elfheader (abfd)->e_shnum) 2142 if (index >= elf_numsections (abfd)) 1493 2143 return NULL; 1494 2144 return elf_elfsections (abfd)[index]->bfd_section; 1495 2145 } 1496 2146 1497 b oolean2147 bfd_boolean 1498 2148 _bfd_elf_new_section_hook (abfd, sec) 1499 2149 bfd *abfd; … … 1502 2152 struct bfd_elf_section_data *sdata; 1503 2153 1504 sdata = (struct bfd_elf_section_data *) bfd_zalloc (abfd, sizeof (*sdata)); 1505 if (!sdata) 1506 return false; 1507 sec->used_by_bfd = (PTR) sdata; 2154 sdata = (struct bfd_elf_section_data *) sec->used_by_bfd; 2155 if (sdata == NULL) 2156 { 2157 bfd_size_type amt = sizeof (*sdata); 2158 sdata = (struct bfd_elf_section_data *) bfd_zalloc (abfd, amt); 2159 if (sdata == NULL) 2160 return FALSE; 2161 sec->used_by_bfd = (PTR) sdata; 2162 } 1508 2163 1509 2164 /* Indicate whether or not this section should use RELA relocations. */ 1510 sdata->use_rela_p 1511 = get_elf_backend_data (abfd)->default_use_rela_p; 1512 1513 return true; 2165 sec->use_rela_p = get_elf_backend_data (abfd)->default_use_rela_p; 2166 2167 return TRUE; 1514 2168 } 1515 2169 … … 1536 2190 */ 1537 2191 1538 b oolean2192 bfd_boolean 1539 2193 _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename) 1540 2194 bfd *abfd; … … 1546 2200 char *name; 1547 2201 char namebuf[64]; 2202 size_t len; 1548 2203 int split; 1549 2204 … … 1552 2207 && (hdr->p_memsz > hdr->p_filesz)); 1553 2208 sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : ""); 1554 name = bfd_alloc (abfd, strlen (namebuf) + 1); 2209 len = strlen (namebuf) + 1; 2210 name = bfd_alloc (abfd, (bfd_size_type) len); 1555 2211 if (!name) 1556 return false;1557 strcpy (name, namebuf);2212 return FALSE; 2213 memcpy (name, namebuf, len); 1558 2214 newsect = bfd_make_section (abfd, name); 1559 2215 if (newsect == NULL) 1560 return false;2216 return FALSE; 1561 2217 newsect->vma = hdr->p_vaddr; 1562 2218 newsect->lma = hdr->p_paddr; … … 1583 2239 { 1584 2240 sprintf (namebuf, "%s%db", typename, index); 1585 name = bfd_alloc (abfd, strlen (namebuf) + 1); 2241 len = strlen (namebuf) + 1; 2242 name = bfd_alloc (abfd, (bfd_size_type) len); 1586 2243 if (!name) 1587 return false;1588 strcpy (name, namebuf);2244 return FALSE; 2245 memcpy (name, namebuf, len); 1589 2246 newsect = bfd_make_section (abfd, name); 1590 2247 if (newsect == NULL) 1591 return false;2248 return FALSE; 1592 2249 newsect->vma = hdr->p_vaddr + hdr->p_filesz; 1593 2250 newsect->lma = hdr->p_paddr + hdr->p_filesz; … … 1603 2260 } 1604 2261 1605 return true;1606 } 1607 1608 b oolean2262 return TRUE; 2263 } 2264 2265 bfd_boolean 1609 2266 bfd_section_from_phdr (abfd, hdr, index) 1610 2267 bfd *abfd; … … 1630 2287 case PT_NOTE: 1631 2288 if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note")) 1632 return false;1633 if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz))1634 return false;1635 return true;2289 return FALSE; 2290 if (! elfcore_read_notes (abfd, (file_ptr) hdr->p_offset, hdr->p_filesz)) 2291 return FALSE; 2292 return TRUE; 1636 2293 1637 2294 case PT_SHLIB: … … 1640 2297 case PT_PHDR: 1641 2298 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "phdr"); 2299 2300 case PT_GNU_EH_FRAME: 2301 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, 2302 "eh_frame_hdr"); 1642 2303 1643 2304 default: … … 1653 2314 1654 2315 /* Initialize REL_HDR, the section-header for new section, containing 1655 relocations against ASECT. If USE_RELA_P is true, we use RELA2316 relocations against ASECT. If USE_RELA_P is TRUE, we use RELA 1656 2317 relocations; otherwise, we use REL relocations. */ 1657 2318 1658 b oolean2319 bfd_boolean 1659 2320 _bfd_elf_init_reloc_shdr (abfd, rel_hdr, asect, use_rela_p) 1660 2321 bfd *abfd; 1661 2322 Elf_Internal_Shdr *rel_hdr; 1662 2323 asection *asect; 1663 b oolean use_rela_p;2324 bfd_boolean use_rela_p; 1664 2325 { 1665 2326 char *name; 1666 struct elf_backend_data *bed ;1667 1668 bed = get_elf_backend_data (abfd); 1669 name = bfd_alloc (abfd, sizeof ".rela" + strlen (asect->name));2327 struct elf_backend_data *bed = get_elf_backend_data (abfd); 2328 bfd_size_type amt = sizeof ".rela" + strlen (asect->name); 2329 2330 name = bfd_alloc (abfd, amt); 1670 2331 if (name == NULL) 1671 return false;2332 return FALSE; 1672 2333 sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", asect->name); 1673 2334 rel_hdr->sh_name = 1674 (unsigned int) _bfd_ stringtab_add (elf_shstrtab (abfd), name,1675 true, false);2335 (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), name, 2336 FALSE); 1676 2337 if (rel_hdr->sh_name == (unsigned int) -1) 1677 return false;2338 return FALSE; 1678 2339 rel_hdr->sh_type = use_rela_p ? SHT_RELA : SHT_REL; 1679 2340 rel_hdr->sh_entsize = (use_rela_p … … 1686 2347 rel_hdr->sh_offset = 0; 1687 2348 1688 return true;2349 return TRUE; 1689 2350 } 1690 2351 … … 1698 2359 { 1699 2360 struct elf_backend_data *bed = get_elf_backend_data (abfd); 1700 b oolean *failedptr = (boolean *) failedptrarg;2361 bfd_boolean *failedptr = (bfd_boolean *) failedptrarg; 1701 2362 Elf_Internal_Shdr *this_hdr; 1702 2363 … … 1710 2371 this_hdr = &elf_section_data (asect)->this_hdr; 1711 2372 1712 this_hdr->sh_name = (unsigned long) _bfd_stringtab_add (elf_shstrtab (abfd), 1713 asect->name, 1714 true, false); 1715 if (this_hdr->sh_name == (unsigned long) -1) 1716 { 1717 *failedptr = true; 2373 this_hdr->sh_name = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), 2374 asect->name, FALSE); 2375 if (this_hdr->sh_name == (unsigned int) -1) 2376 { 2377 *failedptr = TRUE; 1718 2378 return; 1719 2379 } … … 1767 2427 this_hdr->sh_entsize = bed->s->sizeof_rel; 1768 2428 } 2429 else if (strcmp (asect->name, ".init_array") == 0) 2430 this_hdr->sh_type = SHT_INIT_ARRAY; 2431 else if (strcmp (asect->name, ".fini_array") == 0) 2432 this_hdr->sh_type = SHT_FINI_ARRAY; 2433 else if (strcmp (asect->name, ".preinit_array") == 0) 2434 this_hdr->sh_type = SHT_PREINIT_ARRAY; 1769 2435 else if (strncmp (asect->name, ".note", 5) == 0) 1770 2436 this_hdr->sh_type = SHT_NOTE; … … 1803 2469 || this_hdr->sh_info == elf_tdata (abfd)->cverrefs); 1804 2470 } 2471 else if ((asect->flags & SEC_GROUP) != 0) 2472 { 2473 this_hdr->sh_type = SHT_GROUP; 2474 this_hdr->sh_entsize = 4; 2475 } 1805 2476 else if ((asect->flags & SEC_ALLOC) != 0 1806 && ((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)) 2477 && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) 2478 || (asect->flags & SEC_NEVER_LOAD) != 0)) 1807 2479 this_hdr->sh_type = SHT_NOBITS; 1808 2480 else … … 1815 2487 if ((asect->flags & SEC_CODE) != 0) 1816 2488 this_hdr->sh_flags |= SHF_EXECINSTR; 2489 if ((asect->flags & SEC_MERGE) != 0) 2490 { 2491 this_hdr->sh_flags |= SHF_MERGE; 2492 this_hdr->sh_entsize = asect->entsize; 2493 if ((asect->flags & SEC_STRINGS) != 0) 2494 this_hdr->sh_flags |= SHF_STRINGS; 2495 } 2496 if ((asect->flags & SEC_GROUP) == 0 && elf_group_name (asect) != NULL) 2497 this_hdr->sh_flags |= SHF_GROUP; 2498 if ((asect->flags & SEC_THREAD_LOCAL) != 0) 2499 { 2500 this_hdr->sh_flags |= SHF_TLS; 2501 if (asect->_raw_size == 0 && (asect->flags & SEC_HAS_CONTENTS) == 0) 2502 { 2503 struct bfd_link_order *o; 2504 2505 this_hdr->sh_size = 0; 2506 for (o = asect->link_order_head; o != NULL; o = o->next) 2507 if (this_hdr->sh_size < o->offset + o->size) 2508 this_hdr->sh_size = o->offset + o->size; 2509 if (this_hdr->sh_size) 2510 this_hdr->sh_type = SHT_NOBITS; 2511 } 2512 } 1817 2513 1818 2514 /* Check for processor-specific section types. */ 1819 if (bed->elf_backend_fake_sections) 1820 (*bed->elf_backend_fake_sections) (abfd, this_hdr, asect); 2515 if (bed->elf_backend_fake_sections 2516 && !(*bed->elf_backend_fake_sections) (abfd, this_hdr, asect)) 2517 *failedptr = TRUE; 1821 2518 1822 2519 /* If the section has relocs, set up a section header for the … … 1828 2525 &elf_section_data (asect)->rel_hdr, 1829 2526 asect, 1830 elf_section_data (asect)->use_rela_p)) 1831 *failedptr = true; 2527 asect->use_rela_p)) 2528 *failedptr = TRUE; 2529 } 2530 2531 /* Fill in the contents of a SHT_GROUP section. */ 2532 2533 void 2534 bfd_elf_set_group_contents (abfd, sec, failedptrarg) 2535 bfd *abfd; 2536 asection *sec; 2537 PTR failedptrarg; 2538 { 2539 bfd_boolean *failedptr = (bfd_boolean *) failedptrarg; 2540 unsigned long symindx; 2541 asection *elt, *first; 2542 unsigned char *loc; 2543 struct bfd_link_order *l; 2544 bfd_boolean gas; 2545 2546 if (elf_section_data (sec)->this_hdr.sh_type != SHT_GROUP 2547 || *failedptr) 2548 return; 2549 2550 symindx = 0; 2551 if (elf_group_id (sec) != NULL) 2552 symindx = elf_group_id (sec)->udata.i; 2553 2554 if (symindx == 0) 2555 { 2556 /* If called from the assembler, swap_out_syms will have set up 2557 elf_section_syms; If called for "ld -r", use target_index. */ 2558 if (elf_section_syms (abfd) != NULL) 2559 symindx = elf_section_syms (abfd)[sec->index]->udata.i; 2560 else 2561 symindx = sec->target_index; 2562 } 2563 elf_section_data (sec)->this_hdr.sh_info = symindx; 2564 2565 /* The contents won't be allocated for "ld -r" or objcopy. */ 2566 gas = TRUE; 2567 if (sec->contents == NULL) 2568 { 2569 gas = FALSE; 2570 sec->contents = bfd_alloc (abfd, sec->_raw_size); 2571 2572 /* Arrange for the section to be written out. */ 2573 elf_section_data (sec)->this_hdr.contents = sec->contents; 2574 if (sec->contents == NULL) 2575 { 2576 *failedptr = TRUE; 2577 return; 2578 } 2579 } 2580 2581 loc = sec->contents + sec->_raw_size; 2582 2583 /* Get the pointer to the first section in the group that gas 2584 squirreled away here. objcopy arranges for this to be set to the 2585 start of the input section group. */ 2586 first = elt = elf_next_in_group (sec); 2587 2588 /* First element is a flag word. Rest of section is elf section 2589 indices for all the sections of the group. Write them backwards 2590 just to keep the group in the same order as given in .section 2591 directives, not that it matters. */ 2592 while (elt != NULL) 2593 { 2594 asection *s; 2595 unsigned int idx; 2596 2597 loc -= 4; 2598 s = elt; 2599 if (!gas) 2600 s = s->output_section; 2601 idx = 0; 2602 if (s != NULL) 2603 idx = elf_section_data (s)->this_idx; 2604 H_PUT_32 (abfd, idx, loc); 2605 elt = elf_next_in_group (elt); 2606 if (elt == first) 2607 break; 2608 } 2609 2610 /* If this is a relocatable link, then the above did nothing because 2611 SEC is the output section. Look through the input sections 2612 instead. */ 2613 for (l = sec->link_order_head; l != NULL; l = l->next) 2614 if (l->type == bfd_indirect_link_order 2615 && (elt = elf_next_in_group (l->u.indirect.section)) != NULL) 2616 do 2617 { 2618 loc -= 4; 2619 H_PUT_32 (abfd, 2620 elf_section_data (elt->output_section)->this_idx, loc); 2621 elt = elf_next_in_group (elt); 2622 /* During a relocatable link, the lists are circular. */ 2623 } 2624 while (elt != elf_next_in_group (l->u.indirect.section)); 2625 2626 /* With ld -r, merging SHT_GROUP sections results in wasted space 2627 due to allowing for the flag word on each input. We may well 2628 duplicate entries too. */ 2629 while ((loc -= 4) > sec->contents) 2630 H_PUT_32 (abfd, 0, loc); 2631 2632 if (loc != sec->contents) 2633 abort (); 2634 2635 H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc); 1832 2636 } 1833 2637 … … 1836 2640 in here too, while we're at it. */ 1837 2641 1838 static b oolean2642 static bfd_boolean 1839 2643 assign_section_numbers (abfd) 1840 2644 bfd *abfd; … … 1842 2646 struct elf_obj_tdata *t = elf_tdata (abfd); 1843 2647 asection *sec; 1844 unsigned int section_number ;2648 unsigned int section_number, secn; 1845 2649 Elf_Internal_Shdr **i_shdrp; 2650 bfd_size_type amt; 1846 2651 1847 2652 section_number = 1; 1848 2653 2654 _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd)); 2655 1849 2656 for (sec = abfd->sections; sec; sec = sec->next) 1850 2657 { 1851 2658 struct bfd_elf_section_data *d = elf_section_data (sec); 1852 2659 2660 if (section_number == SHN_LORESERVE) 2661 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 1853 2662 d->this_idx = section_number++; 2663 _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name); 1854 2664 if ((sec->flags & SEC_RELOC) == 0) 1855 2665 d->rel_idx = 0; 1856 2666 else 1857 d->rel_idx = section_number++; 2667 { 2668 if (section_number == SHN_LORESERVE) 2669 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 2670 d->rel_idx = section_number++; 2671 _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr.sh_name); 2672 } 1858 2673 1859 2674 if (d->rel_hdr2) 1860 d->rel_idx2 = section_number++; 2675 { 2676 if (section_number == SHN_LORESERVE) 2677 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 2678 d->rel_idx2 = section_number++; 2679 _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr2->sh_name); 2680 } 1861 2681 else 1862 2682 d->rel_idx2 = 0; 1863 2683 } 1864 2684 2685 if (section_number == SHN_LORESERVE) 2686 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 1865 2687 t->shstrtab_section = section_number++; 2688 _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->shstrtab_hdr.sh_name); 1866 2689 elf_elfheader (abfd)->e_shstrndx = t->shstrtab_section; 1867 t->shstrtab_hdr.sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));1868 2690 1869 2691 if (bfd_get_symcount (abfd) > 0) 1870 2692 { 2693 if (section_number == SHN_LORESERVE) 2694 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 1871 2695 t->symtab_section = section_number++; 2696 _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name); 2697 if (section_number > SHN_LORESERVE - 2) 2698 { 2699 if (section_number == SHN_LORESERVE) 2700 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 2701 t->symtab_shndx_section = section_number++; 2702 t->symtab_shndx_hdr.sh_name 2703 = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), 2704 ".symtab_shndx", FALSE); 2705 if (t->symtab_shndx_hdr.sh_name == (unsigned int) -1) 2706 return FALSE; 2707 } 2708 if (section_number == SHN_LORESERVE) 2709 section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; 1872 2710 t->strtab_section = section_number++; 1873 } 1874 2711 _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name); 2712 } 2713 2714 _bfd_elf_strtab_finalize (elf_shstrtab (abfd)); 2715 t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd)); 2716 2717 elf_numsections (abfd) = section_number; 1875 2718 elf_elfheader (abfd)->e_shnum = section_number; 2719 if (section_number > SHN_LORESERVE) 2720 elf_elfheader (abfd)->e_shnum -= SHN_HIRESERVE + 1 - SHN_LORESERVE; 1876 2721 1877 2722 /* Set up the list of section header pointers, in agreement with the 1878 2723 indices. */ 1879 i_shdrp = ((Elf_Internal_Shdr **)1880 bfd_alloc (abfd, section_number * sizeof (Elf_Internal_Shdr *)));2724 amt = section_number * sizeof (Elf_Internal_Shdr *); 2725 i_shdrp = (Elf_Internal_Shdr **) bfd_zalloc (abfd, amt); 1881 2726 if (i_shdrp == NULL) 1882 return false;1883 1884 i_shdrp[0] = ((Elf_Internal_Shdr *)1885 bfd_alloc (abfd, sizeof (Elf_Internal_Shdr)));2727 return FALSE; 2728 2729 amt = sizeof (Elf_Internal_Shdr); 2730 i_shdrp[0] = (Elf_Internal_Shdr *) bfd_zalloc (abfd, amt); 1886 2731 if (i_shdrp[0] == NULL) 1887 2732 { 1888 2733 bfd_release (abfd, i_shdrp); 1889 return false; 1890 } 1891 memset (i_shdrp[0], 0, sizeof (Elf_Internal_Shdr)); 2734 return FALSE; 2735 } 1892 2736 1893 2737 elf_elfsections (abfd) = i_shdrp; … … 1897 2741 { 1898 2742 i_shdrp[t->symtab_section] = &t->symtab_hdr; 2743 if (elf_numsections (abfd) > SHN_LORESERVE) 2744 { 2745 i_shdrp[t->symtab_shndx_section] = &t->symtab_shndx_hdr; 2746 t->symtab_shndx_hdr.sh_link = t->symtab_section; 2747 } 1899 2748 i_shdrp[t->strtab_section] = &t->strtab_hdr; 1900 2749 t->symtab_hdr.sh_link = t->strtab_section; … … 1965 2814 1966 2815 len = strlen (sec->name); 1967 alc = (char *) bfd_malloc ( len - 2);2816 alc = (char *) bfd_malloc ((bfd_size_type) (len - 2)); 1968 2817 if (alc == NULL) 1969 return false;1970 strncpy (alc, sec->name, len - 3);2818 return FALSE; 2819 memcpy (alc, sec->name, len - 3); 1971 2820 alc[len - 3] = '\0'; 1972 2821 s = bfd_get_section_by_name (abfd, alc); … … 1977 2826 1978 2827 /* This is a .stab section. */ 1979 elf_section_data (s)->this_hdr.sh_entsize = 1980 4 + 2 * bfd_get_arch_size (abfd) / 8; 2828 if (elf_section_data (s)->this_hdr.sh_entsize == 0) 2829 elf_section_data (s)->this_hdr.sh_entsize 2830 = 4 + 2 * bfd_get_arch_size (abfd) / 8; 1981 2831 } 1982 2832 } … … 2003 2853 d->this_hdr.sh_link = elf_section_data (s)->this_idx; 2004 2854 break; 2005 } 2006 } 2007 2008 return true; 2855 2856 case SHT_GROUP: 2857 d->this_hdr.sh_link = t->symtab_section; 2858 } 2859 } 2860 2861 for (secn = 1; secn < section_number; ++secn) 2862 if (i_shdrp[secn] == NULL) 2863 i_shdrp[secn] = i_shdrp[0]; 2864 else 2865 i_shdrp[secn]->sh_name = _bfd_elf_strtab_offset (elf_shstrtab (abfd), 2866 i_shdrp[secn]->sh_name); 2867 return TRUE; 2009 2868 } 2010 2869 … … 2027 2886 } 2028 2887 2029 static b oolean2888 static bfd_boolean 2030 2889 elf_map_symbols (abfd) 2031 2890 bfd *abfd; 2032 2891 { 2033 int symcount = bfd_get_symcount (abfd);2892 unsigned int symcount = bfd_get_symcount (abfd); 2034 2893 asymbol **syms = bfd_get_outsymbols (abfd); 2035 2894 asymbol **sect_syms; 2036 int num_locals = 0;2037 int num_globals = 0;2038 int num_locals2 = 0;2039 int num_globals2 = 0;2895 unsigned int num_locals = 0; 2896 unsigned int num_globals = 0; 2897 unsigned int num_locals2 = 0; 2898 unsigned int num_globals2 = 0; 2040 2899 int max_index = 0; 2041 int num_sections = 0; 2042 int idx; 2900 unsigned int idx; 2043 2901 asection *asect; 2044 2902 asymbol **new_syms; 2045 asymbol *sym;2903 bfd_size_type amt; 2046 2904 2047 2905 #ifdef DEBUG … … 2050 2908 #endif 2051 2909 2052 /* Add a section symbol for each BFD section. FIXME: Is this really2053 necessary? */2054 2910 for (asect = abfd->sections; asect; asect = asect->next) 2055 2911 { … … 2059 2915 2060 2916 max_index++; 2061 sect_syms = (asymbol **) bfd_zalloc (abfd, max_index * sizeof (asymbol *)); 2917 amt = max_index * sizeof (asymbol *); 2918 sect_syms = (asymbol **) bfd_zalloc (abfd, amt); 2062 2919 if (sect_syms == NULL) 2063 return false;2920 return FALSE; 2064 2921 elf_section_syms (abfd) = sect_syms; 2065 2922 elf_num_section_syms (abfd) = max_index; 2923 2924 /* Init sect_syms entries for any section symbols we have already 2925 decided to output. */ 2066 2926 for (idx = 0; idx < symcount; idx++) 2067 2927 { 2068 sym = syms[idx];2928 asymbol *sym = syms[idx]; 2069 2929 2070 2930 if ((sym->flags & BSF_SECTION_SYM) != 0 … … 2084 2944 sec = sec->output_section; 2085 2945 2086 /* Empty sections in the input files may have had a section 2087 symbol created for them. (See the comment near the end of 2088 _bfd_generic_link_output_symbols in linker.c). If the linker 2089 script discards such sections then we will reach this point. 2090 Since we know that we cannot avoid this case, we detect it 2091 and skip the abort and the assignment to the sect_syms array. 2092 To reproduce this particular case try running the linker 2093 testsuite test ld-scripts/weak.exp for an ELF port that uses 2094 the generic linker. */ 2946 /* Empty sections in the input files may have had a 2947 section symbol created for them. (See the comment 2948 near the end of _bfd_generic_link_output_symbols in 2949 linker.c). If the linker script discards such 2950 sections then we will reach this point. Since we know 2951 that we cannot avoid this case, we detect it and skip 2952 the abort and the assignment to the sect_syms array. 2953 To reproduce this particular case try running the 2954 linker testsuite test ld-scripts/weak.exp for an ELF 2955 port that uses the generic linker. */ 2095 2956 if (sec->owner == NULL) 2096 2957 continue; … … 2103 2964 } 2104 2965 2105 for (asect = abfd->sections; asect; asect = asect->next)2106 {2107 if (sect_syms[asect->index] != NULL)2108 continue;2109 2110 sym = bfd_make_empty_symbol (abfd);2111 if (sym == NULL)2112 return false;2113 sym->the_bfd = abfd;2114 sym->name = asect->name;2115 sym->value = 0;2116 /* Set the flags to 0 to indicate that this one was newly added. */2117 sym->flags = 0;2118 sym->section = asect;2119 sect_syms[asect->index] = sym;2120 num_sections++;2121 #ifdef DEBUG2122 fprintf (stderr,2123 _("creating section symbol, name = %s, value = 0x%.8lx, index = %d, section = 0x%.8lx\n"),2124 asect->name, (long) asect->vma, asect->index, (long) asect);2125 #endif2126 }2127 2128 2966 /* Classify all of the symbols. */ 2129 2967 for (idx = 0; idx < symcount; idx++) … … 2134 2972 num_globals++; 2135 2973 } 2974 2975 /* We will be adding a section symbol for each BFD section. Most normal 2976 sections will already have a section symbol in outsymbols, but 2977 eg. SHT_GROUP sections will not, and we need the section symbol mapped 2978 at least in that case. */ 2136 2979 for (asect = abfd->sections; asect; asect = asect->next) 2137 2980 { 2138 if (sect_syms[asect->index] != NULL 2139 && sect_syms[asect->index]->flags == 0) 2140 { 2141 sect_syms[asect->index]->flags = BSF_SECTION_SYM; 2142 if (!sym_is_global (abfd, sect_syms[asect->index])) 2981 if (sect_syms[asect->index] == NULL) 2982 { 2983 if (!sym_is_global (abfd, asect->symbol)) 2143 2984 num_locals++; 2144 2985 else 2145 2986 num_globals++; 2146 sect_syms[asect->index]->flags = 0;2147 2987 } 2148 2988 } 2149 2989 2150 2990 /* Now sort the symbols so the local symbols are first. */ 2151 new_syms = ((asymbol **)2152 bfd_alloc (abfd, 2153 (num_locals + num_globals) * sizeof (asymbol *))); 2991 amt = (num_locals + num_globals) * sizeof (asymbol *); 2992 new_syms = (asymbol **) bfd_alloc (abfd, amt); 2993 2154 2994 if (new_syms == NULL) 2155 return false;2995 return FALSE; 2156 2996 2157 2997 for (idx = 0; idx < symcount; idx++) 2158 2998 { 2159 2999 asymbol *sym = syms[idx]; 2160 int i;3000 unsigned int i; 2161 3001 2162 3002 if (!sym_is_global (abfd, sym)) … … 2169 3009 for (asect = abfd->sections; asect; asect = asect->next) 2170 3010 { 2171 if (sect_syms[asect->index] != NULL 2172 && sect_syms[asect->index]->flags == 0) 2173 { 2174 asymbol *sym = sect_syms[asect->index]; 2175 int i; 2176 2177 sym->flags = BSF_SECTION_SYM; 3011 if (sect_syms[asect->index] == NULL) 3012 { 3013 asymbol *sym = asect->symbol; 3014 unsigned int i; 3015 3016 sect_syms[asect->index] = sym; 2178 3017 if (!sym_is_global (abfd, sym)) 2179 3018 i = num_locals2++; … … 2189 3028 elf_num_locals (abfd) = num_locals; 2190 3029 elf_num_globals (abfd) = num_globals; 2191 return true;3030 return TRUE; 2192 3031 } 2193 3032 … … 2195 3034 ELF data structure. */ 2196 3035 2197 static INLINE file_ptr align_file_position PARAMS ((file_ptr, int)); 3036 static INLINE file_ptr align_file_position 3037 PARAMS ((file_ptr, int)); 2198 3038 static INLINE file_ptr 2199 3039 align_file_position (off, align) … … 2211 3051 Elf_Internal_Shdr *i_shdrp; 2212 3052 file_ptr offset; 2213 b oolean align;3053 bfd_boolean align; 2214 3054 { 2215 3055 if (align) … … 2233 3073 is not NULL, this is being called by the ELF backend linker. */ 2234 3074 2235 b oolean3075 bfd_boolean 2236 3076 _bfd_elf_compute_section_file_positions (abfd, link_info) 2237 3077 bfd *abfd; … … 2239 3079 { 2240 3080 struct elf_backend_data *bed = get_elf_backend_data (abfd); 2241 b oolean failed;3081 bfd_boolean failed; 2242 3082 struct bfd_strtab_hash *strtab; 2243 3083 Elf_Internal_Shdr *shstrtab_hdr; 2244 3084 2245 3085 if (abfd->output_has_begun) 2246 return true;3086 return TRUE; 2247 3087 2248 3088 /* Do any elf backend specific processing first. */ … … 2251 3091 2252 3092 if (! prep_headers (abfd)) 2253 return false;3093 return FALSE; 2254 3094 2255 3095 /* Post process the headers if necessary. */ … … 2257 3097 (*bed->elf_backend_post_process_headers) (abfd, link_info); 2258 3098 2259 failed = false;3099 failed = FALSE; 2260 3100 bfd_map_over_sections (abfd, elf_fake_sections, &failed); 2261 3101 if (failed) 2262 return false;3102 return FALSE; 2263 3103 2264 3104 if (!assign_section_numbers (abfd)) 2265 return false;3105 return FALSE; 2266 3106 2267 3107 /* The backend linker builds symbol table information itself. */ … … 2272 3112 2273 3113 if (! swap_out_syms (abfd, &strtab, relocatable_p)) 2274 return false; 3114 return FALSE; 3115 } 3116 3117 if (link_info == NULL) 3118 { 3119 bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed); 3120 if (failed) 3121 return FALSE; 2275 3122 } 2276 3123 … … 2280 3127 shstrtab_hdr->sh_flags = 0; 2281 3128 shstrtab_hdr->sh_addr = 0; 2282 shstrtab_hdr->sh_size = _bfd_ stringtab_size (elf_shstrtab (abfd));3129 shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd)); 2283 3130 shstrtab_hdr->sh_entsize = 0; 2284 3131 shstrtab_hdr->sh_link = 0; … … 2288 3135 2289 3136 if (!assign_file_positions_except_relocs (abfd)) 2290 return false;3137 return FALSE; 2291 3138 2292 3139 if (link_info == NULL && bfd_get_symcount (abfd) > 0) … … 2298 3145 2299 3146 hdr = &elf_tdata (abfd)->symtab_hdr; 2300 off = _bfd_elf_assign_file_position_for_section (hdr, off, true); 3147 off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); 3148 3149 hdr = &elf_tdata (abfd)->symtab_shndx_hdr; 3150 if (hdr->sh_size != 0) 3151 off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); 2301 3152 2302 3153 hdr = &elf_tdata (abfd)->strtab_hdr; 2303 off = _bfd_elf_assign_file_position_for_section (hdr, off, true);3154 off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); 2304 3155 2305 3156 elf_tdata (abfd)->next_file_pos = off; … … 2309 3160 if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0 2310 3161 || ! _bfd_stringtab_emit (abfd, strtab)) 2311 return false;3162 return FALSE; 2312 3163 _bfd_stringtab_free (strtab); 2313 3164 } 2314 3165 2315 abfd->output_has_begun = true;2316 2317 return true;3166 abfd->output_has_begun = TRUE; 3167 3168 return TRUE; 2318 3169 } 2319 3170 … … 2326 3177 unsigned int from; 2327 3178 unsigned int to; 2328 b oolean phdr;3179 bfd_boolean phdr; 2329 3180 { 2330 3181 struct elf_segment_map *m; 2331 3182 unsigned int i; 2332 3183 asection **hdrpp; 2333 2334 m = ((struct elf_segment_map *) 2335 bfd_zalloc (abfd,2336 (sizeof (struct elf_segment_map) 2337 + (to - from - 1) * sizeof (asection *))));3184 bfd_size_type amt; 3185 3186 amt = sizeof (struct elf_segment_map); 3187 amt += (to - from - 1) * sizeof (asection *); 3188 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 2338 3189 if (m == NULL) 2339 3190 return NULL; … … 2356 3207 /* Set up a mapping from BFD sections to program segments. */ 2357 3208 2358 static b oolean3209 static bfd_boolean 2359 3210 map_sections_to_segments (abfd) 2360 3211 bfd *abfd; … … 2371 3222 bfd_vma maxpagesize; 2372 3223 asection **hdrpp; 2373 boolean phdr_in_segment = true; 2374 boolean writable; 2375 asection *dynsec; 3224 bfd_boolean phdr_in_segment = TRUE; 3225 bfd_boolean writable; 3226 int tls_count = 0; 3227 asection *first_tls = NULL; 3228 asection *dynsec, *eh_frame_hdr; 3229 bfd_size_type amt; 2376 3230 2377 3231 if (elf_tdata (abfd)->segment_map != NULL) 2378 return true;3232 return TRUE; 2379 3233 2380 3234 if (bfd_count_sections (abfd) == 0) 2381 return true;3235 return TRUE; 2382 3236 2383 3237 /* Select the allocated sections, and sort them. */ 2384 3238 2385 sections = (asection **) bfd_malloc (bfd_count_sections (abfd)2386 * sizeof (asection *));3239 amt = bfd_count_sections (abfd) * sizeof (asection *); 3240 sections = (asection **) bfd_malloc (amt); 2387 3241 if (sections == NULL) 2388 3242 goto error_return; … … 2413 3267 if (s != NULL && (s->flags & SEC_LOAD) != 0) 2414 3268 { 2415 m = ((struct elf_segment_map *)2416 bfd_zalloc (abfd, sizeof (struct elf_segment_map)));3269 amt = sizeof (struct elf_segment_map); 3270 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 2417 3271 if (m == NULL) 2418 3272 goto error_return; … … 2427 3281 pm = &m->next; 2428 3282 2429 m = ((struct elf_segment_map *)2430 bfd_zalloc (abfd, sizeof (struct elf_segment_map)));3283 amt = sizeof (struct elf_segment_map); 3284 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 2431 3285 if (m == NULL) 2432 3286 goto error_return; … … 2446 3300 phdr_index = 0; 2447 3301 maxpagesize = get_elf_backend_data (abfd)->maxpagesize; 2448 writable = false;3302 writable = FALSE; 2449 3303 dynsec = bfd_get_section_by_name (abfd, ".dynamic"); 2450 3304 if (dynsec != NULL … … 2466 3320 || sections[0]->lma < phdr_size 2467 3321 || sections[0]->lma % maxpagesize < phdr_size % maxpagesize) 2468 phdr_in_segment = false;3322 phdr_in_segment = FALSE; 2469 3323 } 2470 3324 … … 2472 3326 { 2473 3327 asection *hdr; 2474 b oolean new_segment;3328 bfd_boolean new_segment; 2475 3329 2476 3330 hdr = *hdrpp; … … 2483 3337 /* If we don't have a segment yet, then we don't need a new 2484 3338 one (we build the last one after this loop). */ 2485 new_segment = false;3339 new_segment = FALSE; 2486 3340 } 2487 3341 else if (last_hdr->lma - last_hdr->vma != hdr->lma - hdr->vma) … … 2490 3344 virtual address and the load address, then we need a new 2491 3345 segment. */ 2492 new_segment = true;3346 new_segment = TRUE; 2493 3347 } 2494 3348 else if (BFD_ALIGN (last_hdr->lma + last_hdr->_raw_size, maxpagesize) … … 2497 3351 /* If putting this section in this segment would force us to 2498 3352 skip a page in the segment, then we need a new segment. */ 2499 new_segment = true;3353 new_segment = TRUE; 2500 3354 } 2501 3355 else if ((last_hdr->flags & SEC_LOAD) == 0 … … 2504 3358 /* We don't want to put a loadable section after a 2505 3359 nonloadable section in the same segment. */ 2506 new_segment = true;3360 new_segment = TRUE; 2507 3361 } 2508 3362 else if ((abfd->flags & D_PAGED) == 0) … … 2511 3365 don't require the sections to be correctly aligned in the 2512 3366 file, then there is no other reason for a new segment. */ 2513 new_segment = false;3367 new_segment = FALSE; 2514 3368 } 2515 3369 else if (! writable 2516 3370 && (hdr->flags & SEC_READONLY) == 0 2517 && (BFD_ALIGN (last_hdr->lma + last_hdr->_raw_size, maxpagesize) 2518 == hdr->lma)) 3371 && (((last_hdr->lma + last_hdr->_raw_size - 1) 3372 & ~(maxpagesize - 1)) 3373 != (hdr->lma & ~(maxpagesize - 1)))) 2519 3374 { 2520 3375 /* We don't want to put a writable section in a read only … … 2525 3380 page as the previous section is when the previous section 2526 3381 ends precisely on a page boundary. */ 2527 new_segment = true;3382 new_segment = TRUE; 2528 3383 } 2529 3384 else 2530 3385 { 2531 3386 /* Otherwise, we can use the same segment. */ 2532 new_segment = false;3387 new_segment = FALSE; 2533 3388 } 2534 3389 … … 2536 3391 { 2537 3392 if ((hdr->flags & SEC_READONLY) == 0) 2538 writable = true;3393 writable = TRUE; 2539 3394 last_hdr = hdr; 2540 3395 continue; … … 2552 3407 2553 3408 if ((hdr->flags & SEC_READONLY) == 0) 2554 writable = true;3409 writable = TRUE; 2555 3410 else 2556 writable = false;3411 writable = FALSE; 2557 3412 2558 3413 last_hdr = hdr; 2559 3414 phdr_index = i; 2560 phdr_in_segment = false;3415 phdr_in_segment = FALSE; 2561 3416 } 2562 3417 … … 2575 3430 if (dynsec != NULL) 2576 3431 { 2577 m = ((struct elf_segment_map *)2578 bfd_zalloc (abfd, sizeof (struct elf_segment_map)));3432 amt = sizeof (struct elf_segment_map); 3433 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 2579 3434 if (m == NULL) 2580 3435 goto error_return; … … 2598 3453 && strncmp (s->name, ".note", 5) == 0) 2599 3454 { 2600 m = ((struct elf_segment_map *)2601 bfd_zalloc (abfd, sizeof (struct elf_segment_map)));3455 amt = sizeof (struct elf_segment_map); 3456 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 2602 3457 if (m == NULL) 2603 3458 goto error_return; … … 2610 3465 pm = &m->next; 2611 3466 } 3467 if (s->flags & SEC_THREAD_LOCAL) 3468 { 3469 if (! tls_count) 3470 first_tls = s; 3471 tls_count++; 3472 } 3473 } 3474 3475 /* If there are any SHF_TLS output sections, add PT_TLS segment. */ 3476 if (tls_count > 0) 3477 { 3478 int i; 3479 3480 amt = sizeof (struct elf_segment_map); 3481 amt += (tls_count - 1) * sizeof (asection *); 3482 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 3483 if (m == NULL) 3484 goto error_return; 3485 m->next = NULL; 3486 m->p_type = PT_TLS; 3487 m->count = tls_count; 3488 /* Mandated PF_R. */ 3489 m->p_flags = PF_R; 3490 m->p_flags_valid = 1; 3491 for (i = 0; i < tls_count; ++i) 3492 { 3493 BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL); 3494 m->sections[i] = first_tls; 3495 first_tls = first_tls->next; 3496 } 3497 3498 *pm = m; 3499 pm = &m->next; 3500 } 3501 3502 /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME 3503 segment. */ 3504 eh_frame_hdr = elf_tdata (abfd)->eh_frame_hdr; 3505 if (eh_frame_hdr != NULL 3506 && (eh_frame_hdr->output_section->flags & SEC_LOAD) != 0) 3507 { 3508 amt = sizeof (struct elf_segment_map); 3509 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt); 3510 if (m == NULL) 3511 goto error_return; 3512 m->next = NULL; 3513 m->p_type = PT_GNU_EH_FRAME; 3514 m->count = 1; 3515 m->sections[0] = eh_frame_hdr->output_section; 3516 3517 *pm = m; 3518 pm = &m->next; 2612 3519 } 2613 3520 … … 2616 3523 2617 3524 elf_tdata (abfd)->segment_map = mfirst; 2618 return true;3525 return TRUE; 2619 3526 2620 3527 error_return: 2621 3528 if (sections != NULL) 2622 3529 free (sections); 2623 return false;3530 return FALSE; 2624 3531 } 2625 3532 … … 2633 3540 const asection *sec1 = *(const asection **) arg1; 2634 3541 const asection *sec2 = *(const asection **) arg2; 3542 bfd_size_type size1, size2; 2635 3543 2636 3544 /* Sort by LMA first, since this is the address used to … … 2650 3558 /* Put !SEC_LOAD sections after SEC_LOAD ones. */ 2651 3559 2652 #define TOEND(x) (((x)->flags & SEC_LOAD) == 0)3560 #define TOEND(x) (((x)->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0) 2653 3561 2654 3562 if (TOEND (sec1)) 2655 3563 { 2656 3564 if (TOEND (sec2)) 2657 return sec1->target_index - sec2->target_index; 3565 { 3566 /* If the indicies are the same, do not return 0 3567 here, but continue to try the next comparison. */ 3568 if (sec1->target_index - sec2->target_index != 0) 3569 return sec1->target_index - sec2->target_index; 3570 } 2658 3571 else 2659 3572 return 1; 2660 3573 } 2661 2662 if (TOEND (sec2)) 3574 else if (TOEND (sec2)) 2663 3575 return -1; 2664 3576 2665 3577 #undef TOEND 2666 3578 2667 /* Sort by size, to put zero sized sections before others at the 2668 same address. */ 2669 2670 if (sec1->_raw_size < sec2->_raw_size) 3579 /* Sort by size, to put zero sized sections 3580 before others at the same address. */ 3581 3582 size1 = (sec1->flags & SEC_LOAD) ? sec1->_raw_size : 0; 3583 size2 = (sec2->flags & SEC_LOAD) ? sec2->_raw_size : 0; 3584 3585 if (size1 < size2) 2671 3586 return -1; 2672 if (s ec1->_raw_size > sec2->_raw_size)3587 if (size1 > size2) 2673 3588 return 1; 2674 3589 … … 2680 3595 the file header, and writes out the program headers. */ 2681 3596 2682 static b oolean3597 static bfd_boolean 2683 3598 assign_file_positions_for_segments (abfd) 2684 3599 bfd *abfd; … … 2693 3608 bfd_vma phdrs_vaddr, phdrs_paddr; 2694 3609 Elf_Internal_Phdr *p; 3610 bfd_size_type amt; 2695 3611 2696 3612 if (elf_tdata (abfd)->segment_map == NULL) 2697 3613 { 2698 3614 if (! map_sections_to_segments (abfd)) 2699 return false; 3615 return FALSE; 3616 } 3617 else 3618 { 3619 /* The placement algorithm assumes that non allocated sections are 3620 not in PT_LOAD segments. We ensure this here by removing such 3621 sections from the segment map. */ 3622 for (m = elf_tdata (abfd)->segment_map; 3623 m != NULL; 3624 m = m->next) 3625 { 3626 unsigned int new_count; 3627 unsigned int i; 3628 3629 if (m->p_type != PT_LOAD) 3630 continue; 3631 3632 new_count = 0; 3633 for (i = 0; i < m->count; i ++) 3634 { 3635 if ((m->sections[i]->flags & SEC_ALLOC) != 0) 3636 { 3637 if (i != new_count) 3638 m->sections[new_count] = m->sections[i]; 3639 3640 new_count ++; 3641 } 3642 } 3643 3644 if (new_count != m->count) 3645 m->count = new_count; 3646 } 2700 3647 } 2701 3648 … … 2703 3650 { 2704 3651 if (! (*bed->elf_backend_modify_segment_map) (abfd)) 2705 return false;3652 return FALSE; 2706 3653 } 2707 3654 … … 2715 3662 2716 3663 if (count == 0) 2717 return true;3664 return TRUE; 2718 3665 2719 3666 /* If we already counted the number of program segments, make sure … … 2727 3674 bfd_get_filename (abfd), alloc, count)); 2728 3675 bfd_set_error (bfd_error_bad_value); 2729 return false;3676 return FALSE; 2730 3677 } 2731 3678 … … 2733 3680 alloc = count; 2734 3681 2735 phdrs = ((Elf_Internal_Phdr *)2736 bfd_alloc (abfd, alloc * sizeof (Elf_Internal_Phdr)));3682 amt = alloc * sizeof (Elf_Internal_Phdr); 3683 phdrs = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt); 2737 3684 if (phdrs == NULL) 2738 return false;3685 return FALSE; 2739 3686 2740 3687 off = bed->s->sizeof_ehdr; … … 2754 3701 2755 3702 /* If elf_segment_map is not from map_sections_to_segments, the 2756 sections may not be correctly ordered. */ 2757 if (m->count > 0) 3703 sections may not be correctly ordered. NOTE: sorting should 3704 not be done to the PT_NOTE section of a corefile, which may 3705 contain several pseudo-sections artificially created by bfd. 3706 Sorting these pseudo-sections breaks things badly. */ 3707 if (m->count > 1 3708 && !(elf_elfheader (abfd)->e_type == ET_CORE 3709 && m->p_type == PT_NOTE)) 2758 3710 qsort (m->sections, (size_t) m->count, sizeof (asection *), 2759 3711 elf_sort_sections); … … 2823 3775 if (p->p_vaddr < (bfd_vma) off) 2824 3776 { 2825 _bfd_error_handler (_("%s: Not enough room for program headers, try linking with -N"), 2826 bfd_get_filename (abfd)); 3777 (*_bfd_error_handler) 3778 (_("%s: Not enough room for program headers, try linking with -N"), 3779 bfd_get_filename (abfd)); 2827 3780 bfd_set_error (bfd_error_bad_value); 2828 return false;3781 return FALSE; 2829 3782 } 2830 3783 … … 2907 3860 /* The section may have artificial alignment forced by a 2908 3861 link script. Notice this case by the gap between the 2909 cumulative phdr vma and the section's vma. */2910 if (p->p_ vaddr + p->p_memsz < sec->vma)3862 cumulative phdr lma and the section's lma. */ 3863 if (p->p_paddr + p->p_memsz < sec->lma) 2911 3864 { 2912 bfd_vma adjust = sec-> vma - (p->p_vaddr + p->p_memsz);3865 bfd_vma adjust = sec->lma - (p->p_paddr + p->p_memsz); 2913 3866 2914 3867 p->p_memsz += adjust; 2915 off += adjust; 2916 voff += adjust; 2917 if ((flags & SEC_LOAD) != 0) 3868 if (p->p_type == PT_LOAD 3869 || (p->p_type == PT_NOTE 3870 && bfd_get_format (abfd) == bfd_core)) 3871 { 3872 off += adjust; 3873 voff += adjust; 3874 } 3875 if ((flags & SEC_LOAD) != 0 3876 || (flags & SEC_THREAD_LOCAL) != 0) 2918 3877 p->p_filesz += adjust; 2919 3878 } … … 2948 3907 if (i == 0) 2949 3908 { 2950 (* _bfd_error_handler) 2951 (_("Error: First section in segment (%s) starts at 0x%x"), 2952 bfd_section_name (abfd, sec), sec->lma); 2953 (* _bfd_error_handler) 2954 (_(" whereas segment starts at 0x%x"), 2955 p->p_paddr); 2956 2957 return false; 3909 (* _bfd_error_handler) (_("\ 3910 Error: First section in segment (%s) starts at 0x%x whereas the segment starts at 0x%x"), 3911 bfd_section_name (abfd, sec), 3912 sec->lma, 3913 p->p_paddr); 3914 return FALSE; 2958 3915 } 2959 3916 p->p_memsz += adjust; … … 2974 3931 off += sec->_raw_size; 2975 3932 2976 if ((flags & SEC_ALLOC) != 0) 3933 if ((flags & SEC_ALLOC) != 0 3934 && ((flags & SEC_LOAD) != 0 3935 || (flags & SEC_THREAD_LOCAL) == 0)) 2977 3936 voff += sec->_raw_size; 2978 3937 } … … 3001 3960 else 3002 3961 { 3962 if ((sec->flags & SEC_LOAD) != 0 3963 || (sec->flags & SEC_THREAD_LOCAL) == 0 3964 || p->p_type == PT_TLS) 3003 3965 p->p_memsz += sec->_raw_size; 3004 3966 3005 3967 if ((flags & SEC_LOAD) != 0) 3006 3968 p->p_filesz += sec->_raw_size; 3969 3970 if (p->p_type == PT_TLS 3971 && sec->_raw_size == 0 3972 && (sec->flags & SEC_HAS_CONTENTS) == 0) 3973 { 3974 struct bfd_link_order *o; 3975 bfd_vma tbss_size = 0; 3976 3977 for (o = sec->link_order_head; o != NULL; o = o->next) 3978 if (tbss_size < o->offset + o->size) 3979 tbss_size = o->offset + o->size; 3980 3981 p->p_memsz += tbss_size; 3982 } 3007 3983 3008 3984 if (align > p->p_align … … 3062 4038 3063 4039 /* Write out the program headers. */ 3064 if (bfd_seek (abfd, bed->s->sizeof_ehdr, SEEK_SET) != 04040 if (bfd_seek (abfd, (bfd_signed_vma) bed->s->sizeof_ehdr, SEEK_SET) != 0 3065 4041 || bed->s->write_out_phdrs (abfd, phdrs, alloc) != 0) 3066 return false;3067 3068 return true;4042 return FALSE; 4043 4044 return TRUE; 3069 4045 } 3070 4046 … … 3123 4099 } 3124 4100 4101 if (elf_tdata (abfd)->eh_frame_hdr) 4102 { 4103 /* We need a PT_GNU_EH_FRAME segment. */ 4104 ++segs; 4105 } 4106 3125 4107 for (s = abfd->sections; s != NULL; s = s->next) 3126 4108 { … … 3130 4112 /* We need a PT_NOTE segment. */ 3131 4113 ++segs; 4114 } 4115 } 4116 4117 for (s = abfd->sections; s != NULL; s = s->next) 4118 { 4119 if (s->flags & SEC_THREAD_LOCAL) 4120 { 4121 /* We need a PT_TLS segment. */ 4122 ++segs; 4123 break; 3132 4124 } 3133 4125 } … … 3159 4151 We also don't set the positions of the .symtab and .strtab here. */ 3160 4152 3161 static b oolean4153 static bfd_boolean 3162 4154 assign_file_positions_except_relocs (abfd) 3163 4155 bfd *abfd; … … 3166 4158 Elf_Internal_Ehdr * const i_ehdrp = elf_elfheader (abfd); 3167 4159 Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd); 4160 unsigned int num_sec = elf_numsections (abfd); 3168 4161 file_ptr off; 3169 4162 struct elf_backend_data *bed = get_elf_backend_data (abfd); … … 3181 4174 not creating a program header, and that the actual order of 3182 4175 the sections in the file is unimportant. */ 3183 for (i = 1, hdrpp = i_shdrpp + 1; i < i_ehdrp->e_shnum; i++, hdrpp++)4176 for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++) 3184 4177 { 3185 4178 Elf_Internal_Shdr *hdr; 3186 4179 3187 4180 hdr = *hdrpp; 3188 if (hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA) 3189 { 3190 hdr->sh_offset = -1; 3191 continue; 3192 } 3193 if (i == tdata->symtab_section 4181 if (hdr->sh_type == SHT_REL 4182 || hdr->sh_type == SHT_RELA 4183 || i == tdata->symtab_section 4184 || i == tdata->symtab_shndx_section 3194 4185 || i == tdata->strtab_section) 3195 4186 { 3196 4187 hdr->sh_offset = -1; 3197 continue;3198 4188 } 3199 3200 off = _bfd_elf_assign_file_position_for_section (hdr, off, true); 4189 else 4190 off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); 4191 4192 if (i == SHN_LORESERVE - 1) 4193 { 4194 i += SHN_HIRESERVE + 1 - SHN_LORESERVE; 4195 hdrpp += SHN_HIRESERVE + 1 - SHN_LORESERVE; 4196 } 3201 4197 } 3202 4198 } … … 3209 4205 assignment of sections to segments. */ 3210 4206 if (! assign_file_positions_for_segments (abfd)) 3211 return false;4207 return FALSE; 3212 4208 3213 4209 /* Assign file positions for the other sections. */ 3214 4210 3215 4211 off = elf_tdata (abfd)->next_file_pos; 3216 for (i = 1, hdrpp = i_shdrpp + 1; i < i_ehdrp->e_shnum; i++, hdrpp++)4212 for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++) 3217 4213 { 3218 4214 Elf_Internal_Shdr *hdr; … … 3235 4231 off += (hdr->sh_addr - off) % hdr->sh_addralign; 3236 4232 off = _bfd_elf_assign_file_position_for_section (hdr, off, 3237 false);4233 FALSE); 3238 4234 } 3239 4235 else if (hdr->sh_type == SHT_REL 3240 4236 || hdr->sh_type == SHT_RELA 3241 4237 || hdr == i_shdrpp[tdata->symtab_section] 4238 || hdr == i_shdrpp[tdata->symtab_shndx_section] 3242 4239 || hdr == i_shdrpp[tdata->strtab_section]) 3243 4240 hdr->sh_offset = -1; 3244 4241 else 3245 off = _bfd_elf_assign_file_position_for_section (hdr, off, true); 4242 off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); 4243 4244 if (i == SHN_LORESERVE - 1) 4245 { 4246 i += SHN_HIRESERVE + 1 - SHN_LORESERVE; 4247 hdrpp += SHN_HIRESERVE + 1 - SHN_LORESERVE; 4248 } 3246 4249 } 3247 4250 } … … 3254 4257 elf_tdata (abfd)->next_file_pos = off; 3255 4258 3256 return true;3257 } 3258 3259 static b oolean4259 return TRUE; 4260 } 4261 4262 static bfd_boolean 3260 4263 prep_headers (abfd) 3261 4264 bfd *abfd; … … 3264 4267 Elf_Internal_Phdr *i_phdrp = 0; /* Program header table, internal form */ 3265 4268 Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */ 3266 int count; 3267 struct bfd_strtab_hash *shstrtab; 4269 struct elf_strtab_hash *shstrtab; 3268 4270 struct elf_backend_data *bed = get_elf_backend_data (abfd); 3269 4271 … … 3271 4273 i_shdrp = elf_elfsections (abfd); 3272 4274 3273 shstrtab = _bfd_elf_str ingtab_init ();4275 shstrtab = _bfd_elf_strtab_init (); 3274 4276 if (shstrtab == NULL) 3275 return false;4277 return FALSE; 3276 4278 3277 4279 elf_shstrtab (abfd) = shstrtab; … … 3286 4288 bfd_big_endian (abfd) ? ELFDATA2MSB : ELFDATA2LSB; 3287 4289 i_ehdrp->e_ident[EI_VERSION] = bed->s->ev_current; 3288 3289 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_NONE;3290 i_ehdrp->e_ident[EI_ABIVERSION] = 0;3291 3292 for (count = EI_PAD; count < EI_NIDENT; count++)3293 i_ehdrp->e_ident[count] = 0;3294 4290 3295 4291 if ((abfd->flags & DYNAMIC) != 0) … … 3307 4303 i_ehdrp->e_machine = EM_NONE; 3308 4304 break; 3309 case bfd_arch_sparc: 3310 if (bfd_get_arch_size (abfd) == 64) 3311 i_ehdrp->e_machine = EM_SPARCV9; 4305 4306 /* There used to be a long list of cases here, each one setting 4307 e_machine to the same EM_* macro #defined as ELF_MACHINE_CODE 4308 in the corresponding bfd definition. To avoid duplication, 4309 the switch was removed. Machines that need special handling 4310 can generally do it in elf_backend_final_write_processing(), 4311 unless they need the information earlier than the final write. 4312 Such need can generally be supplied by replacing the tests for 4313 e_machine with the conditions used to determine it. */ 4314 default: 4315 if (get_elf_backend_data (abfd) != NULL) 4316 i_ehdrp->e_machine = get_elf_backend_data (abfd)->elf_machine_code; 3312 4317 else 3313 i_ehdrp->e_machine = EM_SPARC; 3314 break; 3315 case bfd_arch_i370: 3316 i_ehdrp->e_machine = EM_S370; 3317 break; 3318 case bfd_arch_i386: 3319 if (bfd_get_arch_size (abfd) == 64) 3320 i_ehdrp->e_machine = EM_X86_64; 3321 else 3322 i_ehdrp->e_machine = EM_386; 3323 break; 3324 case bfd_arch_ia64: 3325 i_ehdrp->e_machine = EM_IA_64; 3326 break; 3327 case bfd_arch_m68hc11: 3328 i_ehdrp->e_machine = EM_68HC11; 3329 break; 3330 case bfd_arch_m68hc12: 3331 i_ehdrp->e_machine = EM_68HC12; 3332 break; 3333 case bfd_arch_m68k: 3334 i_ehdrp->e_machine = EM_68K; 3335 break; 3336 case bfd_arch_m88k: 3337 i_ehdrp->e_machine = EM_88K; 3338 break; 3339 case bfd_arch_i860: 3340 i_ehdrp->e_machine = EM_860; 3341 break; 3342 case bfd_arch_i960: 3343 i_ehdrp->e_machine = EM_960; 3344 break; 3345 case bfd_arch_mips: /* MIPS Rxxxx */ 3346 i_ehdrp->e_machine = EM_MIPS; /* only MIPS R3000 */ 3347 break; 3348 case bfd_arch_hppa: 3349 i_ehdrp->e_machine = EM_PARISC; 3350 break; 3351 case bfd_arch_powerpc: 3352 i_ehdrp->e_machine = EM_PPC; 3353 break; 3354 case bfd_arch_alpha: 3355 i_ehdrp->e_machine = EM_ALPHA; 3356 break; 3357 case bfd_arch_sh: 3358 i_ehdrp->e_machine = EM_SH; 3359 break; 3360 case bfd_arch_d10v: 3361 i_ehdrp->e_machine = EM_CYGNUS_D10V; 3362 break; 3363 case bfd_arch_d30v: 3364 i_ehdrp->e_machine = EM_CYGNUS_D30V; 3365 break; 3366 case bfd_arch_fr30: 3367 i_ehdrp->e_machine = EM_CYGNUS_FR30; 3368 break; 3369 case bfd_arch_mcore: 3370 i_ehdrp->e_machine = EM_MCORE; 3371 break; 3372 case bfd_arch_avr: 3373 i_ehdrp->e_machine = EM_AVR; 3374 break; 3375 case bfd_arch_v850: 3376 switch (bfd_get_mach (abfd)) 3377 { 3378 default: 3379 case 0: i_ehdrp->e_machine = EM_CYGNUS_V850; break; 3380 } 3381 break; 3382 case bfd_arch_arc: 3383 i_ehdrp->e_machine = EM_CYGNUS_ARC; 3384 break; 3385 case bfd_arch_arm: 3386 i_ehdrp->e_machine = EM_ARM; 3387 break; 3388 case bfd_arch_m32r: 3389 i_ehdrp->e_machine = EM_CYGNUS_M32R; 3390 break; 3391 case bfd_arch_mn10200: 3392 i_ehdrp->e_machine = EM_CYGNUS_MN10200; 3393 break; 3394 case bfd_arch_mn10300: 3395 i_ehdrp->e_machine = EM_CYGNUS_MN10300; 3396 break; 3397 case bfd_arch_pj: 3398 i_ehdrp->e_machine = EM_PJ; 3399 break; 3400 case bfd_arch_cris: 3401 i_ehdrp->e_machine = EM_CRIS; 3402 break; 3403 /* Also note that EM_M32, AT&T WE32100 is unknown to bfd. */ 3404 default: 3405 i_ehdrp->e_machine = EM_NONE; 3406 } 4318 i_ehdrp->e_machine = EM_NONE; 4319 } 4320 3407 4321 i_ehdrp->e_version = bed->s->ev_current; 3408 4322 i_ehdrp->e_ehsize = bed->s->sizeof_ehdr; … … 3439 4353 3440 4354 elf_tdata (abfd)->symtab_hdr.sh_name = 3441 (unsigned int) _bfd_ stringtab_add (shstrtab, ".symtab", true, false);4355 (unsigned int) _bfd_elf_strtab_add (shstrtab, ".symtab", FALSE); 3442 4356 elf_tdata (abfd)->strtab_hdr.sh_name = 3443 (unsigned int) _bfd_ stringtab_add (shstrtab, ".strtab", true, false);4357 (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", FALSE); 3444 4358 elf_tdata (abfd)->shstrtab_hdr.sh_name = 3445 (unsigned int) _bfd_ stringtab_add (shstrtab, ".shstrtab", true, false);4359 (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", FALSE); 3446 4360 if (elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1 3447 4361 || elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1 3448 4362 || elf_tdata (abfd)->shstrtab_hdr.sh_name == (unsigned int) -1) 3449 return false;3450 3451 return true;4363 return FALSE; 4364 4365 return TRUE; 3452 4366 } 3453 4367 … … 3460 4374 { 3461 4375 file_ptr off; 3462 unsigned int i ;4376 unsigned int i, num_sec; 3463 4377 Elf_Internal_Shdr **shdrpp; 3464 4378 3465 4379 off = elf_tdata (abfd)->next_file_pos; 3466 4380 3467 for (i = 1, shdrpp = elf_elfsections (abfd) + 1; 3468 i < elf_elfheader (abfd)->e_shnum; 3469 i++, shdrpp++) 4381 num_sec = elf_numsections (abfd); 4382 for (i = 1, shdrpp = elf_elfsections (abfd) + 1; i < num_sec; i++, shdrpp++) 3470 4383 { 3471 4384 Elf_Internal_Shdr *shdrp; … … 3474 4387 if ((shdrp->sh_type == SHT_REL || shdrp->sh_type == SHT_RELA) 3475 4388 && shdrp->sh_offset == -1) 3476 off = _bfd_elf_assign_file_position_for_section (shdrp, off, true);4389 off = _bfd_elf_assign_file_position_for_section (shdrp, off, TRUE); 3477 4390 } 3478 4391 … … 3480 4393 } 3481 4394 3482 b oolean4395 bfd_boolean 3483 4396 _bfd_elf_write_object_contents (abfd) 3484 4397 bfd *abfd; … … 3487 4400 Elf_Internal_Ehdr *i_ehdrp; 3488 4401 Elf_Internal_Shdr **i_shdrp; 3489 b oolean failed;3490 unsigned int count ;4402 bfd_boolean failed; 4403 unsigned int count, num_sec; 3491 4404 3492 4405 if (! abfd->output_has_begun 3493 4406 && ! _bfd_elf_compute_section_file_positions 3494 4407 (abfd, (struct bfd_link_info *) NULL)) 3495 return false;4408 return FALSE; 3496 4409 3497 4410 i_shdrp = elf_elfsections (abfd); 3498 4411 i_ehdrp = elf_elfheader (abfd); 3499 4412 3500 failed = false;4413 failed = FALSE; 3501 4414 bfd_map_over_sections (abfd, bed->s->write_relocs, &failed); 3502 4415 if (failed) 3503 return false;4416 return FALSE; 3504 4417 3505 4418 _bfd_elf_assign_file_positions_for_relocs (abfd); 3506 4419 3507 4420 /* After writing the headers, we need to write the sections too... */ 3508 for (count = 1; count < i_ehdrp->e_shnum; count++) 4421 num_sec = elf_numsections (abfd); 4422 for (count = 1; count < num_sec; count++) 3509 4423 { 3510 4424 if (bed->elf_backend_section_processing) … … 3512 4426 if (i_shdrp[count]->contents) 3513 4427 { 4428 bfd_size_type amt = i_shdrp[count]->sh_size; 4429 3514 4430 if (bfd_seek (abfd, i_shdrp[count]->sh_offset, SEEK_SET) != 0 3515 || (bfd_write (i_shdrp[count]->contents, i_shdrp[count]->sh_size,3516 1, abfd)3517 != i_shdrp[count]->sh_size))3518 return false; 3519 }4431 || bfd_bwrite (i_shdrp[count]->contents, amt, abfd) != amt) 4432 return FALSE; 4433 } 4434 if (count == SHN_LORESERVE - 1) 4435 count += SHN_HIRESERVE + 1 - SHN_LORESERVE; 3520 4436 } 3521 4437 3522 4438 /* Write out the section header names. */ 3523 4439 if (bfd_seek (abfd, elf_tdata (abfd)->shstrtab_hdr.sh_offset, SEEK_SET) != 0 3524 || ! _bfd_ stringtab_emit (abfd, elf_shstrtab (abfd)))3525 return false;4440 || ! _bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd))) 4441 return FALSE; 3526 4442 3527 4443 if (bed->elf_backend_final_write_processing) … … 3532 4448 } 3533 4449 3534 b oolean4450 bfd_boolean 3535 4451 _bfd_elf_write_corefile_contents (abfd) 3536 4452 bfd *abfd; … … 3547 4463 struct sec *asect; 3548 4464 { 3549 struct elf_backend_data *bed = get_elf_backend_data (abfd); 3550 Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); 4465 struct elf_backend_data *bed; 3551 4466 int index; 3552 Elf_Internal_Shdr *hdr; 3553 int maxindex = elf_elfheader (abfd)->e_shnum; 3554 3555 for (index = 0; index < maxindex; index++) 3556 { 3557 hdr = i_shdrp[index]; 3558 if (hdr->bfd_section == asect) 3559 return index; 3560 } 3561 4467 4468 if (elf_section_data (asect) != NULL 4469 && elf_section_data (asect)->this_idx != 0) 4470 return elf_section_data (asect)->this_idx; 4471 4472 if (bfd_is_abs_section (asect)) 4473 index = SHN_ABS; 4474 else if (bfd_is_com_section (asect)) 4475 index = SHN_COMMON; 4476 else if (bfd_is_und_section (asect)) 4477 index = SHN_UNDEF; 4478 else 4479 { 4480 Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); 4481 int maxindex = elf_numsections (abfd); 4482 4483 for (index = 1; index < maxindex; index++) 4484 { 4485 Elf_Internal_Shdr *hdr = i_shdrp[index]; 4486 4487 if (hdr != NULL && hdr->bfd_section == asect) 4488 return index; 4489 } 4490 index = -1; 4491 } 4492 4493 bed = get_elf_backend_data (abfd); 3562 4494 if (bed->elf_backend_section_from_bfd_section) 3563 4495 { 3564 for (index = 0; index < maxindex; index++) 3565 { 3566 int retval; 3567 3568 hdr = i_shdrp[index]; 3569 retval = index; 3570 if ((*bed->elf_backend_section_from_bfd_section) 3571 (abfd, hdr, asect, &retval)) 3572 return retval; 3573 } 3574 } 3575 3576 if (bfd_is_abs_section (asect)) 3577 return SHN_ABS; 3578 if (bfd_is_com_section (asect)) 3579 return SHN_COMMON; 3580 if (bfd_is_und_section (asect)) 3581 return SHN_UNDEF; 3582 3583 bfd_set_error (bfd_error_nonrepresentable_section); 3584 3585 return -1; 4496 int retval = index; 4497 4498 if ((*bed->elf_backend_section_from_bfd_section) (abfd, asect, &retval)) 4499 return retval; 4500 } 4501 4502 if (index == -1) 4503 bfd_set_error (bfd_error_nonrepresentable_section); 4504 4505 return index; 3586 4506 } 3587 4507 … … 3613 4533 else 3614 4534 indx = asym_ptr->section->index; 3615 if (elf_section_syms (abfd)[indx]) 4535 if (indx < elf_num_section_syms (abfd) 4536 && elf_section_syms (abfd)[indx] != NULL) 3616 4537 asym_ptr->udata.i = elf_section_syms (abfd)[indx]->udata.i; 3617 4538 } … … 3625 4546 (*_bfd_error_handler) 3626 4547 (_("%s: symbol `%s' required but not present"), 3627 bfd_ get_filename (abfd), bfd_asymbol_name (asym_ptr));4548 bfd_archive_filename (abfd), bfd_asymbol_name (asym_ptr)); 3628 4549 bfd_set_error (bfd_error_no_symbols); 3629 4550 return -1; … … 3633 4554 { 3634 4555 fprintf (stderr, 3635 _("elf_symbol_from_bfd_symbol 0x%.8lx, name = %s, sym num = %d, flags = 0x%.8lx%s\n"),4556 "elf_symbol_from_bfd_symbol 0x%.8lx, name = %s, sym num = %d, flags = 0x%.8lx%s\n", 3636 4557 (long) asym_ptr, asym_ptr->name, idx, flags, 3637 4558 elf_symbol_flags (flags)); … … 3645 4566 /* Copy private BFD data. This copies any program header information. */ 3646 4567 3647 static b oolean4568 static bfd_boolean 3648 4569 copy_private_bfd_data (ibfd, obfd) 3649 4570 bfd *ibfd; 3650 4571 bfd *obfd; 3651 4572 { 3652 Elf_Internal_Ehdr * iehdr; 3653 struct elf_segment_map * map; 3654 struct elf_segment_map * map_first; 3655 struct elf_segment_map ** pointer_to_map; 3656 Elf_Internal_Phdr * segment; 3657 asection * section; 3658 unsigned int i; 3659 unsigned int num_segments; 3660 boolean phdr_included = false; 3661 bfd_vma maxpagesize; 3662 struct elf_segment_map * phdr_adjust_seg = NULL; 3663 unsigned int phdr_adjust_num = 0; 4573 Elf_Internal_Ehdr *iehdr; 4574 struct elf_segment_map *map; 4575 struct elf_segment_map *map_first; 4576 struct elf_segment_map **pointer_to_map; 4577 Elf_Internal_Phdr *segment; 4578 asection *section; 4579 unsigned int i; 4580 unsigned int num_segments; 4581 bfd_boolean phdr_included = FALSE; 4582 bfd_vma maxpagesize; 4583 struct elf_segment_map *phdr_adjust_seg = NULL; 4584 unsigned int phdr_adjust_num = 0; 4585 struct elf_backend_data *bed; 3664 4586 3665 4587 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 3666 4588 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 3667 return true;4589 return TRUE; 3668 4590 3669 4591 if (elf_tdata (ibfd)->phdr == NULL) 3670 return true; 3671 4592 return TRUE; 4593 4594 bed = get_elf_backend_data (ibfd); 3672 4595 iehdr = elf_elfheader (ibfd); 3673 4596 … … 3679 4602 3680 4603 /* Returns the end address of the segment + 1. */ 3681 #define SEGMENT_END(segment, start) \ 3682 (start + (segment->p_memsz > segment->p_filesz \ 3683 ? segment->p_memsz : segment->p_filesz)) 3684 3685 /* Returns true if the given section is contained within 4604 #define SEGMENT_END(segment, start) \ 4605 (start + (segment->p_memsz > segment->p_filesz \ 4606 ? segment->p_memsz : segment->p_filesz)) 4607 4608 #define SECTION_SIZE(section, segment) \ 4609 (((section->flags & (SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) \ 4610 != SEC_THREAD_LOCAL || segment->p_type == PT_TLS) \ 4611 ? section->_raw_size : 0) 4612 4613 /* Returns TRUE if the given section is contained within 3686 4614 the given segment. VMA addresses are compared. */ 3687 #define IS_CONTAINED_BY_VMA(section, segment) \3688 (section->vma >= segment->p_vaddr \3689 && (section->vma + section->_raw_size)\3690 <= (SEGMENT_END (segment, segment->p_vaddr)))3691 3692 /* Returns trueif the given section is contained within4615 #define IS_CONTAINED_BY_VMA(section, segment) \ 4616 (section->vma >= segment->p_vaddr \ 4617 && (section->vma + SECTION_SIZE (section, segment) \ 4618 <= (SEGMENT_END (segment, segment->p_vaddr)))) 4619 4620 /* Returns TRUE if the given section is contained within 3693 4621 the given segment. LMA addresses are compared. */ 3694 #define IS_CONTAINED_BY_LMA(section, segment, base) \3695 (section->lma >= base\3696 && (section->lma + section->_raw_size)\3697 <= SEGMENT_END (segment, base))4622 #define IS_CONTAINED_BY_LMA(section, segment, base) \ 4623 (section->lma >= base \ 4624 && (section->lma + SECTION_SIZE (section, segment) \ 4625 <= SEGMENT_END (segment, base))) 3698 4626 3699 4627 /* Special case: corefile "NOTE" section containing regs, prpsinfo etc. */ 3700 #define IS_COREFILE_NOTE(p, s) 3701 (p->p_type == PT_NOTE\3702 && bfd_get_format (ibfd) == bfd_core\3703 && s->vma == 0 && s->lma == 0\3704 && (bfd_vma) s->filepos >= p->p_offset\3705 && (bfd_vma) s->filepos + s->_raw_size\3706 <= p->p_offset + p->p_filesz)4628 #define IS_COREFILE_NOTE(p, s) \ 4629 (p->p_type == PT_NOTE \ 4630 && bfd_get_format (ibfd) == bfd_core \ 4631 && s->vma == 0 && s->lma == 0 \ 4632 && (bfd_vma) s->filepos >= p->p_offset \ 4633 && ((bfd_vma) s->filepos + s->_raw_size \ 4634 <= p->p_offset + p->p_filesz)) 3707 4635 3708 4636 /* The complicated case when p_vaddr is 0 is to handle the Solaris 3709 4637 linker, which generates a PT_INTERP section with p_vaddr and 3710 4638 p_memsz set to 0. */ 3711 #define IS_SOLARIS_PT_INTERP(p, s) \ 3712 ( p->p_vaddr == 0 \ 3713 && p->p_filesz > 0 \ 3714 && (s->flags & SEC_HAS_CONTENTS) != 0 \ 3715 && s->_raw_size > 0 \ 3716 && (bfd_vma) s->filepos >= p->p_offset \ 3717 && ((bfd_vma) s->filepos + s->_raw_size \ 3718 <= p->p_offset + p->p_filesz)) 4639 #define IS_SOLARIS_PT_INTERP(p, s) \ 4640 (p->p_vaddr == 0 \ 4641 && p->p_paddr == 0 \ 4642 && p->p_memsz == 0 \ 4643 && p->p_filesz > 0 \ 4644 && (s->flags & SEC_HAS_CONTENTS) != 0 \ 4645 && s->_raw_size > 0 \ 4646 && (bfd_vma) s->filepos >= p->p_offset \ 4647 && ((bfd_vma) s->filepos + s->_raw_size \ 4648 <= p->p_offset + p->p_filesz)) 3719 4649 3720 4650 /* Decide if the given section should be included in the given segment. 3721 4651 A section will be included if: 3722 1. It is within the address space of the segment, 4652 1. It is within the address space of the segment -- we use the LMA 4653 if that is set for the segment and the VMA otherwise, 3723 4654 2. It is an allocated segment, 3724 4655 3. There is an output section associated with it, 3725 4. The section has not already been allocated to a previous segment. */ 3726 #define INCLUDE_SECTION_IN_SEGMENT(section, segment) \ 3727 ((((IS_CONTAINED_BY_VMA (section, segment) \ 3728 || IS_SOLARIS_PT_INTERP (segment, section)) \ 3729 && (section->flags & SEC_ALLOC) != 0) \ 3730 || IS_COREFILE_NOTE (segment, section)) \ 3731 && section->output_section != NULL \ 3732 && section->segment_mark == false) 3733 3734 /* Returns true iff seg1 starts after the end of seg2. */ 3735 #define SEGMENT_AFTER_SEGMENT(seg1, seg2) \ 3736 (seg1->p_vaddr >= SEGMENT_END (seg2, seg2->p_vaddr)) 3737 3738 /* Returns true iff seg1 and seg2 overlap. */ 3739 #define SEGMENT_OVERLAPS(seg1, seg2) \ 3740 (!(SEGMENT_AFTER_SEGMENT (seg1, seg2) || SEGMENT_AFTER_SEGMENT (seg2, seg1))) 4656 4. The section has not already been allocated to a previous segment. 4657 5. PT_TLS segment includes only SHF_TLS sections. 4658 6. SHF_TLS sections are only in PT_TLS or PT_LOAD segments. */ 4659 #define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed) \ 4660 ((((segment->p_paddr \ 4661 ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \ 4662 : IS_CONTAINED_BY_VMA (section, segment)) \ 4663 && (section->flags & SEC_ALLOC) != 0) \ 4664 || IS_COREFILE_NOTE (segment, section)) \ 4665 && section->output_section != NULL \ 4666 && (segment->p_type != PT_TLS \ 4667 || (section->flags & SEC_THREAD_LOCAL)) \ 4668 && (segment->p_type == PT_LOAD \ 4669 || segment->p_type == PT_TLS \ 4670 || (section->flags & SEC_THREAD_LOCAL) == 0) \ 4671 && ! section->segment_mark) 4672 4673 /* Returns TRUE iff seg1 starts after the end of seg2. */ 4674 #define SEGMENT_AFTER_SEGMENT(seg1, seg2, field) \ 4675 (seg1->field >= SEGMENT_END (seg2, seg2->field)) 4676 4677 /* Returns TRUE iff seg1 and seg2 overlap. Segments overlap iff both 4678 their VMA address ranges and their LMA address ranges overlap. 4679 It is possible to have overlapping VMA ranges without overlapping LMA 4680 ranges. RedBoot images for example can have both .data and .bss mapped 4681 to the same VMA range, but with the .data section mapped to a different 4682 LMA. */ 4683 #define SEGMENT_OVERLAPS(seg1, seg2) \ 4684 ( !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_vaddr) \ 4685 || SEGMENT_AFTER_SEGMENT (seg2, seg1, p_vaddr)) \ 4686 && !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_paddr) \ 4687 || SEGMENT_AFTER_SEGMENT (seg2, seg1, p_paddr))) 3741 4688 3742 4689 /* Initialise the segment mark field. */ 3743 4690 for (section = ibfd->sections; section != NULL; section = section->next) 3744 section->segment_mark = false;4691 section->segment_mark = FALSE; 3745 4692 3746 4693 /* Scan through the segments specified in the program header 3747 4694 of the input BFD. For this first scan we look for overlaps 3748 in the loadable segments. These can be created by w ierd3749 parameters to objcopy. */4695 in the loadable segments. These can be created by weird 4696 parameters to objcopy. Also, fix some solaris weirdness. */ 3750 4697 for (i = 0, segment = elf_tdata (ibfd)->phdr; 3751 4698 i < num_segments; … … 3754 4701 unsigned int j; 3755 4702 Elf_Internal_Phdr *segment2; 4703 4704 if (segment->p_type == PT_INTERP) 4705 for (section = ibfd->sections; section; section = section->next) 4706 if (IS_SOLARIS_PT_INTERP (segment, section)) 4707 { 4708 /* Mininal change so that the normal section to segment 4709 assigment code will work. */ 4710 segment->p_vaddr = section->vma; 4711 break; 4712 } 3756 4713 3757 4714 if (segment->p_type != PT_LOAD) … … 3820 4777 bfd_vma suggested_lma; 3821 4778 unsigned int j; 4779 bfd_size_type amt; 3822 4780 3823 4781 if (segment->p_type == PT_NULL) … … 3825 4783 3826 4784 /* Compute how many sections might be placed into this segment. */ 3827 section_count = 0; 3828 for (section = ibfd->sections; section != NULL; section = section->next) 3829 if (INCLUDE_SECTION_IN_SEGMENT (section, segment)) 4785 for (section = ibfd->sections, section_count = 0; 4786 section != NULL; 4787 section = section->next) 4788 if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed)) 3830 4789 ++section_count; 3831 4790 3832 /* Allocate a segment map big enough to contain all of the 3833 sections we have selected. */ 3834 map = ((struct elf_segment_map *) 3835 bfd_alloc (obfd, 3836 (sizeof (struct elf_segment_map) 3837 + ((size_t) section_count - 1) * sizeof (asection *)))); 4791 /* Allocate a segment map big enough to contain 4792 all of the sections we have selected. */ 4793 amt = sizeof (struct elf_segment_map); 4794 amt += ((bfd_size_type) section_count - 1) * sizeof (asection *); 4795 map = (struct elf_segment_map *) bfd_alloc (obfd, amt); 3838 4796 if (map == NULL) 3839 return false;4797 return FALSE; 3840 4798 3841 4799 /* Initialise the fields of the segment map. Default to … … 3864 4822 3865 4823 if (segment->p_type == PT_LOAD && map->includes_phdrs) 3866 phdr_included = true;4824 phdr_included = TRUE; 3867 4825 } 3868 4826 … … 3871 4829 /* Special segments, such as the PT_PHDR segment, may contain 3872 4830 no sections, but ordinary, loadable segments should contain 3873 something. */ 4831 something. They are allowed by the ELF spec however, so only 4832 a warning is produced. */ 3874 4833 if (segment->p_type == PT_LOAD) 3875 _bfd_error_handler3876 (_("%s: warning: Empty loadable segment detected\n"),3877 bfd_get_filename (ibfd));4834 (*_bfd_error_handler) 4835 (_("%s: warning: Empty loadable segment detected, is this intentional ?\n"), 4836 bfd_archive_filename (ibfd)); 3878 4837 3879 4838 map->count = 0; … … 3903 4862 have to be created to contain the other sections. 3904 4863 3905 4. The sections have been moved, but not b ethe same amount.4864 4. The sections have been moved, but not by the same amount. 3906 4865 In this case we can change the segment's LMA to match the LMA 3907 4866 of the first section and we will have to create a new segment … … 3912 4871 to a segment, they are removed from this array. */ 3913 4872 3914 sections = (asection **) bfd_malloc 3915 (sizeof (asection *) * section_count); 4873 /* Gcc 2.96 miscompiles this code on mips. Don't do casting here 4874 to work around this long long bug. */ 4875 amt = section_count * sizeof (asection *); 4876 sections = (asection **) bfd_malloc (amt); 3916 4877 if (sections == NULL) 3917 return false;4878 return FALSE; 3918 4879 3919 4880 /* Step One: Scan for segment vs section LMA conflicts. … … 3931 4892 section = section->next) 3932 4893 { 3933 if (INCLUDE_SECTION_IN_SEGMENT (section, segment ))4894 if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed)) 3934 4895 { 3935 4896 output_section = section->output_section; … … 3939 4900 /* The Solaris native linker always sets p_paddr to 0. 3940 4901 We try to catch that case here, and set it to the 3941 correct value. */ 4902 correct value. Note - some backends require that 4903 p_paddr be left as zero. */ 3942 4904 if (segment->p_paddr == 0 3943 4905 && segment->p_vaddr != 0 4906 && (! bed->want_p_paddr_set_to_zero) 3944 4907 && isec == 0 3945 4908 && output_section->lma != 0 … … 3949 4912 : 0) 3950 4913 + (map->includes_phdrs 3951 ? iehdr->e_phnum * iehdr->e_phentsize 4914 ? (iehdr->e_phnum 4915 * iehdr->e_phentsize) 3952 4916 : 0)))) 3953 4917 map->p_paddr = segment->p_vaddr; … … 3956 4920 LMA address of the output section. */ 3957 4921 if (IS_CONTAINED_BY_LMA (output_section, segment, map->p_paddr) 3958 || IS_COREFILE_NOTE (segment, section)) 4922 || IS_COREFILE_NOTE (segment, section) 4923 || (bed->want_p_paddr_set_to_zero && 4924 IS_CONTAINED_BY_VMA (output_section, segment)) 4925 ) 3959 4926 { 3960 4927 if (matching_lma == 0) … … 4025 4992 4026 4993 /* Step Three: Loop over the sections again, this time assigning 4027 those that fit to the current segment and rem voing them from the4994 those that fit to the current segment and removing them from the 4028 4995 sections array; but making sure not to leave large gaps. Once all 4029 4996 possible sections have been assigned to the current segment it is … … 4074 5041 and the start of this section is more than 4075 5042 maxpagesize then we need to start a new segment. */ 4076 if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size, maxpagesize) 4077 < BFD_ALIGN (output_section->lma, maxpagesize)) 4078 || ((prev_sec->lma + prev_sec->_raw_size) > output_section->lma)) 5043 if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size, 5044 maxpagesize) 5045 < BFD_ALIGN (output_section->lma, maxpagesize)) 5046 || ((prev_sec->lma + prev_sec->_raw_size) 5047 > output_section->lma)) 4079 5048 { 4080 5049 if (suggested_lma == 0) … … 4088 5057 ++isec; 4089 5058 sections[j] = NULL; 4090 section->segment_mark = true;5059 section->segment_mark = TRUE; 4091 5060 } 4092 5061 else if (suggested_lma == 0) … … 4105 5074 segments. Create a new segment here, initialise it 4106 5075 and carry on looping. */ 4107 map = ((struct elf_segment_map *) 4108 bfd_alloc (obfd, 4109 (sizeof (struct elf_segment_map) 4110 + ((size_t) section_count - 1) 4111 * sizeof (asection *)))); 5076 amt = sizeof (struct elf_segment_map); 5077 amt += ((bfd_size_type) section_count - 1) * sizeof (asection *); 5078 map = (struct elf_segment_map *) bfd_alloc (obfd, amt); 4112 5079 if (map == NULL) 4113 return false; 5080 { 5081 free (sections); 5082 return FALSE; 5083 } 4114 5084 4115 5085 /* Initialise the fields of the segment map. Set the physical … … 4139 5109 break; 4140 5110 if (map == NULL) 4141 { 4142 for (map = map_first; map != NULL; map = map->next) 4143 map->p_paddr_valid = 0; 4144 } 5111 for (map = map_first; map != NULL; map = map->next) 5112 map->p_paddr_valid = 0; 4145 5113 4146 5114 elf_tdata (obfd)->segment_map = map_first; 4147 5115 4148 5116 /* If we had to estimate the number of program headers that were 4149 going to be needed, then check our estimate know and adjust5117 going to be needed, then check our estimate now and adjust 4150 5118 the offset if necessary. */ 4151 5119 if (phdr_adjust_seg != NULL) … … 4187 5155 4188 5156 #undef SEGMENT_END 5157 #undef SECTION_SIZE 4189 5158 #undef IS_CONTAINED_BY_VMA 4190 5159 #undef IS_CONTAINED_BY_LMA … … 4194 5163 #undef SEGMENT_AFTER_SEGMENT 4195 5164 #undef SEGMENT_OVERLAPS 4196 return true;5165 return TRUE; 4197 5166 } 4198 5167 … … 4200 5169 field, and sometimes the info field. */ 4201 5170 4202 b oolean5171 bfd_boolean 4203 5172 _bfd_elf_copy_private_section_data (ibfd, isec, obfd, osec) 4204 5173 bfd *ibfd; … … 4211 5180 if (ibfd->xvec->flavour != bfd_target_elf_flavour 4212 5181 || obfd->xvec->flavour != bfd_target_elf_flavour) 4213 return true; 4214 4215 /* Copy over private BFD data if it has not already been copied. 4216 This must be done here, rather than in the copy_private_bfd_data 4217 entry point, because the latter is called after the section 4218 contents have been set, which means that the program headers have 4219 already been worked out. */ 4220 if (elf_tdata (obfd)->segment_map == NULL 4221 && elf_tdata (ibfd)->phdr != NULL) 4222 { 4223 asection *s; 4224 4225 /* Only set up the segments if there are no more SEC_ALLOC 4226 sections. FIXME: This won't do the right thing if objcopy is 4227 used to remove the last SEC_ALLOC section, since objcopy 4228 won't call this routine in that case. */ 4229 for (s = isec->next; s != NULL; s = s->next) 4230 if ((s->flags & SEC_ALLOC) != 0) 4231 break; 4232 if (s == NULL) 4233 { 4234 if (! copy_private_bfd_data (ibfd, obfd)) 4235 return false; 4236 } 5182 return TRUE; 5183 5184 if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL) 5185 { 5186 asection *s; 5187 5188 /* Only set up the segments if there are no more SEC_ALLOC 5189 sections. FIXME: This won't do the right thing if objcopy is 5190 used to remove the last SEC_ALLOC section, since objcopy 5191 won't call this routine in that case. */ 5192 for (s = isec->next; s != NULL; s = s->next) 5193 if ((s->flags & SEC_ALLOC) != 0) 5194 break; 5195 if (s == NULL) 5196 { 5197 if (! copy_private_bfd_data (ibfd, obfd)) 5198 return FALSE; 5199 } 4237 5200 } 4238 5201 … … 4248 5211 ohdr->sh_info = ihdr->sh_info; 4249 5212 4250 elf_section_data (osec)->use_rela_p 4251 = elf_section_data (isec)->use_rela_p; 4252 4253 return true; 5213 /* Set things up for objcopy. The output SHT_GROUP section will 5214 have its elf_next_in_group pointing back to the input group 5215 members. */ 5216 elf_next_in_group (osec) = elf_next_in_group (isec); 5217 elf_group_name (osec) = elf_group_name (isec); 5218 5219 osec->use_rela_p = isec->use_rela_p; 5220 5221 return TRUE; 4254 5222 } 4255 5223 … … 4260 5228 swap_out_syms function. */ 4261 5229 4262 #define MAP_ONESYMTAB (SHN_LORESERVE - 1) 4263 #define MAP_DYNSYMTAB (SHN_LORESERVE - 2) 4264 #define MAP_STRTAB (SHN_LORESERVE - 3) 4265 #define MAP_SHSTRTAB (SHN_LORESERVE - 4) 4266 4267 boolean 5230 #define MAP_ONESYMTAB (SHN_HIOS + 1) 5231 #define MAP_DYNSYMTAB (SHN_HIOS + 2) 5232 #define MAP_STRTAB (SHN_HIOS + 3) 5233 #define MAP_SHSTRTAB (SHN_HIOS + 4) 5234 #define MAP_SYM_SHNDX (SHN_HIOS + 5) 5235 5236 bfd_boolean 4268 5237 _bfd_elf_copy_private_symbol_data (ibfd, isymarg, obfd, osymarg) 4269 5238 bfd *ibfd; … … 4276 5245 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 4277 5246 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 4278 return true;5247 return TRUE; 4279 5248 4280 5249 isym = elf_symbol_from (ibfd, isymarg); … … 4296 5265 else if (shndx == elf_tdata (ibfd)->shstrtab_section) 4297 5266 shndx = MAP_SHSTRTAB; 5267 else if (shndx == elf_tdata (ibfd)->symtab_shndx_section) 5268 shndx = MAP_SYM_SHNDX; 4298 5269 osym->internal_elf_sym.st_shndx = shndx; 4299 5270 } 4300 5271 4301 return true;5272 return TRUE; 4302 5273 } 4303 5274 4304 5275 /* Swap out the symbols. */ 4305 5276 4306 static b oolean5277 static bfd_boolean 4307 5278 swap_out_syms (abfd, sttp, relocatable_p) 4308 5279 bfd *abfd; … … 4310 5281 int relocatable_p; 4311 5282 { 4312 struct elf_backend_data *bed = get_elf_backend_data (abfd); 5283 struct elf_backend_data *bed; 5284 int symcount; 5285 asymbol **syms; 5286 struct bfd_strtab_hash *stt; 5287 Elf_Internal_Shdr *symtab_hdr; 5288 Elf_Internal_Shdr *symtab_shndx_hdr; 5289 Elf_Internal_Shdr *symstrtab_hdr; 5290 char *outbound_syms; 5291 char *outbound_shndx; 5292 int idx; 5293 bfd_size_type amt; 4313 5294 4314 5295 if (!elf_map_symbols (abfd)) 4315 return false;5296 return FALSE; 4316 5297 4317 5298 /* Dump out the symtabs. */ 5299 stt = _bfd_elf_stringtab_init (); 5300 if (stt == NULL) 5301 return FALSE; 5302 5303 bed = get_elf_backend_data (abfd); 5304 symcount = bfd_get_symcount (abfd); 5305 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 5306 symtab_hdr->sh_type = SHT_SYMTAB; 5307 symtab_hdr->sh_entsize = bed->s->sizeof_sym; 5308 symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1); 5309 symtab_hdr->sh_info = elf_num_locals (abfd) + 1; 5310 symtab_hdr->sh_addralign = bed->s->file_align; 5311 5312 symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr; 5313 symstrtab_hdr->sh_type = SHT_STRTAB; 5314 5315 amt = (bfd_size_type) (1 + symcount) * bed->s->sizeof_sym; 5316 outbound_syms = bfd_alloc (abfd, amt); 5317 if (outbound_syms == NULL) 5318 { 5319 _bfd_stringtab_free (stt); 5320 return FALSE; 5321 } 5322 symtab_hdr->contents = (PTR) outbound_syms; 5323 5324 outbound_shndx = NULL; 5325 symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr; 5326 if (symtab_shndx_hdr->sh_name != 0) 5327 { 5328 amt = (bfd_size_type) (1 + symcount) * sizeof (Elf_External_Sym_Shndx); 5329 outbound_shndx = bfd_zalloc (abfd, amt); 5330 if (outbound_shndx == NULL) 5331 { 5332 _bfd_stringtab_free (stt); 5333 return FALSE; 5334 } 5335 5336 symtab_shndx_hdr->contents = outbound_shndx; 5337 symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX; 5338 symtab_shndx_hdr->sh_size = amt; 5339 symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx); 5340 symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx); 5341 } 5342 5343 /* Now generate the data (for "contents"). */ 4318 5344 { 4319 int symcount = bfd_get_symcount (abfd); 4320 asymbol **syms = bfd_get_outsymbols (abfd); 4321 struct bfd_strtab_hash *stt; 4322 Elf_Internal_Shdr *symtab_hdr; 4323 Elf_Internal_Shdr *symstrtab_hdr; 4324 char *outbound_syms; 4325 int idx; 4326 4327 stt = _bfd_elf_stringtab_init (); 4328 if (stt == NULL) 4329 return false; 4330 4331 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4332 symtab_hdr->sh_type = SHT_SYMTAB; 4333 symtab_hdr->sh_entsize = bed->s->sizeof_sym; 4334 symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1); 4335 symtab_hdr->sh_info = elf_num_locals (abfd) + 1; 4336 symtab_hdr->sh_addralign = bed->s->file_align; 4337 4338 symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr; 4339 symstrtab_hdr->sh_type = SHT_STRTAB; 4340 4341 outbound_syms = bfd_alloc (abfd, 4342 (1 + symcount) * bed->s->sizeof_sym); 4343 if (outbound_syms == NULL) 4344 return false; 4345 symtab_hdr->contents = (PTR) outbound_syms; 4346 4347 /* now generate the data (for "contents") */ 4348 { 4349 /* Fill in zeroth symbol and swap it out. */ 5345 /* Fill in zeroth symbol and swap it out. */ 5346 Elf_Internal_Sym sym; 5347 sym.st_name = 0; 5348 sym.st_value = 0; 5349 sym.st_size = 0; 5350 sym.st_info = 0; 5351 sym.st_other = 0; 5352 sym.st_shndx = SHN_UNDEF; 5353 bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx); 5354 outbound_syms += bed->s->sizeof_sym; 5355 if (outbound_shndx != NULL) 5356 outbound_shndx += sizeof (Elf_External_Sym_Shndx); 5357 } 5358 5359 syms = bfd_get_outsymbols (abfd); 5360 for (idx = 0; idx < symcount; idx++) 5361 { 4350 5362 Elf_Internal_Sym sym; 4351 sym.st_name = 0; 4352 sym.st_value = 0; 4353 sym.st_size = 0; 4354 sym.st_info = 0; 4355 sym.st_other = 0; 4356 sym.st_shndx = SHN_UNDEF; 4357 bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms); 5363 bfd_vma value = syms[idx]->value; 5364 elf_symbol_type *type_ptr; 5365 flagword flags = syms[idx]->flags; 5366 int type; 5367 5368 if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM) 5369 { 5370 /* Local section symbols have no name. */ 5371 sym.st_name = 0; 5372 } 5373 else 5374 { 5375 sym.st_name = (unsigned long) _bfd_stringtab_add (stt, 5376 syms[idx]->name, 5377 TRUE, FALSE); 5378 if (sym.st_name == (unsigned long) -1) 5379 { 5380 _bfd_stringtab_free (stt); 5381 return FALSE; 5382 } 5383 } 5384 5385 type_ptr = elf_symbol_from (abfd, syms[idx]); 5386 5387 if ((flags & BSF_SECTION_SYM) == 0 5388 && bfd_is_com_section (syms[idx]->section)) 5389 { 5390 /* ELF common symbols put the alignment into the `value' field, 5391 and the size into the `size' field. This is backwards from 5392 how BFD handles it, so reverse it here. */ 5393 sym.st_size = value; 5394 if (type_ptr == NULL 5395 || type_ptr->internal_elf_sym.st_value == 0) 5396 sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value)); 5397 else 5398 sym.st_value = type_ptr->internal_elf_sym.st_value; 5399 sym.st_shndx = _bfd_elf_section_from_bfd_section 5400 (abfd, syms[idx]->section); 5401 } 5402 else 5403 { 5404 asection *sec = syms[idx]->section; 5405 int shndx; 5406 5407 if (sec->output_section) 5408 { 5409 value += sec->output_offset; 5410 sec = sec->output_section; 5411 } 5412 5413 /* Don't add in the section vma for relocatable output. */ 5414 if (! relocatable_p) 5415 value += sec->vma; 5416 sym.st_value = value; 5417 sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0; 5418 5419 if (bfd_is_abs_section (sec) 5420 && type_ptr != NULL 5421 && type_ptr->internal_elf_sym.st_shndx != 0) 5422 { 5423 /* This symbol is in a real ELF section which we did 5424 not create as a BFD section. Undo the mapping done 5425 by copy_private_symbol_data. */ 5426 shndx = type_ptr->internal_elf_sym.st_shndx; 5427 switch (shndx) 5428 { 5429 case MAP_ONESYMTAB: 5430 shndx = elf_onesymtab (abfd); 5431 break; 5432 case MAP_DYNSYMTAB: 5433 shndx = elf_dynsymtab (abfd); 5434 break; 5435 case MAP_STRTAB: 5436 shndx = elf_tdata (abfd)->strtab_section; 5437 break; 5438 case MAP_SHSTRTAB: 5439 shndx = elf_tdata (abfd)->shstrtab_section; 5440 break; 5441 case MAP_SYM_SHNDX: 5442 shndx = elf_tdata (abfd)->symtab_shndx_section; 5443 break; 5444 default: 5445 break; 5446 } 5447 } 5448 else 5449 { 5450 shndx = _bfd_elf_section_from_bfd_section (abfd, sec); 5451 5452 if (shndx == -1) 5453 { 5454 asection *sec2; 5455 5456 /* Writing this would be a hell of a lot easier if 5457 we had some decent documentation on bfd, and 5458 knew what to expect of the library, and what to 5459 demand of applications. For example, it 5460 appears that `objcopy' might not set the 5461 section of a symbol to be a section that is 5462 actually in the output file. */ 5463 sec2 = bfd_get_section_by_name (abfd, sec->name); 5464 if (sec2 == NULL) 5465 { 5466 _bfd_error_handler (_("\ 5467 Unable to find equivalent output section for symbol '%s' from section '%s'"), 5468 syms[idx]->name ? syms[idx]->name : "<Local sym>", 5469 sec->name); 5470 bfd_set_error (bfd_error_invalid_operation); 5471 _bfd_stringtab_free (stt); 5472 return FALSE; 5473 } 5474 5475 shndx = _bfd_elf_section_from_bfd_section (abfd, sec2); 5476 BFD_ASSERT (shndx != -1); 5477 } 5478 } 5479 5480 sym.st_shndx = shndx; 5481 } 5482 5483 if ((flags & BSF_THREAD_LOCAL) != 0) 5484 type = STT_TLS; 5485 else if ((flags & BSF_FUNCTION) != 0) 5486 type = STT_FUNC; 5487 else if ((flags & BSF_OBJECT) != 0) 5488 type = STT_OBJECT; 5489 else 5490 type = STT_NOTYPE; 5491 5492 if (syms[idx]->section->flags & SEC_THREAD_LOCAL) 5493 type = STT_TLS; 5494 5495 /* Processor-specific types. */ 5496 if (type_ptr != NULL 5497 && bed->elf_backend_get_symbol_type) 5498 type = ((*bed->elf_backend_get_symbol_type) 5499 (&type_ptr->internal_elf_sym, type)); 5500 5501 if (flags & BSF_SECTION_SYM) 5502 { 5503 if (flags & BSF_GLOBAL) 5504 sym.st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); 5505 else 5506 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); 5507 } 5508 else if (bfd_is_com_section (syms[idx]->section)) 5509 sym.st_info = ELF_ST_INFO (STB_GLOBAL, type); 5510 else if (bfd_is_und_section (syms[idx]->section)) 5511 sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK) 5512 ? STB_WEAK 5513 : STB_GLOBAL), 5514 type); 5515 else if (flags & BSF_FILE) 5516 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE); 5517 else 5518 { 5519 int bind = STB_LOCAL; 5520 5521 if (flags & BSF_LOCAL) 5522 bind = STB_LOCAL; 5523 else if (flags & BSF_WEAK) 5524 bind = STB_WEAK; 5525 else if (flags & BSF_GLOBAL) 5526 bind = STB_GLOBAL; 5527 5528 sym.st_info = ELF_ST_INFO (bind, type); 5529 } 5530 5531 if (type_ptr != NULL) 5532 sym.st_other = type_ptr->internal_elf_sym.st_other; 5533 else 5534 sym.st_other = 0; 5535 5536 bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx); 4358 5537 outbound_syms += bed->s->sizeof_sym; 4359 } 4360 for (idx = 0; idx < symcount; idx++) 4361 { 4362 Elf_Internal_Sym sym; 4363 bfd_vma value = syms[idx]->value; 4364 elf_symbol_type *type_ptr; 4365 flagword flags = syms[idx]->flags; 4366 int type; 4367 4368 if ((flags & BSF_SECTION_SYM) != 0) 4369 { 4370 /* Section symbols have no name. */ 4371 sym.st_name = 0; 4372 } 4373 else 4374 { 4375 sym.st_name = (unsigned long) _bfd_stringtab_add (stt, 4376 syms[idx]->name, 4377 true, false); 4378 if (sym.st_name == (unsigned long) -1) 4379 return false; 4380 } 4381 4382 type_ptr = elf_symbol_from (abfd, syms[idx]); 4383 4384 if ((flags & BSF_SECTION_SYM) == 0 4385 && bfd_is_com_section (syms[idx]->section)) 4386 { 4387 /* ELF common symbols put the alignment into the `value' field, 4388 and the size into the `size' field. This is backwards from 4389 how BFD handles it, so reverse it here. */ 4390 sym.st_size = value; 4391 if (type_ptr == NULL 4392 || type_ptr->internal_elf_sym.st_value == 0) 4393 sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value)); 4394 else 4395 sym.st_value = type_ptr->internal_elf_sym.st_value; 4396 sym.st_shndx = _bfd_elf_section_from_bfd_section 4397 (abfd, syms[idx]->section); 4398 } 4399 else 4400 { 4401 asection *sec = syms[idx]->section; 4402 int shndx; 4403 4404 if (sec->output_section) 4405 { 4406 value += sec->output_offset; 4407 sec = sec->output_section; 4408 } 4409 /* Don't add in the section vma for relocatable output. */ 4410 if (! relocatable_p) 4411 value += sec->vma; 4412 sym.st_value = value; 4413 sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0; 4414 4415 if (bfd_is_abs_section (sec) 4416 && type_ptr != NULL 4417 && type_ptr->internal_elf_sym.st_shndx != 0) 4418 { 4419 /* This symbol is in a real ELF section which we did 4420 not create as a BFD section. Undo the mapping done 4421 by copy_private_symbol_data. */ 4422 shndx = type_ptr->internal_elf_sym.st_shndx; 4423 switch (shndx) 4424 { 4425 case MAP_ONESYMTAB: 4426 shndx = elf_onesymtab (abfd); 4427 break; 4428 case MAP_DYNSYMTAB: 4429 shndx = elf_dynsymtab (abfd); 4430 break; 4431 case MAP_STRTAB: 4432 shndx = elf_tdata (abfd)->strtab_section; 4433 break; 4434 case MAP_SHSTRTAB: 4435 shndx = elf_tdata (abfd)->shstrtab_section; 4436 break; 4437 default: 4438 break; 4439 } 4440 } 4441 else 4442 { 4443 shndx = _bfd_elf_section_from_bfd_section (abfd, sec); 4444 4445 if (shndx == -1) 4446 { 4447 asection *sec2; 4448 4449 /* Writing this would be a hell of a lot easier if 4450 we had some decent documentation on bfd, and 4451 knew what to expect of the library, and what to 4452 demand of applications. For example, it 4453 appears that `objcopy' might not set the 4454 section of a symbol to be a section that is 4455 actually in the output file. */ 4456 sec2 = bfd_get_section_by_name (abfd, sec->name); 4457 BFD_ASSERT (sec2 != 0); 4458 shndx = _bfd_elf_section_from_bfd_section (abfd, sec2); 4459 BFD_ASSERT (shndx != -1); 4460 } 4461 } 4462 4463 sym.st_shndx = shndx; 4464 } 4465 4466 if ((flags & BSF_FUNCTION) != 0) 4467 type = STT_FUNC; 4468 else if ((flags & BSF_OBJECT) != 0) 4469 type = STT_OBJECT; 4470 else 4471 type = STT_NOTYPE; 4472 4473 /* Processor-specific types */ 4474 if (type_ptr != NULL 4475 && bed->elf_backend_get_symbol_type) 4476 type = (*bed->elf_backend_get_symbol_type) (&type_ptr->internal_elf_sym, type); 4477 4478 if (flags & BSF_SECTION_SYM) 4479 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); 4480 else if (bfd_is_com_section (syms[idx]->section)) 4481 sym.st_info = ELF_ST_INFO (STB_GLOBAL, type); 4482 else if (bfd_is_und_section (syms[idx]->section)) 4483 sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK) 4484 ? STB_WEAK 4485 : STB_GLOBAL), 4486 type); 4487 else if (flags & BSF_FILE) 4488 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE); 4489 else 4490 { 4491 int bind = STB_LOCAL; 4492 4493 if (flags & BSF_LOCAL) 4494 bind = STB_LOCAL; 4495 else if (flags & BSF_WEAK) 4496 bind = STB_WEAK; 4497 else if (flags & BSF_GLOBAL) 4498 bind = STB_GLOBAL; 4499 4500 sym.st_info = ELF_ST_INFO (bind, type); 4501 } 4502 4503 if (type_ptr != NULL) 4504 sym.st_other = type_ptr->internal_elf_sym.st_other; 4505 else 4506 sym.st_other = 0; 4507 4508 bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms); 4509 outbound_syms += bed->s->sizeof_sym; 4510 } 4511 4512 *sttp = stt; 4513 symstrtab_hdr->sh_size = _bfd_stringtab_size (stt); 4514 symstrtab_hdr->sh_type = SHT_STRTAB; 4515 4516 symstrtab_hdr->sh_flags = 0; 4517 symstrtab_hdr->sh_addr = 0; 4518 symstrtab_hdr->sh_entsize = 0; 4519 symstrtab_hdr->sh_link = 0; 4520 symstrtab_hdr->sh_info = 0; 4521 symstrtab_hdr->sh_addralign = 1; 4522 } 4523 4524 return true; 5538 if (outbound_shndx != NULL) 5539 outbound_shndx += sizeof (Elf_External_Sym_Shndx); 5540 } 5541 5542 *sttp = stt; 5543 symstrtab_hdr->sh_size = _bfd_stringtab_size (stt); 5544 symstrtab_hdr->sh_type = SHT_STRTAB; 5545 5546 symstrtab_hdr->sh_flags = 0; 5547 symstrtab_hdr->sh_addr = 0; 5548 symstrtab_hdr->sh_entsize = 0; 5549 symstrtab_hdr->sh_link = 0; 5550 symstrtab_hdr->sh_info = 0; 5551 symstrtab_hdr->sh_addralign = 1; 5552 5553 return TRUE; 4525 5554 } 4526 5555 … … 4540 5569 4541 5570 symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym; 4542 symtab_size = (symcount - 1 + 1) * (sizeof (asymbol *)); 5571 symtab_size = (symcount + 1) * (sizeof (asymbol *)); 5572 if (symcount > 0) 5573 symtab_size -= sizeof (asymbol *); 4543 5574 4544 5575 return symtab_size; … … 4560 5591 4561 5592 symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym; 4562 symtab_size = (symcount - 1 + 1) * (sizeof (asymbol *)); 5593 symtab_size = (symcount + 1) * (sizeof (asymbol *)); 5594 if (symcount > 0) 5595 symtab_size -= sizeof (asymbol *); 4563 5596 4564 5597 return symtab_size; … … 4584 5617 arelent *tblptr; 4585 5618 unsigned int i; 4586 4587 if (! get_elf_backend_data (abfd)->s->slurp_reloc_table (abfd, 4588 section, 4589 symbols, 4590 false)) 5619 struct elf_backend_data *bed = get_elf_backend_data (abfd); 5620 5621 if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE)) 4591 5622 return -1; 4592 5623 … … 4605 5636 asymbol **alocation; 4606 5637 { 4607 long symcount = get_elf_backend_data (abfd)->s->slurp_symbol_table4608 (abfd, alocation, false);5638 struct elf_backend_data *bed = get_elf_backend_data (abfd); 5639 long symcount = bed->s->slurp_symbol_table (abfd, alocation, FALSE); 4609 5640 4610 5641 if (symcount >= 0) … … 4618 5649 asymbol **alocation; 4619 5650 { 4620 return get_elf_backend_data (abfd)->s->slurp_symbol_table 4621 (abfd, alocation, true); 5651 struct elf_backend_data *bed = get_elf_backend_data (abfd); 5652 long symcount = bed->s->slurp_symbol_table (abfd, alocation, TRUE); 5653 5654 if (symcount >= 0) 5655 bfd_get_dynamic_symcount (abfd) = symcount; 5656 return symcount; 4622 5657 } 4623 5658 … … 4666 5701 asymbol **syms; 4667 5702 { 4668 boolean (*slurp_relocs) PARAMS ((bfd *, asection *, asymbol **, boolean)); 5703 bfd_boolean (*slurp_relocs) 5704 PARAMS ((bfd *, asection *, asymbol **, bfd_boolean)); 4669 5705 asection *s; 4670 5706 long ret; … … 4687 5723 long count, i; 4688 5724 4689 if (! (*slurp_relocs) (abfd, s, syms, true))5725 if (! (*slurp_relocs) (abfd, s, syms, TRUE)) 4690 5726 return -1; 4691 5727 count = s->_raw_size / elf_section_data (s)->this_hdr.sh_entsize; … … 4705 5741 /* Read in the version information. */ 4706 5742 4707 b oolean5743 bfd_boolean 4708 5744 _bfd_elf_slurp_version_tables (abfd) 4709 5745 bfd *abfd; 4710 5746 { 4711 5747 bfd_byte *contents = NULL; 5748 bfd_size_type amt; 4712 5749 4713 5750 if (elf_dynverdef (abfd) != 0) … … 4727 5764 goto error_return; 4728 5765 if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0 4729 || bfd_ read ((PTR) contents, 1, hdr->sh_size, abfd) != hdr->sh_size)5766 || bfd_bread ((PTR) contents, hdr->sh_size, abfd) != hdr->sh_size) 4730 5767 goto error_return; 4731 5768 … … 4746 5783 } 4747 5784 4748 elf_tdata (abfd)->verdef = 4749 ((Elf_Internal_Verdef *) 4750 bfd_zalloc (abfd, maxidx * sizeof (Elf_Internal_Verdef))); 5785 amt = (bfd_size_type) maxidx * sizeof (Elf_Internal_Verdef); 5786 elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *) bfd_zalloc (abfd, amt); 4751 5787 if (elf_tdata (abfd)->verdef == NULL) 4752 5788 goto error_return; … … 4769 5805 iverdef->vd_bfd = abfd; 4770 5806 4771 iverdef->vd_auxptr = ((Elf_Internal_Verdaux *) 4772 bfd_alloc (abfd, 4773 (iverdef->vd_cnt 4774 * sizeof (Elf_Internal_Verdaux)))); 5807 amt = (bfd_size_type) iverdef->vd_cnt * sizeof (Elf_Internal_Verdaux); 5808 iverdef->vd_auxptr = (Elf_Internal_Verdaux *) bfd_alloc (abfd, amt); 4775 5809 if (iverdef->vd_auxptr == NULL) 4776 5810 goto error_return; … … 4822 5856 hdr = &elf_tdata (abfd)->dynverref_hdr; 4823 5857 5858 amt = (bfd_size_type) hdr->sh_info * sizeof (Elf_Internal_Verneed); 4824 5859 elf_tdata (abfd)->verref = 4825 ((Elf_Internal_Verneed *) 4826 bfd_zalloc (abfd, hdr->sh_info * sizeof (Elf_Internal_Verneed))); 5860 (Elf_Internal_Verneed *) bfd_zalloc (abfd, amt); 4827 5861 if (elf_tdata (abfd)->verref == NULL) 4828 5862 goto error_return; … … 4834 5868 goto error_return; 4835 5869 if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0 4836 || bfd_ read ((PTR) contents, 1, hdr->sh_size, abfd) != hdr->sh_size)5870 || bfd_bread ((PTR) contents, hdr->sh_size, abfd) != hdr->sh_size) 4837 5871 goto error_return; 4838 5872 … … 4855 5889 goto error_return; 4856 5890 4857 iverneed->vn_auxptr = 4858 ((Elf_Internal_Vernaux *) 4859 bfd_alloc (abfd, 4860 iverneed->vn_cnt * sizeof (Elf_Internal_Vernaux))); 5891 amt = iverneed->vn_cnt; 5892 amt *= sizeof (Elf_Internal_Vernaux); 5893 iverneed->vn_auxptr = (Elf_Internal_Vernaux *) bfd_alloc (abfd, amt); 4861 5894 4862 5895 evernaux = ((Elf_External_Vernaux *) … … 4895 5928 } 4896 5929 4897 return true;5930 return TRUE; 4898 5931 4899 5932 error_return: 4900 if (contents == NULL)5933 if (contents != NULL) 4901 5934 free (contents); 4902 return false;5935 return FALSE; 4903 5936 } 4904 5937 … … 4909 5942 { 4910 5943 elf_symbol_type *newsym; 4911 4912 newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof (elf_symbol_type)); 5944 bfd_size_type amt = sizeof (elf_symbol_type); 5945 5946 newsym = (elf_symbol_type *) bfd_zalloc (abfd, amt); 4913 5947 if (!newsym) 4914 5948 return NULL; … … 4933 5967 override it. */ 4934 5968 4935 b oolean5969 bfd_boolean 4936 5970 _bfd_elf_is_local_label_name (abfd, name) 4937 5971 bfd *abfd ATTRIBUTE_UNUSED; … … 4940 5974 /* Normal local symbols start with ``.L''. */ 4941 5975 if (name[0] == '.' && name[1] == 'L') 4942 return true;5976 return TRUE; 4943 5977 4944 5978 /* At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate 4945 5979 DWARF debugging symbols starting with ``..''. */ 4946 5980 if (name[0] == '.' && name[1] == '.') 4947 return true;5981 return TRUE; 4948 5982 4949 5983 /* gcc will sometimes generate symbols beginning with ``_.L_'' when … … 4954 5988 we treat such symbols as local. */ 4955 5989 if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_') 4956 return true;4957 4958 return false;5990 return TRUE; 5991 5992 return FALSE; 4959 5993 } 4960 5994 … … 4968 6002 } 4969 6003 4970 b oolean6004 bfd_boolean 4971 6005 _bfd_elf_set_arch_mach (abfd, arch, machine) 4972 6006 bfd *abfd; … … 4979 6013 && arch != bfd_arch_unknown 4980 6014 && get_elf_backend_data (abfd)->arch != bfd_arch_unknown) 4981 return false;6015 return FALSE; 4982 6016 4983 6017 return bfd_default_set_arch_mach (abfd, arch, machine); … … 4987 6021 for error reporting. */ 4988 6022 4989 static b oolean6023 static bfd_boolean 4990 6024 elf_find_function (abfd, section, symbols, offset, 4991 6025 filename_ptr, functionname_ptr) … … 5036 6070 5037 6071 if (func == NULL) 5038 return false;6072 return FALSE; 5039 6073 5040 6074 if (filename_ptr) … … 5043 6077 *functionname_ptr = bfd_asymbol_name (func); 5044 6078 5045 return true;6079 return TRUE; 5046 6080 } 5047 6081 … … 5049 6083 for error reporting. */ 5050 6084 5051 b oolean6085 bfd_boolean 5052 6086 _bfd_elf_find_nearest_line (abfd, section, symbols, offset, 5053 6087 filename_ptr, functionname_ptr, line_ptr) … … 5060 6094 unsigned int *line_ptr; 5061 6095 { 5062 b oolean found;6096 bfd_boolean found; 5063 6097 5064 6098 if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset, … … 5071 6105 functionname_ptr); 5072 6106 5073 return true;6107 return TRUE; 5074 6108 } 5075 6109 … … 5084 6118 functionname_ptr); 5085 6119 5086 return true;6120 return TRUE; 5087 6121 } 5088 6122 … … 5091 6125 functionname_ptr, line_ptr, 5092 6126 &elf_tdata (abfd)->line_info)) 5093 return false;5094 if (found )5095 return true;6127 return FALSE; 6128 if (found && (*functionname_ptr || *line_ptr)) 6129 return TRUE; 5096 6130 5097 6131 if (symbols == NULL) 5098 return false;6132 return FALSE; 5099 6133 5100 6134 if (! elf_find_function (abfd, section, symbols, offset, 5101 6135 filename_ptr, functionname_ptr)) 5102 return false;6136 return FALSE; 5103 6137 5104 6138 *line_ptr = 0; 5105 return true;6139 return TRUE; 5106 6140 } 5107 6141 … … 5109 6143 _bfd_elf_sizeof_headers (abfd, reloc) 5110 6144 bfd *abfd; 5111 b oolean reloc;6145 bfd_boolean reloc; 5112 6146 { 5113 6147 int ret; … … 5119 6153 } 5120 6154 5121 b oolean6155 bfd_boolean 5122 6156 _bfd_elf_set_section_contents (abfd, section, location, offset, count) 5123 6157 bfd *abfd; … … 5128 6162 { 5129 6163 Elf_Internal_Shdr *hdr; 6164 bfd_signed_vma pos; 5130 6165 5131 6166 if (! abfd->output_has_begun 5132 && ! _bfd_elf_compute_section_file_positions5133 (abfd, (struct bfd_link_info *) NULL))5134 return false;6167 && ! (_bfd_elf_compute_section_file_positions 6168 (abfd, (struct bfd_link_info *) NULL))) 6169 return FALSE; 5135 6170 5136 6171 hdr = &elf_section_data (section)->this_hdr; 5137 5138 if (bfd_seek (abfd, hdr->sh_offset + offset, SEEK_SET) == -1) 5139 return false; 5140 if (bfd_write (location, 1, count, abfd) != count) 5141 return false; 5142 5143 return true; 6172 pos = hdr->sh_offset + offset; 6173 if (bfd_seek (abfd, pos, SEEK_SET) != 0 6174 || bfd_bwrite (location, count, abfd) != count) 6175 return FALSE; 6176 6177 return TRUE; 5144 6178 } 5145 6179 … … 5153 6187 } 5154 6188 5155 #if 05156 void5157 _bfd_elf_no_info_to_howto_rel (abfd, cache_ptr, dst)5158 bfd *abfd;5159 arelent *cache_ptr;5160 Elf_Internal_Rel *dst;5161 {5162 abort ();5163 }5164 #endif5165 5166 6189 /* Try to convert a non-ELF reloc into an ELF one. */ 5167 6190 5168 b oolean6191 bfd_boolean 5169 6192 _bfd_elf_validate_reloc (abfd, areloc) 5170 6193 bfd *abfd; … … 5252 6275 } 5253 6276 5254 return true;6277 return TRUE; 5255 6278 5256 6279 fail: 5257 6280 (*_bfd_error_handler) 5258 6281 (_("%s: unsupported relocation type %s"), 5259 bfd_ get_filename (abfd), areloc->howto->name);6282 bfd_archive_filename (abfd), areloc->howto->name); 5260 6283 bfd_set_error (bfd_error_bad_value); 5261 return false;5262 } 5263 5264 b oolean6284 return FALSE; 6285 } 6286 6287 bfd_boolean 5265 6288 _bfd_elf_close_and_cleanup (abfd) 5266 6289 bfd *abfd; … … 5269 6292 { 5270 6293 if (elf_shstrtab (abfd) != NULL) 5271 _bfd_ stringtab_free (elf_shstrtab (abfd));6294 _bfd_elf_strtab_free (elf_shstrtab (abfd)); 5272 6295 } 5273 6296 … … 5303 6326 #endif 5304 6327 5305 /* Define offsetof for those systems which lack it. */5306 5307 #ifndef offsetof5308 # define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)5309 #endif5310 5311 6328 /* FIXME: this is kinda wrong, but it's what gdb wants. */ 5312 6329 … … 5324 6341 overwrite it. */ 5325 6342 5326 static b oolean6343 static bfd_boolean 5327 6344 elfcore_maybe_make_sect (abfd, name, sect) 5328 6345 bfd *abfd; … … 5333 6350 5334 6351 if (bfd_get_section_by_name (abfd, name) != NULL) 5335 return true;6352 return TRUE; 5336 6353 5337 6354 sect2 = bfd_make_section (abfd, name); 5338 6355 if (sect2 == NULL) 5339 return false;6356 return FALSE; 5340 6357 5341 6358 sect2->_raw_size = sect->_raw_size; … … 5343 6360 sect2->flags = sect->flags; 5344 6361 sect2->alignment_power = sect->alignment_power; 5345 return true; 6362 return TRUE; 6363 } 6364 6365 /* Create a pseudosection containing SIZE bytes at FILEPOS. This 6366 actually creates up to two pseudosections: 6367 - For the single-threaded case, a section named NAME, unless 6368 such a section already exists. 6369 - For the multi-threaded case, a section named "NAME/PID", where 6370 PID is elfcore_make_pid (abfd). 6371 Both pseudosections have identical contents. */ 6372 bfd_boolean 6373 _bfd_elfcore_make_pseudosection (abfd, name, size, filepos) 6374 bfd *abfd; 6375 char *name; 6376 size_t size; 6377 ufile_ptr filepos; 6378 { 6379 char buf[100]; 6380 char *threaded_name; 6381 size_t len; 6382 asection *sect; 6383 6384 /* Build the section name. */ 6385 6386 sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd)); 6387 len = strlen (buf) + 1; 6388 threaded_name = bfd_alloc (abfd, (bfd_size_type) len); 6389 if (threaded_name == NULL) 6390 return FALSE; 6391 memcpy (threaded_name, buf, len); 6392 6393 sect = bfd_make_section (abfd, threaded_name); 6394 if (sect == NULL) 6395 return FALSE; 6396 sect->_raw_size = size; 6397 sect->filepos = filepos; 6398 sect->flags = SEC_HAS_CONTENTS; 6399 sect->alignment_power = 2; 6400 6401 return elfcore_maybe_make_sect (abfd, name, sect); 5346 6402 } 5347 6403 … … 5353 6409 5354 6410 #if defined (HAVE_PRSTATUS_T) 5355 static boolean 6411 static bfd_boolean elfcore_grok_prstatus 6412 PARAMS ((bfd *, Elf_Internal_Note *)); 6413 6414 static bfd_boolean 5356 6415 elfcore_grok_prstatus (abfd, note) 5357 6416 bfd *abfd; 5358 6417 Elf_Internal_Note *note; 5359 6418 { 5360 char buf[100]; 5361 char *name; 5362 asection *sect; 5363 int raw_size; 6419 size_t raw_size; 5364 6420 int offset; 5365 6421 … … 5372 6428 memcpy (&prstat, note->descdata, sizeof (prstat)); 5373 6429 5374 elf_tdata (abfd)->core_signal = prstat.pr_cursig; 6430 /* Do not overwrite the core signal if it 6431 has already been set by another thread. */ 6432 if (elf_tdata (abfd)->core_signal == 0) 6433 elf_tdata (abfd)->core_signal = prstat.pr_cursig; 5375 6434 elf_tdata (abfd)->core_pid = prstat.pr_pid; 5376 6435 … … 5395 6454 memcpy (&prstat, note->descdata, sizeof (prstat)); 5396 6455 5397 elf_tdata (abfd)->core_signal = prstat.pr_cursig; 6456 /* Do not overwrite the core signal if it 6457 has already been set by another thread. */ 6458 if (elf_tdata (abfd)->core_signal == 0) 6459 elf_tdata (abfd)->core_signal = prstat.pr_cursig; 5398 6460 elf_tdata (abfd)->core_pid = prstat.pr_pid; 5399 6461 … … 5413 6475 /* Fail - we don't know how to handle any other 5414 6476 note size (ie. data object type). */ 5415 return true; 5416 } 5417 5418 /* Make a ".reg/999" section. */ 5419 5420 sprintf (buf, ".reg/%d", elfcore_make_pid (abfd)); 5421 name = bfd_alloc (abfd, strlen (buf) + 1); 5422 if (name == NULL) 5423 return false; 5424 strcpy (name, buf); 5425 5426 sect = bfd_make_section (abfd, name); 5427 if (sect == NULL) 5428 return false; 5429 5430 sect->_raw_size = raw_size; 5431 sect->filepos = note->descpos + offset; 5432 5433 sect->flags = SEC_HAS_CONTENTS; 5434 sect->alignment_power = 2; 5435 5436 if (! elfcore_maybe_make_sect (abfd, ".reg", sect)) 5437 return false; 5438 5439 return true; 6477 return TRUE; 6478 } 6479 6480 /* Make a ".reg/999" section and a ".reg" section. */ 6481 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 6482 raw_size, note->descpos + offset); 5440 6483 } 5441 6484 #endif /* defined (HAVE_PRSTATUS_T) */ 5442 6485 5443 /* Create a pseudosection containing the exact contents of NOTE. This 5444 actually creates up to two pseudosections: 5445 - For the single-threaded case, a section named NAME, unless 5446 such a section already exists. 5447 - For the multi-threaded case, a section named "NAME/PID", where 5448 PID is elfcore_make_pid (abfd). 5449 Both pseudosections have identical contents: the contents of NOTE. */ 5450 5451 static boolean 6486 /* Create a pseudosection containing the exact contents of NOTE. */ 6487 static bfd_boolean 5452 6488 elfcore_make_note_pseudosection (abfd, name, note) 5453 6489 bfd *abfd; … … 5455 6491 Elf_Internal_Note *note; 5456 6492 { 5457 char buf[100]; 5458 char *threaded_name; 5459 asection *sect; 5460 5461 /* Build the section name. */ 5462 5463 sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd)); 5464 threaded_name = bfd_alloc (abfd, strlen (buf) + 1); 5465 if (threaded_name == NULL) 5466 return false; 5467 strcpy (threaded_name, buf); 5468 5469 sect = bfd_make_section (abfd, threaded_name); 5470 if (sect == NULL) 5471 return false; 5472 sect->_raw_size = note->descsz; 5473 sect->filepos = note->descpos; 5474 sect->flags = SEC_HAS_CONTENTS; 5475 sect->alignment_power = 2; 5476 5477 if (! elfcore_maybe_make_sect (abfd, name, sect)) 5478 return false; 5479 5480 return true; 6493 return _bfd_elfcore_make_pseudosection (abfd, name, 6494 note->descsz, note->descpos); 5481 6495 } 5482 6496 … … 5485 6499 data structure apart. */ 5486 6500 5487 static b oolean6501 static bfd_boolean 5488 6502 elfcore_grok_prfpreg (abfd, note) 5489 6503 bfd *abfd; … … 5497 6511 literally. */ 5498 6512 5499 static b oolean6513 static bfd_boolean 5500 6514 elfcore_grok_prxfpreg (abfd, note) 5501 6515 bfd *abfd; … … 5519 6533 #endif 5520 6534 5521 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)5522 5523 6535 /* return a malloc'ed copy of a string at START which is at 5524 6536 most MAX bytes long, possibly without a terminating '\0'. 5525 6537 the copy will always have a terminating '\0'. */ 5526 6538 5527 static char*5528 elfcore_strndup (abfd, start, max)6539 char * 6540 _bfd_elfcore_strndup (abfd, start, max) 5529 6541 bfd *abfd; 5530 6542 char *start; 5531 int max;5532 { 5533 char *dup ;6543 size_t max; 6544 { 6545 char *dups; 5534 6546 char *end = memchr (start, '\0', max); 5535 int len;6547 size_t len; 5536 6548 5537 6549 if (end == NULL) … … 5540 6552 len = end - start; 5541 6553 5542 dup = bfd_alloc (abfd,len + 1);5543 if (dup == NULL)6554 dups = bfd_alloc (abfd, (bfd_size_type) len + 1); 6555 if (dups == NULL) 5544 6556 return NULL; 5545 6557 5546 memcpy (dup, start, len); 5547 dup[len] = '\0'; 5548 5549 return dup; 5550 } 5551 5552 static boolean 6558 memcpy (dups, start, len); 6559 dups[len] = '\0'; 6560 6561 return dups; 6562 } 6563 6564 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) 6565 static bfd_boolean elfcore_grok_psinfo 6566 PARAMS ((bfd *, Elf_Internal_Note *)); 6567 6568 static bfd_boolean 5553 6569 elfcore_grok_psinfo (abfd, note) 5554 6570 bfd *abfd; … … 5562 6578 5563 6579 elf_tdata (abfd)->core_program 5564 = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); 6580 = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, 6581 sizeof (psinfo.pr_fname)); 5565 6582 5566 6583 elf_tdata (abfd)->core_command 5567 = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); 6584 = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, 6585 sizeof (psinfo.pr_psargs)); 5568 6586 } 5569 6587 #if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T) … … 5576 6594 5577 6595 elf_tdata (abfd)->core_program 5578 = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); 6596 = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, 6597 sizeof (psinfo.pr_fname)); 5579 6598 5580 6599 elf_tdata (abfd)->core_command 5581 = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); 6600 = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, 6601 sizeof (psinfo.pr_psargs)); 5582 6602 } 5583 6603 #endif … … 5587 6607 /* Fail - we don't know how to handle any other 5588 6608 note size (ie. data object type). */ 5589 return true;6609 return TRUE; 5590 6610 } 5591 6611 … … 5602 6622 } 5603 6623 5604 return true;6624 return TRUE; 5605 6625 } 5606 6626 #endif /* defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) */ 5607 6627 5608 6628 #if defined (HAVE_PSTATUS_T) 5609 static boolean 6629 static bfd_boolean elfcore_grok_pstatus 6630 PARAMS ((bfd *, Elf_Internal_Note *)); 6631 6632 static bfd_boolean 5610 6633 elfcore_grok_pstatus (abfd, note) 5611 6634 bfd *abfd; … … 5639 6662 NT_LWPSTATUS note, presumably. */ 5640 6663 5641 return true;6664 return TRUE; 5642 6665 } 5643 6666 #endif /* defined (HAVE_PSTATUS_T) */ 5644 6667 5645 6668 #if defined (HAVE_LWPSTATUS_T) 5646 static boolean 6669 static bfd_boolean elfcore_grok_lwpstatus 6670 PARAMS ((bfd *, Elf_Internal_Note *)); 6671 6672 static bfd_boolean 5647 6673 elfcore_grok_lwpstatus (abfd, note) 5648 6674 bfd *abfd; … … 5652 6678 char buf[100]; 5653 6679 char *name; 6680 size_t len; 5654 6681 asection *sect; 5655 6682 … … 5659 6686 #endif 5660 6687 ) 5661 return true;6688 return TRUE; 5662 6689 5663 6690 memcpy (&lwpstat, note->descdata, sizeof (lwpstat)); … … 5669 6696 5670 6697 sprintf (buf, ".reg/%d", elfcore_make_pid (abfd)); 5671 name = bfd_alloc (abfd, strlen (buf) + 1); 6698 len = strlen (buf) + 1; 6699 name = bfd_alloc (abfd, (bfd_size_type) len); 5672 6700 if (name == NULL) 5673 return false;5674 strcpy (name, buf);6701 return FALSE; 6702 memcpy (name, buf, len); 5675 6703 5676 6704 sect = bfd_make_section (abfd, name); 5677 6705 if (sect == NULL) 5678 return false;6706 return FALSE; 5679 6707 5680 6708 #if defined (HAVE_LWPSTATUS_T_PR_CONTEXT) … … 5693 6721 5694 6722 if (!elfcore_maybe_make_sect (abfd, ".reg", sect)) 5695 return false;6723 return FALSE; 5696 6724 5697 6725 /* Make a ".reg2/999" section */ 5698 6726 5699 6727 sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd)); 5700 name = bfd_alloc (abfd, strlen (buf) + 1); 6728 len = strlen (buf) + 1; 6729 name = bfd_alloc (abfd, (bfd_size_type) len); 5701 6730 if (name == NULL) 5702 return false;5703 strcpy (name, buf);6731 return FALSE; 6732 memcpy (name, buf, len); 5704 6733 5705 6734 sect = bfd_make_section (abfd, name); 5706 6735 if (sect == NULL) 5707 return false;6736 return FALSE; 5708 6737 5709 6738 #if defined (HAVE_LWPSTATUS_T_PR_CONTEXT) … … 5721 6750 sect->alignment_power = 2; 5722 6751 5723 if (!elfcore_maybe_make_sect (abfd, ".reg2", sect)) 5724 return false; 5725 5726 return true; 6752 return elfcore_maybe_make_sect (abfd, ".reg2", sect); 5727 6753 } 5728 6754 #endif /* defined (HAVE_LWPSTATUS_T) */ 5729 6755 5730 6756 #if defined (HAVE_WIN32_PSTATUS_T) 5731 static b oolean6757 static bfd_boolean 5732 6758 elfcore_grok_win32pstatus (abfd, note) 5733 6759 bfd *abfd; … … 5736 6762 char buf[30]; 5737 6763 char *name; 6764 size_t len; 5738 6765 asection *sect; 5739 6766 win32_pstatus_t pstatus; 5740 6767 5741 6768 if (note->descsz < sizeof (pstatus)) 5742 return true;5743 5744 memcpy (&pstatus, note->descdata, note->descsz);6769 return TRUE; 6770 6771 memcpy (&pstatus, note->descdata, sizeof (pstatus)); 5745 6772 5746 6773 switch (pstatus.data_type) … … 5756 6783 sprintf (buf, ".reg/%d", pstatus.data.thread_info.tid); 5757 6784 5758 name = bfd_alloc (abfd, strlen (buf) + 1); 6785 len = strlen (buf) + 1; 6786 name = bfd_alloc (abfd, (bfd_size_type) len); 5759 6787 if (name == NULL) 5760 return false;5761 5762 strcpy (name, buf);6788 return FALSE; 6789 6790 memcpy (name, buf, len); 5763 6791 5764 6792 sect = bfd_make_section (abfd, name); 5765 6793 if (sect == NULL) 5766 return false;6794 return FALSE; 5767 6795 5768 6796 sect->_raw_size = sizeof (pstatus.data.thread_info.thread_context); 5769 sect->filepos = note->descpos + offsetof (struct win32_pstatus, 5770 data.thread_info.thread_context); 6797 sect->filepos = (note->descpos 6798 + offsetof (struct win32_pstatus, 6799 data.thread_info.thread_context)); 5771 6800 sect->flags = SEC_HAS_CONTENTS; 5772 6801 sect->alignment_power = 2; … … 5774 6803 if (pstatus.data.thread_info.is_active_thread) 5775 6804 if (! elfcore_maybe_make_sect (abfd, ".reg", sect)) 5776 return false;6805 return FALSE; 5777 6806 break; 5778 6807 … … 5781 6810 sprintf (buf, ".module/%08x", pstatus.data.module_info.base_address); 5782 6811 5783 name = bfd_alloc (abfd, strlen (buf) + 1); 6812 len = strlen (buf) + 1; 6813 name = bfd_alloc (abfd, (bfd_size_type) len); 5784 6814 if (name == NULL) 5785 return false;5786 5787 strcpy (name, buf);6815 return FALSE; 6816 6817 memcpy (name, buf, len); 5788 6818 5789 6819 sect = bfd_make_section (abfd, name); 5790 6820 5791 6821 if (sect == NULL) 5792 return false;6822 return FALSE; 5793 6823 5794 6824 sect->_raw_size = note->descsz; … … 5799 6829 5800 6830 default: 5801 return true;5802 } 5803 5804 return true;6831 return TRUE; 6832 } 6833 6834 return TRUE; 5805 6835 } 5806 6836 #endif /* HAVE_WIN32_PSTATUS_T */ 5807 6837 5808 static b oolean6838 static bfd_boolean 5809 6839 elfcore_grok_note (abfd, note) 5810 6840 bfd *abfd; 5811 6841 Elf_Internal_Note *note; 5812 6842 { 6843 struct elf_backend_data *bed = get_elf_backend_data (abfd); 6844 5813 6845 switch (note->type) 5814 6846 { 5815 6847 default: 5816 return true; 5817 6848 return TRUE; 6849 6850 case NT_PRSTATUS: 6851 if (bed->elf_backend_grok_prstatus) 6852 if ((*bed->elf_backend_grok_prstatus) (abfd, note)) 6853 return TRUE; 5818 6854 #if defined (HAVE_PRSTATUS_T) 5819 case NT_PRSTATUS:5820 6855 return elfcore_grok_prstatus (abfd, note); 6856 #else 6857 return TRUE; 5821 6858 #endif 5822 6859 … … 5840 6877 5841 6878 case NT_PRXFPREG: /* Linux SSE extension */ 5842 if (note->namesz == 55843 && ! strcmp (note->namedata, "LINUX"))6879 if (note->namesz == 6 6880 && strcmp (note->namedata, "LINUX") == 0) 5844 6881 return elfcore_grok_prxfpreg (abfd, note); 5845 6882 else 5846 return true; 5847 5848 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) 6883 return TRUE; 6884 5849 6885 case NT_PRPSINFO: 5850 6886 case NT_PSINFO: 6887 if (bed->elf_backend_grok_psinfo) 6888 if ((*bed->elf_backend_grok_psinfo) (abfd, note)) 6889 return TRUE; 6890 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) 5851 6891 return elfcore_grok_psinfo (abfd, note); 6892 #else 6893 return TRUE; 5852 6894 #endif 5853 6895 } 5854 6896 } 5855 6897 5856 static boolean 6898 static bfd_boolean 6899 elfcore_netbsd_get_lwpid (note, lwpidp) 6900 Elf_Internal_Note *note; 6901 int *lwpidp; 6902 { 6903 char *cp; 6904 6905 cp = strchr (note->namedata, '@'); 6906 if (cp != NULL) 6907 { 6908 *lwpidp = atoi(cp + 1); 6909 return TRUE; 6910 } 6911 return FALSE; 6912 } 6913 6914 static bfd_boolean 6915 elfcore_grok_netbsd_procinfo (abfd, note) 6916 bfd *abfd; 6917 Elf_Internal_Note *note; 6918 { 6919 6920 /* Signal number at offset 0x08. */ 6921 elf_tdata (abfd)->core_signal 6922 = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x08); 6923 6924 /* Process ID at offset 0x50. */ 6925 elf_tdata (abfd)->core_pid 6926 = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x50); 6927 6928 /* Command name at 0x7c (max 32 bytes, including nul). */ 6929 elf_tdata (abfd)->core_command 6930 = _bfd_elfcore_strndup (abfd, note->descdata + 0x7c, 31); 6931 6932 return TRUE; 6933 } 6934 6935 static bfd_boolean 6936 elfcore_grok_netbsd_note (abfd, note) 6937 bfd *abfd; 6938 Elf_Internal_Note *note; 6939 { 6940 int lwp; 6941 6942 if (elfcore_netbsd_get_lwpid (note, &lwp)) 6943 elf_tdata (abfd)->core_lwpid = lwp; 6944 6945 if (note->type == NT_NETBSDCORE_PROCINFO) 6946 { 6947 /* NetBSD-specific core "procinfo". Note that we expect to 6948 find this note before any of the others, which is fine, 6949 since the kernel writes this note out first when it 6950 creates a core file. */ 6951 6952 return elfcore_grok_netbsd_procinfo (abfd, note); 6953 } 6954 6955 /* As of Jan 2002 there are no other machine-independent notes 6956 defined for NetBSD core files. If the note type is less 6957 than the start of the machine-dependent note types, we don't 6958 understand it. */ 6959 6960 if (note->type < NT_NETBSDCORE_FIRSTMACH) 6961 return TRUE; 6962 6963 6964 switch (bfd_get_arch (abfd)) 6965 { 6966 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 and 6967 PT_GETFPREGS == mach+2. */ 6968 6969 case bfd_arch_alpha: 6970 case bfd_arch_sparc: 6971 switch (note->type) 6972 { 6973 case NT_NETBSDCORE_FIRSTMACH+0: 6974 return elfcore_make_note_pseudosection (abfd, ".reg", note); 6975 6976 case NT_NETBSDCORE_FIRSTMACH+2: 6977 return elfcore_make_note_pseudosection (abfd, ".reg2", note); 6978 6979 default: 6980 return TRUE; 6981 } 6982 6983 /* On all other arch's, PT_GETREGS == mach+1 and 6984 PT_GETFPREGS == mach+3. */ 6985 6986 default: 6987 switch (note->type) 6988 { 6989 case NT_NETBSDCORE_FIRSTMACH+1: 6990 return elfcore_make_note_pseudosection (abfd, ".reg", note); 6991 6992 case NT_NETBSDCORE_FIRSTMACH+3: 6993 return elfcore_make_note_pseudosection (abfd, ".reg2", note); 6994 6995 default: 6996 return TRUE; 6997 } 6998 } 6999 /* NOTREACHED */ 7000 } 7001 7002 static bfd_boolean 7003 elfcore_grok_nto_status (abfd, note, tid) 7004 bfd *abfd; 7005 Elf_Internal_Note *note; 7006 pid_t *tid; 7007 { 7008 void *ddata = note->descdata; 7009 char buf[100]; 7010 char *name; 7011 asection *sect; 7012 7013 /* nto_procfs_status 'pid' field is at offset 0. */ 7014 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, (bfd_byte *) ddata); 7015 7016 /* nto_procfs_status 'tid' field is at offset 4. */ 7017 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, (bfd_byte *) ddata + 4); 7018 7019 /* nto_procfs_status 'what' field is at offset 14. */ 7020 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, (bfd_byte *) ddata + 14); 7021 7022 /* Pass tid back. */ 7023 *tid = elf_tdata (abfd)->core_lwpid; 7024 7025 /* Make a ".qnx_core_status/%d" section. */ 7026 sprintf (buf, ".qnx_core_status/%d", *tid); 7027 7028 name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); 7029 if (name == NULL) 7030 return FALSE; 7031 strcpy (name, buf); 7032 7033 sect = bfd_make_section (abfd, name); 7034 if (sect == NULL) 7035 return FALSE; 7036 7037 sect->_raw_size = note->descsz; 7038 sect->filepos = note->descpos; 7039 sect->flags = SEC_HAS_CONTENTS; 7040 sect->alignment_power = 2; 7041 7042 return (elfcore_maybe_make_sect (abfd, ".qnx_core_status", sect)); 7043 } 7044 7045 static bfd_boolean 7046 elfcore_grok_nto_gregs (abfd, note, tid) 7047 bfd *abfd; 7048 Elf_Internal_Note *note; 7049 pid_t tid; 7050 { 7051 char buf[100]; 7052 char *name; 7053 asection *sect; 7054 7055 /* Make a ".reg/%d" section. */ 7056 sprintf (buf, ".reg/%d", tid); 7057 7058 name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); 7059 if (name == NULL) 7060 return FALSE; 7061 strcpy (name, buf); 7062 7063 sect = bfd_make_section (abfd, name); 7064 if (sect == NULL) 7065 return FALSE; 7066 7067 sect->_raw_size = note->descsz; 7068 sect->filepos = note->descpos; 7069 sect->flags = SEC_HAS_CONTENTS; 7070 sect->alignment_power = 2; 7071 7072 return elfcore_maybe_make_sect (abfd, ".reg", sect); 7073 } 7074 7075 #define BFD_QNT_CORE_INFO 7 7076 #define BFD_QNT_CORE_STATUS 8 7077 #define BFD_QNT_CORE_GREG 9 7078 #define BFD_QNT_CORE_FPREG 10 7079 7080 static bfd_boolean 7081 elfcore_grok_nto_note (abfd, note) 7082 bfd *abfd; 7083 Elf_Internal_Note *note; 7084 { 7085 /* Every GREG section has a STATUS section before it. Store the 7086 tid from the previous call to pass down to the next gregs 7087 function. */ 7088 static pid_t tid = 1; 7089 7090 switch (note->type) 7091 { 7092 case BFD_QNT_CORE_INFO: return elfcore_make_note_pseudosection (abfd, ".qnx_core_info", note); 7093 case BFD_QNT_CORE_STATUS: return elfcore_grok_nto_status (abfd, note, &tid); 7094 case BFD_QNT_CORE_GREG: return elfcore_grok_nto_gregs (abfd, note, tid); 7095 case BFD_QNT_CORE_FPREG: return elfcore_grok_prfpreg (abfd, note); 7096 default: return TRUE; 7097 } 7098 } 7099 7100 /* Function: elfcore_write_note 7101 7102 Inputs: 7103 buffer to hold note 7104 name of note 7105 type of note 7106 data for note 7107 size of data for note 7108 7109 Return: 7110 End of buffer containing note. */ 7111 7112 char * 7113 elfcore_write_note (abfd, buf, bufsiz, name, type, input, size) 7114 bfd *abfd; 7115 char *buf; 7116 int *bufsiz; 7117 const char *name; 7118 int type; 7119 const PTR input; 7120 int size; 7121 { 7122 Elf_External_Note *xnp; 7123 size_t namesz; 7124 size_t pad; 7125 size_t newspace; 7126 char *p, *dest; 7127 7128 namesz = 0; 7129 pad = 0; 7130 if (name != NULL) 7131 { 7132 struct elf_backend_data *bed; 7133 7134 namesz = strlen (name) + 1; 7135 bed = get_elf_backend_data (abfd); 7136 pad = -namesz & (bed->s->file_align - 1); 7137 } 7138 7139 newspace = sizeof (Elf_External_Note) - 1 + namesz + pad + size; 7140 7141 p = realloc (buf, *bufsiz + newspace); 7142 dest = p + *bufsiz; 7143 *bufsiz += newspace; 7144 xnp = (Elf_External_Note *) dest; 7145 H_PUT_32 (abfd, namesz, xnp->namesz); 7146 H_PUT_32 (abfd, size, xnp->descsz); 7147 H_PUT_32 (abfd, type, xnp->type); 7148 dest = xnp->name; 7149 if (name != NULL) 7150 { 7151 memcpy (dest, name, namesz); 7152 dest += namesz; 7153 while (pad != 0) 7154 { 7155 *dest++ = '\0'; 7156 --pad; 7157 } 7158 } 7159 memcpy (dest, input, size); 7160 return p; 7161 } 7162 7163 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) 7164 char * 7165 elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs) 7166 bfd *abfd; 7167 char *buf; 7168 int *bufsiz; 7169 const char *fname; 7170 const char *psargs; 7171 { 7172 int note_type; 7173 char *note_name = "CORE"; 7174 7175 #if defined (HAVE_PSINFO_T) 7176 psinfo_t data; 7177 note_type = NT_PSINFO; 7178 #else 7179 prpsinfo_t data; 7180 note_type = NT_PRPSINFO; 7181 #endif 7182 7183 memset (&data, 0, sizeof (data)); 7184 strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); 7185 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); 7186 return elfcore_write_note (abfd, buf, bufsiz, 7187 note_name, note_type, &data, sizeof (data)); 7188 } 7189 #endif /* PSINFO_T or PRPSINFO_T */ 7190 7191 #if defined (HAVE_PRSTATUS_T) 7192 char * 7193 elfcore_write_prstatus (abfd, buf, bufsiz, pid, cursig, gregs) 7194 bfd *abfd; 7195 char *buf; 7196 int *bufsiz; 7197 long pid; 7198 int cursig; 7199 const PTR gregs; 7200 { 7201 prstatus_t prstat; 7202 char *note_name = "CORE"; 7203 7204 memset (&prstat, 0, sizeof (prstat)); 7205 prstat.pr_pid = pid; 7206 prstat.pr_cursig = cursig; 7207 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); 7208 return elfcore_write_note (abfd, buf, bufsiz, 7209 note_name, NT_PRSTATUS, &prstat, sizeof (prstat)); 7210 } 7211 #endif /* HAVE_PRSTATUS_T */ 7212 7213 #if defined (HAVE_LWPSTATUS_T) 7214 char * 7215 elfcore_write_lwpstatus (abfd, buf, bufsiz, pid, cursig, gregs) 7216 bfd *abfd; 7217 char *buf; 7218 int *bufsiz; 7219 long pid; 7220 int cursig; 7221 const PTR gregs; 7222 { 7223 lwpstatus_t lwpstat; 7224 char *note_name = "CORE"; 7225 7226 memset (&lwpstat, 0, sizeof (lwpstat)); 7227 lwpstat.pr_lwpid = pid >> 16; 7228 lwpstat.pr_cursig = cursig; 7229 #if defined (HAVE_LWPSTATUS_T_PR_REG) 7230 memcpy (lwpstat.pr_reg, gregs, sizeof (lwpstat.pr_reg)); 7231 #elif defined (HAVE_LWPSTATUS_T_PR_CONTEXT) 7232 #if !defined(gregs) 7233 memcpy (lwpstat.pr_context.uc_mcontext.gregs, 7234 gregs, sizeof (lwpstat.pr_context.uc_mcontext.gregs)); 7235 #else 7236 memcpy (lwpstat.pr_context.uc_mcontext.__gregs, 7237 gregs, sizeof (lwpstat.pr_context.uc_mcontext.__gregs)); 7238 #endif 7239 #endif 7240 return elfcore_write_note (abfd, buf, bufsiz, note_name, 7241 NT_LWPSTATUS, &lwpstat, sizeof (lwpstat)); 7242 } 7243 #endif /* HAVE_LWPSTATUS_T */ 7244 7245 #if defined (HAVE_PSTATUS_T) 7246 char * 7247 elfcore_write_pstatus (abfd, buf, bufsiz, pid, cursig, gregs) 7248 bfd *abfd; 7249 char *buf; 7250 int *bufsiz; 7251 long pid; 7252 int cursig; 7253 const PTR gregs; 7254 { 7255 pstatus_t pstat; 7256 char *note_name = "CORE"; 7257 7258 memset (&pstat, 0, sizeof (pstat)); 7259 pstat.pr_pid = pid & 0xffff; 7260 buf = elfcore_write_note (abfd, buf, bufsiz, note_name, 7261 NT_PSTATUS, &pstat, sizeof (pstat)); 7262 return buf; 7263 } 7264 #endif /* HAVE_PSTATUS_T */ 7265 7266 char * 7267 elfcore_write_prfpreg (abfd, buf, bufsiz, fpregs, size) 7268 bfd *abfd; 7269 char *buf; 7270 int *bufsiz; 7271 const PTR fpregs; 7272 int size; 7273 { 7274 char *note_name = "CORE"; 7275 return elfcore_write_note (abfd, buf, bufsiz, 7276 note_name, NT_FPREGSET, fpregs, size); 7277 } 7278 7279 char * 7280 elfcore_write_prxfpreg (abfd, buf, bufsiz, xfpregs, size) 7281 bfd *abfd; 7282 char *buf; 7283 int *bufsiz; 7284 const PTR xfpregs; 7285 int size; 7286 { 7287 char *note_name = "LINUX"; 7288 return elfcore_write_note (abfd, buf, bufsiz, 7289 note_name, NT_PRXFPREG, xfpregs, size); 7290 } 7291 7292 static bfd_boolean 5857 7293 elfcore_read_notes (abfd, offset, size) 5858 7294 bfd *abfd; 5859 bfd_vmaoffset;5860 bfd_ vmasize;7295 file_ptr offset; 7296 bfd_size_type size; 5861 7297 { 5862 7298 char *buf; … … 5864 7300 5865 7301 if (size <= 0) 5866 return true;5867 5868 if (bfd_seek (abfd, offset, SEEK_SET) == -1)5869 return false;5870 5871 buf = bfd_malloc ( (size_t)size);7302 return TRUE; 7303 7304 if (bfd_seek (abfd, offset, SEEK_SET) != 0) 7305 return FALSE; 7306 7307 buf = bfd_malloc (size); 5872 7308 if (buf == NULL) 5873 return false;5874 5875 if (bfd_ read (buf, size, 1, abfd) != size)7309 return FALSE; 7310 7311 if (bfd_bread (buf, size, abfd) != size) 5876 7312 { 5877 7313 error: 5878 7314 free (buf); 5879 return false;7315 return FALSE; 5880 7316 } 5881 7317 … … 5887 7323 Elf_Internal_Note in; 5888 7324 5889 in.type = bfd_h_get_32 (abfd, (bfd_byte *)xnp->type);5890 5891 in.namesz = bfd_h_get_32 (abfd, (bfd_byte *)xnp->namesz);7325 in.type = H_GET_32 (abfd, xnp->type); 7326 7327 in.namesz = H_GET_32 (abfd, xnp->namesz); 5892 7328 in.namedata = xnp->name; 5893 7329 5894 in.descsz = bfd_h_get_32 (abfd, (bfd_byte *)xnp->descsz);7330 in.descsz = H_GET_32 (abfd, xnp->descsz); 5895 7331 in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4); 5896 7332 in.descpos = offset + (in.descdata - buf); 5897 7333 5898 if (! elfcore_grok_note (abfd, &in)) 5899 goto error; 7334 if (strncmp (in.namedata, "NetBSD-CORE", 11) == 0) 7335 { 7336 if (! elfcore_grok_netbsd_note (abfd, &in)) 7337 goto error; 7338 } 7339 else if (strncmp (in.namedata, "QNX", 3) == 0) 7340 { 7341 if (! elfcore_grok_nto_note (abfd, &in)) 7342 goto error; 7343 } 7344 else 7345 { 7346 if (! elfcore_grok_note (abfd, &in)) 7347 goto error; 7348 } 5900 7349 5901 7350 p = in.descdata + BFD_ALIGN (in.descsz, 4); … … 5903 7352 5904 7353 free (buf); 5905 return true; 5906 } 5907 5908 /* FIXME: This function is now unnecessary. Callers can just call 5909 bfd_section_from_phdr directly. */ 5910 5911 boolean 5912 _bfd_elfcore_section_from_phdr (abfd, phdr, sec_num) 5913 bfd *abfd; 5914 Elf_Internal_Phdr* phdr; 5915 int sec_num; 5916 { 5917 if (! bfd_section_from_phdr (abfd, phdr, sec_num)) 5918 return false; 5919 5920 return true; 7354 return TRUE; 5921 7355 } 5922 7356 … … 5938 7372 } 5939 7373 5940 return (elf_elfheader (abfd)->e_phnum 5941 * sizeof (Elf_Internal_Phdr)); 7374 return elf_elfheader (abfd)->e_phnum * sizeof (Elf_Internal_Phdr); 5942 7375 } 5943 7376 … … 5969 7402 return num_phdrs; 5970 7403 } 7404 7405 void 7406 _bfd_elf_sprintf_vma (abfd, buf, value) 7407 bfd *abfd ATTRIBUTE_UNUSED; 7408 char *buf; 7409 bfd_vma value; 7410 { 7411 #ifdef BFD64 7412 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ 7413 7414 i_ehdrp = elf_elfheader (abfd); 7415 if (i_ehdrp == NULL) 7416 sprintf_vma (buf, value); 7417 else 7418 { 7419 if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64) 7420 { 7421 #if BFD_HOST_64BIT_LONG 7422 sprintf (buf, "%016lx", value); 7423 #else 7424 sprintf (buf, "%08lx%08lx", _bfd_int64_high (value), 7425 _bfd_int64_low (value)); 7426 #endif 7427 } 7428 else 7429 sprintf (buf, "%08lx", (unsigned long) (value & 0xffffffff)); 7430 } 7431 #else 7432 sprintf_vma (buf, value); 7433 #endif 7434 } 7435 7436 void 7437 _bfd_elf_fprintf_vma (abfd, stream, value) 7438 bfd *abfd ATTRIBUTE_UNUSED; 7439 PTR stream; 7440 bfd_vma value; 7441 { 7442 #ifdef BFD64 7443 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ 7444 7445 i_ehdrp = elf_elfheader (abfd); 7446 if (i_ehdrp == NULL) 7447 fprintf_vma ((FILE *) stream, value); 7448 else 7449 { 7450 if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64) 7451 { 7452 #if BFD_HOST_64BIT_LONG 7453 fprintf ((FILE *) stream, "%016lx", value); 7454 #else 7455 fprintf ((FILE *) stream, "%08lx%08lx", 7456 _bfd_int64_high (value), _bfd_int64_low (value)); 7457 #endif 7458 } 7459 else 7460 fprintf ((FILE *) stream, "%08lx", 7461 (unsigned long) (value & 0xffffffff)); 7462 } 7463 #else 7464 fprintf_vma ((FILE *) stream, value); 7465 #endif 7466 } 7467 7468 enum elf_reloc_type_class 7469 _bfd_elf_reloc_type_class (rela) 7470 const Elf_Internal_Rela *rela ATTRIBUTE_UNUSED; 7471 { 7472 return reloc_class_normal; 7473 } 7474 7475 /* For RELA architectures, return the relocation value for a 7476 relocation against a local symbol. */ 7477 7478 bfd_vma 7479 _bfd_elf_rela_local_sym (abfd, sym, sec, rel) 7480 bfd *abfd; 7481 Elf_Internal_Sym *sym; 7482 asection *sec; 7483 Elf_Internal_Rela *rel; 7484 { 7485 bfd_vma relocation; 7486 7487 relocation = (sec->output_section->vma 7488 + sec->output_offset 7489 + sym->st_value); 7490 if ((sec->flags & SEC_MERGE) 7491 && ELF_ST_TYPE (sym->st_info) == STT_SECTION 7492 && sec->sec_info_type == ELF_INFO_TYPE_MERGE) 7493 { 7494 asection *msec; 7495 7496 msec = sec; 7497 rel->r_addend = 7498 _bfd_merged_section_offset (abfd, &msec, 7499 elf_section_data (sec)->sec_info, 7500 sym->st_value + rel->r_addend, 7501 (bfd_vma) 0) 7502 - relocation; 7503 rel->r_addend += msec->output_section->vma + msec->output_offset; 7504 } 7505 return relocation; 7506 } 7507 7508 bfd_vma 7509 _bfd_elf_rel_local_sym (abfd, sym, psec, addend) 7510 bfd *abfd; 7511 Elf_Internal_Sym *sym; 7512 asection **psec; 7513 bfd_vma addend; 7514 { 7515 asection *sec = *psec; 7516 7517 if (sec->sec_info_type != ELF_INFO_TYPE_MERGE) 7518 return sym->st_value + addend; 7519 7520 return _bfd_merged_section_offset (abfd, psec, 7521 elf_section_data (sec)->sec_info, 7522 sym->st_value + addend, (bfd_vma) 0); 7523 } 7524 7525 bfd_vma 7526 _bfd_elf_section_offset (abfd, info, sec, offset) 7527 bfd *abfd; 7528 struct bfd_link_info *info; 7529 asection *sec; 7530 bfd_vma offset; 7531 { 7532 struct bfd_elf_section_data *sec_data; 7533 7534 sec_data = elf_section_data (sec); 7535 switch (sec->sec_info_type) 7536 { 7537 case ELF_INFO_TYPE_STABS: 7538 return _bfd_stab_section_offset (abfd, 7539 &elf_hash_table (info)->merge_info, 7540 sec, &sec_data->sec_info, offset); 7541 case ELF_INFO_TYPE_EH_FRAME: 7542 return _bfd_elf_eh_frame_section_offset (abfd, sec, offset); 7543 default: 7544 return offset; 7545 } 7546 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.