1@section Sections 2The raw data contained within a BFD is maintained through the 3section abstraction. A single BFD may have any number of 4sections. It keeps hold of them by pointing to the first; 5each one points to the next in the list. 6 7Sections are supported in BFD in @code{section.c}. 8 9@menu 10* Section Input:: 11* Section Output:: 12* typedef asection:: 13* section prototypes:: 14@end menu 15 16@node Section Input, Section Output, Sections, Sections 17@subsection Section input 18When a BFD is opened for reading, the section structures are 19created and attached to the BFD. 20 21Each section has a name which describes the section in the 22outside world---for example, @code{a.out} would contain at least 23three sections, called @code{.text}, @code{.data} and @code{.bss}. 24 25Names need not be unique; for example a COFF file may have several 26sections named @code{.data}. 27 28Sometimes a BFD will contain more than the ``natural'' number of 29sections. A back end may attach other sections containing 30constructor data, or an application may add a section (using 31@code{bfd_make_section}) to the sections attached to an already open 32BFD. For example, the linker creates an extra section 33@code{COMMON} for each input file's BFD to hold information about 34common storage. 35 36The raw data is not necessarily read in when 37the section descriptor is created. Some targets may leave the 38data in place until a @code{bfd_get_section_contents} call is 39made. Other back ends may read in all the data at once. For 40example, an S-record file has to be read once to determine the 41size of the data. An IEEE-695 file doesn't contain raw data in 42sections, but data and relocation expressions intermixed, so 43the data area has to be parsed to get out the data and 44relocations. 45 46@node Section Output, typedef asection, Section Input, Sections 47@subsection Section output 48To write a new object style BFD, the various sections to be 49written have to be created. They are attached to the BFD in 50the same way as input sections; data is written to the 51sections using @code{bfd_set_section_contents}. 52 53Any program that creates or combines sections (e.g., the assembler 54and linker) must use the @code{asection} fields @code{output_section} and 55@code{output_offset} to indicate the file sections to which each 56section must be written. (If the section is being created from 57scratch, @code{output_section} should probably point to the section 58itself and @code{output_offset} should probably be zero.) 59 60The data to be written comes from input sections attached 61(via @code{output_section} pointers) to 62the output sections. The output section structure can be 63considered a filter for the input section: the output section 64determines the vma of the output data and the name, but the 65input section determines the offset into the output section of 66the data to be written. 67 68E.g., to create a section "O", starting at 0x100, 0x123 long, 69containing two subsections, "A" at offset 0x0 (i.e., at vma 700x100) and "B" at offset 0x20 (i.e., at vma 0x120) the @code{asection} 71structures would look like: 72 73@example 74 section name "A" 75 output_offset 0x00 76 size 0x20 77 output_section -----------> section name "O" 78 | vma 0x100 79 section name "B" | size 0x123 80 output_offset 0x20 | 81 size 0x103 | 82 output_section --------| 83@end example 84 85@subsection Link orders 86The data within a section is stored in a @dfn{link_order}. 87These are much like the fixups in @code{gas}. The link_order 88abstraction allows a section to grow and shrink within itself. 89 90A link_order knows how big it is, and which is the next 91link_order and where the raw data for it is; it also points to 92a list of relocations which apply to it. 93 94The link_order is used by the linker to perform relaxing on 95final code. The compiler creates code which is as big as 96necessary to make it work without relaxing, and the user can 97select whether to relax. Sometimes relaxing takes a lot of 98time. The linker runs around the relocations to see if any 99are attached to data which can be shrunk, if so it does it on 100a link_order by link_order basis. 101 102 103@node typedef asection, section prototypes, Section Output, Sections 104@subsection typedef asection 105Here is the section structure: 106 107 108@example 109 110typedef struct bfd_section 111@{ 112 /* The name of the section; the name isn't a copy, the pointer is 113 the same as that passed to bfd_make_section. */ 114 const char *name; 115 116 /* A unique sequence number. */ 117 unsigned int id; 118 119 /* Which section in the bfd; 0..n-1 as sections are created in a bfd. */ 120 unsigned int index; 121 122 /* The next section in the list belonging to the BFD, or NULL. */ 123 struct bfd_section *next; 124 125 /* The previous section in the list belonging to the BFD, or NULL. */ 126 struct bfd_section *prev; 127 128 /* The field flags contains attributes of the section. Some 129 flags are read in from the object file, and some are 130 synthesized from other information. */ 131 flagword flags; 132 133#define SEC_NO_FLAGS 0x000 134 135 /* Tells the OS to allocate space for this section when loading. 136 This is clear for a section containing debug information only. */ 137#define SEC_ALLOC 0x001 138 139 /* Tells the OS to load the section from the file when loading. 140 This is clear for a .bss section. */ 141#define SEC_LOAD 0x002 142 143 /* The section contains data still to be relocated, so there is 144 some relocation information too. */ 145#define SEC_RELOC 0x004 146 147 /* A signal to the OS that the section contains read only data. */ 148#define SEC_READONLY 0x008 149 150 /* The section contains code only. */ 151#define SEC_CODE 0x010 152 153 /* The section contains data only. */ 154#define SEC_DATA 0x020 155 156 /* The section will reside in ROM. */ 157#define SEC_ROM 0x040 158 159 /* The section contains constructor information. This section 160 type is used by the linker to create lists of constructors and 161 destructors used by @code{g++}. When a back end sees a symbol 162 which should be used in a constructor list, it creates a new 163 section for the type of name (e.g., @code{__CTOR_LIST__}), attaches 164 the symbol to it, and builds a relocation. To build the lists 165 of constructors, all the linker has to do is catenate all the 166 sections called @code{__CTOR_LIST__} and relocate the data 167 contained within - exactly the operations it would peform on 168 standard data. */ 169#define SEC_CONSTRUCTOR 0x080 170 171 /* The section has contents - a data section could be 172 @code{SEC_ALLOC} | @code{SEC_HAS_CONTENTS}; a debug section could be 173 @code{SEC_HAS_CONTENTS} */ 174#define SEC_HAS_CONTENTS 0x100 175 176 /* An instruction to the linker to not output the section 177 even if it has information which would normally be written. */ 178#define SEC_NEVER_LOAD 0x200 179 180 /* The section contains thread local data. */ 181#define SEC_THREAD_LOCAL 0x400 182 183 /* The section has GOT references. This flag is only for the 184 linker, and is currently only used by the elf32-hppa back end. 185 It will be set if global offset table references were detected 186 in this section, which indicate to the linker that the section 187 contains PIC code, and must be handled specially when doing a 188 static link. */ 189#define SEC_HAS_GOT_REF 0x800 190 191 /* The section contains common symbols (symbols may be defined 192 multiple times, the value of a symbol is the amount of 193 space it requires, and the largest symbol value is the one 194 used). Most targets have exactly one of these (which we 195 translate to bfd_com_section_ptr), but ECOFF has two. */ 196#define SEC_IS_COMMON 0x1000 197 198 /* The section contains only debugging information. For 199 example, this is set for ELF .debug and .stab sections. 200 strip tests this flag to see if a section can be 201 discarded. */ 202#define SEC_DEBUGGING 0x2000 203 204 /* The contents of this section are held in memory pointed to 205 by the contents field. This is checked by bfd_get_section_contents, 206 and the data is retrieved from memory if appropriate. */ 207#define SEC_IN_MEMORY 0x4000 208 209 /* The contents of this section are to be excluded by the 210 linker for executable and shared objects unless those 211 objects are to be further relocated. */ 212#define SEC_EXCLUDE 0x8000 213 214 /* The contents of this section are to be sorted based on the sum of 215 the symbol and addend values specified by the associated relocation 216 entries. Entries without associated relocation entries will be 217 appended to the end of the section in an unspecified order. */ 218#define SEC_SORT_ENTRIES 0x10000 219 220 /* When linking, duplicate sections of the same name should be 221 discarded, rather than being combined into a single section as 222 is usually done. This is similar to how common symbols are 223 handled. See SEC_LINK_DUPLICATES below. */ 224#define SEC_LINK_ONCE 0x20000 225 226 /* If SEC_LINK_ONCE is set, this bitfield describes how the linker 227 should handle duplicate sections. */ 228#define SEC_LINK_DUPLICATES 0xc0000 229 230 /* This value for SEC_LINK_DUPLICATES means that duplicate 231 sections with the same name should simply be discarded. */ 232#define SEC_LINK_DUPLICATES_DISCARD 0x0 233 234 /* This value for SEC_LINK_DUPLICATES means that the linker 235 should warn if there are any duplicate sections, although 236 it should still only link one copy. */ 237#define SEC_LINK_DUPLICATES_ONE_ONLY 0x40000 238 239 /* This value for SEC_LINK_DUPLICATES means that the linker 240 should warn if any duplicate sections are a different size. */ 241#define SEC_LINK_DUPLICATES_SAME_SIZE 0x80000 242 243 /* This value for SEC_LINK_DUPLICATES means that the linker 244 should warn if any duplicate sections contain different 245 contents. */ 246#define SEC_LINK_DUPLICATES_SAME_CONTENTS \ 247 (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE) 248 249 /* This section was created by the linker as part of dynamic 250 relocation or other arcane processing. It is skipped when 251 going through the first-pass output, trusting that someone 252 else up the line will take care of it later. */ 253#define SEC_LINKER_CREATED 0x100000 254 255 /* This section should not be subject to garbage collection. 256 Also set to inform the linker that this section should not be 257 listed in the link map as discarded. */ 258#define SEC_KEEP 0x200000 259 260 /* This section contains "short" data, and should be placed 261 "near" the GP. */ 262#define SEC_SMALL_DATA 0x400000 263 264 /* Attempt to merge identical entities in the section. 265 Entity size is given in the entsize field. */ 266#define SEC_MERGE 0x800000 267 268 /* If given with SEC_MERGE, entities to merge are zero terminated 269 strings where entsize specifies character size instead of fixed 270 size entries. */ 271#define SEC_STRINGS 0x1000000 272 273 /* This section contains data about section groups. */ 274#define SEC_GROUP 0x2000000 275 276 /* The section is a COFF shared library section. This flag is 277 only for the linker. If this type of section appears in 278 the input file, the linker must copy it to the output file 279 without changing the vma or size. FIXME: Although this 280 was originally intended to be general, it really is COFF 281 specific (and the flag was renamed to indicate this). It 282 might be cleaner to have some more general mechanism to 283 allow the back end to control what the linker does with 284 sections. */ 285#define SEC_COFF_SHARED_LIBRARY 0x4000000 286 287 /* This input section should be copied to output in reverse order 288 as an array of pointers. This is for ELF linker internal use 289 only. */ 290#define SEC_ELF_REVERSE_COPY 0x4000000 291 292 /* This section contains data which may be shared with other 293 executables or shared objects. This is for COFF only. */ 294#define SEC_COFF_SHARED 0x8000000 295 296 /* This section should be compressed. This is for ELF linker 297 internal use only. */ 298#define SEC_ELF_COMPRESS 0x8000000 299 300 /* When a section with this flag is being linked, then if the size of 301 the input section is less than a page, it should not cross a page 302 boundary. If the size of the input section is one page or more, 303 it should be aligned on a page boundary. This is for TI 304 TMS320C54X only. */ 305#define SEC_TIC54X_BLOCK 0x10000000 306 307 /* This section should be renamed. This is for ELF linker 308 internal use only. */ 309#define SEC_ELF_RENAME 0x10000000 310 311 /* Conditionally link this section; do not link if there are no 312 references found to any symbol in the section. This is for TI 313 TMS320C54X only. */ 314#define SEC_TIC54X_CLINK 0x20000000 315 316 /* This section contains vliw code. This is for Toshiba MeP only. */ 317#define SEC_MEP_VLIW 0x20000000 318 319 /* Indicate that section has the no read flag set. This happens 320 when memory read flag isn't set. */ 321#define SEC_COFF_NOREAD 0x40000000 322 323 /* Indicate that section has the no read flag set. */ 324#define SEC_ELF_NOREAD 0x80000000 325 326 /* End of section flags. */ 327 328 /* Some internal packed boolean fields. */ 329 330 /* See the vma field. */ 331 unsigned int user_set_vma : 1; 332 333 /* A mark flag used by some of the linker backends. */ 334 unsigned int linker_mark : 1; 335 336 /* Another mark flag used by some of the linker backends. Set for 337 output sections that have an input section. */ 338 unsigned int linker_has_input : 1; 339 340 /* Mark flag used by some linker backends for garbage collection. */ 341 unsigned int gc_mark : 1; 342 343 /* Section compression status. */ 344 unsigned int compress_status : 2; 345#define COMPRESS_SECTION_NONE 0 346#define COMPRESS_SECTION_DONE 1 347#define DECOMPRESS_SECTION_SIZED 2 348 349 /* The following flags are used by the ELF linker. */ 350 351 /* Mark sections which have been allocated to segments. */ 352 unsigned int segment_mark : 1; 353 354 /* Type of sec_info information. */ 355 unsigned int sec_info_type:3; 356#define SEC_INFO_TYPE_NONE 0 357#define SEC_INFO_TYPE_STABS 1 358#define SEC_INFO_TYPE_MERGE 2 359#define SEC_INFO_TYPE_EH_FRAME 3 360#define SEC_INFO_TYPE_JUST_SYMS 4 361#define SEC_INFO_TYPE_TARGET 5 362#define SEC_INFO_TYPE_EH_FRAME_ENTRY 6 363 364 /* Nonzero if this section uses RELA relocations, rather than REL. */ 365 unsigned int use_rela_p:1; 366 367 /* Bits used by various backends. The generic code doesn't touch 368 these fields. */ 369 370 unsigned int sec_flg0:1; 371 unsigned int sec_flg1:1; 372 unsigned int sec_flg2:1; 373 unsigned int sec_flg3:1; 374 unsigned int sec_flg4:1; 375 unsigned int sec_flg5:1; 376 377 /* End of internal packed boolean fields. */ 378 379 /* The virtual memory address of the section - where it will be 380 at run time. The symbols are relocated against this. The 381 user_set_vma flag is maintained by bfd; if it's not set, the 382 backend can assign addresses (for example, in @code{a.out}, where 383 the default address for @code{.data} is dependent on the specific 384 target and various flags). */ 385 bfd_vma vma; 386 387 /* The load address of the section - where it would be in a 388 rom image; really only used for writing section header 389 information. */ 390 bfd_vma lma; 391 392 /* The size of the section in *octets*, as it will be output. 393 Contains a value even if the section has no contents (e.g., the 394 size of @code{.bss}). */ 395 bfd_size_type size; 396 397 /* For input sections, the original size on disk of the section, in 398 octets. This field should be set for any section whose size is 399 changed by linker relaxation. It is required for sections where 400 the linker relaxation scheme doesn't cache altered section and 401 reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing 402 targets), and thus the original size needs to be kept to read the 403 section multiple times. For output sections, rawsize holds the 404 section size calculated on a previous linker relaxation pass. */ 405 bfd_size_type rawsize; 406 407 /* The compressed size of the section in octets. */ 408 bfd_size_type compressed_size; 409 410 /* Relaxation table. */ 411 struct relax_table *relax; 412 413 /* Count of used relaxation table entries. */ 414 int relax_count; 415 416 417 /* If this section is going to be output, then this value is the 418 offset in *bytes* into the output section of the first byte in the 419 input section (byte ==> smallest addressable unit on the 420 target). In most cases, if this was going to start at the 421 100th octet (8-bit quantity) in the output section, this value 422 would be 100. However, if the target byte size is 16 bits 423 (bfd_octets_per_byte is "2"), this value would be 50. */ 424 bfd_vma output_offset; 425 426 /* The output section through which to map on output. */ 427 struct bfd_section *output_section; 428 429 /* The alignment requirement of the section, as an exponent of 2 - 430 e.g., 3 aligns to 2^3 (or 8). */ 431 unsigned int alignment_power; 432 433 /* If an input section, a pointer to a vector of relocation 434 records for the data in this section. */ 435 struct reloc_cache_entry *relocation; 436 437 /* If an output section, a pointer to a vector of pointers to 438 relocation records for the data in this section. */ 439 struct reloc_cache_entry **orelocation; 440 441 /* The number of relocation records in one of the above. */ 442 unsigned reloc_count; 443 444 /* Information below is back end specific - and not always used 445 or updated. */ 446 447 /* File position of section data. */ 448 file_ptr filepos; 449 450 /* File position of relocation info. */ 451 file_ptr rel_filepos; 452 453 /* File position of line data. */ 454 file_ptr line_filepos; 455 456 /* Pointer to data for applications. */ 457 void *userdata; 458 459 /* If the SEC_IN_MEMORY flag is set, this points to the actual 460 contents. */ 461 unsigned char *contents; 462 463 /* Attached line number information. */ 464 alent *lineno; 465 466 /* Number of line number records. */ 467 unsigned int lineno_count; 468 469 /* Entity size for merging purposes. */ 470 unsigned int entsize; 471 472 /* Points to the kept section if this section is a link-once section, 473 and is discarded. */ 474 struct bfd_section *kept_section; 475 476 /* When a section is being output, this value changes as more 477 linenumbers are written out. */ 478 file_ptr moving_line_filepos; 479 480 /* What the section number is in the target world. */ 481 int target_index; 482 483 void *used_by_bfd; 484 485 /* If this is a constructor section then here is a list of the 486 relocations created to relocate items within it. */ 487 struct relent_chain *constructor_chain; 488 489 /* The BFD which owns the section. */ 490 bfd *owner; 491 492 /* A symbol which points at this section only. */ 493 struct bfd_symbol *symbol; 494 struct bfd_symbol **symbol_ptr_ptr; 495 496 /* Early in the link process, map_head and map_tail are used to build 497 a list of input sections attached to an output section. Later, 498 output sections use these fields for a list of bfd_link_order 499 structs. */ 500 union @{ 501 struct bfd_link_order *link_order; 502 struct bfd_section *s; 503 @} map_head, map_tail; 504@} asection; 505 506/* Relax table contains information about instructions which can 507 be removed by relaxation -- replacing a long address with a 508 short address. */ 509struct relax_table @{ 510 /* Address where bytes may be deleted. */ 511 bfd_vma addr; 512 513 /* Number of bytes to be deleted. */ 514 int size; 515@}; 516 517/* Note: the following are provided as inline functions rather than macros 518 because not all callers use the return value. A macro implementation 519 would use a comma expression, eg: "((ptr)->foo = val, TRUE)" and some 520 compilers will complain about comma expressions that have no effect. */ 521static inline bfd_boolean 522bfd_set_section_userdata (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, void * val) 523@{ 524 ptr->userdata = val; 525 return TRUE; 526@} 527 528static inline bfd_boolean 529bfd_set_section_vma (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, bfd_vma val) 530@{ 531 ptr->vma = ptr->lma = val; 532 ptr->user_set_vma = TRUE; 533 return TRUE; 534@} 535 536static inline bfd_boolean 537bfd_set_section_alignment (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, unsigned int val) 538@{ 539 ptr->alignment_power = val; 540 return TRUE; 541@} 542 543/* These sections are global, and are managed by BFD. The application 544 and target back end are not permitted to change the values in 545 these sections. */ 546extern asection _bfd_std_section[4]; 547 548#define BFD_ABS_SECTION_NAME "*ABS*" 549#define BFD_UND_SECTION_NAME "*UND*" 550#define BFD_COM_SECTION_NAME "*COM*" 551#define BFD_IND_SECTION_NAME "*IND*" 552 553/* Pointer to the common section. */ 554#define bfd_com_section_ptr (&_bfd_std_section[0]) 555/* Pointer to the undefined section. */ 556#define bfd_und_section_ptr (&_bfd_std_section[1]) 557/* Pointer to the absolute section. */ 558#define bfd_abs_section_ptr (&_bfd_std_section[2]) 559/* Pointer to the indirect section. */ 560#define bfd_ind_section_ptr (&_bfd_std_section[3]) 561 562#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr) 563#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr) 564#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr) 565 566#define bfd_is_const_section(SEC) \ 567 ( ((SEC) == bfd_abs_section_ptr) \ 568 || ((SEC) == bfd_und_section_ptr) \ 569 || ((SEC) == bfd_com_section_ptr) \ 570 || ((SEC) == bfd_ind_section_ptr)) 571 572/* Macros to handle insertion and deletion of a bfd's sections. These 573 only handle the list pointers, ie. do not adjust section_count, 574 target_index etc. */ 575#define bfd_section_list_remove(ABFD, S) \ 576 do \ 577 @{ \ 578 asection *_s = S; \ 579 asection *_next = _s->next; \ 580 asection *_prev = _s->prev; \ 581 if (_prev) \ 582 _prev->next = _next; \ 583 else \ 584 (ABFD)->sections = _next; \ 585 if (_next) \ 586 _next->prev = _prev; \ 587 else \ 588 (ABFD)->section_last = _prev; \ 589 @} \ 590 while (0) 591#define bfd_section_list_append(ABFD, S) \ 592 do \ 593 @{ \ 594 asection *_s = S; \ 595 bfd *_abfd = ABFD; \ 596 _s->next = NULL; \ 597 if (_abfd->section_last) \ 598 @{ \ 599 _s->prev = _abfd->section_last; \ 600 _abfd->section_last->next = _s; \ 601 @} \ 602 else \ 603 @{ \ 604 _s->prev = NULL; \ 605 _abfd->sections = _s; \ 606 @} \ 607 _abfd->section_last = _s; \ 608 @} \ 609 while (0) 610#define bfd_section_list_prepend(ABFD, S) \ 611 do \ 612 @{ \ 613 asection *_s = S; \ 614 bfd *_abfd = ABFD; \ 615 _s->prev = NULL; \ 616 if (_abfd->sections) \ 617 @{ \ 618 _s->next = _abfd->sections; \ 619 _abfd->sections->prev = _s; \ 620 @} \ 621 else \ 622 @{ \ 623 _s->next = NULL; \ 624 _abfd->section_last = _s; \ 625 @} \ 626 _abfd->sections = _s; \ 627 @} \ 628 while (0) 629#define bfd_section_list_insert_after(ABFD, A, S) \ 630 do \ 631 @{ \ 632 asection *_a = A; \ 633 asection *_s = S; \ 634 asection *_next = _a->next; \ 635 _s->next = _next; \ 636 _s->prev = _a; \ 637 _a->next = _s; \ 638 if (_next) \ 639 _next->prev = _s; \ 640 else \ 641 (ABFD)->section_last = _s; \ 642 @} \ 643 while (0) 644#define bfd_section_list_insert_before(ABFD, B, S) \ 645 do \ 646 @{ \ 647 asection *_b = B; \ 648 asection *_s = S; \ 649 asection *_prev = _b->prev; \ 650 _s->prev = _prev; \ 651 _s->next = _b; \ 652 _b->prev = _s; \ 653 if (_prev) \ 654 _prev->next = _s; \ 655 else \ 656 (ABFD)->sections = _s; \ 657 @} \ 658 while (0) 659#define bfd_section_removed_from_list(ABFD, S) \ 660 ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S)) 661 662#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX) \ 663 /* name, id, index, next, prev, flags, user_set_vma, */ \ 664 @{ NAME, IDX, 0, NULL, NULL, FLAGS, 0, \ 665 \ 666 /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \ 667 0, 0, 1, 0, \ 668 \ 669 /* segment_mark, sec_info_type, use_rela_p, */ \ 670 0, 0, 0, \ 671 \ 672 /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \ 673 0, 0, 0, 0, 0, 0, \ 674 \ 675 /* vma, lma, size, rawsize, compressed_size, relax, relax_count, */ \ 676 0, 0, 0, 0, 0, 0, 0, \ 677 \ 678 /* output_offset, output_section, alignment_power, */ \ 679 0, &SEC, 0, \ 680 \ 681 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \ 682 NULL, NULL, 0, 0, 0, \ 683 \ 684 /* line_filepos, userdata, contents, lineno, lineno_count, */ \ 685 0, NULL, NULL, NULL, 0, \ 686 \ 687 /* entsize, kept_section, moving_line_filepos, */ \ 688 0, NULL, 0, \ 689 \ 690 /* target_index, used_by_bfd, constructor_chain, owner, */ \ 691 0, NULL, NULL, NULL, \ 692 \ 693 /* symbol, symbol_ptr_ptr, */ \ 694 (struct bfd_symbol *) SYM, &SEC.symbol, \ 695 \ 696 /* map_head, map_tail */ \ 697 @{ NULL @}, @{ NULL @} \ 698 @} 699 700@end example 701 702@node section prototypes, , typedef asection, Sections 703@subsection Section prototypes 704These are the functions exported by the section handling part of BFD. 705 706@findex bfd_section_list_clear 707@subsubsection @code{bfd_section_list_clear} 708@strong{Synopsis} 709@example 710void bfd_section_list_clear (bfd *); 711@end example 712@strong{Description}@* 713Clears the section list, and also resets the section count and 714hash table entries. 715 716@findex bfd_get_section_by_name 717@subsubsection @code{bfd_get_section_by_name} 718@strong{Synopsis} 719@example 720asection *bfd_get_section_by_name (bfd *abfd, const char *name); 721@end example 722@strong{Description}@* 723Return the most recently created section attached to @var{abfd} 724named @var{name}. Return NULL if no such section exists. 725 726@findex bfd_get_next_section_by_name 727@subsubsection @code{bfd_get_next_section_by_name} 728@strong{Synopsis} 729@example 730asection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec); 731@end example 732@strong{Description}@* 733Given @var{sec} is a section returned by @code{bfd_get_section_by_name}, 734return the next most recently created section attached to the same 735BFD with the same name, or if no such section exists in the same BFD and 736IBFD is non-NULL, the next section with the same name in any input 737BFD following IBFD. Return NULL on finding no section. 738 739@findex bfd_get_linker_section 740@subsubsection @code{bfd_get_linker_section} 741@strong{Synopsis} 742@example 743asection *bfd_get_linker_section (bfd *abfd, const char *name); 744@end example 745@strong{Description}@* 746Return the linker created section attached to @var{abfd} 747named @var{name}. Return NULL if no such section exists. 748 749@findex bfd_get_section_by_name_if 750@subsubsection @code{bfd_get_section_by_name_if} 751@strong{Synopsis} 752@example 753asection *bfd_get_section_by_name_if 754 (bfd *abfd, 755 const char *name, 756 bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj), 757 void *obj); 758@end example 759@strong{Description}@* 760Call the provided function @var{func} for each section 761attached to the BFD @var{abfd} whose name matches @var{name}, 762passing @var{obj} as an argument. The function will be called 763as if by 764 765@example 766 func (abfd, the_section, obj); 767@end example 768 769It returns the first section for which @var{func} returns true, 770otherwise @code{NULL}. 771 772@findex bfd_get_unique_section_name 773@subsubsection @code{bfd_get_unique_section_name} 774@strong{Synopsis} 775@example 776char *bfd_get_unique_section_name 777 (bfd *abfd, const char *templat, int *count); 778@end example 779@strong{Description}@* 780Invent a section name that is unique in @var{abfd} by tacking 781a dot and a digit suffix onto the original @var{templat}. If 782@var{count} is non-NULL, then it specifies the first number 783tried as a suffix to generate a unique name. The value 784pointed to by @var{count} will be incremented in this case. 785 786@findex bfd_make_section_old_way 787@subsubsection @code{bfd_make_section_old_way} 788@strong{Synopsis} 789@example 790asection *bfd_make_section_old_way (bfd *abfd, const char *name); 791@end example 792@strong{Description}@* 793Create a new empty section called @var{name} 794and attach it to the end of the chain of sections for the 795BFD @var{abfd}. An attempt to create a section with a name which 796is already in use returns its pointer without changing the 797section chain. 798 799It has the funny name since this is the way it used to be 800before it was rewritten.... 801 802Possible errors are: 803@itemize @bullet 804 805@item 806@code{bfd_error_invalid_operation} - 807If output has already started for this BFD. 808@item 809@code{bfd_error_no_memory} - 810If memory allocation fails. 811@end itemize 812 813@findex bfd_make_section_anyway_with_flags 814@subsubsection @code{bfd_make_section_anyway_with_flags} 815@strong{Synopsis} 816@example 817asection *bfd_make_section_anyway_with_flags 818 (bfd *abfd, const char *name, flagword flags); 819@end example 820@strong{Description}@* 821Create a new empty section called @var{name} and attach it to the end of 822the chain of sections for @var{abfd}. Create a new section even if there 823is already a section with that name. Also set the attributes of the 824new section to the value @var{flags}. 825 826Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 827@itemize @bullet 828 829@item 830@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 831@item 832@code{bfd_error_no_memory} - If memory allocation fails. 833@end itemize 834 835@findex bfd_make_section_anyway 836@subsubsection @code{bfd_make_section_anyway} 837@strong{Synopsis} 838@example 839asection *bfd_make_section_anyway (bfd *abfd, const char *name); 840@end example 841@strong{Description}@* 842Create a new empty section called @var{name} and attach it to the end of 843the chain of sections for @var{abfd}. Create a new section even if there 844is already a section with that name. 845 846Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 847@itemize @bullet 848 849@item 850@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 851@item 852@code{bfd_error_no_memory} - If memory allocation fails. 853@end itemize 854 855@findex bfd_make_section_with_flags 856@subsubsection @code{bfd_make_section_with_flags} 857@strong{Synopsis} 858@example 859asection *bfd_make_section_with_flags 860 (bfd *, const char *name, flagword flags); 861@end example 862@strong{Description}@* 863Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 864bfd_set_error ()) without changing the section chain if there is already a 865section named @var{name}. Also set the attributes of the new section to 866the value @var{flags}. If there is an error, return @code{NULL} and set 867@code{bfd_error}. 868 869@findex bfd_make_section 870@subsubsection @code{bfd_make_section} 871@strong{Synopsis} 872@example 873asection *bfd_make_section (bfd *, const char *name); 874@end example 875@strong{Description}@* 876Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 877bfd_set_error ()) without changing the section chain if there is already a 878section named @var{name}. If there is an error, return @code{NULL} and set 879@code{bfd_error}. 880 881@findex bfd_get_next_section_id 882@subsubsection @code{bfd_get_next_section_id} 883@strong{Synopsis} 884@example 885int bfd_get_next_section_id (void); 886@end example 887@strong{Description}@* 888Returns the id that the next section created will have. 889 890@findex bfd_set_section_flags 891@subsubsection @code{bfd_set_section_flags} 892@strong{Synopsis} 893@example 894bfd_boolean bfd_set_section_flags 895 (bfd *abfd, asection *sec, flagword flags); 896@end example 897@strong{Description}@* 898Set the attributes of the section @var{sec} in the BFD 899@var{abfd} to the value @var{flags}. Return @code{TRUE} on success, 900@code{FALSE} on error. Possible error returns are: 901 902@itemize @bullet 903 904@item 905@code{bfd_error_invalid_operation} - 906The section cannot have one or more of the attributes 907requested. For example, a .bss section in @code{a.out} may not 908have the @code{SEC_HAS_CONTENTS} field set. 909@end itemize 910 911@findex bfd_rename_section 912@subsubsection @code{bfd_rename_section} 913@strong{Synopsis} 914@example 915void bfd_rename_section 916 (bfd *abfd, asection *sec, const char *newname); 917@end example 918@strong{Description}@* 919Rename section @var{sec} in @var{abfd} to @var{newname}. 920 921@findex bfd_map_over_sections 922@subsubsection @code{bfd_map_over_sections} 923@strong{Synopsis} 924@example 925void bfd_map_over_sections 926 (bfd *abfd, 927 void (*func) (bfd *abfd, asection *sect, void *obj), 928 void *obj); 929@end example 930@strong{Description}@* 931Call the provided function @var{func} for each section 932attached to the BFD @var{abfd}, passing @var{obj} as an 933argument. The function will be called as if by 934 935@example 936 func (abfd, the_section, obj); 937@end example 938 939This is the preferred method for iterating over sections; an 940alternative would be to use a loop: 941 942@example 943 asection *p; 944 for (p = abfd->sections; p != NULL; p = p->next) 945 func (abfd, p, ...) 946@end example 947 948@findex bfd_sections_find_if 949@subsubsection @code{bfd_sections_find_if} 950@strong{Synopsis} 951@example 952asection *bfd_sections_find_if 953 (bfd *abfd, 954 bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj), 955 void *obj); 956@end example 957@strong{Description}@* 958Call the provided function @var{operation} for each section 959attached to the BFD @var{abfd}, passing @var{obj} as an 960argument. The function will be called as if by 961 962@example 963 operation (abfd, the_section, obj); 964@end example 965 966It returns the first section for which @var{operation} returns true. 967 968@findex bfd_set_section_size 969@subsubsection @code{bfd_set_section_size} 970@strong{Synopsis} 971@example 972bfd_boolean bfd_set_section_size 973 (bfd *abfd, asection *sec, bfd_size_type val); 974@end example 975@strong{Description}@* 976Set @var{sec} to the size @var{val}. If the operation is 977ok, then @code{TRUE} is returned, else @code{FALSE}. 978 979Possible error returns: 980@itemize @bullet 981 982@item 983@code{bfd_error_invalid_operation} - 984Writing has started to the BFD, so setting the size is invalid. 985@end itemize 986 987@findex bfd_set_section_contents 988@subsubsection @code{bfd_set_section_contents} 989@strong{Synopsis} 990@example 991bfd_boolean bfd_set_section_contents 992 (bfd *abfd, asection *section, const void *data, 993 file_ptr offset, bfd_size_type count); 994@end example 995@strong{Description}@* 996Sets the contents of the section @var{section} in BFD 997@var{abfd} to the data starting in memory at @var{data}. The 998data is written to the output section starting at offset 999@var{offset} for @var{count} octets. 1000 1001Normally @code{TRUE} is returned, else @code{FALSE}. Possible error 1002returns are: 1003@itemize @bullet 1004 1005@item 1006@code{bfd_error_no_contents} - 1007The output section does not have the @code{SEC_HAS_CONTENTS} 1008attribute, so nothing can be written to it. 1009@item 1010and some more too 1011@end itemize 1012This routine is front end to the back end function 1013@code{_bfd_set_section_contents}. 1014 1015@findex bfd_get_section_contents 1016@subsubsection @code{bfd_get_section_contents} 1017@strong{Synopsis} 1018@example 1019bfd_boolean bfd_get_section_contents 1020 (bfd *abfd, asection *section, void *location, file_ptr offset, 1021 bfd_size_type count); 1022@end example 1023@strong{Description}@* 1024Read data from @var{section} in BFD @var{abfd} 1025into memory starting at @var{location}. The data is read at an 1026offset of @var{offset} from the start of the input section, 1027and is read for @var{count} bytes. 1028 1029If the contents of a constructor with the @code{SEC_CONSTRUCTOR} 1030flag set are requested or if the section does not have the 1031@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled 1032with zeroes. If no errors occur, @code{TRUE} is returned, else 1033@code{FALSE}. 1034 1035@findex bfd_malloc_and_get_section 1036@subsubsection @code{bfd_malloc_and_get_section} 1037@strong{Synopsis} 1038@example 1039bfd_boolean bfd_malloc_and_get_section 1040 (bfd *abfd, asection *section, bfd_byte **buf); 1041@end example 1042@strong{Description}@* 1043Read all data from @var{section} in BFD @var{abfd} 1044into a buffer, *@var{buf}, malloc'd by this function. 1045 1046@findex bfd_copy_private_section_data 1047@subsubsection @code{bfd_copy_private_section_data} 1048@strong{Synopsis} 1049@example 1050bfd_boolean bfd_copy_private_section_data 1051 (bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 1052@end example 1053@strong{Description}@* 1054Copy private section information from @var{isec} in the BFD 1055@var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 1056Return @code{TRUE} on success, @code{FALSE} on error. Possible error 1057returns are: 1058 1059@itemize @bullet 1060 1061@item 1062@code{bfd_error_no_memory} - 1063Not enough memory exists to create private data for @var{osec}. 1064@end itemize 1065@example 1066#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ 1067 BFD_SEND (obfd, _bfd_copy_private_section_data, \ 1068 (ibfd, isection, obfd, osection)) 1069@end example 1070 1071@findex bfd_generic_is_group_section 1072@subsubsection @code{bfd_generic_is_group_section} 1073@strong{Synopsis} 1074@example 1075bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec); 1076@end example 1077@strong{Description}@* 1078Returns TRUE if @var{sec} is a member of a group. 1079 1080@findex bfd_generic_discard_group 1081@subsubsection @code{bfd_generic_discard_group} 1082@strong{Synopsis} 1083@example 1084bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group); 1085@end example 1086@strong{Description}@* 1087Remove all members of @var{group} from the output. 1088 1089