mach-o-target.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* Mach-O support for BFD.
  2. Copyright (C) 1999-2015 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. /* Define generic entry points here so that we don't need to duplicate the
  17. defines in every target. But define once as this file may be included
  18. several times. */
  19. #ifndef MACH_O_TARGET_COMMON_DEFINED
  20. #define MACH_O_TARGET_COMMON_DEFINED
  21. #define bfd_mach_o_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
  22. #define bfd_mach_o_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
  23. #define bfd_mach_o_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
  24. #define bfd_mach_o_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  25. #define bfd_mach_o_bfd_is_local_label_name bfd_generic_is_local_label_name
  26. #define bfd_mach_o_get_lineno _bfd_nosymbols_get_lineno
  27. #define bfd_mach_o_find_inliner_info _bfd_nosymbols_find_inliner_info
  28. #define bfd_mach_o_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string
  29. #define bfd_mach_o_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  30. #define bfd_mach_o_read_minisymbols _bfd_generic_read_minisymbols
  31. #define bfd_mach_o_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
  32. #define bfd_mach_o_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
  33. #define bfd_mach_o_bfd_relax_section bfd_generic_relax_section
  34. #define bfd_mach_o_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  35. #define bfd_mach_o_bfd_link_add_symbols _bfd_generic_link_add_symbols
  36. #define bfd_mach_o_bfd_link_just_syms _bfd_generic_link_just_syms
  37. #define bfd_mach_o_bfd_copy_link_hash_symbol_type \
  38. _bfd_generic_copy_link_hash_symbol_type
  39. #define bfd_mach_o_bfd_final_link _bfd_generic_final_link
  40. #define bfd_mach_o_bfd_link_split_section _bfd_generic_link_split_section
  41. #define bfd_mach_o_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
  42. #define bfd_mach_o_bfd_set_private_flags bfd_mach_o_bfd_set_private_flags
  43. #define bfd_mach_o_get_section_contents _bfd_generic_get_section_contents
  44. #define bfd_mach_o_bfd_gc_sections bfd_generic_gc_sections
  45. #define bfd_mach_o_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  46. #define bfd_mach_o_bfd_merge_sections bfd_generic_merge_sections
  47. #define bfd_mach_o_bfd_is_group_section bfd_generic_is_group_section
  48. #define bfd_mach_o_bfd_discard_group bfd_generic_discard_group
  49. #define bfd_mach_o_section_already_linked _bfd_generic_section_already_linked
  50. #define bfd_mach_o_bfd_define_common_symbol bfd_generic_define_common_symbol
  51. #define bfd_mach_o_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
  52. #define bfd_mach_o_core_file_matches_executable_p generic_core_file_matches_executable_p
  53. #define bfd_mach_o_core_file_pid _bfd_nocore_core_file_pid
  54. #define bfd_mach_o_get_dynamic_symtab_upper_bound bfd_mach_o_get_symtab_upper_bound
  55. #define bfd_mach_o_canonicalize_dynamic_symtab bfd_mach_o_canonicalize_symtab
  56. #define TARGET_NAME_BACKEND XCONCAT2(TARGET_NAME,_backend)
  57. #endif /* MACH_O_TARGET_COMMON_DEFINED */
  58. #ifndef TARGET_NAME
  59. #error TARGET_NAME must be defined
  60. #endif /* TARGET_NAME */
  61. #ifndef TARGET_STRING
  62. #error TARGET_STRING must be defined
  63. #endif /* TARGET_STRING */
  64. #ifndef TARGET_ARCHITECTURE
  65. #error TARGET_ARCHITECTURE must be defined
  66. #endif /* TARGET_ARCHITECTURE */
  67. #ifndef TARGET_BIG_ENDIAN
  68. #error TARGET_BIG_ENDIAN must be defined
  69. #endif /* TARGET_BIG_ENDIAN */
  70. #ifndef TARGET_ARCHIVE
  71. #error TARGET_ARCHIVE must be defined
  72. #endif /* TARGET_ARCHIVE */
  73. #ifndef TARGET_PAGESIZE
  74. #error TARGET_PAGESIZE must be defined
  75. #endif
  76. #if ((TARGET_ARCHIVE) && (! TARGET_BIG_ENDIAN))
  77. #error Mach-O fat files must always be big-endian.
  78. #endif /* ((TARGET_ARCHIVE) && (! TARGET_BIG_ENDIAN)) */
  79. static const bfd_mach_o_backend_data TARGET_NAME_BACKEND =
  80. {
  81. TARGET_ARCHITECTURE,
  82. TARGET_PAGESIZE,
  83. bfd_mach_o_swap_reloc_in,
  84. bfd_mach_o_swap_reloc_out,
  85. bfd_mach_o_print_thread,
  86. bfd_mach_o_tgt_seg_table,
  87. bfd_mach_o_section_type_valid_for_tgt
  88. };
  89. const bfd_target TARGET_NAME =
  90. {
  91. TARGET_STRING, /* Name. */
  92. bfd_target_mach_o_flavour,
  93. #if TARGET_BIG_ENDIAN
  94. BFD_ENDIAN_BIG, /* Target byte order. */
  95. BFD_ENDIAN_BIG, /* Target headers byte order. */
  96. #else
  97. BFD_ENDIAN_LITTLE, /* Target byte order. */
  98. BFD_ENDIAN_LITTLE, /* Target headers byte order. */
  99. #endif
  100. (HAS_RELOC | EXEC_P | /* Object flags. */
  101. HAS_LINENO | HAS_DEBUG |
  102. HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  103. (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
  104. | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
  105. '_', /* symbol_leading_char. */
  106. ' ', /* ar_pad_char. */
  107. 16, /* ar_max_namelen. */
  108. TARGET_PRIORITY, /* match priority. */
  109. #if TARGET_BIG_ENDIAN
  110. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  111. bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  112. bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
  113. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  114. bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  115. bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
  116. #else
  117. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  118. bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  119. bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  120. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  121. bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  122. bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  123. #endif /* TARGET_BIG_ENDIAN */
  124. { /* bfd_check_format. */
  125. #if TARGET_ARCHIVE
  126. _bfd_dummy_target,
  127. _bfd_dummy_target,
  128. bfd_mach_o_archive_p,
  129. _bfd_dummy_target,
  130. #else
  131. _bfd_dummy_target,
  132. bfd_mach_o_object_p,
  133. bfd_generic_archive_p,
  134. bfd_mach_o_core_p
  135. #endif
  136. },
  137. { /* bfd_set_format. */
  138. bfd_false,
  139. bfd_mach_o_mkobject,
  140. _bfd_generic_mkarchive,
  141. bfd_mach_o_mkobject,
  142. },
  143. { /* bfd_write_contents. */
  144. bfd_false,
  145. bfd_mach_o_write_contents,
  146. _bfd_write_archive_contents,
  147. bfd_mach_o_write_contents,
  148. },
  149. BFD_JUMP_TABLE_GENERIC (bfd_mach_o),
  150. BFD_JUMP_TABLE_COPY (bfd_mach_o),
  151. BFD_JUMP_TABLE_CORE (bfd_mach_o),
  152. #if TARGET_ARCHIVE
  153. BFD_JUMP_TABLE_ARCHIVE (bfd_mach_o),
  154. #else
  155. BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd44),
  156. #endif
  157. BFD_JUMP_TABLE_SYMBOLS (bfd_mach_o),
  158. BFD_JUMP_TABLE_RELOCS (bfd_mach_o),
  159. BFD_JUMP_TABLE_WRITE (bfd_mach_o),
  160. BFD_JUMP_TABLE_LINK (bfd_mach_o),
  161. BFD_JUMP_TABLE_DYNAMIC (bfd_mach_o),
  162. /* Alternative endian target. */
  163. NULL,
  164. /* Back-end data. */
  165. &TARGET_NAME_BACKEND
  166. };