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#define SEC_KEEP 0x400000
257
258  /* This section contains "short" data, and should be placed
259     "near" the GP.  */
260#define SEC_SMALL_DATA 0x800000
261
262  /* Attempt to merge identical entities in the section.
263     Entity size is given in the entsize field.  */
264#define SEC_MERGE 0x1000000
265
266  /* If given with SEC_MERGE, entities to merge are zero terminated
267     strings where entsize specifies character size instead of fixed
268     size entries.  */
269#define SEC_STRINGS 0x2000000
270
271  /* This section contains data about section groups.  */
272#define SEC_GROUP 0x4000000
273
274  /* The section is a COFF shared library section.  This flag is
275     only for the linker.  If this type of section appears in
276     the input file, the linker must copy it to the output file
277     without changing the vma or size.  FIXME: Although this
278     was originally intended to be general, it really is COFF
279     specific (and the flag was renamed to indicate this).  It
280     might be cleaner to have some more general mechanism to
281     allow the back end to control what the linker does with
282     sections.  */
283#define SEC_COFF_SHARED_LIBRARY 0x10000000
284
285  /* This section contains data which may be shared with other
286     executables or shared objects. This is for COFF only.  */
287#define SEC_COFF_SHARED 0x20000000
288
289  /* When a section with this flag is being linked, then if the size of
290     the input section is less than a page, it should not cross a page
291     boundary.  If the size of the input section is one page or more,
292     it should be aligned on a page boundary.  This is for TI
293     TMS320C54X only.  */
294#define SEC_TIC54X_BLOCK 0x40000000
295
296  /* Conditionally link this section; do not link if there are no
297     references found to any symbol in the section.  This is for TI
298     TMS320C54X only.  */
299#define SEC_TIC54X_CLINK 0x80000000
300
301  /*  End of section flags.  */
302
303  /* Some internal packed boolean fields.  */
304
305  /* See the vma field.  */
306  unsigned int user_set_vma : 1;
307
308  /* A mark flag used by some of the linker backends.  */
309  unsigned int linker_mark : 1;
310
311  /* Another mark flag used by some of the linker backends.  Set for
312     output sections that have an input section.  */
313  unsigned int linker_has_input : 1;
314
315  /* Mark flags used by some linker backends for garbage collection.  */
316  unsigned int gc_mark : 1;
317  unsigned int gc_mark_from_eh : 1;
318
319  /* The following flags are used by the ELF linker. */
320
321  /* Mark sections which have been allocated to segments.  */
322  unsigned int segment_mark : 1;
323
324  /* Type of sec_info information.  */
325  unsigned int sec_info_type:3;
326#define ELF_INFO_TYPE_NONE      0
327#define ELF_INFO_TYPE_STABS     1
328#define ELF_INFO_TYPE_MERGE     2
329#define ELF_INFO_TYPE_EH_FRAME  3
330#define ELF_INFO_TYPE_JUST_SYMS 4
331
332  /* Nonzero if this section uses RELA relocations, rather than REL.  */
333  unsigned int use_rela_p:1;
334
335  /* Bits used by various backends.  The generic code doesn't touch
336     these fields.  */
337
338  /* Nonzero if this section has TLS related relocations.  */
339  unsigned int has_tls_reloc:1;
340
341  /* Nonzero if this section has a gp reloc.  */
342  unsigned int has_gp_reloc:1;
343
344  /* Nonzero if this section needs the relax finalize pass.  */
345  unsigned int need_finalize_relax:1;
346
347  /* Whether relocations have been processed.  */
348  unsigned int reloc_done : 1;
349
350  /* End of internal packed boolean fields.  */
351
352  /*  The virtual memory address of the section - where it will be
353      at run time.  The symbols are relocated against this.  The
354      user_set_vma flag is maintained by bfd; if it's not set, the
355      backend can assign addresses (for example, in @code{a.out}, where
356      the default address for @code{.data} is dependent on the specific
357      target and various flags).  */
358  bfd_vma vma;
359
360  /*  The load address of the section - where it would be in a
361      rom image; really only used for writing section header
362      information.  */
363  bfd_vma lma;
364
365  /* The size of the section in octets, as it will be output.
366     Contains a value even if the section has no contents (e.g., the
367     size of @code{.bss}).  */
368  bfd_size_type size;
369
370  /* For input sections, the original size on disk of the section, in
371     octets.  This field is used by the linker relaxation code.  It is
372     currently only set for sections where the linker relaxation scheme
373     doesn't cache altered section and reloc contents (stabs, eh_frame,
374     SEC_MERGE, some coff relaxing targets), and thus the original size
375     needs to be kept to read the section multiple times.
376     For output sections, rawsize holds the section size calculated on
377     a previous linker relaxation pass.  */
378  bfd_size_type rawsize;
379
380  /* If this section is going to be output, then this value is the
381     offset in *bytes* into the output section of the first byte in the
382     input section (byte ==> smallest addressable unit on the
383     target).  In most cases, if this was going to start at the
384     100th octet (8-bit quantity) in the output section, this value
385     would be 100.  However, if the target byte size is 16 bits
386     (bfd_octets_per_byte is "2"), this value would be 50.  */
387  bfd_vma output_offset;
388
389  /* The output section through which to map on output.  */
390  struct bfd_section *output_section;
391
392  /* The alignment requirement of the section, as an exponent of 2 -
393     e.g., 3 aligns to 2^3 (or 8).  */
394  unsigned int alignment_power;
395
396  /* If an input section, a pointer to a vector of relocation
397     records for the data in this section.  */
398  struct reloc_cache_entry *relocation;
399
400  /* If an output section, a pointer to a vector of pointers to
401     relocation records for the data in this section.  */
402  struct reloc_cache_entry **orelocation;
403
404  /* The number of relocation records in one of the above.  */
405  unsigned reloc_count;
406
407  /* Information below is back end specific - and not always used
408     or updated.  */
409
410  /* File position of section data.  */
411  file_ptr filepos;
412
413  /* File position of relocation info.  */
414  file_ptr rel_filepos;
415
416  /* File position of line data.  */
417  file_ptr line_filepos;
418
419  /* Pointer to data for applications.  */
420  void *userdata;
421
422  /* If the SEC_IN_MEMORY flag is set, this points to the actual
423     contents.  */
424  unsigned char *contents;
425
426  /* Attached line number information.  */
427  alent *lineno;
428
429  /* Number of line number records.  */
430  unsigned int lineno_count;
431
432  /* Entity size for merging purposes.  */
433  unsigned int entsize;
434
435  /* Points to the kept section if this section is a link-once section,
436     and is discarded.  */
437  struct bfd_section *kept_section;
438
439  /* When a section is being output, this value changes as more
440     linenumbers are written out.  */
441  file_ptr moving_line_filepos;
442
443  /* What the section number is in the target world.  */
444  int target_index;
445
446  void *used_by_bfd;
447
448  /* If this is a constructor section then here is a list of the
449     relocations created to relocate items within it.  */
450  struct relent_chain *constructor_chain;
451
452  /* The BFD which owns the section.  */
453  bfd *owner;
454
455  /* A symbol which points at this section only.  */
456  struct bfd_symbol *symbol;
457  struct bfd_symbol **symbol_ptr_ptr;
458
459  /* Early in the link process, map_head and map_tail are used to build
460     a list of input sections attached to an output section.  Later,
461     output sections use these fields for a list of bfd_link_order
462     structs.  */
463  union @{
464    struct bfd_link_order *link_order;
465    struct bfd_section *s;
466  @} map_head, map_tail;
467@} asection;
468
469/* These sections are global, and are managed by BFD.  The application
470   and target back end are not permitted to change the values in
471   these sections.  New code should use the section_ptr macros rather
472   than referring directly to the const sections.  The const sections
473   may eventually vanish.  */
474#define BFD_ABS_SECTION_NAME "*ABS*"
475#define BFD_UND_SECTION_NAME "*UND*"
476#define BFD_COM_SECTION_NAME "*COM*"
477#define BFD_IND_SECTION_NAME "*IND*"
478
479/* The absolute section.  */
480extern asection bfd_abs_section;
481#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
482#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
483/* Pointer to the undefined section.  */
484extern asection bfd_und_section;
485#define bfd_und_section_ptr ((asection *) &bfd_und_section)
486#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
487/* Pointer to the common section.  */
488extern asection bfd_com_section;
489#define bfd_com_section_ptr ((asection *) &bfd_com_section)
490/* Pointer to the indirect section.  */
491extern asection bfd_ind_section;
492#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
493#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
494
495#define bfd_is_const_section(SEC)              \
496 (   ((SEC) == bfd_abs_section_ptr)            \
497  || ((SEC) == bfd_und_section_ptr)            \
498  || ((SEC) == bfd_com_section_ptr)            \
499  || ((SEC) == bfd_ind_section_ptr))
500
501extern const struct bfd_symbol * const bfd_abs_symbol;
502extern const struct bfd_symbol * const bfd_com_symbol;
503extern const struct bfd_symbol * const bfd_und_symbol;
504extern const struct bfd_symbol * const bfd_ind_symbol;
505
506/* Macros to handle insertion and deletion of a bfd's sections.  These
507   only handle the list pointers, ie. do not adjust section_count,
508   target_index etc.  */
509#define bfd_section_list_remove(ABFD, S) \
510  do                                                   \
511    @{                                                  \
512      asection *_s = S;                                \
513      asection *_next = _s->next;                      \
514      asection *_prev = _s->prev;                      \
515      if (_prev)                                       \
516        _prev->next = _next;                           \
517      else                                             \
518        (ABFD)->sections = _next;                      \
519      if (_next)                                       \
520        _next->prev = _prev;                           \
521      else                                             \
522        (ABFD)->section_last = _prev;                  \
523    @}                                                  \
524  while (0)
525#define bfd_section_list_append(ABFD, S) \
526  do                                                   \
527    @{                                                  \
528      asection *_s = S;                                \
529      bfd *_abfd = ABFD;                               \
530      _s->next = NULL;                                 \
531      if (_abfd->section_last)                         \
532        @{                                              \
533          _s->prev = _abfd->section_last;              \
534          _abfd->section_last->next = _s;              \
535        @}                                              \
536      else                                             \
537        @{                                              \
538          _s->prev = NULL;                             \
539          _abfd->sections = _s;                        \
540        @}                                              \
541      _abfd->section_last = _s;                        \
542    @}                                                  \
543  while (0)
544#define bfd_section_list_prepend(ABFD, S) \
545  do                                                   \
546    @{                                                  \
547      asection *_s = S;                                \
548      bfd *_abfd = ABFD;                               \
549      _s->prev = NULL;                                 \
550      if (_abfd->sections)                             \
551        @{                                              \
552          _s->next = _abfd->sections;                  \
553          _abfd->sections->prev = _s;                  \
554        @}                                              \
555      else                                             \
556        @{                                              \
557          _s->next = NULL;                             \
558          _abfd->section_last = _s;                    \
559        @}                                              \
560      _abfd->sections = _s;                            \
561    @}                                                  \
562  while (0)
563#define bfd_section_list_insert_after(ABFD, A, S) \
564  do                                                   \
565    @{                                                  \
566      asection *_a = A;                                \
567      asection *_s = S;                                \
568      asection *_next = _a->next;                      \
569      _s->next = _next;                                \
570      _s->prev = _a;                                   \
571      _a->next = _s;                                   \
572      if (_next)                                       \
573        _next->prev = _s;                              \
574      else                                             \
575        (ABFD)->section_last = _s;                     \
576    @}                                                  \
577  while (0)
578#define bfd_section_list_insert_before(ABFD, B, S) \
579  do                                                   \
580    @{                                                  \
581      asection *_b = B;                                \
582      asection *_s = S;                                \
583      asection *_prev = _b->prev;                      \
584      _s->prev = _prev;                                \
585      _s->next = _b;                                   \
586      _b->prev = _s;                                   \
587      if (_prev)                                       \
588        _prev->next = _s;                              \
589      else                                             \
590        (ABFD)->sections = _s;                         \
591    @}                                                  \
592  while (0)
593#define bfd_section_removed_from_list(ABFD, S) \
594  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
595
596#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, SYM_PTR, NAME, IDX)          \
597  /* name, id,  index, next, prev, flags, user_set_vma,            */  \
598  @{ NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,                           \
599                                                                       \
600  /* linker_mark, linker_has_input, gc_mark, gc_mark_from_eh,      */  \
601     0,           0,                1,       0,                        \
602                                                                       \
603  /* segment_mark, sec_info_type, use_rela_p, has_tls_reloc,       */  \
604     0,            0,             0,          0,                       \
605                                                                       \
606  /* has_gp_reloc, need_finalize_relax, reloc_done,                */  \
607     0,            0,                   0,                             \
608                                                                       \
609  /* vma, lma, size, rawsize                                       */  \
610     0,   0,   0,    0,                                                \
611                                                                       \
612  /* output_offset, output_section,              alignment_power,  */  \
613     0,             (struct bfd_section *) &SEC, 0,                    \
614                                                                       \
615  /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */  \
616     NULL,       NULL,        0,           0,       0,                 \
617                                                                       \
618  /* line_filepos, userdata, contents, lineno, lineno_count,       */  \
619     0,            NULL,     NULL,     NULL,   0,                      \
620                                                                       \
621  /* entsize, kept_section, moving_line_filepos,                    */ \
622     0,       NULL,          0,                                        \
623                                                                       \
624  /* target_index, used_by_bfd, constructor_chain, owner,          */  \
625     0,            NULL,        NULL,              NULL,               \
626                                                                       \
627  /* symbol,                                                       */  \
628     (struct bfd_symbol *) SYM,                                        \
629                                                                       \
630  /* symbol_ptr_ptr,                                               */  \
631     (struct bfd_symbol **) SYM_PTR,                                   \
632                                                                       \
633  /* map_head, map_tail                                            */  \
634     @{ NULL @}, @{ NULL @}                                                \
635    @}
636
637@end example
638
639@node section prototypes,  , typedef asection, Sections
640@subsection Section prototypes
641These are the functions exported by the section handling part of BFD.
642
643@findex bfd_section_list_clear
644@subsubsection @code{bfd_section_list_clear}
645@strong{Synopsis}
646@example
647void bfd_section_list_clear (bfd *);
648@end example
649@strong{Description}@*
650Clears the section list, and also resets the section count and
651hash table entries.
652
653@findex bfd_get_section_by_name
654@subsubsection @code{bfd_get_section_by_name}
655@strong{Synopsis}
656@example
657asection *bfd_get_section_by_name (bfd *abfd, const char *name);
658@end example
659@strong{Description}@*
660Run through @var{abfd} and return the one of the
661@code{asection}s whose name matches @var{name}, otherwise @code{NULL}.
662@xref{Sections}, for more information.
663
664This should only be used in special cases; the normal way to process
665all sections of a given name is to use @code{bfd_map_over_sections} and
666@code{strcmp} on the name (or better yet, base it on the section flags
667or something else) for each section.
668
669@findex bfd_get_section_by_name_if
670@subsubsection @code{bfd_get_section_by_name_if}
671@strong{Synopsis}
672@example
673asection *bfd_get_section_by_name_if
674   (bfd *abfd,
675    const char *name,
676    bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
677    void *obj);
678@end example
679@strong{Description}@*
680Call the provided function @var{func} for each section
681attached to the BFD @var{abfd} whose name matches @var{name},
682passing @var{obj} as an argument. The function will be called
683as if by
684
685@example
686       func (abfd, the_section, obj);
687@end example
688
689It returns the first section for which @var{func} returns true,
690otherwise @code{NULL}.
691
692@findex bfd_get_unique_section_name
693@subsubsection @code{bfd_get_unique_section_name}
694@strong{Synopsis}
695@example
696char *bfd_get_unique_section_name
697   (bfd *abfd, const char *templat, int *count);
698@end example
699@strong{Description}@*
700Invent a section name that is unique in @var{abfd} by tacking
701a dot and a digit suffix onto the original @var{templat}.  If
702@var{count} is non-NULL, then it specifies the first number
703tried as a suffix to generate a unique name.  The value
704pointed to by @var{count} will be incremented in this case.
705
706@findex bfd_make_section_old_way
707@subsubsection @code{bfd_make_section_old_way}
708@strong{Synopsis}
709@example
710asection *bfd_make_section_old_way (bfd *abfd, const char *name);
711@end example
712@strong{Description}@*
713Create a new empty section called @var{name}
714and attach it to the end of the chain of sections for the
715BFD @var{abfd}. An attempt to create a section with a name which
716is already in use returns its pointer without changing the
717section chain.
718
719It has the funny name since this is the way it used to be
720before it was rewritten....
721
722Possible errors are:
723@itemize @bullet
724
725@item
726@code{bfd_error_invalid_operation} -
727If output has already started for this BFD.
728@item
729@code{bfd_error_no_memory} -
730If memory allocation fails.
731@end itemize
732
733@findex bfd_make_section_anyway_with_flags
734@subsubsection @code{bfd_make_section_anyway_with_flags}
735@strong{Synopsis}
736@example
737asection *bfd_make_section_anyway_with_flags
738   (bfd *abfd, const char *name, flagword flags);
739@end example
740@strong{Description}@*
741Create a new empty section called @var{name} and attach it to the end of
742the chain of sections for @var{abfd}.  Create a new section even if there
743is already a section with that name.  Also set the attributes of the
744new section to the value @var{flags}.
745
746Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
747@itemize @bullet
748
749@item
750@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
751@item
752@code{bfd_error_no_memory} - If memory allocation fails.
753@end itemize
754
755@findex bfd_make_section_anyway
756@subsubsection @code{bfd_make_section_anyway}
757@strong{Synopsis}
758@example
759asection *bfd_make_section_anyway (bfd *abfd, const char *name);
760@end example
761@strong{Description}@*
762Create a new empty section called @var{name} and attach it to the end of
763the chain of sections for @var{abfd}.  Create a new section even if there
764is already a section with that name.
765
766Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
767@itemize @bullet
768
769@item
770@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
771@item
772@code{bfd_error_no_memory} - If memory allocation fails.
773@end itemize
774
775@findex bfd_make_section_with_flags
776@subsubsection @code{bfd_make_section_with_flags}
777@strong{Synopsis}
778@example
779asection *bfd_make_section_with_flags
780   (bfd *, const char *name, flagword flags);
781@end example
782@strong{Description}@*
783Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
784bfd_set_error ()) without changing the section chain if there is already a
785section named @var{name}.  Also set the attributes of the new section to
786the value @var{flags}.  If there is an error, return @code{NULL} and set
787@code{bfd_error}.
788
789@findex bfd_make_section
790@subsubsection @code{bfd_make_section}
791@strong{Synopsis}
792@example
793asection *bfd_make_section (bfd *, const char *name);
794@end example
795@strong{Description}@*
796Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
797bfd_set_error ()) without changing the section chain if there is already a
798section named @var{name}.  If there is an error, return @code{NULL} and set
799@code{bfd_error}.
800
801@findex bfd_set_section_flags
802@subsubsection @code{bfd_set_section_flags}
803@strong{Synopsis}
804@example
805bfd_boolean bfd_set_section_flags
806   (bfd *abfd, asection *sec, flagword flags);
807@end example
808@strong{Description}@*
809Set the attributes of the section @var{sec} in the BFD
810@var{abfd} to the value @var{flags}. Return @code{TRUE} on success,
811@code{FALSE} on error. Possible error returns are:
812
813@itemize @bullet
814
815@item
816@code{bfd_error_invalid_operation} -
817The section cannot have one or more of the attributes
818requested. For example, a .bss section in @code{a.out} may not
819have the @code{SEC_HAS_CONTENTS} field set.
820@end itemize
821
822@findex bfd_map_over_sections
823@subsubsection @code{bfd_map_over_sections}
824@strong{Synopsis}
825@example
826void bfd_map_over_sections
827   (bfd *abfd,
828    void (*func) (bfd *abfd, asection *sect, void *obj),
829    void *obj);
830@end example
831@strong{Description}@*
832Call the provided function @var{func} for each section
833attached to the BFD @var{abfd}, passing @var{obj} as an
834argument. The function will be called as if by
835
836@example
837       func (abfd, the_section, obj);
838@end example
839
840This is the preferred method for iterating over sections; an
841alternative would be to use a loop:
842
843@example
844          section *p;
845          for (p = abfd->sections; p != NULL; p = p->next)
846             func (abfd, p, ...)
847@end example
848
849@findex bfd_sections_find_if
850@subsubsection @code{bfd_sections_find_if}
851@strong{Synopsis}
852@example
853asection *bfd_sections_find_if
854   (bfd *abfd,
855    bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
856    void *obj);
857@end example
858@strong{Description}@*
859Call the provided function @var{operation} for each section
860attached to the BFD @var{abfd}, passing @var{obj} as an
861argument. The function will be called as if by
862
863@example
864       operation (abfd, the_section, obj);
865@end example
866
867It returns the first section for which @var{operation} returns true.
868
869@findex bfd_set_section_size
870@subsubsection @code{bfd_set_section_size}
871@strong{Synopsis}
872@example
873bfd_boolean bfd_set_section_size
874   (bfd *abfd, asection *sec, bfd_size_type val);
875@end example
876@strong{Description}@*
877Set @var{sec} to the size @var{val}. If the operation is
878ok, then @code{TRUE} is returned, else @code{FALSE}.
879
880Possible error returns:
881@itemize @bullet
882
883@item
884@code{bfd_error_invalid_operation} -
885Writing has started to the BFD, so setting the size is invalid.
886@end itemize
887
888@findex bfd_set_section_contents
889@subsubsection @code{bfd_set_section_contents}
890@strong{Synopsis}
891@example
892bfd_boolean bfd_set_section_contents
893   (bfd *abfd, asection *section, const void *data,
894    file_ptr offset, bfd_size_type count);
895@end example
896@strong{Description}@*
897Sets the contents of the section @var{section} in BFD
898@var{abfd} to the data starting in memory at @var{data}. The
899data is written to the output section starting at offset
900@var{offset} for @var{count} octets.
901
902Normally @code{TRUE} is returned, else @code{FALSE}. Possible error
903returns are:
904@itemize @bullet
905
906@item
907@code{bfd_error_no_contents} -
908The output section does not have the @code{SEC_HAS_CONTENTS}
909attribute, so nothing can be written to it.
910@item
911and some more too
912@end itemize
913This routine is front end to the back end function
914@code{_bfd_set_section_contents}.
915
916@findex bfd_get_section_contents
917@subsubsection @code{bfd_get_section_contents}
918@strong{Synopsis}
919@example
920bfd_boolean bfd_get_section_contents
921   (bfd *abfd, asection *section, void *location, file_ptr offset,
922    bfd_size_type count);
923@end example
924@strong{Description}@*
925Read data from @var{section} in BFD @var{abfd}
926into memory starting at @var{location}. The data is read at an
927offset of @var{offset} from the start of the input section,
928and is read for @var{count} bytes.
929
930If the contents of a constructor with the @code{SEC_CONSTRUCTOR}
931flag set are requested or if the section does not have the
932@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled
933with zeroes. If no errors occur, @code{TRUE} is returned, else
934@code{FALSE}.
935
936@findex bfd_malloc_and_get_section
937@subsubsection @code{bfd_malloc_and_get_section}
938@strong{Synopsis}
939@example
940bfd_boolean bfd_malloc_and_get_section
941   (bfd *abfd, asection *section, bfd_byte **buf);
942@end example
943@strong{Description}@*
944Read all data from @var{section} in BFD @var{abfd}
945into a buffer, *@var{buf}, malloc'd by this function.
946
947@findex bfd_copy_private_section_data
948@subsubsection @code{bfd_copy_private_section_data}
949@strong{Synopsis}
950@example
951bfd_boolean bfd_copy_private_section_data
952   (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
953@end example
954@strong{Description}@*
955Copy private section information from @var{isec} in the BFD
956@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
957Return @code{TRUE} on success, @code{FALSE} on error.  Possible error
958returns are:
959
960@itemize @bullet
961
962@item
963@code{bfd_error_no_memory} -
964Not enough memory exists to create private data for @var{osec}.
965@end itemize
966@example
967#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
968     BFD_SEND (obfd, _bfd_copy_private_section_data, \
969               (ibfd, isection, obfd, osection))
970@end example
971
972@findex bfd_generic_is_group_section
973@subsubsection @code{bfd_generic_is_group_section}
974@strong{Synopsis}
975@example
976bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
977@end example
978@strong{Description}@*
979Returns TRUE if @var{sec} is a member of a group.
980
981@findex bfd_generic_discard_group
982@subsubsection @code{bfd_generic_discard_group}
983@strong{Synopsis}
984@example
985bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
986@end example
987@strong{Description}@*
988Remove all members of @var{group} from the output.
989
990