175fd0b74Schristos@section Sections 275fd0b74SchristosThe raw data contained within a BFD is maintained through the 375fd0b74Schristossection abstraction. A single BFD may have any number of 475fd0b74Schristossections. It keeps hold of them by pointing to the first; 575fd0b74Schristoseach one points to the next in the list. 675fd0b74Schristos 775fd0b74SchristosSections are supported in BFD in @code{section.c}. 875fd0b74Schristos 975fd0b74Schristos@menu 1075fd0b74Schristos* Section Input:: 1175fd0b74Schristos* Section Output:: 1275fd0b74Schristos* typedef asection:: 1375fd0b74Schristos* section prototypes:: 1475fd0b74Schristos@end menu 1575fd0b74Schristos 1675fd0b74Schristos@node Section Input, Section Output, Sections, Sections 1775fd0b74Schristos@subsection Section input 1875fd0b74SchristosWhen a BFD is opened for reading, the section structures are 1975fd0b74Schristoscreated and attached to the BFD. 2075fd0b74Schristos 2175fd0b74SchristosEach section has a name which describes the section in the 2275fd0b74Schristosoutside world---for example, @code{a.out} would contain at least 2375fd0b74Schristosthree sections, called @code{.text}, @code{.data} and @code{.bss}. 2475fd0b74Schristos 2575fd0b74SchristosNames need not be unique; for example a COFF file may have several 2675fd0b74Schristossections named @code{.data}. 2775fd0b74Schristos 2875fd0b74SchristosSometimes a BFD will contain more than the ``natural'' number of 2975fd0b74Schristossections. A back end may attach other sections containing 3075fd0b74Schristosconstructor data, or an application may add a section (using 3175fd0b74Schristos@code{bfd_make_section}) to the sections attached to an already open 3275fd0b74SchristosBFD. For example, the linker creates an extra section 3375fd0b74Schristos@code{COMMON} for each input file's BFD to hold information about 3475fd0b74Schristoscommon storage. 3575fd0b74Schristos 3675fd0b74SchristosThe raw data is not necessarily read in when 3775fd0b74Schristosthe section descriptor is created. Some targets may leave the 3875fd0b74Schristosdata in place until a @code{bfd_get_section_contents} call is 3975fd0b74Schristosmade. Other back ends may read in all the data at once. For 4075fd0b74Schristosexample, an S-record file has to be read once to determine the 41ede78133Schristossize of the data. 4275fd0b74Schristos 4375fd0b74Schristos@node Section Output, typedef asection, Section Input, Sections 4475fd0b74Schristos@subsection Section output 4575fd0b74SchristosTo write a new object style BFD, the various sections to be 4675fd0b74Schristoswritten have to be created. They are attached to the BFD in 4775fd0b74Schristosthe same way as input sections; data is written to the 4875fd0b74Schristossections using @code{bfd_set_section_contents}. 4975fd0b74Schristos 5075fd0b74SchristosAny program that creates or combines sections (e.g., the assembler 5175fd0b74Schristosand linker) must use the @code{asection} fields @code{output_section} and 5275fd0b74Schristos@code{output_offset} to indicate the file sections to which each 5375fd0b74Schristossection must be written. (If the section is being created from 5475fd0b74Schristosscratch, @code{output_section} should probably point to the section 5575fd0b74Schristositself and @code{output_offset} should probably be zero.) 5675fd0b74Schristos 5775fd0b74SchristosThe data to be written comes from input sections attached 5875fd0b74Schristos(via @code{output_section} pointers) to 5975fd0b74Schristosthe output sections. The output section structure can be 6075fd0b74Schristosconsidered a filter for the input section: the output section 6175fd0b74Schristosdetermines the vma of the output data and the name, but the 6275fd0b74Schristosinput section determines the offset into the output section of 6375fd0b74Schristosthe data to be written. 6475fd0b74Schristos 6575fd0b74SchristosE.g., to create a section "O", starting at 0x100, 0x123 long, 6675fd0b74Schristoscontaining two subsections, "A" at offset 0x0 (i.e., at vma 6775fd0b74Schristos0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the @code{asection} 6875fd0b74Schristosstructures would look like: 6975fd0b74Schristos 7075fd0b74Schristos@example 7175fd0b74Schristos section name "A" 7275fd0b74Schristos output_offset 0x00 7375fd0b74Schristos size 0x20 7475fd0b74Schristos output_section -----------> section name "O" 7575fd0b74Schristos | vma 0x100 7675fd0b74Schristos section name "B" | size 0x123 7775fd0b74Schristos output_offset 0x20 | 7875fd0b74Schristos size 0x103 | 7975fd0b74Schristos output_section --------| 8075fd0b74Schristos@end example 8175fd0b74Schristos 8275fd0b74Schristos@subsection Link orders 8375fd0b74SchristosThe data within a section is stored in a @dfn{link_order}. 8475fd0b74SchristosThese are much like the fixups in @code{gas}. The link_order 8575fd0b74Schristosabstraction allows a section to grow and shrink within itself. 8675fd0b74Schristos 8775fd0b74SchristosA link_order knows how big it is, and which is the next 8875fd0b74Schristoslink_order and where the raw data for it is; it also points to 8975fd0b74Schristosa list of relocations which apply to it. 9075fd0b74Schristos 9175fd0b74SchristosThe link_order is used by the linker to perform relaxing on 9275fd0b74Schristosfinal code. The compiler creates code which is as big as 9375fd0b74Schristosnecessary to make it work without relaxing, and the user can 9475fd0b74Schristosselect whether to relax. Sometimes relaxing takes a lot of 9575fd0b74Schristostime. The linker runs around the relocations to see if any 9675fd0b74Schristosare attached to data which can be shrunk, if so it does it on 9775fd0b74Schristosa link_order by link_order basis. 9875fd0b74Schristos 9975fd0b74Schristos 10075fd0b74Schristos@node typedef asection, section prototypes, Section Output, Sections 10175fd0b74Schristos@subsection typedef asection 10275fd0b74SchristosHere is the section structure: 10375fd0b74Schristos 10475fd0b74Schristos 10575fd0b74Schristos@example 10675fd0b74Schristos 10775fd0b74Schristostypedef struct bfd_section 10875fd0b74Schristos@{ 10975fd0b74Schristos /* The name of the section; the name isn't a copy, the pointer is 11075fd0b74Schristos the same as that passed to bfd_make_section. */ 11175fd0b74Schristos const char *name; 11275fd0b74Schristos 11375fd0b74Schristos /* The next section in the list belonging to the BFD, or NULL. */ 11475fd0b74Schristos struct bfd_section *next; 11575fd0b74Schristos 11675fd0b74Schristos /* The previous section in the list belonging to the BFD, or NULL. */ 11775fd0b74Schristos struct bfd_section *prev; 11875fd0b74Schristos 119*e992f068Schristos /* A unique sequence number. */ 120*e992f068Schristos unsigned int id; 121*e992f068Schristos 122*e992f068Schristos /* A unique section number which can be used by assembler to 123*e992f068Schristos distinguish different sections with the same section name. */ 124*e992f068Schristos unsigned int section_id; 125*e992f068Schristos 126*e992f068Schristos /* Which section in the bfd; 0..n-1 as sections are created in a bfd. */ 127*e992f068Schristos unsigned int index; 128*e992f068Schristos 12975fd0b74Schristos /* The field flags contains attributes of the section. Some 13075fd0b74Schristos flags are read in from the object file, and some are 13175fd0b74Schristos synthesized from other information. */ 13275fd0b74Schristos flagword flags; 13375fd0b74Schristos 134ede78133Schristos#define SEC_NO_FLAGS 0x0 13575fd0b74Schristos 13675fd0b74Schristos /* Tells the OS to allocate space for this section when loading. 13775fd0b74Schristos This is clear for a section containing debug information only. */ 138ede78133Schristos#define SEC_ALLOC 0x1 13975fd0b74Schristos 14075fd0b74Schristos /* Tells the OS to load the section from the file when loading. 14175fd0b74Schristos This is clear for a .bss section. */ 142ede78133Schristos#define SEC_LOAD 0x2 14375fd0b74Schristos 14475fd0b74Schristos /* The section contains data still to be relocated, so there is 14575fd0b74Schristos some relocation information too. */ 146ede78133Schristos#define SEC_RELOC 0x4 14775fd0b74Schristos 14875fd0b74Schristos /* A signal to the OS that the section contains read only data. */ 149ede78133Schristos#define SEC_READONLY 0x8 15075fd0b74Schristos 15175fd0b74Schristos /* The section contains code only. */ 152ede78133Schristos#define SEC_CODE 0x10 15375fd0b74Schristos 15475fd0b74Schristos /* The section contains data only. */ 155ede78133Schristos#define SEC_DATA 0x20 15675fd0b74Schristos 15775fd0b74Schristos /* The section will reside in ROM. */ 158ede78133Schristos#define SEC_ROM 0x40 15975fd0b74Schristos 16075fd0b74Schristos /* The section contains constructor information. This section 16175fd0b74Schristos type is used by the linker to create lists of constructors and 16275fd0b74Schristos destructors used by @code{g++}. When a back end sees a symbol 16375fd0b74Schristos which should be used in a constructor list, it creates a new 16475fd0b74Schristos section for the type of name (e.g., @code{__CTOR_LIST__}), attaches 16575fd0b74Schristos the symbol to it, and builds a relocation. To build the lists 16675fd0b74Schristos of constructors, all the linker has to do is catenate all the 16775fd0b74Schristos sections called @code{__CTOR_LIST__} and relocate the data 16875fd0b74Schristos contained within - exactly the operations it would peform on 16975fd0b74Schristos standard data. */ 170ede78133Schristos#define SEC_CONSTRUCTOR 0x80 17175fd0b74Schristos 17275fd0b74Schristos /* The section has contents - a data section could be 17375fd0b74Schristos @code{SEC_ALLOC} | @code{SEC_HAS_CONTENTS}; a debug section could be 17475fd0b74Schristos @code{SEC_HAS_CONTENTS} */ 17575fd0b74Schristos#define SEC_HAS_CONTENTS 0x100 17675fd0b74Schristos 17775fd0b74Schristos /* An instruction to the linker to not output the section 17875fd0b74Schristos even if it has information which would normally be written. */ 17975fd0b74Schristos#define SEC_NEVER_LOAD 0x200 18075fd0b74Schristos 18175fd0b74Schristos /* The section contains thread local data. */ 18275fd0b74Schristos#define SEC_THREAD_LOCAL 0x400 18375fd0b74Schristos 184ede78133Schristos /* The section's size is fixed. Generic linker code will not 185ede78133Schristos recalculate it and it is up to whoever has set this flag to 186ede78133Schristos get the size right. */ 187ede78133Schristos#define SEC_FIXED_SIZE 0x800 18875fd0b74Schristos 18975fd0b74Schristos /* The section contains common symbols (symbols may be defined 19075fd0b74Schristos multiple times, the value of a symbol is the amount of 19175fd0b74Schristos space it requires, and the largest symbol value is the one 19275fd0b74Schristos used). Most targets have exactly one of these (which we 19375fd0b74Schristos translate to bfd_com_section_ptr), but ECOFF has two. */ 19475fd0b74Schristos#define SEC_IS_COMMON 0x1000 19575fd0b74Schristos 19675fd0b74Schristos /* The section contains only debugging information. For 19775fd0b74Schristos example, this is set for ELF .debug and .stab sections. 19875fd0b74Schristos strip tests this flag to see if a section can be 19975fd0b74Schristos discarded. */ 20075fd0b74Schristos#define SEC_DEBUGGING 0x2000 20175fd0b74Schristos 20275fd0b74Schristos /* The contents of this section are held in memory pointed to 20375fd0b74Schristos by the contents field. This is checked by bfd_get_section_contents, 20475fd0b74Schristos and the data is retrieved from memory if appropriate. */ 20575fd0b74Schristos#define SEC_IN_MEMORY 0x4000 20675fd0b74Schristos 20775fd0b74Schristos /* The contents of this section are to be excluded by the 20875fd0b74Schristos linker for executable and shared objects unless those 20975fd0b74Schristos objects are to be further relocated. */ 21075fd0b74Schristos#define SEC_EXCLUDE 0x8000 21175fd0b74Schristos 21275fd0b74Schristos /* The contents of this section are to be sorted based on the sum of 21375fd0b74Schristos the symbol and addend values specified by the associated relocation 21475fd0b74Schristos entries. Entries without associated relocation entries will be 21575fd0b74Schristos appended to the end of the section in an unspecified order. */ 21675fd0b74Schristos#define SEC_SORT_ENTRIES 0x10000 21775fd0b74Schristos 21875fd0b74Schristos /* When linking, duplicate sections of the same name should be 21975fd0b74Schristos discarded, rather than being combined into a single section as 22075fd0b74Schristos is usually done. This is similar to how common symbols are 22175fd0b74Schristos handled. See SEC_LINK_DUPLICATES below. */ 22275fd0b74Schristos#define SEC_LINK_ONCE 0x20000 22375fd0b74Schristos 22475fd0b74Schristos /* If SEC_LINK_ONCE is set, this bitfield describes how the linker 22575fd0b74Schristos should handle duplicate sections. */ 22675fd0b74Schristos#define SEC_LINK_DUPLICATES 0xc0000 22775fd0b74Schristos 22875fd0b74Schristos /* This value for SEC_LINK_DUPLICATES means that duplicate 22975fd0b74Schristos sections with the same name should simply be discarded. */ 23075fd0b74Schristos#define SEC_LINK_DUPLICATES_DISCARD 0x0 23175fd0b74Schristos 23275fd0b74Schristos /* This value for SEC_LINK_DUPLICATES means that the linker 23375fd0b74Schristos should warn if there are any duplicate sections, although 23475fd0b74Schristos it should still only link one copy. */ 23575fd0b74Schristos#define SEC_LINK_DUPLICATES_ONE_ONLY 0x40000 23675fd0b74Schristos 23775fd0b74Schristos /* This value for SEC_LINK_DUPLICATES means that the linker 23875fd0b74Schristos should warn if any duplicate sections are a different size. */ 23975fd0b74Schristos#define SEC_LINK_DUPLICATES_SAME_SIZE 0x80000 24075fd0b74Schristos 24175fd0b74Schristos /* This value for SEC_LINK_DUPLICATES means that the linker 24275fd0b74Schristos should warn if any duplicate sections contain different 24375fd0b74Schristos contents. */ 24475fd0b74Schristos#define SEC_LINK_DUPLICATES_SAME_CONTENTS \ 24575fd0b74Schristos (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE) 24675fd0b74Schristos 24775fd0b74Schristos /* This section was created by the linker as part of dynamic 24875fd0b74Schristos relocation or other arcane processing. It is skipped when 24975fd0b74Schristos going through the first-pass output, trusting that someone 25075fd0b74Schristos else up the line will take care of it later. */ 25175fd0b74Schristos#define SEC_LINKER_CREATED 0x100000 25275fd0b74Schristos 253*e992f068Schristos /* This section contains a section ID to distinguish different 254*e992f068Schristos sections with the same section name. */ 255*e992f068Schristos#define SEC_ASSEMBLER_SECTION_ID 0x100000 256*e992f068Schristos 25775fd0b74Schristos /* This section should not be subject to garbage collection. 25875fd0b74Schristos Also set to inform the linker that this section should not be 25975fd0b74Schristos listed in the link map as discarded. */ 26075fd0b74Schristos#define SEC_KEEP 0x200000 26175fd0b74Schristos 26275fd0b74Schristos /* This section contains "short" data, and should be placed 26375fd0b74Schristos "near" the GP. */ 26475fd0b74Schristos#define SEC_SMALL_DATA 0x400000 26575fd0b74Schristos 26675fd0b74Schristos /* Attempt to merge identical entities in the section. 26775fd0b74Schristos Entity size is given in the entsize field. */ 26875fd0b74Schristos#define SEC_MERGE 0x800000 26975fd0b74Schristos 27075fd0b74Schristos /* If given with SEC_MERGE, entities to merge are zero terminated 27175fd0b74Schristos strings where entsize specifies character size instead of fixed 27275fd0b74Schristos size entries. */ 27375fd0b74Schristos#define SEC_STRINGS 0x1000000 27475fd0b74Schristos 27575fd0b74Schristos /* This section contains data about section groups. */ 27675fd0b74Schristos#define SEC_GROUP 0x2000000 27775fd0b74Schristos 27875fd0b74Schristos /* The section is a COFF shared library section. This flag is 27975fd0b74Schristos only for the linker. If this type of section appears in 28075fd0b74Schristos the input file, the linker must copy it to the output file 28175fd0b74Schristos without changing the vma or size. FIXME: Although this 28275fd0b74Schristos was originally intended to be general, it really is COFF 28375fd0b74Schristos specific (and the flag was renamed to indicate this). It 28475fd0b74Schristos might be cleaner to have some more general mechanism to 28575fd0b74Schristos allow the back end to control what the linker does with 28675fd0b74Schristos sections. */ 28775fd0b74Schristos#define SEC_COFF_SHARED_LIBRARY 0x4000000 28875fd0b74Schristos 28975fd0b74Schristos /* This input section should be copied to output in reverse order 29075fd0b74Schristos as an array of pointers. This is for ELF linker internal use 29175fd0b74Schristos only. */ 29275fd0b74Schristos#define SEC_ELF_REVERSE_COPY 0x4000000 29375fd0b74Schristos 29475fd0b74Schristos /* This section contains data which may be shared with other 29575fd0b74Schristos executables or shared objects. This is for COFF only. */ 29675fd0b74Schristos#define SEC_COFF_SHARED 0x8000000 29775fd0b74Schristos 29875fd0b74Schristos /* This section should be compressed. This is for ELF linker 29975fd0b74Schristos internal use only. */ 30075fd0b74Schristos#define SEC_ELF_COMPRESS 0x8000000 30175fd0b74Schristos 30275fd0b74Schristos /* When a section with this flag is being linked, then if the size of 30375fd0b74Schristos the input section is less than a page, it should not cross a page 30475fd0b74Schristos boundary. If the size of the input section is one page or more, 30575fd0b74Schristos it should be aligned on a page boundary. This is for TI 30675fd0b74Schristos TMS320C54X only. */ 30775fd0b74Schristos#define SEC_TIC54X_BLOCK 0x10000000 30875fd0b74Schristos 30975fd0b74Schristos /* This section should be renamed. This is for ELF linker 31075fd0b74Schristos internal use only. */ 31175fd0b74Schristos#define SEC_ELF_RENAME 0x10000000 31275fd0b74Schristos 31375fd0b74Schristos /* Conditionally link this section; do not link if there are no 31475fd0b74Schristos references found to any symbol in the section. This is for TI 31575fd0b74Schristos TMS320C54X only. */ 31675fd0b74Schristos#define SEC_TIC54X_CLINK 0x20000000 31775fd0b74Schristos 31875fd0b74Schristos /* This section contains vliw code. This is for Toshiba MeP only. */ 31975fd0b74Schristos#define SEC_MEP_VLIW 0x20000000 32075fd0b74Schristos 321012573ebSchristos /* All symbols, sizes and relocations in this section are octets 322012573ebSchristos instead of bytes. Required for DWARF debug sections as DWARF 323012573ebSchristos information is organized in octets, not bytes. */ 324012573ebSchristos#define SEC_ELF_OCTETS 0x40000000 325012573ebSchristos 32675fd0b74Schristos /* Indicate that section has the no read flag set. This happens 32775fd0b74Schristos when memory read flag isn't set. */ 32875fd0b74Schristos#define SEC_COFF_NOREAD 0x40000000 32975fd0b74Schristos 330ede78133Schristos /* Indicate that section has the purecode flag set. */ 331ede78133Schristos#define SEC_ELF_PURECODE 0x80000000 33275fd0b74Schristos 33375fd0b74Schristos /* End of section flags. */ 33475fd0b74Schristos 33575fd0b74Schristos /* Some internal packed boolean fields. */ 33675fd0b74Schristos 33775fd0b74Schristos /* See the vma field. */ 33875fd0b74Schristos unsigned int user_set_vma : 1; 33975fd0b74Schristos 34075fd0b74Schristos /* A mark flag used by some of the linker backends. */ 34175fd0b74Schristos unsigned int linker_mark : 1; 34275fd0b74Schristos 34375fd0b74Schristos /* Another mark flag used by some of the linker backends. Set for 34475fd0b74Schristos output sections that have an input section. */ 34575fd0b74Schristos unsigned int linker_has_input : 1; 34675fd0b74Schristos 34775fd0b74Schristos /* Mark flag used by some linker backends for garbage collection. */ 34875fd0b74Schristos unsigned int gc_mark : 1; 34975fd0b74Schristos 35075fd0b74Schristos /* Section compression status. */ 35175fd0b74Schristos unsigned int compress_status : 2; 35275fd0b74Schristos#define COMPRESS_SECTION_NONE 0 35375fd0b74Schristos#define COMPRESS_SECTION_DONE 1 35475fd0b74Schristos#define DECOMPRESS_SECTION_SIZED 2 35575fd0b74Schristos 35675fd0b74Schristos /* The following flags are used by the ELF linker. */ 35775fd0b74Schristos 35875fd0b74Schristos /* Mark sections which have been allocated to segments. */ 35975fd0b74Schristos unsigned int segment_mark : 1; 36075fd0b74Schristos 36175fd0b74Schristos /* Type of sec_info information. */ 36275fd0b74Schristos unsigned int sec_info_type:3; 36375fd0b74Schristos#define SEC_INFO_TYPE_NONE 0 36475fd0b74Schristos#define SEC_INFO_TYPE_STABS 1 36575fd0b74Schristos#define SEC_INFO_TYPE_MERGE 2 36675fd0b74Schristos#define SEC_INFO_TYPE_EH_FRAME 3 36775fd0b74Schristos#define SEC_INFO_TYPE_JUST_SYMS 4 36875fd0b74Schristos#define SEC_INFO_TYPE_TARGET 5 36975fd0b74Schristos#define SEC_INFO_TYPE_EH_FRAME_ENTRY 6 37075fd0b74Schristos 37175fd0b74Schristos /* Nonzero if this section uses RELA relocations, rather than REL. */ 37275fd0b74Schristos unsigned int use_rela_p:1; 37375fd0b74Schristos 37475fd0b74Schristos /* Bits used by various backends. The generic code doesn't touch 37575fd0b74Schristos these fields. */ 37675fd0b74Schristos 37775fd0b74Schristos unsigned int sec_flg0:1; 37875fd0b74Schristos unsigned int sec_flg1:1; 37975fd0b74Schristos unsigned int sec_flg2:1; 38075fd0b74Schristos unsigned int sec_flg3:1; 38175fd0b74Schristos unsigned int sec_flg4:1; 38275fd0b74Schristos unsigned int sec_flg5:1; 38375fd0b74Schristos 38475fd0b74Schristos /* End of internal packed boolean fields. */ 38575fd0b74Schristos 38675fd0b74Schristos /* The virtual memory address of the section - where it will be 38775fd0b74Schristos at run time. The symbols are relocated against this. The 38875fd0b74Schristos user_set_vma flag is maintained by bfd; if it's not set, the 38975fd0b74Schristos backend can assign addresses (for example, in @code{a.out}, where 39075fd0b74Schristos the default address for @code{.data} is dependent on the specific 39175fd0b74Schristos target and various flags). */ 39275fd0b74Schristos bfd_vma vma; 39375fd0b74Schristos 39475fd0b74Schristos /* The load address of the section - where it would be in a 39575fd0b74Schristos rom image; really only used for writing section header 39675fd0b74Schristos information. */ 39775fd0b74Schristos bfd_vma lma; 39875fd0b74Schristos 39975fd0b74Schristos /* The size of the section in *octets*, as it will be output. 40075fd0b74Schristos Contains a value even if the section has no contents (e.g., the 40175fd0b74Schristos size of @code{.bss}). */ 40275fd0b74Schristos bfd_size_type size; 40375fd0b74Schristos 40475fd0b74Schristos /* For input sections, the original size on disk of the section, in 40575fd0b74Schristos octets. This field should be set for any section whose size is 40675fd0b74Schristos changed by linker relaxation. It is required for sections where 40775fd0b74Schristos the linker relaxation scheme doesn't cache altered section and 40875fd0b74Schristos reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing 40975fd0b74Schristos targets), and thus the original size needs to be kept to read the 41075fd0b74Schristos section multiple times. For output sections, rawsize holds the 41175fd0b74Schristos section size calculated on a previous linker relaxation pass. */ 41275fd0b74Schristos bfd_size_type rawsize; 41375fd0b74Schristos 41475fd0b74Schristos /* The compressed size of the section in octets. */ 41575fd0b74Schristos bfd_size_type compressed_size; 41675fd0b74Schristos 41775fd0b74Schristos /* If this section is going to be output, then this value is the 41875fd0b74Schristos offset in *bytes* into the output section of the first byte in the 41975fd0b74Schristos input section (byte ==> smallest addressable unit on the 42075fd0b74Schristos target). In most cases, if this was going to start at the 42175fd0b74Schristos 100th octet (8-bit quantity) in the output section, this value 42275fd0b74Schristos would be 100. However, if the target byte size is 16 bits 42375fd0b74Schristos (bfd_octets_per_byte is "2"), this value would be 50. */ 42475fd0b74Schristos bfd_vma output_offset; 42575fd0b74Schristos 42675fd0b74Schristos /* The output section through which to map on output. */ 42775fd0b74Schristos struct bfd_section *output_section; 42875fd0b74Schristos 42975fd0b74Schristos /* If an input section, a pointer to a vector of relocation 43075fd0b74Schristos records for the data in this section. */ 43175fd0b74Schristos struct reloc_cache_entry *relocation; 43275fd0b74Schristos 43375fd0b74Schristos /* If an output section, a pointer to a vector of pointers to 43475fd0b74Schristos relocation records for the data in this section. */ 43575fd0b74Schristos struct reloc_cache_entry **orelocation; 43675fd0b74Schristos 43775fd0b74Schristos /* The number of relocation records in one of the above. */ 43875fd0b74Schristos unsigned reloc_count; 43975fd0b74Schristos 440*e992f068Schristos /* The alignment requirement of the section, as an exponent of 2 - 441*e992f068Schristos e.g., 3 aligns to 2^3 (or 8). */ 442*e992f068Schristos unsigned int alignment_power; 443*e992f068Schristos 44475fd0b74Schristos /* Information below is back end specific - and not always used 44575fd0b74Schristos or updated. */ 44675fd0b74Schristos 44775fd0b74Schristos /* File position of section data. */ 44875fd0b74Schristos file_ptr filepos; 44975fd0b74Schristos 45075fd0b74Schristos /* File position of relocation info. */ 45175fd0b74Schristos file_ptr rel_filepos; 45275fd0b74Schristos 45375fd0b74Schristos /* File position of line data. */ 45475fd0b74Schristos file_ptr line_filepos; 45575fd0b74Schristos 45675fd0b74Schristos /* Pointer to data for applications. */ 45775fd0b74Schristos void *userdata; 45875fd0b74Schristos 45975fd0b74Schristos /* If the SEC_IN_MEMORY flag is set, this points to the actual 46075fd0b74Schristos contents. */ 46175fd0b74Schristos unsigned char *contents; 46275fd0b74Schristos 46375fd0b74Schristos /* Attached line number information. */ 46475fd0b74Schristos alent *lineno; 46575fd0b74Schristos 46675fd0b74Schristos /* Number of line number records. */ 46775fd0b74Schristos unsigned int lineno_count; 46875fd0b74Schristos 46975fd0b74Schristos /* Entity size for merging purposes. */ 47075fd0b74Schristos unsigned int entsize; 47175fd0b74Schristos 47275fd0b74Schristos /* Points to the kept section if this section is a link-once section, 47375fd0b74Schristos and is discarded. */ 47475fd0b74Schristos struct bfd_section *kept_section; 47575fd0b74Schristos 47675fd0b74Schristos /* When a section is being output, this value changes as more 47775fd0b74Schristos linenumbers are written out. */ 47875fd0b74Schristos file_ptr moving_line_filepos; 47975fd0b74Schristos 48075fd0b74Schristos /* What the section number is in the target world. */ 48175fd0b74Schristos int target_index; 48275fd0b74Schristos 48375fd0b74Schristos void *used_by_bfd; 48475fd0b74Schristos 48575fd0b74Schristos /* If this is a constructor section then here is a list of the 48675fd0b74Schristos relocations created to relocate items within it. */ 48775fd0b74Schristos struct relent_chain *constructor_chain; 48875fd0b74Schristos 48975fd0b74Schristos /* The BFD which owns the section. */ 49075fd0b74Schristos bfd *owner; 49175fd0b74Schristos 49275fd0b74Schristos /* A symbol which points at this section only. */ 49375fd0b74Schristos struct bfd_symbol *symbol; 49475fd0b74Schristos struct bfd_symbol **symbol_ptr_ptr; 49575fd0b74Schristos 49675fd0b74Schristos /* Early in the link process, map_head and map_tail are used to build 49775fd0b74Schristos a list of input sections attached to an output section. Later, 49875fd0b74Schristos output sections use these fields for a list of bfd_link_order 499*e992f068Schristos structs. The linked_to_symbol_name field is for ELF assembler 500*e992f068Schristos internal use. */ 50175fd0b74Schristos union @{ 50275fd0b74Schristos struct bfd_link_order *link_order; 50375fd0b74Schristos struct bfd_section *s; 504*e992f068Schristos const char *linked_to_symbol_name; 50575fd0b74Schristos @} map_head, map_tail; 506*e992f068Schristos 507*e992f068Schristos /* Points to the output section this section is already assigned to, 508*e992f068Schristos if any. This is used when support for non-contiguous memory 509*e992f068Schristos regions is enabled. */ 510*e992f068Schristos struct bfd_section *already_assigned; 511*e992f068Schristos 512*e992f068Schristos /* Explicitly specified section type, if non-zero. */ 513*e992f068Schristos unsigned int type; 514*e992f068Schristos 51575fd0b74Schristos@} asection; 51675fd0b74Schristos 517012573ebSchristosstatic inline const char * 518012573ebSchristosbfd_section_name (const asection *sec) 519012573ebSchristos@{ 520012573ebSchristos return sec->name; 521012573ebSchristos@} 522012573ebSchristos 523012573ebSchristosstatic inline bfd_size_type 524012573ebSchristosbfd_section_size (const asection *sec) 525012573ebSchristos@{ 526012573ebSchristos return sec->size; 527012573ebSchristos@} 528012573ebSchristos 529012573ebSchristosstatic inline bfd_vma 530012573ebSchristosbfd_section_vma (const asection *sec) 531012573ebSchristos@{ 532012573ebSchristos return sec->vma; 533012573ebSchristos@} 534012573ebSchristos 535012573ebSchristosstatic inline bfd_vma 536012573ebSchristosbfd_section_lma (const asection *sec) 537012573ebSchristos@{ 538012573ebSchristos return sec->lma; 539012573ebSchristos@} 540012573ebSchristos 541012573ebSchristosstatic inline unsigned int 542012573ebSchristosbfd_section_alignment (const asection *sec) 543012573ebSchristos@{ 544012573ebSchristos return sec->alignment_power; 545012573ebSchristos@} 546012573ebSchristos 547012573ebSchristosstatic inline flagword 548012573ebSchristosbfd_section_flags (const asection *sec) 549012573ebSchristos@{ 550012573ebSchristos return sec->flags; 551012573ebSchristos@} 552012573ebSchristos 553012573ebSchristosstatic inline void * 554012573ebSchristosbfd_section_userdata (const asection *sec) 555012573ebSchristos@{ 556012573ebSchristos return sec->userdata; 557012573ebSchristos@} 558*e992f068Schristosstatic inline bool 559012573ebSchristosbfd_is_com_section (const asection *sec) 560012573ebSchristos@{ 561012573ebSchristos return (sec->flags & SEC_IS_COMMON) != 0; 562012573ebSchristos@} 563012573ebSchristos 56475fd0b74Schristos/* Note: the following are provided as inline functions rather than macros 56575fd0b74Schristos because not all callers use the return value. A macro implementation 56675fd0b74Schristos would use a comma expression, eg: "((ptr)->foo = val, TRUE)" and some 56775fd0b74Schristos compilers will complain about comma expressions that have no effect. */ 568*e992f068Schristosstatic inline bool 569012573ebSchristosbfd_set_section_userdata (asection *sec, void *val) 57075fd0b74Schristos@{ 571012573ebSchristos sec->userdata = val; 572*e992f068Schristos return true; 57375fd0b74Schristos@} 57475fd0b74Schristos 575*e992f068Schristosstatic inline bool 576012573ebSchristosbfd_set_section_vma (asection *sec, bfd_vma val) 57775fd0b74Schristos@{ 578012573ebSchristos sec->vma = sec->lma = val; 579*e992f068Schristos sec->user_set_vma = true; 580*e992f068Schristos return true; 58175fd0b74Schristos@} 58275fd0b74Schristos 583*e992f068Schristosstatic inline bool 584012573ebSchristosbfd_set_section_lma (asection *sec, bfd_vma val) 58575fd0b74Schristos@{ 586012573ebSchristos sec->lma = val; 587*e992f068Schristos return true; 588012573ebSchristos@} 589012573ebSchristos 590*e992f068Schristosstatic inline bool 591012573ebSchristosbfd_set_section_alignment (asection *sec, unsigned int val) 592012573ebSchristos@{ 593012573ebSchristos sec->alignment_power = val; 594*e992f068Schristos return true; 59575fd0b74Schristos@} 59675fd0b74Schristos 59775fd0b74Schristos/* These sections are global, and are managed by BFD. The application 59875fd0b74Schristos and target back end are not permitted to change the values in 59975fd0b74Schristos these sections. */ 60075fd0b74Schristosextern asection _bfd_std_section[4]; 60175fd0b74Schristos 60275fd0b74Schristos#define BFD_ABS_SECTION_NAME "*ABS*" 60375fd0b74Schristos#define BFD_UND_SECTION_NAME "*UND*" 60475fd0b74Schristos#define BFD_COM_SECTION_NAME "*COM*" 60575fd0b74Schristos#define BFD_IND_SECTION_NAME "*IND*" 60675fd0b74Schristos 60775fd0b74Schristos/* Pointer to the common section. */ 60875fd0b74Schristos#define bfd_com_section_ptr (&_bfd_std_section[0]) 60975fd0b74Schristos/* Pointer to the undefined section. */ 61075fd0b74Schristos#define bfd_und_section_ptr (&_bfd_std_section[1]) 61175fd0b74Schristos/* Pointer to the absolute section. */ 61275fd0b74Schristos#define bfd_abs_section_ptr (&_bfd_std_section[2]) 61375fd0b74Schristos/* Pointer to the indirect section. */ 61475fd0b74Schristos#define bfd_ind_section_ptr (&_bfd_std_section[3]) 61575fd0b74Schristos 616*e992f068Schristosstatic inline bool 617012573ebSchristosbfd_is_und_section (const asection *sec) 618012573ebSchristos@{ 619012573ebSchristos return sec == bfd_und_section_ptr; 620012573ebSchristos@} 62175fd0b74Schristos 622*e992f068Schristosstatic inline bool 623012573ebSchristosbfd_is_abs_section (const asection *sec) 624012573ebSchristos@{ 625012573ebSchristos return sec == bfd_abs_section_ptr; 626012573ebSchristos@} 62775fd0b74Schristos 628*e992f068Schristosstatic inline bool 629012573ebSchristosbfd_is_ind_section (const asection *sec) 630012573ebSchristos@{ 631012573ebSchristos return sec == bfd_ind_section_ptr; 632012573ebSchristos@} 633012573ebSchristos 634*e992f068Schristosstatic inline bool 635012573ebSchristosbfd_is_const_section (const asection *sec) 636012573ebSchristos@{ 637*e992f068Schristos return (sec >= _bfd_std_section 638*e992f068Schristos && sec < _bfd_std_section + (sizeof (_bfd_std_section) 639*e992f068Schristos / sizeof (_bfd_std_section[0]))); 640012573ebSchristos@} 641012573ebSchristos 642012573ebSchristos/* Return TRUE if input section SEC has been discarded. */ 643*e992f068Schristosstatic inline bool 644012573ebSchristosdiscarded_section (const asection *sec) 645012573ebSchristos@{ 646012573ebSchristos return (!bfd_is_abs_section (sec) 647012573ebSchristos && bfd_is_abs_section (sec->output_section) 648012573ebSchristos && sec->sec_info_type != SEC_INFO_TYPE_MERGE 649012573ebSchristos && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS); 650012573ebSchristos@} 65175fd0b74Schristos 652ede78133Schristos#define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS) \ 653*e992f068Schristos /* name, next, prev, id, section_id, index, flags, user_set_vma, */ \ 654*e992f068Schristos @{ NAME, NULL, NULL, IDX, 0, 0, FLAGS, 0, \ 65575fd0b74Schristos \ 65675fd0b74Schristos /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \ 65775fd0b74Schristos 0, 0, 1, 0, \ 65875fd0b74Schristos \ 65975fd0b74Schristos /* segment_mark, sec_info_type, use_rela_p, */ \ 66075fd0b74Schristos 0, 0, 0, \ 66175fd0b74Schristos \ 66275fd0b74Schristos /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \ 66375fd0b74Schristos 0, 0, 0, 0, 0, 0, \ 66475fd0b74Schristos \ 665*e992f068Schristos /* vma, lma, size, rawsize, compressed_size, */ \ 666*e992f068Schristos 0, 0, 0, 0, 0, \ 66775fd0b74Schristos \ 668*e992f068Schristos /* output_offset, output_section, relocation, orelocation, */ \ 669*e992f068Schristos 0, &SEC, NULL, NULL, \ 67075fd0b74Schristos \ 671*e992f068Schristos /* reloc_count, alignment_power, filepos, rel_filepos, */ \ 672*e992f068Schristos 0, 0, 0, 0, \ 67375fd0b74Schristos \ 67475fd0b74Schristos /* line_filepos, userdata, contents, lineno, lineno_count, */ \ 67575fd0b74Schristos 0, NULL, NULL, NULL, 0, \ 67675fd0b74Schristos \ 67775fd0b74Schristos /* entsize, kept_section, moving_line_filepos, */ \ 67875fd0b74Schristos 0, NULL, 0, \ 67975fd0b74Schristos \ 68075fd0b74Schristos /* target_index, used_by_bfd, constructor_chain, owner, */ \ 68175fd0b74Schristos 0, NULL, NULL, NULL, \ 68275fd0b74Schristos \ 68375fd0b74Schristos /* symbol, symbol_ptr_ptr, */ \ 68475fd0b74Schristos (struct bfd_symbol *) SYM, &SEC.symbol, \ 68575fd0b74Schristos \ 686*e992f068Schristos /* map_head, map_tail, already_assigned, type */ \ 687*e992f068Schristos @{ NULL @}, @{ NULL @}, NULL, 0 \ 688*e992f068Schristos \ 68975fd0b74Schristos @} 69075fd0b74Schristos 691ede78133Schristos/* We use a macro to initialize the static asymbol structures because 692ede78133Schristos traditional C does not permit us to initialize a union member while 693ede78133Schristos gcc warns if we don't initialize it. 694ede78133Schristos the_bfd, name, value, attr, section [, udata] */ 695ede78133Schristos#ifdef __STDC__ 696ede78133Schristos#define GLOBAL_SYM_INIT(NAME, SECTION) \ 697ede78133Schristos @{ 0, NAME, 0, BSF_SECTION_SYM, SECTION, @{ 0 @}@} 698ede78133Schristos#else 699ede78133Schristos#define GLOBAL_SYM_INIT(NAME, SECTION) \ 700ede78133Schristos @{ 0, NAME, 0, BSF_SECTION_SYM, SECTION @} 701ede78133Schristos#endif 702ede78133Schristos 70375fd0b74Schristos@end example 70475fd0b74Schristos 70575fd0b74Schristos@node section prototypes, , typedef asection, Sections 70675fd0b74Schristos@subsection Section prototypes 70775fd0b74SchristosThese are the functions exported by the section handling part of BFD. 70875fd0b74Schristos 70975fd0b74Schristos@findex bfd_section_list_clear 71075fd0b74Schristos@subsubsection @code{bfd_section_list_clear} 71175fd0b74Schristos@strong{Synopsis} 71275fd0b74Schristos@example 71375fd0b74Schristosvoid bfd_section_list_clear (bfd *); 71475fd0b74Schristos@end example 71575fd0b74Schristos@strong{Description}@* 71675fd0b74SchristosClears the section list, and also resets the section count and 71775fd0b74Schristoshash table entries. 71875fd0b74Schristos 71975fd0b74Schristos@findex bfd_get_section_by_name 72075fd0b74Schristos@subsubsection @code{bfd_get_section_by_name} 72175fd0b74Schristos@strong{Synopsis} 72275fd0b74Schristos@example 72375fd0b74Schristosasection *bfd_get_section_by_name (bfd *abfd, const char *name); 72475fd0b74Schristos@end example 72575fd0b74Schristos@strong{Description}@* 72675fd0b74SchristosReturn the most recently created section attached to @var{abfd} 72775fd0b74Schristosnamed @var{name}. Return NULL if no such section exists. 72875fd0b74Schristos 72975fd0b74Schristos@findex bfd_get_next_section_by_name 73075fd0b74Schristos@subsubsection @code{bfd_get_next_section_by_name} 73175fd0b74Schristos@strong{Synopsis} 73275fd0b74Schristos@example 73375fd0b74Schristosasection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec); 73475fd0b74Schristos@end example 73575fd0b74Schristos@strong{Description}@* 73675fd0b74SchristosGiven @var{sec} is a section returned by @code{bfd_get_section_by_name}, 73775fd0b74Schristosreturn the next most recently created section attached to the same 73875fd0b74SchristosBFD with the same name, or if no such section exists in the same BFD and 73975fd0b74SchristosIBFD is non-NULL, the next section with the same name in any input 74075fd0b74SchristosBFD following IBFD. Return NULL on finding no section. 74175fd0b74Schristos 74275fd0b74Schristos@findex bfd_get_linker_section 74375fd0b74Schristos@subsubsection @code{bfd_get_linker_section} 74475fd0b74Schristos@strong{Synopsis} 74575fd0b74Schristos@example 74675fd0b74Schristosasection *bfd_get_linker_section (bfd *abfd, const char *name); 74775fd0b74Schristos@end example 74875fd0b74Schristos@strong{Description}@* 74975fd0b74SchristosReturn the linker created section attached to @var{abfd} 75075fd0b74Schristosnamed @var{name}. Return NULL if no such section exists. 75175fd0b74Schristos 75275fd0b74Schristos@findex bfd_get_section_by_name_if 75375fd0b74Schristos@subsubsection @code{bfd_get_section_by_name_if} 75475fd0b74Schristos@strong{Synopsis} 75575fd0b74Schristos@example 75675fd0b74Schristosasection *bfd_get_section_by_name_if 75775fd0b74Schristos (bfd *abfd, 75875fd0b74Schristos const char *name, 759*e992f068Schristos bool (*func) (bfd *abfd, asection *sect, void *obj), 76075fd0b74Schristos void *obj); 76175fd0b74Schristos@end example 76275fd0b74Schristos@strong{Description}@* 76375fd0b74SchristosCall the provided function @var{func} for each section 76475fd0b74Schristosattached to the BFD @var{abfd} whose name matches @var{name}, 76575fd0b74Schristospassing @var{obj} as an argument. The function will be called 76675fd0b74Schristosas if by 76775fd0b74Schristos 76875fd0b74Schristos@example 76975fd0b74Schristos func (abfd, the_section, obj); 77075fd0b74Schristos@end example 77175fd0b74Schristos 77275fd0b74SchristosIt returns the first section for which @var{func} returns true, 77375fd0b74Schristosotherwise @code{NULL}. 77475fd0b74Schristos 77575fd0b74Schristos@findex bfd_get_unique_section_name 77675fd0b74Schristos@subsubsection @code{bfd_get_unique_section_name} 77775fd0b74Schristos@strong{Synopsis} 77875fd0b74Schristos@example 77975fd0b74Schristoschar *bfd_get_unique_section_name 78075fd0b74Schristos (bfd *abfd, const char *templat, int *count); 78175fd0b74Schristos@end example 78275fd0b74Schristos@strong{Description}@* 78375fd0b74SchristosInvent a section name that is unique in @var{abfd} by tacking 78475fd0b74Schristosa dot and a digit suffix onto the original @var{templat}. If 78575fd0b74Schristos@var{count} is non-NULL, then it specifies the first number 78675fd0b74Schristostried as a suffix to generate a unique name. The value 78775fd0b74Schristospointed to by @var{count} will be incremented in this case. 78875fd0b74Schristos 78975fd0b74Schristos@findex bfd_make_section_old_way 79075fd0b74Schristos@subsubsection @code{bfd_make_section_old_way} 79175fd0b74Schristos@strong{Synopsis} 79275fd0b74Schristos@example 79375fd0b74Schristosasection *bfd_make_section_old_way (bfd *abfd, const char *name); 79475fd0b74Schristos@end example 79575fd0b74Schristos@strong{Description}@* 79675fd0b74SchristosCreate a new empty section called @var{name} 79775fd0b74Schristosand attach it to the end of the chain of sections for the 79875fd0b74SchristosBFD @var{abfd}. An attempt to create a section with a name which 79975fd0b74Schristosis already in use returns its pointer without changing the 80075fd0b74Schristossection chain. 80175fd0b74Schristos 80275fd0b74SchristosIt has the funny name since this is the way it used to be 80375fd0b74Schristosbefore it was rewritten.... 80475fd0b74Schristos 80575fd0b74SchristosPossible errors are: 80675fd0b74Schristos@itemize @bullet 80775fd0b74Schristos 80875fd0b74Schristos@item 80975fd0b74Schristos@code{bfd_error_invalid_operation} - 81075fd0b74SchristosIf output has already started for this BFD. 81175fd0b74Schristos@item 81275fd0b74Schristos@code{bfd_error_no_memory} - 81375fd0b74SchristosIf memory allocation fails. 81475fd0b74Schristos@end itemize 81575fd0b74Schristos 81675fd0b74Schristos@findex bfd_make_section_anyway_with_flags 81775fd0b74Schristos@subsubsection @code{bfd_make_section_anyway_with_flags} 81875fd0b74Schristos@strong{Synopsis} 81975fd0b74Schristos@example 82075fd0b74Schristosasection *bfd_make_section_anyway_with_flags 82175fd0b74Schristos (bfd *abfd, const char *name, flagword flags); 82275fd0b74Schristos@end example 82375fd0b74Schristos@strong{Description}@* 82475fd0b74SchristosCreate a new empty section called @var{name} and attach it to the end of 82575fd0b74Schristosthe chain of sections for @var{abfd}. Create a new section even if there 82675fd0b74Schristosis already a section with that name. Also set the attributes of the 82775fd0b74Schristosnew section to the value @var{flags}. 82875fd0b74Schristos 82975fd0b74SchristosReturn @code{NULL} and set @code{bfd_error} on error; possible errors are: 83075fd0b74Schristos@itemize @bullet 83175fd0b74Schristos 83275fd0b74Schristos@item 83375fd0b74Schristos@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 83475fd0b74Schristos@item 83575fd0b74Schristos@code{bfd_error_no_memory} - If memory allocation fails. 83675fd0b74Schristos@end itemize 83775fd0b74Schristos 83875fd0b74Schristos@findex bfd_make_section_anyway 83975fd0b74Schristos@subsubsection @code{bfd_make_section_anyway} 84075fd0b74Schristos@strong{Synopsis} 84175fd0b74Schristos@example 84275fd0b74Schristosasection *bfd_make_section_anyway (bfd *abfd, const char *name); 84375fd0b74Schristos@end example 84475fd0b74Schristos@strong{Description}@* 84575fd0b74SchristosCreate a new empty section called @var{name} and attach it to the end of 84675fd0b74Schristosthe chain of sections for @var{abfd}. Create a new section even if there 84775fd0b74Schristosis already a section with that name. 84875fd0b74Schristos 84975fd0b74SchristosReturn @code{NULL} and set @code{bfd_error} on error; possible errors are: 85075fd0b74Schristos@itemize @bullet 85175fd0b74Schristos 85275fd0b74Schristos@item 85375fd0b74Schristos@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}. 85475fd0b74Schristos@item 85575fd0b74Schristos@code{bfd_error_no_memory} - If memory allocation fails. 85675fd0b74Schristos@end itemize 85775fd0b74Schristos 85875fd0b74Schristos@findex bfd_make_section_with_flags 85975fd0b74Schristos@subsubsection @code{bfd_make_section_with_flags} 86075fd0b74Schristos@strong{Synopsis} 86175fd0b74Schristos@example 86275fd0b74Schristosasection *bfd_make_section_with_flags 86375fd0b74Schristos (bfd *, const char *name, flagword flags); 86475fd0b74Schristos@end example 86575fd0b74Schristos@strong{Description}@* 86675fd0b74SchristosLike @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 86775fd0b74Schristosbfd_set_error ()) without changing the section chain if there is already a 86875fd0b74Schristossection named @var{name}. Also set the attributes of the new section to 86975fd0b74Schristosthe value @var{flags}. If there is an error, return @code{NULL} and set 87075fd0b74Schristos@code{bfd_error}. 87175fd0b74Schristos 87275fd0b74Schristos@findex bfd_make_section 87375fd0b74Schristos@subsubsection @code{bfd_make_section} 87475fd0b74Schristos@strong{Synopsis} 87575fd0b74Schristos@example 87675fd0b74Schristosasection *bfd_make_section (bfd *, const char *name); 87775fd0b74Schristos@end example 87875fd0b74Schristos@strong{Description}@* 87975fd0b74SchristosLike @code{bfd_make_section_anyway}, but return @code{NULL} (without calling 88075fd0b74Schristosbfd_set_error ()) without changing the section chain if there is already a 88175fd0b74Schristossection named @var{name}. If there is an error, return @code{NULL} and set 88275fd0b74Schristos@code{bfd_error}. 88375fd0b74Schristos 88475fd0b74Schristos@findex bfd_set_section_flags 88575fd0b74Schristos@subsubsection @code{bfd_set_section_flags} 88675fd0b74Schristos@strong{Synopsis} 88775fd0b74Schristos@example 888*e992f068Schristosbool bfd_set_section_flags (asection *sec, flagword flags); 88975fd0b74Schristos@end example 89075fd0b74Schristos@strong{Description}@* 891012573ebSchristosSet the attributes of the section @var{sec} to the value @var{flags}. 892012573ebSchristosReturn @code{TRUE} on success, @code{FALSE} on error. Possible error 893012573ebSchristosreturns are: 89475fd0b74Schristos 89575fd0b74Schristos@itemize @bullet 89675fd0b74Schristos 89775fd0b74Schristos@item 89875fd0b74Schristos@code{bfd_error_invalid_operation} - 89975fd0b74SchristosThe section cannot have one or more of the attributes 90075fd0b74Schristosrequested. For example, a .bss section in @code{a.out} may not 90175fd0b74Schristoshave the @code{SEC_HAS_CONTENTS} field set. 90275fd0b74Schristos@end itemize 90375fd0b74Schristos 90475fd0b74Schristos@findex bfd_rename_section 90575fd0b74Schristos@subsubsection @code{bfd_rename_section} 90675fd0b74Schristos@strong{Synopsis} 90775fd0b74Schristos@example 90875fd0b74Schristosvoid bfd_rename_section 909012573ebSchristos (asection *sec, const char *newname); 91075fd0b74Schristos@end example 91175fd0b74Schristos@strong{Description}@* 912012573ebSchristosRename section @var{sec} to @var{newname}. 91375fd0b74Schristos 91475fd0b74Schristos@findex bfd_map_over_sections 91575fd0b74Schristos@subsubsection @code{bfd_map_over_sections} 91675fd0b74Schristos@strong{Synopsis} 91775fd0b74Schristos@example 91875fd0b74Schristosvoid bfd_map_over_sections 91975fd0b74Schristos (bfd *abfd, 92075fd0b74Schristos void (*func) (bfd *abfd, asection *sect, void *obj), 92175fd0b74Schristos void *obj); 92275fd0b74Schristos@end example 92375fd0b74Schristos@strong{Description}@* 92475fd0b74SchristosCall the provided function @var{func} for each section 92575fd0b74Schristosattached to the BFD @var{abfd}, passing @var{obj} as an 92675fd0b74Schristosargument. The function will be called as if by 92775fd0b74Schristos 92875fd0b74Schristos@example 92975fd0b74Schristos func (abfd, the_section, obj); 93075fd0b74Schristos@end example 93175fd0b74Schristos 93275fd0b74SchristosThis is the preferred method for iterating over sections; an 93375fd0b74Schristosalternative would be to use a loop: 93475fd0b74Schristos 93575fd0b74Schristos@example 93675fd0b74Schristos asection *p; 93775fd0b74Schristos for (p = abfd->sections; p != NULL; p = p->next) 93875fd0b74Schristos func (abfd, p, ...) 93975fd0b74Schristos@end example 94075fd0b74Schristos 94175fd0b74Schristos@findex bfd_sections_find_if 94275fd0b74Schristos@subsubsection @code{bfd_sections_find_if} 94375fd0b74Schristos@strong{Synopsis} 94475fd0b74Schristos@example 94575fd0b74Schristosasection *bfd_sections_find_if 94675fd0b74Schristos (bfd *abfd, 947*e992f068Schristos bool (*operation) (bfd *abfd, asection *sect, void *obj), 94875fd0b74Schristos void *obj); 94975fd0b74Schristos@end example 95075fd0b74Schristos@strong{Description}@* 95175fd0b74SchristosCall the provided function @var{operation} for each section 95275fd0b74Schristosattached to the BFD @var{abfd}, passing @var{obj} as an 95375fd0b74Schristosargument. The function will be called as if by 95475fd0b74Schristos 95575fd0b74Schristos@example 95675fd0b74Schristos operation (abfd, the_section, obj); 95775fd0b74Schristos@end example 95875fd0b74Schristos 95975fd0b74SchristosIt returns the first section for which @var{operation} returns true. 96075fd0b74Schristos 96175fd0b74Schristos@findex bfd_set_section_size 96275fd0b74Schristos@subsubsection @code{bfd_set_section_size} 96375fd0b74Schristos@strong{Synopsis} 96475fd0b74Schristos@example 965*e992f068Schristosbool bfd_set_section_size (asection *sec, bfd_size_type val); 96675fd0b74Schristos@end example 96775fd0b74Schristos@strong{Description}@* 96875fd0b74SchristosSet @var{sec} to the size @var{val}. If the operation is 96975fd0b74Schristosok, then @code{TRUE} is returned, else @code{FALSE}. 97075fd0b74Schristos 97175fd0b74SchristosPossible error returns: 97275fd0b74Schristos@itemize @bullet 97375fd0b74Schristos 97475fd0b74Schristos@item 97575fd0b74Schristos@code{bfd_error_invalid_operation} - 97675fd0b74SchristosWriting has started to the BFD, so setting the size is invalid. 97775fd0b74Schristos@end itemize 97875fd0b74Schristos 97975fd0b74Schristos@findex bfd_set_section_contents 98075fd0b74Schristos@subsubsection @code{bfd_set_section_contents} 98175fd0b74Schristos@strong{Synopsis} 98275fd0b74Schristos@example 983*e992f068Schristosbool bfd_set_section_contents 98475fd0b74Schristos (bfd *abfd, asection *section, const void *data, 98575fd0b74Schristos file_ptr offset, bfd_size_type count); 98675fd0b74Schristos@end example 98775fd0b74Schristos@strong{Description}@* 98875fd0b74SchristosSets the contents of the section @var{section} in BFD 989012573ebSchristos@var{abfd} to the data starting in memory at @var{location}. 990012573ebSchristosThe data is written to the output section starting at offset 99175fd0b74Schristos@var{offset} for @var{count} octets. 99275fd0b74Schristos 993012573ebSchristosNormally @code{TRUE} is returned, but @code{FALSE} is returned if 994012573ebSchristosthere was an error. Possible error returns are: 99575fd0b74Schristos@itemize @bullet 99675fd0b74Schristos 99775fd0b74Schristos@item 99875fd0b74Schristos@code{bfd_error_no_contents} - 99975fd0b74SchristosThe output section does not have the @code{SEC_HAS_CONTENTS} 100075fd0b74Schristosattribute, so nothing can be written to it. 100175fd0b74Schristos@item 1002012573ebSchristos@code{bfd_error_bad_value} - 1003012573ebSchristosThe section is unable to contain all of the data. 1004012573ebSchristos@item 1005012573ebSchristos@code{bfd_error_invalid_operation} - 1006012573ebSchristosThe BFD is not writeable. 1007012573ebSchristos@item 1008012573ebSchristosand some more too. 100975fd0b74Schristos@end itemize 101075fd0b74SchristosThis routine is front end to the back end function 101175fd0b74Schristos@code{_bfd_set_section_contents}. 101275fd0b74Schristos 101375fd0b74Schristos@findex bfd_get_section_contents 101475fd0b74Schristos@subsubsection @code{bfd_get_section_contents} 101575fd0b74Schristos@strong{Synopsis} 101675fd0b74Schristos@example 1017*e992f068Schristosbool bfd_get_section_contents 101875fd0b74Schristos (bfd *abfd, asection *section, void *location, file_ptr offset, 101975fd0b74Schristos bfd_size_type count); 102075fd0b74Schristos@end example 102175fd0b74Schristos@strong{Description}@* 102275fd0b74SchristosRead data from @var{section} in BFD @var{abfd} 102375fd0b74Schristosinto memory starting at @var{location}. The data is read at an 102475fd0b74Schristosoffset of @var{offset} from the start of the input section, 102575fd0b74Schristosand is read for @var{count} bytes. 102675fd0b74Schristos 102775fd0b74SchristosIf the contents of a constructor with the @code{SEC_CONSTRUCTOR} 102875fd0b74Schristosflag set are requested or if the section does not have the 102975fd0b74Schristos@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled 103075fd0b74Schristoswith zeroes. If no errors occur, @code{TRUE} is returned, else 103175fd0b74Schristos@code{FALSE}. 103275fd0b74Schristos 103375fd0b74Schristos@findex bfd_malloc_and_get_section 103475fd0b74Schristos@subsubsection @code{bfd_malloc_and_get_section} 103575fd0b74Schristos@strong{Synopsis} 103675fd0b74Schristos@example 1037*e992f068Schristosbool bfd_malloc_and_get_section 103875fd0b74Schristos (bfd *abfd, asection *section, bfd_byte **buf); 103975fd0b74Schristos@end example 104075fd0b74Schristos@strong{Description}@* 104175fd0b74SchristosRead all data from @var{section} in BFD @var{abfd} 104275fd0b74Schristosinto a buffer, *@var{buf}, malloc'd by this function. 104375fd0b74Schristos 104475fd0b74Schristos@findex bfd_copy_private_section_data 104575fd0b74Schristos@subsubsection @code{bfd_copy_private_section_data} 104675fd0b74Schristos@strong{Synopsis} 104775fd0b74Schristos@example 1048*e992f068Schristosbool bfd_copy_private_section_data 104975fd0b74Schristos (bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 105075fd0b74Schristos@end example 105175fd0b74Schristos@strong{Description}@* 105275fd0b74SchristosCopy private section information from @var{isec} in the BFD 105375fd0b74Schristos@var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 105475fd0b74SchristosReturn @code{TRUE} on success, @code{FALSE} on error. Possible error 105575fd0b74Schristosreturns are: 105675fd0b74Schristos 105775fd0b74Schristos@itemize @bullet 105875fd0b74Schristos 105975fd0b74Schristos@item 106075fd0b74Schristos@code{bfd_error_no_memory} - 106175fd0b74SchristosNot enough memory exists to create private data for @var{osec}. 106275fd0b74Schristos@end itemize 106375fd0b74Schristos@example 106475fd0b74Schristos#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ 106575fd0b74Schristos BFD_SEND (obfd, _bfd_copy_private_section_data, \ 106675fd0b74Schristos (ibfd, isection, obfd, osection)) 106775fd0b74Schristos@end example 106875fd0b74Schristos 106975fd0b74Schristos@findex bfd_generic_is_group_section 107075fd0b74Schristos@subsubsection @code{bfd_generic_is_group_section} 107175fd0b74Schristos@strong{Synopsis} 107275fd0b74Schristos@example 1073*e992f068Schristosbool bfd_generic_is_group_section (bfd *, const asection *sec); 107475fd0b74Schristos@end example 107575fd0b74Schristos@strong{Description}@* 107675fd0b74SchristosReturns TRUE if @var{sec} is a member of a group. 107775fd0b74Schristos 1078012573ebSchristos@findex bfd_generic_group_name 1079012573ebSchristos@subsubsection @code{bfd_generic_group_name} 1080012573ebSchristos@strong{Synopsis} 1081012573ebSchristos@example 1082012573ebSchristosconst char *bfd_generic_group_name (bfd *, const asection *sec); 1083012573ebSchristos@end example 1084012573ebSchristos@strong{Description}@* 1085012573ebSchristosReturns group name if @var{sec} is a member of a group. 1086012573ebSchristos 108775fd0b74Schristos@findex bfd_generic_discard_group 108875fd0b74Schristos@subsubsection @code{bfd_generic_discard_group} 108975fd0b74Schristos@strong{Synopsis} 109075fd0b74Schristos@example 1091*e992f068Schristosbool bfd_generic_discard_group (bfd *abfd, asection *group); 109275fd0b74Schristos@end example 109375fd0b74Schristos@strong{Description}@* 109475fd0b74SchristosRemove all members of @var{group} from the output. 109575fd0b74Schristos 1096