1*fae548d3Szrj /* Object file "section" support for the BFD library.
2*fae548d3Szrj    Copyright (C) 1990-2020 Free Software Foundation, Inc.
3*fae548d3Szrj    Written by Cygnus Support.
4*fae548d3Szrj 
5*fae548d3Szrj    This file is part of BFD, the Binary File Descriptor library.
6*fae548d3Szrj 
7*fae548d3Szrj    This program is free software; you can redistribute it and/or modify
8*fae548d3Szrj    it under the terms of the GNU General Public License as published by
9*fae548d3Szrj    the Free Software Foundation; either version 3 of the License, or
10*fae548d3Szrj    (at your option) any later version.
11*fae548d3Szrj 
12*fae548d3Szrj    This program is distributed in the hope that it will be useful,
13*fae548d3Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*fae548d3Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*fae548d3Szrj    GNU General Public License for more details.
16*fae548d3Szrj 
17*fae548d3Szrj    You should have received a copy of the GNU General Public License
18*fae548d3Szrj    along with this program; if not, write to the Free Software
19*fae548d3Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20*fae548d3Szrj    MA 02110-1301, USA.  */
21*fae548d3Szrj 
22*fae548d3Szrj /*
23*fae548d3Szrj SECTION
24*fae548d3Szrj 	Sections
25*fae548d3Szrj 
26*fae548d3Szrj 	The raw data contained within a BFD is maintained through the
27*fae548d3Szrj 	section abstraction.  A single BFD may have any number of
28*fae548d3Szrj 	sections.  It keeps hold of them by pointing to the first;
29*fae548d3Szrj 	each one points to the next in the list.
30*fae548d3Szrj 
31*fae548d3Szrj 	Sections are supported in BFD in <<section.c>>.
32*fae548d3Szrj 
33*fae548d3Szrj @menu
34*fae548d3Szrj @* Section Input::
35*fae548d3Szrj @* Section Output::
36*fae548d3Szrj @* typedef asection::
37*fae548d3Szrj @* section prototypes::
38*fae548d3Szrj @end menu
39*fae548d3Szrj 
40*fae548d3Szrj INODE
41*fae548d3Szrj Section Input, Section Output, Sections, Sections
42*fae548d3Szrj SUBSECTION
43*fae548d3Szrj 	Section input
44*fae548d3Szrj 
45*fae548d3Szrj 	When a BFD is opened for reading, the section structures are
46*fae548d3Szrj 	created and attached to the BFD.
47*fae548d3Szrj 
48*fae548d3Szrj 	Each section has a name which describes the section in the
49*fae548d3Szrj 	outside world---for example, <<a.out>> would contain at least
50*fae548d3Szrj 	three sections, called <<.text>>, <<.data>> and <<.bss>>.
51*fae548d3Szrj 
52*fae548d3Szrj 	Names need not be unique; for example a COFF file may have several
53*fae548d3Szrj 	sections named <<.data>>.
54*fae548d3Szrj 
55*fae548d3Szrj 	Sometimes a BFD will contain more than the ``natural'' number of
56*fae548d3Szrj 	sections. A back end may attach other sections containing
57*fae548d3Szrj 	constructor data, or an application may add a section (using
58*fae548d3Szrj 	<<bfd_make_section>>) to the sections attached to an already open
59*fae548d3Szrj 	BFD. For example, the linker creates an extra section
60*fae548d3Szrj 	<<COMMON>> for each input file's BFD to hold information about
61*fae548d3Szrj 	common storage.
62*fae548d3Szrj 
63*fae548d3Szrj 	The raw data is not necessarily read in when
64*fae548d3Szrj 	the section descriptor is created. Some targets may leave the
65*fae548d3Szrj 	data in place until a <<bfd_get_section_contents>> call is
66*fae548d3Szrj 	made. Other back ends may read in all the data at once.  For
67*fae548d3Szrj 	example, an S-record file has to be read once to determine the
68*fae548d3Szrj 	size of the data.
69*fae548d3Szrj 
70*fae548d3Szrj INODE
71*fae548d3Szrj Section Output, typedef asection, Section Input, Sections
72*fae548d3Szrj 
73*fae548d3Szrj SUBSECTION
74*fae548d3Szrj 	Section output
75*fae548d3Szrj 
76*fae548d3Szrj 	To write a new object style BFD, the various sections to be
77*fae548d3Szrj 	written have to be created. They are attached to the BFD in
78*fae548d3Szrj 	the same way as input sections; data is written to the
79*fae548d3Szrj 	sections using <<bfd_set_section_contents>>.
80*fae548d3Szrj 
81*fae548d3Szrj 	Any program that creates or combines sections (e.g., the assembler
82*fae548d3Szrj 	and linker) must use the <<asection>> fields <<output_section>> and
83*fae548d3Szrj 	<<output_offset>> to indicate the file sections to which each
84*fae548d3Szrj 	section must be written.  (If the section is being created from
85*fae548d3Szrj 	scratch, <<output_section>> should probably point to the section
86*fae548d3Szrj 	itself and <<output_offset>> should probably be zero.)
87*fae548d3Szrj 
88*fae548d3Szrj 	The data to be written comes from input sections attached
89*fae548d3Szrj 	(via <<output_section>> pointers) to
90*fae548d3Szrj 	the output sections.  The output section structure can be
91*fae548d3Szrj 	considered a filter for the input section: the output section
92*fae548d3Szrj 	determines the vma of the output data and the name, but the
93*fae548d3Szrj 	input section determines the offset into the output section of
94*fae548d3Szrj 	the data to be written.
95*fae548d3Szrj 
96*fae548d3Szrj 	E.g., to create a section "O", starting at 0x100, 0x123 long,
97*fae548d3Szrj 	containing two subsections, "A" at offset 0x0 (i.e., at vma
98*fae548d3Szrj 	0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the <<asection>>
99*fae548d3Szrj 	structures would look like:
100*fae548d3Szrj 
101*fae548d3Szrj |   section name          "A"
102*fae548d3Szrj |     output_offset   0x00
103*fae548d3Szrj |     size            0x20
104*fae548d3Szrj |     output_section ----------->  section name    "O"
105*fae548d3Szrj |                             |    vma             0x100
106*fae548d3Szrj |   section name          "B" |    size            0x123
107*fae548d3Szrj |     output_offset   0x20    |
108*fae548d3Szrj |     size            0x103   |
109*fae548d3Szrj |     output_section  --------|
110*fae548d3Szrj 
111*fae548d3Szrj SUBSECTION
112*fae548d3Szrj 	Link orders
113*fae548d3Szrj 
114*fae548d3Szrj 	The data within a section is stored in a @dfn{link_order}.
115*fae548d3Szrj 	These are much like the fixups in <<gas>>.  The link_order
116*fae548d3Szrj 	abstraction allows a section to grow and shrink within itself.
117*fae548d3Szrj 
118*fae548d3Szrj 	A link_order knows how big it is, and which is the next
119*fae548d3Szrj 	link_order and where the raw data for it is; it also points to
120*fae548d3Szrj 	a list of relocations which apply to it.
121*fae548d3Szrj 
122*fae548d3Szrj 	The link_order is used by the linker to perform relaxing on
123*fae548d3Szrj 	final code.  The compiler creates code which is as big as
124*fae548d3Szrj 	necessary to make it work without relaxing, and the user can
125*fae548d3Szrj 	select whether to relax.  Sometimes relaxing takes a lot of
126*fae548d3Szrj 	time.  The linker runs around the relocations to see if any
127*fae548d3Szrj 	are attached to data which can be shrunk, if so it does it on
128*fae548d3Szrj 	a link_order by link_order basis.
129*fae548d3Szrj 
130*fae548d3Szrj */
131*fae548d3Szrj 
132*fae548d3Szrj #include "sysdep.h"
133*fae548d3Szrj #include "bfd.h"
134*fae548d3Szrj #include "libbfd.h"
135*fae548d3Szrj #include "bfdlink.h"
136*fae548d3Szrj 
137*fae548d3Szrj /*
138*fae548d3Szrj DOCDD
139*fae548d3Szrj INODE
140*fae548d3Szrj typedef asection, section prototypes, Section Output, Sections
141*fae548d3Szrj SUBSECTION
142*fae548d3Szrj 	typedef asection
143*fae548d3Szrj 
144*fae548d3Szrj 	Here is the section structure:
145*fae548d3Szrj 
146*fae548d3Szrj CODE_FRAGMENT
147*fae548d3Szrj .
148*fae548d3Szrj .typedef struct bfd_section
149*fae548d3Szrj .{
150*fae548d3Szrj .  {* The name of the section; the name isn't a copy, the pointer is
151*fae548d3Szrj .     the same as that passed to bfd_make_section.  *}
152*fae548d3Szrj .  const char *name;
153*fae548d3Szrj .
154*fae548d3Szrj .  {* A unique sequence number.  *}
155*fae548d3Szrj .  unsigned int id;
156*fae548d3Szrj .
157*fae548d3Szrj .  {* Which section in the bfd; 0..n-1 as sections are created in a bfd.  *}
158*fae548d3Szrj .  unsigned int index;
159*fae548d3Szrj .
160*fae548d3Szrj .  {* The next section in the list belonging to the BFD, or NULL.  *}
161*fae548d3Szrj .  struct bfd_section *next;
162*fae548d3Szrj .
163*fae548d3Szrj .  {* The previous section in the list belonging to the BFD, or NULL.  *}
164*fae548d3Szrj .  struct bfd_section *prev;
165*fae548d3Szrj .
166*fae548d3Szrj .  {* The field flags contains attributes of the section. Some
167*fae548d3Szrj .     flags are read in from the object file, and some are
168*fae548d3Szrj .     synthesized from other information.  *}
169*fae548d3Szrj .  flagword flags;
170*fae548d3Szrj .
171*fae548d3Szrj .#define SEC_NO_FLAGS                      0x0
172*fae548d3Szrj .
173*fae548d3Szrj .  {* Tells the OS to allocate space for this section when loading.
174*fae548d3Szrj .     This is clear for a section containing debug information only.  *}
175*fae548d3Szrj .#define SEC_ALLOC                         0x1
176*fae548d3Szrj .
177*fae548d3Szrj .  {* Tells the OS to load the section from the file when loading.
178*fae548d3Szrj .     This is clear for a .bss section.  *}
179*fae548d3Szrj .#define SEC_LOAD                          0x2
180*fae548d3Szrj .
181*fae548d3Szrj .  {* The section contains data still to be relocated, so there is
182*fae548d3Szrj .     some relocation information too.  *}
183*fae548d3Szrj .#define SEC_RELOC                         0x4
184*fae548d3Szrj .
185*fae548d3Szrj .  {* A signal to the OS that the section contains read only data.  *}
186*fae548d3Szrj .#define SEC_READONLY                      0x8
187*fae548d3Szrj .
188*fae548d3Szrj .  {* The section contains code only.  *}
189*fae548d3Szrj .#define SEC_CODE                         0x10
190*fae548d3Szrj .
191*fae548d3Szrj .  {* The section contains data only.  *}
192*fae548d3Szrj .#define SEC_DATA                         0x20
193*fae548d3Szrj .
194*fae548d3Szrj .  {* The section will reside in ROM.  *}
195*fae548d3Szrj .#define SEC_ROM                          0x40
196*fae548d3Szrj .
197*fae548d3Szrj .  {* The section contains constructor information. This section
198*fae548d3Szrj .     type is used by the linker to create lists of constructors and
199*fae548d3Szrj .     destructors used by <<g++>>. When a back end sees a symbol
200*fae548d3Szrj .     which should be used in a constructor list, it creates a new
201*fae548d3Szrj .     section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
202*fae548d3Szrj .     the symbol to it, and builds a relocation. To build the lists
203*fae548d3Szrj .     of constructors, all the linker has to do is catenate all the
204*fae548d3Szrj .     sections called <<__CTOR_LIST__>> and relocate the data
205*fae548d3Szrj .     contained within - exactly the operations it would peform on
206*fae548d3Szrj .     standard data.  *}
207*fae548d3Szrj .#define SEC_CONSTRUCTOR                  0x80
208*fae548d3Szrj .
209*fae548d3Szrj .  {* The section has contents - a data section could be
210*fae548d3Szrj .     <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
211*fae548d3Szrj .     <<SEC_HAS_CONTENTS>>  *}
212*fae548d3Szrj .#define SEC_HAS_CONTENTS                0x100
213*fae548d3Szrj .
214*fae548d3Szrj .  {* An instruction to the linker to not output the section
215*fae548d3Szrj .     even if it has information which would normally be written.  *}
216*fae548d3Szrj .#define SEC_NEVER_LOAD                  0x200
217*fae548d3Szrj .
218*fae548d3Szrj .  {* The section contains thread local data.  *}
219*fae548d3Szrj .#define SEC_THREAD_LOCAL                0x400
220*fae548d3Szrj .
221*fae548d3Szrj .  {* The section's size is fixed.  Generic linker code will not
222*fae548d3Szrj .     recalculate it and it is up to whoever has set this flag to
223*fae548d3Szrj .     get the size right.  *}
224*fae548d3Szrj .#define SEC_FIXED_SIZE                  0x800
225*fae548d3Szrj .
226*fae548d3Szrj .  {* The section contains common symbols (symbols may be defined
227*fae548d3Szrj .     multiple times, the value of a symbol is the amount of
228*fae548d3Szrj .     space it requires, and the largest symbol value is the one
229*fae548d3Szrj .     used).  Most targets have exactly one of these (which we
230*fae548d3Szrj .     translate to bfd_com_section_ptr), but ECOFF has two.  *}
231*fae548d3Szrj .#define SEC_IS_COMMON                  0x1000
232*fae548d3Szrj .
233*fae548d3Szrj .  {* The section contains only debugging information.  For
234*fae548d3Szrj .     example, this is set for ELF .debug and .stab sections.
235*fae548d3Szrj .     strip tests this flag to see if a section can be
236*fae548d3Szrj .     discarded.  *}
237*fae548d3Szrj .#define SEC_DEBUGGING                  0x2000
238*fae548d3Szrj .
239*fae548d3Szrj .  {* The contents of this section are held in memory pointed to
240*fae548d3Szrj .     by the contents field.  This is checked by bfd_get_section_contents,
241*fae548d3Szrj .     and the data is retrieved from memory if appropriate.  *}
242*fae548d3Szrj .#define SEC_IN_MEMORY                  0x4000
243*fae548d3Szrj .
244*fae548d3Szrj .  {* The contents of this section are to be excluded by the
245*fae548d3Szrj .     linker for executable and shared objects unless those
246*fae548d3Szrj .     objects are to be further relocated.  *}
247*fae548d3Szrj .#define SEC_EXCLUDE                    0x8000
248*fae548d3Szrj .
249*fae548d3Szrj .  {* The contents of this section are to be sorted based on the sum of
250*fae548d3Szrj .     the symbol and addend values specified by the associated relocation
251*fae548d3Szrj .     entries.  Entries without associated relocation entries will be
252*fae548d3Szrj .     appended to the end of the section in an unspecified order.  *}
253*fae548d3Szrj .#define SEC_SORT_ENTRIES              0x10000
254*fae548d3Szrj .
255*fae548d3Szrj .  {* When linking, duplicate sections of the same name should be
256*fae548d3Szrj .     discarded, rather than being combined into a single section as
257*fae548d3Szrj .     is usually done.  This is similar to how common symbols are
258*fae548d3Szrj .     handled.  See SEC_LINK_DUPLICATES below.  *}
259*fae548d3Szrj .#define SEC_LINK_ONCE                 0x20000
260*fae548d3Szrj .
261*fae548d3Szrj .  {* If SEC_LINK_ONCE is set, this bitfield describes how the linker
262*fae548d3Szrj .     should handle duplicate sections.  *}
263*fae548d3Szrj .#define SEC_LINK_DUPLICATES           0xc0000
264*fae548d3Szrj .
265*fae548d3Szrj .  {* This value for SEC_LINK_DUPLICATES means that duplicate
266*fae548d3Szrj .     sections with the same name should simply be discarded.  *}
267*fae548d3Szrj .#define SEC_LINK_DUPLICATES_DISCARD       0x0
268*fae548d3Szrj .
269*fae548d3Szrj .  {* This value for SEC_LINK_DUPLICATES means that the linker
270*fae548d3Szrj .     should warn if there are any duplicate sections, although
271*fae548d3Szrj .     it should still only link one copy.  *}
272*fae548d3Szrj .#define SEC_LINK_DUPLICATES_ONE_ONLY  0x40000
273*fae548d3Szrj .
274*fae548d3Szrj .  {* This value for SEC_LINK_DUPLICATES means that the linker
275*fae548d3Szrj .     should warn if any duplicate sections are a different size.  *}
276*fae548d3Szrj .#define SEC_LINK_DUPLICATES_SAME_SIZE 0x80000
277*fae548d3Szrj .
278*fae548d3Szrj .  {* This value for SEC_LINK_DUPLICATES means that the linker
279*fae548d3Szrj .     should warn if any duplicate sections contain different
280*fae548d3Szrj .     contents.  *}
281*fae548d3Szrj .#define SEC_LINK_DUPLICATES_SAME_CONTENTS \
282*fae548d3Szrj .  (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
283*fae548d3Szrj .
284*fae548d3Szrj .  {* This section was created by the linker as part of dynamic
285*fae548d3Szrj .     relocation or other arcane processing.  It is skipped when
286*fae548d3Szrj .     going through the first-pass output, trusting that someone
287*fae548d3Szrj .     else up the line will take care of it later.  *}
288*fae548d3Szrj .#define SEC_LINKER_CREATED           0x100000
289*fae548d3Szrj .
290*fae548d3Szrj .  {* This section should not be subject to garbage collection.
291*fae548d3Szrj .     Also set to inform the linker that this section should not be
292*fae548d3Szrj .     listed in the link map as discarded.  *}
293*fae548d3Szrj .#define SEC_KEEP                     0x200000
294*fae548d3Szrj .
295*fae548d3Szrj .  {* This section contains "short" data, and should be placed
296*fae548d3Szrj .     "near" the GP.  *}
297*fae548d3Szrj .#define SEC_SMALL_DATA               0x400000
298*fae548d3Szrj .
299*fae548d3Szrj .  {* Attempt to merge identical entities in the section.
300*fae548d3Szrj .     Entity size is given in the entsize field.  *}
301*fae548d3Szrj .#define SEC_MERGE                    0x800000
302*fae548d3Szrj .
303*fae548d3Szrj .  {* If given with SEC_MERGE, entities to merge are zero terminated
304*fae548d3Szrj .     strings where entsize specifies character size instead of fixed
305*fae548d3Szrj .     size entries.  *}
306*fae548d3Szrj .#define SEC_STRINGS                 0x1000000
307*fae548d3Szrj .
308*fae548d3Szrj .  {* This section contains data about section groups.  *}
309*fae548d3Szrj .#define SEC_GROUP                   0x2000000
310*fae548d3Szrj .
311*fae548d3Szrj .  {* The section is a COFF shared library section.  This flag is
312*fae548d3Szrj .     only for the linker.  If this type of section appears in
313*fae548d3Szrj .     the input file, the linker must copy it to the output file
314*fae548d3Szrj .     without changing the vma or size.  FIXME: Although this
315*fae548d3Szrj .     was originally intended to be general, it really is COFF
316*fae548d3Szrj .     specific (and the flag was renamed to indicate this).  It
317*fae548d3Szrj .     might be cleaner to have some more general mechanism to
318*fae548d3Szrj .     allow the back end to control what the linker does with
319*fae548d3Szrj .     sections.  *}
320*fae548d3Szrj .#define SEC_COFF_SHARED_LIBRARY     0x4000000
321*fae548d3Szrj .
322*fae548d3Szrj .  {* This input section should be copied to output in reverse order
323*fae548d3Szrj .     as an array of pointers.  This is for ELF linker internal use
324*fae548d3Szrj .     only.  *}
325*fae548d3Szrj .#define SEC_ELF_REVERSE_COPY        0x4000000
326*fae548d3Szrj .
327*fae548d3Szrj .  {* This section contains data which may be shared with other
328*fae548d3Szrj .     executables or shared objects. This is for COFF only.  *}
329*fae548d3Szrj .#define SEC_COFF_SHARED             0x8000000
330*fae548d3Szrj .
331*fae548d3Szrj .  {* This section should be compressed.  This is for ELF linker
332*fae548d3Szrj .     internal use only.  *}
333*fae548d3Szrj .#define SEC_ELF_COMPRESS            0x8000000
334*fae548d3Szrj .
335*fae548d3Szrj .  {* When a section with this flag is being linked, then if the size of
336*fae548d3Szrj .     the input section is less than a page, it should not cross a page
337*fae548d3Szrj .     boundary.  If the size of the input section is one page or more,
338*fae548d3Szrj .     it should be aligned on a page boundary.  This is for TI
339*fae548d3Szrj .     TMS320C54X only.  *}
340*fae548d3Szrj .#define SEC_TIC54X_BLOCK           0x10000000
341*fae548d3Szrj .
342*fae548d3Szrj .  {* This section should be renamed.  This is for ELF linker
343*fae548d3Szrj .     internal use only.  *}
344*fae548d3Szrj .#define SEC_ELF_RENAME             0x10000000
345*fae548d3Szrj .
346*fae548d3Szrj .  {* Conditionally link this section; do not link if there are no
347*fae548d3Szrj .     references found to any symbol in the section.  This is for TI
348*fae548d3Szrj .     TMS320C54X only.  *}
349*fae548d3Szrj .#define SEC_TIC54X_CLINK           0x20000000
350*fae548d3Szrj .
351*fae548d3Szrj .  {* This section contains vliw code.  This is for Toshiba MeP only.  *}
352*fae548d3Szrj .#define SEC_MEP_VLIW               0x20000000
353*fae548d3Szrj .
354*fae548d3Szrj .  {* All symbols, sizes and relocations in this section are octets
355*fae548d3Szrj .     instead of bytes.  Required for DWARF debug sections as DWARF
356*fae548d3Szrj .     information is organized in octets, not bytes.  *}
357*fae548d3Szrj .#define SEC_ELF_OCTETS             0x40000000
358*fae548d3Szrj .
359*fae548d3Szrj .  {* Indicate that section has the no read flag set. This happens
360*fae548d3Szrj .     when memory read flag isn't set. *}
361*fae548d3Szrj .#define SEC_COFF_NOREAD            0x40000000
362*fae548d3Szrj .
363*fae548d3Szrj .  {* Indicate that section has the purecode flag set.  *}
364*fae548d3Szrj .#define SEC_ELF_PURECODE           0x80000000
365*fae548d3Szrj .
366*fae548d3Szrj .  {*  End of section flags.  *}
367*fae548d3Szrj .
368*fae548d3Szrj .  {* Some internal packed boolean fields.  *}
369*fae548d3Szrj .
370*fae548d3Szrj .  {* See the vma field.  *}
371*fae548d3Szrj .  unsigned int user_set_vma : 1;
372*fae548d3Szrj .
373*fae548d3Szrj .  {* A mark flag used by some of the linker backends.  *}
374*fae548d3Szrj .  unsigned int linker_mark : 1;
375*fae548d3Szrj .
376*fae548d3Szrj .  {* Another mark flag used by some of the linker backends.  Set for
377*fae548d3Szrj .     output sections that have an input section.  *}
378*fae548d3Szrj .  unsigned int linker_has_input : 1;
379*fae548d3Szrj .
380*fae548d3Szrj .  {* Mark flag used by some linker backends for garbage collection.  *}
381*fae548d3Szrj .  unsigned int gc_mark : 1;
382*fae548d3Szrj .
383*fae548d3Szrj .  {* Section compression status.  *}
384*fae548d3Szrj .  unsigned int compress_status : 2;
385*fae548d3Szrj .#define COMPRESS_SECTION_NONE    0
386*fae548d3Szrj .#define COMPRESS_SECTION_DONE    1
387*fae548d3Szrj .#define DECOMPRESS_SECTION_SIZED 2
388*fae548d3Szrj .
389*fae548d3Szrj .  {* The following flags are used by the ELF linker. *}
390*fae548d3Szrj .
391*fae548d3Szrj .  {* Mark sections which have been allocated to segments.  *}
392*fae548d3Szrj .  unsigned int segment_mark : 1;
393*fae548d3Szrj .
394*fae548d3Szrj .  {* Type of sec_info information.  *}
395*fae548d3Szrj .  unsigned int sec_info_type:3;
396*fae548d3Szrj .#define SEC_INFO_TYPE_NONE      0
397*fae548d3Szrj .#define SEC_INFO_TYPE_STABS     1
398*fae548d3Szrj .#define SEC_INFO_TYPE_MERGE     2
399*fae548d3Szrj .#define SEC_INFO_TYPE_EH_FRAME  3
400*fae548d3Szrj .#define SEC_INFO_TYPE_JUST_SYMS 4
401*fae548d3Szrj .#define SEC_INFO_TYPE_TARGET    5
402*fae548d3Szrj .#define SEC_INFO_TYPE_EH_FRAME_ENTRY 6
403*fae548d3Szrj .
404*fae548d3Szrj .  {* Nonzero if this section uses RELA relocations, rather than REL.  *}
405*fae548d3Szrj .  unsigned int use_rela_p:1;
406*fae548d3Szrj .
407*fae548d3Szrj .  {* Bits used by various backends.  The generic code doesn't touch
408*fae548d3Szrj .     these fields.  *}
409*fae548d3Szrj .
410*fae548d3Szrj .  unsigned int sec_flg0:1;
411*fae548d3Szrj .  unsigned int sec_flg1:1;
412*fae548d3Szrj .  unsigned int sec_flg2:1;
413*fae548d3Szrj .  unsigned int sec_flg3:1;
414*fae548d3Szrj .  unsigned int sec_flg4:1;
415*fae548d3Szrj .  unsigned int sec_flg5:1;
416*fae548d3Szrj .
417*fae548d3Szrj .  {* End of internal packed boolean fields.  *}
418*fae548d3Szrj .
419*fae548d3Szrj .  {*  The virtual memory address of the section - where it will be
420*fae548d3Szrj .      at run time.  The symbols are relocated against this.  The
421*fae548d3Szrj .      user_set_vma flag is maintained by bfd; if it's not set, the
422*fae548d3Szrj .      backend can assign addresses (for example, in <<a.out>>, where
423*fae548d3Szrj .      the default address for <<.data>> is dependent on the specific
424*fae548d3Szrj .      target and various flags).  *}
425*fae548d3Szrj .  bfd_vma vma;
426*fae548d3Szrj .
427*fae548d3Szrj .  {*  The load address of the section - where it would be in a
428*fae548d3Szrj .      rom image; really only used for writing section header
429*fae548d3Szrj .      information.  *}
430*fae548d3Szrj .  bfd_vma lma;
431*fae548d3Szrj .
432*fae548d3Szrj .  {* The size of the section in *octets*, as it will be output.
433*fae548d3Szrj .     Contains a value even if the section has no contents (e.g., the
434*fae548d3Szrj .     size of <<.bss>>).  *}
435*fae548d3Szrj .  bfd_size_type size;
436*fae548d3Szrj .
437*fae548d3Szrj .  {* For input sections, the original size on disk of the section, in
438*fae548d3Szrj .     octets.  This field should be set for any section whose size is
439*fae548d3Szrj .     changed by linker relaxation.  It is required for sections where
440*fae548d3Szrj .     the linker relaxation scheme doesn't cache altered section and
441*fae548d3Szrj .     reloc contents (stabs, eh_frame, SEC_MERGE, some coff relaxing
442*fae548d3Szrj .     targets), and thus the original size needs to be kept to read the
443*fae548d3Szrj .     section multiple times.  For output sections, rawsize holds the
444*fae548d3Szrj .     section size calculated on a previous linker relaxation pass.  *}
445*fae548d3Szrj .  bfd_size_type rawsize;
446*fae548d3Szrj .
447*fae548d3Szrj .  {* The compressed size of the section in octets.  *}
448*fae548d3Szrj .  bfd_size_type compressed_size;
449*fae548d3Szrj .
450*fae548d3Szrj .  {* Relaxation table. *}
451*fae548d3Szrj .  struct relax_table *relax;
452*fae548d3Szrj .
453*fae548d3Szrj .  {* Count of used relaxation table entries. *}
454*fae548d3Szrj .  int relax_count;
455*fae548d3Szrj .
456*fae548d3Szrj .
457*fae548d3Szrj .  {* If this section is going to be output, then this value is the
458*fae548d3Szrj .     offset in *bytes* into the output section of the first byte in the
459*fae548d3Szrj .     input section (byte ==> smallest addressable unit on the
460*fae548d3Szrj .     target).  In most cases, if this was going to start at the
461*fae548d3Szrj .     100th octet (8-bit quantity) in the output section, this value
462*fae548d3Szrj .     would be 100.  However, if the target byte size is 16 bits
463*fae548d3Szrj .     (bfd_octets_per_byte is "2"), this value would be 50.  *}
464*fae548d3Szrj .  bfd_vma output_offset;
465*fae548d3Szrj .
466*fae548d3Szrj .  {* The output section through which to map on output.  *}
467*fae548d3Szrj .  struct bfd_section *output_section;
468*fae548d3Szrj .
469*fae548d3Szrj .  {* The alignment requirement of the section, as an exponent of 2 -
470*fae548d3Szrj .     e.g., 3 aligns to 2^3 (or 8).  *}
471*fae548d3Szrj .  unsigned int alignment_power;
472*fae548d3Szrj .
473*fae548d3Szrj .  {* If an input section, a pointer to a vector of relocation
474*fae548d3Szrj .     records for the data in this section.  *}
475*fae548d3Szrj .  struct reloc_cache_entry *relocation;
476*fae548d3Szrj .
477*fae548d3Szrj .  {* If an output section, a pointer to a vector of pointers to
478*fae548d3Szrj .     relocation records for the data in this section.  *}
479*fae548d3Szrj .  struct reloc_cache_entry **orelocation;
480*fae548d3Szrj .
481*fae548d3Szrj .  {* The number of relocation records in one of the above.  *}
482*fae548d3Szrj .  unsigned reloc_count;
483*fae548d3Szrj .
484*fae548d3Szrj .  {* Information below is back end specific - and not always used
485*fae548d3Szrj .     or updated.  *}
486*fae548d3Szrj .
487*fae548d3Szrj .  {* File position of section data.  *}
488*fae548d3Szrj .  file_ptr filepos;
489*fae548d3Szrj .
490*fae548d3Szrj .  {* File position of relocation info.  *}
491*fae548d3Szrj .  file_ptr rel_filepos;
492*fae548d3Szrj .
493*fae548d3Szrj .  {* File position of line data.  *}
494*fae548d3Szrj .  file_ptr line_filepos;
495*fae548d3Szrj .
496*fae548d3Szrj .  {* Pointer to data for applications.  *}
497*fae548d3Szrj .  void *userdata;
498*fae548d3Szrj .
499*fae548d3Szrj .  {* If the SEC_IN_MEMORY flag is set, this points to the actual
500*fae548d3Szrj .     contents.  *}
501*fae548d3Szrj .  unsigned char *contents;
502*fae548d3Szrj .
503*fae548d3Szrj .  {* Attached line number information.  *}
504*fae548d3Szrj .  alent *lineno;
505*fae548d3Szrj .
506*fae548d3Szrj .  {* Number of line number records.  *}
507*fae548d3Szrj .  unsigned int lineno_count;
508*fae548d3Szrj .
509*fae548d3Szrj .  {* Entity size for merging purposes.  *}
510*fae548d3Szrj .  unsigned int entsize;
511*fae548d3Szrj .
512*fae548d3Szrj .  {* Points to the kept section if this section is a link-once section,
513*fae548d3Szrj .     and is discarded.  *}
514*fae548d3Szrj .  struct bfd_section *kept_section;
515*fae548d3Szrj .
516*fae548d3Szrj .  {* When a section is being output, this value changes as more
517*fae548d3Szrj .     linenumbers are written out.  *}
518*fae548d3Szrj .  file_ptr moving_line_filepos;
519*fae548d3Szrj .
520*fae548d3Szrj .  {* What the section number is in the target world.  *}
521*fae548d3Szrj .  int target_index;
522*fae548d3Szrj .
523*fae548d3Szrj .  void *used_by_bfd;
524*fae548d3Szrj .
525*fae548d3Szrj .  {* If this is a constructor section then here is a list of the
526*fae548d3Szrj .     relocations created to relocate items within it.  *}
527*fae548d3Szrj .  struct relent_chain *constructor_chain;
528*fae548d3Szrj .
529*fae548d3Szrj .  {* The BFD which owns the section.  *}
530*fae548d3Szrj .  bfd *owner;
531*fae548d3Szrj .
532*fae548d3Szrj .  {* A symbol which points at this section only.  *}
533*fae548d3Szrj .  struct bfd_symbol *symbol;
534*fae548d3Szrj .  struct bfd_symbol **symbol_ptr_ptr;
535*fae548d3Szrj .
536*fae548d3Szrj .  {* Early in the link process, map_head and map_tail are used to build
537*fae548d3Szrj .     a list of input sections attached to an output section.  Later,
538*fae548d3Szrj .     output sections use these fields for a list of bfd_link_order
539*fae548d3Szrj .     structs.  *}
540*fae548d3Szrj .  union {
541*fae548d3Szrj .    struct bfd_link_order *link_order;
542*fae548d3Szrj .    struct bfd_section *s;
543*fae548d3Szrj .  } map_head, map_tail;
544*fae548d3Szrj .} asection;
545*fae548d3Szrj .
546*fae548d3Szrj .{* Relax table contains information about instructions which can
547*fae548d3Szrj .   be removed by relaxation -- replacing a long address with a
548*fae548d3Szrj .   short address.  *}
549*fae548d3Szrj .struct relax_table {
550*fae548d3Szrj .  {* Address where bytes may be deleted. *}
551*fae548d3Szrj .  bfd_vma addr;
552*fae548d3Szrj .
553*fae548d3Szrj .  {* Number of bytes to be deleted.  *}
554*fae548d3Szrj .  int size;
555*fae548d3Szrj .};
556*fae548d3Szrj .
557*fae548d3Szrj .static inline const char *
558*fae548d3Szrj .bfd_section_name (const asection *sec)
559*fae548d3Szrj .{
560*fae548d3Szrj .  return sec->name;
561*fae548d3Szrj .}
562*fae548d3Szrj .
563*fae548d3Szrj .static inline bfd_size_type
564*fae548d3Szrj .bfd_section_size (const asection *sec)
565*fae548d3Szrj .{
566*fae548d3Szrj .  return sec->size;
567*fae548d3Szrj .}
568*fae548d3Szrj .
569*fae548d3Szrj .static inline bfd_vma
570*fae548d3Szrj .bfd_section_vma (const asection *sec)
571*fae548d3Szrj .{
572*fae548d3Szrj .  return sec->vma;
573*fae548d3Szrj .}
574*fae548d3Szrj .
575*fae548d3Szrj .static inline bfd_vma
576*fae548d3Szrj .bfd_section_lma (const asection *sec)
577*fae548d3Szrj .{
578*fae548d3Szrj .  return sec->lma;
579*fae548d3Szrj .}
580*fae548d3Szrj .
581*fae548d3Szrj .static inline unsigned int
582*fae548d3Szrj .bfd_section_alignment (const asection *sec)
583*fae548d3Szrj .{
584*fae548d3Szrj .  return sec->alignment_power;
585*fae548d3Szrj .}
586*fae548d3Szrj .
587*fae548d3Szrj .static inline flagword
588*fae548d3Szrj .bfd_section_flags (const asection *sec)
589*fae548d3Szrj .{
590*fae548d3Szrj .  return sec->flags;
591*fae548d3Szrj .}
592*fae548d3Szrj .
593*fae548d3Szrj .static inline void *
594*fae548d3Szrj .bfd_section_userdata (const asection *sec)
595*fae548d3Szrj .{
596*fae548d3Szrj .  return sec->userdata;
597*fae548d3Szrj .}
598*fae548d3Szrj .static inline bfd_boolean
599*fae548d3Szrj .bfd_is_com_section (const asection *sec)
600*fae548d3Szrj .{
601*fae548d3Szrj .  return (sec->flags & SEC_IS_COMMON) != 0;
602*fae548d3Szrj .}
603*fae548d3Szrj .
604*fae548d3Szrj .{* Note: the following are provided as inline functions rather than macros
605*fae548d3Szrj .   because not all callers use the return value.  A macro implementation
606*fae548d3Szrj .   would use a comma expression, eg: "((ptr)->foo = val, TRUE)" and some
607*fae548d3Szrj .   compilers will complain about comma expressions that have no effect.  *}
608*fae548d3Szrj .static inline bfd_boolean
609*fae548d3Szrj .bfd_set_section_userdata (asection *sec, void *val)
610*fae548d3Szrj .{
611*fae548d3Szrj .  sec->userdata = val;
612*fae548d3Szrj .  return TRUE;
613*fae548d3Szrj .}
614*fae548d3Szrj .
615*fae548d3Szrj .static inline bfd_boolean
616*fae548d3Szrj .bfd_set_section_vma (asection *sec, bfd_vma val)
617*fae548d3Szrj .{
618*fae548d3Szrj .  sec->vma = sec->lma = val;
619*fae548d3Szrj .  sec->user_set_vma = TRUE;
620*fae548d3Szrj .  return TRUE;
621*fae548d3Szrj .}
622*fae548d3Szrj .
623*fae548d3Szrj .static inline bfd_boolean
624*fae548d3Szrj .bfd_set_section_lma (asection *sec, bfd_vma val)
625*fae548d3Szrj .{
626*fae548d3Szrj .  sec->lma = val;
627*fae548d3Szrj .  return TRUE;
628*fae548d3Szrj .}
629*fae548d3Szrj .
630*fae548d3Szrj .static inline bfd_boolean
631*fae548d3Szrj .bfd_set_section_alignment (asection *sec, unsigned int val)
632*fae548d3Szrj .{
633*fae548d3Szrj .  sec->alignment_power = val;
634*fae548d3Szrj .  return TRUE;
635*fae548d3Szrj .}
636*fae548d3Szrj .
637*fae548d3Szrj .{* These sections are global, and are managed by BFD.  The application
638*fae548d3Szrj .   and target back end are not permitted to change the values in
639*fae548d3Szrj .   these sections.  *}
640*fae548d3Szrj .extern asection _bfd_std_section[4];
641*fae548d3Szrj .
642*fae548d3Szrj .#define BFD_ABS_SECTION_NAME "*ABS*"
643*fae548d3Szrj .#define BFD_UND_SECTION_NAME "*UND*"
644*fae548d3Szrj .#define BFD_COM_SECTION_NAME "*COM*"
645*fae548d3Szrj .#define BFD_IND_SECTION_NAME "*IND*"
646*fae548d3Szrj .
647*fae548d3Szrj .{* Pointer to the common section.  *}
648*fae548d3Szrj .#define bfd_com_section_ptr (&_bfd_std_section[0])
649*fae548d3Szrj .{* Pointer to the undefined section.  *}
650*fae548d3Szrj .#define bfd_und_section_ptr (&_bfd_std_section[1])
651*fae548d3Szrj .{* Pointer to the absolute section.  *}
652*fae548d3Szrj .#define bfd_abs_section_ptr (&_bfd_std_section[2])
653*fae548d3Szrj .{* Pointer to the indirect section.  *}
654*fae548d3Szrj .#define bfd_ind_section_ptr (&_bfd_std_section[3])
655*fae548d3Szrj .
656*fae548d3Szrj .static inline bfd_boolean
657*fae548d3Szrj .bfd_is_und_section (const asection *sec)
658*fae548d3Szrj .{
659*fae548d3Szrj .  return sec == bfd_und_section_ptr;
660*fae548d3Szrj .}
661*fae548d3Szrj .
662*fae548d3Szrj .static inline bfd_boolean
663*fae548d3Szrj .bfd_is_abs_section (const asection *sec)
664*fae548d3Szrj .{
665*fae548d3Szrj .  return sec == bfd_abs_section_ptr;
666*fae548d3Szrj .}
667*fae548d3Szrj .
668*fae548d3Szrj .static inline bfd_boolean
669*fae548d3Szrj .bfd_is_ind_section (const asection *sec)
670*fae548d3Szrj .{
671*fae548d3Szrj .  return sec == bfd_ind_section_ptr;
672*fae548d3Szrj .}
673*fae548d3Szrj .
674*fae548d3Szrj .static inline bfd_boolean
675*fae548d3Szrj .bfd_is_const_section (const asection *sec)
676*fae548d3Szrj .{
677*fae548d3Szrj .  return sec >= bfd_abs_section_ptr && sec <= bfd_ind_section_ptr;
678*fae548d3Szrj .}
679*fae548d3Szrj .
680*fae548d3Szrj .{* Return TRUE if input section SEC has been discarded.  *}
681*fae548d3Szrj .static inline bfd_boolean
682*fae548d3Szrj .discarded_section (const asection *sec)
683*fae548d3Szrj .{
684*fae548d3Szrj .  return (!bfd_is_abs_section (sec)
685*fae548d3Szrj .          && bfd_is_abs_section (sec->output_section)
686*fae548d3Szrj .          && sec->sec_info_type != SEC_INFO_TYPE_MERGE
687*fae548d3Szrj .          && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS);
688*fae548d3Szrj .}
689*fae548d3Szrj .
690*fae548d3Szrj .#define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS)			\
691*fae548d3Szrj .  {* name, id,  index, next, prev, flags, user_set_vma,            *}	\
692*fae548d3Szrj .  {  NAME, IDX, 0,     NULL, NULL, FLAGS, 0,				\
693*fae548d3Szrj .									\
694*fae548d3Szrj .  {* linker_mark, linker_has_input, gc_mark, decompress_status,    *}	\
695*fae548d3Szrj .     0,           0,                1,       0,			\
696*fae548d3Szrj .									\
697*fae548d3Szrj .  {* segment_mark, sec_info_type, use_rela_p,                      *}	\
698*fae548d3Szrj .     0,            0,             0,					\
699*fae548d3Szrj .									\
700*fae548d3Szrj .  {* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5,   *}	\
701*fae548d3Szrj .     0,        0,        0,        0,        0,        0,		\
702*fae548d3Szrj .									\
703*fae548d3Szrj .  {* vma, lma, size, rawsize, compressed_size, relax, relax_count, *}	\
704*fae548d3Szrj .     0,   0,   0,    0,       0,               0,     0,		\
705*fae548d3Szrj .									\
706*fae548d3Szrj .  {* output_offset, output_section, alignment_power,               *}	\
707*fae548d3Szrj .     0,             &SEC,           0,					\
708*fae548d3Szrj .									\
709*fae548d3Szrj .  {* relocation, orelocation, reloc_count, filepos, rel_filepos,   *}	\
710*fae548d3Szrj .     NULL,       NULL,        0,           0,       0,			\
711*fae548d3Szrj .									\
712*fae548d3Szrj .  {* line_filepos, userdata, contents, lineno, lineno_count,       *}	\
713*fae548d3Szrj .     0,            NULL,     NULL,     NULL,   0,			\
714*fae548d3Szrj .									\
715*fae548d3Szrj .  {* entsize, kept_section, moving_line_filepos,		     *}	\
716*fae548d3Szrj .     0,       NULL,	      0,					\
717*fae548d3Szrj .									\
718*fae548d3Szrj .  {* target_index, used_by_bfd, constructor_chain, owner,          *}	\
719*fae548d3Szrj .     0,            NULL,        NULL,              NULL,		\
720*fae548d3Szrj .									\
721*fae548d3Szrj .  {* symbol,                    symbol_ptr_ptr,                    *}	\
722*fae548d3Szrj .     (struct bfd_symbol *) SYM, &SEC.symbol,				\
723*fae548d3Szrj .									\
724*fae548d3Szrj .  {* map_head, map_tail                                            *}	\
725*fae548d3Szrj .     { NULL }, { NULL }						\
726*fae548d3Szrj .    }
727*fae548d3Szrj .
728*fae548d3Szrj .{* We use a macro to initialize the static asymbol structures because
729*fae548d3Szrj .   traditional C does not permit us to initialize a union member while
730*fae548d3Szrj .   gcc warns if we don't initialize it.
731*fae548d3Szrj .   the_bfd, name, value, attr, section [, udata]  *}
732*fae548d3Szrj .#ifdef __STDC__
733*fae548d3Szrj .#define GLOBAL_SYM_INIT(NAME, SECTION) \
734*fae548d3Szrj .  { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }}
735*fae548d3Szrj .#else
736*fae548d3Szrj .#define GLOBAL_SYM_INIT(NAME, SECTION) \
737*fae548d3Szrj .  { 0, NAME, 0, BSF_SECTION_SYM, SECTION }
738*fae548d3Szrj .#endif
739*fae548d3Szrj .
740*fae548d3Szrj */
741*fae548d3Szrj 
742*fae548d3Szrj /* These symbols are global, not specific to any BFD.  Therefore, anything
743*fae548d3Szrj    that tries to change them is broken, and should be repaired.  */
744*fae548d3Szrj 
745*fae548d3Szrj static const asymbol global_syms[] =
746*fae548d3Szrj {
747*fae548d3Szrj   GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, bfd_com_section_ptr),
748*fae548d3Szrj   GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, bfd_und_section_ptr),
749*fae548d3Szrj   GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, bfd_abs_section_ptr),
750*fae548d3Szrj   GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, bfd_ind_section_ptr)
751*fae548d3Szrj };
752*fae548d3Szrj 
753*fae548d3Szrj #define STD_SECTION(NAME, IDX, FLAGS) \
754*fae548d3Szrj   BFD_FAKE_SECTION(_bfd_std_section[IDX], &global_syms[IDX], NAME, IDX, FLAGS)
755*fae548d3Szrj 
756*fae548d3Szrj asection _bfd_std_section[] = {
757*fae548d3Szrj   STD_SECTION (BFD_COM_SECTION_NAME, 0, SEC_IS_COMMON),
758*fae548d3Szrj   STD_SECTION (BFD_UND_SECTION_NAME, 1, 0),
759*fae548d3Szrj   STD_SECTION (BFD_ABS_SECTION_NAME, 2, 0),
760*fae548d3Szrj   STD_SECTION (BFD_IND_SECTION_NAME, 3, 0)
761*fae548d3Szrj };
762*fae548d3Szrj #undef STD_SECTION
763*fae548d3Szrj 
764*fae548d3Szrj /* Initialize an entry in the section hash table.  */
765*fae548d3Szrj 
766*fae548d3Szrj struct bfd_hash_entry *
bfd_section_hash_newfunc(struct bfd_hash_entry * entry,struct bfd_hash_table * table,const char * string)767*fae548d3Szrj bfd_section_hash_newfunc (struct bfd_hash_entry *entry,
768*fae548d3Szrj 			  struct bfd_hash_table *table,
769*fae548d3Szrj 			  const char *string)
770*fae548d3Szrj {
771*fae548d3Szrj   /* Allocate the structure if it has not already been allocated by a
772*fae548d3Szrj      subclass.  */
773*fae548d3Szrj   if (entry == NULL)
774*fae548d3Szrj     {
775*fae548d3Szrj       entry = (struct bfd_hash_entry *)
776*fae548d3Szrj 	bfd_hash_allocate (table, sizeof (struct section_hash_entry));
777*fae548d3Szrj       if (entry == NULL)
778*fae548d3Szrj 	return entry;
779*fae548d3Szrj     }
780*fae548d3Szrj 
781*fae548d3Szrj   /* Call the allocation method of the superclass.  */
782*fae548d3Szrj   entry = bfd_hash_newfunc (entry, table, string);
783*fae548d3Szrj   if (entry != NULL)
784*fae548d3Szrj     memset (&((struct section_hash_entry *) entry)->section, 0,
785*fae548d3Szrj 	    sizeof (asection));
786*fae548d3Szrj 
787*fae548d3Szrj   return entry;
788*fae548d3Szrj }
789*fae548d3Szrj 
790*fae548d3Szrj #define section_hash_lookup(table, string, create, copy) \
791*fae548d3Szrj   ((struct section_hash_entry *) \
792*fae548d3Szrj    bfd_hash_lookup ((table), (string), (create), (copy)))
793*fae548d3Szrj 
794*fae548d3Szrj /* Create a symbol whose only job is to point to this section.  This
795*fae548d3Szrj    is useful for things like relocs which are relative to the base
796*fae548d3Szrj    of a section.  */
797*fae548d3Szrj 
798*fae548d3Szrj bfd_boolean
_bfd_generic_new_section_hook(bfd * abfd,asection * newsect)799*fae548d3Szrj _bfd_generic_new_section_hook (bfd *abfd, asection *newsect)
800*fae548d3Szrj {
801*fae548d3Szrj   newsect->symbol = bfd_make_empty_symbol (abfd);
802*fae548d3Szrj   if (newsect->symbol == NULL)
803*fae548d3Szrj     return FALSE;
804*fae548d3Szrj 
805*fae548d3Szrj   newsect->symbol->name = newsect->name;
806*fae548d3Szrj   newsect->symbol->value = 0;
807*fae548d3Szrj   newsect->symbol->section = newsect;
808*fae548d3Szrj   newsect->symbol->flags = BSF_SECTION_SYM;
809*fae548d3Szrj 
810*fae548d3Szrj   newsect->symbol_ptr_ptr = &newsect->symbol;
811*fae548d3Szrj   return TRUE;
812*fae548d3Szrj }
813*fae548d3Szrj 
814*fae548d3Szrj unsigned int _bfd_section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */
815*fae548d3Szrj 
816*fae548d3Szrj /* Initializes a new section.  NEWSECT->NAME is already set.  */
817*fae548d3Szrj 
818*fae548d3Szrj static asection *
bfd_section_init(bfd * abfd,asection * newsect)819*fae548d3Szrj bfd_section_init (bfd *abfd, asection *newsect)
820*fae548d3Szrj {
821*fae548d3Szrj   newsect->id = _bfd_section_id;
822*fae548d3Szrj   newsect->index = abfd->section_count;
823*fae548d3Szrj   newsect->owner = abfd;
824*fae548d3Szrj 
825*fae548d3Szrj   if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
826*fae548d3Szrj     return NULL;
827*fae548d3Szrj 
828*fae548d3Szrj   _bfd_section_id++;
829*fae548d3Szrj   abfd->section_count++;
830*fae548d3Szrj   bfd_section_list_append (abfd, newsect);
831*fae548d3Szrj   return newsect;
832*fae548d3Szrj }
833*fae548d3Szrj 
834*fae548d3Szrj /*
835*fae548d3Szrj DOCDD
836*fae548d3Szrj INODE
837*fae548d3Szrj section prototypes,  , typedef asection, Sections
838*fae548d3Szrj SUBSECTION
839*fae548d3Szrj 	Section prototypes
840*fae548d3Szrj 
841*fae548d3Szrj These are the functions exported by the section handling part of BFD.
842*fae548d3Szrj */
843*fae548d3Szrj 
844*fae548d3Szrj /*
845*fae548d3Szrj FUNCTION
846*fae548d3Szrj 	bfd_section_list_clear
847*fae548d3Szrj 
848*fae548d3Szrj SYNOPSIS
849*fae548d3Szrj 	void bfd_section_list_clear (bfd *);
850*fae548d3Szrj 
851*fae548d3Szrj DESCRIPTION
852*fae548d3Szrj 	Clears the section list, and also resets the section count and
853*fae548d3Szrj 	hash table entries.
854*fae548d3Szrj */
855*fae548d3Szrj 
856*fae548d3Szrj void
bfd_section_list_clear(bfd * abfd)857*fae548d3Szrj bfd_section_list_clear (bfd *abfd)
858*fae548d3Szrj {
859*fae548d3Szrj   abfd->sections = NULL;
860*fae548d3Szrj   abfd->section_last = NULL;
861*fae548d3Szrj   abfd->section_count = 0;
862*fae548d3Szrj   memset (abfd->section_htab.table, 0,
863*fae548d3Szrj 	  abfd->section_htab.size * sizeof (struct bfd_hash_entry *));
864*fae548d3Szrj   abfd->section_htab.count = 0;
865*fae548d3Szrj }
866*fae548d3Szrj 
867*fae548d3Szrj /*
868*fae548d3Szrj FUNCTION
869*fae548d3Szrj 	bfd_get_section_by_name
870*fae548d3Szrj 
871*fae548d3Szrj SYNOPSIS
872*fae548d3Szrj 	asection *bfd_get_section_by_name (bfd *abfd, const char *name);
873*fae548d3Szrj 
874*fae548d3Szrj DESCRIPTION
875*fae548d3Szrj 	Return the most recently created section attached to @var{abfd}
876*fae548d3Szrj 	named @var{name}.  Return NULL if no such section exists.
877*fae548d3Szrj */
878*fae548d3Szrj 
879*fae548d3Szrj asection *
bfd_get_section_by_name(bfd * abfd,const char * name)880*fae548d3Szrj bfd_get_section_by_name (bfd *abfd, const char *name)
881*fae548d3Szrj {
882*fae548d3Szrj   struct section_hash_entry *sh;
883*fae548d3Szrj 
884*fae548d3Szrj   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
885*fae548d3Szrj   if (sh != NULL)
886*fae548d3Szrj     return &sh->section;
887*fae548d3Szrj 
888*fae548d3Szrj   return NULL;
889*fae548d3Szrj }
890*fae548d3Szrj 
891*fae548d3Szrj /*
892*fae548d3Szrj FUNCTION
893*fae548d3Szrj        bfd_get_next_section_by_name
894*fae548d3Szrj 
895*fae548d3Szrj SYNOPSIS
896*fae548d3Szrj        asection *bfd_get_next_section_by_name (bfd *ibfd, asection *sec);
897*fae548d3Szrj 
898*fae548d3Szrj DESCRIPTION
899*fae548d3Szrj        Given @var{sec} is a section returned by @code{bfd_get_section_by_name},
900*fae548d3Szrj        return the next most recently created section attached to the same
901*fae548d3Szrj        BFD with the same name, or if no such section exists in the same BFD and
902*fae548d3Szrj        IBFD is non-NULL, the next section with the same name in any input
903*fae548d3Szrj        BFD following IBFD.  Return NULL on finding no section.
904*fae548d3Szrj */
905*fae548d3Szrj 
906*fae548d3Szrj asection *
bfd_get_next_section_by_name(bfd * ibfd,asection * sec)907*fae548d3Szrj bfd_get_next_section_by_name (bfd *ibfd, asection *sec)
908*fae548d3Szrj {
909*fae548d3Szrj   struct section_hash_entry *sh;
910*fae548d3Szrj   const char *name;
911*fae548d3Szrj   unsigned long hash;
912*fae548d3Szrj 
913*fae548d3Szrj   sh = ((struct section_hash_entry *)
914*fae548d3Szrj 	((char *) sec - offsetof (struct section_hash_entry, section)));
915*fae548d3Szrj 
916*fae548d3Szrj   hash = sh->root.hash;
917*fae548d3Szrj   name = sec->name;
918*fae548d3Szrj   for (sh = (struct section_hash_entry *) sh->root.next;
919*fae548d3Szrj        sh != NULL;
920*fae548d3Szrj        sh = (struct section_hash_entry *) sh->root.next)
921*fae548d3Szrj     if (sh->root.hash == hash
922*fae548d3Szrj        && strcmp (sh->root.string, name) == 0)
923*fae548d3Szrj       return &sh->section;
924*fae548d3Szrj 
925*fae548d3Szrj   if (ibfd != NULL)
926*fae548d3Szrj     {
927*fae548d3Szrj       while ((ibfd = ibfd->link.next) != NULL)
928*fae548d3Szrj 	{
929*fae548d3Szrj 	  asection *s = bfd_get_section_by_name (ibfd, name);
930*fae548d3Szrj 	  if (s != NULL)
931*fae548d3Szrj 	    return s;
932*fae548d3Szrj 	}
933*fae548d3Szrj     }
934*fae548d3Szrj 
935*fae548d3Szrj   return NULL;
936*fae548d3Szrj }
937*fae548d3Szrj 
938*fae548d3Szrj /*
939*fae548d3Szrj FUNCTION
940*fae548d3Szrj 	bfd_get_linker_section
941*fae548d3Szrj 
942*fae548d3Szrj SYNOPSIS
943*fae548d3Szrj 	asection *bfd_get_linker_section (bfd *abfd, const char *name);
944*fae548d3Szrj 
945*fae548d3Szrj DESCRIPTION
946*fae548d3Szrj 	Return the linker created section attached to @var{abfd}
947*fae548d3Szrj 	named @var{name}.  Return NULL if no such section exists.
948*fae548d3Szrj */
949*fae548d3Szrj 
950*fae548d3Szrj asection *
bfd_get_linker_section(bfd * abfd,const char * name)951*fae548d3Szrj bfd_get_linker_section (bfd *abfd, const char *name)
952*fae548d3Szrj {
953*fae548d3Szrj   asection *sec = bfd_get_section_by_name (abfd, name);
954*fae548d3Szrj 
955*fae548d3Szrj   while (sec != NULL && (sec->flags & SEC_LINKER_CREATED) == 0)
956*fae548d3Szrj     sec = bfd_get_next_section_by_name (NULL, sec);
957*fae548d3Szrj   return sec;
958*fae548d3Szrj }
959*fae548d3Szrj 
960*fae548d3Szrj /*
961*fae548d3Szrj FUNCTION
962*fae548d3Szrj 	bfd_get_section_by_name_if
963*fae548d3Szrj 
964*fae548d3Szrj SYNOPSIS
965*fae548d3Szrj 	asection *bfd_get_section_by_name_if
966*fae548d3Szrj 	  (bfd *abfd,
967*fae548d3Szrj 	   const char *name,
968*fae548d3Szrj 	   bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
969*fae548d3Szrj 	   void *obj);
970*fae548d3Szrj 
971*fae548d3Szrj DESCRIPTION
972*fae548d3Szrj 	Call the provided function @var{func} for each section
973*fae548d3Szrj 	attached to the BFD @var{abfd} whose name matches @var{name},
974*fae548d3Szrj 	passing @var{obj} as an argument. The function will be called
975*fae548d3Szrj 	as if by
976*fae548d3Szrj 
977*fae548d3Szrj |	func (abfd, the_section, obj);
978*fae548d3Szrj 
979*fae548d3Szrj 	It returns the first section for which @var{func} returns true,
980*fae548d3Szrj 	otherwise <<NULL>>.
981*fae548d3Szrj 
982*fae548d3Szrj */
983*fae548d3Szrj 
984*fae548d3Szrj asection *
bfd_get_section_by_name_if(bfd * abfd,const char * name,bfd_boolean (* operation)(bfd *,asection *,void *),void * user_storage)985*fae548d3Szrj bfd_get_section_by_name_if (bfd *abfd, const char *name,
986*fae548d3Szrj 			    bfd_boolean (*operation) (bfd *,
987*fae548d3Szrj 						      asection *,
988*fae548d3Szrj 						      void *),
989*fae548d3Szrj 			    void *user_storage)
990*fae548d3Szrj {
991*fae548d3Szrj   struct section_hash_entry *sh;
992*fae548d3Szrj   unsigned long hash;
993*fae548d3Szrj 
994*fae548d3Szrj   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
995*fae548d3Szrj   if (sh == NULL)
996*fae548d3Szrj     return NULL;
997*fae548d3Szrj 
998*fae548d3Szrj   hash = sh->root.hash;
999*fae548d3Szrj   for (; sh != NULL; sh = (struct section_hash_entry *) sh->root.next)
1000*fae548d3Szrj     if (sh->root.hash == hash
1001*fae548d3Szrj 	&& strcmp (sh->root.string, name) == 0
1002*fae548d3Szrj 	&& (*operation) (abfd, &sh->section, user_storage))
1003*fae548d3Szrj       return &sh->section;
1004*fae548d3Szrj 
1005*fae548d3Szrj   return NULL;
1006*fae548d3Szrj }
1007*fae548d3Szrj 
1008*fae548d3Szrj /*
1009*fae548d3Szrj FUNCTION
1010*fae548d3Szrj 	bfd_get_unique_section_name
1011*fae548d3Szrj 
1012*fae548d3Szrj SYNOPSIS
1013*fae548d3Szrj 	char *bfd_get_unique_section_name
1014*fae548d3Szrj 	  (bfd *abfd, const char *templat, int *count);
1015*fae548d3Szrj 
1016*fae548d3Szrj DESCRIPTION
1017*fae548d3Szrj 	Invent a section name that is unique in @var{abfd} by tacking
1018*fae548d3Szrj 	a dot and a digit suffix onto the original @var{templat}.  If
1019*fae548d3Szrj 	@var{count} is non-NULL, then it specifies the first number
1020*fae548d3Szrj 	tried as a suffix to generate a unique name.  The value
1021*fae548d3Szrj 	pointed to by @var{count} will be incremented in this case.
1022*fae548d3Szrj */
1023*fae548d3Szrj 
1024*fae548d3Szrj char *
bfd_get_unique_section_name(bfd * abfd,const char * templat,int * count)1025*fae548d3Szrj bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count)
1026*fae548d3Szrj {
1027*fae548d3Szrj   int num;
1028*fae548d3Szrj   unsigned int len;
1029*fae548d3Szrj   char *sname;
1030*fae548d3Szrj 
1031*fae548d3Szrj   len = strlen (templat);
1032*fae548d3Szrj   sname = (char *) bfd_malloc (len + 8);
1033*fae548d3Szrj   if (sname == NULL)
1034*fae548d3Szrj     return NULL;
1035*fae548d3Szrj   memcpy (sname, templat, len);
1036*fae548d3Szrj   num = 1;
1037*fae548d3Szrj   if (count != NULL)
1038*fae548d3Szrj     num = *count;
1039*fae548d3Szrj 
1040*fae548d3Szrj   do
1041*fae548d3Szrj     {
1042*fae548d3Szrj       /* If we have a million sections, something is badly wrong.  */
1043*fae548d3Szrj       if (num > 999999)
1044*fae548d3Szrj 	abort ();
1045*fae548d3Szrj       sprintf (sname + len, ".%d", num++);
1046*fae548d3Szrj     }
1047*fae548d3Szrj   while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE));
1048*fae548d3Szrj 
1049*fae548d3Szrj   if (count != NULL)
1050*fae548d3Szrj     *count = num;
1051*fae548d3Szrj   return sname;
1052*fae548d3Szrj }
1053*fae548d3Szrj 
1054*fae548d3Szrj /*
1055*fae548d3Szrj FUNCTION
1056*fae548d3Szrj 	bfd_make_section_old_way
1057*fae548d3Szrj 
1058*fae548d3Szrj SYNOPSIS
1059*fae548d3Szrj 	asection *bfd_make_section_old_way (bfd *abfd, const char *name);
1060*fae548d3Szrj 
1061*fae548d3Szrj DESCRIPTION
1062*fae548d3Szrj 	Create a new empty section called @var{name}
1063*fae548d3Szrj 	and attach it to the end of the chain of sections for the
1064*fae548d3Szrj 	BFD @var{abfd}. An attempt to create a section with a name which
1065*fae548d3Szrj 	is already in use returns its pointer without changing the
1066*fae548d3Szrj 	section chain.
1067*fae548d3Szrj 
1068*fae548d3Szrj 	It has the funny name since this is the way it used to be
1069*fae548d3Szrj 	before it was rewritten....
1070*fae548d3Szrj 
1071*fae548d3Szrj 	Possible errors are:
1072*fae548d3Szrj 	o <<bfd_error_invalid_operation>> -
1073*fae548d3Szrj 	If output has already started for this BFD.
1074*fae548d3Szrj 	o <<bfd_error_no_memory>> -
1075*fae548d3Szrj 	If memory allocation fails.
1076*fae548d3Szrj 
1077*fae548d3Szrj */
1078*fae548d3Szrj 
1079*fae548d3Szrj asection *
bfd_make_section_old_way(bfd * abfd,const char * name)1080*fae548d3Szrj bfd_make_section_old_way (bfd *abfd, const char *name)
1081*fae548d3Szrj {
1082*fae548d3Szrj   asection *newsect;
1083*fae548d3Szrj 
1084*fae548d3Szrj   if (abfd->output_has_begun)
1085*fae548d3Szrj     {
1086*fae548d3Szrj       bfd_set_error (bfd_error_invalid_operation);
1087*fae548d3Szrj       return NULL;
1088*fae548d3Szrj     }
1089*fae548d3Szrj 
1090*fae548d3Szrj   if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
1091*fae548d3Szrj     newsect = bfd_abs_section_ptr;
1092*fae548d3Szrj   else if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
1093*fae548d3Szrj     newsect = bfd_com_section_ptr;
1094*fae548d3Szrj   else if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
1095*fae548d3Szrj     newsect = bfd_und_section_ptr;
1096*fae548d3Szrj   else if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
1097*fae548d3Szrj     newsect = bfd_ind_section_ptr;
1098*fae548d3Szrj   else
1099*fae548d3Szrj     {
1100*fae548d3Szrj       struct section_hash_entry *sh;
1101*fae548d3Szrj 
1102*fae548d3Szrj       sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
1103*fae548d3Szrj       if (sh == NULL)
1104*fae548d3Szrj 	return NULL;
1105*fae548d3Szrj 
1106*fae548d3Szrj       newsect = &sh->section;
1107*fae548d3Szrj       if (newsect->name != NULL)
1108*fae548d3Szrj 	{
1109*fae548d3Szrj 	  /* Section already exists.  */
1110*fae548d3Szrj 	  return newsect;
1111*fae548d3Szrj 	}
1112*fae548d3Szrj 
1113*fae548d3Szrj       newsect->name = name;
1114*fae548d3Szrj       return bfd_section_init (abfd, newsect);
1115*fae548d3Szrj     }
1116*fae548d3Szrj 
1117*fae548d3Szrj   /* Call new_section_hook when "creating" the standard abs, com, und
1118*fae548d3Szrj      and ind sections to tack on format specific section data.
1119*fae548d3Szrj      Also, create a proper section symbol.  */
1120*fae548d3Szrj   if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
1121*fae548d3Szrj     return NULL;
1122*fae548d3Szrj   return newsect;
1123*fae548d3Szrj }
1124*fae548d3Szrj 
1125*fae548d3Szrj /*
1126*fae548d3Szrj FUNCTION
1127*fae548d3Szrj 	bfd_make_section_anyway_with_flags
1128*fae548d3Szrj 
1129*fae548d3Szrj SYNOPSIS
1130*fae548d3Szrj 	asection *bfd_make_section_anyway_with_flags
1131*fae548d3Szrj 	  (bfd *abfd, const char *name, flagword flags);
1132*fae548d3Szrj 
1133*fae548d3Szrj DESCRIPTION
1134*fae548d3Szrj    Create a new empty section called @var{name} and attach it to the end of
1135*fae548d3Szrj    the chain of sections for @var{abfd}.  Create a new section even if there
1136*fae548d3Szrj    is already a section with that name.  Also set the attributes of the
1137*fae548d3Szrj    new section to the value @var{flags}.
1138*fae548d3Szrj 
1139*fae548d3Szrj    Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
1140*fae548d3Szrj    o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
1141*fae548d3Szrj    o <<bfd_error_no_memory>> - If memory allocation fails.
1142*fae548d3Szrj */
1143*fae548d3Szrj 
1144*fae548d3Szrj sec_ptr
bfd_make_section_anyway_with_flags(bfd * abfd,const char * name,flagword flags)1145*fae548d3Szrj bfd_make_section_anyway_with_flags (bfd *abfd, const char *name,
1146*fae548d3Szrj 				    flagword flags)
1147*fae548d3Szrj {
1148*fae548d3Szrj   struct section_hash_entry *sh;
1149*fae548d3Szrj   asection *newsect;
1150*fae548d3Szrj 
1151*fae548d3Szrj   if (abfd->output_has_begun)
1152*fae548d3Szrj     {
1153*fae548d3Szrj       bfd_set_error (bfd_error_invalid_operation);
1154*fae548d3Szrj       return NULL;
1155*fae548d3Szrj     }
1156*fae548d3Szrj 
1157*fae548d3Szrj   sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
1158*fae548d3Szrj   if (sh == NULL)
1159*fae548d3Szrj     return NULL;
1160*fae548d3Szrj 
1161*fae548d3Szrj   newsect = &sh->section;
1162*fae548d3Szrj   if (newsect->name != NULL)
1163*fae548d3Szrj     {
1164*fae548d3Szrj       /* We are making a section of the same name.  Put it in the
1165*fae548d3Szrj 	 section hash table.  Even though we can't find it directly by a
1166*fae548d3Szrj 	 hash lookup, we'll be able to find the section by traversing
1167*fae548d3Szrj 	 sh->root.next quicker than looking at all the bfd sections.  */
1168*fae548d3Szrj       struct section_hash_entry *new_sh;
1169*fae548d3Szrj       new_sh = (struct section_hash_entry *)
1170*fae548d3Szrj 	bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
1171*fae548d3Szrj       if (new_sh == NULL)
1172*fae548d3Szrj 	return NULL;
1173*fae548d3Szrj 
1174*fae548d3Szrj       new_sh->root = sh->root;
1175*fae548d3Szrj       sh->root.next = &new_sh->root;
1176*fae548d3Szrj       newsect = &new_sh->section;
1177*fae548d3Szrj     }
1178*fae548d3Szrj 
1179*fae548d3Szrj   newsect->flags = flags;
1180*fae548d3Szrj   newsect->name = name;
1181*fae548d3Szrj   return bfd_section_init (abfd, newsect);
1182*fae548d3Szrj }
1183*fae548d3Szrj 
1184*fae548d3Szrj /*
1185*fae548d3Szrj FUNCTION
1186*fae548d3Szrj 	bfd_make_section_anyway
1187*fae548d3Szrj 
1188*fae548d3Szrj SYNOPSIS
1189*fae548d3Szrj 	asection *bfd_make_section_anyway (bfd *abfd, const char *name);
1190*fae548d3Szrj 
1191*fae548d3Szrj DESCRIPTION
1192*fae548d3Szrj    Create a new empty section called @var{name} and attach it to the end of
1193*fae548d3Szrj    the chain of sections for @var{abfd}.  Create a new section even if there
1194*fae548d3Szrj    is already a section with that name.
1195*fae548d3Szrj 
1196*fae548d3Szrj    Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
1197*fae548d3Szrj    o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
1198*fae548d3Szrj    o <<bfd_error_no_memory>> - If memory allocation fails.
1199*fae548d3Szrj */
1200*fae548d3Szrj 
1201*fae548d3Szrj sec_ptr
bfd_make_section_anyway(bfd * abfd,const char * name)1202*fae548d3Szrj bfd_make_section_anyway (bfd *abfd, const char *name)
1203*fae548d3Szrj {
1204*fae548d3Szrj   return bfd_make_section_anyway_with_flags (abfd, name, 0);
1205*fae548d3Szrj }
1206*fae548d3Szrj 
1207*fae548d3Szrj /*
1208*fae548d3Szrj FUNCTION
1209*fae548d3Szrj 	bfd_make_section_with_flags
1210*fae548d3Szrj 
1211*fae548d3Szrj SYNOPSIS
1212*fae548d3Szrj 	asection *bfd_make_section_with_flags
1213*fae548d3Szrj 	  (bfd *, const char *name, flagword flags);
1214*fae548d3Szrj 
1215*fae548d3Szrj DESCRIPTION
1216*fae548d3Szrj    Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
1217*fae548d3Szrj    bfd_set_error ()) without changing the section chain if there is already a
1218*fae548d3Szrj    section named @var{name}.  Also set the attributes of the new section to
1219*fae548d3Szrj    the value @var{flags}.  If there is an error, return <<NULL>> and set
1220*fae548d3Szrj    <<bfd_error>>.
1221*fae548d3Szrj */
1222*fae548d3Szrj 
1223*fae548d3Szrj asection *
bfd_make_section_with_flags(bfd * abfd,const char * name,flagword flags)1224*fae548d3Szrj bfd_make_section_with_flags (bfd *abfd, const char *name,
1225*fae548d3Szrj 			     flagword flags)
1226*fae548d3Szrj {
1227*fae548d3Szrj   struct section_hash_entry *sh;
1228*fae548d3Szrj   asection *newsect;
1229*fae548d3Szrj 
1230*fae548d3Szrj   if (abfd == NULL || name == NULL || abfd->output_has_begun)
1231*fae548d3Szrj     {
1232*fae548d3Szrj       bfd_set_error (bfd_error_invalid_operation);
1233*fae548d3Szrj       return NULL;
1234*fae548d3Szrj     }
1235*fae548d3Szrj 
1236*fae548d3Szrj   if (strcmp (name, BFD_ABS_SECTION_NAME) == 0
1237*fae548d3Szrj       || strcmp (name, BFD_COM_SECTION_NAME) == 0
1238*fae548d3Szrj       || strcmp (name, BFD_UND_SECTION_NAME) == 0
1239*fae548d3Szrj       || strcmp (name, BFD_IND_SECTION_NAME) == 0)
1240*fae548d3Szrj     return NULL;
1241*fae548d3Szrj 
1242*fae548d3Szrj   sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
1243*fae548d3Szrj   if (sh == NULL)
1244*fae548d3Szrj     return NULL;
1245*fae548d3Szrj 
1246*fae548d3Szrj   newsect = &sh->section;
1247*fae548d3Szrj   if (newsect->name != NULL)
1248*fae548d3Szrj     {
1249*fae548d3Szrj       /* Section already exists.  */
1250*fae548d3Szrj       return NULL;
1251*fae548d3Szrj     }
1252*fae548d3Szrj 
1253*fae548d3Szrj   newsect->name = name;
1254*fae548d3Szrj   newsect->flags = flags;
1255*fae548d3Szrj   return bfd_section_init (abfd, newsect);
1256*fae548d3Szrj }
1257*fae548d3Szrj 
1258*fae548d3Szrj /*
1259*fae548d3Szrj FUNCTION
1260*fae548d3Szrj 	bfd_make_section
1261*fae548d3Szrj 
1262*fae548d3Szrj SYNOPSIS
1263*fae548d3Szrj 	asection *bfd_make_section (bfd *, const char *name);
1264*fae548d3Szrj 
1265*fae548d3Szrj DESCRIPTION
1266*fae548d3Szrj    Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
1267*fae548d3Szrj    bfd_set_error ()) without changing the section chain if there is already a
1268*fae548d3Szrj    section named @var{name}.  If there is an error, return <<NULL>> and set
1269*fae548d3Szrj    <<bfd_error>>.
1270*fae548d3Szrj */
1271*fae548d3Szrj 
1272*fae548d3Szrj asection *
bfd_make_section(bfd * abfd,const char * name)1273*fae548d3Szrj bfd_make_section (bfd *abfd, const char *name)
1274*fae548d3Szrj {
1275*fae548d3Szrj   return bfd_make_section_with_flags (abfd, name, 0);
1276*fae548d3Szrj }
1277*fae548d3Szrj 
1278*fae548d3Szrj /*
1279*fae548d3Szrj FUNCTION
1280*fae548d3Szrj 	bfd_set_section_flags
1281*fae548d3Szrj 
1282*fae548d3Szrj SYNOPSIS
1283*fae548d3Szrj 	bfd_boolean bfd_set_section_flags (asection *sec, flagword flags);
1284*fae548d3Szrj 
1285*fae548d3Szrj DESCRIPTION
1286*fae548d3Szrj 	Set the attributes of the section @var{sec} to the value @var{flags}.
1287*fae548d3Szrj 	Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
1288*fae548d3Szrj 	returns are:
1289*fae548d3Szrj 
1290*fae548d3Szrj 	o <<bfd_error_invalid_operation>> -
1291*fae548d3Szrj 	The section cannot have one or more of the attributes
1292*fae548d3Szrj 	requested. For example, a .bss section in <<a.out>> may not
1293*fae548d3Szrj 	have the <<SEC_HAS_CONTENTS>> field set.
1294*fae548d3Szrj 
1295*fae548d3Szrj */
1296*fae548d3Szrj 
1297*fae548d3Szrj bfd_boolean
bfd_set_section_flags(asection * section,flagword flags)1298*fae548d3Szrj bfd_set_section_flags (asection *section, flagword flags)
1299*fae548d3Szrj {
1300*fae548d3Szrj   section->flags = flags;
1301*fae548d3Szrj   return TRUE;
1302*fae548d3Szrj }
1303*fae548d3Szrj 
1304*fae548d3Szrj /*
1305*fae548d3Szrj FUNCTION
1306*fae548d3Szrj 	bfd_rename_section
1307*fae548d3Szrj 
1308*fae548d3Szrj SYNOPSIS
1309*fae548d3Szrj 	void bfd_rename_section
1310*fae548d3Szrj 	  (asection *sec, const char *newname);
1311*fae548d3Szrj 
1312*fae548d3Szrj DESCRIPTION
1313*fae548d3Szrj 	Rename section @var{sec} to @var{newname}.
1314*fae548d3Szrj */
1315*fae548d3Szrj 
1316*fae548d3Szrj void
bfd_rename_section(asection * sec,const char * newname)1317*fae548d3Szrj bfd_rename_section (asection *sec, const char *newname)
1318*fae548d3Szrj {
1319*fae548d3Szrj   struct section_hash_entry *sh;
1320*fae548d3Szrj 
1321*fae548d3Szrj   sh = (struct section_hash_entry *)
1322*fae548d3Szrj     ((char *) sec - offsetof (struct section_hash_entry, section));
1323*fae548d3Szrj   sh->section.name = newname;
1324*fae548d3Szrj   bfd_hash_rename (&sec->owner->section_htab, newname, &sh->root);
1325*fae548d3Szrj }
1326*fae548d3Szrj 
1327*fae548d3Szrj /*
1328*fae548d3Szrj FUNCTION
1329*fae548d3Szrj 	bfd_map_over_sections
1330*fae548d3Szrj 
1331*fae548d3Szrj SYNOPSIS
1332*fae548d3Szrj 	void bfd_map_over_sections
1333*fae548d3Szrj 	  (bfd *abfd,
1334*fae548d3Szrj 	   void (*func) (bfd *abfd, asection *sect, void *obj),
1335*fae548d3Szrj 	   void *obj);
1336*fae548d3Szrj 
1337*fae548d3Szrj DESCRIPTION
1338*fae548d3Szrj 	Call the provided function @var{func} for each section
1339*fae548d3Szrj 	attached to the BFD @var{abfd}, passing @var{obj} as an
1340*fae548d3Szrj 	argument. The function will be called as if by
1341*fae548d3Szrj 
1342*fae548d3Szrj |	func (abfd, the_section, obj);
1343*fae548d3Szrj 
1344*fae548d3Szrj 	This is the preferred method for iterating over sections; an
1345*fae548d3Szrj 	alternative would be to use a loop:
1346*fae548d3Szrj 
1347*fae548d3Szrj |	   asection *p;
1348*fae548d3Szrj |	   for (p = abfd->sections; p != NULL; p = p->next)
1349*fae548d3Szrj |	      func (abfd, p, ...)
1350*fae548d3Szrj 
1351*fae548d3Szrj */
1352*fae548d3Szrj 
1353*fae548d3Szrj void
bfd_map_over_sections(bfd * abfd,void (* operation)(bfd *,asection *,void *),void * user_storage)1354*fae548d3Szrj bfd_map_over_sections (bfd *abfd,
1355*fae548d3Szrj 		       void (*operation) (bfd *, asection *, void *),
1356*fae548d3Szrj 		       void *user_storage)
1357*fae548d3Szrj {
1358*fae548d3Szrj   asection *sect;
1359*fae548d3Szrj   unsigned int i = 0;
1360*fae548d3Szrj 
1361*fae548d3Szrj   for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
1362*fae548d3Szrj     (*operation) (abfd, sect, user_storage);
1363*fae548d3Szrj 
1364*fae548d3Szrj   if (i != abfd->section_count)	/* Debugging */
1365*fae548d3Szrj     abort ();
1366*fae548d3Szrj }
1367*fae548d3Szrj 
1368*fae548d3Szrj /*
1369*fae548d3Szrj FUNCTION
1370*fae548d3Szrj 	bfd_sections_find_if
1371*fae548d3Szrj 
1372*fae548d3Szrj SYNOPSIS
1373*fae548d3Szrj 	asection *bfd_sections_find_if
1374*fae548d3Szrj 	  (bfd *abfd,
1375*fae548d3Szrj 	   bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
1376*fae548d3Szrj 	   void *obj);
1377*fae548d3Szrj 
1378*fae548d3Szrj DESCRIPTION
1379*fae548d3Szrj 	Call the provided function @var{operation} for each section
1380*fae548d3Szrj 	attached to the BFD @var{abfd}, passing @var{obj} as an
1381*fae548d3Szrj 	argument. The function will be called as if by
1382*fae548d3Szrj 
1383*fae548d3Szrj |	operation (abfd, the_section, obj);
1384*fae548d3Szrj 
1385*fae548d3Szrj 	It returns the first section for which @var{operation} returns true.
1386*fae548d3Szrj 
1387*fae548d3Szrj */
1388*fae548d3Szrj 
1389*fae548d3Szrj asection *
bfd_sections_find_if(bfd * abfd,bfd_boolean (* operation)(bfd *,asection *,void *),void * user_storage)1390*fae548d3Szrj bfd_sections_find_if (bfd *abfd,
1391*fae548d3Szrj 		      bfd_boolean (*operation) (bfd *, asection *, void *),
1392*fae548d3Szrj 		      void *user_storage)
1393*fae548d3Szrj {
1394*fae548d3Szrj   asection *sect;
1395*fae548d3Szrj 
1396*fae548d3Szrj   for (sect = abfd->sections; sect != NULL; sect = sect->next)
1397*fae548d3Szrj     if ((*operation) (abfd, sect, user_storage))
1398*fae548d3Szrj       break;
1399*fae548d3Szrj 
1400*fae548d3Szrj   return sect;
1401*fae548d3Szrj }
1402*fae548d3Szrj 
1403*fae548d3Szrj /*
1404*fae548d3Szrj FUNCTION
1405*fae548d3Szrj 	bfd_set_section_size
1406*fae548d3Szrj 
1407*fae548d3Szrj SYNOPSIS
1408*fae548d3Szrj 	bfd_boolean bfd_set_section_size (asection *sec, bfd_size_type val);
1409*fae548d3Szrj 
1410*fae548d3Szrj DESCRIPTION
1411*fae548d3Szrj 	Set @var{sec} to the size @var{val}. If the operation is
1412*fae548d3Szrj 	ok, then <<TRUE>> is returned, else <<FALSE>>.
1413*fae548d3Szrj 
1414*fae548d3Szrj 	Possible error returns:
1415*fae548d3Szrj 	o <<bfd_error_invalid_operation>> -
1416*fae548d3Szrj 	Writing has started to the BFD, so setting the size is invalid.
1417*fae548d3Szrj 
1418*fae548d3Szrj */
1419*fae548d3Szrj 
1420*fae548d3Szrj bfd_boolean
bfd_set_section_size(asection * sec,bfd_size_type val)1421*fae548d3Szrj bfd_set_section_size (asection *sec, bfd_size_type val)
1422*fae548d3Szrj {
1423*fae548d3Szrj   /* Once you've started writing to any section you cannot create or change
1424*fae548d3Szrj      the size of any others.  */
1425*fae548d3Szrj 
1426*fae548d3Szrj   if (sec->owner == NULL || sec->owner->output_has_begun)
1427*fae548d3Szrj     {
1428*fae548d3Szrj       bfd_set_error (bfd_error_invalid_operation);
1429*fae548d3Szrj       return FALSE;
1430*fae548d3Szrj     }
1431*fae548d3Szrj 
1432*fae548d3Szrj   sec->size = val;
1433*fae548d3Szrj   return TRUE;
1434*fae548d3Szrj }
1435*fae548d3Szrj 
1436*fae548d3Szrj /*
1437*fae548d3Szrj FUNCTION
1438*fae548d3Szrj 	bfd_set_section_contents
1439*fae548d3Szrj 
1440*fae548d3Szrj SYNOPSIS
1441*fae548d3Szrj 	bfd_boolean bfd_set_section_contents
1442*fae548d3Szrj 	  (bfd *abfd, asection *section, const void *data,
1443*fae548d3Szrj 	   file_ptr offset, bfd_size_type count);
1444*fae548d3Szrj 
1445*fae548d3Szrj DESCRIPTION
1446*fae548d3Szrj 	Sets the contents of the section @var{section} in BFD
1447*fae548d3Szrj 	@var{abfd} to the data starting in memory at @var{location}.
1448*fae548d3Szrj 	The data is written to the output section starting at offset
1449*fae548d3Szrj 	@var{offset} for @var{count} octets.
1450*fae548d3Szrj 
1451*fae548d3Szrj 	Normally <<TRUE>> is returned, but <<FALSE>> is returned if
1452*fae548d3Szrj 	there was an error.  Possible error returns are:
1453*fae548d3Szrj 	o <<bfd_error_no_contents>> -
1454*fae548d3Szrj 	The output section does not have the <<SEC_HAS_CONTENTS>>
1455*fae548d3Szrj 	attribute, so nothing can be written to it.
1456*fae548d3Szrj 	o <<bfd_error_bad_value>> -
1457*fae548d3Szrj 	The section is unable to contain all of the data.
1458*fae548d3Szrj 	o <<bfd_error_invalid_operation>> -
1459*fae548d3Szrj 	The BFD is not writeable.
1460*fae548d3Szrj 	o and some more too.
1461*fae548d3Szrj 
1462*fae548d3Szrj 	This routine is front end to the back end function
1463*fae548d3Szrj 	<<_bfd_set_section_contents>>.
1464*fae548d3Szrj 
1465*fae548d3Szrj */
1466*fae548d3Szrj 
1467*fae548d3Szrj bfd_boolean
bfd_set_section_contents(bfd * abfd,sec_ptr section,const void * location,file_ptr offset,bfd_size_type count)1468*fae548d3Szrj bfd_set_section_contents (bfd *abfd,
1469*fae548d3Szrj 			  sec_ptr section,
1470*fae548d3Szrj 			  const void *location,
1471*fae548d3Szrj 			  file_ptr offset,
1472*fae548d3Szrj 			  bfd_size_type count)
1473*fae548d3Szrj {
1474*fae548d3Szrj   bfd_size_type sz;
1475*fae548d3Szrj 
1476*fae548d3Szrj   if (!(bfd_section_flags (section) & SEC_HAS_CONTENTS))
1477*fae548d3Szrj     {
1478*fae548d3Szrj       bfd_set_error (bfd_error_no_contents);
1479*fae548d3Szrj       return FALSE;
1480*fae548d3Szrj     }
1481*fae548d3Szrj 
1482*fae548d3Szrj   sz = section->size;
1483*fae548d3Szrj   if ((bfd_size_type) offset > sz
1484*fae548d3Szrj       || count > sz
1485*fae548d3Szrj       || offset + count > sz
1486*fae548d3Szrj       || count != (size_t) count)
1487*fae548d3Szrj     {
1488*fae548d3Szrj       bfd_set_error (bfd_error_bad_value);
1489*fae548d3Szrj       return FALSE;
1490*fae548d3Szrj     }
1491*fae548d3Szrj 
1492*fae548d3Szrj   if (!bfd_write_p (abfd))
1493*fae548d3Szrj     {
1494*fae548d3Szrj       bfd_set_error (bfd_error_invalid_operation);
1495*fae548d3Szrj       return FALSE;
1496*fae548d3Szrj     }
1497*fae548d3Szrj 
1498*fae548d3Szrj   /* Record a copy of the data in memory if desired.  */
1499*fae548d3Szrj   if (section->contents
1500*fae548d3Szrj       && location != section->contents + offset)
1501*fae548d3Szrj     memcpy (section->contents + offset, location, (size_t) count);
1502*fae548d3Szrj 
1503*fae548d3Szrj   if (BFD_SEND (abfd, _bfd_set_section_contents,
1504*fae548d3Szrj 		(abfd, section, location, offset, count)))
1505*fae548d3Szrj     {
1506*fae548d3Szrj       abfd->output_has_begun = TRUE;
1507*fae548d3Szrj       return TRUE;
1508*fae548d3Szrj     }
1509*fae548d3Szrj 
1510*fae548d3Szrj   return FALSE;
1511*fae548d3Szrj }
1512*fae548d3Szrj 
1513*fae548d3Szrj /*
1514*fae548d3Szrj FUNCTION
1515*fae548d3Szrj 	bfd_get_section_contents
1516*fae548d3Szrj 
1517*fae548d3Szrj SYNOPSIS
1518*fae548d3Szrj 	bfd_boolean bfd_get_section_contents
1519*fae548d3Szrj 	  (bfd *abfd, asection *section, void *location, file_ptr offset,
1520*fae548d3Szrj 	   bfd_size_type count);
1521*fae548d3Szrj 
1522*fae548d3Szrj DESCRIPTION
1523*fae548d3Szrj 	Read data from @var{section} in BFD @var{abfd}
1524*fae548d3Szrj 	into memory starting at @var{location}. The data is read at an
1525*fae548d3Szrj 	offset of @var{offset} from the start of the input section,
1526*fae548d3Szrj 	and is read for @var{count} bytes.
1527*fae548d3Szrj 
1528*fae548d3Szrj 	If the contents of a constructor with the <<SEC_CONSTRUCTOR>>
1529*fae548d3Szrj 	flag set are requested or if the section does not have the
1530*fae548d3Szrj 	<<SEC_HAS_CONTENTS>> flag set, then the @var{location} is filled
1531*fae548d3Szrj 	with zeroes. If no errors occur, <<TRUE>> is returned, else
1532*fae548d3Szrj 	<<FALSE>>.
1533*fae548d3Szrj 
1534*fae548d3Szrj */
1535*fae548d3Szrj bfd_boolean
bfd_get_section_contents(bfd * abfd,sec_ptr section,void * location,file_ptr offset,bfd_size_type count)1536*fae548d3Szrj bfd_get_section_contents (bfd *abfd,
1537*fae548d3Szrj 			  sec_ptr section,
1538*fae548d3Szrj 			  void *location,
1539*fae548d3Szrj 			  file_ptr offset,
1540*fae548d3Szrj 			  bfd_size_type count)
1541*fae548d3Szrj {
1542*fae548d3Szrj   bfd_size_type sz;
1543*fae548d3Szrj 
1544*fae548d3Szrj   if (section->flags & SEC_CONSTRUCTOR)
1545*fae548d3Szrj     {
1546*fae548d3Szrj       memset (location, 0, (size_t) count);
1547*fae548d3Szrj       return TRUE;
1548*fae548d3Szrj     }
1549*fae548d3Szrj 
1550*fae548d3Szrj   if (abfd->direction != write_direction && section->rawsize != 0)
1551*fae548d3Szrj     sz = section->rawsize;
1552*fae548d3Szrj   else
1553*fae548d3Szrj     sz = section->size;
1554*fae548d3Szrj   if ((bfd_size_type) offset > sz
1555*fae548d3Szrj       || count > sz
1556*fae548d3Szrj       || offset + count > sz
1557*fae548d3Szrj       || count != (size_t) count)
1558*fae548d3Szrj     {
1559*fae548d3Szrj       bfd_set_error (bfd_error_bad_value);
1560*fae548d3Szrj       return FALSE;
1561*fae548d3Szrj     }
1562*fae548d3Szrj 
1563*fae548d3Szrj   if (count == 0)
1564*fae548d3Szrj     /* Don't bother.  */
1565*fae548d3Szrj     return TRUE;
1566*fae548d3Szrj 
1567*fae548d3Szrj   if ((section->flags & SEC_HAS_CONTENTS) == 0)
1568*fae548d3Szrj     {
1569*fae548d3Szrj       memset (location, 0, (size_t) count);
1570*fae548d3Szrj       return TRUE;
1571*fae548d3Szrj     }
1572*fae548d3Szrj 
1573*fae548d3Szrj   if ((section->flags & SEC_IN_MEMORY) != 0)
1574*fae548d3Szrj     {
1575*fae548d3Szrj       if (section->contents == NULL)
1576*fae548d3Szrj 	{
1577*fae548d3Szrj 	  /* This can happen because of errors earlier on in the linking process.
1578*fae548d3Szrj 	     We do not want to seg-fault here, so clear the flag and return an
1579*fae548d3Szrj 	     error code.  */
1580*fae548d3Szrj 	  section->flags &= ~ SEC_IN_MEMORY;
1581*fae548d3Szrj 	  bfd_set_error (bfd_error_invalid_operation);
1582*fae548d3Szrj 	  return FALSE;
1583*fae548d3Szrj 	}
1584*fae548d3Szrj 
1585*fae548d3Szrj       memmove (location, section->contents + offset, (size_t) count);
1586*fae548d3Szrj       return TRUE;
1587*fae548d3Szrj     }
1588*fae548d3Szrj 
1589*fae548d3Szrj   return BFD_SEND (abfd, _bfd_get_section_contents,
1590*fae548d3Szrj 		   (abfd, section, location, offset, count));
1591*fae548d3Szrj }
1592*fae548d3Szrj 
1593*fae548d3Szrj /*
1594*fae548d3Szrj FUNCTION
1595*fae548d3Szrj 	bfd_malloc_and_get_section
1596*fae548d3Szrj 
1597*fae548d3Szrj SYNOPSIS
1598*fae548d3Szrj 	bfd_boolean bfd_malloc_and_get_section
1599*fae548d3Szrj 	  (bfd *abfd, asection *section, bfd_byte **buf);
1600*fae548d3Szrj 
1601*fae548d3Szrj DESCRIPTION
1602*fae548d3Szrj 	Read all data from @var{section} in BFD @var{abfd}
1603*fae548d3Szrj 	into a buffer, *@var{buf}, malloc'd by this function.
1604*fae548d3Szrj */
1605*fae548d3Szrj 
1606*fae548d3Szrj bfd_boolean
bfd_malloc_and_get_section(bfd * abfd,sec_ptr sec,bfd_byte ** buf)1607*fae548d3Szrj bfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf)
1608*fae548d3Szrj {
1609*fae548d3Szrj   *buf = NULL;
1610*fae548d3Szrj   return bfd_get_full_section_contents (abfd, sec, buf);
1611*fae548d3Szrj }
1612*fae548d3Szrj /*
1613*fae548d3Szrj FUNCTION
1614*fae548d3Szrj 	bfd_copy_private_section_data
1615*fae548d3Szrj 
1616*fae548d3Szrj SYNOPSIS
1617*fae548d3Szrj 	bfd_boolean bfd_copy_private_section_data
1618*fae548d3Szrj 	  (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
1619*fae548d3Szrj 
1620*fae548d3Szrj DESCRIPTION
1621*fae548d3Szrj 	Copy private section information from @var{isec} in the BFD
1622*fae548d3Szrj 	@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
1623*fae548d3Szrj 	Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
1624*fae548d3Szrj 	returns are:
1625*fae548d3Szrj 
1626*fae548d3Szrj 	o <<bfd_error_no_memory>> -
1627*fae548d3Szrj 	Not enough memory exists to create private data for @var{osec}.
1628*fae548d3Szrj 
1629*fae548d3Szrj .#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
1630*fae548d3Szrj .	BFD_SEND (obfd, _bfd_copy_private_section_data, \
1631*fae548d3Szrj .		  (ibfd, isection, obfd, osection))
1632*fae548d3Szrj */
1633*fae548d3Szrj 
1634*fae548d3Szrj /*
1635*fae548d3Szrj FUNCTION
1636*fae548d3Szrj 	bfd_generic_is_group_section
1637*fae548d3Szrj 
1638*fae548d3Szrj SYNOPSIS
1639*fae548d3Szrj 	bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
1640*fae548d3Szrj 
1641*fae548d3Szrj DESCRIPTION
1642*fae548d3Szrj 	Returns TRUE if @var{sec} is a member of a group.
1643*fae548d3Szrj */
1644*fae548d3Szrj 
1645*fae548d3Szrj bfd_boolean
bfd_generic_is_group_section(bfd * abfd ATTRIBUTE_UNUSED,const asection * sec ATTRIBUTE_UNUSED)1646*fae548d3Szrj bfd_generic_is_group_section (bfd *abfd ATTRIBUTE_UNUSED,
1647*fae548d3Szrj 			      const asection *sec ATTRIBUTE_UNUSED)
1648*fae548d3Szrj {
1649*fae548d3Szrj   return FALSE;
1650*fae548d3Szrj }
1651*fae548d3Szrj 
1652*fae548d3Szrj /*
1653*fae548d3Szrj FUNCTION
1654*fae548d3Szrj 	bfd_generic_group_name
1655*fae548d3Szrj 
1656*fae548d3Szrj SYNOPSIS
1657*fae548d3Szrj 	const char *bfd_generic_group_name (bfd *, const asection *sec);
1658*fae548d3Szrj 
1659*fae548d3Szrj DESCRIPTION
1660*fae548d3Szrj 	Returns group name if @var{sec} is a member of a group.
1661*fae548d3Szrj */
1662*fae548d3Szrj 
1663*fae548d3Szrj const char *
bfd_generic_group_name(bfd * abfd ATTRIBUTE_UNUSED,const asection * sec ATTRIBUTE_UNUSED)1664*fae548d3Szrj bfd_generic_group_name (bfd *abfd ATTRIBUTE_UNUSED,
1665*fae548d3Szrj 			const asection *sec ATTRIBUTE_UNUSED)
1666*fae548d3Szrj {
1667*fae548d3Szrj   return NULL;
1668*fae548d3Szrj }
1669*fae548d3Szrj 
1670*fae548d3Szrj /*
1671*fae548d3Szrj FUNCTION
1672*fae548d3Szrj 	bfd_generic_discard_group
1673*fae548d3Szrj 
1674*fae548d3Szrj SYNOPSIS
1675*fae548d3Szrj 	bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
1676*fae548d3Szrj 
1677*fae548d3Szrj DESCRIPTION
1678*fae548d3Szrj 	Remove all members of @var{group} from the output.
1679*fae548d3Szrj */
1680*fae548d3Szrj 
1681*fae548d3Szrj bfd_boolean
bfd_generic_discard_group(bfd * abfd ATTRIBUTE_UNUSED,asection * group ATTRIBUTE_UNUSED)1682*fae548d3Szrj bfd_generic_discard_group (bfd *abfd ATTRIBUTE_UNUSED,
1683*fae548d3Szrj 			   asection *group ATTRIBUTE_UNUSED)
1684*fae548d3Szrj {
1685*fae548d3Szrj   return TRUE;
1686*fae548d3Szrj }
1687*fae548d3Szrj 
1688*fae548d3Szrj bfd_boolean
_bfd_nowrite_set_section_contents(bfd * abfd,sec_ptr section ATTRIBUTE_UNUSED,const void * location ATTRIBUTE_UNUSED,file_ptr offset ATTRIBUTE_UNUSED,bfd_size_type count ATTRIBUTE_UNUSED)1689*fae548d3Szrj _bfd_nowrite_set_section_contents (bfd *abfd,
1690*fae548d3Szrj 				   sec_ptr section ATTRIBUTE_UNUSED,
1691*fae548d3Szrj 				   const void *location ATTRIBUTE_UNUSED,
1692*fae548d3Szrj 				   file_ptr offset ATTRIBUTE_UNUSED,
1693*fae548d3Szrj 				   bfd_size_type count ATTRIBUTE_UNUSED)
1694*fae548d3Szrj {
1695*fae548d3Szrj   return _bfd_bool_bfd_false_error (abfd);
1696*fae548d3Szrj }
1697