targets.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. /* Generic target-file-type support for the BFD library.
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. Written by Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "fnmatch.h"
  21. /*
  22. It's okay to see some:
  23. #if 0
  24. directives in this source file, as targets.c uses them to exclude
  25. certain BFD vectors. This comment is specially formatted to catch
  26. users who grep for ^#if 0, so please keep it this way!
  27. */
  28. /*
  29. SECTION
  30. Targets
  31. DESCRIPTION
  32. Each port of BFD to a different machine requires 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. When a file is opened with <<bfd_openr>>, its format and
  39. target are unknown. BFD uses various mechanisms to determine
  40. how to interpret the file. The operations performed are:
  41. o Create a BFD by calling the internal routine
  42. <<_bfd_new_bfd>>, then call <<bfd_find_target>> with the
  43. target string supplied to <<bfd_openr>> and the new BFD pointer.
  44. o If a null target string was provided to <<bfd_find_target>>,
  45. look up the environment variable <<GNUTARGET>> and use
  46. that as the target string.
  47. o If the target string is still <<NULL>>, or the target string is
  48. <<default>>, then use the first item in the target vector
  49. as the target type, and set <<target_defaulted>> in the BFD to
  50. cause <<bfd_check_format>> to loop through all the targets.
  51. @xref{bfd_target}. @xref{Formats}.
  52. o Otherwise, inspect the elements in the target vector
  53. one by one, until a match on target name is found. When found,
  54. use it.
  55. o Otherwise return the error <<bfd_error_invalid_target>> to
  56. <<bfd_openr>>.
  57. o <<bfd_openr>> attempts to open the file using
  58. <<bfd_open_file>>, and returns the BFD.
  59. Once the BFD has been opened and the target selected, the file
  60. format may be determined. This is done by calling
  61. <<bfd_check_format>> on the BFD with a suggested format.
  62. If <<target_defaulted>> has been set, each possible target
  63. type is tried to see if it recognizes the specified format.
  64. <<bfd_check_format>> returns <<TRUE>> when the caller guesses right.
  65. @menu
  66. @* bfd_target::
  67. @end menu
  68. */
  69. /*
  70. INODE
  71. bfd_target, , Targets, Targets
  72. DOCDD
  73. SUBSECTION
  74. bfd_target
  75. DESCRIPTION
  76. This structure contains everything that BFD knows about a
  77. target. It includes things like its byte order, name, and which
  78. routines to call to do various operations.
  79. Every BFD points to a target structure with its <<xvec>>
  80. member.
  81. The macros below are used to dispatch to functions through the
  82. <<bfd_target>> vector. They are used in a number of macros further
  83. down in @file{bfd.h}, and are also used when calling various
  84. routines by hand inside the BFD implementation. The @var{arglist}
  85. argument must be parenthesized; it contains all the arguments
  86. to the called function.
  87. They make the documentation (more) unpleasant to read, so if
  88. someone wants to fix this and not break the above, please do.
  89. .#define BFD_SEND(bfd, message, arglist) \
  90. . ((*((bfd)->xvec->message)) arglist)
  91. .
  92. .#ifdef DEBUG_BFD_SEND
  93. .#undef BFD_SEND
  94. .#define BFD_SEND(bfd, message, arglist) \
  95. . (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
  96. . ((*((bfd)->xvec->message)) arglist) : \
  97. . (bfd_assert (__FILE__,__LINE__), NULL))
  98. .#endif
  99. For operations which index on the BFD format:
  100. .#define BFD_SEND_FMT(bfd, message, arglist) \
  101. . (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist)
  102. .
  103. .#ifdef DEBUG_BFD_SEND
  104. .#undef BFD_SEND_FMT
  105. .#define BFD_SEND_FMT(bfd, message, arglist) \
  106. . (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
  107. . (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist) : \
  108. . (bfd_assert (__FILE__,__LINE__), NULL))
  109. .#endif
  110. .
  111. .{* Defined to TRUE if unused section symbol should be kept. *}
  112. .#ifndef TARGET_KEEP_UNUSED_SECTION_SYMBOLS
  113. .#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS true
  114. .#endif
  115. .
  116. This is the structure which defines the type of BFD this is. The
  117. <<xvec>> member of the struct <<bfd>> itself points here. Each
  118. module that implements access to a different target under BFD,
  119. defines one of these.
  120. FIXME, these names should be rationalised with the names of
  121. the entry points which call them. Too bad we can't have one
  122. macro to define them both!
  123. .enum bfd_flavour
  124. .{
  125. . {* N.B. Update bfd_flavour_name if you change this. *}
  126. . bfd_target_unknown_flavour,
  127. . bfd_target_aout_flavour,
  128. . bfd_target_coff_flavour,
  129. . bfd_target_ecoff_flavour,
  130. . bfd_target_xcoff_flavour,
  131. . bfd_target_elf_flavour,
  132. . bfd_target_tekhex_flavour,
  133. . bfd_target_srec_flavour,
  134. . bfd_target_verilog_flavour,
  135. . bfd_target_ihex_flavour,
  136. . bfd_target_som_flavour,
  137. . bfd_target_os9k_flavour,
  138. . bfd_target_versados_flavour,
  139. . bfd_target_msdos_flavour,
  140. . bfd_target_ovax_flavour,
  141. . bfd_target_evax_flavour,
  142. . bfd_target_mmo_flavour,
  143. . bfd_target_mach_o_flavour,
  144. . bfd_target_pef_flavour,
  145. . bfd_target_pef_xlib_flavour,
  146. . bfd_target_sym_flavour
  147. .};
  148. .
  149. .enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
  150. .
  151. .{* Forward declaration. *}
  152. .typedef struct bfd_link_info _bfd_link_info;
  153. .
  154. .{* Forward declaration. *}
  155. .typedef struct flag_info flag_info;
  156. .
  157. .typedef void (*bfd_cleanup) (bfd *);
  158. .
  159. .typedef struct bfd_target
  160. .{
  161. . {* Identifies the kind of target, e.g., SunOS4, Ultrix, etc. *}
  162. . const char *name;
  163. .
  164. . {* The "flavour" of a back end is a general indication about
  165. . the contents of a file. *}
  166. . enum bfd_flavour flavour;
  167. .
  168. . {* The order of bytes within the data area of a file. *}
  169. . enum bfd_endian byteorder;
  170. .
  171. . {* The order of bytes within the header parts of a file. *}
  172. . enum bfd_endian header_byteorder;
  173. .
  174. . {* A mask of all the flags which an executable may have set -
  175. . from the set <<BFD_NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>. *}
  176. . flagword object_flags;
  177. .
  178. . {* A mask of all the flags which a section may have set - from
  179. . the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>. *}
  180. . flagword section_flags;
  181. .
  182. . {* The character normally found at the front of a symbol.
  183. . (if any), perhaps `_'. *}
  184. . char symbol_leading_char;
  185. .
  186. . {* The pad character for file names within an archive header. *}
  187. . char ar_pad_char;
  188. .
  189. . {* The maximum number of characters in an archive header. *}
  190. . unsigned char ar_max_namelen;
  191. .
  192. . {* How well this target matches, used to select between various
  193. . possible targets when more than one target matches. *}
  194. . unsigned char match_priority;
  195. .
  196. . {* TRUE if unused section symbols should be kept. *}
  197. . bool keep_unused_section_symbols;
  198. .
  199. . {* Entries for byte swapping for data. These are different from the
  200. . other entry points, since they don't take a BFD as the first argument.
  201. . Certain other handlers could do the same. *}
  202. . bfd_uint64_t (*bfd_getx64) (const void *);
  203. . bfd_int64_t (*bfd_getx_signed_64) (const void *);
  204. . void (*bfd_putx64) (bfd_uint64_t, void *);
  205. . bfd_vma (*bfd_getx32) (const void *);
  206. . bfd_signed_vma (*bfd_getx_signed_32) (const void *);
  207. . void (*bfd_putx32) (bfd_vma, void *);
  208. . bfd_vma (*bfd_getx16) (const void *);
  209. . bfd_signed_vma (*bfd_getx_signed_16) (const void *);
  210. . void (*bfd_putx16) (bfd_vma, void *);
  211. .
  212. . {* Byte swapping for the headers. *}
  213. . bfd_uint64_t (*bfd_h_getx64) (const void *);
  214. . bfd_int64_t (*bfd_h_getx_signed_64) (const void *);
  215. . void (*bfd_h_putx64) (bfd_uint64_t, void *);
  216. . bfd_vma (*bfd_h_getx32) (const void *);
  217. . bfd_signed_vma (*bfd_h_getx_signed_32) (const void *);
  218. . void (*bfd_h_putx32) (bfd_vma, void *);
  219. . bfd_vma (*bfd_h_getx16) (const void *);
  220. . bfd_signed_vma (*bfd_h_getx_signed_16) (const void *);
  221. . void (*bfd_h_putx16) (bfd_vma, void *);
  222. .
  223. . {* Format dependent routines: these are vectors of entry points
  224. . within the target vector structure, one for each format to check. *}
  225. .
  226. . {* Check the format of a file being read. Return a <<bfd_cleanup>> on
  227. . success or zero on failure. *}
  228. . bfd_cleanup (*_bfd_check_format[bfd_type_end]) (bfd *);
  229. .
  230. . {* Set the format of a file being written. *}
  231. . bool (*_bfd_set_format[bfd_type_end]) (bfd *);
  232. .
  233. . {* Write cached information into a file being written, at <<bfd_close>>. *}
  234. . bool (*_bfd_write_contents[bfd_type_end]) (bfd *);
  235. .
  236. The general target vector. These vectors are initialized using the
  237. BFD_JUMP_TABLE macros.
  238. .
  239. . {* Generic entry points. *}
  240. .#define BFD_JUMP_TABLE_GENERIC(NAME) \
  241. . NAME##_close_and_cleanup, \
  242. . NAME##_bfd_free_cached_info, \
  243. . NAME##_new_section_hook, \
  244. . NAME##_get_section_contents, \
  245. . NAME##_get_section_contents_in_window
  246. .
  247. . {* Called when the BFD is being closed to do any necessary cleanup. *}
  248. . bool (*_close_and_cleanup) (bfd *);
  249. . {* Ask the BFD to free all cached information. *}
  250. . bool (*_bfd_free_cached_info) (bfd *);
  251. . {* Called when a new section is created. *}
  252. . bool (*_new_section_hook) (bfd *, sec_ptr);
  253. . {* Read the contents of a section. *}
  254. . bool (*_bfd_get_section_contents) (bfd *, sec_ptr, void *, file_ptr,
  255. . bfd_size_type);
  256. . bool (*_bfd_get_section_contents_in_window) (bfd *, sec_ptr, bfd_window *,
  257. . file_ptr, bfd_size_type);
  258. .
  259. . {* Entry points to copy private data. *}
  260. .#define BFD_JUMP_TABLE_COPY(NAME) \
  261. . NAME##_bfd_copy_private_bfd_data, \
  262. . NAME##_bfd_merge_private_bfd_data, \
  263. . _bfd_generic_init_private_section_data, \
  264. . NAME##_bfd_copy_private_section_data, \
  265. . NAME##_bfd_copy_private_symbol_data, \
  266. . NAME##_bfd_copy_private_header_data, \
  267. . NAME##_bfd_set_private_flags, \
  268. . NAME##_bfd_print_private_bfd_data
  269. .
  270. . {* Called to copy BFD general private data from one object file
  271. . to another. *}
  272. . bool (*_bfd_copy_private_bfd_data) (bfd *, bfd *);
  273. . {* Called to merge BFD general private data from one object file
  274. . to a common output file when linking. *}
  275. . bool (*_bfd_merge_private_bfd_data) (bfd *, struct bfd_link_info *);
  276. . {* Called to initialize BFD private section data from one object file
  277. . to another. *}
  278. .#define bfd_init_private_section_data(ibfd, isec, obfd, osec, link_info) \
  279. . BFD_SEND (obfd, _bfd_init_private_section_data, \
  280. . (ibfd, isec, obfd, osec, link_info))
  281. . bool (*_bfd_init_private_section_data) (bfd *, sec_ptr, bfd *, sec_ptr,
  282. . struct bfd_link_info *);
  283. . {* Called to copy BFD private section data from one object file
  284. . to another. *}
  285. . bool (*_bfd_copy_private_section_data) (bfd *, sec_ptr, bfd *, sec_ptr);
  286. . {* Called to copy BFD private symbol data from one symbol
  287. . to another. *}
  288. . bool (*_bfd_copy_private_symbol_data) (bfd *, asymbol *,
  289. . bfd *, asymbol *);
  290. . {* Called to copy BFD private header data from one object file
  291. . to another. *}
  292. . bool (*_bfd_copy_private_header_data) (bfd *, bfd *);
  293. . {* Called to set private backend flags. *}
  294. . bool (*_bfd_set_private_flags) (bfd *, flagword);
  295. .
  296. . {* Called to print private BFD data. *}
  297. . bool (*_bfd_print_private_bfd_data) (bfd *, void *);
  298. .
  299. . {* Core file entry points. *}
  300. .#define BFD_JUMP_TABLE_CORE(NAME) \
  301. . NAME##_core_file_failing_command, \
  302. . NAME##_core_file_failing_signal, \
  303. . NAME##_core_file_matches_executable_p, \
  304. . NAME##_core_file_pid
  305. .
  306. . char *(*_core_file_failing_command) (bfd *);
  307. . int (*_core_file_failing_signal) (bfd *);
  308. . bool (*_core_file_matches_executable_p) (bfd *, bfd *);
  309. . int (*_core_file_pid) (bfd *);
  310. .
  311. . {* Archive entry points. *}
  312. .#define BFD_JUMP_TABLE_ARCHIVE(NAME) \
  313. . NAME##_slurp_armap, \
  314. . NAME##_slurp_extended_name_table, \
  315. . NAME##_construct_extended_name_table, \
  316. . NAME##_truncate_arname, \
  317. . NAME##_write_armap, \
  318. . NAME##_read_ar_hdr, \
  319. . NAME##_write_ar_hdr, \
  320. . NAME##_openr_next_archived_file, \
  321. . NAME##_get_elt_at_index, \
  322. . NAME##_generic_stat_arch_elt, \
  323. . NAME##_update_armap_timestamp
  324. .
  325. . bool (*_bfd_slurp_armap) (bfd *);
  326. . bool (*_bfd_slurp_extended_name_table) (bfd *);
  327. . bool (*_bfd_construct_extended_name_table) (bfd *, char **,
  328. . bfd_size_type *,
  329. . const char **);
  330. . void (*_bfd_truncate_arname) (bfd *, const char *, char *);
  331. . bool (*write_armap) (bfd *, unsigned, struct orl *, unsigned, int);
  332. . void *(*_bfd_read_ar_hdr_fn) (bfd *);
  333. . bool (*_bfd_write_ar_hdr_fn) (bfd *, bfd *);
  334. . bfd *(*openr_next_archived_file) (bfd *, bfd *);
  335. .#define bfd_get_elt_at_index(b,i) \
  336. . BFD_SEND (b, _bfd_get_elt_at_index, (b,i))
  337. . bfd *(*_bfd_get_elt_at_index) (bfd *, symindex);
  338. . int (*_bfd_stat_arch_elt) (bfd *, struct stat *);
  339. . bool (*_bfd_update_armap_timestamp) (bfd *);
  340. .
  341. . {* Entry points used for symbols. *}
  342. .#define BFD_JUMP_TABLE_SYMBOLS(NAME) \
  343. . NAME##_get_symtab_upper_bound, \
  344. . NAME##_canonicalize_symtab, \
  345. . NAME##_make_empty_symbol, \
  346. . NAME##_print_symbol, \
  347. . NAME##_get_symbol_info, \
  348. . NAME##_get_symbol_version_string, \
  349. . NAME##_bfd_is_local_label_name, \
  350. . NAME##_bfd_is_target_special_symbol, \
  351. . NAME##_get_lineno, \
  352. . NAME##_find_nearest_line, \
  353. . NAME##_find_line, \
  354. . NAME##_find_inliner_info, \
  355. . NAME##_bfd_make_debug_symbol, \
  356. . NAME##_read_minisymbols, \
  357. . NAME##_minisymbol_to_symbol
  358. .
  359. . long (*_bfd_get_symtab_upper_bound) (bfd *);
  360. . long (*_bfd_canonicalize_symtab) (bfd *, struct bfd_symbol **);
  361. . struct bfd_symbol *
  362. . (*_bfd_make_empty_symbol) (bfd *);
  363. . void (*_bfd_print_symbol) (bfd *, void *, struct bfd_symbol *,
  364. . bfd_print_symbol_type);
  365. .#define bfd_print_symbol(b,p,s,e) \
  366. . BFD_SEND (b, _bfd_print_symbol, (b,p,s,e))
  367. . void (*_bfd_get_symbol_info) (bfd *, struct bfd_symbol *, symbol_info *);
  368. .#define bfd_get_symbol_info(b,p,e) \
  369. . BFD_SEND (b, _bfd_get_symbol_info, (b,p,e))
  370. . const char *
  371. . (*_bfd_get_symbol_version_string) (bfd *, struct bfd_symbol *,
  372. . bool, bool *);
  373. .#define bfd_get_symbol_version_string(b,s,p,h) \
  374. . BFD_SEND (b, _bfd_get_symbol_version_string, (b,s,p,h))
  375. . bool (*_bfd_is_local_label_name) (bfd *, const char *);
  376. . bool (*_bfd_is_target_special_symbol) (bfd *, asymbol *);
  377. . alent *
  378. . (*_get_lineno) (bfd *, struct bfd_symbol *);
  379. . bool (*_bfd_find_nearest_line) (bfd *, struct bfd_symbol **,
  380. . struct bfd_section *, bfd_vma,
  381. . const char **, const char **,
  382. . unsigned int *, unsigned int *);
  383. . bool (*_bfd_find_line) (bfd *, struct bfd_symbol **,
  384. . struct bfd_symbol *, const char **,
  385. . unsigned int *);
  386. . bool (*_bfd_find_inliner_info)
  387. . (bfd *, const char **, const char **, unsigned int *);
  388. . {* Back-door to allow format-aware applications to create debug symbols
  389. . while using BFD for everything else. Currently used by the assembler
  390. . when creating COFF files. *}
  391. . asymbol *
  392. . (*_bfd_make_debug_symbol) (bfd *, void *, unsigned long size);
  393. .#define bfd_read_minisymbols(b, d, m, s) \
  394. . BFD_SEND (b, _read_minisymbols, (b, d, m, s))
  395. . long (*_read_minisymbols) (bfd *, bool, void **, unsigned int *);
  396. .#define bfd_minisymbol_to_symbol(b, d, m, f) \
  397. . BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
  398. . asymbol *
  399. . (*_minisymbol_to_symbol) (bfd *, bool, const void *, asymbol *);
  400. .
  401. . {* Routines for relocs. *}
  402. .#define BFD_JUMP_TABLE_RELOCS(NAME) \
  403. . NAME##_get_reloc_upper_bound, \
  404. . NAME##_canonicalize_reloc, \
  405. . NAME##_set_reloc, \
  406. . NAME##_bfd_reloc_type_lookup, \
  407. . NAME##_bfd_reloc_name_lookup
  408. .
  409. . long (*_get_reloc_upper_bound) (bfd *, sec_ptr);
  410. . long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
  411. . struct bfd_symbol **);
  412. . void (*_bfd_set_reloc) (bfd *, sec_ptr, arelent **, unsigned int);
  413. . {* See documentation on reloc types. *}
  414. . reloc_howto_type *
  415. . (*reloc_type_lookup) (bfd *, bfd_reloc_code_real_type);
  416. . reloc_howto_type *
  417. . (*reloc_name_lookup) (bfd *, const char *);
  418. .
  419. . {* Routines used when writing an object file. *}
  420. .#define BFD_JUMP_TABLE_WRITE(NAME) \
  421. . NAME##_set_arch_mach, \
  422. . NAME##_set_section_contents
  423. .
  424. . bool (*_bfd_set_arch_mach) (bfd *, enum bfd_architecture,
  425. . unsigned long);
  426. . bool (*_bfd_set_section_contents) (bfd *, sec_ptr, const void *,
  427. . file_ptr, bfd_size_type);
  428. .
  429. . {* Routines used by the linker. *}
  430. .#define BFD_JUMP_TABLE_LINK(NAME) \
  431. . NAME##_sizeof_headers, \
  432. . NAME##_bfd_get_relocated_section_contents, \
  433. . NAME##_bfd_relax_section, \
  434. . NAME##_bfd_link_hash_table_create, \
  435. . NAME##_bfd_link_add_symbols, \
  436. . NAME##_bfd_link_just_syms, \
  437. . NAME##_bfd_copy_link_hash_symbol_type, \
  438. . NAME##_bfd_final_link, \
  439. . NAME##_bfd_link_split_section, \
  440. . NAME##_bfd_link_check_relocs, \
  441. . NAME##_bfd_gc_sections, \
  442. . NAME##_bfd_lookup_section_flags, \
  443. . NAME##_bfd_merge_sections, \
  444. . NAME##_bfd_is_group_section, \
  445. . NAME##_bfd_group_name, \
  446. . NAME##_bfd_discard_group, \
  447. . NAME##_section_already_linked, \
  448. . NAME##_bfd_define_common_symbol, \
  449. . NAME##_bfd_link_hide_symbol, \
  450. . NAME##_bfd_define_start_stop
  451. .
  452. . int (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
  453. . bfd_byte *
  454. . (*_bfd_get_relocated_section_contents) (bfd *,
  455. . struct bfd_link_info *,
  456. . struct bfd_link_order *,
  457. . bfd_byte *, bool,
  458. . struct bfd_symbol **);
  459. .
  460. . bool (*_bfd_relax_section) (bfd *, struct bfd_section *,
  461. . struct bfd_link_info *, bool *);
  462. .
  463. . {* Create a hash table for the linker. Different backends store
  464. . different information in this table. *}
  465. . struct bfd_link_hash_table *
  466. . (*_bfd_link_hash_table_create) (bfd *);
  467. .
  468. . {* Add symbols from this object file into the hash table. *}
  469. . bool (*_bfd_link_add_symbols) (bfd *, struct bfd_link_info *);
  470. .
  471. . {* Indicate that we are only retrieving symbol values from this section. *}
  472. . void (*_bfd_link_just_syms) (asection *, struct bfd_link_info *);
  473. .
  474. . {* Copy the symbol type and other attributes for a linker script
  475. . assignment of one symbol to another. *}
  476. .#define bfd_copy_link_hash_symbol_type(b, t, f) \
  477. . BFD_SEND (b, _bfd_copy_link_hash_symbol_type, (b, t, f))
  478. . void (*_bfd_copy_link_hash_symbol_type) (bfd *,
  479. . struct bfd_link_hash_entry *,
  480. . struct bfd_link_hash_entry *);
  481. .
  482. . {* Do a link based on the link_order structures attached to each
  483. . section of the BFD. *}
  484. . bool (*_bfd_final_link) (bfd *, struct bfd_link_info *);
  485. .
  486. . {* Should this section be split up into smaller pieces during linking. *}
  487. . bool (*_bfd_link_split_section) (bfd *, struct bfd_section *);
  488. .
  489. . {* Check the relocations in the bfd for validity. *}
  490. . bool (* _bfd_link_check_relocs)(bfd *, struct bfd_link_info *);
  491. .
  492. . {* Remove sections that are not referenced from the output. *}
  493. . bool (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
  494. .
  495. . {* Sets the bitmask of allowed and disallowed section flags. *}
  496. . bool (*_bfd_lookup_section_flags) (struct bfd_link_info *,
  497. . struct flag_info *, asection *);
  498. .
  499. . {* Attempt to merge SEC_MERGE sections. *}
  500. . bool (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
  501. .
  502. . {* Is this section a member of a group? *}
  503. . bool (*_bfd_is_group_section) (bfd *, const struct bfd_section *);
  504. .
  505. . {* The group name, if section is a member of a group. *}
  506. . const char *(*_bfd_group_name) (bfd *, const struct bfd_section *);
  507. .
  508. . {* Discard members of a group. *}
  509. . bool (*_bfd_discard_group) (bfd *, struct bfd_section *);
  510. .
  511. . {* Check if SEC has been already linked during a reloceatable or
  512. . final link. *}
  513. . bool (*_section_already_linked) (bfd *, asection *,
  514. . struct bfd_link_info *);
  515. .
  516. . {* Define a common symbol. *}
  517. . bool (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
  518. . struct bfd_link_hash_entry *);
  519. .
  520. . {* Hide a symbol. *}
  521. . void (*_bfd_link_hide_symbol) (bfd *, struct bfd_link_info *,
  522. . struct bfd_link_hash_entry *);
  523. .
  524. . {* Define a __start, __stop, .startof. or .sizeof. symbol. *}
  525. . struct bfd_link_hash_entry *
  526. . (*_bfd_define_start_stop) (struct bfd_link_info *, const char *,
  527. . asection *);
  528. .
  529. . {* Routines to handle dynamic symbols and relocs. *}
  530. .#define BFD_JUMP_TABLE_DYNAMIC(NAME) \
  531. . NAME##_get_dynamic_symtab_upper_bound, \
  532. . NAME##_canonicalize_dynamic_symtab, \
  533. . NAME##_get_synthetic_symtab, \
  534. . NAME##_get_dynamic_reloc_upper_bound, \
  535. . NAME##_canonicalize_dynamic_reloc
  536. .
  537. . {* Get the amount of memory required to hold the dynamic symbols. *}
  538. . long (*_bfd_get_dynamic_symtab_upper_bound) (bfd *);
  539. . {* Read in the dynamic symbols. *}
  540. . long (*_bfd_canonicalize_dynamic_symtab) (bfd *, struct bfd_symbol **);
  541. . {* Create synthetized symbols. *}
  542. . long (*_bfd_get_synthetic_symtab) (bfd *, long, struct bfd_symbol **,
  543. . long, struct bfd_symbol **,
  544. . struct bfd_symbol **);
  545. . {* Get the amount of memory required to hold the dynamic relocs. *}
  546. . long (*_bfd_get_dynamic_reloc_upper_bound) (bfd *);
  547. . {* Read in the dynamic relocs. *}
  548. . long (*_bfd_canonicalize_dynamic_reloc) (bfd *, arelent **,
  549. . struct bfd_symbol **);
  550. .
  551. A pointer to an alternative bfd_target in case the current one is not
  552. satisfactory. This can happen when the target cpu supports both big
  553. and little endian code, and target chosen by the linker has the wrong
  554. endianness. The function open_output() in ld/ldlang.c uses this field
  555. to find an alternative output format that is suitable.
  556. . {* Opposite endian version of this target. *}
  557. . const struct bfd_target *alternative_target;
  558. .
  559. . {* Data for use by back-end routines, which isn't
  560. . generic enough to belong in this structure. *}
  561. . const void *backend_data;
  562. .
  563. .} bfd_target;
  564. .
  565. .static inline const char *
  566. .bfd_get_target (const bfd *abfd)
  567. .{
  568. . return abfd->xvec->name;
  569. .}
  570. .
  571. .static inline enum bfd_flavour
  572. .bfd_get_flavour (const bfd *abfd)
  573. .{
  574. . return abfd->xvec->flavour;
  575. .}
  576. .
  577. .static inline flagword
  578. .bfd_applicable_file_flags (const bfd *abfd)
  579. .{
  580. . return abfd->xvec->object_flags;
  581. .}
  582. .
  583. .static inline bool
  584. .bfd_family_coff (const bfd *abfd)
  585. .{
  586. . return (bfd_get_flavour (abfd) == bfd_target_coff_flavour
  587. . || bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
  588. .}
  589. .
  590. .static inline bool
  591. .bfd_big_endian (const bfd *abfd)
  592. .{
  593. . return abfd->xvec->byteorder == BFD_ENDIAN_BIG;
  594. .}
  595. .static inline bool
  596. .bfd_little_endian (const bfd *abfd)
  597. .{
  598. . return abfd->xvec->byteorder == BFD_ENDIAN_LITTLE;
  599. .}
  600. .
  601. .static inline bool
  602. .bfd_header_big_endian (const bfd *abfd)
  603. .{
  604. . return abfd->xvec->header_byteorder == BFD_ENDIAN_BIG;
  605. .}
  606. .
  607. .static inline bool
  608. .bfd_header_little_endian (const bfd *abfd)
  609. .{
  610. . return abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE;
  611. .}
  612. .
  613. .static inline flagword
  614. .bfd_applicable_section_flags (const bfd *abfd)
  615. .{
  616. . return abfd->xvec->section_flags;
  617. .}
  618. .
  619. .static inline char
  620. .bfd_get_symbol_leading_char (const bfd *abfd)
  621. .{
  622. . return abfd->xvec->symbol_leading_char;
  623. .}
  624. .
  625. .static inline enum bfd_flavour
  626. .bfd_asymbol_flavour (const asymbol *sy)
  627. .{
  628. . if ((sy->flags & BSF_SYNTHETIC) != 0)
  629. . return bfd_target_unknown_flavour;
  630. . return sy->the_bfd->xvec->flavour;
  631. .}
  632. .
  633. .static inline bool
  634. .bfd_keep_unused_section_symbols (const bfd *abfd)
  635. .{
  636. . return abfd->xvec->keep_unused_section_symbols;
  637. .}
  638. .
  639. */
  640. /* All known xvecs (even those that don't compile on all systems).
  641. Alphabetized for easy reference.
  642. They are listed a second time below, since
  643. we can't intermix extern's and initializers. */
  644. extern const bfd_target aarch64_elf32_be_vec;
  645. extern const bfd_target aarch64_elf32_le_vec;
  646. extern const bfd_target aarch64_elf64_be_vec;
  647. extern const bfd_target aarch64_elf64_be_cloudabi_vec;
  648. extern const bfd_target aarch64_elf64_le_vec;
  649. extern const bfd_target aarch64_elf64_le_cloudabi_vec;
  650. extern const bfd_target aarch64_mach_o_vec;
  651. extern const bfd_target aarch64_pei_vec;
  652. extern const bfd_target alpha_ecoff_le_vec;
  653. extern const bfd_target alpha_elf64_vec;
  654. extern const bfd_target alpha_elf64_fbsd_vec;
  655. extern const bfd_target alpha_vms_vec;
  656. extern const bfd_target alpha_vms_lib_txt_vec;
  657. extern const bfd_target am33_elf32_linux_vec;
  658. extern const bfd_target amdgcn_elf64_le_vec;
  659. extern const bfd_target aout_vec;
  660. extern const bfd_target arc_elf32_be_vec;
  661. extern const bfd_target arc_elf32_le_vec;
  662. extern const bfd_target arm_elf32_be_vec;
  663. extern const bfd_target arm_elf32_le_vec;
  664. extern const bfd_target arm_elf32_fdpic_be_vec;
  665. extern const bfd_target arm_elf32_fdpic_le_vec;
  666. extern const bfd_target arm_elf32_nacl_be_vec;
  667. extern const bfd_target arm_elf32_nacl_le_vec;
  668. extern const bfd_target arm_elf32_vxworks_be_vec;
  669. extern const bfd_target arm_elf32_vxworks_le_vec;
  670. extern const bfd_target arm_mach_o_vec;
  671. extern const bfd_target arm_pe_be_vec;
  672. extern const bfd_target arm_pe_le_vec;
  673. extern const bfd_target arm_pe_wince_be_vec;
  674. extern const bfd_target arm_pe_wince_le_vec;
  675. extern const bfd_target arm_pei_be_vec;
  676. extern const bfd_target arm_pei_le_vec;
  677. extern const bfd_target arm_pei_wince_be_vec;
  678. extern const bfd_target arm_pei_wince_le_vec;
  679. extern const bfd_target avr_elf32_vec;
  680. extern const bfd_target bfin_elf32_vec;
  681. extern const bfd_target bfin_elf32_fdpic_vec;
  682. extern const bfd_target cr16_elf32_vec;
  683. extern const bfd_target cris_aout_vec;
  684. extern const bfd_target cris_elf32_vec;
  685. extern const bfd_target cris_elf32_us_vec;
  686. extern const bfd_target crx_elf32_vec;
  687. extern const bfd_target csky_elf32_be_vec;
  688. extern const bfd_target csky_elf32_le_vec;
  689. extern const bfd_target d10v_elf32_vec;
  690. extern const bfd_target d30v_elf32_vec;
  691. extern const bfd_target dlx_elf32_be_vec;
  692. extern const bfd_target elf32_be_vec;
  693. extern const bfd_target elf32_le_vec;
  694. extern const bfd_target elf64_be_vec;
  695. extern const bfd_target elf64_le_vec;
  696. extern const bfd_target bpf_elf64_le_vec;
  697. extern const bfd_target bpf_elf64_be_vec;
  698. extern const bfd_target epiphany_elf32_vec;
  699. extern const bfd_target fr30_elf32_vec;
  700. extern const bfd_target frv_elf32_vec;
  701. extern const bfd_target frv_elf32_fdpic_vec;
  702. extern const bfd_target h8300_elf32_vec;
  703. extern const bfd_target h8300_elf32_linux_vec;
  704. extern const bfd_target hppa_elf32_vec;
  705. extern const bfd_target hppa_elf32_linux_vec;
  706. extern const bfd_target hppa_elf32_nbsd_vec;
  707. extern const bfd_target hppa_elf64_vec;
  708. extern const bfd_target hppa_elf64_linux_vec;
  709. extern const bfd_target hppa_som_vec;
  710. extern const bfd_target i386_aout_vec;
  711. extern const bfd_target i386_aout_bsd_vec;
  712. extern const bfd_target i386_aout_lynx_vec;
  713. extern const bfd_target i386_coff_vec;
  714. extern const bfd_target i386_coff_go32_vec;
  715. extern const bfd_target i386_coff_go32stubbed_vec;
  716. extern const bfd_target i386_coff_lynx_vec;
  717. extern const bfd_target i386_elf32_vec;
  718. extern const bfd_target i386_elf32_fbsd_vec;
  719. extern const bfd_target i386_elf32_sol2_vec;
  720. extern const bfd_target i386_elf32_vxworks_vec;
  721. extern const bfd_target i386_mach_o_vec;
  722. extern const bfd_target i386_msdos_vec;
  723. extern const bfd_target i386_pe_vec;
  724. extern const bfd_target i386_pe_big_vec;
  725. extern const bfd_target i386_pei_vec;
  726. extern const bfd_target iamcu_elf32_vec;
  727. extern const bfd_target ia64_elf32_be_vec;
  728. extern const bfd_target ia64_elf32_hpux_be_vec;
  729. extern const bfd_target ia64_elf64_be_vec;
  730. extern const bfd_target ia64_elf64_le_vec;
  731. extern const bfd_target ia64_elf64_hpux_be_vec;
  732. extern const bfd_target ia64_elf64_vms_vec;
  733. extern const bfd_target ia64_pei_vec;
  734. extern const bfd_target ip2k_elf32_vec;
  735. extern const bfd_target iq2000_elf32_vec;
  736. extern const bfd_target lm32_elf32_vec;
  737. extern const bfd_target lm32_elf32_fdpic_vec;
  738. extern const bfd_target loongarch_elf64_vec;
  739. extern const bfd_target loongarch_elf32_vec;
  740. extern const bfd_target m32c_elf32_vec;
  741. extern const bfd_target m32r_elf32_vec;
  742. extern const bfd_target m32r_elf32_le_vec;
  743. extern const bfd_target m32r_elf32_linux_vec;
  744. extern const bfd_target m32r_elf32_linux_le_vec;
  745. extern const bfd_target m68hc11_elf32_vec;
  746. extern const bfd_target m68hc12_elf32_vec;
  747. extern const bfd_target m68k_elf32_vec;
  748. extern const bfd_target s12z_elf32_vec;
  749. extern const bfd_target mach_o_be_vec;
  750. extern const bfd_target mach_o_le_vec;
  751. extern const bfd_target mach_o_fat_vec;
  752. extern const bfd_target mcore_elf32_be_vec;
  753. extern const bfd_target mcore_elf32_le_vec;
  754. extern const bfd_target mcore_pe_be_vec;
  755. extern const bfd_target mcore_pe_le_vec;
  756. extern const bfd_target mcore_pei_be_vec;
  757. extern const bfd_target mcore_pei_le_vec;
  758. extern const bfd_target mep_elf32_vec;
  759. extern const bfd_target mep_elf32_le_vec;
  760. extern const bfd_target metag_elf32_vec;
  761. extern const bfd_target microblaze_elf32_vec;
  762. extern const bfd_target microblaze_elf32_le_vec;
  763. extern const bfd_target mips_ecoff_be_vec;
  764. extern const bfd_target mips_ecoff_le_vec;
  765. extern const bfd_target mips_ecoff_bele_vec;
  766. extern const bfd_target mips_elf32_be_vec;
  767. extern const bfd_target mips_elf32_le_vec;
  768. extern const bfd_target mips_elf32_n_be_vec;
  769. extern const bfd_target mips_elf32_n_le_vec;
  770. extern const bfd_target mips_elf32_ntrad_be_vec;
  771. extern const bfd_target mips_elf32_ntrad_le_vec;
  772. extern const bfd_target mips_elf32_ntradfbsd_be_vec;
  773. extern const bfd_target mips_elf32_ntradfbsd_le_vec;
  774. extern const bfd_target mips_elf32_trad_be_vec;
  775. extern const bfd_target mips_elf32_trad_le_vec;
  776. extern const bfd_target mips_elf32_tradfbsd_be_vec;
  777. extern const bfd_target mips_elf32_tradfbsd_le_vec;
  778. extern const bfd_target mips_elf32_vxworks_be_vec;
  779. extern const bfd_target mips_elf32_vxworks_le_vec;
  780. extern const bfd_target mips_elf64_be_vec;
  781. extern const bfd_target mips_elf64_le_vec;
  782. extern const bfd_target mips_elf64_trad_be_vec;
  783. extern const bfd_target mips_elf64_trad_le_vec;
  784. extern const bfd_target mips_elf64_tradfbsd_be_vec;
  785. extern const bfd_target mips_elf64_tradfbsd_le_vec;
  786. extern const bfd_target mmix_elf64_vec;
  787. extern const bfd_target mmix_mmo_vec;
  788. extern const bfd_target mn10200_elf32_vec;
  789. extern const bfd_target mn10300_elf32_vec;
  790. extern const bfd_target moxie_elf32_be_vec;
  791. extern const bfd_target moxie_elf32_le_vec;
  792. extern const bfd_target msp430_elf32_vec;
  793. extern const bfd_target msp430_elf32_ti_vec;
  794. extern const bfd_target mt_elf32_vec;
  795. extern const bfd_target nds32_elf32_be_vec;
  796. extern const bfd_target nds32_elf32_le_vec;
  797. extern const bfd_target nds32_elf32_linux_be_vec;
  798. extern const bfd_target nds32_elf32_linux_le_vec;
  799. extern const bfd_target nfp_elf64_vec;
  800. extern const bfd_target nios2_elf32_be_vec;
  801. extern const bfd_target nios2_elf32_le_vec;
  802. extern const bfd_target ns32k_aout_pc532mach_vec;
  803. extern const bfd_target ns32k_aout_pc532nbsd_vec;
  804. extern const bfd_target or1k_elf32_vec;
  805. extern const bfd_target pdp11_aout_vec;
  806. extern const bfd_target pef_vec;
  807. extern const bfd_target pef_xlib_vec;
  808. extern const bfd_target pj_elf32_vec;
  809. extern const bfd_target pj_elf32_le_vec;
  810. extern const bfd_target plugin_vec;
  811. extern const bfd_target powerpc_boot_vec;
  812. extern const bfd_target powerpc_elf32_vec;
  813. extern const bfd_target powerpc_elf32_le_vec;
  814. extern const bfd_target powerpc_elf32_fbsd_vec;
  815. extern const bfd_target powerpc_elf32_vxworks_vec;
  816. extern const bfd_target powerpc_elf64_vec;
  817. extern const bfd_target powerpc_elf64_le_vec;
  818. extern const bfd_target powerpc_elf64_fbsd_vec;
  819. extern const bfd_target powerpc_elf64_fbsd_le_vec;
  820. extern const bfd_target powerpc_xcoff_vec;
  821. extern const bfd_target pru_elf32_vec;
  822. extern const bfd_target riscv_elf32_vec;
  823. extern const bfd_target riscv_elf64_vec;
  824. extern const bfd_target riscv_elf32_be_vec;
  825. extern const bfd_target riscv_elf64_be_vec;
  826. extern const bfd_target rl78_elf32_vec;
  827. extern const bfd_target rs6000_xcoff64_vec;
  828. extern const bfd_target rs6000_xcoff64_aix_vec;
  829. extern const bfd_target rs6000_xcoff_vec;
  830. extern const bfd_target rx_elf32_be_vec;
  831. extern const bfd_target rx_elf32_be_ns_vec;
  832. extern const bfd_target rx_elf32_le_vec;
  833. extern const bfd_target rx_elf32_linux_le_vec;
  834. extern const bfd_target s390_elf32_vec;
  835. extern const bfd_target s390_elf64_vec;
  836. extern const bfd_target score_elf32_be_vec;
  837. extern const bfd_target score_elf32_le_vec;
  838. extern const bfd_target sh_coff_vec;
  839. extern const bfd_target sh_coff_le_vec;
  840. extern const bfd_target sh_coff_small_vec;
  841. extern const bfd_target sh_coff_small_le_vec;
  842. extern const bfd_target sh_elf32_vec;
  843. extern const bfd_target sh_elf32_le_vec;
  844. extern const bfd_target sh_elf32_fdpic_be_vec;
  845. extern const bfd_target sh_elf32_fdpic_le_vec;
  846. extern const bfd_target sh_elf32_linux_vec;
  847. extern const bfd_target sh_elf32_linux_be_vec;
  848. extern const bfd_target sh_elf32_nbsd_vec;
  849. extern const bfd_target sh_elf32_nbsd_le_vec;
  850. extern const bfd_target sh_elf32_vxworks_vec;
  851. extern const bfd_target sh_elf32_vxworks_le_vec;
  852. extern const bfd_target sh_pe_le_vec;
  853. extern const bfd_target sh_pei_le_vec;
  854. extern const bfd_target sparc_elf32_vec;
  855. extern const bfd_target sparc_elf32_sol2_vec;
  856. extern const bfd_target sparc_elf32_vxworks_vec;
  857. extern const bfd_target sparc_elf64_vec;
  858. extern const bfd_target sparc_elf64_fbsd_vec;
  859. extern const bfd_target sparc_elf64_sol2_vec;
  860. extern const bfd_target spu_elf32_vec;
  861. extern const bfd_target sym_vec;
  862. extern const bfd_target tic30_coff_vec;
  863. extern const bfd_target tic4x_coff0_vec;
  864. extern const bfd_target tic4x_coff0_beh_vec;
  865. extern const bfd_target tic4x_coff1_vec;
  866. extern const bfd_target tic4x_coff1_beh_vec;
  867. extern const bfd_target tic4x_coff2_vec;
  868. extern const bfd_target tic4x_coff2_beh_vec;
  869. extern const bfd_target tic54x_coff0_vec;
  870. extern const bfd_target tic54x_coff0_beh_vec;
  871. extern const bfd_target tic54x_coff1_vec;
  872. extern const bfd_target tic54x_coff1_beh_vec;
  873. extern const bfd_target tic54x_coff2_vec;
  874. extern const bfd_target tic54x_coff2_beh_vec;
  875. extern const bfd_target tic6x_elf32_be_vec;
  876. extern const bfd_target tic6x_elf32_le_vec;
  877. extern const bfd_target tic6x_elf32_c6000_be_vec;
  878. extern const bfd_target tic6x_elf32_c6000_le_vec;
  879. extern const bfd_target tic6x_elf32_linux_be_vec;
  880. extern const bfd_target tic6x_elf32_linux_le_vec;
  881. extern const bfd_target tilegx_elf32_be_vec;
  882. extern const bfd_target tilegx_elf32_le_vec;
  883. extern const bfd_target tilegx_elf64_be_vec;
  884. extern const bfd_target tilegx_elf64_le_vec;
  885. extern const bfd_target tilepro_elf32_vec;
  886. extern const bfd_target v800_elf32_vec;
  887. extern const bfd_target v850_elf32_vec;
  888. extern const bfd_target ft32_elf32_vec;
  889. extern const bfd_target vax_aout_1knbsd_vec;
  890. extern const bfd_target vax_aout_nbsd_vec;
  891. extern const bfd_target vax_elf32_vec;
  892. extern const bfd_target visium_elf32_vec;
  893. extern const bfd_target wasm_vec;
  894. extern const bfd_target wasm32_elf32_vec;
  895. extern const bfd_target x86_64_coff_vec;
  896. extern const bfd_target x86_64_elf32_vec;
  897. extern const bfd_target x86_64_elf64_vec;
  898. extern const bfd_target x86_64_elf64_cloudabi_vec;
  899. extern const bfd_target x86_64_elf64_fbsd_vec;
  900. extern const bfd_target x86_64_elf64_sol2_vec;
  901. extern const bfd_target x86_64_mach_o_vec;
  902. extern const bfd_target x86_64_pe_vec;
  903. extern const bfd_target x86_64_pe_big_vec;
  904. extern const bfd_target x86_64_pei_vec;
  905. extern const bfd_target xc16x_elf32_vec;
  906. extern const bfd_target xgate_elf32_vec;
  907. extern const bfd_target xstormy16_elf32_vec;
  908. extern const bfd_target xtensa_elf32_be_vec;
  909. extern const bfd_target xtensa_elf32_le_vec;
  910. extern const bfd_target z80_coff_vec;
  911. extern const bfd_target z80_elf32_vec;
  912. extern const bfd_target z8k_coff_vec;
  913. /* These are always included. */
  914. extern const bfd_target srec_vec;
  915. extern const bfd_target symbolsrec_vec;
  916. extern const bfd_target verilog_vec;
  917. extern const bfd_target tekhex_vec;
  918. extern const bfd_target binary_vec;
  919. extern const bfd_target ihex_vec;
  920. /* All of the xvecs for core files. */
  921. extern const bfd_target core_aix386_vec;
  922. extern const bfd_target core_cisco_be_vec;
  923. extern const bfd_target core_cisco_le_vec;
  924. extern const bfd_target core_hppabsd_vec;
  925. extern const bfd_target core_hpux_vec;
  926. extern const bfd_target core_irix_vec;
  927. extern const bfd_target core_netbsd_vec;
  928. extern const bfd_target core_osf_vec;
  929. extern const bfd_target core_ptrace_vec;
  930. extern const bfd_target core_sco5_vec;
  931. extern const bfd_target core_trad_vec;
  932. static const bfd_target * const _bfd_target_vector[] =
  933. {
  934. #ifdef SELECT_VECS
  935. SELECT_VECS,
  936. #else /* not SELECT_VECS */
  937. #ifdef DEFAULT_VECTOR
  938. &DEFAULT_VECTOR,
  939. #endif
  940. /* This list is alphabetized to make it easy to compare
  941. with other vector lists -- the decls above and
  942. the case statement in configure.ac.
  943. Try to keep it in order when adding new targets, and
  944. use a name of the form <cpu>_<format>_<other>_<endian>_vec.
  945. Note that sorting is done as if _<endian>_vec wasn't present.
  946. Vectors that don't compile on all systems, or aren't finished,
  947. should have an entry here with #if 0 around it, to show that
  948. it wasn't omitted by mistake. */
  949. #ifdef BFD64
  950. &aarch64_elf32_be_vec,
  951. &aarch64_elf32_le_vec,
  952. &aarch64_elf64_be_vec,
  953. &aarch64_elf64_be_cloudabi_vec,
  954. &aarch64_elf64_le_vec,
  955. &aarch64_elf64_le_cloudabi_vec,
  956. &aarch64_mach_o_vec,
  957. &aarch64_pei_vec,
  958. #endif
  959. #ifdef BFD64
  960. &amdgcn_elf64_le_vec,
  961. #endif
  962. #ifdef BFD64
  963. &alpha_ecoff_le_vec,
  964. &alpha_elf64_vec,
  965. &alpha_elf64_fbsd_vec,
  966. &alpha_vms_vec,
  967. #endif
  968. &alpha_vms_lib_txt_vec,
  969. &am33_elf32_linux_vec,
  970. #if 0
  971. /* Since a.out files lack decent magic numbers, no way to recognize
  972. which kind of a.out file it is. */
  973. &aout_vec,
  974. #endif
  975. &arc_elf32_be_vec,
  976. &arc_elf32_le_vec,
  977. &arm_elf32_be_vec,
  978. &arm_elf32_le_vec,
  979. &arm_elf32_fdpic_be_vec,
  980. &arm_elf32_fdpic_le_vec,
  981. &arm_elf32_vxworks_be_vec,
  982. &arm_elf32_vxworks_le_vec,
  983. &arm_mach_o_vec,
  984. &arm_pe_be_vec,
  985. &arm_pe_le_vec,
  986. &arm_pe_wince_be_vec,
  987. &arm_pe_wince_le_vec,
  988. &arm_pei_be_vec,
  989. &arm_pei_le_vec,
  990. &arm_pei_wince_be_vec,
  991. &arm_pei_wince_le_vec,
  992. &avr_elf32_vec,
  993. &bfin_elf32_vec,
  994. &bfin_elf32_fdpic_vec,
  995. &cr16_elf32_vec,
  996. &cris_aout_vec,
  997. &cris_elf32_vec,
  998. &cris_elf32_us_vec,
  999. &crx_elf32_vec,
  1000. &csky_elf32_be_vec,
  1001. &csky_elf32_le_vec,
  1002. &d10v_elf32_vec,
  1003. &d30v_elf32_vec,
  1004. &dlx_elf32_be_vec,
  1005. /* This, and other vectors, may not be used in any *.mt configuration.
  1006. But that does not mean they are unnecessary. If configured with
  1007. --enable-targets=all, objdump or gdb should be able to examine
  1008. the file even if we don't recognize the machine type. */
  1009. &elf32_be_vec,
  1010. &elf32_le_vec,
  1011. #ifdef BFD64
  1012. &elf64_be_vec,
  1013. &elf64_le_vec,
  1014. #endif
  1015. &epiphany_elf32_vec,
  1016. &fr30_elf32_vec,
  1017. &frv_elf32_vec,
  1018. &frv_elf32_fdpic_vec,
  1019. &h8300_elf32_vec,
  1020. &h8300_elf32_linux_vec,
  1021. &hppa_elf32_vec,
  1022. &hppa_elf32_linux_vec,
  1023. &hppa_elf32_nbsd_vec,
  1024. #ifdef BFD64
  1025. &hppa_elf64_vec,
  1026. &hppa_elf64_linux_vec,
  1027. #endif
  1028. &hppa_som_vec,
  1029. &i386_aout_vec,
  1030. &i386_aout_bsd_vec,
  1031. &i386_aout_lynx_vec,
  1032. &i386_coff_vec,
  1033. &i386_coff_go32_vec,
  1034. &i386_coff_go32stubbed_vec,
  1035. &i386_coff_lynx_vec,
  1036. &i386_elf32_vec,
  1037. &i386_elf32_fbsd_vec,
  1038. &i386_elf32_sol2_vec,
  1039. &i386_elf32_vxworks_vec,
  1040. &i386_mach_o_vec,
  1041. &i386_msdos_vec,
  1042. &i386_pe_vec,
  1043. &i386_pe_big_vec,
  1044. &i386_pei_vec,
  1045. &iamcu_elf32_vec,
  1046. #ifdef BFD64
  1047. &bpf_elf64_be_vec,
  1048. &bpf_elf64_le_vec,
  1049. #endif
  1050. #ifdef BFD64
  1051. #if 0
  1052. &ia64_elf32_be_vec,
  1053. #endif
  1054. &ia64_elf32_hpux_be_vec,
  1055. &ia64_elf64_be_vec,
  1056. &ia64_elf64_le_vec,
  1057. &ia64_elf64_hpux_be_vec,
  1058. &ia64_elf64_vms_vec,
  1059. &ia64_pei_vec,
  1060. #endif
  1061. &ip2k_elf32_vec,
  1062. &iq2000_elf32_vec,
  1063. &lm32_elf32_vec,
  1064. &m32c_elf32_vec,
  1065. &m32r_elf32_vec,
  1066. &m32r_elf32_le_vec,
  1067. &m32r_elf32_linux_vec,
  1068. &m32r_elf32_linux_le_vec,
  1069. &m68hc11_elf32_vec,
  1070. &m68hc12_elf32_vec,
  1071. &m68k_elf32_vec,
  1072. &s12z_elf32_vec,
  1073. &mach_o_be_vec,
  1074. &mach_o_le_vec,
  1075. &mach_o_fat_vec,
  1076. &mcore_elf32_be_vec,
  1077. &mcore_elf32_le_vec,
  1078. &mcore_pe_be_vec,
  1079. &mcore_pe_le_vec,
  1080. &mcore_pei_be_vec,
  1081. &mcore_pei_le_vec,
  1082. &mep_elf32_vec,
  1083. &metag_elf32_vec,
  1084. &microblaze_elf32_vec,
  1085. &mips_ecoff_be_vec,
  1086. &mips_ecoff_le_vec,
  1087. &mips_ecoff_bele_vec,
  1088. #ifdef BFD64
  1089. &mips_elf32_be_vec,
  1090. &mips_elf32_le_vec,
  1091. &mips_elf32_n_be_vec,
  1092. &mips_elf32_n_le_vec,
  1093. &mips_elf32_ntrad_be_vec,
  1094. &mips_elf32_ntrad_le_vec,
  1095. &mips_elf32_ntradfbsd_be_vec,
  1096. &mips_elf32_ntradfbsd_le_vec,
  1097. &mips_elf32_trad_be_vec,
  1098. &mips_elf32_trad_le_vec,
  1099. &mips_elf32_tradfbsd_be_vec,
  1100. &mips_elf32_tradfbsd_le_vec,
  1101. &mips_elf32_vxworks_be_vec,
  1102. &mips_elf32_vxworks_le_vec,
  1103. &mips_elf64_be_vec,
  1104. &mips_elf64_le_vec,
  1105. &mips_elf64_trad_be_vec,
  1106. &mips_elf64_trad_le_vec,
  1107. &mips_elf64_tradfbsd_be_vec,
  1108. &mips_elf64_tradfbsd_le_vec,
  1109. #endif
  1110. #ifdef BFD64
  1111. &mmix_elf64_vec,
  1112. &mmix_mmo_vec,
  1113. #endif
  1114. &mn10200_elf32_vec,
  1115. &mn10300_elf32_vec,
  1116. &moxie_elf32_be_vec,
  1117. &moxie_elf32_le_vec,
  1118. &msp430_elf32_vec,
  1119. &msp430_elf32_ti_vec,
  1120. &mt_elf32_vec,
  1121. &nds32_elf32_be_vec,
  1122. &nds32_elf32_le_vec,
  1123. &nds32_elf32_linux_be_vec,
  1124. &nds32_elf32_linux_le_vec,
  1125. #ifdef BFD64
  1126. &nfp_elf64_vec,
  1127. #endif
  1128. &nios2_elf32_be_vec,
  1129. &nios2_elf32_le_vec,
  1130. &ns32k_aout_pc532mach_vec,
  1131. &ns32k_aout_pc532nbsd_vec,
  1132. &or1k_elf32_vec,
  1133. &pdp11_aout_vec,
  1134. &pef_vec,
  1135. &pef_xlib_vec,
  1136. &pj_elf32_vec,
  1137. &pj_elf32_le_vec,
  1138. &powerpc_boot_vec,
  1139. &powerpc_elf32_vec,
  1140. &powerpc_elf32_le_vec,
  1141. &powerpc_elf32_fbsd_vec,
  1142. &powerpc_elf32_vxworks_vec,
  1143. #ifdef BFD64
  1144. &powerpc_elf64_vec,
  1145. &powerpc_elf64_le_vec,
  1146. &powerpc_elf64_fbsd_vec,
  1147. &powerpc_elf64_fbsd_le_vec,
  1148. #endif
  1149. #if 0
  1150. /* This has the same magic number as RS/6000. */
  1151. &powerpc_xcoff_vec,
  1152. #endif
  1153. &pru_elf32_vec,
  1154. #ifdef BFD64
  1155. &riscv_elf32_vec,
  1156. &riscv_elf64_vec,
  1157. &riscv_elf32_be_vec,
  1158. &riscv_elf64_be_vec,
  1159. #endif
  1160. &rl78_elf32_vec,
  1161. #ifdef BFD64
  1162. &rs6000_xcoff64_vec,
  1163. &rs6000_xcoff64_aix_vec,
  1164. #endif
  1165. &rs6000_xcoff_vec,
  1166. &rx_elf32_be_vec,
  1167. &rx_elf32_be_ns_vec,
  1168. &rx_elf32_le_vec,
  1169. &s390_elf32_vec,
  1170. #ifdef BFD64
  1171. &s390_elf64_vec,
  1172. #endif
  1173. #ifdef BFD64
  1174. &score_elf32_be_vec,
  1175. &score_elf32_le_vec,
  1176. #endif
  1177. &sh_coff_vec,
  1178. &sh_coff_le_vec,
  1179. &sh_coff_small_vec,
  1180. &sh_coff_small_le_vec,
  1181. &sh_elf32_vec,
  1182. &sh_elf32_le_vec,
  1183. &sh_elf32_fdpic_be_vec,
  1184. &sh_elf32_fdpic_le_vec,
  1185. &sh_elf32_linux_vec,
  1186. &sh_elf32_linux_be_vec,
  1187. &sh_elf32_nbsd_vec,
  1188. &sh_elf32_nbsd_le_vec,
  1189. &sh_elf32_vxworks_vec,
  1190. &sh_elf32_vxworks_le_vec,
  1191. &sh_pe_le_vec,
  1192. &sh_pei_le_vec,
  1193. &sparc_elf32_vec,
  1194. &sparc_elf32_sol2_vec,
  1195. &sparc_elf32_vxworks_vec,
  1196. #ifdef BFD64
  1197. &sparc_elf64_vec,
  1198. &sparc_elf64_fbsd_vec,
  1199. &sparc_elf64_sol2_vec,
  1200. #endif
  1201. &spu_elf32_vec,
  1202. &sym_vec,
  1203. &tic30_coff_vec,
  1204. &tic54x_coff0_beh_vec,
  1205. &tic54x_coff0_vec,
  1206. &tic54x_coff1_beh_vec,
  1207. &tic54x_coff1_vec,
  1208. &tic54x_coff2_beh_vec,
  1209. &tic54x_coff2_vec,
  1210. &tic6x_elf32_be_vec,
  1211. &tic6x_elf32_le_vec,
  1212. &tilegx_elf32_be_vec,
  1213. &tilegx_elf32_le_vec,
  1214. #ifdef BFD64
  1215. &tilegx_elf64_be_vec,
  1216. &tilegx_elf64_le_vec,
  1217. #endif
  1218. &tilepro_elf32_vec,
  1219. &ft32_elf32_vec,
  1220. &v800_elf32_vec,
  1221. &v850_elf32_vec,
  1222. &vax_aout_1knbsd_vec,
  1223. &vax_aout_nbsd_vec,
  1224. &vax_elf32_vec,
  1225. &visium_elf32_vec,
  1226. &wasm_vec,
  1227. &wasm32_elf32_vec,
  1228. #ifdef BFD64
  1229. &x86_64_coff_vec,
  1230. &x86_64_elf32_vec,
  1231. &x86_64_elf64_vec,
  1232. &x86_64_elf64_cloudabi_vec,
  1233. &x86_64_elf64_fbsd_vec,
  1234. &x86_64_elf64_sol2_vec,
  1235. &x86_64_mach_o_vec,
  1236. &x86_64_pe_vec,
  1237. &x86_64_pe_big_vec,
  1238. &x86_64_pei_vec,
  1239. #endif
  1240. &xc16x_elf32_vec,
  1241. &xgate_elf32_vec,
  1242. &xstormy16_elf32_vec,
  1243. &xtensa_elf32_be_vec,
  1244. &xtensa_elf32_le_vec,
  1245. &z80_coff_vec,
  1246. &z80_elf32_vec,
  1247. &z8k_coff_vec,
  1248. #ifdef BFD64
  1249. &loongarch_elf32_vec,
  1250. &loongarch_elf64_vec,
  1251. #endif
  1252. #endif /* not SELECT_VECS */
  1253. /* Always support S-records, for convenience. */
  1254. &srec_vec,
  1255. &symbolsrec_vec,
  1256. /* And verilog. */
  1257. &verilog_vec,
  1258. /* And tekhex */
  1259. &tekhex_vec,
  1260. /* Likewise for binary output. */
  1261. &binary_vec,
  1262. /* Likewise for ihex. */
  1263. &ihex_vec,
  1264. #if BFD_SUPPORTS_PLUGINS
  1265. &plugin_vec,
  1266. #endif
  1267. /* Add any required traditional-core-file-handler. */
  1268. #ifdef AIX386_CORE
  1269. &core_aix386_vec,
  1270. #endif
  1271. #if 0
  1272. /* We don't include cisco_core_*_vec. Although it has a magic number,
  1273. the magic number isn't at the beginning of the file, and thus
  1274. might spuriously match other kinds of files. */
  1275. &core_cisco_be_vec,
  1276. &core_cisco_le_vec,
  1277. #endif
  1278. #ifdef HPPABSD_CORE
  1279. &core_hppabsd_vec,
  1280. #endif
  1281. #ifdef HPUX_CORE
  1282. &core_hpux_vec,
  1283. #endif
  1284. #ifdef IRIX_CORE
  1285. &core_irix_vec,
  1286. #endif
  1287. #ifdef NETBSD_CORE
  1288. &core_netbsd_vec,
  1289. #endif
  1290. #ifdef OSF_CORE
  1291. &core_osf_vec,
  1292. #endif
  1293. #ifdef PTRACE_CORE
  1294. &core_ptrace_vec,
  1295. #endif
  1296. #ifdef SCO5_CORE
  1297. &core_sco5_vec,
  1298. #endif
  1299. #ifdef TRAD_CORE
  1300. &core_trad_vec,
  1301. #endif
  1302. NULL /* end of list marker */
  1303. };
  1304. const bfd_target *const *const bfd_target_vector = _bfd_target_vector;
  1305. /* bfd_default_vector[0] contains either the address of the default vector,
  1306. if there is one, or zero if there isn't. */
  1307. const bfd_target *bfd_default_vector[] = {
  1308. #ifdef DEFAULT_VECTOR
  1309. &DEFAULT_VECTOR,
  1310. #endif
  1311. NULL
  1312. };
  1313. /* bfd_associated_vector[] contains the associated target vectors used
  1314. to reduce the ambiguity in bfd_check_format_matches. */
  1315. static const bfd_target *const _bfd_associated_vector[] = {
  1316. #ifdef ASSOCIATED_VECS
  1317. ASSOCIATED_VECS,
  1318. #endif
  1319. NULL
  1320. };
  1321. const bfd_target *const *const bfd_associated_vector = _bfd_associated_vector;
  1322. /* When there is an ambiguous match, bfd_check_format_matches puts the
  1323. names of the matching targets in an array. This variable is the maximum
  1324. number of entries that the array could possibly need. */
  1325. const size_t _bfd_target_vector_entries = sizeof (_bfd_target_vector)/sizeof (*_bfd_target_vector);
  1326. /* This array maps configuration triplets onto BFD vectors. */
  1327. struct targmatch
  1328. {
  1329. /* The configuration triplet. */
  1330. const char *triplet;
  1331. /* The BFD vector. If this is NULL, then the vector is found by
  1332. searching forward for the next structure with a non NULL vector
  1333. field. */
  1334. const bfd_target *vector;
  1335. };
  1336. /* targmatch.h is built by Makefile out of config.bfd. */
  1337. static const struct targmatch bfd_target_match[] = {
  1338. #include "targmatch.h"
  1339. { NULL, NULL }
  1340. };
  1341. /* Find a target vector, given a name or configuration triplet. */
  1342. static const bfd_target *
  1343. find_target (const char *name)
  1344. {
  1345. const bfd_target * const *target;
  1346. const struct targmatch *match;
  1347. for (target = &bfd_target_vector[0]; *target != NULL; target++)
  1348. if (strcmp (name, (*target)->name) == 0)
  1349. return *target;
  1350. /* If we couldn't match on the exact name, try matching on the
  1351. configuration triplet. FIXME: We should run the triplet through
  1352. config.sub first, but that is hard. */
  1353. for (match = &bfd_target_match[0]; match->triplet != NULL; match++)
  1354. {
  1355. if (fnmatch (match->triplet, name, 0) == 0)
  1356. {
  1357. while (match->vector == NULL)
  1358. ++match;
  1359. return match->vector;
  1360. }
  1361. }
  1362. bfd_set_error (bfd_error_invalid_target);
  1363. return NULL;
  1364. }
  1365. /*
  1366. FUNCTION
  1367. bfd_set_default_target
  1368. SYNOPSIS
  1369. bool bfd_set_default_target (const char *name);
  1370. DESCRIPTION
  1371. Set the default target vector to use when recognizing a BFD.
  1372. This takes the name of the target, which may be a BFD target
  1373. name or a configuration triplet.
  1374. */
  1375. bool
  1376. bfd_set_default_target (const char *name)
  1377. {
  1378. const bfd_target *target;
  1379. if (bfd_default_vector[0] != NULL
  1380. && strcmp (name, bfd_default_vector[0]->name) == 0)
  1381. return true;
  1382. target = find_target (name);
  1383. if (target == NULL)
  1384. return false;
  1385. bfd_default_vector[0] = target;
  1386. return true;
  1387. }
  1388. /*
  1389. FUNCTION
  1390. bfd_find_target
  1391. SYNOPSIS
  1392. const bfd_target *bfd_find_target (const char *target_name, bfd *abfd);
  1393. DESCRIPTION
  1394. Return a pointer to the transfer vector for the object target
  1395. named @var{target_name}. If @var{target_name} is <<NULL>>,
  1396. choose the one in the environment variable <<GNUTARGET>>; if
  1397. that is null or not defined, then choose the first entry in the
  1398. target list. Passing in the string "default" or setting the
  1399. environment variable to "default" will cause the first entry in
  1400. the target list to be returned, and "target_defaulted" will be
  1401. set in the BFD if @var{abfd} isn't <<NULL>>. This causes
  1402. <<bfd_check_format>> to loop over all the targets to find the
  1403. one that matches the file being read.
  1404. */
  1405. const bfd_target *
  1406. bfd_find_target (const char *target_name, bfd *abfd)
  1407. {
  1408. const char *targname;
  1409. const bfd_target *target;
  1410. if (target_name != NULL)
  1411. targname = target_name;
  1412. else
  1413. targname = getenv ("GNUTARGET");
  1414. /* This is safe; the vector cannot be null. */
  1415. if (targname == NULL || strcmp (targname, "default") == 0)
  1416. {
  1417. if (bfd_default_vector[0] != NULL)
  1418. target = bfd_default_vector[0];
  1419. else
  1420. target = bfd_target_vector[0];
  1421. if (abfd)
  1422. {
  1423. abfd->xvec = target;
  1424. abfd->target_defaulted = true;
  1425. }
  1426. return target;
  1427. }
  1428. if (abfd)
  1429. abfd->target_defaulted = false;
  1430. target = find_target (targname);
  1431. if (target == NULL)
  1432. return NULL;
  1433. if (abfd)
  1434. abfd->xvec = target;
  1435. return target;
  1436. }
  1437. /* Helper function for bfd_get_target_info to determine the target's
  1438. architecture. This method handles bfd internal target names as
  1439. tuples and triplets. */
  1440. static bool
  1441. _bfd_find_arch_match (const char *tname, const char **arch,
  1442. const char **def_target_arch)
  1443. {
  1444. if (!arch)
  1445. return false;
  1446. while (*arch != NULL)
  1447. {
  1448. const char *in_a = strstr (*arch, tname);
  1449. char end_ch = (in_a ? in_a[strlen (tname)] : 0);
  1450. if (in_a && (in_a == *arch || in_a[-1] == ':')
  1451. && end_ch == 0)
  1452. {
  1453. *def_target_arch = *arch;
  1454. return true;
  1455. }
  1456. arch++;
  1457. }
  1458. return false;
  1459. }
  1460. /*
  1461. FUNCTION
  1462. bfd_get_target_info
  1463. SYNOPSIS
  1464. const bfd_target *bfd_get_target_info (const char *target_name,
  1465. bfd *abfd,
  1466. bool *is_bigendian,
  1467. int *underscoring,
  1468. const char **def_target_arch);
  1469. DESCRIPTION
  1470. Return a pointer to the transfer vector for the object target
  1471. named @var{target_name}. If @var{target_name} is <<NULL>>,
  1472. choose the one in the environment variable <<GNUTARGET>>; if
  1473. that is null or not defined, then choose the first entry in the
  1474. target list. Passing in the string "default" or setting the
  1475. environment variable to "default" will cause the first entry in
  1476. the target list to be returned, and "target_defaulted" will be
  1477. set in the BFD if @var{abfd} isn't <<NULL>>. This causes
  1478. <<bfd_check_format>> to loop over all the targets to find the
  1479. one that matches the file being read.
  1480. If @var{is_bigendian} is not <<NULL>>, then set this value to target's
  1481. endian mode. True for big-endian, FALSE for little-endian or for
  1482. invalid target.
  1483. If @var{underscoring} is not <<NULL>>, then set this value to target's
  1484. underscoring mode. Zero for none-underscoring, -1 for invalid target,
  1485. else the value of target vector's symbol underscoring.
  1486. If @var{def_target_arch} is not <<NULL>>, then set it to the architecture
  1487. string specified by the target_name.
  1488. */
  1489. const bfd_target *
  1490. bfd_get_target_info (const char *target_name, bfd *abfd,
  1491. bool *is_bigendian,
  1492. int *underscoring, const char **def_target_arch)
  1493. {
  1494. const bfd_target *target_vec;
  1495. if (is_bigendian)
  1496. *is_bigendian = false;
  1497. if (underscoring)
  1498. *underscoring = -1;
  1499. if (def_target_arch)
  1500. *def_target_arch = NULL;
  1501. target_vec = bfd_find_target (target_name, abfd);
  1502. if (! target_vec)
  1503. return NULL;
  1504. if (is_bigendian)
  1505. *is_bigendian = target_vec->byteorder == BFD_ENDIAN_BIG;
  1506. if (underscoring)
  1507. *underscoring = ((int) target_vec->symbol_leading_char) & 0xff;
  1508. if (def_target_arch)
  1509. {
  1510. const char *tname = target_vec->name;
  1511. const char **arches = bfd_arch_list ();
  1512. if (arches && tname)
  1513. {
  1514. char *hyp = strchr (tname, '-');
  1515. if (hyp != NULL)
  1516. {
  1517. tname = ++hyp;
  1518. /* Make sure we detect architecture names
  1519. for triplets like "pe-arm-wince-little". */
  1520. if (!_bfd_find_arch_match (tname, arches, def_target_arch))
  1521. {
  1522. char new_tname[50];
  1523. strcpy (new_tname, hyp);
  1524. while ((hyp = strrchr (new_tname, '-')) != NULL)
  1525. {
  1526. *hyp = 0;
  1527. if (_bfd_find_arch_match (new_tname, arches,
  1528. def_target_arch))
  1529. break;
  1530. }
  1531. }
  1532. }
  1533. else
  1534. _bfd_find_arch_match (tname, arches, def_target_arch);
  1535. }
  1536. free (arches);
  1537. }
  1538. return target_vec;
  1539. }
  1540. /*
  1541. FUNCTION
  1542. bfd_target_list
  1543. SYNOPSIS
  1544. const char ** bfd_target_list (void);
  1545. DESCRIPTION
  1546. Return a freshly malloced NULL-terminated
  1547. vector of the names of all the valid BFD targets. Do not
  1548. modify the names.
  1549. */
  1550. const char **
  1551. bfd_target_list (void)
  1552. {
  1553. int vec_length = 0;
  1554. size_t amt;
  1555. const bfd_target * const *target;
  1556. const char **name_list, **name_ptr;
  1557. for (target = &bfd_target_vector[0]; *target != NULL; target++)
  1558. vec_length++;
  1559. amt = (vec_length + 1) * sizeof (char **);
  1560. name_ptr = name_list = (const char **) bfd_malloc (amt);
  1561. if (name_list == NULL)
  1562. return NULL;
  1563. for (target = &bfd_target_vector[0]; *target != NULL; target++)
  1564. if (target == &bfd_target_vector[0]
  1565. || *target != bfd_target_vector[0])
  1566. *name_ptr++ = (*target)->name;
  1567. *name_ptr = NULL;
  1568. return name_list;
  1569. }
  1570. /*
  1571. FUNCTION
  1572. bfd_iterate_over_targets
  1573. SYNOPSIS
  1574. const bfd_target *bfd_iterate_over_targets
  1575. (int (*func) (const bfd_target *, void *),
  1576. void *data);
  1577. DESCRIPTION
  1578. Call @var{func} for each target in the list of BFD target
  1579. vectors, passing @var{data} to @var{func}. Stop iterating if
  1580. @var{func} returns a non-zero result, and return that target
  1581. vector. Return NULL if @var{func} always returns zero.
  1582. */
  1583. const bfd_target *
  1584. bfd_iterate_over_targets (int (*func) (const bfd_target *, void *),
  1585. void *data)
  1586. {
  1587. const bfd_target *const *target;
  1588. for (target = bfd_target_vector; *target != NULL; ++target)
  1589. if (func (*target, data))
  1590. return *target;
  1591. return NULL;
  1592. }
  1593. /*
  1594. FUNCTION
  1595. bfd_flavour_name
  1596. SYNOPSIS
  1597. const char *bfd_flavour_name (enum bfd_flavour flavour);
  1598. DESCRIPTION
  1599. Return the string form of @var{flavour}.
  1600. */
  1601. const char *
  1602. bfd_flavour_name (enum bfd_flavour flavour)
  1603. {
  1604. switch (flavour)
  1605. {
  1606. case bfd_target_unknown_flavour: return "unknown file format";
  1607. case bfd_target_aout_flavour: return "a.out";
  1608. case bfd_target_coff_flavour: return "COFF";
  1609. case bfd_target_ecoff_flavour: return "ECOFF";
  1610. case bfd_target_xcoff_flavour: return "XCOFF";
  1611. case bfd_target_elf_flavour: return "ELF";
  1612. case bfd_target_tekhex_flavour: return "Tekhex";
  1613. case bfd_target_srec_flavour: return "Srec";
  1614. case bfd_target_verilog_flavour: return "Verilog";
  1615. case bfd_target_ihex_flavour: return "Ihex";
  1616. case bfd_target_som_flavour: return "SOM";
  1617. case bfd_target_os9k_flavour: return "OS9K";
  1618. case bfd_target_versados_flavour: return "Versados";
  1619. case bfd_target_msdos_flavour: return "MSDOS";
  1620. case bfd_target_ovax_flavour: return "Ovax";
  1621. case bfd_target_evax_flavour: return "Evax";
  1622. case bfd_target_mmo_flavour: return "mmo";
  1623. case bfd_target_mach_o_flavour: return "MACH_O";
  1624. case bfd_target_pef_flavour: return "PEF";
  1625. case bfd_target_pef_xlib_flavour: return "PEF_XLIB";
  1626. case bfd_target_sym_flavour: return "SYM";
  1627. /* There is no "default" case here so that -Wswitch (part of -Wall)
  1628. catches missing entries. */
  1629. }
  1630. abort ();
  1631. }