Home | History | Annotate | Line # | Download | only in bfd
elf64-mmix.c revision 1.1.1.6
      1      1.1     skrll /* MMIX-specific support for 64-bit ELF.
      2  1.1.1.6  christos    Copyright (C) 2001-2018 Free Software Foundation, Inc.
      3      1.1     skrll    Contributed by Hans-Peter Nilsson <hp (at) bitrange.com>
      4      1.1     skrll 
      5      1.1     skrll    This file is part of BFD, the Binary File Descriptor library.
      6      1.1     skrll 
      7      1.1     skrll    This program is free software; you can redistribute it and/or modify
      8      1.1     skrll    it under the terms of the GNU General Public License as published by
      9      1.1     skrll    the Free Software Foundation; either version 3 of the License, or
     10      1.1     skrll    (at your option) any later version.
     11      1.1     skrll 
     12      1.1     skrll    This program is distributed in the hope that it will be useful,
     13      1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1     skrll    GNU General Public License for more details.
     16      1.1     skrll 
     17      1.1     skrll    You should have received a copy of the GNU General Public License
     18      1.1     skrll    along with this program; if not, write to the Free Software
     19      1.1     skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20      1.1     skrll    MA 02110-1301, USA.  */
     21      1.1     skrll 
     22      1.1     skrll 
     23      1.1     skrll /* No specific ABI or "processor-specific supplement" defined.  */
     24      1.1     skrll 
     25      1.1     skrll /* TODO:
     26      1.1     skrll    - "Traditional" linker relaxation (shrinking whole sections).
     27      1.1     skrll    - Merge reloc stubs jumping to same location.
     28      1.1     skrll    - GETA stub relaxation (call a stub for out of range new
     29      1.1     skrll      R_MMIX_GETA_STUBBABLE).  */
     30      1.1     skrll 
     31      1.1     skrll #include "sysdep.h"
     32      1.1     skrll #include "bfd.h"
     33      1.1     skrll #include "libbfd.h"
     34      1.1     skrll #include "elf-bfd.h"
     35      1.1     skrll #include "elf/mmix.h"
     36      1.1     skrll #include "opcode/mmix.h"
     37      1.1     skrll 
     38      1.1     skrll #define MINUS_ONE	(((bfd_vma) 0) - 1)
     39      1.1     skrll 
     40      1.1     skrll #define MAX_PUSHJ_STUB_SIZE (5 * 4)
     41      1.1     skrll 
     42      1.1     skrll /* Put these everywhere in new code.  */
     43      1.1     skrll #define FATAL_DEBUG						\
     44      1.1     skrll  _bfd_abort (__FILE__, __LINE__,				\
     45      1.1     skrll 	     "Internal: Non-debugged code (test-case missing)")
     46      1.1     skrll 
     47      1.1     skrll #define BAD_CASE(x)				\
     48      1.1     skrll  _bfd_abort (__FILE__, __LINE__,		\
     49      1.1     skrll 	     "bad case for " #x)
     50      1.1     skrll 
     51      1.1     skrll struct _mmix_elf_section_data
     52      1.1     skrll {
     53      1.1     skrll   struct bfd_elf_section_data elf;
     54      1.1     skrll   union
     55      1.1     skrll   {
     56      1.1     skrll     struct bpo_reloc_section_info *reloc;
     57      1.1     skrll     struct bpo_greg_section_info *greg;
     58      1.1     skrll   } bpo;
     59      1.1     skrll 
     60      1.1     skrll   struct pushj_stub_info
     61      1.1     skrll   {
     62      1.1     skrll     /* Maximum number of stubs needed for this section.  */
     63      1.1     skrll     bfd_size_type n_pushj_relocs;
     64      1.1     skrll 
     65      1.1     skrll     /* Size of stubs after a mmix_elf_relax_section round.  */
     66      1.1     skrll     bfd_size_type stubs_size_sum;
     67      1.1     skrll 
     68      1.1     skrll     /* Per-reloc stubs_size_sum information.  The stubs_size_sum member is the sum
     69      1.1     skrll        of these.  Allocated in mmix_elf_check_common_relocs.  */
     70      1.1     skrll     bfd_size_type *stub_size;
     71      1.1     skrll 
     72      1.1     skrll     /* Offset of next stub during relocation.  Somewhat redundant with the
     73      1.1     skrll        above: error coverage is easier and we don't have to reset the
     74      1.1     skrll        stubs_size_sum for relocation.  */
     75      1.1     skrll     bfd_size_type stub_offset;
     76      1.1     skrll   } pjs;
     77  1.1.1.3  christos 
     78  1.1.1.3  christos   /* Whether there has been a warning that this section could not be
     79  1.1.1.3  christos      linked due to a specific cause.  FIXME: a way to access the
     80  1.1.1.3  christos      linker info or output section, then stuff the limiter guard
     81  1.1.1.3  christos      there. */
     82  1.1.1.3  christos   bfd_boolean has_warned_bpo;
     83  1.1.1.3  christos   bfd_boolean has_warned_pushj;
     84      1.1     skrll };
     85      1.1     skrll 
     86      1.1     skrll #define mmix_elf_section_data(sec) \
     87      1.1     skrll   ((struct _mmix_elf_section_data *) elf_section_data (sec))
     88      1.1     skrll 
     89      1.1     skrll /* For each section containing a base-plus-offset (BPO) reloc, we attach
     90      1.1     skrll    this struct as mmix_elf_section_data (section)->bpo, which is otherwise
     91      1.1     skrll    NULL.  */
     92      1.1     skrll struct bpo_reloc_section_info
     93      1.1     skrll   {
     94      1.1     skrll     /* The base is 1; this is the first number in this section.  */
     95      1.1     skrll     size_t first_base_plus_offset_reloc;
     96      1.1     skrll 
     97      1.1     skrll     /* Number of BPO-relocs in this section.  */
     98      1.1     skrll     size_t n_bpo_relocs_this_section;
     99      1.1     skrll 
    100      1.1     skrll     /* Running index, used at relocation time.  */
    101      1.1     skrll     size_t bpo_index;
    102      1.1     skrll 
    103      1.1     skrll     /* We don't have access to the bfd_link_info struct in
    104      1.1     skrll        mmix_final_link_relocate.  What we really want to get at is the
    105      1.1     skrll        global single struct greg_relocation, so we stash it here.  */
    106      1.1     skrll     asection *bpo_greg_section;
    107      1.1     skrll   };
    108      1.1     skrll 
    109      1.1     skrll /* Helper struct (in global context) for the one below.
    110      1.1     skrll    There's one of these created for every BPO reloc.  */
    111      1.1     skrll struct bpo_reloc_request
    112      1.1     skrll   {
    113      1.1     skrll     bfd_vma value;
    114      1.1     skrll 
    115      1.1     skrll     /* Valid after relaxation.  The base is 0; the first register number
    116      1.1     skrll        must be added.  The offset is in range 0..255.  */
    117      1.1     skrll     size_t regindex;
    118      1.1     skrll     size_t offset;
    119      1.1     skrll 
    120      1.1     skrll     /* The order number for this BPO reloc, corresponding to the order in
    121      1.1     skrll        which BPO relocs were found.  Used to create an index after reloc
    122      1.1     skrll        requests are sorted.  */
    123      1.1     skrll     size_t bpo_reloc_no;
    124      1.1     skrll 
    125      1.1     skrll     /* Set when the value is computed.  Better than coding "guard values"
    126      1.1     skrll        into the other members.  Is FALSE only for BPO relocs in a GC:ed
    127      1.1     skrll        section.  */
    128      1.1     skrll     bfd_boolean valid;
    129      1.1     skrll   };
    130      1.1     skrll 
    131      1.1     skrll /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
    132      1.1     skrll    greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
    133      1.1     skrll    which is linked into the register contents section
    134      1.1     skrll    (MMIX_REG_CONTENTS_SECTION_NAME).  This section is created by the
    135      1.1     skrll    linker; using the same hook as for usual with BPO relocs does not
    136      1.1     skrll    collide.  */
    137      1.1     skrll struct bpo_greg_section_info
    138      1.1     skrll   {
    139      1.1     skrll     /* After GC, this reflects the number of remaining, non-excluded
    140      1.1     skrll        BPO-relocs.  */
    141      1.1     skrll     size_t n_bpo_relocs;
    142      1.1     skrll 
    143      1.1     skrll     /* This is the number of allocated bpo_reloc_requests; the size of
    144      1.1     skrll        sorted_indexes.  Valid after the check.*relocs functions are called
    145      1.1     skrll        for all incoming sections.  It includes the number of BPO relocs in
    146      1.1     skrll        sections that were GC:ed.  */
    147      1.1     skrll     size_t n_max_bpo_relocs;
    148      1.1     skrll 
    149      1.1     skrll     /* A counter used to find out when to fold the BPO gregs, since we
    150      1.1     skrll        don't have a single "after-relaxation" hook.  */
    151      1.1     skrll     size_t n_remaining_bpo_relocs_this_relaxation_round;
    152      1.1     skrll 
    153      1.1     skrll     /* The number of linker-allocated GREGs resulting from BPO relocs.
    154      1.1     skrll        This is an approximation after _bfd_mmix_before_linker_allocation
    155      1.1     skrll        and supposedly accurate after mmix_elf_relax_section is called for
    156      1.1     skrll        all incoming non-collected sections.  */
    157      1.1     skrll     size_t n_allocated_bpo_gregs;
    158      1.1     skrll 
    159      1.1     skrll     /* Index into reloc_request[], sorted on increasing "value", secondary
    160      1.1     skrll        by increasing index for strict sorting order.  */
    161      1.1     skrll     size_t *bpo_reloc_indexes;
    162      1.1     skrll 
    163      1.1     skrll     /* An array of all relocations, with the "value" member filled in by
    164      1.1     skrll        the relaxation function.  */
    165      1.1     skrll     struct bpo_reloc_request *reloc_request;
    166      1.1     skrll   };
    167      1.1     skrll 
    168      1.1     skrll 
    169  1.1.1.3  christos extern bfd_boolean mmix_elf_final_link (bfd *, struct bfd_link_info *);
    170      1.1     skrll 
    171  1.1.1.3  christos extern void mmix_elf_symbol_processing (bfd *, asymbol *);
    172      1.1     skrll 
    173      1.1     skrll /* Only intended to be called from a debugger.  */
    174      1.1     skrll extern void mmix_dump_bpo_gregs
    175  1.1.1.6  christos   (struct bfd_link_info *, void (*) (const char *, ...));
    176      1.1     skrll 
    177      1.1     skrll static void
    178  1.1.1.3  christos mmix_set_relaxable_size (bfd *, asection *, void *);
    179  1.1.1.3  christos static bfd_reloc_status_type
    180  1.1.1.3  christos mmix_elf_reloc (bfd *, arelent *, asymbol *, void *,
    181  1.1.1.3  christos 		asection *, bfd *, char **);
    182  1.1.1.3  christos static bfd_reloc_status_type
    183  1.1.1.3  christos mmix_final_link_relocate (reloc_howto_type *, asection *, bfd_byte *, bfd_vma,
    184  1.1.1.3  christos 			  bfd_signed_vma, bfd_vma, const char *, asection *,
    185  1.1.1.3  christos 			  char **);
    186      1.1     skrll 
    187      1.1     skrll 
    188      1.1     skrll /* Watch out: this currently needs to have elements with the same index as
    189      1.1     skrll    their R_MMIX_ number.  */
    190      1.1     skrll static reloc_howto_type elf_mmix_howto_table[] =
    191      1.1     skrll  {
    192      1.1     skrll   /* This reloc does nothing.  */
    193      1.1     skrll   HOWTO (R_MMIX_NONE,		/* type */
    194      1.1     skrll 	 0,			/* rightshift */
    195  1.1.1.4  christos 	 3,			/* size (0 = byte, 1 = short, 2 = long) */
    196  1.1.1.4  christos 	 0,			/* bitsize */
    197      1.1     skrll 	 FALSE,			/* pc_relative */
    198      1.1     skrll 	 0,			/* bitpos */
    199  1.1.1.4  christos 	 complain_overflow_dont, /* complain_on_overflow */
    200      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    201      1.1     skrll 	 "R_MMIX_NONE",		/* name */
    202      1.1     skrll 	 FALSE,			/* partial_inplace */
    203      1.1     skrll 	 0,			/* src_mask */
    204      1.1     skrll 	 0,			/* dst_mask */
    205      1.1     skrll 	 FALSE),		/* pcrel_offset */
    206      1.1     skrll 
    207      1.1     skrll   /* An 8 bit absolute relocation.  */
    208      1.1     skrll   HOWTO (R_MMIX_8,		/* type */
    209      1.1     skrll 	 0,			/* rightshift */
    210      1.1     skrll 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    211      1.1     skrll 	 8,			/* bitsize */
    212      1.1     skrll 	 FALSE,			/* pc_relative */
    213      1.1     skrll 	 0,			/* bitpos */
    214      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    215      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    216      1.1     skrll 	 "R_MMIX_8",		/* name */
    217      1.1     skrll 	 FALSE,			/* partial_inplace */
    218      1.1     skrll 	 0,			/* src_mask */
    219      1.1     skrll 	 0xff,			/* dst_mask */
    220      1.1     skrll 	 FALSE),		/* pcrel_offset */
    221      1.1     skrll 
    222      1.1     skrll   /* An 16 bit absolute relocation.  */
    223      1.1     skrll   HOWTO (R_MMIX_16,		/* type */
    224      1.1     skrll 	 0,			/* rightshift */
    225      1.1     skrll 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    226      1.1     skrll 	 16,			/* bitsize */
    227      1.1     skrll 	 FALSE,			/* pc_relative */
    228      1.1     skrll 	 0,			/* bitpos */
    229      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    230      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    231      1.1     skrll 	 "R_MMIX_16",		/* name */
    232      1.1     skrll 	 FALSE,			/* partial_inplace */
    233      1.1     skrll 	 0,			/* src_mask */
    234      1.1     skrll 	 0xffff,		/* dst_mask */
    235      1.1     skrll 	 FALSE),		/* pcrel_offset */
    236      1.1     skrll 
    237      1.1     skrll   /* An 24 bit absolute relocation.  */
    238      1.1     skrll   HOWTO (R_MMIX_24,		/* type */
    239      1.1     skrll 	 0,			/* rightshift */
    240      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    241      1.1     skrll 	 24,			/* bitsize */
    242      1.1     skrll 	 FALSE,			/* pc_relative */
    243      1.1     skrll 	 0,			/* bitpos */
    244      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    245      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    246      1.1     skrll 	 "R_MMIX_24",		/* name */
    247      1.1     skrll 	 FALSE,			/* partial_inplace */
    248      1.1     skrll 	 ~0xffffff,		/* src_mask */
    249      1.1     skrll 	 0xffffff,		/* dst_mask */
    250      1.1     skrll 	 FALSE),		/* pcrel_offset */
    251      1.1     skrll 
    252      1.1     skrll   /* A 32 bit absolute relocation.  */
    253      1.1     skrll   HOWTO (R_MMIX_32,		/* type */
    254      1.1     skrll 	 0,			/* rightshift */
    255      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    256      1.1     skrll 	 32,			/* bitsize */
    257      1.1     skrll 	 FALSE,			/* pc_relative */
    258      1.1     skrll 	 0,			/* bitpos */
    259      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    260      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    261      1.1     skrll 	 "R_MMIX_32",		/* name */
    262      1.1     skrll 	 FALSE,			/* partial_inplace */
    263      1.1     skrll 	 0,			/* src_mask */
    264      1.1     skrll 	 0xffffffff,		/* dst_mask */
    265      1.1     skrll 	 FALSE),		/* pcrel_offset */
    266      1.1     skrll 
    267      1.1     skrll   /* 64 bit relocation.  */
    268      1.1     skrll   HOWTO (R_MMIX_64,		/* type */
    269      1.1     skrll 	 0,			/* rightshift */
    270      1.1     skrll 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    271      1.1     skrll 	 64,			/* bitsize */
    272      1.1     skrll 	 FALSE,			/* pc_relative */
    273      1.1     skrll 	 0,			/* bitpos */
    274      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    275      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    276      1.1     skrll 	 "R_MMIX_64",		/* name */
    277      1.1     skrll 	 FALSE,			/* partial_inplace */
    278      1.1     skrll 	 0,			/* src_mask */
    279      1.1     skrll 	 MINUS_ONE,		/* dst_mask */
    280      1.1     skrll 	 FALSE),		/* pcrel_offset */
    281      1.1     skrll 
    282      1.1     skrll   /* An 8 bit PC-relative relocation.  */
    283      1.1     skrll   HOWTO (R_MMIX_PC_8,		/* type */
    284      1.1     skrll 	 0,			/* rightshift */
    285      1.1     skrll 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    286      1.1     skrll 	 8,			/* bitsize */
    287      1.1     skrll 	 TRUE,			/* pc_relative */
    288      1.1     skrll 	 0,			/* bitpos */
    289      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    290      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    291      1.1     skrll 	 "R_MMIX_PC_8",		/* name */
    292      1.1     skrll 	 FALSE,			/* partial_inplace */
    293      1.1     skrll 	 0,			/* src_mask */
    294      1.1     skrll 	 0xff,			/* dst_mask */
    295      1.1     skrll 	 TRUE),			/* pcrel_offset */
    296      1.1     skrll 
    297      1.1     skrll   /* An 16 bit PC-relative relocation.  */
    298      1.1     skrll   HOWTO (R_MMIX_PC_16,		/* type */
    299      1.1     skrll 	 0,			/* rightshift */
    300      1.1     skrll 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    301      1.1     skrll 	 16,			/* bitsize */
    302      1.1     skrll 	 TRUE,			/* pc_relative */
    303      1.1     skrll 	 0,			/* bitpos */
    304      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    305      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    306      1.1     skrll 	 "R_MMIX_PC_16",	/* name */
    307      1.1     skrll 	 FALSE,			/* partial_inplace */
    308      1.1     skrll 	 0,			/* src_mask */
    309      1.1     skrll 	 0xffff,		/* dst_mask */
    310      1.1     skrll 	 TRUE),			/* pcrel_offset */
    311      1.1     skrll 
    312      1.1     skrll   /* An 24 bit PC-relative relocation.  */
    313      1.1     skrll   HOWTO (R_MMIX_PC_24,		/* type */
    314      1.1     skrll 	 0,			/* rightshift */
    315      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    316      1.1     skrll 	 24,			/* bitsize */
    317      1.1     skrll 	 TRUE,			/* pc_relative */
    318      1.1     skrll 	 0,			/* bitpos */
    319      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    320      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    321      1.1     skrll 	 "R_MMIX_PC_24",	/* name */
    322      1.1     skrll 	 FALSE,			/* partial_inplace */
    323      1.1     skrll 	 ~0xffffff,		/* src_mask */
    324      1.1     skrll 	 0xffffff,		/* dst_mask */
    325      1.1     skrll 	 TRUE),			/* pcrel_offset */
    326      1.1     skrll 
    327      1.1     skrll   /* A 32 bit absolute PC-relative relocation.  */
    328      1.1     skrll   HOWTO (R_MMIX_PC_32,		/* type */
    329      1.1     skrll 	 0,			/* rightshift */
    330      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    331      1.1     skrll 	 32,			/* bitsize */
    332      1.1     skrll 	 TRUE,			/* pc_relative */
    333      1.1     skrll 	 0,			/* bitpos */
    334      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    335      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    336      1.1     skrll 	 "R_MMIX_PC_32",	/* name */
    337      1.1     skrll 	 FALSE,			/* partial_inplace */
    338      1.1     skrll 	 0,			/* src_mask */
    339      1.1     skrll 	 0xffffffff,		/* dst_mask */
    340      1.1     skrll 	 TRUE),			/* pcrel_offset */
    341      1.1     skrll 
    342      1.1     skrll   /* 64 bit PC-relative relocation.  */
    343      1.1     skrll   HOWTO (R_MMIX_PC_64,		/* type */
    344      1.1     skrll 	 0,			/* rightshift */
    345      1.1     skrll 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    346      1.1     skrll 	 64,			/* bitsize */
    347      1.1     skrll 	 TRUE,			/* pc_relative */
    348      1.1     skrll 	 0,			/* bitpos */
    349      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    350      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    351      1.1     skrll 	 "R_MMIX_PC_64",	/* name */
    352      1.1     skrll 	 FALSE,			/* partial_inplace */
    353      1.1     skrll 	 0,			/* src_mask */
    354      1.1     skrll 	 MINUS_ONE,		/* dst_mask */
    355      1.1     skrll 	 TRUE),			/* pcrel_offset */
    356      1.1     skrll 
    357      1.1     skrll   /* GNU extension to record C++ vtable hierarchy.  */
    358      1.1     skrll   HOWTO (R_MMIX_GNU_VTINHERIT, /* type */
    359      1.1     skrll 	 0,			/* rightshift */
    360      1.1     skrll 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    361      1.1     skrll 	 0,			/* bitsize */
    362      1.1     skrll 	 FALSE,			/* pc_relative */
    363      1.1     skrll 	 0,			/* bitpos */
    364      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    365      1.1     skrll 	 NULL,			/* special_function */
    366      1.1     skrll 	 "R_MMIX_GNU_VTINHERIT", /* name */
    367      1.1     skrll 	 FALSE,			/* partial_inplace */
    368      1.1     skrll 	 0,			/* src_mask */
    369      1.1     skrll 	 0,			/* dst_mask */
    370      1.1     skrll 	 TRUE),			/* pcrel_offset */
    371      1.1     skrll 
    372      1.1     skrll   /* GNU extension to record C++ vtable member usage.  */
    373      1.1     skrll   HOWTO (R_MMIX_GNU_VTENTRY,	/* type */
    374      1.1     skrll 	 0,			/* rightshift */
    375      1.1     skrll 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    376      1.1     skrll 	 0,			/* bitsize */
    377      1.1     skrll 	 FALSE,			/* pc_relative */
    378      1.1     skrll 	 0,			/* bitpos */
    379      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    380      1.1     skrll 	 _bfd_elf_rel_vtable_reloc_fn,	/* special_function */
    381      1.1     skrll 	 "R_MMIX_GNU_VTENTRY", /* name */
    382      1.1     skrll 	 FALSE,			/* partial_inplace */
    383      1.1     skrll 	 0,			/* src_mask */
    384      1.1     skrll 	 0,			/* dst_mask */
    385      1.1     skrll 	 FALSE),		/* pcrel_offset */
    386      1.1     skrll 
    387      1.1     skrll   /* The GETA relocation is supposed to get any address that could
    388      1.1     skrll      possibly be reached by the GETA instruction.  It can silently expand
    389      1.1     skrll      to get a 64-bit operand, but will complain if any of the two least
    390      1.1     skrll      significant bits are set.  The howto members reflect a simple GETA.  */
    391      1.1     skrll   HOWTO (R_MMIX_GETA,		/* type */
    392      1.1     skrll 	 2,			/* rightshift */
    393      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    394      1.1     skrll 	 19,			/* bitsize */
    395      1.1     skrll 	 TRUE,			/* pc_relative */
    396      1.1     skrll 	 0,			/* bitpos */
    397      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    398      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    399      1.1     skrll 	 "R_MMIX_GETA",		/* name */
    400      1.1     skrll 	 FALSE,			/* partial_inplace */
    401      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    402      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    403      1.1     skrll 	 TRUE),			/* pcrel_offset */
    404      1.1     skrll 
    405      1.1     skrll   HOWTO (R_MMIX_GETA_1,		/* type */
    406      1.1     skrll 	 2,			/* rightshift */
    407      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    408      1.1     skrll 	 19,			/* bitsize */
    409      1.1     skrll 	 TRUE,			/* pc_relative */
    410      1.1     skrll 	 0,			/* bitpos */
    411      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    412      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    413      1.1     skrll 	 "R_MMIX_GETA_1",		/* name */
    414      1.1     skrll 	 FALSE,			/* partial_inplace */
    415      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    416      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    417      1.1     skrll 	 TRUE),			/* pcrel_offset */
    418      1.1     skrll 
    419      1.1     skrll   HOWTO (R_MMIX_GETA_2,		/* type */
    420      1.1     skrll 	 2,			/* rightshift */
    421      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    422      1.1     skrll 	 19,			/* bitsize */
    423      1.1     skrll 	 TRUE,			/* pc_relative */
    424      1.1     skrll 	 0,			/* bitpos */
    425      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    426      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    427      1.1     skrll 	 "R_MMIX_GETA_2",		/* name */
    428      1.1     skrll 	 FALSE,			/* partial_inplace */
    429      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    430      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    431      1.1     skrll 	 TRUE),			/* pcrel_offset */
    432      1.1     skrll 
    433      1.1     skrll   HOWTO (R_MMIX_GETA_3,		/* type */
    434      1.1     skrll 	 2,			/* rightshift */
    435      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    436      1.1     skrll 	 19,			/* bitsize */
    437      1.1     skrll 	 TRUE,			/* pc_relative */
    438      1.1     skrll 	 0,			/* bitpos */
    439      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    440      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    441      1.1     skrll 	 "R_MMIX_GETA_3",		/* name */
    442      1.1     skrll 	 FALSE,			/* partial_inplace */
    443      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    444      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    445      1.1     skrll 	 TRUE),			/* pcrel_offset */
    446      1.1     skrll 
    447      1.1     skrll   /* The conditional branches are supposed to reach any (code) address.
    448      1.1     skrll      It can silently expand to a 64-bit operand, but will emit an error if
    449      1.1     skrll      any of the two least significant bits are set.  The howto members
    450      1.1     skrll      reflect a simple branch.  */
    451      1.1     skrll   HOWTO (R_MMIX_CBRANCH,	/* type */
    452      1.1     skrll 	 2,			/* rightshift */
    453      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    454      1.1     skrll 	 19,			/* bitsize */
    455      1.1     skrll 	 TRUE,			/* pc_relative */
    456      1.1     skrll 	 0,			/* bitpos */
    457      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    458      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    459      1.1     skrll 	 "R_MMIX_CBRANCH",	/* name */
    460      1.1     skrll 	 FALSE,			/* partial_inplace */
    461      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    462      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    463  1.1.1.6  christos 	 TRUE),			/* pcrel_offset */
    464      1.1     skrll 
    465      1.1     skrll   HOWTO (R_MMIX_CBRANCH_J,	/* type */
    466      1.1     skrll 	 2,			/* rightshift */
    467      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    468      1.1     skrll 	 19,			/* bitsize */
    469      1.1     skrll 	 TRUE,			/* pc_relative */
    470      1.1     skrll 	 0,			/* bitpos */
    471      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    472      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    473      1.1     skrll 	 "R_MMIX_CBRANCH_J",	/* name */
    474      1.1     skrll 	 FALSE,			/* partial_inplace */
    475      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    476      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    477      1.1     skrll 	 TRUE),			/* pcrel_offset */
    478      1.1     skrll 
    479      1.1     skrll   HOWTO (R_MMIX_CBRANCH_1,	/* type */
    480      1.1     skrll 	 2,			/* rightshift */
    481      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    482      1.1     skrll 	 19,			/* bitsize */
    483      1.1     skrll 	 TRUE,			/* pc_relative */
    484      1.1     skrll 	 0,			/* bitpos */
    485      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    486      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    487      1.1     skrll 	 "R_MMIX_CBRANCH_1",	/* name */
    488      1.1     skrll 	 FALSE,			/* partial_inplace */
    489      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    490      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    491      1.1     skrll 	 TRUE),			/* pcrel_offset */
    492      1.1     skrll 
    493      1.1     skrll   HOWTO (R_MMIX_CBRANCH_2,	/* type */
    494      1.1     skrll 	 2,			/* rightshift */
    495      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    496      1.1     skrll 	 19,			/* bitsize */
    497      1.1     skrll 	 TRUE,			/* pc_relative */
    498      1.1     skrll 	 0,			/* bitpos */
    499      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    500      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    501      1.1     skrll 	 "R_MMIX_CBRANCH_2",	/* name */
    502      1.1     skrll 	 FALSE,			/* partial_inplace */
    503      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    504      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    505      1.1     skrll 	 TRUE),			/* pcrel_offset */
    506      1.1     skrll 
    507      1.1     skrll   HOWTO (R_MMIX_CBRANCH_3,	/* type */
    508      1.1     skrll 	 2,			/* rightshift */
    509      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    510      1.1     skrll 	 19,			/* bitsize */
    511      1.1     skrll 	 TRUE,			/* pc_relative */
    512      1.1     skrll 	 0,			/* bitpos */
    513      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    514      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    515      1.1     skrll 	 "R_MMIX_CBRANCH_3",	/* name */
    516      1.1     skrll 	 FALSE,			/* partial_inplace */
    517      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    518      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    519      1.1     skrll 	 TRUE),			/* pcrel_offset */
    520      1.1     skrll 
    521      1.1     skrll   /* The PUSHJ instruction can reach any (code) address, as long as it's
    522      1.1     skrll      the beginning of a function (no usable restriction).  It can silently
    523      1.1     skrll      expand to a 64-bit operand, but will emit an error if any of the two
    524      1.1     skrll      least significant bits are set.  It can also expand into a call to a
    525      1.1     skrll      stub; see R_MMIX_PUSHJ_STUBBABLE.  The howto members reflect a simple
    526      1.1     skrll      PUSHJ.  */
    527      1.1     skrll   HOWTO (R_MMIX_PUSHJ,		/* type */
    528      1.1     skrll 	 2,			/* rightshift */
    529      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    530      1.1     skrll 	 19,			/* bitsize */
    531      1.1     skrll 	 TRUE,			/* pc_relative */
    532      1.1     skrll 	 0,			/* bitpos */
    533      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    534      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    535      1.1     skrll 	 "R_MMIX_PUSHJ",	/* name */
    536      1.1     skrll 	 FALSE,			/* partial_inplace */
    537      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    538      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    539      1.1     skrll 	 TRUE),			/* pcrel_offset */
    540      1.1     skrll 
    541      1.1     skrll   HOWTO (R_MMIX_PUSHJ_1,	/* type */
    542      1.1     skrll 	 2,			/* rightshift */
    543      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    544      1.1     skrll 	 19,			/* bitsize */
    545      1.1     skrll 	 TRUE,			/* pc_relative */
    546      1.1     skrll 	 0,			/* bitpos */
    547      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    548      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    549      1.1     skrll 	 "R_MMIX_PUSHJ_1",	/* name */
    550      1.1     skrll 	 FALSE,			/* partial_inplace */
    551      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    552      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    553      1.1     skrll 	 TRUE),			/* pcrel_offset */
    554      1.1     skrll 
    555      1.1     skrll   HOWTO (R_MMIX_PUSHJ_2,	/* type */
    556      1.1     skrll 	 2,			/* rightshift */
    557      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    558      1.1     skrll 	 19,			/* bitsize */
    559      1.1     skrll 	 TRUE,			/* pc_relative */
    560      1.1     skrll 	 0,			/* bitpos */
    561      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    562      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    563      1.1     skrll 	 "R_MMIX_PUSHJ_2",	/* name */
    564      1.1     skrll 	 FALSE,			/* partial_inplace */
    565      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    566      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    567      1.1     skrll 	 TRUE),			/* pcrel_offset */
    568      1.1     skrll 
    569      1.1     skrll   HOWTO (R_MMIX_PUSHJ_3,	/* type */
    570      1.1     skrll 	 2,			/* rightshift */
    571      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    572      1.1     skrll 	 19,			/* bitsize */
    573      1.1     skrll 	 TRUE,			/* pc_relative */
    574      1.1     skrll 	 0,			/* bitpos */
    575      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    576      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    577      1.1     skrll 	 "R_MMIX_PUSHJ_3",	/* name */
    578      1.1     skrll 	 FALSE,			/* partial_inplace */
    579      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    580      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    581      1.1     skrll 	 TRUE),			/* pcrel_offset */
    582      1.1     skrll 
    583      1.1     skrll   /* A JMP is supposed to reach any (code) address.  By itself, it can
    584      1.1     skrll      reach +-64M; the expansion can reach all 64 bits.  Note that the 64M
    585      1.1     skrll      limit is soon reached if you link the program in wildly different
    586      1.1     skrll      memory segments.  The howto members reflect a trivial JMP.  */
    587      1.1     skrll   HOWTO (R_MMIX_JMP,		/* type */
    588      1.1     skrll 	 2,			/* rightshift */
    589      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    590      1.1     skrll 	 27,			/* bitsize */
    591      1.1     skrll 	 TRUE,			/* pc_relative */
    592      1.1     skrll 	 0,			/* bitpos */
    593      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    594      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    595      1.1     skrll 	 "R_MMIX_JMP",		/* name */
    596      1.1     skrll 	 FALSE,			/* partial_inplace */
    597      1.1     skrll 	 ~0x1ffffff,		/* src_mask */
    598      1.1     skrll 	 0x1ffffff,		/* dst_mask */
    599      1.1     skrll 	 TRUE),			/* pcrel_offset */
    600      1.1     skrll 
    601      1.1     skrll   HOWTO (R_MMIX_JMP_1,		/* type */
    602      1.1     skrll 	 2,			/* rightshift */
    603      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    604      1.1     skrll 	 27,			/* bitsize */
    605      1.1     skrll 	 TRUE,			/* pc_relative */
    606      1.1     skrll 	 0,			/* bitpos */
    607      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    608      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    609      1.1     skrll 	 "R_MMIX_JMP_1",	/* name */
    610      1.1     skrll 	 FALSE,			/* partial_inplace */
    611      1.1     skrll 	 ~0x1ffffff,		/* src_mask */
    612      1.1     skrll 	 0x1ffffff,		/* dst_mask */
    613      1.1     skrll 	 TRUE),			/* pcrel_offset */
    614      1.1     skrll 
    615      1.1     skrll   HOWTO (R_MMIX_JMP_2,		/* type */
    616      1.1     skrll 	 2,			/* rightshift */
    617      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    618      1.1     skrll 	 27,			/* bitsize */
    619      1.1     skrll 	 TRUE,			/* pc_relative */
    620      1.1     skrll 	 0,			/* bitpos */
    621      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    622      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    623      1.1     skrll 	 "R_MMIX_JMP_2",	/* name */
    624      1.1     skrll 	 FALSE,			/* partial_inplace */
    625      1.1     skrll 	 ~0x1ffffff,		/* src_mask */
    626      1.1     skrll 	 0x1ffffff,		/* dst_mask */
    627      1.1     skrll 	 TRUE),			/* pcrel_offset */
    628      1.1     skrll 
    629      1.1     skrll   HOWTO (R_MMIX_JMP_3,		/* type */
    630      1.1     skrll 	 2,			/* rightshift */
    631      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    632      1.1     skrll 	 27,			/* bitsize */
    633      1.1     skrll 	 TRUE,			/* pc_relative */
    634      1.1     skrll 	 0,			/* bitpos */
    635      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    636      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    637      1.1     skrll 	 "R_MMIX_JMP_3",	/* name */
    638      1.1     skrll 	 FALSE,			/* partial_inplace */
    639      1.1     skrll 	 ~0x1ffffff,		/* src_mask */
    640      1.1     skrll 	 0x1ffffff,		/* dst_mask */
    641      1.1     skrll 	 TRUE),			/* pcrel_offset */
    642      1.1     skrll 
    643      1.1     skrll   /* When we don't emit link-time-relaxable code from the assembler, or
    644      1.1     skrll      when relaxation has done all it can do, these relocs are used.  For
    645      1.1     skrll      GETA/PUSHJ/branches.  */
    646      1.1     skrll   HOWTO (R_MMIX_ADDR19,		/* type */
    647      1.1     skrll 	 2,			/* rightshift */
    648      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    649      1.1     skrll 	 19,			/* bitsize */
    650      1.1     skrll 	 TRUE,			/* pc_relative */
    651      1.1     skrll 	 0,			/* bitpos */
    652      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    653      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    654      1.1     skrll 	 "R_MMIX_ADDR19",	/* name */
    655      1.1     skrll 	 FALSE,			/* partial_inplace */
    656      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    657      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    658      1.1     skrll 	 TRUE),			/* pcrel_offset */
    659      1.1     skrll 
    660      1.1     skrll   /* For JMP.  */
    661      1.1     skrll   HOWTO (R_MMIX_ADDR27,		/* type */
    662      1.1     skrll 	 2,			/* rightshift */
    663      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    664      1.1     skrll 	 27,			/* bitsize */
    665      1.1     skrll 	 TRUE,			/* pc_relative */
    666      1.1     skrll 	 0,			/* bitpos */
    667      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    668      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    669      1.1     skrll 	 "R_MMIX_ADDR27",	/* name */
    670      1.1     skrll 	 FALSE,			/* partial_inplace */
    671      1.1     skrll 	 ~0x1ffffff,		/* src_mask */
    672      1.1     skrll 	 0x1ffffff,		/* dst_mask */
    673      1.1     skrll 	 TRUE),			/* pcrel_offset */
    674      1.1     skrll 
    675      1.1     skrll   /* A general register or the value 0..255.  If a value, then the
    676      1.1     skrll      instruction (offset -3) needs adjusting.  */
    677      1.1     skrll   HOWTO (R_MMIX_REG_OR_BYTE,	/* type */
    678      1.1     skrll 	 0,			/* rightshift */
    679      1.1     skrll 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    680      1.1     skrll 	 8,			/* bitsize */
    681      1.1     skrll 	 FALSE,			/* pc_relative */
    682      1.1     skrll 	 0,			/* bitpos */
    683      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    684      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    685      1.1     skrll 	 "R_MMIX_REG_OR_BYTE",	/* name */
    686      1.1     skrll 	 FALSE,			/* partial_inplace */
    687      1.1     skrll 	 0,			/* src_mask */
    688      1.1     skrll 	 0xff,			/* dst_mask */
    689      1.1     skrll 	 FALSE),		/* pcrel_offset */
    690      1.1     skrll 
    691      1.1     skrll   /* A general register.  */
    692      1.1     skrll   HOWTO (R_MMIX_REG,		/* type */
    693      1.1     skrll 	 0,			/* rightshift */
    694      1.1     skrll 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    695      1.1     skrll 	 8,			/* bitsize */
    696      1.1     skrll 	 FALSE,			/* pc_relative */
    697      1.1     skrll 	 0,			/* bitpos */
    698      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    699      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    700      1.1     skrll 	 "R_MMIX_REG",		/* name */
    701      1.1     skrll 	 FALSE,			/* partial_inplace */
    702      1.1     skrll 	 0,			/* src_mask */
    703      1.1     skrll 	 0xff,			/* dst_mask */
    704      1.1     skrll 	 FALSE),		/* pcrel_offset */
    705      1.1     skrll 
    706      1.1     skrll   /* A register plus an index, corresponding to the relocation expression.
    707      1.1     skrll      The sizes must correspond to the valid range of the expression, while
    708      1.1     skrll      the bitmasks correspond to what we store in the image.  */
    709      1.1     skrll   HOWTO (R_MMIX_BASE_PLUS_OFFSET,	/* type */
    710      1.1     skrll 	 0,			/* rightshift */
    711      1.1     skrll 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    712      1.1     skrll 	 64,			/* bitsize */
    713      1.1     skrll 	 FALSE,			/* pc_relative */
    714      1.1     skrll 	 0,			/* bitpos */
    715      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    716      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    717      1.1     skrll 	 "R_MMIX_BASE_PLUS_OFFSET", /* name */
    718      1.1     skrll 	 FALSE,			/* partial_inplace */
    719      1.1     skrll 	 0,			/* src_mask */
    720      1.1     skrll 	 0xffff,		/* dst_mask */
    721      1.1     skrll 	 FALSE),		/* pcrel_offset */
    722      1.1     skrll 
    723      1.1     skrll   /* A "magic" relocation for a LOCAL expression, asserting that the
    724      1.1     skrll      expression is less than the number of global registers.  No actual
    725      1.1     skrll      modification of the contents is done.  Implementing this as a
    726      1.1     skrll      relocation was less intrusive than e.g. putting such expressions in a
    727      1.1     skrll      section to discard *after* relocation.  */
    728      1.1     skrll   HOWTO (R_MMIX_LOCAL,		/* type */
    729      1.1     skrll 	 0,			/* rightshift */
    730      1.1     skrll 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    731      1.1     skrll 	 0,			/* bitsize */
    732      1.1     skrll 	 FALSE,			/* pc_relative */
    733      1.1     skrll 	 0,			/* bitpos */
    734      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    735      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    736      1.1     skrll 	 "R_MMIX_LOCAL",	/* name */
    737      1.1     skrll 	 FALSE,			/* partial_inplace */
    738      1.1     skrll 	 0,			/* src_mask */
    739      1.1     skrll 	 0,			/* dst_mask */
    740      1.1     skrll 	 FALSE),		/* pcrel_offset */
    741      1.1     skrll 
    742      1.1     skrll   HOWTO (R_MMIX_PUSHJ_STUBBABLE, /* type */
    743      1.1     skrll 	 2,			/* rightshift */
    744      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    745      1.1     skrll 	 19,			/* bitsize */
    746      1.1     skrll 	 TRUE,			/* pc_relative */
    747      1.1     skrll 	 0,			/* bitpos */
    748      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    749      1.1     skrll 	 mmix_elf_reloc,	/* special_function */
    750      1.1     skrll 	 "R_MMIX_PUSHJ_STUBBABLE", /* name */
    751      1.1     skrll 	 FALSE,			/* partial_inplace */
    752      1.1     skrll 	 ~0x0100ffff,		/* src_mask */
    753      1.1     skrll 	 0x0100ffff,		/* dst_mask */
    754      1.1     skrll 	 TRUE)			/* pcrel_offset */
    755      1.1     skrll  };
    756      1.1     skrll 
    757      1.1     skrll 
    758      1.1     skrll /* Map BFD reloc types to MMIX ELF reloc types.  */
    759      1.1     skrll 
    760      1.1     skrll struct mmix_reloc_map
    761      1.1     skrll   {
    762      1.1     skrll     bfd_reloc_code_real_type bfd_reloc_val;
    763      1.1     skrll     enum elf_mmix_reloc_type elf_reloc_val;
    764      1.1     skrll   };
    765      1.1     skrll 
    766      1.1     skrll 
    767      1.1     skrll static const struct mmix_reloc_map mmix_reloc_map[] =
    768      1.1     skrll   {
    769      1.1     skrll     {BFD_RELOC_NONE, R_MMIX_NONE},
    770      1.1     skrll     {BFD_RELOC_8, R_MMIX_8},
    771      1.1     skrll     {BFD_RELOC_16, R_MMIX_16},
    772      1.1     skrll     {BFD_RELOC_24, R_MMIX_24},
    773      1.1     skrll     {BFD_RELOC_32, R_MMIX_32},
    774      1.1     skrll     {BFD_RELOC_64, R_MMIX_64},
    775      1.1     skrll     {BFD_RELOC_8_PCREL, R_MMIX_PC_8},
    776      1.1     skrll     {BFD_RELOC_16_PCREL, R_MMIX_PC_16},
    777      1.1     skrll     {BFD_RELOC_24_PCREL, R_MMIX_PC_24},
    778      1.1     skrll     {BFD_RELOC_32_PCREL, R_MMIX_PC_32},
    779      1.1     skrll     {BFD_RELOC_64_PCREL, R_MMIX_PC_64},
    780      1.1     skrll     {BFD_RELOC_VTABLE_INHERIT, R_MMIX_GNU_VTINHERIT},
    781      1.1     skrll     {BFD_RELOC_VTABLE_ENTRY, R_MMIX_GNU_VTENTRY},
    782      1.1     skrll     {BFD_RELOC_MMIX_GETA, R_MMIX_GETA},
    783      1.1     skrll     {BFD_RELOC_MMIX_CBRANCH, R_MMIX_CBRANCH},
    784      1.1     skrll     {BFD_RELOC_MMIX_PUSHJ, R_MMIX_PUSHJ},
    785      1.1     skrll     {BFD_RELOC_MMIX_JMP, R_MMIX_JMP},
    786      1.1     skrll     {BFD_RELOC_MMIX_ADDR19, R_MMIX_ADDR19},
    787      1.1     skrll     {BFD_RELOC_MMIX_ADDR27, R_MMIX_ADDR27},
    788      1.1     skrll     {BFD_RELOC_MMIX_REG_OR_BYTE, R_MMIX_REG_OR_BYTE},
    789      1.1     skrll     {BFD_RELOC_MMIX_REG, R_MMIX_REG},
    790      1.1     skrll     {BFD_RELOC_MMIX_BASE_PLUS_OFFSET, R_MMIX_BASE_PLUS_OFFSET},
    791      1.1     skrll     {BFD_RELOC_MMIX_LOCAL, R_MMIX_LOCAL},
    792      1.1     skrll     {BFD_RELOC_MMIX_PUSHJ_STUBBABLE, R_MMIX_PUSHJ_STUBBABLE}
    793      1.1     skrll   };
    794      1.1     skrll 
    795      1.1     skrll static reloc_howto_type *
    796  1.1.1.3  christos bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    797  1.1.1.3  christos 				 bfd_reloc_code_real_type code)
    798      1.1     skrll {
    799      1.1     skrll   unsigned int i;
    800      1.1     skrll 
    801      1.1     skrll   for (i = 0;
    802      1.1     skrll        i < sizeof (mmix_reloc_map) / sizeof (mmix_reloc_map[0]);
    803      1.1     skrll        i++)
    804      1.1     skrll     {
    805      1.1     skrll       if (mmix_reloc_map[i].bfd_reloc_val == code)
    806      1.1     skrll 	return &elf_mmix_howto_table[mmix_reloc_map[i].elf_reloc_val];
    807      1.1     skrll     }
    808      1.1     skrll 
    809      1.1     skrll   return NULL;
    810      1.1     skrll }
    811      1.1     skrll 
    812      1.1     skrll static reloc_howto_type *
    813      1.1     skrll bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    814      1.1     skrll 				 const char *r_name)
    815      1.1     skrll {
    816      1.1     skrll   unsigned int i;
    817      1.1     skrll 
    818      1.1     skrll   for (i = 0;
    819      1.1     skrll        i < sizeof (elf_mmix_howto_table) / sizeof (elf_mmix_howto_table[0]);
    820      1.1     skrll        i++)
    821      1.1     skrll     if (elf_mmix_howto_table[i].name != NULL
    822      1.1     skrll 	&& strcasecmp (elf_mmix_howto_table[i].name, r_name) == 0)
    823      1.1     skrll       return &elf_mmix_howto_table[i];
    824      1.1     skrll 
    825      1.1     skrll   return NULL;
    826      1.1     skrll }
    827      1.1     skrll 
    828      1.1     skrll static bfd_boolean
    829  1.1.1.3  christos mmix_elf_new_section_hook (bfd *abfd, asection *sec)
    830      1.1     skrll {
    831      1.1     skrll   if (!sec->used_by_bfd)
    832      1.1     skrll     {
    833      1.1     skrll       struct _mmix_elf_section_data *sdata;
    834      1.1     skrll       bfd_size_type amt = sizeof (*sdata);
    835      1.1     skrll 
    836      1.1     skrll       sdata = bfd_zalloc (abfd, amt);
    837      1.1     skrll       if (sdata == NULL)
    838      1.1     skrll 	return FALSE;
    839      1.1     skrll       sec->used_by_bfd = sdata;
    840      1.1     skrll     }
    841      1.1     skrll 
    842      1.1     skrll   return _bfd_elf_new_section_hook (abfd, sec);
    843      1.1     skrll }
    844      1.1     skrll 
    845      1.1     skrll 
    846      1.1     skrll /* This function performs the actual bitfiddling and sanity check for a
    847      1.1     skrll    final relocation.  Each relocation gets its *worst*-case expansion
    848      1.1     skrll    in size when it arrives here; any reduction in size should have been
    849      1.1     skrll    caught in linker relaxation earlier.  When we get here, the relocation
    850      1.1     skrll    looks like the smallest instruction with SWYM:s (nop:s) appended to the
    851      1.1     skrll    max size.  We fill in those nop:s.
    852      1.1     skrll 
    853      1.1     skrll    R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
    854      1.1     skrll     GETA $N,foo
    855      1.1     skrll    ->
    856      1.1     skrll     SETL $N,foo & 0xffff
    857      1.1     skrll     INCML $N,(foo >> 16) & 0xffff
    858      1.1     skrll     INCMH $N,(foo >> 32) & 0xffff
    859      1.1     skrll     INCH $N,(foo >> 48) & 0xffff
    860      1.1     skrll 
    861      1.1     skrll    R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
    862      1.1     skrll    condbranches needing relaxation might be rare enough to not be
    863      1.1     skrll    worthwhile.)
    864      1.1     skrll     [P]Bcc $N,foo
    865      1.1     skrll    ->
    866      1.1     skrll     [~P]B~cc $N,.+20
    867      1.1     skrll     SETL $255,foo & ...
    868      1.1     skrll     INCML ...
    869      1.1     skrll     INCMH ...
    870      1.1     skrll     INCH ...
    871      1.1     skrll     GO $255,$255,0
    872      1.1     skrll 
    873      1.1     skrll    R_MMIX_PUSHJ: (FIXME: Relaxation...)
    874      1.1     skrll     PUSHJ $N,foo
    875      1.1     skrll    ->
    876      1.1     skrll     SETL $255,foo & ...
    877      1.1     skrll     INCML ...
    878      1.1     skrll     INCMH ...
    879      1.1     skrll     INCH ...
    880      1.1     skrll     PUSHGO $N,$255,0
    881      1.1     skrll 
    882      1.1     skrll    R_MMIX_JMP: (FIXME: Relaxation...)
    883      1.1     skrll     JMP foo
    884      1.1     skrll    ->
    885      1.1     skrll     SETL $255,foo & ...
    886      1.1     skrll     INCML ...
    887      1.1     skrll     INCMH ...
    888      1.1     skrll     INCH ...
    889      1.1     skrll     GO $255,$255,0
    890      1.1     skrll 
    891      1.1     skrll    R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in.  */
    892      1.1     skrll 
    893      1.1     skrll static bfd_reloc_status_type
    894  1.1.1.3  christos mmix_elf_perform_relocation (asection *isec, reloc_howto_type *howto,
    895  1.1.1.3  christos 			     void *datap, bfd_vma addr, bfd_vma value,
    896  1.1.1.3  christos 			     char **error_message)
    897      1.1     skrll {
    898      1.1     skrll   bfd *abfd = isec->owner;
    899      1.1     skrll   bfd_reloc_status_type flag = bfd_reloc_ok;
    900      1.1     skrll   bfd_reloc_status_type r;
    901      1.1     skrll   int offs = 0;
    902      1.1     skrll   int reg = 255;
    903      1.1     skrll 
    904      1.1     skrll   /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
    905      1.1     skrll      We handle the differences here and the common sequence later.  */
    906      1.1     skrll   switch (howto->type)
    907      1.1     skrll     {
    908      1.1     skrll     case R_MMIX_GETA:
    909      1.1     skrll       offs = 0;
    910      1.1     skrll       reg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
    911      1.1     skrll 
    912      1.1     skrll       /* We change to an absolute value.  */
    913      1.1     skrll       value += addr;
    914      1.1     skrll       break;
    915      1.1     skrll 
    916      1.1     skrll     case R_MMIX_CBRANCH:
    917      1.1     skrll       {
    918      1.1     skrll 	int in1 = bfd_get_16 (abfd, (bfd_byte *) datap) << 16;
    919      1.1     skrll 
    920      1.1     skrll 	/* Invert the condition and prediction bit, and set the offset
    921      1.1     skrll 	   to five instructions ahead.
    922      1.1     skrll 
    923      1.1     skrll 	   We *can* do better if we want to.  If the branch is found to be
    924      1.1     skrll 	   within limits, we could leave the branch as is; there'll just
    925      1.1     skrll 	   be a bunch of NOP:s after it.  But we shouldn't see this
    926      1.1     skrll 	   sequence often enough that it's worth doing it.  */
    927      1.1     skrll 
    928      1.1     skrll 	bfd_put_32 (abfd,
    929      1.1     skrll 		    (((in1 ^ ((PRED_INV_BIT | COND_INV_BIT) << 24)) & ~0xffff)
    930      1.1     skrll 		     | (24/4)),
    931      1.1     skrll 		    (bfd_byte *) datap);
    932      1.1     skrll 
    933      1.1     skrll 	/* Put a "GO $255,$255,0" after the common sequence.  */
    934      1.1     skrll 	bfd_put_32 (abfd,
    935      1.1     skrll 		    ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | 0xffff00,
    936      1.1     skrll 		    (bfd_byte *) datap + 20);
    937      1.1     skrll 
    938      1.1     skrll 	/* Common sequence starts at offset 4.  */
    939      1.1     skrll 	offs = 4;
    940      1.1     skrll 
    941      1.1     skrll 	/* We change to an absolute value.  */
    942      1.1     skrll 	value += addr;
    943      1.1     skrll       }
    944      1.1     skrll       break;
    945      1.1     skrll 
    946      1.1     skrll     case R_MMIX_PUSHJ_STUBBABLE:
    947      1.1     skrll       /* If the address fits, we're fine.  */
    948      1.1     skrll       if ((value & 3) == 0
    949      1.1     skrll 	  /* Note rightshift 0; see R_MMIX_JMP case below.  */
    950      1.1     skrll 	  && (r = bfd_check_overflow (complain_overflow_signed,
    951      1.1     skrll 				      howto->bitsize,
    952      1.1     skrll 				      0,
    953      1.1     skrll 				      bfd_arch_bits_per_address (abfd),
    954      1.1     skrll 				      value)) == bfd_reloc_ok)
    955      1.1     skrll 	goto pcrel_mmix_reloc_fits;
    956      1.1     skrll       else
    957      1.1     skrll 	{
    958      1.1     skrll 	  bfd_size_type size = isec->rawsize ? isec->rawsize : isec->size;
    959      1.1     skrll 
    960      1.1     skrll 	  /* We have the bytes at the PUSHJ insn and need to get the
    961      1.1     skrll 	     position for the stub.  There's supposed to be room allocated
    962      1.1     skrll 	     for the stub.  */
    963      1.1     skrll 	  bfd_byte *stubcontents
    964      1.1     skrll 	    = ((bfd_byte *) datap
    965      1.1     skrll 	       - (addr - (isec->output_section->vma + isec->output_offset))
    966      1.1     skrll 	       + size
    967      1.1     skrll 	       + mmix_elf_section_data (isec)->pjs.stub_offset);
    968      1.1     skrll 	  bfd_vma stubaddr;
    969      1.1     skrll 
    970  1.1.1.3  christos 	  if (mmix_elf_section_data (isec)->pjs.n_pushj_relocs == 0)
    971  1.1.1.3  christos 	    {
    972  1.1.1.3  christos 	      /* This shouldn't happen when linking to ELF or mmo, so
    973  1.1.1.3  christos 		 this is an attempt to link to "binary", right?  We
    974  1.1.1.3  christos 		 can't access the output bfd, so we can't verify that
    975  1.1.1.3  christos 		 assumption.  We only know that the critical
    976  1.1.1.3  christos 		 mmix_elf_check_common_relocs has not been called,
    977  1.1.1.3  christos 		 which happens when the output format is different
    978  1.1.1.3  christos 		 from the input format (and is not mmo).  */
    979  1.1.1.3  christos 	      if (! mmix_elf_section_data (isec)->has_warned_pushj)
    980  1.1.1.3  christos 		{
    981  1.1.1.3  christos 		  /* For the first such error per input section, produce
    982  1.1.1.3  christos 		     a verbose message.  */
    983  1.1.1.3  christos 		  *error_message
    984  1.1.1.3  christos 		    = _("invalid input relocation when producing"
    985  1.1.1.3  christos 			" non-ELF, non-mmo format output."
    986  1.1.1.3  christos 			"\n Please use the objcopy program to convert from"
    987  1.1.1.3  christos 			" ELF or mmo,"
    988  1.1.1.3  christos 			"\n or assemble using"
    989  1.1.1.3  christos 			" \"-no-expand\" (for gcc, \"-Wa,-no-expand\"");
    990  1.1.1.3  christos 		  mmix_elf_section_data (isec)->has_warned_pushj = TRUE;
    991  1.1.1.3  christos 		  return bfd_reloc_dangerous;
    992  1.1.1.3  christos 		}
    993  1.1.1.3  christos 
    994  1.1.1.3  christos 	      /* For subsequent errors, return this one, which is
    995  1.1.1.3  christos 		 rate-limited but looks a little bit different,
    996  1.1.1.3  christos 		 hopefully without affecting user-friendliness.  */
    997  1.1.1.3  christos 	      return bfd_reloc_overflow;
    998  1.1.1.3  christos 	    }
    999  1.1.1.3  christos 
   1000      1.1     skrll 	  /* The address doesn't fit, so redirect the PUSHJ to the
   1001      1.1     skrll 	     location of the stub.  */
   1002      1.1     skrll 	  r = mmix_elf_perform_relocation (isec,
   1003      1.1     skrll 					   &elf_mmix_howto_table
   1004      1.1     skrll 					   [R_MMIX_ADDR19],
   1005      1.1     skrll 					   datap,
   1006      1.1     skrll 					   addr,
   1007      1.1     skrll 					   isec->output_section->vma
   1008      1.1     skrll 					   + isec->output_offset
   1009      1.1     skrll 					   + size
   1010      1.1     skrll 					   + (mmix_elf_section_data (isec)
   1011      1.1     skrll 					      ->pjs.stub_offset)
   1012  1.1.1.3  christos 					   - addr,
   1013  1.1.1.3  christos 					   error_message);
   1014      1.1     skrll 	  if (r != bfd_reloc_ok)
   1015      1.1     skrll 	    return r;
   1016      1.1     skrll 
   1017      1.1     skrll 	  stubaddr
   1018      1.1     skrll 	    = (isec->output_section->vma
   1019      1.1     skrll 	       + isec->output_offset
   1020      1.1     skrll 	       + size
   1021      1.1     skrll 	       + mmix_elf_section_data (isec)->pjs.stub_offset);
   1022      1.1     skrll 
   1023      1.1     skrll 	  /* We generate a simple JMP if that suffices, else the whole 5
   1024      1.1     skrll 	     insn stub.  */
   1025      1.1     skrll 	  if (bfd_check_overflow (complain_overflow_signed,
   1026      1.1     skrll 				  elf_mmix_howto_table[R_MMIX_ADDR27].bitsize,
   1027      1.1     skrll 				  0,
   1028      1.1     skrll 				  bfd_arch_bits_per_address (abfd),
   1029      1.1     skrll 				  addr + value - stubaddr) == bfd_reloc_ok)
   1030      1.1     skrll 	    {
   1031      1.1     skrll 	      bfd_put_32 (abfd, JMP_INSN_BYTE << 24, stubcontents);
   1032      1.1     skrll 	      r = mmix_elf_perform_relocation (isec,
   1033      1.1     skrll 					       &elf_mmix_howto_table
   1034      1.1     skrll 					       [R_MMIX_ADDR27],
   1035      1.1     skrll 					       stubcontents,
   1036      1.1     skrll 					       stubaddr,
   1037  1.1.1.3  christos 					       value + addr - stubaddr,
   1038  1.1.1.3  christos 					       error_message);
   1039      1.1     skrll 	      mmix_elf_section_data (isec)->pjs.stub_offset += 4;
   1040      1.1     skrll 
   1041      1.1     skrll 	      if (size + mmix_elf_section_data (isec)->pjs.stub_offset
   1042      1.1     skrll 		  > isec->size)
   1043      1.1     skrll 		abort ();
   1044      1.1     skrll 
   1045      1.1     skrll 	      return r;
   1046      1.1     skrll 	    }
   1047      1.1     skrll 	  else
   1048      1.1     skrll 	    {
   1049      1.1     skrll 	      /* Put a "GO $255,0" after the common sequence.  */
   1050      1.1     skrll 	      bfd_put_32 (abfd,
   1051      1.1     skrll 			  ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
   1052      1.1     skrll 			  | 0xff00, (bfd_byte *) stubcontents + 16);
   1053      1.1     skrll 
   1054      1.1     skrll 	      /* Prepare for the general code to set the first part of the
   1055      1.1     skrll 		 linker stub, and */
   1056      1.1     skrll 	      value += addr;
   1057      1.1     skrll 	      datap = stubcontents;
   1058      1.1     skrll 	      mmix_elf_section_data (isec)->pjs.stub_offset
   1059      1.1     skrll 		+= MAX_PUSHJ_STUB_SIZE;
   1060      1.1     skrll 	    }
   1061      1.1     skrll 	}
   1062      1.1     skrll       break;
   1063      1.1     skrll 
   1064      1.1     skrll     case R_MMIX_PUSHJ:
   1065      1.1     skrll       {
   1066      1.1     skrll 	int inreg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
   1067      1.1     skrll 
   1068      1.1     skrll 	/* Put a "PUSHGO $N,$255,0" after the common sequence.  */
   1069      1.1     skrll 	bfd_put_32 (abfd,
   1070      1.1     skrll 		    ((PUSHGO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
   1071      1.1     skrll 		    | (inreg << 16)
   1072      1.1     skrll 		    | 0xff00,
   1073      1.1     skrll 		    (bfd_byte *) datap + 16);
   1074      1.1     skrll 
   1075      1.1     skrll 	/* We change to an absolute value.  */
   1076      1.1     skrll 	value += addr;
   1077      1.1     skrll       }
   1078      1.1     skrll       break;
   1079      1.1     skrll 
   1080      1.1     skrll     case R_MMIX_JMP:
   1081      1.1     skrll       /* This one is a little special.  If we get here on a non-relaxing
   1082      1.1     skrll 	 link, and the destination is actually in range, we don't need to
   1083      1.1     skrll 	 execute the nops.
   1084      1.1     skrll 	 If so, we fall through to the bit-fiddling relocs.
   1085      1.1     skrll 
   1086      1.1     skrll 	 FIXME: bfd_check_overflow seems broken; the relocation is
   1087      1.1     skrll 	 rightshifted before testing, so supply a zero rightshift.  */
   1088      1.1     skrll 
   1089      1.1     skrll       if (! ((value & 3) == 0
   1090      1.1     skrll 	     && (r = bfd_check_overflow (complain_overflow_signed,
   1091      1.1     skrll 					 howto->bitsize,
   1092      1.1     skrll 					 0,
   1093      1.1     skrll 					 bfd_arch_bits_per_address (abfd),
   1094      1.1     skrll 					 value)) == bfd_reloc_ok))
   1095      1.1     skrll 	{
   1096      1.1     skrll 	  /* If the relocation doesn't fit in a JMP, we let the NOP:s be
   1097      1.1     skrll 	     modified below, and put a "GO $255,$255,0" after the
   1098      1.1     skrll 	     address-loading sequence.  */
   1099      1.1     skrll 	  bfd_put_32 (abfd,
   1100      1.1     skrll 		      ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
   1101      1.1     skrll 		      | 0xffff00,
   1102      1.1     skrll 		      (bfd_byte *) datap + 16);
   1103      1.1     skrll 
   1104      1.1     skrll 	  /* We change to an absolute value.  */
   1105      1.1     skrll 	  value += addr;
   1106      1.1     skrll 	  break;
   1107      1.1     skrll 	}
   1108      1.1     skrll       /* FALLTHROUGH.  */
   1109      1.1     skrll     case R_MMIX_ADDR19:
   1110      1.1     skrll     case R_MMIX_ADDR27:
   1111      1.1     skrll     pcrel_mmix_reloc_fits:
   1112      1.1     skrll       /* These must be in range, or else we emit an error.  */
   1113      1.1     skrll       if ((value & 3) == 0
   1114      1.1     skrll 	  /* Note rightshift 0; see above.  */
   1115      1.1     skrll 	  && (r = bfd_check_overflow (complain_overflow_signed,
   1116      1.1     skrll 				      howto->bitsize,
   1117      1.1     skrll 				      0,
   1118      1.1     skrll 				      bfd_arch_bits_per_address (abfd),
   1119      1.1     skrll 				      value)) == bfd_reloc_ok)
   1120      1.1     skrll 	{
   1121      1.1     skrll 	  bfd_vma in1
   1122      1.1     skrll 	    = bfd_get_32 (abfd, (bfd_byte *) datap);
   1123      1.1     skrll 	  bfd_vma highbit;
   1124      1.1     skrll 
   1125      1.1     skrll 	  if ((bfd_signed_vma) value < 0)
   1126      1.1     skrll 	    {
   1127      1.1     skrll 	      highbit = 1 << 24;
   1128      1.1     skrll 	      value += (1 << (howto->bitsize - 1));
   1129      1.1     skrll 	    }
   1130      1.1     skrll 	  else
   1131      1.1     skrll 	    highbit = 0;
   1132      1.1     skrll 
   1133      1.1     skrll 	  value >>= 2;
   1134      1.1     skrll 
   1135      1.1     skrll 	  bfd_put_32 (abfd,
   1136      1.1     skrll 		      (in1 & howto->src_mask)
   1137      1.1     skrll 		      | highbit
   1138      1.1     skrll 		      | (value & howto->dst_mask),
   1139      1.1     skrll 		      (bfd_byte *) datap);
   1140      1.1     skrll 
   1141      1.1     skrll 	  return bfd_reloc_ok;
   1142      1.1     skrll 	}
   1143      1.1     skrll       else
   1144      1.1     skrll 	return bfd_reloc_overflow;
   1145      1.1     skrll 
   1146      1.1     skrll     case R_MMIX_BASE_PLUS_OFFSET:
   1147      1.1     skrll       {
   1148      1.1     skrll 	struct bpo_reloc_section_info *bpodata
   1149      1.1     skrll 	  = mmix_elf_section_data (isec)->bpo.reloc;
   1150  1.1.1.3  christos 	asection *bpo_greg_section;
   1151  1.1.1.3  christos 	struct bpo_greg_section_info *gregdata;
   1152  1.1.1.3  christos 	size_t bpo_index;
   1153  1.1.1.3  christos 
   1154  1.1.1.3  christos 	if (bpodata == NULL)
   1155  1.1.1.3  christos 	  {
   1156  1.1.1.3  christos 	    /* This shouldn't happen when linking to ELF or mmo, so
   1157  1.1.1.3  christos 	       this is an attempt to link to "binary", right?  We
   1158  1.1.1.3  christos 	       can't access the output bfd, so we can't verify that
   1159  1.1.1.3  christos 	       assumption.  We only know that the critical
   1160  1.1.1.3  christos 	       mmix_elf_check_common_relocs has not been called, which
   1161  1.1.1.3  christos 	       happens when the output format is different from the
   1162  1.1.1.3  christos 	       input format (and is not mmo).  */
   1163  1.1.1.3  christos 	    if (! mmix_elf_section_data (isec)->has_warned_bpo)
   1164  1.1.1.3  christos 	      {
   1165  1.1.1.3  christos 		/* For the first such error per input section, produce
   1166  1.1.1.3  christos 		   a verbose message.  */
   1167  1.1.1.3  christos 		*error_message
   1168  1.1.1.3  christos 		  = _("invalid input relocation when producing"
   1169  1.1.1.3  christos 		      " non-ELF, non-mmo format output."
   1170  1.1.1.3  christos 		      "\n Please use the objcopy program to convert from"
   1171  1.1.1.3  christos 		      " ELF or mmo,"
   1172  1.1.1.3  christos 		      "\n or compile using the gcc-option"
   1173  1.1.1.3  christos 		      " \"-mno-base-addresses\".");
   1174  1.1.1.3  christos 		mmix_elf_section_data (isec)->has_warned_bpo = TRUE;
   1175  1.1.1.3  christos 		return bfd_reloc_dangerous;
   1176  1.1.1.3  christos 	      }
   1177  1.1.1.3  christos 
   1178  1.1.1.3  christos 	    /* For subsequent errors, return this one, which is
   1179  1.1.1.3  christos 	       rate-limited but looks a little bit different,
   1180  1.1.1.3  christos 	       hopefully without affecting user-friendliness.  */
   1181  1.1.1.3  christos 	    return bfd_reloc_overflow;
   1182  1.1.1.3  christos 	  }
   1183  1.1.1.3  christos 
   1184  1.1.1.3  christos 	bpo_greg_section = bpodata->bpo_greg_section;
   1185  1.1.1.3  christos 	gregdata = mmix_elf_section_data (bpo_greg_section)->bpo.greg;
   1186  1.1.1.3  christos 	bpo_index = gregdata->bpo_reloc_indexes[bpodata->bpo_index++];
   1187      1.1     skrll 
   1188      1.1     skrll 	/* A consistency check: The value we now have in "relocation" must
   1189      1.1     skrll 	   be the same as the value we stored for that relocation.  It
   1190      1.1     skrll 	   doesn't cost much, so can be left in at all times.  */
   1191      1.1     skrll 	if (value != gregdata->reloc_request[bpo_index].value)
   1192      1.1     skrll 	  {
   1193  1.1.1.6  christos 	    _bfd_error_handler
   1194  1.1.1.6  christos 	      /* xgettext:c-format */
   1195  1.1.1.6  christos 	      (_("%B: Internal inconsistency error for value for\n\
   1196  1.1.1.6  christos  linker-allocated global register: linked: %#Lx != relaxed: %#Lx"),
   1197  1.1.1.6  christos 	       isec->owner,
   1198  1.1.1.6  christos 	       value,
   1199  1.1.1.6  christos 	       gregdata->reloc_request[bpo_index].value);
   1200      1.1     skrll 	    bfd_set_error (bfd_error_bad_value);
   1201      1.1     skrll 	    return bfd_reloc_overflow;
   1202      1.1     skrll 	  }
   1203      1.1     skrll 
   1204      1.1     skrll 	/* Then store the register number and offset for that register
   1205      1.1     skrll 	   into datap and datap + 1 respectively.  */
   1206      1.1     skrll 	bfd_put_8 (abfd,
   1207      1.1     skrll 		   gregdata->reloc_request[bpo_index].regindex
   1208      1.1     skrll 		   + bpo_greg_section->output_section->vma / 8,
   1209      1.1     skrll 		   datap);
   1210      1.1     skrll 	bfd_put_8 (abfd,
   1211      1.1     skrll 		   gregdata->reloc_request[bpo_index].offset,
   1212      1.1     skrll 		   ((unsigned char *) datap) + 1);
   1213      1.1     skrll 	return bfd_reloc_ok;
   1214      1.1     skrll       }
   1215      1.1     skrll 
   1216      1.1     skrll     case R_MMIX_REG_OR_BYTE:
   1217      1.1     skrll     case R_MMIX_REG:
   1218      1.1     skrll       if (value > 255)
   1219      1.1     skrll 	return bfd_reloc_overflow;
   1220      1.1     skrll       bfd_put_8 (abfd, value, datap);
   1221      1.1     skrll       return bfd_reloc_ok;
   1222      1.1     skrll 
   1223      1.1     skrll     default:
   1224      1.1     skrll       BAD_CASE (howto->type);
   1225      1.1     skrll     }
   1226      1.1     skrll 
   1227      1.1     skrll   /* This code adds the common SETL/INCML/INCMH/INCH worst-case
   1228      1.1     skrll      sequence.  */
   1229      1.1     skrll 
   1230      1.1     skrll   /* Lowest two bits must be 0.  We return bfd_reloc_overflow for
   1231      1.1     skrll      everything that looks strange.  */
   1232      1.1     skrll   if (value & 3)
   1233      1.1     skrll     flag = bfd_reloc_overflow;
   1234      1.1     skrll 
   1235      1.1     skrll   bfd_put_32 (abfd,
   1236      1.1     skrll 	      (SETL_INSN_BYTE << 24) | (value & 0xffff) | (reg << 16),
   1237      1.1     skrll 	      (bfd_byte *) datap + offs);
   1238      1.1     skrll   bfd_put_32 (abfd,
   1239      1.1     skrll 	      (INCML_INSN_BYTE << 24) | ((value >> 16) & 0xffff) | (reg << 16),
   1240      1.1     skrll 	      (bfd_byte *) datap + offs + 4);
   1241      1.1     skrll   bfd_put_32 (abfd,
   1242      1.1     skrll 	      (INCMH_INSN_BYTE << 24) | ((value >> 32) & 0xffff) | (reg << 16),
   1243      1.1     skrll 	      (bfd_byte *) datap + offs + 8);
   1244      1.1     skrll   bfd_put_32 (abfd,
   1245      1.1     skrll 	      (INCH_INSN_BYTE << 24) | ((value >> 48) & 0xffff) | (reg << 16),
   1246      1.1     skrll 	      (bfd_byte *) datap + offs + 12);
   1247      1.1     skrll 
   1248      1.1     skrll   return flag;
   1249      1.1     skrll }
   1250      1.1     skrll 
   1251      1.1     skrll /* Set the howto pointer for an MMIX ELF reloc (type RELA).  */
   1252      1.1     skrll 
   1253      1.1     skrll static void
   1254  1.1.1.3  christos mmix_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   1255  1.1.1.3  christos 			 arelent *cache_ptr,
   1256  1.1.1.3  christos 			 Elf_Internal_Rela *dst)
   1257      1.1     skrll {
   1258      1.1     skrll   unsigned int r_type;
   1259      1.1     skrll 
   1260      1.1     skrll   r_type = ELF64_R_TYPE (dst->r_info);
   1261  1.1.1.4  christos   if (r_type >= (unsigned int) R_MMIX_max)
   1262  1.1.1.4  christos     {
   1263  1.1.1.6  christos       /* xgettext:c-format */
   1264  1.1.1.4  christos       _bfd_error_handler (_("%B: invalid MMIX reloc number: %d"), abfd, r_type);
   1265  1.1.1.4  christos       r_type = 0;
   1266  1.1.1.4  christos     }
   1267      1.1     skrll   cache_ptr->howto = &elf_mmix_howto_table[r_type];
   1268      1.1     skrll }
   1269      1.1     skrll 
   1270      1.1     skrll /* Any MMIX-specific relocation gets here at assembly time or when linking
   1271      1.1     skrll    to other formats (such as mmo); this is the relocation function from
   1272      1.1     skrll    the reloc_table.  We don't get here for final pure ELF linking.  */
   1273      1.1     skrll 
   1274      1.1     skrll static bfd_reloc_status_type
   1275  1.1.1.3  christos mmix_elf_reloc (bfd *abfd,
   1276  1.1.1.3  christos 		arelent *reloc_entry,
   1277  1.1.1.3  christos 		asymbol *symbol,
   1278  1.1.1.3  christos 		void * data,
   1279  1.1.1.3  christos 		asection *input_section,
   1280  1.1.1.3  christos 		bfd *output_bfd,
   1281  1.1.1.3  christos 		char **error_message)
   1282      1.1     skrll {
   1283      1.1     skrll   bfd_vma relocation;
   1284      1.1     skrll   bfd_reloc_status_type r;
   1285      1.1     skrll   asection *reloc_target_output_section;
   1286      1.1     skrll   bfd_reloc_status_type flag = bfd_reloc_ok;
   1287      1.1     skrll   bfd_vma output_base = 0;
   1288      1.1     skrll 
   1289      1.1     skrll   r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
   1290      1.1     skrll 			     input_section, output_bfd, error_message);
   1291      1.1     skrll 
   1292      1.1     skrll   /* If that was all that was needed (i.e. this isn't a final link, only
   1293      1.1     skrll      some segment adjustments), we're done.  */
   1294      1.1     skrll   if (r != bfd_reloc_continue)
   1295      1.1     skrll     return r;
   1296      1.1     skrll 
   1297      1.1     skrll   if (bfd_is_und_section (symbol->section)
   1298      1.1     skrll       && (symbol->flags & BSF_WEAK) == 0
   1299      1.1     skrll       && output_bfd == (bfd *) NULL)
   1300      1.1     skrll     return bfd_reloc_undefined;
   1301      1.1     skrll 
   1302      1.1     skrll   /* Is the address of the relocation really within the section?  */
   1303      1.1     skrll   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
   1304      1.1     skrll     return bfd_reloc_outofrange;
   1305      1.1     skrll 
   1306      1.1     skrll   /* Work out which section the relocation is targeted at and the
   1307      1.1     skrll      initial relocation command value.  */
   1308      1.1     skrll 
   1309      1.1     skrll   /* Get symbol value.  (Common symbols are special.)  */
   1310      1.1     skrll   if (bfd_is_com_section (symbol->section))
   1311      1.1     skrll     relocation = 0;
   1312      1.1     skrll   else
   1313      1.1     skrll     relocation = symbol->value;
   1314      1.1     skrll 
   1315      1.1     skrll   reloc_target_output_section = bfd_get_output_section (symbol);
   1316      1.1     skrll 
   1317      1.1     skrll   /* Here the variable relocation holds the final address of the symbol we
   1318      1.1     skrll      are relocating against, plus any addend.  */
   1319      1.1     skrll   if (output_bfd)
   1320      1.1     skrll     output_base = 0;
   1321      1.1     skrll   else
   1322      1.1     skrll     output_base = reloc_target_output_section->vma;
   1323      1.1     skrll 
   1324      1.1     skrll   relocation += output_base + symbol->section->output_offset;
   1325      1.1     skrll 
   1326      1.1     skrll   if (output_bfd != (bfd *) NULL)
   1327      1.1     skrll     {
   1328      1.1     skrll       /* Add in supplied addend.  */
   1329      1.1     skrll       relocation += reloc_entry->addend;
   1330      1.1     skrll 
   1331      1.1     skrll       /* This is a partial relocation, and we want to apply the
   1332      1.1     skrll 	 relocation to the reloc entry rather than the raw data.
   1333      1.1     skrll 	 Modify the reloc inplace to reflect what we now know.  */
   1334      1.1     skrll       reloc_entry->addend = relocation;
   1335      1.1     skrll       reloc_entry->address += input_section->output_offset;
   1336      1.1     skrll       return flag;
   1337      1.1     skrll     }
   1338      1.1     skrll 
   1339      1.1     skrll   return mmix_final_link_relocate (reloc_entry->howto, input_section,
   1340      1.1     skrll 				   data, reloc_entry->address,
   1341      1.1     skrll 				   reloc_entry->addend, relocation,
   1342      1.1     skrll 				   bfd_asymbol_name (symbol),
   1343  1.1.1.3  christos 				   reloc_target_output_section,
   1344  1.1.1.3  christos 				   error_message);
   1345      1.1     skrll }
   1346      1.1     skrll 
   1347      1.1     skrll /* Relocate an MMIX ELF section.  Modified from elf32-fr30.c; look to it
   1349      1.1     skrll    for guidance if you're thinking of copying this.  */
   1350      1.1     skrll 
   1351  1.1.1.3  christos static bfd_boolean
   1352  1.1.1.3  christos mmix_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
   1353  1.1.1.3  christos 			   struct bfd_link_info *info,
   1354  1.1.1.3  christos 			   bfd *input_bfd,
   1355  1.1.1.3  christos 			   asection *input_section,
   1356  1.1.1.3  christos 			   bfd_byte *contents,
   1357  1.1.1.3  christos 			   Elf_Internal_Rela *relocs,
   1358  1.1.1.3  christos 			   Elf_Internal_Sym *local_syms,
   1359      1.1     skrll 			   asection **local_sections)
   1360      1.1     skrll {
   1361      1.1     skrll   Elf_Internal_Shdr *symtab_hdr;
   1362      1.1     skrll   struct elf_link_hash_entry **sym_hashes;
   1363      1.1     skrll   Elf_Internal_Rela *rel;
   1364      1.1     skrll   Elf_Internal_Rela *relend;
   1365      1.1     skrll   bfd_size_type size;
   1366      1.1     skrll   size_t pjsno = 0;
   1367      1.1     skrll 
   1368      1.1     skrll   size = input_section->rawsize ? input_section->rawsize : input_section->size;
   1369      1.1     skrll   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   1370      1.1     skrll   sym_hashes = elf_sym_hashes (input_bfd);
   1371      1.1     skrll   relend = relocs + input_section->reloc_count;
   1372      1.1     skrll 
   1373      1.1     skrll   /* Zero the stub area before we start.  */
   1374      1.1     skrll   if (input_section->rawsize != 0
   1375      1.1     skrll       && input_section->size > input_section->rawsize)
   1376      1.1     skrll     memset (contents + input_section->rawsize, 0,
   1377      1.1     skrll 	    input_section->size - input_section->rawsize);
   1378      1.1     skrll 
   1379      1.1     skrll   for (rel = relocs; rel < relend; rel ++)
   1380      1.1     skrll     {
   1381      1.1     skrll       reloc_howto_type *howto;
   1382      1.1     skrll       unsigned long r_symndx;
   1383      1.1     skrll       Elf_Internal_Sym *sym;
   1384      1.1     skrll       asection *sec;
   1385      1.1     skrll       struct elf_link_hash_entry *h;
   1386      1.1     skrll       bfd_vma relocation;
   1387      1.1     skrll       bfd_reloc_status_type r;
   1388      1.1     skrll       const char *name = NULL;
   1389      1.1     skrll       int r_type;
   1390      1.1     skrll       bfd_boolean undefined_signalled = FALSE;
   1391      1.1     skrll 
   1392      1.1     skrll       r_type = ELF64_R_TYPE (rel->r_info);
   1393      1.1     skrll 
   1394      1.1     skrll       if (r_type == R_MMIX_GNU_VTINHERIT
   1395      1.1     skrll 	  || r_type == R_MMIX_GNU_VTENTRY)
   1396      1.1     skrll 	continue;
   1397      1.1     skrll 
   1398      1.1     skrll       r_symndx = ELF64_R_SYM (rel->r_info);
   1399      1.1     skrll 
   1400      1.1     skrll       howto = elf_mmix_howto_table + ELF64_R_TYPE (rel->r_info);
   1401      1.1     skrll       h = NULL;
   1402      1.1     skrll       sym = NULL;
   1403      1.1     skrll       sec = NULL;
   1404      1.1     skrll 
   1405      1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   1406      1.1     skrll 	{
   1407      1.1     skrll 	  sym = local_syms + r_symndx;
   1408      1.1     skrll 	  sec = local_sections [r_symndx];
   1409      1.1     skrll 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   1410      1.1     skrll 
   1411      1.1     skrll 	  name = bfd_elf_string_from_elf_section (input_bfd,
   1412      1.1     skrll 						  symtab_hdr->sh_link,
   1413      1.1     skrll 						  sym->st_name);
   1414      1.1     skrll 	  if (name == NULL)
   1415      1.1     skrll 	    name = bfd_section_name (input_bfd, sec);
   1416      1.1     skrll 	}
   1417      1.1     skrll       else
   1418  1.1.1.4  christos 	{
   1419      1.1     skrll 	  bfd_boolean unresolved_reloc, ignored;
   1420      1.1     skrll 
   1421      1.1     skrll 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   1422      1.1     skrll 				   r_symndx, symtab_hdr, sym_hashes,
   1423  1.1.1.4  christos 				   h, sec, relocation,
   1424  1.1.1.4  christos 				   unresolved_reloc, undefined_signalled,
   1425      1.1     skrll 				   ignored);
   1426      1.1     skrll 	  name = h->root.root.string;
   1427      1.1     skrll 	}
   1428  1.1.1.3  christos 
   1429  1.1.1.2  christos       if (sec != NULL && discarded_section (sec))
   1430  1.1.1.3  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   1431      1.1     skrll 					 rel, 1, relend, howto, 0, contents);
   1432  1.1.1.4  christos 
   1433      1.1     skrll       if (bfd_link_relocatable (info))
   1434      1.1     skrll 	{
   1435      1.1     skrll 	  /* This is a relocatable link.  For most relocs we don't have to
   1436      1.1     skrll 	     change anything, unless the reloc is against a section
   1437      1.1     skrll 	     symbol, in which case we have to adjust according to where
   1438      1.1     skrll 	     the section symbol winds up in the output section.  */
   1439      1.1     skrll 	  if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   1440      1.1     skrll 	    rel->r_addend += sec->output_offset;
   1441      1.1     skrll 
   1442      1.1     skrll 	  /* For PUSHJ stub relocs however, we may need to change the
   1443      1.1     skrll 	     reloc and the section contents, if the reloc doesn't reach
   1444      1.1     skrll 	     beyond the end of the output section and previous stubs.
   1445      1.1     skrll 	     Then we change the section contents to be a PUSHJ to the end
   1446      1.1     skrll 	     of the input section plus stubs (we can do that without using
   1447      1.1     skrll 	     a reloc), and then we change the reloc to be a R_MMIX_PUSHJ
   1448      1.1     skrll 	     at the stub location.  */
   1449      1.1     skrll 	  if (r_type == R_MMIX_PUSHJ_STUBBABLE)
   1450      1.1     skrll 	    {
   1451      1.1     skrll 	      /* We've already checked whether we need a stub; use that
   1452      1.1     skrll 		 knowledge.  */
   1453      1.1     skrll 	      if (mmix_elf_section_data (input_section)->pjs.stub_size[pjsno]
   1454      1.1     skrll 		  != 0)
   1455      1.1     skrll 		{
   1456      1.1     skrll 		  Elf_Internal_Rela relcpy;
   1457      1.1     skrll 
   1458      1.1     skrll 		  if (mmix_elf_section_data (input_section)
   1459      1.1     skrll 		      ->pjs.stub_size[pjsno] != MAX_PUSHJ_STUB_SIZE)
   1460      1.1     skrll 		    abort ();
   1461      1.1     skrll 
   1462      1.1     skrll 		  /* There's already a PUSHJ insn there, so just fill in
   1463      1.1     skrll 		     the offset bits to the stub.  */
   1464      1.1     skrll 		  if (mmix_final_link_relocate (elf_mmix_howto_table
   1465      1.1     skrll 						+ R_MMIX_ADDR19,
   1466      1.1     skrll 						input_section,
   1467      1.1     skrll 						contents,
   1468      1.1     skrll 						rel->r_offset,
   1469      1.1     skrll 						0,
   1470      1.1     skrll 						input_section
   1471      1.1     skrll 						->output_section->vma
   1472      1.1     skrll 						+ input_section->output_offset
   1473      1.1     skrll 						+ size
   1474      1.1     skrll 						+ mmix_elf_section_data (input_section)
   1475  1.1.1.3  christos 						->pjs.stub_offset,
   1476      1.1     skrll 						NULL, NULL, NULL) != bfd_reloc_ok)
   1477      1.1     skrll 		    return FALSE;
   1478      1.1     skrll 
   1479      1.1     skrll 		  /* Put a JMP insn at the stub; it goes with the
   1480      1.1     skrll 		     R_MMIX_JMP reloc.  */
   1481      1.1     skrll 		  bfd_put_32 (output_bfd, JMP_INSN_BYTE << 24,
   1482      1.1     skrll 			      contents
   1483      1.1     skrll 			      + size
   1484      1.1     skrll 			      + mmix_elf_section_data (input_section)
   1485      1.1     skrll 			      ->pjs.stub_offset);
   1486      1.1     skrll 
   1487      1.1     skrll 		  /* Change the reloc to be at the stub, and to a full
   1488      1.1     skrll 		     R_MMIX_JMP reloc.  */
   1489      1.1     skrll 		  rel->r_info = ELF64_R_INFO (r_symndx, R_MMIX_JMP);
   1490      1.1     skrll 		  rel->r_offset
   1491      1.1     skrll 		    = (size
   1492      1.1     skrll 		       + mmix_elf_section_data (input_section)
   1493      1.1     skrll 		       ->pjs.stub_offset);
   1494      1.1     skrll 
   1495      1.1     skrll 		  mmix_elf_section_data (input_section)->pjs.stub_offset
   1496      1.1     skrll 		    += MAX_PUSHJ_STUB_SIZE;
   1497      1.1     skrll 
   1498      1.1     skrll 		  /* Shift this reloc to the end of the relocs to maintain
   1499      1.1     skrll 		     the r_offset sorted reloc order.  */
   1500      1.1     skrll 		  relcpy = *rel;
   1501      1.1     skrll 		  memmove (rel, rel + 1, (char *) relend - (char *) rel);
   1502      1.1     skrll 		  relend[-1] = relcpy;
   1503      1.1     skrll 
   1504      1.1     skrll 		  /* Back up one reloc, or else we'd skip the next reloc
   1505      1.1     skrll 		   in turn.  */
   1506      1.1     skrll 		  rel--;
   1507      1.1     skrll 		}
   1508      1.1     skrll 
   1509      1.1     skrll 	      pjsno++;
   1510      1.1     skrll 	    }
   1511      1.1     skrll 	  continue;
   1512      1.1     skrll 	}
   1513      1.1     skrll 
   1514      1.1     skrll       r = mmix_final_link_relocate (howto, input_section,
   1515  1.1.1.3  christos 				    contents, rel->r_offset,
   1516      1.1     skrll 				    rel->r_addend, relocation, name, sec, NULL);
   1517      1.1     skrll 
   1518      1.1     skrll       if (r != bfd_reloc_ok)
   1519      1.1     skrll 	{
   1520      1.1     skrll 	  const char * msg = (const char *) NULL;
   1521      1.1     skrll 
   1522      1.1     skrll 	  switch (r)
   1523      1.1     skrll 	    {
   1524  1.1.1.5  christos 	    case bfd_reloc_overflow:
   1525      1.1     skrll 	      info->callbacks->reloc_overflow
   1526      1.1     skrll 		(info, (h ? &h->root : NULL), name, howto->name,
   1527      1.1     skrll 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   1528      1.1     skrll 	      break;
   1529      1.1     skrll 
   1530      1.1     skrll 	    case bfd_reloc_undefined:
   1531      1.1     skrll 	      /* We may have sent this message above.  */
   1532  1.1.1.5  christos 	      if (! undefined_signalled)
   1533  1.1.1.5  christos 		info->callbacks->undefined_symbol
   1534      1.1     skrll 		  (info, name, input_bfd, input_section, rel->r_offset, TRUE);
   1535      1.1     skrll 	      undefined_signalled = TRUE;
   1536      1.1     skrll 	      break;
   1537      1.1     skrll 
   1538      1.1     skrll 	    case bfd_reloc_outofrange:
   1539      1.1     skrll 	      msg = _("internal error: out of range error");
   1540      1.1     skrll 	      break;
   1541      1.1     skrll 
   1542      1.1     skrll 	    case bfd_reloc_notsupported:
   1543      1.1     skrll 	      msg = _("internal error: unsupported relocation error");
   1544      1.1     skrll 	      break;
   1545      1.1     skrll 
   1546      1.1     skrll 	    case bfd_reloc_dangerous:
   1547      1.1     skrll 	      msg = _("internal error: dangerous relocation");
   1548      1.1     skrll 	      break;
   1549      1.1     skrll 
   1550      1.1     skrll 	    default:
   1551      1.1     skrll 	      msg = _("internal error: unknown error");
   1552      1.1     skrll 	      break;
   1553      1.1     skrll 	    }
   1554      1.1     skrll 
   1555  1.1.1.5  christos 	  if (msg)
   1556  1.1.1.5  christos 	    (*info->callbacks->warning) (info, msg, name, input_bfd,
   1557      1.1     skrll 					 input_section, rel->r_offset);
   1558      1.1     skrll 	}
   1559      1.1     skrll     }
   1560      1.1     skrll 
   1561      1.1     skrll   return TRUE;
   1562      1.1     skrll }
   1563      1.1     skrll 
   1564      1.1     skrll /* Perform a single relocation.  By default we use the standard BFD
   1566      1.1     skrll    routines.  A few relocs we have to do ourselves.  */
   1567  1.1.1.3  christos 
   1568  1.1.1.3  christos static bfd_reloc_status_type
   1569  1.1.1.3  christos mmix_final_link_relocate (reloc_howto_type *howto, asection *input_section,
   1570  1.1.1.3  christos 			  bfd_byte *contents, bfd_vma r_offset,
   1571  1.1.1.3  christos 			  bfd_signed_vma r_addend, bfd_vma relocation,
   1572      1.1     skrll 			  const char *symname, asection *symsec,
   1573      1.1     skrll 			  char **error_message)
   1574      1.1     skrll {
   1575      1.1     skrll   bfd_reloc_status_type r = bfd_reloc_ok;
   1576      1.1     skrll   bfd_vma addr
   1577      1.1     skrll     = (input_section->output_section->vma
   1578      1.1     skrll        + input_section->output_offset
   1579      1.1     skrll        + r_offset);
   1580      1.1     skrll   bfd_signed_vma srel
   1581      1.1     skrll     = (bfd_signed_vma) relocation + r_addend;
   1582      1.1     skrll 
   1583      1.1     skrll   switch (howto->type)
   1584      1.1     skrll     {
   1585      1.1     skrll       /* All these are PC-relative.  */
   1586      1.1     skrll     case R_MMIX_PUSHJ_STUBBABLE:
   1587      1.1     skrll     case R_MMIX_PUSHJ:
   1588      1.1     skrll     case R_MMIX_CBRANCH:
   1589      1.1     skrll     case R_MMIX_ADDR19:
   1590      1.1     skrll     case R_MMIX_GETA:
   1591      1.1     skrll     case R_MMIX_ADDR27:
   1592      1.1     skrll     case R_MMIX_JMP:
   1593      1.1     skrll       contents += r_offset;
   1594      1.1     skrll 
   1595      1.1     skrll       srel -= (input_section->output_section->vma
   1596      1.1     skrll 	       + input_section->output_offset
   1597      1.1     skrll 	       + r_offset);
   1598  1.1.1.3  christos 
   1599      1.1     skrll       r = mmix_elf_perform_relocation (input_section, howto, contents,
   1600      1.1     skrll 				       addr, srel, error_message);
   1601      1.1     skrll       break;
   1602      1.1     skrll 
   1603      1.1     skrll     case R_MMIX_BASE_PLUS_OFFSET:
   1604      1.1     skrll       if (symsec == NULL)
   1605      1.1     skrll 	return bfd_reloc_undefined;
   1606      1.1     skrll 
   1607      1.1     skrll       /* Check that we're not relocating against a register symbol.  */
   1608      1.1     skrll       if (strcmp (bfd_get_section_name (symsec->owner, symsec),
   1609      1.1     skrll 		  MMIX_REG_CONTENTS_SECTION_NAME) == 0
   1610      1.1     skrll 	  || strcmp (bfd_get_section_name (symsec->owner, symsec),
   1611      1.1     skrll 		     MMIX_REG_SECTION_NAME) == 0)
   1612      1.1     skrll 	{
   1613      1.1     skrll 	  /* Note: This is separated out into two messages in order
   1614  1.1.1.6  christos 	     to ease the translation into other languages.  */
   1615  1.1.1.6  christos 	  if (symname == NULL || *symname == 0)
   1616  1.1.1.6  christos 	    _bfd_error_handler
   1617  1.1.1.6  christos 	      /* xgettext:c-format */
   1618  1.1.1.6  christos 	      (_("%B: base-plus-offset relocation against register symbol:"
   1619      1.1     skrll 		 " (unknown) in %A"),
   1620  1.1.1.6  christos 	       input_section->owner, symsec);
   1621  1.1.1.6  christos 	  else
   1622  1.1.1.6  christos 	    _bfd_error_handler
   1623  1.1.1.6  christos 	      /* xgettext:c-format */
   1624  1.1.1.6  christos 	      (_("%B: base-plus-offset relocation against register symbol:"
   1625      1.1     skrll 		 " %s in %A"),
   1626      1.1     skrll 	       input_section->owner, symname, symsec);
   1627      1.1     skrll 	  return bfd_reloc_overflow;
   1628      1.1     skrll 	}
   1629      1.1     skrll       goto do_mmix_reloc;
   1630      1.1     skrll 
   1631      1.1     skrll     case R_MMIX_REG_OR_BYTE:
   1632      1.1     skrll     case R_MMIX_REG:
   1633      1.1     skrll       /* For now, we handle these alike.  They must refer to an register
   1634      1.1     skrll 	 symbol, which is either relative to the register section and in
   1635      1.1     skrll 	 the range 0..255, or is in the register contents section with vma
   1636      1.1     skrll 	 regno * 8.  */
   1637      1.1     skrll 
   1638      1.1     skrll       /* FIXME: A better way to check for reg contents section?
   1639      1.1     skrll 	 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
   1640      1.1     skrll       if (symsec == NULL)
   1641      1.1     skrll 	return bfd_reloc_undefined;
   1642      1.1     skrll 
   1643      1.1     skrll       if (strcmp (bfd_get_section_name (symsec->owner, symsec),
   1644      1.1     skrll 		  MMIX_REG_CONTENTS_SECTION_NAME) == 0)
   1645      1.1     skrll 	{
   1646      1.1     skrll 	  if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
   1647      1.1     skrll 	    {
   1648      1.1     skrll 	      /* The bfd_reloc_outofrange return value, though intuitively
   1649      1.1     skrll 		 a better value, will not get us an error.  */
   1650      1.1     skrll 	      return bfd_reloc_overflow;
   1651      1.1     skrll 	    }
   1652      1.1     skrll 	  srel /= 8;
   1653      1.1     skrll 	}
   1654      1.1     skrll       else if (strcmp (bfd_get_section_name (symsec->owner, symsec),
   1655      1.1     skrll 		       MMIX_REG_SECTION_NAME) == 0)
   1656      1.1     skrll 	{
   1657      1.1     skrll 	  if (srel < 0 || srel > 255)
   1658      1.1     skrll 	    /* The bfd_reloc_outofrange return value, though intuitively a
   1659      1.1     skrll 	       better value, will not get us an error.  */
   1660      1.1     skrll 	    return bfd_reloc_overflow;
   1661      1.1     skrll 	}
   1662      1.1     skrll       else
   1663      1.1     skrll 	{
   1664      1.1     skrll 	  /* Note: This is separated out into two messages in order
   1665  1.1.1.6  christos 	     to ease the translation into other languages.  */
   1666  1.1.1.6  christos 	  if (symname == NULL || *symname == 0)
   1667  1.1.1.6  christos 	    _bfd_error_handler
   1668  1.1.1.6  christos 	      /* xgettext:c-format */
   1669  1.1.1.6  christos 	      (_("%B: register relocation against non-register symbol:"
   1670      1.1     skrll 		 " (unknown) in %A"),
   1671  1.1.1.6  christos 	       input_section->owner, symsec);
   1672  1.1.1.6  christos 	  else
   1673  1.1.1.6  christos 	    _bfd_error_handler
   1674  1.1.1.6  christos 	      /* xgettext:c-format */
   1675  1.1.1.6  christos 	      (_("%B: register relocation against non-register symbol:"
   1676      1.1     skrll 		 " %s in %A"),
   1677      1.1     skrll 	       input_section->owner, symname, symsec);
   1678      1.1     skrll 
   1679      1.1     skrll 	  /* The bfd_reloc_outofrange return value, though intuitively a
   1680      1.1     skrll 	     better value, will not get us an error.  */
   1681      1.1     skrll 	  return bfd_reloc_overflow;
   1682      1.1     skrll 	}
   1683      1.1     skrll     do_mmix_reloc:
   1684  1.1.1.3  christos       contents += r_offset;
   1685      1.1     skrll       r = mmix_elf_perform_relocation (input_section, howto, contents,
   1686      1.1     skrll 				       addr, srel, error_message);
   1687      1.1     skrll       break;
   1688      1.1     skrll 
   1689      1.1     skrll     case R_MMIX_LOCAL:
   1690      1.1     skrll       /* This isn't a real relocation, it's just an assertion that the
   1691      1.1     skrll 	 final relocation value corresponds to a local register.  We
   1692      1.1     skrll 	 ignore the actual relocation; nothing is changed.  */
   1693      1.1     skrll       {
   1694      1.1     skrll 	asection *regsec
   1695      1.1     skrll 	  = bfd_get_section_by_name (input_section->output_section->owner,
   1696      1.1     skrll 				     MMIX_REG_CONTENTS_SECTION_NAME);
   1697      1.1     skrll 	bfd_vma first_global;
   1698      1.1     skrll 
   1699      1.1     skrll 	/* Check that this is an absolute value, or a reference to the
   1700      1.1     skrll 	   register contents section or the register (symbol) section.
   1701      1.1     skrll 	   Absolute numbers can get here as undefined section.  Undefined
   1702      1.1     skrll 	   symbols are signalled elsewhere, so there's no conflict in us
   1703      1.1     skrll 	   accidentally handling it.  */
   1704      1.1     skrll 	if (!bfd_is_abs_section (symsec)
   1705      1.1     skrll 	    && !bfd_is_und_section (symsec)
   1706      1.1     skrll 	    && strcmp (bfd_get_section_name (symsec->owner, symsec),
   1707      1.1     skrll 		       MMIX_REG_CONTENTS_SECTION_NAME) != 0
   1708      1.1     skrll 	    && strcmp (bfd_get_section_name (symsec->owner, symsec),
   1709  1.1.1.6  christos 		       MMIX_REG_SECTION_NAME) != 0)
   1710  1.1.1.6  christos 	{
   1711  1.1.1.6  christos 	  _bfd_error_handler
   1712      1.1     skrll 	    (_("%B: directive LOCAL valid only with a register or absolute value"),
   1713      1.1     skrll 	     input_section->owner);
   1714      1.1     skrll 
   1715      1.1     skrll 	  return bfd_reloc_overflow;
   1716      1.1     skrll 	}
   1717      1.1     skrll 
   1718      1.1     skrll       /* If we don't have a register contents section, then $255 is the
   1719      1.1     skrll 	 first global register.  */
   1720      1.1     skrll       if (regsec == NULL)
   1721      1.1     skrll 	first_global = 255;
   1722  1.1.1.3  christos       else
   1723  1.1.1.3  christos 	{
   1724  1.1.1.3  christos 	  first_global
   1725      1.1     skrll 	    = bfd_get_section_vma (input_section->output_section->owner,
   1726      1.1     skrll 				   regsec) / 8;
   1727      1.1     skrll 	  if (strcmp (bfd_get_section_name (symsec->owner, symsec),
   1728      1.1     skrll 		      MMIX_REG_CONTENTS_SECTION_NAME) == 0)
   1729      1.1     skrll 	    {
   1730      1.1     skrll 	      if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
   1731      1.1     skrll 		/* The bfd_reloc_outofrange return value, though
   1732      1.1     skrll 		   intuitively a better value, will not get us an error.  */
   1733      1.1     skrll 		return bfd_reloc_overflow;
   1734      1.1     skrll 	      srel /= 8;
   1735      1.1     skrll 	    }
   1736      1.1     skrll 	}
   1737      1.1     skrll 
   1738      1.1     skrll 	if ((bfd_vma) srel >= first_global)
   1739  1.1.1.6  christos 	  {
   1740  1.1.1.6  christos 	    /* FIXME: Better error message.  */
   1741  1.1.1.6  christos 	    _bfd_error_handler
   1742  1.1.1.6  christos 	      /* xgettext:c-format */
   1743  1.1.1.6  christos 	      (_("%B: LOCAL directive: Register $%Ld is not a local register."
   1744      1.1     skrll 		 "  First global register is $%Ld."),
   1745      1.1     skrll 	       input_section->owner, srel, first_global);
   1746      1.1     skrll 
   1747      1.1     skrll 	    return bfd_reloc_overflow;
   1748      1.1     skrll 	  }
   1749      1.1     skrll       }
   1750      1.1     skrll       r = bfd_reloc_ok;
   1751      1.1     skrll       break;
   1752      1.1     skrll 
   1753      1.1     skrll     default:
   1754      1.1     skrll       r = _bfd_final_link_relocate (howto, input_section->owner, input_section,
   1755      1.1     skrll 				    contents, r_offset,
   1756      1.1     skrll 				    relocation, r_addend);
   1757      1.1     skrll     }
   1758      1.1     skrll 
   1759      1.1     skrll   return r;
   1760      1.1     skrll }
   1761      1.1     skrll 
   1762      1.1     skrll /* Return the section that should be marked against GC for a given
   1764      1.1     skrll    relocation.  */
   1765      1.1     skrll 
   1766      1.1     skrll static asection *
   1767      1.1     skrll mmix_elf_gc_mark_hook (asection *sec,
   1768      1.1     skrll 		       struct bfd_link_info *info,
   1769      1.1     skrll 		       Elf_Internal_Rela *rel,
   1770      1.1     skrll 		       struct elf_link_hash_entry *h,
   1771      1.1     skrll 		       Elf_Internal_Sym *sym)
   1772      1.1     skrll {
   1773      1.1     skrll   if (h != NULL)
   1774      1.1     skrll     switch (ELF64_R_TYPE (rel->r_info))
   1775      1.1     skrll       {
   1776      1.1     skrll       case R_MMIX_GNU_VTINHERIT:
   1777      1.1     skrll       case R_MMIX_GNU_VTENTRY:
   1778      1.1     skrll 	return NULL;
   1779      1.1     skrll       }
   1780      1.1     skrll 
   1781      1.1     skrll   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   1782      1.1     skrll }
   1783      1.1     skrll 
   1784  1.1.1.3  christos /* Sort register relocs to come before expanding relocs.  */
   1786      1.1     skrll 
   1787      1.1     skrll static int
   1788      1.1     skrll mmix_elf_sort_relocs (const void * p1, const void * p2)
   1789      1.1     skrll {
   1790      1.1     skrll   const Elf_Internal_Rela *r1 = (const Elf_Internal_Rela *) p1;
   1791      1.1     skrll   const Elf_Internal_Rela *r2 = (const Elf_Internal_Rela *) p2;
   1792      1.1     skrll   int r1_is_reg, r2_is_reg;
   1793      1.1     skrll 
   1794      1.1     skrll   /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
   1795      1.1     skrll      insns.  */
   1796      1.1     skrll   if ((r1->r_offset & ~(bfd_vma) 3) > (r2->r_offset & ~(bfd_vma) 3))
   1797      1.1     skrll     return 1;
   1798      1.1     skrll   else if ((r1->r_offset & ~(bfd_vma) 3) < (r2->r_offset & ~(bfd_vma) 3))
   1799      1.1     skrll     return -1;
   1800      1.1     skrll 
   1801      1.1     skrll   r1_is_reg
   1802      1.1     skrll     = (ELF64_R_TYPE (r1->r_info) == R_MMIX_REG_OR_BYTE
   1803      1.1     skrll        || ELF64_R_TYPE (r1->r_info) == R_MMIX_REG);
   1804      1.1     skrll   r2_is_reg
   1805      1.1     skrll     = (ELF64_R_TYPE (r2->r_info) == R_MMIX_REG_OR_BYTE
   1806      1.1     skrll        || ELF64_R_TYPE (r2->r_info) == R_MMIX_REG);
   1807      1.1     skrll   if (r1_is_reg != r2_is_reg)
   1808      1.1     skrll     return r2_is_reg - r1_is_reg;
   1809      1.1     skrll 
   1810      1.1     skrll   /* Neither or both are register relocs.  Then sort on full offset.  */
   1811      1.1     skrll   if (r1->r_offset > r2->r_offset)
   1812      1.1     skrll     return 1;
   1813      1.1     skrll   else if (r1->r_offset < r2->r_offset)
   1814      1.1     skrll     return -1;
   1815      1.1     skrll   return 0;
   1816      1.1     skrll }
   1817  1.1.1.3  christos 
   1818  1.1.1.3  christos /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking.  */
   1819  1.1.1.3  christos 
   1820  1.1.1.3  christos static bfd_boolean
   1821      1.1     skrll mmix_elf_check_common_relocs  (bfd *abfd,
   1822      1.1     skrll 			       struct bfd_link_info *info,
   1823      1.1     skrll 			       asection *sec,
   1824      1.1     skrll 			       const Elf_Internal_Rela *relocs)
   1825      1.1     skrll {
   1826      1.1     skrll   bfd *bpo_greg_owner = NULL;
   1827      1.1     skrll   asection *allocated_gregs_section = NULL;
   1828      1.1     skrll   struct bpo_greg_section_info *gregdata = NULL;
   1829      1.1     skrll   struct bpo_reloc_section_info *bpodata = NULL;
   1830      1.1     skrll   const Elf_Internal_Rela *rel;
   1831      1.1     skrll   const Elf_Internal_Rela *rel_end;
   1832      1.1     skrll 
   1833      1.1     skrll   /* We currently have to abuse this COFF-specific member, since there's
   1834      1.1     skrll      no target-machine-dedicated member.  There's no alternative outside
   1835      1.1     skrll      the bfd_link_info struct; we can't specialize a hash-table since
   1836      1.1     skrll      they're different between ELF and mmo.  */
   1837      1.1     skrll   bpo_greg_owner = (bfd *) info->base_file;
   1838      1.1     skrll 
   1839  1.1.1.6  christos   rel_end = relocs + sec->reloc_count;
   1840      1.1     skrll   for (rel = relocs; rel < rel_end; rel++)
   1841      1.1     skrll     {
   1842      1.1     skrll       switch (ELF64_R_TYPE (rel->r_info))
   1843      1.1     skrll 	{
   1844      1.1     skrll 	  /* This relocation causes a GREG allocation.  We need to count
   1845      1.1     skrll 	     them, and we need to create a section for them, so we need an
   1846      1.1     skrll 	     object to fake as the owner of that section.  We can't use
   1847  1.1.1.4  christos 	     the ELF dynobj for this, since the ELF bits assume lots of
   1848      1.1     skrll 	     DSO-related stuff if that member is non-NULL.  */
   1849      1.1     skrll 	case R_MMIX_BASE_PLUS_OFFSET:
   1850      1.1     skrll 	  /* We don't do anything with this reloc for a relocatable link.  */
   1851      1.1     skrll 	  if (bfd_link_relocatable (info))
   1852      1.1     skrll 	    break;
   1853  1.1.1.3  christos 
   1854      1.1     skrll 	  if (bpo_greg_owner == NULL)
   1855      1.1     skrll 	    {
   1856      1.1     skrll 	      bpo_greg_owner = abfd;
   1857      1.1     skrll 	      info->base_file = bpo_greg_owner;
   1858      1.1     skrll 	    }
   1859      1.1     skrll 
   1860      1.1     skrll 	  if (allocated_gregs_section == NULL)
   1861      1.1     skrll 	    allocated_gregs_section
   1862      1.1     skrll 	      = bfd_get_section_by_name (bpo_greg_owner,
   1863      1.1     skrll 					 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
   1864      1.1     skrll 
   1865      1.1     skrll 	  if (allocated_gregs_section == NULL)
   1866      1.1     skrll 	    {
   1867      1.1     skrll 	      allocated_gregs_section
   1868      1.1     skrll 		= bfd_make_section_with_flags (bpo_greg_owner,
   1869      1.1     skrll 					       MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME,
   1870      1.1     skrll 					       (SEC_HAS_CONTENTS
   1871      1.1     skrll 						| SEC_IN_MEMORY
   1872      1.1     skrll 						| SEC_LINKER_CREATED));
   1873      1.1     skrll 	      /* Setting both SEC_ALLOC and SEC_LOAD means the section is
   1874      1.1     skrll 		 treated like any other section, and we'd get errors for
   1875      1.1     skrll 		 address overlap with the text section.  Let's set none of
   1876      1.1     skrll 		 those flags, as that is what currently happens for usual
   1877      1.1     skrll 		 GREG allocations, and that works.  */
   1878      1.1     skrll 	      if (allocated_gregs_section == NULL
   1879      1.1     skrll 		  || !bfd_set_section_alignment (bpo_greg_owner,
   1880      1.1     skrll 						 allocated_gregs_section,
   1881      1.1     skrll 						 3))
   1882      1.1     skrll 		return FALSE;
   1883      1.1     skrll 
   1884      1.1     skrll 	      gregdata = (struct bpo_greg_section_info *)
   1885      1.1     skrll 		bfd_zalloc (bpo_greg_owner, sizeof (struct bpo_greg_section_info));
   1886      1.1     skrll 	      if (gregdata == NULL)
   1887      1.1     skrll 		return FALSE;
   1888      1.1     skrll 	      mmix_elf_section_data (allocated_gregs_section)->bpo.greg
   1889      1.1     skrll 		= gregdata;
   1890      1.1     skrll 	    }
   1891      1.1     skrll 	  else if (gregdata == NULL)
   1892      1.1     skrll 	    gregdata
   1893      1.1     skrll 	      = mmix_elf_section_data (allocated_gregs_section)->bpo.greg;
   1894      1.1     skrll 
   1895      1.1     skrll 	  /* Get ourselves some auxiliary info for the BPO-relocs.  */
   1896      1.1     skrll 	  if (bpodata == NULL)
   1897      1.1     skrll 	    {
   1898      1.1     skrll 	      /* No use doing a separate iteration pass to find the upper
   1899      1.1     skrll 		 limit - just use the number of relocs.  */
   1900      1.1     skrll 	      bpodata = (struct bpo_reloc_section_info *)
   1901      1.1     skrll 		bfd_alloc (bpo_greg_owner,
   1902      1.1     skrll 			   sizeof (struct bpo_reloc_section_info)
   1903      1.1     skrll 			   * (sec->reloc_count + 1));
   1904      1.1     skrll 	      if (bpodata == NULL)
   1905      1.1     skrll 		return FALSE;
   1906      1.1     skrll 	      mmix_elf_section_data (sec)->bpo.reloc = bpodata;
   1907      1.1     skrll 	      bpodata->first_base_plus_offset_reloc
   1908      1.1     skrll 		= bpodata->bpo_index
   1909      1.1     skrll 		= gregdata->n_max_bpo_relocs;
   1910      1.1     skrll 	      bpodata->bpo_greg_section
   1911      1.1     skrll 		= allocated_gregs_section;
   1912      1.1     skrll 	      bpodata->n_bpo_relocs_this_section = 0;
   1913      1.1     skrll 	    }
   1914      1.1     skrll 
   1915      1.1     skrll 	  bpodata->n_bpo_relocs_this_section++;
   1916      1.1     skrll 	  gregdata->n_max_bpo_relocs++;
   1917      1.1     skrll 
   1918      1.1     skrll 	  /* We don't get another chance to set this before GC; we've not
   1919      1.1     skrll 	     set up any hook that runs before GC.  */
   1920      1.1     skrll 	  gregdata->n_bpo_relocs
   1921      1.1     skrll 	    = gregdata->n_max_bpo_relocs;
   1922      1.1     skrll 	  break;
   1923      1.1     skrll 
   1924      1.1     skrll 	case R_MMIX_PUSHJ_STUBBABLE:
   1925      1.1     skrll 	  mmix_elf_section_data (sec)->pjs.n_pushj_relocs++;
   1926      1.1     skrll 	  break;
   1927      1.1     skrll 	}
   1928      1.1     skrll     }
   1929      1.1     skrll 
   1930      1.1     skrll   /* Allocate per-reloc stub storage and initialize it to the max stub
   1931      1.1     skrll      size.  */
   1932      1.1     skrll   if (mmix_elf_section_data (sec)->pjs.n_pushj_relocs != 0)
   1933      1.1     skrll     {
   1934      1.1     skrll       size_t i;
   1935      1.1     skrll 
   1936      1.1     skrll       mmix_elf_section_data (sec)->pjs.stub_size
   1937      1.1     skrll 	= bfd_alloc (abfd, mmix_elf_section_data (sec)->pjs.n_pushj_relocs
   1938      1.1     skrll 		     * sizeof (mmix_elf_section_data (sec)
   1939      1.1     skrll 			       ->pjs.stub_size[0]));
   1940      1.1     skrll       if (mmix_elf_section_data (sec)->pjs.stub_size == NULL)
   1941      1.1     skrll 	return FALSE;
   1942      1.1     skrll 
   1943      1.1     skrll       for (i = 0; i < mmix_elf_section_data (sec)->pjs.n_pushj_relocs; i++)
   1944      1.1     skrll 	mmix_elf_section_data (sec)->pjs.stub_size[i] = MAX_PUSHJ_STUB_SIZE;
   1945      1.1     skrll     }
   1946      1.1     skrll 
   1947      1.1     skrll   return TRUE;
   1948      1.1     skrll }
   1949  1.1.1.3  christos 
   1950  1.1.1.3  christos /* Look through the relocs for a section during the first phase.  */
   1951  1.1.1.3  christos 
   1952  1.1.1.3  christos static bfd_boolean
   1953      1.1     skrll mmix_elf_check_relocs (bfd *abfd,
   1954      1.1     skrll 		       struct bfd_link_info *info,
   1955      1.1     skrll 		       asection *sec,
   1956      1.1     skrll 		       const Elf_Internal_Rela *relocs)
   1957      1.1     skrll {
   1958      1.1     skrll   Elf_Internal_Shdr *symtab_hdr;
   1959      1.1     skrll   struct elf_link_hash_entry **sym_hashes;
   1960      1.1     skrll   const Elf_Internal_Rela *rel;
   1961      1.1     skrll   const Elf_Internal_Rela *rel_end;
   1962      1.1     skrll 
   1963      1.1     skrll   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   1964  1.1.1.3  christos   sym_hashes = elf_sym_hashes (abfd);
   1965      1.1     skrll 
   1966      1.1     skrll   /* First we sort the relocs so that any register relocs come before
   1967      1.1     skrll      expansion-relocs to the same insn.  FIXME: Not done for mmo.  */
   1968      1.1     skrll   qsort ((void *) relocs, sec->reloc_count, sizeof (Elf_Internal_Rela),
   1969      1.1     skrll 	 mmix_elf_sort_relocs);
   1970      1.1     skrll 
   1971  1.1.1.4  christos   /* Do the common part.  */
   1972      1.1     skrll   if (!mmix_elf_check_common_relocs (abfd, info, sec, relocs))
   1973      1.1     skrll     return FALSE;
   1974      1.1     skrll 
   1975      1.1     skrll   if (bfd_link_relocatable (info))
   1976      1.1     skrll     return TRUE;
   1977      1.1     skrll 
   1978      1.1     skrll   rel_end = relocs + sec->reloc_count;
   1979      1.1     skrll   for (rel = relocs; rel < rel_end; rel++)
   1980      1.1     skrll     {
   1981      1.1     skrll       struct elf_link_hash_entry *h;
   1982  1.1.1.6  christos       unsigned long r_symndx;
   1983      1.1     skrll 
   1984      1.1     skrll       r_symndx = ELF64_R_SYM (rel->r_info);
   1985      1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   1986      1.1     skrll 	h = NULL;
   1987      1.1     skrll       else
   1988      1.1     skrll 	{
   1989      1.1     skrll 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1990      1.1     skrll 	  while (h->root.type == bfd_link_hash_indirect
   1991      1.1     skrll 		 || h->root.type == bfd_link_hash_warning)
   1992      1.1     skrll 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1993  1.1.1.6  christos 	}
   1994  1.1.1.6  christos 
   1995  1.1.1.6  christos       switch (ELF64_R_TYPE (rel->r_info))
   1996  1.1.1.6  christos 	{
   1997  1.1.1.6  christos 	/* This relocation describes the C++ object vtable hierarchy.
   1998  1.1.1.6  christos 	   Reconstruct it for later use during GC.  */
   1999  1.1.1.6  christos 	case R_MMIX_GNU_VTINHERIT:
   2000  1.1.1.6  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   2001  1.1.1.6  christos 	    return FALSE;
   2002  1.1.1.6  christos 	  break;
   2003  1.1.1.6  christos 
   2004  1.1.1.6  christos 	/* This relocation describes which C++ vtable entries are actually
   2005  1.1.1.6  christos 	   used.  Record for later use during GC.  */
   2006  1.1.1.6  christos 	case R_MMIX_GNU_VTENTRY:
   2007  1.1.1.6  christos 	  BFD_ASSERT (h != NULL);
   2008      1.1     skrll 	  if (h != NULL
   2009      1.1     skrll 	      && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   2010      1.1     skrll 	    return FALSE;
   2011      1.1     skrll 	  break;
   2012      1.1     skrll 	}
   2013      1.1     skrll     }
   2014      1.1     skrll 
   2015      1.1     skrll   return TRUE;
   2016      1.1     skrll }
   2017      1.1     skrll 
   2018  1.1.1.3  christos /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
   2019      1.1     skrll    Copied from elf_link_add_object_symbols.  */
   2020      1.1     skrll 
   2021      1.1     skrll bfd_boolean
   2022      1.1     skrll _bfd_mmix_check_all_relocs (bfd *abfd, struct bfd_link_info *info)
   2023      1.1     skrll {
   2024      1.1     skrll   asection *o;
   2025      1.1     skrll 
   2026      1.1     skrll   for (o = abfd->sections; o != NULL; o = o->next)
   2027      1.1     skrll     {
   2028      1.1     skrll       Elf_Internal_Rela *internal_relocs;
   2029      1.1     skrll       bfd_boolean ok;
   2030      1.1     skrll 
   2031      1.1     skrll       if ((o->flags & SEC_RELOC) == 0
   2032      1.1     skrll 	  || o->reloc_count == 0
   2033      1.1     skrll 	  || ((info->strip == strip_all || info->strip == strip_debugger)
   2034      1.1     skrll 	      && (o->flags & SEC_DEBUGGING) != 0)
   2035  1.1.1.3  christos 	  || bfd_is_abs_section (o->output_section))
   2036      1.1     skrll 	continue;
   2037      1.1     skrll 
   2038      1.1     skrll       internal_relocs
   2039      1.1     skrll 	= _bfd_elf_link_read_relocs (abfd, o, NULL,
   2040      1.1     skrll 				     (Elf_Internal_Rela *) NULL,
   2041      1.1     skrll 				     info->keep_memory);
   2042      1.1     skrll       if (internal_relocs == NULL)
   2043      1.1     skrll 	return FALSE;
   2044      1.1     skrll 
   2045      1.1     skrll       ok = mmix_elf_check_common_relocs (abfd, info, o, internal_relocs);
   2046      1.1     skrll 
   2047      1.1     skrll       if (! info->keep_memory)
   2048      1.1     skrll 	free (internal_relocs);
   2049      1.1     skrll 
   2050      1.1     skrll       if (! ok)
   2051      1.1     skrll 	return FALSE;
   2052      1.1     skrll     }
   2053      1.1     skrll 
   2054      1.1     skrll   return TRUE;
   2055      1.1     skrll }
   2056      1.1     skrll 
   2057  1.1.1.2  christos /* Change symbols relative to the reg contents section to instead be to
   2059  1.1.1.3  christos    the register section, and scale them down to correspond to the register
   2060  1.1.1.3  christos    number.  */
   2061  1.1.1.3  christos 
   2062  1.1.1.3  christos static int
   2063      1.1     skrll mmix_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2064      1.1     skrll 				  const char *name ATTRIBUTE_UNUSED,
   2065      1.1     skrll 				  Elf_Internal_Sym *sym,
   2066      1.1     skrll 				  asection *input_sec,
   2067      1.1     skrll 				  struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
   2068      1.1     skrll {
   2069      1.1     skrll   if (input_sec != NULL
   2070      1.1     skrll       && input_sec->name != NULL
   2071      1.1     skrll       && ELF_ST_TYPE (sym->st_info) != STT_SECTION
   2072      1.1     skrll       && strcmp (input_sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
   2073  1.1.1.2  christos     {
   2074      1.1     skrll       sym->st_value /= 8;
   2075      1.1     skrll       sym->st_shndx = SHN_REGISTER;
   2076      1.1     skrll     }
   2077      1.1     skrll 
   2078      1.1     skrll   return 1;
   2079      1.1     skrll }
   2080      1.1     skrll 
   2081      1.1     skrll /* We fake a register section that holds values that are register numbers.
   2082      1.1     skrll    Having a SHN_REGISTER and register section translates better to other
   2083      1.1     skrll    formats (e.g. mmo) than for example a STT_REGISTER attribute.
   2084      1.1     skrll    This section faking is based on a construct in elf32-mips.c.  */
   2085      1.1     skrll static asection mmix_elf_reg_section;
   2086      1.1     skrll static asymbol mmix_elf_reg_section_symbol;
   2087  1.1.1.5  christos static asymbol *mmix_elf_reg_section_symbol_ptr;
   2088      1.1     skrll 
   2089      1.1     skrll /* Handle the special section numbers that a symbol may use.  */
   2090      1.1     skrll 
   2091      1.1     skrll void
   2092      1.1     skrll mmix_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
   2093      1.1     skrll {
   2094      1.1     skrll   elf_symbol_type *elfsym;
   2095      1.1     skrll 
   2096      1.1     skrll   elfsym = (elf_symbol_type *) asym;
   2097      1.1     skrll   switch (elfsym->internal_elf_sym.st_shndx)
   2098      1.1     skrll     {
   2099      1.1     skrll     case SHN_REGISTER:
   2100      1.1     skrll       if (mmix_elf_reg_section.name == NULL)
   2101      1.1     skrll 	{
   2102      1.1     skrll 	  /* Initialize the register section.  */
   2103      1.1     skrll 	  mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME;
   2104      1.1     skrll 	  mmix_elf_reg_section.flags = SEC_NO_FLAGS;
   2105      1.1     skrll 	  mmix_elf_reg_section.output_section = &mmix_elf_reg_section;
   2106      1.1     skrll 	  mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol;
   2107      1.1     skrll 	  mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr;
   2108      1.1     skrll 	  mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME;
   2109      1.1     skrll 	  mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM;
   2110      1.1     skrll 	  mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section;
   2111      1.1     skrll 	  mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol;
   2112      1.1     skrll 	}
   2113      1.1     skrll       asym->section = &mmix_elf_reg_section;
   2114      1.1     skrll       break;
   2115      1.1     skrll 
   2116      1.1     skrll     default:
   2117      1.1     skrll       break;
   2118      1.1     skrll     }
   2119      1.1     skrll }
   2120  1.1.1.3  christos 
   2121  1.1.1.3  christos /* Given a BFD section, try to locate the corresponding ELF section
   2122  1.1.1.3  christos    index.  */
   2123      1.1     skrll 
   2124      1.1     skrll static bfd_boolean
   2125      1.1     skrll mmix_elf_section_from_bfd_section (bfd *       abfd ATTRIBUTE_UNUSED,
   2126      1.1     skrll 				   asection *  sec,
   2127      1.1     skrll 				   int *       retval)
   2128      1.1     skrll {
   2129      1.1     skrll   if (strcmp (bfd_get_section_name (abfd, sec), MMIX_REG_SECTION_NAME) == 0)
   2130      1.1     skrll     *retval = SHN_REGISTER;
   2131      1.1     skrll   else
   2132      1.1     skrll     return FALSE;
   2133      1.1     skrll 
   2134      1.1     skrll   return TRUE;
   2135      1.1     skrll }
   2136      1.1     skrll 
   2137      1.1     skrll /* Hook called by the linker routine which adds symbols from an object
   2138      1.1     skrll    file.  We must handle the special SHN_REGISTER section number here.
   2139  1.1.1.3  christos 
   2140  1.1.1.3  christos    We also check that we only have *one* each of the section-start
   2141  1.1.1.3  christos    symbols, since otherwise having two with the same value would cause
   2142  1.1.1.3  christos    them to be "merged", but with the contents serialized.  */
   2143  1.1.1.3  christos 
   2144  1.1.1.3  christos static bfd_boolean
   2145  1.1.1.3  christos mmix_elf_add_symbol_hook (bfd *abfd,
   2146  1.1.1.3  christos 			  struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2147      1.1     skrll 			  Elf_Internal_Sym *sym,
   2148      1.1     skrll 			  const char **namep ATTRIBUTE_UNUSED,
   2149      1.1     skrll 			  flagword *flagsp ATTRIBUTE_UNUSED,
   2150      1.1     skrll 			  asection **secp,
   2151      1.1     skrll 			  bfd_vma *valp ATTRIBUTE_UNUSED)
   2152      1.1     skrll {
   2153      1.1     skrll   if (sym->st_shndx == SHN_REGISTER)
   2154      1.1     skrll     {
   2155      1.1     skrll       *secp = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
   2156      1.1     skrll       (*secp)->flags |= SEC_LINKER_CREATED;
   2157      1.1     skrll     }
   2158      1.1     skrll   else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.'
   2159      1.1     skrll 	   && CONST_STRNEQ (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX))
   2160      1.1     skrll     {
   2161      1.1     skrll       /* See if we have another one.  */
   2162      1.1     skrll       struct bfd_link_hash_entry *h = bfd_link_hash_lookup (info->hash,
   2163      1.1     skrll 							    *namep,
   2164      1.1     skrll 							    FALSE,
   2165      1.1     skrll 							    FALSE,
   2166      1.1     skrll 							    FALSE);
   2167  1.1.1.6  christos 
   2168  1.1.1.6  christos       if (h != NULL && h->type != bfd_link_hash_undefined)
   2169  1.1.1.6  christos 	{
   2170  1.1.1.6  christos 	  /* How do we get the asymbol (or really: the filename) from h?
   2171  1.1.1.6  christos 	     h->u.def.section->owner is NULL.  */
   2172  1.1.1.6  christos 	  _bfd_error_handler
   2173      1.1     skrll 	    /* xgettext:c-format */
   2174      1.1     skrll 	    (_("%B: Error: multiple definition of `%s'; start of %s "
   2175      1.1     skrll 	       "is set in a earlier linked file\n"),
   2176      1.1     skrll 	     abfd, *namep,
   2177      1.1     skrll 	     *namep + strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX));
   2178      1.1     skrll 	   bfd_set_error (bfd_error_bad_value);
   2179      1.1     skrll 	   return FALSE;
   2180      1.1     skrll 	}
   2181      1.1     skrll     }
   2182      1.1     skrll 
   2183  1.1.1.3  christos   return TRUE;
   2184  1.1.1.3  christos }
   2185      1.1     skrll 
   2186      1.1     skrll /* We consider symbols matching "L.*:[0-9]+" to be local symbols.  */
   2187      1.1     skrll 
   2188      1.1     skrll static bfd_boolean
   2189      1.1     skrll mmix_elf_is_local_label_name (bfd *abfd, const char *name)
   2190      1.1     skrll {
   2191      1.1     skrll   const char *colpos;
   2192      1.1     skrll   int digits;
   2193      1.1     skrll 
   2194      1.1     skrll   /* Also include the default local-label definition.  */
   2195      1.1     skrll   if (_bfd_elf_is_local_label_name (abfd, name))
   2196      1.1     skrll     return TRUE;
   2197      1.1     skrll 
   2198      1.1     skrll   if (*name != 'L')
   2199      1.1     skrll     return FALSE;
   2200      1.1     skrll 
   2201      1.1     skrll   /* If there's no ":", or more than one, it's not a local symbol.  */
   2202      1.1     skrll   colpos = strchr (name, ':');
   2203      1.1     skrll   if (colpos == NULL || strchr (colpos + 1, ':') != NULL)
   2204      1.1     skrll     return FALSE;
   2205      1.1     skrll 
   2206      1.1     skrll   /* Check that there are remaining characters and that they are digits.  */
   2207      1.1     skrll   if (colpos[1] == 0)
   2208      1.1     skrll     return FALSE;
   2209      1.1     skrll 
   2210      1.1     skrll   digits = strspn (colpos + 1, "0123456789");
   2211      1.1     skrll   return digits != 0 && colpos[1 + digits] == 0;
   2212  1.1.1.3  christos }
   2213      1.1     skrll 
   2214      1.1     skrll /* We get rid of the register section here.  */
   2215      1.1     skrll 
   2216      1.1     skrll bfd_boolean
   2217      1.1     skrll mmix_elf_final_link (bfd *abfd, struct bfd_link_info *info)
   2218      1.1     skrll {
   2219      1.1     skrll   /* We never output a register section, though we create one for
   2220      1.1     skrll      temporary measures.  Check that nobody entered contents into it.  */
   2221      1.1     skrll   asection *reg_section;
   2222      1.1     skrll 
   2223      1.1     skrll   reg_section = bfd_get_section_by_name (abfd, MMIX_REG_SECTION_NAME);
   2224      1.1     skrll 
   2225      1.1     skrll   if (reg_section != NULL)
   2226      1.1     skrll     {
   2227      1.1     skrll       /* FIXME: Pass error state gracefully.  */
   2228      1.1     skrll       if (bfd_get_section_flags (abfd, reg_section) & SEC_HAS_CONTENTS)
   2229      1.1     skrll 	_bfd_abort (__FILE__, __LINE__, _("Register section has contents\n"));
   2230      1.1     skrll 
   2231      1.1     skrll       /* Really remove the section, if it hasn't already been done.  */
   2232      1.1     skrll       if (!bfd_section_removed_from_list (abfd, reg_section))
   2233      1.1     skrll 	{
   2234      1.1     skrll 	  bfd_section_list_remove (abfd, reg_section);
   2235      1.1     skrll 	  --abfd->section_count;
   2236      1.1     skrll 	}
   2237      1.1     skrll     }
   2238      1.1     skrll 
   2239      1.1     skrll   if (! bfd_elf_final_link (abfd, info))
   2240      1.1     skrll     return FALSE;
   2241      1.1     skrll 
   2242      1.1     skrll   /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
   2243      1.1     skrll      the regular linker machinery.  We do it here, like other targets with
   2244      1.1     skrll      special sections.  */
   2245      1.1     skrll   if (info->base_file != NULL)
   2246      1.1     skrll     {
   2247      1.1     skrll       asection *greg_section
   2248      1.1     skrll 	= bfd_get_section_by_name ((bfd *) info->base_file,
   2249      1.1     skrll 				   MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
   2250      1.1     skrll       if (!bfd_set_section_contents (abfd,
   2251      1.1     skrll 				     greg_section->output_section,
   2252      1.1     skrll 				     greg_section->contents,
   2253      1.1     skrll 				     (file_ptr) greg_section->output_offset,
   2254      1.1     skrll 				     greg_section->size))
   2255      1.1     skrll 	return FALSE;
   2256      1.1     skrll     }
   2257      1.1     skrll   return TRUE;
   2258      1.1     skrll }
   2259  1.1.1.3  christos 
   2260  1.1.1.3  christos /* We need to include the maximum size of PUSHJ-stubs in the initial
   2261  1.1.1.3  christos    section size.  This is expected to shrink during linker relaxation.  */
   2262      1.1     skrll 
   2263      1.1     skrll static void
   2264      1.1     skrll mmix_set_relaxable_size (bfd *abfd ATTRIBUTE_UNUSED,
   2265      1.1     skrll 			 asection *sec,
   2266      1.1     skrll 			 void *ptr)
   2267      1.1     skrll {
   2268      1.1     skrll   struct bfd_link_info *info = ptr;
   2269      1.1     skrll 
   2270      1.1     skrll   /* Make sure we only do this for section where we know we want this,
   2271      1.1     skrll      otherwise we might end up resetting the size of COMMONs.  */
   2272      1.1     skrll   if (mmix_elf_section_data (sec)->pjs.n_pushj_relocs == 0)
   2273      1.1     skrll     return;
   2274      1.1     skrll 
   2275      1.1     skrll   sec->rawsize = sec->size;
   2276  1.1.1.4  christos   sec->size += (mmix_elf_section_data (sec)->pjs.n_pushj_relocs
   2277      1.1     skrll 		* MAX_PUSHJ_STUB_SIZE);
   2278      1.1     skrll 
   2279      1.1     skrll   /* For use in relocatable link, we start with a max stubs size.  See
   2280      1.1     skrll      mmix_elf_relax_section.  */
   2281      1.1     skrll   if (bfd_link_relocatable (info) && sec->output_section)
   2282      1.1     skrll     mmix_elf_section_data (sec->output_section)->pjs.stubs_size_sum
   2283      1.1     skrll       += (mmix_elf_section_data (sec)->pjs.n_pushj_relocs
   2284      1.1     skrll 	  * MAX_PUSHJ_STUB_SIZE);
   2285      1.1     skrll }
   2286  1.1.1.3  christos 
   2287  1.1.1.3  christos /* Initialize stuff for the linker-generated GREGs to match
   2288      1.1     skrll    R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker.  */
   2289      1.1     skrll 
   2290      1.1     skrll bfd_boolean
   2291      1.1     skrll _bfd_mmix_before_linker_allocation (bfd *abfd ATTRIBUTE_UNUSED,
   2292      1.1     skrll 				    struct bfd_link_info *info)
   2293      1.1     skrll {
   2294      1.1     skrll   asection *bpo_gregs_section;
   2295      1.1     skrll   bfd *bpo_greg_owner;
   2296      1.1     skrll   struct bpo_greg_section_info *gregdata;
   2297      1.1     skrll   size_t n_gregs;
   2298      1.1     skrll   bfd_vma gregs_size;
   2299  1.1.1.4  christos   size_t i;
   2300      1.1     skrll   size_t *bpo_reloc_indexes;
   2301      1.1     skrll   bfd *ibfd;
   2302      1.1     skrll 
   2303      1.1     skrll   /* Set the initial size of sections.  */
   2304      1.1     skrll   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   2305      1.1     skrll     bfd_map_over_sections (ibfd, mmix_set_relaxable_size, info);
   2306      1.1     skrll 
   2307      1.1     skrll   /* The bpo_greg_owner bfd is supposed to have been set by
   2308      1.1     skrll      mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
   2309      1.1     skrll      If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET.  */
   2310      1.1     skrll   bpo_greg_owner = (bfd *) info->base_file;
   2311      1.1     skrll   if (bpo_greg_owner == NULL)
   2312      1.1     skrll     return TRUE;
   2313      1.1     skrll 
   2314      1.1     skrll   bpo_gregs_section
   2315      1.1     skrll     = bfd_get_section_by_name (bpo_greg_owner,
   2316      1.1     skrll 			       MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
   2317      1.1     skrll 
   2318      1.1     skrll   if (bpo_gregs_section == NULL)
   2319      1.1     skrll     return TRUE;
   2320      1.1     skrll 
   2321      1.1     skrll   /* We use the target-data handle in the ELF section data.  */
   2322      1.1     skrll   gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
   2323      1.1     skrll   if (gregdata == NULL)
   2324      1.1     skrll     return FALSE;
   2325      1.1     skrll 
   2326      1.1     skrll   n_gregs = gregdata->n_bpo_relocs;
   2327      1.1     skrll   gregdata->n_allocated_bpo_gregs = n_gregs;
   2328      1.1     skrll 
   2329      1.1     skrll   /* When this reaches zero during relaxation, all entries have been
   2330      1.1     skrll      filled in and the size of the linker gregs can be calculated.  */
   2331      1.1     skrll   gregdata->n_remaining_bpo_relocs_this_relaxation_round = n_gregs;
   2332      1.1     skrll 
   2333      1.1     skrll   /* Set the zeroth-order estimate for the GREGs size.  */
   2334      1.1     skrll   gregs_size = n_gregs * 8;
   2335      1.1     skrll 
   2336      1.1     skrll   if (!bfd_set_section_size (bpo_greg_owner, bpo_gregs_section, gregs_size))
   2337      1.1     skrll     return FALSE;
   2338      1.1     skrll 
   2339      1.1     skrll   /* Allocate and set up the GREG arrays.  They're filled in at relaxation
   2340      1.1     skrll      time.  Note that we must use the max number ever noted for the array,
   2341      1.1     skrll      since the index numbers were created before GC.  */
   2342      1.1     skrll   gregdata->reloc_request
   2343      1.1     skrll     = bfd_zalloc (bpo_greg_owner,
   2344      1.1     skrll 		  sizeof (struct bpo_reloc_request)
   2345      1.1     skrll 		  * gregdata->n_max_bpo_relocs);
   2346      1.1     skrll 
   2347      1.1     skrll   gregdata->bpo_reloc_indexes
   2348      1.1     skrll     = bpo_reloc_indexes
   2349      1.1     skrll     = bfd_alloc (bpo_greg_owner,
   2350      1.1     skrll 		 gregdata->n_max_bpo_relocs
   2351      1.1     skrll 		 * sizeof (size_t));
   2352      1.1     skrll   if (bpo_reloc_indexes == NULL)
   2353      1.1     skrll     return FALSE;
   2354      1.1     skrll 
   2355      1.1     skrll   /* The default order is an identity mapping.  */
   2356      1.1     skrll   for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
   2357      1.1     skrll     {
   2358      1.1     skrll       bpo_reloc_indexes[i] = i;
   2359      1.1     skrll       gregdata->reloc_request[i].bpo_reloc_no = i;
   2360      1.1     skrll     }
   2361      1.1     skrll 
   2362      1.1     skrll   return TRUE;
   2363      1.1     skrll }
   2364  1.1.1.3  christos 
   2365  1.1.1.3  christos /* Fill in contents in the linker allocated gregs.  Everything is
   2367      1.1     skrll    calculated at this point; we just move the contents into place here.  */
   2368      1.1     skrll 
   2369      1.1     skrll bfd_boolean
   2370      1.1     skrll _bfd_mmix_after_linker_allocation (bfd *abfd ATTRIBUTE_UNUSED,
   2371      1.1     skrll 				   struct bfd_link_info *link_info)
   2372      1.1     skrll {
   2373      1.1     skrll   asection *bpo_gregs_section;
   2374      1.1     skrll   bfd *bpo_greg_owner;
   2375      1.1     skrll   struct bpo_greg_section_info *gregdata;
   2376      1.1     skrll   size_t n_gregs;
   2377      1.1     skrll   size_t i, j;
   2378      1.1     skrll   size_t lastreg;
   2379      1.1     skrll   bfd_byte *contents;
   2380      1.1     skrll 
   2381      1.1     skrll   /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
   2382      1.1     skrll      when the first R_MMIX_BASE_PLUS_OFFSET is seen.  If there is no such
   2383      1.1     skrll      object, there was no R_MMIX_BASE_PLUS_OFFSET.  */
   2384      1.1     skrll   bpo_greg_owner = (bfd *) link_info->base_file;
   2385      1.1     skrll   if (bpo_greg_owner == NULL)
   2386      1.1     skrll     return TRUE;
   2387      1.1     skrll 
   2388      1.1     skrll   bpo_gregs_section
   2389      1.1     skrll     = bfd_get_section_by_name (bpo_greg_owner,
   2390      1.1     skrll 			       MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
   2391      1.1     skrll 
   2392      1.1     skrll   /* This can't happen without DSO handling.  When DSOs are handled
   2393      1.1     skrll      without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
   2394      1.1     skrll      section.  */
   2395      1.1     skrll   if (bpo_gregs_section == NULL)
   2396      1.1     skrll     return TRUE;
   2397      1.1     skrll 
   2398      1.1     skrll   /* We use the target-data handle in the ELF section data.  */
   2399      1.1     skrll 
   2400      1.1     skrll   gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
   2401      1.1     skrll   if (gregdata == NULL)
   2402      1.1     skrll     return FALSE;
   2403      1.1     skrll 
   2404      1.1     skrll   n_gregs = gregdata->n_allocated_bpo_gregs;
   2405      1.1     skrll 
   2406      1.1     skrll   bpo_gregs_section->contents
   2407      1.1     skrll     = contents = bfd_alloc (bpo_greg_owner, bpo_gregs_section->size);
   2408      1.1     skrll   if (contents == NULL)
   2409      1.1     skrll     return FALSE;
   2410      1.1     skrll 
   2411      1.1     skrll   /* Sanity check: If these numbers mismatch, some relocation has not been
   2412  1.1.1.6  christos      accounted for and the rest of gregdata is probably inconsistent.
   2413  1.1.1.6  christos      It's a bug, but it's more helpful to identify it than segfaulting
   2414  1.1.1.6  christos      below.  */
   2415      1.1     skrll   if (gregdata->n_remaining_bpo_relocs_this_relaxation_round
   2416  1.1.1.6  christos       != gregdata->n_bpo_relocs)
   2417  1.1.1.6  christos     {
   2418      1.1     skrll       _bfd_error_handler
   2419      1.1     skrll 	/* xgettext:c-format */
   2420      1.1     skrll 	(_("Internal inconsistency: remaining %lu != max %lu.\n\
   2421      1.1     skrll   Please report this bug."),
   2422      1.1     skrll 	 (unsigned long) gregdata->n_remaining_bpo_relocs_this_relaxation_round,
   2423      1.1     skrll 	 (unsigned long) gregdata->n_bpo_relocs);
   2424      1.1     skrll       return FALSE;
   2425      1.1     skrll     }
   2426      1.1     skrll 
   2427      1.1     skrll   for (lastreg = 255, i = 0, j = 0; j < n_gregs; i++)
   2428      1.1     skrll     if (gregdata->reloc_request[i].regindex != lastreg)
   2429      1.1     skrll       {
   2430      1.1     skrll 	bfd_put_64 (bpo_greg_owner, gregdata->reloc_request[i].value,
   2431      1.1     skrll 		    contents + j * 8);
   2432      1.1     skrll 	lastreg = gregdata->reloc_request[i].regindex;
   2433      1.1     skrll 	j++;
   2434      1.1     skrll       }
   2435      1.1     skrll 
   2436      1.1     skrll   return TRUE;
   2437  1.1.1.3  christos }
   2438      1.1     skrll 
   2439      1.1     skrll /* Sort valid relocs to come before non-valid relocs, then on increasing
   2440      1.1     skrll    value.  */
   2441      1.1     skrll 
   2442      1.1     skrll static int
   2443      1.1     skrll bpo_reloc_request_sort_fn (const void * p1, const void * p2)
   2444      1.1     skrll {
   2445      1.1     skrll   const struct bpo_reloc_request *r1 = (const struct bpo_reloc_request *) p1;
   2446      1.1     skrll   const struct bpo_reloc_request *r2 = (const struct bpo_reloc_request *) p2;
   2447      1.1     skrll 
   2448      1.1     skrll   /* Primary function is validity; non-valid relocs sorted after valid
   2449      1.1     skrll      ones.  */
   2450      1.1     skrll   if (r1->valid != r2->valid)
   2451      1.1     skrll     return r2->valid - r1->valid;
   2452      1.1     skrll 
   2453      1.1     skrll   /* Then sort on value.  Don't simplify and return just the difference of
   2454      1.1     skrll      the values: the upper bits of the 64-bit value would be truncated on
   2455      1.1     skrll      a host with 32-bit ints.  */
   2456      1.1     skrll   if (r1->value != r2->value)
   2457      1.1     skrll     return r1->value > r2->value ? 1 : -1;
   2458      1.1     skrll 
   2459      1.1     skrll   /* As a last re-sort, use the relocation number, so we get a stable
   2460      1.1     skrll      sort.  The *addresses* aren't stable since items are swapped during
   2461      1.1     skrll      sorting.  It depends on the qsort implementation if this actually
   2462      1.1     skrll      happens.  */
   2463      1.1     skrll   return r1->bpo_reloc_no > r2->bpo_reloc_no
   2464      1.1     skrll     ? 1 : (r1->bpo_reloc_no < r2->bpo_reloc_no ? -1 : 0);
   2465  1.1.1.5  christos }
   2466  1.1.1.6  christos 
   2467      1.1     skrll /* For debug use only.  Dumps the global register allocations resulting
   2468      1.1     skrll    from base-plus-offset relocs.  */
   2469      1.1     skrll 
   2470      1.1     skrll void
   2471      1.1     skrll mmix_dump_bpo_gregs (struct bfd_link_info *link_info,
   2472      1.1     skrll 		     void (*pf) (const char *fmt, ...))
   2473      1.1     skrll {
   2474      1.1     skrll   bfd *bpo_greg_owner;
   2475      1.1     skrll   asection *bpo_gregs_section;
   2476      1.1     skrll   struct bpo_greg_section_info *gregdata;
   2477      1.1     skrll   unsigned int i;
   2478      1.1     skrll 
   2479      1.1     skrll   if (link_info == NULL || link_info->base_file == NULL)
   2480      1.1     skrll     return;
   2481      1.1     skrll 
   2482      1.1     skrll   bpo_greg_owner = (bfd *) link_info->base_file;
   2483      1.1     skrll 
   2484      1.1     skrll   bpo_gregs_section
   2485      1.1     skrll     = bfd_get_section_by_name (bpo_greg_owner,
   2486      1.1     skrll 			       MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
   2487      1.1     skrll 
   2488      1.1     skrll   if (bpo_gregs_section == NULL)
   2489      1.1     skrll     return;
   2490      1.1     skrll 
   2491      1.1     skrll   gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
   2492      1.1     skrll   if (gregdata == NULL)
   2493      1.1     skrll     return;
   2494      1.1     skrll 
   2495      1.1     skrll   if (pf == NULL)
   2496      1.1     skrll     pf = _bfd_error_handler;
   2497      1.1     skrll 
   2498      1.1     skrll   /* These format strings are not translated.  They are for debug purposes
   2499      1.1     skrll      only and never displayed to an end user.  Should they escape, we
   2500      1.1     skrll      surely want them in original.  */
   2501      1.1     skrll   (*pf) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
   2502      1.1     skrll  n_allocated_bpo_gregs: %u\n", gregdata->n_bpo_relocs,
   2503      1.1     skrll      gregdata->n_max_bpo_relocs,
   2504      1.1     skrll      gregdata->n_remaining_bpo_relocs_this_relaxation_round,
   2505      1.1     skrll      gregdata->n_allocated_bpo_gregs);
   2506      1.1     skrll 
   2507      1.1     skrll   if (gregdata->reloc_request)
   2508      1.1     skrll     for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
   2509      1.1     skrll       (*pf) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx  r: %3u o: %3u\n",
   2510      1.1     skrll 	     i,
   2511      1.1     skrll 	     (gregdata->bpo_reloc_indexes != NULL
   2512      1.1     skrll 	      ? gregdata->bpo_reloc_indexes[i] : (size_t) -1),
   2513      1.1     skrll 	     gregdata->reloc_request[i].bpo_reloc_no,
   2514      1.1     skrll 	     gregdata->reloc_request[i].valid,
   2515      1.1     skrll 
   2516      1.1     skrll 	     (unsigned long) (gregdata->reloc_request[i].value >> 32),
   2517      1.1     skrll 	     (unsigned long) gregdata->reloc_request[i].value,
   2518      1.1     skrll 	     gregdata->reloc_request[i].regindex,
   2519      1.1     skrll 	     gregdata->reloc_request[i].offset);
   2520  1.1.1.2  christos }
   2521      1.1     skrll 
   2522      1.1     skrll /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
   2523      1.1     skrll    when the last such reloc is done, an index-array is sorted according to
   2524      1.1     skrll    the values and iterated over to produce register numbers (indexed by 0
   2525      1.1     skrll    from the first allocated register number) and offsets for use in real
   2526      1.1     skrll    relocation.  (N.B.: Relocatable runs are handled, not just punted.)
   2527  1.1.1.3  christos 
   2528  1.1.1.3  christos    PUSHJ stub accounting is also done here.
   2529  1.1.1.3  christos 
   2530  1.1.1.3  christos    Symbol- and reloc-reading infrastructure copied from elf-m10200.c.  */
   2531      1.1     skrll 
   2532      1.1     skrll static bfd_boolean
   2533      1.1     skrll mmix_elf_relax_section (bfd *abfd,
   2534      1.1     skrll 			asection *sec,
   2535      1.1     skrll 			struct bfd_link_info *link_info,
   2536      1.1     skrll 			bfd_boolean *again)
   2537      1.1     skrll {
   2538      1.1     skrll   Elf_Internal_Shdr *symtab_hdr;
   2539      1.1     skrll   Elf_Internal_Rela *internal_relocs;
   2540      1.1     skrll   Elf_Internal_Rela *irel, *irelend;
   2541      1.1     skrll   asection *bpo_gregs_section = NULL;
   2542      1.1     skrll   struct bpo_greg_section_info *gregdata;
   2543      1.1     skrll   struct bpo_reloc_section_info *bpodata
   2544      1.1     skrll     = mmix_elf_section_data (sec)->bpo.reloc;
   2545      1.1     skrll   /* The initialization is to quiet compiler warnings.  The value is to
   2546      1.1     skrll      spot a missing actual initialization.  */
   2547      1.1     skrll   size_t bpono = (size_t) -1;
   2548      1.1     skrll   size_t pjsno = 0;
   2549      1.1     skrll   Elf_Internal_Sym *isymbuf = NULL;
   2550      1.1     skrll   bfd_size_type size = sec->rawsize ? sec->rawsize : sec->size;
   2551      1.1     skrll 
   2552      1.1     skrll   mmix_elf_section_data (sec)->pjs.stubs_size_sum = 0;
   2553      1.1     skrll 
   2554      1.1     skrll   /* Assume nothing changes.  */
   2555      1.1     skrll   *again = FALSE;
   2556      1.1     skrll 
   2557      1.1     skrll   /* We don't have to do anything if this section does not have relocs, or
   2558  1.1.1.6  christos      if this is not a code section.  */
   2559      1.1     skrll   if ((sec->flags & SEC_RELOC) == 0
   2560      1.1     skrll       || sec->reloc_count == 0
   2561      1.1     skrll       || (sec->flags & SEC_CODE) == 0
   2562      1.1     skrll       || (sec->flags & SEC_LINKER_CREATED) != 0
   2563      1.1     skrll       /* If no R_MMIX_BASE_PLUS_OFFSET relocs and no PUSHJ-stub relocs,
   2564      1.1     skrll 	 then nothing to do.  */
   2565      1.1     skrll       || (bpodata == NULL
   2566      1.1     skrll 	  && mmix_elf_section_data (sec)->pjs.n_pushj_relocs == 0))
   2567      1.1     skrll     return TRUE;
   2568      1.1     skrll 
   2569      1.1     skrll   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   2570      1.1     skrll 
   2571      1.1     skrll   if (bpodata != NULL)
   2572      1.1     skrll     {
   2573      1.1     skrll       bpo_gregs_section = bpodata->bpo_greg_section;
   2574      1.1     skrll       gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
   2575      1.1     skrll       bpono = bpodata->first_base_plus_offset_reloc;
   2576  1.1.1.3  christos     }
   2577      1.1     skrll   else
   2578      1.1     skrll     gregdata = NULL;
   2579      1.1     skrll 
   2580      1.1     skrll   /* Get a copy of the native relocations.  */
   2581      1.1     skrll   internal_relocs
   2582      1.1     skrll     = _bfd_elf_link_read_relocs (abfd, sec, NULL,
   2583      1.1     skrll 				 (Elf_Internal_Rela *) NULL,
   2584      1.1     skrll 				 link_info->keep_memory);
   2585      1.1     skrll   if (internal_relocs == NULL)
   2586      1.1     skrll     goto error_return;
   2587      1.1     skrll 
   2588      1.1     skrll   /* Walk through them looking for relaxing opportunities.  */
   2589      1.1     skrll   irelend = internal_relocs + sec->reloc_count;
   2590      1.1     skrll   for (irel = internal_relocs; irel < irelend; irel++)
   2591      1.1     skrll     {
   2592      1.1     skrll       bfd_vma symval;
   2593      1.1     skrll       struct elf_link_hash_entry *h = NULL;
   2594      1.1     skrll 
   2595      1.1     skrll       /* We only process two relocs.  */
   2596      1.1     skrll       if (ELF64_R_TYPE (irel->r_info) != (int) R_MMIX_BASE_PLUS_OFFSET
   2597  1.1.1.4  christos 	  && ELF64_R_TYPE (irel->r_info) != (int) R_MMIX_PUSHJ_STUBBABLE)
   2598      1.1     skrll 	continue;
   2599      1.1     skrll 
   2600      1.1     skrll       /* We process relocs in a distinctly different way when this is a
   2601      1.1     skrll 	 relocatable link (for one, we don't look at symbols), so we avoid
   2602      1.1     skrll 	 mixing its code with that for the "normal" relaxation.  */
   2603      1.1     skrll       if (bfd_link_relocatable (link_info))
   2604      1.1     skrll 	{
   2605      1.1     skrll 	  /* The only transformation in a relocatable link is to generate
   2606      1.1     skrll 	     a full stub at the location of the stub calculated for the
   2607      1.1     skrll 	     input section, if the relocated stub location, the end of the
   2608      1.1     skrll 	     output section plus earlier stubs, cannot be reached.  Thus
   2609      1.1     skrll 	     relocatable linking can only lead to worse code, but it still
   2610      1.1     skrll 	     works.  */
   2611      1.1     skrll 	  if (ELF64_R_TYPE (irel->r_info) == R_MMIX_PUSHJ_STUBBABLE)
   2612      1.1     skrll 	    {
   2613      1.1     skrll 	      /* If we can reach the end of the output-section and beyond
   2614      1.1     skrll 		 any current stubs, then we don't need a stub for this
   2615      1.1     skrll 		 reloc.  The relaxed order of output stub allocation may
   2616      1.1     skrll 		 not exactly match the straightforward order, so we always
   2617      1.1     skrll 		 assume presence of output stubs, which will allow
   2618      1.1     skrll 		 relaxation only on relocations indifferent to the
   2619      1.1     skrll 		 presence of output stub allocations for other relocations
   2620      1.1     skrll 		 and thus the order of output stub allocation.  */
   2621      1.1     skrll 	      if (bfd_check_overflow (complain_overflow_signed,
   2622      1.1     skrll 				      19,
   2623      1.1     skrll 				      0,
   2624      1.1     skrll 				      bfd_arch_bits_per_address (abfd),
   2625      1.1     skrll 				      /* Output-stub location.  */
   2626      1.1     skrll 				      sec->output_section->rawsize
   2627      1.1     skrll 				      + (mmix_elf_section_data (sec
   2628      1.1     skrll 							       ->output_section)
   2629      1.1     skrll 					 ->pjs.stubs_size_sum)
   2630      1.1     skrll 				      /* Location of this PUSHJ reloc.  */
   2631      1.1     skrll 				      - (sec->output_offset + irel->r_offset)
   2632      1.1     skrll 				      /* Don't count *this* stub twice.  */
   2633      1.1     skrll 				      - (mmix_elf_section_data (sec)
   2634      1.1     skrll 					 ->pjs.stub_size[pjsno]
   2635      1.1     skrll 					 + MAX_PUSHJ_STUB_SIZE))
   2636      1.1     skrll 		  == bfd_reloc_ok)
   2637      1.1     skrll 		mmix_elf_section_data (sec)->pjs.stub_size[pjsno] = 0;
   2638      1.1     skrll 
   2639      1.1     skrll 	      mmix_elf_section_data (sec)->pjs.stubs_size_sum
   2640      1.1     skrll 		+= mmix_elf_section_data (sec)->pjs.stub_size[pjsno];
   2641      1.1     skrll 
   2642      1.1     skrll 	      pjsno++;
   2643      1.1     skrll 	    }
   2644      1.1     skrll 
   2645      1.1     skrll 	  continue;
   2646      1.1     skrll 	}
   2647      1.1     skrll 
   2648      1.1     skrll       /* Get the value of the symbol referred to by the reloc.  */
   2649      1.1     skrll       if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
   2650      1.1     skrll 	{
   2651      1.1     skrll 	  /* A local symbol.  */
   2652      1.1     skrll 	  Elf_Internal_Sym *isym;
   2653      1.1     skrll 	  asection *sym_sec;
   2654      1.1     skrll 
   2655      1.1     skrll 	  /* Read this BFD's local symbols if we haven't already.  */
   2656      1.1     skrll 	  if (isymbuf == NULL)
   2657      1.1     skrll 	    {
   2658      1.1     skrll 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   2659      1.1     skrll 	      if (isymbuf == NULL)
   2660      1.1     skrll 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
   2661      1.1     skrll 						symtab_hdr->sh_info, 0,
   2662      1.1     skrll 						NULL, NULL, NULL);
   2663      1.1     skrll 	      if (isymbuf == 0)
   2664      1.1     skrll 		goto error_return;
   2665      1.1     skrll 	    }
   2666      1.1     skrll 
   2667      1.1     skrll 	  isym = isymbuf + ELF64_R_SYM (irel->r_info);
   2668      1.1     skrll 	  if (isym->st_shndx == SHN_UNDEF)
   2669      1.1     skrll 	    sym_sec = bfd_und_section_ptr;
   2670      1.1     skrll 	  else if (isym->st_shndx == SHN_ABS)
   2671      1.1     skrll 	    sym_sec = bfd_abs_section_ptr;
   2672      1.1     skrll 	  else if (isym->st_shndx == SHN_COMMON)
   2673      1.1     skrll 	    sym_sec = bfd_com_section_ptr;
   2674      1.1     skrll 	  else
   2675      1.1     skrll 	    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
   2676      1.1     skrll 	  symval = (isym->st_value
   2677      1.1     skrll 		    + sym_sec->output_section->vma
   2678      1.1     skrll 		    + sym_sec->output_offset);
   2679      1.1     skrll 	}
   2680      1.1     skrll       else
   2681      1.1     skrll 	{
   2682  1.1.1.6  christos 	  unsigned long indx;
   2683  1.1.1.6  christos 
   2684  1.1.1.6  christos 	  /* An external symbol.  */
   2685  1.1.1.6  christos 	  indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
   2686  1.1.1.6  christos 	  h = elf_sym_hashes (abfd)[indx];
   2687  1.1.1.6  christos 	  BFD_ASSERT (h != NULL);
   2688  1.1.1.6  christos 	  if (h->root.type == bfd_link_hash_undefweak)
   2689  1.1.1.6  christos 	    /* FIXME: for R_MMIX_PUSHJ_STUBBABLE, there are alternatives to
   2690  1.1.1.6  christos 	       the canonical value 0 for an unresolved weak symbol to
   2691  1.1.1.6  christos 	       consider: as the debug-friendly approach, resolve to "abort"
   2692  1.1.1.6  christos 	       (or a port-specific function), or as the space-friendly
   2693  1.1.1.6  christos 	       approach resolve to the next instruction (like some other
   2694  1.1.1.6  christos 	       ports, notably ARM and AArch64).  These alternatives require
   2695  1.1.1.6  christos 	       matching code in mmix_elf_perform_relocation or its caller.  */
   2696  1.1.1.6  christos 	    symval = 0;
   2697      1.1     skrll 	  else if (h->root.type == bfd_link_hash_defined
   2698      1.1     skrll 		   || h->root.type == bfd_link_hash_defweak)
   2699      1.1     skrll 	    symval = (h->root.u.def.value
   2700      1.1     skrll 		      + h->root.u.def.section->output_section->vma
   2701      1.1     skrll 		      + h->root.u.def.section->output_offset);
   2702      1.1     skrll 	  else
   2703      1.1     skrll 	    {
   2704      1.1     skrll 	      /* This appears to be a reference to an undefined symbol.  Just
   2705      1.1     skrll 		 ignore it--it will be caught by the regular reloc processing.
   2706      1.1     skrll 		 We need to keep BPO reloc accounting consistent, though
   2707      1.1     skrll 		 else we'll abort instead of emitting an error message.  */
   2708      1.1     skrll 	      if (ELF64_R_TYPE (irel->r_info) == R_MMIX_BASE_PLUS_OFFSET
   2709      1.1     skrll 		  && gregdata != NULL)
   2710      1.1     skrll 		{
   2711      1.1     skrll 		  gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
   2712      1.1     skrll 		  bpono++;
   2713      1.1     skrll 		}
   2714      1.1     skrll 	      continue;
   2715      1.1     skrll 	    }
   2716      1.1     skrll 	}
   2717      1.1     skrll 
   2718      1.1     skrll       if (ELF64_R_TYPE (irel->r_info) == (int) R_MMIX_PUSHJ_STUBBABLE)
   2719      1.1     skrll 	{
   2720      1.1     skrll 	  bfd_vma value = symval + irel->r_addend;
   2721      1.1     skrll 	  bfd_vma dot
   2722      1.1     skrll 	    = (sec->output_section->vma
   2723      1.1     skrll 	       + sec->output_offset
   2724      1.1     skrll 	       + irel->r_offset);
   2725      1.1     skrll 	  bfd_vma stubaddr
   2726      1.1     skrll 	    = (sec->output_section->vma
   2727      1.1     skrll 	       + sec->output_offset
   2728      1.1     skrll 	       + size
   2729      1.1     skrll 	       + mmix_elf_section_data (sec)->pjs.stubs_size_sum);
   2730      1.1     skrll 
   2731      1.1     skrll 	  if ((value & 3) == 0
   2732      1.1     skrll 	      && bfd_check_overflow (complain_overflow_signed,
   2733      1.1     skrll 				     19,
   2734      1.1     skrll 				     0,
   2735      1.1     skrll 				     bfd_arch_bits_per_address (abfd),
   2736      1.1     skrll 				     value - dot
   2737      1.1     skrll 				     - (value > dot
   2738      1.1     skrll 					? mmix_elf_section_data (sec)
   2739      1.1     skrll 					->pjs.stub_size[pjsno]
   2740      1.1     skrll 					: 0))
   2741      1.1     skrll 	      == bfd_reloc_ok)
   2742      1.1     skrll 	    /* If the reloc fits, no stub is needed.  */
   2743      1.1     skrll 	    mmix_elf_section_data (sec)->pjs.stub_size[pjsno] = 0;
   2744      1.1     skrll 	  else
   2745      1.1     skrll 	    /* Maybe we can get away with just a JMP insn?  */
   2746      1.1     skrll 	    if ((value & 3) == 0
   2747      1.1     skrll 		&& bfd_check_overflow (complain_overflow_signed,
   2748      1.1     skrll 				       27,
   2749      1.1     skrll 				       0,
   2750      1.1     skrll 				       bfd_arch_bits_per_address (abfd),
   2751      1.1     skrll 				       value - stubaddr
   2752      1.1     skrll 				       - (value > dot
   2753      1.1     skrll 					  ? mmix_elf_section_data (sec)
   2754      1.1     skrll 					  ->pjs.stub_size[pjsno] - 4
   2755      1.1     skrll 					  : 0))
   2756      1.1     skrll 		== bfd_reloc_ok)
   2757      1.1     skrll 	      /* Yep, account for a stub consisting of a single JMP insn.  */
   2758      1.1     skrll 	      mmix_elf_section_data (sec)->pjs.stub_size[pjsno] = 4;
   2759      1.1     skrll 	  else
   2760      1.1     skrll 	    /* Nope, go for the full insn stub.  It doesn't seem useful to
   2761      1.1     skrll 	       emit the intermediate sizes; those will only be useful for
   2762      1.1     skrll 	       a >64M program assuming contiguous code.  */
   2763      1.1     skrll 	    mmix_elf_section_data (sec)->pjs.stub_size[pjsno]
   2764      1.1     skrll 	      = MAX_PUSHJ_STUB_SIZE;
   2765      1.1     skrll 
   2766      1.1     skrll 	  mmix_elf_section_data (sec)->pjs.stubs_size_sum
   2767      1.1     skrll 	    += mmix_elf_section_data (sec)->pjs.stub_size[pjsno];
   2768      1.1     skrll 	  pjsno++;
   2769      1.1     skrll 	  continue;
   2770      1.1     skrll 	}
   2771      1.1     skrll 
   2772      1.1     skrll       /* We're looking at a R_MMIX_BASE_PLUS_OFFSET reloc.  */
   2773      1.1     skrll 
   2774      1.1     skrll       gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono]].value
   2775      1.1     skrll 	= symval + irel->r_addend;
   2776      1.1     skrll       gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono++]].valid = TRUE;
   2777      1.1     skrll       gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
   2778      1.1     skrll     }
   2779      1.1     skrll 
   2780      1.1     skrll   /* Check if that was the last BPO-reloc.  If so, sort the values and
   2781      1.1     skrll      calculate how many registers we need to cover them.  Set the size of
   2782      1.1     skrll      the linker gregs, and if the number of registers changed, indicate
   2783      1.1     skrll      that we need to relax some more because we have more work to do.  */
   2784      1.1     skrll   if (gregdata != NULL
   2785      1.1     skrll       && gregdata->n_remaining_bpo_relocs_this_relaxation_round == 0)
   2786      1.1     skrll     {
   2787      1.1     skrll       size_t i;
   2788      1.1     skrll       bfd_vma prev_base;
   2789  1.1.1.3  christos       size_t regindex;
   2790      1.1     skrll 
   2791      1.1     skrll       /* First, reset the remaining relocs for the next round.  */
   2792      1.1     skrll       gregdata->n_remaining_bpo_relocs_this_relaxation_round
   2793      1.1     skrll 	= gregdata->n_bpo_relocs;
   2794      1.1     skrll 
   2795      1.1     skrll       qsort (gregdata->reloc_request,
   2796      1.1     skrll 	     gregdata->n_max_bpo_relocs,
   2797      1.1     skrll 	     sizeof (struct bpo_reloc_request),
   2798      1.1     skrll 	     bpo_reloc_request_sort_fn);
   2799      1.1     skrll 
   2800      1.1     skrll       /* Recalculate indexes.  When we find a change (however unlikely
   2801      1.1     skrll 	 after the initial iteration), we know we need to relax again,
   2802      1.1     skrll 	 since items in the GREG-array are sorted by increasing value and
   2803      1.1     skrll 	 stored in the relaxation phase.  */
   2804      1.1     skrll       for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
   2805      1.1     skrll 	if (gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
   2806      1.1     skrll 	    != i)
   2807      1.1     skrll 	  {
   2808      1.1     skrll 	    gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
   2809      1.1     skrll 	      = i;
   2810      1.1     skrll 	    *again = TRUE;
   2811      1.1     skrll 	  }
   2812      1.1     skrll 
   2813      1.1     skrll       /* Allocate register numbers (indexing from 0).  Stop at the first
   2814      1.1     skrll 	 non-valid reloc.  */
   2815      1.1     skrll       for (i = 0, regindex = 0, prev_base = gregdata->reloc_request[0].value;
   2816      1.1     skrll 	   i < gregdata->n_bpo_relocs;
   2817      1.1     skrll 	   i++)
   2818      1.1     skrll 	{
   2819      1.1     skrll 	  if (gregdata->reloc_request[i].value > prev_base + 255)
   2820      1.1     skrll 	    {
   2821      1.1     skrll 	      regindex++;
   2822      1.1     skrll 	      prev_base = gregdata->reloc_request[i].value;
   2823      1.1     skrll 	    }
   2824      1.1     skrll 	  gregdata->reloc_request[i].regindex = regindex;
   2825      1.1     skrll 	  gregdata->reloc_request[i].offset
   2826      1.1     skrll 	    = gregdata->reloc_request[i].value - prev_base;
   2827      1.1     skrll 	}
   2828      1.1     skrll 
   2829      1.1     skrll       /* If it's not the same as the last time, we need to relax again,
   2830      1.1     skrll 	 because the size of the section has changed.  I'm not sure we
   2831      1.1     skrll 	 actually need to do any adjustments since the shrinking happens
   2832      1.1     skrll 	 at the start of this section, but better safe than sorry.  */
   2833      1.1     skrll       if (gregdata->n_allocated_bpo_gregs != regindex + 1)
   2834      1.1     skrll 	{
   2835      1.1     skrll 	  gregdata->n_allocated_bpo_gregs = regindex + 1;
   2836      1.1     skrll 	  *again = TRUE;
   2837      1.1     skrll 	}
   2838      1.1     skrll 
   2839      1.1     skrll       bpo_gregs_section->size = (regindex + 1) * 8;
   2840      1.1     skrll     }
   2841      1.1     skrll 
   2842      1.1     skrll   if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
   2843      1.1     skrll     {
   2844      1.1     skrll       if (! link_info->keep_memory)
   2845      1.1     skrll 	free (isymbuf);
   2846      1.1     skrll       else
   2847  1.1.1.6  christos 	{
   2848  1.1.1.6  christos 	  /* Cache the symbols for elf_link_input_bfd.  */
   2849      1.1     skrll 	  symtab_hdr->contents = (unsigned char *) isymbuf;
   2850      1.1     skrll 	}
   2851      1.1     skrll     }
   2852      1.1     skrll 
   2853      1.1     skrll   BFD_ASSERT(pjsno == mmix_elf_section_data (sec)->pjs.n_pushj_relocs);
   2854      1.1     skrll 
   2855      1.1     skrll   if (internal_relocs != NULL
   2856      1.1     skrll       && elf_section_data (sec)->relocs != internal_relocs)
   2857      1.1     skrll     free (internal_relocs);
   2858      1.1     skrll 
   2859      1.1     skrll   if (sec->size < size + mmix_elf_section_data (sec)->pjs.stubs_size_sum)
   2860      1.1     skrll     abort ();
   2861      1.1     skrll 
   2862      1.1     skrll   if (sec->size > size + mmix_elf_section_data (sec)->pjs.stubs_size_sum)
   2863      1.1     skrll     {
   2864      1.1     skrll       sec->size = size + mmix_elf_section_data (sec)->pjs.stubs_size_sum;
   2865      1.1     skrll       *again = TRUE;
   2866      1.1     skrll     }
   2867      1.1     skrll 
   2868      1.1     skrll   return TRUE;
   2869      1.1     skrll 
   2870      1.1     skrll  error_return:
   2871      1.1     skrll   if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
   2872      1.1     skrll     free (isymbuf);
   2873      1.1     skrll   if (internal_relocs != NULL
   2874  1.1.1.6  christos       && elf_section_data (sec)->relocs != internal_relocs)
   2875      1.1     skrll     free (internal_relocs);
   2876      1.1     skrll   return FALSE;
   2877      1.1     skrll }
   2878      1.1     skrll 
   2879      1.1     skrll #define ELF_ARCH		bfd_arch_mmix
   2881      1.1     skrll #define ELF_MACHINE_CODE	EM_MMIX
   2882      1.1     skrll 
   2883      1.1     skrll /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
   2884      1.1     skrll    However, that's too much for something somewhere in the linker part of
   2885      1.1     skrll    BFD; perhaps the start-address has to be a non-zero multiple of this
   2886      1.1     skrll    number, or larger than this number.  The symptom is that the linker
   2887      1.1     skrll    complains: "warning: allocated section `.text' not in segment".  We
   2888      1.1     skrll    settle for 64k; the page-size used in examples is 8k.
   2889      1.1     skrll    #define ELF_MAXPAGESIZE 0x10000
   2890  1.1.1.4  christos 
   2891      1.1     skrll    Unfortunately, this causes excessive padding in the supposedly small
   2892      1.1     skrll    for-education programs that are the expected usage (where people would
   2893      1.1     skrll    inspect output).  We stick to 256 bytes just to have *some* default
   2894      1.1     skrll    alignment.  */
   2895      1.1     skrll #define ELF_MAXPAGESIZE 0x100
   2896      1.1     skrll 
   2897      1.1     skrll #define TARGET_BIG_SYM		mmix_elf64_vec
   2898      1.1     skrll #define TARGET_BIG_NAME		"elf64-mmix"
   2899      1.1     skrll 
   2900      1.1     skrll #define elf_info_to_howto_rel		NULL
   2901      1.1     skrll #define elf_info_to_howto		mmix_info_to_howto_rela
   2902      1.1     skrll #define elf_backend_relocate_section	mmix_elf_relocate_section
   2903      1.1     skrll #define elf_backend_gc_mark_hook	mmix_elf_gc_mark_hook
   2904      1.1     skrll 
   2905      1.1     skrll #define elf_backend_link_output_symbol_hook \
   2906      1.1     skrll 	mmix_elf_link_output_symbol_hook
   2907  1.1.1.6  christos #define elf_backend_add_symbol_hook	mmix_elf_add_symbol_hook
   2908  1.1.1.6  christos 
   2909  1.1.1.6  christos #define elf_backend_check_relocs	mmix_elf_check_relocs
   2910      1.1     skrll #define elf_backend_symbol_processing	mmix_elf_symbol_processing
   2911      1.1     skrll #define elf_backend_omit_section_dynsym \
   2912      1.1     skrll   ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
   2913      1.1     skrll 
   2914      1.1     skrll #define bfd_elf64_bfd_copy_link_hash_symbol_type \
   2915      1.1     skrll   _bfd_generic_copy_link_hash_symbol_type
   2916      1.1     skrll 
   2917      1.1     skrll #define bfd_elf64_bfd_is_local_label_name \
   2918      1.1     skrll 	mmix_elf_is_local_label_name
   2919      1.1     skrll 
   2920      1.1     skrll #define elf_backend_may_use_rel_p	0
   2921      1.1     skrll #define elf_backend_may_use_rela_p	1
   2922      1.1     skrll #define elf_backend_default_use_rela_p	1
   2923      1.1     skrll 
   2924      1.1     skrll #define elf_backend_can_gc_sections	1
   2925      1.1     skrll #define elf_backend_section_from_bfd_section \
   2926                    	mmix_elf_section_from_bfd_section
   2927                    
   2928                    #define bfd_elf64_new_section_hook	mmix_elf_new_section_hook
   2929                    #define bfd_elf64_bfd_final_link	mmix_elf_final_link
   2930                    #define bfd_elf64_bfd_relax_section	mmix_elf_relax_section
   2931                    
   2932                    #include "elf64-target.h"
   2933