Back to index

cell-binutils  2.17cvs20070401
elf32-m32r.c
Go to the documentation of this file.
00001 /* M32R-specific support for 32-bit ELF.
00002    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00003    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 "libbfd.h"
00024 #include "elf-bfd.h"
00025 #include "elf/m32r.h"
00026 
00027 #define NOP_INSN            0x7000
00028 #define MAKE_PARALLEL(insn) ((insn) | 0x8000)
00029 
00030 /* Use REL instead of RELA to save space.
00031    This only saves space in libraries and object files, but perhaps
00032    relocs will be put in ROM?  All in all though, REL relocs are a pain
00033    to work with.  */
00034 /* #define USE_REL   1
00035 
00036 #ifndef USE_REL
00037 #define USE_REL      0
00038 #endif */
00039 /* Use RELA. But use REL to link old objects for backwords compatibility.  */
00040 
00041 /* Functions for the M32R ELF linker.  */
00042 
00043 /* The name of the dynamic interpreter.  This is put in the .interp
00044    section.  */
00045 
00046 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
00047 
00048 /* The nop opcode we use.  */
00049 
00050 #define M32R_NOP 0x7000f000
00051 
00052 #define PLT_EMPTY   0x10101010  /* RIE  -> RIE */
00053 
00054 /* The size in bytes of an entry in the procedure linkage table.  */
00055 
00056 #define PLT_ENTRY_SIZE 20
00057 #define PLT_HEADER_SIZE 20
00058 
00059 /* The first one entries in a procedure linkage table are reserved,
00060    and the initial contents are unimportant (we zero them out).
00061    Subsequent entries look like this. */
00062 
00063 #define PLT0_ENTRY_WORD0  0xd6c00000    /* seth r6, #high(.got+4)          */
00064 #define PLT0_ENTRY_WORD1  0x86e60000    /* or3  r6, r6, #low(.got)+4)      */
00065 #define PLT0_ENTRY_WORD2  0x24e626c6    /* ld   r4, @r6+    -> ld r6, @r6  */
00066 #define PLT0_ENTRY_WORD3  0x1fc6f000    /* jmp  r6          || pnop        */
00067 #define PLT0_ENTRY_WORD4  PLT_EMPTY     /* RIE             -> RIE          */
00068 
00069 #define PLT0_PIC_ENTRY_WORD0  0xa4cc0004 /* ld   r4, @(4,r12)              */
00070 #define PLT0_PIC_ENTRY_WORD1  0xa6cc0008 /* ld   r6, @(8,r12)              */
00071 #define PLT0_PIC_ENTRY_WORD2  0x1fc6f000 /* jmp  r6         || nop         */
00072 #define PLT0_PIC_ENTRY_WORD3  PLT_EMPTY  /* RIE             -> RIE         */
00073 #define PLT0_PIC_ENTRY_WORD4  PLT_EMPTY  /* RIE             -> RIE         */
00074 
00075 #define PLT_ENTRY_WORD0  0xe6000000 /* ld24 r6, .name_in_GOT                */
00076 #define PLT_ENTRY_WORD1  0x06acf000 /* add  r6, r12          || nop         */
00077 #define PLT_ENTRY_WORD0b 0xd6c00000 /* seth r6, #high(.name_in_GOT)         */
00078 #define PLT_ENTRY_WORD1b 0x86e60000 /* or3  r6, r6, #low(.name_in_GOT)      */
00079 #define PLT_ENTRY_WORD2  0x26c61fc6 /* ld  r6, @r6           -> jmp r6      */
00080 #define PLT_ENTRY_WORD3  0xe5000000 /* ld24 r5, $offset                     */
00081 #define PLT_ENTRY_WORD4  0xff000000 /* bra  .plt0.                          */
00082 
00083 
00084 /* Utility to actually perform an R_M32R_10_PCREL reloc.  */
00085 
00086 static bfd_reloc_status_type
00087 m32r_elf_do_10_pcrel_reloc (bfd *abfd,
00088                          reloc_howto_type *howto,
00089                          asection *input_section,
00090                          bfd_byte *data,
00091                          bfd_vma offset,
00092                          asection *symbol_section ATTRIBUTE_UNUSED,
00093                          bfd_vma symbol_value,
00094                          bfd_vma addend)
00095 {
00096   bfd_signed_vma relocation;
00097   unsigned long x;
00098   bfd_reloc_status_type status;
00099 
00100   /* Sanity check the address (offset in section).  */
00101   if (offset > bfd_get_section_limit (abfd, input_section))
00102     return bfd_reloc_outofrange;
00103 
00104   relocation = symbol_value + addend;
00105   /* Make it pc relative.  */
00106   relocation -=      (input_section->output_section->vma
00107                + input_section->output_offset);
00108   /* These jumps mask off the lower two bits of the current address
00109      before doing pcrel calculations.  */
00110   relocation -= (offset & -(bfd_vma) 4);
00111 
00112   if (relocation < -0x200 || relocation > 0x1ff)
00113     status = bfd_reloc_overflow;
00114   else
00115     status = bfd_reloc_ok;
00116 
00117   x = bfd_get_16 (abfd, data + offset);
00118   relocation >>= howto->rightshift;
00119   relocation <<= howto->bitpos;
00120   x = (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask);
00121   bfd_put_16 (abfd, (bfd_vma) x, data + offset);
00122 
00123   return status;
00124 }
00125 
00126 /* Handle the R_M32R_10_PCREL reloc.  */
00127 
00128 static bfd_reloc_status_type
00129 m32r_elf_10_pcrel_reloc (bfd * abfd,
00130                       arelent * reloc_entry,
00131                       asymbol * symbol,
00132                       void * data,
00133                       asection * input_section,
00134                       bfd * output_bfd,
00135                       char ** error_message ATTRIBUTE_UNUSED)
00136 {
00137   /* This part is from bfd_elf_generic_reloc.  */
00138   if (output_bfd != NULL
00139       && (symbol->flags & BSF_SECTION_SYM) == 0
00140       && (! reloc_entry->howto->partial_inplace
00141          || reloc_entry->addend == 0))
00142     {
00143       reloc_entry->address += input_section->output_offset;
00144       return bfd_reloc_ok;
00145     }
00146 
00147   if (output_bfd != NULL)
00148     /* FIXME: See bfd_perform_relocation.  Is this right?  */
00149     return bfd_reloc_continue;
00150 
00151   return m32r_elf_do_10_pcrel_reloc (abfd, reloc_entry->howto,
00152                                  input_section,
00153                                  data, reloc_entry->address,
00154                                  symbol->section,
00155                                  (symbol->value
00156                                   + symbol->section->output_section->vma
00157                                   + symbol->section->output_offset),
00158                                  reloc_entry->addend);
00159 }
00160 
00161 /* Do generic partial_inplace relocation.
00162    This is a local replacement for bfd_elf_generic_reloc.  */
00163 
00164 static bfd_reloc_status_type
00165 m32r_elf_generic_reloc (bfd *input_bfd,
00166                      arelent *reloc_entry,
00167                      asymbol *symbol,
00168                      void * data,
00169                      asection *input_section,
00170                      bfd *output_bfd,
00171                      char **error_message ATTRIBUTE_UNUSED)
00172 {
00173   bfd_reloc_status_type ret;
00174   bfd_vma relocation;
00175   bfd_byte *inplace_address;
00176 
00177   /* This part is from bfd_elf_generic_reloc.
00178      If we're relocating, and this an external symbol, we don't want
00179      to change anything.  */
00180   if (output_bfd != NULL
00181       && (symbol->flags & BSF_SECTION_SYM) == 0
00182       && reloc_entry->addend == 0)
00183     {
00184       reloc_entry->address += input_section->output_offset;
00185       return bfd_reloc_ok;
00186     }
00187 
00188   /* Now do the reloc in the usual way.
00189      ??? It would be nice to call bfd_elf_generic_reloc here,
00190      but we have partial_inplace set.  bfd_elf_generic_reloc will
00191      pass the handling back to bfd_install_relocation which will install
00192      a section relative addend which is wrong.  */
00193 
00194   /* Sanity check the address (offset in section).  */
00195   if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
00196     return bfd_reloc_outofrange;
00197 
00198   ret = bfd_reloc_ok;
00199   if (bfd_is_und_section (symbol->section)
00200       && output_bfd == NULL)
00201     ret = bfd_reloc_undefined;
00202 
00203   if (bfd_is_com_section (symbol->section)
00204       || output_bfd != NULL)
00205     relocation = 0;
00206   else
00207     relocation = symbol->value;
00208 
00209   /* Only do this for a final link.  */
00210   if (output_bfd == NULL)
00211     {
00212       relocation += symbol->section->output_section->vma;
00213       relocation += symbol->section->output_offset;
00214     }
00215 
00216   relocation += reloc_entry->addend;
00217   inplace_address = (bfd_byte *) data + reloc_entry->address;
00218 
00219 #define DOIT(x)                                  \
00220   x = ( (x & ~reloc_entry->howto->dst_mask) |           \
00221   (((x & reloc_entry->howto->src_mask) +  relocation) & \
00222   reloc_entry->howto->dst_mask))
00223 
00224   switch (reloc_entry->howto->size)
00225     {
00226     case 1:
00227       {
00228        short x = bfd_get_16 (input_bfd, inplace_address);
00229        DOIT (x);
00230        bfd_put_16 (input_bfd, (bfd_vma) x, inplace_address);
00231       }
00232       break;
00233     case 2:
00234       {
00235        unsigned long x = bfd_get_32 (input_bfd, inplace_address);
00236        DOIT (x);
00237        bfd_put_32 (input_bfd, (bfd_vma)x , inplace_address);
00238       }
00239       break;
00240     default:
00241       BFD_ASSERT (0);
00242     }
00243 
00244   if (output_bfd != NULL)
00245     reloc_entry->address += input_section->output_offset;
00246 
00247   return ret;
00248 }
00249 
00250 /* Handle the R_M32R_SDA16 reloc.
00251    This reloc is used to compute the address of objects in the small data area
00252    and to perform loads and stores from that area.
00253    The lower 16 bits are sign extended and added to the register specified
00254    in the instruction, which is assumed to point to _SDA_BASE_.  */
00255 
00256 static bfd_reloc_status_type
00257 m32r_elf_sda16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
00258                     arelent *reloc_entry,
00259                     asymbol *symbol,
00260                     void * data ATTRIBUTE_UNUSED,
00261                     asection *input_section,
00262                     bfd *output_bfd,
00263                     char **error_message ATTRIBUTE_UNUSED)
00264 {
00265   /* This part is from bfd_elf_generic_reloc.  */
00266   if (output_bfd != NULL
00267       && (symbol->flags & BSF_SECTION_SYM) == 0
00268       && (! reloc_entry->howto->partial_inplace
00269          || reloc_entry->addend == 0))
00270     {
00271       reloc_entry->address += input_section->output_offset;
00272       return bfd_reloc_ok;
00273     }
00274 
00275   if (output_bfd != NULL)
00276     /* FIXME: See bfd_perform_relocation.  Is this right?  */
00277     return bfd_reloc_continue;
00278 
00279   /* FIXME: not sure what to do here yet.  But then again, the linker
00280      may never call us.  */
00281   abort ();
00282 }
00283 
00284 
00285 /* Handle the R_M32R_HI16_[SU]LO relocs.
00286    HI16_SLO is for the add3 and load/store with displacement instructions.
00287    HI16_ULO is for the or3 instruction.
00288    For R_M32R_HI16_SLO, the lower 16 bits are sign extended when added to
00289    the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
00290    we must add one to the high 16 bytes (which will get subtracted off when
00291    the low 16 bits are added).
00292    These relocs have to be done in combination with an R_M32R_LO16 reloc
00293    because there is a carry from the LO16 to the HI16.  Here we just save
00294    the information we need; we do the actual relocation when we see the LO16.
00295    This code is copied from the elf32-mips.c.  We also support an arbitrary
00296    number of HI16 relocs to be associated with a single LO16 reloc.  The
00297    assembler sorts the relocs to ensure each HI16 immediately precedes its
00298    LO16.  However if there are multiple copies, the assembler may not find
00299    the real LO16 so it picks the first one it finds.  */
00300 
00301 struct m32r_hi16
00302 {
00303   struct m32r_hi16 *next;
00304   bfd_byte *addr;
00305   bfd_vma addend;
00306 };
00307 
00308 /* FIXME: This should not be a static variable.  */
00309 
00310 static struct m32r_hi16 *m32r_hi16_list;
00311 
00312 static bfd_reloc_status_type
00313 m32r_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
00314                    arelent *reloc_entry,
00315                    asymbol *symbol,
00316                    void * data,
00317                    asection *input_section,
00318                    bfd *output_bfd,
00319                    char **error_message ATTRIBUTE_UNUSED)
00320 {
00321   bfd_reloc_status_type ret;
00322   bfd_vma relocation;
00323   struct m32r_hi16 *n;
00324 
00325   /* This part is from bfd_elf_generic_reloc.
00326      If we're relocating, and this an external symbol, we don't want
00327      to change anything.  */
00328   if (output_bfd != NULL
00329       && (symbol->flags & BSF_SECTION_SYM) == 0
00330       && reloc_entry->addend == 0)
00331     {
00332       reloc_entry->address += input_section->output_offset;
00333       return bfd_reloc_ok;
00334     }
00335 
00336   /* Sanity check the address (offset in section).  */
00337   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
00338     return bfd_reloc_outofrange;
00339 
00340   ret = bfd_reloc_ok;
00341   if (bfd_is_und_section (symbol->section)
00342       && output_bfd == NULL)
00343     ret = bfd_reloc_undefined;
00344 
00345   if (bfd_is_com_section (symbol->section))
00346     relocation = 0;
00347   else
00348     relocation = symbol->value;
00349 
00350   relocation += symbol->section->output_section->vma;
00351   relocation += symbol->section->output_offset;
00352   relocation += reloc_entry->addend;
00353 
00354   /* Save the information, and let LO16 do the actual relocation.  */
00355   n = bfd_malloc ((bfd_size_type) sizeof *n);
00356   if (n == NULL)
00357     return bfd_reloc_outofrange;
00358   n->addr = (bfd_byte *) data + reloc_entry->address;
00359   n->addend = relocation;
00360   n->next = m32r_hi16_list;
00361   m32r_hi16_list = n;
00362 
00363   if (output_bfd != NULL)
00364     reloc_entry->address += input_section->output_offset;
00365 
00366   return ret;
00367 }
00368 
00369 /* Handle an M32R ELF HI16 reloc.  */
00370 
00371 static void
00372 m32r_elf_relocate_hi16 (bfd *input_bfd,
00373                      int type,
00374                      Elf_Internal_Rela *relhi,
00375                      Elf_Internal_Rela *rello,
00376                      bfd_byte *contents,
00377                      bfd_vma addend)
00378 {
00379   unsigned long insn;
00380   bfd_vma addlo;
00381 
00382   insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
00383 
00384   addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
00385   if (type == R_M32R_HI16_SLO)
00386     addlo = ((addlo & 0xffff) ^ 0x8000) - 0x8000;
00387   else
00388     addlo &= 0xffff;
00389 
00390   addend += ((insn & 0xffff) << 16) + addlo;
00391 
00392   /* Reaccount for sign extension of low part.  */
00393   if (type == R_M32R_HI16_SLO
00394       && (addend & 0x8000) != 0)
00395     addend += 0x10000;
00396 
00397   bfd_put_32 (input_bfd,
00398              (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
00399              contents + relhi->r_offset);
00400 }
00401 
00402 /* Do an R_M32R_LO16 relocation.  This is a straightforward 16 bit
00403    inplace relocation; this function exists in order to do the
00404    R_M32R_HI16_[SU]LO relocation described above.  */
00405 
00406 static bfd_reloc_status_type
00407 m32r_elf_lo16_reloc (bfd *input_bfd,
00408                    arelent *reloc_entry,
00409                    asymbol *symbol,
00410                    void * data,
00411                    asection *input_section,
00412                    bfd *output_bfd,
00413                    char **error_message)
00414 {
00415   /* This part is from bfd_elf_generic_reloc.
00416      If we're relocating, and this an external symbol, we don't want
00417      to change anything.  */
00418   if (output_bfd != NULL
00419       && (symbol->flags & BSF_SECTION_SYM) == 0
00420       && reloc_entry->addend == 0)
00421     {
00422       reloc_entry->address += input_section->output_offset;
00423       return bfd_reloc_ok;
00424     }
00425 
00426   if (m32r_hi16_list != NULL)
00427     {
00428       struct m32r_hi16 *l;
00429 
00430       l = m32r_hi16_list;
00431       while (l != NULL)
00432        {
00433          unsigned long insn;
00434          unsigned long val;
00435          unsigned long vallo;
00436          struct m32r_hi16 *next;
00437 
00438          /* Do the HI16 relocation.  Note that we actually don't need
00439             to know anything about the LO16 itself, except where to
00440             find the low 16 bits of the addend needed by the LO16.  */
00441          insn = bfd_get_32 (input_bfd, l->addr);
00442          vallo = ((bfd_get_32 (input_bfd, (bfd_byte *) data + reloc_entry->address)
00443                  & 0xffff) ^ 0x8000) - 0x8000;
00444          val = ((insn & 0xffff) << 16) + vallo;
00445          val += l->addend;
00446 
00447          /* Reaccount for sign extension of low part.  */
00448          if ((val & 0x8000) != 0)
00449            val += 0x10000;
00450 
00451          insn = (insn &~ (bfd_vma) 0xffff) | ((val >> 16) & 0xffff);
00452          bfd_put_32 (input_bfd, (bfd_vma) insn, l->addr);
00453 
00454          next = l->next;
00455          free (l);
00456          l = next;
00457        }
00458 
00459       m32r_hi16_list = NULL;
00460     }
00461 
00462   /* Now do the LO16 reloc in the usual way.
00463      ??? It would be nice to call bfd_elf_generic_reloc here,
00464      but we have partial_inplace set.  bfd_elf_generic_reloc will
00465      pass the handling back to bfd_install_relocation which will install
00466      a section relative addend which is wrong.  */
00467   return m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
00468                             input_section, output_bfd, error_message);
00469 }
00470 
00471 
00472 static reloc_howto_type m32r_elf_howto_table[] =
00473 {
00474   /* This reloc does nothing.  */
00475   HOWTO (R_M32R_NONE,              /* type */
00476         0,                  /* rightshift */
00477         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00478         32,                 /* bitsize */
00479         FALSE,                     /* pc_relative */
00480         0,                  /* bitpos */
00481         complain_overflow_bitfield, /* complain_on_overflow */
00482         bfd_elf_generic_reloc,     /* special_function */
00483         "R_M32R_NONE",             /* name */
00484         FALSE,                     /* partial_inplace */
00485         0,                  /* src_mask */
00486         0,                  /* dst_mask */
00487         FALSE),             /* pcrel_offset */
00488 
00489   /* A 16 bit absolute relocation.  */
00490   HOWTO (R_M32R_16,         /* type */
00491         0,                  /* rightshift */
00492         1,                  /* size (0 = byte, 1 = short, 2 = long) */
00493         16,                 /* bitsize */
00494         FALSE,                     /* pc_relative */
00495         0,                  /* bitpos */
00496         complain_overflow_bitfield, /* complain_on_overflow */
00497         m32r_elf_generic_reloc,/* special_function */
00498         "R_M32R_16",        /* name */
00499         TRUE,               /* partial_inplace */
00500         0xffff,             /* src_mask */
00501         0xffff,             /* dst_mask */
00502         FALSE),             /* pcrel_offset */
00503 
00504   /* A 32 bit absolute relocation.  */
00505   HOWTO (R_M32R_32,         /* type */
00506         0,                  /* rightshift */
00507         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00508         32,                 /* bitsize */
00509         FALSE,                     /* pc_relative */
00510         0,                  /* bitpos */
00511         complain_overflow_bitfield, /* complain_on_overflow */
00512         m32r_elf_generic_reloc,/* special_function */
00513         "R_M32R_32",        /* name */
00514         TRUE,               /* partial_inplace */
00515         0xffffffff,         /* src_mask */
00516         0xffffffff,         /* dst_mask */
00517         FALSE),             /* pcrel_offset */
00518 
00519   /* A 24 bit address.  */
00520   HOWTO (R_M32R_24,         /* type */
00521         0,                  /* rightshift */
00522         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00523         24,                 /* bitsize */
00524         FALSE,                     /* pc_relative */
00525         0,                  /* bitpos */
00526         complain_overflow_unsigned, /* complain_on_overflow */
00527         m32r_elf_generic_reloc,/* special_function */
00528         "R_M32R_24",        /* name */
00529         TRUE,               /* partial_inplace */
00530         0xffffff,           /* src_mask */
00531         0xffffff,           /* dst_mask */
00532         FALSE),             /* pcrel_offset */
00533 
00534   /* An PC Relative 10-bit relocation, shifted by 2.
00535      This reloc is complicated because relocations are relative to pc & -4.
00536      i.e. branches in the right insn slot use the address of the left insn
00537      slot for pc.  */
00538   /* ??? It's not clear whether this should have partial_inplace set or not.
00539      Branch relaxing in the assembler can store the addend in the insn,
00540      and if bfd_install_relocation gets called the addend may get added
00541      again.  */
00542   HOWTO (R_M32R_10_PCREL,   /* type */
00543         2,                    /* rightshift */
00544         1,                    /* size (0 = byte, 1 = short, 2 = long) */
00545         10,                   /* bitsize */
00546         TRUE,                 /* pc_relative */
00547         0,                    /* bitpos */
00548         complain_overflow_signed, /* complain_on_overflow */
00549         m32r_elf_10_pcrel_reloc, /* special_function */
00550         "R_M32R_10_PCREL",  /* name */
00551         FALSE,                       /* partial_inplace */
00552         0xff,                /* src_mask */
00553         0xff,               /* dst_mask */
00554         TRUE),                     /* pcrel_offset */
00555 
00556   /* A relative 18 bit relocation, right shifted by 2.  */
00557   HOWTO (R_M32R_18_PCREL,   /* type */
00558         2,                  /* rightshift */
00559         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00560         16,                 /* bitsize */
00561         TRUE,               /* pc_relative */
00562         0,                  /* bitpos */
00563         complain_overflow_signed, /* complain_on_overflow */
00564         bfd_elf_generic_reloc,     /* special_function */
00565         "R_M32R_18_PCREL",  /* name */
00566         FALSE,                     /* partial_inplace */
00567         0xffff,             /* src_mask */
00568         0xffff,             /* dst_mask */
00569         TRUE),                     /* pcrel_offset */
00570 
00571   /* A relative 26 bit relocation, right shifted by 2.  */
00572   /* ??? It's not clear whether this should have partial_inplace set or not.
00573      Branch relaxing in the assembler can store the addend in the insn,
00574      and if bfd_install_relocation gets called the addend may get added
00575      again.  */
00576   HOWTO (R_M32R_26_PCREL,   /* type */
00577         2,                  /* rightshift */
00578         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00579         26,                 /* bitsize */
00580         TRUE,               /* pc_relative */
00581         0,                  /* bitpos */
00582         complain_overflow_signed, /* complain_on_overflow */
00583         bfd_elf_generic_reloc,     /* special_function */
00584         "R_M32R_26_PCREL",  /* name */
00585         FALSE,                     /* partial_inplace */
00586         0xffffff,           /* src_mask */
00587         0xffffff,           /* dst_mask */
00588         TRUE),                     /* pcrel_offset */
00589 
00590   /* High 16 bits of address when lower 16 is or'd in.  */
00591   HOWTO (R_M32R_HI16_ULO,   /* type */
00592         16,                 /* rightshift */
00593         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00594         16,                 /* bitsize */
00595         FALSE,                     /* pc_relative */
00596         0,                  /* bitpos */
00597         complain_overflow_dont, /* complain_on_overflow */
00598         m32r_elf_hi16_reloc,       /* special_function */
00599         "R_M32R_HI16_ULO",  /* name */
00600         TRUE,               /* partial_inplace */
00601         0x0000ffff,         /* src_mask */
00602         0x0000ffff,         /* dst_mask */
00603         FALSE),             /* pcrel_offset */
00604 
00605   /* High 16 bits of address when lower 16 is added in.  */
00606   HOWTO (R_M32R_HI16_SLO,   /* type */
00607         16,                 /* rightshift */
00608         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00609         16,                 /* bitsize */
00610         FALSE,                     /* pc_relative */
00611         0,                  /* bitpos */
00612         complain_overflow_dont, /* complain_on_overflow */
00613         m32r_elf_hi16_reloc,       /* special_function */
00614         "R_M32R_HI16_SLO",  /* name */
00615         TRUE,               /* partial_inplace */
00616         0x0000ffff,         /* src_mask */
00617         0x0000ffff,         /* dst_mask */
00618         FALSE),             /* pcrel_offset */
00619 
00620   /* Lower 16 bits of address.  */
00621   HOWTO (R_M32R_LO16,              /* type */
00622         0,                  /* rightshift */
00623         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00624         16,                 /* bitsize */
00625         FALSE,                     /* pc_relative */
00626         0,                  /* bitpos */
00627         complain_overflow_dont, /* complain_on_overflow */
00628         m32r_elf_lo16_reloc,       /* special_function */
00629         "R_M32R_LO16",             /* name */
00630         TRUE,               /* partial_inplace */
00631         0x0000ffff,         /* src_mask */
00632         0x0000ffff,         /* dst_mask */
00633         FALSE),             /* pcrel_offset */
00634 
00635   /* Small data area 16 bits offset.  */
00636   HOWTO (R_M32R_SDA16,             /* type */
00637         0,                  /* rightshift */
00638         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00639         16,                 /* bitsize */
00640         FALSE,                     /* pc_relative */
00641         0,                  /* bitpos */
00642         complain_overflow_signed, /* complain_on_overflow */
00643         m32r_elf_sda16_reloc,      /* special_function */
00644         "R_M32R_SDA16",     /* name */
00645         TRUE,               /* partial_inplace */  /* FIXME: correct? */
00646         0x0000ffff,         /* src_mask */
00647         0x0000ffff,         /* dst_mask */
00648         FALSE),             /* pcrel_offset */
00649 
00650   /* GNU extension to record C++ vtable hierarchy.  */
00651   HOWTO (R_M32R_GNU_VTINHERIT, /* type */
00652          0,                     /* rightshift */
00653          2,                     /* size (0 = byte, 1 = short, 2 = long) */
00654          0,                     /* bitsize */
00655          FALSE,                 /* pc_relative */
00656          0,                     /* bitpos */
00657          complain_overflow_dont, /* complain_on_overflow */
00658          NULL,                  /* special_function */
00659          "R_M32R_GNU_VTINHERIT", /* name */
00660          FALSE,                 /* partial_inplace */
00661          0,                     /* src_mask */
00662          0,                     /* dst_mask */
00663          FALSE),                /* pcrel_offset */
00664 
00665   /* GNU extension to record C++ vtable member usage.  */
00666   HOWTO (R_M32R_GNU_VTENTRY,     /* type */
00667          0,                     /* rightshift */
00668          2,                     /* size (0 = byte, 1 = short, 2 = long) */
00669          0,                     /* bitsize */
00670          FALSE,                 /* pc_relative */
00671          0,                     /* bitpos */
00672          complain_overflow_dont, /* complain_on_overflow */
00673          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
00674          "R_M32R_GNU_VTENTRY",   /* name */
00675          FALSE,                 /* partial_inplace */
00676          0,                     /* src_mask */
00677          0,                     /* dst_mask */
00678          FALSE),                /* pcrel_offset */
00679 
00680   EMPTY_HOWTO (13),
00681   EMPTY_HOWTO (14),
00682   EMPTY_HOWTO (15),
00683   EMPTY_HOWTO (16),
00684   EMPTY_HOWTO (17),
00685   EMPTY_HOWTO (18),
00686   EMPTY_HOWTO (19),
00687   EMPTY_HOWTO (20),
00688   EMPTY_HOWTO (21),
00689   EMPTY_HOWTO (22),
00690   EMPTY_HOWTO (23),
00691   EMPTY_HOWTO (24),
00692   EMPTY_HOWTO (25),
00693   EMPTY_HOWTO (26),
00694   EMPTY_HOWTO (27),
00695   EMPTY_HOWTO (28),
00696   EMPTY_HOWTO (29),
00697   EMPTY_HOWTO (30),
00698   EMPTY_HOWTO (31),
00699   EMPTY_HOWTO (32),
00700 
00701   /* A 16 bit absolute relocation.  */
00702   HOWTO (R_M32R_16_RELA,    /* type */
00703         0,                  /* rightshift */
00704         1,                  /* size (0 = byte, 1 = short, 2 = long) */
00705         16,                 /* bitsize */
00706         FALSE,                     /* pc_relative */
00707         0,                  /* bitpos */
00708         complain_overflow_bitfield, /* complain_on_overflow */
00709         bfd_elf_generic_reloc,     /* special_function */
00710         "R_M32R_16_RELA",   /* name */
00711         FALSE,                     /* partial_inplace */
00712         0xffff,             /* src_mask */
00713         0xffff,             /* dst_mask */
00714         FALSE),             /* pcrel_offset */
00715 
00716   /* A 32 bit absolute relocation.  */
00717   HOWTO (R_M32R_32_RELA,    /* type */
00718         0,                  /* rightshift */
00719         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00720         32,                 /* bitsize */
00721         FALSE,                     /* pc_relative */
00722         0,                  /* bitpos */
00723         complain_overflow_bitfield, /* complain_on_overflow */
00724         bfd_elf_generic_reloc,/* special_function */
00725         "R_M32R_32_RELA",          /* name */
00726         FALSE,                     /* partial_inplace */
00727         0xffffffff,         /* src_mask */
00728         0xffffffff,         /* dst_mask */
00729         FALSE),             /* pcrel_offset */
00730 
00731   /* A 24 bit address.  */
00732   HOWTO (R_M32R_24_RELA,    /* type */
00733         0,                  /* rightshift */
00734         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00735         24,                 /* bitsize */
00736         FALSE,                     /* pc_relative */
00737         0,                  /* bitpos */
00738         complain_overflow_unsigned, /* complain_on_overflow */
00739         bfd_elf_generic_reloc,/* special_function */
00740         "R_M32R_24_RELA",   /* name */
00741         FALSE,                     /* partial_inplace */
00742         0xffffff,           /* src_mask */
00743         0xffffff,           /* dst_mask */
00744         FALSE),             /* pcrel_offset */
00745 
00746   HOWTO (R_M32R_10_PCREL_RELA,     /* type */
00747         2,                    /* rightshift */
00748         1,                    /* size (0 = byte, 1 = short, 2 = long) */
00749         10,                   /* bitsize */
00750         TRUE,                 /* pc_relative */
00751         0,                    /* bitpos */
00752         complain_overflow_signed, /* complain_on_overflow */
00753         m32r_elf_10_pcrel_reloc, /* special_function */
00754         "R_M32R_10_PCREL_RELA",/* name */
00755         FALSE,                       /* partial_inplace */
00756         0xff,                /* src_mask */
00757         0xff,               /* dst_mask */
00758         TRUE),                     /* pcrel_offset */
00759 
00760   /* A relative 18 bit relocation, right shifted by 2.  */
00761   HOWTO (R_M32R_18_PCREL_RELA,     /* type */
00762         2,                  /* rightshift */
00763         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00764         16,                 /* bitsize */
00765         TRUE,               /* pc_relative */
00766         0,                  /* bitpos */
00767         complain_overflow_signed, /* complain_on_overflow */
00768         bfd_elf_generic_reloc,     /* special_function */
00769         "R_M32R_18_PCREL_RELA",/* name */
00770         FALSE,                     /* partial_inplace */
00771         0xffff,             /* src_mask */
00772         0xffff,             /* dst_mask */
00773         TRUE),                     /* pcrel_offset */
00774 
00775   /* A relative 26 bit relocation, right shifted by 2.  */
00776   HOWTO (R_M32R_26_PCREL_RELA,     /* type */
00777         2,                  /* rightshift */
00778         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00779         26,                 /* bitsize */
00780         TRUE,               /* pc_relative */
00781         0,                  /* bitpos */
00782         complain_overflow_signed, /* complain_on_overflow */
00783         bfd_elf_generic_reloc,     /* special_function */
00784         "R_M32R_26_PCREL_RELA",/* name */
00785         FALSE,                     /* partial_inplace */
00786         0xffffff,           /* src_mask */
00787         0xffffff,           /* dst_mask */
00788         TRUE),                     /* pcrel_offset */
00789 
00790   /* High 16 bits of address when lower 16 is or'd in.  */
00791   HOWTO (R_M32R_HI16_ULO_RELA,     /* type */
00792         16,                 /* rightshift */
00793         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00794         16,                 /* bitsize */
00795         FALSE,                     /* pc_relative */
00796         0,                  /* bitpos */
00797         complain_overflow_dont, /* complain_on_overflow */
00798         bfd_elf_generic_reloc,     /* special_function */
00799         "R_M32R_HI16_ULO_RELA",/* name */
00800         FALSE,                     /* partial_inplace */
00801         0x0000ffff,         /* src_mask */
00802         0x0000ffff,         /* dst_mask */
00803         FALSE),             /* pcrel_offset */
00804 
00805   /* High 16 bits of address when lower 16 is added in.  */
00806   HOWTO (R_M32R_HI16_SLO_RELA,     /* type */
00807         16,                 /* rightshift */
00808         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00809         16,                 /* bitsize */
00810         FALSE,                     /* pc_relative */
00811         0,                  /* bitpos */
00812         complain_overflow_dont, /* complain_on_overflow */
00813         bfd_elf_generic_reloc,     /* special_function */
00814         "R_M32R_HI16_SLO_RELA",/* name */
00815         FALSE,                     /* partial_inplace */
00816         0x0000ffff,         /* src_mask */
00817         0x0000ffff,         /* dst_mask */
00818         FALSE),             /* pcrel_offset */
00819 
00820   /* Lower 16 bits of address.  */
00821   HOWTO (R_M32R_LO16_RELA,  /* type */
00822         0,                  /* rightshift */
00823         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00824         16,                 /* bitsize */
00825         FALSE,                     /* pc_relative */
00826         0,                  /* bitpos */
00827         complain_overflow_dont, /* complain_on_overflow */
00828         bfd_elf_generic_reloc,     /* special_function */
00829         "R_M32R_LO16_RELA", /* name */
00830         FALSE,                     /* partial_inplace */
00831         0x0000ffff,         /* src_mask */
00832         0x0000ffff,         /* dst_mask */
00833         FALSE),             /* pcrel_offset */
00834 
00835   /* Small data area 16 bits offset.  */
00836   HOWTO (R_M32R_SDA16_RELA, /* type */
00837         0,                  /* rightshift */
00838         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00839         16,                 /* bitsize */
00840         FALSE,                     /* pc_relative */
00841         0,                  /* bitpos */
00842         complain_overflow_signed, /* complain_on_overflow */
00843         bfd_elf_generic_reloc,     /* special_function */
00844         "R_M32R_SDA16_RELA",       /* name */
00845         TRUE,               /* partial_inplace */  /* FIXME: correct? */
00846         0x0000ffff,         /* src_mask */
00847         0x0000ffff,         /* dst_mask */
00848         FALSE),             /* pcrel_offset */
00849 
00850   /* GNU extension to record C++ vtable hierarchy.  */
00851   HOWTO (R_M32R_RELA_GNU_VTINHERIT, /* type */
00852          0,                     /* rightshift */
00853          2,                     /* size (0 = byte, 1 = short, 2 = long) */
00854          0,                     /* bitsize */
00855          FALSE,                 /* pc_relative */
00856          0,                     /* bitpos */
00857          complain_overflow_dont, /* complain_on_overflow */
00858          NULL,                  /* special_function */
00859          "R_M32R_RELA_GNU_VTINHERIT", /* name */
00860          FALSE,                 /* partial_inplace */
00861          0,                     /* src_mask */
00862          0,                     /* dst_mask */
00863          FALSE),                /* pcrel_offset */
00864 
00865   /* GNU extension to record C++ vtable member usage.  */
00866   HOWTO (R_M32R_RELA_GNU_VTENTRY,     /* type */
00867          0,                     /* rightshift */
00868          2,                     /* size (0 = byte, 1 = short, 2 = long) */
00869          0,                     /* bitsize */
00870          FALSE,                 /* pc_relative */
00871          0,                     /* bitpos */
00872          complain_overflow_dont, /* complain_on_overflow */
00873          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
00874          "R_M32R_RELA_GNU_VTENTRY",   /* name */
00875          FALSE,                 /* partial_inplace */
00876          0,                     /* src_mask */
00877          0,                     /* dst_mask */
00878          FALSE),                /* pcrel_offset */
00879 
00880   /* A 32 bit PC relative relocation.  */
00881   HOWTO (R_M32R_REL32,             /* type */
00882         0,                  /* rightshift */
00883         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00884         32,                 /* bitsize */
00885         TRUE,               /* pc_relative */
00886         0,                  /* bitpos */
00887         complain_overflow_bitfield, /* complain_on_overflow */
00888         bfd_elf_generic_reloc,/* special_function */
00889         "R_M32R_REL32",            /* name */
00890         FALSE,                     /* partial_inplace */
00891         0xffffffff,         /* src_mask */
00892         0xffffffff,         /* dst_mask */
00893         TRUE),                     /* pcrel_offset */
00894 
00895   EMPTY_HOWTO (46),
00896   EMPTY_HOWTO (47),
00897 
00898   /* Like R_M32R_24, but referring to the GOT table entry for
00899      the symbol.  */
00900   HOWTO (R_M32R_GOT24,             /* type */
00901         0,                  /* rightshift */
00902         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00903         24,                 /* bitsize */
00904         FALSE,                     /* pc_relative */
00905         0,                  /* bitpos */
00906         complain_overflow_unsigned, /* complain_on_overflow */
00907         bfd_elf_generic_reloc, /* special_function */
00908         "R_M32R_GOT24",     /* name */
00909         FALSE,                     /* partial_inplace */
00910         0xffffff,           /* src_mask */
00911         0xffffff,           /* dst_mask */
00912         FALSE),             /* pcrel_offset */
00913 
00914   /* Like R_M32R_PCREL, but referring to the procedure linkage table
00915      entry for the symbol.  */
00916   HOWTO (R_M32R_26_PLTREL,  /* type */
00917         2,                  /* rightshift */
00918         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00919         24,                 /* bitsize */
00920         TRUE,               /* pc_relative */
00921         0,                  /* bitpos */
00922         complain_overflow_signed, /* complain_on_overflow */
00923         bfd_elf_generic_reloc,     /* special_function */
00924         "R_M32R_26_PLTREL", /* name */
00925         FALSE,                     /* partial_inplace */
00926         0xffffff,           /* src_mask */
00927         0xffffff,           /* dst_mask */
00928         TRUE),                     /* pcrel_offset */
00929 
00930   /* This is used only by the dynamic linker.  The symbol should exist
00931      both in the object being run and in some shared library.  The
00932      dynamic linker copies the data addressed by the symbol from the
00933      shared library into the object, because the object being
00934      run has to have the data at some particular address.  */
00935   HOWTO (R_M32R_COPY,              /* type */
00936         0,                  /* rightshift */
00937         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00938         32,                 /* bitsize */
00939         FALSE,                     /* pc_relative */
00940         0,                  /* bitpos */
00941         complain_overflow_bitfield, /* complain_on_overflow */
00942         bfd_elf_generic_reloc, /* special_function */
00943         "R_M32R_COPY",             /* name */
00944         FALSE,                     /* partial_inplace */
00945         0xffffffff,         /* src_mask */
00946         0xffffffff,         /* dst_mask */
00947         FALSE),             /* pcrel_offset */
00948 
00949   /* Like R_M32R_24, but used when setting global offset table
00950      entries.  */
00951   HOWTO (R_M32R_GLOB_DAT,   /* type */
00952         0,                  /* rightshift */
00953         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00954         32,                 /* bitsize */
00955         FALSE,                     /* pc_relative */
00956         0,                  /* bitpos */
00957         complain_overflow_bitfield, /* complain_on_overflow */
00958         bfd_elf_generic_reloc, /* special_function */
00959         "R_M32R_GLOB_DAT",  /* name */
00960         FALSE,                     /* partial_inplace */
00961         0xffffffff,         /* src_mask */
00962         0xffffffff,         /* dst_mask */
00963         FALSE),             /* pcrel_offset */
00964 
00965   /* Marks a procedure linkage table entry for a symbol.  */
00966   HOWTO (R_M32R_JMP_SLOT,   /* type */
00967         0,                  /* rightshift */
00968         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00969         32,                 /* bitsize */
00970         FALSE,                     /* pc_relative */
00971         0,                  /* bitpos */
00972         complain_overflow_bitfield, /* complain_on_overflow */
00973         bfd_elf_generic_reloc, /* special_function */
00974         "R_M32R_JMP_SLOT",  /* name */
00975         FALSE,                     /* partial_inplace */
00976         0xffffffff,         /* src_mask */
00977         0xffffffff,         /* dst_mask */
00978         FALSE),             /* pcrel_offset */
00979 
00980   /* Used only by the dynamic linker.  When the object is run, this
00981      longword is set to the load address of the object, plus the
00982      addend.  */
00983   HOWTO (R_M32R_RELATIVE,   /* type */
00984         0,                  /* rightshift */
00985         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00986         32,                 /* bitsize */
00987         FALSE,                     /* pc_relative */
00988         0,                  /* bitpos */
00989         complain_overflow_bitfield, /* complain_on_overflow */
00990         bfd_elf_generic_reloc, /* special_function */
00991         "R_M32R_RELATIVE",  /* name */
00992         FALSE,                     /* partial_inplace */
00993         0xffffffff,         /* src_mask */
00994         0xffffffff,         /* dst_mask */
00995         FALSE),             /* pcrel_offset */
00996 
00997   HOWTO (R_M32R_GOTOFF,            /* type */
00998         0,                  /* rightshift */
00999         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01000         24,                 /* bitsize */
01001         FALSE,                     /* pc_relative */
01002         0,                  /* bitpos */
01003         complain_overflow_bitfield, /* complain_on_overflow */
01004         bfd_elf_generic_reloc, /* special_function */
01005         "R_M32R_GOTOFF",    /* name */
01006         FALSE,                     /* partial_inplace */
01007         0xffffff,           /* src_mask */
01008         0xffffff,           /* dst_mask */
01009         FALSE),             /* pcrel_offset */
01010 
01011   /* An PC Relative 24-bit relocation used when setting PIC offset
01012      table register. */
01013   HOWTO (R_M32R_GOTPC24,    /* type */
01014         0,                  /* rightshift */
01015         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01016         24,                 /* bitsize */
01017         TRUE,               /* pc_relative */
01018         0,                  /* bitpos */
01019         complain_overflow_unsigned, /* complain_on_overflow */
01020         bfd_elf_generic_reloc, /* special_function */
01021         "R_M32R_GOTPC24",   /* name */
01022         FALSE,                     /* partial_inplace */
01023         0xffffff,           /* src_mask */
01024         0xffffff,           /* dst_mask */
01025         TRUE),                     /* pcrel_offset */
01026 
01027   /* Like R_M32R_HI16_ULO, but referring to the GOT table entry for
01028      the symbol.  */
01029   HOWTO (R_M32R_GOT16_HI_ULO,      /* type */
01030         16,                 /* rightshift */
01031         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01032         16,                 /* bitsize */
01033         FALSE,                     /* pc_relative */
01034         0,                  /* bitpos */
01035         complain_overflow_dont, /* complain_on_overflow */
01036         bfd_elf_generic_reloc,     /* special_function */
01037         "R_M32R_GOT16_HI_ULO",     /* name */
01038         FALSE,                     /* partial_inplace */
01039         0x0000ffff,         /* src_mask */
01040         0x0000ffff,         /* dst_mask */
01041         FALSE),             /* pcrel_offset */
01042 
01043   /* Like R_M32R_HI16_SLO, but referring to the GOT table entry for
01044      the symbol.  */
01045   HOWTO (R_M32R_GOT16_HI_SLO,      /* type */
01046         16,                 /* rightshift */
01047         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01048         16,                 /* bitsize */
01049         FALSE,                     /* pc_relative */
01050         0,                  /* bitpos */
01051         complain_overflow_dont, /* complain_on_overflow */
01052         bfd_elf_generic_reloc,     /* special_function */
01053         "R_M32R_GOT16_HI_SLO",     /* name */
01054         FALSE,                     /* partial_inplace */
01055         0x0000ffff,         /* src_mask */
01056         0x0000ffff,         /* dst_mask */
01057         FALSE),             /* pcrel_offset */
01058 
01059   /* Like R_M32R_LO16, but referring to the GOT table entry for
01060      the symbol.  */
01061   HOWTO (R_M32R_GOT16_LO,   /* type */
01062         0,                  /* rightshift */
01063         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01064         16,                 /* bitsize */
01065         FALSE,                     /* pc_relative */
01066         0,                  /* bitpos */
01067         complain_overflow_dont, /* complain_on_overflow */
01068         bfd_elf_generic_reloc,     /* special_function */
01069         "R_M32R_GOT16_LO",  /* name */
01070         FALSE,                     /* partial_inplace */
01071         0x0000ffff,         /* src_mask */
01072         0x0000ffff,         /* dst_mask */
01073         FALSE),             /* pcrel_offset */
01074 
01075   /* An PC Relative relocation used when setting PIC offset table register.
01076      Like R_M32R_HI16_ULO, but referring to the GOT table entry for
01077      the symbol.  */
01078   HOWTO (R_M32R_GOTPC_HI_ULO,      /* type */
01079         16,                 /* rightshift */
01080         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01081         16,                 /* bitsize */
01082         FALSE,                     /* pc_relative */
01083         0,                  /* bitpos */
01084         complain_overflow_dont, /* complain_on_overflow */
01085         bfd_elf_generic_reloc,     /* special_function */
01086         "R_M32R_GOTPC_HI_ULO",     /* name */
01087         FALSE,                     /* partial_inplace */
01088         0x0000ffff,         /* src_mask */
01089         0x0000ffff,         /* dst_mask */
01090         TRUE),                     /* pcrel_offset */
01091 
01092   /* An PC Relative relocation used when setting PIC offset table register.
01093      Like R_M32R_HI16_SLO, but referring to the GOT table entry for
01094      the symbol.  */
01095   HOWTO (R_M32R_GOTPC_HI_SLO,      /* type */
01096         16,                 /* rightshift */
01097         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01098         16,                 /* bitsize */
01099         FALSE,                     /* pc_relative */
01100         0,                  /* bitpos */
01101         complain_overflow_dont, /* complain_on_overflow */
01102         bfd_elf_generic_reloc,     /* special_function */
01103         "R_M32R_GOTPC_HI_SLO",     /* name */
01104         FALSE,                     /* partial_inplace */
01105         0x0000ffff,         /* src_mask */
01106         0x0000ffff,         /* dst_mask */
01107         TRUE),                     /* pcrel_offset */
01108 
01109   /* An PC Relative relocation used when setting PIC offset table register.
01110      Like R_M32R_LO16, but referring to the GOT table entry for
01111      the symbol.  */
01112   HOWTO (R_M32R_GOTPC_LO,   /* type */
01113         0,                  /* rightshift */
01114         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01115         16,                 /* bitsize */
01116         FALSE,                     /* pc_relative */
01117         0,                  /* bitpos */
01118         complain_overflow_dont, /* complain_on_overflow */
01119         bfd_elf_generic_reloc,     /* special_function */
01120         "R_M32R_GOTPC_LO",  /* name */
01121         FALSE,                     /* partial_inplace */
01122         0x0000ffff,         /* src_mask */
01123         0x0000ffff,         /* dst_mask */
01124         TRUE),                     /* pcrel_offset */
01125 
01126   HOWTO (R_M32R_GOTOFF_HI_ULO,     /* type */
01127         16,                 /* rightshift */
01128         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01129         16,                 /* bitsize */
01130         FALSE,                     /* pc_relative */
01131         0,                  /* bitpos */
01132         complain_overflow_dont, /* complain_on_overflow */
01133         bfd_elf_generic_reloc,     /* special_function */
01134         "R_M32R_GOTOFF_HI_ULO",/* name */
01135         FALSE,                     /* partial_inplace */
01136         0x0000ffff,         /* src_mask */
01137         0x0000ffff,         /* dst_mask */
01138         FALSE),             /* pcrel_offset */
01139 
01140   HOWTO (R_M32R_GOTOFF_HI_SLO,     /* type */
01141         16,                 /* rightshift */
01142         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01143         16,                 /* bitsize */
01144         FALSE,                     /* pc_relative */
01145         0,                  /* bitpos */
01146         complain_overflow_dont, /* complain_on_overflow */
01147         bfd_elf_generic_reloc,     /* special_function */
01148         "R_M32R_GOTOFF_HI_SLO",/* name */
01149         FALSE,                     /* partial_inplace */
01150         0x0000ffff,         /* src_mask */
01151         0x0000ffff,         /* dst_mask */
01152         FALSE),             /* pcrel_offset */
01153 
01154   HOWTO (R_M32R_GOTOFF_LO,  /* type */
01155         0,                  /* rightshift */
01156         2,                  /* size (0 = byte, 1 = short, 2 = long) */
01157         16,                 /* bitsize */
01158         FALSE,                     /* pc_relative */
01159         0,                  /* bitpos */
01160         complain_overflow_dont, /* complain_on_overflow */
01161         bfd_elf_generic_reloc,     /* special_function */
01162         "R_M32R_GOTOFF_LO", /* name */
01163         FALSE,                     /* partial_inplace */
01164         0x0000ffff,         /* src_mask */
01165         0x0000ffff,         /* dst_mask */
01166         FALSE),             /* pcrel_offset */
01167 };
01168 
01169 /* Map BFD reloc types to M32R ELF reloc types.  */
01170 
01171 struct m32r_reloc_map
01172 {
01173   bfd_reloc_code_real_type bfd_reloc_val;
01174   unsigned char elf_reloc_val;
01175 };
01176 
01177 #ifdef USE_M32R_OLD_RELOC
01178 static const struct m32r_reloc_map m32r_reloc_map_old[] =
01179 {
01180   { BFD_RELOC_NONE, R_M32R_NONE },
01181   { BFD_RELOC_16, R_M32R_16 },
01182   { BFD_RELOC_32, R_M32R_32 },
01183   { BFD_RELOC_M32R_24, R_M32R_24 },
01184   { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL },
01185   { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL },
01186   { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL },
01187   { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO },
01188   { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO },
01189   { BFD_RELOC_M32R_LO16, R_M32R_LO16 },
01190   { BFD_RELOC_M32R_SDA16, R_M32R_SDA16 },
01191   { BFD_RELOC_VTABLE_INHERIT, R_M32R_GNU_VTINHERIT },
01192   { BFD_RELOC_VTABLE_ENTRY, R_M32R_GNU_VTENTRY },
01193 };
01194 #else
01195 static const struct m32r_reloc_map m32r_reloc_map[] =
01196 {
01197   { BFD_RELOC_NONE, R_M32R_NONE },
01198   { BFD_RELOC_16, R_M32R_16_RELA },
01199   { BFD_RELOC_32, R_M32R_32_RELA },
01200   { BFD_RELOC_M32R_24, R_M32R_24_RELA },
01201   { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL_RELA },
01202   { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL_RELA },
01203   { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL_RELA },
01204   { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO_RELA },
01205   { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO_RELA },
01206   { BFD_RELOC_M32R_LO16, R_M32R_LO16_RELA },
01207   { BFD_RELOC_M32R_SDA16, R_M32R_SDA16_RELA },
01208   { BFD_RELOC_VTABLE_INHERIT, R_M32R_RELA_GNU_VTINHERIT },
01209   { BFD_RELOC_VTABLE_ENTRY, R_M32R_RELA_GNU_VTENTRY },
01210   { BFD_RELOC_32_PCREL, R_M32R_REL32 },
01211 
01212   { BFD_RELOC_M32R_GOT24, R_M32R_GOT24 },
01213   { BFD_RELOC_M32R_26_PLTREL, R_M32R_26_PLTREL },
01214   { BFD_RELOC_M32R_COPY, R_M32R_COPY },
01215   { BFD_RELOC_M32R_GLOB_DAT, R_M32R_GLOB_DAT },
01216   { BFD_RELOC_M32R_JMP_SLOT, R_M32R_JMP_SLOT },
01217   { BFD_RELOC_M32R_RELATIVE, R_M32R_RELATIVE },
01218   { BFD_RELOC_M32R_GOTOFF, R_M32R_GOTOFF },
01219   { BFD_RELOC_M32R_GOTPC24, R_M32R_GOTPC24 },
01220   { BFD_RELOC_M32R_GOT16_HI_ULO, R_M32R_GOT16_HI_ULO },
01221   { BFD_RELOC_M32R_GOT16_HI_SLO, R_M32R_GOT16_HI_SLO },
01222   { BFD_RELOC_M32R_GOT16_LO, R_M32R_GOT16_LO },
01223   { BFD_RELOC_M32R_GOTPC_HI_ULO, R_M32R_GOTPC_HI_ULO },
01224   { BFD_RELOC_M32R_GOTPC_HI_SLO, R_M32R_GOTPC_HI_SLO },
01225   { BFD_RELOC_M32R_GOTPC_LO, R_M32R_GOTPC_LO },
01226   { BFD_RELOC_M32R_GOTOFF_HI_ULO, R_M32R_GOTOFF_HI_ULO },
01227   { BFD_RELOC_M32R_GOTOFF_HI_SLO, R_M32R_GOTOFF_HI_SLO },
01228   { BFD_RELOC_M32R_GOTOFF_LO, R_M32R_GOTOFF_LO },
01229 };
01230 #endif
01231 
01232 static reloc_howto_type *
01233 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
01234                              bfd_reloc_code_real_type code)
01235 {
01236   unsigned int i;
01237 
01238 #ifdef USE_M32R_OLD_RELOC
01239   for (i = 0;
01240        i < sizeof (m32r_reloc_map_old) / sizeof (struct m32r_reloc_map);
01241        i++)
01242     if (m32r_reloc_map_old[i].bfd_reloc_val == code)
01243       return &m32r_elf_howto_table[m32r_reloc_map_old[i].elf_reloc_val];
01244 
01245 #else /* ! USE_M32R_OLD_RELOC */
01246 
01247   for (i = 0;
01248        i < sizeof (m32r_reloc_map) / sizeof (struct m32r_reloc_map);
01249        i++)
01250     if (m32r_reloc_map[i].bfd_reloc_val == code)
01251       return &m32r_elf_howto_table[m32r_reloc_map[i].elf_reloc_val];
01252 #endif
01253 
01254   return NULL;
01255 }
01256 
01257 static reloc_howto_type *
01258 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
01259                              const char *r_name)
01260 {
01261   unsigned int i;
01262 
01263   for (i = 0;
01264        i < sizeof (m32r_elf_howto_table) / sizeof (m32r_elf_howto_table[0]);
01265        i++)
01266     if (m32r_elf_howto_table[i].name != NULL
01267        && strcasecmp (m32r_elf_howto_table[i].name, r_name) == 0)
01268       return &m32r_elf_howto_table[i];
01269 
01270   return NULL;
01271 }
01272 
01273 /* Set the howto pointer for an M32R ELF reloc.  */
01274 
01275 static void
01276 m32r_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
01277                      arelent *cache_ptr,
01278                      Elf_Internal_Rela *dst)
01279 {
01280   unsigned int r_type;
01281 
01282   r_type = ELF32_R_TYPE (dst->r_info);
01283   BFD_ASSERT (ELF32_R_TYPE(dst->r_info) <= (unsigned int) R_M32R_GNU_VTENTRY);
01284   cache_ptr->howto = &m32r_elf_howto_table[r_type];
01285 }
01286 
01287 static void
01288 m32r_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
01289                   arelent *cache_ptr,
01290                   Elf_Internal_Rela *dst)
01291 {
01292   BFD_ASSERT ((ELF32_R_TYPE(dst->r_info) == (unsigned int) R_M32R_NONE)
01293               || ((ELF32_R_TYPE(dst->r_info) > (unsigned int) R_M32R_GNU_VTENTRY)
01294                   && (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_M32R_max)));
01295   cache_ptr->howto = &m32r_elf_howto_table[ELF32_R_TYPE(dst->r_info)];
01296 }
01297 
01298 
01299 /* Given a BFD section, try to locate the corresponding ELF section
01300    index.  */
01301 
01302 static bfd_boolean
01303 _bfd_m32r_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
01304                                    asection *sec,
01305                                    int *retval)
01306 {
01307   if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
01308     {
01309       *retval = SHN_M32R_SCOMMON;
01310       return TRUE;
01311     }
01312   return FALSE;
01313 }
01314 
01315 /* M32R ELF uses two common sections.  One is the usual one, and the other
01316    is for small objects.  All the small objects are kept together, and then
01317    referenced via one register, which yields faster assembler code.  It is
01318    up to the compiler to emit an instruction to load the register with
01319    _SDA_BASE.  This is what we use for the small common section.  This
01320    approach is copied from elf32-mips.c.  */
01321 static asection m32r_elf_scom_section;
01322 static asymbol m32r_elf_scom_symbol;
01323 static asymbol *m32r_elf_scom_symbol_ptr;
01324 
01325 /* Handle the special M32R section numbers that a symbol may use.  */
01326 
01327 static void
01328 _bfd_m32r_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
01329 {
01330   elf_symbol_type *elfsym = (elf_symbol_type *) asym;
01331 
01332   switch (elfsym->internal_elf_sym.st_shndx)
01333     {
01334     case SHN_M32R_SCOMMON:
01335       if (m32r_elf_scom_section.name == NULL)
01336        {
01337          /* Initialize the small common section.  */
01338          m32r_elf_scom_section.name = ".scommon";
01339          m32r_elf_scom_section.flags = SEC_IS_COMMON;
01340          m32r_elf_scom_section.output_section = &m32r_elf_scom_section;
01341          m32r_elf_scom_section.symbol = &m32r_elf_scom_symbol;
01342          m32r_elf_scom_section.symbol_ptr_ptr = &m32r_elf_scom_symbol_ptr;
01343          m32r_elf_scom_symbol.name = ".scommon";
01344          m32r_elf_scom_symbol.flags = BSF_SECTION_SYM;
01345          m32r_elf_scom_symbol.section = &m32r_elf_scom_section;
01346          m32r_elf_scom_symbol_ptr = &m32r_elf_scom_symbol;
01347        }
01348       asym->section = &m32r_elf_scom_section;
01349       asym->value = elfsym->internal_elf_sym.st_size;
01350       break;
01351     }
01352 }
01353 
01354 /* Hook called by the linker routine which adds symbols from an object
01355    file.  We must handle the special M32R section numbers here.
01356    We also keep watching for whether we need to create the sdata special
01357    linker sections.  */
01358 
01359 static bfd_boolean
01360 m32r_elf_add_symbol_hook (bfd *abfd,
01361                        struct bfd_link_info *info,
01362                        Elf_Internal_Sym *sym,
01363                        const char **namep,
01364                        flagword *flagsp ATTRIBUTE_UNUSED,
01365                        asection **secp,
01366                        bfd_vma *valp)
01367 {
01368   if (! info->relocatable
01369       && (*namep)[0] == '_' && (*namep)[1] == 'S'
01370       && strcmp (*namep, "_SDA_BASE_") == 0
01371       && is_elf_hash_table (info->hash))
01372     {
01373       /* This is simpler than using _bfd_elf_create_linker_section
01374         (our needs are simpler than ppc's needs).  Also
01375         _bfd_elf_create_linker_section currently has a bug where if a .sdata
01376         section already exists a new one is created that follows it which
01377         screws of _SDA_BASE_ address calcs because output_offset != 0.  */
01378       struct elf_link_hash_entry *h;
01379       struct bfd_link_hash_entry *bh;
01380       asection *s = bfd_get_section_by_name (abfd, ".sdata");
01381 
01382       /* The following code was cobbled from elf32-ppc.c and elflink.c.  */
01383       if (s == NULL)
01384        {
01385          flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
01386                          | SEC_IN_MEMORY | SEC_LINKER_CREATED);
01387 
01388          s = bfd_make_section_anyway_with_flags (abfd, ".sdata",
01389                                             flags);
01390          if (s == NULL)
01391            return FALSE;
01392          bfd_set_section_alignment (abfd, s, 2);
01393        }
01394 
01395       bh = bfd_link_hash_lookup (info->hash, "_SDA_BASE_",
01396                              FALSE, FALSE, FALSE);
01397 
01398       if ((bh == NULL || bh->type == bfd_link_hash_undefined)
01399          && !(_bfd_generic_link_add_one_symbol (info,
01400                                            abfd,
01401                                            "_SDA_BASE_",
01402                                            BSF_GLOBAL,
01403                                            s,
01404                                            (bfd_vma) 32768,
01405                                            NULL,
01406                                            FALSE,
01407                                            get_elf_backend_data (abfd)->collect,
01408                                            &bh)))
01409        return FALSE;
01410       h = (struct elf_link_hash_entry *) bh;
01411       h->type = STT_OBJECT;
01412     }
01413 
01414   switch (sym->st_shndx)
01415     {
01416     case SHN_M32R_SCOMMON:
01417       *secp = bfd_make_section_old_way (abfd, ".scommon");
01418       (*secp)->flags |= SEC_IS_COMMON;
01419       *valp = sym->st_size;
01420       break;
01421     }
01422 
01423   return TRUE;
01424 }
01425 
01426 /* We have to figure out the SDA_BASE value, so that we can adjust the
01427    symbol value correctly.  We look up the symbol _SDA_BASE_ in the output
01428    BFD.  If we can't find it, we're stuck.  We cache it in the ELF
01429    target data.  We don't need to adjust the symbol value for an
01430    external symbol if we are producing relocatable output.  */
01431 
01432 static bfd_reloc_status_type
01433 m32r_elf_final_sda_base (bfd *output_bfd,
01434                       struct bfd_link_info *info,
01435                       const char **error_message,
01436                       bfd_vma *psb)
01437 {
01438   if (elf_gp (output_bfd) == 0)
01439     {
01440       struct bfd_link_hash_entry *h;
01441 
01442       h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", FALSE, FALSE, TRUE);
01443       if (h != NULL && h->type == bfd_link_hash_defined)
01444        elf_gp (output_bfd) = (h->u.def.value
01445                             + h->u.def.section->output_section->vma
01446                             + h->u.def.section->output_offset);
01447       else
01448        {
01449          /* Only get the error once.  */
01450          *psb = elf_gp (output_bfd) = 4;
01451          *error_message =
01452            (const char *) _("SDA relocation when _SDA_BASE_ not defined");
01453          return bfd_reloc_dangerous;
01454        }
01455     }
01456   *psb = elf_gp (output_bfd);
01457   return bfd_reloc_ok;
01458 }
01459 
01460 /* Return size of a PLT entry.  */
01461 #define elf_m32r_sizeof_plt(info) PLT_ENTRY_SIZE
01462 
01463 /* The m32r linker needs to keep track of the number of relocs that it
01464    decides to copy in check_relocs for each symbol.  This is so that
01465    it can discard PC relative relocs if it doesn't need them when
01466    linking with -Bsymbolic.  We store the information in a field
01467    extending the regular ELF linker hash table.  */
01468 
01469 /* This structure keeps track of the number of PC relative relocs we
01470    have copied for a given symbol.  */
01471 
01472 struct elf_m32r_pcrel_relocs_copied
01473 {
01474   /* Next section.  */
01475   struct elf_m32r_pcrel_relocs_copied *next;
01476   /* A section in dynobj.  */
01477   asection *section;
01478   /* Number of relocs copied in this section.  */
01479   bfd_size_type count;
01480 };
01481 
01482 /* The sh linker needs to keep track of the number of relocs that it
01483    decides to copy as dynamic relocs in check_relocs for each symbol.
01484    This is so that it can later discard them if they are found to be
01485    unnecessary.  We store the information in a field extending the
01486    regular ELF linker hash table.  */
01487 
01488 struct elf_m32r_dyn_relocs
01489 {
01490   struct elf_m32r_dyn_relocs *next;
01491 
01492   /* The input section of the reloc.  */
01493   asection *sec;
01494 
01495   /* Total number of relocs copied for the input section.  */
01496   bfd_size_type count;
01497 
01498   /* Number of pc-relative relocs copied for the input section.  */
01499   bfd_size_type pc_count;
01500 };
01501 
01502 
01503 /* m32r ELF linker hash entry.  */
01504 
01505 struct elf_m32r_link_hash_entry
01506 {
01507   struct elf_link_hash_entry root;
01508 
01509   /* Track dynamic relocs copied for this symbol.  */
01510   struct elf_m32r_dyn_relocs *dyn_relocs;
01511 };
01512 
01513 /* m32r ELF linker hash table.  */
01514 
01515 struct elf_m32r_link_hash_table
01516 {
01517   struct elf_link_hash_table root;
01518 
01519   /* Short-cuts to get to dynamic linker sections.  */
01520   asection *sgot;
01521   asection *sgotplt;
01522   asection *srelgot;
01523   asection *splt;
01524   asection *srelplt;
01525   asection *sdynbss;
01526   asection *srelbss;
01527 
01528   /* Small local sym to section mapping cache.  */
01529   struct sym_sec_cache sym_sec;
01530 };
01531 
01532 /* Traverse an m32r ELF linker hash table.  */
01533 
01534 #define m32r_elf_link_hash_traverse(table, func, info)                \
01535   (elf_link_hash_traverse                                      \
01536    (&(table)->root,                                            \
01537     (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func),  \
01538     (info)))
01539 
01540 /* Get the m32r ELF linker hash table from a link_info structure.  */
01541 
01542 
01543 #define m32r_elf_hash_table(p) \
01544   ((struct elf_m32r_link_hash_table *) ((p)->hash))
01545 
01546 /* Create an entry in an m32r ELF linker hash table.  */
01547 
01548 static struct bfd_hash_entry *
01549 m32r_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
01550                          struct bfd_hash_table *table,
01551                          const char *string)
01552 {
01553   struct elf_m32r_link_hash_entry *ret =
01554     (struct elf_m32r_link_hash_entry *) entry;
01555 
01556   /* Allocate the structure if it has not already been allocated by a
01557      subclass.  */
01558   if (ret == NULL)
01559     ret = bfd_hash_allocate (table,
01560                           sizeof (struct elf_m32r_link_hash_entry));
01561   if (ret == NULL)
01562     return NULL;
01563 
01564   /* Call the allocation method of the superclass.  */
01565   ret = ((struct elf_m32r_link_hash_entry *)
01566          _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
01567                                      table, string));
01568   if (ret != NULL)
01569     {
01570       struct elf_m32r_link_hash_entry *eh;
01571 
01572       eh = (struct elf_m32r_link_hash_entry *) ret;
01573       eh->dyn_relocs = NULL;
01574     }
01575 
01576   return (struct bfd_hash_entry *) ret;
01577 }
01578 
01579 /* Create an m32r ELF linker hash table.  */
01580 
01581 static struct bfd_link_hash_table *
01582 m32r_elf_link_hash_table_create (bfd *abfd)
01583 {
01584   struct elf_m32r_link_hash_table *ret;
01585   bfd_size_type amt = sizeof (struct elf_m32r_link_hash_table);
01586 
01587   ret = bfd_malloc (amt);
01588   if (ret == NULL)
01589     return NULL;
01590 
01591   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
01592                                   m32r_elf_link_hash_newfunc,
01593                                   sizeof (struct elf_m32r_link_hash_entry)))
01594     {
01595       free (ret);
01596       return NULL;
01597     }
01598 
01599   ret->sgot = NULL;
01600   ret->sgotplt = NULL;
01601   ret->srelgot = NULL;
01602   ret->splt = NULL;
01603   ret->srelplt = NULL;
01604   ret->sdynbss = NULL;
01605   ret->srelbss = NULL;
01606   ret->sym_sec.abfd = NULL;
01607 
01608   return &ret->root.root;
01609 }
01610 
01611 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
01612    shortcuts to them in our hash table.  */
01613 
01614 static bfd_boolean
01615 create_got_section (bfd *dynobj, struct bfd_link_info *info)
01616 {
01617   struct elf_m32r_link_hash_table *htab;
01618 
01619   if (! _bfd_elf_create_got_section (dynobj, info))
01620     return FALSE;
01621 
01622   htab = m32r_elf_hash_table (info);
01623   htab->sgot = bfd_get_section_by_name (dynobj, ".got");
01624   htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
01625   if (! htab->sgot || ! htab->sgotplt)
01626     abort ();
01627 
01628   htab->srelgot = bfd_make_section_with_flags (dynobj, ".rela.got",
01629                                           (SEC_ALLOC
01630                                           | SEC_LOAD
01631                                           | SEC_HAS_CONTENTS
01632                                           | SEC_IN_MEMORY
01633                                           | SEC_LINKER_CREATED
01634                                           | SEC_READONLY));
01635   if (htab->srelgot == NULL
01636       || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
01637     return FALSE;
01638 
01639   return TRUE;
01640 }
01641 
01642 /* Create dynamic sections when linking against a dynamic object.  */
01643 
01644 static bfd_boolean
01645 m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
01646 {
01647   struct elf_m32r_link_hash_table *htab;
01648   flagword flags, pltflags;
01649   asection *s;
01650   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
01651   int ptralign = 2; /* 32bit */
01652 
01653   htab = m32r_elf_hash_table (info);
01654 
01655   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
01656      .rel[a].bss sections.  */
01657   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
01658            | SEC_LINKER_CREATED);
01659 
01660   pltflags = flags;
01661   pltflags |= SEC_CODE;
01662   if (bed->plt_not_loaded)
01663     pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
01664   if (bed->plt_readonly)
01665     pltflags |= SEC_READONLY;
01666 
01667   s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
01668   htab->splt = s;
01669   if (s == NULL
01670       || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
01671     return FALSE;
01672 
01673   if (bed->want_plt_sym)
01674     {
01675       /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
01676          .plt section.  */
01677       struct bfd_link_hash_entry *bh = NULL;
01678       struct elf_link_hash_entry *h;
01679 
01680       if (! (_bfd_generic_link_add_one_symbol
01681              (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
01682               (bfd_vma) 0, NULL, FALSE,
01683               get_elf_backend_data (abfd)->collect, &bh)))
01684         return FALSE;
01685       h = (struct elf_link_hash_entry *) bh;
01686       h->def_regular = 1;
01687       h->type = STT_OBJECT;
01688       htab->root.hplt = h;
01689 
01690       if (info->shared
01691           && ! bfd_elf_link_record_dynamic_symbol (info, h))
01692         return FALSE;
01693     }
01694 
01695   s = bfd_make_section_with_flags (abfd,
01696                                bed->default_use_rela_p ? ".rela.plt" : ".rel.plt",
01697                                flags | SEC_READONLY);
01698   htab->srelplt = s;
01699   if (s == NULL
01700       || ! bfd_set_section_alignment (abfd, s, ptralign))
01701     return FALSE;
01702 
01703   if (htab->sgot == NULL
01704       && ! create_got_section (abfd, info))
01705     return FALSE;
01706 
01707   {
01708     const char *secname;
01709     char *relname;
01710     flagword secflags;
01711     asection *sec;
01712 
01713     for (sec = abfd->sections; sec; sec = sec->next)
01714       {
01715         secflags = bfd_get_section_flags (abfd, sec);
01716         if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
01717             || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
01718           continue;
01719         secname = bfd_get_section_name (abfd, sec);
01720         relname = bfd_malloc ((bfd_size_type) strlen (secname) + 6);
01721         strcpy (relname, ".rela");
01722         strcat (relname, secname);
01723         if (bfd_get_section_by_name (abfd, secname))
01724           continue;
01725         s = bfd_make_section_with_flags (abfd, relname,
01726                                     flags | SEC_READONLY);
01727         if (s == NULL
01728             || ! bfd_set_section_alignment (abfd, s, ptralign))
01729           return FALSE;
01730       }
01731   }
01732 
01733   if (bed->want_dynbss)
01734     {
01735       /* The .dynbss section is a place to put symbols which are defined
01736          by dynamic objects, are referenced by regular objects, and are
01737          not functions.  We must allocate space for them in the process
01738          image and use a R_*_COPY reloc to tell the dynamic linker to
01739          initialize them at run time.  The linker script puts the .dynbss
01740          section into the .bss section of the final image.  */
01741       s = bfd_make_section_with_flags (abfd, ".dynbss",
01742                                    SEC_ALLOC | SEC_LINKER_CREATED);
01743       htab->sdynbss = s;
01744       if (s == NULL)
01745         return FALSE;
01746       /* The .rel[a].bss section holds copy relocs.  This section is not
01747          normally needed.  We need to create it here, though, so that the
01748          linker will map it to an output section.  We can't just create it
01749          only if we need it, because we will not know whether we need it
01750          until we have seen all the input files, and the first time the
01751          main linker code calls BFD after examining all the input files
01752          (size_dynamic_sections) the input sections have already been
01753          mapped to the output sections.  If the section turns out not to
01754          be needed, we can discard it later.  We will never need this
01755          section when generating a shared object, since they do not use
01756          copy relocs.  */
01757       if (! info->shared)
01758         {
01759           s = bfd_make_section_with_flags (abfd,
01760                                       (bed->default_use_rela_p
01761                                        ? ".rela.bss" : ".rel.bss"),
01762                                       flags | SEC_READONLY);
01763           htab->srelbss = s;
01764           if (s == NULL
01765               || ! bfd_set_section_alignment (abfd, s, ptralign))
01766             return FALSE;
01767         }
01768     }
01769 
01770   return TRUE;
01771 }
01772 
01773 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
01774 
01775 static void
01776 m32r_elf_copy_indirect_symbol (struct bfd_link_info *info,
01777                                struct elf_link_hash_entry *dir,
01778                                struct elf_link_hash_entry *ind)
01779 {
01780   struct elf_m32r_link_hash_entry * edir;
01781   struct elf_m32r_link_hash_entry * eind;
01782 
01783   edir = (struct elf_m32r_link_hash_entry *) dir;
01784   eind = (struct elf_m32r_link_hash_entry *) ind;
01785 
01786   if (eind->dyn_relocs != NULL)
01787     {
01788       if (edir->dyn_relocs != NULL)
01789         {
01790           struct elf_m32r_dyn_relocs **pp;
01791           struct elf_m32r_dyn_relocs *p;
01792 
01793           /* Add reloc counts against the indirect sym to the direct sym
01794              list.  Merge any entries against the same section.  */
01795           for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
01796             {
01797               struct elf_m32r_dyn_relocs *q;
01798 
01799               for (q = edir->dyn_relocs; q != NULL; q = q->next)
01800                 if (q->sec == p->sec)
01801                   {
01802                     q->pc_count += p->pc_count;
01803                     q->count += p->count;
01804                     *pp = p->next;
01805                     break;
01806                   }
01807               if (q == NULL)
01808                 pp = &p->next;
01809             }
01810           *pp = edir->dyn_relocs;
01811         }
01812 
01813       edir->dyn_relocs = eind->dyn_relocs;
01814       eind->dyn_relocs = NULL;
01815     }
01816 
01817   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
01818 }
01819 
01820 
01821 /* Adjust a symbol defined by a dynamic object and referenced by a
01822    regular object.  The current definition is in some section of the
01823    dynamic object, but we're not including those sections.  We have to
01824    change the definition to something the rest of the link can
01825    understand.  */
01826 
01827 static bfd_boolean
01828 m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
01829                             struct elf_link_hash_entry *h)
01830 {
01831   struct elf_m32r_link_hash_table *htab;
01832   struct elf_m32r_link_hash_entry *eh;
01833   struct elf_m32r_dyn_relocs *p;
01834   bfd *dynobj;
01835   asection *s;
01836   unsigned int power_of_two;
01837 
01838 #ifdef DEBUG_PIC
01839   printf ("m32r_elf_adjust_dynamic_symbol()\n");
01840 #endif
01841 
01842   dynobj = elf_hash_table (info)->dynobj;
01843 
01844   /* Make sure we know what is going on here.  */
01845   BFD_ASSERT (dynobj != NULL
01846               && (h->needs_plt
01847                   || h->u.weakdef != NULL
01848                   || (h->def_dynamic
01849                       && h->ref_regular
01850                       && !h->def_regular)));
01851 
01852   /* If this is a function, put it in the procedure linkage table.  We
01853      will fill in the contents of the procedure linkage table later,
01854      when we know the address of the .got section.  */
01855   if (h->type == STT_FUNC
01856       || h->needs_plt)
01857     {
01858       if (! info->shared
01859           && !h->def_dynamic
01860           && !h->ref_dynamic
01861          && h->root.type != bfd_link_hash_undefweak
01862          && h->root.type != bfd_link_hash_undefined)
01863         {
01864           /* This case can occur if we saw a PLT reloc in an input
01865              file, but the symbol was never referred to by a dynamic
01866              object.  In such a case, we don't actually need to build
01867              a procedure linkage table, and we can just do a PCREL
01868              reloc instead.  */
01869           h->plt.offset = (bfd_vma) -1;
01870           h->needs_plt = 0;
01871         }
01872 
01873       return TRUE;
01874     }
01875   else
01876     h->plt.offset = (bfd_vma) -1;
01877 
01878   /* If this is a weak symbol, and there is a real definition, the
01879      processor independent code will have arranged for us to see the
01880      real definition first, and we can just use the same value.  */
01881   if (h->u.weakdef != NULL)
01882     {
01883       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
01884                   || h->u.weakdef->root.type == bfd_link_hash_defweak);
01885       h->root.u.def.section = h->u.weakdef->root.u.def.section;
01886       h->root.u.def.value = h->u.weakdef->root.u.def.value;
01887       return TRUE;
01888     }
01889 
01890   /* This is a reference to a symbol defined by a dynamic object which
01891      is not a function.  */
01892 
01893   /* If we are creating a shared library, we must presume that the
01894      only references to the symbol are via the global offset table.
01895      For such cases we need not do anything here; the relocations will
01896      be handled correctly by relocate_section.  */
01897   if (info->shared)
01898     return TRUE;
01899 
01900   /* If there are no references to this symbol that do not use the
01901      GOT, we don't need to generate a copy reloc.  */
01902   if (!h->non_got_ref)
01903     return TRUE;
01904 
01905   /* If -z nocopyreloc was given, we won't generate them either.  */
01906   if (info->nocopyreloc)
01907     {
01908       h->non_got_ref = 0;
01909       return TRUE;
01910     }
01911 
01912   eh = (struct elf_m32r_link_hash_entry *) h;
01913   for (p = eh->dyn_relocs; p != NULL; p = p->next)
01914     {
01915       s = p->sec->output_section;
01916       if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
01917         break;
01918     }
01919 
01920   /* If we didn't find any dynamic relocs in sections which needs the
01921      copy reloc, then we'll be keeping the dynamic relocs and avoiding
01922      the copy reloc.  */
01923   if (p == NULL)
01924     {
01925       h->non_got_ref = 0;
01926       return TRUE;
01927     }
01928 
01929   if (h->size == 0)
01930     {
01931       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
01932                           h->root.root.string);
01933       return TRUE;
01934     }
01935 
01936   /* We must allocate the symbol in our .dynbss section, which will
01937      become part of the .bss section of the executable.  There will be
01938      an entry for this symbol in the .dynsym section.  The dynamic
01939      object will contain position independent code, so all references
01940      from the dynamic object to this symbol will go through the global
01941      offset table.  The dynamic linker will use the .dynsym entry to
01942      determine the address it must put in the global offset table, so
01943      both the dynamic object and the regular object will refer to the
01944      same memory location for the variable.  */
01945 
01946   htab = m32r_elf_hash_table (info);
01947   s = htab->sdynbss;
01948   BFD_ASSERT (s != NULL);
01949 
01950   /* We must generate a R_M32R_COPY reloc to tell the dynamic linker
01951      to copy the initial value out of the dynamic object and into the
01952      runtime process image.  We need to remember the offset into the
01953      .rela.bss section we are going to use.  */
01954   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
01955     {
01956       asection *srel;
01957 
01958       srel = htab->srelbss;
01959       BFD_ASSERT (srel != NULL);
01960       srel->size += sizeof (Elf32_External_Rela);
01961       h->needs_copy = 1;
01962     }
01963 
01964   /* We need to figure out the alignment required for this symbol.  I
01965      have no idea how ELF linkers handle this.  */
01966   power_of_two = bfd_log2 (h->size);
01967   if (power_of_two > 3)
01968     power_of_two = 3;
01969 
01970   /* Apply the required alignment.  */
01971   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
01972   if (power_of_two > bfd_get_section_alignment (dynobj, s))
01973     {
01974       if (! bfd_set_section_alignment (dynobj, s, power_of_two))
01975         return FALSE;
01976     }
01977 
01978   /* Define the symbol as being at this point in the section.  */
01979   h->root.u.def.section = s;
01980   h->root.u.def.value = s->size;
01981 
01982   /* Increment the section size to make room for the symbol.  */
01983   s->size += h->size;
01984 
01985   return TRUE;
01986 }
01987 
01988 /* Allocate space in .plt, .got and associated reloc sections for
01989    dynamic relocs.  */
01990 
01991 static bfd_boolean
01992 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
01993 {
01994   struct bfd_link_info *info;
01995   struct elf_m32r_link_hash_table *htab;
01996   struct elf_m32r_link_hash_entry *eh;
01997   struct elf_m32r_dyn_relocs *p;
01998 
01999   if (h->root.type == bfd_link_hash_indirect)
02000     return TRUE;
02001 
02002   if (h->root.type == bfd_link_hash_warning)
02003     /* When warning symbols are created, they **replace** the "real"
02004        entry in the hash table, thus we never get to see the real
02005        symbol in a hash traversal.  So look at it now.  */
02006     h = (struct elf_link_hash_entry *) h->root.u.i.link;
02007 
02008   info = (struct bfd_link_info *) inf;
02009   htab = m32r_elf_hash_table (info);
02010 
02011   eh = (struct elf_m32r_link_hash_entry *) h;
02012 
02013   if (htab->root.dynamic_sections_created
02014       && h->plt.refcount > 0)
02015     {
02016       /* Make sure this symbol is output as a dynamic symbol.
02017          Undefined weak syms won't yet be marked as dynamic.  */
02018       if (h->dynindx == -1
02019           && !h->forced_local)
02020         {
02021           if (! bfd_elf_link_record_dynamic_symbol (info, h))
02022             return FALSE;
02023         }
02024 
02025       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
02026         {
02027           asection *s = htab->splt;
02028 
02029           /* If this is the first .plt entry, make room for the special
02030              first entry.  */
02031           if (s->size == 0)
02032             s->size += PLT_ENTRY_SIZE;
02033 
02034           h->plt.offset = s->size;
02035 
02036           /* If this symbol is not defined in a regular file, and we are
02037              not generating a shared library, then set the symbol to this
02038              location in the .plt.  This is required to make function
02039              pointers compare as equal between the normal executable and
02040              the shared library.  */
02041           if (! info->shared
02042               && !h->def_regular)
02043             {
02044               h->root.u.def.section = s;
02045               h->root.u.def.value = h->plt.offset;
02046             }
02047 
02048           /* Make room for this entry.  */
02049           s->size += PLT_ENTRY_SIZE;
02050 
02051           /* We also need to make an entry in the .got.plt section, which
02052              will be placed in the .got section by the linker script.  */
02053           htab->sgotplt->size += 4;
02054 
02055           /* We also need to make an entry in the .rel.plt section.  */
02056           htab->srelplt->size += sizeof (Elf32_External_Rela);
02057         }
02058       else
02059         {
02060           h->plt.offset = (bfd_vma) -1;
02061           h->needs_plt = 0;
02062         }
02063     }
02064   else
02065     {
02066       h->plt.offset = (bfd_vma) -1;
02067       h->needs_plt = 0;
02068     }
02069 
02070   if (h->got.refcount > 0)
02071     {
02072       asection *s;
02073       bfd_boolean dyn;
02074 
02075       /* Make sure this symbol is output as a dynamic symbol.
02076          Undefined weak syms won't yet be marked as dynamic.  */
02077       if (h->dynindx == -1
02078           && !h->forced_local)
02079         {
02080           if (! bfd_elf_link_record_dynamic_symbol (info, h))
02081             return FALSE;
02082         }
02083 
02084       s = htab->sgot;
02085 
02086       h->got.offset = s->size;
02087       s->size += 4;
02088       dyn = htab->root.dynamic_sections_created;
02089       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
02090         htab->srelgot->size += sizeof (Elf32_External_Rela);
02091     }
02092   else
02093     h->got.offset = (bfd_vma) -1;
02094 
02095   if (eh->dyn_relocs == NULL)
02096     return TRUE;
02097 
02098   /* In the shared -Bsymbolic case, discard space allocated for
02099      dynamic pc-relative relocs against symbols which turn out to be
02100      defined in regular objects.  For the normal shared case, discard
02101      space for pc-relative relocs that have become local due to symbol
02102      visibility changes.  */
02103 
02104   if (info->shared)
02105     {
02106       if (h->def_regular
02107           && (h->forced_local
02108               || info->symbolic))
02109         {
02110           struct elf_m32r_dyn_relocs **pp;
02111 
02112           for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
02113             {
02114               p->count -= p->pc_count;
02115               p->pc_count = 0;
02116               if (p->count == 0)
02117                 *pp = p->next;
02118               else
02119                 pp = &p->next;
02120             }
02121         }
02122 
02123       /* Also discard relocs on undefined weak syms with non-default
02124         visibility.  */
02125       if (eh->dyn_relocs != NULL
02126          && h->root.type == bfd_link_hash_undefweak)
02127        {
02128          if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
02129            eh->dyn_relocs = NULL;
02130 
02131          /* Make sure undefined weak symbols are output as a dynamic
02132             symbol in PIEs.  */
02133          else if (h->dynindx == -1
02134                  && !h->forced_local)
02135            {
02136              if (! bfd_elf_link_record_dynamic_symbol (info, h))
02137               return FALSE;
02138            }
02139        }
02140     }
02141   else
02142     {
02143       /* For the non-shared case, discard space for relocs against
02144          symbols which turn out to need copy relocs or are not
02145          dynamic.  */
02146 
02147       if (!h->non_got_ref
02148           && ((h->def_dynamic
02149                && !h->def_regular)
02150               || (htab->root.dynamic_sections_created
02151                   && (h->root.type == bfd_link_hash_undefweak
02152                       || h->root.type == bfd_link_hash_undefined))))
02153         {
02154           /* Make sure this symbol is output as a dynamic symbol.
02155              Undefined weak syms won't yet be marked as dynamic.  */
02156           if (h->dynindx == -1
02157               && !h->forced_local)
02158             {
02159               if (! bfd_elf_link_record_dynamic_symbol (info, h))
02160                 return FALSE;
02161             }
02162 
02163           /* If that succeeded, we know we'll be keeping all the
02164              relocs.  */
02165           if (h->dynindx != -1)
02166             goto keep;
02167         }
02168 
02169       eh->dyn_relocs = NULL;
02170 
02171     keep: ;
02172     }
02173 
02174   /* Finally, allocate space.  */
02175   for (p = eh->dyn_relocs; p != NULL; p = p->next)
02176     {
02177       asection *sreloc = elf_section_data (p->sec)->sreloc;
02178       sreloc->size += p->count * sizeof (Elf32_External_Rela);
02179     }
02180 
02181   return TRUE;
02182 }
02183 
02184 /* Find any dynamic relocs that apply to read-only sections.  */
02185 
02186 static bfd_boolean
02187 readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
02188 {
02189   struct elf_m32r_link_hash_entry *eh;
02190   struct elf_m32r_dyn_relocs *p;
02191 
02192   if (h->root.type == bfd_link_hash_warning)
02193     h = (struct elf_link_hash_entry *) h->root.u.i.link;
02194 
02195   eh = (struct elf_m32r_link_hash_entry *) h;
02196   for (p = eh->dyn_relocs; p != NULL; p = p->next)
02197     {
02198       asection *s = p->sec->output_section;
02199 
02200       if (s != NULL && (s->flags & SEC_READONLY) != 0)
02201         {
02202           struct bfd_link_info *info = (struct bfd_link_info *) inf;
02203 
02204           info->flags |= DF_TEXTREL;
02205 
02206           /* Not an error, just cut short the traversal.  */
02207           return FALSE;
02208         }
02209     }
02210   return TRUE;
02211 }
02212 
02213 /* Set the sizes of the dynamic sections.  */
02214 
02215 static bfd_boolean
02216 m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
02217                             struct bfd_link_info *info)
02218 {
02219   struct elf_m32r_link_hash_table *htab;
02220   bfd *dynobj;
02221   asection *s;
02222   bfd_boolean relocs;
02223   bfd *ibfd;
02224 
02225 #ifdef DEBUG_PIC
02226   printf ("m32r_elf_size_dynamic_sections()\n");
02227 #endif
02228 
02229   htab = m32r_elf_hash_table (info);
02230   dynobj = htab->root.dynobj;
02231   BFD_ASSERT (dynobj != NULL);
02232 
02233   if (htab->root.dynamic_sections_created)
02234     {
02235       /* Set the contents of the .interp section to the interpreter.  */
02236       if (info->executable)
02237        {
02238          s = bfd_get_section_by_name (dynobj, ".interp");
02239          BFD_ASSERT (s != NULL);
02240          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
02241          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
02242        }
02243     }
02244 
02245   /* Set up .got offsets for local syms, and space for local dynamic
02246      relocs.  */
02247   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
02248     {
02249       bfd_signed_vma *local_got;
02250       bfd_signed_vma *end_local_got;
02251       bfd_size_type locsymcount;
02252       Elf_Internal_Shdr *symtab_hdr;
02253       asection *srel;
02254 
02255       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
02256         continue;
02257 
02258       for (s = ibfd->sections; s != NULL; s = s->next)
02259         {
02260           struct elf_m32r_dyn_relocs *p;
02261 
02262           for (p = ((struct elf_m32r_dyn_relocs *)
02263                     elf_section_data (s)->local_dynrel);
02264                p != NULL;
02265                p = p->next)
02266             {
02267               if (! bfd_is_abs_section (p->sec)
02268                   && bfd_is_abs_section (p->sec->output_section))
02269                 {
02270                   /* Input section has been discarded, either because
02271                      it is a copy of a linkonce section or due to
02272                      linker script /DISCARD/, so we'll be discarding
02273                      the relocs too.  */
02274                 }
02275               else if (p->count != 0)
02276                 {
02277                   srel = elf_section_data (p->sec)->sreloc;
02278                   srel->size += p->count * sizeof (Elf32_External_Rela);
02279                   if ((p->sec->output_section->flags & SEC_READONLY) != 0)
02280                     info->flags |= DF_TEXTREL;
02281                 }
02282             }
02283         }
02284 
02285       local_got = elf_local_got_refcounts (ibfd);
02286       if (!local_got)
02287         continue;
02288 
02289       symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
02290       locsymcount = symtab_hdr->sh_info;
02291       end_local_got = local_got + locsymcount;
02292       s = htab->sgot;
02293       srel = htab->srelgot;
02294       for (; local_got < end_local_got; ++local_got)
02295         {
02296           if (*local_got > 0)
02297             {
02298               *local_got = s->size;
02299               s->size += 4;
02300               if (info->shared)
02301                 srel->size += sizeof (Elf32_External_Rela);
02302             }
02303           else
02304             *local_got = (bfd_vma) -1;
02305         }
02306     }
02307 
02308   /* Allocate global sym .plt and .got entries, and space for global
02309      sym dynamic relocs.  */
02310   elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
02311 
02312   /* We now have determined the sizes of the various dynamic sections.
02313      Allocate memory for them.  */
02314   relocs = FALSE;
02315   for (s = dynobj->sections; s != NULL; s = s->next)
02316     {
02317       if ((s->flags & SEC_LINKER_CREATED) == 0)
02318         continue;
02319 
02320       if (s == htab->splt
02321           || s == htab->sgot
02322           || s == htab->sgotplt
02323          || s == htab->sdynbss)
02324         {
02325           /* Strip this section if we don't need it; see the
02326              comment below.  */
02327         }
02328       else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
02329         {
02330           if (s->size != 0 && s != htab->srelplt)
02331             relocs = TRUE;
02332 
02333           /* We use the reloc_count field as a counter if we need
02334              to copy relocs into the output file.  */
02335           s->reloc_count = 0;
02336         }
02337       else
02338        /* It's not one of our sections, so don't allocate space.  */
02339        continue;
02340 
02341       if (s->size == 0)
02342         {
02343           /* If we don't need this section, strip it from the
02344              output file.  This is mostly to handle .rela.bss and
02345              .rela.plt.  We must create both sections in
02346              create_dynamic_sections, because they must be created
02347              before the linker maps input sections to output
02348              sections.  The linker does that before
02349              adjust_dynamic_symbol is called, and it is that
02350              function which decides whether anything needs to go
02351              into these sections.  */
02352           s->flags |= SEC_EXCLUDE;
02353           continue;
02354         }
02355 
02356       if ((s->flags & SEC_HAS_CONTENTS) == 0)
02357        continue;
02358 
02359       /* Allocate memory for the section contents.  We use bfd_zalloc
02360          here in case unused entries are not reclaimed before the
02361          section's contents are written out.  This should not happen,
02362          but this way if it does, we get a R_M32R_NONE reloc instead
02363          of garbage.  */
02364       s->contents = bfd_zalloc (dynobj, s->size);
02365       if (s->contents == NULL)
02366         return FALSE;
02367     }
02368 
02369   if (htab->root.dynamic_sections_created)
02370     {
02371       /* Add some entries to the .dynamic section.  We fill in the
02372         values later, in m32r_elf_finish_dynamic_sections, but we
02373         must add the entries now so that we get the correct size for
02374         the .dynamic section.  The DT_DEBUG entry is filled in by the
02375         dynamic linker and used by the debugger.  */
02376 #define add_dynamic_entry(TAG, VAL) \
02377   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
02378 
02379      if (info->executable)
02380        {
02381          if (! add_dynamic_entry (DT_DEBUG, 0))
02382            return FALSE;
02383        }
02384 
02385       if (htab->splt->size != 0)
02386         {
02387           if (! add_dynamic_entry (DT_PLTGOT, 0)
02388               || ! add_dynamic_entry (DT_PLTRELSZ, 0)
02389               || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
02390               || ! add_dynamic_entry (DT_JMPREL, 0))
02391             return FALSE;
02392         }
02393 
02394       if (relocs)
02395         {
02396           if (! add_dynamic_entry (DT_RELA, 0)
02397               || ! add_dynamic_entry (DT_RELASZ, 0)
02398               || ! add_dynamic_entry (DT_RELAENT,
02399                                       sizeof (Elf32_External_Rela)))
02400             return FALSE;
02401 
02402           /* If any dynamic relocs apply to a read-only section,
02403              then we need a DT_TEXTREL entry.  */
02404           if ((info->flags & DF_TEXTREL) == 0)
02405             elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
02406                                     info);
02407 
02408           if ((info->flags & DF_TEXTREL) != 0)
02409             {
02410               if (! add_dynamic_entry (DT_TEXTREL, 0))
02411                 return FALSE;
02412             }
02413         }
02414     }
02415 #undef add_dynamic_entry
02416 
02417   return TRUE;
02418 }
02419 
02420 /* Relocate an M32R/D ELF section.
02421    There is some attempt to make this function usable for many architectures,
02422    both for RELA and REL type relocs, if only to serve as a learning tool.
02423 
02424    The RELOCATE_SECTION function is called by the new ELF backend linker
02425    to handle the relocations for a section.
02426 
02427    The relocs are always passed as Rela structures; if the section
02428    actually uses Rel structures, the r_addend field will always be
02429    zero.
02430 
02431    This function is responsible for adjust the section contents as
02432    necessary, and (if using Rela relocs and generating a
02433    relocatable output file) adjusting the reloc addend as
02434    necessary.
02435 
02436    This function does not have to worry about setting the reloc
02437    address or the reloc symbol index.
02438 
02439    LOCAL_SYMS is a pointer to the swapped in local symbols.
02440 
02441    LOCAL_SECTIONS is an array giving the section in the input file
02442    corresponding to the st_shndx field of each local symbol.
02443 
02444    The global hash table entry for the global symbols can be found
02445    via elf_sym_hashes (input_bfd).
02446 
02447    When generating relocatable output, this function must handle
02448    STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
02449    going to be the section symbol corresponding to the output
02450    section, which means that the addend must be adjusted
02451    accordingly.  */
02452 
02453 static bfd_boolean
02454 m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
02455                         struct bfd_link_info *info,
02456                         bfd *input_bfd,
02457                         asection *input_section,
02458                         bfd_byte *contents,
02459                         Elf_Internal_Rela *relocs,
02460                         Elf_Internal_Sym *local_syms,
02461                         asection **local_sections)
02462 {
02463   Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
02464   struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
02465   Elf_Internal_Rela *rel, *relend;
02466   /* Assume success.  */
02467   bfd_boolean ret = TRUE;
02468 
02469   struct elf_m32r_link_hash_table *htab = m32r_elf_hash_table (info);
02470   bfd *dynobj;
02471   bfd_vma *local_got_offsets;
02472   asection *sgot, *splt, *sreloc;
02473   bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
02474 
02475   dynobj = htab->root.dynobj;
02476   local_got_offsets = elf_local_got_offsets (input_bfd);
02477 
02478   sgot = htab->sgot;
02479   splt = htab->splt;
02480   sreloc = NULL;
02481 
02482   rel = relocs;
02483   relend = relocs + input_section->reloc_count;
02484   for (; rel < relend; rel++)
02485     {
02486       int r_type;
02487       reloc_howto_type *howto;
02488       unsigned long r_symndx;
02489       struct elf_link_hash_entry *h;
02490       /* We can't modify r_addend here as elf_link_input_bfd has an assert to
02491          ensure it's zero (we use REL relocs, not RELA).  Therefore this
02492          should be assigning zero to `addend', but for clarity we use
02493          `r_addend'.  */
02494       bfd_vma addend = rel->r_addend;
02495       bfd_vma offset = rel->r_offset;
02496       bfd_vma relocation;
02497       Elf_Internal_Sym *sym;
02498       asection *sec;
02499       const char *sym_name;
02500       bfd_reloc_status_type r;
02501       const char *errmsg = NULL;
02502       bfd_boolean use_rel = FALSE;
02503 
02504       h = NULL;
02505       r_type = ELF32_R_TYPE (rel->r_info);
02506       if (r_type < 0 || r_type >= (int) R_M32R_max)
02507        {
02508          (*_bfd_error_handler) (_("%B: unknown relocation type %d"),
02509                              input_bfd,
02510                              (int) r_type);
02511          bfd_set_error (bfd_error_bad_value);
02512          ret = FALSE;
02513          continue;
02514        }
02515 
02516       if (   r_type == R_M32R_GNU_VTENTRY
02517           || r_type == R_M32R_GNU_VTINHERIT
02518           || r_type == R_M32R_NONE
02519           || r_type == R_M32R_RELA_GNU_VTENTRY
02520           || r_type == R_M32R_RELA_GNU_VTINHERIT)
02521         continue;
02522 
02523       if (r_type <= R_M32R_GNU_VTENTRY)
02524         use_rel = TRUE;
02525 
02526       howto = m32r_elf_howto_table + r_type;
02527       r_symndx = ELF32_R_SYM (rel->r_info);
02528 
02529       sym = NULL;
02530       sec = NULL;
02531       h = NULL;
02532 
02533       if (r_symndx < symtab_hdr->sh_info)
02534        {
02535          /* Local symbol.  */
02536          sym = local_syms + r_symndx;
02537          sec = local_sections[r_symndx];
02538          sym_name = "<local symbol>";
02539 
02540          if (!use_rel)
02541            {
02542              relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
02543              addend = rel->r_addend;
02544            }
02545          else
02546            {
02547              relocation = (sec->output_section->vma
02548                          + sec->output_offset
02549                          + sym->st_value);
02550            }
02551        }
02552       else
02553        {
02554          /* External symbol.  */
02555          relocation = 0;
02556 
02557          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
02558          while (h->root.type == bfd_link_hash_indirect
02559                || h->root.type == bfd_link_hash_warning)
02560            h = (struct elf_link_hash_entry *) h->root.u.i.link;
02561          sym_name = h->root.root.string;
02562 
02563          if (h->root.type == bfd_link_hash_defined
02564              || h->root.type == bfd_link_hash_defweak)
02565            {
02566              bfd_boolean dyn;
02567              sec = h->root.u.def.section;
02568 
02569              dyn = htab->root.dynamic_sections_created;
02570              sec = h->root.u.def.section;
02571              if (r_type == R_M32R_GOTPC24
02572                 || (r_type == R_M32R_GOTPC_HI_ULO
02573                     || r_type == R_M32R_GOTPC_HI_SLO
02574                     || r_type == R_M32R_GOTPC_LO)
02575                 || (r_type == R_M32R_26_PLTREL
02576                     && h->plt.offset != (bfd_vma) -1)
02577                 || ((r_type == R_M32R_GOT24
02578                      || r_type == R_M32R_GOT16_HI_ULO
02579                      || r_type == R_M32R_GOT16_HI_SLO
02580                      || r_type == R_M32R_GOT16_LO)
02581                     && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
02582                                                    info->shared, h)
02583                     && (! info->shared
02584                        || (! info->symbolic && h->dynindx != -1)
02585                        || !h->def_regular))
02586                 || (info->shared
02587                     && ((! info->symbolic && h->dynindx != -1)
02588                        || !h->def_regular)
02589                     && (((r_type == R_M32R_16_RELA
02590                          || r_type == R_M32R_32_RELA
02591                          || r_type == R_M32R_24_RELA
02592                          || r_type == R_M32R_HI16_ULO_RELA
02593                          || r_type == R_M32R_HI16_SLO_RELA
02594                          || r_type == R_M32R_LO16_RELA)
02595                         && !h->forced_local)
02596                        || r_type == R_M32R_REL32
02597                        || r_type == R_M32R_10_PCREL_RELA
02598                        || r_type == R_M32R_18_PCREL_RELA
02599                        || r_type == R_M32R_26_PCREL_RELA)
02600                     && ((input_section->flags & SEC_ALLOC) != 0
02601                        /* DWARF will emit R_M32R_16(24,32) relocations
02602                           in its sections against symbols defined
02603                           externally in shared libraries.  We can't do
02604                           anything with them here.  */
02605                        || ((input_section->flags & SEC_DEBUGGING) != 0
02606                            && h->def_dynamic))))
02607               {
02608                 /* In these cases, we don't need the relocation
02609                    value.  We check specially because in some
02610                    obscure cases sec->output_section will be NULL.  */
02611               }
02612              else if (sec->output_section != NULL)
02613               relocation = (h->root.u.def.value
02614                            + sec->output_section->vma
02615                            + sec->output_offset);
02616              else if (!info->relocatable)
02617               {
02618                 (*_bfd_error_handler)
02619                   (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
02620                    input_bfd,
02621                    input_section,
02622                    (long) rel->r_offset,
02623                    howto->name,
02624                    h->root.root.string);
02625               }
02626            }
02627          else if (h->root.type == bfd_link_hash_undefweak)
02628            ;
02629          else if (info->unresolved_syms_in_objects == RM_IGNORE
02630                  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
02631            ;
02632          else if (!info->relocatable)
02633            {
02634              if (! ((*info->callbacks->undefined_symbol)
02635                    (info, h->root.root.string, input_bfd,
02636                     input_section, offset,
02637                     (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
02638                      || ELF_ST_VISIBILITY (h->other)))))
02639               return FALSE;
02640            }
02641        }
02642 
02643       if (sec != NULL && elf_discarded_section (sec))
02644        {
02645          /* For relocs against symbols from removed linkonce sections,
02646             or sections discarded by a linker script, we just want the
02647             section contents zeroed.  Avoid any special processing.  */
02648          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
02649          rel->r_info = 0;
02650          rel->r_addend = 0;
02651          continue;
02652        }
02653 
02654       if (info->relocatable && !use_rel)
02655        {
02656          /* This is a relocatable link.  We don't have to change
02657             anything, unless the reloc is against a section symbol,
02658             in which case we have to adjust according to where the
02659             section symbol winds up in the output section.  */
02660          if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
02661            rel->r_addend += sec->output_offset;
02662          continue;
02663        }
02664 
02665       if (info->relocatable && use_rel)
02666        {
02667          /* This is a relocatable link.  We don't have to change
02668             anything, unless the reloc is against a section symbol,
02669             in which case we have to adjust according to where the
02670             section symbol winds up in the output section.  */
02671          if (sym == NULL || ELF_ST_TYPE (sym->st_info) != STT_SECTION)
02672            continue;
02673 
02674          addend += sec->output_offset;
02675 
02676          /* If partial_inplace, we need to store any additional addend
02677             back in the section.  */
02678          if (! howto->partial_inplace)
02679            continue;
02680          /* ??? Here is a nice place to call a special_function
02681             like handler.  */
02682          if (r_type != R_M32R_HI16_SLO && r_type != R_M32R_HI16_ULO)
02683            r = _bfd_relocate_contents (howto, input_bfd,
02684                                    addend, contents + offset);
02685          else
02686            {
02687              Elf_Internal_Rela *lorel;
02688 
02689              /* We allow an arbitrary number of HI16 relocs before the
02690                LO16 reloc.  This permits gcc to emit the HI and LO relocs
02691                itself.  */
02692              for (lorel = rel + 1;
02693                  (lorel < relend
02694                   && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
02695                      || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
02696                  lorel++)
02697               continue;
02698              if (lorel < relend
02699                 && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
02700               {
02701                 m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
02702                                      contents, addend);
02703                 r = bfd_reloc_ok;
02704               }
02705              else
02706               r = _bfd_relocate_contents (howto, input_bfd,
02707                                        addend, contents + offset);
02708            }
02709        }
02710       else
02711        {
02712          /* Sanity check the address.  */
02713          if (offset > high_address)
02714            {
02715              r = bfd_reloc_outofrange;
02716              goto check_reloc;
02717            }
02718 
02719          switch ((int) r_type)
02720            {
02721             case R_M32R_GOTOFF:
02722               /* Relocation is relative to the start of the global offset
02723                  table (for ld24 rx, #uimm24). eg access at label+addend
02724 
02725                  ld24 rx. #label@GOTOFF + addend
02726                  sub  rx, r12.  */
02727 
02728               BFD_ASSERT (sgot != NULL);
02729 
02730               relocation = -(relocation - sgot->output_section->vma);
02731               rel->r_addend = -rel->r_addend;
02732               break;
02733 
02734             case R_M32R_GOTOFF_HI_ULO:
02735             case R_M32R_GOTOFF_HI_SLO:
02736             case R_M32R_GOTOFF_LO:
02737              BFD_ASSERT (sgot != NULL);
02738 
02739              relocation -= sgot->output_section->vma;
02740 
02741              if ((r_type == R_M32R_GOTOFF_HI_SLO)
02742                 && ((relocation + rel->r_addend) & 0x8000))
02743               rel->r_addend += 0x10000;
02744              break;
02745 
02746             case R_M32R_GOTPC24:
02747               /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
02748                  ld24 rx,#_GLOBAL_OFFSET_TABLE_
02749                */
02750              relocation = sgot->output_section->vma;
02751              break;
02752 
02753             case R_M32R_GOTPC_HI_ULO:
02754             case R_M32R_GOTPC_HI_SLO:
02755             case R_M32R_GOTPC_LO:
02756               {
02757                 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
02758                    bl .+4
02759                    seth rx,#high(_GLOBAL_OFFSET_TABLE_)
02760                    or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
02761                    or
02762                    bl .+4
02763                    seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
02764                    add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
02765                  */
02766                 relocation = sgot->output_section->vma;
02767                 relocation -= (input_section->output_section->vma
02768                                + input_section->output_offset
02769                                + rel->r_offset);
02770                 if ((r_type == R_M32R_GOTPC_HI_SLO)
02771                      && ((relocation + rel->r_addend) & 0x8000))
02772                   rel->r_addend += 0x10000;
02773 
02774                 break;
02775               }
02776             case R_M32R_GOT16_HI_ULO:
02777             case R_M32R_GOT16_HI_SLO:
02778             case R_M32R_GOT16_LO:
02779               /* Fall through.  */
02780             case R_M32R_GOT24:
02781               /* Relocation is to the entry for this symbol in the global
02782                  offset table.  */
02783               BFD_ASSERT (sgot != NULL);
02784 
02785               if (h != NULL)
02786                 {
02787                   bfd_boolean dyn;
02788                   bfd_vma off;
02789 
02790                   off = h->got.offset;
02791                   BFD_ASSERT (off != (bfd_vma) -1);
02792 
02793                   dyn = htab->root.dynamic_sections_created;
02794                   if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
02795                       || (info->shared
02796                           && (info->symbolic
02797                               || h->dynindx == -1
02798                               || h->forced_local)
02799                           && h->def_regular))
02800                     {
02801                       /* This is actually a static link, or it is a
02802                          -Bsymbolic link and the symbol is defined
02803                          locally, or the symbol was forced to be local
02804                          because of a version file.  We must initialize
02805                          this entry in the global offset table.  Since the
02806                          offset must always be a multiple of 4, we use the
02807                          least significant bit to record whether we have
02808                          initialized it already.
02809 
02810                          When doing a dynamic link, we create a .rela.got
02811                          relocation entry to initialize the value.  This
02812                          is done in the finish_dynamic_symbol routine.  */
02813                       if ((off & 1) != 0)
02814                         off &= ~1;
02815                       else
02816                         {
02817                           bfd_put_32 (output_bfd, relocation,
02818                                       sgot->contents + off);
02819                           h->got.offset |= 1;
02820                         }
02821                     }
02822 
02823                   relocation = sgot->output_offset + off;
02824                 }
02825               else
02826                 {
02827                   bfd_vma off;
02828                   bfd_byte *loc;
02829 
02830                   BFD_ASSERT (local_got_offsets != NULL
02831                               && local_got_offsets[r_symndx] != (bfd_vma) -1);
02832 
02833                   off = local_got_offsets[r_symndx];
02834 
02835                   /* The offset must always be a multiple of 4.  We use
02836                      the least significant bit to record whether we have
02837                      already processed this entry.  */
02838                   if ((off & 1) != 0)
02839                     off &= ~1;
02840                   else
02841                     {
02842                       bfd_put_32 (output_bfd, relocation, sgot->contents + off);
02843 
02844                       if (info->shared)
02845                         {
02846                           asection *srelgot;
02847                           Elf_Internal_Rela outrel;
02848 
02849                           /* We need to generate a R_M32R_RELATIVE reloc
02850                              for the dynamic linker.  */
02851                           srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
02852                           BFD_ASSERT (srelgot != NULL);
02853 
02854                           outrel.r_offset = (sgot->output_section->vma
02855                                              + sgot->output_offset
02856                                              + off);
02857                           outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
02858                           outrel.r_addend = relocation;
02859                           loc = srelgot->contents;
02860                           loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
02861                           bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
02862                           ++srelgot->reloc_count;
02863                         }
02864 
02865                       local_got_offsets[r_symndx] |= 1;
02866                     }
02867 
02868                   relocation = sgot->output_offset + off;
02869                 }
02870               if ((r_type == R_M32R_GOT16_HI_SLO)
02871                   && ((relocation + rel->r_addend) & 0x8000))
02872                 rel->r_addend += 0x10000;
02873 
02874               break;
02875 
02876             case R_M32R_26_PLTREL:
02877               /* Relocation is to the entry for this symbol in the
02878                  procedure linkage table.  */
02879 
02880               /* The native assembler will generate a 26_PLTREL reloc
02881                  for a local symbol if you assemble a call from one
02882                  section to another when using -K pic. */
02883               if (h == NULL)
02884                 break;
02885 
02886               if (h->forced_local)
02887                 break;
02888 
02889               if (h->plt.offset == (bfd_vma) -1)
02890               /* We didn't make a PLT entry for this symbol.  This
02891                  happens when statically linking PIC code, or when
02892                  using -Bsymbolic.  */
02893               break;
02894 
02895               relocation = (splt->output_section->vma
02896                             + splt->output_offset
02897                             + h->plt.offset);
02898               break;
02899 
02900             case R_M32R_HI16_SLO_RELA:
02901              if ((relocation + rel->r_addend) & 0x8000)
02902               rel->r_addend += 0x10000;
02903               /* Fall through.  */
02904 
02905             case R_M32R_16_RELA:
02906             case R_M32R_24_RELA:
02907             case R_M32R_32_RELA:
02908             case R_M32R_REL32:
02909            case R_M32R_10_PCREL_RELA:
02910             case R_M32R_18_PCREL_RELA:
02911             case R_M32R_26_PCREL_RELA:
02912             case R_M32R_HI16_ULO_RELA:
02913             case R_M32R_LO16_RELA:
02914               if (info->shared
02915                   && r_symndx != 0
02916                   && (input_section->flags & SEC_ALLOC) != 0
02917                   && ((   r_type != R_M32R_10_PCREL_RELA
02918                        && r_type != R_M32R_18_PCREL_RELA
02919                        && r_type != R_M32R_26_PCREL_RELA
02920                        && r_type != R_M32R_REL32)
02921                       || (h != NULL
02922                           && h->dynindx != -1
02923                           && (! info->symbolic
02924                               || !h->def_regular))))
02925                 {
02926                   Elf_Internal_Rela outrel;
02927                   bfd_boolean skip, relocate;
02928                   bfd_byte *loc;
02929 
02930                   /* When generating a shared object, these relocations
02931                      are copied into the output file to be resolved at run
02932                      time.  */
02933                   if (sreloc == NULL)
02934                     {
02935                       const char *name;
02936 
02937                       name = (bfd_elf_string_from_elf_section
02938                               (input_bfd,
02939                                elf_elfheader (input_bfd)->e_shstrndx,
02940                                elf_section_data (input_section)->rel_hdr.sh_name));
02941                       if (name == NULL)
02942                         return FALSE;
02943 
02944                       BFD_ASSERT (CONST_STRNEQ (name, ".rela")
02945                                   && strcmp (bfd_get_section_name (input_bfd,
02946                                                                    input_section),
02947                                              name + 5) == 0);
02948 
02949                       sreloc = bfd_get_section_by_name (dynobj, name);
02950                       BFD_ASSERT (sreloc != NULL);
02951                     }
02952 
02953                   skip = FALSE;
02954                   relocate = FALSE;
02955 
02956                   outrel.r_offset = _bfd_elf_section_offset (output_bfd,
02957                                                              info,
02958                                                              input_section,
02959                                                              rel->r_offset);
02960                   if (outrel.r_offset == (bfd_vma) -1)
02961                     skip = TRUE;
02962                   else if (outrel.r_offset == (bfd_vma) -2)
02963                     skip = relocate = TRUE;
02964                   outrel.r_offset += (input_section->output_section->vma
02965                                       + input_section->output_offset);
02966 
02967                   if (skip)
02968                     memset (&outrel, 0, sizeof outrel);
02969                   else if (   r_type == R_M32R_10_PCREL_RELA
02970                            || r_type == R_M32R_18_PCREL_RELA
02971                            || r_type == R_M32R_26_PCREL_RELA
02972                            || r_type == R_M32R_REL32)
02973                     {
02974                       BFD_ASSERT (h != NULL && h->dynindx != -1);
02975                       outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
02976                       outrel.r_addend = rel->r_addend;
02977                     }
02978                   else
02979                     {
02980                     /* h->dynindx may be -1 if this symbol was marked to
02981                        become local.  */
02982                     if (h == NULL
02983                         || ((info->symbolic || h->dynindx == -1)
02984                              && h->def_regular))
02985                       {
02986                         relocate = TRUE;
02987                         outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
02988                         outrel.r_addend = relocation + rel->r_addend;
02989                       }
02990                     else
02991                       {
02992                         BFD_ASSERT (h->dynindx != -1);
02993                         outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
02994                         outrel.r_addend = relocation + rel->r_addend;
02995                       }
02996                     }
02997 
02998                   loc = sreloc->contents;
02999                   loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
03000                   bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
03001                   ++sreloc->reloc_count;
03002 
03003                   /* If this reloc is against an external symbol, we do
03004                      not want to fiddle with the addend.  Otherwise, we
03005                      need to include the symbol value so that it becomes
03006                      an addend for the dynamic reloc.  */
03007                   if (! relocate)
03008                     continue;
03009                 break;
03010                 }
03011              else if (r_type != R_M32R_10_PCREL_RELA)
03012               break;
03013              /* Fall through.  */
03014 
03015            case (int) R_M32R_10_PCREL :
03016              r = m32r_elf_do_10_pcrel_reloc (input_bfd, howto, input_section,
03017                                          contents, offset,
03018                                          sec, relocation, addend);
03019               goto check_reloc;
03020 
03021            case (int) R_M32R_HI16_SLO :
03022            case (int) R_M32R_HI16_ULO :
03023              {
03024               Elf_Internal_Rela *lorel;
03025 
03026               /* We allow an arbitrary number of HI16 relocs before the
03027                  LO16 reloc.  This permits gcc to emit the HI and LO relocs
03028                  itself.  */
03029               for (lorel = rel + 1;
03030                    (lorel < relend
03031                     && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
03032                        || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
03033                    lorel++)
03034                 continue;
03035               if (lorel < relend
03036                   && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
03037                 {
03038                   m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
03039                                        contents, relocation + addend);
03040                   r = bfd_reloc_ok;
03041                 }
03042               else
03043                 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
03044                                           contents, offset,
03045                                           relocation, addend);
03046              }
03047 
03048               goto check_reloc;
03049 
03050             case (int) R_M32R_SDA16_RELA:
03051            case (int) R_M32R_SDA16 :
03052              {
03053               const char *name;
03054 
03055               BFD_ASSERT (sec != NULL);
03056               name = bfd_get_section_name (abfd, sec);
03057 
03058               if (   strcmp (name, ".sdata") == 0
03059                   || strcmp (name, ".sbss") == 0
03060                   || strcmp (name, ".scommon") == 0)
03061                 {
03062                   bfd_vma sda_base;
03063                   bfd *out_bfd = sec->output_section->owner;
03064 
03065                   r = m32r_elf_final_sda_base (out_bfd, info,
03066                                            &errmsg,
03067                                            &sda_base);
03068                   if (r != bfd_reloc_ok)
03069                     {
03070                      ret = FALSE;
03071                      goto check_reloc;
03072                     }
03073 
03074                   /* At this point `relocation' contains the object's
03075                      address.  */
03076                   relocation -= sda_base;
03077                   /* Now it contains the offset from _SDA_BASE_.  */
03078                 }
03079               else
03080                 {
03081                   (*_bfd_error_handler)
03082                     (_("%B: The target (%s) of an %s relocation is in the wrong section (%A)"),
03083                      input_bfd,
03084                      sec,
03085                      sym_name,
03086                      m32r_elf_howto_table[(int) r_type].name);
03087                   /*bfd_set_error (bfd_error_bad_value); ??? why? */
03088                   ret = FALSE;
03089                   continue;
03090                 }
03091              }
03092               /* Fall through.  */
03093 
03094            default : /* OLD_M32R_RELOC */
03095 
03096              r = _bfd_final_link_relocate (howto, input_bfd, input_section,
03097                                        contents, offset,
03098                                        relocation, addend);
03099              goto check_reloc;
03100            }
03101 
03102           r = _bfd_final_link_relocate (howto, input_bfd, input_section,
03103                                         contents, rel->r_offset,
03104                                         relocation, rel->r_addend);
03105 
03106        }
03107 
03108     check_reloc:
03109 
03110       if (r != bfd_reloc_ok)
03111        {
03112          /* FIXME: This should be generic enough to go in a utility.  */
03113          const char *name;
03114 
03115          if (h != NULL)
03116            name = h->root.root.string;
03117          else
03118            {
03119              name = (bfd_elf_string_from_elf_section
03120                     (input_bfd, symtab_hdr->sh_link, sym->st_name));
03121              if (name == NULL || *name == '\0')
03122               name = bfd_section_name (input_bfd, sec);
03123            }
03124 
03125          if (errmsg != NULL)
03126            goto common_error;
03127 
03128          switch (r)
03129            {
03130            case bfd_reloc_overflow:
03131              if (! ((*info->callbacks->reloc_overflow)
03132                    (info, (h ? &h->root : NULL), name, howto->name,
03133                     (bfd_vma) 0, input_bfd, input_section, offset)))
03134               return FALSE;
03135              break;
03136 
03137            case bfd_reloc_undefined:
03138              if (! ((*info->callbacks->undefined_symbol)
03139                    (info, name, input_bfd, input_section,
03140                     offset, TRUE)))
03141               return FALSE;
03142              break;
03143 
03144            case bfd_reloc_outofrange:
03145              errmsg = _("internal error: out of range error");
03146              goto common_error;
03147 
03148            case bfd_reloc_notsupported:
03149              errmsg = _("internal error: unsupported relocation error");
03150              goto common_error;
03151 
03152            case bfd_reloc_dangerous:
03153              errmsg = _("internal error: dangerous error");
03154              goto common_error;
03155 
03156            default:
03157              errmsg = _("internal error: unknown error");
03158              /* fall through */
03159 
03160            common_error:
03161              if (!((*info->callbacks->warning)
03162                   (info, errmsg, name, input_bfd, input_section,
03163                    offset)))
03164               return FALSE;
03165              break;
03166            }
03167        }
03168     }
03169 
03170   return ret;
03171 }
03172 
03173 /* Finish up dynamic symbol handling.  We set the contents of various
03174    dynamic sections here.  */
03175 
03176 static bfd_boolean
03177 m32r_elf_finish_dynamic_symbol (bfd *output_bfd,
03178                             struct bfd_link_info *info,
03179                             struct elf_link_hash_entry *h,
03180                             Elf_Internal_Sym *sym)
03181 {
03182   struct elf_m32r_link_hash_table *htab;
03183   bfd *dynobj;
03184   bfd_byte *loc;
03185 
03186 #ifdef DEBUG_PIC
03187   printf ("m32r_elf_finish_dynamic_symbol()\n");
03188 #endif
03189 
03190   htab = m32r_elf_hash_table (info);
03191   dynobj = htab->root.dynobj;
03192 
03193   if (h->plt.offset != (bfd_vma) -1)
03194     {
03195       asection *splt;
03196       asection *sgot;
03197       asection *srela;
03198 
03199       bfd_vma plt_index;
03200       bfd_vma got_offset;
03201       Elf_Internal_Rela rela;
03202 
03203       /* This symbol has an entry in the procedure linkage table.  Set
03204          it up.  */
03205 
03206       BFD_ASSERT (h->dynindx != -1);
03207 
03208       splt = htab->splt;
03209       sgot = htab->sgotplt;
03210       srela = htab->srelplt;
03211       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
03212 
03213       /* Get the index in the procedure linkage table which
03214          corresponds to this symbol.  This is the index of this symbol
03215          in all the symbols for which we are making plt entries.  The
03216          first entry in the procedure linkage table is reserved.  */
03217       plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
03218 
03219       /* Get the offset into the .got table of the entry that
03220         corresponds to this function.  Each .got entry is 4 bytes.
03221         The first three are reserved.  */
03222       got_offset = (plt_index + 3) * 4;
03223 
03224       /* Fill in the entry in the procedure linkage table.  */
03225       if (! info->shared)
03226         {
03227           bfd_put_32 (output_bfd,
03228               (PLT_ENTRY_WORD0b
03229                + (((sgot->output_section->vma
03230                     + sgot->output_offset
03231                     + got_offset) >> 16) & 0xffff)),
03232               splt->contents + h->plt.offset);
03233           bfd_put_32 (output_bfd,
03234               (PLT_ENTRY_WORD1b
03235                + ((sgot->output_section->vma
03236                    + sgot->output_offset
03237                    + got_offset) & 0xffff)),
03238               splt->contents + h->plt.offset + 4);
03239           bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
03240               splt->contents + h->plt.offset + 8);
03241           bfd_put_32 (output_bfd,
03242               (PLT_ENTRY_WORD3
03243                + plt_index * sizeof (Elf32_External_Rela)),
03244               splt->contents + h->plt.offset + 12);
03245           bfd_put_32 (output_bfd,
03246               (PLT_ENTRY_WORD4
03247                + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
03248               splt->contents + h->plt.offset + 16);
03249         }
03250       else
03251         {
03252           bfd_put_32 (output_bfd,
03253               PLT_ENTRY_WORD0 + got_offset,
03254               splt->contents + h->plt.offset);
03255           bfd_put_32 (output_bfd, PLT_ENTRY_WORD1,
03256               splt->contents + h->plt.offset + 4);
03257           bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
03258               splt->contents + h->plt.offset + 8);
03259           bfd_put_32 (output_bfd,
03260               (PLT_ENTRY_WORD3
03261                + plt_index * sizeof (Elf32_External_Rela)),
03262               splt->contents + h->plt.offset + 12);
03263           bfd_put_32 (output_bfd,
03264               (PLT_ENTRY_WORD4
03265                + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
03266               splt->contents + h->plt.offset + 16);
03267         }
03268 
03269       /* Fill in the entry in the global offset table.  */
03270       bfd_put_32 (output_bfd,
03271                   (splt->output_section->vma
03272                    + splt->output_offset
03273                    + h->plt.offset
03274                    + 12), /* same offset */
03275                   sgot->contents + got_offset);
03276 
03277       /* Fill in the entry in the .rela.plt section.  */
03278       rela.r_offset = (sgot->output_section->vma
03279                        + sgot->output_offset
03280                        + got_offset);
03281       rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_JMP_SLOT);
03282       rela.r_addend = 0;
03283       loc = srela->contents;
03284       loc += plt_index * sizeof (Elf32_External_Rela);
03285       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
03286 
03287       if (!h->def_regular)
03288         {
03289           /* Mark the symbol as undefined, rather than as defined in
03290              the .plt section.  Leave the value alone.  */
03291           sym->st_shndx = SHN_UNDEF;
03292         }
03293     }
03294 
03295   if (h->got.offset != (bfd_vma) -1)
03296     {
03297       asection *sgot;
03298       asection *srela;
03299       Elf_Internal_Rela rela;
03300 
03301       /* This symbol has an entry in the global offset table.  Set it
03302          up.  */
03303 
03304       sgot = htab->sgot;
03305       srela = htab->srelgot;
03306       BFD_ASSERT (sgot != NULL && srela != NULL);
03307 
03308       rela.r_offset = (sgot->output_section->vma
03309                        + sgot->output_offset
03310                        + (h->got.offset &~ 1));
03311 
03312       /* If this is a -Bsymbolic link, and the symbol is defined
03313          locally, we just want to emit a RELATIVE reloc.  Likewise if
03314          the symbol was forced to be local because of a version file.
03315          The entry in the global offset table will already have been
03316          initialized in the relocate_section function.  */
03317       if (info->shared
03318           && (info->symbolic
03319              || h->dynindx == -1
03320              || h->forced_local)
03321           && h->def_regular)
03322         {
03323           rela.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
03324           rela.r_addend = (h->root.u.def.value
03325                            + h->root.u.def.section->output_section->vma
03326                            + h->root.u.def.section->output_offset);
03327         }
03328       else
03329         {
03330          BFD_ASSERT ((h->got.offset & 1) == 0);
03331           bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
03332           rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_GLOB_DAT);
03333           rela.r_addend = 0;
03334         }
03335 
03336       loc = srela->contents;
03337       loc += srela->reloc_count * sizeof (Elf32_External_Rela);
03338       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
03339       ++srela->reloc_count;
03340     }
03341 
03342   if (h->needs_copy)
03343     {
03344       asection *s;
03345       Elf_Internal_Rela rela;
03346 
03347       /* This symbols needs a copy reloc.  Set it up.  */
03348 
03349       BFD_ASSERT (h->dynindx != -1
03350                   && (h->root.type == bfd_link_hash_defined
03351                       || h->root.type == bfd_link_hash_defweak));
03352 
03353       s = bfd_get_section_by_name (h->root.u.def.section->owner,
03354                                    ".rela.bss");
03355       BFD_ASSERT (s != NULL);
03356 
03357       rela.r_offset = (h->root.u.def.value
03358                        + h->root.u.def.section->output_section->vma
03359                        + h->root.u.def.section->output_offset);
03360       rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_COPY);
03361       rela.r_addend = 0;
03362       loc = s->contents;
03363       loc += s->reloc_count * sizeof (Elf32_External_Rela);
03364       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
03365       ++s->reloc_count;
03366     }
03367 
03368   /* Mark some specially defined symbols as absolute.  */
03369   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
03370       || h == htab->root.hgot)
03371     sym->st_shndx = SHN_ABS;
03372 
03373   return TRUE;
03374 }
03375 
03376 
03377 /* Finish up the dynamic sections.  */
03378 
03379 static bfd_boolean
03380 m32r_elf_finish_dynamic_sections (bfd *output_bfd,
03381                               struct bfd_link_info *info)
03382 {
03383   struct elf_m32r_link_hash_table *htab;
03384   bfd *dynobj;
03385   asection *sdyn;
03386   asection *sgot;
03387 
03388 #ifdef DEBUG_PIC
03389   printf ("m32r_elf_finish_dynamic_sections()\n");
03390 #endif
03391 
03392   htab = m32r_elf_hash_table (info);
03393   dynobj = htab->root.dynobj;
03394 
03395   sgot = htab->sgotplt;
03396   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
03397 
03398   if (htab->root.dynamic_sections_created)
03399     {
03400       asection *splt;
03401       Elf32_External_Dyn *dyncon, *dynconend;
03402 
03403       BFD_ASSERT (sgot != NULL && sdyn != NULL);
03404 
03405       dyncon = (Elf32_External_Dyn *) sdyn->contents;
03406       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
03407 
03408       for (; dyncon < dynconend; dyncon++)
03409         {
03410           Elf_Internal_Dyn dyn;
03411           const char *name;
03412           asection *s;
03413 
03414           bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
03415 
03416           switch (dyn.d_tag)
03417             {
03418             default:
03419               break;
03420 
03421             case DT_PLTGOT:
03422               name = ".got";
03423               s = htab->sgot->output_section;
03424               goto get_vma;
03425             case DT_JMPREL:
03426               name = ".rela.plt";
03427               s = htab->srelplt->output_section;
03428             get_vma:
03429               BFD_ASSERT (s != NULL);
03430               dyn.d_un.d_ptr = s->vma;
03431               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
03432               break;
03433 
03434             case DT_PLTRELSZ:
03435               s = htab->srelplt->output_section;
03436               BFD_ASSERT (s != NULL);
03437              dyn.d_un.d_val = s->size;
03438               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
03439               break;
03440 
03441             case DT_RELASZ:
03442               /* My reading of the SVR4 ABI indicates that the
03443                  procedure linkage table relocs (DT_JMPREL) should be
03444                  included in the overall relocs (DT_RELA).  This is
03445                  what Solaris does.  However, UnixWare can not handle
03446                  that case.  Therefore, we override the DT_RELASZ entry
03447                  here to make it not include the JMPREL relocs.  Since
03448                  the linker script arranges for .rela.plt to follow all
03449                  other relocation sections, we don't have to worry
03450                  about changing the DT_RELA entry.  */
03451               if (htab->srelplt != NULL)
03452                 {
03453                   s = htab->srelplt->output_section;
03454                 dyn.d_un.d_val -= s->size;
03455                 }
03456               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
03457               break;
03458             }
03459         }
03460 
03461       /* Fill in the first entry in the procedure linkage table.  */
03462       splt = htab->splt;
03463       if (splt && splt->size > 0)
03464         {
03465           if (info->shared)
03466             {
03467               bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents);
03468               bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4);
03469               bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2, splt->contents + 8);
03470               bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3, splt->contents + 12);
03471               bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4, splt->contents + 16);
03472             }
03473           else
03474             {
03475               unsigned long addr;
03476               /* addr = .got + 4 */
03477               addr = sgot->output_section->vma + sgot->output_offset + 4;
03478               bfd_put_32 (output_bfd,
03479                        PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
03480                        splt->contents);
03481               bfd_put_32 (output_bfd,
03482                        PLT0_ENTRY_WORD1 | (addr & 0xffff),
03483                        splt->contents + 4);
03484               bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
03485               bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
03486               bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
03487             }
03488 
03489           elf_section_data (splt->output_section)->this_hdr.sh_entsize =
03490             PLT_ENTRY_SIZE;
03491         }
03492     }
03493 
03494   /* Fill in the first three entries in the global offset table.  */
03495   if (sgot && sgot->size > 0)
03496     {
03497       if (sdyn == NULL)
03498         bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
03499       else
03500         bfd_put_32 (output_bfd,
03501                     sdyn->output_section->vma + sdyn->output_offset,
03502                     sgot->contents);
03503       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
03504       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
03505 
03506       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
03507     }
03508 
03509   return TRUE;
03510 }
03511 
03512 
03513 /* Set the right machine number.  */
03514 
03515 static bfd_boolean
03516 m32r_elf_object_p (bfd *abfd)
03517 {
03518   switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
03519     {
03520     default:
03521     case E_M32R_ARCH:   (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r);  break;
03522     case E_M32RX_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;
03523     case E_M32R2_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r2); break;
03524     }
03525   return TRUE;
03526 }
03527 
03528 /* Store the machine number in the flags field.  */
03529 
03530 static void
03531 m32r_elf_final_write_processing (bfd *abfd,
03532                              bfd_boolean linker ATTRIBUTE_UNUSED)
03533 {
03534   unsigned long val;
03535 
03536   switch (bfd_get_mach (abfd))
03537     {
03538     default:
03539     case bfd_mach_m32r:  val = E_M32R_ARCH; break;
03540     case bfd_mach_m32rx: val = E_M32RX_ARCH; break;
03541     case bfd_mach_m32r2: val = E_M32R2_ARCH; break;
03542     }
03543 
03544   elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;
03545   elf_elfheader (abfd)->e_flags |= val;
03546 }
03547 
03548 /* Function to keep M32R specific file flags.  */
03549 
03550 static bfd_boolean
03551 m32r_elf_set_private_flags (bfd *abfd, flagword flags)
03552 {
03553   BFD_ASSERT (!elf_flags_init (abfd)
03554              || elf_elfheader (abfd)->e_flags == flags);
03555 
03556   elf_elfheader (abfd)->e_flags = flags;
03557   elf_flags_init (abfd) = TRUE;
03558   return TRUE;
03559 }
03560 
03561 /* Merge backend specific data from an object file to the output
03562    object file when linking.  */
03563 
03564 static bfd_boolean
03565 m32r_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
03566 {
03567   flagword out_flags;
03568   flagword in_flags;
03569 
03570   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
03571       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
03572     return TRUE;
03573 
03574   in_flags  = elf_elfheader (ibfd)->e_flags;
03575   out_flags = elf_elfheader (obfd)->e_flags;
03576 
03577   if (! elf_flags_init (obfd))
03578     {
03579       /* If the input is the default architecture then do not
03580         bother setting the flags for the output architecture,
03581         instead allow future merges to do this.  If no future
03582         merges ever set these flags then they will retain their
03583         unitialised values, which surprise surprise, correspond
03584         to the default values.  */
03585       if (bfd_get_arch_info (ibfd)->the_default)
03586        return TRUE;
03587 
03588       elf_flags_init (obfd) = TRUE;
03589       elf_elfheader (obfd)->e_flags = in_flags;
03590 
03591       if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
03592          && bfd_get_arch_info (obfd)->the_default)
03593        return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
03594                               bfd_get_mach (ibfd));
03595 
03596       return TRUE;
03597     }
03598 
03599   /* Check flag compatibility.  */
03600   if (in_flags == out_flags)
03601     return TRUE;
03602 
03603   if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))
03604     {
03605       if (   ((in_flags  & EF_M32R_ARCH) != E_M32R_ARCH)
03606           || ((out_flags & EF_M32R_ARCH) == E_M32R_ARCH)
03607           || ((in_flags  & EF_M32R_ARCH) == E_M32R2_ARCH))
03608        {
03609          (*_bfd_error_handler)
03610            (_("%B: Instruction set mismatch with previous modules"), ibfd);
03611 
03612          bfd_set_error (bfd_error_bad_value);
03613          return FALSE;
03614        }
03615     }
03616 
03617   return TRUE;
03618 }
03619 
03620 /* Display the flags field.  */
03621 
03622 static bfd_boolean
03623 m32r_elf_print_private_bfd_data (bfd *abfd, void * ptr)
03624 {
03625   FILE * file = (FILE *) ptr;
03626 
03627   BFD_ASSERT (abfd != NULL && ptr != NULL);
03628 
03629   _bfd_elf_print_private_bfd_data (abfd, ptr);
03630 
03631   fprintf (file, _("private flags = %lx"), elf_elfheader (abfd)->e_flags);
03632 
03633   switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
03634     {
03635     default:
03636     case E_M32R_ARCH:  fprintf (file, _(": m32r instructions"));  break;
03637     case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;
03638     case E_M32R2_ARCH: fprintf (file, _(": m32r2 instructions")); break;
03639     }
03640 
03641   fputc ('\n', file);
03642 
03643   return TRUE;
03644 }
03645 
03646 static asection *
03647 m32r_elf_gc_mark_hook (asection *sec,
03648                      struct bfd_link_info *info,
03649                      Elf_Internal_Rela *rel,
03650                      struct elf_link_hash_entry *h,
03651                      Elf_Internal_Sym *sym)
03652 {
03653   if (h != NULL)
03654     switch (ELF32_R_TYPE (rel->r_info))
03655       {
03656       case R_M32R_GNU_VTINHERIT:
03657       case R_M32R_GNU_VTENTRY:
03658       case R_M32R_RELA_GNU_VTINHERIT:
03659       case R_M32R_RELA_GNU_VTENTRY:
03660        return NULL;
03661       }
03662 
03663   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
03664 }
03665 
03666 static bfd_boolean
03667 m32r_elf_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED,
03668                      struct bfd_link_info *info ATTRIBUTE_UNUSED,
03669                      asection *sec ATTRIBUTE_UNUSED,
03670                      const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED)
03671 {
03672   /* Update the got entry reference counts for the section being removed.  */
03673   Elf_Internal_Shdr *symtab_hdr;
03674   struct elf_link_hash_entry **sym_hashes;
03675   bfd_signed_vma *local_got_refcounts;
03676   const Elf_Internal_Rela *rel, *relend;
03677 
03678   elf_section_data (sec)->local_dynrel = NULL;
03679 
03680   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
03681   sym_hashes = elf_sym_hashes (abfd);
03682   local_got_refcounts = elf_local_got_refcounts (abfd);
03683 
03684   relend = relocs + sec->reloc_count;
03685   for (rel = relocs; rel < relend; rel++)
03686     {
03687       unsigned long r_symndx;
03688       struct elf_link_hash_entry *h = NULL;
03689 
03690       r_symndx = ELF32_R_SYM (rel->r_info);
03691       if (r_symndx >= symtab_hdr->sh_info)
03692        {
03693          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
03694          while (h->root.type == bfd_link_hash_indirect
03695                || h->root.type == bfd_link_hash_warning)
03696            h = (struct elf_link_hash_entry *) h->root.u.i.link;
03697        }
03698 
03699       switch (ELF32_R_TYPE (rel->r_info))
03700        {
03701        case R_M32R_GOT16_HI_ULO:
03702        case R_M32R_GOT16_HI_SLO:
03703        case R_M32R_GOT16_LO:
03704        case R_M32R_GOTOFF:
03705        case R_M32R_GOTOFF_HI_ULO:
03706        case R_M32R_GOTOFF_HI_SLO:
03707        case R_M32R_GOTOFF_LO:
03708        case R_M32R_GOT24:
03709        case R_M32R_GOTPC_HI_ULO:
03710        case R_M32R_GOTPC_HI_SLO:
03711        case R_M32R_GOTPC_LO:
03712        case R_M32R_GOTPC24:
03713          if (h != NULL)
03714            {
03715              if (h->got.refcount > 0)
03716               h->got.refcount--;
03717            }
03718          else
03719            {
03720              if (local_got_refcounts && local_got_refcounts[r_symndx] > 0)
03721               local_got_refcounts[r_symndx]--;
03722            }
03723          break;
03724 
03725        case R_M32R_16_RELA:
03726        case R_M32R_24_RELA:
03727        case R_M32R_32_RELA:
03728        case R_M32R_REL32:
03729        case R_M32R_HI16_ULO_RELA:
03730        case R_M32R_HI16_SLO_RELA:
03731        case R_M32R_LO16_RELA:
03732        case R_M32R_SDA16_RELA:
03733        case R_M32R_10_PCREL_RELA:
03734        case R_M32R_18_PCREL_RELA:
03735        case R_M32R_26_PCREL_RELA:
03736          if (h != NULL)
03737            {
03738              struct elf_m32r_link_hash_entry *eh;
03739              struct elf_m32r_dyn_relocs **pp;
03740              struct elf_m32r_dyn_relocs *p;
03741 
03742              if (!info->shared && h->plt.refcount > 0)
03743               h->plt.refcount -= 1;
03744 
03745              eh = (struct elf_m32r_link_hash_entry *) h;
03746 
03747              for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
03748               if (p->sec == sec)
03749                 {
03750                   if (   ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
03751                      || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA
03752                      || ELF32_R_TYPE (rel->r_info) == R_M32R_10_PCREL_RELA
03753                      || ELF32_R_TYPE (rel->r_info) == R_M32R_REL32)
03754                     p->pc_count -= 1;
03755                   p->count -= 1;
03756                   if (p->count == 0)
03757                     *pp = p->next;
03758                   break;
03759                 }
03760            }
03761          break;
03762 
03763        case R_M32R_26_PLTREL:
03764          if (h != NULL)
03765            {
03766              if (h->plt.refcount > 0)
03767               h->plt.refcount--;
03768            }
03769          break;
03770 
03771        default:
03772          break;
03773        }
03774     }
03775 
03776   return TRUE;
03777 }
03778 
03779 /* Look through the relocs for a section during the first phase.
03780    Since we don't do .gots or .plts, we just need to consider the
03781    virtual table relocs for gc.  */
03782 
03783 static bfd_boolean
03784 m32r_elf_check_relocs (bfd *abfd,
03785                      struct bfd_link_info *info,
03786                      asection *sec,
03787                      const Elf_Internal_Rela *relocs)
03788 {
03789   Elf_Internal_Shdr *symtab_hdr;
03790   struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
03791   const Elf_Internal_Rela *rel;
03792   const Elf_Internal_Rela *rel_end;
03793   struct elf_m32r_link_hash_table *htab;
03794   bfd *dynobj;
03795   bfd_vma *local_got_offsets;
03796   asection *sgot, *srelgot, *sreloc;
03797 
03798   if (info->relocatable)
03799     return TRUE;
03800 
03801   sgot = srelgot = sreloc = NULL;
03802 
03803   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
03804   sym_hashes = elf_sym_hashes (abfd);
03805   sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
03806   if (!elf_bad_symtab (abfd))
03807     sym_hashes_end -= symtab_hdr->sh_info;
03808 
03809   htab = m32r_elf_hash_table (info);
03810   dynobj = htab->root.dynobj;
03811   local_got_offsets = elf_local_got_offsets (abfd);
03812 
03813   rel_end = relocs + sec->reloc_count;
03814   for (rel = relocs; rel < rel_end; rel++)
03815     {
03816       int r_type;
03817       struct elf_link_hash_entry *h;
03818       unsigned long r_symndx;
03819 
03820       r_symndx = ELF32_R_SYM (rel->r_info);
03821       r_type = ELF32_R_TYPE (rel->r_info);
03822       if (r_symndx < symtab_hdr->sh_info)
03823         h = NULL;
03824       else
03825        {
03826          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
03827          while (h->root.type == bfd_link_hash_indirect
03828                || h->root.type == bfd_link_hash_warning)
03829            h = (struct elf_link_hash_entry *) h->root.u.i.link;
03830        }
03831 
03832       /* Some relocs require a global offset table.  */
03833       if (htab->sgot == NULL)
03834         {
03835           switch (r_type)
03836             {
03837             case R_M32R_GOT16_HI_ULO:
03838             case R_M32R_GOT16_HI_SLO:
03839             case R_M32R_GOTOFF:
03840             case R_M32R_GOTOFF_HI_ULO:
03841             case R_M32R_GOTOFF_HI_SLO:
03842             case R_M32R_GOTOFF_LO:
03843             case R_M32R_GOT16_LO:
03844             case R_M32R_GOTPC24:
03845             case R_M32R_GOTPC_HI_ULO:
03846             case R_M32R_GOTPC_HI_SLO:
03847             case R_M32R_GOTPC_LO:
03848             case R_M32R_GOT24:
03849               if (dynobj == NULL)
03850                 htab->root.dynobj = dynobj = abfd;
03851               if (! create_got_section (dynobj, info))
03852                 return FALSE;
03853               break;
03854 
03855             default:
03856               break;
03857           }
03858         }
03859 
03860       switch (r_type)
03861         {
03862        case R_M32R_GOT16_HI_ULO:
03863        case R_M32R_GOT16_HI_SLO:
03864        case R_M32R_GOT16_LO:
03865         case R_M32R_GOT24:
03866 
03867           if (h != NULL)
03868             h->got.refcount += 1;
03869           else
03870             {
03871               bfd_signed_vma *local_got_refcounts;
03872 
03873               /* This is a global offset table entry for a local
03874                  symbol.  */
03875               local_got_refcounts = elf_local_got_refcounts (abfd);
03876               if (local_got_refcounts == NULL)
03877                 {
03878                   bfd_size_type size;
03879 
03880                   size = symtab_hdr->sh_info;
03881                   size *= sizeof (bfd_signed_vma);
03882                   local_got_refcounts = bfd_zalloc (abfd, size);
03883                   if (local_got_refcounts == NULL)
03884                     return FALSE;
03885                   elf_local_got_refcounts (abfd) = local_got_refcounts;
03886                 }
03887               local_got_refcounts[r_symndx] += 1;
03888             }
03889           break;
03890 
03891         case R_M32R_26_PLTREL:
03892           /* This symbol requires a procedure linkage table entry.  We
03893              actually build the entry in adjust_dynamic_symbol,
03894              because this might be a case of linking PIC code without
03895              linking in any dynamic objects, in which case we don't
03896              need to generate a procedure linkage table after all.  */
03897 
03898          /* If this is a local symbol, we resolve it directly without
03899             creating a procedure linkage table entry.  */
03900           if (h == NULL)
03901             continue;
03902 
03903           if (h->forced_local)
03904             break;
03905 
03906           h->needs_plt = 1;
03907          h->plt.refcount += 1;
03908           break;
03909 
03910         case R_M32R_16_RELA:
03911         case R_M32R_24_RELA:
03912         case R_M32R_32_RELA:
03913         case R_M32R_REL32:
03914         case R_M32R_HI16_ULO_RELA:
03915         case R_M32R_HI16_SLO_RELA:
03916         case R_M32R_LO16_RELA:
03917         case R_M32R_SDA16_RELA:
03918        case R_M32R_10_PCREL_RELA:
03919         case R_M32R_18_PCREL_RELA:
03920         case R_M32R_26_PCREL_RELA:
03921 
03922           if (h != NULL && !info->shared)
03923             {
03924               h->non_got_ref = 1;
03925               h->plt.refcount += 1;
03926             }
03927 
03928           /* If we are creating a shared library, and this is a reloc
03929              against a global symbol, or a non PC relative reloc
03930              against a local symbol, then we need to copy the reloc
03931              into the shared library.  However, if we are linking with
03932              -Bsymbolic, we do not need to copy a reloc against a
03933              global symbol which is defined in an object we are
03934              including in the link (i.e., DEF_REGULAR is set).  At
03935              this point we have not seen all the input files, so it is
03936              possible that DEF_REGULAR is not set now but will be set
03937              later (it is never cleared).  We account for that
03938              possibility below by storing information in the
03939              dyn_relocs field of the hash table entry. A similar
03940              situation occurs when creating shared libraries and symbol
03941              visibility changes render the symbol local.
03942 
03943              If on the other hand, we are creating an executable, we
03944              may need to keep relocations for symbols satisfied by a
03945              dynamic library if we manage to avoid copy relocs for the
03946              symbol.  */
03947           if ((info->shared
03948                && (sec->flags & SEC_ALLOC) != 0
03949               && ((   r_type != R_M32R_26_PCREL_RELA
03950                     && r_type != R_M32R_18_PCREL_RELA
03951                     && r_type != R_M32R_10_PCREL_RELA
03952                     && r_type != R_M32R_REL32)
03953                   || (h != NULL
03954                      && (! info->symbolic
03955                          || h->root.type == bfd_link_hash_defweak
03956                          || !h->def_regular))))
03957               || (!info->shared
03958                   && (sec->flags & SEC_ALLOC) != 0
03959                   && h != NULL
03960                   && (h->root.type == bfd_link_hash_defweak
03961                       || !h->def_regular)))
03962             {
03963               struct elf_m32r_dyn_relocs *p;
03964               struct elf_m32r_dyn_relocs **head;
03965 
03966               if (dynobj == NULL)
03967                 htab->root.dynobj = dynobj = abfd;
03968 
03969               /* When creating a shared object, we must copy these
03970                  relocs into the output file.  We create a reloc
03971                  section in dynobj and make room for the reloc.  */
03972               if (sreloc == NULL)
03973                 {
03974                   const char *name;
03975 
03976                   name = (bfd_elf_string_from_elf_section
03977                           (abfd,
03978                            elf_elfheader (abfd)->e_shstrndx,
03979                            elf_section_data (sec)->rel_hdr.sh_name));
03980                   if (name == NULL)
03981                     return FALSE;
03982 
03983                   BFD_ASSERT (CONST_STRNEQ (name, ".rela")
03984                               && strcmp (bfd_get_section_name (abfd, sec),
03985                                          name + 5) == 0);
03986 
03987                   sreloc = bfd_get_section_by_name (dynobj, name);
03988                   if (sreloc == NULL)
03989                     {
03990                       flagword flags;
03991 
03992                       flags = (SEC_HAS_CONTENTS | SEC_READONLY
03993                                | SEC_IN_MEMORY | SEC_LINKER_CREATED);
03994                       if ((sec->flags & SEC_ALLOC) != 0)
03995                         flags |= SEC_ALLOC | SEC_LOAD;
03996                       sreloc = bfd_make_section_with_flags (dynobj,
03997                                                      name,
03998                                                      flags);
03999                       if (sreloc == NULL
04000                           || ! bfd_set_section_alignment (dynobj, sreloc, 2))
04001                         return FALSE;
04002                     }
04003                   elf_section_data (sec)->sreloc = sreloc;
04004                 }
04005 
04006               /* If this is a global symbol, we count the number of
04007                  relocations we need for this symbol.  */
04008               if (h != NULL)
04009                 head = &((struct elf_m32r_link_hash_entry *) h)->dyn_relocs;
04010               else
04011                 {
04012                   asection *s;
04013                   void *vpp;
04014 
04015                   /* Track dynamic relocs needed for local syms too.  */
04016                   s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
04017                                                  sec, r_symndx);
04018                   if (s == NULL)
04019                     return FALSE;
04020 
04021                 vpp = &elf_section_data (s)->local_dynrel;
04022                   head = (struct elf_m32r_dyn_relocs **) vpp;
04023                 }
04024 
04025               p = *head;
04026               if (p == NULL || p->sec != sec)
04027                 {
04028                   bfd_size_type amt = sizeof (*p);
04029 
04030                   p = bfd_alloc (dynobj, amt);
04031                   if (p == NULL)
04032                     return FALSE;
04033                   p->next = *head;
04034                   *head = p;
04035                   p->sec = sec;
04036                   p->count = 0;
04037                   p->pc_count = 0;
04038                 }
04039 
04040               p->count += 1;
04041               if (   ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
04042                   || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA
04043                 || ELF32_R_TYPE (rel->r_info) == R_M32R_10_PCREL_RELA
04044                 || ELF32_R_TYPE (rel->r_info) == R_M32R_REL32)
04045                 p->pc_count += 1;
04046             }
04047           break;
04048 
04049         /* This relocation describes the C++ object vtable hierarchy.
04050            Reconstruct it for later use during GC.  */
04051         case R_M32R_RELA_GNU_VTINHERIT:
04052         case R_M32R_GNU_VTINHERIT:
04053           if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
04054             return FALSE;
04055           break;
04056 
04057         /* This relocation describes which C++ vtable entries are actually
04058            used.  Record for later use during GC.  */
04059         case R_M32R_GNU_VTENTRY:
04060           if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
04061             return FALSE;
04062           break;
04063         case R_M32R_RELA_GNU_VTENTRY:
04064           if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
04065             return FALSE;
04066           break;
04067         }
04068     }
04069 
04070   return TRUE;
04071 }
04072 
04073 static const struct bfd_elf_special_section m32r_elf_special_sections[] =
04074 {
04075   { STRING_COMMA_LEN (".sbss"),  -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
04076   { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
04077   { NULL,                     0,  0, 0,            0 }
04078 };
04079 
04080 static bfd_boolean
04081 m32r_elf_fake_sections (bfd *abfd,
04082                      Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED,
04083                      asection *sec)
04084 {
04085   const char *name;
04086 
04087   name = bfd_get_section_name (abfd, sec);
04088 
04089   /* The generic elf_fake_sections will set up REL_HDR using the
04090      default kind of relocations.  But, we may actually need both
04091      kinds of relocations, so we set up the second header here.
04092 
04093      This is not necessary for the O32 ABI since that only uses Elf32_Rel
04094      relocations (cf. System V ABI, MIPS RISC Processor Supplement,
04095      3rd Edition, p. 4-17).  It breaks the IRIX 5/6 32-bit ld, since one
04096      of the resulting empty .rela.<section> sections starts with
04097      sh_offset == object size, and ld doesn't allow that.  While the check
04098      is arguably bogus for empty or SHT_NOBITS sections, it can easily be
04099      avoided by not emitting those useless sections in the first place.  */
04100   if ((sec->flags & SEC_RELOC) != 0)
04101     {
04102       struct bfd_elf_section_data *esd;
04103       bfd_size_type amt = sizeof (Elf_Internal_Shdr);
04104 
04105       esd = elf_section_data (sec);
04106       BFD_ASSERT (esd->rel_hdr2 == NULL);
04107       esd->rel_hdr2 = bfd_zalloc (abfd, amt);
04108       if (!esd->rel_hdr2)
04109         return FALSE;
04110       _bfd_elf_init_reloc_shdr (abfd, esd->rel_hdr2, sec,
04111                                 !sec->use_rela_p);
04112     }
04113 
04114   return TRUE;
04115 }
04116 
04117 static enum elf_reloc_type_class
04118 m32r_elf_reloc_type_class (const Elf_Internal_Rela *rela)
04119 {
04120   switch ((int) ELF32_R_TYPE (rela->r_info))
04121     {
04122     case R_M32R_RELATIVE:  return reloc_class_relative;
04123     case R_M32R_JMP_SLOT:  return reloc_class_plt;
04124     case R_M32R_COPY:      return reloc_class_copy;
04125     default:            return reloc_class_normal;
04126     }
04127 }
04128 
04129 #define ELF_ARCH            bfd_arch_m32r
04130 #define ELF_MACHINE_CODE    EM_M32R
04131 #define ELF_MACHINE_ALT1    EM_CYGNUS_M32R
04132 #define ELF_MAXPAGESIZE            0x1 /* Explicitly requested by Mitsubishi.  */
04133 
04134 #define TARGET_BIG_SYM          bfd_elf32_m32r_vec
04135 #define TARGET_BIG_NAME            "elf32-m32r"
04136 #define TARGET_LITTLE_SYM       bfd_elf32_m32rle_vec
04137 #define TARGET_LITTLE_NAME      "elf32-m32rle"
04138 
04139 #define elf_info_to_howto                 m32r_info_to_howto
04140 #define elf_info_to_howto_rel                    m32r_info_to_howto_rel
04141 #define elf_backend_section_from_bfd_section     _bfd_m32r_elf_section_from_bfd_section
04142 #define elf_backend_symbol_processing            _bfd_m32r_elf_symbol_processing
04143 #define elf_backend_add_symbol_hook              m32r_elf_add_symbol_hook
04144 #define elf_backend_relocate_section             m32r_elf_relocate_section
04145 #define elf_backend_gc_mark_hook                m32r_elf_gc_mark_hook
04146 #define elf_backend_gc_sweep_hook               m32r_elf_gc_sweep_hook
04147 #define elf_backend_check_relocs                m32r_elf_check_relocs
04148 
04149 #define elf_backend_create_dynamic_sections     m32r_elf_create_dynamic_sections
04150 #define bfd_elf32_bfd_link_hash_table_create    m32r_elf_link_hash_table_create
04151 #define elf_backend_size_dynamic_sections       m32r_elf_size_dynamic_sections
04152 #define elf_backend_omit_section_dynsym \
04153   ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
04154 #define elf_backend_finish_dynamic_sections     m32r_elf_finish_dynamic_sections
04155 #define elf_backend_adjust_dynamic_symbol       m32r_elf_adjust_dynamic_symbol
04156 #define elf_backend_finish_dynamic_symbol       m32r_elf_finish_dynamic_symbol
04157 #define elf_backend_reloc_type_class            m32r_elf_reloc_type_class
04158 #define elf_backend_copy_indirect_symbol        m32r_elf_copy_indirect_symbol
04159 
04160 #define elf_backend_can_gc_sections             1
04161 /*#if !USE_REL
04162 #define elf_backend_rela_normal                  1
04163 #endif*/
04164 #define elf_backend_can_refcount 1
04165 #define elf_backend_want_got_plt 1
04166 #define elf_backend_plt_readonly 1
04167 #define elf_backend_want_plt_sym 0
04168 #define elf_backend_got_header_size 12
04169 
04170 #define elf_backend_may_use_rel_p       1
04171 #ifdef USE_M32R_OLD_RELOC
04172 #define elf_backend_default_use_rela_p  0
04173 #define elf_backend_may_use_rela_p      0
04174 #else
04175 #define elf_backend_default_use_rela_p  1
04176 #define elf_backend_may_use_rela_p      1
04177 #define elf_backend_fake_sections       m32r_elf_fake_sections
04178 #endif
04179 
04180 #define elf_backend_object_p                     m32r_elf_object_p
04181 #define elf_backend_final_write_processing       m32r_elf_final_write_processing
04182 #define bfd_elf32_bfd_merge_private_bfd_data     m32r_elf_merge_private_bfd_data
04183 #define bfd_elf32_bfd_set_private_flags          m32r_elf_set_private_flags
04184 #define bfd_elf32_bfd_print_private_bfd_data     m32r_elf_print_private_bfd_data
04185 #define elf_backend_special_sections             m32r_elf_special_sections
04186 
04187 #include "elf32-target.h"
04188 
04189 #undef  ELF_MAXPAGESIZE
04190 #define ELF_MAXPAGESIZE         0x1000
04191 
04192 #undef  TARGET_BIG_SYM
04193 #define TARGET_BIG_SYM          bfd_elf32_m32rlin_vec
04194 #undef  TARGET_BIG_NAME
04195 #define TARGET_BIG_NAME         "elf32-m32r-linux"
04196 #undef  TARGET_LITTLE_SYM
04197 #define TARGET_LITTLE_SYM       bfd_elf32_m32rlelin_vec
04198 #undef  TARGET_LITTLE_NAME
04199 #define TARGET_LITTLE_NAME      "elf32-m32rle-linux"
04200 #undef  elf32_bed
04201 #define elf32_bed               elf32_m32r_lin_bed
04202 
04203 #include "elf32-target.h"
04204