Changeset 609 for branches/GNU/src/binutils/bfd/stabs.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/stabs.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Stabs in sections linking support. 2 Copyright 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. 2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 3 Free Software Foundation, Inc. 3 4 Written by Ian Lance Taylor, Cygnus Support. 4 5 … … 26 27 #include "libbfd.h" 27 28 #include "aout/stab_gnu.h" 28 29 #include <ctype.h> 29 #include "safe-ctype.h" 30 30 31 31 /* Stabs entries use a 12 byte format: … … 171 171 pass of the linker. */ 172 172 173 b oolean173 bfd_boolean 174 174 _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo) 175 175 bfd *abfd; … … 179 179 PTR *psecinfo; 180 180 { 181 b oolean first;181 bfd_boolean first; 182 182 struct stab_info *sinfo; 183 bfd_size_type count ;183 bfd_size_type count, amt; 184 184 struct stab_section_info *secinfo; 185 185 bfd_byte *stabbuf = NULL; … … 193 193 { 194 194 /* This file does not contain stabs debugging information. */ 195 return true;195 return TRUE; 196 196 } 197 197 … … 199 199 { 200 200 /* Something is wrong with the format of these stab symbols. 201 202 return true;201 Don't try to optimize them. */ 202 return TRUE; 203 203 } 204 204 … … 206 206 { 207 207 /* We shouldn't see relocations in the strings, and we aren't 208 209 return true;208 prepared to handle them. */ 209 return TRUE; 210 210 } 211 211 … … 216 216 { 217 217 /* At least one of the sections is being discarded from the 218 219 return true;220 } 221 222 first = false;218 link, so we should just ignore them. */ 219 return TRUE; 220 } 221 222 first = FALSE; 223 223 224 224 if (*psinfo == NULL) 225 225 { 226 226 /* Initialize the stabs information we need to keep track of. */ 227 first = true; 228 *psinfo = (PTR) bfd_alloc (abfd, sizeof (struct stab_info)); 227 first = TRUE; 228 amt = sizeof (struct stab_info); 229 *psinfo = (PTR) bfd_alloc (abfd, amt); 229 230 if (*psinfo == NULL) 230 231 goto error_return; … … 234 235 goto error_return; 235 236 /* Make sure the first byte is zero. */ 236 (void) _bfd_stringtab_add (sinfo->strings, "", true, true);237 (void) _bfd_stringtab_add (sinfo->strings, "", TRUE, TRUE); 237 238 if (! bfd_hash_table_init_n (&sinfo->includes.root, 238 239 stab_link_includes_newfunc, … … 250 251 count = stabsec->_raw_size / STABSIZE; 251 252 252 *psecinfo = bfd_alloc (abfd,253 (sizeof (struct stab_section_info) 254 + (count - 1) * sizeof (bfd_size_type)));253 amt = sizeof (struct stab_section_info); 254 amt += (count - 1) * sizeof (bfd_size_type); 255 *psecinfo = bfd_alloc (abfd, amt); 255 256 if (*psecinfo == NULL) 256 257 goto error_return; … … 259 260 secinfo->excls = NULL; 260 261 secinfo->cumulative_skips = NULL; 261 memset (secinfo->stridxs, 0, count * sizeof (bfd_size_type));262 memset (secinfo->stridxs, 0, (size_t) count * sizeof (bfd_size_type)); 262 263 263 264 /* Read the stabs information from abfd. */ … … 268 269 goto error_return; 269 270 270 if (! bfd_get_section_contents (abfd, stabsec, stabbuf, 0,271 if (! bfd_get_section_contents (abfd, stabsec, stabbuf, (bfd_vma) 0, 271 272 stabsec->_raw_size) 272 || ! bfd_get_section_contents (abfd, stabstrsec, stabstrbuf, 0,273 || ! bfd_get_section_contents (abfd, stabstrsec, stabstrbuf, (bfd_vma) 0, 273 274 stabstrsec->_raw_size)) 274 275 goto error_return; … … 286 287 sym += STABSIZE, ++pstridx) 287 288 { 289 bfd_size_type symstroff; 288 290 int type; 289 291 const char *string; … … 300 302 { 301 303 /* Special type 0 stabs indicate the offset to the next 302 304 string table. We only copy the very first one. */ 303 305 stroff = next_stroff; 304 306 next_stroff += bfd_get_32 (abfd, sym + 8); … … 309 311 continue; 310 312 } 311 first = false;313 first = FALSE; 312 314 } 313 315 314 316 /* Store the string in the hash table, and record the index. */ 315 string = ((char *) stabstrbuf 316 + stroff 317 + bfd_get_32 (abfd, sym + STRDXOFF)); 318 *pstridx = _bfd_stringtab_add (sinfo->strings, string, true, true); 317 symstroff = stroff + bfd_get_32 (abfd, sym + STRDXOFF); 318 if (symstroff >= stabstrsec->_raw_size) 319 { 320 (*_bfd_error_handler) 321 (_("%s(%s+0x%lx): Stabs entry has invalid string index."), 322 bfd_archive_filename (abfd), 323 bfd_get_section_name (abfd, stabsec), 324 (long) (sym - stabbuf)); 325 bfd_set_error (bfd_error_bad_value); 326 goto error_return; 327 } 328 string = (char *) stabstrbuf + symstroff; 329 *pstridx = _bfd_stringtab_add (sinfo->strings, string, TRUE, TRUE); 319 330 320 331 /* An N_BINCL symbol indicates the start of the stabs entries … … 323 334 symbol names, not including the file numbers in types (the 324 335 first number after an open parenthesis). */ 325 if (type == N_BINCL)336 if (type == (int) N_BINCL) 326 337 { 327 338 bfd_vma val; … … 343 354 if (incl_type == 0) 344 355 break; 345 else if (incl_type == N_EINCL)356 else if (incl_type == (int) N_EINCL) 346 357 { 347 358 if (nest == 0) … … 349 360 --nest; 350 361 } 351 else if (incl_type == N_BINCL)362 else if (incl_type == (int) N_BINCL) 352 363 ++nest; 353 364 else if (nest == 0) … … 365 376 /* Skip the file number. */ 366 377 ++str; 367 while ( isdigit ((unsigned char)*str))378 while (ISDIGIT (*str)) 368 379 ++str; 369 380 --str; … … 376 387 value, then replaced this one with an N_EXCL symbol. */ 377 388 incl_entry = stab_link_includes_lookup (&sinfo->includes, string, 378 true, true);389 TRUE, TRUE); 379 390 if (incl_entry == NULL) 380 391 goto error_return; … … 385 396 386 397 /* Record this symbol, so that we can set the value 387 correctly. */ 388 ne = (struct stab_excl_list *) bfd_alloc (abfd, sizeof *ne); 398 correctly. */ 399 amt = sizeof *ne; 400 ne = (struct stab_excl_list *) bfd_alloc (abfd, amt); 389 401 if (ne == NULL) 390 402 goto error_return; 391 403 ne->offset = sym - stabbuf; 392 404 ne->val = val; 393 ne->type = N_BINCL;405 ne->type = (int) N_BINCL; 394 406 ne->next = secinfo->excls; 395 407 secinfo->excls = ne; … … 413 425 /* We have seen this header file before. Tell the final 414 426 pass to change the type to N_EXCL. */ 415 ne->type = N_EXCL;427 ne->type = (int) N_EXCL; 416 428 417 429 /* Mark the skipped symbols. */ … … 426 438 incl_type = incl_sym[TYPEOFF]; 427 439 428 if (incl_type == N_EINCL)440 if (incl_type == (int) N_EINCL) 429 441 { 430 442 if (nest == 0) … … 436 448 --nest; 437 449 } 438 else if (incl_type == N_BINCL)450 else if (incl_type == (int) N_BINCL) 439 451 ++nest; 440 452 else if (nest == 0) … … 474 486 bfd_size_type *pskips; 475 487 476 secinfo->cumulative_skips =477 (bfd_size_type *) bfd_alloc (abfd, count * sizeof (bfd_size_type));488 amt = count * sizeof (bfd_size_type); 489 secinfo->cumulative_skips = (bfd_size_type *) bfd_alloc (abfd, amt); 478 490 if (secinfo->cumulative_skips == NULL) 479 491 goto error_return; … … 493 505 } 494 506 495 return true;507 return TRUE; 496 508 497 509 error_return: … … 500 512 if (stabstrbuf != NULL) 501 513 free (stabstrbuf); 502 return false; 514 return FALSE; 515 } 516 517 518 519 /* This function is called for each input file before the stab 520 section is relocated. It discards stab entries for discarded 521 functions and variables. The function returns TRUE iff 522 any entries have been deleted. 523 */ 524 525 bfd_boolean 526 _bfd_discard_section_stabs (abfd, stabsec, psecinfo, 527 reloc_symbol_deleted_p, cookie) 528 bfd *abfd; 529 asection *stabsec; 530 PTR psecinfo; 531 bfd_boolean (*reloc_symbol_deleted_p) PARAMS ((bfd_vma, PTR)); 532 PTR cookie; 533 { 534 bfd_size_type count, amt; 535 struct stab_section_info *secinfo; 536 bfd_byte *stabbuf = NULL; 537 bfd_byte *sym, *symend; 538 bfd_size_type skip; 539 bfd_size_type *pstridx; 540 int deleting; 541 542 if (stabsec->_raw_size == 0) 543 { 544 /* This file does not contain stabs debugging information. */ 545 return FALSE; 546 } 547 548 if (stabsec->_raw_size % STABSIZE != 0) 549 { 550 /* Something is wrong with the format of these stab symbols. 551 Don't try to optimize them. */ 552 return FALSE; 553 } 554 555 if ((stabsec->output_section != NULL 556 && bfd_is_abs_section (stabsec->output_section))) 557 { 558 /* At least one of the sections is being discarded from the 559 link, so we should just ignore them. */ 560 return FALSE; 561 } 562 563 /* We should have initialized our data in _bfd_link_stab_sections. 564 If there was some bizarre error reading the string sections, though, 565 we might not have. Bail rather than asserting. */ 566 if (psecinfo == NULL) 567 return FALSE; 568 569 count = stabsec->_raw_size / STABSIZE; 570 secinfo = (struct stab_section_info *) psecinfo; 571 572 /* Read the stabs information from abfd. */ 573 574 stabbuf = (bfd_byte *) bfd_malloc (stabsec->_raw_size); 575 if (stabbuf == NULL) 576 goto error_return; 577 578 if (! bfd_get_section_contents (abfd, stabsec, stabbuf, (bfd_vma) 0, 579 stabsec->_raw_size)) 580 goto error_return; 581 582 /* Look through the stabs symbols and discard any information for 583 discarded functions. */ 584 585 skip = 0; 586 deleting = -1; 587 588 symend = stabbuf + stabsec->_raw_size; 589 for (sym = stabbuf, pstridx = secinfo->stridxs; 590 sym < symend; 591 sym += STABSIZE, ++pstridx) 592 { 593 int type; 594 595 if (*pstridx == (bfd_size_type) -1) 596 { 597 /* This stab was deleted in a previous pass. */ 598 continue; 599 } 600 601 type = sym[TYPEOFF]; 602 603 if (type == (int) N_FUN) 604 { 605 int strx = bfd_get_32 (abfd, sym + STRDXOFF); 606 607 if (strx == 0) 608 { 609 if (deleting) 610 { 611 skip++; 612 *pstridx = -1; 613 } 614 deleting = -1; 615 continue; 616 } 617 deleting = 0; 618 if ((*reloc_symbol_deleted_p) (sym + VALOFF - stabbuf, cookie)) 619 deleting = 1; 620 } 621 622 if (deleting == 1) 623 { 624 *pstridx = -1; 625 skip++; 626 } 627 else if (deleting == -1) 628 { 629 /* Outside of a function. Check for deleted variables. */ 630 if (type == (int) N_STSYM || type == (int) N_LCSYM) 631 if ((*reloc_symbol_deleted_p) (sym + VALOFF - stabbuf, cookie)) 632 { 633 *pstridx = -1; 634 skip ++; 635 } 636 /* We should also check for N_GSYM entries which reference a 637 deleted global, but those are less harmful to debuggers 638 and would require parsing the stab strings. */ 639 } 640 } 641 642 free (stabbuf); 643 stabbuf = NULL; 644 645 /* Shrink the stabsec as needed. */ 646 stabsec->_cooked_size -= skip * STABSIZE; 647 if (stabsec->_cooked_size == 0) 648 stabsec->flags |= SEC_EXCLUDE; 649 650 /* Recalculate the `cumulative_skips' array now that stabs have been 651 deleted for this section. */ 652 653 if (skip != 0) 654 { 655 bfd_size_type i, offset; 656 bfd_size_type *pskips; 657 658 if (secinfo->cumulative_skips == NULL) 659 { 660 amt = count * sizeof (bfd_size_type); 661 secinfo->cumulative_skips = (bfd_size_type *) bfd_alloc (abfd, amt); 662 if (secinfo->cumulative_skips == NULL) 663 goto error_return; 664 } 665 666 pskips = secinfo->cumulative_skips; 667 pstridx = secinfo->stridxs; 668 offset = 0; 669 670 for (i = 0; i < count; i++, pskips++, pstridx++) 671 { 672 *pskips = offset; 673 if (*pstridx == (bfd_size_type) -1) 674 offset += STABSIZE; 675 } 676 677 BFD_ASSERT (offset != 0); 678 } 679 680 return skip > 0; 681 682 error_return: 683 if (stabbuf != NULL) 684 free (stabbuf); 685 return FALSE; 503 686 } 504 687 … … 506 689 contents. */ 507 690 508 b oolean691 bfd_boolean 509 692 _bfd_write_section_stabs (output_bfd, psinfo, stabsec, psecinfo, contents) 510 693 bfd *output_bfd; … … 525 708 if (secinfo == NULL) 526 709 return bfd_set_section_contents (output_bfd, stabsec->output_section, 527 contents, stabsec->output_offset, 710 contents, 711 (file_ptr) stabsec->output_offset, 528 712 stabsec->_raw_size); 529 713 … … 556 740 { 557 741 /* This is the header symbol for the stabs section. We 558 559 560 742 don't really need one, since we have merged all the 743 input stabs sections into one, but we generate one 744 for the benefit of readers which expect to see one. */ 561 745 BFD_ASSERT (sym == contents); 562 746 bfd_put_32 (output_bfd, _bfd_stringtab_size (sinfo->strings), … … 574 758 575 759 return bfd_set_section_contents (output_bfd, stabsec->output_section, 576 contents, stabsec->output_offset,760 contents, (file_ptr) stabsec->output_offset, 577 761 stabsec->_cooked_size); 578 762 } … … 580 764 /* Write out the .stabstr section. */ 581 765 582 b oolean766 bfd_boolean 583 767 _bfd_write_stab_strings (output_bfd, psinfo) 584 768 bfd *output_bfd; … … 590 774 591 775 if (sinfo == NULL) 592 return true;776 return TRUE; 593 777 594 778 if (bfd_is_abs_section (sinfo->stabstr->output_section)) 595 779 { 596 780 /* The section was discarded from the link. */ 597 return true;781 return TRUE; 598 782 } 599 783 … … 603 787 604 788 if (bfd_seek (output_bfd, 605 ( sinfo->stabstr->output_section->filepos606 + sinfo->stabstr->output_offset),789 (file_ptr) (sinfo->stabstr->output_section->filepos 790 + sinfo->stabstr->output_offset), 607 791 SEEK_SET) != 0) 608 return false;792 return FALSE; 609 793 610 794 if (! _bfd_stringtab_emit (output_bfd, sinfo->strings)) 611 return false;795 return FALSE; 612 796 613 797 /* We no longer need the stabs information. */ … … 615 799 bfd_hash_table_free (&sinfo->includes.root); 616 800 617 return true;801 return TRUE; 618 802 } 619 803 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.