This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

MMIX port, part 6/10: bfd except doc.


Ok to commit?

Part 6/10, bfd subdirectory except doc:

	* Makefile.am (ALL_MACHINES): Add cpu-mmix.lo.
	(BFD64_BACKENDS): Add elf64-mmix.lo and mmo.lo.
	(BFD64_BACKENDS_CFILES): Add elf64-mmix.c and mmo.c.
	Regenerate dependencies.
	* configure.in (bfd_elf64_mmix_vec, bfd_mmo_vec): New vectors.
	* config.bfd: [BFD64] (mmix-*-*): New case.
	* cpu-mmix.c, mmo.c, elf64-mmix.c: New files.
	* archures.c (enum bfd_architecture): Add bfd_arch_mmix.
	(bfd_mmix_arch): Declare.
	(bfd_archures_list): Add bfd_mmix_arch.
	* targets.c (enum bfd_flavour): Add bfd_target_mmo_flavour.
	(bfd_elf64_mmix_vec, bfd_mmo_vec): Declare.
	(bfd_target_vect) [BFD64]: Add bfd_elf64_mmix_vec and
	bfd_mmo_mmix_vec.
	* reloc.c: Add MMIX relocations.
	* bfd.c (struct _bfd, tdata): Add mmo_data.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
	* configure: Rebuild.

Index: Makefile.am
===================================================================
RCS file: /cvs/src/src/bfd/Makefile.am,v
retrieving revision 1.63
diff -p -c -r1.63 Makefile.am
*** Makefile.am	2001/09/21 02:12:28	1.63
--- Makefile.am	2001/09/30 20:51:51
*************** ALL_MACHINES = \
*** 68,73 ****
--- 68,74 ----
  	cpu-m10300.lo \
  	cpu-mcore.lo \
  	cpu-mips.lo \
+ 	cpu-mmix.lo \
  	cpu-ns32k.lo \
  	cpu-openrisc.lo \
  	cpu-pdp11.lo \
*************** ALL_MACHINES_CFILES = \
*** 113,118 ****
--- 114,120 ----
  	cpu-m10300.c \
  	cpu-mcore.c \
  	cpu-mips.c \
+ 	cpu-mmix.c \
  	cpu-ns32k.c \
  	cpu-openrisc.c \
  	cpu-pdp11.c \
*************** BFD64_BACKENDS = \
*** 428,437 ****
--- 430,441 ----
  	elf64-ia64.lo \
  	elf64-gen.lo \
  	elf64-mips.lo \
+ 	elf64-mmix.lo \
  	elf64-ppc.lo \
  	elf64-s390.lo \
  	elf64-sparc.lo \
  	elf64.lo \
+ 	mmo.lo \
  	nlm32-alpha.lo \
  	nlm64.lo \
  	pepigen.lo
*************** BFD64_BACKENDS_CFILES = \
*** 447,456 ****
--- 451,462 ----
  	elf64-hppa.c \
  	elf64-gen.c \
  	elf64-mips.c \
+ 	elf64-mmix.c \
  	elf64-ppc.c \
  	elf64-s390.c \
  	elf64-sparc.c \
  	elf64.c \
+ 	mmo.c \
  	nlm32-alpha.c \
  	nlm64.c

*************** cpu-m10200.lo: cpu-m10200.c $(INCDIR)/fi
*** 821,826 ****
--- 827,833 ----
  cpu-m10300.lo: cpu-m10300.c $(INCDIR)/filenames.h
  cpu-mcore.lo: cpu-mcore.c $(INCDIR)/filenames.h
  cpu-mips.lo: cpu-mips.c $(INCDIR)/filenames.h
+ cpu-mmix.lo: cpu-mmix.c $(INCDIR)/filenames.h
  cpu-ns32k.lo: cpu-ns32k.c $(INCDIR)/filenames.h ns32k.h
  cpu-openrisc.lo: cpu-openrisc.c $(INCDIR)/filenames.h
  cpu-pdp11.lo: cpu-pdp11.c $(INCDIR)/filenames.h
*************** elf64-mips.lo: elf64-mips.c $(INCDIR)/fi
*** 1343,1348 ****
--- 1350,1359 ----
    $(INCDIR)/elf/reloc-macros.h $(INCDIR)/coff/sym.h $(INCDIR)/coff/symconst.h \
    $(INCDIR)/coff/internal.h $(INCDIR)/coff/ecoff.h $(INCDIR)/coff/alpha.h \
    ecoffswap.h elf64-target.h
+ elf64-mmix.lo: elf64-mmix.c $(INCDIR)/filenames.h elf-bfd.h \
+   $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
+   $(INCDIR)/bfdlink.h $(INCDIR)/elf/mmix.h $(INCDIR)/elf/reloc-macros.h \
+   $(INCDIR)/opcode/mmix.h elf64-target.h
  elf64-ppc.lo: elf64-ppc.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \
    elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \
    $(INCDIR)/elf/external.h $(INCDIR)/elf/ppc.h $(INCDIR)/elf/reloc-macros.h \
*************** elf64.lo: elf64.c elfcode.h $(INCDIR)/fi
*** 1360,1365 ****
--- 1371,1378 ----
    $(INCDIR)/bfdlink.h elf-bfd.h $(INCDIR)/elf/common.h \
    $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h elfcore.h \
    elflink.h
+ mmo.lo: mmo.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h \
+   $(INCDIR)/elf/mmix.h $(INCDIR)/elf/reloc-macros.h $(INCDIR)/opcode/mmix.h
  nlm32-alpha.lo: nlm32-alpha.c $(INCDIR)/filenames.h \
    $(INCDIR)/nlm/alpha-ext.h libnlm.h $(INCDIR)/nlm/common.h \
    $(INCDIR)/nlm/internal.h $(INCDIR)/nlm/external.h nlmswap.h \
Index: archures.c
===================================================================
RCS file: /cvs/src/src/bfd/archures.c,v
retrieving revision 1.39
diff -p -c -r1.39 archures.c
*** archures.c	2001/09/19 05:33:12	1.39
--- archures.c	2001/09/30 20:51:55
*************** DESCRIPTION
*** 258,263 ****
--- 258,264 ----
  .#define bfd_mach_s390_esa      0
  .#define bfd_mach_s390_esame    1
  .  bfd_arch_openrisc,  {* OpenRISC *}
+ .  bfd_arch_mmix,      {* Donald Knuth's educational processor *}
  .  bfd_arch_last
  .  };
  */
*************** extern const bfd_arch_info_type bfd_avr_
*** 336,341 ****
--- 337,343 ----
  extern const bfd_arch_info_type bfd_ia64_arch;
  extern const bfd_arch_info_type bfd_s390_arch;
  extern const bfd_arch_info_type bfd_openrisc_arch;
+ extern const bfd_arch_info_type bfd_mmix_arch;

  static const bfd_arch_info_type * const bfd_archures_list[] = {
  #ifdef SELECT_ARCHITECTURES
*************** static const bfd_arch_info_type * const
*** 383,388 ****
--- 385,391 ----
    &bfd_ia64_arch,
    &bfd_s390_arch,
    &bfd_openrisc_arch,
+   &bfd_mmix_arch,
  #endif
    0
  };
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.25
diff -p -c -r1.25 bfd.c
*** bfd.c	2001/09/26 01:53:25	1.25
--- bfd.c	2001/09/30 20:52:01
*************** CODE_FRAGMENT
*** 167,172 ****
--- 167,173 ----
  .      struct elf_obj_tdata *elf_obj_data;
  .      struct nlm_obj_tdata *nlm_obj_data;
  .      struct bout_data_struct *bout_data;
+ .      struct mmo_data_struct *mmo_data;
  .      struct sun_core_struct *sun_core_data;
  .      struct sco5_core_struct *sco5_core_data;
  .      struct trad_core_struct *trad_core_data;
Index: config.bfd
===================================================================
RCS file: /cvs/src/src/bfd/config.bfd,v
retrieving revision 1.68
diff -p -c -r1.68 config.bfd
*** config.bfd	2001/09/14 11:46:39	1.68
--- config.bfd	2001/09/30 20:52:01
*************** case "${targ}" in
*** 706,711 ****
--- 706,717 ----
      targ_defvec=bfd_elf32_tradbigmips_vec
      targ_selvecs="bfd_elf32_tradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec ecoff_big_vec ecoff_little_vec"
      ;;
+ #ifdef BFD64
+   mmix-*-*)
+     targ_defvec=bfd_elf64_mmix_vec
+     targ_selvecs=bfd_mmo_vec
+     ;;
+ #endif
    mn10200-*-*)
      targ_defvec=bfd_elf32_mn10200_vec
      ;;
Index: configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.59
diff -p -c -r1.59 configure.in
*** configure.in	2001/09/29 12:07:00	1.59
--- configure.in	2001/09/30 20:52:19
*************** do
*** 553,558 ****
--- 553,559 ----
      bfd_elf64_ia64_little_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
      bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
      bfd_elf64_littlemips_vec) 	tb="$tb elf64-mips.lo elf64.lo elf32-mips.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
+     bfd_elf64_mmix_vec) 	tb="$tb elf64-mmix.lo elf64.lo $elf" target_size=64 ;;
      bfd_elf64_powerpc_vec)	tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
      bfd_elf64_powerpcle_vec)	tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf" target_size=64 ;;
      bfd_elf64_s390_vec)		tb="$tb elf64-s390.lo elf64.lo $elf"; target_size=64 ;;
*************** do
*** 560,565 ****
--- 561,567 ----
      bfd_elf64_tradbigmips_vec)	tb="$tb elf64-mips.lo elf64.lo $elf ecofflink.lo"; target_size=64 ;;
      bfd_elf64_tradlittlemips_vec) tb="$tb elf64-mips.lo elf64.lo $elf ecofflink.lo"; target_size=64 ;;
      bfd_elf64_x86_64_vec)	tb="$tb elf64-x86-64.lo elf64.lo $elf"; target_size=64 ;;
+     bfd_mmo_vec)		tb="$tb mmo.lo" target_size=64 ;;
      bfd_powerpc_pe_vec)         tb="$tb pe-ppc.lo peigen.lo cofflink.lo" ;;
      bfd_powerpc_pei_vec)        tb="$tb pei-ppc.lo peigen.lo cofflink.lo" ;;
      bfd_powerpcle_pe_vec)       tb="$tb pe-ppc.lo peigen.lo cofflink.lo" ;;
Index: reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.47
diff -p -c -r1.47 reloc.c
*** reloc.c	2001/09/18 09:57:26	1.47
--- reloc.c	2001/09/30 20:52:25
*************** ENUMDOC
*** 2723,2728 ****
--- 2723,2800 ----
    Motorola Mcore relocations.

  ENUM
+   BFD_RELOC_MMIX_GETA
+ ENUMX
+   BFD_RELOC_MMIX_GETA_1
+ ENUMX
+   BFD_RELOC_MMIX_GETA_2
+ ENUMX
+   BFD_RELOC_MMIX_GETA_3
+ ENUMDOC
+   These are relocations for the GETA instruction.
+ ENUM
+   BFD_RELOC_MMIX_CBRANCH
+ ENUMX
+   BFD_RELOC_MMIX_CBRANCH_J
+ ENUMX
+   BFD_RELOC_MMIX_CBRANCH_1
+ ENUMX
+   BFD_RELOC_MMIX_CBRANCH_2
+ ENUMX
+   BFD_RELOC_MMIX_CBRANCH_3
+ ENUMDOC
+   These are relocations for a conditional branch instruction.
+ ENUM
+   BFD_RELOC_MMIX_PUSHJ
+ ENUMX
+   BFD_RELOC_MMIX_PUSHJ_1
+ ENUMX
+   BFD_RELOC_MMIX_PUSHJ_2
+ ENUMX
+   BFD_RELOC_MMIX_PUSHJ_3
+ ENUMDOC
+   These are relocations for the PUSHJ instruction.
+ ENUM
+   BFD_RELOC_MMIX_JMP
+ ENUMX
+   BFD_RELOC_MMIX_JMP_1
+ ENUMX
+   BFD_RELOC_MMIX_JMP_2
+ ENUMX
+   BFD_RELOC_MMIX_JMP_3
+ ENUMDOC
+   These are relocations for the JMP instruction.
+ ENUM
+   BFD_RELOC_MMIX_ADDR19
+ ENUMDOC
+   This is a relocation for a relative address as in a GETA instruction or
+   a branch.
+ ENUM
+   BFD_RELOC_MMIX_ADDR27
+ ENUMDOC
+   This is a relocation for a relative address as in a JMP instruction.
+ ENUM
+   BFD_RELOC_MMIX_REG_OR_BYTE
+ ENUMDOC
+   This is a relocation for an instruction field that may be a general
+   register or a value 0..255.
+ ENUM
+   BFD_RELOC_MMIX_REG
+ ENUMDOC
+   This is a relocation for an instruction field that may be a general
+   register.
+ ENUM
+   BFD_RELOC_MMIX_BASE_PLUS_OFFSET
+ ENUMDOC
+   This is a relocation for two instruction fields holding a register and
+   an offset, the equivalent of the relocation.
+ ENUM
+   BFD_RELOC_MMIX_LOCAL
+ ENUMDOC
+   This relocation is an assertion that the expression is not allocated as
+   a global register.  It does not modify contents.
+
+ ENUM
    BFD_RELOC_AVR_7_PCREL
  ENUMDOC
    This is a 16 bit reloc for the AVR that stores 8 bit pc relative
Index: targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.46
diff -p -c -r1.46 targets.c
*** targets.c	2001/09/18 09:57:26	1.46
--- targets.c	2001/09/30 20:52:28
*************** DESCRIPTION
*** 153,159 ****
  .  bfd_target_versados_flavour,
  .  bfd_target_msdos_flavour,
  .  bfd_target_ovax_flavour,
! .  bfd_target_evax_flavour
  .};
  .
  .enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
--- 153,160 ----
  .  bfd_target_versados_flavour,
  .  bfd_target_msdos_flavour,
  .  bfd_target_ovax_flavour,
! .  bfd_target_evax_flavour,
! .  bfd_target_mmo_flavour
  .};
  .
  .enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
*************** extern const bfd_target bfd_elf64_ia64_b
*** 561,566 ****
--- 562,568 ----
  extern const bfd_target bfd_elf64_ia64_little_vec;
  extern const bfd_target bfd_elf64_little_generic_vec;
  extern const bfd_target bfd_elf64_littlemips_vec;
+ extern const bfd_target bfd_elf64_mmix_vec;
  extern const bfd_target bfd_elf64_powerpc_vec;
  extern const bfd_target bfd_elf64_powerpcle_vec;
  extern const bfd_target bfd_elf64_s390_vec;
*************** extern const bfd_target bfd_elf64_sparc_
*** 568,573 ****
--- 570,576 ----
  extern const bfd_target bfd_elf64_tradbigmips_vec;
  extern const bfd_target bfd_elf64_tradlittlemips_vec;
  extern const bfd_target bfd_elf64_x86_64_vec;
+ extern const bfd_target bfd_mmo_vec;
  extern const bfd_target bfd_powerpc_pe_vec;
  extern const bfd_target bfd_powerpc_pei_vec;
  extern const bfd_target bfd_powerpcle_pe_vec;
*************** static const bfd_target * const _bfd_tar
*** 799,804 ****
--- 802,808 ----
  	&bfd_elf64_ia64_little_vec,
  	&bfd_elf64_little_generic_vec,
  	&bfd_elf64_littlemips_vec,
+ 	&bfd_elf64_mmix_vec,
  	&bfd_elf64_powerpc_vec,
  	&bfd_elf64_powerpcle_vec,
  	&bfd_elf64_s390_vec,
*************** static const bfd_target * const _bfd_tar
*** 808,813 ****
--- 812,818 ----
  	&bfd_elf64_tradbigmips_vec,
  	&bfd_elf64_tradlittlemips_vec,
  	&bfd_elf64_x86_64_vec,
+ 	&bfd_mmo_mmix_vec,
  #endif
  	&bfd_powerpc_pe_vec,
  	&bfd_powerpc_pei_vec,
*** /dev/null	Tue Jan  1 05:00:00 1980
--- elf64-mmix.c	Wed Aug 29 18:03:28 2001
***************
*** 0 ****
--- 1,1739 ----
+ /* MMIX-specific support for 64-bit ELF.
+    Copyright (C) 2001 Free Software Foundation, Inc.
+    Contributed by Hans-Peter Nilsson <hp@bitrange.com>
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+ /* No specific ABI or "processor-specific supplement" defined.  */
+
+ /* TODO:
+    - Linker relaxation.
+    - On-demand register allocation (from R_MMIX_BASE_PLUS_OFFSET).  */
+
+ #include "bfd.h"
+ #include "sysdep.h"
+ #include "libbfd.h"
+ #include "elf-bfd.h"
+ #include "elf/mmix.h"
+ #include "opcode/mmix.h"
+
+ #define MINUS_ONE	(((bfd_vma) 0) - 1)
+
+ /* Put these everywhere in new code.  */
+ #define FATAL_DEBUG						\
+  _bfd_abort (__FILE__, __LINE__,				\
+ 	     "Internal: Non-debugged code (test-case missing)")
+
+ #define BAD_CASE(x)				\
+  _bfd_abort (__FILE__, __LINE__,		\
+ 	     "bad case for " #x)
+
+ static boolean mmix_elf_link_output_symbol_hook
+   PARAMS ((bfd *, struct bfd_link_info *, const char *,
+ 	   Elf_Internal_Sym *, asection *));
+
+ static bfd_reloc_status_type mmix_elf_reloc
+   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+
+ static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
+   PARAMS ((bfd *, bfd_reloc_code_real_type));
+
+ static void mmix_info_to_howto_rela
+   PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *));
+
+ static int mmix_elf_sort_relocs PARAMS ((const PTR, const PTR));
+
+ static boolean mmix_elf_check_relocs
+   PARAMS ((bfd *, struct bfd_link_info *, asection *,
+ 	   const Elf_Internal_Rela *));
+
+ static boolean mmix_elf_relocate_section
+   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
+ 	   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
+
+ static asection * mmix_elf_gc_mark_hook
+   PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+ 	   struct elf_link_hash_entry *, Elf_Internal_Sym *));
+
+ static bfd_reloc_status_type mmix_final_link_relocate
+   PARAMS ((reloc_howto_type *, asection *, bfd_byte *,
+ 	   bfd_vma, bfd_signed_vma, bfd_vma, const char *, asection *));
+
+ static bfd_reloc_status_type mmix_elf_perform_relocation
+   PARAMS ((asection *, reloc_howto_type *, PTR, bfd_vma, bfd_vma));
+
+ static boolean mmix_elf_section_from_bfd_section
+   PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *, int *));
+
+ static boolean mmix_elf_add_symbol_hook
+   PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
+ 	   const char **, flagword *, asection **, bfd_vma *));
+
+ static boolean mmix_elf_is_local_label_name
+   PARAMS ((bfd *, const char *));
+
+ extern boolean mmix_elf_final_link PARAMS ((bfd *, struct bfd_link_info *));
+
+ extern void mmix_elf_symbol_processing PARAMS ((bfd *, asymbol *));
+
+ /* Watch out: this currently needs to have elements with the same index as
+    their R_MMIX_ number.  */
+ static reloc_howto_type elf_mmix_howto_table[] =
+  {
+   /* This reloc does nothing.  */
+   HOWTO (R_MMIX_NONE,		/* type */
+ 	 0,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 32,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_NONE",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0,			/* src_mask */
+ 	 0,			/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* An 8 bit absolute relocation.  */
+   HOWTO (R_MMIX_8,		/* type */
+ 	 0,			/* rightshift */
+ 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 8,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_8",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xff,			/* src_mask */
+ 	 0xff,			/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* An 16 bit absolute relocation.  */
+   HOWTO (R_MMIX_16,		/* type */
+ 	 0,			/* rightshift */
+ 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 16,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_16",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffff,		/* src_mask */
+ 	 0xffff,		/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* An 24 bit absolute relocation.  */
+   HOWTO (R_MMIX_24,		/* type */
+ 	 0,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 24,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_24",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffffff,		/* src_mask */
+ 	 0xffffff,		/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* A 32 bit absolute relocation.  */
+   HOWTO (R_MMIX_32,		/* type */
+ 	 0,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 32,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_32",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffffffff,		/* src_mask */
+ 	 0xffffffff,		/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* 64 bit relocation.  */
+   HOWTO (R_MMIX_64,		/* type */
+ 	 0,			/* rightshift */
+ 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 64,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_64",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 MINUS_ONE,		/* src_mask */
+ 	 MINUS_ONE,		/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* An 8 bit PC-relative relocation.  */
+   HOWTO (R_MMIX_PC_8,		/* type */
+ 	 0,			/* rightshift */
+ 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 8,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_PC_8",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xff,			/* src_mask */
+ 	 0xff,			/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* An 16 bit PC-relative relocation.  */
+   HOWTO (R_MMIX_PC_16,		/* type */
+ 	 0,			/* rightshift */
+ 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 16,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_PC_16",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffff,		/* src_mask */
+ 	 0xffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* An 24 bit PC-relative relocation.  */
+   HOWTO (R_MMIX_PC_24,		/* type */
+ 	 0,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 24,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_PC_24",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffffff,		/* src_mask */
+ 	 0xffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* A 32 bit absolute PC-relative relocation.  */
+   HOWTO (R_MMIX_PC_32,		/* type */
+ 	 0,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 32,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_PC_32",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffffffff,		/* src_mask */
+ 	 0xffffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* 64 bit PC-relative relocation.  */
+   HOWTO (R_MMIX_PC_64,		/* type */
+ 	 0,			/* rightshift */
+ 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 64,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 bfd_elf_generic_reloc,	/* special_function */
+ 	 "R_MMIX_PC_64",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 MINUS_ONE,		/* src_mask */
+ 	 MINUS_ONE,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* GNU extension to record C++ vtable hierarchy.  */
+   HOWTO (R_MMIX_GNU_VTINHERIT, /* type */
+ 	 0,			/* rightshift */
+ 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 0,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_dont, /* complain_on_overflow */
+ 	 NULL,			/* special_function */
+ 	 "R_MMIX_GNU_VTINHERIT", /* name */
+ 	 false,			/* partial_inplace */
+ 	 0,			/* src_mask */
+ 	 0,			/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* GNU extension to record C++ vtable member usage.  */
+   HOWTO (R_MMIX_GNU_VTENTRY,	/* type */
+ 	 0,			/* rightshift */
+ 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 0,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_dont, /* complain_on_overflow */
+ 	 _bfd_elf_rel_vtable_reloc_fn,	/* special_function */
+ 	 "R_MMIX_GNU_VTENTRY", /* name */
+ 	 false,			/* partial_inplace */
+ 	 0,			/* src_mask */
+ 	 0,			/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* The GETA relocation is supposed to get any address that could
+      possibly be reached by the GETA instruction.  It can silently expand
+      to get a 64-bit operand, but will complain if any of the two least
+      significant bits are set.  The howto members reflect a simple GETA.  */
+   HOWTO (R_MMIX_GETA,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_GETA",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_GETA_1,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_GETA_1",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_GETA_2,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_GETA_2",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_GETA_3,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_GETA_3",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* The conditional branches are supposed to reach any (code) address.
+      It can silently expand to a 64-bit operand, but will emit an error if
+      any of the two least significant bits are set.  The howto members
+      reflect a simple branch.  */
+   HOWTO (R_MMIX_CBRANCH,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_CBRANCH",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),		       	/* pcrel_offset */
+
+   HOWTO (R_MMIX_CBRANCH_J,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_CBRANCH_J",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_CBRANCH_1,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_CBRANCH_1",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_CBRANCH_2,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_CBRANCH_2",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_CBRANCH_3,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_CBRANCH_3",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* The PUSHJ instruction can reach any (code) address, as long as it's
+      the beginning of a function (no usable restriction).  It can silently
+      expand to a 64-bit operand, but will emit an error if any of the two
+      least significant bits are set.  The howto members reflect a simple
+      PUSHJ.  */
+   HOWTO (R_MMIX_PUSHJ,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_PUSHJ",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_PUSHJ_1,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_PUSHJ_1",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_PUSHJ_2,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_PUSHJ_2",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_PUSHJ_3,	/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_PUSHJ_3",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* A JMP is supposed to reach any (code) address.  By itself, it can
+      reach +-64M; the expansion can reach all 64 bits.  Note that the 64M
+      limit is soon reached if you link the program in wildly different
+      memory segments.  The howto members reflect a trivial JMP.  */
+   HOWTO (R_MMIX_JMP,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 27,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_JMP",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x1ffffff,		/* src_mask */
+ 	 0x1ffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_JMP_1,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 27,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_JMP_1",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x1ffffff,		/* src_mask */
+ 	 0x1ffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_JMP_2,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 27,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_JMP_2",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x1ffffff,		/* src_mask */
+ 	 0x1ffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   HOWTO (R_MMIX_JMP_3,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 27,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_JMP_3",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x1ffffff,		/* src_mask */
+ 	 0x1ffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* When we don't emit link-time-relaxable code from the assembler, or
+      when relaxation has done all it can do, these relocs are used.  For
+      GETA/PUSHJ/branches.  */
+   HOWTO (R_MMIX_ADDR19,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 19,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_ADDR19",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x0100ffff,		/* src_mask */
+ 	 0x0100ffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* For JMP.  */
+   HOWTO (R_MMIX_ADDR27,		/* type */
+ 	 2,			/* rightshift */
+ 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 27,			/* bitsize */
+ 	 true,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_signed, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_ADDR27",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0x1ffffff,		/* src_mask */
+ 	 0x1ffffff,		/* dst_mask */
+ 	 true),			/* pcrel_offset */
+
+   /* A general register or the value 0..255.  If a value, then the
+      instruction (offset -3) needs adjusting.  */
+   HOWTO (R_MMIX_REG_OR_BYTE,	/* type */
+ 	 0,			/* rightshift */
+ 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 8,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_REG_OR_BYTE",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xff,			/* src_mask */
+ 	 0xff,			/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* A general register.  */
+   HOWTO (R_MMIX_REG,		/* type */
+ 	 0,			/* rightshift */
+ 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 8,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_REG",		/* name */
+ 	 false,			/* partial_inplace */
+ 	 0xff,			/* src_mask */
+ 	 0xff,			/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* A register plus an index, corresponding to the relocation expression.
+      The sizes must correspond to the valid range of the expression, while
+      the bitmasks correspond to what we store in the image.  */
+   HOWTO (R_MMIX_BASE_PLUS_OFFSET,	/* type */
+ 	 0,			/* rightshift */
+ 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 64,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_bitfield, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_BASE_PLUS_OFFSET", /* name */
+ 	 false,			/* partial_inplace */
+ 	 0xffff,		/* src_mask */
+ 	 0xffff,		/* dst_mask */
+ 	 false),		/* pcrel_offset */
+
+   /* A "magic" relocation for a LOCAL expression, asserting that the
+      expression is less than the number of global registers.  No actual
+      modification of the contents is done.  Implementing this as a
+      relocation was less intrusive than e.g. putting such expressions in a
+      section to discard *after* relocation.  */
+   HOWTO (R_MMIX_LOCAL,		/* type */
+ 	 0,			/* rightshift */
+ 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+ 	 0,			/* bitsize */
+ 	 false,			/* pc_relative */
+ 	 0,			/* bitpos */
+ 	 complain_overflow_dont, /* complain_on_overflow */
+ 	 mmix_elf_reloc,	/* special_function */
+ 	 "R_MMIX_LOCAL",	/* name */
+ 	 false,			/* partial_inplace */
+ 	 0,			/* src_mask */
+ 	 0,			/* dst_mask */
+ 	 false),		/* pcrel_offset */
+  };
+
+
+ /* Map BFD reloc types to MMIX ELF reloc types.  */
+
+ struct mmix_reloc_map
+   {
+     bfd_reloc_code_real_type bfd_reloc_val;
+     enum elf_mmix_reloc_type elf_reloc_val;
+   };
+
+
+ static const struct mmix_reloc_map mmix_reloc_map[] =
+   {
+     {BFD_RELOC_NONE, R_MMIX_NONE},
+     {BFD_RELOC_8, R_MMIX_8},
+     {BFD_RELOC_16, R_MMIX_16},
+     {BFD_RELOC_24, R_MMIX_24},
+     {BFD_RELOC_32, R_MMIX_32},
+     {BFD_RELOC_64, R_MMIX_64},
+     {BFD_RELOC_8_PCREL, R_MMIX_PC_8},
+     {BFD_RELOC_16_PCREL, R_MMIX_PC_16},
+     {BFD_RELOC_24_PCREL, R_MMIX_PC_24},
+     {BFD_RELOC_32_PCREL, R_MMIX_PC_32},
+     {BFD_RELOC_64_PCREL, R_MMIX_PC_64},
+     {BFD_RELOC_VTABLE_INHERIT, R_MMIX_GNU_VTINHERIT},
+     {BFD_RELOC_VTABLE_ENTRY, R_MMIX_GNU_VTENTRY},
+     {BFD_RELOC_MMIX_GETA, R_MMIX_GETA},
+     {BFD_RELOC_MMIX_CBRANCH, R_MMIX_CBRANCH},
+     {BFD_RELOC_MMIX_PUSHJ, R_MMIX_PUSHJ},
+     {BFD_RELOC_MMIX_JMP, R_MMIX_JMP},
+     {BFD_RELOC_MMIX_ADDR19, R_MMIX_ADDR19},
+     {BFD_RELOC_MMIX_ADDR27, R_MMIX_ADDR27},
+     {BFD_RELOC_MMIX_REG_OR_BYTE, R_MMIX_REG_OR_BYTE},
+     {BFD_RELOC_MMIX_REG, R_MMIX_REG},
+     {BFD_RELOC_MMIX_BASE_PLUS_OFFSET, R_MMIX_BASE_PLUS_OFFSET},
+     {BFD_RELOC_MMIX_LOCAL, R_MMIX_LOCAL}
+   };
+
+ static reloc_howto_type *
+ bfd_elf64_bfd_reloc_type_lookup (abfd, code)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      bfd_reloc_code_real_type code;
+ {
+   unsigned int i;
+
+   for (i = 0;
+        i < sizeof (mmix_reloc_map) / sizeof (mmix_reloc_map[0]);
+        i++)
+     {
+       if (mmix_reloc_map[i].bfd_reloc_val == code)
+ 	return &elf_mmix_howto_table[mmix_reloc_map[i].elf_reloc_val];
+     }
+
+   return NULL;
+ }
+
+
+ /* This function performs the actual bitfiddling and sanity check for a
+    final relocation.  Each relocation gets its *worst*-case expansion
+    in size when it arrives here; any reduction in size should have been
+    caught in linker relaxation earlier.  When we get here, the relocation
+    looks like the smallest instruction with SWYM:s (nop:s) appended to the
+    max size.  We fill in those nop:s.
+
+    R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
+     GETA $N,foo
+    ->
+     SETL $N,foo & 0xffff
+     INCML $N,(foo >> 16) & 0xffff
+     INCMH $N,(foo >> 32) & 0xffff
+     INCH $N,(foo >> 48) & 0xffff
+
+    R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
+    condbranches needing relaxation might be rare enough to not be
+    worthwhile.)
+     [P]Bcc $N,foo
+    ->
+     [~P]B~cc $N,.+20
+     SETL $255,foo & ...
+     INCML ...
+     INCMH ...
+     INCH ...
+     GO $255,$255,0
+
+    R_MMIX_PUSHJ: (FIXME: Relaxation...)
+     PUSHJ $N,foo
+    ->
+     SETL $255,foo & ...
+     INCML ...
+     INCMH ...
+     INCH ...
+     PUSHGO $N,$255,0
+
+    R_MMIX_JMP: (FIXME: Relaxation...)
+     JMP foo
+    ->
+     SETL $255,foo & ...
+     INCML ...
+     INCMH ...
+     INCH ...
+     GO $255,$255,0
+
+    R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in.  */
+
+ static bfd_reloc_status_type
+ mmix_elf_perform_relocation (isec, howto, datap, addr, value)
+      asection *isec;
+      reloc_howto_type *howto;
+      PTR datap;
+      bfd_vma addr ATTRIBUTE_UNUSED;
+      bfd_vma value;
+ {
+   bfd *abfd = isec->owner;
+   bfd_reloc_status_type flag = bfd_reloc_ok;
+   bfd_reloc_status_type r;
+   int offs = 0;
+   int reg = 255;
+
+   /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
+      We handle the differences here and the common sequence later.  */
+   switch (howto->type)
+     {
+     case R_MMIX_GETA:
+       offs = 0;
+       reg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
+
+       /* We change to an absolute value.  */
+       value += addr;
+       break;
+
+     case R_MMIX_CBRANCH:
+       {
+ 	int in1 = bfd_get_16 (abfd, (bfd_byte *) datap) << 16;
+
+ 	/* Invert the condition and prediction bit, and set the offset
+ 	   to five instructions ahead.
+
+ 	   We *can* do better if we want to.  If the branch is found to be
+ 	   within limits, we could leave the branch as is; there'll just
+ 	   be a bunch of NOP:s after it.  But we shouldn't see this
+ 	   sequence often enough that it's worth doing it.  */
+
+ 	bfd_put_32 (abfd,
+ 		    (((in1 ^ ((PRED_INV_BIT | COND_INV_BIT) << 24)) & ~0xffff)
+ 		     | (24/4)),
+ 		    (bfd_byte *) datap);
+
+ 	/* Put a "GO $255,$255,0" after the common sequence.  */
+ 	bfd_put_32 (abfd,
+ 		    ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | 0xffff00,
+ 		    (bfd_byte *) datap + 20);
+
+ 	/* Common sequence starts at offset 4.  */
+ 	offs = 4;
+
+ 	/* We change to an absolute value.  */
+ 	value += addr;
+       }
+       break;
+
+     case R_MMIX_PUSHJ:
+       {
+ 	int inreg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
+
+ 	/* Put a "PUSHGO $N,$255,0" after the common sequence.  */
+ 	bfd_put_32 (abfd,
+ 		    ((PUSHGO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
+ 		    | (inreg << 16)
+ 		    | 0xff00,
+ 		    (bfd_byte *) datap + 16);
+
+ 	/* We change to an absolute value.  */
+ 	value += addr;
+       }
+       break;
+
+     case R_MMIX_JMP:
+       /* This one is a little special.  If we get here on a non-relaxing
+ 	 link, and the destination is actually in range, we don't need to
+ 	 execute the nops.
+ 	 If so, we fall through to the bit-fiddling relocs.
+
+ 	 FIXME: bfd_check_overflow seems broken; the relocation is
+ 	 rightshifted before testing, so supply a zero rightshift.  */
+
+       if (! ((value & 3) == 0
+ 	     && (r = bfd_check_overflow (complain_overflow_signed,
+ 					 howto->bitsize,
+ 					 0,
+ 					 bfd_arch_bits_per_address (abfd),
+ 					 value)) == bfd_reloc_ok))
+ 	{
+ 	  /* If the relocation doesn't fit in a JMP, we let the NOP:s be
+ 	     modified below, and put a "GO $255,$255,0" after the
+ 	     address-loading sequence.  */
+ 	  bfd_put_32 (abfd,
+ 		      ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
+ 		      | 0xffff00,
+ 		      (bfd_byte *) datap + 16);
+
+ 	  /* We change to an absolute value.  */
+ 	  value += addr;
+ 	  break;
+ 	}
+       /* FALLTHROUGH. */
+     case R_MMIX_ADDR19:
+     case R_MMIX_ADDR27:
+       /* These must be in range, or else we emit an error.  */
+       if ((value & 3) == 0
+ 	  /* Note rightshift 0; see above.  */
+ 	  && (r = bfd_check_overflow (complain_overflow_signed,
+ 				      howto->bitsize,
+ 				      0,
+ 				      bfd_arch_bits_per_address (abfd),
+ 				      value)) == bfd_reloc_ok)
+ 	{
+ 	  bfd_vma in1
+ 	    = bfd_get_32 (abfd, (bfd_byte *) datap);
+ 	  bfd_vma highbit;
+
+ 	  if ((bfd_signed_vma) value < 0)
+ 	    {
+ 	      highbit = (1 << 24);
+ 	      value += (1 << (howto->bitsize - 1));
+ 	    }
+ 	  else
+ 	    highbit = 0;
+
+ 	  value >>= 2;
+
+ 	  bfd_put_32 (abfd,
+ 		      (in1 & ~howto->src_mask)
+ 		      | highbit
+ 		      | (value & howto->dst_mask),
+ 		      (bfd_byte *) datap);
+
+ 	  return bfd_reloc_ok;
+ 	}
+       else
+ 	return bfd_reloc_overflow;
+
+     case R_MMIX_REG_OR_BYTE:
+     case R_MMIX_REG:
+       if (value > 255)
+ 	return bfd_reloc_overflow;
+       bfd_put_8 (abfd, value, datap);
+       return bfd_reloc_ok;
+
+     default:
+       BAD_CASE (howto->type);
+     }
+
+   /* This code adds the common SETL/INCML/INCMH/INCH worst-case
+      sequence.  */
+
+   /* Lowest two bits must be 0.  We return bfd_reloc_overflow for
+      everything that looks strange.  */
+   if (value & 3)
+     flag = bfd_reloc_overflow;
+
+   bfd_put_32 (abfd,
+ 	      (SETL_INSN_BYTE << 24) | (value & 0xffff) | (reg << 16),
+ 	      (bfd_byte *) datap + offs);
+   bfd_put_32 (abfd,
+ 	      (INCML_INSN_BYTE << 24) | ((value >> 16) & 0xffff) | (reg << 16),
+ 	      (bfd_byte *) datap + offs + 4);
+   bfd_put_32 (abfd,
+ 	      (INCMH_INSN_BYTE << 24) | ((value >> 32) & 0xffff) | (reg << 16),
+ 	      (bfd_byte *) datap + offs + 8);
+   bfd_put_32 (abfd,
+ 	      (INCH_INSN_BYTE << 24) | ((value >> 48) & 0xffff) | (reg << 16),
+ 	      (bfd_byte *) datap + offs + 12);
+
+   return flag;
+ }
+
+ /* Set the howto pointer for an MMIX ELF reloc (type RELA).  */
+
+ static void
+ mmix_info_to_howto_rela (abfd, cache_ptr, dst)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      arelent *cache_ptr;
+      Elf64_Internal_Rela *dst;
+ {
+   unsigned int r_type;
+
+   r_type = ELF64_R_TYPE (dst->r_info);
+   BFD_ASSERT (r_type < (unsigned int) R_MMIX_max);
+   cache_ptr->howto = &elf_mmix_howto_table[r_type];
+ }
+
+ /* Any MMIX-specific relocation gets here at assembly time or when linking
+    to other formats (such as mmo); this is the relocation function from
+    the reloc_table.  We don't get here for final pure ELF linking.  */
+
+ static bfd_reloc_status_type
+ mmix_elf_reloc (abfd, reloc_entry, symbol, data, input_section,
+ 		output_bfd, error_message)
+      bfd *abfd;
+      arelent *reloc_entry;
+      asymbol *symbol;
+      PTR data;
+      asection *input_section;
+      bfd *output_bfd;
+      char **error_message ATTRIBUTE_UNUSED;
+ {
+   bfd_vma relocation;
+   bfd_reloc_status_type r;
+   asection *reloc_target_output_section;
+   bfd_reloc_status_type flag = bfd_reloc_ok;
+   bfd_vma output_base = 0;
+   bfd_vma addr;
+
+   r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
+ 			     input_section, output_bfd, error_message);
+
+   /* If that was all that was needed (i.e. this isn't a final link, only
+      some segment adjustments), we're done.  */
+   if (r != bfd_reloc_continue)
+     return r;
+
+   if (bfd_is_und_section (symbol->section)
+       && (symbol->flags & BSF_WEAK) == 0
+       && output_bfd == (bfd *) NULL)
+     return bfd_reloc_undefined;
+
+   /* Is the address of the relocation really within the section?  */
+   if (reloc_entry->address > input_section->_cooked_size)
+     return bfd_reloc_outofrange;
+
+   /* Work out which section the relocation is targetted at and the
+      initial relocation command value.  */
+
+   /* Get symbol value.  (Common symbols are special.)  */
+   if (bfd_is_com_section (symbol->section))
+     relocation = 0;
+   else
+     relocation = symbol->value;
+
+   reloc_target_output_section = bfd_get_output_section (symbol);
+
+   /* Here the variable relocation holds the final address of the symbol we
+      are relocating against, plus any addend.  */
+   if (output_bfd)
+     output_base = 0;
+   else
+     output_base = reloc_target_output_section->vma;
+
+   relocation += output_base + symbol->section->output_offset;
+
+   /* Get position of relocation.  */
+   addr = (reloc_entry->address + input_section->output_section->vma
+ 	  + input_section->output_offset);
+   if (output_bfd != (bfd *) NULL)
+     {
+       /* Add in supplied addend.  */
+       relocation += reloc_entry->addend;
+
+       /* This is a partial relocation, and we want to apply the
+ 	 relocation to the reloc entry rather than the raw data.
+ 	 Modify the reloc inplace to reflect what we now know.  */
+       reloc_entry->addend = relocation;
+       reloc_entry->address += input_section->output_offset;
+       return flag;
+     }
+
+   return mmix_final_link_relocate (reloc_entry->howto, input_section,
+ 				   data, reloc_entry->address,
+ 				   reloc_entry->addend, relocation,
+ 				   bfd_asymbol_name (symbol),
+ 				   reloc_target_output_section);
+ }
+
+ /* Relocate an MMIX ELF section.  Modified from elf32-fr30.c; look to it
+    for guidance if you're thinking of copying this.  */
+
+ static boolean
+ mmix_elf_relocate_section (output_bfd, info, input_bfd, input_section,
+ 			   contents, relocs, local_syms, local_sections)
+      bfd *output_bfd ATTRIBUTE_UNUSED;
+      struct bfd_link_info *info;
+      bfd *input_bfd;
+      asection *input_section;
+      bfd_byte *contents;
+      Elf_Internal_Rela *relocs;
+      Elf_Internal_Sym *local_syms;
+      asection **local_sections;
+ {
+   Elf_Internal_Shdr *symtab_hdr;
+   struct elf_link_hash_entry **sym_hashes;
+   Elf_Internal_Rela *rel;
+   Elf_Internal_Rela *relend;
+
+   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+   sym_hashes = elf_sym_hashes (input_bfd);
+   relend = relocs + input_section->reloc_count;
+
+   for (rel = relocs; rel < relend; rel ++)
+     {
+       reloc_howto_type *howto;
+       unsigned long r_symndx;
+       Elf_Internal_Sym *sym;
+       asection *sec;
+       struct elf_link_hash_entry *h;
+       bfd_vma relocation;
+       bfd_reloc_status_type r;
+       const char *name = NULL;
+       int r_type;
+       boolean undefined_signalled = false;
+
+       r_type = ELF64_R_TYPE (rel->r_info);
+
+       if (r_type == R_MMIX_GNU_VTINHERIT
+ 	  || r_type == R_MMIX_GNU_VTENTRY)
+ 	continue;
+
+       r_symndx = ELF64_R_SYM (rel->r_info);
+
+       if (info->relocateable)
+ 	{
+ 	  /* This is a relocateable link.  We don't have to change
+              anything, unless the reloc is against a section symbol,
+              in which case we have to adjust according to where the
+              section symbol winds up in the output section.  */
+ 	  if (r_symndx < symtab_hdr->sh_info)
+ 	    {
+ 	      sym = local_syms + r_symndx;
+
+ 	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
+ 		{
+ 		  sec = local_sections [r_symndx];
+ 		  rel->r_addend += sec->output_offset + sym->st_value;
+ 		}
+ 	    }
+
+ 	  continue;
+ 	}
+
+       /* This is a final link.  */
+       howto = elf_mmix_howto_table + ELF64_R_TYPE (rel->r_info);
+       h = NULL;
+       sym = NULL;
+       sec = NULL;
+
+       if (r_symndx < symtab_hdr->sh_info)
+ 	{
+ 	  sym = local_syms + r_symndx;
+ 	  sec = local_sections [r_symndx];
+ 	  relocation = (sec->output_section->vma
+ 			+ sec->output_offset
+ 			+ sym->st_value);
+
+ 	  name = bfd_elf_string_from_elf_section
+ 	    (input_bfd, symtab_hdr->sh_link, sym->st_name);
+ 	  name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
+ 	}
+       else
+ 	{
+ 	  h = sym_hashes [r_symndx - symtab_hdr->sh_info];
+
+ 	  while (h->root.type == bfd_link_hash_indirect
+ 		 || h->root.type == bfd_link_hash_warning)
+ 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ 	  name = h->root.root.string;
+
+ 	  if (h->root.type == bfd_link_hash_defined
+ 	      || h->root.type == bfd_link_hash_defweak)
+ 	    {
+ 	      sec = h->root.u.def.section;
+ 	      relocation = (h->root.u.def.value
+ 			    + sec->output_section->vma
+ 			    + sec->output_offset);
+ 	    }
+ 	  else if (h->root.type == bfd_link_hash_undefweak)
+ 	    relocation = 0;
+ 	  else if (info->shared
+ 		   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+ 	    relocation = 0;
+ 	  else
+ 	    {
+ 	      /* The test on undefined_signalled is redundant at the
+ 		 moment, but kept for symmetry.  */
+ 	      if (! undefined_signalled
+ 		  && ! ((*info->callbacks->undefined_symbol)
+ 			(info, h->root.root.string, input_bfd,
+ 			 input_section, rel->r_offset, true)))
+ 		return false;
+ 	      undefined_signalled = true;
+ 	      relocation = 0;
+ 	    }
+ 	}
+
+       r = mmix_final_link_relocate (howto, input_section,
+ 				    contents, rel->r_offset,
+ 				    rel->r_addend, relocation, name, sec);
+
+       if (r != bfd_reloc_ok)
+ 	{
+ 	  boolean check_ok = true;
+ 	  const char * msg = (const char *) NULL;
+
+ 	  switch (r)
+ 	    {
+ 	    case bfd_reloc_overflow:
+ 	      check_ok = info->callbacks->reloc_overflow
+ 		(info, name, howto->name, (bfd_vma) 0,
+ 		 input_bfd, input_section, rel->r_offset);
+ 	      break;
+
+ 	    case bfd_reloc_undefined:
+ 	      /* We may have sent this message above.  */
+ 	      if (! undefined_signalled)
+ 		check_ok = info->callbacks->undefined_symbol
+ 		  (info, name, input_bfd, input_section, rel->r_offset,
+ 		   true);
+ 	      undefined_signalled = true;
+ 	      break;
+
+ 	    case bfd_reloc_outofrange:
+ 	      msg = _("internal error: out of range error");
+ 	      break;
+
+ 	    case bfd_reloc_notsupported:
+ 	      msg = _("internal error: unsupported relocation error");
+ 	      break;
+
+ 	    case bfd_reloc_dangerous:
+ 	      msg = _("internal error: dangerous relocation");
+ 	      break;
+
+ 	    default:
+ 	      msg = _("internal error: unknown error");
+ 	      break;
+ 	    }
+
+ 	  if (msg)
+ 	    check_ok = info->callbacks->warning
+ 	      (info, msg, name, input_bfd, input_section, rel->r_offset);
+
+ 	  if (! check_ok)
+ 	    return false;
+ 	}
+     }
+
+   return true;
+ }
+
+ /* Perform a single relocation.  By default we use the standard BFD
+    routines.  A few relocs we have to do ourselves.  */
+
+ static bfd_reloc_status_type
+ mmix_final_link_relocate (howto, input_section, contents,
+ 			  r_offset, r_addend, relocation, symname, symsec)
+      reloc_howto_type *howto;
+      asection *input_section;
+      bfd_byte *contents;
+      bfd_vma r_offset;
+      bfd_signed_vma r_addend;
+      bfd_vma relocation;
+      const char *symname;
+      asection *symsec;
+ {
+   bfd_reloc_status_type r = bfd_reloc_ok;
+   bfd_vma addr
+     = (input_section->output_section->vma
+        + input_section->output_offset
+        + r_offset);
+   bfd_signed_vma srel
+     = (bfd_signed_vma) relocation + r_addend;
+
+   switch (howto->type)
+     {
+       /* All these are PC-relative.  */
+     case R_MMIX_PUSHJ:
+     case R_MMIX_CBRANCH:
+     case R_MMIX_ADDR19:
+     case R_MMIX_GETA:
+     case R_MMIX_ADDR27:
+     case R_MMIX_JMP:
+       contents += r_offset;
+
+       srel -= (input_section->output_section->vma
+ 	       + input_section->output_offset
+ 	       + r_offset);
+
+       r = mmix_elf_perform_relocation (input_section, howto, contents,
+ 				       addr, srel);
+       break;
+
+     case R_MMIX_REG_OR_BYTE:
+     case R_MMIX_REG:
+       /* For now, we handle these alike.  They must refer to an register
+ 	 symbol, which is either relative to the register section and in
+ 	 the range 0..255, or is in the register contents section with vma
+ 	 regno * 8.  */
+
+       /* FIXME: A better way to check for reg contents section?
+ 	 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
+       if (symsec == NULL)
+ 	return bfd_reloc_undefined;
+
+       if (strcmp (bfd_get_section_name (symsec->owner, symsec),
+ 		  MMIX_REG_CONTENTS_SECTION_NAME) == 0)
+ 	{
+ 	  if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
+ 	    {
+ 	      /* The bfd_reloc_outofrange return value, though intuitively
+ 		 a better value, will not get us an error.  */
+ 	      return bfd_reloc_overflow;
+ 	    }
+ 	  srel /= 8;
+ 	}
+       else if (strcmp (bfd_get_section_name (symsec->owner, symsec),
+ 		       MMIX_REG_SECTION_NAME) == 0)
+ 	{
+ 	  if (srel < 0 || srel > 255)
+ 	    /* The bfd_reloc_outofrange return value, though intuitively a
+ 	       better value, will not get us an error.  */
+ 	    return bfd_reloc_overflow;
+ 	}
+       else
+ 	{
+ 	  (*_bfd_error_handler)
+ 	    (_("%s: register relocation against non-register symbol: %s in %s"),
+ 	     bfd_get_filename (input_section->owner),
+ 	     symname == NULL || *symname == 0 ? _("(unknown)") : symname,
+ 	     bfd_get_section_name (symsec->owner, symsec));
+
+ 	  /* The bfd_reloc_outofrange return value, though intuitively a
+ 	     better value, will not get us an error.  */
+ 	  return bfd_reloc_overflow;
+ 	}
+       contents += r_offset;
+       r = mmix_elf_perform_relocation (input_section, howto, contents,
+ 				       addr, srel);
+       break;
+
+     case R_MMIX_LOCAL:
+       /* This isn't a real relocation, it's just an assertion that the
+ 	 final relocation value corresponds to a local register.  We
+ 	 ignore the actual relocation; nothing is changed.  */
+       {
+ 	asection *regsec
+ 	  = bfd_get_section_by_name (input_section->output_section->owner,
+ 				     MMIX_REG_CONTENTS_SECTION_NAME);
+ 	bfd_vma first_global;
+
+ 	/* Check that this is an absolute value, or a reference to the
+ 	   register contents section or the register (symbol) section.
+ 	   Absolute numbers can get here as undefined section.  Undefined
+ 	   symbols are signalled elsewhere, so there's no conflict in us
+ 	   accidentally handling it.  */
+ 	if (!bfd_is_abs_section (symsec)
+ 	    && !bfd_is_und_section (symsec)
+ 	    && strcmp (bfd_get_section_name (symsec->owner, symsec),
+ 		       MMIX_REG_CONTENTS_SECTION_NAME) != 0
+ 	    && strcmp (bfd_get_section_name (symsec->owner, symsec),
+ 		       MMIX_REG_SECTION_NAME) != 0)
+ 	{
+ 	  (*_bfd_error_handler)
+ 	    (_("%s: directive LOCAL valid only with a register or absolute value"),
+ 	     bfd_get_filename (input_section->owner));
+
+ 	  return bfd_reloc_overflow;
+ 	}
+
+       /* If we don't have a register contents section, then $255 is the
+ 	 first global register.  */
+       if (regsec == NULL)
+ 	first_global = 255;
+       else
+ 	{
+ 	  first_global = bfd_get_section_vma (abfd, regsec) / 8;
+ 	  if (strcmp (bfd_get_section_name (symsec->owner, symsec),
+ 		      MMIX_REG_CONTENTS_SECTION_NAME) == 0)
+ 	    {
+ 	      if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
+ 		/* The bfd_reloc_outofrange return value, though
+ 		   intuitively a better value, will not get us an error.  */
+ 		return bfd_reloc_overflow;
+ 	      srel /= 8;
+ 	    }
+ 	}
+
+ 	if ((bfd_vma) srel >= first_global)
+ 	  {
+ 	    /* FIXME: Better error message.  */
+ 	    (*_bfd_error_handler)
+ 	      (_("%s: LOCAL directive: Register $%ld is not a local register.  First global register is $%ld."),
+ 	       bfd_get_filename (input_section->owner), (long) srel, (long) first_global);
+
+ 	    return bfd_reloc_overflow;
+ 	  }
+       }
+       r = bfd_reloc_ok;
+       break;
+
+     default:
+       r = _bfd_final_link_relocate (howto, input_section->owner, input_section,
+ 				    contents, r_offset,
+ 				    relocation, r_addend);
+     }
+
+   return r;
+ }
+
+ /* Return the section that should be marked against GC for a given
+    relocation.  */
+
+ static asection *
+ mmix_elf_gc_mark_hook (abfd, info, rel, h, sym)
+      bfd *abfd;
+      struct bfd_link_info *info ATTRIBUTE_UNUSED;
+      Elf_Internal_Rela *rel;
+      struct elf_link_hash_entry *h;
+      Elf_Internal_Sym *sym;
+ {
+   if (h != NULL)
+     {
+       switch (ELF64_R_TYPE (rel->r_info))
+ 	{
+ 	case R_MMIX_GNU_VTINHERIT:
+ 	case R_MMIX_GNU_VTENTRY:
+ 	  break;
+
+ 	default:
+ 	  switch (h->root.type)
+ 	    {
+ 	    case bfd_link_hash_defined:
+ 	    case bfd_link_hash_defweak:
+ 	      return h->root.u.def.section;
+
+ 	    case bfd_link_hash_common:
+ 	      return h->root.u.c.p->section;
+
+ 	    default:
+ 	      break;
+ 	    }
+ 	}
+     }
+   else
+     {
+       if (!(elf_bad_symtab (abfd)
+ 	    && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
+ 	  && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
+ 		&& sym->st_shndx != SHN_COMMON))
+ 	{
+ 	  return bfd_section_from_elf_index (abfd, sym->st_shndx);
+ 	}
+     }
+
+   return NULL;
+ }
+
+ /* Sort register relocs to come before expanding relocs.  */
+
+ static int
+ mmix_elf_sort_relocs (p1, p2)
+      const PTR p1;
+      const PTR p2;
+ {
+   const Elf_Internal_Rela *r1 = (const Elf_Internal_Rela *) p1;
+   const Elf_Internal_Rela *r2 = (const Elf_Internal_Rela *) p2;
+   int r1_is_reg, r2_is_reg;
+
+   /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
+      insns.  */
+   if ((r1->r_offset & ~(bfd_vma) 3) > (r2->r_offset & ~(bfd_vma) 3))
+     return 1;
+   else if ((r1->r_offset & ~(bfd_vma) 3) < (r2->r_offset & ~(bfd_vma) 3))
+     return -1;
+
+   r1_is_reg
+     = (ELF64_R_TYPE (r1->r_info) == R_MMIX_REG_OR_BYTE
+        || ELF64_R_TYPE (r1->r_info) == R_MMIX_REG);
+   r2_is_reg
+     = (ELF64_R_TYPE (r2->r_info) == R_MMIX_REG_OR_BYTE
+        || ELF64_R_TYPE (r2->r_info) == R_MMIX_REG);
+   if (r1_is_reg != r2_is_reg)
+     return r2_is_reg - r1_is_reg;
+
+   /* Neither or both are register relocs.  Then sort on full offset.  */
+   if (r1->r_offset > r2->r_offset)
+     return 1;
+   else if (r1->r_offset < r2->r_offset)
+     return -1;
+   return 0;
+ }
+
+ /* Look through the relocs for a section during the first phase.  */
+
+ static boolean
+ mmix_elf_check_relocs (abfd, info, sec, relocs)
+      bfd *abfd;
+      struct bfd_link_info *info;
+      asection *sec;
+      const Elf_Internal_Rela *relocs;
+ {
+   Elf_Internal_Shdr *symtab_hdr;
+   struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
+   const Elf_Internal_Rela *rel;
+   const Elf_Internal_Rela *rel_end;
+
+   if (info->relocateable)
+     return true;
+
+   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+   sym_hashes = elf_sym_hashes (abfd);
+   sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf64_External_Sym);
+   if (!elf_bad_symtab (abfd))
+     sym_hashes_end -= symtab_hdr->sh_info;
+
+   /* First we sort the relocs so that any register relocs come before
+      expansion-relocs to the same insn.  FIXME: Not done for mmo.  */
+   qsort ((PTR) relocs, sec->reloc_count, sizeof (Elf_Internal_Rela),
+ 	 mmix_elf_sort_relocs);
+
+   rel_end = relocs + sec->reloc_count;
+   for (rel = relocs; rel < rel_end; rel++)
+     {
+       struct elf_link_hash_entry *h;
+       unsigned long r_symndx;
+
+       r_symndx = ELF64_R_SYM (rel->r_info);
+       if (r_symndx < symtab_hdr->sh_info)
+         h = NULL;
+       else
+         h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+
+       switch (ELF64_R_TYPE (rel->r_info))
+         {
+         /* This relocation describes the C++ object vtable hierarchy.
+            Reconstruct it for later use during GC.  */
+         case R_MMIX_GNU_VTINHERIT:
+           if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
+             return false;
+           break;
+
+         /* This relocation describes which C++ vtable entries are actually
+            used.  Record for later use during GC.  */
+         case R_MMIX_GNU_VTENTRY:
+           if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+             return false;
+           break;
+         }
+     }
+
+   return true;
+ }
+
+ /* Change symbols relative to the reg contents section to instead be to
+    the register section, and scale them down to correspond to the register
+    number.  */
+
+ static boolean
+ mmix_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      struct bfd_link_info *info ATTRIBUTE_UNUSED;
+      const char *name ATTRIBUTE_UNUSED;
+      Elf_Internal_Sym *sym;
+      asection *input_sec;
+ {
+   if (input_sec != NULL
+       && input_sec->name != NULL
+       && ELF_ST_TYPE (sym->st_info) != STT_SECTION
+       && strcmp (input_sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
+     {
+       sym->st_value /= 8;
+       sym->st_shndx = SHN_REGISTER;
+     }
+
+   return true;
+ }
+
+ /* We fake a register section that holds values that are register numbers.
+    Having a SHN_REGISTER and register section translates better to other
+    formats (e.g. mmo) than for example a STT_REGISTER attribute.
+    This section faking is based on a construct in elf32-mips.c.  */
+ static asection mmix_elf_reg_section;
+ static asymbol mmix_elf_reg_section_symbol;
+ static asymbol *mmix_elf_reg_section_symbol_ptr;
+
+ /* Handle the special MIPS section numbers that a symbol may use.
+    This is used for both the 32-bit and the 64-bit ABI.  */
+
+ void
+ mmix_elf_symbol_processing (abfd, asym)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asymbol *asym;
+ {
+   elf_symbol_type *elfsym;
+
+   elfsym = (elf_symbol_type *) asym;
+   switch (elfsym->internal_elf_sym.st_shndx)
+     {
+     case SHN_REGISTER:
+       if (mmix_elf_reg_section.name == NULL)
+ 	{
+ 	  /* Initialize the register section.  */
+ 	  mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME;
+ 	  mmix_elf_reg_section.flags = SEC_NO_FLAGS;
+ 	  mmix_elf_reg_section.output_section = &mmix_elf_reg_section;
+ 	  mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol;
+ 	  mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr;
+ 	  mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME;
+ 	  mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM;
+ 	  mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section;
+ 	  mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol;
+ 	}
+       asym->section = &mmix_elf_reg_section;
+       break;
+
+     default:
+       break;
+     }
+ }
+
+ /* Given a BFD section, try to locate the corresponding ELF section
+    index.  */
+
+ static boolean
+ mmix_elf_section_from_bfd_section (abfd, hdr, sec, retval)
+      bfd *                 abfd ATTRIBUTE_UNUSED;
+      Elf64_Internal_Shdr * hdr ATTRIBUTE_UNUSED;
+      asection *            sec;
+      int *                 retval;
+ {
+   if (strcmp (bfd_get_section_name (abfd, sec), MMIX_REG_SECTION_NAME) == 0)
+     *retval = SHN_REGISTER;
+   else
+     return false;
+
+   return true;
+ }
+
+ /* Hook called by the linker routine which adds symbols from an object
+    file.  We must handle the special SHN_REGISTER section number here.
+
+    We also check that we only have *one* each of the section-start
+    symbols, since otherwise having two with the same value would cause
+    them to be "merged", but with the contents serialized.  */
+
+ boolean
+ mmix_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
+      bfd *abfd;
+      struct bfd_link_info *info ATTRIBUTE_UNUSED;
+      const Elf_Internal_Sym *sym;
+      const char **namep ATTRIBUTE_UNUSED;
+      flagword *flagsp ATTRIBUTE_UNUSED;
+      asection **secp;
+      bfd_vma *valp ATTRIBUTE_UNUSED;
+ {
+   if (sym->st_shndx == SHN_REGISTER)
+     *secp = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
+   else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.'
+ 	   && strncmp (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
+ 		       strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)) == 0)
+     {
+       /* See if we have another one.  */
+       struct elf_link_hash_entry *h
+ 	= (struct elf_link_hash_entry *) bfd_link_hash_lookup (info->hash,
+ 							       *namep,
+ 							       false,
+ 							       false, false);
+
+       if (h != NULL && h->root.type != bfd_link_hash_undefined)
+ 	{
+ 	  /* How do we get the asymbol (or really: the filename) from h?
+ 	     h->root.u.def.section->owner is NULL.  */
+ 	  ((*_bfd_error_handler)
+ 	   (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
+ 	    bfd_get_filename (abfd), *namep,
+ 	    *namep + strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)));
+ 	   bfd_set_error (bfd_error_bad_value);
+ 	   return false;
+ 	}
+     }
+
+   return true;
+ }
+
+ /* We consider symbols matching "L.*:[0-9]+" to be local symbols.  */
+
+ boolean
+ mmix_elf_is_local_label_name (abfd, name)
+      bfd *abfd;
+      const char *name;
+ {
+   const char *colpos;
+   int digits;
+
+   /* Also include the default local-label definition.  */
+   if (_bfd_elf_is_local_label_name (abfd, name))
+     return true;
+
+   if (*name != 'L')
+     return false;
+
+   /* If there's no ":", or more than one, it's not a local symbol.  */
+   colpos = strchr (name, ':');
+   if (colpos == NULL || strchr (colpos + 1, ':') != NULL)
+     return false;
+
+   /* Check that there are remaining characters and that they are digits.  */
+   if (colpos[1] == 0)
+     return false;
+
+   digits = strspn (colpos + 1, "0123456789");
+   return digits != 0 && colpos[1 + digits] == 0;
+ }
+
+ /* We get rid of the register section here.  */
+
+ boolean
+ mmix_elf_final_link (abfd, info)
+      bfd *abfd;
+      struct bfd_link_info *info;
+ {
+   /* We never output a register section, though we create one for
+      temporary measures.  Check that nobody entered contents into it.  */
+   asection *reg_section;
+   asection **secpp;
+
+   reg_section = bfd_get_section_by_name (abfd, MMIX_REG_SECTION_NAME);
+
+   if (reg_section != NULL)
+     {
+       /* FIXME: Pass error state gracefully.  */
+       if (bfd_get_section_flags (abfd, reg_section) & SEC_HAS_CONTENTS)
+ 	_bfd_abort (__FILE__, __LINE__, _("Register section has contents\n"));
+
+       /* FIXME: This does not seem like the proper way to kill a section,
+ 	 but it's the way it's done elsewhere, like elf64-alpha.c.  */
+       /* Really remove the section.  */
+       for (secpp = &abfd->sections;
+ 	   *secpp != reg_section;
+ 	   secpp = &(*secpp)->next)
+ 	;
+       *secpp = (*secpp)->next;
+       --abfd->section_count;
+     }
+
+   if (! bfd_elf64_bfd_final_link (abfd, info))
+     return false;
+
+   return true;
+ }
+
+ #define ELF_ARCH		bfd_arch_mmix
+ #define ELF_MACHINE_CODE 	EM_MMIX
+
+ /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
+    However, that's too much for something somewhere in the linker part of
+    BFD; perhaps the start-address has to be a non-zero multiple of this
+    number, or larger than this number.  The symptom is that the linker
+    complains: "warning: allocated section `.text' not in segment".  We
+    settle for 64k; the page-size used in examples is 8k.
+    #define ELF_MAXPAGESIZE 0x10000
+
+    Unfortunately, this causes excessive padding in the supposedly small
+    for-education programs that are the expected usage (where people would
+    inspect output).  We stick to 256 bytes just to have *some* default
+    alignment.  */
+ #define ELF_MAXPAGESIZE 0x100
+
+ #define TARGET_BIG_SYM		bfd_elf64_mmix_vec
+ #define TARGET_BIG_NAME		"elf64-mmix"
+
+ #define elf_info_to_howto_rel		NULL
+ #define elf_info_to_howto		mmix_info_to_howto_rela
+ #define elf_backend_relocate_section	mmix_elf_relocate_section
+ #define elf_backend_gc_mark_hook	mmix_elf_gc_mark_hook
+ #define elf_backend_link_output_symbol_hook \
+ 	mmix_elf_link_output_symbol_hook
+ #define elf_backend_add_symbol_hook	mmix_elf_add_symbol_hook
+
+ #define elf_backend_check_relocs	mmix_elf_check_relocs
+ #define elf_backend_symbol_processing	mmix_elf_symbol_processing
+
+ #define bfd_elf64_bfd_is_local_label_name \
+ 	mmix_elf_is_local_label_name
+
+ #define elf_backend_may_use_rel_p	0
+ #define elf_backend_may_use_rela_p	1
+ #define elf_backend_default_use_rela_p	1
+
+ #define elf_backend_can_gc_sections	1
+ #define elf_backend_section_from_bfd_section \
+ 	mmix_elf_section_from_bfd_section
+
+ #define bfd_elf64_bfd_final_link	mmix_elf_final_link
+
+ #include "elf64-target.h"
*** /dev/null	Tue Jan  1 05:00:00 1980
--- mmo.c	Fri Sep 21 02:39:58 2001
***************
*** 0 ****
--- 1,3274 ----
+ /* BFD back-end for mmo objects (MMIX-specific object-format).
+    Copyright 2001
+    Free Software Foundation, Inc.
+    Written by Hans-Peter Nilsson (hp@bitrange.com).
+    Infrastructure and other bits originally copied from srec.c and
+    binary.c.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+ /*
+ SECTION
+ 	mmo backend
+
+ 	The mmo object format is used exclusively together with Professor
+ 	Donald E.@: Knuth's educational 64-bit processor MMIX.  The simulator
+ 	@command{mmix} which is available at
+ 	@url{http://www-cs-faculty.stanford.edu/~knuth/programs/mmix.tar.gz}
+ 	understands this format.  That package also includes a combined
+ 	assembler and linker called @command{mmixal}.  The mmo format has
+ 	no advantages feature-wise compared to e.g. ELF.  It is a simple
+ 	non-relocatable object format with no support for archives or
+ 	debugging information, except for symbol value information and
+ 	line numbers (which is not yet implemented in BFD).  See
+ 	@url{http://www-cs-faculty.stanford.edu/~knuth/mmix.html} for more
+ 	information about MMIX.  The ELF format is used for intermediate
+ 	object files in the BFD implementation.
+
+ @menu
+ @* File layout::
+ @c We want to xref the symbol table node.  A feature in "chew"
+ @c requires that "commands" do not contain spaces in the
+ @c arguments.  Hence the hyphen in "Symbol-table".
+ @* Symbol-table::
+ @* mmo section mapping::
+ @end menu
+
+ INODE
+ File layout, Symbol-table, mmo, mmo
+ SUBSECTION
+ 	File layout
+
+ 	The mmo file contents is not partitioned into named sections as
+ 	with e.g.@: ELF.  Memory areas is formed by specifying the
+ 	location of the data that follows.  Only the memory area
+ 	@samp{0x0000@dots{}00} to @samp{0x01ff@dots{}ff} is executable, so
+ 	it is used for code (and constants) and the area
+ 	@samp{0x2000@dots{}00} to @samp{0x20ff@dots{}ff} is used for
+ 	writable data.  @xref{mmo section mapping}.
+
+ 	Contents is entered as 32-bit words, xor:ed over previous
+ 	contents, always zero-initialized.  A word that starts with the
+ 	byte @samp{0x98} forms a command called a @samp{lopcode}, where
+ 	the next byte distinguished between the thirteen lopcodes.  The
+ 	two remaining bytes, called the @samp{Y} and @samp{Z} fields, or
+ 	the @samp{YZ} field (a 16-bit big-endian number), are used for
+ 	various purposes different for each lopcode.  As documented in
+ 	@url{http://www-cs-faculty.stanford.edu/~knuth/mmixal-intro.ps.gz},
+ 	the lopcodes are:
+
+ 	There is provision for specifying ``special data'' of 65536
+ 	different types.  We use type 80 (decimal), arbitrarily chosen the
+ 	same as the ELF <<e_machine>> number for MMIX, filling it with
+ 	section information normally found in ELF objects. @xref{mmo
+ 	section mapping}.
+
+ 	@table @code
+ 	@item lop_quote
+ 	0x98000001.  The next word is contents, regardless of whether it
+ 	starts with 0x98 or not.
+
+ 	@item lop_loc
+ 	0x9801YYZZ, where @samp{Z} is 1 or 2.  This is a location
+ 	directive, setting the location for the next data to the next
+ 	32-bit word (for @math{Z = 1}) or 64-bit word (for @math{Z = 2}),
+ 	plus @math{Y * 2^56}.  Normally @samp{Y} is 0 for the text segment
+ 	and 2 for the data segment.
+
+ 	@item lop_skip
+ 	0x9802YYZZ.  Increase the current location by @samp{YZ} bytes.
+
+ 	@item lop_fixo
+ 	0x9803YYZZ, where @samp{Z} is 1 or 2.  Store the current location
+ 	as 64 bits into the location pointed to by the next 32-bit
+ 	(@math{Z = 1}) or 64-bit (@math{Z = 2}) word, plus @math{Y *
+ 	2^56}.
+
+ 	@item lop_fixr
+ 	0x9804YYZZ.  @samp{YZ} is stored into the current location plus
+ 	@math{2 - 4 * YZ}.
+
+ 	@item lop_fixrx
+ 	0x980500ZZ.  @samp{Z} is 16 or 24.  A value @samp{L} derived from
+ 	the following 32-bit word are used in a manner similar to
+ 	@samp{YZ} in lop_fixr: it is xor:ed into the current location
+ 	minus @math{4 * L}.  The first byte of the word is 0 or 1.  If it
+ 	is 1, then @math{L = (@var{lowest 24 bits of word}) - 2^Z}, if 0,
+  	then @math{L = (@var{lowest 24 bits of word})}.
+
+ 	@item lop_file
+ 	0x9806YYZZ.  @samp{Y} is the file number, @samp{Z} is count of
+ 	32-bit words.  Set the file number to @samp{Y} and the line
+ 	counter to 0.  The next @math{Z * 4} bytes contain the file name,
+ 	padded with zeros if the count is not a multiple of four.  The
+ 	same @samp{Y} may occur multiple times, but @samp{Z} must be 0 for
+ 	all but the first occurrence.
+
+ 	@item lop_line
+ 	0x9807YYZZ.  @samp{YZ} is the line number.  Together with
+ 	lop_file, it forms the source location for the next 32-bit word.
+ 	Note that for each non-lopcode 32-bit word, line numbers are
+ 	assumed incremented by one.
+
+ 	@item lop_spec
+ 	0x9808YYZZ.  @samp{YZ} is the type number.  Data until the next
+ 	lopcode other than lop_quote forms special data of type @samp{YZ}.
+ 	@xref{mmo section mapping}.
+
+ 	Other types than 80, (or type 80 with a content that does not
+ 	parse) is stored in sections named <<.MMIX.spec_data.@var{n}>>
+ 	where @var{n} is the @samp{YZ}-type.  The flags for such a
+ 	sections say not to allocate or load the data.  The vma is 0.
+ 	Contents of multiple occurrences of special data @var{n} is
+ 	concatenated to the data of the previous lop_spec @var{n}s.  The
+ 	location in data or code at which the lop_spec occurred is lost.
+
+ 	@item lop_pre
+ 	0x980901ZZ.  The first lopcode in a file.  The @samp{Z} field forms the
+ 	length of header information in 32-bit words, where the first word
+ 	tells the time in seconds since @samp{00:00:00 GMT Jan 1 1970}.
+
+ 	@item lop_post
+ 	0x980a00ZZ.  @math{Z > 32}.  This lopcode follows after all
+ 	content-generating lopcodes in a program.  The @samp{Z} field
+ 	denotes the value of @samp{rG} at the beginning of the program.
+ 	The following @math{256 - Z} big-endian 64-bit words are loaded
+ 	into global registers @samp{$G} @dots{} @samp{$255}.
+
+ 	@item lop_stab
+ 	0x980b0000.  The next-to-last lopcode in a program.  Must follow
+ 	immediately after the lop_post lopcode and its data.  After this
+ 	lopcode follows all symbols in a compressed format
+ 	(@pxref{Symbol-table}).
+
+ 	@item lop_end
+ 	0x980cYYZZ.  The last lopcode in a program.  It must follow the
+ 	lop_stab lopcode and its data.  The @samp{YZ} field contains the
+ 	number of 32-bit words of symbol table information after the
+ 	preceding lop_stab lopcode.
+ 	@end table
+
+ 	Note that the lopcode "fixups"; <<lop_fixr>>, <<lop_fixrx>> and
+ 	<<lop_fixo>> are not generated by BFD, but are handled.  They are
+ 	generated by <<mmixal>>.
+
+ EXAMPLE
+ 	This trivial one-label, one-instruction file:
+
+ | :Main TRAP 1,2,3
+
+ 	can be represented this way in mmo:
+
+ | 0x98090101 - lop_pre, one 32-bit word with timestamp.
+ | <timestamp>
+ | 0x98010002 - lop_loc, text segment, using a 64-bit address.
+ |              Note that mmixal does not emit this for the file above.
+ | 0x00000000 - Address, high 32 bits.
+ | 0x00000000 - Address, low 32 bits.
+ | 0x98060002 - lop_file, 2 32-bit words for file-name.
+ | 0x74657374 - "test"
+ | 0x2e730000 - ".s\0\0"
+ | 0x98070001 - lop_line, line 1.
+ | 0x00010203 - TRAP 1,2,3
+ | 0x980a00ff - lop_post, setting $255 to 0.
+ | 0x00000000
+ | 0x00000000
+ | 0x980b0000 - lop_stab for ":Main" = 0, serial 1.
+ | 0x203a4040   @xref{Symbol-table}.
+ | 0x10404020
+ | 0x4d206120
+ | 0x69016e00
+ | 0x81000000
+ | 0x980c0005 - lop_end; symbol table contained five 32-bit words.  */
+
+ #include "bfd.h"
+ #include "sysdep.h"
+ #include "libbfd.h"
+ #include "libiberty.h"
+ #include "elf/mmix.h"
+ #include "opcode/mmix.h"
+ #include <ctype.h>
+
+ #define LOP 0x98
+ #define LOP_QUOTE 0
+ #define LOP_LOC 1
+ #define LOP_SKIP 2
+ #define LOP_FIXO 3
+ #define LOP_FIXR 4
+ #define LOP_FIXRX 5
+ #define LOP_FILE 6
+ #define LOP_LINE 7
+ #define LOP_SPEC 8
+ #define LOP_PRE 9
+ #define LOP_POST 10
+ #define LOP_STAB 11
+ #define LOP_END 12
+
+ #define LOP_QUOTE_NEXT ((LOP << 24) | (LOP_QUOTE << 16) | 1)
+ #define SPEC_DATA_SECTION 80
+ #define LOP_SPEC_SECTION \
+  ((LOP << 24) | (LOP_SPEC << 16) | SPEC_DATA_SECTION)
+
+ /* Must be a power of two.  If you change this to be >= 64k, you need a
+    new test-case; the ld test b-loc64k.d touches chunk-size problem areas.  */
+ #define MMO_SEC_CONTENTS_CHUNK_SIZE (1 << 15)
+
+ /* An arbitrary number for the maximum length section name size.  */
+ #define MAX_SECTION_NAME_SIZE (1024 * 1024)
+
+ /* A quite arbitrary number for the maximum length section size.  */
+ #define MAX_ARTIFICIAL_SECTION_SIZE (1024 * 1024 * 1024)
+
+ #define MMO3_WCHAR 0x80
+ #define MMO3_LEFT 0x40
+ #define MMO3_MIDDLE 0x20
+ #define MMO3_RIGHT 0x10
+ #define MMO3_TYPEBITS 0xf
+ #define MMO3_REGQUAL_BITS 0xf
+ #define MMO3_UNDEF 2
+ #define MMO3_DATA 8
+ #define MMO3_SYMBITS 0x2f
+
+ /* Put these everywhere in new code.  */
+ #define FATAL_DEBUG						\
+  _bfd_abort (__FILE__, __LINE__,				\
+ 	     "Internal: Non-debugged code (test-case missing)")
+
+ #define BAD_CASE(x)				\
+  _bfd_abort (__FILE__, __LINE__,		\
+ 	     "bad case for " #x)
+
+ enum mmo_sym_type { mmo_reg_sym, mmo_undef_sym, mmo_data_sym, mmo_abs_sym};
+
+ /* When scanning the mmo file, a linked list of mmo_symbol
+    structures is built to represent the symbol table (if there is
+    one).  */
+
+ struct mmo_symbol
+   {
+     struct mmo_symbol *next;
+     CONST char *name;
+     bfd_vma value;
+     enum mmo_sym_type sym_type;
+     unsigned int serno;
+   };
+
+ struct mmo_data_list_struct
+   {
+     struct mmo_data_list_struct *next;
+     bfd_vma where;
+     bfd_size_type size;
+     bfd_size_type allocated_size;
+     bfd_byte data[1];
+   };
+
+ typedef struct mmo_data_list_struct mmo_data_list_type;
+
+ struct mmo_symbol_trie
+   {
+     struct mmo_symbol_trie *left;
+     struct mmo_symbol_trie *right;
+     struct mmo_symbol_trie *middle;
+
+     bfd_byte symchar;
+
+     /* A zero name means there's nothing here.  */
+     struct mmo_symbol sym;
+   };
+
+ /* The mmo tdata information.  */
+
+ struct mmo_data_struct
+   {
+     struct mmo_symbol *symbols;
+     struct mmo_symbol *symtail;
+     asymbol *csymbols;
+
+     /* File representation of time (NULL) when this file was created.  */
+     bfd_byte created[4];
+
+     /* When we're reading bytes recursively, check this occasionally.
+        Also holds write errors.  */
+     boolean have_error;
+
+     /* Max symbol length that may appear in the lop_stab table.  Note that
+        this table might just hold a subset of symbols for not-really large
+        programs, as it can only be 65536 * 4 bytes large.  */
+     int max_symbol_length;
+
+     /* Here's the symbol we build in lop_stab.  */
+     char *lop_stab_symbol;
+
+     /* Index into lop_stab_symbol for the next character when parsing the
+        symbol information.  */
+     int symbol_position;
+
+     /* When creating arbitrary sections, we need to count section numbers.  */
+     int sec_no;
+
+     /* When writing or reading byte-wise, we need to count the bytes
+        within a 32-bit word.  */
+     int byte_no;
+
+     /* We also need a buffer to hold the bytes we count reading or writing.  */
+     bfd_byte buf[4];
+   };
+
+ typedef struct mmo_data_struct tdata_type;
+
+ struct mmo_section_data_struct
+   {
+     mmo_data_list_type *head;
+     mmo_data_list_type *tail;
+   };
+
+ /* These structures are used in bfd_map_over_sections constructs.  */
+
+ /* Used when writing out sections; all but the register contents section
+    which is stored in reg_section.  */
+ struct mmo_write_sec_info
+   {
+     asection *reg_section;
+     boolean retval;
+   };
+
+ /* Used when trying to find a section corresponding to addr.  */
+ struct mmo_find_sec_info
+   {
+     asection *sec;
+     bfd_vma addr;
+   };
+
+ static boolean mmo_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
+ static void mmo_write_section_unless_reg_contents
+  PARAMS ((bfd *, asection *, PTR));
+ static void mmo_find_sec_w_addr PARAMS ((bfd *, asection *, PTR));
+ static void mmo_find_sec_w_addr_grow PARAMS ((bfd *, asection *, PTR));
+ static asection *mmo_make_section PARAMS ((bfd *, CONST char *));
+ static void mmo_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
+ static void mmo_print_symbol
+  PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
+ static void mmo_init PARAMS ((void));
+ static boolean mmo_mkobject PARAMS ((bfd *));
+ static boolean mmo_scan PARAMS ((bfd *));
+ static asection *mmo_decide_section PARAMS ((bfd *, bfd_vma));
+ static asection *mmo_get_generic_spec_data_section PARAMS ((bfd *, int));
+ static asection *mmo_get_spec_section PARAMS ((bfd *, int));
+ static INLINE bfd_byte *mmo_get_loc PARAMS ((asection *, bfd_vma, int));
+ static void mmo_xore_64 PARAMS ((asection *, bfd_vma vma, bfd_vma value));
+ static void mmo_xore_32 PARAMS ((asection *, bfd_vma vma, unsigned int));
+ static void mmo_xore_16 PARAMS ((asection *, bfd_vma vma, unsigned int));
+ static CONST bfd_target *mmo_object_p PARAMS ((bfd *));
+ static void mmo_map_set_sizes PARAMS ((bfd *, asection *, PTR));
+ static boolean mmo_get_symbols PARAMS ((bfd *));
+ static boolean mmo_create_symbol PARAMS ((bfd *, CONST char *, bfd_vma,
+ 					  enum mmo_sym_type, unsigned int));
+ static boolean mmo_get_section_contents
+   PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
+ static long mmo_get_symtab_upper_bound PARAMS ((bfd *));
+ static long mmo_get_symtab PARAMS ((bfd *, asymbol **));
+ static asymbol *mmo_make_empty_symbol PARAMS ((bfd *));
+ static void mmo_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
+ static void mmo_print_symbol PARAMS ((bfd *, PTR, asymbol *,
+ 				      bfd_print_symbol_type));
+ static boolean mmo_set_section_contents
+   PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
+ static int mmo_sizeof_headers PARAMS ((bfd *, boolean));
+ static long mmo_get_reloc_upper_bound PARAMS ((bfd *, asection *));
+
+ static boolean mmo_internal_write_header PARAMS ((bfd *));
+ static boolean mmo_internal_write_post PARAMS ((bfd *, int, asection *));
+ static boolean mmo_internal_add_3_sym
+  PARAMS ((bfd *, struct mmo_symbol_trie *, CONST struct mmo_symbol *));
+ static unsigned int mmo_internal_3_length
+  PARAMS ((bfd *, struct mmo_symbol_trie *));
+ static void mmo_internal_3_dump
+  PARAMS ((bfd *, struct mmo_symbol_trie *));
+ static void mmo_beb128_out PARAMS ((bfd *, int, int));
+ static boolean mmo_internal_write_section
+   PARAMS ((bfd *, asection *));
+ static void mmo_write_tetra PARAMS ((bfd *, unsigned int));
+ static void mmo_write_tetra_raw PARAMS ((bfd *, unsigned int));
+ static void mmo_write_octa PARAMS ((bfd *, bfd_vma));
+ static void mmo_write_octa_raw PARAMS ((bfd *, bfd_vma));
+ static boolean mmo_write_chunk
+   PARAMS ((bfd *, CONST bfd_byte *, unsigned int));
+ static boolean mmo_write_loc_chunk
+   PARAMS ((bfd *, bfd_vma, CONST bfd_byte *, unsigned int));
+ static boolean mmo_write_chunk_list PARAMS ((bfd *, mmo_data_list_type *));
+ static boolean mmo_write_loc_chunk_list
+   PARAMS ((bfd *, mmo_data_list_type *));
+ static boolean mmo_write_symbols_and_terminator PARAMS ((bfd *));
+ static flagword mmo_sec_flags_from_bfd_flags PARAMS ((flagword));
+ static flagword bfd_sec_flags_from_mmo_flags PARAMS ((flagword));
+ static bfd_byte mmo_get_byte PARAMS ((bfd *));
+ static void mmo_write_byte PARAMS ((bfd *, bfd_byte));
+ static boolean mmo_new_section_hook PARAMS ((bfd *, asection *));
+ static int mmo_sort_mmo_symbols PARAMS ((CONST PTR, CONST PTR));
+ static boolean mmo_write_object_contents PARAMS ((bfd *));
+ static long mmo_canonicalize_reloc
+   PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
+
+ /* Global "const" variables initialized once.  Must not depend on
+    particular input or caller; put such things into the bfd or elsewhere.
+    Look ma, no static per-invocation data!  */
+
+ static unsigned
+ char valid_mmo_symbol_character_set[/* A-Z a-z (we assume consecutive
+ 				       codes; sorry EBCDIC:ers!).  */
+ 				    + 'Z' - 'A' + 1 + 'z' - 'a' + 1
+ 				    /* Digits.  */
+ 				    + 10
+ 				    /* ':' and '_'.  */
+ 				    + 1 + 1
+ 				    /* Codes higher than 126.  */
+ 				    + 256 - 126
+ 				    /* Ending zero.  */
+ 				    + 1];
+
+
+ /* Get section SECNAME or create one if it doesn't exist.  When creating
+    one, new memory for the name is allocated.  */
+
+ static asection *
+ mmo_make_section (abfd, secname)
+      bfd *abfd;
+      CONST char *secname;
+ {
+   asection *sec = bfd_get_section_by_name (abfd, secname);
+
+   if (sec == NULL)
+     {
+       char *newsecname = strdup (secname);
+
+       if (newsecname == NULL)
+ 	{
+ 	  (*_bfd_error_handler)
+ 	    (_("%s: No core to allocate section name %s\n"),
+ 	     bfd_get_filename (abfd), secname);
+ 	  bfd_set_error (bfd_error_system_call);
+ 	  return NULL;
+ 	}
+       sec = bfd_make_section (abfd, newsecname);
+     }
+
+   return sec;
+ }
+
+ /* Nothing to do, but keep as a placeholder if we need it.
+    Note that state that might differ between bfd:s must not be initialized
+    here, nor must it be static.  Add it to tdata information instead.  */
+
+ static void
+ mmo_init ()
+ {
+   static boolean inited = false;
+   int i = 0;
+   int j = 0;
+   static const char letters[]
+     = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:_";
+
+   if (inited == false)
+     {
+       inited = true;
+     }
+
+   /* Fill in the set of valid symbol characters.  */
+   strcpy (valid_mmo_symbol_character_set, letters);
+   i = strlen (letters);
+
+   for (j = 126; j < 256; j++)
+     valid_mmo_symbol_character_set[i++] = j;
+ }
+
+ /* Check whether an existing file is an mmo file.  */
+
+ static CONST bfd_target *
+ mmo_object_p (abfd)
+      bfd *abfd;
+ {
+   struct stat statbuf;
+   bfd_byte b[4];
+
+   mmo_init ();
+
+   if (bfd_stat (abfd, &statbuf) < 0
+       || bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
+       || bfd_bread (b, 4, abfd) != 4)
+     goto bad_final;
+
+   /* All mmo files are a multiple of four bytes long.
+      Only recognize version one.  */
+   if ((statbuf.st_size % 4) != 0
+       || b[0] != LOP || b[1] != LOP_PRE || b[2] != 1)
+     goto bad_format;
+
+   /* Get the last 32-bit word.  */
+   if (bfd_seek (abfd, (file_ptr) statbuf.st_size - 4, SEEK_SET) != 0
+       || bfd_bread (b, 4, abfd) != 4)
+     goto bad_final;
+
+   /* Check if the file ends in a lop_end lopcode. */
+   if (b[0] != LOP || b[1] != LOP_END || ! mmo_mkobject (abfd))
+     goto bad_format;
+
+   /* Compute an upper bound on the max symbol length.  Not really
+      important as all of the symbol information can only be 256k.  */
+   abfd->tdata.mmo_data->max_symbol_length = (b[2] * 256 + b[3]) * 4;
+   abfd->tdata.mmo_data->lop_stab_symbol
+     = bfd_malloc (abfd->tdata.mmo_data->max_symbol_length + 1);
+
+   if (abfd->tdata.mmo_data->lop_stab_symbol == NULL)
+     {
+       (*_bfd_error_handler)
+ 	(_("%s: No core to allocate a symbol %d bytes long\n"),
+ 	 bfd_get_filename (abfd), abfd->tdata.mmo_data->max_symbol_length);
+       goto bad_final;
+     }
+
+   /* Read in everything.  */
+   if (! mmo_scan (abfd))
+     goto bad_format_free;
+
+   if (abfd->symcount > 0)
+     abfd->flags |= HAS_SYMS;
+
+   /* You'll have to tweak this if you want to use this format for other
+      arches (not recommended due to its small-size limitations).  Look at
+      the ELF format for how to make it target-generic.  */
+   if (! bfd_default_set_arch_mach (abfd, bfd_arch_mmix, 0))
+     goto bad_format_free;
+
+   return abfd->xvec;
+
+  bad_format_free:
+   free (abfd->tdata.mmo_data->lop_stab_symbol);
+  bad_format:
+   bfd_set_error (bfd_error_wrong_format);
+  bad_final:
+   return NULL;
+ }
+
+ /* Set up the mmo tdata information.  */
+
+ static boolean
+ mmo_mkobject (abfd)
+      bfd *abfd;
+ {
+   mmo_init ();
+
+   if (abfd->tdata.mmo_data == NULL)
+     {
+       time_t created;
+
+       /* All fields are zero-initialized, so we don't have to explicitly
+ 	 initialize most.  */
+       tdata_type *tdata = (tdata_type *) bfd_zmalloc (sizeof (tdata_type));
+       if (tdata == NULL)
+ 	return false;
+
+       created = time (NULL);
+       bfd_put_32 (abfd, created, tdata->created);
+
+       abfd->tdata.mmo_data = tdata;
+     }
+
+   return true;
+ }
+
+ static boolean
+ mmo_bfd_copy_private_bfd_data (ibfd, obfd)
+      bfd *ibfd;
+      bfd *obfd;
+ {
+   if (bfd_get_flavour (ibfd) != bfd_target_mmo_flavour
+       || bfd_get_flavour (obfd) != bfd_target_mmo_flavour)
+     return true;
+
+   /* Copy the time the copied-from file was created.  If people want the
+      time the file was last *modified*, they have that in the normal file
+      information.  */
+   memcpy (obfd->tdata.mmo_data->created, ibfd->tdata.mmo_data->created,
+ 	  sizeof (obfd->tdata.mmo_data->created));
+   return true;
+ }
+
+ /* Helper functions for mmo_decide_section, used through
+    bfd_map_over_sections.  */
+
+ static void
+ mmo_find_sec_w_addr (abfd, sec, p)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asection *sec;
+      PTR p;
+ {
+   struct mmo_find_sec_info *infop = (struct mmo_find_sec_info *) p;
+   bfd_vma vma = bfd_get_section_vma (abfd, sec);
+
+   /* Ignore sections that aren't loaded.  */
+   if ((bfd_get_section_flags (abfd, sec) & (SEC_LOAD | SEC_ALLOC))
+       !=  (SEC_LOAD | SEC_ALLOC))
+     return;
+
+   if (infop->addr >= vma && infop->addr < vma + sec->_raw_size)
+     infop->sec = sec;
+ }
+
+ static void
+ mmo_find_sec_w_addr_grow (abfd, sec, p)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asection *sec;
+      PTR p;
+ {
+   struct mmo_find_sec_info *infop = (struct mmo_find_sec_info *) p;
+   bfd_vma vma = bfd_get_section_vma (abfd, sec);
+
+   /* Ignore sections that aren't loaded.  */
+   if ((bfd_get_section_flags (abfd, sec) & (SEC_LOAD | SEC_ALLOC))
+       !=  (SEC_LOAD | SEC_ALLOC))
+     return;
+
+   if (infop->addr >= vma && infop->addr < vma + MAX_ARTIFICIAL_SECTION_SIZE)
+     infop->sec = sec;
+ }
+
+ /* Find a section that corresponds to a VMA.  Automatically create .text
+    or .data and set current section to it, depending on what vma.  If we
+    can't deduce a section, make one up as ".MMIX.sec.N", where N is an
+    increasing number.  */
+
+ static asection *
+ mmo_decide_section (abfd, vma)
+      bfd *abfd;
+      bfd_vma vma;
+ {
+   asection *sec = NULL;
+   char sec_name[sizeof (".MMIX.sec.") + 20];
+   struct mmo_find_sec_info info;
+
+   info.addr = vma;
+   info.sec = NULL;
+
+   /* First see if there's a section that would match exactly.  */
+   bfd_map_over_sections (abfd, mmo_find_sec_w_addr, &info);
+
+   if (info.sec != NULL)
+     return info.sec;
+
+   /* If there's no such section, try and expand one of the existing ones,
+      up to a limit.  Make sure we have .text and .data before we try that;
+      create them corresponding to expected addresses and set flags to make
+      them match the "loaded and with contents" expectation.  */
+   if ((vma >> 56) == 0)
+     {
+       sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
+
+       if (sec == NULL)
+ 	return NULL;
+
+       if (! sec->user_set_vma)
+ 	bfd_set_section_vma (abfd, sec, vma);
+       if (! bfd_set_section_flags (abfd, sec,
+ 				   bfd_get_section_flags (abfd, sec)
+ 				   | SEC_CODE | SEC_LOAD | SEC_ALLOC))
+ 	return NULL;
+     }
+   else if ((vma >> 56) == 0x20)
+     {
+       sec = bfd_make_section_old_way (abfd, MMO_DATA_SECTION_NAME);
+
+       if (sec == NULL)
+ 	return NULL;
+
+       if (! sec->user_set_vma)
+ 	bfd_set_section_vma (abfd, sec, vma);
+       if (! bfd_set_section_flags (abfd, sec,
+ 				   bfd_get_section_flags (abfd, sec)
+ 				   | SEC_LOAD | SEC_ALLOC))
+ 	return NULL;
+     }
+
+   bfd_map_over_sections (abfd, mmo_find_sec_w_addr_grow, &info);
+
+   if (info.sec != NULL)
+     return info.sec;
+
+   /* If there's still no suitable section, make a new one.  */
+   sprintf (sec_name, ".MMIX.sec.%d", abfd->tdata.mmo_data->sec_no++);
+   sec = mmo_make_section (abfd, sec_name);
+   if (! sec->user_set_vma)
+     bfd_set_section_vma (abfd, sec, vma);
+
+   if (! bfd_set_section_flags (abfd, sec,
+ 			       bfd_get_section_flags (abfd, sec)
+ 			       | SEC_LOAD | SEC_ALLOC))
+     return NULL;
+   return sec;
+ }
+
+ /* Xor in a 64-bit value VALUE at VMA.  */
+
+ static INLINE void
+ mmo_xore_64 (sec, vma, value)
+      asection *sec;
+      bfd_vma vma;
+      bfd_vma value;
+ {
+   bfd_byte *loc = mmo_get_loc (sec, vma, 8);
+   bfd_vma prev = bfd_get_64 (sec->owner, loc);
+
+   value ^= prev;
+   bfd_put_64 (sec->owner, value, loc);
+ }
+
+ /* Xor in a 32-bit value VALUE at VMA.  */
+
+ static INLINE void
+ mmo_xore_32 (sec, vma, value)
+      asection *sec;
+      bfd_vma vma;
+      unsigned int value;
+ {
+   bfd_byte *loc = mmo_get_loc (sec, vma, 4);
+   unsigned int prev = bfd_get_32 (sec->owner, loc);
+
+   value ^= prev;
+   bfd_put_32 (sec->owner, value, loc);
+ }
+
+ /* Xor in a 16-bit value VALUE at VMA.  */
+
+ static INLINE void
+ mmo_xore_16 (sec, vma, value)
+      asection *sec;
+      bfd_vma vma;
+      unsigned int value;
+ {
+   bfd_byte *loc = mmo_get_loc (sec, vma, 2);
+   unsigned int prev = bfd_get_16 (sec->owner, loc);
+
+   value ^= prev;
+   bfd_put_16 (sec->owner, value, loc);
+ }
+
+ /* Write a 32-bit word to output file, no lop_quote generated.  */
+
+ static INLINE void
+ mmo_write_tetra_raw (abfd, value)
+      bfd *abfd;
+      unsigned int value;
+ {
+   bfd_byte buf[4];
+
+   bfd_put_32 (abfd, value, buf);
+
+   if (bfd_bwrite ((PTR) buf, 4, abfd) != 4)
+     abfd->tdata.mmo_data->have_error = true;
+ }
+
+ /* Write a 32-bit word to output file; lop_quote if necessary.  */
+
+ static INLINE void
+ mmo_write_tetra (abfd, value)
+      bfd *abfd;
+      unsigned int value;
+ {
+   if (((value >> 24) & 0xff) == LOP)
+     mmo_write_tetra_raw (abfd, LOP_QUOTE_NEXT);
+
+   mmo_write_tetra_raw (abfd, value);
+ }
+
+ /* Write a 64-bit word to output file, perhaps with lop_quoting.  */
+
+ static INLINE void
+ mmo_write_octa (abfd, value)
+      bfd *abfd;
+      bfd_vma value;
+ {
+   mmo_write_tetra (abfd, (unsigned int) (value >> 32));
+   mmo_write_tetra (abfd, (unsigned int) value);
+ }
+
+ /* Write a 64-bit word to output file, without lop_quoting.  */
+
+ static INLINE void
+ mmo_write_octa_raw (abfd, value)
+      bfd *abfd;
+      bfd_vma value;
+ {
+   mmo_write_tetra_raw (abfd, (unsigned int) (value >> 32));
+   mmo_write_tetra_raw (abfd, (unsigned int) value);
+ }
+
+ /* Write quoted contents, zero filled.  */
+
+ static INLINE boolean
+ mmo_write_chunk (abfd, loc, len)
+      bfd *abfd;
+      CONST bfd_byte *loc;
+      unsigned int len;
+ {
+   boolean retval = true;
+   bfd_byte buf[4] = {0, 0, 0, 0};
+
+   while (len >= 4)
+     {
+       if (loc[0] == LOP)
+ 	mmo_write_tetra_raw (abfd, LOP_QUOTE_NEXT);
+
+       retval
+ 	= (retval == true
+ 	   && abfd->tdata.mmo_data->have_error == false
+ 	   && 4 == bfd_bwrite ((PTR) loc, 4, abfd));
+
+       loc += 4;
+       len -= 4;
+     }
+
+   if (len)
+     {
+       memcpy (buf, loc, len);
+       if (buf[0] == LOP)
+ 	mmo_write_tetra_raw (abfd, LOP_QUOTE_NEXT);
+
+       retval
+ 	= (retval == true
+ 	   && abfd->tdata.mmo_data->have_error == false
+ 	   && 4 == bfd_bwrite ((PTR) buf, 4, abfd));
+     }
+
+   return retval;
+ }
+
+ /* Same, but from a list.  */
+
+ static INLINE boolean
+ mmo_write_chunk_list (abfd, datap)
+      bfd *abfd;
+      mmo_data_list_type *datap;
+ {
+   for (; datap != NULL; datap = datap->next)
+     if (! mmo_write_chunk (abfd, datap->data, datap->size))
+       return false;
+
+   return true;
+ }
+
+ /* Write a lop_loc and some contents.  */
+
+ static boolean
+ mmo_write_loc_chunk (abfd, vma, loc, len)
+      bfd *abfd;
+      bfd_vma vma;
+      CONST bfd_byte *loc;
+      unsigned int len;
+ {
+   /* We always write the location as 64 bits; no use saving bytes here.  */
+   mmo_write_tetra_raw (abfd, (LOP << 24) | (LOP_LOC << 16) | 2);
+
+   /* Find an initial and trailing section of zero tetras; we don't need to
+      write out zeros.  FIXME: When we do this, we should emit section size
+      and address specifiers, else objcopy can't perform a unity
+      translation.  */
+   while (len >= 4 && bfd_get_32 (abfd, loc) == 0)
+     {
+       vma += 4;
+       len -= 4;
+       loc += 4;
+     }
+
+   while (len >= 4 && bfd_get_32 (abfd, loc + len - 4) == 0)
+     len -= 4;
+
+   mmo_write_octa_raw (abfd, vma);
+   return
+     abfd->tdata.mmo_data->have_error == false
+     && mmo_write_chunk (abfd, loc, len);
+ }
+
+ /* Same, but from a list.  */
+
+ static INLINE boolean
+ mmo_write_loc_chunk_list (abfd, datap)
+      bfd *abfd;
+      mmo_data_list_type *datap;
+ {
+   for (; datap != NULL; datap = datap->next)
+     if (! mmo_write_loc_chunk (abfd, datap->where, datap->data, datap->size))
+       return false;
+
+   return true;
+ }
+
+ /* Make a .MMIX.spec_data.N section.  */
+
+ static asection *
+ mmo_get_generic_spec_data_section (abfd, spec_data_number)
+      bfd *abfd;
+      int spec_data_number;
+ {
+   asection *sec;
+   char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20]
+     = MMIX_OTHER_SPEC_SECTION_PREFIX;
+
+   sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX),
+ 	   "%d", spec_data_number);
+
+   sec = mmo_make_section (abfd, secname);
+
+   return sec;
+ }
+
+ /* Make a special section for SPEC_DATA_NUMBER.  If it is the one we use
+    ourselves, parse some of its data to get at the section name.  */
+
+ static asection *
+ mmo_get_spec_section (abfd, spec_data_number)
+      bfd *abfd;
+      int spec_data_number;
+ {
+   bfd_byte *secname;
+   asection *sec;
+   bfd_byte buf[4];
+   unsigned int secname_length;
+   unsigned int i;
+   bfd_vma section_length;
+   bfd_vma section_vma;
+   mmo_data_list_type *loc;
+   flagword flags;
+   long orig_pos;
+
+   /* If this isn't the "special" special data, then make a placeholder
+      section.  */
+   if (spec_data_number != SPEC_DATA_SECTION)
+     return mmo_get_generic_spec_data_section (abfd, spec_data_number);
+
+   /* Seek back to this position if there was a format error.  */
+   orig_pos = bfd_tell (abfd);
+
+   /* Read the length (in 32-bit words).  */
+   if (bfd_bread (buf, 4, abfd) != 4)
+     goto format_error;
+
+   if (buf[0] == LOP)
+     {
+       if (buf[1] != LOP_QUOTE)
+ 	goto format_error;
+
+       if (bfd_bread (buf, 4, abfd) != 4)
+ 	goto format_error;
+     }
+
+   /* We don't care to keep the name length accurate.  It's
+      zero-terminated.  */
+   secname_length = bfd_get_32 (abfd, buf) * 4;
+
+   /* Check section name length for sanity.  */
+   if (secname_length > MAX_SECTION_NAME_SIZE)
+     goto format_error;
+
+   /* This should be free'd regardless if a section is created.  */
+   secname = bfd_malloc (secname_length + 1);
+   secname[secname_length] = 0;
+
+   for (i = 0; i < secname_length / 4; i++)
+     {
+       if (bfd_bread (secname + i * 4, 4, abfd) != 4)
+ 	goto format_error_free;
+
+       if (secname[i * 4] == LOP)
+ 	{
+ 	  /* A bit of overkill, but we handle char 0x98 in a section name,
+ 	     and recognize misparsing.  */
+ 	  if (secname[i * 4 + 1] != LOP_QUOTE
+ 	      || bfd_bread (secname + i * 4, 4, abfd) != 4)
+ 	    /* Whoops.  We thought this was a name, and now we found a
+ 	       non-lop_quote lopcode before we parsed the whole length of
+ 	       the name.  Signal end-of-file in the same manner.  */
+ 	      goto format_error_free;
+ 	}
+     }
+
+   /* Get the section flags.  */
+   if (bfd_bread (buf, 4, abfd) != 4
+       || (buf[0] == LOP
+ 	  && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
+     goto format_error_free;
+
+   flags = bfd_get_32 (abfd, buf);
+
+   /* Get the section length.  */
+   if (bfd_bread (buf, 4, abfd) != 4
+       || (buf[0] == LOP
+ 	  && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
+     goto format_error_free;
+
+   section_length = (bfd_vma) bfd_get_32 (abfd, buf) << 32;
+
+   /* That's the first, high-part.  Now get the low part.  */
+
+   if (bfd_bread (buf, 4, abfd) != 4
+       || (buf[0] == LOP
+ 	  && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
+     goto format_error_free;
+
+   section_length |= (bfd_vma) bfd_get_32 (abfd, buf);
+
+   /* Check the section length for sanity.  */
+   if (section_length > MAX_ARTIFICIAL_SECTION_SIZE)
+     goto format_error_free;
+
+   /* Get the section VMA.  */
+   if (bfd_bread (buf, 4, abfd) != 4
+       || (buf[0] == LOP
+ 	  && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
+     goto format_error_free;
+
+   section_vma = (bfd_vma) bfd_get_32 (abfd, buf) << 32;
+
+   /* That's the first, high-part.  Now get the low part.  */
+   if (bfd_bread (buf, 4, abfd) != 4
+       || (buf[0] == LOP
+ 	  && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
+     goto format_error_free;
+
+   section_vma |= (bfd_vma) bfd_get_32 (abfd, buf);
+
+   sec = mmo_make_section (abfd, secname);
+   free (secname);
+   if (sec == NULL)
+     goto format_error;
+
+   /* We allocate a buffer here for the advertised size, with head room for
+      tetrabyte alignment.  */
+   loc = bfd_zmalloc (section_length + 3
+ 		     + sizeof (struct mmo_data_list_struct));
+   if (loc == NULL)
+     goto format_error;
+
+   /* Use a TETRA-rounded size for the allocated buffer; we set the
+      "visible" section size below.  */
+   loc->size = (section_length + 3) & ~3;
+
+   /* Add in the section flags we found to those bfd entered during this
+      process and set the contents.  */
+   if (! bfd_set_section_flags (abfd, sec,
+ 			       bfd_sec_flags_from_mmo_flags (flags)
+ 			       | bfd_get_section_flags (abfd, sec)
+ 			       | (section_length != 0 ? SEC_HAS_CONTENTS : 0))
+       || ! bfd_set_section_size (abfd, sec,
+ 				 sec->_cooked_size + section_length)
+       /* Set VMA only for the first occurrence.  */
+       || (! sec->user_set_vma
+ 	  && ! bfd_set_section_vma  (abfd, sec, section_vma)))
+     {
+       /* If we get an error for any of the calls above, signal more than
+ 	 just a format error for the spec section.  */
+       return NULL;
+     }
+
+   loc->next = NULL;
+   if (((struct mmo_section_data_struct *) (sec->used_by_bfd))->tail != NULL)
+     ((struct mmo_section_data_struct *) (sec->used_by_bfd))->tail->next
+       = loc;
+   else
+     ((struct mmo_section_data_struct *) (sec->used_by_bfd))->head = loc;
+   ((struct mmo_section_data_struct *) (sec->used_by_bfd))->tail = loc;
+   loc->where = section_vma;
+
+   return sec;
+
+  format_error_free:
+   free (secname);
+  format_error:
+   if (bfd_seek (abfd, orig_pos, SEEK_SET) != 0)
+     return NULL;
+
+   return mmo_get_generic_spec_data_section (abfd, spec_data_number);
+ }
+
+ /* Read a byte, but read from file in multiples of 32-bit words.  */
+
+ static bfd_byte
+ mmo_get_byte (abfd)
+      bfd *abfd;
+ {
+   bfd_byte retval;
+
+   if (abfd->tdata.mmo_data->byte_no == 0)
+     {
+       if (abfd->tdata.mmo_data->have_error == false
+ 	  && bfd_bread (abfd->tdata.mmo_data->buf, 4, abfd) != 4)
+ 	{
+ 	  abfd->tdata.mmo_data->have_error = true;
+
+ 	  /* A value somewhat safe against tripping on some inconsistency
+ 	     when mopping up after this error.  */
+ 	  return 128;
+ 	}
+     }
+
+   retval = abfd->tdata.mmo_data->buf[abfd->tdata.mmo_data->byte_no];
+   abfd->tdata.mmo_data->byte_no = (abfd->tdata.mmo_data->byte_no + 1) % 4;
+
+   return retval;
+ }
+
+ /* Write a byte, in multiples of 32-bit words.  */
+
+ static void
+ mmo_write_byte (abfd, value)
+      bfd *abfd;
+      bfd_byte value;
+ {
+   abfd->tdata.mmo_data->buf[(abfd->tdata.mmo_data->byte_no++ % 4)] = value;
+   if ((abfd->tdata.mmo_data->byte_no % 4) == 0)
+     {
+       if (abfd->tdata.mmo_data->have_error == false
+ 	  && bfd_bwrite (abfd->tdata.mmo_data->buf, 4, abfd) != 4)
+ 	abfd->tdata.mmo_data->have_error = true;
+     }
+ }
+
+ /* Create a symbol.  */
+
+ static boolean
+ mmo_create_symbol (abfd, symname, addr, sym_type, serno)
+      bfd *abfd;
+      CONST char *symname;
+      bfd_vma addr;
+      enum mmo_sym_type sym_type;
+      unsigned int serno;
+ {
+   struct mmo_symbol *n;
+
+   n = (struct mmo_symbol *) bfd_alloc (abfd, sizeof (struct mmo_symbol));
+   if (n == NULL)
+     return false;
+
+   n->name = bfd_alloc (abfd, strlen (symname) + 1);
+   if (n->name == NULL)
+     return false;
+
+   strcpy ((PTR) n->name, symname);
+
+   n->value = addr;
+   n->sym_type = sym_type;
+   n->serno = serno;
+
+   if (abfd->tdata.mmo_data->symbols == NULL)
+     abfd->tdata.mmo_data->symbols = n;
+   else
+     abfd->tdata.mmo_data->symtail->next = n;
+   abfd->tdata.mmo_data->symtail = n;
+   n->next = NULL;
+
+   ++abfd->symcount;
+
+   /* Check that :Main equals the last octa of the .MMIX.reg_contents
+      section, as it's the one place we're sure to pass when reading a mmo
+      object.  For written objects, we do it while setting the symbol
+      table.  */
+   if (strcmp (symname, MMIX_START_SYMBOL_NAME) == 0
+       && bfd_get_start_address (abfd) != addr)
+     {
+       (*_bfd_error_handler)
+ 	(_("%s: invalid mmo file: initialization value for $255 is not `Main'\n"),
+ 	 bfd_get_filename (abfd));
+       bfd_set_error (bfd_error_bad_value);
+       return false;
+     }
+
+   return true;
+ }
+
+ /* Read in symbols.  */
+
+ static boolean
+ mmo_get_symbols (abfd)
+      bfd *abfd;
+ {
+ /*
+ INODE
+ Symbol-table, mmo section mapping, File layout, mmo
+ SUBSECTION
+ 	Symbol table format
+
+ 	From mmixal.w (or really, the generated mmixal.tex) in
+ 	@url{http://www-cs-faculty.stanford.edu/~knuth/programs/mmix.tar.gz}):
+ 	``Symbols are stored and retrieved by means of a @samp{ternary
+ 	search trie}, following ideas of Bentley and Sedgewick. (See
+ 	ACM--SIAM Symp.@: on Discrete Algorithms @samp{8} (1997), 360--369;
+ 	R.@:Sedgewick, @samp{Algorithms in C} (Reading, Mass.@:
+ 	Addison--Wesley, 1998), @samp{15.4}.)  Each trie node stores a
+ 	character, and there are branches to subtries for the cases where
+ 	a given character is less than, equal to, or greater than the
+ 	character in the trie.  There also is a pointer to a symbol table
+ 	entry if a symbol ends at the current node.''
+
+ 	So it's a tree encoded as a stream of bytes.  The stream of bytes
+ 	acts on a single virtual global symbol, adding and removing
+ 	characters and signalling complete symbol points.  Here, we read
+ 	the stream and create symbols at the completion points.
+
+ 	First, there's a control byte <<m>>.  If any of the listed bits
+ 	in <<m>> is nonzero, we execute what stands at the right, in
+ 	the listed order:
+
+ | (MMO3_LEFT)
+ | 0x40 - Traverse left trie.
+ |        (Read a new command byte and recurse.)
+ |
+ | (MMO3_SYMBITS)
+ | 0x2f - Read the next byte as a character and store it in the
+ |        current character position; increment character position.
+ |        Test the bits of <<m>>:
+ |
+ |        (MMO3_WCHAR)
+ |        0x80 - The character is 16-bit (so read another byte,
+ |               merge into current character.
+ |
+ |        (MMO3_TYPEBITS)
+ |        0xf  - We have a complete symbol; parse the type, value
+ |               and serial number and do what should be done
+ |               with a symbol.  The type and length information
+ |               is in j = (m & 0xf).
+ |
+ |               (MMO3_REGQUAL_BITS)
+ |	        j == 0xf: A register variable.  The following
+ |                         byte tells which register.
+ |               j <= 8:   An absolute symbol.  Read j bytes as the
+ |                         big-endian number the symbol equals.
+ |                         A j = 2 with two zero bytes denotes an
+ |                         unknown symbol.
+ |               j > 8:    As with j <= 8, but add (0x20 << 56)
+ |                         to the value in the following j - 8
+ |                         bytes.
+ |
+ |               Then comes the serial number, as a variant of
+ |               uleb128, but better named ubeb128:
+ |               Read bytes and shift the previous value left 7
+ |               (multiply by 128).  Add in the new byte, repeat
+ |               until a byte has bit 7 set.  The serial number
+ |               is the computed value minus 128.
+ |
+ |        (MMO3_MIDDLE)
+ |        0x20 - Traverse middle trie.  (Read a new command byte
+ |               and recurse.)  Decrement character position.
+ |
+ | (MMO3_RIGHT)
+ | 0x10 - Traverse right trie.  (Read a new command byte and
+ |        recurse.)
+
+ 	Let's look again at the <<lop_stab>> for the trivial file
+ 	(@pxref{File layout}).
+
+ | 0x980b0000 - lop_stab for ":Main" = 0, serial 1.
+ | 0x203a4040
+ | 0x10404020
+ | 0x4d206120
+ | 0x69016e00
+ | 0x81000000
+
+ 	This forms the trivial trie (note that the path between ``:'' and
+ 	``M'' is redundant):
+
+ | 203a	   ":"
+ | 40       /
+ | 40      /
+ | 10      \
+ | 40      /
+ | 40     /
+ | 204d  "M"
+ | 2061  "a"
+ | 2069  "i"
+ | 016e  "n" is the last character in a full symbol, and
+ |       with a value represented in one byte.
+ | 00    The value is 0.
+ | 81    The serial number is 1.  */
+
+   bfd_byte m = mmo_get_byte (abfd);
+
+   /* Check first if we have a bad hair day.  */
+   if (abfd->tdata.mmo_data->have_error == true)
+     return false;
+
+   if (m & MMO3_LEFT)
+     /* Traverse left trie. */
+     mmo_get_symbols (abfd);
+
+   if (m & MMO3_SYMBITS)
+     {
+       bfd_byte c = mmo_get_byte (abfd);
+       bfd_byte j = m & MMO3_TYPEBITS;
+       bfd_vma addr = 0;
+       enum mmo_sym_type sym_type;
+       unsigned int serno = 0;
+       bfd_byte k;
+
+       if (m & MMO3_WCHAR)
+ 	{
+ 	  bfd_byte c2 = mmo_get_byte (abfd);
+
+ 	  /* A two-byte character.  We can't grok this, but neither can
+ 	     mmotype, for other cases than the second byte being zero.  */
+
+ 	  if (c != 0)
+ 	    {
+ 	      abfd->tdata.mmo_data->lop_stab_symbol
+ 		[abfd->tdata.mmo_data->symbol_position] = 0;
+
+ 	      (*_bfd_error_handler)
+ 		(_("%s: unsupported wide character sequence\
+  0x%02X 0x%02X after symbol name starting with `%s'\n"),
+ 		 bfd_get_filename (abfd), c, c2,
+ 		 abfd->tdata.mmo_data->lop_stab_symbol);
+ 	      bfd_set_error (bfd_error_bad_value);
+ 	      abfd->tdata.mmo_data->have_error = true;
+ 	      return false;
+ 	    }
+ 	  else
+ 	    c = c2;
+ 	}
+
+       abfd->tdata.mmo_data->lop_stab_symbol[abfd->tdata.mmo_data->symbol_position++] = c;
+       abfd->tdata.mmo_data->lop_stab_symbol[abfd->tdata.mmo_data->symbol_position] = 0;
+
+       if (j & MMO3_REGQUAL_BITS)
+ 	{
+ 	  if (j == MMO3_REGQUAL_BITS)
+ 	    {
+ 	      sym_type = mmo_reg_sym;
+ 	      addr = mmo_get_byte (abfd);
+ 	    }
+ 	  else if (j <= 8)
+ 	    {
+ 	      unsigned int i;
+
+ 	      for (i = 0; i < j; i++)
+ 		addr = (addr << 8) + mmo_get_byte (abfd);
+
+ 	      if (addr == 0 && j == MMO3_UNDEF)
+ 		sym_type = mmo_undef_sym;
+ 	      else
+ 		sym_type = mmo_abs_sym;
+ 	    }
+ 	  else
+ 	    {
+ 	      unsigned int i;
+
+ 	      for (i = MMO3_DATA; i < j; i++)
+ 		addr = (addr << 8) + mmo_get_byte (abfd);
+
+ 	      addr += (bfd_vma) 0x20 << 56;
+ 	      sym_type = mmo_data_sym;
+ 	    }
+
+ 	  /* Get the serial number.  */
+ 	  do
+ 	    {
+ 	      k = mmo_get_byte (abfd);
+ 	      serno = (serno << 7) + k;
+ 	    }
+ 	  while (k < 128);
+ 	  serno -= 128;
+
+ 	  /* Got it.  Now enter it.  Skip a leading ":".  */
+ 	  if (abfd->tdata.mmo_data->have_error == false
+ 	      && ! mmo_create_symbol (abfd,
+ 				      abfd->tdata.mmo_data->lop_stab_symbol
+ 				      + 1,
+ 				      addr, sym_type, serno))
+ 	    abfd->tdata.mmo_data->have_error = true;
+ 	}
+
+       if (m & MMO3_MIDDLE)
+ 	/* Traverse middle trie. */
+ 	mmo_get_symbols (abfd);
+
+       abfd->tdata.mmo_data->symbol_position--;
+     }
+
+   if (m & MMO3_RIGHT)
+     /* Traverse right trie.  */
+     mmo_get_symbols (abfd);
+
+   return abfd->tdata.mmo_data->have_error == false;
+ }
+
+ /* Get the location of memory area [VMA..VMA + SIZE - 1], which we think
+    is in section SEC.  Adjust and reallocate zero-initialized contents.
+    If there's new contents, allocate to the next multiple of
+    MMO_SEC_CONTENTS_CHUNK_SIZE.  */
+
+ static INLINE bfd_byte *
+ mmo_get_loc (sec, vma, size)
+      asection *sec;
+      bfd_vma vma;
+      int size;
+ {
+   bfd_size_type allocated_size;
+   struct mmo_section_data_struct *sdatap
+     = (struct mmo_section_data_struct *) sec->used_by_bfd;
+   struct mmo_data_list_struct *datap = sdatap->head;
+   struct mmo_data_list_struct *entry;
+
+   for (; datap != NULL; datap = datap->next)
+     {
+       if (datap->where <= vma
+ 	  && datap->where + datap->size >= vma + size)
+ 	return datap->data + vma - datap->where;
+       else if (datap->where <= vma
+ 	       && datap->where + datap->allocated_size >= vma + size
+ 	       /* Only munch on the "allocated size" if it does not
+ 		  overlap the next chunk.  */
+ 	       && (datap->next == NULL || datap->next->where >= vma + size))
+ 	{
+ 	  /* There was room allocated, but the size wasn't set to include
+ 	     it.  Do that now.  */
+ 	  datap->size += (vma + size) - (datap->where + datap->size);
+
+ 	  /* Update the section size.  */
+ 	  if (vma + size > sec->vma + sec->_raw_size)
+ 	    sec->_raw_size += (vma + size) - (sec->vma + sec->_raw_size);
+
+ 	  return datap->data + vma - datap->where;
+ 	}
+     }
+
+   /* Not found; allocate a new block.  First check in case we get a
+      request for a size split up over several blocks; we'll have to return
+      NULL for those cases, requesting the caller to split up the request.
+      Requests with an address aligned on MMO_SEC_CONTENTS_CHUNK_SIZE bytes and
+      for no more than MMO_SEC_CONTENTS_CHUNK_SIZE will always get resolved.  */
+
+   for (datap = sdatap->head; datap != NULL; datap = datap->next)
+     if ((datap->where <= vma && datap->where + datap->size > vma)
+ 	|| (datap->where < vma + size
+ 	    && datap->where + datap->size >= vma + size))
+       return NULL;
+
+   allocated_size
+     = (size + MMO_SEC_CONTENTS_CHUNK_SIZE - 1) & ~(MMO_SEC_CONTENTS_CHUNK_SIZE - 1);
+   entry = (mmo_data_list_type *)
+     bfd_zalloc (sec->owner, sizeof (mmo_data_list_type) + allocated_size);
+   if (entry == NULL)
+     return false;
+   entry->where = vma;
+   entry->size = size;
+   entry->allocated_size = allocated_size;
+
+   datap = sdatap->head;
+
+   /* Sort the records by address.  Optimize for the common case of adding
+      a record to the end of the list.  */
+   if (sdatap->tail != NULL && entry->where >= sdatap->tail->where)
+     {
+       sdatap->tail->next = entry;
+       entry->next = NULL;
+       sdatap->tail = entry;
+     }
+   else
+     {
+       mmo_data_list_type **look;
+       for (look = &sdatap->head;
+ 	   *look != NULL && (*look)->where < entry->where;
+ 	   look = &(*look)->next)
+ 	;
+       entry->next = *look;
+       *look = entry;
+       if (entry->next == NULL)
+ 	{
+ 	  sdatap->tail = entry;
+
+ 	  /* We get here for the first time (at other times too) for this
+ 	     section.  Say we have contents.  */
+ 	  if (! bfd_set_section_flags (sec->owner, sec,
+ 				       bfd_get_section_flags (sec->owner, sec)
+ 				       | SEC_HAS_CONTENTS))
+ 	    return NULL;
+ 	}
+     }
+
+   /* Update the section size.  */
+   if (vma + size > sec->vma + sec->_raw_size)
+     sec->_raw_size += (vma + size) - (sec->vma + sec->_raw_size);
+   return entry->data;
+ }
+
+ /* Set sizes once we've read in all sections.  */
+
+ static void
+ mmo_map_set_sizes (abfd, sec, ignored)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asection *sec;
+      PTR ignored ATTRIBUTE_UNUSED;
+ {
+   sec->_cooked_size = sec->_raw_size;
+   sec->lma = sec->vma;
+ }
+
+ /* Read the mmo file and turn it into sections.  */
+
+ static boolean
+ mmo_scan (abfd)
+      bfd *abfd;
+ {
+   unsigned int i;
+   unsigned int lineno = 1;
+   boolean error = false;
+   bfd_vma vma = 0;
+   asection *sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
+   asection *non_spec_sec = NULL;
+   bfd_vma non_spec_vma = 0;
+   char *current_filename = NULL;
+   bfd_size_type nbytes_read = 0;
+   /* Buffer with room to read a 64-bit value.  */
+   bfd_byte buf[8];
+   long stab_loc = -1;
+   char *file_names[256];
+
+   memset (file_names, 0, sizeof (file_names));
+
+   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
+     goto error_return;
+
+   while ((nbytes_read = bfd_bread (buf, 4, abfd)) == 4)
+     {
+       if (buf[0] == LOP)
+ 	{
+ 	  unsigned int y = bfd_get_8 (abfd, buf + 2);
+ 	  unsigned int z = bfd_get_8 (abfd, buf + 3);
+
+ 	  /* Change back to the original section for lopcodes other
+ 	     than LOP_QUOTE that comes after a LOP_SPEC.  */
+ 	  if ((buf[1] != LOP_QUOTE || y != 0 || z != 1)
+ 	      && non_spec_sec != NULL)
+ 	    {
+ 	      sec = non_spec_sec;
+ 	      vma = non_spec_vma;
+ 	      non_spec_sec = NULL;
+ 	    }
+
+ 	  switch (buf[1])
+ 	    {
+ 	    default:
+ 	      (*_bfd_error_handler)
+ 		(_("%s: invalid mmo file: unsupported lopcode `%d'\n"),
+ 		 bfd_get_filename (abfd), buf[1]);
+ 	      bfd_set_error (bfd_error_bad_value);
+ 	      goto error_return;
+
+ 	    case LOP_QUOTE:
+ 	      /* Quote the next 32-bit word.  */
+ 	      if (y != 0 || z != 1)
+ 		{
+ 		  (*_bfd_error_handler)
+ 		    (_("%s: invalid mmo file: expected YZ = 1 got YZ = %d for lop_quote\n"),
+ 		     bfd_get_filename (abfd), y*256+z);
+ 		  bfd_set_error (bfd_error_bad_value);
+ 		  goto error_return;
+ 		}
+ 	      if (bfd_bread (buf, 4, abfd) != 4)
+ 		goto error_return;
+
+ 	      mmo_xore_32 (sec, vma, bfd_get_32 (abfd, buf));
+ 	      vma += 4;
+ 	      vma &= ~3;
+ 	      lineno++;
+ 	      break;
+
+ 	    case LOP_LOC:
+ 	      /* Set vma (and section).  */
+ 	      vma = (bfd_vma) y << 56;
+ 	      if (z == 1)
+ 		{
+ 		  /* Get a 32-bit value.  */
+ 		  if (bfd_bread (buf, 4, abfd) != 4)
+ 		    goto error_return;
+
+ 		  vma += bfd_get_32 (abfd, buf);
+ 		}
+ 	      else if (z == 2)
+ 		{
+ 		  /* Get a 64-bit value.  */
+ 		  if (bfd_bread (buf, 8, abfd) != 8)
+ 		    goto error_return;
+
+ 		  vma += bfd_get_64 (abfd, buf);
+ 		}
+ 	      else
+ 		{
+ 		  (*_bfd_error_handler)
+ 		    (_("%s: invalid mmo file: expected z = 1 or z = 2, got z = %d for lop_loc\n"),
+ 		     bfd_get_filename (abfd), z);
+ 		  bfd_set_error (bfd_error_bad_value);
+ 		  goto error_return;
+ 		}
+
+ 	      sec = mmo_decide_section (abfd, vma);
+ 	      if (sec == NULL)
+ 		goto error_return;
+ 	      break;
+
+ 	    case LOP_SKIP:
+ 	      /* Move forward within the same section.  */
+ 	      vma += y * 256 + z;
+
+ 	      sec = mmo_decide_section (abfd, vma);
+ 	      if (sec == NULL)
+ 		goto error_return;
+ 	      break;
+
+ 	    case LOP_FIXO:
+ 	      /* A fixup: Store the current vma somewhere.  Position using
+ 		 same format as LOP_LOC.  */
+ 	      {
+ 		bfd_vma p = (bfd_vma) y << 56;
+ 		asection *fixosec;
+
+ 		if (z == 1)
+ 		  {
+ 		    /* Get a 32-bit value.  */
+ 		    if (bfd_bread (buf, 4, abfd) != 4)
+ 		      goto error_return;
+
+ 		    p += bfd_get_32 (abfd, buf);
+ 		  }
+ 		else if (z == 2)
+ 		  {
+ 		    /* Get a 64-bit value.  */
+ 		    if (bfd_bread (buf, 8, abfd) != 8)
+ 		      goto error_return;
+
+ 		    p += bfd_get_64 (abfd, buf);
+ 		  }
+ 		else
+ 		  {
+ 		    (*_bfd_error_handler)
+ 		      (_("%s: invalid mmo file: expected z = 1 or z = 2, got z = %d for lop_fixo\n"),
+ 		       bfd_get_filename (abfd), z);
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+
+ 		/* The section where we store this address might be a
+ 		   different one than the current section.  */
+ 		fixosec = mmo_decide_section (abfd, p);
+ 		if (fixosec == NULL)
+ 		  goto error_return;
+ 		mmo_xore_64 (fixosec, p, vma);
+ 	      }
+ 	    break;
+
+ 	    case LOP_FIXR:
+ 	      /* A fixup: Store YZ of this lopcode into YZ at vma - 4 * yz.  */
+ 	      {
+ 		unsigned int yz = (y * 256 + z);
+ 		bfd_vma p = vma + 2 - 4 * yz;
+ 		asection *fixrsec = mmo_decide_section (abfd, p);
+ 		if (fixrsec == NULL)
+ 		  goto error_return;
+ 		mmo_xore_16 (fixrsec, p, yz);
+ 	      }
+ 	    break;
+
+ 	    case LOP_FIXRX:
+ 	      /* A fixup, similar to lop_fixr, but taking larger numbers
+ 		 and can change branches into the opposite direction
+ 		 (gasp!).  */
+ 	      {
+ 		bfd_vma delta;
+ 		bfd_vma p;
+ 		asection *fixrsec;
+
+ 		if (y != 0)
+ 		  {
+ 		    (*_bfd_error_handler)
+ 		      (_("%s: invalid mmo file: expected y = 0, got y = %d for lop_fixrx\n"),
+ 		       bfd_get_filename (abfd), y);
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+
+ 		if (z != 16 && z != 24)
+ 		  {
+ 		    (*_bfd_error_handler)
+ 		      (_("%s: invalid mmo file: expected z = 16 or z = 24, got z = %d for lop_fixrx\n"),
+ 		       bfd_get_filename (abfd), z);
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+
+ 		/* Get the next 32-bit value.  */
+ 		if (bfd_bread (buf, 4, abfd) != 4)
+ 		  goto error_return;
+
+ 		delta = bfd_get_32 (abfd, buf);
+
+ 		/* Do an, ehm, involved calculation for the location of
+ 		   the fixup.  See mmixal documentation for a verbose
+ 		   explanation.  We follow it verbosely here for the
+ 		   readers delight.  */
+ 		if (buf[0] == 0)
+ 		  p = vma - 4 * delta;
+ 		else if (buf[0] == 1)
+ 		  p = vma - 4 * ((delta & 0xffffff) - (1 << z));
+ 		else
+ 		  {
+ 		    (*_bfd_error_handler)
+ 		      (_("%s: invalid mmo file: leading byte of operand word must be 0 or 1, got %d for lop_fixrx\n"),
+ 		       bfd_get_filename (abfd), buf[0]);
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+
+ 		fixrsec = mmo_decide_section (abfd, vma);
+ 		if (fixrsec == NULL)
+ 		  goto error_return;
+ 		mmo_xore_32 (fixrsec, p, delta);
+ 	      }
+ 	    break;
+
+ 	    case LOP_FILE:
+ 	      /* Set current file and perhaps the file name.  Reset line
+ 		 number.  */
+ 	      if (z != 0)
+ 		{
+ 		  char *fname = bfd_malloc (z * 4 + 1);
+
+ 		  if (fname == NULL)
+ 		    {
+ 		      (*_bfd_error_handler)
+ 			(_("%s: cannot allocate file name for file number %d, %d bytes\n"),
+ 			 bfd_get_filename (abfd), y, z * 4 + 1);
+ 		      bfd_set_error (bfd_error_system_call);
+ 		      goto error_return;
+ 		    }
+
+ 		  fname[z * 4] = 0;
+
+ 		  for (i = 0; i < z; i++)
+ 		    {
+ 		      if (bfd_bread (fname + i * 4, 4, abfd) != 4)
+ 			{
+ 			  free (fname);
+ 			  goto error_return;
+ 			}
+ 		    }
+
+ 		  if (file_names[y] != NULL)
+ 		    {
+ 		      (*_bfd_error_handler)
+ 			(_("%s: invalid mmo file: file number %d `%s',\
+  was already entered as `%s'\n"),
+ 			 bfd_get_filename (abfd), y, fname, file_names[y]);
+ 		      bfd_set_error (bfd_error_bad_value);
+ 		      goto error_return;
+ 		    }
+
+ 		  file_names[y] = fname;
+ 		}
+
+ 	      if (file_names[y] == NULL)
+ 		{
+ 		  (*_bfd_error_handler)
+ 		    (_("%s: invalid mmo file: file name for number %d\
+  was not specified before use\n"),
+ 		     bfd_get_filename (abfd), y);
+ 		  bfd_set_error (bfd_error_bad_value);
+ 		  goto error_return;
+ 		}
+
+ 	      current_filename = file_names[y];
+ 	      lineno = 0;
+ 	      break;
+
+ 	    case LOP_LINE:
+ 	      /* Set line number.  */
+ 	      lineno = y * 256 + z;
+ 	      /* FIXME: Create a sequence of mmo-specific line number
+ 		 entries for each section, then translate into canonical
+ 		 format.  */
+ 	      break;
+
+ 	    case LOP_SPEC:
+ 	      /* Special data follows until the next non-lop_quote
+ 		 lopcode.  */
+ 	      non_spec_sec = sec;
+ 	      non_spec_vma = vma;
+ 	      sec = mmo_get_spec_section (abfd, y * 256 + z);
+ 	      if (sec == NULL)
+ 		goto error_return;
+
+ 	      vma = sec->vma;
+ 	      break;
+
+ 	    case LOP_PRE:
+ 	      {
+ 		/* We ignore header information, except we read in the
+ 		   creation time from the first 32-bit word with the time
+ 		   in seconds since era.  */
+ 		if (z >= 1
+ 		    && bfd_bread (abfd->tdata.mmo_data->created, 4,
+ 				 abfd) != 4)
+ 		  goto error_return;
+
+ 		for (i = 1; i < z; i++)
+ 		  if (bfd_bread (buf, 4, abfd) != 4)
+ 		    goto error_return;
+ 	      }
+ 	      break;
+
+ 	    case LOP_POST:
+ 	      /* This tells of the contents of registers $Z..$255 at
+ 		 startup.  We make a section out of it, with VMA = Z * 8,
+ 		 but only if Z != 255 or the contents is non-zero.  */
+ 	      {
+ 		asection *rsec;
+ 		bfd_byte *loc;
+ 		bfd_vma first_octa;
+ 		bfd_vma startaddr_octa;
+
+ 		/* Read first octaword outside loop to simplify logic when
+ 		   excluding the Z == 255, octa == 0 case.  */
+ 		if (bfd_bread (buf, 8, abfd) != 8)
+ 		  goto error_return;
+
+ 		first_octa = bfd_get_64 (abfd, buf);
+
+ 		/* Don't emit contents for the trivial case which is
+ 		   always present; $255 pointing to Main.  */
+ 		if (z != 255)
+ 		  {
+ 		    rsec
+ 		      = bfd_make_section_old_way (abfd,
+ 						  MMIX_REG_CONTENTS_SECTION_NAME);
+ 		    rsec->vma = z * 8;
+ 		    loc = mmo_get_loc (rsec, z * 8, (255 - z) * 8);
+ 		    bfd_put_64 (abfd, first_octa, loc);
+
+ 		    for (i = z + 1; i < 255; i++)
+ 		      {
+ 			if (bfd_bread (loc + (i - z) * 8, 8, abfd) != 8)
+ 			  goto error_return;
+ 		      }
+
+ 		    /* Read out the last octabyte, and use it to set the
+ 		       start address.  */
+ 		    if (bfd_bread (buf, 8, abfd) != 8)
+ 		      goto error_return;
+
+ 		    startaddr_octa = bfd_get_64 (abfd, buf);
+ 		  }
+ 		else
+ 		  startaddr_octa = first_octa;
+
+ 		if (! bfd_set_start_address (abfd, startaddr_octa))
+ 		  {
+ 		    /* Currently this can't fail, but this should handle
+ 		       future failures.  */
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+ 	      }
+ 	      break;
+
+ 	    case LOP_STAB:
+ 	      /* We read in the symbols now, not later.  */
+ 	      if (y != 0 || z != 0)
+ 		{
+ 		  (*_bfd_error_handler)
+ 		    (_("%s: invalid mmo file: fields y and z of lop_stab\
+  non-zero, y: %d, z: %d\n"),
+ 		     bfd_get_filename (abfd), y, z);
+ 		  bfd_set_error (bfd_error_bad_value);
+ 		  goto error_return;
+ 		}
+
+ 	      /* Save the location, so we can check that YZ in the LOP_END
+ 		 is correct.  */
+ 	      stab_loc = bfd_tell (abfd);
+
+ 	      /* It's not said that an MMO can be without symbols (though
+ 		 mmixal will refuse to assemble files without Main), but
+ 		 it seems it would still be a valid mmo-file, so allow it.
+ 		 We detect the absence of a symbol area in that the upper
+ 		 limit is computed (from the lop_end YZ field) as 0.
+ 		 Don't call mmo_get_symbols; it can only detect the end of
+ 		 a valid symbol trie, not the absence of one.  */
+ 	      if (abfd->tdata.mmo_data->max_symbol_length != 0
+ 		  && ! mmo_get_symbols (abfd))
+ 		goto error_return;
+ 	      break;
+
+ 	    case LOP_END:
+ 	      {
+ 		/* This must be the last 32-bit word in an mmo file.
+ 		   Let's find out.  */
+ 		struct stat statbuf;
+ 		long curpos = bfd_tell (abfd);
+
+ 		if (bfd_stat (abfd, &statbuf) < 0)
+ 		  goto error_return;
+
+ 		if (statbuf.st_size != curpos)
+ 		  {
+ 		    (*_bfd_error_handler)
+ 		      (_("%s: invalid mmo file: lop_end not last item in\
+  file\n"),
+ 		       bfd_get_filename (abfd));
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+
+ 		/* Check that the YZ field is right.  Subtract the size of
+ 		   this LOP_END in the calculation; YZ does not include
+ 		   it.  */
+ 		if ((long) (y * 256 + z) * 4 != (curpos - stab_loc) - 4)
+ 		  {
+ 		    (*_bfd_error_handler)
+ 		      (_("%s: invalid mmo file: YZ of lop_end (%ld)\
+  not equal to the number of tetras to the preceding lop_stab (%ld)\n"),
+ 		       bfd_get_filename (abfd), (long) (y * 256 + z),
+ 		       (curpos - stab_loc - 4)/4);
+ 		    bfd_set_error (bfd_error_bad_value);
+ 		    goto error_return;
+ 		  }
+
+ 		bfd_map_over_sections (abfd, mmo_map_set_sizes, NULL);
+ 		goto done;
+ 	      }
+ 	    }
+ 	}
+       else
+ 	{
+ 	  /* This wasn't a lopcode, so store it in the current section.  */
+ 	  mmo_xore_32 (sec, vma & ~3, bfd_get_32 (abfd, buf));
+ 	  vma += 4;
+ 	  vma &= ~3;
+ 	  lineno++;
+ 	}
+     }
+
+   /* We know this file is a multiple of four bytes (checked in
+      mmo_object_p), so if we got something other than 0, this was a bad
+      file (although it's more likely we'll get 0 in that case too).
+      If we got end-of-file, then there was no lop_stab, so the file has
+      invalid format.  */
+
+   if (nbytes_read != 0)
+     bfd_set_error (bfd_error_system_call);
+   else
+     bfd_set_error (bfd_error_bad_value);
+
+  error_return:
+   error = true;
+  done:
+   /* Mark the .text and .data section with their normal attribute if they
+      contain anything.  This is not redundant wrt. mmo_decide_section,
+      since that code might never execute, and conversely the alloc+code
+      section flags must be set then.  */
+   sec = bfd_get_section_by_name (abfd, MMO_TEXT_SECTION_NAME);
+   if (sec != NULL
+       && (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS)
+       && ! bfd_set_section_flags (abfd, sec,
+ 				  bfd_get_section_flags (abfd, sec)
+ 				  | SEC_ALLOC | SEC_LOAD | SEC_CODE))
+     error = true;
+
+   sec = bfd_get_section_by_name (abfd, MMO_DATA_SECTION_NAME);
+   if (sec != NULL
+       && (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS)
+       && ! bfd_set_section_flags (abfd, sec,
+ 				  bfd_get_section_flags (abfd, sec)
+ 				  | SEC_ALLOC | SEC_LOAD))
+     error = true;
+
+   /* Free whatever resources we took.  */
+   for (i = 0; i < sizeof (file_names) / sizeof (file_names[0]); i++)
+     if (file_names[i])
+       free (file_names[i]);
+   return error ? false : true;
+ }
+
+ /* A hook to set up object file dependent section information.  For mmo,
+    we point out the shape of allocated section contents.  */
+
+ static boolean
+ mmo_new_section_hook (abfd, newsect)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asection *newsect;
+ {
+   /* We zero-fill all fields and assume NULL is represented by an all
+      zero-bit pattern.  */
+   newsect->used_by_bfd =
+     (PTR) bfd_zalloc (abfd, sizeof (struct mmo_section_data_struct));
+
+   if (!newsect->used_by_bfd)
+     return false;
+
+   /* Always align to at least 32-bit words.  */
+   newsect->alignment_power = 2;
+   return true;
+ }
+
+ /* We already have section contents loaded for sections that have
+    contents.  */
+
+ static boolean
+ mmo_get_section_contents (abfd, sec, location, offset, bytes_to_do)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asection *sec ATTRIBUTE_UNUSED;
+      PTR location ATTRIBUTE_UNUSED;
+      file_ptr offset ATTRIBUTE_UNUSED;
+      bfd_size_type bytes_to_do ATTRIBUTE_UNUSED;
+ {
+   /* Iterate over diminishing chunk sizes, copying contents, like
+      mmo_set_section_contents.  */
+   while (bytes_to_do)
+     {
+       /* A minor song-and-dance to make sure we're not bitten by the
+ 	 distant possibility of the cast from bfd_vma to int making the
+ 	 chunk zero-sized.  */
+       int chunk_size
+ 	= (int) bytes_to_do != 0 ? bytes_to_do : MMO_SEC_CONTENTS_CHUNK_SIZE;
+       bfd_byte *loc;
+
+       do
+ 	loc = mmo_get_loc (sec, sec->vma + offset, chunk_size);
+       while (loc == NULL && (chunk_size /= 2) != 0);
+
+       if (chunk_size == 0)
+ 	return false;
+
+       memcpy (location, loc, chunk_size);
+
+       location += chunk_size;
+       bytes_to_do -= chunk_size;
+       offset += chunk_size;
+     }
+   return true;
+ }
+
+ /* Return the amount of memory needed to read the symbol table.  */
+
+ static long
+ mmo_get_symtab_upper_bound (abfd)
+      bfd *abfd ATTRIBUTE_UNUSED;
+ {
+   return (abfd->symcount + 1) * sizeof (asymbol *);
+ }
+
+ /* Sort mmo symbols by serial number.  */
+
+ static int
+ mmo_sort_mmo_symbols (arg1, arg2)
+      CONST PTR arg1;
+      CONST PTR arg2;
+ {
+   CONST struct mmo_symbol *sym1 = *(CONST struct mmo_symbol **) arg1;
+   CONST struct mmo_symbol *sym2 = *(CONST struct mmo_symbol **) arg2;
+
+   /* Sort by serial number first.  */
+   if (sym1->serno < sym2->serno)
+     return -1;
+   else if (sym1->serno > sym2->serno)
+     return 1;
+
+   /* Then sort by address of the table entries.  */
+   return ((CONST char *) arg1 - (CONST char *) arg2);
+ }
+
+ /* Translate the symbol table.  */
+
+ static long
+ mmo_get_symtab (abfd, alocation)
+      bfd *abfd;
+      asymbol **alocation;
+ {
+   unsigned int symcount = bfd_get_symcount (abfd);
+   asymbol *csymbols;
+   unsigned int i;
+
+   csymbols = abfd->tdata.mmo_data->csymbols;
+   if (csymbols == NULL)
+     {
+       asymbol *c;
+       struct mmo_symbol *s;
+       struct mmo_symbol **msp;
+
+       /* First we store the symbols into the table we'll return, then we
+ 	 qsort it on the serial number, with secondary on the address of
+ 	 the symbol, to preserve order if there would be non-unique serial
+ 	 numbers.  */
+       for (s = abfd->tdata.mmo_data->symbols,
+ 	     msp = (struct mmo_symbol **) alocation;
+ 	   s != NULL;
+ 	   s = s->next, ++msp)
+ 	*msp = s;
+
+       *msp = NULL;
+
+       qsort (alocation, symcount, sizeof (struct mmo_symbol *),
+ 	     mmo_sort_mmo_symbols);
+
+       csymbols = (asymbol *) bfd_alloc (abfd, symcount * sizeof (asymbol));
+       if (csymbols == NULL && symcount != 0)
+ 	return false;
+       abfd->tdata.mmo_data->csymbols = csymbols;
+
+       for (msp = (struct mmo_symbol **) alocation, c = csymbols;
+ 	   *msp != NULL;
+ 	   msp++, ++c)
+ 	{
+ 	  s = *msp;
+ 	  c->the_bfd = abfd;
+ 	  c->name = s->name;
+ 	  c->value = s->value;
+ 	  c->flags = BSF_GLOBAL;
+
+ 	  if (s->sym_type == mmo_data_sym)
+ 	    {
+ 	      c->section
+ 		= bfd_get_section_by_name (abfd, MMO_DATA_SECTION_NAME);
+
+ 	      if (c->section == NULL)
+ 		c->section = bfd_abs_section_ptr;
+ 	      else
+ 		c->value -= c->section->vma;
+ 	    }
+ 	  else if (s->sym_type == mmo_undef_sym)
+ 	    c->section = bfd_und_section_ptr;
+ 	  else if (s->sym_type == mmo_reg_sym)
+ 	    {
+ 	      c->section
+ 		= bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
+ 	    }
+ 	  else
+ 	    {
+ 	      asection *textsec
+ 		= bfd_get_section_by_name (abfd, MMO_TEXT_SECTION_NAME);
+
+ 	      if (textsec != NULL
+ 		  && c->value >= textsec->vma
+ 		  && c->value <= textsec->vma + textsec->_cooked_size)
+ 		{
+ 		  c->section = textsec;
+ 		  c->value -= c->section->vma;
+ 		}
+ 	      else
+ 		c->section = bfd_abs_section_ptr;
+ 	    }
+
+ 	  c->udata.p = NULL;
+ 	}
+     }
+
+   /* Last, overwrite the incoming table with the right-type entries.  */
+   for (i = 0; i < symcount; i++)
+     *alocation++ = csymbols++;
+   *alocation = NULL;
+
+   return symcount;
+ }
+
+ /* Make an empty symbol.  */
+
+ static asymbol *
+ mmo_make_empty_symbol (abfd)
+      bfd *abfd;
+ {
+   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
+
+   if (new)
+     new->the_bfd = abfd;
+   return new;
+ }
+
+ /* Get information about a symbol.  */
+
+ static void
+ mmo_get_symbol_info (ignore_abfd, symbol, ret)
+      bfd *ignore_abfd ATTRIBUTE_UNUSED;
+      asymbol *symbol;
+      symbol_info *ret;
+ {
+   bfd_symbol_info (symbol, ret);
+ }
+
+ static void
+ mmo_print_symbol (abfd, afile, symbol, how)
+      bfd *abfd;
+      PTR afile;
+      asymbol *symbol;
+      bfd_print_symbol_type how;
+ {
+   FILE *file = (FILE *) afile;
+
+   switch (how)
+     {
+     case bfd_print_symbol_name:
+       fprintf (file, "%s", symbol->name);
+       break;
+     default:
+       bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
+
+       fprintf (file, " %-5s %s",
+ 	       symbol->section->name,
+ 	       symbol->name);
+     }
+ }
+
+ /* We can't map a file directly into executable code, so the
+    size of header information is irrelevant.  */
+
+ static int
+ mmo_sizeof_headers (abfd, exec)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      boolean exec ATTRIBUTE_UNUSED;
+ {
+   return 0;
+ }
+
+ /* Write the (section-neutral) file preamble.  */
+
+ static boolean
+ mmo_internal_write_header (abfd)
+      bfd *abfd;
+ {
+   CONST char lop_pre_bfd[] = { LOP, LOP_PRE, 1, 1};
+
+   if (bfd_bwrite (lop_pre_bfd, 4, abfd) != 4)
+     return false;
+
+   /* Copy creation time of original file.  */
+   if (bfd_bwrite (abfd->tdata.mmo_data->created, 4, abfd) != 4)
+     return false;
+
+   return true;
+ }
+
+ /* Write the LOP_POST record, with global register initializations.
+    Z is the Z field of the LOP_POST, corresponding to 255 - number of
+    registers at DATA.  The Z = 255 field is filled in with the
+    start-address.  */
+
+ static boolean
+ mmo_internal_write_post (abfd, z, sec)
+      bfd *abfd;
+      int z;
+      asection *sec;
+ {
+   int i;
+   bfd_byte buf[8];
+   mmo_write_tetra_raw (abfd, (LOP << 24) | (LOP_POST << 16) | z);
+
+   for (i = z; i < 255; i++)
+     {
+       bfd_byte *data = mmo_get_loc (sec, i * 8, 8);
+
+       if (bfd_bwrite (data, 8, abfd) != 8)
+ 	return false;
+     }
+
+   /* For Z == $255, we always emit the start location; supposedly Main,
+      but we have it handy at bfd_get_start_address.  If we're called with
+      Z == 255, don't assume DATA is valid.  */
+   bfd_put_64 (abfd, bfd_get_start_address (abfd), buf);
+
+   return
+     abfd->tdata.mmo_data->have_error == false
+     && bfd_bwrite (buf, 8, abfd) == 8;
+ }
+
+ /* Translate to and from BFD flags.  This is to make sure that we don't
+    get bitten by BFD flag number changes.  */
+
+ static flagword
+ mmo_sec_flags_from_bfd_flags (flags)
+      flagword flags;
+ {
+   flagword oflags = 0;
+
+   if (flags & SEC_ALLOC)
+     oflags |= MMO_SEC_ALLOC;
+   if (flags & SEC_LOAD)
+     oflags |= MMO_SEC_LOAD;
+   if (flags & SEC_RELOC)
+     oflags |= MMO_SEC_RELOC;
+   if (flags & SEC_READONLY)
+     oflags |= MMO_SEC_READONLY;
+   if (flags & SEC_CODE)
+     oflags |= MMO_SEC_CODE;
+   if (flags & SEC_DATA)
+     oflags |= MMO_SEC_DATA;
+   if (flags & SEC_NEVER_LOAD)
+     oflags |= MMO_SEC_NEVER_LOAD;
+   if (flags & SEC_IS_COMMON)
+     oflags |= MMO_SEC_IS_COMMON;
+   if (flags & SEC_DEBUGGING)
+     oflags |= MMO_SEC_DEBUGGING;
+
+   return oflags;
+ }
+
+ static flagword
+ bfd_sec_flags_from_mmo_flags (flags)
+      flagword flags;
+ {
+   flagword oflags = 0;
+
+   if (flags & MMO_SEC_ALLOC)
+     oflags |= SEC_ALLOC;
+   if (flags & MMO_SEC_LOAD)
+     oflags |= SEC_LOAD;
+   if (flags & MMO_SEC_RELOC)
+     oflags |= SEC_RELOC;
+   if (flags & MMO_SEC_READONLY)
+     oflags |= SEC_READONLY;
+   if (flags & MMO_SEC_CODE)
+     oflags |= SEC_CODE;
+   if (flags & MMO_SEC_DATA)
+     oflags |= SEC_DATA;
+   if (flags & MMO_SEC_NEVER_LOAD)
+     oflags |= SEC_NEVER_LOAD;
+   if (flags & MMO_SEC_IS_COMMON)
+     oflags |= SEC_IS_COMMON;
+   if (flags & MMO_SEC_DEBUGGING)
+     oflags |= SEC_DEBUGGING;
+
+   return oflags;
+ }
+
+ /* Write a section.  */
+
+ static boolean
+ mmo_internal_write_section (abfd, sec)
+      bfd *abfd;
+      asection *sec;
+ {
+   /* We do it differently depending on what section this is:
+
+    ".text": Output, prepended by information about the first source file
+    (not yet implemented.)
+
+    ".data": Output.
+
+    (".MMIX.reg_contents": Not handled here.)
+
+    Anything else: Output inside a lop_spec 80, in the format described
+    above.  */
+
+   if (strcmp (sec->name, MMO_TEXT_SECTION_NAME) == 0)
+     /* FIXME: Output source file name and line number.  */
+     return
+       mmo_write_loc_chunk_list (abfd,
+ 				((struct mmo_section_data_struct *)
+ 				 (sec->used_by_bfd))->head);
+   else if (strcmp (sec->name, MMO_DATA_SECTION_NAME) == 0)
+     return
+       mmo_write_loc_chunk_list (abfd,
+ 				((struct mmo_section_data_struct *)
+ 				 (sec->used_by_bfd))->head);
+   else if (strcmp (sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
+     /* Not handled here.  */
+     {
+       /* This would normally be an abort call since this can't happen, but
+          we don't do that.  */
+       bfd_set_error (bfd_error_bad_value);
+       return false;
+     }
+   else if (strncmp (sec->name, MMIX_OTHER_SPEC_SECTION_PREFIX,
+ 		    strlen (MMIX_OTHER_SPEC_SECTION_PREFIX)) == 0)
+     {
+       int n = atoi (sec->name + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX));
+       mmo_write_tetra_raw (abfd, (LOP << 24) | (LOP_SPEC << 16) | n);
+       return
+ 	abfd->tdata.mmo_data->have_error == false
+ 	&& mmo_write_chunk_list (abfd,
+ 				 ((struct mmo_section_data_struct *)
+ 				  (sec->used_by_bfd))->head);
+     }
+   /* Ignore sections that are just allocated or empty; we write out
+      _contents_ here.  */
+   else if ((bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS) != 0
+ 	   && sec->_raw_size != 0)
+     {
+       /* Keep the document-comment formatted the way it is.  */
+ /*
+ INODE
+ mmo section mapping, , Symbol-table, mmo
+ SUBSECTION
+ 	mmo section mapping
+
+ 	The implementation in BFD uses special data type 80 (decimal) to
+ 	encapsulate and describe named sections, containing e.g.@: debug
+ 	information.  If needed, any datum in the encapsulation will be
+ 	quoted using lop_quote.  First comes a 32-bit word holding the
+ 	number of 32-bit words containing the zero-terminated zero-padded
+ 	segment name.  After the name there's a 32-bit word holding flags
+ 	describing the section type.  Then comes a 64-bit big-endian word
+ 	with the section length (in bytes), then another with the section
+ 	start address.  Depending on the type of section, the contents
+ 	might follow, zero-padded to 32-bit boundary.  For a loadable
+ 	section (such as data or code), the contents might follow at some
+ 	later point, not necessarily immediately, as a lop_loc with the
+ 	same start address as in the section description, followed by the
+ 	contents.  This in effect forms a descriptor that must be emitted
+ 	before the actual contents.  Sections described this way must not
+ 	overlap.
+
+ 	For areas that don't have such descriptors, synthetic sections are
+ 	formed by BFD.  Consecutive contents in the two memory areas
+ 	@samp{0x0000@dots{}00} to @samp{0x01ff@dots{}ff} and
+ 	@samp{0x2000@dots{}00} to @samp{0x20ff@dots{}ff} are entered in
+ 	sections named <<.text>> and <<.data>> respectively.  If an area
+ 	is not otherwise described, but would together with a neighboring
+ 	lower area be less than @samp{0x40000000} bytes long, it is joined
+ 	with the lower area and the gap is zero-filled.  For other cases,
+ 	a new section is formed, named <<.MMIX.sec.@var{n}>>.  Here,
+ 	@var{n} is a number, a running count through the mmo file,
+ 	starting at 0.
+
+ EXAMPLE
+ 	A loadable section specified as:
+
+ | .section secname,"ax"
+ | TETRA 1,2,3,4,-1,-2009
+ | BYTE 80
+
+ 	and linked to address @samp{0x4}, is represented by the sequence:
+
+ | 0x98080050 - lop_spec 80
+ | 0x00000002 - two 32-bit words for the section name
+ | 0x7365636e - "secn"
+ | 0x616d6500 - "ame\0"
+ | 0x00000033 - flags CODE, READONLY, LOAD, ALLOC
+ | 0x00000000 - high 32 bits of section length
+ | 0x0000001c - section length is 28 bytes; 6 * 4 + 1 + alignment to 32 bits
+ | 0x00000000 - high 32 bits of section address
+ | 0x00000004 - section address is 4
+ | 0x98010002 - 64 bits with address of following data
+ | 0x00000000 - high 64 bits of address
+ | 0x00000004 - data starts at address 4
+ | 0x00000001 - 1
+ | 0x00000002 - 2
+ | 0x00000003 - 3
+ | 0x00000004 - 4
+ | 0xffffffff - -1
+ | 0xfffff827 - -2009
+ | 0x50000000 - 80 as a byte, padded with zeros.
+
+ 	Note that the lop_spec wrapping does not include the section
+ 	contents.  Compare this to a non-loaded section specified as:
+
+ | .section thirdsec
+ | TETRA 200001,100002
+ | BYTE 38,40
+
+ 	This, when linked to address @samp{0x200000000000001c}, is
+ 	represented by:
+
+ | 0x98080050 - lop_spec 80
+ | 0x00000002 - two 32-bit words for the section name
+ | 0x7365636e - "thir"
+ | 0x616d6500 - "dsec"
+ | 0x00000010 - flag READONLY
+ | 0x00000000 - high 32 bits of section length
+ | 0x0000000c - section length is 12 bytes; 2 * 4 + 2 + alignment to 32 bits
+ | 0x20000000 - high 64 bits of address
+ | 0x0000001c - low 64 bits of address 0x200000000000001c
+ | 0x00030d41 - 200001
+ | 0x000186a2 - 100002
+ | 0x26280000 - 38, 40 as bytes, padded with zeros
+
+ 	For the latter example, the section contents must not to appear
+ 	loaded in memory, and is therefore specified as part of the
+ 	special data.  The address is usually unimportant but might
+ 	provide information for e.g.@: the DWARF 2 debugging format.  */
+
+       mmo_write_tetra_raw (abfd, LOP_SPEC_SECTION);
+       mmo_write_tetra (abfd, (strlen (sec->name) + 3) / 4);
+       mmo_write_chunk (abfd, sec->name, strlen (sec->name));
+       /* FIXME: We can get debug sections (.debug_line & Co.) with a
+ 	 section flag still having SEC_RELOC set.  Investigate.  This
+ 	 might be true for all alien sections; perhaps mmo.em should clear
+ 	 that flag.  Might be related to weak references.  */
+       mmo_write_tetra (abfd,
+ 		       mmo_sec_flags_from_bfd_flags
+ 		       (bfd_get_section_flags (abfd, sec)));
+       mmo_write_octa (abfd, sec->_raw_size);
+       mmo_write_octa (abfd, bfd_get_section_vma (abfd, sec));
+
+       /* Writing a LOP_LOC ends the LOP_SPEC data, and makes data actually
+ 	 loaded.  */
+       if (bfd_get_section_flags (abfd, sec) & SEC_LOAD)
+ 	  return
+ 	    abfd->tdata.mmo_data->have_error == false
+ 	    && mmo_write_loc_chunk_list (abfd,
+ 					 ((struct mmo_section_data_struct *)
+ 					  (sec->used_by_bfd))->head);
+       return
+ 	abfd->tdata.mmo_data->have_error == false
+ 	&& mmo_write_chunk_list (abfd,
+ 				 ((struct mmo_section_data_struct *)
+ 				  (sec->used_by_bfd))->head);
+     }
+   return true;
+ }
+
+ /* We save up all data before output.  */
+
+ static boolean
+ mmo_set_section_contents (abfd, sec, location, offset, bytes_to_do)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      sec_ptr sec;
+      PTR location;
+      file_ptr offset;
+      bfd_size_type bytes_to_do;
+ {
+   /* Iterate over diminishing chunk sizes, copying contents.  */
+   while (bytes_to_do)
+     {
+       /* A minor song-and-dance to make sure we're not bitten by the
+ 	 distant possibility of the cast from bfd_vma to int making the
+ 	 chunk zero-sized.  */
+       int chunk_size
+ 	= (int) bytes_to_do != 0 ? bytes_to_do : MMO_SEC_CONTENTS_CHUNK_SIZE;
+       bfd_byte *loc;
+
+       do
+ 	loc = mmo_get_loc (sec, sec->vma + offset, chunk_size);
+       while (loc == NULL && (chunk_size /= 2) != 0);
+
+       if (chunk_size == 0)
+ 	return false;
+
+       memcpy (loc, location, chunk_size);
+
+       location += chunk_size;
+       bytes_to_do -= chunk_size;
+       offset += chunk_size;
+     }
+   return true;
+ }
+
+ /* Add a symbol to a trie-tree.  */
+
+ static boolean
+ mmo_internal_add_3_sym (abfd, rootp, symp)
+      bfd *abfd;
+      struct mmo_symbol_trie *rootp;
+      CONST struct mmo_symbol *symp;
+ {
+   CONST char *name = symp->name;
+   struct mmo_symbol_trie *trie = rootp;
+   struct mmo_symbol_trie **triep = NULL;
+
+   while (*name && trie != NULL)
+     {
+       if (*name < trie->symchar)
+ 	{
+ 	  triep = &trie->left;
+ 	  trie = trie->left;
+ 	}
+       else if (*name > trie->symchar)
+ 	{
+ 	  triep = &trie->right;
+ 	  trie = trie->right;
+ 	}
+       else if (*name == trie->symchar)
+ 	{
+ 	  triep = &trie->middle;
+ 	  name++;
+
+ 	  /* Make sure "trie" points to where we should fill in the
+ 	     current symbol whenever we've iterated through "name".  We
+ 	     would lose the right position if we encounter "foobar" then
+ 	     "foo".  */
+ 	  if (*name)
+ 	    trie = trie->middle;
+ 	}
+     }
+
+   while (*name != 0)
+     {
+       /* Create middle branches for the rest of the characters.  */
+       trie = bfd_zalloc (abfd, sizeof (struct mmo_symbol_trie));
+       *triep = trie;
+       trie->symchar = *name++;
+       triep = &trie->middle;
+     }
+
+   /* We discover a duplicate symbol rather late in the process, but still;
+      we discover it and bail out.  */
+   if (trie->sym.name != NULL)
+     {
+       (*_bfd_error_handler)
+ 	(_("%s: invalid symbol table: duplicate symbol `%s'\n"),
+ 	 bfd_get_filename (abfd), trie->sym.name);
+       bfd_set_error (bfd_error_bad_value);
+       return false;
+     }
+
+   memcpy (&trie->sym, symp, sizeof *symp);
+   return true;
+ }
+
+ /* Find out the length of the serialized version of a trie in bytes.  */
+
+ static unsigned int
+ mmo_internal_3_length (abfd, trie)
+      bfd *abfd;
+      struct mmo_symbol_trie *trie;
+ {
+   /* First, one for the control byte.  */
+   unsigned int length = 1;
+
+   if (trie == NULL)
+     return 0;
+
+   /* Add in the recursion to the left.  */
+   length += mmo_internal_3_length (abfd, trie->left);
+
+   /* Add in the middle trie and the character.  */
+   length += 1 + mmo_internal_3_length (abfd, trie->middle);
+
+   /* Add in the recursion to the right.  */
+   length += mmo_internal_3_length (abfd, trie->right);
+
+   /* Add in bytes for the symbol (if this is an endnode). */
+   if (trie->sym.name != NULL)
+     {
+       unsigned int serno = trie->sym.serno;
+
+       /* First what it takes to encode the value. */
+       if (trie->sym.sym_type == mmo_reg_sym)
+ 	length++;
+       else if (trie->sym.sym_type == mmo_undef_sym)
+ 	length += 2;
+       else
+ 	{
+ 	  bfd_vma value = trie->sym.value;
+
+ 	  /* Coded in one to eight following bytes.  */
+ 	  if (trie->sym.sym_type == mmo_data_sym)
+ 	    value -= (bfd_vma) 0x20 << 56;
+
+ 	  do
+ 	    {
+ 	      value >>= 8;
+ 	      length++;
+ 	    }
+ 	  while (value != 0);
+ 	}
+
+       /* Find out what it takes to encode the serial number.  */
+       do
+ 	{
+ 	  serno >>= 7;
+ 	  length++;
+ 	}
+       while (serno != 0);
+     }
+
+   return length;
+ }
+
+ /* Helper function for outputting the serial number of a symbol, output as
+    a variant of leb128 (see dwarf2 documentation) which could be called
+    beb128.  Using a helper function and recursion simplifies debugging.  */
+
+ static void
+ mmo_beb128_out (abfd, serno, marker)
+      bfd *abfd;
+      int serno;
+      int marker;
+ {
+   if (serno & ~0x7f)
+     mmo_beb128_out (abfd, serno >> 7, 0);
+   mmo_write_byte (abfd, marker | (serno & 0x7f));
+ }
+
+ /* Serialize a trie.  */
+
+ static void
+ mmo_internal_3_dump (abfd, trie)
+      bfd *abfd;
+      struct mmo_symbol_trie *trie;
+ {
+   bfd_byte control = 0;
+
+   if (trie == NULL)
+     return;
+
+   if (trie->left)
+     control |= MMO3_LEFT;
+
+   if (trie->middle)
+     control |= MMO3_MIDDLE;
+
+   if (trie->right)
+     control |= MMO3_RIGHT;
+
+   if (trie->sym.name != NULL)
+     {
+       /* Encode the symbol type and length of value bytes.  */
+       if (trie->sym.sym_type == mmo_reg_sym)
+ 	control |= MMO3_REGQUAL_BITS;
+       else if (trie->sym.sym_type == mmo_undef_sym)
+ 	control |= MMO3_UNDEF;
+       else
+ 	{
+ 	  bfd_vma value = trie->sym.value;
+
+ 	  /* Coded in 1..8 following bytes.  */
+ 	  if (trie->sym.sym_type == mmo_data_sym)
+ 	    {
+ 	      control |= MMO3_DATA;
+ 	      value -= (bfd_vma) 0x20 << 56;
+ 	    }
+
+ 	  do
+ 	    {
+ 	      value >>= 8;
+ 	      control++;
+ 	    }
+ 	  while (value != 0);
+ 	}
+     }
+
+   /* The control byte is output before recursing.  */
+   mmo_write_byte (abfd, control);
+
+   mmo_internal_3_dump (abfd, trie->left);
+
+   if (control & MMO3_SYMBITS)
+     {
+       mmo_write_byte (abfd, trie->symchar);
+
+       if (trie->sym.name != NULL)
+ 	{
+ 	  if (trie->sym.sym_type == mmo_reg_sym)
+ 	    mmo_write_byte (abfd, trie->sym.value);
+ 	  else if (trie->sym.sym_type == mmo_undef_sym)
+ 	    {
+ 	      mmo_write_byte (abfd, 0);
+ 	      mmo_write_byte (abfd, 0);
+ 	    }
+ 	  else
+ 	    {
+ 	      bfd_vma value = trie->sym.value;
+
+ 	      bfd_byte byte_n = control & 15;
+
+ 	      /* Coded in 1..8 following bytes.  Note that the value is
+ 		 shifted out big-endian.  */
+ 	      if (trie->sym.sym_type == mmo_data_sym)
+ 		{
+ 		  value -= (bfd_vma) 0x20 << 56;
+ 		  byte_n -= 8;
+ 		}
+
+ 	      do
+ 		{
+ 		  mmo_write_byte (abfd, (value >> ((byte_n - 1) * 8)) & 0xff);
+ 		  byte_n--;
+ 		}
+ 	      while (byte_n != 0);
+ 	    }
+
+ 	  mmo_beb128_out (abfd, trie->sym.serno, 128);
+ 	}
+       mmo_internal_3_dump (abfd, trie->middle);
+     }
+   mmo_internal_3_dump (abfd, trie->right);
+ }
+
+ /* Write symbols, either in mmo format or hidden in a lop_spec 80 section.
+    Write the lop_end terminator also.  */
+
+ static boolean
+ mmo_write_symbols_and_terminator (abfd)
+      bfd *abfd;
+ {
+   int count = bfd_get_symcount (abfd);
+   asymbol *fakemain[2];
+   asymbol **table;
+   int serno = 2;
+   struct mmo_symbol_trie root;
+   int trie_len;
+   int i;
+   bfd_byte buf[4];
+
+   /* Create a symbol for "Main".  */
+   asymbol *mainsym = bfd_make_empty_symbol (abfd);
+
+   mainsym->flags = BSF_GLOBAL;
+   mainsym->value = bfd_get_start_address (abfd);
+   mainsym->name = MMIX_START_SYMBOL_NAME;
+   mainsym->section = bfd_abs_section_ptr;
+   fakemain[0] = mainsym;
+   fakemain[1] = NULL;
+
+   memset (&root, 0, sizeof (root));
+
+   /* Make all symbols take a left turn.  */
+   root.symchar = 0xff;
+
+   /* There must always be a ":Main", so we'll add one
+      if there are no symbols.  */
+   if (count == 0)
+     {
+       table = fakemain;
+       count = 1;
+     }
+   else
+     table = bfd_get_outsymbols (abfd);
+
+   for (i = 0; i < count && table[i] != NULL; i++)
+     {
+       asymbol *s = table[i];
+
+       /* It's not enough to consult bfd_is_local_label, since it does not
+ 	 mean "local" in the sense of linkable-and-observable-after-link.
+ 	 Let's just check the BSF_GLOBAL flag.
+
+ 	 Also, don't export symbols with characters not in the allowed set.  */
+       if ((s->flags & (BSF_DEBUGGING|BSF_GLOBAL)) == BSF_GLOBAL
+ 	  && strspn (s->name,
+ 		     valid_mmo_symbol_character_set) == strlen (s->name))
+ 	{
+ 	  struct mmo_symbol sym;
+ 	  memset (&sym, 0, sizeof (sym));
+
+ 	  sym.name = s->name;
+ 	  sym.value =
+ 	    s->value
+ 	    + s->section->output_section->vma
+ 	    + s->section->output_offset;
+
+ 	  if (bfd_is_und_section (s->section))
+ 	    sym.sym_type = mmo_undef_sym;
+ 	  else if (strcmp (s->section->name, MMO_DATA_SECTION_NAME) == 0
+ 		   /* The encoding of data symbols require that the "rest"
+ 		      of the value fits in 6 bytes, so the upper two bytes
+ 		      must be 0x2000.  All other symbols get to be the
+ 		      absolute type.  */
+ 		   && (sym.value >> 48) == 0x2000)
+ 	    sym.sym_type = mmo_data_sym;
+ 	  else if (strcmp (s->section->name, MMIX_REG_SECTION_NAME) == 0)
+ 	    sym.sym_type = mmo_reg_sym;
+ 	  else if (strcmp (s->section->name,
+ 			   MMIX_REG_CONTENTS_SECTION_NAME) == 0)
+ 	    {
+ 	      sym.sym_type = mmo_reg_sym;
+ 	      sym.value /= 8;
+ 	    }
+ 	  else
+ 	    sym.sym_type = mmo_abs_sym;
+
+ 	  /* FIXME: We assume the order of the received symbols is an
+ 	     ordered mapping of the serial numbers.  This is not
+ 	     necessarily true if we e.g. objcopy a mmo file to another and
+ 	     there are gaps in the numbering.  Note sure if this can
+ 	     happen.  Not sure what to do.  */
+ 	  /* Make sure Main has serial number 1; others start at 2.  */
+ 	  if (strcmp (s->name, MMIX_START_SYMBOL_NAME) == 0)
+ 	    {
+ 	      sym.serno = 1;
+
+ 	      /* Check that the value assigned to :Main is the same as the
+ 		 entry address.  The default linker script asserts this.
+ 		 This is as good a place as any to check this consistency. */
+ 	      if (sym.value != bfd_get_start_address (abfd))
+ 		{
+ 		  /* Arbitrary buffer to hold the printable representation
+ 		     of a vma.  */
+ 		  char vmas_main[40];
+ 		  char vmas_start[40];
+ 		  bfd_vma vma_start = bfd_get_start_address (abfd);
+
+ 		  sprintf_vma (vmas_main, s->value);
+ 		  sprintf_vma (vmas_start, vma_start);
+
+ 		  (*_bfd_error_handler)
+ 		    (_("%s: Bad symbol definition: `Main' set to %s rather\
+  than the start address %s\n"),
+ 		     bfd_get_filename (abfd), vmas_main, vmas_start);
+ 		  bfd_set_error (bfd_error_bad_value);
+ 		  return false;
+ 		}
+ 	    }
+ 	  else
+ 	    sym.serno = serno++;
+
+ 	  if (! mmo_internal_add_3_sym (abfd, &root, &sym))
+ 	    return false;
+ 	}
+     }
+
+   /* Change the root node to be a ":"-prefix.  */
+   root.symchar = ':';
+   root.middle = root.left;
+   root.right = NULL;
+   root.left = NULL;
+
+   /* We have to find out if we can fit the whole symbol table in the mmo
+      symtab.  It would be bad to assume we can always fit it in 262144
+      bytes.  If we can't, just leave the Main symbol.  */
+   trie_len = (mmo_internal_3_length (abfd, &root) + 3)/4;
+
+   if (trie_len > 0xffff)
+     {
+       /* Test this code by using a lower limit in the test above and check
+ 	 that the single "Main" symbol is emitted and handled properly.
+ 	 There's no specific test-case.  */
+       struct mmo_symbol sym;
+
+       (*_bfd_error_handler)
+ 	(_("%s: warning: symbol table too large for mmo, larger than 65535\
+  32-bit words: %d.  Only `Main' will be emitted.\n"),
+ 	 bfd_get_filename (abfd), trie_len);
+
+       memset (&sym, 0, sizeof (sym));
+       sym.sym_type = mmo_abs_sym;
+       sym.name = MMIX_START_SYMBOL_NAME;
+       sym.serno = 1;
+       sym.value = bfd_get_start_address (abfd);
+
+       /* Then patch up a symbol table to be just the ":Main" symbol.  */
+       memset (&root, 0, sizeof (root));
+       root.left = root.middle;
+       root.symchar = 0xff;
+       root.middle = NULL;
+       root.right = NULL;
+
+       if (! mmo_internal_add_3_sym (abfd, &root, &sym))
+ 	return false;
+
+       root.symchar = ':';
+       root.middle = root.left;
+       root.right = NULL;
+       root.left = NULL;
+
+       trie_len = (mmo_internal_3_length (abfd, &root) + 3)/4;
+     }
+
+   /* Reset the written-bytes counter.  */
+   abfd->tdata.mmo_data->byte_no = 0;
+
+   /* Put out the lop_stab mark.  */
+   bfd_put_32 (abfd, (LOP << 24) | (LOP_STAB << 16), buf);
+   if (bfd_bwrite (buf, 4, abfd) != 4)
+     return false;
+
+   /* Dump out symbols.  */
+   mmo_internal_3_dump (abfd, &root);
+
+   if (trie_len != (abfd->tdata.mmo_data->byte_no + 3)/4)
+     {
+       /* I haven't seen this trig.  It seems no use claiming this case
+ 	 isn't debugged and abort if we get here.  Instead emit a
+ 	 diagnostic and fail "normally".  */
+       (*_bfd_error_handler)
+ 	(_("%s: internal error, symbol table changed size from %d to %d\
+  words\n"),
+ 	 bfd_get_filename (abfd), trie_len,
+ 	 (abfd->tdata.mmo_data->byte_no + 3)/4);
+       bfd_set_error (bfd_error_bad_value);
+       return false;
+     }
+
+   /* Dump out remaining bytes in the buffer and handle I/O errors by
+      propagating errors.  */
+   if ((abfd->tdata.mmo_data->byte_no % 4) != 0
+       || abfd->tdata.mmo_data->have_error)
+     {
+       memset (abfd->tdata.mmo_data->buf + (abfd->tdata.mmo_data->byte_no % 4),
+ 	      0, 4 - (abfd->tdata.mmo_data->byte_no % 4));
+
+       if (abfd->tdata.mmo_data->have_error
+ 	  || bfd_bwrite (abfd->tdata.mmo_data->buf, 4, abfd) != 4)
+ 	return false;
+     }
+
+   bfd_put_32 (abfd, (LOP << 24) | (LOP_END << 16) | trie_len, buf);
+   return bfd_bwrite (buf, 4, abfd) == 4;
+ }
+
+ /* Write section unless it is the register contents section.  For that, we
+    instead store the section in the supplied pointer.  This function is
+    used through bfd_map_over_sections.  */
+
+ static void
+ mmo_write_section_unless_reg_contents (abfd, sec, p)
+      bfd *abfd;
+      asection *sec;
+      PTR p;
+ {
+   struct mmo_write_sec_info *infop = (struct mmo_write_sec_info *) p;
+
+   if (infop->retval == false)
+     return;
+
+   if (strcmp (sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
+     {
+       infop->reg_section = sec;
+       return;
+     }
+
+   /* Exclude the convenience register section.  */
+   if (strcmp (sec->name, MMIX_REG_SECTION_NAME) == 0)
+     {
+       if (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS)
+ 	{
+ 	  /* Make sure it hasn't got contents.  It seems impossible to
+ 	     make it carry contents, so we don't have a test-case for
+ 	     this.  */
+ 	  (*_bfd_error_handler)
+ 	    (_("%s: internal error, internal register section %s had\
+  contents\n"),
+ 	     bfd_get_filename (abfd), sec->name);
+ 	  bfd_set_error (bfd_error_bad_value);
+ 	  infop->retval = false;
+ 	  return;
+ 	}
+
+       return;
+     }
+
+   infop->retval = mmo_internal_write_section (abfd, sec);
+ }
+
+ /* Do the actual output of a file.  Assumes mmo_set_section_contents is
+    already called. */
+
+ static boolean
+ mmo_write_object_contents (abfd)
+      bfd *abfd;
+ {
+   struct mmo_write_sec_info wsecinfo;
+
+   /* First, there are a few words of preamble.  */
+   if (! mmo_internal_write_header (abfd))
+     return false;
+
+   wsecinfo.reg_section = NULL;
+   wsecinfo.retval = true;
+
+   bfd_map_over_sections (abfd, mmo_write_section_unless_reg_contents,
+ 			 (PTR) &wsecinfo);
+
+   if (wsecinfo.retval == false)
+     return false;
+
+   if (wsecinfo.reg_section != NULL)
+     {
+       asection *sec = wsecinfo.reg_section;
+       unsigned int z = (unsigned int) (sec->vma / 8);
+
+       /* Registers 0..31 must not be global.  Do sanity check on the "vma"
+ 	 of the register contents section and check that it corresponds to
+ 	 the length of the section.  */
+       if (z < 32 || z >= 255 || (sec->vma & 7) != 0
+ 	  || sec->vma != 256 * 8 - sec->_raw_size - 8)
+ 	{
+ 	  bfd_set_error (bfd_error_bad_value);
+
+ 	  if (sec->_raw_size == 0)
+ 	    /* There must always be at least one such register.  */
+ 	    (*_bfd_error_handler)
+ 	      (_("%s: no initialized registers; section length 0\n"),
+ 	       bfd_get_filename (abfd));
+ 	  else if (sec->vma > (256 - 32) * 8)
+ 	    /* Provide better error message for the case of too many
+ 	       global registers.  */
+ 	    (*_bfd_error_handler)
+ 	      (_("%s: too many initialized registers; section length %ld\n"),
+ 	       bfd_get_filename (abfd),
+ 	       (long) sec->_raw_size);
+ 	  else
+ 	    (*_bfd_error_handler)
+ 	      (_("%s: invalid start address for initialized registers of\
+  length %ld: 0x%lx%08lx\n"),
+ 	       bfd_get_filename (abfd),
+ 	       (long) sec->_raw_size,
+ 	       (unsigned long) (sec->vma >> 32), (unsigned long) (sec->vma));
+
+ 	  return false;
+ 	}
+
+       if (! mmo_internal_write_post (abfd, z, sec))
+ 	return false;
+     }
+   else
+     if (! mmo_internal_write_post (abfd, 255, NULL))
+       return false;
+
+   return mmo_write_symbols_and_terminator (abfd);
+ }
+
+ /* Return the size of a NULL pointer, so we support linking in an mmo
+    object.  */
+
+ static long
+ mmo_get_reloc_upper_bound (abfd, sec)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      asection *sec ATTRIBUTE_UNUSED;
+ {
+   return sizeof (PTR);
+ }
+
+ /* Similarly canonicalize relocs to empty, filling in the terminating NULL
+    pointer.  */
+
+ long
+ mmo_canonicalize_reloc (abfd, section, relptr, symbols)
+      bfd *abfd ATTRIBUTE_UNUSED;
+      sec_ptr section ATTRIBUTE_UNUSED;
+      arelent **relptr;
+      asymbol **symbols ATTRIBUTE_UNUSED;
+ {
+   *relptr = NULL;
+   return 0;
+ }
+
+ /* If there's anything in particular in a mmo bfd that we want to free,
+    make this a real function.  Only do this if you see major memory
+    thrashing; zealous free:ing will cause unwanted behavior, especially if
+    you "free" memory allocated with "bfd_alloc", or even "bfd_release" a
+    block allocated with "bfd_alloc"; they're really allocated from an
+    obstack, and we don't know what was allocated there since this
+    particular allocation.  */
+
+ #define	mmo_close_and_cleanup _bfd_generic_close_and_cleanup
+ #define mmo_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
+
+ /* Perhaps we need to adjust this one; mmo labels (originally) without a
+    leading ':' might more appropriately be called local.  */
+ #define mmo_bfd_is_local_label_name bfd_generic_is_local_label_name
+
+ /* Is this one really used or defined by anyone?  */
+ #define mmo_get_lineno _bfd_nosymbols_get_lineno
+
+ /* FIXME: We can do better on this one, if we have a dwarf2 .debug_line
+    section or if MMO line numbers are implemented.  */
+ #define mmo_find_nearest_line _bfd_nosymbols_find_nearest_line
+ #define mmo_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
+ #define mmo_read_minisymbols _bfd_generic_read_minisymbols
+ #define mmo_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
+
+ #define mmo_get_section_contents_in_window \
+   _bfd_generic_get_section_contents_in_window
+ #define mmo_bfd_get_relocated_section_contents \
+   bfd_generic_get_relocated_section_contents
+ #define mmo_bfd_gc_sections bfd_generic_gc_sections
+ #define mmo_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
+ #define mmo_bfd_link_add_symbols _bfd_generic_link_add_symbols
+ #define mmo_bfd_final_link _bfd_generic_final_link
+ #define mmo_bfd_link_split_section _bfd_generic_link_split_section
+
+ /* Strictly speaking, only MMIX uses this restricted format, but let's not
+    stop anybody from shooting themselves in the foot.  */
+ #define mmo_set_arch_mach bfd_default_set_arch_mach
+ #define mmo_bfd_relax_section bfd_generic_relax_section
+ #define mmo_bfd_merge_sections bfd_generic_merge_sections
+
+ /* objcopy will be upset if we return -1 from bfd_get_reloc_upper_bound by
+    using BFD_JUMP_TABLE_RELOCS (_bfd_norelocs) rather than 0.  FIXME: Most
+    likely a bug in the _bfd_norelocs definition.
+
+    On the other hand, we smuggle in an mmo object (because setting up ELF
+    is too cumbersome) when linking (from other formats, presumably ELF) to
+    represent the g255 entry.  We need to link that object, so need to say
+    it has no relocs.  Upper bound for the size of the relocation table is
+    the size of a NULL pointer, and we support "canonicalization" for that
+    pointer.  */
+ #define mmo_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
+
+ /* We want to copy time of creation, otherwise we'd use
+    BFD_JUMP_TABLE_COPY (_bfd_generic).  */
+ #define mmo_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
+ #define mmo_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
+ #define mmo_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
+ #define mmo_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
+ #define mmo_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
+
+ CONST bfd_target bfd_mmo_vec =
+ {
+   "mmo",			/* name */
+   bfd_target_mmo_flavour,
+   BFD_ENDIAN_BIG,		/* target byte order */
+   BFD_ENDIAN_BIG,		/* target headers byte order */
+
+   /* FIXME: Might need adjustments.  */
+   (HAS_RELOC | EXEC_P |		/* object flags */
+    HAS_LINENO | HAS_DEBUG |
+    HAS_SYMS | HAS_LOCALS | WP_TEXT),
+
+   /* FIXME: Might need adjustments.  */
+   (SEC_CODE | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD
+    | SEC_READONLY | SEC_EXCLUDE | SEC_DEBUGGING | SEC_IN_MEMORY),
+ 				/* section flags */
+   0,				/* leading underscore */
+   ' ',				/* ar_pad_char */
+   16,				/* ar_max_namelen */
+   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* data */
+   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* hdrs */
+
+   {
+     _bfd_dummy_target,
+     mmo_object_p,		/* bfd_check_format */
+     _bfd_dummy_target,
+     _bfd_dummy_target,
+   },
+   {
+     bfd_false,
+     mmo_mkobject,
+     bfd_false,
+     bfd_false,
+   },
+   {				/* bfd_write_contents */
+     bfd_false,
+     mmo_write_object_contents,
+     bfd_false,
+     bfd_false,
+   },
+
+   BFD_JUMP_TABLE_GENERIC (mmo),
+   BFD_JUMP_TABLE_COPY (mmo),
+   BFD_JUMP_TABLE_CORE (_bfd_nocore),
+   BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
+   BFD_JUMP_TABLE_SYMBOLS (mmo),
+   /* We have to provide a valid method for getting relocs, returning zero,
+      so we can't say BFD_JUMP_TABLE_RELOCS (_bfd_norelocs).  */
+   BFD_JUMP_TABLE_RELOCS (mmo),
+   BFD_JUMP_TABLE_WRITE (mmo),
+   BFD_JUMP_TABLE_LINK (mmo),
+   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
+
+   NULL,
+
+   NULL
+ };
*** /dev/null	Tue Jan  1 05:00:00 1980
--- cpu-mmix.c	Sun Sep 30 23:23:59 2001
***************
*** 0 ****
--- 1,41 ----
+ /* BFD library support routines for MMIX.
+    Copyright (C) 2001 Free Software Foundation, Inc.
+    Contributed by Hans-Peter Nilsson (hp@bitrange.com)
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+ #include "bfd.h"
+ #include "sysdep.h"
+ #include "libbfd.h"
+
+ const bfd_arch_info_type
+ bfd_mmix_arch =
+  {
+    64,				/* 64 bits in a word.  */
+    64,				/* 64 bits in an address.  */
+    8,				/* 8 bits in a byte.  */
+    bfd_arch_mmix,		/* Architecture.  */
+    0,				/* Machine number - 0 for now.  */
+    /* Sorry, these are by custom and creeping assumption lower-case.  */
+    "mmix",			/* Architecture name.  */
+    "mmix",			/* Printable name.  */
+    3,				/* Section align power.  */
+    true,			/* This is the default architecture.  */
+    bfd_default_compatible,	/* Architecture comparison function.  */
+    bfd_default_scan,		/* String to architecture conversion.  */
+    NULL				/* Next in list.  */
+ };

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]