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