- /* check if both have a valid stub */
- if (bfd_coff_go32stub (ibfd) == NULL
- || bfd_coff_go32stub (obfd) == NULL)
- return true;
+ /* As adjust_filehdr_out_pre may get called only after this function,
+ optionally allocate the output stub. */
+ if (coff_data (obfd)->go32stub == NULL)
+ coff_data (obfd)->go32stub = bfd_alloc (obfd,
+ (bfd_size_type) GO32_STUBSIZE);
+
+ /* Now copy the stub. */
+ if (coff_data (obfd)->go32stub != NULL)
+ memcpy (coff_data (obfd)->go32stub, coff_data (ibfd)->go32stub,
+ GO32_STUBSIZE);
+
+ return TRUE;
+}
+
+/* coff_object_p only checks 2 bytes F_MAGIC at GO32_STUBSIZE inside the file
+ which is too fragile. */
+
+static const bfd_target *
+go32_check_format (bfd *abfd)
+{
+ char mz[2];
+
+ if (bfd_bread (mz, 2, abfd) != 2 || mz[0] != 'M' || mz[1] != 'Z')
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }