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