# This shell script emits C code -*- C -*-
# to keep track of the machine type of Z80 object files
# It does some substitutions.
-# Copyright (C) 2005-2015 Free Software Foundation, Inc.
+# Copyright (C) 2005-2021 Free Software Foundation, Inc.
# This file is part of the GNU Binutils.
#
# This program is free software; you can redistribute it and/or modify
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
-LDEMUL_BEFORE_PARSE=gldz80_before_parse
-LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file
-LDEMUL_AFTER_OPEN=gldz80_after_open
-
-fragment <<EOF
-/* --- \begin{z80.em} */
-/* Codes for machine types, bitwise or gives the code to use for the
- output. */
-#define M_Z80STRICT 1
-#define M_Z80 3
-#define M_Z80FULL 7
-#define M_R800 11
-#define M_Z80ANY 15
-
-/* Bitwise or of the machine types seen so far. */
-static int result_mach_type;
-
+if [ x"${EMULATION_NAME}" = x"elf32z80" ]; then
+ fragment <<EOF
+#include "elf/z80.h"
+EOF
+else
+ fragment <<EOF
static void
-${LDEMUL_BEFORE_PARSE} (void)
+gld${EMULATION_NAME}_after_open (void)
{
-#ifndef TARGET_ /* I.e., if not generic. */
- ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
-#endif /* not TARGET_ */
- result_mach_type = M_Z80STRICT;
}
+EOF
+fi
+fragment <<EOF
+/* --- \begin{z80.em} */
-/* Update result_mach_type. */
-static bfd_boolean
-${LDEMUL_RECOGNIZED_FILE} (lang_input_statement_type *entry)
-{
- unsigned long mach_type;
-
- mach_type = bfd_get_mach (entry->the_bfd);
- switch (mach_type)
- {
- case bfd_mach_z80strict:
- result_mach_type |= M_Z80STRICT;
- break;
- case bfd_mach_z80:
- result_mach_type |= M_Z80;
- break;
- case bfd_mach_z80full:
- result_mach_type |= M_Z80FULL;
- break;
- case bfd_mach_r800:
- result_mach_type |= M_R800;
- break;
- default:
- result_mach_type |= M_Z80ANY;
- }
- return FALSE;
-}
-
-/* Set the machine type of the output file based on result_mach_type. */
+/* Set the machine type of the output file based on types of inputs. */
static void
-gldz80_after_open (void)
+z80_after_open (void)
{
- unsigned long mach_type;
+ bfd *abfd;
- after_open_default ();
-
- switch (result_mach_type)
+ /* For now, make sure all object files are of the same architecture.
+ We may try to merge object files with different architecture together. */
+ for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
{
- case M_Z80STRICT:
- mach_type = bfd_mach_z80strict;
- break;
- case M_Z80:
- mach_type = bfd_mach_z80;
- break;
- case M_Z80FULL:
- mach_type = bfd_mach_z80full;
- break;
- case M_R800:
- mach_type = bfd_mach_r800;
- break;
- default:
- mach_type = 0;
+ const bfd_arch_info_type *info;
+ info = bfd_arch_get_compatible (link_info.output_bfd, abfd, FALSE);
+ if (info == NULL)
+ einfo (_("%F%P: %pB: Instruction sets of object files incompatible\n"),
+ abfd);
+ else
+ bfd_set_arch_info (link_info.output_bfd, info);
}
- bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach_type);
+
+ /* Call the standard elf routine. */
+ gld${EMULATION_NAME}_after_open ();
}
+
/* --- \end{z80.em} */
EOF
+
+LDEMUL_AFTER_OPEN=z80_after_open