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