mach-o.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /* Mach-O support for BFD.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #ifndef _BFD_MACH_O_H_
  17. #define _BFD_MACH_O_H_
  18. #include "mach-o/loader.h"
  19. #include "mach-o/external.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef struct bfd_mach_o_header
  24. {
  25. unsigned long magic;
  26. unsigned long cputype;
  27. unsigned long cpusubtype;
  28. unsigned long filetype;
  29. unsigned long ncmds;
  30. unsigned long sizeofcmds;
  31. unsigned long flags;
  32. unsigned int reserved;
  33. /* Version 1: 32 bits, version 2: 64 bits. */
  34. unsigned int version;
  35. enum bfd_endian byteorder;
  36. }
  37. bfd_mach_o_header;
  38. typedef struct bfd_mach_o_asymbol
  39. {
  40. /* The actual symbol which the rest of BFD works with. */
  41. asymbol symbol;
  42. /* Mach-O symbol fields. */
  43. unsigned char n_type;
  44. unsigned char n_sect;
  45. unsigned short n_desc;
  46. }
  47. bfd_mach_o_asymbol;
  48. #define BFD_MACH_O_SEGNAME_SIZE 16
  49. #define BFD_MACH_O_SECTNAME_SIZE 16
  50. typedef struct bfd_mach_o_section
  51. {
  52. /* Fields present in the file. */
  53. char sectname[BFD_MACH_O_SECTNAME_SIZE + 1]; /* Always NUL padded. */
  54. char segname[BFD_MACH_O_SEGNAME_SIZE + 1];
  55. bfd_vma addr;
  56. bfd_vma size;
  57. bfd_vma offset;
  58. unsigned long align;
  59. bfd_vma reloff;
  60. unsigned long nreloc;
  61. unsigned long flags;
  62. unsigned long reserved1;
  63. unsigned long reserved2;
  64. unsigned long reserved3;
  65. /* Corresponding bfd section. */
  66. asection *bfdsection;
  67. /* An array holding the indirect symbols for this section.
  68. NULL values indicate local symbols.
  69. The number of symbols is determined from the section size and type. */
  70. bfd_mach_o_asymbol **indirect_syms;
  71. /* Simply linked list. */
  72. struct bfd_mach_o_section *next;
  73. }
  74. bfd_mach_o_section;
  75. typedef struct bfd_mach_o_segment_command
  76. {
  77. char segname[BFD_MACH_O_SEGNAME_SIZE + 1];
  78. bfd_vma vmaddr;
  79. bfd_vma vmsize;
  80. bfd_vma fileoff;
  81. unsigned long filesize;
  82. unsigned long maxprot; /* Maximum permitted protection. */
  83. unsigned long initprot; /* Initial protection. */
  84. unsigned long nsects;
  85. unsigned long flags;
  86. /* Linked list of sections. */
  87. bfd_mach_o_section *sect_head;
  88. bfd_mach_o_section *sect_tail;
  89. }
  90. bfd_mach_o_segment_command;
  91. /* Protection flags. */
  92. #define BFD_MACH_O_PROT_READ 0x01
  93. #define BFD_MACH_O_PROT_WRITE 0x02
  94. #define BFD_MACH_O_PROT_EXECUTE 0x04
  95. /* Target platforms. */
  96. #define BFD_MACH_O_PLATFORM_MACOS 1
  97. #define BFD_MACH_O_PLATFORM_IOS 2
  98. #define BFD_MACH_O_PLATFORM_TVOS 3
  99. #define BFD_MACH_O_PLATFORM_WATCHOS 4
  100. #define BFD_MACH_O_PLATFORM_BRIDGEOS 5
  101. /* Build tools. */
  102. #define BFD_MACH_O_TOOL_CLANG 1
  103. #define BFD_MACH_O_TOOL_SWIFT 2
  104. #define BFD_MACH_O_TOOL_LD 3
  105. /* Expanded internal representation of a relocation entry. */
  106. typedef struct bfd_mach_o_reloc_info
  107. {
  108. bfd_vma r_address;
  109. bfd_vma r_value;
  110. unsigned int r_scattered : 1;
  111. unsigned int r_type : 4;
  112. unsigned int r_pcrel : 1;
  113. unsigned int r_length : 2;
  114. unsigned int r_extern : 1;
  115. }
  116. bfd_mach_o_reloc_info;
  117. /* The symbol table is sorted like this:
  118. (1) local.
  119. (otherwise in order of generation)
  120. (2) external defined
  121. (sorted by name)
  122. (3) external undefined / common
  123. (sorted by name)
  124. */
  125. typedef struct bfd_mach_o_symtab_command
  126. {
  127. unsigned int symoff;
  128. unsigned int nsyms;
  129. unsigned int stroff;
  130. unsigned int strsize;
  131. bfd_mach_o_asymbol *symbols;
  132. char *strtab;
  133. }
  134. bfd_mach_o_symtab_command;
  135. /* This is the second set of the symbolic information which is used to support
  136. the data structures for the dynamically link editor.
  137. The original set of symbolic information in the symtab_command which contains
  138. the symbol and string tables must also be present when this load command is
  139. present. When this load command is present the symbol table is organized
  140. into three groups of symbols:
  141. local symbols (static and debugging symbols) - grouped by module
  142. defined external symbols - grouped by module (sorted by name if not lib)
  143. undefined external symbols (sorted by name)
  144. In this load command there are offsets and counts to each of the three groups
  145. of symbols.
  146. This load command contains a the offsets and sizes of the following new
  147. symbolic information tables:
  148. table of contents
  149. module table
  150. reference symbol table
  151. indirect symbol table
  152. The first three tables above (the table of contents, module table and
  153. reference symbol table) are only present if the file is a dynamically linked
  154. shared library. For executable and object modules, which are files
  155. containing only one module, the information that would be in these three
  156. tables is determined as follows:
  157. table of contents - the defined external symbols are sorted by name
  158. module table - the file contains only one module so everything in the
  159. file is part of the module.
  160. reference symbol table - is the defined and undefined external symbols
  161. For dynamically linked shared library files this load command also contains
  162. offsets and sizes to the pool of relocation entries for all sections
  163. separated into two groups:
  164. external relocation entries
  165. local relocation entries
  166. For executable and object modules the relocation entries continue to hang
  167. off the section structures. */
  168. typedef struct bfd_mach_o_dylib_module
  169. {
  170. /* Index into the string table indicating the name of the module. */
  171. unsigned long module_name_idx;
  172. char *module_name;
  173. /* Index into the symbol table of the first defined external symbol provided
  174. by the module. */
  175. unsigned long iextdefsym;
  176. /* Number of external symbols provided by this module. */
  177. unsigned long nextdefsym;
  178. /* Index into the external reference table of the first entry
  179. provided by this module. */
  180. unsigned long irefsym;
  181. /* Number of external reference entries provided by this module. */
  182. unsigned long nrefsym;
  183. /* Index into the symbol table of the first local symbol provided by this
  184. module. */
  185. unsigned long ilocalsym;
  186. /* Number of local symbols provided by this module. */
  187. unsigned long nlocalsym;
  188. /* Index into the external relocation table of the first entry provided
  189. by this module. */
  190. unsigned long iextrel;
  191. /* Number of external relocation entries provided by this module. */
  192. unsigned long nextrel;
  193. /* Index in the module initialization section to the pointers for this
  194. module. */
  195. unsigned short iinit;
  196. /* Index in the module termination section to the pointers for this
  197. module. */
  198. unsigned short iterm;
  199. /* Number of pointers in the module initialization for this module. */
  200. unsigned short ninit;
  201. /* Number of pointers in the module termination for this module. */
  202. unsigned short nterm;
  203. /* Number of data byte for this module that are used in the __module_info
  204. section of the __OBJC segment. */
  205. unsigned long objc_module_info_size;
  206. /* Statically linked address of the start of the data for this module
  207. in the __module_info section of the __OBJC_segment. */
  208. bfd_vma objc_module_info_addr;
  209. }
  210. bfd_mach_o_dylib_module;
  211. typedef struct bfd_mach_o_dylib_table_of_content
  212. {
  213. /* Index into the symbol table to the defined external symbol. */
  214. unsigned long symbol_index;
  215. /* Index into the module table to the module for this entry. */
  216. unsigned long module_index;
  217. }
  218. bfd_mach_o_dylib_table_of_content;
  219. typedef struct bfd_mach_o_dylib_reference
  220. {
  221. /* Index into the symbol table for the symbol being referenced. */
  222. unsigned long isym;
  223. /* Type of the reference being made (use REFERENCE_FLAGS constants). */
  224. unsigned long flags;
  225. }
  226. bfd_mach_o_dylib_reference;
  227. #define BFD_MACH_O_REFERENCE_SIZE 4
  228. typedef struct bfd_mach_o_dysymtab_command
  229. {
  230. /* The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
  231. are grouped into the following three groups:
  232. local symbols (further grouped by the module they are from)
  233. defined external symbols (further grouped by the module they are from)
  234. undefined symbols
  235. The local symbols are used only for debugging. The dynamic binding
  236. process may have to use them to indicate to the debugger the local
  237. symbols for a module that is being bound.
  238. The last two groups are used by the dynamic binding process to do the
  239. binding (indirectly through the module table and the reference symbol
  240. table when this is a dynamically linked shared library file). */
  241. unsigned long ilocalsym; /* Index to local symbols. */
  242. unsigned long nlocalsym; /* Number of local symbols. */
  243. unsigned long iextdefsym; /* Index to externally defined symbols. */
  244. unsigned long nextdefsym; /* Number of externally defined symbols. */
  245. unsigned long iundefsym; /* Index to undefined symbols. */
  246. unsigned long nundefsym; /* Number of undefined symbols. */
  247. /* For the for the dynamic binding process to find which module a symbol
  248. is defined in the table of contents is used (analogous to the ranlib
  249. structure in an archive) which maps defined external symbols to modules
  250. they are defined in. This exists only in a dynamically linked shared
  251. library file. For executable and object modules the defined external
  252. symbols are sorted by name and is use as the table of contents. */
  253. unsigned long tocoff; /* File offset to table of contents. */
  254. unsigned long ntoc; /* Number of entries in table of contents. */
  255. /* To support dynamic binding of "modules" (whole object files) the symbol
  256. table must reflect the modules that the file was created from. This is
  257. done by having a module table that has indexes and counts into the merged
  258. tables for each module. The module structure that these two entries
  259. refer to is described below. This exists only in a dynamically linked
  260. shared library file. For executable and object modules the file only
  261. contains one module so everything in the file belongs to the module. */
  262. unsigned long modtaboff; /* File offset to module table. */
  263. unsigned long nmodtab; /* Number of module table entries. */
  264. /* To support dynamic module binding the module structure for each module
  265. indicates the external references (defined and undefined) each module
  266. makes. For each module there is an offset and a count into the
  267. reference symbol table for the symbols that the module references.
  268. This exists only in a dynamically linked shared library file. For
  269. executable and object modules the defined external symbols and the
  270. undefined external symbols indicates the external references. */
  271. unsigned long extrefsymoff; /* Offset to referenced symbol table. */
  272. unsigned long nextrefsyms; /* Number of referenced symbol table entries. */
  273. /* The sections that contain "symbol pointers" and "routine stubs" have
  274. indexes and (implied counts based on the size of the section and fixed
  275. size of the entry) into the "indirect symbol" table for each pointer
  276. and stub. For every section of these two types the index into the
  277. indirect symbol table is stored in the section header in the field
  278. reserved1. An indirect symbol table entry is simply a 32bit index into
  279. the symbol table to the symbol that the pointer or stub is referring to.
  280. The indirect symbol table is ordered to match the entries in the section. */
  281. unsigned long indirectsymoff; /* File offset to the indirect symbol table. */
  282. unsigned long nindirectsyms; /* Number of indirect symbol table entries. */
  283. /* To support relocating an individual module in a library file quickly the
  284. external relocation entries for each module in the library need to be
  285. accessed efficiently. Since the relocation entries can't be accessed
  286. through the section headers for a library file they are separated into
  287. groups of local and external entries further grouped by module. In this
  288. case the presents of this load command who's extreloff, nextrel,
  289. locreloff and nlocrel fields are non-zero indicates that the relocation
  290. entries of non-merged sections are not referenced through the section
  291. structures (and the reloff and nreloc fields in the section headers are
  292. set to zero).
  293. Since the relocation entries are not accessed through the section headers
  294. this requires the r_address field to be something other than a section
  295. offset to identify the item to be relocated. In this case r_address is
  296. set to the offset from the vmaddr of the first LC_SEGMENT command.
  297. The relocation entries are grouped by module and the module table
  298. entries have indexes and counts into them for the group of external
  299. relocation entries for that the module.
  300. For sections that are merged across modules there must not be any
  301. remaining external relocation entries for them (for merged sections
  302. remaining relocation entries must be local). */
  303. unsigned long extreloff; /* Offset to external relocation entries. */
  304. unsigned long nextrel; /* Number of external relocation entries. */
  305. /* All the local relocation entries are grouped together (they are not
  306. grouped by their module since they are only used if the object is moved
  307. from it statically link edited address). */
  308. unsigned long locreloff; /* Offset to local relocation entries. */
  309. unsigned long nlocrel; /* Number of local relocation entries. */
  310. bfd_mach_o_dylib_module *dylib_module;
  311. bfd_mach_o_dylib_table_of_content *dylib_toc;
  312. unsigned int *indirect_syms;
  313. bfd_mach_o_dylib_reference *ext_refs;
  314. }
  315. bfd_mach_o_dysymtab_command;
  316. /* An indirect symbol table entry is simply a 32bit index into the symbol table
  317. to the symbol that the pointer or stub is refering to. Unless it is for a
  318. non-lazy symbol pointer section for a defined symbol which strip(1) has
  319. removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the
  320. symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. */
  321. #define BFD_MACH_O_INDIRECT_SYMBOL_LOCAL 0x80000000
  322. #define BFD_MACH_O_INDIRECT_SYMBOL_ABS 0x40000000
  323. #define BFD_MACH_O_INDIRECT_SYMBOL_SIZE 4
  324. /* For LC_TWOLEVEL_HINTS. */
  325. typedef struct bfd_mach_o_twolevel_hints_command
  326. {
  327. /* Offset to the hint table. */
  328. unsigned int offset;
  329. /* Number of entries in the table. */
  330. unsigned int nhints;
  331. }
  332. bfd_mach_o_twolevel_hints_command;
  333. /* For LC_PREBIND_CKSUM. */
  334. typedef struct bfd_mach_o_prebind_cksum_command
  335. {
  336. /* Checksum or zero. */
  337. unsigned int cksum;
  338. }
  339. bfd_mach_o_prebind_cksum_command;
  340. /* For LC_THREAD or LC_UNIXTHREAD. */
  341. typedef struct bfd_mach_o_thread_flavour
  342. {
  343. unsigned long flavour;
  344. unsigned long offset;
  345. unsigned long size;
  346. }
  347. bfd_mach_o_thread_flavour;
  348. typedef struct bfd_mach_o_thread_command
  349. {
  350. unsigned long nflavours;
  351. bfd_mach_o_thread_flavour *flavours;
  352. asection *section;
  353. }
  354. bfd_mach_o_thread_command;
  355. /* For LC_LOAD_DYLINKER and LC_ID_DYLINKER. */
  356. typedef struct bfd_mach_o_dylinker_command
  357. {
  358. unsigned int name_offset; /* Offset to library's path name. */
  359. char *name_str;
  360. }
  361. bfd_mach_o_dylinker_command;
  362. /* For LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, LC_ID_DYLIB
  363. or LC_REEXPORT_DYLIB. */
  364. typedef struct bfd_mach_o_dylib_command
  365. {
  366. unsigned int name_offset; /* Offset to library's path name. */
  367. unsigned long timestamp; /* Library's build time stamp. */
  368. unsigned long current_version; /* Library's current version number. */
  369. unsigned long compatibility_version; /* Library's compatibility vers number. */
  370. char *name_str;
  371. }
  372. bfd_mach_o_dylib_command;
  373. /* For LC_PREBOUND_DYLIB. */
  374. typedef struct bfd_mach_o_prebound_dylib_command
  375. {
  376. unsigned int name_offset; /* Library's path name. */
  377. unsigned int nmodules; /* Number of modules in library. */
  378. unsigned int linked_modules_offset; /* Bit vector of linked modules. */
  379. char *name_str;
  380. unsigned char *linked_modules;
  381. }
  382. bfd_mach_o_prebound_dylib_command;
  383. /* For LC_UUID. */
  384. typedef struct bfd_mach_o_uuid_command
  385. {
  386. unsigned char uuid[16];
  387. }
  388. bfd_mach_o_uuid_command;
  389. /* For LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO. */
  390. typedef struct bfd_mach_o_linkedit_command
  391. {
  392. unsigned long dataoff;
  393. unsigned long datasize;
  394. }
  395. bfd_mach_o_linkedit_command;
  396. typedef struct bfd_mach_o_str_command
  397. {
  398. unsigned long stroff;
  399. unsigned long str_len;
  400. char *str;
  401. }
  402. bfd_mach_o_str_command;
  403. typedef struct bfd_mach_o_fvmlib_command
  404. {
  405. unsigned int name_offset;
  406. char *name_str;
  407. unsigned int minor_version;
  408. unsigned int header_addr;
  409. }
  410. bfd_mach_o_fvmlib_command;
  411. typedef struct bfd_mach_o_dyld_info_command
  412. {
  413. /* File offset and size to rebase info. */
  414. unsigned int rebase_off;
  415. unsigned int rebase_size;
  416. unsigned char *rebase_content;
  417. /* File offset and size of binding info. */
  418. unsigned int bind_off;
  419. unsigned int bind_size;
  420. unsigned char *bind_content;
  421. /* File offset and size of weak binding info. */
  422. unsigned int weak_bind_off;
  423. unsigned int weak_bind_size;
  424. unsigned char *weak_bind_content;
  425. /* File offset and size of lazy binding info. */
  426. unsigned int lazy_bind_off;
  427. unsigned int lazy_bind_size;
  428. unsigned char *lazy_bind_content;
  429. /* File offset and size of export info. */
  430. unsigned int export_off;
  431. unsigned int export_size;
  432. unsigned char *export_content;
  433. }
  434. bfd_mach_o_dyld_info_command;
  435. typedef struct bfd_mach_o_version_min_command
  436. {
  437. uint32_t version;
  438. uint32_t sdk;
  439. }
  440. bfd_mach_o_version_min_command;
  441. typedef struct bfd_mach_o_encryption_info_command
  442. {
  443. unsigned int cryptoff;
  444. unsigned int cryptsize;
  445. unsigned int cryptid;
  446. }
  447. bfd_mach_o_encryption_info_command;
  448. typedef struct bfd_mach_o_main_command
  449. {
  450. bfd_uint64_t entryoff;
  451. bfd_uint64_t stacksize;
  452. }
  453. bfd_mach_o_main_command;
  454. typedef struct bfd_mach_o_source_version_command
  455. {
  456. unsigned int a;
  457. unsigned short b;
  458. unsigned short c;
  459. unsigned short d;
  460. unsigned short e;
  461. }
  462. bfd_mach_o_source_version_command;
  463. typedef struct bfd_mach_o_note_command
  464. {
  465. char data_owner[16];
  466. bfd_uint64_t offset;
  467. bfd_uint64_t size;
  468. }
  469. bfd_mach_o_note_command;
  470. typedef struct bfd_mach_o_build_version_tool
  471. {
  472. uint32_t tool;
  473. uint32_t version;
  474. }
  475. bfd_mach_o_build_version_tool;
  476. typedef struct bfd_mach_o_build_version_command
  477. {
  478. uint32_t platform;
  479. uint32_t minos;
  480. uint32_t sdk;
  481. uint32_t ntools;
  482. }
  483. bfd_mach_o_build_version_command;
  484. typedef struct bfd_mach_o_load_command
  485. {
  486. /* Next command in the single linked list. */
  487. struct bfd_mach_o_load_command *next;
  488. /* Type and required flag. */
  489. bfd_mach_o_load_command_type type;
  490. bool type_required;
  491. /* Offset and length in the file. */
  492. unsigned int offset;
  493. unsigned int len;
  494. union
  495. {
  496. bfd_mach_o_segment_command segment;
  497. bfd_mach_o_symtab_command symtab;
  498. bfd_mach_o_dysymtab_command dysymtab;
  499. bfd_mach_o_thread_command thread;
  500. bfd_mach_o_dylib_command dylib;
  501. bfd_mach_o_dylinker_command dylinker;
  502. bfd_mach_o_prebound_dylib_command prebound_dylib;
  503. bfd_mach_o_prebind_cksum_command prebind_cksum;
  504. bfd_mach_o_twolevel_hints_command twolevel_hints;
  505. bfd_mach_o_uuid_command uuid;
  506. bfd_mach_o_linkedit_command linkedit;
  507. bfd_mach_o_str_command str;
  508. bfd_mach_o_dyld_info_command dyld_info;
  509. bfd_mach_o_version_min_command version_min;
  510. bfd_mach_o_encryption_info_command encryption_info;
  511. bfd_mach_o_fvmlib_command fvmlib;
  512. bfd_mach_o_main_command main;
  513. bfd_mach_o_source_version_command source_version;
  514. bfd_mach_o_note_command note;
  515. bfd_mach_o_build_version_command build_version;
  516. } command;
  517. }
  518. bfd_mach_o_load_command;
  519. typedef struct mach_o_data_struct
  520. {
  521. /* Mach-O header. */
  522. bfd_mach_o_header header;
  523. /* File offset of the header. Usually this is 0. */
  524. file_ptr hdr_offset;
  525. /* Array of load commands (length is given by header.ncmds). */
  526. bfd_mach_o_load_command *first_command;
  527. bfd_mach_o_load_command *last_command;
  528. /* Flatten array of sections. The array is 0-based. */
  529. unsigned long nsects;
  530. bfd_mach_o_section **sections;
  531. /* Used while writing: current length of the output file. This is used
  532. to allocate space in the file. */
  533. ufile_ptr filelen;
  534. /* As symtab is referenced by other load command, it is handy to have
  535. a direct access to it. Although it is not clearly stated, only one symtab
  536. is expected. */
  537. bfd_mach_o_symtab_command *symtab;
  538. bfd_mach_o_dysymtab_command *dysymtab;
  539. /* A place to stash dwarf2 info for this bfd. */
  540. void *dwarf2_find_line_info;
  541. /* BFD of .dSYM file. */
  542. bfd *dsym_bfd;
  543. /* Cache of dynamic relocs. */
  544. arelent *dyn_reloc_cache;
  545. }
  546. bfd_mach_o_data_struct;
  547. typedef struct bfd_mach_o_xlat_name
  548. {
  549. const char *name;
  550. unsigned long val;
  551. }
  552. bfd_mach_o_xlat_name;
  553. /* Target specific routines. */
  554. #define bfd_mach_o_get_data(abfd) ((abfd)->tdata.mach_o_data)
  555. #define bfd_mach_o_get_backend_data(abfd) \
  556. ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
  557. /* Get the Mach-O header for section SEC. */
  558. #define bfd_mach_o_get_mach_o_section(sec) \
  559. ((bfd_mach_o_section *)(sec)->used_by_bfd)
  560. bool bfd_mach_o_valid (bfd *);
  561. bool bfd_mach_o_mkobject_init (bfd *);
  562. bfd_cleanup bfd_mach_o_object_p (bfd *);
  563. bfd_cleanup bfd_mach_o_core_p (bfd *);
  564. bfd_cleanup bfd_mach_o_fat_archive_p (bfd *);
  565. bfd *bfd_mach_o_fat_openr_next_archived_file (bfd *, bfd *);
  566. bool bfd_mach_o_set_arch_mach (bfd *, enum bfd_architecture, unsigned long);
  567. int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type,
  568. bfd_mach_o_load_command **);
  569. bool bfd_mach_o_new_section_hook (bfd *, asection *);
  570. bool bfd_mach_o_write_contents (bfd *);
  571. bool bfd_mach_o_bfd_copy_private_symbol_data (bfd *, asymbol *,
  572. bfd *, asymbol *);
  573. bool bfd_mach_o_bfd_copy_private_section_data (bfd *, asection *,
  574. bfd *, asection *);
  575. bool bfd_mach_o_bfd_copy_private_header_data (bfd *, bfd *);
  576. bool bfd_mach_o_bfd_set_private_flags (bfd *, flagword);
  577. bool bfd_mach_o_bfd_print_private_bfd_data (bfd *, void *);
  578. long bfd_mach_o_get_symtab_upper_bound (bfd *);
  579. long bfd_mach_o_canonicalize_symtab (bfd *, asymbol **);
  580. long bfd_mach_o_get_synthetic_symtab (bfd *, long, asymbol **, long,
  581. asymbol **, asymbol **ret);
  582. long bfd_mach_o_get_reloc_upper_bound (bfd *, asection *);
  583. long bfd_mach_o_canonicalize_reloc (bfd *, asection *, arelent **, asymbol **);
  584. long bfd_mach_o_get_dynamic_reloc_upper_bound (bfd *);
  585. long bfd_mach_o_canonicalize_dynamic_reloc (bfd *, arelent **, asymbol **);
  586. asymbol *bfd_mach_o_make_empty_symbol (bfd *);
  587. void bfd_mach_o_get_symbol_info (bfd *, asymbol *, symbol_info *);
  588. void bfd_mach_o_print_symbol (bfd *, void *, asymbol *, bfd_print_symbol_type);
  589. int bfd_mach_o_sizeof_headers (bfd *, struct bfd_link_info *);
  590. unsigned long bfd_mach_o_stack_addr (enum bfd_mach_o_cpu_type);
  591. int bfd_mach_o_core_fetch_environment (bfd *, unsigned char **, unsigned int *);
  592. char *bfd_mach_o_core_file_failing_command (bfd *);
  593. int bfd_mach_o_core_file_failing_signal (bfd *);
  594. bool bfd_mach_o_core_file_matches_executable_p (bfd *, bfd *);
  595. bfd *bfd_mach_o_fat_extract (bfd *, bfd_format , const bfd_arch_info_type *);
  596. bfd_cleanup bfd_mach_o_header_p (bfd *, file_ptr, bfd_mach_o_filetype,
  597. bfd_mach_o_cpu_type);
  598. bool bfd_mach_o_build_commands (bfd *);
  599. bool bfd_mach_o_set_section_contents (bfd *, asection *, const void *,
  600. file_ptr, bfd_size_type);
  601. unsigned int bfd_mach_o_version (bfd *);
  602. unsigned int bfd_mach_o_get_section_type_from_name (bfd *, const char *);
  603. unsigned int bfd_mach_o_get_section_attribute_from_name (const char *);
  604. void bfd_mach_o_convert_section_name_to_bfd (bfd *, const char *, const char *,
  605. const char **, flagword *);
  606. bool bfd_mach_o_find_nearest_line (bfd *, asymbol **,
  607. asection *, bfd_vma,
  608. const char **, const char **,
  609. unsigned int *, unsigned int *);
  610. #define bfd_mach_o_find_line _bfd_nosymbols_find_line
  611. bool bfd_mach_o_close_and_cleanup (bfd *);
  612. bool bfd_mach_o_free_cached_info (bfd *);
  613. unsigned int bfd_mach_o_section_get_nbr_indirect (bfd *, bfd_mach_o_section *);
  614. unsigned int bfd_mach_o_section_get_entry_size (bfd *, bfd_mach_o_section *);
  615. bool bfd_mach_o_read_symtab_symbols (bfd *);
  616. bool bfd_mach_o_read_symtab_strtab (bfd *abfd);
  617. bfd_vma bfd_mach_o_get_base_address (bfd *);
  618. void bfd_mach_o_swap_in_non_scattered_reloc (bfd *, bfd_mach_o_reloc_info *,
  619. unsigned char *);
  620. bool bfd_mach_o_canonicalize_non_scattered_reloc (bfd *, bfd_mach_o_reloc_info *, arelent *, asymbol **);
  621. bool bfd_mach_o_pre_canonicalize_one_reloc (bfd *, struct mach_o_reloc_info_external *, bfd_mach_o_reloc_info *, arelent *, asymbol **);
  622. /* A placeholder in case we need to suppress emitting the dysymtab for some
  623. reason (e.g. compatibility with older system versions). */
  624. #define bfd_mach_o_should_emit_dysymtab(x) true
  625. extern const bfd_mach_o_xlat_name bfd_mach_o_section_attribute_name[];
  626. extern const bfd_mach_o_xlat_name bfd_mach_o_section_type_name[];
  627. extern const bfd_target mach_o_fat_vec;
  628. /* Interfaces between BFD names and Mach-O names. */
  629. typedef struct mach_o_section_name_xlat
  630. {
  631. const char *bfd_name;
  632. const char *mach_o_name;
  633. flagword bfd_flags;
  634. unsigned int macho_sectype;
  635. unsigned int macho_secattr;
  636. unsigned int sectalign;
  637. } mach_o_section_name_xlat;
  638. typedef struct mach_o_segment_name_xlat
  639. {
  640. const char *segname;
  641. const mach_o_section_name_xlat *sections;
  642. } mach_o_segment_name_xlat;
  643. const mach_o_section_name_xlat *
  644. bfd_mach_o_section_data_for_mach_sect (bfd *, const char *, const char *);
  645. const mach_o_section_name_xlat *
  646. bfd_mach_o_section_data_for_bfd_name (bfd *, const char *, const char **);
  647. typedef struct bfd_mach_o_backend_data
  648. {
  649. enum bfd_architecture arch;
  650. bfd_vma page_size;
  651. bool (*_bfd_mach_o_canonicalize_one_reloc)
  652. (bfd *, struct mach_o_reloc_info_external *, arelent *, asymbol **, arelent *);
  653. bool (*_bfd_mach_o_swap_reloc_out)(arelent *, bfd_mach_o_reloc_info *);
  654. bool (*_bfd_mach_o_print_thread)(bfd *, bfd_mach_o_thread_flavour *,
  655. void *, char *);
  656. const mach_o_segment_name_xlat *segsec_names_xlat;
  657. bool (*bfd_mach_o_section_type_valid_for_target) (unsigned long);
  658. }
  659. bfd_mach_o_backend_data;
  660. /* Values used in symbol.udata.i, to signal that the mach-o-specific data in the
  661. symbol are not yet set, or need validation (where this is possible). */
  662. #define SYM_MACHO_FIELDS_UNSET ((bfd_vma) -1)
  663. #define SYM_MACHO_FIELDS_NOT_VALIDATED ((bfd_vma) -2)
  664. #ifdef __cplusplus
  665. }
  666. #endif
  667. #endif /* _BFD_MACH_O_H_ */