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