Index: mn10200/ChangeLog
[deliverable/binutils-gdb.git] / bfd / elf32-dlx.c
CommitLineData
d172d4ba 1/* DLX specific support for 32-bit ELF
eea6121a 2 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
d172d4ba
NC
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "bfd.h"
21#include "sysdep.h"
22#include "libbfd.h"
23#include "elf-bfd.h"
24#include "elf/dlx.h"
25
26int set_dlx_skip_hi16_flag PARAMS ((int));
27
b34976b6
AM
28static bfd_boolean elf32_dlx_check_relocs
29 PARAMS ((bfd *, struct bfd_link_info *, asection *,
30 const Elf_Internal_Rela *));
d172d4ba 31static void elf32_dlx_info_to_howto
947216bf 32 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
d172d4ba 33static void elf32_dlx_info_to_howto_rel
947216bf 34 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
d172d4ba
NC
35static bfd_reloc_status_type elf32_dlx_relocate16
36 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
37static bfd_reloc_status_type elf32_dlx_relocate26
38 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
39static reloc_howto_type *elf32_dlx_reloc_type_lookup
40 PARAMS ((bfd *, bfd_reloc_code_real_type));
41static bfd_reloc_status_type _bfd_dlx_elf_hi16_reloc
42 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
43static reloc_howto_type * dlx_rtype_to_howto
44 PARAMS ((unsigned int));
45
46
47#define USE_REL 1
48
49#define bfd_elf32_bfd_reloc_type_lookup elf32_dlx_reloc_type_lookup
50#define elf_info_to_howto elf32_dlx_info_to_howto
51#define elf_info_to_howto_rel elf32_dlx_info_to_howto_rel
52#define elf_backend_check_relocs elf32_dlx_check_relocs
53
54static reloc_howto_type dlx_elf_howto_table[]=
55 {
56 /* No relocation. */
57 HOWTO (R_DLX_NONE, /* type */
58 0, /* rightshift */
59 0, /* size (0 = byte, 1 = short, 2 = long) */
60 0, /* bitsize */
b34976b6 61 FALSE, /* pc_relative */
d172d4ba
NC
62 0, /* bitpos */
63 complain_overflow_dont,/* complain_on_overflow */
64 bfd_elf_generic_reloc, /* special_function */
65 "R_DLX_NONE", /* name */
b34976b6 66 FALSE, /* partial_inplace */
d172d4ba
NC
67 0, /* src_mask */
68 0, /* dst_mask */
b34976b6 69 FALSE), /* pcrel_offset */
d172d4ba
NC
70
71 /* 8 bit relocation. */
72 HOWTO (R_DLX_RELOC_8, /* type */
73 0, /* rightshift */
74 0, /* size (0 = byte, 1 = short, 2 = long) */
75 8, /* bitsize */
b34976b6 76 FALSE, /* pc_relative */
d172d4ba
NC
77 0, /* bitpos */
78 complain_overflow_dont,/* complain_on_overflow */
79 bfd_elf_generic_reloc, /* special_function */
80 "R_DLX_RELOC_8", /* name */
b34976b6 81 TRUE, /* partial_inplace */
d172d4ba
NC
82 0xff, /* src_mask */
83 0xff, /* dst_mask */
b34976b6 84 FALSE), /* pcrel_offset */
d172d4ba
NC
85
86 /* 16 bit relocation. */
87 HOWTO (R_DLX_RELOC_16, /* type */
88 0, /* rightshift */
89 1, /* size (0 = byte, 1 = short, 2 = long) */
90 16, /* bitsize */
b34976b6 91 FALSE, /* pc_relative */
d172d4ba
NC
92 0, /* bitpos */
93 complain_overflow_dont,/* complain_on_overflow */
94 bfd_elf_generic_reloc, /* special_function */
95 "R_DLX_RELOC_16", /* name */
b34976b6 96 TRUE, /* partial_inplace */
d172d4ba
NC
97 0xffff, /* src_mask */
98 0xffff, /* dst_mask */
b34976b6 99 FALSE), /* pcrel_offset */
d172d4ba
NC
100
101#if 0
102 /* 26 bit jump address. */
103 HOWTO (R_DLX_RELOC_26, /* type */
104 0, /* rightshift */
105 2, /* size (0 = byte, 1 = short, 2 = long) */
106 26, /* bitsize */
b34976b6 107 FALSE, /* pc_relative */
d172d4ba
NC
108 0, /* bitpos */
109 complain_overflow_dont,/* complain_on_overflow */
110 /* This needs complex overflow detection, because the upper four
111 bits must match the PC + 4. */
112 bfd_elf_generic_reloc, /* special_function */
113 "R_DLX_RELOC_26", /* name */
b34976b6 114 TRUE, /* partial_inplace */
d172d4ba
NC
115 0x3ffffff, /* src_mask */
116 0x3ffffff, /* dst_mask */
b34976b6 117 FALSE), /* pcrel_offset */
d172d4ba
NC
118#endif
119
120 /* 32 bit relocation. */
121 HOWTO (R_DLX_RELOC_32, /* type */
122 0, /* rightshift */
123 2, /* size (0 = byte, 1 = short, 2 = long) */
124 32, /* bitsize */
b34976b6 125 FALSE, /* pc_relative */
d172d4ba
NC
126 0, /* bitpos */
127 complain_overflow_dont,/* complain_on_overflow */
128 bfd_elf_generic_reloc, /* special_function */
129 "R_DLX_RELOC_32", /* name */
b34976b6 130 TRUE, /* partial_inplace */
d172d4ba
NC
131 0xffffffff, /* src_mask */
132 0xffffffff, /* dst_mask */
b34976b6 133 FALSE), /* pcrel_offset */
d172d4ba
NC
134
135 /* GNU extension to record C++ vtable hierarchy */
136 HOWTO (R_DLX_GNU_VTINHERIT, /* type */
137 0, /* rightshift */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
139 0, /* bitsize */
b34976b6 140 FALSE, /* pc_relative */
d172d4ba
NC
141 0, /* bitpos */
142 complain_overflow_dont,/* complain_on_overflow */
143 NULL, /* special_function */
144 "R_DLX_GNU_VTINHERIT", /* name */
b34976b6 145 FALSE, /* partial_inplace */
d172d4ba
NC
146 0, /* src_mask */
147 0, /* dst_mask */
b34976b6 148 FALSE), /* pcrel_offset */
d172d4ba
NC
149
150 /* GNU extension to record C++ vtable member usage */
151 HOWTO (R_DLX_GNU_VTENTRY, /* type */
152 0, /* rightshift */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
154 0, /* bitsize */
b34976b6 155 FALSE, /* pc_relative */
d172d4ba
NC
156 0, /* bitpos */
157 complain_overflow_dont,/* complain_on_overflow */
158 _bfd_elf_rel_vtable_reloc_fn,/* special_function */
159 "R_DLX_GNU_VTENTRY", /* name */
b34976b6 160 FALSE, /* partial_inplace */
d172d4ba
NC
161 0, /* src_mask */
162 0, /* dst_mask */
b34976b6 163 FALSE) /* pcrel_offset */
d172d4ba
NC
164 };
165
166/* 16 bit offset for pc-relative branches. */
167static reloc_howto_type elf_dlx_gnu_rel16_s2 =
168HOWTO (R_DLX_RELOC_16_PCREL, /* type */
169 0, /* rightshift */
170 1, /* size (0 = byte, 1 = short, 2 = long) */
171 16, /* bitsize */
b34976b6 172 TRUE, /* pc_relative */
d172d4ba
NC
173 0, /* bitpos */
174 complain_overflow_signed, /* complain_on_overflow */
175 elf32_dlx_relocate16, /* special_function */
176 "R_DLX_RELOC_16_PCREL",/* name */
b34976b6 177 TRUE, /* partial_inplace */
d172d4ba
NC
178 0xffff, /* src_mask */
179 0xffff, /* dst_mask */
b34976b6 180 TRUE); /* pcrel_offset */
d172d4ba
NC
181
182/* 26 bit offset for pc-relative branches. */
183static reloc_howto_type elf_dlx_gnu_rel26_s2 =
184HOWTO (R_DLX_RELOC_26_PCREL, /* type */
185 0, /* rightshift */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
187 26, /* bitsize */
b34976b6 188 TRUE, /* pc_relative */
d172d4ba
NC
189 0, /* bitpos */
190 complain_overflow_dont,/* complain_on_overflow */
191 elf32_dlx_relocate26, /* special_function */
192 "R_DLX_RELOC_26_PCREL",/* name */
b34976b6 193 TRUE, /* partial_inplace */
d172d4ba
NC
194 0xffff, /* src_mask */
195 0xffff, /* dst_mask */
b34976b6 196 TRUE); /* pcrel_offset */
d172d4ba
NC
197
198/* High 16 bits of symbol value. */
199static reloc_howto_type elf_dlx_reloc_16_hi =
200HOWTO (R_DLX_RELOC_16_HI, /* type */
201 16, /* rightshift */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
203 32, /* bitsize */
b34976b6 204 FALSE, /* pc_relative */
d172d4ba
NC
205 0, /* bitpos */
206 complain_overflow_dont, /* complain_on_overflow */
207 _bfd_dlx_elf_hi16_reloc,/* special_function */
208 "R_DLX_RELOC_16_HI", /* name */
b34976b6 209 TRUE, /* partial_inplace */
d172d4ba
NC
210 0xFFFF, /* src_mask */
211 0xffff, /* dst_mask */
b34976b6 212 FALSE); /* pcrel_offset */
d172d4ba
NC
213
214 /* Low 16 bits of symbol value. */
215static reloc_howto_type elf_dlx_reloc_16_lo =
216HOWTO (R_DLX_RELOC_16_LO, /* type */
217 0, /* rightshift */
218 1, /* size (0 = byte, 1 = short, 2 = long) */
219 16, /* bitsize */
b34976b6 220 FALSE, /* pc_relative */
d172d4ba
NC
221 0, /* bitpos */
222 complain_overflow_dont,/* complain_on_overflow */
223 bfd_elf_generic_reloc, /* special_function */
224 "R_DLX_RELOC_16_LO", /* name */
b34976b6 225 TRUE, /* partial_inplace */
d172d4ba
NC
226 0xffff, /* src_mask */
227 0xffff, /* dst_mask */
b34976b6 228 FALSE); /* pcrel_offset */
d172d4ba
NC
229
230
4cc11e76 231/* The gas default behavior is not to preform the %hi modifier so that the
d172d4ba
NC
232 GNU assembler can have the lower 16 bits offset placed in the insn, BUT
233 we do like the gas to indicate it is %hi reloc type so when we in the link
234 loader phase we can have the corrected hi16 vale replace the buggous lo16
235 value that was placed there by gas. */
236
237static int skip_dlx_elf_hi16_reloc = 0;
238
239int
240set_dlx_skip_hi16_flag (flag)
241 int flag;
242{
243 skip_dlx_elf_hi16_reloc = flag;
244 return flag;
245}
246
247static bfd_reloc_status_type
248_bfd_dlx_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
249 input_section, output_bfd, error_message)
250 bfd *abfd;
251 arelent *reloc_entry;
252 asymbol *symbol;
253 PTR data;
254 asection *input_section;
255 bfd *output_bfd;
256 char **error_message;
257{
258 bfd_reloc_status_type ret;
259 bfd_vma relocation;
eea6121a 260 bfd_size_type sz;
d172d4ba
NC
261
262 /* If the skip flag is set then we simply do the generic relocating, this
263 is more of a hack for dlx gas/gld, so we do not need to do the %hi/%lo
264 fixup like mips gld did. */
265#if 0
266 printf ("DEBUG: skip_dlx_elf_hi16_reloc = 0x%08x\n", skip_dlx_elf_hi16_reloc);
267#endif
268 if (skip_dlx_elf_hi16_reloc)
269 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
270 input_section, output_bfd, error_message);
271
272 /* If we're relocating, and this an external symbol, we don't want
273 to change anything. */
274 if (output_bfd != (bfd *) NULL
275 && (symbol->flags & BSF_SECTION_SYM) == 0
276 && reloc_entry->addend == 0)
277 {
278 reloc_entry->address += input_section->output_offset;
279 return bfd_reloc_ok;
280 }
281
282 ret = bfd_reloc_ok;
283
284 if (bfd_is_und_section (symbol->section)
285 && output_bfd == (bfd *) NULL)
286 ret = bfd_reloc_undefined;
287
288#if 0
289 {
290 unsigned long vallo, val;
291
292 vallo = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
293 printf ("DEBUG: The relocation address = 0x%08x\n", reloc_entry->address);
294 printf ("DEBUG: The symbol = 0x%08x\n", vallo);
295 printf ("DEBUG: The symbol name = %s\n", bfd_asymbol_name (symbol));
296 printf ("DEBUG: The symbol->value = 0x%08x\n", symbol->value);
297 printf ("DEBUG: The vma = 0x%08x\n", symbol->section->output_section->vma);
298 printf ("DEBUG: The output_offset = 0x%08x\n", symbol->section->output_offset);
299 printf ("DEBUG: The input_offset = 0x%08x\n", input_section->output_offset);
300 printf ("DEBUG: The input_vma = 0x%08x\n", input_section->vma);
301 printf ("DEBUG: The addend = 0x%08x\n", reloc_entry->addend);
302 }
303#endif
304
305 relocation = (bfd_is_com_section (symbol->section)) ? 0 : symbol->value;
306 relocation += symbol->section->output_section->vma;
307 relocation += symbol->section->output_offset;
308 relocation += reloc_entry->addend;
309 relocation += bfd_get_16 (abfd, (bfd_byte *)data + reloc_entry->address);
310
eea6121a
AM
311 sz = input_section->rawsize ? input_section->rawsize : input_section->size;
312 if (reloc_entry->address > sz)
d172d4ba
NC
313 return bfd_reloc_outofrange;
314
315#if 0
316 printf ("DEBUG: The finial relocation value = 0x%08x\n", relocation);
317#endif
318
319 bfd_put_16 (abfd, (short)((relocation >> 16) & 0xFFFF),
320 (bfd_byte *)data + reloc_entry->address);
321
322 return ret;
323}
324
1049f94e 325/* ELF relocs are against symbols. If we are producing relocatable
d172d4ba
NC
326 output, and the reloc is against an external symbol, and nothing
327 has given us any additional addend, the resulting reloc will also
328 be against the same symbol. In such a case, we don't want to
329 change anything about the way the reloc is handled, since it will
330 all be done at final link time. Rather than put special case code
331 into bfd_perform_relocation, all the reloc types use this howto
332 function. It just short circuits the reloc if producing
1049f94e 333 relocatable output against an external symbol. */
d172d4ba
NC
334
335static bfd_reloc_status_type
336elf32_dlx_relocate16 (abfd, reloc_entry, symbol, data,
337 input_section, output_bfd, error_message)
338 bfd *abfd;
339 arelent *reloc_entry;
340 asymbol *symbol;
341 PTR data;
342 asection *input_section;
343 bfd *output_bfd;
344 char **error_message ATTRIBUTE_UNUSED;
345{
346 unsigned long insn, vallo, allignment;
347 int val;
348
349 /* HACK: I think this first condition is necessary when producing
350 relocatable output. After the end of HACK, the code is identical
351 to bfd_elf_generic_reloc(). I would _guess_ the first change
352 belongs there rather than here. martindo 1998-10-23. */
353
354 if (skip_dlx_elf_hi16_reloc)
355 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
356 input_section, output_bfd, error_message);
357
358 /* Check undefined section and undefined symbols */
359 if (bfd_is_und_section (symbol->section)
360 && output_bfd == (bfd *) NULL)
361 return bfd_reloc_undefined;
362
363 /* Can not support a long jump to sections other then .text */
364 if (strcmp (input_section->name, symbol->section->output_section->name) != 0)
365 {
366 fprintf (stderr,
367 "BFD Link Error: branch (PC rel16) to section (%s) not supported\n",
368 symbol->section->output_section->name);
369 return bfd_reloc_undefined;
370 }
371
372 insn = bfd_get_32 (abfd, (bfd_byte *)data + reloc_entry->address);
373 allignment = 1 << (input_section->output_section->alignment_power - 1);
374 vallo = insn & 0x0000FFFF;
375
376 if (vallo & 0x8000)
377 vallo = ~(vallo | 0xFFFF0000) + 1;
378
379 /* vallo points to the vma of next instruction. */
380 vallo += (((unsigned long)(input_section->output_section->vma +
381 input_section->output_offset) +
382 allignment) & ~allignment);
383
384 /* val is the displacement (PC relative to next instruction). */
385 val = (symbol->section->output_offset +
386 symbol->section->output_section->vma +
387 symbol->value) - vallo;
388#if 0
389 printf ("DEBUG elf32_dlx_relocate: We are here\n");
390 printf ("DEBUG: The insn = 0x%08x\n", insn);
391 printf ("DEBUG: The vallo = 0x%08x\n", vallo);
392 printf ("DEBUG: The val = 0x%08x\n", val);
393 printf ("DEBUG: The symbol name = %s\n", bfd_asymbol_name (symbol));
394 printf ("DEBUG: The symbol->value = 0x%08x\n", symbol->value);
395 printf ("DEBUG: The vma = 0x%08x\n", symbol->section->output_section->vma);
396 printf ("DEBUG: The lma = 0x%08x\n", symbol->section->output_section->lma);
397 printf ("DEBUG: The alignment_power = 0x%08x\n", symbol->section->output_section->alignment_power);
398 printf ("DEBUG: The output_offset = 0x%08x\n", symbol->section->output_offset);
399 printf ("DEBUG: The addend = 0x%08x\n", reloc_entry->addend);
400#endif
401
402 if (abs ((int) val) > 0x00007FFF)
403 return bfd_reloc_outofrange;
404
405 insn = (insn & 0xFFFF0000) | (val & 0x0000FFFF);
406
407 bfd_put_32 (abfd, insn,
408 (bfd_byte *) data + reloc_entry->address);
409
410 return bfd_reloc_ok;
411}
412
413static bfd_reloc_status_type
414elf32_dlx_relocate26 (abfd, reloc_entry, symbol, data,
415 input_section, output_bfd, error_message)
416 bfd *abfd;
417 arelent *reloc_entry;
418 asymbol *symbol;
419 PTR data;
420 asection *input_section;
421 bfd *output_bfd;
422 char **error_message ATTRIBUTE_UNUSED;
423{
424 unsigned long insn, vallo, allignment;
425 int val;
426
427 /* HACK: I think this first condition is necessary when producing
428 relocatable output. After the end of HACK, the code is identical
429 to bfd_elf_generic_reloc(). I would _guess_ the first change
430 belongs there rather than here. martindo 1998-10-23. */
431
432 if (skip_dlx_elf_hi16_reloc)
433 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
434 input_section, output_bfd, error_message);
435
436 /* Check undefined section and undefined symbols. */
437 if (bfd_is_und_section (symbol->section)
438 && output_bfd == (bfd *) NULL)
439 return bfd_reloc_undefined;
440
441 /* Can not support a long jump to sections other then .text */
442 if (strcmp (input_section->name, symbol->section->output_section->name) != 0)
443 {
444 fprintf (stderr,
445 "BFD Link Error: jump (PC rel26) to section (%s) not supported\n",
446 symbol->section->output_section->name);
447 return bfd_reloc_undefined;
448 }
449
450 insn = bfd_get_32 (abfd, (bfd_byte *)data + reloc_entry->address);
451 allignment = 1 << (input_section->output_section->alignment_power - 1);
452 vallo = insn & 0x03FFFFFF;
453
454 if (vallo & 0x03000000)
455 vallo = ~(vallo | 0xFC000000) + 1;
456
457 /* vallo is the vma for the next instruction. */
458 vallo += (((unsigned long) (input_section->output_section->vma +
459 input_section->output_offset) +
460 allignment) & ~allignment);
461
462 /* val is the displacement (PC relative to next instruction). */
463 val = (symbol->section->output_offset +
464 symbol->section->output_section->vma + symbol->value)
465 - vallo;
466#if 0
467 printf ("DEBUG elf32_dlx_relocate26: We are here\n");
468 printf ("DEBUG: The insn = 0x%08x\n", insn);
469 printf ("DEBUG: The vallo = 0x%08x\n", vallo);
470 printf ("DEBUG: The val = 0x%08x\n", val);
471 printf ("DEBUG: The abs(val) = 0x%08x\n", abs (val));
472 printf ("DEBUG: The symbol name = %s\n", bfd_asymbol_name (symbol));
473 printf ("DEBUG: The symbol->value = 0x%08x\n", symbol->value);
474 printf ("DEBUG: The vma = 0x%08x\n", symbol->section->output_section->vma);
475 printf ("DEBUG: The output_offset = 0x%08x\n", symbol->section->output_offset);
476 printf ("DEBUG: The input_vma = 0x%08x\n", input_section->output_section->vma);
477 printf ("DEBUG: The input_offset = 0x%08x\n", input_section->output_offset);
478 printf ("DEBUG: The input_name = %s\n", input_section->name);
479 printf ("DEBUG: The addend = 0x%08x\n", reloc_entry->addend);
480#endif
481
482 if (abs ((int) val) > 0x01FFFFFF)
483 return bfd_reloc_outofrange;
484
485 insn = (insn & 0xFC000000) | (val & 0x03FFFFFF);
486 bfd_put_32 (abfd, insn,
487 (bfd_byte *) data + reloc_entry->address);
488
489 return bfd_reloc_ok;
490}
491
492/* A mapping from BFD reloc types to DLX ELF reloc types.
493 Stolen from elf32-mips.c.
cedb70c5 494
d172d4ba
NC
495 More about this table - for dlx elf relocation we do not really
496 need this table, if we have a rtype defined in this table will
497 caused tc_gen_relocate confused and die on us, but if we remove
4cc11e76 498 this table it will caused more problem, so for now simple solution
d172d4ba
NC
499 is to remove those entries which may cause problem. */
500struct elf_reloc_map
501{
502 bfd_reloc_code_real_type bfd_reloc_val;
503 enum elf_dlx_reloc_type elf_reloc_val;
504};
505
3f9c735e 506static const struct elf_reloc_map dlx_reloc_map[] =
d172d4ba
NC
507 {
508 { BFD_RELOC_NONE, R_DLX_NONE },
509 { BFD_RELOC_16, R_DLX_RELOC_16 },
510#if 0
511 { BFD_RELOC_DLX_JMP26, R_DLX_RELOC_26_PCREL },
512#endif
513 { BFD_RELOC_32, R_DLX_RELOC_32 },
514 { BFD_RELOC_DLX_HI16_S, R_DLX_RELOC_16_HI },
515 { BFD_RELOC_DLX_LO16, R_DLX_RELOC_16_LO },
516 { BFD_RELOC_VTABLE_INHERIT, R_DLX_GNU_VTINHERIT },
517 { BFD_RELOC_VTABLE_ENTRY, R_DLX_GNU_VTENTRY }
518 };
519
520
521/* Look through the relocs for a section during the first phase.
522 Since we don't do .gots or .plts, we just need to consider the
523 virtual table relocs for gc. */
524
b34976b6 525static bfd_boolean
d172d4ba
NC
526elf32_dlx_check_relocs (abfd, info, sec, relocs)
527 bfd *abfd;
528 struct bfd_link_info *info;
529 asection *sec;
530 const Elf_Internal_Rela *relocs;
531{
532 Elf_Internal_Shdr *symtab_hdr;
533 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
534 const Elf_Internal_Rela *rel;
535 const Elf_Internal_Rela *rel_end;
536
1049f94e 537 if (info->relocatable)
b34976b6 538 return TRUE;
d172d4ba
NC
539
540 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
541 sym_hashes = elf_sym_hashes (abfd);
542 sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
543 if (!elf_bad_symtab (abfd))
544 sym_hashes_end -= symtab_hdr->sh_info;
545
546 rel_end = relocs + sec->reloc_count;
547 for (rel = relocs; rel < rel_end; rel++)
548 {
549 struct elf_link_hash_entry *h;
550 unsigned long r_symndx;
551
552 r_symndx = ELF32_R_SYM (rel->r_info);
553 if (r_symndx < symtab_hdr->sh_info)
554 h = NULL;
555 else
556 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
557
558 switch (ELF32_R_TYPE (rel->r_info))
559 {
560 /* This relocation describes the C++ object vtable hierarchy.
561 Reconstruct it for later use during GC. */
562 case R_DLX_GNU_VTINHERIT:
c152c796 563 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
b34976b6 564 return FALSE;
d172d4ba
NC
565 break;
566
567 /* This relocation describes which C++ vtable entries are actually
568 used. Record for later use during GC. */
569 case R_DLX_GNU_VTENTRY:
c152c796 570 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
b34976b6 571 return FALSE;
d172d4ba
NC
572 break;
573 }
574 }
575
b34976b6 576 return TRUE;
d172d4ba
NC
577}
578
579/* Given a BFD reloc type, return a howto structure. */
580
581static reloc_howto_type *
582elf32_dlx_reloc_type_lookup (abfd, code)
583 bfd *abfd ATTRIBUTE_UNUSED;
584 bfd_reloc_code_real_type code;
585{
586 unsigned int i;
587
588 for (i = 0; i < sizeof (dlx_reloc_map) / sizeof (struct elf_reloc_map); i++)
589 if (dlx_reloc_map[i].bfd_reloc_val == code)
590 return &dlx_elf_howto_table[(int) dlx_reloc_map[i].elf_reloc_val];
591
592 switch (code)
593 {
594 default:
595 bfd_set_error (bfd_error_bad_value);
596 return NULL;
597 case BFD_RELOC_16_PCREL_S2:
598 return &elf_dlx_gnu_rel16_s2;
599 case BFD_RELOC_DLX_JMP26:
600 return &elf_dlx_gnu_rel26_s2;
601 case BFD_RELOC_HI16_S:
602 return &elf_dlx_reloc_16_hi;
603 case BFD_RELOC_LO16:
604 return &elf_dlx_reloc_16_lo;
605 }
606}
607
608static reloc_howto_type *
609dlx_rtype_to_howto (r_type)
610 unsigned int r_type;
611{
612 switch (r_type)
613 {
614 case R_DLX_RELOC_16_PCREL:
615 return & elf_dlx_gnu_rel16_s2;
616 break;
617 case R_DLX_RELOC_26_PCREL:
618 return & elf_dlx_gnu_rel26_s2;
619 break;
620 case R_DLX_RELOC_16_HI:
621 return & elf_dlx_reloc_16_hi;
622 break;
623 case R_DLX_RELOC_16_LO:
624 return & elf_dlx_reloc_16_lo;
625 break;
626
627 default:
628 BFD_ASSERT (r_type < (unsigned int) R_DLX_max);
629 return & dlx_elf_howto_table[r_type];
630 break;
631 }
632}
633
634static void
635elf32_dlx_info_to_howto (abfd, cache_ptr, dst)
636 bfd * abfd ATTRIBUTE_UNUSED;
637 arelent * cache_ptr ATTRIBUTE_UNUSED;
947216bf 638 Elf_Internal_Rela * dst ATTRIBUTE_UNUSED;
d172d4ba
NC
639{
640 abort ();
641}
642
643static void
644elf32_dlx_info_to_howto_rel (abfd, cache_ptr, dst)
645 bfd *abfd ATTRIBUTE_UNUSED;
646 arelent *cache_ptr;
947216bf 647 Elf_Internal_Rela *dst;
d172d4ba
NC
648{
649 unsigned int r_type;
650
651 r_type = ELF32_R_TYPE (dst->r_info);
652 cache_ptr->howto = dlx_rtype_to_howto (r_type);
653 return;
654}
655
656#define TARGET_BIG_SYM bfd_elf32_dlx_big_vec
657#define TARGET_BIG_NAME "elf32-dlx"
658#define ELF_ARCH bfd_arch_dlx
659#define ELF_MACHINE_CODE EM_DLX
660#define ELF_MAXPAGESIZE 1 /* FIXME: This number is wrong, It should be the page size in bytes. */
661
662#include "elf32-target.h"
This page took 0.156771 seconds and 4 git commands to generate.