/[gcl]/gcl/binutils/bfd/elf32-m32r.c
ViewVC logotype

Diff of /gcl/binutils/bfd/elf32-m32r.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by camm, Fri Aug 9 05:35:15 2002 UTC revision 1.1.1.1.20.1 by camm, Fri Sep 30 02:08:58 2005 UTC
# Line 1  Line 1 
1  /* M32R-specific support for 32-bit ELF.  /* M32R-specific support for 32-bit ELF.
2     Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002     Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3     Free Software Foundation, Inc.     Free Software Foundation, Inc.
4    
5  This file is part of BFD, the Binary File Descriptor library.     This file is part of BFD, the Binary File Descriptor library.
6    
7  This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.     (at your option) any later version.
11    
12  This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.     GNU General Public License for more details.
16    
17  You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20    
21  #include "bfd.h"  #include "bfd.h"
22  #include "sysdep.h"  #include "sysdep.h"
# Line 43  static bfd_reloc_status_type m32r_elf_sd Line 43  static bfd_reloc_status_type m32r_elf_sd
43  static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup  static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
44    PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));    PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
45  static void m32r_info_to_howto_rel  static void m32r_info_to_howto_rel
46    PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));    PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
47  boolean _bfd_m32r_elf_section_from_bfd_section  static void m32r_info_to_howto
48      PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
49    bfd_boolean _bfd_m32r_elf_section_from_bfd_section
50    PARAMS ((bfd *, asection *, int *));    PARAMS ((bfd *, asection *, int *));
51  void _bfd_m32r_elf_symbol_processing  void _bfd_m32r_elf_symbol_processing
52    PARAMS ((bfd *, asymbol *));    PARAMS ((bfd *, asymbol *));
53  static boolean m32r_elf_add_symbol_hook  static bfd_boolean m32r_elf_add_symbol_hook
54    PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,    PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
55             const char **, flagword *, asection **, bfd_vma *));             const char **, flagword *, asection **, bfd_vma *));
56  static boolean m32r_elf_relocate_section  static bfd_boolean m32r_elf_relocate_section
57    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
58             Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));             Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
 #if 0 /* not yet */  
 static boolean m32r_elf_relax_delete_bytes  
   PARAMS ((bfd *, asection *, bfd_vma, int));  
 #endif  
59  static bfd_reloc_status_type m32r_elf_final_sda_base  static bfd_reloc_status_type m32r_elf_final_sda_base
60    PARAMS ((bfd *, struct bfd_link_info *, const char **, bfd_vma *));    PARAMS ((bfd *, struct bfd_link_info *, const char **, bfd_vma *));
61  static boolean m32r_elf_object_p  static bfd_boolean m32r_elf_object_p
62    PARAMS ((bfd *));    PARAMS ((bfd *));
63  static void m32r_elf_final_write_processing  static void m32r_elf_final_write_processing
64    PARAMS ((bfd *, boolean));    PARAMS ((bfd *, bfd_boolean));
65  static boolean m32r_elf_set_private_flags  static bfd_boolean m32r_elf_set_private_flags
66    PARAMS ((bfd *, flagword));    PARAMS ((bfd *, flagword));
67  static boolean m32r_elf_merge_private_bfd_data  static bfd_boolean m32r_elf_merge_private_bfd_data
68    PARAMS ((bfd *, bfd *));    PARAMS ((bfd *, bfd *));
69  static boolean m32r_elf_print_private_bfd_data  static bfd_boolean m32r_elf_print_private_bfd_data
70    PARAMS ((bfd *, PTR));    PARAMS ((bfd *, PTR));
71  static boolean m32r_elf_gc_sweep_hook  static bfd_boolean m32r_elf_gc_sweep_hook
72    PARAMS ((bfd *, struct bfd_link_info *, asection *,    PARAMS ((bfd *, struct bfd_link_info *, asection *,
73             const Elf_Internal_Rela *));             const Elf_Internal_Rela *));
74  static boolean m32r_elf_check_relocs  static bfd_boolean m32r_elf_check_relocs
75    PARAMS ((bfd *, struct bfd_link_info *, asection *,    PARAMS ((bfd *, struct bfd_link_info *, asection *,
76             const Elf_Internal_Rela *));             const Elf_Internal_Rela *));
77    
78    static bfd_boolean m32r_elf_adjust_dynamic_symbol
79      PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
80    static bfd_boolean m32r_elf_size_dynamic_sections
81      PARAMS ((bfd *, struct bfd_link_info *));
82    
83  asection * m32r_elf_gc_mark_hook  asection * m32r_elf_gc_mark_hook
84    PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,    PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
85             struct elf_link_hash_entry *, Elf_Internal_Sym *));             struct elf_link_hash_entry *, Elf_Internal_Sym *));
86    
87    static bfd_boolean m32r_elf_create_dynamic_sections
88      PARAMS ((bfd *, struct bfd_link_info *));
89    
90    static bfd_boolean m32r_elf_finish_dynamic_sections
91      PARAMS ((bfd *, struct bfd_link_info *));
92    
93    static bfd_boolean m32r_elf_finish_dynamic_symbol
94      PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
95               Elf_Internal_Sym *));
96    
97    static bfd_boolean allocate_dynrelocs
98      PARAMS ((struct elf_link_hash_entry *, PTR));
99    static bfd_boolean readonly_dynrelocs
100      PARAMS ((struct elf_link_hash_entry *, PTR));
101    static enum elf_reloc_type_class m32r_elf_reloc_type_class
102      PARAMS ((const Elf_Internal_Rela *));
103    static bfd_boolean m32r_elf_fake_sections
104      PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
105    
106  #define NOP_INSN                0x7000  #define NOP_INSN                0x7000
107  #define MAKE_PARALLEL(insn)     ((insn) | 0x8000)  #define MAKE_PARALLEL(insn)     ((insn) | 0x8000)
108    
# Line 88  asection * m32r_elf_gc_mark_hook Line 110  asection * m32r_elf_gc_mark_hook
110     This only saves space in libraries and object files, but perhaps     This only saves space in libraries and object files, but perhaps
111     relocs will be put in ROM?  All in all though, REL relocs are a pain     relocs will be put in ROM?  All in all though, REL relocs are a pain
112     to work with.  */     to work with.  */
113  #define USE_REL  /* #define USE_REL      1
114    
115    #ifndef USE_REL
116    #define USE_REL 0
117    #endif */
118    /* Use RELA. But use REL to link old objects for backwords compatibility. */
119    
120    /* Functions for the M32R ELF linker.  */
121    
122    /* The name of the dynamic interpreter.  This is put in the .interp
123       section.  */
124    
125    #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
126    
127    /* The nop opcode we use.  */
128    
129    #define M32R_NOP 0x7000f000
130    
131    #define PLT_EMPTY   0x10101010  /* RIE  -> RIE */
132    
133    /* The size in bytes of an entry in the procedure linkage table.  */
134    
135    #define PLT_ENTRY_SIZE 20
136    #define PLT_HEADER_SIZE 20
137    
138    /* The first one entries in a procedure linkage table are reserved,
139       and the initial contents are unimportant (we zero them out).
140       Subsequent entries look like this. */
141    
142    #define PLT0_ENTRY_WORD0  0xd6c00000    /* seth r6, #high(.got+4)          */
143    #define PLT0_ENTRY_WORD1  0x86e60000    /* or3  r6, r6, #low(.got)+4)      */
144    #define PLT0_ENTRY_WORD2  0x24e626c6    /* ld   r4, @r6+    -> ld r6, @r6  */
145    #define PLT0_ENTRY_WORD3  0x1fc6f000    /* jmp  r6          || pnop        */
146    #define PLT0_ENTRY_WORD4  PLT_EMPTY     /* RIE             -> RIE          */
147    
148    #define PLT0_PIC_ENTRY_WORD0  0xa4cc0004 /* ld   r4, @(4,r12)              */
149    #define PLT0_PIC_ENTRY_WORD1  0xa6cc0008 /* ld   r6, @(8,r12)              */
150    #define PLT0_PIC_ENTRY_WORD2  0x1fc6f000 /* jmp  r6         || nop         */
151    #define PLT0_PIC_ENTRY_WORD3  PLT_EMPTY  /* RIE             -> RIE         */
152    #define PLT0_PIC_ENTRY_WORD4  PLT_EMPTY  /* RIE             -> RIE         */
153    
154    #define PLT_ENTRY_WORD0  0xe6000000 /* ld24 r6, .name_in_GOT                */
155    #define PLT_ENTRY_WORD1  0x06acf000 /* add  r6, r12          || nop         */
156    #define PLT_ENTRY_WORD0b 0xd6c00000 /* seth r6, #high(.name_in_GOT)         */
157    #define PLT_ENTRY_WORD1b 0x86e60000 /* or3  r6, r6, #low(.name_in_GOT)      */
158    #define PLT_ENTRY_WORD2  0x26c61fc6 /* ld  r6, @r6           -> jmp r6      */
159    #define PLT_ENTRY_WORD3  0xe5000000 /* ld24 r5, $offset                     */
160    #define PLT_ENTRY_WORD4  0xff000000 /* bra  .plt0.                          */
161    
162    
163  static reloc_howto_type m32r_elf_howto_table[] =  static reloc_howto_type m32r_elf_howto_table[] =
164  {  {
# Line 97  static reloc_howto_type m32r_elf_howto_t Line 167  static reloc_howto_type m32r_elf_howto_t
167           0,                     /* rightshift */           0,                     /* rightshift */
168           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
169           32,                    /* bitsize */           32,                    /* bitsize */
170           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
171           0,                     /* bitpos */           0,                     /* bitpos */
172           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
173           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
174           "R_M32R_NONE",         /* name */           "R_M32R_NONE",         /* name */
175           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
176           0,                     /* src_mask */           0,                     /* src_mask */
177           0,                     /* dst_mask */           0,                     /* dst_mask */
178           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
179    
180    /* A 16 bit absolute relocation.  */    /* A 16 bit absolute relocation.  */
181    HOWTO (R_M32R_16,             /* type */    HOWTO (R_M32R_16,             /* type */
182           0,                     /* rightshift */           0,                     /* rightshift */
183           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
184           16,                    /* bitsize */           16,                    /* bitsize */
185           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
186           0,                     /* bitpos */           0,                     /* bitpos */
187           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
188           m32r_elf_generic_reloc,/* special_function */           m32r_elf_generic_reloc,/* special_function */
189           "R_M32R_16",           /* name */           "R_M32R_16",           /* name */
190           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
191           0xffff,                /* src_mask */           0xffff,                /* src_mask */
192           0xffff,                /* dst_mask */           0xffff,                /* dst_mask */
193           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
194    
195    /* A 32 bit absolute relocation.  */    /* A 32 bit absolute relocation.  */
196    HOWTO (R_M32R_32,             /* type */    HOWTO (R_M32R_32,             /* type */
197           0,                     /* rightshift */           0,                     /* rightshift */
198           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
199           32,                    /* bitsize */           32,                    /* bitsize */
200           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
201           0,                     /* bitpos */           0,                     /* bitpos */
202           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
203           m32r_elf_generic_reloc,/* special_function */           m32r_elf_generic_reloc,/* special_function */
204           "R_M32R_32",           /* name */           "R_M32R_32",           /* name */
205           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
206           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
207           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
208           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
209    
210    /* A 24 bit address.  */    /* A 24 bit address.  */
211    HOWTO (R_M32R_24,             /* type */    HOWTO (R_M32R_24,             /* type */
212           0,                     /* rightshift */           0,                     /* rightshift */
213           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
214           24,                    /* bitsize */           24,                    /* bitsize */
215           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
216           0,                     /* bitpos */           0,                     /* bitpos */
217           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
218           m32r_elf_generic_reloc,/* special_function */           m32r_elf_generic_reloc,/* special_function */
219           "R_M32R_24",           /* name */           "R_M32R_24",           /* name */
220           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
221           0xffffff,              /* src_mask */           0xffffff,              /* src_mask */
222           0xffffff,              /* dst_mask */           0xffffff,              /* dst_mask */
223           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
224    
225    /* An PC Relative 10-bit relocation, shifted by 2.    /* An PC Relative 10-bit relocation, shifted by 2.
226       This reloc is complicated because relocations are relative to pc & -4.       This reloc is complicated because relocations are relative to pc & -4.
# Line 164  static reloc_howto_type m32r_elf_howto_t Line 234  static reloc_howto_type m32r_elf_howto_t
234           2,                     /* rightshift */           2,                     /* rightshift */
235           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
236           10,                    /* bitsize */           10,                    /* bitsize */
237           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
238           0,                     /* bitpos */           0,                     /* bitpos */
239           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
240           m32r_elf_10_pcrel_reloc, /* special_function */           m32r_elf_10_pcrel_reloc, /* special_function */
241           "R_M32R_10_PCREL",     /* name */           "R_M32R_10_PCREL",     /* name */
242           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
243           0xff,                  /* src_mask */           0xff,                  /* src_mask */
244           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
245           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
246    
247    /* A relative 18 bit relocation, right shifted by 2.  */    /* A relative 18 bit relocation, right shifted by 2.  */
248    HOWTO (R_M32R_18_PCREL,       /* type */    HOWTO (R_M32R_18_PCREL,       /* type */
249           2,                     /* rightshift */           2,                     /* rightshift */
250           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
251           16,                    /* bitsize */           16,                    /* bitsize */
252           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
253           0,                     /* bitpos */           0,                     /* bitpos */
254           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
255           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
256           "R_M32R_18_PCREL",     /* name */           "R_M32R_18_PCREL",     /* name */
257           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
258           0xffff,                /* src_mask */           0xffff,                /* src_mask */
259           0xffff,                /* dst_mask */           0xffff,                /* dst_mask */
260           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
261    
262    /* A relative 26 bit relocation, right shifted by 2.  */    /* A relative 26 bit relocation, right shifted by 2.  */
263    /* ??? It's not clear whether this should have partial_inplace set or not.    /* ??? It's not clear whether this should have partial_inplace set or not.
# Line 198  static reloc_howto_type m32r_elf_howto_t Line 268  static reloc_howto_type m32r_elf_howto_t
268           2,                     /* rightshift */           2,                     /* rightshift */
269           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
270           26,                    /* bitsize */           26,                    /* bitsize */
271           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
272           0,                     /* bitpos */           0,                     /* bitpos */
273           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
274           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
275           "R_M32R_26_PCREL",     /* name */           "R_M32R_26_PCREL",     /* name */
276           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
277           0xffffff,              /* src_mask */           0xffffff,              /* src_mask */
278           0xffffff,              /* dst_mask */           0xffffff,              /* dst_mask */
279           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
280    
281    /* High 16 bits of address when lower 16 is or'd in.  */    /* High 16 bits of address when lower 16 is or'd in.  */
282    HOWTO (R_M32R_HI16_ULO,       /* type */    HOWTO (R_M32R_HI16_ULO,       /* type */
283           16,                    /* rightshift */           16,                    /* rightshift */
284           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
285           16,                    /* bitsize */           16,                    /* bitsize */
286           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
287           0,                     /* bitpos */           0,                     /* bitpos */
288           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
289           m32r_elf_hi16_reloc,   /* special_function */           m32r_elf_hi16_reloc,   /* special_function */
290           "R_M32R_HI16_ULO",     /* name */           "R_M32R_HI16_ULO",     /* name */
291           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
292           0x0000ffff,            /* src_mask */           0x0000ffff,            /* src_mask */
293           0x0000ffff,            /* dst_mask */           0x0000ffff,            /* dst_mask */
294           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
295    
296    /* High 16 bits of address when lower 16 is added in.  */    /* High 16 bits of address when lower 16 is added in.  */
297    HOWTO (R_M32R_HI16_SLO,       /* type */    HOWTO (R_M32R_HI16_SLO,       /* type */
298           16,                    /* rightshift */           16,                    /* rightshift */
299           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
300           16,                    /* bitsize */           16,                    /* bitsize */
301           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
302           0,                     /* bitpos */           0,                     /* bitpos */
303           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
304           m32r_elf_hi16_reloc,   /* special_function */           m32r_elf_hi16_reloc,   /* special_function */
305           "R_M32R_HI16_SLO",     /* name */           "R_M32R_HI16_SLO",     /* name */
306           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
307           0x0000ffff,            /* src_mask */           0x0000ffff,            /* src_mask */
308           0x0000ffff,            /* dst_mask */           0x0000ffff,            /* dst_mask */
309           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
310    
311    /* Lower 16 bits of address.  */    /* Lower 16 bits of address.  */
312    HOWTO (R_M32R_LO16,           /* type */    HOWTO (R_M32R_LO16,           /* type */
313           0,                     /* rightshift */           0,                     /* rightshift */
314           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
315           16,                    /* bitsize */           16,                    /* bitsize */
316           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
317           0,                     /* bitpos */           0,                     /* bitpos */
318           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
319           m32r_elf_lo16_reloc,   /* special_function */           m32r_elf_lo16_reloc,   /* special_function */
320           "R_M32R_LO16",         /* name */           "R_M32R_LO16",         /* name */
321           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
322           0x0000ffff,            /* src_mask */           0x0000ffff,            /* src_mask */
323           0x0000ffff,            /* dst_mask */           0x0000ffff,            /* dst_mask */
324           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
325    
326    /* Small data area 16 bits offset.  */    /* Small data area 16 bits offset.  */
327    HOWTO (R_M32R_SDA16,          /* type */    HOWTO (R_M32R_SDA16,          /* type */
328           0,                     /* rightshift */           0,                     /* rightshift */
329           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
330           16,                    /* bitsize */           16,                    /* bitsize */
331           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
332           0,                     /* bitpos */           0,                     /* bitpos */
333           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
334           m32r_elf_sda16_reloc,  /* special_function */           m32r_elf_sda16_reloc,  /* special_function */
335           "R_M32R_SDA16",        /* name */           "R_M32R_SDA16",        /* name */
336           true,                  /* partial_inplace */  /* FIXME: correct? */           TRUE,                  /* partial_inplace */  /* FIXME: correct? */
337           0x0000ffff,            /* src_mask */           0x0000ffff,            /* src_mask */
338           0x0000ffff,            /* dst_mask */           0x0000ffff,            /* dst_mask */
339           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
340    
341    /* GNU extension to record C++ vtable hierarchy */    /* GNU extension to record C++ vtable hierarchy */
342    HOWTO (R_M32R_GNU_VTINHERIT, /* type */    HOWTO (R_M32R_GNU_VTINHERIT, /* type */
343           0,                     /* rightshift */           0,                     /* rightshift */
344           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
345           0,                     /* bitsize */           0,                     /* bitsize */
346           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
347           0,                     /* bitpos */           0,                     /* bitpos */
348           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
349           NULL,                  /* special_function */           NULL,                  /* special_function */
350           "R_M32R_GNU_VTINHERIT", /* name */           "R_M32R_GNU_VTINHERIT", /* name */
351           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
352           0,                     /* src_mask */           0,                     /* src_mask */
353           0,                     /* dst_mask */           0,                     /* dst_mask */
354           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
355    
356    /* GNU extension to record C++ vtable member usage */    /* GNU extension to record C++ vtable member usage */
357    HOWTO (R_M32R_GNU_VTENTRY,     /* type */    HOWTO (R_M32R_GNU_VTENTRY,     /* type */
358           0,                     /* rightshift */           0,                     /* rightshift */
359           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
360           0,                     /* bitsize */           0,                     /* bitsize */
361           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
362           0,                     /* bitpos */           0,                     /* bitpos */
363           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
364           _bfd_elf_rel_vtable_reloc_fn,  /* special_function */           _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
365           "R_M32R_GNU_VTENTRY",   /* name */           "R_M32R_GNU_VTENTRY",   /* name */
366           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
367           0,                     /* src_mask */           0,                     /* src_mask */
368           0,                     /* dst_mask */           0,                     /* dst_mask */
369           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
370    
371      EMPTY_HOWTO (13),
372      EMPTY_HOWTO (14),
373      EMPTY_HOWTO (15),
374      EMPTY_HOWTO (16),
375      EMPTY_HOWTO (17),
376      EMPTY_HOWTO (18),
377      EMPTY_HOWTO (19),
378      EMPTY_HOWTO (20),
379      EMPTY_HOWTO (21),
380      EMPTY_HOWTO (22),
381      EMPTY_HOWTO (23),
382      EMPTY_HOWTO (24),
383      EMPTY_HOWTO (25),
384      EMPTY_HOWTO (26),
385      EMPTY_HOWTO (27),
386      EMPTY_HOWTO (28),
387      EMPTY_HOWTO (29),
388      EMPTY_HOWTO (30),
389      EMPTY_HOWTO (31),
390      EMPTY_HOWTO (32),
391    
392      /* A 16 bit absolute relocation.  */
393      HOWTO (R_M32R_16_RELA,        /* type */
394             0,                     /* rightshift */
395             1,                     /* size (0 = byte, 1 = short, 2 = long) */
396             16,                    /* bitsize */
397             FALSE,                 /* pc_relative */
398             0,                     /* bitpos */
399             complain_overflow_bitfield, /* complain_on_overflow */
400             bfd_elf_generic_reloc, /* special_function */
401             "R_M32R_16_RELA",      /* name */
402             FALSE,                 /* partial_inplace */
403             0xffff,                /* src_mask */
404             0xffff,                /* dst_mask */
405             FALSE),                /* pcrel_offset */
406    
407      /* A 32 bit absolute relocation.  */
408      HOWTO (R_M32R_32_RELA,        /* type */
409             0,                     /* rightshift */
410             2,                     /* size (0 = byte, 1 = short, 2 = long) */
411             32,                    /* bitsize */
412             FALSE,                 /* pc_relative */
413             0,                     /* bitpos */
414             complain_overflow_bitfield, /* complain_on_overflow */
415             bfd_elf_generic_reloc,/* special_function */
416             "R_M32R_32_RELA",              /* name */
417             FALSE,                 /* partial_inplace */
418             0xffffffff,            /* src_mask */
419             0xffffffff,            /* dst_mask */
420             FALSE),                /* pcrel_offset */
421    
422      /* A 24 bit address.  */
423      HOWTO (R_M32R_24_RELA,        /* type */
424             0,                     /* rightshift */
425             2,                     /* size (0 = byte, 1 = short, 2 = long) */
426             24,                    /* bitsize */
427             FALSE,                 /* pc_relative */
428             0,                     /* bitpos */
429             complain_overflow_unsigned, /* complain_on_overflow */
430             bfd_elf_generic_reloc,/* special_function */
431             "R_M32R_24_RELA",      /* name */
432             FALSE,                 /* partial_inplace */
433             0xffffff,              /* src_mask */
434             0xffffff,              /* dst_mask */
435             FALSE),                /* pcrel_offset */
436    
437      HOWTO (R_M32R_10_PCREL_RELA,  /* type */
438             2,                     /* rightshift */
439             1,                     /* size (0 = byte, 1 = short, 2 = long) */
440             10,                    /* bitsize */
441             TRUE,                  /* pc_relative */
442             0,                     /* bitpos */
443             complain_overflow_signed, /* complain_on_overflow */
444             m32r_elf_10_pcrel_reloc, /* special_function */
445             "R_M32R_10_PCREL_RELA",/* name */
446             FALSE,                 /* partial_inplace */
447             0xff,                  /* src_mask */
448             0xff,                  /* dst_mask */
449             TRUE),                 /* pcrel_offset */
450    
451      /* A relative 18 bit relocation, right shifted by 2.  */
452      HOWTO (R_M32R_18_PCREL_RELA,  /* type */
453             2,                     /* rightshift */
454             2,                     /* size (0 = byte, 1 = short, 2 = long) */
455             16,                    /* bitsize */
456             TRUE,                  /* pc_relative */
457             0,                     /* bitpos */
458             complain_overflow_signed, /* complain_on_overflow */
459             bfd_elf_generic_reloc, /* special_function */
460             "R_M32R_18_PCREL_RELA",/* name */
461             FALSE,                 /* partial_inplace */
462             0xffff,                /* src_mask */
463             0xffff,                /* dst_mask */
464             TRUE),                 /* pcrel_offset */
465    
466      /* A relative 26 bit relocation, right shifted by 2.  */
467      HOWTO (R_M32R_26_PCREL_RELA,  /* type */
468             2,                     /* rightshift */
469             2,                     /* size (0 = byte, 1 = short, 2 = long) */
470             26,                    /* bitsize */
471             TRUE,                  /* pc_relative */
472             0,                     /* bitpos */
473             complain_overflow_signed, /* complain_on_overflow */
474             bfd_elf_generic_reloc, /* special_function */
475             "R_M32R_26_PCREL_RELA",/* name */
476             FALSE,                 /* partial_inplace */
477             0xffffff,              /* src_mask */
478             0xffffff,              /* dst_mask */
479             TRUE),                 /* pcrel_offset */
480    
481      /* High 16 bits of address when lower 16 is or'd in.  */
482      HOWTO (R_M32R_HI16_ULO_RELA,  /* type */
483             16,                    /* rightshift */
484             2,                     /* size (0 = byte, 1 = short, 2 = long) */
485             16,                    /* bitsize */
486             FALSE,                 /* pc_relative */
487             0,                     /* bitpos */
488             complain_overflow_dont, /* complain_on_overflow */
489             bfd_elf_generic_reloc, /* special_function */
490             "R_M32R_HI16_ULO_RELA",/* name */
491             FALSE,                 /* partial_inplace */
492             0x0000ffff,            /* src_mask */
493             0x0000ffff,            /* dst_mask */
494             FALSE),                /* pcrel_offset */
495    
496      /* High 16 bits of address when lower 16 is added in.  */
497      HOWTO (R_M32R_HI16_SLO_RELA,  /* type */
498             16,                    /* rightshift */
499             2,                     /* size (0 = byte, 1 = short, 2 = long) */
500             16,                    /* bitsize */
501             FALSE,                 /* pc_relative */
502             0,                     /* bitpos */
503             complain_overflow_dont, /* complain_on_overflow */
504             bfd_elf_generic_reloc, /* special_function */
505             "R_M32R_HI16_SLO_RELA",/* name */
506             FALSE,                 /* partial_inplace */
507             0x0000ffff,            /* src_mask */
508             0x0000ffff,            /* dst_mask */
509             FALSE),                /* pcrel_offset */
510    
511      /* Lower 16 bits of address.  */
512      HOWTO (R_M32R_LO16_RELA,              /* type */
513             0,                     /* rightshift */
514             2,                     /* size (0 = byte, 1 = short, 2 = long) */
515             16,                    /* bitsize */
516             FALSE,                 /* pc_relative */
517             0,                     /* bitpos */
518             complain_overflow_dont, /* complain_on_overflow */
519             bfd_elf_generic_reloc, /* special_function */
520             "R_M32R_LO16_RELA",    /* name */
521             FALSE,                 /* partial_inplace */
522             0x0000ffff,            /* src_mask */
523             0x0000ffff,            /* dst_mask */
524             FALSE),                /* pcrel_offset */
525    
526      /* Small data area 16 bits offset.  */
527      HOWTO (R_M32R_SDA16_RELA,     /* type */
528             0,                     /* rightshift */
529             2,                     /* size (0 = byte, 1 = short, 2 = long) */
530             16,                    /* bitsize */
531             FALSE,                 /* pc_relative */
532             0,                     /* bitpos */
533             complain_overflow_signed, /* complain_on_overflow */
534             bfd_elf_generic_reloc, /* special_function */
535             "R_M32R_SDA16_RELA",   /* name */
536             TRUE,                  /* partial_inplace */  /* FIXME: correct? */
537             0x0000ffff,            /* src_mask */
538             0x0000ffff,            /* dst_mask */
539             FALSE),                /* pcrel_offset */
540    
541      /* GNU extension to record C++ vtable hierarchy */
542      HOWTO (R_M32R_RELA_GNU_VTINHERIT, /* type */
543             0,                     /* rightshift */
544             2,                     /* size (0 = byte, 1 = short, 2 = long) */
545             0,                     /* bitsize */
546             FALSE,                 /* pc_relative */
547             0,                     /* bitpos */
548             complain_overflow_dont, /* complain_on_overflow */
549             NULL,                  /* special_function */
550             "R_M32R_RELA_GNU_VTINHERIT", /* name */
551             FALSE,                 /* partial_inplace */
552             0,                     /* src_mask */
553             0,                     /* dst_mask */
554             FALSE),                /* pcrel_offset */
555    
556      /* GNU extension to record C++ vtable member usage */
557      HOWTO (R_M32R_RELA_GNU_VTENTRY,     /* type */
558             0,                     /* rightshift */
559             2,                     /* size (0 = byte, 1 = short, 2 = long) */
560             0,                     /* bitsize */
561             FALSE,                 /* pc_relative */
562             0,                     /* bitpos */
563             complain_overflow_dont, /* complain_on_overflow */
564             _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
565             "R_M32R_RELA_GNU_VTENTRY",   /* name */
566             FALSE,                 /* partial_inplace */
567             0,                     /* src_mask */
568             0,                     /* dst_mask */
569             FALSE),                /* pcrel_offset */
570    
571      EMPTY_HOWTO (45),
572      EMPTY_HOWTO (46),
573      EMPTY_HOWTO (47),
574    
575      /* Like R_M32R_24, but referring to the GOT table entry for
576         the symbol.  */
577      HOWTO (R_M32R_GOT24,          /* type */
578             0,                     /* rightshift */
579             2,                     /* size (0 = byte, 1 = short, 2 = long) */
580             24,                    /* bitsize */
581             FALSE,                 /* pc_relative */
582             0,                     /* bitpos */
583             complain_overflow_unsigned, /* complain_on_overflow */
584             bfd_elf_generic_reloc, /* special_function */
585             "R_M32R_GOT24",        /* name */
586             FALSE,                 /* partial_inplace */
587             0xffffff,              /* src_mask */
588             0xffffff,              /* dst_mask */
589             FALSE),                /* pcrel_offset */
590    
591      /* Like R_M32R_PCREL, but referring to the procedure linkage table
592         entry for the symbol.  */
593      HOWTO (R_M32R_26_PLTREL,      /* type */
594             2,                     /* rightshift */
595             2,                     /* size (0 = byte, 1 = short, 2 = long) */
596             24,                    /* bitsize */
597             TRUE,                  /* pc_relative */
598             0,                     /* bitpos */
599             complain_overflow_signed, /* complain_on_overflow */
600             bfd_elf_generic_reloc, /* special_function */
601             "R_M32R_26_PLTREL",    /* name */
602             FALSE,                 /* partial_inplace */
603             0xffffff,              /* src_mask */
604             0xffffff,              /* dst_mask */
605             TRUE),                 /* pcrel_offset */
606    
607      /* This is used only by the dynamic linker.  The symbol should exist
608         both in the object being run and in some shared library.  The
609         dynamic linker copies the data addressed by the symbol from the
610         shared library into the object, because the object being
611         run has to have the data at some particular address.  */
612      HOWTO (R_M32R_COPY,           /* type */
613             0,                     /* rightshift */
614             2,                     /* size (0 = byte, 1 = short, 2 = long) */
615             32,                    /* bitsize */
616             FALSE,                 /* pc_relative */
617             0,                     /* bitpos */
618             complain_overflow_bitfield, /* complain_on_overflow */
619             bfd_elf_generic_reloc, /* special_function */
620             "R_M32R_COPY",         /* name */
621             FALSE,                 /* partial_inplace */
622             0xffffffff,            /* src_mask */
623             0xffffffff,            /* dst_mask */
624             FALSE),                /* pcrel_offset */
625    
626      /* Like R_M32R_24, but used when setting global offset table
627         entries.  */
628      HOWTO (R_M32R_GLOB_DAT,       /* type */
629             0,                     /* rightshift */
630             2,                     /* size (0 = byte, 1 = short, 2 = long) */
631             32,                    /* bitsize */
632             FALSE,                 /* pc_relative */
633             0,                     /* bitpos */
634             complain_overflow_bitfield, /* complain_on_overflow */
635             bfd_elf_generic_reloc, /* special_function */
636             "R_M32R_GLOB_DAT",     /* name */
637             FALSE,                 /* partial_inplace */
638             0xffffffff,            /* src_mask */
639             0xffffffff,            /* dst_mask */
640             FALSE),                /* pcrel_offset */
641    
642      /* Marks a procedure linkage table entry for a symbol.  */
643      HOWTO (R_M32R_JMP_SLOT,       /* type */
644             0,                     /* rightshift */
645             2,                     /* size (0 = byte, 1 = short, 2 = long) */
646             32,                    /* bitsize */
647             FALSE,                 /* pc_relative */
648             0,                     /* bitpos */
649             complain_overflow_bitfield, /* complain_on_overflow */
650             bfd_elf_generic_reloc, /* special_function */
651             "R_M32R_JMP_SLOT",     /* name */
652             FALSE,                 /* partial_inplace */
653             0xffffffff,            /* src_mask */
654             0xffffffff,            /* dst_mask */
655             FALSE),                /* pcrel_offset */
656    
657      /* Used only by the dynamic linker.  When the object is run, this
658         longword is set to the load address of the object, plus the
659         addend.  */
660      HOWTO (R_M32R_RELATIVE,       /* type */
661             0,                     /* rightshift */
662             2,                     /* size (0 = byte, 1 = short, 2 = long) */
663             32,                    /* bitsize */
664             FALSE,                 /* pc_relative */
665             0,                     /* bitpos */
666             complain_overflow_bitfield, /* complain_on_overflow */
667             bfd_elf_generic_reloc, /* special_function */
668             "R_M32R_RELATIVE",     /* name */
669             FALSE,                 /* partial_inplace */
670             0xffffffff,            /* src_mask */
671             0xffffffff,            /* dst_mask */
672             FALSE),                /* pcrel_offset */
673    
674      HOWTO (R_M32R_GOTOFF, /* type */
675             0,                     /* rightshift */
676             2,                     /* size (0 = byte, 1 = short, 2 = long) */
677             24,                    /* bitsize */
678             FALSE,                 /* pc_relative */
679             0,                     /* bitpos */
680             complain_overflow_bitfield, /* complain_on_overflow */
681             bfd_elf_generic_reloc, /* special_function */
682             "R_M32R_GOTOFF",       /* name */
683             FALSE,                 /* partial_inplace */
684             0xffffff,              /* src_mask */
685             0xffffff,              /* dst_mask */
686             FALSE),                /* pcrel_offset */
687    
688      /* An PC Relative 24-bit relocation used when setting PIC offset
689         table register. */
690      HOWTO (R_M32R_GOTPC24,                /* type */
691             0,                     /* rightshift */
692             2,                     /* size (0 = byte, 1 = short, 2 = long) */
693             24,                    /* bitsize */
694             TRUE,                  /* pc_relative */
695             0,                     /* bitpos */
696             complain_overflow_unsigned, /* complain_on_overflow */
697             bfd_elf_generic_reloc, /* special_function */
698             "R_M32R_GOTPC24",      /* name */
699             FALSE,                 /* partial_inplace */
700             0xffffff,              /* src_mask */
701             0xffffff,              /* dst_mask */
702             TRUE),                 /* pcrel_offset */
703    
704      /* Like R_M32R_HI16_ULO, but referring to the GOT table entry for
705         the symbol.  */
706      HOWTO (R_M32R_GOT16_HI_ULO,   /* type */
707             16,                    /* rightshift */
708             2,                     /* size (0 = byte, 1 = short, 2 = long) */
709             16,                    /* bitsize */
710             FALSE,                 /* pc_relative */
711             0,                     /* bitpos */
712             complain_overflow_dont, /* complain_on_overflow */
713             bfd_elf_generic_reloc, /* special_function */
714             "R_M32R_GOT16_HI_ULO", /* name */
715             FALSE,                 /* partial_inplace */
716             0x0000ffff,            /* src_mask */
717             0x0000ffff,            /* dst_mask */
718             FALSE),                /* pcrel_offset */
719    
720      /* Like R_M32R_HI16_SLO, but referring to the GOT table entry for
721         the symbol.  */
722      HOWTO (R_M32R_GOT16_HI_SLO,   /* type */
723             16,                    /* rightshift */
724             2,                     /* size (0 = byte, 1 = short, 2 = long) */
725             16,                    /* bitsize */
726             FALSE,                 /* pc_relative */
727             0,                     /* bitpos */
728             complain_overflow_dont, /* complain_on_overflow */
729             bfd_elf_generic_reloc, /* special_function */
730             "R_M32R_GOT16_HI_SLO", /* name */
731             FALSE,                 /* partial_inplace */
732             0x0000ffff,            /* src_mask */
733             0x0000ffff,            /* dst_mask */
734             FALSE),                /* pcrel_offset */
735    
736      /* Like R_M32R_LO16, but referring to the GOT table entry for
737         the symbol.  */
738      HOWTO (R_M32R_GOT16_LO,       /* type */
739             0,                     /* rightshift */
740             2,                     /* size (0 = byte, 1 = short, 2 = long) */
741             16,                    /* bitsize */
742             FALSE,                 /* pc_relative */
743             0,                     /* bitpos */
744             complain_overflow_dont, /* complain_on_overflow */
745             bfd_elf_generic_reloc, /* special_function */
746             "R_M32R_GOT16_LO",     /* name */
747             FALSE,                 /* partial_inplace */
748             0x0000ffff,            /* src_mask */
749             0x0000ffff,            /* dst_mask */
750             FALSE),                /* pcrel_offset */
751    
752      /* An PC Relative relocation used when setting PIC offset table register.
753         Like R_M32R_HI16_ULO, but referring to the GOT table entry for
754         the symbol.  */
755      HOWTO (R_M32R_GOTPC_HI_ULO,   /* type */
756             16,                    /* rightshift */
757             2,                     /* size (0 = byte, 1 = short, 2 = long) */
758             16,                    /* bitsize */
759             FALSE,                 /* pc_relative */
760             0,                     /* bitpos */
761             complain_overflow_dont, /* complain_on_overflow */
762             bfd_elf_generic_reloc, /* special_function */
763             "R_M32R_GOTPC_HI_ULO", /* name */
764             FALSE,                 /* partial_inplace */
765             0x0000ffff,            /* src_mask */
766             0x0000ffff,            /* dst_mask */
767             TRUE),                 /* pcrel_offset */
768    
769      /* An PC Relative relocation used when setting PIC offset table register.
770         Like R_M32R_HI16_SLO, but referring to the GOT table entry for
771         the symbol.  */
772      HOWTO (R_M32R_GOTPC_HI_SLO,   /* type */
773             16,                    /* rightshift */
774             2,                     /* size (0 = byte, 1 = short, 2 = long) */
775             16,                    /* bitsize */
776             FALSE,                 /* pc_relative */
777             0,                     /* bitpos */
778             complain_overflow_dont, /* complain_on_overflow */
779             bfd_elf_generic_reloc, /* special_function */
780             "R_M32R_GOTPC_HI_SLO", /* name */
781             FALSE,                 /* partial_inplace */
782             0x0000ffff,            /* src_mask */
783             0x0000ffff,            /* dst_mask */
784             TRUE),                 /* pcrel_offset */
785    
786      /* An PC Relative relocation used when setting PIC offset table register.
787         Like R_M32R_LO16, but referring to the GOT table entry for
788         the symbol.  */
789      HOWTO (R_M32R_GOTPC_LO,       /* type */
790             0,                     /* rightshift */
791             2,                     /* size (0 = byte, 1 = short, 2 = long) */
792             16,                    /* bitsize */
793             FALSE,                 /* pc_relative */
794             0,                     /* bitpos */
795             complain_overflow_dont, /* complain_on_overflow */
796             bfd_elf_generic_reloc, /* special_function */
797             "R_M32R_GOTPC_LO",     /* name */
798             FALSE,                 /* partial_inplace */
799             0x0000ffff,            /* src_mask */
800             0x0000ffff,            /* dst_mask */
801             TRUE),                 /* pcrel_offset */
802    
803      HOWTO (R_M32R_GOTOFF_HI_ULO,  /* type */
804             16,                    /* rightshift */
805             2,                     /* size (0 = byte, 1 = short, 2 = long) */
806             16,                    /* bitsize */
807             FALSE,                 /* pc_relative */
808             0,                     /* bitpos */
809             complain_overflow_dont, /* complain_on_overflow */
810             bfd_elf_generic_reloc, /* special_function */
811             "R_M32R_GOTOFF_HI_ULO",/* name */
812             FALSE,                 /* partial_inplace */
813             0x0000ffff,            /* src_mask */
814             0x0000ffff,            /* dst_mask */
815             FALSE),                /* pcrel_offset */
816    
817      HOWTO (R_M32R_GOTOFF_HI_SLO,  /* type */
818             16,                    /* rightshift */
819             2,                     /* size (0 = byte, 1 = short, 2 = long) */
820             16,                    /* bitsize */
821             FALSE,                 /* pc_relative */
822             0,                     /* bitpos */
823             complain_overflow_dont, /* complain_on_overflow */
824             bfd_elf_generic_reloc, /* special_function */
825             "R_M32R_GOTOFF_HI_SLO",/* name */
826             FALSE,                 /* partial_inplace */
827             0x0000ffff,            /* src_mask */
828             0x0000ffff,            /* dst_mask */
829             FALSE),                /* pcrel_offset */
830    
831      HOWTO (R_M32R_GOTOFF_LO,      /* type */
832             0,                     /* rightshift */
833             2,                     /* size (0 = byte, 1 = short, 2 = long) */
834             16,                    /* bitsize */
835             FALSE,                 /* pc_relative */
836             0,                     /* bitpos */
837             complain_overflow_dont, /* complain_on_overflow */
838             bfd_elf_generic_reloc, /* special_function */
839             "R_M32R_GOTOFF_LO",    /* name */
840             FALSE,                 /* partial_inplace */
841             0x0000ffff,            /* src_mask */
842             0x0000ffff,            /* dst_mask */
843             FALSE),                /* pcrel_offset */
844  };  };
845    
846  /* Handle the R_M32R_10_PCREL reloc.  */  /* Handle the R_M32R_10_PCREL reloc.  */
# Line 358  m32r_elf_do_10_pcrel_reloc (abfd, howto, Line 901  m32r_elf_do_10_pcrel_reloc (abfd, howto,
901    bfd_reloc_status_type status;    bfd_reloc_status_type status;
902    
903    /* Sanity check the address (offset in section).  */    /* Sanity check the address (offset in section).  */
904    if (offset > input_section->_cooked_size)    if (offset > bfd_get_section_limit (abfd, input_section))
905      return bfd_reloc_outofrange;      return bfd_reloc_outofrange;
906    
907    relocation = symbol_value + addend;    relocation = symbol_value + addend;
# Line 437  m32r_elf_hi16_reloc (abfd, reloc_entry, Line 980  m32r_elf_hi16_reloc (abfd, reloc_entry,
980      }      }
981    
982    /* Sanity check the address (offset in section).  */    /* Sanity check the address (offset in section).  */
983    if (reloc_entry->address > input_section->_cooked_size)    if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
984      return bfd_reloc_outofrange;      return bfd_reloc_outofrange;
985    
986    ret = bfd_reloc_ok;    ret = bfd_reloc_ok;
# Line 567  m32r_elf_lo16_reloc (input_bfd, reloc_en Line 1110  m32r_elf_lo16_reloc (input_bfd, reloc_en
1110    
1111    /* Now do the LO16 reloc in the usual way.    /* Now do the LO16 reloc in the usual way.
1112       ??? It would be nice to call bfd_elf_generic_reloc here,       ??? It would be nice to call bfd_elf_generic_reloc here,
1113       but we have partial_inplace == TRUE.  bfd_elf_generic_reloc will       but we have partial_inplace set.  bfd_elf_generic_reloc will
1114       pass the handling back to bfd_install_relocation which will install       pass the handling back to bfd_install_relocation which will install
1115       a section relative addend which is wrong.  */       a section relative addend which is wrong.  */
1116    return m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,    return m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
# Line 605  m32r_elf_generic_reloc (input_bfd, reloc Line 1148  m32r_elf_generic_reloc (input_bfd, reloc
1148    
1149    /* Now do the reloc in the usual way.    /* Now do the reloc in the usual way.
1150       ??? It would be nice to call bfd_elf_generic_reloc here,       ??? It would be nice to call bfd_elf_generic_reloc here,
1151       but we have partial_inplace == TRUE.  bfd_elf_generic_reloc will       but we have partial_inplace set.  bfd_elf_generic_reloc will
1152       pass the handling back to bfd_install_relocation which will install       pass the handling back to bfd_install_relocation which will install
1153       a section relative addend which is wrong.  */       a section relative addend which is wrong.  */
1154    
1155    /* Sanity check the address (offset in section).  */    /* Sanity check the address (offset in section).  */
1156    if (reloc_entry->address > input_section->_cooked_size)    if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
1157      return bfd_reloc_outofrange;      return bfd_reloc_outofrange;
1158    
1159    ret = bfd_reloc_ok;    ret = bfd_reloc_ok;
# Line 711  struct m32r_reloc_map Line 1254  struct m32r_reloc_map
1254    unsigned char elf_reloc_val;    unsigned char elf_reloc_val;
1255  };  };
1256    
1257  static const struct m32r_reloc_map m32r_reloc_map[] =  #ifdef USE_M32R_OLD_RELOC
1258    static const struct m32r_reloc_map m32r_reloc_map_old[] =
1259  {  {
1260    { BFD_RELOC_NONE, R_M32R_NONE },    { BFD_RELOC_NONE, R_M32R_NONE },
1261    { BFD_RELOC_16, R_M32R_16 },    { BFD_RELOC_16, R_M32R_16 },
# Line 727  static const struct m32r_reloc_map m32r_ Line 1271  static const struct m32r_reloc_map m32r_
1271    { BFD_RELOC_VTABLE_INHERIT, R_M32R_GNU_VTINHERIT },    { BFD_RELOC_VTABLE_INHERIT, R_M32R_GNU_VTINHERIT },
1272    { BFD_RELOC_VTABLE_ENTRY, R_M32R_GNU_VTENTRY },    { BFD_RELOC_VTABLE_ENTRY, R_M32R_GNU_VTENTRY },
1273  };  };
1274    #else
1275    static const struct m32r_reloc_map m32r_reloc_map[] =
1276    {
1277      { BFD_RELOC_NONE, R_M32R_NONE },
1278      { BFD_RELOC_16, R_M32R_16_RELA },
1279      { BFD_RELOC_32, R_M32R_32_RELA },
1280      { BFD_RELOC_M32R_24, R_M32R_24_RELA },
1281      { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL_RELA },
1282      { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL_RELA },
1283      { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL_RELA },
1284      { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO_RELA },
1285      { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO_RELA },
1286      { BFD_RELOC_M32R_LO16, R_M32R_LO16_RELA },
1287      { BFD_RELOC_M32R_SDA16, R_M32R_SDA16_RELA },
1288      { BFD_RELOC_VTABLE_INHERIT, R_M32R_RELA_GNU_VTINHERIT },
1289      { BFD_RELOC_VTABLE_ENTRY, R_M32R_RELA_GNU_VTENTRY },
1290    
1291      { BFD_RELOC_M32R_GOT24, R_M32R_GOT24 },
1292      { BFD_RELOC_M32R_26_PLTREL, R_M32R_26_PLTREL },
1293      { BFD_RELOC_M32R_COPY, R_M32R_COPY },
1294      { BFD_RELOC_M32R_GLOB_DAT, R_M32R_GLOB_DAT },
1295      { BFD_RELOC_M32R_JMP_SLOT, R_M32R_JMP_SLOT },
1296      { BFD_RELOC_M32R_RELATIVE, R_M32R_RELATIVE },
1297      { BFD_RELOC_M32R_GOTOFF, R_M32R_GOTOFF },
1298      { BFD_RELOC_M32R_GOTPC24, R_M32R_GOTPC24 },
1299      { BFD_RELOC_M32R_GOT16_HI_ULO, R_M32R_GOT16_HI_ULO },
1300      { BFD_RELOC_M32R_GOT16_HI_SLO, R_M32R_GOT16_HI_SLO },
1301      { BFD_RELOC_M32R_GOT16_LO, R_M32R_GOT16_LO },
1302      { BFD_RELOC_M32R_GOTPC_HI_ULO, R_M32R_GOTPC_HI_ULO },
1303      { BFD_RELOC_M32R_GOTPC_HI_SLO, R_M32R_GOTPC_HI_SLO },
1304      { BFD_RELOC_M32R_GOTPC_LO, R_M32R_GOTPC_LO },
1305      { BFD_RELOC_M32R_GOTOFF_HI_ULO, R_M32R_GOTOFF_HI_ULO },
1306      { BFD_RELOC_M32R_GOTOFF_HI_SLO, R_M32R_GOTOFF_HI_SLO },
1307      { BFD_RELOC_M32R_GOTOFF_LO, R_M32R_GOTOFF_LO },
1308    };
1309    #endif
1310    
1311  static reloc_howto_type *  static reloc_howto_type *
1312  bfd_elf32_bfd_reloc_type_lookup (abfd, code)  bfd_elf32_bfd_reloc_type_lookup (abfd, code)
# Line 735  bfd_elf32_bfd_reloc_type_lookup (abfd, c Line 1315  bfd_elf32_bfd_reloc_type_lookup (abfd, c
1315  {  {
1316    unsigned int i;    unsigned int i;
1317    
1318    #ifdef USE_M32R_OLD_RELOC
1319      for (i = 0;
1320           i < sizeof (m32r_reloc_map_old) / sizeof (struct m32r_reloc_map);
1321           i++)
1322        {
1323          if (m32r_reloc_map_old[i].bfd_reloc_val == code)
1324            return &m32r_elf_howto_table[m32r_reloc_map_old[i].elf_reloc_val];
1325        }
1326    #else /* ! USE_M32R_OLD_RELOC */
1327    
1328    for (i = 0;    for (i = 0;
1329         i < sizeof (m32r_reloc_map) / sizeof (struct m32r_reloc_map);         i < sizeof (m32r_reloc_map) / sizeof (struct m32r_reloc_map);
1330         i++)         i++)
# Line 742  bfd_elf32_bfd_reloc_type_lookup (abfd, c Line 1332  bfd_elf32_bfd_reloc_type_lookup (abfd, c
1332        if (m32r_reloc_map[i].bfd_reloc_val == code)        if (m32r_reloc_map[i].bfd_reloc_val == code)
1333          return &m32r_elf_howto_table[m32r_reloc_map[i].elf_reloc_val];          return &m32r_elf_howto_table[m32r_reloc_map[i].elf_reloc_val];
1334      }      }
1335    #endif
1336    
1337    return NULL;    return NULL;
1338  }  }
# Line 752  static void Line 1343  static void
1343  m32r_info_to_howto_rel (abfd, cache_ptr, dst)  m32r_info_to_howto_rel (abfd, cache_ptr, dst)
1344       bfd *abfd ATTRIBUTE_UNUSED;       bfd *abfd ATTRIBUTE_UNUSED;
1345       arelent *cache_ptr;       arelent *cache_ptr;
1346       Elf32_Internal_Rel *dst;       Elf_Internal_Rela *dst;
1347  {  {
1348    unsigned int r_type;    unsigned int r_type;
1349    
1350    r_type = ELF32_R_TYPE (dst->r_info);    r_type = ELF32_R_TYPE (dst->r_info);
1351    BFD_ASSERT (r_type < (unsigned int) R_M32R_max);    BFD_ASSERT (ELF32_R_TYPE(dst->r_info) <= (unsigned int) R_M32R_GNU_VTENTRY);
1352    cache_ptr->howto = &m32r_elf_howto_table[r_type];    cache_ptr->howto = &m32r_elf_howto_table[r_type];
1353  }  }
1354    
1355    static void
1356    m32r_info_to_howto (abfd, cache_ptr, dst)
1357         bfd *abfd ATTRIBUTE_UNUSED;
1358         arelent *cache_ptr;
1359         Elf_Internal_Rela *dst;
1360    {
1361      BFD_ASSERT ((ELF32_R_TYPE(dst->r_info) == (unsigned int) R_M32R_NONE)
1362                  || ((ELF32_R_TYPE(dst->r_info) > (unsigned int) R_M32R_GNU_VTENTRY)
1363                      && (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_M32R_max)));
1364      cache_ptr->howto = &m32r_elf_howto_table[ELF32_R_TYPE(dst->r_info)];
1365    }
1366    
1367    
1368  /* Given a BFD section, try to locate the corresponding ELF section  /* Given a BFD section, try to locate the corresponding ELF section
1369     index.  */     index.  */
1370    
1371  boolean  bfd_boolean
1372  _bfd_m32r_elf_section_from_bfd_section (abfd, sec, retval)  _bfd_m32r_elf_section_from_bfd_section (abfd, sec, retval)
1373       bfd *abfd ATTRIBUTE_UNUSED;       bfd *abfd ATTRIBUTE_UNUSED;
1374       asection *sec;       asection *sec;
# Line 773  _bfd_m32r_elf_section_from_bfd_section ( Line 1377  _bfd_m32r_elf_section_from_bfd_section (
1377    if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)    if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
1378      {      {
1379        *retval = SHN_M32R_SCOMMON;        *retval = SHN_M32R_SCOMMON;
1380        return true;        return TRUE;
1381      }      }
1382    return false;    return FALSE;
1383  }  }
1384    
1385  /* M32R ELF uses two common sections.  One is the usual one, and the other  /* M32R ELF uses two common sections.  One is the usual one, and the other
# Line 826  _bfd_m32r_elf_symbol_processing (abfd, a Line 1430  _bfd_m32r_elf_symbol_processing (abfd, a
1430     We also keep watching for whether we need to create the sdata special     We also keep watching for whether we need to create the sdata special
1431     linker sections.  */     linker sections.  */
1432    
1433  static boolean  static bfd_boolean
1434  m32r_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)  m32r_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1435       bfd *abfd;       bfd *abfd;
1436       struct bfd_link_info *info;       struct bfd_link_info *info;
1437       const Elf_Internal_Sym *sym;       Elf_Internal_Sym *sym;
1438       const char **namep;       const char **namep;
1439       flagword *flagsp ATTRIBUTE_UNUSED;       flagword *flagsp ATTRIBUTE_UNUSED;
1440       asection **secp;       asection **secp;
1441       bfd_vma *valp;       bfd_vma *valp;
1442  {  {
1443    if (! info->relocateable    if (! info->relocatable
1444        && (*namep)[0] == '_' && (*namep)[1] == 'S'        && (*namep)[0] == '_' && (*namep)[1] == 'S'
1445        && strcmp (*namep, "_SDA_BASE_") == 0        && strcmp (*namep, "_SDA_BASE_") == 0
1446        && info->hash->creator->flavour == bfd_target_elf_flavour)        && is_elf_hash_table (info->hash))
1447      {      {
1448        /* This is simpler than using _bfd_elf_create_linker_section        /* This is simpler than using _bfd_elf_create_linker_section
1449           (our needs are simpler than ppc's needs).  Also           (our needs are simpler than ppc's needs).  Also
# Line 847  m32r_elf_add_symbol_hook (abfd, info, sy Line 1451  m32r_elf_add_symbol_hook (abfd, info, sy
1451           section already exists a new one is created that follows it which           section already exists a new one is created that follows it which
1452           screws of _SDA_BASE_ address calcs because output_offset != 0.  */           screws of _SDA_BASE_ address calcs because output_offset != 0.  */
1453        struct elf_link_hash_entry *h;        struct elf_link_hash_entry *h;
1454          struct bfd_link_hash_entry *bh;
1455        asection *s = bfd_get_section_by_name (abfd, ".sdata");        asection *s = bfd_get_section_by_name (abfd, ".sdata");
1456    
1457        /* The following code was cobbled from elf32-ppc.c and elflink.c.  */        /* The following code was cobbled from elf32-ppc.c and elflink.c.  */
# Line 858  m32r_elf_add_symbol_hook (abfd, info, sy Line 1463  m32r_elf_add_symbol_hook (abfd, info, sy
1463    
1464            s = bfd_make_section_anyway (abfd, ".sdata");            s = bfd_make_section_anyway (abfd, ".sdata");
1465            if (s == NULL)            if (s == NULL)
1466              return false;              return FALSE;
1467            bfd_set_section_flags (abfd, s, flags);            bfd_set_section_flags (abfd, s, flags);
1468            bfd_set_section_alignment (abfd, s, 2);            bfd_set_section_alignment (abfd, s, 2);
1469          }          }
1470    
1471        h = (struct elf_link_hash_entry *)        bh = bfd_link_hash_lookup (info->hash, "_SDA_BASE_",
1472          bfd_link_hash_lookup (info->hash, "_SDA_BASE_", false, false, false);                                   FALSE, FALSE, FALSE);
1473    
1474        if ((h == NULL || h->root.type == bfd_link_hash_undefined)        if ((bh == NULL || bh->type == bfd_link_hash_undefined)
1475            && !(_bfd_generic_link_add_one_symbol (info,            && !(_bfd_generic_link_add_one_symbol (info,
1476                                                   abfd,                                                   abfd,
1477                                                   "_SDA_BASE_",                                                   "_SDA_BASE_",
# Line 874  m32r_elf_add_symbol_hook (abfd, info, sy Line 1479  m32r_elf_add_symbol_hook (abfd, info, sy
1479                                                   s,                                                   s,
1480                                                   (bfd_vma) 32768,                                                   (bfd_vma) 32768,
1481                                                   (const char *) NULL,                                                   (const char *) NULL,
1482                                                   false,                                                   FALSE,
1483                                                   get_elf_backend_data (abfd)->collect,                                                   get_elf_backend_data (abfd)->collect,
1484                                                   (struct bfd_link_hash_entry **) &h)))                                                   &bh)))
1485          return false;          return FALSE;
1486          h = (struct elf_link_hash_entry *) bh;
1487        h->type = STT_OBJECT;        h->type = STT_OBJECT;
1488      }      }
1489    
# Line 890  m32r_elf_add_symbol_hook (abfd, info, sy Line 1496  m32r_elf_add_symbol_hook (abfd, info, sy
1496        break;        break;
1497      }      }
1498    
1499    return true;    return TRUE;
1500  }  }
1501    
1502  /* We have to figure out the SDA_BASE value, so that we can adjust the  /* We have to figure out the SDA_BASE value, so that we can adjust the
1503     symbol value correctly.  We look up the symbol _SDA_BASE_ in the output     symbol value correctly.  We look up the symbol _SDA_BASE_ in the output
1504     BFD.  If we can't find it, we're stuck.  We cache it in the ELF     BFD.  If we can't find it, we're stuck.  We cache it in the ELF
1505     target data.  We don't need to adjust the symbol value for an     target data.  We don't need to adjust the symbol value for an
1506     external symbol if we are producing relocateable output.  */     external symbol if we are producing relocatable output.  */
1507    
1508  static bfd_reloc_status_type  static bfd_reloc_status_type
1509  m32r_elf_final_sda_base (output_bfd, info, error_message, psb)  m32r_elf_final_sda_base (output_bfd, info, error_message, psb)
# Line 910  m32r_elf_final_sda_base (output_bfd, inf Line 1516  m32r_elf_final_sda_base (output_bfd, inf
1516      {      {
1517        struct bfd_link_hash_entry *h;        struct bfd_link_hash_entry *h;
1518    
1519        h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", false, false, true);        h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", FALSE, FALSE, TRUE);
1520        if (h != (struct bfd_link_hash_entry *) NULL        if (h != (struct bfd_link_hash_entry *) NULL
1521            && h->type == bfd_link_hash_defined)            && h->type == bfd_link_hash_defined)
1522          elf_gp (output_bfd) = (h->u.def.value          elf_gp (output_bfd) = (h->u.def.value
# Line 929  m32r_elf_final_sda_base (output_bfd, inf Line 1535  m32r_elf_final_sda_base (output_bfd, inf
1535    return bfd_reloc_ok;    return bfd_reloc_ok;
1536  }  }
1537    
1538    /* Return size of a PLT entry.  */
1539    #define elf_m32r_sizeof_plt(info) PLT_ENTRY_SIZE
1540    
1541    /* The m32r linker needs to keep track of the number of relocs that it
1542       decides to copy in check_relocs for each symbol.  This is so that
1543       it can discard PC relative relocs if it doesn't need them when
1544       linking with -Bsymbolic.  We store the information in a field
1545       extending the regular ELF linker hash table.  */
1546    
1547    /* This structure keeps track of the number of PC relative relocs we
1548       have copied for a given symbol.  */
1549    
1550    struct elf_m32r_pcrel_relocs_copied
1551    {
1552      /* Next section.  */
1553      struct elf_m32r_pcrel_relocs_copied *next;
1554      /* A section in dynobj.  */
1555      asection *section;
1556      /* Number of relocs copied in this section.  */
1557      bfd_size_type count;
1558    };
1559    
1560    /* The sh linker needs to keep track of the number of relocs that it
1561       decides to copy as dynamic relocs in check_relocs for each symbol.
1562       This is so that it can later discard them if they are found to be
1563       unnecessary.  We store the information in a field extending the
1564       regular ELF linker hash table.  */
1565    
1566    struct elf_m32r_dyn_relocs
1567    {
1568      struct elf_m32r_dyn_relocs *next;
1569    
1570      /* The input section of the reloc.  */
1571      asection *sec;
1572    
1573      /* Total number of relocs copied for the input section.  */
1574      bfd_size_type count;
1575    
1576      /* Number of pc-relative relocs copied for the input section.  */
1577      bfd_size_type pc_count;
1578    };
1579    
1580    
1581    /* m32r ELF linker hash entry.  */
1582    
1583    struct elf_m32r_link_hash_entry
1584    {
1585      struct elf_link_hash_entry root;
1586    
1587      /* Track dynamic relocs copied for this symbol.  */
1588      struct elf_m32r_dyn_relocs *dyn_relocs;
1589    
1590    //  bfd_signed_vma gotplt_refcount;
1591    
1592      /* Number of PC relative relocs copied for this symbol.  */
1593      /* struct elf_m32r_pcrel_relocs_copied *pcrel_relocs_copied;  FIXME */
1594    };
1595    
1596    /* m32r ELF linker hash table.  */
1597    
1598    struct elf_m32r_link_hash_table
1599    {
1600      struct elf_link_hash_table root;
1601    
1602      /* Short-cuts to get to dynamic linker sections.  */
1603      asection *sgot;
1604      asection *sgotplt;
1605      asection *srelgot;
1606      asection *splt;
1607      asection *srelplt;
1608      asection *sdynbss;
1609      asection *srelbss;
1610    
1611      /* Small local sym to section mapping cache.  */
1612      struct sym_sec_cache sym_sec;
1613    };
1614    
1615    /* Traverse an m32r ELF linker hash table.  */
1616    
1617    #define m32r_elf_link_hash_traverse(table, func, info)                  \
1618      (elf_link_hash_traverse                                               \
1619       (&(table)->root,                                                     \
1620        (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func),      \
1621        (info)))
1622    
1623    /* Get the m32r ELF linker hash table from a link_info structure.  */
1624    
1625    
1626    #define m32r_elf_hash_table(p) \
1627      ((struct elf_m32r_link_hash_table *) ((p)->hash))
1628    
1629    /* Create an entry in an m32r ELF linker hash table.  */
1630    static struct bfd_hash_entry *
1631    m32r_elf_link_hash_newfunc (struct bfd_hash_entry *, struct bfd_hash_table *,
1632                                const char * );
1633    
1634    static struct bfd_hash_entry *
1635    m32r_elf_link_hash_newfunc (entry, table, string)
1636         struct bfd_hash_entry *entry;
1637         struct bfd_hash_table *table;
1638         const char *string;
1639    {
1640      struct elf_m32r_link_hash_entry *ret =
1641        (struct elf_m32r_link_hash_entry *) entry;
1642    
1643      /* Allocate the structure if it has not already been allocated by a
1644         subclass.  */
1645      if (ret == (struct elf_m32r_link_hash_entry *) NULL)
1646        ret = ((struct elf_m32r_link_hash_entry *)
1647               bfd_hash_allocate (table,
1648                                  sizeof (struct elf_m32r_link_hash_entry)));
1649      if (ret == (struct elf_m32r_link_hash_entry *) NULL)
1650        return (struct bfd_hash_entry *) ret;
1651    
1652      /* Call the allocation method of the superclass.  */
1653      ret = ((struct elf_m32r_link_hash_entry *)
1654             _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1655                                         table, string));
1656      if (ret != (struct elf_m32r_link_hash_entry *) NULL)
1657        {
1658          struct elf_m32r_link_hash_entry *eh;
1659    
1660          eh = (struct elf_m32r_link_hash_entry *) ret;
1661          eh->dyn_relocs = NULL;
1662    //      eh->gotplt_refcount = 0;
1663          /* eh->pcrel_relocs_copied = NULL; FIXME */
1664        }
1665    
1666      return (struct bfd_hash_entry *) ret;
1667    }
1668    
1669    /* Create an m32r ELF linker hash table.  */
1670    static struct bfd_link_hash_table *m32r_elf_link_hash_table_create (bfd *);
1671    
1672    static struct bfd_link_hash_table *
1673    m32r_elf_link_hash_table_create (abfd)
1674         bfd *abfd;
1675    {
1676      struct elf_m32r_link_hash_table *ret;
1677      bfd_size_type amt = sizeof (struct elf_m32r_link_hash_table);
1678    
1679      ret = (struct elf_m32r_link_hash_table *) bfd_malloc (amt);
1680      if (ret == (struct elf_m32r_link_hash_table *) NULL)
1681        return NULL;
1682    
1683      if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
1684                                           m32r_elf_link_hash_newfunc))
1685        {
1686          free (ret);
1687          return NULL;
1688        }
1689    
1690      ret->sgot = NULL;
1691      ret->sgotplt = NULL;
1692      ret->srelgot = NULL;
1693      ret->splt = NULL;
1694      ret->srelplt = NULL;
1695      ret->sdynbss = NULL;
1696      ret->srelbss = NULL;
1697      ret->sym_sec.abfd = NULL;
1698    
1699      return &ret->root.root;
1700    }
1701    
1702    /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
1703       shortcuts to them in our hash table.  */
1704    static bfd_boolean create_got_section (bfd *, struct bfd_link_info *);
1705    
1706    static bfd_boolean
1707    create_got_section (dynobj, info)
1708         bfd *dynobj;
1709         struct bfd_link_info *info;
1710    {
1711      struct elf_m32r_link_hash_table *htab;
1712    
1713      if (! _bfd_elf_create_got_section (dynobj, info))
1714        return FALSE;
1715    
1716      htab = m32r_elf_hash_table (info);
1717      htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1718      htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1719      if (! htab->sgot || ! htab->sgotplt)
1720        abort ();
1721    
1722      htab->srelgot = bfd_make_section (dynobj, ".rela.got");
1723      if (htab->srelgot == NULL
1724          || ! bfd_set_section_flags (dynobj, htab->srelgot,
1725                                      (SEC_ALLOC
1726                                       | SEC_LOAD
1727                                       | SEC_HAS_CONTENTS
1728                                       | SEC_IN_MEMORY
1729                                       | SEC_LINKER_CREATED
1730                                       | SEC_READONLY))
1731          || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1732        return FALSE;
1733    
1734      return TRUE;
1735    }
1736    
1737    /* Create dynamic sections when linking against a dynamic object.  */
1738    
1739    static bfd_boolean
1740    m32r_elf_create_dynamic_sections (abfd, info)
1741         bfd *abfd;
1742         struct bfd_link_info *info;
1743    {
1744      struct elf_m32r_link_hash_table *htab;
1745      flagword flags, pltflags;
1746      register asection *s;
1747      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1748      int ptralign = 2; /* 32bit */
1749    
1750      htab = m32r_elf_hash_table (info);
1751    
1752      /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
1753         .rel[a].bss sections.  */
1754    
1755      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1756               | SEC_LINKER_CREATED);
1757    
1758      pltflags = flags;
1759      pltflags |= SEC_CODE;
1760      if (bed->plt_not_loaded)
1761        pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
1762      if (bed->plt_readonly)
1763        pltflags |= SEC_READONLY;
1764    
1765      s = bfd_make_section (abfd, ".plt");
1766      htab->splt = s;
1767      if (s == NULL
1768          || ! bfd_set_section_flags (abfd, s, pltflags)
1769          || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
1770        return FALSE;
1771    
1772      if (bed->want_plt_sym)
1773        {
1774          /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1775             .plt section.  */
1776          struct bfd_link_hash_entry *bh = NULL;
1777          struct elf_link_hash_entry *h;
1778          if (! (_bfd_generic_link_add_one_symbol
1779                 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1780                  (bfd_vma) 0, (const char *) NULL, FALSE,
1781                  get_elf_backend_data (abfd)->collect, &bh)))
1782            return FALSE;
1783          h = (struct elf_link_hash_entry *) bh;
1784          h->def_regular = 1;
1785          h->type = STT_OBJECT;
1786    
1787          if (info->shared
1788              && ! bfd_elf_link_record_dynamic_symbol (info, h))
1789            return FALSE;
1790        }
1791    
1792      s = bfd_make_section (abfd,
1793                            bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
1794      htab->srelplt = s;
1795      if (s == NULL
1796          || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
1797          || ! bfd_set_section_alignment (abfd, s, ptralign))
1798        return FALSE;
1799    
1800      if (htab->sgot == NULL
1801          && ! create_got_section (abfd, info))
1802        return FALSE;
1803    
1804      {
1805        const char *secname;
1806        char *relname;
1807        flagword secflags;
1808        asection *sec;
1809    
1810        for (sec = abfd->sections; sec; sec = sec->next)
1811          {
1812            secflags = bfd_get_section_flags (abfd, sec);
1813            if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
1814                || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
1815              continue;
1816            secname = bfd_get_section_name (abfd, sec);
1817            relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
1818            strcpy (relname, ".rela");
1819            strcat (relname, secname);
1820            if (bfd_get_section_by_name (abfd, secname))
1821              continue;
1822            s = bfd_make_section (abfd, relname);
1823            if (s == NULL
1824                || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
1825                || ! bfd_set_section_alignment (abfd, s, ptralign))
1826              return FALSE;
1827          }
1828      }
1829    
1830      if (bed->want_dynbss)
1831        {
1832          /* The .dynbss section is a place to put symbols which are defined
1833             by dynamic objects, are referenced by regular objects, and are
1834             not functions.  We must allocate space for them in the process
1835             image and use a R_*_COPY reloc to tell the dynamic linker to
1836             initialize them at run time.  The linker script puts the .dynbss
1837             section into the .bss section of the final image.  */
1838          s = bfd_make_section (abfd, ".dynbss");
1839          htab->sdynbss = s;
1840          if (s == NULL
1841              || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
1842            return FALSE;
1843          /* The .rel[a].bss section holds copy relocs.  This section is not
1844             normally needed.  We need to create it here, though, so that the
1845             linker will map it to an output section.  We can't just create it
1846             only if we need it, because we will not know whether we need it
1847             until we have seen all the input files, and the first time the
1848             main linker code calls BFD after examining all the input files
1849             (size_dynamic_sections) the input sections have already been
1850             mapped to the output sections.  If the section turns out not to
1851             be needed, we can discard it later.  We will never need this
1852             section when generating a shared object, since they do not use
1853             copy relocs.  */
1854          if (! info->shared)
1855            {
1856              s = bfd_make_section (abfd,
1857                                    (bed->default_use_rela_p
1858                                     ? ".rela.bss" : ".rel.bss"));
1859              htab->srelbss = s;
1860              if (s == NULL
1861                  || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
1862                  || ! bfd_set_section_alignment (abfd, s, ptralign))
1863                return FALSE;
1864            }
1865        }
1866    
1867      return TRUE;
1868    }
1869    
1870    /* Copy the extra info we tack onto an elf_link_hash_entry.  */
1871    static void m32r_elf_copy_indirect_symbol (const struct elf_backend_data *,
1872                                               struct elf_link_hash_entry *,
1873                                               struct elf_link_hash_entry *);
1874    
1875    static void
1876    m32r_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
1877                                   struct elf_link_hash_entry *dir,
1878                                   struct elf_link_hash_entry *ind)
1879    {
1880      struct elf_m32r_link_hash_entry *edir, *eind;
1881    
1882      edir = (struct elf_m32r_link_hash_entry *) dir;
1883      eind = (struct elf_m32r_link_hash_entry *) ind;
1884    
1885      if (eind->dyn_relocs != NULL)
1886        {
1887          if (edir->dyn_relocs != NULL)
1888            {
1889              struct elf_m32r_dyn_relocs **pp;
1890              struct elf_m32r_dyn_relocs *p;
1891    
1892              if (ind->root.type == bfd_link_hash_indirect)
1893                abort ();
1894    
1895              /* Add reloc counts against the weak sym to the strong sym
1896                 list.  Merge any entries against the same section.  */
1897              for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1898                {
1899                  struct elf_m32r_dyn_relocs *q;
1900    
1901                  for (q = edir->dyn_relocs; q != NULL; q = q->next)
1902                    if (q->sec == p->sec)
1903                      {
1904                        q->pc_count += p->pc_count;
1905                        q->count += p->count;
1906                        *pp = p->next;
1907                        break;
1908                      }
1909                  if (q == NULL)
1910                    pp = &p->next;
1911                }
1912              *pp = edir->dyn_relocs;
1913            }
1914    
1915          edir->dyn_relocs = eind->dyn_relocs;
1916          eind->dyn_relocs = NULL;
1917        }
1918    
1919    //  if (ind->root.type == bfd_link_hash_indirect
1920    //      && dir->got.refcount <= 0)
1921    //    {
1922    //      edir->tls_type = eind->tls_type;
1923    //      eind->tls_type = GOT_UNKNOWN;
1924    //    }
1925      _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
1926    }
1927    
1928    
1929    /* Adjust a symbol defined by a dynamic object and referenced by a
1930       regular object.  The current definition is in some section of the
1931       dynamic object, but we're not including those sections.  We have to
1932       change the definition to something the rest of the link can
1933       understand.  */
1934    
1935    static bfd_boolean
1936    m32r_elf_adjust_dynamic_symbol (info, h)
1937         struct bfd_link_info *info;
1938         struct elf_link_hash_entry *h;
1939    {
1940      struct elf_m32r_link_hash_table *htab;
1941      struct elf_m32r_link_hash_entry *eh;
1942      struct elf_m32r_dyn_relocs *p;
1943      bfd *dynobj;
1944      asection *s;
1945      unsigned int power_of_two;
1946    
1947    #ifdef DEBUG_PIC
1948    printf("m32r_elf_adjust_dynamic_symbol()\n");
1949    #endif
1950    
1951      dynobj = elf_hash_table (info)->dynobj;
1952    
1953      /* Make sure we know what is going on here.  */
1954      BFD_ASSERT (dynobj != NULL
1955                  && (h->needs_plt
1956                      || h->u.weakdef != NULL
1957                      || (h->def_dynamic
1958                          && h->ref_regular
1959                          && !h->def_regular)));
1960    
1961    
1962      /* If this is a function, put it in the procedure linkage table.  We
1963         will fill in the contents of the procedure linkage table later,
1964         when we know the address of the .got section.  */
1965      if (h->type == STT_FUNC
1966          || h->needs_plt)
1967        {
1968          if (! info->shared
1969              && !h->def_dynamic
1970              && !h->ref_dynamic
1971              && h->root.type != bfd_link_hash_undefweak
1972              && h->root.type != bfd_link_hash_undefined)
1973            {
1974              /* This case can occur if we saw a PLT reloc in an input
1975                 file, but the symbol was never referred to by a dynamic
1976                 object.  In such a case, we don't actually need to build
1977                 a procedure linkage table, and we can just do a PCREL
1978                 reloc instead.  */
1979              h->plt.offset = (bfd_vma) -1;
1980              h->needs_plt = 0;
1981            }
1982    
1983          return TRUE;
1984        }
1985      else
1986        h->plt.offset = (bfd_vma) -1;
1987    
1988      /* If this is a weak symbol, and there is a real definition, the
1989         processor independent code will have arranged for us to see the
1990         real definition first, and we can just use the same value.  */
1991      if (h->u.weakdef != NULL)
1992        {
1993          BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1994                      || h->u.weakdef->root.type == bfd_link_hash_defweak);
1995          h->root.u.def.section = h->u.weakdef->root.u.def.section;
1996          h->root.u.def.value = h->u.weakdef->root.u.def.value;
1997          return TRUE;
1998        }
1999    
2000      /* This is a reference to a symbol defined by a dynamic object which
2001         is not a function.  */
2002    
2003      /* If we are creating a shared library, we must presume that the
2004         only references to the symbol are via the global offset table.
2005         For such cases we need not do anything here; the relocations will
2006         be handled correctly by relocate_section.  */
2007      if (info->shared)
2008        return TRUE;
2009    
2010      /* If there are no references to this symbol that do not use the
2011         GOT, we don't need to generate a copy reloc.  */
2012      if (!h->non_got_ref)
2013        return TRUE;
2014    
2015      /* If -z nocopyreloc was given, we won't generate them either.  */
2016      if (info->nocopyreloc)
2017        {
2018          h->non_got_ref = 0;
2019          return TRUE;
2020        }
2021    
2022      eh = (struct elf_m32r_link_hash_entry *) h;
2023      for (p = eh->dyn_relocs; p != NULL; p = p->next)
2024        {
2025          s = p->sec->output_section;
2026          if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
2027            break;
2028        }
2029    
2030      /* If we didn't find any dynamic relocs in sections which needs the
2031         copy reloc, then we'll be keeping the dynamic relocs and avoiding
2032         the copy reloc.  */
2033      if (p == NULL)
2034        {
2035          h->non_got_ref = 0;
2036          return TRUE;
2037        }
2038    
2039      /* We must allocate the symbol in our .dynbss section, which will
2040         become part of the .bss section of the executable.  There will be
2041         an entry for this symbol in the .dynsym section.  The dynamic
2042         object will contain position independent code, so all references
2043         from the dynamic object to this symbol will go through the global
2044         offset table.  The dynamic linker will use the .dynsym entry to
2045         determine the address it must put in the global offset table, so
2046         both the dynamic object and the regular object will refer to the
2047         same memory location for the variable.  */
2048    
2049      htab = m32r_elf_hash_table (info);
2050      s = htab->sdynbss;
2051      BFD_ASSERT (s != NULL);
2052    
2053      /* We must generate a R_M32R_COPY reloc to tell the dynamic linker
2054         to copy the initial value out of the dynamic object and into the
2055         runtime process image.  We need to remember the offset into the
2056         .rela.bss section we are going to use.  */
2057      if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2058        {
2059          asection *srel;
2060    
2061          srel = htab->srelbss;
2062          BFD_ASSERT (srel != NULL);
2063          srel->size += sizeof (Elf32_External_Rela);
2064          h->needs_copy = 1;
2065        }
2066    
2067      /* We need to figure out the alignment required for this symbol.  I
2068         have no idea how ELF linkers handle this.  */
2069      power_of_two = bfd_log2 (h->size);
2070      if (power_of_two > 3)
2071        power_of_two = 3;
2072    
2073      /* Apply the required alignment.  */
2074      s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
2075      if (power_of_two > bfd_get_section_alignment (dynobj, s))
2076        {
2077          if (! bfd_set_section_alignment (dynobj, s, power_of_two))
2078            return FALSE;
2079        }
2080    
2081      /* Define the symbol as being at this point in the section.  */
2082      h->root.u.def.section = s;
2083      h->root.u.def.value = s->size;
2084    
2085      /* Increment the section size to make room for the symbol.  */
2086      s->size += h->size;
2087    
2088      return TRUE;
2089    }
2090    
2091    /* Allocate space in .plt, .got and associated reloc sections for
2092       dynamic relocs.  */
2093    
2094    static bfd_boolean
2095    allocate_dynrelocs (h, inf)
2096         struct elf_link_hash_entry *h;
2097         PTR inf;
2098    {
2099      struct bfd_link_info *info;
2100      struct elf_m32r_link_hash_table *htab;
2101      struct elf_m32r_link_hash_entry *eh;
2102      struct elf_m32r_dyn_relocs *p;
2103    
2104      if (h->root.type == bfd_link_hash_indirect)
2105        return TRUE;
2106    
2107      if (h->root.type == bfd_link_hash_warning)
2108        /* When warning symbols are created, they **replace** the "real"
2109           entry in the hash table, thus we never get to see the real
2110           symbol in a hash traversal.  So look at it now.  */
2111        h = (struct elf_link_hash_entry *) h->root.u.i.link;
2112    
2113      info = (struct bfd_link_info *) inf;
2114      htab = m32r_elf_hash_table (info);
2115    
2116      eh = (struct elf_m32r_link_hash_entry *) h;
2117    //  if ((h->got.refcount > 0
2118    //      || h->forced_local)
2119    //      && eh->gotplt_refcount > 0)
2120    //    {
2121    //      /* The symbol has been forced local, or we have some direct got refs,
2122    //         so treat all the gotplt refs as got refs. */
2123    //      h->got.refcount += eh->gotplt_refcount;
2124    //      if (h->plt.refcount >= eh->gotplt_refcount)
2125    //        h->plt.refcount -= eh->gotplt_refcount;
2126    //    }
2127    
2128      if (htab->root.dynamic_sections_created
2129          && h->plt.refcount > 0)
2130        {
2131          /* Make sure this symbol is output as a dynamic symbol.
2132             Undefined weak syms won't yet be marked as dynamic.  */
2133          if (h->dynindx == -1
2134              && !h->forced_local)
2135            {
2136              if (! bfd_elf_link_record_dynamic_symbol (info, h))
2137                return FALSE;
2138            }
2139    
2140          if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
2141            {
2142              asection *s = htab->splt;
2143    
2144              /* If this is the first .plt entry, make room for the special
2145                 first entry.  */
2146              if (s->size == 0)
2147                s->size += PLT_ENTRY_SIZE;
2148    
2149              h->plt.offset = s->size;
2150    
2151              /* If this symbol is not defined in a regular file, and we are
2152                 not generating a shared library, then set the symbol to this
2153                 location in the .plt.  This is required to make function
2154                 pointers compare as equal between the normal executable and
2155                 the shared library.  */
2156              if (! info->shared
2157                  && !h->def_regular)
2158                {
2159                  h->root.u.def.section = s;
2160                  h->root.u.def.value = h->plt.offset;
2161                }
2162    
2163              /* Make room for this entry.  */
2164              s->size += PLT_ENTRY_SIZE;
2165    
2166              /* We also need to make an entry in the .got.plt section, which
2167                 will be placed in the .got section by the linker script.  */
2168              htab->sgotplt->size += 4;
2169    
2170              /* We also need to make an entry in the .rel.plt section.  */
2171              htab->srelplt->size += sizeof (Elf32_External_Rela);
2172            }
2173          else
2174            {
2175              h->plt.offset = (bfd_vma) -1;
2176              h->needs_plt = 0;
2177            }
2178        }
2179      else
2180        {
2181          h->plt.offset = (bfd_vma) -1;
2182          h->needs_plt = 0;
2183        }
2184    
2185      if (h->got.refcount > 0)
2186        {
2187          asection *s;
2188          bfd_boolean dyn;
2189    
2190          /* Make sure this symbol is output as a dynamic symbol.
2191             Undefined weak syms won't yet be marked as dynamic.  */
2192          if (h->dynindx == -1
2193              && !h->forced_local)
2194            {
2195              if (! bfd_elf_link_record_dynamic_symbol (info, h))
2196                return FALSE;
2197            }
2198    
2199          s = htab->sgot;
2200    
2201          h->got.offset = s->size;
2202          s->size += 4;
2203          dyn = htab->root.dynamic_sections_created;
2204          if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
2205            htab->srelgot->size += sizeof (Elf32_External_Rela);
2206        }
2207      else
2208        h->got.offset = (bfd_vma) -1;
2209    
2210      if (eh->dyn_relocs == NULL)
2211        return TRUE;
2212    
2213      /* In the shared -Bsymbolic case, discard space allocated for
2214         dynamic pc-relative relocs against symbols which turn out to be
2215         defined in regular objects.  For the normal shared case, discard
2216         space for pc-relative relocs that have become local due to symbol
2217         visibility changes.  */
2218    
2219      if (info->shared)
2220        {
2221          if (h->def_regular
2222              && (h->forced_local
2223                  || info->symbolic))
2224            {
2225              struct elf_m32r_dyn_relocs **pp;
2226              for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2227                {
2228                  p->count -= p->pc_count;
2229                  p->pc_count = 0;
2230                  if (p->count == 0)
2231                    *pp = p->next;
2232                  else
2233                    pp = &p->next;
2234                }
2235            }
2236        }
2237      else
2238        {
2239          /* For the non-shared case, discard space for relocs against
2240             symbols which turn out to need copy relocs or are not
2241             dynamic.  */
2242    
2243          if (!h->non_got_ref
2244              && ((h->def_dynamic
2245                   && !h->def_regular)
2246                  || (htab->root.dynamic_sections_created
2247                      && (h->root.type == bfd_link_hash_undefweak
2248                          || h->root.type == bfd_link_hash_undefined))))
2249            {
2250              /* Make sure this symbol is output as a dynamic symbol.
2251                 Undefined weak syms won't yet be marked as dynamic.  */
2252              if (h->dynindx == -1
2253                  && !h->forced_local)
2254                {
2255                  if (! bfd_elf_link_record_dynamic_symbol (info, h))
2256                    return FALSE;
2257                }
2258    
2259              /* If that succeeded, we know we'll be keeping all the
2260                 relocs.  */
2261              if (h->dynindx != -1)
2262                goto keep;
2263            }
2264    
2265          eh->dyn_relocs = NULL;
2266    
2267        keep: ;
2268        }
2269    
2270      /* Finally, allocate space.  */
2271      for (p = eh->dyn_relocs; p != NULL; p = p->next)
2272        {
2273          asection *sreloc = elf_section_data (p->sec)->sreloc;
2274          sreloc->size += p->count * sizeof (Elf32_External_Rela);
2275        }
2276    
2277      return TRUE;
2278    }
2279    /* Find any dynamic relocs that apply to read-only sections.  */
2280    
2281    static bfd_boolean
2282    readonly_dynrelocs (h, inf)
2283         struct elf_link_hash_entry *h;
2284         PTR inf;
2285    {
2286      struct elf_m32r_link_hash_entry *eh;
2287      struct elf_m32r_dyn_relocs *p;
2288    
2289      if (h->root.type == bfd_link_hash_warning)
2290        h = (struct elf_link_hash_entry *) h->root.u.i.link;
2291    
2292      eh = (struct elf_m32r_link_hash_entry *) h;
2293      for (p = eh->dyn_relocs; p != NULL; p = p->next)
2294        {
2295          asection *s = p->sec->output_section;
2296    
2297          if (s != NULL && (s->flags & SEC_READONLY) != 0)
2298            {
2299              struct bfd_link_info *info = (struct bfd_link_info *) inf;
2300    
2301              info->flags |= DF_TEXTREL;
2302    
2303              /* Not an error, just cut short the traversal.  */
2304              return FALSE;
2305            }
2306        }
2307      return TRUE;
2308    }
2309    
2310    /* Set the sizes of the dynamic sections.  */
2311    
2312    static bfd_boolean
2313    m32r_elf_size_dynamic_sections (output_bfd, info)
2314         bfd *output_bfd ATTRIBUTE_UNUSED;
2315         struct bfd_link_info *info;
2316    {
2317      struct elf_m32r_link_hash_table *htab;
2318      bfd *dynobj;
2319      asection *s;
2320      bfd_boolean relocs;
2321      bfd *ibfd;
2322    
2323    #ifdef DEBUG_PIC
2324    printf("m32r_elf_size_dynamic_sections()\n");
2325    #endif
2326    
2327      htab = m32r_elf_hash_table (info);
2328      dynobj = htab->root.dynobj;
2329      BFD_ASSERT (dynobj != NULL);
2330    
2331      if (htab->root.dynamic_sections_created)
2332        {
2333          /* Set the contents of the .interp section to the interpreter.  */
2334          if (! info->shared)
2335            {
2336              s = bfd_get_section_by_name (dynobj, ".interp");
2337              BFD_ASSERT (s != NULL);
2338              s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2339              s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2340            }
2341        }
2342    
2343      /* Set up .got offsets for local syms, and space for local dynamic
2344         relocs.  */
2345      for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2346        {
2347          bfd_signed_vma *local_got;
2348          bfd_signed_vma *end_local_got;
2349          bfd_size_type locsymcount;
2350          Elf_Internal_Shdr *symtab_hdr;
2351          asection *srel;
2352    
2353          if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2354            continue;
2355    
2356          for (s = ibfd->sections; s != NULL; s = s->next)
2357            {
2358              struct elf_m32r_dyn_relocs *p;
2359    
2360              for (p = ((struct elf_m32r_dyn_relocs *)
2361                        elf_section_data (s)->local_dynrel);
2362                   p != NULL;
2363                   p = p->next)
2364                {
2365                  if (! bfd_is_abs_section (p->sec)
2366                      && bfd_is_abs_section (p->sec->output_section))
2367                    {
2368                      /* Input section has been discarded, either because
2369                         it is a copy of a linkonce section or due to
2370                         linker script /DISCARD/, so we'll be discarding
2371                         the relocs too.  */
2372                    }
2373                  else if (p->count != 0)
2374                    {
2375                      srel = elf_section_data (p->sec)->sreloc;
2376                      srel->size += p->count * sizeof (Elf32_External_Rela);
2377                      if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2378                        info->flags |= DF_TEXTREL;
2379                    }
2380                }
2381            }
2382    
2383          local_got = elf_local_got_refcounts (ibfd);
2384          if (!local_got)
2385            continue;
2386    
2387          symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2388          locsymcount = symtab_hdr->sh_info;
2389          end_local_got = local_got + locsymcount;
2390          s = htab->sgot;
2391          srel = htab->srelgot;
2392          for (; local_got < end_local_got; ++local_got)
2393            {
2394              if (*local_got > 0)
2395                {
2396                  *local_got = s->size;
2397                  s->size += 4;
2398                  if (info->shared)
2399                    srel->size += sizeof (Elf32_External_Rela);
2400                }
2401              else
2402                *local_got = (bfd_vma) -1;
2403            }
2404        }
2405    
2406      /* Allocate global sym .plt and .got entries, and space for global
2407         sym dynamic relocs.  */
2408      elf_link_hash_traverse (&htab->root, allocate_dynrelocs, (PTR) info);
2409    
2410      /* We now have determined the sizes of the various dynamic sections.
2411         Allocate memory for them.  */
2412      relocs = FALSE;
2413      for (s = dynobj->sections; s != NULL; s = s->next)
2414        {
2415          if ((s->flags & SEC_LINKER_CREATED) == 0)
2416            continue;
2417    
2418          if (s == htab->splt
2419              || s == htab->sgot
2420              || s == htab->sgotplt)
2421            {
2422              /* Strip this section if we don't need it; see the
2423                 comment below.  */
2424            }
2425          else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
2426            {
2427              if (s->size != 0 && s != htab->srelplt)
2428                relocs = TRUE;
2429    
2430              /* We use the reloc_count field as a counter if we need
2431                 to copy relocs into the output file.  */
2432              s->reloc_count = 0;
2433            }
2434          else
2435            {
2436              /* It's not one of our sections, so don't allocate space.  */
2437              continue;
2438            }
2439    
2440          if (s->size == 0)
2441            {
2442              /* If we don't need this section, strip it from the
2443                 output file.  This is mostly to handle .rela.bss and
2444                 .rela.plt.  We must create both sections in
2445                 create_dynamic_sections, because they must be created
2446                 before the linker maps input sections to output
2447                 sections.  The linker does that before
2448                 adjust_dynamic_symbol is called, and it is that
2449                 function which decides whether anything needs to go
2450                 into these sections.  */
2451              _bfd_strip_section_from_output (info, s);
2452              continue;
2453            }
2454    
2455          /* Allocate memory for the section contents.  We use bfd_zalloc
2456             here in case unused entries are not reclaimed before the
2457             section's contents are written out.  This should not happen,
2458             but this way if it does, we get a R_M32R_NONE reloc instead
2459             of garbage.  */
2460          s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2461          if (s->contents == NULL)
2462            return FALSE;
2463        }
2464    
2465      if (htab->root.dynamic_sections_created)
2466        {
2467          /* Add some entries to the .dynamic section.  We fill in the
2468             values later, in m32r_elf_finish_dynamic_sections, but we
2469             must add the entries now so that we get the correct size for
2470             the .dynamic section.  The DT_DEBUG entry is filled in by the
2471             dynamic linker and used by the debugger.  */
2472    #define add_dynamic_entry(TAG, VAL) \
2473      _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2474    
2475          if (! info->shared)
2476            {
2477              if (! add_dynamic_entry (DT_DEBUG, 0))
2478                return FALSE;
2479            }
2480    
2481          if (htab->splt->size != 0)
2482            {
2483              if (! add_dynamic_entry (DT_PLTGOT, 0)
2484                  || ! add_dynamic_entry (DT_PLTRELSZ, 0)
2485                  || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
2486                  || ! add_dynamic_entry (DT_JMPREL, 0))
2487                return FALSE;
2488            }
2489    
2490          if (relocs)
2491            {
2492              if (! add_dynamic_entry (DT_RELA, 0)
2493                  || ! add_dynamic_entry (DT_RELASZ, 0)
2494                  || ! add_dynamic_entry (DT_RELAENT,
2495                                          sizeof (Elf32_External_Rela)))
2496                return FALSE;
2497    
2498              /* If any dynamic relocs apply to a read-only section,
2499                 then we need a DT_TEXTREL entry.  */
2500              if ((info->flags & DF_TEXTREL) == 0)
2501                elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
2502                                        (PTR) info);
2503    
2504              if ((info->flags & DF_TEXTREL) != 0)
2505                {
2506                  if (! add_dynamic_entry (DT_TEXTREL, 0))
2507                    return FALSE;
2508                }
2509            }
2510        }
2511    #undef add_dynamic_entry
2512    
2513      return TRUE;
2514    }
2515  /* Relocate an M32R/D ELF section.  /* Relocate an M32R/D ELF section.
2516     There is some attempt to make this function usable for many architectures,     There is some attempt to make this function usable for many architectures,
2517     both USE_REL and USE_RELA ['twould be nice if such a critter existed],     both for RELA and REL type relocs, if only to serve as a learning tool.
    if only to serve as a learning tool.  
2518    
2519     The RELOCATE_SECTION function is called by the new ELF backend linker     The RELOCATE_SECTION function is called by the new ELF backend linker
2520     to handle the relocations for a section.     to handle the relocations for a section.
# Line 943  m32r_elf_final_sda_base (output_bfd, inf Line 2525  m32r_elf_final_sda_base (output_bfd, inf
2525    
2526     This function is responsible for adjust the section contents as     This function is responsible for adjust the section contents as
2527     necessary, and (if using Rela relocs and generating a     necessary, and (if using Rela relocs and generating a
2528     relocateable output file) adjusting the reloc addend as     relocatable output file) adjusting the reloc addend as
2529     necessary.     necessary.
2530    
2531     This function does not have to worry about setting the reloc     This function does not have to worry about setting the reloc
# Line 957  m32r_elf_final_sda_base (output_bfd, inf Line 2539  m32r_elf_final_sda_base (output_bfd, inf
2539     The global hash table entry for the global symbols can be found     The global hash table entry for the global symbols can be found
2540     via elf_sym_hashes (input_bfd).     via elf_sym_hashes (input_bfd).
2541    
2542     When generating relocateable output, this function must handle     When generating relocatable output, this function must handle
2543     STB_LOCAL/STT_SECTION symbols specially.  The output symbol is     STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
2544     going to be the section symbol corresponding to the output     going to be the section symbol corresponding to the output
2545     section, which means that the addend must be adjusted     section, which means that the addend must be adjusted
2546     accordingly.  */     accordingly.  */
2547    
2548  static boolean  static bfd_boolean
2549  m32r_elf_relocate_section (output_bfd, info, input_bfd, input_section,  m32r_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2550                             contents, relocs, local_syms, local_sections)                             contents, relocs, local_syms, local_sections)
2551       bfd *output_bfd ATTRIBUTE_UNUSED;       bfd *output_bfd ATTRIBUTE_UNUSED;
# Line 979  m32r_elf_relocate_section (output_bfd, i Line 2561  m32r_elf_relocate_section (output_bfd, i
2561    struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);    struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2562    Elf_Internal_Rela *rel, *relend;    Elf_Internal_Rela *rel, *relend;
2563    /* Assume success.  */    /* Assume success.  */
2564    boolean ret = true;    bfd_boolean ret = TRUE;
2565    
2566  #ifndef USE_REL    struct elf_m32r_link_hash_table *htab = m32r_elf_hash_table (info);
2567    if (info->relocateable)    bfd *dynobj;
2568      return true;    bfd_vma *local_got_offsets;
2569  #endif    asection *sgot, *splt, *sreloc;
2570      bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
2571    
2572      dynobj = htab->root.dynobj;
2573      local_got_offsets = elf_local_got_offsets (input_bfd);
2574    
2575      sgot = htab->sgot;
2576      splt = htab->splt;
2577      sreloc = NULL;
2578    
2579    rel = relocs;    rel = relocs;
2580    relend = relocs + input_section->reloc_count;    relend = relocs + input_section->reloc_count;
# Line 993  m32r_elf_relocate_section (output_bfd, i Line 2583  m32r_elf_relocate_section (output_bfd, i
2583        int r_type;        int r_type;
2584        reloc_howto_type *howto;        reloc_howto_type *howto;
2585        unsigned long r_symndx;        unsigned long r_symndx;
2586          struct elf_link_hash_entry *h;
2587        /* We can't modify r_addend here as elf_link_input_bfd has an assert to        /* We can't modify r_addend here as elf_link_input_bfd has an assert to
2588           ensure it's zero (we use REL relocs, not RELA).  Therefore this           ensure it's zero (we use REL relocs, not RELA).  Therefore this
2589           should be assigning zero to `addend', but for clarity we use           should be assigning zero to `addend', but for clarity we use
2590           `r_addend'.  */           `r_addend'.  */
2591        bfd_vma addend = rel->r_addend;        bfd_vma addend = rel->r_addend;
2592        bfd_vma offset = rel->r_offset;        bfd_vma offset = rel->r_offset;
       struct elf_link_hash_entry *h;  
2593        Elf_Internal_Sym *sym;        Elf_Internal_Sym *sym;
2594        asection *sec;        asection *sec;
2595        const char *sym_name;        const char *sym_name;
2596        bfd_reloc_status_type r;        bfd_reloc_status_type r;
2597        const char *errmsg = NULL;        const char *errmsg = NULL;
2598          bfd_boolean use_rel = FALSE;
2599    
2600        h = NULL;        h = NULL;
2601        r_type = ELF32_R_TYPE (rel->r_info);        r_type = ELF32_R_TYPE (rel->r_info);
2602        if (r_type < 0 || r_type >= (int) R_M32R_max)        if (r_type < 0 || r_type >= (int) R_M32R_max)
2603          {          {
2604            (*_bfd_error_handler) (_("%s: unknown relocation type %d"),            (*_bfd_error_handler) (_("%B: unknown relocation type %d"),
2605                                   bfd_archive_filename (input_bfd),                                   input_bfd,
2606                                   (int) r_type);                                   (int) r_type);
2607            bfd_set_error (bfd_error_bad_value);            bfd_set_error (bfd_error_bad_value);
2608            ret = false;            ret = FALSE;
2609            continue;            continue;
2610          }          }
2611    
2612        if (r_type == R_M32R_GNU_VTENTRY        if (r_type == R_M32R_GNU_VTENTRY
2613            || r_type == R_M32R_GNU_VTINHERIT)            || r_type == R_M32R_GNU_VTINHERIT
2614              || r_type == R_M32R_NONE
2615              || r_type == R_M32R_RELA_GNU_VTENTRY
2616              || r_type == R_M32R_RELA_GNU_VTINHERIT)
2617          continue;          continue;
2618    
2619          if (r_type <= R_M32R_GNU_VTENTRY)
2620            use_rel = TRUE;
2621    
2622        howto = m32r_elf_howto_table + r_type;        howto = m32r_elf_howto_table + r_type;
2623        r_symndx = ELF32_R_SYM (rel->r_info);        r_symndx = ELF32_R_SYM (rel->r_info);
2624    
2625  #ifdef USE_REL        if (info->relocatable && use_rel)
       if (info->relocateable)  
2626          {          {
2627            /* This is a relocateable link.  We don't have to change            /* This is a relocatable link.  We don't have to change
2628               anything, unless the reloc is against a section symbol,               anything, unless the reloc is against a section symbol,
2629               in which case we have to adjust according to where the               in which case we have to adjust according to where the
2630               section symbol winds up in the output section.  */               section symbol winds up in the output section.  */
# Line 1087  m32r_elf_relocate_section (output_bfd, i Line 2683  m32r_elf_relocate_section (output_bfd, i
2683              }              }
2684          }          }
2685        else        else
 #endif /* USE_REL */  
2686          {          {
2687            bfd_vma relocation;            bfd_vma relocation;
2688    
2689            /* This is a final link.  */            /* This is a final link.  */
2690            sym = NULL;            sym = NULL;
2691            sec = NULL;            sec = NULL;
2692              h = NULL;
2693    
2694            if (r_symndx < symtab_hdr->sh_info)            if (r_symndx < symtab_hdr->sh_info)
2695              {              {
# Line 1101  m32r_elf_relocate_section (output_bfd, i Line 2697  m32r_elf_relocate_section (output_bfd, i
2697                sym = local_syms + r_symndx;                sym = local_syms + r_symndx;
2698                sec = local_sections[r_symndx];                sec = local_sections[r_symndx];
2699                sym_name = "<local symbol>";                sym_name = "<local symbol>";
2700  #ifndef USE_REL  
2701                relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);                if (!use_rel)
2702                addend = rel->r_addend;                  {
2703  #else                    relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2704                /* FIXME: This won't handle local relocations against SEC_MERGE                    addend = rel->r_addend;
2705                   symbols.  See elf32-i386.c for how to do this.  */  
2706                relocation = (sec->output_section->vma                    if (info->relocatable)
2707                              + sec->output_offset                      {
2708                              + sym->st_value);                        /* This is a relocatable link.  We don't have to change
2709  #endif                           anything, unless the reloc is against a section symbol,
2710                             in which case we have to adjust according to where the
2711                             section symbol winds up in the output section.  */
2712                          if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2713                            rel->r_addend += sec->output_offset + sym->st_value;
2714    
2715                          continue;
2716                        }
2717                    }
2718                  else
2719                    {
2720                      relocation = (sec->output_section->vma
2721                                    + sec->output_offset
2722                                    + sym->st_value);
2723                    }
2724              }              }
2725            else            else
2726              {              {
2727                /* External symbol.  */                /* External symbol.  */
2728                  if (info->relocatable && !use_rel)
2729                    continue;
2730    
2731                h = sym_hashes[r_symndx - symtab_hdr->sh_info];                h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2732                while (h->root.type == bfd_link_hash_indirect                while (h->root.type == bfd_link_hash_indirect
2733                       || h->root.type == bfd_link_hash_warning)                       || h->root.type == bfd_link_hash_warning)
# Line 1124  m32r_elf_relocate_section (output_bfd, i Line 2737  m32r_elf_relocate_section (output_bfd, i
2737                if (h->root.type == bfd_link_hash_defined                if (h->root.type == bfd_link_hash_defined
2738                    || h->root.type == bfd_link_hash_defweak)                    || h->root.type == bfd_link_hash_defweak)
2739                  {                  {
2740                      bfd_boolean dyn;
2741                    sec = h->root.u.def.section;                    sec = h->root.u.def.section;
2742                    if (sec->output_section == NULL)  
2743                      relocation = 0;                    dyn = htab->root.dynamic_sections_created;
2744                      sec = h->root.u.def.section;
2745                      if (r_type == R_M32R_GOTPC24
2746                          || (r_type == R_M32R_GOTPC_HI_ULO
2747                              || r_type == R_M32R_GOTPC_HI_SLO
2748                              || r_type == R_M32R_GOTPC_LO)
2749                          || (r_type == R_M32R_26_PLTREL
2750                              && h->plt.offset != (bfd_vma) -1)
2751                          || ((r_type == R_M32R_GOT24
2752                               || r_type == R_M32R_GOT16_HI_ULO
2753                               || r_type == R_M32R_GOT16_HI_SLO
2754                               || r_type == R_M32R_GOT16_LO)
2755                              && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2756                                                                  info->shared, h)
2757                              && (! info->shared
2758                                  || (! info->symbolic && h->dynindx != -1)
2759                                  || !h->def_regular))
2760                          || (info->shared
2761                              && ((! info->symbolic && h->dynindx != -1)
2762                                  || !h->def_regular)
2763                              && (((r_type == R_M32R_16_RELA
2764                                  || r_type == R_M32R_32_RELA
2765                                  || r_type == R_M32R_24_RELA
2766                                  || r_type == R_M32R_HI16_ULO_RELA
2767                                  || r_type == R_M32R_HI16_SLO_RELA
2768                                  || r_type == R_M32R_LO16_RELA)
2769                                      && !h->forced_local)
2770                                  || r_type == R_M32R_10_PCREL_RELA
2771                                  || r_type == R_M32R_18_PCREL_RELA
2772                                  || r_type == R_M32R_26_PCREL_RELA)
2773                              && ((input_section->flags & SEC_ALLOC) != 0
2774                                  /* DWARF will emit R_M32R_16(24,32) relocations
2775                                     in its sections against symbols defined
2776                                     externally in shared libraries.  We can't do
2777                                     anything with them here.  */
2778                                  || ((input_section->flags & SEC_DEBUGGING) != 0
2779                                      && h->def_dynamic))))
2780                        {
2781                          /* In these cases, we don't need the relocation
2782                             value.  We check specially because in some
2783                             obscure cases sec->output_section will be NULL.  */
2784                          relocation = 0;
2785                        }
2786                      else if (sec->output_section == NULL)
2787                        {
2788                          (*_bfd_error_handler)
2789                            (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
2790                             bfd_get_filename (input_bfd), h->root.root.string,
2791                             bfd_get_section_name (input_bfd, input_section));
2792    
2793                           relocation = 0;
2794                        }
2795                    else                    else
2796                      relocation = (h->root.u.def.value                      relocation = (h->root.u.def.value
2797                                    + sec->output_section->vma                                    + sec->output_section->vma
# Line 1134  m32r_elf_relocate_section (output_bfd, i Line 2799  m32r_elf_relocate_section (output_bfd, i
2799                  }                  }
2800                else if (h->root.type == bfd_link_hash_undefweak)                else if (h->root.type == bfd_link_hash_undefweak)
2801                  relocation = 0;                  relocation = 0;
2802                  else if (info->unresolved_syms_in_objects == RM_IGNORE
2803                           && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
2804                    relocation = 0;
2805                else                else
2806                  {                  {
2807                    if (! ((*info->callbacks->undefined_symbol)                    if (! ((*info->callbacks->undefined_symbol)
2808                           (info, h->root.root.string, input_bfd,                           (info, h->root.root.string, input_bfd,
2809                            input_section, offset, true)))                            input_section, offset,
2810                      return false;                            (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
2811                               || ELF_ST_VISIBILITY (h->other)))))
2812                        return FALSE;
2813                    relocation = 0;                    relocation = 0;
2814                  }                  }
2815              }              }
2816    
2817            /* Sanity check the address.  */            /* Sanity check the address.  */
2818            if (offset > input_section->_raw_size)            if (offset > high_address)
2819              {              {
2820                r = bfd_reloc_outofrange;                r = bfd_reloc_outofrange;
2821                goto check_reloc;                goto check_reloc;
# Line 1153  m32r_elf_relocate_section (output_bfd, i Line 2823  m32r_elf_relocate_section (output_bfd, i
2823    
2824            switch ((int) r_type)            switch ((int) r_type)
2825              {              {
2826                case R_M32R_GOTOFF:
2827                  /* Relocation is relative to the start of the global offset
2828                     table (for ld24 rx, #uimm24). eg access at label+addend
2829    
2830                     ld24 rx. #label@GOTOFF + addend
2831                     sub  rx, r12.  */
2832    
2833                  BFD_ASSERT (sgot != NULL);
2834    
2835                  relocation = -(relocation - sgot->output_section->vma);
2836                  rel->r_addend = -rel->r_addend;
2837                  break;
2838    
2839                case R_M32R_GOTOFF_HI_ULO:
2840                case R_M32R_GOTOFF_HI_SLO:
2841                case R_M32R_GOTOFF_LO:
2842                  BFD_ASSERT (sgot != NULL);
2843    
2844                  relocation -= sgot->output_section->vma;
2845    
2846                  if ((r_type == R_M32R_GOTOFF_HI_SLO)
2847                      && ((relocation + rel->r_addend) & 0x8000))
2848                    rel->r_addend += 0x10000;
2849                  break;
2850    
2851                case R_M32R_GOTPC24:
2852                  /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2853                     ld24 rx,#_GLOBAL_OFFSET_TABLE_
2854                   */
2855                 relocation = sgot->output_section->vma;
2856                 break;
2857    
2858                case R_M32R_GOTPC_HI_ULO:
2859                case R_M32R_GOTPC_HI_SLO:
2860                case R_M32R_GOTPC_LO:
2861                  {
2862                    /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2863                       bl .+4
2864                       seth rx,#high(_GLOBAL_OFFSET_TABLE_)
2865                       or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2866                       or
2867                       bl .+4
2868                       seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
2869                       add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2870                     */
2871                    relocation = sgot->output_section->vma;
2872                    relocation -= (input_section->output_section->vma
2873                                   + input_section->output_offset
2874                                   + rel->r_offset);
2875                    if ((r_type == R_M32R_GOTPC_HI_SLO)
2876                         && ((relocation + rel->r_addend) & 0x8000))
2877                      rel->r_addend += 0x10000;
2878    
2879                    break;
2880                  }
2881                case R_M32R_GOT16_HI_ULO:
2882                case R_M32R_GOT16_HI_SLO:
2883                case R_M32R_GOT16_LO:
2884                  /* Fall through.  */
2885                case R_M32R_GOT24:
2886                  /* Relocation is to the entry for this symbol in the global
2887                     offset table.  */
2888                  BFD_ASSERT (sgot != NULL);
2889    
2890                  if (h != NULL)
2891                    {
2892                      bfd_boolean dyn;
2893                      bfd_vma off;
2894    
2895                      off = h->got.offset;
2896                      BFD_ASSERT (off != (bfd_vma) -1);
2897    
2898                      dyn = htab->root.dynamic_sections_created;
2899                      if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2900                          || (info->shared
2901                              && (info->symbolic
2902                                  || h->dynindx == -1
2903                                  || h->forced_local)
2904                              && h->def_regular))
2905                        {
2906                          /* This is actually a static link, or it is a
2907                             -Bsymbolic link and the symbol is defined
2908                             locally, or the symbol was forced to be local
2909                             because of a version file.  We must initialize
2910                             this entry in the global offset table.  Since the
2911                             offset must always be a multiple of 4, we use the
2912                             least significant bit to record whether we have
2913                             initialized it already.
2914    
2915                             When doing a dynamic link, we create a .rela.got
2916                             relocation entry to initialize the value.  This
2917                             is done in the finish_dynamic_symbol routine.  */
2918                          if ((off & 1) != 0)
2919                            off &= ~1;
2920                          else
2921                            {
2922                              bfd_put_32 (output_bfd, relocation,
2923                                          sgot->contents + off);
2924                              h->got.offset |= 1;
2925                            }
2926                        }
2927    
2928                      relocation = sgot->output_offset + off;
2929                    }
2930                  else
2931                    {
2932                      bfd_vma off;
2933                      bfd_byte *loc;
2934    
2935                      BFD_ASSERT (local_got_offsets != NULL
2936                                  && local_got_offsets[r_symndx] != (bfd_vma) -1);
2937    
2938                      off = local_got_offsets[r_symndx];
2939    
2940                      /* The offset must always be a multiple of 4.  We use
2941                         the least significant bit to record whether we have
2942                         already processed this entry.  */
2943                      if ((off & 1) != 0)
2944                        off &= ~1;
2945                      else
2946                        {
2947                          bfd_put_32 (output_bfd, relocation, sgot->contents + off);
2948    
2949                          if (info->shared)
2950                            {
2951                              asection *srelgot;
2952                              Elf_Internal_Rela outrel;
2953    
2954                              /* We need to generate a R_M32R_RELATIVE reloc
2955                                 for the dynamic linker.  */
2956                              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2957                              BFD_ASSERT (srelgot != NULL);
2958    
2959                              outrel.r_offset = (sgot->output_section->vma
2960                                                 + sgot->output_offset
2961                                                 + off);
2962                              outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
2963                              outrel.r_addend = relocation;
2964                              loc = srelgot->contents;
2965                              loc += srelgot->reloc_count * sizeof(Elf32_External_Rela);
2966                              bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
2967                              ++srelgot->reloc_count;
2968                            }
2969    
2970                          local_got_offsets[r_symndx] |= 1;
2971                        }
2972    
2973                      relocation = sgot->output_offset + off;
2974                    }
2975                  if ((r_type == R_M32R_GOT16_HI_SLO)
2976                      && ((relocation + rel->r_addend) & 0x8000))
2977                    rel->r_addend += 0x10000;
2978    
2979                  break;
2980    
2981                case R_M32R_26_PLTREL:
2982                  /* Relocation is to the entry for this symbol in the
2983                     procedure linkage table.  */
2984    
2985                  /* The native assembler will generate a 26_PLTREL reloc
2986                     for a local symbol if you assemble a call from one
2987                     section to another when using -K pic. */
2988                  if (h == NULL)
2989                    break;
2990    
2991                  //if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2992                  //    || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2993                  //  break;
2994                  if (h->forced_local)
2995                    break;
2996    
2997                  if (h->plt.offset == (bfd_vma) -1)
2998                    {
2999                      /* We didn't make a PLT entry for this symbol.  This
3000                         happens when statically linking PIC code, or when
3001                         using -Bsymbolic.  */
3002                      break;
3003                    }
3004    
3005                  relocation = (splt->output_section->vma
3006                                + splt->output_offset
3007                                + h->plt.offset);
3008                  break;
3009    
3010                case R_M32R_HI16_SLO_RELA:
3011                  {
3012                     if ((relocation + rel->r_addend) & 0x8000)
3013                       {
3014                         rel->r_addend += 0x10000;
3015                       }
3016                  }
3017                  /* Fall through.  */
3018                case R_M32R_16_RELA:
3019                case R_M32R_24_RELA:
3020                case R_M32R_32_RELA:
3021                case R_M32R_18_PCREL_RELA:
3022                case R_M32R_26_PCREL_RELA:
3023                case R_M32R_HI16_ULO_RELA:
3024                case R_M32R_LO16_RELA:
3025                  if (info->shared
3026                      && r_symndx != 0
3027                      && (input_section->flags & SEC_ALLOC) != 0
3028                      && ((r_type != R_M32R_18_PCREL_RELA
3029                           && r_type != R_M32R_26_PCREL_RELA)
3030                          || (h != NULL
3031                              && h->dynindx != -1
3032                              && (! info->symbolic
3033                                  || !h->def_regular))))
3034                    {
3035                      Elf_Internal_Rela outrel;
3036                      bfd_boolean skip, relocate;
3037                      bfd_byte *loc;
3038    
3039                      /* When generating a shared object, these relocations
3040                         are copied into the output file to be resolved at run
3041                         time.  */
3042    
3043                      if (sreloc == NULL)
3044                        {
3045                          const char *name;
3046    
3047                          name = (bfd_elf_string_from_elf_section
3048                                  (input_bfd,
3049                                   elf_elfheader (input_bfd)->e_shstrndx,
3050                                   elf_section_data (input_section)->rel_hdr.sh_name));
3051                          if (name == NULL)
3052                            return FALSE;
3053    
3054                          BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3055                                      && strcmp (bfd_get_section_name (input_bfd,
3056                                                                       input_section),
3057                                                 name + 5) == 0);
3058    
3059                          sreloc = bfd_get_section_by_name (dynobj, name);
3060                          BFD_ASSERT (sreloc != NULL);
3061                        }
3062    
3063                      skip = FALSE;
3064                      relocate = FALSE;
3065    
3066                      outrel.r_offset = _bfd_elf_section_offset (output_bfd,
3067                                                                 info,
3068                                                                 input_section,
3069                                                                 rel->r_offset);
3070                      if (outrel.r_offset == (bfd_vma) -1)
3071                        skip = TRUE;
3072                      else if (outrel.r_offset == (bfd_vma) -2)
3073                        skip = TRUE, relocate = TRUE;
3074                      outrel.r_offset += (input_section->output_section->vma
3075                                          + input_section->output_offset);
3076    
3077                      if (skip)
3078                        memset (&outrel, 0, sizeof outrel);
3079                      else if (r_type == R_M32R_18_PCREL_RELA
3080                               || r_type == R_M32R_26_PCREL_RELA)
3081                        {
3082                          BFD_ASSERT (h != NULL && h->dynindx != -1);
3083                          outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3084                          outrel.r_addend = rel->r_addend;
3085                        }
3086                      else
3087                        {
3088                        /* h->dynindx may be -1 if this symbol was marked to
3089                           become local.  */
3090                        if (h == NULL
3091                            || ((info->symbolic || h->dynindx == -1)
3092                                 && h->def_regular))
3093                          {
3094                            relocate = TRUE;
3095                            outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
3096                            outrel.r_addend = relocation + rel->r_addend;
3097                          }
3098                        else
3099                          {
3100                            BFD_ASSERT (h->dynindx != -1);
3101                            outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3102                            outrel.r_addend = relocation + rel->r_addend;
3103                          }
3104                        }
3105    
3106                      loc = sreloc->contents;
3107                      loc += sreloc->reloc_count * sizeof(Elf32_External_Rela);
3108                      bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
3109                      ++sreloc->reloc_count;
3110    
3111                      /* If this reloc is against an external symbol, we do
3112                         not want to fiddle with the addend.  Otherwise, we
3113                         need to include the symbol value so that it becomes
3114                         an addend for the dynamic reloc.  */
3115                      if (! relocate)
3116                        continue;
3117                    }
3118                  break;
3119    
3120              case (int) R_M32R_10_PCREL :              case (int) R_M32R_10_PCREL :
3121                r = m32r_elf_do_10_pcrel_reloc (input_bfd, howto, input_section,                r = m32r_elf_do_10_pcrel_reloc (input_bfd, howto, input_section,
3122                                                contents, offset,                                                contents, offset,
3123                                                sec, relocation, addend);                                                sec, relocation, addend);
3124                break;                goto check_reloc;
3125    
3126              case (int) R_M32R_HI16_SLO :              case (int) R_M32R_HI16_SLO :
3127              case (int) R_M32R_HI16_ULO :              case (int) R_M32R_HI16_ULO :
# Line 1185  m32r_elf_relocate_section (output_bfd, i Line 3149  m32r_elf_relocate_section (output_bfd, i
3149                                                  contents, offset,                                                  contents, offset,
3150                                                  relocation, addend);                                                  relocation, addend);
3151                }                }
               break;  
3152    
3153                  goto check_reloc;
3154    
3155                case (int) R_M32R_SDA16_RELA:
3156              case (int) R_M32R_SDA16 :              case (int) R_M32R_SDA16 :
3157                {                {
3158                  const char *name;                  const char *name;
# Line 1206  m32r_elf_relocate_section (output_bfd, i Line 3172  m32r_elf_relocate_section (output_bfd, i
3172                                                   &sda_base);                                                   &sda_base);
3173                      if (r != bfd_reloc_ok)                      if (r != bfd_reloc_ok)
3174                        {                        {
3175                          ret = false;                          ret = FALSE;
3176                          goto check_reloc;                          goto check_reloc;
3177                        }                        }
3178    
# Line 1218  m32r_elf_relocate_section (output_bfd, i Line 3184  m32r_elf_relocate_section (output_bfd, i
3184                  else                  else
3185                    {                    {
3186                      (*_bfd_error_handler)                      (*_bfd_error_handler)
3187                        (_("%s: The target (%s) of an %s relocation is in the wrong section (%s)"),                        (_("%B: The target (%s) of an %s relocation is in the wrong section (%A)"),
3188                         bfd_archive_filename (input_bfd),                         input_bfd,
3189                           sec,
3190                         sym_name,                         sym_name,
3191                         m32r_elf_howto_table[(int) r_type].name,                         m32r_elf_howto_table[(int) r_type].name);
                        bfd_get_section_name (abfd, sec));  
3192                      /*bfd_set_error (bfd_error_bad_value); ??? why? */                      /*bfd_set_error (bfd_error_bad_value); ??? why? */
3193                      ret = false;                      ret = FALSE;
3194                      continue;                      continue;
3195                    }                    }
3196                }                }
3197                /* fall through */                /* fall through */
3198    
3199                default : /* OLD_M32R_RELOC */
3200    
             default :  
3201                r = _bfd_final_link_relocate (howto, input_bfd, input_section,                r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3202                                              contents, offset,                                              contents, offset,
3203                                              relocation, addend);                                              relocation, addend);
3204                break;                goto check_reloc;
3205              }              }
3206    
3207              r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3208                                            contents, rel->r_offset,
3209                                            relocation, rel->r_addend);
3210    
3211          }          }
3212    
3213      check_reloc:      check_reloc:
# Line 1262  m32r_elf_relocate_section (output_bfd, i Line 3234  m32r_elf_relocate_section (output_bfd, i
3234              {              {
3235              case bfd_reloc_overflow:              case bfd_reloc_overflow:
3236                if (! ((*info->callbacks->reloc_overflow)                if (! ((*info->callbacks->reloc_overflow)
3237                       (info, name, howto->name, (bfd_vma) 0,                       (info, (h ? &h->root : NULL), name, howto->name,
3238                        input_bfd, input_section, offset)))                        (bfd_vma) 0, input_bfd, input_section, offset)))
3239                  return false;                  return FALSE;
3240                break;                break;
3241    
3242              case bfd_reloc_undefined:              case bfd_reloc_undefined:
3243                if (! ((*info->callbacks->undefined_symbol)                if (! ((*info->callbacks->undefined_symbol)
3244                       (info, name, input_bfd, input_section,                       (info, name, input_bfd, input_section,
3245                        offset, true)))                        offset, TRUE)))
3246                  return false;                  return FALSE;
3247                break;                break;
3248    
3249              case bfd_reloc_outofrange:              case bfd_reloc_outofrange:
# Line 1294  m32r_elf_relocate_section (output_bfd, i Line 3266  m32r_elf_relocate_section (output_bfd, i
3266                if (!((*info->callbacks->warning)                if (!((*info->callbacks->warning)
3267                      (info, errmsg, name, input_bfd, input_section,                      (info, errmsg, name, input_bfd, input_section,
3268                       offset)))                       offset)))
3269                  return false;                  return FALSE;
3270                break;                break;
3271              }              }
3272          }          }
# Line 1302  m32r_elf_relocate_section (output_bfd, i Line 3274  m32r_elf_relocate_section (output_bfd, i
3274    
3275    return ret;    return ret;
3276  }  }
   
 #if 0 /* relaxing not supported yet */  
   
 /* This function handles relaxing for the m32r.  
    Relaxing on the m32r is tricky because of instruction alignment  
    requirements (4 byte instructions must be aligned on 4 byte boundaries).  
   
    The following relaxing opportunities are handled:  
   
    seth/add3/jl -> bl24 or bl8  
    seth/add3 -> ld24  
   
    It would be nice to handle bl24 -> bl8 but given:  
   
    - 4 byte insns must be on 4 byte boundaries  
    - branch instructions only branch to insns on 4 byte boundaries  
3277    
3278     this isn't much of a win because the insn in the 2 "deleted" bytes  /* Finish up dynamic symbol handling.  We set the contents of various
3279     must become a nop.  With some complexity some real relaxation could be     dynamic sections here.  */
3280     done but the frequency just wouldn't make it worth it; it's better to  static bfd_boolean
3281     try to do all the code compaction one can elsewhere.  m32r_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
3282     When the chip supports parallel 16 bit insns, things may change.       bfd *output_bfd;
3283  */       struct bfd_link_info *info;
3284         struct elf_link_hash_entry *h;
3285  static boolean       Elf_Internal_Sym *sym;
 m32r_elf_relax_section (abfd, sec, link_info, again)  
      bfd *abfd;  
      asection *sec;  
      struct bfd_link_info *link_info;  
      boolean *again;  
3286  {  {
3287    Elf_Internal_Shdr *symtab_hdr;    struct elf_m32r_link_hash_table *htab;
3288    /* The Rela structures are used here because that's what    bfd *dynobj;
3289       _bfd_elf32_link_read_relocs uses [for convenience - it sets the addend    bfd_byte *loc;
      field to 0].  */  
   Elf_Internal_Rela *internal_relocs = NULL;  
   Elf_Internal_Rela *irel, *irelend;  
   bfd_byte *contents = NULL;  
   Elf_Internal_Sym *isymbuf = NULL;  
   
   /* Assume nothing changes.  */  
   *again = false;  
   
   /* We don't have to do anything for a relocateable link, if  
      this section does not have relocs, or if this is not a  
      code section.  */  
   if (link_info->relocateable  
       || (sec->flags & SEC_RELOC) == 0  
       || sec->reloc_count == 0  
       || (sec->flags & SEC_CODE) == 0  
       || 0 /* FIXME: check SHF_M32R_CAN_RELAX */)  
     return true;  
   
   /* If this is the first time we have been called for this section,  
      initialize the cooked size.  */  
   if (sec->_cooked_size == 0)  
     sec->_cooked_size = sec->_raw_size;  
   
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;  
   
   /* Get a copy of the native relocations.  */  
   internal_relocs = (_bfd_elf32_link_read_relocs  
                      (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,  
                       link_info->keep_memory));  
   if (internal_relocs == NULL)  
     goto error_return;  
   
   /* Walk through them looking for relaxing opportunities.  */  
   irelend = internal_relocs + sec->reloc_count;  
   for (irel = internal_relocs; irel < irelend; irel++)  
     {  
       bfd_vma symval;  
   
       /* If this isn't something that can be relaxed, then ignore  
          this reloc.  */  
       if (ELF32_R_TYPE (irel->r_info) != (int) R_M32R_HI16_SLO)  
         continue;  
3290    
3291        /* Get the section contents if we haven't done so already.  */  #ifdef DEBUG_PIC
3292        if (contents == NULL)  printf("m32r_elf_finish_dynamic_symbol()\n");
         {  
           /* Get cached copy if it exists.  */  
           if (elf_section_data (sec)->this_hdr.contents != NULL)  
             contents = elf_section_data (sec)->this_hdr.contents;  
           else  
             {  
               /* Go get them off disk.  */  
               contents = (bfd_byte *) bfd_malloc (sec->_raw_size);  
               if (contents == NULL)  
                 goto error_return;  
   
               if (! bfd_get_section_contents (abfd, sec, contents,  
                                               (file_ptr) 0, sec->_raw_size))  
                 goto error_return;  
             }  
         }  
   
       /* Read this BFD's local symbols if we haven't done so already.  */  
       if (isymbuf == NULL && symtab_hdr->sh_info != 0)  
         {  
           isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;  
           if (isymbuf == NULL)  
             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,  
                                             symtab_hdr->sh_info, 0,  
                                             NULL, NULL, NULL);  
           if (isymbuf == NULL)  
             goto error_return;  
         }  
   
       /* Get the value of the symbol referred to by the reloc.  */  
       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)  
         {  
           /* A local symbol.  */  
           Elf_Internal_Sym *isym;  
           asection *sym_sec;  
   
           isym = isymbuf + ELF32_R_SYM (irel->r_info),  
           sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);  
           symval = (isym->st_value  
                     + sym_sec->output_section->vma  
                     + sym_sec->output_offset);  
         }  
       else  
         {  
           unsigned long indx;  
           struct elf_link_hash_entry *h;  
   
           /* An external symbol.  */  
           indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;  
           h = elf_sym_hashes (abfd)[indx];  
           BFD_ASSERT (h != NULL);  
           if (h->root.type != bfd_link_hash_defined  
               && h->root.type != bfd_link_hash_defweak)  
             {  
               /* This appears to be a reference to an undefined  
                  symbol.  Just ignore it--it will be caught by the  
                  regular reloc processing.  */  
               continue;  
             }  
   
           symval = (h->root.u.def.value  
                     + h->root.u.def.section->output_section->vma  
                     + h->root.u.def.section->output_offset);  
         }  
   
       /* For simplicity of coding, we are going to modify the section  
          contents, the section relocs, and the BFD symbol table.  We  
          must tell the rest of the code not to free up this  
          information.  It would be possible to instead create a table  
          of changes which have to be made, as is done in coff-mips.c;  
          that would be more work, but would require less memory when  
          the linker is run.  */  
   
       /* Try to change a seth/add3/jl subroutine call to bl24 or bl8.  
          This sequence is generated by the compiler when compiling in  
          32 bit mode.  Also look for seth/add3 -> ld24.  */  
   
       if (ELF32_R_TYPE (irel->r_info) == (int) R_M32R_HI16_SLO)  
         {  
           Elf_Internal_Rela *nrel;  
           bfd_vma pc = (sec->output_section->vma + sec->output_offset  
                         + irel->r_offset);  
           bfd_signed_vma pcrel_value = symval - pc;  
           unsigned int code,reg;  
           int addend,nop_p,bl8_p,to_delete;  
   
           /* The tests are ordered so that we get out as quickly as possible  
              if this isn't something we can relax, taking into account that  
              we are looking for two separate possibilities (jl/ld24).  */  
   
           /* Do nothing if no room in the section for this to be what we're  
              looking for.  */  
           if (irel->r_offset > sec->_cooked_size - 8)  
             continue;  
   
           /* Make sure the next relocation applies to the next  
              instruction and that it's the add3's reloc.  */  
           nrel = irel + 1;  
           if (nrel == irelend  
               || irel->r_offset + 4 != nrel->r_offset  
               || ELF32_R_TYPE (nrel->r_info) != (int) R_M32R_LO16)  
             continue;  
   
           /* See if the instructions are seth/add3.  */  
           /* FIXME: This is where macros from cgen can come in.  */  
           code = bfd_get_16 (abfd, contents + irel->r_offset + 0);  
           if ((code & 0xf0ff) != 0xd0c0)  
             continue; /* not seth rN,foo */  
           reg = (code & 0x0f00) >> 8;  
           code = bfd_get_16 (abfd, contents + irel->r_offset + 4);  
           if (code != (0x80a0 | reg | (reg << 8)))  
             continue; /* not add3 rN,rN,foo */  
   
           /* At this point we've confirmed we have seth/add3.  Now check  
              whether the next insn is a jl, in which case try to change this  
              to bl24 or bl8.  */  
   
           /* Ensure the branch target is in range.  
              The bl24 instruction has a 24 bit operand which is the target  
              address right shifted by 2, giving a signed range of 26 bits.  
              Note that 4 bytes are added to the high value because the target  
              will be at least 4 bytes closer if we can relax.  It'll actually  
              be 4 or 8 bytes closer, but we don't know which just yet and  
              the difference isn't significant enough to worry about.  */  
 #ifndef USE_REL /* put in for learning purposes */  
           pcrel_value += irel->r_addend;  
 #else  
           addend = bfd_get_signed_16 (abfd, contents + irel->r_offset + 2);  
           pcrel_value += addend;  
3293  #endif  #endif
3294    
3295            if (pcrel_value >= -(1 << 25) && pcrel_value < (1 << 25) + 4    htab = m32r_elf_hash_table (info);
3296                /* Do nothing if no room in the section for this to be what we're    dynobj = htab->root.dynobj;
                  looking for.  */  
               && (irel->r_offset <= sec->_cooked_size - 12)  
               /* Ensure the next insn is "jl rN".  */  
               && ((code = bfd_get_16 (abfd, contents + irel->r_offset + 8)),  
                   code != (0x1ec0 | reg)))  
             {  
               /* We can relax to bl24/bl8.  */  
   
               /* See if there's a nop following the jl.  
                  Also see if we can use a bl8 insn.  */  
               code = bfd_get_16 (abfd, contents + irel->r_offset + 10);  
               nop_p = (code & 0x7fff) == NOP_INSN;  
               bl8_p = pcrel_value >= -0x200 && pcrel_value < 0x200;  
   
               if (bl8_p)  
                 {  
                   /* Change "seth rN,foo" to "bl8 foo || nop".  
                      We OR in CODE just in case it's not a nop (technically,  
                      CODE currently must be a nop, but for cleanness we  
                      allow it to be anything).  */  
 #ifndef USE_REL /* put in for learning purposes */  
                   code = 0x7e000000 | MAKE_PARALLEL (code);  
 #else  
                   code = (0x7e000000 + (((addend >> 2) & 0xff) << 16)) | MAKE_PARALLEL (code);  
 #endif  
                   to_delete = 8;  
                 }  
               else  
                 {  
                   /* Change the seth rN,foo to a bl24 foo.  */  
 #ifndef USE_REL /* put in for learning purposes */  
                   code = 0xfe000000;  
 #else  
                   code = 0xfe000000 + ((addend >> 2) & 0xffffff);  
 #endif  
                   to_delete = nop_p ? 8 : 4;  
                 }  
3297    
3298                bfd_put_32 (abfd, code, contents + irel->r_offset);    if (h->plt.offset != (bfd_vma) -1)
3299        {
3300                /* Set the new reloc type.  */        asection *splt;
3301                irel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),        asection *sgot;
3302                                             bl8_p ? R_M32R_10_PCREL : R_M32R_26_PCREL);        asection *srela;
3303    
3304                /* Delete the add3 reloc by making it a null reloc.  */        bfd_vma plt_index;
3305                nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),        bfd_vma got_offset;
3306                                             R_M32R_NONE);        Elf_Internal_Rela rela;
3307              }  
3308            else if (addend >= 0        /* This symbol has an entry in the procedure linkage table.  Set
3309                     && symval + addend <= 0xffffff)           it up.  */
3310              {  
3311                /* We can relax to ld24.  */        BFD_ASSERT (h->dynindx != -1);
3312    
3313                code = 0xe0000000 | (reg << 24) | (addend & 0xffffff);        splt = htab->splt;
3314                bfd_put_32 (abfd, code, contents + irel->r_offset);        sgot = htab->sgotplt;
3315                to_delete = 4;        srela = htab->srelplt;
3316                /* Tell the following code a nop filler isn't needed.  */        BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
3317                nop_p = 1;  
3318              }        /* Get the index in the procedure linkage table which
3319            else           corresponds to this symbol.  This is the index of this symbol
3320              {           in all the symbols for which we are making plt entries.  The
3321                /* Can't do anything here.  */           first entry in the procedure linkage table is reserved.  */
3322                continue;        plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3323              }  
3324          /* Get the offset into the .got table of the entry that
3325            corresponds to this function.  Each .got entry is 4 bytes.
3326            The first three are reserved.  */
3327          got_offset = (plt_index + 3) * 4;
3328    
3329            /* Note that we've changed the relocs, section contents, etc.  */        /* Fill in the entry in the procedure linkage table.  */
3330            elf_section_data (sec)->relocs = internal_relocs;        if (! info->shared)
3331            elf_section_data (sec)->this_hdr.contents = contents;          {
3332            symtab_hdr->contents = (unsigned char *) isymbuf;            bfd_put_32 (output_bfd,
3333                  (PLT_ENTRY_WORD0b
3334            /* Delete TO_DELETE bytes of data.  */                 + (((sgot->output_section->vma
3335            if (!m32r_elf_relax_delete_bytes (abfd, sec,                      + sgot->output_offset
3336                                              irel->r_offset + 4, to_delete))                      + got_offset) >> 16) & 0xffff)),
3337              goto error_return;                splt->contents + h->plt.offset);
3338              bfd_put_32 (output_bfd,
3339            /* Now that the following bytes have been moved into place, see if                (PLT_ENTRY_WORD1b
3340               we need to replace the jl with a nop.  This happens when we had                 + ((sgot->output_section->vma
3341               to use a bl24 insn and the insn following the jl isn't a nop.                     + sgot->output_offset
3342               Technically, this situation can't happen (since the insn can                     + got_offset) & 0xffff)),
3343               never be executed) but to be clean we do this.  When the chip                splt->contents + h->plt.offset + 4);
3344               supports parallel 16 bit insns things may change.            bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
3345               We don't need to do this in the case of relaxing to ld24,                splt->contents + h->plt.offset + 8);
3346               and the above code sets nop_p so this isn't done.  */            bfd_put_32 (output_bfd,
3347            if (! nop_p && to_delete == 4)                (PLT_ENTRY_WORD3
3348              bfd_put_16 (abfd, NOP_INSN, contents + irel->r_offset + 4);                 + plt_index * sizeof (Elf32_External_Rela)),
3349                  splt->contents + h->plt.offset + 12);
3350            /* That will change things, so we should relax again.            bfd_put_32 (output_bfd,
3351               Note that this is not required, and it may be slow.  */                (PLT_ENTRY_WORD4
3352            *again = true;                 + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
3353                  splt->contents + h->plt.offset + 16);
3354            }
3355          else
3356            {
3357              bfd_put_32 (output_bfd,
3358                  PLT_ENTRY_WORD0 + got_offset,
3359                  splt->contents + h->plt.offset);
3360              bfd_put_32 (output_bfd, PLT_ENTRY_WORD1,
3361                  splt->contents + h->plt.offset + 4);
3362              bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
3363                  splt->contents + h->plt.offset + 8);
3364              bfd_put_32 (output_bfd,
3365                  (PLT_ENTRY_WORD3
3366                   + plt_index * sizeof (Elf32_External_Rela)),
3367                  splt->contents + h->plt.offset + 12);
3368              bfd_put_32 (output_bfd,
3369                  (PLT_ENTRY_WORD4
3370                   + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
3371                  splt->contents + h->plt.offset + 16);
3372            }
3373    
3374            continue;        /* Fill in the entry in the global offset table.  */
3375          }        bfd_put_32 (output_bfd,
3376                      (splt->output_section->vma
3377                       + splt->output_offset
3378                       + h->plt.offset
3379                       + 12), /* same offset */
3380                      sgot->contents + got_offset);
3381    
3382          /* Fill in the entry in the .rela.plt section.  */
3383          rela.r_offset = (sgot->output_section->vma
3384                           + sgot->output_offset
3385                           + got_offset);
3386          rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_JMP_SLOT);
3387          rela.r_addend = 0;
3388          loc = srela->contents;
3389          loc += plt_index * sizeof(Elf32_External_Rela);
3390          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3391    
3392        /* loop to try the next reloc */        if (!h->def_regular)
3393            {
3394              /* Mark the symbol as undefined, rather than as defined in
3395                 the .plt section.  Leave the value alone.  */
3396              sym->st_shndx = SHN_UNDEF;
3397            }
3398      }      }
3399    
3400    if (isymbuf != NULL    if (h->got.offset != (bfd_vma) -1)
       && symtab_hdr->contents != (unsigned char *) isymbuf)  
3401      {      {
3402        if (! link_info->keep_memory)        asection *sgot;
3403          free (isymbuf);        asection *srela;
3404          Elf_Internal_Rela rela;
3405    
3406          /* This symbol has an entry in the global offset table.  Set it
3407             up.  */
3408    
3409          sgot = htab->sgot;
3410          srela = htab->srelgot;
3411          BFD_ASSERT (sgot != NULL && srela != NULL);
3412    
3413          rela.r_offset = (sgot->output_section->vma
3414                           + sgot->output_offset
3415                           + (h->got.offset &~ 1));
3416    
3417          /* If this is a -Bsymbolic link, and the symbol is defined
3418             locally, we just want to emit a RELATIVE reloc.  Likewise if
3419             the symbol was forced to be local because of a version file.
3420             The entry in the global offset table will already have been
3421             initialized in the relocate_section function.  */
3422          if (info->shared
3423              && (info->symbolic
3424                  || h->dynindx == -1
3425                  || h->forced_local)
3426              && h->def_regular)
3427            {
3428              rela.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
3429              rela.r_addend = (h->root.u.def.value
3430                               + h->root.u.def.section->output_section->vma
3431                               + h->root.u.def.section->output_offset);
3432            }
3433        else        else
3434          {          {
3435            /* Cache the symbols for elf_link_input_bfd.  */            BFD_ASSERT((h->got.offset & 1) == 0);
3436            symtab_hdr->contents = (unsigned char *) isymbuf;            bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3437          }            rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_GLOB_DAT);
3438              rela.r_addend = 0;
3439            }
3440    
3441          loc = srela->contents;
3442          loc += srela->reloc_count * sizeof(Elf32_External_Rela);
3443          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3444          ++srela->reloc_count;
3445      }      }
3446    
3447    if (contents != NULL    if (h->needs_copy)
       && elf_section_data (sec)->this_hdr.contents != contents)  
3448      {      {
3449        if (! link_info->keep_memory)        asection *s;
3450          free (contents);        Elf_Internal_Rela rela;
3451        else  
3452          {        /* This symbols needs a copy reloc.  Set it up.  */
3453            /* Cache the section contents for elf_link_input_bfd.  */  
3454            elf_section_data (sec)->this_hdr.contents = contents;        BFD_ASSERT (h->dynindx != -1
3455          }                    && (h->root.type == bfd_link_hash_defined
3456                          || h->root.type == bfd_link_hash_defweak));
3457    
3458          s = bfd_get_section_by_name (h->root.u.def.section->owner,
3459                                       ".rela.bss");
3460          BFD_ASSERT (s != NULL);
3461    
3462          rela.r_offset = (h->root.u.def.value
3463                           + h->root.u.def.section->output_section->vma
3464                           + h->root.u.def.section->output_offset);
3465          rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_COPY);
3466          rela.r_addend = 0;
3467          loc = s->contents;
3468          loc += s->reloc_count * sizeof(Elf32_External_Rela);
3469          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3470          ++s->reloc_count;
3471      }      }
3472    
3473    if (internal_relocs != NULL    /* Mark some specially defined symbols as absolute.  */
3474        && elf_section_data (sec)->relocs != internal_relocs)    if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3475      free (internal_relocs);        || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3476        sym->st_shndx = SHN_ABS;
   return true;  
   
  error_return:  
   if (isymbuf != NULL  
       && symtab_hdr->contents != (unsigned char *) isymbuf)  
     free (isymbuf);  
   if (contents != NULL  
       && elf_section_data (sec)->this_hdr.contents != contents)  
     free (contents);  
   if (internal_relocs != NULL  
       && elf_section_data (sec)->relocs != internal_relocs)  
     free (internal_relocs);  
3477    
3478    return false;    return TRUE;
3479  }  }
3480    
 /* Delete some bytes from a section while relaxing.  */  
3481    
3482  static boolean  /* Finish up the dynamic sections.  */
3483  m32r_elf_relax_delete_bytes (abfd, sec, addr, count)  
3484       bfd *abfd;  static bfd_boolean
3485       asection *sec;  m32r_elf_finish_dynamic_sections (output_bfd, info)
3486       bfd_vma addr;       bfd *output_bfd;
3487       int count;       struct bfd_link_info *info;
3488  {  {
3489    Elf_Internal_Shdr *symtab_hdr;    struct elf_m32r_link_hash_table *htab;
3490    int shndx;    bfd *dynobj;
3491    bfd_byte *contents;    asection *sdyn;
3492    Elf_Internal_Rela *irel, *irelend;    asection *sgot;
   Elf_Internal_Rela *irelalign;  
   bfd_vma toaddr;  
   Elf_Internal_Sym *isym, *isymend;  
   struct elf_link_hash_entry **sym_hashes;  
   struct elf_link_hash_entry **end_hashes;  
   unsigned int symcount;  
3493    
3494    shndx = _bfd_elf_section_from_bfd_section (abfd, sec);  #ifdef DEBUG_PIC
3495    printf("m32r_elf_finish_dynamic_sections()\n");
3496    #endif
3497    
3498    contents = elf_section_data (sec)->this_hdr.contents;    htab = m32r_elf_hash_table (info);
3499      dynobj = htab->root.dynobj;
3500    
3501    /* The deletion must stop at the next ALIGN reloc for an aligment    sgot = htab->sgotplt;
3502       power larger than the number of bytes we are deleting.  */    sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3503    
3504    irelalign = NULL;    if (htab->root.dynamic_sections_created)
3505    toaddr = sec->_cooked_size;      {
3506          asection *splt;
3507          Elf32_External_Dyn *dyncon, *dynconend;
3508    
3509    irel = elf_section_data (sec)->relocs;        BFD_ASSERT (sgot != NULL && sdyn != NULL);
   irelend = irel + sec->reloc_count;  
3510    
3511    /* Actually delete the bytes.  */        dyncon = (Elf32_External_Dyn *) sdyn->contents;
3512    memmove (contents + addr, contents + addr + count, toaddr - addr - count);        dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   sec->_cooked_size -= count;  
3513    
3514    /* Adjust all the relocs.  */        for (; dyncon < dynconend; dyncon++)
3515    for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)          {
3516      {            Elf_Internal_Dyn dyn;
3517        /* Get the new reloc address.  */            const char *name;
3518        if ((irel->r_offset > addr            asection *s;
3519             && irel->r_offset < toaddr))  
3520          irel->r_offset -= count;            bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3521      }  
3522              switch (dyn.d_tag)
3523                {
3524                default:
3525                  break;
3526    
3527                case DT_PLTGOT:
3528                  name = ".got";
3529                  s = htab->sgot->output_section;
3530                  goto get_vma;
3531                case DT_JMPREL:
3532                  name = ".rela.plt";
3533                  s = htab->srelplt->output_section;
3534                get_vma:
3535                  BFD_ASSERT (s != NULL);
3536                  dyn.d_un.d_ptr = s->vma;
3537                  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3538                  break;
3539    
3540                case DT_PLTRELSZ:
3541                  s = htab->srelplt->output_section;
3542                  BFD_ASSERT (s != NULL);
3543                  dyn.d_un.d_val = s->size;
3544                  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3545                  break;
3546    
3547                case DT_RELASZ:
3548                  /* My reading of the SVR4 ABI indicates that the
3549                     procedure linkage table relocs (DT_JMPREL) should be
3550                     included in the overall relocs (DT_RELA).  This is
3551                     what Solaris does.  However, UnixWare can not handle
3552                     that case.  Therefore, we override the DT_RELASZ entry
3553                     here to make it not include the JMPREL relocs.  Since
3554                     the linker script arranges for .rela.plt to follow all
3555                     other relocation sections, we don't have to worry
3556                     about changing the DT_RELA entry.  */
3557                  if (htab->srelplt != NULL)
3558                    {
3559                      s = htab->srelplt->output_section;
3560                      dyn.d_un.d_val -= s->size;
3561                    }
3562                  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3563                  break;
3564                }
3565            }
3566    
3567    /* Adjust the local symbols defined in this section.  */        /* Fill in the first entry in the procedure linkage table.  */
3568    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;        splt = htab->splt;
3569    isym = (Elf_Internal_Sym *) symtab_hdr->contents;        if (splt && splt->size > 0)
3570    for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)          {
3571      {            if (info->shared)
3572        if (isym->st_shndx == shndx              {
3573            && isym->st_value > addr                bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents);
3574            && isym->st_value < toaddr)                bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4);
3575          isym->st_value -= count;                bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2, splt->contents + 8);
3576                  bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3, splt->contents + 12);
3577                  bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4, splt->contents + 16);
3578                }
3579              else
3580                {
3581                  unsigned long addr;
3582                  /* addr = .got + 4 */
3583                  addr = sgot->output_section->vma + sgot->output_offset + 4;
3584                  bfd_put_32 (output_bfd,
3585                              PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
3586                              splt->contents);
3587                  bfd_put_32 (output_bfd,
3588                              PLT0_ENTRY_WORD1 | (addr & 0xffff),
3589                              splt->contents + 4);
3590                  bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
3591                  bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
3592                  bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
3593                }
3594    
3595              elf_section_data (splt->output_section)->this_hdr.sh_entsize =
3596                PLT_ENTRY_SIZE;
3597            }
3598      }      }
3599    
3600    /* Now adjust the global symbols defined in this section.  */    /* Fill in the first three entries in the global offset table.  */
3601    symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)    if (sgot && sgot->size > 0)
               - symtab_hdr->sh_info);  
   sym_hashes = elf_sym_hashes (abfd);  
   end_hashes = sym_hashes + symcount;  
   for (; sym_hashes < end_hashes; sym_hashes++)  
3602      {      {
3603        struct elf_link_hash_entry *sym_hash = *sym_hashes;        if (sdyn == NULL)
3604            bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3605          else
3606            bfd_put_32 (output_bfd,
3607                        sdyn->output_section->vma + sdyn->output_offset,
3608                        sgot->contents);
3609          bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
3610          bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3611    
3612        if ((sym_hash->root.type == bfd_link_hash_defined        elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
            || sym_hash->root.type == bfd_link_hash_defweak)  
           && sym_hash->root.u.def.section == sec  
           && sym_hash->root.u.def.value > addr  
           && sym_hash->root.u.def.value < toaddr)  
         {  
           sym_hash->root.u.def.value -= count;  
         }  
3613      }      }
3614    
3615    return true;    return TRUE;
 }  
   
 /* This is a version of bfd_generic_get_relocated_section_contents  
    which uses m32r_elf_relocate_section.  */  
   
 static bfd_byte *  
 m32r_elf_get_relocated_section_contents (output_bfd, link_info, link_order,  
                                          data, relocateable, symbols)  
      bfd *output_bfd;  
      struct bfd_link_info *link_info;  
      struct bfd_link_order *link_order;  
      bfd_byte *data;  
      boolean relocateable;  
      asymbol **symbols;  
 {  
   Elf_Internal_Shdr *symtab_hdr;  
   asection *input_section = link_order->u.indirect.section;  
   bfd *input_bfd = input_section->owner;  
   asection **sections = NULL;  
   Elf_Internal_Rela *internal_relocs = NULL;  
   Elf_Internal_Sym *isymbuf = NULL;  
   bfd_size_type amt;  
   
   /* We only need to handle the case of relaxing, or of having a  
      particular set of section contents, specially.  */  
   if (relocateable  
       || elf_section_data (input_section)->this_hdr.contents == NULL)  
     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,  
                                                        link_order, data,  
                                                        relocateable,  
                                                        symbols);  
   
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;  
   
   memcpy (data, elf_section_data (input_section)->this_hdr.contents,  
           input_section->_raw_size);  
   
   if ((input_section->flags & SEC_RELOC) != 0  
       && input_section->reloc_count > 0)  
     {  
       Elf_Internal_Sym *isymp;  
       asection **secpp;  
       Elf32_External_Sym *esym, *esymend;  
   
       internal_relocs = (_bfd_elf32_link_read_relocs  
                          (input_bfd, input_section, (PTR) NULL,  
                           (Elf_Internal_Rela *) NULL, false));  
       if (internal_relocs == NULL)  
         goto error_return;  
   
       if (symtab_hdr->sh_info != 0)  
         {  
           isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;  
           if (isymbuf == NULL)  
             isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,  
                                             symtab_hdr->sh_info, 0,  
                                             NULL, NULL, NULL);  
           if (isymbuf == NULL)  
             goto error_return;  
         }  
   
       amt = symtab_hdr->sh_info;  
       amt *= sizeof (asection *);  
       sections = (asection **) bfd_malloc (amt);  
       if (sections == NULL && symtab_hdr->sh_info > 0)  
         goto error_return;  
   
       isymend = isymbuf + symtab_hdr->sh_info;  
       for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)  
         {  
           asection *isec;  
   
           if (isym->st_shndx == SHN_UNDEF)  
             isec = bfd_und_section_ptr;  
           else if (isym->st_shndx == SHN_ABS)  
             isec = bfd_abs_section_ptr;  
           else if (isym->st_shndx == SHN_COMMON)  
             isec = bfd_com_section_ptr;  
           else if (isym->st_shndx == SHN_M32R_SCOMMON)  
             isec = &m32r_elf_scom_section;  
           else  
             isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);  
   
           *secpp = isec;  
         }  
   
       if (! m32r_elf_relocate_section (output_bfd, link_info, input_bfd,  
                                        input_section, data, internal_relocs,  
                                        isymbuf, sections))  
         goto error_return;  
   
       if (sections != NULL)  
         free (sections);  
       if (isymbuf != NULL  
           && symtab_hdr->contents != (unsigned char *) isymbuf)  
         free (isymbuf);  
       if (elf_section_data (input_section)->relocs != internal_relocs)  
         free (internal_relocs);  
     }  
   
   return data;  
   
  error_return:  
   if (sections != NULL)  
     free (sections);  
   if (isymbuf != NULL  
       && symtab_hdr->contents != (unsigned char *) isymbuf)  
     free (isymbuf);  
   if (internal_relocs != NULL  
       && elf_section_data (input_section)->relocs != internal_relocs)  
     free (internal_relocs);  
   return NULL;  
3616  }  }
3617    
 #endif /* #if 0 */  
3618    
3619  /* Set the right machine number.  */  /* Set the right machine number.  */
3620  static boolean  static bfd_boolean
3621  m32r_elf_object_p (abfd)  m32r_elf_object_p (abfd)
3622       bfd *abfd;       bfd *abfd;
3623  {  {
# Line 1858  m32r_elf_object_p (abfd) Line 3626  m32r_elf_object_p (abfd)
3626      default:      default:
3627      case E_M32R_ARCH:   (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r);  break;      case E_M32R_ARCH:   (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r);  break;
3628      case E_M32RX_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;      case E_M32RX_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;
3629        case E_M32R2_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r2); break;
3630      }      }
3631    return true;    return TRUE;
3632  }  }
3633    
3634  /* Store the machine number in the flags field.  */  /* Store the machine number in the flags field.  */
3635  static void  static void
3636  m32r_elf_final_write_processing (abfd, linker)  m32r_elf_final_write_processing (abfd, linker)
3637       bfd *   abfd;       bfd *abfd;
3638       boolean linker ATTRIBUTE_UNUSED;       bfd_boolean linker ATTRIBUTE_UNUSED;
3639  {  {
3640    unsigned long val;    unsigned long val;
3641    
# Line 1875  m32r_elf_final_write_processing (abfd, l Line 3644  m32r_elf_final_write_processing (abfd, l
3644      default:      default:
3645      case bfd_mach_m32r:  val = E_M32R_ARCH; break;      case bfd_mach_m32r:  val = E_M32R_ARCH; break;
3646      case bfd_mach_m32rx: val = E_M32RX_ARCH; break;      case bfd_mach_m32rx: val = E_M32RX_ARCH; break;
3647        case bfd_mach_m32r2: val = E_M32R2_ARCH; break;
3648      }      }
3649    
3650    elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;    elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;
# Line 1882  m32r_elf_final_write_processing (abfd, l Line 3652  m32r_elf_final_write_processing (abfd, l
3652  }  }
3653    
3654  /* Function to keep M32R specific file flags.  */  /* Function to keep M32R specific file flags.  */
3655  static boolean  static bfd_boolean
3656  m32r_elf_set_private_flags (abfd, flags)  m32r_elf_set_private_flags (abfd, flags)
3657       bfd *    abfd;       bfd *abfd;
3658       flagword flags;       flagword flags;
3659  {  {
3660    BFD_ASSERT (!elf_flags_init (abfd)    BFD_ASSERT (!elf_flags_init (abfd)
3661                || elf_elfheader (abfd)->e_flags == flags);                || elf_elfheader (abfd)->e_flags == flags);
3662    
3663    elf_elfheader (abfd)->e_flags = flags;    elf_elfheader (abfd)->e_flags = flags;
3664    elf_flags_init (abfd) = true;    elf_flags_init (abfd) = TRUE;
3665    return true;    return TRUE;
3666  }  }
3667    
3668  /* Merge backend specific data from an object file to the output  /* Merge backend specific data from an object file to the output
3669     object file when linking.  */     object file when linking.  */
3670  static boolean  static bfd_boolean
3671  m32r_elf_merge_private_bfd_data (ibfd, obfd)  m32r_elf_merge_private_bfd_data (ibfd, obfd)
3672       bfd * ibfd;       bfd *ibfd;
3673       bfd * obfd;       bfd *obfd;
3674  {  {
3675    flagword out_flags;    flagword out_flags;
3676    flagword in_flags;    flagword in_flags;
3677    
3678    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3679        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3680      return true;      return TRUE;
3681    
3682    in_flags  = elf_elfheader (ibfd)->e_flags;    in_flags  = elf_elfheader (ibfd)->e_flags;
3683    out_flags = elf_elfheader (obfd)->e_flags;    out_flags = elf_elfheader (obfd)->e_flags;
# Line 1921  m32r_elf_merge_private_bfd_data (ibfd, o Line 3691  m32r_elf_merge_private_bfd_data (ibfd, o
3691           unitialised values, which surprise surprise, correspond           unitialised values, which surprise surprise, correspond
3692           to the default values.  */           to the default values.  */
3693        if (bfd_get_arch_info (ibfd)->the_default)        if (bfd_get_arch_info (ibfd)->the_default)
3694          return true;          return TRUE;
3695    
3696        elf_flags_init (obfd) = true;        elf_flags_init (obfd) = TRUE;
3697        elf_elfheader (obfd)->e_flags = in_flags;        elf_elfheader (obfd)->e_flags = in_flags;
3698    
3699        if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)        if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
# Line 1932  m32r_elf_merge_private_bfd_data (ibfd, o Line 3702  m32r_elf_merge_private_bfd_data (ibfd, o
3702            return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));            return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
3703          }          }
3704    
3705        return true;        return TRUE;
3706      }      }
3707    
3708    /* Check flag compatibility.  */    /* Check flag compatibility.  */
3709    if (in_flags == out_flags)    if (in_flags == out_flags)
3710      return true;      return TRUE;
3711    
3712    if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))    if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))
3713      {      {
3714        if ((in_flags & EF_M32R_ARCH) != E_M32R_ARCH)        if (   ((in_flags  & EF_M32R_ARCH) != E_M32R_ARCH)
3715              || ((out_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3716              || ((in_flags  & EF_M32R_ARCH) == E_M32R2_ARCH))
3717          {          {
3718            (*_bfd_error_handler)            (*_bfd_error_handler)
3719              (_("%s: Instruction set mismatch with previous modules"),              (_("%B: Instruction set mismatch with previous modules"), ibfd);
              bfd_archive_filename (ibfd));  
3720    
3721            bfd_set_error (bfd_error_bad_value);            bfd_set_error (bfd_error_bad_value);
3722            return false;            return FALSE;
3723          }          }
3724      }      }
3725    
3726    return true;    return TRUE;
3727  }  }
3728    
3729  /* Display the flags field */  /* Display the flags field */
3730  static boolean  static bfd_boolean
3731  m32r_elf_print_private_bfd_data (abfd, ptr)  m32r_elf_print_private_bfd_data (abfd, ptr)
3732       bfd *   abfd;       bfd *abfd;
3733       PTR     ptr;       PTR ptr;
3734  {  {
3735    FILE * file = (FILE *) ptr;    FILE * file = (FILE *) ptr;
3736    
3737    BFD_ASSERT (abfd != NULL && ptr != NULL)    BFD_ASSERT (abfd != NULL && ptr != NULL);
3738    
3739    _bfd_elf_print_private_bfd_data (abfd, ptr);    _bfd_elf_print_private_bfd_data (abfd, ptr);
3740    
# Line 1974  m32r_elf_print_private_bfd_data (abfd, p Line 3745  m32r_elf_print_private_bfd_data (abfd, p
3745      default:      default:
3746      case E_M32R_ARCH:  fprintf (file, _(": m32r instructions"));  break;      case E_M32R_ARCH:  fprintf (file, _(": m32r instructions"));  break;
3747      case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;      case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;
3748        case E_M32R2_ARCH: fprintf (file, _(": m32r2 instructions")); break;
3749      }      }
3750    
3751    fputc ('\n', file);    fputc ('\n', file);
3752    
3753    return true;    return TRUE;
3754  }  }
3755    
3756  asection *  asection *
# Line 1995  m32r_elf_gc_mark_hook (sec, info, rel, h Line 3767  m32r_elf_gc_mark_hook (sec, info, rel, h
3767        {        {
3768        case R_M32R_GNU_VTINHERIT:        case R_M32R_GNU_VTINHERIT:
3769        case R_M32R_GNU_VTENTRY:        case R_M32R_GNU_VTENTRY:
3770          case R_M32R_RELA_GNU_VTINHERIT:
3771          case R_M32R_RELA_GNU_VTENTRY:
3772          break;          break;
3773    
3774        default:        default:
# Line 2018  m32r_elf_gc_mark_hook (sec, info, rel, h Line 3792  m32r_elf_gc_mark_hook (sec, info, rel, h
3792    return NULL;    return NULL;
3793  }  }
3794    
3795  static boolean  static bfd_boolean
3796  m32r_elf_gc_sweep_hook (abfd, info, sec, relocs)  m32r_elf_gc_sweep_hook (abfd, info, sec, relocs)
3797       bfd *abfd ATTRIBUTE_UNUSED;       bfd *abfd ATTRIBUTE_UNUSED;
3798       struct bfd_link_info *info ATTRIBUTE_UNUSED;       struct bfd_link_info *info ATTRIBUTE_UNUSED;
3799       asection *sec ATTRIBUTE_UNUSED;       asection *sec ATTRIBUTE_UNUSED;
3800       const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;       const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
3801  {  {
3802    /* we don't use got and plt entries for m32r */    /* Update the got entry reference counts for the section being removed.  */
3803    return true;    Elf_Internal_Shdr *symtab_hdr;
3804      struct elf_link_hash_entry **sym_hashes;
3805      bfd_signed_vma *local_got_refcounts;
3806      const Elf_Internal_Rela *rel, *relend;
3807    
3808      elf_section_data (sec)->local_dynrel = NULL;
3809    
3810      symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3811      sym_hashes = elf_sym_hashes (abfd);
3812      local_got_refcounts = elf_local_got_refcounts (abfd);
3813    
3814      relend = relocs + sec->reloc_count;
3815      for (rel = relocs; rel < relend; rel++)
3816        {
3817          unsigned long r_symndx;
3818          struct elf_link_hash_entry *h = NULL;
3819    
3820          r_symndx = ELF32_R_SYM (rel->r_info);
3821          if (r_symndx >= symtab_hdr->sh_info)
3822            {
3823              h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3824              while (h->root.type == bfd_link_hash_indirect
3825                     || h->root.type == bfd_link_hash_warning)
3826                h = (struct elf_link_hash_entry *) h->root.u.i.link;
3827            }
3828    
3829          switch (ELF32_R_TYPE (rel->r_info))
3830            {
3831            case R_M32R_GOT16_HI_ULO:
3832            case R_M32R_GOT16_HI_SLO:
3833            case R_M32R_GOT16_LO:
3834            case R_M32R_GOTOFF:
3835            case R_M32R_GOTOFF_HI_ULO:
3836            case R_M32R_GOTOFF_HI_SLO:
3837            case R_M32R_GOTOFF_LO:
3838            case R_M32R_GOT24:
3839            case R_M32R_GOTPC_HI_ULO:
3840            case R_M32R_GOTPC_HI_SLO:
3841            case R_M32R_GOTPC_LO:
3842            case R_M32R_GOTPC24:
3843              if (h != NULL)
3844                {
3845                  if (h->got.refcount > 0)
3846                    h->got.refcount--;
3847                }
3848              else
3849                {
3850                  if (local_got_refcounts && local_got_refcounts[r_symndx] > 0)
3851                    local_got_refcounts[r_symndx]--;
3852                }
3853              break;
3854    
3855            case R_M32R_16_RELA:
3856            case R_M32R_24_RELA:
3857            case R_M32R_32_RELA:
3858            case R_M32R_HI16_ULO_RELA:
3859            case R_M32R_HI16_SLO_RELA:
3860            case R_M32R_LO16_RELA:
3861            case R_M32R_SDA16_RELA:
3862            case R_M32R_18_PCREL_RELA:
3863            case R_M32R_26_PCREL_RELA:
3864              if (h != NULL)
3865                {
3866                  struct elf_m32r_link_hash_entry *eh;
3867                  struct elf_m32r_dyn_relocs **pp;
3868                  struct elf_m32r_dyn_relocs *p;
3869    
3870                  if (!info->shared && h->plt.refcount > 0)
3871                    h->plt.refcount -= 1;
3872    
3873                  eh = (struct elf_m32r_link_hash_entry *) h;
3874    
3875                  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3876                    if (p->sec == sec)
3877                      {
3878                        if (ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
3879                            || ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA)
3880                          p->pc_count -= 1;
3881                        p->count -= 1;
3882                        if (p->count == 0)
3883                          *pp = p->next;
3884                        break;
3885                      }
3886                }
3887              break;
3888    
3889            case R_M32R_26_PLTREL:
3890              if (h != NULL)
3891                {
3892                  if (h->plt.refcount > 0)
3893                    h->plt.refcount--;
3894                }
3895              break;
3896    
3897            default:
3898              break;
3899            }
3900        }
3901    
3902      return TRUE;
3903  }  }
3904    
3905  /* Look through the relocs for a section during the first phase.  /* Look through the relocs for a section during the first phase.
3906     Since we don't do .gots or .plts, we just need to consider the     Since we don't do .gots or .plts, we just need to consider the
3907     virtual table relocs for gc.  */     virtual table relocs for gc.  */
3908    
3909  static boolean  static bfd_boolean
3910  m32r_elf_check_relocs (abfd, info, sec, relocs)  m32r_elf_check_relocs (abfd, info, sec, relocs)
3911       bfd *abfd;       bfd *abfd;
3912       struct bfd_link_info *info;       struct bfd_link_info *info;
# Line 2044  m32r_elf_check_relocs (abfd, info, sec, Line 3917  m32r_elf_check_relocs (abfd, info, sec,
3917    struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;    struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
3918    const Elf_Internal_Rela *rel;    const Elf_Internal_Rela *rel;
3919    const Elf_Internal_Rela *rel_end;    const Elf_Internal_Rela *rel_end;
3920      struct elf_m32r_link_hash_table *htab;
3921      bfd *dynobj;
3922      bfd_vma *local_got_offsets;
3923      asection *sgot, *srelgot, *sreloc;
3924    
3925    if (info->relocateable)    if (info->relocatable)
3926      return true;      return TRUE;
3927    
3928      sgot = srelgot = sreloc = NULL;
3929    
3930    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3931    sym_hashes = elf_sym_hashes (abfd);    sym_hashes = elf_sym_hashes (abfd);
# Line 2054  m32r_elf_check_relocs (abfd, info, sec, Line 3933  m32r_elf_check_relocs (abfd, info, sec,
3933    if (!elf_bad_symtab (abfd))    if (!elf_bad_symtab (abfd))
3934      sym_hashes_end -= symtab_hdr->sh_info;      sym_hashes_end -= symtab_hdr->sh_info;
3935    
3936      htab = m32r_elf_hash_table (info);
3937      dynobj = htab->root.dynobj;
3938      local_got_offsets = elf_local_got_offsets (abfd);
3939    
3940    rel_end = relocs + sec->reloc_count;    rel_end = relocs + sec->reloc_count;
3941    for (rel = relocs; rel < rel_end; rel++)    for (rel = relocs; rel < rel_end; rel++)
3942      {      {
3943          int r_type;
3944        struct elf_link_hash_entry *h;        struct elf_link_hash_entry *h;
3945        unsigned long r_symndx;        unsigned long r_symndx;
3946    
3947        r_symndx = ELF32_R_SYM (rel->r_info);        r_symndx = ELF32_R_SYM (rel->r_info);
3948          r_type = ELF32_R_TYPE (rel->r_info);
3949        if (r_symndx < symtab_hdr->sh_info)        if (r_symndx < symtab_hdr->sh_info)
3950          h = NULL;          h = NULL;
3951        else        else
3952          h = sym_hashes[r_symndx - symtab_hdr->sh_info];          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3953    
3954        switch (ELF32_R_TYPE (rel->r_info))        /* Some relocs require a global offset table.  */
3955          if (htab->sgot == NULL)
3956          {          {
3957              switch (r_type)
3958                {
3959                case R_M32R_GOT16_HI_ULO:
3960                case R_M32R_GOT16_HI_SLO:
3961                case R_M32R_GOTOFF:
3962                case R_M32R_GOTOFF_HI_ULO:
3963                case R_M32R_GOTOFF_HI_SLO:
3964                case R_M32R_GOTOFF_LO:
3965                case R_M32R_GOT16_LO:
3966                case R_M32R_GOTPC24:
3967                case R_M32R_GOTPC_HI_ULO:
3968                case R_M32R_GOTPC_HI_SLO:
3969                case R_M32R_GOTPC_LO:
3970                case R_M32R_GOT24:
3971                  if (dynobj == NULL)
3972                    htab->root.dynobj = dynobj = abfd;
3973                  if (! create_got_section (dynobj, info))
3974                    return FALSE;
3975                  break;
3976    
3977                default:
3978                  break;
3979              }
3980            }
3981    
3982          switch (r_type)
3983            {
3984            case R_M32R_GOT16_HI_ULO:
3985            case R_M32R_GOT16_HI_SLO:
3986            case R_M32R_GOT16_LO:
3987            case R_M32R_GOT24:
3988    
3989              if (h != NULL)
3990                h->got.refcount += 1;
3991              else
3992                {
3993                  bfd_signed_vma *local_got_refcounts;
3994    
3995                  /* This is a global offset table entry for a local
3996                     symbol.  */
3997                  local_got_refcounts = elf_local_got_refcounts (abfd);
3998                  if (local_got_refcounts == NULL)
3999                    {
4000                      bfd_size_type size;
4001    
4002                      size = symtab_hdr->sh_info;
4003                      size *= sizeof (bfd_signed_vma);
4004                      local_got_refcounts = ((bfd_signed_vma *)
4005                                             bfd_zalloc (abfd, size));
4006                      if (local_got_refcounts == NULL)
4007                        return FALSE;
4008                      elf_local_got_refcounts (abfd) = local_got_refcounts;
4009                    }
4010                  local_got_refcounts[r_symndx] += 1;
4011                }
4012              break;
4013    
4014            case R_M32R_26_PLTREL:
4015              /* This symbol requires a procedure linkage table entry.  We
4016                 actually build the entry in adjust_dynamic_symbol,
4017                 because this might be a case of linking PIC code without
4018                 linking in any dynamic objects, in which case we don't
4019                 need to generate a procedure linkage table after all.  */
4020    
4021              /* If this is a local symbol, we resolve it directly without
4022                 creating a procedure linkage table entry.  */
4023              if (h == NULL)
4024                continue;
4025    
4026              if (h->forced_local)
4027                break;
4028    
4029              h->needs_plt = 1;
4030              h->plt.refcount += 1;
4031              break;
4032    
4033            case R_M32R_16_RELA:
4034            case R_M32R_24_RELA:
4035            case R_M32R_32_RELA:
4036            case R_M32R_HI16_ULO_RELA:
4037            case R_M32R_HI16_SLO_RELA:
4038            case R_M32R_LO16_RELA:
4039            case R_M32R_SDA16_RELA:
4040            case R_M32R_18_PCREL_RELA:
4041            case R_M32R_26_PCREL_RELA:
4042    
4043              if (h != NULL && !info->shared)
4044                {
4045                  h->non_got_ref = 1;
4046                  h->plt.refcount += 1;
4047                }
4048    
4049              /* If we are creating a shared library, and this is a reloc
4050                 against a global symbol, or a non PC relative reloc
4051                 against a local symbol, then we need to copy the reloc
4052                 into the shared library.  However, if we are linking with
4053                 -Bsymbolic, we do not need to copy a reloc against a
4054                 global symbol which is defined in an object we are
4055                 including in the link (i.e., DEF_REGULAR is set).  At
4056                 this point we have not seen all the input files, so it is
4057                 possible that DEF_REGULAR is not set now but will be set
4058                 later (it is never cleared).  We account for that
4059                 possibility below by storing information in the
4060                 dyn_relocs field of the hash table entry. A similar
4061                 situation occurs when creating shared libraries and symbol
4062                 visibility changes render the symbol local.
4063    
4064                 If on the other hand, we are creating an executable, we
4065                 may need to keep relocations for symbols satisfied by a
4066                 dynamic library if we manage to avoid copy relocs for the
4067                 symbol.  */
4068              if ((info->shared
4069                   && (sec->flags & SEC_ALLOC) != 0
4070                   && ((r_type != R_M32R_26_PCREL_RELA
4071                        && r_type != R_M32R_18_PCREL_RELA)
4072                       || (h != NULL
4073                           && (! info->symbolic
4074                               || h->root.type == bfd_link_hash_defweak
4075                               || !h->def_regular))))
4076                  || (!info->shared
4077                      && (sec->flags & SEC_ALLOC) != 0
4078                      && h != NULL
4079                      && (h->root.type == bfd_link_hash_defweak
4080                          || !h->def_regular)))
4081                {
4082                  struct elf_m32r_dyn_relocs *p;
4083                  struct elf_m32r_dyn_relocs **head;
4084    
4085                  if (dynobj == NULL)
4086                    htab->root.dynobj = dynobj = abfd;
4087    
4088                  /* When creating a shared object, we must copy these
4089                     relocs into the output file.  We create a reloc
4090                     section in dynobj and make room for the reloc.  */
4091                  if (sreloc == NULL)
4092                    {
4093                      const char *name;
4094    
4095                      name = (bfd_elf_string_from_elf_section
4096                              (abfd,
4097                               elf_elfheader (abfd)->e_shstrndx,
4098                               elf_section_data (sec)->rel_hdr.sh_name));
4099                      if (name == NULL)
4100                        return FALSE;
4101    
4102                      BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4103                                  && strcmp (bfd_get_section_name (abfd, sec),
4104                                             name + 5) == 0);
4105    
4106                      sreloc = bfd_get_section_by_name (dynobj, name);
4107                      if (sreloc == NULL)
4108                        {
4109                          flagword flags;
4110    
4111                          sreloc = bfd_make_section (dynobj, name);
4112                          flags = (SEC_HAS_CONTENTS | SEC_READONLY
4113                                   | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4114                          if ((sec->flags & SEC_ALLOC) != 0)
4115                            flags |= SEC_ALLOC | SEC_LOAD;
4116                          if (sreloc == NULL
4117                              || ! bfd_set_section_flags (dynobj, sreloc, flags)
4118                              || ! bfd_set_section_alignment (dynobj, sreloc, 2))
4119                            return FALSE;
4120                        }
4121                      elf_section_data (sec)->sreloc = sreloc;
4122                    }
4123    
4124                  /* If this is a global symbol, we count the number of
4125                     relocations we need for this symbol.  */
4126                  if (h != NULL)
4127                    head = &((struct elf_m32r_link_hash_entry *) h)->dyn_relocs;
4128                  else
4129                    {
4130                      asection *s;
4131    
4132                      /* Track dynamic relocs needed for local syms too.  */
4133                      s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
4134                                                     sec, r_symndx);
4135                      if (s == NULL)
4136                        return FALSE;
4137    
4138                      head = ((struct elf_m32r_dyn_relocs **)
4139                              &elf_section_data (s)->local_dynrel);
4140                    }
4141    
4142                  p = *head;
4143                  if (p == NULL || p->sec != sec)
4144                    {
4145                      bfd_size_type amt = sizeof (*p);
4146                      p = ((struct elf_m32r_dyn_relocs *) bfd_alloc (dynobj, amt));
4147                      if (p == NULL)
4148                        return FALSE;
4149                      p->next = *head;
4150                      *head = p;
4151                      p->sec = sec;
4152                      p->count = 0;
4153                      p->pc_count = 0;
4154                    }
4155    
4156                  p->count += 1;
4157                  if (ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
4158                      || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA)
4159                    p->pc_count += 1;
4160                }
4161              break;
4162    
4163          /* This relocation describes the C++ object vtable hierarchy.          /* This relocation describes the C++ object vtable hierarchy.
4164             Reconstruct it for later use during GC.  */             Reconstruct it for later use during GC.  */
4165            case R_M32R_RELA_GNU_VTINHERIT:
4166          case R_M32R_GNU_VTINHERIT:          case R_M32R_GNU_VTINHERIT:
4167            if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))            if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4168              return false;              return FALSE;
4169            break;            break;
4170    
4171          /* This relocation describes which C++ vtable entries are actually          /* This relocation describes which C++ vtable entries are actually
4172             used.  Record for later use during GC.  */             used.  Record for later use during GC.  */
4173          case R_M32R_GNU_VTENTRY:          case R_M32R_GNU_VTENTRY:
4174            if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))            if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
4175              return false;              return FALSE;
4176              break;
4177            case R_M32R_RELA_GNU_VTENTRY:
4178              if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4179                return FALSE;
4180            break;            break;
4181          }          }
4182      }      }
4183    
4184    return true;    return TRUE;
4185    }
4186    
4187    static struct bfd_elf_special_section const m32r_elf_special_sections[]=
4188    {
4189      { ".sdata",   6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4190      { ".sbss",    5, -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
4191      { NULL,       0,  0, 0,            0 }
4192    };
4193    
4194    static bfd_boolean
4195    m32r_elf_fake_sections (abfd, hdr, sec)
4196         bfd *abfd;
4197         Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
4198         asection *sec;
4199    {
4200      register const char *name;
4201    
4202      name = bfd_get_section_name (abfd, sec);
4203    
4204      /* The generic elf_fake_sections will set up REL_HDR using the
4205         default kind of relocations.  But, we may actually need both
4206         kinds of relocations, so we set up the second header here.
4207    
4208         This is not necessary for the O32 ABI since that only uses Elf32_Rel
4209         relocations (cf. System V ABI, MIPS RISC Processor Supplement,
4210         3rd Edition, p. 4-17).  It breaks the IRIX 5/6 32-bit ld, since one
4211         of the resulting empty .rela.<section> sections starts with
4212         sh_offset == object size, and ld doesn't allow that.  While the check
4213         is arguably bogus for empty or SHT_NOBITS sections, it can easily be
4214         avoided by not emitting those useless sections in the first place.  */
4215      if ((sec->flags & SEC_RELOC) != 0)
4216        {
4217          struct bfd_elf_section_data *esd;
4218          bfd_size_type amt = sizeof (Elf_Internal_Shdr);
4219    
4220          esd = elf_section_data (sec);
4221          BFD_ASSERT (esd->rel_hdr2 == NULL);
4222          esd->rel_hdr2 = (Elf_Internal_Shdr *) bfd_zalloc (abfd, amt);
4223          if (!esd->rel_hdr2)
4224            return FALSE;
4225          _bfd_elf_init_reloc_shdr (abfd, esd->rel_hdr2, sec,
4226                                    !sec->use_rela_p);
4227        }
4228    
4229      return TRUE;
4230    }
4231    
4232    static enum elf_reloc_type_class
4233    m32r_elf_reloc_type_class (rela)
4234         const Elf_Internal_Rela *rela;
4235    {
4236      switch ((int) ELF32_R_TYPE (rela->r_info))
4237        {
4238        case R_M32R_RELATIVE:
4239          return reloc_class_relative;
4240        case R_M32R_JMP_SLOT:
4241          return reloc_class_plt;
4242        case R_M32R_COPY:
4243          return reloc_class_copy;
4244        default:
4245          return reloc_class_normal;
4246        }
4247  }  }
4248    
4249  #define ELF_ARCH                bfd_arch_m32r  #define ELF_ARCH                bfd_arch_m32r
# Line 2094  m32r_elf_check_relocs (abfd, info, sec, Line 4253  m32r_elf_check_relocs (abfd, info, sec,
4253    
4254  #define TARGET_BIG_SYM          bfd_elf32_m32r_vec  #define TARGET_BIG_SYM          bfd_elf32_m32r_vec
4255  #define TARGET_BIG_NAME         "elf32-m32r"  #define TARGET_BIG_NAME         "elf32-m32r"
4256    #define TARGET_LITTLE_SYM       bfd_elf32_m32rle_vec
4257    #define TARGET_LITTLE_NAME      "elf32-m32rle"
4258    
4259  #define elf_info_to_howto                       0  #define elf_info_to_howto                       m32r_info_to_howto
4260  #define elf_info_to_howto_rel                   m32r_info_to_howto_rel  #define elf_info_to_howto_rel                   m32r_info_to_howto_rel
4261  #define elf_backend_section_from_bfd_section    _bfd_m32r_elf_section_from_bfd_section  #define elf_backend_section_from_bfd_section    _bfd_m32r_elf_section_from_bfd_section
4262  #define elf_backend_symbol_processing           _bfd_m32r_elf_symbol_processing  #define elf_backend_symbol_processing           _bfd_m32r_elf_symbol_processing
# Line 2105  m32r_elf_check_relocs (abfd, info, sec, Line 4266  m32r_elf_check_relocs (abfd, info, sec,
4266  #define elf_backend_gc_sweep_hook               m32r_elf_gc_sweep_hook  #define elf_backend_gc_sweep_hook               m32r_elf_gc_sweep_hook
4267  #define elf_backend_check_relocs                m32r_elf_check_relocs  #define elf_backend_check_relocs                m32r_elf_check_relocs
4268    
4269    #define elf_backend_create_dynamic_sections     m32r_elf_create_dynamic_sections
4270    #define bfd_elf32_bfd_link_hash_table_create    m32r_elf_link_hash_table_create
4271    #define elf_backend_size_dynamic_sections       m32r_elf_size_dynamic_sections
4272    #define elf_backend_finish_dynamic_sections     m32r_elf_finish_dynamic_sections
4273    #define elf_backend_adjust_dynamic_symbol       m32r_elf_adjust_dynamic_symbol
4274    #define elf_backend_finish_dynamic_symbol       m32r_elf_finish_dynamic_symbol
4275    #define elf_backend_reloc_type_class            m32r_elf_reloc_type_class
4276    #define elf_backend_copy_indirect_symbol        m32r_elf_copy_indirect_symbol
4277    
4278  #define elf_backend_can_gc_sections             1  #define elf_backend_can_gc_sections             1
4279  #ifndef USE_REL  /*#if !USE_REL
4280  #define elf_backend_rela_normal                 1  #define elf_backend_rela_normal                 1
4281  #endif  #endif*/
4282  #if 0 /* not yet */  #define elf_backend_can_refcount 1
4283  /* relax support */  #define elf_backend_want_got_plt 1
4284  #define bfd_elf32_bfd_relax_section             m32r_elf_relax_section  #define elf_backend_plt_readonly 1
4285  #define bfd_elf32_bfd_get_relocated_section_contents \  #define elf_backend_want_plt_sym 0
4286                                          m32r_elf_get_relocated_section_contents  #define elf_backend_got_header_size 12
4287    
4288    #define elf_backend_may_use_rel_p       1
4289    #ifdef USE_M32R_OLD_RELOC
4290    #define elf_backend_default_use_rela_p  0
4291    #define elf_backend_may_use_rela_p      0
4292    #else
4293    #define elf_backend_default_use_rela_p  1
4294    #define elf_backend_may_use_rela_p      1
4295    #define elf_backend_fake_sections       m32r_elf_fake_sections
4296  #endif  #endif
4297    
4298  #define elf_backend_object_p                    m32r_elf_object_p  #define elf_backend_object_p                    m32r_elf_object_p
# Line 2121  m32r_elf_check_relocs (abfd, info, sec, Line 4300  m32r_elf_check_relocs (abfd, info, sec,
4300  #define bfd_elf32_bfd_merge_private_bfd_data    m32r_elf_merge_private_bfd_data  #define bfd_elf32_bfd_merge_private_bfd_data    m32r_elf_merge_private_bfd_data
4301  #define bfd_elf32_bfd_set_private_flags         m32r_elf_set_private_flags  #define bfd_elf32_bfd_set_private_flags         m32r_elf_set_private_flags
4302  #define bfd_elf32_bfd_print_private_bfd_data    m32r_elf_print_private_bfd_data  #define bfd_elf32_bfd_print_private_bfd_data    m32r_elf_print_private_bfd_data
4303    #define elf_backend_special_sections            m32r_elf_special_sections
4304    
4305    #include "elf32-target.h"
4306    
4307    #undef ELF_MAXPAGESIZE
4308    #define ELF_MAXPAGESIZE         0x1000
4309    
4310    #undef TARGET_BIG_SYM
4311    #define TARGET_BIG_SYM          bfd_elf32_m32rlin_vec
4312    #undef TARGET_BIG_NAME
4313    #define TARGET_BIG_NAME         "elf32-m32r-linux"
4314    #undef TARGET_LITTLE_SYM
4315    #define TARGET_LITTLE_SYM       bfd_elf32_m32rlelin_vec
4316    #undef TARGET_LITTLE_NAME
4317    #define TARGET_LITTLE_NAME      "elf32-m32rle-linux"
4318    #undef elf32_bed
4319    #define elf32_bed               elf32_m32r_lin_bed
4320    
4321  #include "elf32-target.h"  #include "elf32-target.h"
4322    

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.1.20.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26