1a1ba9ba4Schristos /* Visium-specific support for 32-bit ELF.
2a1ba9ba4Schristos 
3*184b2d41Schristos    Copyright (C) 2003-2020 Free Software Foundation, Inc.
4a1ba9ba4Schristos 
5a1ba9ba4Schristos    This file is part of BFD, the Binary File Descriptor library.
6a1ba9ba4Schristos 
7a1ba9ba4Schristos    This program is free software; you can redistribute it and/or modify
8a1ba9ba4Schristos    it under the terms of the GNU General Public License as published by
9a1ba9ba4Schristos    the Free Software Foundation; either version 3 of the License, or
10a1ba9ba4Schristos    (at your option) any later version.
11a1ba9ba4Schristos 
12a1ba9ba4Schristos    This program is distributed in the hope that it will be useful,
13a1ba9ba4Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14a1ba9ba4Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a1ba9ba4Schristos    GNU General Public License for more details.
16a1ba9ba4Schristos 
17a1ba9ba4Schristos    You should have received a copy of the GNU General Public License
18a1ba9ba4Schristos    along with this program; if not, write to the Free Software
19a1ba9ba4Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor,
20a1ba9ba4Schristos    Boston, MA 02110-1301, USA.  */
21a1ba9ba4Schristos 
22a1ba9ba4Schristos #include "sysdep.h"
23a1ba9ba4Schristos #include "bfd.h"
24a1ba9ba4Schristos #include "sysdep.h"
25a1ba9ba4Schristos #include "libbfd.h"
26a1ba9ba4Schristos #include "elf-bfd.h"
27a1ba9ba4Schristos #include "elf/visium.h"
28051580eeSchristos #include "libiberty.h"
29a1ba9ba4Schristos 
30a1ba9ba4Schristos static bfd_reloc_status_type visium_elf_howto_parity_reloc
31a1ba9ba4Schristos   (bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **);
32a1ba9ba4Schristos 
33a1ba9ba4Schristos static reloc_howto_type visium_elf_howto_table[] = {
34a1ba9ba4Schristos   /* This reloc does nothing.  */
35a1ba9ba4Schristos   HOWTO (R_VISIUM_NONE,		/* type */
36a1ba9ba4Schristos 	 0,			/* rightshift */
37a1ba9ba4Schristos 	 3,			/* size (0 = byte, 1 = short, 2 = long) */
38a1ba9ba4Schristos 	 0,			/* bitsize */
39a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
40a1ba9ba4Schristos 	 0,			/* bitpos */
41a1ba9ba4Schristos 	 complain_overflow_dont,	/* complain_on_overflow */
42a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
43a1ba9ba4Schristos 	 "R_VISIUM_NONE",	/* name */
44a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
45a1ba9ba4Schristos 	 0,			/* src_mask */
46a1ba9ba4Schristos 	 0,			/* dst_mask */
47a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
48a1ba9ba4Schristos 
49a1ba9ba4Schristos   /* A 8 bit absolute relocation.  */
50a1ba9ba4Schristos   HOWTO (R_VISIUM_8,		/* type */
51a1ba9ba4Schristos 	 0,			/* rightshift */
52a1ba9ba4Schristos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
53a1ba9ba4Schristos 	 8,			/* bitsize */
54a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
55a1ba9ba4Schristos 	 0,			/* bitpos */
56a1ba9ba4Schristos 	 complain_overflow_bitfield,	/* complain_on_overflow */
57a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
58a1ba9ba4Schristos 	 "R_VISIUM_8",		/* name */
59a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
60a1ba9ba4Schristos 	 0x00,			/* src_mask */
61a1ba9ba4Schristos 	 0xff,			/* dst_mask */
62a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
63a1ba9ba4Schristos 
64a1ba9ba4Schristos   /* A 16 bit absolute relocation.  */
65a1ba9ba4Schristos   HOWTO (R_VISIUM_16,		/* type */
66a1ba9ba4Schristos 	 0,			/* rightshift */
67a1ba9ba4Schristos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
68a1ba9ba4Schristos 	 16,			/* bitsize */
69a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
70a1ba9ba4Schristos 	 0,			/* bitpos */
71a1ba9ba4Schristos 	 complain_overflow_bitfield,	/* complain_on_overflow */
72a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
73a1ba9ba4Schristos 	 "R_VISIUM_16",		/* name */
74a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
75a1ba9ba4Schristos 	 0x0000,		/* src_mask */
76a1ba9ba4Schristos 	 0xffff,		/* dst_mask */
77a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
78a1ba9ba4Schristos 
79a1ba9ba4Schristos   /* A 32 bit absolute relocation.  */
80a1ba9ba4Schristos   HOWTO (R_VISIUM_32,		/* type */
81a1ba9ba4Schristos 	 0,			/* rightshift */
82a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
83a1ba9ba4Schristos 	 32,			/* bitsize */
84a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
85a1ba9ba4Schristos 	 0,			/* bitpos */
86a1ba9ba4Schristos 	 complain_overflow_bitfield,	/* complain_on_overflow */
87a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
88a1ba9ba4Schristos 	 "R_VISIUM_32",		/* name */
89a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
90a1ba9ba4Schristos 	 0x00000000,		/* src_mask */
91a1ba9ba4Schristos 	 0xffffffff,		/* dst_mask */
92a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
93a1ba9ba4Schristos 
94a1ba9ba4Schristos 
95a1ba9ba4Schristos   /* A 8 bit PC relative relocation.  */
96a1ba9ba4Schristos   HOWTO (R_VISIUM_8_PCREL,		/* type */
97a1ba9ba4Schristos 	 0,			/* rightshift */
98a1ba9ba4Schristos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
99a1ba9ba4Schristos 	 8,			/* bitsize */
100a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
101a1ba9ba4Schristos 	 0,			/* bitpos */
102a1ba9ba4Schristos 	 complain_overflow_bitfield,	/* complain_on_overflow */
103a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
104a1ba9ba4Schristos 	 "R_VISIUM_8_PCREL",	/* name */
105a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
106a1ba9ba4Schristos 	 0x00,			/* src_mask */
107a1ba9ba4Schristos 	 0xff,			/* dst_mask */
108a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
109a1ba9ba4Schristos 
110a1ba9ba4Schristos   /* A 16 bit PC relative relocation.  */
111a1ba9ba4Schristos   HOWTO (R_VISIUM_16_PCREL,	/* type */
112a1ba9ba4Schristos 	 0,			/* rightshift */
113a1ba9ba4Schristos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
114a1ba9ba4Schristos 	 16,			/* bitsize */
115a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
116a1ba9ba4Schristos 	 0,			/* bitpos */
117a1ba9ba4Schristos 	 complain_overflow_bitfield,	/* complain_on_overflow */
118a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
119a1ba9ba4Schristos 	 "R_VISIUM_16_PCREL",	/* name */
120a1ba9ba4Schristos 	 FALSE,			/* partial inplace */
121a1ba9ba4Schristos 	 0x0000,		/* src_mask */
122a1ba9ba4Schristos 	 0xffff,		/* dst_mask */
123a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
124a1ba9ba4Schristos 
125a1ba9ba4Schristos   /* A 32-bit PC relative relocation.  */
126a1ba9ba4Schristos   HOWTO (R_VISIUM_32_PCREL,	/* type */
127a1ba9ba4Schristos 	 0,			/* rightshift */
128a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
129a1ba9ba4Schristos 	 32,			/* bitsize */
130a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
131a1ba9ba4Schristos 	 0,			/* bitpos */
132a1ba9ba4Schristos 	 complain_overflow_bitfield,	/* complain_on_overflow */
133a1ba9ba4Schristos 	 bfd_elf_generic_reloc,	/* special_function */
134a1ba9ba4Schristos 	 "R_VISIUM_32_PCREL",	/* name */
135a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
136a1ba9ba4Schristos 	 0,			/* src_mask */
137a1ba9ba4Schristos 	 0xffffffff,		/* dst_mask */
138a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
139a1ba9ba4Schristos 
140a1ba9ba4Schristos   /* A 16-bit PC word relative offset, relative to start of instruction
141a1ba9ba4Schristos      and always in the second half of the instruction.  */
142a1ba9ba4Schristos   HOWTO (R_VISIUM_PC16,		/* type */
143a1ba9ba4Schristos 	 2,			/* rightshift */
144a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
145a1ba9ba4Schristos 	 16,			/* bitsize */
146a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
147a1ba9ba4Schristos 	 0,			/* bitpos */
148a1ba9ba4Schristos 	 complain_overflow_signed,	/* complain_on_overflow */
149a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
150a1ba9ba4Schristos 	 "R_VISIUM_PC16",	/* name */
151a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
152a1ba9ba4Schristos 	 0x00000000,		/* src_mask */
153a1ba9ba4Schristos 	 0x0000ffff,		/* dst_mask */
154a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
155a1ba9ba4Schristos 
156a1ba9ba4Schristos   /* The high 16 bits of symbol value.  */
157a1ba9ba4Schristos   HOWTO (R_VISIUM_HI16,		/* type */
158a1ba9ba4Schristos 	 16,			/* rightshift */
159a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
160a1ba9ba4Schristos 	 16,			/* bitsize */
161a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
162a1ba9ba4Schristos 	 0,			/* bitpos */
163a1ba9ba4Schristos 	 complain_overflow_dont,	/* complain_on_overflow */
164a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
165a1ba9ba4Schristos 	 "R_VISIUM_HI16",	/* name */
166a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
167a1ba9ba4Schristos 	 0x00000000,		/* src_mask */
168a1ba9ba4Schristos 	 0x0000ffff,		/* dst_mask */
169a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
170a1ba9ba4Schristos 
171a1ba9ba4Schristos   /* The low 16 bits of symbol value.  */
172a1ba9ba4Schristos   HOWTO (R_VISIUM_LO16,		/* type */
173a1ba9ba4Schristos 	 0,			/* rightshift */
174a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
175a1ba9ba4Schristos 	 16,			/* bitsize */
176a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
177a1ba9ba4Schristos 	 0,			/* bitpos */
178a1ba9ba4Schristos 	 complain_overflow_dont,	/* complain_on_overflow */
179a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
180a1ba9ba4Schristos 	 "R_VISIUM_LO16",	/* name */
181a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
182a1ba9ba4Schristos 	 0x00000000,		/* src_mask */
183a1ba9ba4Schristos 	 0x0000ffff,		/* dst_mask */
184a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
185a1ba9ba4Schristos 
186a1ba9ba4Schristos   /* A 16 bit immediate value.  */
187a1ba9ba4Schristos   HOWTO (R_VISIUM_IM16,		/* type */
188a1ba9ba4Schristos 	 0,			/* rightshift */
189a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
190a1ba9ba4Schristos 	 16,			/* bitsize */
191a1ba9ba4Schristos 	 FALSE,			/* pc_relative */
192a1ba9ba4Schristos 	 0,			/* bitpos */
193a1ba9ba4Schristos 	 complain_overflow_unsigned,	/* complain_on_overflow */
194a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
195a1ba9ba4Schristos 	 "R_VISIUM_IM16",	/* name */
196a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
197a1ba9ba4Schristos 	 0x0000000,		/* src_mask */
198a1ba9ba4Schristos 	 0x000ffff,		/* dst_mask */
199a1ba9ba4Schristos 	 FALSE),		/* pcrel_offset */
200a1ba9ba4Schristos 
201a1ba9ba4Schristos   /* The high 16 bits of symbol value, pc relative.  */
202a1ba9ba4Schristos   HOWTO (R_VISIUM_HI16_PCREL,	/* type */
203a1ba9ba4Schristos 	 16,			/* rightshift */
204a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
205a1ba9ba4Schristos 	 16,			/* bitsize */
206a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
207a1ba9ba4Schristos 	 0,			/* bitpos */
208a1ba9ba4Schristos 	 complain_overflow_dont,	/* complain_on_overflow */
209a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
210a1ba9ba4Schristos 	 "R_VISIUM_HI16_PCREL",	/* name */
211a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
212a1ba9ba4Schristos 	 0x00000000,		/* src_mask */
213a1ba9ba4Schristos 	 0x0000ffff,		/* dst_mask */
214a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
215a1ba9ba4Schristos 
216a1ba9ba4Schristos   /* The low 16 bits of symbol value, pc relative.  */
217a1ba9ba4Schristos   HOWTO (R_VISIUM_LO16_PCREL,	/* type */
218a1ba9ba4Schristos 	 0,			/* rightshift */
219a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
220a1ba9ba4Schristos 	 16,			/* bitsize */
221a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
222a1ba9ba4Schristos 	 0,			/* bitpos */
223a1ba9ba4Schristos 	 complain_overflow_dont,	/* complain_on_overflow */
224a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
225a1ba9ba4Schristos 	 "R_VISIUM_LO16_PCREL",	/* name */
226a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
227a1ba9ba4Schristos 	 0x00000000,		/* src_mask */
228a1ba9ba4Schristos 	 0x0000ffff,		/* dst_mask */
229a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
230a1ba9ba4Schristos 
231a1ba9ba4Schristos   /* A 16 bit immediate value, pc relative.  */
232a1ba9ba4Schristos   HOWTO (R_VISIUM_IM16_PCREL,	/* type */
233a1ba9ba4Schristos 	 0,			/* rightshift */
234a1ba9ba4Schristos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
235a1ba9ba4Schristos 	 16,			/* bitsize */
236a1ba9ba4Schristos 	 TRUE,			/* pc_relative */
237a1ba9ba4Schristos 	 0,			/* bitpos */
238a1ba9ba4Schristos 	 complain_overflow_unsigned,	/* complain_on_overflow */
239a1ba9ba4Schristos 	 visium_elf_howto_parity_reloc,	/* special_function */
240a1ba9ba4Schristos 	 "R_VISIUM_IM16_PCREL",	/* name */
241a1ba9ba4Schristos 	 FALSE,			/* partial_inplace */
242a1ba9ba4Schristos 	 0x0000000,		/* src_mask */
243a1ba9ba4Schristos 	 0x000ffff,		/* dst_mask */
244a1ba9ba4Schristos 	 TRUE),			/* pcrel_offset */
245a1ba9ba4Schristos 
246a1ba9ba4Schristos };
247a1ba9ba4Schristos 
248a1ba9ba4Schristos /* GNU extension to record C++ vtable hierarchy.  */
249a1ba9ba4Schristos static reloc_howto_type visium_elf_vtinherit_howto =
250a1ba9ba4Schristos   HOWTO (R_VISIUM_GNU_VTINHERIT,      /* type */
251a1ba9ba4Schristos 	 0,			   /* rightshift */
252a1ba9ba4Schristos 	 2,			   /* size (0 = byte, 1 = short, 2 = long) */
253a1ba9ba4Schristos 	 0,			   /* bitsize */
254a1ba9ba4Schristos 	 FALSE,			   /* pc_relative */
255a1ba9ba4Schristos 	 0,			   /* bitpos */
256a1ba9ba4Schristos 	 complain_overflow_dont,   /* complain_on_overflow */
257a1ba9ba4Schristos 	 NULL,			   /* special_function */
258a1ba9ba4Schristos 	 "R_VISIUM_GNU_VTINHERIT", /* name */
259a1ba9ba4Schristos 	 FALSE,			   /* partial_inplace */
260a1ba9ba4Schristos 	 0,			   /* src_mask */
261a1ba9ba4Schristos 	 0,			   /* dst_mask */
262a1ba9ba4Schristos 	 FALSE);		   /* pcrel_offset */
263a1ba9ba4Schristos 
264a1ba9ba4Schristos /* GNU extension to record C++ vtable member usage.  */
265a1ba9ba4Schristos static reloc_howto_type visium_elf_vtentry_howto =
266a1ba9ba4Schristos   HOWTO (R_VISIUM_GNU_VTENTRY,	   /* type */
267a1ba9ba4Schristos 	 0,			   /* rightshift */
268a1ba9ba4Schristos 	 2,			   /* size (0 = byte, 1 = short, 2 = long) */
269a1ba9ba4Schristos 	 0,			   /* bitsize */
270a1ba9ba4Schristos 	 FALSE,			   /* pc_relative */
271a1ba9ba4Schristos 	 0,			   /* bitpos */
272a1ba9ba4Schristos 	 complain_overflow_dont,   /* complain_on_overflow */
273a1ba9ba4Schristos 	 NULL,			   /* special_function */
274a1ba9ba4Schristos 	 "R_VISIUM_GNU_VTENTRY",   /* name */
275a1ba9ba4Schristos 	 FALSE,			   /* partial_inplace */
276a1ba9ba4Schristos 	 0,			   /* src_mask */
277a1ba9ba4Schristos 	 0,			   /* dst_mask */
278a1ba9ba4Schristos 	 FALSE);		   /* pcrel_offset */
279a1ba9ba4Schristos 
280a1ba9ba4Schristos /* Return the parity bit for INSN shifted to its final position.  */
281a1ba9ba4Schristos 
282a1ba9ba4Schristos static bfd_vma
visium_parity_bit(bfd_vma insn)283a1ba9ba4Schristos visium_parity_bit (bfd_vma insn)
284a1ba9ba4Schristos {
285a1ba9ba4Schristos   bfd_vma p = 0;
286a1ba9ba4Schristos   int i;
287a1ba9ba4Schristos 
288a1ba9ba4Schristos   for (i = 0; i < 31; i++)
289a1ba9ba4Schristos     {
290a1ba9ba4Schristos       p ^= (insn & 1);
291a1ba9ba4Schristos       insn >>= 1;
292a1ba9ba4Schristos     }
293a1ba9ba4Schristos 
294a1ba9ba4Schristos   return p << 31;
295a1ba9ba4Schristos }
296a1ba9ba4Schristos 
297a1ba9ba4Schristos /* This "special function" will only be used when the input and
298a1ba9ba4Schristos    output files have different formats ie. when generating S-records
299a1ba9ba4Schristos    directly using "--oformat srec". Otherwise we use
300a1ba9ba4Schristos    _bfd_final_link_relocate which uses a howto structure, but does
301a1ba9ba4Schristos    not use the special_function field.
302a1ba9ba4Schristos 
303a1ba9ba4Schristos    It sets instruction parity to even.  This cannot be done by a howto.  */
304a1ba9ba4Schristos 
305a1ba9ba4Schristos static bfd_reloc_status_type
visium_elf_howto_parity_reloc(bfd * input_bfd,arelent * reloc_entry,asymbol * symbol,PTR data,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)306a1ba9ba4Schristos visium_elf_howto_parity_reloc (bfd * input_bfd, arelent *reloc_entry,
307a1ba9ba4Schristos 			       asymbol *symbol, PTR data,
308a1ba9ba4Schristos 			       asection *input_section, bfd *output_bfd,
309a1ba9ba4Schristos 			       char **error_message ATTRIBUTE_UNUSED)
310a1ba9ba4Schristos {
311a1ba9ba4Schristos   bfd_reloc_status_type ret;
312a1ba9ba4Schristos   bfd_vma relocation;
313a1ba9ba4Schristos   bfd_byte *inplace_address;
314a1ba9ba4Schristos   bfd_vma insn;
315a1ba9ba4Schristos 
316a1ba9ba4Schristos   /* This part is from bfd_elf_generic_reloc.
317a1ba9ba4Schristos      If we're relocating, and this an external symbol, we don't want
318a1ba9ba4Schristos      to change anything.  */
319a1ba9ba4Schristos   if (output_bfd != (bfd *) NULL && (symbol->flags & BSF_SECTION_SYM) == 0)
320a1ba9ba4Schristos     {
321a1ba9ba4Schristos       reloc_entry->address += input_section->output_offset;
322a1ba9ba4Schristos       return bfd_reloc_ok;
323a1ba9ba4Schristos     }
324a1ba9ba4Schristos 
325a1ba9ba4Schristos   /* Now do the reloc in the usual way.  */
326a1ba9ba4Schristos 
327a1ba9ba4Schristos   /* Sanity check the address (offset in section).  */
328a1ba9ba4Schristos   if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
329a1ba9ba4Schristos     return bfd_reloc_outofrange;
330a1ba9ba4Schristos 
331a1ba9ba4Schristos   ret = bfd_reloc_ok;
332a1ba9ba4Schristos   if (bfd_is_und_section (symbol->section) && output_bfd == (bfd *) NULL)
333a1ba9ba4Schristos     ret = bfd_reloc_undefined;
334a1ba9ba4Schristos 
335a1ba9ba4Schristos   if (bfd_is_com_section (symbol->section) || output_bfd != (bfd *) NULL)
336a1ba9ba4Schristos     relocation = 0;
337a1ba9ba4Schristos   else
338a1ba9ba4Schristos     relocation = symbol->value;
339a1ba9ba4Schristos 
340a1ba9ba4Schristos   /* Only do this for a final link.  */
341a1ba9ba4Schristos   if (output_bfd == (bfd *) NULL)
342a1ba9ba4Schristos     {
343a1ba9ba4Schristos       relocation += symbol->section->output_section->vma;
344a1ba9ba4Schristos       relocation += symbol->section->output_offset;
345a1ba9ba4Schristos     }
346a1ba9ba4Schristos 
347a1ba9ba4Schristos   relocation += reloc_entry->addend;
348a1ba9ba4Schristos   inplace_address = (bfd_byte *) data + reloc_entry->address;
349a1ba9ba4Schristos   insn = bfd_get_32 (input_bfd, inplace_address);
350a1ba9ba4Schristos 
351a1ba9ba4Schristos   if (reloc_entry->howto->pc_relative)
352a1ba9ba4Schristos     {
353051580eeSchristos       relocation -= input_section->output_section->vma;
354051580eeSchristos       relocation -= input_section->output_offset;
355a1ba9ba4Schristos       relocation -= reloc_entry->address;
356a1ba9ba4Schristos     }
357a1ba9ba4Schristos 
358a1ba9ba4Schristos   switch (reloc_entry->howto->type)
359a1ba9ba4Schristos     {
360a1ba9ba4Schristos     case R_VISIUM_PC16:
361051580eeSchristos       if (ret == bfd_reloc_ok
362051580eeSchristos 	  && ((bfd_signed_vma) relocation < -0x20000
363051580eeSchristos 	      || (bfd_signed_vma) relocation > 0x1ffff))
364a1ba9ba4Schristos 	ret = bfd_reloc_overflow;
365051580eeSchristos       relocation = (relocation >> 2) & 0xffff;
366a1ba9ba4Schristos       break;
367a1ba9ba4Schristos     case R_VISIUM_HI16:
368a1ba9ba4Schristos     case R_VISIUM_HI16_PCREL:
369a1ba9ba4Schristos       relocation = (relocation >> 16) & 0xffff;
370a1ba9ba4Schristos       break;
371a1ba9ba4Schristos     case R_VISIUM_LO16:
372a1ba9ba4Schristos     case R_VISIUM_LO16_PCREL:
373a1ba9ba4Schristos       relocation &= 0xffff;
374a1ba9ba4Schristos       break;
375a1ba9ba4Schristos     case R_VISIUM_IM16:
376a1ba9ba4Schristos     case R_VISIUM_IM16_PCREL:
377a1ba9ba4Schristos       if (ret == bfd_reloc_ok && (relocation & 0xffff0000) != 0)
378a1ba9ba4Schristos 	ret = bfd_reloc_overflow;
379a1ba9ba4Schristos       relocation &= 0xffff;
380a1ba9ba4Schristos       break;
381a1ba9ba4Schristos     }
382a1ba9ba4Schristos   insn = (insn & 0x7fff0000) | relocation;
383a1ba9ba4Schristos   insn |= visium_parity_bit (insn);
384a1ba9ba4Schristos   bfd_put_32 (input_bfd, insn, inplace_address);
385a1ba9ba4Schristos 
386a1ba9ba4Schristos   if (output_bfd != (bfd *) NULL)
387a1ba9ba4Schristos     reloc_entry->address += input_section->output_offset;
388a1ba9ba4Schristos 
389a1ba9ba4Schristos   return ret;
390a1ba9ba4Schristos }
391a1ba9ba4Schristos 
392a1ba9ba4Schristos static reloc_howto_type *
visium_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)393a1ba9ba4Schristos visium_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
394a1ba9ba4Schristos 			  bfd_reloc_code_real_type code)
395a1ba9ba4Schristos {
396a1ba9ba4Schristos   /* Note that the visium_elf_howto_table is indexed by the R_
397a1ba9ba4Schristos      constants. Thus, the order that the howto records appear in the
398a1ba9ba4Schristos      table *must* match the order of the relocation types defined in
399a1ba9ba4Schristos      include/elf/visium.h.  */
400a1ba9ba4Schristos   switch (code)
401a1ba9ba4Schristos     {
402a1ba9ba4Schristos     case BFD_RELOC_NONE:
403a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_NONE];
404a1ba9ba4Schristos     case BFD_RELOC_8:
405a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_8];
406a1ba9ba4Schristos     case BFD_RELOC_16:
407a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_16];
408a1ba9ba4Schristos     case BFD_RELOC_32:
409a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_32];
410a1ba9ba4Schristos     case BFD_RELOC_8_PCREL:
411a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_8_PCREL];
412a1ba9ba4Schristos     case BFD_RELOC_16_PCREL:
413a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_16_PCREL];
414a1ba9ba4Schristos     case BFD_RELOC_32_PCREL:
415a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_32_PCREL];
416a1ba9ba4Schristos     case BFD_RELOC_VISIUM_REL16:
417a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_PC16];
418a1ba9ba4Schristos     case BFD_RELOC_VISIUM_HI16:
419a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_HI16];
420a1ba9ba4Schristos     case BFD_RELOC_VISIUM_LO16:
421a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_LO16];
422a1ba9ba4Schristos     case BFD_RELOC_VISIUM_IM16:
423a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_IM16];
424a1ba9ba4Schristos     case BFD_RELOC_VISIUM_HI16_PCREL:
425a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_HI16_PCREL];
426a1ba9ba4Schristos     case BFD_RELOC_VISIUM_LO16_PCREL:
427a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_LO16_PCREL];
428a1ba9ba4Schristos     case BFD_RELOC_VISIUM_IM16_PCREL:
429a1ba9ba4Schristos       return &visium_elf_howto_table[(int) R_VISIUM_IM16_PCREL];
430a1ba9ba4Schristos     case BFD_RELOC_VTABLE_INHERIT:
431a1ba9ba4Schristos       return &visium_elf_vtinherit_howto;
432a1ba9ba4Schristos     case BFD_RELOC_VTABLE_ENTRY:
433a1ba9ba4Schristos       return &visium_elf_vtentry_howto;
434a1ba9ba4Schristos     default:
435a1ba9ba4Schristos       return NULL;
436a1ba9ba4Schristos     }
437a1ba9ba4Schristos }
438a1ba9ba4Schristos 
439a1ba9ba4Schristos static reloc_howto_type *
visium_reloc_name_lookup(bfd * abfd ATTRIBUTE_UNUSED,const char * r_name)440a1ba9ba4Schristos visium_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
441a1ba9ba4Schristos {
442a1ba9ba4Schristos   unsigned int i;
443a1ba9ba4Schristos 
444a1ba9ba4Schristos   for (i = 0;
445a1ba9ba4Schristos        i < (sizeof (visium_elf_howto_table)
446a1ba9ba4Schristos 	    / sizeof (visium_elf_howto_table[0])); i++)
447a1ba9ba4Schristos     if (visium_elf_howto_table[i].name != NULL
448a1ba9ba4Schristos 	&& strcasecmp (visium_elf_howto_table[i].name, r_name) == 0)
449a1ba9ba4Schristos       return &visium_elf_howto_table[i];
450a1ba9ba4Schristos 
451a1ba9ba4Schristos   if (strcasecmp (visium_elf_vtinherit_howto.name, r_name) == 0)
452a1ba9ba4Schristos     return &visium_elf_vtinherit_howto;
453a1ba9ba4Schristos   if (strcasecmp (visium_elf_vtentry_howto.name, r_name) == 0)
454a1ba9ba4Schristos     return &visium_elf_vtentry_howto;
455a1ba9ba4Schristos 
456a1ba9ba4Schristos   return NULL;
457a1ba9ba4Schristos }
458a1ba9ba4Schristos 
459a1ba9ba4Schristos /* Set the howto pointer for a VISIUM ELF reloc.  */
460a1ba9ba4Schristos 
461051580eeSchristos static bfd_boolean
visium_info_to_howto_rela(bfd * abfd,arelent * cache_ptr,Elf_Internal_Rela * dst)462051580eeSchristos visium_info_to_howto_rela (bfd *abfd, arelent *cache_ptr,
463a1ba9ba4Schristos 			   Elf_Internal_Rela *dst)
464a1ba9ba4Schristos {
465a1ba9ba4Schristos   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
466a1ba9ba4Schristos 
467a1ba9ba4Schristos   switch (r_type)
468a1ba9ba4Schristos     {
469a1ba9ba4Schristos     case R_VISIUM_GNU_VTINHERIT:
470a1ba9ba4Schristos       cache_ptr->howto = &visium_elf_vtinherit_howto;
471a1ba9ba4Schristos       break;
472a1ba9ba4Schristos 
473a1ba9ba4Schristos     case R_VISIUM_GNU_VTENTRY:
474a1ba9ba4Schristos       cache_ptr->howto = &visium_elf_vtentry_howto;
475a1ba9ba4Schristos       break;
476a1ba9ba4Schristos 
477a1ba9ba4Schristos     default:
478051580eeSchristos       if (r_type >= ARRAY_SIZE (visium_elf_howto_table))
479a1ba9ba4Schristos 	{
48015d8e94aSchristos 	  /* xgettext:c-format */
481051580eeSchristos 	  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
482051580eeSchristos 			      abfd, r_type);
483051580eeSchristos 	  bfd_set_error (bfd_error_bad_value);
484051580eeSchristos 	  return FALSE;
485a1ba9ba4Schristos 	}
486a1ba9ba4Schristos       cache_ptr->howto = &visium_elf_howto_table[r_type];
487a1ba9ba4Schristos       break;
488a1ba9ba4Schristos     }
489051580eeSchristos   return TRUE;
490a1ba9ba4Schristos }
491a1ba9ba4Schristos 
492a1ba9ba4Schristos /* Look through the relocs for a section during the first phase.
493a1ba9ba4Schristos    Since we don't do .gots or .plts, we just need to consider the
494a1ba9ba4Schristos    virtual table relocs for gc.  */
495a1ba9ba4Schristos 
496a1ba9ba4Schristos static bfd_boolean
visium_elf_check_relocs(bfd * abfd,struct bfd_link_info * info,asection * sec,const Elf_Internal_Rela * relocs)497a1ba9ba4Schristos visium_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
498a1ba9ba4Schristos 			 asection *sec, const Elf_Internal_Rela *relocs)
499a1ba9ba4Schristos {
500a1ba9ba4Schristos   Elf_Internal_Shdr *symtab_hdr;
501a1ba9ba4Schristos   struct elf_link_hash_entry **sym_hashes;
502a1ba9ba4Schristos   const Elf_Internal_Rela *rel;
503a1ba9ba4Schristos   const Elf_Internal_Rela *rel_end;
504a1ba9ba4Schristos 
505b2396a7bSchristos   if (bfd_link_relocatable (info))
506a1ba9ba4Schristos     return TRUE;
507a1ba9ba4Schristos 
508a1ba9ba4Schristos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
509a1ba9ba4Schristos   sym_hashes = elf_sym_hashes (abfd);
510a1ba9ba4Schristos 
511a1ba9ba4Schristos   rel_end = relocs + sec->reloc_count;
512a1ba9ba4Schristos   for (rel = relocs; rel < rel_end; rel++)
513a1ba9ba4Schristos     {
514a1ba9ba4Schristos       struct elf_link_hash_entry *h;
515a1ba9ba4Schristos       unsigned long r_symndx;
516a1ba9ba4Schristos 
517a1ba9ba4Schristos       r_symndx = ELF32_R_SYM (rel->r_info);
518a1ba9ba4Schristos       if (r_symndx < symtab_hdr->sh_info)
519a1ba9ba4Schristos 	h = NULL;
520a1ba9ba4Schristos       else
521a1ba9ba4Schristos 	{
522a1ba9ba4Schristos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
523a1ba9ba4Schristos 	  while (h->root.type == bfd_link_hash_indirect
524a1ba9ba4Schristos 		 || h->root.type == bfd_link_hash_warning)
525a1ba9ba4Schristos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
526a1ba9ba4Schristos 	}
527a1ba9ba4Schristos 
528a1ba9ba4Schristos       switch (ELF32_R_TYPE (rel->r_info))
529a1ba9ba4Schristos 	{
530a1ba9ba4Schristos 	  /* This relocation describes the C++ object vtable hierarchy.
531a1ba9ba4Schristos 	     Reconstruct it for later use during GC.  */
532a1ba9ba4Schristos 	case R_VISIUM_GNU_VTINHERIT:
533a1ba9ba4Schristos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
534a1ba9ba4Schristos 	    return FALSE;
535a1ba9ba4Schristos 	  break;
536a1ba9ba4Schristos 
537a1ba9ba4Schristos 	  /* This relocation describes which C++ vtable entries are actually
538a1ba9ba4Schristos 	     used.  Record for later use during GC.  */
539a1ba9ba4Schristos 	case R_VISIUM_GNU_VTENTRY:
540a1ba9ba4Schristos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
541a1ba9ba4Schristos 	    return FALSE;
542a1ba9ba4Schristos 	  break;
543a1ba9ba4Schristos 	}
544a1ba9ba4Schristos     }
545a1ba9ba4Schristos 
546a1ba9ba4Schristos   return TRUE;
547a1ba9ba4Schristos }
548a1ba9ba4Schristos 
549a1ba9ba4Schristos /* Relocate a VISIUM ELF section.  */
550a1ba9ba4Schristos 
551a1ba9ba4Schristos static bfd_boolean
visium_elf_relocate_section(bfd * output_bfd,struct bfd_link_info * info,bfd * input_bfd,asection * input_section,bfd_byte * contents,Elf_Internal_Rela * relocs,Elf_Internal_Sym * local_syms,asection ** local_sections)552a1ba9ba4Schristos visium_elf_relocate_section (bfd *output_bfd,
553a1ba9ba4Schristos 			     struct bfd_link_info *info, bfd *input_bfd,
554a1ba9ba4Schristos 			     asection *input_section, bfd_byte *contents,
555a1ba9ba4Schristos 			     Elf_Internal_Rela *relocs,
556a1ba9ba4Schristos 			     Elf_Internal_Sym *local_syms,
557a1ba9ba4Schristos 			     asection **local_sections)
558a1ba9ba4Schristos {
559a1ba9ba4Schristos   Elf_Internal_Shdr *symtab_hdr;
560a1ba9ba4Schristos   struct elf_link_hash_entry **sym_hashes;
561a1ba9ba4Schristos   Elf_Internal_Rela *rel;
562a1ba9ba4Schristos   Elf_Internal_Rela *relend;
563a1ba9ba4Schristos 
564a1ba9ba4Schristos   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
565a1ba9ba4Schristos   sym_hashes = elf_sym_hashes (input_bfd);
566a1ba9ba4Schristos   relend = relocs + input_section->reloc_count;
567a1ba9ba4Schristos 
568a1ba9ba4Schristos   for (rel = relocs; rel < relend; rel++)
569a1ba9ba4Schristos     {
570a1ba9ba4Schristos       reloc_howto_type *howto;
571a1ba9ba4Schristos       unsigned long r_symndx;
572a1ba9ba4Schristos       Elf_Internal_Sym *sym;
573a1ba9ba4Schristos       asection *sec;
574a1ba9ba4Schristos       struct elf_link_hash_entry *h;
575a1ba9ba4Schristos       bfd_vma relocation;
576a1ba9ba4Schristos       bfd_reloc_status_type r;
577a1ba9ba4Schristos       const char *name = NULL;
578a1ba9ba4Schristos       int r_type;
579a1ba9ba4Schristos       bfd_vma insn;
580a1ba9ba4Schristos 
581a1ba9ba4Schristos       r_type = ELF32_R_TYPE (rel->r_info);
582a1ba9ba4Schristos 
583a1ba9ba4Schristos       if (r_type == R_VISIUM_GNU_VTINHERIT || r_type == R_VISIUM_GNU_VTENTRY)
584a1ba9ba4Schristos 	continue;
585a1ba9ba4Schristos 
586a1ba9ba4Schristos       r_symndx = ELF32_R_SYM (rel->r_info);
587a1ba9ba4Schristos 
588a1ba9ba4Schristos       howto = visium_elf_howto_table + ELF32_R_TYPE (rel->r_info);
589a1ba9ba4Schristos       h = NULL;
590a1ba9ba4Schristos       sym = NULL;
591a1ba9ba4Schristos       sec = NULL;
592a1ba9ba4Schristos 
593a1ba9ba4Schristos       if (r_symndx < symtab_hdr->sh_info)
594a1ba9ba4Schristos 	{
595a1ba9ba4Schristos 	  /* This is a local symbol.  */
596a1ba9ba4Schristos 	  sym = local_syms + r_symndx;
597a1ba9ba4Schristos 	  sec = local_sections[r_symndx];
598a1ba9ba4Schristos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
599a1ba9ba4Schristos 
600a1ba9ba4Schristos 	  name = bfd_elf_string_from_elf_section
601a1ba9ba4Schristos 	    (input_bfd, symtab_hdr->sh_link, sym->st_name);
602*184b2d41Schristos 	  name = name == NULL ? bfd_section_name (sec) : name;
603a1ba9ba4Schristos 	}
604a1ba9ba4Schristos       else
605a1ba9ba4Schristos 	{
606a1ba9ba4Schristos 	  bfd_boolean unresolved_reloc;
607a1ba9ba4Schristos 	  bfd_boolean warned, ignored;
608a1ba9ba4Schristos 
609a1ba9ba4Schristos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
610a1ba9ba4Schristos 				   r_symndx, symtab_hdr, sym_hashes,
611a1ba9ba4Schristos 				   h, sec, relocation,
612a1ba9ba4Schristos 				   unresolved_reloc, warned, ignored);
613a1ba9ba4Schristos 
614a1ba9ba4Schristos 	  name = h->root.root.string;
615a1ba9ba4Schristos 	}
616a1ba9ba4Schristos 
617a1ba9ba4Schristos       if (sec != NULL && discarded_section (sec))
618a1ba9ba4Schristos 	{
619a1ba9ba4Schristos 	  /* For relocs against symbols from removed linkonce sections,
620a1ba9ba4Schristos 	     or sections discarded by a linker script, we just want the
621a1ba9ba4Schristos 	     section contents zeroed.  Avoid any special processing.  */
622a1ba9ba4Schristos 	  _bfd_clear_contents (howto, input_bfd, input_section,
623051580eeSchristos 			       contents, rel->r_offset);
624a1ba9ba4Schristos 
625a1ba9ba4Schristos 	  rel->r_info = 0;
626a1ba9ba4Schristos 	  rel->r_addend = 0;
627a1ba9ba4Schristos 	  continue;
628a1ba9ba4Schristos 	}
629a1ba9ba4Schristos 
630b2396a7bSchristos       if (bfd_link_relocatable (info))
631a1ba9ba4Schristos 	continue;
632a1ba9ba4Schristos 
633a1ba9ba4Schristos       switch (r_type)
634a1ba9ba4Schristos 	{
635a1ba9ba4Schristos 	case R_VISIUM_PC16:
636a1ba9ba4Schristos 	case R_VISIUM_HI16:
637a1ba9ba4Schristos 	case R_VISIUM_LO16:
638a1ba9ba4Schristos 	case R_VISIUM_IM16:
639a1ba9ba4Schristos 	case R_VISIUM_HI16_PCREL:
640a1ba9ba4Schristos 	case R_VISIUM_LO16_PCREL:
641a1ba9ba4Schristos 	case R_VISIUM_IM16_PCREL:
642a1ba9ba4Schristos 	  r = _bfd_final_link_relocate (howto, input_bfd, input_section,
643a1ba9ba4Schristos 					contents, rel->r_offset,
644a1ba9ba4Schristos 					relocation, rel->r_addend);
645a1ba9ba4Schristos 
646a1ba9ba4Schristos 	  /* For instruction relocations, the parity needs correcting.  */
647a1ba9ba4Schristos 	  if (r == bfd_reloc_ok)
648a1ba9ba4Schristos 	    {
649a1ba9ba4Schristos 	      insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
650a1ba9ba4Schristos 	      insn = (insn & 0x7fffffff) | visium_parity_bit (insn);
651a1ba9ba4Schristos 	      bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
652a1ba9ba4Schristos 	    }
653a1ba9ba4Schristos 	  break;
654a1ba9ba4Schristos 
655a1ba9ba4Schristos 	default:
656a1ba9ba4Schristos 	  r = _bfd_final_link_relocate (howto, input_bfd, input_section,
657a1ba9ba4Schristos 					contents, rel->r_offset,
658a1ba9ba4Schristos 					relocation, rel->r_addend);
659a1ba9ba4Schristos 	  break;
660a1ba9ba4Schristos 	}
661a1ba9ba4Schristos 
662a1ba9ba4Schristos       if (r != bfd_reloc_ok)
663a1ba9ba4Schristos 	{
664a1ba9ba4Schristos 	  const char *msg = (const char *) NULL;
665a1ba9ba4Schristos 
666a1ba9ba4Schristos 	  switch (r)
667a1ba9ba4Schristos 	    {
668a1ba9ba4Schristos 	    case bfd_reloc_overflow:
669b2396a7bSchristos 	      (*info->callbacks->reloc_overflow)
670a1ba9ba4Schristos 		(info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
671a1ba9ba4Schristos 		 input_bfd, input_section, rel->r_offset);
672a1ba9ba4Schristos 	      break;
673a1ba9ba4Schristos 
674a1ba9ba4Schristos 	    case bfd_reloc_undefined:
675b2396a7bSchristos 	      (*info->callbacks->undefined_symbol)
676a1ba9ba4Schristos 		(info, name, input_bfd, input_section, rel->r_offset, TRUE);
677a1ba9ba4Schristos 	      break;
678a1ba9ba4Schristos 
679a1ba9ba4Schristos 	    case bfd_reloc_outofrange:
680a1ba9ba4Schristos 	      msg = _("internal error: out of range error");
681a1ba9ba4Schristos 	      break;
682a1ba9ba4Schristos 
683a1ba9ba4Schristos 	    case bfd_reloc_notsupported:
684a1ba9ba4Schristos 	      msg = _("internal error: unsupported relocation error");
685a1ba9ba4Schristos 	      break;
686a1ba9ba4Schristos 
687a1ba9ba4Schristos 	    case bfd_reloc_dangerous:
688a1ba9ba4Schristos 	      msg = _("internal error: dangerous relocation");
689a1ba9ba4Schristos 	      break;
690a1ba9ba4Schristos 
691a1ba9ba4Schristos 	    default:
692a1ba9ba4Schristos 	      msg = _("internal error: unknown error");
693a1ba9ba4Schristos 	      break;
694a1ba9ba4Schristos 	    }
695a1ba9ba4Schristos 
696a1ba9ba4Schristos 	  if (msg)
697b2396a7bSchristos 	    (*info->callbacks->warning) (info, msg, name, input_bfd,
698b2396a7bSchristos 					 input_section, rel->r_offset);
699a1ba9ba4Schristos 	}
700a1ba9ba4Schristos     }
701a1ba9ba4Schristos 
702a1ba9ba4Schristos   return TRUE;
703a1ba9ba4Schristos }
704a1ba9ba4Schristos 
705a1ba9ba4Schristos /* This function is called during section gc to discover the section a
706a1ba9ba4Schristos    to which a particular relocation refers.  Return the section that
707a1ba9ba4Schristos    should be marked against GC for a given relocation.  */
708a1ba9ba4Schristos 
709a1ba9ba4Schristos static asection *
visium_elf_gc_mark_hook(asection * sec,struct bfd_link_info * info,Elf_Internal_Rela * rel,struct elf_link_hash_entry * h,Elf_Internal_Sym * sym)710a1ba9ba4Schristos visium_elf_gc_mark_hook (asection *sec, struct bfd_link_info *info,
711a1ba9ba4Schristos 			 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
712a1ba9ba4Schristos 			 Elf_Internal_Sym *sym)
713a1ba9ba4Schristos {
714a1ba9ba4Schristos   if (h != NULL)
715a1ba9ba4Schristos     switch (ELF32_R_TYPE (rel->r_info))
716a1ba9ba4Schristos       {
717a1ba9ba4Schristos       case R_VISIUM_GNU_VTINHERIT:
718a1ba9ba4Schristos       case R_VISIUM_GNU_VTENTRY:
719a1ba9ba4Schristos 	return NULL;
720a1ba9ba4Schristos       }
721a1ba9ba4Schristos 
722a1ba9ba4Schristos   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
723a1ba9ba4Schristos }
724a1ba9ba4Schristos 
725*184b2d41Schristos static bfd_boolean
visium_elf_init_file_header(bfd * abfd,struct bfd_link_info * info)726*184b2d41Schristos visium_elf_init_file_header (bfd *abfd, struct bfd_link_info *info)
727a1ba9ba4Schristos {
728*184b2d41Schristos   Elf_Internal_Ehdr *i_ehdrp;
729*184b2d41Schristos 
730*184b2d41Schristos   if (!_bfd_elf_init_file_header (abfd, info))
731*184b2d41Schristos     return FALSE;
732*184b2d41Schristos 
733*184b2d41Schristos   i_ehdrp = elf_elfheader (abfd);
734a1ba9ba4Schristos   i_ehdrp->e_ident[EI_ABIVERSION] = 1;
735*184b2d41Schristos   return TRUE;
736a1ba9ba4Schristos }
737a1ba9ba4Schristos 
738a1ba9ba4Schristos /* Function to set the ELF flag bits.  */
739a1ba9ba4Schristos 
740a1ba9ba4Schristos static bfd_boolean
visium_elf_set_private_flags(bfd * abfd,flagword flags)741a1ba9ba4Schristos visium_elf_set_private_flags (bfd *abfd, flagword flags)
742a1ba9ba4Schristos {
743a1ba9ba4Schristos   elf_elfheader (abfd)->e_flags = flags;
744a1ba9ba4Schristos   elf_flags_init (abfd) = TRUE;
745a1ba9ba4Schristos   return TRUE;
746a1ba9ba4Schristos }
747a1ba9ba4Schristos 
748a1ba9ba4Schristos /* Copy backend specific data from one object module to another.  */
749a1ba9ba4Schristos 
750a1ba9ba4Schristos static bfd_boolean
visium_elf_copy_private_bfd_data(bfd * ibfd,bfd * obfd)751a1ba9ba4Schristos visium_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
752a1ba9ba4Schristos {
753a1ba9ba4Schristos   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
754a1ba9ba4Schristos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
755a1ba9ba4Schristos     return TRUE;
756a1ba9ba4Schristos 
757a1ba9ba4Schristos   BFD_ASSERT (!elf_flags_init (obfd)
758a1ba9ba4Schristos 	      || elf_elfheader (obfd)->e_flags ==
759a1ba9ba4Schristos 	      elf_elfheader (ibfd)->e_flags);
760a1ba9ba4Schristos 
761a1ba9ba4Schristos   elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
762a1ba9ba4Schristos   elf_flags_init (obfd) = TRUE;
763a1ba9ba4Schristos 
764a1ba9ba4Schristos   /* Copy object attributes.  */
765a1ba9ba4Schristos   _bfd_elf_copy_obj_attributes (ibfd, obfd);
766a1ba9ba4Schristos 
767a1ba9ba4Schristos   return TRUE;
768a1ba9ba4Schristos }
769a1ba9ba4Schristos 
770a1ba9ba4Schristos /* Merge backend specific data from an object
771a1ba9ba4Schristos    file to the output object file when linking.  */
772a1ba9ba4Schristos 
773a1ba9ba4Schristos static bfd_boolean
visium_elf_merge_private_bfd_data(bfd * ibfd,struct bfd_link_info * info)77415d8e94aSchristos visium_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
775a1ba9ba4Schristos {
77615d8e94aSchristos   bfd *obfd = info->output_bfd;
777a1ba9ba4Schristos   flagword old_flags;
778a1ba9ba4Schristos   flagword new_flags;
779a1ba9ba4Schristos   flagword mismatch;
780a1ba9ba4Schristos   const char *opt_arch = NULL;
781a1ba9ba4Schristos   const char *new_opt_with = NULL;
782a1ba9ba4Schristos   const char *old_opt_with = NULL;
783a1ba9ba4Schristos   const char *with = "with";
784a1ba9ba4Schristos   const char *without = "without";
785a1ba9ba4Schristos   const char *mcm = "mcm";
786a1ba9ba4Schristos   const char *mcm24 = "mcm24";
787a1ba9ba4Schristos   const char *gr6 = "gr6";
788a1ba9ba4Schristos 
789a1ba9ba4Schristos   new_flags = elf_elfheader (ibfd)->e_flags;
790a1ba9ba4Schristos   old_flags = elf_elfheader (obfd)->e_flags;
791a1ba9ba4Schristos 
792a1ba9ba4Schristos   if (!elf_flags_init (obfd))
793a1ba9ba4Schristos     {
794a1ba9ba4Schristos       /* First call, no flags set.  */
795a1ba9ba4Schristos       elf_flags_init (obfd) = TRUE;
796a1ba9ba4Schristos       elf_elfheader (obfd)->e_flags = new_flags;
797a1ba9ba4Schristos     }
798a1ba9ba4Schristos   else
799a1ba9ba4Schristos     {
800a1ba9ba4Schristos       mismatch = (new_flags ^ old_flags)
801a1ba9ba4Schristos 	& (EF_VISIUM_ARCH_MCM | EF_VISIUM_ARCH_MCM24 | EF_VISIUM_ARCH_GR6);
802a1ba9ba4Schristos       if (mismatch & EF_VISIUM_ARCH_GR6)
803a1ba9ba4Schristos 	{
804a1ba9ba4Schristos 	  opt_arch = gr6;
805a1ba9ba4Schristos 	  new_opt_with = new_flags & EF_VISIUM_ARCH_GR6 ? with : without;
806a1ba9ba4Schristos 	  old_opt_with = old_flags & EF_VISIUM_ARCH_GR6 ? with : without;
807a1ba9ba4Schristos 	}
808a1ba9ba4Schristos       else if (mismatch & EF_VISIUM_ARCH_MCM)
809a1ba9ba4Schristos 	{
810a1ba9ba4Schristos 	  opt_arch = mcm;
811a1ba9ba4Schristos 	  new_opt_with = new_flags & EF_VISIUM_ARCH_MCM ? with : without;
812a1ba9ba4Schristos 	  old_opt_with = old_flags & EF_VISIUM_ARCH_MCM ? with : without;
813a1ba9ba4Schristos 	}
814a1ba9ba4Schristos       else if (mismatch & EF_VISIUM_ARCH_MCM24)
815a1ba9ba4Schristos 	{
816a1ba9ba4Schristos 	  opt_arch = mcm24;
817a1ba9ba4Schristos 	  new_opt_with = new_flags & EF_VISIUM_ARCH_MCM24 ? with : without;
818a1ba9ba4Schristos 	  old_opt_with = old_flags & EF_VISIUM_ARCH_MCM24 ? with : without;
819a1ba9ba4Schristos 	}
820a1ba9ba4Schristos 
821a1ba9ba4Schristos       if (mismatch)
822a1ba9ba4Schristos 	_bfd_error_handler
82315d8e94aSchristos 	  /* xgettext:c-format */
824051580eeSchristos 	  (_("%pB: compiled %s -mtune=%s and linked with modules"
825a1ba9ba4Schristos 	     " compiled %s -mtune=%s"),
82615d8e94aSchristos 	   ibfd, new_opt_with, opt_arch, old_opt_with, opt_arch);
827a1ba9ba4Schristos     }
828a1ba9ba4Schristos 
829a1ba9ba4Schristos   return TRUE;
830a1ba9ba4Schristos }
831a1ba9ba4Schristos 
832a1ba9ba4Schristos static bfd_boolean
visium_elf_print_private_bfd_data(bfd * abfd,void * ptr)833a1ba9ba4Schristos visium_elf_print_private_bfd_data (bfd *abfd, void *ptr)
834a1ba9ba4Schristos {
835a1ba9ba4Schristos   FILE *file = (FILE *) ptr;
836a1ba9ba4Schristos   flagword flags;
837a1ba9ba4Schristos 
838a1ba9ba4Schristos   BFD_ASSERT (abfd != NULL && ptr != NULL);
839a1ba9ba4Schristos 
840a1ba9ba4Schristos   /* Print normal ELF private data.  */
841a1ba9ba4Schristos   _bfd_elf_print_private_bfd_data (abfd, ptr);
842a1ba9ba4Schristos 
843a1ba9ba4Schristos   flags = elf_elfheader (abfd)->e_flags;
844a1ba9ba4Schristos   fprintf (file, _("private flags = 0x%lx:"), (long) flags);
845a1ba9ba4Schristos 
846a1ba9ba4Schristos   if (flags & EF_VISIUM_ARCH_GR6)
847a1ba9ba4Schristos     fprintf (file, " -mtune=gr6");
848a1ba9ba4Schristos   else if (flags & EF_VISIUM_ARCH_MCM)
849a1ba9ba4Schristos     fprintf (file, " -mtune=mcm");
850a1ba9ba4Schristos   else if (flags & EF_VISIUM_ARCH_MCM24)
851a1ba9ba4Schristos     fprintf (file, " -mtune=mcm24");
852a1ba9ba4Schristos 
853a1ba9ba4Schristos   fputc ('\n', file);
854a1ba9ba4Schristos   return TRUE;
855a1ba9ba4Schristos }
856a1ba9ba4Schristos 
857a1ba9ba4Schristos #define ELF_ARCH		bfd_arch_visium
858a1ba9ba4Schristos #define ELF_MACHINE_CODE	EM_VISIUM
859*184b2d41Schristos #define ELF_OSABI		ELFOSABI_STANDALONE
860a1ba9ba4Schristos #define ELF_MAXPAGESIZE		1
861a1ba9ba4Schristos 
862a1ba9ba4Schristos #define TARGET_BIG_SYM		visium_elf32_vec
863a1ba9ba4Schristos #define TARGET_BIG_NAME		"elf32-visium"
864a1ba9ba4Schristos 
865a1ba9ba4Schristos #define elf_info_to_howto_rel			NULL
866a1ba9ba4Schristos #define elf_info_to_howto			visium_info_to_howto_rela
867a1ba9ba4Schristos #define elf_backend_relocate_section		visium_elf_relocate_section
868a1ba9ba4Schristos #define elf_backend_gc_mark_hook		visium_elf_gc_mark_hook
869a1ba9ba4Schristos #define elf_backend_check_relocs		visium_elf_check_relocs
870a1ba9ba4Schristos #define elf_backend_rela_normal			1
871a1ba9ba4Schristos 
872a1ba9ba4Schristos #define elf_backend_can_gc_sections		1
873a1ba9ba4Schristos 
874a1ba9ba4Schristos #define bfd_elf32_bfd_reloc_type_lookup		visium_reloc_type_lookup
875a1ba9ba4Schristos #define bfd_elf32_bfd_reloc_name_lookup		visium_reloc_name_lookup
876a1ba9ba4Schristos 
877a1ba9ba4Schristos #define bfd_elf32_bfd_set_private_flags		visium_elf_set_private_flags
878a1ba9ba4Schristos #define bfd_elf32_bfd_copy_private_bfd_data	visium_elf_copy_private_bfd_data
879a1ba9ba4Schristos #define bfd_elf32_bfd_merge_private_bfd_data	visium_elf_merge_private_bfd_data
880a1ba9ba4Schristos #define bfd_elf32_bfd_print_private_bfd_data	visium_elf_print_private_bfd_data
881*184b2d41Schristos #define elf_backend_init_file_header		visium_elf_init_file_header
882a1ba9ba4Schristos 
883a1ba9ba4Schristos #include "elf32-target.h"
884