]>
Commit | Line | Data |
---|---|---|
4e6f9223 SC |
1 | /* Generic target-file-type support for the BFD library. |
2 | Copyright (C) 1990-1991 Free Software Foundation, Inc. | |
3 | Written by Cygnus Support. | |
4a81b561 | 4 | |
4e6f9223 | 5 | This file is part of BFD, the Binary File Descriptor library. |
4a81b561 | 6 | |
4e6f9223 | 7 | This program is free software; you can redistribute it and/or modify |
4a81b561 | 8 | it under the terms of the GNU General Public License as published by |
4e6f9223 SC |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
4a81b561 | 11 | |
4e6f9223 | 12 | This program is distributed in the hope that it will be useful, |
4a81b561 DHW |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
4e6f9223 SC |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
4a81b561 DHW |
20 | |
21 | /* $Id$ */ | |
22 | ||
4a81b561 | 23 | #include "bfd.h" |
bbc8d484 | 24 | #include "sysdep.h" |
4a81b561 DHW |
25 | #include "libbfd.h" |
26 | ||
0cda46cf SC |
27 | /* |
28 | SECTION | |
29 | Targets | |
30 | ||
e98e6ec1 | 31 | DESCRIPTION |
0cda46cf SC |
32 | Each port of BFD to a different machine requries the creation |
33 | of a target back end. All the back end provides to the root | |
34 | part of BFD is a structure containing pointers to functions | |
35 | which perform certain low level operations on files. BFD | |
36 | translates the applications's requests through a pointer into | |
37 | calls to the back end routines. | |
38 | ||
39 | When a file is opened with <<bfd_openr>>, its format and | |
40 | target are unknown. BFD uses various mechanisms to determine | |
41 | how to interpret the file. The operations performed are: | |
42 | ||
43 | o First a BFD is created by calling the internal routine | |
44 | <<new_bfd>>, then <<bfd_find_target>> is called with the | |
45 | target string supplied to <<bfd_openr>> and the new BFD pointer. | |
46 | ||
47 | o If a null target string was provided to <<bfd_find_target>>, | |
48 | it looks up the environment variable <<GNUTARGET>> and uses | |
49 | that as the target string. | |
50 | ||
51 | o If the target string is still NULL, or the target string is | |
52 | <<default>>, then the first item in the target vector is used | |
53 | as the target type. @xref{bfd_target}. | |
54 | ||
55 | o Otherwise, the elements in the target vector are inspected | |
56 | one by one, until a match on target name is found. When found, | |
57 | that is used. | |
58 | ||
59 | o Otherwise the error <<invalid_target>> is returned to | |
60 | <<bfd_openr>>. | |
61 | ||
62 | o <<bfd_openr>> attempts to open the file using | |
63 | <<bfd_open_file>>, and returns the BFD. | |
64 | ||
65 | Once the BFD has been opened and the target selected, the file | |
66 | format may be determined. This is done by calling | |
67 | <<bfd_check_format>> on the BFD with a suggested format. The | |
68 | routine returns <<true>> when the application guesses right. | |
92c78ee6 | 69 | @menu |
e98e6ec1 | 70 | @* bfd_target:: |
92c78ee6 | 71 | @end menu |
6f715d66 SC |
72 | */ |
73 | ||
74 | ||
0cda46cf SC |
75 | /* |
76 | ||
e98e6ec1 SC |
77 | INODE |
78 | bfd_target, , Targets, Targets | |
6f715d66 | 79 | |
0cda46cf SC |
80 | SUBSECTION |
81 | bfd_target | |
82 | ||
e98e6ec1 | 83 | DESCRIPTION |
0cda46cf SC |
84 | This structure contains everything that BFD knows about a |
85 | target. It includes things like its byte order, name, what | |
86 | routines to call to do various operations, etc. | |
6f715d66 | 87 | |
0cda46cf SC |
88 | Every BFD points to a target structure with its <<xvec>> |
89 | member. | |
6f715d66 | 90 | |
0cda46cf SC |
91 | Shortcut for declaring fields which are prototyped function |
92 | pointers, while avoiding anguish on compilers that don't | |
93 | support protos. | |
6f715d66 | 94 | |
0cda46cf SC |
95 | .#define SDEF(ret, name, arglist) \ |
96 | . PROTO(ret,(*name),arglist) | |
97 | .#define SDEF_FMT(ret, name, arglist) \ | |
98 | . PROTO(ret,(*name[bfd_type_end]),arglist) | |
6f715d66 | 99 | |
0cda46cf SC |
100 | These macros are used to dispatch to functions through the |
101 | bfd_target vector. They are used in a number of macros further | |
102 | down in @file{bfd.h}, and are also used when calling various | |
103 | routines by hand inside the BFD implementation. The "arglist" | |
104 | argument must be parenthesized; it contains all the arguments | |
105 | to the called function. | |
6f715d66 | 106 | |
ce07dd7c KR |
107 | They make the documentation (more) unpleasant to read, so if |
108 | someone wants to fix this and not break the above, please do. | |
6f715d66 | 109 | |
0cda46cf SC |
110 | .#define BFD_SEND(bfd, message, arglist) \ |
111 | . ((*((bfd)->xvec->message)) arglist) | |
6f715d66 | 112 | |
0cda46cf | 113 | For operations which index on the BFD format |
6f715d66 | 114 | |
0cda46cf SC |
115 | .#define BFD_SEND_FMT(bfd, message, arglist) \ |
116 | . (((bfd)->xvec->message[(int)((bfd)->format)]) arglist) | |
6f715d66 | 117 | |
0cda46cf SC |
118 | This is the struct which defines the type of BFD this is. The |
119 | <<xvec>> member of the struct <<bfd>> itself points here. Each | |
120 | module that implements access to a different target under BFD, | |
121 | defines one of these. | |
6f715d66 | 122 | |
6f715d66 | 123 | |
0cda46cf SC |
124 | FIXME, these names should be rationalised with the names of |
125 | the entry points which call them. Too bad we can't have one | |
126 | macro to define them both! | |
127 | ||
128 | .typedef struct bfd_target | |
129 | .{ | |
6f715d66 | 130 | |
ce07dd7c | 131 | Identifies the kind of target, eg SunOS4, Ultrix, etc. |
6f715d66 | 132 | |
0cda46cf | 133 | . char *name; |
6f715d66 SC |
134 | |
135 | The "flavour" of a back end is a general indication about the contents | |
136 | of a file. | |
137 | ||
0cda46cf SC |
138 | . enum target_flavour { |
139 | . bfd_target_unknown_flavour, | |
140 | . bfd_target_aout_flavour, | |
141 | . bfd_target_coff_flavour, | |
142 | . bfd_target_elf_flavour, | |
143 | . bfd_target_ieee_flavour, | |
144 | . bfd_target_oasys_flavour, | |
69e0d34d | 145 | . bfd_target_tekhex_flavour, |
e3c01e92 SG |
146 | . bfd_target_srec_flavour, |
147 | . bfd_target_hppa_flavour} flavour; | |
6f715d66 SC |
148 | |
149 | The order of bytes within the data area of a file. | |
150 | ||
0cda46cf | 151 | . boolean byteorder_big_p; |
6f715d66 SC |
152 | |
153 | The order of bytes within the header parts of a file. | |
154 | ||
0cda46cf | 155 | . boolean header_byteorder_big_p; |
6f715d66 SC |
156 | |
157 | This is a mask of all the flags which an executable may have set - | |
0cda46cf | 158 | from the set <<NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>. |
6f715d66 | 159 | |
0cda46cf | 160 | . flagword object_flags; |
6f715d66 SC |
161 | |
162 | This is a mask of all the flags which a section may have set - from | |
0cda46cf | 163 | the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>. |
6f715d66 | 164 | |
0cda46cf | 165 | . flagword section_flags; |
6f715d66 SC |
166 | |
167 | The pad character for filenames within an archive header. | |
168 | ||
0cda46cf | 169 | . char ar_pad_char; |
6f715d66 SC |
170 | |
171 | The maximum number of characters in an archive header. | |
172 | ||
0cda46cf | 173 | . unsigned short ar_max_namelen; |
6f715d66 SC |
174 | |
175 | The minimum alignment restriction for any section. | |
176 | ||
0cda46cf | 177 | . unsigned int align_power_min; |
6f715d66 SC |
178 | |
179 | Entries for byte swapping for data. These are different to the other | |
4e6f9223 | 180 | entry points, since they don't take BFD as first arg. Certain other handlers |
6f715d66 SC |
181 | could do the same. |
182 | ||
0cda46cf SC |
183 | . SDEF (bfd_vma, bfd_getx64, (bfd_byte *)); |
184 | . SDEF (void, bfd_putx64, (bfd_vma, bfd_byte *)); | |
185 | . SDEF (bfd_vma, bfd_getx32, (bfd_byte *)); | |
186 | . SDEF (void, bfd_putx32, (bfd_vma, bfd_byte *)); | |
187 | . SDEF (bfd_vma, bfd_getx16, (bfd_byte *)); | |
188 | . SDEF (void, bfd_putx16, (bfd_vma, bfd_byte *)); | |
6f715d66 SC |
189 | |
190 | Byte swapping for the headers | |
191 | ||
0cda46cf SC |
192 | . SDEF (bfd_vma, bfd_h_getx64, (bfd_byte *)); |
193 | . SDEF (void, bfd_h_putx64, (bfd_vma, bfd_byte *)); | |
194 | . SDEF (bfd_vma, bfd_h_getx32, (bfd_byte *)); | |
195 | . SDEF (void, bfd_h_putx32, (bfd_vma, bfd_byte *)); | |
196 | . SDEF (bfd_vma, bfd_h_getx16, (bfd_byte *)); | |
197 | . SDEF (void, bfd_h_putx16, (bfd_vma, bfd_byte *)); | |
6f715d66 SC |
198 | |
199 | Format dependent routines, these turn into vectors of entry points | |
200 | within the target vector structure; one for each format to check. | |
201 | ||
202 | Check the format of a file being read. Return bfd_target * or zero. | |
203 | ||
0cda46cf | 204 | . SDEF_FMT (struct bfd_target *, _bfd_check_format, (bfd *)); |
6f715d66 SC |
205 | |
206 | Set the format of a file being written. | |
207 | ||
0cda46cf | 208 | . SDEF_FMT (boolean, _bfd_set_format, (bfd *)); |
6f715d66 SC |
209 | |
210 | Write cached information into a file being written, at bfd_close. | |
211 | ||
0cda46cf | 212 | . SDEF_FMT (boolean, _bfd_write_contents, (bfd *)); |
6f715d66 | 213 | |
0cda46cf SC |
214 | The following functions are defined in <<JUMP_TABLE>>. The idea is |
215 | that the back end writer of <<foo>> names all the routines | |
216 | <<foo_>>@var{entry_point}, <<JUMP_TABLE>> will built the entries | |
6f715d66 SC |
217 | in this structure in the right order. |
218 | ||
219 | Core file entry points | |
220 | ||
0cda46cf SC |
221 | . SDEF (char *, _core_file_failing_command, (bfd *)); |
222 | . SDEF (int, _core_file_failing_signal, (bfd *)); | |
223 | . SDEF (boolean, _core_file_matches_executable_p, (bfd *, bfd *)); | |
6f715d66 SC |
224 | |
225 | Archive entry points | |
226 | ||
0cda46cf SC |
227 | . SDEF (boolean, _bfd_slurp_armap, (bfd *)); |
228 | . SDEF (boolean, _bfd_slurp_extended_name_table, (bfd *)); | |
229 | . SDEF (void, _bfd_truncate_arname, (bfd *, CONST char *, char *)); | |
230 | . SDEF (boolean, write_armap, (bfd *arch, | |
231 | . unsigned int elength, | |
232 | . struct orl *map, | |
233 | . unsigned int orl_count, | |
234 | . int stridx)); | |
6f715d66 SC |
235 | |
236 | Standard stuff. | |
237 | ||
0cda46cf SC |
238 | . SDEF (boolean, _close_and_cleanup, (bfd *)); |
239 | . SDEF (boolean, _bfd_set_section_contents, (bfd *, sec_ptr, PTR, | |
240 | . file_ptr, bfd_size_type)); | |
241 | . SDEF (boolean, _bfd_get_section_contents, (bfd *, sec_ptr, PTR, | |
242 | . file_ptr, bfd_size_type)); | |
243 | . SDEF (boolean, _new_section_hook, (bfd *, sec_ptr)); | |
6f715d66 | 244 | |
ce07dd7c | 245 | Symbols and relocations |
6f715d66 | 246 | |
0cda46cf SC |
247 | . SDEF (unsigned int, _get_symtab_upper_bound, (bfd *)); |
248 | . SDEF (unsigned int, _bfd_canonicalize_symtab, | |
249 | . (bfd *, struct symbol_cache_entry **)); | |
250 | . SDEF (unsigned int, _get_reloc_upper_bound, (bfd *, sec_ptr)); | |
251 | . SDEF (unsigned int, _bfd_canonicalize_reloc, (bfd *, sec_ptr, arelent **, | |
252 | . struct symbol_cache_entry**)); | |
253 | . SDEF (struct symbol_cache_entry *, _bfd_make_empty_symbol, (bfd *)); | |
254 | . SDEF (void, _bfd_print_symbol, (bfd *, PTR, struct symbol_cache_entry *, | |
255 | . bfd_print_symbol_type)); | |
256 | .#define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e)) | |
257 | . SDEF (alent *, _get_lineno, (bfd *, struct symbol_cache_entry *)); | |
258 | . | |
259 | . SDEF (boolean, _bfd_set_arch_mach, (bfd *, enum bfd_architecture, | |
260 | . unsigned long)); | |
261 | . | |
262 | . SDEF (bfd *, openr_next_archived_file, (bfd *arch, bfd *prev)); | |
263 | . SDEF (boolean, _bfd_find_nearest_line, | |
264 | . (bfd *abfd, struct sec *section, | |
265 | . struct symbol_cache_entry **symbols,bfd_vma offset, | |
266 | . CONST char **file, CONST char **func, unsigned int *line)); | |
267 | . SDEF (int, _bfd_stat_arch_elt, (bfd *, struct stat *)); | |
268 | . | |
269 | . SDEF (int, _bfd_sizeof_headers, (bfd *, boolean)); | |
270 | . | |
271 | . SDEF (void, _bfd_debug_info_start, (bfd *)); | |
272 | . SDEF (void, _bfd_debug_info_end, (bfd *)); | |
273 | . SDEF (void, _bfd_debug_info_accumulate, (bfd *, struct sec *)); | |
ce07dd7c | 274 | . SDEF (bfd_byte *, _bfd_get_relocated_section_contents, (bfd*,struct bfd_seclet_struct *, bfd_byte *data)); |
69e0d34d | 275 | . SDEF (boolean,_bfd_relax_section,(bfd *, struct sec *, struct symbol_cache_entry **)); |
6f715d66 SC |
276 | Special entry points for gdb to swap in coff symbol table parts |
277 | ||
0cda46cf SC |
278 | . SDEF(void, _bfd_coff_swap_aux_in,( |
279 | . bfd *abfd , | |
280 | . PTR ext, | |
281 | . int type, | |
282 | . int class , | |
283 | . PTR in)); | |
284 | . | |
285 | . SDEF(void, _bfd_coff_swap_sym_in,( | |
286 | . bfd *abfd , | |
287 | . PTR ext, | |
288 | . PTR in)); | |
289 | . | |
290 | . SDEF(void, _bfd_coff_swap_lineno_in, ( | |
291 | . bfd *abfd, | |
292 | . PTR ext, | |
293 | . PTR in)); | |
294 | . | |
0d740984 SC |
295 | |
296 | Special entry points for gas to swap coff parts | |
297 | ||
0cda46cf SC |
298 | . SDEF(unsigned int, _bfd_coff_swap_aux_out,( |
299 | . bfd *abfd, | |
300 | . PTR in, | |
301 | . int type, | |
302 | . int class, | |
303 | . PTR ext)); | |
304 | . | |
305 | . SDEF(unsigned int, _bfd_coff_swap_sym_out,( | |
306 | . bfd *abfd, | |
307 | . PTR in, | |
308 | . PTR ext)); | |
309 | . | |
310 | . SDEF(unsigned int, _bfd_coff_swap_lineno_out,( | |
311 | . bfd *abfd, | |
312 | . PTR in, | |
313 | . PTR ext)); | |
314 | . | |
315 | . SDEF(unsigned int, _bfd_coff_swap_reloc_out,( | |
316 | . bfd *abfd, | |
317 | . PTR src, | |
318 | . PTR dst)); | |
319 | . | |
320 | . SDEF(unsigned int, _bfd_coff_swap_filehdr_out,( | |
321 | . bfd *abfd, | |
322 | . PTR in, | |
323 | . PTR out)); | |
324 | . | |
325 | . SDEF(unsigned int, _bfd_coff_swap_aouthdr_out,( | |
326 | . bfd *abfd, | |
327 | . PTR in, | |
328 | . PTR out)); | |
329 | . | |
330 | . SDEF(unsigned int, _bfd_coff_swap_scnhdr_out,( | |
331 | . bfd *abfd, | |
332 | . PTR in, | |
333 | . PTR out)); | |
334 | . | |
ce07dd7c KR |
335 | . {* See documentation on reloc types. *} |
336 | . SDEF (CONST struct reloc_howto_struct *, | |
337 | . reloc_type_lookup, | |
800aef7c | 338 | . (bfd *abfd, bfd_reloc_code_real_type code)); |
ce07dd7c KR |
339 | . |
340 | . {* Complete and utter crock, currently used for the assembler | |
341 | . when creating COFF files. *} | |
342 | . SDEF (asymbol *, _bfd_make_debug_symbol, ( | |
343 | . bfd *abfd, | |
344 | . void *ptr, | |
345 | . unsigned long size)); | |
346 | ||
347 | Data for use by back-end routines; e.g., for a.out, includes whether | |
348 | this particular target maps ZMAGIC files contiguously or with text and | |
349 | data separated. Could perhaps also be used to eliminate some of the | |
350 | above COFF-specific fields. | |
351 | ||
352 | . PTR backend_data; | |
0cda46cf | 353 | .} bfd_target; |
6f715d66 SC |
354 | |
355 | */ | |
f8adc62d | 356 | |
616ebcfd SC |
357 | /* The default is to define a target_vector containing all the targets. |
358 | By setting MINIMIZE=1 on the "make" command line, the user can change this | |
359 | to a vector containing just DEFAULT_VECTOR and any required | |
360 | traditional-core-file handler. (This is to save space in the executables.) | |
361 | The config files can also override the default large vector by giving an | |
362 | explicit SELECT_VECS macro. */ | |
f8adc62d JG |
363 | |
364 | #if MINIMIZE && defined(DEFAULT_VECTOR) && !defined(SELECT_VECS) | |
365 | #ifdef TRAD_CORE | |
366 | #define SELECT_VECS &DEFAULT_VECTOR,&trad_core_vec | |
367 | #else | |
368 | #define SELECT_VECS &DEFAULT_VECTOR | |
369 | #endif | |
370 | #endif | |
371 | ||
616ebcfd SC |
372 | /* All known xvecs. They are listed a second time below, since |
373 | we can't intermix extern's and initializers. */ | |
23b0b558 JG |
374 | extern bfd_target ecoff_little_vec; |
375 | extern bfd_target ecoff_big_vec; | |
2b1d8a50 | 376 | extern bfd_target sunos_big_vec; |
7ed4093a | 377 | extern bfd_target demo_64_vec; |
4a81b561 | 378 | extern bfd_target srec_vec; |
69e0d34d | 379 | extern bfd_target tekhex_vec; |
4a81b561 DHW |
380 | extern bfd_target b_out_vec_little_host; |
381 | extern bfd_target b_out_vec_big_host; | |
382 | extern bfd_target icoff_little_vec; | |
383 | extern bfd_target icoff_big_vec; | |
3f85ebce JG |
384 | extern bfd_target elf_little_vec; |
385 | extern bfd_target elf_big_vec; | |
aacf30e3 DHW |
386 | extern bfd_target ieee_vec; |
387 | extern bfd_target oasys_vec; | |
f8adc62d | 388 | extern bfd_target m88kbcs_vec; |
c407897e | 389 | extern bfd_target m68kcoff_vec; |
20fdc627 | 390 | extern bfd_target i386coff_vec; |
bbc8d484 | 391 | extern bfd_target i386aout_vec; |
41f50af0 | 392 | extern bfd_target a29kcoff_big_vec; |
f58809fd | 393 | extern bfd_target trad_core_vec; |
cbdc7909 | 394 | extern bfd_target rs6000coff_vec; |
3b4f1a5d | 395 | extern bfd_target h8300coff_vec; |
e3c01e92 SG |
396 | #ifdef hp9000s800 |
397 | extern bfd_target hppa_vec; | |
398 | #endif | |
4e6f9223 | 399 | |
f8adc62d JG |
400 | #ifdef DEFAULT_VECTOR |
401 | extern bfd_target DEFAULT_VECTOR; | |
402 | #endif | |
403 | ||
4e6f9223 SC |
404 | #ifdef SELECT_VECS |
405 | ||
406 | bfd_target *target_vector[] = { | |
f39b81f5 | 407 | SELECT_VECS, |
616ebcfd | 408 | 0 |
4e6f9223 | 409 | }; |
c0e5039e | 410 | |
616ebcfd | 411 | #else |
4e6f9223 | 412 | |
7d774e01 | 413 | bfd_target *target_vector[] = { |
f39b81f5 SC |
414 | |
415 | #ifdef DEFAULT_VECTOR | |
416 | &DEFAULT_VECTOR, | |
417 | #endif | |
418 | ||
419 | &i386coff_vec, | |
420 | &i386aout_vec, | |
421 | &ecoff_little_vec, | |
422 | &ecoff_big_vec, | |
423 | &ieee_vec, | |
ce07dd7c | 424 | #if 1 |
f39b81f5 SC |
425 | /* We have no oasys tools anymore, so we can't test any of this |
426 | anymore. If you want to test the stuff yourself, go ahead... | |
427 | [email protected] */ | |
428 | &oasys_vec, | |
429 | #endif | |
430 | &sunos_big_vec, | |
431 | #ifdef HOST_64_BIT | |
432 | &demo_64_vec, /* Only compiled if host has long-long support */ | |
433 | #endif | |
434 | &h8300coff_vec, | |
435 | &m88kbcs_vec, | |
436 | &srec_vec, | |
69e0d34d | 437 | /* &tekhex_vec,*/ |
616ebcfd | 438 | &icoff_little_vec, |
f39b81f5 SC |
439 | &icoff_big_vec, |
440 | &elf_little_vec, | |
441 | &elf_big_vec, | |
442 | &b_out_vec_little_host, | |
443 | &b_out_vec_big_host, | |
444 | &m68kcoff_vec, | |
445 | &a29kcoff_big_vec, | |
446 | &rs6000coff_vec, | |
e3c01e92 SG |
447 | #ifdef hp9000s800 |
448 | &hppa_vec, | |
449 | #endif | |
f39b81f5 SC |
450 | |
451 | #ifdef TRAD_CORE | |
452 | &trad_core_vec, | |
453 | #endif | |
616ebcfd | 454 | NULL, /* end of list marker */ |
7d774e01 | 455 | }; |
c0e5039e | 456 | |
4e6f9223 | 457 | #endif |
c0e5039e JG |
458 | |
459 | /* default_vector[0] contains either the address of the default vector, | |
460 | if there is one, or zero if there isn't. */ | |
461 | ||
462 | bfd_target *default_vector[] = { | |
463 | #ifdef DEFAULT_VECTOR | |
616ebcfd | 464 | &DEFAULT_VECTOR, |
c0e5039e | 465 | #endif |
616ebcfd | 466 | 0, |
c0e5039e | 467 | }; |
6f715d66 SC |
468 | |
469 | ||
470 | ||
471 | ||
0cda46cf SC |
472 | /* |
473 | FUNCTION | |
474 | bfd_find_target | |
475 | ||
476 | DESCRIPTION | |
477 | Returns a pointer to the transfer vector for the object target | |
478 | named target_name. If target_name is NULL, chooses the one in | |
479 | the environment variable GNUTARGET; if that is null or not | |
480 | defined thenthe first entry in the target list is chosen. | |
481 | Passing in the string "default" or setting the environment | |
482 | variable to "default" will cause the first entry in the target | |
483 | list to be returned, and "target_defaulted" will be set in the | |
484 | BFD. This causes <<bfd_check_format>> to loop over all the | |
485 | targets to find the one that matches the file being read. | |
486 | ||
487 | SYNOPSIS | |
488 | bfd_target *bfd_find_target(CONST char *, bfd *); | |
489 | */ | |
6f715d66 SC |
490 | |
491 | bfd_target * | |
492 | DEFUN(bfd_find_target,(target_name, abfd), | |
493 | CONST char *target_name AND | |
494 | bfd *abfd) | |
495 | { | |
496 | bfd_target **target; | |
497 | extern char *getenv (); | |
f8adc62d JG |
498 | CONST char *targname = (target_name ? target_name : |
499 | (CONST char *) getenv ("GNUTARGET")); | |
6f715d66 SC |
500 | |
501 | /* This is safe; the vector cannot be null */ | |
502 | if (targname == NULL || !strcmp (targname, "default")) { | |
503 | abfd->target_defaulted = true; | |
504 | return abfd->xvec = target_vector[0]; | |
505 | } | |
506 | ||
507 | abfd->target_defaulted = false; | |
508 | ||
509 | for (target = &target_vector[0]; *target != NULL; target++) { | |
510 | if (!strcmp (targname, (*target)->name)) | |
511 | return abfd->xvec = *target; | |
512 | } | |
513 | ||
514 | bfd_error = invalid_target; | |
515 | return NULL; | |
516 | } | |
517 | ||
518 | ||
0cda46cf SC |
519 | /* |
520 | FUNCTION | |
521 | bfd_target_list | |
522 | ||
523 | DESCRIPTION | |
524 | This function returns a freshly malloced NULL-terminated | |
525 | vector of the names of all the valid BFD targets. Do not | |
526 | modify the names | |
6f715d66 | 527 | |
0cda46cf | 528 | SYNOPSIS |
69e0d34d | 529 | CONST char **bfd_target_list(void); |
0cda46cf SC |
530 | |
531 | */ | |
6f715d66 SC |
532 | |
533 | CONST char ** | |
534 | DEFUN_VOID(bfd_target_list) | |
535 | { | |
536 | int vec_length= 0; | |
537 | bfd_target **target; | |
4e6f9223 | 538 | CONST char **name_list, **name_ptr; |
6f715d66 SC |
539 | |
540 | for (target = &target_vector[0]; *target != NULL; target++) | |
541 | vec_length++; | |
542 | ||
543 | name_ptr = | |
544 | name_list = (CONST char **) zalloc ((vec_length + 1) * sizeof (char **)); | |
545 | ||
546 | if (name_list == NULL) { | |
547 | bfd_error = no_memory; | |
548 | return NULL; | |
549 | } | |
550 | ||
6f715d66 SC |
551 | for (target = &target_vector[0]; *target != NULL; target++) |
552 | *(name_ptr++) = (*target)->name; | |
553 | ||
554 | return name_list; | |
555 | } |