/* BFD back-end for Intel 386 COFF files (DJGPP variant with a stub).
- Copyright (C) 1997-2020 Free Software Foundation, Inc.
+ Copyright (C) 1997-2023 Free Software Foundation, Inc.
Written by Robert Hoehne.
This file is part of BFD, the Binary File Descriptor library.
{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
+/* Section contains extended relocations. */
+#define IMAGE_SCN_LNK_NRELOC_OVFL (0x01000000)
+
#include "sysdep.h"
#include "bfd.h"
#include "coff/msdos.h"
static bfd_cleanup go32exe_check_format (bfd *);
-static bfd_boolean go32exe_write_object_contents (bfd *);
-static bfd_boolean go32exe_mkobject (bfd *);
-static bfd_boolean go32exe_copy_private_bfd_data (bfd *, bfd *);
+static bool go32exe_write_object_contents (bfd *);
+static bool go32exe_mkobject (bfd *);
+static bool go32exe_copy_private_bfd_data (bfd *, bfd *);
+
+/* Defined in coff-go32.c. */
+bool _bfd_go32_mkobject (bfd *);
+void _bfd_go32_swap_scnhdr_in (bfd *, void *, void *);
+unsigned int _bfd_go32_swap_scnhdr_out (bfd *, void *, void *);
#define COFF_CHECK_FORMAT go32exe_check_format
#define COFF_WRITE_CONTENTS go32exe_write_object_contents
#define coff_mkobject go32exe_mkobject
#define coff_bfd_copy_private_bfd_data go32exe_copy_private_bfd_data
+#define coff_SWAP_scnhdr_in _bfd_go32_swap_scnhdr_in
+#define coff_SWAP_scnhdr_out _bfd_go32_swap_scnhdr_out
#include "coff-i386.c"
close (f);
goto stub_end;
}
- if (! CONST_STRNEQ (magic, "go32stub"))
+ if (! startswith (magic, "go32stub"))
{
close (f);
goto stub_end;
/* If ibfd was a stubbed coff image, copy the stub from that bfd
to the new obfd. */
-static bfd_boolean
+static bool
go32exe_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
{
/* Check if both are the same targets. */
if (ibfd->xvec != obfd->xvec)
- return TRUE;
+ return true;
/* Make sure we have a source stub. */
BFD_ASSERT (coff_data (ibfd)->stub != NULL);
if (coff_data (ibfd)->stub_size > coff_data (obfd)->stub_size)
coff_data (obfd)->stub = bfd_alloc (obfd, coff_data (ibfd)->stub_size);
if (coff_data (obfd)->stub == NULL)
- return FALSE;
+ return false;
/* Now copy the stub. */
memcpy (coff_data (obfd)->stub, coff_data (ibfd)->stub,
coff_data (obfd)->stub_size = coff_data (ibfd)->stub_size;
obfd->origin = coff_data (obfd)->stub_size;
- return TRUE;
+ return true;
}
/* Cleanup function, returned from check_format hook. */
{
abfd->origin = 0;
- if (go32exe_temp_stub != NULL)
- free (go32exe_temp_stub);
+ free (go32exe_temp_stub);
go32exe_temp_stub = NULL;
go32exe_temp_stub_size = 0;
}
if (last_page_size != 0)
stubsize += last_page_size - 512;
+ ufile_ptr filesize = bfd_get_file_size (abfd);
+ if (filesize != 0 && stubsize > filesize)
+ goto fail_format;
+
/* Save now the stub to be used later. Put the stub data to a temporary
location first as tdata still does not exist. It may not even
be ever created if we are just checking the file format of ABFD. */
/* Confirm that this is a go32stub. */
header_end = H_GET_16 (abfd, filehdr_dos.e_cparhdr) * 16UL;
- if (! CONST_STRNEQ (go32exe_temp_stub + header_end, "go32stub"))
+ if (go32exe_temp_stub_size < header_end
+ || go32exe_temp_stub_size - header_end < sizeof "go32stub" - 1
+ || !startswith (go32exe_temp_stub + header_end, "go32stub"))
goto fail_format;
/* Set origin to where the COFF header starts and seek there. */
/* Write the stub to the output file, then call coff_write_object_contents. */
-static bfd_boolean
+static bool
go32exe_write_object_contents (bfd *abfd)
{
const bfd_size_type pos = bfd_tell (abfd);
/* Write the stub. */
abfd->origin = 0;
if (bfd_seek (abfd, 0, SEEK_SET) != 0)
- return FALSE;
+ return false;
if (bfd_bwrite (coff_data (abfd)->stub, stubsize, abfd) != stubsize)
- return FALSE;
+ return false;
/* Seek back to where we were. */
abfd->origin = stubsize;
if (bfd_seek (abfd, pos, SEEK_SET) != 0)
- return FALSE;
+ return false;
return coff_write_object_contents (abfd);
}
/* mkobject hook. Called directly through bfd_set_format or via
coff_mkobject_hook etc from bfd_check_format. */
-static bfd_boolean
+static bool
go32exe_mkobject (bfd *abfd)
{
- coff_data_type *coff = NULL;
- const bfd_size_type amt = sizeof (coff_data_type);
-
/* Don't output to an archive. */
if (abfd->my_archive != NULL)
- return FALSE;
-
- abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
- if (abfd->tdata.coff_obj_data == NULL)
- return FALSE;
- coff = coff_data (abfd);
- coff->symbols = NULL;
- coff->conversion_table = NULL;
- coff->raw_syments = NULL;
- coff->relocbase = 0;
- coff->local_toc_sym_map = 0;
+ return false;
+
+ if (!_bfd_go32_mkobject (abfd))
+ return false;
go32exe_create_stub (abfd);
- if (coff->stub == NULL)
+ if (coff_data (abfd)->stub == NULL)
{
- bfd_release (abfd, coff);
- return FALSE;
+ bfd_release (abfd, coff_data (abfd));
+ return false;
}
- abfd->origin = coff->stub_size;
-
-/* make_abs_section(abfd);*/ /* ??? */
+ abfd->origin = coff_data (abfd)->stub_size;
- return TRUE;
+ return true;
}