1 /* Matsushita 10200 specific support for 32-bit ELF
2 Copyright (C) 1996 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
26 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
27 static void mn10200_info_to_howto
28 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
29 static bfd_reloc_status_type bfd_elf32_mn10200_reloc
30 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
33 /* We have to use RELA instructions since md_apply_fix3 in the assembler
34 does absolutely nothing. */
44 R_MN10200_PCREL32_1BYTE
,
45 R_MN10200_PCREL16_1BYTE
,
46 R_MN10200_PCREL8_1BYTE
,
47 R_MN10200_PCREL32_2BYTE
,
48 R_MN10200_PCREL16_2BYTE
,
53 static reloc_howto_type elf_mn10200_howto_table
[] =
55 /* Dummy relocation. Does nothing. */
56 HOWTO (R_MN10200_NONE
,
62 complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
,
69 /* Standard 32 bit reloc. */
76 complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
,
83 /* Standard 16 bit reloc. */
90 complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
,
97 /* Standard 8 bit reloc. */
104 complain_overflow_bitfield
,
105 bfd_elf_generic_reloc
,
112 /* Simple 32bit pc-relative reloc with a 1 byte adjustment
113 to get the pc-relative offset correct. */
114 HOWTO (R_MN10200_PCREL32_1BYTE
,
120 complain_overflow_bitfield
,
121 bfd_elf32_mn10200_reloc
,
122 "R_MN10200_PCREL32_1BYTE",
127 /* Simple 16bit pc-relative reloc with a 1 byte adjustment
128 to get the pc-relative offset correct. */
129 HOWTO (R_MN10200_PCREL16_1BYTE
,
135 complain_overflow_bitfield
,
136 bfd_elf32_mn10200_reloc
,
137 "R_MN10200_PCREL16_1BYTE",
142 /* Simple 8 pc-relative reloc with a 1 byte adjustment
143 to get the pc-relative offset correct. */
144 HOWTO (R_MN10200_PCREL8_1BYTE
,
150 complain_overflow_bitfield
,
151 bfd_elf32_mn10200_reloc
,
152 "R_MN10200_PCREL8_1BYTE",
157 /* Simple 32 pc-relative reloc with a 2 byte adjustment
158 to get the pc-relative offset correct. */
159 HOWTO (R_MN10200_PCREL32_2BYTE
,
165 complain_overflow_bitfield
,
166 bfd_elf32_mn10200_reloc
,
167 "R_MN10200_PCREL32_2BYTE",
172 /* Simple 16 pc-relative reloc with a 2 byte adjustment
173 to get the pc-relative offset correct. */
174 HOWTO (R_MN10200_PCREL16_2BYTE
,
180 complain_overflow_bitfield
,
181 bfd_elf32_mn10200_reloc
,
182 "R_MN10200_PCREL16_2BYTE",
190 struct mn10200_reloc_map
192 unsigned char bfd_reloc_val
;
193 unsigned char elf_reloc_val
;
196 static const struct mn10200_reloc_map mn10200_reloc_map
[] =
198 { BFD_RELOC_NONE
, R_MN10200_NONE
, },
199 { BFD_RELOC_32
, R_MN10200_32
, },
200 { BFD_RELOC_16
, R_MN10200_16
, },
201 { BFD_RELOC_8
, R_MN10200_8
, },
203 { BFD_RELOC_MN10200_32B
, R_MN10200_32B
, },
204 { BFD_RELOC_MN10200_16B
, R_MN10200_16B
, },
205 { BFD_RELOC_32_PCREL
, R_MN10200_PCREL32_1BYTE
, },
206 { BFD_RELOC_16_PCREL
, R_MN10200_PCREL16_1BYTE
, },
207 { BFD_RELOC_8_PCREL
, R_MN10200_PCREL8_1BYTE
, },
208 { BFD_RELOC_MN10200_32_PCREL
, R_MN10200_PCREL32_2BYTE
, },
209 { BFD_RELOC_MN10200_16_PCREL
, R_MN10200_PCREL16_2BYTE
, },
213 static reloc_howto_type
*
214 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
216 bfd_reloc_code_real_type code
;
221 i
< sizeof (mn10200_reloc_map
) / sizeof (struct mn10200_reloc_map
);
224 if (mn10200_reloc_map
[i
].bfd_reloc_val
== code
)
225 return &elf_mn10200_howto_table
[mn10200_reloc_map
[i
].elf_reloc_val
];
231 /* Set the howto pointer for an MN10200 ELF reloc. */
234 mn10200_info_to_howto (abfd
, cache_ptr
, dst
)
237 Elf32_Internal_Rela
*dst
;
241 r_type
= ELF32_R_TYPE (dst
->r_info
);
242 BFD_ASSERT (r_type
< (unsigned int) R_MN10200_MAX
);
243 cache_ptr
->howto
= &elf_mn10200_howto_table
[r_type
];
246 static bfd_reloc_status_type
247 bfd_elf32_mn10200_reloc (abfd
, reloc
, symbol
, data
, isection
, obfd
, err
)
256 if (obfd
!= (bfd
*) NULL
257 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
258 && (! reloc
->howto
->partial_inplace
259 || reloc
->addend
== 0))
261 reloc
->address
+= isection
->output_offset
;
264 else if (obfd
!= NULL
)
266 return bfd_reloc_continue
;
270 /* Catch relocs involving undefined symbols. */
271 if (bfd_is_und_section (symbol
->section
)
272 && (symbol
->flags
& BSF_WEAK
) == 0
274 return bfd_reloc_undefined
;
276 /* We handle final linking of some relocs ourselves. */
280 /* Is the address of the relocation really within the section? */
281 if (reloc
->address
> isection
->_cooked_size
)
282 return bfd_reloc_outofrange
;
284 /* Work out which section the relocation is targetted at and the
285 initial relocation command value. */
287 /* Get symbol value. (Common symbols are special.) */
288 if (bfd_is_com_section (symbol
->section
))
291 relocation
= symbol
->value
;
293 /* Convert input-section-relative symbol value to absolute + addend. */
294 relocation
+= symbol
->section
->output_section
->vma
;
295 relocation
+= symbol
->section
->output_offset
;
296 relocation
+= reloc
->addend
;
298 if (reloc
->howto
->pc_relative
== true)
300 /* Here the variable relocation holds the final address of the
301 symbol we are relocating against, plus any addend. */
302 relocation
-= isection
->output_section
->vma
+ isection
->output_offset
;
304 /* Deal with pcrel_offset */
305 relocation
-= reloc
->address
;
307 if (reloc
->howto
->type
== R_MN10200_PCREL32_1BYTE
308 || reloc
->howto
->type
== R_MN10200_PCREL16_1BYTE
309 || reloc
->howto
->type
== R_MN10200_PCREL8_1BYTE
)
311 else if (reloc
->howto
->type
== R_MN10200_PCREL32_2BYTE
312 || reloc
->howto
->type
== R_MN10200_PCREL16_2BYTE
)
316 /* I've got no clue... */
319 if (reloc
->howto
->size
== 0)
321 if (relocation
> 0x7f || relocation
< -0x80)
322 return bfd_reloc_overflow
;
324 bfd_put_8 (abfd
, relocation
& 0xff,
325 (bfd_byte
*)data
+ reloc
->address
);
327 else if (reloc
->howto
->size
== 1)
329 if (relocation
> 0x7fff || relocation
< -0x8000)
330 return bfd_reloc_overflow
;
332 bfd_putb16 (relocation
& 0xffff, (bfd_byte
*)data
+ reloc
->address
);
334 else if (reloc
->howto
->size
== 2)
335 bfd_putb32 (relocation
, (bfd_byte
*)data
+ reloc
->address
);
340 return bfd_reloc_continue
;
343 #define TARGET_LITTLE_SYM bfd_elf32_mn10200_vec
344 #define TARGET_LITTLE_NAME "elf32-mn10200"
345 #define ELF_ARCH bfd_arch_mn10200
346 #define ELF_MACHINE_CODE EM_CYGNUS_MN10200
347 #define ELF_MAXPAGESIZE 0x1000
349 #define elf_info_to_howto mn10200_info_to_howto
350 #define elf_info_to_howto_rel 0
352 #define elf_symbol_leading_char '_'
354 #include "elf32-target.h"