xref: /openbsd/gnu/usr.bin/binutils/bfd/elf32-m88k.c (revision f6aab3d8)
1 /* Motorola 88k series support for 32-bit ELF
2    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3    2004 Free Software Foundation, Inc.
4 
5    This file is part of BFD, the Binary File Descriptor library.
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20 
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "bfdlink.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf/m88k.h"
27 
28 static reloc_howto_type *reloc_type_lookup
29   PARAMS ((bfd *, bfd_reloc_code_real_type));
30 static void rtype_to_howto
31   PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
32 static struct bfd_hash_entry *elf_m88k_link_hash_newfunc
33   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
34 static struct bfd_link_hash_table *elf_m88k_link_hash_table_create
35   PARAMS ((bfd *));
36 static bfd_boolean elf_m88k_check_relocs
37   PARAMS ((bfd *, struct bfd_link_info *, asection *,
38 	   const Elf_Internal_Rela *));
39 static asection *elf_m88k_gc_mark_hook
40   PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
41 	   struct elf_link_hash_entry *, Elf_Internal_Sym *));
42 static bfd_boolean elf_m88k_gc_sweep_hook
43   PARAMS ((bfd *, struct bfd_link_info *, asection *,
44 	   const Elf_Internal_Rela *));
45 static bfd_boolean elf_m88k_adjust_dynamic_symbol
46   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
47 static bfd_boolean elf_m88k_size_dynamic_sections
48   PARAMS ((bfd *, struct bfd_link_info *));
49 static bfd_boolean elf_m88k_discard_copies
50   PARAMS ((struct elf_link_hash_entry *, PTR));
51 static bfd_boolean elf_m88k_relocate_section
52   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
53 	   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
54 static bfd_boolean elf_m88k_finish_dynamic_symbol
55   PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
56 	   Elf_Internal_Sym *));
57 static bfd_boolean elf_m88k_finish_dynamic_sections
58   PARAMS ((bfd *, struct bfd_link_info *));
59 
60 static bfd_boolean elf32_m88k_set_private_flags
61   PARAMS ((bfd *, flagword));
62 static bfd_boolean elf32_m88k_merge_private_bfd_data
63   PARAMS ((bfd *, bfd *));
64 static bfd_boolean elf32_m88k_print_private_bfd_data
65   PARAMS ((bfd *, PTR));
66 static enum elf_reloc_type_class elf32_m88k_reloc_type_class
67   PARAMS ((const Elf_Internal_Rela *));
68 
69 #define UNHANDLED_HOWTO(C) \
70   HOWTO ((C), 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL, __STRING(C), \
71 	 FALSE, 0, 0, FALSE)
72 #define UNIMPLEMENTED_HOWTO \
73   HOWTO (R_88K_UNIMPLEMENTED, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL, \
74 	 "R_88K_UNIMPLEMENTED", FALSE, 0, 0, FALSE)
75 
76 static reloc_howto_type howto_table[] = {
77   HOWTO (R_88K_NONE,       0, 0, 0, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_NONE",      FALSE, 0, 0x00000000,FALSE),
78   UNHANDLED_HOWTO (R_88K_COPY),
79   UNHANDLED_HOWTO (R_88K_GOTP_ENT),
80   UNIMPLEMENTED_HOWTO,
81   HOWTO (R_88K_8,          0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_88K_8",         FALSE, 0, 0x000000ff,FALSE),
82   UNHANDLED_HOWTO (R_88K_8S),
83   UNIMPLEMENTED_HOWTO,
84   UNHANDLED_HOWTO (R_88K_16S),
85   HOWTO (R_88K_DISP16,     2, 2,16, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_88K_DISP16",      FALSE, 0, 0x0000ffff,TRUE),
86   UNIMPLEMENTED_HOWTO,
87   HOWTO (R_88K_DISP26,     2, 2,26, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_88K_DISP26",      FALSE, 0, 0x03ffffff,TRUE),
88   UNIMPLEMENTED_HOWTO,
89   UNIMPLEMENTED_HOWTO,
90   UNIMPLEMENTED_HOWTO,
91   HOWTO (R_88K_PLT_DISP26, 2, 2,26, TRUE, 0, complain_overflow_signed,   bfd_elf_generic_reloc, "R_88K_PLT_DISP26",  FALSE, 0, 0x03ffffff,TRUE),
92   UNIMPLEMENTED_HOWTO,
93   UNHANDLED_HOWTO (R_88K_BBASED_32),
94   UNHANDLED_HOWTO (R_88K_BBASED_32UA),
95   UNHANDLED_HOWTO (R_88K_BBASED_16H),
96   UNHANDLED_HOWTO (R_88K_BBASED_16L),
97   UNIMPLEMENTED_HOWTO,
98   UNIMPLEMENTED_HOWTO,
99   UNIMPLEMENTED_HOWTO,
100   UNIMPLEMENTED_HOWTO,
101   UNHANDLED_HOWTO (R_88K_ABDIFF_32),
102   UNHANDLED_HOWTO (R_88K_ABDIFF_32UA),
103   HOWTO (R_88K_ABDIFF_16H, 16, 1,16, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_ABDIFF_16H", FALSE, 0, 0x0000ffff,FALSE),
104   HOWTO (R_88K_ABDIFF_16L, 0,  1,16, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_ABDIFF_16L", FALSE, 0, 0x0000ffff,FALSE),
105   UNHANDLED_HOWTO (R_88K_ABDIFF_16),
106   UNIMPLEMENTED_HOWTO,
107   UNIMPLEMENTED_HOWTO,
108   UNIMPLEMENTED_HOWTO,
109   HOWTO (R_88K_32,         0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_88K_32",        FALSE, 0, 0xffffffff,FALSE),
110   UNHANDLED_HOWTO (R_88K_32UA),
111   HOWTO (R_88K_16H,       16, 1,16, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_16H",      FALSE, 0, 0x0000ffff,FALSE),
112   HOWTO (R_88K_16L,        0, 1,16, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_16L",      FALSE, 0, 0x0000ffff,FALSE),
113   HOWTO (R_88K_16,         0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_88K_16",        FALSE, 0, 0x0000ffff,FALSE),
114   UNIMPLEMENTED_HOWTO,
115   UNIMPLEMENTED_HOWTO,
116   UNIMPLEMENTED_HOWTO,
117   UNHANDLED_HOWTO (R_88K_GOT_32),
118   UNHANDLED_HOWTO (R_88K_GOT_32UA),
119   HOWTO (R_88K_GOT_16H,    16, 1,16, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_GOT_16H",    FALSE, 0, 0x0000ffff,FALSE),
120   HOWTO (R_88K_GOT_16L,    0,  1,16, FALSE,0, complain_overflow_dont,     bfd_elf_generic_reloc, "R_88K_GOT_16L",    FALSE, 0, 0x0000ffff,FALSE),
121   UNHANDLED_HOWTO (R_88K_GOT_16),
122   UNIMPLEMENTED_HOWTO,
123   UNIMPLEMENTED_HOWTO,
124   UNIMPLEMENTED_HOWTO,
125   UNHANDLED_HOWTO (R_88K_GOTP_32),
126   UNHANDLED_HOWTO (R_88K_GOTP_32UA),
127   UNHANDLED_HOWTO (R_88K_GOTP_16H),
128   UNHANDLED_HOWTO (R_88K_GOTP_16L),
129   UNHANDLED_HOWTO (R_88K_GOTP_16),
130   UNIMPLEMENTED_HOWTO,
131   UNIMPLEMENTED_HOWTO,
132   UNIMPLEMENTED_HOWTO,
133   HOWTO (R_88K_PLT_32,     0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_88K_PLT_32",    FALSE, 0, 0xffffffff,FALSE),
134   UNHANDLED_HOWTO (R_88K_PLT_32UA),
135   UNHANDLED_HOWTO (R_88K_PLT_16H),
136   UNHANDLED_HOWTO (R_88K_PLT_16L),
137   UNHANDLED_HOWTO (R_88K_PLT_16),
138   UNIMPLEMENTED_HOWTO,
139   UNIMPLEMENTED_HOWTO,
140   UNIMPLEMENTED_HOWTO,
141   UNHANDLED_HOWTO (R_88K_ABREL_32),
142   UNHANDLED_HOWTO (R_88K_ABREL_32UA),
143   UNHANDLED_HOWTO (R_88K_ABREL_16H),
144   UNHANDLED_HOWTO (R_88K_ABREL_16L),
145   UNHANDLED_HOWTO (R_88K_ABREL_16),
146   UNIMPLEMENTED_HOWTO,
147   UNIMPLEMENTED_HOWTO,
148   UNIMPLEMENTED_HOWTO,
149   UNHANDLED_HOWTO (R_88K_GOT_ABREL_32),
150   UNHANDLED_HOWTO (R_88K_GOT_ABREL_32UA),
151   UNHANDLED_HOWTO (R_88K_GOT_ABREL_16H),
152   UNHANDLED_HOWTO (R_88K_GOT_ABREL_16L),
153   UNHANDLED_HOWTO (R_88K_GOT_ABREL_16),
154   UNIMPLEMENTED_HOWTO,
155   UNIMPLEMENTED_HOWTO,
156   UNIMPLEMENTED_HOWTO,
157   UNHANDLED_HOWTO (R_88K_GOTP_ABREL_32),
158   UNHANDLED_HOWTO (R_88K_GOTP_ABREL_32UA),
159   UNHANDLED_HOWTO (R_88K_GOTP_ABREL_16H),
160   UNHANDLED_HOWTO (R_88K_GOTP_ABREL_16L),
161   UNHANDLED_HOWTO (R_88K_GOTP_ABREL_16),
162   UNIMPLEMENTED_HOWTO,
163   UNIMPLEMENTED_HOWTO,
164   UNIMPLEMENTED_HOWTO,
165   UNHANDLED_HOWTO (R_88K_PLT_ABREL_32),
166   UNHANDLED_HOWTO (R_88K_PLT_ABREL_32UA),
167   UNHANDLED_HOWTO (R_88K_PLT_ABREL_16H),
168   UNHANDLED_HOWTO (R_88K_PLT_ABREL_16L),
169   UNHANDLED_HOWTO (R_88K_PLT_ABREL_16),
170   UNIMPLEMENTED_HOWTO,
171   UNIMPLEMENTED_HOWTO,
172   UNIMPLEMENTED_HOWTO,
173   UNHANDLED_HOWTO (R_88K_SREL_32),
174   UNHANDLED_HOWTO (R_88K_SREL_32UA),
175   UNHANDLED_HOWTO (R_88K_SREL_16H),
176   UNHANDLED_HOWTO (R_88K_SREL_16L),
177   /* GNU extension to record C++ vtable hierarchy */
178   HOWTO (R_88K_GNU_VTINHERIT,0,2,0, FALSE,0, complain_overflow_dont,     NULL,                  "R_88K_GNU_VTINHERIT",FALSE,0,0,        FALSE),
179   /* GNU extension to record C++ vtable member usage */
180   HOWTO (R_88K_GNU_VTENTRY,0, 2, 0, FALSE,0, complain_overflow_dont,     _bfd_elf_rel_vtable_reloc_fn,"R_88K_GNU_VTENTRY",FALSE,0,0,    FALSE)
181 };
182 
183 static void
184 rtype_to_howto (abfd, cache_ptr, dst)
185      bfd *abfd ATTRIBUTE_UNUSED;
186      arelent *cache_ptr;
187      Elf_Internal_Rela *dst;
188 {
189   BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_88K_UNIMPLEMENTED);
190   cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
191 }
192 
193 #define elf_info_to_howto rtype_to_howto
194 
195 static const struct
196 {
197   bfd_reloc_code_real_type bfd_val;
198   int elf_val;
199 } reloc_map[] = {
200   { BFD_RELOC_NONE,           R_88K_NONE },
201   { BFD_RELOC_LO16,           R_88K_16L },
202   { BFD_RELOC_HI16,           R_88K_16H },
203   { BFD_RELOC_18_PCREL_S2,    R_88K_DISP16 },
204   { BFD_RELOC_28_PCREL_S2,    R_88K_DISP26 },
205   { BFD_RELOC_8,              R_88K_8 },
206   { BFD_RELOC_16,             R_88K_16 },
207   { BFD_RELOC_32,             R_88K_32 },
208 
209   { BFD_RELOC_LO16_BASEREL,   R_88K_ABDIFF_16L },
210   { BFD_RELOC_HI16_BASEREL,   R_88K_ABDIFF_16H },
211   { BFD_RELOC_LO16_GOTOFF,    R_88K_GOT_16L },
212   { BFD_RELOC_HI16_GOTOFF,    R_88K_GOT_16H },
213   { BFD_RELOC_32_PLTOFF,      R_88K_PLT_32 },
214   { BFD_RELOC_32_PLT_PCREL,   R_88K_PLT_DISP26 },
215 
216   { BFD_RELOC_VTABLE_INHERIT, R_88K_GNU_VTINHERIT },
217   { BFD_RELOC_VTABLE_ENTRY,   R_88K_GNU_VTENTRY }
218 };
219 
220 static reloc_howto_type *
221 reloc_type_lookup (abfd, code)
222      bfd *abfd ATTRIBUTE_UNUSED;
223      bfd_reloc_code_real_type code;
224 {
225   unsigned int i;
226   for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
227     {
228       if (reloc_map[i].bfd_val == code)
229 	return &howto_table[reloc_map[i].elf_val];
230     }
231   return 0;
232 }
233 
234 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
235 #define ELF_ARCH bfd_arch_m88k
236 
237 /* Functions for the m88k ELF linker.  */
238 
239 /* The name of the dynamic interpreter.  This is put in the .interp
240    section.  */
241 
242 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
243 
244 /* The size in bytes of an entry in the procedure linkage table.  */
245 
246 #define PLT_ENTRY_SIZE 24
247 
248 /* The size in bytes of the first entry in the procedure linkage table.  */
249 
250 #define PLT_ENTRY0_SIZE (3 * PLT_ENTRY_SIZE)
251 
252 /* The first entry in a procedure linkage table looks like this.  See
253    the SVR4 ABI m88k supplement to see how this works.  */
254 
255 static const bfd_byte elf_m88k_plt0_entry[PLT_ENTRY0_SIZE] =
256 {
257   0x67, 0xff, 0x00, 0x10, /*	subu r31, r31, 0x10             */
258   0x24, 0x3f, 0x00, 0x0c, /*	st   r1,  r31, 0x0c             */
259   0x25, 0x7f, 0x00, 0x08, /*	st   r11, r31, 0x08             */
260   0xc8, 0x00, 0x00, 0x01, /*	bsr  1f                         */
261   0x5d, 0x60, 0x00, 0x00, /* 1:	or.u r11, r0,  %hi16(1b#abdiff) */
262   0x59, 0x6b, 0x00, 0x00, /*	or   r11, r11, %lo16(1b#abdiff) */
263   0xf5, 0x6b, 0x60, 0x01, /*	addu r11, r11, r1               */
264   0x14, 0x2b, 0x00, 0x04, /*	ld   r1,  r11, 0x04             */
265   0x24, 0x3f, 0x00, 0x04, /*	st   r1,  r31, 0x04             */
266   0x15, 0x6b, 0x00, 0x08, /*	ld   r11, r11, 0x08             */
267   0x24, 0x1f, 0x00, 0x00, /*	st   r0,  r31, 0                */
268   0xf4, 0x00, 0xc8, 0x0b, /*	jsr  r11                        */
269   0xf4, 0x00, 0x58, 0x00, /*	nop                             */
270   0xf4, 0x00, 0x58, 0x00, /*	nop                             */
271   0xf4, 0x00, 0x58, 0x00, /*	nop                             */
272   0xf4, 0x00, 0x58, 0x00, /*	nop                             */
273   0xf4, 0x00, 0x58, 0x00, /*	nop                             */
274   0xf4, 0x00, 0x58, 0x00  /*	nop                             */
275 };
276 
277 /* Subsequent entries in a procedure linkage table look like this.  */
278 
279 static const bfd_byte elf_m88k_plt_entry[PLT_ENTRY_SIZE] =
280 {
281   0x5d, 0x60, 0x00, 0x00, /*	or.u r11, r0,  %hi16(symbol#gotrel) */
282   0x15, 0x6b, 0x00, 0x00, /*	ld   r11, r11, %lo16(symbol#gotrel) */
283   0xf4, 0x00, 0xc0, 0x0b, /*	jmp  r11                            */
284   0x5d, 0x60, 0x00, 0x00, /* 1:	or.u r11, r0,  %hi16(.rela offset)  */
285   0x59, 0x6b, 0x00, 0x00, /*	or   r11, r11, %lo16(.rela offset)  */
286   0xc0, 0x00, 0x00, 0x00  /*	br   resolver                       */
287 };
288 
289 /* The m88k linker needs to keep track of the number of relocs that it
290    decides to copy in check_relocs for each symbol.  This is so that it
291    can discard PC relative relocs if it doesn't need them when linking
292    with -Bsymbolic.  We store the information in a field extending the
293    regular ELF linker hash table.  */
294 
295 /* This structure keeps track of the number of PC relative relocs we have
296    copied for a given symbol.  */
297 
298 struct elf_m88k_pcrel_relocs_copied
299 {
300   /* Next section.  */
301   struct elf_m88k_pcrel_relocs_copied *next;
302   /* A section in dynobj.  */
303   asection *section;
304   /* Number of relocs copied in this section.  */
305   bfd_size_type count;
306 };
307 
308 /* m88k ELF linker hash entry.  */
309 
310 struct elf_m88k_link_hash_entry
311 {
312   struct elf_link_hash_entry root;
313 
314   /* Number of PC relative relocs copied for this symbol.  */
315   struct elf_m88k_pcrel_relocs_copied *pcrel_relocs_copied;
316 };
317 
318 #define elf_m88k_hash_entry(ent) ((struct elf_m88k_link_hash_entry *) (ent))
319 
320 /* m88k ELF linker hash table.  */
321 
322 struct elf_m88k_link_hash_table
323 {
324   struct elf_link_hash_table root;
325 
326   /* Small local sym to section mapping cache.  */
327   struct sym_sec_cache sym_sec;
328 };
329 
330 /* Get the m88k ELF linker hash table from a link_info structure.  */
331 
332 #define elf_m88k_hash_table(p) \
333   ((struct elf_m88k_link_hash_table *) (p)->hash)
334 
335 /* Create an entry in an m88k ELF linker hash table.  */
336 
337 static struct bfd_hash_entry *
338 elf_m88k_link_hash_newfunc (entry, table, string)
339      struct bfd_hash_entry *entry;
340      struct bfd_hash_table *table;
341      const char *string;
342 {
343   struct bfd_hash_entry *ret = entry;
344 
345   /* Allocate the structure if it has not already been allocated by a
346      subclass.  */
347   if (ret == NULL)
348     ret = bfd_hash_allocate (table,
349 			     sizeof (struct elf_m88k_link_hash_entry));
350   if (ret == NULL)
351     return ret;
352 
353   /* Call the allocation method of the superclass.  */
354   ret = _bfd_elf_link_hash_newfunc (ret, table, string);
355   if (ret != NULL)
356     elf_m88k_hash_entry (ret)->pcrel_relocs_copied = NULL;
357 
358   return ret;
359 }
360 
361 /* Create an m88k ELF linker hash table.  */
362 
363 static struct bfd_link_hash_table *
364 elf_m88k_link_hash_table_create (abfd)
365      bfd *abfd;
366 {
367   struct elf_m88k_link_hash_table *ret;
368   bfd_size_type amt = sizeof (struct elf_m88k_link_hash_table);
369 
370   ret = (struct elf_m88k_link_hash_table *) bfd_alloc (abfd, amt);
371   if (ret == (struct elf_m88k_link_hash_table *) NULL)
372     return NULL;
373 
374   if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
375 				       elf_m88k_link_hash_newfunc))
376     {
377       free (ret);
378       return NULL;
379     }
380 
381   ret->sym_sec.abfd = NULL;
382 
383   return &ret->root.root;
384 }
385 
386 /* Keep m88k-specific flags in the ELF header.  */
387 static bfd_boolean
388 elf32_m88k_set_private_flags (abfd, flags)
389      bfd *abfd;
390      flagword flags;
391 {
392   elf_elfheader (abfd)->e_flags = flags;
393   elf_flags_init (abfd) = TRUE;
394   return TRUE;
395 }
396 
397 /* Merge backend specific data from an object file to the output
398    object file when linking.  */
399 static bfd_boolean
400 elf32_m88k_merge_private_bfd_data (ibfd, obfd)
401      bfd *ibfd;
402      bfd *obfd;
403 {
404   flagword out_flags;
405   flagword in_flags;
406 
407   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
408       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
409     return TRUE;
410 
411   in_flags  = elf_elfheader (ibfd)->e_flags;
412   out_flags = elf_elfheader (obfd)->e_flags;
413 
414   if (!elf_flags_init (obfd))
415     {
416       elf_flags_init (obfd) = TRUE;
417       elf_elfheader (obfd)->e_flags = in_flags;
418     }
419 
420   return TRUE;
421 }
422 
423 /* Display the flags field.  */
424 static bfd_boolean
425 elf32_m88k_print_private_bfd_data (abfd, ptr)
426      bfd *abfd;
427      PTR ptr;
428 {
429   FILE *file = (FILE *) ptr;
430 
431   BFD_ASSERT (abfd != NULL && ptr != NULL);
432 
433   /* Print normal ELF private data.  */
434   _bfd_elf_print_private_bfd_data (abfd, ptr);
435 
436   /* xgettext:c-format */
437   fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
438 
439   if (elf_elfheader (abfd)->e_flags & EF_NABI)
440     fprintf (file, _(" [not ABI]"));
441 
442   if (elf_elfheader (abfd)->e_flags & EF_M88110)
443     fprintf (file, _(" [m88110]"));
444 
445   fputc ('\n', file);
446 
447   return TRUE;
448 }
449 
450 /* Look through the relocs for a section during the first phase, and
451    allocate space in the global offset table or procedure linkage
452    table.  */
453 
454 static bfd_boolean
455 elf_m88k_check_relocs (abfd, info, sec, relocs)
456      bfd *abfd;
457      struct bfd_link_info *info;
458      asection *sec;
459      const Elf_Internal_Rela *relocs;
460 {
461   bfd *dynobj;
462   Elf_Internal_Shdr *symtab_hdr;
463   struct elf_link_hash_entry **sym_hashes;
464   bfd_signed_vma *local_got_refcounts;
465   const Elf_Internal_Rela *rel;
466   const Elf_Internal_Rela *rel_end;
467   asection *sgot;
468   asection *srelgot;
469   asection *sreloc;
470 
471   if (info->relocatable)
472     return TRUE;
473 
474   dynobj = elf_hash_table (info)->dynobj;
475   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
476   sym_hashes = elf_sym_hashes (abfd);
477   local_got_refcounts = elf_local_got_refcounts (abfd);
478 
479   sgot = NULL;
480   srelgot = NULL;
481   sreloc = NULL;
482 
483   rel_end = relocs + sec->reloc_count;
484   for (rel = relocs; rel < rel_end; rel++)
485     {
486       unsigned long r_symndx;
487       struct elf_link_hash_entry *h;
488 
489       r_symndx = ELF32_R_SYM (rel->r_info);
490 
491       if (r_symndx < symtab_hdr->sh_info)
492 	h = NULL;
493       else
494 	h = sym_hashes[r_symndx - symtab_hdr->sh_info];
495 
496       switch (ELF32_R_TYPE (rel->r_info))
497 	{
498 	case R_88K_GOT_16L:
499 	case R_88K_GOT_16H:
500 	  /* This symbol requires a global offset table entry.  */
501 
502 	  if (dynobj == NULL)
503 	    {
504 	      /* Create the .got section.  */
505 	      elf_hash_table (info)->dynobj = dynobj = abfd;
506 	      if (!_bfd_elf_create_got_section (dynobj, info))
507 		return FALSE;
508 	    }
509 
510 	  if (sgot == NULL)
511 	    {
512 	      sgot = bfd_get_section_by_name (dynobj, ".got");
513 	      BFD_ASSERT (sgot != NULL);
514 	    }
515 
516 	  if (srelgot == NULL
517 	      && (h != NULL || info->shared))
518 	    {
519 	      srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
520 	      if (srelgot == NULL)
521 		{
522 		  srelgot = bfd_make_section (dynobj, ".rela.got");
523 		  if (srelgot == NULL
524 		      || !bfd_set_section_flags (dynobj, srelgot,
525 						 (SEC_ALLOC
526 						  | SEC_LOAD
527 						  | SEC_HAS_CONTENTS
528 						  | SEC_IN_MEMORY
529 						  | SEC_LINKER_CREATED
530 						  | SEC_READONLY))
531 		      || !bfd_set_section_alignment (dynobj, srelgot, 2))
532 		    return FALSE;
533 		}
534 	    }
535 
536 	  if (h != NULL)
537 	    {
538 	      if (h->got.refcount == 0)
539 		{
540 		  /* Make sure this symbol is output as a dynamic symbol.  */
541 		  if (h->dynindx == -1
542 		      && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
543 		    {
544 		      if (!bfd_elf_link_record_dynamic_symbol (info, h))
545 			return FALSE;
546 		    }
547 
548 		  /* Allocate space in the .got section.  */
549 		  sgot->_raw_size += 4;
550 		  /* Allocate relocation space.  */
551 		  srelgot->_raw_size += sizeof (Elf32_External_Rela);
552 		}
553 	      h->got.refcount++;
554 	    }
555 	  else
556 	    {
557 	      /* This is a global offset table entry for a local symbol.  */
558 	      if (local_got_refcounts == NULL)
559 		{
560 		  bfd_size_type size;
561 
562 		  size = symtab_hdr->sh_info;
563 		  size *= sizeof (bfd_signed_vma);
564 		  local_got_refcounts = ((bfd_signed_vma *)
565 					 bfd_zalloc (abfd, size));
566 		  if (local_got_refcounts == NULL)
567 		    return FALSE;
568 		  elf_local_got_refcounts (abfd) = local_got_refcounts;
569 		}
570 	      if (local_got_refcounts[r_symndx] == 0)
571 		{
572 		  sgot->_raw_size += 4;
573 		  if (info->shared)
574 		    {
575 		      /* If we are generating a shared object, we need to
576 			 output a R_88K_BBASED reloc so that the dynamic
577 			 linker can adjust this GOT entry.  */
578 		      srelgot->_raw_size += sizeof (Elf32_External_Rela);
579 		    }
580 		}
581 	      local_got_refcounts[r_symndx]++;
582 	    }
583 	  break;
584 
585 	case R_88K_PLT_DISP26:
586 	  /* This symbol requires a procedure linkage table entry.  We
587 	     actually build the entry in adjust_dynamic_symbol,
588              because this might be a case of linking PIC code which is
589              never referenced by a dynamic object, in which case we
590              don't need to generate a procedure linkage table entry
591              after all.  */
592 
593 	  /* If this is a local symbol, we resolve it directly without
594 	     creating a procedure linkage table entry.  */
595 	  if (h == NULL)
596 	    continue;
597 
598 	  h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
599 	  h->plt.refcount++;
600 	  break;
601 
602 	case R_88K_PLT_32:
603 	  /* This symbol requires a procedure linkage table entry.  */
604 
605 	  if (h == NULL)
606 	    {
607 	      /* It does not make sense to have this relocation for a
608 		 local symbol.  FIXME: does it?  How to handle it if
609 		 it does make sense?  */
610 	      bfd_set_error (bfd_error_bad_value);
611 	      return FALSE;
612 	    }
613 
614 	  /* Make sure this symbol is output as a dynamic symbol.  */
615 	  if (h->dynindx == -1
616 	      && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
617 	    {
618 	      if (!bfd_elf_link_record_dynamic_symbol (info, h))
619 		return FALSE;
620 	    }
621 
622 	  h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
623 	  h->plt.refcount++;
624 	  break;
625 
626 	case R_88K_DISP16:
627 	case R_88K_DISP26:
628 	  /* If we are creating a shared library and this is not a local
629 	     symbol, we need to copy the reloc into the shared library.
630 	     However when linking with -Bsymbolic and this is a global
631 	     symbol which is defined in an object we are including in the
632 	     link (i.e., DEF_REGULAR is set), then we can resolve the
633 	     reloc directly.  At this point we have not seen all the input
634 	     files, so it is possible that DEF_REGULAR is not set now but
635 	     will be set later (it is never cleared).  We account for that
636 	     possibility below by storing information in the
637 	     pcrel_relocs_copied field of the hash table entry.  */
638 	  if (!(info->shared
639 		&& (sec->flags & SEC_ALLOC) != 0
640 		&& h != NULL
641 		&& (!info->symbolic
642 		    || h->root.type == bfd_link_hash_defweak
643 		    || (h->elf_link_hash_flags
644 			& ELF_LINK_HASH_DEF_REGULAR) == 0)))
645 	    {
646 	      if (h != NULL)
647 		{
648 		  /* Make sure a plt entry is created for this symbol if
649 		     it turns out to be a function defined by a dynamic
650 		     object.  */
651 		  h->plt.refcount++;
652 		}
653 	      break;
654 	    }
655 	  /* Fall through.  */
656 	case R_88K_32:
657 	case R_88K_16L:
658 	case R_88K_16H:
659 	  if (h != NULL)
660 	    {
661 	      /* Make sure a plt entry is created for this symbol if it
662 		 turns out to be a function defined by a dynamic object.  */
663 	      h->plt.refcount++;
664 	    }
665 
666 	  /* If we are creating a shared library, we need to copy the
667 	     reloc into the shared library.  */
668 	  if (info->shared
669 	      && (sec->flags & SEC_ALLOC) != 0)
670 	    {
671 	      /* When creating a shared object, we must copy these
672 		 reloc types into the output file.  We create a reloc
673 		 section in dynobj and make room for this reloc.  */
674 	      if (sreloc == NULL)
675 		{
676 		  const char *name;
677 
678 		  name = (bfd_elf_string_from_elf_section
679 			  (abfd,
680 			   elf_elfheader (abfd)->e_shstrndx,
681 			   elf_section_data (sec)->rel_hdr.sh_name));
682 		  if (name == NULL)
683 		    return FALSE;
684 
685 		  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
686 			      && strcmp (bfd_get_section_name (abfd, sec),
687 					 name + 5) == 0);
688 
689 		  sreloc = bfd_get_section_by_name (dynobj, name);
690 		  if (sreloc == NULL)
691 		    {
692 		      sreloc = bfd_make_section (dynobj, name);
693 		      if (sreloc == NULL
694 			  || !bfd_set_section_flags (dynobj, sreloc,
695 						     (SEC_ALLOC
696 						      | SEC_LOAD
697 						      | SEC_HAS_CONTENTS
698 						      | SEC_IN_MEMORY
699 						      | SEC_LINKER_CREATED
700 						      | SEC_READONLY))
701 			  || !bfd_set_section_alignment (dynobj, sreloc, 2))
702 			return FALSE;
703 		    }
704 		  elf_section_data (sec)->sreloc = sreloc;
705 		}
706 
707 	      if (sec->flags & SEC_READONLY
708 		  /* Don't set DF_TEXTREL yet for PC relative
709 		     relocations, they might be discarded later.  */
710 		  && !(ELF32_R_TYPE (rel->r_info) == R_88K_DISP16
711 		       || ELF32_R_TYPE (rel->r_info) == R_88K_DISP26))
712 		    info->flags |= DF_TEXTREL;
713 
714 	      sreloc->_raw_size += sizeof (Elf32_External_Rela);
715 
716 	      /* We count the number of PC relative relocations we have
717 		 entered for this symbol, so that we can discard them
718 		 again if, in the -Bsymbolic case, the symbol is later
719 		 defined by a regular object, or, in the normal shared
720 		 case, the symbol is forced to be local.  Note that this
721 		 function is only called if we are using an m88kelf linker
722 		 hash table, which means that h is really a pointer to an
723 		 elf_m88k_link_hash_entry.  */
724 	      if (ELF32_R_TYPE (rel->r_info) == R_88K_DISP16
725 		  || ELF32_R_TYPE (rel->r_info) == R_88K_DISP26)
726 		{
727 		  struct elf_m88k_pcrel_relocs_copied *p;
728 		  struct elf_m88k_pcrel_relocs_copied **head;
729 
730 		  if (h != NULL)
731 		    {
732 		      struct elf_m88k_link_hash_entry *eh
733 			= elf_m88k_hash_entry (h);
734 		      head = &eh->pcrel_relocs_copied;
735 		    }
736 		  else
737 		    {
738 		      asection *s;
739 		      s = (bfd_section_from_r_symndx
740 			   (abfd, &elf_m88k_hash_table (info)->sym_sec,
741 			    sec, r_symndx));
742 		      if (s == NULL)
743 			return FALSE;
744 
745 		      head = ((struct elf_m88k_pcrel_relocs_copied **)
746 			      &elf_section_data (s)->local_dynrel);
747 		    }
748 
749 		  for (p = *head; p != NULL; p = p->next)
750 		    if (p->section == sreloc)
751 		      break;
752 
753 		  if (p == NULL)
754 		    {
755 		      p = ((struct elf_m88k_pcrel_relocs_copied *)
756 			   bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
757 		      if (p == NULL)
758 			return FALSE;
759 		      p->next = *head;
760 		      *head = p;
761 		      p->section = sreloc;
762 		      p->count = 0;
763 		    }
764 
765 		  ++p->count;
766 		}
767 	    }
768 
769 	  break;
770 
771 	  /* This relocation describes the C++ object vtable hierarchy.
772 	     Reconstruct it for later use during GC.  */
773 	case R_88K_GNU_VTINHERIT:
774 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
775 	    return FALSE;
776 	  break;
777 
778 	  /* This relocation describes which C++ vtable entries are actually
779 	     used.  Record for later use during GC.  */
780 	case R_88K_GNU_VTENTRY:
781 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
782 	    return FALSE;
783 	  break;
784 
785 	default:
786 	  break;
787 	}
788     }
789 
790   return TRUE;
791 }
792 
793 /* Return the section that should be marked against GC for a given
794    relocation.  */
795 
796 static asection *
797 elf_m88k_gc_mark_hook (sec, info, rel, h, sym)
798      asection *sec;
799      struct bfd_link_info *info ATTRIBUTE_UNUSED;
800      Elf_Internal_Rela *rel;
801      struct elf_link_hash_entry *h;
802      Elf_Internal_Sym *sym;
803 {
804   if (h != NULL)
805     {
806       switch (ELF32_R_TYPE (rel->r_info))
807 	{
808 	case R_88K_GNU_VTINHERIT:
809 	case R_88K_GNU_VTENTRY:
810 	  break;
811 
812 	default:
813 	  switch (h->root.type)
814 	    {
815 	    default:
816 	      break;
817 
818 	    case bfd_link_hash_defined:
819 	    case bfd_link_hash_defweak:
820 	      return h->root.u.def.section;
821 
822 	    case bfd_link_hash_common:
823 	      return h->root.u.c.p->section;
824 	    }
825 	}
826     }
827   else
828     return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
829 
830   return NULL;
831 }
832 
833 /* Update the got entry reference counts for the section being removed.  */
834 
835 static bfd_boolean
836 elf_m88k_gc_sweep_hook (abfd, info, sec, relocs)
837      bfd *abfd;
838      struct bfd_link_info *info;
839      asection *sec;
840      const Elf_Internal_Rela *relocs;
841 {
842   Elf_Internal_Shdr *symtab_hdr;
843   struct elf_link_hash_entry **sym_hashes;
844   bfd_signed_vma *local_got_refcounts;
845   const Elf_Internal_Rela *rel, *relend;
846   bfd *dynobj;
847   asection *sgot;
848   asection *srelgot;
849 
850   dynobj = elf_hash_table (info)->dynobj;
851   if (dynobj == NULL)
852     return TRUE;
853 
854   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
855   sym_hashes = elf_sym_hashes (abfd);
856   local_got_refcounts = elf_local_got_refcounts (abfd);
857 
858   sgot = bfd_get_section_by_name (dynobj, ".got");
859   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
860 
861   relend = relocs + sec->reloc_count;
862   for (rel = relocs; rel < relend; rel++)
863     {
864       unsigned long r_symndx;
865       struct elf_link_hash_entry *h;
866 
867       switch (ELF32_R_TYPE (rel->r_info))
868 	{
869 	case R_88K_GOT_16L:
870 	case R_88K_GOT_16H:
871 	  r_symndx = ELF32_R_SYM (rel->r_info);
872 	  if (r_symndx >= symtab_hdr->sh_info)
873 	    {
874 	      h = sym_hashes[r_symndx - symtab_hdr->sh_info];
875 	      if (h->got.refcount > 0)
876 		{
877 		  --h->got.refcount;
878 		  if (h->got.refcount == 0)
879 		    {
880 		      /* We don't need the .got entry any more.  */
881 		      sgot->_raw_size -= 4;
882 		      srelgot->_raw_size -= sizeof (Elf32_External_Rela);
883 		    }
884 		}
885 	    }
886 	  else if (local_got_refcounts != NULL)
887 	    {
888 	      if (local_got_refcounts[r_symndx] > 0)
889 		{
890 		  --local_got_refcounts[r_symndx];
891 		  if (local_got_refcounts[r_symndx] == 0)
892 		    {
893 		      /* We don't need the .got entry any more.  */
894 		      sgot->_raw_size -= 4;
895 		      if (info->shared)
896 			srelgot->_raw_size -= sizeof (Elf32_External_Rela);
897 		    }
898 		}
899 	    }
900 	  break;
901 
902 	case R_88K_PLT_DISP26:
903 	case R_88K_PLT_32:
904 	case R_88K_DISP16:
905 	case R_88K_DISP26:
906 	case R_88K_32:
907 	case R_88K_16L:
908 	case R_88K_16H:
909 	  r_symndx = ELF32_R_SYM (rel->r_info);
910 	  if (r_symndx >= symtab_hdr->sh_info)
911 	    {
912 	      h = sym_hashes[r_symndx - symtab_hdr->sh_info];
913 	      if (h->plt.refcount > 0)
914 		--h->plt.refcount;
915 	    }
916 	  break;
917 
918 	default:
919 	  break;
920 	}
921     }
922 
923   return TRUE;
924 }
925 
926 /* Adjust a symbol defined by a dynamic object and referenced by a
927    regular object.  The current definition is in some section of the
928    dynamic object, but we're not including those sections.  We have to
929    change the definition to something the rest of the link can
930    understand.  */
931 
932 static bfd_boolean
933 elf_m88k_adjust_dynamic_symbol (info, h)
934      struct bfd_link_info *info;
935      struct elf_link_hash_entry *h;
936 {
937   bfd *dynobj;
938   asection *s;
939   unsigned int power_of_two;
940 
941   dynobj = elf_hash_table (info)->dynobj;
942 
943   /* Make sure we know what is going on here.  */
944   BFD_ASSERT (dynobj != NULL
945 	      && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
946 		  || h->weakdef != NULL
947 		  || ((h->elf_link_hash_flags
948 		       & ELF_LINK_HASH_DEF_DYNAMIC) != 0
949 		      && (h->elf_link_hash_flags
950 			  & ELF_LINK_HASH_REF_REGULAR) != 0
951 		      && (h->elf_link_hash_flags
952 			  & ELF_LINK_HASH_DEF_REGULAR) == 0)));
953 
954   /* If this is a function, put it in the procedure linkage table.  We
955      will fill in the contents of the procedure linkage table later,
956      when we know the address of the .got section.  */
957   if (h->type == STT_FUNC
958       || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
959     {
960       if (! info->shared
961 	  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
962 	  && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
963 	  /* We must always create the plt entry if it was referenced
964 	     by a PLTxxO relocation.  In this case we already recorded
965 	     it as a dynamic symbol.  */
966 	  && h->dynindx == -1)
967 	{
968 	  /* This case can occur if we saw a PLTxx reloc in an input
969 	     file, but the symbol was never referred to by a dynamic
970 	     object.  In such a case, we don't actually need to build
971 	     a procedure linkage table, and we can just do a PCxx
972 	     reloc instead.  */
973 	  BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
974 	  h->plt.offset = (bfd_vma) -1;
975 	  return TRUE;
976 	}
977 
978       /* GC may have rendered this entry unused.  */
979       if (h->plt.refcount <= 0)
980 	{
981 	  h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
982 	  h->plt.offset = (bfd_vma) -1;
983 	  return TRUE;
984 	}
985 
986       /* Make sure this symbol is output as a dynamic symbol.  */
987       if (h->dynindx == -1
988 	  && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
989 	{
990 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
991 	    return FALSE;
992 	}
993 
994       s = bfd_get_section_by_name (dynobj, ".plt");
995       BFD_ASSERT (s != NULL);
996 
997       /* If this is the first .plt entry, make room for the special
998 	 first entry.  */
999       if (s->_raw_size == 0)
1000 	{
1001 	  s->_raw_size += PLT_ENTRY0_SIZE;
1002 	}
1003 
1004       /* If this symbol is not defined in a regular file, and we are
1005 	 not generating a shared library, then set the symbol to this
1006 	 location in the .plt.  This is required to make function
1007 	 pointers compare as equal between the normal executable and
1008 	 the shared library.  */
1009       if (!info->shared
1010 	  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1011 	{
1012 	  h->root.u.def.section = s;
1013 	  h->root.u.def.value = s->_raw_size;
1014 	}
1015 
1016       h->plt.offset = s->_raw_size;
1017 
1018       /* Make room for this entry.  */
1019       s->_raw_size += PLT_ENTRY_SIZE;
1020 
1021       /* We also need to make an entry in the .got.plt section, which
1022 	 will be placed in the .got section by the linker script.  */
1023       s = bfd_get_section_by_name (dynobj, ".got.plt");
1024       BFD_ASSERT (s != NULL);
1025       s->_raw_size += 4;
1026 
1027       /* We also need to make an entry in the .rela.plt section.  */
1028       s = bfd_get_section_by_name (dynobj, ".rela.plt");
1029       BFD_ASSERT (s != NULL);
1030       s->_raw_size += sizeof (Elf32_External_Rela);
1031 
1032       return TRUE;
1033     }
1034 
1035   /* Reinitialize the plt offset now that it is not used as a reference
1036      count any more.  */
1037   h->plt.offset = (bfd_vma) -1;
1038 
1039   /* If this is a weak symbol, and there is a real definition, the
1040      processor independent code will have arranged for us to see the
1041      real definition first, and we can just use the same value.  */
1042   if (h->weakdef != NULL)
1043     {
1044       BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1045 		  || h->weakdef->root.type == bfd_link_hash_defweak);
1046       h->root.u.def.section = h->weakdef->root.u.def.section;
1047       h->root.u.def.value = h->weakdef->root.u.def.value;
1048       return TRUE;
1049     }
1050 
1051   /* This is a reference to a symbol defined by a dynamic object which
1052      is not a function.  */
1053 
1054   /* If we are creating a shared library, we must presume that the
1055      only references to the symbol are via the global offset table.
1056      For such cases we need not do anything here; the relocations will
1057      be handled correctly by relocate_section.  */
1058   if (info->shared)
1059     return TRUE;
1060 
1061   /* We must allocate the symbol in our .dynbss section, which will
1062      become part of the .bss section of the executable.  There will be
1063      an entry for this symbol in the .dynsym section.  The dynamic
1064      object will contain position independent code, so all references
1065      from the dynamic object to this symbol will go through the global
1066      offset table.  The dynamic linker will use the .dynsym entry to
1067      determine the address it must put in the global offset table, so
1068      both the dynamic object and the regular object will refer to the
1069      same memory location for the variable.  */
1070 
1071   s = bfd_get_section_by_name (dynobj, ".dynbss");
1072   BFD_ASSERT (s != NULL);
1073 
1074   /* We must generate a R_88K_COPY reloc to tell the dynamic linker to
1075      copy the initial value out of the dynamic object and into the
1076      runtime process image.  We need to remember the offset into the
1077      .rela.bss section we are going to use.  */
1078   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1079     {
1080       asection *srel;
1081 
1082       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1083       BFD_ASSERT (srel != NULL);
1084       srel->_raw_size += sizeof (Elf32_External_Rela);
1085       h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1086     }
1087 
1088   /* We need to figure out the alignment required for this symbol.  I
1089      have no idea how other ELF linkers handle this.  */
1090   power_of_two = bfd_log2 (h->size);
1091   if (power_of_two > 3)
1092     power_of_two = 3;
1093 
1094   /* Apply the required alignment.  */
1095   s->_raw_size = BFD_ALIGN (s->_raw_size,
1096 			    (bfd_size_type) (1 << power_of_two));
1097   if (power_of_two > bfd_get_section_alignment (dynobj, s))
1098     {
1099       if (!bfd_set_section_alignment (dynobj, s, power_of_two))
1100 	return FALSE;
1101     }
1102 
1103   /* Define the symbol as being at this point in the section.  */
1104   h->root.u.def.section = s;
1105   h->root.u.def.value = s->_raw_size;
1106 
1107   /* Increment the section size to make room for the symbol.  */
1108   s->_raw_size += h->size;
1109 
1110   return TRUE;
1111 }
1112 
1113 /* Set the sizes of the dynamic sections.  */
1114 
1115 static bfd_boolean
1116 elf_m88k_size_dynamic_sections (output_bfd, info)
1117      bfd *output_bfd ATTRIBUTE_UNUSED;
1118      struct bfd_link_info *info;
1119 {
1120   bfd *dynobj;
1121   asection *s;
1122   bfd_boolean plt;
1123   bfd_boolean relocs;
1124 
1125   dynobj = elf_hash_table (info)->dynobj;
1126   BFD_ASSERT (dynobj != NULL);
1127 
1128   if (elf_hash_table (info)->dynamic_sections_created)
1129     {
1130       /* Set the contents of the .interp section to the interpreter.  */
1131       if (info->executable && !info->static_link)
1132 	{
1133 	  s = bfd_get_section_by_name (dynobj, ".interp");
1134 	  BFD_ASSERT (s != NULL);
1135 	  s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1136 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1137 	}
1138     }
1139   else
1140     {
1141       /* We may have created entries in the .rela.got section.
1142 	 However, if we are not creating the dynamic sections, we will
1143 	 not actually use these entries.  Reset the size of .rela.got,
1144 	 which will cause it to get stripped from the output file
1145 	 below.  */
1146       s = bfd_get_section_by_name (dynobj, ".rela.got");
1147       if (s != NULL)
1148 	s->_raw_size = 0;
1149     }
1150 
1151   /* If this is a -Bsymbolic shared link, then we need to discard all
1152      PC relative relocs against symbols defined in a regular object.
1153      For the normal shared case we discard the PC relative relocs
1154      against symbols that have become local due to visibility changes.
1155      We allocated space for them in the check_relocs routine, but we
1156      will not fill them in in the relocate_section routine.  */
1157   if (info->shared)
1158     elf_link_hash_traverse (elf_hash_table (info),
1159 			    elf_m88k_discard_copies,
1160 			    (PTR) info);
1161 
1162   /* The check_relocs and adjust_dynamic_symbol entry points have
1163      determined the sizes of the various dynamic sections.  Allocate
1164      memory for them.  */
1165   plt = FALSE;
1166   relocs = FALSE;
1167   for (s = dynobj->sections; s != NULL; s = s->next)
1168     {
1169       const char *name;
1170       bfd_boolean strip;
1171 
1172       if ((s->flags & SEC_LINKER_CREATED) == 0)
1173 	continue;
1174 
1175       /* It's OK to base decisions on the section name, because none
1176 	 of the dynobj section names depend upon the input files.  */
1177       name = bfd_get_section_name (dynobj, s);
1178 
1179       strip = FALSE;
1180 
1181       if (strcmp (name, ".plt") == 0)
1182 	{
1183 	  if (s->_raw_size == 0)
1184 	    {
1185 	      /* Strip this section if we don't need it; see the
1186                  comment below.  */
1187 	      strip = TRUE;
1188 	    }
1189 	  else
1190 	    {
1191 	      /* Remember whether there is a PLT.  */
1192 	      plt = TRUE;
1193 	    }
1194 	}
1195       else if (strncmp (name, ".rela", 5) == 0)
1196 	{
1197 	  if (s->_raw_size == 0)
1198 	    {
1199 	      /* If we don't need this section, strip it from the
1200 		 output file.  This is mostly to handle .rela.bss and
1201 		 .rela.plt.  We must create both sections in
1202 		 create_dynamic_sections, because they must be created
1203 		 before the linker maps input sections to output
1204 		 sections.  The linker does that before
1205 		 adjust_dynamic_symbol is called, and it is that
1206 		 function which decides whether anything needs to go
1207 		 into these sections.  */
1208 	      strip = TRUE;
1209 	    }
1210 	  else
1211 	    {
1212 	      relocs = TRUE;
1213 
1214 	      /* We use the reloc_count field as a counter if we need
1215 		 to copy relocs into the output file.  */
1216 	      s->reloc_count = 0;
1217 	    }
1218 	}
1219       else if (strncmp (name, ".got", 4) != 0)
1220 	{
1221 	  /* It's not one of our sections, so don't allocate space.  */
1222 	  continue;
1223 	}
1224 
1225       if (strip)
1226 	{
1227 	  _bfd_strip_section_from_output (info, s);
1228 	  continue;
1229 	}
1230 
1231       /* Allocate memory for the section contents.  */
1232       /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
1233 	 Unused entries should be reclaimed before the section's contents
1234 	 are written out, but at the moment this does not happen.  Thus in
1235 	 order to prevent writing out garbage, we initialise the section's
1236 	 contents to zero.  */
1237       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1238       if (s->contents == NULL && s->_raw_size != 0)
1239 	return FALSE;
1240     }
1241 
1242   if (elf_hash_table (info)->dynamic_sections_created)
1243     {
1244       /* Add some entries to the .dynamic section.  We fill in the
1245 	 values later, in elf_m88k_finish_dynamic_sections, but we
1246 	 must add the entries now so that we get the correct size for
1247 	 the .dynamic section.  The DT_DEBUG entry is filled in by the
1248 	 dynamic linker and used by the debugger.  */
1249 #define add_dynamic_entry(TAG, VAL) \
1250   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1251 
1252       if (!info->shared)
1253 	{
1254 	  if (!add_dynamic_entry (DT_DEBUG, 0))
1255 	    return FALSE;
1256 	}
1257 
1258       if (plt)
1259 	{
1260 	  if (!add_dynamic_entry (DT_PLTGOT, 0)
1261 	      || !add_dynamic_entry (DT_PLTRELSZ, 0)
1262 	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1263 	      || !add_dynamic_entry (DT_JMPREL, 0)
1264 	      || !add_dynamic_entry (DT_88K_PLTSTART, 0)
1265 	      || !add_dynamic_entry (DT_88K_PLTEND, 0))
1266 	    return FALSE;
1267 	}
1268 
1269       if (relocs)
1270 	{
1271 	  if (!add_dynamic_entry (DT_RELA, 0)
1272 	      || !add_dynamic_entry (DT_RELASZ, 0)
1273 	      || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1274 	    return FALSE;
1275 	}
1276 
1277       if ((info->flags & DF_TEXTREL) != 0)
1278 	{
1279 	  if (!add_dynamic_entry (DT_TEXTREL, 0))
1280 	    return FALSE;
1281 	}
1282     }
1283 #undef add_dynamic_entry
1284 
1285   return TRUE;
1286 }
1287 
1288 /* This function is called via elf_link_hash_traverse if we are
1289    creating a shared object.  In the -Bsymbolic case it discards the
1290    space allocated to copy PC relative relocs against symbols which
1291    are defined in regular objects.  For the normal shared case, it
1292    discards space for pc-relative relocs that have become local due to
1293    symbol visibility changes.  We allocated space for them in the
1294    check_relocs routine, but we won't fill them in in the
1295    relocate_section routine.
1296 
1297    We also check whether any of the remaining relocations apply
1298    against a readonly section, and set the DF_TEXTREL flag in this
1299    case.  */
1300 
1301 static bfd_boolean
1302 elf_m88k_discard_copies (h, inf)
1303      struct elf_link_hash_entry *h;
1304      PTR inf;
1305 {
1306   struct bfd_link_info *info = (struct bfd_link_info *) inf;
1307   struct elf_m88k_pcrel_relocs_copied *s;
1308 
1309   if (h->root.type == bfd_link_hash_warning)
1310     h = (struct elf_link_hash_entry *) h->root.u.i.link;
1311 
1312   if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1313       || (!info->symbolic
1314 	  && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0))
1315     {
1316       if ((info->flags & DF_TEXTREL) == 0)
1317 	{
1318 	  /* Look for relocations against read-only sections.  */
1319 	  for (s = elf_m88k_hash_entry (h)->pcrel_relocs_copied;
1320 	       s != NULL;
1321 	       s = s->next)
1322 	    if ((s->section->flags & SEC_READONLY) != 0)
1323 	      {
1324 		info->flags |= DF_TEXTREL;
1325 		break;
1326 	      }
1327 	}
1328 
1329       return TRUE;
1330     }
1331 
1332   for (s = elf_m88k_hash_entry (h)->pcrel_relocs_copied;
1333        s != NULL;
1334        s = s->next)
1335     s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
1336 
1337   return TRUE;
1338 }
1339 
1340 /* Relocate an M88K ELF section.  */
1341 
1342 static bfd_boolean
1343 elf_m88k_relocate_section (output_bfd, info, input_bfd, input_section,
1344 			   contents, relocs, local_syms, local_sections)
1345      bfd *output_bfd;
1346      struct bfd_link_info *info;
1347      bfd *input_bfd;
1348      asection *input_section;
1349      bfd_byte *contents;
1350      Elf_Internal_Rela *relocs;
1351      Elf_Internal_Sym *local_syms;
1352      asection **local_sections;
1353 {
1354   bfd *dynobj;
1355   Elf_Internal_Shdr *symtab_hdr;
1356   struct elf_link_hash_entry **sym_hashes;
1357   bfd_vma *local_got_offsets;
1358   asection *sgot;
1359   asection *splt;
1360   asection *sreloc;
1361   Elf_Internal_Rela *rel;
1362   Elf_Internal_Rela *relend;
1363 
1364   if (info->relocatable)
1365     return TRUE;
1366 
1367   dynobj = elf_hash_table (info)->dynobj;
1368   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1369   sym_hashes = elf_sym_hashes (input_bfd);
1370   local_got_offsets = elf_local_got_offsets (input_bfd);
1371 
1372   sgot = NULL;
1373   splt = NULL;
1374   sreloc = NULL;
1375 
1376   rel = relocs;
1377   relend = relocs + input_section->reloc_count;
1378   for (; rel < relend; rel++)
1379     {
1380       int r_type;
1381       const char *sym_name;
1382       reloc_howto_type *howto;
1383       unsigned long r_symndx;
1384       struct elf_link_hash_entry *h;
1385       Elf_Internal_Sym *sym;
1386       asection *sec;
1387       bfd_vma relocation;
1388       bfd_boolean unresolved_reloc;
1389       bfd_reloc_status_type r;
1390 
1391       r_type = ELF32_R_TYPE (rel->r_info);
1392       if (r_type < 0 || r_type >= (int) R_88K_UNIMPLEMENTED)
1393 	{
1394 	  bfd_set_error (bfd_error_bad_value);
1395 	  return FALSE;
1396 	}
1397       howto = howto_table + r_type;
1398 
1399       r_symndx = ELF32_R_SYM (rel->r_info);
1400 
1401       h = NULL;
1402       sym = NULL;
1403       sec = NULL;
1404       unresolved_reloc = FALSE;
1405 
1406       if (r_symndx < symtab_hdr->sh_info)
1407 	{
1408 	  sym = local_syms + r_symndx;
1409 	  sec = local_sections[r_symndx];
1410 	  sym_name = bfd_elf_local_sym_name (input_bfd, sym);
1411 
1412 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1413 	}
1414       else
1415 	{
1416 	  bfd_boolean warned;
1417 
1418 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1419 				   r_symndx, symtab_hdr, sym_hashes,
1420 				   h, sec, relocation,
1421 				   unresolved_reloc, warned);
1422 
1423 	  sym_name = h->root.root.string;
1424 	}
1425 
1426       switch (r_type)
1427 	{
1428 	case R_88K_GOT_16L:
1429 	case R_88K_GOT_16H:
1430 	  /* Relocation is the offset of the entry for this symbol in
1431 	     the global offset table.  */
1432 	  {
1433 	    bfd_vma off;
1434 
1435 	    if (sgot == NULL)
1436 	      {
1437 		sgot = bfd_get_section_by_name (dynobj, ".got");
1438 		BFD_ASSERT (sgot != NULL);
1439 	      }
1440 
1441 	    if (h != NULL)
1442 	      {
1443 		bfd_boolean dyn;
1444 
1445 		off = h->got.offset;
1446 		BFD_ASSERT (off != (bfd_vma) -1);
1447 
1448 		dyn = elf_hash_table (info)->dynamic_sections_created;
1449 		if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
1450 		    || (info->shared
1451 			&& (info->symbolic
1452 			    || h->dynindx == -1
1453 			    || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
1454 			&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) != 0)
1455 		  {
1456 		    /* This is actually a static link, or it is a
1457 		       -Bsymbolic link and the symbol is defined
1458 		       locally, or the symbol was forced to be local
1459 		       because of a version file..  We must initialize
1460 		       this entry in the global offset table.  Since
1461 		       the offset must always be a multiple of 4, we
1462 		       use the least significant bit to record whether
1463 		       we have initialized it already.
1464 
1465 		       When doing a dynamic link, we create a .rela.got
1466 		       relocation entry to initialize the value.  This
1467 		       is done in the finish_dynamic_symbol routine.  */
1468 		    if ((off & 1) != 0)
1469 		      off &= ~1;
1470 		    else
1471 		      {
1472 			bfd_put_32 (output_bfd, relocation,
1473 				    sgot->contents + off);
1474 			h->got.offset |= 1;
1475 		      }
1476 		  }
1477 		else
1478 		  unresolved_reloc = FALSE;
1479 	      }
1480 	    else
1481 	      {
1482 		BFD_ASSERT (local_got_offsets != NULL
1483 			    && local_got_offsets[r_symndx] != (bfd_vma) -1);
1484 
1485 		off = local_got_offsets[r_symndx];
1486 
1487 		/* The offset must always be a multiple of 4.  We use
1488 		   the least significant bit to record whether we have
1489 		   already generated the necessary reloc.  */
1490 		if ((off & 1) != 0)
1491 		  off &= ~1;
1492 		else
1493 		  {
1494 		    bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1495 
1496 		    if (info->shared)
1497 		      {
1498 			asection *s;
1499 			Elf_Internal_Rela outrel;
1500 			bfd_byte *loc;
1501 
1502 			s = bfd_get_section_by_name (dynobj, ".rela.got");
1503 			BFD_ASSERT (s != NULL);
1504 
1505 			outrel.r_offset = (sgot->output_section->vma
1506 					   + sgot->output_offset
1507 					   + off);
1508 			outrel.r_info = ELF32_R_INFO (0, R_88K_BBASED_32);
1509 			outrel.r_addend = relocation;
1510 			loc = s->contents;
1511 			loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
1512 			bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1513 		      }
1514 
1515 		    local_got_offsets[r_symndx] |= 1;
1516 		  }
1517 	      }
1518 
1519 	    /* Addends on got relocations don't make much sense.
1520 	       x+off@got is actually x@got+off, and since the got is
1521 	       generated by a hash table traversal, the value in the
1522 	       got at entry m+n bears little relation to the entry m.  */
1523 	    if (rel->r_addend != 0)
1524 	      (*_bfd_error_handler)
1525 		(_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
1526 		 bfd_archive_filename (input_bfd),
1527 		 bfd_get_section_name (input_bfd, input_section),
1528 		 (long) rel->r_offset,
1529 		 howto->name,
1530 		 sym_name);
1531 
1532 	    relocation = sgot->output_offset + off;
1533 	  }
1534 	  break;
1535 
1536 	case R_88K_ABDIFF_16L:
1537 	case R_88K_ABDIFF_16H:
1538 	  /* Relocation is the offset from this symbol to the address of
1539 	     the global offset table.  */
1540 
1541 	  if (sgot == NULL)
1542 	    {
1543 	      sgot = bfd_get_section_by_name (dynobj, ".got");
1544 	      BFD_ASSERT (sgot != NULL);
1545 	    }
1546 
1547 	  relocation = sgot->output_section->vma
1548 		       - (input_section->output_section->vma
1549 			  + input_section->output_offset + rel->r_addend);
1550 	  rel->r_addend = 0;
1551 	  unresolved_reloc = FALSE;
1552 	  break;
1553 
1554 	case R_88K_PLT_DISP26:
1555 	  /* Relocation is to the entry for this symbol in the
1556 	     procedure linkage table.  */
1557 
1558 	  /* Resolve a PLTxx reloc against a local symbol directly,
1559 	     without using the procedure linkage table.  */
1560 	  if (h == NULL)
1561 	    break;
1562 
1563 	  if (h->plt.offset == (bfd_vma) -1
1564 	      || !elf_hash_table (info)->dynamic_sections_created)
1565 	    {
1566 	      /* We didn't make a PLT entry for this symbol.  This
1567 		 happens when statically linking PIC code, or when
1568 		 using -Bsymbolic.  */
1569 	      break;
1570 	    }
1571 
1572 	  if (splt == NULL)
1573 	    {
1574 	      splt = bfd_get_section_by_name (dynobj, ".plt");
1575 	      BFD_ASSERT (splt != NULL);
1576 	    }
1577 
1578 	  relocation = (splt->output_section->vma
1579 			+ splt->output_offset
1580 			+ h->plt.offset);
1581 	  unresolved_reloc = FALSE;
1582 	  break;
1583 
1584 	case R_88K_PLT_32:
1585 	  /* Relocation is the offset of the entry for this symbol in
1586 	     the procedure linkage table.  */
1587 	  BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
1588 
1589 	  if (splt == NULL)
1590 	    {
1591 	      splt = bfd_get_section_by_name (dynobj, ".plt");
1592 	      BFD_ASSERT (splt != NULL);
1593 	    }
1594 
1595 	  relocation = h->plt.offset;
1596 	  unresolved_reloc = FALSE;
1597 
1598 	  /* This relocation does not use the addend.  */
1599 	  rel->r_addend = 0;
1600 
1601 	  break;
1602 
1603 	case R_88K_DISP16:
1604 	case R_88K_DISP26:
1605 	  if (h == NULL
1606 	      || (info->shared
1607 		  && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1608 	    break;
1609 	  /* Fall through.  */
1610 	case R_88K_8:
1611 	case R_88K_16:
1612 	case R_88K_32:
1613 	case R_88K_16L:
1614 	case R_88K_16H:
1615 	  if (info->shared
1616 	      && r_symndx != 0
1617 	      && (input_section->flags & SEC_ALLOC) != 0
1618 	      && (h == NULL
1619 		  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1620 		  || h->root.type != bfd_link_hash_undefweak)
1621 	      && ((r_type != R_88K_DISP16
1622 		   && r_type != R_88K_DISP26)
1623 		  || (h != NULL
1624 		      && h->dynindx != -1
1625 		      && (!info->symbolic
1626 			  || (h->elf_link_hash_flags
1627 			      & ELF_LINK_HASH_DEF_REGULAR) == 0))))
1628 	    {
1629 	      Elf_Internal_Rela outrel;
1630 	      bfd_byte *loc;
1631 	      bfd_boolean skip, relocate;
1632 
1633 	      /* When generating a shared object, these relocations
1634 		 are copied into the output file to be resolved at run
1635 		 time.  */
1636 
1637 	      skip = FALSE;
1638 	      relocate = FALSE;
1639 
1640 	      outrel.r_offset =
1641 		_bfd_elf_section_offset (output_bfd, info, input_section,
1642 					 rel->r_offset);
1643 	      if (outrel.r_offset == (bfd_vma) -1)
1644 		skip = TRUE;
1645 	      else if (outrel.r_offset == (bfd_vma) -2)
1646 		skip = TRUE, relocate = TRUE;
1647 	      outrel.r_offset += (input_section->output_section->vma
1648 				  + input_section->output_offset);
1649 
1650 	      if (skip)
1651 		memset (&outrel, 0, sizeof outrel);
1652 	      else if (h != NULL
1653 		       && h->dynindx != -1
1654 		       && (r_type == R_88K_DISP16
1655 			   || r_type == R_88K_DISP26
1656 			   || !info->shared
1657 			   || !info->symbolic
1658 			   || (h->elf_link_hash_flags
1659 			       & ELF_LINK_HASH_DEF_REGULAR) == 0))
1660 		{
1661 		  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1662 		  outrel.r_addend = rel->r_addend;
1663 		}
1664 	      else
1665 		{
1666 		  /* This symbol is local, or marked to become local.  */
1667 		  if (r_type == R_88K_32)
1668 		    {
1669 		      relocate = TRUE;
1670 		      outrel.r_info = ELF32_R_INFO (0, R_88K_BBASED_32);
1671 		      outrel.r_addend = relocation + rel->r_addend;
1672 		    }
1673 		  else
1674 		    {
1675 		      long indx;
1676 
1677 		      if (bfd_is_abs_section (sec))
1678 			indx = 0;
1679 		      else if (sec == NULL || sec->owner == NULL)
1680 			{
1681 			  bfd_set_error (bfd_error_bad_value);
1682 			  return FALSE;
1683 			}
1684 		      else
1685 			{
1686 			  asection *osec;
1687 
1688 			  osec = sec->output_section;
1689 			  indx = elf_section_data (osec)->dynindx;
1690 			  BFD_ASSERT (indx > 0);
1691 			}
1692 
1693 		      outrel.r_info = ELF32_R_INFO (indx, r_type);
1694 		      outrel.r_addend = relocation + rel->r_addend;
1695 		    }
1696 		}
1697 
1698 	      sreloc = elf_section_data (input_section)->sreloc;
1699 	      if (sreloc == NULL)
1700 		abort ();
1701 
1702 	      loc = sreloc->contents;
1703 	      loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1704 	      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1705 
1706 	      /* This reloc will be computed at runtime, so there's no
1707                  need to do anything now, except for R_88K_32
1708                  relocations that have been turned into
1709                  R_88K_BBASED_32.  */
1710 	      if (!relocate)
1711 		continue;
1712 	    }
1713 
1714 	  break;
1715 
1716 	case R_88K_GNU_VTINHERIT:
1717 	case R_88K_GNU_VTENTRY:
1718 	  /* These are no-ops in the end.  */
1719 	  continue;
1720 
1721 	default:
1722 	  break;
1723 	}
1724 
1725       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
1726 	 because such sections are not SEC_ALLOC and thus ld.so will
1727 	 not process them.  */
1728       if (unresolved_reloc
1729 	  && !((input_section->flags & SEC_DEBUGGING) != 0
1730 	       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
1731 	{
1732 	  (*_bfd_error_handler)
1733 	    (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
1734 	     bfd_archive_filename (input_bfd),
1735 	     bfd_get_section_name (input_bfd, input_section),
1736 	     (long) rel->r_offset,
1737 	     howto->name,
1738 	     sym_name);
1739 	  return FALSE;
1740 	}
1741 
1742       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1743 				    contents, rel->r_offset,
1744 				    relocation, rel->r_addend);
1745 
1746       if (r != bfd_reloc_ok)
1747 	{
1748 	  if (sym_name == NULL)
1749 	    sym_name = "(null)";
1750 	  if (r == bfd_reloc_overflow)
1751 	    {
1752 	      if (!(info->callbacks->reloc_overflow
1753 		    (info, sym_name, howto->name, (bfd_vma) 0,
1754 		     input_bfd, input_section, rel->r_offset)))
1755 		return FALSE;
1756 	    }
1757 	  else
1758 	    {
1759 	      (*_bfd_error_handler)
1760 		(_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
1761 		 bfd_archive_filename (input_bfd),
1762 		 bfd_get_section_name (input_bfd, input_section),
1763 		 (long) rel->r_offset, howto->name, sym_name, (int) r);
1764 	      return FALSE;
1765 	    }
1766 	}
1767     }
1768 
1769   return TRUE;
1770 }
1771 
1772 /* Finish up dynamic symbol handling.  We set the contents of various
1773    dynamic sections here.  */
1774 
1775 static bfd_boolean
1776 elf_m88k_finish_dynamic_symbol (output_bfd, info, h, sym)
1777      bfd *output_bfd;
1778      struct bfd_link_info *info;
1779      struct elf_link_hash_entry *h;
1780      Elf_Internal_Sym *sym;
1781 {
1782   bfd *dynobj;
1783 
1784   dynobj = elf_hash_table (info)->dynobj;
1785 
1786   if (h->plt.offset != (bfd_vma) -1)
1787     {
1788       asection *splt;
1789       asection *sgot;
1790       asection *srela;
1791       bfd_vma plt_index;
1792       bfd_vma got_offset;
1793       bfd_vma dyn_offset;
1794       Elf_Internal_Rela rela;
1795       unsigned int br;
1796 
1797       /* This symbol has an entry in the procedure linkage table.  Set
1798 	 it up.  */
1799 
1800       BFD_ASSERT (h->dynindx != -1);
1801 
1802       splt = bfd_get_section_by_name (dynobj, ".plt");
1803       sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1804       srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1805       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1806 
1807       /* Get the index in the procedure linkage table which
1808 	 corresponds to this symbol.  This is the index of this symbol
1809 	 in all the symbols for which we are making plt entries.  The
1810 	 first entry in the procedure linkage table, spanning three
1811 	 regular entries, is reserved.  */
1812       plt_index = (h->plt.offset - PLT_ENTRY0_SIZE) / PLT_ENTRY_SIZE;
1813 
1814       /* Get the offset into the .got table of the entry that
1815 	 corresponds to this function.  Each .got entry is 4 bytes.
1816 	 The first three are reserved.  */
1817       got_offset = (plt_index + 3) * 4;
1818 
1819       /* Fill in the entry in the procedure linkage table.  */
1820       memcpy (splt->contents + h->plt.offset, elf_m88k_plt_entry,
1821 	      PLT_ENTRY_SIZE);
1822 
1823       dyn_offset = sgot->output_section->vma + sgot->output_offset + got_offset;
1824       bfd_put_16 (output_bfd, dyn_offset >> 16,
1825 		  splt->contents + h->plt.offset + 2);
1826       bfd_put_16 (output_bfd, dyn_offset & 0xffff,
1827 		  splt->contents + h->plt.offset + 6);
1828 
1829       dyn_offset = plt_index * sizeof (Elf32_External_Rela);
1830       bfd_put_16 (output_bfd, dyn_offset >> 16,
1831 		  splt->contents + h->plt.offset + 14);
1832       bfd_put_16 (output_bfd, dyn_offset & 0xffff,
1833 		  splt->contents + h->plt.offset + 18);
1834 
1835       br = bfd_get_32 (output_bfd, splt->contents + h->plt.offset + 20);
1836       br &= ~0x03ffffff;
1837       br |= 0x04000000 -  ((h->plt.offset + 20) >> 2);
1838       bfd_put_32 (output_bfd, br,
1839 		  splt->contents + h->plt.offset + 20);
1840 
1841       /* Fill in the entry in the global offset table.  */
1842       bfd_put_32 (output_bfd,
1843 		  (splt->output_section->vma
1844 		   + splt->output_offset
1845 		   + h->plt.offset
1846 		   + 12),
1847 		  sgot->contents + got_offset);
1848 
1849       /* Fill in the entry in the .rela.plt section.  */
1850       rela.r_offset = (sgot->output_section->vma
1851 		       + sgot->output_offset
1852 		       + got_offset);
1853       rela.r_info = ELF32_R_INFO (h->dynindx, R_88K_GOTP_ENT);
1854       rela.r_addend = splt->output_section->vma + h->plt.offset;
1855       bfd_elf32_swap_reloca_out (output_bfd, &rela,
1856 				 srela->contents
1857 				 + plt_index * sizeof (Elf32_External_Rela));
1858 
1859       if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1860 	{
1861 	  /* Mark the symbol as undefined, rather than as defined in
1862 	     the .plt section.  Leave the value alone.  */
1863 	  sym->st_shndx = SHN_UNDEF;
1864 	}
1865     }
1866 
1867   if (h->got.offset != (bfd_vma) -1)
1868     {
1869       asection *sgot;
1870       asection *srela;
1871       Elf_Internal_Rela rela;
1872       bfd_byte *loc;
1873 
1874       /* This symbol has an entry in the global offset table.  Set it
1875 	 up.  */
1876 
1877       sgot = bfd_get_section_by_name (dynobj, ".got");
1878       srela = bfd_get_section_by_name (dynobj, ".rela.got");
1879       BFD_ASSERT (sgot != NULL && srela != NULL);
1880 
1881       rela.r_offset = (sgot->output_section->vma
1882 		       + sgot->output_offset
1883 		       + (h->got.offset &~ (bfd_vma) 1));
1884 
1885       /* If this is a -Bsymbolic link, and the symbol is defined
1886 	 locally, we just want to emit a BBASED reloc.  Likewise if
1887 	 the symbol was forced to be local because of a version file.
1888 	 The entry in the global offset table will already have been
1889 	 initialized in the relocate_section function.  */
1890       if (info->shared
1891 	  && (info->symbolic
1892 	      || h->dynindx == -1
1893 	      || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
1894 	  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1895 	{
1896 	  rela.r_info = ELF32_R_INFO (0, R_88K_BBASED_32);
1897 	  rela.r_addend = bfd_get_signed_32 (output_bfd,
1898 					     (sgot->contents
1899 					      + (h->got.offset &~ (bfd_vma) 1)));
1900 	}
1901       else
1902 	{
1903 	  bfd_put_32 (output_bfd, (bfd_vma) 0,
1904 		      sgot->contents + (h->got.offset &~ (bfd_vma) 1));
1905 	  rela.r_info = ELF32_R_INFO (h->dynindx, R_88K_32);
1906 	  rela.r_addend = 0;
1907 	}
1908 
1909       loc = srela->contents;
1910       loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
1911       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1912     }
1913 
1914   if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1915     {
1916       asection *s;
1917       Elf_Internal_Rela rela;
1918       bfd_byte *loc;
1919 
1920       /* This symbol needs a copy reloc.  Set it up.  */
1921 
1922       BFD_ASSERT (h->dynindx != -1
1923 		  && (h->root.type == bfd_link_hash_defined
1924 		      || h->root.type == bfd_link_hash_defweak));
1925 
1926       s = bfd_get_section_by_name (h->root.u.def.section->owner,
1927 				   ".rela.bss");
1928       BFD_ASSERT (s != NULL);
1929 
1930       rela.r_offset = (h->root.u.def.value
1931 		       + h->root.u.def.section->output_section->vma
1932 		       + h->root.u.def.section->output_offset);
1933       rela.r_info = ELF32_R_INFO (h->dynindx, R_88K_COPY);
1934       rela.r_addend = 0;
1935       loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
1936       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1937     }
1938 
1939   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
1940   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1941       || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1942     sym->st_shndx = SHN_ABS;
1943 
1944   return TRUE;
1945 }
1946 
1947 /* Finish up the dynamic sections.  */
1948 
1949 static bfd_boolean
1950 elf_m88k_finish_dynamic_sections (output_bfd, info)
1951      bfd *output_bfd;
1952      struct bfd_link_info *info;
1953 {
1954   bfd *dynobj;
1955   asection *sgot;
1956   asection *sdyn;
1957 
1958   dynobj = elf_hash_table (info)->dynobj;
1959 
1960   sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1961   BFD_ASSERT (sgot != NULL);
1962   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1963 
1964   if (elf_hash_table (info)->dynamic_sections_created)
1965     {
1966       asection *splt;
1967       Elf32_External_Dyn *dyncon, *dynconend;
1968 
1969       splt = bfd_get_section_by_name (dynobj, ".plt");
1970       BFD_ASSERT (splt != NULL && sdyn != NULL);
1971 
1972       dyncon = (Elf32_External_Dyn *) sdyn->contents;
1973       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1974       for (; dyncon < dynconend; dyncon++)
1975 	{
1976 	  Elf_Internal_Dyn dyn;
1977 	  const char *name;
1978 	  asection *s;
1979 
1980 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1981 
1982 	  switch (dyn.d_tag)
1983 	    {
1984 	    default:
1985 	      break;
1986 
1987 	    case DT_PLTGOT:
1988 	      name = ".got";
1989 	      goto get_vma;
1990 	    case DT_JMPREL:
1991 	      name = ".rela.plt";
1992 	    get_vma:
1993 	      s = bfd_get_section_by_name (output_bfd, name);
1994 	      BFD_ASSERT (s != NULL);
1995 	      dyn.d_un.d_ptr = s->vma;
1996 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1997 	      break;
1998 
1999 	    case DT_PLTRELSZ:
2000 	      s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2001 	      BFD_ASSERT (s != NULL);
2002 	      if (s->_cooked_size != 0)
2003 		dyn.d_un.d_val = s->_cooked_size;
2004 	      else
2005 		dyn.d_un.d_val = s->_raw_size;
2006 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2007 	      break;
2008 
2009 	    case DT_RELASZ:
2010 	      /* The procedure linkage table relocs (DT_JMPREL) should
2011 		 not be included in the overall relocs (DT_RELA).
2012 		 Therefore, we override the DT_RELASZ entry here to
2013 		 make it not include the JMPREL relocs.  Since the
2014 		 linker script arranges for .rela.plt to follow all
2015 		 other relocation sections, we don't have to worry
2016 		 about changing the DT_RELA entry.  */
2017 	      s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2018 	      if (s != NULL)
2019 		{
2020 		  if (s->_cooked_size != 0)
2021 		    dyn.d_un.d_val -= s->_cooked_size;
2022 		  else
2023 		    dyn.d_un.d_val -= s->_raw_size;
2024 		}
2025 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2026 	      break;
2027 
2028 	    case DT_88K_PLTSTART:
2029 	      name = ".plt";
2030 	      goto get_vma;
2031 	    case DT_88K_PLTEND:
2032 	      s = bfd_get_section_by_name (output_bfd, ".plt");
2033 	      BFD_ASSERT (s != NULL);
2034 	      dyn.d_un.d_ptr = s->vma + s->_raw_size;
2035 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2036 	      break;
2037 	    }
2038 	}
2039 
2040       /* Fill in the first entry in the procedure linkage table.  */
2041       if (splt->_raw_size > 0)
2042 	{
2043 	      memcpy (splt->contents, elf_m88k_plt0_entry, PLT_ENTRY0_SIZE);
2044 	      bfd_put_16 (output_bfd,
2045 		          (sgot->output_section->vma
2046 		           + sgot->output_offset
2047 		           - (splt->output_section->vma + 16)) >> 16,
2048 		          splt->contents + 18);
2049 	      bfd_put_16 (output_bfd,
2050 		          (sgot->output_section->vma
2051 		           + sgot->output_offset
2052 		           - (splt->output_section->vma + 16)) & 0xffff,
2053 		          splt->contents + 22);
2054               elf_section_data (splt->output_section)->this_hdr.sh_entsize
2055                = PLT_ENTRY0_SIZE;
2056 	}
2057     }
2058 
2059   /* Fill in the first three entries in the global offset table.  */
2060   if (sgot->_raw_size > 0)
2061     {
2062       if (sdyn == NULL)
2063 	bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2064       else
2065 	bfd_put_32 (output_bfd,
2066 		    sdyn->output_section->vma + sdyn->output_offset,
2067 		    sgot->contents);
2068       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
2069       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
2070     }
2071 
2072   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2073 
2074   return TRUE;
2075 }
2076 
2077 static enum elf_reloc_type_class
2078 elf32_m88k_reloc_type_class (rela)
2079      const Elf_Internal_Rela *rela;
2080 {
2081   switch ((int) ELF32_R_TYPE (rela->r_info))
2082     {
2083     case R_88K_BBASED_32:
2084     case R_88K_BBASED_16H:
2085     case R_88K_BBASED_16L:
2086       return reloc_class_relative;
2087     case R_88K_GOTP_ENT:
2088       return reloc_class_plt;
2089     case R_88K_COPY:
2090       return reloc_class_copy;
2091     default:
2092       return reloc_class_normal;
2093     }
2094 }
2095 
2096 #define TARGET_BIG_SYM			bfd_elf32_m88k_vec
2097 #define TARGET_BIG_NAME			"elf32-m88k"
2098 #define ELF_MACHINE_CODE		EM_88K
2099 #define ELF_MAXPAGESIZE			0x1000
2100 #define elf_backend_create_dynamic_sections \
2101 					_bfd_elf_create_dynamic_sections
2102 #define bfd_elf32_bfd_link_hash_table_create \
2103 					elf_m88k_link_hash_table_create
2104 #define bfd_elf32_bfd_final_link	bfd_elf_gc_common_final_link
2105 
2106 #define elf_backend_check_relocs	elf_m88k_check_relocs
2107 #define elf_backend_adjust_dynamic_symbol \
2108 					elf_m88k_adjust_dynamic_symbol
2109 #define elf_backend_size_dynamic_sections \
2110 					elf_m88k_size_dynamic_sections
2111 #define elf_backend_relocate_section	elf_m88k_relocate_section
2112 #define elf_backend_finish_dynamic_symbol \
2113 					elf_m88k_finish_dynamic_symbol
2114 #define elf_backend_finish_dynamic_sections \
2115 					elf_m88k_finish_dynamic_sections
2116 #define elf_backend_gc_mark_hook	elf_m88k_gc_mark_hook
2117 #define elf_backend_gc_sweep_hook	elf_m88k_gc_sweep_hook
2118 #define bfd_elf32_bfd_merge_private_bfd_data \
2119                                         elf32_m88k_merge_private_bfd_data
2120 #define bfd_elf32_bfd_set_private_flags \
2121                                         elf32_m88k_set_private_flags
2122 #define bfd_elf32_bfd_print_private_bfd_data \
2123                                         elf32_m88k_print_private_bfd_data
2124 #define elf_backend_reloc_type_class	elf32_m88k_reloc_type_class
2125 
2126 #define elf_backend_can_gc_sections	1
2127 #define elf_backend_can_refcount	1
2128 #define elf_backend_want_got_plt	1
2129 #define elf_backend_plt_readonly	1
2130 #define elf_backend_want_plt_sym	0
2131 #define elf_backend_got_header_size	12
2132 #define elf_backend_rela_normal		1
2133 
2134 #include "elf32-target.h"
2135