1 /* picoJava specific support for 32-bit ELF
2 Copyright (C) 1999-2020 Free Software Foundation, Inc.
3 Contributed by Steve Chamberlan of Transmeta (sac@pobox.com).
5 This file is part of BFD, the Binary File Descriptor library.
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 3 of the License, or
10 (at your option) any later version.
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.
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
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
29 /* This function is used for normal relocs. This is like the COFF
30 function, and is almost certainly incorrect for other ELF targets. */
32 static bfd_reloc_status_type
33 pj_elf_reloc (bfd
*abfd
,
37 asection
*input_section
,
39 char **error_message ATTRIBUTE_UNUSED
)
43 enum elf_pj_reloc_type r_type
;
44 bfd_vma addr
= reloc_entry
->address
;
45 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
47 r_type
= (enum elf_pj_reloc_type
) reloc_entry
->howto
->type
;
49 if (output_bfd
!= NULL
)
51 /* Partial linking--do nothing. */
52 reloc_entry
->address
+= input_section
->output_offset
;
57 && (symbol_in
->flags
& BSF_WEAK
) == 0
58 && bfd_is_und_section (symbol_in
->section
))
59 return bfd_reloc_undefined
;
61 if (bfd_is_com_section (symbol_in
->section
))
64 sym_value
= (symbol_in
->value
+
65 symbol_in
->section
->output_section
->vma
+
66 symbol_in
->section
->output_offset
);
71 insn
= bfd_get_32 (abfd
, hit_data
);
72 insn
+= sym_value
+ reloc_entry
->addend
;
73 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
76 /* Relocations in code are always bigendian, no matter what the
77 data endianness is. */
80 insn
= bfd_getb32 (hit_data
);
81 insn
+= sym_value
+ reloc_entry
->addend
;
82 bfd_putb32 ((bfd_vma
) insn
, hit_data
);
86 insn
= bfd_getb16 (hit_data
);
87 insn
+= sym_value
+ reloc_entry
->addend
88 - (input_section
->output_section
->vma
89 + input_section
->output_offset
);
90 bfd_putb16 ((bfd_vma
) insn
, hit_data
);
93 insn
= bfd_getb16 (hit_data
);
94 insn
+= sym_value
+ reloc_entry
->addend
;
95 bfd_putb16 ((bfd_vma
) insn
, hit_data
);
99 insn
= bfd_getb16 (hit_data
);
100 insn
+= (sym_value
+ reloc_entry
->addend
) >> 16;
101 bfd_putb16 ((bfd_vma
) insn
, hit_data
);
112 static reloc_howto_type pj_elf_howto_table
[] =
115 HOWTO (R_PJ_NONE
, /* type */
117 3, /* size (0 = byte, 1 = short, 2 = long) */
119 FALSE
, /* pc_relative */
121 complain_overflow_dont
, /* complain_on_overflow */
122 pj_elf_reloc
, /* special_function */
123 "R_PJ_NONE", /* name */
124 FALSE
, /* partial_inplace */
127 FALSE
), /* pcrel_offset */
129 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
130 src_mask to a non-zero value is similar to the COFF toolchain. */
131 HOWTO (R_PJ_DATA_DIR32
, /* type */
133 2, /* size (0 = byte, 1 = short, 2 = long) */
135 FALSE
, /* pc_relative */
137 complain_overflow_bitfield
, /* complain_on_overflow */
138 pj_elf_reloc
, /* special_function */
139 "R_PJ_DIR32", /* name */
140 TRUE
, /* partial_inplace */
141 0xffffffff, /* src_mask */
142 0xffffffff, /* dst_mask */
143 FALSE
), /* pcrel_offset */
145 /* 32 bit PC relative relocation. */
146 HOWTO (R_PJ_CODE_REL32
, /* type */
148 2, /* size (0 = byte, 1 = short, 2 = long) */
150 TRUE
, /* pc_relative */
152 complain_overflow_signed
, /* complain_on_overflow */
153 pj_elf_reloc
, /* special_function */
154 "R_PJ_REL32", /* name */
155 FALSE
, /* partial_inplace */
157 0xffffffff, /* dst_mask */
158 TRUE
), /* pcrel_offset */
160 /* 16 bit PC relative relocation. */
161 HOWTO (R_PJ_CODE_REL16
, /* type */
163 1, /* size (0 = byte, 1 = short, 2 = long) */
165 TRUE
, /* pc_relative */
167 complain_overflow_signed
, /* complain_on_overf6w */
168 pj_elf_reloc
, /* special_function */
169 "R_PJ_REL16", /* name */
170 FALSE
, /* partial_inplace */
171 0xffff, /* src_mask */
172 0xffff, /* dst_mask */
173 TRUE
), /* pcrel_offset */
176 HOWTO (R_PJ_CODE_DIR32
, /* type */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
180 FALSE
, /* pc_relative */
182 complain_overflow_bitfield
, /* complain_on_overflow */
183 pj_elf_reloc
, /* special_function */
184 "R_PJ_CODE_DIR32", /* name */
185 TRUE
, /* partial_inplace */
186 0xffffffff, /* src_mask */
187 0xffffffff, /* dst_mask */
188 FALSE
), /* pcrel_offset */
197 HOWTO (R_PJ_CODE_LO16
, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 FALSE
, /* pc_relative */
203 complain_overflow_unsigned
, /* complain_on_overflow */
204 pj_elf_reloc
, /* special_function */
205 "R_PJ_LO16", /* name */
206 FALSE
, /* partial_inplace */
207 0xffff, /* src_mask */
208 0xffff, /* dst_mask */
209 TRUE
), /* pcrel_offset */
211 HOWTO (R_PJ_CODE_HI16
, /* type */
213 1, /* size (0 = byte, 1 = short, 2 = long) */
215 FALSE
, /* pc_relative */
217 complain_overflow_unsigned
, /* complain_on_overflow */
218 pj_elf_reloc
, /* special_function */
219 "R_PJ_HI16", /* name */
220 FALSE
, /* partial_inplace */
221 0xffff, /* src_mask */
222 0xffff, /* dst_mask */
223 TRUE
), /* pcrel_offset */
225 /* GNU extension to record C++ vtable hierarchy. */
226 HOWTO (R_PJ_GNU_VTINHERIT
, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE
, /* pc_relative */
232 complain_overflow_dont
, /* complain_on_overflow */
233 NULL
, /* special_function */
234 "R_PJ_GNU_VTINHERIT", /* name */
235 FALSE
, /* partial_inplace */
238 FALSE
), /* pcrel_offset */
240 /* GNU extension to record C++ vtable member usage. */
241 HOWTO (R_PJ_GNU_VTENTRY
, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 FALSE
, /* pc_relative */
247 complain_overflow_dont
, /* complain_on_overflow */
248 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
249 "R_PJ_GNU_VTENTRY", /* name */
250 FALSE
, /* partial_inplace */
253 FALSE
), /* pcrel_offset */
256 /* This structure is used to map BFD reloc codes to PJ ELF relocs. */
260 bfd_reloc_code_real_type bfd_reloc_val
;
261 unsigned char elf_reloc_val
;
264 /* An array mapping BFD reloc codes to PJ ELF relocs. */
266 static const struct elf_reloc_map pj_reloc_map
[] =
268 { BFD_RELOC_NONE
, R_PJ_NONE
},
269 { BFD_RELOC_32
, R_PJ_DATA_DIR32
},
270 { BFD_RELOC_PJ_CODE_DIR16
, R_PJ_CODE_DIR16
},
271 { BFD_RELOC_PJ_CODE_DIR32
, R_PJ_CODE_DIR32
},
272 { BFD_RELOC_PJ_CODE_LO16
, R_PJ_CODE_LO16
},
273 { BFD_RELOC_PJ_CODE_HI16
, R_PJ_CODE_HI16
},
274 { BFD_RELOC_PJ_CODE_REL32
, R_PJ_CODE_REL32
},
275 { BFD_RELOC_PJ_CODE_REL16
, R_PJ_CODE_REL16
},
276 { BFD_RELOC_VTABLE_INHERIT
, R_PJ_GNU_VTINHERIT
},
277 { BFD_RELOC_VTABLE_ENTRY
, R_PJ_GNU_VTENTRY
},
280 /* Given a BFD reloc code, return the howto structure for the
281 corresponding PJ ELf reloc. */
283 static reloc_howto_type
*
284 pj_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
285 bfd_reloc_code_real_type code
)
289 for (i
= 0; i
< sizeof (pj_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
290 if (pj_reloc_map
[i
].bfd_reloc_val
== code
)
291 return & pj_elf_howto_table
[(int) pj_reloc_map
[i
].elf_reloc_val
];
296 static reloc_howto_type
*
297 pj_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
303 i
< sizeof (pj_elf_howto_table
) / sizeof (pj_elf_howto_table
[0]);
305 if (pj_elf_howto_table
[i
].name
!= NULL
306 && strcasecmp (pj_elf_howto_table
[i
].name
, r_name
) == 0)
307 return &pj_elf_howto_table
[i
];
312 /* Given an ELF reloc, fill in the howto field of a relent. */
315 pj_elf_info_to_howto (bfd
*abfd
,
317 Elf_Internal_Rela
*dst
)
321 r
= ELF32_R_TYPE (dst
->r_info
);
325 /* xgettext:c-format */
326 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
328 bfd_set_error (bfd_error_bad_value
);
332 cache_ptr
->howto
= &pj_elf_howto_table
[r
];
336 /* Take this moment to fill in the special picoJava bits in the
340 pj_elf_final_write_processing (bfd
*abfd
)
342 elf_elfheader (abfd
)->e_flags
|= EF_PICOJAVA_ARCH
;
343 elf_elfheader (abfd
)->e_flags
|= EF_PICOJAVA_GNUCALLS
;
344 return _bfd_elf_final_write_processing (abfd
);
347 #define TARGET_BIG_SYM pj_elf32_vec
348 #define TARGET_BIG_NAME "elf32-pj"
349 #define TARGET_LITTLE_SYM pj_elf32_le_vec
350 #define TARGET_LITTLE_NAME "elf32-pjl"
351 #define ELF_ARCH bfd_arch_pj
352 #define ELF_MACHINE_CODE EM_PJ
353 #define ELF_MACHINE_ALT1 EM_PJ_OLD
354 #define ELF_MAXPAGESIZE 0x1000
355 #define bfd_elf32_bfd_get_relocated_section_contents \
356 bfd_generic_get_relocated_section_contents
357 #define bfd_elf32_bfd_reloc_type_lookup pj_elf_reloc_type_lookup
358 #define bfd_elf32_bfd_reloc_name_lookup pj_elf_reloc_name_lookup
359 #define elf_backend_final_write_processing pj_elf_final_write_processing
360 #define elf_info_to_howto pj_elf_info_to_howto
361 #include "elf32-target.h"