Home | History | Annotate | Line # | Download | only in bfd
      1       1.1     skrll /* M32R-specific support for 32-bit ELF.
      2  1.1.1.12  christos    Copyright (C) 1996-2026 Free Software Foundation, Inc.
      3       1.1     skrll 
      4       1.1     skrll    This file is part of BFD, the Binary File Descriptor library.
      5       1.1     skrll 
      6       1.1     skrll    This program is free software; you can redistribute it and/or modify
      7       1.1     skrll    it under the terms of the GNU General Public License as published by
      8       1.1     skrll    the Free Software Foundation; either version 3 of the License, or
      9       1.1     skrll    (at your option) any later version.
     10       1.1     skrll 
     11       1.1     skrll    This program is distributed in the hope that it will be useful,
     12       1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13       1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14       1.1     skrll    GNU General Public License for more details.
     15       1.1     skrll 
     16       1.1     skrll    You should have received a copy of the GNU General Public License
     17       1.1     skrll    along with this program; if not, write to the Free Software
     18       1.1     skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19       1.1     skrll    MA 02110-1301, USA.  */
     20       1.1     skrll 
     21       1.1     skrll #include "sysdep.h"
     22       1.1     skrll #include "bfd.h"
     23       1.1     skrll #include "libbfd.h"
     24       1.1     skrll #include "elf-bfd.h"
     25       1.1     skrll #include "elf/m32r.h"
     26       1.1     skrll 
     27       1.1     skrll #define NOP_INSN		0x7000
     28       1.1     skrll #define MAKE_PARALLEL(insn)	((insn) | 0x8000)
     29       1.1     skrll 
     30       1.1     skrll /* Use REL instead of RELA to save space.
     31       1.1     skrll    This only saves space in libraries and object files, but perhaps
     32       1.1     skrll    relocs will be put in ROM?  All in all though, REL relocs are a pain
     33       1.1     skrll    to work with.  */
     34       1.1     skrll /* #define USE_REL	1
     35       1.1     skrll 
     36       1.1     skrll #ifndef USE_REL
     37       1.1     skrll #define USE_REL	0
     38       1.1     skrll #endif */
     39       1.1     skrll /* Use RELA. But use REL to link old objects for backwords compatibility.  */
     40       1.1     skrll 
     41       1.1     skrll /* Functions for the M32R ELF linker.  */
     42       1.1     skrll 
     43       1.1     skrll /* The name of the dynamic interpreter.  This is put in the .interp
     44       1.1     skrll    section.  */
     45       1.1     skrll 
     46       1.1     skrll #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
     47       1.1     skrll 
     48       1.1     skrll /* The nop opcode we use.  */
     49       1.1     skrll 
     50       1.1     skrll #define M32R_NOP 0x7000f000
     51       1.1     skrll 
     52       1.1     skrll #define PLT_EMPTY   0x10101010  /* RIE  -> RIE */
     53       1.1     skrll 
     54       1.1     skrll /* The size in bytes of an entry in the procedure linkage table.  */
     55       1.1     skrll 
     56       1.1     skrll #define PLT_ENTRY_SIZE 20
     57       1.1     skrll #define PLT_HEADER_SIZE 20
     58       1.1     skrll 
     59       1.1     skrll /* The first one entries in a procedure linkage table are reserved,
     60       1.1     skrll    and the initial contents are unimportant (we zero them out).
     61       1.1     skrll    Subsequent entries look like this. */
     62       1.1     skrll 
     63   1.1.1.6  christos #define PLT0_ENTRY_WORD0  0xd6c00000	/* seth r6, #high(.got+4)	   */
     64   1.1.1.6  christos #define PLT0_ENTRY_WORD1  0x86e60000	/* or3	r6, r6, #low(.got)+4)	   */
     65   1.1.1.6  christos #define PLT0_ENTRY_WORD2  0x24e626c6	/* ld	r4, @r6+    -> ld r6, @r6  */
     66   1.1.1.6  christos #define PLT0_ENTRY_WORD3  0x1fc6f000	/* jmp	r6	    || pnop	   */
     67   1.1.1.6  christos #define PLT0_ENTRY_WORD4  PLT_EMPTY	/* RIE		   -> RIE	   */
     68   1.1.1.6  christos 
     69   1.1.1.6  christos #define PLT0_PIC_ENTRY_WORD0  0xa4cc0004 /* ld	 r4, @(4,r12)		   */
     70   1.1.1.6  christos #define PLT0_PIC_ENTRY_WORD1  0xa6cc0008 /* ld	 r6, @(8,r12)		   */
     71   1.1.1.6  christos #define PLT0_PIC_ENTRY_WORD2  0x1fc6f000 /* jmp	 r6	    || nop	   */
     72   1.1.1.6  christos #define PLT0_PIC_ENTRY_WORD3  PLT_EMPTY	 /* RIE		    -> RIE	   */
     73   1.1.1.6  christos #define PLT0_PIC_ENTRY_WORD4  PLT_EMPTY	 /* RIE		    -> RIE	   */
     74   1.1.1.6  christos 
     75   1.1.1.6  christos #define PLT_ENTRY_WORD0	 0xe6000000 /* ld24 r6, .name_in_GOT		    */
     76   1.1.1.6  christos #define PLT_ENTRY_WORD1	 0x06acf000 /* add  r6, r12	     || nop	    */
     77   1.1.1.6  christos #define PLT_ENTRY_WORD0b 0xd6c00000 /* seth r6, #high(.name_in_GOT)	    */
     78   1.1.1.6  christos #define PLT_ENTRY_WORD1b 0x86e60000 /* or3  r6, r6, #low(.name_in_GOT)	    */
     79   1.1.1.6  christos #define PLT_ENTRY_WORD2	 0x26c61fc6 /* ld  r6, @r6	     -> jmp r6	    */
     80   1.1.1.6  christos #define PLT_ENTRY_WORD3	 0xe5000000 /* ld24 r5, $offset			    */
     81   1.1.1.6  christos #define PLT_ENTRY_WORD4	 0xff000000 /* bra  .plt0.			    */
     82       1.1     skrll 
     83       1.1     skrll 
     84       1.1     skrll /* Utility to actually perform an R_M32R_10_PCREL reloc.  */
     85       1.1     skrll 
     86       1.1     skrll static bfd_reloc_status_type
     87       1.1     skrll m32r_elf_do_10_pcrel_reloc (bfd *abfd,
     88       1.1     skrll 			    reloc_howto_type *howto,
     89       1.1     skrll 			    asection *input_section,
     90       1.1     skrll 			    bfd_byte *data,
     91       1.1     skrll 			    bfd_vma offset,
     92       1.1     skrll 			    asection *symbol_section ATTRIBUTE_UNUSED,
     93       1.1     skrll 			    bfd_vma symbol_value,
     94       1.1     skrll 			    bfd_vma addend)
     95       1.1     skrll {
     96       1.1     skrll   bfd_signed_vma relocation;
     97       1.1     skrll   unsigned long x;
     98       1.1     skrll   bfd_reloc_status_type status;
     99       1.1     skrll 
    100       1.1     skrll   /* Sanity check the address (offset in section).  */
    101       1.1     skrll   if (offset > bfd_get_section_limit (abfd, input_section))
    102       1.1     skrll     return bfd_reloc_outofrange;
    103       1.1     skrll 
    104       1.1     skrll   relocation = symbol_value + addend;
    105       1.1     skrll   /* Make it pc relative.  */
    106       1.1     skrll   relocation -=	(input_section->output_section->vma
    107       1.1     skrll 		 + input_section->output_offset);
    108       1.1     skrll   /* These jumps mask off the lower two bits of the current address
    109       1.1     skrll      before doing pcrel calculations.  */
    110       1.1     skrll   relocation -= (offset & -(bfd_vma) 4);
    111       1.1     skrll 
    112       1.1     skrll   if (relocation < -0x200 || relocation > 0x1ff)
    113       1.1     skrll     status = bfd_reloc_overflow;
    114       1.1     skrll   else
    115       1.1     skrll     status = bfd_reloc_ok;
    116       1.1     skrll 
    117       1.1     skrll   x = bfd_get_16 (abfd, data + offset);
    118       1.1     skrll   relocation >>= howto->rightshift;
    119       1.1     skrll   relocation <<= howto->bitpos;
    120       1.1     skrll   x = (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask);
    121       1.1     skrll   bfd_put_16 (abfd, (bfd_vma) x, data + offset);
    122       1.1     skrll 
    123       1.1     skrll   return status;
    124       1.1     skrll }
    125       1.1     skrll 
    126       1.1     skrll /* Handle the R_M32R_10_PCREL reloc.  */
    127       1.1     skrll 
    128       1.1     skrll static bfd_reloc_status_type
    129       1.1     skrll m32r_elf_10_pcrel_reloc (bfd * abfd,
    130       1.1     skrll 			 arelent * reloc_entry,
    131       1.1     skrll 			 asymbol * symbol,
    132       1.1     skrll 			 void * data,
    133       1.1     skrll 			 asection * input_section,
    134       1.1     skrll 			 bfd * output_bfd,
    135       1.1     skrll 			 char ** error_message ATTRIBUTE_UNUSED)
    136       1.1     skrll {
    137       1.1     skrll   /* This part is from bfd_elf_generic_reloc.  */
    138       1.1     skrll   if (output_bfd != NULL
    139       1.1     skrll       && (symbol->flags & BSF_SECTION_SYM) == 0
    140       1.1     skrll       && (! reloc_entry->howto->partial_inplace
    141       1.1     skrll 	  || reloc_entry->addend == 0))
    142       1.1     skrll     {
    143       1.1     skrll       reloc_entry->address += input_section->output_offset;
    144       1.1     skrll       return bfd_reloc_ok;
    145       1.1     skrll     }
    146       1.1     skrll 
    147       1.1     skrll   if (output_bfd != NULL)
    148       1.1     skrll     /* FIXME: See bfd_perform_relocation.  Is this right?  */
    149       1.1     skrll     return bfd_reloc_continue;
    150       1.1     skrll 
    151       1.1     skrll   return m32r_elf_do_10_pcrel_reloc (abfd, reloc_entry->howto,
    152       1.1     skrll 				     input_section,
    153       1.1     skrll 				     data, reloc_entry->address,
    154       1.1     skrll 				     symbol->section,
    155       1.1     skrll 				     (symbol->value
    156       1.1     skrll 				      + symbol->section->output_section->vma
    157       1.1     skrll 				      + symbol->section->output_offset),
    158       1.1     skrll 				     reloc_entry->addend);
    159       1.1     skrll }
    160       1.1     skrll 
    161       1.1     skrll /* Do generic partial_inplace relocation.
    162       1.1     skrll    This is a local replacement for bfd_elf_generic_reloc.  */
    163       1.1     skrll 
    164       1.1     skrll static bfd_reloc_status_type
    165       1.1     skrll m32r_elf_generic_reloc (bfd *input_bfd,
    166       1.1     skrll 			arelent *reloc_entry,
    167       1.1     skrll 			asymbol *symbol,
    168       1.1     skrll 			void * data,
    169       1.1     skrll 			asection *input_section,
    170       1.1     skrll 			bfd *output_bfd,
    171       1.1     skrll 			char **error_message ATTRIBUTE_UNUSED)
    172       1.1     skrll {
    173       1.1     skrll   bfd_reloc_status_type ret;
    174       1.1     skrll   bfd_vma relocation;
    175       1.1     skrll   bfd_byte *inplace_address;
    176       1.1     skrll 
    177       1.1     skrll   /* This part is from bfd_elf_generic_reloc.
    178       1.1     skrll      If we're relocating, and this an external symbol, we don't want
    179       1.1     skrll      to change anything.  */
    180       1.1     skrll   if (output_bfd != NULL
    181       1.1     skrll       && (symbol->flags & BSF_SECTION_SYM) == 0
    182       1.1     skrll       && reloc_entry->addend == 0)
    183       1.1     skrll     {
    184       1.1     skrll       reloc_entry->address += input_section->output_offset;
    185       1.1     skrll       return bfd_reloc_ok;
    186       1.1     skrll     }
    187       1.1     skrll 
    188       1.1     skrll   /* Now do the reloc in the usual way.
    189       1.1     skrll      ??? It would be nice to call bfd_elf_generic_reloc here,
    190       1.1     skrll      but we have partial_inplace set.  bfd_elf_generic_reloc will
    191       1.1     skrll      pass the handling back to bfd_install_relocation which will install
    192       1.1     skrll      a section relative addend which is wrong.  */
    193       1.1     skrll 
    194       1.1     skrll   /* Sanity check the address (offset in section).  */
    195       1.1     skrll   if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
    196       1.1     skrll     return bfd_reloc_outofrange;
    197       1.1     skrll 
    198       1.1     skrll   ret = bfd_reloc_ok;
    199       1.1     skrll   if (bfd_is_und_section (symbol->section)
    200       1.1     skrll       && output_bfd == NULL)
    201       1.1     skrll     ret = bfd_reloc_undefined;
    202       1.1     skrll 
    203       1.1     skrll   if (bfd_is_com_section (symbol->section)
    204       1.1     skrll       || output_bfd != NULL)
    205       1.1     skrll     relocation = 0;
    206       1.1     skrll   else
    207       1.1     skrll     relocation = symbol->value;
    208       1.1     skrll 
    209       1.1     skrll   /* Only do this for a final link.  */
    210       1.1     skrll   if (output_bfd == NULL)
    211       1.1     skrll     {
    212       1.1     skrll       relocation += symbol->section->output_section->vma;
    213       1.1     skrll       relocation += symbol->section->output_offset;
    214       1.1     skrll     }
    215       1.1     skrll 
    216       1.1     skrll   relocation += reloc_entry->addend;
    217       1.1     skrll   inplace_address = (bfd_byte *) data + reloc_entry->address;
    218       1.1     skrll 
    219   1.1.1.6  christos #define DOIT(x)						\
    220   1.1.1.6  christos   x = ( (x & ~reloc_entry->howto->dst_mask) |		\
    221       1.1     skrll   (((x & reloc_entry->howto->src_mask) +  relocation) &	\
    222       1.1     skrll   reloc_entry->howto->dst_mask))
    223       1.1     skrll 
    224   1.1.1.9  christos   switch (bfd_get_reloc_size (reloc_entry->howto))
    225       1.1     skrll     {
    226   1.1.1.9  christos     case 2:
    227       1.1     skrll       {
    228       1.1     skrll 	short x = bfd_get_16 (input_bfd, inplace_address);
    229       1.1     skrll 	DOIT (x);
    230   1.1.1.6  christos 	bfd_put_16 (input_bfd, (bfd_vma) x, inplace_address);
    231       1.1     skrll       }
    232       1.1     skrll       break;
    233   1.1.1.9  christos     case 4:
    234       1.1     skrll       {
    235       1.1     skrll 	unsigned long x = bfd_get_32 (input_bfd, inplace_address);
    236       1.1     skrll 	DOIT (x);
    237   1.1.1.6  christos 	bfd_put_32 (input_bfd, (bfd_vma)x , inplace_address);
    238       1.1     skrll       }
    239       1.1     skrll       break;
    240       1.1     skrll     default:
    241       1.1     skrll       BFD_ASSERT (0);
    242       1.1     skrll     }
    243       1.1     skrll 
    244       1.1     skrll   if (output_bfd != NULL)
    245       1.1     skrll     reloc_entry->address += input_section->output_offset;
    246       1.1     skrll 
    247       1.1     skrll   return ret;
    248       1.1     skrll }
    249       1.1     skrll 
    250       1.1     skrll /* Handle the R_M32R_SDA16 reloc.
    251       1.1     skrll    This reloc is used to compute the address of objects in the small data area
    252       1.1     skrll    and to perform loads and stores from that area.
    253       1.1     skrll    The lower 16 bits are sign extended and added to the register specified
    254       1.1     skrll    in the instruction, which is assumed to point to _SDA_BASE_.  */
    255       1.1     skrll 
    256       1.1     skrll static bfd_reloc_status_type
    257       1.1     skrll m32r_elf_sda16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    258       1.1     skrll 		      arelent *reloc_entry,
    259       1.1     skrll 		      asymbol *symbol,
    260       1.1     skrll 		      void * data ATTRIBUTE_UNUSED,
    261       1.1     skrll 		      asection *input_section,
    262       1.1     skrll 		      bfd *output_bfd,
    263       1.1     skrll 		      char **error_message ATTRIBUTE_UNUSED)
    264       1.1     skrll {
    265       1.1     skrll   /* This part is from bfd_elf_generic_reloc.  */
    266       1.1     skrll   if (output_bfd != NULL
    267       1.1     skrll       && (symbol->flags & BSF_SECTION_SYM) == 0
    268       1.1     skrll       && (! reloc_entry->howto->partial_inplace
    269       1.1     skrll 	  || reloc_entry->addend == 0))
    270       1.1     skrll     {
    271       1.1     skrll       reloc_entry->address += input_section->output_offset;
    272       1.1     skrll       return bfd_reloc_ok;
    273       1.1     skrll     }
    274       1.1     skrll 
    275       1.1     skrll   if (output_bfd != NULL)
    276       1.1     skrll     /* FIXME: See bfd_perform_relocation.  Is this right?  */
    277       1.1     skrll     return bfd_reloc_continue;
    278       1.1     skrll 
    279       1.1     skrll   /* FIXME: not sure what to do here yet.  But then again, the linker
    280       1.1     skrll      may never call us.  */
    281       1.1     skrll   abort ();
    282       1.1     skrll }
    283       1.1     skrll 
    284       1.1     skrll 
    285       1.1     skrll /* Handle the R_M32R_HI16_[SU]LO relocs.
    287       1.1     skrll    HI16_SLO is for the add3 and load/store with displacement instructions.
    288       1.1     skrll    HI16_ULO is for the or3 instruction.
    289       1.1     skrll    For R_M32R_HI16_SLO, the lower 16 bits are sign extended when added to
    290       1.1     skrll    the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
    291       1.1     skrll    we must add one to the high 16 bytes (which will get subtracted off when
    292       1.1     skrll    the low 16 bits are added).
    293       1.1     skrll    These relocs have to be done in combination with an R_M32R_LO16 reloc
    294       1.1     skrll    because there is a carry from the LO16 to the HI16.  Here we just save
    295       1.1     skrll    the information we need; we do the actual relocation when we see the LO16.
    296       1.1     skrll    This code is copied from the elf32-mips.c.  We also support an arbitrary
    297       1.1     skrll    number of HI16 relocs to be associated with a single LO16 reloc.  The
    298       1.1     skrll    assembler sorts the relocs to ensure each HI16 immediately precedes its
    299       1.1     skrll    LO16.  However if there are multiple copies, the assembler may not find
    300       1.1     skrll    the real LO16 so it picks the first one it finds.  */
    301       1.1     skrll 
    302       1.1     skrll struct m32r_hi16
    303       1.1     skrll {
    304       1.1     skrll   struct m32r_hi16 *next;
    305       1.1     skrll   bfd_byte *addr;
    306       1.1     skrll   bfd_vma addend;
    307       1.1     skrll };
    308       1.1     skrll 
    309       1.1     skrll /* FIXME: This should not be a static variable.  */
    310       1.1     skrll 
    311       1.1     skrll static struct m32r_hi16 *m32r_hi16_list;
    312       1.1     skrll 
    313       1.1     skrll static bfd_reloc_status_type
    314       1.1     skrll m32r_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    315       1.1     skrll 		     arelent *reloc_entry,
    316       1.1     skrll 		     asymbol *symbol,
    317       1.1     skrll 		     void * data,
    318       1.1     skrll 		     asection *input_section,
    319       1.1     skrll 		     bfd *output_bfd,
    320       1.1     skrll 		     char **error_message ATTRIBUTE_UNUSED)
    321       1.1     skrll {
    322       1.1     skrll   bfd_reloc_status_type ret;
    323       1.1     skrll   bfd_vma relocation;
    324       1.1     skrll   struct m32r_hi16 *n;
    325       1.1     skrll 
    326       1.1     skrll   /* This part is from bfd_elf_generic_reloc.
    327       1.1     skrll      If we're relocating, and this an external symbol, we don't want
    328       1.1     skrll      to change anything.  */
    329       1.1     skrll   if (output_bfd != NULL
    330       1.1     skrll       && (symbol->flags & BSF_SECTION_SYM) == 0
    331       1.1     skrll       && reloc_entry->addend == 0)
    332       1.1     skrll     {
    333       1.1     skrll       reloc_entry->address += input_section->output_offset;
    334       1.1     skrll       return bfd_reloc_ok;
    335       1.1     skrll     }
    336       1.1     skrll 
    337       1.1     skrll   /* Sanity check the address (offset in section).  */
    338       1.1     skrll   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    339       1.1     skrll     return bfd_reloc_outofrange;
    340       1.1     skrll 
    341       1.1     skrll   ret = bfd_reloc_ok;
    342       1.1     skrll   if (bfd_is_und_section (symbol->section)
    343       1.1     skrll       && output_bfd == NULL)
    344       1.1     skrll     ret = bfd_reloc_undefined;
    345       1.1     skrll 
    346       1.1     skrll   if (bfd_is_com_section (symbol->section))
    347       1.1     skrll     relocation = 0;
    348       1.1     skrll   else
    349       1.1     skrll     relocation = symbol->value;
    350       1.1     skrll 
    351       1.1     skrll   relocation += symbol->section->output_section->vma;
    352       1.1     skrll   relocation += symbol->section->output_offset;
    353       1.1     skrll   relocation += reloc_entry->addend;
    354       1.1     skrll 
    355       1.1     skrll   /* Save the information, and let LO16 do the actual relocation.  */
    356       1.1     skrll   n = bfd_malloc ((bfd_size_type) sizeof *n);
    357       1.1     skrll   if (n == NULL)
    358       1.1     skrll     return bfd_reloc_outofrange;
    359       1.1     skrll   n->addr = (bfd_byte *) data + reloc_entry->address;
    360       1.1     skrll   n->addend = relocation;
    361       1.1     skrll   n->next = m32r_hi16_list;
    362       1.1     skrll   m32r_hi16_list = n;
    363       1.1     skrll 
    364       1.1     skrll   if (output_bfd != NULL)
    365       1.1     skrll     reloc_entry->address += input_section->output_offset;
    366       1.1     skrll 
    367       1.1     skrll   return ret;
    368       1.1     skrll }
    369       1.1     skrll 
    370       1.1     skrll /* Handle an M32R ELF HI16 reloc.  */
    371       1.1     skrll 
    372       1.1     skrll static void
    373       1.1     skrll m32r_elf_relocate_hi16 (bfd *input_bfd,
    374       1.1     skrll 			int type,
    375       1.1     skrll 			Elf_Internal_Rela *relhi,
    376       1.1     skrll 			Elf_Internal_Rela *rello,
    377       1.1     skrll 			bfd_byte *contents,
    378       1.1     skrll 			bfd_vma addend)
    379       1.1     skrll {
    380       1.1     skrll   unsigned long insn;
    381       1.1     skrll   bfd_vma addlo;
    382       1.1     skrll 
    383       1.1     skrll   insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
    384       1.1     skrll 
    385       1.1     skrll   addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
    386       1.1     skrll   if (type == R_M32R_HI16_SLO)
    387       1.1     skrll     addlo = ((addlo & 0xffff) ^ 0x8000) - 0x8000;
    388       1.1     skrll   else
    389       1.1     skrll     addlo &= 0xffff;
    390       1.1     skrll 
    391       1.1     skrll   addend += ((insn & 0xffff) << 16) + addlo;
    392       1.1     skrll 
    393       1.1     skrll   /* Reaccount for sign extension of low part.  */
    394       1.1     skrll   if (type == R_M32R_HI16_SLO
    395       1.1     skrll       && (addend & 0x8000) != 0)
    396       1.1     skrll     addend += 0x10000;
    397       1.1     skrll 
    398       1.1     skrll   bfd_put_32 (input_bfd,
    399       1.1     skrll 	      (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
    400       1.1     skrll 	      contents + relhi->r_offset);
    401       1.1     skrll }
    402       1.1     skrll 
    403       1.1     skrll /* Do an R_M32R_LO16 relocation.  This is a straightforward 16 bit
    404       1.1     skrll    inplace relocation; this function exists in order to do the
    405       1.1     skrll    R_M32R_HI16_[SU]LO relocation described above.  */
    406       1.1     skrll 
    407       1.1     skrll static bfd_reloc_status_type
    408       1.1     skrll m32r_elf_lo16_reloc (bfd *input_bfd,
    409       1.1     skrll 		     arelent *reloc_entry,
    410       1.1     skrll 		     asymbol *symbol,
    411       1.1     skrll 		     void * data,
    412       1.1     skrll 		     asection *input_section,
    413       1.1     skrll 		     bfd *output_bfd,
    414       1.1     skrll 		     char **error_message)
    415       1.1     skrll {
    416       1.1     skrll   /* This part is from bfd_elf_generic_reloc.
    417       1.1     skrll      If we're relocating, and this an external symbol, we don't want
    418       1.1     skrll      to change anything.  */
    419       1.1     skrll   if (output_bfd != NULL
    420       1.1     skrll       && (symbol->flags & BSF_SECTION_SYM) == 0
    421       1.1     skrll       && reloc_entry->addend == 0)
    422       1.1     skrll     {
    423       1.1     skrll       reloc_entry->address += input_section->output_offset;
    424       1.1     skrll       return bfd_reloc_ok;
    425       1.1     skrll     }
    426       1.1     skrll 
    427       1.1     skrll   if (m32r_hi16_list != NULL)
    428       1.1     skrll     {
    429       1.1     skrll       struct m32r_hi16 *l;
    430       1.1     skrll 
    431       1.1     skrll       l = m32r_hi16_list;
    432       1.1     skrll       while (l != NULL)
    433       1.1     skrll 	{
    434       1.1     skrll 	  unsigned long insn;
    435       1.1     skrll 	  unsigned long val;
    436       1.1     skrll 	  unsigned long vallo;
    437       1.1     skrll 	  struct m32r_hi16 *next;
    438       1.1     skrll 
    439       1.1     skrll 	  /* Do the HI16 relocation.  Note that we actually don't need
    440       1.1     skrll 	     to know anything about the LO16 itself, except where to
    441       1.1     skrll 	     find the low 16 bits of the addend needed by the LO16.  */
    442       1.1     skrll 	  insn = bfd_get_32 (input_bfd, l->addr);
    443       1.1     skrll 	  vallo = ((bfd_get_32 (input_bfd, (bfd_byte *) data + reloc_entry->address)
    444       1.1     skrll 		   & 0xffff) ^ 0x8000) - 0x8000;
    445       1.1     skrll 	  val = ((insn & 0xffff) << 16) + vallo;
    446       1.1     skrll 	  val += l->addend;
    447       1.1     skrll 
    448       1.1     skrll 	  /* Reaccount for sign extension of low part.  */
    449       1.1     skrll 	  if ((val & 0x8000) != 0)
    450       1.1     skrll 	    val += 0x10000;
    451       1.1     skrll 
    452       1.1     skrll 	  insn = (insn &~ (bfd_vma) 0xffff) | ((val >> 16) & 0xffff);
    453       1.1     skrll 	  bfd_put_32 (input_bfd, (bfd_vma) insn, l->addr);
    454       1.1     skrll 
    455       1.1     skrll 	  next = l->next;
    456       1.1     skrll 	  free (l);
    457       1.1     skrll 	  l = next;
    458       1.1     skrll 	}
    459       1.1     skrll 
    460       1.1     skrll       m32r_hi16_list = NULL;
    461       1.1     skrll     }
    462       1.1     skrll 
    463       1.1     skrll   /* Now do the LO16 reloc in the usual way.
    464       1.1     skrll      ??? It would be nice to call bfd_elf_generic_reloc here,
    465       1.1     skrll      but we have partial_inplace set.  bfd_elf_generic_reloc will
    466       1.1     skrll      pass the handling back to bfd_install_relocation which will install
    467       1.1     skrll      a section relative addend which is wrong.  */
    468       1.1     skrll   return m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
    469       1.1     skrll 				input_section, output_bfd, error_message);
    470       1.1     skrll }
    471       1.1     skrll 
    472       1.1     skrll 
    473       1.1     skrll static reloc_howto_type m32r_elf_howto_table[] =
    475       1.1     skrll {
    476       1.1     skrll   /* This reloc does nothing.  */
    477   1.1.1.9  christos   HOWTO (R_M32R_NONE,		/* type */
    478   1.1.1.4  christos 	 0,			/* rightshift */
    479   1.1.1.9  christos 	 0,			/* size */
    480       1.1     skrll 	 0,			/* bitsize */
    481   1.1.1.4  christos 	 false,			/* pc_relative */
    482       1.1     skrll 	 0,			/* bitpos */
    483       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    484   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    485       1.1     skrll 	 "R_M32R_NONE",		/* name */
    486       1.1     skrll 	 false,			/* partial_inplace */
    487   1.1.1.9  christos 	 0,			/* src_mask */
    488       1.1     skrll 	 0,			/* dst_mask */
    489       1.1     skrll 	 false),		/* pcrel_offset */
    490       1.1     skrll 
    491       1.1     skrll   /* A 16 bit absolute relocation.  */
    492   1.1.1.9  christos   HOWTO (R_M32R_16,		/* type */
    493       1.1     skrll 	 0,			/* rightshift */
    494   1.1.1.9  christos 	 2,			/* size */
    495       1.1     skrll 	 16,			/* bitsize */
    496       1.1     skrll 	 false,			/* pc_relative */
    497       1.1     skrll 	 0,			/* bitpos */
    498       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    499   1.1.1.9  christos 	 m32r_elf_generic_reloc,/* special_function */
    500       1.1     skrll 	 "R_M32R_16",		/* name */
    501       1.1     skrll 	 true,			/* partial_inplace */
    502   1.1.1.9  christos 	 0xffff,		/* src_mask */
    503       1.1     skrll 	 0xffff,		/* dst_mask */
    504       1.1     skrll 	 false),		/* pcrel_offset */
    505       1.1     skrll 
    506       1.1     skrll   /* A 32 bit absolute relocation.  */
    507   1.1.1.9  christos   HOWTO (R_M32R_32,		/* type */
    508       1.1     skrll 	 0,			/* rightshift */
    509   1.1.1.9  christos 	 4,			/* size */
    510       1.1     skrll 	 32,			/* bitsize */
    511       1.1     skrll 	 false,			/* pc_relative */
    512       1.1     skrll 	 0,			/* bitpos */
    513       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    514   1.1.1.9  christos 	 m32r_elf_generic_reloc,/* special_function */
    515       1.1     skrll 	 "R_M32R_32",		/* name */
    516       1.1     skrll 	 true,			/* partial_inplace */
    517   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    518       1.1     skrll 	 0xffffffff,		/* dst_mask */
    519       1.1     skrll 	 false),		/* pcrel_offset */
    520       1.1     skrll 
    521       1.1     skrll   /* A 24 bit address.  */
    522   1.1.1.9  christos   HOWTO (R_M32R_24,		/* type */
    523       1.1     skrll 	 0,			/* rightshift */
    524   1.1.1.9  christos 	 4,			/* size */
    525       1.1     skrll 	 24,			/* bitsize */
    526       1.1     skrll 	 false,			/* pc_relative */
    527       1.1     skrll 	 0,			/* bitpos */
    528       1.1     skrll 	 complain_overflow_unsigned, /* complain_on_overflow */
    529   1.1.1.9  christos 	 m32r_elf_generic_reloc,/* special_function */
    530       1.1     skrll 	 "R_M32R_24",		/* name */
    531       1.1     skrll 	 true,			/* partial_inplace */
    532   1.1.1.9  christos 	 0xffffff,		/* src_mask */
    533       1.1     skrll 	 0xffffff,		/* dst_mask */
    534       1.1     skrll 	 false),		/* pcrel_offset */
    535       1.1     skrll 
    536       1.1     skrll   /* An PC Relative 10-bit relocation, shifted by 2.
    537       1.1     skrll      This reloc is complicated because relocations are relative to pc & -4.
    538       1.1     skrll      i.e. branches in the right insn slot use the address of the left insn
    539       1.1     skrll      slot for pc.  */
    540       1.1     skrll   /* ??? It's not clear whether this should have partial_inplace set or not.
    541       1.1     skrll      Branch relaxing in the assembler can store the addend in the insn,
    542       1.1     skrll      and if bfd_install_relocation gets called the addend may get added
    543   1.1.1.6  christos      again.  */
    544   1.1.1.9  christos   HOWTO (R_M32R_10_PCREL,	/* type */
    545   1.1.1.6  christos 	 2,			/* rightshift */
    546   1.1.1.9  christos 	 2,			/* size */
    547   1.1.1.6  christos 	 10,			/* bitsize */
    548       1.1     skrll 	 true,			/* pc_relative */
    549       1.1     skrll 	 0,			/* bitpos */
    550       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    551   1.1.1.9  christos 	 m32r_elf_10_pcrel_reloc, /* special_function */
    552   1.1.1.6  christos 	 "R_M32R_10_PCREL",	/* name */
    553   1.1.1.6  christos 	 false,			/* partial_inplace */
    554   1.1.1.9  christos 	 0xff,			/* src_mask */
    555       1.1     skrll 	 0xff,			/* dst_mask */
    556       1.1     skrll 	 true),			/* pcrel_offset */
    557       1.1     skrll 
    558       1.1     skrll   /* A relative 18 bit relocation, right shifted by 2.  */
    559   1.1.1.9  christos   HOWTO (R_M32R_18_PCREL,	/* type */
    560       1.1     skrll 	 2,			/* rightshift */
    561   1.1.1.9  christos 	 4,			/* size */
    562       1.1     skrll 	 16,			/* bitsize */
    563       1.1     skrll 	 true,			/* pc_relative */
    564       1.1     skrll 	 0,			/* bitpos */
    565       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    566   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    567       1.1     skrll 	 "R_M32R_18_PCREL",	/* name */
    568       1.1     skrll 	 false,			/* partial_inplace */
    569   1.1.1.9  christos 	 0xffff,		/* src_mask */
    570       1.1     skrll 	 0xffff,		/* dst_mask */
    571       1.1     skrll 	 true),			/* pcrel_offset */
    572       1.1     skrll 
    573       1.1     skrll   /* A relative 26 bit relocation, right shifted by 2.  */
    574       1.1     skrll   /* ??? It's not clear whether this should have partial_inplace set or not.
    575       1.1     skrll      Branch relaxing in the assembler can store the addend in the insn,
    576       1.1     skrll      and if bfd_install_relocation gets called the addend may get added
    577       1.1     skrll      again.  */
    578   1.1.1.9  christos   HOWTO (R_M32R_26_PCREL,	/* type */
    579       1.1     skrll 	 2,			/* rightshift */
    580   1.1.1.9  christos 	 4,			/* size */
    581       1.1     skrll 	 26,			/* bitsize */
    582       1.1     skrll 	 true,			/* pc_relative */
    583       1.1     skrll 	 0,			/* bitpos */
    584       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    585   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    586       1.1     skrll 	 "R_M32R_26_PCREL",	/* name */
    587       1.1     skrll 	 false,			/* partial_inplace */
    588   1.1.1.9  christos 	 0xffffff,		/* src_mask */
    589       1.1     skrll 	 0xffffff,		/* dst_mask */
    590       1.1     skrll 	 true),			/* pcrel_offset */
    591       1.1     skrll 
    592       1.1     skrll   /* High 16 bits of address when lower 16 is or'd in.  */
    593   1.1.1.9  christos   HOWTO (R_M32R_HI16_ULO,	/* type */
    594       1.1     skrll 	 16,			/* rightshift */
    595   1.1.1.9  christos 	 4,			/* size */
    596       1.1     skrll 	 16,			/* bitsize */
    597       1.1     skrll 	 false,			/* pc_relative */
    598       1.1     skrll 	 0,			/* bitpos */
    599       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    600   1.1.1.9  christos 	 m32r_elf_hi16_reloc,	/* special_function */
    601       1.1     skrll 	 "R_M32R_HI16_ULO",	/* name */
    602       1.1     skrll 	 true,			/* partial_inplace */
    603   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    604       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    605       1.1     skrll 	 false),		/* pcrel_offset */
    606       1.1     skrll 
    607       1.1     skrll   /* High 16 bits of address when lower 16 is added in.  */
    608   1.1.1.9  christos   HOWTO (R_M32R_HI16_SLO,	/* type */
    609       1.1     skrll 	 16,			/* rightshift */
    610   1.1.1.9  christos 	 4,			/* size */
    611       1.1     skrll 	 16,			/* bitsize */
    612       1.1     skrll 	 false,			/* pc_relative */
    613       1.1     skrll 	 0,			/* bitpos */
    614       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    615   1.1.1.9  christos 	 m32r_elf_hi16_reloc,	/* special_function */
    616       1.1     skrll 	 "R_M32R_HI16_SLO",	/* name */
    617       1.1     skrll 	 true,			/* partial_inplace */
    618   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    619       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    620       1.1     skrll 	 false),		/* pcrel_offset */
    621       1.1     skrll 
    622       1.1     skrll   /* Lower 16 bits of address.  */
    623   1.1.1.9  christos   HOWTO (R_M32R_LO16,		/* type */
    624       1.1     skrll 	 0,			/* rightshift */
    625   1.1.1.9  christos 	 4,			/* size */
    626       1.1     skrll 	 16,			/* bitsize */
    627       1.1     skrll 	 false,			/* pc_relative */
    628       1.1     skrll 	 0,			/* bitpos */
    629       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    630   1.1.1.9  christos 	 m32r_elf_lo16_reloc,	/* special_function */
    631       1.1     skrll 	 "R_M32R_LO16",		/* name */
    632       1.1     skrll 	 true,			/* partial_inplace */
    633   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    634       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    635       1.1     skrll 	 false),		/* pcrel_offset */
    636       1.1     skrll 
    637       1.1     skrll   /* Small data area 16 bits offset.  */
    638   1.1.1.9  christos   HOWTO (R_M32R_SDA16,		/* type */
    639       1.1     skrll 	 0,			/* rightshift */
    640   1.1.1.9  christos 	 4,			/* size */
    641       1.1     skrll 	 16,			/* bitsize */
    642       1.1     skrll 	 false,			/* pc_relative */
    643       1.1     skrll 	 0,			/* bitpos */
    644       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    645   1.1.1.9  christos 	 m32r_elf_sda16_reloc,	/* special_function */
    646       1.1     skrll 	 "R_M32R_SDA16",	/* name */
    647       1.1     skrll 	 true,			/* partial_inplace */  /* FIXME: correct? */
    648   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    649       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    650       1.1     skrll 	 false),		/* pcrel_offset */
    651       1.1     skrll 
    652   1.1.1.6  christos   /* GNU extension to record C++ vtable hierarchy.  */
    653   1.1.1.9  christos   HOWTO (R_M32R_GNU_VTINHERIT, /* type */
    654   1.1.1.6  christos 	 0,			/* rightshift */
    655   1.1.1.9  christos 	 4,			/* size */
    656   1.1.1.6  christos 	 0,			/* bitsize */
    657   1.1.1.6  christos 	 false,			/* pc_relative */
    658   1.1.1.6  christos 	 0,			/* bitpos */
    659   1.1.1.6  christos 	 complain_overflow_dont, /* complain_on_overflow */
    660   1.1.1.9  christos 	 NULL,			/* special_function */
    661   1.1.1.6  christos 	 "R_M32R_GNU_VTINHERIT", /* name */
    662   1.1.1.6  christos 	 false,			/* partial_inplace */
    663   1.1.1.9  christos 	 0,			/* src_mask */
    664       1.1     skrll 	 0,			/* dst_mask */
    665       1.1     skrll 	 false),		/* pcrel_offset */
    666   1.1.1.6  christos 
    667   1.1.1.6  christos   /* GNU extension to record C++ vtable member usage.  */
    668   1.1.1.9  christos   HOWTO (R_M32R_GNU_VTENTRY,	 /* type */
    669   1.1.1.6  christos 	 0,			/* rightshift */
    670   1.1.1.9  christos 	 4,			/* size */
    671   1.1.1.6  christos 	 0,			/* bitsize */
    672   1.1.1.6  christos 	 false,			/* pc_relative */
    673   1.1.1.6  christos 	 0,			/* bitpos */
    674   1.1.1.6  christos 	 complain_overflow_dont, /* complain_on_overflow */
    675   1.1.1.9  christos 	 _bfd_elf_rel_vtable_reloc_fn,	/* special_function */
    676   1.1.1.6  christos 	 "R_M32R_GNU_VTENTRY",	 /* name */
    677   1.1.1.6  christos 	 false,			/* partial_inplace */
    678   1.1.1.9  christos 	 0,			/* src_mask */
    679       1.1     skrll 	 0,			/* dst_mask */
    680       1.1     skrll 	 false),		/* pcrel_offset */
    681       1.1     skrll 
    682       1.1     skrll   EMPTY_HOWTO (13),
    683       1.1     skrll   EMPTY_HOWTO (14),
    684       1.1     skrll   EMPTY_HOWTO (15),
    685       1.1     skrll   EMPTY_HOWTO (16),
    686       1.1     skrll   EMPTY_HOWTO (17),
    687       1.1     skrll   EMPTY_HOWTO (18),
    688       1.1     skrll   EMPTY_HOWTO (19),
    689       1.1     skrll   EMPTY_HOWTO (20),
    690       1.1     skrll   EMPTY_HOWTO (21),
    691       1.1     skrll   EMPTY_HOWTO (22),
    692       1.1     skrll   EMPTY_HOWTO (23),
    693       1.1     skrll   EMPTY_HOWTO (24),
    694       1.1     skrll   EMPTY_HOWTO (25),
    695       1.1     skrll   EMPTY_HOWTO (26),
    696       1.1     skrll   EMPTY_HOWTO (27),
    697       1.1     skrll   EMPTY_HOWTO (28),
    698       1.1     skrll   EMPTY_HOWTO (29),
    699       1.1     skrll   EMPTY_HOWTO (30),
    700       1.1     skrll   EMPTY_HOWTO (31),
    701       1.1     skrll   EMPTY_HOWTO (32),
    702       1.1     skrll 
    703       1.1     skrll   /* A 16 bit absolute relocation.  */
    704   1.1.1.9  christos   HOWTO (R_M32R_16_RELA,	/* type */
    705       1.1     skrll 	 0,			/* rightshift */
    706   1.1.1.9  christos 	 2,			/* size */
    707       1.1     skrll 	 16,			/* bitsize */
    708       1.1     skrll 	 false,			/* pc_relative */
    709       1.1     skrll 	 0,			/* bitpos */
    710       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    711   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    712       1.1     skrll 	 "R_M32R_16_RELA",	/* name */
    713       1.1     skrll 	 false,			/* partial_inplace */
    714   1.1.1.9  christos 	 0xffff,		/* src_mask */
    715       1.1     skrll 	 0xffff,		/* dst_mask */
    716       1.1     skrll 	 false),		/* pcrel_offset */
    717       1.1     skrll 
    718       1.1     skrll   /* A 32 bit absolute relocation.  */
    719   1.1.1.9  christos   HOWTO (R_M32R_32_RELA,	/* type */
    720       1.1     skrll 	 0,			/* rightshift */
    721   1.1.1.9  christos 	 4,			/* size */
    722       1.1     skrll 	 32,			/* bitsize */
    723       1.1     skrll 	 false,			/* pc_relative */
    724       1.1     skrll 	 0,			/* bitpos */
    725       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    726   1.1.1.9  christos 	 bfd_elf_generic_reloc,/* special_function */
    727       1.1     skrll 	 "R_M32R_32_RELA",		/* name */
    728       1.1     skrll 	 false,			/* partial_inplace */
    729   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    730       1.1     skrll 	 0xffffffff,		/* dst_mask */
    731       1.1     skrll 	 false),		/* pcrel_offset */
    732       1.1     skrll 
    733       1.1     skrll   /* A 24 bit address.  */
    734   1.1.1.9  christos   HOWTO (R_M32R_24_RELA,	/* type */
    735       1.1     skrll 	 0,			/* rightshift */
    736   1.1.1.9  christos 	 4,			/* size */
    737       1.1     skrll 	 24,			/* bitsize */
    738       1.1     skrll 	 false,			/* pc_relative */
    739       1.1     skrll 	 0,			/* bitpos */
    740       1.1     skrll 	 complain_overflow_unsigned, /* complain_on_overflow */
    741   1.1.1.9  christos 	 bfd_elf_generic_reloc,/* special_function */
    742       1.1     skrll 	 "R_M32R_24_RELA",	/* name */
    743       1.1     skrll 	 false,			/* partial_inplace */
    744   1.1.1.9  christos 	 0xffffff,		/* src_mask */
    745       1.1     skrll 	 0xffffff,		/* dst_mask */
    746       1.1     skrll 	 false),		/* pcrel_offset */
    747   1.1.1.6  christos 
    748   1.1.1.9  christos   HOWTO (R_M32R_10_PCREL_RELA,	/* type */
    749   1.1.1.6  christos 	 2,			/* rightshift */
    750   1.1.1.9  christos 	 2,			/* size */
    751   1.1.1.6  christos 	 10,			/* bitsize */
    752       1.1     skrll 	 true,			/* pc_relative */
    753       1.1     skrll 	 0,			/* bitpos */
    754       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    755   1.1.1.9  christos 	 m32r_elf_10_pcrel_reloc, /* special_function */
    756   1.1.1.6  christos 	 "R_M32R_10_PCREL_RELA",/* name */
    757   1.1.1.6  christos 	 false,			/* partial_inplace */
    758   1.1.1.9  christos 	 0xff,			/* src_mask */
    759       1.1     skrll 	 0xff,			/* dst_mask */
    760       1.1     skrll 	 true),			/* pcrel_offset */
    761       1.1     skrll 
    762       1.1     skrll   /* A relative 18 bit relocation, right shifted by 2.  */
    763   1.1.1.9  christos   HOWTO (R_M32R_18_PCREL_RELA,	/* type */
    764       1.1     skrll 	 2,			/* rightshift */
    765   1.1.1.9  christos 	 4,			/* size */
    766       1.1     skrll 	 16,			/* bitsize */
    767       1.1     skrll 	 true,			/* pc_relative */
    768       1.1     skrll 	 0,			/* bitpos */
    769       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    770   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    771       1.1     skrll 	 "R_M32R_18_PCREL_RELA",/* name */
    772       1.1     skrll 	 false,			/* partial_inplace */
    773   1.1.1.9  christos 	 0xffff,		/* src_mask */
    774       1.1     skrll 	 0xffff,		/* dst_mask */
    775       1.1     skrll 	 true),			/* pcrel_offset */
    776       1.1     skrll 
    777       1.1     skrll   /* A relative 26 bit relocation, right shifted by 2.  */
    778   1.1.1.9  christos   HOWTO (R_M32R_26_PCREL_RELA,	/* type */
    779       1.1     skrll 	 2,			/* rightshift */
    780   1.1.1.9  christos 	 4,			/* size */
    781       1.1     skrll 	 26,			/* bitsize */
    782       1.1     skrll 	 true,			/* pc_relative */
    783       1.1     skrll 	 0,			/* bitpos */
    784       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    785   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    786       1.1     skrll 	 "R_M32R_26_PCREL_RELA",/* name */
    787       1.1     skrll 	 false,			/* partial_inplace */
    788   1.1.1.9  christos 	 0xffffff,		/* src_mask */
    789       1.1     skrll 	 0xffffff,		/* dst_mask */
    790       1.1     skrll 	 true),			/* pcrel_offset */
    791       1.1     skrll 
    792       1.1     skrll   /* High 16 bits of address when lower 16 is or'd in.  */
    793   1.1.1.9  christos   HOWTO (R_M32R_HI16_ULO_RELA,	/* type */
    794       1.1     skrll 	 16,			/* rightshift */
    795   1.1.1.9  christos 	 4,			/* size */
    796       1.1     skrll 	 16,			/* bitsize */
    797       1.1     skrll 	 false,			/* pc_relative */
    798       1.1     skrll 	 0,			/* bitpos */
    799       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    800   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    801       1.1     skrll 	 "R_M32R_HI16_ULO_RELA",/* name */
    802       1.1     skrll 	 false,			/* partial_inplace */
    803   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    804       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    805       1.1     skrll 	 false),		/* pcrel_offset */
    806       1.1     skrll 
    807       1.1     skrll   /* High 16 bits of address when lower 16 is added in.  */
    808   1.1.1.9  christos   HOWTO (R_M32R_HI16_SLO_RELA,	/* type */
    809       1.1     skrll 	 16,			/* rightshift */
    810   1.1.1.9  christos 	 4,			/* size */
    811       1.1     skrll 	 16,			/* bitsize */
    812       1.1     skrll 	 false,			/* pc_relative */
    813       1.1     skrll 	 0,			/* bitpos */
    814       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    815   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    816       1.1     skrll 	 "R_M32R_HI16_SLO_RELA",/* name */
    817       1.1     skrll 	 false,			/* partial_inplace */
    818   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    819       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    820       1.1     skrll 	 false),		/* pcrel_offset */
    821       1.1     skrll 
    822       1.1     skrll   /* Lower 16 bits of address.  */
    823   1.1.1.9  christos   HOWTO (R_M32R_LO16_RELA,	/* type */
    824       1.1     skrll 	 0,			/* rightshift */
    825   1.1.1.9  christos 	 4,			/* size */
    826       1.1     skrll 	 16,			/* bitsize */
    827       1.1     skrll 	 false,			/* pc_relative */
    828       1.1     skrll 	 0,			/* bitpos */
    829       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    830   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    831       1.1     skrll 	 "R_M32R_LO16_RELA",	/* name */
    832       1.1     skrll 	 false,			/* partial_inplace */
    833   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    834       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    835       1.1     skrll 	 false),		/* pcrel_offset */
    836       1.1     skrll 
    837       1.1     skrll   /* Small data area 16 bits offset.  */
    838   1.1.1.9  christos   HOWTO (R_M32R_SDA16_RELA,	/* type */
    839       1.1     skrll 	 0,			/* rightshift */
    840   1.1.1.9  christos 	 4,			/* size */
    841       1.1     skrll 	 16,			/* bitsize */
    842       1.1     skrll 	 false,			/* pc_relative */
    843       1.1     skrll 	 0,			/* bitpos */
    844       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    845   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    846       1.1     skrll 	 "R_M32R_SDA16_RELA",	/* name */
    847       1.1     skrll 	 true,			/* partial_inplace */  /* FIXME: correct? */
    848   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
    849       1.1     skrll 	 0x0000ffff,		/* dst_mask */
    850       1.1     skrll 	 false),		/* pcrel_offset */
    851       1.1     skrll 
    852   1.1.1.6  christos   /* GNU extension to record C++ vtable hierarchy.  */
    853   1.1.1.9  christos   HOWTO (R_M32R_RELA_GNU_VTINHERIT, /* type */
    854   1.1.1.6  christos 	 0,			/* rightshift */
    855   1.1.1.9  christos 	 4,			/* size */
    856   1.1.1.6  christos 	 0,			/* bitsize */
    857   1.1.1.6  christos 	 false,			/* pc_relative */
    858   1.1.1.6  christos 	 0,			/* bitpos */
    859   1.1.1.6  christos 	 complain_overflow_dont, /* complain_on_overflow */
    860   1.1.1.9  christos 	 NULL,			/* special_function */
    861   1.1.1.6  christos 	 "R_M32R_RELA_GNU_VTINHERIT", /* name */
    862   1.1.1.6  christos 	 false,			/* partial_inplace */
    863   1.1.1.9  christos 	 0,			/* src_mask */
    864       1.1     skrll 	 0,			/* dst_mask */
    865       1.1     skrll 	 false),		/* pcrel_offset */
    866       1.1     skrll 
    867   1.1.1.6  christos   /* GNU extension to record C++ vtable member usage.  */
    868   1.1.1.9  christos   HOWTO (R_M32R_RELA_GNU_VTENTRY,     /* type */
    869   1.1.1.6  christos 	 0,			/* rightshift */
    870   1.1.1.9  christos 	 4,			/* size */
    871   1.1.1.6  christos 	 0,			/* bitsize */
    872   1.1.1.6  christos 	 false,			/* pc_relative */
    873   1.1.1.6  christos 	 0,			/* bitpos */
    874   1.1.1.6  christos 	 complain_overflow_dont, /* complain_on_overflow */
    875   1.1.1.9  christos 	 _bfd_elf_rel_vtable_reloc_fn,	/* special_function */
    876   1.1.1.6  christos 	 "R_M32R_RELA_GNU_VTENTRY",   /* name */
    877   1.1.1.6  christos 	 false,			/* partial_inplace */
    878   1.1.1.9  christos 	 0,			/* src_mask */
    879       1.1     skrll 	 0,			/* dst_mask */
    880       1.1     skrll 	 false),		/* pcrel_offset */
    881       1.1     skrll 
    882       1.1     skrll   /* A 32 bit PC relative relocation.  */
    883   1.1.1.9  christos   HOWTO (R_M32R_REL32,		/* type */
    884       1.1     skrll 	 0,			/* rightshift */
    885   1.1.1.9  christos 	 4,			/* size */
    886       1.1     skrll 	 32,			/* bitsize */
    887       1.1     skrll 	 true,			/* pc_relative */
    888       1.1     skrll 	 0,			/* bitpos */
    889       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    890   1.1.1.9  christos 	 bfd_elf_generic_reloc,/* special_function */
    891       1.1     skrll 	 "R_M32R_REL32",		/* name */
    892       1.1     skrll 	 false,			/* partial_inplace */
    893   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    894       1.1     skrll 	 0xffffffff,		/* dst_mask */
    895       1.1     skrll 	 true),			/* pcrel_offset */
    896       1.1     skrll 
    897       1.1     skrll   EMPTY_HOWTO (46),
    898       1.1     skrll   EMPTY_HOWTO (47),
    899       1.1     skrll 
    900       1.1     skrll   /* Like R_M32R_24, but referring to the GOT table entry for
    901       1.1     skrll      the symbol.  */
    902   1.1.1.9  christos   HOWTO (R_M32R_GOT24,		/* type */
    903       1.1     skrll 	 0,			/* rightshift */
    904   1.1.1.9  christos 	 4,			/* size */
    905       1.1     skrll 	 24,			/* bitsize */
    906       1.1     skrll 	 false,			/* pc_relative */
    907       1.1     skrll 	 0,			/* bitpos */
    908       1.1     skrll 	 complain_overflow_unsigned, /* complain_on_overflow */
    909   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
    910       1.1     skrll 	 "R_M32R_GOT24",	/* name */
    911       1.1     skrll 	 false,			/* partial_inplace */
    912   1.1.1.9  christos 	 0xffffff,		/* src_mask */
    913       1.1     skrll 	 0xffffff,		/* dst_mask */
    914       1.1     skrll 	 false),		/* pcrel_offset */
    915       1.1     skrll 
    916       1.1     skrll   /* Like R_M32R_PCREL, but referring to the procedure linkage table
    917       1.1     skrll      entry for the symbol.  */
    918   1.1.1.9  christos   HOWTO (R_M32R_26_PLTREL,	/* type */
    919       1.1     skrll 	 2,			/* rightshift */
    920   1.1.1.9  christos 	 4,			/* size */
    921       1.1     skrll 	 24,			/* bitsize */
    922       1.1     skrll 	 true,			/* pc_relative */
    923       1.1     skrll 	 0,			/* bitpos */
    924       1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    925   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
    926       1.1     skrll 	 "R_M32R_26_PLTREL",	/* name */
    927       1.1     skrll 	 false,			/* partial_inplace */
    928   1.1.1.9  christos 	 0xffffff,		/* src_mask */
    929       1.1     skrll 	 0xffffff,		/* dst_mask */
    930       1.1     skrll 	 true),			/* pcrel_offset */
    931       1.1     skrll 
    932       1.1     skrll   /* This is used only by the dynamic linker.  The symbol should exist
    933       1.1     skrll      both in the object being run and in some shared library.  The
    934       1.1     skrll      dynamic linker copies the data addressed by the symbol from the
    935       1.1     skrll      shared library into the object, because the object being
    936       1.1     skrll      run has to have the data at some particular address.  */
    937   1.1.1.9  christos   HOWTO (R_M32R_COPY,		/* type */
    938       1.1     skrll 	 0,			/* rightshift */
    939   1.1.1.9  christos 	 4,			/* size */
    940       1.1     skrll 	 32,			/* bitsize */
    941       1.1     skrll 	 false,			/* pc_relative */
    942       1.1     skrll 	 0,			/* bitpos */
    943       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    944   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
    945       1.1     skrll 	 "R_M32R_COPY",		/* name */
    946       1.1     skrll 	 false,			/* partial_inplace */
    947   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    948       1.1     skrll 	 0xffffffff,		/* dst_mask */
    949       1.1     skrll 	 false),		/* pcrel_offset */
    950       1.1     skrll 
    951       1.1     skrll   /* Like R_M32R_24, but used when setting global offset table
    952       1.1     skrll      entries.  */
    953   1.1.1.9  christos   HOWTO (R_M32R_GLOB_DAT,	/* type */
    954       1.1     skrll 	 0,			/* rightshift */
    955   1.1.1.9  christos 	 4,			/* size */
    956       1.1     skrll 	 32,			/* bitsize */
    957       1.1     skrll 	 false,			/* pc_relative */
    958       1.1     skrll 	 0,			/* bitpos */
    959       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    960   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
    961       1.1     skrll 	 "R_M32R_GLOB_DAT",	/* name */
    962       1.1     skrll 	 false,			/* partial_inplace */
    963   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    964       1.1     skrll 	 0xffffffff,		/* dst_mask */
    965       1.1     skrll 	 false),		/* pcrel_offset */
    966       1.1     skrll 
    967       1.1     skrll   /* Marks a procedure linkage table entry for a symbol.  */
    968   1.1.1.9  christos   HOWTO (R_M32R_JMP_SLOT,	/* type */
    969       1.1     skrll 	 0,			/* rightshift */
    970   1.1.1.9  christos 	 4,			/* size */
    971       1.1     skrll 	 32,			/* bitsize */
    972       1.1     skrll 	 false,			/* pc_relative */
    973       1.1     skrll 	 0,			/* bitpos */
    974       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    975   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
    976       1.1     skrll 	 "R_M32R_JMP_SLOT",	/* name */
    977       1.1     skrll 	 false,			/* partial_inplace */
    978   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    979       1.1     skrll 	 0xffffffff,		/* dst_mask */
    980       1.1     skrll 	 false),		/* pcrel_offset */
    981       1.1     skrll 
    982       1.1     skrll   /* Used only by the dynamic linker.  When the object is run, this
    983       1.1     skrll      longword is set to the load address of the object, plus the
    984       1.1     skrll      addend.  */
    985   1.1.1.9  christos   HOWTO (R_M32R_RELATIVE,	/* type */
    986       1.1     skrll 	 0,			/* rightshift */
    987   1.1.1.9  christos 	 4,			/* size */
    988       1.1     skrll 	 32,			/* bitsize */
    989       1.1     skrll 	 false,			/* pc_relative */
    990       1.1     skrll 	 0,			/* bitpos */
    991       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    992   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
    993       1.1     skrll 	 "R_M32R_RELATIVE",	/* name */
    994       1.1     skrll 	 false,			/* partial_inplace */
    995   1.1.1.9  christos 	 0xffffffff,		/* src_mask */
    996       1.1     skrll 	 0xffffffff,		/* dst_mask */
    997       1.1     skrll 	 false),		/* pcrel_offset */
    998       1.1     skrll 
    999   1.1.1.9  christos   HOWTO (R_M32R_GOTOFF,		/* type */
   1000       1.1     skrll 	 0,			/* rightshift */
   1001   1.1.1.9  christos 	 4,			/* size */
   1002       1.1     skrll 	 24,			/* bitsize */
   1003       1.1     skrll 	 false,			/* pc_relative */
   1004       1.1     skrll 	 0,			/* bitpos */
   1005       1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
   1006   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
   1007       1.1     skrll 	 "R_M32R_GOTOFF",	/* name */
   1008       1.1     skrll 	 false,			/* partial_inplace */
   1009   1.1.1.9  christos 	 0xffffff,		/* src_mask */
   1010       1.1     skrll 	 0xffffff,		/* dst_mask */
   1011       1.1     skrll 	 false),		/* pcrel_offset */
   1012       1.1     skrll 
   1013       1.1     skrll   /* An PC Relative 24-bit relocation used when setting PIC offset
   1014       1.1     skrll      table register. */
   1015   1.1.1.9  christos   HOWTO (R_M32R_GOTPC24,	/* type */
   1016       1.1     skrll 	 0,			/* rightshift */
   1017   1.1.1.9  christos 	 4,			/* size */
   1018       1.1     skrll 	 24,			/* bitsize */
   1019       1.1     skrll 	 true,			/* pc_relative */
   1020       1.1     skrll 	 0,			/* bitpos */
   1021       1.1     skrll 	 complain_overflow_unsigned, /* complain_on_overflow */
   1022   1.1.1.9  christos 	 bfd_elf_generic_reloc, /* special_function */
   1023       1.1     skrll 	 "R_M32R_GOTPC24",	/* name */
   1024       1.1     skrll 	 false,			/* partial_inplace */
   1025   1.1.1.9  christos 	 0xffffff,		/* src_mask */
   1026       1.1     skrll 	 0xffffff,		/* dst_mask */
   1027       1.1     skrll 	 true),			/* pcrel_offset */
   1028       1.1     skrll 
   1029       1.1     skrll   /* Like R_M32R_HI16_ULO, but referring to the GOT table entry for
   1030       1.1     skrll      the symbol.  */
   1031   1.1.1.9  christos   HOWTO (R_M32R_GOT16_HI_ULO,	/* type */
   1032       1.1     skrll 	 16,			/* rightshift */
   1033   1.1.1.9  christos 	 4,			/* size */
   1034       1.1     skrll 	 16,			/* bitsize */
   1035       1.1     skrll 	 false,			/* pc_relative */
   1036       1.1     skrll 	 0,			/* bitpos */
   1037       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1038   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1039       1.1     skrll 	 "R_M32R_GOT16_HI_ULO",	/* name */
   1040       1.1     skrll 	 false,			/* partial_inplace */
   1041   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1042       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1043       1.1     skrll 	 false),		/* pcrel_offset */
   1044       1.1     skrll 
   1045       1.1     skrll   /* Like R_M32R_HI16_SLO, but referring to the GOT table entry for
   1046       1.1     skrll      the symbol.  */
   1047   1.1.1.9  christos   HOWTO (R_M32R_GOT16_HI_SLO,	/* type */
   1048       1.1     skrll 	 16,			/* rightshift */
   1049   1.1.1.9  christos 	 4,			/* size */
   1050       1.1     skrll 	 16,			/* bitsize */
   1051       1.1     skrll 	 false,			/* pc_relative */
   1052       1.1     skrll 	 0,			/* bitpos */
   1053       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1054   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1055       1.1     skrll 	 "R_M32R_GOT16_HI_SLO",	/* name */
   1056       1.1     skrll 	 false,			/* partial_inplace */
   1057   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1058       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1059       1.1     skrll 	 false),		/* pcrel_offset */
   1060       1.1     skrll 
   1061       1.1     skrll   /* Like R_M32R_LO16, but referring to the GOT table entry for
   1062       1.1     skrll      the symbol.  */
   1063   1.1.1.9  christos   HOWTO (R_M32R_GOT16_LO,	/* type */
   1064       1.1     skrll 	 0,			/* rightshift */
   1065   1.1.1.9  christos 	 4,			/* size */
   1066       1.1     skrll 	 16,			/* bitsize */
   1067       1.1     skrll 	 false,			/* pc_relative */
   1068       1.1     skrll 	 0,			/* bitpos */
   1069       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1070   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1071       1.1     skrll 	 "R_M32R_GOT16_LO",	/* name */
   1072       1.1     skrll 	 false,			/* partial_inplace */
   1073   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1074       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1075       1.1     skrll 	 false),		/* pcrel_offset */
   1076       1.1     skrll 
   1077       1.1     skrll   /* An PC Relative relocation used when setting PIC offset table register.
   1078       1.1     skrll      Like R_M32R_HI16_ULO, but referring to the GOT table entry for
   1079       1.1     skrll      the symbol.  */
   1080   1.1.1.9  christos   HOWTO (R_M32R_GOTPC_HI_ULO,	/* type */
   1081       1.1     skrll 	 16,			/* rightshift */
   1082   1.1.1.9  christos 	 4,			/* size */
   1083       1.1     skrll 	 16,			/* bitsize */
   1084       1.1     skrll 	 false,			/* pc_relative */
   1085       1.1     skrll 	 0,			/* bitpos */
   1086       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1087   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1088       1.1     skrll 	 "R_M32R_GOTPC_HI_ULO",	/* name */
   1089       1.1     skrll 	 false,			/* partial_inplace */
   1090   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1091       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1092       1.1     skrll 	 true),			/* pcrel_offset */
   1093       1.1     skrll 
   1094       1.1     skrll   /* An PC Relative relocation used when setting PIC offset table register.
   1095       1.1     skrll      Like R_M32R_HI16_SLO, but referring to the GOT table entry for
   1096       1.1     skrll      the symbol.  */
   1097   1.1.1.9  christos   HOWTO (R_M32R_GOTPC_HI_SLO,	/* type */
   1098       1.1     skrll 	 16,			/* rightshift */
   1099   1.1.1.9  christos 	 4,			/* size */
   1100       1.1     skrll 	 16,			/* bitsize */
   1101       1.1     skrll 	 false,			/* pc_relative */
   1102       1.1     skrll 	 0,			/* bitpos */
   1103       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1104   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1105       1.1     skrll 	 "R_M32R_GOTPC_HI_SLO",	/* name */
   1106       1.1     skrll 	 false,			/* partial_inplace */
   1107   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1108       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1109       1.1     skrll 	 true),			/* pcrel_offset */
   1110       1.1     skrll 
   1111       1.1     skrll   /* An PC Relative relocation used when setting PIC offset table register.
   1112       1.1     skrll      Like R_M32R_LO16, but referring to the GOT table entry for
   1113       1.1     skrll      the symbol.  */
   1114   1.1.1.9  christos   HOWTO (R_M32R_GOTPC_LO,	/* type */
   1115       1.1     skrll 	 0,			/* rightshift */
   1116   1.1.1.9  christos 	 4,			/* size */
   1117       1.1     skrll 	 16,			/* bitsize */
   1118       1.1     skrll 	 false,			/* pc_relative */
   1119       1.1     skrll 	 0,			/* bitpos */
   1120       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1121   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1122       1.1     skrll 	 "R_M32R_GOTPC_LO",	/* name */
   1123       1.1     skrll 	 false,			/* partial_inplace */
   1124   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1125       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1126       1.1     skrll 	 true),			/* pcrel_offset */
   1127       1.1     skrll 
   1128   1.1.1.9  christos   HOWTO (R_M32R_GOTOFF_HI_ULO,	/* type */
   1129       1.1     skrll 	 16,			/* rightshift */
   1130   1.1.1.9  christos 	 4,			/* size */
   1131       1.1     skrll 	 16,			/* bitsize */
   1132       1.1     skrll 	 false,			/* pc_relative */
   1133       1.1     skrll 	 0,			/* bitpos */
   1134       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1135   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1136       1.1     skrll 	 "R_M32R_GOTOFF_HI_ULO",/* name */
   1137       1.1     skrll 	 false,			/* partial_inplace */
   1138   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1139       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1140       1.1     skrll 	 false),		/* pcrel_offset */
   1141       1.1     skrll 
   1142   1.1.1.9  christos   HOWTO (R_M32R_GOTOFF_HI_SLO,	/* type */
   1143       1.1     skrll 	 16,			/* rightshift */
   1144   1.1.1.9  christos 	 4,			/* size */
   1145       1.1     skrll 	 16,			/* bitsize */
   1146       1.1     skrll 	 false,			/* pc_relative */
   1147       1.1     skrll 	 0,			/* bitpos */
   1148       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1149   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1150       1.1     skrll 	 "R_M32R_GOTOFF_HI_SLO",/* name */
   1151       1.1     skrll 	 false,			/* partial_inplace */
   1152   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1153       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1154       1.1     skrll 	 false),		/* pcrel_offset */
   1155       1.1     skrll 
   1156   1.1.1.9  christos   HOWTO (R_M32R_GOTOFF_LO,	/* type */
   1157       1.1     skrll 	 0,			/* rightshift */
   1158   1.1.1.9  christos 	 4,			/* size */
   1159       1.1     skrll 	 16,			/* bitsize */
   1160       1.1     skrll 	 false,			/* pc_relative */
   1161       1.1     skrll 	 0,			/* bitpos */
   1162       1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
   1163   1.1.1.9  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1164       1.1     skrll 	 "R_M32R_GOTOFF_LO",	/* name */
   1165       1.1     skrll 	 false,			/* partial_inplace */
   1166   1.1.1.9  christos 	 0x0000ffff,		/* src_mask */
   1167       1.1     skrll 	 0x0000ffff,		/* dst_mask */
   1168       1.1     skrll 	 false),		/* pcrel_offset */
   1169       1.1     skrll };
   1170       1.1     skrll 
   1171       1.1     skrll /* Map BFD reloc types to M32R ELF reloc types.  */
   1172       1.1     skrll 
   1173       1.1     skrll struct m32r_reloc_map
   1174       1.1     skrll {
   1175       1.1     skrll   bfd_reloc_code_real_type bfd_reloc_val;
   1176       1.1     skrll   unsigned char elf_reloc_val;
   1177       1.1     skrll };
   1178       1.1     skrll 
   1179       1.1     skrll #ifdef USE_M32R_OLD_RELOC
   1180       1.1     skrll static const struct m32r_reloc_map m32r_reloc_map_old[] =
   1181       1.1     skrll {
   1182       1.1     skrll   { BFD_RELOC_NONE, R_M32R_NONE },
   1183       1.1     skrll   { BFD_RELOC_16, R_M32R_16 },
   1184       1.1     skrll   { BFD_RELOC_32, R_M32R_32 },
   1185       1.1     skrll   { BFD_RELOC_M32R_24, R_M32R_24 },
   1186       1.1     skrll   { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL },
   1187       1.1     skrll   { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL },
   1188       1.1     skrll   { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL },
   1189       1.1     skrll   { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO },
   1190       1.1     skrll   { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO },
   1191       1.1     skrll   { BFD_RELOC_M32R_LO16, R_M32R_LO16 },
   1192       1.1     skrll   { BFD_RELOC_M32R_SDA16, R_M32R_SDA16 },
   1193       1.1     skrll   { BFD_RELOC_VTABLE_INHERIT, R_M32R_GNU_VTINHERIT },
   1194       1.1     skrll   { BFD_RELOC_VTABLE_ENTRY, R_M32R_GNU_VTENTRY },
   1195       1.1     skrll };
   1196       1.1     skrll #else
   1197       1.1     skrll static const struct m32r_reloc_map m32r_reloc_map[] =
   1198       1.1     skrll {
   1199       1.1     skrll   { BFD_RELOC_NONE, R_M32R_NONE },
   1200       1.1     skrll   { BFD_RELOC_16, R_M32R_16_RELA },
   1201       1.1     skrll   { BFD_RELOC_32, R_M32R_32_RELA },
   1202       1.1     skrll   { BFD_RELOC_M32R_24, R_M32R_24_RELA },
   1203       1.1     skrll   { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL_RELA },
   1204       1.1     skrll   { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL_RELA },
   1205       1.1     skrll   { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL_RELA },
   1206       1.1     skrll   { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO_RELA },
   1207       1.1     skrll   { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO_RELA },
   1208       1.1     skrll   { BFD_RELOC_M32R_LO16, R_M32R_LO16_RELA },
   1209       1.1     skrll   { BFD_RELOC_M32R_SDA16, R_M32R_SDA16_RELA },
   1210       1.1     skrll   { BFD_RELOC_VTABLE_INHERIT, R_M32R_RELA_GNU_VTINHERIT },
   1211       1.1     skrll   { BFD_RELOC_VTABLE_ENTRY, R_M32R_RELA_GNU_VTENTRY },
   1212       1.1     skrll   { BFD_RELOC_32_PCREL, R_M32R_REL32 },
   1213       1.1     skrll 
   1214  1.1.1.12  christos   { BFD_RELOC_M32R_GOT24, R_M32R_GOT24 },
   1215  1.1.1.12  christos   { BFD_RELOC_M32R_26_PLTREL, R_M32R_26_PLTREL },
   1216  1.1.1.12  christos   { BFD_RELOC_COPY, R_M32R_COPY },
   1217  1.1.1.12  christos   { BFD_RELOC_GLOB_DAT, R_M32R_GLOB_DAT },
   1218       1.1     skrll   { BFD_RELOC_JMP_SLOT, R_M32R_JMP_SLOT },
   1219       1.1     skrll   { BFD_RELOC_RELATIVE, R_M32R_RELATIVE },
   1220       1.1     skrll   { BFD_RELOC_M32R_GOTOFF, R_M32R_GOTOFF },
   1221       1.1     skrll   { BFD_RELOC_M32R_GOTPC24, R_M32R_GOTPC24 },
   1222       1.1     skrll   { BFD_RELOC_M32R_GOT16_HI_ULO, R_M32R_GOT16_HI_ULO },
   1223       1.1     skrll   { BFD_RELOC_M32R_GOT16_HI_SLO, R_M32R_GOT16_HI_SLO },
   1224       1.1     skrll   { BFD_RELOC_M32R_GOT16_LO, R_M32R_GOT16_LO },
   1225       1.1     skrll   { BFD_RELOC_M32R_GOTPC_HI_ULO, R_M32R_GOTPC_HI_ULO },
   1226       1.1     skrll   { BFD_RELOC_M32R_GOTPC_HI_SLO, R_M32R_GOTPC_HI_SLO },
   1227       1.1     skrll   { BFD_RELOC_M32R_GOTPC_LO, R_M32R_GOTPC_LO },
   1228       1.1     skrll   { BFD_RELOC_M32R_GOTOFF_HI_ULO, R_M32R_GOTOFF_HI_ULO },
   1229       1.1     skrll   { BFD_RELOC_M32R_GOTOFF_HI_SLO, R_M32R_GOTOFF_HI_SLO },
   1230       1.1     skrll   { BFD_RELOC_M32R_GOTOFF_LO, R_M32R_GOTOFF_LO },
   1231       1.1     skrll };
   1232       1.1     skrll #endif
   1233       1.1     skrll 
   1234       1.1     skrll static reloc_howto_type *
   1235       1.1     skrll bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1236       1.1     skrll 				 bfd_reloc_code_real_type code)
   1237       1.1     skrll {
   1238       1.1     skrll   unsigned int i;
   1239       1.1     skrll 
   1240       1.1     skrll #ifdef USE_M32R_OLD_RELOC
   1241       1.1     skrll   for (i = 0;
   1242       1.1     skrll        i < sizeof (m32r_reloc_map_old) / sizeof (struct m32r_reloc_map);
   1243       1.1     skrll        i++)
   1244       1.1     skrll     if (m32r_reloc_map_old[i].bfd_reloc_val == code)
   1245       1.1     skrll       return &m32r_elf_howto_table[m32r_reloc_map_old[i].elf_reloc_val];
   1246       1.1     skrll 
   1247       1.1     skrll #else /* ! USE_M32R_OLD_RELOC */
   1248       1.1     skrll 
   1249       1.1     skrll   for (i = 0;
   1250       1.1     skrll        i < sizeof (m32r_reloc_map) / sizeof (struct m32r_reloc_map);
   1251       1.1     skrll        i++)
   1252       1.1     skrll     if (m32r_reloc_map[i].bfd_reloc_val == code)
   1253       1.1     skrll       return &m32r_elf_howto_table[m32r_reloc_map[i].elf_reloc_val];
   1254       1.1     skrll #endif
   1255       1.1     skrll 
   1256       1.1     skrll   return NULL;
   1257       1.1     skrll }
   1258       1.1     skrll 
   1259       1.1     skrll static reloc_howto_type *
   1260       1.1     skrll bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1261       1.1     skrll 				 const char *r_name)
   1262       1.1     skrll {
   1263       1.1     skrll   unsigned int i;
   1264       1.1     skrll 
   1265       1.1     skrll   for (i = 0;
   1266       1.1     skrll        i < sizeof (m32r_elf_howto_table) / sizeof (m32r_elf_howto_table[0]);
   1267       1.1     skrll        i++)
   1268       1.1     skrll     if (m32r_elf_howto_table[i].name != NULL
   1269       1.1     skrll 	&& strcasecmp (m32r_elf_howto_table[i].name, r_name) == 0)
   1270       1.1     skrll       return &m32r_elf_howto_table[i];
   1271       1.1     skrll 
   1272       1.1     skrll   return NULL;
   1273       1.1     skrll }
   1274       1.1     skrll 
   1275   1.1.1.9  christos /* Set the howto pointer for an M32R ELF reloc.  */
   1276       1.1     skrll 
   1277       1.1     skrll static bool
   1278       1.1     skrll m32r_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   1279       1.1     skrll 			arelent *cache_ptr,
   1280       1.1     skrll 			Elf_Internal_Rela *dst)
   1281       1.1     skrll {
   1282       1.1     skrll   unsigned int r_type;
   1283   1.1.1.4  christos 
   1284   1.1.1.4  christos   r_type = ELF32_R_TYPE (dst->r_info);
   1285   1.1.1.6  christos   if (r_type > (unsigned int) R_M32R_GNU_VTENTRY)
   1286   1.1.1.7  christos     {
   1287   1.1.1.7  christos       /* xgettext:c-format */
   1288   1.1.1.7  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1289   1.1.1.9  christos 			  abfd, r_type);
   1290   1.1.1.4  christos       bfd_set_error (bfd_error_bad_value);
   1291       1.1     skrll       return false;
   1292   1.1.1.9  christos     }
   1293       1.1     skrll   cache_ptr->howto = &m32r_elf_howto_table[r_type];
   1294       1.1     skrll   return true;
   1295   1.1.1.9  christos }
   1296       1.1     skrll 
   1297       1.1     skrll static bool
   1298       1.1     skrll m32r_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   1299       1.1     skrll 		    arelent *cache_ptr,
   1300   1.1.1.7  christos 		    Elf_Internal_Rela *dst)
   1301   1.1.1.7  christos {
   1302   1.1.1.7  christos   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
   1303   1.1.1.7  christos 
   1304   1.1.1.7  christos   if (r_type == (unsigned int) R_M32R_NONE
   1305   1.1.1.7  christos       || ((r_type > (unsigned int) R_M32R_GNU_VTENTRY)
   1306   1.1.1.7  christos 	  && (r_type < (unsigned int) R_M32R_max)))
   1307   1.1.1.9  christos     {
   1308   1.1.1.7  christos       cache_ptr->howto = &m32r_elf_howto_table[r_type];
   1309   1.1.1.7  christos       return true;
   1310   1.1.1.7  christos     }
   1311   1.1.1.7  christos 
   1312   1.1.1.7  christos   /* xgettext:c-format */
   1313   1.1.1.9  christos   _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
   1314       1.1     skrll   bfd_set_error (bfd_error_bad_value);
   1315       1.1     skrll   return false;
   1316       1.1     skrll }
   1317       1.1     skrll 
   1318       1.1     skrll 
   1319       1.1     skrll /* Given a BFD section, try to locate the corresponding ELF section
   1321       1.1     skrll    index.  */
   1322       1.1     skrll 
   1323       1.1     skrll static bool
   1324       1.1     skrll _bfd_m32r_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
   1325   1.1.1.8  christos 					asection *sec,
   1326       1.1     skrll 					int *retval)
   1327       1.1     skrll {
   1328   1.1.1.9  christos   if (strcmp (bfd_section_name (sec), ".scommon") == 0)
   1329       1.1     skrll     {
   1330   1.1.1.9  christos       *retval = SHN_M32R_SCOMMON;
   1331       1.1     skrll       return true;
   1332       1.1     skrll     }
   1333       1.1     skrll   return false;
   1334       1.1     skrll }
   1335       1.1     skrll 
   1336       1.1     skrll /* M32R ELF uses two common sections.  One is the usual one, and the other
   1337       1.1     skrll    is for small objects.  All the small objects are kept together, and then
   1338       1.1     skrll    referenced via one register, which yields faster assembler code.  It is
   1339       1.1     skrll    up to the compiler to emit an instruction to load the register with
   1340   1.1.1.9  christos    _SDA_BASE.  This is what we use for the small common section.  This
   1341   1.1.1.9  christos    approach is copied from elf32-mips.c.  */
   1342   1.1.1.9  christos static asection m32r_elf_scom_section;
   1343   1.1.1.9  christos static const asymbol m32r_elf_scom_symbol =
   1344   1.1.1.9  christos   GLOBAL_SYM_INIT (".scommon", &m32r_elf_scom_section);
   1345       1.1     skrll static asection m32r_elf_scom_section =
   1346       1.1     skrll   BFD_FAKE_SECTION (m32r_elf_scom_section, &m32r_elf_scom_symbol,
   1347       1.1     skrll 		    ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
   1348       1.1     skrll 
   1349       1.1     skrll /* Handle the special M32R section numbers that a symbol may use.  */
   1350       1.1     skrll 
   1351       1.1     skrll static void
   1352       1.1     skrll _bfd_m32r_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
   1353       1.1     skrll {
   1354       1.1     skrll   elf_symbol_type *elfsym = (elf_symbol_type *) asym;
   1355       1.1     skrll 
   1356       1.1     skrll   switch (elfsym->internal_elf_sym.st_shndx)
   1357       1.1     skrll     {
   1358       1.1     skrll     case SHN_M32R_SCOMMON:
   1359       1.1     skrll       asym->section = &m32r_elf_scom_section;
   1360       1.1     skrll       asym->value = elfsym->internal_elf_sym.st_size;
   1361       1.1     skrll       break;
   1362       1.1     skrll     }
   1363       1.1     skrll }
   1364       1.1     skrll 
   1365       1.1     skrll /* Hook called by the linker routine which adds symbols from an object
   1366       1.1     skrll    file.  We must handle the special M32R section numbers here.
   1367   1.1.1.9  christos    We also keep watching for whether we need to create the sdata special
   1368       1.1     skrll    linker sections.  */
   1369       1.1     skrll 
   1370       1.1     skrll static bool
   1371       1.1     skrll m32r_elf_add_symbol_hook (bfd *abfd,
   1372       1.1     skrll 			  struct bfd_link_info *info,
   1373       1.1     skrll 			  Elf_Internal_Sym *sym,
   1374       1.1     skrll 			  const char **namep,
   1375       1.1     skrll 			  flagword *flagsp ATTRIBUTE_UNUSED,
   1376   1.1.1.4  christos 			  asection **secp,
   1377       1.1     skrll 			  bfd_vma *valp)
   1378       1.1     skrll {
   1379       1.1     skrll   if (! bfd_link_relocatable (info)
   1380       1.1     skrll       && (*namep)[0] == '_' && (*namep)[1] == 'S'
   1381       1.1     skrll       && strcmp (*namep, "_SDA_BASE_") == 0
   1382       1.1     skrll       && is_elf_hash_table (info->hash))
   1383       1.1     skrll     {
   1384       1.1     skrll       /* This is simpler than using _bfd_elf_create_linker_section
   1385       1.1     skrll 	 (our needs are simpler than ppc's needs).  Also
   1386       1.1     skrll 	 _bfd_elf_create_linker_section currently has a bug where if a .sdata
   1387       1.1     skrll 	 section already exists a new one is created that follows it which
   1388       1.1     skrll 	 screws of _SDA_BASE_ address calcs because output_offset != 0.  */
   1389       1.1     skrll       struct elf_link_hash_entry *h;
   1390       1.1     skrll       struct bfd_link_hash_entry *bh;
   1391       1.1     skrll       asection *s = bfd_get_section_by_name (abfd, ".sdata");
   1392       1.1     skrll 
   1393       1.1     skrll       /* The following code was cobbled from elf32-ppc.c and elflink.c.  */
   1394       1.1     skrll       if (s == NULL)
   1395       1.1     skrll 	{
   1396       1.1     skrll 	  flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
   1397       1.1     skrll 			    | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   1398       1.1     skrll 
   1399   1.1.1.9  christos 	  s = bfd_make_section_anyway_with_flags (abfd, ".sdata",
   1400   1.1.1.8  christos 						  flags);
   1401   1.1.1.9  christos 	  if (s == NULL)
   1402       1.1     skrll 	    return false;
   1403       1.1     skrll 	  if (!bfd_set_section_alignment (s, 2))
   1404       1.1     skrll 	    return false;
   1405   1.1.1.9  christos 	}
   1406       1.1     skrll 
   1407       1.1     skrll       bh = bfd_link_hash_lookup (info->hash, "_SDA_BASE_",
   1408       1.1     skrll 				 false, false, false);
   1409       1.1     skrll 
   1410       1.1     skrll       if ((bh == NULL || bh->type == bfd_link_hash_undefined)
   1411       1.1     skrll 	  && !(_bfd_generic_link_add_one_symbol (info,
   1412       1.1     skrll 						 abfd,
   1413       1.1     skrll 						 "_SDA_BASE_",
   1414       1.1     skrll 						 BSF_GLOBAL,
   1415   1.1.1.9  christos 						 s,
   1416       1.1     skrll 						 (bfd_vma) 32768,
   1417       1.1     skrll 						 NULL,
   1418   1.1.1.9  christos 						 false,
   1419       1.1     skrll 						 get_elf_backend_data (abfd)->collect,
   1420       1.1     skrll 						 &bh)))
   1421       1.1     skrll 	return false;
   1422       1.1     skrll       h = (struct elf_link_hash_entry *) bh;
   1423       1.1     skrll       h->type = STT_OBJECT;
   1424       1.1     skrll     }
   1425       1.1     skrll 
   1426       1.1     skrll   switch (sym->st_shndx)
   1427   1.1.1.9  christos     {
   1428       1.1     skrll     case SHN_M32R_SCOMMON:
   1429       1.1     skrll       *secp = bfd_make_section_old_way (abfd, ".scommon");
   1430       1.1     skrll       (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
   1431       1.1     skrll       *valp = sym->st_size;
   1432   1.1.1.9  christos       break;
   1433       1.1     skrll     }
   1434       1.1     skrll 
   1435       1.1     skrll   return true;
   1436       1.1     skrll }
   1437       1.1     skrll 
   1438       1.1     skrll /* We have to figure out the SDA_BASE value, so that we can adjust the
   1439       1.1     skrll    symbol value correctly.  We look up the symbol _SDA_BASE_ in the output
   1440       1.1     skrll    BFD.  If we can't find it, we're stuck.  We cache it in the ELF
   1441       1.1     skrll    target data.  We don't need to adjust the symbol value for an
   1442       1.1     skrll    external symbol if we are producing relocatable output.  */
   1443       1.1     skrll 
   1444       1.1     skrll static bfd_reloc_status_type
   1445       1.1     skrll m32r_elf_final_sda_base (bfd *output_bfd,
   1446       1.1     skrll 			 struct bfd_link_info *info,
   1447       1.1     skrll 			 const char **error_message,
   1448       1.1     skrll 			 bfd_vma *psb)
   1449       1.1     skrll {
   1450       1.1     skrll   if (elf_gp (output_bfd) == 0)
   1451   1.1.1.9  christos     {
   1452       1.1     skrll       struct bfd_link_hash_entry *h;
   1453       1.1     skrll 
   1454       1.1     skrll       h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", false, false, true);
   1455       1.1     skrll       if (h != NULL && h->type == bfd_link_hash_defined)
   1456       1.1     skrll 	elf_gp (output_bfd) = (h->u.def.value
   1457       1.1     skrll 			       + h->u.def.section->output_section->vma
   1458       1.1     skrll 			       + h->u.def.section->output_offset);
   1459       1.1     skrll       else
   1460       1.1     skrll 	{
   1461       1.1     skrll 	  /* Only get the error once.  */
   1462       1.1     skrll 	  *psb = elf_gp (output_bfd) = 4;
   1463       1.1     skrll 	  *error_message =
   1464       1.1     skrll 	    (const char *) _("SDA relocation when _SDA_BASE_ not defined");
   1465       1.1     skrll 	  return bfd_reloc_dangerous;
   1466       1.1     skrll 	}
   1467       1.1     skrll     }
   1468       1.1     skrll   *psb = elf_gp (output_bfd);
   1469       1.1     skrll   return bfd_reloc_ok;
   1470       1.1     skrll }
   1471       1.1     skrll 
   1472       1.1     skrll /* Return size of a PLT entry.  */
   1474       1.1     skrll #define elf_m32r_sizeof_plt(info) PLT_ENTRY_SIZE
   1475       1.1     skrll 
   1476       1.1     skrll /* The m32r linker needs to keep track of the number of relocs that it
   1477       1.1     skrll    decides to copy in check_relocs for each symbol.  This is so that
   1478       1.1     skrll    it can discard PC relative relocs if it doesn't need them when
   1479       1.1     skrll    linking with -Bsymbolic.  We store the information in a field
   1480       1.1     skrll    extending the regular ELF linker hash table.  */
   1481       1.1     skrll 
   1482       1.1     skrll /* This structure keeps track of the number of PC relative relocs we
   1483       1.1     skrll    have copied for a given symbol.  */
   1484       1.1     skrll 
   1485       1.1     skrll struct elf_m32r_pcrel_relocs_copied
   1486       1.1     skrll {
   1487       1.1     skrll   /* Next section.  */
   1488       1.1     skrll   struct elf_m32r_pcrel_relocs_copied *next;
   1489       1.1     skrll   /* A section in dynobj.  */
   1490       1.1     skrll   asection *section;
   1491       1.1     skrll   /* Number of relocs copied in this section.  */
   1492       1.1     skrll   bfd_size_type count;
   1493       1.1     skrll };
   1494       1.1     skrll 
   1495       1.1     skrll /* Traverse an m32r ELF linker hash table.  */
   1496   1.1.1.9  christos 
   1497       1.1     skrll #define m32r_elf_link_hash_traverse(table, func, info)			\
   1498       1.1     skrll   (elf_link_hash_traverse						\
   1499       1.1     skrll    (&(table)->root,							\
   1500       1.1     skrll     (bool (*) (struct elf_link_hash_entry *, void *)) (func),		\
   1501       1.1     skrll     (info)))
   1502   1.1.1.9  christos 
   1503   1.1.1.9  christos /* Get the m32r ELF linker hash table from a link_info structure.  */
   1504   1.1.1.9  christos 
   1505       1.1     skrll #define m32r_elf_hash_table(p) \
   1506       1.1     skrll   ((is_elf_hash_table ((p)->hash)					\
   1507       1.1     skrll     && elf_hash_table_id (elf_hash_table (p)) == M32R_ELF_DATA)		\
   1508       1.1     skrll    ? (struct elf_link_hash_table *) (p)->hash : NULL)
   1509       1.1     skrll 
   1510       1.1     skrll /* Create an m32r ELF linker hash table.  */
   1511   1.1.1.9  christos 
   1512   1.1.1.9  christos static struct bfd_link_hash_table *
   1513       1.1     skrll m32r_elf_link_hash_table_create (bfd *abfd)
   1514   1.1.1.4  christos {
   1515       1.1     skrll   struct elf_link_hash_table *ret;
   1516       1.1     skrll   size_t amt = sizeof (struct elf_link_hash_table);
   1517       1.1     skrll 
   1518   1.1.1.9  christos   ret = bfd_zmalloc (amt);
   1519   1.1.1.9  christos   if (ret == NULL)
   1520  1.1.1.11  christos     return NULL;
   1521       1.1     skrll 
   1522       1.1     skrll   if (!_bfd_elf_link_hash_table_init (ret, abfd,
   1523       1.1     skrll 				      _bfd_elf_link_hash_newfunc,
   1524       1.1     skrll 				      sizeof (struct elf_link_hash_entry)))
   1525       1.1     skrll     {
   1526   1.1.1.9  christos       free (ret);
   1527       1.1     skrll       return NULL;
   1528       1.1     skrll     }
   1529       1.1     skrll 
   1530       1.1     skrll   return &ret->root;
   1531   1.1.1.9  christos }
   1532       1.1     skrll 
   1533       1.1     skrll /* Create dynamic sections when linking against a dynamic object.  */
   1534   1.1.1.9  christos 
   1535       1.1     skrll static bool
   1536       1.1     skrll m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   1537  1.1.1.12  christos {
   1538       1.1     skrll   struct elf_link_hash_table *htab;
   1539       1.1     skrll   flagword flags, pltflags;
   1540       1.1     skrll   asection *s;
   1541   1.1.1.2  christos   elf_backend_data *bed = get_elf_backend_data (abfd);
   1542   1.1.1.9  christos   int ptralign = 2; /* 32bit */
   1543       1.1     skrll 
   1544       1.1     skrll   htab = m32r_elf_hash_table (info);
   1545       1.1     skrll   if (htab == NULL)
   1546       1.1     skrll     return false;
   1547   1.1.1.6  christos 
   1548       1.1     skrll   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
   1549       1.1     skrll      .rel[a].bss sections.  */
   1550       1.1     skrll   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
   1551       1.1     skrll 	   | SEC_LINKER_CREATED);
   1552       1.1     skrll 
   1553       1.1     skrll   pltflags = flags;
   1554       1.1     skrll   pltflags |= SEC_CODE;
   1555       1.1     skrll   if (bed->plt_not_loaded)
   1556   1.1.1.3  christos     pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
   1557   1.1.1.9  christos   if (bed->plt_readonly)
   1558       1.1     skrll     pltflags |= SEC_READONLY;
   1559   1.1.1.8  christos 
   1560   1.1.1.9  christos   s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
   1561       1.1     skrll   htab->splt = s;
   1562       1.1     skrll   if (s == NULL
   1563       1.1     skrll       || !bfd_set_section_alignment (s, bed->plt_alignment))
   1564       1.1     skrll     return false;
   1565   1.1.1.6  christos 
   1566       1.1     skrll   if (bed->want_plt_sym)
   1567       1.1     skrll     {
   1568       1.1     skrll       /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
   1569       1.1     skrll 	 .plt section.  */
   1570   1.1.1.6  christos       struct bfd_link_hash_entry *bh = NULL;
   1571   1.1.1.9  christos       struct elf_link_hash_entry *h;
   1572   1.1.1.6  christos 
   1573   1.1.1.9  christos       if (! (_bfd_generic_link_add_one_symbol
   1574       1.1     skrll 	     (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
   1575       1.1     skrll 	      (bfd_vma) 0, NULL, false,
   1576       1.1     skrll 	      get_elf_backend_data (abfd)->collect, &bh)))
   1577   1.1.1.9  christos 	return false;
   1578       1.1     skrll       h = (struct elf_link_hash_entry *) bh;
   1579   1.1.1.4  christos       h->def_regular = 1;
   1580   1.1.1.6  christos       h->type = STT_OBJECT;
   1581   1.1.1.9  christos       htab->hplt = h;
   1582       1.1     skrll 
   1583       1.1     skrll       if (bfd_link_pic (info)
   1584   1.1.1.3  christos 	  && ! bfd_elf_link_record_dynamic_symbol (info, h))
   1585   1.1.1.3  christos 	return false;
   1586   1.1.1.3  christos     }
   1587   1.1.1.3  christos 
   1588   1.1.1.9  christos   s = bfd_make_section_anyway_with_flags (abfd,
   1589       1.1     skrll 					  bed->default_use_rela_p
   1590   1.1.1.8  christos 					  ? ".rela.plt" : ".rel.plt",
   1591   1.1.1.9  christos 					  flags | SEC_READONLY);
   1592       1.1     skrll   htab->srelplt = s;
   1593   1.1.1.9  christos   if (s == NULL
   1594   1.1.1.6  christos       || !bfd_set_section_alignment (s, ptralign))
   1595   1.1.1.9  christos     return false;
   1596       1.1     skrll 
   1597       1.1     skrll   if (htab->sgot == NULL
   1598       1.1     skrll       && !_bfd_elf_create_got_section (abfd, info))
   1599       1.1     skrll     return false;
   1600   1.1.1.6  christos 
   1601   1.1.1.6  christos   if (bed->want_dynbss)
   1602   1.1.1.6  christos     {
   1603   1.1.1.6  christos       /* The .dynbss section is a place to put symbols which are defined
   1604   1.1.1.6  christos 	 by dynamic objects, are referenced by regular objects, and are
   1605   1.1.1.3  christos 	 not functions.  We must allocate space for them in the process
   1606   1.1.1.3  christos 	 image and use a R_*_COPY reloc to tell the dynamic linker to
   1607       1.1     skrll 	 initialize them at run time.  The linker script puts the .dynbss
   1608       1.1     skrll 	 section into the .bss section of the final image.  */
   1609   1.1.1.9  christos       s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
   1610       1.1     skrll 					      SEC_ALLOC | SEC_LINKER_CREATED);
   1611   1.1.1.6  christos       htab->sdynbss = s;
   1612   1.1.1.6  christos       if (s == NULL)
   1613   1.1.1.6  christos 	return false;
   1614   1.1.1.6  christos       /* The .rel[a].bss section holds copy relocs.  This section is not
   1615   1.1.1.6  christos 	 normally needed.  We need to create it here, though, so that the
   1616   1.1.1.6  christos 	 linker will map it to an output section.  We can't just create it
   1617   1.1.1.6  christos 	 only if we need it, because we will not know whether we need it
   1618   1.1.1.6  christos 	 until we have seen all the input files, and the first time the
   1619   1.1.1.6  christos 	 main linker code calls BFD after examining all the input files
   1620   1.1.1.6  christos 	 (size_dynamic_sections) the input sections have already been
   1621   1.1.1.4  christos 	 mapped to the output sections.  If the section turns out not to
   1622   1.1.1.6  christos 	 be needed, we can discard it later.  We will never need this
   1623   1.1.1.6  christos 	 section when generating a shared object, since they do not use
   1624   1.1.1.3  christos 	 copy relocs.  */
   1625   1.1.1.3  christos       if (! bfd_link_pic (info))
   1626   1.1.1.3  christos 	{
   1627   1.1.1.6  christos 	  s = bfd_make_section_anyway_with_flags (abfd,
   1628   1.1.1.6  christos 						  (bed->default_use_rela_p
   1629   1.1.1.8  christos 						   ? ".rela.bss" : ".rel.bss"),
   1630   1.1.1.9  christos 						  flags | SEC_READONLY);
   1631   1.1.1.6  christos 	  htab->srelbss = s;
   1632       1.1     skrll 	  if (s == NULL
   1633       1.1     skrll 	      || !bfd_set_section_alignment (s, ptralign))
   1634   1.1.1.9  christos 	    return false;
   1635       1.1     skrll 	}
   1636       1.1     skrll     }
   1637       1.1     skrll 
   1638       1.1     skrll   return true;
   1639       1.1     skrll }
   1640       1.1     skrll 
   1641       1.1     skrll 
   1642       1.1     skrll /* Adjust a symbol defined by a dynamic object and referenced by a
   1644   1.1.1.9  christos    regular object.  The current definition is in some section of the
   1645       1.1     skrll    dynamic object, but we're not including those sections.  We have to
   1646       1.1     skrll    change the definition to something the rest of the link can
   1647       1.1     skrll    understand.  */
   1648   1.1.1.9  christos 
   1649       1.1     skrll static bool
   1650       1.1     skrll m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   1651       1.1     skrll 				struct elf_link_hash_entry *h)
   1652       1.1     skrll {
   1653       1.1     skrll   struct elf_link_hash_table *htab;
   1654       1.1     skrll   bfd *dynobj;
   1655       1.1     skrll   asection *s;
   1656       1.1     skrll 
   1657       1.1     skrll #ifdef DEBUG_PIC
   1658       1.1     skrll   printf ("m32r_elf_adjust_dynamic_symbol()\n");
   1659       1.1     skrll #endif
   1660   1.1.1.6  christos 
   1661   1.1.1.6  christos   dynobj = elf_hash_table (info)->dynobj;
   1662   1.1.1.6  christos 
   1663   1.1.1.6  christos   /* Make sure we know what is going on here.  */
   1664   1.1.1.6  christos   BFD_ASSERT (dynobj != NULL
   1665       1.1     skrll 	      && (h->needs_plt
   1666       1.1     skrll 		  || h->is_weakalias
   1667       1.1     skrll 		  || (h->def_dynamic
   1668       1.1     skrll 		      && h->ref_regular
   1669       1.1     skrll 		      && !h->def_regular)));
   1670       1.1     skrll 
   1671       1.1     skrll   /* If this is a function, put it in the procedure linkage table.  We
   1672   1.1.1.4  christos      will fill in the contents of the procedure linkage table later,
   1673   1.1.1.6  christos      when we know the address of the .got section.  */
   1674   1.1.1.6  christos   if (h->type == STT_FUNC
   1675       1.1     skrll       || h->needs_plt)
   1676       1.1     skrll     {
   1677   1.1.1.6  christos       if (! bfd_link_pic (info)
   1678   1.1.1.6  christos 	  && !h->def_dynamic
   1679   1.1.1.6  christos 	  && !h->ref_dynamic
   1680   1.1.1.6  christos 	  && h->root.type != bfd_link_hash_undefweak
   1681   1.1.1.6  christos 	  && h->root.type != bfd_link_hash_undefined)
   1682   1.1.1.6  christos 	{
   1683   1.1.1.6  christos 	  /* This case can occur if we saw a PLT reloc in an input
   1684   1.1.1.6  christos 	     file, but the symbol was never referred to by a dynamic
   1685   1.1.1.6  christos 	     object.  In such a case, we don't actually need to build
   1686       1.1     skrll 	     a procedure linkage table, and we can just do a PCREL
   1687   1.1.1.9  christos 	     reloc instead.  */
   1688       1.1     skrll 	  h->plt.offset = (bfd_vma) -1;
   1689       1.1     skrll 	  h->needs_plt = 0;
   1690       1.1     skrll 	}
   1691       1.1     skrll 
   1692       1.1     skrll       return true;
   1693       1.1     skrll     }
   1694       1.1     skrll   else
   1695   1.1.1.6  christos     h->plt.offset = (bfd_vma) -1;
   1696       1.1     skrll 
   1697   1.1.1.6  christos   /* If this is a weak symbol, and there is a real definition, the
   1698   1.1.1.6  christos      processor independent code will have arranged for us to see the
   1699   1.1.1.6  christos      real definition first, and we can just use the same value.  */
   1700   1.1.1.6  christos   if (h->is_weakalias)
   1701   1.1.1.9  christos     {
   1702       1.1     skrll       struct elf_link_hash_entry *def = weakdef (h);
   1703       1.1     skrll       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   1704       1.1     skrll       h->root.u.def.section = def->root.u.def.section;
   1705       1.1     skrll       h->root.u.def.value = def->root.u.def.value;
   1706       1.1     skrll       return true;
   1707       1.1     skrll     }
   1708       1.1     skrll 
   1709       1.1     skrll   /* This is a reference to a symbol defined by a dynamic object which
   1710       1.1     skrll      is not a function.  */
   1711   1.1.1.4  christos 
   1712   1.1.1.9  christos   /* If we are creating a shared library, we must presume that the
   1713       1.1     skrll      only references to the symbol are via the global offset table.
   1714       1.1     skrll      For such cases we need not do anything here; the relocations will
   1715       1.1     skrll      be handled correctly by relocate_section.  */
   1716       1.1     skrll   if (bfd_link_pic (info))
   1717   1.1.1.9  christos     return true;
   1718       1.1     skrll 
   1719       1.1     skrll   /* If there are no references to this symbol that do not use the
   1720   1.1.1.6  christos      GOT, we don't need to generate a copy reloc.  */
   1721       1.1     skrll   if (!h->non_got_ref)
   1722       1.1     skrll     return true;
   1723   1.1.1.9  christos 
   1724       1.1     skrll   /* If -z nocopyreloc was given, we won't generate them either.  */
   1725       1.1     skrll   if (0 && info->nocopyreloc)
   1726   1.1.1.6  christos     {
   1727   1.1.1.6  christos       h->non_got_ref = 0;
   1728   1.1.1.9  christos       return true;
   1729       1.1     skrll     }
   1730       1.1     skrll 
   1731   1.1.1.9  christos   /* If we don't find any dynamic relocs in read-only sections, then
   1732       1.1     skrll      we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
   1733       1.1     skrll   if (0 && !_bfd_elf_readonly_dynrelocs (h))
   1734       1.1     skrll     {
   1735       1.1     skrll       h->non_got_ref = 0;
   1736       1.1     skrll       return true;
   1737       1.1     skrll     }
   1738       1.1     skrll 
   1739       1.1     skrll   /* We must allocate the symbol in our .dynbss section, which will
   1740       1.1     skrll      become part of the .bss section of the executable.  There will be
   1741       1.1     skrll      an entry for this symbol in the .dynsym section.  The dynamic
   1742       1.1     skrll      object will contain position independent code, so all references
   1743       1.1     skrll      from the dynamic object to this symbol will go through the global
   1744       1.1     skrll      offset table.  The dynamic linker will use the .dynsym entry to
   1745   1.1.1.2  christos      determine the address it must put in the global offset table, so
   1746   1.1.1.9  christos      both the dynamic object and the regular object will refer to the
   1747   1.1.1.2  christos      same memory location for the variable.  */
   1748       1.1     skrll 
   1749       1.1     skrll   htab = m32r_elf_hash_table (info);
   1750       1.1     skrll   if (htab == NULL)
   1751       1.1     skrll     return false;
   1752       1.1     skrll 
   1753       1.1     skrll   s = htab->sdynbss;
   1754       1.1     skrll   BFD_ASSERT (s != NULL);
   1755   1.1.1.3  christos 
   1756       1.1     skrll   /* We must generate a R_M32R_COPY reloc to tell the dynamic linker
   1757       1.1     skrll      to copy the initial value out of the dynamic object and into the
   1758       1.1     skrll      runtime process image.  We need to remember the offset into the
   1759       1.1     skrll      .rela.bss section we are going to use.  */
   1760       1.1     skrll   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   1761       1.1     skrll     {
   1762       1.1     skrll       asection *srel;
   1763       1.1     skrll 
   1764       1.1     skrll       srel = htab->srelbss;
   1765   1.1.1.4  christos       BFD_ASSERT (srel != NULL);
   1766       1.1     skrll       srel->size += sizeof (Elf32_External_Rela);
   1767       1.1     skrll       h->needs_copy = 1;
   1768       1.1     skrll     }
   1769       1.1     skrll 
   1770       1.1     skrll   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   1771   1.1.1.9  christos }
   1772       1.1     skrll 
   1773       1.1     skrll /* Allocate space in .plt, .got and associated reloc sections for
   1774       1.1     skrll    dynamic relocs.  */
   1775   1.1.1.9  christos 
   1776   1.1.1.6  christos static bool
   1777       1.1     skrll allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   1778       1.1     skrll {
   1779   1.1.1.9  christos   struct bfd_link_info *info;
   1780       1.1     skrll   struct elf_link_hash_table *htab;
   1781       1.1     skrll   struct elf_dyn_relocs *p;
   1782       1.1     skrll 
   1783   1.1.1.2  christos   if (h->root.type == bfd_link_hash_indirect)
   1784   1.1.1.9  christos     return true;
   1785       1.1     skrll 
   1786   1.1.1.9  christos   info = (struct bfd_link_info *) inf;
   1787       1.1     skrll   htab = m32r_elf_hash_table (info);
   1788       1.1     skrll   if (htab == NULL)
   1789       1.1     skrll     return false;
   1790   1.1.1.6  christos 
   1791       1.1     skrll   if (htab->dynamic_sections_created
   1792   1.1.1.6  christos       && h->plt.refcount > 0)
   1793   1.1.1.6  christos     {
   1794   1.1.1.6  christos       /* Make sure this symbol is output as a dynamic symbol.
   1795   1.1.1.9  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   1796   1.1.1.6  christos       if (h->dynindx == -1
   1797       1.1     skrll 	  && !h->forced_local)
   1798   1.1.1.4  christos 	{
   1799   1.1.1.6  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   1800   1.1.1.9  christos 	    return false;
   1801   1.1.1.6  christos 	}
   1802   1.1.1.6  christos 
   1803   1.1.1.6  christos       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
   1804   1.1.1.6  christos 	{
   1805   1.1.1.6  christos 	  asection *s = htab->splt;
   1806   1.1.1.6  christos 
   1807   1.1.1.6  christos 	  /* If this is the first .plt entry, make room for the special
   1808   1.1.1.6  christos 	     first entry.  */
   1809   1.1.1.6  christos 	  if (s->size == 0)
   1810   1.1.1.6  christos 	    s->size += PLT_ENTRY_SIZE;
   1811   1.1.1.6  christos 
   1812   1.1.1.6  christos 	  h->plt.offset = s->size;
   1813   1.1.1.6  christos 
   1814   1.1.1.6  christos 	  /* If this symbol is not defined in a regular file, and we are
   1815   1.1.1.6  christos 	     not generating a shared library, then set the symbol to this
   1816   1.1.1.6  christos 	     location in the .plt.  This is required to make function
   1817   1.1.1.6  christos 	     pointers compare as equal between the normal executable and
   1818   1.1.1.6  christos 	     the shared library.  */
   1819   1.1.1.6  christos 	  if (! bfd_link_pic (info)
   1820   1.1.1.6  christos 	      && !h->def_regular)
   1821   1.1.1.6  christos 	    {
   1822   1.1.1.6  christos 	      h->root.u.def.section = s;
   1823       1.1     skrll 	      h->root.u.def.value = h->plt.offset;
   1824   1.1.1.6  christos 	    }
   1825   1.1.1.6  christos 
   1826   1.1.1.9  christos 	  /* Make room for this entry.  */
   1827   1.1.1.6  christos 	  s->size += PLT_ENTRY_SIZE;
   1828   1.1.1.6  christos 
   1829   1.1.1.9  christos 	  /* We also need to make an entry in the .got.plt section, which
   1830   1.1.1.6  christos 	     will be placed in the .got section by the linker script.  */
   1831       1.1     skrll 	  htab->sgotplt->size += 4;
   1832   1.1.1.6  christos 
   1833   1.1.1.6  christos 	  /* We also need to make an entry in the .rel.plt section.  */
   1834   1.1.1.6  christos 	  htab->srelplt->size += sizeof (Elf32_External_Rela);
   1835   1.1.1.6  christos 	}
   1836       1.1     skrll       else
   1837       1.1     skrll 	{
   1838       1.1     skrll 	  h->plt.offset = (bfd_vma) -1;
   1839       1.1     skrll 	  h->needs_plt = 0;
   1840       1.1     skrll 	}
   1841       1.1     skrll     }
   1842       1.1     skrll   else
   1843       1.1     skrll     {
   1844       1.1     skrll       h->plt.offset = (bfd_vma) -1;
   1845       1.1     skrll       h->needs_plt = 0;
   1846   1.1.1.9  christos     }
   1847       1.1     skrll 
   1848       1.1     skrll   if (h->got.refcount > 0)
   1849   1.1.1.6  christos     {
   1850       1.1     skrll       asection *s;
   1851   1.1.1.6  christos       bool dyn;
   1852   1.1.1.6  christos 
   1853   1.1.1.6  christos       /* Make sure this symbol is output as a dynamic symbol.
   1854   1.1.1.9  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   1855   1.1.1.6  christos       if (h->dynindx == -1
   1856       1.1     skrll 	  && !h->forced_local)
   1857   1.1.1.9  christos 	{
   1858       1.1     skrll 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   1859       1.1     skrll 	    return false;
   1860       1.1     skrll 	}
   1861   1.1.1.9  christos 
   1862   1.1.1.4  christos       s = htab->sgot;
   1863   1.1.1.9  christos 
   1864       1.1     skrll       h->got.offset = s->size;
   1865       1.1     skrll       s->size += 4;
   1866       1.1     skrll       dyn = htab->dynamic_sections_created;
   1867       1.1     skrll       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
   1868   1.1.1.9  christos 	htab->srelgot->size += sizeof (Elf32_External_Rela);
   1869   1.1.1.9  christos     }
   1870       1.1     skrll   else
   1871       1.1     skrll     h->got.offset = (bfd_vma) -1;
   1872       1.1     skrll 
   1873       1.1     skrll   if (h->dyn_relocs == NULL)
   1874       1.1     skrll     return true;
   1875       1.1     skrll 
   1876       1.1     skrll   /* In the shared -Bsymbolic case, discard space allocated for
   1877   1.1.1.4  christos      dynamic pc-relative relocs against symbols which turn out to be
   1878       1.1     skrll      defined in regular objects.  For the normal shared case, discard
   1879       1.1     skrll      space for pc-relative relocs that have become local due to symbol
   1880   1.1.1.6  christos      visibility changes.  */
   1881   1.1.1.6  christos 
   1882   1.1.1.6  christos   if (bfd_link_pic (info))
   1883   1.1.1.6  christos     {
   1884   1.1.1.6  christos       if (h->def_regular
   1885   1.1.1.9  christos 	  && (h->forced_local
   1886   1.1.1.6  christos 	      || info->symbolic))
   1887   1.1.1.6  christos 	{
   1888   1.1.1.6  christos 	  struct elf_dyn_relocs **pp;
   1889   1.1.1.6  christos 
   1890   1.1.1.6  christos 	  for (pp = &h->dyn_relocs; (p = *pp) != NULL;)
   1891   1.1.1.6  christos 	    {
   1892   1.1.1.6  christos 	      p->count -= p->pc_count;
   1893   1.1.1.6  christos 	      p->pc_count = 0;
   1894   1.1.1.6  christos 	      if (p->count == 0)
   1895       1.1     skrll 		*pp = p->next;
   1896       1.1     skrll 	      else
   1897       1.1     skrll 		pp = &p->next;
   1898   1.1.1.9  christos 	    }
   1899       1.1     skrll 	}
   1900       1.1     skrll 
   1901       1.1     skrll       /* Also discard relocs on undefined weak syms with non-default
   1902   1.1.1.9  christos 	 visibility.  */
   1903       1.1     skrll       if (h->dyn_relocs != NULL
   1904       1.1     skrll 	  && h->root.type == bfd_link_hash_undefweak)
   1905       1.1     skrll 	{
   1906       1.1     skrll 	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
   1907       1.1     skrll 	    h->dyn_relocs = NULL;
   1908       1.1     skrll 
   1909       1.1     skrll 	  /* Make sure undefined weak symbols are output as a dynamic
   1910   1.1.1.9  christos 	     symbol in PIEs.  */
   1911       1.1     skrll 	  else if (h->dynindx == -1
   1912       1.1     skrll 		   && !h->forced_local)
   1913       1.1     skrll 	    {
   1914       1.1     skrll 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   1915       1.1     skrll 		return false;
   1916       1.1     skrll 	    }
   1917   1.1.1.6  christos 	}
   1918   1.1.1.6  christos     }
   1919       1.1     skrll   else
   1920       1.1     skrll     {
   1921   1.1.1.6  christos       /* For the non-shared case, discard space for relocs against
   1922   1.1.1.6  christos 	 symbols which turn out to need copy relocs or are not
   1923   1.1.1.9  christos 	 dynamic.  */
   1924   1.1.1.6  christos 
   1925   1.1.1.6  christos       if (!h->non_got_ref
   1926   1.1.1.6  christos 	  && ((h->def_dynamic
   1927   1.1.1.6  christos 	       && !h->def_regular)
   1928   1.1.1.6  christos 	      || (htab->dynamic_sections_created
   1929   1.1.1.6  christos 		  && (h->root.type == bfd_link_hash_undefweak
   1930   1.1.1.6  christos 		      || h->root.type == bfd_link_hash_undefined))))
   1931   1.1.1.6  christos 	{
   1932   1.1.1.6  christos 	  /* Make sure this symbol is output as a dynamic symbol.
   1933   1.1.1.9  christos 	     Undefined weak syms won't yet be marked as dynamic.  */
   1934   1.1.1.6  christos 	  if (h->dynindx == -1
   1935   1.1.1.6  christos 	      && !h->forced_local)
   1936   1.1.1.6  christos 	    {
   1937   1.1.1.6  christos 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   1938   1.1.1.6  christos 		return false;
   1939   1.1.1.6  christos 	    }
   1940   1.1.1.6  christos 
   1941       1.1     skrll 	  /* If that succeeded, we know we'll be keeping all the
   1942   1.1.1.9  christos 	     relocs.  */
   1943       1.1     skrll 	  if (h->dynindx != -1)
   1944       1.1     skrll 	    goto keep;
   1945       1.1     skrll 	}
   1946       1.1     skrll 
   1947       1.1     skrll       h->dyn_relocs = NULL;
   1948   1.1.1.9  christos 
   1949       1.1     skrll     keep: ;
   1950       1.1     skrll     }
   1951       1.1     skrll 
   1952       1.1     skrll   /* Finally, allocate space.  */
   1953       1.1     skrll   for (p = h->dyn_relocs; p != NULL; p = p->next)
   1954   1.1.1.9  christos     {
   1955       1.1     skrll       asection *sreloc = elf_section_data (p->sec)->sreloc;
   1956       1.1     skrll       sreloc->size += p->count * sizeof (Elf32_External_Rela);
   1957       1.1     skrll     }
   1958       1.1     skrll 
   1959   1.1.1.9  christos   return true;
   1960  1.1.1.11  christos }
   1961  1.1.1.11  christos 
   1962       1.1     skrll /* Set the sizes of the dynamic sections.  */
   1963   1.1.1.9  christos 
   1964       1.1     skrll static bool
   1965       1.1     skrll m32r_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   1966   1.1.1.9  christos 			     struct bfd_link_info *info)
   1967       1.1     skrll {
   1968       1.1     skrll   struct elf_link_hash_table *htab;
   1969       1.1     skrll   bfd *dynobj;
   1970  1.1.1.11  christos   asection *s;
   1971       1.1     skrll   bool relocs;
   1972       1.1     skrll   bfd *ibfd;
   1973       1.1     skrll 
   1974   1.1.1.2  christos #ifdef DEBUG_PIC
   1975   1.1.1.9  christos   printf ("m32r_elf_late_size_sections()\n");
   1976   1.1.1.2  christos #endif
   1977   1.1.1.9  christos 
   1978  1.1.1.11  christos   htab = m32r_elf_hash_table (info);
   1979  1.1.1.11  christos   if (htab == NULL)
   1980       1.1     skrll     return false;
   1981   1.1.1.9  christos 
   1982       1.1     skrll   dynobj = htab->dynobj;
   1983       1.1     skrll   if (dynobj == NULL)
   1984   1.1.1.4  christos     return true;
   1985       1.1     skrll 
   1986  1.1.1.12  christos   if (htab->dynamic_sections_created)
   1987       1.1     skrll     {
   1988       1.1     skrll       /* Set the contents of the .interp section to the interpreter.  */
   1989       1.1     skrll       if (bfd_link_executable (info) && !info->nointerp)
   1990  1.1.1.11  christos 	{
   1991       1.1     skrll 	  s = htab->interp;
   1992       1.1     skrll 	  BFD_ASSERT (s != NULL);
   1993       1.1     skrll 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   1994       1.1     skrll 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   1995       1.1     skrll 	  s->alloced = 1;
   1996   1.1.1.4  christos 	}
   1997       1.1     skrll     }
   1998       1.1     skrll 
   1999       1.1     skrll   /* Set up .got offsets for local syms, and space for local dynamic
   2000       1.1     skrll      relocs.  */
   2001       1.1     skrll   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   2002       1.1     skrll     {
   2003       1.1     skrll       bfd_signed_vma *local_got;
   2004       1.1     skrll       bfd_signed_vma *end_local_got;
   2005   1.1.1.6  christos       bfd_size_type locsymcount;
   2006       1.1     skrll       Elf_Internal_Shdr *symtab_hdr;
   2007       1.1     skrll       asection *srel;
   2008   1.1.1.6  christos 
   2009   1.1.1.6  christos       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
   2010       1.1     skrll 	continue;
   2011   1.1.1.6  christos 
   2012   1.1.1.6  christos       for (s = ibfd->sections; s != NULL; s = s->next)
   2013   1.1.1.6  christos 	{
   2014   1.1.1.6  christos 	  struct elf_dyn_relocs *p;
   2015   1.1.1.6  christos 
   2016   1.1.1.6  christos 	  for (p = ((struct elf_dyn_relocs *)
   2017   1.1.1.6  christos 		    elf_section_data (s)->local_dynrel);
   2018   1.1.1.6  christos 	       p != NULL;
   2019   1.1.1.6  christos 	       p = p->next)
   2020   1.1.1.6  christos 	    {
   2021   1.1.1.6  christos 	      if (! bfd_is_abs_section (p->sec)
   2022   1.1.1.6  christos 		  && bfd_is_abs_section (p->sec->output_section))
   2023   1.1.1.6  christos 		{
   2024   1.1.1.6  christos 		  /* Input section has been discarded, either because
   2025   1.1.1.6  christos 		     it is a copy of a linkonce section or due to
   2026   1.1.1.6  christos 		     linker script /DISCARD/, so we'll be discarding
   2027   1.1.1.6  christos 		     the relocs too.  */
   2028   1.1.1.6  christos 		}
   2029   1.1.1.6  christos 	      else if (p->count != 0)
   2030   1.1.1.6  christos 		{
   2031   1.1.1.6  christos 		  srel = elf_section_data (p->sec)->sreloc;
   2032   1.1.1.6  christos 		  srel->size += p->count * sizeof (Elf32_External_Rela);
   2033       1.1     skrll 		  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
   2034       1.1     skrll 		    info->flags |= DF_TEXTREL;
   2035       1.1     skrll 		}
   2036   1.1.1.6  christos 	    }
   2037       1.1     skrll 	}
   2038       1.1     skrll 
   2039       1.1     skrll       local_got = elf_local_got_refcounts (ibfd);
   2040       1.1     skrll       if (!local_got)
   2041   1.1.1.9  christos 	continue;
   2042   1.1.1.9  christos 
   2043       1.1     skrll       symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
   2044   1.1.1.6  christos       locsymcount = symtab_hdr->sh_info;
   2045   1.1.1.6  christos       end_local_got = local_got + locsymcount;
   2046   1.1.1.6  christos       s = htab->sgot;
   2047   1.1.1.6  christos       srel = htab->srelgot;
   2048   1.1.1.6  christos       for (; local_got < end_local_got; ++local_got)
   2049   1.1.1.6  christos 	{
   2050   1.1.1.6  christos 	  if (*local_got > 0)
   2051   1.1.1.6  christos 	    {
   2052   1.1.1.6  christos 	      *local_got = s->size;
   2053   1.1.1.6  christos 	      s->size += 4;
   2054   1.1.1.6  christos 	      if (bfd_link_pic (info))
   2055       1.1     skrll 		srel->size += sizeof (Elf32_External_Rela);
   2056       1.1     skrll 	    }
   2057       1.1     skrll 	  else
   2058       1.1     skrll 	    *local_got = (bfd_vma) -1;
   2059   1.1.1.9  christos 	}
   2060       1.1     skrll     }
   2061       1.1     skrll 
   2062       1.1     skrll   /* Allocate global sym .plt and .got entries, and space for global
   2063   1.1.1.9  christos      sym dynamic relocs.  */
   2064       1.1     skrll   elf_link_hash_traverse (htab, allocate_dynrelocs, info);
   2065       1.1     skrll 
   2066       1.1     skrll   /* We now have determined the sizes of the various dynamic sections.
   2067   1.1.1.6  christos      Allocate memory for them.  */
   2068       1.1     skrll   relocs = false;
   2069   1.1.1.9  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   2070   1.1.1.9  christos     {
   2071   1.1.1.9  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   2072       1.1     skrll 	continue;
   2073   1.1.1.6  christos 
   2074   1.1.1.6  christos       if (s == htab->splt
   2075   1.1.1.6  christos 	  || s == htab->sgot
   2076   1.1.1.6  christos 	  || s == htab->sgotplt
   2077   1.1.1.9  christos 	  || s == htab->sdynbss)
   2078   1.1.1.6  christos 	{
   2079   1.1.1.9  christos 	  /* Strip this section if we don't need it; see the
   2080   1.1.1.9  christos 	     comment below.  */
   2081   1.1.1.6  christos 	}
   2082   1.1.1.6  christos       else if (startswith (bfd_section_name (s), ".rela"))
   2083   1.1.1.6  christos 	{
   2084   1.1.1.6  christos 	  if (s->size != 0 && s != htab->srelplt)
   2085   1.1.1.6  christos 	    relocs = true;
   2086       1.1     skrll 
   2087       1.1     skrll 	  /* We use the reloc_count field as a counter if we need
   2088       1.1     skrll 	     to copy relocs into the output file.  */
   2089       1.1     skrll 	  s->reloc_count = 0;
   2090       1.1     skrll 	}
   2091   1.1.1.6  christos       else
   2092   1.1.1.6  christos 	/* It's not one of our sections, so don't allocate space.  */
   2093   1.1.1.6  christos 	continue;
   2094   1.1.1.6  christos 
   2095   1.1.1.6  christos       if (s->size == 0)
   2096   1.1.1.6  christos 	{
   2097   1.1.1.6  christos 	  /* If we don't need this section, strip it from the
   2098   1.1.1.6  christos 	     output file.  This is mostly to handle .rela.bss and
   2099   1.1.1.6  christos 	     .rela.plt.  We must create both sections in
   2100   1.1.1.6  christos 	     create_dynamic_sections, because they must be created
   2101   1.1.1.6  christos 	     before the linker maps input sections to output
   2102   1.1.1.6  christos 	     sections.  The linker does that before
   2103   1.1.1.6  christos 	     adjust_dynamic_symbol is called, and it is that
   2104       1.1     skrll 	     function which decides whether anything needs to go
   2105       1.1     skrll 	     into these sections.  */
   2106       1.1     skrll 	  s->flags |= SEC_EXCLUDE;
   2107       1.1     skrll 	  continue;
   2108       1.1     skrll 	}
   2109   1.1.1.6  christos 
   2110   1.1.1.6  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   2111   1.1.1.6  christos 	continue;
   2112   1.1.1.6  christos 
   2113       1.1     skrll       /* Allocate memory for the section contents.  We use bfd_zalloc
   2114       1.1     skrll 	 here in case unused entries are not reclaimed before the
   2115   1.1.1.9  christos 	 section's contents are written out.  This should not happen,
   2116  1.1.1.11  christos 	 but this way if it does, we get a R_M32R_NONE reloc instead
   2117       1.1     skrll 	 of garbage.  */
   2118       1.1     skrll       s->contents = bfd_zalloc (dynobj, s->size);
   2119   1.1.1.9  christos       if (s->contents == NULL)
   2120       1.1     skrll 	return false;
   2121       1.1     skrll       s->alloced = 1;
   2122       1.1     skrll     }
   2123       1.1     skrll 
   2124       1.1     skrll   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
   2125       1.1     skrll }
   2126       1.1     skrll 
   2127       1.1     skrll /* Relocate an M32R/D ELF section.
   2128       1.1     skrll    There is some attempt to make this function usable for many architectures,
   2129       1.1     skrll    both for RELA and REL type relocs, if only to serve as a learning tool.
   2130       1.1     skrll 
   2131       1.1     skrll    The RELOCATE_SECTION function is called by the new ELF backend linker
   2132       1.1     skrll    to handle the relocations for a section.
   2133       1.1     skrll 
   2134       1.1     skrll    The relocs are always passed as Rela structures; if the section
   2135       1.1     skrll    actually uses Rel structures, the r_addend field will always be
   2136       1.1     skrll    zero.
   2137       1.1     skrll 
   2138       1.1     skrll    This function is responsible for adjust the section contents as
   2139       1.1     skrll    necessary, and (if using Rela relocs and generating a
   2140       1.1     skrll    relocatable output file) adjusting the reloc addend as
   2141       1.1     skrll    necessary.
   2142       1.1     skrll 
   2143       1.1     skrll    This function does not have to worry about setting the reloc
   2144       1.1     skrll    address or the reloc symbol index.
   2145       1.1     skrll 
   2146       1.1     skrll    LOCAL_SYMS is a pointer to the swapped in local symbols.
   2147       1.1     skrll 
   2148       1.1     skrll    LOCAL_SECTIONS is an array giving the section in the input file
   2149       1.1     skrll    corresponding to the st_shndx field of each local symbol.
   2150       1.1     skrll 
   2151       1.1     skrll    The global hash table entry for the global symbols can be found
   2152       1.1     skrll    via elf_sym_hashes (input_bfd).
   2153       1.1     skrll 
   2154       1.1     skrll    When generating relocatable output, this function must handle
   2155   1.1.1.9  christos    STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
   2156       1.1     skrll    going to be the section symbol corresponding to the output
   2157       1.1     skrll    section, which means that the addend must be adjusted
   2158       1.1     skrll    accordingly.  */
   2159       1.1     skrll 
   2160       1.1     skrll static int
   2161       1.1     skrll m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
   2162       1.1     skrll 			   struct bfd_link_info *info,
   2163       1.1     skrll 			   bfd *input_bfd,
   2164       1.1     skrll 			   asection *input_section,
   2165       1.1     skrll 			   bfd_byte *contents,
   2166       1.1     skrll 			   Elf_Internal_Rela *relocs,
   2167       1.1     skrll 			   Elf_Internal_Sym *local_syms,
   2168       1.1     skrll 			   asection **local_sections)
   2169   1.1.1.9  christos {
   2170   1.1.1.9  christos   Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   2171       1.1     skrll   struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
   2172       1.1     skrll   Elf_Internal_Rela *rel, *relend;
   2173       1.1     skrll   /* Assume success.  */
   2174       1.1     skrll   bool ret = true;
   2175   1.1.1.2  christos   struct elf_link_hash_table *htab = m32r_elf_hash_table (info);
   2176   1.1.1.9  christos   bfd_vma *local_got_offsets;
   2177   1.1.1.2  christos   asection *sgot, *splt, *sreloc;
   2178       1.1     skrll   bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
   2179       1.1     skrll 
   2180   1.1.1.9  christos   if (htab == NULL)
   2181   1.1.1.9  christos     return false;
   2182       1.1     skrll 
   2183       1.1     skrll   local_got_offsets = elf_local_got_offsets (input_bfd);
   2184       1.1     skrll 
   2185       1.1     skrll   sgot = htab->sgot;
   2186       1.1     skrll   splt = htab->splt;
   2187       1.1     skrll   sreloc = NULL;
   2188       1.1     skrll 
   2189       1.1     skrll   rel = relocs;
   2190       1.1     skrll   relend = relocs + input_section->reloc_count;
   2191       1.1     skrll   for (; rel < relend; rel++)
   2192       1.1     skrll     {
   2193   1.1.1.6  christos       int r_type;
   2194   1.1.1.6  christos       reloc_howto_type *howto;
   2195   1.1.1.6  christos       unsigned long r_symndx;
   2196       1.1     skrll       struct elf_link_hash_entry *h;
   2197       1.1     skrll       /* We can't modify r_addend here as elf_link_input_bfd has an assert to
   2198       1.1     skrll 	 ensure it's zero (we use REL relocs, not RELA).  Therefore this
   2199       1.1     skrll 	 should be assigning zero to `addend', but for clarity we use
   2200       1.1     skrll 	 `r_addend'.  */
   2201       1.1     skrll       bfd_vma addend = rel->r_addend;
   2202       1.1     skrll       bfd_vma offset = rel->r_offset;
   2203       1.1     skrll       bfd_vma relocation;
   2204   1.1.1.9  christos       Elf_Internal_Sym *sym;
   2205       1.1     skrll       asection *sec;
   2206       1.1     skrll       const char *sym_name;
   2207       1.1     skrll       bfd_reloc_status_type r;
   2208       1.1     skrll       const char *errmsg = NULL;
   2209       1.1     skrll       bool use_rel = false;
   2210   1.1.1.6  christos 
   2211   1.1.1.7  christos       h = NULL;
   2212   1.1.1.6  christos       r_type = ELF32_R_TYPE (rel->r_info);
   2213       1.1     skrll       if (r_type < 0 || r_type >= (int) R_M32R_max)
   2214   1.1.1.9  christos 	{
   2215       1.1     skrll 	  /* xgettext:c-format */
   2216       1.1     skrll 	  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   2217       1.1     skrll 			      input_bfd, (int) r_type);
   2218       1.1     skrll 	  bfd_set_error (bfd_error_bad_value);
   2219   1.1.1.6  christos 	  ret = false;
   2220   1.1.1.6  christos 	  continue;
   2221   1.1.1.6  christos 	}
   2222   1.1.1.6  christos 
   2223   1.1.1.6  christos       if (   r_type == R_M32R_GNU_VTENTRY
   2224       1.1     skrll 	  || r_type == R_M32R_GNU_VTINHERIT
   2225       1.1     skrll 	  || r_type == R_M32R_NONE
   2226   1.1.1.9  christos 	  || r_type == R_M32R_RELA_GNU_VTENTRY
   2227       1.1     skrll 	  || r_type == R_M32R_RELA_GNU_VTINHERIT)
   2228       1.1     skrll 	continue;
   2229       1.1     skrll 
   2230       1.1     skrll       if (r_type <= R_M32R_GNU_VTENTRY)
   2231       1.1     skrll 	use_rel = true;
   2232       1.1     skrll 
   2233       1.1     skrll       howto = m32r_elf_howto_table + r_type;
   2234       1.1     skrll       r_symndx = ELF32_R_SYM (rel->r_info);
   2235       1.1     skrll 
   2236       1.1     skrll       sym = NULL;
   2237       1.1     skrll       sec = NULL;
   2238       1.1     skrll       h = NULL;
   2239       1.1     skrll 
   2240       1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   2241       1.1     skrll 	{
   2242       1.1     skrll 	  /* Local symbol.  */
   2243       1.1     skrll 	  sym = local_syms + r_symndx;
   2244       1.1     skrll 	  sec = local_sections[r_symndx];
   2245       1.1     skrll 	  sym_name = "<local symbol>";
   2246       1.1     skrll 
   2247       1.1     skrll 	  if (!use_rel)
   2248       1.1     skrll 	    {
   2249       1.1     skrll 	      relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   2250       1.1     skrll 	      addend = rel->r_addend;
   2251       1.1     skrll 	    }
   2252       1.1     skrll 	  else
   2253       1.1     skrll 	    {
   2254       1.1     skrll 	      relocation = (sec->output_section->vma
   2255       1.1     skrll 			    + sec->output_offset
   2256       1.1     skrll 			    + sym->st_value);
   2257       1.1     skrll 	    }
   2258       1.1     skrll 	}
   2259       1.1     skrll       else
   2260   1.1.1.4  christos 	{
   2261   1.1.1.4  christos 	  /* External symbol.  */
   2262   1.1.1.4  christos 	  relocation = 0;
   2263   1.1.1.4  christos 
   2264   1.1.1.4  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   2265   1.1.1.4  christos 
   2266       1.1     skrll 	  if (info->wrap_hash != NULL
   2267       1.1     skrll 	      && (input_section->flags & SEC_DEBUGGING) != 0)
   2268       1.1     skrll 	    h = ((struct elf_link_hash_entry *)
   2269       1.1     skrll 		 unwrap_hash_lookup (info, input_bfd, &h->root));
   2270       1.1     skrll 
   2271       1.1     skrll 	  while (h->root.type == bfd_link_hash_indirect
   2272       1.1     skrll 		 || h->root.type == bfd_link_hash_warning)
   2273       1.1     skrll 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   2274   1.1.1.9  christos 	  sym_name = h->root.root.string;
   2275       1.1     skrll 
   2276       1.1     skrll 	  if (h->root.type == bfd_link_hash_defined
   2277   1.1.1.9  christos 	      || h->root.type == bfd_link_hash_defweak)
   2278       1.1     skrll 	    {
   2279       1.1     skrll 	      bool dyn;
   2280       1.1     skrll 	      sec = h->root.u.def.section;
   2281       1.1     skrll 
   2282       1.1     skrll 	      dyn = htab->dynamic_sections_created;
   2283       1.1     skrll 	      sec = h->root.u.def.section;
   2284       1.1     skrll 	      if (r_type == R_M32R_GOTPC24
   2285       1.1     skrll 		  || (r_type == R_M32R_GOTPC_HI_ULO
   2286       1.1     skrll 		      || r_type == R_M32R_GOTPC_HI_SLO
   2287       1.1     skrll 		      || r_type == R_M32R_GOTPC_LO)
   2288       1.1     skrll 		  || (r_type == R_M32R_26_PLTREL
   2289       1.1     skrll 		      && h->plt.offset != (bfd_vma) -1)
   2290   1.1.1.4  christos 		  || ((r_type == R_M32R_GOT24
   2291   1.1.1.4  christos 		       || r_type == R_M32R_GOT16_HI_ULO
   2292   1.1.1.4  christos 		       || r_type == R_M32R_GOT16_HI_SLO
   2293       1.1     skrll 		       || r_type == R_M32R_GOT16_LO)
   2294       1.1     skrll 		      && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   2295   1.1.1.4  christos 							  bfd_link_pic (info),
   2296       1.1     skrll 							  h)
   2297       1.1     skrll 		      && (! bfd_link_pic (info)
   2298       1.1     skrll 			  || (! info->symbolic && h->dynindx != -1)
   2299       1.1     skrll 			  || !h->def_regular))
   2300       1.1     skrll 		  || (bfd_link_pic (info)
   2301       1.1     skrll 		      && ((! info->symbolic && h->dynindx != -1)
   2302       1.1     skrll 			  || !h->def_regular)
   2303       1.1     skrll 		      && (((r_type == R_M32R_16_RELA
   2304       1.1     skrll 			    || r_type == R_M32R_32_RELA
   2305       1.1     skrll 			    || r_type == R_M32R_24_RELA
   2306       1.1     skrll 			    || r_type == R_M32R_HI16_ULO_RELA
   2307       1.1     skrll 			    || r_type == R_M32R_HI16_SLO_RELA
   2308       1.1     skrll 			    || r_type == R_M32R_LO16_RELA)
   2309       1.1     skrll 			   && !h->forced_local)
   2310       1.1     skrll 			  || r_type == R_M32R_REL32
   2311       1.1     skrll 			  || r_type == R_M32R_10_PCREL_RELA
   2312       1.1     skrll 			  || r_type == R_M32R_18_PCREL_RELA
   2313       1.1     skrll 			  || r_type == R_M32R_26_PCREL_RELA)
   2314       1.1     skrll 		      && ((input_section->flags & SEC_ALLOC) != 0
   2315       1.1     skrll 			  /* DWARF will emit R_M32R_16(24,32) relocations
   2316       1.1     skrll 			     in its sections against symbols defined
   2317       1.1     skrll 			     externally in shared libraries.  We can't do
   2318       1.1     skrll 			     anything with them here.  */
   2319       1.1     skrll 			  || ((input_section->flags & SEC_DEBUGGING) != 0
   2320       1.1     skrll 			      && h->def_dynamic))))
   2321       1.1     skrll 		{
   2322       1.1     skrll 		  /* In these cases, we don't need the relocation
   2323       1.1     skrll 		     value.  We check specially because in some
   2324       1.1     skrll 		     obscure cases sec->output_section will be NULL.  */
   2325   1.1.1.4  christos 		}
   2326   1.1.1.3  christos 	      else if (sec->output_section != NULL)
   2327   1.1.1.3  christos 		relocation = (h->root.u.def.value
   2328   1.1.1.3  christos 			      + sec->output_section->vma
   2329   1.1.1.3  christos 			      + sec->output_offset);
   2330       1.1     skrll 	      else if (!bfd_link_relocatable (info)
   2331   1.1.1.6  christos 		       && (_bfd_elf_section_offset (output_bfd, info,
   2332   1.1.1.6  christos 						    input_section,
   2333   1.1.1.7  christos 						    rel->r_offset)
   2334   1.1.1.6  christos 			   != (bfd_vma) -1))
   2335       1.1     skrll 		{
   2336       1.1     skrll 		  _bfd_error_handler
   2337   1.1.1.7  christos 		    /* xgettext:c-format */
   2338       1.1     skrll 		    (_("%pB(%pA+%#" PRIx64 "): unresolvable %s relocation "
   2339       1.1     skrll 		       "against symbol `%s'"),
   2340       1.1     skrll 		     input_bfd,
   2341       1.1     skrll 		     input_section,
   2342       1.1     skrll 		     (uint64_t) rel->r_offset,
   2343       1.1     skrll 		     howto->name,
   2344       1.1     skrll 		     h->root.root.string);
   2345       1.1     skrll 		}
   2346       1.1     skrll 	    }
   2347   1.1.1.4  christos 	  else if (h->root.type == bfd_link_hash_undefweak)
   2348   1.1.1.9  christos 	    ;
   2349   1.1.1.9  christos 	  else if (info->unresolved_syms_in_objects == RM_IGNORE
   2350   1.1.1.9  christos 		   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
   2351   1.1.1.9  christos 	    ;
   2352   1.1.1.9  christos 	  else if (!bfd_link_relocatable (info))
   2353   1.1.1.9  christos             info->callbacks->undefined_symbol
   2354       1.1     skrll 	      (info, h->root.root.string, input_bfd, input_section, offset,
   2355   1.1.1.3  christos 	       (info->unresolved_syms_in_objects == RM_DIAGNOSE
   2356   1.1.1.2  christos 		&& !info->warn_unresolved_syms)
   2357  1.1.1.12  christos 	       || ELF_ST_VISIBILITY (h->other));
   2358  1.1.1.12  christos         }
   2359       1.1     skrll 
   2360   1.1.1.4  christos       if (sec != NULL && discarded_section (sec))
   2361       1.1     skrll 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2362       1.1     skrll 					 rel, 1, relend, R_M32R_NONE,
   2363       1.1     skrll 					 howto, 0, contents);
   2364       1.1     skrll 
   2365       1.1     skrll       if (bfd_link_relocatable (info) && !use_rel)
   2366       1.1     skrll 	{
   2367       1.1     skrll 	  /* This is a relocatable link.  We don't have to change
   2368       1.1     skrll 	     anything, unless the reloc is against a section symbol,
   2369       1.1     skrll 	     in which case we have to adjust according to where the
   2370       1.1     skrll 	     section symbol winds up in the output section.  */
   2371   1.1.1.4  christos 	  if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   2372       1.1     skrll 	    rel->r_addend += sec->output_offset;
   2373       1.1     skrll 	  continue;
   2374       1.1     skrll 	}
   2375       1.1     skrll 
   2376       1.1     skrll       if (bfd_link_relocatable (info) && use_rel)
   2377       1.1     skrll 	{
   2378       1.1     skrll 	  /* This is a relocatable link.  We don't have to change
   2379       1.1     skrll 	     anything, unless the reloc is against a section symbol,
   2380       1.1     skrll 	     in which case we have to adjust according to where the
   2381       1.1     skrll 	     section symbol winds up in the output section.  */
   2382       1.1     skrll 	  if (sym == NULL || ELF_ST_TYPE (sym->st_info) != STT_SECTION)
   2383       1.1     skrll 	    continue;
   2384       1.1     skrll 
   2385       1.1     skrll 	  addend += sec->output_offset;
   2386       1.1     skrll 
   2387       1.1     skrll 	  /* If partial_inplace, we need to store any additional addend
   2388       1.1     skrll 	     back in the section.  */
   2389       1.1     skrll 	  if (! howto->partial_inplace)
   2390       1.1     skrll 	    continue;
   2391       1.1     skrll 	  /* ??? Here is a nice place to call a special_function
   2392       1.1     skrll 	     like handler.  */
   2393       1.1     skrll 	  if (r_type != R_M32R_HI16_SLO && r_type != R_M32R_HI16_ULO)
   2394       1.1     skrll 	    r = _bfd_relocate_contents (howto, input_bfd,
   2395       1.1     skrll 					addend, contents + offset);
   2396       1.1     skrll 	  else
   2397       1.1     skrll 	    {
   2398       1.1     skrll 	      Elf_Internal_Rela *lorel;
   2399       1.1     skrll 
   2400       1.1     skrll 	      /* We allow an arbitrary number of HI16 relocs before the
   2401       1.1     skrll 		 LO16 reloc.  This permits gcc to emit the HI and LO relocs
   2402       1.1     skrll 		 itself.  */
   2403       1.1     skrll 	      for (lorel = rel + 1;
   2404       1.1     skrll 		   (lorel < relend
   2405       1.1     skrll 		    && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
   2406       1.1     skrll 			|| ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
   2407       1.1     skrll 		   lorel++)
   2408       1.1     skrll 		continue;
   2409       1.1     skrll 	      if (lorel < relend
   2410       1.1     skrll 		  && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
   2411       1.1     skrll 		{
   2412       1.1     skrll 		  m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
   2413       1.1     skrll 					  contents, addend);
   2414       1.1     skrll 		  r = bfd_reloc_ok;
   2415       1.1     skrll 		}
   2416       1.1     skrll 	      else
   2417       1.1     skrll 		r = _bfd_relocate_contents (howto, input_bfd,
   2418       1.1     skrll 					    addend, contents + offset);
   2419       1.1     skrll 	    }
   2420       1.1     skrll 	}
   2421       1.1     skrll       else
   2422       1.1     skrll 	{
   2423       1.1     skrll 	  /* Sanity check the address.  */
   2424       1.1     skrll 	  if (offset > high_address)
   2425       1.1     skrll 	    {
   2426       1.1     skrll 	      r = bfd_reloc_outofrange;
   2427   1.1.1.6  christos 	      goto check_reloc;
   2428   1.1.1.6  christos 	    }
   2429   1.1.1.6  christos 
   2430   1.1.1.6  christos 	  switch ((int) r_type)
   2431   1.1.1.6  christos 	    {
   2432   1.1.1.6  christos 	    case R_M32R_GOTOFF:
   2433   1.1.1.6  christos 	      /* Relocation is relative to the start of the global offset
   2434   1.1.1.6  christos 		 table (for ld24 rx, #uimm24). eg access at label+addend
   2435   1.1.1.6  christos 
   2436   1.1.1.6  christos 		 ld24 rx. #label@GOTOFF + addend
   2437   1.1.1.6  christos 		 sub  rx, r12.  */
   2438   1.1.1.6  christos 
   2439   1.1.1.6  christos 	      BFD_ASSERT (sgot != NULL);
   2440   1.1.1.6  christos 
   2441   1.1.1.6  christos 	      relocation = -(relocation - sgot->output_section->vma);
   2442   1.1.1.6  christos 	      rel->r_addend = -rel->r_addend;
   2443       1.1     skrll 	      break;
   2444       1.1     skrll 
   2445       1.1     skrll 	    case R_M32R_GOTOFF_HI_ULO:
   2446       1.1     skrll 	    case R_M32R_GOTOFF_HI_SLO:
   2447       1.1     skrll 	    case R_M32R_GOTOFF_LO:
   2448       1.1     skrll 	      BFD_ASSERT (sgot != NULL);
   2449       1.1     skrll 
   2450       1.1     skrll 	      relocation -= sgot->output_section->vma;
   2451       1.1     skrll 
   2452   1.1.1.6  christos 	      if ((r_type == R_M32R_GOTOFF_HI_SLO)
   2453   1.1.1.6  christos 		  && ((relocation + rel->r_addend) & 0x8000))
   2454   1.1.1.6  christos 		rel->r_addend += 0x10000;
   2455   1.1.1.6  christos 	      break;
   2456   1.1.1.6  christos 
   2457   1.1.1.6  christos 	    case R_M32R_GOTPC24:
   2458   1.1.1.6  christos 	      /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
   2459   1.1.1.6  christos 		 ld24 rx,#_GLOBAL_OFFSET_TABLE_
   2460   1.1.1.6  christos 	       */
   2461   1.1.1.6  christos 	     relocation = sgot->output_section->vma;
   2462   1.1.1.6  christos 	     break;
   2463   1.1.1.6  christos 
   2464   1.1.1.6  christos 	    case R_M32R_GOTPC_HI_ULO:
   2465   1.1.1.6  christos 	    case R_M32R_GOTPC_HI_SLO:
   2466   1.1.1.6  christos 	    case R_M32R_GOTPC_LO:
   2467   1.1.1.6  christos 	      {
   2468   1.1.1.6  christos 		/* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
   2469   1.1.1.6  christos 		   bl .+4
   2470   1.1.1.6  christos 		   seth rx,#high(_GLOBAL_OFFSET_TABLE_)
   2471   1.1.1.6  christos 		   or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
   2472   1.1.1.6  christos 		   or
   2473   1.1.1.6  christos 		   bl .+4
   2474   1.1.1.6  christos 		   seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
   2475   1.1.1.6  christos 		   add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
   2476   1.1.1.6  christos 		 */
   2477   1.1.1.6  christos 		relocation = sgot->output_section->vma;
   2478   1.1.1.6  christos 		relocation -= (input_section->output_section->vma
   2479   1.1.1.6  christos 			       + input_section->output_offset
   2480   1.1.1.6  christos 			       + rel->r_offset);
   2481   1.1.1.6  christos 		if ((r_type == R_M32R_GOTPC_HI_SLO)
   2482   1.1.1.6  christos 		     && ((relocation + rel->r_addend) & 0x8000))
   2483   1.1.1.6  christos 		  rel->r_addend += 0x10000;
   2484   1.1.1.6  christos 
   2485   1.1.1.6  christos 		break;
   2486   1.1.1.6  christos 	      }
   2487   1.1.1.6  christos 	    case R_M32R_GOT16_HI_ULO:
   2488   1.1.1.6  christos 	    case R_M32R_GOT16_HI_SLO:
   2489   1.1.1.6  christos 	    case R_M32R_GOT16_LO:
   2490   1.1.1.6  christos 	      /* Fall through.  */
   2491   1.1.1.6  christos 	    case R_M32R_GOT24:
   2492   1.1.1.6  christos 	      /* Relocation is to the entry for this symbol in the global
   2493   1.1.1.9  christos 		 offset table.  */
   2494   1.1.1.6  christos 	      BFD_ASSERT (sgot != NULL);
   2495       1.1     skrll 
   2496   1.1.1.6  christos 	      if (h != NULL)
   2497   1.1.1.6  christos 		{
   2498       1.1     skrll 		  bool dyn;
   2499   1.1.1.9  christos 		  bfd_vma off;
   2500   1.1.1.6  christos 
   2501   1.1.1.4  christos 		  off = h->got.offset;
   2502   1.1.1.4  christos 		  BFD_ASSERT (off != (bfd_vma) -1);
   2503   1.1.1.6  christos 
   2504   1.1.1.6  christos 		  dyn = htab->dynamic_sections_created;
   2505   1.1.1.6  christos 		  if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   2506   1.1.1.6  christos 							 bfd_link_pic (info),
   2507   1.1.1.6  christos 							 h)
   2508   1.1.1.6  christos 		      || (bfd_link_pic (info)
   2509   1.1.1.6  christos 			  && (info->symbolic
   2510   1.1.1.6  christos 			      || h->dynindx == -1
   2511   1.1.1.6  christos 			      || h->forced_local)
   2512   1.1.1.6  christos 			  && h->def_regular))
   2513   1.1.1.6  christos 		    {
   2514   1.1.1.6  christos 		      /* This is actually a static link, or it is a
   2515   1.1.1.6  christos 			 -Bsymbolic link and the symbol is defined
   2516   1.1.1.6  christos 			 locally, or the symbol was forced to be local
   2517   1.1.1.6  christos 			 because of a version file.  We must initialize
   2518   1.1.1.6  christos 			 this entry in the global offset table.  Since the
   2519   1.1.1.6  christos 			 offset must always be a multiple of 4, we use the
   2520   1.1.1.6  christos 			 least significant bit to record whether we have
   2521   1.1.1.6  christos 			 initialized it already.
   2522   1.1.1.6  christos 
   2523   1.1.1.6  christos 			 When doing a dynamic link, we create a .rela.got
   2524   1.1.1.6  christos 			 relocation entry to initialize the value.  This
   2525   1.1.1.6  christos 			 is done in the finish_dynamic_symbol routine.  */
   2526   1.1.1.6  christos 		      if ((off & 1) != 0)
   2527   1.1.1.6  christos 			off &= ~1;
   2528   1.1.1.6  christos 		      else
   2529   1.1.1.6  christos 			{
   2530   1.1.1.6  christos 			  bfd_put_32 (output_bfd, relocation,
   2531   1.1.1.6  christos 				      sgot->contents + off);
   2532   1.1.1.6  christos 			  h->got.offset |= 1;
   2533   1.1.1.6  christos 			}
   2534   1.1.1.6  christos 		    }
   2535   1.1.1.6  christos 
   2536   1.1.1.6  christos 		  relocation = sgot->output_offset + off;
   2537   1.1.1.6  christos 		}
   2538   1.1.1.6  christos 	      else
   2539   1.1.1.6  christos 		{
   2540   1.1.1.6  christos 		  bfd_vma off;
   2541   1.1.1.6  christos 		  bfd_byte *loc;
   2542   1.1.1.6  christos 
   2543   1.1.1.6  christos 		  BFD_ASSERT (local_got_offsets != NULL
   2544   1.1.1.6  christos 			      && local_got_offsets[r_symndx] != (bfd_vma) -1);
   2545   1.1.1.6  christos 
   2546   1.1.1.6  christos 		  off = local_got_offsets[r_symndx];
   2547   1.1.1.6  christos 
   2548   1.1.1.6  christos 		  /* The offset must always be a multiple of 4.  We use
   2549   1.1.1.6  christos 		     the least significant bit to record whether we have
   2550   1.1.1.6  christos 		     already processed this entry.  */
   2551   1.1.1.6  christos 		  if ((off & 1) != 0)
   2552   1.1.1.6  christos 		    off &= ~1;
   2553   1.1.1.6  christos 		  else
   2554   1.1.1.6  christos 		    {
   2555   1.1.1.6  christos 		      bfd_put_32 (output_bfd, relocation, sgot->contents + off);
   2556   1.1.1.6  christos 
   2557   1.1.1.6  christos 		      if (bfd_link_pic (info))
   2558   1.1.1.6  christos 			{
   2559   1.1.1.9  christos 			  asection *srelgot;
   2560   1.1.1.6  christos 			  Elf_Internal_Rela outrel;
   2561   1.1.1.6  christos 
   2562   1.1.1.6  christos 			  /* We need to generate a R_M32R_RELATIVE reloc
   2563   1.1.1.6  christos 			     for the dynamic linker.  */
   2564   1.1.1.6  christos 			  srelgot = htab->srelgot;
   2565   1.1.1.6  christos 			  BFD_ASSERT (srelgot != NULL);
   2566   1.1.1.6  christos 
   2567   1.1.1.6  christos 			  outrel.r_offset = (sgot->output_section->vma
   2568   1.1.1.6  christos 					     + sgot->output_offset
   2569   1.1.1.6  christos 					     + off);
   2570   1.1.1.6  christos 			  outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
   2571   1.1.1.6  christos 			  outrel.r_addend = relocation;
   2572   1.1.1.6  christos 			  loc = srelgot->contents;
   2573   1.1.1.6  christos 			  loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
   2574   1.1.1.6  christos 			  bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
   2575   1.1.1.6  christos 			  ++srelgot->reloc_count;
   2576   1.1.1.6  christos 			}
   2577   1.1.1.6  christos 
   2578   1.1.1.6  christos 		      local_got_offsets[r_symndx] |= 1;
   2579   1.1.1.6  christos 		    }
   2580   1.1.1.6  christos 
   2581   1.1.1.6  christos 		  relocation = sgot->output_offset + off;
   2582   1.1.1.6  christos 		}
   2583       1.1     skrll 	      if ((r_type == R_M32R_GOT16_HI_SLO)
   2584   1.1.1.6  christos 		  && ((relocation + rel->r_addend) & 0x8000))
   2585   1.1.1.6  christos 		rel->r_addend += 0x10000;
   2586   1.1.1.6  christos 
   2587   1.1.1.6  christos 	      break;
   2588   1.1.1.6  christos 
   2589   1.1.1.6  christos 	    case R_M32R_26_PLTREL:
   2590   1.1.1.6  christos 	      /* Relocation is to the entry for this symbol in the
   2591   1.1.1.6  christos 		 procedure linkage table.  */
   2592   1.1.1.6  christos 
   2593       1.1     skrll 	      /* The native assembler will generate a 26_PLTREL reloc
   2594   1.1.1.6  christos 		 for a local symbol if you assemble a call from one
   2595   1.1.1.6  christos 		 section to another when using -K pic. */
   2596   1.1.1.6  christos 	      if (h == NULL)
   2597   1.1.1.6  christos 		break;
   2598       1.1     skrll 
   2599       1.1     skrll 	      if (h->forced_local)
   2600       1.1     skrll 		break;
   2601       1.1     skrll 
   2602       1.1     skrll 	      if (h->plt.offset == (bfd_vma) -1)
   2603   1.1.1.6  christos 		/* We didn't make a PLT entry for this symbol.  This
   2604   1.1.1.6  christos 		   happens when statically linking PIC code, or when
   2605   1.1.1.6  christos 		   using -Bsymbolic.  */
   2606   1.1.1.6  christos 		break;
   2607       1.1     skrll 
   2608   1.1.1.6  christos 	      relocation = (splt->output_section->vma
   2609       1.1     skrll 			    + splt->output_offset
   2610       1.1     skrll 			    + h->plt.offset);
   2611   1.1.1.6  christos 	      break;
   2612       1.1     skrll 
   2613   1.1.1.6  christos 	    case R_M32R_HI16_SLO_RELA:
   2614   1.1.1.6  christos 	      if ((relocation + rel->r_addend) & 0x8000)
   2615   1.1.1.6  christos 		rel->r_addend += 0x10000;
   2616   1.1.1.6  christos 	      /* Fall through.  */
   2617       1.1     skrll 
   2618   1.1.1.6  christos 	    case R_M32R_16_RELA:
   2619   1.1.1.6  christos 	    case R_M32R_24_RELA:
   2620   1.1.1.6  christos 	    case R_M32R_32_RELA:
   2621   1.1.1.6  christos 	    case R_M32R_REL32:
   2622   1.1.1.6  christos 	    case R_M32R_10_PCREL_RELA:
   2623   1.1.1.6  christos 	    case R_M32R_18_PCREL_RELA:
   2624   1.1.1.6  christos 	    case R_M32R_26_PCREL_RELA:
   2625   1.1.1.6  christos 	    case R_M32R_HI16_ULO_RELA:
   2626   1.1.1.6  christos 	    case R_M32R_LO16_RELA:
   2627   1.1.1.6  christos 	      if (bfd_link_pic (info)
   2628   1.1.1.6  christos 		  && r_symndx != STN_UNDEF
   2629   1.1.1.6  christos 		  && (input_section->flags & SEC_ALLOC) != 0
   2630   1.1.1.6  christos 		  && ((   r_type != R_M32R_10_PCREL_RELA
   2631   1.1.1.6  christos 		       && r_type != R_M32R_18_PCREL_RELA
   2632   1.1.1.6  christos 		       && r_type != R_M32R_26_PCREL_RELA
   2633   1.1.1.6  christos 		       && r_type != R_M32R_REL32)
   2634   1.1.1.6  christos 		      || (h != NULL
   2635   1.1.1.9  christos 			  && h->dynindx != -1
   2636   1.1.1.6  christos 			  && (! info->symbolic
   2637   1.1.1.6  christos 			      || !h->def_regular))))
   2638   1.1.1.6  christos 		{
   2639   1.1.1.6  christos 		  Elf_Internal_Rela outrel;
   2640   1.1.1.6  christos 		  bool skip, relocate;
   2641   1.1.1.6  christos 		  bfd_byte *loc;
   2642   1.1.1.6  christos 
   2643   1.1.1.2  christos 		  /* When generating a shared object, these relocations
   2644   1.1.1.9  christos 		     are copied into the output file to be resolved at run
   2645   1.1.1.2  christos 		     time.  */
   2646   1.1.1.9  christos 		  if (sreloc == NULL)
   2647   1.1.1.6  christos 		    {
   2648       1.1     skrll 		      sreloc = _bfd_elf_get_dynamic_reloc_section
   2649   1.1.1.9  christos 			(input_bfd, input_section, /*rela?*/ true);
   2650   1.1.1.9  christos 		      if (sreloc == NULL)
   2651       1.1     skrll 			return false;
   2652   1.1.1.6  christos 		    }
   2653   1.1.1.6  christos 
   2654   1.1.1.6  christos 		  skip = false;
   2655   1.1.1.6  christos 		  relocate = false;
   2656   1.1.1.6  christos 
   2657   1.1.1.9  christos 		  outrel.r_offset = _bfd_elf_section_offset (output_bfd,
   2658   1.1.1.6  christos 							     info,
   2659   1.1.1.9  christos 							     input_section,
   2660   1.1.1.6  christos 							     rel->r_offset);
   2661   1.1.1.6  christos 		  if (outrel.r_offset == (bfd_vma) -1)
   2662   1.1.1.6  christos 		    skip = true;
   2663   1.1.1.6  christos 		  else if (outrel.r_offset == (bfd_vma) -2)
   2664   1.1.1.6  christos 		    skip = relocate = true;
   2665   1.1.1.6  christos 		  outrel.r_offset += (input_section->output_section->vma
   2666   1.1.1.6  christos 				      + input_section->output_offset);
   2667   1.1.1.6  christos 
   2668   1.1.1.6  christos 		  if (skip)
   2669   1.1.1.6  christos 		    memset (&outrel, 0, sizeof outrel);
   2670   1.1.1.6  christos 		  else if (   r_type == R_M32R_10_PCREL_RELA
   2671   1.1.1.6  christos 			   || r_type == R_M32R_18_PCREL_RELA
   2672   1.1.1.6  christos 			   || r_type == R_M32R_26_PCREL_RELA
   2673   1.1.1.6  christos 			   || r_type == R_M32R_REL32)
   2674   1.1.1.6  christos 		    {
   2675   1.1.1.6  christos 		      BFD_ASSERT (h != NULL && h->dynindx != -1);
   2676   1.1.1.6  christos 		      outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   2677   1.1.1.6  christos 		      outrel.r_addend = rel->r_addend;
   2678   1.1.1.6  christos 		    }
   2679   1.1.1.6  christos 		  else
   2680   1.1.1.6  christos 		    {
   2681   1.1.1.6  christos 		    /* h->dynindx may be -1 if this symbol was marked to
   2682   1.1.1.9  christos 		       become local.  */
   2683   1.1.1.6  christos 		    if (h == NULL
   2684   1.1.1.6  christos 			|| ((info->symbolic || h->dynindx == -1)
   2685   1.1.1.6  christos 			     && h->def_regular))
   2686   1.1.1.6  christos 		      {
   2687   1.1.1.6  christos 			relocate = true;
   2688   1.1.1.6  christos 			outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
   2689   1.1.1.6  christos 			outrel.r_addend = relocation + rel->r_addend;
   2690   1.1.1.6  christos 		      }
   2691   1.1.1.6  christos 		    else
   2692   1.1.1.6  christos 		      {
   2693   1.1.1.6  christos 			BFD_ASSERT (h->dynindx != -1);
   2694   1.1.1.6  christos 			outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   2695   1.1.1.6  christos 			outrel.r_addend = relocation + rel->r_addend;
   2696   1.1.1.6  christos 		      }
   2697   1.1.1.6  christos 		    }
   2698   1.1.1.6  christos 
   2699   1.1.1.6  christos 		  loc = sreloc->contents;
   2700   1.1.1.6  christos 		  loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
   2701   1.1.1.6  christos 		  bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
   2702   1.1.1.6  christos 		  ++sreloc->reloc_count;
   2703   1.1.1.6  christos 
   2704   1.1.1.6  christos 		  /* If this reloc is against an external symbol, we do
   2705       1.1     skrll 		     not want to fiddle with the addend.  Otherwise, we
   2706   1.1.1.6  christos 		     need to include the symbol value so that it becomes
   2707       1.1     skrll 		     an addend for the dynamic reloc.  */
   2708       1.1     skrll 		  if (! relocate)
   2709       1.1     skrll 		    continue;
   2710       1.1     skrll 		  break;
   2711       1.1     skrll 		}
   2712       1.1     skrll 	      else if (r_type != R_M32R_10_PCREL_RELA)
   2713       1.1     skrll 		break;
   2714       1.1     skrll 	      /* Fall through.  */
   2715   1.1.1.6  christos 
   2716       1.1     skrll 	    case (int) R_M32R_10_PCREL :
   2717       1.1     skrll 	      r = m32r_elf_do_10_pcrel_reloc (input_bfd, howto, input_section,
   2718       1.1     skrll 					      contents, offset,
   2719       1.1     skrll 					      sec, relocation, addend);
   2720       1.1     skrll 	      goto check_reloc;
   2721       1.1     skrll 
   2722       1.1     skrll 	    case (int) R_M32R_HI16_SLO :
   2723       1.1     skrll 	    case (int) R_M32R_HI16_ULO :
   2724       1.1     skrll 	      {
   2725       1.1     skrll 		Elf_Internal_Rela *lorel;
   2726       1.1     skrll 
   2727       1.1     skrll 		/* We allow an arbitrary number of HI16 relocs before the
   2728       1.1     skrll 		   LO16 reloc.  This permits gcc to emit the HI and LO relocs
   2729       1.1     skrll 		   itself.  */
   2730       1.1     skrll 		for (lorel = rel + 1;
   2731       1.1     skrll 		     (lorel < relend
   2732       1.1     skrll 		      && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
   2733       1.1     skrll 			  || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
   2734       1.1     skrll 		     lorel++)
   2735       1.1     skrll 		  continue;
   2736       1.1     skrll 		if (lorel < relend
   2737       1.1     skrll 		    && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
   2738       1.1     skrll 		  {
   2739       1.1     skrll 		    m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
   2740       1.1     skrll 					    contents, relocation + addend);
   2741       1.1     skrll 		    r = bfd_reloc_ok;
   2742       1.1     skrll 		  }
   2743       1.1     skrll 		else
   2744   1.1.1.6  christos 		  r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   2745       1.1     skrll 						contents, offset,
   2746   1.1.1.6  christos 						relocation, addend);
   2747       1.1     skrll 	      }
   2748       1.1     skrll 
   2749       1.1     skrll 	      goto check_reloc;
   2750       1.1     skrll 
   2751       1.1     skrll 	    case (int) R_M32R_SDA16_RELA:
   2752   1.1.1.8  christos 	    case (int) R_M32R_SDA16 :
   2753       1.1     skrll 	      {
   2754       1.1     skrll 		const char *name;
   2755       1.1     skrll 
   2756       1.1     skrll 		BFD_ASSERT (sec != NULL);
   2757       1.1     skrll 		name = bfd_section_name (sec);
   2758       1.1     skrll 
   2759       1.1     skrll 		if (   strcmp (name, ".sdata") == 0
   2760       1.1     skrll 		    || strcmp (name, ".sbss") == 0
   2761       1.1     skrll 		    || strcmp (name, ".scommon") == 0)
   2762       1.1     skrll 		  {
   2763       1.1     skrll 		    bfd_vma sda_base;
   2764       1.1     skrll 		    bfd *out_bfd = sec->output_section->owner;
   2765       1.1     skrll 
   2766   1.1.1.9  christos 		    r = m32r_elf_final_sda_base (out_bfd, info,
   2767       1.1     skrll 						 &errmsg,
   2768       1.1     skrll 						 &sda_base);
   2769       1.1     skrll 		    if (r != bfd_reloc_ok)
   2770       1.1     skrll 		      {
   2771       1.1     skrll 			ret = false;
   2772       1.1     skrll 			goto check_reloc;
   2773       1.1     skrll 		      }
   2774       1.1     skrll 
   2775       1.1     skrll 		    /* At this point `relocation' contains the object's
   2776       1.1     skrll 		       address.  */
   2777   1.1.1.6  christos 		    relocation -= sda_base;
   2778   1.1.1.6  christos 		    /* Now it contains the offset from _SDA_BASE_.  */
   2779   1.1.1.7  christos 		  }
   2780   1.1.1.7  christos 		else
   2781       1.1     skrll 		  {
   2782       1.1     skrll 		    _bfd_error_handler
   2783   1.1.1.6  christos 		      /* xgettext:c-format */
   2784   1.1.1.6  christos 		      (_("%pB: the target (%s) of an %s relocation"
   2785       1.1     skrll 			 " is in the wrong section (%pA)"),
   2786   1.1.1.9  christos 		       input_bfd,
   2787       1.1     skrll 		       sym_name,
   2788       1.1     skrll 		       m32r_elf_howto_table[(int) r_type].name,
   2789       1.1     skrll 		       sec);
   2790   1.1.1.6  christos 		    /*bfd_set_error (bfd_error_bad_value); ??? why? */
   2791       1.1     skrll 		    ret = false;
   2792       1.1     skrll 		    continue;
   2793       1.1     skrll 		  }
   2794       1.1     skrll 	      }
   2795       1.1     skrll 	      /* Fall through.  */
   2796       1.1     skrll 
   2797       1.1     skrll 	    default : /* OLD_M32R_RELOC */
   2798       1.1     skrll 
   2799       1.1     skrll 	      r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   2800   1.1.1.6  christos 					    contents, offset,
   2801   1.1.1.6  christos 					    relocation, addend);
   2802   1.1.1.6  christos 	      goto check_reloc;
   2803       1.1     skrll 	    }
   2804       1.1     skrll 
   2805       1.1     skrll 	  r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   2806       1.1     skrll 					contents, rel->r_offset,
   2807       1.1     skrll 					relocation, rel->r_addend);
   2808       1.1     skrll 
   2809       1.1     skrll 	}
   2810       1.1     skrll 
   2811       1.1     skrll     check_reloc:
   2812       1.1     skrll 
   2813       1.1     skrll       if (r != bfd_reloc_ok)
   2814       1.1     skrll 	{
   2815       1.1     skrll 	  /* FIXME: This should be generic enough to go in a utility.  */
   2816       1.1     skrll 	  const char *name;
   2817       1.1     skrll 
   2818       1.1     skrll 	  if (h != NULL)
   2819       1.1     skrll 	    name = h->root.root.string;
   2820   1.1.1.8  christos 	  else
   2821       1.1     skrll 	    {
   2822       1.1     skrll 	      name = (bfd_elf_string_from_elf_section
   2823       1.1     skrll 		      (input_bfd, symtab_hdr->sh_link, sym->st_name));
   2824       1.1     skrll 	      if (name == NULL || *name == '\0')
   2825       1.1     skrll 		name = bfd_section_name (sec);
   2826       1.1     skrll 	    }
   2827       1.1     skrll 
   2828       1.1     skrll 	  if (errmsg != NULL)
   2829   1.1.1.5  christos 	    goto common_error;
   2830   1.1.1.5  christos 
   2831   1.1.1.5  christos 	  switch (r)
   2832       1.1     skrll 	    {
   2833       1.1     skrll 	    case bfd_reloc_overflow:
   2834       1.1     skrll 	      (*info->callbacks->reloc_overflow)
   2835   1.1.1.5  christos 		(info, (h ? &h->root : NULL), name, howto->name,
   2836   1.1.1.9  christos 		 (bfd_vma) 0, input_bfd, input_section, offset);
   2837       1.1     skrll 	      break;
   2838       1.1     skrll 
   2839       1.1     skrll 	    case bfd_reloc_undefined:
   2840       1.1     skrll 	      (*info->callbacks->undefined_symbol)
   2841       1.1     skrll 		(info, name, input_bfd, input_section, offset, true);
   2842       1.1     skrll 	      break;
   2843       1.1     skrll 
   2844       1.1     skrll 	    case bfd_reloc_outofrange:
   2845       1.1     skrll 	      errmsg = _("internal error: out of range error");
   2846       1.1     skrll 	      goto common_error;
   2847       1.1     skrll 
   2848       1.1     skrll 	    case bfd_reloc_notsupported:
   2849       1.1     skrll 	      errmsg = _("internal error: unsupported relocation error");
   2850       1.1     skrll 	      goto common_error;
   2851       1.1     skrll 
   2852       1.1     skrll 	    case bfd_reloc_dangerous:
   2853       1.1     skrll 	      errmsg = _("internal error: dangerous error");
   2854       1.1     skrll 	      goto common_error;
   2855       1.1     skrll 
   2856   1.1.1.5  christos 	    default:
   2857   1.1.1.5  christos 	      errmsg = _("internal error: unknown error");
   2858       1.1     skrll 	      /* fall through */
   2859       1.1     skrll 
   2860       1.1     skrll 	    common_error:
   2861       1.1     skrll 	      (*info->callbacks->warning) (info, errmsg, name, input_bfd,
   2862       1.1     skrll 					   input_section, offset);
   2863       1.1     skrll 	      break;
   2864       1.1     skrll 	    }
   2865       1.1     skrll 	}
   2866       1.1     skrll     }
   2867       1.1     skrll 
   2868       1.1     skrll   return ret;
   2869   1.1.1.9  christos }
   2870       1.1     skrll 
   2871       1.1     skrll /* Finish up dynamic symbol handling.  We set the contents of various
   2872       1.1     skrll    dynamic sections here.  */
   2873       1.1     skrll 
   2874       1.1     skrll static bool
   2875   1.1.1.9  christos m32r_elf_finish_dynamic_symbol (bfd *output_bfd,
   2876       1.1     skrll 				struct bfd_link_info *info,
   2877       1.1     skrll 				struct elf_link_hash_entry *h,
   2878       1.1     skrll 				Elf_Internal_Sym *sym)
   2879       1.1     skrll {
   2880       1.1     skrll   struct elf_link_hash_table *htab;
   2881       1.1     skrll   bfd_byte *loc;
   2882       1.1     skrll 
   2883       1.1     skrll #ifdef DEBUG_PIC
   2884       1.1     skrll   printf ("m32r_elf_finish_dynamic_symbol()\n");
   2885       1.1     skrll #endif
   2886       1.1     skrll 
   2887       1.1     skrll   htab = m32r_elf_hash_table (info);
   2888       1.1     skrll 
   2889       1.1     skrll   if (h->plt.offset != (bfd_vma) -1)
   2890       1.1     skrll     {
   2891       1.1     skrll       asection *splt;
   2892       1.1     skrll       asection *sgot;
   2893       1.1     skrll       asection *srela;
   2894       1.1     skrll 
   2895   1.1.1.6  christos       bfd_vma plt_index;
   2896       1.1     skrll       bfd_vma got_offset;
   2897       1.1     skrll       Elf_Internal_Rela rela;
   2898       1.1     skrll 
   2899   1.1.1.9  christos       /* This symbol has an entry in the procedure linkage table.  Set
   2900   1.1.1.9  christos 	 it up.  */
   2901   1.1.1.9  christos 
   2902       1.1     skrll       BFD_ASSERT (h->dynindx != -1);
   2903       1.1     skrll 
   2904       1.1     skrll       splt = htab->splt;
   2905   1.1.1.6  christos       sgot = htab->sgotplt;
   2906   1.1.1.6  christos       srela = htab->srelplt;
   2907   1.1.1.6  christos       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
   2908       1.1     skrll 
   2909       1.1     skrll       /* Get the index in the procedure linkage table which
   2910       1.1     skrll 	 corresponds to this symbol.  This is the index of this symbol
   2911   1.1.1.6  christos 	 in all the symbols for which we are making plt entries.  The
   2912   1.1.1.6  christos 	 first entry in the procedure linkage table is reserved.  */
   2913       1.1     skrll       plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   2914       1.1     skrll 
   2915       1.1     skrll       /* Get the offset into the .got table of the entry that
   2916   1.1.1.4  christos 	corresponds to this function.  Each .got entry is 4 bytes.
   2917   1.1.1.6  christos 	The first three are reserved.  */
   2918   1.1.1.6  christos       got_offset = (plt_index + 3) * 4;
   2919   1.1.1.6  christos 
   2920   1.1.1.6  christos       /* Fill in the entry in the procedure linkage table.  */
   2921   1.1.1.6  christos       if (! bfd_link_pic (info))
   2922   1.1.1.6  christos 	{
   2923   1.1.1.6  christos 	  bfd_put_32 (output_bfd,
   2924   1.1.1.6  christos 	      (PLT_ENTRY_WORD0b
   2925   1.1.1.6  christos 	       + (((sgot->output_section->vma
   2926   1.1.1.6  christos 		    + sgot->output_offset
   2927   1.1.1.6  christos 		    + got_offset) >> 16) & 0xffff)),
   2928   1.1.1.6  christos 	      splt->contents + h->plt.offset);
   2929   1.1.1.6  christos 	  bfd_put_32 (output_bfd,
   2930   1.1.1.6  christos 	      (PLT_ENTRY_WORD1b
   2931   1.1.1.6  christos 	       + ((sgot->output_section->vma
   2932   1.1.1.6  christos 		   + sgot->output_offset
   2933   1.1.1.6  christos 		   + got_offset) & 0xffff)),
   2934   1.1.1.6  christos 	      splt->contents + h->plt.offset + 4);
   2935   1.1.1.6  christos 	  bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
   2936   1.1.1.6  christos 	      splt->contents + h->plt.offset + 8);
   2937   1.1.1.6  christos 	  bfd_put_32 (output_bfd,
   2938   1.1.1.6  christos 	      (PLT_ENTRY_WORD3
   2939   1.1.1.6  christos 	       + plt_index * sizeof (Elf32_External_Rela)),
   2940   1.1.1.6  christos 	      splt->contents + h->plt.offset + 12);
   2941       1.1     skrll 	  bfd_put_32 (output_bfd,
   2942   1.1.1.6  christos 	      (PLT_ENTRY_WORD4
   2943   1.1.1.6  christos 	       + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
   2944   1.1.1.6  christos 	      splt->contents + h->plt.offset + 16);
   2945   1.1.1.6  christos 	}
   2946   1.1.1.6  christos       else
   2947   1.1.1.6  christos 	{
   2948   1.1.1.6  christos 	  bfd_put_32 (output_bfd,
   2949   1.1.1.6  christos 	      PLT_ENTRY_WORD0 + got_offset,
   2950   1.1.1.6  christos 	      splt->contents + h->plt.offset);
   2951   1.1.1.6  christos 	  bfd_put_32 (output_bfd, PLT_ENTRY_WORD1,
   2952   1.1.1.6  christos 	      splt->contents + h->plt.offset + 4);
   2953   1.1.1.6  christos 	  bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
   2954   1.1.1.6  christos 	      splt->contents + h->plt.offset + 8);
   2955   1.1.1.6  christos 	  bfd_put_32 (output_bfd,
   2956   1.1.1.6  christos 	      (PLT_ENTRY_WORD3
   2957   1.1.1.6  christos 	       + plt_index * sizeof (Elf32_External_Rela)),
   2958   1.1.1.6  christos 	      splt->contents + h->plt.offset + 12);
   2959       1.1     skrll 	  bfd_put_32 (output_bfd,
   2960       1.1     skrll 	      (PLT_ENTRY_WORD4
   2961       1.1     skrll 	       + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
   2962   1.1.1.6  christos 	      splt->contents + h->plt.offset + 16);
   2963   1.1.1.6  christos 	}
   2964   1.1.1.6  christos 
   2965   1.1.1.6  christos       /* Fill in the entry in the global offset table.  */
   2966   1.1.1.6  christos       bfd_put_32 (output_bfd,
   2967       1.1     skrll 		  (splt->output_section->vma
   2968       1.1     skrll 		   + splt->output_offset
   2969       1.1     skrll 		   + h->plt.offset
   2970   1.1.1.6  christos 		   + 12), /* same offset */
   2971   1.1.1.6  christos 		  sgot->contents + got_offset);
   2972       1.1     skrll 
   2973       1.1     skrll       /* Fill in the entry in the .rela.plt section.  */
   2974       1.1     skrll       rela.r_offset = (sgot->output_section->vma
   2975       1.1     skrll 		       + sgot->output_offset
   2976       1.1     skrll 		       + got_offset);
   2977       1.1     skrll       rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_JMP_SLOT);
   2978       1.1     skrll       rela.r_addend = 0;
   2979   1.1.1.6  christos       loc = srela->contents;
   2980   1.1.1.6  christos       loc += plt_index * sizeof (Elf32_External_Rela);
   2981   1.1.1.6  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   2982   1.1.1.6  christos 
   2983   1.1.1.6  christos       if (!h->def_regular)
   2984       1.1     skrll 	{
   2985       1.1     skrll 	  /* Mark the symbol as undefined, rather than as defined in
   2986       1.1     skrll 	     the .plt section.  Leave the value alone.  */
   2987       1.1     skrll 	  sym->st_shndx = SHN_UNDEF;
   2988       1.1     skrll 	}
   2989       1.1     skrll     }
   2990       1.1     skrll 
   2991       1.1     skrll   if (h->got.offset != (bfd_vma) -1)
   2992       1.1     skrll     {
   2993   1.1.1.6  christos       asection *sgot;
   2994       1.1     skrll       asection *srela;
   2995   1.1.1.9  christos       Elf_Internal_Rela rela;
   2996   1.1.1.9  christos 
   2997       1.1     skrll       /* This symbol has an entry in the global offset table.  Set it
   2998       1.1     skrll 	 up.  */
   2999       1.1     skrll 
   3000   1.1.1.6  christos       sgot = htab->sgot;
   3001   1.1.1.6  christos       srela = htab->srelgot;
   3002       1.1     skrll       BFD_ASSERT (sgot != NULL && srela != NULL);
   3003       1.1     skrll 
   3004   1.1.1.6  christos       rela.r_offset = (sgot->output_section->vma
   3005   1.1.1.6  christos 		       + sgot->output_offset
   3006   1.1.1.6  christos 		       + (h->got.offset &~ 1));
   3007   1.1.1.6  christos 
   3008   1.1.1.4  christos       /* If this is a -Bsymbolic link, and the symbol is defined
   3009   1.1.1.6  christos 	 locally, we just want to emit a RELATIVE reloc.  Likewise if
   3010       1.1     skrll 	 the symbol was forced to be local because of a version file.
   3011       1.1     skrll 	 The entry in the global offset table will already have been
   3012   1.1.1.6  christos 	 initialized in the relocate_section function.  */
   3013   1.1.1.6  christos       if (bfd_link_pic (info)
   3014   1.1.1.6  christos 	  && (info->symbolic
   3015   1.1.1.6  christos 	      || h->dynindx == -1
   3016   1.1.1.6  christos 	      || h->forced_local)
   3017   1.1.1.6  christos 	  && h->def_regular)
   3018   1.1.1.6  christos 	{
   3019       1.1     skrll 	  rela.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
   3020   1.1.1.6  christos 	  rela.r_addend = (h->root.u.def.value
   3021       1.1     skrll 			   + h->root.u.def.section->output_section->vma
   3022   1.1.1.6  christos 			   + h->root.u.def.section->output_offset);
   3023   1.1.1.6  christos 	}
   3024   1.1.1.6  christos       else
   3025   1.1.1.6  christos 	{
   3026       1.1     skrll 	  BFD_ASSERT ((h->got.offset & 1) == 0);
   3027       1.1     skrll 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   3028       1.1     skrll 	  rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_GLOB_DAT);
   3029       1.1     skrll 	  rela.r_addend = 0;
   3030       1.1     skrll 	}
   3031       1.1     skrll 
   3032       1.1     skrll       loc = srela->contents;
   3033       1.1     skrll       loc += srela->reloc_count * sizeof (Elf32_External_Rela);
   3034       1.1     skrll       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   3035       1.1     skrll       ++srela->reloc_count;
   3036       1.1     skrll     }
   3037       1.1     skrll 
   3038       1.1     skrll   if (h->needs_copy)
   3039       1.1     skrll     {
   3040       1.1     skrll       asection *s;
   3041   1.1.1.6  christos       Elf_Internal_Rela rela;
   3042   1.1.1.6  christos 
   3043       1.1     skrll       /* This symbols needs a copy reloc.  Set it up.  */
   3044   1.1.1.9  christos 
   3045       1.1     skrll       BFD_ASSERT (h->dynindx != -1
   3046       1.1     skrll 		  && (h->root.type == bfd_link_hash_defined
   3047       1.1     skrll 		      || h->root.type == bfd_link_hash_defweak));
   3048   1.1.1.6  christos 
   3049   1.1.1.6  christos       s = bfd_get_linker_section (htab->dynobj, ".rela.bss");
   3050       1.1     skrll       BFD_ASSERT (s != NULL);
   3051       1.1     skrll 
   3052       1.1     skrll       rela.r_offset = (h->root.u.def.value
   3053       1.1     skrll 		       + h->root.u.def.section->output_section->vma
   3054       1.1     skrll 		       + h->root.u.def.section->output_offset);
   3055       1.1     skrll       rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_COPY);
   3056       1.1     skrll       rela.r_addend = 0;
   3057       1.1     skrll       loc = s->contents;
   3058       1.1     skrll       loc += s->reloc_count * sizeof (Elf32_External_Rela);
   3059   1.1.1.9  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   3060       1.1     skrll       ++s->reloc_count;
   3061       1.1     skrll     }
   3062   1.1.1.9  christos 
   3063       1.1     skrll   /* Mark some specially defined symbols as absolute.  */
   3064       1.1     skrll   if (h == htab->hdynamic || h == htab->hgot)
   3065       1.1     skrll     sym->st_shndx = SHN_ABS;
   3066       1.1     skrll 
   3067       1.1     skrll   return true;
   3068   1.1.1.9  christos }
   3069       1.1     skrll 
   3070  1.1.1.12  christos 
   3071  1.1.1.12  christos /* Finish up the dynamic sections.  */
   3072       1.1     skrll 
   3073   1.1.1.9  christos static bool
   3074       1.1     skrll m32r_elf_finish_dynamic_sections (bfd *output_bfd,
   3075       1.1     skrll 				  struct bfd_link_info *info,
   3076       1.1     skrll 				  bfd_byte *buf ATTRIBUTE_UNUSED)
   3077       1.1     skrll {
   3078       1.1     skrll   struct elf_link_hash_table *htab;
   3079       1.1     skrll   bfd *dynobj;
   3080       1.1     skrll   asection *sdyn;
   3081       1.1     skrll   asection *sgot;
   3082       1.1     skrll 
   3083   1.1.1.2  christos #ifdef DEBUG_PIC
   3084   1.1.1.9  christos   printf ("m32r_elf_finish_dynamic_sections()\n");
   3085   1.1.1.2  christos #endif
   3086   1.1.1.9  christos 
   3087       1.1     skrll   htab = m32r_elf_hash_table (info);
   3088   1.1.1.9  christos   if (htab == NULL)
   3089   1.1.1.3  christos     return false;
   3090       1.1     skrll 
   3091   1.1.1.9  christos   dynobj = htab->dynobj;
   3092       1.1     skrll 
   3093       1.1     skrll   sgot = htab->sgotplt;
   3094       1.1     skrll   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   3095       1.1     skrll 
   3096       1.1     skrll   if (htab->dynamic_sections_created)
   3097       1.1     skrll     {
   3098       1.1     skrll       asection *splt;
   3099       1.1     skrll       Elf32_External_Dyn *dyncon, *dynconend;
   3100       1.1     skrll 
   3101       1.1     skrll       BFD_ASSERT (sgot != NULL && sdyn != NULL);
   3102   1.1.1.6  christos 
   3103   1.1.1.6  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   3104   1.1.1.6  christos       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   3105       1.1     skrll 
   3106   1.1.1.6  christos       for (; dyncon < dynconend; dyncon++)
   3107       1.1     skrll 	{
   3108   1.1.1.6  christos 	  Elf_Internal_Dyn dyn;
   3109   1.1.1.6  christos 	  asection *s;
   3110   1.1.1.6  christos 
   3111   1.1.1.6  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   3112   1.1.1.6  christos 
   3113   1.1.1.6  christos 	  switch (dyn.d_tag)
   3114   1.1.1.9  christos 	    {
   3115   1.1.1.6  christos 	    default:
   3116   1.1.1.6  christos 	      break;
   3117   1.1.1.9  christos 
   3118   1.1.1.6  christos 	    case DT_PLTGOT:
   3119   1.1.1.6  christos 	      s = htab->sgotplt;
   3120   1.1.1.6  christos 	      goto get_vma;
   3121   1.1.1.6  christos 	    case DT_JMPREL:
   3122   1.1.1.6  christos 	      s = htab->srelplt;
   3123   1.1.1.6  christos 	    get_vma:
   3124   1.1.1.9  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   3125   1.1.1.6  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   3126   1.1.1.6  christos 	      break;
   3127   1.1.1.6  christos 
   3128   1.1.1.6  christos 	    case DT_PLTRELSZ:
   3129   1.1.1.6  christos 	      s = htab->srelplt;
   3130       1.1     skrll 	      dyn.d_un.d_val = s->size;
   3131       1.1     skrll 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   3132   1.1.1.9  christos 	      break;
   3133       1.1     skrll 	    }
   3134   1.1.1.6  christos 	}
   3135   1.1.1.6  christos 
   3136   1.1.1.6  christos       /* Fill in the first entry in the procedure linkage table.  */
   3137   1.1.1.6  christos       splt = htab->splt;
   3138   1.1.1.6  christos       if (splt && splt->size > 0)
   3139   1.1.1.6  christos 	{
   3140   1.1.1.6  christos 	  if (bfd_link_pic (info))
   3141   1.1.1.6  christos 	    {
   3142   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents);
   3143   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4);
   3144   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2, splt->contents + 8);
   3145   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3, splt->contents + 12);
   3146   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4, splt->contents + 16);
   3147   1.1.1.6  christos 	    }
   3148   1.1.1.6  christos 	  else
   3149       1.1     skrll 	    {
   3150       1.1     skrll 	      unsigned long addr;
   3151   1.1.1.6  christos 	      /* addr = .got + 4 */
   3152       1.1     skrll 	      addr = sgot->output_section->vma + sgot->output_offset + 4;
   3153       1.1     skrll 	      bfd_put_32 (output_bfd,
   3154   1.1.1.6  christos 			  PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
   3155   1.1.1.6  christos 			  splt->contents);
   3156   1.1.1.6  christos 	      bfd_put_32 (output_bfd,
   3157   1.1.1.6  christos 			  PLT0_ENTRY_WORD1 | (addr & 0xffff),
   3158   1.1.1.6  christos 			  splt->contents + 4);
   3159   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
   3160   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
   3161   1.1.1.6  christos 	      bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
   3162       1.1     skrll 	    }
   3163       1.1     skrll 
   3164       1.1     skrll 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize =
   3165       1.1     skrll 	    PLT_ENTRY_SIZE;
   3166       1.1     skrll 	}
   3167       1.1     skrll     }
   3168   1.1.1.6  christos 
   3169       1.1     skrll   /* Fill in the first three entries in the global offset table.  */
   3170   1.1.1.6  christos   if (sgot && sgot->size > 0)
   3171   1.1.1.6  christos     {
   3172   1.1.1.6  christos       if (sdyn == NULL)
   3173       1.1     skrll 	bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
   3174       1.1     skrll       else
   3175       1.1     skrll 	bfd_put_32 (output_bfd,
   3176       1.1     skrll 		    sdyn->output_section->vma + sdyn->output_offset,
   3177       1.1     skrll 		    sgot->contents);
   3178       1.1     skrll       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
   3179   1.1.1.9  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
   3180       1.1     skrll 
   3181       1.1     skrll       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
   3182       1.1     skrll     }
   3183       1.1     skrll 
   3184       1.1     skrll   return true;
   3185   1.1.1.9  christos }
   3186       1.1     skrll 
   3187       1.1     skrll 
   3188       1.1     skrll /* Set the right machine number.  */
   3190       1.1     skrll 
   3191       1.1     skrll static bool
   3192       1.1     skrll m32r_elf_object_p (bfd *abfd)
   3193       1.1     skrll {
   3194       1.1     skrll   switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
   3195   1.1.1.9  christos     {
   3196       1.1     skrll     default:
   3197       1.1     skrll     case E_M32R_ARCH:   (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r);  break;
   3198       1.1     skrll     case E_M32RX_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;
   3199       1.1     skrll     case E_M32R2_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r2); break;
   3200   1.1.1.9  christos     }
   3201   1.1.1.8  christos   return true;
   3202       1.1     skrll }
   3203       1.1     skrll 
   3204       1.1     skrll /* Store the machine number in the flags field.  */
   3205       1.1     skrll 
   3206       1.1     skrll static bool
   3207       1.1     skrll m32r_elf_final_write_processing (bfd *abfd)
   3208       1.1     skrll {
   3209       1.1     skrll   unsigned long val;
   3210       1.1     skrll 
   3211       1.1     skrll   switch (bfd_get_mach (abfd))
   3212       1.1     skrll     {
   3213       1.1     skrll     default:
   3214       1.1     skrll     case bfd_mach_m32r:  val = E_M32R_ARCH; break;
   3215   1.1.1.8  christos     case bfd_mach_m32rx: val = E_M32RX_ARCH; break;
   3216       1.1     skrll     case bfd_mach_m32r2: val = E_M32R2_ARCH; break;
   3217       1.1     skrll     }
   3218       1.1     skrll 
   3219       1.1     skrll   elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;
   3220   1.1.1.9  christos   elf_elfheader (abfd)->e_flags |= val;
   3221       1.1     skrll   return _bfd_elf_final_write_processing (abfd);
   3222       1.1     skrll }
   3223       1.1     skrll 
   3224       1.1     skrll /* Function to keep M32R specific file flags.  */
   3225       1.1     skrll 
   3226       1.1     skrll static bool
   3227   1.1.1.9  christos m32r_elf_set_private_flags (bfd *abfd, flagword flags)
   3228   1.1.1.9  christos {
   3229       1.1     skrll   BFD_ASSERT (!elf_flags_init (abfd)
   3230       1.1     skrll 	      || elf_elfheader (abfd)->e_flags == flags);
   3231       1.1     skrll 
   3232       1.1     skrll   elf_elfheader (abfd)->e_flags = flags;
   3233       1.1     skrll   elf_flags_init (abfd) = true;
   3234   1.1.1.9  christos   return true;
   3235   1.1.1.6  christos }
   3236       1.1     skrll 
   3237   1.1.1.6  christos /* Merge backend specific data from an object file to the output
   3238       1.1     skrll    object file when linking.  */
   3239       1.1     skrll 
   3240       1.1     skrll static bool
   3241  1.1.1.12  christos m32r_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   3242   1.1.1.9  christos {
   3243       1.1     skrll   bfd *obfd = info->output_bfd;
   3244       1.1     skrll   flagword out_flags;
   3245       1.1     skrll   flagword in_flags;
   3246       1.1     skrll 
   3247       1.1     skrll   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
   3248       1.1     skrll     return true;
   3249       1.1     skrll 
   3250       1.1     skrll   in_flags  = elf_elfheader (ibfd)->e_flags;
   3251       1.1     skrll   out_flags = elf_elfheader (obfd)->e_flags;
   3252       1.1     skrll 
   3253       1.1     skrll   if (! elf_flags_init (obfd))
   3254       1.1     skrll     {
   3255       1.1     skrll       /* If the input is the default architecture then do not
   3256   1.1.1.9  christos 	 bother setting the flags for the output architecture,
   3257       1.1     skrll 	 instead allow future merges to do this.  If no future
   3258   1.1.1.9  christos 	 merges ever set these flags then they will retain their
   3259       1.1     skrll 	 unitialised values, which surprise surprise, correspond
   3260       1.1     skrll 	 to the default values.  */
   3261       1.1     skrll       if (bfd_get_arch_info (ibfd)->the_default)
   3262       1.1     skrll 	return true;
   3263       1.1     skrll 
   3264       1.1     skrll       elf_flags_init (obfd) = true;
   3265       1.1     skrll       elf_elfheader (obfd)->e_flags = in_flags;
   3266   1.1.1.9  christos 
   3267       1.1     skrll       if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
   3268       1.1     skrll 	  && bfd_get_arch_info (obfd)->the_default)
   3269       1.1     skrll 	return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
   3270       1.1     skrll 				  bfd_get_mach (ibfd));
   3271   1.1.1.9  christos 
   3272       1.1     skrll       return true;
   3273       1.1     skrll     }
   3274       1.1     skrll 
   3275       1.1     skrll   /* Check flag compatibility.  */
   3276   1.1.1.6  christos   if (in_flags == out_flags)
   3277   1.1.1.6  christos     return true;
   3278       1.1     skrll 
   3279   1.1.1.6  christos   if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))
   3280   1.1.1.7  christos     {
   3281       1.1     skrll       if (   ((in_flags  & EF_M32R_ARCH) != E_M32R_ARCH)
   3282       1.1     skrll 	  || ((out_flags & EF_M32R_ARCH) == E_M32R_ARCH)
   3283   1.1.1.9  christos 	  || ((in_flags  & EF_M32R_ARCH) == E_M32R2_ARCH))
   3284       1.1     skrll 	{
   3285       1.1     skrll 	  _bfd_error_handler
   3286       1.1     skrll 	    (_("%pB: instruction set mismatch with previous modules"), ibfd);
   3287   1.1.1.9  christos 
   3288       1.1     skrll 	  bfd_set_error (bfd_error_bad_value);
   3289       1.1     skrll 	  return false;
   3290       1.1     skrll 	}
   3291       1.1     skrll     }
   3292   1.1.1.9  christos 
   3293       1.1     skrll   return true;
   3294       1.1     skrll }
   3295       1.1     skrll 
   3296       1.1     skrll /* Display the flags field.  */
   3297       1.1     skrll 
   3298       1.1     skrll static bool
   3299       1.1     skrll m32r_elf_print_private_bfd_data (bfd *abfd, void * ptr)
   3300       1.1     skrll {
   3301       1.1     skrll   FILE * file = (FILE *) ptr;
   3302       1.1     skrll 
   3303       1.1     skrll   BFD_ASSERT (abfd != NULL && ptr != NULL);
   3304       1.1     skrll 
   3305       1.1     skrll   _bfd_elf_print_private_bfd_data (abfd, ptr);
   3306       1.1     skrll 
   3307       1.1     skrll   fprintf (file, _("private flags = %lx"), elf_elfheader (abfd)->e_flags);
   3308       1.1     skrll 
   3309       1.1     skrll   switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
   3310       1.1     skrll     {
   3311       1.1     skrll     default:
   3312       1.1     skrll     case E_M32R_ARCH:  fprintf (file, _(": m32r instructions"));  break;
   3313   1.1.1.9  christos     case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;
   3314       1.1     skrll     case E_M32R2_ARCH: fprintf (file, _(": m32r2 instructions")); break;
   3315       1.1     skrll     }
   3316       1.1     skrll 
   3317       1.1     skrll   fputc ('\n', file);
   3318       1.1     skrll 
   3319  1.1.1.12  christos   return true;
   3320       1.1     skrll }
   3321  1.1.1.12  christos 
   3322       1.1     skrll static asection *
   3323       1.1     skrll m32r_elf_gc_mark_hook (asection *sec,
   3324  1.1.1.12  christos 		       struct bfd_link_info *info,
   3325       1.1     skrll 		       struct elf_reloc_cookie *cookie,
   3326       1.1     skrll 		       struct elf_link_hash_entry *h,
   3327       1.1     skrll 		       unsigned int symndx)
   3328       1.1     skrll {
   3329       1.1     skrll   if (h != NULL)
   3330       1.1     skrll     switch (ELF32_R_TYPE (cookie->rel->r_info))
   3331       1.1     skrll       {
   3332       1.1     skrll       case R_M32R_GNU_VTINHERIT:
   3333  1.1.1.12  christos       case R_M32R_GNU_VTENTRY:
   3334       1.1     skrll       case R_M32R_RELA_GNU_VTINHERIT:
   3335       1.1     skrll       case R_M32R_RELA_GNU_VTENTRY:
   3336       1.1     skrll 	return NULL;
   3337       1.1     skrll       }
   3338       1.1     skrll 
   3339       1.1     skrll   return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx);
   3340   1.1.1.9  christos }
   3341       1.1     skrll 
   3342       1.1     skrll /* Look through the relocs for a section during the first phase.
   3343       1.1     skrll    Since we don't do .gots or .plts, we just need to consider the
   3344       1.1     skrll    virtual table relocs for gc.  */
   3345       1.1     skrll 
   3346       1.1     skrll static bool
   3347       1.1     skrll m32r_elf_check_relocs (bfd *abfd,
   3348       1.1     skrll 		       struct bfd_link_info *info,
   3349       1.1     skrll 		       asection *sec,
   3350   1.1.1.9  christos 		       const Elf_Internal_Rela *relocs)
   3351       1.1     skrll {
   3352   1.1.1.2  christos   Elf_Internal_Shdr *symtab_hdr;
   3353       1.1     skrll   struct elf_link_hash_entry **sym_hashes;
   3354   1.1.1.4  christos   const Elf_Internal_Rela *rel;
   3355   1.1.1.9  christos   const Elf_Internal_Rela *rel_end;
   3356   1.1.1.6  christos   struct elf_link_hash_table *htab;
   3357   1.1.1.2  christos   bfd *dynobj;
   3358       1.1     skrll   asection *sreloc;
   3359       1.1     skrll 
   3360       1.1     skrll   if (bfd_link_relocatable (info))
   3361       1.1     skrll     return true;
   3362   1.1.1.2  christos 
   3363   1.1.1.9  christos   sreloc = NULL;
   3364   1.1.1.2  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   3365   1.1.1.9  christos   sym_hashes = elf_sym_hashes (abfd);
   3366       1.1     skrll 
   3367       1.1     skrll   htab = m32r_elf_hash_table (info);
   3368       1.1     skrll   if (htab == NULL)
   3369       1.1     skrll     return false;
   3370       1.1     skrll 
   3371       1.1     skrll   dynobj = htab->dynobj;
   3372       1.1     skrll 
   3373       1.1     skrll   rel_end = relocs + sec->reloc_count;
   3374       1.1     skrll   for (rel = relocs; rel < rel_end; rel++)
   3375       1.1     skrll     {
   3376       1.1     skrll       int r_type;
   3377   1.1.1.6  christos       struct elf_link_hash_entry *h;
   3378       1.1     skrll       unsigned long r_symndx;
   3379       1.1     skrll 
   3380       1.1     skrll       r_symndx = ELF32_R_SYM (rel->r_info);
   3381       1.1     skrll       r_type = ELF32_R_TYPE (rel->r_info);
   3382       1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   3383       1.1     skrll 	h = NULL;
   3384       1.1     skrll       else
   3385       1.1     skrll 	{
   3386       1.1     skrll 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   3387   1.1.1.9  christos 	  while (h->root.type == bfd_link_hash_indirect
   3388   1.1.1.6  christos 		 || h->root.type == bfd_link_hash_warning)
   3389   1.1.1.6  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   3390   1.1.1.6  christos 	}
   3391   1.1.1.6  christos 
   3392   1.1.1.6  christos       /* Some relocs require a global offset table.  */
   3393   1.1.1.6  christos       if (htab->sgot == NULL)
   3394   1.1.1.6  christos 	{
   3395   1.1.1.6  christos 	  switch (r_type)
   3396   1.1.1.6  christos 	    {
   3397   1.1.1.6  christos 	    case R_M32R_GOT16_HI_ULO:
   3398   1.1.1.6  christos 	    case R_M32R_GOT16_HI_SLO:
   3399   1.1.1.6  christos 	    case R_M32R_GOTOFF:
   3400   1.1.1.6  christos 	    case R_M32R_GOTOFF_HI_ULO:
   3401   1.1.1.6  christos 	    case R_M32R_GOTOFF_HI_SLO:
   3402   1.1.1.6  christos 	    case R_M32R_GOTOFF_LO:
   3403   1.1.1.6  christos 	    case R_M32R_GOT16_LO:
   3404   1.1.1.9  christos 	    case R_M32R_GOTPC24:
   3405   1.1.1.6  christos 	    case R_M32R_GOTPC_HI_ULO:
   3406   1.1.1.9  christos 	    case R_M32R_GOTPC_HI_SLO:
   3407   1.1.1.6  christos 	    case R_M32R_GOTPC_LO:
   3408   1.1.1.6  christos 	    case R_M32R_GOT24:
   3409   1.1.1.6  christos 	      if (dynobj == NULL)
   3410   1.1.1.6  christos 		htab->dynobj = dynobj = abfd;
   3411   1.1.1.6  christos 	      if (!_bfd_elf_create_got_section (dynobj, info))
   3412   1.1.1.6  christos 		return false;
   3413       1.1     skrll 	      break;
   3414       1.1     skrll 
   3415   1.1.1.6  christos 	    default:
   3416       1.1     skrll 	      break;
   3417       1.1     skrll 	  }
   3418       1.1     skrll 	}
   3419   1.1.1.6  christos 
   3420   1.1.1.6  christos       switch (r_type)
   3421   1.1.1.6  christos 	{
   3422   1.1.1.6  christos 	case R_M32R_GOT16_HI_ULO:
   3423   1.1.1.6  christos 	case R_M32R_GOT16_HI_SLO:
   3424   1.1.1.6  christos 	case R_M32R_GOT16_LO:
   3425   1.1.1.6  christos 	case R_M32R_GOT24:
   3426       1.1     skrll 
   3427   1.1.1.6  christos 	  if (h != NULL)
   3428   1.1.1.6  christos 	    h->got.refcount += 1;
   3429   1.1.1.6  christos 	  else
   3430   1.1.1.6  christos 	    {
   3431   1.1.1.6  christos 	      bfd_signed_vma *local_got_refcounts;
   3432   1.1.1.6  christos 
   3433   1.1.1.6  christos 	      /* This is a global offset table entry for a local
   3434   1.1.1.6  christos 		 symbol.  */
   3435   1.1.1.6  christos 	      local_got_refcounts = elf_local_got_refcounts (abfd);
   3436   1.1.1.6  christos 	      if (local_got_refcounts == NULL)
   3437   1.1.1.6  christos 		{
   3438   1.1.1.9  christos 		  bfd_size_type size;
   3439   1.1.1.6  christos 
   3440   1.1.1.6  christos 		  size = symtab_hdr->sh_info;
   3441   1.1.1.6  christos 		  size *= sizeof (bfd_signed_vma);
   3442   1.1.1.6  christos 		  local_got_refcounts = bfd_zalloc (abfd, size);
   3443   1.1.1.6  christos 		  if (local_got_refcounts == NULL)
   3444   1.1.1.6  christos 		    return false;
   3445   1.1.1.6  christos 		  elf_local_got_refcounts (abfd) = local_got_refcounts;
   3446   1.1.1.6  christos 		}
   3447   1.1.1.6  christos 	      local_got_refcounts[r_symndx] += 1;
   3448   1.1.1.6  christos 	    }
   3449   1.1.1.6  christos 	  break;
   3450   1.1.1.6  christos 
   3451       1.1     skrll 	case R_M32R_26_PLTREL:
   3452       1.1     skrll 	  /* This symbol requires a procedure linkage table entry.  We
   3453       1.1     skrll 	     actually build the entry in adjust_dynamic_symbol,
   3454   1.1.1.6  christos 	     because this might be a case of linking PIC code without
   3455   1.1.1.6  christos 	     linking in any dynamic objects, in which case we don't
   3456       1.1     skrll 	     need to generate a procedure linkage table after all.  */
   3457   1.1.1.6  christos 
   3458   1.1.1.6  christos 	  /* If this is a local symbol, we resolve it directly without
   3459       1.1     skrll 	     creating a procedure linkage table entry.  */
   3460   1.1.1.6  christos 	  if (h == NULL)
   3461       1.1     skrll 	    continue;
   3462   1.1.1.6  christos 
   3463       1.1     skrll 	  if (h->forced_local)
   3464   1.1.1.6  christos 	    break;
   3465   1.1.1.6  christos 
   3466   1.1.1.6  christos 	  h->needs_plt = 1;
   3467   1.1.1.6  christos 	  h->plt.refcount += 1;
   3468   1.1.1.6  christos 	  break;
   3469   1.1.1.6  christos 
   3470   1.1.1.6  christos 	case R_M32R_16_RELA:
   3471   1.1.1.6  christos 	case R_M32R_24_RELA:
   3472       1.1     skrll 	case R_M32R_32_RELA:
   3473   1.1.1.6  christos 	case R_M32R_REL32:
   3474   1.1.1.6  christos 	case R_M32R_HI16_ULO_RELA:
   3475   1.1.1.6  christos 	case R_M32R_HI16_SLO_RELA:
   3476   1.1.1.6  christos 	case R_M32R_LO16_RELA:
   3477   1.1.1.6  christos 	case R_M32R_SDA16_RELA:
   3478   1.1.1.6  christos 	case R_M32R_10_PCREL_RELA:
   3479   1.1.1.6  christos 	case R_M32R_18_PCREL_RELA:
   3480   1.1.1.6  christos 	case R_M32R_26_PCREL_RELA:
   3481       1.1     skrll 
   3482   1.1.1.6  christos 	  if (h != NULL && !bfd_link_pic (info))
   3483   1.1.1.6  christos 	    {
   3484   1.1.1.6  christos 	      h->non_got_ref = 1;
   3485   1.1.1.6  christos 	      h->plt.refcount += 1;
   3486   1.1.1.6  christos 	    }
   3487   1.1.1.6  christos 
   3488   1.1.1.6  christos 	  /* If we are creating a shared library, and this is a reloc
   3489   1.1.1.6  christos 	     against a global symbol, or a non PC relative reloc
   3490   1.1.1.6  christos 	     against a local symbol, then we need to copy the reloc
   3491   1.1.1.6  christos 	     into the shared library.  However, if we are linking with
   3492   1.1.1.6  christos 	     -Bsymbolic, we do not need to copy a reloc against a
   3493   1.1.1.6  christos 	     global symbol which is defined in an object we are
   3494   1.1.1.6  christos 	     including in the link (i.e., DEF_REGULAR is set).  At
   3495   1.1.1.6  christos 	     this point we have not seen all the input files, so it is
   3496   1.1.1.6  christos 	     possible that DEF_REGULAR is not set now but will be set
   3497   1.1.1.6  christos 	     later (it is never cleared).  We account for that
   3498   1.1.1.6  christos 	     possibility below by storing information in the
   3499   1.1.1.6  christos 	     dyn_relocs field of the hash table entry. A similar
   3500   1.1.1.6  christos 	     situation occurs when creating shared libraries and symbol
   3501   1.1.1.6  christos 	     visibility changes render the symbol local.
   3502   1.1.1.6  christos 
   3503       1.1     skrll 	     If on the other hand, we are creating an executable, we
   3504   1.1.1.6  christos 	     may need to keep relocations for symbols satisfied by a
   3505   1.1.1.6  christos 	     dynamic library if we manage to avoid copy relocs for the
   3506   1.1.1.6  christos 	     symbol.  */
   3507   1.1.1.6  christos 	  if ((bfd_link_pic (info)
   3508       1.1     skrll 	       && (sec->flags & SEC_ALLOC) != 0
   3509   1.1.1.6  christos 	       && ((   r_type != R_M32R_26_PCREL_RELA
   3510   1.1.1.6  christos 		    && r_type != R_M32R_18_PCREL_RELA
   3511   1.1.1.6  christos 		    && r_type != R_M32R_10_PCREL_RELA
   3512   1.1.1.6  christos 		    && r_type != R_M32R_REL32)
   3513   1.1.1.6  christos 		   || (h != NULL
   3514   1.1.1.6  christos 		       && (! info->symbolic
   3515   1.1.1.6  christos 			   || h->root.type == bfd_link_hash_defweak
   3516   1.1.1.6  christos 			   || !h->def_regular))))
   3517   1.1.1.6  christos 	      || (!bfd_link_pic (info)
   3518   1.1.1.6  christos 		  && (sec->flags & SEC_ALLOC) != 0
   3519   1.1.1.6  christos 		  && h != NULL
   3520   1.1.1.6  christos 		  && (h->root.type == bfd_link_hash_defweak
   3521   1.1.1.9  christos 		      || !h->def_regular)))
   3522   1.1.1.6  christos 	    {
   3523   1.1.1.6  christos 	      struct elf_dyn_relocs *p;
   3524   1.1.1.6  christos 	      struct elf_dyn_relocs **head;
   3525   1.1.1.6  christos 
   3526   1.1.1.6  christos 	      if (dynobj == NULL)
   3527   1.1.1.6  christos 		htab->dynobj = dynobj = abfd;
   3528   1.1.1.2  christos 
   3529   1.1.1.9  christos 	      /* When creating a shared object, we must copy these
   3530       1.1     skrll 		 relocs into the output file.  We create a reloc
   3531   1.1.1.2  christos 		 section in dynobj and make room for the reloc.  */
   3532   1.1.1.9  christos 	      if (sreloc == NULL)
   3533   1.1.1.6  christos 		{
   3534       1.1     skrll 		  sreloc = _bfd_elf_make_dynamic_reloc_section
   3535   1.1.1.6  christos 		    (sec, dynobj, 2, abfd, /*rela?*/ true);
   3536   1.1.1.6  christos 
   3537   1.1.1.6  christos 		  if (sreloc == NULL)
   3538   1.1.1.9  christos 		    return false;
   3539   1.1.1.6  christos 		}
   3540   1.1.1.6  christos 
   3541   1.1.1.6  christos 	      /* If this is a global symbol, we count the number of
   3542   1.1.1.6  christos 		 relocations we need for this symbol.  */
   3543   1.1.1.6  christos 	      if (h != NULL)
   3544   1.1.1.2  christos 		head = &h->dyn_relocs;
   3545       1.1     skrll 	      else
   3546   1.1.1.2  christos 		{
   3547   1.1.1.2  christos 		  /* Track dynamic relocs needed for local syms too.  */
   3548   1.1.1.2  christos 		  asection *s;
   3549   1.1.1.9  christos 		  void *vpp;
   3550   1.1.1.2  christos 		  Elf_Internal_Sym *isym;
   3551   1.1.1.2  christos 
   3552   1.1.1.2  christos 		  isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   3553   1.1.1.2  christos 						abfd, r_symndx);
   3554       1.1     skrll 		  if (isym == NULL)
   3555       1.1     skrll 		    return false;
   3556   1.1.1.6  christos 
   3557   1.1.1.6  christos 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   3558       1.1     skrll 		  if (s == NULL)
   3559   1.1.1.6  christos 		    s = sec;
   3560   1.1.1.6  christos 
   3561   1.1.1.6  christos 		  vpp = &elf_section_data (s)->local_dynrel;
   3562   1.1.1.9  christos 		  head = (struct elf_dyn_relocs **) vpp;
   3563   1.1.1.6  christos 		}
   3564   1.1.1.6  christos 
   3565   1.1.1.6  christos 	      p = *head;
   3566   1.1.1.9  christos 	      if (p == NULL || p->sec != sec)
   3567   1.1.1.6  christos 		{
   3568   1.1.1.6  christos 		  size_t amt = sizeof (*p);
   3569   1.1.1.6  christos 
   3570   1.1.1.6  christos 		  p = bfd_alloc (dynobj, amt);
   3571   1.1.1.6  christos 		  if (p == NULL)
   3572   1.1.1.6  christos 		    return false;
   3573   1.1.1.6  christos 		  p->next = *head;
   3574   1.1.1.6  christos 		  *head = p;
   3575   1.1.1.6  christos 		  p->sec = sec;
   3576   1.1.1.6  christos 		  p->count = 0;
   3577       1.1     skrll 		  p->pc_count = 0;
   3578       1.1     skrll 		}
   3579   1.1.1.6  christos 
   3580   1.1.1.6  christos 	      p->count += 1;
   3581   1.1.1.6  christos 	      if (   ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
   3582   1.1.1.6  christos 		  || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA
   3583   1.1.1.6  christos 		  || ELF32_R_TYPE (rel->r_info) == R_M32R_10_PCREL_RELA
   3584   1.1.1.6  christos 		  || ELF32_R_TYPE (rel->r_info) == R_M32R_REL32)
   3585   1.1.1.6  christos 		p->pc_count += 1;
   3586   1.1.1.6  christos 	    }
   3587   1.1.1.6  christos 	  break;
   3588   1.1.1.9  christos 
   3589   1.1.1.6  christos 	/* This relocation describes the C++ object vtable hierarchy.
   3590   1.1.1.6  christos 	   Reconstruct it for later use during GC.  */
   3591   1.1.1.6  christos 	case R_M32R_RELA_GNU_VTINHERIT:
   3592   1.1.1.6  christos 	case R_M32R_GNU_VTINHERIT:
   3593   1.1.1.6  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   3594   1.1.1.8  christos 	    return false;
   3595   1.1.1.9  christos 	  break;
   3596   1.1.1.6  christos 
   3597   1.1.1.6  christos 	/* This relocation describes which C++ vtable entries are actually
   3598   1.1.1.8  christos 	   used.  Record for later use during GC.  */
   3599   1.1.1.9  christos 	case R_M32R_GNU_VTENTRY:
   3600   1.1.1.6  christos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
   3601   1.1.1.6  christos 	    return false;
   3602       1.1     skrll 	  break;
   3603       1.1     skrll 	case R_M32R_RELA_GNU_VTENTRY:
   3604   1.1.1.9  christos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   3605       1.1     skrll 	    return false;
   3606       1.1     skrll 	  break;
   3607       1.1     skrll 	}
   3608       1.1     skrll     }
   3609   1.1.1.6  christos 
   3610       1.1     skrll   return true;
   3611   1.1.1.6  christos }
   3612       1.1     skrll 
   3613       1.1     skrll static const struct bfd_elf_special_section m32r_elf_special_sections[] =
   3614   1.1.1.9  christos {
   3615   1.1.1.9  christos   { STRING_COMMA_LEN (".sbss"),	 -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
   3616   1.1.1.9  christos   { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
   3617   1.1.1.9  christos   { NULL,		      0,  0, 0,		   0 }
   3618   1.1.1.9  christos };
   3619   1.1.1.9  christos 
   3620   1.1.1.9  christos static bool
   3621   1.1.1.9  christos m32r_elf_section_flags (const Elf_Internal_Shdr *hdr)
   3622   1.1.1.9  christos {
   3623   1.1.1.9  christos   const char *name = hdr->bfd_section->name;
   3624   1.1.1.9  christos 
   3625   1.1.1.9  christos   if (startswith (name, ".sbss")
   3626       1.1     skrll       || startswith (name, ".sdata"))
   3627   1.1.1.4  christos     hdr->bfd_section->flags |= SEC_SMALL_DATA;
   3628   1.1.1.4  christos 
   3629   1.1.1.4  christos   return true;
   3630       1.1     skrll }
   3631       1.1     skrll 
   3632       1.1     skrll static enum elf_reloc_type_class
   3633       1.1     skrll m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   3634       1.1     skrll 			   const asection *rel_sec ATTRIBUTE_UNUSED,
   3635       1.1     skrll 			   const Elf_Internal_Rela *rela)
   3636   1.1.1.6  christos {
   3637       1.1     skrll   switch ((int) ELF32_R_TYPE (rela->r_info))
   3638       1.1     skrll     {
   3639       1.1     skrll     case R_M32R_RELATIVE:  return reloc_class_relative;
   3640       1.1     skrll     case R_M32R_JMP_SLOT:  return reloc_class_plt;
   3641   1.1.1.2  christos     case R_M32R_COPY:      return reloc_class_copy;
   3642       1.1     skrll     default:		   return reloc_class_normal;
   3643       1.1     skrll     }
   3644       1.1     skrll }
   3645       1.1     skrll 
   3646   1.1.1.6  christos #define ELF_ARCH		bfd_arch_m32r
   3648   1.1.1.6  christos #define ELF_TARGET_ID		M32R_ELF_DATA
   3649   1.1.1.6  christos #define ELF_MACHINE_CODE	EM_M32R
   3650       1.1     skrll #define ELF_MACHINE_ALT1	EM_CYGNUS_M32R
   3651       1.1     skrll #define ELF_MAXPAGESIZE		0x1 /* Explicitly requested by Mitsubishi.  */
   3652       1.1     skrll 
   3653       1.1     skrll #define TARGET_BIG_SYM		m32r_elf32_vec
   3654       1.1     skrll #define TARGET_BIG_NAME		"elf32-m32r"
   3655       1.1     skrll #define TARGET_LITTLE_SYM	m32r_elf32_le_vec
   3656       1.1     skrll #define TARGET_LITTLE_NAME	"elf32-m32rle"
   3657   1.1.1.6  christos 
   3658   1.1.1.6  christos #define elf_info_to_howto			m32r_info_to_howto
   3659   1.1.1.6  christos #define elf_info_to_howto_rel			m32r_info_to_howto_rel
   3660   1.1.1.6  christos #define elf_backend_section_from_bfd_section	_bfd_m32r_elf_section_from_bfd_section
   3661   1.1.1.6  christos #define elf_backend_symbol_processing		_bfd_m32r_elf_symbol_processing
   3662  1.1.1.11  christos #define elf_backend_add_symbol_hook		m32r_elf_add_symbol_hook
   3663   1.1.1.7  christos #define elf_backend_relocate_section		m32r_elf_relocate_section
   3664   1.1.1.6  christos #define elf_backend_gc_mark_hook		m32r_elf_gc_mark_hook
   3665   1.1.1.6  christos #define elf_backend_check_relocs		m32r_elf_check_relocs
   3666   1.1.1.6  christos 
   3667   1.1.1.6  christos #define elf_backend_create_dynamic_sections	m32r_elf_create_dynamic_sections
   3668       1.1     skrll #define bfd_elf32_bfd_link_hash_table_create	m32r_elf_link_hash_table_create
   3669   1.1.1.6  christos #define elf_backend_late_size_sections		m32r_elf_late_size_sections
   3670       1.1     skrll #define elf_backend_omit_section_dynsym		_bfd_elf_omit_section_dynsym_all
   3671       1.1     skrll #define elf_backend_finish_dynamic_sections	m32r_elf_finish_dynamic_sections
   3672       1.1     skrll #define elf_backend_adjust_dynamic_symbol	m32r_elf_adjust_dynamic_symbol
   3673       1.1     skrll #define elf_backend_finish_dynamic_symbol	m32r_elf_finish_dynamic_symbol
   3674       1.1     skrll #define elf_backend_reloc_type_class		m32r_elf_reloc_type_class
   3675       1.1     skrll 
   3676       1.1     skrll #define elf_backend_can_gc_sections		1
   3677       1.1     skrll /*#if !USE_REL
   3678   1.1.1.6  christos #define elf_backend_rela_normal			1
   3679       1.1     skrll #endif*/
   3680   1.1.1.6  christos #define elf_backend_can_refcount 1
   3681       1.1     skrll #define elf_backend_want_got_plt 1
   3682   1.1.1.6  christos #define elf_backend_plt_readonly 1
   3683   1.1.1.6  christos #define elf_backend_want_plt_sym 0
   3684       1.1     skrll #define elf_backend_got_header_size 12
   3685   1.1.1.6  christos #define elf_backend_dtrel_excludes_plt	1
   3686   1.1.1.6  christos 
   3687       1.1     skrll #define elf_backend_may_use_rel_p	1
   3688       1.1     skrll #ifdef USE_M32R_OLD_RELOC
   3689       1.1     skrll #define elf_backend_default_use_rela_p	0
   3690   1.1.1.6  christos #define elf_backend_may_use_rela_p	0
   3691   1.1.1.6  christos #else
   3692       1.1     skrll #define elf_backend_default_use_rela_p	1
   3693       1.1     skrll #define elf_backend_may_use_rela_p	1
   3694       1.1     skrll #endif
   3695   1.1.1.9  christos 
   3696       1.1     skrll #define elf_backend_object_p			m32r_elf_object_p
   3697   1.1.1.9  christos #define elf_backend_final_write_processing	m32r_elf_final_write_processing
   3698   1.1.1.6  christos #define bfd_elf32_bfd_merge_private_bfd_data	m32r_elf_merge_private_bfd_data
   3699       1.1     skrll #define bfd_elf32_bfd_set_private_flags		m32r_elf_set_private_flags
   3700       1.1     skrll #define bfd_elf32_bfd_print_private_bfd_data	m32r_elf_print_private_bfd_data
   3701   1.1.1.6  christos #define elf_backend_special_sections		m32r_elf_special_sections
   3702   1.1.1.6  christos #define elf_backend_section_flags		m32r_elf_section_flags
   3703       1.1     skrll 
   3704   1.1.1.6  christos #define elf_backend_linux_prpsinfo32_ugid16	true
   3705   1.1.1.6  christos 
   3706   1.1.1.6  christos #include "elf32-target.h"
   3707   1.1.1.6  christos 
   3708   1.1.1.6  christos #undef	ELF_MAXPAGESIZE
   3709   1.1.1.6  christos #define ELF_MAXPAGESIZE		0x1000
   3710   1.1.1.6  christos 
   3711   1.1.1.6  christos #undef	TARGET_BIG_SYM
   3712   1.1.1.6  christos #define TARGET_BIG_SYM		m32r_elf32_linux_vec
   3713   1.1.1.6  christos #undef	TARGET_BIG_NAME
   3714       1.1     skrll #define TARGET_BIG_NAME		"elf32-m32r-linux"
   3715       1.1     skrll #undef	TARGET_LITTLE_SYM
   3716                     #define TARGET_LITTLE_SYM	m32r_elf32_linux_le_vec
   3717                     #undef	TARGET_LITTLE_NAME
   3718                     #define TARGET_LITTLE_NAME	"elf32-m32rle-linux"
   3719                     #undef	elf32_bed
   3720                     #define elf32_bed		elf32_m32r_lin_bed
   3721                     
   3722                     #include "elf32-target.h"
   3723