}
static bfd_boolean
-bfd_mach_o_read_header (bfd *abfd, bfd_mach_o_header *header)
+bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
{
struct mach_o_header_external raw;
unsigned int size;
bfd_vma (*get32) (const void *) = NULL;
/* Just read the magic number. */
- if (bfd_seek (abfd, 0, SEEK_SET) != 0
+ if (bfd_seek (abfd, hdr_off, SEEK_SET) != 0
|| bfd_bread (raw.magic, sizeof (raw.magic), abfd) != 4)
return FALSE;
size = mach_o_wide_p (header) ?
BFD_MACH_O_HEADER_64_SIZE : BFD_MACH_O_HEADER_SIZE;
- if (bfd_seek (abfd, 0, SEEK_SET) != 0
+ if (bfd_seek (abfd, hdr_off, SEEK_SET) != 0
|| bfd_bread (&raw, size, abfd) != size)
return FALSE;
}
static asection *
-bfd_mach_o_read_section_32 (bfd *abfd,
- unsigned int offset,
- unsigned long prot)
+bfd_mach_o_read_section_32 (bfd *abfd, unsigned long prot)
{
struct mach_o_section_32_external raw;
asection *sec;
bfd_mach_o_section *section;
- if (bfd_seek (abfd, offset, SEEK_SET) != 0
- || (bfd_bread (&raw, BFD_MACH_O_SECTION_SIZE, abfd)
- != BFD_MACH_O_SECTION_SIZE))
+ if (bfd_bread (&raw, BFD_MACH_O_SECTION_SIZE, abfd)
+ != BFD_MACH_O_SECTION_SIZE)
return NULL;
sec = bfd_mach_o_make_bfd_section (abfd, raw.segname, raw.sectname);
}
static asection *
-bfd_mach_o_read_section_64 (bfd *abfd,
- unsigned int offset,
- unsigned long prot)
+bfd_mach_o_read_section_64 (bfd *abfd, unsigned long prot)
{
struct mach_o_section_64_external raw;
asection *sec;
bfd_mach_o_section *section;
- if (bfd_seek (abfd, offset, SEEK_SET) != 0
- || (bfd_bread (&raw, BFD_MACH_O_SECTION_64_SIZE, abfd)
- != BFD_MACH_O_SECTION_64_SIZE))
+ if (bfd_bread (&raw, BFD_MACH_O_SECTION_64_SIZE, abfd)
+ != BFD_MACH_O_SECTION_64_SIZE)
return NULL;
sec = bfd_mach_o_make_bfd_section (abfd, raw.segname, raw.sectname);
}
static asection *
-bfd_mach_o_read_section (bfd *abfd,
- unsigned int offset,
- unsigned long prot,
- unsigned int wide)
+bfd_mach_o_read_section (bfd *abfd, unsigned long prot, unsigned int wide)
{
if (wide)
- return bfd_mach_o_read_section_64 (abfd, offset, prot);
+ return bfd_mach_o_read_section_64 (abfd, prot);
else
- return bfd_mach_o_read_section_32 (abfd, offset, prot);
+ return bfd_mach_o_read_section_32 (abfd, prot);
}
static bfd_boolean
unsigned int nameoff;
unsigned int namelen;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
nameoff = bfd_h_get_32 (abfd, raw.str);
static bfd_boolean
bfd_mach_o_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
{
+ bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
bfd_mach_o_dylib_command *cmd = &command->command.dylib;
struct mach_o_dylib_command_external raw;
unsigned int nameoff;
return FALSE;
}
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
nameoff = bfd_h_get_32 (abfd, raw.name);
cmd->name_str = bfd_alloc (abfd, namelen);
if (cmd->name_str == NULL)
return FALSE;
- if (bfd_seek (abfd, cmd->name_offset, SEEK_SET) != 0
+ if (bfd_seek (abfd, mdata->hdr_offset + cmd->name_offset, SEEK_SET) != 0
|| bfd_bread (cmd->name_str, namelen, abfd) != namelen)
return FALSE;
return TRUE;
unsigned int str_len;
unsigned char *str;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
nameoff = bfd_h_get_32 (abfd, raw.name);
bfd_mach_o_prebind_cksum_command *cmd = &command->command.prebind_cksum;
struct mach_o_prebind_cksum_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->cksum = bfd_get_32 (abfd, raw.cksum);
bfd_mach_o_twolevel_hints_command *cmd = &command->command.twolevel_hints;
struct mach_o_twolevel_hints_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->offset = bfd_get_32 (abfd, raw.offset);
unsigned int nameoff;
unsigned int namelen;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
nameoff = bfd_h_get_32 (abfd, raw.name);
{
struct mach_o_dysymtab_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->ilocalsym = bfd_h_get_32 (abfd, raw.ilocalsym);
BFD_ASSERT (command->type == BFD_MACH_O_LC_SYMTAB);
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
symtab->symoff = bfd_h_get_32 (abfd, raw.symoff);
BFD_ASSERT (command->type == BFD_MACH_O_LC_UUID);
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (cmd->uuid, 16, abfd) != 16)
+ if (bfd_bread (cmd->uuid, 16, abfd) != 16)
return FALSE;
return TRUE;
bfd_mach_o_linkedit_command *cmd = &command->command.linkedit;
struct mach_o_linkedit_data_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->dataoff = bfd_get_32 (abfd, raw.dataoff);
struct mach_o_str_command_external raw;
unsigned long off;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
off = bfd_get_32 (abfd, raw.str);
bfd_mach_o_dyld_info_command *cmd = &command->command.dyld_info;
struct mach_o_dyld_info_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->rebase_off = bfd_get_32 (abfd, raw.rebase_off);
struct mach_o_version_min_command_external raw;
unsigned int ver;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
ver = bfd_get_32 (abfd, raw.version);
bfd_mach_o_encryption_info_command *cmd = &command->command.encryption_info;
struct mach_o_encryption_info_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ return FALSE;
+
+ cmd->cryptoff = bfd_get_32 (abfd, raw.cryptoff);
+ cmd->cryptsize = bfd_get_32 (abfd, raw.cryptsize);
+ cmd->cryptid = bfd_get_32 (abfd, raw.cryptid);
+ return TRUE;
+}
+
+static bfd_boolean
+bfd_mach_o_read_encryption_info_64 (bfd *abfd, bfd_mach_o_load_command *command)
+{
+ bfd_mach_o_encryption_info_command *cmd = &command->command.encryption_info;
+ struct mach_o_encryption_info_64_command_external raw;
+
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->cryptoff = bfd_get_32 (abfd, raw.cryptoff);
bfd_mach_o_main_command *cmd = &command->command.main;
struct mach_o_entry_point_command_external raw;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
cmd->entryoff = bfd_get_64 (abfd, raw.entryoff);
struct mach_o_source_version_command_external raw;
bfd_uint64_t ver;
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
ver = bfd_get_64 (abfd, raw.version);
BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT_64);
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
memcpy (seg->segname, raw.segname, 16);
BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT);
- if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
- || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+ if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
memcpy (seg->segname, raw.segname, 16);
for (i = 0; i < seg->nsects; i++)
{
- bfd_vma segoff;
asection *sec;
- if (wide)
- segoff = command->offset + BFD_MACH_O_LC_SEGMENT_64_SIZE
- + (i * BFD_MACH_O_SECTION_64_SIZE);
- else
- segoff = command->offset + BFD_MACH_O_LC_SEGMENT_SIZE
- + (i * BFD_MACH_O_SECTION_SIZE);
-
- sec = bfd_mach_o_read_section (abfd, segoff, seg->initprot, wide);
+ sec = bfd_mach_o_read_section (abfd, seg->initprot, wide);
if (sec == NULL)
return FALSE;
static bfd_boolean
bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command)
{
+ bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
struct mach_o_load_command_external raw;
unsigned int cmd;
/* Read command type and length. */
- if (bfd_seek (abfd, command->offset, SEEK_SET) != 0
+ if (bfd_seek (abfd, mdata->hdr_offset + command->offset, SEEK_SET) != 0
|| bfd_bread (&raw, BFD_MACH_O_LC_SIZE, abfd) != BFD_MACH_O_LC_SIZE)
return FALSE;
case BFD_MACH_O_LC_FUNCTION_STARTS:
case BFD_MACH_O_LC_DATA_IN_CODE:
case BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS:
+ case BFD_MACH_O_LC_LINKER_OPTIMIZATION_HINT:
if (!bfd_mach_o_read_linkedit (abfd, command))
return FALSE;
break;
if (!bfd_mach_o_read_encryption_info (abfd, command))
return FALSE;
break;
+ case BFD_MACH_O_LC_ENCRYPTION_INFO_64:
+ if (!bfd_mach_o_read_encryption_info_64 (abfd, command))
+ return FALSE;
+ break;
case BFD_MACH_O_LC_DYLD_INFO:
if (!bfd_mach_o_read_dyld_info (abfd, command))
return FALSE;
break;
case BFD_MACH_O_LC_VERSION_MIN_MACOSX:
case BFD_MACH_O_LC_VERSION_MIN_IPHONEOS:
+ case BFD_MACH_O_LC_VERSION_MIN_WATCHOS:
if (!bfd_mach_o_read_version_min (abfd, command))
return FALSE;
break;
const bfd_target *
bfd_mach_o_header_p (bfd *abfd,
+ file_ptr hdr_off,
bfd_mach_o_filetype filetype,
bfd_mach_o_cpu_type cputype)
{
bfd_mach_o_header header;
bfd_mach_o_data_struct *mdata;
- if (!bfd_mach_o_read_header (abfd, &header))
+ if (!bfd_mach_o_read_header (abfd, hdr_off, &header))
goto wrong;
if (! (header.byteorder == BFD_ENDIAN_BIG
mdata = (bfd_mach_o_data_struct *) bfd_zalloc (abfd, sizeof (*mdata));
if (mdata == NULL)
goto fail;
+ mdata->hdr_offset = hdr_off;
if (!bfd_mach_o_scan (abfd, &header, mdata))
goto wrong;
static const bfd_target *
bfd_mach_o_gen_object_p (bfd *abfd)
{
- return bfd_mach_o_header_p (abfd, 0, 0);
+ return bfd_mach_o_header_p (abfd, 0, 0, 0);
}
static const bfd_target *
bfd_mach_o_gen_core_p (bfd *abfd)
{
- return bfd_mach_o_header_p (abfd, BFD_MACH_O_MH_CORE, 0);
+ return bfd_mach_o_header_p (abfd, 0, BFD_MACH_O_MH_CORE, 0);
}
/* Return the base address of ABFD, ie the address at which the image is
} mach_o_fat_data_struct;
const bfd_target *
-bfd_mach_o_archive_p (bfd *abfd)
+bfd_mach_o_fat_archive_p (bfd *abfd)
{
mach_o_fat_data_struct *adata = NULL;
struct mach_o_fat_header_external hdr;
}
bfd *
-bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
+bfd_mach_o_fat_openr_next_archived_file (bfd *archive, bfd *prev)
{
mach_o_fat_data_struct *adata;
mach_o_fat_archentry *entry = NULL;
}
}
- if (bfd_get_format (abfd) == bfd_archive
- && abfd->xvec == &mach_o_fat_vec)
- return TRUE;
return _bfd_generic_close_and_cleanup (abfd);
}
/* Not yet handled: creating an archive. */
#define bfd_mach_o_mkarchive _bfd_noarchive_mkarchive
+#define bfd_mach_o_close_and_cleanup bfd_true
+
/* Not used. */
-#define bfd_mach_o_read_ar_hdr _bfd_noarchive_read_ar_hdr
-#define bfd_mach_o_write_ar_hdr _bfd_noarchive_write_ar_hdr
-#define bfd_mach_o_slurp_armap _bfd_noarchive_slurp_armap
-#define bfd_mach_o_slurp_extended_name_table _bfd_noarchive_slurp_extended_name_table
-#define bfd_mach_o_construct_extended_name_table _bfd_noarchive_construct_extended_name_table
-#define bfd_mach_o_truncate_arname _bfd_noarchive_truncate_arname
-#define bfd_mach_o_write_armap _bfd_noarchive_write_armap
-#define bfd_mach_o_get_elt_at_index _bfd_noarchive_get_elt_at_index
#define bfd_mach_o_generic_stat_arch_elt bfd_mach_o_fat_stat_arch_elt
-#define bfd_mach_o_update_armap_timestamp _bfd_noarchive_update_armap_timestamp
+#define bfd_mach_o_openr_next_archived_file bfd_mach_o_fat_openr_next_archived_file
+#define bfd_mach_o_archive_p bfd_mach_o_fat_archive_p
#define TARGET_NAME mach_o_fat_vec
#define TARGET_STRING "mach-o-fat"