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

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

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

revision 1.1.1.1 by camm, Fri Aug 9 05:35:20 2002 UTC revision 1.1.1.1.20.1 by camm, Fri Sep 30 02:08:58 2005 UTC
# Line 1  Line 1 
1  /* Hitachi SH specific support for 32-bit ELF  /* Renesas / SuperH SH 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     Contributed by Ian Lance Taylor, Cygnus Support.     Contributed by Ian Lance Taylor, Cygnus Support.
5    
6  This file is part of BFD, the Binary File Descriptor library.     This file is part of BFD, the Binary File Descriptor library.
7    
8  This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
9  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
10  the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.     (at your option) any later version.
12    
13  This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.     GNU General Public License for more details.
17    
18  You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
21    
22  #include "bfd.h"  #include "bfd.h"
23  #include "sysdep.h"  #include "sysdep.h"
# Line 25  Foundation, Inc., 59 Temple Place - Suit Line 25  Foundation, Inc., 59 Temple Place - Suit
25  #include "libbfd.h"  #include "libbfd.h"
26  #include "elf-bfd.h"  #include "elf-bfd.h"
27  #include "elf/sh.h"  #include "elf/sh.h"
28    #include "libiberty.h"
29    #include "../opcodes/sh-opc.h"
30    
31  static bfd_reloc_status_type sh_elf_reloc  static bfd_reloc_status_type sh_elf_reloc
32    PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));    (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
33  static bfd_reloc_status_type sh_elf_ignore_reloc  static bfd_reloc_status_type sh_elf_ignore_reloc
34    PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));    (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
35  static reloc_howto_type *sh_elf_reloc_type_lookup  static bfd_boolean sh_elf_relax_delete_bytes
36    PARAMS ((bfd *, bfd_reloc_code_real_type));    (bfd *, asection *, bfd_vma, int);
37  static void sh_elf_info_to_howto  static bfd_boolean sh_elf_align_loads
38    PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));    (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
39  static boolean sh_elf_set_private_flags  #ifndef SH64_ELF
40    PARAMS ((bfd *, flagword));  static bfd_boolean sh_elf_swap_insns
41  static boolean sh_elf_copy_private_data    (bfd *, asection *, void *, bfd_byte *, bfd_vma);
42    PARAMS ((bfd *, bfd *));  #endif
43  static boolean sh_elf_merge_private_data  static int sh_elf_optimized_tls_reloc
44    PARAMS ((bfd *, bfd *));    (struct bfd_link_info *, int, int);
45  static boolean sh_elf_set_mach_from_flags  static bfd_vma dtpoff_base
46    PARAMS ((bfd *));    (struct bfd_link_info *);
47  static boolean sh_elf_relax_section  static bfd_vma tpoff
48    PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));    (struct bfd_link_info *, bfd_vma);
 static boolean sh_elf_relax_delete_bytes  
   PARAMS ((bfd *, asection *, bfd_vma, int));  
 static boolean sh_elf_align_loads  
   PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, boolean *));  
 static boolean sh_elf_swap_insns  
   PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));  
 static boolean sh_elf_relocate_section  
   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,  
            Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));  
 static bfd_byte *sh_elf_get_relocated_section_contents  
   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,  
            bfd_byte *, boolean, asymbol **));  
 static boolean sh_elf_check_relocs  
   PARAMS ((bfd *, struct bfd_link_info *, asection *,  
            const Elf_Internal_Rela *));  
 static struct bfd_hash_entry *sh_elf_link_hash_newfunc  
   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));  
 static struct bfd_link_hash_table *sh_elf_link_hash_table_create  
   PARAMS ((bfd *));  
 static boolean sh_elf_adjust_dynamic_symbol  
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));  
 static boolean sh_elf_size_dynamic_sections  
   PARAMS ((bfd *, struct bfd_link_info *));  
 static boolean sh_elf_finish_dynamic_symbol  
   PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,  
            Elf_Internal_Sym *));  
 static boolean sh_elf_finish_dynamic_sections  
   PARAMS ((bfd *, struct bfd_link_info *));  
 static bfd_reloc_status_type sh_elf_reloc_loop  
   PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *,  
            bfd_vma, bfd_vma));  
 static boolean sh_elf_create_dynamic_sections  
   PARAMS ((bfd *, struct bfd_link_info *));  
 static asection * sh_elf_gc_mark_hook  
   PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,  
            struct elf_link_hash_entry *, Elf_Internal_Sym *));  
 static boolean sh_elf_gc_sweep_hook  
   PARAMS ((bfd *, struct bfd_link_info *, asection *,  
            const Elf_Internal_Rela *));  
 static enum elf_reloc_type_class sh_elf_reloc_type_class  
   PARAMS ((const Elf_Internal_Rela *));  
 #ifdef INCLUDE_SHMEDIA  
 inline static void movi_shori_putval PARAMS ((bfd *, unsigned long, char *));  
 #endif  
49    
50  /* The name of the dynamic interpreter.  This is put in the .interp  /* The name of the dynamic interpreter.  This is put in the .interp
51     section.  */     section.  */
# Line 101  static reloc_howto_type sh_elf_howto_tab Line 59  static reloc_howto_type sh_elf_howto_tab
59           0,                     /* rightshift */           0,                     /* rightshift */
60           0,                     /* size (0 = byte, 1 = short, 2 = long) */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
61           0,                     /* bitsize */           0,                     /* bitsize */
62           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
63           0,                     /* bitpos */           0,                     /* bitpos */
64           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
65           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
66           "R_SH_NONE",           /* name */           "R_SH_NONE",           /* name */
67           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
68           0,                     /* src_mask */           0,                     /* src_mask */
69           0,                     /* dst_mask */           0,                     /* dst_mask */
70           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
71    
72    /* 32 bit absolute relocation.  Setting partial_inplace to true and    /* 32 bit absolute relocation.  Setting partial_inplace to TRUE and
73       src_mask to a non-zero value is similar to the COFF toolchain.  */       src_mask to a non-zero value is similar to the COFF toolchain.  */
74    HOWTO (R_SH_DIR32,            /* type */    HOWTO (R_SH_DIR32,            /* type */
75           0,                     /* rightshift */           0,                     /* rightshift */
76           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
77           32,                    /* bitsize */           32,                    /* bitsize */
78           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
79           0,                     /* bitpos */           0,                     /* bitpos */
80           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
81           sh_elf_reloc,          /* special_function */           sh_elf_reloc,          /* special_function */
82           "R_SH_DIR32",          /* name */           "R_SH_DIR32",          /* name */
83           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
84           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
85           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
86           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
87    
88    /* 32 bit PC relative relocation.  */    /* 32 bit PC relative relocation.  */
89    HOWTO (R_SH_REL32,            /* type */    HOWTO (R_SH_REL32,            /* type */
90           0,                     /* rightshift */           0,                     /* rightshift */
91           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
92           32,                    /* bitsize */           32,                    /* bitsize */
93           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
94           0,                     /* bitpos */           0,                     /* bitpos */
95           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
96           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
97           "R_SH_REL32",          /* name */           "R_SH_REL32",          /* name */
98           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
99           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
100           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
101           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
102    
103    /* 8 bit PC relative branch divided by 2.  */    /* 8 bit PC relative branch divided by 2.  */
104    HOWTO (R_SH_DIR8WPN,          /* type */    HOWTO (R_SH_DIR8WPN,          /* type */
105           1,                     /* rightshift */           1,                     /* rightshift */
106           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
107           8,                     /* bitsize */           8,                     /* bitsize */
108           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
109           0,                     /* bitpos */           0,                     /* bitpos */
110           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
111           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
112           "R_SH_DIR8WPN",        /* name */           "R_SH_DIR8WPN",        /* name */
113           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
114           0xff,                  /* src_mask */           0xff,                  /* src_mask */
115           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
116           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
117    
118    /* 12 bit PC relative branch divided by 2.  */    /* 12 bit PC relative branch divided by 2.  */
119      /* This cannot be partial_inplace because relaxation can't know the
120         eventual value of a symbol.  */
121    HOWTO (R_SH_IND12W,           /* type */    HOWTO (R_SH_IND12W,           /* type */
122           1,                     /* rightshift */           1,                     /* rightshift */
123           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
124           12,                    /* bitsize */           12,                    /* bitsize */
125           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
126           0,                     /* bitpos */           0,                     /* bitpos */
127           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
128           sh_elf_reloc,          /* special_function */           NULL,                  /* special_function */
129           "R_SH_IND12W",         /* name */           "R_SH_IND12W",         /* name */
130           true,                  /* partial_inplace */           FALSE,                 /* partial_inplace */
131           0xfff,                 /* src_mask */           0x0,                   /* src_mask */
132           0xfff,                 /* dst_mask */           0xfff,                 /* dst_mask */
133           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
134    
135    /* 8 bit unsigned PC relative divided by 4.  */    /* 8 bit unsigned PC relative divided by 4.  */
136    HOWTO (R_SH_DIR8WPL,          /* type */    HOWTO (R_SH_DIR8WPL,          /* type */
137           2,                     /* rightshift */           2,                     /* rightshift */
138           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
139           8,                     /* bitsize */           8,                     /* bitsize */
140           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
141           0,                     /* bitpos */           0,                     /* bitpos */
142           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
143           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
144           "R_SH_DIR8WPL",        /* name */           "R_SH_DIR8WPL",        /* name */
145           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
146           0xff,                  /* src_mask */           0xff,                  /* src_mask */
147           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
148           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
149    
150    /* 8 bit unsigned PC relative divided by 2.  */    /* 8 bit unsigned PC relative divided by 2.  */
151    HOWTO (R_SH_DIR8WPZ,          /* type */    HOWTO (R_SH_DIR8WPZ,          /* type */
152           1,                     /* rightshift */           1,                     /* rightshift */
153           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
154           8,                     /* bitsize */           8,                     /* bitsize */
155           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
156           0,                     /* bitpos */           0,                     /* bitpos */
157           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
158           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
159           "R_SH_DIR8WPZ",        /* name */           "R_SH_DIR8WPZ",        /* name */
160           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
161           0xff,                  /* src_mask */           0xff,                  /* src_mask */
162           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
163           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
164    
165    /* 8 bit GBR relative.  FIXME: This only makes sense if we have some    /* 8 bit GBR relative.  FIXME: This only makes sense if we have some
166       special symbol for the GBR relative area, and that is not       special symbol for the GBR relative area, and that is not
# Line 209  static reloc_howto_type sh_elf_howto_tab Line 169  static reloc_howto_type sh_elf_howto_tab
169           0,                     /* rightshift */           0,                     /* rightshift */
170           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
171           8,                     /* bitsize */           8,                     /* bitsize */
172           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
173           0,                     /* bitpos */           0,                     /* bitpos */
174           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
175           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
176           "R_SH_DIR8BP",         /* name */           "R_SH_DIR8BP",         /* name */
177           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
178           0,                     /* src_mask */           0,                     /* src_mask */
179           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
180           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
181    
182    /* 8 bit GBR relative divided by 2.  FIXME: This only makes sense if    /* 8 bit GBR relative divided by 2.  FIXME: This only makes sense if
183       we have some special symbol for the GBR relative area, and that       we have some special symbol for the GBR relative area, and that
# Line 226  static reloc_howto_type sh_elf_howto_tab Line 186  static reloc_howto_type sh_elf_howto_tab
186           1,                     /* rightshift */           1,                     /* rightshift */
187           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
188           8,                     /* bitsize */           8,                     /* bitsize */
189           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
190           0,                     /* bitpos */           0,                     /* bitpos */
191           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
192           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
193           "R_SH_DIR8W",          /* name */           "R_SH_DIR8W",          /* name */
194           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
195           0,                     /* src_mask */           0,                     /* src_mask */
196           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
197           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
198    
199    /* 8 bit GBR relative divided by 4.  FIXME: This only makes sense if    /* 8 bit GBR relative divided by 4.  FIXME: This only makes sense if
200       we have some special symbol for the GBR relative area, and that       we have some special symbol for the GBR relative area, and that
# Line 243  static reloc_howto_type sh_elf_howto_tab Line 203  static reloc_howto_type sh_elf_howto_tab
203           2,                     /* rightshift */           2,                     /* rightshift */
204           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
205           8,                     /* bitsize */           8,                     /* bitsize */
206           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
207           0,                     /* bitpos */           0,                     /* bitpos */
208           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
209           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
210           "R_SH_DIR8L",          /* name */           "R_SH_DIR8L",          /* name */
211           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
212           0,                     /* src_mask */           0,                     /* src_mask */
213           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
214           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
215    
216      /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
217      HOWTO (R_SH_LOOP_START,       /* type */
218             1,                     /* rightshift */
219             1,                     /* size (0 = byte, 1 = short, 2 = long) */
220             8,                     /* bitsize */
221             FALSE,                 /* pc_relative */
222             0,                     /* bitpos */
223             complain_overflow_signed, /* complain_on_overflow */
224             sh_elf_ignore_reloc,   /* special_function */
225             "R_SH_LOOP_START",     /* name */
226             TRUE,                  /* partial_inplace */
227             0xff,                  /* src_mask */
228             0xff,                  /* dst_mask */
229             TRUE),                 /* pcrel_offset */
230    
231      /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
232      HOWTO (R_SH_LOOP_END,         /* type */
233             1,                     /* rightshift */
234             1,                     /* size (0 = byte, 1 = short, 2 = long) */
235             8,                     /* bitsize */
236             FALSE,                 /* pc_relative */
237             0,                     /* bitpos */
238             complain_overflow_signed, /* complain_on_overflow */
239             sh_elf_ignore_reloc,   /* special_function */
240             "R_SH_LOOP_END",       /* name */
241             TRUE,                  /* partial_inplace */
242             0xff,                  /* src_mask */
243             0xff,                  /* dst_mask */
244             TRUE),                 /* pcrel_offset */
245    
   EMPTY_HOWTO (10),  
   EMPTY_HOWTO (11),  
246    EMPTY_HOWTO (12),    EMPTY_HOWTO (12),
247    EMPTY_HOWTO (13),    EMPTY_HOWTO (13),
248    EMPTY_HOWTO (14),    EMPTY_HOWTO (14),
# Line 265  static reloc_howto_type sh_elf_howto_tab Line 253  static reloc_howto_type sh_elf_howto_tab
253    EMPTY_HOWTO (19),    EMPTY_HOWTO (19),
254    EMPTY_HOWTO (20),    EMPTY_HOWTO (20),
255    EMPTY_HOWTO (21),    EMPTY_HOWTO (21),
   EMPTY_HOWTO (22),  
   EMPTY_HOWTO (23),  
   EMPTY_HOWTO (24),  
256    
257    /* The remaining relocs are a GNU extension used for relaxing.  The    /* The remaining relocs are a GNU extension used for relaxing.  The
258       final pass of the linker never needs to do anything with any of       final pass of the linker never needs to do anything with any of
259       these relocs.  Any required operations are handled by the       these relocs.  Any required operations are handled by the
260       relaxation code.  */       relaxation code.  */
261    
262      /* GNU extension to record C++ vtable hierarchy */
263      HOWTO (R_SH_GNU_VTINHERIT, /* type */
264             0,                     /* rightshift */
265             2,                     /* size (0 = byte, 1 = short, 2 = long) */
266             0,                     /* bitsize */
267             FALSE,                 /* pc_relative */
268             0,                     /* bitpos */
269             complain_overflow_dont, /* complain_on_overflow */
270             NULL,                  /* special_function */
271             "R_SH_GNU_VTINHERIT", /* name */
272             FALSE,                 /* partial_inplace */
273             0,                     /* src_mask */
274             0,                     /* dst_mask */
275             FALSE),                /* pcrel_offset */
276    
277      /* GNU extension to record C++ vtable member usage */
278      HOWTO (R_SH_GNU_VTENTRY,     /* type */
279             0,                     /* rightshift */
280             2,                     /* size (0 = byte, 1 = short, 2 = long) */
281             0,                     /* bitsize */
282             FALSE,                 /* pc_relative */
283             0,                     /* bitpos */
284             complain_overflow_dont, /* complain_on_overflow */
285             _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
286             "R_SH_GNU_VTENTRY",   /* name */
287             FALSE,                 /* partial_inplace */
288             0,                     /* src_mask */
289             0,                     /* dst_mask */
290             FALSE),                /* pcrel_offset */
291    
292      /* An 8 bit switch table entry.  This is generated for an expression
293         such as ``.word L1 - L2''.  The offset holds the difference
294         between the reloc address and L2.  */
295      HOWTO (R_SH_SWITCH8,          /* type */
296             0,                     /* rightshift */
297             0,                     /* size (0 = byte, 1 = short, 2 = long) */
298             8,                     /* bitsize */
299             FALSE,                 /* pc_relative */
300             0,                     /* bitpos */
301             complain_overflow_unsigned, /* complain_on_overflow */
302             sh_elf_ignore_reloc,   /* special_function */
303             "R_SH_SWITCH8",        /* name */
304             FALSE,                 /* partial_inplace */
305             0,                     /* src_mask */
306             0,                     /* dst_mask */
307             TRUE),                 /* pcrel_offset */
308    
309    /* A 16 bit switch table entry.  This is generated for an expression    /* A 16 bit switch table entry.  This is generated for an expression
310       such as ``.word L1 - L2''.  The offset holds the difference       such as ``.word L1 - L2''.  The offset holds the difference
311       between the reloc address and L2.  */       between the reloc address and L2.  */
# Line 281  static reloc_howto_type sh_elf_howto_tab Line 313  static reloc_howto_type sh_elf_howto_tab
313           0,                     /* rightshift */           0,                     /* rightshift */
314           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* 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_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
319           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
320           "R_SH_SWITCH16",       /* name */           "R_SH_SWITCH16",       /* name */
321           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
322           0,                     /* src_mask */           0,                     /* src_mask */
323           0,                     /* dst_mask */           0,                     /* dst_mask */
324           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
325    
326    /* A 32 bit switch table entry.  This is generated for an expression    /* A 32 bit switch table entry.  This is generated for an expression
327       such as ``.long L1 - L2''.  The offset holds the difference       such as ``.long L1 - L2''.  The offset holds the difference
# Line 298  static reloc_howto_type sh_elf_howto_tab Line 330  static reloc_howto_type sh_elf_howto_tab
330           0,                     /* rightshift */           0,                     /* rightshift */
331           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
332           32,                    /* bitsize */           32,                    /* bitsize */
333           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
334           0,                     /* bitpos */           0,                     /* bitpos */
335           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
336           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
337           "R_SH_SWITCH32",       /* name */           "R_SH_SWITCH32",       /* name */
338           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
339           0,                     /* src_mask */           0,                     /* src_mask */
340           0,                     /* dst_mask */           0,                     /* dst_mask */
341           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
342    
343    /* Indicates a .uses pseudo-op.  The compiler will generate .uses    /* Indicates a .uses pseudo-op.  The compiler will generate .uses
344       pseudo-ops when it finds a function call which can be relaxed.       pseudo-ops when it finds a function call which can be relaxed.
# Line 316  static reloc_howto_type sh_elf_howto_tab Line 348  static reloc_howto_type sh_elf_howto_tab
348           0,                     /* rightshift */           0,                     /* rightshift */
349           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
350           0,                     /* bitsize */           0,                     /* bitsize */
351           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
352           0,                     /* bitpos */           0,                     /* bitpos */
353           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
354           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
355           "R_SH_USES",           /* name */           "R_SH_USES",           /* name */
356           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
357           0,                     /* src_mask */           0,                     /* src_mask */
358           0,                     /* dst_mask */           0,                     /* dst_mask */
359           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
360    
361    /* The assembler will generate this reloc for addresses referred to    /* The assembler will generate this reloc for addresses referred to
362       by the register loads associated with USES relocs.  The offset       by the register loads associated with USES relocs.  The offset
# Line 334  static reloc_howto_type sh_elf_howto_tab Line 366  static reloc_howto_type sh_elf_howto_tab
366           0,                     /* rightshift */           0,                     /* rightshift */
367           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
368           0,                     /* bitsize */           0,                     /* bitsize */
369           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
370           0,                     /* bitpos */           0,                     /* bitpos */
371           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
372           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
373           "R_SH_COUNT",          /* name */           "R_SH_COUNT",          /* name */
374           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
375           0,                     /* src_mask */           0,                     /* src_mask */
376           0,                     /* dst_mask */           0,                     /* dst_mask */
377           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
378    
379    /* Indicates an alignment statement.  The offset field is the power    /* Indicates an alignment statement.  The offset field is the power
380       of 2 to which subsequent portions of the object file must be       of 2 to which subsequent portions of the object file must be
# Line 351  static reloc_howto_type sh_elf_howto_tab Line 383  static reloc_howto_type sh_elf_howto_tab
383           0,                     /* rightshift */           0,                     /* rightshift */
384           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
385           0,                     /* bitsize */           0,                     /* bitsize */
386           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
387           0,                     /* bitpos */           0,                     /* bitpos */
388           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
389           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
390           "R_SH_ALIGN",  /* name */           "R_SH_ALIGN",  /* name */
391           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
392           0,                     /* src_mask */           0,                     /* src_mask */
393           0,                     /* dst_mask */           0,                     /* dst_mask */
394           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
395    
396    /* The assembler will generate this reloc before a block of    /* The assembler will generate this reloc before a block of
397       instructions.  A section should be processed as assumining it       instructions.  A section should be processed as assuming it
398       contains data, unless this reloc is seen.  */       contains data, unless this reloc is seen.  */
399    HOWTO (R_SH_CODE,             /* type */    HOWTO (R_SH_CODE,             /* type */
400           0,                     /* rightshift */           0,                     /* rightshift */
401           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
402           0,                     /* bitsize */           0,                     /* bitsize */
403           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
404           0,                     /* bitpos */           0,                     /* bitpos */
405           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
406           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
407           "R_SH_CODE",           /* name */           "R_SH_CODE",           /* name */
408           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
409           0,                     /* src_mask */           0,                     /* src_mask */
410           0,                     /* dst_mask */           0,                     /* dst_mask */
411           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
412    
413    /* The assembler will generate this reloc after a block of    /* The assembler will generate this reloc after a block of
414       instructions when it sees data that is not instructions.  */       instructions when it sees data that is not instructions.  */
# Line 384  static reloc_howto_type sh_elf_howto_tab Line 416  static reloc_howto_type sh_elf_howto_tab
416           0,                     /* rightshift */           0,                     /* rightshift */
417           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
418           0,                     /* bitsize */           0,                     /* bitsize */
419           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
420           0,                     /* bitpos */           0,                     /* bitpos */
421           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
422           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
423           "R_SH_DATA",           /* name */           "R_SH_DATA",           /* name */
424           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
425           0,                     /* src_mask */           0,                     /* src_mask */
426           0,                     /* dst_mask */           0,                     /* dst_mask */
427           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
428    
429    /* The assembler generates this reloc for each label within a block    /* The assembler generates this reloc for each label within a block
430       of instructions.  This permits the linker to avoid swapping       of instructions.  This permits the linker to avoid swapping
# Line 401  static reloc_howto_type sh_elf_howto_tab Line 433  static reloc_howto_type sh_elf_howto_tab
433           0,                     /* rightshift */           0,                     /* rightshift */
434           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
435           0,                     /* bitsize */           0,                     /* bitsize */
436           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
437           0,                     /* bitpos */           0,                     /* bitpos */
438           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
439           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
440           "R_SH_LABEL",          /* name */           "R_SH_LABEL",          /* name */
441           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
442           0,                     /* src_mask */           0,                     /* src_mask */
443           0,                     /* dst_mask */           0,                     /* dst_mask */
444           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
445    
446    /* An 8 bit switch table entry.  This is generated for an expression    /* The next 12 are only supported via linking in SHC-generated objects.  */
447       such as ``.word L1 - L2''.  The offset holds the difference    HOWTO (R_SH_DIR16,            /* type */
448       between the reloc address and L2.  */           0,                     /* rightshift */
449    HOWTO (R_SH_SWITCH8,          /* type */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
450             16,                    /* bitsize */
451             FALSE,                 /* pc_relative */
452             0,                     /* bitpos */
453             complain_overflow_dont, /* complain_on_overflow */
454             bfd_elf_generic_reloc, /* special_function */
455             "R_SH_DIR16",          /* name */
456             FALSE,                 /* partial_inplace */
457             0,                     /* src_mask */
458             0xffff,                /* dst_mask */
459             FALSE),                /* pcrel_offset */
460    
461      HOWTO (R_SH_DIR8,             /* type */
462           0,                     /* rightshift */           0,                     /* rightshift */
463           0,                     /* size (0 = byte, 1 = short, 2 = long) */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
464           8,                     /* bitsize */           8,                     /* bitsize */
465           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
466             0,                     /* bitpos */
467             complain_overflow_dont, /* complain_on_overflow */
468             bfd_elf_generic_reloc, /* special_function */
469             "R_SH_DIR8",           /* name */
470             FALSE,                 /* partial_inplace */
471             0,                     /* src_mask */
472             0xff,                  /* dst_mask */
473             FALSE),                /* pcrel_offset */
474    
475      HOWTO (R_SH_DIR8UL,           /* type */
476             2,                     /* rightshift */
477             0,                     /* size (0 = byte, 1 = short, 2 = long) */
478             8,                     /* bitsize */
479             FALSE,                 /* pc_relative */
480           0,                     /* bitpos */           0,                     /* bitpos */
481           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
482           sh_elf_ignore_reloc,   /* special_function */           bfd_elf_generic_reloc, /* special_function */
483           "R_SH_SWITCH8",        /* name */           "R_SH_DIR8UL",         /* name */
484           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
485           0,                     /* src_mask */           0,                     /* src_mask */
486           0,                     /* dst_mask */           0xff,                  /* dst_mask */
487           true),                 /* pcrel_offset */           FALSE),                /* pcrel_offset */
488    
489    /* GNU extension to record C++ vtable hierarchy */    HOWTO (R_SH_DIR8UW,           /* type */
490    HOWTO (R_SH_GNU_VTINHERIT, /* type */           1,                     /* rightshift */
491           0,                     /* rightshift */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
492           2,                     /* size (0 = byte, 1 = short, 2 = long) */           8,                     /* bitsize */
493           0,                     /* bitsize */           FALSE,                 /* pc_relative */
494           false,                 /* pc_relative */           0,                     /* bitpos */
495           0,                     /* bitpos */           complain_overflow_unsigned, /* complain_on_overflow */
496           complain_overflow_dont, /* complain_on_overflow */           bfd_elf_generic_reloc, /* special_function */
497           NULL,                  /* special_function */           "R_SH_DIR8UW",         /* name */
498           "R_SH_GNU_VTINHERIT", /* name */           FALSE,                 /* partial_inplace */
499           false,                 /* partial_inplace */           0,                     /* src_mask */
500           0,                     /* src_mask */           0xff,                  /* dst_mask */
501           0,                     /* dst_mask */           FALSE),                /* pcrel_offset */
          false),                /* pcrel_offset */  
502    
503    /* GNU extension to record C++ vtable member usage */    HOWTO (R_SH_DIR8U,            /* type */
504    HOWTO (R_SH_GNU_VTENTRY,     /* type */           0,                     /* rightshift */
505           0,                     /* rightshift */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
506           2,                     /* size (0 = byte, 1 = short, 2 = long) */           8,                     /* bitsize */
507           0,                     /* bitsize */           FALSE,                 /* pc_relative */
508           false,                 /* pc_relative */           0,                     /* bitpos */
509           0,                     /* bitpos */           complain_overflow_unsigned, /* complain_on_overflow */
510           complain_overflow_dont, /* complain_on_overflow */           bfd_elf_generic_reloc, /* special_function */
511           _bfd_elf_rel_vtable_reloc_fn,  /* special_function */           "R_SH_DIR8U",          /* name */
512           "R_SH_GNU_VTENTRY",   /* name */           FALSE,                 /* partial_inplace */
513           false,                 /* partial_inplace */           0,                     /* src_mask */
514           0,                     /* src_mask */           0xff,                  /* dst_mask */
515           0,                     /* dst_mask */           FALSE),                /* pcrel_offset */
          false),                /* pcrel_offset */  
516    
517    /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */    HOWTO (R_SH_DIR8SW,           /* type */
   HOWTO (R_SH_LOOP_START,       /* type */  
518           1,                     /* rightshift */           1,                     /* rightshift */
519           1,                     /* size (0 = byte, 1 = short, 2 = long) */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
520           8,                     /* bitsize */           8,                     /* bitsize */
521           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
522           0,                     /* bitpos */           0,                     /* bitpos */
523           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
524           sh_elf_ignore_reloc,   /* special_function */           bfd_elf_generic_reloc, /* special_function */
525           "R_SH_LOOP_START",     /* name */           "R_SH_DIR8SW",         /* name */
526           true,                  /* partial_inplace */           FALSE,                 /* partial_inplace */
527           0xff,                  /* src_mask */           0,                     /* src_mask */
528           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
529           true),                 /* pcrel_offset */           FALSE),                /* pcrel_offset */
530    
531    /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */    HOWTO (R_SH_DIR8S,            /* type */
532    HOWTO (R_SH_LOOP_END,         /* type */           0,                     /* rightshift */
533           1,                     /* rightshift */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
          1,                     /* size (0 = byte, 1 = short, 2 = long) */  
534           8,                     /* bitsize */           8,                     /* bitsize */
535           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
536           0,                     /* bitpos */           0,                     /* bitpos */
537           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
538           sh_elf_ignore_reloc,   /* special_function */           bfd_elf_generic_reloc, /* special_function */
539           "R_SH_LOOP_END",       /* name */           "R_SH_DIR8S",          /* name */
540           true,                  /* partial_inplace */           FALSE,                 /* partial_inplace */
541           0xff,                  /* src_mask */           0,                     /* src_mask */
542           0xff,                  /* dst_mask */           0xff,                  /* dst_mask */
543           true),                 /* pcrel_offset */           FALSE),                /* pcrel_offset */
544    
545    EMPTY_HOWTO (38),    HOWTO (R_SH_DIR4UL,           /* type */
546    EMPTY_HOWTO (39),           2,                     /* rightshift */
547    EMPTY_HOWTO (40),           0,                     /* size (0 = byte, 1 = short, 2 = long) */
548    EMPTY_HOWTO (41),           4,                     /* bitsize */
549    EMPTY_HOWTO (42),           FALSE,                 /* pc_relative */
550    EMPTY_HOWTO (43),           0,                     /* bitpos */
551    EMPTY_HOWTO (44),           complain_overflow_unsigned, /* complain_on_overflow */
552             bfd_elf_generic_reloc, /* special_function */
553             "R_SH_DIR4UL",         /* name */
554             FALSE,                 /* partial_inplace */
555             0,                     /* src_mask */
556             0x0f,                  /* dst_mask */
557             FALSE),                /* pcrel_offset */
558    
559      HOWTO (R_SH_DIR4UW,           /* type */
560             1,                     /* rightshift */
561             0,                     /* size (0 = byte, 1 = short, 2 = long) */
562             4,                     /* bitsize */
563             FALSE,                 /* pc_relative */
564             0,                     /* bitpos */
565             complain_overflow_unsigned, /* complain_on_overflow */
566             bfd_elf_generic_reloc, /* special_function */
567             "R_SH_DIR4UW",         /* name */
568             FALSE,                 /* partial_inplace */
569             0,                     /* src_mask */
570             0x0f,                  /* dst_mask */
571             FALSE),                /* pcrel_offset */
572    
573      HOWTO (R_SH_DIR4U,            /* type */
574             0,                     /* rightshift */
575             0,                     /* size (0 = byte, 1 = short, 2 = long) */
576             4,                     /* bitsize */
577             FALSE,                 /* pc_relative */
578             0,                     /* bitpos */
579             complain_overflow_unsigned, /* complain_on_overflow */
580             bfd_elf_generic_reloc, /* special_function */
581             "R_SH_DIR4U",          /* name */
582             FALSE,                 /* partial_inplace */
583             0,                     /* src_mask */
584             0x0f,                  /* dst_mask */
585             FALSE),                /* pcrel_offset */
586    
587      HOWTO (R_SH_PSHA,             /* type */
588             0,                     /* rightshift */
589             1,                     /* size (0 = byte, 1 = short, 2 = long) */
590             7,                     /* bitsize */
591             FALSE,                 /* pc_relative */
592             4,                     /* bitpos */
593             complain_overflow_signed, /* complain_on_overflow */
594             bfd_elf_generic_reloc, /* special_function */
595             "R_SH_PSHA",           /* name */
596             FALSE,                 /* partial_inplace */
597             0,                     /* src_mask */
598             0x0f,                  /* dst_mask */
599             FALSE),                /* pcrel_offset */
600    
601      HOWTO (R_SH_PSHL,             /* type */
602             0,                     /* rightshift */
603             1,                     /* size (0 = byte, 1 = short, 2 = long) */
604             7,                     /* bitsize */
605             FALSE,                 /* pc_relative */
606             4,                     /* bitpos */
607             complain_overflow_signed, /* complain_on_overflow */
608             bfd_elf_generic_reloc, /* special_function */
609             "R_SH_PSHL",           /* name */
610             FALSE,                 /* partial_inplace */
611             0,                     /* src_mask */
612             0x0f,                  /* dst_mask */
613             FALSE),                /* pcrel_offset */
614    
615  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
616    /* Used in SHLLI.L and SHLRI.L.  */    /* Used in SHLLI.L and SHLRI.L.  */
# Line 502  static reloc_howto_type sh_elf_howto_tab Line 618  static reloc_howto_type sh_elf_howto_tab
618           0,                     /* rightshift */           0,                     /* rightshift */
619           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
620           5,                     /* bitsize */           5,                     /* bitsize */
621           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
622           10,                    /* bitpos */           10,                    /* bitpos */
623           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
624           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
625           "R_SH_DIR5U",          /* name */           "R_SH_DIR5U",          /* name */
626           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
627           0,                     /* src_mask */           0,                     /* src_mask */
628           0xfc00,                /* dst_mask */           0xfc00,                /* dst_mask */
629           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
630    
631    /* Used in SHARI, SHLLI et al.  */    /* Used in SHARI, SHLLI et al.  */
632    HOWTO (R_SH_DIR6U,            /* type */    HOWTO (R_SH_DIR6U,            /* type */
633           0,                     /* rightshift */           0,                     /* rightshift */
634           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
635           6,                     /* bitsize */           6,                     /* bitsize */
636           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
637           10,                    /* bitpos */           10,                    /* bitpos */
638           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
639           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
640           "R_SH_DIR6U",          /* name */           "R_SH_DIR6U",          /* name */
641           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
642           0,                     /* src_mask */           0,                     /* src_mask */
643           0xfc00,                /* dst_mask */           0xfc00,                /* dst_mask */
644           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
645    
646    /* Used in BxxI, LDHI.L et al.  */    /* Used in BxxI, LDHI.L et al.  */
647    HOWTO (R_SH_DIR6S,            /* type */    HOWTO (R_SH_DIR6S,            /* type */
648           0,                     /* rightshift */           0,                     /* rightshift */
649           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
650           6,                     /* bitsize */           6,                     /* bitsize */
651           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
652           10,                    /* bitpos */           10,                    /* bitpos */
653           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
654           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
655           "R_SH_DIR6S",          /* name */           "R_SH_DIR6S",          /* name */
656           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
657           0,                     /* src_mask */           0,                     /* src_mask */
658           0xfc00,                /* dst_mask */           0xfc00,                /* dst_mask */
659           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
660    
661    /* Used in ADDI, ANDI et al.  */    /* Used in ADDI, ANDI et al.  */
662    HOWTO (R_SH_DIR10S,           /* type */    HOWTO (R_SH_DIR10S,           /* type */
663           0,                     /* rightshift */           0,                     /* rightshift */
664           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
665           10,                    /* bitsize */           10,                    /* bitsize */
666           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
667           10,                    /* bitpos */           10,                    /* bitpos */
668           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
669           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
670           "R_SH_DIR10S",         /* name */           "R_SH_DIR10S",         /* name */
671           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
672           0,                     /* src_mask */           0,                     /* src_mask */
673           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
674           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
675    
676    /* Used in LD.UW, ST.W et al.  */    /* Used in LD.UW, ST.W et al.  */
677    HOWTO (R_SH_DIR10SW,  /* type */    HOWTO (R_SH_DIR10SW,  /* type */
678           1,                     /* rightshift */           1,                     /* rightshift */
679           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
680           11,                    /* bitsize */           11,                    /* bitsize */
681           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
682           10,                    /* bitpos */           10,                    /* bitpos */
683           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
684           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
685           "R_SH_DIR10SW",        /* name */           "R_SH_DIR10SW",        /* name */
686           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
687           0,                     /* src_mask */           0,                     /* src_mask */
688           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
689           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
690    
691    /* Used in LD.L, FLD.S et al.  */    /* Used in LD.L, FLD.S et al.  */
692    HOWTO (R_SH_DIR10SL,  /* type */    HOWTO (R_SH_DIR10SL,  /* type */
693           2,                     /* rightshift */           2,                     /* rightshift */
694           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
695           12,                    /* bitsize */           12,                    /* bitsize */
696           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
697           10,                    /* bitpos */           10,                    /* bitpos */
698           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
699           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
700           "R_SH_DIR10SL",        /* name */           "R_SH_DIR10SL",        /* name */
701           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
702           0,                     /* src_mask */           0,                     /* src_mask */
703           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
704           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
705    
706    /* Used in FLD.D, FST.P et al.  */    /* Used in FLD.D, FST.P et al.  */
707    HOWTO (R_SH_DIR10SQ,  /* type */    HOWTO (R_SH_DIR10SQ,  /* type */
708           3,                     /* rightshift */           3,                     /* rightshift */
709           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
710           13,                    /* bitsize */           13,                    /* bitsize */
711           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
712           10,                    /* bitpos */           10,                    /* bitpos */
713           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
714           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
715           "R_SH_DIR10SQ",        /* name */           "R_SH_DIR10SQ",        /* name */
716           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
717           0,                     /* src_mask */           0,                     /* src_mask */
718           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
719           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
720    
721  #else  #else
722    EMPTY_HOWTO (45),    EMPTY_HOWTO (45),
# Line 613  static reloc_howto_type sh_elf_howto_tab Line 729  static reloc_howto_type sh_elf_howto_tab
729  #endif  #endif
730    
731    EMPTY_HOWTO (52),    EMPTY_HOWTO (52),
732    EMPTY_HOWTO (53),  
733      HOWTO (R_SH_DIR16S,           /* type */
734             0,                     /* rightshift */
735             1,                     /* size (0 = byte, 1 = short, 2 = long) */
736             16,                    /* bitsize */
737             FALSE,                 /* pc_relative */
738             0,                     /* bitpos */
739             complain_overflow_signed, /* complain_on_overflow */
740             bfd_elf_generic_reloc, /* special_function */
741             "R_SH_DIR16S",         /* name */
742             FALSE,                 /* partial_inplace */
743             0,                     /* src_mask */
744             0xffff,                /* dst_mask */
745             FALSE),                /* pcrel_offset */
746    
747    EMPTY_HOWTO (54),    EMPTY_HOWTO (54),
748    EMPTY_HOWTO (55),    EMPTY_HOWTO (55),
749    EMPTY_HOWTO (56),    EMPTY_HOWTO (56),
# Line 704  static reloc_howto_type sh_elf_howto_tab Line 834  static reloc_howto_type sh_elf_howto_tab
834    EMPTY_HOWTO (141),    EMPTY_HOWTO (141),
835    EMPTY_HOWTO (142),    EMPTY_HOWTO (142),
836    EMPTY_HOWTO (143),    EMPTY_HOWTO (143),
837    EMPTY_HOWTO (144),  
838    EMPTY_HOWTO (145),    HOWTO (R_SH_TLS_GD_32,        /* type */
839    EMPTY_HOWTO (146),           0,                     /* rightshift */
840    EMPTY_HOWTO (147),           2,                     /* size (0 = byte, 1 = short, 2 = long) */
841    EMPTY_HOWTO (148),           32,                    /* bitsize */
842    EMPTY_HOWTO (149),           FALSE,                 /* pc_relative */
843    EMPTY_HOWTO (150),           0,                     /* bitpos */
844    EMPTY_HOWTO (151),           complain_overflow_bitfield, /* complain_on_overflow */
845             bfd_elf_generic_reloc, /* */
846             "R_SH_TLS_GD_32",      /* name */
847             TRUE,                  /* partial_inplace */
848             0xffffffff,            /* src_mask */
849             0xffffffff,            /* dst_mask */
850             FALSE),                /* pcrel_offset */
851    
852      HOWTO (R_SH_TLS_LD_32,        /* type */
853             0,                     /* rightshift */
854             2,                     /* size (0 = byte, 1 = short, 2 = long) */
855             32,                    /* bitsize */
856             FALSE,                 /* pc_relative */
857             0,                     /* bitpos */
858             complain_overflow_bitfield, /* complain_on_overflow */
859             bfd_elf_generic_reloc, /* */
860             "R_SH_TLS_LD_32",      /* name */
861             TRUE,                  /* partial_inplace */
862             0xffffffff,            /* src_mask */
863             0xffffffff,            /* dst_mask */
864             FALSE),                /* pcrel_offset */
865    
866      HOWTO (R_SH_TLS_LDO_32,       /* type */
867             0,                     /* rightshift */
868             2,                     /* size (0 = byte, 1 = short, 2 = long) */
869             32,                    /* bitsize */
870             FALSE,                 /* pc_relative */
871             0,                     /* bitpos */
872             complain_overflow_bitfield, /* complain_on_overflow */
873             bfd_elf_generic_reloc, /* */
874             "R_SH_TLS_LDO_32",     /* name */
875             TRUE,                  /* partial_inplace */
876             0xffffffff,            /* src_mask */
877             0xffffffff,            /* dst_mask */
878             FALSE),                /* pcrel_offset */
879    
880      HOWTO (R_SH_TLS_IE_32,        /* type */
881             0,                     /* rightshift */
882             2,                     /* size (0 = byte, 1 = short, 2 = long) */
883             32,                    /* bitsize */
884             FALSE,                 /* pc_relative */
885             0,                     /* bitpos */
886             complain_overflow_bitfield, /* complain_on_overflow */
887             bfd_elf_generic_reloc, /* */
888             "R_SH_TLS_IE_32",      /* name */
889             TRUE,                  /* partial_inplace */
890             0xffffffff,            /* src_mask */
891             0xffffffff,            /* dst_mask */
892             FALSE),                /* pcrel_offset */
893    
894      HOWTO (R_SH_TLS_LE_32,        /* type */
895             0,                     /* rightshift */
896             2,                     /* size (0 = byte, 1 = short, 2 = long) */
897             32,                    /* bitsize */
898             FALSE,                 /* pc_relative */
899             0,                     /* bitpos */
900             complain_overflow_bitfield, /* complain_on_overflow */
901             bfd_elf_generic_reloc, /* */
902             "R_SH_TLS_LE_32",      /* name */
903             TRUE,                  /* partial_inplace */
904             0xffffffff,            /* src_mask */
905             0xffffffff,            /* dst_mask */
906             FALSE),                /* pcrel_offset */
907    
908      HOWTO (R_SH_TLS_DTPMOD32,     /* type */
909             0,                     /* rightshift */
910             2,                     /* size (0 = byte, 1 = short, 2 = long) */
911             32,                    /* bitsize */
912             FALSE,                 /* pc_relative */
913             0,                     /* bitpos */
914             complain_overflow_bitfield, /* complain_on_overflow */
915             bfd_elf_generic_reloc, /* */
916             "R_SH_TLS_DTPMOD32",   /* name */
917             TRUE,                  /* partial_inplace */
918             0xffffffff,            /* src_mask */
919             0xffffffff,            /* dst_mask */
920             FALSE),                /* pcrel_offset */
921    
922      HOWTO (R_SH_TLS_DTPOFF32,     /* type */
923             0,                     /* rightshift */
924             2,                     /* size (0 = byte, 1 = short, 2 = long) */
925             32,                    /* bitsize */
926             FALSE,                 /* pc_relative */
927             0,                     /* bitpos */
928             complain_overflow_bitfield, /* complain_on_overflow */
929             bfd_elf_generic_reloc, /* */
930             "R_SH_TLS_DTPOFF32",   /* name */
931             TRUE,                  /* partial_inplace */
932             0xffffffff,            /* src_mask */
933             0xffffffff,            /* dst_mask */
934             FALSE),                /* pcrel_offset */
935    
936      HOWTO (R_SH_TLS_TPOFF32,      /* type */
937             0,                     /* rightshift */
938             2,                     /* size (0 = byte, 1 = short, 2 = long) */
939             32,                    /* bitsize */
940             FALSE,                 /* pc_relative */
941             0,                     /* bitpos */
942             complain_overflow_bitfield, /* complain_on_overflow */
943             bfd_elf_generic_reloc, /* */
944             "R_SH_TLS_TPOFF32",    /* name */
945             TRUE,                  /* partial_inplace */
946             0xffffffff,            /* src_mask */
947             0xffffffff,            /* dst_mask */
948             FALSE),                /* pcrel_offset */
949    
950    EMPTY_HOWTO (152),    EMPTY_HOWTO (152),
951    EMPTY_HOWTO (153),    EMPTY_HOWTO (153),
952    EMPTY_HOWTO (154),    EMPTY_HOWTO (154),
# Line 725  static reloc_howto_type sh_elf_howto_tab Line 960  static reloc_howto_type sh_elf_howto_tab
960           0,                     /* rightshift */           0,                     /* rightshift */
961           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
962           32,                    /* bitsize */           32,                    /* bitsize */
963           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
964           0,                     /* bitpos */           0,                     /* bitpos */
965           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
966           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
967           "R_SH_GOT32",          /* name */           "R_SH_GOT32",          /* name */
968           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
969           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
970           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
971           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
972    
973    HOWTO (R_SH_PLT32,            /* type */    HOWTO (R_SH_PLT32,            /* type */
974           0,                     /* rightshift */           0,                     /* rightshift */
975           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
976           32,                    /* bitsize */           32,                    /* bitsize */
977           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
978           0,                     /* bitpos */           0,                     /* bitpos */
979           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
980           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
981           "R_SH_PLT32",          /* name */           "R_SH_PLT32",          /* name */
982           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
983           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
984           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
985           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
986    
987    HOWTO (R_SH_COPY,             /* type */    HOWTO (R_SH_COPY,             /* type */
988           0,                     /* rightshift */           0,                     /* rightshift */
989           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
990           32,                    /* bitsize */           32,                    /* bitsize */
991           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
992           0,                     /* bitpos */           0,                     /* bitpos */
993           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
994           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
995           "R_SH_COPY",           /* name */           "R_SH_COPY",           /* name */
996           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
997           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
998           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
999           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1000    
1001    HOWTO (R_SH_GLOB_DAT,         /* type */    HOWTO (R_SH_GLOB_DAT,         /* type */
1002           0,                     /* rightshift */           0,                     /* rightshift */
1003           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1004           32,                    /* bitsize */           32,                    /* bitsize */
1005           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1006           0,                     /* bitpos */           0,                     /* bitpos */
1007           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
1008           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
1009           "R_SH_GLOB_DAT",       /* name */           "R_SH_GLOB_DAT",       /* name */
1010           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
1011           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
1012           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
1013           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1014    
1015    HOWTO (R_SH_JMP_SLOT,         /* type */    HOWTO (R_SH_JMP_SLOT,         /* type */
1016           0,                     /* rightshift */           0,                     /* rightshift */
1017           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1018           32,                    /* bitsize */           32,                    /* bitsize */
1019           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1020           0,                     /* bitpos */           0,                     /* bitpos */
1021           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
1022           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
1023           "R_SH_JMP_SLOT",       /* name */           "R_SH_JMP_SLOT",       /* name */
1024           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
1025           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
1026           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
1027           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1028    
1029    HOWTO (R_SH_RELATIVE,         /* type */    HOWTO (R_SH_RELATIVE,         /* type */
1030           0,                     /* rightshift */           0,                     /* rightshift */
1031           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1032           32,                    /* bitsize */           32,                    /* bitsize */
1033           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1034           0,                     /* bitpos */           0,                     /* bitpos */
1035           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
1036           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
1037           "R_SH_RELATIVE",       /* name */           "R_SH_RELATIVE",       /* name */
1038           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
1039           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
1040           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
1041           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1042    
1043    HOWTO (R_SH_GOTOFF,           /* type */    HOWTO (R_SH_GOTOFF,           /* type */
1044           0,                     /* rightshift */           0,                     /* rightshift */
1045           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1046           32,                    /* bitsize */           32,                    /* bitsize */
1047           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1048           0,                     /* bitpos */           0,                     /* bitpos */
1049           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
1050           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
1051           "R_SH_GOTOFF",         /* name */           "R_SH_GOTOFF",         /* name */
1052           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
1053           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
1054           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
1055           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1056    
1057    HOWTO (R_SH_GOTPC,            /* type */    HOWTO (R_SH_GOTPC,            /* type */
1058           0,                     /* rightshift */           0,                     /* rightshift */
1059           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1060           32,                    /* bitsize */           32,                    /* bitsize */
1061           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1062           0,                     /* bitpos */           0,                     /* bitpos */
1063           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
1064           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
1065           "R_SH_GOTPC",          /* name */           "R_SH_GOTPC",          /* name */
1066           true,                  /* partial_inplace */           TRUE,                  /* partial_inplace */
1067           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
1068           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
1069           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1070    
1071    HOWTO (R_SH_GOTPLT32,         /* type */    HOWTO (R_SH_GOTPLT32,         /* type */
1072           0,                     /* rightshift */           0,                     /* rightshift */
1073           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1074           32,                    /* bitsize */           32,                    /* bitsize */
1075           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1076           0,                     /* bitpos */           0,                     /* bitpos */
1077           complain_overflow_bitfield, /* complain_on_overflow */           complain_overflow_bitfield, /* complain_on_overflow */
1078           bfd_elf_generic_reloc, /* */           bfd_elf_generic_reloc, /* */
1079           "R_SH_GOTPLT32",       /* name */           "R_SH_GOTPLT32",       /* name */
1080           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1081           0xffffffff,            /* src_mask */           0xffffffff,            /* src_mask */
1082           0xffffffff,            /* dst_mask */           0xffffffff,            /* dst_mask */
1083           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1084    
1085  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
1086    /* Used in MOVI and SHORI (x & 65536).  */    /* Used in MOVI and SHORI (x & 65536).  */
# Line 853  static reloc_howto_type sh_elf_howto_tab Line 1088  static reloc_howto_type sh_elf_howto_tab
1088           0,                     /* rightshift */           0,                     /* rightshift */
1089           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1090           64,                    /* bitsize */           64,                    /* bitsize */
1091           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1092           10,                    /* bitpos */           10,                    /* bitpos */
1093           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1094           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1095           "R_SH_GOT_LOW16",      /* name */           "R_SH_GOT_LOW16",      /* name */
1096           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1097           0,                     /* src_mask */           0,                     /* src_mask */
1098           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1099           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1100    
1101    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1102    HOWTO (R_SH_GOT_MEDLOW16,     /* type */    HOWTO (R_SH_GOT_MEDLOW16,     /* type */
1103           16,                    /* rightshift */           16,                    /* rightshift */
1104           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1105           64,                    /* bitsize */           64,                    /* bitsize */
1106           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1107           10,                    /* bitpos */           10,                    /* bitpos */
1108           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1109           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1110           "R_SH_GOT_MEDLOW16",   /* name */           "R_SH_GOT_MEDLOW16",   /* name */
1111           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1112           0,                     /* src_mask */           0,                     /* src_mask */
1113           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1114           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1115    
1116    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1117    HOWTO (R_SH_GOT_MEDHI16,      /* type */    HOWTO (R_SH_GOT_MEDHI16,      /* type */
1118           32,                    /* rightshift */           32,                    /* rightshift */
1119           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1120           64,                    /* bitsize */           64,                    /* bitsize */
1121           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1122           10,                    /* bitpos */           10,                    /* bitpos */
1123           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1124           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1125           "R_SH_GOT_MEDHI16",    /* name */           "R_SH_GOT_MEDHI16",    /* name */
1126           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1127           0,                     /* src_mask */           0,                     /* src_mask */
1128           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1129           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1130    
1131    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1132    HOWTO (R_SH_GOT_HI16,         /* type */    HOWTO (R_SH_GOT_HI16,         /* type */
1133           48,                    /* rightshift */           48,                    /* rightshift */
1134           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1135           64,                    /* bitsize */           64,                    /* bitsize */
1136           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1137           10,                    /* bitpos */           10,                    /* bitpos */
1138           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1139           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1140           "R_SH_GOT_HI16",       /* name */           "R_SH_GOT_HI16",       /* name */
1141           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1142           0,                     /* src_mask */           0,                     /* src_mask */
1143           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1144           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1145    
1146    /* Used in MOVI and SHORI (x & 65536).  */    /* Used in MOVI and SHORI (x & 65536).  */
1147    HOWTO (R_SH_GOTPLT_LOW16,     /* type */    HOWTO (R_SH_GOTPLT_LOW16,     /* type */
1148           0,                     /* rightshift */           0,                     /* rightshift */
1149           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1150           64,                    /* bitsize */           64,                    /* bitsize */
1151           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1152           10,                    /* bitpos */           10,                    /* bitpos */
1153           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1154           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1155           "R_SH_GOTPLT_LOW16",   /* name */           "R_SH_GOTPLT_LOW16",   /* name */
1156           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1157           0,                     /* src_mask */           0,                     /* src_mask */
1158           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1159           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1160    
1161    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1162    HOWTO (R_SH_GOTPLT_MEDLOW16,  /* type */    HOWTO (R_SH_GOTPLT_MEDLOW16,  /* type */
1163           16,                    /* rightshift */           16,                    /* rightshift */
1164           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1165           64,                    /* bitsize */           64,                    /* bitsize */
1166           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1167           10,                    /* bitpos */           10,                    /* bitpos */
1168           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1169           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1170           "R_SH_GOTPLT_MEDLOW16", /* name */           "R_SH_GOTPLT_MEDLOW16", /* name */
1171           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1172           0,                     /* src_mask */           0,                     /* src_mask */
1173           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1174           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1175    
1176    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1177    HOWTO (R_SH_GOTPLT_MEDHI16,   /* type */    HOWTO (R_SH_GOTPLT_MEDHI16,   /* type */
1178           32,                    /* rightshift */           32,                    /* rightshift */
1179           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1180           64,                    /* bitsize */           64,                    /* bitsize */
1181           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1182           10,                    /* bitpos */           10,                    /* bitpos */
1183           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1184           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1185           "R_SH_GOTPLT_MEDHI16", /* name */           "R_SH_GOTPLT_MEDHI16", /* name */
1186           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1187           0,                     /* src_mask */           0,                     /* src_mask */
1188           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1189           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1190    
1191    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1192    HOWTO (R_SH_GOTPLT_HI16,      /* type */    HOWTO (R_SH_GOTPLT_HI16,      /* type */
1193           48,                    /* rightshift */           48,                    /* rightshift */
1194           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1195           64,                    /* bitsize */           64,                    /* bitsize */
1196           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1197           10,                    /* bitpos */           10,                    /* bitpos */
1198           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1199           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1200           "R_SH_GOTPLT_HI16",    /* name */           "R_SH_GOTPLT_HI16",    /* name */
1201           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1202           0,                     /* src_mask */           0,                     /* src_mask */
1203           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1204           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1205    
1206    /* Used in MOVI and SHORI (x & 65536).  */    /* Used in MOVI and SHORI (x & 65536).  */
1207    HOWTO (R_SH_PLT_LOW16,        /* type */    HOWTO (R_SH_PLT_LOW16,        /* type */
1208           0,                     /* rightshift */           0,                     /* rightshift */
1209           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1210           64,                    /* bitsize */           64,                    /* bitsize */
1211           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1212           10,                    /* bitpos */           10,                    /* bitpos */
1213           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1214           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1215           "R_SH_PLT_LOW16",      /* name */           "R_SH_PLT_LOW16",      /* name */
1216           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1217           0,                     /* src_mask */           0,                     /* src_mask */
1218           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1219           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1220    
1221    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1222    HOWTO (R_SH_PLT_MEDLOW16,     /* type */    HOWTO (R_SH_PLT_MEDLOW16,     /* type */
1223           16,                    /* rightshift */           16,                    /* rightshift */
1224           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1225           64,                    /* bitsize */           64,                    /* bitsize */
1226           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1227           10,                    /* bitpos */           10,                    /* bitpos */
1228           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1229           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1230           "R_SH_PLT_MEDLOW16",   /* name */           "R_SH_PLT_MEDLOW16",   /* name */
1231           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1232           0,                     /* src_mask */           0,                     /* src_mask */
1233           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1234           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1235    
1236    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1237    HOWTO (R_SH_PLT_MEDHI16,      /* type */    HOWTO (R_SH_PLT_MEDHI16,      /* type */
1238           32,                    /* rightshift */           32,                    /* rightshift */
1239           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1240           64,                    /* bitsize */           64,                    /* bitsize */
1241           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1242           10,                    /* bitpos */           10,                    /* bitpos */
1243           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1244           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1245           "R_SH_PLT_MEDHI16",    /* name */           "R_SH_PLT_MEDHI16",    /* name */
1246           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1247           0,                     /* src_mask */           0,                     /* src_mask */
1248           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1249           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1250    
1251    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1252    HOWTO (R_SH_PLT_HI16,         /* type */    HOWTO (R_SH_PLT_HI16,         /* type */
1253           48,                    /* rightshift */           48,                    /* rightshift */
1254           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1255           64,                    /* bitsize */           64,                    /* bitsize */
1256           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1257           10,                    /* bitpos */           10,                    /* bitpos */
1258           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1259           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1260           "R_SH_PLT_HI16",       /* name */           "R_SH_PLT_HI16",       /* name */
1261           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1262           0,                     /* src_mask */           0,                     /* src_mask */
1263           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1264           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1265    
1266    /* Used in MOVI and SHORI (x & 65536).  */    /* Used in MOVI and SHORI (x & 65536).  */
1267    HOWTO (R_SH_GOTOFF_LOW16,     /* type */    HOWTO (R_SH_GOTOFF_LOW16,     /* type */
1268           0,                     /* rightshift */           0,                     /* rightshift */
1269           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1270           64,                    /* bitsize */           64,                    /* bitsize */
1271           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1272           10,                    /* bitpos */           10,                    /* bitpos */
1273           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1274           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1275           "R_SH_GOTOFF_LOW16",   /* name */           "R_SH_GOTOFF_LOW16",   /* name */
1276           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1277           0,                     /* src_mask */           0,                     /* src_mask */
1278           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1279           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1280    
1281    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1282    HOWTO (R_SH_GOTOFF_MEDLOW16,  /* type */    HOWTO (R_SH_GOTOFF_MEDLOW16,  /* type */
1283           16,                    /* rightshift */           16,                    /* rightshift */
1284           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1285           64,                    /* bitsize */           64,                    /* bitsize */
1286           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1287           10,                    /* bitpos */           10,                    /* bitpos */
1288           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1289           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1290           "R_SH_GOTOFF_MEDLOW16", /* name */           "R_SH_GOTOFF_MEDLOW16", /* name */
1291           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1292           0,                     /* src_mask */           0,                     /* src_mask */
1293           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1294           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1295    
1296    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1297    HOWTO (R_SH_GOTOFF_MEDHI16,   /* type */    HOWTO (R_SH_GOTOFF_MEDHI16,   /* type */
1298           32,                    /* rightshift */           32,                    /* rightshift */
1299           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1300           64,                    /* bitsize */           64,                    /* bitsize */
1301           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1302           10,                    /* bitpos */           10,                    /* bitpos */
1303           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1304           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1305           "R_SH_GOTOFF_MEDHI16", /* name */           "R_SH_GOTOFF_MEDHI16", /* name */
1306           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1307           0,                     /* src_mask */           0,                     /* src_mask */
1308           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1309           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1310    
1311    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1312    HOWTO (R_SH_GOTOFF_HI16,      /* type */    HOWTO (R_SH_GOTOFF_HI16,      /* type */
1313           48,                    /* rightshift */           48,                    /* rightshift */
1314           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1315           64,                    /* bitsize */           64,                    /* bitsize */
1316           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1317           10,                    /* bitpos */           10,                    /* bitpos */
1318           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1319           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1320           "R_SH_GOTOFF_HI16",    /* name */           "R_SH_GOTOFF_HI16",    /* name */
1321           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1322           0,                     /* src_mask */           0,                     /* src_mask */
1323           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1324           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1325    
1326    /* Used in MOVI and SHORI (x & 65536).  */    /* Used in MOVI and SHORI (x & 65536).  */
1327    HOWTO (R_SH_GOTPC_LOW16,      /* type */    HOWTO (R_SH_GOTPC_LOW16,      /* type */
1328           0,                     /* rightshift */           0,                     /* rightshift */
1329           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1330           64,                    /* bitsize */           64,                    /* bitsize */
1331           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1332           10,                    /* bitpos */           10,                    /* bitpos */
1333           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1334           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1335           "R_SH_GOTPC_LOW16",    /* name */           "R_SH_GOTPC_LOW16",    /* name */
1336           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1337           0,                     /* src_mask */           0,                     /* src_mask */
1338           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1339           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1340    
1341    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1342    HOWTO (R_SH_GOTPC_MEDLOW16,   /* type */    HOWTO (R_SH_GOTPC_MEDLOW16,   /* type */
1343           16,                    /* rightshift */           16,                    /* rightshift */
1344           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1345           64,                    /* bitsize */           64,                    /* bitsize */
1346           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1347           10,                    /* bitpos */           10,                    /* bitpos */
1348           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1349           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1350           "R_SH_GOTPC_MEDLOW16", /* name */           "R_SH_GOTPC_MEDLOW16", /* name */
1351           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1352           0,                     /* src_mask */           0,                     /* src_mask */
1353           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1354           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1355    
1356    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1357    HOWTO (R_SH_GOTPC_MEDHI16,    /* type */    HOWTO (R_SH_GOTPC_MEDHI16,    /* type */
1358           32,                    /* rightshift */           32,                    /* rightshift */
1359           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1360           64,                    /* bitsize */           64,                    /* bitsize */
1361           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1362           10,                    /* bitpos */           10,                    /* bitpos */
1363           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1364           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1365           "R_SH_GOTPC_MEDHI16",  /* name */           "R_SH_GOTPC_MEDHI16",  /* name */
1366           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1367           0,                     /* src_mask */           0,                     /* src_mask */
1368           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1369           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1370    
1371    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1372    HOWTO (R_SH_GOTPC_HI16,       /* type */    HOWTO (R_SH_GOTPC_HI16,       /* type */
1373           48,                    /* rightshift */           48,                    /* rightshift */
1374           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1375           64,                    /* bitsize */           64,                    /* bitsize */
1376           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1377           10,                    /* bitpos */           10,                    /* bitpos */
1378           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1379           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1380           "R_SH_GOTPC_HI16",     /* name */           "R_SH_GOTPC_HI16",     /* name */
1381           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1382           0,                     /* src_mask */           0,                     /* src_mask */
1383           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1384           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1385    
1386    /* Used in LD.L, FLD.S et al.  */    /* Used in LD.L, FLD.S et al.  */
1387    HOWTO (R_SH_GOT10BY4,         /* type */    HOWTO (R_SH_GOT10BY4,         /* type */
1388           2,                     /* rightshift */           2,                     /* rightshift */
1389           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1390           12,                    /* bitsize */           12,                    /* bitsize */
1391           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1392           10,                    /* bitpos */           10,                    /* bitpos */
1393           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
1394           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1395           "R_SH_GOT10BY4",       /* name */           "R_SH_GOT10BY4",       /* name */
1396           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1397           0,                     /* src_mask */           0,                     /* src_mask */
1398           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
1399           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1400    
1401    /* Used in LD.L, FLD.S et al.  */    /* Used in LD.L, FLD.S et al.  */
1402    HOWTO (R_SH_GOTPLT10BY4,      /* type */    HOWTO (R_SH_GOTPLT10BY4,      /* type */
1403           2,                     /* rightshift */           2,                     /* rightshift */
1404           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1405           12,                    /* bitsize */           12,                    /* bitsize */
1406           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1407           10,                    /* bitpos */           10,                    /* bitpos */
1408           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
1409           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1410           "R_SH_GOTPLT10BY4",    /* name */           "R_SH_GOTPLT10BY4",    /* name */
1411           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1412           0,                     /* src_mask */           0,                     /* src_mask */
1413           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
1414           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1415    
1416    /* Used in FLD.D, FST.P et al.  */    /* Used in FLD.D, FST.P et al.  */
1417    HOWTO (R_SH_GOT10BY8,         /* type */    HOWTO (R_SH_GOT10BY8,         /* type */
1418           3,                     /* rightshift */           3,                     /* rightshift */
1419           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1420           13,                    /* bitsize */           13,                    /* bitsize */
1421           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1422           10,                    /* bitpos */           10,                    /* bitpos */
1423           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
1424           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1425           "R_SH_GOT10BY8",       /* name */           "R_SH_GOT10BY8",       /* name */
1426           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1427           0,                     /* src_mask */           0,                     /* src_mask */
1428           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
1429           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1430    
1431    /* Used in FLD.D, FST.P et al.  */    /* Used in FLD.D, FST.P et al.  */
1432    HOWTO (R_SH_GOTPLT10BY8,      /* type */    HOWTO (R_SH_GOTPLT10BY8,      /* type */
1433           3,                     /* rightshift */           3,                     /* rightshift */
1434           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1435           13,                    /* bitsize */           13,                    /* bitsize */
1436           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1437           10,                    /* bitpos */           10,                    /* bitpos */
1438           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
1439           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1440           "R_SH_GOTPLT10BY8",    /* name */           "R_SH_GOTPLT10BY8",    /* name */
1441           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1442           0,                     /* src_mask */           0,                     /* src_mask */
1443           0xffc00,               /* dst_mask */           0xffc00,               /* dst_mask */
1444           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1445    
1446    HOWTO (R_SH_COPY64,           /* type */    HOWTO (R_SH_COPY64,           /* type */
1447           0,                     /* rightshift */           0,                     /* rightshift */
1448           4,                     /* size (0 = byte, 1 = short, 2 = long) */           4,                     /* size (0 = byte, 1 = short, 2 = long) */
1449           64,                    /* bitsize */           64,                    /* bitsize */
1450           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1451           0,                     /* bitpos */           0,                     /* bitpos */
1452           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1453           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1454           "R_SH_COPY64",         /* name */           "R_SH_COPY64",         /* name */
1455           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1456           0,                     /* src_mask */           0,                     /* src_mask */
1457           ((bfd_vma) 0) - 1,     /* dst_mask */           ((bfd_vma) 0) - 1,     /* dst_mask */
1458           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1459    
1460    HOWTO (R_SH_GLOB_DAT64,       /* type */    HOWTO (R_SH_GLOB_DAT64,       /* type */
1461           0,                     /* rightshift */           0,                     /* rightshift */
1462           4,                     /* size (0 = byte, 1 = short, 2 = long) */           4,                     /* size (0 = byte, 1 = short, 2 = long) */
1463           64,                    /* bitsize */           64,                    /* bitsize */
1464           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1465           0,                     /* bitpos */           0,                     /* bitpos */
1466           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1467           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1468           "R_SH_GLOB_DAT64",     /* name */           "R_SH_GLOB_DAT64",     /* name */
1469           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1470           0,                     /* src_mask */           0,                     /* src_mask */
1471           ((bfd_vma) 0) - 1,     /* dst_mask */           ((bfd_vma) 0) - 1,     /* dst_mask */
1472           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1473    
1474    HOWTO (R_SH_JMP_SLOT64,       /* type */    HOWTO (R_SH_JMP_SLOT64,       /* type */
1475           0,                     /* rightshift */           0,                     /* rightshift */
1476           4,                     /* size (0 = byte, 1 = short, 2 = long) */           4,                     /* size (0 = byte, 1 = short, 2 = long) */
1477           64,                    /* bitsize */           64,                    /* bitsize */
1478           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1479           0,                     /* bitpos */           0,                     /* bitpos */
1480           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1481           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1482           "R_SH_JMP_SLOT64",     /* name */           "R_SH_JMP_SLOT64",     /* name */
1483           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1484           0,                     /* src_mask */           0,                     /* src_mask */
1485           ((bfd_vma) 0) - 1,     /* dst_mask */           ((bfd_vma) 0) - 1,     /* dst_mask */
1486           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1487    
1488    HOWTO (R_SH_RELATIVE64,       /* type */    HOWTO (R_SH_RELATIVE64,       /* type */
1489           0,                     /* rightshift */           0,                     /* rightshift */
1490           4,                     /* size (0 = byte, 1 = short, 2 = long) */           4,                     /* size (0 = byte, 1 = short, 2 = long) */
1491           64,                    /* bitsize */           64,                    /* bitsize */
1492           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1493           0,                     /* bitpos */           0,                     /* bitpos */
1494           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1495           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1496           "R_SH_RELATIVE64",     /* name */           "R_SH_RELATIVE64",     /* name */
1497           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1498           0,                     /* src_mask */           0,                     /* src_mask */
1499           ((bfd_vma) 0) - 1,     /* dst_mask */           ((bfd_vma) 0) - 1,     /* dst_mask */
1500           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1501    
1502    EMPTY_HOWTO (197),    EMPTY_HOWTO (197),
1503    EMPTY_HOWTO (198),    EMPTY_HOWTO (198),
# Line 1323  static reloc_howto_type sh_elf_howto_tab Line 1558  static reloc_howto_type sh_elf_howto_tab
1558           0,                     /* rightshift */           0,                     /* rightshift */
1559           1,                     /* size (0 = byte, 1 = short, 2 = long) */           1,                     /* size (0 = byte, 1 = short, 2 = long) */
1560           0,                     /* bitsize */           0,                     /* bitsize */
1561           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1562           0,                     /* bitpos */           0,                     /* bitpos */
1563           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
1564           sh_elf_ignore_reloc,   /* special_function */           sh_elf_ignore_reloc,   /* special_function */
1565           "R_SH_SHMEDIA_CODE",   /* name */           "R_SH_SHMEDIA_CODE",   /* name */
1566           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1567           0,                     /* src_mask */           0,                     /* src_mask */
1568           0,                     /* dst_mask */           0,                     /* dst_mask */
1569           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1570    
1571    /* The assembler will generate this reloc at a PTA or PTB instruction,    /* The assembler will generate this reloc at a PTA or PTB instruction,
1572       and the linker checks the right type of target, or changes a PTA to a       and the linker checks the right type of target, or changes a PTA to a
# Line 1340  static reloc_howto_type sh_elf_howto_tab Line 1575  static reloc_howto_type sh_elf_howto_tab
1575           2,                     /* rightshift */           2,                     /* rightshift */
1576           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1577           18,                    /* bitsize */           18,                    /* bitsize */
1578           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1579           10,                    /* bitpos */           10,                    /* bitpos */
1580           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
1581           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1582           "R_SH_PT_16",          /* name */           "R_SH_PT_16",          /* name */
1583           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1584           0,                     /* src_mask */           0,                     /* src_mask */
1585           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1586           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1587    
1588    /* Used in unexpanded MOVI.  */    /* Used in unexpanded MOVI.  */
1589    HOWTO (R_SH_IMMS16,           /* type */    HOWTO (R_SH_IMMS16,           /* type */
1590           0,                     /* rightshift */           0,                     /* rightshift */
1591           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1592           16,                    /* bitsize */           16,                    /* bitsize */
1593           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1594           10,                    /* bitpos */           10,                    /* bitpos */
1595           complain_overflow_signed, /* complain_on_overflow */           complain_overflow_signed, /* complain_on_overflow */
1596           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1597           "R_SH_IMMS16",         /* name */           "R_SH_IMMS16",         /* name */
1598           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1599           0,                     /* src_mask */           0,                     /* src_mask */
1600           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1601           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1602    
1603    /* Used in SHORI.  */    /* Used in SHORI.  */
1604    HOWTO (R_SH_IMMU16,           /* type */    HOWTO (R_SH_IMMU16,           /* type */
1605           0,                     /* rightshift */           0,                     /* rightshift */
1606           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1607           16,                    /* bitsize */           16,                    /* bitsize */
1608           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1609           10,                    /* bitpos */           10,                    /* bitpos */
1610           complain_overflow_unsigned, /* complain_on_overflow */           complain_overflow_unsigned, /* complain_on_overflow */
1611           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1612           "R_SH_IMMU16",         /* name */           "R_SH_IMMU16",         /* name */
1613           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1614           0,                     /* src_mask */           0,                     /* src_mask */
1615           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1616           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1617    
1618    /* Used in MOVI and SHORI (x & 65536).  */    /* Used in MOVI and SHORI (x & 65536).  */
1619    HOWTO (R_SH_IMM_LOW16,        /* type */    HOWTO (R_SH_IMM_LOW16,        /* type */
1620           0,                     /* rightshift */           0,                     /* rightshift */
1621           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1622           64,                    /* bitsize */           64,                    /* bitsize */
1623           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1624           10,                    /* bitpos */           10,                    /* bitpos */
1625           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1626           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1627           "R_SH_IMM_LOW16",      /* name */           "R_SH_IMM_LOW16",      /* name */
1628           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1629           0,                     /* src_mask */           0,                     /* src_mask */
1630           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1631           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1632    
1633    /* Used in MOVI and SHORI ((x - $) & 65536).  */    /* Used in MOVI and SHORI ((x - $) & 65536).  */
1634    HOWTO (R_SH_IMM_LOW16_PCREL,  /* type */    HOWTO (R_SH_IMM_LOW16_PCREL,  /* type */
1635           0,                     /* rightshift */           0,                     /* rightshift */
1636           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1637           64,                    /* bitsize */           64,                    /* bitsize */
1638           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1639           10,                    /* bitpos */           10,                    /* bitpos */
1640           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1641           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1642           "R_SH_IMM_LOW16_PCREL", /* name */           "R_SH_IMM_LOW16_PCREL", /* name */
1643           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1644           0,                     /* src_mask */           0,                     /* src_mask */
1645           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1646           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1647    
1648    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */    /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1649    HOWTO (R_SH_IMM_MEDLOW16,     /* type */    HOWTO (R_SH_IMM_MEDLOW16,     /* type */
1650           16,                    /* rightshift */           16,                    /* rightshift */
1651           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1652           64,                    /* bitsize */           64,                    /* bitsize */
1653           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1654           10,                    /* bitpos */           10,                    /* bitpos */
1655           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1656           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1657           "R_SH_IMM_MEDLOW16",   /* name */           "R_SH_IMM_MEDLOW16",   /* name */
1658           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1659           0,                     /* src_mask */           0,                     /* src_mask */
1660           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1661           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1662    
1663    /* Used in MOVI and SHORI (((x - $) >> 16) & 65536).  */    /* Used in MOVI and SHORI (((x - $) >> 16) & 65536).  */
1664    HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */    HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1665           16,                    /* rightshift */           16,                    /* rightshift */
1666           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1667           64,                    /* bitsize */           64,                    /* bitsize */
1668           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1669           10,                    /* bitpos */           10,                    /* bitpos */
1670           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1671           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1672           "R_SH_IMM_MEDLOW16_PCREL", /* name */           "R_SH_IMM_MEDLOW16_PCREL", /* name */
1673           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1674           0,                     /* src_mask */           0,                     /* src_mask */
1675           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1676           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1677    
1678    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */    /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1679    HOWTO (R_SH_IMM_MEDHI16,      /* type */    HOWTO (R_SH_IMM_MEDHI16,      /* type */
1680           32,                    /* rightshift */           32,                    /* rightshift */
1681           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1682           64,                    /* bitsize */           64,                    /* bitsize */
1683           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1684           10,                    /* bitpos */           10,                    /* bitpos */
1685           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1686           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1687           "R_SH_IMM_MEDHI16",    /* name */           "R_SH_IMM_MEDHI16",    /* name */
1688           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1689           0,                     /* src_mask */           0,                     /* src_mask */
1690           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1691           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1692    
1693    /* Used in MOVI and SHORI (((x - $) >> 32) & 65536).  */    /* Used in MOVI and SHORI (((x - $) >> 32) & 65536).  */
1694    HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */    HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1695           32,                    /* rightshift */           32,                    /* rightshift */
1696           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1697           64,                    /* bitsize */           64,                    /* bitsize */
1698           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1699           10,                    /* bitpos */           10,                    /* bitpos */
1700           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1701           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1702           "R_SH_IMM_MEDHI16_PCREL", /* name */           "R_SH_IMM_MEDHI16_PCREL", /* name */
1703           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1704           0,                     /* src_mask */           0,                     /* src_mask */
1705           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1706           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1707    
1708    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */    /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1709    HOWTO (R_SH_IMM_HI16,         /* type */    HOWTO (R_SH_IMM_HI16,         /* type */
1710           48,                    /* rightshift */           48,                    /* rightshift */
1711           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1712           64,                    /* bitsize */           64,                    /* bitsize */
1713           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1714           10,                    /* bitpos */           10,                    /* bitpos */
1715           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1716           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1717           "R_SH_IMM_HI16",       /* name */           "R_SH_IMM_HI16",       /* name */
1718           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1719           0,                     /* src_mask */           0,                     /* src_mask */
1720           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1721           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1722    
1723    /* Used in MOVI and SHORI (((x - $) >> 48) & 65536).  */    /* Used in MOVI and SHORI (((x - $) >> 48) & 65536).  */
1724    HOWTO (R_SH_IMM_HI16_PCREL,   /* type */    HOWTO (R_SH_IMM_HI16_PCREL,   /* type */
1725           48,                    /* rightshift */           48,                    /* rightshift */
1726           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1727           64,                    /* bitsize */           64,                    /* bitsize */
1728           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1729           10,                    /* bitpos */           10,                    /* bitpos */
1730           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1731           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1732           "R_SH_IMM_HI16_PCREL", /* name */           "R_SH_IMM_HI16_PCREL", /* name */
1733           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1734           0,                     /* src_mask */           0,                     /* src_mask */
1735           0x3fffc00,             /* dst_mask */           0x3fffc00,             /* dst_mask */
1736           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1737    
1738    /* For the .uaquad pseudo.  */    /* For the .uaquad pseudo.  */
1739    HOWTO (R_SH_64,               /* type */    HOWTO (R_SH_64,               /* type */
1740           0,                     /* rightshift */           0,                     /* rightshift */
1741           4,                     /* size (0 = byte, 1 = short, 2 = long) */           4,                     /* size (0 = byte, 1 = short, 2 = long) */
1742           64,                    /* bitsize */           64,                    /* bitsize */
1743           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
1744           0,                     /* bitpos */           0,                     /* bitpos */
1745           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1746           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1747           "R_SH_64",             /* name */           "R_SH_64",             /* name */
1748           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1749           0,                     /* src_mask */           0,                     /* src_mask */
1750           ((bfd_vma) 0) - 1,     /* dst_mask */           ((bfd_vma) 0) - 1,     /* dst_mask */
1751           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
1752    
1753    /* For the .uaquad pseudo, (x - $).  */    /* For the .uaquad pseudo, (x - $).  */
1754    HOWTO (R_SH_64_PCREL,         /* type */    HOWTO (R_SH_64_PCREL,         /* type */
1755           48,                    /* rightshift */           48,                    /* rightshift */
1756           2,                     /* size (0 = byte, 1 = short, 2 = long) */           2,                     /* size (0 = byte, 1 = short, 2 = long) */
1757           64,                    /* bitsize */           64,                    /* bitsize */
1758           true,                  /* pc_relative */           TRUE,                  /* pc_relative */
1759           10,                    /* bitpos */           10,                    /* bitpos */
1760           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
1761           bfd_elf_generic_reloc, /* special_function */           bfd_elf_generic_reloc, /* special_function */
1762           "R_SH_64_PCREL",       /* name */           "R_SH_64_PCREL",       /* name */
1763           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
1764           0,                     /* src_mask */           0,                     /* src_mask */
1765           ((bfd_vma) 0) - 1,     /* dst_mask */           ((bfd_vma) 0) - 1,     /* dst_mask */
1766           true),                 /* pcrel_offset */           TRUE),                 /* pcrel_offset */
1767    
1768  #endif  #endif
1769  };  };
1770    
1771  static bfd_reloc_status_type  static bfd_reloc_status_type
1772  sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr,  sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
1773                     symbol_section, start, end)                     asection *input_section, bfd_byte *contents,
1774       int r_type ATTRIBUTE_UNUSED;                     bfd_vma addr, asection *symbol_section,
1775       bfd *input_bfd;                     bfd_vma start, bfd_vma end)
      asection *input_section;  
      bfd_byte *contents;  
      bfd_vma addr;  
      asection *symbol_section;  
      bfd_vma start, end;  
1776  {  {
1777    static bfd_vma last_addr;    static bfd_vma last_addr;
1778    static asection *last_symbol_section;    static asection *last_symbol_section;
# Line 1552  sh_elf_reloc_loop (r_type, input_bfd, in Line 1782  sh_elf_reloc_loop (r_type, input_bfd, in
1782    int insn;    int insn;
1783    
1784    /* Sanity check the address.  */    /* Sanity check the address.  */
1785    if (addr > input_section->_raw_size)    if (addr > bfd_get_section_limit (input_bfd, input_section))
1786      return bfd_reloc_outofrange;      return bfd_reloc_outofrange;
1787    
1788    /* We require the start and end relocations to be processed consecutively -    /* We require the start and end relocations to be processed consecutively -
# Line 1577  sh_elf_reloc_loop (r_type, input_bfd, in Line 1807  sh_elf_reloc_loop (r_type, input_bfd, in
1807          contents = elf_section_data (symbol_section)->this_hdr.contents;          contents = elf_section_data (symbol_section)->this_hdr.contents;
1808        else        else
1809          {          {
1810            contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);            if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
1811            if (contents == NULL)                                             &contents))
             return bfd_reloc_outofrange;  
           if (! bfd_get_section_contents (input_bfd, symbol_section, contents,  
                                           (file_ptr) 0,  
                                           symbol_section->_raw_size))  
1812              {              {
1813                free (contents);                if (contents != NULL)
1814                    free (contents);
1815                return bfd_reloc_outofrange;                return bfd_reloc_outofrange;
1816              }              }
1817          }          }
# Line 1644  sh_elf_reloc_loop (r_type, input_bfd, in Line 1871  sh_elf_reloc_loop (r_type, input_bfd, in
1871     function, and is almost certainly incorrect for other ELF targets.  */     function, and is almost certainly incorrect for other ELF targets.  */
1872    
1873  static bfd_reloc_status_type  static bfd_reloc_status_type
1874  sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,  sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
1875                error_message)                void *data, asection *input_section, bfd *output_bfd,
1876       bfd *abfd;                char **error_message ATTRIBUTE_UNUSED)
      arelent *reloc_entry;  
      asymbol *symbol_in;  
      PTR data;  
      asection *input_section;  
      bfd *output_bfd;  
      char **error_message ATTRIBUTE_UNUSED;  
1877  {  {
1878    unsigned long insn;    unsigned long insn;
1879    bfd_vma sym_value;    bfd_vma sym_value;
# Line 1719  sh_elf_reloc (abfd, reloc_entry, symbol_ Line 1940  sh_elf_reloc (abfd, reloc_entry, symbol_
1940     which the linker should otherwise ignore.  */     which the linker should otherwise ignore.  */
1941    
1942  static bfd_reloc_status_type  static bfd_reloc_status_type
1943  sh_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,  sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1944                       output_bfd, error_message)                       asymbol *symbol ATTRIBUTE_UNUSED,
1945       bfd *abfd ATTRIBUTE_UNUSED;                       void *data ATTRIBUTE_UNUSED, asection *input_section,
1946       arelent *reloc_entry;                       bfd *output_bfd,
1947       asymbol *symbol ATTRIBUTE_UNUSED;                       char **error_message ATTRIBUTE_UNUSED)
      PTR data ATTRIBUTE_UNUSED;  
      asection *input_section;  
      bfd *output_bfd;  
      char **error_message ATTRIBUTE_UNUSED;  
1948  {  {
1949    if (output_bfd != NULL)    if (output_bfd != NULL)
1950      reloc_entry->address += input_section->output_offset;      reloc_entry->address += input_section->output_offset;
# Line 1748  static const struct elf_reloc_map sh_rel Line 1965  static const struct elf_reloc_map sh_rel
1965  {  {
1966    { BFD_RELOC_NONE, R_SH_NONE },    { BFD_RELOC_NONE, R_SH_NONE },
1967    { BFD_RELOC_32, R_SH_DIR32 },    { BFD_RELOC_32, R_SH_DIR32 },
1968      { BFD_RELOC_16, R_SH_DIR16 },
1969      { BFD_RELOC_8, R_SH_DIR8 },
1970    { BFD_RELOC_CTOR, R_SH_DIR32 },    { BFD_RELOC_CTOR, R_SH_DIR32 },
1971    { BFD_RELOC_32_PCREL, R_SH_REL32 },    { BFD_RELOC_32_PCREL, R_SH_REL32 },
1972    { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },    { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
# Line 1767  static const struct elf_reloc_map sh_rel Line 1986  static const struct elf_reloc_map sh_rel
1986    { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },    { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1987    { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },    { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
1988    { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },    { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
1989      { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
1990      { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
1991      { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
1992      { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
1993      { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
1994      { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
1995      { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
1996      { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
1997    { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },    { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
1998    { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },    { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
1999    { BFD_RELOC_SH_COPY, R_SH_COPY },    { BFD_RELOC_SH_COPY, R_SH_COPY },
# Line 1833  static const struct elf_reloc_map sh_rel Line 2060  static const struct elf_reloc_map sh_rel
2060     corresponding SH ELf reloc.  */     corresponding SH ELf reloc.  */
2061    
2062  static reloc_howto_type *  static reloc_howto_type *
2063  sh_elf_reloc_type_lookup (abfd, code)  sh_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2064       bfd *abfd ATTRIBUTE_UNUSED;                            bfd_reloc_code_real_type code)
      bfd_reloc_code_real_type code;  
2065  {  {
2066    unsigned int i;    unsigned int i;
2067    
# Line 1851  sh_elf_reloc_type_lookup (abfd, code) Line 2077  sh_elf_reloc_type_lookup (abfd, code)
2077  /* Given an ELF reloc, fill in the howto field of a relent.  */  /* Given an ELF reloc, fill in the howto field of a relent.  */
2078    
2079  static void  static void
2080  sh_elf_info_to_howto (abfd, cache_ptr, dst)  sh_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
2081       bfd *abfd ATTRIBUTE_UNUSED;                        Elf_Internal_Rela *dst)
      arelent *cache_ptr;  
      Elf_Internal_Rela *dst;  
2082  {  {
2083    unsigned int r;    unsigned int r;
2084    
# Line 1865  sh_elf_info_to_howto (abfd, cache_ptr, d Line 2089  sh_elf_info_to_howto (abfd, cache_ptr, d
2089    BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);    BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
2090    BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);    BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
2091    BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);    BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
2092      BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
2093    
2094    cache_ptr->howto = &sh_elf_howto_table[r];    cache_ptr->howto = &sh_elf_howto_table[r];
2095  }  }
# Line 1879  sh_elf_info_to_howto (abfd, cache_ptr, d Line 2104  sh_elf_info_to_howto (abfd, cache_ptr, d
2104     values; in coff-sh.c they come from include/coff/sh.h, whereas here     values; in coff-sh.c they come from include/coff/sh.h, whereas here
2105     they come from enum elf_sh_reloc_type in include/elf/sh.h.  */     they come from enum elf_sh_reloc_type in include/elf/sh.h.  */
2106    
2107  static boolean  static bfd_boolean
2108  sh_elf_relax_section (abfd, sec, link_info, again)  sh_elf_relax_section (bfd *abfd, asection *sec,
2109       bfd *abfd;                        struct bfd_link_info *link_info, bfd_boolean *again)
      asection *sec;  
      struct bfd_link_info *link_info;  
      boolean *again;  
2110  {  {
2111    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
2112    Elf_Internal_Rela *internal_relocs;    Elf_Internal_Rela *internal_relocs;
2113    boolean have_code;    bfd_boolean have_code;
2114    Elf_Internal_Rela *irel, *irelend;    Elf_Internal_Rela *irel, *irelend;
2115    bfd_byte *contents = NULL;    bfd_byte *contents = NULL;
2116    Elf_Internal_Sym *isymbuf = NULL;    Elf_Internal_Sym *isymbuf = NULL;
2117    
2118    *again = false;    *again = FALSE;
2119    
2120    if (link_info->relocateable    if (link_info->relocatable
2121        || (sec->flags & SEC_RELOC) == 0        || (sec->flags & SEC_RELOC) == 0
2122        || sec->reloc_count == 0)        || sec->reloc_count == 0)
2123      return true;      return TRUE;
2124    
2125  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
2126    if (elf_section_data (sec)->this_hdr.sh_flags    if (elf_section_data (sec)->this_hdr.sh_flags
2127        & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))        & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
2128      {      {
2129        return true;        return TRUE;
2130      }      }
2131  #endif  #endif
2132    
   /* 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;  
   
2133    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2134    
2135    internal_relocs = (_bfd_elf32_link_read_relocs    internal_relocs = (_bfd_elf_link_read_relocs
2136                       (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,                       (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
2137                        link_info->keep_memory));                        link_info->keep_memory));
2138    if (internal_relocs == NULL)    if (internal_relocs == NULL)
2139      goto error_return;      goto error_return;
2140    
2141    have_code = false;    have_code = FALSE;
2142    
2143    irelend = internal_relocs + sec->reloc_count;    irelend = internal_relocs + sec->reloc_count;
2144    for (irel = internal_relocs; irel < irelend; irel++)    for (irel = internal_relocs; irel < irelend; irel++)
# Line 1932  sh_elf_relax_section (abfd, sec, link_in Line 2149  sh_elf_relax_section (abfd, sec, link_in
2149        bfd_signed_vma foff;        bfd_signed_vma foff;
2150    
2151        if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)        if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
2152          have_code = true;          have_code = TRUE;
2153    
2154        if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)        if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
2155          continue;          continue;
# Line 1944  sh_elf_relax_section (abfd, sec, link_in Line 2161  sh_elf_relax_section (abfd, sec, link_in
2161              contents = elf_section_data (sec)->this_hdr.contents;              contents = elf_section_data (sec)->this_hdr.contents;
2162            else            else
2163              {              {
2164                contents = (bfd_byte *) bfd_malloc (sec->_raw_size);                if (!bfd_malloc_and_get_section (abfd, sec, &contents))
               if (contents == NULL)  
                 goto error_return;  
   
               if (! bfd_get_section_contents (abfd, sec, contents,  
                                               (file_ptr) 0, sec->_raw_size))  
2165                  goto error_return;                  goto error_return;
2166              }              }
2167          }          }
2168    
2169        /* The r_addend field of the R_SH_USES reloc will point us to        /* The r_addend field of the R_SH_USES reloc will point us to
2170           the register load.  The 4 is because the r_addend field is           the register load.  The 4 is because the r_addend field is
2171           computed as though it were a jump offset, which are based           computed as though it were a jump offset, which are based
2172           from 4 bytes after the jump instruction.  */           from 4 bytes after the jump instruction.  */
2173        laddr = irel->r_offset + 4 + irel->r_addend;        laddr = irel->r_offset + 4 + irel->r_addend;
2174        if (laddr >= sec->_raw_size)        if (laddr >= sec->size)
2175          {          {
2176            (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),            (*_bfd_error_handler) (_("%B: 0x%lx: warning: bad R_SH_USES offset"),
2177                                   bfd_archive_filename (abfd),                                   abfd,
2178                                   (unsigned long) irel->r_offset);                                   (unsigned long) irel->r_offset);
2179            continue;            continue;
2180          }          }
2181        insn = bfd_get_16 (abfd, contents + laddr);        insn = bfd_get_16 (abfd, contents + laddr);
2182    
2183        /* If the instruction is not mov.l NN,rN, we don't know what to        /* If the instruction is not mov.l NN,rN, we don't know what to
2184           do.  */           do.  */
2185        if ((insn & 0xf000) != 0xd000)        if ((insn & 0xf000) != 0xd000)
2186          {          {
2187            ((*_bfd_error_handler)            ((*_bfd_error_handler)
2188             (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),             (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2189              bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));              abfd, (unsigned long) irel->r_offset, insn));
2190            continue;            continue;
2191          }          }
2192    
# Line 1987  sh_elf_relax_section (abfd, sec, link_in Line 2199  sh_elf_relax_section (abfd, sec, link_in
2199        paddr = insn & 0xff;        paddr = insn & 0xff;
2200        paddr *= 4;        paddr *= 4;
2201        paddr += (laddr + 4) &~ (bfd_vma) 3;        paddr += (laddr + 4) &~ (bfd_vma) 3;
2202        if (paddr >= sec->_raw_size)        if (paddr >= sec->size)
2203          {          {
2204            ((*_bfd_error_handler)            ((*_bfd_error_handler)
2205             (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),             (_("%B: 0x%lx: warning: bad R_SH_USES load offset"),
2206              bfd_archive_filename (abfd), (unsigned long) irel->r_offset));              abfd, (unsigned long) irel->r_offset));
2207            continue;            continue;
2208          }          }
2209    
2210        /* Get the reloc for the address from which the register is        /* Get the reloc for the address from which the register is
2211           being loaded.  This reloc will tell us which function is           being loaded.  This reloc will tell us which function is
2212           actually being called.  */           actually being called.  */
2213        for (irelfn = internal_relocs; irelfn < irelend; irelfn++)        for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
2214          if (irelfn->r_offset == paddr          if (irelfn->r_offset == paddr
2215              && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)              && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
# Line 2005  sh_elf_relax_section (abfd, sec, link_in Line 2217  sh_elf_relax_section (abfd, sec, link_in
2217        if (irelfn >= irelend)        if (irelfn >= irelend)
2218          {          {
2219            ((*_bfd_error_handler)            ((*_bfd_error_handler)
2220             (_("%s: 0x%lx: warning: could not find expected reloc"),             (_("%B: 0x%lx: warning: could not find expected reloc"),
2221              bfd_archive_filename (abfd), (unsigned long) paddr));              abfd, (unsigned long) paddr));
2222            continue;            continue;
2223          }          }
2224    
# Line 2033  sh_elf_relax_section (abfd, sec, link_in Line 2245  sh_elf_relax_section (abfd, sec, link_in
2245                != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))                != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
2246              {              {
2247                ((*_bfd_error_handler)                ((*_bfd_error_handler)
2248                 (_("%s: 0x%lx: warning: symbol in unexpected section"),                 (_("%B: 0x%lx: warning: symbol in unexpected section"),
2249                  bfd_archive_filename (abfd), (unsigned long) paddr));                  abfd, (unsigned long) paddr));
2250                continue;                continue;
2251              }              }
2252    
# Line 2054  sh_elf_relax_section (abfd, sec, link_in Line 2266  sh_elf_relax_section (abfd, sec, link_in
2266                && h->root.type != bfd_link_hash_defweak)                && h->root.type != bfd_link_hash_defweak)
2267              {              {
2268                /* This appears to be a reference to an undefined                /* This appears to be a reference to an undefined
2269                   symbol.  Just ignore it--it will be caught by the                   symbol.  Just ignore it--it will be caught by the
2270                   regular reloc processing.  */                   regular reloc processing.  */
2271                continue;                continue;
2272              }              }
2273    
# Line 2095  sh_elf_relax_section (abfd, sec, link_in Line 2307  sh_elf_relax_section (abfd, sec, link_in
2307        /* Replace the jsr with a bsr.  */        /* Replace the jsr with a bsr.  */
2308    
2309        /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and        /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2310           replace the jsr with a bsr.  */           replace the jsr with a bsr.  */
2311        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
2312        if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)        /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2313          {           here, but that only checks if the symbol is an external symbol,
2314            /* If this needs to be changed because of future relaxing,           not if the symbol is in a different section.  Besides, we need
2315               it will be handled here like other internal IND12W           a consistent meaning for the relocation, so we just assume here that
2316               relocs.  */           the value of the symbol is not available.  */
2317            bfd_put_16 (abfd,  
2318                        (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),        /* We can't fully resolve this yet, because the external
2319                        contents + irel->r_offset);           symbol value may be changed by future relaxing.  We let
2320          }           the final link phase handle it.  */
2321        else        bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
2322          {  
2323            /* We can't fully resolve this yet, because the external        irel->r_addend = -4;
              symbol value may be changed by future relaxing.  We let  
              the final link phase handle it.  */  
           bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);  
         }  
2324    
2325        /* See if there is another R_SH_USES reloc referring to the same        /* See if there is another R_SH_USES reloc referring to the same
2326           register load.  */           register load.  */
2327        for (irelscan = internal_relocs; irelscan < irelend; irelscan++)        for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
2328          if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES          if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
2329              && laddr == irelscan->r_offset + 4 + irelscan->r_addend)              && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
# Line 2130  sh_elf_relax_section (abfd, sec, link_in Line 2338  sh_elf_relax_section (abfd, sec, link_in
2338          }          }
2339    
2340        /* Look for a R_SH_COUNT reloc on the location where the        /* Look for a R_SH_COUNT reloc on the location where the
2341           function address is stored.  Do this before deleting any           function address is stored.  Do this before deleting any
2342           bytes, to avoid confusion about the address.  */           bytes, to avoid confusion about the address.  */
2343        for (irelcount = internal_relocs; irelcount < irelend; irelcount++)        for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
2344          if (irelcount->r_offset == paddr          if (irelcount->r_offset == paddr
2345              && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)              && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
# Line 2142  sh_elf_relax_section (abfd, sec, link_in Line 2350  sh_elf_relax_section (abfd, sec, link_in
2350          goto error_return;          goto error_return;
2351    
2352        /* That will change things, so, just in case it permits some        /* That will change things, so, just in case it permits some
2353           other function call to come within range, we should relax           other function call to come within range, we should relax
2354           again.  Note that this is not required, and it may be slow.  */           again.  Note that this is not required, and it may be slow.  */
2355        *again = true;        *again = TRUE;
2356    
2357        /* Now check whether we got a COUNT reloc.  */        /* Now check whether we got a COUNT reloc.  */
2358        if (irelcount >= irelend)        if (irelcount >= irelend)
2359          {          {
2360            ((*_bfd_error_handler)            ((*_bfd_error_handler)
2361             (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),             (_("%B: 0x%lx: warning: could not find expected COUNT reloc"),
2362              bfd_archive_filename (abfd), (unsigned long) paddr));              abfd, (unsigned long) paddr));
2363            continue;            continue;
2364          }          }
2365    
2366        /* The number of uses is stored in the r_addend field.  We've        /* The number of uses is stored in the r_addend field.  We've
2367           just deleted one.  */           just deleted one.  */
2368        if (irelcount->r_addend == 0)        if (irelcount->r_addend == 0)
2369          {          {
2370            ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),            ((*_bfd_error_handler) (_("%B: 0x%lx: warning: bad count"),
2371                                    bfd_archive_filename (abfd),                                    abfd,
2372                                    (unsigned long) paddr));                                    (unsigned long) paddr));
2373            continue;            continue;
2374          }          }
# Line 2168  sh_elf_relax_section (abfd, sec, link_in Line 2376  sh_elf_relax_section (abfd, sec, link_in
2376        --irelcount->r_addend;        --irelcount->r_addend;
2377    
2378        /* If there are no more uses, we can delete the address.  Reload        /* If there are no more uses, we can delete the address.  Reload
2379           the address from irelfn, in case it was changed by the           the address from irelfn, in case it was changed by the
2380           previous call to sh_elf_relax_delete_bytes.  */           previous call to sh_elf_relax_delete_bytes.  */
2381        if (irelcount->r_addend == 0)        if (irelcount->r_addend == 0)
2382          {          {
2383            if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))            if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
# Line 2181  sh_elf_relax_section (abfd, sec, link_in Line 2389  sh_elf_relax_section (abfd, sec, link_in
2389    
2390    /* Look for load and store instructions that we can align on four    /* Look for load and store instructions that we can align on four
2391       byte boundaries.  */       byte boundaries.  */
2392    if (have_code)    if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
2393          && have_code)
2394      {      {
2395        boolean swapped;        bfd_boolean swapped;
2396    
2397        /* Get the section contents.  */        /* Get the section contents.  */
2398        if (contents == NULL)        if (contents == NULL)
# Line 2192  sh_elf_relax_section (abfd, sec, link_in Line 2401  sh_elf_relax_section (abfd, sec, link_in
2401              contents = elf_section_data (sec)->this_hdr.contents;              contents = elf_section_data (sec)->this_hdr.contents;
2402            else            else
2403              {              {
2404                contents = (bfd_byte *) bfd_malloc (sec->_raw_size);                if (!bfd_malloc_and_get_section (abfd, sec, &contents))
               if (contents == NULL)  
                 goto error_return;  
   
               if (! bfd_get_section_contents (abfd, sec, contents,  
                                               (file_ptr) 0, sec->_raw_size))  
2405                  goto error_return;                  goto error_return;
2406              }              }
2407          }          }
# Line 2242  sh_elf_relax_section (abfd, sec, link_in Line 2446  sh_elf_relax_section (abfd, sec, link_in
2446        && elf_section_data (sec)->relocs != internal_relocs)        && elf_section_data (sec)->relocs != internal_relocs)
2447      free (internal_relocs);      free (internal_relocs);
2448    
2449    return true;    return TRUE;
2450    
2451   error_return:   error_return:
2452    if (isymbuf != NULL    if (isymbuf != NULL
# Line 2255  sh_elf_relax_section (abfd, sec, link_in Line 2459  sh_elf_relax_section (abfd, sec, link_in
2459        && elf_section_data (sec)->relocs != internal_relocs)        && elf_section_data (sec)->relocs != internal_relocs)
2460      free (internal_relocs);      free (internal_relocs);
2461    
2462    return false;    return FALSE;
2463  }  }
2464    
2465  /* Delete some bytes from a section while relaxing.  FIXME: There is a  /* Delete some bytes from a section while relaxing.  FIXME: There is a
2466     lot of duplication between this function and sh_relax_delete_bytes     lot of duplication between this function and sh_relax_delete_bytes
2467     in coff-sh.c.  */     in coff-sh.c.  */
2468    
2469  static boolean  static bfd_boolean
2470  sh_elf_relax_delete_bytes (abfd, sec, addr, count)  sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
2471       bfd *abfd;                             int count)
      asection *sec;  
      bfd_vma addr;  
      int count;  
2472  {  {
2473    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
2474    unsigned int sec_shndx;    unsigned int sec_shndx;
# Line 2292  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2493  sh_elf_relax_delete_bytes (abfd, sec, ad
2493       power larger than the number of bytes we are deleting.  */       power larger than the number of bytes we are deleting.  */
2494    
2495    irelalign = NULL;    irelalign = NULL;
2496    toaddr = sec->_cooked_size;    toaddr = sec->size;
2497    
2498    irel = elf_section_data (sec)->relocs;    irel = elf_section_data (sec)->relocs;
2499    irelend = irel + sec->reloc_count;    irelend = irel + sec->reloc_count;
# Line 2312  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2513  sh_elf_relax_delete_bytes (abfd, sec, ad
2513    memmove (contents + addr, contents + addr + count,    memmove (contents + addr, contents + addr + count,
2514             (size_t) (toaddr - addr - count));             (size_t) (toaddr - addr - count));
2515    if (irelalign == NULL)    if (irelalign == NULL)
2516      sec->_cooked_size -= count;      sec->size -= count;
2517    else    else
2518      {      {
2519        int i;        int i;
# Line 2332  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2533  sh_elf_relax_delete_bytes (abfd, sec, ad
2533        int insn = 0;        int insn = 0;
2534        int off, adjust, oinsn;        int off, adjust, oinsn;
2535        bfd_signed_vma voff = 0;        bfd_signed_vma voff = 0;
2536        boolean overflow;        bfd_boolean overflow;
2537    
2538        /* Get the new reloc address.  */        /* Get the new reloc address.  */
2539        nraddr = irel->r_offset;        nraddr = irel->r_offset;
# Line 2355  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2556  sh_elf_relax_delete_bytes (abfd, sec, ad
2556                                       (int) R_SH_NONE);                                       (int) R_SH_NONE);
2557    
2558        /* If this is a PC relative reloc, see if the range it covers        /* If this is a PC relative reloc, see if the range it covers
2559           includes the bytes we have deleted.  */           includes the bytes we have deleted.  */
2560        switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))        switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2561          {          {
2562          default:          default:
# Line 2378  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2579  sh_elf_relax_delete_bytes (abfd, sec, ad
2579    
2580          case R_SH_DIR32:          case R_SH_DIR32:
2581            /* If this reloc is against a symbol defined in this            /* If this reloc is against a symbol defined in this
2582               section, and the symbol will not be adjusted below, we               section, and the symbol will not be adjusted below, we
2583               must check the addend to see it will put the value in               must check the addend to see it will put the value in
2584               range to be adjusted, and hence must be changed.  */               range to be adjusted, and hence must be changed.  */
2585            if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)            if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2586              {              {
2587                isym = isymbuf + ELF32_R_SYM (irel->r_info);                isym = isymbuf + ELF32_R_SYM (irel->r_info);
# Line 2407  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2608  sh_elf_relax_delete_bytes (abfd, sec, ad
2608            break;            break;
2609    
2610          case R_SH_IND12W:          case R_SH_IND12W:
2611            if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)            off = insn & 0xfff;
2612              start = stop = addr;            if (! off)
2613                {
2614                  /* This has been made by previous relaxation.  Since the
2615                     relocation will be against an external symbol, the
2616                     final relocation will just do the right thing.  */
2617                  start = stop = addr;
2618                }
2619            else            else
2620              {              {
               off = insn & 0xfff;  
2621                if (off & 0x800)                if (off & 0x800)
2622                  off -= 0x1000;                  off -= 0x1000;
2623                stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);                stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2624    
2625                  /* The addend will be against the section symbol, thus
2626                     for adjusting the addend, the relevant start is the
2627                     start of the section.
2628                     N.B. If we want to abandon in-place changes here and
2629                     test directly using symbol + addend, we have to take into
2630                     account that the addend has already been adjusted by -4.  */
2631                  if (stop > addr && stop < toaddr)
2632                    irel->r_addend -= count;
2633              }              }
2634            break;            break;
2635    
# Line 2484  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2699  sh_elf_relax_delete_bytes (abfd, sec, ad
2699        if (adjust != 0)        if (adjust != 0)
2700          {          {
2701            oinsn = insn;            oinsn = insn;
2702            overflow = false;            overflow = FALSE;
2703            switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))            switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2704              {              {
2705              default:              default:
# Line 2495  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2710  sh_elf_relax_delete_bytes (abfd, sec, ad
2710              case R_SH_DIR8WPZ:              case R_SH_DIR8WPZ:
2711                insn += adjust / 2;                insn += adjust / 2;
2712                if ((oinsn & 0xff00) != (insn & 0xff00))                if ((oinsn & 0xff00) != (insn & 0xff00))
2713                  overflow = true;                  overflow = TRUE;
2714                bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);                bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2715                break;                break;
2716    
2717              case R_SH_IND12W:              case R_SH_IND12W:
2718                insn += adjust / 2;                insn += adjust / 2;
2719                if ((oinsn & 0xf000) != (insn & 0xf000))                if ((oinsn & 0xf000) != (insn & 0xf000))
2720                  overflow = true;                  overflow = TRUE;
2721                bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);                bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2722                break;                break;
2723    
# Line 2516  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2731  sh_elf_relax_delete_bytes (abfd, sec, ad
2731                      ++insn;                      ++insn;
2732                  }                  }
2733                if ((oinsn & 0xff00) != (insn & 0xff00))                if ((oinsn & 0xff00) != (insn & 0xff00))
2734                  overflow = true;                  overflow = TRUE;
2735                bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);                bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2736                break;                break;
2737    
2738              case R_SH_SWITCH8:              case R_SH_SWITCH8:
2739                voff += adjust;                voff += adjust;
2740                if (voff < 0 || voff >= 0xff)                if (voff < 0 || voff >= 0xff)
2741                  overflow = true;                  overflow = TRUE;
2742                bfd_put_8 (abfd, voff, contents + nraddr);                bfd_put_8 (abfd, voff, contents + nraddr);
2743                break;                break;
2744    
2745              case R_SH_SWITCH16:              case R_SH_SWITCH16:
2746                voff += adjust;                voff += adjust;
2747                if (voff < - 0x8000 || voff >= 0x8000)                if (voff < - 0x8000 || voff >= 0x8000)
2748                  overflow = true;                  overflow = TRUE;
2749                bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);                bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
2750                break;                break;
2751    
# Line 2547  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2762  sh_elf_relax_delete_bytes (abfd, sec, ad
2762            if (overflow)            if (overflow)
2763              {              {
2764                ((*_bfd_error_handler)                ((*_bfd_error_handler)
2765                 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),                 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
2766                  bfd_archive_filename (abfd), (unsigned long) irel->r_offset));                  abfd, (unsigned long) irel->r_offset));
2767                bfd_set_error (bfd_error_bad_value);                bfd_set_error (bfd_error_bad_value);
2768                return false;                return FALSE;
2769              }              }
2770          }          }
2771    
# Line 2572  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2787  sh_elf_relax_delete_bytes (abfd, sec, ad
2787          continue;          continue;
2788    
2789        /* We always cache the relocs.  Perhaps, if info->keep_memory is        /* We always cache the relocs.  Perhaps, if info->keep_memory is
2790           false, we should free them, if we are permitted to, when we           FALSE, we should free them, if we are permitted to, when we
2791           leave sh_coff_relax_section.  */           leave sh_coff_relax_section.  */
2792        internal_relocs = (_bfd_elf32_link_read_relocs        internal_relocs = (_bfd_elf_link_read_relocs
2793                           (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,                           (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
                           true));  
2794        if (internal_relocs == NULL)        if (internal_relocs == NULL)
2795          return false;          return FALSE;
2796    
2797        ocontents = NULL;        ocontents = NULL;
2798        irelscanend = internal_relocs + o->reloc_count;        irelscanend = internal_relocs + o->reloc_count;
# Line 2597  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2811  sh_elf_relax_delete_bytes (abfd, sec, ad
2811                    else                    else
2812                      {                      {
2813                        /* We always cache the section contents.                        /* We always cache the section contents.
2814                           Perhaps, if info->keep_memory is false, we                           Perhaps, if info->keep_memory is FALSE, we
2815                           should free them, if we are permitted to,                           should free them, if we are permitted to,
2816                           when we leave sh_coff_relax_section.  */                           when we leave sh_coff_relax_section.  */
2817                        ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);                        if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
2818                        if (ocontents == NULL)                          {
2819                          return false;                            if (ocontents != NULL)
2820                        if (! bfd_get_section_contents (abfd, o, ocontents,                              free (ocontents);
2821                                                        (file_ptr) 0,                            return FALSE;
2822                                                        o->_raw_size))                          }
2823                          return false;  
2824                        elf_section_data (o)->this_hdr.contents = ocontents;                        elf_section_data (o)->this_hdr.contents = ocontents;
2825                      }                      }
2826                  }                  }
# Line 2655  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2869  sh_elf_relax_delete_bytes (abfd, sec, ad
2869                    else                    else
2870                      {                      {
2871                        /* We always cache the section contents.                        /* We always cache the section contents.
2872                           Perhaps, if info->keep_memory is false, we                           Perhaps, if info->keep_memory is FALSE, we
2873                           should free them, if we are permitted to,                           should free them, if we are permitted to,
2874                           when we leave sh_coff_relax_section.  */                           when we leave sh_coff_relax_section.  */
2875                        ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);                        if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
2876                        if (ocontents == NULL)                          {
2877                          return false;                            if (ocontents != NULL)
2878                        if (! bfd_get_section_contents (abfd, o, ocontents,                              free (ocontents);
2879                                                        (file_ptr) 0,                            return FALSE;
2880                                                        o->_raw_size))                          }
2881                          return false;  
2882                        elf_section_data (o)->this_hdr.contents = ocontents;                        elf_section_data (o)->this_hdr.contents = ocontents;
2883                      }                      }
2884                  }                  }
# Line 2723  sh_elf_relax_delete_bytes (abfd, sec, ad Line 2937  sh_elf_relax_delete_bytes (abfd, sec, ad
2937          }          }
2938      }      }
2939    
2940    return true;    return TRUE;
2941  }  }
2942    
2943  /* Look for loads and stores which we can align to four byte  /* Look for loads and stores which we can align to four byte
2944     boundaries.  This is like sh_align_loads in coff-sh.c.  */     boundaries.  This is like sh_align_loads in coff-sh.c.  */
2945    
2946  static boolean  static bfd_boolean
2947  sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)  sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
2948       bfd *abfd ATTRIBUTE_UNUSED;                      Elf_Internal_Rela *internal_relocs,
2949       asection *sec;                      bfd_byte *contents ATTRIBUTE_UNUSED,
2950       Elf_Internal_Rela *internal_relocs;                      bfd_boolean *pswapped)
      bfd_byte *contents ATTRIBUTE_UNUSED;  
      boolean *pswapped;  
2951  {  {
2952    Elf_Internal_Rela *irel, *irelend;    Elf_Internal_Rela *irel, *irelend;
2953    bfd_vma *labels = NULL;    bfd_vma *labels = NULL;
2954    bfd_vma *label, *label_end;    bfd_vma *label, *label_end;
2955    bfd_size_type amt;    bfd_size_type amt;
2956    
2957    *pswapped = false;    *pswapped = FALSE;
2958    
2959    irelend = internal_relocs + sec->reloc_count;    irelend = internal_relocs + sec->reloc_count;
2960    
# Line 2783  sh_elf_align_loads (abfd, sec, internal_ Line 2995  sh_elf_align_loads (abfd, sec, internal_
2995        if (irel < irelend)        if (irel < irelend)
2996          stop = irel->r_offset;          stop = irel->r_offset;
2997        else        else
2998          stop = sec->_cooked_size;          stop = sec->size;
2999    
3000        if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,        if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
3001                                       (PTR) internal_relocs, &label,                                       internal_relocs, &label,
3002                                       label_end, start, stop, pswapped))                                       label_end, start, stop, pswapped))
3003          goto error_return;          goto error_return;
3004      }      }
3005    
3006    free (labels);    free (labels);
3007    
3008    return true;    return TRUE;
3009    
3010   error_return:   error_return:
3011    if (labels != NULL)    if (labels != NULL)
3012      free (labels);      free (labels);
3013    return false;    return FALSE;
3014  }  }
3015    
3016    #ifndef SH64_ELF
3017  /* Swap two SH instructions.  This is like sh_swap_insns in coff-sh.c.  */  /* Swap two SH instructions.  This is like sh_swap_insns in coff-sh.c.  */
3018    
3019  static boolean  static bfd_boolean
3020  sh_elf_swap_insns (abfd, sec, relocs, contents, addr)  sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
3021       bfd *abfd;                     bfd_byte *contents, bfd_vma addr)
      asection *sec;  
      PTR relocs;  
      bfd_byte *contents;  
      bfd_vma addr;  
3022  {  {
3023    Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;    Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
3024    unsigned short i1, i2;    unsigned short i1, i2;
# Line 2829  sh_elf_swap_insns (abfd, sec, relocs, co Line 3038  sh_elf_swap_insns (abfd, sec, relocs, co
3038        int add;        int add;
3039    
3040        /* There are a few special types of relocs that we don't want to        /* There are a few special types of relocs that we don't want to
3041           adjust.  These relocs do not apply to the instruction itself,           adjust.  These relocs do not apply to the instruction itself,
3042           but are only associated with the address.  */           but are only associated with the address.  */
3043        type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);        type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
3044        if (type == R_SH_ALIGN        if (type == R_SH_ALIGN
3045            || type == R_SH_CODE            || type == R_SH_CODE
# Line 2839  sh_elf_swap_insns (abfd, sec, relocs, co Line 3048  sh_elf_swap_insns (abfd, sec, relocs, co
3048          continue;          continue;
3049    
3050        /* If an R_SH_USES reloc points to one of the addresses being        /* If an R_SH_USES reloc points to one of the addresses being
3051           swapped, we must adjust it.  It would be incorrect to do this           swapped, we must adjust it.  It would be incorrect to do this
3052           for a jump, though, since we want to execute both           for a jump, though, since we want to execute both
3053           instructions after the jump.  (We have avoided swapping           instructions after the jump.  (We have avoided swapping
3054           around a label, so the jump will not wind up executing an           around a label, so the jump will not wind up executing an
3055           instruction it shouldn't).  */           instruction it shouldn't).  */
3056        if (type == R_SH_USES)        if (type == R_SH_USES)
3057          {          {
3058            bfd_vma off;            bfd_vma off;
# Line 2872  sh_elf_swap_insns (abfd, sec, relocs, co Line 3081  sh_elf_swap_insns (abfd, sec, relocs, co
3081          {          {
3082            bfd_byte *loc;            bfd_byte *loc;
3083            unsigned short insn, oinsn;            unsigned short insn, oinsn;
3084            boolean overflow;            bfd_boolean overflow;
3085    
3086            loc = contents + irel->r_offset;            loc = contents + irel->r_offset;
3087            overflow = false;            overflow = FALSE;
3088            switch (type)            switch (type)
3089              {              {
3090              default:              default:
# Line 2887  sh_elf_swap_insns (abfd, sec, relocs, co Line 3096  sh_elf_swap_insns (abfd, sec, relocs, co
3096                oinsn = insn;                oinsn = insn;
3097                insn += add / 2;                insn += add / 2;
3098                if ((oinsn & 0xff00) != (insn & 0xff00))                if ((oinsn & 0xff00) != (insn & 0xff00))
3099                  overflow = true;                  overflow = TRUE;
3100                bfd_put_16 (abfd, (bfd_vma) insn, loc);                bfd_put_16 (abfd, (bfd_vma) insn, loc);
3101                break;                break;
3102    
# Line 2896  sh_elf_swap_insns (abfd, sec, relocs, co Line 3105  sh_elf_swap_insns (abfd, sec, relocs, co
3105                oinsn = insn;                oinsn = insn;
3106                insn += add / 2;                insn += add / 2;
3107                if ((oinsn & 0xf000) != (insn & 0xf000))                if ((oinsn & 0xf000) != (insn & 0xf000))
3108                  overflow = true;                  overflow = TRUE;
3109                bfd_put_16 (abfd, (bfd_vma) insn, loc);                bfd_put_16 (abfd, (bfd_vma) insn, loc);
3110                break;                break;
3111    
3112              case R_SH_DIR8WPL:              case R_SH_DIR8WPL:
3113                /* This reloc ignores the least significant 3 bits of                /* This reloc ignores the least significant 3 bits of
3114                   the program counter before adding in the offset.                   the program counter before adding in the offset.
3115                   This means that if ADDR is at an even address, the                   This means that if ADDR is at an even address, the
3116                   swap will not affect the offset.  If ADDR is an at an                   swap will not affect the offset.  If ADDR is an at an
3117                   odd address, then the instruction will be crossing a                   odd address, then the instruction will be crossing a
3118                   four byte boundary, and must be adjusted.  */                   four byte boundary, and must be adjusted.  */
3119                if ((addr & 3) != 0)                if ((addr & 3) != 0)
3120                  {                  {
3121                    insn = bfd_get_16 (abfd, loc);                    insn = bfd_get_16 (abfd, loc);
3122                    oinsn = insn;                    oinsn = insn;
3123                    insn += add / 2;                    insn += add / 2;
3124                    if ((oinsn & 0xff00) != (insn & 0xff00))                    if ((oinsn & 0xff00) != (insn & 0xff00))
3125                      overflow = true;                      overflow = TRUE;
3126                    bfd_put_16 (abfd, (bfd_vma) insn, loc);                    bfd_put_16 (abfd, (bfd_vma) insn, loc);
3127                  }                  }
3128    
# Line 2923  sh_elf_swap_insns (abfd, sec, relocs, co Line 3132  sh_elf_swap_insns (abfd, sec, relocs, co
3132            if (overflow)            if (overflow)
3133              {              {
3134                ((*_bfd_error_handler)                ((*_bfd_error_handler)
3135                 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),                 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
3136                  bfd_archive_filename (abfd), (unsigned long) irel->r_offset));                  abfd, (unsigned long) irel->r_offset));
3137                bfd_set_error (bfd_error_bad_value);                bfd_set_error (bfd_error_bad_value);
3138                return false;                return FALSE;
3139              }              }
3140          }          }
3141      }      }
3142    
3143    return true;    return TRUE;
3144  }  }
3145    #endif /* defined SH64_ELF */
3146    
3147  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
3148    
# Line 2947  static const bfd_byte elf_sh_plt0_entry_ Line 3157  static const bfd_byte elf_sh_plt0_entry_
3157    0xcc, 0x00, 0x01, 0x10, /* movi  .got.plt >> 16, r17 */    0xcc, 0x00, 0x01, 0x10, /* movi  .got.plt >> 16, r17 */
3158    0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */    0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3159    0x89, 0x10, 0x09, 0x90, /* ld.l  r17, 8, r25 */    0x89, 0x10, 0x09, 0x90, /* ld.l  r17, 8, r25 */
3160    0x6b, 0xf1, 0x46, 0x00, /* ptabs r17, tr0 */    0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3161    0x89, 0x10, 0x05, 0x10, /* ld.l  r17, 4, r17 */    0x89, 0x10, 0x05, 0x10, /* ld.l  r17, 4, r17 */
3162    0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */    0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3163    0x6f, 0xf0, 0xff, 0xf0, /* nop */    0x6f, 0xf0, 0xff, 0xf0, /* nop */
# Line 2967  static const bfd_byte elf_sh_plt0_entry_ Line 3177  static const bfd_byte elf_sh_plt0_entry_
3177    0x10, 0x01, 0x00, 0xcc, /* movi  .got.plt >> 16, r17 */    0x10, 0x01, 0x00, 0xcc, /* movi  .got.plt >> 16, r17 */
3178    0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */    0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3179    0x90, 0x09, 0x10, 0x89, /* ld.l  r17, 8, r25 */    0x90, 0x09, 0x10, 0x89, /* ld.l  r17, 8, r25 */
3180    0x00, 0x46, 0xf1, 0x6b, /* ptabs r17, tr0 */    0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3181    0x10, 0x05, 0x10, 0x89, /* ld.l  r17, 4, r17 */    0x10, 0x05, 0x10, 0x89, /* ld.l  r17, 4, r17 */
3182    0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */    0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3183    0xf0, 0xff, 0xf0, 0x6f, /* nop */    0xf0, 0xff, 0xf0, 0x6f, /* nop */
# Line 3038  static const bfd_byte elf_sh_pic_plt_ent Line 3248  static const bfd_byte elf_sh_pic_plt_ent
3248    0x6f, 0xf0, 0xff, 0xf0, /* nop */    0x6f, 0xf0, 0xff, 0xf0, /* nop */
3249    0x6f, 0xf0, 0xff, 0xf0, /* nop */    0x6f, 0xf0, 0xff, 0xf0, /* nop */
3250    0xce, 0x00, 0x01, 0x10, /* movi  -GOT_BIAS, r17 */    0xce, 0x00, 0x01, 0x10, /* movi  -GOT_BIAS, r17 */
3251    0x00, 0xca, 0x45, 0x10, /* sub.l r12, r17, r17 */    0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3252    0x89, 0x10, 0x09, 0x90, /* ld.l  r17, 8, r25 */    0x89, 0x10, 0x09, 0x90, /* ld.l  r17, 8, r25 */
3253    0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */    0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3254    0x89, 0x10, 0x05, 0x10, /* ld.l  r17, 4, r17 */    0x89, 0x10, 0x05, 0x10, /* ld.l  r17, 4, r17 */
# Line 3058  static const bfd_byte elf_sh_pic_plt_ent Line 3268  static const bfd_byte elf_sh_pic_plt_ent
3268    0xf0, 0xff, 0xf0, 0x6f, /* nop */    0xf0, 0xff, 0xf0, 0x6f, /* nop */
3269    0xf0, 0xff, 0xf0, 0x6f, /* nop */    0xf0, 0xff, 0xf0, 0x6f, /* nop */
3270    0x10, 0x01, 0x00, 0xce, /* movi  -GOT_BIAS, r17 */    0x10, 0x01, 0x00, 0xce, /* movi  -GOT_BIAS, r17 */
3271    0x10, 0x45, 0xca, 0x00, /* sub.l r12, r17, r17 */    0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3272    0x90, 0x09, 0x10, 0x89, /* ld.l  r17, 8, r25 */    0x90, 0x09, 0x10, 0x89, /* ld.l  r17, 8, r25 */
3273    0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */    0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3274    0x10, 0x05, 0x10, 0x89, /* ld.l  r17, 4, r17 */    0x10, 0x05, 0x10, 0x89, /* ld.l  r17, 4, r17 */
# Line 3090  static const bfd_byte *elf_sh_pic_plt_en Line 3300  static const bfd_byte *elf_sh_pic_plt_en
3300  #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)  #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3301    
3302  inline static void  inline static void
3303  movi_shori_putval (output_bfd, value, addr)  movi_shori_putval (bfd *output_bfd, unsigned long value, bfd_byte *addr)
      bfd *output_bfd;  
      unsigned long value;  
      char *addr;  
3304  {  {
3305    bfd_put_32 (output_bfd,    bfd_put_32 (output_bfd,
3306                bfd_get_32 (output_bfd, addr)                bfd_get_32 (output_bfd, addr)
# Line 3112  movi_shori_putval (output_bfd, value, ad Line 3319  movi_shori_putval (output_bfd, value, ad
3319    
3320  /* First entry in an absolute procedure linkage table look like this.  */  /* First entry in an absolute procedure linkage table look like this.  */
3321    
 #if 1  
3322  /* Note - this code has been "optimised" not to use r2.  r2 is used by  /* Note - this code has been "optimised" not to use r2.  r2 is used by
3323     GCC to return the address of large strutcures, so it should not be     GCC to return the address of large structures, so it should not be
3324     corrupted here.  This does mean however, that this PLT does not conform     corrupted here.  This does mean however, that this PLT does not conform
3325     to the SH PIC ABI.  That spec says that r0 contains the type of the PLT     to the SH PIC ABI.  That spec says that r0 contains the type of the PLT
3326     and r2 contains the GOT id.  This version stores the GOT id in r0 and     and r2 contains the GOT id.  This version stores the GOT id in r0 and
# Line 3220  static const bfd_byte elf_sh_pic_plt_ent Line 3426  static const bfd_byte elf_sh_pic_plt_ent
3426    0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */    0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */
3427  };  };
3428    
 #else /* These are the old style PLT entries.  */  
 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =  
 {  
   0xd0, 0x04,   /* mov.l 1f,r0 */  
   0xd2, 0x05,   /* mov.l 2f,r2 */  
   0x60, 0x02,   /* mov.l @r0,r0 */  
   0x62, 0x22,   /* mov.l @r2,r2 */  
   0x40, 0x2b,   /* jmp @r0 */  
   0xe0, 0x00,   /*  mov #0,r0 */  
   0x00, 0x09,   /* nop */  
   0x00, 0x09,   /* nop */  
   0x00, 0x09,   /* nop */  
   0x00, 0x09,   /* nop */  
   0, 0, 0, 0,   /* 1: replaced with address of .got.plt + 8.  */  
   0, 0, 0, 0,   /* 2: replaced with address of .got.plt + 4.  */  
 };  
   
 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =  
 {  
   0x04, 0xd0,   /* mov.l 1f,r0 */  
   0x05, 0xd2,   /* mov.l 2f,r2 */  
   0x02, 0x60,   /* mov.l @r0,r0 */  
   0x22, 0x62,   /* mov.l @r2,r2 */  
   0x2b, 0x40,   /* jmp @r0 */  
   0x00, 0xe0,   /*  mov #0,r0 */  
   0x09, 0x00,   /* nop */  
   0x09, 0x00,   /* nop */  
   0x09, 0x00,   /* nop */  
   0x09, 0x00,   /* nop */  
   0, 0, 0, 0,   /* 1: replaced with address of .got.plt + 8.  */  
   0, 0, 0, 0,   /* 2: replaced with address of .got.plt + 4.  */  
 };  
   
 /* Sebsequent entries in an absolute procedure linkage table look like  
    this.  */  
   
 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =  
 {  
   0xd0, 0x04,   /* mov.l 1f,r0 */  
   0x60, 0x02,   /* mov.l @r0,r0 */  
   0xd2, 0x02,   /* mov.l 0f,r2 */  
   0x40, 0x2b,   /* jmp @r0 */  
   0x60, 0x23,   /*  mov r2,r0 */  
   0xd1, 0x03,   /* mov.l 2f,r1 */  
   0x40, 0x2b,   /* jmp @r0 */  
   0x00, 0x09,   /* nop */  
   0, 0, 0, 0,   /* 0: replaced with address of .PLT0.  */  
   0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */  
   0, 0, 0, 0,   /* 2: replaced with offset into relocation table.  */  
 };  
   
 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =  
 {  
   0x04, 0xd0,   /* mov.l 1f,r0 */  
   0x02, 0x60,   /* mov.l @r0,r0 */  
   0x02, 0xd2,   /* mov.l 0f,r2 */  
   0x2b, 0x40,   /* jmp @r0 */  
   0x23, 0x60,   /*  mov r2,r0 */  
   0x03, 0xd1,   /* mov.l 2f,r1 */  
   0x2b, 0x40,   /* jmp @r0 */  
   0x09, 0x00,   /*  nop */  
   0, 0, 0, 0,   /* 0: replaced with address of .PLT.  */  
   0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */  
   0, 0, 0, 0,   /* 2: replaced with offset into relocation table.  */  
 };  
   
 /* Entries in a PIC procedure linkage table look like this.  */  
   
 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =  
 {  
   0xd0, 0x04,   /* mov.l 1f,r0 */  
   0x00, 0xce,   /* mov.l @(r0,r12),r0 */  
   0x40, 0x2b,   /* jmp @r0 */  
   0x00, 0x09,   /*  nop */  
   0x50, 0xc2,   /* 0: mov.l @(8,r12),r0 */  
   0x52, 0xc1,   /* 1: mov.l @(4,r12),r2 */  
   0xd1, 0x02,   /* mov.l 2f,r1 */  
   0x40, 0x2b,   /* jmp @r0 */  
   0xe0, 0x00,   /*  mov #0,r0 ! shows the type of PLT.  */  
   0x00, 0x09,   /* nop */  
   0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */  
   0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */  
 };  
   
 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =  
 {  
   0x04, 0xd0,   /* mov.l 1f,r0 */  
   0xce, 0x00,   /* mov.l @(r0,r12),r0 */  
   0x2b, 0x40,   /* jmp @r0 */  
   0x09, 0x00,   /*  nop */  
   0xc2, 0x50,   /* 0: mov.l @(8,r12),r0 */  
   0xc1, 0x52,   /* 1: mov.l @(4,r12),r2 */  
   0x02, 0xd1,   /* mov.l 2f,r1 */  
   0x2b, 0x40,   /* jmp @r0 */  
   0x00, 0xe0,   /*  mov #0,r0 ! shows the type of PLT.  */  
   0x09, 0x00,   /* nop */  
   0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */  
   0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */  
 };  
 #endif /* old style PLT entries.  */  
   
3429  static const bfd_byte *elf_sh_plt0_entry;  static const bfd_byte *elf_sh_plt0_entry;
3430  static const bfd_byte *elf_sh_plt_entry;  static const bfd_byte *elf_sh_plt_entry;
3431  static const bfd_byte *elf_sh_pic_plt_entry;  static const bfd_byte *elf_sh_pic_plt_entry;
# Line 3337  static const bfd_byte *elf_sh_pic_plt_en Line 3442  static const bfd_byte *elf_sh_pic_plt_en
3442  /* Return offset of the GOT id in PLT0 entry.  */  /* Return offset of the GOT id in PLT0 entry.  */
3443  #define elf_sh_plt0_gotid_offset(info) 24  #define elf_sh_plt0_gotid_offset(info) 24
3444    
3445  /* Return offset of the tempoline in PLT entry */  /* Return offset of the temporary in PLT entry */
3446  #define elf_sh_plt_temp_offset(info) 8  #define elf_sh_plt_temp_offset(info) 8
3447    
3448  /* Return offset of the symbol in PLT entry.  */  /* Return offset of the symbol in PLT entry.  */
# Line 3348  static const bfd_byte *elf_sh_pic_plt_en Line 3453  static const bfd_byte *elf_sh_pic_plt_en
3453  #endif  #endif
3454    
3455  /* The sh linker needs to keep track of the number of relocs that it  /* The sh linker needs to keep track of the number of relocs that it
3456     decides to copy in check_relocs for each symbol.  This is so that     decides to copy as dynamic relocs in check_relocs for each symbol.
3457     it can discard PC relative relocs if it doesn't need them when     This is so that it can later discard them if they are found to be
3458     linking with -Bsymbolic.  We store the information in a field     unnecessary.  We store the information in a field extending the
3459     extending the regular ELF linker hash table.  */     regular ELF linker hash table.  */
3460    
3461  /* This structure keeps track of the number of PC relative relocs we  struct elf_sh_dyn_relocs
3462     have copied for a given symbol.  */  {
3463      struct elf_sh_dyn_relocs *next;
3464  struct elf_sh_pcrel_relocs_copied  
3465  {    /* The input section of the reloc.  */
3466    /* Next section.  */    asection *sec;
3467    struct elf_sh_pcrel_relocs_copied *next;  
3468    /* A section in dynobj.  */    /* Total number of relocs copied for the input section.  */
   asection *section;  
   /* Number of relocs copied in this section.  */  
3469    bfd_size_type count;    bfd_size_type count;
3470    
3471      /* Number of pc-relative relocs copied for the input section.  */
3472      bfd_size_type pc_count;
3473  };  };
3474    
3475  /* sh ELF linker hash entry.  */  /* sh ELF linker hash entry.  */
# Line 3373  struct elf_sh_link_hash_entry Line 3479  struct elf_sh_link_hash_entry
3479    struct elf_link_hash_entry root;    struct elf_link_hash_entry root;
3480    
3481  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
3482    bfd_vma datalabel_got_offset;    union
3483      {
3484        bfd_signed_vma refcount;
3485        bfd_vma offset;
3486      } datalabel_got;
3487  #endif  #endif
3488    
3489    /* Number of PC relative relocs copied for this symbol.  */    /* Track dynamic relocs copied for this symbol.  */
3490    struct elf_sh_pcrel_relocs_copied *pcrel_relocs_copied;    struct elf_sh_dyn_relocs *dyn_relocs;
3491    
3492      bfd_signed_vma gotplt_refcount;
3493    
3494      enum {
3495        GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
3496      } tls_type;
3497    };
3498    
3499    #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3500    
3501    struct sh_elf_obj_tdata
3502    {
3503      struct elf_obj_tdata root;
3504    
3505      /* tls_type for each local got entry.  */
3506      char *local_got_tls_type;
3507  };  };
3508    
3509    #define sh_elf_tdata(abfd) \
3510      ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3511    
3512    #define sh_elf_local_got_tls_type(abfd) \
3513      (sh_elf_tdata (abfd)->local_got_tls_type)
3514    
3515    /* Override the generic function because we need to store sh_elf_obj_tdata
3516       as the specific tdata.  */
3517    
3518    static bfd_boolean
3519    sh_elf_mkobject (bfd *abfd)
3520    {
3521      bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
3522      abfd->tdata.any = bfd_zalloc (abfd, amt);
3523      if (abfd->tdata.any == NULL)
3524        return FALSE;
3525      return TRUE;
3526    }
3527    
3528  /* sh ELF linker hash table.  */  /* sh ELF linker hash table.  */
3529    
3530  struct elf_sh_link_hash_table  struct elf_sh_link_hash_table
3531  {  {
3532    struct elf_link_hash_table root;    struct elf_link_hash_table root;
 };  
   
 /* Declare this now that the above structures are defined.  */  
3533    
3534  static boolean sh_elf_discard_copies    /* Short-cuts to get to dynamic linker sections.  */
3535    PARAMS ((struct elf_sh_link_hash_entry *, PTR));    asection *sgot;
3536      asection *sgotplt;
3537      asection *srelgot;
3538      asection *splt;
3539      asection *srelplt;
3540      asection *sdynbss;
3541      asection *srelbss;
3542    
3543      /* Small local sym to section mapping cache.  */
3544      struct sym_sec_cache sym_sec;
3545    
3546      /* A counter or offset to track a TLS got entry.  */
3547      union
3548        {
3549          bfd_signed_vma refcount;
3550          bfd_vma offset;
3551        } tls_ldm_got;
3552    };
3553    
3554  /* Traverse an sh ELF linker hash table.  */  /* Traverse an sh ELF linker hash table.  */
3555    
3556  #define sh_elf_link_hash_traverse(table, func, info)                    \  #define sh_elf_link_hash_traverse(table, func, info)                    \
3557    (elf_link_hash_traverse                                               \    (elf_link_hash_traverse                                               \
3558     (&(table)->root,                                                     \     (&(table)->root,                                                     \
3559      (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func),  \      (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3560      (info)))      (info)))
3561    
3562  /* Get the sh ELF linker hash table from a link_info structure.  */  /* Get the sh ELF linker hash table from a link_info structure.  */
# Line 3408  static boolean sh_elf_discard_copies Line 3567  static boolean sh_elf_discard_copies
3567  /* Create an entry in an sh ELF linker hash table.  */  /* Create an entry in an sh ELF linker hash table.  */
3568    
3569  static struct bfd_hash_entry *  static struct bfd_hash_entry *
3570  sh_elf_link_hash_newfunc (entry, table, string)  sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
3571       struct bfd_hash_entry *entry;                            struct bfd_hash_table *table,
3572       struct bfd_hash_table *table;                            const char *string)
      const char *string;  
3573  {  {
3574    struct elf_sh_link_hash_entry *ret =    struct elf_sh_link_hash_entry *ret =
3575      (struct elf_sh_link_hash_entry *) entry;      (struct elf_sh_link_hash_entry *) entry;
# Line 3431  sh_elf_link_hash_newfunc (entry, table, Line 3589  sh_elf_link_hash_newfunc (entry, table,
3589                                       table, string));                                       table, string));
3590    if (ret != (struct elf_sh_link_hash_entry *) NULL)    if (ret != (struct elf_sh_link_hash_entry *) NULL)
3591      {      {
3592        ret->pcrel_relocs_copied = NULL;        ret->dyn_relocs = NULL;
3593          ret->gotplt_refcount = 0;
3594  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
3595        ret->datalabel_got_offset = (bfd_vma) -1;        ret->datalabel_got.refcount = ret->root.got.refcount;
3596  #endif  #endif
3597          ret->tls_type = GOT_UNKNOWN;
3598      }      }
3599    
3600    return (struct bfd_hash_entry *) ret;    return (struct bfd_hash_entry *) ret;
# Line 3443  sh_elf_link_hash_newfunc (entry, table, Line 3603  sh_elf_link_hash_newfunc (entry, table,
3603  /* Create an sh ELF linker hash table.  */  /* Create an sh ELF linker hash table.  */
3604    
3605  static struct bfd_link_hash_table *  static struct bfd_link_hash_table *
3606  sh_elf_link_hash_table_create (abfd)  sh_elf_link_hash_table_create (bfd *abfd)
      bfd *abfd;  
3607  {  {
3608    struct elf_sh_link_hash_table *ret;    struct elf_sh_link_hash_table *ret;
3609    bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);    bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
# Line 3460  sh_elf_link_hash_table_create (abfd) Line 3619  sh_elf_link_hash_table_create (abfd)
3619        return NULL;        return NULL;
3620      }      }
3621    
3622      ret->sgot = NULL;
3623      ret->sgotplt = NULL;
3624      ret->srelgot = NULL;
3625      ret->splt = NULL;
3626      ret->srelplt = NULL;
3627      ret->sdynbss = NULL;
3628      ret->srelbss = NULL;
3629      ret->sym_sec.abfd = NULL;
3630      ret->tls_ldm_got.refcount = 0;
3631    
3632    return &ret->root.root;    return &ret->root.root;
3633  }  }
3634    
3635    /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3636       shortcuts to them in our hash table.  */
3637    
3638    static bfd_boolean
3639    create_got_section (bfd *dynobj, struct bfd_link_info *info)
3640    {
3641      struct elf_sh_link_hash_table *htab;
3642    
3643      if (! _bfd_elf_create_got_section (dynobj, info))
3644        return FALSE;
3645    
3646      htab = sh_elf_hash_table (info);
3647      htab->sgot = bfd_get_section_by_name (dynobj, ".got");
3648      htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
3649      if (! htab->sgot || ! htab->sgotplt)
3650        abort ();
3651    
3652      htab->srelgot = bfd_make_section (dynobj, ".rela.got");
3653      if (htab->srelgot == NULL
3654          || ! bfd_set_section_flags (dynobj, htab->srelgot,
3655                                      (SEC_ALLOC
3656                                       | SEC_LOAD
3657                                       | SEC_HAS_CONTENTS
3658                                       | SEC_IN_MEMORY
3659                                       | SEC_LINKER_CREATED
3660                                       | SEC_READONLY))
3661          || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
3662        return FALSE;
3663      return TRUE;
3664    }
3665    
3666  /* Create dynamic sections when linking against a dynamic object.  */  /* Create dynamic sections when linking against a dynamic object.  */
3667    
3668  static boolean  static bfd_boolean
3669  sh_elf_create_dynamic_sections (abfd, info)  sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
      bfd *abfd;  
      struct bfd_link_info *info;  
3670  {  {
3671      struct elf_sh_link_hash_table *htab;
3672    flagword flags, pltflags;    flagword flags, pltflags;
3673    register asection *s;    register asection *s;
3674    struct elf_backend_data *bed = get_elf_backend_data (abfd);    const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3675    int ptralign = 0;    int ptralign = 0;
3676    
3677    switch (bed->s->arch_size)    switch (bed->s->arch_size)
# Line 3487  sh_elf_create_dynamic_sections (abfd, in Line 3686  sh_elf_create_dynamic_sections (abfd, in
3686    
3687      default:      default:
3688        bfd_set_error (bfd_error_bad_value);        bfd_set_error (bfd_error_bad_value);
3689        return false;        return FALSE;
3690      }      }
3691    
3692      htab = sh_elf_hash_table (info);
3693      if (htab->root.dynamic_sections_created)
3694        return TRUE;
3695    
3696    /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and    /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3697       .rel[a].bss sections.  */       .rel[a].bss sections.  */
3698    
# Line 3504  sh_elf_create_dynamic_sections (abfd, in Line 3707  sh_elf_create_dynamic_sections (abfd, in
3707      pltflags |= SEC_READONLY;      pltflags |= SEC_READONLY;
3708    
3709    s = bfd_make_section (abfd, ".plt");    s = bfd_make_section (abfd, ".plt");
3710      htab->splt = s;
3711    if (s == NULL    if (s == NULL
3712        || ! bfd_set_section_flags (abfd, s, pltflags)        || ! bfd_set_section_flags (abfd, s, pltflags)
3713        || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))        || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3714      return false;      return FALSE;
3715    
3716    if (bed->want_plt_sym)    if (bed->want_plt_sym)
3717      {      {
3718        /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the        /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3719           .plt section.  */           .plt section.  */
3720        struct elf_link_hash_entry *h = NULL;        struct elf_link_hash_entry *h;
3721          struct bfd_link_hash_entry *bh = NULL;
3722    
3723        if (! (_bfd_generic_link_add_one_symbol        if (! (_bfd_generic_link_add_one_symbol
3724               (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,               (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3725                (bfd_vma) 0, (const char *) NULL, false,                (bfd_vma) 0, (const char *) NULL, FALSE,
3726                get_elf_backend_data (abfd)->collect,                get_elf_backend_data (abfd)->collect, &bh)))
3727                (struct bfd_link_hash_entry **) &h)))          return FALSE;
3728          return false;  
3729        h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;        h = (struct elf_link_hash_entry *) bh;
3730          h->def_regular = 1;
3731        h->type = STT_OBJECT;        h->type = STT_OBJECT;
3732    
3733        if (info->shared        if (info->shared
3734            && ! _bfd_elf_link_record_dynamic_symbol (info, h))            && ! bfd_elf_link_record_dynamic_symbol (info, h))
3735          return false;          return FALSE;
3736      }      }
3737    
3738    s = bfd_make_section (abfd,    s = bfd_make_section (abfd,
3739                          bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");                          bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3740      htab->srelplt = s;
3741    if (s == NULL    if (s == NULL
3742        || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)        || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3743        || ! bfd_set_section_alignment (abfd, s, ptralign))        || ! bfd_set_section_alignment (abfd, s, ptralign))
3744      return false;      return FALSE;
3745    
3746    if (! _bfd_elf_create_got_section (abfd, info))    if (htab->sgot == NULL
3747      return false;        && !create_got_section (abfd, info))
3748        return FALSE;
3749    
3750    {    {
3751      const char *secname;      const char *secname;
# Line 3554  sh_elf_create_dynamic_sections (abfd, in Line 3763  sh_elf_create_dynamic_sections (abfd, in
3763          relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);          relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
3764          strcpy (relname, ".rela");          strcpy (relname, ".rela");
3765          strcat (relname, secname);          strcat (relname, secname);
3766            if (bfd_get_section_by_name (abfd, secname))
3767              continue;
3768          s = bfd_make_section (abfd, relname);          s = bfd_make_section (abfd, relname);
3769          if (s == NULL          if (s == NULL
3770              || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)              || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3771              || ! bfd_set_section_alignment (abfd, s, ptralign))              || ! bfd_set_section_alignment (abfd, s, ptralign))
3772            return false;            return FALSE;
3773        }        }
3774    }    }
3775    
# Line 3571  sh_elf_create_dynamic_sections (abfd, in Line 3782  sh_elf_create_dynamic_sections (abfd, in
3782           initialize them at run time.  The linker script puts the .dynbss           initialize them at run time.  The linker script puts the .dynbss
3783           section into the .bss section of the final image.  */           section into the .bss section of the final image.  */
3784        s = bfd_make_section (abfd, ".dynbss");        s = bfd_make_section (abfd, ".dynbss");
3785          htab->sdynbss = s;
3786        if (s == NULL        if (s == NULL
3787            || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))            || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
3788          return false;          return FALSE;
3789    
3790        /* The .rel[a].bss section holds copy relocs.  This section is not        /* The .rel[a].bss section holds copy relocs.  This section is not
3791           normally needed.  We need to create it here, though, so that the           normally needed.  We need to create it here, though, so that the
# Line 3591  sh_elf_create_dynamic_sections (abfd, in Line 3803  sh_elf_create_dynamic_sections (abfd, in
3803            s = bfd_make_section (abfd,            s = bfd_make_section (abfd,
3804                                  (bed->default_use_rela_p                                  (bed->default_use_rela_p
3805                                   ? ".rela.bss" : ".rel.bss"));                                   ? ".rela.bss" : ".rel.bss"));
3806              htab->srelbss = s;
3807            if (s == NULL            if (s == NULL
3808                || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)                || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3809                || ! bfd_set_section_alignment (abfd, s, ptralign))                || ! bfd_set_section_alignment (abfd, s, ptralign))
3810              return false;              return FALSE;
3811          }          }
3812      }      }
3813    
3814    return true;    return TRUE;
3815  }  }
3816    
3817  /* Adjust a symbol defined by a dynamic object and referenced by a  /* Adjust a symbol defined by a dynamic object and referenced by a
# Line 3607  sh_elf_create_dynamic_sections (abfd, in Line 3820  sh_elf_create_dynamic_sections (abfd, in
3820     change the definition to something the rest of the link can     change the definition to something the rest of the link can
3821     understand.  */     understand.  */
3822    
3823  static boolean  static bfd_boolean
3824  sh_elf_adjust_dynamic_symbol (info, h)  sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3825       struct bfd_link_info *info;                                struct elf_link_hash_entry *h)
3826       struct elf_link_hash_entry *h;  {
3827  {    struct elf_sh_link_hash_table *htab;
3828    bfd *dynobj;    struct elf_sh_link_hash_entry *eh;
3829      struct elf_sh_dyn_relocs *p;
3830    asection *s;    asection *s;
3831    unsigned int power_of_two;    unsigned int power_of_two;
3832    
3833    dynobj = elf_hash_table (info)->dynobj;    htab = sh_elf_hash_table (info);
3834    
3835    /* Make sure we know what is going on here.  */    /* Make sure we know what is going on here.  */
3836    BFD_ASSERT (dynobj != NULL    BFD_ASSERT (htab->root.dynobj != NULL
3837                && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)                && (h->needs_plt
3838                    || h->weakdef != NULL                    || h->u.weakdef != NULL
3839                    || ((h->elf_link_hash_flags                    || (h->def_dynamic
3840                         & ELF_LINK_HASH_DEF_DYNAMIC) != 0                        && h->ref_regular
3841                        && (h->elf_link_hash_flags                        && !h->def_regular)));
                           & ELF_LINK_HASH_REF_REGULAR) != 0  
                       && (h->elf_link_hash_flags  
                           & ELF_LINK_HASH_DEF_REGULAR) == 0)));  
3842    
3843    /* If this is a function, put it in the procedure linkage table.  We    /* If this is a function, put it in the procedure linkage table.  We
3844       will fill in the contents of the procedure linkage table later,       will fill in the contents of the procedure linkage table later,
3845       when we know the address of the .got section.  */       when we know the address of the .got section.  */
3846    if (h->type == STT_FUNC    if (h->type == STT_FUNC
3847        || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)        || h->needs_plt)
3848      {      {
3849        if (! info->shared        if (h->plt.refcount <= 0
3850            && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0            || SYMBOL_CALLS_LOCAL (info, h)
3851            && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)            || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3852                  && h->root.type == bfd_link_hash_undefweak))
3853          {          {
3854            /* This case can occur if we saw a PLT reloc in an input            /* This case can occur if we saw a PLT reloc in an input
3855               file, but the symbol was never referred to by a dynamic               file, but the symbol was never referred to by a dynamic
3856               object.  In such a case, we don't actually need to build               object.  In such a case, we don't actually need to build
3857               a procedure linkage table, and we can just do a REL32               a procedure linkage table, and we can just do a REL32
3858               reloc instead.  */               reloc instead.  */
3859            BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);            h->plt.offset = (bfd_vma) -1;
3860            return true;            h->needs_plt = 0;
         }  
   
       /* Make sure this symbol is output as a dynamic symbol.  */  
       if (h->dynindx == -1)  
         {  
           if (! bfd_elf32_link_record_dynamic_symbol (info, h))  
             return false;  
         }  
   
       s = bfd_get_section_by_name (dynobj, ".plt");  
       BFD_ASSERT (s != NULL);  
   
       /* If this is the first .plt entry, make room for the special  
          first entry.  */  
       if (s->_raw_size == 0)  
         s->_raw_size += PLT_ENTRY_SIZE;  
   
       /* If this symbol is not defined in a regular file, and we are  
          not generating a shared library, then set the symbol to this  
          location in the .plt.  This is required to make function  
          pointers compare as equal between the normal executable and  
          the shared library.  */  
       if (! info->shared  
           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)  
         {  
           h->root.u.def.section = s;  
           h->root.u.def.value = s->_raw_size;  
3861          }          }
3862    
3863        h->plt.offset = s->_raw_size;        return TRUE;
   
       /* Make room for this entry.  */  
       s->_raw_size += elf_sh_sizeof_plt (info);  
   
       /* We also need to make an entry in the .got.plt section, which  
          will be placed in the .got section by the linker script.  */  
   
       s = bfd_get_section_by_name (dynobj, ".got.plt");  
       BFD_ASSERT (s != NULL);  
       s->_raw_size += 4;  
   
       /* We also need to make an entry in the .rela.plt section.  */  
   
       s = bfd_get_section_by_name (dynobj, ".rela.plt");  
       BFD_ASSERT (s != NULL);  
       s->_raw_size += sizeof (Elf32_External_Rela);  
   
       return true;  
3864      }      }
3865      else
3866        h->plt.offset = (bfd_vma) -1;
3867    
3868    /* If this is a weak symbol, and there is a real definition, the    /* If this is a weak symbol, and there is a real definition, the
3869       processor independent code will have arranged for us to see the       processor independent code will have arranged for us to see the
3870       real definition first, and we can just use the same value.  */       real definition first, and we can just use the same value.  */
3871    if (h->weakdef != NULL)    if (h->u.weakdef != NULL)
3872      {      {
3873        BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined        BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3874                    || h->weakdef->root.type == bfd_link_hash_defweak);                    || h->u.weakdef->root.type == bfd_link_hash_defweak);
3875        h->root.u.def.section = h->weakdef->root.u.def.section;        h->root.u.def.section = h->u.weakdef->root.u.def.section;
3876        h->root.u.def.value = h->weakdef->root.u.def.value;        h->root.u.def.value = h->u.weakdef->root.u.def.value;
3877        return true;        if (info->nocopyreloc)
3878            h->non_got_ref = h->u.weakdef->non_got_ref;
3879          return TRUE;
3880      }      }
3881    
3882    /* This is a reference to a symbol defined by a dynamic object which    /* This is a reference to a symbol defined by a dynamic object which
# Line 3716  sh_elf_adjust_dynamic_symbol (info, h) Line 3887  sh_elf_adjust_dynamic_symbol (info, h)
3887       For such cases we need not do anything here; the relocations will       For such cases we need not do anything here; the relocations will
3888       be handled correctly by relocate_section.  */       be handled correctly by relocate_section.  */
3889    if (info->shared)    if (info->shared)
3890      return true;      return TRUE;
3891    
3892    /* If there are no references to this symbol that do not use the    /* If there are no references to this symbol that do not use the
3893       GOT, we don't need to generate a copy reloc.  */       GOT, we don't need to generate a copy reloc.  */
3894    if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)    if (!h->non_got_ref)
3895      return true;      return TRUE;
3896    
3897      /* If -z nocopyreloc was given, we won't generate them either.  */
3898      if (info->nocopyreloc)
3899        {
3900          h->non_got_ref = 0;
3901          return TRUE;
3902        }
3903    
3904      eh = (struct elf_sh_link_hash_entry *) h;
3905      for (p = eh->dyn_relocs; p != NULL; p = p->next)
3906        {
3907          s = p->sec->output_section;
3908          if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
3909            break;
3910        }
3911    
3912      /* If we didn't find any dynamic relocs in sections which needs the
3913         copy reloc, then we'll be keeping the dynamic relocs and avoiding
3914         the copy reloc.  */
3915      if (p == NULL)
3916        {
3917          h->non_got_ref = 0;
3918          return TRUE;
3919        }
3920    
3921    /* We must allocate the symbol in our .dynbss section, which will    /* We must allocate the symbol in our .dynbss section, which will
3922       become part of the .bss section of the executable.  There will be       become part of the .bss section of the executable.  There will be
# Line 3733  sh_elf_adjust_dynamic_symbol (info, h) Line 3928  sh_elf_adjust_dynamic_symbol (info, h)
3928       both the dynamic object and the regular object will refer to the       both the dynamic object and the regular object will refer to the
3929       same memory location for the variable.  */       same memory location for the variable.  */
3930    
3931    s = bfd_get_section_by_name (dynobj, ".dynbss");    s = htab->sdynbss;
3932    BFD_ASSERT (s != NULL);    BFD_ASSERT (s != NULL);
3933    
3934    /* We must generate a R_SH_COPY reloc to tell the dynamic linker to    /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
# Line 3744  sh_elf_adjust_dynamic_symbol (info, h) Line 3939  sh_elf_adjust_dynamic_symbol (info, h)
3939      {      {
3940        asection *srel;        asection *srel;
3941    
3942        srel = bfd_get_section_by_name (dynobj, ".rela.bss");        srel = htab->srelbss;
3943        BFD_ASSERT (srel != NULL);        BFD_ASSERT (srel != NULL);
3944        srel->_raw_size += sizeof (Elf32_External_Rela);        srel->size += sizeof (Elf32_External_Rela);
3945        h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;        h->needs_copy = 1;
3946      }      }
3947    
3948    /* We need to figure out the alignment required for this symbol.  I    /* We need to figure out the alignment required for this symbol.  I
# Line 3757  sh_elf_adjust_dynamic_symbol (info, h) Line 3952  sh_elf_adjust_dynamic_symbol (info, h)
3952      power_of_two = 3;      power_of_two = 3;
3953    
3954    /* Apply the required alignment.  */    /* Apply the required alignment.  */
3955    s->_raw_size = BFD_ALIGN (s->_raw_size,    s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
3956                              (bfd_size_type) (1 << power_of_two));    if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
   if (power_of_two > bfd_get_section_alignment (dynobj, s))  
3957      {      {
3958        if (! bfd_set_section_alignment (dynobj, s, power_of_two))        if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
3959          return false;          return FALSE;
3960      }      }
3961    
3962    /* Define the symbol as being at this point in the section.  */    /* Define the symbol as being at this point in the section.  */
3963    h->root.u.def.section = s;    h->root.u.def.section = s;
3964    h->root.u.def.value = s->_raw_size;    h->root.u.def.value = s->size;
3965    
3966    /* Increment the section size to make room for the symbol.  */    /* Increment the section size to make room for the symbol.  */
3967    s->_raw_size += h->size;    s->size += h->size;
3968    
3969    return true;    return TRUE;
3970    }
3971    
3972    /* Allocate space in .plt, .got and associated reloc sections for
3973       dynamic relocs.  */
3974    
3975    static bfd_boolean
3976    allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3977    {
3978      struct bfd_link_info *info;
3979      struct elf_sh_link_hash_table *htab;
3980      struct elf_sh_link_hash_entry *eh;
3981      struct elf_sh_dyn_relocs *p;
3982    
3983      if (h->root.type == bfd_link_hash_indirect)
3984        return TRUE;
3985    
3986      if (h->root.type == bfd_link_hash_warning)
3987        /* When warning symbols are created, they **replace** the "real"
3988           entry in the hash table, thus we never get to see the real
3989           symbol in a hash traversal.  So look at it now.  */
3990        h = (struct elf_link_hash_entry *) h->root.u.i.link;
3991    
3992      info = (struct bfd_link_info *) inf;
3993      htab = sh_elf_hash_table (info);
3994    
3995      eh = (struct elf_sh_link_hash_entry *) h;
3996      if ((h->got.refcount > 0
3997           || h->forced_local)
3998          && eh->gotplt_refcount > 0)
3999        {
4000          /* The symbol has been forced local, or we have some direct got refs,
4001             so treat all the gotplt refs as got refs. */
4002          h->got.refcount += eh->gotplt_refcount;
4003          if (h->plt.refcount >= eh->gotplt_refcount)
4004            h->plt.refcount -= eh->gotplt_refcount;
4005        }
4006    
4007      if (htab->root.dynamic_sections_created
4008          && h->plt.refcount > 0
4009          && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4010              || h->root.type != bfd_link_hash_undefweak))
4011        {
4012          /* Make sure this symbol is output as a dynamic symbol.
4013             Undefined weak syms won't yet be marked as dynamic.  */
4014          if (h->dynindx == -1
4015              && !h->forced_local)
4016            {
4017              if (! bfd_elf_link_record_dynamic_symbol (info, h))
4018                return FALSE;
4019            }
4020    
4021          if (info->shared
4022              || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
4023            {
4024              asection *s = htab->splt;
4025    
4026              /* If this is the first .plt entry, make room for the special
4027                 first entry.  */
4028              if (s->size == 0)
4029                s->size += PLT_ENTRY_SIZE;
4030    
4031              h->plt.offset = s->size;
4032    
4033              /* If this symbol is not defined in a regular file, and we are
4034                 not generating a shared library, then set the symbol to this
4035                 location in the .plt.  This is required to make function
4036                 pointers compare as equal between the normal executable and
4037                 the shared library.  */
4038              if (! info->shared
4039                  && !h->def_regular)
4040                {
4041                  h->root.u.def.section = s;
4042                  h->root.u.def.value = h->plt.offset;
4043                }
4044    
4045              /* Make room for this entry.  */
4046              s->size += PLT_ENTRY_SIZE;
4047    
4048              /* We also need to make an entry in the .got.plt section, which
4049                 will be placed in the .got section by the linker script.  */
4050              htab->sgotplt->size += 4;
4051    
4052              /* We also need to make an entry in the .rel.plt section.  */
4053              htab->srelplt->size += sizeof (Elf32_External_Rela);
4054            }
4055          else
4056            {
4057              h->plt.offset = (bfd_vma) -1;
4058              h->needs_plt = 0;
4059            }
4060        }
4061      else
4062        {
4063          h->plt.offset = (bfd_vma) -1;
4064          h->needs_plt = 0;
4065        }
4066    
4067      if (h->got.refcount > 0)
4068        {
4069          asection *s;
4070          bfd_boolean dyn;
4071          int tls_type = sh_elf_hash_entry (h)->tls_type;
4072    
4073          /* Make sure this symbol is output as a dynamic symbol.
4074             Undefined weak syms won't yet be marked as dynamic.  */
4075          if (h->dynindx == -1
4076              && !h->forced_local)
4077            {
4078              if (! bfd_elf_link_record_dynamic_symbol (info, h))
4079                return FALSE;
4080            }
4081    
4082          s = htab->sgot;
4083          h->got.offset = s->size;
4084          s->size += 4;
4085          /* R_SH_TLS_GD needs 2 consecutive GOT slots.  */
4086          if (tls_type == GOT_TLS_GD)
4087            s->size += 4;
4088          dyn = htab->root.dynamic_sections_created;
4089          /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
4090             R_SH_TLS_GD needs one if local symbol and two if global.  */
4091          if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
4092              || (tls_type == GOT_TLS_IE && dyn))
4093            htab->srelgot->size += sizeof (Elf32_External_Rela);
4094          else if (tls_type == GOT_TLS_GD)
4095            htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
4096          else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4097                    || h->root.type != bfd_link_hash_undefweak)
4098                   && (info->shared
4099                       || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
4100            htab->srelgot->size += sizeof (Elf32_External_Rela);
4101        }
4102      else
4103        h->got.offset = (bfd_vma) -1;
4104    
4105    #ifdef INCLUDE_SHMEDIA
4106      if (eh->datalabel_got.refcount > 0)
4107        {
4108          asection *s;
4109          bfd_boolean dyn;
4110    
4111          /* Make sure this symbol is output as a dynamic symbol.
4112             Undefined weak syms won't yet be marked as dynamic.  */
4113          if (h->dynindx == -1
4114              && !h->forced_local)
4115            {
4116              if (! bfd_elf_link_record_dynamic_symbol (info, h))
4117                return FALSE;
4118            }
4119    
4120          s = htab->sgot;
4121          eh->datalabel_got.offset = s->size;
4122          s->size += 4;
4123          dyn = htab->root.dynamic_sections_created;
4124          if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
4125            htab->srelgot->size += sizeof (Elf32_External_Rela);
4126        }
4127      else
4128        eh->datalabel_got.offset = (bfd_vma) -1;
4129    #endif
4130    
4131      if (eh->dyn_relocs == NULL)
4132        return TRUE;
4133    
4134      /* In the shared -Bsymbolic case, discard space allocated for
4135         dynamic pc-relative relocs against symbols which turn out to be
4136         defined in regular objects.  For the normal shared case, discard
4137         space for pc-relative relocs that have become local due to symbol
4138         visibility changes.  */
4139    
4140      if (info->shared)
4141        {
4142          if (SYMBOL_CALLS_LOCAL (info, h))
4143            {
4144              struct elf_sh_dyn_relocs **pp;
4145    
4146              for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4147                {
4148                  p->count -= p->pc_count;
4149                  p->pc_count = 0;
4150                  if (p->count == 0)
4151                    *pp = p->next;
4152                  else
4153                    pp = &p->next;
4154                }
4155            }
4156    
4157          /* Also discard relocs on undefined weak syms with non-default
4158             visibility.  */
4159          if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4160              && h->root.type == bfd_link_hash_undefweak)
4161            eh->dyn_relocs = NULL;
4162        }
4163      else
4164        {
4165          /* For the non-shared case, discard space for relocs against
4166             symbols which turn out to need copy relocs or are not
4167             dynamic.  */
4168    
4169          if (!h->non_got_ref
4170              && ((h->def_dynamic
4171                   && !h->def_regular)
4172                  || (htab->root.dynamic_sections_created
4173                      && (h->root.type == bfd_link_hash_undefweak
4174                          || h->root.type == bfd_link_hash_undefined))))
4175            {
4176              /* Make sure this symbol is output as a dynamic symbol.
4177                 Undefined weak syms won't yet be marked as dynamic.  */
4178              if (h->dynindx == -1
4179                  && !h->forced_local)
4180                {
4181                  if (! bfd_elf_link_record_dynamic_symbol (info, h))
4182                    return FALSE;
4183                }
4184    
4185              /* If that succeeded, we know we'll be keeping all the
4186                 relocs.  */
4187              if (h->dynindx != -1)
4188                goto keep;
4189            }
4190    
4191          eh->dyn_relocs = NULL;
4192    
4193        keep: ;
4194        }
4195    
4196      /* Finally, allocate space.  */
4197      for (p = eh->dyn_relocs; p != NULL; p = p->next)
4198        {
4199          asection *sreloc = elf_section_data (p->sec)->sreloc;
4200          sreloc->size += p->count * sizeof (Elf32_External_Rela);
4201        }
4202    
4203      return TRUE;
4204    }
4205    
4206    /* Find any dynamic relocs that apply to read-only sections.  */
4207    
4208    static bfd_boolean
4209    readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4210    {
4211      struct elf_sh_link_hash_entry *eh;
4212      struct elf_sh_dyn_relocs *p;
4213    
4214      if (h->root.type == bfd_link_hash_warning)
4215        h = (struct elf_link_hash_entry *) h->root.u.i.link;
4216    
4217      eh = (struct elf_sh_link_hash_entry *) h;
4218      for (p = eh->dyn_relocs; p != NULL; p = p->next)
4219        {
4220          asection *s = p->sec->output_section;
4221    
4222          if (s != NULL && (s->flags & SEC_READONLY) != 0)
4223            {
4224              struct bfd_link_info *info = (struct bfd_link_info *) inf;
4225    
4226              info->flags |= DF_TEXTREL;
4227    
4228              /* Not an error, just cut short the traversal.  */
4229              return FALSE;
4230            }
4231        }
4232      return TRUE;
4233  }  }
4234    
4235  /* Set the sizes of the dynamic sections.  */  /* Set the sizes of the dynamic sections.  */
4236    
4237  static boolean  static bfd_boolean
4238  sh_elf_size_dynamic_sections (output_bfd, info)  sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4239       bfd *output_bfd ATTRIBUTE_UNUSED;                                struct bfd_link_info *info)
      struct bfd_link_info *info;  
4240  {  {
4241      struct elf_sh_link_hash_table *htab;
4242    bfd *dynobj;    bfd *dynobj;
4243    asection *s;    asection *s;
4244    boolean plt;    bfd_boolean relocs;
4245    boolean relocs;    bfd *ibfd;
4246    
4247    dynobj = elf_hash_table (info)->dynobj;    htab = sh_elf_hash_table (info);
4248      dynobj = htab->root.dynobj;
4249    BFD_ASSERT (dynobj != NULL);    BFD_ASSERT (dynobj != NULL);
4250    
4251    if (elf_hash_table (info)->dynamic_sections_created)    if (htab->root.dynamic_sections_created)
4252      {      {
4253        /* Set the contents of the .interp section to the interpreter.  */        /* Set the contents of the .interp section to the interpreter.  */
4254        if (! info->shared)        if (info->executable)
4255          {          {
4256            s = bfd_get_section_by_name (dynobj, ".interp");            s = bfd_get_section_by_name (dynobj, ".interp");
4257            BFD_ASSERT (s != NULL);            BFD_ASSERT (s != NULL);
4258            s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;            s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4259            s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;            s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4260          }          }
4261      }      }
   else  
     {  
       /* We may have created entries in the .rela.got section.  
          However, if we are not creating the dynamic sections, we will  
          not actually use these entries.  Reset the size of .rela.got,  
          which will cause it to get stripped from the output file  
          below.  */  
       s = bfd_get_section_by_name (dynobj, ".rela.got");  
       if (s != NULL)  
         s->_raw_size = 0;  
     }  
   
   /* If this is a -Bsymbolic shared link, then we need to discard all  
      PC relative relocs against symbols defined in a regular object.  
      We allocated space for them in the check_relocs routine, but we  
      will not fill them in in the relocate_section routine.  */  
   if (info->shared && info->symbolic)  
     sh_elf_link_hash_traverse (sh_elf_hash_table (info),  
                                sh_elf_discard_copies,  
                                (PTR) NULL);  
   
   /* The check_relocs and adjust_dynamic_symbol entry points have  
      determined the sizes of the various dynamic sections.  Allocate  
      memory for them.  */  
   plt = false;  
   relocs = false;  
   for (s = dynobj->sections; s != NULL; s = s->next)  
     {  
       const char *name;  
       boolean strip;  
   
       if ((s->flags & SEC_LINKER_CREATED) == 0)  
         continue;  
4262    
4263        /* It's OK to base decisions on the section name, because none    /* Set up .got offsets for local syms, and space for local dynamic
4264           of the dynobj section names depend upon the input files.  */       relocs.  */
4265        name = bfd_get_section_name (dynobj, s);    for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4266        {
4267          bfd_signed_vma *local_got;
4268          bfd_signed_vma *end_local_got;
4269          char *local_tls_type;
4270          bfd_size_type locsymcount;
4271          Elf_Internal_Shdr *symtab_hdr;
4272          asection *srel;
4273    
4274        strip = false;        if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4275            continue;
4276    
4277        if (strcmp (name, ".plt") == 0)        for (s = ibfd->sections; s != NULL; s = s->next)
4278          {          {
4279            if (s->_raw_size == 0)            struct elf_sh_dyn_relocs *p;
4280              {  
4281                /* Strip this section if we don't need it; see the            for (p = ((struct elf_sh_dyn_relocs *)
4282                   comment below.  */                      elf_section_data (s)->local_dynrel);
4283                strip = true;                 p != NULL;
4284              }                 p = p->next)
           else  
4285              {              {
4286                /* Remember whether there is a PLT.  */                if (! bfd_is_abs_section (p->sec)
4287                plt = true;                    && bfd_is_abs_section (p->sec->output_section))
4288                    {
4289                      /* Input section has been discarded, either because
4290                         it is a copy of a linkonce section or due to
4291                         linker script /DISCARD/, so we'll be discarding
4292                         the relocs too.  */
4293                    }
4294                  else if (p->count != 0)
4295                    {
4296                      srel = elf_section_data (p->sec)->sreloc;
4297                      srel->size += p->count * sizeof (Elf32_External_Rela);
4298                      if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4299                        info->flags |= DF_TEXTREL;
4300                    }
4301              }              }
4302          }          }
4303        else if (strncmp (name, ".rela", 5) == 0)  
4304          {        local_got = elf_local_got_refcounts (ibfd);
4305            if (s->_raw_size == 0)        if (!local_got)
4306              {          continue;
4307                /* If we don't need this section, strip it from the  
4308                   output file.  This is mostly to handle .rela.bss and        symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4309                   .rela.plt.  We must create both sections in        locsymcount = symtab_hdr->sh_info;
4310                   create_dynamic_sections, because they must be created  #ifdef INCLUDE_SHMEDIA
4311                   before the linker maps input sections to output        /* Count datalabel local GOT.  */
4312                   sections.  The linker does that before        locsymcount *= 2;
4313                   adjust_dynamic_symbol is called, and it is that  #endif
4314                   function which decides whether anything needs to go        end_local_got = local_got + locsymcount;
4315                   into these sections.  */        local_tls_type = sh_elf_local_got_tls_type (ibfd);
4316                strip = true;        s = htab->sgot;
4317          srel = htab->srelgot;
4318          for (; local_got < end_local_got; ++local_got)
4319            {
4320              if (*local_got > 0)
4321                {
4322                  *local_got = s->size;
4323                  s->size += 4;
4324                  if (*local_tls_type == GOT_TLS_GD)
4325                    s->size += 4;
4326                  if (info->shared)
4327                    srel->size += sizeof (Elf32_External_Rela);
4328              }              }
4329            else            else
4330              {              *local_got = (bfd_vma) -1;
4331                /* Remember whether there are any reloc sections other            ++local_tls_type;
4332                   than .rela.plt.  */          }
4333                if (strcmp (name, ".rela.plt") != 0)      }
                 relocs = true;  
4334    
4335                /* We use the reloc_count field as a counter if we need    if (htab->tls_ldm_got.refcount > 0)
4336                   to copy relocs into the output file.  */      {
4337                s->reloc_count = 0;        /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4338              }           relocs.  */
4339          htab->tls_ldm_got.offset = htab->sgot->size;
4340          htab->sgot->size += 8;
4341          htab->srelgot->size += sizeof (Elf32_External_Rela);
4342        }
4343      else
4344        htab->tls_ldm_got.offset = -1;
4345    
4346      /* Allocate global sym .plt and .got entries, and space for global
4347         sym dynamic relocs.  */
4348      elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
4349    
4350      /* We now have determined the sizes of the various dynamic sections.
4351         Allocate memory for them.  */
4352      relocs = FALSE;
4353      for (s = dynobj->sections; s != NULL; s = s->next)
4354        {
4355          if ((s->flags & SEC_LINKER_CREATED) == 0)
4356            continue;
4357    
4358          if (s == htab->splt
4359              || s == htab->sgot
4360              || s == htab->sgotplt)
4361            {
4362              /* Strip this section if we don't need it; see the
4363                 comment below.  */
4364          }          }
4365        else if (strncmp (name, ".got", 4) != 0)        else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4366            {
4367              if (s->size != 0 && s != htab->srelplt)
4368                relocs = TRUE;
4369    
4370              /* We use the reloc_count field as a counter if we need
4371                 to copy relocs into the output file.  */
4372              s->reloc_count = 0;
4373            }
4374          else
4375          {          {
4376            /* It's not one of our sections, so don't allocate space.  */            /* It's not one of our sections, so don't allocate space.  */
4377            continue;            continue;
4378          }          }
4379    
4380        if (strip)        if (s->size == 0)
4381          {          {
4382              /* If we don't need this section, strip it from the
4383                 output file.  This is mostly to handle .rela.bss and
4384                 .rela.plt.  We must create both sections in
4385                 create_dynamic_sections, because they must be created
4386                 before the linker maps input sections to output
4387                 sections.  The linker does that before
4388                 adjust_dynamic_symbol is called, and it is that
4389                 function which decides whether anything needs to go
4390                 into these sections.  */
4391    
4392            _bfd_strip_section_from_output (info, s);            _bfd_strip_section_from_output (info, s);
4393            continue;            continue;
4394          }          }
4395    
4396        /* Allocate memory for the section contents.  */        /* Allocate memory for the section contents.  We use bfd_zalloc
4397        s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);           here in case unused entries are not reclaimed before the
4398        if (s->contents == NULL && s->_raw_size != 0)           section's contents are written out.  This should not happen,
4399          return false;           but this way if it does, we get a R_SH_NONE reloc instead
4400             of garbage.  */
4401          s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4402          if (s->contents == NULL)
4403            return FALSE;
4404      }      }
4405    
4406    if (elf_hash_table (info)->dynamic_sections_created)    if (htab->root.dynamic_sections_created)
4407      {      {
4408        /* Add some entries to the .dynamic section.  We fill in the        /* Add some entries to the .dynamic section.  We fill in the
4409           values later, in sh_elf_finish_dynamic_sections, but we           values later, in sh_elf_finish_dynamic_sections, but we
# Line 3908  sh_elf_size_dynamic_sections (output_bfd Line 4411  sh_elf_size_dynamic_sections (output_bfd
4411           the .dynamic section.  The DT_DEBUG entry is filled in by the           the .dynamic section.  The DT_DEBUG entry is filled in by the
4412           dynamic linker and used by the debugger.  */           dynamic linker and used by the debugger.  */
4413  #define add_dynamic_entry(TAG, VAL) \  #define add_dynamic_entry(TAG, VAL) \
4414    bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))    _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4415    
4416        if (! info->shared)        if (info->executable)
4417          {          {
4418            if (!add_dynamic_entry (DT_DEBUG, 0))            if (! add_dynamic_entry (DT_DEBUG, 0))
4419              return false;              return FALSE;
4420          }          }
4421    
4422        if (plt)        if (htab->splt->size != 0)
4423          {          {
4424            if (!add_dynamic_entry (DT_PLTGOT, 0)            if (! add_dynamic_entry (DT_PLTGOT, 0)
4425                || !add_dynamic_entry (DT_PLTRELSZ, 0)                || ! add_dynamic_entry (DT_PLTRELSZ, 0)
4426                || !add_dynamic_entry (DT_PLTREL, DT_RELA)                || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
4427                || !add_dynamic_entry (DT_JMPREL, 0))                || ! add_dynamic_entry (DT_JMPREL, 0))
4428              return false;              return FALSE;
4429          }          }
4430    
4431        if (relocs)        if (relocs)
4432          {          {
4433            if (!add_dynamic_entry (DT_RELA, 0)            if (! add_dynamic_entry (DT_RELA, 0)
4434                || !add_dynamic_entry (DT_RELASZ, 0)                || ! add_dynamic_entry (DT_RELASZ, 0)
4435                || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))                || ! add_dynamic_entry (DT_RELAENT,
4436              return false;                                        sizeof (Elf32_External_Rela)))
4437          }              return FALSE;
4438    
4439              /* If any dynamic relocs apply to a read-only section,
4440                 then we need a DT_TEXTREL entry.  */
4441              if ((info->flags & DF_TEXTREL) == 0)
4442                elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
4443    
4444        if ((info->flags & DF_TEXTREL) != 0)            if ((info->flags & DF_TEXTREL) != 0)
4445          {              {
4446            if (!add_dynamic_entry (DT_TEXTREL, 0))                if (! add_dynamic_entry (DT_TEXTREL, 0))
4447              return false;                  return FALSE;
4448                }
4449          }          }
4450      }      }
4451  #undef add_dynamic_entry  #undef add_dynamic_entry
4452    
4453    return true;    return TRUE;
 }  
   
 /* This function is called via sh_elf_link_hash_traverse if we are  
    creating a shared object with -Bsymbolic.  It discards the space  
    allocated to copy PC relative relocs against symbols which are  
    defined in regular objects.  We allocated space for them in the  
    check_relocs routine, but we won't fill them in in the  
    relocate_section routine.  */  
   
 static boolean  
 sh_elf_discard_copies (h, ignore)  
      struct elf_sh_link_hash_entry *h;  
      PTR ignore ATTRIBUTE_UNUSED;  
 {  
   struct elf_sh_pcrel_relocs_copied *s;  
   
   if (h->root.root.type == bfd_link_hash_warning)  
     h = (struct elf_sh_link_hash_entry *) h->root.root.u.i.link;  
   
   /* We only discard relocs for symbols defined in a regular object.  */  
   if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)  
     return true;  
   
   for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)  
     s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);  
   
   return true;  
4454  }  }
4455    
4456  /* Relocate an SH ELF section.  */  /* Relocate an SH ELF section.  */
4457    
4458  static boolean  static bfd_boolean
4459  sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,  sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
4460                           contents, relocs, local_syms, local_sections)                           bfd *input_bfd, asection *input_section,
4461       bfd *output_bfd;                           bfd_byte *contents, Elf_Internal_Rela *relocs,
4462       struct bfd_link_info *info;                           Elf_Internal_Sym *local_syms,
4463       bfd *input_bfd;                           asection **local_sections)
      asection *input_section;  
      bfd_byte *contents;  
      Elf_Internal_Rela *relocs;  
      Elf_Internal_Sym *local_syms;  
      asection **local_sections;  
4464  {  {
4465      struct elf_sh_link_hash_table *htab;
4466    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
4467    struct elf_link_hash_entry **sym_hashes;    struct elf_link_hash_entry **sym_hashes;
4468    Elf_Internal_Rela *rel, *relend;    Elf_Internal_Rela *rel, *relend;
# Line 3994  sh_elf_relocate_section (output_bfd, inf Line 4472  sh_elf_relocate_section (output_bfd, inf
4472    asection *sgotplt;    asection *sgotplt;
4473    asection *splt;    asection *splt;
4474    asection *sreloc;    asection *sreloc;
4475      asection *srelgot;
4476    
4477      htab = sh_elf_hash_table (info);
4478    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4479    sym_hashes = elf_sym_hashes (input_bfd);    sym_hashes = elf_sym_hashes (input_bfd);
4480    dynobj = elf_hash_table (info)->dynobj;    dynobj = htab->root.dynobj;
4481    local_got_offsets = elf_local_got_offsets (input_bfd);    local_got_offsets = elf_local_got_offsets (input_bfd);
4482    
4483    sgot = NULL;    sgot = htab->sgot;
4484    sgotplt = NULL;    sgotplt = htab->sgotplt;
4485    splt = NULL;    splt = htab->splt;
4486    sreloc = NULL;    sreloc = NULL;
4487      srelgot = NULL;
4488    
4489    rel = relocs;    rel = relocs;
4490    relend = relocs + input_section->reloc_count;    relend = relocs + input_section->reloc_count;
# Line 4019  sh_elf_relocate_section (output_bfd, inf Line 4500  sh_elf_relocate_section (output_bfd, inf
4500        bfd_vma addend = (bfd_vma) 0;        bfd_vma addend = (bfd_vma) 0;
4501        bfd_reloc_status_type r;        bfd_reloc_status_type r;
4502        int seen_stt_datalabel = 0;        int seen_stt_datalabel = 0;
4503          bfd_vma off;
4504          int tls_type;
4505    
4506        r_symndx = ELF32_R_SYM (rel->r_info);        r_symndx = ELF32_R_SYM (rel->r_info);
4507    
4508        r_type = ELF32_R_TYPE (rel->r_info);        r_type = ELF32_R_TYPE (rel->r_info);
4509    
4510        /* Many of the relocs are only used for relaxing, and are        /* Many of the relocs are only used for relaxing, and are
4511           handled entirely by the relaxation code.  */           handled entirely by the relaxation code.  */
4512        if (r_type > (int) R_SH_LAST_INVALID_RELOC        if (r_type >= (int) R_SH_GNU_VTINHERIT
4513            && r_type < (int) R_SH_LOOP_START)            && r_type <= (int) R_SH_LABEL)
4514          continue;          continue;
4515        if (r_type == (int) R_SH_NONE)        if (r_type == (int) R_SH_NONE)
4516          continue;          continue;
# Line 4040  sh_elf_relocate_section (output_bfd, inf Line 4523  sh_elf_relocate_section (output_bfd, inf
4523                && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)                && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
4524            || (   r_type >= (int) R_SH_FIRST_INVALID_RELOC_4            || (   r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
4525                && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)                && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
4526              || (   r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
4527                  && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
4528            || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2            || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
4529                && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))                && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
4530          {          {
4531            bfd_set_error (bfd_error_bad_value);            bfd_set_error (bfd_error_bad_value);
4532            return false;            return FALSE;
4533          }          }
4534    
4535        howto = sh_elf_howto_table + r_type;        howto = sh_elf_howto_table + r_type;
4536    
4537        /* For relocs that aren't partial_inplace, we get the addend from        /* For relocs that aren't partial_inplace, we get the addend from
4538           the relocation.  */           the relocation.  */
4539        if (! howto->partial_inplace)        if (! howto->partial_inplace)
4540          addend = rel->r_addend;          addend = rel->r_addend;
4541    
# Line 4072  sh_elf_relocate_section (output_bfd, inf Line 4557  sh_elf_relocate_section (output_bfd, inf
4557               (info,               (info,
4558                _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),                _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4559                input_bfd, input_section, rel->r_offset));                input_bfd, input_section, rel->r_offset));
4560            if (info->relocateable)            if (info->relocatable)
4561              {              {
4562                /* This is a relocateable link.  We don't have to change                /* This is a relocatable link.  We don't have to change
4563                   anything, unless the reloc is against a section symbol,                   anything, unless the reloc is against a section symbol,
4564                   in which case we have to adjust according to where the                   in which case we have to adjust according to where the
4565                   section symbol winds up in the output section.  */                   section symbol winds up in the output section.  */
# Line 4111  sh_elf_relocate_section (output_bfd, inf Line 4596  sh_elf_relocate_section (output_bfd, inf
4596              }              }
4597            else if (! howto->partial_inplace)            else if (! howto->partial_inplace)
4598              {              {
4599                relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);                relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4600                addend = rel->r_addend;                addend = rel->r_addend;
4601              }              }
4602            else if ((sec->flags & SEC_MERGE)            else if ((sec->flags & SEC_MERGE)
# Line 4122  sh_elf_relocate_section (output_bfd, inf Line 4607  sh_elf_relocate_section (output_bfd, inf
4607                if (howto->rightshift || howto->src_mask != 0xffffffff)                if (howto->rightshift || howto->src_mask != 0xffffffff)
4608                  {                  {
4609                    (*_bfd_error_handler)                    (*_bfd_error_handler)
4610                      (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),                      (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4611                       bfd_archive_filename (input_bfd),                       input_bfd, input_section,
                      bfd_get_section_name (input_bfd, input_section),  
4612                       (long) rel->r_offset, howto->name);                       (long) rel->r_offset, howto->name);
4613                    return false;                    return FALSE;
4614                  }                  }
4615    
4616                addend = bfd_get_32 (input_bfd, contents + rel->r_offset);                addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4617                msec = sec;                msec = sec;
4618                addend =                addend =
4619                  _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)                  _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4620                  - relocation;                  - relocation;
4621                addend += msec->output_section->vma + msec->output_offset;                addend += msec->output_section->vma + msec->output_offset;
# Line 4141  sh_elf_relocate_section (output_bfd, inf Line 4625  sh_elf_relocate_section (output_bfd, inf
4625          }          }
4626        else        else
4627          {          {
4628              /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro.  */
4629    
4630            /* Section symbol are never (?) placed in the hash table, so            /* Section symbol are never (?) placed in the hash table, so
4631               we can just ignore hash relocations when creating a               we can just ignore hash relocations when creating a
4632               relocateable object file.  */               relocatable object file.  */
4633            if (info->relocateable)            if (info->relocatable)
4634              continue;              continue;
4635    
4636            h = sym_hashes[r_symndx - symtab_hdr->sh_info];            h = sym_hashes[r_symndx - symtab_hdr->sh_info];
# Line 4162  sh_elf_relocate_section (output_bfd, inf Line 4648  sh_elf_relocate_section (output_bfd, inf
4648            if (h->root.type == bfd_link_hash_defined            if (h->root.type == bfd_link_hash_defined
4649                || h->root.type == bfd_link_hash_defweak)                || h->root.type == bfd_link_hash_defweak)
4650              {              {
4651                  bfd_boolean dyn;
4652    
4653                  dyn = htab->root.dynamic_sections_created;
4654                sec = h->root.u.def.section;                sec = h->root.u.def.section;
4655                /* In these cases, we don't need the relocation value.                /* In these cases, we don't need the relocation value.
4656                   We check specially because in some obscure cases                   We check specially because in some obscure cases
# Line 4182  sh_elf_relocate_section (output_bfd, inf Line 4671  sh_elf_relocate_section (output_bfd, inf
4671                         || r_type == R_SH_GOT_MEDLOW16                         || r_type == R_SH_GOT_MEDLOW16
4672                         || r_type == R_SH_GOT_MEDHI16                         || r_type == R_SH_GOT_MEDHI16
4673                         || r_type == R_SH_GOT_HI16)                         || r_type == R_SH_GOT_HI16)
4674                        && elf_hash_table (info)->dynamic_sections_created                        && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4675                        && (! info->shared                        && (! info->shared
4676                            || (! info->symbolic && h->dynindx != -1)                            || (! info->symbolic && h->dynindx != -1)
4677                            || (h->elf_link_hash_flags                            || !h->def_regular))
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))  
4678                    /* The cases above are those in which relocation is                    /* The cases above are those in which relocation is
4679                       overwritten in the switch block below.  The cases                       overwritten in the switch block below.  The cases
4680                       below are those in which we must defer relocation                       below are those in which we must defer relocation
# Line 4194  sh_elf_relocate_section (output_bfd, inf Line 4682  sh_elf_relocate_section (output_bfd, inf
4682                       addresses when creating a shared library.  */                       addresses when creating a shared library.  */
4683                    || (info->shared                    || (info->shared
4684                        && ((! info->symbolic && h->dynindx != -1)                        && ((! info->symbolic && h->dynindx != -1)
4685                            || (h->elf_link_hash_flags                            || !h->def_regular)
                               & ELF_LINK_HASH_DEF_REGULAR) == 0)  
4686                        && ((r_type == R_SH_DIR32                        && ((r_type == R_SH_DIR32
4687                             && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL                             && !h->forced_local)
                                 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))  
4688                            || r_type == R_SH_REL32)                            || r_type == R_SH_REL32)
4689                        && ((input_section->flags & SEC_ALLOC) != 0                        && ((input_section->flags & SEC_ALLOC) != 0
4690                            /* DWARF will emit R_SH_DIR32 relocations in its                            /* DWARF will emit R_SH_DIR32 relocations in its
4691                               sections against symbols defined externally                               sections against symbols defined externally
4692                               in shared libraries.  We can't do anything                               in shared libraries.  We can't do anything
4693                               with them here.  */                               with them here.  */
4694                            || (input_section->flags & SEC_DEBUGGING) != 0)))                            || ((input_section->flags & SEC_DEBUGGING) != 0
4695                                  && h->def_dynamic)))
4696                      /* Dynamic relocs are not propagated for SEC_DEBUGGING
4697                         sections because such sections are not SEC_ALLOC and
4698                         thus ld.so will not process them.  */
4699                      || (sec->output_section == NULL
4700                          && ((input_section->flags & SEC_DEBUGGING) != 0
4701                              && h->def_dynamic))
4702                      || (sec->output_section == NULL
4703                          && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
4704                              || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
4705                  relocation = 0;                  relocation = 0;
4706                else if (sec->output_section == NULL)                else if (sec->output_section == NULL)
4707                  {                  {
4708                    (*_bfd_error_handler)                    (*_bfd_error_handler)
4709                      (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),                      (_("%B(%A): unresolvable relocation against symbol `%s'"),
4710                       bfd_archive_filename (input_bfd), h->root.root.string,                       input_bfd, input_section, h->root.root.string);
4711                       bfd_get_section_name (input_bfd, input_section));                    return FALSE;
                   relocation = 0;  
4712                  }                  }
4713                else                else
4714                  relocation = ((h->root.u.def.value                  relocation = ((h->root.u.def.value
# Line 4227  sh_elf_relocate_section (output_bfd, inf Line 4722  sh_elf_relocate_section (output_bfd, inf
4722              }              }
4723            else if (h->root.type == bfd_link_hash_undefweak)            else if (h->root.type == bfd_link_hash_undefweak)
4724              relocation = 0;              relocation = 0;
4725            else if (info->shared            else if (info->unresolved_syms_in_objects == RM_IGNORE
4726                 && (!info->symbolic || info->allow_shlib_undefined)                     && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
                && !info->no_undefined)  
4727              relocation = 0;              relocation = 0;
4728            else            else
4729              {              {
4730                if (! ((*info->callbacks->undefined_symbol)                if (! info->callbacks->undefined_symbol
4731                       (info, h->root.root.string, input_bfd,                    (info, h->root.root.string, input_bfd,
4732                        input_section, rel->r_offset, true)))                     input_section, rel->r_offset,
4733                  return false;                     (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
4734                        || ELF_ST_VISIBILITY (h->other))))
4735                    return FALSE;
4736                relocation = 0;                relocation = 0;
4737              }              }
4738          }          }
# Line 4252  sh_elf_relocate_section (output_bfd, inf Line 4748  sh_elf_relocate_section (output_bfd, inf
4748            break;            break;
4749    
4750          case R_SH_IND12W:          case R_SH_IND12W:
           relocation -= 4;  
4751            goto final_link_relocate;            goto final_link_relocate;
4752    
4753          case R_SH_DIR8WPN:          case R_SH_DIR8WPN:
# Line 4281  sh_elf_relocate_section (output_bfd, inf Line 4776  sh_elf_relocate_section (output_bfd, inf
4776                if (disp & mask)                if (disp & mask)
4777                  {                  {
4778                    ((*_bfd_error_handler)                    ((*_bfd_error_handler)
4779                     (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),                     (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4780                      bfd_archive_filename (input_section->owner),                      input_section->owner,
4781                      (unsigned long) rel->r_offset));                      (unsigned long) rel->r_offset));
4782                    bfd_set_error (bfd_error_bad_value);                    bfd_set_error (bfd_error_bad_value);
4783                    return false;                    return FALSE;
4784                  }                  }
4785                relocation -= 4;                relocation -= 4;
4786                goto final_link_relocate;                goto final_link_relocate;
# Line 4300  sh_elf_relocate_section (output_bfd, inf Line 4795  sh_elf_relocate_section (output_bfd, inf
4795              goto final_link_relocate;              goto final_link_relocate;
4796  #endif  #endif
4797            bfd_set_error (bfd_error_bad_value);            bfd_set_error (bfd_error_bad_value);
4798            return false;            return FALSE;
4799    
4800            case R_SH_DIR16:
4801            case R_SH_DIR8:
4802            case R_SH_DIR8U:
4803            case R_SH_DIR8S:
4804            case R_SH_DIR4U:
4805              goto final_link_relocate;
4806    
4807            case R_SH_DIR8UL:
4808            case R_SH_DIR4UL:
4809              if (relocation & 3)
4810                {
4811                  ((*_bfd_error_handler)
4812                   (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4813                    input_section->owner,
4814                    (unsigned long) rel->r_offset, howto->name,
4815                    (unsigned long) relocation));
4816                  bfd_set_error (bfd_error_bad_value);
4817                  return FALSE;
4818                }
4819              goto final_link_relocate;
4820    
4821            case R_SH_DIR8UW:
4822            case R_SH_DIR8SW:
4823            case R_SH_DIR4UW:
4824              if (relocation & 1)
4825                {
4826                  ((*_bfd_error_handler)
4827                   (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4828                    input_section->owner,
4829                    (unsigned long) rel->r_offset, howto->name,
4830                    (unsigned long) relocation));
4831                  bfd_set_error (bfd_error_bad_value);
4832                  return FALSE;
4833                }
4834              goto final_link_relocate;
4835    
4836            case R_SH_PSHA:
4837              if ((signed int)relocation < -32
4838                  || (signed int)relocation > 32)
4839                {
4840                  ((*_bfd_error_handler)
4841                   (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
4842                    input_section->owner,
4843                    (unsigned long) rel->r_offset,
4844                    (unsigned long) relocation));
4845                  bfd_set_error (bfd_error_bad_value);
4846                  return FALSE;
4847                }
4848              goto final_link_relocate;
4849    
4850            case R_SH_PSHL:
4851              if ((signed int)relocation < -16
4852                  || (signed int)relocation > 16)
4853                {
4854                  ((*_bfd_error_handler)
4855                   (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
4856                    input_section->owner,
4857                    (unsigned long) rel->r_offset,
4858                    (unsigned long) relocation));
4859                  bfd_set_error (bfd_error_bad_value);
4860                  return FALSE;
4861                }
4862              goto final_link_relocate;
4863    
4864          case R_SH_DIR32:          case R_SH_DIR32:
4865          case R_SH_REL32:          case R_SH_REL32:
4866    #ifdef INCLUDE_SHMEDIA
4867            case R_SH_IMM_LOW16_PCREL:
4868            case R_SH_IMM_MEDLOW16_PCREL:
4869            case R_SH_IMM_MEDHI16_PCREL:
4870            case R_SH_IMM_HI16_PCREL:
4871    #endif
4872            if (info->shared            if (info->shared
4873                  && (h == NULL
4874                      || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4875                      || h->root.type != bfd_link_hash_undefweak)
4876                && r_symndx != 0                && r_symndx != 0
4877                && (input_section->flags & SEC_ALLOC) != 0                && (input_section->flags & SEC_ALLOC) != 0
4878                && (r_type != R_SH_REL32                && (r_type == R_SH_DIR32
4879                    || (h != NULL                    || !SYMBOL_CALLS_LOCAL (info, h)))
                       && h->dynindx != -1  
                       && (! info->symbolic  
                           || (h->elf_link_hash_flags  
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))  
4880              {              {
4881                Elf_Internal_Rela outrel;                Elf_Internal_Rela outrel;
4882                boolean skip, relocate;                bfd_byte *loc;
4883                  bfd_boolean skip, relocate;
4884    
4885                /* When generating a shared object, these relocations                /* When generating a shared object, these relocations
4886                   are copied into the output file to be resolved at run                   are copied into the output file to be resolved at run
# Line 4330  sh_elf_relocate_section (output_bfd, inf Line 4895  sh_elf_relocate_section (output_bfd, inf
4895                             elf_elfheader (input_bfd)->e_shstrndx,                             elf_elfheader (input_bfd)->e_shstrndx,
4896                             elf_section_data (input_section)->rel_hdr.sh_name));                             elf_section_data (input_section)->rel_hdr.sh_name));
4897                    if (name == NULL)                    if (name == NULL)
4898                      return false;                      return FALSE;
4899    
4900                    BFD_ASSERT (strncmp (name, ".rela", 5) == 0                    BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4901                                && strcmp (bfd_get_section_name (input_bfd,                                && strcmp (bfd_get_section_name (input_bfd,
# Line 4341  sh_elf_relocate_section (output_bfd, inf Line 4906  sh_elf_relocate_section (output_bfd, inf
4906                    BFD_ASSERT (sreloc != NULL);                    BFD_ASSERT (sreloc != NULL);
4907                  }                  }
4908    
4909                skip = false;                skip = FALSE;
4910                relocate = false;                relocate = FALSE;
4911    
4912                outrel.r_offset =                outrel.r_offset =
4913                  _bfd_elf_section_offset (output_bfd, info, input_section,                  _bfd_elf_section_offset (output_bfd, info, input_section,
4914                                           rel->r_offset);                                           rel->r_offset);
4915                if (outrel.r_offset == (bfd_vma) -1)                if (outrel.r_offset == (bfd_vma) -1)
4916                  skip = true;                  skip = TRUE;
4917                else if (outrel.r_offset == (bfd_vma) -2)                else if (outrel.r_offset == (bfd_vma) -2)
4918                  skip = true, relocate = true;                  skip = TRUE, relocate = TRUE;
4919                outrel.r_offset += (input_section->output_section->vma                outrel.r_offset += (input_section->output_section->vma
4920                                    + input_section->output_offset);                                    + input_section->output_offset);
4921    
# Line 4363  sh_elf_relocate_section (output_bfd, inf Line 4928  sh_elf_relocate_section (output_bfd, inf
4928                    outrel.r_addend                    outrel.r_addend
4929                      = bfd_get_32 (input_bfd, contents + rel->r_offset);                      = bfd_get_32 (input_bfd, contents + rel->r_offset);
4930                  }                  }
4931    #ifdef INCLUDE_SHMEDIA
4932                  else if (r_type == R_SH_IMM_LOW16_PCREL
4933                           || r_type == R_SH_IMM_MEDLOW16_PCREL
4934                           || r_type == R_SH_IMM_MEDHI16_PCREL
4935                           || r_type == R_SH_IMM_HI16_PCREL)
4936                    {
4937                      BFD_ASSERT (h != NULL && h->dynindx != -1);
4938                      outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4939                      outrel.r_addend = addend;
4940                    }
4941    #endif
4942                else                else
4943                  {                  {
4944                    /* h->dynindx may be -1 if this symbol was marked to                    /* h->dynindx may be -1 if this symbol was marked to
4945                       become local.  */                       become local.  */
4946                    if (h == NULL                    if (h == NULL
4947                        || ((info->symbolic || h->dynindx == -1)                        || ((info->symbolic || h->dynindx == -1)
4948                            && (h->elf_link_hash_flags                            && h->def_regular))
                               & ELF_LINK_HASH_DEF_REGULAR) != 0))  
4949                      {                      {
4950                        relocate = true;                        relocate = TRUE;
4951                        outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);                        outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4952                        outrel.r_addend                        outrel.r_addend
4953                          = relocation + bfd_get_32 (input_bfd,                          = relocation + bfd_get_32 (input_bfd,
# Line 4388  sh_elf_relocate_section (output_bfd, inf Line 4963  sh_elf_relocate_section (output_bfd, inf
4963                      }                      }
4964                  }                  }
4965    
4966                bfd_elf32_swap_reloca_out (output_bfd, &outrel,                loc = sreloc->contents;
4967                                           (((Elf32_External_Rela *)                loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4968                                             sreloc->contents)                bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
                                           + sreloc->reloc_count));  
               ++sreloc->reloc_count;  
4969    
4970                /* If this reloc is against an external symbol, we do                /* If this reloc is against an external symbol, we do
4971                   not want to fiddle with the addend.  Otherwise, we                   not want to fiddle with the addend.  Otherwise, we
# Line 4416  sh_elf_relocate_section (output_bfd, inf Line 4989  sh_elf_relocate_section (output_bfd, inf
4989               procedure linkage table.  */               procedure linkage table.  */
4990    
4991            if (h == NULL            if (h == NULL
4992                || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL                || h->forced_local
               || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN  
4993                || ! info->shared                || ! info->shared
4994                || info->symbolic                || info->symbolic
4995                || h->dynindx == -1                || h->dynindx == -1
# Line 4427  sh_elf_relocate_section (output_bfd, inf Line 4999  sh_elf_relocate_section (output_bfd, inf
4999    
5000            /* Relocation is to the entry for this symbol in the global            /* Relocation is to the entry for this symbol in the global
5001               offset table extension for the procedure linkage table.  */               offset table extension for the procedure linkage table.  */
           if (sgotplt == NULL)  
             {  
               sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");  
               BFD_ASSERT (sgotplt != NULL);  
             }  
5002    
5003              BFD_ASSERT (sgotplt != NULL);
5004            relocation = (sgotplt->output_offset            relocation = (sgotplt->output_offset
5005                          + ((h->plt.offset / elf_sh_sizeof_plt (info)                          + ((h->plt.offset / elf_sh_sizeof_plt (info)
5006                              - 1 + 3) * 4));                              - 1 + 3) * 4));
# Line 4455  sh_elf_relocate_section (output_bfd, inf Line 5023  sh_elf_relocate_section (output_bfd, inf
5023  #endif  #endif
5024            /* Relocation is to the entry for this symbol in the global            /* Relocation is to the entry for this symbol in the global
5025               offset table.  */               offset table.  */
5026            if (sgot == NULL)  
5027              {            BFD_ASSERT (sgot != NULL);
               sgot = bfd_get_section_by_name (dynobj, ".got");  
               BFD_ASSERT (sgot != NULL);  
             }  
5028    
5029            if (h != NULL)            if (h != NULL)
5030              {              {
5031                bfd_vma off;                bfd_boolean dyn;
5032    
5033                off = h->got.offset;                off = h->got.offset;
5034  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
# Line 4472  sh_elf_relocate_section (output_bfd, inf Line 5037  sh_elf_relocate_section (output_bfd, inf
5037                    struct elf_sh_link_hash_entry *hsh;                    struct elf_sh_link_hash_entry *hsh;
5038    
5039                    hsh = (struct elf_sh_link_hash_entry *)h;                    hsh = (struct elf_sh_link_hash_entry *)h;
5040                    off = hsh->datalabel_got_offset;                    off = hsh->datalabel_got.offset;
5041                  }                  }
5042  #endif  #endif
5043                BFD_ASSERT (off != (bfd_vma) -1);                BFD_ASSERT (off != (bfd_vma) -1);
5044    
5045                if (! elf_hash_table (info)->dynamic_sections_created                dyn = htab->root.dynamic_sections_created;
5046                  if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5047                    || (info->shared                    || (info->shared
5048                        && (info->symbolic || h->dynindx == -1                        && SYMBOL_REFERENCES_LOCAL (info, h))
5049                            || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL                    || (ELF_ST_VISIBILITY (h->other)
5050                            || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)                        && h->root.type == bfd_link_hash_undefweak))
                       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))  
5051                  {                  {
5052                    /* This is actually a static link, or it is a                    /* This is actually a static link, or it is a
5053                       -Bsymbolic link and the symbol is defined                       -Bsymbolic link and the symbol is defined
# Line 4508  sh_elf_relocate_section (output_bfd, inf Line 5073  sh_elf_relocate_section (output_bfd, inf
5073                            struct elf_sh_link_hash_entry *hsh;                            struct elf_sh_link_hash_entry *hsh;
5074    
5075                            hsh = (struct elf_sh_link_hash_entry *)h;                            hsh = (struct elf_sh_link_hash_entry *)h;
5076                            hsh->datalabel_got_offset |= 1;                            hsh->datalabel_got.offset |= 1;
5077                          }                          }
5078                        else                        else
5079  #endif  #endif
# Line 4520  sh_elf_relocate_section (output_bfd, inf Line 5085  sh_elf_relocate_section (output_bfd, inf
5085              }              }
5086            else            else
5087              {              {
               bfd_vma off;  
   
5088  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
5089                if (rel->r_addend)                if (rel->r_addend)
5090                  {                  {
# Line 4555  sh_elf_relocate_section (output_bfd, inf Line 5118  sh_elf_relocate_section (output_bfd, inf
5118    
5119                    if (info->shared)                    if (info->shared)
5120                      {                      {
                       asection *srelgot;  
5121                        Elf_Internal_Rela outrel;                        Elf_Internal_Rela outrel;
5122                          bfd_byte *loc;
5123    
5124                        srelgot = bfd_get_section_by_name (dynobj, ".rela.got");                        if (srelgot == NULL)
5125                        BFD_ASSERT (srelgot != NULL);                          {
5126                              srelgot = bfd_get_section_by_name (dynobj,
5127                                                                 ".rela.got");
5128                              BFD_ASSERT (srelgot != NULL);
5129                            }
5130    
5131                        outrel.r_offset = (sgot->output_section->vma                        outrel.r_offset = (sgot->output_section->vma
5132                                           + sgot->output_offset                                           + sgot->output_offset
5133                                           + off);                                           + off);
5134                        outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);                        outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5135                        outrel.r_addend = relocation;                        outrel.r_addend = relocation;
5136                        bfd_elf32_swap_reloca_out (output_bfd, &outrel,                        loc = srelgot->contents;
5137                                                  (((Elf32_External_Rela *)                        loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5138                                                    srelgot->contents)                        bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
                                                  + srelgot->reloc_count));  
                       ++srelgot->reloc_count;  
5139                      }                      }
5140    
5141  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
# Line 4585  sh_elf_relocate_section (output_bfd, inf Line 5150  sh_elf_relocate_section (output_bfd, inf
5150              }              }
5151    
5152  #ifdef GOT_BIAS  #ifdef GOT_BIAS
5153            relocation -= GOT_BIAS;            relocation -= GOT_BIAS;
5154  #endif  #endif
5155    
5156            goto final_link_relocate;            goto final_link_relocate;
# Line 4600  sh_elf_relocate_section (output_bfd, inf Line 5165  sh_elf_relocate_section (output_bfd, inf
5165            /* Relocation is relative to the start of the global offset            /* Relocation is relative to the start of the global offset
5166               table.  */               table.  */
5167    
5168            if (sgot == NULL)            BFD_ASSERT (sgot != NULL);
             {  
               sgot = bfd_get_section_by_name (dynobj, ".got");  
               BFD_ASSERT (sgot != NULL);  
             }  
5169    
5170            /* Note that sgot->output_offset is not involved in this            /* Note that sgot->output_offset is not involved in this
5171               calculation.  We always want the start of .got.  If we               calculation.  We always want the start of .got.  If we
# Line 4630  sh_elf_relocate_section (output_bfd, inf Line 5191  sh_elf_relocate_section (output_bfd, inf
5191  #endif  #endif
5192            /* Use global offset table as symbol value.  */            /* Use global offset table as symbol value.  */
5193    
5194            if (sgot == NULL)            BFD_ASSERT (sgot != NULL);
             {  
               sgot = bfd_get_section_by_name (dynobj, ".got");  
               BFD_ASSERT (sgot != NULL);  
             }  
   
5195            relocation = sgot->output_section->vma;            relocation = sgot->output_section->vma;
5196    
5197  #ifdef GOT_BIAS  #ifdef GOT_BIAS
# Line 4661  sh_elf_relocate_section (output_bfd, inf Line 5217  sh_elf_relocate_section (output_bfd, inf
5217            if (h == NULL)            if (h == NULL)
5218              goto final_link_relocate;              goto final_link_relocate;
5219    
5220            if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL            if (h->forced_local)
               || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)  
5221              goto final_link_relocate;              goto final_link_relocate;
5222    
5223            if (h->plt.offset == (bfd_vma) -1)            if (h->plt.offset == (bfd_vma) -1)
# Line 4673  sh_elf_relocate_section (output_bfd, inf Line 5228  sh_elf_relocate_section (output_bfd, inf
5228                goto final_link_relocate;                goto final_link_relocate;
5229              }              }
5230    
5231            if (splt == NULL)            BFD_ASSERT (splt != NULL);
             {  
               splt = bfd_get_section_by_name (dynobj, ".plt");  
               BFD_ASSERT (splt != NULL);  
             }  
   
5232            relocation = (splt->output_section->vma            relocation = (splt->output_section->vma
5233                          + splt->output_offset                          + splt->output_offset
5234                          + h->plt.offset);                          + h->plt.offset);
# Line 4708  sh_elf_relocate_section (output_bfd, inf Line 5258  sh_elf_relocate_section (output_bfd, inf
5258                                     rel->r_offset, sec, start, end);                                     rel->r_offset, sec, start, end);
5259              break;              break;
5260            }            }
5261    
5262            case R_SH_TLS_GD_32:
5263            case R_SH_TLS_IE_32:
5264              r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5265              tls_type = GOT_UNKNOWN;
5266              if (h == NULL && local_got_offsets)
5267                tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
5268              else if (h != NULL)
5269                {
5270                  tls_type = sh_elf_hash_entry (h)->tls_type;
5271                  if (! info->shared
5272                      && (h->dynindx == -1
5273                          || h->def_regular))
5274                    r_type = R_SH_TLS_LE_32;
5275                }
5276    
5277              if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
5278                r_type = R_SH_TLS_IE_32;
5279    
5280              if (r_type == R_SH_TLS_LE_32)
5281                {
5282                  bfd_vma offset;
5283                  unsigned short insn;
5284    
5285                  if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5286                    {
5287                      /* GD->LE transition:
5288                           mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5289                           jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5290                           1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5291                         We change it into:
5292                           mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5293                           nop; nop; ...
5294                           1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:.  */
5295    
5296                      offset = rel->r_offset;
5297                      BFD_ASSERT (offset >= 16);
5298                      /* Size of GD instructions is 16 or 18.  */
5299                      offset -= 16;
5300                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
5301                      if ((insn & 0xff00) == 0xc700)
5302                        {
5303                          BFD_ASSERT (offset >= 2);
5304                          offset -= 2;
5305                          insn = bfd_get_16 (input_bfd, contents + offset + 0);
5306                        }
5307    
5308                      BFD_ASSERT ((insn & 0xff00) == 0xd400);
5309                      insn = bfd_get_16 (input_bfd, contents + offset + 2);
5310                      BFD_ASSERT ((insn & 0xff00) == 0xc700);
5311                      insn = bfd_get_16 (input_bfd, contents + offset + 4);
5312                      BFD_ASSERT ((insn & 0xff00) == 0xd100);
5313                      insn = bfd_get_16 (input_bfd, contents + offset + 6);
5314                      BFD_ASSERT (insn == 0x310c);
5315                      insn = bfd_get_16 (input_bfd, contents + offset + 8);
5316                      BFD_ASSERT (insn == 0x410b);
5317                      insn = bfd_get_16 (input_bfd, contents + offset + 10);
5318                      BFD_ASSERT (insn == 0x34cc);
5319    
5320                      bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5321                      bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5322                      bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5323                      bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5324                      bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5325                    }
5326                  else
5327                    {
5328                      int index;
5329    
5330                      /* IE->LE transition:
5331                         mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5332                         bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5333                         We change it into:
5334                         mov.l .Ln,rM; stc gbr,rN; nop; ...;
5335                         1: x@TPOFF; 2:.  */
5336    
5337                      offset = rel->r_offset;
5338                      BFD_ASSERT (offset >= 16);
5339                      /* Size of IE instructions is 10 or 12.  */
5340                      offset -= 10;
5341                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
5342                      if ((insn & 0xf0ff) == 0x0012)
5343                        {
5344                          BFD_ASSERT (offset >= 2);
5345                          offset -= 2;
5346                          insn = bfd_get_16 (input_bfd, contents + offset + 0);
5347                        }
5348    
5349                      BFD_ASSERT ((insn & 0xff00) == 0xd000);
5350                      index = insn & 0x00ff;
5351                      insn = bfd_get_16 (input_bfd, contents + offset + 2);
5352                      BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5353                      insn = bfd_get_16 (input_bfd, contents + offset + 4);
5354                      BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5355                      insn = 0xd000 | (insn & 0x0f00) | index;
5356                      bfd_put_16 (output_bfd, insn, contents + offset + 0);
5357                      bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5358                    }
5359    
5360                  bfd_put_32 (output_bfd, tpoff (info, relocation),
5361                              contents + rel->r_offset);
5362                  continue;
5363                }
5364    
5365              sgot = htab->sgot;
5366              if (sgot == NULL)
5367                abort ();
5368    
5369              if (h != NULL)
5370                off = h->got.offset;
5371              else
5372                {
5373                  if (local_got_offsets == NULL)
5374                    abort ();
5375    
5376                  off = local_got_offsets[r_symndx];
5377                }
5378    
5379              /* Relocate R_SH_TLS_IE_32 directly when statically linking.  */
5380              if (r_type == R_SH_TLS_IE_32
5381                  && ! htab->root.dynamic_sections_created)
5382                {
5383                  off &= ~1;
5384                  bfd_put_32 (output_bfd, tpoff (info, relocation),
5385                              sgot->contents + off);
5386                  bfd_put_32 (output_bfd, sgot->output_offset + off,
5387                              contents + rel->r_offset);
5388                  continue;
5389                }
5390    
5391              if ((off & 1) != 0)
5392                off &= ~1;
5393              else
5394                {
5395                  Elf_Internal_Rela outrel;
5396                  bfd_byte *loc;
5397                  int dr_type, indx;
5398    
5399                  if (srelgot == NULL)
5400                    {
5401                      srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5402                      BFD_ASSERT (srelgot != NULL);
5403                    }
5404    
5405                  outrel.r_offset = (sgot->output_section->vma
5406                                     + sgot->output_offset + off);
5407    
5408                  if (h == NULL || h->dynindx == -1)
5409                    indx = 0;
5410                  else
5411                    indx = h->dynindx;
5412    
5413                  dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5414                             R_SH_TLS_TPOFF32);
5415                  if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5416                    outrel.r_addend = relocation - dtpoff_base (info);
5417                  else
5418                    outrel.r_addend = 0;
5419                  outrel.r_info = ELF32_R_INFO (indx, dr_type);
5420                  loc = srelgot->contents;
5421                  loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5422                  bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5423    
5424                  if (r_type == R_SH_TLS_GD_32)
5425                    {
5426                      if (indx == 0)
5427                        {
5428                          bfd_put_32 (output_bfd,
5429                                      relocation - dtpoff_base (info),
5430                                      sgot->contents + off + 4);
5431                        }
5432                      else
5433                        {
5434                          outrel.r_info = ELF32_R_INFO (indx,
5435                                                        R_SH_TLS_DTPOFF32);
5436                          outrel.r_offset += 4;
5437                          outrel.r_addend = 0;
5438                          srelgot->reloc_count++;
5439                          loc += sizeof (Elf32_External_Rela);
5440                          bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5441                        }
5442                    }
5443    
5444                  if (h != NULL)
5445                    h->got.offset |= 1;
5446                  else
5447                    local_got_offsets[r_symndx] |= 1;
5448                }
5449    
5450              if (off >= (bfd_vma) -2)
5451                abort ();
5452    
5453              if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5454                relocation = sgot->output_offset + off;
5455              else
5456                {
5457                  bfd_vma offset;
5458                  unsigned short insn;
5459    
5460                  /* GD->IE transition:
5461                       mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5462                       jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5463                       1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5464                     We change it into:
5465                       mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5466                       nop; nop; bra 3f; nop; .align 2;
5467                       1: .long x@TPOFF; 2:...; 3:.  */
5468    
5469                  offset = rel->r_offset;
5470                  BFD_ASSERT (offset >= 16);
5471                  /* Size of GD instructions is 16 or 18.  */
5472                  offset -= 16;
5473                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
5474                  if ((insn & 0xff00) == 0xc700)
5475                    {
5476                      BFD_ASSERT (offset >= 2);
5477                      offset -= 2;
5478                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
5479                    }
5480    
5481                  BFD_ASSERT ((insn & 0xff00) == 0xd400);
5482    
5483                  /* Replace mov.l 1f,R4 with mov.l 1f,r0.  */
5484                  bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5485    
5486                  insn = bfd_get_16 (input_bfd, contents + offset + 2);
5487                  BFD_ASSERT ((insn & 0xff00) == 0xc700);
5488                  insn = bfd_get_16 (input_bfd, contents + offset + 4);
5489                  BFD_ASSERT ((insn & 0xff00) == 0xd100);
5490                  insn = bfd_get_16 (input_bfd, contents + offset + 6);
5491                  BFD_ASSERT (insn == 0x310c);
5492                  insn = bfd_get_16 (input_bfd, contents + offset + 8);
5493                  BFD_ASSERT (insn == 0x410b);
5494                  insn = bfd_get_16 (input_bfd, contents + offset + 10);
5495                  BFD_ASSERT (insn == 0x34cc);
5496    
5497                  bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5498                  bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5499                  bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5500                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5501                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5502    
5503                  bfd_put_32 (output_bfd, sgot->output_offset + off,
5504                              contents + rel->r_offset);
5505    
5506                  continue;
5507              }
5508    
5509              addend = rel->r_addend;
5510    
5511              goto final_link_relocate;
5512    
5513            case R_SH_TLS_LD_32:
5514              if (! info->shared)
5515                {
5516                  bfd_vma offset;
5517                  unsigned short insn;
5518    
5519                  /* LD->LE transition:
5520                       mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5521                       jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5522                       1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5523                     We change it into:
5524                       stc gbr,r0; nop; nop; nop;
5525                       nop; nop; bra 3f; ...; 3:.  */
5526    
5527                  offset = rel->r_offset;
5528                  BFD_ASSERT (offset >= 16);
5529                  /* Size of LD instructions is 16 or 18.  */
5530                  offset -= 16;
5531                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
5532                  if ((insn & 0xff00) == 0xc700)
5533                    {
5534                      BFD_ASSERT (offset >= 2);
5535                      offset -= 2;
5536                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
5537                    }
5538    
5539                  BFD_ASSERT ((insn & 0xff00) == 0xd400);
5540                  insn = bfd_get_16 (input_bfd, contents + offset + 2);
5541                  BFD_ASSERT ((insn & 0xff00) == 0xc700);
5542                  insn = bfd_get_16 (input_bfd, contents + offset + 4);
5543                  BFD_ASSERT ((insn & 0xff00) == 0xd100);
5544                  insn = bfd_get_16 (input_bfd, contents + offset + 6);
5545                  BFD_ASSERT (insn == 0x310c);
5546                  insn = bfd_get_16 (input_bfd, contents + offset + 8);
5547                  BFD_ASSERT (insn == 0x410b);
5548                  insn = bfd_get_16 (input_bfd, contents + offset + 10);
5549                  BFD_ASSERT (insn == 0x34cc);
5550    
5551                  bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5552                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5553                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5554                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5555                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5556                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5557    
5558                  continue;
5559                }
5560    
5561              sgot = htab->sgot;
5562              if (sgot == NULL)
5563                abort ();
5564    
5565              off = htab->tls_ldm_got.offset;
5566              if (off & 1)
5567                off &= ~1;
5568              else
5569                {
5570                  Elf_Internal_Rela outrel;
5571                  bfd_byte *loc;
5572    
5573                  srelgot = htab->srelgot;
5574                  if (srelgot == NULL)
5575                    abort ();
5576    
5577                  outrel.r_offset = (sgot->output_section->vma
5578                                     + sgot->output_offset + off);
5579                  outrel.r_addend = 0;
5580                  outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5581                  loc = srelgot->contents;
5582                  loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5583                  bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5584                  htab->tls_ldm_got.offset |= 1;
5585                }
5586    
5587              relocation = sgot->output_offset + off;
5588              addend = rel->r_addend;
5589    
5590              goto final_link_relocate;
5591    
5592            case R_SH_TLS_LDO_32:
5593              if (! info->shared)
5594                relocation = tpoff (info, relocation);
5595              else
5596                relocation -= dtpoff_base (info);
5597    
5598              addend = rel->r_addend;
5599              goto final_link_relocate;
5600    
5601            case R_SH_TLS_LE_32:
5602              {
5603                int indx;
5604                Elf_Internal_Rela outrel;
5605                bfd_byte *loc;
5606    
5607                if (! info->shared)
5608                  {
5609                    relocation = tpoff (info, relocation);
5610                    addend = rel->r_addend;
5611                    goto final_link_relocate;
5612                  }
5613    
5614                if (sreloc == NULL)
5615                  {
5616                    const char *name;
5617    
5618                    name = (bfd_elf_string_from_elf_section
5619                            (input_bfd,
5620                             elf_elfheader (input_bfd)->e_shstrndx,
5621                             elf_section_data (input_section)->rel_hdr.sh_name));
5622                    if (name == NULL)
5623                      return FALSE;
5624    
5625                    BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5626                                && strcmp (bfd_get_section_name (input_bfd,
5627                                                                 input_section),
5628                                           name + 5) == 0);
5629    
5630                    sreloc = bfd_get_section_by_name (dynobj, name);
5631                    BFD_ASSERT (sreloc != NULL);
5632                  }
5633    
5634                if (h == NULL || h->dynindx == -1)
5635                  indx = 0;
5636                else
5637                  indx = h->dynindx;
5638    
5639                outrel.r_offset = (input_section->output_section->vma
5640                                   + input_section->output_offset
5641                                   + rel->r_offset);
5642                outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5643                if (indx == 0)
5644                  outrel.r_addend = relocation - dtpoff_base (info);
5645                else
5646                  outrel.r_addend = 0;
5647    
5648                loc = sreloc->contents;
5649                loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5650                bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5651                continue;
5652              }
5653          }          }
5654    
5655      relocation_done:      relocation_done:
# Line 4723  sh_elf_relocate_section (output_bfd, inf Line 5665  sh_elf_relocate_section (output_bfd, inf
5665                  const char *name;                  const char *name;
5666    
5667                  if (h != NULL)                  if (h != NULL)
5668                    name = h->root.root.string;                    name = NULL;
5669                  else                  else
5670                    {                    {
5671                      name = (bfd_elf_string_from_elf_section                      name = (bfd_elf_string_from_elf_section
5672                              (input_bfd, symtab_hdr->sh_link, sym->st_name));                              (input_bfd, symtab_hdr->sh_link, sym->st_name));
5673                      if (name == NULL)                      if (name == NULL)
5674                        return false;                        return FALSE;
5675                      if (*name == '\0')                      if (*name == '\0')
5676                        name = bfd_section_name (input_bfd, sec);                        name = bfd_section_name (input_bfd, sec);
5677                    }                    }
5678                  if (! ((*info->callbacks->reloc_overflow)                  if (! ((*info->callbacks->reloc_overflow)
5679                         (info, name, howto->name, (bfd_vma) 0,                         (info, (h ? &h->root : NULL), name, howto->name,
5680                          input_bfd, input_section, rel->r_offset)))                          (bfd_vma) 0, input_bfd, input_section,
5681                    return false;                          rel->r_offset)))
5682                      return FALSE;
5683                }                }
5684                break;                break;
5685              }              }
5686          }          }
5687      }      }
5688    
5689    return true;    return TRUE;
5690  }  }
5691    
5692  /* This is a version of bfd_generic_get_relocated_section_contents  /* This is a version of bfd_generic_get_relocated_section_contents
5693     which uses sh_elf_relocate_section.  */     which uses sh_elf_relocate_section.  */
5694    
5695  static bfd_byte *  static bfd_byte *
5696  sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,  sh_elf_get_relocated_section_contents (bfd *output_bfd,
5697                                         data, relocateable, symbols)                                         struct bfd_link_info *link_info,
5698       bfd *output_bfd;                                         struct bfd_link_order *link_order,
5699       struct bfd_link_info *link_info;                                         bfd_byte *data,
5700       struct bfd_link_order *link_order;                                         bfd_boolean relocatable,
5701       bfd_byte *data;                                         asymbol **symbols)
      boolean relocateable;  
      asymbol **symbols;  
5702  {  {
5703    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
5704    asection *input_section = link_order->u.indirect.section;    asection *input_section = link_order->u.indirect.section;
# Line 4768  sh_elf_get_relocated_section_contents (o Line 5709  sh_elf_get_relocated_section_contents (o
5709    
5710    /* We only need to handle the case of relaxing, or of having a    /* We only need to handle the case of relaxing, or of having a
5711       particular set of section contents, specially.  */       particular set of section contents, specially.  */
5712    if (relocateable    if (relocatable
5713        || elf_section_data (input_section)->this_hdr.contents == NULL)        || elf_section_data (input_section)->this_hdr.contents == NULL)
5714      return bfd_generic_get_relocated_section_contents (output_bfd, link_info,      return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5715                                                         link_order, data,                                                         link_order, data,
5716                                                         relocateable,                                                         relocatable,
5717                                                         symbols);                                                         symbols);
5718    
5719    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5720    
5721    memcpy (data, elf_section_data (input_section)->this_hdr.contents,    memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5722            (size_t) input_section->_raw_size);            (size_t) input_section->size);
5723    
5724    if ((input_section->flags & SEC_RELOC) != 0    if ((input_section->flags & SEC_RELOC) != 0
5725        && input_section->reloc_count > 0)        && input_section->reloc_count > 0)
# Line 4787  sh_elf_get_relocated_section_contents (o Line 5728  sh_elf_get_relocated_section_contents (o
5728        Elf_Internal_Sym *isym, *isymend;        Elf_Internal_Sym *isym, *isymend;
5729        bfd_size_type amt;        bfd_size_type amt;
5730    
5731        internal_relocs = (_bfd_elf32_link_read_relocs        internal_relocs = (_bfd_elf_link_read_relocs
5732                           (input_bfd, input_section, (PTR) NULL,                           (input_bfd, input_section, NULL,
5733                            (Elf_Internal_Rela *) NULL, false));                            (Elf_Internal_Rela *) NULL, FALSE));
5734        if (internal_relocs == NULL)        if (internal_relocs == NULL)
5735          goto error_return;          goto error_return;
5736    
# Line 4855  sh_elf_get_relocated_section_contents (o Line 5796  sh_elf_get_relocated_section_contents (o
5796    return NULL;    return NULL;
5797  }  }
5798    
5799    /* Return the base VMA address which should be subtracted from real addresses
5800       when resolving @dtpoff relocation.
5801       This is PT_TLS segment p_vaddr.  */
5802    
5803    static bfd_vma
5804    dtpoff_base (struct bfd_link_info *info)
5805    {
5806      /* If tls_sec is NULL, we should have signalled an error already.  */
5807      if (elf_hash_table (info)->tls_sec == NULL)
5808        return 0;
5809      return elf_hash_table (info)->tls_sec->vma;
5810    }
5811    
5812    /* Return the relocation value for R_SH_TLS_TPOFF32..  */
5813    
5814    static bfd_vma
5815    tpoff (struct bfd_link_info *info, bfd_vma address)
5816    {
5817      /* If tls_sec is NULL, we should have signalled an error already.  */
5818      if (elf_hash_table (info)->tls_sec == NULL)
5819        return 0;
5820      /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5821         structure which has 2 pointer fields.  */
5822      return (address - elf_hash_table (info)->tls_sec->vma
5823              + align_power ((bfd_vma) 8,
5824                             elf_hash_table (info)->tls_sec->alignment_power));
5825    }
5826    
5827  static asection *  static asection *
5828  sh_elf_gc_mark_hook (sec, info, rel, h, sym)  sh_elf_gc_mark_hook (asection *sec,
5829       asection *sec;                       struct bfd_link_info *info ATTRIBUTE_UNUSED,
5830       struct bfd_link_info *info ATTRIBUTE_UNUSED;                       Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
5831       Elf_Internal_Rela *rel;                       Elf_Internal_Sym *sym)
      struct elf_link_hash_entry *h;  
      Elf_Internal_Sym *sym;  
5832  {  {
5833    if (h != NULL)    if (h != NULL)
5834      {      {
# Line 4872  sh_elf_gc_mark_hook (sec, info, rel, h, Line 5839  sh_elf_gc_mark_hook (sec, info, rel, h,
5839            break;            break;
5840    
5841          default:          default:
5842    #ifdef INCLUDE_SHMEDIA
5843              while (h->root.type == bfd_link_hash_indirect
5844                     && h->root.u.i.link)
5845                h = (struct elf_link_hash_entry *) h->root.u.i.link;
5846    #endif
5847            switch (h->root.type)            switch (h->root.type)
5848              {              {
5849              case bfd_link_hash_defined:              case bfd_link_hash_defined:
# Line 4894  sh_elf_gc_mark_hook (sec, info, rel, h, Line 5866  sh_elf_gc_mark_hook (sec, info, rel, h,
5866    
5867  /* Update the got entry reference counts for the section being removed.  */  /* Update the got entry reference counts for the section being removed.  */
5868    
5869  static boolean  static bfd_boolean
5870  sh_elf_gc_sweep_hook (abfd, info, sec, relocs)  sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
5871       bfd *abfd ATTRIBUTE_UNUSED;                        asection *sec, const Elf_Internal_Rela *relocs)
5872       struct bfd_link_info *info ATTRIBUTE_UNUSED;  {
5873       asection *sec ATTRIBUTE_UNUSED;    Elf_Internal_Shdr *symtab_hdr;
5874       const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;    struct elf_link_hash_entry **sym_hashes;
5875  {    bfd_signed_vma *local_got_refcounts;
5876    /* We use got and plt entries for sh, but it would seem that the    const Elf_Internal_Rela *rel, *relend;
5877       existing SH code does no sort of reference counting or whatnot on  
5878       its GOT and PLT entries, so it is not possible to garbage collect    elf_section_data (sec)->local_dynrel = NULL;
5879       them at this time.  */  
5880    return true;    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5881      sym_hashes = elf_sym_hashes (abfd);
5882      local_got_refcounts = elf_local_got_refcounts (abfd);
5883    
5884      relend = relocs + sec->reloc_count;
5885      for (rel = relocs; rel < relend; rel++)
5886        {
5887          unsigned long r_symndx;
5888          unsigned int r_type;
5889          struct elf_link_hash_entry *h = NULL;
5890    #ifdef INCLUDE_SHMEDIA
5891          int seen_stt_datalabel = 0;
5892    #endif
5893    
5894          r_symndx = ELF32_R_SYM (rel->r_info);
5895          if (r_symndx >= symtab_hdr->sh_info)
5896            {
5897              struct elf_sh_link_hash_entry *eh;
5898              struct elf_sh_dyn_relocs **pp;
5899              struct elf_sh_dyn_relocs *p;
5900    
5901              h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5902              while (h->root.type == bfd_link_hash_indirect
5903                     || h->root.type == bfd_link_hash_warning)
5904                {
5905    #ifdef INCLUDE_SHMEDIA
5906                  seen_stt_datalabel |= h->type == STT_DATALABEL;
5907    #endif
5908                  h = (struct elf_link_hash_entry *) h->root.u.i.link;
5909                }
5910              eh = (struct elf_sh_link_hash_entry *) h;
5911              for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
5912                if (p->sec == sec)
5913                  {
5914                    /* Everything must go for SEC.  */
5915                    *pp = p->next;
5916                    break;
5917                  }
5918            }
5919    
5920          r_type = ELF32_R_TYPE (rel->r_info);
5921          switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
5922            {
5923            case R_SH_TLS_LD_32:
5924              if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
5925                sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
5926              break;
5927    
5928            case R_SH_GOT32:
5929            case R_SH_GOTOFF:
5930            case R_SH_GOTPC:
5931    #ifdef INCLUDE_SHMEDIA
5932            case R_SH_GOT_LOW16:
5933            case R_SH_GOT_MEDLOW16:
5934            case R_SH_GOT_MEDHI16:
5935            case R_SH_GOT_HI16:
5936            case R_SH_GOT10BY4:
5937            case R_SH_GOT10BY8:
5938            case R_SH_GOTOFF_LOW16:
5939            case R_SH_GOTOFF_MEDLOW16:
5940            case R_SH_GOTOFF_MEDHI16:
5941            case R_SH_GOTOFF_HI16:
5942            case R_SH_GOTPC_LOW16:
5943            case R_SH_GOTPC_MEDLOW16:
5944            case R_SH_GOTPC_MEDHI16:
5945            case R_SH_GOTPC_HI16:
5946    #endif
5947            case R_SH_TLS_GD_32:
5948            case R_SH_TLS_IE_32:
5949              if (h != NULL)
5950                {
5951    #ifdef INCLUDE_SHMEDIA
5952                  if (seen_stt_datalabel)
5953                    {
5954                      struct elf_sh_link_hash_entry *eh;
5955                      eh = (struct elf_sh_link_hash_entry *) h;
5956                      if (eh->datalabel_got.refcount > 0)
5957                        eh->datalabel_got.refcount -= 1;
5958                    }
5959                  else
5960    #endif
5961                    if (h->got.refcount > 0)
5962                      h->got.refcount -= 1;
5963                }
5964              else if (local_got_refcounts != NULL)
5965                {
5966    #ifdef INCLUDE_SHMEDIA
5967                  if (rel->r_addend & 1)
5968                    {
5969                      if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
5970                        local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
5971                    }
5972                  else
5973    #endif
5974                    if (local_got_refcounts[r_symndx] > 0)
5975                      local_got_refcounts[r_symndx] -= 1;
5976                }
5977              break;
5978    
5979            case R_SH_DIR32:
5980            case R_SH_REL32:
5981              if (info->shared)
5982                break;
5983              /* Fall thru */
5984    
5985            case R_SH_PLT32:
5986    #ifdef INCLUDE_SHMEDIA
5987            case R_SH_PLT_LOW16:
5988            case R_SH_PLT_MEDLOW16:
5989            case R_SH_PLT_MEDHI16:
5990            case R_SH_PLT_HI16:
5991    #endif
5992              if (h != NULL)
5993                {
5994                  if (h->plt.refcount > 0)
5995                    h->plt.refcount -= 1;
5996                }
5997              break;
5998    
5999            case R_SH_GOTPLT32:
6000    #ifdef INCLUDE_SHMEDIA
6001            case R_SH_GOTPLT_LOW16:
6002            case R_SH_GOTPLT_MEDLOW16:
6003            case R_SH_GOTPLT_MEDHI16:
6004            case R_SH_GOTPLT_HI16:
6005            case R_SH_GOTPLT10BY4:
6006            case R_SH_GOTPLT10BY8:
6007    #endif
6008              if (h != NULL)
6009                {
6010                  struct elf_sh_link_hash_entry *eh;
6011                  eh = (struct elf_sh_link_hash_entry *) h;
6012                  if (eh->gotplt_refcount > 0)
6013                    {
6014                      eh->gotplt_refcount -= 1;
6015                      if (h->plt.refcount > 0)
6016                        h->plt.refcount -= 1;
6017                    }
6018    #ifdef INCLUDE_SHMEDIA
6019                  else if (seen_stt_datalabel)
6020                    {
6021                      if (eh->datalabel_got.refcount > 0)
6022                        eh->datalabel_got.refcount -= 1;
6023                    }
6024    #endif
6025                  else if (h->got.refcount > 0)
6026                    h->got.refcount -= 1;
6027                }
6028              else if (local_got_refcounts != NULL)
6029                {
6030    #ifdef INCLUDE_SHMEDIA
6031                  if (rel->r_addend & 1)
6032                    {
6033                      if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
6034                        local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
6035                    }
6036                  else
6037    #endif
6038                    if (local_got_refcounts[r_symndx] > 0)
6039                      local_got_refcounts[r_symndx] -= 1;
6040                }
6041              break;
6042    
6043            default:
6044              break;
6045            }
6046        }
6047    
6048      return TRUE;
6049    }
6050    
6051    /* Copy the extra info we tack onto an elf_link_hash_entry.  */
6052    
6053    static void
6054    sh_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
6055                                 struct elf_link_hash_entry *dir,
6056                                 struct elf_link_hash_entry *ind)
6057    {
6058      struct elf_sh_link_hash_entry *edir, *eind;
6059    #ifdef INCLUDE_SHMEDIA
6060      bfd_signed_vma tmp;
6061    #endif
6062    
6063      edir = (struct elf_sh_link_hash_entry *) dir;
6064      eind = (struct elf_sh_link_hash_entry *) ind;
6065    
6066      if (eind->dyn_relocs != NULL)
6067        {
6068          if (edir->dyn_relocs != NULL)
6069            {
6070              struct elf_sh_dyn_relocs **pp;
6071              struct elf_sh_dyn_relocs *p;
6072    
6073              BFD_ASSERT (ind->root.type != bfd_link_hash_indirect);
6074    
6075              /* Add reloc counts against the weak sym to the strong sym
6076                 list.  Merge any entries against the same section.  */
6077              for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
6078                {
6079                  struct elf_sh_dyn_relocs *q;
6080    
6081                  for (q = edir->dyn_relocs; q != NULL; q = q->next)
6082                    if (q->sec == p->sec)
6083                      {
6084                        q->pc_count += p->pc_count;
6085                        q->count += p->count;
6086                        *pp = p->next;
6087                        break;
6088                      }
6089                  if (q == NULL)
6090                    pp = &p->next;
6091                }
6092              *pp = edir->dyn_relocs;
6093            }
6094    
6095          edir->dyn_relocs = eind->dyn_relocs;
6096          eind->dyn_relocs = NULL;
6097        }
6098      edir->gotplt_refcount = eind->gotplt_refcount;
6099      eind->gotplt_refcount = 0;
6100    #ifdef INCLUDE_SHMEDIA
6101      tmp = edir->datalabel_got.refcount;
6102      if (tmp < 1)
6103        {
6104          edir->datalabel_got.refcount = eind->datalabel_got.refcount;
6105          eind->datalabel_got.refcount = tmp;
6106        }
6107      else
6108        BFD_ASSERT (eind->datalabel_got.refcount < 1);
6109    #endif
6110    
6111      if (ind->root.type == bfd_link_hash_indirect
6112          && dir->got.refcount <= 0)
6113        {
6114          edir->tls_type = eind->tls_type;
6115          eind->tls_type = GOT_UNKNOWN;
6116        }
6117    
6118      if (ind->root.type != bfd_link_hash_indirect
6119          && dir->dynamic_adjusted)
6120        {
6121          /* If called to transfer flags for a weakdef during processing
6122             of elf_adjust_dynamic_symbol, don't copy non_got_ref.
6123             We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
6124          dir->ref_dynamic |= ind->ref_dynamic;
6125          dir->ref_regular |= ind->ref_regular;
6126          dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
6127          dir->needs_plt |= ind->needs_plt;
6128        }
6129      else
6130        _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
6131    }
6132    
6133    static int
6134    sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
6135                                int is_local)
6136    {
6137      if (info->shared)
6138        return r_type;
6139    
6140      switch (r_type)
6141        {
6142        case R_SH_TLS_GD_32:
6143        case R_SH_TLS_IE_32:
6144          if (is_local)
6145            return R_SH_TLS_LE_32;
6146          return R_SH_TLS_IE_32;
6147        case R_SH_TLS_LD_32:
6148          return R_SH_TLS_LE_32;
6149        }
6150    
6151      return r_type;
6152  }  }
6153    
6154  /* Look through the relocs for a section during the first phase.  /* Look through the relocs for a section during the first phase.
6155     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
6156     virtual table relocs for gc.  */     virtual table relocs for gc.  */
6157    
6158  static boolean  static bfd_boolean
6159  sh_elf_check_relocs (abfd, info, sec, relocs)  sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
6160       bfd *abfd;                       const Elf_Internal_Rela *relocs)
      struct bfd_link_info *info;  
      asection *sec;  
      const Elf_Internal_Rela *relocs;  
6161  {  {
6162    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
6163    struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;    struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6164      struct elf_sh_link_hash_table *htab;
6165    const Elf_Internal_Rela *rel;    const Elf_Internal_Rela *rel;
6166    const Elf_Internal_Rela *rel_end;    const Elf_Internal_Rela *rel_end;
   bfd *dynobj;  
6167    bfd_vma *local_got_offsets;    bfd_vma *local_got_offsets;
6168    asection *sgot;    asection *sgot;
6169    asection *srelgot;    asection *srelgot;
6170    asection *sreloc;    asection *sreloc;
6171      unsigned int r_type;
6172      int tls_type, old_tls_type;
6173    
6174    sgot = NULL;    sgot = NULL;
6175    srelgot = NULL;    srelgot = NULL;
6176    sreloc = NULL;    sreloc = NULL;
6177    
6178    if (info->relocateable)    if (info->relocatable)
6179      return true;      return TRUE;
6180    
6181    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6182    sym_hashes = elf_sym_hashes (abfd);    sym_hashes = elf_sym_hashes (abfd);
# Line 4942  sh_elf_check_relocs (abfd, info, sec, re Line 6184  sh_elf_check_relocs (abfd, info, sec, re
6184    if (!elf_bad_symtab (abfd))    if (!elf_bad_symtab (abfd))
6185      sym_hashes_end -= symtab_hdr->sh_info;      sym_hashes_end -= symtab_hdr->sh_info;
6186    
6187    dynobj = elf_hash_table (info)->dynobj;    htab = sh_elf_hash_table (info);
6188    local_got_offsets = elf_local_got_offsets (abfd);    local_got_offsets = elf_local_got_offsets (abfd);
6189    
6190    rel_end = relocs + sec->reloc_count;    rel_end = relocs + sec->reloc_count;
# Line 4950  sh_elf_check_relocs (abfd, info, sec, re Line 6192  sh_elf_check_relocs (abfd, info, sec, re
6192      {      {
6193        struct elf_link_hash_entry *h;        struct elf_link_hash_entry *h;
6194        unsigned long r_symndx;        unsigned long r_symndx;
6195    #ifdef INCLUDE_SHMEDIA
6196          int seen_stt_datalabel = 0;
6197    #endif
6198    
6199        r_symndx = ELF32_R_SYM (rel->r_info);        r_symndx = ELF32_R_SYM (rel->r_info);
6200          r_type = ELF32_R_TYPE (rel->r_info);
6201    
6202        if (r_symndx < symtab_hdr->sh_info)        if (r_symndx < symtab_hdr->sh_info)
6203          h = NULL;          h = NULL;
6204        else        else
6205          h = sym_hashes[r_symndx - symtab_hdr->sh_info];          {
6206              h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6207    #ifdef INCLUDE_SHMEDIA
6208              while (h->root.type == bfd_link_hash_indirect
6209                     || h->root.type == bfd_link_hash_warning)
6210                {
6211                  seen_stt_datalabel |= h->type == STT_DATALABEL;
6212                  h = (struct elf_link_hash_entry *) h->root.u.i.link;
6213                }
6214    #endif
6215            }
6216    
6217          r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
6218          if (! info->shared
6219              && r_type == R_SH_TLS_IE_32
6220              && h != NULL
6221              && h->root.type != bfd_link_hash_undefined
6222              && h->root.type != bfd_link_hash_undefweak
6223              && (h->dynindx == -1
6224                  || h->def_regular))
6225            r_type = R_SH_TLS_LE_32;
6226    
6227        /* Some relocs require a global offset table.  */        /* Some relocs require a global offset table.  */
6228        if (dynobj == NULL)        if (htab->sgot == NULL)
6229          {          {
6230            switch (ELF32_R_TYPE (rel->r_info))            switch (r_type)
6231              {              {
6232              case R_SH_GOTPLT32:              case R_SH_GOTPLT32:
6233              case R_SH_GOT32:              case R_SH_GOT32:
# Line 4988  sh_elf_check_relocs (abfd, info, sec, re Line 6255  sh_elf_check_relocs (abfd, info, sec, re
6255              case R_SH_GOTPC_MEDHI16:              case R_SH_GOTPC_MEDHI16:
6256              case R_SH_GOTPC_HI16:              case R_SH_GOTPC_HI16:
6257  #endif  #endif
6258                elf_hash_table (info)->dynobj = dynobj = abfd;              case R_SH_TLS_GD_32:
6259                if (! _bfd_elf_create_got_section (dynobj, info))              case R_SH_TLS_LD_32:
6260                  return false;              case R_SH_TLS_IE_32:
6261                  if (htab->sgot == NULL)
6262                    {
6263                      if (htab->root.dynobj == NULL)
6264                        htab->root.dynobj = abfd;
6265                      if (!create_got_section (htab->root.dynobj, info))
6266                        return FALSE;
6267                    }
6268                break;                break;
6269    
6270              default:              default:
# Line 4998  sh_elf_check_relocs (abfd, info, sec, re Line 6272  sh_elf_check_relocs (abfd, info, sec, re
6272              }              }
6273          }          }
6274    
6275        switch (ELF32_R_TYPE (rel->r_info))        switch (r_type)
6276          {          {
6277          /* This relocation describes the C++ object vtable hierarchy.            /* This relocation describes the C++ object vtable hierarchy.
6278             Reconstruct it for later use during GC.  */               Reconstruct it for later use during GC.  */
6279          case R_SH_GNU_VTINHERIT:          case R_SH_GNU_VTINHERIT:
6280            if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))            if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6281              return false;              return FALSE;
6282            break;            break;
6283    
6284          /* This relocation describes which C++ vtable entries are actually            /* This relocation describes which C++ vtable entries are actually
6285             used.  Record for later use during GC.  */               used.  Record for later use during GC.  */
6286          case R_SH_GNU_VTENTRY:          case R_SH_GNU_VTENTRY:
6287            if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))            if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6288              return false;              return FALSE;
6289            break;            break;
6290    
6291            case R_SH_TLS_IE_32:
6292              if (info->shared)
6293                info->flags |= DF_STATIC_TLS;
6294    
6295              /* FALLTHROUGH */
6296          force_got:          force_got:
6297            case R_SH_TLS_GD_32:
6298          case R_SH_GOT32:          case R_SH_GOT32:
6299  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
6300          case R_SH_GOT_LOW16:          case R_SH_GOT_LOW16:
# Line 5024  sh_elf_check_relocs (abfd, info, sec, re Line 6304  sh_elf_check_relocs (abfd, info, sec, re
6304          case R_SH_GOT10BY4:          case R_SH_GOT10BY4:
6305          case R_SH_GOT10BY8:          case R_SH_GOT10BY8:
6306  #endif  #endif
6307            /* This symbol requires a global offset table entry.  */            switch (r_type)
   
           if (sgot == NULL)  
6308              {              {
6309                sgot = bfd_get_section_by_name (dynobj, ".got");              default:
6310                BFD_ASSERT (sgot != NULL);                tls_type = GOT_NORMAL;
6311              }                break;
6312                case R_SH_TLS_GD_32:
6313            if (srelgot == NULL                tls_type = GOT_TLS_GD;
6314                && (h != NULL || info->shared))                break;
6315              {              case R_SH_TLS_IE_32:
6316                srelgot = bfd_get_section_by_name (dynobj, ".rela.got");                tls_type = GOT_TLS_IE;
6317                if (srelgot == NULL)                break;
                 {  
                   srelgot = bfd_make_section (dynobj, ".rela.got");  
                   if (srelgot == NULL  
                       || ! bfd_set_section_flags (dynobj, srelgot,  
                                                   (SEC_ALLOC  
                                                    | SEC_LOAD  
                                                    | SEC_HAS_CONTENTS  
                                                    | SEC_IN_MEMORY  
                                                    | SEC_LINKER_CREATED  
                                                    | SEC_READONLY))  
                       || ! bfd_set_section_alignment (dynobj, srelgot, 2))  
                     return false;  
                 }  
6318              }              }
6319    
6320            if (h != NULL)            if (h != NULL)
6321              {              {
6322  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
6323                if (h->type == STT_DATALABEL)                if (seen_stt_datalabel)
6324                  {                  {
6325                    struct elf_sh_link_hash_entry *hsh;                    struct elf_sh_link_hash_entry *eh
6326                        = (struct elf_sh_link_hash_entry *) h;
6327    
6328                    h = (struct elf_link_hash_entry *) h->root.u.i.link;                    eh->datalabel_got.refcount += 1;
                   hsh = (struct elf_sh_link_hash_entry *)h;  
                   if (hsh->datalabel_got_offset != (bfd_vma) -1)  
                     break;  
   
                   hsh->datalabel_got_offset = sgot->_raw_size;  
6329                  }                  }
6330                else                else
                 {  
 #endif  
               if (h->got.offset != (bfd_vma) -1)  
                 {  
                   /* We have already allocated space in the .got.  */  
                   break;  
                 }  
               h->got.offset = sgot->_raw_size;  
 #ifdef INCLUDE_SHMEDIA  
                 }  
6331  #endif  #endif
6332                    h->got.refcount += 1;
6333                /* Make sure this symbol is output as a dynamic symbol.  */                old_tls_type = sh_elf_hash_entry (h)->tls_type;
               if (h->dynindx == -1)  
                 {  
                   if (! bfd_elf32_link_record_dynamic_symbol (info, h))  
                     return false;  
                 }  
   
               srelgot->_raw_size += sizeof (Elf32_External_Rela);  
6334              }              }
6335            else            else
6336              {              {
6337                  bfd_signed_vma *local_got_refcounts;
6338    
6339                /* This is a global offset table entry for a local                /* This is a global offset table entry for a local
6340                   symbol.  */                   symbol.  */
6341                if (local_got_offsets == NULL)                local_got_refcounts = elf_local_got_refcounts (abfd);
6342                  if (local_got_refcounts == NULL)
6343                  {                  {
6344                    bfd_size_type size;                    bfd_size_type size;
                   register unsigned int i;  
6345    
6346                    size = symtab_hdr->sh_info;                    size = symtab_hdr->sh_info;
6347                    size *= sizeof (bfd_vma);                    size *= sizeof (bfd_signed_vma);
6348  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
6349                    /* Reserve space for both the datalabel and                    /* Reserve space for both the datalabel and
6350                       codelabel local GOT offsets.  */                       codelabel local GOT offsets.  */
6351                    size *= 2;                    size *= 2;
6352  #endif  #endif
6353                    local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);                    size += symtab_hdr->sh_info;
6354                    if (local_got_offsets == NULL)                    local_got_refcounts = ((bfd_signed_vma *)
6355                      return false;                                           bfd_zalloc (abfd, size));
6356                    elf_local_got_offsets (abfd) = local_got_offsets;                    if (local_got_refcounts == NULL)
6357                    for (i = 0; i < symtab_hdr->sh_info; i++)                      return FALSE;
6358                      local_got_offsets[i] = (bfd_vma) -1;                    elf_local_got_refcounts (abfd) = local_got_refcounts;
6359  #ifdef INCLUDE_SHMEDIA  #ifdef  INCLUDE_SHMEDIA
6360                    for (; i < 2 * symtab_hdr->sh_info; i++)                    /* Take care of both the datalabel and codelabel local
6361                      local_got_offsets[i] = (bfd_vma) -1;                       GOT offsets.  */
6362                      sh_elf_local_got_tls_type (abfd)
6363                        = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6364    #else
6365                      sh_elf_local_got_tls_type (abfd)
6366                        = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6367  #endif  #endif
6368                  }                  }
6369  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
6370                if ((rel->r_addend & 1) != 0)                if (rel->r_addend & 1)
6371                  {                  local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
                   if (local_got_offsets[symtab_hdr->sh_info  
                                         + r_symndx] != (bfd_vma) -1)  
                     {  
                       /* We have already allocated space in the .got.  */  
                       break;  
                     }  
                   local_got_offsets[symtab_hdr->sh_info  
                                     + r_symndx] = sgot->_raw_size;  
                 }  
6372                else                else
                 {  
 #endif  
               if (local_got_offsets[r_symndx] != (bfd_vma) -1)  
                 {  
                   /* We have already allocated space in the .got.  */  
                   break;  
                 }  
               local_got_offsets[r_symndx] = sgot->_raw_size;  
 #ifdef INCLUDE_SHMEDIA  
                 }  
6373  #endif  #endif
6374                    local_got_refcounts[r_symndx] += 1;
6375                  old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
6376                }
6377    
6378                if (info->shared)            /* If a TLS symbol is accessed using IE at least once,
6379                 there is no point to use dynamic model for it.  */
6380              if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
6381                  && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
6382                {
6383                  if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
6384                    tls_type = GOT_TLS_IE;
6385                  else
6386                  {                  {
6387                    /* If we are generating a shared object, we need to                    (*_bfd_error_handler)
6388                       output a R_SH_RELATIVE reloc so that the dynamic                      (_("%B: `%s' accessed both as normal and thread local symbol"),
6389                       linker can adjust this GOT entry.  */                       abfd, h->root.root.string);
6390                    srelgot->_raw_size += sizeof (Elf32_External_Rela);                    return FALSE;
6391                  }                  }
6392              }              }
6393    
6394            sgot->_raw_size += 4;            if (old_tls_type != tls_type)
6395                {
6396                  if (h != NULL)
6397                    sh_elf_hash_entry (h)->tls_type = tls_type;
6398                  else
6399                    sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
6400                }
6401    
6402            break;            break;
6403    
6404            case R_SH_TLS_LD_32:
6405              sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6406              break;
6407    
6408          case R_SH_GOTPLT32:          case R_SH_GOTPLT32:
6409  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
6410          case R_SH_GOTPLT_LOW16:          case R_SH_GOTPLT_LOW16:
# Line 5166  sh_elf_check_relocs (abfd, info, sec, re Line 6418  sh_elf_check_relocs (abfd, info, sec, re
6418               creating a procedure linkage table entry.  */               creating a procedure linkage table entry.  */
6419    
6420            if (h == NULL            if (h == NULL
6421                || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL                || h->forced_local
               || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN  
6422                || ! info->shared                || ! info->shared
6423                || info->symbolic                || info->symbolic
6424                || h->dynindx == -1                || h->dynindx == -1)
               || h->got.offset != (bfd_vma) -1)  
6425              goto force_got;              goto force_got;
6426    
6427            /* Make sure this symbol is output as a dynamic symbol.  */            h->needs_plt = 1;
6428            if (h->dynindx == -1)            h->plt.refcount += 1;
6429              {            ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
               if (! bfd_elf32_link_record_dynamic_symbol (info, h))  
                 return false;  
             }  
   
           h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;  
6430    
6431            break;            break;
6432    
# Line 5204  sh_elf_check_relocs (abfd, info, sec, re Line 6449  sh_elf_check_relocs (abfd, info, sec, re
6449            if (h == NULL)            if (h == NULL)
6450              continue;              continue;
6451    
6452            if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL            if (h->forced_local)
               || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)  
6453              break;              break;
6454    
6455            h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;            h->needs_plt = 1;
6456              h->plt.refcount += 1;
6457            break;            break;
6458    
6459          case R_SH_DIR32:          case R_SH_DIR32:
6460          case R_SH_REL32:          case R_SH_REL32:
6461            if (h != NULL)  #ifdef INCLUDE_SHMEDIA
6462              h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;          case R_SH_IMM_LOW16_PCREL:
6463            case R_SH_IMM_MEDLOW16_PCREL:
6464            case R_SH_IMM_MEDHI16_PCREL:
6465            case R_SH_IMM_HI16_PCREL:
6466    #endif
6467              if (h != NULL && ! info->shared)
6468                {
6469                  h->non_got_ref = 1;
6470                  h->plt.refcount += 1;
6471                }
6472    
6473            /* If we are creating a shared library, and this is a reloc            /* If we are creating a shared library, and this is a reloc
6474               against a global symbol, or a non PC relative reloc               against a global symbol, or a non PC relative reloc
# Line 5228  sh_elf_check_relocs (abfd, info, sec, re Line 6481  sh_elf_check_relocs (abfd, info, sec, re
6481               possible that DEF_REGULAR is not set now but will be set               possible that DEF_REGULAR is not set now but will be set
6482               later (it is never cleared).  We account for that               later (it is never cleared).  We account for that
6483               possibility below by storing information in the               possibility below by storing information in the
6484               pcrel_relocs_copied field of the hash table entry.  */               dyn_relocs field of the hash table entry. A similar
6485            if (info->shared               situation occurs when creating shared libraries and symbol
6486                && (sec->flags & SEC_ALLOC) != 0               visibility changes render the symbol local.
6487                && (ELF32_R_TYPE (rel->r_info) != R_SH_REL32  
6488                    || (h != NULL               If on the other hand, we are creating an executable, we
6489                        && (! info->symbolic               may need to keep relocations for symbols satisfied by a
6490                            || (h->elf_link_hash_flags               dynamic library if we manage to avoid copy relocs for the
6491                                & ELF_LINK_HASH_DEF_REGULAR) == 0))))               symbol.  */
6492              if ((info->shared
6493                   && (sec->flags & SEC_ALLOC) != 0
6494                   && (r_type != R_SH_REL32
6495                       || (h != NULL
6496                           && (! info->symbolic
6497                               || h->root.type == bfd_link_hash_defweak
6498                               || !h->def_regular))))
6499                  || (! info->shared
6500                      && (sec->flags & SEC_ALLOC) != 0
6501                      && h != NULL
6502                      && (h->root.type == bfd_link_hash_defweak
6503                          || !h->def_regular)))
6504              {              {
6505                  struct elf_sh_dyn_relocs *p;
6506                  struct elf_sh_dyn_relocs **head;
6507    
6508                  if (htab->root.dynobj == NULL)
6509                    htab->root.dynobj = abfd;
6510    
6511                /* When creating a shared object, we must copy these                /* When creating a shared object, we must copy these
6512                   reloc types into the output file.  We create a reloc                   reloc types into the output file.  We create a reloc
6513                   section in dynobj and make room for this reloc.  */                   section in dynobj and make room for this reloc.  */
# Line 5249  sh_elf_check_relocs (abfd, info, sec, re Line 6520  sh_elf_check_relocs (abfd, info, sec, re
6520                             elf_elfheader (abfd)->e_shstrndx,                             elf_elfheader (abfd)->e_shstrndx,
6521                             elf_section_data (sec)->rel_hdr.sh_name));                             elf_section_data (sec)->rel_hdr.sh_name));
6522                    if (name == NULL)                    if (name == NULL)
6523                      return false;                      return FALSE;
6524    
6525                    BFD_ASSERT (strncmp (name, ".rela", 5) == 0                    BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6526                                && strcmp (bfd_get_section_name (abfd, sec),                                && strcmp (bfd_get_section_name (abfd, sec),
6527                                           name + 5) == 0);                                           name + 5) == 0);
6528    
6529                    sreloc = bfd_get_section_by_name (dynobj, name);                    sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
6530                    if (sreloc == NULL)                    if (sreloc == NULL)
6531                      {                      {
6532                        flagword flags;                        flagword flags;
6533    
6534                        sreloc = bfd_make_section (dynobj, name);                        sreloc = bfd_make_section (htab->root.dynobj, name);
6535                        flags = (SEC_HAS_CONTENTS | SEC_READONLY                        flags = (SEC_HAS_CONTENTS | SEC_READONLY
6536                                 | SEC_IN_MEMORY | SEC_LINKER_CREATED);                                 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6537                        if ((sec->flags & SEC_ALLOC) != 0)                        if ((sec->flags & SEC_ALLOC) != 0)
6538                          flags |= SEC_ALLOC | SEC_LOAD;                          flags |= SEC_ALLOC | SEC_LOAD;
6539                        if (sreloc == NULL                        if (sreloc == NULL
6540                            || ! bfd_set_section_flags (dynobj, sreloc, flags)                            || ! bfd_set_section_flags (htab->root.dynobj,
6541                            || ! bfd_set_section_alignment (dynobj, sreloc, 2))                                                        sreloc, flags)
6542                          return false;                            || ! bfd_set_section_alignment (htab->root.dynobj,
6543                                                              sreloc, 2))
6544                            return FALSE;
6545                      }                      }
6546                    if (sec->flags & SEC_READONLY)                    elf_section_data (sec)->sreloc = sreloc;
                     info->flags |= DF_TEXTREL;  
6547                  }                  }
6548    
6549                sreloc->_raw_size += sizeof (Elf32_External_Rela);                /* If this is a global symbol, we count the number of
6550                     relocations we need for this symbol.  */
6551                /* If we are linking with -Bsymbolic, and this is a                if (h != NULL)
6552                   global symbol, we count the number of PC relative                  head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6553                   relocations we have entered for this symbol, so that                else
                  we can discard them again if the symbol is later  
                  defined by a regular object.  Note that this function  
                  is only called if we are using an elf_sh linker  
                  hash table, which means that h is really a pointer to  
                  an elf_sh_link_hash_entry.  */  
               if (h != NULL && info->symbolic  
                   && ELF32_R_TYPE (rel->r_info) == R_SH_REL32)  
6554                  {                  {
6555                    struct elf_sh_link_hash_entry *eh;                    asection *s;
                   struct elf_sh_pcrel_relocs_copied *p;  
6556    
6557                    eh = (struct elf_sh_link_hash_entry *) h;                    /* Track dynamic relocs needed for local syms too.  */
6558                      s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6559                                                     sec, r_symndx);
6560                      if (s == NULL)
6561                        return FALSE;
6562    
6563                    for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)                    head = ((struct elf_sh_dyn_relocs **)
6564                      if (p->section == sreloc)                            &elf_section_data (s)->local_dynrel);
6565                        break;                  }
6566    
6567                  p = *head;
6568                  if (p == NULL || p->sec != sec)
6569                    {
6570                      bfd_size_type amt = sizeof (*p);
6571                      p = bfd_alloc (htab->root.dynobj, amt);
6572                    if (p == NULL)                    if (p == NULL)
6573                      {                      return FALSE;
6574                        p = ((struct elf_sh_pcrel_relocs_copied *)                    p->next = *head;
6575                             bfd_alloc (dynobj, (bfd_size_type) sizeof *p));                    *head = p;
6576                        if (p == NULL)                    p->sec = sec;
6577                          return false;                    p->count = 0;
6578                        p->next = eh->pcrel_relocs_copied;                    p->pc_count = 0;
                       eh->pcrel_relocs_copied = p;  
                       p->section = sreloc;  
                       p->count = 0;  
                     }  
   
                   ++p->count;  
6579                  }                  }
6580    
6581                  p->count += 1;
6582                  if (r_type == R_SH_REL32
6583    #ifdef INCLUDE_SHMEDIA
6584                      || r_type == R_SH_IMM_LOW16_PCREL
6585                      || r_type == R_SH_IMM_MEDLOW16_PCREL
6586                      || r_type == R_SH_IMM_MEDHI16_PCREL
6587                      || r_type == R_SH_IMM_HI16_PCREL
6588    #endif
6589                      )
6590                    p->pc_count += 1;
6591                }
6592    
6593              break;
6594    
6595            case R_SH_TLS_LE_32:
6596              if (info->shared)
6597                {
6598                  (*_bfd_error_handler)
6599                    (_("%B: TLS local exec code cannot be linked into shared objects"),
6600                     abfd);
6601                  return FALSE;
6602              }              }
6603    
6604            break;            break;
6605    
6606            case R_SH_TLS_LDO_32:
6607              /* Nothing to do.  */
6608              break;
6609    
6610            default:
6611              break;
6612          }          }
6613      }      }
6614    
6615    return true;    return TRUE;
6616  }  }
6617    
6618  #ifndef sh_elf_set_mach_from_flags  #ifndef sh_elf_set_mach_from_flags
6619  static boolean  static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE };
6620  sh_elf_set_mach_from_flags (abfd)  
6621       bfd *abfd;  static bfd_boolean
6622    sh_elf_set_mach_from_flags (bfd *abfd)
6623  {  {
6624    flagword flags = elf_elfheader (abfd)->e_flags;    flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK;
6625    
6626    switch (flags & EF_SH_MACH_MASK)    if (flags >= sizeof(sh_ef_bfd_table))
6627      {      return FALSE;
6628      case EF_SH1:  
6629        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh);    if (sh_ef_bfd_table[flags] == 0)
6630        break;      return FALSE;
6631      case EF_SH2:    
6632        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);    bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]);
6633        break;  
6634      case EF_SH_DSP:    return TRUE;
6635        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp);  }
6636        break;  
6637      case EF_SH3:  
6638        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3);  /* Reverse table lookup for sh_ef_bfd_table[].
6639        break;     Given a bfd MACH value from archures.c
6640      case EF_SH3_DSP:     return the equivalent ELF flags from the table.
6641        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3_dsp);     Return -1 if no match is found.  */
6642        break;  
6643      case EF_SH3E:  int
6644        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3e);  sh_elf_get_flags_from_mach (unsigned long mach)
6645        break;  {
6646      case EF_SH_UNKNOWN:    int i = ARRAY_SIZE (sh_ef_bfd_table);
6647      case EF_SH4:    
6648        bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4);    for (; i>0; i--)
6649        break;      if (sh_ef_bfd_table[i] == mach)
6650      default:        return i;
6651        return false;    
6652      }    /* shouldn't get here */
6653    return true;    BFD_FAIL();
6654    
6655      return -1;
6656  }  }
6657  #endif /* not sh_elf_set_mach_from_flags */  #endif /* not sh_elf_set_mach_from_flags */
6658    
6659  #ifndef sh_elf_set_private_flags  #ifndef sh_elf_set_private_flags
6660  /* Function to keep SH specific file flags.  */  /* Function to keep SH specific file flags.  */
6661    
6662  static boolean  static bfd_boolean
6663  sh_elf_set_private_flags (abfd, flags)  sh_elf_set_private_flags (bfd *abfd, flagword flags)
      bfd *abfd;  
      flagword flags;  
6664  {  {
6665    BFD_ASSERT (! elf_flags_init (abfd)    BFD_ASSERT (! elf_flags_init (abfd)
6666                || elf_elfheader (abfd)->e_flags == flags);                || elf_elfheader (abfd)->e_flags == flags);
6667    
6668    elf_elfheader (abfd)->e_flags = flags;    elf_elfheader (abfd)->e_flags = flags;
6669    elf_flags_init (abfd) = true;    elf_flags_init (abfd) = TRUE;
6670    return sh_elf_set_mach_from_flags (abfd);    return sh_elf_set_mach_from_flags (abfd);
6671  }  }
6672  #endif /* not sh_elf_set_private_flags */  #endif /* not sh_elf_set_private_flags */
# Line 5377  sh_elf_set_private_flags (abfd, flags) Line 6674  sh_elf_set_private_flags (abfd, flags)
6674  #ifndef sh_elf_copy_private_data  #ifndef sh_elf_copy_private_data
6675  /* Copy backend specific data from one object module to another */  /* Copy backend specific data from one object module to another */
6676    
6677  static boolean  static bfd_boolean
6678  sh_elf_copy_private_data (ibfd, obfd)  sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
      bfd * ibfd;  
      bfd * obfd;  
6679  {  {
6680    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6681        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6682      return true;      return TRUE;
6683    
6684    return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);    return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
6685  }  }
6686  #endif /* not sh_elf_copy_private_data */  #endif /* not sh_elf_copy_private_data */
6687    
6688  #ifndef sh_elf_merge_private_data  #ifndef sh_elf_merge_private_data
 /* This routine checks for linking big and little endian objects  
    together, and for linking sh-dsp with sh3e / sh4 objects.  */  
6689    
6690  static boolean  /* This function returns the ELF architecture number that
6691  sh_elf_merge_private_data (ibfd, obfd)     corresponds to the given arch_sh* flags.  */
6692       bfd *ibfd;  
6693       bfd *obfd;  int
6694    sh_find_elf_flags (unsigned int arch_set)
6695  {  {
6696    flagword old_flags, new_flags;    extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
6697      unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set);
6698    
6699      return sh_elf_get_flags_from_mach (bfd_mach);
6700    }
6701    
6702    if (! _bfd_generic_verify_endian_match (ibfd, obfd))  /* This routine initialises the elf flags when required and
6703      return false;     calls sh_merge_bfd_arch() to check dsp/fpu compatibility.  */
6704    
6705    static bfd_boolean
6706    sh_elf_merge_private_data (bfd *ibfd, bfd *obfd)
6707    {
6708      extern bfd_boolean sh_merge_bfd_arch (bfd *, bfd *);
6709    
6710    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6711        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6712      return true;      return TRUE;
6713    
6714    if (! elf_flags_init (obfd))    if (! elf_flags_init (obfd))
6715      {      {
6716        /* This happens when ld starts out with a 'blank' output file.  */        /* This happens when ld starts out with a 'blank' output file.  */
6717        elf_flags_init (obfd) = true;        elf_flags_init (obfd) = TRUE;
6718        elf_elfheader (obfd)->e_flags = EF_SH1;        elf_elfheader (obfd)->e_flags = EF_SH1;
6719          sh_elf_set_mach_from_flags (obfd);
6720      }      }
6721    old_flags = elf_elfheader (obfd)->e_flags;  
6722    new_flags = elf_elfheader (ibfd)->e_flags;    if (! sh_merge_bfd_arch (ibfd, obfd))
6723    if ((EF_SH_HAS_DSP (old_flags) && EF_SH_HAS_FP (new_flags))      {
6724        || (EF_SH_HAS_DSP (new_flags) && EF_SH_HAS_FP (old_flags)))        _bfd_error_handler ("%B: uses instructions which are incompatible "
6725      {                            "with instructions used in previous modules",
6726        (*_bfd_error_handler)                            ibfd);
         ("%s: uses %s instructions while previous modules use %s instructions",  
          bfd_archive_filename (ibfd),  
          EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point",  
          EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp");  
6727        bfd_set_error (bfd_error_bad_value);        bfd_set_error (bfd_error_bad_value);
6728        return false;        return FALSE;
6729      }      }
   elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags);  
6730    
6731    return sh_elf_set_mach_from_flags (obfd);    elf_elfheader (obfd)->e_flags =
6732        sh_elf_get_flags_from_mach (bfd_get_mach (obfd));
6733      
6734      return TRUE;
6735  }  }
6736  #endif /* not sh_elf_merge_private_data */  #endif /* not sh_elf_merge_private_data */
6737    
6738    /* Override the generic function because we need to store sh_elf_obj_tdata
6739       as the specific tdata.  We set also the machine architecture from flags
6740       here.  */
6741    
6742    static bfd_boolean
6743    sh_elf_object_p (bfd *abfd)
6744    {
6745      return sh_elf_set_mach_from_flags (abfd);
6746    }
6747    
6748  /* Finish up dynamic symbol handling.  We set the contents of various  /* Finish up dynamic symbol handling.  We set the contents of various
6749     dynamic sections here.  */     dynamic sections here.  */
6750    
6751  static boolean  static bfd_boolean
6752  sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)  sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6753       bfd *output_bfd;                                struct elf_link_hash_entry *h,
6754       struct bfd_link_info *info;                                Elf_Internal_Sym *sym)
      struct elf_link_hash_entry *h;  
      Elf_Internal_Sym *sym;  
6755  {  {
6756    bfd *dynobj;    struct elf_sh_link_hash_table *htab;
6757    
6758    dynobj = elf_hash_table (info)->dynobj;    htab = sh_elf_hash_table (info);
6759    
6760    if (h->plt.offset != (bfd_vma) -1)    if (h->plt.offset != (bfd_vma) -1)
6761      {      {
# Line 5456  sh_elf_finish_dynamic_symbol (output_bfd Line 6766  sh_elf_finish_dynamic_symbol (output_bfd
6766        bfd_vma plt_index;        bfd_vma plt_index;
6767        bfd_vma got_offset;        bfd_vma got_offset;
6768        Elf_Internal_Rela rel;        Elf_Internal_Rela rel;
6769          bfd_byte *loc;
6770    
6771        /* This symbol has an entry in the procedure linkage table.  Set        /* This symbol has an entry in the procedure linkage table.  Set
6772           it up.  */           it up.  */
6773    
6774        BFD_ASSERT (h->dynindx != -1);        BFD_ASSERT (h->dynindx != -1);
6775    
6776        splt = bfd_get_section_by_name (dynobj, ".plt");        splt = htab->splt;
6777        sgot = bfd_get_section_by_name (dynobj, ".got.plt");        sgot = htab->sgotplt;
6778        srel = bfd_get_section_by_name (dynobj, ".rela.plt");        srel = htab->srelplt;
6779        BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);        BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
6780    
6781        /* Get the index in the procedure linkage table which        /* Get the index in the procedure linkage table which
# Line 5479  sh_elf_finish_dynamic_symbol (output_bfd Line 6790  sh_elf_finish_dynamic_symbol (output_bfd
6790        got_offset = (plt_index + 3) * 4;        got_offset = (plt_index + 3) * 4;
6791    
6792  #ifdef GOT_BIAS  #ifdef GOT_BIAS
6793        got_offset -= GOT_BIAS;        if (info->shared)
6794            got_offset -= GOT_BIAS;
6795  #endif  #endif
6796    
6797        /* Fill in the entry in the procedure linkage table.  */        /* Fill in the entry in the procedure linkage table.  */
# Line 5500  sh_elf_finish_dynamic_symbol (output_bfd Line 6812  sh_elf_finish_dynamic_symbol (output_bfd
6812                               (splt->contents + h->plt.offset                               (splt->contents + h->plt.offset
6813                                + elf_sh_plt_symbol_offset (info)));                                + elf_sh_plt_symbol_offset (info)));
6814    
6815              /* Set bottom bit because its for a branch to SHmedia */
6816            movi_shori_putval (output_bfd,            movi_shori_putval (output_bfd,
6817                               (splt->output_section->vma + splt->output_offset),                               (splt->output_section->vma + splt->output_offset)
6818                                 | 1,
6819                               (splt->contents + h->plt.offset                               (splt->contents + h->plt.offset
6820                                + elf_sh_plt_plt0_offset (info)));                                + elf_sh_plt_plt0_offset (info)));
6821  #else  #else
# Line 5540  sh_elf_finish_dynamic_symbol (output_bfd Line 6854  sh_elf_finish_dynamic_symbol (output_bfd
6854          }          }
6855    
6856  #ifdef GOT_BIAS  #ifdef GOT_BIAS
6857        got_offset += GOT_BIAS;        if (info->shared)
6858            got_offset += GOT_BIAS;
6859  #endif  #endif
6860    
6861  #ifdef INCLUDE_SHMEDIA  #ifdef INCLUDE_SHMEDIA
# Line 5571  sh_elf_finish_dynamic_symbol (output_bfd Line 6886  sh_elf_finish_dynamic_symbol (output_bfd
6886  #ifdef GOT_BIAS  #ifdef GOT_BIAS
6887        rel.r_addend = GOT_BIAS;        rel.r_addend = GOT_BIAS;
6888  #endif  #endif
6889        bfd_elf32_swap_reloca_out (output_bfd, &rel,        loc = srel->contents + plt_index * sizeof (Elf32_External_Rela);
6890                                  ((Elf32_External_Rela *) srel->contents        bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
                                  + plt_index));  
6891    
6892        if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)        if (!h->def_regular)
6893          {          {
6894            /* Mark the symbol as undefined, rather than as defined in            /* Mark the symbol as undefined, rather than as defined in
6895               the .plt section.  Leave the value alone.  */               the .plt section.  Leave the value alone.  */
# Line 5583  sh_elf_finish_dynamic_symbol (output_bfd Line 6897  sh_elf_finish_dynamic_symbol (output_bfd
6897          }          }
6898      }      }
6899    
6900    if (h->got.offset != (bfd_vma) -1)    if (h->got.offset != (bfd_vma) -1
6901          && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
6902          && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
6903      {      {
6904        asection *sgot;        asection *sgot;
6905        asection *srel;        asection *srel;
6906        Elf_Internal_Rela rel;        Elf_Internal_Rela rel;
6907          bfd_byte *loc;
6908    
6909        /* This symbol has an entry in the global offset table.  Set it        /* This symbol has an entry in the global offset table.  Set it
6910           up.  */           up.  */
6911    
6912        sgot = bfd_get_section_by_name (dynobj, ".got");        sgot = htab->sgot;
6913        srel = bfd_get_section_by_name (dynobj, ".rela.got");        srel = htab->srelgot;
6914        BFD_ASSERT (sgot != NULL && srel != NULL);        BFD_ASSERT (sgot != NULL && srel != NULL);
6915    
6916        rel.r_offset = (sgot->output_section->vma        rel.r_offset = (sgot->output_section->vma
6917                        + sgot->output_offset                        + sgot->output_offset
6918                        + (h->got.offset &~ (bfd_vma) 1));                        + (h->got.offset &~ (bfd_vma) 1));
6919    
6920        /* If this is a -Bsymbolic link, and the symbol is defined        /* If this is a static link, or it is a -Bsymbolic link and the
6921           locally, we just want to emit a RELATIVE reloc.  Likewise if           symbol is defined locally or was forced to be local because
6922           the symbol was forced to be local because of a version file.           of a version file, we just want to emit a RELATIVE reloc.
6923           The entry in the global offset table will already have been           The entry in the global offset table will already have been
6924           initialized in the relocate_section function.  */           initialized in the relocate_section function.  */
6925        if (info->shared        if (info->shared
6926            && (info->symbolic || h->dynindx == -1)            && SYMBOL_REFERENCES_LOCAL (info, h))
           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))  
6927          {          {
6928            rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);            rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6929            rel.r_addend = (h->root.u.def.value            rel.r_addend = (h->root.u.def.value
# Line 5621  sh_elf_finish_dynamic_symbol (output_bfd Line 6937  sh_elf_finish_dynamic_symbol (output_bfd
6937            rel.r_addend = 0;            rel.r_addend = 0;
6938          }          }
6939    
6940        bfd_elf32_swap_reloca_out (output_bfd, &rel,        loc = srel->contents;
6941                                   ((Elf32_External_Rela *) srel->contents        loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
6942                                    + srel->reloc_count));        bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
       ++srel->reloc_count;  
6943      }      }
6944    
6945    if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)  #ifdef INCLUDE_SHMEDIA
6946      {
6947        struct elf_sh_link_hash_entry *eh;
6948    
6949        eh = (struct elf_sh_link_hash_entry *) h;
6950        if (eh->datalabel_got.offset != (bfd_vma) -1)
6951          {
6952            asection *sgot;
6953            asection *srel;
6954            Elf_Internal_Rela rel;
6955            bfd_byte *loc;
6956    
6957            /* This symbol has a datalabel entry in the global offset table.
6958               Set it up.  */
6959    
6960            sgot = htab->sgot;
6961            srel = htab->srelgot;
6962            BFD_ASSERT (sgot != NULL && srel != NULL);
6963    
6964            rel.r_offset = (sgot->output_section->vma
6965                            + sgot->output_offset
6966                            + (eh->datalabel_got.offset &~ (bfd_vma) 1));
6967    
6968            /* If this is a static link, or it is a -Bsymbolic link and the
6969               symbol is defined locally or was forced to be local because
6970               of a version file, we just want to emit a RELATIVE reloc.
6971               The entry in the global offset table will already have been
6972               initialized in the relocate_section function.  */
6973            if (info->shared
6974                && SYMBOL_REFERENCES_LOCAL (info, h))
6975              {
6976                rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6977                rel.r_addend = (h->root.u.def.value
6978                                + h->root.u.def.section->output_section->vma
6979                                + h->root.u.def.section->output_offset);
6980              }
6981            else
6982              {
6983                bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
6984                            + eh->datalabel_got.offset);
6985                rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6986                rel.r_addend = 0;
6987              }
6988    
6989            loc = srel->contents;
6990            loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
6991            bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6992          }
6993      }
6994    #endif
6995    
6996      if (h->needs_copy)
6997      {      {
6998        asection *s;        asection *s;
6999        Elf_Internal_Rela rel;        Elf_Internal_Rela rel;
7000          bfd_byte *loc;
7001    
7002        /* This symbol needs a copy reloc.  Set it up.  */        /* This symbol needs a copy reloc.  Set it up.  */
7003    
# Line 5647  sh_elf_finish_dynamic_symbol (output_bfd Line 7014  sh_elf_finish_dynamic_symbol (output_bfd
7014                        + h->root.u.def.section->output_offset);                        + h->root.u.def.section->output_offset);
7015        rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);        rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
7016        rel.r_addend = 0;        rel.r_addend = 0;
7017        bfd_elf32_swap_reloca_out (output_bfd, &rel,        loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
7018                                   ((Elf32_External_Rela *) s->contents        bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
                                   + s->reloc_count));  
       ++s->reloc_count;  
7019      }      }
7020    
7021    /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */    /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
# Line 5658  sh_elf_finish_dynamic_symbol (output_bfd Line 7023  sh_elf_finish_dynamic_symbol (output_bfd
7023        || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)        || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7024      sym->st_shndx = SHN_ABS;      sym->st_shndx = SHN_ABS;
7025    
7026    return true;    return TRUE;
7027  }  }
7028    
7029  /* Finish up the dynamic sections.  */  /* Finish up the dynamic sections.  */
7030    
7031  static boolean  static bfd_boolean
7032  sh_elf_finish_dynamic_sections (output_bfd, info)  sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
      bfd *output_bfd;  
      struct bfd_link_info *info;  
7033  {  {
7034    bfd *dynobj;    struct elf_sh_link_hash_table *htab;
7035    asection *sgot;    asection *sgot;
7036    asection *sdyn;    asection *sdyn;
7037    
7038    dynobj = elf_hash_table (info)->dynobj;    htab = sh_elf_hash_table (info);
7039      sgot = htab->sgotplt;
7040    sgot = bfd_get_section_by_name (dynobj, ".got.plt");    sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic");
   BFD_ASSERT (sgot != NULL);  
   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");  
7041    
7042    if (elf_hash_table (info)->dynamic_sections_created)    if (htab->root.dynamic_sections_created)
7043      {      {
7044        asection *splt;        asection *splt;
7045        Elf32_External_Dyn *dyncon, *dynconend;        Elf32_External_Dyn *dyncon, *dynconend;
7046    
7047        BFD_ASSERT (sdyn != NULL);        BFD_ASSERT (sgot != NULL && sdyn != NULL);
7048    
7049        dyncon = (Elf32_External_Dyn *) sdyn->contents;        dyncon = (Elf32_External_Dyn *) sdyn->contents;
7050        dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);        dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
7051        for (; dyncon < dynconend; dyncon++)        for (; dyncon < dynconend; dyncon++)
7052          {          {
7053            Elf_Internal_Dyn dyn;            Elf_Internal_Dyn dyn;
           const char *name;  
7054            asection *s;            asection *s;
7055    #ifdef INCLUDE_SHMEDIA
7056              const char *name;
7057    #endif
7058    
7059            bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);            bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
7060    
7061            switch (dyn.d_tag)            switch (dyn.d_tag)
7062              {              {
7063              default:              default:
7064                break;                break;
7065    
7066    #ifdef INCLUDE_SHMEDIA
7067                case DT_INIT:
7068                  name = info->init_function;
7069                  goto get_sym;
7070    
7071                case DT_FINI:
7072                  name = info->fini_function;
7073                get_sym:
7074                  if (dyn.d_un.d_val != 0)
7075                    {
7076                      struct elf_link_hash_entry *h;
7077    
7078                      h = elf_link_hash_lookup (&htab->root, name,
7079                                                FALSE, FALSE, TRUE);
7080                      if (h != NULL && (h->other & STO_SH5_ISA32))
7081                        {
7082                          dyn.d_un.d_val |= 1;
7083                          bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7084                        }
7085                    }
7086                  break;
7087    #endif
7088    
7089              case DT_PLTGOT:              case DT_PLTGOT:
7090                name = ".got";                s = htab->sgot->output_section;
7091                goto get_vma;                goto get_vma;
7092    
7093              case DT_JMPREL:              case DT_JMPREL:
7094                name = ".rela.plt";                s = htab->srelplt->output_section;
7095              get_vma:              get_vma:
               s = bfd_get_section_by_name (output_bfd, name);  
7096                BFD_ASSERT (s != NULL);                BFD_ASSERT (s != NULL);
7097                dyn.d_un.d_ptr = s->vma;                dyn.d_un.d_ptr = s->vma;
7098                bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);                bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7099                break;                break;
7100    
7101              case DT_PLTRELSZ:              case DT_PLTRELSZ:
7102                s = bfd_get_section_by_name (output_bfd, ".rela.plt");                s = htab->srelplt->output_section;
7103                BFD_ASSERT (s != NULL);                BFD_ASSERT (s != NULL);
7104                if (s->_cooked_size != 0)                dyn.d_un.d_val = s->size;
                 dyn.d_un.d_val = s->_cooked_size;  
               else  
                 dyn.d_un.d_val = s->_raw_size;  
7105                bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);                bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7106                break;                break;
7107    
# Line 5733  sh_elf_finish_dynamic_sections (output_b Line 7115  sh_elf_finish_dynamic_sections (output_b
7115                   the linker script arranges for .rela.plt to follow all                   the linker script arranges for .rela.plt to follow all
7116                   other relocation sections, we don't have to worry                   other relocation sections, we don't have to worry
7117                   about changing the DT_RELA entry.  */                   about changing the DT_RELA entry.  */
7118                s = bfd_get_section_by_name (output_bfd, ".rela.plt");                if (htab->srelplt != NULL)
               if (s != NULL)  
7119                  {                  {
7120                    if (s->_cooked_size != 0)                    s = htab->srelplt->output_section;
7121                      dyn.d_un.d_val -= s->_cooked_size;                    dyn.d_un.d_val -= s->size;
                   else  
                     dyn.d_un.d_val -= s->_raw_size;  
7122                  }                  }
7123                bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);                bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7124                break;                break;
# Line 5747  sh_elf_finish_dynamic_sections (output_b Line 7126  sh_elf_finish_dynamic_sections (output_b
7126          }          }
7127    
7128        /* Fill in the first entry in the procedure linkage table.  */        /* Fill in the first entry in the procedure linkage table.  */
7129        splt = bfd_get_section_by_name (dynobj, ".plt");        splt = htab->splt;
7130        if (splt && splt->_raw_size > 0)        if (splt && splt->size > 0)
7131          {          {
7132            if (info->shared)            if (info->shared)
7133              {              {
# Line 5793  sh_elf_finish_dynamic_sections (output_b Line 7172  sh_elf_finish_dynamic_sections (output_b
7172      }      }
7173    
7174    /* Fill in the first three entries in the global offset table.  */    /* Fill in the first three entries in the global offset table.  */
7175    if (sgot->_raw_size > 0)    if (sgot && sgot->size > 0)
7176      {      {
7177        if (sdyn == NULL)        if (sdyn == NULL)
7178          bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);          bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
# Line 5803  sh_elf_finish_dynamic_sections (output_b Line 7182  sh_elf_finish_dynamic_sections (output_b
7182                      sgot->contents);                      sgot->contents);
7183        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7184        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
     }  
7185    
7186    elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;        elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7187        }
7188    
7189    return true;    return TRUE;
7190  }  }
7191    
7192  static enum elf_reloc_type_class  static enum elf_reloc_type_class
7193  sh_elf_reloc_type_class (rela)  sh_elf_reloc_type_class (const Elf_Internal_Rela *rela)
      const Elf_Internal_Rela *rela;  
7194  {  {
7195    switch ((int) ELF32_R_TYPE (rela->r_info))    switch ((int) ELF32_R_TYPE (rela->r_info))
7196      {      {
# Line 5827  sh_elf_reloc_type_class (rela) Line 7205  sh_elf_reloc_type_class (rela)
7205      }      }
7206  }  }
7207    
7208  #ifndef ELF_ARCH  #if !defined SH_TARGET_ALREADY_DEFINED
7209    /* Support for Linux core dump NOTE sections.  */
7210    
7211    static bfd_boolean
7212    elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7213    {
7214      int offset;
7215      unsigned int size;
7216    
7217      switch (note->descsz)
7218        {
7219          default:
7220            return FALSE;
7221    
7222          case 168:         /* Linux/SH */
7223            /* pr_cursig */
7224            elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
7225    
7226            /* pr_pid */
7227            elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
7228    
7229            /* pr_reg */
7230            offset = 72;
7231            size = 92;
7232    
7233            break;
7234        }
7235    
7236      /* Make a ".reg/999" section.  */
7237      return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7238                                              size, note->descpos + offset);
7239    }
7240    
7241    static bfd_boolean
7242    elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7243    {
7244      switch (note->descsz)
7245        {
7246          default:
7247            return FALSE;
7248    
7249          case 124:         /* Linux/SH elf_prpsinfo */
7250            elf_tdata (abfd)->core_program
7251             = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7252            elf_tdata (abfd)->core_command
7253             = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7254        }
7255    
7256      /* Note that for some reason, a spurious space is tacked
7257         onto the end of the args in some (at least one anyway)
7258         implementations, so strip it off if it exists.  */
7259    
7260      {
7261        char *command = elf_tdata (abfd)->core_command;
7262        int n = strlen (command);
7263    
7264        if (0 < n && command[n - 1] == ' ')
7265          command[n - 1] = '\0';
7266      }
7267    
7268      return TRUE;
7269    }
7270    #endif /* not SH_TARGET_ALREADY_DEFINED */
7271    
7272    
7273    /* Return address for Ith PLT stub in section PLT, for relocation REL
7274       or (bfd_vma) -1 if it should not be included.  */
7275    
7276    static bfd_vma
7277    sh_elf_plt_sym_val (bfd_vma i, const asection *plt,
7278                        const arelent *rel ATTRIBUTE_UNUSED)
7279    {
7280      return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
7281    }
7282    
7283    #if !defined SH_TARGET_ALREADY_DEFINED
7284  #define TARGET_BIG_SYM          bfd_elf32_sh_vec  #define TARGET_BIG_SYM          bfd_elf32_sh_vec
7285  #define TARGET_BIG_NAME         "elf32-sh"  #define TARGET_BIG_NAME         "elf32-sh"
7286  #define TARGET_LITTLE_SYM       bfd_elf32_shl_vec  #define TARGET_LITTLE_SYM       bfd_elf32_shl_vec
7287  #define TARGET_LITTLE_NAME      "elf32-shl"  #define TARGET_LITTLE_NAME      "elf32-shl"
7288    #endif
7289    
7290  #define ELF_ARCH                bfd_arch_sh  #define ELF_ARCH                bfd_arch_sh
7291  #define ELF_MACHINE_CODE        EM_SH  #define ELF_MACHINE_CODE        EM_SH
7292  #define ELF_MAXPAGESIZE         128  #ifdef __QNXTARGET__
7293    #define ELF_MAXPAGESIZE         0x1000
7294    #else
7295    #define ELF_MAXPAGESIZE         0x80
7296    #endif
7297    
7298  #define elf_symbol_leading_char '_'  #define elf_symbol_leading_char '_'
 #endif /* ELF_ARCH */  
7299    
7300  #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup  #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7301  #define elf_info_to_howto               sh_elf_info_to_howto  #define elf_info_to_howto               sh_elf_info_to_howto
# Line 5845  sh_elf_reloc_type_class (rela) Line 7303  sh_elf_reloc_type_class (rela)
7303  #define elf_backend_relocate_section    sh_elf_relocate_section  #define elf_backend_relocate_section    sh_elf_relocate_section
7304  #define bfd_elf32_bfd_get_relocated_section_contents \  #define bfd_elf32_bfd_get_relocated_section_contents \
7305                                          sh_elf_get_relocated_section_contents                                          sh_elf_get_relocated_section_contents
7306  #define elf_backend_object_p            sh_elf_set_mach_from_flags  #define bfd_elf32_mkobject              sh_elf_mkobject
7307    #define elf_backend_object_p            sh_elf_object_p
7308  #define bfd_elf32_bfd_set_private_bfd_flags \  #define bfd_elf32_bfd_set_private_bfd_flags \
7309                                          sh_elf_set_private_flags                                          sh_elf_set_private_flags
7310  #define bfd_elf32_bfd_copy_private_bfd_data \  #define bfd_elf32_bfd_copy_private_bfd_data \
# Line 5853  sh_elf_reloc_type_class (rela) Line 7312  sh_elf_reloc_type_class (rela)
7312  #define bfd_elf32_bfd_merge_private_bfd_data \  #define bfd_elf32_bfd_merge_private_bfd_data \
7313                                          sh_elf_merge_private_data                                          sh_elf_merge_private_data
7314    
7315  #define elf_backend_gc_mark_hook        sh_elf_gc_mark_hook  #define elf_backend_gc_mark_hook        sh_elf_gc_mark_hook
7316  #define elf_backend_gc_sweep_hook       sh_elf_gc_sweep_hook  #define elf_backend_gc_sweep_hook       sh_elf_gc_sweep_hook
7317  #define elf_backend_check_relocs        sh_elf_check_relocs  #define elf_backend_check_relocs        sh_elf_check_relocs
7318    #define elf_backend_copy_indirect_symbol \
7319  #define elf_backend_can_gc_sections     1                                          sh_elf_copy_indirect_symbol
7320  #define elf_backend_create_dynamic_sections \  #define elf_backend_create_dynamic_sections \
7321                                          sh_elf_create_dynamic_sections                                          sh_elf_create_dynamic_sections
7322  #define bfd_elf32_bfd_link_hash_table_create \  #define bfd_elf32_bfd_link_hash_table_create \
# Line 5871  sh_elf_reloc_type_class (rela) Line 7330  sh_elf_reloc_type_class (rela)
7330  #define elf_backend_finish_dynamic_sections \  #define elf_backend_finish_dynamic_sections \
7331                                          sh_elf_finish_dynamic_sections                                          sh_elf_finish_dynamic_sections
7332  #define elf_backend_reloc_type_class    sh_elf_reloc_type_class  #define elf_backend_reloc_type_class    sh_elf_reloc_type_class
7333    #define elf_backend_plt_sym_val         sh_elf_plt_sym_val
7334    
7335    #define elf_backend_can_gc_sections     1
7336    #define elf_backend_can_refcount        1
7337  #define elf_backend_want_got_plt        1  #define elf_backend_want_got_plt        1
7338  #define elf_backend_plt_readonly        1  #define elf_backend_plt_readonly        1
7339  #define elf_backend_want_plt_sym        0  #define elf_backend_want_plt_sym        0
7340  #define elf_backend_got_header_size     12  #define elf_backend_got_header_size     12
7341  #define elf_backend_plt_header_size     PLT_ENTRY_SIZE  
7342    #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
7343    
7344  #include "elf32-target.h"  #include "elf32-target.h"
7345    
7346    /* NetBSD support.  */
7347    #undef  TARGET_BIG_SYM
7348    #define TARGET_BIG_SYM                  bfd_elf32_shnbsd_vec
7349    #undef  TARGET_BIG_NAME
7350    #define TARGET_BIG_NAME                 "elf32-sh-nbsd"
7351    #undef  TARGET_LITTLE_SYM
7352    #define TARGET_LITTLE_SYM               bfd_elf32_shlnbsd_vec
7353    #undef  TARGET_LITTLE_NAME
7354    #define TARGET_LITTLE_NAME              "elf32-shl-nbsd"
7355    #undef  ELF_MAXPAGESIZE
7356    #define ELF_MAXPAGESIZE                 0x10000
7357    #undef  elf_symbol_leading_char
7358    #define elf_symbol_leading_char         0
7359    #undef  elf32_bed
7360    #define elf32_bed                       elf32_sh_nbsd_bed
7361    
7362    #include "elf32-target.h"
7363    
7364    
7365    /* Linux support.  */
7366    #undef  TARGET_BIG_SYM
7367    #define TARGET_BIG_SYM                  bfd_elf32_shblin_vec
7368    #undef  TARGET_BIG_NAME
7369    #define TARGET_BIG_NAME                 "elf32-shbig-linux"
7370    #undef  TARGET_LITTLE_SYM
7371    #define TARGET_LITTLE_SYM               bfd_elf32_shlin_vec
7372    #undef  TARGET_LITTLE_NAME
7373    #define TARGET_LITTLE_NAME              "elf32-sh-linux"
7374    
7375    #undef  elf_backend_grok_prstatus
7376    #define elf_backend_grok_prstatus       elf32_shlin_grok_prstatus
7377    #undef  elf_backend_grok_psinfo
7378    #define elf_backend_grok_psinfo         elf32_shlin_grok_psinfo
7379    #undef  elf32_bed
7380    #define elf32_bed                       elf32_sh_lin_bed
7381    
7382    #include "elf32-target.h"
7383    
7384    #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */

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