/[gcl]/gcl/binutils/bfd/elf-m10300.c
ViewVC logotype

Diff of /gcl/binutils/bfd/elf-m10300.c

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

revision 1.1.1.1 by camm, Fri Aug 9 05:35:07 2002 UTC revision 1.2 by camm, Fri Sep 9 23:32:08 2005 UTC
# Line 1  Line 1 
1  /* Matsushita 10300 specific support for 32-bit ELF  /* Matsushita 10300 specific support for 32-bit ELF
2     Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002     Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3     Free Software Foundation, Inc.     Free Software Foundation, Inc.
4    
5  This file is part of BFD, the Binary File Descriptor library.  This file is part of BFD, the Binary File Descriptor library.
# Line 26  Foundation, Inc., 59 Temple Place - Suit Line 26  Foundation, Inc., 59 Temple Place - Suit
26    
27  static bfd_reloc_status_type mn10300_elf_final_link_relocate  static bfd_reloc_status_type mn10300_elf_final_link_relocate
28    PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,    PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
29             bfd_vma, bfd_vma, bfd_vma, struct bfd_link_info *,             bfd_vma, bfd_vma, bfd_vma,
30               struct elf_link_hash_entry *, unsigned long, struct bfd_link_info *,
31             asection *, int));             asection *, int));
32  static boolean mn10300_elf_relocate_section  static bfd_boolean mn10300_elf_relocate_section
33    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
34             Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));             Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
35  static boolean mn10300_elf_relax_section  static bfd_boolean mn10300_elf_relax_section
36    PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));    PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
37  static bfd_byte * mn10300_elf_get_relocated_section_contents  static bfd_byte * mn10300_elf_get_relocated_section_contents
38    PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,    PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
39             bfd_byte *, boolean, asymbol **));             bfd_byte *, bfd_boolean, asymbol **));
40  static unsigned long elf_mn10300_mach PARAMS ((flagword));  static unsigned long elf_mn10300_mach
41      PARAMS ((flagword));
42    void _bfd_mn10300_elf_final_write_processing
43      PARAMS ((bfd *, bfd_boolean));
44    bfd_boolean _bfd_mn10300_elf_object_p
45      PARAMS ((bfd *));
46    bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data
47      PARAMS ((bfd *,bfd *));
48    
49  void    _bfd_mn10300_elf_final_write_processing PARAMS ((bfd *, boolean));  /* The mn10300 linker needs to keep track of the number of relocs that
50  boolean _bfd_mn10300_elf_object_p PARAMS ((bfd *));     it decides to copy in check_relocs for each symbol.  This is so
51  boolean _bfd_mn10300_elf_merge_private_bfd_data PARAMS ((bfd *,bfd *));     that it can discard PC relative relocs if it doesn't need them when
52       linking with -Bsymbolic.  We store the information in a field
53       extending the regular ELF linker hash table.  */
54    
55  struct elf32_mn10300_link_hash_entry {  struct elf32_mn10300_link_hash_entry {
56    /* The basic elf link hash table entry.  */    /* The basic elf link hash table entry.  */
# Line 62  struct elf32_mn10300_link_hash_entry { Line 72  struct elf32_mn10300_link_hash_entry {
72       to the target when it's valid and profitable to do so.  */       to the target when it's valid and profitable to do so.  */
73    unsigned char movm_args;    unsigned char movm_args;
74    
75    /* For funtion symbols, the amount of stack space that would be allocated    /* For function symbols, the amount of stack space that would be allocated
76       by the movm instruction.  This is redundant with movm_args, but we       by the movm instruction.  This is redundant with movm_args, but we
77       add it to the hash table to avoid computing it over and over.  */       add it to the hash table to avoid computing it over and over.  */
78    unsigned char movm_stack_size;    unsigned char movm_stack_size;
# Line 104  struct elf32_mn10300_link_hash_table { Line 114  struct elf32_mn10300_link_hash_table {
114  #define elf32_mn10300_link_hash_traverse(table, func, info)             \  #define elf32_mn10300_link_hash_traverse(table, func, info)             \
115    (elf_link_hash_traverse                                               \    (elf_link_hash_traverse                                               \
116     (&(table)->root,                                                     \     (&(table)->root,                                                     \
117      (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func),  \      (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
118      (info)))      (info)))
119    
120  static struct bfd_hash_entry *elf32_mn10300_link_hash_newfunc  static struct bfd_hash_entry *elf32_mn10300_link_hash_newfunc
# Line 117  static void elf32_mn10300_link_hash_tabl Line 127  static void elf32_mn10300_link_hash_tabl
127  static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup  static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
128    PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));    PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
129  static void mn10300_info_to_howto  static void mn10300_info_to_howto
130    PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));    PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
131  static boolean mn10300_elf_check_relocs  static bfd_boolean mn10300_elf_check_relocs
132    PARAMS ((bfd *, struct bfd_link_info *, asection *,    PARAMS ((bfd *, struct bfd_link_info *, asection *,
133             const Elf_Internal_Rela *));             const Elf_Internal_Rela *));
134  static asection *mn10300_elf_gc_mark_hook  static asection *mn10300_elf_gc_mark_hook
135    PARAMS ((asection *, struct bfd_link_info *info, Elf_Internal_Rela *,    PARAMS ((asection *, struct bfd_link_info *info, Elf_Internal_Rela *,
136             struct elf_link_hash_entry *, Elf_Internal_Sym *));             struct elf_link_hash_entry *, Elf_Internal_Sym *));
137  static boolean mn10300_elf_relax_delete_bytes  static bfd_boolean mn10300_elf_relax_delete_bytes
138    PARAMS ((bfd *, asection *, bfd_vma, int));    PARAMS ((bfd *, asection *, bfd_vma, int));
139  static boolean mn10300_elf_symbol_address_p  static bfd_boolean mn10300_elf_symbol_address_p
140  PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));    PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
141  static boolean elf32_mn10300_finish_hash_table_entry  static bfd_boolean elf32_mn10300_finish_hash_table_entry
142    PARAMS ((struct bfd_hash_entry *, PTR));    PARAMS ((struct bfd_hash_entry *, PTR));
143  static void compute_function_info  static void compute_function_info
144    PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *,    PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *,
145             bfd_vma, unsigned char *));             bfd_vma, unsigned char *));
146    
147  /* We have to use RELA instructions since md_apply_fix3 in the assembler  static bfd_boolean _bfd_mn10300_elf_create_got_section
148     does absolutely nothing.  */    PARAMS ((bfd *, struct bfd_link_info *));
149  #define USE_RELA  static bfd_boolean _bfd_mn10300_elf_create_dynamic_sections
150      PARAMS ((bfd *, struct bfd_link_info *));
151    static bfd_boolean _bfd_mn10300_elf_adjust_dynamic_symbol
152      PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
153    static bfd_boolean _bfd_mn10300_elf_size_dynamic_sections
154      PARAMS ((bfd *, struct bfd_link_info *));
155    static bfd_boolean _bfd_mn10300_elf_finish_dynamic_symbol
156      PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
157               Elf_Internal_Sym *));
158    static bfd_boolean _bfd_mn10300_elf_finish_dynamic_sections
159      PARAMS ((bfd *, struct bfd_link_info *));
160    
161  static reloc_howto_type elf_mn10300_howto_table[] = {  static reloc_howto_type elf_mn10300_howto_table[] = {
162    /* Dummy relocation.  Does nothing.  */    /* Dummy relocation.  Does nothing.  */
# Line 144  static reloc_howto_type elf_mn10300_howt Line 164  static reloc_howto_type elf_mn10300_howt
164           0,           0,
165           2,           2,
166           16,           16,
167           false,           FALSE,
168           0,           0,
169           complain_overflow_bitfield,           complain_overflow_bitfield,
170           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
171           "R_MN10300_NONE",           "R_MN10300_NONE",
172           false,           FALSE,
173           0,           0,
174           0,           0,
175           false),           FALSE),
176    /* Standard 32 bit reloc.  */    /* Standard 32 bit reloc.  */
177    HOWTO (R_MN10300_32,    HOWTO (R_MN10300_32,
178           0,           0,
179           2,           2,
180           32,           32,
181           false,           FALSE,
182           0,           0,
183           complain_overflow_bitfield,           complain_overflow_bitfield,
184           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
185           "R_MN10300_32",           "R_MN10300_32",
186           false,           FALSE,
187           0xffffffff,           0xffffffff,
188           0xffffffff,           0xffffffff,
189           false),           FALSE),
190    /* Standard 16 bit reloc.  */    /* Standard 16 bit reloc.  */
191    HOWTO (R_MN10300_16,    HOWTO (R_MN10300_16,
192           0,           0,
193           1,           1,
194           16,           16,
195           false,           FALSE,
196           0,           0,
197           complain_overflow_bitfield,           complain_overflow_bitfield,
198           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
199           "R_MN10300_16",           "R_MN10300_16",
200           false,           FALSE,
201           0xffff,           0xffff,
202           0xffff,           0xffff,
203           false),           FALSE),
204    /* Standard 8 bit reloc.  */    /* Standard 8 bit reloc.  */
205    HOWTO (R_MN10300_8,    HOWTO (R_MN10300_8,
206           0,           0,
207           0,           0,
208           8,           8,
209           false,           FALSE,
210           0,           0,
211           complain_overflow_bitfield,           complain_overflow_bitfield,
212           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
213           "R_MN10300_8",           "R_MN10300_8",
214           false,           FALSE,
215           0xff,           0xff,
216           0xff,           0xff,
217           false),           FALSE),
218    /* Standard 32bit pc-relative reloc.  */    /* Standard 32bit pc-relative reloc.  */
219    HOWTO (R_MN10300_PCREL32,    HOWTO (R_MN10300_PCREL32,
220           0,           0,
221           2,           2,
222           32,           32,
223           true,           TRUE,
224           0,           0,
225           complain_overflow_bitfield,           complain_overflow_bitfield,
226           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
227           "R_MN10300_PCREL32",           "R_MN10300_PCREL32",
228           false,           FALSE,
229           0xffffffff,           0xffffffff,
230           0xffffffff,           0xffffffff,
231           true),           TRUE),
232    /* Standard 16bit pc-relative reloc.  */    /* Standard 16bit pc-relative reloc.  */
233    HOWTO (R_MN10300_PCREL16,    HOWTO (R_MN10300_PCREL16,
234           0,           0,
235           1,           1,
236           16,           16,
237           true,           TRUE,
238           0,           0,
239           complain_overflow_bitfield,           complain_overflow_bitfield,
240           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
241           "R_MN10300_PCREL16",           "R_MN10300_PCREL16",
242           false,           FALSE,
243           0xffff,           0xffff,
244           0xffff,           0xffff,
245           true),           TRUE),
246    /* Standard 8 pc-relative reloc.  */    /* Standard 8 pc-relative reloc.  */
247    HOWTO (R_MN10300_PCREL8,    HOWTO (R_MN10300_PCREL8,
248           0,           0,
249           0,           0,
250           8,           8,
251           true,           TRUE,
252           0,           0,
253           complain_overflow_bitfield,           complain_overflow_bitfield,
254           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
255           "R_MN10300_PCREL8",           "R_MN10300_PCREL8",
256           false,           FALSE,
257           0xff,           0xff,
258           0xff,           0xff,
259           true),           TRUE),
260    
261    /* GNU extension to record C++ vtable hierarchy */    /* GNU extension to record C++ vtable hierarchy */
262    HOWTO (R_MN10300_GNU_VTINHERIT, /* type */    HOWTO (R_MN10300_GNU_VTINHERIT, /* type */
263           0,                     /* rightshift */           0,                     /* rightshift */
264           0,                     /* size (0 = byte, 1 = short, 2 = long) */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
265           0,                     /* bitsize */           0,                     /* bitsize */
266           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
267           0,                     /* bitpos */           0,                     /* bitpos */
268           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
269           NULL,                  /* special_function */           NULL,                  /* special_function */
270           "R_MN10300_GNU_VTINHERIT", /* name */           "R_MN10300_GNU_VTINHERIT", /* name */
271           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
272           0,                     /* src_mask */           0,                     /* src_mask */
273           0,                     /* dst_mask */           0,                     /* dst_mask */
274           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
275    
276    /* GNU extension to record C++ vtable member usage */    /* GNU extension to record C++ vtable member usage */
277    HOWTO (R_MN10300_GNU_VTENTRY, /* type */    HOWTO (R_MN10300_GNU_VTENTRY, /* type */
278           0,                     /* rightshift */           0,                     /* rightshift */
279           0,                     /* size (0 = byte, 1 = short, 2 = long) */           0,                     /* size (0 = byte, 1 = short, 2 = long) */
280           0,                     /* bitsize */           0,                     /* bitsize */
281           false,                 /* pc_relative */           FALSE,                 /* pc_relative */
282           0,                     /* bitpos */           0,                     /* bitpos */
283           complain_overflow_dont, /* complain_on_overflow */           complain_overflow_dont, /* complain_on_overflow */
284           NULL,                  /* special_function */           NULL,                  /* special_function */
285           "R_MN10300_GNU_VTENTRY", /* name */           "R_MN10300_GNU_VTENTRY", /* name */
286           false,                 /* partial_inplace */           FALSE,                 /* partial_inplace */
287           0,                     /* src_mask */           0,                     /* src_mask */
288           0,                     /* dst_mask */           0,                     /* dst_mask */
289           false),                /* pcrel_offset */           FALSE),                /* pcrel_offset */
290    
291    /* Standard 24 bit reloc.  */    /* Standard 24 bit reloc.  */
292    HOWTO (R_MN10300_24,    HOWTO (R_MN10300_24,
293           0,           0,
294           2,           2,
295           24,           24,
296           false,           FALSE,
297           0,           0,
298           complain_overflow_bitfield,           complain_overflow_bitfield,
299           bfd_elf_generic_reloc,           bfd_elf_generic_reloc,
300           "R_MN10300_24",           "R_MN10300_24",
301           false,           FALSE,
302           0xffffff,           0xffffff,
303           0xffffff,           0xffffff,
304           false),           FALSE),
305      HOWTO (R_MN10300_GOTPC32,     /* type */
306             0,                     /* rightshift */
307             2,                     /* size (0 = byte, 1 = short, 2 = long) */
308             32,                    /* bitsize */
309             TRUE,                  /* pc_relative */
310             0,                     /* bitpos */
311             complain_overflow_bitfield, /* complain_on_overflow */
312             bfd_elf_generic_reloc, /* */
313             "R_MN10300_GOTPC32",   /* name */
314             FALSE,                 /* partial_inplace */
315             0xffffffff,            /* src_mask */
316             0xffffffff,            /* dst_mask */
317             TRUE),                 /* pcrel_offset */
318    
319      HOWTO (R_MN10300_GOTPC16,     /* type */
320             0,                     /* rightshift */
321             1,                     /* size (0 = byte, 1 = short, 2 = long) */
322             16,                    /* bitsize */
323             TRUE,                  /* pc_relative */
324             0,                     /* bitpos */
325             complain_overflow_bitfield, /* complain_on_overflow */
326             bfd_elf_generic_reloc, /* */
327             "R_MN10300_GOTPC16",   /* name */
328             FALSE,                 /* partial_inplace */
329             0xffff,                /* src_mask */
330             0xffff,                /* dst_mask */
331             TRUE),                 /* pcrel_offset */
332    
333      HOWTO (R_MN10300_GOTOFF32,    /* type */
334             0,                     /* rightshift */
335             2,                     /* size (0 = byte, 1 = short, 2 = long) */
336             32,                    /* bitsize */
337             FALSE,                 /* pc_relative */
338             0,                     /* bitpos */
339             complain_overflow_bitfield, /* complain_on_overflow */
340             bfd_elf_generic_reloc, /* */
341             "R_MN10300_GOTOFF32",  /* name */
342             FALSE,                 /* partial_inplace */
343             0xffffffff,            /* src_mask */
344             0xffffffff,            /* dst_mask */
345             FALSE),                /* pcrel_offset */
346    
347      HOWTO (R_MN10300_GOTOFF24,    /* type */
348             0,                     /* rightshift */
349             2,                     /* size (0 = byte, 1 = short, 2 = long) */
350             24,                    /* bitsize */
351             FALSE,                 /* pc_relative */
352             0,                     /* bitpos */
353             complain_overflow_bitfield, /* complain_on_overflow */
354             bfd_elf_generic_reloc, /* */
355             "R_MN10300_GOTOFF24",  /* name */
356             FALSE,                 /* partial_inplace */
357             0xffffff,              /* src_mask */
358             0xffffff,              /* dst_mask */
359             FALSE),                /* pcrel_offset */
360    
361      HOWTO (R_MN10300_GOTOFF16,    /* type */
362             0,                     /* rightshift */
363             1,                     /* size (0 = byte, 1 = short, 2 = long) */
364             16,                    /* bitsize */
365             FALSE,                 /* pc_relative */
366             0,                     /* bitpos */
367             complain_overflow_bitfield, /* complain_on_overflow */
368             bfd_elf_generic_reloc, /* */
369             "R_MN10300_GOTOFF16",  /* name */
370             FALSE,                 /* partial_inplace */
371             0xffff,                /* src_mask */
372             0xffff,                /* dst_mask */
373             FALSE),                /* pcrel_offset */
374    
375      HOWTO (R_MN10300_PLT32,       /* type */
376             0,                     /* rightshift */
377             2,                     /* size (0 = byte, 1 = short, 2 = long) */
378             32,                    /* bitsize */
379             TRUE,                  /* pc_relative */
380             0,                     /* bitpos */
381             complain_overflow_bitfield, /* complain_on_overflow */
382             bfd_elf_generic_reloc, /* */
383             "R_MN10300_PLT32",     /* name */
384             FALSE,                 /* partial_inplace */
385             0xffffffff,            /* src_mask */
386             0xffffffff,            /* dst_mask */
387             TRUE),                 /* pcrel_offset */
388    
389      HOWTO (R_MN10300_PLT16,       /* type */
390             0,                     /* rightshift */
391             1,                     /* size (0 = byte, 1 = short, 2 = long) */
392             16,                    /* bitsize */
393             TRUE,                  /* pc_relative */
394             0,                     /* bitpos */
395             complain_overflow_bitfield, /* complain_on_overflow */
396             bfd_elf_generic_reloc, /* */
397             "R_MN10300_PLT16",     /* name */
398             FALSE,                 /* partial_inplace */
399             0xffff,                /* src_mask */
400             0xffff,                /* dst_mask */
401             TRUE),                 /* pcrel_offset */
402    
403      HOWTO (R_MN10300_GOT32,       /* type */
404             0,                     /* rightshift */
405             2,                     /* size (0 = byte, 1 = short, 2 = long) */
406             32,                    /* bitsize */
407             FALSE,                 /* pc_relative */
408             0,                     /* bitpos */
409             complain_overflow_bitfield, /* complain_on_overflow */
410             bfd_elf_generic_reloc, /* */
411             "R_MN10300_GOT32",     /* name */
412             FALSE,                 /* partial_inplace */
413             0xffffffff,            /* src_mask */
414             0xffffffff,            /* dst_mask */
415             FALSE),                /* pcrel_offset */
416    
417      HOWTO (R_MN10300_GOT24,       /* type */
418             0,                     /* rightshift */
419             2,                     /* size (0 = byte, 1 = short, 2 = long) */
420             24,                    /* bitsize */
421             FALSE,                 /* pc_relative */
422             0,                     /* bitpos */
423             complain_overflow_bitfield, /* complain_on_overflow */
424             bfd_elf_generic_reloc, /* */
425             "R_MN10300_GOT24",     /* name */
426             FALSE,                 /* partial_inplace */
427             0xffffffff,            /* src_mask */
428             0xffffffff,            /* dst_mask */
429             FALSE),                /* pcrel_offset */
430    
431      HOWTO (R_MN10300_GOT16,       /* type */
432             0,                     /* rightshift */
433             1,                     /* size (0 = byte, 1 = short, 2 = long) */
434             16,                    /* bitsize */
435             FALSE,                 /* pc_relative */
436             0,                     /* bitpos */
437             complain_overflow_bitfield, /* complain_on_overflow */
438             bfd_elf_generic_reloc, /* */
439             "R_MN10300_GOT16",     /* name */
440             FALSE,                 /* partial_inplace */
441             0xffffffff,            /* src_mask */
442             0xffffffff,            /* dst_mask */
443             FALSE),                /* pcrel_offset */
444    
445      HOWTO (R_MN10300_COPY,        /* type */
446             0,                     /* rightshift */
447             2,                     /* size (0 = byte, 1 = short, 2 = long) */
448             32,                    /* bitsize */
449             FALSE,                 /* pc_relative */
450             0,                     /* bitpos */
451             complain_overflow_bitfield, /* complain_on_overflow */
452             bfd_elf_generic_reloc, /* */
453             "R_MN10300_COPY",              /* name */
454             FALSE,                 /* partial_inplace */
455             0xffffffff,            /* src_mask */
456             0xffffffff,            /* dst_mask */
457             FALSE),                /* pcrel_offset */
458    
459      HOWTO (R_MN10300_GLOB_DAT,    /* type */
460             0,                     /* rightshift */
461             2,                     /* size (0 = byte, 1 = short, 2 = long) */
462             32,                    /* bitsize */
463             FALSE,                 /* pc_relative */
464             0,                     /* bitpos */
465             complain_overflow_bitfield, /* complain_on_overflow */
466             bfd_elf_generic_reloc, /* */
467             "R_MN10300_GLOB_DAT",  /* name */
468             FALSE,                 /* partial_inplace */
469             0xffffffff,            /* src_mask */
470             0xffffffff,            /* dst_mask */
471             FALSE),                /* pcrel_offset */
472    
473      HOWTO (R_MN10300_JMP_SLOT,    /* type */
474             0,                     /* rightshift */
475             2,                     /* size (0 = byte, 1 = short, 2 = long) */
476             32,                    /* bitsize */
477             FALSE,                 /* pc_relative */
478             0,                     /* bitpos */
479             complain_overflow_bitfield, /* complain_on_overflow */
480             bfd_elf_generic_reloc, /* */
481             "R_MN10300_JMP_SLOT",  /* name */
482             FALSE,                 /* partial_inplace */
483             0xffffffff,            /* src_mask */
484             0xffffffff,            /* dst_mask */
485             FALSE),                /* pcrel_offset */
486    
487      HOWTO (R_MN10300_RELATIVE,    /* type */
488             0,                     /* rightshift */
489             2,                     /* size (0 = byte, 1 = short, 2 = long) */
490             32,                    /* bitsize */
491             FALSE,                 /* pc_relative */
492             0,                     /* bitpos */
493             complain_overflow_bitfield, /* complain_on_overflow */
494             bfd_elf_generic_reloc, /* */
495             "R_MN10300_RELATIVE",  /* name */
496             FALSE,                 /* partial_inplace */
497             0xffffffff,            /* src_mask */
498             0xffffffff,            /* dst_mask */
499             FALSE),                /* pcrel_offset */
500    
501  };  };
502    
503  struct mn10300_reloc_map {  struct mn10300_reloc_map {
# Line 300  static const struct mn10300_reloc_map mn Line 516  static const struct mn10300_reloc_map mn
516    { BFD_RELOC_24, R_MN10300_24, },    { BFD_RELOC_24, R_MN10300_24, },
517    { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },    { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },
518    { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },    { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },
519      { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 },
520      { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 },
521      { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 },
522      { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 },
523      { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 },
524      { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 },
525      { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 },
526      { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 },
527      { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 },
528      { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 },
529      { BFD_RELOC_MN10300_COPY, R_MN10300_COPY },
530      { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT },
531      { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT },
532      { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE },
533  };  };
534    
535    /* Create the GOT section.  */
536    
537    static bfd_boolean
538    _bfd_mn10300_elf_create_got_section (abfd, info)
539         bfd * abfd;
540         struct bfd_link_info * info;
541    {
542      flagword   flags;
543      flagword   pltflags;
544      asection * s;
545      struct bfd_link_hash_entry * bh;
546      struct elf_link_hash_entry * h;
547      const struct elf_backend_data * bed = get_elf_backend_data (abfd);
548      int ptralign;
549    
550      /* This function may be called more than once.  */
551      if (bfd_get_section_by_name (abfd, ".got") != NULL)
552        return TRUE;
553    
554      switch (bed->s->arch_size)
555        {
556        case 32:
557          ptralign = 2;
558          break;
559    
560        case 64:
561          ptralign = 3;
562          break;
563    
564        default:
565          bfd_set_error (bfd_error_bad_value);
566          return FALSE;
567        }
568    
569      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
570               | SEC_LINKER_CREATED);
571    
572      pltflags = flags;
573      pltflags |= SEC_CODE;
574      if (bed->plt_not_loaded)
575        pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
576      if (bed->plt_readonly)
577        pltflags |= SEC_READONLY;
578    
579      s = bfd_make_section (abfd, ".plt");
580      if (s == NULL
581          || ! bfd_set_section_flags (abfd, s, pltflags)
582          || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
583        return FALSE;
584    
585      if (bed->want_plt_sym)
586        {
587          /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
588             .plt section.  */
589          bh = NULL;
590          if (! (_bfd_generic_link_add_one_symbol
591                 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
592                  (bfd_vma) 0, (const char *) NULL, FALSE,
593                  get_elf_backend_data (abfd)->collect, &bh)))
594            return FALSE;
595          h = (struct elf_link_hash_entry *) bh;
596          h->def_regular = 1;
597          h->type = STT_OBJECT;
598    
599          if (info->shared
600              && ! bfd_elf_link_record_dynamic_symbol (info, h))
601            return FALSE;
602        }
603    
604      s = bfd_make_section (abfd, ".got");
605      if (s == NULL
606          || ! bfd_set_section_flags (abfd, s, flags)
607          || ! bfd_set_section_alignment (abfd, s, ptralign))
608        return FALSE;
609    
610      if (bed->want_got_plt)
611        {
612          s = bfd_make_section (abfd, ".got.plt");
613          if (s == NULL
614              || ! bfd_set_section_flags (abfd, s, flags)
615              || ! bfd_set_section_alignment (abfd, s, ptralign))
616            return FALSE;
617        }
618    
619      /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
620         (or .got.plt) section.  We don't do this in the linker script
621         because we don't want to define the symbol if we are not creating
622         a global offset table.  */
623      bh = NULL;
624      if (!(_bfd_generic_link_add_one_symbol
625            (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
626             bed->got_symbol_offset, (const char *) NULL, FALSE,
627             bed->collect, &bh)))
628        return FALSE;
629      h = (struct elf_link_hash_entry *) bh;
630      h->def_regular = 1;
631      h->type = STT_OBJECT;
632    
633      if (info->shared
634          && ! bfd_elf_link_record_dynamic_symbol (info, h))
635        return FALSE;
636    
637      elf_hash_table (info)->hgot = h;
638    
639      /* The first bit of the global offset table is the header.  */
640      s->size += bed->got_header_size + bed->got_symbol_offset;
641    
642      return TRUE;
643    }
644    
645  static reloc_howto_type *  static reloc_howto_type *
646  bfd_elf32_bfd_reloc_type_lookup (abfd, code)  bfd_elf32_bfd_reloc_type_lookup (abfd, code)
647       bfd *abfd ATTRIBUTE_UNUSED;       bfd *abfd ATTRIBUTE_UNUSED;
# Line 326  static void Line 666  static void
666  mn10300_info_to_howto (abfd, cache_ptr, dst)  mn10300_info_to_howto (abfd, cache_ptr, dst)
667       bfd *abfd ATTRIBUTE_UNUSED;       bfd *abfd ATTRIBUTE_UNUSED;
668       arelent *cache_ptr;       arelent *cache_ptr;
669       Elf32_Internal_Rela *dst;       Elf_Internal_Rela *dst;
670  {  {
671    unsigned int r_type;    unsigned int r_type;
672    
# Line 339  mn10300_info_to_howto (abfd, cache_ptr, Line 679  mn10300_info_to_howto (abfd, cache_ptr,
679     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
680     virtual table relocs for gc.  */     virtual table relocs for gc.  */
681    
682  static boolean  static bfd_boolean
683  mn10300_elf_check_relocs (abfd, info, sec, relocs)  mn10300_elf_check_relocs (abfd, info, sec, relocs)
684       bfd *abfd;       bfd *abfd;
685       struct bfd_link_info *info;       struct bfd_link_info *info;
# Line 350  mn10300_elf_check_relocs (abfd, info, se Line 690  mn10300_elf_check_relocs (abfd, info, se
690    struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;    struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
691    const Elf_Internal_Rela *rel;    const Elf_Internal_Rela *rel;
692    const Elf_Internal_Rela *rel_end;    const Elf_Internal_Rela *rel_end;
693      bfd *      dynobj;
694      bfd_vma *  local_got_offsets;
695      asection * sgot;
696      asection * srelgot;
697      asection * sreloc;
698    
699      sgot    = NULL;
700      srelgot = NULL;
701      sreloc  = NULL;
702    
703    if (info->relocateable)    if (info->relocatable)
704      return true;      return TRUE;
705    
706    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
707    sym_hashes = elf_sym_hashes (abfd);    sym_hashes = elf_sym_hashes (abfd);
# Line 360  mn10300_elf_check_relocs (abfd, info, se Line 709  mn10300_elf_check_relocs (abfd, info, se
709    if (!elf_bad_symtab (abfd))    if (!elf_bad_symtab (abfd))
710      sym_hashes_end -= symtab_hdr->sh_info;      sym_hashes_end -= symtab_hdr->sh_info;
711    
712      dynobj = elf_hash_table (info)->dynobj;
713      local_got_offsets = elf_local_got_offsets (abfd);
714    rel_end = relocs + sec->reloc_count;    rel_end = relocs + sec->reloc_count;
715    for (rel = relocs; rel < rel_end; rel++)    for (rel = relocs; rel < rel_end; rel++)
716      {      {
# Line 372  mn10300_elf_check_relocs (abfd, info, se Line 723  mn10300_elf_check_relocs (abfd, info, se
723        else        else
724          h = sym_hashes[r_symndx - symtab_hdr->sh_info];          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
725    
726          /* Some relocs require a global offset table.  */
727          if (dynobj == NULL)
728            {
729              switch (ELF32_R_TYPE (rel->r_info))
730                {
731                case R_MN10300_GOT32:
732                case R_MN10300_GOT24:
733                case R_MN10300_GOT16:
734                case R_MN10300_GOTOFF32:
735                case R_MN10300_GOTOFF24:
736                case R_MN10300_GOTOFF16:
737                case R_MN10300_GOTPC32:
738                case R_MN10300_GOTPC16:
739                  elf_hash_table (info)->dynobj = dynobj = abfd;
740                  if (! _bfd_mn10300_elf_create_got_section (dynobj, info))
741                    return FALSE;
742                  break;
743    
744                default:
745                  break;
746                }
747            }
748    
749        switch (ELF32_R_TYPE (rel->r_info))        switch (ELF32_R_TYPE (rel->r_info))
750          {          {
751          /* This relocation describes the C++ object vtable hierarchy.          /* This relocation describes the C++ object vtable hierarchy.
752             Reconstruct it for later use during GC.  */             Reconstruct it for later use during GC.  */
753          case R_MN10300_GNU_VTINHERIT:          case R_MN10300_GNU_VTINHERIT:
754            if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))            if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
755              return false;              return FALSE;
756            break;            break;
757    
758          /* This relocation describes which C++ vtable entries are actually          /* This relocation describes which C++ vtable entries are actually
759             used.  Record for later use during GC.  */             used.  Record for later use during GC.  */
760          case R_MN10300_GNU_VTENTRY:          case R_MN10300_GNU_VTENTRY:
761            if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))            if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
762              return false;              return FALSE;
763              break;
764            case R_MN10300_GOT32:
765            case R_MN10300_GOT24:
766            case R_MN10300_GOT16:
767              /* This symbol requires a global offset table entry.  */
768    
769              if (sgot == NULL)
770                {
771                  sgot = bfd_get_section_by_name (dynobj, ".got");
772                  BFD_ASSERT (sgot != NULL);
773                }
774    
775              if (srelgot == NULL
776                  && (h != NULL || info->shared))
777                {
778                  srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
779                  if (srelgot == NULL)
780                    {
781                      srelgot = bfd_make_section (dynobj, ".rela.got");
782                      if (srelgot == NULL
783                          || ! bfd_set_section_flags (dynobj, srelgot,
784                                                      (SEC_ALLOC
785                                                       | SEC_LOAD
786                                                       | SEC_HAS_CONTENTS
787                                                       | SEC_IN_MEMORY
788                                                       | SEC_LINKER_CREATED
789                                                       | SEC_READONLY))
790                          || ! bfd_set_section_alignment (dynobj, srelgot, 2))
791                        return FALSE;
792                    }
793                }
794    
795              if (h != NULL)
796                {
797                  if (h->got.offset != (bfd_vma) -1)
798                    /* We have already allocated space in the .got.  */
799                    break;
800    
801                  h->got.offset = sgot->size;
802    
803                  /* Make sure this symbol is output as a dynamic symbol.  */
804                  if (h->dynindx == -1)
805                    {
806                      if (! bfd_elf_link_record_dynamic_symbol (info, h))
807                        return FALSE;
808                    }
809    
810                  srelgot->size += sizeof (Elf32_External_Rela);
811                }
812              else
813                {
814                  /* This is a global offset table entry for a local
815                     symbol.  */
816                  if (local_got_offsets == NULL)
817                    {
818                      size_t       size;
819                      unsigned int i;
820    
821                      size = symtab_hdr->sh_info * sizeof (bfd_vma);
822                      local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
823    
824                      if (local_got_offsets == NULL)
825                        return FALSE;
826                      elf_local_got_offsets (abfd) = local_got_offsets;
827    
828                      for (i = 0; i < symtab_hdr->sh_info; i++)
829                        local_got_offsets[i] = (bfd_vma) -1;
830                    }
831    
832                  if (local_got_offsets[r_symndx] != (bfd_vma) -1)
833                    /* We have already allocated space in the .got.  */
834                    break;
835    
836                  local_got_offsets[r_symndx] = sgot->size;
837    
838                  if (info->shared)
839                    /* If we are generating a shared object, we need to
840                       output a R_MN10300_RELATIVE reloc so that the dynamic
841                       linker can adjust this GOT entry.  */
842                    srelgot->size += sizeof (Elf32_External_Rela);
843                }
844    
845              sgot->size += 4;
846    
847              break;
848    
849            case R_MN10300_PLT32:
850            case R_MN10300_PLT16:
851              /* This symbol requires a procedure linkage table entry.  We
852                 actually build the entry in adjust_dynamic_symbol,
853                 because this might be a case of linking PIC code which is
854                 never referenced by a dynamic object, in which case we
855                 don't need to generate a procedure linkage table entry
856                 after all.  */
857    
858              /* If this is a local symbol, we resolve it directly without
859                 creating a procedure linkage table entry.  */
860              if (h == NULL)
861                continue;
862    
863              if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
864                  || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
865                break;
866    
867              h->needs_plt = 1;
868    
869              break;
870    
871            case R_MN10300_24:
872            case R_MN10300_16:
873            case R_MN10300_8:
874            case R_MN10300_PCREL32:
875            case R_MN10300_PCREL16:
876            case R_MN10300_PCREL8:
877              if (h != NULL)
878                h->non_got_ref = 1;
879              break;
880    
881            case R_MN10300_32:
882              if (h != NULL)
883                h->non_got_ref = 1;
884    
885              /* If we are creating a shared library, then we need to copy
886                 the reloc into the shared library.  */
887              if (info->shared
888                  && (sec->flags & SEC_ALLOC) != 0)
889                {
890                  /* When creating a shared object, we must copy these
891                     reloc types into the output file.  We create a reloc
892                     section in dynobj and make room for this reloc.  */
893                  if (sreloc == NULL)
894                    {
895                      const char * name;
896    
897                      name = (bfd_elf_string_from_elf_section
898                              (abfd,
899                               elf_elfheader (abfd)->e_shstrndx,
900                               elf_section_data (sec)->rel_hdr.sh_name));
901                      if (name == NULL)
902                        return FALSE;
903    
904                      BFD_ASSERT (strncmp (name, ".rela", 5) == 0
905                                  && strcmp (bfd_get_section_name (abfd, sec),
906                                             name + 5) == 0);
907    
908                      sreloc = bfd_get_section_by_name (dynobj, name);
909                      if (sreloc == NULL)
910                        {
911                          flagword flags;
912    
913                          sreloc = bfd_make_section (dynobj, name);
914                          flags = (SEC_HAS_CONTENTS | SEC_READONLY
915                                   | SEC_IN_MEMORY | SEC_LINKER_CREATED);
916                          if ((sec->flags & SEC_ALLOC) != 0)
917                            flags |= SEC_ALLOC | SEC_LOAD;
918                          if (sreloc == NULL
919                              || ! bfd_set_section_flags (dynobj, sreloc, flags)
920                              || ! bfd_set_section_alignment (dynobj, sreloc, 2))
921                            return FALSE;
922                        }
923                    }
924    
925                  sreloc->size += sizeof (Elf32_External_Rela);
926                }
927    
928            break;            break;
929          }          }
930      }      }
931    
932    return true;    return TRUE;
933  }  }
934    
935  /* Return the section that should be marked against GC for a given  /* Return the section that should be marked against GC for a given
# Line 437  mn10300_elf_gc_mark_hook (sec, info, rel Line 976  mn10300_elf_gc_mark_hook (sec, info, rel
976  static bfd_reloc_status_type  static bfd_reloc_status_type
977  mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,  mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
978                                   input_section, contents, offset, value,                                   input_section, contents, offset, value,
979                                   addend, info, sym_sec, is_local)                                   addend, h, symndx, info, sym_sec, is_local)
980       reloc_howto_type *howto;       reloc_howto_type *howto;
981       bfd *input_bfd;       bfd *input_bfd;
982       bfd *output_bfd ATTRIBUTE_UNUSED;       bfd *output_bfd ATTRIBUTE_UNUSED;
# Line 446  mn10300_elf_final_link_relocate (howto, Line 985  mn10300_elf_final_link_relocate (howto,
985       bfd_vma offset;       bfd_vma offset;
986       bfd_vma value;       bfd_vma value;
987       bfd_vma addend;       bfd_vma addend;
988       struct bfd_link_info *info ATTRIBUTE_UNUSED;       struct elf_link_hash_entry * h;
989         unsigned long symndx;
990         struct bfd_link_info *info;
991       asection *sym_sec ATTRIBUTE_UNUSED;       asection *sym_sec ATTRIBUTE_UNUSED;
992       int is_local ATTRIBUTE_UNUSED;       int is_local ATTRIBUTE_UNUSED;
993  {  {
994    unsigned long r_type = howto->type;    unsigned long r_type = howto->type;
995    bfd_byte *hit_data = contents + offset;    bfd_byte *hit_data = contents + offset;
996      bfd *      dynobj;
997      bfd_vma *  local_got_offsets;
998      asection * sgot;
999      asection * splt;
1000      asection * sreloc;
1001    
1002      dynobj = elf_hash_table (info)->dynobj;
1003      local_got_offsets = elf_local_got_offsets (input_bfd);
1004    
1005      sgot   = NULL;
1006      splt   = NULL;
1007      sreloc = NULL;
1008    
1009      switch (r_type)
1010        {
1011        case R_MN10300_24:
1012        case R_MN10300_16:
1013        case R_MN10300_8:
1014        case R_MN10300_PCREL8:
1015        case R_MN10300_PCREL16:
1016        case R_MN10300_PCREL32:
1017        case R_MN10300_GOTOFF32:
1018        case R_MN10300_GOTOFF24:
1019        case R_MN10300_GOTOFF16:
1020          if (info->shared
1021              && (input_section->flags & SEC_ALLOC) != 0
1022              && h != NULL
1023              && ! SYMBOL_REFERENCES_LOCAL (info, h))
1024            return bfd_reloc_dangerous;
1025        }
1026    
1027    switch (r_type)    switch (r_type)
1028      {      {
# Line 459  mn10300_elf_final_link_relocate (howto, Line 1030  mn10300_elf_final_link_relocate (howto,
1030        return bfd_reloc_ok;        return bfd_reloc_ok;
1031    
1032      case R_MN10300_32:      case R_MN10300_32:
1033          if (info->shared
1034              && (input_section->flags & SEC_ALLOC) != 0)
1035            {
1036              Elf_Internal_Rela outrel;
1037              bfd_boolean skip, relocate;
1038    
1039              /* When generating a shared object, these relocations are
1040                 copied into the output file to be resolved at run
1041                 time.  */
1042              if (sreloc == NULL)
1043                {
1044                  const char * name;
1045    
1046                  name = (bfd_elf_string_from_elf_section
1047                          (input_bfd,
1048                           elf_elfheader (input_bfd)->e_shstrndx,
1049                           elf_section_data (input_section)->rel_hdr.sh_name));
1050                  if (name == NULL)
1051                    return FALSE;
1052    
1053                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1054                              && strcmp (bfd_get_section_name (input_bfd,
1055                                                               input_section),
1056                                         name + 5) == 0);
1057    
1058                  sreloc = bfd_get_section_by_name (dynobj, name);
1059                  BFD_ASSERT (sreloc != NULL);
1060                }
1061    
1062              skip = FALSE;
1063    
1064              outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
1065                                                         input_section, offset);
1066              if (outrel.r_offset == (bfd_vma) -1)
1067                skip = TRUE;
1068    
1069              outrel.r_offset += (input_section->output_section->vma
1070                                  + input_section->output_offset);
1071    
1072              if (skip)
1073                {
1074                  memset (&outrel, 0, sizeof outrel);
1075                  relocate = FALSE;
1076                }
1077              else
1078                {
1079                  /* h->dynindx may be -1 if this symbol was marked to
1080                     become local.  */
1081                  if (h == NULL
1082                      || SYMBOL_REFERENCES_LOCAL (info, h))
1083                    {
1084                      relocate = TRUE;
1085                      outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1086                      outrel.r_addend = value + addend;
1087                    }
1088                  else
1089                    {
1090                      BFD_ASSERT (h->dynindx != -1);
1091                      relocate = FALSE;
1092                      outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32);
1093                      outrel.r_addend = value + addend;
1094                    }
1095                }
1096    
1097              bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1098                                         (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
1099                                                       + sreloc->reloc_count));
1100              ++sreloc->reloc_count;
1101    
1102              /* If this reloc is against an external symbol, we do
1103                 not want to fiddle with the addend.  Otherwise, we
1104                 need to include the symbol value so that it becomes
1105                 an addend for the dynamic reloc.  */
1106              if (! relocate)
1107                return bfd_reloc_ok;
1108            }
1109        value += addend;        value += addend;
1110        bfd_put_32 (input_bfd, value, hit_data);        bfd_put_32 (input_bfd, value, hit_data);
1111        return bfd_reloc_ok;        return bfd_reloc_ok;
# Line 529  mn10300_elf_final_link_relocate (howto, Line 1176  mn10300_elf_final_link_relocate (howto,
1176      case R_MN10300_GNU_VTENTRY:      case R_MN10300_GNU_VTENTRY:
1177        return bfd_reloc_ok;        return bfd_reloc_ok;
1178    
1179        case R_MN10300_GOTPC32:
1180          /* Use global offset table as symbol value.  */
1181    
1182          value = bfd_get_section_by_name (dynobj,
1183                                           ".got")->output_section->vma;
1184          value -= (input_section->output_section->vma
1185                    + input_section->output_offset);
1186          value -= offset;
1187          value += addend;
1188    
1189          bfd_put_32 (input_bfd, value, hit_data);
1190          return bfd_reloc_ok;
1191          
1192        case R_MN10300_GOTPC16:
1193          /* Use global offset table as symbol value.  */
1194    
1195          value = bfd_get_section_by_name (dynobj,
1196                                           ".got")->output_section->vma;
1197          value -= (input_section->output_section->vma
1198                    + input_section->output_offset);
1199          value -= offset;
1200          value += addend;
1201    
1202          if ((long) value > 0xffff || (long) value < -0x10000)
1203            return bfd_reloc_overflow;
1204    
1205          bfd_put_16 (input_bfd, value, hit_data);
1206          return bfd_reloc_ok;
1207    
1208        case R_MN10300_GOTOFF32:
1209          value -= bfd_get_section_by_name (dynobj,
1210                                            ".got")->output_section->vma;
1211          value += addend;
1212          
1213          bfd_put_32 (input_bfd, value, hit_data);
1214          return bfd_reloc_ok;
1215    
1216        case R_MN10300_GOTOFF24:
1217          value -= bfd_get_section_by_name (dynobj,
1218                                            ".got")->output_section->vma;
1219          value += addend;
1220          
1221          if ((long) value > 0x7fffff || (long) value < -0x800000)
1222            return bfd_reloc_overflow;
1223    
1224          bfd_put_8 (input_bfd, value, hit_data);
1225          bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1226          bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1227          return bfd_reloc_ok;
1228    
1229        case R_MN10300_GOTOFF16:
1230          value -= bfd_get_section_by_name (dynobj,
1231                                            ".got")->output_section->vma;
1232          value += addend;
1233          
1234          if ((long) value > 0xffff || (long) value < -0x10000)
1235            return bfd_reloc_overflow;
1236    
1237          bfd_put_16 (input_bfd, value, hit_data);
1238          return bfd_reloc_ok;
1239    
1240        case R_MN10300_PLT32:
1241          if (h != NULL
1242              && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1243              && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1244              && h->plt.offset != (bfd_vma) -1)
1245            {
1246              asection * splt;
1247    
1248              splt = bfd_get_section_by_name (dynobj, ".plt");
1249              
1250              value = (splt->output_section->vma
1251                       + splt->output_offset
1252                       + h->plt.offset) - value;
1253            }
1254    
1255          value -= (input_section->output_section->vma
1256                    + input_section->output_offset);
1257          value -= offset;
1258          value += addend;
1259    
1260          bfd_put_32 (input_bfd, value, hit_data);
1261          return bfd_reloc_ok;
1262    
1263        case R_MN10300_PLT16:
1264          if (h != NULL
1265              && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1266              && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1267              && h->plt.offset != (bfd_vma) -1)
1268            {
1269              asection * splt;
1270    
1271              splt = bfd_get_section_by_name (dynobj, ".plt");
1272              
1273              value = (splt->output_section->vma
1274                       + splt->output_offset
1275                       + h->plt.offset) - value;
1276            }
1277    
1278          value -= (input_section->output_section->vma
1279                    + input_section->output_offset);
1280          value -= offset;
1281          value += addend;
1282    
1283          if ((long) value > 0xffff || (long) value < -0x10000)
1284            return bfd_reloc_overflow;
1285    
1286          bfd_put_16 (input_bfd, value, hit_data);
1287          return bfd_reloc_ok;
1288    
1289        case R_MN10300_GOT32:
1290        case R_MN10300_GOT24:
1291        case R_MN10300_GOT16:
1292          {
1293            asection * sgot;
1294    
1295            sgot = bfd_get_section_by_name (dynobj, ".got");
1296            
1297              if (h != NULL)
1298                {
1299                  bfd_vma off;
1300    
1301                  off = h->got.offset;
1302                  BFD_ASSERT (off != (bfd_vma) -1);
1303    
1304                  if (! elf_hash_table (info)->dynamic_sections_created
1305                      || SYMBOL_REFERENCES_LOCAL (info, h))
1306                    /* This is actually a static link, or it is a
1307                       -Bsymbolic link and the symbol is defined
1308                       locally, or the symbol was forced to be local
1309                       because of a version file.  We must initialize
1310                       this entry in the global offset table.
1311    
1312                       When doing a dynamic link, we create a .rela.got
1313                       relocation entry to initialize the value.  This
1314                       is done in the finish_dynamic_symbol routine.  */
1315                    bfd_put_32 (output_bfd, value,
1316                                sgot->contents + off);
1317    
1318                  value = sgot->output_offset + off;
1319                }
1320              else
1321                {
1322                  bfd_vma off;
1323    
1324                  off = elf_local_got_offsets (input_bfd)[symndx];
1325    
1326                  bfd_put_32 (output_bfd, value, sgot->contents + off);
1327    
1328                  if (info->shared)
1329                    {
1330                      asection * srelgot;
1331                      Elf_Internal_Rela outrel;
1332    
1333                      srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1334                      BFD_ASSERT (srelgot != NULL);
1335    
1336                      outrel.r_offset = (sgot->output_section->vma
1337                                         + sgot->output_offset
1338                                         + off);
1339                      outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1340                      outrel.r_addend = value;
1341                      bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1342                                                 (bfd_byte *) (((Elf32_External_Rela *)
1343                                                                srelgot->contents)
1344                                                               + srelgot->reloc_count));
1345                      ++ srelgot->reloc_count;
1346                    }
1347    
1348                  value = sgot->output_offset + off;
1349                }
1350          }
1351    
1352          value += addend;
1353    
1354          if (r_type == R_MN10300_GOT32)
1355            {
1356              bfd_put_32 (input_bfd, value, hit_data);
1357              return bfd_reloc_ok;
1358            }
1359          else if (r_type == R_MN10300_GOT24)
1360            {
1361              if ((long) value > 0x7fffff || (long) value < -0x800000)
1362                return bfd_reloc_overflow;
1363    
1364              bfd_put_8 (input_bfd, value & 0xff, hit_data);
1365              bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1366              bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1367              return bfd_reloc_ok;
1368            }
1369          else if (r_type == R_MN10300_GOT16)
1370            {
1371              if ((long) value > 0xffff || (long) value < -0x10000)
1372                return bfd_reloc_overflow;
1373    
1374              bfd_put_16 (input_bfd, value, hit_data);
1375              return bfd_reloc_ok;
1376            }
1377          /* Fall through.  */
1378          
1379      default:      default:
1380        return bfd_reloc_notsupported;        return bfd_reloc_notsupported;
1381      }      }
1382  }  }
1383    
1384  /* Relocate an MN10300 ELF section.  */  /* Relocate an MN10300 ELF section.  */
1385  static boolean  static bfd_boolean
1386  mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,  mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1387                                contents, relocs, local_syms, local_sections)                                contents, relocs, local_syms, local_sections)
1388       bfd *output_bfd;       bfd *output_bfd;
# Line 548  mn10300_elf_relocate_section (output_bfd Line 1395  mn10300_elf_relocate_section (output_bfd
1395       asection **local_sections;       asection **local_sections;
1396  {  {
1397    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
1398    struct elf32_mn10300_link_hash_entry **sym_hashes;    struct elf_link_hash_entry **sym_hashes;
1399    Elf_Internal_Rela *rel, *relend;    Elf_Internal_Rela *rel, *relend;
1400    
1401    if (info->relocateable)    if (info->relocatable)
1402      return true;      return TRUE;
1403    
1404    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1405    sym_hashes = (struct elf32_mn10300_link_hash_entry **)    sym_hashes = elf_sym_hashes (input_bfd);
                  (elf_sym_hashes (input_bfd));  
1406    
1407    rel = relocs;    rel = relocs;
1408    relend = relocs + input_section->reloc_count;    relend = relocs + input_section->reloc_count;
# Line 587  mn10300_elf_relocate_section (output_bfd Line 1433  mn10300_elf_relocate_section (output_bfd
1433          {          {
1434            sym = local_syms + r_symndx;            sym = local_syms + r_symndx;
1435            sec = local_sections[r_symndx];            sec = local_sections[r_symndx];
1436            relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);            relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1437          }          }
1438        else        else
1439          {          {
1440            h = sym_hashes[r_symndx - symtab_hdr->sh_info];            bfd_boolean unresolved_reloc;
1441            while (h->root.root.type == bfd_link_hash_indirect            bfd_boolean warned;
1442                   || h->root.root.type == bfd_link_hash_warning)            struct elf_link_hash_entry *hh;
1443              h = (struct elf32_mn10300_link_hash_entry *) h->root.root.u.i.link;  
1444            if (h->root.root.type == bfd_link_hash_defined            RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1445                                       r_symndx, symtab_hdr, sym_hashes,
1446                                       hh, sec, relocation,
1447                                       unresolved_reloc, warned);
1448    
1449              h = (struct elf32_mn10300_link_hash_entry *) hh;
1450    
1451              if ((h->root.root.type == bfd_link_hash_defined
1452                || h->root.root.type == bfd_link_hash_defweak)                || h->root.root.type == bfd_link_hash_defweak)
1453              {                && (   r_type == R_MN10300_GOTPC32
1454                sec = h->root.root.u.def.section;                    || r_type == R_MN10300_GOTPC16
1455                relocation = (h->root.root.u.def.value                    || ((   r_type == R_MN10300_PLT32
1456                              + sec->output_section->vma                         || r_type == R_MN10300_PLT16)
1457                              + sec->output_offset);                        && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
1458              }                        && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
1459            else if (h->root.root.type == bfd_link_hash_undefweak)                        && h->root.plt.offset != (bfd_vma) -1)
1460                      || ((   r_type == R_MN10300_GOT32
1461                           || r_type == R_MN10300_GOT24
1462                           || r_type == R_MN10300_GOT16)
1463                          && elf_hash_table (info)->dynamic_sections_created
1464                          && !SYMBOL_REFERENCES_LOCAL (info, hh))
1465                      || (r_type == R_MN10300_32
1466                          && !SYMBOL_REFERENCES_LOCAL (info, hh)
1467                          && ((input_section->flags & SEC_ALLOC) != 0
1468                              /* DWARF will emit R_MN10300_32 relocations
1469                                 in its sections against symbols defined
1470                                 externally in shared libraries.  We can't
1471                                 do anything with them here.  */
1472                              || ((input_section->flags & SEC_DEBUGGING) != 0
1473                                  && h->root.def_dynamic)))))
1474                /* In these cases, we don't need the relocation
1475                   value.  We check specially because in some
1476                   obscure cases sec->output_section will be NULL.  */
1477              relocation = 0;              relocation = 0;
1478            else  
1479              {            else if (unresolved_reloc)
1480                if (! ((*info->callbacks->undefined_symbol)              (*_bfd_error_handler)
1481                       (info, h->root.root.root.string, input_bfd,                (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
1482                        input_section, rel->r_offset, true)))                 bfd_get_filename (input_bfd), h->root.root.root.string,
1483                  return false;                 bfd_get_section_name (input_bfd, input_section));
               relocation = 0;  
             }  
1484          }          }
1485    
1486        r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,        r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
1487                                             input_section,                                             input_section,
1488                                             contents, rel->r_offset,                                             contents, rel->r_offset,
1489                                             relocation, rel->r_addend,                                             relocation, rel->r_addend,
1490                                               (struct elf_link_hash_entry *)h,
1491                                               r_symndx,
1492                                             info, sec, h == NULL);                                             info, sec, h == NULL);
1493    
1494        if (r != bfd_reloc_ok)        if (r != bfd_reloc_ok)
# Line 640  mn10300_elf_relocate_section (output_bfd Line 1510  mn10300_elf_relocate_section (output_bfd
1510              {              {
1511              case bfd_reloc_overflow:              case bfd_reloc_overflow:
1512                if (! ((*info->callbacks->reloc_overflow)                if (! ((*info->callbacks->reloc_overflow)
1513                       (info, name, howto->name, (bfd_vma) 0,                       (info, (h ? &h->root.root : NULL), name,
1514                        input_bfd, input_section, rel->r_offset)))                        howto->name, (bfd_vma) 0, input_bfd,
1515                  return false;                        input_section, rel->r_offset)))
1516                    return FALSE;
1517                break;                break;
1518    
1519              case bfd_reloc_undefined:              case bfd_reloc_undefined:
1520                if (! ((*info->callbacks->undefined_symbol)                if (! ((*info->callbacks->undefined_symbol)
1521                       (info, name, input_bfd, input_section,                       (info, name, input_bfd, input_section,
1522                        rel->r_offset, true)))                        rel->r_offset, TRUE)))
1523                  return false;                  return FALSE;
1524                break;                break;
1525    
1526              case bfd_reloc_outofrange:              case bfd_reloc_outofrange:
# Line 672  mn10300_elf_relocate_section (output_bfd Line 1543  mn10300_elf_relocate_section (output_bfd
1543                if (!((*info->callbacks->warning)                if (!((*info->callbacks->warning)
1544                      (info, msg, name, input_bfd, input_section,                      (info, msg, name, input_bfd, input_section,
1545                       rel->r_offset)))                       rel->r_offset)))
1546                  return false;                  return FALSE;
1547                break;                break;
1548              }              }
1549          }          }
1550      }      }
1551    
1552    return true;    return TRUE;
1553  }  }
1554    
1555  /* Finish initializing one hash table entry.  */  /* Finish initializing one hash table entry.  */
1556  static boolean  static bfd_boolean
1557  elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)  elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
1558       struct bfd_hash_entry *gen_entry;       struct bfd_hash_entry *gen_entry;
1559       PTR in_args ATTRIBUTE_UNUSED;       PTR in_args;
1560  {  {
1561    struct elf32_mn10300_link_hash_entry *entry;    struct elf32_mn10300_link_hash_entry *entry;
1562      struct bfd_link_info *link_info = (struct bfd_link_info *)in_args;
1563    unsigned int byte_count = 0;    unsigned int byte_count = 0;
1564    
1565    entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;    entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
# Line 698  elf32_mn10300_finish_hash_table_entry (g Line 1570  elf32_mn10300_finish_hash_table_entry (g
1570    /* If we already know we want to convert "call" to "calls" for calls    /* If we already know we want to convert "call" to "calls" for calls
1571       to this symbol, then return now.  */       to this symbol, then return now.  */
1572    if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)    if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
1573      return true;      return TRUE;
1574    
1575    /* If there are no named calls to this symbol, or there's nothing we    /* If there are no named calls to this symbol, or there's nothing we
1576       can move from the function itself into the "call" instruction, then       can move from the function itself into the "call" instruction,
1577       note that all "call" instructions should be converted into "calls"       then note that all "call" instructions should be converted into
1578       instructions and return.  */       "calls" instructions and return.  If a symbol is available for
1579         dynamic symbol resolution (overridable or overriding), avoid
1580         custom calling conventions.  */
1581    if (entry->direct_calls == 0    if (entry->direct_calls == 0
1582        || (entry->stack_size == 0 && entry->movm_args == 0))        || (entry->stack_size == 0 && entry->movm_args == 0)
1583          || (elf_hash_table (link_info)->dynamic_sections_created
1584              && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
1585              && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
1586      {      {
1587        /* Make a note that we should convert "call" instructions to "calls"        /* Make a note that we should convert "call" instructions to "calls"
1588           instructions for calls to this symbol.  */           instructions for calls to this symbol.  */
1589        entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;        entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1590        return true;        return TRUE;
1591      }      }
1592    
1593    /* We may be able to move some instructions from the function itself into    /* We may be able to move some instructions from the function itself into
# Line 722  elf32_mn10300_finish_hash_table_entry (g Line 1599  elf32_mn10300_finish_hash_table_entry (g
1599      byte_count += 2;      byte_count += 2;
1600    
1601    /* Count the insn to allocate stack space too.  */    /* Count the insn to allocate stack space too.  */
1602    if (entry->stack_size > 0 && entry->stack_size <= 128)    if (entry->stack_size > 0)
1603      byte_count += 3;      {
1604    else if (entry->stack_size > 0 && entry->stack_size < 256)        if (entry->stack_size <= 128)
1605      byte_count += 4;          byte_count += 3;
1606          else
1607            byte_count += 4;
1608        }
1609    
1610    /* If using "call" will result in larger code, then turn all    /* If using "call" will result in larger code, then turn all
1611       the associated "call" instructions into "calls" instrutions.  */       the associated "call" instructions into "calls" instructions.  */
1612    if (byte_count < entry->direct_calls)    if (byte_count < entry->direct_calls)
1613      entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;      entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1614    
1615    /* This routine never fails.  */    /* This routine never fails.  */
1616    return true;    return TRUE;
1617  }  }
1618    
1619  /* This function handles relaxing for the mn10300.  /* This function handles relaxing for the mn10300.
1620    
1621     There's quite a few relaxing opportunites available on the mn10300:     There are quite a few relaxing opportunities available on the mn10300:
1622    
1623          * calls:32 -> calls:16                                     2 bytes          * calls:32 -> calls:16                                     2 bytes
1624          * call:32  -> call:16                                      2 bytes          * call:32  -> call:16                                      2 bytes
# Line 775  elf32_mn10300_finish_hash_table_entry (g Line 1655  elf32_mn10300_finish_hash_table_entry (g
1655          We don't handle imm16->imm8 or d16->d8 as they're very rare          We don't handle imm16->imm8 or d16->d8 as they're very rare
1656          and somewhat more difficult to support.  */          and somewhat more difficult to support.  */
1657    
1658  static boolean  static bfd_boolean
1659  mn10300_elf_relax_section (abfd, sec, link_info, again)  mn10300_elf_relax_section (abfd, sec, link_info, again)
1660       bfd *abfd;       bfd *abfd;
1661       asection *sec;       asection *sec;
1662       struct bfd_link_info *link_info;       struct bfd_link_info *link_info;
1663       boolean *again;       bfd_boolean *again;
1664  {  {
1665    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
1666    Elf_Internal_Rela *internal_relocs = NULL;    Elf_Internal_Rela *internal_relocs = NULL;
# Line 791  mn10300_elf_relax_section (abfd, sec, li Line 1671  mn10300_elf_relax_section (abfd, sec, li
1671    asection *section = sec;    asection *section = sec;
1672    
1673    /* Assume nothing changes.  */    /* Assume nothing changes.  */
1674    *again = false;    *again = FALSE;
1675    
1676    /* We need a pointer to the mn10300 specific hash table.  */    /* We need a pointer to the mn10300 specific hash table.  */
1677    hash_table = elf32_mn10300_hash_table (link_info);    hash_table = elf32_mn10300_hash_table (link_info);
# Line 839  mn10300_elf_relax_section (abfd, sec, li Line 1719  mn10300_elf_relax_section (abfd, sec, li
1719                /* Get cached copy of section contents if it exists.  */                /* Get cached copy of section contents if it exists.  */
1720                if (elf_section_data (section)->this_hdr.contents != NULL)                if (elf_section_data (section)->this_hdr.contents != NULL)
1721                  contents = elf_section_data (section)->this_hdr.contents;                  contents = elf_section_data (section)->this_hdr.contents;
1722                else if (section->_raw_size != 0)                else if (section->size != 0)
1723                  {                  {
1724                    /* Go get them off disk.  */                    /* Go get them off disk.  */
1725                    contents = (bfd_byte *) bfd_malloc (section->_raw_size);                    if (!bfd_malloc_and_get_section (input_bfd, section,
1726                    if (contents == NULL)                                                     &contents))
                     goto error_return;  
   
                   if (!bfd_get_section_contents (input_bfd, section,  
                                                  contents, (file_ptr) 0,  
                                                  section->_raw_size))  
1727                      goto error_return;                      goto error_return;
1728                  }                  }
1729                else                else
# Line 860  mn10300_elf_relax_section (abfd, sec, li Line 1735  mn10300_elf_relax_section (abfd, sec, li
1735                  {                  {
1736    
1737                    /* Get a copy of the native relocations.  */                    /* Get a copy of the native relocations.  */
1738                    internal_relocs = (_bfd_elf32_link_read_relocs                    internal_relocs = (_bfd_elf_link_read_relocs
1739                                       (input_bfd, section, (PTR) NULL,                                       (input_bfd, section, (PTR) NULL,
1740                                        (Elf_Internal_Rela *) NULL,                                        (Elf_Internal_Rela *) NULL,
1741                                        link_info->keep_memory));                                        link_info->keep_memory));
# Line 925  mn10300_elf_relax_section (abfd, sec, li Line 1800  mn10300_elf_relax_section (abfd, sec, li
1800                            if (new_name == 0)                            if (new_name == 0)
1801                              goto error_return;                              goto error_return;
1802    
1803                            sprintf (new_name, "%s_%08x",                            sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
                                    sym_name, (int) sym_sec);  
1804                            sym_name = new_name;                            sym_name = new_name;
1805    
1806                            elftab = &hash_table->static_hash_table->root;                            elftab = &hash_table->static_hash_table->root;
1807                            hash = ((struct elf32_mn10300_link_hash_entry *)                            hash = ((struct elf32_mn10300_link_hash_entry *)
1808                                    elf_link_hash_lookup (elftab, sym_name,                                    elf_link_hash_lookup (elftab, sym_name,
1809                                                          true, true, false));                                                          TRUE, TRUE, FALSE));
1810                            free (new_name);                            free (new_name);
1811                          }                          }
1812                        else                        else
# Line 954  mn10300_elf_relax_section (abfd, sec, li Line 1828  mn10300_elf_relax_section (abfd, sec, li
1828                           direct_calls counter.  Else force "call" to                           direct_calls counter.  Else force "call" to
1829                           "calls" conversions.  */                           "calls" conversions.  */
1830                        if (r_type == R_MN10300_PCREL32                        if (r_type == R_MN10300_PCREL32
1831                              || r_type == R_MN10300_PLT32
1832                              || r_type == R_MN10300_PLT16
1833                            || r_type == R_MN10300_PCREL16)                            || r_type == R_MN10300_PCREL16)
1834                          hash->direct_calls++;                          hash->direct_calls++;
1835                        else                        else
# Line 975  mn10300_elf_relax_section (abfd, sec, li Line 1851  mn10300_elf_relax_section (abfd, sec, li
1851                    sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,                    sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
1852                                                                   section);                                                                   section);
1853    
1854                      symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1855                                  - symtab_hdr->sh_info);
1856                      hashes = elf_sym_hashes (input_bfd);
1857                      end_hashes = hashes + symcount;
1858    
1859                    /* Look at each function defined in this section and                    /* Look at each function defined in this section and
1860                       update info for that function.  */                       update info for that function.  */
1861                    isymend = isymbuf + symtab_hdr->sh_info;                    isymend = isymbuf + symtab_hdr->sh_info;
# Line 985  mn10300_elf_relax_section (abfd, sec, li Line 1866  mn10300_elf_relax_section (abfd, sec, li
1866                          {                          {
1867                            struct elf_link_hash_table *elftab;                            struct elf_link_hash_table *elftab;
1868                            bfd_size_type amt;                            bfd_size_type amt;
1869                              struct elf_link_hash_entry **lhashes = hashes;
1870    
1871                              /* Skip a local symbol if it aliases a
1872                                 global one.  */
1873                              for (; lhashes < end_hashes; lhashes++)
1874                                {
1875                                  hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
1876                                  if ((hash->root.root.type == bfd_link_hash_defined
1877                                       || hash->root.root.type == bfd_link_hash_defweak)
1878                                      && hash->root.root.u.def.section == section
1879                                      && hash->root.type == STT_FUNC
1880                                      && hash->root.root.u.def.value == isym->st_value)
1881                                    break;
1882                                }
1883                              if (lhashes != end_hashes)
1884                                continue;
1885    
1886                            if (isym->st_shndx == SHN_UNDEF)                            if (isym->st_shndx == SHN_UNDEF)
1887                              sym_sec = bfd_und_section_ptr;                              sym_sec = bfd_und_section_ptr;
# Line 1008  mn10300_elf_relax_section (abfd, sec, li Line 1905  mn10300_elf_relax_section (abfd, sec, li
1905                            if (new_name == 0)                            if (new_name == 0)
1906                              goto error_return;                              goto error_return;
1907    
1908                            sprintf (new_name, "%s_%08x",                            sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
                                    sym_name, (int) sym_sec);  
1909                            sym_name = new_name;                            sym_name = new_name;
1910    
1911                            elftab = &hash_table->static_hash_table->root;                            elftab = &hash_table->static_hash_table->root;
1912                            hash = ((struct elf32_mn10300_link_hash_entry *)                            hash = ((struct elf32_mn10300_link_hash_entry *)
1913                                    elf_link_hash_lookup (elftab, sym_name,                                    elf_link_hash_lookup (elftab, sym_name,
1914                                                          true, true, false));                                                          TRUE, TRUE, FALSE));
1915                            free (new_name);                            free (new_name);
1916                            compute_function_info (input_bfd, hash,                            compute_function_info (input_bfd, hash,
1917                                                   isym->st_value, contents);                                                   isym->st_value, contents);
1918                          }                          }
1919                      }                      }
1920    
                   symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)  
                               - symtab_hdr->sh_info);  
                   hashes = elf_sym_hashes (abfd);  
                   end_hashes = hashes + symcount;  
1921                    for (; hashes < end_hashes; hashes++)                    for (; hashes < end_hashes; hashes++)
1922                      {                      {
1923                        hash = (struct elf32_mn10300_link_hash_entry *) *hashes;                        hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
1924                        if ((hash->root.root.type == bfd_link_hash_defined                        if ((hash->root.root.type == bfd_link_hash_defined
1925                             || hash->root.root.type == bfd_link_hash_defweak)                             || hash->root.root.type == bfd_link_hash_defweak)
1926                            && hash->root.root.u.def.section == section                            && hash->root.root.u.def.section == section
1927                            && ELF_ST_TYPE (isym->st_info) == STT_FUNC)                            && hash->root.type == STT_FUNC)
1928                          compute_function_info (input_bfd, hash,                          compute_function_info (input_bfd, hash,
1929                                                 (hash)->root.root.u.def.value,                                                 (hash)->root.root.u.def.value,
1930                                                 contents);                                                 contents);
# Line 1079  mn10300_elf_relax_section (abfd, sec, li Line 1971  mn10300_elf_relax_section (abfd, sec, li
1971           the final initialization steps on each.  */           the final initialization steps on each.  */
1972        elf32_mn10300_link_hash_traverse (hash_table,        elf32_mn10300_link_hash_traverse (hash_table,
1973                                          elf32_mn10300_finish_hash_table_entry,                                          elf32_mn10300_finish_hash_table_entry,
1974                                          NULL);                                          link_info);
1975        elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,        elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
1976                                          elf32_mn10300_finish_hash_table_entry,                                          elf32_mn10300_finish_hash_table_entry,
1977                                          NULL);                                          link_info);
1978    
1979        /* All entries in the hash table are fully initialized.  */        /* All entries in the hash table are fully initialized.  */
1980        hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;        hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
# Line 1120  mn10300_elf_relax_section (abfd, sec, li Line 2012  mn10300_elf_relax_section (abfd, sec, li
2012                unsigned int symcount;                unsigned int symcount;
2013    
2014                /* Skip non-code sections and empty sections.  */                /* Skip non-code sections and empty sections.  */
2015                if ((section->flags & SEC_CODE) == 0 || section->_raw_size == 0)                if ((section->flags & SEC_CODE) == 0 || section->size == 0)
2016                  continue;                  continue;
2017    
2018                if (section->reloc_count != 0)                if (section->reloc_count != 0)
2019                  {                  {
2020                    /* Get a copy of the native relocations.  */                    /* Get a copy of the native relocations.  */
2021                    internal_relocs = (_bfd_elf32_link_read_relocs                    internal_relocs = (_bfd_elf_link_read_relocs
2022                                       (input_bfd, section, (PTR) NULL,                                       (input_bfd, section, (PTR) NULL,
2023                                        (Elf_Internal_Rela *) NULL,                                        (Elf_Internal_Rela *) NULL,
2024                                        link_info->keep_memory));                                        link_info->keep_memory));
# Line 1140  mn10300_elf_relax_section (abfd, sec, li Line 2032  mn10300_elf_relax_section (abfd, sec, li
2032                else                else
2033                  {                  {
2034                    /* Go get them off disk.  */                    /* Go get them off disk.  */
2035                    contents = (bfd_byte *) bfd_malloc (section->_raw_size);                    if (!bfd_malloc_and_get_section (input_bfd, section,
2036                    if (contents == NULL)                                                     &contents))
                     goto error_return;  
   
                   if (!bfd_get_section_contents (input_bfd, section,  
                                                  contents, (file_ptr) 0,  
                                                  section->_raw_size))  
2037                      goto error_return;                      goto error_return;
2038                  }                  }
2039    
# Line 1189  mn10300_elf_relax_section (abfd, sec, li Line 2076  mn10300_elf_relax_section (abfd, sec, li
2076                    new_name = bfd_malloc (amt);                    new_name = bfd_malloc (amt);
2077                    if (new_name == 0)                    if (new_name == 0)
2078                      goto error_return;                      goto error_return;
2079                    sprintf (new_name, "%s_%08x", sym_name, (int) sym_sec);                    sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2080                    sym_name = new_name;                    sym_name = new_name;
2081    
2082                    elftab = &hash_table->static_hash_table->root;                    elftab = &hash_table->static_hash_table->root;
2083                    sym_hash = ((struct elf32_mn10300_link_hash_entry *)                    sym_hash = ((struct elf32_mn10300_link_hash_entry *)
2084                                elf_link_hash_lookup (elftab, sym_name,                                elf_link_hash_lookup (elftab, sym_name,
2085                                                      false, false, false));                                                      FALSE, FALSE, FALSE));
2086    
2087                    free (new_name);                    free (new_name);
2088                    if (sym_hash == NULL)                    if (sym_hash == NULL)
# Line 1215  mn10300_elf_relax_section (abfd, sec, li Line 2102  mn10300_elf_relax_section (abfd, sec, li
2102                        if (sym_hash->movm_args)                        if (sym_hash->movm_args)
2103                          bytes += 2;                          bytes += 2;
2104    
2105                        if (sym_hash->stack_size && sym_hash->stack_size <= 128)                        if (sym_hash->stack_size > 0)
2106                          bytes += 3;                          {
2107                        else if (sym_hash->stack_size                            if (sym_hash->stack_size <= 128)
2108                                 && sym_hash->stack_size < 256)                              bytes += 3;
2109                          bytes += 4;                            else
2110                                bytes += 4;
2111                            }
2112    
2113                        /* Note that we've deleted prologue bytes for this                        /* Note that we've deleted prologue bytes for this
2114                           function.  */                           function.  */
# Line 1234  mn10300_elf_relax_section (abfd, sec, li Line 2123  mn10300_elf_relax_section (abfd, sec, li
2123    
2124                        /* Something changed.  Not strictly necessary, but                        /* Something changed.  Not strictly necessary, but
2125                           may lead to more relaxing opportunities.  */                           may lead to more relaxing opportunities.  */
2126                        *again = true;                        *again = TRUE;
2127                      }                      }
2128                  }                  }
2129    
# Line 1242  mn10300_elf_relax_section (abfd, sec, li Line 2131  mn10300_elf_relax_section (abfd, sec, li
2131                   need insns deleted from their prologues.  */                   need insns deleted from their prologues.  */
2132                symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)                symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2133                            - symtab_hdr->sh_info);                            - symtab_hdr->sh_info);
2134                hashes = elf_sym_hashes (abfd);                hashes = elf_sym_hashes (input_bfd);
2135                end_hashes = hashes + symcount;                end_hashes = hashes + symcount;
2136                for (; hashes < end_hashes; hashes++)                for (; hashes < end_hashes; hashes++)
2137                  {                  {
# Line 1267  mn10300_elf_relax_section (abfd, sec, li Line 2156  mn10300_elf_relax_section (abfd, sec, li
2156                        if (sym_hash->movm_args)                        if (sym_hash->movm_args)
2157                          bytes += 2;                          bytes += 2;
2158    
2159                        if (sym_hash->stack_size && sym_hash->stack_size <= 128)                        if (sym_hash->stack_size > 0)
2160                          bytes += 3;                          {
2161                        else if (sym_hash->stack_size                            if (sym_hash->stack_size <= 128)
2162                                 && sym_hash->stack_size < 256)                              bytes += 3;
2163                          bytes += 4;                            else
2164                                bytes += 4;
2165                            }
2166    
2167                        /* Note that we've deleted prologue bytes for this                        /* Note that we've deleted prologue bytes for this
2168                           function.  */                           function.  */
# Line 1287  mn10300_elf_relax_section (abfd, sec, li Line 2178  mn10300_elf_relax_section (abfd, sec, li
2178    
2179                        /* Something changed.  Not strictly necessary, but                        /* Something changed.  Not strictly necessary, but
2180                           may lead to more relaxing opportunities.  */                           may lead to more relaxing opportunities.  */
2181                        *again = true;                        *again = TRUE;
2182                      }                      }
2183                  }                  }
2184    
# Line 1335  mn10300_elf_relax_section (abfd, sec, li Line 2226  mn10300_elf_relax_section (abfd, sec, li
2226    /* For error_return.  */    /* For error_return.  */
2227    section = sec;    section = sec;
2228    
2229    /* We don't have to do anything for a relocateable link, if    /* We don't have to do anything for a relocatable link, if
2230       this section does not have relocs, or if this is not a       this section does not have relocs, or if this is not a
2231       code section.  */       code section.  */
2232    if (link_info->relocateable    if (link_info->relocatable
2233        || (sec->flags & SEC_RELOC) == 0        || (sec->flags & SEC_RELOC) == 0
2234        || sec->reloc_count == 0        || sec->reloc_count == 0
2235        || (sec->flags & SEC_CODE) == 0)        || (sec->flags & SEC_CODE) == 0)
2236      return true;      return TRUE;
   
   /* If this is the first time we have been called for this section,  
      initialize the cooked size.  */  
   if (sec->_cooked_size == 0)  
     sec->_cooked_size = sec->_raw_size;  
2237    
2238    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2239    
2240    /* Get a copy of the native relocations.  */    /* Get a copy of the native relocations.  */
2241    internal_relocs = (_bfd_elf32_link_read_relocs    internal_relocs = (_bfd_elf_link_read_relocs
2242                       (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,                       (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2243                        link_info->keep_memory));                        link_info->keep_memory));
2244    if (internal_relocs == NULL)    if (internal_relocs == NULL)
# Line 1381  mn10300_elf_relax_section (abfd, sec, li Line 2267  mn10300_elf_relax_section (abfd, sec, li
2267            else            else
2268              {              {
2269                /* Go get them off disk.  */                /* Go get them off disk.  */
2270                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))  
2271                  goto error_return;                  goto error_return;
2272              }              }
2273          }          }
2274    
2275        /* Read this BFD's symbols if we haven't done so already.  */        /* Read this BFD's symbols if we haven't done so already.  */
2276        if (isymbuf == NULL && symtab_hdr->sh_info != 0)        if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2277          {          {
2278            isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;            isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
# Line 1410  mn10300_elf_relax_section (abfd, sec, li Line 2291  mn10300_elf_relax_section (abfd, sec, li
2291            asection *sym_sec = NULL;            asection *sym_sec = NULL;
2292            const char *sym_name;            const char *sym_name;
2293            char *new_name;            char *new_name;
2294              bfd_vma saved_addend;
2295    
2296            /* A local symbol.  */            /* A local symbol.  */
2297            isym = isymbuf + ELF32_R_SYM (irel->r_info);            isym = isymbuf + ELF32_R_SYM (irel->r_info);
# Line 1422  mn10300_elf_relax_section (abfd, sec, li Line 2304  mn10300_elf_relax_section (abfd, sec, li
2304            else            else
2305              sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);              sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2306    
           symval = (isym->st_value  
                     + sym_sec->output_section->vma  
                     + sym_sec->output_offset);  
2307            sym_name = bfd_elf_string_from_elf_section (abfd,            sym_name = bfd_elf_string_from_elf_section (abfd,
2308                                                        symtab_hdr->sh_link,                                                        symtab_hdr->sh_link,
2309                                                        isym->st_name);                                                        isym->st_name);
2310    
2311              if ((sym_sec->flags & SEC_MERGE)
2312                  && ELF_ST_TYPE (isym->st_info) == STT_SECTION
2313                  && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
2314                {
2315                  saved_addend = irel->r_addend;
2316                  symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
2317                  symval += irel->r_addend;
2318                  irel->r_addend = saved_addend;
2319                }
2320              else
2321                {
2322                  symval = (isym->st_value
2323                            + sym_sec->output_section->vma
2324                            + sym_sec->output_offset);
2325                }
2326            /* Tack on an ID so we can uniquely identify this            /* Tack on an ID so we can uniquely identify this
2327               local symbol in the global hash table.  */               local symbol in the global hash table.  */
2328            new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);            new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
2329            if (new_name == 0)            if (new_name == 0)
2330              goto error_return;              goto error_return;
2331            sprintf (new_name, "%s_%08x", sym_name, (int) sym_sec);            sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2332            sym_name = new_name;            sym_name = new_name;
2333    
2334            h = (struct elf32_mn10300_link_hash_entry *)            h = (struct elf32_mn10300_link_hash_entry *)
2335                  elf_link_hash_lookup (&hash_table->static_hash_table->root,                  elf_link_hash_lookup (&hash_table->static_hash_table->root,
2336                                        sym_name, false, false, false);                                        sym_name, FALSE, FALSE, FALSE);
2337            free (new_name);            free (new_name);
2338          }          }
2339        else        else
# Line 1476  mn10300_elf_relax_section (abfd, sec, li Line 2370  mn10300_elf_relax_section (abfd, sec, li
2370        /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative        /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
2371           branch/call, also deal with "call" -> "calls" conversions and           branch/call, also deal with "call" -> "calls" conversions and
2372           insertion of prologue data into "call" instructions.  */           insertion of prologue data into "call" instructions.  */
2373        if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32)        if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
2374              || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
2375          {          {
2376            bfd_vma value = symval;            bfd_vma value = symval;
2377    
2378              if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
2379                  && h != NULL
2380                  && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
2381                  && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
2382                  && h->root.plt.offset != (bfd_vma) -1)
2383                {
2384                  asection * splt;
2385    
2386                  splt = bfd_get_section_by_name (elf_hash_table (link_info)
2387                                                  ->dynobj, ".plt");
2388              
2389                  value = ((splt->output_section->vma
2390                            + splt->output_offset
2391                            + h->root.plt.offset)
2392                           - (sec->output_section->vma
2393                              + sec->output_offset
2394                              + irel->r_offset));
2395                }
2396    
2397            /* If we've got a "call" instruction that needs to be turned            /* If we've got a "call" instruction that needs to be turned
2398               into a "calls" instruction, do so now.  It saves a byte.  */               into a "calls" instruction, do so now.  It saves a byte.  */
2399            if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))            if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
# Line 1513  mn10300_elf_relax_section (abfd, sec, li Line 2427  mn10300_elf_relax_section (abfd, sec, li
2427    
2428                    /* That will change things, so, we should relax again.                    /* That will change things, so, we should relax again.
2429                       Note that this is not required, and it may be slow.  */                       Note that this is not required, and it may be slow.  */
2430                    *again = true;                    *again = TRUE;
2431                  }                  }
2432              }              }
2433            else if (h)            else if (h)
# Line 1568  mn10300_elf_relax_section (abfd, sec, li Line 2482  mn10300_elf_relax_section (abfd, sec, li
2482    
2483                /* Fix the relocation's type.  */                /* Fix the relocation's type.  */
2484                irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2485                                               (ELF32_R_TYPE (irel->r_info)
2486                                                == (int) R_MN10300_PLT32)
2487                                               ? R_MN10300_PLT16 :
2488                                             R_MN10300_PCREL16);                                             R_MN10300_PCREL16);
2489    
2490                /* Delete two bytes of data.  */                /* Delete two bytes of data.  */
# Line 1577  mn10300_elf_relax_section (abfd, sec, li Line 2494  mn10300_elf_relax_section (abfd, sec, li
2494    
2495                /* That will change things, so, we should relax again.                /* That will change things, so, we should relax again.
2496                   Note that this is not required, and it may be slow.  */                   Note that this is not required, and it may be slow.  */
2497                *again = true;                *again = TRUE;
2498              }              }
2499          }          }
2500    
# Line 1620  mn10300_elf_relax_section (abfd, sec, li Line 2537  mn10300_elf_relax_section (abfd, sec, li
2537    
2538                    /* That will change things, so, we should relax again.                    /* That will change things, so, we should relax again.
2539                       Note that this is not required, and it may be slow.  */                       Note that this is not required, and it may be slow.  */
2540                    *again = true;                    *again = TRUE;
2541                  }                  }
2542              }              }
2543            else if (h)            else if (h)
# Line 1677  mn10300_elf_relax_section (abfd, sec, li Line 2594  mn10300_elf_relax_section (abfd, sec, li
2594    
2595                /* That will change things, so, we should relax again.                /* That will change things, so, we should relax again.
2596                   Note that this is not required, and it may be slow.  */                   Note that this is not required, and it may be slow.  */
2597                *again = true;                *again = TRUE;
2598              }              }
2599          }          }
2600    
# Line 1704  mn10300_elf_relax_section (abfd, sec, li Line 2621  mn10300_elf_relax_section (abfd, sec, li
2621            value += irel->r_addend;            value += irel->r_addend;
2622    
2623            /* Do nothing if this reloc is the last byte in the section.  */            /* Do nothing if this reloc is the last byte in the section.  */
2624            if (irel->r_offset == sec->_cooked_size)            if (irel->r_offset == sec->size)
2625              continue;              continue;
2626    
2627            /* See if the next instruction is an unconditional pc-relative            /* See if the next instruction is an unconditional pc-relative
# Line 1817  mn10300_elf_relax_section (abfd, sec, li Line 2734  mn10300_elf_relax_section (abfd, sec, li
2734    
2735            /* That will change things, so, we should relax again.            /* That will change things, so, we should relax again.
2736               Note that this is not required, and it may be slow.  */               Note that this is not required, and it may be slow.  */
2737            *again = true;            *again = TRUE;
2738          }          }
2739    
2740        /* Try to turn a 24 immediate, displacement or absolute address        /* Try to turn a 24 immediate, displacement or absolute address
# Line 1880  mn10300_elf_relax_section (abfd, sec, li Line 2797  mn10300_elf_relax_section (abfd, sec, li
2797                            /* That will change things, so, we should relax                            /* That will change things, so, we should relax
2798                               again.  Note that this is not required, and it                               again.  Note that this is not required, and it
2799                               may be slow.  */                               may be slow.  */
2800                            *again = true;                            *again = TRUE;
2801                            break;                            break;
2802                          }                          }
2803                      }                      }
# Line 1890  mn10300_elf_relax_section (abfd, sec, li Line 2807  mn10300_elf_relax_section (abfd, sec, li
2807    
2808        /* Try to turn a 32bit immediate, displacement or absolute address        /* Try to turn a 32bit immediate, displacement or absolute address
2809           into a 16bit immediate, displacement or absolute address.  */           into a 16bit immediate, displacement or absolute address.  */
2810        if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32)        if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
2811              || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
2812              || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32
2813              || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
2814          {          {
2815            bfd_vma value = symval;            bfd_vma value = symval;
2816    
2817              if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
2818                {
2819                  asection * sgot;
2820    
2821                  sgot = bfd_get_section_by_name (elf_hash_table (link_info)
2822                                                  ->dynobj, ".got");
2823    
2824                  if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
2825                    {
2826                      value = sgot->output_offset;
2827    
2828                      if (h)
2829                        value += h->root.got.offset;
2830                      else
2831                        value += (elf_local_got_offsets
2832                                  (abfd)[ELF32_R_SYM (irel->r_info)]);
2833                    }
2834                  else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2835                    value -= sgot->output_section->vma;
2836                  else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
2837                    value = (sgot->output_section->vma
2838                             - (sec->output_section->vma
2839                                + sec->output_offset
2840                                + irel->r_offset));
2841                  else
2842                    abort ();
2843                }
2844    
2845            value += irel->r_addend;            value += irel->r_addend;
2846    
2847            /* See if the value will fit in 24 bits.            /* See if the value will fit in 24 bits.
# Line 1918  mn10300_elf_relax_section (abfd, sec, li Line 2867  mn10300_elf_relax_section (abfd, sec, li
2867                       equivalent instructions exists.  */                       equivalent instructions exists.  */
2868                    if (code != 0x6b && code != 0x7b                    if (code != 0x6b && code != 0x7b
2869                        && code != 0x8b && code != 0x9b                        && code != 0x8b && code != 0x9b
2870                          && (ELF32_R_TYPE (irel->r_info)
2871                              != (int) R_MN10300_GOTPC32)
2872                        && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08                        && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2873                            || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b                            || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2874                            || (code & 0x0f) == 0x0e))                            || (code & 0x0f) == 0x0e))
# Line 1941  mn10300_elf_relax_section (abfd, sec, li Line 2892  mn10300_elf_relax_section (abfd, sec, li
2892                            /* Fix the relocation's type.  */                            /* Fix the relocation's type.  */
2893                            irel->r_info =                            irel->r_info =
2894                              ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                              ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2895                                              (ELF32_R_TYPE (irel->r_info)
2896                                               == (int) R_MN10300_GOTOFF32)
2897                                              ? R_MN10300_GOTOFF24
2898                                              : (ELF32_R_TYPE (irel->r_info)
2899                                                 == (int) R_MN10300_GOT32)
2900                                              ? R_MN10300_GOT24 :
2901                                            R_MN10300_24);                                            R_MN10300_24);
2902    
2903                            /* Delete one byte of data.  */                            /* Delete one byte of data.  */
# Line 1951  mn10300_elf_relax_section (abfd, sec, li Line 2908  mn10300_elf_relax_section (abfd, sec, li
2908                            /* That will change things, so, we should relax                            /* That will change things, so, we should relax
2909                               again.  Note that this is not required, and it                               again.  Note that this is not required, and it
2910                               may be slow.  */                               may be slow.  */
2911                            *again = true;                            *again = TRUE;
2912                            break;                            break;
2913                          }                          }
2914                      }                      }
# Line 2019  mn10300_elf_relax_section (abfd, sec, li Line 2976  mn10300_elf_relax_section (abfd, sec, li
2976    
2977                      /* Fix the relocation's type.  */                      /* Fix the relocation's type.  */
2978                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2979                                                     (ELF32_R_TYPE (irel->r_info)
2980                                                      == (int) R_MN10300_GOTOFF32)
2981                                                     ? R_MN10300_GOTOFF16
2982                                                     : (ELF32_R_TYPE (irel->r_info)
2983                                                        == (int) R_MN10300_GOT32)
2984                                                     ? R_MN10300_GOT16
2985                                                     : (ELF32_R_TYPE (irel->r_info)
2986                                                        == (int) R_MN10300_GOTPC32)
2987                                                     ? R_MN10300_GOTPC16 :
2988                                                   R_MN10300_16);                                                   R_MN10300_16);
2989    
2990                      /* Delete two bytes of data.  */                      /* Delete two bytes of data.  */
# Line 2028  mn10300_elf_relax_section (abfd, sec, li Line 2994  mn10300_elf_relax_section (abfd, sec, li
2994    
2995                      /* That will change things, so, we should relax again.                      /* That will change things, so, we should relax again.
2996                         Note that this is not required, and it may be slow.  */                         Note that this is not required, and it may be slow.  */
2997                      *again = true;                      *again = TRUE;
2998                      break;                      break;
2999                    }                    }
3000                else if ((code & 0xf0) == 0x80                else if ((code & 0xf0) == 0x80
# Line 2060  mn10300_elf_relax_section (abfd, sec, li Line 3026  mn10300_elf_relax_section (abfd, sec, li
3026    
3027                      /* Fix the relocation's type.  */                      /* Fix the relocation's type.  */
3028                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3029                                                     (ELF32_R_TYPE (irel->r_info)
3030                                                      == (int) R_MN10300_GOTOFF32)
3031                                                     ? R_MN10300_GOTOFF16
3032                                                     : (ELF32_R_TYPE (irel->r_info)
3033                                                        == (int) R_MN10300_GOT32)
3034                                                     ? R_MN10300_GOT16
3035                                                     : (ELF32_R_TYPE (irel->r_info)
3036                                                        == (int) R_MN10300_GOTPC32)
3037                                                     ? R_MN10300_GOTPC16 :
3038                                                   R_MN10300_16);                                                   R_MN10300_16);
3039    
3040                      /* The opcode got shorter too, so we have to fix the                      /* The opcode got shorter too, so we have to fix the
# Line 2073  mn10300_elf_relax_section (abfd, sec, li Line 3048  mn10300_elf_relax_section (abfd, sec, li
3048    
3049                      /* That will change things, so, we should relax again.                      /* That will change things, so, we should relax again.
3050                         Note that this is not required, and it may be slow.  */                         Note that this is not required, and it may be slow.  */
3051                      *again = true;                      *again = TRUE;
3052                      break;                      break;
3053    
3054                    /* mov am,(abs32)    -> mov am,(abs16)                    /* mov am,(abs32)    -> mov am,(abs16)
# Line 2102  mn10300_elf_relax_section (abfd, sec, li Line 3077  mn10300_elf_relax_section (abfd, sec, li
3077    
3078                      /* Fix the relocation's type.  */                      /* Fix the relocation's type.  */
3079                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3080                                                     (ELF32_R_TYPE (irel->r_info)
3081                                                      == (int) R_MN10300_GOTOFF32)
3082                                                     ? R_MN10300_GOTOFF16
3083                                                     : (ELF32_R_TYPE (irel->r_info)
3084                                                        == (int) R_MN10300_GOT32)
3085                                                     ? R_MN10300_GOT16
3086                                                     : (ELF32_R_TYPE (irel->r_info)
3087                                                        == (int) R_MN10300_GOTPC32)
3088                                                     ? R_MN10300_GOTPC16 :
3089                                                   R_MN10300_16);                                                   R_MN10300_16);
3090    
3091                      /* Delete two bytes of data.  */                      /* Delete two bytes of data.  */
# Line 2111  mn10300_elf_relax_section (abfd, sec, li Line 3095  mn10300_elf_relax_section (abfd, sec, li
3095    
3096                      /* That will change things, so, we should relax again.                      /* That will change things, so, we should relax again.
3097                         Note that this is not required, and it may be slow.  */                         Note that this is not required, and it may be slow.  */
3098                      *again = true;                      *again = TRUE;
3099                      break;                      break;
3100                    }                    }
3101                else if ((code & 0xf0) < 0xf0)                else if ((code & 0xf0) < 0xf0)
# Line 2162  mn10300_elf_relax_section (abfd, sec, li Line 3146  mn10300_elf_relax_section (abfd, sec, li
3146    
3147                      /* Fix the relocation's type.  */                      /* Fix the relocation's type.  */
3148                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3149                                                     (ELF32_R_TYPE (irel->r_info)
3150                                                      == (int) R_MN10300_GOTOFF32)
3151                                                     ? R_MN10300_GOTOFF16
3152                                                     : (ELF32_R_TYPE (irel->r_info)
3153                                                        == (int) R_MN10300_GOT32)
3154                                                     ? R_MN10300_GOT16
3155                                                     : (ELF32_R_TYPE (irel->r_info)
3156                                                        == (int) R_MN10300_GOTPC32)
3157                                                     ? R_MN10300_GOTPC16 :
3158                                                   R_MN10300_16);                                                   R_MN10300_16);
3159    
3160                      /* The opcode got shorter too, so we have to fix the                      /* The opcode got shorter too, so we have to fix the
# Line 2175  mn10300_elf_relax_section (abfd, sec, li Line 3168  mn10300_elf_relax_section (abfd, sec, li
3168    
3169                      /* That will change things, so, we should relax again.                      /* That will change things, so, we should relax again.
3170                         Note that this is not required, and it may be slow.  */                         Note that this is not required, and it may be slow.  */
3171                      *again = true;                      *again = TRUE;
3172                      break;                      break;
3173    
3174                    /* mov (abs32),an    -> mov (abs16),an                    /* mov (abs32),an    -> mov (abs16),an
# Line 2227  mn10300_elf_relax_section (abfd, sec, li Line 3220  mn10300_elf_relax_section (abfd, sec, li
3220    
3221                      /* Fix the relocation's type.  */                      /* Fix the relocation's type.  */
3222                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3223                                                     (ELF32_R_TYPE (irel->r_info)
3224                                                      == (int) R_MN10300_GOTOFF32)
3225                                                     ? R_MN10300_GOTOFF16
3226                                                     : (ELF32_R_TYPE (irel->r_info)
3227                                                        == (int) R_MN10300_GOT32)
3228                                                     ? R_MN10300_GOT16
3229                                                     : (ELF32_R_TYPE (irel->r_info)
3230                                                        == (int) R_MN10300_GOTPC32)
3231                                                     ? R_MN10300_GOTPC16 :
3232                                                   R_MN10300_16);                                                   R_MN10300_16);
3233    
3234                      /* Delete two bytes of data.  */                      /* Delete two bytes of data.  */
# Line 2236  mn10300_elf_relax_section (abfd, sec, li Line 3238  mn10300_elf_relax_section (abfd, sec, li
3238    
3239                      /* That will change things, so, we should relax again.                      /* That will change things, so, we should relax again.
3240                         Note that this is not required, and it may be slow.  */                         Note that this is not required, and it may be slow.  */
3241                      *again = true;                      *again = TRUE;
3242                      break;                      break;
3243                    }                    }
3244                else if (code == 0xfe)                else if (code == 0xfe)
# Line 2254  mn10300_elf_relax_section (abfd, sec, li Line 3256  mn10300_elf_relax_section (abfd, sec, li
3256    
3257                    /* Fix the relocation's type.  */                    /* Fix the relocation's type.  */
3258                    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),                    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3259                                                   (ELF32_R_TYPE (irel->r_info)
3260                                                    == (int) R_MN10300_GOT32)
3261                                                   ? R_MN10300_GOT16
3262                                                   : (ELF32_R_TYPE (irel->r_info)
3263                                                      == (int) R_MN10300_GOTOFF32)
3264                                                   ? R_MN10300_GOTOFF16
3265                                                   : (ELF32_R_TYPE (irel->r_info)
3266                                                      == (int) R_MN10300_GOTPC32)
3267                                                   ? R_MN10300_GOTPC16 :
3268                                                 R_MN10300_16);                                                 R_MN10300_16);
3269    
3270                    /* Delete two bytes of data.  */                    /* Delete two bytes of data.  */
# Line 2263  mn10300_elf_relax_section (abfd, sec, li Line 3274  mn10300_elf_relax_section (abfd, sec, li
3274    
3275                    /* That will change things, so, we should relax again.                    /* That will change things, so, we should relax again.
3276                       Note that this is not required, and it may be slow.  */                       Note that this is not required, and it may be slow.  */
3277                    *again = true;                    *again = TRUE;
3278                    break;                    break;
3279                  }                  }
3280              }              }
# Line 2298  mn10300_elf_relax_section (abfd, sec, li Line 3309  mn10300_elf_relax_section (abfd, sec, li
3309        && elf_section_data (sec)->relocs != internal_relocs)        && elf_section_data (sec)->relocs != internal_relocs)
3310      free (internal_relocs);      free (internal_relocs);
3311    
3312    return true;    return TRUE;
3313    
3314   error_return:   error_return:
3315    if (isymbuf != NULL    if (isymbuf != NULL
# Line 2311  mn10300_elf_relax_section (abfd, sec, li Line 3322  mn10300_elf_relax_section (abfd, sec, li
3322        && elf_section_data (section)->relocs != internal_relocs)        && elf_section_data (section)->relocs != internal_relocs)
3323      free (internal_relocs);      free (internal_relocs);
3324    
3325    return false;    return FALSE;
3326  }  }
3327    
3328  /* Compute the stack size and movm arguments for the function  /* Compute the stack size and movm arguments for the function
# Line 2347  compute_function_info (abfd, hash, addr, Line 3358  compute_function_info (abfd, hash, addr,
3358      }      }
3359    
3360    /* Now figure out how much stack space will be allocated by the movm    /* Now figure out how much stack space will be allocated by the movm
3361       instruction.  We need this kept separate from the funtion's normal       instruction.  We need this kept separate from the function's normal
3362       stack space.  */       stack space.  */
3363    if (hash->movm_args)    if (hash->movm_args)
3364      {      {
# Line 2371  compute_function_info (abfd, hash, addr, Line 3382  compute_function_info (abfd, hash, addr,
3382        if (hash->movm_args & 0x08)        if (hash->movm_args & 0x08)
3383          hash->movm_stack_size += 8 * 4;          hash->movm_stack_size += 8 * 4;
3384    
3385        if (bfd_get_mach (abfd) == bfd_mach_am33)        if (bfd_get_mach (abfd) == bfd_mach_am33
3386              || bfd_get_mach (abfd) == bfd_mach_am33_2)
3387          {          {
3388            /* "exother" space.  e0, e1, mdrq, mcrh, mcrl, mcvf */            /* "exother" space.  e0, e1, mdrq, mcrh, mcrl, mcvf */
3389            if (hash->movm_args & 0x1)            if (hash->movm_args & 0x1)
# Line 2416  compute_function_info (abfd, hash, addr, Line 3428  compute_function_info (abfd, hash, addr,
3428    
3429  /* Delete some bytes from a section while relaxing.  */  /* Delete some bytes from a section while relaxing.  */
3430    
3431  static boolean  static bfd_boolean
3432  mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)  mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
3433       bfd *abfd;       bfd *abfd;
3434       asection *sec;       asection *sec;
# Line 2442  mn10300_elf_relax_delete_bytes (abfd, se Line 3454  mn10300_elf_relax_delete_bytes (abfd, se
3454       power larger than the number of bytes we are deleting.  */       power larger than the number of bytes we are deleting.  */
3455    
3456    irelalign = NULL;    irelalign = NULL;
3457    toaddr = sec->_cooked_size;    toaddr = sec->size;
3458    
3459    irel = elf_section_data (sec)->relocs;    irel = elf_section_data (sec)->relocs;
3460    irelend = irel + sec->reloc_count;    irelend = irel + sec->reloc_count;
# Line 2450  mn10300_elf_relax_delete_bytes (abfd, se Line 3462  mn10300_elf_relax_delete_bytes (abfd, se
3462    /* Actually delete the bytes.  */    /* Actually delete the bytes.  */
3463    memmove (contents + addr, contents + addr + count,    memmove (contents + addr, contents + addr + count,
3464             (size_t) (toaddr - addr - count));             (size_t) (toaddr - addr - count));
3465    sec->_cooked_size -= count;    sec->size -= count;
3466    
3467    /* Adjust all the relocs.  */    /* Adjust all the relocs.  */
3468    for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)    for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
# Line 2490  mn10300_elf_relax_delete_bytes (abfd, se Line 3502  mn10300_elf_relax_delete_bytes (abfd, se
3502          }          }
3503      }      }
3504    
3505    return true;    return TRUE;
3506  }  }
3507    
3508  /* Return true if a symbol exists at the given address, else return  /* Return TRUE if a symbol exists at the given address, else return
3509     false.  */     FALSE.  */
3510  static boolean  static bfd_boolean
3511  mn10300_elf_symbol_address_p (abfd, sec, isym, addr)  mn10300_elf_symbol_address_p (abfd, sec, isym, addr)
3512       bfd *abfd;       bfd *abfd;
3513       asection *sec;       asection *sec;
# Line 2517  mn10300_elf_symbol_address_p (abfd, sec, Line 3529  mn10300_elf_symbol_address_p (abfd, sec,
3529      {      {
3530        if (isym->st_shndx == sec_shndx        if (isym->st_shndx == sec_shndx
3531            && isym->st_value == addr)            && isym->st_value == addr)
3532          return true;          return TRUE;
3533      }      }
3534    
3535    symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)    symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
# Line 2531  mn10300_elf_symbol_address_p (abfd, sec, Line 3543  mn10300_elf_symbol_address_p (abfd, sec,
3543             || sym_hash->root.type == bfd_link_hash_defweak)             || sym_hash->root.type == bfd_link_hash_defweak)
3544            && sym_hash->root.u.def.section == sec            && sym_hash->root.u.def.section == sec
3545            && sym_hash->root.u.def.value == addr)            && sym_hash->root.u.def.value == addr)
3546          return true;          return TRUE;
3547      }      }
3548    
3549    return false;    return FALSE;
3550  }  }
3551    
3552  /* This is a version of bfd_generic_get_relocated_section_contents  /* This is a version of bfd_generic_get_relocated_section_contents
# Line 2542  mn10300_elf_symbol_address_p (abfd, sec, Line 3554  mn10300_elf_symbol_address_p (abfd, sec,
3554    
3555  static bfd_byte *  static bfd_byte *
3556  mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,  mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
3557                                              data, relocateable, symbols)                                              data, relocatable, symbols)
3558       bfd *output_bfd;       bfd *output_bfd;
3559       struct bfd_link_info *link_info;       struct bfd_link_info *link_info;
3560       struct bfd_link_order *link_order;       struct bfd_link_order *link_order;
3561       bfd_byte *data;       bfd_byte *data;
3562       boolean relocateable;       bfd_boolean relocatable;
3563       asymbol **symbols;       asymbol **symbols;
3564  {  {
3565    Elf_Internal_Shdr *symtab_hdr;    Elf_Internal_Shdr *symtab_hdr;
# Line 2559  mn10300_elf_get_relocated_section_conten Line 3571  mn10300_elf_get_relocated_section_conten
3571    
3572    /* 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
3573       particular set of section contents, specially.  */       particular set of section contents, specially.  */
3574    if (relocateable    if (relocatable
3575        || elf_section_data (input_section)->this_hdr.contents == NULL)        || elf_section_data (input_section)->this_hdr.contents == NULL)
3576      return bfd_generic_get_relocated_section_contents (output_bfd, link_info,      return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
3577                                                         link_order, data,                                                         link_order, data,
3578                                                         relocateable,                                                         relocatable,
3579                                                         symbols);                                                         symbols);
3580    
3581    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;    symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3582    
3583    memcpy (data, elf_section_data (input_section)->this_hdr.contents,    memcpy (data, elf_section_data (input_section)->this_hdr.contents,
3584            (size_t) input_section->_raw_size);            (size_t) input_section->size);
3585    
3586    if ((input_section->flags & SEC_RELOC) != 0    if ((input_section->flags & SEC_RELOC) != 0
3587        && input_section->reloc_count > 0)        && input_section->reloc_count > 0)
# Line 2578  mn10300_elf_get_relocated_section_conten Line 3590  mn10300_elf_get_relocated_section_conten
3590        Elf_Internal_Sym *isym, *isymend;        Elf_Internal_Sym *isym, *isymend;
3591        bfd_size_type amt;        bfd_size_type amt;
3592    
3593        internal_relocs = (_bfd_elf32_link_read_relocs        internal_relocs = (_bfd_elf_link_read_relocs
3594                           (input_bfd, input_section, (PTR) NULL,                           (input_bfd, input_section, (PTR) NULL,
3595                            (Elf_Internal_Rela *) NULL, false));                            (Elf_Internal_Rela *) NULL, FALSE));
3596        if (internal_relocs == NULL)        if (internal_relocs == NULL)
3597          goto error_return;          goto error_return;
3598    
# Line 2676  elf32_mn10300_link_hash_newfunc (entry, Line 3688  elf32_mn10300_link_hash_newfunc (entry,
3688      {      {
3689        ret->direct_calls = 0;        ret->direct_calls = 0;
3690        ret->stack_size = 0;        ret->stack_size = 0;
3691          ret->movm_args = 0;
3692        ret->movm_stack_size = 0;        ret->movm_stack_size = 0;
3693        ret->flags = 0;        ret->flags = 0;
       ret->movm_args = 0;  
3694      }      }
3695    
3696    return (struct bfd_hash_entry *) ret;    return (struct bfd_hash_entry *) ret;
# Line 2751  elf_mn10300_mach (flags) Line 3763  elf_mn10300_mach (flags)
3763    
3764      case E_MN10300_MACH_AM33:      case E_MN10300_MACH_AM33:
3765        return bfd_mach_am33;        return bfd_mach_am33;
3766    
3767        case E_MN10300_MACH_AM33_2:
3768          return bfd_mach_am33_2;
3769      }      }
3770  }  }
3771    
# Line 2761  elf_mn10300_mach (flags) Line 3776  elf_mn10300_mach (flags)
3776  void  void
3777  _bfd_mn10300_elf_final_write_processing (abfd, linker)  _bfd_mn10300_elf_final_write_processing (abfd, linker)
3778       bfd *abfd;       bfd *abfd;
3779       boolean linker ATTRIBUTE_UNUSED;       bfd_boolean linker ATTRIBUTE_UNUSED;
3780  {  {
3781    unsigned long val;    unsigned long val;
3782    
# Line 2775  _bfd_mn10300_elf_final_write_processing Line 3790  _bfd_mn10300_elf_final_write_processing
3790      case bfd_mach_am33:      case bfd_mach_am33:
3791        val = E_MN10300_MACH_AM33;        val = E_MN10300_MACH_AM33;
3792        break;        break;
3793    
3794        case bfd_mach_am33_2:
3795          val = E_MN10300_MACH_AM33_2;
3796          break;
3797      }      }
3798    
3799    elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);    elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
3800    elf_elfheader (abfd)->e_flags |= val;    elf_elfheader (abfd)->e_flags |= val;
3801  }  }
3802    
3803  boolean  bfd_boolean
3804  _bfd_mn10300_elf_object_p (abfd)  _bfd_mn10300_elf_object_p (abfd)
3805       bfd *abfd;       bfd *abfd;
3806  {  {
3807    bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,    bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
3808                               elf_mn10300_mach (elf_elfheader (abfd)->e_flags));                               elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
3809    return true;    return TRUE;
3810  }  }
3811    
3812  /* Merge backend specific data from an object file to the output  /* Merge backend specific data from an object file to the output
3813     object file when linking.  */     object file when linking.  */
3814    
3815  boolean  bfd_boolean
3816  _bfd_mn10300_elf_merge_private_bfd_data (ibfd, obfd)  _bfd_mn10300_elf_merge_private_bfd_data (ibfd, obfd)
3817       bfd *ibfd;       bfd *ibfd;
3818       bfd *obfd;       bfd *obfd;
3819  {  {
3820    if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour    if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3821        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3822      return true;      return TRUE;
3823    
3824    if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)    if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3825        && bfd_get_mach (obfd) < bfd_get_mach (ibfd))        && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
3826      {      {
3827        if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),        if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3828                                 bfd_get_mach (ibfd)))                                 bfd_get_mach (ibfd)))
3829          return false;          return FALSE;
3830      }      }
3831    
3832    return true;    return TRUE;
3833  }  }
3834    
3835    #define PLT0_ENTRY_SIZE 15
3836    #define PLT_ENTRY_SIZE 20
3837    #define PIC_PLT_ENTRY_SIZE 24
3838    
3839    static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
3840    {
3841      0xfc, 0xa0, 0, 0, 0, 0,       /* mov  (.got+8),a0 */
3842      0xfe, 0xe, 0x10, 0, 0, 0, 0,  /* mov  (.got+4),r1 */
3843      0xf0, 0xf4,                   /* jmp  (a0) */
3844    };
3845    
3846    static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
3847    {
3848      0xfc, 0xa0, 0, 0, 0, 0,       /* mov  (nameN@GOT + .got),a0 */
3849      0xf0, 0xf4,                   /* jmp  (a0) */
3850      0xfe, 8, 0, 0, 0, 0, 0,       /* mov  reloc-table-address,r0 */
3851      0xdc, 0, 0, 0, 0,             /* jmp  .plt0 */
3852    };
3853    
3854    static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
3855    {
3856      0xfc, 0x22, 0, 0, 0, 0,       /* mov  (nameN@GOT,a2),a0 */
3857      0xf0, 0xf4,                   /* jmp  (a0) */
3858      0xfe, 8, 0, 0, 0, 0, 0,       /* mov  reloc-table-address,r0 */
3859      0xf8, 0x22, 8,                /* mov  (8,a2),a0 */
3860      0xfb, 0xa, 0x1a, 4,           /* mov  (4,a2),r1 */
3861      0xf0, 0xf4,                   /* jmp  (a0) */
3862    };
3863    
3864    /* Return size of the first PLT entry.  */
3865    #define elf_mn10300_sizeof_plt0(info) \
3866      (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
3867    
3868    /* Return size of a PLT entry.  */
3869    #define elf_mn10300_sizeof_plt(info) \
3870      (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
3871    
3872    /* Return offset of the PLT0 address in an absolute PLT entry.  */
3873    #define elf_mn10300_plt_plt0_offset(info) 16
3874    
3875    /* Return offset of the linker in PLT0 entry.  */
3876    #define elf_mn10300_plt0_linker_offset(info) 2
3877    
3878    /* Return offset of the GOT id in PLT0 entry.  */
3879    #define elf_mn10300_plt0_gotid_offset(info) 9
3880    
3881    /* Return offset of the temporary in PLT entry */
3882    #define elf_mn10300_plt_temp_offset(info) 8
3883    
3884    /* Return offset of the symbol in PLT entry.  */
3885    #define elf_mn10300_plt_symbol_offset(info) 2
3886    
3887    /* Return offset of the relocation in PLT entry.  */
3888    #define elf_mn10300_plt_reloc_offset(info) 11
3889    
3890    /* The name of the dynamic interpreter.  This is put in the .interp
3891       section.  */
3892    
3893    #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
3894    
3895    /* Create dynamic sections when linking against a dynamic object.  */
3896    
3897    static bfd_boolean
3898    _bfd_mn10300_elf_create_dynamic_sections (abfd, info)
3899         bfd *abfd;
3900         struct bfd_link_info *info;
3901    {
3902      flagword   flags;
3903      asection * s;
3904      const struct elf_backend_data * bed = get_elf_backend_data (abfd);
3905      int ptralign = 0;
3906    
3907      switch (bed->s->arch_size)
3908        {
3909        case 32:
3910          ptralign = 2;
3911          break;
3912    
3913        case 64:
3914          ptralign = 3;
3915          break;
3916    
3917        default:
3918          bfd_set_error (bfd_error_bad_value);
3919          return FALSE;
3920        }
3921    
3922      /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3923         .rel[a].bss sections.  */
3924    
3925      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3926               | SEC_LINKER_CREATED);
3927    
3928      s = bfd_make_section (abfd,
3929                            bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3930      if (s == NULL
3931          || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3932          || ! bfd_set_section_alignment (abfd, s, ptralign))
3933        return FALSE;
3934    
3935      if (! _bfd_mn10300_elf_create_got_section (abfd, info))
3936        return FALSE;
3937    
3938      {
3939        const char * secname;
3940        char *       relname;
3941        flagword     secflags;
3942        asection *   sec;
3943    
3944        for (sec = abfd->sections; sec; sec = sec->next)
3945          {
3946            secflags = bfd_get_section_flags (abfd, sec);
3947            if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3948                || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3949              continue;
3950    
3951            secname = bfd_get_section_name (abfd, sec);
3952            relname = (char *) bfd_malloc (strlen (secname) + 6);
3953            strcpy (relname, ".rela");
3954            strcat (relname, secname);
3955    
3956            s = bfd_make_section (abfd, relname);
3957            if (s == NULL
3958                || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3959                || ! bfd_set_section_alignment (abfd, s, ptralign))
3960              return FALSE;
3961          }
3962      }
3963    
3964      if (bed->want_dynbss)
3965        {
3966          /* The .dynbss section is a place to put symbols which are defined
3967             by dynamic objects, are referenced by regular objects, and are
3968             not functions.  We must allocate space for them in the process
3969             image and use a R_*_COPY reloc to tell the dynamic linker to
3970             initialize them at run time.  The linker script puts the .dynbss
3971             section into the .bss section of the final image.  */
3972          s = bfd_make_section (abfd, ".dynbss");
3973          if (s == NULL
3974              || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
3975            return FALSE;
3976    
3977          /* The .rel[a].bss section holds copy relocs.  This section is not
3978             normally needed.  We need to create it here, though, so that the
3979             linker will map it to an output section.  We can't just create it
3980             only if we need it, because we will not know whether we need it
3981             until we have seen all the input files, and the first time the
3982             main linker code calls BFD after examining all the input files
3983             (size_dynamic_sections) the input sections have already been
3984             mapped to the output sections.  If the section turns out not to
3985             be needed, we can discard it later.  We will never need this
3986             section when generating a shared object, since they do not use
3987             copy relocs.  */
3988          if (! info->shared)
3989            {
3990              s = bfd_make_section (abfd,
3991                                    (bed->default_use_rela_p
3992                                     ? ".rela.bss" : ".rel.bss"));
3993              if (s == NULL
3994                  || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3995                  || ! bfd_set_section_alignment (abfd, s, ptralign))
3996                return FALSE;
3997            }
3998        }
3999    
4000      return TRUE;
4001    }
4002    
4003    /* Adjust a symbol defined by a dynamic object and referenced by a
4004       regular object.  The current definition is in some section of the
4005       dynamic object, but we're not including those sections.  We have to
4006       change the definition to something the rest of the link can
4007       understand.  */
4008    
4009    static bfd_boolean
4010    _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
4011         struct bfd_link_info * info;
4012         struct elf_link_hash_entry * h;
4013    {
4014      bfd * dynobj;
4015      asection * s;
4016      unsigned int power_of_two;
4017    
4018      dynobj = elf_hash_table (info)->dynobj;
4019    
4020      /* Make sure we know what is going on here.  */
4021      BFD_ASSERT (dynobj != NULL
4022                  && (h->needs_plt
4023                      || h->u.weakdef != NULL
4024                      || (h->def_dynamic
4025                          && h->ref_regular
4026                          && !h->def_regular)));
4027    
4028      /* If this is a function, put it in the procedure linkage table.  We
4029         will fill in the contents of the procedure linkage table later,
4030         when we know the address of the .got section.  */
4031      if (h->type == STT_FUNC
4032          || h->needs_plt)
4033        {
4034          if (! info->shared
4035              && !h->def_dynamic
4036              && !h->ref_dynamic)
4037            {
4038              /* This case can occur if we saw a PLT reloc in an input
4039                 file, but the symbol was never referred to by a dynamic
4040                 object.  In such a case, we don't actually need to build
4041                 a procedure linkage table, and we can just do a REL32
4042                 reloc instead.  */
4043              BFD_ASSERT (h->needs_plt);
4044              return TRUE;
4045            }
4046    
4047          /* Make sure this symbol is output as a dynamic symbol.  */
4048          if (h->dynindx == -1)
4049            {
4050              if (! bfd_elf_link_record_dynamic_symbol (info, h))
4051                return FALSE;
4052            }
4053    
4054          s = bfd_get_section_by_name (dynobj, ".plt");
4055          BFD_ASSERT (s != NULL);
4056    
4057          /* If this is the first .plt entry, make room for the special
4058             first entry.  */
4059          if (s->size == 0)
4060            s->size += elf_mn10300_sizeof_plt0 (info);
4061    
4062          /* If this symbol is not defined in a regular file, and we are
4063             not generating a shared library, then set the symbol to this
4064             location in the .plt.  This is required to make function
4065             pointers compare as equal between the normal executable and
4066             the shared library.  */
4067          if (! info->shared
4068              && !h->def_regular)
4069            {
4070              h->root.u.def.section = s;
4071              h->root.u.def.value = s->size;
4072            }
4073    
4074          h->plt.offset = s->size;
4075    
4076          /* Make room for this entry.  */
4077          s->size += elf_mn10300_sizeof_plt (info);
4078    
4079          /* We also need to make an entry in the .got.plt section, which
4080             will be placed in the .got section by the linker script.  */
4081    
4082          s = bfd_get_section_by_name (dynobj, ".got.plt");
4083          BFD_ASSERT (s != NULL);
4084          s->size += 4;
4085    
4086          /* We also need to make an entry in the .rela.plt section.  */
4087    
4088          s = bfd_get_section_by_name (dynobj, ".rela.plt");
4089          BFD_ASSERT (s != NULL);
4090          s->size += sizeof (Elf32_External_Rela);
4091    
4092          return TRUE;
4093        }
4094    
4095      /* If this is a weak symbol, and there is a real definition, the
4096         processor independent code will have arranged for us to see the
4097         real definition first, and we can just use the same value.  */
4098      if (h->u.weakdef != NULL)
4099        {
4100          BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4101                      || h->u.weakdef->root.type == bfd_link_hash_defweak);
4102          h->root.u.def.section = h->u.weakdef->root.u.def.section;
4103          h->root.u.def.value = h->u.weakdef->root.u.def.value;
4104          return TRUE;
4105        }
4106    
4107      /* This is a reference to a symbol defined by a dynamic object which
4108         is not a function.  */
4109    
4110      /* If we are creating a shared library, we must presume that the
4111         only references to the symbol are via the global offset table.
4112         For such cases we need not do anything here; the relocations will
4113         be handled correctly by relocate_section.  */
4114      if (info->shared)
4115        return TRUE;
4116    
4117      /* If there are no references to this symbol that do not use the
4118         GOT, we don't need to generate a copy reloc.  */
4119      if (!h->non_got_ref)
4120        return TRUE;
4121    
4122      /* We must allocate the symbol in our .dynbss section, which will
4123         become part of the .bss section of the executable.  There will be
4124         an entry for this symbol in the .dynsym section.  The dynamic
4125         object will contain position independent code, so all references
4126         from the dynamic object to this symbol will go through the global
4127         offset table.  The dynamic linker will use the .dynsym entry to
4128         determine the address it must put in the global offset table, so
4129         both the dynamic object and the regular object will refer to the
4130         same memory location for the variable.  */
4131    
4132      s = bfd_get_section_by_name (dynobj, ".dynbss");
4133      BFD_ASSERT (s != NULL);
4134    
4135      /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
4136         copy the initial value out of the dynamic object and into the
4137         runtime process image.  We need to remember the offset into the
4138         .rela.bss section we are going to use.  */
4139      if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4140        {
4141          asection * srel;
4142    
4143          srel = bfd_get_section_by_name (dynobj, ".rela.bss");
4144          BFD_ASSERT (srel != NULL);
4145          srel->size += sizeof (Elf32_External_Rela);
4146          h->needs_copy = 1;
4147        }
4148    
4149      /* We need to figure out the alignment required for this symbol.  I
4150         have no idea how ELF linkers handle this.  */
4151      power_of_two = bfd_log2 (h->size);
4152      if (power_of_two > 3)
4153        power_of_two = 3;
4154    
4155      /* Apply the required alignment.  */
4156      s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4157      if (power_of_two > bfd_get_section_alignment (dynobj, s))
4158        {
4159          if (! bfd_set_section_alignment (dynobj, s, power_of_two))
4160            return FALSE;
4161        }
4162    
4163      /* Define the symbol as being at this point in the section.  */
4164      h->root.u.def.section = s;
4165      h->root.u.def.value = s->size;
4166    
4167      /* Increment the section size to make room for the symbol.  */
4168      s->size += h->size;
4169    
4170      return TRUE;
4171    }
4172    
4173    /* Set the sizes of the dynamic sections.  */
4174    
4175    static bfd_boolean
4176    _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
4177         bfd * output_bfd;
4178         struct bfd_link_info * info;
4179    {
4180      bfd * dynobj;
4181      asection * s;
4182      bfd_boolean plt;
4183      bfd_boolean relocs;
4184      bfd_boolean reltext;
4185    
4186      dynobj = elf_hash_table (info)->dynobj;
4187      BFD_ASSERT (dynobj != NULL);
4188    
4189      if (elf_hash_table (info)->dynamic_sections_created)
4190        {
4191          /* Set the contents of the .interp section to the interpreter.  */
4192          if (info->executable)
4193            {
4194              s = bfd_get_section_by_name (dynobj, ".interp");
4195              BFD_ASSERT (s != NULL);
4196              s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4197              s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4198            }
4199        }
4200      else
4201        {
4202          /* We may have created entries in the .rela.got section.
4203             However, if we are not creating the dynamic sections, we will
4204             not actually use these entries.  Reset the size of .rela.got,
4205             which will cause it to get stripped from the output file
4206             below.  */
4207          s = bfd_get_section_by_name (dynobj, ".rela.got");
4208          if (s != NULL)
4209            s->size = 0;
4210        }
4211    
4212      /* The check_relocs and adjust_dynamic_symbol entry points have
4213         determined the sizes of the various dynamic sections.  Allocate
4214         memory for them.  */
4215      plt = FALSE;
4216      relocs = FALSE;
4217      reltext = FALSE;
4218      for (s = dynobj->sections; s != NULL; s = s->next)
4219        {
4220          const char * name;
4221          bfd_boolean strip;
4222    
4223          if ((s->flags & SEC_LINKER_CREATED) == 0)
4224            continue;
4225    
4226          /* It's OK to base decisions on the section name, because none
4227             of the dynobj section names depend upon the input files.  */
4228          name = bfd_get_section_name (dynobj, s);
4229    
4230          strip = FALSE;
4231    
4232          if (strcmp (name, ".plt") == 0)
4233            {
4234              if (s->size == 0)
4235                /* Strip this section if we don't need it; see the
4236                   comment below.  */
4237                strip = TRUE;
4238              else
4239                /* Remember whether there is a PLT.  */
4240                plt = TRUE;
4241            }
4242          else if (strncmp (name, ".rela", 5) == 0)
4243            {
4244              if (s->size == 0)
4245                {
4246                  /* If we don't need this section, strip it from the
4247                     output file.  This is mostly to handle .rela.bss and
4248                     .rela.plt.  We must create both sections in
4249                     create_dynamic_sections, because they must be created
4250                     before the linker maps input sections to output
4251                     sections.  The linker does that before
4252                     adjust_dynamic_symbol is called, and it is that
4253                     function which decides whether anything needs to go
4254                     into these sections.  */
4255                  strip = TRUE;
4256                }
4257              else
4258                {
4259                  asection * target;
4260    
4261                  /* Remember whether there are any reloc sections other
4262                     than .rela.plt.  */
4263                  if (strcmp (name, ".rela.plt") != 0)
4264                    {
4265                      const char * outname;
4266    
4267                      relocs = TRUE;
4268    
4269                      /* If this relocation section applies to a read only
4270                         section, then we probably need a DT_TEXTREL
4271                         entry.  The entries in the .rela.plt section
4272                         really apply to the .got section, which we
4273                         created ourselves and so know is not readonly.  */
4274                      outname = bfd_get_section_name (output_bfd,
4275                                                      s->output_section);
4276                      target = bfd_get_section_by_name (output_bfd, outname + 5);
4277                      if (target != NULL
4278                          && (target->flags & SEC_READONLY) != 0
4279                          && (target->flags & SEC_ALLOC) != 0)
4280                        reltext = TRUE;
4281                    }
4282    
4283                  /* We use the reloc_count field as a counter if we need
4284                     to copy relocs into the output file.  */
4285                  s->reloc_count = 0;
4286                }
4287            }
4288          else if (strncmp (name, ".got", 4) != 0)
4289            /* It's not one of our sections, so don't allocate space.  */
4290            continue;
4291    
4292          if (strip)
4293            {
4294              _bfd_strip_section_from_output (info, s);
4295              continue;
4296            }
4297    
4298          /* Allocate memory for the section contents.  We use bfd_zalloc
4299             here in case unused entries are not reclaimed before the
4300             section's contents are written out.  This should not happen,
4301             but this way if it does, we get a R_MN10300_NONE reloc
4302             instead of garbage.  */
4303          s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4304          if (s->contents == NULL && s->size != 0)
4305            return FALSE;
4306        }
4307    
4308      if (elf_hash_table (info)->dynamic_sections_created)
4309        {
4310          /* Add some entries to the .dynamic section.  We fill in the
4311             values later, in _bfd_mn10300_elf_finish_dynamic_sections,
4312             but we must add the entries now so that we get the correct
4313             size for the .dynamic section.  The DT_DEBUG entry is filled
4314             in by the dynamic linker and used by the debugger.  */
4315          if (! info->shared)
4316            {
4317              if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
4318                return FALSE;
4319            }
4320    
4321          if (plt)
4322            {
4323              if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
4324                  || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
4325                  || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
4326                  || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
4327                return FALSE;
4328            }
4329    
4330          if (relocs)
4331            {
4332              if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
4333                  || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
4334                  || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
4335                                                  sizeof (Elf32_External_Rela)))
4336                return FALSE;
4337            }
4338    
4339          if (reltext)
4340            {
4341              if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
4342                return FALSE;
4343            }
4344        }
4345    
4346      return TRUE;
4347    }
4348    
4349    /* Finish up dynamic symbol handling.  We set the contents of various
4350       dynamic sections here.  */
4351    
4352    static bfd_boolean
4353    _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
4354         bfd * output_bfd;
4355         struct bfd_link_info * info;
4356         struct elf_link_hash_entry * h;
4357         Elf_Internal_Sym * sym;
4358    {
4359      bfd * dynobj;
4360    
4361      dynobj = elf_hash_table (info)->dynobj;
4362    
4363      if (h->plt.offset != (bfd_vma) -1)
4364        {
4365          asection *        splt;
4366          asection *        sgot;
4367          asection *        srel;
4368          bfd_vma           plt_index;
4369          bfd_vma           got_offset;
4370          Elf_Internal_Rela rel;
4371    
4372          /* This symbol has an entry in the procedure linkage table.  Set
4373             it up.  */
4374    
4375          BFD_ASSERT (h->dynindx != -1);
4376    
4377          splt = bfd_get_section_by_name (dynobj, ".plt");
4378          sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4379          srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4380          BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
4381    
4382          /* Get the index in the procedure linkage table which
4383             corresponds to this symbol.  This is the index of this symbol
4384             in all the symbols for which we are making plt entries.  The
4385             first entry in the procedure linkage table is reserved.  */
4386          plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
4387                       / elf_mn10300_sizeof_plt (info));
4388    
4389          /* Get the offset into the .got table of the entry that
4390             corresponds to this function.  Each .got entry is 4 bytes.
4391             The first three are reserved.  */
4392          got_offset = (plt_index + 3) * 4;
4393    
4394          /* Fill in the entry in the procedure linkage table.  */
4395          if (! info->shared)
4396            {
4397              memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
4398                      elf_mn10300_sizeof_plt (info));
4399              bfd_put_32 (output_bfd,
4400                          (sgot->output_section->vma
4401                           + sgot->output_offset
4402                           + got_offset),
4403                          (splt->contents + h->plt.offset
4404                           + elf_mn10300_plt_symbol_offset (info)));
4405    
4406              bfd_put_32 (output_bfd,
4407                          (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
4408                          (splt->contents + h->plt.offset
4409                           + elf_mn10300_plt_plt0_offset (info)));
4410            }
4411          else
4412            {
4413              memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
4414                      elf_mn10300_sizeof_plt (info));
4415    
4416              bfd_put_32 (output_bfd, got_offset,
4417                          (splt->contents + h->plt.offset
4418                           + elf_mn10300_plt_symbol_offset (info)));
4419            }
4420    
4421          bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4422                      (splt->contents + h->plt.offset
4423                       + elf_mn10300_plt_reloc_offset (info)));
4424    
4425          /* Fill in the entry in the global offset table.  */
4426          bfd_put_32 (output_bfd,
4427                      (splt->output_section->vma
4428                       + splt->output_offset
4429                       + h->plt.offset
4430                       + elf_mn10300_plt_temp_offset (info)),
4431                      sgot->contents + got_offset);
4432    
4433          /* Fill in the entry in the .rela.plt section.  */
4434          rel.r_offset = (sgot->output_section->vma
4435                          + sgot->output_offset
4436                          + got_offset);
4437          rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
4438          rel.r_addend = 0;
4439          bfd_elf32_swap_reloca_out (output_bfd, &rel,
4440                                     (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4441                                                   + plt_index));
4442    
4443          if (!h->def_regular)
4444            /* Mark the symbol as undefined, rather than as defined in
4445               the .plt section.  Leave the value alone.  */
4446            sym->st_shndx = SHN_UNDEF;
4447        }
4448    
4449      if (h->got.offset != (bfd_vma) -1)
4450        {
4451          asection *        sgot;
4452          asection *        srel;
4453          Elf_Internal_Rela rel;
4454    
4455          /* This symbol has an entry in the global offset table.  Set it up.  */
4456    
4457          sgot = bfd_get_section_by_name (dynobj, ".got");
4458          srel = bfd_get_section_by_name (dynobj, ".rela.got");
4459          BFD_ASSERT (sgot != NULL && srel != NULL);
4460    
4461          rel.r_offset = (sgot->output_section->vma
4462                          + sgot->output_offset
4463                          + (h->got.offset &~ 1));
4464    
4465          /* If this is a -Bsymbolic link, and the symbol is defined
4466             locally, we just want to emit a RELATIVE reloc.  Likewise if
4467             the symbol was forced to be local because of a version file.
4468             The entry in the global offset table will already have been
4469             initialized in the relocate_section function.  */
4470          if (info->shared
4471              && (info->symbolic || h->dynindx == -1)
4472              && h->def_regular)
4473            {
4474              rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
4475              rel.r_addend = (h->root.u.def.value
4476                              + h->root.u.def.section->output_section->vma
4477                              + h->root.u.def.section->output_offset);
4478            }
4479          else
4480            {
4481              bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
4482              rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
4483              rel.r_addend = 0;
4484            }
4485    
4486          bfd_elf32_swap_reloca_out (output_bfd, &rel,
4487                                     (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4488                                                   + srel->reloc_count));
4489          ++ srel->reloc_count;
4490        }
4491    
4492      if (h->needs_copy)
4493        {
4494          asection *        s;
4495          Elf_Internal_Rela rel;
4496    
4497          /* This symbol needs a copy reloc.  Set it up.  */
4498          BFD_ASSERT (h->dynindx != -1
4499                      && (h->root.type == bfd_link_hash_defined
4500                          || h->root.type == bfd_link_hash_defweak));
4501    
4502          s = bfd_get_section_by_name (h->root.u.def.section->owner,
4503                                       ".rela.bss");
4504          BFD_ASSERT (s != NULL);
4505    
4506          rel.r_offset = (h->root.u.def.value
4507                          + h->root.u.def.section->output_section->vma
4508                          + h->root.u.def.section->output_offset);
4509          rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
4510          rel.r_addend = 0;
4511          bfd_elf32_swap_reloca_out (output_bfd, &rel,
4512                                     (bfd_byte *) ((Elf32_External_Rela *) s->contents
4513                                                   + s->reloc_count));
4514          ++ s->reloc_count;
4515        }
4516    
4517      /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
4518      if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4519          || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
4520        sym->st_shndx = SHN_ABS;
4521    
4522      return TRUE;
4523    }
4524    
4525    /* Finish up the dynamic sections.  */
4526    
4527    static bfd_boolean
4528    _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
4529         bfd * output_bfd;
4530         struct bfd_link_info * info;
4531    {
4532      bfd *      dynobj;
4533      asection * sgot;
4534      asection * sdyn;
4535    
4536      dynobj = elf_hash_table (info)->dynobj;
4537    
4538      sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4539      BFD_ASSERT (sgot != NULL);
4540      sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4541    
4542      if (elf_hash_table (info)->dynamic_sections_created)
4543        {
4544          asection *           splt;
4545          Elf32_External_Dyn * dyncon;
4546          Elf32_External_Dyn * dynconend;
4547    
4548          BFD_ASSERT (sdyn != NULL);
4549    
4550          dyncon = (Elf32_External_Dyn *) sdyn->contents;
4551          dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4552    
4553          for (; dyncon < dynconend; dyncon++)
4554            {
4555              Elf_Internal_Dyn dyn;
4556              const char * name;
4557              asection * s;
4558    
4559              bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4560    
4561              switch (dyn.d_tag)
4562                {
4563                default:
4564                  break;
4565    
4566                case DT_PLTGOT:
4567                  name = ".got";
4568                  goto get_vma;
4569    
4570                case DT_JMPREL:
4571                  name = ".rela.plt";
4572                get_vma:
4573                  s = bfd_get_section_by_name (output_bfd, name);
4574                  BFD_ASSERT (s != NULL);
4575                  dyn.d_un.d_ptr = s->vma;
4576                  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4577                  break;
4578    
4579                case DT_PLTRELSZ:
4580                  s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4581                  BFD_ASSERT (s != NULL);
4582                  dyn.d_un.d_val = s->size;
4583                  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4584                  break;
4585    
4586                case DT_RELASZ:
4587                  /* My reading of the SVR4 ABI indicates that the
4588                     procedure linkage table relocs (DT_JMPREL) should be
4589                     included in the overall relocs (DT_RELA).  This is
4590                     what Solaris does.  However, UnixWare can not handle
4591                     that case.  Therefore, we override the DT_RELASZ entry
4592                     here to make it not include the JMPREL relocs.  Since
4593                     the linker script arranges for .rela.plt to follow all
4594                     other relocation sections, we don't have to worry
4595                     about changing the DT_RELA entry.  */
4596                  s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4597                  if (s != NULL)
4598                    dyn.d_un.d_val -= s->size;
4599                  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4600                  break;
4601                }
4602            }
4603    
4604          /* Fill in the first entry in the procedure linkage table.  */
4605          splt = bfd_get_section_by_name (dynobj, ".plt");
4606          if (splt && splt->size > 0)
4607            {
4608              if (info->shared)
4609                {
4610                  memcpy (splt->contents, elf_mn10300_pic_plt_entry,
4611                          elf_mn10300_sizeof_plt (info));
4612                }
4613              else
4614                {
4615                  memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
4616                  bfd_put_32 (output_bfd,
4617                              sgot->output_section->vma + sgot->output_offset + 4,
4618                              splt->contents + elf_mn10300_plt0_gotid_offset (info));
4619                  bfd_put_32 (output_bfd,
4620                              sgot->output_section->vma + sgot->output_offset + 8,
4621                              splt->contents + elf_mn10300_plt0_linker_offset (info));
4622                }
4623    
4624              /* UnixWare sets the entsize of .plt to 4, although that doesn't
4625                 really seem like the right value.  */
4626              elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
4627            }
4628        }
4629    
4630      /* Fill in the first three entries in the global offset table.  */
4631      if (sgot->size > 0)
4632        {
4633          if (sdyn == NULL)
4634            bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4635          else
4636            bfd_put_32 (output_bfd,
4637                        sdyn->output_section->vma + sdyn->output_offset,
4638                        sgot->contents);
4639          bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4640          bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4641        }
4642    
4643      elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4644    
4645      return TRUE;
4646    }
4647    
4648    /* Classify relocation types, such that combreloc can sort them
4649       properly.  */
4650    
4651    static enum elf_reloc_type_class
4652    _bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela *rela)
4653    {
4654      switch ((int) ELF32_R_TYPE (rela->r_info))
4655        {
4656        case R_MN10300_RELATIVE:
4657          return reloc_class_relative;
4658        case R_MN10300_JMP_SLOT:
4659          return reloc_class_plt;
4660        case R_MN10300_COPY:
4661          return reloc_class_copy;
4662        default:
4663          return reloc_class_normal;
4664        }
4665    }
4666    
4667    #ifndef ELF_ARCH
4668  #define TARGET_LITTLE_SYM       bfd_elf32_mn10300_vec  #define TARGET_LITTLE_SYM       bfd_elf32_mn10300_vec
4669  #define TARGET_LITTLE_NAME      "elf32-mn10300"  #define TARGET_LITTLE_NAME      "elf32-mn10300"
4670  #define ELF_ARCH                bfd_arch_mn10300  #define ELF_ARCH                bfd_arch_mn10300
4671  #define ELF_MACHINE_CODE        EM_MN10300  #define ELF_MACHINE_CODE        EM_MN10300
4672  #define ELF_MACHINE_ALT1        EM_CYGNUS_MN10300  #define ELF_MACHINE_ALT1        EM_CYGNUS_MN10300
4673  #define ELF_MAXPAGESIZE         0x1000  #define ELF_MAXPAGESIZE         0x1000
4674    #endif
4675    
4676  #define elf_info_to_howto               mn10300_info_to_howto  #define elf_info_to_howto               mn10300_info_to_howto
4677  #define elf_info_to_howto_rel           0  #define elf_info_to_howto_rel           0
# Line 2835  _bfd_mn10300_elf_merge_private_bfd_data Line 4688  _bfd_mn10300_elf_merge_private_bfd_data
4688  #define bfd_elf32_bfd_link_hash_table_free \  #define bfd_elf32_bfd_link_hash_table_free \
4689                                  elf32_mn10300_link_hash_table_free                                  elf32_mn10300_link_hash_table_free
4690    
4691    #ifndef elf_symbol_leading_char
4692  #define elf_symbol_leading_char '_'  #define elf_symbol_leading_char '_'
4693    #endif
4694    
4695  /* So we can set bits in e_flags.  */  /* So we can set bits in e_flags.  */
4696  #define elf_backend_final_write_processing \  #define elf_backend_final_write_processing \
# Line 2845  _bfd_mn10300_elf_merge_private_bfd_data Line 4700  _bfd_mn10300_elf_merge_private_bfd_data
4700  #define bfd_elf32_bfd_merge_private_bfd_data \  #define bfd_elf32_bfd_merge_private_bfd_data \
4701                                          _bfd_mn10300_elf_merge_private_bfd_data                                          _bfd_mn10300_elf_merge_private_bfd_data
4702    
4703    #define elf_backend_can_gc_sections     1
4704    #define elf_backend_create_dynamic_sections \
4705      _bfd_mn10300_elf_create_dynamic_sections
4706    #define elf_backend_adjust_dynamic_symbol \
4707      _bfd_mn10300_elf_adjust_dynamic_symbol
4708    #define elf_backend_size_dynamic_sections \
4709      _bfd_mn10300_elf_size_dynamic_sections
4710    #define elf_backend_finish_dynamic_symbol \
4711      _bfd_mn10300_elf_finish_dynamic_symbol
4712    #define elf_backend_finish_dynamic_sections \
4713      _bfd_mn10300_elf_finish_dynamic_sections
4714    
4715    #define elf_backend_reloc_type_class \
4716      _bfd_mn10300_elf_reloc_type_class
4717    
4718    #define elf_backend_want_got_plt        1
4719    #define elf_backend_plt_readonly        1
4720    #define elf_backend_want_plt_sym        0
4721    #define elf_backend_got_header_size     12
4722    
4723  #include "elf32-target.h"  #include "elf32-target.h"

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

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