Back to index

cell-binutils  2.17cvs20070401
elf32-m68k.c
Go to the documentation of this file.
00001 /* Motorola 68k series support for 32-bit ELF
00002    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
00003    2004, 2005, 2006, 2007 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 #include "bfd.h"
00022 #include "sysdep.h"
00023 #include "bfdlink.h"
00024 #include "libbfd.h"
00025 #include "elf-bfd.h"
00026 #include "elf/m68k.h"
00027 #include "opcode/m68k.h"
00028 
00029 static reloc_howto_type *reloc_type_lookup
00030   PARAMS ((bfd *, bfd_reloc_code_real_type));
00031 static void rtype_to_howto
00032   PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
00033 static struct bfd_hash_entry *elf_m68k_link_hash_newfunc
00034   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
00035 static struct bfd_link_hash_table *elf_m68k_link_hash_table_create
00036   PARAMS ((bfd *));
00037 static bfd_boolean elf_m68k_check_relocs
00038   PARAMS ((bfd *, struct bfd_link_info *, asection *,
00039           const Elf_Internal_Rela *));
00040 static bfd_boolean elf_m68k_adjust_dynamic_symbol
00041   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
00042 static bfd_boolean elf_m68k_size_dynamic_sections
00043   PARAMS ((bfd *, struct bfd_link_info *));
00044 static bfd_boolean elf_m68k_discard_copies
00045   PARAMS ((struct elf_link_hash_entry *, PTR));
00046 static bfd_boolean elf_m68k_relocate_section
00047   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
00048           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
00049 static bfd_boolean elf_m68k_finish_dynamic_symbol
00050   PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
00051           Elf_Internal_Sym *));
00052 static bfd_boolean elf_m68k_finish_dynamic_sections
00053   PARAMS ((bfd *, struct bfd_link_info *));
00054 
00055 static bfd_boolean elf32_m68k_set_private_flags
00056   PARAMS ((bfd *, flagword));
00057 static bfd_boolean elf32_m68k_merge_private_bfd_data
00058   PARAMS ((bfd *, bfd *));
00059 static bfd_boolean elf32_m68k_print_private_bfd_data
00060   PARAMS ((bfd *, PTR));
00061 static enum elf_reloc_type_class elf32_m68k_reloc_type_class
00062   PARAMS ((const Elf_Internal_Rela *));
00063 
00064 static reloc_howto_type howto_table[] = {
00065   HOWTO(R_68K_NONE,       0, 0, 0, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_68K_NONE",      FALSE, 0, 0x00000000,FALSE),
00066   HOWTO(R_68K_32,         0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32",        FALSE, 0, 0xffffffff,FALSE),
00067   HOWTO(R_68K_16,         0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16",        FALSE, 0, 0x0000ffff,FALSE),
00068   HOWTO(R_68K_8,          0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8",         FALSE, 0, 0x000000ff,FALSE),
00069   HOWTO(R_68K_PC32,       0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32",      FALSE, 0, 0xffffffff,TRUE),
00070   HOWTO(R_68K_PC16,       0, 1,16, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_PC16",      FALSE, 0, 0x0000ffff,TRUE),
00071   HOWTO(R_68K_PC8,        0, 0, 8, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_PC8",       FALSE, 0, 0x000000ff,TRUE),
00072   HOWTO(R_68K_GOT32,      0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32",     FALSE, 0, 0xffffffff,TRUE),
00073   HOWTO(R_68K_GOT16,      0, 1,16, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_GOT16",     FALSE, 0, 0x0000ffff,TRUE),
00074   HOWTO(R_68K_GOT8,       0, 0, 8, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_GOT8",      FALSE, 0, 0x000000ff,TRUE),
00075   HOWTO(R_68K_GOT32O,     0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O",    FALSE, 0, 0xffffffff,FALSE),
00076   HOWTO(R_68K_GOT16O,     0, 1,16, FALSE,0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_GOT16O",    FALSE, 0, 0x0000ffff,FALSE),
00077   HOWTO(R_68K_GOT8O,      0, 0, 8, FALSE,0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_GOT8O",     FALSE, 0, 0x000000ff,FALSE),
00078   HOWTO(R_68K_PLT32,      0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32",     FALSE, 0, 0xffffffff,TRUE),
00079   HOWTO(R_68K_PLT16,      0, 1,16, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_PLT16",     FALSE, 0, 0x0000ffff,TRUE),
00080   HOWTO(R_68K_PLT8,       0, 0, 8, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_PLT8",      FALSE, 0, 0x000000ff,TRUE),
00081   HOWTO(R_68K_PLT32O,     0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O",    FALSE, 0, 0xffffffff,FALSE),
00082   HOWTO(R_68K_PLT16O,     0, 1,16, FALSE,0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_PLT16O",    FALSE, 0, 0x0000ffff,FALSE),
00083   HOWTO(R_68K_PLT8O,      0, 0, 8, FALSE,0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_68K_PLT8O",     FALSE, 0, 0x000000ff,FALSE),
00084   HOWTO(R_68K_COPY,       0, 0, 0, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_68K_COPY",      FALSE, 0, 0xffffffff,FALSE),
00085   HOWTO(R_68K_GLOB_DAT,   0, 2,32, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_68K_GLOB_DAT",  FALSE, 0, 0xffffffff,FALSE),
00086   HOWTO(R_68K_JMP_SLOT,   0, 2,32, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_68K_JMP_SLOT",  FALSE, 0, 0xffffffff,FALSE),
00087   HOWTO(R_68K_RELATIVE,   0, 2,32, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_68K_RELATIVE",  FALSE, 0, 0xffffffff,FALSE),
00088   /* GNU extension to record C++ vtable hierarchy.  */
00089   HOWTO (R_68K_GNU_VTINHERIT,      /* type */
00090         0,                  /* rightshift */
00091         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00092         0,                  /* bitsize */
00093         FALSE,                     /* pc_relative */
00094         0,                  /* bitpos */
00095         complain_overflow_dont, /* complain_on_overflow */
00096         NULL,               /* special_function */
00097         "R_68K_GNU_VTINHERIT",     /* name */
00098         FALSE,                     /* partial_inplace */
00099         0,                  /* src_mask */
00100         0,                  /* dst_mask */
00101         FALSE),
00102   /* GNU extension to record C++ vtable member usage.  */
00103   HOWTO (R_68K_GNU_VTENTRY, /* type */
00104         0,                  /* rightshift */
00105         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00106         0,                  /* bitsize */
00107         FALSE,                     /* pc_relative */
00108         0,                  /* bitpos */
00109         complain_overflow_dont, /* complain_on_overflow */
00110         _bfd_elf_rel_vtable_reloc_fn, /* special_function */
00111         "R_68K_GNU_VTENTRY",       /* name */
00112         FALSE,                     /* partial_inplace */
00113         0,                  /* src_mask */
00114         0,                  /* dst_mask */
00115         FALSE),
00116 };
00117 
00118 static void
00119 rtype_to_howto (abfd, cache_ptr, dst)
00120      bfd *abfd ATTRIBUTE_UNUSED;
00121      arelent *cache_ptr;
00122      Elf_Internal_Rela *dst;
00123 {
00124   BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K_max);
00125   cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
00126 }
00127 
00128 #define elf_info_to_howto rtype_to_howto
00129 
00130 static const struct
00131 {
00132   bfd_reloc_code_real_type bfd_val;
00133   int elf_val;
00134 } reloc_map[] = {
00135   { BFD_RELOC_NONE, R_68K_NONE },
00136   { BFD_RELOC_32, R_68K_32 },
00137   { BFD_RELOC_16, R_68K_16 },
00138   { BFD_RELOC_8, R_68K_8 },
00139   { BFD_RELOC_32_PCREL, R_68K_PC32 },
00140   { BFD_RELOC_16_PCREL, R_68K_PC16 },
00141   { BFD_RELOC_8_PCREL, R_68K_PC8 },
00142   { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
00143   { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
00144   { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
00145   { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
00146   { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
00147   { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
00148   { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
00149   { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
00150   { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
00151   { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
00152   { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
00153   { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
00154   { BFD_RELOC_NONE, R_68K_COPY },
00155   { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
00156   { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
00157   { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
00158   { BFD_RELOC_CTOR, R_68K_32 },
00159   { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
00160   { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
00161 };
00162 
00163 static reloc_howto_type *
00164 reloc_type_lookup (abfd, code)
00165      bfd *abfd ATTRIBUTE_UNUSED;
00166      bfd_reloc_code_real_type code;
00167 {
00168   unsigned int i;
00169   for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
00170     {
00171       if (reloc_map[i].bfd_val == code)
00172        return &howto_table[reloc_map[i].elf_val];
00173     }
00174   return 0;
00175 }
00176 
00177 static reloc_howto_type *
00178 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
00179 {
00180   unsigned int i;
00181 
00182   for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
00183     if (howto_table[i].name != NULL
00184        && strcasecmp (howto_table[i].name, r_name) == 0)
00185       return &howto_table[i];
00186 
00187   return NULL;
00188 }
00189 
00190 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
00191 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
00192 #define ELF_ARCH bfd_arch_m68k
00193 
00194 /* Functions for the m68k ELF linker.  */
00195 
00196 /* The name of the dynamic interpreter.  This is put in the .interp
00197    section.  */
00198 
00199 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
00200 
00201 /* Describes one of the various PLT styles.  */
00202 
00203 struct elf_m68k_plt_info
00204 {
00205   /* The size of each PLT entry.  */
00206   bfd_vma size;
00207 
00208   /* The template for the first PLT entry.  */
00209   const bfd_byte *plt0_entry;
00210 
00211   /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
00212      The comments by each member indicate the value that the relocation
00213      is against.  */
00214   struct {
00215     unsigned int got4; /* .got + 4 */
00216     unsigned int got8; /* .got + 8 */
00217   } plt0_relocs;
00218 
00219   /* The template for a symbol's PLT entry.  */
00220   const bfd_byte *symbol_entry;
00221 
00222   /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
00223      The comments by each member indicate the value that the relocation
00224      is against.  */
00225   struct {
00226     unsigned int got; /* the symbol's .got.plt entry */
00227     unsigned int plt; /* .plt */
00228   } symbol_relocs;
00229 
00230   /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
00231      The stub starts with "move.l #relocoffset,%d0".  */
00232   bfd_vma symbol_resolve_entry;
00233 };
00234 
00235 /* The size in bytes of an entry in the procedure linkage table.  */
00236 
00237 #define PLT_ENTRY_SIZE 20
00238 
00239 /* The first entry in a procedure linkage table looks like this.  See
00240    the SVR4 ABI m68k supplement to see how this works.  */
00241 
00242 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
00243 {
00244   0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
00245   0, 0, 0, 2,          /* + (.got + 4) - . */
00246   0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
00247   0, 0, 0, 2,          /* + (.got + 8) - . */
00248   0, 0, 0, 0           /* pad out to 20 bytes.  */
00249 };
00250 
00251 /* Subsequent entries in a procedure linkage table look like this.  */
00252 
00253 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
00254 {
00255   0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
00256   0, 0, 0, 2,          /* + (.got.plt entry) - . */
00257   0x2f, 0x3c,          /* move.l #offset,-(%sp) */
00258   0, 0, 0, 0,          /* + reloc index */
00259   0x60, 0xff,          /* bra.l .plt */
00260   0, 0, 0, 0           /* + .plt - . */
00261 };
00262 
00263 static const struct elf_m68k_plt_info elf_m68k_plt_info = {
00264   PLT_ENTRY_SIZE,
00265   elf_m68k_plt0_entry, { 4, 12 },
00266   elf_m68k_plt_entry, { 4, 16 }, 8
00267 };
00268 
00269 #define ISAB_PLT_ENTRY_SIZE 24 
00270 
00271 static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
00272 {
00273   0x20, 0x3c,             /* move.l #offset,%d0 */
00274   0, 0, 0, 0,             /* + (.got + 4) - . */
00275   0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
00276   0x20, 0x3c,             /* move.l #offset,%d0 */
00277   0, 0, 0, 0,             /* + (.got + 8) - . */
00278   0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
00279   0x4e, 0xd0,             /* jmp (%a0) */
00280   0x4e, 0x71           /* nop */
00281 };
00282 
00283 /* Subsequent entries in a procedure linkage table look like this.  */
00284 
00285 static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
00286 {
00287   0x20, 0x3c,             /* move.l #offset,%d0 */
00288   0, 0, 0, 0,             /* + (.got.plt entry) - . */
00289   0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
00290   0x4e, 0xd0,             /* jmp (%a0) */
00291   0x2f, 0x3c,             /* move.l #offset,-(%sp) */
00292   0, 0, 0, 0,             /* + reloc index */
00293   0x60, 0xff,             /* bra.l .plt */
00294   0, 0, 0, 0              /* + .plt - . */
00295 };
00296 
00297 static const struct elf_m68k_plt_info elf_isab_plt_info = {
00298   ISAB_PLT_ENTRY_SIZE,
00299   elf_isab_plt0_entry, { 2, 12 },
00300   elf_isab_plt_entry, { 2, 20 }, 12
00301 };
00302 
00303 #define CPU32_PLT_ENTRY_SIZE 24
00304 /* Procedure linkage table entries for the cpu32 */
00305 static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
00306 {
00307   0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
00308   0, 0, 0, 2,             /* + (.got + 4) - . */
00309   0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
00310   0, 0, 0, 2,             /* + (.got + 8) - . */
00311   0x4e, 0xd1,             /* jmp %a1@ */
00312   0, 0, 0, 0,             /* pad out to 24 bytes.  */
00313   0, 0
00314 };
00315 
00316 static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
00317 {
00318   0x22, 0x7b, 0x01, 0x70,  /* moveal %pc@(0xc), %a1 */
00319   0, 0, 0, 2,              /* + (.got.plt entry) - . */
00320   0x4e, 0xd1,              /* jmp %a1@ */
00321   0x2f, 0x3c,              /* move.l #offset,-(%sp) */
00322   0, 0, 0, 0,              /* + reloc index */
00323   0x60, 0xff,              /* bra.l .plt */
00324   0, 0, 0, 0,              /* + .plt - . */
00325   0, 0
00326 };
00327 
00328 static const struct elf_m68k_plt_info elf_cpu32_plt_info = {
00329   CPU32_PLT_ENTRY_SIZE,
00330   elf_cpu32_plt0_entry, { 4, 12 },
00331   elf_cpu32_plt_entry, { 4, 18 }, 10
00332 };
00333 
00334 /* The m68k linker needs to keep track of the number of relocs that it
00335    decides to copy in check_relocs for each symbol.  This is so that it
00336    can discard PC relative relocs if it doesn't need them when linking
00337    with -Bsymbolic.  We store the information in a field extending the
00338    regular ELF linker hash table.  */
00339 
00340 /* This structure keeps track of the number of PC relative relocs we have
00341    copied for a given symbol.  */
00342 
00343 struct elf_m68k_pcrel_relocs_copied
00344 {
00345   /* Next section.  */
00346   struct elf_m68k_pcrel_relocs_copied *next;
00347   /* A section in dynobj.  */
00348   asection *section;
00349   /* Number of relocs copied in this section.  */
00350   bfd_size_type count;
00351 };
00352 
00353 /* m68k ELF linker hash entry.  */
00354 
00355 struct elf_m68k_link_hash_entry
00356 {
00357   struct elf_link_hash_entry root;
00358 
00359   /* Number of PC relative relocs copied for this symbol.  */
00360   struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
00361 };
00362 
00363 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
00364 
00365 /* m68k ELF linker hash table.  */
00366 
00367 struct elf_m68k_link_hash_table
00368 {
00369   struct elf_link_hash_table root;
00370 
00371   /* Small local sym to section mapping cache.  */
00372   struct sym_sec_cache sym_sec;
00373 
00374   /* The PLT format used by this link, or NULL if the format has not
00375      yet been chosen.  */
00376   const struct elf_m68k_plt_info *plt_info;
00377 };
00378 
00379 /* Get the m68k ELF linker hash table from a link_info structure.  */
00380 
00381 #define elf_m68k_hash_table(p) \
00382   ((struct elf_m68k_link_hash_table *) (p)->hash)
00383 
00384 /* Create an entry in an m68k ELF linker hash table.  */
00385 
00386 static struct bfd_hash_entry *
00387 elf_m68k_link_hash_newfunc (entry, table, string)
00388      struct bfd_hash_entry *entry;
00389      struct bfd_hash_table *table;
00390      const char *string;
00391 {
00392   struct bfd_hash_entry *ret = entry;
00393 
00394   /* Allocate the structure if it has not already been allocated by a
00395      subclass.  */
00396   if (ret == NULL)
00397     ret = bfd_hash_allocate (table,
00398                           sizeof (struct elf_m68k_link_hash_entry));
00399   if (ret == NULL)
00400     return ret;
00401 
00402   /* Call the allocation method of the superclass.  */
00403   ret = _bfd_elf_link_hash_newfunc (ret, table, string);
00404   if (ret != NULL)
00405     elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
00406 
00407   return ret;
00408 }
00409 
00410 /* Create an m68k ELF linker hash table.  */
00411 
00412 static struct bfd_link_hash_table *
00413 elf_m68k_link_hash_table_create (abfd)
00414      bfd *abfd;
00415 {
00416   struct elf_m68k_link_hash_table *ret;
00417   bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table);
00418 
00419   ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt);
00420   if (ret == (struct elf_m68k_link_hash_table *) NULL)
00421     return NULL;
00422 
00423   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
00424                                   elf_m68k_link_hash_newfunc,
00425                                   sizeof (struct elf_m68k_link_hash_entry)))
00426     {
00427       free (ret);
00428       return NULL;
00429     }
00430 
00431   ret->sym_sec.abfd = NULL;
00432   ret->plt_info = NULL;
00433 
00434   return &ret->root.root;
00435 }
00436 
00437 /* Set the right machine number.  */
00438 
00439 static bfd_boolean
00440 elf32_m68k_object_p (bfd *abfd)
00441 {
00442   unsigned int mach = 0;
00443   unsigned features = 0;
00444   flagword eflags = elf_elfheader (abfd)->e_flags;
00445 
00446   if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
00447     features |= m68000;
00448   else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
00449     features |= cpu32;
00450   else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
00451     features |= fido_a;
00452   else
00453     {
00454       switch (eflags & EF_M68K_CF_ISA_MASK)
00455        {
00456        case EF_M68K_CF_ISA_A_NODIV:
00457          features |= mcfisa_a;
00458          break;
00459        case EF_M68K_CF_ISA_A:
00460          features |= mcfisa_a|mcfhwdiv;
00461          break;
00462        case EF_M68K_CF_ISA_A_PLUS:
00463          features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
00464          break;
00465        case EF_M68K_CF_ISA_B_NOUSP:
00466          features |= mcfisa_a|mcfisa_b|mcfhwdiv;
00467          break;
00468        case EF_M68K_CF_ISA_B:
00469          features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
00470          break;
00471        }
00472       switch (eflags & EF_M68K_CF_MAC_MASK)
00473        {
00474        case EF_M68K_CF_MAC:
00475          features |= mcfmac;
00476          break;
00477        case EF_M68K_CF_EMAC:
00478          features |= mcfemac;
00479          break;
00480        }
00481       if (eflags & EF_M68K_CF_FLOAT)
00482        features |= cfloat;
00483     }
00484 
00485   mach = bfd_m68k_features_to_mach (features);
00486   bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
00487 
00488   return TRUE;
00489 }
00490 
00491 /* Keep m68k-specific flags in the ELF header.  */
00492 static bfd_boolean
00493 elf32_m68k_set_private_flags (abfd, flags)
00494      bfd *abfd;
00495      flagword flags;
00496 {
00497   elf_elfheader (abfd)->e_flags = flags;
00498   elf_flags_init (abfd) = TRUE;
00499   return TRUE;
00500 }
00501 
00502 /* Merge backend specific data from an object file to the output
00503    object file when linking.  */
00504 static bfd_boolean
00505 elf32_m68k_merge_private_bfd_data (ibfd, obfd)
00506      bfd *ibfd;
00507      bfd *obfd;
00508 {
00509   flagword out_flags;
00510   flagword in_flags;
00511   flagword out_isa;
00512   flagword in_isa;
00513   const bfd_arch_info_type *arch_info;
00514   
00515   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
00516       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
00517     return FALSE;
00518 
00519   /* Get the merged machine.  This checks for incompatibility between
00520      Coldfire & non-Coldfire flags, incompability between different
00521      Coldfire ISAs, and incompability between different MAC types.  */
00522   arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
00523   if (!arch_info)
00524     return FALSE;
00525 
00526   bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
00527   
00528   in_flags = elf_elfheader (ibfd)->e_flags;
00529   if (!elf_flags_init (obfd))
00530     {
00531       elf_flags_init (obfd) = TRUE;
00532       out_flags = in_flags;
00533     }
00534   else
00535     {
00536       out_flags = elf_elfheader (obfd)->e_flags;
00537       unsigned int variant_mask;
00538 
00539       if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
00540        variant_mask = 0;
00541       else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
00542        variant_mask = 0;
00543       else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
00544        variant_mask = 0;
00545       else
00546        variant_mask = EF_M68K_CF_ISA_MASK;
00547 
00548       in_isa = (in_flags & variant_mask);
00549       out_isa = (out_flags & variant_mask);
00550       if (in_isa > out_isa)
00551        out_flags ^= in_isa ^ out_isa;
00552       if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
00553           && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
00554          || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
00555              && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
00556        out_flags = EF_M68K_FIDO;
00557       else
00558       out_flags |= in_flags ^ in_isa;
00559     }
00560   elf_elfheader (obfd)->e_flags = out_flags;
00561 
00562   return TRUE;
00563 }
00564 
00565 /* Display the flags field.  */
00566 static bfd_boolean
00567 elf32_m68k_print_private_bfd_data (abfd, ptr)
00568      bfd *abfd;
00569      PTR ptr;
00570 {
00571   FILE *file = (FILE *) ptr;
00572   flagword eflags = elf_elfheader (abfd)->e_flags;
00573 
00574   BFD_ASSERT (abfd != NULL && ptr != NULL);
00575 
00576   /* Print normal ELF private data.  */
00577   _bfd_elf_print_private_bfd_data (abfd, ptr);
00578 
00579   /* Ignore init flag - it may not be set, despite the flags field containing valid data.  */
00580 
00581   /* xgettext:c-format */
00582   fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
00583 
00584   if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
00585     fprintf (file, " [m68000]");
00586   else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
00587     fprintf (file, " [cpu32]");
00588   else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
00589     fprintf (file, " [fido]");
00590   else
00591     {
00592       if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
00593        fprintf (file, " [cfv4e]");
00594 
00595       if (eflags & EF_M68K_CF_ISA_MASK)
00596        {
00597          char const *isa = _("unknown");
00598          char const *mac = _("unknown");
00599          char const *additional = "";
00600       
00601          switch (eflags & EF_M68K_CF_ISA_MASK)
00602            {
00603            case EF_M68K_CF_ISA_A_NODIV:
00604              isa = "A";
00605              additional = " [nodiv]";
00606              break;
00607            case EF_M68K_CF_ISA_A:
00608              isa = "A";
00609              break;
00610            case EF_M68K_CF_ISA_A_PLUS:
00611              isa = "A+";
00612              break;
00613            case EF_M68K_CF_ISA_B_NOUSP:
00614              isa = "B";
00615              additional = " [nousp]";
00616              break;
00617            case EF_M68K_CF_ISA_B:
00618              isa = "B";
00619              break;
00620            }
00621          fprintf (file, " [isa %s]%s", isa, additional);
00622          if (eflags & EF_M68K_CF_FLOAT)
00623            fprintf (file, " [float]");
00624          switch (eflags & EF_M68K_CF_MAC_MASK)
00625            {
00626            case 0:
00627              mac = NULL;
00628              break;
00629            case EF_M68K_CF_MAC:
00630              mac = "mac";
00631              break;
00632            case EF_M68K_CF_EMAC:
00633              mac = "emac";
00634              break;
00635            }
00636          if (mac)
00637            fprintf (file, " [%s]", mac);
00638        }
00639     }
00640   
00641   fputc ('\n', file);
00642 
00643   return TRUE;
00644 }
00645 /* Look through the relocs for a section during the first phase, and
00646    allocate space in the global offset table or procedure linkage
00647    table.  */
00648 
00649 static bfd_boolean
00650 elf_m68k_check_relocs (abfd, info, sec, relocs)
00651      bfd *abfd;
00652      struct bfd_link_info *info;
00653      asection *sec;
00654      const Elf_Internal_Rela *relocs;
00655 {
00656   bfd *dynobj;
00657   Elf_Internal_Shdr *symtab_hdr;
00658   struct elf_link_hash_entry **sym_hashes;
00659   bfd_signed_vma *local_got_refcounts;
00660   const Elf_Internal_Rela *rel;
00661   const Elf_Internal_Rela *rel_end;
00662   asection *sgot;
00663   asection *srelgot;
00664   asection *sreloc;
00665 
00666   if (info->relocatable)
00667     return TRUE;
00668 
00669   dynobj = elf_hash_table (info)->dynobj;
00670   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
00671   sym_hashes = elf_sym_hashes (abfd);
00672   local_got_refcounts = elf_local_got_refcounts (abfd);
00673 
00674   sgot = NULL;
00675   srelgot = NULL;
00676   sreloc = NULL;
00677 
00678   rel_end = relocs + sec->reloc_count;
00679   for (rel = relocs; rel < rel_end; rel++)
00680     {
00681       unsigned long r_symndx;
00682       struct elf_link_hash_entry *h;
00683 
00684       r_symndx = ELF32_R_SYM (rel->r_info);
00685 
00686       if (r_symndx < symtab_hdr->sh_info)
00687        h = NULL;
00688       else
00689        {
00690          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
00691          while (h->root.type == bfd_link_hash_indirect
00692                || h->root.type == bfd_link_hash_warning)
00693            h = (struct elf_link_hash_entry *) h->root.u.i.link;
00694        }
00695 
00696       switch (ELF32_R_TYPE (rel->r_info))
00697        {
00698        case R_68K_GOT8:
00699        case R_68K_GOT16:
00700        case R_68K_GOT32:
00701          if (h != NULL
00702              && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
00703            break;
00704          /* Fall through.  */
00705        case R_68K_GOT8O:
00706        case R_68K_GOT16O:
00707        case R_68K_GOT32O:
00708          /* This symbol requires a global offset table entry.  */
00709 
00710          if (dynobj == NULL)
00711            {
00712              /* Create the .got section.  */
00713              elf_hash_table (info)->dynobj = dynobj = abfd;
00714              if (!_bfd_elf_create_got_section (dynobj, info))
00715               return FALSE;
00716            }
00717 
00718          if (sgot == NULL)
00719            {
00720              sgot = bfd_get_section_by_name (dynobj, ".got");
00721              BFD_ASSERT (sgot != NULL);
00722            }
00723 
00724          if (srelgot == NULL
00725              && (h != NULL || info->shared))
00726            {
00727              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
00728              if (srelgot == NULL)
00729               {
00730                 srelgot = bfd_make_section_with_flags (dynobj,
00731                                                   ".rela.got",
00732                                                   (SEC_ALLOC
00733                                                    | SEC_LOAD
00734                                                    | SEC_HAS_CONTENTS
00735                                                    | SEC_IN_MEMORY
00736                                                    | SEC_LINKER_CREATED
00737                                                    | SEC_READONLY));
00738                 if (srelgot == NULL
00739                     || !bfd_set_section_alignment (dynobj, srelgot, 2))
00740                   return FALSE;
00741               }
00742            }
00743 
00744          if (h != NULL)
00745            {
00746              if (h->got.refcount == 0)
00747               {
00748                 /* Make sure this symbol is output as a dynamic symbol.  */
00749                 if (h->dynindx == -1
00750                     && !h->forced_local)
00751                   {
00752                     if (!bfd_elf_link_record_dynamic_symbol (info, h))
00753                      return FALSE;
00754                   }
00755 
00756                 /* Allocate space in the .got section.  */
00757                 sgot->size += 4;
00758                 /* Allocate relocation space.  */
00759                 srelgot->size += sizeof (Elf32_External_Rela);
00760               }
00761              h->got.refcount++;
00762            }
00763          else
00764            {
00765              /* This is a global offset table entry for a local symbol.  */
00766              if (local_got_refcounts == NULL)
00767               {
00768                 bfd_size_type size;
00769 
00770                 size = symtab_hdr->sh_info;
00771                 size *= sizeof (bfd_signed_vma);
00772                 local_got_refcounts = ((bfd_signed_vma *)
00773                                     bfd_zalloc (abfd, size));
00774                 if (local_got_refcounts == NULL)
00775                   return FALSE;
00776                 elf_local_got_refcounts (abfd) = local_got_refcounts;
00777               }
00778              if (local_got_refcounts[r_symndx] == 0)
00779               {
00780                 sgot->size += 4;
00781                 if (info->shared)
00782                   {
00783                     /* If we are generating a shared object, we need to
00784                       output a R_68K_RELATIVE reloc so that the dynamic
00785                       linker can adjust this GOT entry.  */
00786                     srelgot->size += sizeof (Elf32_External_Rela);
00787                   }
00788               }
00789              local_got_refcounts[r_symndx]++;
00790            }
00791          break;
00792 
00793        case R_68K_PLT8:
00794        case R_68K_PLT16:
00795        case R_68K_PLT32:
00796          /* This symbol requires a procedure linkage table entry.  We
00797             actually build the entry in adjust_dynamic_symbol,
00798              because this might be a case of linking PIC code which is
00799              never referenced by a dynamic object, in which case we
00800              don't need to generate a procedure linkage table entry
00801              after all.  */
00802 
00803          /* If this is a local symbol, we resolve it directly without
00804             creating a procedure linkage table entry.  */
00805          if (h == NULL)
00806            continue;
00807 
00808          h->needs_plt = 1;
00809          h->plt.refcount++;
00810          break;
00811 
00812        case R_68K_PLT8O:
00813        case R_68K_PLT16O:
00814        case R_68K_PLT32O:
00815          /* This symbol requires a procedure linkage table entry.  */
00816 
00817          if (h == NULL)
00818            {
00819              /* It does not make sense to have this relocation for a
00820                local symbol.  FIXME: does it?  How to handle it if
00821                it does make sense?  */
00822              bfd_set_error (bfd_error_bad_value);
00823              return FALSE;
00824            }
00825 
00826          /* Make sure this symbol is output as a dynamic symbol.  */
00827          if (h->dynindx == -1
00828              && !h->forced_local)
00829            {
00830              if (!bfd_elf_link_record_dynamic_symbol (info, h))
00831               return FALSE;
00832            }
00833 
00834          h->needs_plt = 1;
00835          h->plt.refcount++;
00836          break;
00837 
00838        case R_68K_PC8:
00839        case R_68K_PC16:
00840        case R_68K_PC32:
00841          /* If we are creating a shared library and this is not a local
00842             symbol, we need to copy the reloc into the shared library.
00843             However when linking with -Bsymbolic and this is a global
00844             symbol which is defined in an object we are including in the
00845             link (i.e., DEF_REGULAR is set), then we can resolve the
00846             reloc directly.  At this point we have not seen all the input
00847             files, so it is possible that DEF_REGULAR is not set now but
00848             will be set later (it is never cleared).  We account for that
00849             possibility below by storing information in the
00850             pcrel_relocs_copied field of the hash table entry.  */
00851          if (!(info->shared
00852               && (sec->flags & SEC_ALLOC) != 0
00853               && h != NULL
00854               && (!info->symbolic
00855                   || h->root.type == bfd_link_hash_defweak
00856                   || !h->def_regular)))
00857            {
00858              if (h != NULL)
00859               {
00860                 /* Make sure a plt entry is created for this symbol if
00861                    it turns out to be a function defined by a dynamic
00862                    object.  */
00863                 h->plt.refcount++;
00864               }
00865              break;
00866            }
00867          /* Fall through.  */
00868        case R_68K_8:
00869        case R_68K_16:
00870        case R_68K_32:
00871          if (h != NULL)
00872            {
00873              /* Make sure a plt entry is created for this symbol if it
00874                turns out to be a function defined by a dynamic object.  */
00875              h->plt.refcount++;
00876            }
00877 
00878          /* If we are creating a shared library, we need to copy the
00879             reloc into the shared library.  */
00880          if (info->shared
00881              && (sec->flags & SEC_ALLOC) != 0)
00882            {
00883              /* When creating a shared object, we must copy these
00884                reloc types into the output file.  We create a reloc
00885                section in dynobj and make room for this reloc.  */
00886              if (sreloc == NULL)
00887               {
00888                 const char *name;
00889 
00890                 name = (bfd_elf_string_from_elf_section
00891                        (abfd,
00892                         elf_elfheader (abfd)->e_shstrndx,
00893                         elf_section_data (sec)->rel_hdr.sh_name));
00894                 if (name == NULL)
00895                   return FALSE;
00896 
00897                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
00898                            && strcmp (bfd_get_section_name (abfd, sec),
00899                                     name + 5) == 0);
00900 
00901                 sreloc = bfd_get_section_by_name (dynobj, name);
00902                 if (sreloc == NULL)
00903                   {
00904                     sreloc = bfd_make_section_with_flags (dynobj,
00905                                                      name,
00906                                                      (SEC_ALLOC
00907                                                       | SEC_LOAD
00908                                                       | SEC_HAS_CONTENTS
00909                                                       | SEC_IN_MEMORY
00910                                                       | SEC_LINKER_CREATED
00911                                                       | SEC_READONLY));
00912                     if (sreloc == NULL
00913                        || !bfd_set_section_alignment (dynobj, sreloc, 2))
00914                      return FALSE;
00915                   }
00916                 elf_section_data (sec)->sreloc = sreloc;
00917               }
00918 
00919              if (sec->flags & SEC_READONLY
00920                 /* Don't set DF_TEXTREL yet for PC relative
00921                    relocations, they might be discarded later.  */
00922                 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
00923                      || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
00924                      || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
00925                   info->flags |= DF_TEXTREL;
00926 
00927              sreloc->size += sizeof (Elf32_External_Rela);
00928 
00929              /* We count the number of PC relative relocations we have
00930                entered for this symbol, so that we can discard them
00931                again if, in the -Bsymbolic case, the symbol is later
00932                defined by a regular object, or, in the normal shared
00933                case, the symbol is forced to be local.  Note that this
00934                function is only called if we are using an m68kelf linker
00935                hash table, which means that h is really a pointer to an
00936                elf_m68k_link_hash_entry.  */
00937              if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
00938                 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
00939                 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
00940               {
00941                 struct elf_m68k_pcrel_relocs_copied *p;
00942                 struct elf_m68k_pcrel_relocs_copied **head;
00943 
00944                 if (h != NULL)
00945                   {
00946                     struct elf_m68k_link_hash_entry *eh
00947                      = elf_m68k_hash_entry (h);
00948                     head = &eh->pcrel_relocs_copied;
00949                   }
00950                 else
00951                   {
00952                     asection *s;
00953                     void *vpp;
00954 
00955                     s = (bfd_section_from_r_symndx
00956                         (abfd, &elf_m68k_hash_table (info)->sym_sec,
00957                          sec, r_symndx));
00958                     if (s == NULL)
00959                      return FALSE;
00960 
00961                     vpp = &elf_section_data (s)->local_dynrel;
00962                     head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
00963                   }
00964 
00965                 for (p = *head; p != NULL; p = p->next)
00966                   if (p->section == sreloc)
00967                     break;
00968 
00969                 if (p == NULL)
00970                   {
00971                     p = ((struct elf_m68k_pcrel_relocs_copied *)
00972                         bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
00973                     if (p == NULL)
00974                      return FALSE;
00975                     p->next = *head;
00976                     *head = p;
00977                     p->section = sreloc;
00978                     p->count = 0;
00979                   }
00980 
00981                 ++p->count;
00982               }
00983            }
00984 
00985          break;
00986 
00987          /* This relocation describes the C++ object vtable hierarchy.
00988             Reconstruct it for later use during GC.  */
00989        case R_68K_GNU_VTINHERIT:
00990          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
00991            return FALSE;
00992          break;
00993 
00994          /* This relocation describes which C++ vtable entries are actually
00995             used.  Record for later use during GC.  */
00996        case R_68K_GNU_VTENTRY:
00997          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
00998            return FALSE;
00999          break;
01000 
01001        default:
01002          break;
01003        }
01004     }
01005 
01006   return TRUE;
01007 }
01008 
01009 /* Return the section that should be marked against GC for a given
01010    relocation.  */
01011 
01012 static asection *
01013 elf_m68k_gc_mark_hook (asection *sec,
01014                      struct bfd_link_info *info,
01015                      Elf_Internal_Rela *rel,
01016                      struct elf_link_hash_entry *h,
01017                      Elf_Internal_Sym *sym)
01018 {
01019   if (h != NULL)
01020     switch (ELF32_R_TYPE (rel->r_info))
01021       {
01022       case R_68K_GNU_VTINHERIT:
01023       case R_68K_GNU_VTENTRY:
01024        return NULL;
01025       }
01026 
01027   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
01028 }
01029 
01030 /* Update the got entry reference counts for the section being removed.  */
01031 
01032 static bfd_boolean
01033 elf_m68k_gc_sweep_hook (bfd *abfd,
01034                      struct bfd_link_info *info,
01035                      asection *sec,
01036                      const Elf_Internal_Rela *relocs)
01037 {
01038   Elf_Internal_Shdr *symtab_hdr;
01039   struct elf_link_hash_entry **sym_hashes;
01040   bfd_signed_vma *local_got_refcounts;
01041   const Elf_Internal_Rela *rel, *relend;
01042   bfd *dynobj;
01043   asection *sgot;
01044   asection *srelgot;
01045 
01046   dynobj = elf_hash_table (info)->dynobj;
01047   if (dynobj == NULL)
01048     return TRUE;
01049 
01050   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
01051   sym_hashes = elf_sym_hashes (abfd);
01052   local_got_refcounts = elf_local_got_refcounts (abfd);
01053 
01054   sgot = bfd_get_section_by_name (dynobj, ".got");
01055   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
01056 
01057   relend = relocs + sec->reloc_count;
01058   for (rel = relocs; rel < relend; rel++)
01059     {
01060       unsigned long r_symndx;
01061       struct elf_link_hash_entry *h = NULL;
01062 
01063       r_symndx = ELF32_R_SYM (rel->r_info);
01064       if (r_symndx >= symtab_hdr->sh_info)
01065        {
01066          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
01067          while (h->root.type == bfd_link_hash_indirect
01068                || h->root.type == bfd_link_hash_warning)
01069            h = (struct elf_link_hash_entry *) h->root.u.i.link;
01070        }
01071 
01072       switch (ELF32_R_TYPE (rel->r_info))
01073        {
01074        case R_68K_GOT8:
01075        case R_68K_GOT16:
01076        case R_68K_GOT32:
01077        case R_68K_GOT8O:
01078        case R_68K_GOT16O:
01079        case R_68K_GOT32O:
01080          if (h != NULL)
01081            {
01082              if (h->got.refcount > 0)
01083               {
01084                 --h->got.refcount;
01085                 if (h->got.refcount == 0)
01086                   {
01087                     /* We don't need the .got entry any more.  */
01088                     sgot->size -= 4;
01089                     srelgot->size -= sizeof (Elf32_External_Rela);
01090                   }
01091               }
01092            }
01093          else if (local_got_refcounts != NULL)
01094            {
01095              if (local_got_refcounts[r_symndx] > 0)
01096               {
01097                 --local_got_refcounts[r_symndx];
01098                 if (local_got_refcounts[r_symndx] == 0)
01099                   {
01100                     /* We don't need the .got entry any more.  */
01101                     sgot->size -= 4;
01102                     if (info->shared)
01103                      srelgot->size -= sizeof (Elf32_External_Rela);
01104                   }
01105               }
01106            }
01107          break;
01108 
01109        case R_68K_PLT8:
01110        case R_68K_PLT16:
01111        case R_68K_PLT32:
01112        case R_68K_PLT8O:
01113        case R_68K_PLT16O:
01114        case R_68K_PLT32O:
01115        case R_68K_PC8:
01116        case R_68K_PC16:
01117        case R_68K_PC32:
01118        case R_68K_8:
01119        case R_68K_16:
01120        case R_68K_32:
01121          if (h != NULL)
01122            {
01123              if (h->plt.refcount > 0)
01124               --h->plt.refcount;
01125            }
01126          break;
01127 
01128        default:
01129          break;
01130        }
01131     }
01132 
01133   return TRUE;
01134 }
01135 
01136 /* Return the type of PLT associated with OUTPUT_BFD.  */
01137 
01138 static const struct elf_m68k_plt_info *
01139 elf_m68k_get_plt_info (bfd *output_bfd)
01140 {
01141   unsigned int features;
01142 
01143   features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
01144   if (features & cpu32)
01145     return &elf_cpu32_plt_info;
01146   if (features & mcfisa_b)
01147     return &elf_isab_plt_info;
01148   return &elf_m68k_plt_info;
01149 }
01150 
01151 /* This function is called after all the input files have been read,
01152    and the input sections have been assigned to output sections.
01153    It's a convenient place to determine the PLT style.  */
01154 
01155 static bfd_boolean
01156 elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
01157 {
01158   elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
01159   return TRUE;
01160 }
01161 
01162 /* Adjust a symbol defined by a dynamic object and referenced by a
01163    regular object.  The current definition is in some section of the
01164    dynamic object, but we're not including those sections.  We have to
01165    change the definition to something the rest of the link can
01166    understand.  */
01167 
01168 static bfd_boolean
01169 elf_m68k_adjust_dynamic_symbol (info, h)
01170      struct bfd_link_info *info;
01171      struct elf_link_hash_entry *h;
01172 {
01173   struct elf_m68k_link_hash_table *htab;
01174   bfd *dynobj;
01175   asection *s;
01176   unsigned int power_of_two;
01177 
01178   htab = elf_m68k_hash_table (info);
01179   dynobj = elf_hash_table (info)->dynobj;
01180 
01181   /* Make sure we know what is going on here.  */
01182   BFD_ASSERT (dynobj != NULL
01183              && (h->needs_plt
01184                 || h->u.weakdef != NULL
01185                 || (h->def_dynamic
01186                     && h->ref_regular
01187                     && !h->def_regular)));
01188 
01189   /* If this is a function, put it in the procedure linkage table.  We
01190      will fill in the contents of the procedure linkage table later,
01191      when we know the address of the .got section.  */
01192   if (h->type == STT_FUNC
01193       || h->needs_plt)
01194     {
01195       if ((h->plt.refcount <= 0
01196            || SYMBOL_CALLS_LOCAL (info, h)
01197           || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
01198               && h->root.type == bfd_link_hash_undefweak))
01199          /* We must always create the plt entry if it was referenced
01200             by a PLTxxO relocation.  In this case we already recorded
01201             it as a dynamic symbol.  */
01202          && h->dynindx == -1)
01203        {
01204          /* This case can occur if we saw a PLTxx reloc in an input
01205             file, but the symbol was never referred to by a dynamic
01206             object, or if all references were garbage collected.  In
01207             such a case, we don't actually need to build a procedure
01208             linkage table, and we can just do a PCxx reloc instead.  */
01209          h->plt.offset = (bfd_vma) -1;
01210          h->needs_plt = 0;
01211          return TRUE;
01212        }
01213 
01214       /* Make sure this symbol is output as a dynamic symbol.  */
01215       if (h->dynindx == -1
01216          && !h->forced_local)
01217        {
01218          if (! bfd_elf_link_record_dynamic_symbol (info, h))
01219            return FALSE;
01220        }
01221 
01222       s = bfd_get_section_by_name (dynobj, ".plt");
01223       BFD_ASSERT (s != NULL);
01224 
01225       /* If this is the first .plt entry, make room for the special
01226         first entry.  */
01227       if (s->size == 0)
01228        s->size = htab->plt_info->size;
01229 
01230       /* If this symbol is not defined in a regular file, and we are
01231         not generating a shared library, then set the symbol to this
01232         location in the .plt.  This is required to make function
01233         pointers compare as equal between the normal executable and
01234         the shared library.  */
01235       if (!info->shared
01236          && !h->def_regular)
01237        {
01238          h->root.u.def.section = s;
01239          h->root.u.def.value = s->size;
01240        }
01241 
01242       h->plt.offset = s->size;
01243 
01244       /* Make room for this entry.  */
01245       s->size += htab->plt_info->size;
01246 
01247       /* We also need to make an entry in the .got.plt section, which
01248         will be placed in the .got section by the linker script.  */
01249       s = bfd_get_section_by_name (dynobj, ".got.plt");
01250       BFD_ASSERT (s != NULL);
01251       s->size += 4;
01252 
01253       /* We also need to make an entry in the .rela.plt section.  */
01254       s = bfd_get_section_by_name (dynobj, ".rela.plt");
01255       BFD_ASSERT (s != NULL);
01256       s->size += sizeof (Elf32_External_Rela);
01257 
01258       return TRUE;
01259     }
01260 
01261   /* Reinitialize the plt offset now that it is not used as a reference
01262      count any more.  */
01263   h->plt.offset = (bfd_vma) -1;
01264 
01265   /* If this is a weak symbol, and there is a real definition, the
01266      processor independent code will have arranged for us to see the
01267      real definition first, and we can just use the same value.  */
01268   if (h->u.weakdef != NULL)
01269     {
01270       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
01271                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
01272       h->root.u.def.section = h->u.weakdef->root.u.def.section;
01273       h->root.u.def.value = h->u.weakdef->root.u.def.value;
01274       return TRUE;
01275     }
01276 
01277   /* This is a reference to a symbol defined by a dynamic object which
01278      is not a function.  */
01279 
01280   /* If we are creating a shared library, we must presume that the
01281      only references to the symbol are via the global offset table.
01282      For such cases we need not do anything here; the relocations will
01283      be handled correctly by relocate_section.  */
01284   if (info->shared)
01285     return TRUE;
01286 
01287   if (h->size == 0)
01288     {
01289       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
01290                           h->root.root.string);
01291       return TRUE;
01292     }
01293 
01294   /* We must allocate the symbol in our .dynbss section, which will
01295      become part of the .bss section of the executable.  There will be
01296      an entry for this symbol in the .dynsym section.  The dynamic
01297      object will contain position independent code, so all references
01298      from the dynamic object to this symbol will go through the global
01299      offset table.  The dynamic linker will use the .dynsym entry to
01300      determine the address it must put in the global offset table, so
01301      both the dynamic object and the regular object will refer to the
01302      same memory location for the variable.  */
01303 
01304   s = bfd_get_section_by_name (dynobj, ".dynbss");
01305   BFD_ASSERT (s != NULL);
01306 
01307   /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
01308      copy the initial value out of the dynamic object and into the
01309      runtime process image.  We need to remember the offset into the
01310      .rela.bss section we are going to use.  */
01311   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
01312     {
01313       asection *srel;
01314 
01315       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
01316       BFD_ASSERT (srel != NULL);
01317       srel->size += sizeof (Elf32_External_Rela);
01318       h->needs_copy = 1;
01319     }
01320 
01321   /* We need to figure out the alignment required for this symbol.  I
01322      have no idea how ELF linkers handle this.  */
01323   power_of_two = bfd_log2 (h->size);
01324   if (power_of_two > 3)
01325     power_of_two = 3;
01326 
01327   /* Apply the required alignment.  */
01328   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
01329   if (power_of_two > bfd_get_section_alignment (dynobj, s))
01330     {
01331       if (!bfd_set_section_alignment (dynobj, s, power_of_two))
01332        return FALSE;
01333     }
01334 
01335   /* Define the symbol as being at this point in the section.  */
01336   h->root.u.def.section = s;
01337   h->root.u.def.value = s->size;
01338 
01339   /* Increment the section size to make room for the symbol.  */
01340   s->size += h->size;
01341 
01342   return TRUE;
01343 }
01344 
01345 /* Set the sizes of the dynamic sections.  */
01346 
01347 static bfd_boolean
01348 elf_m68k_size_dynamic_sections (output_bfd, info)
01349      bfd *output_bfd ATTRIBUTE_UNUSED;
01350      struct bfd_link_info *info;
01351 {
01352   bfd *dynobj;
01353   asection *s;
01354   bfd_boolean plt;
01355   bfd_boolean relocs;
01356 
01357   dynobj = elf_hash_table (info)->dynobj;
01358   BFD_ASSERT (dynobj != NULL);
01359 
01360   if (elf_hash_table (info)->dynamic_sections_created)
01361     {
01362       /* Set the contents of the .interp section to the interpreter.  */
01363       if (info->executable)
01364        {
01365          s = bfd_get_section_by_name (dynobj, ".interp");
01366          BFD_ASSERT (s != NULL);
01367          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
01368          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
01369        }
01370     }
01371   else
01372     {
01373       /* We may have created entries in the .rela.got section.
01374         However, if we are not creating the dynamic sections, we will
01375         not actually use these entries.  Reset the size of .rela.got,
01376         which will cause it to get stripped from the output file
01377         below.  */
01378       s = bfd_get_section_by_name (dynobj, ".rela.got");
01379       if (s != NULL)
01380        s->size = 0;
01381     }
01382 
01383   /* If this is a -Bsymbolic shared link, then we need to discard all
01384      PC relative relocs against symbols defined in a regular object.
01385      For the normal shared case we discard the PC relative relocs
01386      against symbols that have become local due to visibility changes.
01387      We allocated space for them in the check_relocs routine, but we
01388      will not fill them in in the relocate_section routine.  */
01389   if (info->shared)
01390     elf_link_hash_traverse (elf_hash_table (info),
01391                          elf_m68k_discard_copies,
01392                          (PTR) info);
01393 
01394   /* The check_relocs and adjust_dynamic_symbol entry points have
01395      determined the sizes of the various dynamic sections.  Allocate
01396      memory for them.  */
01397   plt = FALSE;
01398   relocs = FALSE;
01399   for (s = dynobj->sections; s != NULL; s = s->next)
01400     {
01401       const char *name;
01402 
01403       if ((s->flags & SEC_LINKER_CREATED) == 0)
01404        continue;
01405 
01406       /* It's OK to base decisions on the section name, because none
01407         of the dynobj section names depend upon the input files.  */
01408       name = bfd_get_section_name (dynobj, s);
01409 
01410       if (strcmp (name, ".plt") == 0)
01411        {
01412          /* Remember whether there is a PLT.  */
01413          plt = s->size != 0;
01414        }
01415       else if (CONST_STRNEQ (name, ".rela"))
01416        {
01417          if (s->size != 0)
01418            {
01419              relocs = TRUE;
01420 
01421              /* We use the reloc_count field as a counter if we need
01422                to copy relocs into the output file.  */
01423              s->reloc_count = 0;
01424            }
01425        }
01426       else if (! CONST_STRNEQ (name, ".got")
01427               && strcmp (name, ".dynbss") != 0)
01428        {
01429          /* It's not one of our sections, so don't allocate space.  */
01430          continue;
01431        }
01432 
01433       if (s->size == 0)
01434        {
01435          /* If we don't need this section, strip it from the
01436             output file.  This is mostly to handle .rela.bss and
01437             .rela.plt.  We must create both sections in
01438             create_dynamic_sections, because they must be created
01439             before the linker maps input sections to output
01440             sections.  The linker does that before
01441             adjust_dynamic_symbol is called, and it is that
01442             function which decides whether anything needs to go
01443             into these sections.  */
01444          s->flags |= SEC_EXCLUDE;
01445          continue;
01446        }
01447 
01448       if ((s->flags & SEC_HAS_CONTENTS) == 0)
01449        continue;
01450 
01451       /* Allocate memory for the section contents.  */
01452       /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
01453         Unused entries should be reclaimed before the section's contents
01454         are written out, but at the moment this does not happen.  Thus in
01455         order to prevent writing out garbage, we initialise the section's
01456         contents to zero.  */
01457       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
01458       if (s->contents == NULL)
01459        return FALSE;
01460     }
01461 
01462   if (elf_hash_table (info)->dynamic_sections_created)
01463     {
01464       /* Add some entries to the .dynamic section.  We fill in the
01465         values later, in elf_m68k_finish_dynamic_sections, but we
01466         must add the entries now so that we get the correct size for
01467         the .dynamic section.  The DT_DEBUG entry is filled in by the
01468         dynamic linker and used by the debugger.  */
01469 #define add_dynamic_entry(TAG, VAL) \
01470   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
01471 
01472       if (!info->shared)
01473        {
01474          if (!add_dynamic_entry (DT_DEBUG, 0))
01475            return FALSE;
01476        }
01477 
01478       if (plt)
01479        {
01480          if (!add_dynamic_entry (DT_PLTGOT, 0)
01481              || !add_dynamic_entry (DT_PLTRELSZ, 0)
01482              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
01483              || !add_dynamic_entry (DT_JMPREL, 0))
01484            return FALSE;
01485        }
01486 
01487       if (relocs)
01488        {
01489          if (!add_dynamic_entry (DT_RELA, 0)
01490              || !add_dynamic_entry (DT_RELASZ, 0)
01491              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
01492            return FALSE;
01493        }
01494 
01495       if ((info->flags & DF_TEXTREL) != 0)
01496        {
01497          if (!add_dynamic_entry (DT_TEXTREL, 0))
01498            return FALSE;
01499        }
01500     }
01501 #undef add_dynamic_entry
01502 
01503   return TRUE;
01504 }
01505 
01506 /* This function is called via elf_link_hash_traverse if we are
01507    creating a shared object.  In the -Bsymbolic case it discards the
01508    space allocated to copy PC relative relocs against symbols which
01509    are defined in regular objects.  For the normal shared case, it
01510    discards space for pc-relative relocs that have become local due to
01511    symbol visibility changes.  We allocated space for them in the
01512    check_relocs routine, but we won't fill them in in the
01513    relocate_section routine.
01514 
01515    We also check whether any of the remaining relocations apply
01516    against a readonly section, and set the DF_TEXTREL flag in this
01517    case.  */
01518 
01519 static bfd_boolean
01520 elf_m68k_discard_copies (h, inf)
01521      struct elf_link_hash_entry *h;
01522      PTR inf;
01523 {
01524   struct bfd_link_info *info = (struct bfd_link_info *) inf;
01525   struct elf_m68k_pcrel_relocs_copied *s;
01526 
01527   if (h->root.type == bfd_link_hash_warning)
01528     h = (struct elf_link_hash_entry *) h->root.u.i.link;
01529 
01530   if (!h->def_regular
01531       || (!info->symbolic
01532          && !h->forced_local))
01533     {
01534       if ((info->flags & DF_TEXTREL) == 0)
01535        {
01536          /* Look for relocations against read-only sections.  */
01537          for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
01538               s != NULL;
01539               s = s->next)
01540            if ((s->section->flags & SEC_READONLY) != 0)
01541              {
01542               info->flags |= DF_TEXTREL;
01543               break;
01544              }
01545        }
01546 
01547       return TRUE;
01548     }
01549 
01550   for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
01551        s != NULL;
01552        s = s->next)
01553     s->section->size -= s->count * sizeof (Elf32_External_Rela);
01554 
01555   return TRUE;
01556 }
01557 
01558 /* Relocate an M68K ELF section.  */
01559 
01560 static bfd_boolean
01561 elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section,
01562                         contents, relocs, local_syms, local_sections)
01563      bfd *output_bfd;
01564      struct bfd_link_info *info;
01565      bfd *input_bfd;
01566      asection *input_section;
01567      bfd_byte *contents;
01568      Elf_Internal_Rela *relocs;
01569      Elf_Internal_Sym *local_syms;
01570      asection **local_sections;
01571 {
01572   bfd *dynobj;
01573   Elf_Internal_Shdr *symtab_hdr;
01574   struct elf_link_hash_entry **sym_hashes;
01575   bfd_vma *local_got_offsets;
01576   asection *sgot;
01577   asection *splt;
01578   asection *sreloc;
01579   Elf_Internal_Rela *rel;
01580   Elf_Internal_Rela *relend;
01581 
01582   dynobj = elf_hash_table (info)->dynobj;
01583   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
01584   sym_hashes = elf_sym_hashes (input_bfd);
01585   local_got_offsets = elf_local_got_offsets (input_bfd);
01586 
01587   sgot = NULL;
01588   splt = NULL;
01589   sreloc = NULL;
01590 
01591   rel = relocs;
01592   relend = relocs + input_section->reloc_count;
01593   for (; rel < relend; rel++)
01594     {
01595       int r_type;
01596       reloc_howto_type *howto;
01597       unsigned long r_symndx;
01598       struct elf_link_hash_entry *h;
01599       Elf_Internal_Sym *sym;
01600       asection *sec;
01601       bfd_vma relocation;
01602       bfd_boolean unresolved_reloc;
01603       bfd_reloc_status_type r;
01604 
01605       r_type = ELF32_R_TYPE (rel->r_info);
01606       if (r_type < 0 || r_type >= (int) R_68K_max)
01607        {
01608          bfd_set_error (bfd_error_bad_value);
01609          return FALSE;
01610        }
01611       howto = howto_table + r_type;
01612 
01613       r_symndx = ELF32_R_SYM (rel->r_info);
01614 
01615       h = NULL;
01616       sym = NULL;
01617       sec = NULL;
01618       unresolved_reloc = FALSE;
01619 
01620       if (r_symndx < symtab_hdr->sh_info)
01621        {
01622          sym = local_syms + r_symndx;
01623          sec = local_sections[r_symndx];
01624          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
01625        }
01626       else
01627        {
01628          bfd_boolean warned;
01629 
01630          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
01631                                r_symndx, symtab_hdr, sym_hashes,
01632                                h, sec, relocation,
01633                                unresolved_reloc, warned);
01634        }
01635 
01636       if (sec != NULL && elf_discarded_section (sec))
01637        {
01638          /* For relocs against symbols from removed linkonce sections,
01639             or sections discarded by a linker script, we just want the
01640             section contents zeroed.  Avoid any special processing.  */
01641          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
01642          rel->r_info = 0;
01643          rel->r_addend = 0;
01644          continue;
01645        }
01646 
01647       if (info->relocatable)
01648        continue;
01649 
01650       switch (r_type)
01651        {
01652        case R_68K_GOT8:
01653        case R_68K_GOT16:
01654        case R_68K_GOT32:
01655          /* Relocation is to the address of the entry for this symbol
01656             in the global offset table.  */
01657          if (h != NULL
01658              && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
01659            break;
01660          /* Fall through.  */
01661        case R_68K_GOT8O:
01662        case R_68K_GOT16O:
01663        case R_68K_GOT32O:
01664          /* Relocation is the offset of the entry for this symbol in
01665             the global offset table.  */
01666 
01667          {
01668            bfd_vma off;
01669 
01670            if (sgot == NULL)
01671              {
01672               sgot = bfd_get_section_by_name (dynobj, ".got");
01673               BFD_ASSERT (sgot != NULL);
01674              }
01675 
01676            if (h != NULL)
01677              {
01678               bfd_boolean dyn;
01679 
01680               off = h->got.offset;
01681               BFD_ASSERT (off != (bfd_vma) -1);
01682 
01683               dyn = elf_hash_table (info)->dynamic_sections_created;
01684               if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
01685                   || (info->shared
01686                      && (info->symbolic
01687                          || h->dynindx == -1
01688                          || h->forced_local)
01689                      && h->def_regular))
01690                 {
01691                   /* This is actually a static link, or it is a
01692                      -Bsymbolic link and the symbol is defined
01693                      locally, or the symbol was forced to be local
01694                      because of a version file..  We must initialize
01695                      this entry in the global offset table.  Since
01696                      the offset must always be a multiple of 4, we
01697                      use the least significant bit to record whether
01698                      we have initialized it already.
01699 
01700                      When doing a dynamic link, we create a .rela.got
01701                      relocation entry to initialize the value.  This
01702                      is done in the finish_dynamic_symbol routine.  */
01703                   if ((off & 1) != 0)
01704                     off &= ~1;
01705                   else
01706                     {
01707                      bfd_put_32 (output_bfd, relocation,
01708                                 sgot->contents + off);
01709                      h->got.offset |= 1;
01710                     }
01711                 }
01712               else
01713                 unresolved_reloc = FALSE;
01714              }
01715            else
01716              {
01717               BFD_ASSERT (local_got_offsets != NULL
01718                          && local_got_offsets[r_symndx] != (bfd_vma) -1);
01719 
01720               off = local_got_offsets[r_symndx];
01721 
01722               /* The offset must always be a multiple of 4.  We use
01723                  the least significant bit to record whether we have
01724                  already generated the necessary reloc.  */
01725               if ((off & 1) != 0)
01726                 off &= ~1;
01727               else
01728                 {
01729                   bfd_put_32 (output_bfd, relocation, sgot->contents + off);
01730 
01731                   if (info->shared)
01732                     {
01733                      asection *s;
01734                      Elf_Internal_Rela outrel;
01735                      bfd_byte *loc;
01736 
01737                      s = bfd_get_section_by_name (dynobj, ".rela.got");
01738                      BFD_ASSERT (s != NULL);
01739 
01740                      outrel.r_offset = (sgot->output_section->vma
01741                                       + sgot->output_offset
01742                                       + off);
01743                      outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
01744                      outrel.r_addend = relocation;
01745                      loc = s->contents;
01746                      loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
01747                      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
01748                     }
01749 
01750                   local_got_offsets[r_symndx] |= 1;
01751                 }
01752              }
01753 
01754            relocation = sgot->output_offset + off;
01755            if (r_type == R_68K_GOT8O
01756               || r_type == R_68K_GOT16O
01757               || r_type == R_68K_GOT32O)
01758              {
01759               /* This relocation does not use the addend.  */
01760               rel->r_addend = 0;
01761              }
01762            else
01763              relocation += sgot->output_section->vma;
01764          }
01765          break;
01766 
01767        case R_68K_PLT8:
01768        case R_68K_PLT16:
01769        case R_68K_PLT32:
01770          /* Relocation is to the entry for this symbol in the
01771             procedure linkage table.  */
01772 
01773          /* Resolve a PLTxx reloc against a local symbol directly,
01774             without using the procedure linkage table.  */
01775          if (h == NULL)
01776            break;
01777 
01778          if (h->plt.offset == (bfd_vma) -1
01779              || !elf_hash_table (info)->dynamic_sections_created)
01780            {
01781              /* We didn't make a PLT entry for this symbol.  This
01782                happens when statically linking PIC code, or when
01783                using -Bsymbolic.  */
01784              break;
01785            }
01786 
01787          if (splt == NULL)
01788            {
01789              splt = bfd_get_section_by_name (dynobj, ".plt");
01790              BFD_ASSERT (splt != NULL);
01791            }
01792 
01793          relocation = (splt->output_section->vma
01794                      + splt->output_offset
01795                      + h->plt.offset);
01796          unresolved_reloc = FALSE;
01797          break;
01798 
01799        case R_68K_PLT8O:
01800        case R_68K_PLT16O:
01801        case R_68K_PLT32O:
01802          /* Relocation is the offset of the entry for this symbol in
01803             the procedure linkage table.  */
01804          BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
01805 
01806          if (splt == NULL)
01807            {
01808              splt = bfd_get_section_by_name (dynobj, ".plt");
01809              BFD_ASSERT (splt != NULL);
01810            }
01811 
01812          relocation = h->plt.offset;
01813          unresolved_reloc = FALSE;
01814 
01815          /* This relocation does not use the addend.  */
01816          rel->r_addend = 0;
01817 
01818          break;
01819 
01820        case R_68K_PC8:
01821        case R_68K_PC16:
01822        case R_68K_PC32:
01823          if (h == NULL
01824              || (info->shared
01825                 && h->forced_local))
01826            break;
01827          /* Fall through.  */
01828        case R_68K_8:
01829        case R_68K_16:
01830        case R_68K_32:
01831          if (info->shared
01832              && r_symndx != 0
01833              && (input_section->flags & SEC_ALLOC) != 0
01834              && (h == NULL
01835                 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
01836                 || h->root.type != bfd_link_hash_undefweak)
01837              && ((r_type != R_68K_PC8
01838                  && r_type != R_68K_PC16
01839                  && r_type != R_68K_PC32)
01840                 || (h != NULL
01841                     && h->dynindx != -1
01842                     && (!info->symbolic
01843                        || !h->def_regular))))
01844            {
01845              Elf_Internal_Rela outrel;
01846              bfd_byte *loc;
01847              bfd_boolean skip, relocate;
01848 
01849              /* When generating a shared object, these relocations
01850                are copied into the output file to be resolved at run
01851                time.  */
01852 
01853              skip = FALSE;
01854              relocate = FALSE;
01855 
01856              outrel.r_offset =
01857               _bfd_elf_section_offset (output_bfd, info, input_section,
01858                                     rel->r_offset);
01859              if (outrel.r_offset == (bfd_vma) -1)
01860               skip = TRUE;
01861              else if (outrel.r_offset == (bfd_vma) -2)
01862               skip = TRUE, relocate = TRUE;
01863              outrel.r_offset += (input_section->output_section->vma
01864                               + input_section->output_offset);
01865 
01866              if (skip)
01867               memset (&outrel, 0, sizeof outrel);
01868              else if (h != NULL
01869                      && h->dynindx != -1
01870                      && (r_type == R_68K_PC8
01871                         || r_type == R_68K_PC16
01872                         || r_type == R_68K_PC32
01873                         || !info->shared
01874                         || !info->symbolic
01875                         || !h->def_regular))
01876               {
01877                 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
01878                 outrel.r_addend = rel->r_addend;
01879               }
01880              else
01881               {
01882                 /* This symbol is local, or marked to become local.  */
01883                 outrel.r_addend = relocation + rel->r_addend;
01884 
01885                 if (r_type == R_68K_32)
01886                   {
01887                     relocate = TRUE;
01888                     outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
01889                   }
01890                 else
01891                   {
01892                     long indx;
01893 
01894                     if (bfd_is_abs_section (sec))
01895                      indx = 0;
01896                     else if (sec == NULL || sec->owner == NULL)
01897                      {
01898                        bfd_set_error (bfd_error_bad_value);
01899                        return FALSE;
01900                      }
01901                     else
01902                      {
01903                        asection *osec;
01904 
01905                        /* We are turning this relocation into one
01906                           against a section symbol.  It would be
01907                           proper to subtract the symbol's value,
01908                           osec->vma, from the emitted reloc addend,
01909                           but ld.so expects buggy relocs.  */
01910                        osec = sec->output_section;
01911                        indx = elf_section_data (osec)->dynindx;
01912                        if (indx == 0)
01913                          {
01914                            struct elf_link_hash_table *htab;
01915                            htab = elf_hash_table (info);
01916                            osec = htab->text_index_section;
01917                            indx = elf_section_data (osec)->dynindx;
01918                          }
01919                        BFD_ASSERT (indx != 0);
01920                      }
01921 
01922                     outrel.r_info = ELF32_R_INFO (indx, r_type);
01923                   }
01924               }
01925 
01926              sreloc = elf_section_data (input_section)->sreloc;
01927              if (sreloc == NULL)
01928               abort ();
01929 
01930              loc = sreloc->contents;
01931              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
01932              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
01933 
01934              /* This reloc will be computed at runtime, so there's no
01935                  need to do anything now, except for R_68K_32
01936                  relocations that have been turned into
01937                  R_68K_RELATIVE.  */
01938              if (!relocate)
01939               continue;
01940            }
01941 
01942          break;
01943 
01944        case R_68K_GNU_VTINHERIT:
01945        case R_68K_GNU_VTENTRY:
01946          /* These are no-ops in the end.  */
01947          continue;
01948 
01949        default:
01950          break;
01951        }
01952 
01953       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
01954         because such sections are not SEC_ALLOC and thus ld.so will
01955         not process them.  */
01956       if (unresolved_reloc
01957          && !((input_section->flags & SEC_DEBUGGING) != 0
01958               && h->def_dynamic))
01959        {
01960          (*_bfd_error_handler)
01961            (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
01962             input_bfd,
01963             input_section,
01964             (long) rel->r_offset,
01965             howto->name,
01966             h->root.root.string);
01967          return FALSE;
01968        }
01969 
01970       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
01971                                 contents, rel->r_offset,
01972                                 relocation, rel->r_addend);
01973 
01974       if (r != bfd_reloc_ok)
01975        {
01976          const char *name;
01977 
01978          if (h != NULL)
01979            name = h->root.root.string;
01980          else
01981            {
01982              name = bfd_elf_string_from_elf_section (input_bfd,
01983                                                 symtab_hdr->sh_link,
01984                                                 sym->st_name);
01985              if (name == NULL)
01986               return FALSE;
01987              if (*name == '\0')
01988               name = bfd_section_name (input_bfd, sec);
01989            }
01990 
01991          if (r == bfd_reloc_overflow)
01992            {
01993              if (!(info->callbacks->reloc_overflow
01994                   (info, (h ? &h->root : NULL), name, howto->name,
01995                    (bfd_vma) 0, input_bfd, input_section,
01996                    rel->r_offset)))
01997               return FALSE;
01998            }
01999          else
02000            {
02001              (*_bfd_error_handler)
02002               (_("%B(%A+0x%lx): reloc against `%s': error %d"),
02003                input_bfd, input_section,
02004                (long) rel->r_offset, name, (int) r);
02005              return FALSE;
02006            }
02007        }
02008     }
02009 
02010   return TRUE;
02011 }
02012 
02013 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
02014    into section SEC.  */
02015 
02016 static void
02017 elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
02018 {
02019   /* Make VALUE PC-relative.  */
02020   value -= sec->output_section->vma + offset;
02021 
02022   /* Apply any in-place addend.  */
02023   value += bfd_get_32 (sec->owner, sec->contents + offset);
02024 
02025   bfd_put_32 (sec->owner, value, sec->contents + offset);
02026 }
02027 
02028 /* Finish up dynamic symbol handling.  We set the contents of various
02029    dynamic sections here.  */
02030 
02031 static bfd_boolean
02032 elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym)
02033      bfd *output_bfd;
02034      struct bfd_link_info *info;
02035      struct elf_link_hash_entry *h;
02036      Elf_Internal_Sym *sym;
02037 {
02038   bfd *dynobj;
02039 
02040   dynobj = elf_hash_table (info)->dynobj;
02041 
02042   if (h->plt.offset != (bfd_vma) -1)
02043     {
02044       const struct elf_m68k_plt_info *plt_info;
02045       asection *splt;
02046       asection *sgot;
02047       asection *srela;
02048       bfd_vma plt_index;
02049       bfd_vma got_offset;
02050       Elf_Internal_Rela rela;
02051       bfd_byte *loc;
02052 
02053       /* This symbol has an entry in the procedure linkage table.  Set
02054         it up.  */
02055 
02056       BFD_ASSERT (h->dynindx != -1);
02057 
02058       plt_info = elf_m68k_hash_table (info)->plt_info;
02059       splt = bfd_get_section_by_name (dynobj, ".plt");
02060       sgot = bfd_get_section_by_name (dynobj, ".got.plt");
02061       srela = bfd_get_section_by_name (dynobj, ".rela.plt");
02062       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
02063 
02064       /* Get the index in the procedure linkage table which
02065         corresponds to this symbol.  This is the index of this symbol
02066         in all the symbols for which we are making plt entries.  The
02067         first entry in the procedure linkage table is reserved.  */
02068       plt_index = (h->plt.offset / plt_info->size) - 1;
02069 
02070       /* Get the offset into the .got table of the entry that
02071         corresponds to this function.  Each .got entry is 4 bytes.
02072         The first three are reserved.  */
02073       got_offset = (plt_index + 3) * 4;
02074 
02075       memcpy (splt->contents + h->plt.offset,
02076              plt_info->symbol_entry,
02077              plt_info->size);
02078 
02079       elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
02080                           (sgot->output_section->vma
02081                            + sgot->output_offset
02082                            + got_offset));
02083 
02084       bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
02085                 splt->contents
02086                 + h->plt.offset
02087                 + plt_info->symbol_resolve_entry + 2);
02088 
02089       elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
02090                           splt->output_section->vma);
02091 
02092       /* Fill in the entry in the global offset table.  */
02093       bfd_put_32 (output_bfd,
02094                 (splt->output_section->vma
02095                  + splt->output_offset
02096                  + h->plt.offset
02097                  + plt_info->symbol_resolve_entry),
02098                 sgot->contents + got_offset);
02099 
02100       /* Fill in the entry in the .rela.plt section.  */
02101       rela.r_offset = (sgot->output_section->vma
02102                      + sgot->output_offset
02103                      + got_offset);
02104       rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
02105       rela.r_addend = 0;
02106       loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
02107       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
02108 
02109       if (!h->def_regular)
02110        {
02111          /* Mark the symbol as undefined, rather than as defined in
02112             the .plt section.  Leave the value alone.  */
02113          sym->st_shndx = SHN_UNDEF;
02114        }
02115     }
02116 
02117   if (h->got.offset != (bfd_vma) -1)
02118     {
02119       asection *sgot;
02120       asection *srela;
02121       Elf_Internal_Rela rela;
02122       bfd_byte *loc;
02123 
02124       /* This symbol has an entry in the global offset table.  Set it
02125         up.  */
02126 
02127       sgot = bfd_get_section_by_name (dynobj, ".got");
02128       srela = bfd_get_section_by_name (dynobj, ".rela.got");
02129       BFD_ASSERT (sgot != NULL && srela != NULL);
02130 
02131       rela.r_offset = (sgot->output_section->vma
02132                      + sgot->output_offset
02133                      + (h->got.offset &~ (bfd_vma) 1));
02134 
02135       /* If this is a -Bsymbolic link, and the symbol is defined
02136         locally, we just want to emit a RELATIVE reloc.  Likewise if
02137         the symbol was forced to be local because of a version file.
02138         The entry in the global offset table will already have been
02139         initialized in the relocate_section function.  */
02140       if (info->shared
02141          && (info->symbolic
02142              || h->dynindx == -1
02143              || h->forced_local)
02144          && h->def_regular)
02145        {
02146          rela.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
02147          rela.r_addend = bfd_get_signed_32 (output_bfd,
02148                                         (sgot->contents
02149                                          + (h->got.offset &~ (bfd_vma) 1)));
02150        }
02151       else
02152        {
02153          bfd_put_32 (output_bfd, (bfd_vma) 0,
02154                     sgot->contents + (h->got.offset &~ (bfd_vma) 1));
02155          rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
02156          rela.r_addend = 0;
02157        }
02158 
02159       loc = srela->contents;
02160       loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
02161       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
02162     }
02163 
02164   if (h->needs_copy)
02165     {
02166       asection *s;
02167       Elf_Internal_Rela rela;
02168       bfd_byte *loc;
02169 
02170       /* This symbol needs a copy reloc.  Set it up.  */
02171 
02172       BFD_ASSERT (h->dynindx != -1
02173                 && (h->root.type == bfd_link_hash_defined
02174                     || h->root.type == bfd_link_hash_defweak));
02175 
02176       s = bfd_get_section_by_name (h->root.u.def.section->owner,
02177                                ".rela.bss");
02178       BFD_ASSERT (s != NULL);
02179 
02180       rela.r_offset = (h->root.u.def.value
02181                      + h->root.u.def.section->output_section->vma
02182                      + h->root.u.def.section->output_offset);
02183       rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
02184       rela.r_addend = 0;
02185       loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
02186       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
02187     }
02188 
02189   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
02190   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
02191       || h == elf_hash_table (info)->hgot)
02192     sym->st_shndx = SHN_ABS;
02193 
02194   return TRUE;
02195 }
02196 
02197 /* Finish up the dynamic sections.  */
02198 
02199 static bfd_boolean
02200 elf_m68k_finish_dynamic_sections (output_bfd, info)
02201      bfd *output_bfd;
02202      struct bfd_link_info *info;
02203 {
02204   bfd *dynobj;
02205   asection *sgot;
02206   asection *sdyn;
02207 
02208   dynobj = elf_hash_table (info)->dynobj;
02209 
02210   sgot = bfd_get_section_by_name (dynobj, ".got.plt");
02211   BFD_ASSERT (sgot != NULL);
02212   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
02213 
02214   if (elf_hash_table (info)->dynamic_sections_created)
02215     {
02216       asection *splt;
02217       Elf32_External_Dyn *dyncon, *dynconend;
02218 
02219       splt = bfd_get_section_by_name (dynobj, ".plt");
02220       BFD_ASSERT (splt != NULL && sdyn != NULL);
02221 
02222       dyncon = (Elf32_External_Dyn *) sdyn->contents;
02223       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
02224       for (; dyncon < dynconend; dyncon++)
02225        {
02226          Elf_Internal_Dyn dyn;
02227          const char *name;
02228          asection *s;
02229 
02230          bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
02231 
02232          switch (dyn.d_tag)
02233            {
02234            default:
02235              break;
02236 
02237            case DT_PLTGOT:
02238              name = ".got";
02239              goto get_vma;
02240            case DT_JMPREL:
02241              name = ".rela.plt";
02242            get_vma:
02243              s = bfd_get_section_by_name (output_bfd, name);
02244              BFD_ASSERT (s != NULL);
02245              dyn.d_un.d_ptr = s->vma;
02246              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
02247              break;
02248 
02249            case DT_PLTRELSZ:
02250              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
02251              BFD_ASSERT (s != NULL);
02252              dyn.d_un.d_val = s->size;
02253              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
02254              break;
02255 
02256            case DT_RELASZ:
02257              /* The procedure linkage table relocs (DT_JMPREL) should
02258                not be included in the overall relocs (DT_RELA).
02259                Therefore, we override the DT_RELASZ entry here to
02260                make it not include the JMPREL relocs.  Since the
02261                linker script arranges for .rela.plt to follow all
02262                other relocation sections, we don't have to worry
02263                about changing the DT_RELA entry.  */
02264              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
02265              if (s != NULL)
02266               dyn.d_un.d_val -= s->size;
02267              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
02268              break;
02269            }
02270        }
02271 
02272       /* Fill in the first entry in the procedure linkage table.  */
02273       if (splt->size > 0)
02274        {
02275          const struct elf_m68k_plt_info *plt_info;
02276 
02277          plt_info = elf_m68k_hash_table (info)->plt_info;
02278          memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
02279 
02280          elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
02281                              (sgot->output_section->vma
02282                               + sgot->output_offset
02283                               + 4));
02284 
02285          elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
02286                              (sgot->output_section->vma
02287                               + sgot->output_offset
02288                               + 8));
02289 
02290          elf_section_data (splt->output_section)->this_hdr.sh_entsize
02291            = plt_info->size;
02292        }
02293     }
02294 
02295   /* Fill in the first three entries in the global offset table.  */
02296   if (sgot->size > 0)
02297     {
02298       if (sdyn == NULL)
02299        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
02300       else
02301        bfd_put_32 (output_bfd,
02302                   sdyn->output_section->vma + sdyn->output_offset,
02303                   sgot->contents);
02304       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
02305       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
02306     }
02307 
02308   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
02309 
02310   return TRUE;
02311 }
02312 
02313 /* Given a .data section and a .emreloc in-memory section, store
02314    relocation information into the .emreloc section which can be
02315    used at runtime to relocate the section.  This is called by the
02316    linker when the --embedded-relocs switch is used.  This is called
02317    after the add_symbols entry point has been called for all the
02318    objects, and before the final_link entry point is called.  */
02319 
02320 bfd_boolean
02321 bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
02322      bfd *abfd;
02323      struct bfd_link_info *info;
02324      asection *datasec;
02325      asection *relsec;
02326      char **errmsg;
02327 {
02328   Elf_Internal_Shdr *symtab_hdr;
02329   Elf_Internal_Sym *isymbuf = NULL;
02330   Elf_Internal_Rela *internal_relocs = NULL;
02331   Elf_Internal_Rela *irel, *irelend;
02332   bfd_byte *p;
02333   bfd_size_type amt;
02334 
02335   BFD_ASSERT (! info->relocatable);
02336 
02337   *errmsg = NULL;
02338 
02339   if (datasec->reloc_count == 0)
02340     return TRUE;
02341 
02342   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
02343 
02344   /* Get a copy of the native relocations.  */
02345   internal_relocs = (_bfd_elf_link_read_relocs
02346                    (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
02347                     info->keep_memory));
02348   if (internal_relocs == NULL)
02349     goto error_return;
02350 
02351   amt = (bfd_size_type) datasec->reloc_count * 12;
02352   relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
02353   if (relsec->contents == NULL)
02354     goto error_return;
02355 
02356   p = relsec->contents;
02357 
02358   irelend = internal_relocs + datasec->reloc_count;
02359   for (irel = internal_relocs; irel < irelend; irel++, p += 12)
02360     {
02361       asection *targetsec;
02362 
02363       /* We are going to write a four byte longword into the runtime
02364        reloc section.  The longword will be the address in the data
02365        section which must be relocated.  It is followed by the name
02366        of the target section NUL-padded or truncated to 8
02367        characters.  */
02368 
02369       /* We can only relocate absolute longword relocs at run time.  */
02370       if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
02371        {
02372          *errmsg = _("unsupported reloc type");
02373          bfd_set_error (bfd_error_bad_value);
02374          goto error_return;
02375        }
02376 
02377       /* Get the target section referred to by the reloc.  */
02378       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
02379        {
02380          /* A local symbol.  */
02381          Elf_Internal_Sym *isym;
02382 
02383          /* Read this BFD's local symbols if we haven't done so already.  */
02384          if (isymbuf == NULL)
02385            {
02386              isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
02387              if (isymbuf == NULL)
02388               isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
02389                                           symtab_hdr->sh_info, 0,
02390                                           NULL, NULL, NULL);
02391              if (isymbuf == NULL)
02392               goto error_return;
02393            }
02394 
02395          isym = isymbuf + ELF32_R_SYM (irel->r_info);
02396          targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
02397        }
02398       else
02399        {
02400          unsigned long indx;
02401          struct elf_link_hash_entry *h;
02402 
02403          /* An external symbol.  */
02404          indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
02405          h = elf_sym_hashes (abfd)[indx];
02406          BFD_ASSERT (h != NULL);
02407          if (h->root.type == bfd_link_hash_defined
02408              || h->root.type == bfd_link_hash_defweak)
02409            targetsec = h->root.u.def.section;
02410          else
02411            targetsec = NULL;
02412        }
02413 
02414       bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
02415       memset (p + 4, 0, 8);
02416       if (targetsec != NULL)
02417        strncpy ((char *) p + 4, targetsec->output_section->name, 8);
02418     }
02419 
02420   if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
02421     free (isymbuf);
02422   if (internal_relocs != NULL
02423       && elf_section_data (datasec)->relocs != internal_relocs)
02424     free (internal_relocs);
02425   return TRUE;
02426 
02427 error_return:
02428   if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
02429     free (isymbuf);
02430   if (internal_relocs != NULL
02431       && elf_section_data (datasec)->relocs != internal_relocs)
02432     free (internal_relocs);
02433   return FALSE;
02434 }
02435 
02436 static enum elf_reloc_type_class
02437 elf32_m68k_reloc_type_class (rela)
02438      const Elf_Internal_Rela *rela;
02439 {
02440   switch ((int) ELF32_R_TYPE (rela->r_info))
02441     {
02442     case R_68K_RELATIVE:
02443       return reloc_class_relative;
02444     case R_68K_JMP_SLOT:
02445       return reloc_class_plt;
02446     case R_68K_COPY:
02447       return reloc_class_copy;
02448     default:
02449       return reloc_class_normal;
02450     }
02451 }
02452 
02453 /* Return address for Ith PLT stub in section PLT, for relocation REL
02454    or (bfd_vma) -1 if it should not be included.  */
02455 
02456 static bfd_vma
02457 elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
02458                     const arelent *rel ATTRIBUTE_UNUSED)
02459 {
02460   return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
02461 }
02462 
02463 #define TARGET_BIG_SYM                    bfd_elf32_m68k_vec
02464 #define TARGET_BIG_NAME                   "elf32-m68k"
02465 #define ELF_MACHINE_CODE           EM_68K
02466 #define ELF_MAXPAGESIZE                   0x2000
02467 #define elf_backend_create_dynamic_sections \
02468                                    _bfd_elf_create_dynamic_sections
02469 #define bfd_elf32_bfd_link_hash_table_create \
02470                                    elf_m68k_link_hash_table_create
02471 #define bfd_elf32_bfd_final_link   bfd_elf_gc_common_final_link
02472 
02473 #define elf_backend_check_relocs   elf_m68k_check_relocs
02474 #define elf_backend_always_size_sections \
02475                                    elf_m68k_always_size_sections
02476 #define elf_backend_adjust_dynamic_symbol \
02477                                    elf_m68k_adjust_dynamic_symbol
02478 #define elf_backend_size_dynamic_sections \
02479                                    elf_m68k_size_dynamic_sections
02480 #define elf_backend_init_index_section    _bfd_elf_init_1_index_section
02481 #define elf_backend_relocate_section      elf_m68k_relocate_section
02482 #define elf_backend_finish_dynamic_symbol \
02483                                    elf_m68k_finish_dynamic_symbol
02484 #define elf_backend_finish_dynamic_sections \
02485                                    elf_m68k_finish_dynamic_sections
02486 #define elf_backend_gc_mark_hook   elf_m68k_gc_mark_hook
02487 #define elf_backend_gc_sweep_hook  elf_m68k_gc_sweep_hook
02488 #define bfd_elf32_bfd_merge_private_bfd_data \
02489                                         elf32_m68k_merge_private_bfd_data
02490 #define bfd_elf32_bfd_set_private_flags \
02491                                         elf32_m68k_set_private_flags
02492 #define bfd_elf32_bfd_print_private_bfd_data \
02493                                         elf32_m68k_print_private_bfd_data
02494 #define elf_backend_reloc_type_class      elf32_m68k_reloc_type_class
02495 #define elf_backend_plt_sym_val           elf_m68k_plt_sym_val
02496 #define elf_backend_object_p              elf32_m68k_object_p
02497 
02498 #define elf_backend_can_gc_sections 1
02499 #define elf_backend_can_refcount 1
02500 #define elf_backend_want_got_plt 1
02501 #define elf_backend_plt_readonly 1
02502 #define elf_backend_want_plt_sym 0
02503 #define elf_backend_got_header_size       12
02504 #define elf_backend_rela_normal           1
02505 
02506 #include "elf32-target.h"