Back to index

cell-binutils  2.17cvs20070401
elf64-sh64.c
Go to the documentation of this file.
00001 /* SuperH SH64-specific support for 64-bit ELF
00002    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00003    Free Software Foundation, Inc.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #define SH64_ELF64
00022 
00023 #include "bfd.h"
00024 #include "sysdep.h"
00025 #include "bfdlink.h"
00026 #include "libbfd.h"
00027 #include "elf-bfd.h"
00028 #include "elf/sh.h"
00029 
00030 /* Add a suffix for datalabel indirection symbols.  It must not match any
00031    other symbols; user symbols with or without version or other
00032    decoration.  It must only be used internally and not emitted by any
00033    means.  */
00034 #define DATALABEL_SUFFIX " DL"
00035 
00036 #define GOT_BIAS (-((long)-32768))
00037 
00038 #define PLT_ENTRY_SIZE 64
00039 
00040 /* Return size of a PLT entry.  */
00041 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
00042 
00043 /* Return offset of the PLT0 address in an absolute PLT entry.  */
00044 #define elf_sh64_plt_plt0_offset(info) 32
00045 
00046 /* Return offset of the linker in PLT0 entry.  */
00047 #define elf_sh64_plt0_gotplt_offset(info) 0
00048 
00049 /* Return offset of the trampoline in PLT entry */
00050 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia.  */
00051 
00052 /* Return offset of the symbol in PLT entry.  */
00053 #define elf_sh64_plt_symbol_offset(info) 0
00054 
00055 /* Return offset of the relocation in PLT entry.  */
00056 #define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
00057 
00058 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
00059 
00060 /* The sh linker needs to keep track of the number of relocs that it
00061    decides to copy in check_relocs for each symbol.  This is so that
00062    it can discard PC relative relocs if it doesn't need them when
00063    linking with -Bsymbolic.  We store the information in a field
00064    extending the regular ELF linker hash table.  */
00065 
00066 /* This structure keeps track of the number of PC relative relocs we
00067    have copied for a given symbol.  */
00068 
00069 struct elf_sh64_pcrel_relocs_copied
00070 {
00071   /* Next section.  */
00072   struct elf_sh64_pcrel_relocs_copied *next;
00073   /* A section in dynobj.  */
00074   asection *section;
00075   /* Number of relocs copied in this section.  */
00076   bfd_size_type count;
00077 };
00078 
00079 /* sh ELF linker hash entry.  */
00080 
00081 struct elf_sh64_link_hash_entry
00082 {
00083   struct elf_link_hash_entry root;
00084 
00085   bfd_vma datalabel_got_offset;
00086 
00087   /* Number of PC relative relocs copied for this symbol.  */
00088   struct elf_sh64_pcrel_relocs_copied *pcrel_relocs_copied;
00089 };
00090 
00091 /* sh ELF linker hash table.  */
00092 
00093 struct elf_sh64_link_hash_table
00094 {
00095   struct elf_link_hash_table root;
00096 };
00097 
00098 /* Traverse an sh ELF linker hash table.  */
00099 
00100 #define sh64_elf64_link_hash_traverse(table, func, info)              \
00101   (elf_link_hash_traverse                                      \
00102    (&(table)->root,                                            \
00103     (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
00104     (info)))
00105 
00106 /* Get the sh ELF linker hash table from a link_info structure.  */
00107 
00108 #define sh64_elf64_hash_table(p) \
00109   ((struct elf_sh64_link_hash_table *) ((p)->hash))
00110 
00111 static bfd_reloc_status_type sh_elf64_ignore_reloc
00112   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
00113 static bfd_reloc_status_type sh_elf64_reloc
00114   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
00115 
00116 static reloc_howto_type sh_elf64_howto_table[] = {
00117   /* No relocation.  */
00118   HOWTO (R_SH_NONE,         /* type */
00119         0,                  /* rightshift */
00120         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00121         0,                  /* bitsize */
00122         FALSE,                     /* pc_relative */
00123         0,                  /* bitpos */
00124         complain_overflow_dont, /* complain_on_overflow */
00125         sh_elf64_ignore_reloc,     /* special_function */
00126         "R_SH_NONE",        /* name */
00127         FALSE,                     /* partial_inplace */
00128         0,                  /* src_mask */
00129         0,                  /* dst_mask */
00130         FALSE),             /* pcrel_offset */
00131 
00132   /* 32 bit absolute relocation.  Setting partial_inplace to TRUE and
00133      src_mask to a non-zero value is similar to the COFF toolchain.  */
00134   HOWTO (R_SH_DIR32,        /* type */
00135         0,                  /* rightshift */
00136         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00137         32,                 /* bitsize */
00138         FALSE,                     /* pc_relative */
00139         0,                  /* bitpos */
00140         complain_overflow_bitfield, /* complain_on_overflow */
00141         sh_elf64_reloc,            /* special_function */
00142         "R_SH_DIR32",              /* name */
00143         TRUE,               /* partial_inplace */
00144         0xffffffff,         /* src_mask */
00145         0xffffffff,         /* dst_mask */
00146         FALSE),             /* pcrel_offset */
00147 
00148   /* 32 bit PC relative relocation.  */
00149   HOWTO (R_SH_REL32,        /* type */
00150         0,                  /* rightshift */
00151         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00152         32,                 /* bitsize */
00153         TRUE,               /* pc_relative */
00154         0,                  /* bitpos */
00155         complain_overflow_signed, /* complain_on_overflow */
00156         sh_elf64_ignore_reloc,     /* special_function */
00157         "R_SH_REL32",              /* name */
00158         FALSE,                     /* partial_inplace */
00159         0,                  /* src_mask */
00160         0xffffffff,         /* dst_mask */
00161         TRUE),                     /* pcrel_offset */
00162 
00163   /* For 32-bit sh, this is R_SH_DIR8WPN.  */
00164   EMPTY_HOWTO (3),
00165 
00166   /* For 32-bit sh, this is R_SH_IND12W.  */
00167   EMPTY_HOWTO (4),
00168 
00169   /* For 32-bit sh, this is R_SH_DIR8WPL.  */
00170   EMPTY_HOWTO (5),
00171 
00172   /* For 32-bit sh, this is R_SH_DIR8WPZ.  */
00173   EMPTY_HOWTO (6),
00174 
00175   /* For 32-bit sh, this is R_SH_DIR8BP.  */
00176   EMPTY_HOWTO (7),
00177 
00178   /* For 32-bit sh, this is R_SH_DIR8W.  */
00179   EMPTY_HOWTO (8),
00180 
00181   /* For 32-bit sh, this is R_SH_DIR8L.  */
00182   EMPTY_HOWTO (9),
00183 
00184   EMPTY_HOWTO (10),
00185   EMPTY_HOWTO (11),
00186   EMPTY_HOWTO (12),
00187   EMPTY_HOWTO (13),
00188   EMPTY_HOWTO (14),
00189   EMPTY_HOWTO (15),
00190   EMPTY_HOWTO (16),
00191   EMPTY_HOWTO (17),
00192   EMPTY_HOWTO (18),
00193   EMPTY_HOWTO (19),
00194   EMPTY_HOWTO (20),
00195   EMPTY_HOWTO (21),
00196   EMPTY_HOWTO (22),
00197   EMPTY_HOWTO (23),
00198   EMPTY_HOWTO (24),
00199 
00200   /* The remaining relocs are a GNU extension used for relaxing.  The
00201      final pass of the linker never needs to do anything with any of
00202      these relocs.  Any required operations are handled by the
00203      relaxation code.  */
00204 
00205   /* A 16 bit switch table entry.  This is generated for an expression
00206      such as ``.word L1 - L2''.  The offset holds the difference
00207      between the reloc address and L2.  */
00208   HOWTO (R_SH_SWITCH16,            /* type */
00209         0,                  /* rightshift */
00210         1,                  /* size (0 = byte, 1 = short, 2 = long) */
00211         16,                 /* bitsize */
00212         FALSE,                     /* pc_relative */
00213         0,                  /* bitpos */
00214         complain_overflow_unsigned, /* complain_on_overflow */
00215         sh_elf64_ignore_reloc,     /* special_function */
00216         "R_SH_SWITCH16",    /* name */
00217         FALSE,                     /* partial_inplace */
00218         0,                  /* src_mask */
00219         0,                  /* dst_mask */
00220         TRUE),                     /* pcrel_offset */
00221 
00222   /* A 32 bit switch table entry.  This is generated for an expression
00223      such as ``.long L1 - L2''.  The offset holds the difference
00224      between the reloc address and L2.  */
00225   HOWTO (R_SH_SWITCH32,            /* type */
00226         0,                  /* rightshift */
00227         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00228         32,                 /* bitsize */
00229         FALSE,                     /* pc_relative */
00230         0,                  /* bitpos */
00231         complain_overflow_unsigned, /* complain_on_overflow */
00232         sh_elf64_ignore_reloc,     /* special_function */
00233         "R_SH_SWITCH32",    /* name */
00234         FALSE,                     /* partial_inplace */
00235         0,                  /* src_mask */
00236         0,                  /* dst_mask */
00237         TRUE),                     /* pcrel_offset */
00238 
00239   /* For 32-bit sh, this is R_SH_USES.  */
00240   EMPTY_HOWTO (27),
00241 
00242   /* For 32-bit sh, this is R_SH_COUNT.  */
00243   EMPTY_HOWTO (28),
00244 
00245   /* For 32-bit sh, this is R_SH_ALIGN.  FIXME: For linker relaxation,
00246      this might be emitted.  When linker relaxation is implemented, we
00247      might want to use it.  */
00248   EMPTY_HOWTO (29),
00249 
00250   /* For 32-bit sh, this is R_SH_CODE.  FIXME: For linker relaxation,
00251      this might be emitted.  When linker relaxation is implemented, we
00252      might want to use it.  */
00253   EMPTY_HOWTO (30),
00254 
00255   /* For 32-bit sh, this is R_SH_DATA.  FIXME: For linker relaxation,
00256      this might be emitted.  When linker relaxation is implemented, we
00257      might want to use it.  */
00258   EMPTY_HOWTO (31),
00259 
00260   /* For 32-bit sh, this is R_SH_LABEL.  FIXME: For linker relaxation,
00261      this might be emitted.  When linker relaxation is implemented, we
00262      might want to use it.  */
00263   EMPTY_HOWTO (32),
00264 
00265   /* An 8 bit switch table entry.  This is generated for an expression
00266      such as ``.word L1 - L2''.  The offset holds the difference
00267      between the reloc address and L2.  */
00268   HOWTO (R_SH_SWITCH8,             /* type */
00269         0,                  /* rightshift */
00270         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00271         8,                  /* bitsize */
00272         FALSE,                     /* pc_relative */
00273         0,                  /* bitpos */
00274         complain_overflow_unsigned, /* complain_on_overflow */
00275         sh_elf64_ignore_reloc,     /* special_function */
00276         "R_SH_SWITCH8",     /* name */
00277         FALSE,                     /* partial_inplace */
00278         0,                  /* src_mask */
00279         0,                  /* dst_mask */
00280         TRUE),                     /* pcrel_offset */
00281 
00282   /* GNU extension to record C++ vtable hierarchy */
00283   HOWTO (R_SH_GNU_VTINHERIT, /* type */
00284          0,                     /* rightshift */
00285          2,                     /* size (0 = byte, 1 = short, 2 = long) */
00286          0,                     /* bitsize */
00287          FALSE,                 /* pc_relative */
00288          0,                     /* bitpos */
00289          complain_overflow_dont, /* complain_on_overflow */
00290          NULL,                  /* special_function */
00291          "R_SH_GNU_VTINHERIT", /* name */
00292          FALSE,                 /* partial_inplace */
00293          0,                     /* src_mask */
00294          0,                     /* dst_mask */
00295          FALSE),                /* pcrel_offset */
00296 
00297   /* GNU extension to record C++ vtable member usage */
00298   HOWTO (R_SH_GNU_VTENTRY,     /* type */
00299          0,                     /* rightshift */
00300          2,                     /* size (0 = byte, 1 = short, 2 = long) */
00301          0,                     /* bitsize */
00302          FALSE,                 /* pc_relative */
00303          0,                     /* bitpos */
00304          complain_overflow_dont, /* complain_on_overflow */
00305          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
00306          "R_SH_GNU_VTENTRY",   /* name */
00307          FALSE,                 /* partial_inplace */
00308          0,                     /* src_mask */
00309          0,                     /* dst_mask */
00310          FALSE),                /* pcrel_offset */
00311 
00312   /* For 32-bit sh, this is R_SH_LOOP_START.  */
00313   EMPTY_HOWTO (36),
00314 
00315   /* For 32-bit sh, this is R_SH_LOOP_END.  */
00316   EMPTY_HOWTO (37),
00317 
00318   EMPTY_HOWTO (38),
00319   EMPTY_HOWTO (39),
00320   EMPTY_HOWTO (40),
00321   EMPTY_HOWTO (41),
00322   EMPTY_HOWTO (42),
00323   EMPTY_HOWTO (43),
00324   EMPTY_HOWTO (44),
00325 
00326   /* Used in SHLLI.L and SHLRI.L.  */
00327   HOWTO (R_SH_DIR5U,        /* type */
00328         0,                  /* rightshift */
00329         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00330         5,                  /* bitsize */
00331         FALSE,                     /* pc_relative */
00332         10,                 /* bitpos */
00333         complain_overflow_unsigned, /* complain_on_overflow */
00334         bfd_elf_generic_reloc,     /* special_function */
00335         "R_SH_DIR5U",              /* name */
00336         FALSE,                     /* partial_inplace */
00337         0,                  /* src_mask */
00338         0xfc00,             /* dst_mask */
00339         FALSE),                    /* pcrel_offset */
00340 
00341   /* Used in SHARI, SHLLI et al.  */
00342   HOWTO (R_SH_DIR6U,        /* type */
00343         0,                  /* rightshift */
00344         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00345         6,                  /* bitsize */
00346         FALSE,                     /* pc_relative */
00347         10,                 /* bitpos */
00348         complain_overflow_unsigned, /* complain_on_overflow */
00349         bfd_elf_generic_reloc,     /* special_function */
00350         "R_SH_DIR6U",              /* name */
00351         FALSE,                     /* partial_inplace */
00352         0,                  /* src_mask */
00353         0xfc00,             /* dst_mask */
00354         FALSE),                    /* pcrel_offset */
00355 
00356   /* Used in BxxI, LDHI.L et al.  */
00357   HOWTO (R_SH_DIR6S,        /* type */
00358         0,                  /* rightshift */
00359         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00360         6,                  /* bitsize */
00361         FALSE,                     /* pc_relative */
00362         10,                 /* bitpos */
00363         complain_overflow_signed, /* complain_on_overflow */
00364         bfd_elf_generic_reloc,     /* special_function */
00365         "R_SH_DIR6S",              /* name */
00366         FALSE,                     /* partial_inplace */
00367         0,                  /* src_mask */
00368         0xfc00,             /* dst_mask */
00369         FALSE),                    /* pcrel_offset */
00370 
00371   /* Used in ADDI, ANDI et al.  */
00372   HOWTO (R_SH_DIR10S,              /* type */
00373         0,                  /* rightshift */
00374         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00375         10,                 /* bitsize */
00376         FALSE,                     /* pc_relative */
00377         10,                 /* bitpos */
00378         complain_overflow_signed, /* complain_on_overflow */
00379         bfd_elf_generic_reloc,     /* special_function */
00380         "R_SH_DIR10S",             /* name */
00381         FALSE,                     /* partial_inplace */
00382         0,                  /* src_mask */
00383         0xffc00,            /* dst_mask */
00384         FALSE),                    /* pcrel_offset */
00385 
00386   /* Used in LD.UW, ST.W et al.  */
00387   HOWTO (R_SH_DIR10SW,      /* type */
00388         1,                  /* rightshift */
00389         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00390         11,                 /* bitsize */
00391         FALSE,                     /* pc_relative */
00392         10,                 /* bitpos */
00393         complain_overflow_signed, /* complain_on_overflow */
00394         bfd_elf_generic_reloc,     /* special_function */
00395         "R_SH_DIR10SW",     /* name */
00396         FALSE,                     /* partial_inplace */
00397         0,                  /* src_mask */
00398         0xffc00,            /* dst_mask */
00399         FALSE),                    /* pcrel_offset */
00400 
00401   /* Used in LD.L, FLD.S et al.  */
00402   HOWTO (R_SH_DIR10SL,      /* type */
00403         2,                  /* rightshift */
00404         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00405         12,                 /* bitsize */
00406         FALSE,                     /* pc_relative */
00407         10,                 /* bitpos */
00408         complain_overflow_signed, /* complain_on_overflow */
00409         bfd_elf_generic_reloc,     /* special_function */
00410         "R_SH_DIR10SL",     /* name */
00411         FALSE,                     /* partial_inplace */
00412         0,                  /* src_mask */
00413         0xffc00,            /* dst_mask */
00414         FALSE),                    /* pcrel_offset */
00415 
00416   /* Used in FLD.D, FST.P et al.  */
00417   HOWTO (R_SH_DIR10SQ,      /* type */
00418         3,                  /* rightshift */
00419         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00420         13,                 /* bitsize */
00421         FALSE,                     /* pc_relative */
00422         10,                 /* bitpos */
00423         complain_overflow_signed, /* complain_on_overflow */
00424         bfd_elf_generic_reloc,     /* special_function */
00425         "R_SH_DIR10SQ",     /* name */
00426         FALSE,                     /* partial_inplace */
00427         0,                  /* src_mask */
00428         0xffc00,            /* dst_mask */
00429         FALSE),                    /* pcrel_offset */
00430 
00431   EMPTY_HOWTO (52),
00432   EMPTY_HOWTO (53),
00433   EMPTY_HOWTO (54),
00434   EMPTY_HOWTO (55),
00435   EMPTY_HOWTO (56),
00436   EMPTY_HOWTO (57),
00437   EMPTY_HOWTO (58),
00438   EMPTY_HOWTO (59),
00439   EMPTY_HOWTO (60),
00440   EMPTY_HOWTO (61),
00441   EMPTY_HOWTO (62),
00442   EMPTY_HOWTO (63),
00443   EMPTY_HOWTO (64),
00444   EMPTY_HOWTO (65),
00445   EMPTY_HOWTO (66),
00446   EMPTY_HOWTO (67),
00447   EMPTY_HOWTO (68),
00448   EMPTY_HOWTO (69),
00449   EMPTY_HOWTO (70),
00450   EMPTY_HOWTO (71),
00451   EMPTY_HOWTO (72),
00452   EMPTY_HOWTO (73),
00453   EMPTY_HOWTO (74),
00454   EMPTY_HOWTO (75),
00455   EMPTY_HOWTO (76),
00456   EMPTY_HOWTO (77),
00457   EMPTY_HOWTO (78),
00458   EMPTY_HOWTO (79),
00459   EMPTY_HOWTO (80),
00460   EMPTY_HOWTO (81),
00461   EMPTY_HOWTO (82),
00462   EMPTY_HOWTO (83),
00463   EMPTY_HOWTO (84),
00464   EMPTY_HOWTO (85),
00465   EMPTY_HOWTO (86),
00466   EMPTY_HOWTO (87),
00467   EMPTY_HOWTO (88),
00468   EMPTY_HOWTO (89),
00469   EMPTY_HOWTO (90),
00470   EMPTY_HOWTO (91),
00471   EMPTY_HOWTO (92),
00472   EMPTY_HOWTO (93),
00473   EMPTY_HOWTO (94),
00474   EMPTY_HOWTO (95),
00475   EMPTY_HOWTO (96),
00476   EMPTY_HOWTO (97),
00477   EMPTY_HOWTO (98),
00478   EMPTY_HOWTO (99),
00479   EMPTY_HOWTO (100),
00480   EMPTY_HOWTO (101),
00481   EMPTY_HOWTO (102),
00482   EMPTY_HOWTO (103),
00483   EMPTY_HOWTO (104),
00484   EMPTY_HOWTO (105),
00485   EMPTY_HOWTO (106),
00486   EMPTY_HOWTO (107),
00487   EMPTY_HOWTO (108),
00488   EMPTY_HOWTO (109),
00489   EMPTY_HOWTO (110),
00490   EMPTY_HOWTO (111),
00491   EMPTY_HOWTO (112),
00492   EMPTY_HOWTO (113),
00493   EMPTY_HOWTO (114),
00494   EMPTY_HOWTO (115),
00495   EMPTY_HOWTO (116),
00496   EMPTY_HOWTO (117),
00497   EMPTY_HOWTO (118),
00498   EMPTY_HOWTO (119),
00499   EMPTY_HOWTO (120),
00500   EMPTY_HOWTO (121),
00501   EMPTY_HOWTO (122),
00502   EMPTY_HOWTO (123),
00503   EMPTY_HOWTO (124),
00504   EMPTY_HOWTO (125),
00505   EMPTY_HOWTO (126),
00506   EMPTY_HOWTO (127),
00507   EMPTY_HOWTO (128),
00508   EMPTY_HOWTO (129),
00509   EMPTY_HOWTO (130),
00510   EMPTY_HOWTO (131),
00511   EMPTY_HOWTO (132),
00512   EMPTY_HOWTO (133),
00513   EMPTY_HOWTO (134),
00514   EMPTY_HOWTO (135),
00515   EMPTY_HOWTO (136),
00516   EMPTY_HOWTO (137),
00517   EMPTY_HOWTO (138),
00518   EMPTY_HOWTO (139),
00519   EMPTY_HOWTO (140),
00520   EMPTY_HOWTO (141),
00521   EMPTY_HOWTO (142),
00522   EMPTY_HOWTO (143),
00523   EMPTY_HOWTO (144),
00524   EMPTY_HOWTO (145),
00525   EMPTY_HOWTO (146),
00526   EMPTY_HOWTO (147),
00527   EMPTY_HOWTO (148),
00528   EMPTY_HOWTO (149),
00529   EMPTY_HOWTO (150),
00530   EMPTY_HOWTO (151),
00531   EMPTY_HOWTO (152),
00532   EMPTY_HOWTO (153),
00533   EMPTY_HOWTO (154),
00534   EMPTY_HOWTO (155),
00535   EMPTY_HOWTO (156),
00536   EMPTY_HOWTO (157),
00537   EMPTY_HOWTO (158),
00538   EMPTY_HOWTO (159),
00539 
00540   /* Relocs for dynamic linking for 32-bit SH would follow.  We don't have
00541      any dynamic linking support for 64-bit SH at present.  */
00542 
00543   EMPTY_HOWTO (160),
00544   EMPTY_HOWTO (161),
00545   EMPTY_HOWTO (162),
00546   EMPTY_HOWTO (163),
00547   EMPTY_HOWTO (164),
00548   EMPTY_HOWTO (165),
00549   EMPTY_HOWTO (166),
00550   EMPTY_HOWTO (167),
00551   EMPTY_HOWTO (168),
00552 
00553   /* Back to SH5 relocations.  */
00554   /* Used in MOVI and SHORI (x & 65536).  */
00555   HOWTO (R_SH_GOT_LOW16,    /* type */
00556         0,                  /* rightshift */
00557         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00558         64,                 /* bitsize */
00559         FALSE,                     /* pc_relative */
00560         10,                 /* bitpos */
00561         complain_overflow_dont, /* complain_on_overflow */
00562         bfd_elf_generic_reloc,     /* special_function */
00563         "R_SH_GOT_LOW16",          /* name */
00564         FALSE,                     /* partial_inplace */
00565         0,                  /* src_mask */
00566         0x3fffc00,          /* dst_mask */
00567         FALSE),                    /* pcrel_offset */
00568 
00569   /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
00570   HOWTO (R_SH_GOT_MEDLOW16, /* type */
00571         16,                 /* rightshift */
00572         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00573         64,                 /* bitsize */
00574         FALSE,                     /* pc_relative */
00575         10,                 /* bitpos */
00576         complain_overflow_dont, /* complain_on_overflow */
00577         bfd_elf_generic_reloc,     /* special_function */
00578         "R_SH_GOT_MEDLOW16",       /* name */
00579         FALSE,                     /* partial_inplace */
00580         0,                  /* src_mask */
00581         0x3fffc00,          /* dst_mask */
00582         FALSE),                    /* pcrel_offset */
00583 
00584   /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
00585   HOWTO (R_SH_GOT_MEDHI16,  /* type */
00586         32,                 /* rightshift */
00587         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00588         64,                 /* bitsize */
00589         FALSE,                     /* pc_relative */
00590         10,                 /* bitpos */
00591         complain_overflow_dont, /* complain_on_overflow */
00592         bfd_elf_generic_reloc,     /* special_function */
00593         "R_SH_GOT_MEDHI16", /* name */
00594         FALSE,                     /* partial_inplace */
00595         0,                  /* src_mask */
00596         0x3fffc00,          /* dst_mask */
00597         FALSE),                    /* pcrel_offset */
00598 
00599   /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
00600   HOWTO (R_SH_GOT_HI16,            /* type */
00601         48,                 /* rightshift */
00602         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00603         64,                 /* bitsize */
00604         FALSE,                     /* pc_relative */
00605         10,                 /* bitpos */
00606         complain_overflow_dont, /* complain_on_overflow */
00607         bfd_elf_generic_reloc,     /* special_function */
00608         "R_SH_GOT_HI16",    /* name */
00609         FALSE,                     /* partial_inplace */
00610         0,                  /* src_mask */
00611         0x3fffc00,          /* dst_mask */
00612         FALSE),                    /* pcrel_offset */
00613 
00614   /* Used in MOVI and SHORI (x & 65536).  */
00615   HOWTO (R_SH_GOTPLT_LOW16, /* type */
00616         0,                  /* rightshift */
00617         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00618         64,                 /* bitsize */
00619         FALSE,                     /* pc_relative */
00620         10,                 /* bitpos */
00621         complain_overflow_dont, /* complain_on_overflow */
00622         bfd_elf_generic_reloc,     /* special_function */
00623         "R_SH_GOTPLT_LOW16",   /* name */
00624         FALSE,                     /* partial_inplace */
00625         0,                  /* src_mask */
00626         0x3fffc00,          /* dst_mask */
00627         FALSE),                    /* pcrel_offset */
00628 
00629   /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
00630   HOWTO (R_SH_GOTPLT_MEDLOW16,     /* type */
00631         16,                 /* rightshift */
00632         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00633         64,                 /* bitsize */
00634         FALSE,                     /* pc_relative */
00635         10,                 /* bitpos */
00636         complain_overflow_dont, /* complain_on_overflow */
00637         bfd_elf_generic_reloc,     /* special_function */
00638         "R_SH_GOTPLT_MEDLOW16", /* name */
00639         FALSE,                     /* partial_inplace */
00640         0,                  /* src_mask */
00641         0x3fffc00,          /* dst_mask */
00642         FALSE),                    /* pcrel_offset */
00643 
00644   /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
00645   HOWTO (R_SH_GOTPLT_MEDHI16,      /* type */
00646         32,                 /* rightshift */
00647         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00648         64,                 /* bitsize */
00649         FALSE,                     /* pc_relative */
00650         10,                 /* bitpos */
00651         complain_overflow_dont, /* complain_on_overflow */
00652         bfd_elf_generic_reloc,     /* special_function */
00653         "R_SH_GOTPLT_MEDHI16",     /* name */
00654         FALSE,                     /* partial_inplace */
00655         0,                  /* src_mask */
00656         0x3fffc00,          /* dst_mask */
00657         FALSE),                    /* pcrel_offset */
00658 
00659   /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
00660   HOWTO (R_SH_GOTPLT_HI16,  /* type */
00661         48,                 /* rightshift */
00662         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00663         64,                 /* bitsize */
00664         FALSE,                     /* pc_relative */
00665         10,                 /* bitpos */
00666         complain_overflow_dont, /* complain_on_overflow */
00667         bfd_elf_generic_reloc,     /* special_function */
00668         "R_SH_GOTPLT_HI16", /* name */
00669         FALSE,                     /* partial_inplace */
00670         0,                  /* src_mask */
00671         0x3fffc00,          /* dst_mask */
00672         FALSE),                    /* pcrel_offset */
00673 
00674   /* Used in MOVI and SHORI (x & 65536).  */
00675   HOWTO (R_SH_PLT_LOW16,    /* type */
00676         0,                  /* rightshift */
00677         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00678         64,                 /* bitsize */
00679         TRUE,               /* pc_relative */
00680         10,                 /* bitpos */
00681         complain_overflow_dont, /* complain_on_overflow */
00682         bfd_elf_generic_reloc,     /* special_function */
00683         "R_SH_PLT_LOW16",          /* name */
00684         FALSE,                     /* partial_inplace */
00685         0,                  /* src_mask */
00686         0x3fffc00,          /* dst_mask */
00687         TRUE),                            /* pcrel_offset */
00688 
00689   /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
00690   HOWTO (R_SH_PLT_MEDLOW16, /* type */
00691         16,                 /* rightshift */
00692         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00693         64,                 /* bitsize */
00694         TRUE,               /* pc_relative */
00695         10,                 /* bitpos */
00696         complain_overflow_dont, /* complain_on_overflow */
00697         bfd_elf_generic_reloc,     /* special_function */
00698         "R_SH_PLT_MEDLOW16",       /* name */
00699         FALSE,                     /* partial_inplace */
00700         0,                  /* src_mask */
00701         0x3fffc00,          /* dst_mask */
00702         TRUE),                            /* pcrel_offset */
00703 
00704   /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
00705   HOWTO (R_SH_PLT_MEDHI16,  /* type */
00706         32,                 /* rightshift */
00707         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00708         64,                 /* bitsize */
00709         TRUE,               /* pc_relative */
00710         10,                 /* bitpos */
00711         complain_overflow_dont, /* complain_on_overflow */
00712         bfd_elf_generic_reloc,     /* special_function */
00713         "R_SH_PLT_MEDHI16", /* name */
00714         FALSE,                     /* partial_inplace */
00715         0,                  /* src_mask */
00716         0x3fffc00,          /* dst_mask */
00717         TRUE),                            /* pcrel_offset */
00718 
00719   /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
00720   HOWTO (R_SH_PLT_HI16,            /* type */
00721         48,                 /* rightshift */
00722         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00723         64,                 /* bitsize */
00724         TRUE,               /* pc_relative */
00725         10,                 /* bitpos */
00726         complain_overflow_dont, /* complain_on_overflow */
00727         bfd_elf_generic_reloc,     /* special_function */
00728         "R_SH_PLT_HI16",    /* name */
00729         FALSE,                     /* partial_inplace */
00730         0,                  /* src_mask */
00731         0x3fffc00,          /* dst_mask */
00732         TRUE),                            /* pcrel_offset */
00733 
00734   /* Used in MOVI and SHORI (x & 65536).  */
00735   HOWTO (R_SH_GOTOFF_LOW16, /* type */
00736         0,                  /* rightshift */
00737         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00738         64,                 /* bitsize */
00739         FALSE,                     /* pc_relative */
00740         10,                 /* bitpos */
00741         complain_overflow_dont, /* complain_on_overflow */
00742         bfd_elf_generic_reloc,     /* special_function */
00743         "R_SH_GOTOFF_LOW16",   /* name */
00744         FALSE,                     /* partial_inplace */
00745         0,                  /* src_mask */
00746         0x3fffc00,          /* dst_mask */
00747         FALSE),                    /* pcrel_offset */
00748 
00749   /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
00750   HOWTO (R_SH_GOTOFF_MEDLOW16,     /* type */
00751         16,                 /* rightshift */
00752         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00753         64,                 /* bitsize */
00754         FALSE,                     /* pc_relative */
00755         10,                 /* bitpos */
00756         complain_overflow_dont, /* complain_on_overflow */
00757         bfd_elf_generic_reloc,     /* special_function */
00758         "R_SH_GOTOFF_MEDLOW16", /* name */
00759         FALSE,                     /* partial_inplace */
00760         0,                  /* src_mask */
00761         0x3fffc00,          /* dst_mask */
00762         FALSE),                    /* pcrel_offset */
00763 
00764   /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
00765   HOWTO (R_SH_GOTOFF_MEDHI16,      /* type */
00766         32,                 /* rightshift */
00767         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00768         64,                 /* bitsize */
00769         FALSE,                     /* pc_relative */
00770         10,                 /* bitpos */
00771         complain_overflow_dont, /* complain_on_overflow */
00772         bfd_elf_generic_reloc,     /* special_function */
00773         "R_SH_GOTOFF_MEDHI16",     /* name */
00774         FALSE,                     /* partial_inplace */
00775         0,                  /* src_mask */
00776         0x3fffc00,          /* dst_mask */
00777         FALSE),                    /* pcrel_offset */
00778 
00779   /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
00780   HOWTO (R_SH_GOTOFF_HI16,  /* type */
00781         48,                 /* rightshift */
00782         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00783         64,                 /* bitsize */
00784         FALSE,                     /* pc_relative */
00785         10,                 /* bitpos */
00786         complain_overflow_dont, /* complain_on_overflow */
00787         bfd_elf_generic_reloc,     /* special_function */
00788         "R_SH_GOTOFF_HI16", /* name */
00789         FALSE,                     /* partial_inplace */
00790         0,                  /* src_mask */
00791         0x3fffc00,          /* dst_mask */
00792         FALSE),                    /* pcrel_offset */
00793 
00794   /* Used in MOVI and SHORI (x & 65536).  */
00795   HOWTO (R_SH_GOTPC_LOW16,  /* type */
00796         0,                  /* rightshift */
00797         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00798         64,                 /* bitsize */
00799         TRUE,               /* pc_relative */
00800         10,                 /* bitpos */
00801         complain_overflow_dont, /* complain_on_overflow */
00802         bfd_elf_generic_reloc,     /* special_function */
00803         "R_SH_GOTPC_LOW16",    /* name */
00804         FALSE,                     /* partial_inplace */
00805         0,                  /* src_mask */
00806         0x3fffc00,          /* dst_mask */
00807         TRUE),                            /* pcrel_offset */
00808 
00809   /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
00810   HOWTO (R_SH_GOTPC_MEDLOW16,      /* type */
00811         16,                 /* rightshift */
00812         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00813         64,                 /* bitsize */
00814         TRUE,               /* pc_relative */
00815         10,                 /* bitpos */
00816         complain_overflow_dont, /* complain_on_overflow */
00817         bfd_elf_generic_reloc,     /* special_function */
00818         "R_SH_GOTPC_MEDLOW16", /* name */
00819         FALSE,                     /* partial_inplace */
00820         0,                  /* src_mask */
00821         0x3fffc00,          /* dst_mask */
00822         TRUE),                            /* pcrel_offset */
00823 
00824   /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
00825   HOWTO (R_SH_GOTPC_MEDHI16,       /* type */
00826         32,                 /* rightshift */
00827         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00828         64,                 /* bitsize */
00829         TRUE,               /* pc_relative */
00830         10,                 /* bitpos */
00831         complain_overflow_dont, /* complain_on_overflow */
00832         bfd_elf_generic_reloc,     /* special_function */
00833         "R_SH_GOTPC_MEDHI16",      /* name */
00834         FALSE,                     /* partial_inplace */
00835         0,                  /* src_mask */
00836         0x3fffc00,          /* dst_mask */
00837         TRUE),                            /* pcrel_offset */
00838 
00839   /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
00840   HOWTO (R_SH_GOTPC_HI16,   /* type */
00841         48,                 /* rightshift */
00842         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00843         64,                 /* bitsize */
00844         TRUE,               /* pc_relative */
00845         10,                 /* bitpos */
00846         complain_overflow_dont, /* complain_on_overflow */
00847         bfd_elf_generic_reloc,     /* special_function */
00848         "R_SH_GOTPC_HI16",  /* name */
00849         FALSE,                     /* partial_inplace */
00850         0,                  /* src_mask */
00851         0x3fffc00,          /* dst_mask */
00852         TRUE),                            /* pcrel_offset */
00853 
00854   /* Used in LD.L, FLD.S et al.  */
00855   HOWTO (R_SH_GOT10BY4,            /* type */
00856         2,                  /* rightshift */
00857         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00858         12,                 /* bitsize */
00859         FALSE,                     /* pc_relative */
00860         10,                 /* bitpos */
00861         complain_overflow_signed, /* complain_on_overflow */
00862         bfd_elf_generic_reloc,     /* special_function */
00863         "R_SH_GOT10BY4",    /* name */
00864         FALSE,                     /* partial_inplace */
00865         0,                  /* src_mask */
00866         0xffc00,            /* dst_mask */
00867         FALSE),                    /* pcrel_offset */
00868 
00869   /* Used in LD.L, FLD.S et al.  */
00870   HOWTO (R_SH_GOTPLT10BY4,  /* type */
00871         2,                  /* rightshift */
00872         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00873         12,                 /* bitsize */
00874         FALSE,                     /* pc_relative */
00875         10,                 /* bitpos */
00876         complain_overflow_signed, /* complain_on_overflow */
00877         bfd_elf_generic_reloc,     /* special_function */
00878         "R_SH_GOTPLT10BY4", /* name */
00879         FALSE,                     /* partial_inplace */
00880         0,                  /* src_mask */
00881         0xffc00,            /* dst_mask */
00882         FALSE),                    /* pcrel_offset */
00883 
00884   /* Used in FLD.D, FST.P et al.  */
00885   HOWTO (R_SH_GOT10BY8,            /* type */
00886         3,                  /* rightshift */
00887         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00888         13,                 /* bitsize */
00889         FALSE,                     /* pc_relative */
00890         10,                 /* bitpos */
00891         complain_overflow_signed, /* complain_on_overflow */
00892         bfd_elf_generic_reloc,     /* special_function */
00893         "R_SH_GOT10BY8",    /* name */
00894         FALSE,                     /* partial_inplace */
00895         0,                  /* src_mask */
00896         0xffc00,            /* dst_mask */
00897         FALSE),                    /* pcrel_offset */
00898 
00899   /* Used in FLD.D, FST.P et al.  */
00900   HOWTO (R_SH_GOTPLT10BY8,  /* type */
00901         3,                  /* rightshift */
00902         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00903         13,                 /* bitsize */
00904         FALSE,                     /* pc_relative */
00905         10,                 /* bitpos */
00906         complain_overflow_signed, /* complain_on_overflow */
00907         bfd_elf_generic_reloc,     /* special_function */
00908         "R_SH_GOTPLT10BY8", /* name */
00909         FALSE,                     /* partial_inplace */
00910         0,                  /* src_mask */
00911         0xffc00,            /* dst_mask */
00912         FALSE),                    /* pcrel_offset */
00913 
00914   HOWTO (R_SH_COPY64,              /* type */
00915         0,                  /* rightshift */
00916         4,                  /* size (0 = byte, 1 = short, 2 = long) */
00917         64,                 /* bitsize */
00918         FALSE,                     /* pc_relative */
00919         0,                  /* bitpos */
00920         complain_overflow_dont, /* complain_on_overflow */
00921         bfd_elf_generic_reloc,     /* special_function */
00922         "R_SH_COPY64",      /* name */
00923         FALSE,                     /* partial_inplace */
00924         0,                  /* src_mask */
00925         ((bfd_vma) 0) - 1,  /* dst_mask */
00926         FALSE),                    /* pcrel_offset */
00927 
00928   HOWTO (R_SH_GLOB_DAT64,   /* type */
00929         0,                  /* rightshift */
00930         4,                  /* size (0 = byte, 1 = short, 2 = long) */
00931         64,                 /* bitsize */
00932         FALSE,                     /* pc_relative */
00933         0,                  /* bitpos */
00934         complain_overflow_dont, /* complain_on_overflow */
00935         bfd_elf_generic_reloc,     /* special_function */
00936         "R_SH_GLOB_DAT64",  /* name */
00937         FALSE,                     /* partial_inplace */
00938         0,                  /* src_mask */
00939         ((bfd_vma) 0) - 1,  /* dst_mask */
00940         FALSE),                    /* pcrel_offset */
00941 
00942   HOWTO (R_SH_JMP_SLOT64,   /* type */
00943         0,                  /* rightshift */
00944         4,                  /* size (0 = byte, 1 = short, 2 = long) */
00945         64,                 /* bitsize */
00946         FALSE,                     /* pc_relative */
00947         0,                  /* bitpos */
00948         complain_overflow_dont, /* complain_on_overflow */
00949         bfd_elf_generic_reloc,     /* special_function */
00950         "R_SH_JMP_SLOT64",  /* name */
00951         FALSE,                     /* partial_inplace */
00952         0,                  /* src_mask */
00953         ((bfd_vma) 0) - 1,  /* dst_mask */
00954         FALSE),                    /* pcrel_offset */
00955 
00956   HOWTO (R_SH_RELATIVE64,   /* type */
00957         0,                  /* rightshift */
00958         4,                  /* size (0 = byte, 1 = short, 2 = long) */
00959         64,                 /* bitsize */
00960         FALSE,                     /* pc_relative */
00961         0,                  /* bitpos */
00962         complain_overflow_dont, /* complain_on_overflow */
00963         bfd_elf_generic_reloc,     /* special_function */
00964         "R_SH_RELATIVE64",  /* name */
00965         FALSE,                     /* partial_inplace */
00966         0,                  /* src_mask */
00967         ((bfd_vma) 0) - 1,  /* dst_mask */
00968         FALSE),                    /* pcrel_offset */
00969 
00970   EMPTY_HOWTO (197),
00971   EMPTY_HOWTO (198),
00972   EMPTY_HOWTO (199),
00973   EMPTY_HOWTO (200),
00974   EMPTY_HOWTO (201),
00975   EMPTY_HOWTO (202),
00976   EMPTY_HOWTO (203),
00977   EMPTY_HOWTO (204),
00978   EMPTY_HOWTO (205),
00979   EMPTY_HOWTO (206),
00980   EMPTY_HOWTO (207),
00981   EMPTY_HOWTO (208),
00982   EMPTY_HOWTO (209),
00983   EMPTY_HOWTO (210),
00984   EMPTY_HOWTO (211),
00985   EMPTY_HOWTO (212),
00986   EMPTY_HOWTO (213),
00987   EMPTY_HOWTO (214),
00988   EMPTY_HOWTO (215),
00989   EMPTY_HOWTO (216),
00990   EMPTY_HOWTO (217),
00991   EMPTY_HOWTO (218),
00992   EMPTY_HOWTO (219),
00993   EMPTY_HOWTO (220),
00994   EMPTY_HOWTO (221),
00995   EMPTY_HOWTO (222),
00996   EMPTY_HOWTO (223),
00997   EMPTY_HOWTO (224),
00998   EMPTY_HOWTO (225),
00999   EMPTY_HOWTO (226),
01000   EMPTY_HOWTO (227),
01001   EMPTY_HOWTO (228),
01002   EMPTY_HOWTO (229),
01003   EMPTY_HOWTO (230),
01004   EMPTY_HOWTO (231),
01005   EMPTY_HOWTO (232),
01006   EMPTY_HOWTO (233),
01007   EMPTY_HOWTO (234),
01008   EMPTY_HOWTO (235),
01009   EMPTY_HOWTO (236),
01010   EMPTY_HOWTO (237),
01011   EMPTY_HOWTO (238),
01012   EMPTY_HOWTO (239),
01013   EMPTY_HOWTO (240),
01014   EMPTY_HOWTO (241),
01015 
01016   /* Relocations for SHmedia code.  None of these are partial_inplace or
01017      use the field being relocated.  */
01018 
01019   /* The assembler will generate this reloc before a block of SHmedia
01020      instructions.  A section should be processed as assuming it contains
01021      data, unless this reloc is seen.  Note that a block of SHcompact
01022      instructions are instead preceded by R_SH_CODE.
01023      This is currently not implemented, but should be used for SHmedia
01024      linker relaxation.  */
01025   HOWTO (R_SH_SHMEDIA_CODE, /* type */
01026         0,                  /* rightshift */
01027         1,                  /* size (0 = byte, 1 = short, 2 = long) */
01028         0,                  /* bitsize */
01029         FALSE,                     /* pc_relative */
01030         0,                  /* bitpos */
01031         complain_overflow_unsigned, /* complain_on_overflow */
01032         sh_elf64_ignore_reloc,     /* special_function */
01033         "R_SH_SHMEDIA_CODE",       /* name */
01034         FALSE,                     /* partial_inplace */
01035         0,                  /* src_mask */
01036         0,                  /* dst_mask */
01037         FALSE),             /* pcrel_offset */
01038 
01039   /* The assembler will generate this reloc at a PTA or PTB instruction,
01040      and the linker checks the right type of target, or changes a PTA to a
01041      PTB, if the original insn was PT.  */
01042   HOWTO (R_SH_PT_16,        /* type */
01043         2,                  /* rightshift */
01044         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01045         18,                 /* bitsize */
01046         TRUE,               /* pc_relative */
01047         10,                 /* bitpos */
01048         complain_overflow_signed, /* complain_on_overflow */
01049         bfd_elf_generic_reloc,     /* special_function */
01050         "R_SH_PT_16",              /* name */
01051         FALSE,                     /* partial_inplace */
01052         0,                  /* src_mask */
01053         0x3fffc00,          /* dst_mask */
01054         TRUE),                     /* pcrel_offset */
01055 
01056   /* Used in unexpanded MOVI.  */
01057   HOWTO (R_SH_IMMS16,              /* type */
01058         0,                  /* rightshift */
01059         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01060         16,                 /* bitsize */
01061         FALSE,                     /* pc_relative */
01062         10,                 /* bitpos */
01063         complain_overflow_signed, /* complain_on_overflow */
01064         bfd_elf_generic_reloc,     /* special_function */
01065         "R_SH_IMMS16",             /* name */
01066         FALSE,                     /* partial_inplace */
01067         0,                  /* src_mask */
01068         0x3fffc00,          /* dst_mask */
01069         FALSE),                    /* pcrel_offset */
01070 
01071   /* Used in SHORI.  */
01072   HOWTO (R_SH_IMMU16,              /* type */
01073         0,                  /* rightshift */
01074         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01075         16,                 /* bitsize */
01076         FALSE,                     /* pc_relative */
01077         10,                 /* bitpos */
01078         complain_overflow_unsigned, /* complain_on_overflow */
01079         bfd_elf_generic_reloc,     /* special_function */
01080         "R_SH_IMMU16",             /* name */
01081         FALSE,                     /* partial_inplace */
01082         0,                  /* src_mask */
01083         0x3fffc00,          /* dst_mask */
01084         FALSE),                    /* pcrel_offset */
01085 
01086   /* Used in MOVI and SHORI (x & 65536).  */
01087   HOWTO (R_SH_IMM_LOW16,    /* type */
01088         0,                  /* rightshift */
01089         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01090         64,                 /* bitsize */
01091         FALSE,                     /* pc_relative */
01092         10,                 /* bitpos */
01093         complain_overflow_dont, /* complain_on_overflow */
01094         bfd_elf_generic_reloc,     /* special_function */
01095         "R_SH_IMM_LOW16",          /* name */
01096         FALSE,                     /* partial_inplace */
01097         0,                  /* src_mask */
01098         0x3fffc00,          /* dst_mask */
01099         FALSE),                    /* pcrel_offset */
01100 
01101   /* Used in MOVI and SHORI ((x - $) & 65536).  */
01102   HOWTO (R_SH_IMM_LOW16_PCREL,     /* type */
01103         0,                  /* rightshift */
01104         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01105         64,                 /* bitsize */
01106         TRUE,               /* pc_relative */
01107         10,                 /* bitpos */
01108         complain_overflow_dont, /* complain_on_overflow */
01109         bfd_elf_generic_reloc,     /* special_function */
01110         "R_SH_IMM_LOW16_PCREL", /* name */
01111         FALSE,                     /* partial_inplace */
01112         0,                  /* src_mask */
01113         0x3fffc00,          /* dst_mask */
01114         TRUE),                     /* pcrel_offset */
01115 
01116   /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
01117   HOWTO (R_SH_IMM_MEDLOW16, /* type */
01118         16,                 /* rightshift */
01119         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01120         64,                 /* bitsize */
01121         FALSE,                     /* pc_relative */
01122         10,                 /* bitpos */
01123         complain_overflow_dont, /* complain_on_overflow */
01124         bfd_elf_generic_reloc,     /* special_function */
01125         "R_SH_IMM_MEDLOW16",       /* name */
01126         FALSE,                     /* partial_inplace */
01127         0,                  /* src_mask */
01128         0x3fffc00,          /* dst_mask */
01129         FALSE),                    /* pcrel_offset */
01130 
01131   /* Used in MOVI and SHORI (((x - $) >> 16) & 65536).  */
01132   HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
01133         16,                 /* rightshift */
01134         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01135         64,                 /* bitsize */
01136         TRUE,               /* pc_relative */
01137         10,                 /* bitpos */
01138         complain_overflow_dont, /* complain_on_overflow */
01139         bfd_elf_generic_reloc,     /* special_function */
01140         "R_SH_IMM_MEDLOW16_PCREL", /* name */
01141         FALSE,                     /* partial_inplace */
01142         0,                  /* src_mask */
01143         0x3fffc00,          /* dst_mask */
01144         TRUE),                     /* pcrel_offset */
01145 
01146   /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
01147   HOWTO (R_SH_IMM_MEDHI16,  /* type */
01148         32,                 /* rightshift */
01149         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01150         64,                 /* bitsize */
01151         FALSE,                     /* pc_relative */
01152         10,                 /* bitpos */
01153         complain_overflow_dont, /* complain_on_overflow */
01154         bfd_elf_generic_reloc,     /* special_function */
01155         "R_SH_IMM_MEDHI16", /* name */
01156         FALSE,                     /* partial_inplace */
01157         0,                  /* src_mask */
01158         0x3fffc00,          /* dst_mask */
01159         FALSE),                    /* pcrel_offset */
01160 
01161   /* Used in MOVI and SHORI (((x - $) >> 32) & 65536).  */
01162   HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
01163         32,                 /* rightshift */
01164         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01165         64,                 /* bitsize */
01166         TRUE,               /* pc_relative */
01167         10,                 /* bitpos */
01168         complain_overflow_dont, /* complain_on_overflow */
01169         bfd_elf_generic_reloc,     /* special_function */
01170         "R_SH_IMM_MEDHI16_PCREL", /* name */
01171         FALSE,                     /* partial_inplace */
01172         0,                  /* src_mask */
01173         0x3fffc00,          /* dst_mask */
01174         TRUE),                     /* pcrel_offset */
01175 
01176   /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
01177   HOWTO (R_SH_IMM_HI16,            /* type */
01178         48,                 /* rightshift */
01179         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01180         64,                 /* bitsize */
01181         FALSE,                     /* pc_relative */
01182         10,                 /* bitpos */
01183         complain_overflow_dont, /* complain_on_overflow */
01184         bfd_elf_generic_reloc,     /* special_function */
01185         "R_SH_IMM_HI16",    /* name */
01186         FALSE,                     /* partial_inplace */
01187         0,                  /* src_mask */
01188         0x3fffc00,          /* dst_mask */
01189         FALSE),                    /* pcrel_offset */
01190 
01191   /* Used in MOVI and SHORI (((x - $) >> 48) & 65536).  */
01192   HOWTO (R_SH_IMM_HI16_PCREL,      /* type */
01193         48,                 /* rightshift */
01194         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01195         64,                 /* bitsize */
01196         TRUE,               /* pc_relative */
01197         10,                 /* bitpos */
01198         complain_overflow_dont, /* complain_on_overflow */
01199         bfd_elf_generic_reloc,     /* special_function */
01200         "R_SH_IMM_HI16_PCREL", /* name */
01201         FALSE,                     /* partial_inplace */
01202         0,                  /* src_mask */
01203         0x3fffc00,          /* dst_mask */
01204         TRUE),                     /* pcrel_offset */
01205 
01206   /* For the .uaquad pseudo.  */
01207   HOWTO (R_SH_64,           /* type */
01208         0,                  /* rightshift */
01209         4,                  /* size (0 = byte, 1 = short, 2 = long) */
01210         64,                 /* bitsize */
01211         FALSE,                     /* pc_relative */
01212         0,                  /* bitpos */
01213         complain_overflow_dont, /* complain_on_overflow */
01214         bfd_elf_generic_reloc,     /* special_function */
01215         "R_SH_64",          /* name */
01216         FALSE,                     /* partial_inplace */
01217         0,                  /* src_mask */
01218         ((bfd_vma) 0) - 1,  /* dst_mask */
01219         FALSE),                    /* pcrel_offset */
01220 
01221   /* For the .uaquad pseudo, (x - $).  */
01222   HOWTO (R_SH_64_PCREL,            /* type */
01223         48,                 /* rightshift */
01224         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01225         64,                 /* bitsize */
01226         TRUE,               /* pc_relative */
01227         10,                 /* bitpos */
01228         complain_overflow_dont, /* complain_on_overflow */
01229         bfd_elf_generic_reloc,     /* special_function */
01230         "R_SH_64_PCREL",    /* name */
01231         FALSE,                     /* partial_inplace */
01232         0,                  /* src_mask */
01233         ((bfd_vma) 0) - 1,  /* dst_mask */
01234         TRUE),                     /* pcrel_offset */
01235 
01236 };
01237 
01238 /* This function is used for relocs which are only used for relaxing,
01239    which the linker should otherwise ignore.  */
01240 
01241 static bfd_reloc_status_type
01242 sh_elf64_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
01243                      asymbol *symbol ATTRIBUTE_UNUSED,
01244                      void *data ATTRIBUTE_UNUSED, asection *input_section,
01245                      bfd *output_bfd,
01246                      char **error_message ATTRIBUTE_UNUSED)
01247 {
01248   if (output_bfd != NULL)
01249     reloc_entry->address += input_section->output_offset;
01250   return bfd_reloc_ok;
01251 }
01252 
01253 /* This function is used for normal relocs.  This used to be like the COFF
01254    function, and is almost certainly incorrect for other ELF targets.
01255 
01256    See sh_elf_reloc in elf32-sh.c for the original.  */
01257 
01258 static bfd_reloc_status_type
01259 sh_elf64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
01260               void *data, asection *input_section, bfd *output_bfd,
01261               char **error_message ATTRIBUTE_UNUSED)
01262 {
01263   unsigned long insn;
01264   bfd_vma sym_value;
01265   enum elf_sh_reloc_type r_type;
01266   bfd_vma addr = reloc_entry->address;
01267   bfd_byte *hit_data = addr + (bfd_byte *) data;
01268 
01269   r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
01270 
01271   if (output_bfd != NULL)
01272     {
01273       /* Partial linking--do nothing.  */
01274       reloc_entry->address += input_section->output_offset;
01275       return bfd_reloc_ok;
01276     }
01277 
01278   if (symbol_in != NULL
01279       && bfd_is_und_section (symbol_in->section))
01280     return bfd_reloc_undefined;
01281 
01282   if (bfd_is_com_section (symbol_in->section))
01283     sym_value = 0;
01284   else
01285     sym_value = (symbol_in->value +
01286                symbol_in->section->output_section->vma +
01287                symbol_in->section->output_offset);
01288 
01289   switch (r_type)
01290     {
01291     case R_SH_DIR32:
01292       insn = bfd_get_32 (abfd, hit_data);
01293       insn += sym_value + reloc_entry->addend;
01294       bfd_put_32 (abfd, insn, hit_data);
01295       break;
01296 
01297     default:
01298       abort ();
01299       break;
01300     }
01301 
01302   return bfd_reloc_ok;
01303 }
01304 
01305 /* This structure is used to map BFD reloc codes to SH ELF relocs.  */
01306 
01307 struct elf_reloc_map
01308 {
01309   bfd_reloc_code_real_type bfd_reloc_val;
01310   unsigned char elf_reloc_val;
01311 };
01312 
01313 /* An array mapping BFD reloc codes to SH ELF relocs.  */
01314 
01315 static const struct elf_reloc_map sh64_reloc_map[] =
01316 {
01317   { BFD_RELOC_NONE, R_SH_NONE },
01318   { BFD_RELOC_32, R_SH_DIR32 },
01319   { BFD_RELOC_CTOR, R_SH_DIR32 },
01320   { BFD_RELOC_32_PCREL, R_SH_REL32 },
01321   { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
01322   { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
01323   { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
01324   { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
01325   { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
01326   { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
01327   { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
01328   { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
01329   { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
01330   { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
01331   { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
01332   { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
01333   { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
01334   { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
01335   { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
01336   { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
01337   { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
01338   { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
01339   { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
01340   { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
01341   { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
01342   { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
01343   { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
01344   { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
01345   { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
01346   { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
01347   { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
01348   { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
01349   { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
01350   { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
01351   { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
01352   { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
01353   { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
01354   { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
01355   { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
01356   { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
01357   { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
01358   { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
01359   { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
01360   { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
01361   { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
01362   { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
01363   { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
01364   { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
01365   { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
01366   { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
01367   { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
01368   { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
01369   { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
01370   { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
01371   { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
01372   { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
01373   { BFD_RELOC_64, R_SH_64 },
01374   { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
01375 };
01376 
01377 /* Given a BFD reloc code, return the howto structure for the
01378    corresponding SH ELf reloc.  */
01379 
01380 static reloc_howto_type *
01381 sh_elf64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
01382                          bfd_reloc_code_real_type code)
01383 {
01384   unsigned int i;
01385 
01386   for (i = 0; i < sizeof (sh64_reloc_map) / sizeof (struct elf_reloc_map); i++)
01387     {
01388       if (sh64_reloc_map[i].bfd_reloc_val == code)
01389        return &sh_elf64_howto_table[(int) sh64_reloc_map[i].elf_reloc_val];
01390     }
01391 
01392   return NULL;
01393 }
01394 
01395 static reloc_howto_type *
01396 sh_elf64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
01397                          const char *r_name)
01398 {
01399   unsigned int i;
01400 
01401   for (i = 0;
01402        i < sizeof (sh_elf64_howto_table) / sizeof (sh_elf64_howto_table[0]);
01403        i++)
01404     if (sh_elf64_howto_table[i].name != NULL
01405        && strcasecmp (sh_elf64_howto_table[i].name, r_name) == 0)
01406       return &sh_elf64_howto_table[i];
01407 
01408   return NULL;
01409 }
01410 
01411 /* Given an ELF reloc, fill in the howto field of a relent.
01412 
01413    See sh_elf_info_to_howto in elf32-sh.c for the original.  */
01414 
01415 static void
01416 sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
01417                      Elf_Internal_Rela *dst)
01418 {
01419   unsigned int r;
01420 
01421   r = ELF64_R_TYPE (dst->r_info);
01422 
01423   BFD_ASSERT (r <= (unsigned int) R_SH_64_PCREL);
01424   BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
01425   BFD_ASSERT (r < R_SH_DIR8WPN || r > R_SH_LAST_INVALID_RELOC_2);
01426   BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_GOTPLT32);
01427   BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
01428 
01429   cache_ptr->howto = &sh_elf64_howto_table[r];
01430 }
01431 
01432 /* Relocate an SH ELF section.
01433 
01434    See sh_elf_info_to_howto in elf32-sh.c for the original.  */
01435 
01436 static bfd_boolean
01437 sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
01438                         struct bfd_link_info *info, bfd *input_bfd,
01439                         asection *input_section, bfd_byte *contents,
01440                         Elf_Internal_Rela *relocs,
01441                         Elf_Internal_Sym *local_syms,
01442                         asection **local_sections)
01443 {
01444   Elf_Internal_Shdr *symtab_hdr;
01445   struct elf_link_hash_entry **sym_hashes;
01446   Elf_Internal_Rela *rel, *relend;
01447   bfd *dynobj;
01448   bfd_vma *local_got_offsets;
01449   asection *sgot;
01450   asection *sgotplt;
01451   asection *splt;
01452   asection *sreloc;
01453   bfd_vma disp, dropped;
01454 
01455   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
01456   sym_hashes = elf_sym_hashes (input_bfd);
01457   dynobj = elf_hash_table (info)->dynobj;
01458   local_got_offsets = elf_local_got_offsets (input_bfd);
01459 
01460   sgot = NULL;
01461   sgotplt = NULL;
01462   splt = NULL;
01463   sreloc = NULL;
01464 
01465   rel = relocs;
01466   relend = relocs + input_section->reloc_count;
01467   for (; rel < relend; rel++)
01468     {
01469       int r_type;
01470       reloc_howto_type *howto;
01471       unsigned long r_symndx;
01472       Elf_Internal_Sym *sym;
01473       asection *sec;
01474       struct elf_link_hash_entry *h;
01475       bfd_vma relocation;
01476       bfd_vma addend = (bfd_vma)0;
01477       bfd_reloc_status_type r;
01478       int seen_stt_datalabel = 0;
01479 
01480       r_symndx = ELF64_R_SYM (rel->r_info);
01481 
01482       r_type = ELF64_R_TYPE (rel->r_info);
01483 
01484       if (r_type == (int) R_SH_NONE)
01485        continue;
01486 
01487       if (r_type < 0
01488          || r_type > R_SH_64_PCREL
01489          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
01490              && r_type <= (int) R_SH_LAST_INVALID_RELOC)
01491          || (r_type >= (int) R_SH_DIR8WPN
01492              && r_type <= (int) R_SH_LAST_INVALID_RELOC)
01493          || (r_type >= (int) R_SH_GNU_VTINHERIT
01494              && r_type <= (int) R_SH_PSHL)
01495          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
01496              && r_type <= R_SH_GOTPLT32)
01497          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
01498              && r_type <= (int) R_SH_LAST_INVALID_RELOC_4))
01499        {
01500          bfd_set_error (bfd_error_bad_value);
01501          return FALSE;
01502        }
01503 
01504       howto = sh_elf64_howto_table + r_type;
01505 
01506       h = NULL;
01507       sym = NULL;
01508       sec = NULL;
01509       relocation = 0;
01510       if (r_symndx < symtab_hdr->sh_info)
01511        {
01512          sym = local_syms + r_symndx;
01513          sec = local_sections[r_symndx];
01514          relocation = ((sec->output_section->vma
01515                       + sec->output_offset
01516                       + sym->st_value)
01517                      | ((sym->st_other & STO_SH5_ISA32) != 0));
01518 
01519          /* A local symbol never has STO_SH5_ISA32, so we don't need
01520             datalabel processing here.  Make sure this does not change
01521             without notice.  */
01522          if ((sym->st_other & STO_SH5_ISA32) != 0)
01523            ((*info->callbacks->reloc_dangerous)
01524             (info,
01525              _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
01526              input_bfd, input_section, rel->r_offset));
01527 
01528          if (sec != NULL && elf_discarded_section (sec))
01529            /* Handled below.  */
01530            ;
01531          else if (info->relocatable)
01532            {
01533              /* This is a relocatable link.  We don't have to change
01534                anything, unless the reloc is against a section symbol,
01535                in which case we have to adjust according to where the
01536                section symbol winds up in the output section.  */
01537              if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
01538               goto final_link_relocate;
01539 
01540              continue;
01541            }
01542          else if (! howto->partial_inplace)
01543            {
01544              relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
01545              relocation |= ((sym->st_other & STO_SH5_ISA32) != 0);
01546            }
01547          else if ((sec->flags & SEC_MERGE)
01548                  && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
01549            {
01550              asection *msec;
01551 
01552              if (howto->rightshift || howto->src_mask != 0xffffffff)
01553               {
01554                 (*_bfd_error_handler)
01555                   (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
01556                    input_bfd, input_section,
01557                    (long) rel->r_offset, howto->name);
01558                 return FALSE;
01559               }
01560 
01561               addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
01562               msec = sec;
01563               addend =
01564               _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
01565               - relocation;
01566              addend += msec->output_section->vma + msec->output_offset;
01567              bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
01568              addend = 0;
01569            }
01570        }
01571       else
01572        {
01573          /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ?  */
01574 
01575          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
01576          while (h->root.type == bfd_link_hash_indirect
01577                || h->root.type == bfd_link_hash_warning)
01578            {
01579              /* If the reference passes a symbol marked with
01580                STT_DATALABEL, then any STO_SH5_ISA32 on the final value
01581                doesn't count.  */
01582              seen_stt_datalabel |= h->type == STT_DATALABEL;
01583              h = (struct elf_link_hash_entry *) h->root.u.i.link;
01584            }
01585 
01586          if (h->root.type == bfd_link_hash_defined
01587              || h->root.type == bfd_link_hash_defweak)
01588            {
01589              sec = h->root.u.def.section;
01590              /* In these cases, we don't need the relocation value.
01591                We check specially because in some obscure cases
01592                sec->output_section will be NULL.  */
01593              if (r_type == R_SH_GOTPC_LOW16
01594                 || r_type == R_SH_GOTPC_MEDLOW16
01595                 || r_type == R_SH_GOTPC_MEDHI16
01596                 || r_type == R_SH_GOTPC_HI16
01597                 || ((r_type == R_SH_PLT_LOW16
01598                      || r_type == R_SH_PLT_MEDLOW16
01599                      || r_type == R_SH_PLT_MEDHI16
01600                      || r_type == R_SH_PLT_HI16)
01601                     && h->plt.offset != (bfd_vma) -1)
01602                 || ((r_type == R_SH_GOT_LOW16
01603                      || r_type == R_SH_GOT_MEDLOW16
01604                      || r_type == R_SH_GOT_MEDHI16
01605                      || r_type == R_SH_GOT_HI16)
01606                     && elf_hash_table (info)->dynamic_sections_created
01607                     && (! info->shared
01608                        || (! info->symbolic && h->dynindx != -1)
01609                        || !h->def_regular))
01610                 /* The cases above are those in which relocation is
01611                    overwritten in the switch block below.  The cases
01612                    below are those in which we must defer relocation
01613                    to run-time, because we can't resolve absolute
01614                    addresses when creating a shared library.  */
01615                 || (info->shared
01616                     && ((! info->symbolic && h->dynindx != -1)
01617                        || !h->def_regular)
01618                     && ((r_type == R_SH_64
01619                         && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
01620                             || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
01621                        || r_type == R_SH_64_PCREL)
01622                     && ((input_section->flags & SEC_ALLOC) != 0
01623                        /* DWARF will emit R_SH_DIR32 relocations in its
01624                           sections against symbols defined externally
01625                           in shared libraries.  We can't do anything
01626                           with them here.  */
01627                        || (input_section->flags & SEC_DEBUGGING) != 0))
01628                 /* Dynamic relocs are not propagated for SEC_DEBUGGING
01629                    sections because such sections are not SEC_ALLOC and
01630                    thus ld.so will not process them.  */
01631                 || (sec->output_section == NULL
01632                     && ((input_section->flags & SEC_DEBUGGING) != 0
01633                        && h->def_dynamic)))
01634               ;
01635              else if (sec->output_section != NULL)
01636               relocation = ((h->root.u.def.value
01637                             + sec->output_section->vma
01638                             + sec->output_offset)
01639                            /* A STO_SH5_ISA32 causes a "bitor 1" to the
01640                              symbol value, unless we've seen
01641                              STT_DATALABEL on the way to it.  */
01642                            | ((h->other & STO_SH5_ISA32) != 0
01643                              && ! seen_stt_datalabel));
01644              else if (!info->relocatable)
01645               {
01646                 (*_bfd_error_handler)
01647                   (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
01648                    input_bfd,
01649                    input_section,
01650                    (long) rel->r_offset,
01651                    howto->name,
01652                    h->root.root.string);
01653               }
01654            }
01655          else if (h->root.type == bfd_link_hash_undefweak)
01656            ;
01657          else if (info->unresolved_syms_in_objects == RM_IGNORE
01658                  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
01659            ;
01660          else if (!info->relocatable)
01661            {
01662              if (! ((*info->callbacks->undefined_symbol)
01663                    (info, h->root.root.string, input_bfd,
01664                     input_section, rel->r_offset,
01665                     (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
01666                      || ELF_ST_VISIBILITY (h->other)))))
01667               return FALSE;
01668            }
01669        }
01670 
01671       if (sec != NULL && elf_discarded_section (sec))
01672        {
01673          /* For relocs against symbols from removed linkonce sections,
01674             or sections discarded by a linker script, we just want the
01675             section contents zeroed.  Avoid any special processing.  */
01676          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
01677          rel->r_info = 0;
01678          rel->r_addend = 0;
01679          continue;
01680        }
01681 
01682       if (info->relocatable)
01683        continue;
01684 
01685       disp = (relocation
01686              - input_section->output_section->vma
01687              - input_section->output_offset
01688              - rel->r_offset);
01689       dropped = 0;
01690       switch ((int)r_type)
01691        {
01692        case R_SH_PT_16:     dropped = disp & 2; break;
01693        case R_SH_DIR10SW: dropped = disp & 1; break;
01694        case R_SH_DIR10SL: dropped = disp & 3; break;
01695        case R_SH_DIR10SQ: dropped = disp & 7; break;
01696        }
01697       if (dropped != 0)
01698        {
01699          (*_bfd_error_handler)
01700            (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
01701             bfd_get_filename (input_bfd), (int)r_type, (unsigned)rel->r_offset, (unsigned)relocation);
01702          bfd_set_error (bfd_error_bad_value);
01703          return FALSE;
01704        }
01705       switch ((int)r_type)
01706        {
01707        case R_SH_64:
01708        case R_SH_64_PCREL:
01709          if (info->shared
01710              && (input_section->flags & SEC_ALLOC) != 0
01711              && (r_type != R_SH_64_PCREL
01712                 || (h != NULL
01713                     && h->dynindx != -1
01714                     && (! info->symbolic
01715                        || !h->def_regular))))
01716            {
01717              Elf_Internal_Rela outrel;
01718              bfd_byte *loc;
01719              bfd_boolean skip, relocate;
01720 
01721              /* When generating a shared object, these relocations
01722                are copied into the output file to be resolved at run
01723                time.  */
01724 
01725              if (sreloc == NULL)
01726               {
01727                 const char *name;
01728 
01729                 name = (bfd_elf_string_from_elf_section
01730                        (input_bfd,
01731                         elf_elfheader (input_bfd)->e_shstrndx,
01732                         elf_section_data (input_section)->rel_hdr.sh_name));
01733                 if (name == NULL)
01734                   return FALSE;
01735 
01736                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
01737                            && strcmp (bfd_get_section_name (input_bfd,
01738                                                         input_section),
01739                                     name + 5) == 0);
01740 
01741                 sreloc = bfd_get_section_by_name (dynobj, name);
01742                 BFD_ASSERT (sreloc != NULL);
01743               }
01744 
01745              skip = FALSE;
01746              relocate = FALSE;
01747 
01748              outrel.r_offset
01749               = _bfd_elf_section_offset (output_bfd, info,
01750                                       input_section, rel->r_offset);
01751 
01752              if (outrel.r_offset == (bfd_vma) -1)
01753               skip = TRUE;
01754              else if (outrel.r_offset == (bfd_vma) -2)
01755               skip = TRUE, relocate = TRUE;
01756 
01757              outrel.r_offset += (input_section->output_section->vma
01758                               + input_section->output_offset);
01759 
01760              if (skip)
01761               memset (&outrel, 0, sizeof outrel);
01762              else if (r_type == R_SH_64_PCREL)
01763               {
01764                 BFD_ASSERT (h != NULL && h->dynindx != -1);
01765                 outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64_PCREL);
01766                 outrel.r_addend = rel->r_addend;
01767               }
01768              else
01769               {
01770                 /* h->dynindx may be -1 if this symbol was marked to
01771                    become local.  */
01772                 if (h == NULL
01773                     || ((info->symbolic || h->dynindx == -1)
01774                        && h->def_regular))
01775                   {
01776                     relocate = TRUE;
01777                     outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
01778                     outrel.r_addend = relocation + rel->r_addend;
01779                   }
01780                 else
01781                   {
01782                     BFD_ASSERT (h->dynindx != -1);
01783                     outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64);
01784                     outrel.r_addend = relocation + rel->r_addend;
01785                   }
01786               }
01787 
01788              loc = sreloc->contents;
01789              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
01790              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
01791 
01792              /* If this reloc is against an external symbol, we do
01793                not want to fiddle with the addend.  Otherwise, we
01794                need to include the symbol value so that it becomes
01795                an addend for the dynamic reloc.  */
01796              if (! relocate)
01797               continue;
01798            }
01799          else if (r_type == R_SH_64)
01800            addend = rel->r_addend;
01801          goto final_link_relocate;
01802 
01803        case R_SH_GOTPLT_LOW16:
01804        case R_SH_GOTPLT_MEDLOW16:
01805        case R_SH_GOTPLT_MEDHI16:
01806        case R_SH_GOTPLT_HI16:
01807        case R_SH_GOTPLT10BY4:
01808        case R_SH_GOTPLT10BY8:
01809          /* Relocation is to the entry for this symbol in the
01810             procedure linkage table.  */
01811 
01812          if (h == NULL
01813              || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
01814              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
01815              || ! info->shared
01816              || info->symbolic
01817              || h->dynindx == -1
01818              || h->plt.offset == (bfd_vma) -1
01819              || h->got.offset != (bfd_vma) -1)
01820            goto force_got;
01821 
01822          /* Relocation is to the entry for this symbol in the global
01823             offset table extension for the procedure linkage table.  */
01824          if (sgotplt == NULL)
01825            {
01826              sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
01827              BFD_ASSERT (sgotplt != NULL);
01828            }
01829 
01830          relocation = (sgotplt->output_offset
01831                      + ((h->plt.offset / elf_sh64_sizeof_plt (info)
01832                          - 1 + 3) * 8));
01833 
01834          relocation -= GOT_BIAS;
01835 
01836          goto final_link_relocate;
01837 
01838        force_got:
01839        case R_SH_GOT_LOW16:
01840        case R_SH_GOT_MEDLOW16:
01841        case R_SH_GOT_MEDHI16:
01842        case R_SH_GOT_HI16:
01843        case R_SH_GOT10BY4:
01844        case R_SH_GOT10BY8:
01845          /* Relocation is to the entry for this symbol in the global
01846             offset table.  */
01847          if (sgot == NULL)
01848            {
01849              sgot = bfd_get_section_by_name (dynobj, ".got");
01850              BFD_ASSERT (sgot != NULL);
01851            }
01852 
01853          if (h != NULL)
01854            {
01855              bfd_vma off;
01856 
01857              off = h->got.offset;
01858              if (seen_stt_datalabel)
01859               {
01860                 struct elf_sh64_link_hash_entry *hsh;
01861 
01862                 hsh = (struct elf_sh64_link_hash_entry *)h;
01863                 off = hsh->datalabel_got_offset;
01864               }
01865              BFD_ASSERT (off != (bfd_vma) -1);
01866 
01867              if (! elf_hash_table (info)->dynamic_sections_created
01868                 || (info->shared
01869                     && (info->symbolic || h->dynindx == -1
01870                        || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
01871                        || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
01872                     && h->def_regular))
01873               {
01874                 /* This is actually a static link, or it is a
01875                    -Bsymbolic link and the symbol is defined
01876                    locally, or the symbol was forced to be local
01877                    because of a version file.  We must initialize
01878                    this entry in the global offset table.  Since the
01879                    offset must always be a multiple of 4, we use the
01880                    least significant bit to record whether we have
01881                    initialized it already.
01882 
01883                    When doing a dynamic link, we create a .rela.got
01884                    relocation entry to initialize the value.  This
01885                    is done in the finish_dynamic_symbol routine.  */
01886                 if ((off & 1) != 0)
01887                   off &= ~1;
01888                 else
01889                   {
01890                     bfd_put_64 (output_bfd, relocation,
01891                               sgot->contents + off);
01892                     if (seen_stt_datalabel)
01893                      {
01894                        struct elf_sh64_link_hash_entry *hsh;
01895 
01896                        hsh = (struct elf_sh64_link_hash_entry *)h;
01897                        hsh->datalabel_got_offset |= 1;
01898                      }
01899                     else
01900                      h->got.offset |= 1;
01901                   }
01902               }
01903 
01904              relocation = sgot->output_offset + off;
01905            }
01906          else
01907            {
01908              bfd_vma off;
01909 
01910              if (rel->r_addend)
01911               {
01912                 BFD_ASSERT (local_got_offsets != NULL
01913                            && (local_got_offsets[symtab_hdr->sh_info
01914                                               + r_symndx]
01915                               != (bfd_vma) -1));
01916 
01917                 off = local_got_offsets[symtab_hdr->sh_info
01918                                      + r_symndx];
01919               }
01920              else
01921               {
01922                 BFD_ASSERT (local_got_offsets != NULL
01923                            && local_got_offsets[r_symndx] != (bfd_vma) -1);
01924 
01925                 off = local_got_offsets[r_symndx];
01926               }
01927 
01928              /* The offset must always be a multiple of 8.  We use
01929                the least significant bit to record whether we have
01930                already generated the necessary reloc.  */
01931              if ((off & 1) != 0)
01932               off &= ~1;
01933              else
01934               {
01935                 bfd_put_64 (output_bfd, relocation, sgot->contents + off);
01936 
01937                 if (info->shared)
01938                   {
01939                     asection *s;
01940                     Elf_Internal_Rela outrel;
01941                     bfd_byte *loc;
01942 
01943                     s = bfd_get_section_by_name (dynobj, ".rela.got");
01944                     BFD_ASSERT (s != NULL);
01945 
01946                     outrel.r_offset = (sgot->output_section->vma
01947                                     + sgot->output_offset
01948                                     + off);
01949                     outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
01950                     outrel.r_addend = relocation;
01951                     loc = s->contents;
01952                     loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
01953                     bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
01954                   }
01955 
01956                 if (rel->r_addend)
01957                   local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
01958                 else
01959                   local_got_offsets[r_symndx] |= 1;
01960               }
01961 
01962              relocation = sgot->output_offset + off;
01963            }
01964 
01965          relocation -= GOT_BIAS;
01966 
01967          goto final_link_relocate;
01968 
01969        case R_SH_GOTOFF_LOW16:
01970        case R_SH_GOTOFF_MEDLOW16:
01971        case R_SH_GOTOFF_MEDHI16:
01972        case R_SH_GOTOFF_HI16:
01973          /* Relocation is relative to the start of the global offset
01974             table.  */
01975 
01976          if (sgot == NULL)
01977            {
01978              sgot = bfd_get_section_by_name (dynobj, ".got");
01979              BFD_ASSERT (sgot != NULL);
01980            }
01981 
01982          /* Note that sgot->output_offset is not involved in this
01983             calculation.  We always want the start of .got.  If we
01984             defined _GLOBAL_OFFSET_TABLE in a different way, as is
01985             permitted by the ABI, we might have to change this
01986             calculation.  */
01987          relocation -= sgot->output_section->vma;
01988 
01989          relocation -= GOT_BIAS;
01990 
01991          addend = rel->r_addend;
01992 
01993          goto final_link_relocate;
01994 
01995        case R_SH_GOTPC_LOW16:
01996        case R_SH_GOTPC_MEDLOW16:
01997        case R_SH_GOTPC_MEDHI16:
01998        case R_SH_GOTPC_HI16:
01999          /* Use global offset table as symbol value.  */
02000 
02001          if (sgot == NULL)
02002            {
02003              sgot = bfd_get_section_by_name (dynobj, ".got");
02004              BFD_ASSERT (sgot != NULL);
02005            }
02006 
02007          relocation = sgot->output_section->vma;
02008 
02009          relocation += GOT_BIAS;
02010 
02011          addend = rel->r_addend;
02012 
02013          goto final_link_relocate;
02014 
02015        case R_SH_PLT_LOW16:
02016        case R_SH_PLT_MEDLOW16:
02017        case R_SH_PLT_MEDHI16:
02018        case R_SH_PLT_HI16:
02019          /* Relocation is to the entry for this symbol in the
02020             procedure linkage table.  */
02021 
02022          /* Resolve a PLT reloc against a local symbol directly,
02023             without using the procedure linkage table.  */
02024          if (h == NULL)
02025            goto final_link_relocate;
02026 
02027          if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
02028              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
02029            goto final_link_relocate;
02030 
02031          if (h->plt.offset == (bfd_vma) -1)
02032            {
02033              /* We didn't make a PLT entry for this symbol.  This
02034                happens when statically linking PIC code, or when
02035                using -Bsymbolic.  */
02036              goto final_link_relocate;
02037            }
02038 
02039          if (splt == NULL)
02040            {
02041              splt = bfd_get_section_by_name (dynobj, ".plt");
02042              BFD_ASSERT (splt != NULL);
02043            }
02044 
02045          relocation = (splt->output_section->vma
02046                      + splt->output_offset
02047                      + h->plt.offset);
02048          relocation++;
02049 
02050          addend = rel->r_addend;
02051 
02052          goto final_link_relocate;
02053 
02054        case R_SH_DIR32:
02055        case R_SH_SHMEDIA_CODE:
02056        case R_SH_PT_16:
02057        case R_SH_DIR5U:
02058        case R_SH_DIR6S:
02059        case R_SH_DIR6U:
02060        case R_SH_DIR10S:
02061        case R_SH_DIR10SW:
02062        case R_SH_DIR10SL:
02063        case R_SH_DIR10SQ:
02064        case R_SH_IMMS16:
02065        case R_SH_IMMU16:
02066        case R_SH_IMM_LOW16:
02067        case R_SH_IMM_LOW16_PCREL:
02068        case R_SH_IMM_MEDLOW16:
02069        case R_SH_IMM_MEDLOW16_PCREL:
02070        case R_SH_IMM_MEDHI16:
02071        case R_SH_IMM_MEDHI16_PCREL:
02072        case R_SH_IMM_HI16:
02073        case R_SH_IMM_HI16_PCREL:
02074          addend = rel->r_addend;
02075          /* Fall through.  */
02076        case R_SH_REL32:
02077        final_link_relocate:
02078          r = _bfd_final_link_relocate (howto, input_bfd, input_section,
02079                                    contents, rel->r_offset,
02080                                    relocation, addend);
02081          break;
02082 
02083        default:
02084          bfd_set_error (bfd_error_bad_value);
02085          return FALSE;
02086 
02087        }
02088 
02089       if (r != bfd_reloc_ok)
02090        {
02091          switch (r)
02092            {
02093            default:
02094            case bfd_reloc_outofrange:
02095              abort ();
02096            case bfd_reloc_overflow:
02097              {
02098               const char *name;
02099 
02100               if (h != NULL)
02101                 name = NULL;
02102               else
02103                 {
02104                   name = (bfd_elf_string_from_elf_section
02105                          (input_bfd, symtab_hdr->sh_link, sym->st_name));
02106                   if (name == NULL)
02107                     return FALSE;
02108                   if (*name == '\0')
02109                     name = bfd_section_name (input_bfd, sec);
02110                 }
02111               if (! ((*info->callbacks->reloc_overflow)
02112                      (info, (h ? &h->root : NULL), name, howto->name,
02113                      (bfd_vma) 0, input_bfd, input_section,
02114                      rel->r_offset)))
02115                 return FALSE;
02116              }
02117              break;
02118            }
02119        }
02120     }
02121 
02122   return TRUE;
02123 }
02124 
02125 /* This is a version of bfd_generic_get_relocated_section_contents
02126    that uses sh_elf64_relocate_section.
02127 
02128    See sh_elf_relocate_section in elf32-sh.c for the original.  */
02129 
02130 static bfd_byte *
02131 sh_elf64_get_relocated_section_contents (bfd *output_bfd,
02132                                     struct bfd_link_info *link_info,
02133                                     struct bfd_link_order *link_order,
02134                                     bfd_byte *data,
02135                                     bfd_boolean relocatable,
02136                                     asymbol **symbols)
02137 {
02138   Elf_Internal_Shdr *symtab_hdr;
02139   asection *input_section = link_order->u.indirect.section;
02140   bfd *input_bfd = input_section->owner;
02141   asection **sections = NULL;
02142   Elf_Internal_Rela *internal_relocs = NULL;
02143   Elf_Internal_Sym *isymbuf = NULL;
02144 
02145   /* We only need to handle the case of relaxing, or of having a
02146      particular set of section contents, specially.  */
02147   if (relocatable
02148       || elf_section_data (input_section)->this_hdr.contents == NULL)
02149     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
02150                                                  link_order, data,
02151                                                  relocatable,
02152                                                  symbols);
02153 
02154   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
02155 
02156   memcpy (data, elf_section_data (input_section)->this_hdr.contents,
02157          input_section->size);
02158 
02159   if ((input_section->flags & SEC_RELOC) != 0
02160       && input_section->reloc_count > 0)
02161     {
02162       Elf_Internal_Sym *isymp;
02163       Elf_Internal_Sym *isymend;
02164       asection **secpp;
02165 
02166       /* Read this BFD's local symbols.  */
02167       if (symtab_hdr->sh_info != 0)
02168        {
02169          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
02170          if (isymbuf == NULL)
02171            isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
02172                                        symtab_hdr->sh_info, 0,
02173                                        NULL, NULL, NULL);
02174          if (isymbuf == NULL)
02175            goto error_return;
02176        }
02177 
02178       internal_relocs = (_bfd_elf_link_read_relocs
02179                       (input_bfd, input_section, NULL,
02180                        (Elf_Internal_Rela *) NULL, FALSE));
02181       if (internal_relocs == NULL)
02182        goto error_return;
02183 
02184       sections = (asection **) bfd_malloc (symtab_hdr->sh_info
02185                                       * sizeof (asection *));
02186       if (sections == NULL && symtab_hdr->sh_info > 0)
02187        goto error_return;
02188 
02189       secpp = sections;
02190       isymend = isymbuf + symtab_hdr->sh_info;
02191       for (isymp = isymbuf; isymp < isymend; ++isymp, ++secpp)
02192        {
02193          asection *isec;
02194 
02195          if (isymp->st_shndx == SHN_UNDEF)
02196            isec = bfd_und_section_ptr;
02197          else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)
02198            isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
02199          else if (isymp->st_shndx == SHN_ABS)
02200            isec = bfd_abs_section_ptr;
02201          else if (isymp->st_shndx == SHN_COMMON)
02202            isec = bfd_com_section_ptr;
02203          else
02204            {
02205              /* Who knows?  */
02206              isec = NULL;
02207            }
02208 
02209          *secpp = isec;
02210        }
02211 
02212       if (! sh_elf64_relocate_section (output_bfd, link_info, input_bfd,
02213                                    input_section, data, internal_relocs,
02214                                    isymbuf, sections))
02215        goto error_return;
02216 
02217       if (sections != NULL)
02218        free (sections);
02219       if (internal_relocs != elf_section_data (input_section)->relocs)
02220        free (internal_relocs);
02221       if (isymbuf != NULL
02222          && (unsigned char *) isymbuf != symtab_hdr->contents)
02223        free (isymbuf);
02224     }
02225 
02226   return data;
02227 
02228  error_return:
02229   if (sections != NULL)
02230     free (sections);
02231   if (internal_relocs != NULL
02232       && internal_relocs != elf_section_data (input_section)->relocs)
02233     free (internal_relocs);
02234   if (isymbuf != NULL
02235       && (unsigned char *) isymbuf != symtab_hdr->contents)
02236     free (isymbuf);
02237   return NULL;
02238 }
02239 
02240 /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections.  */
02241 
02242 static bfd_boolean
02243 sh64_elf64_fake_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
02244                        Elf_Internal_Shdr *elf_section_hdr,
02245                        asection *asect)
02246 {
02247   /* Code sections can only contain SH64 code, so mark them as such.  */
02248   if (bfd_get_section_flags (output_bfd, asect) & SEC_CODE)
02249     elf_section_hdr->sh_flags |= SHF_SH5_ISA32;
02250 
02251   return TRUE;
02252 }
02253 
02254 static bfd_boolean
02255 sh_elf64_set_mach_from_flags (bfd *abfd)
02256 {
02257   flagword flags = elf_elfheader (abfd)->e_flags;
02258 
02259   switch (flags & EF_SH_MACH_MASK)
02260     {
02261     case EF_SH5:
02262       /* Just one, but keep the switch construct to make additions easy.  */
02263       bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh5);
02264       break;
02265 
02266     default:
02267       bfd_set_error (bfd_error_wrong_format);
02268       return FALSE;
02269     }
02270   return TRUE;
02271 }
02272 
02273 /* Function to keep SH64 specific file flags.
02274 
02275    See sh64_elf_set_private_flags in elf32-sh64.c for the original.  */
02276 
02277 static bfd_boolean
02278 sh_elf64_set_private_flags (bfd *abfd, flagword flags)
02279 {
02280   BFD_ASSERT (! elf_flags_init (abfd)
02281              || elf_elfheader (abfd)->e_flags == flags);
02282 
02283   elf_elfheader (abfd)->e_flags = flags;
02284   elf_flags_init (abfd) = TRUE;
02285   return sh_elf64_set_mach_from_flags (abfd);
02286 }
02287 
02288 /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
02289    code, to keep attributes the same as for SHmedia in 32-bit ELF.  */
02290 
02291 static bfd_boolean
02292 sh_elf64_copy_private_data_internal (bfd *ibfd, bfd *obfd)
02293 {
02294   Elf_Internal_Shdr **o_shdrp;
02295   asection *isec;
02296   asection *osec;
02297 
02298   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
02299       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
02300     return TRUE;
02301 
02302   o_shdrp = elf_elfsections (obfd);
02303   for (osec = obfd->sections; osec; osec = osec->next)
02304     {
02305       int oIndex = ((struct bfd_elf_section_data *) elf_section_data (osec))->this_idx;
02306       for (isec = ibfd->sections; isec; isec = isec->next)
02307        {
02308          if (strcmp (osec->name, isec->name) == 0)
02309            {
02310              /* Note that we're not disallowing mixing data and code.  */
02311              if ((elf_section_data (isec)->this_hdr.sh_flags
02312                  & SHF_SH5_ISA32) != 0)
02313               o_shdrp[oIndex]->sh_flags |= SHF_SH5_ISA32;
02314              break;
02315            }
02316        }
02317     }
02318 
02319   return sh_elf64_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
02320 }
02321 
02322 static bfd_boolean
02323 sh_elf64_copy_private_data (bfd *ibfd, bfd *obfd)
02324 {
02325   return sh_elf64_copy_private_data_internal (ibfd, obfd);
02326 }
02327 
02328 static bfd_boolean
02329 sh_elf64_merge_private_data (bfd *ibfd, bfd *obfd)
02330 {
02331   flagword old_flags, new_flags;
02332 
02333   if (! _bfd_generic_verify_endian_match (ibfd, obfd))
02334     return FALSE;
02335 
02336   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
02337       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
02338     return TRUE;
02339 
02340   if (bfd_get_arch_size (ibfd) != bfd_get_arch_size (obfd))
02341     {
02342       const char *msg;
02343 
02344       if (bfd_get_arch_size (ibfd) == 32
02345          && bfd_get_arch_size (obfd) == 64)
02346        msg = _("%s: compiled as 32-bit object and %s is 64-bit");
02347       else if (bfd_get_arch_size (ibfd) == 64
02348               && bfd_get_arch_size (obfd) == 32)
02349        msg = _("%s: compiled as 64-bit object and %s is 32-bit");
02350       else
02351        msg = _("%s: object size does not match that of target %s");
02352 
02353       (*_bfd_error_handler) (msg, bfd_get_filename (ibfd),
02354                           bfd_get_filename (obfd));
02355       bfd_set_error (bfd_error_wrong_format);
02356       return FALSE;
02357     }
02358 
02359   old_flags = elf_elfheader (obfd)->e_flags;
02360   new_flags = elf_elfheader (ibfd)->e_flags;
02361   if (! elf_flags_init (obfd))
02362     {
02363       /* This happens when ld starts out with a 'blank' output file.  */
02364       elf_flags_init (obfd) = TRUE;
02365       elf_elfheader (obfd)->e_flags = old_flags = new_flags;
02366     }
02367   /* We don't allow linking in anything else than SH64 code, and since
02368      this is a 64-bit ELF, we assume the 64-bit ABI is used.  Add code
02369      here as things change.  */
02370   else if ((new_flags & EF_SH_MACH_MASK) != EF_SH5)
02371     {
02372       (*_bfd_error_handler)
02373        ("%s: does not use the SH64 64-bit ABI as previous modules do",
02374         bfd_get_filename (ibfd));
02375       bfd_set_error (bfd_error_bad_value);
02376       return FALSE;
02377     }
02378 
02379   sh_elf64_copy_private_data_internal (ibfd, obfd);
02380 
02381   /* I can't think of anything sane other than old_flags being EF_SH5 and
02382      that we need to preserve that.  */
02383   elf_elfheader (obfd)->e_flags = old_flags;
02384 
02385   return sh_elf64_set_mach_from_flags (obfd);
02386 }
02387 
02388 /* Return the section that should be marked against GC for a given
02389    relocation.  */
02390 
02391 static asection *
02392 sh_elf64_gc_mark_hook (asection *sec,
02393                      struct bfd_link_info *info,
02394                      Elf_Internal_Rela *rel,
02395                      struct elf_link_hash_entry *h,
02396                      Elf_Internal_Sym *sym)
02397 {
02398   if (h != NULL)
02399     switch (ELF64_R_TYPE (rel->r_info))
02400       {
02401       case R_SH_GNU_VTINHERIT:
02402       case R_SH_GNU_VTENTRY:
02403        return NULL;
02404       }
02405 
02406   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
02407 }
02408 
02409 /* Look through the relocs for a section during the first phase.
02410    Since we don't do .gots or .plts, we just need to consider the
02411    virtual table relocs for gc.  */
02412 
02413 static bfd_boolean
02414 sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
02415                      asection *sec, const Elf_Internal_Rela *relocs)
02416 {
02417   Elf_Internal_Shdr *symtab_hdr;
02418   struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
02419   const Elf_Internal_Rela *rel;
02420   const Elf_Internal_Rela *rel_end;
02421   bfd *dynobj;
02422   bfd_vma *local_got_offsets;
02423   asection *sgot;
02424   asection *srelgot;
02425   asection *sreloc;
02426 
02427   sgot = NULL;
02428   srelgot = NULL;
02429   sreloc = NULL;
02430 
02431   if (info->relocatable)
02432     return TRUE;
02433 
02434   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
02435   sym_hashes = elf_sym_hashes (abfd);
02436   sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf64_External_Sym);
02437   if (!elf_bad_symtab (abfd))
02438     sym_hashes_end -= symtab_hdr->sh_info;
02439 
02440   dynobj = elf_hash_table (info)->dynobj;
02441   local_got_offsets = elf_local_got_offsets (abfd);
02442 
02443   rel_end = relocs + sec->reloc_count;
02444   for (rel = relocs; rel < rel_end; rel++)
02445     {
02446       struct elf_link_hash_entry *h;
02447       unsigned long r_symndx;
02448 
02449       r_symndx = ELF64_R_SYM (rel->r_info);
02450       if (r_symndx < symtab_hdr->sh_info)
02451         h = NULL;
02452       else
02453        {
02454          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
02455          while (h->root.type == bfd_link_hash_indirect
02456                || h->root.type == bfd_link_hash_warning)
02457            h = (struct elf_link_hash_entry *) h->root.u.i.link;
02458        }
02459 
02460       /* Some relocs require a global offset table.  */
02461       if (dynobj == NULL)
02462        {
02463          switch (ELF64_R_TYPE (rel->r_info))
02464            {
02465            case R_SH_GOTPLT_LOW16:
02466            case R_SH_GOTPLT_MEDLOW16:
02467            case R_SH_GOTPLT_MEDHI16:
02468            case R_SH_GOTPLT_HI16:
02469            case R_SH_GOTPLT10BY4:
02470            case R_SH_GOTPLT10BY8:
02471            case R_SH_GOT_LOW16:
02472            case R_SH_GOT_MEDLOW16:
02473            case R_SH_GOT_MEDHI16:
02474            case R_SH_GOT_HI16:
02475            case R_SH_GOT10BY4:
02476            case R_SH_GOT10BY8:
02477            case R_SH_GOTOFF_LOW16:
02478            case R_SH_GOTOFF_MEDLOW16:
02479            case R_SH_GOTOFF_MEDHI16:
02480            case R_SH_GOTOFF_HI16:
02481            case R_SH_GOTPC_LOW16:
02482            case R_SH_GOTPC_MEDLOW16:
02483            case R_SH_GOTPC_MEDHI16:
02484            case R_SH_GOTPC_HI16:
02485              elf_hash_table (info)->dynobj = dynobj = abfd;
02486              if (! _bfd_elf_create_got_section (dynobj, info))
02487               return FALSE;
02488              break;
02489 
02490            default:
02491              break;
02492            }
02493        }
02494 
02495       switch (ELF64_R_TYPE (rel->r_info))
02496         {
02497          /* This relocation describes the C++ object vtable hierarchy.
02498             Reconstruct it for later use during GC.  */
02499         case R_SH_GNU_VTINHERIT:
02500           if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
02501             return FALSE;
02502           break;
02503 
02504          /* This relocation describes which C++ vtable entries are actually
02505             used.  Record for later use during GC.  */
02506         case R_SH_GNU_VTENTRY:
02507           if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
02508             return FALSE;
02509           break;
02510 
02511        force_got:
02512        case R_SH_GOT_LOW16:
02513        case R_SH_GOT_MEDLOW16:
02514        case R_SH_GOT_MEDHI16:
02515        case R_SH_GOT_HI16:
02516        case R_SH_GOT10BY4:
02517        case R_SH_GOT10BY8:
02518          /* This symbol requires a global offset table entry.  */
02519 
02520          if (sgot == NULL)
02521            {
02522              sgot = bfd_get_section_by_name (dynobj, ".got");
02523              BFD_ASSERT (sgot != NULL);
02524            }
02525 
02526          if (srelgot == NULL
02527              && (h != NULL || info->shared))
02528            {
02529              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
02530              if (srelgot == NULL)
02531               {
02532                 srelgot = bfd_make_section_with_flags (dynobj,
02533                                                   ".rela.got",
02534                                                   (SEC_ALLOC
02535                                                    | SEC_LOAD
02536                                                    | SEC_HAS_CONTENTS
02537                                                    | SEC_IN_MEMORY
02538                                                    | SEC_LINKER_CREATED
02539                                                    | SEC_READONLY));
02540                 if (srelgot == NULL
02541                     || ! bfd_set_section_alignment (dynobj, srelgot, 2))
02542                   return FALSE;
02543               }
02544            }
02545 
02546          if (h != NULL)
02547            {
02548              if (h->type == STT_DATALABEL)
02549               {
02550                 struct elf_sh64_link_hash_entry *hsh;
02551 
02552                 h = (struct elf_link_hash_entry *) h->root.u.i.link;
02553                 hsh = (struct elf_sh64_link_hash_entry *)h;
02554                 if (hsh->datalabel_got_offset != (bfd_vma) -1)
02555                   break;
02556 
02557                 hsh->datalabel_got_offset = sgot->size;
02558               }
02559              else
02560               {
02561                 if (h->got.offset != (bfd_vma) -1)
02562                   {
02563                     /* We have already allocated space in the .got.  */
02564                     break;
02565                   }
02566                 h->got.offset = sgot->size;
02567               }
02568 
02569              /* Make sure this symbol is output as a dynamic symbol.  */
02570              if (h->dynindx == -1)
02571               {
02572                 if (! bfd_elf_link_record_dynamic_symbol (info, h))
02573                   return FALSE;
02574               }
02575 
02576              srelgot->size += sizeof (Elf64_External_Rela);
02577            }
02578          else
02579            {
02580              /* This is a global offset table entry for a local
02581                symbol.  */
02582              if (local_got_offsets == NULL)
02583               {
02584                 size_t size;
02585                 register unsigned int i;
02586 
02587                 size = symtab_hdr->sh_info * sizeof (bfd_vma);
02588                 /* Reserve space for both the datalabel and
02589                    codelabel local GOT offsets.  */
02590                 size *= 2;
02591                 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
02592                 if (local_got_offsets == NULL)
02593                   return FALSE;
02594                 elf_local_got_offsets (abfd) = local_got_offsets;
02595                 for (i = 0; i < symtab_hdr->sh_info; i++)
02596                   local_got_offsets[i] = (bfd_vma) -1;
02597                 for (; i < 2 * symtab_hdr->sh_info; i++)
02598                   local_got_offsets[i] = (bfd_vma) -1;
02599               }
02600              if ((rel->r_addend & 1) != 0)
02601               {
02602                 if (local_got_offsets[symtab_hdr->sh_info
02603                                    + r_symndx] != (bfd_vma) -1)
02604                   {
02605                     /* We have already allocated space in the .got.  */
02606                     break;
02607                   }
02608                 local_got_offsets[symtab_hdr->sh_info
02609                                 + r_symndx] = sgot->size;
02610               }
02611              else
02612               {
02613                 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
02614                   {
02615                     /* We have already allocated space in the .got.  */
02616                     break;
02617                   }
02618                 local_got_offsets[r_symndx] = sgot->size;
02619               }
02620 
02621              if (info->shared)
02622               {
02623                 /* If we are generating a shared object, we need to
02624                    output a R_SH_RELATIVE reloc so that the dynamic
02625                    linker can adjust this GOT entry.  */
02626                 srelgot->size += sizeof (Elf64_External_Rela);
02627               }
02628            }
02629 
02630          sgot->size += 8;
02631 
02632          break;
02633 
02634        case R_SH_GOTPLT_LOW16:
02635        case R_SH_GOTPLT_MEDLOW16:
02636        case R_SH_GOTPLT_MEDHI16:
02637        case R_SH_GOTPLT_HI16:
02638        case R_SH_GOTPLT10BY4:
02639        case R_SH_GOTPLT10BY8:
02640          /* If this is a local symbol, we resolve it directly without
02641             creating a procedure linkage table entry.  */
02642 
02643          if (h == NULL
02644              || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
02645              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
02646              || ! info->shared
02647              || info->symbolic
02648              || h->dynindx == -1
02649              || h->got.offset != (bfd_vma) -1)
02650            goto force_got;
02651 
02652          /* Make sure this symbol is output as a dynamic symbol.  */
02653          if (h->dynindx == -1)
02654            {
02655              if (! bfd_elf_link_record_dynamic_symbol (info, h))
02656               return FALSE;
02657            }
02658 
02659          h->needs_plt = 1;
02660 
02661          break;
02662 
02663        case R_SH_PLT_LOW16:
02664        case R_SH_PLT_MEDLOW16:
02665        case R_SH_PLT_MEDHI16:
02666        case R_SH_PLT_HI16:
02667          /* This symbol requires a procedure linkage table entry.  We
02668             actually build the entry in adjust_dynamic_symbol,
02669             because this might be a case of linking PIC code which is
02670             never referenced by a dynamic object, in which case we
02671             don't need to generate a procedure linkage table entry
02672             after all.  */
02673 
02674          /* If this is a local symbol, we resolve it directly without
02675             creating a procedure linkage table entry.  */
02676          if (h == NULL)
02677            continue;
02678 
02679          if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
02680              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
02681            break;
02682 
02683          h->needs_plt = 1;
02684 
02685          break;
02686 
02687        case R_SH_64:
02688        case R_SH_64_PCREL:
02689          if (h != NULL)
02690            h->non_got_ref = 1;
02691 
02692          /* If we are creating a shared library, and this is a reloc
02693             against a global symbol, or a non PC relative reloc
02694             against a local symbol, then we need to copy the reloc
02695             into the shared library.  However, if we are linking with
02696             -Bsymbolic, we do not need to copy a reloc against a
02697             global symbol which is defined in an object we are
02698             including in the link (i.e., DEF_REGULAR is set).  At
02699             this point we have not seen all the input files, so it is
02700             possible that DEF_REGULAR is not set now but will be set
02701             later (it is never cleared).  We account for that
02702             possibility below by storing information in the
02703             pcrel_relocs_copied field of the hash table entry.  */
02704          if (info->shared
02705              && (sec->flags & SEC_ALLOC) != 0
02706              && (ELF32_R_TYPE (rel->r_info) != R_SH_64_PCREL
02707                 || (h != NULL
02708                     && (! info->symbolic
02709                        || !h->def_regular))))
02710            {
02711              /* When creating a shared object, we must copy these
02712                reloc types into the output file.  We create a reloc
02713                section in dynobj and make room for this reloc.  */
02714              if (sreloc == NULL)
02715               {
02716                 const char *name;
02717 
02718                 name = (bfd_elf_string_from_elf_section
02719                        (abfd,
02720                         elf_elfheader (abfd)->e_shstrndx,
02721                         elf_section_data (sec)->rel_hdr.sh_name));
02722                 if (name == NULL)
02723                   return FALSE;
02724 
02725                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
02726                            && strcmp (bfd_get_section_name (abfd, sec),
02727                                     name + 5) == 0);
02728 
02729                 sreloc = bfd_get_section_by_name (dynobj, name);
02730                 if (sreloc == NULL)
02731                   {
02732                     flagword flags;
02733 
02734                     flags = (SEC_HAS_CONTENTS | SEC_READONLY
02735                             | SEC_IN_MEMORY | SEC_LINKER_CREATED);
02736                     if ((sec->flags & SEC_ALLOC) != 0)
02737                      flags |= SEC_ALLOC | SEC_LOAD;
02738                     sreloc = bfd_make_section_with_flags (dynobj,
02739                                                      name,
02740                                                      flags);
02741                     if (sreloc == NULL
02742                        || ! bfd_set_section_alignment (dynobj, sreloc, 2))
02743                      return FALSE;
02744                   }
02745               }
02746 
02747              sreloc->size += sizeof (Elf64_External_Rela);
02748 
02749              /* If we are linking with -Bsymbolic, and this is a
02750                global symbol, we count the number of PC relative
02751                relocations we have entered for this symbol, so that
02752                we can discard them again if the symbol is later
02753                defined by a regular object.  Note that this function
02754                is only called if we are using an elf_sh linker
02755                hash table, which means that h is really a pointer to
02756                an elf_sh_link_hash_entry.  */
02757              if (h != NULL && info->symbolic
02758                 && ELF64_R_TYPE (rel->r_info) == R_SH_64_PCREL)
02759               {
02760                 struct elf_sh64_link_hash_entry *eh;
02761                 struct elf_sh64_pcrel_relocs_copied *p;
02762 
02763                 eh = (struct elf_sh64_link_hash_entry *) h;
02764 
02765                 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
02766                   if (p->section == sreloc)
02767                     break;
02768 
02769                 if (p == NULL)
02770                   {
02771                     p = ((struct elf_sh64_pcrel_relocs_copied *)
02772                         bfd_alloc (dynobj, sizeof *p));
02773                     if (p == NULL)
02774                      return FALSE;
02775                     p->next = eh->pcrel_relocs_copied;
02776                     eh->pcrel_relocs_copied = p;
02777                     p->section = sreloc;
02778                     p->count = 0;
02779                   }
02780 
02781                 ++p->count;
02782               }
02783            }
02784 
02785          break;
02786         }
02787     }
02788 
02789   return TRUE;
02790 }
02791 
02792 static int
02793 sh64_elf64_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
02794 {
02795   if (ELF_ST_TYPE (elf_sym->st_info) == STT_DATALABEL)
02796     return STT_DATALABEL;
02797 
02798   return type;
02799 }
02800 
02801 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
02802    Either file can presumably exist without the other, but do not differ
02803    in elf-size-ness.  How to share?
02804 
02805    Hook called by the linker routine which adds symbols from an object
02806    file.  We must make indirect symbols for undefined symbols marked with
02807    STT_DATALABEL, so relocations passing them will pick up that attribute
02808    and neutralize STO_SH5_ISA32 found on the symbol definition.
02809 
02810    There is a problem, though: We want to fill in the hash-table entry for
02811    this symbol and signal to the caller that no further processing is
02812    needed.  But we don't have the index for this hash-table entry.  We
02813    rely here on that the current entry is the first hash-entry with NULL,
02814    which seems brittle.  Also, iterating over the hash-table to find that
02815    entry is a linear operation on the number of symbols in this input
02816    file, and this function should take constant time, so that's not good
02817    too.  Only comfort is that DataLabel references should only be found in
02818    hand-written assembly code and thus be rare.  FIXME: Talk maintainers
02819    into adding an option to elf_add_symbol_hook (preferably) for the index
02820    or the hash entry, alternatively adding the index to Elf_Internal_Sym
02821    (not so good).  */
02822 
02823 static bfd_boolean
02824 sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
02825                          Elf_Internal_Sym *sym, const char **namep,
02826                          flagword *flagsp ATTRIBUTE_UNUSED,
02827                          asection **secp, bfd_vma *valp)
02828 {
02829   /* We want to do this for relocatable as well as final linking.  */
02830   if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL
02831       && is_elf_hash_table (info->hash))
02832     {
02833       struct elf_link_hash_entry *h;
02834 
02835       /* For relocatable links, we register the DataLabel sym in its own
02836         right, and tweak the name when it's output.  Otherwise, we make
02837         an indirect symbol of it.  */
02838       flagword flags
02839        = info->relocatable || info->emitrelocations
02840        ? BSF_GLOBAL : BSF_GLOBAL | BSF_INDIRECT;
02841 
02842       char *dl_name
02843        = bfd_malloc (strlen (*namep) + sizeof (DATALABEL_SUFFIX));
02844       struct elf_link_hash_entry ** sym_hash = elf_sym_hashes (abfd);
02845 
02846       BFD_ASSERT (sym_hash != NULL);
02847 
02848       /* Allocation may fail.  */
02849       if (dl_name == NULL)
02850        return FALSE;
02851 
02852       strcpy (dl_name, *namep);
02853       strcat (dl_name, DATALABEL_SUFFIX);
02854 
02855       h = (struct elf_link_hash_entry *)
02856        bfd_link_hash_lookup (info->hash, dl_name, FALSE, FALSE, FALSE);
02857 
02858       if (h == NULL)
02859        {
02860          /* No previous datalabel symbol.  Make one.  */
02861          struct bfd_link_hash_entry *bh = NULL;
02862          const struct elf_backend_data *bed = get_elf_backend_data (abfd);
02863 
02864          if (! _bfd_generic_link_add_one_symbol (info, abfd, dl_name,
02865                                             flags, *secp, *valp,
02866                                             *namep, FALSE,
02867                                             bed->collect, &bh))
02868            {
02869              free (dl_name);
02870              return FALSE;
02871            }
02872 
02873          h = (struct elf_link_hash_entry *) bh;
02874          h->non_elf = 0;
02875          h->type = STT_DATALABEL;
02876        }
02877       else
02878        /* If a new symbol was created, it holds the allocated name.
02879           Otherwise, we don't need it anymore and should deallocate it.  */
02880        free (dl_name);
02881 
02882       if (h->type != STT_DATALABEL
02883          || ((info->relocatable || info->emitrelocations)
02884              && h->root.type != bfd_link_hash_undefined)
02885          || (! info->relocatable && !info->emitrelocations
02886              && h->root.type != bfd_link_hash_indirect))
02887        {
02888          /* Make sure we don't get confused on invalid input.  */
02889          (*_bfd_error_handler)
02890            (_("%s: encountered datalabel symbol in input"),
02891             bfd_get_filename (abfd));
02892          bfd_set_error (bfd_error_bad_value);
02893          return FALSE;
02894        }
02895 
02896       /* Now find the hash-table slot for this entry and fill it in.  */
02897       while (*sym_hash != NULL)
02898        sym_hash++;
02899       *sym_hash = h;
02900 
02901       /* Signal to caller to skip this symbol - we've handled it.  */
02902       *namep = NULL;
02903     }
02904 
02905   return TRUE;
02906 }
02907 
02908 /* This hook function is called before the linker writes out a global
02909    symbol.  For relocatable links, DataLabel symbols will be present in
02910    linker output.  We cut off the special suffix on those symbols, so the
02911    right name appears in the output.
02912 
02913    When linking and emitting relocations, there can appear global symbols
02914    that are not referenced by relocs, but rather only implicitly through
02915    DataLabel references, a relation that is not visible to the linker.
02916    Since no stripping of global symbols in done when doing such linking,
02917    we don't need to look up and make sure to emit the main symbol for each
02918    DataLabel symbol.  */
02919 
02920 static bfd_boolean
02921 sh64_elf64_link_output_symbol_hook (struct bfd_link_info *info,
02922                                 const char *cname,
02923                                 Elf_Internal_Sym *sym,
02924                                 asection *input_sec ATTRIBUTE_UNUSED,
02925                                 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
02926 {
02927   char *name = (char *) cname;
02928 
02929   if (info->relocatable || info->emitrelocations)
02930     {
02931       if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL)
02932        name[strlen (name) - strlen (DATALABEL_SUFFIX)] = 0;
02933     }
02934 
02935   return TRUE;
02936 }
02937 
02938 /* Set bit 0 on the entry address; it always points to SHmedia code.  This
02939    is mostly for symmetry with the 32-bit format, where code can be
02940    SHcompact and we need to make a distinction to make sure execution
02941    starts in the right ISA mode.  It is also convenient for a loader,
02942    which would otherwise have to set this bit when loading a TR register
02943    before jumping to the program entry.  */
02944 
02945 static void
02946 sh64_elf64_final_write_processing (bfd *abfd,
02947                                bfd_boolean linker ATTRIBUTE_UNUSED)
02948 {
02949   /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
02950      numerically, but we currently lack the infrastructure to recognize
02951      that: The entry symbol, and info whether it is numeric or a symbol
02952      name is kept private in the linker.  */
02953   if (elf_elfheader (abfd)->e_type == ET_EXEC)
02954     elf_elfheader (abfd)->e_entry |= 1;
02955 }
02956 
02957 /* First entry in an absolute procedure linkage table look like this.  */
02958 
02959 static const bfd_byte elf_sh64_plt0_entry_be[PLT_ENTRY_SIZE] =
02960 {
02961   0xcc, 0x00, 0x01, 0x10, /* movi  .got.plt >> 48, r17 */
02962   0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
02963   0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
02964   0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
02965   0x8d, 0x10, 0x09, 0x90, /* ld.q  r17, 16, r25 */
02966   0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
02967   0x8d, 0x10, 0x05, 0x10, /* ld.q  r17, 8, r17 */
02968   0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
02969   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02970   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02971   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02972   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02973   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02974   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02975   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02976   0x6f, 0xf0, 0xff, 0xf0, /* nop */
02977 };
02978 
02979 static const bfd_byte elf_sh64_plt0_entry_le[PLT_ENTRY_SIZE] =
02980 {
02981   0x10, 0x01, 0x00, 0xcc, /* movi  .got.plt >> 16, r17 */
02982   0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
02983   0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
02984   0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
02985   0x90, 0x09, 0x10, 0x8d, /* ld.q  r17, 16, r25 */
02986   0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
02987   0x10, 0x05, 0x10, 0x8d, /* ld.q  r17, 8, r17 */
02988   0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
02989   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02990   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02991   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02992   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02993   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02994   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02995   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02996   0xf0, 0xff, 0xf0, 0x6f, /* nop */
02997 };
02998 
02999 /* Sebsequent entries in an absolute procedure linkage table look like
03000    this.  */
03001 
03002 static const bfd_byte elf_sh64_plt_entry_be[PLT_ENTRY_SIZE] =
03003 {
03004   0xcc, 0x00, 0x01, 0x90, /* movi  nameN-in-GOT >> 48, r25 */
03005   0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
03006   0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
03007   0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
03008   0x8d, 0x90, 0x01, 0x90, /* ld.q  r25, 0, r25 */
03009   0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
03010   0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
03011   0x6f, 0xf0, 0xff, 0xf0, /* nop */
03012   0xcc, 0x00, 0x01, 0x90, /* movi  (.+8-.PLT0) >> 16, r25 */
03013   0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
03014   0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
03015   0xcc, 0x00, 0x01, 0x50, /* movi  reloc-offset >> 16, r21 */
03016   0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
03017   0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
03018   0x6f, 0xf0, 0xff, 0xf0, /* nop */
03019   0x6f, 0xf0, 0xff, 0xf0, /* nop */
03020 };
03021 
03022 static const bfd_byte elf_sh64_plt_entry_le[PLT_ENTRY_SIZE] =
03023 {
03024   0x90, 0x01, 0x00, 0xcc, /* movi  nameN-in-GOT >> 16, r25 */
03025   0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
03026   0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
03027   0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
03028   0x90, 0x01, 0x90, 0x8d, /* ld.q  r25, 0, r25 */
03029   0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
03030   0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
03031   0xf0, 0xff, 0xf0, 0x6f, /* nop */
03032   0x90, 0x01, 0x00, 0xcc, /* movi  (.+8-.PLT0) >> 16, r25 */
03033   0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
03034   0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
03035   0x50, 0x01, 0x00, 0xcc, /* movi  reloc-offset >> 16, r21 */
03036   0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
03037   0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
03038   0xf0, 0xff, 0xf0, 0x6f, /* nop */
03039   0xf0, 0xff, 0xf0, 0x6f, /* nop */
03040 };
03041 
03042 /* Entries in a PIC procedure linkage table look like this.  */
03043 
03044 static const bfd_byte elf_sh64_pic_plt_entry_be[PLT_ENTRY_SIZE] =
03045 {
03046   0xcc, 0x00, 0x01, 0x90, /* movi  nameN@GOT >> 16, r25 */
03047   0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
03048   0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
03049   0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
03050   0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
03051   0x6f, 0xf0, 0xff, 0xf0, /* nop */
03052   0x6f, 0xf0, 0xff, 0xf0, /* nop */
03053   0x6f, 0xf0, 0xff, 0xf0, /* nop */
03054   0xce, 0x00, 0x01, 0x10, /* movi  -GOT_BIAS, r17 */
03055   0x00, 0xc9, 0x45, 0x10, /* add   r12, r17, r17 */
03056   0x8d, 0x10, 0x09, 0x90, /* ld.q  r17, 16, r25 */
03057   0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
03058   0x8d, 0x10, 0x05, 0x10, /* ld.q  r17, 8, r17 */
03059   0xcc, 0x00, 0x01, 0x50, /* movi  reloc-offset >> 16, r21 */
03060   0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
03061   0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
03062 };
03063 
03064 static const bfd_byte elf_sh64_pic_plt_entry_le[PLT_ENTRY_SIZE] =
03065 {
03066   0x90, 0x01, 0x00, 0xcc, /* movi  nameN@GOT >> 16, r25 */
03067   0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
03068   0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
03069   0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
03070   0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
03071   0xf0, 0xff, 0xf0, 0x6f, /* nop */
03072   0xf0, 0xff, 0xf0, 0x6f, /* nop */
03073   0xf0, 0xff, 0xf0, 0x6f, /* nop */
03074   0x10, 0x01, 0x00, 0xce, /* movi  -GOT_BIAS, r17 */
03075   0x10, 0x45, 0xc9, 0x00, /* add   r12, r17, r17 */
03076   0x90, 0x09, 0x10, 0x8d, /* ld.q  r17, 16, r25 */
03077   0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
03078   0x10, 0x05, 0x10, 0x8d, /* ld.q  r17, 8, r17 */
03079   0x50, 0x01, 0x00, 0xcc, /* movi  reloc-offset >> 16, r21 */
03080   0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
03081   0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
03082 };
03083 
03084 static const bfd_byte *elf_sh64_plt0_entry;
03085 static const bfd_byte *elf_sh64_plt_entry;
03086 static const bfd_byte *elf_sh64_pic_plt_entry;
03087 
03088 /* Create an entry in an sh ELF linker hash table.  */
03089 
03090 static struct bfd_hash_entry *
03091 sh64_elf64_link_hash_newfunc (struct bfd_hash_entry *entry,
03092                            struct bfd_hash_table *table,
03093                            const char *string)
03094 {
03095   struct elf_sh64_link_hash_entry *ret =
03096     (struct elf_sh64_link_hash_entry *) entry;
03097 
03098   /* Allocate the structure if it has not already been allocated by a
03099      subclass.  */
03100   if (ret == (struct elf_sh64_link_hash_entry *) NULL)
03101     ret = ((struct elf_sh64_link_hash_entry *)
03102           bfd_hash_allocate (table,
03103                            sizeof (struct elf_sh64_link_hash_entry)));
03104   if (ret == (struct elf_sh64_link_hash_entry *) NULL)
03105     return (struct bfd_hash_entry *) ret;
03106 
03107   /* Call the allocation method of the superclass.  */
03108   ret = ((struct elf_sh64_link_hash_entry *)
03109         _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
03110                                  table, string));
03111   if (ret != (struct elf_sh64_link_hash_entry *) NULL)
03112     {
03113       ret->pcrel_relocs_copied = NULL;
03114       ret->datalabel_got_offset = (bfd_vma) -1;
03115     }
03116 
03117   return (struct bfd_hash_entry *) ret;
03118 }
03119 
03120 /* Create an sh64 ELF linker hash table.  */
03121 
03122 static struct bfd_link_hash_table *
03123 sh64_elf64_link_hash_table_create (bfd *abfd)
03124 {
03125   struct elf_sh64_link_hash_table *ret;
03126 
03127   ret = ((struct elf_sh64_link_hash_table *)
03128         bfd_malloc (sizeof (struct elf_sh64_link_hash_table)));
03129   if (ret == (struct elf_sh64_link_hash_table *) NULL)
03130     return NULL;
03131 
03132   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
03133                                   sh64_elf64_link_hash_newfunc,
03134                                   sizeof (struct elf_sh64_link_hash_entry)))
03135     {
03136       free (ret);
03137       return NULL;
03138     }
03139 
03140   return &ret->root.root;
03141 }
03142 
03143 inline static void
03144 movi_shori_putval (bfd *output_bfd, unsigned long value, bfd_byte *addr)
03145 {
03146   bfd_put_32 (output_bfd,
03147              bfd_get_32 (output_bfd, addr)
03148              | ((value >> 6) & 0x3fffc00),
03149              addr);
03150   bfd_put_32 (output_bfd,
03151              bfd_get_32 (output_bfd, addr + 4)
03152              | ((value << 10) & 0x3fffc00),
03153              addr + 4);
03154 }
03155 
03156 inline static void
03157 movi_3shori_putval (bfd *output_bfd, bfd_vma value, bfd_byte *addr)
03158 {
03159   bfd_put_32 (output_bfd,
03160              bfd_get_32 (output_bfd, addr)
03161              | ((value >> 38) & 0x3fffc00),
03162              addr);
03163   bfd_put_32 (output_bfd,
03164              bfd_get_32 (output_bfd, addr + 4)
03165              | ((value >> 22) & 0x3fffc00),
03166              addr + 4);
03167   bfd_put_32 (output_bfd,
03168              bfd_get_32 (output_bfd, addr + 8)
03169              | ((value >> 6) & 0x3fffc00),
03170              addr + 8);
03171   bfd_put_32 (output_bfd,
03172              bfd_get_32 (output_bfd, addr + 12)
03173              | ((value << 10) & 0x3fffc00),
03174              addr + 12);
03175 }
03176 
03177 /* Create dynamic sections when linking against a dynamic object.  */
03178 
03179 static bfd_boolean
03180 sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
03181 {
03182   flagword flags, pltflags;
03183   register asection *s;
03184   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
03185   int ptralign = 0;
03186 
03187   switch (bed->s->arch_size)
03188     {
03189     case 32:
03190       ptralign = 2;
03191       break;
03192 
03193     case 64:
03194       ptralign = 3;
03195       break;
03196 
03197     default:
03198       bfd_set_error (bfd_error_bad_value);
03199       return FALSE;
03200     }
03201 
03202   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
03203      .rel[a].bss sections.  */
03204 
03205   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
03206           | SEC_LINKER_CREATED);
03207 
03208   pltflags = flags;
03209   pltflags |= SEC_CODE;
03210   if (bed->plt_not_loaded)
03211     pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
03212   if (bed->plt_readonly)
03213     pltflags |= SEC_READONLY;
03214 
03215   s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
03216   if (s == NULL
03217       || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
03218     return FALSE;
03219 
03220   if (bed->want_plt_sym)
03221     {
03222       /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
03223         .plt section.  */
03224       struct elf_link_hash_entry *h;
03225       struct bfd_link_hash_entry *bh = NULL;
03226 
03227       if (! (_bfd_generic_link_add_one_symbol
03228             (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
03229              (bfd_vma) 0, (const char *) NULL, FALSE, bed->collect, &bh)))
03230        return FALSE;
03231 
03232       h = (struct elf_link_hash_entry *) bh;
03233       h->def_regular = 1;
03234       h->type = STT_OBJECT;
03235       elf_hash_table (info)->hplt = h;
03236 
03237       if (info->shared
03238          && ! bfd_elf_link_record_dynamic_symbol (info, h))
03239        return FALSE;
03240     }
03241 
03242   s = bfd_make_section_with_flags (abfd,
03243                                bed->default_use_rela_p ? ".rela.plt" : ".rel.plt",
03244                                flags | SEC_READONLY);
03245   if (s == NULL
03246       || ! bfd_set_section_alignment (abfd, s, ptralign))
03247     return FALSE;
03248 
03249   if (! _bfd_elf_create_got_section (abfd, info))
03250     return FALSE;
03251 
03252   {
03253     const char *secname;
03254     char *relname;
03255     flagword secflags;
03256     asection *sec;
03257 
03258     for (sec = abfd->sections; sec; sec = sec->next)
03259       {
03260        secflags = bfd_get_section_flags (abfd, sec);
03261        if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
03262            || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
03263          continue;
03264        secname = bfd_get_section_name (abfd, sec);
03265        relname = (char *) bfd_malloc (strlen (secname) + 6);
03266        strcpy (relname, ".rela");
03267        strcat (relname, secname);
03268        s = bfd_make_section_with_flags (abfd, relname,
03269                                     flags | SEC_READONLY);
03270        if (s == NULL
03271            || ! bfd_set_section_alignment (abfd, s, ptralign))
03272          return FALSE;
03273       }
03274   }
03275 
03276   if (bed->want_dynbss)
03277     {
03278       /* The .dynbss section is a place to put symbols which are defined
03279         by dynamic objects, are referenced by regular objects, and are
03280         not functions.  We must allocate space for them in the process
03281         image and use a R_*_COPY reloc to tell the dynamic linker to
03282         initialize them at run time.  The linker script puts the .dynbss
03283         section into the .bss section of the final image.  */
03284       s = bfd_make_section_with_flags (abfd, ".dynbss",
03285                                    SEC_ALLOC | SEC_LINKER_CREATED);
03286       if (s == NULL)
03287        return FALSE;
03288 
03289       /* The .rel[a].bss section holds copy relocs.  This section is not
03290         normally needed.  We need to create it here, though, so that the
03291         linker will map it to an output section.  We can't just create it
03292         only if we need it, because we will not know whether we need it
03293         until we have seen all the input files, and the first time the
03294         main linker code calls BFD after examining all the input files
03295         (size_dynamic_sections) the input sections have already been
03296         mapped to the output sections.  If the section turns out not to
03297         be needed, we can discard it later.  We will never need this
03298         section when generating a shared object, since they do not use
03299         copy relocs.  */
03300       if (! info->shared)
03301        {
03302          s = bfd_make_section_with_flags (abfd,
03303                                       (bed->default_use_rela_p
03304                                        ? ".rela.bss" : ".rel.bss"),
03305                                       flags | SEC_READONLY);
03306          if (s == NULL
03307              || ! bfd_set_section_alignment (abfd, s, ptralign))
03308            return FALSE;
03309        }
03310     }
03311 
03312   return TRUE;
03313 }
03314 
03315 /* Adjust a symbol defined by a dynamic object and referenced by a
03316    regular object.  The current definition is in some section of the
03317    dynamic object, but we're not including those sections.  We have to
03318    change the definition to something the rest of the link can
03319    understand.  */
03320 
03321 static bfd_boolean
03322 sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
03323                               struct elf_link_hash_entry *h)
03324 {
03325   bfd *dynobj;
03326   asection *s;
03327   unsigned int power_of_two;
03328 
03329   dynobj = elf_hash_table (info)->dynobj;
03330 
03331   /* Make sure we know what is going on here.  */
03332   BFD_ASSERT (dynobj != NULL
03333              && (h->needs_plt
03334                 || h->u.weakdef != NULL
03335                 || (h->def_dynamic
03336                     && h->ref_regular
03337                     && !h->def_regular)));
03338 
03339   /* If this is a function, put it in the procedure linkage table.  We
03340      will fill in the contents of the procedure linkage table later,
03341      when we know the address of the .got section.  */
03342   if (h->type == STT_FUNC
03343       || h->needs_plt)
03344     {
03345       if (! info->shared
03346          && !h->def_dynamic
03347          && !h->ref_dynamic)
03348        {
03349          /* This case can occur if we saw a PLT reloc in an input
03350             file, but the symbol was never referred to by a dynamic
03351             object.  In such a case, we don't actually need to build
03352             a procedure linkage table, and we can just do a REL64
03353             reloc instead.  */
03354          BFD_ASSERT (h->needs_plt);
03355          return TRUE;
03356        }
03357 
03358       /* Make sure this symbol is output as a dynamic symbol.  */
03359       if (h->dynindx == -1)
03360        {
03361          if (! bfd_elf_link_record_dynamic_symbol (info, h))
03362            return FALSE;
03363        }
03364 
03365       s = bfd_get_section_by_name (dynobj, ".plt");
03366       BFD_ASSERT (s != NULL);
03367 
03368       /* If this is the first .plt entry, make room for the special
03369         first entry.  */
03370       if (s->size == 0)
03371        s->size += PLT_ENTRY_SIZE;
03372 
03373       /* If this symbol is not defined in a regular file, and we are
03374         not generating a shared library, then set the symbol to this
03375         location in the .plt.  This is required to make function
03376         pointers compare as equal between the normal executable and
03377         the shared library.  */
03378       if (! info->shared
03379          && !h->def_regular)
03380        {
03381          h->root.u.def.section = s;
03382          h->root.u.def.value = s->size;
03383        }
03384 
03385       h->plt.offset = s->size;
03386 
03387       /* Make room for this entry.  */
03388       s->size += elf_sh64_sizeof_plt (info);
03389 
03390       /* We also need to make an entry in the .got.plt section, which
03391         will be placed in the .got section by the linker script.  */
03392 
03393       s = bfd_get_section_by_name (dynobj, ".got.plt");
03394       BFD_ASSERT (s != NULL);
03395       s->size += 8;
03396 
03397       /* We also need to make an entry in the .rela.plt section.  */
03398 
03399       s = bfd_get_section_by_name (dynobj, ".rela.plt");
03400       BFD_ASSERT (s != NULL);
03401       s->size += sizeof (Elf64_External_Rela);
03402 
03403       return TRUE;
03404     }
03405 
03406   /* If this is a weak symbol, and there is a real definition, the
03407      processor independent code will have arranged for us to see the
03408      real definition first, and we can just use the same value.  */
03409   if (h->u.weakdef != NULL)
03410     {
03411       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
03412                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
03413       h->root.u.def.section = h->u.weakdef->root.u.def.section;
03414       h->root.u.def.value = h->u.weakdef->root.u.def.value;
03415       return TRUE;
03416     }
03417 
03418   /* This is a reference to a symbol defined by a dynamic object which
03419      is not a function.  */
03420 
03421   /* If we are creating a shared library, we must presume that the
03422      only references to the symbol are via the global offset table.
03423      For such cases we need not do anything here; the relocations will
03424      be handled correctly by relocate_section.  */
03425   if (info->shared)
03426     return TRUE;
03427 
03428   /* If there are no references to this symbol that do not use the
03429      GOT, we don't need to generate a copy reloc.  */
03430   if (!h->non_got_ref)
03431     return TRUE;
03432 
03433   if (h->size == 0)
03434     {
03435       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
03436                           h->root.root.string);
03437       return TRUE;
03438     }
03439 
03440   /* We must allocate the symbol in our .dynbss section, which will
03441      become part of the .bss section of the executable.  There will be
03442      an entry for this symbol in the .dynsym section.  The dynamic
03443      object will contain position independent code, so all references
03444      from the dynamic object to this symbol will go through the global
03445      offset table.  The dynamic linker will use the .dynsym entry to
03446      determine the address it must put in the global offset table, so
03447      both the dynamic object and the regular object will refer to the
03448      same memory location for the variable.  */
03449 
03450   s = bfd_get_section_by_name (dynobj, ".dynbss");
03451   BFD_ASSERT (s != NULL);
03452 
03453   /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
03454      copy the initial value out of the dynamic object and into the
03455      runtime process image.  We need to remember the offset into the
03456      .rela.bss section we are going to use.  */
03457   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
03458     {
03459       asection *srel;
03460 
03461       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
03462       BFD_ASSERT (srel != NULL);
03463       srel->size += sizeof (Elf64_External_Rela);
03464       h->needs_copy = 1;
03465     }
03466 
03467   /* We need to figure out the alignment required for this symbol.  I
03468      have no idea how ELF linkers handle this.  */
03469   power_of_two = bfd_log2 (h->size);
03470   if (power_of_two > 3)
03471     power_of_two = 3;
03472 
03473   /* Apply the required alignment.  */
03474   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
03475   if (power_of_two > bfd_get_section_alignment (dynobj, s))
03476     {
03477       if (! bfd_set_section_alignment (dynobj, s, power_of_two))
03478        return FALSE;
03479     }
03480 
03481   /* Define the symbol as being at this point in the section.  */
03482   h->root.u.def.section = s;
03483   h->root.u.def.value = s->size;
03484 
03485   /* Increment the section size to make room for the symbol.  */
03486   s->size += h->size;
03487 
03488   return TRUE;
03489 }
03490 
03491 /* This function is called via sh_elf_link_hash_traverse if we are
03492    creating a shared object with -Bsymbolic.  It discards the space
03493    allocated to copy PC relative relocs against symbols which are
03494    defined in regular objects.  We allocated space for them in the
03495    check_relocs routine, but we won't fill them in in the
03496    relocate_section routine.  */
03497 
03498 static bfd_boolean
03499 sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry *h,
03500                         void *ignore ATTRIBUTE_UNUSED)
03501 {
03502   struct elf_sh64_pcrel_relocs_copied *s;
03503 
03504   if (h->root.root.type == bfd_link_hash_warning)
03505     h = (struct elf_sh64_link_hash_entry *) h->root.root.u.i.link;
03506 
03507   /* We only discard relocs for symbols defined in a regular object.  */
03508   if (!h->root.def_regular)
03509     return TRUE;
03510 
03511   for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
03512     s->section->size -= s->count * sizeof (Elf64_External_Rela);
03513 
03514   return TRUE;
03515 }
03516 
03517 /* Set the sizes of the dynamic sections.  */
03518 
03519 static bfd_boolean
03520 sh64_elf64_size_dynamic_sections (bfd *output_bfd,
03521                               struct bfd_link_info *info)
03522 {
03523   bfd *dynobj;
03524   asection *s;
03525   bfd_boolean plt;
03526   bfd_boolean relocs;
03527   bfd_boolean reltext;
03528 
03529   dynobj = elf_hash_table (info)->dynobj;
03530   BFD_ASSERT (dynobj != NULL);
03531 
03532   if (elf_hash_table (info)->dynamic_sections_created)
03533     {
03534       /* Set the contents of the .interp section to the interpreter.  */
03535       if (info->executable)
03536        {
03537          s = bfd_get_section_by_name (dynobj, ".interp");
03538          BFD_ASSERT (s != NULL);
03539          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
03540          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
03541        }
03542     }
03543   else
03544     {
03545       /* We may have created entries in the .rela.got section.
03546         However, if we are not creating the dynamic sections, we will
03547         not actually use these entries.  Reset the size of .rela.got,
03548         which will cause it to get stripped from the output file
03549         below.  */
03550       s = bfd_get_section_by_name (dynobj, ".rela.got");
03551       if (s != NULL)
03552        s->size = 0;
03553     }
03554 
03555   /* If this is a -Bsymbolic shared link, then we need to discard all
03556      PC relative relocs against symbols defined in a regular object.
03557      We allocated space for them in the check_relocs routine, but we
03558      will not fill them in in the relocate_section routine.  */
03559   if (info->shared && info->symbolic)
03560     sh64_elf64_link_hash_traverse (sh64_elf64_hash_table (info),
03561                                sh64_elf64_discard_copies, NULL);
03562 
03563   /* The check_relocs and adjust_dynamic_symbol entry points have
03564      determined the sizes of the various dynamic sections.  Allocate
03565      memory for them.  */
03566   plt = FALSE;
03567   relocs = FALSE;
03568   reltext = FALSE;
03569   for (s = dynobj->sections; s != NULL; s = s->next)
03570     {
03571       const char *name;
03572 
03573       if ((s->flags & SEC_LINKER_CREATED) == 0)
03574        continue;
03575 
03576       /* It's OK to base decisions on the section name, because none
03577         of the dynobj section names depend upon the input files.  */
03578       name = bfd_get_section_name (dynobj, s);
03579 
03580       if (strcmp (name, ".plt") == 0)
03581        {
03582          /* Remember whether there is a PLT.  */
03583          plt = s->size != 0;
03584        }
03585       else if (CONST_STRNEQ (name, ".rela"))
03586        {
03587          if (s->size != 0)
03588            {
03589              asection *target;
03590 
03591              /* Remember whether there are any reloc sections other
03592                than .rela.plt.  */
03593              if (strcmp (name, ".rela.plt") != 0)
03594               {
03595                 const char *outname;
03596 
03597                 relocs = TRUE;
03598 
03599                 /* If this relocation section applies to a read only
03600                    section, then we probably need a DT_TEXTREL
03601                    entry.  The entries in the .rela.plt section
03602                    really apply to the .got section, which we
03603                    created ourselves and so know is not readonly.  */
03604                 outname = bfd_get_section_name (output_bfd,
03605                                             s->output_section);
03606                 target = bfd_get_section_by_name (output_bfd, outname + 5);
03607                 if (target != NULL
03608                     && (target->flags & SEC_READONLY) != 0
03609                     && (target->flags & SEC_ALLOC) != 0)
03610                   reltext = TRUE;
03611               }
03612 
03613              /* We use the reloc_count field as a counter if we need
03614                to copy relocs into the output file.  */
03615              s->reloc_count = 0;
03616            }
03617        }
03618       else if (! CONST_STRNEQ (name, ".got")
03619               && strcmp (name, ".dynbss") != 0)
03620        {
03621          /* It's not one of our sections, so don't allocate space.  */
03622          continue;
03623        }
03624 
03625       if (s->size == 0)
03626        {
03627          /* If we don't need this section, strip it from the
03628             output file.  This is mostly to handle .rela.bss and
03629             .rela.plt.  We must create both sections in
03630             create_dynamic_sections, because they must be created
03631             before the linker maps input sections to output
03632             sections.  The linker does that before
03633             adjust_dynamic_symbol is called, and it is that
03634             function which decides whether anything needs to go
03635             into these sections.  */
03636          s->flags |= SEC_EXCLUDE;
03637          continue;
03638        }
03639 
03640       if ((s->flags & SEC_HAS_CONTENTS) == 0)
03641        continue;
03642 
03643       /* Allocate memory for the section contents.  */
03644       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
03645       if (s->contents == NULL)
03646        return FALSE;
03647     }
03648 
03649   if (elf_hash_table (info)->dynamic_sections_created)
03650     {
03651       /* Add some entries to the .dynamic section.  We fill in the
03652         values later, in sh64_elf64_finish_dynamic_sections, but we
03653         must add the entries now so that we get the correct size for
03654         the .dynamic section.  The DT_DEBUG entry is filled in by the
03655         dynamic linker and used by the debugger.  */
03656       if (info->executable)
03657        {
03658          if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
03659            return FALSE;
03660        }
03661 
03662       if (plt)
03663        {
03664          if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
03665              || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
03666              || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
03667              || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
03668            return FALSE;
03669        }
03670 
03671       if (relocs)
03672        {
03673          if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
03674              || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
03675              || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
03676                                          sizeof (Elf64_External_Rela)))
03677            return FALSE;
03678        }
03679 
03680       if (reltext)
03681        {
03682          if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
03683            return FALSE;
03684        }
03685     }
03686 
03687   return TRUE;
03688 }
03689 
03690 /* Finish up dynamic symbol handling.  We set the contents of various
03691    dynamic sections here.  */
03692 
03693 static bfd_boolean
03694 sh64_elf64_finish_dynamic_symbol (bfd *output_bfd,
03695                               struct bfd_link_info *info,
03696                               struct elf_link_hash_entry *h,
03697                               Elf_Internal_Sym *sym)
03698 {
03699   bfd *dynobj;
03700 
03701   dynobj = elf_hash_table (info)->dynobj;
03702 
03703   if (h->plt.offset != (bfd_vma) -1)
03704     {
03705       asection *splt;
03706       asection *sgot;
03707       asection *srel;
03708 
03709       bfd_vma plt_index;
03710       bfd_vma got_offset;
03711       Elf_Internal_Rela rel;
03712       bfd_byte *loc;
03713 
03714       /* This symbol has an entry in the procedure linkage table.  Set
03715         it up.  */
03716 
03717       BFD_ASSERT (h->dynindx != -1);
03718 
03719       splt = bfd_get_section_by_name (dynobj, ".plt");
03720       sgot = bfd_get_section_by_name (dynobj, ".got.plt");
03721       srel = bfd_get_section_by_name (dynobj, ".rela.plt");
03722       BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
03723 
03724       /* Get the index in the procedure linkage table which
03725         corresponds to this symbol.  This is the index of this symbol
03726         in all the symbols for which we are making plt entries.  The
03727         first entry in the procedure linkage table is reserved.  */
03728       plt_index = h->plt.offset / elf_sh64_sizeof_plt (info) - 1;
03729 
03730       /* Get the offset into the .got table of the entry that
03731         corresponds to this function.  Each .got entry is 8 bytes.
03732         The first three are reserved.  */
03733       got_offset = (plt_index + 3) * 8;
03734 
03735       if (info->shared)
03736        got_offset -= GOT_BIAS;
03737 
03738       /* Fill in the entry in the procedure linkage table.  */
03739       if (! info->shared)
03740        {
03741          if (elf_sh64_plt_entry == NULL)
03742            {
03743              elf_sh64_plt_entry = (bfd_big_endian (output_bfd) ?
03744                               elf_sh64_plt_entry_be : elf_sh64_plt_entry_le);
03745            }
03746          memcpy (splt->contents + h->plt.offset, elf_sh64_plt_entry,
03747                 elf_sh64_sizeof_plt (info));
03748          movi_3shori_putval (output_bfd,
03749                            (sgot->output_section->vma
03750                             + sgot->output_offset
03751                             + got_offset),
03752                            (splt->contents + h->plt.offset
03753                             + elf_sh64_plt_symbol_offset (info)));
03754 
03755          /* Set bottom bit because its for a branch to SHmedia */
03756          movi_shori_putval (output_bfd,
03757                           -(h->plt.offset
03758                            + elf_sh64_plt_plt0_offset (info) + 8)
03759                           | 1,
03760                           (splt->contents + h->plt.offset
03761                            + elf_sh64_plt_plt0_offset (info)));
03762        }
03763       else
03764        {
03765          if (elf_sh64_pic_plt_entry == NULL)
03766            {
03767              elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
03768                                   elf_sh64_pic_plt_entry_be :
03769                                   elf_sh64_pic_plt_entry_le);
03770            }
03771          memcpy (splt->contents + h->plt.offset, elf_sh64_pic_plt_entry,
03772                 elf_sh64_sizeof_plt (info));
03773          movi_shori_putval (output_bfd, got_offset,
03774                           (splt->contents + h->plt.offset
03775                            + elf_sh64_plt_symbol_offset (info)));
03776        }
03777 
03778       if (info->shared)
03779        got_offset += GOT_BIAS;
03780 
03781       movi_shori_putval (output_bfd,
03782                       plt_index * sizeof (Elf64_External_Rela),
03783                       (splt->contents + h->plt.offset
03784                        + elf_sh64_plt_reloc_offset (info)));
03785 
03786       /* Fill in the entry in the global offset table.  */
03787       bfd_put_64 (output_bfd,
03788                 (splt->output_section->vma
03789                  + splt->output_offset
03790                  + h->plt.offset
03791                  + elf_sh64_plt_temp_offset (info)),
03792                 sgot->contents + got_offset);
03793 
03794       /* Fill in the entry in the .rela.plt section.  */
03795       rel.r_offset = (sgot->output_section->vma
03796                     + sgot->output_offset
03797                     + got_offset);
03798       rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_JMP_SLOT64);
03799       rel.r_addend = 0;
03800       rel.r_addend = GOT_BIAS;
03801       loc = srel->contents + plt_index * sizeof (Elf64_External_Rela);
03802       bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
03803 
03804       if (!h->def_regular)
03805        {
03806          /* Mark the symbol as undefined, rather than as defined in
03807             the .plt section.  Leave the value alone.  */
03808          sym->st_shndx = SHN_UNDEF;
03809        }
03810     }
03811 
03812   if (h->got.offset != (bfd_vma) -1)
03813     {
03814       asection *sgot;
03815       asection *srel;
03816       Elf_Internal_Rela rel;
03817       bfd_byte *loc;
03818 
03819       /* This symbol has an entry in the global offset table.  Set it
03820         up.  */
03821 
03822       sgot = bfd_get_section_by_name (dynobj, ".got");
03823       srel = bfd_get_section_by_name (dynobj, ".rela.got");
03824       BFD_ASSERT (sgot != NULL && srel != NULL);
03825 
03826       rel.r_offset = (sgot->output_section->vma
03827                     + sgot->output_offset
03828                     + (h->got.offset &~ 1));
03829 
03830       /* If this is a -Bsymbolic link, and the symbol is defined
03831         locally, we just want to emit a RELATIVE reloc.  Likewise if
03832         the symbol was forced to be local because of a version file.
03833         The entry in the global offset table will already have been
03834         initialized in the relocate_section function.  */
03835       if (info->shared
03836          && (info->symbolic || h->dynindx == -1)
03837          && h->def_regular)
03838        {
03839          rel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
03840          rel.r_addend = (h->root.u.def.value
03841                        + h->root.u.def.section->output_section->vma
03842                        + h->root.u.def.section->output_offset);
03843        }
03844       else
03845        {
03846          bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
03847          rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_GLOB_DAT64);
03848          rel.r_addend = 0;
03849        }
03850 
03851       loc = srel->contents;
03852       loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
03853       bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
03854     }
03855 
03856   if (h->needs_copy)
03857     {
03858       asection *s;
03859       Elf_Internal_Rela rel;
03860       bfd_byte *loc;
03861 
03862       /* This symbol needs a copy reloc.  Set it up.  */
03863 
03864       BFD_ASSERT (h->dynindx != -1
03865                 && (h->root.type == bfd_link_hash_defined
03866                     || h->root.type == bfd_link_hash_defweak));
03867 
03868       s = bfd_get_section_by_name (h->root.u.def.section->owner,
03869                                ".rela.bss");
03870       BFD_ASSERT (s != NULL);
03871 
03872       rel.r_offset = (h->root.u.def.value
03873                     + h->root.u.def.section->output_section->vma
03874                     + h->root.u.def.section->output_offset);
03875       rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_COPY64);
03876       rel.r_addend = 0;
03877       loc = s->contents;
03878       loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
03879       bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
03880     }
03881 
03882   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
03883   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
03884       || h == elf_hash_table (info)->hgot)
03885     sym->st_shndx = SHN_ABS;
03886 
03887   return TRUE;
03888 }
03889 
03890 /* Finish up the dynamic sections.  */
03891 
03892 static bfd_boolean
03893 sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
03894                                 struct bfd_link_info *info)
03895 {
03896   bfd *dynobj;
03897   asection *sgot;
03898   asection *sdyn;
03899 
03900   dynobj = elf_hash_table (info)->dynobj;
03901 
03902   sgot = bfd_get_section_by_name (dynobj, ".got.plt");
03903   BFD_ASSERT (sgot != NULL);
03904   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
03905 
03906   if (elf_hash_table (info)->dynamic_sections_created)
03907     {
03908       asection *splt;
03909       Elf64_External_Dyn *dyncon, *dynconend;
03910 
03911       BFD_ASSERT (sdyn != NULL);
03912 
03913       dyncon = (Elf64_External_Dyn *) sdyn->contents;
03914       dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
03915       for (; dyncon < dynconend; dyncon++)
03916        {
03917          Elf_Internal_Dyn dyn;
03918          const char *name;
03919          asection *s;
03920          struct elf_link_hash_entry *h;
03921 
03922          bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
03923 
03924          switch (dyn.d_tag)
03925            {
03926            default:
03927              break;
03928 
03929            case DT_INIT:
03930              name = info->init_function;
03931              goto get_sym;
03932 
03933            case DT_FINI:
03934              name = info->fini_function;
03935            get_sym:
03936              if (dyn.d_un.d_val != 0)
03937               {
03938                 h = elf_link_hash_lookup (elf_hash_table (info), name,
03939                                        FALSE, FALSE, TRUE);
03940                 if (h != NULL && (h->other & STO_SH5_ISA32))
03941                   {
03942                     dyn.d_un.d_val |= 1;
03943                     bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
03944                   }
03945               }
03946              break;
03947 
03948            case DT_PLTGOT:
03949              name = ".got";
03950              goto get_vma;
03951 
03952            case DT_JMPREL:
03953              name = ".rela.plt";
03954            get_vma:
03955              s = bfd_get_section_by_name (output_bfd, name);
03956              BFD_ASSERT (s != NULL);
03957              dyn.d_un.d_ptr = s->vma;
03958              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
03959              break;
03960 
03961            case DT_PLTRELSZ:
03962              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
03963              BFD_ASSERT (s != NULL);
03964              dyn.d_un.d_val = s->size;
03965              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
03966              break;
03967 
03968            case DT_RELASZ:
03969              /* My reading of the SVR4 ABI indicates that the
03970                procedure linkage table relocs (DT_JMPREL) should be
03971                included in the overall relocs (DT_RELA).  This is
03972                what Solaris does.  However, UnixWare can not handle
03973                that case.  Therefore, we override the DT_RELASZ entry
03974                here to make it not include the JMPREL relocs.  Since
03975                the linker script arranges for .rela.plt to follow all
03976                other relocation sections, we don't have to worry
03977                about changing the DT_RELA entry.  */
03978              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
03979              if (s != NULL)
03980               dyn.d_un.d_val -= s->size;
03981              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
03982              break;
03983            }
03984        }
03985 
03986       /* Fill in the first entry in the procedure linkage table.  */
03987       splt = bfd_get_section_by_name (dynobj, ".plt");
03988       if (splt && splt->size > 0)
03989        {
03990          if (info->shared)
03991            {
03992              if (elf_sh64_pic_plt_entry == NULL)
03993               {
03994                 elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
03995                                      elf_sh64_pic_plt_entry_be :
03996                                      elf_sh64_pic_plt_entry_le);
03997               }
03998              memcpy (splt->contents, elf_sh64_pic_plt_entry,
03999                     elf_sh64_sizeof_plt (info));
04000            }
04001          else
04002            {
04003              if (elf_sh64_plt0_entry == NULL)
04004               {
04005                 elf_sh64_plt0_entry = (bfd_big_endian (output_bfd) ?
04006                                    elf_sh64_plt0_entry_be :
04007                                    elf_sh64_plt0_entry_le);
04008               }
04009              memcpy (splt->contents, elf_sh64_plt0_entry, PLT_ENTRY_SIZE);
04010              movi_3shori_putval (output_bfd,
04011                               sgot->output_section->vma
04012                               + sgot->output_offset,
04013                               splt->contents
04014                               + elf_sh64_plt0_gotplt_offset (info));
04015            }
04016 
04017          /* UnixWare sets the entsize of .plt to 8, although that doesn't
04018             really seem like the right value.  */
04019          elf_section_data (splt->output_section)->this_hdr.sh_entsize = 8;
04020        }
04021     }
04022 
04023   /* Fill in the first three entries in the global offset table.  */
04024   if (sgot->size > 0)
04025     {
04026       if (sdyn == NULL)
04027        bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
04028       else
04029        bfd_put_64 (output_bfd,
04030                   sdyn->output_section->vma + sdyn->output_offset,
04031                   sgot->contents);
04032       bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
04033       bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 16);
04034     }
04035 
04036   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 8;
04037 
04038   return TRUE;
04039 }
04040 
04041 /* Merge non visibility st_other attribute when the symbol comes from
04042    a dynamic object.  */
04043 static void
04044 sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry *h,
04045                                const Elf_Internal_Sym *isym,
04046                                bfd_boolean definition,
04047                                bfd_boolean dynamic ATTRIBUTE_UNUSED)
04048 {
04049   if ((isym->st_other & ~ELF_ST_VISIBILITY (-1)) != 0)
04050     {
04051       unsigned char other;
04052 
04053       /* Take the balance of OTHER from the definition.  */
04054       other = (definition ? isym->st_other : h->other);
04055       other &= ~ ELF_ST_VISIBILITY (-1);
04056       h->other = other | ELF_ST_VISIBILITY (h->other);
04057     }
04058 
04059   return;
04060 }
04061 
04062 static const struct bfd_elf_special_section sh64_elf64_special_sections[]=
04063 {
04064   { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS, 0 },
04065   { NULL,                       0, 0, 0,            0 }
04066 };
04067 
04068 #define TARGET_BIG_SYM             bfd_elf64_sh64_vec
04069 #define TARGET_BIG_NAME            "elf64-sh64"
04070 #define TARGET_LITTLE_SYM   bfd_elf64_sh64l_vec
04071 #define TARGET_LITTLE_NAME  "elf64-sh64l"
04072 #define ELF_ARCH            bfd_arch_sh
04073 #define ELF_MACHINE_CODE    EM_SH
04074 #define ELF_MAXPAGESIZE            128
04075 
04076 #define elf_symbol_leading_char '_'
04077 
04078 #define bfd_elf64_bfd_reloc_type_lookup   sh_elf64_reloc_type_lookup
04079 #define bfd_elf64_bfd_reloc_name_lookup \
04080                                    sh_elf64_reloc_name_lookup
04081 #define elf_info_to_howto          sh_elf64_info_to_howto
04082 
04083 /* Note: there's no relaxation at present.  */
04084 
04085 #define elf_backend_relocate_section      sh_elf64_relocate_section
04086 #define bfd_elf64_bfd_get_relocated_section_contents \
04087                                    sh_elf64_get_relocated_section_contents
04088 #define elf_backend_object_p              sh_elf64_set_mach_from_flags
04089 #define bfd_elf64_bfd_set_private_flags \
04090                                    sh_elf64_set_private_flags
04091 #define bfd_elf64_bfd_copy_private_bfd_data \
04092                                    sh_elf64_copy_private_data
04093 #define bfd_elf64_bfd_merge_private_bfd_data \
04094                                    sh_elf64_merge_private_data
04095 #define elf_backend_fake_sections  sh64_elf64_fake_sections
04096 
04097 #define elf_backend_gc_mark_hook        sh_elf64_gc_mark_hook
04098 #define elf_backend_check_relocs        sh_elf64_check_relocs
04099 
04100 #define elf_backend_can_gc_sections       1
04101 
04102 #define elf_backend_get_symbol_type       sh64_elf64_get_symbol_type
04103 
04104 #define elf_backend_add_symbol_hook       sh64_elf64_add_symbol_hook
04105 
04106 #define elf_backend_link_output_symbol_hook \
04107        sh64_elf64_link_output_symbol_hook
04108 
04109 #define       elf_backend_merge_symbol_attribute \
04110        sh64_elf64_merge_symbol_attribute
04111 
04112 #define elf_backend_final_write_processing \
04113        sh64_elf64_final_write_processing
04114 
04115 #define elf_backend_create_dynamic_sections \
04116                                    sh64_elf64_create_dynamic_sections
04117 #define bfd_elf64_bfd_link_hash_table_create \
04118                                    sh64_elf64_link_hash_table_create
04119 #define elf_backend_adjust_dynamic_symbol \
04120                                    sh64_elf64_adjust_dynamic_symbol
04121 #define elf_backend_size_dynamic_sections \
04122                                    sh64_elf64_size_dynamic_sections
04123 #define elf_backend_omit_section_dynsym \
04124   ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
04125 #define elf_backend_finish_dynamic_symbol \
04126                                    sh64_elf64_finish_dynamic_symbol
04127 #define elf_backend_finish_dynamic_sections \
04128                                    sh64_elf64_finish_dynamic_sections
04129 #define elf_backend_special_sections      sh64_elf64_special_sections
04130 
04131 #define elf_backend_want_got_plt   1
04132 #define elf_backend_plt_readonly   1
04133 #define elf_backend_want_plt_sym   0
04134 #define elf_backend_got_header_size       24
04135 
04136 #include "elf64-target.h"
04137 
04138 /* NetBSD support.  */
04139 #undef TARGET_BIG_SYM
04140 #define       TARGET_BIG_SYM                     bfd_elf64_sh64nbsd_vec
04141 #undef TARGET_BIG_NAME
04142 #define       TARGET_BIG_NAME                    "elf64-sh64-nbsd"
04143 #undef TARGET_LITTLE_SYM
04144 #define       TARGET_LITTLE_SYM           bfd_elf64_sh64lnbsd_vec
04145 #undef TARGET_LITTLE_NAME
04146 #define       TARGET_LITTLE_NAME          "elf64-sh64l-nbsd"
04147 #undef ELF_MAXPAGESIZE
04148 #define       ELF_MAXPAGESIZE                    0x10000
04149 #undef elf_symbol_leading_char
04150 #define       elf_symbol_leading_char            0
04151 
04152 #define       elf64_bed                   elf64_sh64_nbsd_bed
04153 
04154 #include "elf64-target.h"
04155 
04156 /* Linux support.  */
04157 #undef TARGET_BIG_SYM
04158 #define       TARGET_BIG_SYM                     bfd_elf64_sh64blin_vec
04159 #undef TARGET_BIG_NAME
04160 #define       TARGET_BIG_NAME                    "elf64-sh64big-linux"
04161 #undef TARGET_LITTLE_SYM
04162 #define       TARGET_LITTLE_SYM           bfd_elf64_sh64lin_vec
04163 #undef TARGET_LITTLE_NAME
04164 #define       TARGET_LITTLE_NAME          "elf64-sh64-linux"
04165 #undef elf64_bed
04166 #define       elf64_bed                   elf64_sh64_linux_bed
04167 
04168 #include "elf64-target.h"