1 /* Freescale S12Z-specific support for 32-bit ELF
2 Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 (Heavily copied from the D10V port by Martin Hunt (hunt@cygnus.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. */
30 /* Relocation functions. */
31 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
32 (bfd *, bfd_reloc_code_real_type);
33 static bfd_boolean s12z_info_to_howto_rel
34 (bfd *, arelent *, Elf_Internal_Rela *);
36 static bfd_reloc_status_type
37 shift_addend_reloc (bfd *abfd, arelent *reloc_entry, struct bfd_symbol *symbol ATTRIBUTE_UNUSED,
38 void *data ATTRIBUTE_UNUSED, asection *input_section ATTRIBUTE_UNUSED,
39 bfd *output ATTRIBUTE_UNUSED, char **msg ATTRIBUTE_UNUSED)
41 /* This is a really peculiar reloc, which is done for compatibility
42 with the Freescale toolchain.
44 That toolchain appears to (ab)use the lowest 15 bits of the addend for
45 the purpose of holding flags. The purpose of these flags are unknown.
46 So in this function, when writing the bfd we left shift the addend by
47 15, and when reading we right shift it by 15 (discarding the lower bits).
49 This allows the linker to work with object files generated by Freescale,
52 if (abfd->is_linker_input)
53 reloc_entry->addend >>= 15;
55 reloc_entry->addend <<= 15;
57 return bfd_reloc_continue;
62 static reloc_howto_type elf_s12z_howto_table[] =
64 /* This reloc does nothing. */
65 HOWTO (R_S12Z_NONE, /* type */
67 3, /* size (0 = byte, 1 = short, 2 = long) */
69 FALSE, /* pc_relative */
71 complain_overflow_dont,/* complain_on_overflow */
72 bfd_elf_generic_reloc, /* special_function */
73 "R_S12Z_NONE", /* name */
74 FALSE, /* partial_inplace */
77 FALSE), /* pcrel_offset */
79 /* A 24 bit absolute relocation emitted by the OPR mode operands */
80 HOWTO (R_S12Z_OPR, /* type */
82 5, /* size (0 = byte, 1 = short, 2 = long) */
84 FALSE, /* pc_relative */
86 complain_overflow_bitfield, /* complain_on_overflow */
88 "R_S12Z_OPR", /* name */
89 FALSE, /* partial_inplace */
90 0x00ffffff, /* src_mask */
91 0x00ffffff, /* dst_mask */
92 FALSE), /* pcrel_offset */
94 /* The purpose of this reloc is not known */
95 HOWTO (R_S12Z_UKNWN_2, /* type */
97 3, /* size (0 = byte, 1 = short, 2 = long) */
99 FALSE, /* pc_relative */
101 complain_overflow_dont,/* complain_on_overflow */
102 bfd_elf_generic_reloc, /* special_function */
103 "R_S12Z_UKNWN_2", /* name */
104 FALSE, /* partial_inplace */
107 FALSE), /* pcrel_offset */
109 /* A 15 bit PC-rel relocation */
110 HOWTO (R_S12Z_PCREL_7_15, /* type */
112 1, /* size (0 = byte, 1 = short, 2 = long) */
114 TRUE, /* pc_relative */
116 complain_overflow_bitfield, /* complain_on_overflow */
118 "R_S12Z_PCREL_7_15", /* name */
119 FALSE, /* partial_inplace */
121 0x007fff, /* dst_mask */
122 TRUE), /* pcrel_offset */
124 /* A 24 bit absolute relocation emitted by EXT24 mode operands */
125 HOWTO (R_S12Z_EXT24, /* type */
127 5, /* size (0 = byte, 1 = short, 2 = long) */
129 FALSE, /* pc_relative */
131 complain_overflow_bitfield, /* complain_on_overflow */
132 bfd_elf_generic_reloc, /* special_function */
133 "R_S12Z_EXT24", /* name */
134 FALSE, /* partial_inplace */
135 0x00ffffff, /* src_mask */
136 0x00ffffff, /* dst_mask */
137 FALSE), /* pcrel_offset */
139 /* The purpose of this reloc is not known */
140 HOWTO (R_S12Z_UKNWN_3, /* type */
142 3, /* size (0 = byte, 1 = short, 2 = long) */
144 FALSE, /* pc_relative */
146 complain_overflow_dont,/* complain_on_overflow */
147 bfd_elf_generic_reloc, /* special_function */
148 "R_S12Z_UKNWN_3", /* name */
149 FALSE, /* partial_inplace */
152 FALSE), /* pcrel_offset */
154 /* A 32 bit absolute relocation */
155 HOWTO (R_S12Z_EXT32, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 FALSE, /* pc_relative */
161 complain_overflow_bitfield, /* complain_on_overflow */
162 bfd_elf_generic_reloc, /* special_function */
163 "R_S12Z_EXT32", /* name */
164 FALSE, /* partial_inplace */
165 0xffffffff, /* src_mask */
166 0xffffffff, /* dst_mask */
167 FALSE), /* pcrel_offset */
170 /* Map BFD reloc types to S12Z ELF reloc types. */
172 struct s12z_reloc_map
174 bfd_reloc_code_real_type bfd_reloc_val;
175 unsigned char elf_reloc_val;
178 static const struct s12z_reloc_map s12z_reloc_map[] =
180 /* bfd reloc val */ /* elf reloc val */
181 {BFD_RELOC_NONE, R_S12Z_NONE},
182 {BFD_RELOC_32, R_S12Z_EXT32},
183 {BFD_RELOC_24, R_S12Z_EXT24},
184 {BFD_RELOC_16_PCREL, R_S12Z_PCREL_7_15}
187 static reloc_howto_type *
188 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
189 bfd_reloc_code_real_type code)
194 i < sizeof (s12z_reloc_map) / sizeof (struct s12z_reloc_map);
197 if (s12z_reloc_map[i].bfd_reloc_val == code)
199 return &elf_s12z_howto_table[s12z_reloc_map[i].elf_reloc_val];
203 printf ("%s:%d Not found type %d\n", __FILE__, __LINE__, code);
208 static reloc_howto_type *
209 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
214 printf ("%s:%d Looking up %s\n", __FILE__, __LINE__, r_name);
217 i < (sizeof (elf_s12z_howto_table)
218 / sizeof (elf_s12z_howto_table[0]));
220 if (elf_s12z_howto_table[i].name != NULL
221 && strcasecmp (elf_s12z_howto_table[i].name, r_name) == 0)
222 return &elf_s12z_howto_table[i];
227 /* Set the howto pointer for an S12Z ELF reloc. */
230 s12z_info_to_howto_rel (bfd *abfd,
231 arelent *cache_ptr, Elf_Internal_Rela *dst)
233 unsigned int r_type = ELF32_R_TYPE (dst->r_info);
235 if (r_type >= (unsigned int) R_S12Z_max)
237 /* xgettext:c-format */
238 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
240 bfd_set_error (bfd_error_bad_value);
244 cache_ptr->howto = &elf_s12z_howto_table[r_type];
249 s12z_elf_set_mach_from_flags (bfd *abfd)
251 bfd_default_set_arch_mach (abfd, bfd_arch_s12z, 0); // bfd_mach_s12z);
256 #define ELF_ARCH bfd_arch_s12z
257 #define ELF_TARGET_ID 0
258 #define ELF_MACHINE_CODE EM_S12Z
259 #define ELF_MAXPAGESIZE 0x1000
261 #define TARGET_BIG_SYM s12z_elf32_vec
262 #define TARGET_BIG_NAME "elf32-s12z"
264 #define elf_info_to_howto NULL
265 #define elf_info_to_howto_rel s12z_info_to_howto_rel
266 #define elf_backend_object_p s12z_elf_set_mach_from_flags
267 #define elf_backend_final_write_processing NULL
268 #define elf_backend_can_gc_sections 1
270 #include "elf32-target.h"