section.texi revision 1.1.1.6
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 0x0 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 0x1 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 0x2 142 143 /* The section contains data still to be relocated, so there is 144 some relocation information too. */ 145#define SEC_RELOC 0x4 146 147 /* A signal to the OS that the section contains read only data. */ 148#define SEC_READONLY 0x8 149 150 /* The section contains code only. */ 151#define SEC_CODE 0x10 152 153 /* The section contains data only. */ 154#define SEC_DATA 0x20 155 156 /* The section will reside in ROM. */ 157#define SEC_ROM 0x40 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 0x80 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 purecode flag set. */ 324#define SEC_ELF_PURECODE 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, 523 void * val) 524@{ 525 ptr->userdata = val; 526 return TRUE; 527@} 528 529static inline bfd_boolean 530bfd_set_section_vma (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, bfd_vma val) 531@{ 532 ptr->vma = ptr->lma = val; 533 ptr->user_set_vma = TRUE; 534 return TRUE; 535@} 536 537static inline bfd_boolean 538bfd_set_section_alignment (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, 539 unsigned int val) 540@{ 541 ptr->alignment_power = val; 542 return TRUE; 543@} 544 545/* These sections are global, and are managed by BFD. The application 546 and target back end are not permitted to change the values in 547 these sections. */ 548extern asection _bfd_std_section[4]; 549 550#define BFD_ABS_SECTION_NAME "*ABS*" 551#define BFD_UND_SECTION_NAME "*UND*" 552#define BFD_COM_SECTION_NAME "*COM*" 553#define BFD_IND_SECTION_NAME "*IND*" 554 555/* Pointer to the common section. */ 556#define bfd_com_section_ptr (&_bfd_std_section[0]) 557/* Pointer to the undefined section. */ 558#define bfd_und_section_ptr (&_bfd_std_section[1]) 559/* Pointer to the absolute section. */ 560#define bfd_abs_section_ptr (&_bfd_std_section[2]) 561/* Pointer to the indirect section. */ 562#define bfd_ind_section_ptr (&_bfd_std_section[3]) 563 564#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr) 565#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr) 566#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr) 567 568#define bfd_is_const_section(SEC) \ 569 ( ((SEC) == bfd_abs_section_ptr) \ 570 || ((SEC) == bfd_und_section_ptr) \ 571 || ((SEC) == bfd_com_section_ptr) \ 572 || ((SEC) == bfd_ind_section_ptr)) 573 574/* Macros to handle insertion and deletion of a bfd's sections. These 575 only handle the list pointers, ie. do not adjust section_count, 576 target_index etc. */ 577#define bfd_section_list_remove(ABFD, S) \ 578 do \ 579 @{ \ 580 asection *_s = S; \ 581 asection *_next = _s->next; \ 582 asection *_prev = _s->prev; \ 583 if (_prev) \ 584 _prev->next = _next; \ 585 else \ 586 (ABFD)->sections = _next; \ 587 if (_next) \ 588 _next->prev = _prev; \ 589 else \ 590 (ABFD)->section_last = _prev; \ 591 @} \ 592 while (0) 593#define bfd_section_list_append(ABFD, S) \ 594 do \ 595 @{ \ 596 asection *_s = S; \ 597 bfd *_abfd = ABFD; \ 598 _s->next = NULL; \ 599 if (_abfd->section_last) \ 600 @{ \ 601 _s->prev = _abfd->section_last; \ 602 _abfd->section_last->next = _s; \ 603 @} \ 604 else \ 605 @{ \ 606 _s->prev = NULL; \ 607 _abfd->sections = _s; \ 608 @} \ 609 _abfd->section_last = _s; \ 610 @} \ 611 while (0) 612#define bfd_section_list_prepend(ABFD, S) \ 613 do \ 614 @{ \ 615 asection *_s = S; \ 616 bfd *_abfd = ABFD; \ 617 _s->prev = NULL; \ 618 if (_abfd->sections) \ 619 @{ \ 620 _s->next = _abfd->sections; \ 621 _abfd->sections->prev = _s; \ 622 @} \ 623 else \ 624 @{ \ 625 _s->next = NULL; \ 626 _abfd->section_last = _s; \ 627 @} \ 628 _abfd->sections = _s; \ 629 @} \ 630 while (0) 631#define bfd_section_list_insert_after(ABFD, A, S) \ 632 do \ 633 @{ \ 634 asection *_a = A; \ 635 asection *_s = S; \ 636 asection *_next = _a->next; \ 637 _s->next = _next; \ 638 _s->prev = _a; \ 639 _a->next = _s; \ 640 if (_next) \ 641 _next->prev = _s; \ 642 else \ 643 (ABFD)->section_last = _s; \ 644 @} \ 645 while (0) 646#define bfd_section_list_insert_before(ABFD, B, S) \ 647 do \ 648 @{ \ 649 asection *_b = B; \ 650 asection *_s = S; \ 651 asection *_prev = _b->prev; \ 652 _s->prev = _prev; \ 653 _s->next = _b; \ 654 _b->prev = _s; \ 655 if (_prev) \ 656 _prev->next = _s; \ 657 else \ 658 (ABFD)->sections = _s; \ 659 @} \ 660 while (0) 661#define bfd_section_removed_from_list(ABFD, S) \ 662 ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S)) 663 664#define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS) \ 665 /* name, id, index, next, prev, flags, user_set_vma, */ \ 666 @{ NAME, IDX, 0, NULL, NULL, FLAGS, 0, \ 667 \ 668 /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \ 669 0, 0, 1, 0, \ 670 \ 671 /* segment_mark, sec_info_type, use_rela_p, */ \ 672 0, 0, 0, \ 673 \ 674 /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \ 675 0, 0, 0, 0, 0, 0, \ 676 \ 677 /* vma, lma, size, rawsize, compressed_size, relax, relax_count, */ \ 678 0, 0, 0, 0, 0, 0, 0, \ 679 \ 680 /* output_offset, output_section, alignment_power, */ \ 681 0, &SEC, 0, \ 682 \ 683 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \ 684 NULL, NULL, 0, 0, 0, \ 685 \ 686 /* line_filepos, userdata, contents, lineno, lineno_count, */ \ 687 0, NULL, NULL, NULL, 0, \ 688 \ 689 /* entsize, kept_section, moving_line_filepos, */ \ 690 0, NULL, 0, \ 691 \ 692 /* target_index, used_by_bfd, constructor_chain, owner, */ \ 693 0, NULL, NULL, NULL, \ 694 \ 695 /* symbol, symbol_ptr_ptr, */ \ 696 (struct bfd_symbol *) SYM, &SEC.symbol, \ 697 \ 698 /* map_head, map_tail */ \ 699 @{ NULL @}, @{ NULL @} \ 700 @} 701 702/* We use a macro to initialize the static asymbol structures because 703 traditional C does not permit us to initialize a union member while 704 gcc warns if we don't initialize it. 705 the_bfd, name, value, attr, section [, udata] */ 706#ifdef __STDC__ 707#define GLOBAL_SYM_INIT(NAME, SECTION) \ 708 @{ 0, NAME, 0, BSF_SECTION_SYM, SECTION, @{ 0 @}@} 709#else 710#define GLOBAL_SYM_INIT(NAME, SECTION) \ 711 @{ 0, NAME, 0, BSF_SECTION_SYM, SECTION @} 712#endif 713 714@end example 715 716@node section prototypes, , typedef asection, Sections 717@subsection Section prototypes 718These are the functions exported by the section handling part of BFD. 719 720@findex bfd_section_list_clear 721@subsubsection @code{bfd_section_list_clear} 722@strong{Synopsis} 723@example 724void bfd_section_list_clear (bfd *); 725@end example 726@strong{Description}@* 727Clears the section list, and also resets the section count and 728hash table entries. 729 730@findex bfd_get_section_by_name 731@subsubsection @code{bfd_get_section_by_name} 732@strong{Synopsis} 733@example 734asection *bfd_get_section_by_name (bfd *abfd, const char *name); 735@end example 736@strong{Description}@* 737Return the most recently created section attached to @var{abfd} 738named @var{name}. Return NULL if no such section exists. 739 740@findex bfd_get_next_section_by_name 741@subsubsection @code{bfd_get_next_section_by_name} 742@strong{Synopsis} 743@example 744asection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec); 745@end example 746@strong{Description}@* 747Given @var{sec} is a section returned by @code{bfd_get_section_by_name}, 748return the next most recently created section attached to the same 749BFD with the same name, or if no such section exists in the same BFD and 750IBFD is non-NULL, the next section with the same name in any input 751BFD following IBFD. Return NULL on finding no section. 752 753@findex bfd_get_linker_section 754@subsubsection @code{bfd_get_linker_section} 755@strong{Synopsis} 756@example 757asection *bfd_get_linker_section (bfd *abfd, const char *name); 758@end example 759@strong{Description}@* 760Return the linker created section attached to @var{abfd} 761named @var{name}. Return NULL if no such section exists. 762 763@findex bfd_get_section_by_name_if 764@subsubsection @code{bfd_get_section_by_name_if} 765@strong{Synopsis} 766@example 767asection *bfd_get_section_by_name_if 768 (bfd *abfd, 769 const char *name, 770 bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj), 771 void *obj); 772@end example 773@strong{Description}@* 774Call the provided function @var{func} for each section 775attached to the BFD @var{abfd} whose name matches @var{name}, 776passing @var{obj} as an argument. The function will be called 777as if by 778 779@example 780 func (abfd, the_section, obj); 781@end example 782 783It returns the first section for which @var{func} returns true, 784otherwise @code{NULL}. 785 786@findex bfd_get_unique_section_name 787@subsubsection @code{bfd_get_unique_section_name} 788@strong{Synopsis} 789@example 790char *bfd_get_unique_section_name 791 (bfd *abfd, const char *templat, int *count); 792@end example 793@strong{Description}@* 794Invent a section name that is unique in @var{abfd} by tacking 795a dot and a digit suffix onto the original @var{templat}. If 796@var{count} is non-NULL, then it specifies the first number 797tried as a suffix to generate a unique name. The value 798pointed to by @var{count} will be incremented in this case. 799 800@findex bfd_make_section_old_way 801@subsubsection @code{bfd_make_section_old_way} 802@strong{Synopsis} 803@example 804asection *bfd_make_section_old_way (bfd *abfd, const char *name); 805@end example 806@strong{Description}@* 807Create a new empty section called @var{name} 808and attach it to the end of the chain of sections for the 809BFD @var{abfd}. An attempt to create a section with a name which 810is already in use returns its pointer without changing the 811section chain. 812 813It has the funny name since this is the way it used to be 814before it was rewritten.... 815 816Possible errors are: 817@itemize @bullet 818 819@item 820@code{bfd_error_invalid_operation} - 821If output has already started for this BFD. 822@item 823@code{bfd_error_no_memory} - 824If memory allocation fails. 825@end itemize 826 827@findex bfd_make_section_anyway_with_flags 828@subsubsection @code{bfd_make_section_anyway_with_flags} 829@strong{Synopsis} 830@example 831asection *bfd_make_section_anyway_with_flags 832 (bfd *abfd, const char *name, flagword flags); 833@end example 834@strong{Description}@* 835Create a new empty section called @var{name} and attach it to the end of 836the chain of sections for @var{abfd}. Create a new section even if there 837is already a section with that name. Also set the attributes of the 838new section to the value @var{flags}. 839 840Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 841@itemize @bullet 842 843@item 844@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 845@item 846@code{bfd_error_no_memory} - If memory allocation fails. 847@end itemize 848 849@findex bfd_make_section_anyway 850@subsubsection @code{bfd_make_section_anyway} 851@strong{Synopsis} 852@example 853asection *bfd_make_section_anyway (bfd *abfd, const char *name); 854@end example 855@strong{Description}@* 856Create a new empty section called @var{name} and attach it to the end of 857the chain of sections for @var{abfd}. Create a new section even if there 858is already a section with that name. 859 860Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 861@itemize @bullet 862 863@item 864@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 865@item 866@code{bfd_error_no_memory} - If memory allocation fails. 867@end itemize 868 869@findex bfd_make_section_with_flags 870@subsubsection @code{bfd_make_section_with_flags} 871@strong{Synopsis} 872@example 873asection *bfd_make_section_with_flags 874 (bfd *, const char *name, flagword flags); 875@end example 876@strong{Description}@* 877Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 878bfd_set_error ()) without changing the section chain if there is already a 879section named @var{name}. Also set the attributes of the new section to 880the value @var{flags}. If there is an error, return @code{NULL} and set 881@code{bfd_error}. 882 883@findex bfd_make_section 884@subsubsection @code{bfd_make_section} 885@strong{Synopsis} 886@example 887asection *bfd_make_section (bfd *, const char *name); 888@end example 889@strong{Description}@* 890Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 891bfd_set_error ()) without changing the section chain if there is already a 892section named @var{name}. If there is an error, return @code{NULL} and set 893@code{bfd_error}. 894 895@findex bfd_get_next_section_id 896@subsubsection @code{bfd_get_next_section_id} 897@strong{Synopsis} 898@example 899int bfd_get_next_section_id (void); 900@end example 901@strong{Description}@* 902Returns the id that the next section created will have. 903 904@findex bfd_set_section_flags 905@subsubsection @code{bfd_set_section_flags} 906@strong{Synopsis} 907@example 908bfd_boolean bfd_set_section_flags 909 (bfd *abfd, asection *sec, flagword flags); 910@end example 911@strong{Description}@* 912Set the attributes of the section @var{sec} in the BFD 913@var{abfd} to the value @var{flags}. Return @code{TRUE} on success, 914@code{FALSE} on error. Possible error returns are: 915 916@itemize @bullet 917 918@item 919@code{bfd_error_invalid_operation} - 920The section cannot have one or more of the attributes 921requested. For example, a .bss section in @code{a.out} may not 922have the @code{SEC_HAS_CONTENTS} field set. 923@end itemize 924 925@findex bfd_rename_section 926@subsubsection @code{bfd_rename_section} 927@strong{Synopsis} 928@example 929void bfd_rename_section 930 (bfd *abfd, asection *sec, const char *newname); 931@end example 932@strong{Description}@* 933Rename section @var{sec} in @var{abfd} to @var{newname}. 934 935@findex bfd_map_over_sections 936@subsubsection @code{bfd_map_over_sections} 937@strong{Synopsis} 938@example 939void bfd_map_over_sections 940 (bfd *abfd, 941 void (*func) (bfd *abfd, asection *sect, void *obj), 942 void *obj); 943@end example 944@strong{Description}@* 945Call the provided function @var{func} for each section 946attached to the BFD @var{abfd}, passing @var{obj} as an 947argument. The function will be called as if by 948 949@example 950 func (abfd, the_section, obj); 951@end example 952 953This is the preferred method for iterating over sections; an 954alternative would be to use a loop: 955 956@example 957 asection *p; 958 for (p = abfd->sections; p != NULL; p = p->next) 959 func (abfd, p, ...) 960@end example 961 962@findex bfd_sections_find_if 963@subsubsection @code{bfd_sections_find_if} 964@strong{Synopsis} 965@example 966asection *bfd_sections_find_if 967 (bfd *abfd, 968 bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj), 969 void *obj); 970@end example 971@strong{Description}@* 972Call the provided function @var{operation} for each section 973attached to the BFD @var{abfd}, passing @var{obj} as an 974argument. The function will be called as if by 975 976@example 977 operation (abfd, the_section, obj); 978@end example 979 980It returns the first section for which @var{operation} returns true. 981 982@findex bfd_set_section_size 983@subsubsection @code{bfd_set_section_size} 984@strong{Synopsis} 985@example 986bfd_boolean bfd_set_section_size 987 (bfd *abfd, asection *sec, bfd_size_type val); 988@end example 989@strong{Description}@* 990Set @var{sec} to the size @var{val}. If the operation is 991ok, then @code{TRUE} is returned, else @code{FALSE}. 992 993Possible error returns: 994@itemize @bullet 995 996@item 997@code{bfd_error_invalid_operation} - 998Writing has started to the BFD, so setting the size is invalid. 999@end itemize 1000 1001@findex bfd_set_section_contents 1002@subsubsection @code{bfd_set_section_contents} 1003@strong{Synopsis} 1004@example 1005bfd_boolean bfd_set_section_contents 1006 (bfd *abfd, asection *section, const void *data, 1007 file_ptr offset, bfd_size_type count); 1008@end example 1009@strong{Description}@* 1010Sets the contents of the section @var{section} in BFD 1011@var{abfd} to the data starting in memory at @var{data}. The 1012data is written to the output section starting at offset 1013@var{offset} for @var{count} octets. 1014 1015Normally @code{TRUE} is returned, else @code{FALSE}. Possible error 1016returns are: 1017@itemize @bullet 1018 1019@item 1020@code{bfd_error_no_contents} - 1021The output section does not have the @code{SEC_HAS_CONTENTS} 1022attribute, so nothing can be written to it. 1023@item 1024and some more too 1025@end itemize 1026This routine is front end to the back end function 1027@code{_bfd_set_section_contents}. 1028 1029@findex bfd_get_section_contents 1030@subsubsection @code{bfd_get_section_contents} 1031@strong{Synopsis} 1032@example 1033bfd_boolean bfd_get_section_contents 1034 (bfd *abfd, asection *section, void *location, file_ptr offset, 1035 bfd_size_type count); 1036@end example 1037@strong{Description}@* 1038Read data from @var{section} in BFD @var{abfd} 1039into memory starting at @var{location}. The data is read at an 1040offset of @var{offset} from the start of the input section, 1041and is read for @var{count} bytes. 1042 1043If the contents of a constructor with the @code{SEC_CONSTRUCTOR} 1044flag set are requested or if the section does not have the 1045@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled 1046with zeroes. If no errors occur, @code{TRUE} is returned, else 1047@code{FALSE}. 1048 1049@findex bfd_malloc_and_get_section 1050@subsubsection @code{bfd_malloc_and_get_section} 1051@strong{Synopsis} 1052@example 1053bfd_boolean bfd_malloc_and_get_section 1054 (bfd *abfd, asection *section, bfd_byte **buf); 1055@end example 1056@strong{Description}@* 1057Read all data from @var{section} in BFD @var{abfd} 1058into a buffer, *@var{buf}, malloc'd by this function. 1059 1060@findex bfd_copy_private_section_data 1061@subsubsection @code{bfd_copy_private_section_data} 1062@strong{Synopsis} 1063@example 1064bfd_boolean bfd_copy_private_section_data 1065 (bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 1066@end example 1067@strong{Description}@* 1068Copy private section information from @var{isec} in the BFD 1069@var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 1070Return @code{TRUE} on success, @code{FALSE} on error. Possible error 1071returns are: 1072 1073@itemize @bullet 1074 1075@item 1076@code{bfd_error_no_memory} - 1077Not enough memory exists to create private data for @var{osec}. 1078@end itemize 1079@example 1080#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ 1081 BFD_SEND (obfd, _bfd_copy_private_section_data, \ 1082 (ibfd, isection, obfd, osection)) 1083@end example 1084 1085@findex bfd_generic_is_group_section 1086@subsubsection @code{bfd_generic_is_group_section} 1087@strong{Synopsis} 1088@example 1089bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec); 1090@end example 1091@strong{Description}@* 1092Returns TRUE if @var{sec} is a member of a group. 1093 1094@findex bfd_generic_discard_group 1095@subsubsection @code{bfd_generic_discard_group} 1096@strong{Synopsis} 1097@example 1098bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group); 1099@end example 1100@strong{Description}@* 1101Remove all members of @var{group} from the output. 1102 1103