+static bfd_boolean
+bfd_mach_o_write_dylinker (bfd *abfd, bfd_mach_o_load_command *command)
+{
+ bfd_mach_o_dylinker_command *cmd = &command->command.dylinker;
+ struct mach_o_str_command_external raw;
+ unsigned int namelen;
+
+ bfd_h_put_32 (abfd, cmd->name_offset, raw.str);
+
+ if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+ || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
+ return FALSE;
+
+ namelen = strlen (cmd->name_str) + 1;
+ if (bfd_bwrite (cmd->name_str, namelen, abfd) != namelen)
+ return FALSE;
+
+ if (bfd_mach_o_pad_command (abfd, namelen) < 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static bfd_boolean
+bfd_mach_o_write_dylib (bfd *abfd, bfd_mach_o_load_command *command)
+{
+ bfd_mach_o_dylib_command *cmd = &command->command.dylib;
+ struct mach_o_dylib_command_external raw;
+ unsigned int namelen;
+
+ bfd_h_put_32 (abfd, cmd->name_offset, raw.name);
+ bfd_h_put_32 (abfd, cmd->timestamp, raw.timestamp);
+ bfd_h_put_32 (abfd, cmd->current_version, raw.current_version);
+ bfd_h_put_32 (abfd, cmd->compatibility_version, raw.compatibility_version);
+
+ if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+ || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
+ return FALSE;
+
+ namelen = strlen (cmd->name_str) + 1;
+ if (bfd_bwrite (cmd->name_str, namelen, abfd) != namelen)
+ return FALSE;
+
+ if (bfd_mach_o_pad_command (abfd, namelen) < 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static bfd_boolean
+bfd_mach_o_write_main (bfd *abfd, bfd_mach_o_load_command *command)
+{
+ bfd_mach_o_main_command *cmd = &command->command.main;
+ struct mach_o_entry_point_command_external raw;
+
+ bfd_h_put_64 (abfd, cmd->entryoff, raw.entryoff);
+ bfd_h_put_64 (abfd, cmd->stacksize, raw.stacksize);
+
+ if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+ || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
+ return FALSE;
+
+ return TRUE;
+}
+
+static bfd_boolean
+bfd_mach_o_write_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
+{
+ bfd_mach_o_dyld_info_command *cmd = &command->command.dyld_info;
+ struct mach_o_dyld_info_command_external raw;
+
+ bfd_h_put_32 (abfd, cmd->rebase_off, raw.rebase_off);
+ bfd_h_put_32 (abfd, cmd->rebase_size, raw.rebase_size);
+ bfd_h_put_32 (abfd, cmd->bind_off, raw.bind_off);
+ bfd_h_put_32 (abfd, cmd->bind_size, raw.bind_size);
+ bfd_h_put_32 (abfd, cmd->weak_bind_off, raw.weak_bind_off);
+ bfd_h_put_32 (abfd, cmd->weak_bind_size, raw.weak_bind_size);
+ bfd_h_put_32 (abfd, cmd->lazy_bind_off, raw.lazy_bind_off);
+ bfd_h_put_32 (abfd, cmd->lazy_bind_size, raw.lazy_bind_size);
+ bfd_h_put_32 (abfd, cmd->export_off, raw.export_off);
+ bfd_h_put_32 (abfd, cmd->export_size, raw.export_size);
+
+ if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+ || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
+ return FALSE;
+
+ if (cmd->rebase_size != 0)
+ if (bfd_seek (abfd, cmd->rebase_off, SEEK_SET) != 0
+ || (bfd_bwrite (cmd->rebase_content, cmd->rebase_size, abfd) !=
+ cmd->rebase_size))
+ return FALSE;
+
+ if (cmd->bind_size != 0)
+ if (bfd_seek (abfd, cmd->bind_off, SEEK_SET) != 0
+ || (bfd_bwrite (cmd->bind_content, cmd->bind_size, abfd) !=
+ cmd->bind_size))
+ return FALSE;
+
+ if (cmd->weak_bind_size != 0)
+ if (bfd_seek (abfd, cmd->weak_bind_off, SEEK_SET) != 0
+ || (bfd_bwrite (cmd->weak_bind_content, cmd->weak_bind_size, abfd) !=
+ cmd->weak_bind_size))
+ return FALSE;
+
+ if (cmd->lazy_bind_size != 0)
+ if (bfd_seek (abfd, cmd->lazy_bind_off, SEEK_SET) != 0
+ || (bfd_bwrite (cmd->lazy_bind_content, cmd->lazy_bind_size, abfd) !=
+ cmd->lazy_bind_size))
+ return FALSE;
+
+ if (cmd->export_size != 0)
+ if (bfd_seek (abfd, cmd->export_off, SEEK_SET) != 0
+ || (bfd_bwrite (cmd->export_content, cmd->export_size, abfd) !=
+ cmd->export_size))
+ return FALSE;
+
+ return TRUE;
+}
+