133965Sjdp/* Object file "section" support for the BFD library.
278828Sobrien   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3218822Sdim   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
433965Sjdp   Free Software Foundation, Inc.
533965Sjdp   Written by Cygnus Support.
633965Sjdp
733965SjdpThis file is part of BFD, the Binary File Descriptor library.
833965Sjdp
933965SjdpThis program is free software; you can redistribute it and/or modify
1033965Sjdpit under the terms of the GNU General Public License as published by
1133965Sjdpthe Free Software Foundation; either version 2 of the License, or
1233965Sjdp(at your option) any later version.
1333965Sjdp
1433965SjdpThis program is distributed in the hope that it will be useful,
1533965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1633965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1733965SjdpGNU General Public License for more details.
1833965Sjdp
1933965SjdpYou should have received a copy of the GNU General Public License
2033965Sjdpalong with this program; if not, write to the Free Software
21218822SdimFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2233965Sjdp
2333965Sjdp/*
2433965SjdpSECTION
2533965Sjdp	Sections
2633965Sjdp
2733965Sjdp	The raw data contained within a BFD is maintained through the
2833965Sjdp	section abstraction.  A single BFD may have any number of
2933965Sjdp	sections.  It keeps hold of them by pointing to the first;
3033965Sjdp	each one points to the next in the list.
3133965Sjdp
3233965Sjdp	Sections are supported in BFD in <<section.c>>.
3333965Sjdp
3433965Sjdp@menu
3533965Sjdp@* Section Input::
3633965Sjdp@* Section Output::
3733965Sjdp@* typedef asection::
3833965Sjdp@* section prototypes::
3933965Sjdp@end menu
4033965Sjdp
4133965SjdpINODE
4233965SjdpSection Input, Section Output, Sections, Sections
4333965SjdpSUBSECTION
4433965Sjdp	Section input
4533965Sjdp
4633965Sjdp	When a BFD is opened for reading, the section structures are
4733965Sjdp	created and attached to the BFD.
4833965Sjdp
4933965Sjdp	Each section has a name which describes the section in the
5033965Sjdp	outside world---for example, <<a.out>> would contain at least
5133965Sjdp	three sections, called <<.text>>, <<.data>> and <<.bss>>.
5233965Sjdp
5333965Sjdp	Names need not be unique; for example a COFF file may have several
5433965Sjdp	sections named <<.data>>.
5533965Sjdp
5633965Sjdp	Sometimes a BFD will contain more than the ``natural'' number of
5733965Sjdp	sections. A back end may attach other sections containing
5833965Sjdp	constructor data, or an application may add a section (using
5933965Sjdp	<<bfd_make_section>>) to the sections attached to an already open
6033965Sjdp	BFD. For example, the linker creates an extra section
6133965Sjdp	<<COMMON>> for each input file's BFD to hold information about
6233965Sjdp	common storage.
6333965Sjdp
6433965Sjdp	The raw data is not necessarily read in when
6533965Sjdp	the section descriptor is created. Some targets may leave the
6633965Sjdp	data in place until a <<bfd_get_section_contents>> call is
6733965Sjdp	made. Other back ends may read in all the data at once.  For
6833965Sjdp	example, an S-record file has to be read once to determine the
6933965Sjdp	size of the data. An IEEE-695 file doesn't contain raw data in
7033965Sjdp	sections, but data and relocation expressions intermixed, so
7133965Sjdp	the data area has to be parsed to get out the data and
7233965Sjdp	relocations.
7333965Sjdp
7433965SjdpINODE
7533965SjdpSection Output, typedef asection, Section Input, Sections
7633965Sjdp
7733965SjdpSUBSECTION
7833965Sjdp	Section output
7933965Sjdp
8033965Sjdp	To write a new object style BFD, the various sections to be
8133965Sjdp	written have to be created. They are attached to the BFD in
8233965Sjdp	the same way as input sections; data is written to the
8333965Sjdp	sections using <<bfd_set_section_contents>>.
8433965Sjdp
8533965Sjdp	Any program that creates or combines sections (e.g., the assembler
8633965Sjdp	and linker) must use the <<asection>> fields <<output_section>> and
8733965Sjdp	<<output_offset>> to indicate the file sections to which each
8833965Sjdp	section must be written.  (If the section is being created from
8933965Sjdp	scratch, <<output_section>> should probably point to the section
9033965Sjdp	itself and <<output_offset>> should probably be zero.)
9133965Sjdp
9233965Sjdp	The data to be written comes from input sections attached
9333965Sjdp	(via <<output_section>> pointers) to
9433965Sjdp	the output sections.  The output section structure can be
9533965Sjdp	considered a filter for the input section: the output section
9633965Sjdp	determines the vma of the output data and the name, but the
9733965Sjdp	input section determines the offset into the output section of
9833965Sjdp	the data to be written.
9933965Sjdp
10033965Sjdp	E.g., to create a section "O", starting at 0x100, 0x123 long,
10133965Sjdp	containing two subsections, "A" at offset 0x0 (i.e., at vma
10233965Sjdp	0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the <<asection>>
10333965Sjdp	structures would look like:
10433965Sjdp
10533965Sjdp|   section name          "A"
10633965Sjdp|     output_offset   0x00
10733965Sjdp|     size            0x20
10833965Sjdp|     output_section ----------->  section name    "O"
10933965Sjdp|                             |    vma             0x100
11033965Sjdp|   section name          "B" |    size            0x123
11133965Sjdp|     output_offset   0x20    |
11233965Sjdp|     size            0x103   |
11333965Sjdp|     output_section  --------|
11433965Sjdp
11533965SjdpSUBSECTION
11633965Sjdp	Link orders
11733965Sjdp
11833965Sjdp	The data within a section is stored in a @dfn{link_order}.
11933965Sjdp	These are much like the fixups in <<gas>>.  The link_order
12033965Sjdp	abstraction allows a section to grow and shrink within itself.
12133965Sjdp
12233965Sjdp	A link_order knows how big it is, and which is the next
12333965Sjdp	link_order and where the raw data for it is; it also points to
12433965Sjdp	a list of relocations which apply to it.
12533965Sjdp
12633965Sjdp	The link_order is used by the linker to perform relaxing on
12733965Sjdp	final code.  The compiler creates code which is as big as
12833965Sjdp	necessary to make it work without relaxing, and the user can
12933965Sjdp	select whether to relax.  Sometimes relaxing takes a lot of
13033965Sjdp	time.  The linker runs around the relocations to see if any
13133965Sjdp	are attached to data which can be shrunk, if so it does it on
13233965Sjdp	a link_order by link_order basis.
13333965Sjdp
13433965Sjdp*/
13533965Sjdp
136218822Sdim#include "sysdep.h"
13733965Sjdp#include "bfd.h"
13833965Sjdp#include "libbfd.h"
13960484Sobrien#include "bfdlink.h"
14033965Sjdp
14133965Sjdp/*
14233965SjdpDOCDD
14333965SjdpINODE
14433965Sjdptypedef asection, section prototypes, Section Output, Sections
14533965SjdpSUBSECTION
14633965Sjdp	typedef asection
14733965Sjdp
14833965Sjdp	Here is the section structure:
14933965Sjdp
15033965SjdpCODE_FRAGMENT
15133965Sjdp.
152130561Sobrien.typedef struct bfd_section
15333965Sjdp.{
15477298Sobrien.  {* The name of the section; the name isn't a copy, the pointer is
15577298Sobrien.     the same as that passed to bfd_make_section.  *}
15677298Sobrien.  const char *name;
15733965Sjdp.
15877298Sobrien.  {* A unique sequence number.  *}
15977298Sobrien.  int id;
16033965Sjdp.
16189857Sobrien.  {* Which section in the bfd; 0..n-1 as sections are created in a bfd.  *}
16277298Sobrien.  int index;
16333965Sjdp.
16477298Sobrien.  {* The next section in the list belonging to the BFD, or NULL.  *}
165130561Sobrien.  struct bfd_section *next;
16633965Sjdp.
167218822Sdim.  {* The previous section in the list belonging to the BFD, or NULL.  *}
168218822Sdim.  struct bfd_section *prev;
169218822Sdim.
17077298Sobrien.  {* The field flags contains attributes of the section. Some
17177298Sobrien.     flags are read in from the object file, and some are
17277298Sobrien.     synthesized from other information.  *}
17377298Sobrien.  flagword flags;
17477298Sobrien.
17533965Sjdp.#define SEC_NO_FLAGS   0x000
17633965Sjdp.
17777298Sobrien.  {* Tells the OS to allocate space for this section when loading.
17877298Sobrien.     This is clear for a section containing debug information only.  *}
17933965Sjdp.#define SEC_ALLOC      0x001
18033965Sjdp.
18177298Sobrien.  {* Tells the OS to load the section from the file when loading.
18277298Sobrien.     This is clear for a .bss section.  *}
18333965Sjdp.#define SEC_LOAD       0x002
18433965Sjdp.
18577298Sobrien.  {* The section contains data still to be relocated, so there is
18677298Sobrien.     some relocation information too.  *}
18733965Sjdp.#define SEC_RELOC      0x004
18833965Sjdp.
18977298Sobrien.  {* A signal to the OS that the section contains read only data.  *}
190218822Sdim.#define SEC_READONLY   0x008
19133965Sjdp.
19277298Sobrien.  {* The section contains code only.  *}
193218822Sdim.#define SEC_CODE       0x010
19433965Sjdp.
19577298Sobrien.  {* The section contains data only.  *}
196218822Sdim.#define SEC_DATA       0x020
19733965Sjdp.
19877298Sobrien.  {* The section will reside in ROM.  *}
199218822Sdim.#define SEC_ROM        0x040
20033965Sjdp.
20177298Sobrien.  {* The section contains constructor information. This section
20277298Sobrien.     type is used by the linker to create lists of constructors and
20377298Sobrien.     destructors used by <<g++>>. When a back end sees a symbol
20477298Sobrien.     which should be used in a constructor list, it creates a new
20577298Sobrien.     section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
20677298Sobrien.     the symbol to it, and builds a relocation. To build the lists
20777298Sobrien.     of constructors, all the linker has to do is catenate all the
20877298Sobrien.     sections called <<__CTOR_LIST__>> and relocate the data
20977298Sobrien.     contained within - exactly the operations it would peform on
21077298Sobrien.     standard data.  *}
211218822Sdim.#define SEC_CONSTRUCTOR 0x080
21233965Sjdp.
21377298Sobrien.  {* The section has contents - a data section could be
21477298Sobrien.     <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
21577298Sobrien.     <<SEC_HAS_CONTENTS>>  *}
216218822Sdim.#define SEC_HAS_CONTENTS 0x100
21733965Sjdp.
21877298Sobrien.  {* An instruction to the linker to not output the section
21977298Sobrien.     even if it has information which would normally be written.  *}
220218822Sdim.#define SEC_NEVER_LOAD 0x200
22133965Sjdp.
222104834Sobrien.  {* The section contains thread local data.  *}
223218822Sdim.#define SEC_THREAD_LOCAL 0x400
224104834Sobrien.
22577298Sobrien.  {* The section has GOT references.  This flag is only for the
22677298Sobrien.     linker, and is currently only used by the elf32-hppa back end.
22777298Sobrien.     It will be set if global offset table references were detected
22877298Sobrien.     in this section, which indicate to the linker that the section
22977298Sobrien.     contains PIC code, and must be handled specially when doing a
23077298Sobrien.     static link.  *}
231218822Sdim.#define SEC_HAS_GOT_REF 0x800
23277298Sobrien.
23377298Sobrien.  {* The section contains common symbols (symbols may be defined
23477298Sobrien.     multiple times, the value of a symbol is the amount of
23577298Sobrien.     space it requires, and the largest symbol value is the one
23677298Sobrien.     used).  Most targets have exactly one of these (which we
23777298Sobrien.     translate to bfd_com_section_ptr), but ECOFF has two.  *}
238218822Sdim.#define SEC_IS_COMMON 0x1000
23933965Sjdp.
24077298Sobrien.  {* The section contains only debugging information.  For
24177298Sobrien.     example, this is set for ELF .debug and .stab sections.
24277298Sobrien.     strip tests this flag to see if a section can be
24377298Sobrien.     discarded.  *}
244218822Sdim.#define SEC_DEBUGGING 0x2000
24533965Sjdp.
24677298Sobrien.  {* The contents of this section are held in memory pointed to
24777298Sobrien.     by the contents field.  This is checked by bfd_get_section_contents,
24877298Sobrien.     and the data is retrieved from memory if appropriate.  *}
249218822Sdim.#define SEC_IN_MEMORY 0x4000
25033965Sjdp.
25177298Sobrien.  {* The contents of this section are to be excluded by the
25277298Sobrien.     linker for executable and shared objects unless those
25377298Sobrien.     objects are to be further relocated.  *}
254218822Sdim.#define SEC_EXCLUDE 0x8000
25533965Sjdp.
25689857Sobrien.  {* The contents of this section are to be sorted based on the sum of
25789857Sobrien.     the symbol and addend values specified by the associated relocation
25889857Sobrien.     entries.  Entries without associated relocation entries will be
25989857Sobrien.     appended to the end of the section in an unspecified order.  *}
260218822Sdim.#define SEC_SORT_ENTRIES 0x10000
26133965Sjdp.
26277298Sobrien.  {* When linking, duplicate sections of the same name should be
26377298Sobrien.     discarded, rather than being combined into a single section as
26477298Sobrien.     is usually done.  This is similar to how common symbols are
26577298Sobrien.     handled.  See SEC_LINK_DUPLICATES below.  *}
266218822Sdim.#define SEC_LINK_ONCE 0x20000
26733965Sjdp.
26877298Sobrien.  {* If SEC_LINK_ONCE is set, this bitfield describes how the linker
26977298Sobrien.     should handle duplicate sections.  *}
270218822Sdim.#define SEC_LINK_DUPLICATES 0x40000
27133965Sjdp.
27277298Sobrien.  {* This value for SEC_LINK_DUPLICATES means that duplicate
27377298Sobrien.     sections with the same name should simply be discarded.  *}
27433965Sjdp.#define SEC_LINK_DUPLICATES_DISCARD 0x0
27533965Sjdp.
27677298Sobrien.  {* This value for SEC_LINK_DUPLICATES means that the linker
27777298Sobrien.     should warn if there are any duplicate sections, although
27877298Sobrien.     it should still only link one copy.  *}
279218822Sdim.#define SEC_LINK_DUPLICATES_ONE_ONLY 0x80000
28033965Sjdp.
28177298Sobrien.  {* This value for SEC_LINK_DUPLICATES means that the linker
28277298Sobrien.     should warn if any duplicate sections are a different size.  *}
283218822Sdim.#define SEC_LINK_DUPLICATES_SAME_SIZE 0x100000
28433965Sjdp.
28577298Sobrien.  {* This value for SEC_LINK_DUPLICATES means that the linker
28677298Sobrien.     should warn if any duplicate sections contain different
28777298Sobrien.     contents.  *}
288218822Sdim.#define SEC_LINK_DUPLICATES_SAME_CONTENTS \
289218822Sdim.  (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
29033965Sjdp.
29177298Sobrien.  {* This section was created by the linker as part of dynamic
29277298Sobrien.     relocation or other arcane processing.  It is skipped when
29377298Sobrien.     going through the first-pass output, trusting that someone
29477298Sobrien.     else up the line will take care of it later.  *}
295218822Sdim.#define SEC_LINKER_CREATED 0x200000
29633965Sjdp.
297218822Sdim.  {* This section should not be subject to garbage collection.
298218822Sdim.     Also set to inform the linker that this section should not be
299218822Sdim.     listed in the link map as discarded.  *}
300218822Sdim.#define SEC_KEEP 0x400000
30160484Sobrien.
30277298Sobrien.  {* This section contains "short" data, and should be placed
30377298Sobrien.     "near" the GP.  *}
304218822Sdim.#define SEC_SMALL_DATA 0x800000
30560484Sobrien.
30689857Sobrien.  {* Attempt to merge identical entities in the section.
30789857Sobrien.     Entity size is given in the entsize field.  *}
308218822Sdim.#define SEC_MERGE 0x1000000
30989857Sobrien.
31089857Sobrien.  {* If given with SEC_MERGE, entities to merge are zero terminated
31189857Sobrien.     strings where entsize specifies character size instead of fixed
31289857Sobrien.     size entries.  *}
313218822Sdim.#define SEC_STRINGS 0x2000000
31489857Sobrien.
31589857Sobrien.  {* This section contains data about section groups.  *}
316218822Sdim.#define SEC_GROUP 0x4000000
31789857Sobrien.
318218822Sdim.  {* The section is a COFF shared library section.  This flag is
319218822Sdim.     only for the linker.  If this type of section appears in
320218822Sdim.     the input file, the linker must copy it to the output file
321218822Sdim.     without changing the vma or size.  FIXME: Although this
322218822Sdim.     was originally intended to be general, it really is COFF
323218822Sdim.     specific (and the flag was renamed to indicate this).  It
324218822Sdim.     might be cleaner to have some more general mechanism to
325218822Sdim.     allow the back end to control what the linker does with
326218822Sdim.     sections.  *}
327218822Sdim.#define SEC_COFF_SHARED_LIBRARY 0x10000000
328218822Sdim.
329218822Sdim.  {* This section contains data which may be shared with other
330218822Sdim.     executables or shared objects. This is for COFF only.  *}
331218822Sdim.#define SEC_COFF_SHARED 0x20000000
332218822Sdim.
333218822Sdim.  {* When a section with this flag is being linked, then if the size of
334218822Sdim.     the input section is less than a page, it should not cross a page
335218822Sdim.     boundary.  If the size of the input section is one page or more,
336218822Sdim.     it should be aligned on a page boundary.  This is for TI
337218822Sdim.     TMS320C54X only.  *}
338218822Sdim.#define SEC_TIC54X_BLOCK 0x40000000
339218822Sdim.
340218822Sdim.  {* Conditionally link this section; do not link if there are no
341218822Sdim.     references found to any symbol in the section.  This is for TI
342218822Sdim.     TMS320C54X only.  *}
343218822Sdim.#define SEC_TIC54X_CLINK 0x80000000
344218822Sdim.
34577298Sobrien.  {*  End of section flags.  *}
34633965Sjdp.
34777298Sobrien.  {* Some internal packed boolean fields.  *}
34833965Sjdp.
34977298Sobrien.  {* See the vma field.  *}
35077298Sobrien.  unsigned int user_set_vma : 1;
35133965Sjdp.
35277298Sobrien.  {* A mark flag used by some of the linker backends.  *}
35377298Sobrien.  unsigned int linker_mark : 1;
35433965Sjdp.
35578828Sobrien.  {* Another mark flag used by some of the linker backends.  Set for
35689857Sobrien.     output sections that have an input section.  *}
35778828Sobrien.  unsigned int linker_has_input : 1;
35878828Sobrien.
359218822Sdim.  {* Mark flags used by some linker backends for garbage collection.  *}
36077298Sobrien.  unsigned int gc_mark : 1;
361218822Sdim.  unsigned int gc_mark_from_eh : 1;
36233965Sjdp.
363130561Sobrien.  {* The following flags are used by the ELF linker. *}
364130561Sobrien.
365130561Sobrien.  {* Mark sections which have been allocated to segments.  *}
36677298Sobrien.  unsigned int segment_mark : 1;
36733965Sjdp.
368130561Sobrien.  {* Type of sec_info information.  *}
369130561Sobrien.  unsigned int sec_info_type:3;
370130561Sobrien.#define ELF_INFO_TYPE_NONE      0
371130561Sobrien.#define ELF_INFO_TYPE_STABS     1
372130561Sobrien.#define ELF_INFO_TYPE_MERGE     2
373130561Sobrien.#define ELF_INFO_TYPE_EH_FRAME  3
374130561Sobrien.#define ELF_INFO_TYPE_JUST_SYMS 4
375130561Sobrien.
376130561Sobrien.  {* Nonzero if this section uses RELA relocations, rather than REL.  *}
377130561Sobrien.  unsigned int use_rela_p:1;
378130561Sobrien.
379218822Sdim.  {* Bits used by various backends.  The generic code doesn't touch
380218822Sdim.     these fields.  *}
381218822Sdim.
382218822Sdim.  {* Nonzero if this section has TLS related relocations.  *}
383130561Sobrien.  unsigned int has_tls_reloc:1;
384130561Sobrien.
385218822Sdim.  {* Nonzero if this section has a gp reloc.  *}
386218822Sdim.  unsigned int has_gp_reloc:1;
387218822Sdim.
388130561Sobrien.  {* Nonzero if this section needs the relax finalize pass.  *}
389130561Sobrien.  unsigned int need_finalize_relax:1;
390130561Sobrien.
391218822Sdim.  {* Whether relocations have been processed.  *}
392218822Sdim.  unsigned int reloc_done : 1;
393130561Sobrien.
39477298Sobrien.  {* End of internal packed boolean fields.  *}
39533965Sjdp.
39677298Sobrien.  {*  The virtual memory address of the section - where it will be
39777298Sobrien.      at run time.  The symbols are relocated against this.  The
39877298Sobrien.      user_set_vma flag is maintained by bfd; if it's not set, the
39977298Sobrien.      backend can assign addresses (for example, in <<a.out>>, where
40077298Sobrien.      the default address for <<.data>> is dependent on the specific
40177298Sobrien.      target and various flags).  *}
40277298Sobrien.  bfd_vma vma;
40333965Sjdp.
40477298Sobrien.  {*  The load address of the section - where it would be in a
40577298Sobrien.      rom image; really only used for writing section header
40691041Sobrien.      information.  *}
40777298Sobrien.  bfd_vma lma;
40833965Sjdp.
40977298Sobrien.  {* The size of the section in octets, as it will be output.
41077298Sobrien.     Contains a value even if the section has no contents (e.g., the
411218822Sdim.     size of <<.bss>>).  *}
412218822Sdim.  bfd_size_type size;
41333965Sjdp.
414218822Sdim.  {* For input sections, the original size on disk of the section, in
415218822Sdim.     octets.  This field is used by the linker relaxation code.  It is
416218822Sdim.     currently only set for sections where the linker relaxation scheme
417218822Sdim.     doesn't cache altered section and reloc contents (stabs, eh_frame,
418218822Sdim.     SEC_MERGE, some coff relaxing targets), and thus the original size
419218822Sdim.     needs to be kept to read the section multiple times.
420218822Sdim.     For output sections, rawsize holds the section size calculated on
421218822Sdim.     a previous linker relaxation pass.  *}
422218822Sdim.  bfd_size_type rawsize;
42333965Sjdp.
42477298Sobrien.  {* If this section is going to be output, then this value is the
42577298Sobrien.     offset in *bytes* into the output section of the first byte in the
42677298Sobrien.     input section (byte ==> smallest addressable unit on the
42777298Sobrien.     target).  In most cases, if this was going to start at the
42877298Sobrien.     100th octet (8-bit quantity) in the output section, this value
42977298Sobrien.     would be 100.  However, if the target byte size is 16 bits
43077298Sobrien.     (bfd_octets_per_byte is "2"), this value would be 50.  *}
43177298Sobrien.  bfd_vma output_offset;
43233965Sjdp.
43377298Sobrien.  {* The output section through which to map on output.  *}
434130561Sobrien.  struct bfd_section *output_section;
43533965Sjdp.
43677298Sobrien.  {* The alignment requirement of the section, as an exponent of 2 -
43777298Sobrien.     e.g., 3 aligns to 2^3 (or 8).  *}
43877298Sobrien.  unsigned int alignment_power;
43933965Sjdp.
44077298Sobrien.  {* If an input section, a pointer to a vector of relocation
44177298Sobrien.     records for the data in this section.  *}
44277298Sobrien.  struct reloc_cache_entry *relocation;
44333965Sjdp.
44477298Sobrien.  {* If an output section, a pointer to a vector of pointers to
44577298Sobrien.     relocation records for the data in this section.  *}
44677298Sobrien.  struct reloc_cache_entry **orelocation;
44733965Sjdp.
44891041Sobrien.  {* The number of relocation records in one of the above.  *}
44977298Sobrien.  unsigned reloc_count;
45033965Sjdp.
45177298Sobrien.  {* Information below is back end specific - and not always used
45277298Sobrien.     or updated.  *}
45333965Sjdp.
45477298Sobrien.  {* File position of section data.  *}
45577298Sobrien.  file_ptr filepos;
45633965Sjdp.
45777298Sobrien.  {* File position of relocation info.  *}
45877298Sobrien.  file_ptr rel_filepos;
45933965Sjdp.
46077298Sobrien.  {* File position of line data.  *}
46177298Sobrien.  file_ptr line_filepos;
46233965Sjdp.
46377298Sobrien.  {* Pointer to data for applications.  *}
464130561Sobrien.  void *userdata;
46533965Sjdp.
46677298Sobrien.  {* If the SEC_IN_MEMORY flag is set, this points to the actual
46777298Sobrien.     contents.  *}
46877298Sobrien.  unsigned char *contents;
46933965Sjdp.
47077298Sobrien.  {* Attached line number information.  *}
47177298Sobrien.  alent *lineno;
47260484Sobrien.
47377298Sobrien.  {* Number of line number records.  *}
47477298Sobrien.  unsigned int lineno_count;
47533965Sjdp.
47689857Sobrien.  {* Entity size for merging purposes.  *}
47789857Sobrien.  unsigned int entsize;
47889857Sobrien.
479130561Sobrien.  {* Points to the kept section if this section is a link-once section,
480130561Sobrien.     and is discarded.  *}
481130561Sobrien.  struct bfd_section *kept_section;
482130561Sobrien.
48377298Sobrien.  {* When a section is being output, this value changes as more
48477298Sobrien.     linenumbers are written out.  *}
48577298Sobrien.  file_ptr moving_line_filepos;
48633965Sjdp.
48777298Sobrien.  {* What the section number is in the target world.  *}
48877298Sobrien.  int target_index;
48933965Sjdp.
490130561Sobrien.  void *used_by_bfd;
49133965Sjdp.
49277298Sobrien.  {* If this is a constructor section then here is a list of the
49377298Sobrien.     relocations created to relocate items within it.  *}
49477298Sobrien.  struct relent_chain *constructor_chain;
49577298Sobrien.
49677298Sobrien.  {* The BFD which owns the section.  *}
49777298Sobrien.  bfd *owner;
49877298Sobrien.
49991041Sobrien.  {* A symbol which points at this section only.  *}
500130561Sobrien.  struct bfd_symbol *symbol;
501130561Sobrien.  struct bfd_symbol **symbol_ptr_ptr;
50277298Sobrien.
503218822Sdim.  {* Early in the link process, map_head and map_tail are used to build
504218822Sdim.     a list of input sections attached to an output section.  Later,
505218822Sdim.     output sections use these fields for a list of bfd_link_order
506218822Sdim.     structs.  *}
507218822Sdim.  union {
508218822Sdim.    struct bfd_link_order *link_order;
509218822Sdim.    struct bfd_section *s;
510218822Sdim.  } map_head, map_tail;
51191041Sobrien.} asection;
51233965Sjdp.
51377298Sobrien.{* These sections are global, and are managed by BFD.  The application
51477298Sobrien.   and target back end are not permitted to change the values in
51577298Sobrien.   these sections.  New code should use the section_ptr macros rather
51677298Sobrien.   than referring directly to the const sections.  The const sections
51777298Sobrien.   may eventually vanish.  *}
51833965Sjdp.#define BFD_ABS_SECTION_NAME "*ABS*"
51933965Sjdp.#define BFD_UND_SECTION_NAME "*UND*"
52033965Sjdp.#define BFD_COM_SECTION_NAME "*COM*"
52133965Sjdp.#define BFD_IND_SECTION_NAME "*IND*"
52233965Sjdp.
52391041Sobrien.{* The absolute section.  *}
524130561Sobrien.extern asection bfd_abs_section;
52533965Sjdp.#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
52633965Sjdp.#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
52791041Sobrien.{* Pointer to the undefined section.  *}
528130561Sobrien.extern asection bfd_und_section;
52933965Sjdp.#define bfd_und_section_ptr ((asection *) &bfd_und_section)
53033965Sjdp.#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
53191041Sobrien.{* Pointer to the common section.  *}
532130561Sobrien.extern asection bfd_com_section;
53333965Sjdp.#define bfd_com_section_ptr ((asection *) &bfd_com_section)
53491041Sobrien.{* Pointer to the indirect section.  *}
535130561Sobrien.extern asection bfd_ind_section;
53633965Sjdp.#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
53733965Sjdp.#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
53833965Sjdp.
53989857Sobrien.#define bfd_is_const_section(SEC)		\
54089857Sobrien. (   ((SEC) == bfd_abs_section_ptr)		\
54189857Sobrien.  || ((SEC) == bfd_und_section_ptr)		\
54289857Sobrien.  || ((SEC) == bfd_com_section_ptr)		\
54389857Sobrien.  || ((SEC) == bfd_ind_section_ptr))
54489857Sobrien.
54589857Sobrien.{* Macros to handle insertion and deletion of a bfd's sections.  These
54689857Sobrien.   only handle the list pointers, ie. do not adjust section_count,
54789857Sobrien.   target_index etc.  *}
548218822Sdim.#define bfd_section_list_remove(ABFD, S) \
54989857Sobrien.  do							\
55089857Sobrien.    {							\
551218822Sdim.      asection *_s = S;				\
552218822Sdim.      asection *_next = _s->next;			\
553218822Sdim.      asection *_prev = _s->prev;			\
554218822Sdim.      if (_prev)					\
555218822Sdim.        _prev->next = _next;				\
556218822Sdim.      else						\
557218822Sdim.        (ABFD)->sections = _next;			\
558218822Sdim.      if (_next)					\
559218822Sdim.        _next->prev = _prev;				\
560218822Sdim.      else						\
561218822Sdim.        (ABFD)->section_last = _prev;			\
56289857Sobrien.    }							\
56389857Sobrien.  while (0)
564218822Sdim.#define bfd_section_list_append(ABFD, S) \
56589857Sobrien.  do							\
56689857Sobrien.    {							\
56789857Sobrien.      asection *_s = S;				\
568218822Sdim.      bfd *_abfd = ABFD;				\
569218822Sdim.      _s->next = NULL;					\
570218822Sdim.      if (_abfd->section_last)				\
571218822Sdim.        {						\
572218822Sdim.          _s->prev = _abfd->section_last;		\
573218822Sdim.          _abfd->section_last->next = _s;		\
574218822Sdim.        }						\
575218822Sdim.      else						\
576218822Sdim.        {						\
577218822Sdim.          _s->prev = NULL;				\
578218822Sdim.          _abfd->sections = _s;			\
579218822Sdim.        }						\
580218822Sdim.      _abfd->section_last = _s;			\
58189857Sobrien.    }							\
58289857Sobrien.  while (0)
583218822Sdim.#define bfd_section_list_prepend(ABFD, S) \
584218822Sdim.  do							\
585218822Sdim.    {							\
586218822Sdim.      asection *_s = S;				\
587218822Sdim.      bfd *_abfd = ABFD;				\
588218822Sdim.      _s->prev = NULL;					\
589218822Sdim.      if (_abfd->sections)				\
590218822Sdim.        {						\
591218822Sdim.          _s->next = _abfd->sections;			\
592218822Sdim.          _abfd->sections->prev = _s;			\
593218822Sdim.        }						\
594218822Sdim.      else						\
595218822Sdim.        {						\
596218822Sdim.          _s->next = NULL;				\
597218822Sdim.          _abfd->section_last = _s;			\
598218822Sdim.        }						\
599218822Sdim.      _abfd->sections = _s;				\
600218822Sdim.    }							\
601218822Sdim.  while (0)
602218822Sdim.#define bfd_section_list_insert_after(ABFD, A, S) \
603218822Sdim.  do							\
604218822Sdim.    {							\
605218822Sdim.      asection *_a = A;				\
606218822Sdim.      asection *_s = S;				\
607218822Sdim.      asection *_next = _a->next;			\
608218822Sdim.      _s->next = _next;				\
609218822Sdim.      _s->prev = _a;					\
610218822Sdim.      _a->next = _s;					\
611218822Sdim.      if (_next)					\
612218822Sdim.        _next->prev = _s;				\
613218822Sdim.      else						\
614218822Sdim.        (ABFD)->section_last = _s;			\
615218822Sdim.    }							\
616218822Sdim.  while (0)
617218822Sdim.#define bfd_section_list_insert_before(ABFD, B, S) \
618218822Sdim.  do							\
619218822Sdim.    {							\
620218822Sdim.      asection *_b = B;				\
621218822Sdim.      asection *_s = S;				\
622218822Sdim.      asection *_prev = _b->prev;			\
623218822Sdim.      _s->prev = _prev;				\
624218822Sdim.      _s->next = _b;					\
625218822Sdim.      _b->prev = _s;					\
626218822Sdim.      if (_prev)					\
627218822Sdim.        _prev->next = _s;				\
628218822Sdim.      else						\
629218822Sdim.        (ABFD)->sections = _s;				\
630218822Sdim.    }							\
631218822Sdim.  while (0)
632218822Sdim.#define bfd_section_removed_from_list(ABFD, S) \
633218822Sdim.  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
63489857Sobrien.
635218822Sdim.#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX)			\
636218822Sdim.  {* name, id,  index, next, prev, flags, user_set_vma,            *}	\
637218822Sdim.  { NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,				\
638218822Sdim.									\
639218822Sdim.  {* linker_mark, linker_has_input, gc_mark, gc_mark_from_eh,      *}	\
640218822Sdim.     0,           0,                1,       0,			\
641218822Sdim.									\
642218822Sdim.  {* segment_mark, sec_info_type, use_rela_p, has_tls_reloc,       *}	\
643218822Sdim.     0,            0,             0,          0,			\
644218822Sdim.									\
645218822Sdim.  {* has_gp_reloc, need_finalize_relax, reloc_done,                *}	\
646218822Sdim.     0,            0,                   0,				\
647218822Sdim.									\
648218822Sdim.  {* vma, lma, size, rawsize                                       *}	\
649218822Sdim.     0,   0,   0,    0,						\
650218822Sdim.									\
651218822Sdim.  {* output_offset, output_section,              alignment_power,  *}	\
652218822Sdim.     0,             (struct bfd_section *) &SEC, 0,			\
653218822Sdim.									\
654218822Sdim.  {* relocation, orelocation, reloc_count, filepos, rel_filepos,   *}	\
655218822Sdim.     NULL,       NULL,        0,           0,       0,			\
656218822Sdim.									\
657218822Sdim.  {* line_filepos, userdata, contents, lineno, lineno_count,       *}	\
658218822Sdim.     0,            NULL,     NULL,     NULL,   0,			\
659218822Sdim.									\
660218822Sdim.  {* entsize, kept_section, moving_line_filepos,		     *}	\
661218822Sdim.     0,       NULL,	      0,					\
662218822Sdim.									\
663218822Sdim.  {* target_index, used_by_bfd, constructor_chain, owner,          *}	\
664218822Sdim.     0,            NULL,        NULL,              NULL,		\
665218822Sdim.									\
666218822Sdim.  {* symbol,                    symbol_ptr_ptr,                    *}	\
667218822Sdim.     (struct bfd_symbol *) SYM, &SEC.symbol,				\
668218822Sdim.									\
669218822Sdim.  {* map_head, map_tail                                            *}	\
670218822Sdim.     { NULL }, { NULL }						\
671218822Sdim.    }
672218822Sdim.
67333965Sjdp*/
67433965Sjdp
67560484Sobrien/* We use a macro to initialize the static asymbol structures because
67660484Sobrien   traditional C does not permit us to initialize a union member while
67760484Sobrien   gcc warns if we don't initialize it.  */
67860484Sobrien /* the_bfd, name, value, attr, section [, udata] */
67960484Sobrien#ifdef __STDC__
68060484Sobrien#define GLOBAL_SYM_INIT(NAME, SECTION) \
68160484Sobrien  { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION, { 0 }}
68260484Sobrien#else
68360484Sobrien#define GLOBAL_SYM_INIT(NAME, SECTION) \
68460484Sobrien  { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION }
68560484Sobrien#endif
68660484Sobrien
68733965Sjdp/* These symbols are global, not specific to any BFD.  Therefore, anything
68833965Sjdp   that tries to change them is broken, and should be repaired.  */
68960484Sobrien
69033965Sjdpstatic const asymbol global_syms[] =
69133965Sjdp{
69260484Sobrien  GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, &bfd_com_section),
69360484Sobrien  GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, &bfd_und_section),
69460484Sobrien  GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, &bfd_abs_section),
69560484Sobrien  GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, &bfd_ind_section)
69633965Sjdp};
69733965Sjdp
698218822Sdim#define STD_SECTION(SEC, FLAGS, NAME, IDX)				\
699218822Sdim  asection SEC = BFD_FAKE_SECTION(SEC, FLAGS, &global_syms[IDX],	\
700218822Sdim				  NAME, IDX)
70133965Sjdp
702218822SdimSTD_SECTION (bfd_com_section, SEC_IS_COMMON, BFD_COM_SECTION_NAME, 0);
703218822SdimSTD_SECTION (bfd_und_section, 0, BFD_UND_SECTION_NAME, 1);
704218822SdimSTD_SECTION (bfd_abs_section, 0, BFD_ABS_SECTION_NAME, 2);
705218822SdimSTD_SECTION (bfd_ind_section, 0, BFD_IND_SECTION_NAME, 3);
70633965Sjdp#undef STD_SECTION
70733965Sjdp
70889857Sobrien/* Initialize an entry in the section hash table.  */
70989857Sobrien
71089857Sobrienstruct bfd_hash_entry *
711130561Sobrienbfd_section_hash_newfunc (struct bfd_hash_entry *entry,
712130561Sobrien			  struct bfd_hash_table *table,
713130561Sobrien			  const char *string)
71489857Sobrien{
71589857Sobrien  /* Allocate the structure if it has not already been allocated by a
71689857Sobrien     subclass.  */
71789857Sobrien  if (entry == NULL)
71889857Sobrien    {
719107492Sobrien      entry = (struct bfd_hash_entry *)
720107492Sobrien	bfd_hash_allocate (table, sizeof (struct section_hash_entry));
72189857Sobrien      if (entry == NULL)
72289857Sobrien	return entry;
72389857Sobrien    }
72489857Sobrien
72589857Sobrien  /* Call the allocation method of the superclass.  */
72689857Sobrien  entry = bfd_hash_newfunc (entry, table, string);
72789857Sobrien  if (entry != NULL)
728130561Sobrien    memset (&((struct section_hash_entry *) entry)->section, 0,
729130561Sobrien	    sizeof (asection));
73089857Sobrien
73189857Sobrien  return entry;
73289857Sobrien}
73389857Sobrien
73489857Sobrien#define section_hash_lookup(table, string, create, copy) \
73589857Sobrien  ((struct section_hash_entry *) \
73689857Sobrien   bfd_hash_lookup ((table), (string), (create), (copy)))
73789857Sobrien
738218822Sdim/* Create a symbol whose only job is to point to this section.  This
739218822Sdim   is useful for things like relocs which are relative to the base
740218822Sdim   of a section.  */
74189857Sobrien
742218822Sdimbfd_boolean
743218822Sdim_bfd_generic_new_section_hook (bfd *abfd, asection *newsect)
74489857Sobrien{
74589857Sobrien  newsect->symbol = bfd_make_empty_symbol (abfd);
74689857Sobrien  if (newsect->symbol == NULL)
747218822Sdim    return FALSE;
74889857Sobrien
74989857Sobrien  newsect->symbol->name = newsect->name;
75089857Sobrien  newsect->symbol->value = 0;
75189857Sobrien  newsect->symbol->section = newsect;
75289857Sobrien  newsect->symbol->flags = BSF_SECTION_SYM;
75389857Sobrien
75489857Sobrien  newsect->symbol_ptr_ptr = &newsect->symbol;
755218822Sdim  return TRUE;
756218822Sdim}
75789857Sobrien
758218822Sdim/* Initializes a new section.  NEWSECT->NAME is already set.  */
759218822Sdim
760218822Sdimstatic asection *
761218822Sdimbfd_section_init (bfd *abfd, asection *newsect)
762218822Sdim{
763218822Sdim  static int section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */
764218822Sdim
765218822Sdim  newsect->id = section_id;
766218822Sdim  newsect->index = abfd->section_count;
767218822Sdim  newsect->owner = abfd;
768218822Sdim
76989857Sobrien  if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
77089857Sobrien    return NULL;
77189857Sobrien
77289857Sobrien  section_id++;
77389857Sobrien  abfd->section_count++;
774218822Sdim  bfd_section_list_append (abfd, newsect);
77589857Sobrien  return newsect;
77689857Sobrien}
77789857Sobrien
77833965Sjdp/*
77933965SjdpDOCDD
78033965SjdpINODE
78133965Sjdpsection prototypes,  , typedef asection, Sections
78233965SjdpSUBSECTION
78333965Sjdp	Section prototypes
78433965Sjdp
78533965SjdpThese are the functions exported by the section handling part of BFD.
78633965Sjdp*/
78733965Sjdp
78833965Sjdp/*
78933965SjdpFUNCTION
79089857Sobrien	bfd_section_list_clear
79189857Sobrien
79289857SobrienSYNOPSIS
79389857Sobrien	void bfd_section_list_clear (bfd *);
79489857Sobrien
79589857SobrienDESCRIPTION
79689857Sobrien	Clears the section list, and also resets the section count and
79789857Sobrien	hash table entries.
79889857Sobrien*/
79989857Sobrien
80089857Sobrienvoid
801130561Sobrienbfd_section_list_clear (bfd *abfd)
80289857Sobrien{
80389857Sobrien  abfd->sections = NULL;
804218822Sdim  abfd->section_last = NULL;
80589857Sobrien  abfd->section_count = 0;
806130561Sobrien  memset (abfd->section_htab.table, 0,
80789857Sobrien	  abfd->section_htab.size * sizeof (struct bfd_hash_entry *));
80889857Sobrien}
80989857Sobrien
81089857Sobrien/*
81189857SobrienFUNCTION
81233965Sjdp	bfd_get_section_by_name
81333965Sjdp
81433965SjdpSYNOPSIS
815130561Sobrien	asection *bfd_get_section_by_name (bfd *abfd, const char *name);
81633965Sjdp
81733965SjdpDESCRIPTION
81833965Sjdp	Run through @var{abfd} and return the one of the
81933965Sjdp	<<asection>>s whose name matches @var{name}, otherwise <<NULL>>.
82033965Sjdp	@xref{Sections}, for more information.
82133965Sjdp
82233965Sjdp	This should only be used in special cases; the normal way to process
82333965Sjdp	all sections of a given name is to use <<bfd_map_over_sections>> and
82433965Sjdp	<<strcmp>> on the name (or better yet, base it on the section flags
82533965Sjdp	or something else) for each section.
82633965Sjdp*/
82733965Sjdp
82833965Sjdpasection *
829130561Sobrienbfd_get_section_by_name (bfd *abfd, const char *name)
83033965Sjdp{
83189857Sobrien  struct section_hash_entry *sh;
83233965Sjdp
833130561Sobrien  sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
83489857Sobrien  if (sh != NULL)
83589857Sobrien    return &sh->section;
83689857Sobrien
83733965Sjdp  return NULL;
83833965Sjdp}
83933965Sjdp
84077298Sobrien/*
84177298SobrienFUNCTION
842218822Sdim	bfd_get_section_by_name_if
843218822Sdim
844218822SdimSYNOPSIS
845218822Sdim	asection *bfd_get_section_by_name_if
846218822Sdim	  (bfd *abfd,
847218822Sdim	   const char *name,
848218822Sdim	   bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
849218822Sdim	   void *obj);
850218822Sdim
851218822SdimDESCRIPTION
852218822Sdim	Call the provided function @var{func} for each section
853218822Sdim	attached to the BFD @var{abfd} whose name matches @var{name},
854218822Sdim	passing @var{obj} as an argument. The function will be called
855218822Sdim	as if by
856218822Sdim
857218822Sdim|	func (abfd, the_section, obj);
858218822Sdim
859218822Sdim	It returns the first section for which @var{func} returns true,
860218822Sdim	otherwise <<NULL>>.
861218822Sdim
862218822Sdim*/
863218822Sdim
864218822Sdimasection *
865218822Sdimbfd_get_section_by_name_if (bfd *abfd, const char *name,
866218822Sdim			    bfd_boolean (*operation) (bfd *,
867218822Sdim						      asection *,
868218822Sdim						      void *),
869218822Sdim			    void *user_storage)
870218822Sdim{
871218822Sdim  struct section_hash_entry *sh;
872218822Sdim  unsigned long hash;
873218822Sdim
874218822Sdim  sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
875218822Sdim  if (sh == NULL)
876218822Sdim    return NULL;
877218822Sdim
878218822Sdim  hash = sh->root.hash;
879218822Sdim  do
880218822Sdim    {
881218822Sdim      if ((*operation) (abfd, &sh->section, user_storage))
882218822Sdim	return &sh->section;
883218822Sdim      sh = (struct section_hash_entry *) sh->root.next;
884218822Sdim    }
885218822Sdim  while (sh != NULL && sh->root.hash == hash
886218822Sdim	 && strcmp (sh->root.string, name) == 0);
887218822Sdim
888218822Sdim  return NULL;
889218822Sdim}
890218822Sdim
891218822Sdim/*
892218822SdimFUNCTION
89377298Sobrien	bfd_get_unique_section_name
89433965Sjdp
89577298SobrienSYNOPSIS
896130561Sobrien	char *bfd_get_unique_section_name
897130561Sobrien	  (bfd *abfd, const char *templat, int *count);
89877298Sobrien
89977298SobrienDESCRIPTION
90077298Sobrien	Invent a section name that is unique in @var{abfd} by tacking
90177298Sobrien	a dot and a digit suffix onto the original @var{templat}.  If
90277298Sobrien	@var{count} is non-NULL, then it specifies the first number
90377298Sobrien	tried as a suffix to generate a unique name.  The value
90477298Sobrien	pointed to by @var{count} will be incremented in this case.
90577298Sobrien*/
90677298Sobrien
90777298Sobrienchar *
908130561Sobrienbfd_get_unique_section_name (bfd *abfd, const char *templat, int *count)
90977298Sobrien{
91077298Sobrien  int num;
91177298Sobrien  unsigned int len;
91277298Sobrien  char *sname;
91377298Sobrien
91477298Sobrien  len = strlen (templat);
915130561Sobrien  sname = bfd_malloc (len + 8);
91677298Sobrien  if (sname == NULL)
91777298Sobrien    return NULL;
918104834Sobrien  memcpy (sname, templat, len);
91977298Sobrien  num = 1;
92077298Sobrien  if (count != NULL)
92177298Sobrien    num = *count;
92277298Sobrien
92377298Sobrien  do
92477298Sobrien    {
92577298Sobrien      /* If we have a million sections, something is badly wrong.  */
92677298Sobrien      if (num > 999999)
92777298Sobrien	abort ();
92877298Sobrien      sprintf (sname + len, ".%d", num++);
92977298Sobrien    }
930130561Sobrien  while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE));
93177298Sobrien
93277298Sobrien  if (count != NULL)
93377298Sobrien    *count = num;
93477298Sobrien  return sname;
93577298Sobrien}
93677298Sobrien
93733965Sjdp/*
93833965SjdpFUNCTION
93933965Sjdp	bfd_make_section_old_way
94033965Sjdp
94133965SjdpSYNOPSIS
942130561Sobrien	asection *bfd_make_section_old_way (bfd *abfd, const char *name);
94333965Sjdp
94433965SjdpDESCRIPTION
94533965Sjdp	Create a new empty section called @var{name}
94633965Sjdp	and attach it to the end of the chain of sections for the
94733965Sjdp	BFD @var{abfd}. An attempt to create a section with a name which
94833965Sjdp	is already in use returns its pointer without changing the
94933965Sjdp	section chain.
95033965Sjdp
95133965Sjdp	It has the funny name since this is the way it used to be
95233965Sjdp	before it was rewritten....
95333965Sjdp
95433965Sjdp	Possible errors are:
95533965Sjdp	o <<bfd_error_invalid_operation>> -
95633965Sjdp	If output has already started for this BFD.
95733965Sjdp	o <<bfd_error_no_memory>> -
95833965Sjdp	If memory allocation fails.
95933965Sjdp
96033965Sjdp*/
96133965Sjdp
96233965Sjdpasection *
963130561Sobrienbfd_make_section_old_way (bfd *abfd, const char *name)
96433965Sjdp{
96589857Sobrien  asection *newsect;
96689857Sobrien
96789857Sobrien  if (abfd->output_has_begun)
96833965Sjdp    {
96989857Sobrien      bfd_set_error (bfd_error_invalid_operation);
97089857Sobrien      return NULL;
97133965Sjdp    }
97289857Sobrien
97389857Sobrien  if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
974218822Sdim    newsect = bfd_abs_section_ptr;
975218822Sdim  else if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
976218822Sdim    newsect = bfd_com_section_ptr;
977218822Sdim  else if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
978218822Sdim    newsect = bfd_und_section_ptr;
979218822Sdim  else if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
980218822Sdim    newsect = bfd_ind_section_ptr;
981218822Sdim  else
982218822Sdim    {
983218822Sdim      struct section_hash_entry *sh;
98489857Sobrien
985218822Sdim      sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
986218822Sdim      if (sh == NULL)
987218822Sdim	return NULL;
98889857Sobrien
989218822Sdim      newsect = &sh->section;
990218822Sdim      if (newsect->name != NULL)
991218822Sdim	{
992218822Sdim	  /* Section already exists.  */
993218822Sdim	  return newsect;
994218822Sdim	}
99589857Sobrien
996218822Sdim      newsect->name = name;
997218822Sdim      return bfd_section_init (abfd, newsect);
998218822Sdim    }
99989857Sobrien
1000218822Sdim  /* Call new_section_hook when "creating" the standard abs, com, und
1001218822Sdim     and ind sections to tack on format specific section data.
1002218822Sdim     Also, create a proper section symbol.  */
1003218822Sdim  if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
100489857Sobrien    return NULL;
1005218822Sdim  return newsect;
100633965Sjdp}
100733965Sjdp
100833965Sjdp/*
100933965SjdpFUNCTION
1010218822Sdim	bfd_make_section_anyway_with_flags
101133965Sjdp
101233965SjdpSYNOPSIS
1013218822Sdim	asection *bfd_make_section_anyway_with_flags
1014218822Sdim	  (bfd *abfd, const char *name, flagword flags);
101533965Sjdp
101633965SjdpDESCRIPTION
101733965Sjdp   Create a new empty section called @var{name} and attach it to the end of
101833965Sjdp   the chain of sections for @var{abfd}.  Create a new section even if there
1019218822Sdim   is already a section with that name.  Also set the attributes of the
1020218822Sdim   new section to the value @var{flags}.
102133965Sjdp
102233965Sjdp   Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
102333965Sjdp   o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
102433965Sjdp   o <<bfd_error_no_memory>> - If memory allocation fails.
102533965Sjdp*/
102633965Sjdp
102733965Sjdpsec_ptr
1028218822Sdimbfd_make_section_anyway_with_flags (bfd *abfd, const char *name,
1029218822Sdim				    flagword flags)
103033965Sjdp{
103189857Sobrien  struct section_hash_entry *sh;
103233965Sjdp  asection *newsect;
103333965Sjdp
103433965Sjdp  if (abfd->output_has_begun)
103533965Sjdp    {
103633965Sjdp      bfd_set_error (bfd_error_invalid_operation);
103733965Sjdp      return NULL;
103833965Sjdp    }
103933965Sjdp
1040130561Sobrien  sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
104189857Sobrien  if (sh == NULL)
104233965Sjdp    return NULL;
104333965Sjdp
104489857Sobrien  newsect = &sh->section;
104589857Sobrien  if (newsect->name != NULL)
104677298Sobrien    {
1047218822Sdim      /* We are making a section of the same name.  Put it in the
1048218822Sdim	 section hash table.  Even though we can't find it directly by a
1049218822Sdim	 hash lookup, we'll be able to find the section by traversing
1050218822Sdim	 sh->root.next quicker than looking at all the bfd sections.  */
1051218822Sdim      struct section_hash_entry *new_sh;
1052218822Sdim      new_sh = (struct section_hash_entry *)
1053218822Sdim	bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
1054218822Sdim      if (new_sh == NULL)
105589857Sobrien	return NULL;
1056218822Sdim
1057218822Sdim      new_sh->root = sh->root;
1058218822Sdim      sh->root.next = &new_sh->root;
1059218822Sdim      newsect = &new_sh->section;
106077298Sobrien    }
106133965Sjdp
1062218822Sdim  newsect->flags = flags;
106389857Sobrien  newsect->name = name;
106489857Sobrien  return bfd_section_init (abfd, newsect);
106533965Sjdp}
106633965Sjdp
106733965Sjdp/*
106833965SjdpFUNCTION
1069218822Sdim	bfd_make_section_anyway
107033965Sjdp
107133965SjdpSYNOPSIS
1072218822Sdim	asection *bfd_make_section_anyway (bfd *abfd, const char *name);
107333965Sjdp
107433965SjdpDESCRIPTION
1075218822Sdim   Create a new empty section called @var{name} and attach it to the end of
1076218822Sdim   the chain of sections for @var{abfd}.  Create a new section even if there
1077218822Sdim   is already a section with that name.
1078218822Sdim
1079218822Sdim   Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
1080218822Sdim   o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
1081218822Sdim   o <<bfd_error_no_memory>> - If memory allocation fails.
1082218822Sdim*/
1083218822Sdim
1084218822Sdimsec_ptr
1085218822Sdimbfd_make_section_anyway (bfd *abfd, const char *name)
1086218822Sdim{
1087218822Sdim  return bfd_make_section_anyway_with_flags (abfd, name, 0);
1088218822Sdim}
1089218822Sdim
1090218822Sdim/*
1091218822SdimFUNCTION
1092218822Sdim	bfd_make_section_with_flags
1093218822Sdim
1094218822SdimSYNOPSIS
1095218822Sdim	asection *bfd_make_section_with_flags
1096218822Sdim	  (bfd *, const char *name, flagword flags);
1097218822Sdim
1098218822SdimDESCRIPTION
109933965Sjdp   Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
110033965Sjdp   bfd_set_error ()) without changing the section chain if there is already a
1101218822Sdim   section named @var{name}.  Also set the attributes of the new section to
1102218822Sdim   the value @var{flags}.  If there is an error, return <<NULL>> and set
110333965Sjdp   <<bfd_error>>.
110433965Sjdp*/
110533965Sjdp
110633965Sjdpasection *
1107218822Sdimbfd_make_section_with_flags (bfd *abfd, const char *name,
1108218822Sdim			     flagword flags)
110933965Sjdp{
111089857Sobrien  struct section_hash_entry *sh;
111189857Sobrien  asection *newsect;
111233965Sjdp
111389857Sobrien  if (abfd->output_has_begun)
111433965Sjdp    {
111589857Sobrien      bfd_set_error (bfd_error_invalid_operation);
111689857Sobrien      return NULL;
111733965Sjdp    }
111833965Sjdp
111989857Sobrien  if (strcmp (name, BFD_ABS_SECTION_NAME) == 0
112089857Sobrien      || strcmp (name, BFD_COM_SECTION_NAME) == 0
112189857Sobrien      || strcmp (name, BFD_UND_SECTION_NAME) == 0
112289857Sobrien      || strcmp (name, BFD_IND_SECTION_NAME) == 0)
112389857Sobrien    return NULL;
112433965Sjdp
1125130561Sobrien  sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
112689857Sobrien  if (sh == NULL)
112789857Sobrien    return NULL;
112889857Sobrien
112989857Sobrien  newsect = &sh->section;
113089857Sobrien  if (newsect->name != NULL)
113133965Sjdp    {
113289857Sobrien      /* Section already exists.  */
1133130561Sobrien      return NULL;
113433965Sjdp    }
113533965Sjdp
113689857Sobrien  newsect->name = name;
1137218822Sdim  newsect->flags = flags;
113889857Sobrien  return bfd_section_init (abfd, newsect);
113933965Sjdp}
114033965Sjdp
114133965Sjdp/*
114233965SjdpFUNCTION
1143218822Sdim	bfd_make_section
1144218822Sdim
1145218822SdimSYNOPSIS
1146218822Sdim	asection *bfd_make_section (bfd *, const char *name);
1147218822Sdim
1148218822SdimDESCRIPTION
1149218822Sdim   Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
1150218822Sdim   bfd_set_error ()) without changing the section chain if there is already a
1151218822Sdim   section named @var{name}.  If there is an error, return <<NULL>> and set
1152218822Sdim   <<bfd_error>>.
1153218822Sdim*/
1154218822Sdim
1155218822Sdimasection *
1156218822Sdimbfd_make_section (bfd *abfd, const char *name)
1157218822Sdim{
1158218822Sdim  return bfd_make_section_with_flags (abfd, name, 0);
1159218822Sdim}
1160218822Sdim
1161218822Sdim/*
1162218822SdimFUNCTION
116333965Sjdp	bfd_set_section_flags
116433965Sjdp
116533965SjdpSYNOPSIS
1166130561Sobrien	bfd_boolean bfd_set_section_flags
1167130561Sobrien	  (bfd *abfd, asection *sec, flagword flags);
116833965Sjdp
116933965SjdpDESCRIPTION
117033965Sjdp	Set the attributes of the section @var{sec} in the BFD
1171130561Sobrien	@var{abfd} to the value @var{flags}. Return <<TRUE>> on success,
1172130561Sobrien	<<FALSE>> on error. Possible error returns are:
117333965Sjdp
117433965Sjdp	o <<bfd_error_invalid_operation>> -
117533965Sjdp	The section cannot have one or more of the attributes
117633965Sjdp	requested. For example, a .bss section in <<a.out>> may not
117733965Sjdp	have the <<SEC_HAS_CONTENTS>> field set.
117833965Sjdp
117933965Sjdp*/
118033965Sjdp
1181130561Sobrienbfd_boolean
1182130561Sobrienbfd_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
1183130561Sobrien		       sec_ptr section,
1184130561Sobrien		       flagword flags)
118533965Sjdp{
118633965Sjdp  section->flags = flags;
1187130561Sobrien  return TRUE;
118833965Sjdp}
118933965Sjdp
119033965Sjdp/*
119133965SjdpFUNCTION
119233965Sjdp	bfd_map_over_sections
119333965Sjdp
119433965SjdpSYNOPSIS
1195130561Sobrien	void bfd_map_over_sections
1196130561Sobrien	  (bfd *abfd,
1197130561Sobrien	   void (*func) (bfd *abfd, asection *sect, void *obj),
1198130561Sobrien	   void *obj);
119933965Sjdp
120033965SjdpDESCRIPTION
120133965Sjdp	Call the provided function @var{func} for each section
120233965Sjdp	attached to the BFD @var{abfd}, passing @var{obj} as an
120333965Sjdp	argument. The function will be called as if by
120433965Sjdp
1205130561Sobrien|	func (abfd, the_section, obj);
120633965Sjdp
1207130561Sobrien	This is the preferred method for iterating over sections; an
120833965Sjdp	alternative would be to use a loop:
120933965Sjdp
121033965Sjdp|	   section *p;
121133965Sjdp|	   for (p = abfd->sections; p != NULL; p = p->next)
1212130561Sobrien|	      func (abfd, p, ...)
121333965Sjdp
121433965Sjdp*/
121533965Sjdp
121633965Sjdpvoid
1217130561Sobrienbfd_map_over_sections (bfd *abfd,
1218130561Sobrien		       void (*operation) (bfd *, asection *, void *),
1219130561Sobrien		       void *user_storage)
122033965Sjdp{
122133965Sjdp  asection *sect;
122233965Sjdp  unsigned int i = 0;
122333965Sjdp
122433965Sjdp  for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
122533965Sjdp    (*operation) (abfd, sect, user_storage);
122633965Sjdp
122733965Sjdp  if (i != abfd->section_count)	/* Debugging */
122833965Sjdp    abort ();
122933965Sjdp}
123033965Sjdp
123133965Sjdp/*
123233965SjdpFUNCTION
1233218822Sdim	bfd_sections_find_if
1234218822Sdim
1235218822SdimSYNOPSIS
1236218822Sdim	asection *bfd_sections_find_if
1237218822Sdim	  (bfd *abfd,
1238218822Sdim	   bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
1239218822Sdim	   void *obj);
1240218822Sdim
1241218822SdimDESCRIPTION
1242218822Sdim	Call the provided function @var{operation} for each section
1243218822Sdim	attached to the BFD @var{abfd}, passing @var{obj} as an
1244218822Sdim	argument. The function will be called as if by
1245218822Sdim
1246218822Sdim|	operation (abfd, the_section, obj);
1247218822Sdim
1248218822Sdim	It returns the first section for which @var{operation} returns true.
1249218822Sdim
1250218822Sdim*/
1251218822Sdim
1252218822Sdimasection *
1253218822Sdimbfd_sections_find_if (bfd *abfd,
1254218822Sdim		      bfd_boolean (*operation) (bfd *, asection *, void *),
1255218822Sdim		      void *user_storage)
1256218822Sdim{
1257218822Sdim  asection *sect;
1258218822Sdim
1259218822Sdim  for (sect = abfd->sections; sect != NULL; sect = sect->next)
1260218822Sdim    if ((*operation) (abfd, sect, user_storage))
1261218822Sdim      break;
1262218822Sdim
1263218822Sdim  return sect;
1264218822Sdim}
1265218822Sdim
1266218822Sdim/*
1267218822SdimFUNCTION
126833965Sjdp	bfd_set_section_size
126933965Sjdp
127033965SjdpSYNOPSIS
1271130561Sobrien	bfd_boolean bfd_set_section_size
1272130561Sobrien	  (bfd *abfd, asection *sec, bfd_size_type val);
127333965Sjdp
127433965SjdpDESCRIPTION
127533965Sjdp	Set @var{sec} to the size @var{val}. If the operation is
1276130561Sobrien	ok, then <<TRUE>> is returned, else <<FALSE>>.
127733965Sjdp
127833965Sjdp	Possible error returns:
127933965Sjdp	o <<bfd_error_invalid_operation>> -
128033965Sjdp	Writing has started to the BFD, so setting the size is invalid.
128133965Sjdp
128233965Sjdp*/
128333965Sjdp
1284130561Sobrienbfd_boolean
1285130561Sobrienbfd_set_section_size (bfd *abfd, sec_ptr ptr, bfd_size_type val)
128633965Sjdp{
128733965Sjdp  /* Once you've started writing to any section you cannot create or change
128877298Sobrien     the size of any others.  */
128933965Sjdp
129033965Sjdp  if (abfd->output_has_begun)
129133965Sjdp    {
129233965Sjdp      bfd_set_error (bfd_error_invalid_operation);
1293130561Sobrien      return FALSE;
129433965Sjdp    }
129533965Sjdp
1296218822Sdim  ptr->size = val;
1297130561Sobrien  return TRUE;
129833965Sjdp}
129933965Sjdp
130033965Sjdp/*
130133965SjdpFUNCTION
130233965Sjdp	bfd_set_section_contents
130333965Sjdp
130433965SjdpSYNOPSIS
1305130561Sobrien	bfd_boolean bfd_set_section_contents
1306130561Sobrien	  (bfd *abfd, asection *section, const void *data,
1307130561Sobrien	   file_ptr offset, bfd_size_type count);
130833965Sjdp
130933965SjdpDESCRIPTION
131033965Sjdp	Sets the contents of the section @var{section} in BFD
131133965Sjdp	@var{abfd} to the data starting in memory at @var{data}. The
131233965Sjdp	data is written to the output section starting at offset
131360484Sobrien	@var{offset} for @var{count} octets.
131433965Sjdp
1315130561Sobrien	Normally <<TRUE>> is returned, else <<FALSE>>. Possible error
131633965Sjdp	returns are:
131733965Sjdp	o <<bfd_error_no_contents>> -
131833965Sjdp	The output section does not have the <<SEC_HAS_CONTENTS>>
131933965Sjdp	attribute, so nothing can be written to it.
132033965Sjdp	o and some more too
132133965Sjdp
132233965Sjdp	This routine is front end to the back end function
132333965Sjdp	<<_bfd_set_section_contents>>.
132433965Sjdp
132533965Sjdp*/
132633965Sjdp
1327130561Sobrienbfd_boolean
1328130561Sobrienbfd_set_section_contents (bfd *abfd,
1329130561Sobrien			  sec_ptr section,
1330130561Sobrien			  const void *location,
1331130561Sobrien			  file_ptr offset,
1332130561Sobrien			  bfd_size_type count)
133333965Sjdp{
133433965Sjdp  bfd_size_type sz;
133533965Sjdp
133633965Sjdp  if (!(bfd_get_section_flags (abfd, section) & SEC_HAS_CONTENTS))
133733965Sjdp    {
133833965Sjdp      bfd_set_error (bfd_error_no_contents);
1339130561Sobrien      return FALSE;
134033965Sjdp    }
134133965Sjdp
1342218822Sdim  sz = section->size;
134389857Sobrien  if ((bfd_size_type) offset > sz
134489857Sobrien      || count > sz
134589857Sobrien      || offset + count > sz
134689857Sobrien      || count != (size_t) count)
134733965Sjdp    {
134833965Sjdp      bfd_set_error (bfd_error_bad_value);
1349130561Sobrien      return FALSE;
135033965Sjdp    }
135133965Sjdp
1352218822Sdim  if (!bfd_write_p (abfd))
135333965Sjdp    {
135433965Sjdp      bfd_set_error (bfd_error_invalid_operation);
1355130561Sobrien      return FALSE;
135633965Sjdp    }
135733965Sjdp
135877298Sobrien  /* Record a copy of the data in memory if desired.  */
135977298Sobrien  if (section->contents
1360130561Sobrien      && location != section->contents + offset)
136189857Sobrien    memcpy (section->contents + offset, location, (size_t) count);
136277298Sobrien
136333965Sjdp  if (BFD_SEND (abfd, _bfd_set_section_contents,
136433965Sjdp		(abfd, section, location, offset, count)))
136533965Sjdp    {
1366130561Sobrien      abfd->output_has_begun = TRUE;
1367130561Sobrien      return TRUE;
136833965Sjdp    }
136933965Sjdp
1370130561Sobrien  return FALSE;
137133965Sjdp}
137233965Sjdp
137333965Sjdp/*
137433965SjdpFUNCTION
137533965Sjdp	bfd_get_section_contents
137633965Sjdp
137733965SjdpSYNOPSIS
1378130561Sobrien	bfd_boolean bfd_get_section_contents
1379130561Sobrien	  (bfd *abfd, asection *section, void *location, file_ptr offset,
1380130561Sobrien	   bfd_size_type count);
138133965Sjdp
138233965SjdpDESCRIPTION
138333965Sjdp	Read data from @var{section} in BFD @var{abfd}
138433965Sjdp	into memory starting at @var{location}. The data is read at an
138533965Sjdp	offset of @var{offset} from the start of the input section,
138633965Sjdp	and is read for @var{count} bytes.
138733965Sjdp
138833965Sjdp	If the contents of a constructor with the <<SEC_CONSTRUCTOR>>
138933965Sjdp	flag set are requested or if the section does not have the
139033965Sjdp	<<SEC_HAS_CONTENTS>> flag set, then the @var{location} is filled
1391130561Sobrien	with zeroes. If no errors occur, <<TRUE>> is returned, else
1392130561Sobrien	<<FALSE>>.
139333965Sjdp
139433965Sjdp*/
1395130561Sobrienbfd_boolean
1396130561Sobrienbfd_get_section_contents (bfd *abfd,
1397130561Sobrien			  sec_ptr section,
1398130561Sobrien			  void *location,
1399130561Sobrien			  file_ptr offset,
1400130561Sobrien			  bfd_size_type count)
140133965Sjdp{
140233965Sjdp  bfd_size_type sz;
140333965Sjdp
140433965Sjdp  if (section->flags & SEC_CONSTRUCTOR)
140533965Sjdp    {
140689857Sobrien      memset (location, 0, (size_t) count);
1407130561Sobrien      return TRUE;
140833965Sjdp    }
140933965Sjdp
1410218822Sdim  sz = section->rawsize ? section->rawsize : section->size;
141189857Sobrien  if ((bfd_size_type) offset > sz
141289857Sobrien      || count > sz
141389857Sobrien      || offset + count > sz
141489857Sobrien      || count != (size_t) count)
141533965Sjdp    {
141633965Sjdp      bfd_set_error (bfd_error_bad_value);
1417130561Sobrien      return FALSE;
141833965Sjdp    }
141933965Sjdp
142033965Sjdp  if (count == 0)
142133965Sjdp    /* Don't bother.  */
1422130561Sobrien    return TRUE;
142333965Sjdp
142433965Sjdp  if ((section->flags & SEC_HAS_CONTENTS) == 0)
142533965Sjdp    {
142689857Sobrien      memset (location, 0, (size_t) count);
1427130561Sobrien      return TRUE;
142833965Sjdp    }
142933965Sjdp
143033965Sjdp  if ((section->flags & SEC_IN_MEMORY) != 0)
143133965Sjdp    {
143233965Sjdp      memcpy (location, section->contents + offset, (size_t) count);
1433130561Sobrien      return TRUE;
143433965Sjdp    }
143533965Sjdp
143633965Sjdp  return BFD_SEND (abfd, _bfd_get_section_contents,
143733965Sjdp		   (abfd, section, location, offset, count));
143833965Sjdp}
143933965Sjdp
144033965Sjdp/*
144133965SjdpFUNCTION
1442218822Sdim	bfd_malloc_and_get_section
1443218822Sdim
1444218822SdimSYNOPSIS
1445218822Sdim	bfd_boolean bfd_malloc_and_get_section
1446218822Sdim	  (bfd *abfd, asection *section, bfd_byte **buf);
1447218822Sdim
1448218822SdimDESCRIPTION
1449218822Sdim	Read all data from @var{section} in BFD @var{abfd}
1450218822Sdim	into a buffer, *@var{buf}, malloc'd by this function.
1451218822Sdim*/
1452218822Sdim
1453218822Sdimbfd_boolean
1454218822Sdimbfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf)
1455218822Sdim{
1456218822Sdim  bfd_size_type sz = sec->rawsize ? sec->rawsize : sec->size;
1457218822Sdim  bfd_byte *p = NULL;
1458218822Sdim
1459218822Sdim  *buf = p;
1460218822Sdim  if (sz == 0)
1461218822Sdim    return TRUE;
1462218822Sdim
1463218822Sdim  p = bfd_malloc (sec->rawsize > sec->size ? sec->rawsize : sec->size);
1464218822Sdim  if (p == NULL)
1465218822Sdim    return FALSE;
1466218822Sdim  *buf = p;
1467218822Sdim
1468218822Sdim  return bfd_get_section_contents (abfd, sec, p, 0, sz);
1469218822Sdim}
1470218822Sdim/*
1471218822SdimFUNCTION
147233965Sjdp	bfd_copy_private_section_data
147333965Sjdp
147433965SjdpSYNOPSIS
1475130561Sobrien	bfd_boolean bfd_copy_private_section_data
1476130561Sobrien	  (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
147733965Sjdp
147833965SjdpDESCRIPTION
147933965Sjdp	Copy private section information from @var{isec} in the BFD
148033965Sjdp	@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
1481130561Sobrien	Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
148233965Sjdp	returns are:
148333965Sjdp
148433965Sjdp	o <<bfd_error_no_memory>> -
148533965Sjdp	Not enough memory exists to create private data for @var{osec}.
148633965Sjdp
148733965Sjdp.#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
148833965Sjdp.     BFD_SEND (obfd, _bfd_copy_private_section_data, \
148933965Sjdp.		(ibfd, isection, obfd, osection))
149033965Sjdp*/
149160484Sobrien
149260484Sobrien/*
149360484SobrienFUNCTION
1494218822Sdim	bfd_generic_is_group_section
149560484Sobrien
149660484SobrienSYNOPSIS
1497218822Sdim	bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
149860484Sobrien
149960484SobrienDESCRIPTION
1500218822Sdim	Returns TRUE if @var{sec} is a member of a group.
1501218822Sdim*/
1502104834Sobrien
1503218822Sdimbfd_boolean
1504218822Sdimbfd_generic_is_group_section (bfd *abfd ATTRIBUTE_UNUSED,
1505218822Sdim			      const asection *sec ATTRIBUTE_UNUSED)
150660484Sobrien{
1507218822Sdim  return FALSE;
1508104834Sobrien}
150960484Sobrien
1510104834Sobrien/*
1511104834SobrienFUNCTION
1512104834Sobrien	bfd_generic_discard_group
151360484Sobrien
1514104834SobrienSYNOPSIS
1515130561Sobrien	bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
151689857Sobrien
1517104834SobrienDESCRIPTION
1518104834Sobrien	Remove all members of @var{group} from the output.
1519104834Sobrien*/
1520104834Sobrien
1521130561Sobrienbfd_boolean
1522130561Sobrienbfd_generic_discard_group (bfd *abfd ATTRIBUTE_UNUSED,
1523130561Sobrien			   asection *group ATTRIBUTE_UNUSED)
1524104834Sobrien{
1525130561Sobrien  return TRUE;
152660484Sobrien}
1527