xref: /dflybsd-src/contrib/gdb-7/bfd/section.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Object file "section" support for the BFD library.
25796c8dcSSimon Schubert    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3*ef5ccd6cSJohn Marino    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4*ef5ccd6cSJohn Marino    2012, 2013
55796c8dcSSimon Schubert    Free Software Foundation, Inc.
65796c8dcSSimon Schubert    Written by Cygnus Support.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This file is part of BFD, the Binary File Descriptor library.
95796c8dcSSimon Schubert 
105796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
115796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
125796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
135796c8dcSSimon Schubert    (at your option) any later version.
145796c8dcSSimon Schubert 
155796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
165796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
175796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
185796c8dcSSimon Schubert    GNU General Public License for more details.
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
215796c8dcSSimon Schubert    along with this program; if not, write to the Free Software
225796c8dcSSimon Schubert    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
235796c8dcSSimon Schubert    MA 02110-1301, USA.  */
245796c8dcSSimon Schubert 
255796c8dcSSimon Schubert /*
265796c8dcSSimon Schubert SECTION
275796c8dcSSimon Schubert 	Sections
285796c8dcSSimon Schubert 
295796c8dcSSimon Schubert 	The raw data contained within a BFD is maintained through the
305796c8dcSSimon Schubert 	section abstraction.  A single BFD may have any number of
315796c8dcSSimon Schubert 	sections.  It keeps hold of them by pointing to the first;
325796c8dcSSimon Schubert 	each one points to the next in the list.
335796c8dcSSimon Schubert 
345796c8dcSSimon Schubert 	Sections are supported in BFD in <<section.c>>.
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert @menu
375796c8dcSSimon Schubert @* Section Input::
385796c8dcSSimon Schubert @* Section Output::
395796c8dcSSimon Schubert @* typedef asection::
405796c8dcSSimon Schubert @* section prototypes::
415796c8dcSSimon Schubert @end menu
425796c8dcSSimon Schubert 
435796c8dcSSimon Schubert INODE
445796c8dcSSimon Schubert Section Input, Section Output, Sections, Sections
455796c8dcSSimon Schubert SUBSECTION
465796c8dcSSimon Schubert 	Section input
475796c8dcSSimon Schubert 
485796c8dcSSimon Schubert 	When a BFD is opened for reading, the section structures are
495796c8dcSSimon Schubert 	created and attached to the BFD.
505796c8dcSSimon Schubert 
515796c8dcSSimon Schubert 	Each section has a name which describes the section in the
525796c8dcSSimon Schubert 	outside world---for example, <<a.out>> would contain at least
535796c8dcSSimon Schubert 	three sections, called <<.text>>, <<.data>> and <<.bss>>.
545796c8dcSSimon Schubert 
555796c8dcSSimon Schubert 	Names need not be unique; for example a COFF file may have several
565796c8dcSSimon Schubert 	sections named <<.data>>.
575796c8dcSSimon Schubert 
585796c8dcSSimon Schubert 	Sometimes a BFD will contain more than the ``natural'' number of
595796c8dcSSimon Schubert 	sections. A back end may attach other sections containing
605796c8dcSSimon Schubert 	constructor data, or an application may add a section (using
615796c8dcSSimon Schubert 	<<bfd_make_section>>) to the sections attached to an already open
625796c8dcSSimon Schubert 	BFD. For example, the linker creates an extra section
635796c8dcSSimon Schubert 	<<COMMON>> for each input file's BFD to hold information about
645796c8dcSSimon Schubert 	common storage.
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert 	The raw data is not necessarily read in when
675796c8dcSSimon Schubert 	the section descriptor is created. Some targets may leave the
685796c8dcSSimon Schubert 	data in place until a <<bfd_get_section_contents>> call is
695796c8dcSSimon Schubert 	made. Other back ends may read in all the data at once.  For
705796c8dcSSimon Schubert 	example, an S-record file has to be read once to determine the
715796c8dcSSimon Schubert 	size of the data. An IEEE-695 file doesn't contain raw data in
725796c8dcSSimon Schubert 	sections, but data and relocation expressions intermixed, so
735796c8dcSSimon Schubert 	the data area has to be parsed to get out the data and
745796c8dcSSimon Schubert 	relocations.
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert INODE
775796c8dcSSimon Schubert Section Output, typedef asection, Section Input, Sections
785796c8dcSSimon Schubert 
795796c8dcSSimon Schubert SUBSECTION
805796c8dcSSimon Schubert 	Section output
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert 	To write a new object style BFD, the various sections to be
835796c8dcSSimon Schubert 	written have to be created. They are attached to the BFD in
845796c8dcSSimon Schubert 	the same way as input sections; data is written to the
855796c8dcSSimon Schubert 	sections using <<bfd_set_section_contents>>.
865796c8dcSSimon Schubert 
875796c8dcSSimon Schubert 	Any program that creates or combines sections (e.g., the assembler
885796c8dcSSimon Schubert 	and linker) must use the <<asection>> fields <<output_section>> and
895796c8dcSSimon Schubert 	<<output_offset>> to indicate the file sections to which each
905796c8dcSSimon Schubert 	section must be written.  (If the section is being created from
915796c8dcSSimon Schubert 	scratch, <<output_section>> should probably point to the section
925796c8dcSSimon Schubert 	itself and <<output_offset>> should probably be zero.)
935796c8dcSSimon Schubert 
945796c8dcSSimon Schubert 	The data to be written comes from input sections attached
955796c8dcSSimon Schubert 	(via <<output_section>> pointers) to
965796c8dcSSimon Schubert 	the output sections.  The output section structure can be
975796c8dcSSimon Schubert 	considered a filter for the input section: the output section
985796c8dcSSimon Schubert 	determines the vma of the output data and the name, but the
995796c8dcSSimon Schubert 	input section determines the offset into the output section of
1005796c8dcSSimon Schubert 	the data to be written.
1015796c8dcSSimon Schubert 
1025796c8dcSSimon Schubert 	E.g., to create a section "O", starting at 0x100, 0x123 long,
1035796c8dcSSimon Schubert 	containing two subsections, "A" at offset 0x0 (i.e., at vma
1045796c8dcSSimon Schubert 	0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the <<asection>>
1055796c8dcSSimon Schubert 	structures would look like:
1065796c8dcSSimon Schubert 
1075796c8dcSSimon Schubert |   section name          "A"
1085796c8dcSSimon Schubert |     output_offset   0x00
1095796c8dcSSimon Schubert |     size            0x20
1105796c8dcSSimon Schubert |     output_section ----------->  section name    "O"
1115796c8dcSSimon Schubert |                             |    vma             0x100
1125796c8dcSSimon Schubert |   section name          "B" |    size            0x123
1135796c8dcSSimon Schubert |     output_offset   0x20    |
1145796c8dcSSimon Schubert |     size            0x103   |
1155796c8dcSSimon Schubert |     output_section  --------|
1165796c8dcSSimon Schubert 
1175796c8dcSSimon Schubert SUBSECTION
1185796c8dcSSimon Schubert 	Link orders
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert 	The data within a section is stored in a @dfn{link_order}.
1215796c8dcSSimon Schubert 	These are much like the fixups in <<gas>>.  The link_order
1225796c8dcSSimon Schubert 	abstraction allows a section to grow and shrink within itself.
1235796c8dcSSimon Schubert 
1245796c8dcSSimon Schubert 	A link_order knows how big it is, and which is the next
1255796c8dcSSimon Schubert 	link_order and where the raw data for it is; it also points to
1265796c8dcSSimon Schubert 	a list of relocations which apply to it.
1275796c8dcSSimon Schubert 
1285796c8dcSSimon Schubert 	The link_order is used by the linker to perform relaxing on
1295796c8dcSSimon Schubert 	final code.  The compiler creates code which is as big as
1305796c8dcSSimon Schubert 	necessary to make it work without relaxing, and the user can
1315796c8dcSSimon Schubert 	select whether to relax.  Sometimes relaxing takes a lot of
1325796c8dcSSimon Schubert 	time.  The linker runs around the relocations to see if any
1335796c8dcSSimon Schubert 	are attached to data which can be shrunk, if so it does it on
1345796c8dcSSimon Schubert 	a link_order by link_order basis.
1355796c8dcSSimon Schubert 
1365796c8dcSSimon Schubert */
1375796c8dcSSimon Schubert 
1385796c8dcSSimon Schubert #include "sysdep.h"
1395796c8dcSSimon Schubert #include "bfd.h"
1405796c8dcSSimon Schubert #include "libbfd.h"
1415796c8dcSSimon Schubert #include "bfdlink.h"
1425796c8dcSSimon Schubert 
1435796c8dcSSimon Schubert /*
1445796c8dcSSimon Schubert DOCDD
1455796c8dcSSimon Schubert INODE
1465796c8dcSSimon Schubert typedef asection, section prototypes, Section Output, Sections
1475796c8dcSSimon Schubert SUBSECTION
1485796c8dcSSimon Schubert 	typedef asection
1495796c8dcSSimon Schubert 
1505796c8dcSSimon Schubert 	Here is the section structure:
1515796c8dcSSimon Schubert 
1525796c8dcSSimon Schubert CODE_FRAGMENT
1535796c8dcSSimon Schubert .
1545796c8dcSSimon Schubert .typedef struct bfd_section
1555796c8dcSSimon Schubert .{
1565796c8dcSSimon Schubert .  {* The name of the section; the name isn't a copy, the pointer is
1575796c8dcSSimon Schubert .     the same as that passed to bfd_make_section.  *}
1585796c8dcSSimon Schubert .  const char *name;
1595796c8dcSSimon Schubert .
1605796c8dcSSimon Schubert .  {* A unique sequence number.  *}
1615796c8dcSSimon Schubert .  int id;
1625796c8dcSSimon Schubert .
1635796c8dcSSimon Schubert .  {* Which section in the bfd; 0..n-1 as sections are created in a bfd.  *}
1645796c8dcSSimon Schubert .  int index;
1655796c8dcSSimon Schubert .
1665796c8dcSSimon Schubert .  {* The next section in the list belonging to the BFD, or NULL.  *}
1675796c8dcSSimon Schubert .  struct bfd_section *next;
1685796c8dcSSimon Schubert .
1695796c8dcSSimon Schubert .  {* The previous section in the list belonging to the BFD, or NULL.  *}
1705796c8dcSSimon Schubert .  struct bfd_section *prev;
1715796c8dcSSimon Schubert .
1725796c8dcSSimon Schubert .  {* The field flags contains attributes of the section. Some
1735796c8dcSSimon Schubert .     flags are read in from the object file, and some are
1745796c8dcSSimon Schubert .     synthesized from other information.  *}
1755796c8dcSSimon Schubert .  flagword flags;
1765796c8dcSSimon Schubert .
1775796c8dcSSimon Schubert .#define SEC_NO_FLAGS   0x000
1785796c8dcSSimon Schubert .
1795796c8dcSSimon Schubert .  {* Tells the OS to allocate space for this section when loading.
1805796c8dcSSimon Schubert .     This is clear for a section containing debug information only.  *}
1815796c8dcSSimon Schubert .#define SEC_ALLOC      0x001
1825796c8dcSSimon Schubert .
1835796c8dcSSimon Schubert .  {* Tells the OS to load the section from the file when loading.
1845796c8dcSSimon Schubert .     This is clear for a .bss section.  *}
1855796c8dcSSimon Schubert .#define SEC_LOAD       0x002
1865796c8dcSSimon Schubert .
1875796c8dcSSimon Schubert .  {* The section contains data still to be relocated, so there is
1885796c8dcSSimon Schubert .     some relocation information too.  *}
1895796c8dcSSimon Schubert .#define SEC_RELOC      0x004
1905796c8dcSSimon Schubert .
1915796c8dcSSimon Schubert .  {* A signal to the OS that the section contains read only data.  *}
1925796c8dcSSimon Schubert .#define SEC_READONLY   0x008
1935796c8dcSSimon Schubert .
1945796c8dcSSimon Schubert .  {* The section contains code only.  *}
1955796c8dcSSimon Schubert .#define SEC_CODE       0x010
1965796c8dcSSimon Schubert .
1975796c8dcSSimon Schubert .  {* The section contains data only.  *}
1985796c8dcSSimon Schubert .#define SEC_DATA       0x020
1995796c8dcSSimon Schubert .
2005796c8dcSSimon Schubert .  {* The section will reside in ROM.  *}
2015796c8dcSSimon Schubert .#define SEC_ROM        0x040
2025796c8dcSSimon Schubert .
2035796c8dcSSimon Schubert .  {* The section contains constructor information. This section
2045796c8dcSSimon Schubert .     type is used by the linker to create lists of constructors and
2055796c8dcSSimon Schubert .     destructors used by <<g++>>. When a back end sees a symbol
2065796c8dcSSimon Schubert .     which should be used in a constructor list, it creates a new
2075796c8dcSSimon Schubert .     section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
2085796c8dcSSimon Schubert .     the symbol to it, and builds a relocation. To build the lists
2095796c8dcSSimon Schubert .     of constructors, all the linker has to do is catenate all the
2105796c8dcSSimon Schubert .     sections called <<__CTOR_LIST__>> and relocate the data
2115796c8dcSSimon Schubert .     contained within - exactly the operations it would peform on
2125796c8dcSSimon Schubert .     standard data.  *}
2135796c8dcSSimon Schubert .#define SEC_CONSTRUCTOR 0x080
2145796c8dcSSimon Schubert .
2155796c8dcSSimon Schubert .  {* The section has contents - a data section could be
2165796c8dcSSimon Schubert .     <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
2175796c8dcSSimon Schubert .     <<SEC_HAS_CONTENTS>>  *}
2185796c8dcSSimon Schubert .#define SEC_HAS_CONTENTS 0x100
2195796c8dcSSimon Schubert .
2205796c8dcSSimon Schubert .  {* An instruction to the linker to not output the section
2215796c8dcSSimon Schubert .     even if it has information which would normally be written.  *}
2225796c8dcSSimon Schubert .#define SEC_NEVER_LOAD 0x200
2235796c8dcSSimon Schubert .
2245796c8dcSSimon Schubert .  {* The section contains thread local data.  *}
2255796c8dcSSimon Schubert .#define SEC_THREAD_LOCAL 0x400
2265796c8dcSSimon Schubert .
2275796c8dcSSimon Schubert .  {* The section has GOT references.  This flag is only for the
2285796c8dcSSimon Schubert .     linker, and is currently only used by the elf32-hppa back end.
2295796c8dcSSimon Schubert .     It will be set if global offset table references were detected
2305796c8dcSSimon Schubert .     in this section, which indicate to the linker that the section
2315796c8dcSSimon Schubert .     contains PIC code, and must be handled specially when doing a
2325796c8dcSSimon Schubert .     static link.  *}
2335796c8dcSSimon Schubert .#define SEC_HAS_GOT_REF 0x800
2345796c8dcSSimon Schubert .
2355796c8dcSSimon Schubert .  {* The section contains common symbols (symbols may be defined
2365796c8dcSSimon Schubert .     multiple times, the value of a symbol is the amount of
2375796c8dcSSimon Schubert .     space it requires, and the largest symbol value is the one
2385796c8dcSSimon Schubert .     used).  Most targets have exactly one of these (which we
2395796c8dcSSimon Schubert .     translate to bfd_com_section_ptr), but ECOFF has two.  *}
2405796c8dcSSimon Schubert .#define SEC_IS_COMMON 0x1000
2415796c8dcSSimon Schubert .
2425796c8dcSSimon Schubert .  {* The section contains only debugging information.  For
2435796c8dcSSimon Schubert .     example, this is set for ELF .debug and .stab sections.
2445796c8dcSSimon Schubert .     strip tests this flag to see if a section can be
2455796c8dcSSimon Schubert .     discarded.  *}
2465796c8dcSSimon Schubert .#define SEC_DEBUGGING 0x2000
2475796c8dcSSimon Schubert .
2485796c8dcSSimon Schubert .  {* The contents of this section are held in memory pointed to
2495796c8dcSSimon Schubert .     by the contents field.  This is checked by bfd_get_section_contents,
2505796c8dcSSimon Schubert .     and the data is retrieved from memory if appropriate.  *}
2515796c8dcSSimon Schubert .#define SEC_IN_MEMORY 0x4000
2525796c8dcSSimon Schubert .
2535796c8dcSSimon Schubert .  {* The contents of this section are to be excluded by the
2545796c8dcSSimon Schubert .     linker for executable and shared objects unless those
2555796c8dcSSimon Schubert .     objects are to be further relocated.  *}
2565796c8dcSSimon Schubert .#define SEC_EXCLUDE 0x8000
2575796c8dcSSimon Schubert .
2585796c8dcSSimon Schubert .  {* The contents of this section are to be sorted based on the sum of
2595796c8dcSSimon Schubert .     the symbol and addend values specified by the associated relocation
2605796c8dcSSimon Schubert .     entries.  Entries without associated relocation entries will be
2615796c8dcSSimon Schubert .     appended to the end of the section in an unspecified order.  *}
2625796c8dcSSimon Schubert .#define SEC_SORT_ENTRIES 0x10000
2635796c8dcSSimon Schubert .
2645796c8dcSSimon Schubert .  {* When linking, duplicate sections of the same name should be
2655796c8dcSSimon Schubert .     discarded, rather than being combined into a single section as
2665796c8dcSSimon Schubert .     is usually done.  This is similar to how common symbols are
2675796c8dcSSimon Schubert .     handled.  See SEC_LINK_DUPLICATES below.  *}
2685796c8dcSSimon Schubert .#define SEC_LINK_ONCE 0x20000
2695796c8dcSSimon Schubert .
2705796c8dcSSimon Schubert .  {* If SEC_LINK_ONCE is set, this bitfield describes how the linker
2715796c8dcSSimon Schubert .     should handle duplicate sections.  *}
2725796c8dcSSimon Schubert .#define SEC_LINK_DUPLICATES 0xc0000
2735796c8dcSSimon Schubert .
2745796c8dcSSimon Schubert .  {* This value for SEC_LINK_DUPLICATES means that duplicate
2755796c8dcSSimon Schubert .     sections with the same name should simply be discarded.  *}
2765796c8dcSSimon Schubert .#define SEC_LINK_DUPLICATES_DISCARD 0x0
2775796c8dcSSimon Schubert .
2785796c8dcSSimon Schubert .  {* This value for SEC_LINK_DUPLICATES means that the linker
2795796c8dcSSimon Schubert .     should warn if there are any duplicate sections, although
2805796c8dcSSimon Schubert .     it should still only link one copy.  *}
2815796c8dcSSimon Schubert .#define SEC_LINK_DUPLICATES_ONE_ONLY 0x40000
2825796c8dcSSimon Schubert .
2835796c8dcSSimon Schubert .  {* This value for SEC_LINK_DUPLICATES means that the linker
2845796c8dcSSimon Schubert .     should warn if any duplicate sections are a different size.  *}
2855796c8dcSSimon Schubert .#define SEC_LINK_DUPLICATES_SAME_SIZE 0x80000
2865796c8dcSSimon Schubert .
2875796c8dcSSimon Schubert .  {* This value for SEC_LINK_DUPLICATES means that the linker
2885796c8dcSSimon Schubert .     should warn if any duplicate sections contain different
2895796c8dcSSimon Schubert .     contents.  *}
2905796c8dcSSimon Schubert .#define SEC_LINK_DUPLICATES_SAME_CONTENTS \
2915796c8dcSSimon Schubert .  (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
2925796c8dcSSimon Schubert .
2935796c8dcSSimon Schubert .  {* This section was created by the linker as part of dynamic
2945796c8dcSSimon Schubert .     relocation or other arcane processing.  It is skipped when
2955796c8dcSSimon Schubert .     going through the first-pass output, trusting that someone
2965796c8dcSSimon Schubert .     else up the line will take care of it later.  *}
2975796c8dcSSimon Schubert .#define SEC_LINKER_CREATED 0x100000
2985796c8dcSSimon Schubert .
2995796c8dcSSimon Schubert .  {* This section should not be subject to garbage collection.
3005796c8dcSSimon Schubert .     Also set to inform the linker that this section should not be
3015796c8dcSSimon Schubert .     listed in the link map as discarded.  *}
3025796c8dcSSimon Schubert .#define SEC_KEEP 0x200000
3035796c8dcSSimon Schubert .
3045796c8dcSSimon Schubert .  {* This section contains "short" data, and should be placed
3055796c8dcSSimon Schubert .     "near" the GP.  *}
3065796c8dcSSimon Schubert .#define SEC_SMALL_DATA 0x400000
3075796c8dcSSimon Schubert .
3085796c8dcSSimon Schubert .  {* Attempt to merge identical entities in the section.
3095796c8dcSSimon Schubert .     Entity size is given in the entsize field.  *}
3105796c8dcSSimon Schubert .#define SEC_MERGE 0x800000
3115796c8dcSSimon Schubert .
3125796c8dcSSimon Schubert .  {* If given with SEC_MERGE, entities to merge are zero terminated
3135796c8dcSSimon Schubert .     strings where entsize specifies character size instead of fixed
3145796c8dcSSimon Schubert .     size entries.  *}
3155796c8dcSSimon Schubert .#define SEC_STRINGS 0x1000000
3165796c8dcSSimon Schubert .
3175796c8dcSSimon Schubert .  {* This section contains data about section groups.  *}
3185796c8dcSSimon Schubert .#define SEC_GROUP 0x2000000
3195796c8dcSSimon Schubert .
3205796c8dcSSimon Schubert .  {* The section is a COFF shared library section.  This flag is
3215796c8dcSSimon Schubert .     only for the linker.  If this type of section appears in
3225796c8dcSSimon Schubert .     the input file, the linker must copy it to the output file
3235796c8dcSSimon Schubert .     without changing the vma or size.  FIXME: Although this
3245796c8dcSSimon Schubert .     was originally intended to be general, it really is COFF
3255796c8dcSSimon Schubert .     specific (and the flag was renamed to indicate this).  It
3265796c8dcSSimon Schubert .     might be cleaner to have some more general mechanism to
3275796c8dcSSimon Schubert .     allow the back end to control what the linker does with
3285796c8dcSSimon Schubert .     sections.  *}
3295796c8dcSSimon Schubert .#define SEC_COFF_SHARED_LIBRARY 0x4000000
3305796c8dcSSimon Schubert .
331a45ae5f8SJohn Marino .  {* This input section should be copied to output in reverse order
332a45ae5f8SJohn Marino .     as an array of pointers.  This is for ELF linker internal use
333a45ae5f8SJohn Marino .     only.  *}
334a45ae5f8SJohn Marino .#define SEC_ELF_REVERSE_COPY 0x4000000
335a45ae5f8SJohn Marino .
3365796c8dcSSimon Schubert .  {* This section contains data which may be shared with other
3375796c8dcSSimon Schubert .     executables or shared objects. This is for COFF only.  *}
3385796c8dcSSimon Schubert .#define SEC_COFF_SHARED 0x8000000
3395796c8dcSSimon Schubert .
3405796c8dcSSimon Schubert .  {* When a section with this flag is being linked, then if the size of
3415796c8dcSSimon Schubert .     the input section is less than a page, it should not cross a page
3425796c8dcSSimon Schubert .     boundary.  If the size of the input section is one page or more,
3435796c8dcSSimon Schubert .     it should be aligned on a page boundary.  This is for TI
3445796c8dcSSimon Schubert .     TMS320C54X only.  *}
3455796c8dcSSimon Schubert .#define SEC_TIC54X_BLOCK 0x10000000
3465796c8dcSSimon Schubert .
3475796c8dcSSimon Schubert .  {* Conditionally link this section; do not link if there are no
3485796c8dcSSimon Schubert .     references found to any symbol in the section.  This is for TI
3495796c8dcSSimon Schubert .     TMS320C54X only.  *}
3505796c8dcSSimon Schubert .#define SEC_TIC54X_CLINK 0x20000000
3515796c8dcSSimon Schubert .
3525796c8dcSSimon Schubert .  {* Indicate that section has the no read flag set. This happens
3535796c8dcSSimon Schubert .     when memory read flag isn't set. *}
3545796c8dcSSimon Schubert .#define SEC_COFF_NOREAD 0x40000000
3555796c8dcSSimon Schubert .
3565796c8dcSSimon Schubert .  {*  End of section flags.  *}
3575796c8dcSSimon Schubert .
3585796c8dcSSimon Schubert .  {* Some internal packed boolean fields.  *}
3595796c8dcSSimon Schubert .
3605796c8dcSSimon Schubert .  {* See the vma field.  *}
3615796c8dcSSimon Schubert .  unsigned int user_set_vma : 1;
3625796c8dcSSimon Schubert .
3635796c8dcSSimon Schubert .  {* A mark flag used by some of the linker backends.  *}
3645796c8dcSSimon Schubert .  unsigned int linker_mark : 1;
3655796c8dcSSimon Schubert .
3665796c8dcSSimon Schubert .  {* Another mark flag used by some of the linker backends.  Set for
3675796c8dcSSimon Schubert .     output sections that have an input section.  *}
3685796c8dcSSimon Schubert .  unsigned int linker_has_input : 1;
3695796c8dcSSimon Schubert .
3705796c8dcSSimon Schubert .  {* Mark flag used by some linker backends for garbage collection.  *}
3715796c8dcSSimon Schubert .  unsigned int gc_mark : 1;
3725796c8dcSSimon Schubert .
373c50c785cSJohn Marino .  {* Section compression status.  *}
374c50c785cSJohn Marino .  unsigned int compress_status : 2;
375c50c785cSJohn Marino .#define COMPRESS_SECTION_NONE    0
376c50c785cSJohn Marino .#define COMPRESS_SECTION_DONE    1
377c50c785cSJohn Marino .#define DECOMPRESS_SECTION_SIZED 2
378c50c785cSJohn Marino .
3795796c8dcSSimon Schubert .  {* The following flags are used by the ELF linker. *}
3805796c8dcSSimon Schubert .
3815796c8dcSSimon Schubert .  {* Mark sections which have been allocated to segments.  *}
3825796c8dcSSimon Schubert .  unsigned int segment_mark : 1;
3835796c8dcSSimon Schubert .
3845796c8dcSSimon Schubert .  {* Type of sec_info information.  *}
3855796c8dcSSimon Schubert .  unsigned int sec_info_type:3;
386*ef5ccd6cSJohn Marino .#define SEC_INFO_TYPE_NONE      0
387*ef5ccd6cSJohn Marino .#define SEC_INFO_TYPE_STABS     1
388*ef5ccd6cSJohn Marino .#define SEC_INFO_TYPE_MERGE     2
389*ef5ccd6cSJohn Marino .#define SEC_INFO_TYPE_EH_FRAME  3
390*ef5ccd6cSJohn Marino .#define SEC_INFO_TYPE_JUST_SYMS 4
3915796c8dcSSimon Schubert .
3925796c8dcSSimon Schubert .  {* Nonzero if this section uses RELA relocations, rather than REL.  *}
3935796c8dcSSimon Schubert .  unsigned int use_rela_p:1;
3945796c8dcSSimon Schubert .
3955796c8dcSSimon Schubert .  {* Bits used by various backends.  The generic code doesn't touch
3965796c8dcSSimon Schubert .     these fields.  *}
3975796c8dcSSimon Schubert .
398cf7f2e2dSJohn Marino .  unsigned int sec_flg0:1;
399cf7f2e2dSJohn Marino .  unsigned int sec_flg1:1;
400cf7f2e2dSJohn Marino .  unsigned int sec_flg2:1;
401cf7f2e2dSJohn Marino .  unsigned int sec_flg3:1;
402cf7f2e2dSJohn Marino .  unsigned int sec_flg4:1;
403cf7f2e2dSJohn Marino .  unsigned int sec_flg5:1;
4045796c8dcSSimon Schubert .
4055796c8dcSSimon Schubert .  {* End of internal packed boolean fields.  *}
4065796c8dcSSimon Schubert .
4075796c8dcSSimon Schubert .  {*  The virtual memory address of the section - where it will be
4085796c8dcSSimon Schubert .      at run time.  The symbols are relocated against this.  The
4095796c8dcSSimon Schubert .      user_set_vma flag is maintained by bfd; if it's not set, the
4105796c8dcSSimon Schubert .      backend can assign addresses (for example, in <<a.out>>, where
4115796c8dcSSimon Schubert .      the default address for <<.data>> is dependent on the specific
4125796c8dcSSimon Schubert .      target and various flags).  *}
4135796c8dcSSimon Schubert .  bfd_vma vma;
4145796c8dcSSimon Schubert .
4155796c8dcSSimon Schubert .  {*  The load address of the section - where it would be in a
4165796c8dcSSimon Schubert .      rom image; really only used for writing section header
4175796c8dcSSimon Schubert .      information.  *}
4185796c8dcSSimon Schubert .  bfd_vma lma;
4195796c8dcSSimon Schubert .
4205796c8dcSSimon Schubert .  {* The size of the section in octets, as it will be output.
4215796c8dcSSimon Schubert .     Contains a value even if the section has no contents (e.g., the
4225796c8dcSSimon Schubert .     size of <<.bss>>).  *}
4235796c8dcSSimon Schubert .  bfd_size_type size;
4245796c8dcSSimon Schubert .
4255796c8dcSSimon Schubert .  {* For input sections, the original size on disk of the section, in
4265796c8dcSSimon Schubert .     octets.  This field should be set for any section whose size is
4275796c8dcSSimon Schubert .     changed by linker relaxation.  It is required for sections where
4285796c8dcSSimon Schubert .     the linker relaxation scheme doesn't cache altered section and
4295796c8dcSSimon Schubert .     reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing
4305796c8dcSSimon Schubert .     targets), and thus the original size needs to be kept to read the
4315796c8dcSSimon Schubert .     section multiple times.  For output sections, rawsize holds the
4325796c8dcSSimon Schubert .     section size calculated on a previous linker relaxation pass.  *}
4335796c8dcSSimon Schubert .  bfd_size_type rawsize;
4345796c8dcSSimon Schubert .
435c50c785cSJohn Marino .  {* The compressed size of the section in octets.  *}
436c50c785cSJohn Marino .  bfd_size_type compressed_size;
437c50c785cSJohn Marino .
4385796c8dcSSimon Schubert .  {* Relaxation table. *}
4395796c8dcSSimon Schubert .  struct relax_table *relax;
4405796c8dcSSimon Schubert .
4415796c8dcSSimon Schubert .  {* Count of used relaxation table entries. *}
4425796c8dcSSimon Schubert .  int relax_count;
4435796c8dcSSimon Schubert .
4445796c8dcSSimon Schubert .
4455796c8dcSSimon Schubert .  {* If this section is going to be output, then this value is the
4465796c8dcSSimon Schubert .     offset in *bytes* into the output section of the first byte in the
4475796c8dcSSimon Schubert .     input section (byte ==> smallest addressable unit on the
4485796c8dcSSimon Schubert .     target).  In most cases, if this was going to start at the
4495796c8dcSSimon Schubert .     100th octet (8-bit quantity) in the output section, this value
4505796c8dcSSimon Schubert .     would be 100.  However, if the target byte size is 16 bits
4515796c8dcSSimon Schubert .     (bfd_octets_per_byte is "2"), this value would be 50.  *}
4525796c8dcSSimon Schubert .  bfd_vma output_offset;
4535796c8dcSSimon Schubert .
4545796c8dcSSimon Schubert .  {* The output section through which to map on output.  *}
4555796c8dcSSimon Schubert .  struct bfd_section *output_section;
4565796c8dcSSimon Schubert .
4575796c8dcSSimon Schubert .  {* The alignment requirement of the section, as an exponent of 2 -
4585796c8dcSSimon Schubert .     e.g., 3 aligns to 2^3 (or 8).  *}
4595796c8dcSSimon Schubert .  unsigned int alignment_power;
4605796c8dcSSimon Schubert .
4615796c8dcSSimon Schubert .  {* If an input section, a pointer to a vector of relocation
4625796c8dcSSimon Schubert .     records for the data in this section.  *}
4635796c8dcSSimon Schubert .  struct reloc_cache_entry *relocation;
4645796c8dcSSimon Schubert .
4655796c8dcSSimon Schubert .  {* If an output section, a pointer to a vector of pointers to
4665796c8dcSSimon Schubert .     relocation records for the data in this section.  *}
4675796c8dcSSimon Schubert .  struct reloc_cache_entry **orelocation;
4685796c8dcSSimon Schubert .
4695796c8dcSSimon Schubert .  {* The number of relocation records in one of the above.  *}
4705796c8dcSSimon Schubert .  unsigned reloc_count;
4715796c8dcSSimon Schubert .
4725796c8dcSSimon Schubert .  {* Information below is back end specific - and not always used
4735796c8dcSSimon Schubert .     or updated.  *}
4745796c8dcSSimon Schubert .
4755796c8dcSSimon Schubert .  {* File position of section data.  *}
4765796c8dcSSimon Schubert .  file_ptr filepos;
4775796c8dcSSimon Schubert .
4785796c8dcSSimon Schubert .  {* File position of relocation info.  *}
4795796c8dcSSimon Schubert .  file_ptr rel_filepos;
4805796c8dcSSimon Schubert .
4815796c8dcSSimon Schubert .  {* File position of line data.  *}
4825796c8dcSSimon Schubert .  file_ptr line_filepos;
4835796c8dcSSimon Schubert .
4845796c8dcSSimon Schubert .  {* Pointer to data for applications.  *}
4855796c8dcSSimon Schubert .  void *userdata;
4865796c8dcSSimon Schubert .
4875796c8dcSSimon Schubert .  {* If the SEC_IN_MEMORY flag is set, this points to the actual
4885796c8dcSSimon Schubert .     contents.  *}
4895796c8dcSSimon Schubert .  unsigned char *contents;
4905796c8dcSSimon Schubert .
4915796c8dcSSimon Schubert .  {* Attached line number information.  *}
4925796c8dcSSimon Schubert .  alent *lineno;
4935796c8dcSSimon Schubert .
4945796c8dcSSimon Schubert .  {* Number of line number records.  *}
4955796c8dcSSimon Schubert .  unsigned int lineno_count;
4965796c8dcSSimon Schubert .
4975796c8dcSSimon Schubert .  {* Entity size for merging purposes.  *}
4985796c8dcSSimon Schubert .  unsigned int entsize;
4995796c8dcSSimon Schubert .
5005796c8dcSSimon Schubert .  {* Points to the kept section if this section is a link-once section,
5015796c8dcSSimon Schubert .     and is discarded.  *}
5025796c8dcSSimon Schubert .  struct bfd_section *kept_section;
5035796c8dcSSimon Schubert .
5045796c8dcSSimon Schubert .  {* When a section is being output, this value changes as more
5055796c8dcSSimon Schubert .     linenumbers are written out.  *}
5065796c8dcSSimon Schubert .  file_ptr moving_line_filepos;
5075796c8dcSSimon Schubert .
5085796c8dcSSimon Schubert .  {* What the section number is in the target world.  *}
5095796c8dcSSimon Schubert .  int target_index;
5105796c8dcSSimon Schubert .
5115796c8dcSSimon Schubert .  void *used_by_bfd;
5125796c8dcSSimon Schubert .
5135796c8dcSSimon Schubert .  {* If this is a constructor section then here is a list of the
5145796c8dcSSimon Schubert .     relocations created to relocate items within it.  *}
5155796c8dcSSimon Schubert .  struct relent_chain *constructor_chain;
5165796c8dcSSimon Schubert .
5175796c8dcSSimon Schubert .  {* The BFD which owns the section.  *}
5185796c8dcSSimon Schubert .  bfd *owner;
5195796c8dcSSimon Schubert .
5205796c8dcSSimon Schubert .  {* A symbol which points at this section only.  *}
5215796c8dcSSimon Schubert .  struct bfd_symbol *symbol;
5225796c8dcSSimon Schubert .  struct bfd_symbol **symbol_ptr_ptr;
5235796c8dcSSimon Schubert .
5245796c8dcSSimon Schubert .  {* Early in the link process, map_head and map_tail are used to build
5255796c8dcSSimon Schubert .     a list of input sections attached to an output section.  Later,
5265796c8dcSSimon Schubert .     output sections use these fields for a list of bfd_link_order
5275796c8dcSSimon Schubert .     structs.  *}
5285796c8dcSSimon Schubert .  union {
5295796c8dcSSimon Schubert .    struct bfd_link_order *link_order;
5305796c8dcSSimon Schubert .    struct bfd_section *s;
5315796c8dcSSimon Schubert .  } map_head, map_tail;
5325796c8dcSSimon Schubert .} asection;
5335796c8dcSSimon Schubert .
5345796c8dcSSimon Schubert .{* Relax table contains information about instructions which can
5355796c8dcSSimon Schubert .   be removed by relaxation -- replacing a long address with a
5365796c8dcSSimon Schubert .   short address.  *}
5375796c8dcSSimon Schubert .struct relax_table {
5385796c8dcSSimon Schubert .  {* Address where bytes may be deleted. *}
5395796c8dcSSimon Schubert .  bfd_vma addr;
5405796c8dcSSimon Schubert .
5415796c8dcSSimon Schubert .  {* Number of bytes to be deleted.  *}
5425796c8dcSSimon Schubert .  int size;
5435796c8dcSSimon Schubert .};
5445796c8dcSSimon Schubert .
5455796c8dcSSimon Schubert .{* These sections are global, and are managed by BFD.  The application
5465796c8dcSSimon Schubert .   and target back end are not permitted to change the values in
547*ef5ccd6cSJohn Marino .   these sections.  *}
548*ef5ccd6cSJohn Marino .extern asection _bfd_std_section[4];
549*ef5ccd6cSJohn Marino .
5505796c8dcSSimon Schubert .#define BFD_ABS_SECTION_NAME "*ABS*"
5515796c8dcSSimon Schubert .#define BFD_UND_SECTION_NAME "*UND*"
5525796c8dcSSimon Schubert .#define BFD_COM_SECTION_NAME "*COM*"
5535796c8dcSSimon Schubert .#define BFD_IND_SECTION_NAME "*IND*"
5545796c8dcSSimon Schubert .
5555796c8dcSSimon Schubert .{* Pointer to the common section.  *}
556*ef5ccd6cSJohn Marino .#define bfd_com_section_ptr (&_bfd_std_section[0])
557*ef5ccd6cSJohn Marino .{* Pointer to the undefined section.  *}
558*ef5ccd6cSJohn Marino .#define bfd_und_section_ptr (&_bfd_std_section[1])
559*ef5ccd6cSJohn Marino .{* Pointer to the absolute section.  *}
560*ef5ccd6cSJohn Marino .#define bfd_abs_section_ptr (&_bfd_std_section[2])
5615796c8dcSSimon Schubert .{* Pointer to the indirect section.  *}
562*ef5ccd6cSJohn Marino .#define bfd_ind_section_ptr (&_bfd_std_section[3])
563*ef5ccd6cSJohn Marino .
564*ef5ccd6cSJohn Marino .#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
565*ef5ccd6cSJohn Marino .#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
5665796c8dcSSimon Schubert .#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
5675796c8dcSSimon Schubert .
5685796c8dcSSimon Schubert .#define bfd_is_const_section(SEC)		\
5695796c8dcSSimon Schubert . (   ((SEC) == bfd_abs_section_ptr)		\
5705796c8dcSSimon Schubert .  || ((SEC) == bfd_und_section_ptr)		\
5715796c8dcSSimon Schubert .  || ((SEC) == bfd_com_section_ptr)		\
5725796c8dcSSimon Schubert .  || ((SEC) == bfd_ind_section_ptr))
5735796c8dcSSimon Schubert .
5745796c8dcSSimon Schubert .{* Macros to handle insertion and deletion of a bfd's sections.  These
5755796c8dcSSimon Schubert .   only handle the list pointers, ie. do not adjust section_count,
5765796c8dcSSimon Schubert .   target_index etc.  *}
5775796c8dcSSimon Schubert .#define bfd_section_list_remove(ABFD, S) \
5785796c8dcSSimon Schubert .  do							\
5795796c8dcSSimon Schubert .    {							\
5805796c8dcSSimon Schubert .      asection *_s = S;				\
5815796c8dcSSimon Schubert .      asection *_next = _s->next;			\
5825796c8dcSSimon Schubert .      asection *_prev = _s->prev;			\
5835796c8dcSSimon Schubert .      if (_prev)					\
5845796c8dcSSimon Schubert .        _prev->next = _next;				\
5855796c8dcSSimon Schubert .      else						\
5865796c8dcSSimon Schubert .        (ABFD)->sections = _next;			\
5875796c8dcSSimon Schubert .      if (_next)					\
5885796c8dcSSimon Schubert .        _next->prev = _prev;				\
5895796c8dcSSimon Schubert .      else						\
5905796c8dcSSimon Schubert .        (ABFD)->section_last = _prev;			\
5915796c8dcSSimon Schubert .    }							\
5925796c8dcSSimon Schubert .  while (0)
5935796c8dcSSimon Schubert .#define bfd_section_list_append(ABFD, S) \
5945796c8dcSSimon Schubert .  do							\
5955796c8dcSSimon Schubert .    {							\
5965796c8dcSSimon Schubert .      asection *_s = S;				\
5975796c8dcSSimon Schubert .      bfd *_abfd = ABFD;				\
5985796c8dcSSimon Schubert .      _s->next = NULL;					\
5995796c8dcSSimon Schubert .      if (_abfd->section_last)				\
6005796c8dcSSimon Schubert .        {						\
6015796c8dcSSimon Schubert .          _s->prev = _abfd->section_last;		\
6025796c8dcSSimon Schubert .          _abfd->section_last->next = _s;		\
6035796c8dcSSimon Schubert .        }						\
6045796c8dcSSimon Schubert .      else						\
6055796c8dcSSimon Schubert .        {						\
6065796c8dcSSimon Schubert .          _s->prev = NULL;				\
6075796c8dcSSimon Schubert .          _abfd->sections = _s;			\
6085796c8dcSSimon Schubert .        }						\
6095796c8dcSSimon Schubert .      _abfd->section_last = _s;			\
6105796c8dcSSimon Schubert .    }							\
6115796c8dcSSimon Schubert .  while (0)
6125796c8dcSSimon Schubert .#define bfd_section_list_prepend(ABFD, S) \
6135796c8dcSSimon Schubert .  do							\
6145796c8dcSSimon Schubert .    {							\
6155796c8dcSSimon Schubert .      asection *_s = S;				\
6165796c8dcSSimon Schubert .      bfd *_abfd = ABFD;				\
6175796c8dcSSimon Schubert .      _s->prev = NULL;					\
6185796c8dcSSimon Schubert .      if (_abfd->sections)				\
6195796c8dcSSimon Schubert .        {						\
6205796c8dcSSimon Schubert .          _s->next = _abfd->sections;			\
6215796c8dcSSimon Schubert .          _abfd->sections->prev = _s;			\
6225796c8dcSSimon Schubert .        }						\
6235796c8dcSSimon Schubert .      else						\
6245796c8dcSSimon Schubert .        {						\
6255796c8dcSSimon Schubert .          _s->next = NULL;				\
6265796c8dcSSimon Schubert .          _abfd->section_last = _s;			\
6275796c8dcSSimon Schubert .        }						\
6285796c8dcSSimon Schubert .      _abfd->sections = _s;				\
6295796c8dcSSimon Schubert .    }							\
6305796c8dcSSimon Schubert .  while (0)
6315796c8dcSSimon Schubert .#define bfd_section_list_insert_after(ABFD, A, S) \
6325796c8dcSSimon Schubert .  do							\
6335796c8dcSSimon Schubert .    {							\
6345796c8dcSSimon Schubert .      asection *_a = A;				\
6355796c8dcSSimon Schubert .      asection *_s = S;				\
6365796c8dcSSimon Schubert .      asection *_next = _a->next;			\
6375796c8dcSSimon Schubert .      _s->next = _next;				\
6385796c8dcSSimon Schubert .      _s->prev = _a;					\
6395796c8dcSSimon Schubert .      _a->next = _s;					\
6405796c8dcSSimon Schubert .      if (_next)					\
6415796c8dcSSimon Schubert .        _next->prev = _s;				\
6425796c8dcSSimon Schubert .      else						\
6435796c8dcSSimon Schubert .        (ABFD)->section_last = _s;			\
6445796c8dcSSimon Schubert .    }							\
6455796c8dcSSimon Schubert .  while (0)
6465796c8dcSSimon Schubert .#define bfd_section_list_insert_before(ABFD, B, S) \
6475796c8dcSSimon Schubert .  do							\
6485796c8dcSSimon Schubert .    {							\
6495796c8dcSSimon Schubert .      asection *_b = B;				\
6505796c8dcSSimon Schubert .      asection *_s = S;				\
6515796c8dcSSimon Schubert .      asection *_prev = _b->prev;			\
6525796c8dcSSimon Schubert .      _s->prev = _prev;				\
6535796c8dcSSimon Schubert .      _s->next = _b;					\
6545796c8dcSSimon Schubert .      _b->prev = _s;					\
6555796c8dcSSimon Schubert .      if (_prev)					\
6565796c8dcSSimon Schubert .        _prev->next = _s;				\
6575796c8dcSSimon Schubert .      else						\
6585796c8dcSSimon Schubert .        (ABFD)->sections = _s;				\
6595796c8dcSSimon Schubert .    }							\
6605796c8dcSSimon Schubert .  while (0)
6615796c8dcSSimon Schubert .#define bfd_section_removed_from_list(ABFD, S) \
6625796c8dcSSimon Schubert .  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
6635796c8dcSSimon Schubert .
6645796c8dcSSimon Schubert .#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, NAME, IDX)			\
6655796c8dcSSimon Schubert .  {* name, id,  index, next, prev, flags, user_set_vma,            *}	\
6665796c8dcSSimon Schubert .  { NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,				\
6675796c8dcSSimon Schubert .									\
668c50c785cSJohn Marino .  {* linker_mark, linker_has_input, gc_mark, decompress_status,    *}	\
669cf7f2e2dSJohn Marino .     0,           0,                1,       0,			\
6705796c8dcSSimon Schubert .									\
671c50c785cSJohn Marino .  {* segment_mark, sec_info_type, use_rela_p,                      *}	\
672c50c785cSJohn Marino .     0,            0,             0,					\
6735796c8dcSSimon Schubert .									\
674cf7f2e2dSJohn Marino .  {* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5,   *}	\
675cf7f2e2dSJohn Marino .     0,        0,        0,        0,        0,        0,		\
6765796c8dcSSimon Schubert .									\
677c50c785cSJohn Marino .  {* vma, lma, size, rawsize, compressed_size, relax, relax_count, *}	\
678c50c785cSJohn Marino .     0,   0,   0,    0,       0,               0,     0,		\
6795796c8dcSSimon Schubert .									\
6805796c8dcSSimon Schubert .  {* output_offset, output_section, alignment_power,               *}	\
681*ef5ccd6cSJohn Marino .     0,             &SEC,           0,					\
6825796c8dcSSimon Schubert .									\
6835796c8dcSSimon Schubert .  {* relocation, orelocation, reloc_count, filepos, rel_filepos,   *}	\
6845796c8dcSSimon Schubert .     NULL,       NULL,        0,           0,       0,			\
6855796c8dcSSimon Schubert .									\
6865796c8dcSSimon Schubert .  {* line_filepos, userdata, contents, lineno, lineno_count,       *}	\
6875796c8dcSSimon Schubert .     0,            NULL,     NULL,     NULL,   0,			\
6885796c8dcSSimon Schubert .									\
6895796c8dcSSimon Schubert .  {* entsize, kept_section, moving_line_filepos,		     *}	\
6905796c8dcSSimon Schubert .     0,       NULL,	      0,					\
6915796c8dcSSimon Schubert .									\
6925796c8dcSSimon Schubert .  {* target_index, used_by_bfd, constructor_chain, owner,          *}	\
6935796c8dcSSimon Schubert .     0,            NULL,        NULL,              NULL,		\
6945796c8dcSSimon Schubert .									\
6955796c8dcSSimon Schubert .  {* symbol,                    symbol_ptr_ptr,                    *}	\
6965796c8dcSSimon Schubert .     (struct bfd_symbol *) SYM, &SEC.symbol,				\
6975796c8dcSSimon Schubert .									\
6985796c8dcSSimon Schubert .  {* map_head, map_tail                                            *}	\
6995796c8dcSSimon Schubert .     { NULL }, { NULL }						\
7005796c8dcSSimon Schubert .    }
7015796c8dcSSimon Schubert .
7025796c8dcSSimon Schubert */
7035796c8dcSSimon Schubert 
7045796c8dcSSimon Schubert /* We use a macro to initialize the static asymbol structures because
7055796c8dcSSimon Schubert    traditional C does not permit us to initialize a union member while
7065796c8dcSSimon Schubert    gcc warns if we don't initialize it.  */
7075796c8dcSSimon Schubert  /* the_bfd, name, value, attr, section [, udata] */
7085796c8dcSSimon Schubert #ifdef __STDC__
7095796c8dcSSimon Schubert #define GLOBAL_SYM_INIT(NAME, SECTION) \
710*ef5ccd6cSJohn Marino   { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }}
7115796c8dcSSimon Schubert #else
7125796c8dcSSimon Schubert #define GLOBAL_SYM_INIT(NAME, SECTION) \
713*ef5ccd6cSJohn Marino   { 0, NAME, 0, BSF_SECTION_SYM, SECTION }
7145796c8dcSSimon Schubert #endif
7155796c8dcSSimon Schubert 
7165796c8dcSSimon Schubert /* These symbols are global, not specific to any BFD.  Therefore, anything
7175796c8dcSSimon Schubert    that tries to change them is broken, and should be repaired.  */
7185796c8dcSSimon Schubert 
7195796c8dcSSimon Schubert static const asymbol global_syms[] =
7205796c8dcSSimon Schubert {
721*ef5ccd6cSJohn Marino   GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, bfd_com_section_ptr),
722*ef5ccd6cSJohn Marino   GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, bfd_und_section_ptr),
723*ef5ccd6cSJohn Marino   GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, bfd_abs_section_ptr),
724*ef5ccd6cSJohn Marino   GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, bfd_ind_section_ptr)
7255796c8dcSSimon Schubert };
7265796c8dcSSimon Schubert 
727*ef5ccd6cSJohn Marino #define STD_SECTION(NAME, IDX, FLAGS) \
728*ef5ccd6cSJohn Marino   BFD_FAKE_SECTION(_bfd_std_section[IDX], FLAGS, &global_syms[IDX], NAME, IDX)
7295796c8dcSSimon Schubert 
730*ef5ccd6cSJohn Marino asection _bfd_std_section[] = {
731*ef5ccd6cSJohn Marino   STD_SECTION (BFD_COM_SECTION_NAME, 0, SEC_IS_COMMON),
732*ef5ccd6cSJohn Marino   STD_SECTION (BFD_UND_SECTION_NAME, 1, 0),
733*ef5ccd6cSJohn Marino   STD_SECTION (BFD_ABS_SECTION_NAME, 2, 0),
734*ef5ccd6cSJohn Marino   STD_SECTION (BFD_IND_SECTION_NAME, 3, 0)
735*ef5ccd6cSJohn Marino };
7365796c8dcSSimon Schubert #undef STD_SECTION
7375796c8dcSSimon Schubert 
7385796c8dcSSimon Schubert /* Initialize an entry in the section hash table.  */
7395796c8dcSSimon Schubert 
7405796c8dcSSimon Schubert struct bfd_hash_entry *
bfd_section_hash_newfunc(struct bfd_hash_entry * entry,struct bfd_hash_table * table,const char * string)7415796c8dcSSimon Schubert bfd_section_hash_newfunc (struct bfd_hash_entry *entry,
7425796c8dcSSimon Schubert 			  struct bfd_hash_table *table,
7435796c8dcSSimon Schubert 			  const char *string)
7445796c8dcSSimon Schubert {
7455796c8dcSSimon Schubert   /* Allocate the structure if it has not already been allocated by a
7465796c8dcSSimon Schubert      subclass.  */
7475796c8dcSSimon Schubert   if (entry == NULL)
7485796c8dcSSimon Schubert     {
7495796c8dcSSimon Schubert       entry = (struct bfd_hash_entry *)
7505796c8dcSSimon Schubert 	bfd_hash_allocate (table, sizeof (struct section_hash_entry));
7515796c8dcSSimon Schubert       if (entry == NULL)
7525796c8dcSSimon Schubert 	return entry;
7535796c8dcSSimon Schubert     }
7545796c8dcSSimon Schubert 
7555796c8dcSSimon Schubert   /* Call the allocation method of the superclass.  */
7565796c8dcSSimon Schubert   entry = bfd_hash_newfunc (entry, table, string);
7575796c8dcSSimon Schubert   if (entry != NULL)
7585796c8dcSSimon Schubert     memset (&((struct section_hash_entry *) entry)->section, 0,
7595796c8dcSSimon Schubert 	    sizeof (asection));
7605796c8dcSSimon Schubert 
7615796c8dcSSimon Schubert   return entry;
7625796c8dcSSimon Schubert }
7635796c8dcSSimon Schubert 
7645796c8dcSSimon Schubert #define section_hash_lookup(table, string, create, copy) \
7655796c8dcSSimon Schubert   ((struct section_hash_entry *) \
7665796c8dcSSimon Schubert    bfd_hash_lookup ((table), (string), (create), (copy)))
7675796c8dcSSimon Schubert 
7685796c8dcSSimon Schubert /* Create a symbol whose only job is to point to this section.  This
7695796c8dcSSimon Schubert    is useful for things like relocs which are relative to the base
7705796c8dcSSimon Schubert    of a section.  */
7715796c8dcSSimon Schubert 
7725796c8dcSSimon Schubert bfd_boolean
_bfd_generic_new_section_hook(bfd * abfd,asection * newsect)7735796c8dcSSimon Schubert _bfd_generic_new_section_hook (bfd *abfd, asection *newsect)
7745796c8dcSSimon Schubert {
7755796c8dcSSimon Schubert   newsect->symbol = bfd_make_empty_symbol (abfd);
7765796c8dcSSimon Schubert   if (newsect->symbol == NULL)
7775796c8dcSSimon Schubert     return FALSE;
7785796c8dcSSimon Schubert 
7795796c8dcSSimon Schubert   newsect->symbol->name = newsect->name;
7805796c8dcSSimon Schubert   newsect->symbol->value = 0;
7815796c8dcSSimon Schubert   newsect->symbol->section = newsect;
7825796c8dcSSimon Schubert   newsect->symbol->flags = BSF_SECTION_SYM;
7835796c8dcSSimon Schubert 
7845796c8dcSSimon Schubert   newsect->symbol_ptr_ptr = &newsect->symbol;
7855796c8dcSSimon Schubert   return TRUE;
7865796c8dcSSimon Schubert }
7875796c8dcSSimon Schubert 
7885796c8dcSSimon Schubert /* Initializes a new section.  NEWSECT->NAME is already set.  */
7895796c8dcSSimon Schubert 
7905796c8dcSSimon Schubert static asection *
bfd_section_init(bfd * abfd,asection * newsect)7915796c8dcSSimon Schubert bfd_section_init (bfd *abfd, asection *newsect)
7925796c8dcSSimon Schubert {
7935796c8dcSSimon Schubert   static int section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */
7945796c8dcSSimon Schubert 
7955796c8dcSSimon Schubert   newsect->id = section_id;
7965796c8dcSSimon Schubert   newsect->index = abfd->section_count;
7975796c8dcSSimon Schubert   newsect->owner = abfd;
7985796c8dcSSimon Schubert 
7995796c8dcSSimon Schubert   if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
8005796c8dcSSimon Schubert     return NULL;
8015796c8dcSSimon Schubert 
8025796c8dcSSimon Schubert   section_id++;
8035796c8dcSSimon Schubert   abfd->section_count++;
8045796c8dcSSimon Schubert   bfd_section_list_append (abfd, newsect);
8055796c8dcSSimon Schubert   return newsect;
8065796c8dcSSimon Schubert }
8075796c8dcSSimon Schubert 
8085796c8dcSSimon Schubert /*
8095796c8dcSSimon Schubert DOCDD
8105796c8dcSSimon Schubert INODE
8115796c8dcSSimon Schubert section prototypes,  , typedef asection, Sections
8125796c8dcSSimon Schubert SUBSECTION
8135796c8dcSSimon Schubert 	Section prototypes
8145796c8dcSSimon Schubert 
8155796c8dcSSimon Schubert These are the functions exported by the section handling part of BFD.
8165796c8dcSSimon Schubert */
8175796c8dcSSimon Schubert 
8185796c8dcSSimon Schubert /*
8195796c8dcSSimon Schubert FUNCTION
8205796c8dcSSimon Schubert 	bfd_section_list_clear
8215796c8dcSSimon Schubert 
8225796c8dcSSimon Schubert SYNOPSIS
8235796c8dcSSimon Schubert 	void bfd_section_list_clear (bfd *);
8245796c8dcSSimon Schubert 
8255796c8dcSSimon Schubert DESCRIPTION
8265796c8dcSSimon Schubert 	Clears the section list, and also resets the section count and
8275796c8dcSSimon Schubert 	hash table entries.
8285796c8dcSSimon Schubert */
8295796c8dcSSimon Schubert 
8305796c8dcSSimon Schubert void
bfd_section_list_clear(bfd * abfd)8315796c8dcSSimon Schubert bfd_section_list_clear (bfd *abfd)
8325796c8dcSSimon Schubert {
8335796c8dcSSimon Schubert   abfd->sections = NULL;
8345796c8dcSSimon Schubert   abfd->section_last = NULL;
8355796c8dcSSimon Schubert   abfd->section_count = 0;
8365796c8dcSSimon Schubert   memset (abfd->section_htab.table, 0,
8375796c8dcSSimon Schubert 	  abfd->section_htab.size * sizeof (struct bfd_hash_entry *));
838*ef5ccd6cSJohn Marino   abfd->section_htab.count = 0;
8395796c8dcSSimon Schubert }
8405796c8dcSSimon Schubert 
8415796c8dcSSimon Schubert /*
8425796c8dcSSimon Schubert FUNCTION
8435796c8dcSSimon Schubert 	bfd_get_section_by_name
8445796c8dcSSimon Schubert 
8455796c8dcSSimon Schubert SYNOPSIS
8465796c8dcSSimon Schubert 	asection *bfd_get_section_by_name (bfd *abfd, const char *name);
8475796c8dcSSimon Schubert 
8485796c8dcSSimon Schubert DESCRIPTION
849*ef5ccd6cSJohn Marino 	Return the most recently created section attached to @var{abfd}
850*ef5ccd6cSJohn Marino 	named @var{name}.  Return NULL if no such section exists.
8515796c8dcSSimon Schubert */
8525796c8dcSSimon Schubert 
8535796c8dcSSimon Schubert asection *
bfd_get_section_by_name(bfd * abfd,const char * name)8545796c8dcSSimon Schubert bfd_get_section_by_name (bfd *abfd, const char *name)
8555796c8dcSSimon Schubert {
8565796c8dcSSimon Schubert   struct section_hash_entry *sh;
8575796c8dcSSimon Schubert 
8585796c8dcSSimon Schubert   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
8595796c8dcSSimon Schubert   if (sh != NULL)
8605796c8dcSSimon Schubert     return &sh->section;
8615796c8dcSSimon Schubert 
8625796c8dcSSimon Schubert   return NULL;
8635796c8dcSSimon Schubert }
8645796c8dcSSimon Schubert 
8655796c8dcSSimon Schubert /*
8665796c8dcSSimon Schubert FUNCTION
867*ef5ccd6cSJohn Marino        bfd_get_next_section_by_name
868*ef5ccd6cSJohn Marino 
869*ef5ccd6cSJohn Marino SYNOPSIS
870*ef5ccd6cSJohn Marino        asection *bfd_get_next_section_by_name (asection *sec);
871*ef5ccd6cSJohn Marino 
872*ef5ccd6cSJohn Marino DESCRIPTION
873*ef5ccd6cSJohn Marino        Given @var{sec} is a section returned by @code{bfd_get_section_by_name},
874*ef5ccd6cSJohn Marino        return the next most recently created section attached to the same
875*ef5ccd6cSJohn Marino        BFD with the same name.  Return NULL if no such section exists.
876*ef5ccd6cSJohn Marino */
877*ef5ccd6cSJohn Marino 
878*ef5ccd6cSJohn Marino asection *
bfd_get_next_section_by_name(asection * sec)879*ef5ccd6cSJohn Marino bfd_get_next_section_by_name (asection *sec)
880*ef5ccd6cSJohn Marino {
881*ef5ccd6cSJohn Marino   struct section_hash_entry *sh;
882*ef5ccd6cSJohn Marino   const char *name;
883*ef5ccd6cSJohn Marino   unsigned long hash;
884*ef5ccd6cSJohn Marino 
885*ef5ccd6cSJohn Marino   sh = ((struct section_hash_entry *)
886*ef5ccd6cSJohn Marino 	((char *) sec - offsetof (struct section_hash_entry, section)));
887*ef5ccd6cSJohn Marino 
888*ef5ccd6cSJohn Marino   hash = sh->root.hash;
889*ef5ccd6cSJohn Marino   name = sec->name;
890*ef5ccd6cSJohn Marino   for (sh = (struct section_hash_entry *) sh->root.next;
891*ef5ccd6cSJohn Marino        sh != NULL;
892*ef5ccd6cSJohn Marino        sh = (struct section_hash_entry *) sh->root.next)
893*ef5ccd6cSJohn Marino     if (sh->root.hash == hash
894*ef5ccd6cSJohn Marino        && strcmp (sh->root.string, name) == 0)
895*ef5ccd6cSJohn Marino       return &sh->section;
896*ef5ccd6cSJohn Marino 
897*ef5ccd6cSJohn Marino   return NULL;
898*ef5ccd6cSJohn Marino }
899*ef5ccd6cSJohn Marino 
900*ef5ccd6cSJohn Marino /*
901*ef5ccd6cSJohn Marino FUNCTION
902*ef5ccd6cSJohn Marino 	bfd_get_linker_section
903*ef5ccd6cSJohn Marino 
904*ef5ccd6cSJohn Marino SYNOPSIS
905*ef5ccd6cSJohn Marino 	asection *bfd_get_linker_section (bfd *abfd, const char *name);
906*ef5ccd6cSJohn Marino 
907*ef5ccd6cSJohn Marino DESCRIPTION
908*ef5ccd6cSJohn Marino 	Return the linker created section attached to @var{abfd}
909*ef5ccd6cSJohn Marino 	named @var{name}.  Return NULL if no such section exists.
910*ef5ccd6cSJohn Marino */
911*ef5ccd6cSJohn Marino 
912*ef5ccd6cSJohn Marino asection *
bfd_get_linker_section(bfd * abfd,const char * name)913*ef5ccd6cSJohn Marino bfd_get_linker_section (bfd *abfd, const char *name)
914*ef5ccd6cSJohn Marino {
915*ef5ccd6cSJohn Marino   asection *sec = bfd_get_section_by_name (abfd, name);
916*ef5ccd6cSJohn Marino 
917*ef5ccd6cSJohn Marino   while (sec != NULL && (sec->flags & SEC_LINKER_CREATED) == 0)
918*ef5ccd6cSJohn Marino     sec = bfd_get_next_section_by_name (sec);
919*ef5ccd6cSJohn Marino   return sec;
920*ef5ccd6cSJohn Marino }
921*ef5ccd6cSJohn Marino 
922*ef5ccd6cSJohn Marino /*
923*ef5ccd6cSJohn Marino FUNCTION
9245796c8dcSSimon Schubert 	bfd_get_section_by_name_if
9255796c8dcSSimon Schubert 
9265796c8dcSSimon Schubert SYNOPSIS
9275796c8dcSSimon Schubert 	asection *bfd_get_section_by_name_if
9285796c8dcSSimon Schubert 	  (bfd *abfd,
9295796c8dcSSimon Schubert 	   const char *name,
9305796c8dcSSimon Schubert 	   bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
9315796c8dcSSimon Schubert 	   void *obj);
9325796c8dcSSimon Schubert 
9335796c8dcSSimon Schubert DESCRIPTION
9345796c8dcSSimon Schubert 	Call the provided function @var{func} for each section
9355796c8dcSSimon Schubert 	attached to the BFD @var{abfd} whose name matches @var{name},
9365796c8dcSSimon Schubert 	passing @var{obj} as an argument. The function will be called
9375796c8dcSSimon Schubert 	as if by
9385796c8dcSSimon Schubert 
9395796c8dcSSimon Schubert |	func (abfd, the_section, obj);
9405796c8dcSSimon Schubert 
9415796c8dcSSimon Schubert 	It returns the first section for which @var{func} returns true,
9425796c8dcSSimon Schubert 	otherwise <<NULL>>.
9435796c8dcSSimon Schubert 
9445796c8dcSSimon Schubert */
9455796c8dcSSimon Schubert 
9465796c8dcSSimon Schubert asection *
bfd_get_section_by_name_if(bfd * abfd,const char * name,bfd_boolean (* operation)(bfd *,asection *,void *),void * user_storage)9475796c8dcSSimon Schubert bfd_get_section_by_name_if (bfd *abfd, const char *name,
9485796c8dcSSimon Schubert 			    bfd_boolean (*operation) (bfd *,
9495796c8dcSSimon Schubert 						      asection *,
9505796c8dcSSimon Schubert 						      void *),
9515796c8dcSSimon Schubert 			    void *user_storage)
9525796c8dcSSimon Schubert {
9535796c8dcSSimon Schubert   struct section_hash_entry *sh;
9545796c8dcSSimon Schubert   unsigned long hash;
9555796c8dcSSimon Schubert 
9565796c8dcSSimon Schubert   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
9575796c8dcSSimon Schubert   if (sh == NULL)
9585796c8dcSSimon Schubert     return NULL;
9595796c8dcSSimon Schubert 
9605796c8dcSSimon Schubert   hash = sh->root.hash;
9615796c8dcSSimon Schubert   do
9625796c8dcSSimon Schubert     {
9635796c8dcSSimon Schubert       if ((*operation) (abfd, &sh->section, user_storage))
9645796c8dcSSimon Schubert 	return &sh->section;
9655796c8dcSSimon Schubert       sh = (struct section_hash_entry *) sh->root.next;
9665796c8dcSSimon Schubert     }
9675796c8dcSSimon Schubert   while (sh != NULL && sh->root.hash == hash
9685796c8dcSSimon Schubert 	 && strcmp (sh->root.string, name) == 0);
9695796c8dcSSimon Schubert 
9705796c8dcSSimon Schubert   return NULL;
9715796c8dcSSimon Schubert }
9725796c8dcSSimon Schubert 
9735796c8dcSSimon Schubert /*
9745796c8dcSSimon Schubert FUNCTION
9755796c8dcSSimon Schubert 	bfd_get_unique_section_name
9765796c8dcSSimon Schubert 
9775796c8dcSSimon Schubert SYNOPSIS
9785796c8dcSSimon Schubert 	char *bfd_get_unique_section_name
9795796c8dcSSimon Schubert 	  (bfd *abfd, const char *templat, int *count);
9805796c8dcSSimon Schubert 
9815796c8dcSSimon Schubert DESCRIPTION
9825796c8dcSSimon Schubert 	Invent a section name that is unique in @var{abfd} by tacking
9835796c8dcSSimon Schubert 	a dot and a digit suffix onto the original @var{templat}.  If
9845796c8dcSSimon Schubert 	@var{count} is non-NULL, then it specifies the first number
9855796c8dcSSimon Schubert 	tried as a suffix to generate a unique name.  The value
9865796c8dcSSimon Schubert 	pointed to by @var{count} will be incremented in this case.
9875796c8dcSSimon Schubert */
9885796c8dcSSimon Schubert 
9895796c8dcSSimon Schubert char *
bfd_get_unique_section_name(bfd * abfd,const char * templat,int * count)9905796c8dcSSimon Schubert bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count)
9915796c8dcSSimon Schubert {
9925796c8dcSSimon Schubert   int num;
9935796c8dcSSimon Schubert   unsigned int len;
9945796c8dcSSimon Schubert   char *sname;
9955796c8dcSSimon Schubert 
9965796c8dcSSimon Schubert   len = strlen (templat);
9975796c8dcSSimon Schubert   sname = (char *) bfd_malloc (len + 8);
9985796c8dcSSimon Schubert   if (sname == NULL)
9995796c8dcSSimon Schubert     return NULL;
10005796c8dcSSimon Schubert   memcpy (sname, templat, len);
10015796c8dcSSimon Schubert   num = 1;
10025796c8dcSSimon Schubert   if (count != NULL)
10035796c8dcSSimon Schubert     num = *count;
10045796c8dcSSimon Schubert 
10055796c8dcSSimon Schubert   do
10065796c8dcSSimon Schubert     {
10075796c8dcSSimon Schubert       /* If we have a million sections, something is badly wrong.  */
10085796c8dcSSimon Schubert       if (num > 999999)
10095796c8dcSSimon Schubert 	abort ();
10105796c8dcSSimon Schubert       sprintf (sname + len, ".%d", num++);
10115796c8dcSSimon Schubert     }
10125796c8dcSSimon Schubert   while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE));
10135796c8dcSSimon Schubert 
10145796c8dcSSimon Schubert   if (count != NULL)
10155796c8dcSSimon Schubert     *count = num;
10165796c8dcSSimon Schubert   return sname;
10175796c8dcSSimon Schubert }
10185796c8dcSSimon Schubert 
10195796c8dcSSimon Schubert /*
10205796c8dcSSimon Schubert FUNCTION
10215796c8dcSSimon Schubert 	bfd_make_section_old_way
10225796c8dcSSimon Schubert 
10235796c8dcSSimon Schubert SYNOPSIS
10245796c8dcSSimon Schubert 	asection *bfd_make_section_old_way (bfd *abfd, const char *name);
10255796c8dcSSimon Schubert 
10265796c8dcSSimon Schubert DESCRIPTION
10275796c8dcSSimon Schubert 	Create a new empty section called @var{name}
10285796c8dcSSimon Schubert 	and attach it to the end of the chain of sections for the
10295796c8dcSSimon Schubert 	BFD @var{abfd}. An attempt to create a section with a name which
10305796c8dcSSimon Schubert 	is already in use returns its pointer without changing the
10315796c8dcSSimon Schubert 	section chain.
10325796c8dcSSimon Schubert 
10335796c8dcSSimon Schubert 	It has the funny name since this is the way it used to be
10345796c8dcSSimon Schubert 	before it was rewritten....
10355796c8dcSSimon Schubert 
10365796c8dcSSimon Schubert 	Possible errors are:
10375796c8dcSSimon Schubert 	o <<bfd_error_invalid_operation>> -
10385796c8dcSSimon Schubert 	If output has already started for this BFD.
10395796c8dcSSimon Schubert 	o <<bfd_error_no_memory>> -
10405796c8dcSSimon Schubert 	If memory allocation fails.
10415796c8dcSSimon Schubert 
10425796c8dcSSimon Schubert */
10435796c8dcSSimon Schubert 
10445796c8dcSSimon Schubert asection *
bfd_make_section_old_way(bfd * abfd,const char * name)10455796c8dcSSimon Schubert bfd_make_section_old_way (bfd *abfd, const char *name)
10465796c8dcSSimon Schubert {
10475796c8dcSSimon Schubert   asection *newsect;
10485796c8dcSSimon Schubert 
10495796c8dcSSimon Schubert   if (abfd->output_has_begun)
10505796c8dcSSimon Schubert     {
10515796c8dcSSimon Schubert       bfd_set_error (bfd_error_invalid_operation);
10525796c8dcSSimon Schubert       return NULL;
10535796c8dcSSimon Schubert     }
10545796c8dcSSimon Schubert 
10555796c8dcSSimon Schubert   if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
10565796c8dcSSimon Schubert     newsect = bfd_abs_section_ptr;
10575796c8dcSSimon Schubert   else if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
10585796c8dcSSimon Schubert     newsect = bfd_com_section_ptr;
10595796c8dcSSimon Schubert   else if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
10605796c8dcSSimon Schubert     newsect = bfd_und_section_ptr;
10615796c8dcSSimon Schubert   else if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
10625796c8dcSSimon Schubert     newsect = bfd_ind_section_ptr;
10635796c8dcSSimon Schubert   else
10645796c8dcSSimon Schubert     {
10655796c8dcSSimon Schubert       struct section_hash_entry *sh;
10665796c8dcSSimon Schubert 
10675796c8dcSSimon Schubert       sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
10685796c8dcSSimon Schubert       if (sh == NULL)
10695796c8dcSSimon Schubert 	return NULL;
10705796c8dcSSimon Schubert 
10715796c8dcSSimon Schubert       newsect = &sh->section;
10725796c8dcSSimon Schubert       if (newsect->name != NULL)
10735796c8dcSSimon Schubert 	{
10745796c8dcSSimon Schubert 	  /* Section already exists.  */
10755796c8dcSSimon Schubert 	  return newsect;
10765796c8dcSSimon Schubert 	}
10775796c8dcSSimon Schubert 
10785796c8dcSSimon Schubert       newsect->name = name;
10795796c8dcSSimon Schubert       return bfd_section_init (abfd, newsect);
10805796c8dcSSimon Schubert     }
10815796c8dcSSimon Schubert 
10825796c8dcSSimon Schubert   /* Call new_section_hook when "creating" the standard abs, com, und
10835796c8dcSSimon Schubert      and ind sections to tack on format specific section data.
10845796c8dcSSimon Schubert      Also, create a proper section symbol.  */
10855796c8dcSSimon Schubert   if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
10865796c8dcSSimon Schubert     return NULL;
10875796c8dcSSimon Schubert   return newsect;
10885796c8dcSSimon Schubert }
10895796c8dcSSimon Schubert 
10905796c8dcSSimon Schubert /*
10915796c8dcSSimon Schubert FUNCTION
10925796c8dcSSimon Schubert 	bfd_make_section_anyway_with_flags
10935796c8dcSSimon Schubert 
10945796c8dcSSimon Schubert SYNOPSIS
10955796c8dcSSimon Schubert 	asection *bfd_make_section_anyway_with_flags
10965796c8dcSSimon Schubert 	  (bfd *abfd, const char *name, flagword flags);
10975796c8dcSSimon Schubert 
10985796c8dcSSimon Schubert DESCRIPTION
10995796c8dcSSimon Schubert    Create a new empty section called @var{name} and attach it to the end of
11005796c8dcSSimon Schubert    the chain of sections for @var{abfd}.  Create a new section even if there
11015796c8dcSSimon Schubert    is already a section with that name.  Also set the attributes of the
11025796c8dcSSimon Schubert    new section to the value @var{flags}.
11035796c8dcSSimon Schubert 
11045796c8dcSSimon Schubert    Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
11055796c8dcSSimon Schubert    o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
11065796c8dcSSimon Schubert    o <<bfd_error_no_memory>> - If memory allocation fails.
11075796c8dcSSimon Schubert */
11085796c8dcSSimon Schubert 
11095796c8dcSSimon Schubert sec_ptr
bfd_make_section_anyway_with_flags(bfd * abfd,const char * name,flagword flags)11105796c8dcSSimon Schubert bfd_make_section_anyway_with_flags (bfd *abfd, const char *name,
11115796c8dcSSimon Schubert 				    flagword flags)
11125796c8dcSSimon Schubert {
11135796c8dcSSimon Schubert   struct section_hash_entry *sh;
11145796c8dcSSimon Schubert   asection *newsect;
11155796c8dcSSimon Schubert 
11165796c8dcSSimon Schubert   if (abfd->output_has_begun)
11175796c8dcSSimon Schubert     {
11185796c8dcSSimon Schubert       bfd_set_error (bfd_error_invalid_operation);
11195796c8dcSSimon Schubert       return NULL;
11205796c8dcSSimon Schubert     }
11215796c8dcSSimon Schubert 
11225796c8dcSSimon Schubert   sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
11235796c8dcSSimon Schubert   if (sh == NULL)
11245796c8dcSSimon Schubert     return NULL;
11255796c8dcSSimon Schubert 
11265796c8dcSSimon Schubert   newsect = &sh->section;
11275796c8dcSSimon Schubert   if (newsect->name != NULL)
11285796c8dcSSimon Schubert     {
11295796c8dcSSimon Schubert       /* We are making a section of the same name.  Put it in the
11305796c8dcSSimon Schubert 	 section hash table.  Even though we can't find it directly by a
11315796c8dcSSimon Schubert 	 hash lookup, we'll be able to find the section by traversing
11325796c8dcSSimon Schubert 	 sh->root.next quicker than looking at all the bfd sections.  */
11335796c8dcSSimon Schubert       struct section_hash_entry *new_sh;
11345796c8dcSSimon Schubert       new_sh = (struct section_hash_entry *)
11355796c8dcSSimon Schubert 	bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
11365796c8dcSSimon Schubert       if (new_sh == NULL)
11375796c8dcSSimon Schubert 	return NULL;
11385796c8dcSSimon Schubert 
11395796c8dcSSimon Schubert       new_sh->root = sh->root;
11405796c8dcSSimon Schubert       sh->root.next = &new_sh->root;
11415796c8dcSSimon Schubert       newsect = &new_sh->section;
11425796c8dcSSimon Schubert     }
11435796c8dcSSimon Schubert 
11445796c8dcSSimon Schubert   newsect->flags = flags;
11455796c8dcSSimon Schubert   newsect->name = name;
11465796c8dcSSimon Schubert   return bfd_section_init (abfd, newsect);
11475796c8dcSSimon Schubert }
11485796c8dcSSimon Schubert 
11495796c8dcSSimon Schubert /*
11505796c8dcSSimon Schubert FUNCTION
11515796c8dcSSimon Schubert 	bfd_make_section_anyway
11525796c8dcSSimon Schubert 
11535796c8dcSSimon Schubert SYNOPSIS
11545796c8dcSSimon Schubert 	asection *bfd_make_section_anyway (bfd *abfd, const char *name);
11555796c8dcSSimon Schubert 
11565796c8dcSSimon Schubert DESCRIPTION
11575796c8dcSSimon Schubert    Create a new empty section called @var{name} and attach it to the end of
11585796c8dcSSimon Schubert    the chain of sections for @var{abfd}.  Create a new section even if there
11595796c8dcSSimon Schubert    is already a section with that name.
11605796c8dcSSimon Schubert 
11615796c8dcSSimon Schubert    Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
11625796c8dcSSimon Schubert    o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
11635796c8dcSSimon Schubert    o <<bfd_error_no_memory>> - If memory allocation fails.
11645796c8dcSSimon Schubert */
11655796c8dcSSimon Schubert 
11665796c8dcSSimon Schubert sec_ptr
bfd_make_section_anyway(bfd * abfd,const char * name)11675796c8dcSSimon Schubert bfd_make_section_anyway (bfd *abfd, const char *name)
11685796c8dcSSimon Schubert {
11695796c8dcSSimon Schubert   return bfd_make_section_anyway_with_flags (abfd, name, 0);
11705796c8dcSSimon Schubert }
11715796c8dcSSimon Schubert 
11725796c8dcSSimon Schubert /*
11735796c8dcSSimon Schubert FUNCTION
11745796c8dcSSimon Schubert 	bfd_make_section_with_flags
11755796c8dcSSimon Schubert 
11765796c8dcSSimon Schubert SYNOPSIS
11775796c8dcSSimon Schubert 	asection *bfd_make_section_with_flags
11785796c8dcSSimon Schubert 	  (bfd *, const char *name, flagword flags);
11795796c8dcSSimon Schubert 
11805796c8dcSSimon Schubert DESCRIPTION
11815796c8dcSSimon Schubert    Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
11825796c8dcSSimon Schubert    bfd_set_error ()) without changing the section chain if there is already a
11835796c8dcSSimon Schubert    section named @var{name}.  Also set the attributes of the new section to
11845796c8dcSSimon Schubert    the value @var{flags}.  If there is an error, return <<NULL>> and set
11855796c8dcSSimon Schubert    <<bfd_error>>.
11865796c8dcSSimon Schubert */
11875796c8dcSSimon Schubert 
11885796c8dcSSimon Schubert asection *
bfd_make_section_with_flags(bfd * abfd,const char * name,flagword flags)11895796c8dcSSimon Schubert bfd_make_section_with_flags (bfd *abfd, const char *name,
11905796c8dcSSimon Schubert 			     flagword flags)
11915796c8dcSSimon Schubert {
11925796c8dcSSimon Schubert   struct section_hash_entry *sh;
11935796c8dcSSimon Schubert   asection *newsect;
11945796c8dcSSimon Schubert 
11955796c8dcSSimon Schubert   if (abfd->output_has_begun)
11965796c8dcSSimon Schubert     {
11975796c8dcSSimon Schubert       bfd_set_error (bfd_error_invalid_operation);
11985796c8dcSSimon Schubert       return NULL;
11995796c8dcSSimon Schubert     }
12005796c8dcSSimon Schubert 
12015796c8dcSSimon Schubert   if (strcmp (name, BFD_ABS_SECTION_NAME) == 0
12025796c8dcSSimon Schubert       || strcmp (name, BFD_COM_SECTION_NAME) == 0
12035796c8dcSSimon Schubert       || strcmp (name, BFD_UND_SECTION_NAME) == 0
12045796c8dcSSimon Schubert       || strcmp (name, BFD_IND_SECTION_NAME) == 0)
12055796c8dcSSimon Schubert     return NULL;
12065796c8dcSSimon Schubert 
12075796c8dcSSimon Schubert   sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
12085796c8dcSSimon Schubert   if (sh == NULL)
12095796c8dcSSimon Schubert     return NULL;
12105796c8dcSSimon Schubert 
12115796c8dcSSimon Schubert   newsect = &sh->section;
12125796c8dcSSimon Schubert   if (newsect->name != NULL)
12135796c8dcSSimon Schubert     {
12145796c8dcSSimon Schubert       /* Section already exists.  */
12155796c8dcSSimon Schubert       return NULL;
12165796c8dcSSimon Schubert     }
12175796c8dcSSimon Schubert 
12185796c8dcSSimon Schubert   newsect->name = name;
12195796c8dcSSimon Schubert   newsect->flags = flags;
12205796c8dcSSimon Schubert   return bfd_section_init (abfd, newsect);
12215796c8dcSSimon Schubert }
12225796c8dcSSimon Schubert 
12235796c8dcSSimon Schubert /*
12245796c8dcSSimon Schubert FUNCTION
12255796c8dcSSimon Schubert 	bfd_make_section
12265796c8dcSSimon Schubert 
12275796c8dcSSimon Schubert SYNOPSIS
12285796c8dcSSimon Schubert 	asection *bfd_make_section (bfd *, const char *name);
12295796c8dcSSimon Schubert 
12305796c8dcSSimon Schubert DESCRIPTION
12315796c8dcSSimon Schubert    Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
12325796c8dcSSimon Schubert    bfd_set_error ()) without changing the section chain if there is already a
12335796c8dcSSimon Schubert    section named @var{name}.  If there is an error, return <<NULL>> and set
12345796c8dcSSimon Schubert    <<bfd_error>>.
12355796c8dcSSimon Schubert */
12365796c8dcSSimon Schubert 
12375796c8dcSSimon Schubert asection *
bfd_make_section(bfd * abfd,const char * name)12385796c8dcSSimon Schubert bfd_make_section (bfd *abfd, const char *name)
12395796c8dcSSimon Schubert {
12405796c8dcSSimon Schubert   return bfd_make_section_with_flags (abfd, name, 0);
12415796c8dcSSimon Schubert }
12425796c8dcSSimon Schubert 
12435796c8dcSSimon Schubert /*
12445796c8dcSSimon Schubert FUNCTION
12455796c8dcSSimon Schubert 	bfd_set_section_flags
12465796c8dcSSimon Schubert 
12475796c8dcSSimon Schubert SYNOPSIS
12485796c8dcSSimon Schubert 	bfd_boolean bfd_set_section_flags
12495796c8dcSSimon Schubert 	  (bfd *abfd, asection *sec, flagword flags);
12505796c8dcSSimon Schubert 
12515796c8dcSSimon Schubert DESCRIPTION
12525796c8dcSSimon Schubert 	Set the attributes of the section @var{sec} in the BFD
12535796c8dcSSimon Schubert 	@var{abfd} to the value @var{flags}. Return <<TRUE>> on success,
12545796c8dcSSimon Schubert 	<<FALSE>> on error. Possible error returns are:
12555796c8dcSSimon Schubert 
12565796c8dcSSimon Schubert 	o <<bfd_error_invalid_operation>> -
12575796c8dcSSimon Schubert 	The section cannot have one or more of the attributes
12585796c8dcSSimon Schubert 	requested. For example, a .bss section in <<a.out>> may not
12595796c8dcSSimon Schubert 	have the <<SEC_HAS_CONTENTS>> field set.
12605796c8dcSSimon Schubert 
12615796c8dcSSimon Schubert */
12625796c8dcSSimon Schubert 
12635796c8dcSSimon Schubert bfd_boolean
bfd_set_section_flags(bfd * abfd ATTRIBUTE_UNUSED,sec_ptr section,flagword flags)12645796c8dcSSimon Schubert bfd_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
12655796c8dcSSimon Schubert 		       sec_ptr section,
12665796c8dcSSimon Schubert 		       flagword flags)
12675796c8dcSSimon Schubert {
12685796c8dcSSimon Schubert   section->flags = flags;
12695796c8dcSSimon Schubert   return TRUE;
12705796c8dcSSimon Schubert }
12715796c8dcSSimon Schubert 
12725796c8dcSSimon Schubert /*
12735796c8dcSSimon Schubert FUNCTION
1274c50c785cSJohn Marino 	bfd_rename_section
1275c50c785cSJohn Marino 
1276c50c785cSJohn Marino SYNOPSIS
1277c50c785cSJohn Marino 	void bfd_rename_section
1278c50c785cSJohn Marino 	  (bfd *abfd, asection *sec, const char *newname);
1279c50c785cSJohn Marino 
1280c50c785cSJohn Marino DESCRIPTION
1281c50c785cSJohn Marino 	Rename section @var{sec} in @var{abfd} to @var{newname}.
1282c50c785cSJohn Marino */
1283c50c785cSJohn Marino 
1284c50c785cSJohn Marino void
bfd_rename_section(bfd * abfd,sec_ptr sec,const char * newname)1285c50c785cSJohn Marino bfd_rename_section (bfd *abfd, sec_ptr sec, const char *newname)
1286c50c785cSJohn Marino {
1287c50c785cSJohn Marino   struct section_hash_entry *sh;
1288c50c785cSJohn Marino 
1289c50c785cSJohn Marino   sh = (struct section_hash_entry *)
1290c50c785cSJohn Marino     ((char *) sec - offsetof (struct section_hash_entry, section));
1291c50c785cSJohn Marino   sh->section.name = newname;
1292c50c785cSJohn Marino   bfd_hash_rename (&abfd->section_htab, newname, &sh->root);
1293c50c785cSJohn Marino }
1294c50c785cSJohn Marino 
1295c50c785cSJohn Marino /*
1296c50c785cSJohn Marino FUNCTION
12975796c8dcSSimon Schubert 	bfd_map_over_sections
12985796c8dcSSimon Schubert 
12995796c8dcSSimon Schubert SYNOPSIS
13005796c8dcSSimon Schubert 	void bfd_map_over_sections
13015796c8dcSSimon Schubert 	  (bfd *abfd,
13025796c8dcSSimon Schubert 	   void (*func) (bfd *abfd, asection *sect, void *obj),
13035796c8dcSSimon Schubert 	   void *obj);
13045796c8dcSSimon Schubert 
13055796c8dcSSimon Schubert DESCRIPTION
13065796c8dcSSimon Schubert 	Call the provided function @var{func} for each section
13075796c8dcSSimon Schubert 	attached to the BFD @var{abfd}, passing @var{obj} as an
13085796c8dcSSimon Schubert 	argument. The function will be called as if by
13095796c8dcSSimon Schubert 
13105796c8dcSSimon Schubert |	func (abfd, the_section, obj);
13115796c8dcSSimon Schubert 
13125796c8dcSSimon Schubert 	This is the preferred method for iterating over sections; an
13135796c8dcSSimon Schubert 	alternative would be to use a loop:
13145796c8dcSSimon Schubert 
1315*ef5ccd6cSJohn Marino |	   asection *p;
13165796c8dcSSimon Schubert |	   for (p = abfd->sections; p != NULL; p = p->next)
13175796c8dcSSimon Schubert |	      func (abfd, p, ...)
13185796c8dcSSimon Schubert 
13195796c8dcSSimon Schubert */
13205796c8dcSSimon Schubert 
13215796c8dcSSimon Schubert void
bfd_map_over_sections(bfd * abfd,void (* operation)(bfd *,asection *,void *),void * user_storage)13225796c8dcSSimon Schubert bfd_map_over_sections (bfd *abfd,
13235796c8dcSSimon Schubert 		       void (*operation) (bfd *, asection *, void *),
13245796c8dcSSimon Schubert 		       void *user_storage)
13255796c8dcSSimon Schubert {
13265796c8dcSSimon Schubert   asection *sect;
13275796c8dcSSimon Schubert   unsigned int i = 0;
13285796c8dcSSimon Schubert 
13295796c8dcSSimon Schubert   for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
13305796c8dcSSimon Schubert     (*operation) (abfd, sect, user_storage);
13315796c8dcSSimon Schubert 
13325796c8dcSSimon Schubert   if (i != abfd->section_count)	/* Debugging */
13335796c8dcSSimon Schubert     abort ();
13345796c8dcSSimon Schubert }
13355796c8dcSSimon Schubert 
13365796c8dcSSimon Schubert /*
13375796c8dcSSimon Schubert FUNCTION
13385796c8dcSSimon Schubert 	bfd_sections_find_if
13395796c8dcSSimon Schubert 
13405796c8dcSSimon Schubert SYNOPSIS
13415796c8dcSSimon Schubert 	asection *bfd_sections_find_if
13425796c8dcSSimon Schubert 	  (bfd *abfd,
13435796c8dcSSimon Schubert 	   bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
13445796c8dcSSimon Schubert 	   void *obj);
13455796c8dcSSimon Schubert 
13465796c8dcSSimon Schubert DESCRIPTION
13475796c8dcSSimon Schubert 	Call the provided function @var{operation} for each section
13485796c8dcSSimon Schubert 	attached to the BFD @var{abfd}, passing @var{obj} as an
13495796c8dcSSimon Schubert 	argument. The function will be called as if by
13505796c8dcSSimon Schubert 
13515796c8dcSSimon Schubert |	operation (abfd, the_section, obj);
13525796c8dcSSimon Schubert 
13535796c8dcSSimon Schubert 	It returns the first section for which @var{operation} returns true.
13545796c8dcSSimon Schubert 
13555796c8dcSSimon Schubert */
13565796c8dcSSimon Schubert 
13575796c8dcSSimon Schubert asection *
bfd_sections_find_if(bfd * abfd,bfd_boolean (* operation)(bfd *,asection *,void *),void * user_storage)13585796c8dcSSimon Schubert bfd_sections_find_if (bfd *abfd,
13595796c8dcSSimon Schubert 		      bfd_boolean (*operation) (bfd *, asection *, void *),
13605796c8dcSSimon Schubert 		      void *user_storage)
13615796c8dcSSimon Schubert {
13625796c8dcSSimon Schubert   asection *sect;
13635796c8dcSSimon Schubert 
13645796c8dcSSimon Schubert   for (sect = abfd->sections; sect != NULL; sect = sect->next)
13655796c8dcSSimon Schubert     if ((*operation) (abfd, sect, user_storage))
13665796c8dcSSimon Schubert       break;
13675796c8dcSSimon Schubert 
13685796c8dcSSimon Schubert   return sect;
13695796c8dcSSimon Schubert }
13705796c8dcSSimon Schubert 
13715796c8dcSSimon Schubert /*
13725796c8dcSSimon Schubert FUNCTION
13735796c8dcSSimon Schubert 	bfd_set_section_size
13745796c8dcSSimon Schubert 
13755796c8dcSSimon Schubert SYNOPSIS
13765796c8dcSSimon Schubert 	bfd_boolean bfd_set_section_size
13775796c8dcSSimon Schubert 	  (bfd *abfd, asection *sec, bfd_size_type val);
13785796c8dcSSimon Schubert 
13795796c8dcSSimon Schubert DESCRIPTION
13805796c8dcSSimon Schubert 	Set @var{sec} to the size @var{val}. If the operation is
13815796c8dcSSimon Schubert 	ok, then <<TRUE>> is returned, else <<FALSE>>.
13825796c8dcSSimon Schubert 
13835796c8dcSSimon Schubert 	Possible error returns:
13845796c8dcSSimon Schubert 	o <<bfd_error_invalid_operation>> -
13855796c8dcSSimon Schubert 	Writing has started to the BFD, so setting the size is invalid.
13865796c8dcSSimon Schubert 
13875796c8dcSSimon Schubert */
13885796c8dcSSimon Schubert 
13895796c8dcSSimon Schubert bfd_boolean
bfd_set_section_size(bfd * abfd,sec_ptr ptr,bfd_size_type val)13905796c8dcSSimon Schubert bfd_set_section_size (bfd *abfd, sec_ptr ptr, bfd_size_type val)
13915796c8dcSSimon Schubert {
13925796c8dcSSimon Schubert   /* Once you've started writing to any section you cannot create or change
13935796c8dcSSimon Schubert      the size of any others.  */
13945796c8dcSSimon Schubert 
13955796c8dcSSimon Schubert   if (abfd->output_has_begun)
13965796c8dcSSimon Schubert     {
13975796c8dcSSimon Schubert       bfd_set_error (bfd_error_invalid_operation);
13985796c8dcSSimon Schubert       return FALSE;
13995796c8dcSSimon Schubert     }
14005796c8dcSSimon Schubert 
14015796c8dcSSimon Schubert   ptr->size = val;
14025796c8dcSSimon Schubert   return TRUE;
14035796c8dcSSimon Schubert }
14045796c8dcSSimon Schubert 
14055796c8dcSSimon Schubert /*
14065796c8dcSSimon Schubert FUNCTION
14075796c8dcSSimon Schubert 	bfd_set_section_contents
14085796c8dcSSimon Schubert 
14095796c8dcSSimon Schubert SYNOPSIS
14105796c8dcSSimon Schubert 	bfd_boolean bfd_set_section_contents
14115796c8dcSSimon Schubert 	  (bfd *abfd, asection *section, const void *data,
14125796c8dcSSimon Schubert 	   file_ptr offset, bfd_size_type count);
14135796c8dcSSimon Schubert 
14145796c8dcSSimon Schubert DESCRIPTION
14155796c8dcSSimon Schubert 	Sets the contents of the section @var{section} in BFD
14165796c8dcSSimon Schubert 	@var{abfd} to the data starting in memory at @var{data}. The
14175796c8dcSSimon Schubert 	data is written to the output section starting at offset
14185796c8dcSSimon Schubert 	@var{offset} for @var{count} octets.
14195796c8dcSSimon Schubert 
14205796c8dcSSimon Schubert 	Normally <<TRUE>> is returned, else <<FALSE>>. Possible error
14215796c8dcSSimon Schubert 	returns are:
14225796c8dcSSimon Schubert 	o <<bfd_error_no_contents>> -
14235796c8dcSSimon Schubert 	The output section does not have the <<SEC_HAS_CONTENTS>>
14245796c8dcSSimon Schubert 	attribute, so nothing can be written to it.
14255796c8dcSSimon Schubert 	o and some more too
14265796c8dcSSimon Schubert 
14275796c8dcSSimon Schubert 	This routine is front end to the back end function
14285796c8dcSSimon Schubert 	<<_bfd_set_section_contents>>.
14295796c8dcSSimon Schubert 
14305796c8dcSSimon Schubert */
14315796c8dcSSimon Schubert 
14325796c8dcSSimon Schubert bfd_boolean
bfd_set_section_contents(bfd * abfd,sec_ptr section,const void * location,file_ptr offset,bfd_size_type count)14335796c8dcSSimon Schubert bfd_set_section_contents (bfd *abfd,
14345796c8dcSSimon Schubert 			  sec_ptr section,
14355796c8dcSSimon Schubert 			  const void *location,
14365796c8dcSSimon Schubert 			  file_ptr offset,
14375796c8dcSSimon Schubert 			  bfd_size_type count)
14385796c8dcSSimon Schubert {
14395796c8dcSSimon Schubert   bfd_size_type sz;
14405796c8dcSSimon Schubert 
14415796c8dcSSimon Schubert   if (!(bfd_get_section_flags (abfd, section) & SEC_HAS_CONTENTS))
14425796c8dcSSimon Schubert     {
14435796c8dcSSimon Schubert       bfd_set_error (bfd_error_no_contents);
14445796c8dcSSimon Schubert       return FALSE;
14455796c8dcSSimon Schubert     }
14465796c8dcSSimon Schubert 
14475796c8dcSSimon Schubert   sz = section->size;
14485796c8dcSSimon Schubert   if ((bfd_size_type) offset > sz
14495796c8dcSSimon Schubert       || count > sz
14505796c8dcSSimon Schubert       || offset + count > sz
14515796c8dcSSimon Schubert       || count != (size_t) count)
14525796c8dcSSimon Schubert     {
14535796c8dcSSimon Schubert       bfd_set_error (bfd_error_bad_value);
14545796c8dcSSimon Schubert       return FALSE;
14555796c8dcSSimon Schubert     }
14565796c8dcSSimon Schubert 
14575796c8dcSSimon Schubert   if (!bfd_write_p (abfd))
14585796c8dcSSimon Schubert     {
14595796c8dcSSimon Schubert       bfd_set_error (bfd_error_invalid_operation);
14605796c8dcSSimon Schubert       return FALSE;
14615796c8dcSSimon Schubert     }
14625796c8dcSSimon Schubert 
14635796c8dcSSimon Schubert   /* Record a copy of the data in memory if desired.  */
14645796c8dcSSimon Schubert   if (section->contents
14655796c8dcSSimon Schubert       && location != section->contents + offset)
14665796c8dcSSimon Schubert     memcpy (section->contents + offset, location, (size_t) count);
14675796c8dcSSimon Schubert 
14685796c8dcSSimon Schubert   if (BFD_SEND (abfd, _bfd_set_section_contents,
14695796c8dcSSimon Schubert 		(abfd, section, location, offset, count)))
14705796c8dcSSimon Schubert     {
14715796c8dcSSimon Schubert       abfd->output_has_begun = TRUE;
14725796c8dcSSimon Schubert       return TRUE;
14735796c8dcSSimon Schubert     }
14745796c8dcSSimon Schubert 
14755796c8dcSSimon Schubert   return FALSE;
14765796c8dcSSimon Schubert }
14775796c8dcSSimon Schubert 
14785796c8dcSSimon Schubert /*
14795796c8dcSSimon Schubert FUNCTION
14805796c8dcSSimon Schubert 	bfd_get_section_contents
14815796c8dcSSimon Schubert 
14825796c8dcSSimon Schubert SYNOPSIS
14835796c8dcSSimon Schubert 	bfd_boolean bfd_get_section_contents
14845796c8dcSSimon Schubert 	  (bfd *abfd, asection *section, void *location, file_ptr offset,
14855796c8dcSSimon Schubert 	   bfd_size_type count);
14865796c8dcSSimon Schubert 
14875796c8dcSSimon Schubert DESCRIPTION
14885796c8dcSSimon Schubert 	Read data from @var{section} in BFD @var{abfd}
14895796c8dcSSimon Schubert 	into memory starting at @var{location}. The data is read at an
14905796c8dcSSimon Schubert 	offset of @var{offset} from the start of the input section,
14915796c8dcSSimon Schubert 	and is read for @var{count} bytes.
14925796c8dcSSimon Schubert 
14935796c8dcSSimon Schubert 	If the contents of a constructor with the <<SEC_CONSTRUCTOR>>
14945796c8dcSSimon Schubert 	flag set are requested or if the section does not have the
14955796c8dcSSimon Schubert 	<<SEC_HAS_CONTENTS>> flag set, then the @var{location} is filled
14965796c8dcSSimon Schubert 	with zeroes. If no errors occur, <<TRUE>> is returned, else
14975796c8dcSSimon Schubert 	<<FALSE>>.
14985796c8dcSSimon Schubert 
14995796c8dcSSimon Schubert */
15005796c8dcSSimon Schubert bfd_boolean
bfd_get_section_contents(bfd * abfd,sec_ptr section,void * location,file_ptr offset,bfd_size_type count)15015796c8dcSSimon Schubert bfd_get_section_contents (bfd *abfd,
15025796c8dcSSimon Schubert 			  sec_ptr section,
15035796c8dcSSimon Schubert 			  void *location,
15045796c8dcSSimon Schubert 			  file_ptr offset,
15055796c8dcSSimon Schubert 			  bfd_size_type count)
15065796c8dcSSimon Schubert {
15075796c8dcSSimon Schubert   bfd_size_type sz;
15085796c8dcSSimon Schubert 
15095796c8dcSSimon Schubert   if (section->flags & SEC_CONSTRUCTOR)
15105796c8dcSSimon Schubert     {
15115796c8dcSSimon Schubert       memset (location, 0, (size_t) count);
15125796c8dcSSimon Schubert       return TRUE;
15135796c8dcSSimon Schubert     }
15145796c8dcSSimon Schubert 
1515a45ae5f8SJohn Marino   if (abfd->direction != write_direction && section->rawsize != 0)
1516a45ae5f8SJohn Marino     sz = section->rawsize;
1517a45ae5f8SJohn Marino   else
1518a45ae5f8SJohn Marino     sz = section->size;
15195796c8dcSSimon Schubert   if ((bfd_size_type) offset > sz
15205796c8dcSSimon Schubert       || count > sz
15215796c8dcSSimon Schubert       || offset + count > sz
15225796c8dcSSimon Schubert       || count != (size_t) count)
15235796c8dcSSimon Schubert     {
15245796c8dcSSimon Schubert       bfd_set_error (bfd_error_bad_value);
15255796c8dcSSimon Schubert       return FALSE;
15265796c8dcSSimon Schubert     }
15275796c8dcSSimon Schubert 
15285796c8dcSSimon Schubert   if (count == 0)
15295796c8dcSSimon Schubert     /* Don't bother.  */
15305796c8dcSSimon Schubert     return TRUE;
15315796c8dcSSimon Schubert 
15325796c8dcSSimon Schubert   if ((section->flags & SEC_HAS_CONTENTS) == 0)
15335796c8dcSSimon Schubert     {
15345796c8dcSSimon Schubert       memset (location, 0, (size_t) count);
15355796c8dcSSimon Schubert       return TRUE;
15365796c8dcSSimon Schubert     }
15375796c8dcSSimon Schubert 
15385796c8dcSSimon Schubert   if ((section->flags & SEC_IN_MEMORY) != 0)
15395796c8dcSSimon Schubert     {
15405796c8dcSSimon Schubert       if (section->contents == NULL)
15415796c8dcSSimon Schubert 	{
15425796c8dcSSimon Schubert 	  /* This can happen because of errors earlier on in the linking process.
15435796c8dcSSimon Schubert 	     We do not want to seg-fault here, so clear the flag and return an
15445796c8dcSSimon Schubert 	     error code.  */
15455796c8dcSSimon Schubert 	  section->flags &= ~ SEC_IN_MEMORY;
15465796c8dcSSimon Schubert 	  bfd_set_error (bfd_error_invalid_operation);
15475796c8dcSSimon Schubert 	  return FALSE;
15485796c8dcSSimon Schubert 	}
15495796c8dcSSimon Schubert 
1550*ef5ccd6cSJohn Marino       memmove (location, section->contents + offset, (size_t) count);
15515796c8dcSSimon Schubert       return TRUE;
15525796c8dcSSimon Schubert     }
15535796c8dcSSimon Schubert 
15545796c8dcSSimon Schubert   return BFD_SEND (abfd, _bfd_get_section_contents,
15555796c8dcSSimon Schubert 		   (abfd, section, location, offset, count));
15565796c8dcSSimon Schubert }
15575796c8dcSSimon Schubert 
15585796c8dcSSimon Schubert /*
15595796c8dcSSimon Schubert FUNCTION
15605796c8dcSSimon Schubert 	bfd_malloc_and_get_section
15615796c8dcSSimon Schubert 
15625796c8dcSSimon Schubert SYNOPSIS
15635796c8dcSSimon Schubert 	bfd_boolean bfd_malloc_and_get_section
15645796c8dcSSimon Schubert 	  (bfd *abfd, asection *section, bfd_byte **buf);
15655796c8dcSSimon Schubert 
15665796c8dcSSimon Schubert DESCRIPTION
15675796c8dcSSimon Schubert 	Read all data from @var{section} in BFD @var{abfd}
15685796c8dcSSimon Schubert 	into a buffer, *@var{buf}, malloc'd by this function.
15695796c8dcSSimon Schubert */
15705796c8dcSSimon Schubert 
15715796c8dcSSimon Schubert bfd_boolean
bfd_malloc_and_get_section(bfd * abfd,sec_ptr sec,bfd_byte ** buf)15725796c8dcSSimon Schubert bfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf)
15735796c8dcSSimon Schubert {
1574c50c785cSJohn Marino   *buf = NULL;
1575c50c785cSJohn Marino   return bfd_get_full_section_contents (abfd, sec, buf);
15765796c8dcSSimon Schubert }
15775796c8dcSSimon Schubert /*
15785796c8dcSSimon Schubert FUNCTION
15795796c8dcSSimon Schubert 	bfd_copy_private_section_data
15805796c8dcSSimon Schubert 
15815796c8dcSSimon Schubert SYNOPSIS
15825796c8dcSSimon Schubert 	bfd_boolean bfd_copy_private_section_data
15835796c8dcSSimon Schubert 	  (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
15845796c8dcSSimon Schubert 
15855796c8dcSSimon Schubert DESCRIPTION
15865796c8dcSSimon Schubert 	Copy private section information from @var{isec} in the BFD
15875796c8dcSSimon Schubert 	@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
15885796c8dcSSimon Schubert 	Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
15895796c8dcSSimon Schubert 	returns are:
15905796c8dcSSimon Schubert 
15915796c8dcSSimon Schubert 	o <<bfd_error_no_memory>> -
15925796c8dcSSimon Schubert 	Not enough memory exists to create private data for @var{osec}.
15935796c8dcSSimon Schubert 
15945796c8dcSSimon Schubert .#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
15955796c8dcSSimon Schubert .     BFD_SEND (obfd, _bfd_copy_private_section_data, \
15965796c8dcSSimon Schubert .		(ibfd, isection, obfd, osection))
15975796c8dcSSimon Schubert */
15985796c8dcSSimon Schubert 
15995796c8dcSSimon Schubert /*
16005796c8dcSSimon Schubert FUNCTION
16015796c8dcSSimon Schubert 	bfd_generic_is_group_section
16025796c8dcSSimon Schubert 
16035796c8dcSSimon Schubert SYNOPSIS
16045796c8dcSSimon Schubert 	bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
16055796c8dcSSimon Schubert 
16065796c8dcSSimon Schubert DESCRIPTION
16075796c8dcSSimon Schubert 	Returns TRUE if @var{sec} is a member of a group.
16085796c8dcSSimon Schubert */
16095796c8dcSSimon Schubert 
16105796c8dcSSimon Schubert bfd_boolean
bfd_generic_is_group_section(bfd * abfd ATTRIBUTE_UNUSED,const asection * sec ATTRIBUTE_UNUSED)16115796c8dcSSimon Schubert bfd_generic_is_group_section (bfd *abfd ATTRIBUTE_UNUSED,
16125796c8dcSSimon Schubert 			      const asection *sec ATTRIBUTE_UNUSED)
16135796c8dcSSimon Schubert {
16145796c8dcSSimon Schubert   return FALSE;
16155796c8dcSSimon Schubert }
16165796c8dcSSimon Schubert 
16175796c8dcSSimon Schubert /*
16185796c8dcSSimon Schubert FUNCTION
16195796c8dcSSimon Schubert 	bfd_generic_discard_group
16205796c8dcSSimon Schubert 
16215796c8dcSSimon Schubert SYNOPSIS
16225796c8dcSSimon Schubert 	bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
16235796c8dcSSimon Schubert 
16245796c8dcSSimon Schubert DESCRIPTION
16255796c8dcSSimon Schubert 	Remove all members of @var{group} from the output.
16265796c8dcSSimon Schubert */
16275796c8dcSSimon Schubert 
16285796c8dcSSimon Schubert bfd_boolean
bfd_generic_discard_group(bfd * abfd ATTRIBUTE_UNUSED,asection * group ATTRIBUTE_UNUSED)16295796c8dcSSimon Schubert bfd_generic_discard_group (bfd *abfd ATTRIBUTE_UNUSED,
16305796c8dcSSimon Schubert 			   asection *group ATTRIBUTE_UNUSED)
16315796c8dcSSimon Schubert {
16325796c8dcSSimon Schubert   return TRUE;
16335796c8dcSSimon Schubert }
1634