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