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 106typedef struct bfd_section 107@{ 108 /* The name of the section; the name isn't a copy, the pointer is 109 the same as that passed to bfd_make_section. */ 110 const char *name; 111 112 /* The next section in the list belonging to the BFD, or NULL. */ 113 struct bfd_section *next; 114 115 /* The previous section in the list belonging to the BFD, or NULL. */ 116 struct bfd_section *prev; 117 118 /* A unique sequence number. */ 119 unsigned int id; 120 121 /* A unique section number which can be used by assembler to 122 distinguish different sections with the same section name. */ 123 unsigned int section_id; 124 125 /* Which section in the bfd; 0..n-1 as sections are created in a bfd. */ 126 unsigned int index; 127 128 /* The field flags contains attributes of the section. Some 129 flags are read in from the object file, and some are 130 synthesized from other information. */ 131 flagword flags; 132 133#define SEC_NO_FLAGS 0x0 134 135 /* Tells the OS to allocate space for this section when loading. 136 This is clear for a section containing debug information only. */ 137#define SEC_ALLOC 0x1 138 139 /* Tells the OS to load the section from the file when loading. 140 This is clear for a .bss section. */ 141#define SEC_LOAD 0x2 142 143 /* The section contains data still to be relocated, so there is 144 some relocation information too. */ 145#define SEC_RELOC 0x4 146 147 /* A signal to the OS that the section contains read only data. */ 148#define SEC_READONLY 0x8 149 150 /* The section contains code only. */ 151#define SEC_CODE 0x10 152 153 /* The section contains data only. */ 154#define SEC_DATA 0x20 155 156 /* The section will reside in ROM. */ 157#define SEC_ROM 0x40 158 159 /* The section contains constructor information. This section 160 type is used by the linker to create lists of constructors and 161 destructors used by @code{g++}. When a back end sees a symbol 162 which should be used in a constructor list, it creates a new 163 section for the type of name (e.g., @code{__CTOR_LIST__}), attaches 164 the symbol to it, and builds a relocation. To build the lists 165 of constructors, all the linker has to do is catenate all the 166 sections called @code{__CTOR_LIST__} and relocate the data 167 contained within - exactly the operations it would peform on 168 standard data. */ 169#define SEC_CONSTRUCTOR 0x80 170 171 /* The section has contents - a data section could be 172 @code{SEC_ALLOC} | @code{SEC_HAS_CONTENTS}; a debug section could be 173 @code{SEC_HAS_CONTENTS} */ 174#define SEC_HAS_CONTENTS 0x100 175 176 /* An instruction to the linker to not output the section 177 even if it has information which would normally be written. */ 178#define SEC_NEVER_LOAD 0x200 179 180 /* The section contains thread local data. */ 181#define SEC_THREAD_LOCAL 0x400 182 183 /* The section's size is fixed. Generic linker code will not 184 recalculate it and it is up to whoever has set this flag to 185 get the size right. */ 186#define SEC_FIXED_SIZE 0x800 187 188 /* The section contains common symbols (symbols may be defined 189 multiple times, the value of a symbol is the amount of 190 space it requires, and the largest symbol value is the one 191 used). Most targets have exactly one of these (which we 192 translate to bfd_com_section_ptr), but ECOFF has two. */ 193#define SEC_IS_COMMON 0x1000 194 195 /* The section contains only debugging information. For 196 example, this is set for ELF .debug and .stab sections. 197 strip tests this flag to see if a section can be 198 discarded. */ 199#define SEC_DEBUGGING 0x2000 200 201 /* The contents of this section are held in memory pointed to 202 by the contents field. This is checked by bfd_get_section_contents, 203 and the data is retrieved from memory if appropriate. */ 204#define SEC_IN_MEMORY 0x4000 205 206 /* The contents of this section are to be excluded by the 207 linker for executable and shared objects unless those 208 objects are to be further relocated. */ 209#define SEC_EXCLUDE 0x8000 210 211 /* The contents of this section are to be sorted based on the sum of 212 the symbol and addend values specified by the associated relocation 213 entries. Entries without associated relocation entries will be 214 appended to the end of the section in an unspecified order. */ 215#define SEC_SORT_ENTRIES 0x10000 216 217 /* When linking, duplicate sections of the same name should be 218 discarded, rather than being combined into a single section as 219 is usually done. This is similar to how common symbols are 220 handled. See SEC_LINK_DUPLICATES below. */ 221#define SEC_LINK_ONCE 0x20000 222 223 /* If SEC_LINK_ONCE is set, this bitfield describes how the linker 224 should handle duplicate sections. */ 225#define SEC_LINK_DUPLICATES 0xc0000 226 227 /* This value for SEC_LINK_DUPLICATES means that duplicate 228 sections with the same name should simply be discarded. */ 229#define SEC_LINK_DUPLICATES_DISCARD 0x0 230 231 /* This value for SEC_LINK_DUPLICATES means that the linker 232 should warn if there are any duplicate sections, although 233 it should still only link one copy. */ 234#define SEC_LINK_DUPLICATES_ONE_ONLY 0x40000 235 236 /* This value for SEC_LINK_DUPLICATES means that the linker 237 should warn if any duplicate sections are a different size. */ 238#define SEC_LINK_DUPLICATES_SAME_SIZE 0x80000 239 240 /* This value for SEC_LINK_DUPLICATES means that the linker 241 should warn if any duplicate sections contain different 242 contents. */ 243#define SEC_LINK_DUPLICATES_SAME_CONTENTS \ 244 (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE) 245 246 /* This section was created by the linker as part of dynamic 247 relocation or other arcane processing. It is skipped when 248 going through the first-pass output, trusting that someone 249 else up the line will take care of it later. */ 250#define SEC_LINKER_CREATED 0x100000 251 252 /* This section contains a section ID to distinguish different 253 sections with the same section name. */ 254#define SEC_ASSEMBLER_SECTION_ID 0x100000 255 256 /* This section should not be subject to garbage collection. 257 Also set to inform the linker that this section should not be 258 listed in the link map as discarded. */ 259#define SEC_KEEP 0x200000 260 261 /* This section contains "short" data, and should be placed 262 "near" the GP. */ 263#define SEC_SMALL_DATA 0x400000 264 265 /* Attempt to merge identical entities in the section. 266 Entity size is given in the entsize field. */ 267#define SEC_MERGE 0x800000 268 269 /* If given with SEC_MERGE, entities to merge are zero terminated 270 strings where entsize specifies character size instead of fixed 271 size entries. */ 272#define SEC_STRINGS 0x1000000 273 274 /* This section contains data about section groups. */ 275#define SEC_GROUP 0x2000000 276 277 /* The section is a COFF shared library section. This flag is 278 only for the linker. If this type of section appears in 279 the input file, the linker must copy it to the output file 280 without changing the vma or size. FIXME: Although this 281 was originally intended to be general, it really is COFF 282 specific (and the flag was renamed to indicate this). It 283 might be cleaner to have some more general mechanism to 284 allow the back end to control what the linker does with 285 sections. */ 286#define SEC_COFF_SHARED_LIBRARY 0x4000000 287 288 /* This input section should be copied to output in reverse order 289 as an array of pointers. This is for ELF linker internal use 290 only. */ 291#define SEC_ELF_REVERSE_COPY 0x4000000 292 293 /* This section contains data which may be shared with other 294 executables or shared objects. This is for COFF only. */ 295#define SEC_COFF_SHARED 0x8000000 296 297 /* Indicate that section has the purecode flag set. */ 298#define SEC_ELF_PURECODE 0x8000000 299 300 /* When a section with this flag is being linked, then if the size of 301 the input section is less than a page, it should not cross a page 302 boundary. If the size of the input section is one page or more, 303 it should be aligned on a page boundary. This is for TI 304 TMS320C54X only. */ 305#define SEC_TIC54X_BLOCK 0x10000000 306 307 /* This section has the SHF_X86_64_LARGE flag. This is ELF x86-64 only. */ 308#define SEC_ELF_LARGE 0x10000000 309 310 /* Conditionally link this section; do not link if there are no 311 references found to any symbol in the section. This is for TI 312 TMS320C54X only. */ 313#define SEC_TIC54X_CLINK 0x20000000 314 315 /* This section contains vliw code. This is for Toshiba MeP only. */ 316#define SEC_MEP_VLIW 0x20000000 317 318 /* All symbols, sizes and relocations in this section are octets 319 instead of bytes. Required for DWARF debug sections as DWARF 320 information is organized in octets, not bytes. */ 321#define SEC_ELF_OCTETS 0x40000000 322 323 /* Indicate that section has the no read flag set. This happens 324 when memory read flag isn't set. */ 325#define SEC_COFF_NOREAD 0x40000000 326 327 /* End of section flags. */ 328 329 /* Some internal packed boolean fields. */ 330 331 /* See the vma field. */ 332 unsigned int user_set_vma : 1; 333 334 /* A mark flag used by some of the linker backends. */ 335 unsigned int linker_mark : 1; 336 337 /* Another mark flag used by some of the linker backends. Set for 338 output sections that have an input section. */ 339 unsigned int linker_has_input : 1; 340 341 /* Mark flag used by some linker backends for garbage collection. */ 342 unsigned int gc_mark : 1; 343 344 /* Section compression status. */ 345 unsigned int compress_status : 2; 346#define COMPRESS_SECTION_NONE 0 347#define COMPRESS_SECTION_DONE 1 348#define DECOMPRESS_SECTION_ZLIB 2 349#define DECOMPRESS_SECTION_ZSTD 3 350 351 /* The following flags are used by the ELF linker. */ 352 353 /* Mark sections which have been allocated to segments. */ 354 unsigned int segment_mark : 1; 355 356 /* Type of sec_info information. */ 357 unsigned int sec_info_type:3; 358#define SEC_INFO_TYPE_NONE 0 359#define SEC_INFO_TYPE_STABS 1 360#define SEC_INFO_TYPE_MERGE 2 361#define SEC_INFO_TYPE_EH_FRAME 3 362#define SEC_INFO_TYPE_JUST_SYMS 4 363#define SEC_INFO_TYPE_TARGET 5 364#define SEC_INFO_TYPE_EH_FRAME_ENTRY 6 365#define SEC_INFO_TYPE_SFRAME 7 366 367 /* Nonzero if this section uses RELA relocations, rather than REL. */ 368 unsigned int use_rela_p:1; 369 370 /* Bits used by various backends. The generic code doesn't touch 371 these fields. */ 372 373 unsigned int sec_flg0:1; 374 unsigned int sec_flg1:1; 375 unsigned int sec_flg2:1; 376 unsigned int sec_flg3:1; 377 unsigned int sec_flg4:1; 378 unsigned int sec_flg5:1; 379 380 /* End of internal packed boolean fields. */ 381 382 /* The virtual memory address of the section - where it will be 383 at run time. The symbols are relocated against this. The 384 user_set_vma flag is maintained by bfd; if it's not set, the 385 backend can assign addresses (for example, in @code{a.out}, where 386 the default address for @code{.data} is dependent on the specific 387 target and various flags). */ 388 bfd_vma vma; 389 390 /* The load address of the section - where it would be in a 391 rom image; really only used for writing section header 392 information. */ 393 bfd_vma lma; 394 395 /* The size of the section in *octets*, as it will be output. 396 Contains a value even if the section has no contents (e.g., the 397 size of @code{.bss}). */ 398 bfd_size_type size; 399 400 /* For input sections, the original size on disk of the section, in 401 octets. This field should be set for any section whose size is 402 changed by linker relaxation. It is required for sections where 403 the linker relaxation scheme doesn't cache altered section and 404 reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing 405 targets), and thus the original size needs to be kept to read the 406 section multiple times. For output sections, rawsize holds the 407 section size calculated on a previous linker relaxation pass. */ 408 bfd_size_type rawsize; 409 410 /* The compressed size of the section in octets. */ 411 bfd_size_type compressed_size; 412 413 /* If this section is going to be output, then this value is the 414 offset in *bytes* into the output section of the first byte in the 415 input section (byte ==> smallest addressable unit on the 416 target). In most cases, if this was going to start at the 417 100th octet (8-bit quantity) in the output section, this value 418 would be 100. However, if the target byte size is 16 bits 419 (bfd_octets_per_byte is "2"), this value would be 50. */ 420 bfd_vma output_offset; 421 422 /* The output section through which to map on output. */ 423 struct bfd_section *output_section; 424 425 /* If an input section, a pointer to a vector of relocation 426 records for the data in this section. */ 427 struct reloc_cache_entry *relocation; 428 429 /* If an output section, a pointer to a vector of pointers to 430 relocation records for the data in this section. */ 431 struct reloc_cache_entry **orelocation; 432 433 /* The number of relocation records in one of the above. */ 434 unsigned reloc_count; 435 436 /* The alignment requirement of the section, as an exponent of 2 - 437 e.g., 3 aligns to 2^3 (or 8). */ 438 unsigned int alignment_power; 439 440 /* Information below is back end specific - and not always used 441 or updated. */ 442 443 /* File position of section data. */ 444 file_ptr filepos; 445 446 /* File position of relocation info. */ 447 file_ptr rel_filepos; 448 449 /* File position of line data. */ 450 file_ptr line_filepos; 451 452 /* Pointer to data for applications. */ 453 void *userdata; 454 455 /* If the SEC_IN_MEMORY flag is set, this points to the actual 456 contents. */ 457 bfd_byte *contents; 458 459 /* Attached line number information. */ 460 alent *lineno; 461 462 /* Number of line number records. */ 463 unsigned int lineno_count; 464 465 /* Entity size for merging purposes. */ 466 unsigned int entsize; 467 468 /* Points to the kept section if this section is a link-once section, 469 and is discarded. */ 470 struct bfd_section *kept_section; 471 472 /* When a section is being output, this value changes as more 473 linenumbers are written out. */ 474 file_ptr moving_line_filepos; 475 476 /* What the section number is in the target world. */ 477 int target_index; 478 479 void *used_by_bfd; 480 481 /* If this is a constructor section then here is a list of the 482 relocations created to relocate items within it. */ 483 struct relent_chain *constructor_chain; 484 485 /* The BFD which owns the section. */ 486 bfd *owner; 487 488 /* A symbol which points at this section only. */ 489 struct bfd_symbol *symbol; 490 struct bfd_symbol **symbol_ptr_ptr; 491 492 /* Early in the link process, map_head and map_tail are used to build 493 a list of input sections attached to an output section. Later, 494 output sections use these fields for a list of bfd_link_order 495 structs. The linked_to_symbol_name field is for ELF assembler 496 internal use. */ 497 union @{ 498 struct bfd_link_order *link_order; 499 struct bfd_section *s; 500 const char *linked_to_symbol_name; 501 @} map_head, map_tail; 502 503 /* Points to the output section this section is already assigned to, 504 if any. This is used when support for non-contiguous memory 505 regions is enabled. */ 506 struct bfd_section *already_assigned; 507 508 /* Explicitly specified section type, if non-zero. */ 509 unsigned int type; 510 511@} asection; 512 513@end example 514 515@node section prototypes, , typedef asection, Sections 516@subsection Section prototypes 517These are the functions exported by the section handling part of BFD. 518 519@findex bfd_section_list_clear 520@subsubsection @code{bfd_section_list_clear} 521@deftypefn {Function} void bfd_section_list_clear (bfd *); 522Clears the section list, and also resets the section count and 523hash table entries. 524 525@end deftypefn 526@findex bfd_get_section_by_name 527@subsubsection @code{bfd_get_section_by_name} 528@deftypefn {Function} asection *bfd_get_section_by_name (bfd *abfd, const char *name); 529Return the most recently created section attached to @var{abfd} 530named @var{name}. Return NULL if no such section exists. 531 532@end deftypefn 533@findex bfd_get_next_section_by_name 534@subsubsection @code{bfd_get_next_section_by_name} 535@deftypefn {Function} asection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec); 536Given @var{sec} is a section returned by @code{bfd_get_section_by_name}, 537return the next most recently created section attached to the same 538BFD with the same name, or if no such section exists in the same BFD and 539IBFD is non-NULL, the next section with the same name in any input 540BFD following IBFD. Return NULL on finding no section. 541 542@end deftypefn 543@findex bfd_get_linker_section 544@subsubsection @code{bfd_get_linker_section} 545@deftypefn {Function} asection *bfd_get_linker_section (bfd *abfd, const char *name); 546Return the linker created section attached to @var{abfd} 547named @var{name}. Return NULL if no such section exists. 548 549@end deftypefn 550@findex bfd_get_section_by_name_if 551@subsubsection @code{bfd_get_section_by_name_if} 552@deftypefn {Function} asection *bfd_get_section_by_name_if (bfd *abfd, const char *name, bool (*func) (bfd *abfd, asection *sect, void *obj), void *obj); 553Call the provided function @var{func} for each section 554attached to the BFD @var{abfd} whose name matches @var{name}, 555passing @var{obj} as an argument. The function will be called 556as if by 557 558@example 559 func (abfd, the_section, obj); 560@end example 561 562It returns the first section for which @var{func} returns true, 563otherwise @code{NULL}. 564 565@end deftypefn 566@findex bfd_get_unique_section_name 567@subsubsection @code{bfd_get_unique_section_name} 568@deftypefn {Function} char *bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count); 569Invent a section name that is unique in @var{abfd} by tacking 570a dot and a digit suffix onto the original @var{templat}. If 571@var{count} is non-NULL, then it specifies the first number 572tried as a suffix to generate a unique name. The value 573pointed to by @var{count} will be incremented in this case. 574 575@end deftypefn 576@findex bfd_make_section_old_way 577@subsubsection @code{bfd_make_section_old_way} 578@deftypefn {Function} asection *bfd_make_section_old_way (bfd *abfd, const char *name); 579Create a new empty section called @var{name} 580and attach it to the end of the chain of sections for the 581BFD @var{abfd}. An attempt to create a section with a name which 582is already in use returns its pointer without changing the 583section chain. 584 585It has the funny name since this is the way it used to be 586before it was rewritten.... 587 588Possible errors are: 589@itemize @bullet 590 591@item 592@code{bfd_error_invalid_operation} - 593If output has already started for this BFD. 594@item 595@code{bfd_error_no_memory} - 596If memory allocation fails. 597@end itemize 598 599@end deftypefn 600@findex bfd_make_section_anyway_with_flags 601@subsubsection @code{bfd_make_section_anyway_with_flags} 602@deftypefn {Function} asection *bfd_make_section_anyway_with_flags (bfd *abfd, const char *name, flagword flags); 603Create a new empty section called @var{name} and attach it to the end of 604the chain of sections for @var{abfd}. Create a new section even if there 605is already a section with that name. Also set the attributes of the 606new section to the value @var{flags}. 607 608Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 609@itemize @bullet 610 611@item 612@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 613@item 614@code{bfd_error_no_memory} - If memory allocation fails. 615@end itemize 616 617@end deftypefn 618@findex bfd_make_section_anyway 619@subsubsection @code{bfd_make_section_anyway} 620@deftypefn {Function} asection *bfd_make_section_anyway (bfd *abfd, const char *name); 621Create a new empty section called @var{name} and attach it to the end of 622the chain of sections for @var{abfd}. Create a new section even if there 623is already a section with that name. 624 625Return @code{NULL} and set @code{bfd_error} on error; possible errors are: 626@itemize @bullet 627 628@item 629@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 630@item 631@code{bfd_error_no_memory} - If memory allocation fails. 632@end itemize 633 634@end deftypefn 635@findex bfd_make_section_with_flags 636@subsubsection @code{bfd_make_section_with_flags} 637@deftypefn {Function} asection *bfd_make_section_with_flags (bfd *, const char *name, flagword flags); 638Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 639bfd_set_error ()) without changing the section chain if there is already a 640section named @var{name}. Also set the attributes of the new section to 641the value @var{flags}. If there is an error, return @code{NULL} and set 642@code{bfd_error}. 643 644@end deftypefn 645@findex bfd_make_section 646@subsubsection @code{bfd_make_section} 647@deftypefn {Function} asection *bfd_make_section (bfd *, const char *name); 648Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 649bfd_set_error ()) without changing the section chain if there is already a 650section named @var{name}. If there is an error, return @code{NULL} and set 651@code{bfd_error}. 652 653@end deftypefn 654@findex bfd_set_section_flags 655@subsubsection @code{bfd_set_section_flags} 656@deftypefn {Function} bool bfd_set_section_flags (asection *sec, flagword flags); 657Set the attributes of the section @var{sec} to the value @var{flags}. 658Return @code{TRUE} on success, @code{FALSE} on error. Possible error 659returns are: 660 661@itemize @bullet 662 663@item 664@code{bfd_error_invalid_operation} - 665The section cannot have one or more of the attributes 666requested. For example, a .bss section in @code{a.out} may not 667have the @code{SEC_HAS_CONTENTS} field set. 668@end itemize 669 670@end deftypefn 671@findex bfd_rename_section 672@subsubsection @code{bfd_rename_section} 673@deftypefn {Function} void bfd_rename_section (asection *sec, const char *newname); 674Rename section @var{sec} to @var{newname}. 675 676@end deftypefn 677@findex bfd_map_over_sections 678@subsubsection @code{bfd_map_over_sections} 679@deftypefn {Function} void bfd_map_over_sections (bfd *abfd, void (*func) (bfd *abfd, asection *sect, void *obj), void *obj); 680Call the provided function @var{func} for each section 681attached to the BFD @var{abfd}, passing @var{obj} as an 682argument. The function will be called as if by 683 684@example 685 func (abfd, the_section, obj); 686@end example 687 688This is the preferred method for iterating over sections; an 689alternative would be to use a loop: 690 691@example 692 asection *p; 693 for (p = abfd->sections; p != NULL; p = p->next) 694 func (abfd, p, ...) 695@end example 696 697@end deftypefn 698@findex bfd_sections_find_if 699@subsubsection @code{bfd_sections_find_if} 700@deftypefn {Function} asection *bfd_sections_find_if (bfd *abfd, bool (*operation) (bfd *abfd, asection *sect, void *obj), void *obj); 701Call the provided function @var{operation} for each section 702attached to the BFD @var{abfd}, passing @var{obj} as an 703argument. The function will be called as if by 704 705@example 706 operation (abfd, the_section, obj); 707@end example 708 709It returns the first section for which @var{operation} returns true. 710 711@end deftypefn 712@findex bfd_set_section_size 713@subsubsection @code{bfd_set_section_size} 714@deftypefn {Function} bool bfd_set_section_size (asection *sec, bfd_size_type val); 715Set @var{sec} to the size @var{val}. If the operation is 716ok, then @code{TRUE} is returned, else @code{FALSE}. 717 718Possible error returns: 719@itemize @bullet 720 721@item 722@code{bfd_error_invalid_operation} - 723Writing has started to the BFD, so setting the size is invalid. 724@end itemize 725 726@end deftypefn 727@findex bfd_set_section_contents 728@subsubsection @code{bfd_set_section_contents} 729@deftypefn {Function} bool bfd_set_section_contents (bfd *abfd, asection *section, const void *data, file_ptr offset, bfd_size_type count); 730Sets the contents of the section @var{section} in BFD 731@var{abfd} to the data starting in memory at @var{location}. 732The data is written to the output section starting at offset 733@var{offset} for @var{count} octets. 734 735Normally @code{TRUE} is returned, but @code{FALSE} is returned if 736there was an error. Possible error returns are: 737@itemize @bullet 738 739@item 740@code{bfd_error_no_contents} - 741The output section does not have the @code{SEC_HAS_CONTENTS} 742attribute, so nothing can be written to it. 743@item 744@code{bfd_error_bad_value} - 745The section is unable to contain all of the data. 746@item 747@code{bfd_error_invalid_operation} - 748The BFD is not writeable. 749@item 750and some more too. 751@end itemize 752This routine is front end to the back end function 753@code{_bfd_set_section_contents}. 754 755@end deftypefn 756@findex bfd_get_section_contents 757@subsubsection @code{bfd_get_section_contents} 758@deftypefn {Function} bool bfd_get_section_contents (bfd *abfd, asection *section, void *location, file_ptr offset, bfd_size_type count); 759Read data from @var{section} in BFD @var{abfd} 760into memory starting at @var{location}. The data is read at an 761offset of @var{offset} from the start of the input section, 762and is read for @var{count} bytes. 763 764If the contents of a constructor with the @code{SEC_CONSTRUCTOR} 765flag set are requested or if the section does not have the 766@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled 767with zeroes. If no errors occur, @code{TRUE} is returned, else 768@code{FALSE}. 769 770@end deftypefn 771@findex bfd_malloc_and_get_section 772@subsubsection @code{bfd_malloc_and_get_section} 773@deftypefn {Function} bool bfd_malloc_and_get_section (bfd *abfd, asection *section, bfd_byte **buf); 774Read all data from @var{section} in BFD @var{abfd} 775into a buffer, *@var{buf}, malloc'd by this function. 776Return @code{true} on success, @code{false} on failure in which 777case *@var{buf} will be NULL. 778 779@end deftypefn 780@findex bfd_copy_private_section_data 781@subsubsection @code{bfd_copy_private_section_data} 782@deftypefn {Function} bool bfd_copy_private_section_data (bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 783Copy private section information from @var{isec} in the BFD 784@var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 785Return @code{TRUE} on success, @code{FALSE} on error. Possible error 786returns are: 787 788@itemize @bullet 789 790@item 791@code{bfd_error_no_memory} - 792Not enough memory exists to create private data for @var{osec}. 793@end itemize 794@example 795#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ 796 BFD_SEND (obfd, _bfd_copy_private_section_data, \ 797 (ibfd, isection, obfd, osection)) 798@end example 799 800@end deftypefn 801@findex bfd_generic_is_group_section 802@subsubsection @code{bfd_generic_is_group_section} 803@deftypefn {Function} bool bfd_generic_is_group_section (bfd *, const asection *sec); 804Returns TRUE if @var{sec} is a member of a group. 805 806@end deftypefn 807@findex bfd_generic_group_name 808@subsubsection @code{bfd_generic_group_name} 809@deftypefn {Function} const char *bfd_generic_group_name (bfd *, const asection *sec); 810Returns group name if @var{sec} is a member of a group. 811 812@end deftypefn 813@findex bfd_generic_discard_group 814@subsubsection @code{bfd_generic_discard_group} 815@deftypefn {Function} bool bfd_generic_discard_group (bfd *abfd, asection *group); 816Remove all members of @var{group} from the output. 817 818@end deftypefn 819@findex _bfd_section_size_insane 820@subsubsection @code{_bfd_section_size_insane} 821@deftypefn {Function} bool _bfd_section_size_insane (bfd *abfd, asection *sec); 822Returns true if the given section has a size that indicates 823it cannot be read from file. Return false if the size is OK 824or* this function can't say one way or the other. 825 826@end deftypefn 827