]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elf32-v850.c
gas/
[thirdparty/binutils-gdb.git] / bfd / elf32-v850.c
CommitLineData
252b5132 1/* V850-specific support for 32-bit ELF
9553c638 2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
7898deda 3 Free Software Foundation, Inc.
252b5132 4
86aba9db 5 This file is part of BFD, the Binary File Descriptor library.
252b5132 6
86aba9db
NC
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
252b5132 11
86aba9db
NC
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
252b5132 16
86aba9db
NC
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
3e110533 19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132 20
252b5132 21/* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char
86aba9db 22 dependencies. As is the gas & simulator code for the v850. */
252b5132 23
252b5132
RH
24#include "bfd.h"
25#include "sysdep.h"
26#include "bfdlink.h"
27#include "libbfd.h"
28#include "elf-bfd.h"
29#include "elf/v850.h"
e12dd2ea 30#include "libiberty.h"
252b5132 31
e12dd2ea 32/* Sign-extend a 24-bit number. */
dc810e39 33#define SEXT24(x) ((((x) & 0xffffff) ^ 0x800000) - 0x800000)
435b1e90 34
252b5132
RH
35static reloc_howto_type *v850_elf_reloc_type_lookup
36 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
37static void v850_elf_info_to_howto_rel
947216bf 38 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
252b5132 39static void v850_elf_info_to_howto_rela
947216bf 40 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
252b5132
RH
41static bfd_reloc_status_type v850_elf_reloc
42 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
b34976b6 43static bfd_boolean v850_elf_is_local_label_name
252b5132 44 PARAMS ((bfd *, const char *));
b34976b6 45static bfd_boolean v850_elf_relocate_section
252b5132
RH
46 PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
47 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
48static bfd_reloc_status_type v850_elf_perform_relocation
dc810e39 49 PARAMS ((bfd *, unsigned int, bfd_vma, bfd_byte *));
b34976b6 50static bfd_boolean v850_elf_check_relocs
252b5132
RH
51 PARAMS ((bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *));
52static void remember_hi16s_reloc
53 PARAMS ((bfd *, bfd_vma, bfd_byte *));
54static bfd_byte * find_remembered_hi16s_reloc
b34976b6 55 PARAMS ((bfd_vma, bfd_boolean *));
252b5132
RH
56static bfd_reloc_status_type v850_elf_final_link_relocate
57 PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *, bfd_vma,
58 bfd_vma, bfd_vma, struct bfd_link_info *, asection *, int));
b34976b6 59static bfd_boolean v850_elf_object_p
252b5132 60 PARAMS ((bfd *));
b34976b6 61static bfd_boolean v850_elf_fake_sections
947216bf 62 PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
252b5132 63static void v850_elf_final_write_processing
b34976b6
AM
64 PARAMS ((bfd *, bfd_boolean));
65static bfd_boolean v850_elf_set_private_flags
252b5132 66 PARAMS ((bfd *, flagword));
b34976b6 67static bfd_boolean v850_elf_merge_private_bfd_data
252b5132 68 PARAMS ((bfd *, bfd *));
b34976b6 69static bfd_boolean v850_elf_print_private_bfd_data
252b5132 70 PARAMS ((bfd *, PTR));
b34976b6 71static bfd_boolean v850_elf_section_from_bfd_section
af746e92 72 PARAMS ((bfd *, asection *, int *));
252b5132
RH
73static void v850_elf_symbol_processing
74 PARAMS ((bfd *, asymbol *));
b34976b6 75static bfd_boolean v850_elf_add_symbol_hook
555cd476 76 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
252b5132 77 const char **, flagword *, asection **, bfd_vma *));
b34976b6 78static bfd_boolean v850_elf_link_output_symbol_hook
754021d0
AM
79 PARAMS ((struct bfd_link_info *, const char *, Elf_Internal_Sym *,
80 asection *, struct elf_link_hash_entry *));
b34976b6 81static bfd_boolean v850_elf_gc_sweep_hook
e12dd2ea
NC
82 PARAMS ((bfd *, struct bfd_link_info *, asection *,
83 const Elf_Internal_Rela *));
84static asection * v850_elf_gc_mark_hook
1e2f5b6e 85 PARAMS ((asection *, struct bfd_link_info *,
e12dd2ea
NC
86 Elf_Internal_Rela *, struct elf_link_hash_entry *,
87 Elf_Internal_Sym *));
86aba9db
NC
88static bfd_reloc_status_type v850_elf_ignore_reloc
89 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
b34976b6 90static bfd_boolean v850_elf_relax_delete_bytes
86aba9db 91 PARAMS ((bfd *, asection *, bfd_vma, bfd_vma, int));
b34976b6
AM
92static bfd_boolean v850_elf_relax_section
93 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
e12dd2ea
NC
94
95/* Note: It is REQUIRED that the 'type' value of each entry
96 in this array match the index of the entry in the array. */
252b5132
RH
97static reloc_howto_type v850_elf_howto_table[] =
98{
99 /* This reloc does nothing. */
100 HOWTO (R_V850_NONE, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
b34976b6 104 FALSE, /* pc_relative */
252b5132
RH
105 0, /* bitpos */
106 complain_overflow_bitfield, /* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_V850_NONE", /* name */
b34976b6 109 FALSE, /* partial_inplace */
252b5132
RH
110 0, /* src_mask */
111 0, /* dst_mask */
b34976b6 112 FALSE), /* pcrel_offset */
252b5132 113
435b1e90 114 /* A PC relative 9 bit branch. */
252b5132
RH
115 HOWTO (R_V850_9_PCREL, /* type */
116 2, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 26, /* bitsize */
b34976b6 119 TRUE, /* pc_relative */
252b5132
RH
120 0, /* bitpos */
121 complain_overflow_bitfield, /* complain_on_overflow */
122 v850_elf_reloc, /* special_function */
123 "R_V850_9_PCREL", /* name */
b34976b6 124 FALSE, /* partial_inplace */
252b5132
RH
125 0x00ffffff, /* src_mask */
126 0x00ffffff, /* dst_mask */
b34976b6 127 TRUE), /* pcrel_offset */
252b5132 128
435b1e90 129 /* A PC relative 22 bit branch. */
252b5132
RH
130 HOWTO (R_V850_22_PCREL, /* type */
131 2, /* rightshift */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
133 22, /* bitsize */
b34976b6 134 TRUE, /* pc_relative */
252b5132
RH
135 7, /* bitpos */
136 complain_overflow_signed, /* complain_on_overflow */
137 v850_elf_reloc, /* special_function */
138 "R_V850_22_PCREL", /* name */
b34976b6 139 FALSE, /* partial_inplace */
252b5132
RH
140 0x07ffff80, /* src_mask */
141 0x07ffff80, /* dst_mask */
b34976b6 142 TRUE), /* pcrel_offset */
252b5132
RH
143
144 /* High 16 bits of symbol value. */
145 HOWTO (R_V850_HI16_S, /* type */
146 0, /* rightshift */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
148 16, /* bitsize */
b34976b6 149 FALSE, /* pc_relative */
252b5132
RH
150 0, /* bitpos */
151 complain_overflow_dont, /* complain_on_overflow */
152 v850_elf_reloc, /* special_function */
153 "R_V850_HI16_S", /* name */
b34976b6 154 FALSE, /* partial_inplace */
252b5132
RH
155 0xffff, /* src_mask */
156 0xffff, /* dst_mask */
b34976b6 157 FALSE), /* pcrel_offset */
252b5132
RH
158
159 /* High 16 bits of symbol value. */
160 HOWTO (R_V850_HI16, /* type */
161 0, /* rightshift */
162 1, /* size (0 = byte, 1 = short, 2 = long) */
163 16, /* bitsize */
b34976b6 164 FALSE, /* pc_relative */
252b5132
RH
165 0, /* bitpos */
166 complain_overflow_dont, /* complain_on_overflow */
167 v850_elf_reloc, /* special_function */
168 "R_V850_HI16", /* name */
b34976b6 169 FALSE, /* partial_inplace */
252b5132
RH
170 0xffff, /* src_mask */
171 0xffff, /* dst_mask */
b34976b6 172 FALSE), /* pcrel_offset */
252b5132
RH
173
174 /* Low 16 bits of symbol value. */
175 HOWTO (R_V850_LO16, /* type */
176 0, /* rightshift */
177 1, /* size (0 = byte, 1 = short, 2 = long) */
178 16, /* bitsize */
b34976b6 179 FALSE, /* pc_relative */
252b5132
RH
180 0, /* bitpos */
181 complain_overflow_dont, /* complain_on_overflow */
182 v850_elf_reloc, /* special_function */
183 "R_V850_LO16", /* name */
b34976b6 184 FALSE, /* partial_inplace */
252b5132
RH
185 0xffff, /* src_mask */
186 0xffff, /* dst_mask */
b34976b6 187 FALSE), /* pcrel_offset */
252b5132
RH
188
189 /* Simple 32bit reloc. */
e30ddb24 190 HOWTO (R_V850_ABS32, /* type */
252b5132
RH
191 0, /* rightshift */
192 2, /* size (0 = byte, 1 = short, 2 = long) */
193 32, /* bitsize */
b34976b6 194 FALSE, /* pc_relative */
252b5132
RH
195 0, /* bitpos */
196 complain_overflow_dont, /* complain_on_overflow */
197 v850_elf_reloc, /* special_function */
e30ddb24 198 "R_V850_ABS32", /* name */
b34976b6 199 FALSE, /* partial_inplace */
252b5132
RH
200 0xffffffff, /* src_mask */
201 0xffffffff, /* dst_mask */
b34976b6 202 FALSE), /* pcrel_offset */
252b5132
RH
203
204 /* Simple 16bit reloc. */
205 HOWTO (R_V850_16, /* type */
206 0, /* rightshift */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
208 16, /* bitsize */
b34976b6 209 FALSE, /* pc_relative */
252b5132
RH
210 0, /* bitpos */
211 complain_overflow_dont, /* complain_on_overflow */
212 bfd_elf_generic_reloc, /* special_function */
213 "R_V850_16", /* name */
b34976b6 214 FALSE, /* partial_inplace */
252b5132
RH
215 0xffff, /* src_mask */
216 0xffff, /* dst_mask */
b34976b6 217 FALSE), /* pcrel_offset */
252b5132
RH
218
219 /* Simple 8bit reloc. */
220 HOWTO (R_V850_8, /* type */
221 0, /* rightshift */
222 0, /* size (0 = byte, 1 = short, 2 = long) */
223 8, /* bitsize */
b34976b6 224 FALSE, /* pc_relative */
252b5132
RH
225 0, /* bitpos */
226 complain_overflow_dont, /* complain_on_overflow */
227 bfd_elf_generic_reloc, /* special_function */
228 "R_V850_8", /* name */
b34976b6 229 FALSE, /* partial_inplace */
252b5132
RH
230 0xff, /* src_mask */
231 0xff, /* dst_mask */
b34976b6 232 FALSE), /* pcrel_offset */
252b5132
RH
233
234 /* 16 bit offset from the short data area pointer. */
235 HOWTO (R_V850_SDA_16_16_OFFSET, /* type */
236 0, /* rightshift */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
238 16, /* bitsize */
b34976b6 239 FALSE, /* pc_relative */
252b5132
RH
240 0, /* bitpos */
241 complain_overflow_dont, /* complain_on_overflow */
242 v850_elf_reloc, /* special_function */
243 "R_V850_SDA_16_16_OFFSET", /* name */
b34976b6 244 FALSE, /* partial_inplace */
252b5132
RH
245 0xffff, /* src_mask */
246 0xffff, /* dst_mask */
b34976b6 247 FALSE), /* pcrel_offset */
252b5132
RH
248
249 /* 15 bit offset from the short data area pointer. */
250 HOWTO (R_V850_SDA_15_16_OFFSET, /* type */
251 1, /* rightshift */
252 1, /* size (0 = byte, 1 = short, 2 = long) */
253 16, /* bitsize */
b34976b6 254 FALSE, /* pc_relative */
252b5132
RH
255 1, /* bitpos */
256 complain_overflow_dont, /* complain_on_overflow */
257 v850_elf_reloc, /* special_function */
258 "R_V850_SDA_15_16_OFFSET", /* name */
b34976b6 259 FALSE, /* partial_inplace */
252b5132
RH
260 0xfffe, /* src_mask */
261 0xfffe, /* dst_mask */
b34976b6 262 FALSE), /* pcrel_offset */
252b5132
RH
263
264 /* 16 bit offset from the zero data area pointer. */
265 HOWTO (R_V850_ZDA_16_16_OFFSET, /* type */
266 0, /* rightshift */
267 1, /* size (0 = byte, 1 = short, 2 = long) */
268 16, /* bitsize */
b34976b6 269 FALSE, /* pc_relative */
252b5132
RH
270 0, /* bitpos */
271 complain_overflow_dont, /* complain_on_overflow */
272 v850_elf_reloc, /* special_function */
273 "R_V850_ZDA_16_16_OFFSET", /* name */
b34976b6 274 FALSE, /* partial_inplace */
252b5132
RH
275 0xffff, /* src_mask */
276 0xffff, /* dst_mask */
b34976b6 277 FALSE), /* pcrel_offset */
252b5132
RH
278
279 /* 15 bit offset from the zero data area pointer. */
280 HOWTO (R_V850_ZDA_15_16_OFFSET, /* type */
281 1, /* rightshift */
282 1, /* size (0 = byte, 1 = short, 2 = long) */
283 16, /* bitsize */
b34976b6 284 FALSE, /* pc_relative */
252b5132
RH
285 1, /* bitpos */
286 complain_overflow_dont, /* complain_on_overflow */
287 v850_elf_reloc, /* special_function */
288 "R_V850_ZDA_15_16_OFFSET", /* name */
b34976b6 289 FALSE, /* partial_inplace */
252b5132
RH
290 0xfffe, /* src_mask */
291 0xfffe, /* dst_mask */
b34976b6 292 FALSE), /* pcrel_offset */
252b5132
RH
293
294 /* 6 bit offset from the tiny data area pointer. */
295 HOWTO (R_V850_TDA_6_8_OFFSET, /* type */
296 2, /* rightshift */
297 1, /* size (0 = byte, 1 = short, 2 = long) */
298 8, /* bitsize */
b34976b6 299 FALSE, /* pc_relative */
252b5132
RH
300 1, /* bitpos */
301 complain_overflow_dont, /* complain_on_overflow */
302 v850_elf_reloc, /* special_function */
303 "R_V850_TDA_6_8_OFFSET", /* name */
b34976b6 304 FALSE, /* partial_inplace */
252b5132
RH
305 0x7e, /* src_mask */
306 0x7e, /* dst_mask */
b34976b6 307 FALSE), /* pcrel_offset */
252b5132
RH
308
309 /* 8 bit offset from the tiny data area pointer. */
310 HOWTO (R_V850_TDA_7_8_OFFSET, /* type */
311 1, /* rightshift */
312 1, /* size (0 = byte, 1 = short, 2 = long) */
313 8, /* bitsize */
b34976b6 314 FALSE, /* pc_relative */
252b5132
RH
315 0, /* bitpos */
316 complain_overflow_dont, /* complain_on_overflow */
317 v850_elf_reloc, /* special_function */
318 "R_V850_TDA_7_8_OFFSET", /* name */
b34976b6 319 FALSE, /* partial_inplace */
252b5132
RH
320 0x7f, /* src_mask */
321 0x7f, /* dst_mask */
b34976b6 322 FALSE), /* pcrel_offset */
435b1e90 323
252b5132
RH
324 /* 7 bit offset from the tiny data area pointer. */
325 HOWTO (R_V850_TDA_7_7_OFFSET, /* type */
326 0, /* rightshift */
327 1, /* size (0 = byte, 1 = short, 2 = long) */
328 7, /* bitsize */
b34976b6 329 FALSE, /* pc_relative */
252b5132
RH
330 0, /* bitpos */
331 complain_overflow_dont, /* complain_on_overflow */
332 v850_elf_reloc, /* special_function */
333 "R_V850_TDA_7_7_OFFSET", /* name */
b34976b6 334 FALSE, /* partial_inplace */
252b5132
RH
335 0x7f, /* src_mask */
336 0x7f, /* dst_mask */
b34976b6 337 FALSE), /* pcrel_offset */
252b5132
RH
338
339 /* 16 bit offset from the tiny data area pointer! */
340 HOWTO (R_V850_TDA_16_16_OFFSET, /* type */
341 0, /* rightshift */
342 1, /* size (0 = byte, 1 = short, 2 = long) */
343 16, /* bitsize */
b34976b6 344 FALSE, /* pc_relative */
252b5132
RH
345 0, /* bitpos */
346 complain_overflow_dont, /* complain_on_overflow */
347 v850_elf_reloc, /* special_function */
348 "R_V850_TDA_16_16_OFFSET", /* name */
b34976b6 349 FALSE, /* partial_inplace */
252b5132
RH
350 0xffff, /* src_mask */
351 0xfff, /* dst_mask */
b34976b6 352 FALSE), /* pcrel_offset */
252b5132
RH
353
354 /* 5 bit offset from the tiny data area pointer. */
355 HOWTO (R_V850_TDA_4_5_OFFSET, /* type */
356 1, /* rightshift */
357 1, /* size (0 = byte, 1 = short, 2 = long) */
358 5, /* bitsize */
b34976b6 359 FALSE, /* pc_relative */
252b5132
RH
360 0, /* bitpos */
361 complain_overflow_dont, /* complain_on_overflow */
362 v850_elf_reloc, /* special_function */
363 "R_V850_TDA_4_5_OFFSET", /* name */
b34976b6 364 FALSE, /* partial_inplace */
252b5132
RH
365 0x0f, /* src_mask */
366 0x0f, /* dst_mask */
b34976b6 367 FALSE), /* pcrel_offset */
252b5132
RH
368
369 /* 4 bit offset from the tiny data area pointer. */
370 HOWTO (R_V850_TDA_4_4_OFFSET, /* type */
371 0, /* rightshift */
372 1, /* size (0 = byte, 1 = short, 2 = long) */
373 4, /* bitsize */
b34976b6 374 FALSE, /* pc_relative */
252b5132
RH
375 0, /* bitpos */
376 complain_overflow_dont, /* complain_on_overflow */
377 v850_elf_reloc, /* special_function */
378 "R_V850_TDA_4_4_OFFSET", /* name */
b34976b6 379 FALSE, /* partial_inplace */
252b5132
RH
380 0x0f, /* src_mask */
381 0x0f, /* dst_mask */
b34976b6 382 FALSE), /* pcrel_offset */
252b5132
RH
383
384 /* 16 bit offset from the short data area pointer. */
385 HOWTO (R_V850_SDA_16_16_SPLIT_OFFSET, /* type */
386 0, /* rightshift */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
388 16, /* bitsize */
b34976b6 389 FALSE, /* pc_relative */
252b5132
RH
390 0, /* bitpos */
391 complain_overflow_dont, /* complain_on_overflow */
392 v850_elf_reloc, /* special_function */
393 "R_V850_SDA_16_16_SPLIT_OFFSET",/* name */
b34976b6 394 FALSE, /* partial_inplace */
252b5132
RH
395 0xfffe0020, /* src_mask */
396 0xfffe0020, /* dst_mask */
b34976b6 397 FALSE), /* pcrel_offset */
252b5132
RH
398
399 /* 16 bit offset from the zero data area pointer. */
400 HOWTO (R_V850_ZDA_16_16_SPLIT_OFFSET, /* type */
401 0, /* rightshift */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
403 16, /* bitsize */
b34976b6 404 FALSE, /* pc_relative */
252b5132
RH
405 0, /* bitpos */
406 complain_overflow_dont, /* complain_on_overflow */
407 v850_elf_reloc, /* special_function */
408 "R_V850_ZDA_16_16_SPLIT_OFFSET",/* name */
b34976b6 409 FALSE, /* partial_inplace */
252b5132
RH
410 0xfffe0020, /* src_mask */
411 0xfffe0020, /* dst_mask */
b34976b6 412 FALSE), /* pcrel_offset */
252b5132
RH
413
414 /* 6 bit offset from the call table base pointer. */
415 HOWTO (R_V850_CALLT_6_7_OFFSET, /* type */
416 0, /* rightshift */
417 1, /* size (0 = byte, 1 = short, 2 = long) */
418 7, /* bitsize */
b34976b6 419 FALSE, /* pc_relative */
252b5132
RH
420 0, /* bitpos */
421 complain_overflow_dont, /* complain_on_overflow */
422 v850_elf_reloc, /* special_function */
423 "R_V850_CALLT_6_7_OFFSET", /* name */
b34976b6 424 FALSE, /* partial_inplace */
252b5132
RH
425 0x3f, /* src_mask */
426 0x3f, /* dst_mask */
b34976b6 427 FALSE), /* pcrel_offset */
252b5132
RH
428
429 /* 16 bit offset from the call table base pointer. */
430 HOWTO (R_V850_CALLT_16_16_OFFSET, /* type */
431 0, /* rightshift */
432 1, /* size (0 = byte, 1 = short, 2 = long) */
433 16, /* bitsize */
b34976b6 434 FALSE, /* pc_relative */
252b5132
RH
435 0, /* bitpos */
436 complain_overflow_dont, /* complain_on_overflow */
437 v850_elf_reloc, /* special_function */
438 "R_V850_CALLT_16_16_OFFSET", /* name */
b34976b6 439 FALSE, /* partial_inplace */
252b5132
RH
440 0xffff, /* src_mask */
441 0xffff, /* dst_mask */
b34976b6 442 FALSE), /* pcrel_offset */
252b5132
RH
443
444 /* GNU extension to record C++ vtable hierarchy */
445 HOWTO (R_V850_GNU_VTINHERIT, /* type */
446 0, /* rightshift */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
448 0, /* bitsize */
b34976b6 449 FALSE, /* pc_relative */
252b5132
RH
450 0, /* bitpos */
451 complain_overflow_dont, /* complain_on_overflow */
452 NULL, /* special_function */
453 "R_V850_GNU_VTINHERIT", /* name */
b34976b6 454 FALSE, /* partial_inplace */
252b5132
RH
455 0, /* src_mask */
456 0, /* dst_mask */
b34976b6 457 FALSE), /* pcrel_offset */
252b5132
RH
458
459 /* GNU extension to record C++ vtable member usage */
460 HOWTO (R_V850_GNU_VTENTRY, /* type */
461 0, /* rightshift */
462 2, /* size (0 = byte, 1 = short, 2 = long) */
463 0, /* bitsize */
b34976b6 464 FALSE, /* pc_relative */
252b5132
RH
465 0, /* bitpos */
466 complain_overflow_dont, /* complain_on_overflow */
467 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
468 "R_V850_GNU_VTENTRY", /* name */
b34976b6 469 FALSE, /* partial_inplace */
252b5132
RH
470 0, /* src_mask */
471 0, /* dst_mask */
b34976b6 472 FALSE), /* pcrel_offset */
435b1e90 473
86aba9db
NC
474 /* Indicates a .longcall pseudo-op. The compiler will generate a .longcall
475 pseudo-op when it finds a function call which can be relaxed. */
476 HOWTO (R_V850_LONGCALL, /* type */
477 0, /* rightshift */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
479 32, /* bitsize */
b34976b6 480 TRUE, /* pc_relative */
86aba9db
NC
481 0, /* bitpos */
482 complain_overflow_signed, /* complain_on_overflow */
483 v850_elf_ignore_reloc, /* special_function */
484 "R_V850_LONGCALL", /* name */
b34976b6 485 FALSE, /* partial_inplace */
86aba9db
NC
486 0, /* src_mask */
487 0, /* dst_mask */
b34976b6 488 TRUE), /* pcrel_offset */
86aba9db
NC
489
490 /* Indicates a .longjump pseudo-op. The compiler will generate a
491 .longjump pseudo-op when it finds a branch which can be relaxed. */
492 HOWTO (R_V850_LONGJUMP, /* type */
493 0, /* rightshift */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
495 32, /* bitsize */
b34976b6 496 TRUE, /* pc_relative */
86aba9db
NC
497 0, /* bitpos */
498 complain_overflow_signed, /* complain_on_overflow */
499 v850_elf_ignore_reloc, /* special_function */
500 "R_V850_LONGJUMP", /* name */
b34976b6 501 FALSE, /* partial_inplace */
86aba9db
NC
502 0, /* src_mask */
503 0, /* dst_mask */
b34976b6 504 TRUE), /* pcrel_offset */
86aba9db
NC
505
506 HOWTO (R_V850_ALIGN, /* type */
507 0, /* rightshift */
508 1, /* size (0 = byte, 1 = short, 2 = long) */
509 0, /* bitsize */
b34976b6 510 FALSE, /* pc_relative */
86aba9db
NC
511 0, /* bitpos */
512 complain_overflow_unsigned, /* complain_on_overflow */
513 v850_elf_ignore_reloc, /* special_function */
514 "R_V850_ALIGN", /* name */
b34976b6 515 FALSE, /* partial_inplace */
86aba9db
NC
516 0, /* src_mask */
517 0, /* dst_mask */
b34976b6 518 TRUE), /* pcrel_offset */
e30ddb24
NC
519
520 /* Simple pc-relative 32bit reloc. */
521 HOWTO (R_V850_REL32, /* type */
522 0, /* rightshift */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
524 32, /* bitsize */
525 TRUE, /* pc_relative */
526 0, /* bitpos */
527 complain_overflow_dont, /* complain_on_overflow */
528 v850_elf_reloc, /* special_function */
529 "R_V850_REL32", /* name */
530 FALSE, /* partial_inplace */
531 0xffffffff, /* src_mask */
532 0xffffffff, /* dst_mask */
533 FALSE), /* pcrel_offset */
1e50d24d
RS
534
535 /* An ld.bu version of R_V850_LO16. */
536 HOWTO (R_V850_LO16_SPLIT_OFFSET, /* type */
537 0, /* rightshift */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
539 16, /* bitsize */
540 FALSE, /* pc_relative */
541 0, /* bitpos */
542 complain_overflow_dont, /* complain_on_overflow */
543 v850_elf_reloc, /* special_function */
544 "R_V850_LO16_SPLIT_OFFSET", /* name */
545 FALSE, /* partial_inplace */
546 0xfffe0020, /* src_mask */
547 0xfffe0020, /* dst_mask */
548 FALSE), /* pcrel_offset */
252b5132
RH
549};
550
551/* Map BFD reloc types to V850 ELF reloc types. */
552
553struct v850_elf_reloc_map
554{
555 /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an
556 unsigned char. */
557 bfd_reloc_code_real_type bfd_reloc_val;
917583ad 558 unsigned int elf_reloc_val;
252b5132
RH
559};
560
561static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
562{
86aba9db
NC
563 { BFD_RELOC_NONE, R_V850_NONE },
564 { BFD_RELOC_V850_9_PCREL, R_V850_9_PCREL },
565 { BFD_RELOC_V850_22_PCREL, R_V850_22_PCREL },
566 { BFD_RELOC_HI16_S, R_V850_HI16_S },
567 { BFD_RELOC_HI16, R_V850_HI16 },
568 { BFD_RELOC_LO16, R_V850_LO16 },
e30ddb24
NC
569 { BFD_RELOC_32, R_V850_ABS32 },
570 { BFD_RELOC_32_PCREL, R_V850_REL32 },
86aba9db
NC
571 { BFD_RELOC_16, R_V850_16 },
572 { BFD_RELOC_8, R_V850_8 },
573 { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V850_SDA_16_16_OFFSET },
574 { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V850_SDA_15_16_OFFSET },
575 { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V850_ZDA_16_16_OFFSET },
576 { BFD_RELOC_V850_ZDA_15_16_OFFSET, R_V850_ZDA_15_16_OFFSET },
577 { BFD_RELOC_V850_TDA_6_8_OFFSET, R_V850_TDA_6_8_OFFSET },
578 { BFD_RELOC_V850_TDA_7_8_OFFSET, R_V850_TDA_7_8_OFFSET },
579 { BFD_RELOC_V850_TDA_7_7_OFFSET, R_V850_TDA_7_7_OFFSET },
580 { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V850_TDA_16_16_OFFSET },
252b5132
RH
581 { BFD_RELOC_V850_TDA_4_5_OFFSET, R_V850_TDA_4_5_OFFSET },
582 { BFD_RELOC_V850_TDA_4_4_OFFSET, R_V850_TDA_4_4_OFFSET },
1e50d24d 583 { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_LO16_SPLIT_OFFSET },
252b5132
RH
584 { BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET, R_V850_SDA_16_16_SPLIT_OFFSET },
585 { BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET, R_V850_ZDA_16_16_SPLIT_OFFSET },
586 { BFD_RELOC_V850_CALLT_6_7_OFFSET, R_V850_CALLT_6_7_OFFSET },
587 { BFD_RELOC_V850_CALLT_16_16_OFFSET, R_V850_CALLT_16_16_OFFSET },
86aba9db
NC
588 { BFD_RELOC_VTABLE_INHERIT, R_V850_GNU_VTINHERIT },
589 { BFD_RELOC_VTABLE_ENTRY, R_V850_GNU_VTENTRY },
590 { BFD_RELOC_V850_LONGCALL, R_V850_LONGCALL },
591 { BFD_RELOC_V850_LONGJUMP, R_V850_LONGJUMP },
592 { BFD_RELOC_V850_ALIGN, R_V850_ALIGN },
252b5132
RH
593
594};
252b5132 595\f
e12dd2ea
NC
596/* Map a bfd relocation into the appropriate howto structure. */
597
252b5132
RH
598static reloc_howto_type *
599v850_elf_reloc_type_lookup (abfd, code)
b34976b6
AM
600 bfd *abfd ATTRIBUTE_UNUSED;
601 bfd_reloc_code_real_type code;
252b5132
RH
602{
603 unsigned int i;
604
e12dd2ea
NC
605 for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;)
606 if (v850_elf_reloc_map[i].bfd_reloc_val == code)
607 {
917583ad 608 unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val;
dc810e39 609
fbad9a25 610 BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val);
435b1e90 611
fbad9a25 612 return v850_elf_howto_table + elf_reloc_val;
e12dd2ea 613 }
252b5132
RH
614
615 return NULL;
616}
252b5132
RH
617\f
618/* Set the howto pointer for an V850 ELF reloc. */
e12dd2ea 619
252b5132
RH
620static void
621v850_elf_info_to_howto_rel (abfd, cache_ptr, dst)
b34976b6
AM
622 bfd *abfd ATTRIBUTE_UNUSED;
623 arelent *cache_ptr;
624 Elf_Internal_Rela *dst;
252b5132
RH
625{
626 unsigned int r_type;
627
628 r_type = ELF32_R_TYPE (dst->r_info);
629 BFD_ASSERT (r_type < (unsigned int) R_V850_max);
630 cache_ptr->howto = &v850_elf_howto_table[r_type];
631}
632
435b1e90 633/* Set the howto pointer for a V850 ELF reloc (type RELA). */
252b5132
RH
634static void
635v850_elf_info_to_howto_rela (abfd, cache_ptr, dst)
b34976b6
AM
636 bfd *abfd ATTRIBUTE_UNUSED;
637 arelent * cache_ptr;
638 Elf_Internal_Rela *dst;
252b5132
RH
639{
640 unsigned int r_type;
641
642 r_type = ELF32_R_TYPE (dst->r_info);
643 BFD_ASSERT (r_type < (unsigned int) R_V850_max);
644 cache_ptr->howto = &v850_elf_howto_table[r_type];
645}
252b5132
RH
646\f
647/* Look through the relocs for a section during the first phase, and
648 allocate space in the global offset table or procedure linkage
649 table. */
650
b34976b6 651static bfd_boolean
252b5132 652v850_elf_check_relocs (abfd, info, sec, relocs)
b34976b6
AM
653 bfd *abfd;
654 struct bfd_link_info *info;
655 asection *sec;
656 const Elf_Internal_Rela *relocs;
252b5132 657{
b34976b6 658 bfd_boolean ret = TRUE;
252b5132
RH
659 bfd *dynobj;
660 Elf_Internal_Shdr *symtab_hdr;
661 struct elf_link_hash_entry **sym_hashes;
662 const Elf_Internal_Rela *rel;
663 const Elf_Internal_Rela *rel_end;
664 asection *sreloc;
665 enum v850_reloc_type r_type;
666 int other = 0;
667 const char *common = (const char *)0;
668
1049f94e 669 if (info->relocatable)
b34976b6 670 return TRUE;
252b5132
RH
671
672#ifdef DEBUG
d003868e
AM
673 _bfd_error_handler ("v850_elf_check_relocs called for section %A in %B",
674 sec, abfd);
252b5132
RH
675#endif
676
677 dynobj = elf_hash_table (info)->dynobj;
678 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
679 sym_hashes = elf_sym_hashes (abfd);
680 sreloc = NULL;
681
682 rel_end = relocs + sec->reloc_count;
683 for (rel = relocs; rel < rel_end; rel++)
684 {
685 unsigned long r_symndx;
686 struct elf_link_hash_entry *h;
687
688 r_symndx = ELF32_R_SYM (rel->r_info);
689 if (r_symndx < symtab_hdr->sh_info)
690 h = NULL;
691 else
973a3492
L
692 {
693 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
694 while (h->root.type == bfd_link_hash_indirect
695 || h->root.type == bfd_link_hash_warning)
696 h = (struct elf_link_hash_entry *) h->root.u.i.link;
697 }
252b5132
RH
698
699 r_type = (enum v850_reloc_type) ELF32_R_TYPE (rel->r_info);
700 switch (r_type)
701 {
702 default:
703 case R_V850_NONE:
704 case R_V850_9_PCREL:
705 case R_V850_22_PCREL:
706 case R_V850_HI16_S:
707 case R_V850_HI16:
708 case R_V850_LO16:
1e50d24d 709 case R_V850_LO16_SPLIT_OFFSET:
e30ddb24
NC
710 case R_V850_ABS32:
711 case R_V850_REL32:
252b5132
RH
712 case R_V850_16:
713 case R_V850_8:
714 case R_V850_CALLT_6_7_OFFSET:
715 case R_V850_CALLT_16_16_OFFSET:
716 break;
717
718 /* This relocation describes the C++ object vtable hierarchy.
719 Reconstruct it for later use during GC. */
720 case R_V850_GNU_VTINHERIT:
c152c796 721 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
b34976b6 722 return FALSE;
252b5132
RH
723 break;
724
e12dd2ea
NC
725 /* This relocation describes which C++ vtable entries
726 are actually used. Record for later use during GC. */
252b5132 727 case R_V850_GNU_VTENTRY:
c152c796 728 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
b34976b6 729 return FALSE;
252b5132
RH
730 break;
731
732 case R_V850_SDA_16_16_SPLIT_OFFSET:
733 case R_V850_SDA_16_16_OFFSET:
734 case R_V850_SDA_15_16_OFFSET:
735 other = V850_OTHER_SDA;
736 common = ".scommon";
737 goto small_data_common;
435b1e90 738
252b5132
RH
739 case R_V850_ZDA_16_16_SPLIT_OFFSET:
740 case R_V850_ZDA_16_16_OFFSET:
741 case R_V850_ZDA_15_16_OFFSET:
742 other = V850_OTHER_ZDA;
743 common = ".zcommon";
744 goto small_data_common;
435b1e90 745
252b5132
RH
746 case R_V850_TDA_4_5_OFFSET:
747 case R_V850_TDA_4_4_OFFSET:
748 case R_V850_TDA_6_8_OFFSET:
749 case R_V850_TDA_7_8_OFFSET:
750 case R_V850_TDA_7_7_OFFSET:
751 case R_V850_TDA_16_16_OFFSET:
752 other = V850_OTHER_TDA;
753 common = ".tcommon";
754 /* fall through */
755
756#define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA)
757
758 small_data_common:
759 if (h)
760 {
e12dd2ea
NC
761 /* Flag which type of relocation was used. */
762 h->other |= other;
252b5132
RH
763 if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
764 && (h->other & V850_OTHER_ERROR) == 0)
765 {
766 const char * msg;
767 static char buff[200]; /* XXX */
768
769 switch (h->other & V850_OTHER_MASK)
770 {
771 default:
772 msg = _("Variable `%s' cannot occupy in multiple small data regions");
773 break;
774 case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA:
775 msg = _("Variable `%s' can only be in one of the small, zero, and tiny data regions");
776 break;
777 case V850_OTHER_SDA | V850_OTHER_ZDA:
778 msg = _("Variable `%s' cannot be in both small and zero data regions simultaneously");
779 break;
780 case V850_OTHER_SDA | V850_OTHER_TDA:
781 msg = _("Variable `%s' cannot be in both small and tiny data regions simultaneously");
782 break;
783 case V850_OTHER_ZDA | V850_OTHER_TDA:
784 msg = _("Variable `%s' cannot be in both zero and tiny data regions simultaneously");
785 break;
786 }
787
788 sprintf (buff, msg, h->root.root.string);
789 info->callbacks->warning (info, buff, h->root.root.string,
dc810e39
AM
790 abfd, h->root.u.def.section,
791 (bfd_vma) 0);
252b5132
RH
792
793 bfd_set_error (bfd_error_bad_value);
794 h->other |= V850_OTHER_ERROR;
b34976b6 795 ret = FALSE;
252b5132
RH
796 }
797 }
798
799 if (h && h->root.type == bfd_link_hash_common
800 && h->root.u.c.p
801 && !strcmp (bfd_get_section_name (abfd, h->root.u.c.p->section), "COMMON"))
802 {
e12dd2ea
NC
803 asection * section;
804
805 section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
252b5132
RH
806 section->flags |= SEC_IS_COMMON;
807 }
808
809#ifdef DEBUG
810 fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n",
811 v850_elf_howto_table[ (int)r_type ].name,
812 (h && h->root.root.string) ? h->root.root.string : "<unknown>",
813 (h->root.type == bfd_link_hash_common) ? ", symbol is common" : "");
814#endif
815 break;
816 }
817 }
818
819 return ret;
820}
821
e12dd2ea
NC
822/* In the old version, when an entry was checked out from the table,
823 it was deleted. This produced an error if the entry was needed
824 more than once, as the second attempted retry failed.
825
826 In the current version, the entry is not deleted, instead we set
b34976b6 827 the field 'found' to TRUE. If a second lookup matches the same
e12dd2ea
NC
828 entry, then we know that the hi16s reloc has already been updated
829 and does not need to be updated a second time.
830
831 TODO - TOFIX: If it is possible that we need to restore 2 different
832 addresses from the same table entry, where the first generates an
833 overflow, whilst the second do not, then this code will fail. */
252b5132
RH
834
835typedef struct hi16s_location
836{
b34976b6
AM
837 bfd_vma addend;
838 bfd_byte *address;
252b5132 839 unsigned long counter;
b34976b6
AM
840 bfd_boolean found;
841 struct hi16s_location *next;
252b5132
RH
842}
843hi16s_location;
844
b34976b6
AM
845static hi16s_location *previous_hi16s;
846static hi16s_location *free_hi16s;
847static unsigned long hi16s_counter;
252b5132
RH
848
849static void
850remember_hi16s_reloc (abfd, addend, address)
b34976b6
AM
851 bfd *abfd;
852 bfd_vma addend;
853 bfd_byte *address;
252b5132
RH
854{
855 hi16s_location * entry = NULL;
dc810e39 856 bfd_size_type amt = sizeof (* free_hi16s);
435b1e90 857
252b5132
RH
858 /* Find a free structure. */
859 if (free_hi16s == NULL)
dc810e39 860 free_hi16s = (hi16s_location *) bfd_zalloc (abfd, amt);
252b5132
RH
861
862 entry = free_hi16s;
863 free_hi16s = free_hi16s->next;
435b1e90 864
252b5132
RH
865 entry->addend = addend;
866 entry->address = address;
867 entry->counter = hi16s_counter ++;
b34976b6 868 entry->found = FALSE;
252b5132
RH
869 entry->next = previous_hi16s;
870 previous_hi16s = entry;
435b1e90 871
252b5132
RH
872 /* Cope with wrap around of our counter. */
873 if (hi16s_counter == 0)
874 {
875 /* XXX - Assume that all counter entries differ only in their low 16 bits. */
876 for (entry = previous_hi16s; entry != NULL; entry = entry->next)
877 entry->counter &= 0xffff;
878
879 hi16s_counter = 0x10000;
880 }
435b1e90 881
252b5132
RH
882 return;
883}
884
885static bfd_byte *
886find_remembered_hi16s_reloc (addend, already_found)
b34976b6
AM
887 bfd_vma addend;
888 bfd_boolean *already_found;
252b5132 889{
b34976b6
AM
890 hi16s_location *match = NULL;
891 hi16s_location *entry;
892 hi16s_location *previous = NULL;
893 hi16s_location *prev;
894 bfd_byte *addr;
435b1e90 895
252b5132
RH
896 /* Search the table. Record the most recent entry that matches. */
897 for (entry = previous_hi16s; entry; entry = entry->next)
898 {
899 if (entry->addend == addend
900 && (match == NULL || match->counter < entry->counter))
901 {
902 previous = prev;
903 match = entry;
904 }
435b1e90 905
252b5132
RH
906 prev = entry;
907 }
908
909 if (match == NULL)
910 return NULL;
911
912 /* Extract the address. */
913 addr = match->address;
914
4cc11e76 915 /* Remember if this entry has already been used before. */
252b5132
RH
916 if (already_found)
917 * already_found = match->found;
918
919 /* Note that this entry has now been used. */
b34976b6 920 match->found = TRUE;
435b1e90 921
252b5132 922 return addr;
435b1e90 923}
252b5132 924
1e50d24d
RS
925/* Calculate the final operand value for a R_V850_LO16 or
926 R_V850_LO16_SPLIT_OFFSET. *INSN is the current operand value and
927 ADDEND is the sum of the relocation symbol and offset. Store the
928 operand value in *INSN and return true on success.
929
930 The assembler has already done some of this: If the value stored in
931 the instruction has its 15th bit set, (counting from zero) then the
932 assembler will have added 1 to the value stored in the associated
933 HI16S reloc. So for example, these relocations:
934
935 movhi hi( fred ), r0, r1
936 movea lo( fred ), r1, r1
937
938 will store 0 in the value fields for the MOVHI and MOVEA instructions
939 and addend will be the address of fred, but for these instructions:
940
941 movhi hi( fred + 0x123456), r0, r1
942 movea lo( fred + 0x123456), r1, r1
943
944 the value stored in the MOVHI instruction will be 0x12 and the value
945 stored in the MOVEA instruction will be 0x3456. If however the
946 instructions were:
947
948 movhi hi( fred + 0x10ffff), r0, r1
949 movea lo( fred + 0x10ffff), r1, r1
950
951 then the value stored in the MOVHI instruction would be 0x11 (not
952 0x10) and the value stored in the MOVEA instruction would be 0xffff.
953 Thus (assuming for the moment that the addend is 0), at run time the
954 MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction
955 adds 0xffffffff (sign extension!) producing 0x10ffff. Similarly if
956 the instructions were:
957
958 movhi hi( fred - 1), r0, r1
959 movea lo( fred - 1), r1, r1
960
961 then 0 is stored in the MOVHI instruction and -1 is stored in the
962 MOVEA instruction.
963
964 Overflow can occur if the addition of the value stored in the
965 instruction plus the addend sets the 15th bit when before it was clear.
966 This is because the 15th bit will be sign extended into the high part,
967 thus reducing its value by one, but since the 15th bit was originally
968 clear, the assembler will not have added 1 to the previous HI16S reloc
969 to compensate for this effect. For example:
970
971 movhi hi( fred + 0x123456), r0, r1
972 movea lo( fred + 0x123456), r1, r1
973
974 The value stored in HI16S reloc is 0x12, the value stored in the LO16
975 reloc is 0x3456. If we assume that the address of fred is 0x00007000
976 then the relocations become:
977
978 HI16S: 0x0012 + (0x00007000 >> 16) = 0x12
979 LO16: 0x3456 + (0x00007000 & 0xffff) = 0xa456
980
981 but when the instructions are executed, the MOVEA instruction's value
982 is signed extended, so the sum becomes:
983
984 0x00120000
985 + 0xffffa456
986 ------------
987 0x0011a456 but 'fred + 0x123456' = 0x0012a456
988
989 Note that if the 15th bit was set in the value stored in the LO16
990 reloc, then we do not have to do anything:
991
992 movhi hi( fred + 0x10ffff), r0, r1
993 movea lo( fred + 0x10ffff), r1, r1
994
995 HI16S: 0x0011 + (0x00007000 >> 16) = 0x11
996 LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff
997
998 0x00110000
999 + 0x00006fff
1000 ------------
1001 0x00116fff = fred + 0x10ffff = 0x7000 + 0x10ffff
1002
1003 Overflow can also occur if the computation carries into the 16th bit
1004 and it also results in the 15th bit having the same value as the 15th
1005 bit of the original value. What happens is that the HI16S reloc
1006 will have already examined the 15th bit of the original value and
1007 added 1 to the high part if the bit is set. This compensates for the
1008 sign extension of 15th bit of the result of the computation. But now
1009 there is a carry into the 16th bit, and this has not been allowed for.
1010
1011 So, for example if fred is at address 0xf000:
1012
1013 movhi hi( fred + 0xffff), r0, r1 [bit 15 of the offset is set]
1014 movea lo( fred + 0xffff), r1, r1
1015
1016 HI16S: 0x0001 + (0x0000f000 >> 16) = 0x0001
1017 LO16: 0xffff + (0x0000f000 & 0xffff) = 0xefff (carry into bit 16 is lost)
1018
1019 0x00010000
1020 + 0xffffefff
1021 ------------
1022 0x0000efff but 'fred + 0xffff' = 0x0001efff
1023
1024 Similarly, if the 15th bit remains clear, but overflow occurs into
1025 the 16th bit then (assuming the address of fred is 0xf000):
1026
1027 movhi hi( fred + 0x7000), r0, r1 [bit 15 of the offset is clear]
1028 movea lo( fred + 0x7000), r1, r1
1029
1030 HI16S: 0x0000 + (0x0000f000 >> 16) = 0x0000
1031 LO16: 0x7000 + (0x0000f000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
1032
1033 0x00000000
1034 + 0x00006fff
1035 ------------
1036 0x00006fff but 'fred + 0x7000' = 0x00016fff
1037
1038 Note - there is no need to change anything if a carry occurs, and the
1039 15th bit changes its value from being set to being clear, as the HI16S
1040 reloc will have already added in 1 to the high part for us:
1041
1042 movhi hi( fred + 0xffff), r0, r1 [bit 15 of the offset is set]
1043 movea lo( fred + 0xffff), r1, r1
1044
1045 HI16S: 0x0001 + (0x00007000 >> 16)
1046 LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
1047
1048 0x00010000
1049 + 0x00006fff (bit 15 not set, so the top half is zero)
1050 ------------
1051 0x00016fff which is right (assuming that fred is at 0x7000)
1052
1053 but if the 15th bit goes from being clear to being set, then we must
1054 once again handle overflow:
1055
1056 movhi hi( fred + 0x7000), r0, r1 [bit 15 of the offset is clear]
1057 movea lo( fred + 0x7000), r1, r1
1058
1059 HI16S: 0x0000 + (0x0000ffff >> 16)
1060 LO16: 0x7000 + (0x0000ffff & 0xffff) = 0x6fff (carry into bit 16)
1061
1062 0x00000000
1063 + 0x00006fff (bit 15 not set, so the top half is zero)
1064 ------------
1065 0x00006fff which is wrong (assuming that fred is at 0xffff). */
1066
1067static bfd_boolean
1068v850_elf_perform_lo16_relocation (bfd *abfd, unsigned long *insn,
1069 unsigned long addend)
1070{
1071#define BIT15_SET(x) ((x) & 0x8000)
1072#define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff)
1073 if ((BIT15_SET (*insn + addend) && ! BIT15_SET (addend))
1074 || (OVERFLOWS (addend, *insn)
1075 && ((! BIT15_SET (*insn)) || (BIT15_SET (addend)))))
1076 {
1077 bfd_boolean already_updated;
1078 bfd_byte *hi16s_address = find_remembered_hi16s_reloc
1079 (addend, & already_updated);
1080
1081 /* Amend the matching HI16_S relocation. */
1082 if (hi16s_address != NULL)
1083 {
1084 if (! already_updated)
1085 {
1086 unsigned long hi_insn = bfd_get_16 (abfd, hi16s_address);
1087 hi_insn += 1;
1088 bfd_put_16 (abfd, hi_insn, hi16s_address);
1089 }
1090 }
1091 else
1092 {
1093 fprintf (stderr, _("FAILED to find previous HI16 reloc\n"));
1094 return FALSE;
1095 }
1096 }
1097#undef OVERFLOWS
1098#undef BIT15_SET
1099
1100 /* Do not complain if value has top bit set, as this has been
1101 anticipated. */
1102 *insn = (*insn + addend) & 0xffff;
1103 return TRUE;
1104}
1105
252b5132 1106/* FIXME: The code here probably ought to be removed and the code in reloc.c
4cc11e76 1107 allowed to do its stuff instead. At least for most of the relocs, anyway. */
e12dd2ea 1108
252b5132
RH
1109static bfd_reloc_status_type
1110v850_elf_perform_relocation (abfd, r_type, addend, address)
dc810e39
AM
1111 bfd *abfd;
1112 unsigned int r_type;
1113 bfd_vma addend;
1114 bfd_byte *address;
252b5132
RH
1115{
1116 unsigned long insn;
1e50d24d 1117 unsigned long result;
252b5132 1118 bfd_signed_vma saddend = (bfd_signed_vma) addend;
435b1e90 1119
252b5132
RH
1120 switch (r_type)
1121 {
1122 default:
1123 /* fprintf (stderr, "reloc type %d not SUPPORTED\n", r_type ); */
1124 return bfd_reloc_notsupported;
435b1e90 1125
e30ddb24
NC
1126 case R_V850_REL32:
1127 case R_V850_ABS32:
252b5132
RH
1128 bfd_put_32 (abfd, addend, address);
1129 return bfd_reloc_ok;
435b1e90 1130
252b5132
RH
1131 case R_V850_22_PCREL:
1132 if (saddend > 0x1fffff || saddend < -0x200000)
1133 return bfd_reloc_overflow;
435b1e90 1134
252b5132
RH
1135 if ((addend % 2) != 0)
1136 return bfd_reloc_dangerous;
435b1e90 1137
252b5132
RH
1138 insn = bfd_get_32 (abfd, address);
1139 insn &= ~0xfffe003f;
1140 insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16));
dc810e39 1141 bfd_put_32 (abfd, (bfd_vma) insn, address);
252b5132 1142 return bfd_reloc_ok;
435b1e90 1143
252b5132
RH
1144 case R_V850_9_PCREL:
1145 if (saddend > 0xff || saddend < -0x100)
1146 return bfd_reloc_overflow;
435b1e90 1147
252b5132
RH
1148 if ((addend % 2) != 0)
1149 return bfd_reloc_dangerous;
435b1e90 1150
252b5132
RH
1151 insn = bfd_get_16 (abfd, address);
1152 insn &= ~ 0xf870;
1153 insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3);
1154 break;
435b1e90 1155
252b5132
RH
1156 case R_V850_HI16:
1157 addend += (bfd_get_16 (abfd, address) << 16);
1158 addend = (addend >> 16);
1159 insn = addend;
1160 break;
435b1e90 1161
252b5132
RH
1162 case R_V850_HI16_S:
1163 /* Remember where this relocation took place. */
1164 remember_hi16s_reloc (abfd, addend, address);
1165
1166 addend += (bfd_get_16 (abfd, address) << 16);
1167 addend = (addend >> 16) + ((addend & 0x8000) != 0);
435b1e90
KH
1168
1169 /* This relocation cannot overflow. */
252b5132
RH
1170 if (addend > 0x7fff)
1171 addend = 0;
435b1e90 1172
252b5132
RH
1173 insn = addend;
1174 break;
435b1e90 1175
252b5132 1176 case R_V850_LO16:
1e50d24d
RS
1177 insn = bfd_get_16 (abfd, address);
1178 if (! v850_elf_perform_lo16_relocation (abfd, &insn, addend))
1179 return bfd_reloc_overflow;
1180 break;
252b5132
RH
1181
1182 case R_V850_8:
1183 addend += (char) bfd_get_8 (abfd, address);
1184
1185 saddend = (bfd_signed_vma) addend;
435b1e90 1186
252b5132
RH
1187 if (saddend > 0x7f || saddend < -0x80)
1188 return bfd_reloc_overflow;
1189
1190 bfd_put_8 (abfd, addend, address);
1191 return bfd_reloc_ok;
1192
1193 case R_V850_CALLT_16_16_OFFSET:
1194 addend += bfd_get_16 (abfd, address);
435b1e90 1195
252b5132 1196 saddend = (bfd_signed_vma) addend;
435b1e90 1197
252b5132
RH
1198 if (saddend > 0xffff || saddend < 0)
1199 return bfd_reloc_overflow;
1200
1201 insn = addend;
1202 break;
435b1e90 1203
252b5132
RH
1204 case R_V850_16:
1205
435b1e90 1206 /* drop through */
252b5132
RH
1207 case R_V850_SDA_16_16_OFFSET:
1208 case R_V850_ZDA_16_16_OFFSET:
1209 case R_V850_TDA_16_16_OFFSET:
1210 addend += bfd_get_16 (abfd, address);
435b1e90 1211
252b5132 1212 saddend = (bfd_signed_vma) addend;
435b1e90 1213
252b5132
RH
1214 if (saddend > 0x7fff || saddend < -0x8000)
1215 return bfd_reloc_overflow;
1216
1217 insn = addend;
1218 break;
435b1e90 1219
252b5132
RH
1220 case R_V850_SDA_15_16_OFFSET:
1221 case R_V850_ZDA_15_16_OFFSET:
1222 insn = bfd_get_16 (abfd, address);
1223 addend += (insn & 0xfffe);
435b1e90 1224
252b5132 1225 saddend = (bfd_signed_vma) addend;
435b1e90 1226
252b5132
RH
1227 if (saddend > 0x7ffe || saddend < -0x8000)
1228 return bfd_reloc_overflow;
435b1e90 1229
252b5132
RH
1230 if (addend & 1)
1231 return bfd_reloc_dangerous;
435b1e90 1232
dc810e39 1233 insn = (addend &~ (bfd_vma) 1) | (insn & 1);
252b5132 1234 break;
435b1e90 1235
252b5132
RH
1236 case R_V850_TDA_6_8_OFFSET:
1237 insn = bfd_get_16 (abfd, address);
1238 addend += ((insn & 0x7e) << 1);
435b1e90 1239
252b5132 1240 saddend = (bfd_signed_vma) addend;
435b1e90 1241
252b5132
RH
1242 if (saddend > 0xfc || saddend < 0)
1243 return bfd_reloc_overflow;
435b1e90 1244
252b5132
RH
1245 if (addend & 3)
1246 return bfd_reloc_dangerous;
435b1e90 1247
252b5132
RH
1248 insn &= 0xff81;
1249 insn |= (addend >> 1);
1250 break;
435b1e90 1251
252b5132
RH
1252 case R_V850_TDA_7_8_OFFSET:
1253 insn = bfd_get_16 (abfd, address);
1254 addend += ((insn & 0x7f) << 1);
435b1e90 1255
252b5132 1256 saddend = (bfd_signed_vma) addend;
435b1e90 1257
252b5132
RH
1258 if (saddend > 0xfe || saddend < 0)
1259 return bfd_reloc_overflow;
435b1e90 1260
252b5132
RH
1261 if (addend & 1)
1262 return bfd_reloc_dangerous;
435b1e90 1263
252b5132
RH
1264 insn &= 0xff80;
1265 insn |= (addend >> 1);
1266 break;
435b1e90 1267
252b5132
RH
1268 case R_V850_TDA_7_7_OFFSET:
1269 insn = bfd_get_16 (abfd, address);
1270 addend += insn & 0x7f;
435b1e90 1271
252b5132 1272 saddend = (bfd_signed_vma) addend;
435b1e90 1273
252b5132
RH
1274 if (saddend > 0x7f || saddend < 0)
1275 return bfd_reloc_overflow;
435b1e90 1276
252b5132
RH
1277 insn &= 0xff80;
1278 insn |= addend;
1279 break;
435b1e90 1280
252b5132
RH
1281 case R_V850_TDA_4_5_OFFSET:
1282 insn = bfd_get_16 (abfd, address);
1283 addend += ((insn & 0xf) << 1);
435b1e90 1284
252b5132 1285 saddend = (bfd_signed_vma) addend;
435b1e90 1286
252b5132
RH
1287 if (saddend > 0x1e || saddend < 0)
1288 return bfd_reloc_overflow;
435b1e90 1289
252b5132
RH
1290 if (addend & 1)
1291 return bfd_reloc_dangerous;
435b1e90 1292
252b5132
RH
1293 insn &= 0xfff0;
1294 insn |= (addend >> 1);
1295 break;
435b1e90 1296
252b5132
RH
1297 case R_V850_TDA_4_4_OFFSET:
1298 insn = bfd_get_16 (abfd, address);
1299 addend += insn & 0xf;
435b1e90 1300
252b5132 1301 saddend = (bfd_signed_vma) addend;
435b1e90 1302
252b5132
RH
1303 if (saddend > 0xf || saddend < 0)
1304 return bfd_reloc_overflow;
435b1e90 1305
252b5132
RH
1306 insn &= 0xfff0;
1307 insn |= addend;
1308 break;
435b1e90 1309
1e50d24d
RS
1310 case R_V850_LO16_SPLIT_OFFSET:
1311 insn = bfd_get_32 (abfd, address);
1312 result = ((insn & 0xfffe0000) >> 16) | ((insn & 0x20) >> 5);
1313 if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
1314 return bfd_reloc_overflow;
1315 insn = (((result << 16) & 0xfffe0000)
1316 | ((result << 5) & 0x20)
1317 | (insn & ~0xfffe0020));
1318 bfd_put_32 (abfd, insn, address);
1319 return bfd_reloc_ok;
1320
252b5132
RH
1321 case R_V850_ZDA_16_16_SPLIT_OFFSET:
1322 case R_V850_SDA_16_16_SPLIT_OFFSET:
1323 insn = bfd_get_32 (abfd, address);
1324 addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5);
435b1e90 1325
252b5132 1326 saddend = (bfd_signed_vma) addend;
435b1e90 1327
252b5132
RH
1328 if (saddend > 0x7fff || saddend < -0x8000)
1329 return bfd_reloc_overflow;
435b1e90 1330
252b5132
RH
1331 insn &= 0x0001ffdf;
1332 insn |= (addend & 1) << 5;
dc810e39 1333 insn |= (addend &~ (bfd_vma) 1) << 16;
435b1e90 1334
dc810e39 1335 bfd_put_32 (abfd, (bfd_vma) insn, address);
252b5132 1336 return bfd_reloc_ok;
435b1e90 1337
252b5132
RH
1338 case R_V850_CALLT_6_7_OFFSET:
1339 insn = bfd_get_16 (abfd, address);
1340 addend += ((insn & 0x3f) << 1);
435b1e90 1341
252b5132 1342 saddend = (bfd_signed_vma) addend;
435b1e90 1343
252b5132
RH
1344 if (saddend > 0x7e || saddend < 0)
1345 return bfd_reloc_overflow;
435b1e90 1346
252b5132
RH
1347 if (addend & 1)
1348 return bfd_reloc_dangerous;
435b1e90 1349
252b5132
RH
1350 insn &= 0xff80;
1351 insn |= (addend >> 1);
1352 break;
1353
1354 case R_V850_GNU_VTINHERIT:
1355 case R_V850_GNU_VTENTRY:
1356 return bfd_reloc_ok;
1357
1358 }
1359
dc810e39 1360 bfd_put_16 (abfd, (bfd_vma) insn, address);
252b5132
RH
1361 return bfd_reloc_ok;
1362}
252b5132
RH
1363\f
1364/* Insert the addend into the instruction. */
e12dd2ea 1365
252b5132
RH
1366static bfd_reloc_status_type
1367v850_elf_reloc (abfd, reloc, symbol, data, isection, obfd, err)
b34976b6
AM
1368 bfd *abfd ATTRIBUTE_UNUSED;
1369 arelent *reloc;
1370 asymbol *symbol;
1371 PTR data ATTRIBUTE_UNUSED;
1372 asection *isection;
1373 bfd *obfd;
1374 char **err ATTRIBUTE_UNUSED;
252b5132
RH
1375{
1376 long relocation;
435b1e90 1377
252b5132
RH
1378 /* If there is an output BFD,
1379 and the symbol is not a section name (which is only defined at final link time),
1380 and either we are not putting the addend into the instruction
e12dd2ea 1381 or the addend is zero, so there is nothing to add into the instruction
252b5132
RH
1382 then just fixup the address and return. */
1383 if (obfd != (bfd *) NULL
1384 && (symbol->flags & BSF_SECTION_SYM) == 0
1385 && (! reloc->howto->partial_inplace
1386 || reloc->addend == 0))
1387 {
1388 reloc->address += isection->output_offset;
1389 return bfd_reloc_ok;
1390 }
435b1e90 1391
252b5132
RH
1392 /* Catch relocs involving undefined symbols. */
1393 if (bfd_is_und_section (symbol->section)
1394 && (symbol->flags & BSF_WEAK) == 0
1395 && obfd == NULL)
1396 return bfd_reloc_undefined;
1397
1398 /* We handle final linking of some relocs ourselves. */
1399
1400 /* Is the address of the relocation really within the section? */
07515404 1401 if (reloc->address > bfd_get_section_limit (abfd, isection))
252b5132 1402 return bfd_reloc_outofrange;
435b1e90 1403
4cc11e76 1404 /* Work out which section the relocation is targeted at and the
252b5132 1405 initial relocation command value. */
435b1e90 1406
b34976b6 1407 if (reloc->howto->pc_relative)
86aba9db
NC
1408 return bfd_reloc_ok;
1409
252b5132
RH
1410 /* Get symbol value. (Common symbols are special.) */
1411 if (bfd_is_com_section (symbol->section))
1412 relocation = 0;
1413 else
1414 relocation = symbol->value;
435b1e90 1415
252b5132
RH
1416 /* Convert input-section-relative symbol value to absolute + addend. */
1417 relocation += symbol->section->output_section->vma;
1418 relocation += symbol->section->output_offset;
1419 relocation += reloc->addend;
435b1e90 1420
435b1e90 1421 reloc->addend = relocation;
252b5132
RH
1422 return bfd_reloc_ok;
1423}
86aba9db
NC
1424
1425/* This function is used for relocs which are only used
1426 for relaxing, which the linker should otherwise ignore. */
1427
1428static bfd_reloc_status_type
1429v850_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,
1430 output_bfd, error_message)
b34976b6
AM
1431 bfd *abfd ATTRIBUTE_UNUSED;
1432 arelent *reloc_entry;
1433 asymbol *symbol ATTRIBUTE_UNUSED;
1434 PTR data ATTRIBUTE_UNUSED;
1435 asection *input_section;
1436 bfd *output_bfd;
1437 char **error_message ATTRIBUTE_UNUSED;
86aba9db
NC
1438{
1439 if (output_bfd != NULL)
1440 reloc_entry->address += input_section->output_offset;
1441
1442 return bfd_reloc_ok;
1443}
252b5132 1444\f
b34976b6 1445static bfd_boolean
252b5132 1446v850_elf_is_local_label_name (abfd, name)
b34976b6
AM
1447 bfd *abfd ATTRIBUTE_UNUSED;
1448 const char *name;
252b5132
RH
1449{
1450 return ( (name[0] == '.' && (name[1] == 'L' || name[1] == '.'))
1451 || (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_'));
1452}
252b5132 1453\f
5cec6941
NC
1454/* We overload some of the bfd_reloc error codes for own purposes. */
1455#define bfd_reloc_gp_not_found bfd_reloc_other
1456#define bfd_reloc_ep_not_found bfd_reloc_continue
1457#define bfd_reloc_ctbp_not_found (bfd_reloc_dangerous + 1)
1458
252b5132 1459/* Perform a relocation as part of a final link. */
e12dd2ea 1460
252b5132
RH
1461static bfd_reloc_status_type
1462v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
86aba9db
NC
1463 input_section, contents, offset, value,
1464 addend, info, sym_sec, is_local)
b34976b6
AM
1465 reloc_howto_type *howto;
1466 bfd *input_bfd;
1467 bfd *output_bfd ATTRIBUTE_UNUSED;
1468 asection *input_section;
1469 bfd_byte *contents;
1470 bfd_vma offset;
1471 bfd_vma value;
1472 bfd_vma addend;
1473 struct bfd_link_info *info;
1474 asection *sym_sec;
1475 int is_local ATTRIBUTE_UNUSED;
252b5132 1476{
b34976b6
AM
1477 unsigned int r_type = howto->type;
1478 bfd_byte *hit_data = contents + offset;
252b5132
RH
1479
1480 /* Adjust the value according to the relocation. */
1481 switch (r_type)
1482 {
1483 case R_V850_9_PCREL:
1484 value -= (input_section->output_section->vma
1485 + input_section->output_offset);
1486 value -= offset;
1487 break;
435b1e90 1488
252b5132
RH
1489 case R_V850_22_PCREL:
1490 value -= (input_section->output_section->vma
1491 + input_section->output_offset
1492 + offset);
1493
232fb1a3
NC
1494 /* If the sign extension will corrupt the value then we have overflowed. */
1495 if (((value & 0xff000000) != 0x0) && ((value & 0xff000000) != 0xff000000))
1496 return bfd_reloc_overflow;
435b1e90 1497
e12dd2ea
NC
1498 /* Only the bottom 24 bits of the PC are valid */
1499 value = SEXT24 (value);
252b5132 1500 break;
435b1e90 1501
e30ddb24
NC
1502 case R_V850_REL32:
1503 value -= (input_section->output_section->vma
1504 + input_section->output_offset
1505 + offset);
1506 break;
1507
252b5132
RH
1508 case R_V850_HI16_S:
1509 case R_V850_HI16:
1510 case R_V850_LO16:
1e50d24d 1511 case R_V850_LO16_SPLIT_OFFSET:
252b5132 1512 case R_V850_16:
e30ddb24 1513 case R_V850_ABS32:
252b5132
RH
1514 case R_V850_8:
1515 break;
1516
435b1e90 1517 case R_V850_ZDA_15_16_OFFSET:
252b5132
RH
1518 case R_V850_ZDA_16_16_OFFSET:
1519 case R_V850_ZDA_16_16_SPLIT_OFFSET:
1520 if (sym_sec == NULL)
1521 return bfd_reloc_undefined;
435b1e90 1522
252b5132
RH
1523 value -= sym_sec->output_section->vma;
1524 break;
1525
1526 case R_V850_SDA_15_16_OFFSET:
1527 case R_V850_SDA_16_16_OFFSET:
1528 case R_V850_SDA_16_16_SPLIT_OFFSET:
1529 {
1530 unsigned long gp;
1531 struct bfd_link_hash_entry * h;
1532
1533 if (sym_sec == NULL)
1534 return bfd_reloc_undefined;
435b1e90 1535
252b5132 1536 /* Get the value of __gp. */
b34976b6 1537 h = bfd_link_hash_lookup (info->hash, "__gp", FALSE, FALSE, TRUE);
252b5132
RH
1538 if (h == (struct bfd_link_hash_entry *) NULL
1539 || h->type != bfd_link_hash_defined)
5cec6941 1540 return bfd_reloc_gp_not_found;
252b5132
RH
1541
1542 gp = (h->u.def.value
1543 + h->u.def.section->output_section->vma
1544 + h->u.def.section->output_offset);
1545
1546 value -= sym_sec->output_section->vma;
1547 value -= (gp - sym_sec->output_section->vma);
1548 }
1549 break;
1550
1551 case R_V850_TDA_4_4_OFFSET:
1552 case R_V850_TDA_4_5_OFFSET:
1553 case R_V850_TDA_16_16_OFFSET:
1554 case R_V850_TDA_7_7_OFFSET:
1555 case R_V850_TDA_7_8_OFFSET:
1556 case R_V850_TDA_6_8_OFFSET:
1557 {
1558 unsigned long ep;
1559 struct bfd_link_hash_entry * h;
435b1e90 1560
252b5132 1561 /* Get the value of __ep. */
b34976b6 1562 h = bfd_link_hash_lookup (info->hash, "__ep", FALSE, FALSE, TRUE);
252b5132
RH
1563 if (h == (struct bfd_link_hash_entry *) NULL
1564 || h->type != bfd_link_hash_defined)
5cec6941 1565 return bfd_reloc_ep_not_found;
252b5132
RH
1566
1567 ep = (h->u.def.value
1568 + h->u.def.section->output_section->vma
1569 + h->u.def.section->output_offset);
1570
1571 value -= ep;
1572 }
1573 break;
435b1e90 1574
252b5132
RH
1575 case R_V850_CALLT_6_7_OFFSET:
1576 {
1577 unsigned long ctbp;
1578 struct bfd_link_hash_entry * h;
435b1e90 1579
252b5132 1580 /* Get the value of __ctbp. */
b34976b6 1581 h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
252b5132
RH
1582 if (h == (struct bfd_link_hash_entry *) NULL
1583 || h->type != bfd_link_hash_defined)
5cec6941 1584 return bfd_reloc_ctbp_not_found;
252b5132
RH
1585
1586 ctbp = (h->u.def.value
1587 + h->u.def.section->output_section->vma
1588 + h->u.def.section->output_offset);
1589 value -= ctbp;
1590 }
1591 break;
435b1e90 1592
252b5132
RH
1593 case R_V850_CALLT_16_16_OFFSET:
1594 {
1595 unsigned long ctbp;
1596 struct bfd_link_hash_entry * h;
1597
1598 if (sym_sec == NULL)
1599 return bfd_reloc_undefined;
435b1e90 1600
252b5132 1601 /* Get the value of __ctbp. */
b34976b6 1602 h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
252b5132
RH
1603 if (h == (struct bfd_link_hash_entry *) NULL
1604 || h->type != bfd_link_hash_defined)
5cec6941 1605 return bfd_reloc_ctbp_not_found;
252b5132
RH
1606
1607 ctbp = (h->u.def.value
1608 + h->u.def.section->output_section->vma
1609 + h->u.def.section->output_offset);
1610
1611 value -= sym_sec->output_section->vma;
1612 value -= (ctbp - sym_sec->output_section->vma);
1613 }
1614 break;
435b1e90 1615
252b5132
RH
1616 case R_V850_NONE:
1617 case R_V850_GNU_VTINHERIT:
1618 case R_V850_GNU_VTENTRY:
86aba9db
NC
1619 case R_V850_LONGCALL:
1620 case R_V850_LONGJUMP:
1621 case R_V850_ALIGN:
252b5132
RH
1622 return bfd_reloc_ok;
1623
1624 default:
1625 return bfd_reloc_notsupported;
1626 }
1627
1628 /* Perform the relocation. */
435b1e90 1629 return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data);
252b5132 1630}
252b5132
RH
1631\f
1632/* Relocate an V850 ELF section. */
e12dd2ea 1633
b34976b6 1634static bfd_boolean
252b5132
RH
1635v850_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1636 contents, relocs, local_syms, local_sections)
b34976b6
AM
1637 bfd *output_bfd;
1638 struct bfd_link_info *info;
1639 bfd *input_bfd;
1640 asection *input_section;
1641 bfd_byte *contents;
1642 Elf_Internal_Rela *relocs;
1643 Elf_Internal_Sym *local_syms;
1644 asection **local_sections;
252b5132 1645{
b34976b6
AM
1646 Elf_Internal_Shdr *symtab_hdr;
1647 struct elf_link_hash_entry **sym_hashes;
1648 Elf_Internal_Rela *rel;
1649 Elf_Internal_Rela *relend;
252b5132 1650
1049f94e 1651 if (info->relocatable)
b34976b6 1652 return TRUE;
f0fe0e16 1653
252b5132
RH
1654 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1655 sym_hashes = elf_sym_hashes (input_bfd);
1656
252b5132
RH
1657 /* Reset the list of remembered HI16S relocs to empty. */
1658 free_hi16s = previous_hi16s;
1659 previous_hi16s = NULL;
1660 hi16s_counter = 0;
435b1e90 1661
252b5132
RH
1662 rel = relocs;
1663 relend = relocs + input_section->reloc_count;
1664 for (; rel < relend; rel++)
1665 {
b34976b6
AM
1666 int r_type;
1667 reloc_howto_type *howto;
1668 unsigned long r_symndx;
1669 Elf_Internal_Sym *sym;
1670 asection *sec;
1671 struct elf_link_hash_entry *h;
1672 bfd_vma relocation;
1673 bfd_reloc_status_type r;
252b5132
RH
1674
1675 r_symndx = ELF32_R_SYM (rel->r_info);
1676 r_type = ELF32_R_TYPE (rel->r_info);
1677
1678 if (r_type == R_V850_GNU_VTENTRY
1679 || r_type == R_V850_GNU_VTINHERIT)
1680 continue;
1681
252b5132 1682 /* This is a final link. */
f0fe0e16 1683 howto = v850_elf_howto_table + r_type;
252b5132
RH
1684 h = NULL;
1685 sym = NULL;
1686 sec = NULL;
1687 if (r_symndx < symtab_hdr->sh_info)
1688 {
1689 sym = local_syms + r_symndx;
1690 sec = local_sections[r_symndx];
8517fae7 1691 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
252b5132
RH
1692 }
1693 else
1694 {
59c2e50f 1695 bfd_boolean unresolved_reloc, warned;
435b1e90 1696
641bd093
NC
1697 /* Note - this check is delayed until now as it is possible and valid
1698 to have a file without any symbols but with relocs that can be
1699 processed. */
1700 if (sym_hashes == NULL)
1701 {
1702 info->callbacks->warning
1703 (info, "no hash table available",
1704 NULL, input_bfd, input_section, (bfd_vma) 0);
1705
1706 return FALSE;
1707 }
1708
b2a8e766
AM
1709 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1710 r_symndx, symtab_hdr, sym_hashes,
1711 h, sec, relocation,
1712 unresolved_reloc, warned);
252b5132
RH
1713 }
1714
e12dd2ea 1715 /* FIXME: We should use the addend, but the COFF relocations don't. */
252b5132
RH
1716 r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
1717 input_section,
1718 contents, rel->r_offset,
1719 relocation, rel->r_addend,
1720 info, sec, h == NULL);
1721
1722 if (r != bfd_reloc_ok)
1723 {
1724 const char * name;
1725 const char * msg = (const char *)0;
1726
1727 if (h != NULL)
1728 name = h->root.root.string;
1729 else
1730 {
1731 name = (bfd_elf_string_from_elf_section
1732 (input_bfd, symtab_hdr->sh_link, sym->st_name));
1733 if (name == NULL || *name == '\0')
1734 name = bfd_section_name (input_bfd, sec);
1735 }
1736
1737 switch (r)
1738 {
1739 case bfd_reloc_overflow:
1740 if (! ((*info->callbacks->reloc_overflow)
dfeffb9f
L
1741 (info, (h ? &h->root : NULL), name, howto->name,
1742 (bfd_vma) 0, input_bfd, input_section,
1743 rel->r_offset)))
b34976b6 1744 return FALSE;
252b5132
RH
1745 break;
1746
1747 case bfd_reloc_undefined:
1748 if (! ((*info->callbacks->undefined_symbol)
1749 (info, name, input_bfd, input_section,
b34976b6
AM
1750 rel->r_offset, TRUE)))
1751 return FALSE;
252b5132
RH
1752 break;
1753
1754 case bfd_reloc_outofrange:
1755 msg = _("internal error: out of range error");
1756 goto common_error;
1757
1758 case bfd_reloc_notsupported:
1759 msg = _("internal error: unsupported relocation error");
1760 goto common_error;
1761
1762 case bfd_reloc_dangerous:
1763 msg = _("internal error: dangerous relocation");
1764 goto common_error;
1765
5cec6941 1766 case bfd_reloc_gp_not_found:
252b5132
RH
1767 msg = _("could not locate special linker symbol __gp");
1768 goto common_error;
1769
5cec6941 1770 case bfd_reloc_ep_not_found:
252b5132
RH
1771 msg = _("could not locate special linker symbol __ep");
1772 goto common_error;
1773
5cec6941 1774 case bfd_reloc_ctbp_not_found:
252b5132
RH
1775 msg = _("could not locate special linker symbol __ctbp");
1776 goto common_error;
435b1e90 1777
252b5132
RH
1778 default:
1779 msg = _("internal error: unknown error");
1780 /* fall through */
1781
1782 common_error:
1783 if (!((*info->callbacks->warning)
1784 (info, msg, name, input_bfd, input_section,
1785 rel->r_offset)))
b34976b6 1786 return FALSE;
252b5132
RH
1787 break;
1788 }
1789 }
1790 }
1791
b34976b6 1792 return TRUE;
252b5132
RH
1793}
1794
b34976b6 1795static bfd_boolean
252b5132 1796v850_elf_gc_sweep_hook (abfd, info, sec, relocs)
5f771d47
ILT
1797 bfd *abfd ATTRIBUTE_UNUSED;
1798 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1799 asection *sec ATTRIBUTE_UNUSED;
1800 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
252b5132 1801{
e12dd2ea 1802 /* No got and plt entries for v850-elf. */
b34976b6 1803 return TRUE;
252b5132
RH
1804}
1805
1806static asection *
1e2f5b6e
AM
1807v850_elf_gc_mark_hook (sec, info, rel, h, sym)
1808 asection *sec;
5f771d47 1809 struct bfd_link_info *info ATTRIBUTE_UNUSED;
252b5132
RH
1810 Elf_Internal_Rela *rel;
1811 struct elf_link_hash_entry *h;
1812 Elf_Internal_Sym *sym;
1813{
1814 if (h != NULL)
1815 {
1816 switch (ELF32_R_TYPE (rel->r_info))
1817 {
1818 case R_V850_GNU_VTINHERIT:
1819 case R_V850_GNU_VTENTRY:
1820 break;
1821
1822 default:
1823 switch (h->root.type)
1824 {
1825 case bfd_link_hash_defined:
1826 case bfd_link_hash_defweak:
1827 return h->root.u.def.section;
1828
1829 case bfd_link_hash_common:
1830 return h->root.u.c.p->section;
e049a0de
ILT
1831
1832 default:
1833 break;
252b5132
RH
1834 }
1835 }
1836 }
1837 else
1e2f5b6e 1838 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
9ad5cbcf 1839
252b5132
RH
1840 return NULL;
1841}
e12dd2ea 1842
252b5132 1843/* Set the right machine number. */
e12dd2ea 1844
b34976b6 1845static bfd_boolean
252b5132
RH
1846v850_elf_object_p (abfd)
1847 bfd *abfd;
1848{
1849 switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
1850 {
1851 default:
250d94fd
AM
1852 case E_V850_ARCH:
1853 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850);
1854 break;
1855 case E_V850E_ARCH:
1856 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e);
1857 break;
8ad30312
NC
1858 case E_V850E1_ARCH:
1859 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e1);
1860 break;
252b5132 1861 }
b34976b6 1862 return TRUE;
252b5132
RH
1863}
1864
1865/* Store the machine number in the flags field. */
e12dd2ea 1866
252b5132
RH
1867static void
1868v850_elf_final_write_processing (abfd, linker)
b34976b6
AM
1869 bfd *abfd;
1870 bfd_boolean linker ATTRIBUTE_UNUSED;
252b5132
RH
1871{
1872 unsigned long val;
1873
1874 switch (bfd_get_mach (abfd))
1875 {
b34976b6 1876 default:
250d94fd
AM
1877 case bfd_mach_v850: val = E_V850_ARCH; break;
1878 case bfd_mach_v850e: val = E_V850E_ARCH; break;
8ad30312 1879 case bfd_mach_v850e1: val = E_V850E1_ARCH; break;
252b5132
RH
1880 }
1881
1882 elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH;
1883 elf_elfheader (abfd)->e_flags |= val;
1884}
1885
435b1e90 1886/* Function to keep V850 specific file flags. */
e12dd2ea 1887
b34976b6 1888static bfd_boolean
252b5132 1889v850_elf_set_private_flags (abfd, flags)
b34976b6 1890 bfd *abfd;
252b5132
RH
1891 flagword flags;
1892{
1893 BFD_ASSERT (!elf_flags_init (abfd)
1894 || elf_elfheader (abfd)->e_flags == flags);
1895
1896 elf_elfheader (abfd)->e_flags = flags;
b34976b6
AM
1897 elf_flags_init (abfd) = TRUE;
1898 return TRUE;
252b5132
RH
1899}
1900
e12dd2ea
NC
1901/* Merge backend specific data from an object file
1902 to the output object file when linking. */
b34976b6 1903static bfd_boolean
252b5132 1904v850_elf_merge_private_bfd_data (ibfd, obfd)
b34976b6
AM
1905 bfd *ibfd;
1906 bfd *obfd;
252b5132
RH
1907{
1908 flagword out_flags;
1909 flagword in_flags;
1910
1911 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1912 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
b34976b6 1913 return TRUE;
252b5132
RH
1914
1915 in_flags = elf_elfheader (ibfd)->e_flags;
1916 out_flags = elf_elfheader (obfd)->e_flags;
1917
1918 if (! elf_flags_init (obfd))
1919 {
1920 /* If the input is the default architecture then do not
1921 bother setting the flags for the output architecture,
1922 instead allow future merges to do this. If no future
1923 merges ever set these flags then they will retain their
1924 unitialised values, which surprise surprise, correspond
1925 to the default values. */
1926 if (bfd_get_arch_info (ibfd)->the_default)
b34976b6 1927 return TRUE;
435b1e90 1928
b34976b6 1929 elf_flags_init (obfd) = TRUE;
252b5132
RH
1930 elf_elfheader (obfd)->e_flags = in_flags;
1931
1932 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
1933 && bfd_get_arch_info (obfd)->the_default)
e12dd2ea 1934 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
252b5132 1935
b34976b6 1936 return TRUE;
252b5132
RH
1937 }
1938
1939 /* Check flag compatibility. */
1940 if (in_flags == out_flags)
b34976b6 1941 return TRUE;
252b5132
RH
1942
1943 if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH)
1944 && (in_flags & EF_V850_ARCH) != E_V850_ARCH)
8ad30312
NC
1945 {
1946 /* Allow v850e1 binaries to be linked with v850e binaries.
1947 Set the output binary to v850e. */
1948 if ((in_flags & EF_V850_ARCH) == E_V850E1_ARCH
1949 && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
1950 return TRUE;
1951
1952 if ((in_flags & EF_V850_ARCH) == E_V850E_ARCH
1953 && (out_flags & EF_V850_ARCH) == E_V850E1_ARCH)
1954 {
1955 elf_elfheader (obfd)->e_flags =
1956 ((out_flags & ~ EF_V850_ARCH) | E_V850E_ARCH);
1957 return TRUE;
1958 }
1959
d003868e
AM
1960 _bfd_error_handler (_("%B: Architecture mismatch with previous modules"),
1961 ibfd);
8ad30312 1962 }
252b5132 1963
b34976b6 1964 return TRUE;
252b5132 1965}
e12dd2ea
NC
1966
1967/* Display the flags field. */
252b5132 1968
b34976b6 1969static bfd_boolean
252b5132 1970v850_elf_print_private_bfd_data (abfd, ptr)
b34976b6
AM
1971 bfd *abfd;
1972 PTR ptr;
252b5132
RH
1973{
1974 FILE * file = (FILE *) ptr;
435b1e90 1975
252b5132 1976 BFD_ASSERT (abfd != NULL && ptr != NULL);
435b1e90 1977
252b5132 1978 _bfd_elf_print_private_bfd_data (abfd, ptr);
435b1e90 1979
252b5132
RH
1980 /* xgettext:c-format */
1981 fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags);
435b1e90 1982
252b5132
RH
1983 switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
1984 {
1985 default:
1986 case E_V850_ARCH: fprintf (file, _("v850 architecture")); break;
1987 case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break;
8ad30312 1988 case E_V850E1_ARCH: fprintf (file, _("v850e1 architecture")); break;
252b5132 1989 }
435b1e90 1990
252b5132 1991 fputc ('\n', file);
435b1e90 1992
b34976b6 1993 return TRUE;
252b5132
RH
1994}
1995
1996/* V850 ELF uses four common sections. One is the usual one, and the
1997 others are for (small) objects in one of the special data areas:
1998 small, tiny and zero. All the objects are kept together, and then
1999 referenced via the gp register, the ep register or the r0 register
2000 respectively, which yields smaller, faster assembler code. This
2001 approach is copied from elf32-mips.c. */
2002
2003static asection v850_elf_scom_section;
2004static asymbol v850_elf_scom_symbol;
2005static asymbol * v850_elf_scom_symbol_ptr;
2006static asection v850_elf_tcom_section;
2007static asymbol v850_elf_tcom_symbol;
2008static asymbol * v850_elf_tcom_symbol_ptr;
2009static asection v850_elf_zcom_section;
2010static asymbol v850_elf_zcom_symbol;
2011static asymbol * v850_elf_zcom_symbol_ptr;
2012
e12dd2ea
NC
2013/* Given a BFD section, try to locate the
2014 corresponding ELF section index. */
252b5132 2015
b34976b6 2016static bfd_boolean
af746e92 2017v850_elf_section_from_bfd_section (abfd, sec, retval)
b34976b6
AM
2018 bfd *abfd ATTRIBUTE_UNUSED;
2019 asection *sec;
2020 int *retval;
252b5132
RH
2021{
2022 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
2023 *retval = SHN_V850_SCOMMON;
2024 else if (strcmp (bfd_get_section_name (abfd, sec), ".tcommon") == 0)
2025 *retval = SHN_V850_TCOMMON;
2026 else if (strcmp (bfd_get_section_name (abfd, sec), ".zcommon") == 0)
2027 *retval = SHN_V850_ZCOMMON;
2028 else
b34976b6 2029 return FALSE;
435b1e90 2030
b34976b6 2031 return TRUE;
252b5132
RH
2032}
2033
2034/* Handle the special V850 section numbers that a symbol may use. */
2035
2036static void
2037v850_elf_symbol_processing (abfd, asym)
b34976b6
AM
2038 bfd *abfd;
2039 asymbol *asym;
252b5132
RH
2040{
2041 elf_symbol_type * elfsym = (elf_symbol_type *) asym;
9ad5cbcf 2042 unsigned int indx;
435b1e90 2043
9ad5cbcf 2044 indx = elfsym->internal_elf_sym.st_shndx;
252b5132
RH
2045
2046 /* If the section index is an "ordinary" index, then it may
2047 refer to a v850 specific section created by the assembler.
2048 Check the section's type and change the index it matches.
435b1e90 2049
252b5132 2050 FIXME: Should we alter the st_shndx field as well ? */
435b1e90 2051
9ad5cbcf
AM
2052 if (indx < elf_numsections (abfd))
2053 switch (elf_elfsections(abfd)[indx]->sh_type)
252b5132
RH
2054 {
2055 case SHT_V850_SCOMMON:
9ad5cbcf 2056 indx = SHN_V850_SCOMMON;
252b5132 2057 break;
435b1e90 2058
252b5132 2059 case SHT_V850_TCOMMON:
9ad5cbcf 2060 indx = SHN_V850_TCOMMON;
252b5132 2061 break;
435b1e90 2062
252b5132 2063 case SHT_V850_ZCOMMON:
9ad5cbcf 2064 indx = SHN_V850_ZCOMMON;
252b5132 2065 break;
435b1e90 2066
252b5132
RH
2067 default:
2068 break;
2069 }
435b1e90 2070
9ad5cbcf 2071 switch (indx)
252b5132
RH
2072 {
2073 case SHN_V850_SCOMMON:
2074 if (v850_elf_scom_section.name == NULL)
2075 {
2076 /* Initialize the small common section. */
2077 v850_elf_scom_section.name = ".scommon";
2078 v850_elf_scom_section.flags = SEC_IS_COMMON | SEC_ALLOC | SEC_DATA;
2079 v850_elf_scom_section.output_section = & v850_elf_scom_section;
2080 v850_elf_scom_section.symbol = & v850_elf_scom_symbol;
2081 v850_elf_scom_section.symbol_ptr_ptr = & v850_elf_scom_symbol_ptr;
2082 v850_elf_scom_symbol.name = ".scommon";
2083 v850_elf_scom_symbol.flags = BSF_SECTION_SYM;
2084 v850_elf_scom_symbol.section = & v850_elf_scom_section;
2085 v850_elf_scom_symbol_ptr = & v850_elf_scom_symbol;
2086 }
2087 asym->section = & v850_elf_scom_section;
2088 asym->value = elfsym->internal_elf_sym.st_size;
2089 break;
435b1e90 2090
252b5132
RH
2091 case SHN_V850_TCOMMON:
2092 if (v850_elf_tcom_section.name == NULL)
2093 {
2094 /* Initialize the tcommon section. */
2095 v850_elf_tcom_section.name = ".tcommon";
2096 v850_elf_tcom_section.flags = SEC_IS_COMMON;
2097 v850_elf_tcom_section.output_section = & v850_elf_tcom_section;
2098 v850_elf_tcom_section.symbol = & v850_elf_tcom_symbol;
2099 v850_elf_tcom_section.symbol_ptr_ptr = & v850_elf_tcom_symbol_ptr;
2100 v850_elf_tcom_symbol.name = ".tcommon";
2101 v850_elf_tcom_symbol.flags = BSF_SECTION_SYM;
2102 v850_elf_tcom_symbol.section = & v850_elf_tcom_section;
2103 v850_elf_tcom_symbol_ptr = & v850_elf_tcom_symbol;
2104 }
2105 asym->section = & v850_elf_tcom_section;
2106 asym->value = elfsym->internal_elf_sym.st_size;
2107 break;
2108
2109 case SHN_V850_ZCOMMON:
2110 if (v850_elf_zcom_section.name == NULL)
2111 {
2112 /* Initialize the zcommon section. */
2113 v850_elf_zcom_section.name = ".zcommon";
2114 v850_elf_zcom_section.flags = SEC_IS_COMMON;
2115 v850_elf_zcom_section.output_section = & v850_elf_zcom_section;
2116 v850_elf_zcom_section.symbol = & v850_elf_zcom_symbol;
2117 v850_elf_zcom_section.symbol_ptr_ptr = & v850_elf_zcom_symbol_ptr;
2118 v850_elf_zcom_symbol.name = ".zcommon";
2119 v850_elf_zcom_symbol.flags = BSF_SECTION_SYM;
2120 v850_elf_zcom_symbol.section = & v850_elf_zcom_section;
2121 v850_elf_zcom_symbol_ptr = & v850_elf_zcom_symbol;
2122 }
2123 asym->section = & v850_elf_zcom_section;
2124 asym->value = elfsym->internal_elf_sym.st_size;
2125 break;
2126 }
2127}
2128
2129/* Hook called by the linker routine which adds symbols from an object
2130 file. We must handle the special v850 section numbers here. */
2131
b34976b6 2132static bfd_boolean
252b5132 2133v850_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
b34976b6
AM
2134 bfd *abfd;
2135 struct bfd_link_info *info ATTRIBUTE_UNUSED;
555cd476 2136 Elf_Internal_Sym *sym;
b34976b6
AM
2137 const char **namep ATTRIBUTE_UNUSED;
2138 flagword *flagsp ATTRIBUTE_UNUSED;
2139 asection **secp;
2140 bfd_vma *valp;
252b5132 2141{
9ad5cbcf 2142 unsigned int indx = sym->st_shndx;
435b1e90 2143
252b5132
RH
2144 /* If the section index is an "ordinary" index, then it may
2145 refer to a v850 specific section created by the assembler.
2146 Check the section's type and change the index it matches.
435b1e90 2147
252b5132 2148 FIXME: Should we alter the st_shndx field as well ? */
435b1e90 2149
9ad5cbcf
AM
2150 if (indx < elf_numsections (abfd))
2151 switch (elf_elfsections(abfd)[indx]->sh_type)
252b5132
RH
2152 {
2153 case SHT_V850_SCOMMON:
9ad5cbcf 2154 indx = SHN_V850_SCOMMON;
252b5132 2155 break;
435b1e90 2156
252b5132 2157 case SHT_V850_TCOMMON:
9ad5cbcf 2158 indx = SHN_V850_TCOMMON;
252b5132 2159 break;
435b1e90 2160
252b5132 2161 case SHT_V850_ZCOMMON:
9ad5cbcf 2162 indx = SHN_V850_ZCOMMON;
252b5132 2163 break;
435b1e90 2164
252b5132
RH
2165 default:
2166 break;
2167 }
435b1e90 2168
9ad5cbcf 2169 switch (indx)
252b5132
RH
2170 {
2171 case SHN_V850_SCOMMON:
2172 *secp = bfd_make_section_old_way (abfd, ".scommon");
2173 (*secp)->flags |= SEC_IS_COMMON;
2174 *valp = sym->st_size;
2175 break;
435b1e90 2176
252b5132
RH
2177 case SHN_V850_TCOMMON:
2178 *secp = bfd_make_section_old_way (abfd, ".tcommon");
2179 (*secp)->flags |= SEC_IS_COMMON;
2180 *valp = sym->st_size;
2181 break;
435b1e90 2182
252b5132
RH
2183 case SHN_V850_ZCOMMON:
2184 *secp = bfd_make_section_old_way (abfd, ".zcommon");
2185 (*secp)->flags |= SEC_IS_COMMON;
2186 *valp = sym->st_size;
2187 break;
2188 }
2189
b34976b6 2190 return TRUE;
252b5132
RH
2191}
2192
b34976b6 2193static bfd_boolean
754021d0 2194v850_elf_link_output_symbol_hook (info, name, sym, input_sec, h)
b34976b6
AM
2195 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2196 const char *name ATTRIBUTE_UNUSED;
2197 Elf_Internal_Sym *sym;
2198 asection *input_sec;
754021d0 2199 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED;
252b5132
RH
2200{
2201 /* If we see a common symbol, which implies a relocatable link, then
2202 if a symbol was in a special common section in an input file, mark
2203 it as a special common in the output file. */
435b1e90 2204
252b5132
RH
2205 if (sym->st_shndx == SHN_COMMON)
2206 {
2207 if (strcmp (input_sec->name, ".scommon") == 0)
2208 sym->st_shndx = SHN_V850_SCOMMON;
2209 else if (strcmp (input_sec->name, ".tcommon") == 0)
2210 sym->st_shndx = SHN_V850_TCOMMON;
2211 else if (strcmp (input_sec->name, ".zcommon") == 0)
2212 sym->st_shndx = SHN_V850_ZCOMMON;
2213 }
2214
b34976b6 2215 return TRUE;
252b5132
RH
2216}
2217
b34976b6 2218static bfd_boolean
6dc132d9
L
2219v850_elf_section_from_shdr (bfd *abfd,
2220 Elf_Internal_Shdr *hdr,
2221 const char *name,
2222 int shindex)
252b5132
RH
2223{
2224 /* There ought to be a place to keep ELF backend specific flags, but
2225 at the moment there isn't one. We just keep track of the
2226 sections by their name, instead. */
2227
6dc132d9 2228 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
b34976b6 2229 return FALSE;
252b5132
RH
2230
2231 switch (hdr->sh_type)
2232 {
2233 case SHT_V850_SCOMMON:
2234 case SHT_V850_TCOMMON:
2235 case SHT_V850_ZCOMMON:
2236 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
2237 (bfd_get_section_flags (abfd,
2238 hdr->bfd_section)
2239 | SEC_IS_COMMON)))
b34976b6 2240 return FALSE;
252b5132
RH
2241 }
2242
b34976b6 2243 return TRUE;
252b5132
RH
2244}
2245
e12dd2ea
NC
2246/* Set the correct type for a V850 ELF section. We do this
2247 by the section name, which is a hack, but ought to work. */
2248
b34976b6 2249static bfd_boolean
252b5132 2250v850_elf_fake_sections (abfd, hdr, sec)
b34976b6
AM
2251 bfd *abfd ATTRIBUTE_UNUSED;
2252 Elf_Internal_Shdr *hdr;
2253 asection *sec;
252b5132
RH
2254{
2255 register const char * name;
2256
2257 name = bfd_get_section_name (abfd, sec);
2258
2259 if (strcmp (name, ".scommon") == 0)
2260 {
2261 hdr->sh_type = SHT_V850_SCOMMON;
2262 }
2263 else if (strcmp (name, ".tcommon") == 0)
2264 {
2265 hdr->sh_type = SHT_V850_TCOMMON;
2266 }
2267 else if (strcmp (name, ".zcommon") == 0)
2268 hdr->sh_type = SHT_V850_ZCOMMON;
435b1e90 2269
b34976b6 2270 return TRUE;
252b5132 2271}
86aba9db
NC
2272
2273/* Delete some bytes from a section while relaxing. */
2274
b34976b6 2275static bfd_boolean
86aba9db 2276v850_elf_relax_delete_bytes (abfd, sec, addr, toaddr, count)
b34976b6
AM
2277 bfd *abfd;
2278 asection *sec;
2279 bfd_vma addr;
2280 bfd_vma toaddr;
2281 int count;
86aba9db 2282{
b34976b6
AM
2283 Elf_Internal_Shdr *symtab_hdr;
2284 Elf32_External_Sym *extsyms;
2285 Elf32_External_Sym *esym;
2286 Elf32_External_Sym *esymend;
2287 int index;
2288 unsigned int sec_shndx;
2289 bfd_byte *contents;
2290 Elf_Internal_Rela *irel;
2291 Elf_Internal_Rela *irelend;
2292 struct elf_link_hash_entry *sym_hash;
2293 Elf_Internal_Shdr *shndx_hdr;
2294 Elf_External_Sym_Shndx *shndx;
86aba9db
NC
2295
2296 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2297 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
2298
2299 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2300
2301 contents = elf_section_data (sec)->this_hdr.contents;
2302
2303 /* The deletion must stop at the next ALIGN reloc for an alignment
2304 power larger than the number of bytes we are deleting. */
2305
2306 /* Actually delete the bytes. */
2307#if (DEBUG_RELAX & 2)
2308 fprintf (stderr, "relax_delete: contents: sec: %s %p .. %p %x\n",
2309 sec->name, addr, toaddr, count );
2310#endif
2311 memmove (contents + addr, contents + addr + count,
2312 toaddr - addr - count);
2313 memset (contents + toaddr-count, 0, count);
2314
2315 /* Adjust all the relocs. */
2316 irel = elf_section_data (sec)->relocs;
2317 irelend = irel + sec->reloc_count;
2318 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
2319 shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
2320
2321 for (; irel < irelend; irel++)
2322 {
2323 bfd_vma raddr, paddr, symval;
2324 Elf_Internal_Sym isym;
2325
2326 /* Get the new reloc address. */
2327 raddr = irel->r_offset;
2328 if ((raddr >= (addr + count) && raddr < toaddr))
b34976b6 2329 irel->r_offset -= count;
86aba9db
NC
2330
2331 if (raddr >= addr && raddr < addr + count)
2332 {
2333 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2334 (int) R_V850_NONE);
2335 continue;
2336 }
b34976b6 2337
86aba9db
NC
2338 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN)
2339 continue;
2340
2341 bfd_elf32_swap_symbol_in (abfd,
2342 extsyms + ELF32_R_SYM (irel->r_info),
2343 shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL,
2344 & isym);
b34976b6 2345
86aba9db
NC
2346 if (isym.st_shndx != sec_shndx)
2347 continue;
2348
2349 /* Get the value of the symbol referred to by the reloc. */
2350 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2351 {
2352 symval = isym.st_value;
2353#if (DEBUG_RELAX & 2)
2354 {
2355 char * name = bfd_elf_string_from_elf_section
2356 (abfd, symtab_hdr->sh_link, isym.st_name);
2357 fprintf (stderr,
2358 "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
2359 sec->name, name, isym.st_name,
2360 sec->output_section->vma, sec->output_offset,
2361 isym.st_value, irel->r_addend);
2362 }
2363#endif
2364 }
2365 else
2366 {
2367 unsigned long indx;
2368 struct elf_link_hash_entry * h;
2369
2370 /* An external symbol. */
2371 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2372
2373 h = elf_sym_hashes (abfd) [indx];
2374 BFD_ASSERT (h != NULL);
2375
2376 symval = h->root.u.def.value;
2377#if (DEBUG_RELAX & 2)
2378 fprintf (stderr,
2379 "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
2380 sec->name, h->root.root.string, h->root.u.def.value,
2381 sec->output_section->vma, sec->output_offset, irel->r_addend);
2382#endif
2383 }
b34976b6 2384
86aba9db 2385 paddr = symval + irel->r_addend;
b34976b6 2386
86aba9db
NC
2387 if ( (symval >= addr + count && symval < toaddr)
2388 && (paddr < addr + count || paddr >= toaddr))
2389 irel->r_addend += count;
2390 else if ( (symval < addr + count || symval >= toaddr)
2391 && (paddr >= addr + count && paddr < toaddr))
2392 irel->r_addend -= count;
2393 }
2394
2395 /* Adjust the local symbols defined in this section. */
2396 esym = extsyms;
2397 esymend = esym + symtab_hdr->sh_info;
2398
2399 for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
2400 {
2401 Elf_Internal_Sym isym;
2402
2403 bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
2404
2405 if (isym.st_shndx == sec_shndx
2406 && isym.st_value >= addr + count
2407 && isym.st_value < toaddr)
2408 {
2409 isym.st_value -= count;
2410
2411 if (isym.st_value + isym.st_size >= toaddr)
b34976b6
AM
2412 isym.st_size += count;
2413
63a23799 2414 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
86aba9db
NC
2415 }
2416 else if (isym.st_shndx == sec_shndx
2417 && isym.st_value < addr + count)
2418 {
2419 if (isym.st_value+isym.st_size >= addr + count
2420 && isym.st_value+isym.st_size < toaddr)
2421 isym.st_size -= count;
2422
2423 if (isym.st_value >= addr
2424 && isym.st_value < addr + count)
2425 isym.st_value = addr;
2426
63a23799 2427 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
86aba9db
NC
2428 }
2429 }
2430
2431 /* Now adjust the global symbols defined in this section. */
2432 esym = extsyms + symtab_hdr->sh_info;
2433 esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
2434
2435 for (index = 0; esym < esymend; esym ++, index ++)
2436 {
2437 Elf_Internal_Sym isym;
2438
2439 bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
2440 sym_hash = elf_sym_hashes (abfd) [index];
2441
2442 if (isym.st_shndx == sec_shndx
2443 && ((sym_hash)->root.type == bfd_link_hash_defined
2444 || (sym_hash)->root.type == bfd_link_hash_defweak)
2445 && (sym_hash)->root.u.def.section == sec
2446 && (sym_hash)->root.u.def.value >= addr + count
2447 && (sym_hash)->root.u.def.value < toaddr)
2448 {
2449 if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr)
2450 {
2451 isym.st_size += count;
63a23799 2452 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
86aba9db
NC
2453 }
2454
2455 (sym_hash)->root.u.def.value -= count;
2456 }
2457 else if (isym.st_shndx == sec_shndx
2458 && ((sym_hash)->root.type == bfd_link_hash_defined
2459 || (sym_hash)->root.type == bfd_link_hash_defweak)
2460 && (sym_hash)->root.u.def.section == sec
2461 && (sym_hash)->root.u.def.value < addr + count)
2462 {
2463 if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count
2464 && (sym_hash)->root.u.def.value+isym.st_size < toaddr)
2465 isym.st_size -= count;
2466
2467 if ((sym_hash)->root.u.def.value >= addr
2468 && (sym_hash)->root.u.def.value < addr + count)
2469 (sym_hash)->root.u.def.value = addr;
2470
63a23799 2471 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
86aba9db
NC
2472 }
2473
2474 if (shndx)
2475 ++ shndx;
2476 }
2477
b34976b6 2478 return TRUE;
86aba9db
NC
2479}
2480
2481#define NOP_OPCODE (0x0000)
b34976b6 2482#define MOVHI 0x0640 /* 4byte */
86aba9db 2483#define MOVHI_MASK 0x07e0
b34976b6 2484#define MOVHI_R1(insn) ((insn) & 0x1f) /* 4byte */
86aba9db
NC
2485#define MOVHI_R2(insn) ((insn) >> 11)
2486#define MOVEA 0x0620 /* 2byte */
2487#define MOVEA_MASK 0x07e0
2488#define MOVEA_R1(insn) ((insn) & 0x1f)
2489#define MOVEA_R2(insn) ((insn) >> 11)
2490#define JARL_4 0x00040780 /* 4byte */
2491#define JARL_4_MASK 0xFFFF07FF
2492#define JARL_R2(insn) (int)(((insn) & (~JARL_4_MASK)) >> 11)
2493#define ADD_I 0x0240 /* 2byte */
2494#define ADD_I_MASK 0x07e0
2495#define ADD_I5(insn) ((((insn) & 0x001f) << 11) >> 11) /* 2byte */
2496#define ADD_R2(insn) ((insn) >> 11)
2497#define JMP_R 0x0060 /* 2byte */
2498#define JMP_R_MASK 0xFFE0
2499#define JMP_R1(insn) ((insn) & 0x1f)
2500
b34976b6 2501static bfd_boolean
86aba9db 2502v850_elf_relax_section (abfd, sec, link_info, again)
b34976b6
AM
2503 bfd *abfd;
2504 asection *sec;
2505 struct bfd_link_info *link_info;
2506 bfd_boolean *again;
86aba9db 2507{
b34976b6
AM
2508 Elf_Internal_Shdr *symtab_hdr;
2509 Elf_Internal_Rela *internal_relocs;
2510 Elf_Internal_Rela *irel;
2511 Elf_Internal_Rela *irelend;
2512 Elf_Internal_Rela *irelalign = NULL;
2513 Elf_Internal_Sym *isymbuf = NULL;
2514 bfd_byte *contents = NULL;
2515 bfd_vma addr = 0;
2516 bfd_vma toaddr;
2517 int align_pad_size = 0;
2518 bfd_boolean result = TRUE;
2519
2520 *again = FALSE;
86aba9db 2521
1049f94e 2522 if (link_info->relocatable
86aba9db
NC
2523 || (sec->flags & SEC_RELOC) == 0
2524 || sec->reloc_count == 0)
b34976b6 2525 return TRUE;
86aba9db 2526
86aba9db
NC
2527 symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
2528
45d6a902 2529 internal_relocs = (_bfd_elf_link_read_relocs
86aba9db
NC
2530 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2531 link_info->keep_memory));
2532 if (internal_relocs == NULL)
2533 goto error_return;
86aba9db
NC
2534
2535 irelend = internal_relocs + sec->reloc_count;
b34976b6 2536
eea6121a 2537 while (addr < sec->size)
86aba9db 2538 {
eea6121a 2539 toaddr = sec->size;
86aba9db
NC
2540
2541 for (irel = internal_relocs; irel < irelend; irel ++)
2542 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
2543 && irel->r_offset > addr
2544 && irel->r_offset < toaddr)
2545 toaddr = irel->r_offset;
b34976b6 2546
86aba9db
NC
2547#ifdef DEBUG_RELAX
2548 fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n",
2549 addr, toaddr, align_pad_size);
2550#endif
2551 if (irelalign)
2552 {
2553 bfd_vma alignto;
2554 bfd_vma alignmoveto;
2555
2556 alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend);
2557 alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend);
2558
2559 if (alignmoveto < alignto)
2560 {
2561 unsigned int i;
2562
2563 align_pad_size = alignto - alignmoveto;
2564#ifdef DEBUG_RELAX
2565 fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n",
2566 alignmoveto, toaddr, align_pad_size);
2567#endif
2568 if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto,
2569 toaddr, align_pad_size))
b34976b6 2570 goto error_return;
86aba9db
NC
2571
2572 for (i = BFD_ALIGN (toaddr - align_pad_size, 1);
2573 (i + 1) < toaddr; i += 2)
2574 bfd_put_16 (abfd, NOP_OPCODE, contents + i);
2575
2576 addr = alignmoveto;
2577 }
2578 else
2579 align_pad_size = 0;
2580 }
2581
2582 for (irel = internal_relocs; irel < irelend; irel++)
2583 {
b34976b6
AM
2584 bfd_vma laddr;
2585 bfd_vma addend;
2586 bfd_vma symval;
2587 int insn[5];
2588 int no_match = -1;
2589 Elf_Internal_Rela *hi_irelfn;
2590 Elf_Internal_Rela *lo_irelfn;
2591 Elf_Internal_Rela *irelcall;
2592 bfd_signed_vma foff;
86aba9db
NC
2593
2594 if (! (irel->r_offset >= addr && irel->r_offset < toaddr
2595 && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL
2596 || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)))
2597 continue;
2598
2599#ifdef DEBUG_RELAX
2600 fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n",
2601 irel->r_info,
2602 irel->r_offset,
2603 irel->r_addend );
2604#endif
2605
2606 /* Get the section contents. */
2607 if (contents == NULL)
2608 {
2609 if (elf_section_data (sec)->this_hdr.contents != NULL)
2610 contents = elf_section_data (sec)->this_hdr.contents;
2611 else
2612 {
eea6121a 2613 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
86aba9db
NC
2614 goto error_return;
2615 }
2616 }
2617
5cec6941
NC
2618 /* Read this BFD's local symbols if we haven't done so already. */
2619 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
86aba9db 2620 {
5cec6941
NC
2621 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2622 if (isymbuf == NULL)
2623 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2624 symtab_hdr->sh_info, 0,
2625 NULL, NULL, NULL);
2626 if (isymbuf == NULL)
2627 goto error_return;
86aba9db
NC
2628 }
2629
2630 laddr = irel->r_offset;
2631
2632 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL)
2633 {
2634 /* Check code for -mlong-calls output. */
eea6121a 2635 if (laddr + 16 <= (bfd_vma) sec->size)
86aba9db
NC
2636 {
2637 insn[0] = bfd_get_16 (abfd, contents + laddr);
2638 insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
2639 insn[2] = bfd_get_32 (abfd, contents + laddr + 8);
2640 insn[3] = bfd_get_16 (abfd, contents + laddr + 12);
2641 insn[4] = bfd_get_16 (abfd, contents + laddr + 14);
b34976b6 2642
86aba9db
NC
2643 if ((insn[0] & MOVHI_MASK) != MOVHI
2644 || MOVHI_R1 (insn[0]) != 0)
2645 no_match = 0;
2646
2647 if (no_match < 0
2648 && ((insn[1] & MOVEA_MASK) != MOVEA
2649 || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
2650 no_match = 1;
2651
2652 if (no_match < 0
2653 && (insn[2] & JARL_4_MASK) != JARL_4)
2654 no_match = 2;
2655
2656 if (no_match < 0
2657 && ((insn[3] & ADD_I_MASK) != ADD_I
2658 || ADD_I5 (insn[3]) != 4
2659 || JARL_R2 (insn[2]) != ADD_R2 (insn[3])))
2660 no_match = 3;
2661
2662 if (no_match < 0
2663 && ((insn[4] & JMP_R_MASK) != JMP_R
2664 || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4])))
2665 no_match = 4;
2666 }
2667 else
2668 {
2669 ((*_bfd_error_handler)
2670 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insns",
2671 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
2672
2673 continue;
2674 }
2675
2676 if (no_match >= 0)
2677 {
2678 ((*_bfd_error_handler)
2679 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insn 0x%x",
2680 bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
2681
2682 continue;
b34976b6 2683 }
86aba9db
NC
2684
2685 /* Get the reloc for the address from which the register is
2686 being loaded. This reloc will tell us which function is
2687 actually being called. */
2688 for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
2689 if (hi_irelfn->r_offset == laddr + 2
b34976b6 2690 && ELF32_R_TYPE (hi_irelfn->r_info)
86aba9db
NC
2691 == (int) R_V850_HI16_S)
2692 break;
2693
2694 for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
2695 if (lo_irelfn->r_offset == laddr + 6
2696 && ELF32_R_TYPE (lo_irelfn->r_info)
2697 == (int) R_V850_LO16)
2698 break;
2699
2700 for (irelcall = internal_relocs; irelcall < irelend; irelcall ++)
2701 if (irelcall->r_offset == laddr + 8
2702 && ELF32_R_TYPE (irelcall->r_info)
2703 == (int) R_V850_22_PCREL)
2704 break;
2705
2706 if ( hi_irelfn == irelend
2707 || lo_irelfn == irelend
2708 || irelcall == irelend)
2709 {
2710 ((*_bfd_error_handler)
2711 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc",
2712 bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
2713
2714 continue;
2715 }
b34976b6 2716
86aba9db
NC
2717 if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info)
2718 {
5cec6941 2719 Elf_Internal_Sym * isym;
86aba9db
NC
2720
2721 /* A local symbol. */
5cec6941 2722 isym = isymbuf + ELF32_R_SYM (irelcall->r_info);
86aba9db 2723
5cec6941 2724 symval = isym->st_value;
86aba9db
NC
2725 }
2726 else
2727 {
2728 unsigned long indx;
2729 struct elf_link_hash_entry * h;
2730
2731 /* An external symbol. */
2732 indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info;
2733 h = elf_sym_hashes (abfd)[indx];
2734 BFD_ASSERT (h != NULL);
2735
2736 if ( h->root.type != bfd_link_hash_defined
2737 && h->root.type != bfd_link_hash_defweak)
2738 /* This appears to be a reference to an undefined
2739 symbol. Just ignore it--it will be caught by the
2740 regular reloc processing. */
2741 continue;
2742
2743 symval = h->root.u.def.value;
2744 }
2745
2746 if (symval + irelcall->r_addend != irelcall->r_offset + 4)
2747 {
2748 ((*_bfd_error_handler)
2749 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc 0x%lx",
2750 bfd_get_filename (abfd), (unsigned long) irel->r_offset, irelcall->r_offset ));
2751
2752 continue;
2753 }
2754
2755 /* Get the value of the symbol referred to by the reloc. */
2756 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2757 {
b34976b6
AM
2758 Elf_Internal_Sym *isym;
2759 asection *sym_sec;
86aba9db
NC
2760
2761 /* A local symbol. */
5cec6941 2762 isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
b34976b6 2763
5cec6941 2764 if (isym->st_shndx == SHN_UNDEF)
86aba9db 2765 sym_sec = bfd_und_section_ptr;
5cec6941 2766 else if (isym->st_shndx == SHN_ABS)
86aba9db 2767 sym_sec = bfd_abs_section_ptr;
5cec6941 2768 else if (isym->st_shndx == SHN_COMMON)
86aba9db
NC
2769 sym_sec = bfd_com_section_ptr;
2770 else
5cec6941
NC
2771 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2772 symval = (isym->st_value
86aba9db
NC
2773 + sym_sec->output_section->vma
2774 + sym_sec->output_offset);
2775 }
2776 else
2777 {
2778 unsigned long indx;
b34976b6 2779 struct elf_link_hash_entry *h;
86aba9db
NC
2780
2781 /* An external symbol. */
5cec6941 2782 indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
86aba9db
NC
2783 h = elf_sym_hashes (abfd)[indx];
2784 BFD_ASSERT (h != NULL);
2785
2786 if ( h->root.type != bfd_link_hash_defined
2787 && h->root.type != bfd_link_hash_defweak)
2788 /* This appears to be a reference to an undefined
2789 symbol. Just ignore it--it will be caught by the
2790 regular reloc processing. */
2791 continue;
2792
2793 symval = (h->root.u.def.value
2794 + h->root.u.def.section->output_section->vma
2795 + h->root.u.def.section->output_offset);
2796 }
2797
2798 addend = irel->r_addend;
2799
2800 foff = (symval + addend
2801 - (irel->r_offset
2802 + sec->output_section->vma
2803 + sec->output_offset
2804 + 4));
2805#ifdef DEBUG_RELAX
2806 fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
2807 irel->r_offset,
2808 (irel->r_offset
2809 + sec->output_section->vma
2810 + sec->output_offset),
2811 symval, addend, foff);
2812#endif
2813
2814 if (foff < -0x100000 || foff >= 0x100000)
2815 /* After all that work, we can't shorten this function call. */
2816 continue;
2817
2818 /* For simplicity of coding, we are going to modify the section
2819 contents, the section relocs, and the BFD symbol table. We
2820 must tell the rest of the code not to free up this
2821 information. It would be possible to instead create a table
2822 of changes which have to be made, as is done in coff-mips.c;
2823 that would be more work, but would require less memory when
2824 the linker is run. */
2825 elf_section_data (sec)->relocs = internal_relocs;
86aba9db 2826 elf_section_data (sec)->this_hdr.contents = contents;
5cec6941 2827 symtab_hdr->contents = (bfd_byte *) isymbuf;
b34976b6 2828
86aba9db
NC
2829 /* Replace the long call with a jarl. */
2830 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL);
2831
2832 addend = 0;
2833
2834 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2835 /* If this needs to be changed because of future relaxing,
2836 it will be handled here like other internal IND12W
2837 relocs. */
2838 bfd_put_32 (abfd,
2839 0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf),
2840 contents + irel->r_offset);
2841 else
2842 /* We can't fully resolve this yet, because the external
2843 symbol value may be changed by future relaxing.
2844 We let the final link phase handle it. */
2845 bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11),
2846 contents + irel->r_offset);
2847
b34976b6 2848 hi_irelfn->r_info =
86aba9db
NC
2849 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
2850 lo_irelfn->r_info =
2851 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
2852 irelcall->r_info =
2853 ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE);
2854
2855 if (! v850_elf_relax_delete_bytes (abfd, sec,
2856 irel->r_offset + 4, toaddr, 12))
2857 goto error_return;
2858
2859 align_pad_size += 12;
2860 }
2861 else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)
2862 {
2863 /* Check code for -mlong-jumps output. */
eea6121a 2864 if (laddr + 10 <= (bfd_vma) sec->size)
86aba9db
NC
2865 {
2866 insn[0] = bfd_get_16 (abfd, contents + laddr);
2867 insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
2868 insn[2] = bfd_get_16 (abfd, contents + laddr + 8);
2869
2870 if ((insn[0] & MOVHI_MASK) != MOVHI
2871 || MOVHI_R1 (insn[0]) != 0)
2872 no_match = 0;
2873
2874 if (no_match < 0
2875 && ((insn[1] & MOVEA_MASK) != MOVEA
2876 || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
2877 no_match = 1;
2878
2879 if (no_match < 0
2880 && ((insn[2] & JMP_R_MASK) != JMP_R
2881 || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2])))
2882 no_match = 4;
2883 }
2884 else
2885 {
2886 ((*_bfd_error_handler)
2887 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insns",
2888 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
2889
2890 continue;
2891 }
2892
2893 if (no_match >= 0)
2894 {
2895 ((*_bfd_error_handler)
2896 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insn 0x%x",
2897 bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
2898
2899 continue;
2900 }
2901
2902 /* Get the reloc for the address from which the register is
2903 being loaded. This reloc will tell us which function is
2904 actually being called. */
2905 for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
2906 if (hi_irelfn->r_offset == laddr + 2
b34976b6 2907 && ELF32_R_TYPE (hi_irelfn->r_info) == (int) R_V850_HI16_S)
86aba9db
NC
2908 break;
2909
2910 for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
2911 if (lo_irelfn->r_offset == laddr + 6
2912 && ELF32_R_TYPE (lo_irelfn->r_info) == (int) R_V850_LO16)
2913 break;
2914
2915 if ( hi_irelfn == irelend
2916 || lo_irelfn == irelend)
2917 {
2918 ((*_bfd_error_handler)
2919 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized reloc",
2920 bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
2921
2922 continue;
2923 }
b34976b6 2924
86aba9db
NC
2925 /* Get the value of the symbol referred to by the reloc. */
2926 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2927 {
5cec6941
NC
2928 Elf_Internal_Sym * isym;
2929 asection * sym_sec;
86aba9db
NC
2930
2931 /* A local symbol. */
5cec6941
NC
2932 isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
2933
2934 if (isym->st_shndx == SHN_UNDEF)
86aba9db 2935 sym_sec = bfd_und_section_ptr;
5cec6941 2936 else if (isym->st_shndx == SHN_ABS)
86aba9db 2937 sym_sec = bfd_abs_section_ptr;
5cec6941 2938 else if (isym->st_shndx == SHN_COMMON)
86aba9db
NC
2939 sym_sec = bfd_com_section_ptr;
2940 else
5cec6941
NC
2941 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2942 symval = (isym->st_value
86aba9db
NC
2943 + sym_sec->output_section->vma
2944 + sym_sec->output_offset);
2945#ifdef DEBUG_RELAX
2946 {
2947 char * name = bfd_elf_string_from_elf_section
5cec6941 2948 (abfd, symtab_hdr->sh_link, isym->st_name);
86aba9db
NC
2949
2950 fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
5cec6941
NC
2951 sym_sec->name, name, isym->st_name,
2952 sym_sec->output_section->vma,
2953 sym_sec->output_offset,
2954 isym->st_value, irel->r_addend);
86aba9db
NC
2955 }
2956#endif
2957 }
2958 else
2959 {
2960 unsigned long indx;
2961 struct elf_link_hash_entry * h;
2962
2963 /* An external symbol. */
2964 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2965 h = elf_sym_hashes (abfd)[indx];
2966 BFD_ASSERT (h != NULL);
2967
2968 if ( h->root.type != bfd_link_hash_defined
2969 && h->root.type != bfd_link_hash_defweak)
2970 /* This appears to be a reference to an undefined
2971 symbol. Just ignore it--it will be caught by the
2972 regular reloc processing. */
2973 continue;
2974
2975 symval = (h->root.u.def.value
2976 + h->root.u.def.section->output_section->vma
2977 + h->root.u.def.section->output_offset);
2978#ifdef DEBUG_RELAX
2979 fprintf (stderr,
2980 "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
2981 sec->name, h->root.root.string, h->root.u.def.value,
2982 sec->output_section->vma, sec->output_offset, irel->r_addend);
2983#endif
2984 }
2985
2986 addend = irel->r_addend;
2987
2988 foff = (symval + addend
2989 - (irel->r_offset
2990 + sec->output_section->vma
2991 + sec->output_offset
2992 + 4));
2993#ifdef DEBUG_RELAX
2994 fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
2995 irel->r_offset,
2996 (irel->r_offset
2997 + sec->output_section->vma
2998 + sec->output_offset),
2999 symval, addend, foff);
3000#endif
3001 if (foff < -0x100000 || foff >= 0x100000)
3002 /* After all that work, we can't shorten this function call. */
3003 continue;
3004
3005 /* For simplicity of coding, we are going to modify the section
3006 contents, the section relocs, and the BFD symbol table. We
3007 must tell the rest of the code not to free up this
3008 information. It would be possible to instead create a table
3009 of changes which have to be made, as is done in coff-mips.c;
3010 that would be more work, but would require less memory when
3011 the linker is run. */
3012 elf_section_data (sec)->relocs = internal_relocs;
86aba9db 3013 elf_section_data (sec)->this_hdr.contents = contents;
5cec6941 3014 symtab_hdr->contents = (bfd_byte *) isymbuf;
86aba9db
NC
3015
3016 if (foff < -0x100 || foff >= 0x100)
3017 {
3018 /* Replace the long jump with a jr. */
3019
3020 irel->r_info =
b34976b6
AM
3021 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL);
3022
86aba9db
NC
3023 irel->r_addend = addend;
3024 addend = 0;
3025
3026 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3027 /* If this needs to be changed because of future relaxing,
3028 it will be handled here like other internal IND12W
3029 relocs. */
3030 bfd_put_32 (abfd,
3031 0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf),
3032 contents + irel->r_offset);
3033 else
3034 /* We can't fully resolve this yet, because the external
3035 symbol value may be changed by future relaxing.
3036 We let the final link phase handle it. */
3037 bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset);
3038
3039 hi_irelfn->r_info =
3040 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
3041 lo_irelfn->r_info =
3042 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
3043 if (!v850_elf_relax_delete_bytes (abfd, sec,
3044 irel->r_offset + 4, toaddr, 6))
3045 goto error_return;
3046
3047 align_pad_size += 6;
3048 }
3049 else
3050 {
3051 /* Replace the long jump with a br. */
3052
3053 irel->r_info =
3054 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL);
3055
3056 irel->r_addend = addend;
3057 addend = 0;
3058
3059 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3060 /* If this needs to be changed because of future relaxing,
3061 it will be handled here like other internal IND12W
3062 relocs. */
3063 bfd_put_16 (abfd,
3064 0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070),
3065 contents + irel->r_offset);
3066 else
3067 /* We can't fully resolve this yet, because the external
3068 symbol value may be changed by future relaxing.
3069 We let the final link phase handle it. */
3070 bfd_put_16 (abfd, 0x0585, contents + irel->r_offset);
3071
3072 hi_irelfn->r_info =
3073 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
3074 lo_irelfn->r_info =
3075 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
3076 if (!v850_elf_relax_delete_bytes (abfd, sec,
3077 irel->r_offset + 2, toaddr, 8))
3078 goto error_return;
3079
3080 align_pad_size += 8;
3081 }
3082 }
3083 }
3084
3085 irelalign = NULL;
3086 for (irel = internal_relocs; irel < irelend; irel++)
3087 {
3088 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
3089 && irel->r_offset == toaddr)
3090 {
3091 irel->r_offset -= align_pad_size;
3092
3093 if (irelalign == NULL || irelalign->r_addend > irel->r_addend)
3094 irelalign = irel;
3095 }
3096 }
3097
3098 addr = toaddr;
3099 }
3100
3101 if (!irelalign)
3102 {
3103#ifdef DEBUG_RELAX
3104 fprintf (stderr, "relax pad %d shorten %d -> %d\n",
3105 align_pad_size,
eea6121a
AM
3106 sec->size,
3107 sec->size - align_pad_size);
86aba9db 3108#endif
eea6121a 3109 sec->size -= align_pad_size;
86aba9db
NC
3110 }
3111
5cec6941
NC
3112 finish:
3113 if (internal_relocs != NULL
3114 && elf_section_data (sec)->relocs != internal_relocs)
3115 free (internal_relocs);
86aba9db 3116
5cec6941
NC
3117 if (contents != NULL
3118 && elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents)
3119 free (contents);
86aba9db 3120
5cec6941
NC
3121 if (isymbuf != NULL
3122 && symtab_hdr->contents != (bfd_byte *) isymbuf)
3123 free (isymbuf);
86aba9db 3124
5cec6941 3125 return result;
86aba9db 3126
5cec6941 3127 error_return:
b34976b6 3128 result = FALSE;
5cec6941 3129 goto finish;
86aba9db 3130}
2f89ff8d 3131
7f4d3958
L
3132static struct bfd_elf_special_section const
3133 v850_special_sections_c[]=
3134{
3135 { ".call_table_data", 16, 0, SHT_PROGBITS, (SHF_ALLOC
3136 + SHF_WRITE) },
3137 { ".call_table_text", 16, 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3138 + SHF_EXECINSTR) },
3139 { NULL, 0, 0, 0, 0 }
3140};
3141
3142static struct bfd_elf_special_section const
3143 v850_special_sections_r[]=
2f89ff8d 3144{
7dcb9820
AM
3145 { ".rosdata", 8, -2, SHT_PROGBITS, (SHF_ALLOC
3146 + SHF_V850_GPREL) },
7f4d3958
L
3147 { ".rozdata", 8, -2, SHT_PROGBITS, (SHF_ALLOC
3148 + SHF_V850_R0REL) },
3149 { NULL, 0, 0, 0, 0 }
3150};
3151
3152static struct bfd_elf_special_section const
3153 v850_special_sections_s[]=
3154{
3155 { ".sdata", 6, -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3156 + SHF_V850_GPREL) },
7dcb9820
AM
3157 { ".sbss", 5, -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3158 + SHF_V850_GPREL) },
3159 { ".scommon", 8, -2, SHT_V850_SCOMMON, (SHF_ALLOC + SHF_WRITE
3160 + SHF_V850_GPREL) },
7f4d3958
L
3161 { NULL, 0, 0, 0, 0 }
3162};
3163
3164static struct bfd_elf_special_section const
3165 v850_special_sections_t[]=
3166{
7dcb9820
AM
3167 { ".tdata", 6, -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3168 + SHF_V850_EPREL) },
3169 { ".tbss", 5, -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3170 + SHF_V850_EPREL) },
3171 { ".tcommon", 8, -2, SHT_V850_TCOMMON, (SHF_ALLOC + SHF_WRITE
3172 + SHF_V850_R0REL) },
7f4d3958
L
3173 { NULL, 0, 0, 0, 0 }
3174};
3175
3176static struct bfd_elf_special_section const
3177 v850_special_sections_z[]=
3178{
7dcb9820
AM
3179 { ".zdata", 6, -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3180 + SHF_V850_R0REL) },
7dcb9820
AM
3181 { ".zbss", 5, -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3182 + SHF_V850_R0REL) },
3183 { ".zcommon", 8, -2, SHT_V850_ZCOMMON, (SHF_ALLOC + SHF_WRITE
3184 + SHF_V850_R0REL) },
7f4d3958
L
3185 { NULL, 0, 0, 0, 0 }
3186};
3187
3188static struct bfd_elf_special_section const *
3189 v850_elf_special_sections[27] =
3190{
3191 NULL, /* 'a' */
3192 NULL, /* 'b' */
3193 v850_special_sections_c, /* 'c' */
3194 NULL, /* 'd' */
3195 NULL, /* 'e' */
3196 NULL, /* 'f' */
3197 NULL, /* 'g' */
3198 NULL, /* 'h' */
3199 NULL, /* 'i' */
3200 NULL, /* 'j' */
3201 NULL, /* 'k' */
3202 NULL, /* 'l' */
3203 NULL, /* 'm' */
3204 NULL, /* 'n' */
3205 NULL, /* 'o' */
3206 NULL, /* 'p' */
3207 NULL, /* 'q' */
3208 v850_special_sections_r, /* 'r' */
3209 v850_special_sections_s, /* 's' */
3210 v850_special_sections_t, /* 't' */
3211 NULL, /* 'u' */
3212 NULL, /* 'v' */
3213 NULL, /* 'w' */
3214 NULL, /* 'x' */
3215 NULL, /* 'y' */
3216 v850_special_sections_z, /* 'z' */
3217 NULL /* other */
2f89ff8d 3218};
252b5132
RH
3219\f
3220#define TARGET_LITTLE_SYM bfd_elf32_v850_vec
3221#define TARGET_LITTLE_NAME "elf32-v850"
3222#define ELF_ARCH bfd_arch_v850
aa4f99bb
AO
3223#define ELF_MACHINE_CODE EM_V850
3224#define ELF_MACHINE_ALT1 EM_CYGNUS_V850
46767561 3225#define ELF_MACHINE_ALT2 EM_V800 /* This is the value used by the GreenHills toolchain. */
252b5132 3226#define ELF_MAXPAGESIZE 0x1000
435b1e90 3227
252b5132
RH
3228#define elf_info_to_howto v850_elf_info_to_howto_rela
3229#define elf_info_to_howto_rel v850_elf_info_to_howto_rel
3230
3231#define elf_backend_check_relocs v850_elf_check_relocs
3232#define elf_backend_relocate_section v850_elf_relocate_section
3233#define elf_backend_object_p v850_elf_object_p
3234#define elf_backend_final_write_processing v850_elf_final_write_processing
3235#define elf_backend_section_from_bfd_section v850_elf_section_from_bfd_section
3236#define elf_backend_symbol_processing v850_elf_symbol_processing
3237#define elf_backend_add_symbol_hook v850_elf_add_symbol_hook
3238#define elf_backend_link_output_symbol_hook v850_elf_link_output_symbol_hook
3239#define elf_backend_section_from_shdr v850_elf_section_from_shdr
3240#define elf_backend_fake_sections v850_elf_fake_sections
3241#define elf_backend_gc_mark_hook v850_elf_gc_mark_hook
3242#define elf_backend_gc_sweep_hook v850_elf_gc_sweep_hook
2f89ff8d 3243#define elf_backend_special_sections v850_elf_special_sections
252b5132
RH
3244
3245#define elf_backend_can_gc_sections 1
f0fe0e16 3246#define elf_backend_rela_normal 1
252b5132 3247
252b5132
RH
3248#define bfd_elf32_bfd_is_local_label_name v850_elf_is_local_label_name
3249#define bfd_elf32_bfd_reloc_type_lookup v850_elf_reloc_type_lookup
252b5132
RH
3250#define bfd_elf32_bfd_merge_private_bfd_data v850_elf_merge_private_bfd_data
3251#define bfd_elf32_bfd_set_private_flags v850_elf_set_private_flags
3252#define bfd_elf32_bfd_print_private_bfd_data v850_elf_print_private_bfd_data
86aba9db 3253#define bfd_elf32_bfd_relax_section v850_elf_relax_section
252b5132
RH
3254
3255#define elf_symbol_leading_char '_'
3256
3257#include "elf32-target.h"