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. An IEEE-695 file doesn't contain raw data in
42sections, but data and relocation expressions intermixed, so
43the data area has to be parsed to get out the data and
44relocations.
45
46@node Section Output, typedef asection, Section Input, Sections
47@subsection Section output
48To write a new object style BFD, the various sections to be
49written have to be created. They are attached to the BFD in
50the same way as input sections; data is written to the
51sections using @code{bfd_set_section_contents}.
52
53Any program that creates or combines sections (e.g., the assembler
54and linker) must use the @code{asection} fields @code{output_section} and
55@code{output_offset} to indicate the file sections to which each
56section must be written.  (If the section is being created from
57scratch, @code{output_section} should probably point to the section
58itself and @code{output_offset} should probably be zero.)
59
60The data to be written comes from input sections attached
61(via @code{output_section} pointers) to
62the output sections.  The output section structure can be
63considered a filter for the input section: the output section
64determines the vma of the output data and the name, but the
65input section determines the offset into the output section of
66the data to be written.
67
68E.g., to create a section "O", starting at 0x100, 0x123 long,
69containing two subsections, "A" at offset 0x0 (i.e., at vma
700x100) and "B" at offset 0x20 (i.e., at vma 0x120) the @code{asection}
71structures would look like:
72
73@example
74   section name          "A"
75     output_offset   0x00
76     size            0x20
77     output_section ----------->  section name    "O"
78                             |    vma             0x100
79   section name          "B" |    size            0x123
80     output_offset   0x20    |
81     size            0x103   |
82     output_section  --------|
83@end example
84
85@subsection Link orders
86The data within a section is stored in a @dfn{link_order}.
87These are much like the fixups in @code{gas}.  The link_order
88abstraction allows a section to grow and shrink within itself.
89
90A link_order knows how big it is, and which is the next
91link_order and where the raw data for it is; it also points to
92a list of relocations which apply to it.
93
94The link_order is used by the linker to perform relaxing on
95final code.  The compiler creates code which is as big as
96necessary to make it work without relaxing, and the user can
97select whether to relax.  Sometimes relaxing takes a lot of
98time.  The linker runs around the relocations to see if any
99are attached to data which can be shrunk, if so it does it on
100a link_order by link_order basis.
101
102
103@node typedef asection, section prototypes, Section Output, Sections
104@subsection typedef asection
105Here is the section structure:
106
107
108@example
109
110typedef struct bfd_section
111@{
112  /* The name of the section; the name isn't a copy, the pointer is
113     the same as that passed to bfd_make_section.  */
114  const char *name;
115
116  /* A unique sequence number.  */
117  int id;
118
119  /* Which section in the bfd; 0..n-1 as sections are created in a bfd.  */
120  int index;
121
122  /* The next section in the list belonging to the BFD, or NULL.  */
123  struct bfd_section *next;
124
125  /* The previous section in the list belonging to the BFD, or NULL.  */
126  struct bfd_section *prev;
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   0x000
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      0x001
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       0x002
142
143  /* The section contains data still to be relocated, so there is
144     some relocation information too.  */
145#define SEC_RELOC      0x004
146
147  /* A signal to the OS that the section contains read only data.  */
148#define SEC_READONLY   0x008
149
150  /* The section contains code only.  */
151#define SEC_CODE       0x010
152
153  /* The section contains data only.  */
154#define SEC_DATA       0x020
155
156  /* The section will reside in ROM.  */
157#define SEC_ROM        0x040
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 0x080
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 has GOT references.  This flag is only for the
184     linker, and is currently only used by the elf32-hppa back end.
185     It will be set if global offset table references were detected
186     in this section, which indicate to the linker that the section
187     contains PIC code, and must be handled specially when doing a
188     static link.  */
189#define SEC_HAS_GOT_REF 0x800
190
191  /* The section contains common symbols (symbols may be defined
192     multiple times, the value of a symbol is the amount of
193     space it requires, and the largest symbol value is the one
194     used).  Most targets have exactly one of these (which we
195     translate to bfd_com_section_ptr), but ECOFF has two.  */
196#define SEC_IS_COMMON 0x1000
197
198  /* The section contains only debugging information.  For
199     example, this is set for ELF .debug and .stab sections.
200     strip tests this flag to see if a section can be
201     discarded.  */
202#define SEC_DEBUGGING 0x2000
203
204  /* The contents of this section are held in memory pointed to
205     by the contents field.  This is checked by bfd_get_section_contents,
206     and the data is retrieved from memory if appropriate.  */
207#define SEC_IN_MEMORY 0x4000
208
209  /* The contents of this section are to be excluded by the
210     linker for executable and shared objects unless those
211     objects are to be further relocated.  */
212#define SEC_EXCLUDE 0x8000
213
214  /* The contents of this section are to be sorted based on the sum of
215     the symbol and addend values specified by the associated relocation
216     entries.  Entries without associated relocation entries will be
217     appended to the end of the section in an unspecified order.  */
218#define SEC_SORT_ENTRIES 0x10000
219
220  /* When linking, duplicate sections of the same name should be
221     discarded, rather than being combined into a single section as
222     is usually done.  This is similar to how common symbols are
223     handled.  See SEC_LINK_DUPLICATES below.  */
224#define SEC_LINK_ONCE 0x20000
225
226  /* If SEC_LINK_ONCE is set, this bitfield describes how the linker
227     should handle duplicate sections.  */
228#define SEC_LINK_DUPLICATES 0x40000
229
230  /* This value for SEC_LINK_DUPLICATES means that duplicate
231     sections with the same name should simply be discarded.  */
232#define SEC_LINK_DUPLICATES_DISCARD 0x0
233
234  /* This value for SEC_LINK_DUPLICATES means that the linker
235     should warn if there are any duplicate sections, although
236     it should still only link one copy.  */
237#define SEC_LINK_DUPLICATES_ONE_ONLY 0x80000
238
239  /* This value for SEC_LINK_DUPLICATES means that the linker
240     should warn if any duplicate sections are a different size.  */
241#define SEC_LINK_DUPLICATES_SAME_SIZE 0x100000
242
243  /* This value for SEC_LINK_DUPLICATES means that the linker
244     should warn if any duplicate sections contain different
245     contents.  */
246#define SEC_LINK_DUPLICATES_SAME_CONTENTS \
247  (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
248
249  /* This section was created by the linker as part of dynamic
250     relocation or other arcane processing.  It is skipped when
251     going through the first-pass output, trusting that someone
252     else up the line will take care of it later.  */
253#define SEC_LINKER_CREATED 0x200000
254
255  /* This section should not be subject to garbage collection.
256     Also set to inform the linker that this section should not be
257     listed in the link map as discarded.  */
258#define SEC_KEEP 0x400000
259
260  /* This section contains "short" data, and should be placed
261     "near" the GP.  */
262#define SEC_SMALL_DATA 0x800000
263
264  /* Attempt to merge identical entities in the section.
265     Entity size is given in the entsize field.  */
266#define SEC_MERGE 0x1000000
267
268  /* If given with SEC_MERGE, entities to merge are zero terminated
269     strings where entsize specifies character size instead of fixed
270     size entries.  */
271#define SEC_STRINGS 0x2000000
272
273  /* This section contains data about section groups.  */
274#define SEC_GROUP 0x4000000
275
276  /* The section is a COFF shared library section.  This flag is
277     only for the linker.  If this type of section appears in
278     the input file, the linker must copy it to the output file
279     without changing the vma or size.  FIXME: Although this
280     was originally intended to be general, it really is COFF
281     specific (and the flag was renamed to indicate this).  It
282     might be cleaner to have some more general mechanism to
283     allow the back end to control what the linker does with
284     sections.  */
285#define SEC_COFF_SHARED_LIBRARY 0x10000000
286
287  /* This section contains data which may be shared with other
288     executables or shared objects. This is for COFF only.  */
289#define SEC_COFF_SHARED 0x20000000
290
291  /* When a section with this flag is being linked, then if the size of
292     the input section is less than a page, it should not cross a page
293     boundary.  If the size of the input section is one page or more,
294     it should be aligned on a page boundary.  This is for TI
295     TMS320C54X only.  */
296#define SEC_TIC54X_BLOCK 0x40000000
297
298  /* Conditionally link this section; do not link if there are no
299     references found to any symbol in the section.  This is for TI
300     TMS320C54X only.  */
301#define SEC_TIC54X_CLINK 0x80000000
302
303  /*  End of section flags.  */
304
305  /* Some internal packed boolean fields.  */
306
307  /* See the vma field.  */
308  unsigned int user_set_vma : 1;
309
310  /* A mark flag used by some of the linker backends.  */
311  unsigned int linker_mark : 1;
312
313  /* Another mark flag used by some of the linker backends.  Set for
314     output sections that have an input section.  */
315  unsigned int linker_has_input : 1;
316
317  /* Mark flags used by some linker backends for garbage collection.  */
318  unsigned int gc_mark : 1;
319  unsigned int gc_mark_from_eh : 1;
320
321  /* The following flags are used by the ELF linker. */
322
323  /* Mark sections which have been allocated to segments.  */
324  unsigned int segment_mark : 1;
325
326  /* Type of sec_info information.  */
327  unsigned int sec_info_type:3;
328#define ELF_INFO_TYPE_NONE      0
329#define ELF_INFO_TYPE_STABS     1
330#define ELF_INFO_TYPE_MERGE     2
331#define ELF_INFO_TYPE_EH_FRAME  3
332#define ELF_INFO_TYPE_JUST_SYMS 4
333
334  /* Nonzero if this section uses RELA relocations, rather than REL.  */
335  unsigned int use_rela_p:1;
336
337  /* Bits used by various backends.  The generic code doesn't touch
338     these fields.  */
339
340  /* Nonzero if this section has TLS related relocations.  */
341  unsigned int has_tls_reloc:1;
342
343  /* Nonzero if this section has a gp reloc.  */
344  unsigned int has_gp_reloc:1;
345
346  /* Nonzero if this section needs the relax finalize pass.  */
347  unsigned int need_finalize_relax:1;
348
349  /* Whether relocations have been processed.  */
350  unsigned int reloc_done : 1;
351
352  /* End of internal packed boolean fields.  */
353
354  /*  The virtual memory address of the section - where it will be
355      at run time.  The symbols are relocated against this.  The
356      user_set_vma flag is maintained by bfd; if it's not set, the
357      backend can assign addresses (for example, in @code{a.out}, where
358      the default address for @code{.data} is dependent on the specific
359      target and various flags).  */
360  bfd_vma vma;
361
362  /*  The load address of the section - where it would be in a
363      rom image; really only used for writing section header
364      information.  */
365  bfd_vma lma;
366
367  /* The size of the section in octets, as it will be output.
368     Contains a value even if the section has no contents (e.g., the
369     size of @code{.bss}).  */
370  bfd_size_type size;
371
372  /* For input sections, the original size on disk of the section, in
373     octets.  This field is used by the linker relaxation code.  It is
374     currently only set for sections where the linker relaxation scheme
375     doesn't cache altered section and reloc contents (stabs, eh_frame,
376     SEC_MERGE, some coff relaxing targets), and thus the original size
377     needs to be kept to read the section multiple times.
378     For output sections, rawsize holds the section size calculated on
379     a previous linker relaxation pass.  */
380  bfd_size_type rawsize;
381
382  /* If this section is going to be output, then this value is the
383     offset in *bytes* into the output section of the first byte in the
384     input section (byte ==> smallest addressable unit on the
385     target).  In most cases, if this was going to start at the
386     100th octet (8-bit quantity) in the output section, this value
387     would be 100.  However, if the target byte size is 16 bits
388     (bfd_octets_per_byte is "2"), this value would be 50.  */
389  bfd_vma output_offset;
390
391  /* The output section through which to map on output.  */
392  struct bfd_section *output_section;
393
394  /* The alignment requirement of the section, as an exponent of 2 -
395     e.g., 3 aligns to 2^3 (or 8).  */
396  unsigned int alignment_power;
397
398  /* If an input section, a pointer to a vector of relocation
399     records for the data in this section.  */
400  struct reloc_cache_entry *relocation;
401
402  /* If an output section, a pointer to a vector of pointers to
403     relocation records for the data in this section.  */
404  struct reloc_cache_entry **orelocation;
405
406  /* The number of relocation records in one of the above.  */
407  unsigned reloc_count;
408
409  /* Information below is back end specific - and not always used
410     or updated.  */
411
412  /* File position of section data.  */
413  file_ptr filepos;
414
415  /* File position of relocation info.  */
416  file_ptr rel_filepos;
417
418  /* File position of line data.  */
419  file_ptr line_filepos;
420
421  /* Pointer to data for applications.  */
422  void *userdata;
423
424  /* If the SEC_IN_MEMORY flag is set, this points to the actual
425     contents.  */
426  unsigned char *contents;
427
428  /* Attached line number information.  */
429  alent *lineno;
430
431  /* Number of line number records.  */
432  unsigned int lineno_count;
433
434  /* Entity size for merging purposes.  */
435  unsigned int entsize;
436
437  /* Points to the kept section if this section is a link-once section,
438     and is discarded.  */
439  struct bfd_section *kept_section;
440
441  /* When a section is being output, this value changes as more
442     linenumbers are written out.  */
443  file_ptr moving_line_filepos;
444
445  /* What the section number is in the target world.  */
446  int target_index;
447
448  void *used_by_bfd;
449
450  /* If this is a constructor section then here is a list of the
451     relocations created to relocate items within it.  */
452  struct relent_chain *constructor_chain;
453
454  /* The BFD which owns the section.  */
455  bfd *owner;
456
457  /* A symbol which points at this section only.  */
458  struct bfd_symbol *symbol;
459  struct bfd_symbol **symbol_ptr_ptr;
460
461  /* Early in the link process, map_head and map_tail are used to build
462     a list of input sections attached to an output section.  Later,
463     output sections use these fields for a list of bfd_link_order
464     structs.  */
465  union @{
466    struct bfd_link_order *link_order;
467    struct bfd_section *s;
468  @} map_head, map_tail;
469@} asection;
470
471/* These sections are global, and are managed by BFD.  The application
472   and target back end are not permitted to change the values in
473   these sections.  New code should use the section_ptr macros rather
474   than referring directly to the const sections.  The const sections
475   may eventually vanish.  */
476#define BFD_ABS_SECTION_NAME "*ABS*"
477#define BFD_UND_SECTION_NAME "*UND*"
478#define BFD_COM_SECTION_NAME "*COM*"
479#define BFD_IND_SECTION_NAME "*IND*"
480
481/* The absolute section.  */
482extern asection bfd_abs_section;
483#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
484#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
485/* Pointer to the undefined section.  */
486extern asection bfd_und_section;
487#define bfd_und_section_ptr ((asection *) &bfd_und_section)
488#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
489/* Pointer to the common section.  */
490extern asection bfd_com_section;
491#define bfd_com_section_ptr ((asection *) &bfd_com_section)
492/* Pointer to the indirect section.  */
493extern asection bfd_ind_section;
494#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
495#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
496
497#define bfd_is_const_section(SEC)              \
498 (   ((SEC) == bfd_abs_section_ptr)            \
499  || ((SEC) == bfd_und_section_ptr)            \
500  || ((SEC) == bfd_com_section_ptr)            \
501  || ((SEC) == bfd_ind_section_ptr))
502
503/* Macros to handle insertion and deletion of a bfd's sections.  These
504   only handle the list pointers, ie. do not adjust section_count,
505   target_index etc.  */
506#define bfd_section_list_remove(ABFD, S) \
507  do                                                   \
508    @{                                                  \
509      asection *_s = S;                                \
510      asection *_next = _s->next;                      \
511      asection *_prev = _s->prev;                      \
512      if (_prev)                                       \
513        _prev->next = _next;                           \
514      else                                             \
515        (ABFD)->sections = _next;                      \
516      if (_next)                                       \
517        _next->prev = _prev;                           \
518      else                                             \
519        (ABFD)->section_last = _prev;                  \
520    @}                                                  \
521  while (0)
522#define bfd_section_list_append(ABFD, S) \
523  do                                                   \
524    @{                                                  \
525      asection *_s = S;                                \
526      bfd *_abfd = ABFD;                               \
527      _s->next = NULL;                                 \
528      if (_abfd->section_last)                         \
529        @{                                              \
530          _s->prev = _abfd->section_last;              \
531          _abfd->section_last->next = _s;              \
532        @}                                              \
533      else                                             \
534        @{                                              \
535          _s->prev = NULL;                             \
536          _abfd->sections = _s;                        \
537        @}                                              \
538      _abfd->section_last = _s;                        \
539    @}                                                  \
540  while (0)
541#define bfd_section_list_prepend(ABFD, S) \
542  do                                                   \
543    @{                                                  \
544      asection *_s = S;                                \
545      bfd *_abfd = ABFD;                               \
546      _s->prev = NULL;                                 \
547      if (_abfd->sections)                             \
548        @{                                              \
549          _s->next = _abfd->sections;                  \
550          _abfd->sections->prev = _s;                  \
551        @}                                              \
552      else                                             \
553        @{                                              \
554          _s->next = NULL;                             \
555          _abfd->section_last = _s;                    \
556        @}                                              \
557      _abfd->sections = _s;                            \
558    @}                                                  \
559  while (0)
560#define bfd_section_list_insert_after(ABFD, A, S) \
561  do                                                   \
562    @{                                                  \
563      asection *_a = A;                                \
564      asection *_s = S;                                \
565      asection *_next = _a->next;                      \
566      _s->next = _next;                                \
567      _s->prev = _a;                                   \
568      _a->next = _s;                                   \
569      if (_next)                                       \
570        _next->prev = _s;                              \
571      else                                             \
572        (ABFD)->section_last = _s;                     \
573    @}                                                  \
574  while (0)
575#define bfd_section_list_insert_before(ABFD, B, S) \
576  do                                                   \
577    @{                                                  \
578      asection *_b = B;                                \
579      asection *_s = S;                                \
580      asection *_prev = _b->prev;                      \
581      _s->prev = _prev;                                \
582      _s->next = _b;                                   \
583      _b->prev = _s;                                   \
584      if (_prev)                                       \
585        _prev->next = _s;                              \
586      else                                             \
587        (ABFD)->sections = _s;                         \
588    @}                                                  \
589  while (0)
590#define bfd_section_removed_from_list(ABFD, S) \
591  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
592
593#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX)                   \
594  /* name, id,  index, next, prev, flags, user_set_vma,            */  \
595  @{ NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,                           \
596                                                                       \
597  /* linker_mark, linker_has_input, gc_mark, gc_mark_from_eh,      */  \
598     0,           0,                1,       0,                        \
599                                                                       \
600  /* segment_mark, sec_info_type, use_rela_p, has_tls_reloc,       */  \
601     0,            0,             0,          0,                       \
602                                                                       \
603  /* has_gp_reloc, need_finalize_relax, reloc_done,                */  \
604     0,            0,                   0,                             \
605                                                                       \
606  /* vma, lma, size, rawsize                                       */  \
607     0,   0,   0,    0,                                                \
608                                                                       \
609  /* output_offset, output_section,              alignment_power,  */  \
610     0,             (struct bfd_section *) &SEC, 0,                    \
611                                                                       \
612  /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */  \
613     NULL,       NULL,        0,           0,       0,                 \
614                                                                       \
615  /* line_filepos, userdata, contents, lineno, lineno_count,       */  \
616     0,            NULL,     NULL,     NULL,   0,                      \
617                                                                       \
618  /* entsize, kept_section, moving_line_filepos,                    */ \
619     0,       NULL,          0,                                        \
620                                                                       \
621  /* target_index, used_by_bfd, constructor_chain, owner,          */  \
622     0,            NULL,        NULL,              NULL,               \
623                                                                       \
624  /* symbol,                    symbol_ptr_ptr,                    */  \
625     (struct bfd_symbol *) SYM, &SEC.symbol,                           \
626                                                                       \
627  /* map_head, map_tail                                            */  \
628     @{ NULL @}, @{ NULL @}                                                \
629    @}
630
631@end example
632
633@node section prototypes,  , typedef asection, Sections
634@subsection Section prototypes
635These are the functions exported by the section handling part of BFD.
636
637@findex bfd_section_list_clear
638@subsubsection @code{bfd_section_list_clear}
639@strong{Synopsis}
640@example
641void bfd_section_list_clear (bfd *);
642@end example
643@strong{Description}@*
644Clears the section list, and also resets the section count and
645hash table entries.
646
647@findex bfd_get_section_by_name
648@subsubsection @code{bfd_get_section_by_name}
649@strong{Synopsis}
650@example
651asection *bfd_get_section_by_name (bfd *abfd, const char *name);
652@end example
653@strong{Description}@*
654Run through @var{abfd} and return the one of the
655@code{asection}s whose name matches @var{name}, otherwise @code{NULL}.
656@xref{Sections}, for more information.
657
658This should only be used in special cases; the normal way to process
659all sections of a given name is to use @code{bfd_map_over_sections} and
660@code{strcmp} on the name (or better yet, base it on the section flags
661or something else) for each section.
662
663@findex bfd_get_section_by_name_if
664@subsubsection @code{bfd_get_section_by_name_if}
665@strong{Synopsis}
666@example
667asection *bfd_get_section_by_name_if
668   (bfd *abfd,
669    const char *name,
670    bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
671    void *obj);
672@end example
673@strong{Description}@*
674Call the provided function @var{func} for each section
675attached to the BFD @var{abfd} whose name matches @var{name},
676passing @var{obj} as an argument. The function will be called
677as if by
678
679@example
680       func (abfd, the_section, obj);
681@end example
682
683It returns the first section for which @var{func} returns true,
684otherwise @code{NULL}.
685
686@findex bfd_get_unique_section_name
687@subsubsection @code{bfd_get_unique_section_name}
688@strong{Synopsis}
689@example
690char *bfd_get_unique_section_name
691   (bfd *abfd, const char *templat, int *count);
692@end example
693@strong{Description}@*
694Invent a section name that is unique in @var{abfd} by tacking
695a dot and a digit suffix onto the original @var{templat}.  If
696@var{count} is non-NULL, then it specifies the first number
697tried as a suffix to generate a unique name.  The value
698pointed to by @var{count} will be incremented in this case.
699
700@findex bfd_make_section_old_way
701@subsubsection @code{bfd_make_section_old_way}
702@strong{Synopsis}
703@example
704asection *bfd_make_section_old_way (bfd *abfd, const char *name);
705@end example
706@strong{Description}@*
707Create a new empty section called @var{name}
708and attach it to the end of the chain of sections for the
709BFD @var{abfd}. An attempt to create a section with a name which
710is already in use returns its pointer without changing the
711section chain.
712
713It has the funny name since this is the way it used to be
714before it was rewritten....
715
716Possible errors are:
717@itemize @bullet
718
719@item
720@code{bfd_error_invalid_operation} -
721If output has already started for this BFD.
722@item
723@code{bfd_error_no_memory} -
724If memory allocation fails.
725@end itemize
726
727@findex bfd_make_section_anyway_with_flags
728@subsubsection @code{bfd_make_section_anyway_with_flags}
729@strong{Synopsis}
730@example
731asection *bfd_make_section_anyway_with_flags
732   (bfd *abfd, const char *name, flagword flags);
733@end example
734@strong{Description}@*
735Create a new empty section called @var{name} and attach it to the end of
736the chain of sections for @var{abfd}.  Create a new section even if there
737is already a section with that name.  Also set the attributes of the
738new section to the value @var{flags}.
739
740Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
741@itemize @bullet
742
743@item
744@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
745@item
746@code{bfd_error_no_memory} - If memory allocation fails.
747@end itemize
748
749@findex bfd_make_section_anyway
750@subsubsection @code{bfd_make_section_anyway}
751@strong{Synopsis}
752@example
753asection *bfd_make_section_anyway (bfd *abfd, const char *name);
754@end example
755@strong{Description}@*
756Create a new empty section called @var{name} and attach it to the end of
757the chain of sections for @var{abfd}.  Create a new section even if there
758is already a section with that name.
759
760Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
761@itemize @bullet
762
763@item
764@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
765@item
766@code{bfd_error_no_memory} - If memory allocation fails.
767@end itemize
768
769@findex bfd_make_section_with_flags
770@subsubsection @code{bfd_make_section_with_flags}
771@strong{Synopsis}
772@example
773asection *bfd_make_section_with_flags
774   (bfd *, const char *name, flagword flags);
775@end example
776@strong{Description}@*
777Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
778bfd_set_error ()) without changing the section chain if there is already a
779section named @var{name}.  Also set the attributes of the new section to
780the value @var{flags}.  If there is an error, return @code{NULL} and set
781@code{bfd_error}.
782
783@findex bfd_make_section
784@subsubsection @code{bfd_make_section}
785@strong{Synopsis}
786@example
787asection *bfd_make_section (bfd *, const char *name);
788@end example
789@strong{Description}@*
790Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
791bfd_set_error ()) without changing the section chain if there is already a
792section named @var{name}.  If there is an error, return @code{NULL} and set
793@code{bfd_error}.
794
795@findex bfd_set_section_flags
796@subsubsection @code{bfd_set_section_flags}
797@strong{Synopsis}
798@example
799bfd_boolean bfd_set_section_flags
800   (bfd *abfd, asection *sec, flagword flags);
801@end example
802@strong{Description}@*
803Set the attributes of the section @var{sec} in the BFD
804@var{abfd} to the value @var{flags}. Return @code{TRUE} on success,
805@code{FALSE} on error. Possible error returns are:
806
807@itemize @bullet
808
809@item
810@code{bfd_error_invalid_operation} -
811The section cannot have one or more of the attributes
812requested. For example, a .bss section in @code{a.out} may not
813have the @code{SEC_HAS_CONTENTS} field set.
814@end itemize
815
816@findex bfd_map_over_sections
817@subsubsection @code{bfd_map_over_sections}
818@strong{Synopsis}
819@example
820void bfd_map_over_sections
821   (bfd *abfd,
822    void (*func) (bfd *abfd, asection *sect, void *obj),
823    void *obj);
824@end example
825@strong{Description}@*
826Call the provided function @var{func} for each section
827attached to the BFD @var{abfd}, passing @var{obj} as an
828argument. The function will be called as if by
829
830@example
831       func (abfd, the_section, obj);
832@end example
833
834This is the preferred method for iterating over sections; an
835alternative would be to use a loop:
836
837@example
838          section *p;
839          for (p = abfd->sections; p != NULL; p = p->next)
840             func (abfd, p, ...)
841@end example
842
843@findex bfd_sections_find_if
844@subsubsection @code{bfd_sections_find_if}
845@strong{Synopsis}
846@example
847asection *bfd_sections_find_if
848   (bfd *abfd,
849    bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
850    void *obj);
851@end example
852@strong{Description}@*
853Call the provided function @var{operation} for each section
854attached to the BFD @var{abfd}, passing @var{obj} as an
855argument. The function will be called as if by
856
857@example
858       operation (abfd, the_section, obj);
859@end example
860
861It returns the first section for which @var{operation} returns true.
862
863@findex bfd_set_section_size
864@subsubsection @code{bfd_set_section_size}
865@strong{Synopsis}
866@example
867bfd_boolean bfd_set_section_size
868   (bfd *abfd, asection *sec, bfd_size_type val);
869@end example
870@strong{Description}@*
871Set @var{sec} to the size @var{val}. If the operation is
872ok, then @code{TRUE} is returned, else @code{FALSE}.
873
874Possible error returns:
875@itemize @bullet
876
877@item
878@code{bfd_error_invalid_operation} -
879Writing has started to the BFD, so setting the size is invalid.
880@end itemize
881
882@findex bfd_set_section_contents
883@subsubsection @code{bfd_set_section_contents}
884@strong{Synopsis}
885@example
886bfd_boolean bfd_set_section_contents
887   (bfd *abfd, asection *section, const void *data,
888    file_ptr offset, bfd_size_type count);
889@end example
890@strong{Description}@*
891Sets the contents of the section @var{section} in BFD
892@var{abfd} to the data starting in memory at @var{data}. The
893data is written to the output section starting at offset
894@var{offset} for @var{count} octets.
895
896Normally @code{TRUE} is returned, else @code{FALSE}. Possible error
897returns are:
898@itemize @bullet
899
900@item
901@code{bfd_error_no_contents} -
902The output section does not have the @code{SEC_HAS_CONTENTS}
903attribute, so nothing can be written to it.
904@item
905and some more too
906@end itemize
907This routine is front end to the back end function
908@code{_bfd_set_section_contents}.
909
910@findex bfd_get_section_contents
911@subsubsection @code{bfd_get_section_contents}
912@strong{Synopsis}
913@example
914bfd_boolean bfd_get_section_contents
915   (bfd *abfd, asection *section, void *location, file_ptr offset,
916    bfd_size_type count);
917@end example
918@strong{Description}@*
919Read data from @var{section} in BFD @var{abfd}
920into memory starting at @var{location}. The data is read at an
921offset of @var{offset} from the start of the input section,
922and is read for @var{count} bytes.
923
924If the contents of a constructor with the @code{SEC_CONSTRUCTOR}
925flag set are requested or if the section does not have the
926@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled
927with zeroes. If no errors occur, @code{TRUE} is returned, else
928@code{FALSE}.
929
930@findex bfd_malloc_and_get_section
931@subsubsection @code{bfd_malloc_and_get_section}
932@strong{Synopsis}
933@example
934bfd_boolean bfd_malloc_and_get_section
935   (bfd *abfd, asection *section, bfd_byte **buf);
936@end example
937@strong{Description}@*
938Read all data from @var{section} in BFD @var{abfd}
939into a buffer, *@var{buf}, malloc'd by this function.
940
941@findex bfd_copy_private_section_data
942@subsubsection @code{bfd_copy_private_section_data}
943@strong{Synopsis}
944@example
945bfd_boolean bfd_copy_private_section_data
946   (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
947@end example
948@strong{Description}@*
949Copy private section information from @var{isec} in the BFD
950@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
951Return @code{TRUE} on success, @code{FALSE} on error.  Possible error
952returns are:
953
954@itemize @bullet
955
956@item
957@code{bfd_error_no_memory} -
958Not enough memory exists to create private data for @var{osec}.
959@end itemize
960@example
961#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
962     BFD_SEND (obfd, _bfd_copy_private_section_data, \
963               (ibfd, isection, obfd, osection))
964@end example
965
966@findex bfd_generic_is_group_section
967@subsubsection @code{bfd_generic_is_group_section}
968@strong{Synopsis}
969@example
970bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
971@end example
972@strong{Description}@*
973Returns TRUE if @var{sec} is a member of a group.
974
975@findex bfd_generic_discard_group
976@subsubsection @code{bfd_generic_discard_group}
977@strong{Synopsis}
978@example
979bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
980@end example
981@strong{Description}@*
982Remove all members of @var{group} from the output.
983
984