Correct spelling of "relocatable".
[deliverable/binutils-gdb.git] / bfd / bfd.c
CommitLineData
252b5132 1/* Generic BFD library interface and support routines.
7898deda 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
ed781d5d 3 2000, 2001, 2002, 2003
252b5132
RH
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
6
3af9a47b 7 This file is part of BFD, the Binary File Descriptor library.
252b5132 8
3af9a47b
NC
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
252b5132 13
3af9a47b
NC
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
252b5132 18
3af9a47b
NC
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
252b5132
RH
22
23/*
24SECTION
25 <<typedef bfd>>
26
27 A BFD has type <<bfd>>; objects of this type are the
28 cornerstone of any application using BFD. Using BFD
29 consists of making references though the BFD and to data in the BFD.
30
31 Here is the structure that defines the type <<bfd>>. It
32 contains the major data about the file and pointers
33 to the rest of the data.
34
35CODE_FRAGMENT
36.
c2852e88 37.struct bfd
252b5132 38.{
52b69c9e
AO
39. {* A unique identifier of the BFD *}
40. unsigned int id;
41.
b5f79c76
NC
42. {* The filename the application opened the BFD with. *}
43. const char *filename;
252b5132 44.
b5f79c76
NC
45. {* A pointer to the target jump table. *}
46. const struct bfd_target *xvec;
252b5132 47.
b5f79c76
NC
48. {* To avoid dragging too many header files into every file that
49. includes `<<bfd.h>>', IOSTREAM has been declared as a "char *",
50. and MTIME as a "long". Their correct types, to which they
51. are cast when used, are "FILE *" and "time_t". The iostream
52. is the result of an fopen on the filename. However, if the
53. BFD_IN_MEMORY flag is set, then iostream is actually a pointer
54. to a bfd_in_memory struct. *}
55. PTR iostream;
56.
57. {* Is the file descriptor being cached? That is, can it be closed as
58. needed, and re-opened when accessed later? *}
b34976b6 59. bfd_boolean cacheable;
b5f79c76
NC
60.
61. {* Marks whether there was a default target specified when the
62. BFD was opened. This is used to select which matching algorithm
63. to use to choose the back end. *}
b34976b6 64. bfd_boolean target_defaulted;
b5f79c76
NC
65.
66. {* The caching routines use these to maintain a
67. least-recently-used list of BFDs. *}
2ce40c65 68. struct bfd *lru_prev, *lru_next;
b5f79c76
NC
69.
70. {* When a file is closed by the caching routines, BFD retains
71. state information on the file here... *}
72. ufile_ptr where;
73.
74. {* ... and here: (``once'' means at least once). *}
b34976b6 75. bfd_boolean opened_once;
b5f79c76
NC
76.
77. {* Set if we have a locally maintained mtime value, rather than
78. getting it from the file each time. *}
b34976b6 79. bfd_boolean mtime_set;
b5f79c76 80.
b34976b6 81. {* File modified time, if mtime_set is TRUE. *}
b5f79c76
NC
82. long mtime;
83.
84. {* Reserved for an unimplemented file locking extension. *}
85. int ifd;
86.
87. {* The format which belongs to the BFD. (object, core, etc.) *}
88. bfd_format format;
89.
90. {* The direction with which the BFD was opened. *}
91. enum bfd_direction
92. {
93. no_direction = 0,
94. read_direction = 1,
95. write_direction = 2,
96. both_direction = 3
97. }
98. direction;
99.
100. {* Format_specific flags. *}
101. flagword flags;
102.
103. {* Currently my_archive is tested before adding origin to
104. anything. I believe that this can become always an add of
105. origin, with origin set to 0 for non archive files. *}
106. ufile_ptr origin;
107.
108. {* Remember when output has begun, to stop strange things
109. from happening. *}
b34976b6 110. bfd_boolean output_has_begun;
b5f79c76
NC
111.
112. {* A hash table for section names. *}
113. struct bfd_hash_table section_htab;
114.
115. {* Pointer to linked list of sections. *}
116. struct sec *sections;
117.
118. {* The place where we add to the section list. *}
119. struct sec **section_tail;
120.
121. {* The number of sections. *}
122. unsigned int section_count;
123.
124. {* Stuff only useful for object files:
125. The start address. *}
126. bfd_vma start_address;
127.
128. {* Used for input and output. *}
129. unsigned int symcount;
130.
131. {* Symbol table for output BFD (with symcount entries). *}
132. struct symbol_cache_entry **outsymbols;
133.
1f70368c
DJ
134. {* Used for slurped dynamic symbol tables. *}
135. unsigned int dynsymcount;
136.
b5f79c76
NC
137. {* Pointer to structure which contains architecture information. *}
138. const struct bfd_arch_info *arch_info;
139.
140. {* Stuff only useful for archives. *}
141. PTR arelt_data;
2ce40c65
AM
142. struct bfd *my_archive; {* The containing archive BFD. *}
143. struct bfd *next; {* The next BFD in the archive. *}
144. struct bfd *archive_head; {* The first BFD in the archive. *}
b34976b6 145. bfd_boolean has_armap;
252b5132 146.
b5f79c76 147. {* A chain of BFD structures involved in a link. *}
2ce40c65 148. struct bfd *link_next;
b5f79c76
NC
149.
150. {* A field used by _bfd_generic_link_add_archive_symbols. This will
151. be used only for archive elements. *}
152. int archive_pass;
153.
154. {* Used by the back end to hold private data. *}
155. union
156. {
252b5132
RH
157. struct aout_data_struct *aout_data;
158. struct artdata *aout_ar_data;
159. struct _oasys_data *oasys_obj_data;
160. struct _oasys_ar_data *oasys_ar_data;
161. struct coff_tdata *coff_obj_data;
162. struct pe_tdata *pe_obj_data;
163. struct xcoff_tdata *xcoff_obj_data;
164. struct ecoff_tdata *ecoff_obj_data;
165. struct ieee_data_struct *ieee_data;
166. struct ieee_ar_data_struct *ieee_ar_data;
167. struct srec_data_struct *srec_data;
168. struct ihex_data_struct *ihex_data;
169. struct tekhex_data_struct *tekhex_data;
170. struct elf_obj_tdata *elf_obj_data;
171. struct nlm_obj_tdata *nlm_obj_data;
172. struct bout_data_struct *bout_data;
3c3bdf30 173. struct mmo_data_struct *mmo_data;
252b5132
RH
174. struct sun_core_struct *sun_core_data;
175. struct sco5_core_struct *sco5_core_data;
176. struct trad_core_struct *trad_core_data;
177. struct som_data_struct *som_data;
178. struct hpux_core_struct *hpux_core_data;
179. struct hppabsd_core_struct *hppabsd_core_data;
180. struct sgi_core_struct *sgi_core_data;
181. struct lynx_core_struct *lynx_core_data;
182. struct osf_core_struct *osf_core_data;
183. struct cisco_core_struct *cisco_core_data;
184. struct versados_data_struct *versados_data;
185. struct netbsd_core_struct *netbsd_core_data;
3af9a47b
NC
186. struct mach_o_data_struct *mach_o_data;
187. struct mach_o_fat_data_struct *mach_o_fat_data;
188. struct bfd_pef_data_struct *pef_data;
189. struct bfd_pef_xlib_data_struct *pef_xlib_data;
190. struct bfd_sym_data_struct *sym_data;
252b5132 191. PTR any;
b5f79c76
NC
192. }
193. tdata;
aebad5fe 194.
b5f79c76
NC
195. {* Used by the application to hold private data. *}
196. PTR usrdata;
252b5132
RH
197.
198. {* Where all the allocated stuff under this BFD goes. This is a
199. struct objalloc *, but we use PTR to avoid requiring the inclusion of
200. objalloc.h. *}
b5f79c76 201. PTR memory;
252b5132
RH
202.};
203.
204*/
205
206#include "bfd.h"
6a0735ef 207#include "bfdver.h"
252b5132
RH
208#include "sysdep.h"
209
210#ifdef ANSI_PROTOTYPES
211#include <stdarg.h>
212#else
213#include <varargs.h>
214#endif
215
216#include "libiberty.h"
3882b010 217#include "safe-ctype.h"
252b5132
RH
218#include "bfdlink.h"
219#include "libbfd.h"
220#include "coff/internal.h"
221#include "coff/sym.h"
222#include "libcoff.h"
223#include "libecoff.h"
224#undef obj_symbols
225#include "elf-bfd.h"
252b5132
RH
226\f
227/* provide storage for subsystem, stack and heap data which may have been
228 passed in on the command line. Ld puts this data into a bfd_link_info
229 struct which ultimately gets passed in to the bfd. When it arrives, copy
230 it to the following struct so that the data will be available in coffcode.h
231 where it is needed. The typedef's used are defined in bfd.h */
252b5132
RH
232\f
233/*
234SECTION
235 Error reporting
236
237 Most BFD functions return nonzero on success (check their
238 individual documentation for precise semantics). On an error,
239 they call <<bfd_set_error>> to set an error condition that callers
240 can check by calling <<bfd_get_error>>.
241 If that returns <<bfd_error_system_call>>, then check
242 <<errno>>.
243
244 The easiest way to report a BFD error to the user is to
245 use <<bfd_perror>>.
246
247SUBSECTION
248 Type <<bfd_error_type>>
249
250 The values returned by <<bfd_get_error>> are defined by the
251 enumerated type <<bfd_error_type>>.
252
253CODE_FRAGMENT
254.
255.typedef enum bfd_error
256.{
257. bfd_error_no_error = 0,
258. bfd_error_system_call,
259. bfd_error_invalid_target,
260. bfd_error_wrong_format,
3619ad04 261. bfd_error_wrong_object_format,
252b5132
RH
262. bfd_error_invalid_operation,
263. bfd_error_no_memory,
264. bfd_error_no_symbols,
265. bfd_error_no_armap,
266. bfd_error_no_more_archived_files,
267. bfd_error_malformed_archive,
268. bfd_error_file_not_recognized,
269. bfd_error_file_ambiguously_recognized,
270. bfd_error_no_contents,
271. bfd_error_nonrepresentable_section,
272. bfd_error_no_debug_section,
273. bfd_error_bad_value,
274. bfd_error_file_truncated,
275. bfd_error_file_too_big,
276. bfd_error_invalid_error_code
b5f79c76
NC
277.}
278.bfd_error_type;
252b5132
RH
279.
280*/
281
282static bfd_error_type bfd_error = bfd_error_no_error;
283
55ab10f0
NC
284const char *const bfd_errmsgs[] =
285{
286 N_("No error"),
287 N_("System call error"),
288 N_("Invalid bfd target"),
289 N_("File in wrong format"),
3619ad04 290 N_("Archive object file in wrong format"),
55ab10f0
NC
291 N_("Invalid operation"),
292 N_("Memory exhausted"),
293 N_("No symbols"),
294 N_("Archive has no index; run ranlib to add one"),
295 N_("No more archived files"),
296 N_("Malformed archive"),
297 N_("File format not recognized"),
298 N_("File format is ambiguous"),
299 N_("Section has no contents"),
300 N_("Nonrepresentable section on output"),
301 N_("Symbol needs debug section which does not exist"),
302 N_("Bad value"),
303 N_("File truncated"),
304 N_("File too big"),
305 N_("#<Invalid error code>")
306};
252b5132
RH
307
308/*
309FUNCTION
310 bfd_get_error
311
312SYNOPSIS
313 bfd_error_type bfd_get_error (void);
314
315DESCRIPTION
316 Return the current BFD error condition.
317*/
318
319bfd_error_type
320bfd_get_error ()
321{
322 return bfd_error;
323}
324
325/*
326FUNCTION
327 bfd_set_error
328
329SYNOPSIS
330 void bfd_set_error (bfd_error_type error_tag);
331
332DESCRIPTION
333 Set the BFD error condition to be @var{error_tag}.
334*/
335
336void
337bfd_set_error (error_tag)
338 bfd_error_type error_tag;
339{
340 bfd_error = error_tag;
341}
342
343/*
344FUNCTION
345 bfd_errmsg
346
347SYNOPSIS
55ab10f0 348 const char *bfd_errmsg (bfd_error_type error_tag);
252b5132
RH
349
350DESCRIPTION
351 Return a string describing the error @var{error_tag}, or
352 the system error if @var{error_tag} is <<bfd_error_system_call>>.
353*/
354
55ab10f0 355const char *
252b5132
RH
356bfd_errmsg (error_tag)
357 bfd_error_type error_tag;
358{
359#ifndef errno
360 extern int errno;
361#endif
362 if (error_tag == bfd_error_system_call)
363 return xstrerror (errno);
364
55ab10f0
NC
365 if ((((int) error_tag < (int) bfd_error_no_error) ||
366 ((int) error_tag > (int) bfd_error_invalid_error_code)))
252b5132
RH
367 error_tag = bfd_error_invalid_error_code;/* sanity check */
368
369 return _(bfd_errmsgs [(int)error_tag]);
370}
371
372/*
373FUNCTION
374 bfd_perror
375
376SYNOPSIS
55ab10f0 377 void bfd_perror (const char *message);
252b5132
RH
378
379DESCRIPTION
380 Print to the standard error stream a string describing the
381 last BFD error that occurred, or the last system error if
382 the last BFD error was a system call failure. If @var{message}
383 is non-NULL and non-empty, the error string printed is preceded
384 by @var{message}, a colon, and a space. It is followed by a newline.
385*/
386
387void
388bfd_perror (message)
55ab10f0 389 const char *message;
252b5132
RH
390{
391 if (bfd_get_error () == bfd_error_system_call)
55ab10f0
NC
392 /* Must be a system error then. */
393 perror ((char *)message);
394 else
395 {
396 if (message == NULL || *message == '\0')
397 fprintf (stderr, "%s\n", bfd_errmsg (bfd_get_error ()));
398 else
399 fprintf (stderr, "%s: %s\n", message, bfd_errmsg (bfd_get_error ()));
400 }
252b5132
RH
401}
402
403/*
404SUBSECTION
405 BFD error handler
406
407 Some BFD functions want to print messages describing the
408 problem. They call a BFD error handler function. This
409 function may be overriden by the program.
410
411 The BFD error handler acts like printf.
412
413CODE_FRAGMENT
414.
415.typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
416.
417*/
418
419/* The program name used when printing BFD error messages. */
420
421static const char *_bfd_error_program_name;
422
423/* This is the default routine to handle BFD error messages. */
424
252b5132
RH
425static void _bfd_default_error_handler PARAMS ((const char *s, ...));
426
427static void
af6166c0 428_bfd_default_error_handler VPARAMS ((const char *s, ...))
252b5132 429{
252b5132
RH
430 if (_bfd_error_program_name != NULL)
431 fprintf (stderr, "%s: ", _bfd_error_program_name);
432 else
433 fprintf (stderr, "BFD: ");
434
af6166c0
AM
435 VA_OPEN (p, s);
436 VA_FIXEDARG (p, const char *, s);
252b5132 437 vfprintf (stderr, s, p);
af6166c0 438 VA_CLOSE (p);
252b5132
RH
439
440 fprintf (stderr, "\n");
441}
442
252b5132
RH
443/* This is a function pointer to the routine which should handle BFD
444 error messages. It is called when a BFD routine encounters an
445 error for which it wants to print a message. Going through a
446 function pointer permits a program linked against BFD to intercept
447 the messages and deal with them itself. */
448
449bfd_error_handler_type _bfd_error_handler = _bfd_default_error_handler;
450
451/*
452FUNCTION
453 bfd_set_error_handler
454
455SYNOPSIS
456 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
457
458DESCRIPTION
459 Set the BFD error handler function. Returns the previous
460 function.
461*/
462
463bfd_error_handler_type
464bfd_set_error_handler (pnew)
465 bfd_error_handler_type pnew;
466{
467 bfd_error_handler_type pold;
468
469 pold = _bfd_error_handler;
470 _bfd_error_handler = pnew;
471 return pold;
472}
473
474/*
475FUNCTION
476 bfd_set_error_program_name
477
478SYNOPSIS
479 void bfd_set_error_program_name (const char *);
480
481DESCRIPTION
482 Set the program name to use when printing a BFD error. This
483 is printed before the error message followed by a colon and
484 space. The string must not be changed after it is passed to
485 this function.
486*/
487
488void
489bfd_set_error_program_name (name)
490 const char *name;
491{
492 _bfd_error_program_name = name;
493}
494
252b5132
RH
495/*
496FUNCTION
497 bfd_get_error_handler
498
499SYNOPSIS
500 bfd_error_handler_type bfd_get_error_handler (void);
501
502DESCRIPTION
503 Return the BFD error handler function.
504*/
505
506bfd_error_handler_type
507bfd_get_error_handler ()
508{
509 return _bfd_error_handler;
510}
8f615d07
AM
511
512/*
513FUNCTION
514 bfd_archive_filename
515
516SYNOPSIS
517 const char *bfd_archive_filename (bfd *);
518
519DESCRIPTION
520 For a BFD that is a component of an archive, returns a string
521 with both the archive name and file name. For other BFDs, just
522 returns the file name.
523*/
524
525const char *
526bfd_archive_filename (abfd)
527 bfd *abfd;
528{
529 if (abfd->my_archive)
530 {
531 static size_t curr = 0;
532 static char *buf;
533 size_t needed;
534
535 needed = (strlen (bfd_get_filename (abfd->my_archive))
536 + strlen (bfd_get_filename (abfd)) + 3);
537 if (needed > curr)
538 {
539 if (curr)
540 free (buf);
541 curr = needed + (needed >> 1);
af6166c0 542 buf = bfd_malloc ((bfd_size_type) curr);
8f615d07
AM
543 /* If we can't malloc, fail safe by returning just the file
544 name. This function is only used when building error
545 messages. */
546 if (!buf)
547 {
548 curr = 0;
549 return bfd_get_filename (abfd);
550 }
551 }
552 sprintf (buf, "%s(%s)", bfd_get_filename (abfd->my_archive),
553 bfd_get_filename (abfd));
554 return buf;
555 }
556 else
557 return bfd_get_filename (abfd);
558}
252b5132
RH
559\f
560/*
561SECTION
562 Symbols
563*/
564
565/*
566FUNCTION
567 bfd_get_reloc_upper_bound
568
569SYNOPSIS
ed781d5d 570 long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
252b5132
RH
571
572DESCRIPTION
573 Return the number of bytes required to store the
574 relocation information associated with section @var{sect}
575 attached to bfd @var{abfd}. If an error occurs, return -1.
576
577*/
578
252b5132
RH
579long
580bfd_get_reloc_upper_bound (abfd, asect)
581 bfd *abfd;
582 sec_ptr asect;
583{
55ab10f0
NC
584 if (abfd->format != bfd_object)
585 {
586 bfd_set_error (bfd_error_invalid_operation);
587 return -1;
588 }
252b5132
RH
589
590 return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect));
591}
592
593/*
594FUNCTION
595 bfd_canonicalize_reloc
596
597SYNOPSIS
598 long bfd_canonicalize_reloc
599 (bfd *abfd,
600 asection *sec,
601 arelent **loc,
602 asymbol **syms);
603
604DESCRIPTION
605 Call the back end associated with the open BFD
606 @var{abfd} and translate the external form of the relocation
607 information attached to @var{sec} into the internal canonical
608 form. Place the table into memory at @var{loc}, which has
609 been preallocated, usually by a call to
610 <<bfd_get_reloc_upper_bound>>. Returns the number of relocs, or
611 -1 on error.
612
613 The @var{syms} table is also needed for horrible internal magic
614 reasons.
615
252b5132
RH
616*/
617long
618bfd_canonicalize_reloc (abfd, asect, location, symbols)
619 bfd *abfd;
620 sec_ptr asect;
621 arelent **location;
622 asymbol **symbols;
623{
55ab10f0
NC
624 if (abfd->format != bfd_object)
625 {
626 bfd_set_error (bfd_error_invalid_operation);
627 return -1;
628 }
629
252b5132
RH
630 return BFD_SEND (abfd, _bfd_canonicalize_reloc,
631 (abfd, asect, location, symbols));
632}
633
634/*
635FUNCTION
636 bfd_set_reloc
637
638SYNOPSIS
639 void bfd_set_reloc
b5f79c76 640 (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
252b5132
RH
641
642DESCRIPTION
643 Set the relocation pointer and count within
644 section @var{sec} to the values @var{rel} and @var{count}.
645 The argument @var{abfd} is ignored.
646
647*/
aebad5fe 648
252b5132
RH
649void
650bfd_set_reloc (ignore_abfd, asect, location, count)
7442e600 651 bfd *ignore_abfd ATTRIBUTE_UNUSED;
252b5132
RH
652 sec_ptr asect;
653 arelent **location;
654 unsigned int count;
655{
656 asect->orelocation = location;
657 asect->reloc_count = count;
658}
659
660/*
661FUNCTION
662 bfd_set_file_flags
663
664SYNOPSIS
ed781d5d 665 bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
252b5132
RH
666
667DESCRIPTION
668 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
669
670 Possible errors are:
671 o <<bfd_error_wrong_format>> - The target bfd was not of object format.
672 o <<bfd_error_invalid_operation>> - The target bfd was open for reading.
673 o <<bfd_error_invalid_operation>> -
674 The flag word contained a bit which was not applicable to the
675 type of file. E.g., an attempt was made to set the <<D_PAGED>> bit
676 on a BFD format which does not support demand paging.
677
678*/
679
b34976b6 680bfd_boolean
252b5132
RH
681bfd_set_file_flags (abfd, flags)
682 bfd *abfd;
683 flagword flags;
684{
55ab10f0
NC
685 if (abfd->format != bfd_object)
686 {
687 bfd_set_error (bfd_error_wrong_format);
b34976b6 688 return FALSE;
55ab10f0 689 }
252b5132 690
55ab10f0
NC
691 if (bfd_read_p (abfd))
692 {
693 bfd_set_error (bfd_error_invalid_operation);
b34976b6 694 return FALSE;
55ab10f0 695 }
252b5132
RH
696
697 bfd_get_file_flags (abfd) = flags;
55ab10f0
NC
698 if ((flags & bfd_applicable_file_flags (abfd)) != flags)
699 {
700 bfd_set_error (bfd_error_invalid_operation);
b34976b6 701 return FALSE;
55ab10f0 702 }
252b5132 703
b34976b6 704 return TRUE;
252b5132
RH
705}
706
707void
708bfd_assert (file, line)
709 const char *file;
710 int line;
711{
aec2f561
AM
712 (*_bfd_error_handler) (_("BFD %s assertion fail %s:%d"),
713 BFD_VERSION_STRING, file, line);
252b5132
RH
714}
715
c0bed66d
ILT
716/* A more or less friendly abort message. In libbfd.h abort is
717 defined to call this function. */
718
719#ifndef EXIT_FAILURE
720#define EXIT_FAILURE 1
721#endif
722
723void
724_bfd_abort (file, line, fn)
725 const char *file;
726 int line;
727 const char *fn;
728{
729 if (fn != NULL)
730 (*_bfd_error_handler)
aec2f561
AM
731 (_("BFD %s internal error, aborting at %s line %d in %s\n"),
732 BFD_VERSION_STRING, file, line, fn);
c0bed66d
ILT
733 else
734 (*_bfd_error_handler)
391154e9 735 (_("BFD %s internal error, aborting at %s line %d\n"),
aec2f561 736 BFD_VERSION_STRING, file, line);
c0bed66d
ILT
737 (*_bfd_error_handler) (_("Please report this bug.\n"));
738 xexit (EXIT_FAILURE);
739}
252b5132 740
125c4a69
NC
741/*
742FUNCTION
743 bfd_get_arch_size
744
745SYNOPSIS
746 int bfd_get_arch_size (bfd *abfd);
747
748DESCRIPTION
749 Returns the architecture address size, in bits, as determined
750 by the object file's format. For ELF, this information is
751 included in the header.
752
753RETURNS
754 Returns the arch size in bits if known, <<-1>> otherwise.
755*/
756
757int
758bfd_get_arch_size (abfd)
759 bfd *abfd;
760{
761 if (abfd->xvec->flavour == bfd_target_elf_flavour)
762 return (get_elf_backend_data (abfd))->s->arch_size;
763
125c4a69
NC
764 return -1;
765}
766
767/*
768FUNCTION
769 bfd_get_sign_extend_vma
770
771SYNOPSIS
772 int bfd_get_sign_extend_vma (bfd *abfd);
773
774DESCRIPTION
775 Indicates if the target architecture "naturally" sign extends
776 an address. Some architectures implicitly sign extend address
777 values when they are converted to types larger than the size
778 of an address. For instance, bfd_get_start_address() will
779 return an address sign extended to fill a bfd_vma when this is
780 the case.
781
782RETURNS
783 Returns <<1>> if the target architecture is known to sign
784 extend addresses, <<0>> if the target architecture is known to
785 not sign extend addresses, and <<-1>> otherwise.
786*/
787
788int
789bfd_get_sign_extend_vma (abfd)
790 bfd *abfd;
791{
f47e5071
NC
792 char *name;
793
125c4a69
NC
794 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
795 return (get_elf_backend_data (abfd)->sign_extend_vma);
796
f47e5071
NC
797 name = bfd_get_target (abfd);
798
799 /* Return a proper value for DJGPP COFF (an x86 COFF variant).
800 This function is required for DWARF2 support, but there is
801 no place to store this information in the COFF back end.
802 Should enough other COFF targets add support for DWARF2,
803 a place will have to be found. Until then, this hack will do. */
804 if (strncmp (name, "coff-go32", sizeof ("coff-go32") - 1) == 0)
805 return 1;
806
a022216b 807 bfd_set_error (bfd_error_wrong_format);
125c4a69
NC
808 return -1;
809}
810
252b5132
RH
811/*
812FUNCTION
813 bfd_set_start_address
814
815SYNOPSIS
ed781d5d 816 bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
252b5132
RH
817
818DESCRIPTION
819 Make @var{vma} the entry point of output BFD @var{abfd}.
820
821RETURNS
b34976b6 822 Returns <<TRUE>> on success, <<FALSE>> otherwise.
252b5132
RH
823*/
824
b34976b6 825bfd_boolean
55ab10f0
NC
826bfd_set_start_address (abfd, vma)
827 bfd *abfd;
828 bfd_vma vma;
252b5132
RH
829{
830 abfd->start_address = vma;
b34976b6 831 return TRUE;
252b5132
RH
832}
833
252b5132
RH
834/*
835FUNCTION
836 bfd_get_gp_size
837
838SYNOPSIS
ed781d5d 839 unsigned int bfd_get_gp_size (bfd *abfd);
252b5132
RH
840
841DESCRIPTION
842 Return the maximum size of objects to be optimized using the GP
843 register under MIPS ECOFF. This is typically set by the <<-G>>
844 argument to the compiler, assembler or linker.
845*/
846
c0846b23 847unsigned int
252b5132
RH
848bfd_get_gp_size (abfd)
849 bfd *abfd;
850{
851 if (abfd->format == bfd_object)
852 {
853 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
854 return ecoff_data (abfd)->gp_size;
855 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
856 return elf_gp_size (abfd);
857 }
858 return 0;
859}
860
861/*
862FUNCTION
863 bfd_set_gp_size
864
865SYNOPSIS
ed781d5d 866 void bfd_set_gp_size (bfd *abfd, unsigned int i);
252b5132
RH
867
868DESCRIPTION
869 Set the maximum size of objects to be optimized using the GP
870 register under ECOFF or MIPS ELF. This is typically set by
871 the <<-G>> argument to the compiler, assembler or linker.
872*/
873
874void
875bfd_set_gp_size (abfd, i)
876 bfd *abfd;
c0846b23 877 unsigned int i;
252b5132 878{
55ab10f0 879 /* Don't try to set GP size on an archive or core file! */
252b5132
RH
880 if (abfd->format != bfd_object)
881 return;
55ab10f0 882
252b5132
RH
883 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
884 ecoff_data (abfd)->gp_size = i;
885 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
886 elf_gp_size (abfd) = i;
887}
888
889/* Get the GP value. This is an internal function used by some of the
890 relocation special_function routines on targets which support a GP
891 register. */
892
893bfd_vma
894_bfd_get_gp_value (abfd)
895 bfd *abfd;
896{
9bcf4de0
TS
897 if (! abfd)
898 return 0;
55ab10f0
NC
899 if (abfd->format != bfd_object)
900 return 0;
901
902 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
903 return ecoff_data (abfd)->gp;
904 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
905 return elf_gp (abfd);
906
252b5132
RH
907 return 0;
908}
909
910/* Set the GP value. */
911
912void
913_bfd_set_gp_value (abfd, v)
914 bfd *abfd;
915 bfd_vma v;
916{
9bcf4de0
TS
917 if (! abfd)
918 BFD_FAIL ();
252b5132
RH
919 if (abfd->format != bfd_object)
920 return;
55ab10f0 921
252b5132
RH
922 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
923 ecoff_data (abfd)->gp = v;
924 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
925 elf_gp (abfd) = v;
926}
927
928/*
929FUNCTION
930 bfd_scan_vma
931
932SYNOPSIS
ed781d5d 933 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
252b5132
RH
934
935DESCRIPTION
936 Convert, like <<strtoul>>, a numerical expression
937 @var{string} into a <<bfd_vma>> integer, and return that integer.
938 (Though without as many bells and whistles as <<strtoul>>.)
939 The expression is assumed to be unsigned (i.e., positive).
940 If given a @var{base}, it is used as the base for conversion.
941 A base of 0 causes the function to interpret the string
942 in hex if a leading "0x" or "0X" is found, otherwise
943 in octal if a leading zero is found, otherwise in decimal.
944
88eaccc2
AM
945 If the value would overflow, the maximum <<bfd_vma>> value is
946 returned.
252b5132
RH
947*/
948
949bfd_vma
950bfd_scan_vma (string, end, base)
55ab10f0
NC
951 const char *string;
952 const char **end;
252b5132
RH
953 int base;
954{
955 bfd_vma value;
88eaccc2
AM
956 bfd_vma cutoff;
957 unsigned int cutlim;
958 int overflow;
252b5132
RH
959
960 /* Let the host do it if possible. */
eb6e10cb 961 if (sizeof (bfd_vma) <= sizeof (unsigned long))
252b5132
RH
962 return (bfd_vma) strtoul (string, (char **) end, base);
963
252b5132
RH
964 if (base == 0)
965 {
966 if (string[0] == '0')
967 {
968 if ((string[1] == 'x') || (string[1] == 'X'))
969 base = 16;
252b5132
RH
970 else
971 base = 8;
972 }
252b5132 973 }
55ab10f0 974
88eaccc2
AM
975 if ((base < 2) || (base > 36))
976 base = 10;
977
978 if (base == 16
979 && string[0] == '0'
980 && (string[1] == 'x' || string[1] == 'X')
981 && ISXDIGIT (string[2]))
982 {
983 string += 2;
984 }
aebad5fe 985
88eaccc2
AM
986 cutoff = (~ (bfd_vma) 0) / (bfd_vma) base;
987 cutlim = (~ (bfd_vma) 0) % (bfd_vma) base;
988 value = 0;
989 overflow = 0;
990 while (1)
991 {
992 unsigned int digit;
993
994 digit = *string;
995 if (ISDIGIT (digit))
996 digit = digit - '0';
997 else if (ISALPHA (digit))
998 digit = TOUPPER (digit) - 'A' + 10;
999 else
1000 break;
1001 if (digit >= (unsigned int) base)
1002 break;
1003 if (value > cutoff || (value == cutoff && digit > cutlim))
1004 overflow = 1;
1005 value = value * base + digit;
1006 ++string;
1007 }
252b5132 1008
88eaccc2
AM
1009 if (overflow)
1010 value = ~ (bfd_vma) 0;
252b5132 1011
88eaccc2
AM
1012 if (end != NULL)
1013 *end = string;
252b5132
RH
1014
1015 return value;
1016}
1017
1018/*
1019FUNCTION
1020 bfd_copy_private_bfd_data
1021
1022SYNOPSIS
ed781d5d 1023 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
252b5132
RH
1024
1025DESCRIPTION
aebad5fe 1026 Copy private BFD information from the BFD @var{ibfd} to the
b34976b6 1027 the BFD @var{obfd}. Return <<TRUE>> on success, <<FALSE>> on error.
252b5132
RH
1028 Possible error returns are:
1029
1030 o <<bfd_error_no_memory>> -
1031 Not enough memory exists to create private data for @var{obfd}.
1032
1033.#define bfd_copy_private_bfd_data(ibfd, obfd) \
1034. BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
1035. (ibfd, obfd))
1036
1037*/
1038
1039/*
1040FUNCTION
1041 bfd_merge_private_bfd_data
1042
1043SYNOPSIS
ed781d5d 1044 bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
252b5132
RH
1045
1046DESCRIPTION
aebad5fe 1047 Merge private BFD information from the BFD @var{ibfd} to the
b34976b6
AM
1048 the output file BFD @var{obfd} when linking. Return <<TRUE>>
1049 on success, <<FALSE>> on error. Possible error returns are:
252b5132
RH
1050
1051 o <<bfd_error_no_memory>> -
1052 Not enough memory exists to create private data for @var{obfd}.
1053
1054.#define bfd_merge_private_bfd_data(ibfd, obfd) \
1055. BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
1056. (ibfd, obfd))
1057
1058*/
1059
1060/*
1061FUNCTION
1062 bfd_set_private_flags
1063
1064SYNOPSIS
ed781d5d 1065 bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
252b5132
RH
1066
1067DESCRIPTION
1068 Set private BFD flag information in the BFD @var{abfd}.
b34976b6 1069 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
252b5132
RH
1070 returns are:
1071
1072 o <<bfd_error_no_memory>> -
1073 Not enough memory exists to create private data for @var{obfd}.
1074
1075.#define bfd_set_private_flags(abfd, flags) \
ed781d5d 1076. BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
252b5132
RH
1077
1078*/
1079
1080/*
1081FUNCTION
ed781d5d 1082 Other functions
252b5132
RH
1083
1084DESCRIPTION
ed781d5d 1085 The following functions exist but have not yet been documented.
252b5132
RH
1086
1087.#define bfd_sizeof_headers(abfd, reloc) \
ed781d5d 1088. BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
252b5132
RH
1089.
1090.#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
ed781d5d
NC
1091. BFD_SEND (abfd, _bfd_find_nearest_line, \
1092. (abfd, sec, syms, off, file, func, line))
252b5132 1093.
252b5132 1094.#define bfd_debug_info_start(abfd) \
ed781d5d 1095. BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
252b5132
RH
1096.
1097.#define bfd_debug_info_end(abfd) \
ed781d5d 1098. BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
252b5132
RH
1099.
1100.#define bfd_debug_info_accumulate(abfd, section) \
ed781d5d 1101. BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
252b5132
RH
1102.
1103.#define bfd_stat_arch_elt(abfd, stat) \
ed781d5d 1104. BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
252b5132
RH
1105.
1106.#define bfd_update_armap_timestamp(abfd) \
ed781d5d 1107. BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
252b5132
RH
1108.
1109.#define bfd_set_arch_mach(abfd, arch, mach)\
ed781d5d 1110. BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
252b5132
RH
1111.
1112.#define bfd_relax_section(abfd, section, link_info, again) \
1113. BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
1114.
1115.#define bfd_gc_sections(abfd, link_info) \
1116. BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
8550eb6e
JJ
1117.
1118.#define bfd_merge_sections(abfd, link_info) \
1119. BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
252b5132 1120.
e61463e1
AM
1121.#define bfd_discard_group(abfd, sec) \
1122. BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
1123.
252b5132
RH
1124.#define bfd_link_hash_table_create(abfd) \
1125. BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
1126.
e2d34d7d
DJ
1127.#define bfd_link_hash_table_free(abfd, hash) \
1128. BFD_SEND (abfd, _bfd_link_hash_table_free, (hash))
1129.
252b5132
RH
1130.#define bfd_link_add_symbols(abfd, info) \
1131. BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
1132.
2d653fc7
AM
1133.#define bfd_link_just_syms(sec, info) \
1134. BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
1135.
252b5132
RH
1136.#define bfd_final_link(abfd, info) \
1137. BFD_SEND (abfd, _bfd_final_link, (abfd, info))
1138.
1139.#define bfd_free_cached_info(abfd) \
1140. BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
1141.
1142.#define bfd_get_dynamic_symtab_upper_bound(abfd) \
1143. BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
1144.
1145.#define bfd_print_private_bfd_data(abfd, file)\
1146. BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
1147.
1148.#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
1149. BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
1150.
1151.#define bfd_get_dynamic_reloc_upper_bound(abfd) \
1152. BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
1153.
1154.#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
1155. BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
1156.
1157.extern bfd_byte *bfd_get_relocated_section_contents
1158. PARAMS ((bfd *, struct bfd_link_info *,
1159. struct bfd_link_order *, bfd_byte *,
b34976b6 1160. bfd_boolean, asymbol **));
252b5132
RH
1161.
1162
1163*/
1164
1165bfd_byte *
1166bfd_get_relocated_section_contents (abfd, link_info, link_order, data,
1049f94e 1167 relocatable, symbols)
252b5132
RH
1168 bfd *abfd;
1169 struct bfd_link_info *link_info;
1170 struct bfd_link_order *link_order;
1171 bfd_byte *data;
1049f94e 1172 bfd_boolean relocatable;
252b5132
RH
1173 asymbol **symbols;
1174{
1175 bfd *abfd2;
1176 bfd_byte *(*fn) PARAMS ((bfd *, struct bfd_link_info *,
b34976b6 1177 struct bfd_link_order *, bfd_byte *, bfd_boolean,
252b5132
RH
1178 asymbol **));
1179
1180 if (link_order->type == bfd_indirect_link_order)
1181 {
1182 abfd2 = link_order->u.indirect.section->owner;
55ab10f0 1183 if (abfd2 == NULL)
252b5132
RH
1184 abfd2 = abfd;
1185 }
1186 else
1187 abfd2 = abfd;
55ab10f0 1188
252b5132
RH
1189 fn = abfd2->xvec->_bfd_get_relocated_section_contents;
1190
1049f94e 1191 return (*fn) (abfd, link_info, link_order, data, relocatable, symbols);
252b5132
RH
1192}
1193
1194/* Record information about an ELF program header. */
1195
b34976b6 1196bfd_boolean
252b5132
RH
1197bfd_record_phdr (abfd, type, flags_valid, flags, at_valid, at,
1198 includes_filehdr, includes_phdrs, count, secs)
1199 bfd *abfd;
1200 unsigned long type;
b34976b6 1201 bfd_boolean flags_valid;
252b5132 1202 flagword flags;
b34976b6 1203 bfd_boolean at_valid;
252b5132 1204 bfd_vma at;
b34976b6
AM
1205 bfd_boolean includes_filehdr;
1206 bfd_boolean includes_phdrs;
252b5132
RH
1207 unsigned int count;
1208 asection **secs;
1209{
1210 struct elf_segment_map *m, **pm;
dc810e39 1211 bfd_size_type amt;
252b5132
RH
1212
1213 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
b34976b6 1214 return TRUE;
252b5132 1215
dc810e39
AM
1216 amt = sizeof (struct elf_segment_map);
1217 amt += ((bfd_size_type) count - 1) * sizeof (asection *);
1218 m = (struct elf_segment_map *) bfd_alloc (abfd, amt);
252b5132 1219 if (m == NULL)
b34976b6 1220 return FALSE;
252b5132
RH
1221
1222 m->next = NULL;
1223 m->p_type = type;
1224 m->p_flags = flags;
1225 m->p_paddr = at;
d45913a0
DA
1226 m->p_flags_valid = (unsigned int) flags_valid;
1227 m->p_paddr_valid = (unsigned int) at_valid;
1228 m->includes_filehdr = (unsigned int) includes_filehdr;
1229 m->includes_phdrs = (unsigned int) includes_phdrs;
252b5132
RH
1230 m->count = count;
1231 if (count > 0)
1232 memcpy (m->sections, secs, count * sizeof (asection *));
1233
1234 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
1235 ;
1236 *pm = m;
1237
b34976b6 1238 return TRUE;
252b5132 1239}
ae4221d7
L
1240
1241void
1242bfd_sprintf_vma (abfd, buf, value)
1243 bfd *abfd;
1244 char *buf;
1245 bfd_vma value;
1246{
1247 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
4e771d61 1248 get_elf_backend_data (abfd)->elf_backend_sprintf_vma (abfd, buf, value);
ef071f24
L
1249 else
1250 sprintf_vma (buf, value);
ae4221d7
L
1251}
1252
1253void
1254bfd_fprintf_vma (abfd, stream, value)
1255 bfd *abfd;
1256 PTR stream;
1257 bfd_vma value;
1258{
1259 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
4e771d61 1260 get_elf_backend_data (abfd)->elf_backend_fprintf_vma (abfd, stream, value);
ef071f24
L
1261 else
1262 fprintf_vma ((FILE *) stream, value);
ae4221d7 1263}
8c98ec7d
AO
1264
1265/*
1266FUNCTION
1267 bfd_alt_mach_code
1268
1269SYNOPSIS
ed781d5d 1270 bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
8c98ec7d
AO
1271
1272DESCRIPTION
1273
1274 When more than one machine code number is available for the
1275 same machine type, this function can be used to switch between
47badb7b 1276 the preferred one (alternative == 0) and any others. Currently,
8c98ec7d
AO
1277 only ELF supports this feature, with up to two alternate
1278 machine codes.
1279*/
1280
b34976b6 1281bfd_boolean
47badb7b 1282bfd_alt_mach_code (abfd, alternative)
8c98ec7d 1283 bfd *abfd;
47badb7b 1284 int alternative;
8c98ec7d
AO
1285{
1286 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1287 {
1288 int code;
1289
47badb7b 1290 switch (alternative)
8c98ec7d
AO
1291 {
1292 case 0:
1293 code = get_elf_backend_data (abfd)->elf_machine_code;
1294 break;
1295
1296 case 1:
1297 code = get_elf_backend_data (abfd)->elf_machine_alt1;
1298 if (code == 0)
b34976b6 1299 return FALSE;
8c98ec7d
AO
1300 break;
1301
1302 case 2:
1303 code = get_elf_backend_data (abfd)->elf_machine_alt2;
1304 if (code == 0)
b34976b6 1305 return FALSE;
8c98ec7d
AO
1306 break;
1307
1308 default:
b34976b6 1309 return FALSE;
8c98ec7d
AO
1310 }
1311
1312 elf_elfheader (abfd)->e_machine = code;
1313
b34976b6 1314 return TRUE;
8c98ec7d
AO
1315 }
1316
b34976b6 1317 return FALSE;
8c98ec7d 1318}
e84d6fca
AM
1319
1320/*
1321CODE_FRAGMENT
1322
1323.struct bfd_preserve
1324.{
1325. PTR marker;
1326. PTR tdata;
1327. flagword flags;
1328. const struct bfd_arch_info *arch_info;
1329. struct sec *sections;
1330. struct sec **section_tail;
1331. unsigned int section_count;
1332. struct bfd_hash_table section_htab;
1333.};
1334.
1335*/
1336
1337/*
1338FUNCTION
1339 bfd_preserve_save
1340
1341SYNOPSIS
b34976b6 1342 bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
e84d6fca
AM
1343
1344DESCRIPTION
1345 When testing an object for compatibility with a particular
1346 target back-end, the back-end object_p function needs to set
1347 up certain fields in the bfd on successfully recognizing the
1348 object. This typically happens in a piecemeal fashion, with
1349 failures possible at many points. On failure, the bfd is
1350 supposed to be restored to its initial state, which is
1351 virtually impossible. However, restoring a subset of the bfd
1352 state works in practice. This function stores the subset and
1353 reinitializes the bfd.
1354
1355*/
1356
b34976b6 1357bfd_boolean
e84d6fca
AM
1358bfd_preserve_save (abfd, preserve)
1359 bfd *abfd;
1360 struct bfd_preserve *preserve;
1361{
1362 preserve->tdata = abfd->tdata.any;
1363 preserve->arch_info = abfd->arch_info;
1364 preserve->flags = abfd->flags;
e84d6fca
AM
1365 preserve->sections = abfd->sections;
1366 preserve->section_tail = abfd->section_tail;
1367 preserve->section_count = abfd->section_count;
1368 preserve->section_htab = abfd->section_htab;
1369
1370 if (! bfd_hash_table_init (&abfd->section_htab, bfd_section_hash_newfunc))
b34976b6 1371 return FALSE;
e84d6fca
AM
1372
1373 abfd->tdata.any = NULL;
1374 abfd->arch_info = &bfd_default_arch_struct;
3ae41454 1375 abfd->flags &= BFD_IN_MEMORY;
e84d6fca
AM
1376 abfd->sections = NULL;
1377 abfd->section_tail = &abfd->sections;
1378 abfd->section_count = 0;
1379
b34976b6 1380 return TRUE;
e84d6fca
AM
1381}
1382
1383/*
1384FUNCTION
1385 bfd_preserve_restore
1386
1387SYNOPSIS
1388 void bfd_preserve_restore (bfd *, struct bfd_preserve *);
1389
1390DESCRIPTION
1391 This function restores bfd state saved by bfd_preserve_save.
1392 If MARKER is non-NULL in struct bfd_preserve then that block
1393 and all subsequently bfd_alloc'd memory is freed.
1394
1395*/
1396
1397void
1398bfd_preserve_restore (abfd, preserve)
1399 bfd *abfd;
1400 struct bfd_preserve *preserve;
1401{
1402 bfd_hash_table_free (&abfd->section_htab);
1403
1404 abfd->tdata.any = preserve->tdata;
1405 abfd->arch_info = preserve->arch_info;
1406 abfd->flags = preserve->flags;
e84d6fca
AM
1407 abfd->section_htab = preserve->section_htab;
1408 abfd->sections = preserve->sections;
1409 abfd->section_tail = preserve->section_tail;
1410 abfd->section_count = preserve->section_count;
1411
1412 /* bfd_release frees all memory more recently bfd_alloc'd than
1413 its arg, as well as its arg. */
1414 if (preserve->marker != NULL)
1415 {
1416 bfd_release (abfd, preserve->marker);
1417 preserve->marker = NULL;
1418 }
1419}
1420
1421/*
1422FUNCTION
1423 bfd_preserve_finish
1424
1425SYNOPSIS
1426 void bfd_preserve_finish (bfd *, struct bfd_preserve *);
1427
1428DESCRIPTION
1429 This function should be called when the bfd state saved by
1430 bfd_preserve_save is no longer needed. ie. when the back-end
1431 object_p function returns with success.
1432
1433*/
1434
1435void
1436bfd_preserve_finish (abfd, preserve)
1437 bfd *abfd ATTRIBUTE_UNUSED;
1438 struct bfd_preserve *preserve;
1439{
1440 /* It would be nice to be able to free more memory here, eg. old
1441 tdata, but that's not possible since these blocks are sitting
1442 inside bfd_alloc'd memory. The section hash is on a separate
1443 objalloc. */
1444 bfd_hash_table_free (&preserve->section_htab);
1445}
This page took 0.308979 seconds and 4 git commands to generate.