Changeset 609 for branches/GNU/src/binutils/bfd/section.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/section.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Object file "section" support for the BFD library. 2 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 3 2000, 2001 3 2000, 2001, 2002, 2003 4 4 Free Software Foundation, Inc. 5 5 Written by Cygnus Support. … … 171 171 . {* The name of the section; the name isn't a copy, the pointer is 172 172 . the same as that passed to bfd_make_section. *} 173 .174 173 . const char *name; 175 174 . 176 175 . {* A unique sequence number. *} 177 .178 176 . int id; 179 177 . 180 . {* Which section is it; 0..nth. *} 181 . 178 . {* Which section in the bfd; 0..n-1 as sections are created in a bfd. *} 182 179 . int index; 183 180 . 184 181 . {* The next section in the list belonging to the BFD, or NULL. *} 185 .186 182 . struct sec *next; 187 183 . … … 189 185 . flags are read in from the object file, and some are 190 186 . synthesized from other information. *} 191 .192 187 . flagword flags; 193 188 . … … 206 201 .#define SEC_RELOC 0x004 207 202 . 208 .#if 0 {* Obsolete ? *} 209 .#define SEC_BALIGN 0x008 210 .#endif 203 . {* ELF reserves 4 processor specific bits and 8 operating system 204 . specific bits in sh_flags; at present we can get away with just 205 . one in communicating between the assembler and BFD, but this 206 . isn't a good long-term solution. *} 207 .#define SEC_ARCH_BIT_0 0x008 211 208 . 212 209 . {* A signal to the OS that the section contains read only data. *} … … 234 231 .#define SEC_CONSTRUCTOR 0x100 235 232 . 236 . {* The section is a constructor, and should be placed at the237 . end of the text, data, or bss section(?). *}238 .#define SEC_CONSTRUCTOR_TEXT 0x1100239 .#define SEC_CONSTRUCTOR_DATA 0x2100240 .#define SEC_CONSTRUCTOR_BSS 0x3100241 .242 233 . {* The section has contents - a data section could be 243 234 . <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be … … 260 251 .#define SEC_COFF_SHARED_LIBRARY 0x800 261 252 . 253 . {* The section contains thread local data. *} 254 .#define SEC_THREAD_LOCAL 0x1000 255 . 262 256 . {* The section has GOT references. This flag is only for the 263 257 . linker, and is currently only used by the elf32-hppa back end. … … 291 285 .#define SEC_EXCLUDE 0x40000 292 286 . 293 . {* The contents of this section are to be sorted by the 294 . based on the address specified in the associated symbol 295 . table. *} 287 . {* The contents of this section are to be sorted based on the sum of 288 . the symbol and addend values specified by the associated relocation 289 . entries. Entries without associated relocation entries will be 290 . appended to the end of the section in an unspecified order. *} 296 291 .#define SEC_SORT_ENTRIES 0x80000 297 292 . … … 351 346 .#define SEC_CLINK 0x10000000 352 347 . 348 . {* Attempt to merge identical entities in the section. 349 . Entity size is given in the entsize field. *} 350 .#define SEC_MERGE 0x20000000 351 . 352 . {* If given with SEC_MERGE, entities to merge are zero terminated 353 . strings where entsize specifies character size instead of fixed 354 . size entries. *} 355 .#define SEC_STRINGS 0x40000000 356 . 357 . {* This section contains data about section groups. *} 358 .#define SEC_GROUP 0x80000000 359 . 353 360 . {* End of section flags. *} 354 361 . … … 365 372 . 366 373 . {* Another mark flag used by some of the linker backends. Set for 367 . output sections that have a input section. *}374 . output sections that have an input section. *} 368 375 . unsigned int linker_has_input : 1; 369 376 . … … 371 378 . unsigned int gc_mark : 1; 372 379 . 373 . {* Used by the ELF code to mark sections which have been allocated to segments. *} 380 . {* The following flags are used by the ELF linker. *} 381 . 382 . {* Mark sections which have been allocated to segments. *} 374 383 . unsigned int segment_mark : 1; 384 . 385 . {* Type of sec_info information. *} 386 . unsigned int sec_info_type:3; 387 .#define ELF_INFO_TYPE_NONE 0 388 .#define ELF_INFO_TYPE_STABS 1 389 .#define ELF_INFO_TYPE_MERGE 2 390 .#define ELF_INFO_TYPE_EH_FRAME 3 391 .#define ELF_INFO_TYPE_JUST_SYMS 4 392 . 393 . {* Nonzero if this section uses RELA relocations, rather than REL. *} 394 . unsigned int use_rela_p:1; 395 . 396 . {* Bits used by various backends. *} 397 . unsigned int has_tls_reloc:1; 398 . 399 . {* Nonzero if this section needs the relax finalize pass. *} 400 . unsigned int need_finalize_relax:1; 401 . 402 . {* Usused bits. *} 403 . unsigned int flag12:1; 404 . unsigned int flag13:1; 405 . unsigned int flag14:1; 406 . unsigned int flag15:1; 407 . unsigned int flag16:4; 408 . unsigned int flag20:4; 409 . unsigned int flag24:8; 375 410 . 376 411 . {* End of internal packed boolean fields. *} … … 382 417 . the default address for <<.data>> is dependent on the specific 383 418 . target and various flags). *} 384 .385 419 . bfd_vma vma; 386 420 . 387 421 . {* The load address of the section - where it would be in a 388 422 . rom image; really only used for writing section header 389 . information. *} 390 . 423 . information. *} 391 424 . bfd_vma lma; 392 425 . … … 394 427 . Contains a value even if the section has no contents (e.g., the 395 428 . size of <<.bss>>). This will be filled in after relocation. *} 396 .397 429 . bfd_size_type _cooked_size; 398 430 . … … 400 432 . value is the same as the size, but if some relaxing has 401 433 . been done, then this value will be bigger. *} 402 .403 434 . bfd_size_type _raw_size; 404 435 . … … 410 441 . would be 100. However, if the target byte size is 16 bits 411 442 . (bfd_octets_per_byte is "2"), this value would be 50. *} 412 .413 443 . bfd_vma output_offset; 414 444 . 415 445 . {* The output section through which to map on output. *} 416 .417 446 . struct sec *output_section; 418 447 . 419 448 . {* The alignment requirement of the section, as an exponent of 2 - 420 449 . e.g., 3 aligns to 2^3 (or 8). *} 421 .422 450 . unsigned int alignment_power; 423 451 . 424 452 . {* If an input section, a pointer to a vector of relocation 425 453 . records for the data in this section. *} 426 .427 454 . struct reloc_cache_entry *relocation; 428 455 . 429 456 . {* If an output section, a pointer to a vector of pointers to 430 457 . relocation records for the data in this section. *} 431 .432 458 . struct reloc_cache_entry **orelocation; 433 459 . 434 . {* The number of relocation records in one of the above *} 435 . 460 . {* The number of relocation records in one of the above. *} 436 461 . unsigned reloc_count; 437 462 . … … 440 465 . 441 466 . {* File position of section data. *} 442 .443 467 . file_ptr filepos; 444 468 . 445 469 . {* File position of relocation info. *} 446 .447 470 . file_ptr rel_filepos; 448 471 . 449 472 . {* File position of line data. *} 450 .451 473 . file_ptr line_filepos; 452 474 . 453 475 . {* Pointer to data for applications. *} 454 .455 476 . PTR userdata; 456 477 . … … 460 481 . 461 482 . {* Attached line number information. *} 462 .463 483 . alent *lineno; 464 484 . 465 485 . {* Number of line number records. *} 466 .467 486 . unsigned int lineno_count; 468 487 . 488 . {* Entity size for merging purposes. *} 489 . unsigned int entsize; 490 . 469 491 . {* Optional information about a COMDAT entry; NULL if not COMDAT. *} 470 .471 492 . struct bfd_comdat_info *comdat; 472 .473 . {* Points to the kept section if this section is a link-once section,474 . and is discarded. *}475 . struct sec *kept_section;476 493 . 477 494 . {* When a section is being output, this value changes as more 478 495 . linenumbers are written out. *} 479 .480 496 . file_ptr moving_line_filepos; 481 497 . 482 498 . {* What the section number is in the target world. *} 483 .484 499 . int target_index; 485 500 . … … 488 503 . {* If this is a constructor section then here is a list of the 489 504 . relocations created to relocate items within it. *} 490 .491 505 . struct relent_chain *constructor_chain; 492 506 . 493 507 . {* The BFD which owns the section. *} 494 .495 508 . bfd *owner; 496 509 . 497 . {* A symbol which points at this section only *}510 . {* A symbol which points at this section only. *} 498 511 . struct symbol_cache_entry *symbol; 499 512 . struct symbol_cache_entry **symbol_ptr_ptr; … … 501 514 . struct bfd_link_order *link_order_head; 502 515 . struct bfd_link_order *link_order_tail; 503 .} asection 516 .} asection; 504 517 . 505 518 .{* These sections are global, and are managed by BFD. The application … … 513 526 .#define BFD_IND_SECTION_NAME "*IND*" 514 527 . 515 .{* the absolute section*}528 .{* The absolute section. *} 516 529 .extern const asection bfd_abs_section; 517 530 .#define bfd_abs_section_ptr ((asection *) &bfd_abs_section) 518 531 .#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr) 519 .{* Pointer to the undefined section *}532 .{* Pointer to the undefined section. *} 520 533 .extern const asection bfd_und_section; 521 534 .#define bfd_und_section_ptr ((asection *) &bfd_und_section) 522 535 .#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr) 523 .{* Pointer to the common section *}536 .{* Pointer to the common section. *} 524 537 .extern const asection bfd_com_section; 525 538 .#define bfd_com_section_ptr ((asection *) &bfd_com_section) 526 .{* Pointer to the indirect section *}539 .{* Pointer to the indirect section. *} 527 540 .extern const asection bfd_ind_section; 528 541 .#define bfd_ind_section_ptr ((asection *) &bfd_ind_section) 529 542 .#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr) 543 . 544 .#define bfd_is_const_section(SEC) \ 545 . ( ((SEC) == bfd_abs_section_ptr) \ 546 . || ((SEC) == bfd_und_section_ptr) \ 547 . || ((SEC) == bfd_com_section_ptr) \ 548 . || ((SEC) == bfd_ind_section_ptr)) 530 549 . 531 550 .extern const struct symbol_cache_entry * const bfd_abs_symbol; … … 539 558 . ((section)->reloc_done ? (section)->_cooked_size \ 540 559 . : (abort (), (bfd_size_type) 1)) 560 . 561 .{* Macros to handle insertion and deletion of a bfd's sections. These 562 . only handle the list pointers, ie. do not adjust section_count, 563 . target_index etc. *} 564 .#define bfd_section_list_remove(ABFD, PS) \ 565 . do \ 566 . { \ 567 . asection **_ps = PS; \ 568 . asection *_s = *_ps; \ 569 . *_ps = _s->next; \ 570 . if (_s->next == NULL) \ 571 . (ABFD)->section_tail = _ps; \ 572 . } \ 573 . while (0) 574 .#define bfd_section_list_insert(ABFD, PS, S) \ 575 . do \ 576 . { \ 577 . asection **_ps = PS; \ 578 . asection *_s = S; \ 579 . _s->next = *_ps; \ 580 . *_ps = _s; \ 581 . if (_s->next == NULL) \ 582 . (ABFD)->section_tail = &_s->next; \ 583 . } \ 584 . while (0) 585 . 541 586 */ 542 587 … … 572 617 /* linker_mark, linker_has_input, gc_mark, segment_mark, */ \ 573 618 0, 0, 1, 0, \ 619 \ 620 /* sec_info_type, use_rela_p, has_tls_reloc, need_finalize_relax, flag12, */ \ 621 0, 0, 0, 0, 0, \ 622 \ 623 /* flag13, flag14, flag15, flag16, flag20, flag24, */ \ 624 0, 0, 0, 0, 0, 0, \ 574 625 \ 575 626 /* vma, lma, _cooked_size, _raw_size, */ \ … … 585 636 0, NULL, NULL, NULL, 0, \ 586 637 \ 587 /* comdat, kept_section, moving_line_filepos, target_index,*/ \588 NULL, NULL, 0, 0,\638 /* entsize, comdat, moving_line_filepos, */ \ 639 0, NULL, 0, \ 589 640 \ 590 /* used_by_bfd, constructor_chain, owner,*/ \591 NULL, NULL, NULL,\641 /* target_index, used_by_bfd, constructor_chain, owner, */ \ 642 0, NULL, NULL, NULL, \ 592 643 \ 593 644 /* symbol, */ \ … … 608 659 #undef STD_SECTION 609 660 661 struct section_hash_entry 662 { 663 struct bfd_hash_entry root; 664 asection section; 665 }; 666 667 /* Initialize an entry in the section hash table. */ 668 669 struct bfd_hash_entry * 670 bfd_section_hash_newfunc (entry, table, string) 671 struct bfd_hash_entry *entry; 672 struct bfd_hash_table *table; 673 const char *string; 674 { 675 /* Allocate the structure if it has not already been allocated by a 676 subclass. */ 677 if (entry == NULL) 678 { 679 entry = (struct bfd_hash_entry *) 680 bfd_hash_allocate (table, sizeof (struct section_hash_entry)); 681 if (entry == NULL) 682 return entry; 683 } 684 685 /* Call the allocation method of the superclass. */ 686 entry = bfd_hash_newfunc (entry, table, string); 687 if (entry != NULL) 688 { 689 memset ((PTR) &((struct section_hash_entry *) entry)->section, 690 0, sizeof (asection)); 691 } 692 693 return entry; 694 } 695 696 #define section_hash_lookup(table, string, create, copy) \ 697 ((struct section_hash_entry *) \ 698 bfd_hash_lookup ((table), (string), (create), (copy))) 699 700 /* Initializes a new section. NEWSECT->NAME is already set. */ 701 702 static asection *bfd_section_init PARAMS ((bfd *, asection *)); 703 704 static asection * 705 bfd_section_init (abfd, newsect) 706 bfd *abfd; 707 asection *newsect; 708 { 709 static int section_id = 0x10; /* id 0 to 3 used by STD_SECTION. */ 710 711 newsect->id = section_id; 712 newsect->index = abfd->section_count; 713 newsect->owner = abfd; 714 715 /* Create a symbol whose only job is to point to this section. This 716 is useful for things like relocs which are relative to the base 717 of a section. */ 718 newsect->symbol = bfd_make_empty_symbol (abfd); 719 if (newsect->symbol == NULL) 720 return NULL; 721 722 newsect->symbol->name = newsect->name; 723 newsect->symbol->value = 0; 724 newsect->symbol->section = newsect; 725 newsect->symbol->flags = BSF_SECTION_SYM; 726 727 newsect->symbol_ptr_ptr = &newsect->symbol; 728 729 if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect))) 730 return NULL; 731 732 section_id++; 733 abfd->section_count++; 734 *abfd->section_tail = newsect; 735 abfd->section_tail = &newsect->next; 736 return newsect; 737 } 738 610 739 /* 611 740 DOCDD … … 620 749 /* 621 750 FUNCTION 751 bfd_section_list_clear 752 753 SYNOPSIS 754 void bfd_section_list_clear (bfd *); 755 756 DESCRIPTION 757 Clears the section list, and also resets the section count and 758 hash table entries. 759 */ 760 761 void 762 bfd_section_list_clear (abfd) 763 bfd *abfd; 764 { 765 abfd->sections = NULL; 766 abfd->section_tail = &abfd->sections; 767 abfd->section_count = 0; 768 memset ((PTR) abfd->section_htab.table, 0, 769 abfd->section_htab.size * sizeof (struct bfd_hash_entry *)); 770 } 771 772 /* 773 FUNCTION 622 774 bfd_get_section_by_name 623 775 … … 641 793 const char *name; 642 794 { 643 asection *sect; 644 645 for (sect = abfd->sections; sect != NULL; sect = sect->next) 646 if (!strcmp (sect->name, name)) 647 return sect; 795 struct section_hash_entry *sh; 796 797 sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE); 798 if (sh != NULL) 799 return &sh->section; 800 648 801 return NULL; 649 802 } … … 677 830 678 831 len = strlen (templat); 679 sname = bfd_malloc ( len + 8);832 sname = bfd_malloc ((bfd_size_type) len + 8); 680 833 if (sname == NULL) 681 834 return NULL; 682 strcpy (sname, templat);835 memcpy (sname, templat, len); 683 836 num = 1; 684 837 if (count != NULL) … … 692 845 sprintf (sname + len, ".%d", num++); 693 846 } 694 while ( bfd_get_section_by_name (abfd, sname) != NULL);847 while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE)); 695 848 696 849 if (count != NULL) … … 729 882 const char *name; 730 883 { 731 asection *sec = bfd_get_section_by_name (abfd, name); 732 if (sec == (asection *) NULL) 733 { 734 sec = bfd_make_section (abfd, name); 735 } 736 return sec; 884 struct section_hash_entry *sh; 885 asection *newsect; 886 887 if (abfd->output_has_begun) 888 { 889 bfd_set_error (bfd_error_invalid_operation); 890 return NULL; 891 } 892 893 if (strcmp (name, BFD_ABS_SECTION_NAME) == 0) 894 return bfd_abs_section_ptr; 895 896 if (strcmp (name, BFD_COM_SECTION_NAME) == 0) 897 return bfd_com_section_ptr; 898 899 if (strcmp (name, BFD_UND_SECTION_NAME) == 0) 900 return bfd_und_section_ptr; 901 902 if (strcmp (name, BFD_IND_SECTION_NAME) == 0) 903 return bfd_ind_section_ptr; 904 905 sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE); 906 if (sh == NULL) 907 return NULL; 908 909 newsect = &sh->section; 910 if (newsect->name != NULL) 911 { 912 /* Section already exists. */ 913 return newsect; 914 } 915 916 newsect->name = name; 917 return bfd_section_init (abfd, newsect); 737 918 } 738 919 … … 759 940 const char *name; 760 941 { 761 st atic int section_id = 0x10; /* id 0 to 3 used by STD_SECTION. */942 struct section_hash_entry *sh; 762 943 asection *newsect; 763 asection **prev = &abfd->sections;764 asection *sect = abfd->sections;765 944 766 945 if (abfd->output_has_begun) … … 770 949 } 771 950 772 while (sect) 773 { 774 prev = §->next; 775 sect = sect->next; 776 } 777 778 newsect = (asection *) bfd_zalloc (abfd, sizeof (asection)); 779 if (newsect == NULL) 951 sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE); 952 if (sh == NULL) 780 953 return NULL; 781 954 955 newsect = &sh->section; 956 if (newsect->name != NULL) 957 { 958 /* We are making a section of the same name. It can't go in 959 section_htab without generating a unique section name and 960 that would be pointless; We don't need to traverse the 961 hash table. */ 962 newsect = (asection *) bfd_zalloc (abfd, sizeof (asection)); 963 if (newsect == NULL) 964 return NULL; 965 } 966 782 967 newsect->name = name; 783 newsect->id = section_id++; 784 newsect->index = abfd->section_count++; 785 newsect->flags = SEC_NO_FLAGS; 786 787 newsect->userdata = NULL; 788 newsect->contents = NULL; 789 newsect->next = (asection *) NULL; 790 newsect->relocation = (arelent *) NULL; 791 newsect->reloc_count = 0; 792 newsect->line_filepos = 0; 793 newsect->owner = abfd; 794 newsect->comdat = NULL; 795 newsect->kept_section = NULL; 796 797 /* Create a symbol whos only job is to point to this section. This is 798 useful for things like relocs which are relative to the base of a 799 section. */ 800 newsect->symbol = bfd_make_empty_symbol (abfd); 801 if (newsect->symbol == NULL) 802 { 803 bfd_release (abfd, newsect); 804 return NULL; 805 } 806 newsect->symbol->name = name; 807 newsect->symbol->value = 0; 808 newsect->symbol->section = newsect; 809 newsect->symbol->flags = BSF_SECTION_SYM; 810 811 newsect->symbol_ptr_ptr = &newsect->symbol; 812 813 if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true) 814 { 815 bfd_release (abfd, newsect); 816 return NULL; 817 } 818 819 *prev = newsect; 820 return newsect; 968 return bfd_section_init (abfd, newsect); 821 969 } 822 970 … … 840 988 const char *name; 841 989 { 842 asection *sect = abfd->sections; 843 844 if (strcmp (name, BFD_ABS_SECTION_NAME) == 0) 845 { 846 return bfd_abs_section_ptr; 847 } 848 if (strcmp (name, BFD_COM_SECTION_NAME) == 0) 849 { 850 return bfd_com_section_ptr; 851 } 852 if (strcmp (name, BFD_UND_SECTION_NAME) == 0) 853 { 854 return bfd_und_section_ptr; 855 } 856 857 if (strcmp (name, BFD_IND_SECTION_NAME) == 0) 858 { 859 return bfd_ind_section_ptr; 860 } 861 862 while (sect) 863 { 864 if (!strcmp (sect->name, name)) 865 return NULL; 866 sect = sect->next; 867 } 868 869 /* The name is not already used; go ahead and make a new section. */ 870 return bfd_make_section_anyway (abfd, name); 990 struct section_hash_entry *sh; 991 asection *newsect; 992 993 if (abfd->output_has_begun) 994 { 995 bfd_set_error (bfd_error_invalid_operation); 996 return NULL; 997 } 998 999 if (strcmp (name, BFD_ABS_SECTION_NAME) == 0 1000 || strcmp (name, BFD_COM_SECTION_NAME) == 0 1001 || strcmp (name, BFD_UND_SECTION_NAME) == 0 1002 || strcmp (name, BFD_IND_SECTION_NAME) == 0) 1003 return NULL; 1004 1005 sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE); 1006 if (sh == NULL) 1007 return NULL; 1008 1009 newsect = &sh->section; 1010 if (newsect->name != NULL) 1011 { 1012 /* Section already exists. */ 1013 return newsect; 1014 } 1015 1016 newsect->name = name; 1017 return bfd_section_init (abfd, newsect); 871 1018 } 872 1019 … … 876 1023 877 1024 SYNOPSIS 878 b oolean bfd_set_section_flags(bfd *abfd, asection *sec, flagword flags);1025 bfd_boolean bfd_set_section_flags (bfd *abfd, asection *sec, flagword flags); 879 1026 880 1027 DESCRIPTION 881 1028 Set the attributes of the section @var{sec} in the BFD 882 @var{abfd} to the value @var{flags}. Return << true>> on success,883 << false>> on error. Possible error returns are:1029 @var{abfd} to the value @var{flags}. Return <<TRUE>> on success, 1030 <<FALSE>> on error. Possible error returns are: 884 1031 885 1032 o <<bfd_error_invalid_operation>> - … … 891 1038 892 1039 /*ARGSUSED*/ 893 b oolean1040 bfd_boolean 894 1041 bfd_set_section_flags (abfd, section, flags) 895 1042 bfd *abfd ATTRIBUTE_UNUSED; … … 906 1053 { 907 1054 bfd_set_error (bfd_error_invalid_operation); 908 return false;1055 return FALSE; 909 1056 } 910 1057 #endif 911 1058 912 1059 section->flags = flags; 913 return true;1060 return TRUE; 914 1061 } 915 1062 … … 963 1110 964 1111 SYNOPSIS 965 b oolean bfd_set_section_size(bfd *abfd, asection *sec, bfd_size_type val);1112 bfd_boolean bfd_set_section_size (bfd *abfd, asection *sec, bfd_size_type val); 966 1113 967 1114 DESCRIPTION 968 1115 Set @var{sec} to the size @var{val}. If the operation is 969 ok, then << true>> is returned, else <<false>>.1116 ok, then <<TRUE>> is returned, else <<FALSE>>. 970 1117 971 1118 Possible error returns: … … 975 1122 */ 976 1123 977 b oolean1124 bfd_boolean 978 1125 bfd_set_section_size (abfd, ptr, val) 979 1126 bfd *abfd; … … 987 1134 { 988 1135 bfd_set_error (bfd_error_invalid_operation); 989 return false;1136 return FALSE; 990 1137 } 991 1138 … … 993 1140 ptr->_raw_size = val; 994 1141 995 return true;1142 return TRUE; 996 1143 } 997 1144 … … 1001 1148 1002 1149 SYNOPSIS 1003 boolean bfd_set_section_contents 1004 (bfd *abfd, 1005 asection *section, 1006 PTR data, 1007 file_ptr offset, 1008 bfd_size_type count); 1150 bfd_boolean bfd_set_section_contents (bfd *abfd, asection *section, 1151 PTR data, file_ptr offset, 1152 bfd_size_type count); 1009 1153 1010 1154 DESCRIPTION … … 1014 1158 @var{offset} for @var{count} octets. 1015 1159 1016 Normally << true>> is returned, else <<false>>. Possible error1160 Normally <<TRUE>> is returned, else <<FALSE>>. Possible error 1017 1161 returns are: 1018 1162 o <<bfd_error_no_contents>> - … … 1031 1175 : bfd_get_section_size_before_reloc (sec)) 1032 1176 1033 b oolean1177 bfd_boolean 1034 1178 bfd_set_section_contents (abfd, section, location, offset, count) 1035 1179 bfd *abfd; … … 1044 1188 { 1045 1189 bfd_set_error (bfd_error_no_contents); 1046 return (false); 1047 } 1048 1049 if (offset < 0) 1050 { 1051 bad_val: 1052 bfd_set_error (bfd_error_bad_value); 1053 return false; 1054 } 1190 return FALSE; 1191 } 1192 1055 1193 sz = bfd_get_section_size_now (abfd, section); 1056 1194 if ((bfd_size_type) offset > sz 1057 1195 || count > sz 1058 || offset + count > sz) 1059 goto bad_val; 1196 || offset + count > sz 1197 || count != (size_t) count) 1198 { 1199 bfd_set_error (bfd_error_bad_value); 1200 return FALSE; 1201 } 1060 1202 1061 1203 switch (abfd->direction) … … 1064 1206 case no_direction: 1065 1207 bfd_set_error (bfd_error_invalid_operation); 1066 return false;1208 return FALSE; 1067 1209 1068 1210 case write_direction: … … 1073 1215 the file was created. Do not recompute sections sizes or alignments 1074 1216 in _bfd_set_section_content. */ 1075 abfd->output_has_begun = true;1217 abfd->output_has_begun = TRUE; 1076 1218 break; 1077 1219 } … … 1079 1221 /* Record a copy of the data in memory if desired. */ 1080 1222 if (section->contents 1081 && location != section->contents + offset)1082 memcpy (section->contents + offset, location, count);1223 && location != (PTR) (section->contents + offset)) 1224 memcpy (section->contents + offset, location, (size_t) count); 1083 1225 1084 1226 if (BFD_SEND (abfd, _bfd_set_section_contents, 1085 1227 (abfd, section, location, offset, count))) 1086 1228 { 1087 abfd->output_has_begun = true;1088 return true;1089 } 1090 1091 return false;1229 abfd->output_has_begun = TRUE; 1230 return TRUE; 1231 } 1232 1233 return FALSE; 1092 1234 } 1093 1235 … … 1097 1239 1098 1240 SYNOPSIS 1099 b oolean bfd_get_section_contents1100 (bfd *abfd, asection *section, PTR location,1101 file_ptr offset,bfd_size_type count);1241 bfd_boolean bfd_get_section_contents (bfd *abfd, asection *section, 1242 PTR location, file_ptr offset, 1243 bfd_size_type count); 1102 1244 1103 1245 DESCRIPTION … … 1110 1252 flag set are requested or if the section does not have the 1111 1253 <<SEC_HAS_CONTENTS>> flag set, then the @var{location} is filled 1112 with zeroes. If no errors occur, << true>> is returned, else1113 << false>>.1114 1115 */ 1116 b oolean1254 with zeroes. If no errors occur, <<TRUE>> is returned, else 1255 <<FALSE>>. 1256 1257 */ 1258 bfd_boolean 1117 1259 bfd_get_section_contents (abfd, section, location, offset, count) 1118 1260 bfd *abfd; … … 1126 1268 if (section->flags & SEC_CONSTRUCTOR) 1127 1269 { 1128 memset (location, 0, (unsigned) count); 1129 return true; 1130 } 1131 1132 if (offset < 0) 1133 { 1134 bad_val: 1135 bfd_set_error (bfd_error_bad_value); 1136 return false; 1137 } 1138 /* Even if reloc_done is true, this function reads unrelocated 1270 memset (location, 0, (size_t) count); 1271 return TRUE; 1272 } 1273 1274 /* Even if reloc_done is TRUE, this function reads unrelocated 1139 1275 contents, so we want the raw size. */ 1140 1276 sz = section->_raw_size; 1141 if ((bfd_size_type) offset > sz || count > sz || offset + count > sz) 1142 goto bad_val; 1277 if ((bfd_size_type) offset > sz 1278 || count > sz 1279 || offset + count > sz 1280 || count != (size_t) count) 1281 { 1282 bfd_set_error (bfd_error_bad_value); 1283 return FALSE; 1284 } 1143 1285 1144 1286 if (count == 0) 1145 1287 /* Don't bother. */ 1146 return true;1288 return TRUE; 1147 1289 1148 1290 if ((section->flags & SEC_HAS_CONTENTS) == 0) 1149 1291 { 1150 memset (location, 0, ( unsigned) count);1151 return true;1292 memset (location, 0, (size_t) count); 1293 return TRUE; 1152 1294 } 1153 1295 … … 1155 1297 { 1156 1298 memcpy (location, section->contents + offset, (size_t) count); 1157 return true;1299 return TRUE; 1158 1300 } 1159 1301 … … 1167 1309 1168 1310 SYNOPSIS 1169 boolean bfd_copy_private_section_data(bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 1311 bfd_boolean bfd_copy_private_section_data (bfd *ibfd, asection *isec, 1312 bfd *obfd, asection *osec); 1170 1313 1171 1314 DESCRIPTION 1172 1315 Copy private section information from @var{isec} in the BFD 1173 1316 @var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 1174 Return << true>> on success, <<false>> on error. Possible error1317 Return <<TRUE>> on success, <<FALSE>> on error. Possible error 1175 1318 returns are: 1176 1319 … … 1193 1336 DESCRIPTION 1194 1337 Remove @var{section} from the output. If the output section 1195 becomes empty, remove it from the output bfd. @var{info} may 1196 be NULL; if it is not, it is used to decide whether the output 1197 section is empty. 1338 becomes empty, remove it from the output bfd. 1339 1340 This function won't actually do anything except twiddle flags 1341 if called too late in the linking process, when it's not safe 1342 to remove sections. 1198 1343 */ 1199 1344 void … … 1202 1347 asection *s; 1203 1348 { 1204 asection * *spp, *os;1205 struct bfd_link_order *p, *pp;1206 b oolean keep_os;1207 1208 /* Excise the input section from the link order.1209 1210 FIXME: For all calls that I can see to this function, the link1211 orders have not yet been set up. So why are we checking them? --1212 Ian*/1349 asection *os; 1350 asection *is; 1351 bfd *abfd; 1352 1353 s->flags |= SEC_EXCLUDE; 1354 1355 /* If the section wasn't assigned to an output section, or the 1356 section has been discarded by the linker script, there's nothing 1357 more to do. */ 1213 1358 os = s->output_section; 1214 1215 /* Handle a section that wasn't output. */ 1216 if (os == NULL) 1359 if (os == NULL || os->owner == NULL) 1217 1360 return; 1218 1361 1219 for (p = os->link_order_head, pp = NULL; p != NULL; pp = p, p = p->next) 1220 if (p->type == bfd_indirect_link_order 1221 && p->u.indirect.section == s) 1222 { 1223 if (pp) 1224 pp->next = p->next; 1225 else 1226 os->link_order_head = p->next; 1227 if (!p->next) 1228 os->link_order_tail = pp; 1229 break; 1230 } 1231 1232 keep_os = os->link_order_head != NULL; 1233 1234 if (! keep_os && info != NULL) 1235 { 1236 bfd *abfd; 1237 for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next) 1238 { 1239 asection *is; 1240 for (is = abfd->sections; is != NULL; is = is->next) 1241 { 1242 if (is != s && is->output_section == os) 1243 break; 1244 } 1245 if (is != NULL) 1246 break; 1247 } 1248 if (abfd != NULL) 1249 keep_os = true; 1250 } 1251 1252 /* If the output section is empty, remove it too. Careful about sections 1253 that have been discarded in the link script -- they are mapped to 1254 bfd_abs_section, which has no owner. */ 1255 if (!keep_os && os->owner != NULL) 1256 { 1257 for (spp = &os->owner->sections; *spp; spp = &(*spp)->next) 1258 if (*spp == os) 1259 { 1260 *spp = os->next; 1261 os->owner->section_count--; 1262 break; 1263 } 1264 } 1265 } 1362 /* If the output section has other (non-excluded) input sections, we 1363 can't remove it. */ 1364 for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next) 1365 for (is = abfd->sections; is != NULL; is = is->next) 1366 if (is->output_section == os && (is->flags & SEC_EXCLUDE) == 0) 1367 return; 1368 1369 /* If the output section is empty, flag it for removal too. 1370 See ldlang.c:strip_excluded_output_sections for the action. */ 1371 os->flags |= SEC_EXCLUDE; 1372 } 1373 1374 /* 1375 FUNCTION 1376 bfd_generic_discard_group 1377 1378 SYNOPSIS 1379 bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group); 1380 1381 DESCRIPTION 1382 Remove all members of @var{group} from the output. 1383 */ 1384 1385 bfd_boolean 1386 bfd_generic_discard_group (abfd, group) 1387 bfd *abfd ATTRIBUTE_UNUSED; 1388 asection *group ATTRIBUTE_UNUSED; 1389 { 1390 return TRUE; 1391 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.