section.texi revision 1.3
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 /* End of section flags. */ 324 325 /* Some internal packed boolean fields. */ 326 327 /* See the vma field. */ 328 unsigned int user_set_vma : 1; 329 330 /* A mark flag used by some of the linker backends. */ 331 unsigned int linker_mark : 1; 332 333 /* Another mark flag used by some of the linker backends. Set for 334 output sections that have an input section. */ 335 unsigned int linker_has_input : 1; 336 337 /* Mark flag used by some linker backends for garbage collection. */ 338 unsigned int gc_mark : 1; 339 340 /* Section compression status. */ 341 unsigned int compress_status : 2; 342#define COMPRESS_SECTION_NONE 0 343#define COMPRESS_SECTION_DONE 1 344#define DECOMPRESS_SECTION_SIZED 2 345 346 /* The following flags are used by the ELF linker. */ 347 348 /* Mark sections which have been allocated to segments. */ 349 unsigned int segment_mark : 1; 350 351 /* Type of sec_info information. */ 352 unsigned int sec_info_type:3; 353#define SEC_INFO_TYPE_NONE 0 354#define SEC_INFO_TYPE_STABS 1 355#define SEC_INFO_TYPE_MERGE 2 356#define SEC_INFO_TYPE_EH_FRAME 3 357#define SEC_INFO_TYPE_JUST_SYMS 4 358#define SEC_INFO_TYPE_TARGET 5 359#define SEC_INFO_TYPE_EH_FRAME_ENTRY 6 360 361 /* Nonzero if this section uses RELA relocations, rather than REL. */ 362 unsigned int use_rela_p:1; 363 364 /* Bits used by various backends. The generic code doesn't touch 365 these fields. */ 366 367 unsigned int sec_flg0:1; 368 unsigned int sec_flg1:1; 369 unsigned int sec_flg2:1; 370 unsigned int sec_flg3:1; 371 unsigned int sec_flg4:1; 372 unsigned int sec_flg5:1; 373 374 /* End of internal packed boolean fields. */ 375 376 /* The virtual memory address of the section - where it will be 377 at run time. The symbols are relocated against this. The 378 user_set_vma flag is maintained by bfd; if it's not set, the 379 backend can assign addresses (for example, in @code{a.out}, where 380 the default address for @code{.data} is dependent on the specific 381 target and various flags). */ 382 bfd_vma vma; 383 384 /* The load address of the section - where it would be in a 385 rom image; really only used for writing section header 386 information. */ 387 bfd_vma lma; 388 389 /* The size of the section in octets, as it will be output. 390 Contains a value even if the section has no contents (e.g., the 391 size of @code{.bss}). */ 392 bfd_size_type size; 393 394 /* For input sections, the original size on disk of the section, in 395 octets. This field should be set for any section whose size is 396 changed by linker relaxation. It is required for sections where 397 the linker relaxation scheme doesn't cache altered section and 398 reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing 399 targets), and thus the original size needs to be kept to read the 400 section multiple times. For output sections, rawsize holds the 401 section size calculated on a previous linker relaxation pass. */ 402 bfd_size_type rawsize; 403 404 /* The compressed size of the section in octets. */ 405 bfd_size_type compressed_size; 406 407 /* Relaxation table. */ 408 struct relax_table *relax; 409 410 /* Count of used relaxation table entries. */ 411 int relax_count; 412 413 414 /* If this section is going to be output, then this value is the 415 offset in *bytes* into the output section of the first byte in the 416 input section (byte ==> smallest addressable unit on the 417 target). In most cases, if this was going to start at the 418 100th octet (8-bit quantity) in the output section, this value 419 would be 100. However, if the target byte size is 16 bits 420 (bfd_octets_per_byte is "2"), this value would be 50. */ 421 bfd_vma output_offset; 422 423 /* The output section through which to map on output. */ 424 struct bfd_section *output_section; 425 426 /* The alignment requirement of the section, as an exponent of 2 - 427 e.g., 3 aligns to 2^3 (or 8). */ 428 unsigned int alignment_power; 429 430 /* If an input section, a pointer to a vector of relocation 431 records for the data in this section. */ 432 struct reloc_cache_entry *relocation; 433 434 /* If an output section, a pointer to a vector of pointers to 435 relocation records for the data in this section. */ 436 struct reloc_cache_entry **orelocation; 437 438 /* The number of relocation records in one of the above. */ 439 unsigned reloc_count; 440 441 /* Information below is back end specific - and not always used 442 or updated. */ 443 444 /* File position of section data. */ 445 file_ptr filepos; 446 447 /* File position of relocation info. */ 448 file_ptr rel_filepos; 449 450 /* File position of line data. */ 451 file_ptr line_filepos; 452 453 /* Pointer to data for applications. */ 454 void *userdata; 455 456 /* If the SEC_IN_MEMORY flag is set, this points to the actual 457 contents. */ 458 unsigned char *contents; 459 460 /* Attached line number information. */ 461 alent *lineno; 462 463 /* Number of line number records. */ 464 unsigned int lineno_count; 465 466 /* Entity size for merging purposes. */ 467 unsigned int entsize; 468 469 /* Points to the kept section if this section is a link-once section, 470 and is discarded. */ 471 struct bfd_section *kept_section; 472 473 /* When a section is being output, this value changes as more 474 linenumbers are written out. */ 475 file_ptr moving_line_filepos; 476 477 /* What the section number is in the target world. */ 478 int target_index; 479 480 void *used_by_bfd; 481 482 /* If this is a constructor section then here is a list of the 483 relocations created to relocate items within it. */ 484 struct relent_chain *constructor_chain; 485 486 /* The BFD which owns the section. */ 487 bfd *owner; 488 489 /* A symbol which points at this section only. */ 490 struct bfd_symbol *symbol; 491 struct bfd_symbol **symbol_ptr_ptr; 492 493 /* Early in the link process, map_head and map_tail are used to build 494 a list of input sections attached to an output section. Later, 495 output sections use these fields for a list of bfd_link_order 496 structs. */ 497 union @{ 498 struct bfd_link_order *link_order; 499 struct bfd_section *s; 500 @} map_head, map_tail; 501@} asection; 502 503/* Relax table contains information about instructions which can 504 be removed by relaxation -- replacing a long address with a 505 short address. */ 506struct relax_table @{ 507 /* Address where bytes may be deleted. */ 508 bfd_vma addr; 509 510 /* Number of bytes to be deleted. */ 511 int size; 512@}; 513 514/* Note: the following are provided as inline functions rather than macros 515 because not all callers use the return value. A macro implementation 516 would use a comma expression, eg: "((ptr)->foo = val, TRUE)" and some 517 compilers will complain about comma expressions that have no effect. */ 518static inline bfd_boolean 519bfd_set_section_userdata (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, void * val) 520@{ 521 ptr->userdata = val; 522 return TRUE; 523@} 524 525static inline bfd_boolean 526bfd_set_section_vma (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, bfd_vma val) 527@{ 528 ptr->vma = ptr->lma = val; 529 ptr->user_set_vma = TRUE; 530 return TRUE; 531@} 532 533static inline bfd_boolean 534bfd_set_section_alignment (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, unsigned int val) 535@{ 536 ptr->alignment_power = val; 537 return TRUE; 538@} 539 540/* These sections are global, and are managed by BFD. The application 541 and target back end are not permitted to change the values in 542 these sections. */ 543extern asection _bfd_std_section[4]; 544 545#define BFD_ABS_SECTION_NAME "*ABS*" 546#define BFD_UND_SECTION_NAME "*UND*" 547#define BFD_COM_SECTION_NAME "*COM*" 548#define BFD_IND_SECTION_NAME "*IND*" 549 550/* Pointer to the common section. */ 551#define bfd_com_section_ptr (&_bfd_std_section[0]) 552/* Pointer to the undefined section. */ 553#define bfd_und_section_ptr (&_bfd_std_section[1]) 554/* Pointer to the absolute section. */ 555#define bfd_abs_section_ptr (&_bfd_std_section[2]) 556/* Pointer to the indirect section. */ 557#define bfd_ind_section_ptr (&_bfd_std_section[3]) 558 559#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr) 560#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr) 561#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr) 562 563#define bfd_is_const_section(SEC) \ 564 ( ((SEC) == bfd_abs_section_ptr) \ 565 || ((SEC) == bfd_und_section_ptr) \ 566 || ((SEC) == bfd_com_section_ptr) \ 567 || ((SEC) == bfd_ind_section_ptr)) 568 569/* Macros to handle insertion and deletion of a bfd's sections. These 570 only handle the list pointers, ie. do not adjust section_count, 571 target_index etc. */ 572#define bfd_section_list_remove(ABFD, S) \ 573 do \ 574 @{ \ 575 asection *_s = S; \ 576 asection *_next = _s->next; \ 577 asection *_prev = _s->prev; \ 578 if (_prev) \ 579 _prev->next = _next; \ 580 else \ 581 (ABFD)->sections = _next; \ 582 if (_next) \ 583 _next->prev = _prev; \ 584 else \ 585 (ABFD)->section_last = _prev; \ 586 @} \ 587 while (0) 588#define bfd_section_list_append(ABFD, S) \ 589 do \ 590 @{ \ 591 asection *_s = S; \ 592 bfd *_abfd = ABFD; \ 593 _s->next = NULL; \ 594 if (_abfd->section_last) \ 595 @{ \ 596 _s->prev = _abfd->section_last; \ 597 _abfd->section_last->next = _s; \ 598 @} \ 599 else \ 600 @{ \ 601 _s->prev = NULL; \ 602 _abfd->sections = _s; \ 603 @} \ 604 _abfd->section_last = _s; \ 605 @} \ 606 while (0) 607#define bfd_section_list_prepend(ABFD, S) \ 608 do \ 609 @{ \ 610 asection *_s = S; \ 611 bfd *_abfd = ABFD; \ 612 _s->prev = NULL; \ 613 if (_abfd->sections) \ 614 @{ \ 615 _s->next = _abfd->sections; \ 616 _abfd->sections->prev = _s; \ 617 @} \ 618 else \ 619 @{ \ 620 _s->next = NULL; \ 621 _abfd->section_last = _s; \ 622 @} \ 623 _abfd->sections = _s; \ 624 @} \ 625 while (0) 626#define bfd_section_list_insert_after(ABFD, A, S) \ 627 do \ 628 @{ \ 629 asection *_a = A; \ 630 asection *_s = S; \ 631 asection *_next = _a->next; \ 632 _s->next = _next; \ 633 _s->prev = _a; \ 634 _a->next = _s; \ 635 if (_next) \ 636 _next->prev = _s; \ 637 else \ 638 (ABFD)->section_last = _s; \ 639 @} \ 640 while (0) 641#define bfd_section_list_insert_before(ABFD, B, S) \ 642 do \ 643 @{ \ 644 asection *_b = B; \ 645 asection *_s = S; \ 646 asection *_prev = _b->prev; \ 647 _s->prev = _prev; \ 648 _s->next = _b; \ 649 _b->prev = _s; \ 650 if (_prev) \ 651 _prev->next = _s; \ 652 else \ 653 (ABFD)->sections = _s; \ 654 @} \ 655 while (0) 656#define bfd_section_removed_from_list(ABFD, S) \ 657 ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S)) 658 659#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX) \ 660 /* name, id, index, next, prev, flags, user_set_vma, */ \ 661 @{ NAME, IDX, 0, NULL, NULL, FLAGS, 0, \ 662 \ 663 /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \ 664 0, 0, 1, 0, \ 665 \ 666 /* segment_mark, sec_info_type, use_rela_p, */ \ 667 0, 0, 0, \ 668 \ 669 /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \ 670 0, 0, 0, 0, 0, 0, \ 671 \ 672 /* vma, lma, size, rawsize, compressed_size, relax, relax_count, */ \ 673 0, 0, 0, 0, 0, 0, 0, \ 674 \ 675 /* output_offset, output_section, alignment_power, */ \ 676 0, &SEC, 0, \ 677 \ 678 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \ 679 NULL, NULL, 0, 0, 0, \ 680 \ 681 /* line_filepos, userdata, contents, lineno, lineno_count, */ \ 682 0, NULL, NULL, NULL, 0, \ 683 \ 684 /* entsize, kept_section, moving_line_filepos, */ \ 685 0, NULL, 0, \ 686 \ 687 /* target_index, used_by_bfd, constructor_chain, owner, */ \ 688 0, NULL, NULL, NULL, \ 689 \ 690 /* symbol, symbol_ptr_ptr, */ \ 691 (struct bfd_symbol *) SYM, &SEC.symbol, \ 692 \ 693 /* map_head, map_tail */ \ 694 @{ NULL @}, @{ NULL @} \ 695 @} 696 697@end example 698 699@node section prototypes, , typedef asection, Sections 700@subsection Section prototypes 701These are the functions exported by the section handling part of BFD. 702 703@findex bfd_section_list_clear 704@subsubsection @code{bfd_section_list_clear} 705@strong{Synopsis} 706@example 707void bfd_section_list_clear (bfd *); 708@end example 709@strong{Description}@* 710Clears the section list, and also resets the section count and 711hash table entries. 712 713@findex bfd_get_section_by_name 714@subsubsection @code{bfd_get_section_by_name} 715@strong{Synopsis} 716@example 717asection *bfd_get_section_by_name (bfd *abfd, const char *name); 718@end example 719@strong{Description}@* 720Return the most recently created section attached to @var{abfd} 721named @var{name}. Return NULL if no such section exists. 722 723@findex bfd_get_next_section_by_name 724@subsubsection @code{bfd_get_next_section_by_name} 725@strong{Synopsis} 726@example 727asection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec); 728@end example 729@strong{Description}@* 730Given @var{sec} is a section returned by @code{bfd_get_section_by_name}, 731return the next most recently created section attached to the same 732BFD with the same name, or if no such section exists in the same BFD and 733IBFD is non-NULL, the next section with the same name in any input 734BFD following IBFD. Return NULL on finding no section. 735 736@findex bfd_get_linker_section 737@subsubsection @code{bfd_get_linker_section} 738@strong{Synopsis} 739@example 740asection *bfd_get_linker_section (bfd *abfd, const char *name); 741@end example 742@strong{Description}@* 743Return the linker created section attached to @var{abfd} 744named @var{name}. Return NULL if no such section exists. 745 746@findex bfd_get_section_by_name_if 747@subsubsection @code{bfd_get_section_by_name_if} 748@strong{Synopsis} 749@example 750asection *bfd_get_section_by_name_if 751 (bfd *abfd, 752 const char *name, 753 bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj), 754 void *obj); 755@end example 756@strong{Description}@* 757Call the provided function @var{func} for each section 758attached to the BFD @var{abfd} whose name matches @var{name}, 759passing @var{obj} as an argument. The function will be called 760as if by 761 762@example 763 func (abfd, the_section, obj); 764@end example 765 766It returns the first section for which @var{func} returns true, 767otherwise @code{NULL}. 768 769@findex bfd_get_unique_section_name 770@subsubsection @code{bfd_get_unique_section_name} 771@strong{Synopsis} 772@example 773char *bfd_get_unique_section_name 774 (bfd *abfd, const char *templat, int *count); 775@end example 776@strong{Description}@* 777Invent a section name that is unique in @var{abfd} by tacking 778a dot and a digit suffix onto the original @var{templat}. If 779@var{count} is non-NULL, then it specifies the first number 780tried as a suffix to generate a unique name. The value 781pointed to by @var{count} will be incremented in this case. 782 783@findex bfd_make_section_old_way 784@subsubsection @code{bfd_make_section_old_way} 785@strong{Synopsis} 786@example 787asection *bfd_make_section_old_way (bfd *abfd, const char *name); 788@end example 789@strong{Description}@* 790Create a new empty section called @var{name} 791and attach it to the end of the chain of sections for the 792BFD @var{abfd}. An attempt to create a section with a name which 793is already in use returns its pointer without changing the 794section chain. 795 796It has the funny name since this is the way it used to be 797before it was rewritten.... 798 799Possible errors are: 800@itemize @bullet 801 802@item 803@code{bfd_error_invalid_operation} - 804If output has already started for this BFD. 805@item 806@code{bfd_error_no_memory} - 807If memory allocation fails. 808@end itemize 809 810@findex bfd_make_section_anyway_with_flags 811@subsubsection @code{bfd_make_section_anyway_with_flags} 812@strong{Synopsis} 813@example 814asection *bfd_make_section_anyway_with_flags 815 (bfd *abfd, const char *name, flagword flags); 816@end example 817@strong{Description}@* 818Create a new empty section called @var{name} and attach it to the end of 819the chain of sections for @var{abfd}. Create a new section even if there 820is already a section with that name. Also set the attributes of the 821new section to the value @var{flags}. 822 823Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 824@itemize @bullet 825 826@item 827@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 828@item 829@code{bfd_error_no_memory} - If memory allocation fails. 830@end itemize 831 832@findex bfd_make_section_anyway 833@subsubsection @code{bfd_make_section_anyway} 834@strong{Synopsis} 835@example 836asection *bfd_make_section_anyway (bfd *abfd, const char *name); 837@end example 838@strong{Description}@* 839Create a new empty section called @var{name} and attach it to the end of 840the chain of sections for @var{abfd}. Create a new section even if there 841is already a section with that name. 842 843Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 844@itemize @bullet 845 846@item 847@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 848@item 849@code{bfd_error_no_memory} - If memory allocation fails. 850@end itemize 851 852@findex bfd_make_section_with_flags 853@subsubsection @code{bfd_make_section_with_flags} 854@strong{Synopsis} 855@example 856asection *bfd_make_section_with_flags 857 (bfd *, const char *name, flagword flags); 858@end example 859@strong{Description}@* 860Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 861bfd_set_error ()) without changing the section chain if there is already a 862section named @var{name}. Also set the attributes of the new section to 863the value @var{flags}. If there is an error, return @code{NULL} and set 864@code{bfd_error}. 865 866@findex bfd_make_section 867@subsubsection @code{bfd_make_section} 868@strong{Synopsis} 869@example 870asection *bfd_make_section (bfd *, const char *name); 871@end example 872@strong{Description}@* 873Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 874bfd_set_error ()) without changing the section chain if there is already a 875section named @var{name}. If there is an error, return @code{NULL} and set 876@code{bfd_error}. 877 878@findex bfd_get_next_section_id 879@subsubsection @code{bfd_get_next_section_id} 880@strong{Synopsis} 881@example 882int bfd_get_next_section_id (void); 883@end example 884@strong{Description}@* 885Returns the id that the next section created will have. 886 887@findex bfd_set_section_flags 888@subsubsection @code{bfd_set_section_flags} 889@strong{Synopsis} 890@example 891bfd_boolean bfd_set_section_flags 892 (bfd *abfd, asection *sec, flagword flags); 893@end example 894@strong{Description}@* 895Set the attributes of the section @var{sec} in the BFD 896@var{abfd} to the value @var{flags}. Return @code{TRUE} on success, 897@code{FALSE} on error. Possible error returns are: 898 899@itemize @bullet 900 901@item 902@code{bfd_error_invalid_operation} - 903The section cannot have one or more of the attributes 904requested. For example, a .bss section in @code{a.out} may not 905have the @code{SEC_HAS_CONTENTS} field set. 906@end itemize 907 908@findex bfd_rename_section 909@subsubsection @code{bfd_rename_section} 910@strong{Synopsis} 911@example 912void bfd_rename_section 913 (bfd *abfd, asection *sec, const char *newname); 914@end example 915@strong{Description}@* 916Rename section @var{sec} in @var{abfd} to @var{newname}. 917 918@findex bfd_map_over_sections 919@subsubsection @code{bfd_map_over_sections} 920@strong{Synopsis} 921@example 922void bfd_map_over_sections 923 (bfd *abfd, 924 void (*func) (bfd *abfd, asection *sect, void *obj), 925 void *obj); 926@end example 927@strong{Description}@* 928Call the provided function @var{func} for each section 929attached to the BFD @var{abfd}, passing @var{obj} as an 930argument. The function will be called as if by 931 932@example 933 func (abfd, the_section, obj); 934@end example 935 936This is the preferred method for iterating over sections; an 937alternative would be to use a loop: 938 939@example 940 asection *p; 941 for (p = abfd->sections; p != NULL; p = p->next) 942 func (abfd, p, ...) 943@end example 944 945@findex bfd_sections_find_if 946@subsubsection @code{bfd_sections_find_if} 947@strong{Synopsis} 948@example 949asection *bfd_sections_find_if 950 (bfd *abfd, 951 bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj), 952 void *obj); 953@end example 954@strong{Description}@* 955Call the provided function @var{operation} for each section 956attached to the BFD @var{abfd}, passing @var{obj} as an 957argument. The function will be called as if by 958 959@example 960 operation (abfd, the_section, obj); 961@end example 962 963It returns the first section for which @var{operation} returns true. 964 965@findex bfd_set_section_size 966@subsubsection @code{bfd_set_section_size} 967@strong{Synopsis} 968@example 969bfd_boolean bfd_set_section_size 970 (bfd *abfd, asection *sec, bfd_size_type val); 971@end example 972@strong{Description}@* 973Set @var{sec} to the size @var{val}. If the operation is 974ok, then @code{TRUE} is returned, else @code{FALSE}. 975 976Possible error returns: 977@itemize @bullet 978 979@item 980@code{bfd_error_invalid_operation} - 981Writing has started to the BFD, so setting the size is invalid. 982@end itemize 983 984@findex bfd_set_section_contents 985@subsubsection @code{bfd_set_section_contents} 986@strong{Synopsis} 987@example 988bfd_boolean bfd_set_section_contents 989 (bfd *abfd, asection *section, const void *data, 990 file_ptr offset, bfd_size_type count); 991@end example 992@strong{Description}@* 993Sets the contents of the section @var{section} in BFD 994@var{abfd} to the data starting in memory at @var{data}. The 995data is written to the output section starting at offset 996@var{offset} for @var{count} octets. 997 998Normally @code{TRUE} is returned, else @code{FALSE}. Possible error 999returns are: 1000@itemize @bullet 1001 1002@item 1003@code{bfd_error_no_contents} - 1004The output section does not have the @code{SEC_HAS_CONTENTS} 1005attribute, so nothing can be written to it. 1006@item 1007and some more too 1008@end itemize 1009This routine is front end to the back end function 1010@code{_bfd_set_section_contents}. 1011 1012@findex bfd_get_section_contents 1013@subsubsection @code{bfd_get_section_contents} 1014@strong{Synopsis} 1015@example 1016bfd_boolean bfd_get_section_contents 1017 (bfd *abfd, asection *section, void *location, file_ptr offset, 1018 bfd_size_type count); 1019@end example 1020@strong{Description}@* 1021Read data from @var{section} in BFD @var{abfd} 1022into memory starting at @var{location}. The data is read at an 1023offset of @var{offset} from the start of the input section, 1024and is read for @var{count} bytes. 1025 1026If the contents of a constructor with the @code{SEC_CONSTRUCTOR} 1027flag set are requested or if the section does not have the 1028@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled 1029with zeroes. If no errors occur, @code{TRUE} is returned, else 1030@code{FALSE}. 1031 1032@findex bfd_malloc_and_get_section 1033@subsubsection @code{bfd_malloc_and_get_section} 1034@strong{Synopsis} 1035@example 1036bfd_boolean bfd_malloc_and_get_section 1037 (bfd *abfd, asection *section, bfd_byte **buf); 1038@end example 1039@strong{Description}@* 1040Read all data from @var{section} in BFD @var{abfd} 1041into a buffer, *@var{buf}, malloc'd by this function. 1042 1043@findex bfd_copy_private_section_data 1044@subsubsection @code{bfd_copy_private_section_data} 1045@strong{Synopsis} 1046@example 1047bfd_boolean bfd_copy_private_section_data 1048 (bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 1049@end example 1050@strong{Description}@* 1051Copy private section information from @var{isec} in the BFD 1052@var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 1053Return @code{TRUE} on success, @code{FALSE} on error. Possible error 1054returns are: 1055 1056@itemize @bullet 1057 1058@item 1059@code{bfd_error_no_memory} - 1060Not enough memory exists to create private data for @var{osec}. 1061@end itemize 1062@example 1063#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ 1064 BFD_SEND (obfd, _bfd_copy_private_section_data, \ 1065 (ibfd, isection, obfd, osection)) 1066@end example 1067 1068@findex bfd_generic_is_group_section 1069@subsubsection @code{bfd_generic_is_group_section} 1070@strong{Synopsis} 1071@example 1072bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec); 1073@end example 1074@strong{Description}@* 1075Returns TRUE if @var{sec} is a member of a group. 1076 1077@findex bfd_generic_discard_group 1078@subsubsection @code{bfd_generic_discard_group} 1079@strong{Synopsis} 1080@example 1081bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group); 1082@end example 1083@strong{Description}@* 1084Remove all members of @var{group} from the output. 1085 1086