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