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