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.
7 Sections are supported in BFD in @code{section.c}.
13 * section prototypes::
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.
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}.
25 Names need not be unique; for example a COFF file may have several
26 sections named @code{.data}.
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
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
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}.
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.)
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.
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:
77 output_section -----------> section name "O"
79 section name "B" | size 0x123
82 output_section --------|
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.
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.
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.
103 @node typedef asection, section prototypes, Section Output, Sections
104 @subsection typedef asection
105 Here is the section structure:
110 typedef struct bfd_section
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. */
116 /* A unique sequence number. */
119 /* Which section in the bfd; 0..n-1 as sections are created in a bfd. */
122 /* The next section in the list belonging to the BFD, or NULL. */
123 struct bfd_section *next;
125 /* The previous section in the list belonging to the BFD, or NULL. */
126 struct bfd_section *prev;
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. */
133 #define SEC_NO_FLAGS 0x000
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
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
143 /* The section contains data still to be relocated, so there is
144 some relocation information too. */
145 #define SEC_RELOC 0x004
147 /* A signal to the OS that the section contains read only data. */
148 #define SEC_READONLY 0x008
150 /* The section contains code only. */
151 #define SEC_CODE 0x010
153 /* The section contains data only. */
154 #define SEC_DATA 0x020
156 /* The section will reside in ROM. */
157 #define SEC_ROM 0x040
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
169 #define SEC_CONSTRUCTOR 0x080
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
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
180 /* The section contains thread local data. */
181 #define SEC_THREAD_LOCAL 0x400
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
189 #define SEC_HAS_GOT_REF 0x800
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
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
202 #define SEC_DEBUGGING 0x2000
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
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
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
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
226 /* If SEC_LINK_ONCE is set, this bitfield describes how the linker
227 should handle duplicate sections. */
228 #define SEC_LINK_DUPLICATES 0xc0000
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
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
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
243 /* This value for SEC_LINK_DUPLICATES means that the linker
244 should warn if any duplicate sections contain different
246 #define SEC_LINK_DUPLICATES_SAME_CONTENTS \
247 (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
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
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
260 /* This section contains "short" data, and should be placed
262 #define SEC_SMALL_DATA 0x400000
264 /* Attempt to merge identical entities in the section.
265 Entity size is given in the entsize field. */
266 #define SEC_MERGE 0x800000
268 /* If given with SEC_MERGE, entities to merge are zero terminated
269 strings where entsize specifies character size instead of fixed
271 #define SEC_STRINGS 0x1000000
273 /* This section contains data about section groups. */
274 #define SEC_GROUP 0x2000000
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
285 #define SEC_COFF_SHARED_LIBRARY 0x4000000
287 /* This section contains data which may be shared with other
288 executables or shared objects. This is for COFF only. */
289 #define SEC_COFF_SHARED 0x8000000
291 /* When a section with this flag is being linked, then if the size of
292 the input section is less than a page, it should not cross a page
293 boundary. If the size of the input section is one page or more,
294 it should be aligned on a page boundary. This is for TI
296 #define SEC_TIC54X_BLOCK 0x10000000
298 /* Conditionally link this section; do not link if there are no
299 references found to any symbol in the section. This is for TI
301 #define SEC_TIC54X_CLINK 0x20000000
303 /* Indicate that section has the no read flag set. This happens
304 when memory read flag isn't set. */
305 #define SEC_COFF_NOREAD 0x40000000
307 /* End of section flags. */
309 /* Some internal packed boolean fields. */
311 /* See the vma field. */
312 unsigned int user_set_vma : 1;
314 /* A mark flag used by some of the linker backends. */
315 unsigned int linker_mark : 1;
317 /* Another mark flag used by some of the linker backends. Set for
318 output sections that have an input section. */
319 unsigned int linker_has_input : 1;
321 /* Mark flag used by some linker backends for garbage collection. */
322 unsigned int gc_mark : 1;
324 /* The following flags are used by the ELF linker. */
326 /* Mark sections which have been allocated to segments. */
327 unsigned int segment_mark : 1;
329 /* Type of sec_info information. */
330 unsigned int sec_info_type:3;
331 #define ELF_INFO_TYPE_NONE 0
332 #define ELF_INFO_TYPE_STABS 1
333 #define ELF_INFO_TYPE_MERGE 2
334 #define ELF_INFO_TYPE_EH_FRAME 3
335 #define ELF_INFO_TYPE_JUST_SYMS 4
337 /* Nonzero if this section uses RELA relocations, rather than REL. */
338 unsigned int use_rela_p:1;
340 /* Bits used by various backends. The generic code doesn't touch
343 /* Nonzero if this section has TLS related relocations. */
344 unsigned int has_tls_reloc:1;
346 /* Nonzero if this section has a call to __tls_get_addr. */
347 unsigned int has_tls_get_addr_call:1;
349 /* Nonzero if this section has a gp reloc. */
350 unsigned int has_gp_reloc:1;
352 /* Nonzero if this section needs the relax finalize pass. */
353 unsigned int need_finalize_relax:1;
355 /* Whether relocations have been processed. */
356 unsigned int reloc_done : 1;
358 /* End of internal packed boolean fields. */
360 /* The virtual memory address of the section - where it will be
361 at run time. The symbols are relocated against this. The
362 user_set_vma flag is maintained by bfd; if it's not set, the
363 backend can assign addresses (for example, in @code{a.out}, where
364 the default address for @code{.data} is dependent on the specific
365 target and various flags). */
368 /* The load address of the section - where it would be in a
369 rom image; really only used for writing section header
373 /* The size of the section in octets, as it will be output.
374 Contains a value even if the section has no contents (e.g., the
375 size of @code{.bss}). */
378 /* For input sections, the original size on disk of the section, in
379 octets. This field should be set for any section whose size is
380 changed by linker relaxation. It is required for sections where
381 the linker relaxation scheme doesn't cache altered section and
382 reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing
383 targets), and thus the original size needs to be kept to read the
384 section multiple times. For output sections, rawsize holds the
385 section size calculated on a previous linker relaxation pass. */
386 bfd_size_type rawsize;
388 /* Relaxation table. */
389 struct relax_table *relax;
391 /* Count of used relaxation table entries. */
395 /* If this section is going to be output, then this value is the
396 offset in *bytes* into the output section of the first byte in the
397 input section (byte ==> smallest addressable unit on the
398 target). In most cases, if this was going to start at the
399 100th octet (8-bit quantity) in the output section, this value
400 would be 100. However, if the target byte size is 16 bits
401 (bfd_octets_per_byte is "2"), this value would be 50. */
402 bfd_vma output_offset;
404 /* The output section through which to map on output. */
405 struct bfd_section *output_section;
407 /* The alignment requirement of the section, as an exponent of 2 -
408 e.g., 3 aligns to 2^3 (or 8). */
409 unsigned int alignment_power;
411 /* If an input section, a pointer to a vector of relocation
412 records for the data in this section. */
413 struct reloc_cache_entry *relocation;
415 /* If an output section, a pointer to a vector of pointers to
416 relocation records for the data in this section. */
417 struct reloc_cache_entry **orelocation;
419 /* The number of relocation records in one of the above. */
420 unsigned reloc_count;
422 /* Information below is back end specific - and not always used
425 /* File position of section data. */
428 /* File position of relocation info. */
429 file_ptr rel_filepos;
431 /* File position of line data. */
432 file_ptr line_filepos;
434 /* Pointer to data for applications. */
437 /* If the SEC_IN_MEMORY flag is set, this points to the actual
439 unsigned char *contents;
441 /* Attached line number information. */
444 /* Number of line number records. */
445 unsigned int lineno_count;
447 /* Entity size for merging purposes. */
448 unsigned int entsize;
450 /* Points to the kept section if this section is a link-once section,
452 struct bfd_section *kept_section;
454 /* When a section is being output, this value changes as more
455 linenumbers are written out. */
456 file_ptr moving_line_filepos;
458 /* What the section number is in the target world. */
463 /* If this is a constructor section then here is a list of the
464 relocations created to relocate items within it. */
465 struct relent_chain *constructor_chain;
467 /* The BFD which owns the section. */
470 /* A symbol which points at this section only. */
471 struct bfd_symbol *symbol;
472 struct bfd_symbol **symbol_ptr_ptr;
474 /* Early in the link process, map_head and map_tail are used to build
475 a list of input sections attached to an output section. Later,
476 output sections use these fields for a list of bfd_link_order
479 struct bfd_link_order *link_order;
480 struct bfd_section *s;
481 @} map_head, map_tail;
484 /* Relax table contains information about instructions which can
485 be removed by relaxation -- replacing a long address with a
487 struct relax_table @{
488 /* Address where bytes may be deleted. */
491 /* Number of bytes to be deleted. */
495 /* These sections are global, and are managed by BFD. The application
496 and target back end are not permitted to change the values in
497 these sections. New code should use the section_ptr macros rather
498 than referring directly to the const sections. The const sections
499 may eventually vanish. */
500 #define BFD_ABS_SECTION_NAME "*ABS*"
501 #define BFD_UND_SECTION_NAME "*UND*"
502 #define BFD_COM_SECTION_NAME "*COM*"
503 #define BFD_IND_SECTION_NAME "*IND*"
505 /* The absolute section. */
506 extern asection bfd_abs_section;
507 #define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
508 #define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
509 /* Pointer to the undefined section. */
510 extern asection bfd_und_section;
511 #define bfd_und_section_ptr ((asection *) &bfd_und_section)
512 #define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
513 /* Pointer to the common section. */
514 extern asection bfd_com_section;
515 #define bfd_com_section_ptr ((asection *) &bfd_com_section)
516 /* Pointer to the indirect section. */
517 extern asection bfd_ind_section;
518 #define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
519 #define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
521 #define bfd_is_const_section(SEC) \
522 ( ((SEC) == bfd_abs_section_ptr) \
523 || ((SEC) == bfd_und_section_ptr) \
524 || ((SEC) == bfd_com_section_ptr) \
525 || ((SEC) == bfd_ind_section_ptr))
527 /* Macros to handle insertion and deletion of a bfd's sections. These
528 only handle the list pointers, ie. do not adjust section_count,
530 #define bfd_section_list_remove(ABFD, S) \
534 asection *_next = _s->next; \
535 asection *_prev = _s->prev; \
537 _prev->next = _next; \
539 (ABFD)->sections = _next; \
541 _next->prev = _prev; \
543 (ABFD)->section_last = _prev; \
546 #define bfd_section_list_append(ABFD, S) \
552 if (_abfd->section_last) \
554 _s->prev = _abfd->section_last; \
555 _abfd->section_last->next = _s; \
560 _abfd->sections = _s; \
562 _abfd->section_last = _s; \
565 #define bfd_section_list_prepend(ABFD, S) \
571 if (_abfd->sections) \
573 _s->next = _abfd->sections; \
574 _abfd->sections->prev = _s; \
579 _abfd->section_last = _s; \
581 _abfd->sections = _s; \
584 #define bfd_section_list_insert_after(ABFD, A, S) \
589 asection *_next = _a->next; \
596 (ABFD)->section_last = _s; \
599 #define bfd_section_list_insert_before(ABFD, B, S) \
604 asection *_prev = _b->prev; \
611 (ABFD)->sections = _s; \
614 #define bfd_section_removed_from_list(ABFD, S) \
615 ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
617 #define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX) \
618 /* name, id, index, next, prev, flags, user_set_vma, */ \
619 @{ NAME, IDX, 0, NULL, NULL, FLAGS, 0, \
621 /* linker_mark, linker_has_input, gc_mark, */ \
624 /* segment_mark, sec_info_type, use_rela_p, has_tls_reloc, */ \
627 /* has_tls_get_addr_call, has_gp_reloc, need_finalize_relax, */ \
630 /* reloc_done, vma, lma, size, rawsize, relax, relax_count, */ \
631 0, 0, 0, 0, 0, 0, 0, \
633 /* output_offset, output_section, alignment_power, */ \
634 0, (struct bfd_section *) &SEC, 0, \
636 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \
637 NULL, NULL, 0, 0, 0, \
639 /* line_filepos, userdata, contents, lineno, lineno_count, */ \
640 0, NULL, NULL, NULL, 0, \
642 /* entsize, kept_section, moving_line_filepos, */ \
645 /* target_index, used_by_bfd, constructor_chain, owner, */ \
646 0, NULL, NULL, NULL, \
648 /* symbol, symbol_ptr_ptr, */ \
649 (struct bfd_symbol *) SYM, &SEC.symbol, \
651 /* map_head, map_tail */ \
652 @{ NULL @}, @{ NULL @} \
657 @node section prototypes, , typedef asection, Sections
658 @subsection Section prototypes
659 These are the functions exported by the section handling part of BFD.
661 @findex bfd_section_list_clear
662 @subsubsection @code{bfd_section_list_clear}
665 void bfd_section_list_clear (bfd *);
667 @strong{Description}@*
668 Clears the section list, and also resets the section count and
671 @findex bfd_get_section_by_name
672 @subsubsection @code{bfd_get_section_by_name}
675 asection *bfd_get_section_by_name (bfd *abfd, const char *name);
677 @strong{Description}@*
678 Run through @var{abfd} and return the one of the
679 @code{asection}s whose name matches @var{name}, otherwise @code{NULL}.
680 @xref{Sections}, for more information.
682 This should only be used in special cases; the normal way to process
683 all sections of a given name is to use @code{bfd_map_over_sections} and
684 @code{strcmp} on the name (or better yet, base it on the section flags
685 or something else) for each section.
687 @findex bfd_get_section_by_name_if
688 @subsubsection @code{bfd_get_section_by_name_if}
691 asection *bfd_get_section_by_name_if
694 bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
697 @strong{Description}@*
698 Call the provided function @var{func} for each section
699 attached to the BFD @var{abfd} whose name matches @var{name},
700 passing @var{obj} as an argument. The function will be called
704 func (abfd, the_section, obj);
707 It returns the first section for which @var{func} returns true,
708 otherwise @code{NULL}.
710 @findex bfd_get_unique_section_name
711 @subsubsection @code{bfd_get_unique_section_name}
714 char *bfd_get_unique_section_name
715 (bfd *abfd, const char *templat, int *count);
717 @strong{Description}@*
718 Invent a section name that is unique in @var{abfd} by tacking
719 a dot and a digit suffix onto the original @var{templat}. If
720 @var{count} is non-NULL, then it specifies the first number
721 tried as a suffix to generate a unique name. The value
722 pointed to by @var{count} will be incremented in this case.
724 @findex bfd_make_section_old_way
725 @subsubsection @code{bfd_make_section_old_way}
728 asection *bfd_make_section_old_way (bfd *abfd, const char *name);
730 @strong{Description}@*
731 Create a new empty section called @var{name}
732 and attach it to the end of the chain of sections for the
733 BFD @var{abfd}. An attempt to create a section with a name which
734 is already in use returns its pointer without changing the
737 It has the funny name since this is the way it used to be
738 before it was rewritten....
744 @code{bfd_error_invalid_operation} -
745 If output has already started for this BFD.
747 @code{bfd_error_no_memory} -
748 If memory allocation fails.
751 @findex bfd_make_section_anyway_with_flags
752 @subsubsection @code{bfd_make_section_anyway_with_flags}
755 asection *bfd_make_section_anyway_with_flags
756 (bfd *abfd, const char *name, flagword flags);
758 @strong{Description}@*
759 Create a new empty section called @var{name} and attach it to the end of
760 the chain of sections for @var{abfd}. Create a new section even if there
761 is already a section with that name. Also set the attributes of the
762 new section to the value @var{flags}.
764 Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
768 @code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
770 @code{bfd_error_no_memory} - If memory allocation fails.
773 @findex bfd_make_section_anyway
774 @subsubsection @code{bfd_make_section_anyway}
777 asection *bfd_make_section_anyway (bfd *abfd, const char *name);
779 @strong{Description}@*
780 Create a new empty section called @var{name} and attach it to the end of
781 the chain of sections for @var{abfd}. Create a new section even if there
782 is already a section with that name.
784 Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
788 @code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
790 @code{bfd_error_no_memory} - If memory allocation fails.
793 @findex bfd_make_section_with_flags
794 @subsubsection @code{bfd_make_section_with_flags}
797 asection *bfd_make_section_with_flags
798 (bfd *, const char *name, flagword flags);
800 @strong{Description}@*
801 Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
802 bfd_set_error ()) without changing the section chain if there is already a
803 section named @var{name}. Also set the attributes of the new section to
804 the value @var{flags}. If there is an error, return @code{NULL} and set
807 @findex bfd_make_section
808 @subsubsection @code{bfd_make_section}
811 asection *bfd_make_section (bfd *, const char *name);
813 @strong{Description}@*
814 Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
815 bfd_set_error ()) without changing the section chain if there is already a
816 section named @var{name}. If there is an error, return @code{NULL} and set
819 @findex bfd_set_section_flags
820 @subsubsection @code{bfd_set_section_flags}
823 bfd_boolean bfd_set_section_flags
824 (bfd *abfd, asection *sec, flagword flags);
826 @strong{Description}@*
827 Set the attributes of the section @var{sec} in the BFD
828 @var{abfd} to the value @var{flags}. Return @code{TRUE} on success,
829 @code{FALSE} on error. Possible error returns are:
834 @code{bfd_error_invalid_operation} -
835 The section cannot have one or more of the attributes
836 requested. For example, a .bss section in @code{a.out} may not
837 have the @code{SEC_HAS_CONTENTS} field set.
840 @findex bfd_map_over_sections
841 @subsubsection @code{bfd_map_over_sections}
844 void bfd_map_over_sections
846 void (*func) (bfd *abfd, asection *sect, void *obj),
849 @strong{Description}@*
850 Call the provided function @var{func} for each section
851 attached to the BFD @var{abfd}, passing @var{obj} as an
852 argument. The function will be called as if by
855 func (abfd, the_section, obj);
858 This is the preferred method for iterating over sections; an
859 alternative would be to use a loop:
863 for (p = abfd->sections; p != NULL; p = p->next)
867 @findex bfd_sections_find_if
868 @subsubsection @code{bfd_sections_find_if}
871 asection *bfd_sections_find_if
873 bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
876 @strong{Description}@*
877 Call the provided function @var{operation} for each section
878 attached to the BFD @var{abfd}, passing @var{obj} as an
879 argument. The function will be called as if by
882 operation (abfd, the_section, obj);
885 It returns the first section for which @var{operation} returns true.
887 @findex bfd_set_section_size
888 @subsubsection @code{bfd_set_section_size}
891 bfd_boolean bfd_set_section_size
892 (bfd *abfd, asection *sec, bfd_size_type val);
894 @strong{Description}@*
895 Set @var{sec} to the size @var{val}. If the operation is
896 ok, then @code{TRUE} is returned, else @code{FALSE}.
898 Possible error returns:
902 @code{bfd_error_invalid_operation} -
903 Writing has started to the BFD, so setting the size is invalid.
906 @findex bfd_set_section_contents
907 @subsubsection @code{bfd_set_section_contents}
910 bfd_boolean bfd_set_section_contents
911 (bfd *abfd, asection *section, const void *data,
912 file_ptr offset, bfd_size_type count);
914 @strong{Description}@*
915 Sets the contents of the section @var{section} in BFD
916 @var{abfd} to the data starting in memory at @var{data}. The
917 data is written to the output section starting at offset
918 @var{offset} for @var{count} octets.
920 Normally @code{TRUE} is returned, else @code{FALSE}. Possible error
925 @code{bfd_error_no_contents} -
926 The output section does not have the @code{SEC_HAS_CONTENTS}
927 attribute, so nothing can be written to it.
931 This routine is front end to the back end function
932 @code{_bfd_set_section_contents}.
934 @findex bfd_get_section_contents
935 @subsubsection @code{bfd_get_section_contents}
938 bfd_boolean bfd_get_section_contents
939 (bfd *abfd, asection *section, void *location, file_ptr offset,
940 bfd_size_type count);
942 @strong{Description}@*
943 Read data from @var{section} in BFD @var{abfd}
944 into memory starting at @var{location}. The data is read at an
945 offset of @var{offset} from the start of the input section,
946 and is read for @var{count} bytes.
948 If the contents of a constructor with the @code{SEC_CONSTRUCTOR}
949 flag set are requested or if the section does not have the
950 @code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled
951 with zeroes. If no errors occur, @code{TRUE} is returned, else
954 @findex bfd_malloc_and_get_section
955 @subsubsection @code{bfd_malloc_and_get_section}
958 bfd_boolean bfd_malloc_and_get_section
959 (bfd *abfd, asection *section, bfd_byte **buf);
961 @strong{Description}@*
962 Read all data from @var{section} in BFD @var{abfd}
963 into a buffer, *@var{buf}, malloc'd by this function.
965 @findex bfd_copy_private_section_data
966 @subsubsection @code{bfd_copy_private_section_data}
969 bfd_boolean bfd_copy_private_section_data
970 (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
972 @strong{Description}@*
973 Copy private section information from @var{isec} in the BFD
974 @var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
975 Return @code{TRUE} on success, @code{FALSE} on error. Possible error
981 @code{bfd_error_no_memory} -
982 Not enough memory exists to create private data for @var{osec}.
985 #define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
986 BFD_SEND (obfd, _bfd_copy_private_section_data, \
987 (ibfd, isection, obfd, osection))
990 @findex bfd_generic_is_group_section
991 @subsubsection @code{bfd_generic_is_group_section}
994 bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
996 @strong{Description}@*
997 Returns TRUE if @var{sec} is a member of a group.
999 @findex bfd_generic_discard_group
1000 @subsubsection @code{bfd_generic_discard_group}
1003 bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
1005 @strong{Description}@*
1006 Remove all members of @var{group} from the output.