Commit | Line | Data |
---|---|---|
d031aafb | 1 | /* Morpho Technologies MT specific support for 32-bit ELF |
4b95cf5c | 2 | Copyright (C) 2001-2014 Free Software Foundation, Inc. |
de33e640 AH |
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 | |
cd123cb7 | 8 | the Free Software Foundation; either version 3 of the License, or |
de33e640 AH |
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 | |
cd123cb7 NC |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
19 | MA 02111-1307, USA. */ | |
de33e640 | 20 | |
de33e640 | 21 | #include "sysdep.h" |
3db64b00 | 22 | #include "bfd.h" |
de33e640 AH |
23 | #include "libbfd.h" |
24 | #include "elf-bfd.h" | |
4970f871 | 25 | #include "elf/mt.h" |
de33e640 AH |
26 | |
27 | /* Prototypes. */ | |
68ffbac6 | 28 | static reloc_howto_type * mt_reloc_type_lookup |
de33e640 AH |
29 | (bfd *, bfd_reloc_code_real_type); |
30 | ||
d031aafb | 31 | static void mt_info_to_howto_rela |
de33e640 AH |
32 | (bfd *, arelent *, Elf_Internal_Rela *); |
33 | ||
d031aafb | 34 | static bfd_reloc_status_type mt_elf_relocate_hi16 |
de33e640 AH |
35 | (bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma); |
36 | ||
d031aafb | 37 | static bfd_reloc_status_type mt_final_link_relocate |
68ffbac6 | 38 | (reloc_howto_type *, bfd *, asection *, bfd_byte *, |
de33e640 AH |
39 | Elf_Internal_Rela *, bfd_vma); |
40 | ||
d031aafb | 41 | static bfd_boolean mt_elf_relocate_section |
68ffbac6 | 42 | (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
de33e640 AH |
43 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **); |
44 | ||
45 | /* Relocation tables. */ | |
d031aafb | 46 | static reloc_howto_type mt_elf_howto_table [] = |
de33e640 AH |
47 | { |
48 | /* This reloc does nothing. */ | |
d031aafb | 49 | HOWTO (R_MT_NONE, /* type */ |
68ffbac6 L |
50 | 0, /* rightshift */ |
51 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
de33e640 | 52 | 32, /* bitsize */ |
68ffbac6 L |
53 | FALSE, /* pc_relative */ |
54 | 0, /* bitpos */ | |
55 | complain_overflow_dont, /* complain_on_overflow */ | |
56 | bfd_elf_generic_reloc, /* special_function */ | |
57 | "R_MT_NONE", /* name */ | |
58 | FALSE, /* partial_inplace */ | |
59 | 0 , /* src_mask */ | |
60 | 0, /* dst_mask */ | |
de33e640 AH |
61 | FALSE), /* pcrel_offset */ |
62 | ||
63 | /* A 16 bit absolute relocation. */ | |
d031aafb | 64 | HOWTO (R_MT_16, /* type */ |
68ffbac6 L |
65 | 0, /* rightshift */ |
66 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
de33e640 | 67 | 16, /* bitsize */ |
68ffbac6 L |
68 | FALSE, /* pc_relative */ |
69 | 0, /* bitpos */ | |
70 | complain_overflow_dont, /* complain_on_overflow */ | |
71 | bfd_elf_generic_reloc, /* special_function */ | |
72 | "R_MT_16", /* name */ | |
73 | FALSE, /* partial_inplace */ | |
74 | 0 , /* src_mask */ | |
75 | 0xffff, /* dst_mask */ | |
de33e640 AH |
76 | FALSE), /* pcrel_offset */ |
77 | ||
78 | /* A 32 bit absolute relocation. */ | |
d031aafb | 79 | HOWTO (R_MT_32, /* type */ |
68ffbac6 L |
80 | 0, /* rightshift */ |
81 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
de33e640 | 82 | 32, /* bitsize */ |
68ffbac6 L |
83 | FALSE, /* pc_relative */ |
84 | 0, /* bitpos */ | |
85 | complain_overflow_dont, /* complain_on_overflow */ | |
86 | bfd_elf_generic_reloc, /* special_function */ | |
87 | "R_MT_32", /* name */ | |
88 | FALSE, /* partial_inplace */ | |
89 | 0 , /* src_mask */ | |
90 | 0xffffffff, /* dst_mask */ | |
de33e640 AH |
91 | FALSE), /* pcrel_offset */ |
92 | ||
93 | /* A 32 bit pc-relative relocation. */ | |
d031aafb | 94 | HOWTO (R_MT_32_PCREL, /* type */ |
68ffbac6 L |
95 | 0, /* rightshift */ |
96 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
de33e640 | 97 | 32, /* bitsize */ |
68ffbac6 L |
98 | TRUE, /* pc_relative */ |
99 | 0, /* bitpos */ | |
100 | complain_overflow_dont, /* complain_on_overflow */ | |
101 | bfd_elf_generic_reloc, /* special_function */ | |
102 | "R_MT_32_PCREL", /* name */ | |
103 | FALSE, /* partial_inplace */ | |
104 | 0 , /* src_mask */ | |
105 | 0xffffffff, /* dst_mask */ | |
de33e640 AH |
106 | TRUE), /* pcrel_offset */ |
107 | ||
108 | /* A 16 bit pc-relative relocation. */ | |
d031aafb | 109 | HOWTO (R_MT_PC16, /* type */ |
68ffbac6 L |
110 | 0, /* rightshift */ |
111 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
de33e640 | 112 | 16, /* bitsize */ |
68ffbac6 L |
113 | TRUE, /* pc_relative */ |
114 | 0, /* bitpos */ | |
115 | complain_overflow_signed, /* complain_on_overflow */ | |
116 | bfd_elf_generic_reloc, /* special_function */ | |
117 | "R_MT_PC16", /* name */ | |
118 | FALSE, /* partial_inplace */ | |
119 | 0, /* src_mask */ | |
120 | 0xffff, /* dst_mask */ | |
de33e640 AH |
121 | TRUE), /* pcrel_offset */ |
122 | ||
123 | /* high 16 bits of symbol value. */ | |
d031aafb | 124 | HOWTO (R_MT_HI16, /* type */ |
de33e640 AH |
125 | 0, /* rightshift */ |
126 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
127 | 16, /* bitsize */ | |
128 | FALSE, /* pc_relative */ | |
129 | 0, /* bitpos */ | |
130 | complain_overflow_dont, /* complain_on_overflow */ | |
131 | bfd_elf_generic_reloc, /* special_function */ | |
d031aafb | 132 | "R_MT_HI16", /* name */ |
de33e640 AH |
133 | FALSE, /* partial_inplace */ |
134 | 0xffff0000, /* src_mask */ | |
135 | 0xffff0000, /* dst_mask */ | |
136 | FALSE), /* pcrel_offset */ | |
137 | ||
138 | /* Low 16 bits of symbol value. */ | |
d031aafb | 139 | HOWTO (R_MT_LO16, /* type */ |
de33e640 AH |
140 | 0, /* rightshift */ |
141 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
142 | 16, /* bitsize */ | |
143 | FALSE, /* pc_relative */ | |
144 | 0, /* bitpos */ | |
145 | complain_overflow_dont, /* complain_on_overflow */ | |
146 | bfd_elf_generic_reloc, /* special_function */ | |
d031aafb | 147 | "R_MT_LO16", /* name */ |
de33e640 AH |
148 | FALSE, /* partial_inplace */ |
149 | 0xffff, /* src_mask */ | |
150 | 0xffff, /* dst_mask */ | |
151 | FALSE), /* pcrel_offset */ | |
152 | }; | |
153 | ||
d031aafb | 154 | /* Map BFD reloc types to MT ELF reloc types. */ |
de33e640 AH |
155 | |
156 | static reloc_howto_type * | |
d031aafb | 157 | mt_reloc_type_lookup |
de33e640 AH |
158 | (bfd * abfd ATTRIBUTE_UNUSED, |
159 | bfd_reloc_code_real_type code) | |
160 | { | |
d031aafb | 161 | /* Note that the mt_elf_howto_table is indxed by the R_ |
de33e640 AH |
162 | constants. Thus, the order that the howto records appear in the |
163 | table *must* match the order of the relocation types defined in | |
d031aafb | 164 | include/elf/mt.h. */ |
de33e640 AH |
165 | |
166 | switch (code) | |
167 | { | |
168 | case BFD_RELOC_NONE: | |
d031aafb | 169 | return &mt_elf_howto_table[ (int) R_MT_NONE]; |
de33e640 | 170 | case BFD_RELOC_16: |
d031aafb | 171 | return &mt_elf_howto_table[ (int) R_MT_16]; |
de33e640 | 172 | case BFD_RELOC_32: |
d031aafb | 173 | return &mt_elf_howto_table[ (int) R_MT_32]; |
de33e640 | 174 | case BFD_RELOC_32_PCREL: |
d031aafb | 175 | return &mt_elf_howto_table[ (int) R_MT_32_PCREL]; |
de33e640 | 176 | case BFD_RELOC_16_PCREL: |
d031aafb | 177 | return &mt_elf_howto_table[ (int) R_MT_PC16]; |
de33e640 | 178 | case BFD_RELOC_HI16: |
d031aafb | 179 | return &mt_elf_howto_table[ (int) R_MT_HI16]; |
de33e640 | 180 | case BFD_RELOC_LO16: |
d031aafb | 181 | return &mt_elf_howto_table[ (int) R_MT_LO16]; |
de33e640 AH |
182 | |
183 | default: | |
184 | /* Pacify gcc -Wall. */ | |
185 | return NULL; | |
186 | } | |
187 | return NULL; | |
188 | } | |
189 | ||
157090f7 AM |
190 | static reloc_howto_type * |
191 | mt_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
192 | const char *r_name) | |
193 | { | |
194 | unsigned int i; | |
195 | ||
196 | for (i = 0; | |
197 | i < sizeof (mt_elf_howto_table) / sizeof (mt_elf_howto_table[0]); | |
198 | i++) | |
199 | if (mt_elf_howto_table[i].name != NULL | |
200 | && strcasecmp (mt_elf_howto_table[i].name, r_name) == 0) | |
201 | return &mt_elf_howto_table[i]; | |
202 | ||
203 | return NULL; | |
204 | } | |
205 | ||
de33e640 | 206 | bfd_reloc_status_type |
d031aafb | 207 | mt_elf_relocate_hi16 |
de33e640 AH |
208 | (bfd * input_bfd, |
209 | Elf_Internal_Rela * relhi, | |
210 | bfd_byte * contents, | |
211 | bfd_vma value) | |
212 | { | |
213 | bfd_vma insn; | |
214 | ||
215 | insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); | |
216 | ||
217 | value += relhi->r_addend; | |
218 | value >>= 16; | |
219 | insn = ((insn & ~0xFFFF) | value); | |
220 | ||
221 | bfd_put_32 (input_bfd, insn, contents + relhi->r_offset); | |
222 | return bfd_reloc_ok; | |
223 | } | |
224 | \f | |
225 | /* XXX: The following code is the result of a cut&paste. This unfortunate | |
226 | practice is very widespread in the various target back-end files. */ | |
227 | ||
d031aafb | 228 | /* Set the howto pointer for a MT ELF reloc. */ |
de33e640 AH |
229 | |
230 | static void | |
d031aafb | 231 | mt_info_to_howto_rela |
de33e640 AH |
232 | (bfd * abfd ATTRIBUTE_UNUSED, |
233 | arelent * cache_ptr, | |
234 | Elf_Internal_Rela * dst) | |
235 | { | |
236 | unsigned int r_type; | |
237 | ||
238 | r_type = ELF32_R_TYPE (dst->r_info); | |
d031aafb | 239 | cache_ptr->howto = & mt_elf_howto_table [r_type]; |
de33e640 AH |
240 | } |
241 | ||
242 | /* Perform a single relocation. By default we use the standard BFD | |
243 | routines. */ | |
244 | ||
245 | static bfd_reloc_status_type | |
d031aafb | 246 | mt_final_link_relocate |
de33e640 AH |
247 | (reloc_howto_type * howto, |
248 | bfd * input_bfd, | |
249 | asection * input_section, | |
250 | bfd_byte * contents, | |
251 | Elf_Internal_Rela * rel, | |
252 | bfd_vma relocation) | |
253 | { | |
254 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
255 | contents, rel->r_offset, | |
256 | relocation, rel->r_addend); | |
257 | } | |
258 | ||
d031aafb | 259 | /* Relocate a MT ELF section. |
de33e640 AH |
260 | There is some attempt to make this function usable for many architectures, |
261 | both USE_REL and USE_RELA ['twould be nice if such a critter existed], | |
262 | if only to serve as a learning tool. | |
263 | ||
264 | The RELOCATE_SECTION function is called by the new ELF backend linker | |
265 | to handle the relocations for a section. | |
266 | ||
267 | The relocs are always passed as Rela structures; if the section | |
268 | actually uses Rel structures, the r_addend field will always be | |
269 | zero. | |
270 | ||
271 | This function is responsible for adjusting the section contents as | |
272 | necessary, and (if using Rela relocs and generating a relocatable | |
273 | output file) adjusting the reloc addend as necessary. | |
274 | ||
275 | This function does not have to worry about setting the reloc | |
276 | address or the reloc symbol index. | |
277 | ||
278 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
279 | ||
280 | LOCAL_SECTIONS is an array giving the section in the input file | |
281 | corresponding to the st_shndx field of each local symbol. | |
282 | ||
283 | The global hash table entry for the global symbols can be found | |
284 | via elf_sym_hashes (input_bfd). | |
285 | ||
286 | When generating relocatable output, this function must handle | |
287 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
288 | going to be the section symbol corresponding to the output | |
289 | section, which means that the addend must be adjusted | |
290 | accordingly. */ | |
291 | ||
292 | static bfd_boolean | |
d031aafb | 293 | mt_elf_relocate_section |
de33e640 AH |
294 | (bfd * output_bfd ATTRIBUTE_UNUSED, |
295 | struct bfd_link_info * info, | |
296 | bfd * input_bfd, | |
297 | asection * input_section, | |
298 | bfd_byte * contents, | |
299 | Elf_Internal_Rela * relocs, | |
300 | Elf_Internal_Sym * local_syms, | |
301 | asection ** local_sections) | |
302 | { | |
303 | Elf_Internal_Shdr * symtab_hdr; | |
304 | struct elf_link_hash_entry ** sym_hashes; | |
305 | Elf_Internal_Rela * rel; | |
306 | Elf_Internal_Rela * relend; | |
307 | ||
308 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
309 | sym_hashes = elf_sym_hashes (input_bfd); | |
310 | relend = relocs + input_section->reloc_count; | |
311 | ||
312 | for (rel = relocs; rel < relend; rel ++) | |
313 | { | |
314 | reloc_howto_type * howto; | |
315 | unsigned long r_symndx; | |
316 | Elf_Internal_Sym * sym; | |
317 | asection * sec; | |
318 | struct elf_link_hash_entry * h; | |
319 | bfd_vma relocation; | |
320 | bfd_reloc_status_type r; | |
321 | const char * name = NULL; | |
322 | int r_type; | |
68ffbac6 | 323 | |
de33e640 AH |
324 | r_type = ELF32_R_TYPE (rel->r_info); |
325 | ||
326 | r_symndx = ELF32_R_SYM (rel->r_info); | |
327 | ||
d031aafb | 328 | howto = mt_elf_howto_table + ELF32_R_TYPE (rel->r_info); |
de33e640 AH |
329 | h = NULL; |
330 | sym = NULL; | |
331 | sec = NULL; | |
68ffbac6 | 332 | |
de33e640 AH |
333 | if (r_symndx < symtab_hdr->sh_info) |
334 | { | |
335 | sym = local_syms + r_symndx; | |
336 | sec = local_sections [r_symndx]; | |
337 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
68ffbac6 | 338 | |
de33e640 AH |
339 | name = bfd_elf_string_from_elf_section |
340 | (input_bfd, symtab_hdr->sh_link, sym->st_name); | |
341 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; | |
342 | } | |
343 | else | |
344 | { | |
345 | bfd_boolean unresolved_reloc; | |
62d887d4 | 346 | bfd_boolean warned, ignored; |
de33e640 AH |
347 | |
348 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, | |
349 | r_symndx, symtab_hdr, sym_hashes, | |
350 | h, sec, relocation, | |
62d887d4 | 351 | unresolved_reloc, warned, ignored); |
de33e640 AH |
352 | |
353 | name = h->root.root.string; | |
354 | } | |
355 | ||
dbaa2011 | 356 | if (sec != NULL && discarded_section (sec)) |
e4067dbb | 357 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
545fd46b | 358 | rel, 1, relend, howto, 0, contents); |
ab96bf03 AM |
359 | |
360 | if (info->relocatable) | |
361 | continue; | |
de33e640 | 362 | |
d031aafb | 363 | /* Finally, the sole MT-specific part. */ |
de33e640 AH |
364 | switch (r_type) |
365 | { | |
d031aafb NS |
366 | case R_MT_HI16: |
367 | r = mt_elf_relocate_hi16 (input_bfd, rel, contents, relocation); | |
de33e640 AH |
368 | break; |
369 | default: | |
d031aafb | 370 | r = mt_final_link_relocate (howto, input_bfd, input_section, |
de33e640 AH |
371 | contents, rel, relocation); |
372 | break; | |
373 | } | |
374 | ||
375 | ||
376 | if (r != bfd_reloc_ok) | |
377 | { | |
378 | const char * msg = (const char *) NULL; | |
379 | ||
380 | switch (r) | |
381 | { | |
382 | case bfd_reloc_overflow: | |
383 | r = info->callbacks->reloc_overflow | |
384 | (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, | |
385 | input_bfd, input_section, rel->r_offset); | |
386 | break; | |
68ffbac6 | 387 | |
de33e640 AH |
388 | case bfd_reloc_undefined: |
389 | r = info->callbacks->undefined_symbol | |
390 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); | |
391 | break; | |
68ffbac6 | 392 | |
de33e640 AH |
393 | case bfd_reloc_outofrange: |
394 | msg = _("internal error: out of range error"); | |
395 | break; | |
396 | ||
397 | case bfd_reloc_dangerous: | |
398 | msg = _("internal error: dangerous relocation"); | |
399 | break; | |
400 | ||
401 | default: | |
402 | msg = _("internal error: unknown error"); | |
403 | break; | |
404 | } | |
405 | ||
406 | if (msg) | |
407 | r = info->callbacks->warning | |
408 | (info, msg, name, input_bfd, input_section, rel->r_offset); | |
409 | ||
410 | if (! r) | |
411 | return FALSE; | |
412 | } | |
413 | } | |
414 | ||
415 | return TRUE; | |
416 | } | |
417 | ||
de33e640 AH |
418 | /* Look through the relocs for a section during the first phase. |
419 | Since we don't do .gots or .plts, we just need to consider the | |
420 | virtual table relocs for gc. */ | |
68ffbac6 | 421 | |
de33e640 | 422 | static bfd_boolean |
d031aafb | 423 | mt_elf_check_relocs |
de33e640 AH |
424 | (bfd * abfd, |
425 | struct bfd_link_info * info, | |
426 | asection * sec, | |
427 | const Elf_Internal_Rela * relocs) | |
428 | { | |
429 | Elf_Internal_Shdr * symtab_hdr; | |
430 | struct elf_link_hash_entry ** sym_hashes; | |
de33e640 AH |
431 | const Elf_Internal_Rela * rel; |
432 | const Elf_Internal_Rela * rel_end; | |
68ffbac6 | 433 | |
de33e640 AH |
434 | if (info->relocatable) |
435 | return TRUE; | |
68ffbac6 | 436 | |
de33e640 AH |
437 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
438 | sym_hashes = elf_sym_hashes (abfd); | |
68ffbac6 | 439 | |
de33e640 AH |
440 | rel_end = relocs + sec->reloc_count; |
441 | for (rel = relocs; rel < rel_end; rel++) | |
442 | { | |
443 | struct elf_link_hash_entry *h; | |
444 | unsigned long r_symndx; | |
68ffbac6 | 445 | |
de33e640 AH |
446 | r_symndx = ELF32_R_SYM (rel->r_info); |
447 | if (r_symndx < symtab_hdr->sh_info) | |
448 | h = NULL; | |
449 | else | |
973a3492 L |
450 | { |
451 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
452 | while (h->root.type == bfd_link_hash_indirect | |
453 | || h->root.type == bfd_link_hash_warning) | |
454 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
81fbe831 AM |
455 | |
456 | /* PR15323, ref flags aren't set for references in the same | |
457 | object. */ | |
458 | h->root.non_ir_ref = 1; | |
973a3492 | 459 | } |
de33e640 AH |
460 | } |
461 | ||
462 | return TRUE; | |
463 | } | |
464 | ||
465 | /* Return the MACH for an e_flags value. */ | |
466 | ||
467 | static int | |
d031aafb | 468 | elf32_mt_machine (bfd *abfd) |
de33e640 | 469 | { |
d031aafb | 470 | switch (elf_elfheader (abfd)->e_flags & EF_MT_CPU_MASK) |
de33e640 | 471 | { |
d031aafb NS |
472 | case EF_MT_CPU_MRISC: return bfd_mach_ms1; |
473 | case EF_MT_CPU_MRISC2: return bfd_mach_mrisc2; | |
474 | case EF_MT_CPU_MS2: return bfd_mach_ms2; | |
de33e640 AH |
475 | } |
476 | ||
477 | return bfd_mach_ms1; | |
478 | } | |
479 | ||
480 | static bfd_boolean | |
d031aafb | 481 | mt_elf_object_p (bfd * abfd) |
de33e640 | 482 | { |
d031aafb | 483 | bfd_default_set_arch_mach (abfd, bfd_arch_mt, elf32_mt_machine (abfd)); |
de33e640 AH |
484 | |
485 | return TRUE; | |
486 | } | |
487 | ||
488 | /* Function to set the ELF flag bits. */ | |
489 | ||
490 | static bfd_boolean | |
d031aafb | 491 | mt_elf_set_private_flags (bfd * abfd, |
de33e640 AH |
492 | flagword flags) |
493 | { | |
494 | elf_elfheader (abfd)->e_flags = flags; | |
495 | elf_flags_init (abfd) = TRUE; | |
496 | return TRUE; | |
497 | } | |
498 | ||
de33e640 AH |
499 | /* Merge backend specific data from an object file to the output |
500 | object file when linking. */ | |
501 | ||
502 | static bfd_boolean | |
d031aafb | 503 | mt_elf_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
de33e640 AH |
504 | { |
505 | flagword old_flags, new_flags; | |
e510ff97 | 506 | bfd_boolean ok = TRUE; |
de33e640 | 507 | |
cc643b88 | 508 | /* Check if we have the same endianness. */ |
de33e640 AH |
509 | if (_bfd_generic_verify_endian_match (ibfd, obfd) == FALSE) |
510 | return FALSE; | |
511 | ||
d031aafb | 512 | /* If they're not both mt, then merging is meaningless, so just |
de33e640 | 513 | don't do it. */ |
d031aafb | 514 | if (strcmp (ibfd->arch_info->arch_name, "mt") != 0) |
de33e640 | 515 | return TRUE; |
d031aafb | 516 | if (strcmp (obfd->arch_info->arch_name, "mt") != 0) |
de33e640 AH |
517 | return TRUE; |
518 | ||
519 | new_flags = elf_elfheader (ibfd)->e_flags; | |
520 | old_flags = elf_elfheader (obfd)->e_flags; | |
521 | ||
522 | #ifdef DEBUG | |
523 | _bfd_error_handler ("%B: old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s", | |
524 | ibfd, old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no"); | |
525 | #endif | |
526 | ||
6f84a2a6 NS |
527 | if (!elf_flags_init (obfd)) |
528 | { | |
529 | old_flags = new_flags; | |
530 | elf_flags_init (obfd) = TRUE; | |
531 | } | |
d031aafb | 532 | else if ((new_flags & EF_MT_CPU_MASK) != (old_flags & EF_MT_CPU_MASK)) |
6f84a2a6 NS |
533 | { |
534 | /* CPU has changed. This is invalid, because MRISC, MRISC2 and | |
535 | MS2 are not subsets of each other. */ | |
e510ff97 | 536 | ok = FALSE; |
6f84a2a6 | 537 | } |
68ffbac6 | 538 | |
e510ff97 | 539 | if (ok) |
de33e640 | 540 | { |
de33e640 | 541 | obfd->arch_info = ibfd->arch_info; |
6f84a2a6 | 542 | elf_elfheader (obfd)->e_flags = old_flags; |
de33e640 AH |
543 | } |
544 | ||
e510ff97 | 545 | return ok; |
de33e640 AH |
546 | } |
547 | ||
548 | static bfd_boolean | |
d031aafb | 549 | mt_elf_print_private_bfd_data (bfd * abfd, void * ptr) |
de33e640 AH |
550 | { |
551 | FILE * file = (FILE *) ptr; | |
552 | flagword flags; | |
553 | ||
554 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
68ffbac6 | 555 | |
de33e640 AH |
556 | /* Print normal ELF private data. */ |
557 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
558 | ||
559 | flags = elf_elfheader (abfd)->e_flags; | |
0af1713e | 560 | fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags); |
de33e640 | 561 | |
d031aafb | 562 | switch (flags & EF_MT_CPU_MASK) |
de33e640 AH |
563 | { |
564 | default: | |
d031aafb NS |
565 | case EF_MT_CPU_MRISC: fprintf (file, " ms1-16-002"); break; |
566 | case EF_MT_CPU_MRISC2: fprintf (file, " ms1-16-003"); break; | |
567 | case EF_MT_CPU_MS2: fprintf (file, " ms2"); break; | |
de33e640 AH |
568 | } |
569 | ||
570 | fputc ('\n', file); | |
571 | ||
572 | return TRUE; | |
573 | } | |
574 | ||
575 | \f | |
d031aafb NS |
576 | #define TARGET_BIG_SYM bfd_elf32_mt_vec |
577 | #define TARGET_BIG_NAME "elf32-mt" | |
de33e640 | 578 | |
d031aafb NS |
579 | #define ELF_ARCH bfd_arch_mt |
580 | #define ELF_MACHINE_CODE EM_MT | |
581 | #define ELF_MAXPAGESIZE 1 /* No pages on the MT. */ | |
de33e640 AH |
582 | |
583 | #define elf_info_to_howto_rel NULL | |
d031aafb | 584 | #define elf_info_to_howto mt_info_to_howto_rela |
de33e640 | 585 | |
d031aafb | 586 | #define elf_backend_relocate_section mt_elf_relocate_section |
de33e640 | 587 | |
d031aafb | 588 | #define bfd_elf32_bfd_reloc_type_lookup mt_reloc_type_lookup |
157090f7 | 589 | #define bfd_elf32_bfd_reloc_name_lookup mt_reloc_name_lookup |
de33e640 | 590 | |
d031aafb NS |
591 | #define elf_backend_check_relocs mt_elf_check_relocs |
592 | #define elf_backend_object_p mt_elf_object_p | |
de33e640 AH |
593 | #define elf_backend_rela_normal 1 |
594 | ||
595 | #define elf_backend_can_gc_sections 1 | |
596 | ||
d031aafb | 597 | #define bfd_elf32_bfd_set_private_flags mt_elf_set_private_flags |
d031aafb NS |
598 | #define bfd_elf32_bfd_merge_private_bfd_data mt_elf_merge_private_bfd_data |
599 | #define bfd_elf32_bfd_print_private_bfd_data mt_elf_print_private_bfd_data | |
de33e640 AH |
600 | |
601 | #include "elf32-target.h" |