Initial revision
[deliverable/binutils-gdb.git] / bfd / libbfd.h
CommitLineData
fc723380
JG
1/* libbfd.h -- Declarations used by bfd library implementation.
2 This include file is not for users of the library */
3
4a81b561
DHW
4/* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
5
6This file is part of BFD, the Binary File Diddler.
7
8BFD is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 1, or (at your option)
11any later version.
12
13BFD is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with BFD; see the file COPYING. If not, write to
20the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22/* $Id$ */
23
4a81b561
DHW
24/* If you want to read and write large blocks, you might want to do it
25 in quanta of this amount */
26#define DEFAULT_BUFFERSIZE 8192
27
fc723380
JG
28/* Set a tdata field. Can't use the other macros for this, since they
29 do casts, and casting to the left of assignment isn't portable. */
30#define set_tdata(bfd, v) ((bfd)->tdata = (PTR) (v))
31
32/* tdata for an archive. For an input archive, cache
33 needs to be free()'d. For an output archive, symdefs do. */
4a81b561
DHW
34
35struct artdata {
36 file_ptr first_file_filepos;
37 /* Speed up searching the armap */
38 struct ar_cache *cache;
39 bfd *archive_head; /* Only interesting in output routines */
40 carsym *symdefs; /* the symdef entries */
41 symindex symdef_count; /* how many there are */
42 char *extended_names; /* clever intel extension */
43};
44
45#define bfd_ardata(bfd) ((struct artdata *) ((bfd)->tdata))
4a81b561
DHW
46
47/* Goes in bfd's arelt_data slot */
48struct areltdata {
49 char * arch_header; /* it's actually a string */
50 unsigned int parsed_size; /* octets of filesize not including ar_hdr */
51 char *filename; /* null-terminated */
52};
53
54#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
55
56/* FIXME -- a lot of my code allocates a large block and subdivides it.
57 This can't always work, because of alignment restrictions. We should change
58 it before it becomes a problem -- Gumby */
59
fc723380 60PROTO (char *, zalloc, (bfd_size_type size));
9846338e 61
fc723380
JG
62/* These routines allocate and free things on the BFD's obstack. Note
63 that realloc can never occur in place. */
4a81b561 64
fc723380
JG
65PROTO(PTR, bfd_alloc, (bfd *abfd, bfd_size_type size));
66PROTO(PTR, bfd_zalloc,(bfd *abfd, bfd_size_type size));
67PROTO(PTR, bfd_realloc,(bfd *abfd, PTR orig, bfd_size_type new));
6f715d66
SC
68PROTO(void, bfd_alloc_grow,(bfd *abfd, PTR thing, bfd_size_type size));
69PROTO(PTR, bfd_alloc_finish,(bfd *abfd));
70
fc723380 71#define bfd_release(x,y) (void) obstack_free(&(x->memory),y)
4a81b561 72
6f715d66 73
fc723380
JG
74PROTO (bfd_size_type, bfd_read, (PTR ptr, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
75PROTO (bfd_size_type, bfd_write, (PTR ptr, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
4a81b561 76
6f715d66
SC
77
78
9846338e 79PROTO (int, bfd_seek,(bfd* abfd, file_ptr fp , int direction));
4a81b561
DHW
80PROTO (long, bfd_tell, (bfd *abfd));
81PROTO (bfd *, _bfd_create_empty_archive_element_shell, (bfd *obfd));
82PROTO (bfd *, look_for_bfd_in_cache, (bfd *arch_bfd, file_ptr index));
83PROTO (boolean, _bfd_generic_mkarchive, (bfd *abfd));
84PROTO (struct areltdata *, snarf_ar_hdr, (bfd *abfd));
85PROTO (bfd_target *, bfd_generic_archive_p, (bfd *abfd));
86PROTO (boolean, bfd_slurp_bsd_armap, (bfd *abfd));
87PROTO (boolean, bfd_slurp_coff_armap, (bfd *abfd));
88PROTO (boolean, _bfd_slurp_extended_name_table, (bfd *abfd));
89PROTO (boolean, _bfd_write_archive_contents, (bfd *abfd));
90PROTO (bfd *, new_bfd, ());
91
92#define DEFAULT_STRING_SPACE_SIZE 0x2000
93PROTO (boolean, bfd_add_to_string_table, (char **table, char *new_string,
94 unsigned int *table_length,
95 char **free_ptr));
7ed4093a
SC
96PROTO (bfd_64_type, _do_getb64, (unsigned char *addr));
97PROTO (bfd_64_type, _do_getl64, (unsigned char *addr));
98PROTO (unsigned int, _do_getb32, (unsigned char *addr));
99PROTO (unsigned int, _do_getl32, (unsigned char *addr));
100PROTO (unsigned int, _do_getb16, (unsigned char *addr));
101PROTO (unsigned int, _do_getl16, (unsigned char *addr));
102PROTO (void, _do_putb64, (bfd_64_type data, unsigned char *addr));
103PROTO (void, _do_putl64, (bfd_64_type data, unsigned char *addr));
104PROTO (void, _do_putb32, (unsigned long data, unsigned char *addr));
105PROTO (void, _do_putl32, (unsigned long data, unsigned char *addr));
106PROTO (void, _do_putb16, (int data, unsigned char *addr));
107PROTO (void, _do_putl16, (int data, unsigned char *addr));
4a81b561
DHW
108
109PROTO (boolean, bfd_false, (bfd *ignore));
110PROTO (boolean, bfd_true, (bfd *ignore));
a0ad3035 111PROTO (PTR, bfd_nullvoidptr, (bfd *ignore));
4a81b561
DHW
112PROTO (int, bfd_0, (bfd *ignore));
113PROTO (unsigned int, bfd_0u, (bfd *ignore));
114PROTO (void, bfd_void, (bfd *ignore));
115
4a81b561
DHW
116PROTO (bfd *,new_bfd_contained_in,(bfd *));
117PROTO (boolean, _bfd_dummy_new_section_hook, (bfd *ignore, asection *newsect));
118PROTO (char *, _bfd_dummy_core_file_failing_command, (bfd *abfd));
119PROTO (int, _bfd_dummy_core_file_failing_signal, (bfd *abfd));
120PROTO (boolean, _bfd_dummy_core_file_matches_executable_p, (bfd *core_bfd,
121 bfd *exec_bfd));
122PROTO (bfd_target *, _bfd_dummy_target, (bfd *abfd));
123
69ebee86
JG
124PROTO (void, bfd_dont_truncate_arname, (bfd *abfd, CONST char *filename,
125 char *hdr));
126PROTO (void, bfd_bsd_truncate_arname, (bfd *abfd, CONST char *filename,
127 char *hdr));
128PROTO (void, bfd_gnu_truncate_arname, (bfd *abfd, CONST char *filename,
129 char *hdr));
4a81b561
DHW
130
131PROTO (boolean, bsd_write_armap, (bfd *arch, unsigned int elength,
132 struct orl *map, int orl_count, int stridx));
133
134PROTO (boolean, coff_write_armap, (bfd *arch, unsigned int elength,
135 struct orl *map, int orl_count, int stridx));
136
2203f786
JG
137PROTO (bfd *, bfd_generic_openr_next_archived_file, (bfd *archive,
138 bfd *last_file));
4a81b561
DHW
139
140PROTO(int, bfd_generic_stat_arch_elt, (bfd *, struct stat *));
fc723380 141
2203f786 142PROTO(boolean, bfd_generic_get_section_contents,
7ed4093a 143 (bfd *abfd, sec_ptr section, PTR location, file_ptr offset, bfd_size_type count));
2203f786 144
4a81b561
DHW
145/* Macros to tell if bfds are read or write enabled.
146
147 Note that bfds open for read may be scribbled into if the fd passed
148 to bfd_fdopenr is actually open both for read and write
149 simultaneously. However an output bfd will never be open for
150 read. Therefore sometimes you want to check bfd_read_p or
151 !bfd_read_p, and only sometimes bfd_write_p.
152*/
153
154#define bfd_read_p(abfd) ((abfd)->direction == read_direction || (abfd)->direction == both_direction)
155#define bfd_write_p(abfd) ((abfd)->direction == write_direction || (abfd)->direction == both_direction)
156
157PROTO (void, bfd_assert,(char*,int));
158#define BFD_ASSERT(x) \
159{ if (!(x)) bfd_assert(__FILE__,__LINE__); }
160
161#define BFD_FAIL() \
162{ bfd_assert(__FILE__,__LINE__); }
163
164PROTO (FILE *, bfd_cache_lookup_worker, (bfd *));
165
166extern bfd *bfd_last_cache;
4a81b561
DHW
167
168/* Now Steve, what's the story here? */
169#ifdef lint
170#define itos(x) "l"
171#define stoi(x) 1
172#else
173#define itos(x) ((char*)(x))
174#define stoi(x) ((int)(x))
175#endif
69ebee86
JG
176
177/* Generic routine for close_and_cleanup is really just bfd_true. */
178#define bfd_generic_close_and_cleanup bfd_true
6f715d66
SC
179
180/* THE FOLLOWING IS EXTRACTED FROM THE SOURCE*/
181
182/* Return the log base 2 of the value supplied, rounded up. eg an arg
183of 1025 would return 11.
184*/
185PROTO(bfd_vma, bfd_log2,(bfd_vma x));
186/* The maxiumum number of files which the cache will keep open at one
187time.
188*/
189#define BFD_CACHE_MAX_OPEN 10
190
191/* Zero, or a pointer to the topmost bfd on the chain. This is used by the
192bfd_cache_lookup() macro in libbfd.h to determine when it can avoid a function
193call.
194*/
195extern bfd *bfd_last_cache;
196
197/* Checks to see if the required bfd is the same as the last one looked
198up. If so then it can use the iostream in the bfd with impunity, since
199it can't have changed since the last lookup, otherwise it has to
200perform the complicated lookup function
201*/
202#define bfd_cache_lookup(x) \
203 ((x)==bfd_last_cache? \
204 (FILE*)(bfd_last_cache->iostream): \
205 bfd_cache_lookup_worker(x))
206
207
208/* Initialize a BFD by putting it on the cache LRU.
209*/
210PROTO(void, bfd_cache_init, (bfd *));
211/* Remove the bfd from the cache. If the attatched file is open, then close it too.
212*/
213PROTO(void, bfd_cache_close, (bfd *));
214/* Call the OS to open a file for this BFD. Returns the FILE *
215(possibly null) that results from this operation. Sets up the
216BFD so that future accesses know the file is open. If the FILE *
217returned is null, then there is won't have been put in the cache, so
218it won't have to be removed from it.
219*/
220PROTO(FILE *, bfd_open_file, (bfd *));
221/* Called when the macro @code{bfd_cache_lookup} fails to find a quick
222answer. Finds a file descriptor for this BFD. If necessary, it open it.
223If there are already more than BFD_CACHE_MAX_OPEN files open, it trys to close
224one first, to avoid running out of file descriptors.
225*/
226PROTO(FILE *, bfd_cache_lookup_worker, (bfd *));
This page took 0.038102 seconds and 4 git commands to generate.