Debian Codegraph @

gnu/binutils-2.35.1/bfd/doc/section.texi

raw
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.
42
43 @node Section Output, typedef asection, Section Input, Sections
44 @subsection Section output
45 To write a new object style BFD, the various sections to be
46 written have to be created. They are attached to the BFD in
47 the same way as input sections; data is written to the
48 sections using @code{bfd_set_section_contents}.
49
50 Any program that creates or combines sections (e.g., the assembler
51 and linker) must use the @code{asection} fields @code{output_section} and
52 @code{output_offset} to indicate the file sections to which each
53 section must be written. (If the section is being created from
54 scratch, @code{output_section} should probably point to the section
55 itself and @code{output_offset} should probably be zero.)
56
57 The data to be written comes from input sections attached
58 (via @code{output_section} pointers) to
59 the output sections. The output section structure can be
60 considered a filter for the input section: the output section
61 determines the vma of the output data and the name, but the
62 input section determines the offset into the output section of
63 the data to be written.
64
65 E.g., to create a section "O", starting at 0x100, 0x123 long,
66 containing two subsections, "A" at offset 0x0 (i.e., at vma
67 0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the @code{asection}
68 structures would look like:
69
70 @example
71 section name "A"
72 output_offset 0x00
73 size 0x20
74 output_section -----------> section name "O"
75 | vma 0x100
76 section name "B" | size 0x123
77 output_offset 0x20 |
78 size 0x103 |
79 output_section --------|
80 @end example
81
82 @subsection Link orders
83 The data within a section is stored in a @dfn{link_order}.
84 These are much like the fixups in @code{gas}. The link_order
85 abstraction allows a section to grow and shrink within itself.
86
87 A link_order knows how big it is, and which is the next
88 link_order and where the raw data for it is; it also points to
89 a list of relocations which apply to it.
90
91 The link_order is used by the linker to perform relaxing on
92 final code. The compiler creates code which is as big as
93 necessary to make it work without relaxing, and the user can
94 select whether to relax. Sometimes relaxing takes a lot of
95 time. The linker runs around the relocations to see if any
96 are attached to data which can be shrunk, if so it does it on
97 a link_order by link_order basis.
98
99
100 @node typedef asection, section prototypes, Section Output, Sections
101 @subsection typedef asection
102 Here is the section structure:
103
104
105 @example
106
107 typedef struct bfd_section
108 @{
109 /* The name of the section; the name isn't a copy, the pointer is
110 the same as that passed to bfd_make_section. */
111 const char *name;
112
113 /* A unique sequence number. */
114 unsigned int id;
115
116 /* A unique section number which can be used by assembler to
117 distinguish different sections with the same section name. */
118 unsigned int section_id;
119
120 /* Which section in the bfd; 0..n-1 as sections are created in a bfd. */
121 unsigned int index;
122
123 /* The next section in the list belonging to the BFD, or NULL. */
124 struct bfd_section *next;
125
126 /* The previous section in the list belonging to the BFD, or NULL. */
127 struct bfd_section *prev;
128
129 /* The field flags contains attributes of the section. Some
130 flags are read in from the object file, and some are
131 synthesized from other information. */
132 flagword flags;
133
134 #define SEC_NO_FLAGS 0x0
135
136 /* Tells the OS to allocate space for this section when loading.
137 This is clear for a section containing debug information only. */
138 #define SEC_ALLOC 0x1
139
140 /* Tells the OS to load the section from the file when loading.
141 This is clear for a .bss section. */
142 #define SEC_LOAD 0x2
143
144 /* The section contains data still to be relocated, so there is
145 some relocation information too. */
146 #define SEC_RELOC 0x4
147
148 /* A signal to the OS that the section contains read only data. */
149 #define SEC_READONLY 0x8
150
151 /* The section contains code only. */
152 #define SEC_CODE 0x10
153
154 /* The section contains data only. */
155 #define SEC_DATA 0x20
156
157 /* The section will reside in ROM. */
158 #define SEC_ROM 0x40
159
160 /* The section contains constructor information. This section
161 type is used by the linker to create lists of constructors and
162 destructors used by @code{g++}. When a back end sees a symbol
163 which should be used in a constructor list, it creates a new
164 section for the type of name (e.g., @code{__CTOR_LIST__}), attaches
165 the symbol to it, and builds a relocation. To build the lists
166 of constructors, all the linker has to do is catenate all the
167 sections called @code{__CTOR_LIST__} and relocate the data
168 contained within - exactly the operations it would peform on
169 standard data. */
170 #define SEC_CONSTRUCTOR 0x80
171
172 /* The section has contents - a data section could be
173 @code{SEC_ALLOC} | @code{SEC_HAS_CONTENTS}; a debug section could be
174 @code{SEC_HAS_CONTENTS} */
175 #define SEC_HAS_CONTENTS 0x100
176
177 /* An instruction to the linker to not output the section
178 even if it has information which would normally be written. */
179 #define SEC_NEVER_LOAD 0x200
180
181 /* The section contains thread local data. */
182 #define SEC_THREAD_LOCAL 0x400
183
184 /* The section's size is fixed. Generic linker code will not
185 recalculate it and it is up to whoever has set this flag to
186 get the size right. */
187 #define SEC_FIXED_SIZE 0x800
188
189 /* The section contains common symbols (symbols may be defined
190 multiple times, the value of a symbol is the amount of
191 space it requires, and the largest symbol value is the one
192 used). Most targets have exactly one of these (which we
193 translate to bfd_com_section_ptr), but ECOFF has two. */
194 #define SEC_IS_COMMON 0x1000
195
196 /* The section contains only debugging information. For
197 example, this is set for ELF .debug and .stab sections.
198 strip tests this flag to see if a section can be
199 discarded. */
200 #define SEC_DEBUGGING 0x2000
201
202 /* The contents of this section are held in memory pointed to
203 by the contents field. This is checked by bfd_get_section_contents,
204 and the data is retrieved from memory if appropriate. */
205 #define SEC_IN_MEMORY 0x4000
206
207 /* The contents of this section are to be excluded by the
208 linker for executable and shared objects unless those
209 objects are to be further relocated. */
210 #define SEC_EXCLUDE 0x8000
211
212 /* The contents of this section are to be sorted based on the sum of
213 the symbol and addend values specified by the associated relocation
214 entries. Entries without associated relocation entries will be
215 appended to the end of the section in an unspecified order. */
216 #define SEC_SORT_ENTRIES 0x10000
217
218 /* When linking, duplicate sections of the same name should be
219 discarded, rather than being combined into a single section as
220 is usually done. This is similar to how common symbols are
221 handled. See SEC_LINK_DUPLICATES below. */
222 #define SEC_LINK_ONCE 0x20000
223
224 /* If SEC_LINK_ONCE is set, this bitfield describes how the linker
225 should handle duplicate sections. */
226 #define SEC_LINK_DUPLICATES 0xc0000
227
228 /* This value for SEC_LINK_DUPLICATES means that duplicate
229 sections with the same name should simply be discarded. */
230 #define SEC_LINK_DUPLICATES_DISCARD 0x0
231
232 /* This value for SEC_LINK_DUPLICATES means that the linker
233 should warn if there are any duplicate sections, although
234 it should still only link one copy. */
235 #define SEC_LINK_DUPLICATES_ONE_ONLY 0x40000
236
237 /* This value for SEC_LINK_DUPLICATES means that the linker
238 should warn if any duplicate sections are a different size. */
239 #define SEC_LINK_DUPLICATES_SAME_SIZE 0x80000
240
241 /* This value for SEC_LINK_DUPLICATES means that the linker
242 should warn if any duplicate sections contain different
243 contents. */
244 #define SEC_LINK_DUPLICATES_SAME_CONTENTS \
245 (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
246
247 /* This section was created by the linker as part of dynamic
248 relocation or other arcane processing. It is skipped when
249 going through the first-pass output, trusting that someone
250 else up the line will take care of it later. */
251 #define SEC_LINKER_CREATED 0x100000
252
253 /* This section contains a section ID to distinguish different
254 sections with the same section name. */
255 #define SEC_ASSEMBLER_SECTION_ID 0x100000
256
257 /* This section should not be subject to garbage collection.
258 Also set to inform the linker that this section should not be
259 listed in the link map as discarded. */
260 #define SEC_KEEP 0x200000
261
262 /* This section contains "short" data, and should be placed
263 "near" the GP. */
264 #define SEC_SMALL_DATA 0x400000
265
266 /* Attempt to merge identical entities in the section.
267 Entity size is given in the entsize field. */
268 #define SEC_MERGE 0x800000
269
270 /* If given with SEC_MERGE, entities to merge are zero terminated
271 strings where entsize specifies character size instead of fixed
272 size entries. */
273 #define SEC_STRINGS 0x1000000
274
275 /* This section contains data about section groups. */
276 #define SEC_GROUP 0x2000000
277
278 /* The section is a COFF shared library section. This flag is
279 only for the linker. If this type of section appears in
280 the input file, the linker must copy it to the output file
281 without changing the vma or size. FIXME: Although this
282 was originally intended to be general, it really is COFF
283 specific (and the flag was renamed to indicate this). It
284 might be cleaner to have some more general mechanism to
285 allow the back end to control what the linker does with
286 sections. */
287 #define SEC_COFF_SHARED_LIBRARY 0x4000000
288
289 /* This input section should be copied to output in reverse order
290 as an array of pointers. This is for ELF linker internal use
291 only. */
292 #define SEC_ELF_REVERSE_COPY 0x4000000
293
294 /* This section contains data which may be shared with other
295 executables or shared objects. This is for COFF only. */
296 #define SEC_COFF_SHARED 0x8000000
297
298 /* This section should be compressed. This is for ELF linker
299 internal use only. */
300 #define SEC_ELF_COMPRESS 0x8000000
301
302 /* When a section with this flag is being linked, then if the size of
303 the input section is less than a page, it should not cross a page
304 boundary. If the size of the input section is one page or more,
305 it should be aligned on a page boundary. This is for TI
306 TMS320C54X only. */
307 #define SEC_TIC54X_BLOCK 0x10000000
308
309 /* This section should be renamed. This is for ELF linker
310 internal use only. */
311 #define SEC_ELF_RENAME 0x10000000
312
313 /* Conditionally link this section; do not link if there are no
314 references found to any symbol in the section. This is for TI
315 TMS320C54X only. */
316 #define SEC_TIC54X_CLINK 0x20000000
317
318 /* This section contains vliw code. This is for Toshiba MeP only. */
319 #define SEC_MEP_VLIW 0x20000000
320
321 /* All symbols, sizes and relocations in this section are octets
322 instead of bytes. Required for DWARF debug sections as DWARF
323 information is organized in octets, not bytes. */
324 #define SEC_ELF_OCTETS 0x40000000
325
326 /* Indicate that section has the no read flag set. This happens
327 when memory read flag isn't set. */
328 #define SEC_COFF_NOREAD 0x40000000
329
330 /* Indicate that section has the purecode flag set. */
331 #define SEC_ELF_PURECODE 0x80000000
332
333 /* End of section flags. */
334
335 /* Some internal packed boolean fields. */
336
337 /* See the vma field. */
338 unsigned int user_set_vma : 1;
339
340 /* A mark flag used by some of the linker backends. */
341 unsigned int linker_mark : 1;
342
343 /* Another mark flag used by some of the linker backends. Set for
344 output sections that have an input section. */
345 unsigned int linker_has_input : 1;
346
347 /* Mark flag used by some linker backends for garbage collection. */
348 unsigned int gc_mark : 1;
349
350 /* Section compression status. */
351 unsigned int compress_status : 2;
352 #define COMPRESS_SECTION_NONE 0
353 #define COMPRESS_SECTION_DONE 1
354 #define DECOMPRESS_SECTION_SIZED 2
355
356 /* The following flags are used by the ELF linker. */
357
358 /* Mark sections which have been allocated to segments. */
359 unsigned int segment_mark : 1;
360
361 /* Type of sec_info information. */
362 unsigned int sec_info_type:3;
363 #define SEC_INFO_TYPE_NONE 0
364 #define SEC_INFO_TYPE_STABS 1
365 #define SEC_INFO_TYPE_MERGE 2
366 #define SEC_INFO_TYPE_EH_FRAME 3
367 #define SEC_INFO_TYPE_JUST_SYMS 4
368 #define SEC_INFO_TYPE_TARGET 5
369 #define SEC_INFO_TYPE_EH_FRAME_ENTRY 6
370
371 /* Nonzero if this section uses RELA relocations, rather than REL. */
372 unsigned int use_rela_p:1;
373
374 /* Bits used by various backends. The generic code doesn't touch
375 these fields. */
376
377 unsigned int sec_flg0:1;
378 unsigned int sec_flg1:1;
379 unsigned int sec_flg2:1;
380 unsigned int sec_flg3:1;
381 unsigned int sec_flg4:1;
382 unsigned int sec_flg5:1;
383
384 /* End of internal packed boolean fields. */
385
386 /* The virtual memory address of the section - where it will be
387 at run time. The symbols are relocated against this. The
388 user_set_vma flag is maintained by bfd; if it's not set, the
389 backend can assign addresses (for example, in @code{a.out}, where
390 the default address for @code{.data} is dependent on the specific
391 target and various flags). */
392 bfd_vma vma;
393
394 /* The load address of the section - where it would be in a
395 rom image; really only used for writing section header
396 information. */
397 bfd_vma lma;
398
399 /* The size of the section in *octets*, as it will be output.
400 Contains a value even if the section has no contents (e.g., the
401 size of @code{.bss}). */
402 bfd_size_type size;
403
404 /* For input sections, the original size on disk of the section, in
405 octets. This field should be set for any section whose size is
406 changed by linker relaxation. It is required for sections where
407 the linker relaxation scheme doesn't cache altered section and
408 reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing
409 targets), and thus the original size needs to be kept to read the
410 section multiple times. For output sections, rawsize holds the
411 section size calculated on a previous linker relaxation pass. */
412 bfd_size_type rawsize;
413
414 /* The compressed size of the section in octets. */
415 bfd_size_type compressed_size;
416
417 /* Relaxation table. */
418 struct relax_table *relax;
419
420 /* Count of used relaxation table entries. */
421 int relax_count;
422
423
424 /* If this section is going to be output, then this value is the
425 offset in *bytes* into the output section of the first byte in the
426 input section (byte ==> smallest addressable unit on the
427 target). In most cases, if this was going to start at the
428 100th octet (8-bit quantity) in the output section, this value
429 would be 100. However, if the target byte size is 16 bits
430 (bfd_octets_per_byte is "2"), this value would be 50. */
431 bfd_vma output_offset;
432
433 /* The output section through which to map on output. */
434 struct bfd_section *output_section;
435
436 /* The alignment requirement of the section, as an exponent of 2 -
437 e.g., 3 aligns to 2^3 (or 8). */
438 unsigned int alignment_power;
439
440 /* If an input section, a pointer to a vector of relocation
441 records for the data in this section. */
442 struct reloc_cache_entry *relocation;
443
444 /* If an output section, a pointer to a vector of pointers to
445 relocation records for the data in this section. */
446 struct reloc_cache_entry **orelocation;
447
448 /* The number of relocation records in one of the above. */
449 unsigned reloc_count;
450
451 /* Information below is back end specific - and not always used
452 or updated. */
453
454 /* File position of section data. */
455 file_ptr filepos;
456
457 /* File position of relocation info. */
458 file_ptr rel_filepos;
459
460 /* File position of line data. */
461 file_ptr line_filepos;
462
463 /* Pointer to data for applications. */
464 void *userdata;
465
466 /* If the SEC_IN_MEMORY flag is set, this points to the actual
467 contents. */
468 unsigned char *contents;
469
470 /* Attached line number information. */
471 alent *lineno;
472
473 /* Number of line number records. */
474 unsigned int lineno_count;
475
476 /* Entity size for merging purposes. */
477 unsigned int entsize;
478
479 /* Points to the kept section if this section is a link-once section,
480 and is discarded. */
481 struct bfd_section *kept_section;
482
483 /* When a section is being output, this value changes as more
484 linenumbers are written out. */
485 file_ptr moving_line_filepos;
486
487 /* What the section number is in the target world. */
488 int target_index;
489
490 void *used_by_bfd;
491
492 /* If this is a constructor section then here is a list of the
493 relocations created to relocate items within it. */
494 struct relent_chain *constructor_chain;
495
496 /* The BFD which owns the section. */
497 bfd *owner;
498
499 /* A symbol which points at this section only. */
500 struct bfd_symbol *symbol;
501 struct bfd_symbol **symbol_ptr_ptr;
502
503 /* Early in the link process, map_head and map_tail are used to build
504 a list of input sections attached to an output section. Later,
505 output sections use these fields for a list of bfd_link_order
506 structs. The linked_to_symbol_name field is for ELF assembler
507 internal use. */
508 union @{
509 struct bfd_link_order *link_order;
510 struct bfd_section *s;
511 const char *linked_to_symbol_name;
512 @} map_head, map_tail;
513 /* Points to the output section this section is already assigned to, if any.
514 This is used when support for non-contiguous memory regions is enabled. */
515 struct bfd_section *already_assigned;
516
517 @} asection;
518
519 /* Relax table contains information about instructions which can
520 be removed by relaxation -- replacing a long address with a
521 short address. */
522 struct relax_table @{
523 /* Address where bytes may be deleted. */
524 bfd_vma addr;
525
526 /* Number of bytes to be deleted. */
527 int size;
528 @};
529
530 static inline const char *
531 bfd_section_name (const asection *sec)
532 @{
533 return sec->name;
534 @}
535
536 static inline bfd_size_type
537 bfd_section_size (const asection *sec)
538 @{
539 return sec->size;
540 @}
541
542 static inline bfd_vma
543 bfd_section_vma (const asection *sec)
544 @{
545 return sec->vma;
546 @}
547
548 static inline bfd_vma
549 bfd_section_lma (const asection *sec)
550 @{
551 return sec->lma;
552 @}
553
554 static inline unsigned int
555 bfd_section_alignment (const asection *sec)
556 @{
557 return sec->alignment_power;
558 @}
559
560 static inline flagword
561 bfd_section_flags (const asection *sec)
562 @{
563 return sec->flags;
564 @}
565
566 static inline void *
567 bfd_section_userdata (const asection *sec)
568 @{
569 return sec->userdata;
570 @}
571 static inline bfd_boolean
572 bfd_is_com_section (const asection *sec)
573 @{
574 return (sec->flags & SEC_IS_COMMON) != 0;
575 @}
576
577 /* Note: the following are provided as inline functions rather than macros
578 because not all callers use the return value. A macro implementation
579 would use a comma expression, eg: "((ptr)->foo = val, TRUE)" and some
580 compilers will complain about comma expressions that have no effect. */
581 static inline bfd_boolean
582 bfd_set_section_userdata (asection *sec, void *val)
583 @{
584 sec->userdata = val;
585 return TRUE;
586 @}
587
588 static inline bfd_boolean
589 bfd_set_section_vma (asection *sec, bfd_vma val)
590 @{
591 sec->vma = sec->lma = val;
592 sec->user_set_vma = TRUE;
593 return TRUE;
594 @}
595
596 static inline bfd_boolean
597 bfd_set_section_lma (asection *sec, bfd_vma val)
598 @{
599 sec->lma = val;
600 return TRUE;
601 @}
602
603 static inline bfd_boolean
604 bfd_set_section_alignment (asection *sec, unsigned int val)
605 @{
606 sec->alignment_power = val;
607 return TRUE;
608 @}
609
610 /* These sections are global, and are managed by BFD. The application
611 and target back end are not permitted to change the values in
612 these sections. */
613 extern asection _bfd_std_section[4];
614
615 #define BFD_ABS_SECTION_NAME "*ABS*"
616 #define BFD_UND_SECTION_NAME "*UND*"
617 #define BFD_COM_SECTION_NAME "*COM*"
618 #define BFD_IND_SECTION_NAME "*IND*"
619
620 /* Pointer to the common section. */
621 #define bfd_com_section_ptr (&_bfd_std_section[0])
622 /* Pointer to the undefined section. */
623 #define bfd_und_section_ptr (&_bfd_std_section[1])
624 /* Pointer to the absolute section. */
625 #define bfd_abs_section_ptr (&_bfd_std_section[2])
626 /* Pointer to the indirect section. */
627 #define bfd_ind_section_ptr (&_bfd_std_section[3])
628
629 static inline bfd_boolean
630 bfd_is_und_section (const asection *sec)
631 @{
632 return sec == bfd_und_section_ptr;
633 @}
634
635 static inline bfd_boolean
636 bfd_is_abs_section (const asection *sec)
637 @{
638 return sec == bfd_abs_section_ptr;
639 @}
640
641 static inline bfd_boolean
642 bfd_is_ind_section (const asection *sec)
643 @{
644 return sec == bfd_ind_section_ptr;
645 @}
646
647 static inline bfd_boolean
648 bfd_is_const_section (const asection *sec)
649 @{
650 return (sec >= _bfd_std_section
651 && sec < _bfd_std_section + (sizeof (_bfd_std_section)
652 / sizeof (_bfd_std_section[0])));
653 @}
654
655 /* Return TRUE if input section SEC has been discarded. */
656 static inline bfd_boolean
657 discarded_section (const asection *sec)
658 @{
659 return (!bfd_is_abs_section (sec)
660 && bfd_is_abs_section (sec->output_section)
661 && sec->sec_info_type != SEC_INFO_TYPE_MERGE
662 && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS);
663 @}
664
665 #define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS) \
666 /* name, id, section_id, index, next, prev, flags, user_set_vma, */ \
667 @{ NAME, IDX, 0, 0, NULL, NULL, FLAGS, 0, \
668 \
669 /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \
670 0, 0, 1, 0, \
671 \
672 /* segment_mark, sec_info_type, use_rela_p, */ \
673 0, 0, 0, \
674 \
675 /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \
676 0, 0, 0, 0, 0, 0, \
677 \
678 /* vma, lma, size, rawsize, compressed_size, relax, relax_count, */ \
679 0, 0, 0, 0, 0, 0, 0, \
680 \
681 /* output_offset, output_section, alignment_power, */ \
682 0, &SEC, 0, \
683 \
684 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \
685 NULL, NULL, 0, 0, 0, \
686 \
687 /* line_filepos, userdata, contents, lineno, lineno_count, */ \
688 0, NULL, NULL, NULL, 0, \
689 \
690 /* entsize, kept_section, moving_line_filepos, */ \
691 0, NULL, 0, \
692 \
693 /* target_index, used_by_bfd, constructor_chain, owner, */ \
694 0, NULL, NULL, NULL, \
695 \
696 /* symbol, symbol_ptr_ptr, */ \
697 (struct bfd_symbol *) SYM, &SEC.symbol, \
698 \
699 /* map_head, map_tail, already_assigned */ \
700 @{ NULL @}, @{ NULL @}, NULL \
701 \
702 @}
703
704 /* We use a macro to initialize the static asymbol structures because
705 traditional C does not permit us to initialize a union member while
706 gcc warns if we don't initialize it.
707 the_bfd, name, value, attr, section [, udata] */
708 #ifdef __STDC__
709 #define GLOBAL_SYM_INIT(NAME, SECTION) \
710 @{ 0, NAME, 0, BSF_SECTION_SYM, SECTION, @{ 0 @}@}
711 #else
712 #define GLOBAL_SYM_INIT(NAME, SECTION) \
713 @{ 0, NAME, 0, BSF_SECTION_SYM, SECTION @}
714 #endif
715
716 @end example
717
718 @node section prototypes, , typedef asection, Sections
719 @subsection Section prototypes
720 These are the functions exported by the section handling part of BFD.
721
722 @findex bfd_section_list_clear
723 @subsubsection @code{bfd_section_list_clear}
724 @strong{Synopsis}
725 @example
726 void bfd_section_list_clear (bfd *);
727 @end example
728 @strong{Description}@*
729 Clears the section list, and also resets the section count and
730 hash table entries.
731
732 @findex bfd_get_section_by_name
733 @subsubsection @code{bfd_get_section_by_name}
734 @strong{Synopsis}
735 @example
736 asection *bfd_get_section_by_name (bfd *abfd, const char *name);
737 @end example
738 @strong{Description}@*
739 Return the most recently created section attached to @var{abfd}
740 named @var{name}. Return NULL if no such section exists.
741
742 @findex bfd_get_next_section_by_name
743 @subsubsection @code{bfd_get_next_section_by_name}
744 @strong{Synopsis}
745 @example
746 asection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec);
747 @end example
748 @strong{Description}@*
749 Given @var{sec} is a section returned by @code{bfd_get_section_by_name},
750 return the next most recently created section attached to the same
751 BFD with the same name, or if no such section exists in the same BFD and
752 IBFD is non-NULL, the next section with the same name in any input
753 BFD following IBFD. Return NULL on finding no section.
754
755 @findex bfd_get_linker_section
756 @subsubsection @code{bfd_get_linker_section}
757 @strong{Synopsis}
758 @example
759 asection *bfd_get_linker_section (bfd *abfd, const char *name);
760 @end example
761 @strong{Description}@*
762 Return the linker created section attached to @var{abfd}
763 named @var{name}. Return NULL if no such section exists.
764
765 @findex bfd_get_section_by_name_if
766 @subsubsection @code{bfd_get_section_by_name_if}
767 @strong{Synopsis}
768 @example
769 asection *bfd_get_section_by_name_if
770 (bfd *abfd,
771 const char *name,
772 bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
773 void *obj);
774 @end example
775 @strong{Description}@*
776 Call the provided function @var{func} for each section
777 attached to the BFD @var{abfd} whose name matches @var{name},
778 passing @var{obj} as an argument. The function will be called
779 as if by
780
781 @example
782 func (abfd, the_section, obj);
783 @end example
784
785 It returns the first section for which @var{func} returns true,
786 otherwise @code{NULL}.
787
788 @findex bfd_get_unique_section_name
789 @subsubsection @code{bfd_get_unique_section_name}
790 @strong{Synopsis}
791 @example
792 char *bfd_get_unique_section_name
793 (bfd *abfd, const char *templat, int *count);
794 @end example
795 @strong{Description}@*
796 Invent a section name that is unique in @var{abfd} by tacking
797 a dot and a digit suffix onto the original @var{templat}. If
798 @var{count} is non-NULL, then it specifies the first number
799 tried as a suffix to generate a unique name. The value
800 pointed to by @var{count} will be incremented in this case.
801
802 @findex bfd_make_section_old_way
803 @subsubsection @code{bfd_make_section_old_way}
804 @strong{Synopsis}
805 @example
806 asection *bfd_make_section_old_way (bfd *abfd, const char *name);
807 @end example
808 @strong{Description}@*
809 Create a new empty section called @var{name}
810 and attach it to the end of the chain of sections for the
811 BFD @var{abfd}. An attempt to create a section with a name which
812 is already in use returns its pointer without changing the
813 section chain.
814
815 It has the funny name since this is the way it used to be
816 before it was rewritten....
817
818 Possible errors are:
819 @itemize @bullet
820
821 @item
822 @code{bfd_error_invalid_operation} -
823 If output has already started for this BFD.
824 @item
825 @code{bfd_error_no_memory} -
826 If memory allocation fails.
827 @end itemize
828
829 @findex bfd_make_section_anyway_with_flags
830 @subsubsection @code{bfd_make_section_anyway_with_flags}
831 @strong{Synopsis}
832 @example
833 asection *bfd_make_section_anyway_with_flags
834 (bfd *abfd, const char *name, flagword flags);
835 @end example
836 @strong{Description}@*
837 Create a new empty section called @var{name} and attach it to the end of
838 the chain of sections for @var{abfd}. Create a new section even if there
839 is already a section with that name. Also set the attributes of the
840 new section to the value @var{flags}.
841
842 Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
843 @itemize @bullet
844
845 @item
846 @code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
847 @item
848 @code{bfd_error_no_memory} - If memory allocation fails.
849 @end itemize
850
851 @findex bfd_make_section_anyway
852 @subsubsection @code{bfd_make_section_anyway}
853 @strong{Synopsis}
854 @example
855 asection *bfd_make_section_anyway (bfd *abfd, const char *name);
856 @end example
857 @strong{Description}@*
858 Create a new empty section called @var{name} and attach it to the end of
859 the chain of sections for @var{abfd}. Create a new section even if there
860 is already a section with that name.
861
862 Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
863 @itemize @bullet
864
865 @item
866 @code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
867 @item
868 @code{bfd_error_no_memory} - If memory allocation fails.
869 @end itemize
870
871 @findex bfd_make_section_with_flags
872 @subsubsection @code{bfd_make_section_with_flags}
873 @strong{Synopsis}
874 @example
875 asection *bfd_make_section_with_flags
876 (bfd *, const char *name, flagword flags);
877 @end example
878 @strong{Description}@*
879 Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
880 bfd_set_error ()) without changing the section chain if there is already a
881 section named @var{name}. Also set the attributes of the new section to
882 the value @var{flags}. If there is an error, return @code{NULL} and set
883 @code{bfd_error}.
884
885 @findex bfd_make_section
886 @subsubsection @code{bfd_make_section}
887 @strong{Synopsis}
888 @example
889 asection *bfd_make_section (bfd *, const char *name);
890 @end example
891 @strong{Description}@*
892 Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
893 bfd_set_error ()) without changing the section chain if there is already a
894 section named @var{name}. If there is an error, return @code{NULL} and set
895 @code{bfd_error}.
896
897 @findex bfd_set_section_flags
898 @subsubsection @code{bfd_set_section_flags}
899 @strong{Synopsis}
900 @example
901 bfd_boolean bfd_set_section_flags (asection *sec, flagword flags);
902 @end example
903 @strong{Description}@*
904 Set the attributes of the section @var{sec} to the value @var{flags}.
905 Return @code{TRUE} on success, @code{FALSE} on error. Possible error
906 returns are:
907
908 @itemize @bullet
909
910 @item
911 @code{bfd_error_invalid_operation} -
912 The section cannot have one or more of the attributes
913 requested. For example, a .bss section in @code{a.out} may not
914 have the @code{SEC_HAS_CONTENTS} field set.
915 @end itemize
916
917 @findex bfd_rename_section
918 @subsubsection @code{bfd_rename_section}
919 @strong{Synopsis}
920 @example
921 void bfd_rename_section
922 (asection *sec, const char *newname);
923 @end example
924 @strong{Description}@*
925 Rename section @var{sec} to @var{newname}.
926
927 @findex bfd_map_over_sections
928 @subsubsection @code{bfd_map_over_sections}
929 @strong{Synopsis}
930 @example
931 void bfd_map_over_sections
932 (bfd *abfd,
933 void (*func) (bfd *abfd, asection *sect, void *obj),
934 void *obj);
935 @end example
936 @strong{Description}@*
937 Call the provided function @var{func} for each section
938 attached to the BFD @var{abfd}, passing @var{obj} as an
939 argument. The function will be called as if by
940
941 @example
942 func (abfd, the_section, obj);
943 @end example
944
945 This is the preferred method for iterating over sections; an
946 alternative would be to use a loop:
947
948 @example
949 asection *p;
950 for (p = abfd->sections; p != NULL; p = p->next)
951 func (abfd, p, ...)
952 @end example
953
954 @findex bfd_sections_find_if
955 @subsubsection @code{bfd_sections_find_if}
956 @strong{Synopsis}
957 @example
958 asection *bfd_sections_find_if
959 (bfd *abfd,
960 bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
961 void *obj);
962 @end example
963 @strong{Description}@*
964 Call the provided function @var{operation} for each section
965 attached to the BFD @var{abfd}, passing @var{obj} as an
966 argument. The function will be called as if by
967
968 @example
969 operation (abfd, the_section, obj);
970 @end example
971
972 It returns the first section for which @var{operation} returns true.
973
974 @findex bfd_set_section_size
975 @subsubsection @code{bfd_set_section_size}
976 @strong{Synopsis}
977 @example
978 bfd_boolean bfd_set_section_size (asection *sec, bfd_size_type val);
979 @end example
980 @strong{Description}@*
981 Set @var{sec} to the size @var{val}. If the operation is
982 ok, then @code{TRUE} is returned, else @code{FALSE}.
983
984 Possible error returns:
985 @itemize @bullet
986
987 @item
988 @code{bfd_error_invalid_operation} -
989 Writing has started to the BFD, so setting the size is invalid.
990 @end itemize
991
992 @findex bfd_set_section_contents
993 @subsubsection @code{bfd_set_section_contents}
994 @strong{Synopsis}
995 @example
996 bfd_boolean bfd_set_section_contents
997 (bfd *abfd, asection *section, const void *data,
998 file_ptr offset, bfd_size_type count);
999 @end example
1000 @strong{Description}@*
1001 Sets the contents of the section @var{section} in BFD
1002 @var{abfd} to the data starting in memory at @var{location}.
1003 The data is written to the output section starting at offset
1004 @var{offset} for @var{count} octets.
1005
1006 Normally @code{TRUE} is returned, but @code{FALSE} is returned if
1007 there was an error. Possible error returns are:
1008 @itemize @bullet
1009
1010 @item
1011 @code{bfd_error_no_contents} -
1012 The output section does not have the @code{SEC_HAS_CONTENTS}
1013 attribute, so nothing can be written to it.
1014 @item
1015 @code{bfd_error_bad_value} -
1016 The section is unable to contain all of the data.
1017 @item
1018 @code{bfd_error_invalid_operation} -
1019 The BFD is not writeable.
1020 @item
1021 and some more too.
1022 @end itemize
1023 This routine is front end to the back end function
1024 @code{_bfd_set_section_contents}.
1025
1026 @findex bfd_get_section_contents
1027 @subsubsection @code{bfd_get_section_contents}
1028 @strong{Synopsis}
1029 @example
1030 bfd_boolean bfd_get_section_contents
1031 (bfd *abfd, asection *section, void *location, file_ptr offset,
1032 bfd_size_type count);
1033 @end example
1034 @strong{Description}@*
1035 Read data from @var{section} in BFD @var{abfd}
1036 into memory starting at @var{location}. The data is read at an
1037 offset of @var{offset} from the start of the input section,
1038 and is read for @var{count} bytes.
1039
1040 If the contents of a constructor with the @code{SEC_CONSTRUCTOR}
1041 flag set are requested or if the section does not have the
1042 @code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled
1043 with zeroes. If no errors occur, @code{TRUE} is returned, else
1044 @code{FALSE}.
1045
1046 @findex bfd_malloc_and_get_section
1047 @subsubsection @code{bfd_malloc_and_get_section}
1048 @strong{Synopsis}
1049 @example
1050 bfd_boolean bfd_malloc_and_get_section
1051 (bfd *abfd, asection *section, bfd_byte **buf);
1052 @end example
1053 @strong{Description}@*
1054 Read all data from @var{section} in BFD @var{abfd}
1055 into a buffer, *@var{buf}, malloc'd by this function.
1056
1057 @findex bfd_copy_private_section_data
1058 @subsubsection @code{bfd_copy_private_section_data}
1059 @strong{Synopsis}
1060 @example
1061 bfd_boolean bfd_copy_private_section_data
1062 (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
1063 @end example
1064 @strong{Description}@*
1065 Copy private section information from @var{isec} in the BFD
1066 @var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
1067 Return @code{TRUE} on success, @code{FALSE} on error. Possible error
1068 returns are:
1069
1070 @itemize @bullet
1071
1072 @item
1073 @code{bfd_error_no_memory} -
1074 Not enough memory exists to create private data for @var{osec}.
1075 @end itemize
1076 @example
1077 #define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
1078 BFD_SEND (obfd, _bfd_copy_private_section_data, \
1079 (ibfd, isection, obfd, osection))
1080 @end example
1081
1082 @findex bfd_generic_is_group_section
1083 @subsubsection @code{bfd_generic_is_group_section}
1084 @strong{Synopsis}
1085 @example
1086 bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
1087 @end example
1088 @strong{Description}@*
1089 Returns TRUE if @var{sec} is a member of a group.
1090
1091 @findex bfd_generic_group_name
1092 @subsubsection @code{bfd_generic_group_name}
1093 @strong{Synopsis}
1094 @example
1095 const char *bfd_generic_group_name (bfd *, const asection *sec);
1096 @end example
1097 @strong{Description}@*
1098 Returns group name if @var{sec} is a member of a group.
1099
1100 @findex bfd_generic_discard_group
1101 @subsubsection @code{bfd_generic_discard_group}
1102 @strong{Synopsis}
1103 @example
1104 bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
1105 @end example
1106 @strong{Description}@*
1107 Remove all members of @var{group} from the output.
1108