1 |
/* Generic support for 32-bit ELF |
/* BFD back-end for Renesas H8/300 ELF binaries. |
2 |
Copyright 1993, 1995, 1998, 1999, 2001, 2002 |
Copyright 1993, 1995, 1998, 1999, 2001, 2002, 2003, 2004 |
3 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of BFD, the Binary File Descriptor library. |
This file is part of BFD, the Binary File Descriptor library. |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify |
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 |
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 |
the Free Software Foundation; either version 2 of the License, or |
10 |
(at your option) any later version. |
(at your option) any later version. |
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
20 |
|
|
21 |
#include "bfd.h" |
#include "bfd.h" |
22 |
#include "sysdep.h" |
#include "sysdep.h" |
25 |
#include "elf/h8.h" |
#include "elf/h8.h" |
26 |
|
|
27 |
static reloc_howto_type *elf32_h8_reloc_type_lookup |
static reloc_howto_type *elf32_h8_reloc_type_lookup |
28 |
PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); |
(bfd *abfd, bfd_reloc_code_real_type code); |
29 |
static void elf32_h8_info_to_howto |
static void elf32_h8_info_to_howto |
30 |
PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
(bfd *, arelent *, Elf_Internal_Rela *); |
31 |
static void elf32_h8_info_to_howto_rel |
static void elf32_h8_info_to_howto_rel |
32 |
PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *)); |
(bfd *, arelent *, Elf_Internal_Rela *); |
33 |
static unsigned long elf32_h8_mach |
static unsigned long elf32_h8_mach (flagword); |
34 |
PARAMS ((flagword)); |
static void elf32_h8_final_write_processing (bfd *, bfd_boolean); |
35 |
static void elf32_h8_final_write_processing |
static bfd_boolean elf32_h8_object_p (bfd *); |
36 |
PARAMS ((bfd *, boolean)); |
static bfd_boolean elf32_h8_merge_private_bfd_data (bfd *, bfd *); |
37 |
static boolean elf32_h8_object_p |
static bfd_boolean elf32_h8_relax_section |
38 |
PARAMS ((bfd *)); |
(bfd *, asection *, struct bfd_link_info *, bfd_boolean *); |
39 |
static boolean elf32_h8_merge_private_bfd_data |
static bfd_boolean elf32_h8_relax_delete_bytes |
40 |
PARAMS ((bfd *, bfd *)); |
(bfd *, asection *, bfd_vma, int); |
41 |
static boolean elf32_h8_relax_section |
static bfd_boolean elf32_h8_symbol_address_p (bfd *, asection *, bfd_vma); |
|
PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *)); |
|
|
static boolean elf32_h8_relax_delete_bytes |
|
|
PARAMS ((bfd *, asection *, bfd_vma, int)); |
|
|
static boolean elf32_h8_symbol_address_p |
|
|
PARAMS ((bfd *, asection *, bfd_vma)); |
|
42 |
static bfd_byte *elf32_h8_get_relocated_section_contents |
static bfd_byte *elf32_h8_get_relocated_section_contents |
43 |
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, |
(bfd *, struct bfd_link_info *, struct bfd_link_order *, |
44 |
bfd_byte *, boolean, asymbol **)); |
bfd_byte *, bfd_boolean, asymbol **); |
45 |
|
static asection *elf32_h8_gc_mark_hook |
46 |
|
(asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
47 |
|
struct elf_link_hash_entry *, Elf_Internal_Sym *); |
48 |
|
static bfd_boolean elf32_h8_gc_sweep_hook |
49 |
|
(bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *); |
50 |
static bfd_reloc_status_type elf32_h8_final_link_relocate |
static bfd_reloc_status_type elf32_h8_final_link_relocate |
51 |
PARAMS ((unsigned long, bfd *, bfd *, asection *, |
(unsigned long, bfd *, bfd *, asection *, |
52 |
bfd_byte *, bfd_vma, bfd_vma, bfd_vma, |
bfd_byte *, bfd_vma, bfd_vma, bfd_vma, |
53 |
struct bfd_link_info *, asection *, int)); |
struct bfd_link_info *, asection *, int); |
54 |
static boolean elf32_h8_relocate_section |
static bfd_boolean elf32_h8_relocate_section |
55 |
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, |
(bfd *, struct bfd_link_info *, bfd *, asection *, |
56 |
bfd_byte *, Elf_Internal_Rela *, |
bfd_byte *, Elf_Internal_Rela *, |
57 |
Elf_Internal_Sym *, asection **)); |
Elf_Internal_Sym *, asection **); |
58 |
static bfd_reloc_status_type special |
static bfd_reloc_status_type special |
59 |
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); |
(bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **); |
60 |
|
|
61 |
/* This does not include any relocation information, but should be |
/* This does not include any relocation information, but should be |
62 |
good enough for GDB or objdump to read the file. */ |
good enough for GDB or objdump to read the file. */ |
63 |
|
|
64 |
static reloc_howto_type h8_elf_howto_table[] = |
static reloc_howto_type h8_elf_howto_table[] = { |
|
{ |
|
65 |
#define R_H8_NONE_X 0 |
#define R_H8_NONE_X 0 |
66 |
HOWTO (R_H8_NONE, /* type */ |
HOWTO (R_H8_NONE, /* type */ |
67 |
0, /* rightshift */ |
0, /* rightshift */ |
68 |
0, /* size (0 = byte, 1 = short, 2 = long) */ |
0, /* size (0 = byte, 1 = short, 2 = long) */ |
69 |
0, /* bitsize */ |
0, /* bitsize */ |
70 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
71 |
0, /* bitpos */ |
0, /* bitpos */ |
72 |
complain_overflow_dont, /* complain_on_overflow */ |
complain_overflow_dont,/* complain_on_overflow */ |
73 |
special, /* special_function */ |
special, /* special_function */ |
74 |
"R_H8_NONE", /* name */ |
"R_H8_NONE", /* name */ |
75 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
76 |
0, /* src_mask */ |
0, /* src_mask */ |
77 |
0, /* dst_mask */ |
0, /* dst_mask */ |
78 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
79 |
#define R_H8_DIR32_X (R_H8_NONE_X + 1) |
#define R_H8_DIR32_X (R_H8_NONE_X + 1) |
80 |
HOWTO (R_H8_DIR32, /* type */ |
HOWTO (R_H8_DIR32, /* type */ |
81 |
0, /* rightshift */ |
0, /* rightshift */ |
82 |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
83 |
32, /* bitsize */ |
32, /* bitsize */ |
84 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
85 |
0, /* bitpos */ |
0, /* bitpos */ |
86 |
complain_overflow_dont, /* complain_on_overflow */ |
complain_overflow_dont,/* complain_on_overflow */ |
87 |
special, /* special_function */ |
special, /* special_function */ |
88 |
"R_H8_DIR32", /* name */ |
"R_H8_DIR32", /* name */ |
89 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
90 |
0, /* src_mask */ |
0, /* src_mask */ |
91 |
0xffffffff, /* dst_mask */ |
0xffffffff, /* dst_mask */ |
92 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
93 |
#define R_H8_DIR16_X (R_H8_DIR32_X + 1) |
#define R_H8_DIR16_X (R_H8_DIR32_X + 1) |
94 |
HOWTO (R_H8_DIR16, /* type */ |
HOWTO (R_H8_DIR16, /* type */ |
95 |
0, /* rightshift */ |
0, /* rightshift */ |
96 |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
97 |
16, /* bitsize */ |
16, /* bitsize */ |
98 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
99 |
0, /* bitpos */ |
0, /* bitpos */ |
100 |
complain_overflow_dont, /* complain_on_overflow */ |
complain_overflow_dont,/* complain_on_overflow */ |
101 |
special, /* special_function */ |
special, /* special_function */ |
102 |
"R_H8_DIR16", /* name */ |
"R_H8_DIR16", /* name */ |
103 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
104 |
0, /* src_mask */ |
0, /* src_mask */ |
105 |
0x0000ffff, /* dst_mask */ |
0x0000ffff, /* dst_mask */ |
106 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
107 |
#define R_H8_DIR8_X (R_H8_DIR16_X + 1) |
#define R_H8_DIR8_X (R_H8_DIR16_X + 1) |
108 |
HOWTO (R_H8_DIR8, /* type */ |
HOWTO (R_H8_DIR8, /* type */ |
109 |
0, /* rightshift */ |
0, /* rightshift */ |
110 |
0, /* size (0 = byte, 1 = short, 2 = long) */ |
0, /* size (0 = byte, 1 = short, 2 = long) */ |
111 |
8, /* bitsize */ |
8, /* bitsize */ |
112 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
113 |
0, /* bitpos */ |
0, /* bitpos */ |
114 |
complain_overflow_dont, /* complain_on_overflow */ |
complain_overflow_dont,/* complain_on_overflow */ |
115 |
special, /* special_function */ |
special, /* special_function */ |
116 |
"R_H8_DIR16", /* name */ |
"R_H8_DIR8", /* name */ |
117 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
118 |
0, /* src_mask */ |
0, /* src_mask */ |
119 |
0x000000ff, /* dst_mask */ |
0x000000ff, /* dst_mask */ |
120 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
121 |
#define R_H8_DIR16A8_X (R_H8_DIR8_X + 1) |
#define R_H8_DIR16A8_X (R_H8_DIR8_X + 1) |
122 |
HOWTO (R_H8_DIR16A8, /* type */ |
HOWTO (R_H8_DIR16A8, /* type */ |
123 |
0, /* rightshift */ |
0, /* rightshift */ |
124 |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
125 |
16, /* bitsize */ |
16, /* bitsize */ |
126 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
127 |
0, /* bitpos */ |
0, /* bitpos */ |
128 |
complain_overflow_bitfield, /* complain_on_overflow */ |
complain_overflow_bitfield, /* complain_on_overflow */ |
129 |
special, /* special_function */ |
special, /* special_function */ |
130 |
"R_H8_DIR16A8", /* name */ |
"R_H8_DIR16A8", /* name */ |
131 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
132 |
0, /* src_mask */ |
0, /* src_mask */ |
133 |
0x0000ffff, /* dst_mask */ |
0x0000ffff, /* dst_mask */ |
134 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
135 |
#define R_H8_DIR16R8_X (R_H8_DIR16A8_X + 1) |
#define R_H8_DIR16R8_X (R_H8_DIR16A8_X + 1) |
136 |
HOWTO (R_H8_DIR16R8, /* type */ |
HOWTO (R_H8_DIR16R8, /* type */ |
137 |
0, /* rightshift */ |
0, /* rightshift */ |
138 |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
139 |
16, /* bitsize */ |
16, /* bitsize */ |
140 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
141 |
0, /* bitpos */ |
0, /* bitpos */ |
142 |
complain_overflow_bitfield, /* complain_on_overflow */ |
complain_overflow_bitfield, /* complain_on_overflow */ |
143 |
special, /* special_function */ |
special, /* special_function */ |
144 |
"R_H8_DIR16R8", /* name */ |
"R_H8_DIR16R8", /* name */ |
145 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
146 |
0, /* src_mask */ |
0, /* src_mask */ |
147 |
0x0000ffff, /* dst_mask */ |
0x0000ffff, /* dst_mask */ |
148 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
149 |
#define R_H8_DIR24A8_X (R_H8_DIR16R8_X + 1) |
#define R_H8_DIR24A8_X (R_H8_DIR16R8_X + 1) |
150 |
HOWTO (R_H8_DIR24A8, /* type */ |
HOWTO (R_H8_DIR24A8, /* type */ |
151 |
0, /* rightshift */ |
0, /* rightshift */ |
152 |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
153 |
24, /* bitsize */ |
24, /* bitsize */ |
154 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
155 |
0, /* bitpos */ |
0, /* bitpos */ |
156 |
complain_overflow_bitfield, /* complain_on_overflow */ |
complain_overflow_bitfield, /* complain_on_overflow */ |
157 |
special, /* special_function */ |
special, /* special_function */ |
158 |
"R_H8_DIR24A8", /* name */ |
"R_H8_DIR24A8", /* name */ |
159 |
true, /* partial_inplace */ |
TRUE, /* partial_inplace */ |
160 |
0xff000000, /* src_mask */ |
0xff000000, /* src_mask */ |
161 |
0x00ffffff, /* dst_mask */ |
0x00ffffff, /* dst_mask */ |
162 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
163 |
#define R_H8_DIR24R8_X (R_H8_DIR24A8_X + 1) |
#define R_H8_DIR24R8_X (R_H8_DIR24A8_X + 1) |
164 |
HOWTO (R_H8_DIR24R8, /* type */ |
HOWTO (R_H8_DIR24R8, /* type */ |
165 |
0, /* rightshift */ |
0, /* rightshift */ |
166 |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
167 |
24, /* bitsize */ |
24, /* bitsize */ |
168 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
169 |
0, /* bitpos */ |
0, /* bitpos */ |
170 |
complain_overflow_bitfield, /* complain_on_overflow */ |
complain_overflow_bitfield, /* complain_on_overflow */ |
171 |
special, /* special_function */ |
special, /* special_function */ |
172 |
"R_H8_DIR24R8", /* name */ |
"R_H8_DIR24R8", /* name */ |
173 |
true, /* partial_inplace */ |
TRUE, /* partial_inplace */ |
174 |
0xff000000, /* src_mask */ |
0xff000000, /* src_mask */ |
175 |
0x00ffffff, /* dst_mask */ |
0x00ffffff, /* dst_mask */ |
176 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
177 |
#define R_H8_DIR32A16_X (R_H8_DIR24R8_X + 1) |
#define R_H8_DIR32A16_X (R_H8_DIR24R8_X + 1) |
178 |
HOWTO (R_H8_DIR32A16, /* type */ |
HOWTO (R_H8_DIR32A16, /* type */ |
179 |
0, /* rightshift */ |
0, /* rightshift */ |
180 |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
2, /* size (0 = byte, 1 = short, 2 = long) */ |
181 |
32, /* bitsize */ |
32, /* bitsize */ |
182 |
false, /* pc_relative */ |
FALSE, /* pc_relative */ |
183 |
0, /* bitpos */ |
0, /* bitpos */ |
184 |
complain_overflow_dont, /* complain_on_overflow */ |
complain_overflow_dont,/* complain_on_overflow */ |
185 |
special, /* special_function */ |
special, /* special_function */ |
186 |
"R_H8_DIR32", /* name */ |
"R_H8_DIR32A16", /* name */ |
187 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
188 |
0, /* src_mask */ |
0, /* src_mask */ |
189 |
0xffffffff, /* dst_mask */ |
0xffffffff, /* dst_mask */ |
190 |
false), /* pcrel_offset */ |
FALSE), /* pcrel_offset */ |
191 |
#define R_H8_PCREL16_X (R_H8_DIR32A16_X + 1) |
#define R_H8_PCREL16_X (R_H8_DIR32A16_X + 1) |
192 |
HOWTO (R_H8_PCREL16, /* type */ |
HOWTO (R_H8_PCREL16, /* type */ |
193 |
0, /* rightshift */ |
0, /* rightshift */ |
194 |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
1, /* size (0 = byte, 1 = short, 2 = long) */ |
195 |
16, /* bitsize */ |
16, /* bitsize */ |
196 |
true, /* pc_relative */ |
TRUE, /* pc_relative */ |
197 |
0, /* bitpos */ |
0, /* bitpos */ |
198 |
complain_overflow_signed, /* complain_on_overflow */ |
complain_overflow_signed,/* complain_on_overflow */ |
199 |
special, /* special_function */ |
special, /* special_function */ |
200 |
"R_H8_PCREL16", /* name */ |
"R_H8_PCREL16", /* name */ |
201 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
202 |
0xffff, /* src_mask */ |
0xffff, /* src_mask */ |
203 |
0xffff, /* dst_mask */ |
0xffff, /* dst_mask */ |
204 |
true), /* pcrel_offset */ |
TRUE), /* pcrel_offset */ |
205 |
#define R_H8_PCREL8_X (R_H8_PCREL16_X + 1) |
#define R_H8_PCREL8_X (R_H8_PCREL16_X + 1) |
206 |
HOWTO (R_H8_PCREL8, /* type */ |
HOWTO (R_H8_PCREL8, /* type */ |
207 |
0, /* rightshift */ |
0, /* rightshift */ |
208 |
0, /* size (0 = byte, 1 = short, 2 = long) */ |
0, /* size (0 = byte, 1 = short, 2 = long) */ |
209 |
8, /* bitsize */ |
8, /* bitsize */ |
210 |
true, /* pc_relative */ |
TRUE, /* pc_relative */ |
211 |
0, /* bitpos */ |
0, /* bitpos */ |
212 |
complain_overflow_signed, /* complain_on_overflow */ |
complain_overflow_signed,/* complain_on_overflow */ |
213 |
special, /* special_function */ |
special, /* special_function */ |
214 |
"R_H8_PCREL8", /* name */ |
"R_H8_PCREL8", /* name */ |
215 |
false, /* partial_inplace */ |
FALSE, /* partial_inplace */ |
216 |
0xff, /* src_mask */ |
0xff, /* src_mask */ |
217 |
0xff, /* dst_mask */ |
0xff, /* dst_mask */ |
218 |
true), /* pcrel_offset */ |
TRUE), /* pcrel_offset */ |
219 |
}; |
}; |
220 |
|
|
221 |
/* This structure is used to map BFD reloc codes to H8 ELF relocs. */ |
/* This structure is used to map BFD reloc codes to H8 ELF relocs. */ |
222 |
|
|
223 |
struct elf_reloc_map |
struct elf_reloc_map { |
|
{ |
|
224 |
bfd_reloc_code_real_type bfd_reloc_val; |
bfd_reloc_code_real_type bfd_reloc_val; |
225 |
unsigned char howto_index; |
unsigned char howto_index; |
226 |
}; |
}; |
227 |
|
|
228 |
/* An array mapping BFD reloc codes to SH ELF relocs. */ |
/* An array mapping BFD reloc codes to H8 ELF relocs. */ |
229 |
|
|
230 |
static const struct elf_reloc_map h8_reloc_map[] = |
static const struct elf_reloc_map h8_reloc_map[] = { |
|
{ |
|
231 |
{ BFD_RELOC_NONE, R_H8_NONE_X }, |
{ BFD_RELOC_NONE, R_H8_NONE_X }, |
232 |
{ BFD_RELOC_32, R_H8_DIR32_X }, |
{ BFD_RELOC_32, R_H8_DIR32_X }, |
233 |
{ BFD_RELOC_16, R_H8_DIR16_X }, |
{ BFD_RELOC_16, R_H8_DIR16_X }, |
243 |
|
|
244 |
|
|
245 |
static reloc_howto_type * |
static reloc_howto_type * |
246 |
elf32_h8_reloc_type_lookup (abfd, code) |
elf32_h8_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
247 |
bfd *abfd ATTRIBUTE_UNUSED; |
bfd_reloc_code_real_type code) |
|
bfd_reloc_code_real_type code; |
|
248 |
{ |
{ |
249 |
unsigned int i; |
unsigned int i; |
250 |
|
|
257 |
} |
} |
258 |
|
|
259 |
static void |
static void |
260 |
elf32_h8_info_to_howto (abfd, bfd_reloc, elf_reloc) |
elf32_h8_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, |
261 |
bfd *abfd ATTRIBUTE_UNUSED; |
Elf_Internal_Rela *elf_reloc) |
|
arelent *bfd_reloc; |
|
|
Elf32_Internal_Rela *elf_reloc; |
|
262 |
{ |
{ |
263 |
unsigned int r; |
unsigned int r; |
264 |
unsigned int i; |
unsigned int i; |
265 |
|
|
266 |
r = ELF32_R_TYPE (elf_reloc->r_info); |
r = ELF32_R_TYPE (elf_reloc->r_info); |
267 |
for (i = 0; i < sizeof (h8_elf_howto_table) / sizeof (reloc_howto_type); i++) |
for (i = 0; i < sizeof (h8_elf_howto_table) / sizeof (reloc_howto_type); i++) |
268 |
if (h8_elf_howto_table[i].type== r) |
if (h8_elf_howto_table[i].type == r) |
269 |
{ |
{ |
270 |
bfd_reloc->howto = &h8_elf_howto_table[i]; |
bfd_reloc->howto = &h8_elf_howto_table[i]; |
271 |
return; |
return; |
274 |
} |
} |
275 |
|
|
276 |
static void |
static void |
277 |
elf32_h8_info_to_howto_rel (abfd, bfd_reloc, elf_reloc) |
elf32_h8_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, |
278 |
bfd *abfd ATTRIBUTE_UNUSED; |
Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) |
|
arelent *bfd_reloc; |
|
|
Elf32_Internal_Rel *elf_reloc ATTRIBUTE_UNUSED; |
|
279 |
{ |
{ |
280 |
unsigned int r; |
unsigned int r; |
281 |
|
|
289 |
When doing -r, we can't do any arithmetic for the pcrel stuff, because |
When doing -r, we can't do any arithmetic for the pcrel stuff, because |
290 |
we support relaxing on the H8/300 series chips. */ |
we support relaxing on the H8/300 series chips. */ |
291 |
static bfd_reloc_status_type |
static bfd_reloc_status_type |
292 |
special (abfd, reloc_entry, symbol, data, input_section, output_bfd, |
special (bfd *abfd ATTRIBUTE_UNUSED, |
293 |
error_message) |
arelent *reloc_entry ATTRIBUTE_UNUSED, |
294 |
bfd *abfd ATTRIBUTE_UNUSED; |
asymbol *symbol ATTRIBUTE_UNUSED, |
295 |
arelent *reloc_entry ATTRIBUTE_UNUSED; |
PTR data ATTRIBUTE_UNUSED, |
296 |
asymbol *symbol ATTRIBUTE_UNUSED; |
asection *input_section ATTRIBUTE_UNUSED, |
297 |
PTR data ATTRIBUTE_UNUSED; |
bfd *output_bfd, |
298 |
asection *input_section ATTRIBUTE_UNUSED; |
char **error_message ATTRIBUTE_UNUSED) |
|
bfd *output_bfd; |
|
|
char **error_message ATTRIBUTE_UNUSED; |
|
299 |
{ |
{ |
300 |
if (output_bfd == (bfd *) NULL) |
if (output_bfd == (bfd *) NULL) |
301 |
return bfd_reloc_continue; |
return bfd_reloc_continue; |
307 |
|
|
308 |
/* Perform a relocation as part of a final link. */ |
/* Perform a relocation as part of a final link. */ |
309 |
static bfd_reloc_status_type |
static bfd_reloc_status_type |
310 |
elf32_h8_final_link_relocate (r_type, input_bfd, output_bfd, |
elf32_h8_final_link_relocate (unsigned long r_type, bfd *input_bfd, |
311 |
input_section, contents, offset, value, |
bfd *output_bfd ATTRIBUTE_UNUSED, |
312 |
addend, info, sym_sec, is_local) |
asection *input_section ATTRIBUTE_UNUSED, |
313 |
unsigned long r_type; |
bfd_byte *contents, bfd_vma offset, |
314 |
bfd *input_bfd; |
bfd_vma value, bfd_vma addend, |
315 |
bfd *output_bfd ATTRIBUTE_UNUSED; |
struct bfd_link_info *info ATTRIBUTE_UNUSED, |
316 |
asection *input_section ATTRIBUTE_UNUSED; |
asection *sym_sec ATTRIBUTE_UNUSED, |
317 |
bfd_byte *contents; |
int is_local ATTRIBUTE_UNUSED) |
|
bfd_vma offset; |
|
|
bfd_vma value; |
|
|
bfd_vma addend; |
|
|
struct bfd_link_info *info ATTRIBUTE_UNUSED; |
|
|
asection *sym_sec ATTRIBUTE_UNUSED; |
|
|
int is_local ATTRIBUTE_UNUSED; |
|
318 |
{ |
{ |
319 |
bfd_byte *hit_data = contents + offset; |
bfd_byte *hit_data = contents + offset; |
320 |
|
|
321 |
switch (r_type) |
switch (r_type) |
322 |
{ |
{ |
|
|
|
323 |
case R_H8_NONE: |
case R_H8_NONE: |
324 |
return bfd_reloc_ok; |
return bfd_reloc_ok; |
325 |
|
|
348 |
value += addend; |
value += addend; |
349 |
|
|
350 |
/* HIT_DATA is the address for the first byte for the relocated |
/* HIT_DATA is the address for the first byte for the relocated |
351 |
value. Subtract 1 so that we can manipulate the data in 32bit |
value. Subtract 1 so that we can manipulate the data in 32-bit |
352 |
hunks. */ |
hunks. */ |
353 |
hit_data--; |
hit_data--; |
354 |
|
|
358 |
/* Retrieve the type byte for value from the section contents. */ |
/* Retrieve the type byte for value from the section contents. */ |
359 |
value |= (bfd_get_32 (input_bfd, hit_data) & 0xff000000); |
value |= (bfd_get_32 (input_bfd, hit_data) & 0xff000000); |
360 |
|
|
361 |
/* Now scribble it out in one 32bit hunk. */ |
/* Now scribble it out in one 32-bit hunk. */ |
362 |
bfd_put_32 (input_bfd, value, hit_data); |
bfd_put_32 (input_bfd, value, hit_data); |
363 |
return bfd_reloc_ok; |
return bfd_reloc_ok; |
364 |
|
|
396 |
} |
} |
397 |
|
|
398 |
/* Relocate an H8 ELF section. */ |
/* Relocate an H8 ELF section. */ |
399 |
static boolean |
static bfd_boolean |
400 |
elf32_h8_relocate_section (output_bfd, info, input_bfd, input_section, |
elf32_h8_relocate_section (bfd *output_bfd, struct bfd_link_info *info, |
401 |
contents, relocs, local_syms, local_sections) |
bfd *input_bfd, asection *input_section, |
402 |
bfd *output_bfd; |
bfd_byte *contents, Elf_Internal_Rela *relocs, |
403 |
struct bfd_link_info *info; |
Elf_Internal_Sym *local_syms, |
404 |
bfd *input_bfd; |
asection **local_sections) |
|
asection *input_section; |
|
|
bfd_byte *contents; |
|
|
Elf_Internal_Rela *relocs; |
|
|
Elf_Internal_Sym *local_syms; |
|
|
asection **local_sections; |
|
405 |
{ |
{ |
406 |
Elf_Internal_Shdr *symtab_hdr; |
Elf_Internal_Shdr *symtab_hdr; |
407 |
struct elf_link_hash_entry **sym_hashes; |
struct elf_link_hash_entry **sym_hashes; |
408 |
Elf_Internal_Rela *rel, *relend; |
Elf_Internal_Rela *rel, *relend; |
409 |
|
|
410 |
|
if (info->relocatable) |
411 |
|
return TRUE; |
412 |
|
|
413 |
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
414 |
sym_hashes = elf_sym_hashes (input_bfd); |
sym_hashes = elf_sym_hashes (input_bfd); |
415 |
|
|
425 |
bfd_vma relocation; |
bfd_vma relocation; |
426 |
bfd_reloc_status_type r; |
bfd_reloc_status_type r; |
427 |
|
|
428 |
|
/* This is a final link. */ |
429 |
r_symndx = ELF32_R_SYM (rel->r_info); |
r_symndx = ELF32_R_SYM (rel->r_info); |
430 |
r_type = ELF32_R_TYPE (rel->r_info); |
r_type = ELF32_R_TYPE (rel->r_info); |
|
|
|
|
if (info->relocateable) |
|
|
{ |
|
|
/* This is a relocateable link. We don't have to change |
|
|
anything, unless the reloc is against a section symbol, |
|
|
in which case we have to adjust according to where the |
|
|
section symbol winds up in the output section. */ |
|
|
if (r_symndx < symtab_hdr->sh_info) |
|
|
{ |
|
|
sym = local_syms + r_symndx; |
|
|
if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
|
|
{ |
|
|
sec = local_sections[r_symndx]; |
|
|
rel->r_addend += sec->output_offset + sym->st_value; |
|
|
} |
|
|
} |
|
|
|
|
|
continue; |
|
|
} |
|
|
|
|
|
/* This is a final link. */ |
|
431 |
h = NULL; |
h = NULL; |
432 |
sym = NULL; |
sym = NULL; |
433 |
sec = NULL; |
sec = NULL; |
435 |
{ |
{ |
436 |
sym = local_syms + r_symndx; |
sym = local_syms + r_symndx; |
437 |
sec = local_sections[r_symndx]; |
sec = local_sections[r_symndx]; |
438 |
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
439 |
} |
} |
440 |
else |
else |
441 |
{ |
{ |
442 |
h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
bfd_boolean unresolved_reloc, warned; |
443 |
while (h->root.type == bfd_link_hash_indirect |
|
444 |
|| h->root.type == bfd_link_hash_warning) |
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
445 |
h = (struct elf_link_hash_entry *) h->root.u.i.link; |
r_symndx, symtab_hdr, sym_hashes, |
446 |
if (h->root.type == bfd_link_hash_defined |
h, sec, relocation, |
447 |
|| h->root.type == bfd_link_hash_defweak) |
unresolved_reloc, warned); |
|
{ |
|
|
sec = h->root.u.def.section; |
|
|
relocation = (h->root.u.def.value |
|
|
+ sec->output_section->vma |
|
|
+ sec->output_offset); |
|
|
} |
|
|
else if (h->root.type == bfd_link_hash_undefweak) |
|
|
relocation = 0; |
|
|
else |
|
|
{ |
|
|
if (! ((*info->callbacks->undefined_symbol) |
|
|
(info, h->root.root.string, input_bfd, |
|
|
input_section, rel->r_offset, true))) |
|
|
return false; |
|
|
relocation = 0; |
|
|
} |
|
448 |
} |
} |
449 |
|
|
450 |
r = elf32_h8_final_link_relocate (r_type, input_bfd, output_bfd, |
r = elf32_h8_final_link_relocate (r_type, input_bfd, output_bfd, |
477 |
{ |
{ |
478 |
case bfd_reloc_overflow: |
case bfd_reloc_overflow: |
479 |
if (! ((*info->callbacks->reloc_overflow) |
if (! ((*info->callbacks->reloc_overflow) |
480 |
(info, name, howto->name, (bfd_vma) 0, |
(info, (h ? &h->root : NULL), name, howto->name, |
481 |
input_bfd, input_section, rel->r_offset))) |
(bfd_vma) 0, input_bfd, input_section, |
482 |
return false; |
rel->r_offset))) |
483 |
|
return FALSE; |
484 |
break; |
break; |
485 |
|
|
486 |
case bfd_reloc_undefined: |
case bfd_reloc_undefined: |
487 |
if (! ((*info->callbacks->undefined_symbol) |
if (! ((*info->callbacks->undefined_symbol) |
488 |
(info, name, input_bfd, input_section, |
(info, name, input_bfd, input_section, |
489 |
rel->r_offset, true))) |
rel->r_offset, TRUE))) |
490 |
return false; |
return FALSE; |
491 |
break; |
break; |
492 |
|
|
493 |
case bfd_reloc_outofrange: |
case bfd_reloc_outofrange: |
510 |
if (!((*info->callbacks->warning) |
if (!((*info->callbacks->warning) |
511 |
(info, msg, name, input_bfd, input_section, |
(info, msg, name, input_bfd, input_section, |
512 |
rel->r_offset))) |
rel->r_offset))) |
513 |
return false; |
return FALSE; |
514 |
break; |
break; |
515 |
} |
} |
516 |
} |
} |
517 |
} |
} |
518 |
|
|
519 |
return true; |
return TRUE; |
520 |
} |
} |
521 |
|
|
522 |
/* Object files encode the specific H8 model they were compiled |
/* Object files encode the specific H8 model they were compiled |
525 |
Examine that field and return the proper BFD machine type for |
Examine that field and return the proper BFD machine type for |
526 |
the object file. */ |
the object file. */ |
527 |
static unsigned long |
static unsigned long |
528 |
elf32_h8_mach (flags) |
elf32_h8_mach (flagword flags) |
|
flagword flags; |
|
529 |
{ |
{ |
530 |
switch (flags & EF_H8_MACH) |
switch (flags & EF_H8_MACH) |
531 |
{ |
{ |
538 |
|
|
539 |
case E_H8_MACH_H8300S: |
case E_H8_MACH_H8300S: |
540 |
return bfd_mach_h8300s; |
return bfd_mach_h8300s; |
541 |
|
|
542 |
|
case E_H8_MACH_H8300HN: |
543 |
|
return bfd_mach_h8300hn; |
544 |
|
|
545 |
|
case E_H8_MACH_H8300SN: |
546 |
|
return bfd_mach_h8300sn; |
547 |
|
|
548 |
|
case E_H8_MACH_H8300SX: |
549 |
|
return bfd_mach_h8300sx; |
550 |
|
|
551 |
|
case E_H8_MACH_H8300SXN: |
552 |
|
return bfd_mach_h8300sxn; |
553 |
} |
} |
554 |
} |
} |
555 |
|
|
558 |
into the flags field in the object file. */ |
into the flags field in the object file. */ |
559 |
|
|
560 |
static void |
static void |
561 |
elf32_h8_final_write_processing (abfd, linker) |
elf32_h8_final_write_processing (bfd *abfd, |
562 |
bfd *abfd; |
bfd_boolean linker ATTRIBUTE_UNUSED) |
|
boolean linker ATTRIBUTE_UNUSED; |
|
563 |
{ |
{ |
564 |
unsigned long val; |
unsigned long val; |
565 |
|
|
577 |
case bfd_mach_h8300s: |
case bfd_mach_h8300s: |
578 |
val = E_H8_MACH_H8300S; |
val = E_H8_MACH_H8300S; |
579 |
break; |
break; |
580 |
|
|
581 |
|
case bfd_mach_h8300hn: |
582 |
|
val = E_H8_MACH_H8300HN; |
583 |
|
break; |
584 |
|
|
585 |
|
case bfd_mach_h8300sn: |
586 |
|
val = E_H8_MACH_H8300SN; |
587 |
|
break; |
588 |
|
|
589 |
|
case bfd_mach_h8300sx: |
590 |
|
val = E_H8_MACH_H8300SX; |
591 |
|
break; |
592 |
|
|
593 |
|
case bfd_mach_h8300sxn: |
594 |
|
val = E_H8_MACH_H8300SXN; |
595 |
|
break; |
596 |
} |
} |
597 |
|
|
598 |
elf_elfheader (abfd)->e_flags &= ~ (EF_H8_MACH); |
elf_elfheader (abfd)->e_flags &= ~ (EF_H8_MACH); |
602 |
/* Return nonzero if ABFD represents a valid H8 ELF object file; also |
/* Return nonzero if ABFD represents a valid H8 ELF object file; also |
603 |
record the encoded machine type found in the ELF flags. */ |
record the encoded machine type found in the ELF flags. */ |
604 |
|
|
605 |
static boolean |
static bfd_boolean |
606 |
elf32_h8_object_p (abfd) |
elf32_h8_object_p (bfd *abfd) |
|
bfd *abfd; |
|
607 |
{ |
{ |
608 |
bfd_default_set_arch_mach (abfd, bfd_arch_h8300, |
bfd_default_set_arch_mach (abfd, bfd_arch_h8300, |
609 |
elf32_h8_mach (elf_elfheader (abfd)->e_flags)); |
elf32_h8_mach (elf_elfheader (abfd)->e_flags)); |
610 |
return true; |
return TRUE; |
611 |
} |
} |
612 |
|
|
613 |
/* Merge backend specific data from an object file to the output |
/* Merge backend specific data from an object file to the output |
614 |
object file when linking. The only data we need to copy at this |
object file when linking. The only data we need to copy at this |
615 |
time is the architecture/machine information. */ |
time is the architecture/machine information. */ |
616 |
|
|
617 |
static boolean |
static bfd_boolean |
618 |
elf32_h8_merge_private_bfd_data (ibfd, obfd) |
elf32_h8_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
|
bfd *ibfd; |
|
|
bfd *obfd; |
|
619 |
{ |
{ |
620 |
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
621 |
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
622 |
return true; |
return TRUE; |
623 |
|
|
624 |
if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) |
if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) |
625 |
&& bfd_get_mach (obfd) < bfd_get_mach (ibfd)) |
&& bfd_get_mach (obfd) < bfd_get_mach (ibfd)) |
626 |
{ |
{ |
627 |
if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), |
if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), |
628 |
bfd_get_mach (ibfd))) |
bfd_get_mach (ibfd))) |
629 |
return false; |
return FALSE; |
630 |
} |
} |
631 |
|
|
632 |
return true; |
return TRUE; |
633 |
} |
} |
634 |
|
|
635 |
/* This function handles relaxing for the H8.. |
/* This function handles relaxing for the H8.. |
636 |
|
|
637 |
There's a few relaxing opportunites available on the H8: |
There are a few relaxing opportunities available on the H8: |
638 |
|
|
639 |
jmp/jsr:24 -> bra/bsr:8 2 bytes |
jmp/jsr:24 -> bra/bsr:8 2 bytes |
640 |
The jmp may be completely eliminated if the previous insn is a |
The jmp may be completely eliminated if the previous insn is a |
644 |
bCC:16 -> bCC:8 2 bytes |
bCC:16 -> bCC:8 2 bytes |
645 |
bsr:16 -> bsr:8 2 bytes |
bsr:16 -> bsr:8 2 bytes |
646 |
|
|
647 |
|
bset:16 -> bset:8 2 bytes |
648 |
|
bset:24/32 -> bset:8 4 bytes |
649 |
|
(also applicable to other bit manipulation instructions) |
650 |
|
|
651 |
mov.b:16 -> mov.b:8 2 bytes |
mov.b:16 -> mov.b:8 2 bytes |
652 |
mov.b:24/32 -> mov.b:8 4 bytes |
mov.b:24/32 -> mov.b:8 4 bytes |
653 |
|
|
654 |
|
bset:24/32 -> bset:16 2 bytes |
655 |
|
(also applicable to other bit manipulation instructions) |
656 |
|
|
657 |
mov.[bwl]:24/32 -> mov.[bwl]:16 2 bytes */ |
mov.[bwl]:24/32 -> mov.[bwl]:16 2 bytes */ |
658 |
|
|
659 |
static boolean |
static bfd_boolean |
660 |
elf32_h8_relax_section (abfd, sec, link_info, again) |
elf32_h8_relax_section (bfd *abfd, asection *sec, |
661 |
bfd *abfd; |
struct bfd_link_info *link_info, bfd_boolean *again) |
|
asection *sec; |
|
|
struct bfd_link_info *link_info; |
|
|
boolean *again; |
|
662 |
{ |
{ |
663 |
Elf_Internal_Shdr *symtab_hdr; |
Elf_Internal_Shdr *symtab_hdr; |
664 |
Elf_Internal_Rela *internal_relocs; |
Elf_Internal_Rela *internal_relocs; |
669 |
static Elf_Internal_Rela *last_reloc = NULL; |
static Elf_Internal_Rela *last_reloc = NULL; |
670 |
|
|
671 |
/* Assume nothing changes. */ |
/* Assume nothing changes. */ |
672 |
*again = false; |
*again = FALSE; |
673 |
|
|
674 |
/* We don't have to do anything for a relocateable link, if |
/* We don't have to do anything for a relocatable link, if |
675 |
this section does not have relocs, or if this is not a |
this section does not have relocs, or if this is not a |
676 |
code section. */ |
code section. */ |
677 |
if (link_info->relocateable |
if (link_info->relocatable |
678 |
|| (sec->flags & SEC_RELOC) == 0 |
|| (sec->flags & SEC_RELOC) == 0 |
679 |
|| sec->reloc_count == 0 |
|| sec->reloc_count == 0 |
680 |
|| (sec->flags & SEC_CODE) == 0) |
|| (sec->flags & SEC_CODE) == 0) |
681 |
return true; |
return TRUE; |
|
|
|
|
/* If this is the first time we have been called for this section, |
|
|
initialize the cooked size. */ |
|
|
if (sec->_cooked_size == 0) |
|
|
sec->_cooked_size = sec->_raw_size; |
|
682 |
|
|
683 |
symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
684 |
|
|
685 |
/* Get a copy of the native relocations. */ |
/* Get a copy of the native relocations. */ |
686 |
internal_relocs = (_bfd_elf32_link_read_relocs |
internal_relocs = (_bfd_elf_link_read_relocs |
687 |
(abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
(abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
688 |
link_info->keep_memory)); |
link_info->keep_memory)); |
689 |
if (internal_relocs == NULL) |
if (internal_relocs == NULL) |
721 |
else |
else |
722 |
{ |
{ |
723 |
/* Go get them off disk. */ |
/* Go get them off disk. */ |
724 |
contents = (bfd_byte *) bfd_malloc (sec->_raw_size); |
if (!bfd_malloc_and_get_section (abfd, sec, &contents)) |
|
if (contents == NULL) |
|
|
goto error_return; |
|
|
|
|
|
if (! bfd_get_section_contents (abfd, sec, contents, |
|
|
(file_ptr) 0, sec->_raw_size)) |
|
725 |
goto error_return; |
goto error_return; |
726 |
} |
} |
727 |
} |
} |
745 |
Elf_Internal_Sym *isym; |
Elf_Internal_Sym *isym; |
746 |
asection *sym_sec; |
asection *sym_sec; |
747 |
|
|
748 |
isym = isymbuf + ELF64_R_SYM (irel->r_info); |
isym = isymbuf + ELF32_R_SYM (irel->r_info); |
749 |
sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
750 |
symval = (isym->st_value |
symval = isym->st_value; |
751 |
+ sym_sec->output_section->vma |
/* If the reloc is absolute, it will not have |
752 |
+ sym_sec->output_offset); |
a symbol or section associated with it. */ |
753 |
|
if (sym_sec) |
754 |
|
symval += sym_sec->output_section->vma |
755 |
|
+ sym_sec->output_offset; |
756 |
} |
} |
757 |
else |
else |
758 |
{ |
{ |
786 |
the linker is run. */ |
the linker is run. */ |
787 |
switch (ELF32_R_TYPE (irel->r_info)) |
switch (ELF32_R_TYPE (irel->r_info)) |
788 |
{ |
{ |
789 |
/* Try to turn a 24 bit absolute branch/call into an 8 bit |
/* Try to turn a 24-bit absolute branch/call into an 8-bit |
790 |
pc-relative branch/call. */ |
pc-relative branch/call. */ |
791 |
case R_H8_DIR24R8: |
case R_H8_DIR24R8: |
792 |
{ |
{ |
813 |
elf_section_data (sec)->this_hdr.contents = contents; |
elf_section_data (sec)->this_hdr.contents = contents; |
814 |
symtab_hdr->contents = (unsigned char *) isymbuf; |
symtab_hdr->contents = (unsigned char *) isymbuf; |
815 |
|
|
816 |
|
/* Get the instruction code being relaxed. */ |
817 |
|
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
818 |
|
|
819 |
/* If the previous instruction conditionally jumped around |
/* If the previous instruction conditionally jumped around |
820 |
this instruction, we may be able to reverse the condition |
this instruction, we may be able to reverse the condition |
821 |
and redirect the previous instruction to the target of |
and redirect the previous instruction to the target of |
822 |
this instruction. |
this instruction. |
823 |
|
|
824 |
Such sequences are used by the compiler to deal with |
Such sequences are used by the compiler to deal with |
825 |
long conditional branches. */ |
long conditional branches. |
826 |
if ((int) gap <= 130 |
|
827 |
|
Only perform this optimisation for jumps (code 0x5a) not |
828 |
|
subroutine calls, as otherwise it could transform: |
829 |
|
|
830 |
|
mov.w r0,r0 |
831 |
|
beq .L1 |
832 |
|
jsr @_bar |
833 |
|
.L1: rts |
834 |
|
_bar: rts |
835 |
|
into: |
836 |
|
mov.w r0,r0 |
837 |
|
bne _bar |
838 |
|
rts |
839 |
|
_bar: rts |
840 |
|
|
841 |
|
which changes the call (jsr) into a branch (bne). */ |
842 |
|
if (code == 0x5a |
843 |
|
&& (int) gap <= 130 |
844 |
&& (int) gap >= -128 |
&& (int) gap >= -128 |
845 |
&& last_reloc |
&& last_reloc |
846 |
&& ELF32_R_TYPE (last_reloc->r_info) == R_H8_PCREL8 |
&& ELF32_R_TYPE (last_reloc->r_info) == R_H8_PCREL8 |
873 |
= ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
= ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
874 |
ELF32_R_TYPE (R_H8_NONE)); |
ELF32_R_TYPE (R_H8_NONE)); |
875 |
|
|
876 |
last_reloc->r_info |
last_reloc->r_info |
877 |
= ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
= ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
878 |
ELF32_R_TYPE (R_H8_PCREL8)); |
ELF32_R_TYPE (R_H8_PCREL8)); |
879 |
last_reloc->r_addend = irel->r_addend; |
last_reloc->r_addend = irel->r_addend; |
|
|
|
880 |
|
|
881 |
code = bfd_get_8 (abfd, |
code = bfd_get_8 (abfd, |
882 |
contents + last_reloc->r_offset - 1); |
contents + last_reloc->r_offset - 1); |
891 |
4)) |
4)) |
892 |
goto error_return; |
goto error_return; |
893 |
|
|
894 |
*again = true; |
*again = TRUE; |
895 |
break; |
break; |
896 |
} |
} |
897 |
} |
} |
898 |
|
|
|
/* We could not eliminate this jump, so just shorten it. */ |
|
|
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
|
|
|
|
899 |
if (code == 0x5e) |
if (code == 0x5e) |
900 |
|
/* This is jsr. */ |
901 |
bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 1); |
bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 1); |
902 |
else if (code == 0x5a) |
else if (code == 0x5a) |
903 |
|
/* This is jmp. */ |
904 |
bfd_put_8 (abfd, 0x40, contents + irel->r_offset - 1); |
bfd_put_8 (abfd, 0x40, contents + irel->r_offset - 1); |
905 |
else |
else |
906 |
abort (); |
abort (); |
916 |
|
|
917 |
/* That will change things, so, we should relax again. |
/* That will change things, so, we should relax again. |
918 |
Note that this is not required, and it may be slow. */ |
Note that this is not required, and it may be slow. */ |
919 |
*again = true; |
*again = TRUE; |
920 |
} |
} |
921 |
break; |
break; |
922 |
} |
} |
923 |
|
|
924 |
/* Try to turn a 16bit pc-relative branch into a 8bit pc-relative |
/* Try to turn a 16-bit pc-relative branch into a 8-bit pc-relative |
925 |
branch. */ |
branch. */ |
926 |
case R_H8_PCREL16: |
case R_H8_PCREL16: |
927 |
{ |
{ |
939 |
/* If the distance is within -126..+130 inclusive, then we can |
/* If the distance is within -126..+130 inclusive, then we can |
940 |
relax this jump. +130 is valid since the target will move |
relax this jump. +130 is valid since the target will move |
941 |
two bytes closer if we do relax this branch. */ |
two bytes closer if we do relax this branch. */ |
942 |
if ((int)gap >= -126 && (int)gap <= 130) |
if ((int) gap >= -126 && (int) gap <= 130) |
943 |
{ |
{ |
944 |
unsigned char code; |
unsigned char code; |
945 |
|
|
946 |
/* Note that we've changed the relocs, section contents, |
/* Note that we've changed the relocs, section contents, |
947 |
etc. */ |
etc. */ |
948 |
elf_section_data (sec)->relocs = internal_relocs; |
elf_section_data (sec)->relocs = internal_relocs; |
949 |
elf_section_data (sec)->this_hdr.contents = contents; |
elf_section_data (sec)->this_hdr.contents = contents; |
950 |
symtab_hdr->contents = (unsigned char *) isymbuf; |
symtab_hdr->contents = (unsigned char *) isymbuf; |
951 |
|
|
952 |
/* Get the opcode. */ |
/* Get the opcode. */ |
953 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 2); |
code = bfd_get_8 (abfd, contents + irel->r_offset - 2); |
954 |
|
|
955 |
if (code == 0x58) |
if (code == 0x58) |
956 |
{ |
{ |
957 |
/* bCC:16 -> bCC:8 */ |
/* bCC:16 -> bCC:8 */ |
958 |
/* Get the condition code from the original insn. */ |
/* Get the second byte of the original insn, which |
959 |
|
contains the condition code. */ |
960 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
961 |
|
|
962 |
|
/* Compute the fisrt byte of the relaxed |
963 |
|
instruction. The original sequence 0x58 0xX0 |
964 |
|
is relaxed to 0x4X, where X represents the |
965 |
|
condition code. */ |
966 |
code &= 0xf0; |
code &= 0xf0; |
967 |
code >>= 4; |
code >>= 4; |
968 |
code |= 0x40; |
code |= 0x40; |
969 |
bfd_put_8 (abfd, code, contents + irel->r_offset - 2); |
bfd_put_8 (abfd, code, contents + irel->r_offset - 2); |
970 |
} |
} |
971 |
else if (code == 0x5c) |
else if (code == 0x5c) |
972 |
|
/* This is bsr. */ |
973 |
bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 2); |
bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 2); |
974 |
else |
else |
975 |
abort (); |
abort (); |
976 |
|
|
977 |
/* Fix the relocation's type. */ |
/* Fix the relocation's type. */ |
978 |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
979 |
R_H8_PCREL8); |
R_H8_PCREL8); |
980 |
irel->r_offset--; |
irel->r_offset--; |
981 |
|
|
982 |
/* Delete two bytes of data. */ |
/* Delete two bytes of data. */ |
983 |
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
984 |
irel->r_offset + 1, 2)) |
irel->r_offset + 1, 2)) |
985 |
goto error_return; |
goto error_return; |
986 |
|
|
987 |
/* That will change things, so, we should relax again. |
/* That will change things, so, we should relax again. |
988 |
Note that this is not required, and it may be slow. */ |
Note that this is not required, and it may be slow. */ |
989 |
*again = true; |
*again = TRUE; |
990 |
} |
} |
991 |
break; |
break; |
992 |
} |
} |
993 |
|
|
994 |
/* This is a 16 bit absolute address in a "mov.b" insn, which may |
/* This is a 16-bit absolute address in one of the following |
995 |
become an 8 bit absolute address if its in the right range. */ |
instructions: |
996 |
|
|
997 |
|
"band", "bclr", "biand", "bild", "bior", "bist", "bixor", |
998 |
|
"bld", "bnot", "bor", "bset", "bst", "btst", "bxor", and |
999 |
|
"mov.b" |
1000 |
|
|
1001 |
|
We may relax this into an 8-bit absolute address if it's in |
1002 |
|
the right range. */ |
1003 |
case R_H8_DIR16A8: |
case R_H8_DIR16A8: |
1004 |
{ |
{ |
1005 |
bfd_vma value = symval + irel->r_addend; |
bfd_vma value; |
1006 |
|
|
1007 |
if ((bfd_get_mach (abfd) == bfd_mach_h8300 |
value = bfd_h8300_pad_address (abfd, symval + irel->r_addend); |
1008 |
&& value >= 0xff00 |
if (value >= 0xffffff00u) |
|
&& value <= 0xffff) |
|
|
|| ((bfd_get_mach (abfd) == bfd_mach_h8300h |
|
|
|| bfd_get_mach (abfd) == bfd_mach_h8300s) |
|
|
&& value >= 0xffff00 |
|
|
&& value <= 0xffffff)) |
|
1009 |
{ |
{ |
1010 |
unsigned char code; |
unsigned char code; |
1011 |
|
unsigned char temp_code; |
1012 |
|
|
1013 |
/* Note that we've changed the relocs, section contents, |
/* Note that we've changed the relocs, section contents, |
1014 |
etc. */ |
etc. */ |
1015 |
elf_section_data (sec)->relocs = internal_relocs; |
elf_section_data (sec)->relocs = internal_relocs; |
1016 |
elf_section_data (sec)->this_hdr.contents = contents; |
elf_section_data (sec)->this_hdr.contents = contents; |
1017 |
symtab_hdr->contents = (unsigned char *) isymbuf; |
symtab_hdr->contents = (unsigned char *) isymbuf; |
1018 |
|
|
1019 |
/* Get the opcode. */ |
/* Get the opcode. */ |
1020 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 2); |
code = bfd_get_8 (abfd, contents + irel->r_offset - 2); |
1021 |
|
|
1022 |
/* Sanity check. */ |
/* All instructions with R_H8_DIR16A8 start with |
1023 |
if (code != 0x6a) |
0x6a. */ |
1024 |
|
if (code != 0x6a) |
1025 |
abort (); |
abort (); |
1026 |
|
|
1027 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
temp_code = code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
1028 |
|
/* If this is a mov.b instruction, clear the lower |
1029 |
|
nibble, which contains the source/destination |
1030 |
|
register number. */ |
1031 |
|
if ((temp_code & 0x10) != 0x10) |
1032 |
|
temp_code &= 0xf0; |
1033 |
|
|
1034 |
if ((code & 0xf0) == 0x00) |
switch (temp_code) |
1035 |
bfd_put_8 (abfd, |
{ |
1036 |
(code & 0xf) | 0x20, |
case 0x00: |
1037 |
contents + irel->r_offset - 2); |
/* This is mov.b @aa:16,Rd. */ |
1038 |
else if ((code & 0xf0) == 0x80) |
bfd_put_8 (abfd, (code & 0xf) | 0x20, |
1039 |
bfd_put_8 (abfd, |
contents + irel->r_offset - 2); |
1040 |
(code & 0xf) | 0x30, |
break; |
1041 |
contents + irel->r_offset - 2); |
case 0x80: |
1042 |
else |
/* This is mov.b Rs,@aa:16. */ |
1043 |
abort (); |
bfd_put_8 (abfd, (code & 0xf) | 0x30, |
1044 |
|
contents + irel->r_offset - 2); |
1045 |
|
break; |
1046 |
|
case 0x18: |
1047 |
|
/* This is a bit-maniputation instruction that |
1048 |
|
stores one bit into memory, one of "bclr", |
1049 |
|
"bist", "bnot", "bset", and "bst". */ |
1050 |
|
bfd_put_8 (abfd, 0x7f, contents + irel->r_offset - 2); |
1051 |
|
break; |
1052 |
|
case 0x10: |
1053 |
|
/* This is a bit-maniputation instruction that |
1054 |
|
loads one bit from memory, one of "band", |
1055 |
|
"biand", "bild", "bior", "bixor", "bld", "bor", |
1056 |
|
"btst", and "bxor". */ |
1057 |
|
bfd_put_8 (abfd, 0x7e, contents + irel->r_offset - 2); |
1058 |
|
break; |
1059 |
|
default: |
1060 |
|
abort (); |
1061 |
|
} |
1062 |
|
|
1063 |
/* Fix the relocation's type. */ |
/* Fix the relocation's type. */ |
1064 |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
1065 |
R_H8_DIR8); |
R_H8_DIR8); |
1066 |
|
|
1067 |
/* Delete two bytes of data. */ |
/* Move the relocation. */ |
1068 |
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
irel->r_offset--; |
1069 |
|
|
1070 |
|
/* Delete two bytes of data. */ |
1071 |
|
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
1072 |
irel->r_offset + 1, 2)) |
irel->r_offset + 1, 2)) |
1073 |
goto error_return; |
goto error_return; |
1074 |
|
|
1075 |
/* That will change things, so, we should relax again. |
/* That will change things, so, we should relax again. |
1076 |
Note that this is not required, and it may be slow. */ |
Note that this is not required, and it may be slow. */ |
1077 |
*again = true; |
*again = TRUE; |
1078 |
} |
} |
1079 |
break; |
break; |
1080 |
} |
} |
1081 |
|
|
1082 |
/* This is a 24 bit absolute address in a "mov.b" insn, which may |
/* This is a 24-bit absolute address in one of the following |
1083 |
become an 8 bit absolute address if its in the right range. */ |
instructions: |
1084 |
|
|
1085 |
|
"band", "bclr", "biand", "bild", "bior", "bist", "bixor", |
1086 |
|
"bld", "bnot", "bor", "bset", "bst", "btst", "bxor", and |
1087 |
|
"mov.b" |
1088 |
|
|
1089 |
|
We may relax this into an 8-bit absolute address if it's in |
1090 |
|
the right range. */ |
1091 |
case R_H8_DIR24A8: |
case R_H8_DIR24A8: |
1092 |
{ |
{ |
1093 |
bfd_vma value = symval + irel->r_addend; |
bfd_vma value; |
1094 |
|
|
1095 |
if ((bfd_get_mach (abfd) == bfd_mach_h8300 |
value = bfd_h8300_pad_address (abfd, symval + irel->r_addend); |
1096 |
&& value >= 0xff00 |
if (value >= 0xffffff00u) |
|
&& value <= 0xffff) |
|
|
|| ((bfd_get_mach (abfd) == bfd_mach_h8300h |
|
|
|| bfd_get_mach (abfd) == bfd_mach_h8300s) |
|
|
&& value >= 0xffff00 |
|
|
&& value <= 0xffffff)) |
|
1097 |
{ |
{ |
1098 |
unsigned char code; |
unsigned char code; |
1099 |
|
unsigned char temp_code; |
1100 |
|
|
1101 |
/* Note that we've changed the relocs, section contents, |
/* Note that we've changed the relocs, section contents, |
1102 |
etc. */ |
etc. */ |
1103 |
elf_section_data (sec)->relocs = internal_relocs; |
elf_section_data (sec)->relocs = internal_relocs; |
1104 |
elf_section_data (sec)->this_hdr.contents = contents; |
elf_section_data (sec)->this_hdr.contents = contents; |
1105 |
symtab_hdr->contents = (unsigned char *) isymbuf; |
symtab_hdr->contents = (unsigned char *) isymbuf; |
1106 |
|
|
1107 |
/* Get the opcode. */ |
/* Get the opcode. */ |
1108 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 2); |
code = bfd_get_8 (abfd, contents + irel->r_offset - 2); |
1109 |
|
|
1110 |
/* Sanity check. */ |
/* All instructions with R_H8_DIR24A8 start with |
1111 |
if (code != 0x6a) |
0x6a. */ |
1112 |
|
if (code != 0x6a) |
1113 |
abort (); |
abort (); |
1114 |
|
|
1115 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
temp_code = code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
1116 |
|
|
1117 |
if ((code & 0xf0) == 0x00) |
/* If this is a mov.b instruction, clear the lower |
1118 |
bfd_put_8 (abfd, |
nibble, which contains the source/destination |
1119 |
(code & 0xf) | 0x20, |
register number. */ |
1120 |
contents + irel->r_offset - 2); |
if ((temp_code & 0x30) != 0x30) |
1121 |
else if ((code & 0xf0) == 0x80) |
temp_code &= 0xf0; |
|
bfd_put_8 (abfd, |
|
|
(code & 0xf) | 0x30, |
|
|
contents + irel->r_offset - 2); |
|
|
else |
|
|
abort (); |
|
1122 |
|
|
1123 |
/* Fix the relocation's type. */ |
switch (temp_code) |
1124 |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
{ |
1125 |
|
case 0x20: |
1126 |
|
/* This is mov.b @aa:24/32,Rd. */ |
1127 |
|
bfd_put_8 (abfd, (code & 0xf) | 0x20, |
1128 |
|
contents + irel->r_offset - 2); |
1129 |
|
break; |
1130 |
|
case 0xa0: |
1131 |
|
/* This is mov.b Rs,@aa:24/32. */ |
1132 |
|
bfd_put_8 (abfd, (code & 0xf) | 0x30, |
1133 |
|
contents + irel->r_offset - 2); |
1134 |
|
break; |
1135 |
|
case 0x38: |
1136 |
|
/* This is a bit-maniputation instruction that |
1137 |
|
stores one bit into memory, one of "bclr", |
1138 |
|
"bist", "bnot", "bset", and "bst". */ |
1139 |
|
bfd_put_8 (abfd, 0x7f, contents + irel->r_offset - 2); |
1140 |
|
break; |
1141 |
|
case 0x30: |
1142 |
|
/* This is a bit-maniputation instruction that |
1143 |
|
loads one bit from memory, one of "band", |
1144 |
|
"biand", "bild", "bior", "bixor", "bld", "bor", |
1145 |
|
"btst", and "bxor". */ |
1146 |
|
bfd_put_8 (abfd, 0x7e, contents + irel->r_offset - 2); |
1147 |
|
break; |
1148 |
|
default: |
1149 |
|
abort(); |
1150 |
|
} |
1151 |
|
|
1152 |
|
/* Fix the relocation's type. */ |
1153 |
|
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
1154 |
R_H8_DIR8); |
R_H8_DIR8); |
1155 |
|
irel->r_offset--; |
1156 |
|
|
1157 |
/* Delete two bytes of data. */ |
/* Delete two bytes of data. */ |
1158 |
if (!elf32_h8_relax_delete_bytes (abfd, sec, irel->r_offset, 2)) |
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
1159 |
|
irel->r_offset + 1, 4)) |
1160 |
goto error_return; |
goto error_return; |
1161 |
|
|
1162 |
/* That will change things, so, we should relax again. |
/* That will change things, so, we should relax again. |
1163 |
Note that this is not required, and it may be slow. */ |
Note that this is not required, and it may be slow. */ |
1164 |
*again = true; |
*again = TRUE; |
1165 |
|
break; |
1166 |
} |
} |
1167 |
} |
} |
1168 |
|
|
1169 |
/* FALLTHRU */ |
/* Fall through. */ |
1170 |
|
|
1171 |
|
/* This is a 24-/32-bit absolute address in one of the |
1172 |
|
following instructions: |
1173 |
|
|
1174 |
/* This is a 24/32bit absolute address in a "mov" insn, which may |
"band", "bclr", "biand", "bild", "bior", "bist", |
1175 |
become a 16bit absoulte address if it is in the right range. */ |
"bixor", "bld", "bnot", "bor", "bset", "bst", "btst", |
1176 |
|
"bxor", "ldc.w", "stc.w" and "mov.[bwl]" |
1177 |
|
|
1178 |
|
We may relax this into an 16-bit absolute address if it's |
1179 |
|
in the right range. */ |
1180 |
case R_H8_DIR32A16: |
case R_H8_DIR32A16: |
1181 |
{ |
{ |
1182 |
bfd_vma value = symval + irel->r_addend; |
bfd_vma value; |
1183 |
|
|
1184 |
if (value <= 0x7fff || value >= 0xff8000) |
value = bfd_h8300_pad_address (abfd, symval + irel->r_addend); |
1185 |
|
if (value <= 0x7fff || value >= 0xffff8000u) |
1186 |
{ |
{ |
1187 |
unsigned char code; |
unsigned char code; |
1188 |
|
|
1189 |
/* Note that we've changed the relocs, section contents, |
/* Note that we've changed the relocs, section contents, |
1190 |
etc. */ |
etc. */ |
1191 |
elf_section_data (sec)->relocs = internal_relocs; |
elf_section_data (sec)->relocs = internal_relocs; |
1192 |
elf_section_data (sec)->this_hdr.contents = contents; |
elf_section_data (sec)->this_hdr.contents = contents; |
1193 |
symtab_hdr->contents = (unsigned char *) isymbuf; |
symtab_hdr->contents = (unsigned char *) isymbuf; |
1194 |
|
|
1195 |
/* Get the opcode. */ |
/* Get the opcode. */ |
1196 |
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
code = bfd_get_8 (abfd, contents + irel->r_offset - 1); |
1197 |
|
|
1198 |
/* We just need to turn off bit 0x20. */ |
/* Fix the opcode. For all the instructions that |
1199 |
code &= ~0x20; |
belong to this relaxation, we simply need to turn |
1200 |
|
off bit 0x20 in the previous byte. */ |
1201 |
|
code &= ~0x20; |
1202 |
|
|
1203 |
bfd_put_8 (abfd, code, contents + irel->r_offset - 1); |
bfd_put_8 (abfd, code, contents + irel->r_offset - 1); |
1204 |
|
|
1205 |
/* Fix the relocation's type. */ |
/* Fix the relocation's type. */ |
1206 |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
1207 |
R_H8_DIR16A8); |
R_H8_DIR16); |
1208 |
|
|
1209 |
/* Delete two bytes of data. */ |
/* Delete two bytes of data. */ |
1210 |
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
if (!elf32_h8_relax_delete_bytes (abfd, sec, |
1211 |
irel->r_offset + 1, 2)) |
irel->r_offset + 1, 2)) |
1212 |
goto error_return; |
goto error_return; |
1213 |
|
|
1214 |
/* That will change things, so, we should relax again. |
/* That will change things, so, we should relax again. |
1215 |
Note that this is not required, and it may be slow. */ |
Note that this is not required, and it may be slow. */ |
1216 |
*again = true; |
*again = TRUE; |
1217 |
} |
} |
1218 |
break; |
break; |
1219 |
} |
} |
1248 |
&& elf_section_data (sec)->relocs != internal_relocs) |
&& elf_section_data (sec)->relocs != internal_relocs) |
1249 |
free (internal_relocs); |
free (internal_relocs); |
1250 |
|
|
1251 |
return true; |
return TRUE; |
1252 |
|
|
1253 |
error_return: |
error_return: |
1254 |
if (isymbuf != NULL |
if (isymbuf != NULL |
1260 |
if (internal_relocs != NULL |
if (internal_relocs != NULL |
1261 |
&& elf_section_data (sec)->relocs != internal_relocs) |
&& elf_section_data (sec)->relocs != internal_relocs) |
1262 |
free (internal_relocs); |
free (internal_relocs); |
1263 |
return false; |
return FALSE; |
1264 |
} |
} |
1265 |
|
|
1266 |
/* Delete some bytes from a section while relaxing. */ |
/* Delete some bytes from a section while relaxing. */ |
1267 |
|
|
1268 |
static boolean |
static bfd_boolean |
1269 |
elf32_h8_relax_delete_bytes (abfd, sec, addr, count) |
elf32_h8_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, int count) |
|
bfd *abfd; |
|
|
asection *sec; |
|
|
bfd_vma addr; |
|
|
int count; |
|
1270 |
{ |
{ |
1271 |
Elf_Internal_Shdr *symtab_hdr; |
Elf_Internal_Shdr *symtab_hdr; |
1272 |
unsigned int sec_shndx; |
unsigned int sec_shndx; |
1288 |
power larger than the number of bytes we are deleting. */ |
power larger than the number of bytes we are deleting. */ |
1289 |
|
|
1290 |
irelalign = NULL; |
irelalign = NULL; |
1291 |
toaddr = sec->_cooked_size; |
toaddr = sec->size; |
1292 |
|
|
1293 |
irel = elf_section_data (sec)->relocs; |
irel = elf_section_data (sec)->relocs; |
1294 |
irelend = irel + sec->reloc_count; |
irelend = irel + sec->reloc_count; |
1296 |
/* Actually delete the bytes. */ |
/* Actually delete the bytes. */ |
1297 |
memmove (contents + addr, contents + addr + count, |
memmove (contents + addr, contents + addr + count, |
1298 |
(size_t) (toaddr - addr - count)); |
(size_t) (toaddr - addr - count)); |
1299 |
sec->_cooked_size -= count; |
sec->size -= count; |
1300 |
|
|
1301 |
/* Adjust all the relocs. */ |
/* Adjust all the relocs. */ |
1302 |
for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) |
for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) |
1337 |
} |
} |
1338 |
} |
} |
1339 |
|
|
1340 |
return true; |
return TRUE; |
1341 |
} |
} |
1342 |
|
|
1343 |
/* Return true if a symbol exists at the given address, else return |
/* Return TRUE if a symbol exists at the given address, else return |
1344 |
false. */ |
FALSE. */ |
1345 |
static boolean |
static bfd_boolean |
1346 |
elf32_h8_symbol_address_p (abfd, sec, addr) |
elf32_h8_symbol_address_p (bfd *abfd, asection *sec, bfd_vma addr) |
|
bfd *abfd; |
|
|
asection *sec; |
|
|
bfd_vma addr; |
|
1347 |
{ |
{ |
1348 |
Elf_Internal_Shdr *symtab_hdr; |
Elf_Internal_Shdr *symtab_hdr; |
1349 |
unsigned int sec_shndx; |
unsigned int sec_shndx; |
1363 |
{ |
{ |
1364 |
if (isym->st_shndx == sec_shndx |
if (isym->st_shndx == sec_shndx |
1365 |
&& isym->st_value == addr) |
&& isym->st_value == addr) |
1366 |
return true; |
return TRUE; |
1367 |
} |
} |
1368 |
|
|
1369 |
symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) |
symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) |
1377 |
|| sym_hash->root.type == bfd_link_hash_defweak) |
|| sym_hash->root.type == bfd_link_hash_defweak) |
1378 |
&& sym_hash->root.u.def.section == sec |
&& sym_hash->root.u.def.section == sec |
1379 |
&& sym_hash->root.u.def.value == addr) |
&& sym_hash->root.u.def.value == addr) |
1380 |
return true; |
return TRUE; |
1381 |
} |
} |
1382 |
|
|
1383 |
return false; |
return FALSE; |
1384 |
} |
} |
1385 |
|
|
1386 |
/* This is a version of bfd_generic_get_relocated_section_contents |
/* This is a version of bfd_generic_get_relocated_section_contents |
1387 |
which uses elf32_h8_relocate_section. */ |
which uses elf32_h8_relocate_section. */ |
1388 |
|
|
1389 |
static bfd_byte * |
static bfd_byte * |
1390 |
elf32_h8_get_relocated_section_contents (output_bfd, link_info, link_order, |
elf32_h8_get_relocated_section_contents (bfd *output_bfd, |
1391 |
data, relocateable, symbols) |
struct bfd_link_info *link_info, |
1392 |
bfd *output_bfd; |
struct bfd_link_order *link_order, |
1393 |
struct bfd_link_info *link_info; |
bfd_byte *data, |
1394 |
struct bfd_link_order *link_order; |
bfd_boolean relocatable, |
1395 |
bfd_byte *data; |
asymbol **symbols) |
|
boolean relocateable; |
|
|
asymbol **symbols; |
|
1396 |
{ |
{ |
1397 |
Elf_Internal_Shdr *symtab_hdr; |
Elf_Internal_Shdr *symtab_hdr; |
1398 |
asection *input_section = link_order->u.indirect.section; |
asection *input_section = link_order->u.indirect.section; |
1403 |
|
|
1404 |
/* We only need to handle the case of relaxing, or of having a |
/* We only need to handle the case of relaxing, or of having a |
1405 |
particular set of section contents, specially. */ |
particular set of section contents, specially. */ |
1406 |
if (relocateable |
if (relocatable |
1407 |
|| elf_section_data (input_section)->this_hdr.contents == NULL) |
|| elf_section_data (input_section)->this_hdr.contents == NULL) |
1408 |
return bfd_generic_get_relocated_section_contents (output_bfd, link_info, |
return bfd_generic_get_relocated_section_contents (output_bfd, link_info, |
1409 |
link_order, data, |
link_order, data, |
1410 |
relocateable, |
relocatable, |
1411 |
symbols); |
symbols); |
1412 |
|
|
1413 |
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
1414 |
|
|
1415 |
memcpy (data, elf_section_data (input_section)->this_hdr.contents, |
memcpy (data, elf_section_data (input_section)->this_hdr.contents, |
1416 |
(size_t) input_section->_raw_size); |
(size_t) input_section->size); |
1417 |
|
|
1418 |
if ((input_section->flags & SEC_RELOC) != 0 |
if ((input_section->flags & SEC_RELOC) != 0 |
1419 |
&& input_section->reloc_count > 0) |
&& input_section->reloc_count > 0) |
1422 |
Elf_Internal_Sym *isym, *isymend; |
Elf_Internal_Sym *isym, *isymend; |
1423 |
bfd_size_type amt; |
bfd_size_type amt; |
1424 |
|
|
1425 |
internal_relocs = (_bfd_elf32_link_read_relocs |
internal_relocs = (_bfd_elf_link_read_relocs |
1426 |
(input_bfd, input_section, (PTR) NULL, |
(input_bfd, input_section, (PTR) NULL, |
1427 |
(Elf_Internal_Rela *) NULL, false)); |
(Elf_Internal_Rela *) NULL, FALSE)); |
1428 |
if (internal_relocs == NULL) |
if (internal_relocs == NULL) |
1429 |
goto error_return; |
goto error_return; |
1430 |
|
|
1490 |
return NULL; |
return NULL; |
1491 |
} |
} |
1492 |
|
|
1493 |
|
static asection * |
1494 |
|
elf32_h8_gc_mark_hook (asection *sec, |
1495 |
|
struct bfd_link_info *info ATTRIBUTE_UNUSED, |
1496 |
|
Elf_Internal_Rela *rel ATTRIBUTE_UNUSED, |
1497 |
|
struct elf_link_hash_entry *h, |
1498 |
|
Elf_Internal_Sym *sym) |
1499 |
|
{ |
1500 |
|
if (h != NULL) |
1501 |
|
{ |
1502 |
|
switch (h->root.type) |
1503 |
|
{ |
1504 |
|
case bfd_link_hash_defined: |
1505 |
|
case bfd_link_hash_defweak: |
1506 |
|
return h->root.u.def.section; |
1507 |
|
|
1508 |
|
case bfd_link_hash_common: |
1509 |
|
return h->root.u.c.p->section; |
1510 |
|
|
1511 |
|
default: |
1512 |
|
break; |
1513 |
|
} |
1514 |
|
} |
1515 |
|
else |
1516 |
|
return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
1517 |
|
return NULL; |
1518 |
|
} |
1519 |
|
|
1520 |
|
static bfd_boolean |
1521 |
|
elf32_h8_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED, |
1522 |
|
struct bfd_link_info *info ATTRIBUTE_UNUSED, |
1523 |
|
asection *sec ATTRIBUTE_UNUSED, |
1524 |
|
const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED) |
1525 |
|
{ |
1526 |
|
return TRUE; |
1527 |
|
} |
1528 |
|
|
1529 |
|
|
1530 |
#define TARGET_BIG_SYM bfd_elf32_h8300_vec |
#define TARGET_BIG_SYM bfd_elf32_h8300_vec |
1531 |
#define TARGET_BIG_NAME "elf32-h8300" |
#define TARGET_BIG_NAME "elf32-h8300" |
1544 |
elf32_h8_object_p |
elf32_h8_object_p |
1545 |
#define bfd_elf32_bfd_merge_private_bfd_data \ |
#define bfd_elf32_bfd_merge_private_bfd_data \ |
1546 |
elf32_h8_merge_private_bfd_data |
elf32_h8_merge_private_bfd_data |
1547 |
|
#define elf_backend_gc_mark_hook elf32_h8_gc_mark_hook |
1548 |
|
#define elf_backend_gc_sweep_hook elf32_h8_gc_sweep_hook |
1549 |
|
|
1550 |
/* ??? when elf_backend_relocate_section is not defined, elf32-target.h |
/* ??? when elf_backend_relocate_section is not defined, elf32-target.h |
1551 |
defaults to using _bfd_generic_link_hash_table_create, but |
defaults to using _bfd_generic_link_hash_table_create, but |
1552 |
elflink.h:bfd_elf32_size_dynamic_sections uses |
bfd_elf_size_dynamic_sections uses |
1553 |
dynobj = elf_hash_table (info)->dynobj; |
dynobj = elf_hash_table (info)->dynobj; |
1554 |
and thus requires an elf hash table. */ |
and thus requires an elf hash table. */ |
1555 |
#define bfd_elf32_bfd_link_hash_table_create _bfd_elf_link_hash_table_create |
#define bfd_elf32_bfd_link_hash_table_create _bfd_elf_link_hash_table_create |
1556 |
|
|
1557 |
/* Use an H8 specific linker, not the ELF generic linker. */ |
/* Use an H8 specific linker, not the ELF generic linker. */ |
1558 |
#define elf_backend_relocate_section elf32_h8_relocate_section |
#define elf_backend_relocate_section elf32_h8_relocate_section |
1559 |
|
#define elf_backend_rela_normal 1 |
1560 |
|
#define elf_backend_can_gc_sections 1 |
1561 |
|
|
1562 |
/* And relaxing stuff. */ |
/* And relaxing stuff. */ |
1563 |
#define bfd_elf32_bfd_relax_section elf32_h8_relax_section |
#define bfd_elf32_bfd_relax_section elf32_h8_relax_section |