175fd0b74Schristos /* Mach-O support for BFD. 2*e992f068Schristos Copyright (C) 1999-2022 Free Software Foundation, Inc. 375fd0b74Schristos 475fd0b74Schristos This file is part of BFD, the Binary File Descriptor library. 575fd0b74Schristos 675fd0b74Schristos This program is free software; you can redistribute it and/or modify 775fd0b74Schristos it under the terms of the GNU General Public License as published by 875fd0b74Schristos the Free Software Foundation; either version 3 of the License, or 975fd0b74Schristos (at your option) any later version. 1075fd0b74Schristos 1175fd0b74Schristos This program is distributed in the hope that it will be useful, 1275fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1375fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1475fd0b74Schristos GNU General Public License for more details. 1575fd0b74Schristos 1675fd0b74Schristos You should have received a copy of the GNU General Public License 1775fd0b74Schristos along with this program; if not, write to the Free Software 1875fd0b74Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 1975fd0b74Schristos MA 02110-1301, USA. */ 2075fd0b74Schristos 2175fd0b74Schristos /* Define generic entry points here so that we don't need to duplicate the 2275fd0b74Schristos defines in every target. But define once as this file may be included 2375fd0b74Schristos several times. */ 2475fd0b74Schristos #ifndef MACH_O_TARGET_COMMON_DEFINED 2575fd0b74Schristos #define MACH_O_TARGET_COMMON_DEFINED 2675fd0b74Schristos 2775fd0b74Schristos #define bfd_mach_o_bfd_free_cached_info _bfd_generic_bfd_free_cached_info 2875fd0b74Schristos #define bfd_mach_o_get_section_contents_in_window _bfd_generic_get_section_contents_in_window 29ede78133Schristos #define bfd_mach_o_bfd_print_private_bfd_data bfd_mach_o_bfd_print_private_bfd_data 30ede78133Schristos #define bfd_mach_o_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false 3175fd0b74Schristos #define bfd_mach_o_bfd_is_local_label_name bfd_generic_is_local_label_name 3275fd0b74Schristos #define bfd_mach_o_get_lineno _bfd_nosymbols_get_lineno 3375fd0b74Schristos #define bfd_mach_o_find_inliner_info _bfd_nosymbols_find_inliner_info 3475fd0b74Schristos #define bfd_mach_o_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string 3575fd0b74Schristos #define bfd_mach_o_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol 3675fd0b74Schristos #define bfd_mach_o_read_minisymbols _bfd_generic_read_minisymbols 3775fd0b74Schristos #define bfd_mach_o_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol 3875fd0b74Schristos #define bfd_mach_o_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents 3975fd0b74Schristos #define bfd_mach_o_bfd_relax_section bfd_generic_relax_section 4075fd0b74Schristos #define bfd_mach_o_bfd_link_hash_table_create _bfd_generic_link_hash_table_create 4175fd0b74Schristos #define bfd_mach_o_bfd_link_add_symbols _bfd_generic_link_add_symbols 4275fd0b74Schristos #define bfd_mach_o_bfd_link_just_syms _bfd_generic_link_just_syms 4375fd0b74Schristos #define bfd_mach_o_bfd_copy_link_hash_symbol_type \ 4475fd0b74Schristos _bfd_generic_copy_link_hash_symbol_type 4575fd0b74Schristos #define bfd_mach_o_bfd_final_link _bfd_generic_final_link 4675fd0b74Schristos #define bfd_mach_o_bfd_link_split_section _bfd_generic_link_split_section 4775fd0b74Schristos #define bfd_mach_o_bfd_link_check_relocs _bfd_generic_link_check_relocs 4875fd0b74Schristos #define bfd_mach_o_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data 4975fd0b74Schristos #define bfd_mach_o_bfd_set_private_flags bfd_mach_o_bfd_set_private_flags 5075fd0b74Schristos #define bfd_mach_o_get_section_contents _bfd_generic_get_section_contents 5175fd0b74Schristos #define bfd_mach_o_bfd_gc_sections bfd_generic_gc_sections 5275fd0b74Schristos #define bfd_mach_o_bfd_lookup_section_flags bfd_generic_lookup_section_flags 5375fd0b74Schristos #define bfd_mach_o_bfd_merge_sections bfd_generic_merge_sections 5475fd0b74Schristos #define bfd_mach_o_bfd_is_group_section bfd_generic_is_group_section 55012573ebSchristos #define bfd_mach_o_bfd_group_name bfd_generic_group_name 5675fd0b74Schristos #define bfd_mach_o_bfd_discard_group bfd_generic_discard_group 5775fd0b74Schristos #define bfd_mach_o_section_already_linked _bfd_generic_section_already_linked 5875fd0b74Schristos #define bfd_mach_o_bfd_define_common_symbol bfd_generic_define_common_symbol 59ede78133Schristos #define bfd_mach_o_bfd_link_hide_symbol _bfd_generic_link_hide_symbol 60ede78133Schristos #define bfd_mach_o_bfd_define_start_stop bfd_generic_define_start_stop 6175fd0b74Schristos #define bfd_mach_o_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data 6275fd0b74Schristos #define bfd_mach_o_core_file_matches_executable_p generic_core_file_matches_executable_p 6375fd0b74Schristos #define bfd_mach_o_core_file_pid _bfd_nocore_core_file_pid 64ede78133Schristos #define bfd_mach_o_set_reloc _bfd_generic_set_reloc 6575fd0b74Schristos 6675fd0b74Schristos #define bfd_mach_o_get_dynamic_symtab_upper_bound bfd_mach_o_get_symtab_upper_bound 6775fd0b74Schristos #define bfd_mach_o_canonicalize_dynamic_symtab bfd_mach_o_canonicalize_symtab 6875fd0b74Schristos 6975fd0b74Schristos /* For Mach-O special archives. */ 7075fd0b74Schristos #define bfd_mach_o_read_ar_hdr _bfd_noarchive_read_ar_hdr 7175fd0b74Schristos #define bfd_mach_o_write_ar_hdr _bfd_noarchive_write_ar_hdr 7275fd0b74Schristos #define bfd_mach_o_slurp_armap _bfd_noarchive_slurp_armap 7375fd0b74Schristos #define bfd_mach_o_slurp_extended_name_table _bfd_noarchive_slurp_extended_name_table 7475fd0b74Schristos #define bfd_mach_o_construct_extended_name_table _bfd_noarchive_construct_extended_name_table 7575fd0b74Schristos #define bfd_mach_o_truncate_arname _bfd_noarchive_truncate_arname 7675fd0b74Schristos #define bfd_mach_o_write_armap _bfd_noarchive_write_armap 7775fd0b74Schristos #define bfd_mach_o_get_elt_at_index _bfd_noarchive_get_elt_at_index 7875fd0b74Schristos #define bfd_mach_o_update_armap_timestamp _bfd_noarchive_update_armap_timestamp 7975fd0b74Schristos 8075fd0b74Schristos #define TARGET_NAME_BACKEND XCONCAT2(TARGET_NAME,_backend) 8175fd0b74Schristos 8275fd0b74Schristos #endif /* MACH_O_TARGET_COMMON_DEFINED */ 8375fd0b74Schristos 8475fd0b74Schristos #ifndef TARGET_NAME 8575fd0b74Schristos #error TARGET_NAME must be defined 8675fd0b74Schristos #endif /* TARGET_NAME */ 8775fd0b74Schristos 8875fd0b74Schristos #ifndef TARGET_STRING 8975fd0b74Schristos #error TARGET_STRING must be defined 9075fd0b74Schristos #endif /* TARGET_STRING */ 9175fd0b74Schristos 9275fd0b74Schristos #ifndef TARGET_ARCHITECTURE 9375fd0b74Schristos #error TARGET_ARCHITECTURE must be defined 9475fd0b74Schristos #endif /* TARGET_ARCHITECTURE */ 9575fd0b74Schristos 9675fd0b74Schristos #ifndef TARGET_BIG_ENDIAN 9775fd0b74Schristos #error TARGET_BIG_ENDIAN must be defined 9875fd0b74Schristos #endif /* TARGET_BIG_ENDIAN */ 9975fd0b74Schristos 10075fd0b74Schristos #ifndef TARGET_ARCHIVE 10175fd0b74Schristos #error TARGET_ARCHIVE must be defined 10275fd0b74Schristos #endif /* TARGET_ARCHIVE */ 10375fd0b74Schristos 10475fd0b74Schristos #ifndef TARGET_PAGESIZE 10575fd0b74Schristos #error TARGET_PAGESIZE must be defined 10675fd0b74Schristos #endif 10775fd0b74Schristos 10875fd0b74Schristos static const bfd_mach_o_backend_data TARGET_NAME_BACKEND = 10975fd0b74Schristos { 11075fd0b74Schristos TARGET_ARCHITECTURE, 11175fd0b74Schristos TARGET_PAGESIZE, 11275fd0b74Schristos bfd_mach_o_canonicalize_one_reloc, 11375fd0b74Schristos bfd_mach_o_swap_reloc_out, 11475fd0b74Schristos bfd_mach_o_print_thread, 11575fd0b74Schristos bfd_mach_o_tgt_seg_table, 11675fd0b74Schristos bfd_mach_o_section_type_valid_for_tgt 11775fd0b74Schristos }; 11875fd0b74Schristos 11975fd0b74Schristos const bfd_target TARGET_NAME = 12075fd0b74Schristos { 12175fd0b74Schristos TARGET_STRING, /* Name. */ 12275fd0b74Schristos bfd_target_mach_o_flavour, 12375fd0b74Schristos #if TARGET_BIG_ENDIAN 12475fd0b74Schristos BFD_ENDIAN_BIG, /* Target byte order. */ 12575fd0b74Schristos BFD_ENDIAN_BIG, /* Target headers byte order. */ 12675fd0b74Schristos #else 12775fd0b74Schristos BFD_ENDIAN_LITTLE, /* Target byte order. */ 12875fd0b74Schristos BFD_ENDIAN_LITTLE, /* Target headers byte order. */ 12975fd0b74Schristos #endif 13075fd0b74Schristos (HAS_RELOC | EXEC_P | /* Object flags. */ 13175fd0b74Schristos HAS_LINENO | HAS_DEBUG | 13275fd0b74Schristos HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), 13375fd0b74Schristos (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS 13475fd0b74Schristos | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */ 13575fd0b74Schristos '_', /* symbol_leading_char. */ 13675fd0b74Schristos ' ', /* ar_pad_char. */ 13775fd0b74Schristos 16, /* ar_max_namelen. */ 13875fd0b74Schristos TARGET_PRIORITY, /* match priority. */ 139*e992f068Schristos TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ 14075fd0b74Schristos 14175fd0b74Schristos #if TARGET_BIG_ENDIAN 14275fd0b74Schristos bfd_getb64, bfd_getb_signed_64, bfd_putb64, 14375fd0b74Schristos bfd_getb32, bfd_getb_signed_32, bfd_putb32, 14475fd0b74Schristos bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ 14575fd0b74Schristos bfd_getb64, bfd_getb_signed_64, bfd_putb64, 14675fd0b74Schristos bfd_getb32, bfd_getb_signed_32, bfd_putb32, 14775fd0b74Schristos bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */ 14875fd0b74Schristos #else 14975fd0b74Schristos bfd_getl64, bfd_getl_signed_64, bfd_putl64, 15075fd0b74Schristos bfd_getl32, bfd_getl_signed_32, bfd_putl32, 15175fd0b74Schristos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ 15275fd0b74Schristos bfd_getl64, bfd_getl_signed_64, bfd_putl64, 15375fd0b74Schristos bfd_getl32, bfd_getl_signed_32, bfd_putl32, 15475fd0b74Schristos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ 15575fd0b74Schristos #endif /* TARGET_BIG_ENDIAN */ 15675fd0b74Schristos 15775fd0b74Schristos { /* bfd_check_format. */ 15875fd0b74Schristos #if TARGET_ARCHIVE 15975fd0b74Schristos _bfd_dummy_target, 16075fd0b74Schristos _bfd_dummy_target, 16175fd0b74Schristos bfd_mach_o_archive_p, 16275fd0b74Schristos _bfd_dummy_target, 16375fd0b74Schristos #else 16475fd0b74Schristos _bfd_dummy_target, 16575fd0b74Schristos bfd_mach_o_object_p, 16675fd0b74Schristos bfd_generic_archive_p, 16775fd0b74Schristos bfd_mach_o_core_p 16875fd0b74Schristos #endif 16975fd0b74Schristos }, 17075fd0b74Schristos { /* bfd_set_format. */ 171ede78133Schristos _bfd_bool_bfd_false_error, 17275fd0b74Schristos bfd_mach_o_mkobject, 17375fd0b74Schristos _bfd_generic_mkarchive, 17475fd0b74Schristos bfd_mach_o_mkobject, 17575fd0b74Schristos }, 17675fd0b74Schristos { /* bfd_write_contents. */ 177ede78133Schristos _bfd_bool_bfd_false_error, 17875fd0b74Schristos bfd_mach_o_write_contents, 17975fd0b74Schristos _bfd_write_archive_contents, 18075fd0b74Schristos bfd_mach_o_write_contents, 18175fd0b74Schristos }, 18275fd0b74Schristos 18375fd0b74Schristos BFD_JUMP_TABLE_GENERIC (bfd_mach_o), 18475fd0b74Schristos BFD_JUMP_TABLE_COPY (bfd_mach_o), 18575fd0b74Schristos BFD_JUMP_TABLE_CORE (bfd_mach_o), 18675fd0b74Schristos #if TARGET_ARCHIVE 18775fd0b74Schristos BFD_JUMP_TABLE_ARCHIVE (bfd_mach_o), 18875fd0b74Schristos #else 18975fd0b74Schristos BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd44), 19075fd0b74Schristos #endif 19175fd0b74Schristos BFD_JUMP_TABLE_SYMBOLS (bfd_mach_o), 19275fd0b74Schristos BFD_JUMP_TABLE_RELOCS (bfd_mach_o), 19375fd0b74Schristos BFD_JUMP_TABLE_WRITE (bfd_mach_o), 19475fd0b74Schristos BFD_JUMP_TABLE_LINK (bfd_mach_o), 19575fd0b74Schristos BFD_JUMP_TABLE_DYNAMIC (bfd_mach_o), 19675fd0b74Schristos 19775fd0b74Schristos /* Alternative endian target. */ 19875fd0b74Schristos NULL, 19975fd0b74Schristos 20075fd0b74Schristos /* Back-end data. */ 20175fd0b74Schristos &TARGET_NAME_BACKEND 20275fd0b74Schristos }; 20375fd0b74Schristos 204