elf32-m68k.c revision 1.1.1.2 1 1.1 skrll /* Motorola 68k series support for 32-bit ELF
2 1.1 skrll Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 1.1.1.2 christos 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 1.1 skrll
5 1.1 skrll This file is part of BFD, the Binary File Descriptor library.
6 1.1 skrll
7 1.1 skrll This program is free software; you can redistribute it and/or modify
8 1.1 skrll it under the terms of the GNU General Public License as published by
9 1.1 skrll the Free Software Foundation; either version 3 of the License, or
10 1.1 skrll (at your option) any later version.
11 1.1 skrll
12 1.1 skrll This program is distributed in the hope that it will be useful,
13 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 skrll GNU General Public License for more details.
16 1.1 skrll
17 1.1 skrll You should have received a copy of the GNU General Public License
18 1.1 skrll along with this program; if not, write to the Free Software
19 1.1 skrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 1.1 skrll MA 02110-1301, USA. */
21 1.1 skrll
22 1.1 skrll #include "sysdep.h"
23 1.1 skrll #include "bfd.h"
24 1.1 skrll #include "bfdlink.h"
25 1.1 skrll #include "libbfd.h"
26 1.1 skrll #include "elf-bfd.h"
27 1.1 skrll #include "elf/m68k.h"
28 1.1 skrll #include "opcode/m68k.h"
29 1.1 skrll
30 1.1 skrll static reloc_howto_type *reloc_type_lookup
31 1.1 skrll PARAMS ((bfd *, bfd_reloc_code_real_type));
32 1.1 skrll static void rtype_to_howto
33 1.1 skrll PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
34 1.1 skrll static struct bfd_hash_entry *elf_m68k_link_hash_newfunc
35 1.1 skrll PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
36 1.1 skrll static struct bfd_link_hash_table *elf_m68k_link_hash_table_create
37 1.1 skrll PARAMS ((bfd *));
38 1.1 skrll static bfd_boolean elf_m68k_check_relocs
39 1.1 skrll PARAMS ((bfd *, struct bfd_link_info *, asection *,
40 1.1 skrll const Elf_Internal_Rela *));
41 1.1 skrll static bfd_boolean elf_m68k_adjust_dynamic_symbol
42 1.1 skrll PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
43 1.1 skrll static bfd_boolean elf_m68k_size_dynamic_sections
44 1.1 skrll PARAMS ((bfd *, struct bfd_link_info *));
45 1.1 skrll static bfd_boolean elf_m68k_discard_copies
46 1.1 skrll PARAMS ((struct elf_link_hash_entry *, PTR));
47 1.1 skrll static bfd_boolean elf_m68k_relocate_section
48 1.1 skrll PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
49 1.1 skrll Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
50 1.1 skrll static bfd_boolean elf_m68k_finish_dynamic_symbol
51 1.1 skrll PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
52 1.1 skrll Elf_Internal_Sym *));
53 1.1 skrll static bfd_boolean elf_m68k_finish_dynamic_sections
54 1.1 skrll PARAMS ((bfd *, struct bfd_link_info *));
55 1.1 skrll
56 1.1 skrll static bfd_boolean elf32_m68k_set_private_flags
57 1.1 skrll PARAMS ((bfd *, flagword));
58 1.1 skrll static bfd_boolean elf32_m68k_merge_private_bfd_data
59 1.1 skrll PARAMS ((bfd *, bfd *));
60 1.1 skrll static bfd_boolean elf32_m68k_print_private_bfd_data
61 1.1 skrll PARAMS ((bfd *, PTR));
62 1.1 skrll static enum elf_reloc_type_class elf32_m68k_reloc_type_class
63 1.1 skrll PARAMS ((const Elf_Internal_Rela *));
64 1.1 skrll
65 1.1 skrll static reloc_howto_type howto_table[] = {
66 1.1 skrll HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE),
67 1.1 skrll HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE),
68 1.1 skrll HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE),
69 1.1 skrll HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE),
70 1.1 skrll HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE),
71 1.1 skrll HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE),
72 1.1 skrll HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE),
73 1.1 skrll HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE),
74 1.1 skrll HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE),
75 1.1 skrll HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE),
76 1.1 skrll HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE),
77 1.1 skrll HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE),
78 1.1 skrll HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE),
79 1.1 skrll HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE),
80 1.1 skrll HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE),
81 1.1 skrll HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE),
82 1.1 skrll HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE),
83 1.1 skrll HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE),
84 1.1 skrll HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE),
85 1.1 skrll HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE),
86 1.1 skrll HOWTO(R_68K_GLOB_DAT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", FALSE, 0, 0xffffffff,FALSE),
87 1.1 skrll HOWTO(R_68K_JMP_SLOT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", FALSE, 0, 0xffffffff,FALSE),
88 1.1 skrll HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE),
89 1.1 skrll /* GNU extension to record C++ vtable hierarchy. */
90 1.1 skrll HOWTO (R_68K_GNU_VTINHERIT, /* type */
91 1.1 skrll 0, /* rightshift */
92 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
93 1.1 skrll 0, /* bitsize */
94 1.1 skrll FALSE, /* pc_relative */
95 1.1 skrll 0, /* bitpos */
96 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
97 1.1 skrll NULL, /* special_function */
98 1.1 skrll "R_68K_GNU_VTINHERIT", /* name */
99 1.1 skrll FALSE, /* partial_inplace */
100 1.1 skrll 0, /* src_mask */
101 1.1 skrll 0, /* dst_mask */
102 1.1 skrll FALSE),
103 1.1 skrll /* GNU extension to record C++ vtable member usage. */
104 1.1 skrll HOWTO (R_68K_GNU_VTENTRY, /* type */
105 1.1 skrll 0, /* rightshift */
106 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
107 1.1 skrll 0, /* bitsize */
108 1.1 skrll FALSE, /* pc_relative */
109 1.1 skrll 0, /* bitpos */
110 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
111 1.1 skrll _bfd_elf_rel_vtable_reloc_fn, /* special_function */
112 1.1 skrll "R_68K_GNU_VTENTRY", /* name */
113 1.1 skrll FALSE, /* partial_inplace */
114 1.1 skrll 0, /* src_mask */
115 1.1 skrll 0, /* dst_mask */
116 1.1 skrll FALSE),
117 1.1.1.2 christos
118 1.1.1.2 christos /* TLS general dynamic variable reference. */
119 1.1.1.2 christos HOWTO (R_68K_TLS_GD32, /* type */
120 1.1.1.2 christos 0, /* rightshift */
121 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
122 1.1.1.2 christos 32, /* bitsize */
123 1.1.1.2 christos FALSE, /* pc_relative */
124 1.1.1.2 christos 0, /* bitpos */
125 1.1.1.2 christos complain_overflow_bitfield, /* complain_on_overflow */
126 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
127 1.1.1.2 christos "R_68K_TLS_GD32", /* name */
128 1.1.1.2 christos FALSE, /* partial_inplace */
129 1.1.1.2 christos 0, /* src_mask */
130 1.1.1.2 christos 0xffffffff, /* dst_mask */
131 1.1.1.2 christos FALSE), /* pcrel_offset */
132 1.1.1.2 christos
133 1.1.1.2 christos HOWTO (R_68K_TLS_GD16, /* type */
134 1.1.1.2 christos 0, /* rightshift */
135 1.1.1.2 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
136 1.1.1.2 christos 16, /* bitsize */
137 1.1.1.2 christos FALSE, /* pc_relative */
138 1.1.1.2 christos 0, /* bitpos */
139 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
140 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
141 1.1.1.2 christos "R_68K_TLS_GD16", /* name */
142 1.1.1.2 christos FALSE, /* partial_inplace */
143 1.1.1.2 christos 0, /* src_mask */
144 1.1.1.2 christos 0x0000ffff, /* dst_mask */
145 1.1.1.2 christos FALSE), /* pcrel_offset */
146 1.1.1.2 christos
147 1.1.1.2 christos HOWTO (R_68K_TLS_GD8, /* type */
148 1.1.1.2 christos 0, /* rightshift */
149 1.1.1.2 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
150 1.1.1.2 christos 8, /* bitsize */
151 1.1.1.2 christos FALSE, /* pc_relative */
152 1.1.1.2 christos 0, /* bitpos */
153 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
154 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
155 1.1.1.2 christos "R_68K_TLS_GD8", /* name */
156 1.1.1.2 christos FALSE, /* partial_inplace */
157 1.1.1.2 christos 0, /* src_mask */
158 1.1.1.2 christos 0x000000ff, /* dst_mask */
159 1.1.1.2 christos FALSE), /* pcrel_offset */
160 1.1.1.2 christos
161 1.1.1.2 christos /* TLS local dynamic variable reference. */
162 1.1.1.2 christos HOWTO (R_68K_TLS_LDM32, /* type */
163 1.1.1.2 christos 0, /* rightshift */
164 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
165 1.1.1.2 christos 32, /* bitsize */
166 1.1.1.2 christos FALSE, /* pc_relative */
167 1.1.1.2 christos 0, /* bitpos */
168 1.1.1.2 christos complain_overflow_bitfield, /* complain_on_overflow */
169 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
170 1.1.1.2 christos "R_68K_TLS_LDM32", /* name */
171 1.1.1.2 christos FALSE, /* partial_inplace */
172 1.1.1.2 christos 0, /* src_mask */
173 1.1.1.2 christos 0xffffffff, /* dst_mask */
174 1.1.1.2 christos FALSE), /* pcrel_offset */
175 1.1.1.2 christos
176 1.1.1.2 christos HOWTO (R_68K_TLS_LDM16, /* type */
177 1.1.1.2 christos 0, /* rightshift */
178 1.1.1.2 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
179 1.1.1.2 christos 16, /* bitsize */
180 1.1.1.2 christos FALSE, /* pc_relative */
181 1.1.1.2 christos 0, /* bitpos */
182 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
183 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
184 1.1.1.2 christos "R_68K_TLS_LDM16", /* name */
185 1.1.1.2 christos FALSE, /* partial_inplace */
186 1.1.1.2 christos 0, /* src_mask */
187 1.1.1.2 christos 0x0000ffff, /* dst_mask */
188 1.1.1.2 christos FALSE), /* pcrel_offset */
189 1.1.1.2 christos
190 1.1.1.2 christos HOWTO (R_68K_TLS_LDM8, /* type */
191 1.1.1.2 christos 0, /* rightshift */
192 1.1.1.2 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
193 1.1.1.2 christos 8, /* bitsize */
194 1.1.1.2 christos FALSE, /* pc_relative */
195 1.1.1.2 christos 0, /* bitpos */
196 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
197 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
198 1.1.1.2 christos "R_68K_TLS_LDM8", /* name */
199 1.1.1.2 christos FALSE, /* partial_inplace */
200 1.1.1.2 christos 0, /* src_mask */
201 1.1.1.2 christos 0x000000ff, /* dst_mask */
202 1.1.1.2 christos FALSE), /* pcrel_offset */
203 1.1.1.2 christos
204 1.1.1.2 christos HOWTO (R_68K_TLS_LDO32, /* type */
205 1.1.1.2 christos 0, /* rightshift */
206 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
207 1.1.1.2 christos 32, /* bitsize */
208 1.1.1.2 christos FALSE, /* pc_relative */
209 1.1.1.2 christos 0, /* bitpos */
210 1.1.1.2 christos complain_overflow_bitfield, /* complain_on_overflow */
211 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
212 1.1.1.2 christos "R_68K_TLS_LDO32", /* name */
213 1.1.1.2 christos FALSE, /* partial_inplace */
214 1.1.1.2 christos 0, /* src_mask */
215 1.1.1.2 christos 0xffffffff, /* dst_mask */
216 1.1.1.2 christos FALSE), /* pcrel_offset */
217 1.1.1.2 christos
218 1.1.1.2 christos HOWTO (R_68K_TLS_LDO16, /* type */
219 1.1.1.2 christos 0, /* rightshift */
220 1.1.1.2 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
221 1.1.1.2 christos 16, /* bitsize */
222 1.1.1.2 christos FALSE, /* pc_relative */
223 1.1.1.2 christos 0, /* bitpos */
224 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
225 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
226 1.1.1.2 christos "R_68K_TLS_LDO16", /* name */
227 1.1.1.2 christos FALSE, /* partial_inplace */
228 1.1.1.2 christos 0, /* src_mask */
229 1.1.1.2 christos 0x0000ffff, /* dst_mask */
230 1.1.1.2 christos FALSE), /* pcrel_offset */
231 1.1.1.2 christos
232 1.1.1.2 christos HOWTO (R_68K_TLS_LDO8, /* type */
233 1.1.1.2 christos 0, /* rightshift */
234 1.1.1.2 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
235 1.1.1.2 christos 8, /* bitsize */
236 1.1.1.2 christos FALSE, /* pc_relative */
237 1.1.1.2 christos 0, /* bitpos */
238 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
239 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
240 1.1.1.2 christos "R_68K_TLS_LDO8", /* name */
241 1.1.1.2 christos FALSE, /* partial_inplace */
242 1.1.1.2 christos 0, /* src_mask */
243 1.1.1.2 christos 0x000000ff, /* dst_mask */
244 1.1.1.2 christos FALSE), /* pcrel_offset */
245 1.1.1.2 christos
246 1.1.1.2 christos /* TLS initial execution variable reference. */
247 1.1.1.2 christos HOWTO (R_68K_TLS_IE32, /* type */
248 1.1.1.2 christos 0, /* rightshift */
249 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
250 1.1.1.2 christos 32, /* bitsize */
251 1.1.1.2 christos FALSE, /* pc_relative */
252 1.1.1.2 christos 0, /* bitpos */
253 1.1.1.2 christos complain_overflow_bitfield, /* complain_on_overflow */
254 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
255 1.1.1.2 christos "R_68K_TLS_IE32", /* name */
256 1.1.1.2 christos FALSE, /* partial_inplace */
257 1.1.1.2 christos 0, /* src_mask */
258 1.1.1.2 christos 0xffffffff, /* dst_mask */
259 1.1.1.2 christos FALSE), /* pcrel_offset */
260 1.1.1.2 christos
261 1.1.1.2 christos HOWTO (R_68K_TLS_IE16, /* type */
262 1.1.1.2 christos 0, /* rightshift */
263 1.1.1.2 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
264 1.1.1.2 christos 16, /* bitsize */
265 1.1.1.2 christos FALSE, /* pc_relative */
266 1.1.1.2 christos 0, /* bitpos */
267 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
268 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
269 1.1.1.2 christos "R_68K_TLS_IE16", /* name */
270 1.1.1.2 christos FALSE, /* partial_inplace */
271 1.1.1.2 christos 0, /* src_mask */
272 1.1.1.2 christos 0x0000ffff, /* dst_mask */
273 1.1.1.2 christos FALSE), /* pcrel_offset */
274 1.1.1.2 christos
275 1.1.1.2 christos HOWTO (R_68K_TLS_IE8, /* type */
276 1.1.1.2 christos 0, /* rightshift */
277 1.1.1.2 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
278 1.1.1.2 christos 8, /* bitsize */
279 1.1.1.2 christos FALSE, /* pc_relative */
280 1.1.1.2 christos 0, /* bitpos */
281 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
282 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
283 1.1.1.2 christos "R_68K_TLS_IE8", /* name */
284 1.1.1.2 christos FALSE, /* partial_inplace */
285 1.1.1.2 christos 0, /* src_mask */
286 1.1.1.2 christos 0x000000ff, /* dst_mask */
287 1.1.1.2 christos FALSE), /* pcrel_offset */
288 1.1.1.2 christos
289 1.1.1.2 christos /* TLS local execution variable reference. */
290 1.1.1.2 christos HOWTO (R_68K_TLS_LE32, /* type */
291 1.1.1.2 christos 0, /* rightshift */
292 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
293 1.1.1.2 christos 32, /* bitsize */
294 1.1.1.2 christos FALSE, /* pc_relative */
295 1.1.1.2 christos 0, /* bitpos */
296 1.1.1.2 christos complain_overflow_bitfield, /* complain_on_overflow */
297 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
298 1.1.1.2 christos "R_68K_TLS_LE32", /* name */
299 1.1.1.2 christos FALSE, /* partial_inplace */
300 1.1.1.2 christos 0, /* src_mask */
301 1.1.1.2 christos 0xffffffff, /* dst_mask */
302 1.1.1.2 christos FALSE), /* pcrel_offset */
303 1.1.1.2 christos
304 1.1.1.2 christos HOWTO (R_68K_TLS_LE16, /* type */
305 1.1.1.2 christos 0, /* rightshift */
306 1.1.1.2 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
307 1.1.1.2 christos 16, /* bitsize */
308 1.1.1.2 christos FALSE, /* pc_relative */
309 1.1.1.2 christos 0, /* bitpos */
310 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
311 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
312 1.1.1.2 christos "R_68K_TLS_LE16", /* name */
313 1.1.1.2 christos FALSE, /* partial_inplace */
314 1.1.1.2 christos 0, /* src_mask */
315 1.1.1.2 christos 0x0000ffff, /* dst_mask */
316 1.1.1.2 christos FALSE), /* pcrel_offset */
317 1.1.1.2 christos
318 1.1.1.2 christos HOWTO (R_68K_TLS_LE8, /* type */
319 1.1.1.2 christos 0, /* rightshift */
320 1.1.1.2 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
321 1.1.1.2 christos 8, /* bitsize */
322 1.1.1.2 christos FALSE, /* pc_relative */
323 1.1.1.2 christos 0, /* bitpos */
324 1.1.1.2 christos complain_overflow_signed, /* complain_on_overflow */
325 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
326 1.1.1.2 christos "R_68K_TLS_LE8", /* name */
327 1.1.1.2 christos FALSE, /* partial_inplace */
328 1.1.1.2 christos 0, /* src_mask */
329 1.1.1.2 christos 0x000000ff, /* dst_mask */
330 1.1.1.2 christos FALSE), /* pcrel_offset */
331 1.1.1.2 christos
332 1.1.1.2 christos /* TLS GD/LD dynamic relocations. */
333 1.1.1.2 christos HOWTO (R_68K_TLS_DTPMOD32, /* type */
334 1.1.1.2 christos 0, /* rightshift */
335 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
336 1.1.1.2 christos 32, /* bitsize */
337 1.1.1.2 christos FALSE, /* pc_relative */
338 1.1.1.2 christos 0, /* bitpos */
339 1.1.1.2 christos complain_overflow_dont, /* complain_on_overflow */
340 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
341 1.1.1.2 christos "R_68K_TLS_DTPMOD32", /* name */
342 1.1.1.2 christos FALSE, /* partial_inplace */
343 1.1.1.2 christos 0, /* src_mask */
344 1.1.1.2 christos 0xffffffff, /* dst_mask */
345 1.1.1.2 christos FALSE), /* pcrel_offset */
346 1.1.1.2 christos
347 1.1.1.2 christos HOWTO (R_68K_TLS_DTPREL32, /* type */
348 1.1.1.2 christos 0, /* rightshift */
349 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
350 1.1.1.2 christos 32, /* bitsize */
351 1.1.1.2 christos FALSE, /* pc_relative */
352 1.1.1.2 christos 0, /* bitpos */
353 1.1.1.2 christos complain_overflow_dont, /* complain_on_overflow */
354 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
355 1.1.1.2 christos "R_68K_TLS_DTPREL32", /* name */
356 1.1.1.2 christos FALSE, /* partial_inplace */
357 1.1.1.2 christos 0, /* src_mask */
358 1.1.1.2 christos 0xffffffff, /* dst_mask */
359 1.1.1.2 christos FALSE), /* pcrel_offset */
360 1.1.1.2 christos
361 1.1.1.2 christos HOWTO (R_68K_TLS_TPREL32, /* type */
362 1.1.1.2 christos 0, /* rightshift */
363 1.1.1.2 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
364 1.1.1.2 christos 32, /* bitsize */
365 1.1.1.2 christos FALSE, /* pc_relative */
366 1.1.1.2 christos 0, /* bitpos */
367 1.1.1.2 christos complain_overflow_dont, /* complain_on_overflow */
368 1.1.1.2 christos bfd_elf_generic_reloc, /* special_function */
369 1.1.1.2 christos "R_68K_TLS_TPREL32", /* name */
370 1.1.1.2 christos FALSE, /* partial_inplace */
371 1.1.1.2 christos 0, /* src_mask */
372 1.1.1.2 christos 0xffffffff, /* dst_mask */
373 1.1.1.2 christos FALSE), /* pcrel_offset */
374 1.1 skrll };
375 1.1 skrll
376 1.1 skrll static void
377 1.1.1.2 christos rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
378 1.1 skrll {
379 1.1.1.2 christos unsigned int indx = ELF32_R_TYPE (dst->r_info);
380 1.1.1.2 christos
381 1.1.1.2 christos if (indx >= (unsigned int) R_68K_max)
382 1.1.1.2 christos {
383 1.1.1.2 christos (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
384 1.1.1.2 christos abfd, (int) indx);
385 1.1.1.2 christos indx = R_68K_NONE;
386 1.1.1.2 christos }
387 1.1.1.2 christos cache_ptr->howto = &howto_table[indx];
388 1.1 skrll }
389 1.1 skrll
390 1.1 skrll #define elf_info_to_howto rtype_to_howto
391 1.1 skrll
392 1.1 skrll static const struct
393 1.1 skrll {
394 1.1 skrll bfd_reloc_code_real_type bfd_val;
395 1.1 skrll int elf_val;
396 1.1.1.2 christos }
397 1.1.1.2 christos reloc_map[] =
398 1.1.1.2 christos {
399 1.1 skrll { BFD_RELOC_NONE, R_68K_NONE },
400 1.1 skrll { BFD_RELOC_32, R_68K_32 },
401 1.1 skrll { BFD_RELOC_16, R_68K_16 },
402 1.1 skrll { BFD_RELOC_8, R_68K_8 },
403 1.1 skrll { BFD_RELOC_32_PCREL, R_68K_PC32 },
404 1.1 skrll { BFD_RELOC_16_PCREL, R_68K_PC16 },
405 1.1 skrll { BFD_RELOC_8_PCREL, R_68K_PC8 },
406 1.1 skrll { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
407 1.1 skrll { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
408 1.1 skrll { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
409 1.1 skrll { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
410 1.1 skrll { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
411 1.1 skrll { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
412 1.1 skrll { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
413 1.1 skrll { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
414 1.1 skrll { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
415 1.1 skrll { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
416 1.1 skrll { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
417 1.1 skrll { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
418 1.1 skrll { BFD_RELOC_NONE, R_68K_COPY },
419 1.1 skrll { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
420 1.1 skrll { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
421 1.1 skrll { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
422 1.1 skrll { BFD_RELOC_CTOR, R_68K_32 },
423 1.1 skrll { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
424 1.1 skrll { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
425 1.1.1.2 christos { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 },
426 1.1.1.2 christos { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 },
427 1.1.1.2 christos { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 },
428 1.1.1.2 christos { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 },
429 1.1.1.2 christos { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 },
430 1.1.1.2 christos { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 },
431 1.1.1.2 christos { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 },
432 1.1.1.2 christos { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 },
433 1.1.1.2 christos { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 },
434 1.1.1.2 christos { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 },
435 1.1.1.2 christos { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 },
436 1.1.1.2 christos { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 },
437 1.1.1.2 christos { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 },
438 1.1.1.2 christos { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 },
439 1.1.1.2 christos { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 },
440 1.1 skrll };
441 1.1 skrll
442 1.1 skrll static reloc_howto_type *
443 1.1 skrll reloc_type_lookup (abfd, code)
444 1.1 skrll bfd *abfd ATTRIBUTE_UNUSED;
445 1.1 skrll bfd_reloc_code_real_type code;
446 1.1 skrll {
447 1.1 skrll unsigned int i;
448 1.1 skrll for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
449 1.1 skrll {
450 1.1 skrll if (reloc_map[i].bfd_val == code)
451 1.1 skrll return &howto_table[reloc_map[i].elf_val];
452 1.1 skrll }
453 1.1 skrll return 0;
454 1.1 skrll }
455 1.1 skrll
456 1.1 skrll static reloc_howto_type *
457 1.1 skrll reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
458 1.1 skrll {
459 1.1 skrll unsigned int i;
460 1.1 skrll
461 1.1 skrll for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
462 1.1 skrll if (howto_table[i].name != NULL
463 1.1 skrll && strcasecmp (howto_table[i].name, r_name) == 0)
464 1.1 skrll return &howto_table[i];
465 1.1 skrll
466 1.1 skrll return NULL;
467 1.1 skrll }
468 1.1 skrll
469 1.1 skrll #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
470 1.1 skrll #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
471 1.1 skrll #define ELF_ARCH bfd_arch_m68k
472 1.1.1.2 christos #define ELF_TARGET_ID M68K_ELF_DATA
473 1.1 skrll
474 1.1 skrll /* Functions for the m68k ELF linker. */
476 1.1 skrll
477 1.1 skrll /* The name of the dynamic interpreter. This is put in the .interp
478 1.1 skrll section. */
479 1.1 skrll
480 1.1 skrll #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
481 1.1 skrll
482 1.1 skrll /* Describes one of the various PLT styles. */
483 1.1 skrll
484 1.1 skrll struct elf_m68k_plt_info
485 1.1 skrll {
486 1.1 skrll /* The size of each PLT entry. */
487 1.1 skrll bfd_vma size;
488 1.1 skrll
489 1.1 skrll /* The template for the first PLT entry. */
490 1.1 skrll const bfd_byte *plt0_entry;
491 1.1 skrll
492 1.1 skrll /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
493 1.1 skrll The comments by each member indicate the value that the relocation
494 1.1 skrll is against. */
495 1.1 skrll struct {
496 1.1 skrll unsigned int got4; /* .got + 4 */
497 1.1 skrll unsigned int got8; /* .got + 8 */
498 1.1 skrll } plt0_relocs;
499 1.1 skrll
500 1.1 skrll /* The template for a symbol's PLT entry. */
501 1.1 skrll const bfd_byte *symbol_entry;
502 1.1 skrll
503 1.1 skrll /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
504 1.1 skrll The comments by each member indicate the value that the relocation
505 1.1 skrll is against. */
506 1.1 skrll struct {
507 1.1 skrll unsigned int got; /* the symbol's .got.plt entry */
508 1.1 skrll unsigned int plt; /* .plt */
509 1.1 skrll } symbol_relocs;
510 1.1 skrll
511 1.1 skrll /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
512 1.1 skrll The stub starts with "move.l #relocoffset,%d0". */
513 1.1 skrll bfd_vma symbol_resolve_entry;
514 1.1 skrll };
515 1.1 skrll
516 1.1 skrll /* The size in bytes of an entry in the procedure linkage table. */
517 1.1 skrll
518 1.1 skrll #define PLT_ENTRY_SIZE 20
519 1.1 skrll
520 1.1 skrll /* The first entry in a procedure linkage table looks like this. See
521 1.1 skrll the SVR4 ABI m68k supplement to see how this works. */
522 1.1 skrll
523 1.1 skrll static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
524 1.1 skrll {
525 1.1 skrll 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
526 1.1 skrll 0, 0, 0, 2, /* + (.got + 4) - . */
527 1.1 skrll 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
528 1.1 skrll 0, 0, 0, 2, /* + (.got + 8) - . */
529 1.1 skrll 0, 0, 0, 0 /* pad out to 20 bytes. */
530 1.1 skrll };
531 1.1 skrll
532 1.1 skrll /* Subsequent entries in a procedure linkage table look like this. */
533 1.1 skrll
534 1.1 skrll static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
535 1.1 skrll {
536 1.1 skrll 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
537 1.1 skrll 0, 0, 0, 2, /* + (.got.plt entry) - . */
538 1.1 skrll 0x2f, 0x3c, /* move.l #offset,-(%sp) */
539 1.1 skrll 0, 0, 0, 0, /* + reloc index */
540 1.1 skrll 0x60, 0xff, /* bra.l .plt */
541 1.1 skrll 0, 0, 0, 0 /* + .plt - . */
542 1.1 skrll };
543 1.1 skrll
544 1.1 skrll static const struct elf_m68k_plt_info elf_m68k_plt_info = {
545 1.1 skrll PLT_ENTRY_SIZE,
546 1.1 skrll elf_m68k_plt0_entry, { 4, 12 },
547 1.1 skrll elf_m68k_plt_entry, { 4, 16 }, 8
548 1.1 skrll };
549 1.1 skrll
550 1.1 skrll #define ISAB_PLT_ENTRY_SIZE 24
551 1.1 skrll
552 1.1 skrll static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
553 1.1 skrll {
554 1.1 skrll 0x20, 0x3c, /* move.l #offset,%d0 */
555 1.1 skrll 0, 0, 0, 0, /* + (.got + 4) - . */
556 1.1 skrll 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
557 1.1 skrll 0x20, 0x3c, /* move.l #offset,%d0 */
558 1.1 skrll 0, 0, 0, 0, /* + (.got + 8) - . */
559 1.1 skrll 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
560 1.1 skrll 0x4e, 0xd0, /* jmp (%a0) */
561 1.1 skrll 0x4e, 0x71 /* nop */
562 1.1 skrll };
563 1.1 skrll
564 1.1 skrll /* Subsequent entries in a procedure linkage table look like this. */
565 1.1 skrll
566 1.1 skrll static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
567 1.1 skrll {
568 1.1 skrll 0x20, 0x3c, /* move.l #offset,%d0 */
569 1.1 skrll 0, 0, 0, 0, /* + (.got.plt entry) - . */
570 1.1 skrll 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
571 1.1 skrll 0x4e, 0xd0, /* jmp (%a0) */
572 1.1 skrll 0x2f, 0x3c, /* move.l #offset,-(%sp) */
573 1.1 skrll 0, 0, 0, 0, /* + reloc index */
574 1.1 skrll 0x60, 0xff, /* bra.l .plt */
575 1.1 skrll 0, 0, 0, 0 /* + .plt - . */
576 1.1 skrll };
577 1.1 skrll
578 1.1 skrll static const struct elf_m68k_plt_info elf_isab_plt_info = {
579 1.1 skrll ISAB_PLT_ENTRY_SIZE,
580 1.1 skrll elf_isab_plt0_entry, { 2, 12 },
581 1.1 skrll elf_isab_plt_entry, { 2, 20 }, 12
582 1.1 skrll };
583 1.1 skrll
584 1.1 skrll #define ISAC_PLT_ENTRY_SIZE 24
585 1.1 skrll
586 1.1 skrll static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
587 1.1 skrll {
588 1.1 skrll 0x20, 0x3c, /* move.l #offset,%d0 */
589 1.1 skrll 0, 0, 0, 0, /* replaced with .got + 4 - . */
590 1.1 skrll 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
591 1.1 skrll 0x20, 0x3c, /* move.l #offset,%d0 */
592 1.1 skrll 0, 0, 0, 0, /* replaced with .got + 8 - . */
593 1.1 skrll 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
594 1.1 skrll 0x4e, 0xd0, /* jmp (%a0) */
595 1.1 skrll 0x4e, 0x71 /* nop */
596 1.1 skrll };
597 1.1 skrll
598 1.1 skrll /* Subsequent entries in a procedure linkage table look like this. */
599 1.1 skrll
600 1.1 skrll static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
601 1.1 skrll {
602 1.1 skrll 0x20, 0x3c, /* move.l #offset,%d0 */
603 1.1 skrll 0, 0, 0, 0, /* replaced with (.got entry) - . */
604 1.1 skrll 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
605 1.1 skrll 0x4e, 0xd0, /* jmp (%a0) */
606 1.1 skrll 0x2f, 0x3c, /* move.l #offset,-(%sp) */
607 1.1 skrll 0, 0, 0, 0, /* replaced with offset into relocation table */
608 1.1 skrll 0x61, 0xff, /* bsr.l .plt */
609 1.1 skrll 0, 0, 0, 0 /* replaced with .plt - . */
610 1.1 skrll };
611 1.1 skrll
612 1.1 skrll static const struct elf_m68k_plt_info elf_isac_plt_info = {
613 1.1 skrll ISAC_PLT_ENTRY_SIZE,
614 1.1 skrll elf_isac_plt0_entry, { 2, 12},
615 1.1 skrll elf_isac_plt_entry, { 2, 20 }, 12
616 1.1 skrll };
617 1.1 skrll
618 1.1 skrll #define CPU32_PLT_ENTRY_SIZE 24
619 1.1 skrll /* Procedure linkage table entries for the cpu32 */
620 1.1 skrll static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
621 1.1 skrll {
622 1.1 skrll 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
623 1.1 skrll 0, 0, 0, 2, /* + (.got + 4) - . */
624 1.1 skrll 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
625 1.1 skrll 0, 0, 0, 2, /* + (.got + 8) - . */
626 1.1 skrll 0x4e, 0xd1, /* jmp %a1@ */
627 1.1 skrll 0, 0, 0, 0, /* pad out to 24 bytes. */
628 1.1 skrll 0, 0
629 1.1 skrll };
630 1.1 skrll
631 1.1 skrll static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
632 1.1 skrll {
633 1.1 skrll 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
634 1.1 skrll 0, 0, 0, 2, /* + (.got.plt entry) - . */
635 1.1 skrll 0x4e, 0xd1, /* jmp %a1@ */
636 1.1 skrll 0x2f, 0x3c, /* move.l #offset,-(%sp) */
637 1.1 skrll 0, 0, 0, 0, /* + reloc index */
638 1.1 skrll 0x60, 0xff, /* bra.l .plt */
639 1.1 skrll 0, 0, 0, 0, /* + .plt - . */
640 1.1 skrll 0, 0
641 1.1 skrll };
642 1.1 skrll
643 1.1 skrll static const struct elf_m68k_plt_info elf_cpu32_plt_info = {
644 1.1 skrll CPU32_PLT_ENTRY_SIZE,
645 1.1 skrll elf_cpu32_plt0_entry, { 4, 12 },
646 1.1 skrll elf_cpu32_plt_entry, { 4, 18 }, 10
647 1.1 skrll };
648 1.1 skrll
649 1.1 skrll /* The m68k linker needs to keep track of the number of relocs that it
650 1.1 skrll decides to copy in check_relocs for each symbol. This is so that it
651 1.1 skrll can discard PC relative relocs if it doesn't need them when linking
652 1.1 skrll with -Bsymbolic. We store the information in a field extending the
653 1.1 skrll regular ELF linker hash table. */
654 1.1 skrll
655 1.1 skrll /* This structure keeps track of the number of PC relative relocs we have
656 1.1 skrll copied for a given symbol. */
657 1.1 skrll
658 1.1 skrll struct elf_m68k_pcrel_relocs_copied
659 1.1 skrll {
660 1.1 skrll /* Next section. */
661 1.1 skrll struct elf_m68k_pcrel_relocs_copied *next;
662 1.1 skrll /* A section in dynobj. */
663 1.1 skrll asection *section;
664 1.1 skrll /* Number of relocs copied in this section. */
665 1.1 skrll bfd_size_type count;
666 1.1 skrll };
667 1.1 skrll
668 1.1 skrll /* Forward declaration. */
669 1.1 skrll struct elf_m68k_got_entry;
670 1.1 skrll
671 1.1 skrll /* m68k ELF linker hash entry. */
672 1.1 skrll
673 1.1 skrll struct elf_m68k_link_hash_entry
674 1.1 skrll {
675 1.1 skrll struct elf_link_hash_entry root;
676 1.1 skrll
677 1.1 skrll /* Number of PC relative relocs copied for this symbol. */
678 1.1 skrll struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
679 1.1 skrll
680 1.1 skrll /* Key to got_entries. */
681 1.1 skrll unsigned long got_entry_key;
682 1.1 skrll
683 1.1 skrll /* List of GOT entries for this symbol. This list is build during
684 1.1 skrll offset finalization and is used within elf_m68k_finish_dynamic_symbol
685 1.1 skrll to traverse all GOT entries for a particular symbol.
686 1.1 skrll
687 1.1 skrll ??? We could've used root.got.glist field instead, but having
688 1.1 skrll a separate field is cleaner. */
689 1.1 skrll struct elf_m68k_got_entry *glist;
690 1.1 skrll };
691 1.1 skrll
692 1.1 skrll #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
693 1.1 skrll
694 1.1 skrll /* Key part of GOT entry in hashtable. */
695 1.1 skrll struct elf_m68k_got_entry_key
696 1.1 skrll {
697 1.1 skrll /* BFD in which this symbol was defined. NULL for global symbols. */
698 1.1 skrll const bfd *bfd;
699 1.1 skrll
700 1.1 skrll /* Symbol index. Either local symbol index or h->got_entry_key. */
701 1.1.1.2 christos unsigned long symndx;
702 1.1.1.2 christos
703 1.1.1.2 christos /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
704 1.1.1.2 christos R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
705 1.1.1.2 christos
706 1.1.1.2 christos From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
707 1.1.1.2 christos matters. That is, we distinguish between, say, R_68K_GOT16O
708 1.1.1.2 christos and R_68K_GOT32O when allocating offsets, but they are considered to be
709 1.1.1.2 christos the same when searching got->entries. */
710 1.1 skrll enum elf_m68k_reloc_type type;
711 1.1 skrll };
712 1.1.1.2 christos
713 1.1.1.2 christos /* Size of the GOT offset suitable for relocation. */
714 1.1.1.2 christos enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST };
715 1.1 skrll
716 1.1 skrll /* Entry of the GOT. */
717 1.1 skrll struct elf_m68k_got_entry
718 1.1 skrll {
719 1.1 skrll /* GOT entries are put into a got->entries hashtable. This is the key. */
720 1.1 skrll struct elf_m68k_got_entry_key key_;
721 1.1 skrll
722 1.1 skrll /* GOT entry data. We need s1 before offset finalization and s2 after. */
723 1.1 skrll union
724 1.1 skrll {
725 1.1 skrll struct
726 1.1 skrll {
727 1.1 skrll /* Number of times this entry is referenced. It is used to
728 1.1 skrll filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */
729 1.1 skrll bfd_vma refcount;
730 1.1 skrll } s1;
731 1.1 skrll
732 1.1 skrll struct
733 1.1 skrll {
734 1.1 skrll /* Offset from the start of .got section. To calculate offset relative
735 1.1 skrll to GOT pointer one should substract got->offset from this value. */
736 1.1 skrll bfd_vma offset;
737 1.1 skrll
738 1.1 skrll /* Pointer to the next GOT entry for this global symbol.
739 1.1 skrll Symbols have at most one entry in one GOT, but might
740 1.1 skrll have entries in more than one GOT.
741 1.1 skrll Root of this list is h->glist.
742 1.1 skrll NULL for local symbols. */
743 1.1 skrll struct elf_m68k_got_entry *next;
744 1.1 skrll } s2;
745 1.1 skrll } u;
746 1.1 skrll };
747 1.1.1.2 christos
748 1.1.1.2 christos /* Return representative type for relocation R_TYPE.
749 1.1.1.2 christos This is used to avoid enumerating many relocations in comparisons,
750 1.1.1.2 christos switches etc. */
751 1.1.1.2 christos
752 1.1.1.2 christos static enum elf_m68k_reloc_type
753 1.1.1.2 christos elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type)
754 1.1.1.2 christos {
755 1.1.1.2 christos switch (r_type)
756 1.1.1.2 christos {
757 1.1.1.2 christos /* In most cases R_68K_GOTx relocations require the very same
758 1.1.1.2 christos handling as R_68K_GOT32O relocation. In cases when we need
759 1.1.1.2 christos to distinguish between the two, we use explicitly compare against
760 1.1.1.2 christos r_type. */
761 1.1.1.2 christos case R_68K_GOT32:
762 1.1.1.2 christos case R_68K_GOT16:
763 1.1.1.2 christos case R_68K_GOT8:
764 1.1.1.2 christos case R_68K_GOT32O:
765 1.1.1.2 christos case R_68K_GOT16O:
766 1.1.1.2 christos case R_68K_GOT8O:
767 1.1.1.2 christos return R_68K_GOT32O;
768 1.1.1.2 christos
769 1.1.1.2 christos case R_68K_TLS_GD32:
770 1.1.1.2 christos case R_68K_TLS_GD16:
771 1.1.1.2 christos case R_68K_TLS_GD8:
772 1.1.1.2 christos return R_68K_TLS_GD32;
773 1.1.1.2 christos
774 1.1.1.2 christos case R_68K_TLS_LDM32:
775 1.1.1.2 christos case R_68K_TLS_LDM16:
776 1.1.1.2 christos case R_68K_TLS_LDM8:
777 1.1.1.2 christos return R_68K_TLS_LDM32;
778 1.1.1.2 christos
779 1.1.1.2 christos case R_68K_TLS_IE32:
780 1.1.1.2 christos case R_68K_TLS_IE16:
781 1.1.1.2 christos case R_68K_TLS_IE8:
782 1.1.1.2 christos return R_68K_TLS_IE32;
783 1.1.1.2 christos
784 1.1.1.2 christos default:
785 1.1.1.2 christos BFD_ASSERT (FALSE);
786 1.1.1.2 christos return 0;
787 1.1.1.2 christos }
788 1.1.1.2 christos }
789 1.1.1.2 christos
790 1.1.1.2 christos /* Return size of the GOT entry offset for relocation R_TYPE. */
791 1.1.1.2 christos
792 1.1.1.2 christos static enum elf_m68k_got_offset_size
793 1.1.1.2 christos elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type)
794 1.1.1.2 christos {
795 1.1.1.2 christos switch (r_type)
796 1.1.1.2 christos {
797 1.1.1.2 christos case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8:
798 1.1.1.2 christos case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32:
799 1.1.1.2 christos case R_68K_TLS_IE32:
800 1.1.1.2 christos return R_32;
801 1.1.1.2 christos
802 1.1.1.2 christos case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16:
803 1.1.1.2 christos case R_68K_TLS_IE16:
804 1.1.1.2 christos return R_16;
805 1.1.1.2 christos
806 1.1.1.2 christos case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8:
807 1.1.1.2 christos case R_68K_TLS_IE8:
808 1.1.1.2 christos return R_8;
809 1.1.1.2 christos
810 1.1.1.2 christos default:
811 1.1.1.2 christos BFD_ASSERT (FALSE);
812 1.1.1.2 christos return 0;
813 1.1.1.2 christos }
814 1.1.1.2 christos }
815 1.1.1.2 christos
816 1.1.1.2 christos /* Return number of GOT entries we need to allocate in GOT for
817 1.1.1.2 christos relocation R_TYPE. */
818 1.1.1.2 christos
819 1.1.1.2 christos static bfd_vma
820 1.1.1.2 christos elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type)
821 1.1.1.2 christos {
822 1.1.1.2 christos switch (elf_m68k_reloc_got_type (r_type))
823 1.1.1.2 christos {
824 1.1.1.2 christos case R_68K_GOT32O:
825 1.1.1.2 christos case R_68K_TLS_IE32:
826 1.1.1.2 christos return 1;
827 1.1.1.2 christos
828 1.1.1.2 christos case R_68K_TLS_GD32:
829 1.1.1.2 christos case R_68K_TLS_LDM32:
830 1.1.1.2 christos return 2;
831 1.1.1.2 christos
832 1.1.1.2 christos default:
833 1.1.1.2 christos BFD_ASSERT (FALSE);
834 1.1.1.2 christos return 0;
835 1.1.1.2 christos }
836 1.1.1.2 christos }
837 1.1.1.2 christos
838 1.1.1.2 christos /* Return TRUE if relocation R_TYPE is a TLS one. */
839 1.1.1.2 christos
840 1.1.1.2 christos static bfd_boolean
841 1.1.1.2 christos elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type)
842 1.1.1.2 christos {
843 1.1.1.2 christos switch (r_type)
844 1.1.1.2 christos {
845 1.1.1.2 christos case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8:
846 1.1.1.2 christos case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8:
847 1.1.1.2 christos case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8:
848 1.1.1.2 christos case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8:
849 1.1.1.2 christos case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8:
850 1.1.1.2 christos case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32:
851 1.1.1.2 christos return TRUE;
852 1.1.1.2 christos
853 1.1.1.2 christos default:
854 1.1.1.2 christos return FALSE;
855 1.1.1.2 christos }
856 1.1.1.2 christos }
857 1.1 skrll
858 1.1 skrll /* Data structure representing a single GOT. */
859 1.1 skrll struct elf_m68k_got
860 1.1 skrll {
861 1.1 skrll /* Hashtable of 'struct elf_m68k_got_entry's.
862 1.1 skrll Starting size of this table is the maximum number of
863 1.1 skrll R_68K_GOT8O entries. */
864 1.1 skrll htab_t entries;
865 1.1.1.2 christos
866 1.1.1.2 christos /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
867 1.1 skrll several GOT slots.
868 1.1.1.2 christos
869 1.1.1.2 christos n_slots[R_8] is the count of R_8 slots in this GOT.
870 1.1.1.2 christos n_slots[R_16] is the cumulative count of R_8 and R_16 slots
871 1.1.1.2 christos in this GOT.
872 1.1.1.2 christos n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
873 1.1.1.2 christos in this GOT. This is the total number of slots. */
874 1.1.1.2 christos bfd_vma n_slots[R_LAST];
875 1.1.1.2 christos
876 1.1 skrll /* Number of local (entry->key_.h == NULL) slots in this GOT.
877 1.1 skrll This is only used to properly calculate size of .rela.got section;
878 1.1.1.2 christos see elf_m68k_partition_multi_got. */
879 1.1 skrll bfd_vma local_n_slots;
880 1.1 skrll
881 1.1 skrll /* Offset of this GOT relative to beginning of .got section. */
882 1.1 skrll bfd_vma offset;
883 1.1 skrll };
884 1.1 skrll
885 1.1 skrll /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
886 1.1 skrll struct elf_m68k_bfd2got_entry
887 1.1 skrll {
888 1.1 skrll /* BFD. */
889 1.1 skrll const bfd *bfd;
890 1.1 skrll
891 1.1 skrll /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
892 1.1 skrll GOT structure. After partitioning several BFD's might [and often do]
893 1.1 skrll share a single GOT. */
894 1.1 skrll struct elf_m68k_got *got;
895 1.1 skrll };
896 1.1 skrll
897 1.1 skrll /* The main data structure holding all the pieces. */
898 1.1 skrll struct elf_m68k_multi_got
899 1.1 skrll {
900 1.1 skrll /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
901 1.1 skrll here, then it doesn't need a GOT (this includes the case of a BFD
902 1.1 skrll having an empty GOT).
903 1.1 skrll
904 1.1 skrll ??? This hashtable can be replaced by an array indexed by bfd->id. */
905 1.1 skrll htab_t bfd2got;
906 1.1 skrll
907 1.1 skrll /* Next symndx to assign a global symbol.
908 1.1 skrll h->got_entry_key is initialized from this counter. */
909 1.1 skrll unsigned long global_symndx;
910 1.1 skrll };
911 1.1 skrll
912 1.1 skrll /* m68k ELF linker hash table. */
913 1.1 skrll
914 1.1 skrll struct elf_m68k_link_hash_table
915 1.1 skrll {
916 1.1 skrll struct elf_link_hash_table root;
917 1.1.1.2 christos
918 1.1.1.2 christos /* Small local sym cache. */
919 1.1 skrll struct sym_cache sym_cache;
920 1.1 skrll
921 1.1 skrll /* The PLT format used by this link, or NULL if the format has not
922 1.1 skrll yet been chosen. */
923 1.1 skrll const struct elf_m68k_plt_info *plt_info;
924 1.1 skrll
925 1.1 skrll /* True, if GP is loaded within each function which uses it.
926 1.1 skrll Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
927 1.1 skrll bfd_boolean local_gp_p;
928 1.1 skrll
929 1.1 skrll /* Switch controlling use of negative offsets to double the size of GOTs. */
930 1.1 skrll bfd_boolean use_neg_got_offsets_p;
931 1.1 skrll
932 1.1 skrll /* Switch controlling generation of multiple GOTs. */
933 1.1 skrll bfd_boolean allow_multigot_p;
934 1.1 skrll
935 1.1 skrll /* Multi-GOT data structure. */
936 1.1 skrll struct elf_m68k_multi_got multi_got_;
937 1.1 skrll };
938 1.1 skrll
939 1.1 skrll /* Get the m68k ELF linker hash table from a link_info structure. */
940 1.1 skrll
941 1.1.1.2 christos #define elf_m68k_hash_table(p) \
942 1.1.1.2 christos (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
943 1.1 skrll == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
944 1.1 skrll
945 1.1 skrll /* Shortcut to multi-GOT data. */
946 1.1 skrll #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
947 1.1 skrll
948 1.1 skrll /* Create an entry in an m68k ELF linker hash table. */
949 1.1 skrll
950 1.1.1.2 christos static struct bfd_hash_entry *
951 1.1.1.2 christos elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry,
952 1.1.1.2 christos struct bfd_hash_table *table,
953 1.1 skrll const char *string)
954 1.1 skrll {
955 1.1 skrll struct bfd_hash_entry *ret = entry;
956 1.1 skrll
957 1.1 skrll /* Allocate the structure if it has not already been allocated by a
958 1.1 skrll subclass. */
959 1.1 skrll if (ret == NULL)
960 1.1 skrll ret = bfd_hash_allocate (table,
961 1.1 skrll sizeof (struct elf_m68k_link_hash_entry));
962 1.1 skrll if (ret == NULL)
963 1.1 skrll return ret;
964 1.1 skrll
965 1.1 skrll /* Call the allocation method of the superclass. */
966 1.1 skrll ret = _bfd_elf_link_hash_newfunc (ret, table, string);
967 1.1 skrll if (ret != NULL)
968 1.1 skrll {
969 1.1 skrll elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
970 1.1 skrll elf_m68k_hash_entry (ret)->got_entry_key = 0;
971 1.1 skrll elf_m68k_hash_entry (ret)->glist = NULL;
972 1.1 skrll }
973 1.1 skrll
974 1.1 skrll return ret;
975 1.1 skrll }
976 1.1 skrll
977 1.1 skrll /* Create an m68k ELF linker hash table. */
978 1.1 skrll
979 1.1.1.2 christos static struct bfd_link_hash_table *
980 1.1 skrll elf_m68k_link_hash_table_create (bfd *abfd)
981 1.1 skrll {
982 1.1 skrll struct elf_m68k_link_hash_table *ret;
983 1.1 skrll bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table);
984 1.1 skrll
985 1.1 skrll ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt);
986 1.1 skrll if (ret == (struct elf_m68k_link_hash_table *) NULL)
987 1.1 skrll return NULL;
988 1.1 skrll
989 1.1 skrll if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
990 1.1.1.2 christos elf_m68k_link_hash_newfunc,
991 1.1.1.2 christos sizeof (struct elf_m68k_link_hash_entry),
992 1.1 skrll M68K_ELF_DATA))
993 1.1 skrll {
994 1.1 skrll free (ret);
995 1.1 skrll return NULL;
996 1.1 skrll }
997 1.1.1.2 christos
998 1.1 skrll ret->sym_cache.abfd = NULL;
999 1.1 skrll ret->plt_info = NULL;
1000 1.1 skrll ret->local_gp_p = FALSE;
1001 1.1 skrll ret->use_neg_got_offsets_p = FALSE;
1002 1.1 skrll ret->allow_multigot_p = FALSE;
1003 1.1 skrll ret->multi_got_.bfd2got = NULL;
1004 1.1 skrll ret->multi_got_.global_symndx = 1;
1005 1.1 skrll
1006 1.1 skrll return &ret->root.root;
1007 1.1 skrll }
1008 1.1 skrll
1009 1.1 skrll /* Destruct local data. */
1010 1.1 skrll
1011 1.1 skrll static void
1012 1.1 skrll elf_m68k_link_hash_table_free (struct bfd_link_hash_table *_htab)
1013 1.1 skrll {
1014 1.1 skrll struct elf_m68k_link_hash_table *htab;
1015 1.1 skrll
1016 1.1 skrll htab = (struct elf_m68k_link_hash_table *) _htab;
1017 1.1 skrll
1018 1.1 skrll if (htab->multi_got_.bfd2got != NULL)
1019 1.1 skrll {
1020 1.1 skrll htab_delete (htab->multi_got_.bfd2got);
1021 1.1 skrll htab->multi_got_.bfd2got = NULL;
1022 1.1 skrll }
1023 1.1 skrll }
1024 1.1 skrll
1025 1.1 skrll /* Set the right machine number. */
1026 1.1 skrll
1027 1.1 skrll static bfd_boolean
1028 1.1 skrll elf32_m68k_object_p (bfd *abfd)
1029 1.1 skrll {
1030 1.1 skrll unsigned int mach = 0;
1031 1.1 skrll unsigned features = 0;
1032 1.1 skrll flagword eflags = elf_elfheader (abfd)->e_flags;
1033 1.1 skrll
1034 1.1 skrll if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1035 1.1 skrll features |= m68000;
1036 1.1 skrll else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1037 1.1 skrll features |= cpu32;
1038 1.1 skrll else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1039 1.1 skrll features |= fido_a;
1040 1.1 skrll else
1041 1.1 skrll {
1042 1.1 skrll switch (eflags & EF_M68K_CF_ISA_MASK)
1043 1.1 skrll {
1044 1.1 skrll case EF_M68K_CF_ISA_A_NODIV:
1045 1.1 skrll features |= mcfisa_a;
1046 1.1 skrll break;
1047 1.1 skrll case EF_M68K_CF_ISA_A:
1048 1.1 skrll features |= mcfisa_a|mcfhwdiv;
1049 1.1 skrll break;
1050 1.1 skrll case EF_M68K_CF_ISA_A_PLUS:
1051 1.1 skrll features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
1052 1.1 skrll break;
1053 1.1 skrll case EF_M68K_CF_ISA_B_NOUSP:
1054 1.1 skrll features |= mcfisa_a|mcfisa_b|mcfhwdiv;
1055 1.1 skrll break;
1056 1.1 skrll case EF_M68K_CF_ISA_B:
1057 1.1 skrll features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
1058 1.1 skrll break;
1059 1.1 skrll case EF_M68K_CF_ISA_C:
1060 1.1 skrll features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
1061 1.1 skrll break;
1062 1.1 skrll case EF_M68K_CF_ISA_C_NODIV:
1063 1.1 skrll features |= mcfisa_a|mcfisa_c|mcfusp;
1064 1.1 skrll break;
1065 1.1 skrll }
1066 1.1 skrll switch (eflags & EF_M68K_CF_MAC_MASK)
1067 1.1 skrll {
1068 1.1 skrll case EF_M68K_CF_MAC:
1069 1.1 skrll features |= mcfmac;
1070 1.1 skrll break;
1071 1.1 skrll case EF_M68K_CF_EMAC:
1072 1.1 skrll features |= mcfemac;
1073 1.1 skrll break;
1074 1.1 skrll }
1075 1.1 skrll if (eflags & EF_M68K_CF_FLOAT)
1076 1.1 skrll features |= cfloat;
1077 1.1 skrll }
1078 1.1 skrll
1079 1.1 skrll mach = bfd_m68k_features_to_mach (features);
1080 1.1 skrll bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
1081 1.1 skrll
1082 1.1 skrll return TRUE;
1083 1.1 skrll }
1084 1.1.1.2 christos
1085 1.1.1.2 christos /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1086 1.1.1.2 christos field based on the machine number. */
1087 1.1.1.2 christos
1088 1.1.1.2 christos static void
1089 1.1.1.2 christos elf_m68k_final_write_processing (bfd *abfd,
1090 1.1.1.2 christos bfd_boolean linker ATTRIBUTE_UNUSED)
1091 1.1.1.2 christos {
1092 1.1.1.2 christos int mach = bfd_get_mach (abfd);
1093 1.1.1.2 christos unsigned long e_flags = elf_elfheader (abfd)->e_flags;
1094 1.1.1.2 christos
1095 1.1.1.2 christos if (!e_flags)
1096 1.1.1.2 christos {
1097 1.1.1.2 christos unsigned int arch_mask;
1098 1.1.1.2 christos
1099 1.1.1.2 christos arch_mask = bfd_m68k_mach_to_features (mach);
1100 1.1.1.2 christos
1101 1.1.1.2 christos if (arch_mask & m68000)
1102 1.1.1.2 christos e_flags = EF_M68K_M68000;
1103 1.1.1.2 christos else if (arch_mask & cpu32)
1104 1.1.1.2 christos e_flags = EF_M68K_CPU32;
1105 1.1.1.2 christos else if (arch_mask & fido_a)
1106 1.1.1.2 christos e_flags = EF_M68K_FIDO;
1107 1.1.1.2 christos else
1108 1.1.1.2 christos {
1109 1.1.1.2 christos switch (arch_mask
1110 1.1.1.2 christos & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp))
1111 1.1.1.2 christos {
1112 1.1.1.2 christos case mcfisa_a:
1113 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_A_NODIV;
1114 1.1.1.2 christos break;
1115 1.1.1.2 christos case mcfisa_a | mcfhwdiv:
1116 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_A;
1117 1.1.1.2 christos break;
1118 1.1.1.2 christos case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp:
1119 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_A_PLUS;
1120 1.1.1.2 christos break;
1121 1.1.1.2 christos case mcfisa_a | mcfisa_b | mcfhwdiv:
1122 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_B_NOUSP;
1123 1.1.1.2 christos break;
1124 1.1.1.2 christos case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp:
1125 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_B;
1126 1.1.1.2 christos break;
1127 1.1.1.2 christos case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp:
1128 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_C;
1129 1.1.1.2 christos break;
1130 1.1.1.2 christos case mcfisa_a | mcfisa_c | mcfusp:
1131 1.1.1.2 christos e_flags |= EF_M68K_CF_ISA_C_NODIV;
1132 1.1.1.2 christos break;
1133 1.1.1.2 christos }
1134 1.1.1.2 christos if (arch_mask & mcfmac)
1135 1.1.1.2 christos e_flags |= EF_M68K_CF_MAC;
1136 1.1.1.2 christos else if (arch_mask & mcfemac)
1137 1.1.1.2 christos e_flags |= EF_M68K_CF_EMAC;
1138 1.1.1.2 christos if (arch_mask & cfloat)
1139 1.1.1.2 christos e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
1140 1.1.1.2 christos }
1141 1.1.1.2 christos elf_elfheader (abfd)->e_flags = e_flags;
1142 1.1.1.2 christos }
1143 1.1.1.2 christos }
1144 1.1 skrll
1145 1.1.1.2 christos /* Keep m68k-specific flags in the ELF header. */
1146 1.1 skrll
1147 1.1 skrll static bfd_boolean
1148 1.1 skrll elf32_m68k_set_private_flags (abfd, flags)
1149 1.1 skrll bfd *abfd;
1150 1.1 skrll flagword flags;
1151 1.1 skrll {
1152 1.1 skrll elf_elfheader (abfd)->e_flags = flags;
1153 1.1 skrll elf_flags_init (abfd) = TRUE;
1154 1.1 skrll return TRUE;
1155 1.1 skrll }
1156 1.1 skrll
1157 1.1 skrll /* Merge backend specific data from an object file to the output
1158 1.1 skrll object file when linking. */
1159 1.1 skrll static bfd_boolean
1160 1.1 skrll elf32_m68k_merge_private_bfd_data (ibfd, obfd)
1161 1.1 skrll bfd *ibfd;
1162 1.1 skrll bfd *obfd;
1163 1.1 skrll {
1164 1.1 skrll flagword out_flags;
1165 1.1 skrll flagword in_flags;
1166 1.1 skrll flagword out_isa;
1167 1.1 skrll flagword in_isa;
1168 1.1 skrll const bfd_arch_info_type *arch_info;
1169 1.1 skrll
1170 1.1 skrll if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1171 1.1 skrll || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1172 1.1 skrll return FALSE;
1173 1.1 skrll
1174 1.1 skrll /* Get the merged machine. This checks for incompatibility between
1175 1.1 skrll Coldfire & non-Coldfire flags, incompability between different
1176 1.1 skrll Coldfire ISAs, and incompability between different MAC types. */
1177 1.1 skrll arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
1178 1.1 skrll if (!arch_info)
1179 1.1 skrll return FALSE;
1180 1.1 skrll
1181 1.1 skrll bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
1182 1.1 skrll
1183 1.1 skrll in_flags = elf_elfheader (ibfd)->e_flags;
1184 1.1 skrll if (!elf_flags_init (obfd))
1185 1.1 skrll {
1186 1.1 skrll elf_flags_init (obfd) = TRUE;
1187 1.1 skrll out_flags = in_flags;
1188 1.1 skrll }
1189 1.1 skrll else
1190 1.1 skrll {
1191 1.1 skrll out_flags = elf_elfheader (obfd)->e_flags;
1192 1.1 skrll unsigned int variant_mask;
1193 1.1 skrll
1194 1.1 skrll if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1195 1.1 skrll variant_mask = 0;
1196 1.1 skrll else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1197 1.1 skrll variant_mask = 0;
1198 1.1 skrll else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1199 1.1 skrll variant_mask = 0;
1200 1.1 skrll else
1201 1.1 skrll variant_mask = EF_M68K_CF_ISA_MASK;
1202 1.1 skrll
1203 1.1 skrll in_isa = (in_flags & variant_mask);
1204 1.1 skrll out_isa = (out_flags & variant_mask);
1205 1.1 skrll if (in_isa > out_isa)
1206 1.1 skrll out_flags ^= in_isa ^ out_isa;
1207 1.1 skrll if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
1208 1.1 skrll && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1209 1.1 skrll || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
1210 1.1 skrll && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
1211 1.1 skrll out_flags = EF_M68K_FIDO;
1212 1.1 skrll else
1213 1.1 skrll out_flags |= in_flags ^ in_isa;
1214 1.1 skrll }
1215 1.1 skrll elf_elfheader (obfd)->e_flags = out_flags;
1216 1.1 skrll
1217 1.1 skrll return TRUE;
1218 1.1 skrll }
1219 1.1 skrll
1220 1.1 skrll /* Display the flags field. */
1221 1.1 skrll
1222 1.1 skrll static bfd_boolean
1223 1.1 skrll elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
1224 1.1 skrll {
1225 1.1 skrll FILE *file = (FILE *) ptr;
1226 1.1 skrll flagword eflags = elf_elfheader (abfd)->e_flags;
1227 1.1 skrll
1228 1.1 skrll BFD_ASSERT (abfd != NULL && ptr != NULL);
1229 1.1 skrll
1230 1.1 skrll /* Print normal ELF private data. */
1231 1.1 skrll _bfd_elf_print_private_bfd_data (abfd, ptr);
1232 1.1 skrll
1233 1.1 skrll /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1234 1.1 skrll
1235 1.1 skrll /* xgettext:c-format */
1236 1.1 skrll fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
1237 1.1 skrll
1238 1.1 skrll if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1239 1.1 skrll fprintf (file, " [m68000]");
1240 1.1 skrll else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1241 1.1 skrll fprintf (file, " [cpu32]");
1242 1.1 skrll else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1243 1.1 skrll fprintf (file, " [fido]");
1244 1.1 skrll else
1245 1.1 skrll {
1246 1.1 skrll if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
1247 1.1 skrll fprintf (file, " [cfv4e]");
1248 1.1 skrll
1249 1.1 skrll if (eflags & EF_M68K_CF_ISA_MASK)
1250 1.1 skrll {
1251 1.1 skrll char const *isa = _("unknown");
1252 1.1 skrll char const *mac = _("unknown");
1253 1.1 skrll char const *additional = "";
1254 1.1 skrll
1255 1.1 skrll switch (eflags & EF_M68K_CF_ISA_MASK)
1256 1.1 skrll {
1257 1.1 skrll case EF_M68K_CF_ISA_A_NODIV:
1258 1.1 skrll isa = "A";
1259 1.1 skrll additional = " [nodiv]";
1260 1.1 skrll break;
1261 1.1 skrll case EF_M68K_CF_ISA_A:
1262 1.1 skrll isa = "A";
1263 1.1 skrll break;
1264 1.1 skrll case EF_M68K_CF_ISA_A_PLUS:
1265 1.1 skrll isa = "A+";
1266 1.1 skrll break;
1267 1.1 skrll case EF_M68K_CF_ISA_B_NOUSP:
1268 1.1 skrll isa = "B";
1269 1.1 skrll additional = " [nousp]";
1270 1.1 skrll break;
1271 1.1 skrll case EF_M68K_CF_ISA_B:
1272 1.1 skrll isa = "B";
1273 1.1 skrll break;
1274 1.1 skrll case EF_M68K_CF_ISA_C:
1275 1.1 skrll isa = "C";
1276 1.1 skrll break;
1277 1.1 skrll case EF_M68K_CF_ISA_C_NODIV:
1278 1.1 skrll isa = "C";
1279 1.1 skrll additional = " [nodiv]";
1280 1.1 skrll break;
1281 1.1 skrll }
1282 1.1 skrll fprintf (file, " [isa %s]%s", isa, additional);
1283 1.1 skrll
1284 1.1 skrll if (eflags & EF_M68K_CF_FLOAT)
1285 1.1 skrll fprintf (file, " [float]");
1286 1.1 skrll
1287 1.1 skrll switch (eflags & EF_M68K_CF_MAC_MASK)
1288 1.1 skrll {
1289 1.1 skrll case 0:
1290 1.1 skrll mac = NULL;
1291 1.1 skrll break;
1292 1.1 skrll case EF_M68K_CF_MAC:
1293 1.1 skrll mac = "mac";
1294 1.1 skrll break;
1295 1.1 skrll case EF_M68K_CF_EMAC:
1296 1.1 skrll mac = "emac";
1297 1.1.1.2 christos break;
1298 1.1.1.2 christos case EF_M68K_CF_EMAC_B:
1299 1.1.1.2 christos mac = "emac_b";
1300 1.1 skrll break;
1301 1.1 skrll }
1302 1.1 skrll if (mac)
1303 1.1 skrll fprintf (file, " [%s]", mac);
1304 1.1 skrll }
1305 1.1 skrll }
1306 1.1 skrll
1307 1.1 skrll fputc ('\n', file);
1308 1.1 skrll
1309 1.1 skrll return TRUE;
1310 1.1 skrll }
1311 1.1 skrll
1312 1.1 skrll /* Multi-GOT support implementation design:
1313 1.1 skrll
1314 1.1 skrll Multi-GOT starts in check_relocs hook. There we scan all
1315 1.1 skrll relocations of a BFD and build a local GOT (struct elf_m68k_got)
1316 1.1 skrll for it. If a single BFD appears to require too many GOT slots with
1317 1.1 skrll R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1318 1.1 skrll to user.
1319 1.1 skrll After check_relocs has been invoked for each input BFD, we have
1320 1.1 skrll constructed a GOT for each input BFD.
1321 1.1 skrll
1322 1.1 skrll To minimize total number of GOTs required for a particular output BFD
1323 1.1 skrll (as some environments support only 1 GOT per output object) we try
1324 1.1 skrll to merge some of the GOTs to share an offset space. Ideally [and in most
1325 1.1 skrll cases] we end up with a single GOT. In cases when there are too many
1326 1.1 skrll restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1327 1.1 skrll several GOTs, assuming the environment can handle them.
1328 1.1 skrll
1329 1.1 skrll Partitioning is done in elf_m68k_partition_multi_got. We start with
1330 1.1 skrll an empty GOT and traverse bfd2got hashtable putting got_entries from
1331 1.1 skrll local GOTs to the new 'big' one. We do that by constructing an
1332 1.1 skrll intermediate GOT holding all the entries the local GOT has and the big
1333 1.1 skrll GOT lacks. Then we check if there is room in the big GOT to accomodate
1334 1.1 skrll all the entries from diff. On success we add those entries to the big
1335 1.1 skrll GOT; on failure we start the new 'big' GOT and retry the adding of
1336 1.1 skrll entries from the local GOT. Note that this retry will always succeed as
1337 1.1 skrll each local GOT doesn't overflow the limits. After partitioning we
1338 1.1 skrll end up with each bfd assigned one of the big GOTs. GOT entries in the
1339 1.1 skrll big GOTs are initialized with GOT offsets. Note that big GOTs are
1340 1.1 skrll positioned consequently in program space and represent a single huge GOT
1341 1.1 skrll to the outside world.
1342 1.1 skrll
1343 1.1 skrll After that we get to elf_m68k_relocate_section. There we
1344 1.1 skrll adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1345 1.1 skrll relocations to refer to appropriate [assigned to current input_bfd]
1346 1.1 skrll big GOT.
1347 1.1 skrll
1348 1.1 skrll Notes:
1349 1.1.1.2 christos
1350 1.1.1.2 christos GOT entry type: We have several types of GOT entries.
1351 1.1.1.2 christos * R_8 type is used in entries for symbols that have at least one
1352 1.1 skrll R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1353 1.1.1.2 christos such entries in one GOT.
1354 1.1.1.2 christos * R_16 type is used in entries for symbols that have at least one
1355 1.1 skrll R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1356 1.1.1.2 christos We can have at most 0x4000 such entries in one GOT.
1357 1.1.1.2 christos * R_32 type is used in all other cases. We can have as many
1358 1.1 skrll such entries in one GOT as we'd like.
1359 1.1 skrll When counting relocations we have to include the count of the smaller
1360 1.1 skrll ranged relocations in the counts of the larger ranged ones in order
1361 1.1 skrll to correctly detect overflow.
1362 1.1 skrll
1363 1.1.1.2 christos Sorting the GOT: In each GOT starting offsets are assigned to
1364 1.1.1.2 christos R_8 entries, which are followed by R_16 entries, and
1365 1.1 skrll R_32 entries go at the end. See finalize_got_offsets for details.
1366 1.1 skrll
1367 1.1 skrll Negative GOT offsets: To double usable offset range of GOTs we use
1368 1.1 skrll negative offsets. As we assign entries with GOT offsets relative to
1369 1.1 skrll start of .got section, the offset values are positive. They become
1370 1.1 skrll negative only in relocate_section where got->offset value is
1371 1.1 skrll subtracted from them.
1372 1.1 skrll
1373 1.1 skrll 3 special GOT entries: There are 3 special GOT entries used internally
1374 1.1 skrll by loader. These entries happen to be placed to .got.plt section,
1375 1.1 skrll so we don't do anything about them in multi-GOT support.
1376 1.1 skrll
1377 1.1 skrll Memory management: All data except for hashtables
1378 1.1 skrll multi_got->bfd2got and got->entries are allocated on
1379 1.1 skrll elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1380 1.1 skrll to most functions), so we don't need to care to free them. At the
1381 1.1 skrll moment of allocation hashtables are being linked into main data
1382 1.1 skrll structure (multi_got), all pieces of which are reachable from
1383 1.1 skrll elf_m68k_multi_got (info). We deallocate them in
1384 1.1 skrll elf_m68k_link_hash_table_free. */
1385 1.1 skrll
1386 1.1 skrll /* Initialize GOT. */
1387 1.1 skrll
1388 1.1.1.2 christos static void
1389 1.1.1.2 christos elf_m68k_init_got (struct elf_m68k_got *got)
1390 1.1.1.2 christos {
1391 1.1.1.2 christos got->entries = NULL;
1392 1.1.1.2 christos got->n_slots[R_8] = 0;
1393 1.1.1.2 christos got->n_slots[R_16] = 0;
1394 1.1.1.2 christos got->n_slots[R_32] = 0;
1395 1.1.1.2 christos got->local_n_slots = 0;
1396 1.1 skrll got->offset = (bfd_vma) -1;
1397 1.1 skrll }
1398 1.1 skrll
1399 1.1 skrll /* Destruct GOT. */
1400 1.1 skrll
1401 1.1 skrll static void
1402 1.1 skrll elf_m68k_clear_got (struct elf_m68k_got *got)
1403 1.1 skrll {
1404 1.1 skrll if (got->entries != NULL)
1405 1.1 skrll {
1406 1.1 skrll htab_delete (got->entries);
1407 1.1 skrll got->entries = NULL;
1408 1.1 skrll }
1409 1.1 skrll }
1410 1.1 skrll
1411 1.1 skrll /* Create and empty GOT structure. INFO is the context where memory
1412 1.1 skrll should be allocated. */
1413 1.1 skrll
1414 1.1 skrll static struct elf_m68k_got *
1415 1.1 skrll elf_m68k_create_empty_got (struct bfd_link_info *info)
1416 1.1 skrll {
1417 1.1 skrll struct elf_m68k_got *got;
1418 1.1 skrll
1419 1.1 skrll got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
1420 1.1 skrll if (got == NULL)
1421 1.1 skrll return NULL;
1422 1.1.1.2 christos
1423 1.1 skrll elf_m68k_init_got (got);
1424 1.1 skrll
1425 1.1 skrll return got;
1426 1.1 skrll }
1427 1.1 skrll
1428 1.1 skrll /* Initialize KEY. */
1429 1.1 skrll
1430 1.1 skrll static void
1431 1.1 skrll elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
1432 1.1.1.2 christos struct elf_link_hash_entry *h,
1433 1.1.1.2 christos const bfd *abfd, unsigned long symndx,
1434 1.1 skrll enum elf_m68k_reloc_type reloc_type)
1435 1.1.1.2 christos {
1436 1.1.1.2 christos if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32)
1437 1.1.1.2 christos /* All TLS_LDM relocations share a single GOT entry. */
1438 1.1.1.2 christos {
1439 1.1.1.2 christos key->bfd = NULL;
1440 1.1.1.2 christos key->symndx = 0;
1441 1.1.1.2 christos }
1442 1.1.1.2 christos else if (h != NULL)
1443 1.1 skrll /* Global symbols are identified with their got_entry_key. */
1444 1.1 skrll {
1445 1.1 skrll key->bfd = NULL;
1446 1.1 skrll key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
1447 1.1 skrll BFD_ASSERT (key->symndx != 0);
1448 1.1 skrll }
1449 1.1.1.2 christos else
1450 1.1 skrll /* Local symbols are identified by BFD they appear in and symndx. */
1451 1.1 skrll {
1452 1.1 skrll key->bfd = abfd;
1453 1.1 skrll key->symndx = symndx;
1454 1.1.1.2 christos }
1455 1.1.1.2 christos
1456 1.1 skrll key->type = reloc_type;
1457 1.1 skrll }
1458 1.1 skrll
1459 1.1 skrll /* Calculate hash of got_entry.
1460 1.1 skrll ??? Is it good? */
1461 1.1 skrll
1462 1.1 skrll static hashval_t
1463 1.1 skrll elf_m68k_got_entry_hash (const void *_entry)
1464 1.1 skrll {
1465 1.1 skrll const struct elf_m68k_got_entry_key *key;
1466 1.1 skrll
1467 1.1 skrll key = &((const struct elf_m68k_got_entry *) _entry)->key_;
1468 1.1.1.2 christos
1469 1.1.1.2 christos return (key->symndx
1470 1.1.1.2 christos + (key->bfd != NULL ? (int) key->bfd->id : -1)
1471 1.1 skrll + elf_m68k_reloc_got_type (key->type));
1472 1.1 skrll }
1473 1.1 skrll
1474 1.1 skrll /* Check if two got entries are equal. */
1475 1.1 skrll
1476 1.1 skrll static int
1477 1.1 skrll elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
1478 1.1 skrll {
1479 1.1 skrll const struct elf_m68k_got_entry_key *key1;
1480 1.1 skrll const struct elf_m68k_got_entry_key *key2;
1481 1.1 skrll
1482 1.1 skrll key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
1483 1.1 skrll key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
1484 1.1 skrll
1485 1.1.1.2 christos return (key1->bfd == key2->bfd
1486 1.1.1.2 christos && key1->symndx == key2->symndx
1487 1.1.1.2 christos && (elf_m68k_reloc_got_type (key1->type)
1488 1.1 skrll == elf_m68k_reloc_got_type (key2->type)));
1489 1.1 skrll }
1490 1.1.1.2 christos
1491 1.1.1.2 christos /* When using negative offsets, we allocate one extra R_8, one extra R_16
1492 1.1.1.2 christos and one extra R_32 slots to simplify handling of 2-slot entries during
1493 1.1.1.2 christos offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1494 1.1.1.2 christos
1495 1.1.1.2 christos /* Maximal number of R_8 slots in a single GOT. */
1496 1.1 skrll #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1497 1.1.1.2 christos (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1498 1.1 skrll ? (0x40 - 1) \
1499 1.1 skrll : 0x20)
1500 1.1.1.2 christos
1501 1.1.1.2 christos /* Maximal number of R_8 and R_16 slots in a single GOT. */
1502 1.1 skrll #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1503 1.1.1.2 christos (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1504 1.1 skrll ? (0x4000 - 2) \
1505 1.1 skrll : 0x2000)
1506 1.1 skrll
1507 1.1 skrll /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1508 1.1 skrll the entry cannot be found.
1509 1.1 skrll FIND_OR_CREATE - search for an existing entry, but create new if there's
1510 1.1 skrll no such.
1511 1.1 skrll MUST_FIND - search for an existing entry and assert that it exist.
1512 1.1 skrll MUST_CREATE - assert that there's no such entry and create new one. */
1513 1.1 skrll enum elf_m68k_get_entry_howto
1514 1.1 skrll {
1515 1.1 skrll SEARCH,
1516 1.1 skrll FIND_OR_CREATE,
1517 1.1 skrll MUST_FIND,
1518 1.1 skrll MUST_CREATE
1519 1.1 skrll };
1520 1.1 skrll
1521 1.1 skrll /* Get or create (depending on HOWTO) entry with KEY in GOT.
1522 1.1 skrll INFO is context in which memory should be allocated (can be NULL if
1523 1.1 skrll HOWTO is SEARCH or MUST_FIND). */
1524 1.1 skrll
1525 1.1 skrll static struct elf_m68k_got_entry *
1526 1.1 skrll elf_m68k_get_got_entry (struct elf_m68k_got *got,
1527 1.1 skrll const struct elf_m68k_got_entry_key *key,
1528 1.1 skrll enum elf_m68k_get_entry_howto howto,
1529 1.1 skrll struct bfd_link_info *info)
1530 1.1 skrll {
1531 1.1 skrll struct elf_m68k_got_entry entry_;
1532 1.1 skrll struct elf_m68k_got_entry *entry;
1533 1.1 skrll void **ptr;
1534 1.1 skrll
1535 1.1 skrll BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1536 1.1 skrll
1537 1.1 skrll if (got->entries == NULL)
1538 1.1 skrll /* This is the first entry in ABFD. Initialize hashtable. */
1539 1.1 skrll {
1540 1.1 skrll if (howto == SEARCH)
1541 1.1 skrll return NULL;
1542 1.1.1.2 christos
1543 1.1 skrll got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1544 1.1 skrll (info),
1545 1.1 skrll elf_m68k_got_entry_hash,
1546 1.1 skrll elf_m68k_got_entry_eq, NULL);
1547 1.1 skrll if (got->entries == NULL)
1548 1.1 skrll {
1549 1.1 skrll bfd_set_error (bfd_error_no_memory);
1550 1.1 skrll return NULL;
1551 1.1 skrll }
1552 1.1 skrll }
1553 1.1 skrll
1554 1.1 skrll entry_.key_ = *key;
1555 1.1 skrll ptr = htab_find_slot (got->entries, &entry_, (howto != SEARCH
1556 1.1 skrll ? INSERT : NO_INSERT));
1557 1.1 skrll if (ptr == NULL)
1558 1.1 skrll {
1559 1.1 skrll if (howto == SEARCH)
1560 1.1 skrll /* Entry not found. */
1561 1.1 skrll return NULL;
1562 1.1 skrll
1563 1.1 skrll /* We're out of memory. */
1564 1.1 skrll bfd_set_error (bfd_error_no_memory);
1565 1.1 skrll return NULL;
1566 1.1 skrll }
1567 1.1 skrll
1568 1.1 skrll if (*ptr == NULL)
1569 1.1 skrll /* We didn't find the entry and we're asked to create a new one. */
1570 1.1 skrll {
1571 1.1 skrll BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1572 1.1 skrll
1573 1.1 skrll entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
1574 1.1 skrll if (entry == NULL)
1575 1.1 skrll return NULL;
1576 1.1 skrll
1577 1.1 skrll /* Initialize new entry. */
1578 1.1 skrll entry->key_ = *key;
1579 1.1 skrll
1580 1.1.1.2 christos entry->u.s1.refcount = 0;
1581 1.1.1.2 christos
1582 1.1.1.2 christos /* Mark the entry as not initialized. */
1583 1.1 skrll entry->key_.type = R_68K_max;
1584 1.1 skrll
1585 1.1 skrll *ptr = entry;
1586 1.1 skrll }
1587 1.1 skrll else
1588 1.1 skrll /* We found the entry. */
1589 1.1 skrll {
1590 1.1 skrll BFD_ASSERT (howto != MUST_CREATE);
1591 1.1 skrll
1592 1.1 skrll entry = *ptr;
1593 1.1 skrll }
1594 1.1 skrll
1595 1.1 skrll return entry;
1596 1.1 skrll }
1597 1.1 skrll
1598 1.1 skrll /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1599 1.1 skrll Return the value to which ENTRY's type should be set. */
1600 1.1.1.2 christos
1601 1.1.1.2 christos static enum elf_m68k_reloc_type
1602 1.1.1.2 christos elf_m68k_update_got_entry_type (struct elf_m68k_got *got,
1603 1.1.1.2 christos enum elf_m68k_reloc_type was,
1604 1.1.1.2 christos enum elf_m68k_reloc_type new_reloc)
1605 1.1.1.2 christos {
1606 1.1.1.2 christos enum elf_m68k_got_offset_size was_size;
1607 1.1.1.2 christos enum elf_m68k_got_offset_size new_size;
1608 1.1.1.2 christos bfd_vma n_slots;
1609 1.1.1.2 christos
1610 1.1.1.2 christos if (was == R_68K_max)
1611 1.1 skrll /* The type of the entry is not initialized yet. */
1612 1.1.1.2 christos {
1613 1.1.1.2 christos /* Update all got->n_slots counters, including n_slots[R_32]. */
1614 1.1 skrll was_size = R_LAST;
1615 1.1.1.2 christos
1616 1.1 skrll was = new_reloc;
1617 1.1 skrll }
1618 1.1.1.2 christos else
1619 1.1.1.2 christos {
1620 1.1.1.2 christos /* !!! We, probably, should emit an error rather then fail on assert
1621 1.1.1.2 christos in such a case. */
1622 1.1.1.2 christos BFD_ASSERT (elf_m68k_reloc_got_type (was)
1623 1.1.1.2 christos == elf_m68k_reloc_got_type (new_reloc));
1624 1.1.1.2 christos
1625 1.1.1.2 christos was_size = elf_m68k_reloc_got_offset_size (was);
1626 1.1 skrll }
1627 1.1.1.2 christos
1628 1.1.1.2 christos new_size = elf_m68k_reloc_got_offset_size (new_reloc);
1629 1.1.1.2 christos n_slots = elf_m68k_reloc_got_n_slots (new_reloc);
1630 1.1.1.2 christos
1631 1.1.1.2 christos while (was_size > new_size)
1632 1.1.1.2 christos {
1633 1.1.1.2 christos --was_size;
1634 1.1.1.2 christos got->n_slots[was_size] += n_slots;
1635 1.1.1.2 christos }
1636 1.1.1.2 christos
1637 1.1.1.2 christos if (new_reloc > was)
1638 1.1.1.2 christos /* Relocations are ordered from bigger got offset size to lesser,
1639 1.1.1.2 christos so choose the relocation type with lesser offset size. */
1640 1.1.1.2 christos was = new_reloc;
1641 1.1.1.2 christos
1642 1.1 skrll return was;
1643 1.1 skrll }
1644 1.1 skrll
1645 1.1 skrll /* Update GOT counters when removing an entry of type TYPE. */
1646 1.1 skrll
1647 1.1.1.2 christos static void
1648 1.1.1.2 christos elf_m68k_remove_got_entry_type (struct elf_m68k_got *got,
1649 1.1 skrll enum elf_m68k_reloc_type type)
1650 1.1.1.2 christos {
1651 1.1.1.2 christos enum elf_m68k_got_offset_size os;
1652 1.1 skrll bfd_vma n_slots;
1653 1.1.1.2 christos
1654 1.1 skrll n_slots = elf_m68k_reloc_got_n_slots (type);
1655 1.1.1.2 christos
1656 1.1.1.2 christos /* Decrese counter of slots with offset size corresponding to TYPE
1657 1.1.1.2 christos and all greater offset sizes. */
1658 1.1.1.2 christos for (os = elf_m68k_reloc_got_offset_size (type); os <= R_32; ++os)
1659 1.1.1.2 christos {
1660 1.1 skrll BFD_ASSERT (got->n_slots[os] >= n_slots);
1661 1.1.1.2 christos
1662 1.1 skrll got->n_slots[os] -= n_slots;
1663 1.1 skrll }
1664 1.1 skrll }
1665 1.1 skrll
1666 1.1 skrll /* Add new or update existing entry to GOT.
1667 1.1 skrll H, ABFD, TYPE and SYMNDX is data for the entry.
1668 1.1 skrll INFO is a context where memory should be allocated. */
1669 1.1 skrll
1670 1.1 skrll static struct elf_m68k_got_entry *
1671 1.1 skrll elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
1672 1.1 skrll struct elf_link_hash_entry *h,
1673 1.1.1.2 christos const bfd *abfd,
1674 1.1.1.2 christos enum elf_m68k_reloc_type reloc_type,
1675 1.1 skrll unsigned long symndx,
1676 1.1 skrll struct bfd_link_info *info)
1677 1.1 skrll {
1678 1.1 skrll struct elf_m68k_got_entry_key key_;
1679 1.1 skrll struct elf_m68k_got_entry *entry;
1680 1.1 skrll
1681 1.1 skrll if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
1682 1.1 skrll elf_m68k_hash_entry (h)->got_entry_key
1683 1.1 skrll = elf_m68k_multi_got (info)->global_symndx++;
1684 1.1.1.2 christos
1685 1.1 skrll elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type);
1686 1.1 skrll
1687 1.1 skrll entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
1688 1.1 skrll if (entry == NULL)
1689 1.1 skrll return NULL;
1690 1.1.1.2 christos
1691 1.1.1.2 christos /* Determine entry's type and update got->n_slots counters. */
1692 1.1.1.2 christos entry->key_.type = elf_m68k_update_got_entry_type (got,
1693 1.1.1.2 christos entry->key_.type,
1694 1.1.1.2 christos reloc_type);
1695 1.1 skrll
1696 1.1 skrll /* Update refcount. */
1697 1.1 skrll ++entry->u.s1.refcount;
1698 1.1 skrll
1699 1.1 skrll if (entry->u.s1.refcount == 1)
1700 1.1 skrll /* We see this entry for the first time. */
1701 1.1 skrll {
1702 1.1.1.2 christos if (entry->key_.bfd != NULL)
1703 1.1 skrll got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type);
1704 1.1 skrll }
1705 1.1.1.2 christos
1706 1.1 skrll BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
1707 1.1.1.2 christos
1708 1.1.1.2 christos if ((got->n_slots[R_8]
1709 1.1.1.2 christos > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1710 1.1.1.2 christos || (got->n_slots[R_16]
1711 1.1 skrll > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1712 1.1 skrll /* This BFD has too many relocation. */
1713 1.1.1.2 christos {
1714 1.1 skrll if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1715 1.1.1.2 christos (*_bfd_error_handler) (_("%B: GOT overflow: "
1716 1.1.1.2 christos "Number of relocations with 8-bit "
1717 1.1 skrll "offset > %d"),
1718 1.1.1.2 christos abfd,
1719 1.1 skrll ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info));
1720 1.1 skrll else
1721 1.1.1.2 christos (*_bfd_error_handler) (_("%B: GOT overflow: "
1722 1.1.1.2 christos "Number of relocations with 8- or 16-bit "
1723 1.1 skrll "offset > %d"),
1724 1.1.1.2 christos abfd,
1725 1.1 skrll ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info));
1726 1.1 skrll
1727 1.1 skrll return NULL;
1728 1.1 skrll }
1729 1.1 skrll
1730 1.1 skrll return entry;
1731 1.1 skrll }
1732 1.1 skrll
1733 1.1 skrll /* Compute the hash value of the bfd in a bfd2got hash entry. */
1734 1.1 skrll
1735 1.1 skrll static hashval_t
1736 1.1 skrll elf_m68k_bfd2got_entry_hash (const void *entry)
1737 1.1 skrll {
1738 1.1 skrll const struct elf_m68k_bfd2got_entry *e;
1739 1.1 skrll
1740 1.1 skrll e = (const struct elf_m68k_bfd2got_entry *) entry;
1741 1.1 skrll
1742 1.1 skrll return e->bfd->id;
1743 1.1 skrll }
1744 1.1 skrll
1745 1.1 skrll /* Check whether two hash entries have the same bfd. */
1746 1.1 skrll
1747 1.1 skrll static int
1748 1.1 skrll elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
1749 1.1 skrll {
1750 1.1 skrll const struct elf_m68k_bfd2got_entry *e1;
1751 1.1 skrll const struct elf_m68k_bfd2got_entry *e2;
1752 1.1 skrll
1753 1.1 skrll e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
1754 1.1 skrll e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
1755 1.1 skrll
1756 1.1 skrll return e1->bfd == e2->bfd;
1757 1.1 skrll }
1758 1.1 skrll
1759 1.1 skrll /* Destruct a bfd2got entry. */
1760 1.1 skrll
1761 1.1 skrll static void
1762 1.1 skrll elf_m68k_bfd2got_entry_del (void *_entry)
1763 1.1 skrll {
1764 1.1 skrll struct elf_m68k_bfd2got_entry *entry;
1765 1.1 skrll
1766 1.1 skrll entry = (struct elf_m68k_bfd2got_entry *) _entry;
1767 1.1 skrll
1768 1.1 skrll BFD_ASSERT (entry->got != NULL);
1769 1.1 skrll elf_m68k_clear_got (entry->got);
1770 1.1 skrll }
1771 1.1 skrll
1772 1.1 skrll /* Find existing or create new (depending on HOWTO) bfd2got entry in
1773 1.1 skrll MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1774 1.1 skrll memory should be allocated. */
1775 1.1 skrll
1776 1.1 skrll static struct elf_m68k_bfd2got_entry *
1777 1.1 skrll elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
1778 1.1 skrll const bfd *abfd,
1779 1.1 skrll enum elf_m68k_get_entry_howto howto,
1780 1.1 skrll struct bfd_link_info *info)
1781 1.1 skrll {
1782 1.1 skrll struct elf_m68k_bfd2got_entry entry_;
1783 1.1 skrll void **ptr;
1784 1.1 skrll struct elf_m68k_bfd2got_entry *entry;
1785 1.1 skrll
1786 1.1 skrll BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1787 1.1 skrll
1788 1.1 skrll if (multi_got->bfd2got == NULL)
1789 1.1 skrll /* This is the first GOT. Initialize bfd2got. */
1790 1.1 skrll {
1791 1.1 skrll if (howto == SEARCH)
1792 1.1 skrll return NULL;
1793 1.1 skrll
1794 1.1 skrll multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
1795 1.1 skrll elf_m68k_bfd2got_entry_eq,
1796 1.1 skrll elf_m68k_bfd2got_entry_del);
1797 1.1 skrll if (multi_got->bfd2got == NULL)
1798 1.1 skrll {
1799 1.1 skrll bfd_set_error (bfd_error_no_memory);
1800 1.1 skrll return NULL;
1801 1.1 skrll }
1802 1.1 skrll }
1803 1.1 skrll
1804 1.1 skrll entry_.bfd = abfd;
1805 1.1 skrll ptr = htab_find_slot (multi_got->bfd2got, &entry_, (howto != SEARCH
1806 1.1 skrll ? INSERT : NO_INSERT));
1807 1.1 skrll if (ptr == NULL)
1808 1.1 skrll {
1809 1.1 skrll if (howto == SEARCH)
1810 1.1 skrll /* Entry not found. */
1811 1.1 skrll return NULL;
1812 1.1 skrll
1813 1.1 skrll /* We're out of memory. */
1814 1.1 skrll bfd_set_error (bfd_error_no_memory);
1815 1.1 skrll return NULL;
1816 1.1 skrll }
1817 1.1 skrll
1818 1.1 skrll if (*ptr == NULL)
1819 1.1 skrll /* Entry was not found. Create new one. */
1820 1.1 skrll {
1821 1.1 skrll BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1822 1.1 skrll
1823 1.1 skrll entry = ((struct elf_m68k_bfd2got_entry *)
1824 1.1 skrll bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
1825 1.1 skrll if (entry == NULL)
1826 1.1 skrll return NULL;
1827 1.1 skrll
1828 1.1 skrll entry->bfd = abfd;
1829 1.1 skrll
1830 1.1 skrll entry->got = elf_m68k_create_empty_got (info);
1831 1.1 skrll if (entry->got == NULL)
1832 1.1 skrll return NULL;
1833 1.1 skrll
1834 1.1 skrll *ptr = entry;
1835 1.1 skrll }
1836 1.1 skrll else
1837 1.1 skrll {
1838 1.1 skrll BFD_ASSERT (howto != MUST_CREATE);
1839 1.1 skrll
1840 1.1 skrll /* Return existing entry. */
1841 1.1 skrll entry = *ptr;
1842 1.1 skrll }
1843 1.1 skrll
1844 1.1 skrll return entry;
1845 1.1 skrll }
1846 1.1 skrll
1847 1.1 skrll struct elf_m68k_can_merge_gots_arg
1848 1.1 skrll {
1849 1.1 skrll /* A current_got that we constructing a DIFF against. */
1850 1.1 skrll struct elf_m68k_got *big;
1851 1.1 skrll
1852 1.1 skrll /* GOT holding entries not present or that should be changed in
1853 1.1 skrll BIG. */
1854 1.1 skrll struct elf_m68k_got *diff;
1855 1.1 skrll
1856 1.1 skrll /* Context where to allocate memory. */
1857 1.1 skrll struct bfd_link_info *info;
1858 1.1 skrll
1859 1.1 skrll /* Error flag. */
1860 1.1 skrll bfd_boolean error_p;
1861 1.1 skrll };
1862 1.1 skrll
1863 1.1 skrll /* Process a single entry from the small GOT to see if it should be added
1864 1.1 skrll or updated in the big GOT. */
1865 1.1 skrll
1866 1.1 skrll static int
1867 1.1 skrll elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
1868 1.1 skrll {
1869 1.1 skrll const struct elf_m68k_got_entry *entry1;
1870 1.1 skrll struct elf_m68k_can_merge_gots_arg *arg;
1871 1.1.1.2 christos const struct elf_m68k_got_entry *entry2;
1872 1.1 skrll enum elf_m68k_reloc_type type;
1873 1.1 skrll
1874 1.1 skrll entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
1875 1.1 skrll arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
1876 1.1 skrll
1877 1.1 skrll entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
1878 1.1 skrll
1879 1.1.1.2 christos if (entry2 != NULL)
1880 1.1 skrll /* We found an existing entry. Check if we should update it. */
1881 1.1.1.2 christos {
1882 1.1.1.2 christos type = elf_m68k_update_got_entry_type (arg->diff,
1883 1.1.1.2 christos entry2->key_.type,
1884 1.1 skrll entry1->key_.type);
1885 1.1.1.2 christos
1886 1.1 skrll if (type == entry2->key_.type)
1887 1.1 skrll /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1888 1.1 skrll To skip creation of difference entry we use the type,
1889 1.1.1.2 christos which we won't see in GOT entries for sure. */
1890 1.1 skrll type = R_68K_max;
1891 1.1 skrll }
1892 1.1.1.2 christos else
1893 1.1 skrll /* We didn't find the entry. Add entry1 to DIFF. */
1894 1.1.1.2 christos {
1895 1.1 skrll BFD_ASSERT (entry1->key_.type != R_68K_max);
1896 1.1.1.2 christos
1897 1.1.1.2 christos type = elf_m68k_update_got_entry_type (arg->diff,
1898 1.1 skrll R_68K_max, entry1->key_.type);
1899 1.1 skrll
1900 1.1.1.2 christos if (entry1->key_.bfd != NULL)
1901 1.1 skrll arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type);
1902 1.1 skrll }
1903 1.1.1.2 christos
1904 1.1 skrll if (type != R_68K_max)
1905 1.1 skrll /* Create an entry in DIFF. */
1906 1.1 skrll {
1907 1.1 skrll struct elf_m68k_got_entry *entry;
1908 1.1 skrll
1909 1.1 skrll entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
1910 1.1 skrll arg->info);
1911 1.1 skrll if (entry == NULL)
1912 1.1 skrll {
1913 1.1 skrll arg->error_p = TRUE;
1914 1.1 skrll return 0;
1915 1.1 skrll }
1916 1.1.1.2 christos
1917 1.1 skrll entry->key_.type = type;
1918 1.1 skrll }
1919 1.1 skrll
1920 1.1 skrll return 1;
1921 1.1 skrll }
1922 1.1 skrll
1923 1.1 skrll /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1924 1.1 skrll Construct DIFF GOT holding the entries which should be added or updated
1925 1.1 skrll in BIG GOT to accumulate information from SMALL.
1926 1.1 skrll INFO is the context where memory should be allocated. */
1927 1.1 skrll
1928 1.1 skrll static bfd_boolean
1929 1.1 skrll elf_m68k_can_merge_gots (struct elf_m68k_got *big,
1930 1.1 skrll const struct elf_m68k_got *small,
1931 1.1 skrll struct bfd_link_info *info,
1932 1.1 skrll struct elf_m68k_got *diff)
1933 1.1 skrll {
1934 1.1 skrll struct elf_m68k_can_merge_gots_arg arg_;
1935 1.1 skrll
1936 1.1 skrll BFD_ASSERT (small->offset == (bfd_vma) -1);
1937 1.1 skrll
1938 1.1 skrll arg_.big = big;
1939 1.1 skrll arg_.diff = diff;
1940 1.1 skrll arg_.info = info;
1941 1.1 skrll arg_.error_p = FALSE;
1942 1.1 skrll htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
1943 1.1 skrll if (arg_.error_p)
1944 1.1 skrll {
1945 1.1 skrll diff->offset = 0;
1946 1.1 skrll return FALSE;
1947 1.1 skrll }
1948 1.1 skrll
1949 1.1.1.2 christos /* Check for overflow. */
1950 1.1.1.2 christos if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8]
1951 1.1.1.2 christos > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1952 1.1.1.2 christos || (big->n_slots[R_16] + arg_.diff->n_slots[R_16]
1953 1.1 skrll > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1954 1.1 skrll return FALSE;
1955 1.1 skrll
1956 1.1 skrll return TRUE;
1957 1.1 skrll }
1958 1.1 skrll
1959 1.1 skrll struct elf_m68k_merge_gots_arg
1960 1.1 skrll {
1961 1.1 skrll /* The BIG got. */
1962 1.1 skrll struct elf_m68k_got *big;
1963 1.1 skrll
1964 1.1 skrll /* Context where memory should be allocated. */
1965 1.1 skrll struct bfd_link_info *info;
1966 1.1 skrll
1967 1.1 skrll /* Error flag. */
1968 1.1 skrll bfd_boolean error_p;
1969 1.1 skrll };
1970 1.1 skrll
1971 1.1 skrll /* Process a single entry from DIFF got. Add or update corresponding
1972 1.1 skrll entry in the BIG got. */
1973 1.1 skrll
1974 1.1 skrll static int
1975 1.1 skrll elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
1976 1.1 skrll {
1977 1.1 skrll const struct elf_m68k_got_entry *from;
1978 1.1 skrll struct elf_m68k_merge_gots_arg *arg;
1979 1.1 skrll struct elf_m68k_got_entry *to;
1980 1.1 skrll
1981 1.1 skrll from = (const struct elf_m68k_got_entry *) *entry_ptr;
1982 1.1 skrll arg = (struct elf_m68k_merge_gots_arg *) _arg;
1983 1.1 skrll
1984 1.1 skrll to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
1985 1.1 skrll arg->info);
1986 1.1 skrll if (to == NULL)
1987 1.1 skrll {
1988 1.1 skrll arg->error_p = TRUE;
1989 1.1 skrll return 0;
1990 1.1 skrll }
1991 1.1 skrll
1992 1.1 skrll BFD_ASSERT (to->u.s1.refcount == 0);
1993 1.1.1.2 christos /* All we need to merge is TYPE. */
1994 1.1 skrll to->key_.type = from->key_.type;
1995 1.1 skrll
1996 1.1 skrll return 1;
1997 1.1 skrll }
1998 1.1 skrll
1999 1.1 skrll /* Merge data from DIFF to BIG. INFO is context where memory should be
2000 1.1 skrll allocated. */
2001 1.1 skrll
2002 1.1 skrll static bfd_boolean
2003 1.1 skrll elf_m68k_merge_gots (struct elf_m68k_got *big,
2004 1.1 skrll struct elf_m68k_got *diff,
2005 1.1 skrll struct bfd_link_info *info)
2006 1.1 skrll {
2007 1.1 skrll if (diff->entries != NULL)
2008 1.1 skrll /* DIFF is not empty. Merge it into BIG GOT. */
2009 1.1 skrll {
2010 1.1 skrll struct elf_m68k_merge_gots_arg arg_;
2011 1.1 skrll
2012 1.1 skrll /* Merge entries. */
2013 1.1 skrll arg_.big = big;
2014 1.1 skrll arg_.info = info;
2015 1.1 skrll arg_.error_p = FALSE;
2016 1.1 skrll htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
2017 1.1 skrll if (arg_.error_p)
2018 1.1 skrll return FALSE;
2019 1.1 skrll
2020 1.1.1.2 christos /* Merge counters. */
2021 1.1.1.2 christos big->n_slots[R_8] += diff->n_slots[R_8];
2022 1.1.1.2 christos big->n_slots[R_16] += diff->n_slots[R_16];
2023 1.1.1.2 christos big->n_slots[R_32] += diff->n_slots[R_32];
2024 1.1 skrll big->local_n_slots += diff->local_n_slots;
2025 1.1 skrll }
2026 1.1 skrll else
2027 1.1 skrll /* DIFF is empty. */
2028 1.1.1.2 christos {
2029 1.1.1.2 christos BFD_ASSERT (diff->n_slots[R_8] == 0);
2030 1.1.1.2 christos BFD_ASSERT (diff->n_slots[R_16] == 0);
2031 1.1.1.2 christos BFD_ASSERT (diff->n_slots[R_32] == 0);
2032 1.1 skrll BFD_ASSERT (diff->local_n_slots == 0);
2033 1.1 skrll }
2034 1.1 skrll
2035 1.1.1.2 christos BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
2036 1.1.1.2 christos || ((big->n_slots[R_8]
2037 1.1.1.2 christos <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
2038 1.1.1.2 christos && (big->n_slots[R_16]
2039 1.1 skrll <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))));
2040 1.1 skrll
2041 1.1 skrll return TRUE;
2042 1.1 skrll }
2043 1.1 skrll
2044 1.1 skrll struct elf_m68k_finalize_got_offsets_arg
2045 1.1.1.2 christos {
2046 1.1.1.2 christos /* Ranges of the offsets for GOT entries.
2047 1.1.1.2 christos R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2048 1.1.1.2 christos R_x is R_8, R_16 and R_32. */
2049 1.1.1.2 christos bfd_vma *offset1;
2050 1.1 skrll bfd_vma *offset2;
2051 1.1 skrll
2052 1.1 skrll /* Mapping from global symndx to global symbols.
2053 1.1 skrll This is used to build lists of got entries for global symbols. */
2054 1.1.1.2 christos struct elf_m68k_link_hash_entry **symndx2h;
2055 1.1.1.2 christos
2056 1.1 skrll bfd_vma n_ldm_entries;
2057 1.1 skrll };
2058 1.1 skrll
2059 1.1 skrll /* Assign ENTRY an offset. Build list of GOT entries for global symbols
2060 1.1 skrll along the way. */
2061 1.1 skrll
2062 1.1 skrll static int
2063 1.1 skrll elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
2064 1.1 skrll {
2065 1.1 skrll struct elf_m68k_got_entry *entry;
2066 1.1 skrll struct elf_m68k_finalize_got_offsets_arg *arg;
2067 1.1.1.2 christos
2068 1.1.1.2 christos enum elf_m68k_got_offset_size got_offset_size;
2069 1.1.1.2 christos bfd_vma entry_size;
2070 1.1 skrll
2071 1.1 skrll entry = (struct elf_m68k_got_entry *) *entry_ptr;
2072 1.1 skrll arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
2073 1.1 skrll
2074 1.1 skrll /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2075 1.1 skrll BFD_ASSERT (entry->u.s1.refcount == 0);
2076 1.1.1.2 christos
2077 1.1.1.2 christos /* Get GOT offset size for the entry . */
2078 1.1 skrll got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type);
2079 1.1.1.2 christos
2080 1.1.1.2 christos /* Calculate entry size in bytes. */
2081 1.1 skrll entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type);
2082 1.1.1.2 christos
2083 1.1.1.2 christos /* Check if we should switch to negative range of the offsets. */
2084 1.1.1.2 christos if (arg->offset1[got_offset_size] + entry_size
2085 1.1.1.2 christos > arg->offset2[got_offset_size])
2086 1.1.1.2 christos {
2087 1.1.1.2 christos /* Verify that this is the only switch to negative range for
2088 1.1.1.2 christos got_offset_size. If this assertion fails, then we've miscalculated
2089 1.1.1.2 christos range for got_offset_size entries in
2090 1.1.1.2 christos elf_m68k_finalize_got_offsets. */
2091 1.1.1.2 christos BFD_ASSERT (arg->offset2[got_offset_size]
2092 1.1.1.2 christos != arg->offset2[-(int) got_offset_size - 1]);
2093 1.1.1.2 christos
2094 1.1.1.2 christos /* Switch. */
2095 1.1.1.2 christos arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1];
2096 1.1.1.2 christos arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1];
2097 1.1.1.2 christos
2098 1.1.1.2 christos /* Verify that now we have enough room for the entry. */
2099 1.1.1.2 christos BFD_ASSERT (arg->offset1[got_offset_size] + entry_size
2100 1.1.1.2 christos <= arg->offset2[got_offset_size]);
2101 1.1.1.2 christos }
2102 1.1.1.2 christos
2103 1.1.1.2 christos /* Assign offset to entry. */
2104 1.1.1.2 christos entry->u.s2.offset = arg->offset1[got_offset_size];
2105 1.1 skrll arg->offset1[got_offset_size] += entry_size;
2106 1.1 skrll
2107 1.1 skrll if (entry->key_.bfd == NULL)
2108 1.1 skrll /* Hook up this entry into the list of got_entries of H. */
2109 1.1 skrll {
2110 1.1 skrll struct elf_m68k_link_hash_entry *h;
2111 1.1 skrll
2112 1.1.1.2 christos h = arg->symndx2h[entry->key_.symndx];
2113 1.1.1.2 christos if (h != NULL)
2114 1.1.1.2 christos {
2115 1.1.1.2 christos entry->u.s2.next = h->glist;
2116 1.1.1.2 christos h->glist = entry;
2117 1.1.1.2 christos }
2118 1.1.1.2 christos else
2119 1.1.1.2 christos /* This should be the entry for TLS_LDM relocation then. */
2120 1.1.1.2 christos {
2121 1.1.1.2 christos BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type)
2122 1.1.1.2 christos == R_68K_TLS_LDM32)
2123 1.1 skrll && entry->key_.symndx == 0);
2124 1.1.1.2 christos
2125 1.1.1.2 christos ++arg->n_ldm_entries;
2126 1.1 skrll }
2127 1.1 skrll }
2128 1.1 skrll else
2129 1.1 skrll /* This entry is for local symbol. */
2130 1.1 skrll entry->u.s2.next = NULL;
2131 1.1 skrll
2132 1.1 skrll return 1;
2133 1.1 skrll }
2134 1.1 skrll
2135 1.1 skrll /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2136 1.1 skrll should use negative offsets.
2137 1.1 skrll Build list of GOT entries for global symbols along the way.
2138 1.1.1.2 christos SYMNDX2H is mapping from global symbol indices to actual
2139 1.1.1.2 christos global symbols.
2140 1.1 skrll Return offset at which next GOT should start. */
2141 1.1 skrll
2142 1.1 skrll static void
2143 1.1 skrll elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
2144 1.1.1.2 christos bfd_boolean use_neg_got_offsets_p,
2145 1.1.1.2 christos struct elf_m68k_link_hash_entry **symndx2h,
2146 1.1 skrll bfd_vma *final_offset, bfd_vma *n_ldm_entries)
2147 1.1 skrll {
2148 1.1.1.2 christos struct elf_m68k_finalize_got_offsets_arg arg_;
2149 1.1.1.2 christos bfd_vma offset1_[2 * R_LAST];
2150 1.1.1.2 christos bfd_vma offset2_[2 * R_LAST];
2151 1.1.1.2 christos int i;
2152 1.1 skrll bfd_vma start_offset;
2153 1.1 skrll
2154 1.1 skrll BFD_ASSERT (got->offset != (bfd_vma) -1);
2155 1.1 skrll
2156 1.1 skrll /* We set entry offsets relative to the .got section (and not the
2157 1.1.1.2 christos start of a particular GOT), so that we can use them in
2158 1.1 skrll finish_dynamic_symbol without needing to know the GOT which they come
2159 1.1 skrll from. */
2160 1.1.1.2 christos
2161 1.1.1.2 christos /* Put offset1 in the middle of offset1_, same for offset2. */
2162 1.1.1.2 christos arg_.offset1 = offset1_ + R_LAST;
2163 1.1.1.2 christos arg_.offset2 = offset2_ + R_LAST;
2164 1.1.1.2 christos
2165 1.1.1.2 christos start_offset = got->offset;
2166 1.1 skrll
2167 1.1.1.2 christos if (use_neg_got_offsets_p)
2168 1.1.1.2 christos /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2169 1.1.1.2 christos i = -(int) R_32 - 1;
2170 1.1.1.2 christos else
2171 1.1.1.2 christos /* Setup positives ranges for R_8, R_16 and R_32. */
2172 1.1.1.2 christos i = (int) R_8;
2173 1.1.1.2 christos
2174 1.1 skrll for (; i <= (int) R_32; ++i)
2175 1.1.1.2 christos {
2176 1.1 skrll int j;
2177 1.1 skrll size_t n;
2178 1.1.1.2 christos
2179 1.1.1.2 christos /* Set beginning of the range of offsets I. */
2180 1.1 skrll arg_.offset1[i] = start_offset;
2181 1.1.1.2 christos
2182 1.1.1.2 christos /* Calculate number of slots that require I offsets. */
2183 1.1.1.2 christos j = (i >= 0) ? i : -i - 1;
2184 1.1.1.2 christos n = (j >= 1) ? got->n_slots[j - 1] : 0;
2185 1.1.1.2 christos n = got->n_slots[j] - n;
2186 1.1.1.2 christos
2187 1.1.1.2 christos if (use_neg_got_offsets_p && n != 0)
2188 1.1.1.2 christos {
2189 1.1.1.2 christos if (i < 0)
2190 1.1.1.2 christos /* We first fill the positive side of the range, so we might
2191 1.1.1.2 christos end up with one empty slot at that side when we can't fit
2192 1.1.1.2 christos whole 2-slot entry. Account for that at negative side of
2193 1.1.1.2 christos the interval with one additional entry. */
2194 1.1.1.2 christos n = n / 2 + 1;
2195 1.1.1.2 christos else
2196 1.1.1.2 christos /* When the number of slots is odd, make positive side of the
2197 1.1.1.2 christos range one entry bigger. */
2198 1.1.1.2 christos n = (n + 1) / 2;
2199 1.1 skrll }
2200 1.1.1.2 christos
2201 1.1.1.2 christos /* N is the number of slots that require I offsets.
2202 1.1.1.2 christos Calculate length of the range for I offsets. */
2203 1.1 skrll n = 4 * n;
2204 1.1.1.2 christos
2205 1.1.1.2 christos /* Set end of the range. */
2206 1.1 skrll arg_.offset2[i] = start_offset + n;
2207 1.1.1.2 christos
2208 1.1 skrll start_offset = arg_.offset2[i];
2209 1.1 skrll }
2210 1.1.1.2 christos
2211 1.1.1.2 christos if (!use_neg_got_offsets_p)
2212 1.1.1.2 christos /* Make sure that if we try to switch to negative offsets in
2213 1.1.1.2 christos elf_m68k_finalize_got_offsets_1, the assert therein will catch
2214 1.1.1.2 christos the bug. */
2215 1.1.1.2 christos for (i = R_8; i <= R_32; ++i)
2216 1.1 skrll arg_.offset2[-i - 1] = arg_.offset2[i];
2217 1.1.1.2 christos
2218 1.1.1.2 christos /* Setup got->offset. offset1[R_8] is either in the middle or at the
2219 1.1.1.2 christos beginning of GOT depending on use_neg_got_offsets_p. */
2220 1.1 skrll got->offset = arg_.offset1[R_8];
2221 1.1 skrll
2222 1.1.1.2 christos arg_.symndx2h = symndx2h;
2223 1.1 skrll arg_.n_ldm_entries = 0;
2224 1.1.1.2 christos
2225 1.1 skrll /* Assign offsets. */
2226 1.1 skrll htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
2227 1.1.1.2 christos
2228 1.1.1.2 christos /* Check offset ranges we have actually assigned. */
2229 1.1.1.2 christos for (i = (int) R_8; i <= (int) R_32; ++i)
2230 1.1 skrll BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4);
2231 1.1.1.2 christos
2232 1.1.1.2 christos *final_offset = start_offset;
2233 1.1 skrll *n_ldm_entries = arg_.n_ldm_entries;
2234 1.1 skrll }
2235 1.1 skrll
2236 1.1 skrll struct elf_m68k_partition_multi_got_arg
2237 1.1 skrll {
2238 1.1 skrll /* The GOT we are adding entries to. Aka big got. */
2239 1.1 skrll struct elf_m68k_got *current_got;
2240 1.1 skrll
2241 1.1 skrll /* Offset to assign the next CURRENT_GOT. */
2242 1.1 skrll bfd_vma offset;
2243 1.1 skrll
2244 1.1 skrll /* Context where memory should be allocated. */
2245 1.1 skrll struct bfd_link_info *info;
2246 1.1.1.2 christos
2247 1.1 skrll /* Total number of slots in the .got section.
2248 1.1.1.2 christos This is used to calculate size of the .got and .rela.got sections. */
2249 1.1 skrll bfd_vma n_slots;
2250 1.1.1.2 christos
2251 1.1.1.2 christos /* Difference in numbers of allocated slots in the .got section
2252 1.1 skrll and necessary relocations in the .rela.got section.
2253 1.1.1.2 christos This is used to calculate size of the .rela.got section. */
2254 1.1 skrll bfd_vma slots_relas_diff;
2255 1.1 skrll
2256 1.1 skrll /* Error flag. */
2257 1.1 skrll bfd_boolean error_p;
2258 1.1 skrll
2259 1.1 skrll /* Mapping from global symndx to global symbols.
2260 1.1 skrll This is used to build lists of got entries for global symbols. */
2261 1.1 skrll struct elf_m68k_link_hash_entry **symndx2h;
2262 1.1 skrll };
2263 1.1.1.2 christos
2264 1.1.1.2 christos static void
2265 1.1.1.2 christos elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg)
2266 1.1.1.2 christos {
2267 1.1.1.2 christos bfd_vma n_ldm_entries;
2268 1.1.1.2 christos
2269 1.1.1.2 christos elf_m68k_finalize_got_offsets (arg->current_got,
2270 1.1.1.2 christos (elf_m68k_hash_table (arg->info)
2271 1.1.1.2 christos ->use_neg_got_offsets_p),
2272 1.1.1.2 christos arg->symndx2h,
2273 1.1.1.2 christos &arg->offset, &n_ldm_entries);
2274 1.1.1.2 christos
2275 1.1.1.2 christos arg->n_slots += arg->current_got->n_slots[R_32];
2276 1.1.1.2 christos
2277 1.1.1.2 christos if (!arg->info->shared)
2278 1.1.1.2 christos /* If we are generating a shared object, we need to
2279 1.1.1.2 christos output a R_68K_RELATIVE reloc so that the dynamic
2280 1.1.1.2 christos linker can adjust this GOT entry. Overwise we
2281 1.1.1.2 christos don't need space in .rela.got for local symbols. */
2282 1.1.1.2 christos arg->slots_relas_diff += arg->current_got->local_n_slots;
2283 1.1.1.2 christos
2284 1.1.1.2 christos /* @LDM relocations require a 2-slot GOT entry, but only
2285 1.1.1.2 christos one relocation. Account for that. */
2286 1.1.1.2 christos arg->slots_relas_diff += n_ldm_entries;
2287 1.1.1.2 christos
2288 1.1.1.2 christos BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots);
2289 1.1.1.2 christos }
2290 1.1.1.2 christos
2291 1.1 skrll
2292 1.1 skrll /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2293 1.1 skrll or start a new CURRENT_GOT. */
2294 1.1 skrll
2295 1.1 skrll static int
2296 1.1 skrll elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
2297 1.1 skrll {
2298 1.1 skrll struct elf_m68k_bfd2got_entry *entry;
2299 1.1 skrll struct elf_m68k_partition_multi_got_arg *arg;
2300 1.1 skrll struct elf_m68k_got *got;
2301 1.1 skrll struct elf_m68k_got diff_;
2302 1.1 skrll struct elf_m68k_got *diff;
2303 1.1 skrll
2304 1.1 skrll entry = (struct elf_m68k_bfd2got_entry *) *_entry;
2305 1.1 skrll arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2306 1.1 skrll
2307 1.1 skrll got = entry->got;
2308 1.1 skrll BFD_ASSERT (got != NULL);
2309 1.1 skrll BFD_ASSERT (got->offset == (bfd_vma) -1);
2310 1.1 skrll
2311 1.1 skrll diff = NULL;
2312 1.1 skrll
2313 1.1 skrll if (arg->current_got != NULL)
2314 1.1 skrll /* Construct diff. */
2315 1.1 skrll {
2316 1.1.1.2 christos diff = &diff_;
2317 1.1 skrll elf_m68k_init_got (diff);
2318 1.1 skrll
2319 1.1 skrll if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
2320 1.1 skrll {
2321 1.1 skrll if (diff->offset == 0)
2322 1.1 skrll /* Offset set to 0 in the diff_ indicates an error. */
2323 1.1 skrll {
2324 1.1 skrll arg->error_p = TRUE;
2325 1.1 skrll goto final_return;
2326 1.1 skrll }
2327 1.1 skrll
2328 1.1 skrll if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
2329 1.1 skrll {
2330 1.1.1.2 christos elf_m68k_clear_got (diff);
2331 1.1 skrll /* Schedule to finish up current_got and start new one. */
2332 1.1 skrll diff = NULL;
2333 1.1 skrll }
2334 1.1 skrll /* else
2335 1.1 skrll Merge GOTs no matter what. If big GOT overflows,
2336 1.1 skrll we'll fail in relocate_section due to truncated relocations.
2337 1.1 skrll
2338 1.1 skrll ??? May be fail earlier? E.g., in can_merge_gots. */
2339 1.1 skrll }
2340 1.1 skrll }
2341 1.1 skrll else
2342 1.1 skrll /* Diff of got against empty current_got is got itself. */
2343 1.1.1.2 christos {
2344 1.1 skrll /* Create empty current_got to put subsequent GOTs to. */
2345 1.1 skrll arg->current_got = elf_m68k_create_empty_got (arg->info);
2346 1.1 skrll if (arg->current_got == NULL)
2347 1.1 skrll {
2348 1.1 skrll arg->error_p = TRUE;
2349 1.1 skrll goto final_return;
2350 1.1 skrll }
2351 1.1 skrll
2352 1.1 skrll arg->current_got->offset = arg->offset;
2353 1.1 skrll
2354 1.1 skrll diff = got;
2355 1.1 skrll }
2356 1.1 skrll
2357 1.1 skrll if (diff != NULL)
2358 1.1.1.2 christos {
2359 1.1 skrll if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info))
2360 1.1 skrll {
2361 1.1 skrll arg->error_p = TRUE;
2362 1.1 skrll goto final_return;
2363 1.1 skrll }
2364 1.1 skrll
2365 1.1 skrll /* Now we can free GOT. */
2366 1.1 skrll elf_m68k_clear_got (got);
2367 1.1.1.2 christos
2368 1.1 skrll entry->got = arg->current_got;
2369 1.1 skrll }
2370 1.1 skrll else
2371 1.1 skrll {
2372 1.1.1.2 christos /* Finish up current_got. */
2373 1.1 skrll elf_m68k_partition_multi_got_2 (arg);
2374 1.1.1.2 christos
2375 1.1.1.2 christos /* Schedule to start a new current_got. */
2376 1.1 skrll arg->current_got = NULL;
2377 1.1 skrll
2378 1.1 skrll /* Retry. */
2379 1.1 skrll if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
2380 1.1 skrll {
2381 1.1 skrll BFD_ASSERT (arg->error_p);
2382 1.1 skrll goto final_return;
2383 1.1 skrll }
2384 1.1 skrll }
2385 1.1 skrll
2386 1.1 skrll final_return:
2387 1.1 skrll if (diff != NULL)
2388 1.1 skrll elf_m68k_clear_got (diff);
2389 1.1 skrll
2390 1.1 skrll return arg->error_p == FALSE ? 1 : 0;
2391 1.1 skrll }
2392 1.1 skrll
2393 1.1 skrll /* Helper function to build symndx2h mapping. */
2394 1.1 skrll
2395 1.1 skrll static bfd_boolean
2396 1.1 skrll elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
2397 1.1 skrll void *_arg)
2398 1.1 skrll {
2399 1.1 skrll struct elf_m68k_link_hash_entry *h;
2400 1.1 skrll
2401 1.1 skrll h = elf_m68k_hash_entry (_h);
2402 1.1 skrll
2403 1.1 skrll if (h->got_entry_key != 0)
2404 1.1 skrll /* H has at least one entry in the GOT. */
2405 1.1 skrll {
2406 1.1 skrll struct elf_m68k_partition_multi_got_arg *arg;
2407 1.1 skrll
2408 1.1 skrll arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2409 1.1 skrll
2410 1.1 skrll BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
2411 1.1 skrll arg->symndx2h[h->got_entry_key] = h;
2412 1.1 skrll }
2413 1.1 skrll
2414 1.1 skrll return TRUE;
2415 1.1 skrll }
2416 1.1 skrll
2417 1.1 skrll /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2418 1.1 skrll lists of GOT entries for global symbols.
2419 1.1 skrll Calculate sizes of .got and .rela.got sections. */
2420 1.1 skrll
2421 1.1 skrll static bfd_boolean
2422 1.1 skrll elf_m68k_partition_multi_got (struct bfd_link_info *info)
2423 1.1 skrll {
2424 1.1 skrll struct elf_m68k_multi_got *multi_got;
2425 1.1 skrll struct elf_m68k_partition_multi_got_arg arg_;
2426 1.1 skrll
2427 1.1 skrll multi_got = elf_m68k_multi_got (info);
2428 1.1 skrll
2429 1.1 skrll arg_.current_got = NULL;
2430 1.1 skrll arg_.offset = 0;
2431 1.1.1.2 christos arg_.info = info;
2432 1.1.1.2 christos arg_.n_slots = 0;
2433 1.1 skrll arg_.slots_relas_diff = 0;
2434 1.1 skrll arg_.error_p = FALSE;
2435 1.1 skrll
2436 1.1 skrll if (multi_got->bfd2got != NULL)
2437 1.1 skrll {
2438 1.1 skrll /* Initialize symndx2h mapping. */
2439 1.1 skrll {
2440 1.1 skrll arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
2441 1.1 skrll * sizeof (*arg_.symndx2h));
2442 1.1 skrll if (arg_.symndx2h == NULL)
2443 1.1 skrll return FALSE;
2444 1.1 skrll
2445 1.1 skrll elf_link_hash_traverse (elf_hash_table (info),
2446 1.1 skrll elf_m68k_init_symndx2h_1, &arg_);
2447 1.1 skrll }
2448 1.1 skrll
2449 1.1 skrll /* Partition. */
2450 1.1 skrll htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
2451 1.1 skrll &arg_);
2452 1.1 skrll if (arg_.error_p)
2453 1.1 skrll {
2454 1.1 skrll free (arg_.symndx2h);
2455 1.1 skrll arg_.symndx2h = NULL;
2456 1.1 skrll
2457 1.1 skrll return FALSE;
2458 1.1 skrll }
2459 1.1 skrll
2460 1.1.1.2 christos /* Finish up last current_got. */
2461 1.1 skrll elf_m68k_partition_multi_got_2 (&arg_);
2462 1.1 skrll
2463 1.1 skrll free (arg_.symndx2h);
2464 1.1 skrll }
2465 1.1 skrll
2466 1.1 skrll if (elf_hash_table (info)->dynobj != NULL)
2467 1.1 skrll /* Set sizes of .got and .rela.got sections. */
2468 1.1 skrll {
2469 1.1 skrll asection *s;
2470 1.1 skrll
2471 1.1 skrll s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".got");
2472 1.1.1.2 christos if (s != NULL)
2473 1.1 skrll s->size = arg_.offset;
2474 1.1.1.2 christos else
2475 1.1 skrll BFD_ASSERT (arg_.offset == 0);
2476 1.1.1.2 christos
2477 1.1.1.2 christos BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots);
2478 1.1 skrll arg_.n_slots -= arg_.slots_relas_diff;
2479 1.1 skrll
2480 1.1 skrll s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".rela.got");
2481 1.1.1.2 christos if (s != NULL)
2482 1.1 skrll s->size = arg_.n_slots * sizeof (Elf32_External_Rela);
2483 1.1.1.2 christos else
2484 1.1 skrll BFD_ASSERT (arg_.n_slots == 0);
2485 1.1 skrll }
2486 1.1 skrll else
2487 1.1 skrll BFD_ASSERT (multi_got->bfd2got == NULL);
2488 1.1 skrll
2489 1.1 skrll return TRUE;
2490 1.1 skrll }
2491 1.1 skrll
2492 1.1 skrll /* Specialized version of elf_m68k_get_got_entry that returns pointer
2493 1.1 skrll to hashtable slot, thus allowing removal of entry via
2494 1.1 skrll elf_m68k_remove_got_entry. */
2495 1.1 skrll
2496 1.1 skrll static struct elf_m68k_got_entry **
2497 1.1 skrll elf_m68k_find_got_entry_ptr (struct elf_m68k_got *got,
2498 1.1 skrll struct elf_m68k_got_entry_key *key)
2499 1.1 skrll {
2500 1.1 skrll void **ptr;
2501 1.1 skrll struct elf_m68k_got_entry entry_;
2502 1.1 skrll struct elf_m68k_got_entry **entry_ptr;
2503 1.1 skrll
2504 1.1 skrll entry_.key_ = *key;
2505 1.1 skrll ptr = htab_find_slot (got->entries, &entry_, NO_INSERT);
2506 1.1 skrll BFD_ASSERT (ptr != NULL);
2507 1.1 skrll
2508 1.1 skrll entry_ptr = (struct elf_m68k_got_entry **) ptr;
2509 1.1 skrll
2510 1.1 skrll return entry_ptr;
2511 1.1 skrll }
2512 1.1 skrll
2513 1.1 skrll /* Remove entry pointed to by ENTRY_PTR from GOT. */
2514 1.1 skrll
2515 1.1 skrll static void
2516 1.1 skrll elf_m68k_remove_got_entry (struct elf_m68k_got *got,
2517 1.1 skrll struct elf_m68k_got_entry **entry_ptr)
2518 1.1 skrll {
2519 1.1 skrll struct elf_m68k_got_entry *entry;
2520 1.1 skrll
2521 1.1 skrll entry = *entry_ptr;
2522 1.1 skrll
2523 1.1 skrll /* Check that offsets have not been finalized yet. */
2524 1.1 skrll BFD_ASSERT (got->offset == (bfd_vma) -1);
2525 1.1 skrll /* Check that this entry is indeed unused. */
2526 1.1 skrll BFD_ASSERT (entry->u.s1.refcount == 0);
2527 1.1.1.2 christos
2528 1.1 skrll elf_m68k_remove_got_entry_type (got, entry->key_.type);
2529 1.1 skrll
2530 1.1.1.2 christos if (entry->key_.bfd != NULL)
2531 1.1.1.2 christos got->local_n_slots -= elf_m68k_reloc_got_n_slots (entry->key_.type);
2532 1.1.1.2 christos
2533 1.1 skrll BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
2534 1.1 skrll
2535 1.1 skrll htab_clear_slot (got->entries, (void **) entry_ptr);
2536 1.1 skrll }
2537 1.1 skrll
2538 1.1 skrll /* Copy any information related to dynamic linking from a pre-existing
2539 1.1 skrll symbol to a newly created symbol. Also called to copy flags and
2540 1.1 skrll other back-end info to a weakdef, in which case the symbol is not
2541 1.1 skrll newly created and plt/got refcounts and dynamic indices should not
2542 1.1 skrll be copied. */
2543 1.1 skrll
2544 1.1 skrll static void
2545 1.1 skrll elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
2546 1.1 skrll struct elf_link_hash_entry *_dir,
2547 1.1 skrll struct elf_link_hash_entry *_ind)
2548 1.1 skrll {
2549 1.1 skrll struct elf_m68k_link_hash_entry *dir;
2550 1.1 skrll struct elf_m68k_link_hash_entry *ind;
2551 1.1 skrll
2552 1.1 skrll _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
2553 1.1 skrll
2554 1.1 skrll if (_ind->root.type != bfd_link_hash_indirect)
2555 1.1 skrll return;
2556 1.1 skrll
2557 1.1 skrll dir = elf_m68k_hash_entry (_dir);
2558 1.1 skrll ind = elf_m68k_hash_entry (_ind);
2559 1.1.1.2 christos
2560 1.1.1.2 christos /* Any absolute non-dynamic relocations against an indirect or weak
2561 1.1.1.2 christos definition will be against the target symbol. */
2562 1.1.1.2 christos _dir->non_got_ref |= _ind->non_got_ref;
2563 1.1 skrll
2564 1.1 skrll /* We might have a direct symbol already having entries in the GOTs.
2565 1.1 skrll Update its key only in case indirect symbol has GOT entries and
2566 1.1 skrll assert that both indirect and direct symbols don't have GOT entries
2567 1.1 skrll at the same time. */
2568 1.1 skrll if (ind->got_entry_key != 0)
2569 1.1 skrll {
2570 1.1 skrll BFD_ASSERT (dir->got_entry_key == 0);
2571 1.1 skrll /* Assert that GOTs aren't partioned yet. */
2572 1.1 skrll BFD_ASSERT (ind->glist == NULL);
2573 1.1 skrll
2574 1.1 skrll dir->got_entry_key = ind->got_entry_key;
2575 1.1 skrll ind->got_entry_key = 0;
2576 1.1 skrll }
2577 1.1 skrll }
2578 1.1 skrll
2579 1.1 skrll /* Look through the relocs for a section during the first phase, and
2580 1.1 skrll allocate space in the global offset table or procedure linkage
2581 1.1 skrll table. */
2582 1.1 skrll
2583 1.1 skrll static bfd_boolean
2584 1.1 skrll elf_m68k_check_relocs (abfd, info, sec, relocs)
2585 1.1 skrll bfd *abfd;
2586 1.1 skrll struct bfd_link_info *info;
2587 1.1 skrll asection *sec;
2588 1.1 skrll const Elf_Internal_Rela *relocs;
2589 1.1 skrll {
2590 1.1 skrll bfd *dynobj;
2591 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
2592 1.1 skrll struct elf_link_hash_entry **sym_hashes;
2593 1.1 skrll const Elf_Internal_Rela *rel;
2594 1.1 skrll const Elf_Internal_Rela *rel_end;
2595 1.1 skrll asection *sgot;
2596 1.1 skrll asection *srelgot;
2597 1.1 skrll asection *sreloc;
2598 1.1 skrll struct elf_m68k_got *got;
2599 1.1 skrll
2600 1.1 skrll if (info->relocatable)
2601 1.1 skrll return TRUE;
2602 1.1 skrll
2603 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
2604 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2605 1.1 skrll sym_hashes = elf_sym_hashes (abfd);
2606 1.1 skrll
2607 1.1 skrll sgot = NULL;
2608 1.1 skrll srelgot = NULL;
2609 1.1 skrll sreloc = NULL;
2610 1.1 skrll
2611 1.1 skrll got = NULL;
2612 1.1 skrll
2613 1.1 skrll rel_end = relocs + sec->reloc_count;
2614 1.1 skrll for (rel = relocs; rel < rel_end; rel++)
2615 1.1 skrll {
2616 1.1 skrll unsigned long r_symndx;
2617 1.1 skrll struct elf_link_hash_entry *h;
2618 1.1 skrll
2619 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
2620 1.1 skrll
2621 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
2622 1.1 skrll h = NULL;
2623 1.1 skrll else
2624 1.1 skrll {
2625 1.1 skrll h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2626 1.1 skrll while (h->root.type == bfd_link_hash_indirect
2627 1.1 skrll || h->root.type == bfd_link_hash_warning)
2628 1.1 skrll h = (struct elf_link_hash_entry *) h->root.u.i.link;
2629 1.1 skrll }
2630 1.1 skrll
2631 1.1 skrll switch (ELF32_R_TYPE (rel->r_info))
2632 1.1 skrll {
2633 1.1 skrll case R_68K_GOT8:
2634 1.1 skrll case R_68K_GOT16:
2635 1.1 skrll case R_68K_GOT32:
2636 1.1 skrll if (h != NULL
2637 1.1 skrll && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2638 1.1 skrll break;
2639 1.1.1.2 christos /* Fall through. */
2640 1.1.1.2 christos
2641 1.1 skrll /* Relative GOT relocations. */
2642 1.1 skrll case R_68K_GOT8O:
2643 1.1 skrll case R_68K_GOT16O:
2644 1.1.1.2 christos case R_68K_GOT32O:
2645 1.1.1.2 christos /* Fall through. */
2646 1.1.1.2 christos
2647 1.1.1.2 christos /* TLS relocations. */
2648 1.1.1.2 christos case R_68K_TLS_GD8:
2649 1.1.1.2 christos case R_68K_TLS_GD16:
2650 1.1.1.2 christos case R_68K_TLS_GD32:
2651 1.1.1.2 christos case R_68K_TLS_LDM8:
2652 1.1.1.2 christos case R_68K_TLS_LDM16:
2653 1.1.1.2 christos case R_68K_TLS_LDM32:
2654 1.1.1.2 christos case R_68K_TLS_IE8:
2655 1.1.1.2 christos case R_68K_TLS_IE16:
2656 1.1.1.2 christos case R_68K_TLS_IE32:
2657 1.1.1.2 christos
2658 1.1.1.2 christos case R_68K_TLS_TPREL32:
2659 1.1.1.2 christos case R_68K_TLS_DTPREL32:
2660 1.1.1.2 christos
2661 1.1.1.2 christos if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
2662 1.1.1.2 christos && info->shared)
2663 1.1.1.2 christos /* Do the special chorus for libraries with static TLS. */
2664 1.1.1.2 christos info->flags |= DF_STATIC_TLS;
2665 1.1 skrll
2666 1.1 skrll /* This symbol requires a global offset table entry. */
2667 1.1 skrll
2668 1.1 skrll if (dynobj == NULL)
2669 1.1 skrll {
2670 1.1 skrll /* Create the .got section. */
2671 1.1 skrll elf_hash_table (info)->dynobj = dynobj = abfd;
2672 1.1 skrll if (!_bfd_elf_create_got_section (dynobj, info))
2673 1.1 skrll return FALSE;
2674 1.1 skrll }
2675 1.1 skrll
2676 1.1 skrll if (sgot == NULL)
2677 1.1 skrll {
2678 1.1 skrll sgot = bfd_get_section_by_name (dynobj, ".got");
2679 1.1 skrll BFD_ASSERT (sgot != NULL);
2680 1.1 skrll }
2681 1.1 skrll
2682 1.1 skrll if (srelgot == NULL
2683 1.1 skrll && (h != NULL || info->shared))
2684 1.1 skrll {
2685 1.1 skrll srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2686 1.1 skrll if (srelgot == NULL)
2687 1.1 skrll {
2688 1.1 skrll srelgot = bfd_make_section_with_flags (dynobj,
2689 1.1 skrll ".rela.got",
2690 1.1 skrll (SEC_ALLOC
2691 1.1 skrll | SEC_LOAD
2692 1.1 skrll | SEC_HAS_CONTENTS
2693 1.1 skrll | SEC_IN_MEMORY
2694 1.1 skrll | SEC_LINKER_CREATED
2695 1.1 skrll | SEC_READONLY));
2696 1.1 skrll if (srelgot == NULL
2697 1.1 skrll || !bfd_set_section_alignment (dynobj, srelgot, 2))
2698 1.1 skrll return FALSE;
2699 1.1 skrll }
2700 1.1 skrll }
2701 1.1 skrll
2702 1.1 skrll if (got == NULL)
2703 1.1 skrll {
2704 1.1 skrll struct elf_m68k_bfd2got_entry *bfd2got_entry;
2705 1.1 skrll
2706 1.1 skrll bfd2got_entry
2707 1.1 skrll = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2708 1.1 skrll abfd, FIND_OR_CREATE, info);
2709 1.1 skrll if (bfd2got_entry == NULL)
2710 1.1 skrll return FALSE;
2711 1.1 skrll
2712 1.1 skrll got = bfd2got_entry->got;
2713 1.1 skrll BFD_ASSERT (got != NULL);
2714 1.1 skrll }
2715 1.1 skrll
2716 1.1 skrll {
2717 1.1 skrll struct elf_m68k_got_entry *got_entry;
2718 1.1 skrll
2719 1.1 skrll /* Add entry to got. */
2720 1.1 skrll got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
2721 1.1 skrll ELF32_R_TYPE (rel->r_info),
2722 1.1 skrll r_symndx, info);
2723 1.1 skrll if (got_entry == NULL)
2724 1.1 skrll return FALSE;
2725 1.1 skrll
2726 1.1 skrll if (got_entry->u.s1.refcount == 1)
2727 1.1 skrll {
2728 1.1 skrll /* Make sure this symbol is output as a dynamic symbol. */
2729 1.1 skrll if (h != NULL
2730 1.1 skrll && h->dynindx == -1
2731 1.1 skrll && !h->forced_local)
2732 1.1 skrll {
2733 1.1 skrll if (!bfd_elf_link_record_dynamic_symbol (info, h))
2734 1.1 skrll return FALSE;
2735 1.1 skrll }
2736 1.1 skrll }
2737 1.1 skrll }
2738 1.1 skrll
2739 1.1 skrll break;
2740 1.1 skrll
2741 1.1 skrll case R_68K_PLT8:
2742 1.1 skrll case R_68K_PLT16:
2743 1.1 skrll case R_68K_PLT32:
2744 1.1 skrll /* This symbol requires a procedure linkage table entry. We
2745 1.1 skrll actually build the entry in adjust_dynamic_symbol,
2746 1.1 skrll because this might be a case of linking PIC code which is
2747 1.1 skrll never referenced by a dynamic object, in which case we
2748 1.1 skrll don't need to generate a procedure linkage table entry
2749 1.1 skrll after all. */
2750 1.1 skrll
2751 1.1 skrll /* If this is a local symbol, we resolve it directly without
2752 1.1 skrll creating a procedure linkage table entry. */
2753 1.1 skrll if (h == NULL)
2754 1.1 skrll continue;
2755 1.1 skrll
2756 1.1 skrll h->needs_plt = 1;
2757 1.1 skrll h->plt.refcount++;
2758 1.1 skrll break;
2759 1.1 skrll
2760 1.1 skrll case R_68K_PLT8O:
2761 1.1 skrll case R_68K_PLT16O:
2762 1.1 skrll case R_68K_PLT32O:
2763 1.1 skrll /* This symbol requires a procedure linkage table entry. */
2764 1.1 skrll
2765 1.1 skrll if (h == NULL)
2766 1.1 skrll {
2767 1.1 skrll /* It does not make sense to have this relocation for a
2768 1.1 skrll local symbol. FIXME: does it? How to handle it if
2769 1.1 skrll it does make sense? */
2770 1.1 skrll bfd_set_error (bfd_error_bad_value);
2771 1.1 skrll return FALSE;
2772 1.1 skrll }
2773 1.1 skrll
2774 1.1 skrll /* Make sure this symbol is output as a dynamic symbol. */
2775 1.1 skrll if (h->dynindx == -1
2776 1.1 skrll && !h->forced_local)
2777 1.1 skrll {
2778 1.1 skrll if (!bfd_elf_link_record_dynamic_symbol (info, h))
2779 1.1 skrll return FALSE;
2780 1.1 skrll }
2781 1.1 skrll
2782 1.1 skrll h->needs_plt = 1;
2783 1.1 skrll h->plt.refcount++;
2784 1.1 skrll break;
2785 1.1 skrll
2786 1.1 skrll case R_68K_PC8:
2787 1.1 skrll case R_68K_PC16:
2788 1.1 skrll case R_68K_PC32:
2789 1.1 skrll /* If we are creating a shared library and this is not a local
2790 1.1 skrll symbol, we need to copy the reloc into the shared library.
2791 1.1 skrll However when linking with -Bsymbolic and this is a global
2792 1.1 skrll symbol which is defined in an object we are including in the
2793 1.1 skrll link (i.e., DEF_REGULAR is set), then we can resolve the
2794 1.1 skrll reloc directly. At this point we have not seen all the input
2795 1.1 skrll files, so it is possible that DEF_REGULAR is not set now but
2796 1.1 skrll will be set later (it is never cleared). We account for that
2797 1.1 skrll possibility below by storing information in the
2798 1.1 skrll pcrel_relocs_copied field of the hash table entry. */
2799 1.1 skrll if (!(info->shared
2800 1.1 skrll && (sec->flags & SEC_ALLOC) != 0
2801 1.1 skrll && h != NULL
2802 1.1 skrll && (!info->symbolic
2803 1.1 skrll || h->root.type == bfd_link_hash_defweak
2804 1.1 skrll || !h->def_regular)))
2805 1.1 skrll {
2806 1.1 skrll if (h != NULL)
2807 1.1 skrll {
2808 1.1 skrll /* Make sure a plt entry is created for this symbol if
2809 1.1 skrll it turns out to be a function defined by a dynamic
2810 1.1 skrll object. */
2811 1.1 skrll h->plt.refcount++;
2812 1.1 skrll }
2813 1.1 skrll break;
2814 1.1 skrll }
2815 1.1 skrll /* Fall through. */
2816 1.1 skrll case R_68K_8:
2817 1.1 skrll case R_68K_16:
2818 1.1 skrll case R_68K_32:
2819 1.1 skrll if (h != NULL)
2820 1.1 skrll {
2821 1.1 skrll /* Make sure a plt entry is created for this symbol if it
2822 1.1 skrll turns out to be a function defined by a dynamic object. */
2823 1.1.1.2 christos h->plt.refcount++;
2824 1.1.1.2 christos
2825 1.1.1.2 christos if (!info->shared)
2826 1.1.1.2 christos /* This symbol needs a non-GOT reference. */
2827 1.1 skrll h->non_got_ref = 1;
2828 1.1 skrll }
2829 1.1 skrll
2830 1.1 skrll /* If we are creating a shared library, we need to copy the
2831 1.1 skrll reloc into the shared library. */
2832 1.1 skrll if (info->shared
2833 1.1 skrll && (sec->flags & SEC_ALLOC) != 0)
2834 1.1 skrll {
2835 1.1 skrll /* When creating a shared object, we must copy these
2836 1.1 skrll reloc types into the output file. We create a reloc
2837 1.1 skrll section in dynobj and make room for this reloc. */
2838 1.1 skrll if (sreloc == NULL)
2839 1.1.1.2 christos {
2840 1.1.1.2 christos sreloc = _bfd_elf_make_dynamic_reloc_section
2841 1.1 skrll (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2842 1.1 skrll
2843 1.1.1.2 christos if (sreloc == NULL)
2844 1.1 skrll return FALSE;
2845 1.1 skrll }
2846 1.1 skrll
2847 1.1 skrll if (sec->flags & SEC_READONLY
2848 1.1 skrll /* Don't set DF_TEXTREL yet for PC relative
2849 1.1 skrll relocations, they might be discarded later. */
2850 1.1 skrll && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2851 1.1 skrll || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2852 1.1 skrll || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
2853 1.1 skrll info->flags |= DF_TEXTREL;
2854 1.1 skrll
2855 1.1 skrll sreloc->size += sizeof (Elf32_External_Rela);
2856 1.1 skrll
2857 1.1 skrll /* We count the number of PC relative relocations we have
2858 1.1 skrll entered for this symbol, so that we can discard them
2859 1.1 skrll again if, in the -Bsymbolic case, the symbol is later
2860 1.1 skrll defined by a regular object, or, in the normal shared
2861 1.1 skrll case, the symbol is forced to be local. Note that this
2862 1.1 skrll function is only called if we are using an m68kelf linker
2863 1.1 skrll hash table, which means that h is really a pointer to an
2864 1.1 skrll elf_m68k_link_hash_entry. */
2865 1.1 skrll if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2866 1.1 skrll || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2867 1.1 skrll || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
2868 1.1 skrll {
2869 1.1 skrll struct elf_m68k_pcrel_relocs_copied *p;
2870 1.1 skrll struct elf_m68k_pcrel_relocs_copied **head;
2871 1.1 skrll
2872 1.1 skrll if (h != NULL)
2873 1.1 skrll {
2874 1.1 skrll struct elf_m68k_link_hash_entry *eh
2875 1.1 skrll = elf_m68k_hash_entry (h);
2876 1.1 skrll head = &eh->pcrel_relocs_copied;
2877 1.1 skrll }
2878 1.1 skrll else
2879 1.1 skrll {
2880 1.1 skrll asection *s;
2881 1.1.1.2 christos void *vpp;
2882 1.1 skrll Elf_Internal_Sym *isym;
2883 1.1.1.2 christos
2884 1.1.1.2 christos isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->sym_cache,
2885 1.1.1.2 christos abfd, r_symndx);
2886 1.1 skrll if (isym == NULL)
2887 1.1 skrll return FALSE;
2888 1.1.1.2 christos
2889 1.1.1.2 christos s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2890 1.1.1.2 christos if (s == NULL)
2891 1.1.1.2 christos s = sec;
2892 1.1 skrll
2893 1.1 skrll vpp = &elf_section_data (s)->local_dynrel;
2894 1.1 skrll head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
2895 1.1 skrll }
2896 1.1 skrll
2897 1.1 skrll for (p = *head; p != NULL; p = p->next)
2898 1.1 skrll if (p->section == sreloc)
2899 1.1 skrll break;
2900 1.1 skrll
2901 1.1 skrll if (p == NULL)
2902 1.1 skrll {
2903 1.1 skrll p = ((struct elf_m68k_pcrel_relocs_copied *)
2904 1.1 skrll bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
2905 1.1 skrll if (p == NULL)
2906 1.1 skrll return FALSE;
2907 1.1 skrll p->next = *head;
2908 1.1 skrll *head = p;
2909 1.1 skrll p->section = sreloc;
2910 1.1 skrll p->count = 0;
2911 1.1 skrll }
2912 1.1 skrll
2913 1.1 skrll ++p->count;
2914 1.1 skrll }
2915 1.1 skrll }
2916 1.1 skrll
2917 1.1 skrll break;
2918 1.1 skrll
2919 1.1 skrll /* This relocation describes the C++ object vtable hierarchy.
2920 1.1 skrll Reconstruct it for later use during GC. */
2921 1.1 skrll case R_68K_GNU_VTINHERIT:
2922 1.1 skrll if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2923 1.1 skrll return FALSE;
2924 1.1 skrll break;
2925 1.1 skrll
2926 1.1 skrll /* This relocation describes which C++ vtable entries are actually
2927 1.1 skrll used. Record for later use during GC. */
2928 1.1 skrll case R_68K_GNU_VTENTRY:
2929 1.1 skrll BFD_ASSERT (h != NULL);
2930 1.1 skrll if (h != NULL
2931 1.1 skrll && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2932 1.1 skrll return FALSE;
2933 1.1 skrll break;
2934 1.1 skrll
2935 1.1 skrll default:
2936 1.1 skrll break;
2937 1.1 skrll }
2938 1.1 skrll }
2939 1.1 skrll
2940 1.1 skrll return TRUE;
2941 1.1 skrll }
2942 1.1 skrll
2943 1.1 skrll /* Return the section that should be marked against GC for a given
2944 1.1 skrll relocation. */
2945 1.1 skrll
2946 1.1 skrll static asection *
2947 1.1 skrll elf_m68k_gc_mark_hook (asection *sec,
2948 1.1 skrll struct bfd_link_info *info,
2949 1.1 skrll Elf_Internal_Rela *rel,
2950 1.1 skrll struct elf_link_hash_entry *h,
2951 1.1 skrll Elf_Internal_Sym *sym)
2952 1.1 skrll {
2953 1.1 skrll if (h != NULL)
2954 1.1 skrll switch (ELF32_R_TYPE (rel->r_info))
2955 1.1 skrll {
2956 1.1 skrll case R_68K_GNU_VTINHERIT:
2957 1.1 skrll case R_68K_GNU_VTENTRY:
2958 1.1 skrll return NULL;
2959 1.1 skrll }
2960 1.1 skrll
2961 1.1 skrll return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2962 1.1 skrll }
2963 1.1 skrll
2964 1.1 skrll /* Update the got entry reference counts for the section being removed. */
2965 1.1 skrll
2966 1.1 skrll static bfd_boolean
2967 1.1 skrll elf_m68k_gc_sweep_hook (bfd *abfd,
2968 1.1 skrll struct bfd_link_info *info,
2969 1.1 skrll asection *sec,
2970 1.1 skrll const Elf_Internal_Rela *relocs)
2971 1.1 skrll {
2972 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
2973 1.1 skrll struct elf_link_hash_entry **sym_hashes;
2974 1.1 skrll const Elf_Internal_Rela *rel, *relend;
2975 1.1 skrll bfd *dynobj;
2976 1.1 skrll struct elf_m68k_got *got;
2977 1.1 skrll
2978 1.1 skrll if (info->relocatable)
2979 1.1 skrll return TRUE;
2980 1.1 skrll
2981 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
2982 1.1 skrll if (dynobj == NULL)
2983 1.1 skrll return TRUE;
2984 1.1 skrll
2985 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2986 1.1 skrll sym_hashes = elf_sym_hashes (abfd);
2987 1.1 skrll got = NULL;
2988 1.1 skrll
2989 1.1 skrll relend = relocs + sec->reloc_count;
2990 1.1 skrll for (rel = relocs; rel < relend; rel++)
2991 1.1 skrll {
2992 1.1 skrll unsigned long r_symndx;
2993 1.1 skrll struct elf_link_hash_entry *h = NULL;
2994 1.1 skrll
2995 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
2996 1.1 skrll if (r_symndx >= symtab_hdr->sh_info)
2997 1.1 skrll {
2998 1.1 skrll h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2999 1.1 skrll while (h->root.type == bfd_link_hash_indirect
3000 1.1 skrll || h->root.type == bfd_link_hash_warning)
3001 1.1 skrll h = (struct elf_link_hash_entry *) h->root.u.i.link;
3002 1.1 skrll }
3003 1.1 skrll
3004 1.1 skrll switch (ELF32_R_TYPE (rel->r_info))
3005 1.1 skrll {
3006 1.1 skrll case R_68K_GOT8:
3007 1.1 skrll case R_68K_GOT16:
3008 1.1 skrll case R_68K_GOT32:
3009 1.1 skrll if (h != NULL
3010 1.1 skrll && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3011 1.1 skrll break;
3012 1.1 skrll
3013 1.1 skrll /* FALLTHRU */
3014 1.1 skrll case R_68K_GOT8O:
3015 1.1 skrll case R_68K_GOT16O:
3016 1.1.1.2 christos case R_68K_GOT32O:
3017 1.1.1.2 christos /* Fall through. */
3018 1.1.1.2 christos
3019 1.1.1.2 christos /* TLS relocations. */
3020 1.1.1.2 christos case R_68K_TLS_GD8:
3021 1.1.1.2 christos case R_68K_TLS_GD16:
3022 1.1.1.2 christos case R_68K_TLS_GD32:
3023 1.1.1.2 christos case R_68K_TLS_LDM8:
3024 1.1.1.2 christos case R_68K_TLS_LDM16:
3025 1.1.1.2 christos case R_68K_TLS_LDM32:
3026 1.1.1.2 christos case R_68K_TLS_IE8:
3027 1.1.1.2 christos case R_68K_TLS_IE16:
3028 1.1.1.2 christos case R_68K_TLS_IE32:
3029 1.1.1.2 christos
3030 1.1.1.2 christos case R_68K_TLS_TPREL32:
3031 1.1.1.2 christos case R_68K_TLS_DTPREL32:
3032 1.1 skrll
3033 1.1 skrll if (got == NULL)
3034 1.1 skrll {
3035 1.1 skrll got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3036 1.1 skrll abfd, MUST_FIND, NULL)->got;
3037 1.1 skrll BFD_ASSERT (got != NULL);
3038 1.1 skrll }
3039 1.1 skrll
3040 1.1 skrll {
3041 1.1 skrll struct elf_m68k_got_entry_key key_;
3042 1.1 skrll struct elf_m68k_got_entry **got_entry_ptr;
3043 1.1 skrll struct elf_m68k_got_entry *got_entry;
3044 1.1.1.2 christos
3045 1.1.1.2 christos elf_m68k_init_got_entry_key (&key_, h, abfd, r_symndx,
3046 1.1 skrll ELF32_R_TYPE (rel->r_info));
3047 1.1 skrll got_entry_ptr = elf_m68k_find_got_entry_ptr (got, &key_);
3048 1.1 skrll
3049 1.1 skrll got_entry = *got_entry_ptr;
3050 1.1 skrll
3051 1.1 skrll if (got_entry->u.s1.refcount > 0)
3052 1.1 skrll {
3053 1.1 skrll --got_entry->u.s1.refcount;
3054 1.1 skrll
3055 1.1 skrll if (got_entry->u.s1.refcount == 0)
3056 1.1 skrll /* We don't need the .got entry any more. */
3057 1.1 skrll elf_m68k_remove_got_entry (got, got_entry_ptr);
3058 1.1 skrll }
3059 1.1 skrll }
3060 1.1 skrll break;
3061 1.1 skrll
3062 1.1 skrll case R_68K_PLT8:
3063 1.1 skrll case R_68K_PLT16:
3064 1.1 skrll case R_68K_PLT32:
3065 1.1 skrll case R_68K_PLT8O:
3066 1.1 skrll case R_68K_PLT16O:
3067 1.1 skrll case R_68K_PLT32O:
3068 1.1 skrll case R_68K_PC8:
3069 1.1 skrll case R_68K_PC16:
3070 1.1 skrll case R_68K_PC32:
3071 1.1 skrll case R_68K_8:
3072 1.1 skrll case R_68K_16:
3073 1.1 skrll case R_68K_32:
3074 1.1 skrll if (h != NULL)
3075 1.1 skrll {
3076 1.1 skrll if (h->plt.refcount > 0)
3077 1.1 skrll --h->plt.refcount;
3078 1.1 skrll }
3079 1.1 skrll break;
3080 1.1 skrll
3081 1.1 skrll default:
3082 1.1 skrll break;
3083 1.1 skrll }
3084 1.1 skrll }
3085 1.1 skrll
3086 1.1 skrll return TRUE;
3087 1.1 skrll }
3088 1.1 skrll
3089 1.1 skrll /* Return the type of PLT associated with OUTPUT_BFD. */
3091 1.1 skrll
3092 1.1 skrll static const struct elf_m68k_plt_info *
3093 1.1 skrll elf_m68k_get_plt_info (bfd *output_bfd)
3094 1.1 skrll {
3095 1.1 skrll unsigned int features;
3096 1.1 skrll
3097 1.1 skrll features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
3098 1.1 skrll if (features & cpu32)
3099 1.1 skrll return &elf_cpu32_plt_info;
3100 1.1 skrll if (features & mcfisa_b)
3101 1.1 skrll return &elf_isab_plt_info;
3102 1.1 skrll if (features & mcfisa_c)
3103 1.1 skrll return &elf_isac_plt_info;
3104 1.1 skrll return &elf_m68k_plt_info;
3105 1.1 skrll }
3106 1.1 skrll
3107 1.1 skrll /* This function is called after all the input files have been read,
3108 1.1 skrll and the input sections have been assigned to output sections.
3109 1.1 skrll It's a convenient place to determine the PLT style. */
3110 1.1 skrll
3111 1.1 skrll static bfd_boolean
3112 1.1 skrll elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3113 1.1 skrll {
3114 1.1 skrll /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
3115 1.1 skrll sections. */
3116 1.1 skrll if (!elf_m68k_partition_multi_got (info))
3117 1.1 skrll return FALSE;
3118 1.1 skrll
3119 1.1 skrll elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
3120 1.1 skrll return TRUE;
3121 1.1 skrll }
3122 1.1 skrll
3123 1.1 skrll /* Adjust a symbol defined by a dynamic object and referenced by a
3124 1.1 skrll regular object. The current definition is in some section of the
3125 1.1 skrll dynamic object, but we're not including those sections. We have to
3126 1.1 skrll change the definition to something the rest of the link can
3127 1.1 skrll understand. */
3128 1.1 skrll
3129 1.1 skrll static bfd_boolean
3130 1.1 skrll elf_m68k_adjust_dynamic_symbol (info, h)
3131 1.1 skrll struct bfd_link_info *info;
3132 1.1 skrll struct elf_link_hash_entry *h;
3133 1.1 skrll {
3134 1.1 skrll struct elf_m68k_link_hash_table *htab;
3135 1.1 skrll bfd *dynobj;
3136 1.1 skrll asection *s;
3137 1.1 skrll
3138 1.1 skrll htab = elf_m68k_hash_table (info);
3139 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
3140 1.1 skrll
3141 1.1 skrll /* Make sure we know what is going on here. */
3142 1.1 skrll BFD_ASSERT (dynobj != NULL
3143 1.1 skrll && (h->needs_plt
3144 1.1 skrll || h->u.weakdef != NULL
3145 1.1 skrll || (h->def_dynamic
3146 1.1 skrll && h->ref_regular
3147 1.1 skrll && !h->def_regular)));
3148 1.1 skrll
3149 1.1 skrll /* If this is a function, put it in the procedure linkage table. We
3150 1.1 skrll will fill in the contents of the procedure linkage table later,
3151 1.1 skrll when we know the address of the .got section. */
3152 1.1 skrll if (h->type == STT_FUNC
3153 1.1 skrll || h->needs_plt)
3154 1.1 skrll {
3155 1.1 skrll if ((h->plt.refcount <= 0
3156 1.1 skrll || SYMBOL_CALLS_LOCAL (info, h)
3157 1.1 skrll || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3158 1.1 skrll && h->root.type == bfd_link_hash_undefweak))
3159 1.1 skrll /* We must always create the plt entry if it was referenced
3160 1.1 skrll by a PLTxxO relocation. In this case we already recorded
3161 1.1 skrll it as a dynamic symbol. */
3162 1.1 skrll && h->dynindx == -1)
3163 1.1 skrll {
3164 1.1 skrll /* This case can occur if we saw a PLTxx reloc in an input
3165 1.1 skrll file, but the symbol was never referred to by a dynamic
3166 1.1 skrll object, or if all references were garbage collected. In
3167 1.1 skrll such a case, we don't actually need to build a procedure
3168 1.1 skrll linkage table, and we can just do a PCxx reloc instead. */
3169 1.1 skrll h->plt.offset = (bfd_vma) -1;
3170 1.1 skrll h->needs_plt = 0;
3171 1.1 skrll return TRUE;
3172 1.1 skrll }
3173 1.1 skrll
3174 1.1 skrll /* Make sure this symbol is output as a dynamic symbol. */
3175 1.1 skrll if (h->dynindx == -1
3176 1.1 skrll && !h->forced_local)
3177 1.1 skrll {
3178 1.1 skrll if (! bfd_elf_link_record_dynamic_symbol (info, h))
3179 1.1 skrll return FALSE;
3180 1.1 skrll }
3181 1.1 skrll
3182 1.1 skrll s = bfd_get_section_by_name (dynobj, ".plt");
3183 1.1 skrll BFD_ASSERT (s != NULL);
3184 1.1 skrll
3185 1.1 skrll /* If this is the first .plt entry, make room for the special
3186 1.1 skrll first entry. */
3187 1.1 skrll if (s->size == 0)
3188 1.1 skrll s->size = htab->plt_info->size;
3189 1.1 skrll
3190 1.1 skrll /* If this symbol is not defined in a regular file, and we are
3191 1.1 skrll not generating a shared library, then set the symbol to this
3192 1.1 skrll location in the .plt. This is required to make function
3193 1.1 skrll pointers compare as equal between the normal executable and
3194 1.1 skrll the shared library. */
3195 1.1 skrll if (!info->shared
3196 1.1 skrll && !h->def_regular)
3197 1.1 skrll {
3198 1.1 skrll h->root.u.def.section = s;
3199 1.1 skrll h->root.u.def.value = s->size;
3200 1.1 skrll }
3201 1.1 skrll
3202 1.1 skrll h->plt.offset = s->size;
3203 1.1 skrll
3204 1.1 skrll /* Make room for this entry. */
3205 1.1 skrll s->size += htab->plt_info->size;
3206 1.1 skrll
3207 1.1 skrll /* We also need to make an entry in the .got.plt section, which
3208 1.1 skrll will be placed in the .got section by the linker script. */
3209 1.1 skrll s = bfd_get_section_by_name (dynobj, ".got.plt");
3210 1.1 skrll BFD_ASSERT (s != NULL);
3211 1.1 skrll s->size += 4;
3212 1.1 skrll
3213 1.1 skrll /* We also need to make an entry in the .rela.plt section. */
3214 1.1 skrll s = bfd_get_section_by_name (dynobj, ".rela.plt");
3215 1.1 skrll BFD_ASSERT (s != NULL);
3216 1.1 skrll s->size += sizeof (Elf32_External_Rela);
3217 1.1 skrll
3218 1.1 skrll return TRUE;
3219 1.1 skrll }
3220 1.1 skrll
3221 1.1 skrll /* Reinitialize the plt offset now that it is not used as a reference
3222 1.1 skrll count any more. */
3223 1.1 skrll h->plt.offset = (bfd_vma) -1;
3224 1.1 skrll
3225 1.1 skrll /* If this is a weak symbol, and there is a real definition, the
3226 1.1 skrll processor independent code will have arranged for us to see the
3227 1.1 skrll real definition first, and we can just use the same value. */
3228 1.1 skrll if (h->u.weakdef != NULL)
3229 1.1 skrll {
3230 1.1 skrll BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3231 1.1 skrll || h->u.weakdef->root.type == bfd_link_hash_defweak);
3232 1.1 skrll h->root.u.def.section = h->u.weakdef->root.u.def.section;
3233 1.1 skrll h->root.u.def.value = h->u.weakdef->root.u.def.value;
3234 1.1 skrll return TRUE;
3235 1.1 skrll }
3236 1.1 skrll
3237 1.1 skrll /* This is a reference to a symbol defined by a dynamic object which
3238 1.1 skrll is not a function. */
3239 1.1 skrll
3240 1.1 skrll /* If we are creating a shared library, we must presume that the
3241 1.1 skrll only references to the symbol are via the global offset table.
3242 1.1 skrll For such cases we need not do anything here; the relocations will
3243 1.1 skrll be handled correctly by relocate_section. */
3244 1.1 skrll if (info->shared)
3245 1.1.1.2 christos return TRUE;
3246 1.1.1.2 christos
3247 1.1.1.2 christos /* If there are no references to this symbol that do not use the
3248 1.1.1.2 christos GOT, we don't need to generate a copy reloc. */
3249 1.1.1.2 christos if (!h->non_got_ref)
3250 1.1 skrll return TRUE;
3251 1.1 skrll
3252 1.1 skrll if (h->size == 0)
3253 1.1 skrll {
3254 1.1 skrll (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
3255 1.1 skrll h->root.root.string);
3256 1.1 skrll return TRUE;
3257 1.1 skrll }
3258 1.1 skrll
3259 1.1 skrll /* We must allocate the symbol in our .dynbss section, which will
3260 1.1 skrll become part of the .bss section of the executable. There will be
3261 1.1 skrll an entry for this symbol in the .dynsym section. The dynamic
3262 1.1 skrll object will contain position independent code, so all references
3263 1.1 skrll from the dynamic object to this symbol will go through the global
3264 1.1 skrll offset table. The dynamic linker will use the .dynsym entry to
3265 1.1 skrll determine the address it must put in the global offset table, so
3266 1.1 skrll both the dynamic object and the regular object will refer to the
3267 1.1 skrll same memory location for the variable. */
3268 1.1 skrll
3269 1.1 skrll s = bfd_get_section_by_name (dynobj, ".dynbss");
3270 1.1 skrll BFD_ASSERT (s != NULL);
3271 1.1 skrll
3272 1.1 skrll /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3273 1.1 skrll copy the initial value out of the dynamic object and into the
3274 1.1 skrll runtime process image. We need to remember the offset into the
3275 1.1 skrll .rela.bss section we are going to use. */
3276 1.1 skrll if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3277 1.1 skrll {
3278 1.1 skrll asection *srel;
3279 1.1 skrll
3280 1.1 skrll srel = bfd_get_section_by_name (dynobj, ".rela.bss");
3281 1.1 skrll BFD_ASSERT (srel != NULL);
3282 1.1 skrll srel->size += sizeof (Elf32_External_Rela);
3283 1.1 skrll h->needs_copy = 1;
3284 1.1 skrll }
3285 1.1 skrll
3286 1.1 skrll return _bfd_elf_adjust_dynamic_copy (h, s);
3287 1.1 skrll }
3288 1.1 skrll
3289 1.1 skrll /* Set the sizes of the dynamic sections. */
3290 1.1 skrll
3291 1.1 skrll static bfd_boolean
3292 1.1 skrll elf_m68k_size_dynamic_sections (output_bfd, info)
3293 1.1 skrll bfd *output_bfd ATTRIBUTE_UNUSED;
3294 1.1 skrll struct bfd_link_info *info;
3295 1.1 skrll {
3296 1.1 skrll bfd *dynobj;
3297 1.1 skrll asection *s;
3298 1.1 skrll bfd_boolean plt;
3299 1.1 skrll bfd_boolean relocs;
3300 1.1 skrll
3301 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
3302 1.1 skrll BFD_ASSERT (dynobj != NULL);
3303 1.1 skrll
3304 1.1 skrll if (elf_hash_table (info)->dynamic_sections_created)
3305 1.1 skrll {
3306 1.1 skrll /* Set the contents of the .interp section to the interpreter. */
3307 1.1 skrll if (info->executable)
3308 1.1 skrll {
3309 1.1 skrll s = bfd_get_section_by_name (dynobj, ".interp");
3310 1.1 skrll BFD_ASSERT (s != NULL);
3311 1.1 skrll s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3312 1.1 skrll s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3313 1.1 skrll }
3314 1.1 skrll }
3315 1.1 skrll else
3316 1.1 skrll {
3317 1.1 skrll /* We may have created entries in the .rela.got section.
3318 1.1 skrll However, if we are not creating the dynamic sections, we will
3319 1.1 skrll not actually use these entries. Reset the size of .rela.got,
3320 1.1 skrll which will cause it to get stripped from the output file
3321 1.1 skrll below. */
3322 1.1 skrll s = bfd_get_section_by_name (dynobj, ".rela.got");
3323 1.1 skrll if (s != NULL)
3324 1.1 skrll s->size = 0;
3325 1.1 skrll }
3326 1.1 skrll
3327 1.1 skrll /* If this is a -Bsymbolic shared link, then we need to discard all
3328 1.1 skrll PC relative relocs against symbols defined in a regular object.
3329 1.1 skrll For the normal shared case we discard the PC relative relocs
3330 1.1 skrll against symbols that have become local due to visibility changes.
3331 1.1 skrll We allocated space for them in the check_relocs routine, but we
3332 1.1 skrll will not fill them in in the relocate_section routine. */
3333 1.1 skrll if (info->shared)
3334 1.1 skrll elf_link_hash_traverse (elf_hash_table (info),
3335 1.1 skrll elf_m68k_discard_copies,
3336 1.1 skrll (PTR) info);
3337 1.1 skrll
3338 1.1 skrll /* The check_relocs and adjust_dynamic_symbol entry points have
3339 1.1 skrll determined the sizes of the various dynamic sections. Allocate
3340 1.1 skrll memory for them. */
3341 1.1 skrll plt = FALSE;
3342 1.1 skrll relocs = FALSE;
3343 1.1 skrll for (s = dynobj->sections; s != NULL; s = s->next)
3344 1.1 skrll {
3345 1.1 skrll const char *name;
3346 1.1 skrll
3347 1.1 skrll if ((s->flags & SEC_LINKER_CREATED) == 0)
3348 1.1 skrll continue;
3349 1.1 skrll
3350 1.1 skrll /* It's OK to base decisions on the section name, because none
3351 1.1 skrll of the dynobj section names depend upon the input files. */
3352 1.1 skrll name = bfd_get_section_name (dynobj, s);
3353 1.1 skrll
3354 1.1 skrll if (strcmp (name, ".plt") == 0)
3355 1.1 skrll {
3356 1.1 skrll /* Remember whether there is a PLT. */
3357 1.1 skrll plt = s->size != 0;
3358 1.1 skrll }
3359 1.1 skrll else if (CONST_STRNEQ (name, ".rela"))
3360 1.1 skrll {
3361 1.1 skrll if (s->size != 0)
3362 1.1 skrll {
3363 1.1 skrll relocs = TRUE;
3364 1.1 skrll
3365 1.1 skrll /* We use the reloc_count field as a counter if we need
3366 1.1 skrll to copy relocs into the output file. */
3367 1.1 skrll s->reloc_count = 0;
3368 1.1 skrll }
3369 1.1 skrll }
3370 1.1 skrll else if (! CONST_STRNEQ (name, ".got")
3371 1.1 skrll && strcmp (name, ".dynbss") != 0)
3372 1.1 skrll {
3373 1.1 skrll /* It's not one of our sections, so don't allocate space. */
3374 1.1 skrll continue;
3375 1.1 skrll }
3376 1.1 skrll
3377 1.1 skrll if (s->size == 0)
3378 1.1 skrll {
3379 1.1 skrll /* If we don't need this section, strip it from the
3380 1.1 skrll output file. This is mostly to handle .rela.bss and
3381 1.1 skrll .rela.plt. We must create both sections in
3382 1.1 skrll create_dynamic_sections, because they must be created
3383 1.1 skrll before the linker maps input sections to output
3384 1.1 skrll sections. The linker does that before
3385 1.1 skrll adjust_dynamic_symbol is called, and it is that
3386 1.1 skrll function which decides whether anything needs to go
3387 1.1 skrll into these sections. */
3388 1.1 skrll s->flags |= SEC_EXCLUDE;
3389 1.1 skrll continue;
3390 1.1 skrll }
3391 1.1 skrll
3392 1.1 skrll if ((s->flags & SEC_HAS_CONTENTS) == 0)
3393 1.1 skrll continue;
3394 1.1 skrll
3395 1.1 skrll /* Allocate memory for the section contents. */
3396 1.1 skrll /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3397 1.1 skrll Unused entries should be reclaimed before the section's contents
3398 1.1 skrll are written out, but at the moment this does not happen. Thus in
3399 1.1 skrll order to prevent writing out garbage, we initialise the section's
3400 1.1 skrll contents to zero. */
3401 1.1 skrll s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3402 1.1 skrll if (s->contents == NULL)
3403 1.1 skrll return FALSE;
3404 1.1 skrll }
3405 1.1 skrll
3406 1.1 skrll if (elf_hash_table (info)->dynamic_sections_created)
3407 1.1 skrll {
3408 1.1 skrll /* Add some entries to the .dynamic section. We fill in the
3409 1.1 skrll values later, in elf_m68k_finish_dynamic_sections, but we
3410 1.1 skrll must add the entries now so that we get the correct size for
3411 1.1 skrll the .dynamic section. The DT_DEBUG entry is filled in by the
3412 1.1 skrll dynamic linker and used by the debugger. */
3413 1.1 skrll #define add_dynamic_entry(TAG, VAL) \
3414 1.1 skrll _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3415 1.1 skrll
3416 1.1 skrll if (!info->shared)
3417 1.1 skrll {
3418 1.1 skrll if (!add_dynamic_entry (DT_DEBUG, 0))
3419 1.1 skrll return FALSE;
3420 1.1 skrll }
3421 1.1 skrll
3422 1.1 skrll if (plt)
3423 1.1 skrll {
3424 1.1 skrll if (!add_dynamic_entry (DT_PLTGOT, 0)
3425 1.1 skrll || !add_dynamic_entry (DT_PLTRELSZ, 0)
3426 1.1 skrll || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3427 1.1 skrll || !add_dynamic_entry (DT_JMPREL, 0))
3428 1.1 skrll return FALSE;
3429 1.1 skrll }
3430 1.1 skrll
3431 1.1 skrll if (relocs)
3432 1.1 skrll {
3433 1.1 skrll if (!add_dynamic_entry (DT_RELA, 0)
3434 1.1 skrll || !add_dynamic_entry (DT_RELASZ, 0)
3435 1.1 skrll || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3436 1.1 skrll return FALSE;
3437 1.1 skrll }
3438 1.1 skrll
3439 1.1 skrll if ((info->flags & DF_TEXTREL) != 0)
3440 1.1 skrll {
3441 1.1 skrll if (!add_dynamic_entry (DT_TEXTREL, 0))
3442 1.1 skrll return FALSE;
3443 1.1 skrll }
3444 1.1 skrll }
3445 1.1 skrll #undef add_dynamic_entry
3446 1.1 skrll
3447 1.1 skrll return TRUE;
3448 1.1 skrll }
3449 1.1 skrll
3450 1.1 skrll /* This function is called via elf_link_hash_traverse if we are
3451 1.1 skrll creating a shared object. In the -Bsymbolic case it discards the
3452 1.1 skrll space allocated to copy PC relative relocs against symbols which
3453 1.1 skrll are defined in regular objects. For the normal shared case, it
3454 1.1 skrll discards space for pc-relative relocs that have become local due to
3455 1.1 skrll symbol visibility changes. We allocated space for them in the
3456 1.1 skrll check_relocs routine, but we won't fill them in in the
3457 1.1 skrll relocate_section routine.
3458 1.1 skrll
3459 1.1 skrll We also check whether any of the remaining relocations apply
3460 1.1 skrll against a readonly section, and set the DF_TEXTREL flag in this
3461 1.1 skrll case. */
3462 1.1 skrll
3463 1.1 skrll static bfd_boolean
3464 1.1 skrll elf_m68k_discard_copies (h, inf)
3465 1.1 skrll struct elf_link_hash_entry *h;
3466 1.1 skrll PTR inf;
3467 1.1 skrll {
3468 1.1 skrll struct bfd_link_info *info = (struct bfd_link_info *) inf;
3469 1.1 skrll struct elf_m68k_pcrel_relocs_copied *s;
3470 1.1 skrll
3471 1.1 skrll if (h->root.type == bfd_link_hash_warning)
3472 1.1.1.2 christos h = (struct elf_link_hash_entry *) h->root.u.i.link;
3473 1.1 skrll
3474 1.1 skrll if (!SYMBOL_CALLS_LOCAL (info, h))
3475 1.1 skrll {
3476 1.1 skrll if ((info->flags & DF_TEXTREL) == 0)
3477 1.1 skrll {
3478 1.1 skrll /* Look for relocations against read-only sections. */
3479 1.1 skrll for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3480 1.1 skrll s != NULL;
3481 1.1 skrll s = s->next)
3482 1.1 skrll if ((s->section->flags & SEC_READONLY) != 0)
3483 1.1 skrll {
3484 1.1 skrll info->flags |= DF_TEXTREL;
3485 1.1 skrll break;
3486 1.1 skrll }
3487 1.1 skrll }
3488 1.1 skrll
3489 1.1 skrll return TRUE;
3490 1.1 skrll }
3491 1.1 skrll
3492 1.1 skrll for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3493 1.1 skrll s != NULL;
3494 1.1 skrll s = s->next)
3495 1.1 skrll s->section->size -= s->count * sizeof (Elf32_External_Rela);
3496 1.1 skrll
3497 1.1 skrll return TRUE;
3498 1.1.1.2 christos }
3499 1.1.1.2 christos
3500 1.1.1.2 christos
3501 1.1.1.2 christos /* Install relocation RELA. */
3502 1.1.1.2 christos
3503 1.1.1.2 christos static void
3504 1.1.1.2 christos elf_m68k_install_rela (bfd *output_bfd,
3505 1.1.1.2 christos asection *srela,
3506 1.1.1.2 christos Elf_Internal_Rela *rela)
3507 1.1.1.2 christos {
3508 1.1.1.2 christos bfd_byte *loc;
3509 1.1.1.2 christos
3510 1.1.1.2 christos loc = srela->contents;
3511 1.1.1.2 christos loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
3512 1.1.1.2 christos bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
3513 1.1.1.2 christos }
3514 1.1.1.2 christos
3515 1.1.1.2 christos /* Find the base offsets for thread-local storage in this object,
3516 1.1.1.2 christos for GD/LD and IE/LE respectively. */
3517 1.1.1.2 christos
3518 1.1.1.2 christos #define DTP_OFFSET 0x8000
3519 1.1.1.2 christos #define TP_OFFSET 0x7000
3520 1.1.1.2 christos
3521 1.1.1.2 christos static bfd_vma
3522 1.1.1.2 christos dtpoff_base (struct bfd_link_info *info)
3523 1.1.1.2 christos {
3524 1.1.1.2 christos /* If tls_sec is NULL, we should have signalled an error already. */
3525 1.1.1.2 christos if (elf_hash_table (info)->tls_sec == NULL)
3526 1.1.1.2 christos return 0;
3527 1.1.1.2 christos return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET;
3528 1.1.1.2 christos }
3529 1.1.1.2 christos
3530 1.1.1.2 christos static bfd_vma
3531 1.1.1.2 christos tpoff_base (struct bfd_link_info *info)
3532 1.1.1.2 christos {
3533 1.1.1.2 christos /* If tls_sec is NULL, we should have signalled an error already. */
3534 1.1.1.2 christos if (elf_hash_table (info)->tls_sec == NULL)
3535 1.1.1.2 christos return 0;
3536 1.1.1.2 christos return elf_hash_table (info)->tls_sec->vma + TP_OFFSET;
3537 1.1.1.2 christos }
3538 1.1.1.2 christos
3539 1.1.1.2 christos /* Output necessary relocation to handle a symbol during static link.
3540 1.1.1.2 christos This function is called from elf_m68k_relocate_section. */
3541 1.1.1.2 christos
3542 1.1.1.2 christos static void
3543 1.1.1.2 christos elf_m68k_init_got_entry_static (struct bfd_link_info *info,
3544 1.1.1.2 christos bfd *output_bfd,
3545 1.1.1.2 christos enum elf_m68k_reloc_type r_type,
3546 1.1.1.2 christos asection *sgot,
3547 1.1.1.2 christos bfd_vma got_entry_offset,
3548 1.1.1.2 christos bfd_vma relocation)
3549 1.1.1.2 christos {
3550 1.1.1.2 christos switch (elf_m68k_reloc_got_type (r_type))
3551 1.1.1.2 christos {
3552 1.1.1.2 christos case R_68K_GOT32O:
3553 1.1.1.2 christos bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset);
3554 1.1.1.2 christos break;
3555 1.1.1.2 christos
3556 1.1.1.2 christos case R_68K_TLS_GD32:
3557 1.1.1.2 christos /* We know the offset within the module,
3558 1.1.1.2 christos put it into the second GOT slot. */
3559 1.1.1.2 christos bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3560 1.1.1.2 christos sgot->contents + got_entry_offset + 4);
3561 1.1.1.2 christos /* FALLTHRU */
3562 1.1.1.2 christos
3563 1.1.1.2 christos case R_68K_TLS_LDM32:
3564 1.1.1.2 christos /* Mark it as belonging to module 1, the executable. */
3565 1.1.1.2 christos bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset);
3566 1.1.1.2 christos break;
3567 1.1.1.2 christos
3568 1.1.1.2 christos case R_68K_TLS_IE32:
3569 1.1.1.2 christos bfd_put_32 (output_bfd, relocation - tpoff_base (info),
3570 1.1.1.2 christos sgot->contents + got_entry_offset);
3571 1.1.1.2 christos break;
3572 1.1.1.2 christos
3573 1.1.1.2 christos default:
3574 1.1.1.2 christos BFD_ASSERT (FALSE);
3575 1.1.1.2 christos }
3576 1.1.1.2 christos }
3577 1.1.1.2 christos
3578 1.1.1.2 christos /* Output necessary relocation to handle a local symbol
3579 1.1.1.2 christos during dynamic link.
3580 1.1.1.2 christos This function is called either from elf_m68k_relocate_section
3581 1.1.1.2 christos or from elf_m68k_finish_dynamic_symbol. */
3582 1.1.1.2 christos
3583 1.1.1.2 christos static void
3584 1.1.1.2 christos elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info,
3585 1.1.1.2 christos bfd *output_bfd,
3586 1.1.1.2 christos enum elf_m68k_reloc_type r_type,
3587 1.1.1.2 christos asection *sgot,
3588 1.1.1.2 christos bfd_vma got_entry_offset,
3589 1.1.1.2 christos bfd_vma relocation,
3590 1.1.1.2 christos asection *srela)
3591 1.1.1.2 christos {
3592 1.1.1.2 christos Elf_Internal_Rela outrel;
3593 1.1.1.2 christos
3594 1.1.1.2 christos switch (elf_m68k_reloc_got_type (r_type))
3595 1.1.1.2 christos {
3596 1.1.1.2 christos case R_68K_GOT32O:
3597 1.1.1.2 christos /* Emit RELATIVE relocation to initialize GOT slot
3598 1.1.1.2 christos at run-time. */
3599 1.1.1.2 christos outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3600 1.1.1.2 christos outrel.r_addend = relocation;
3601 1.1.1.2 christos break;
3602 1.1.1.2 christos
3603 1.1.1.2 christos case R_68K_TLS_GD32:
3604 1.1.1.2 christos /* We know the offset within the module,
3605 1.1.1.2 christos put it into the second GOT slot. */
3606 1.1.1.2 christos bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3607 1.1.1.2 christos sgot->contents + got_entry_offset + 4);
3608 1.1.1.2 christos /* FALLTHRU */
3609 1.1.1.2 christos
3610 1.1.1.2 christos case R_68K_TLS_LDM32:
3611 1.1.1.2 christos /* We don't know the module number,
3612 1.1.1.2 christos create a relocation for it. */
3613 1.1.1.2 christos outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
3614 1.1.1.2 christos outrel.r_addend = 0;
3615 1.1.1.2 christos break;
3616 1.1.1.2 christos
3617 1.1.1.2 christos case R_68K_TLS_IE32:
3618 1.1.1.2 christos /* Emit TPREL relocation to initialize GOT slot
3619 1.1.1.2 christos at run-time. */
3620 1.1.1.2 christos outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
3621 1.1.1.2 christos outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma;
3622 1.1.1.2 christos break;
3623 1.1.1.2 christos
3624 1.1.1.2 christos default:
3625 1.1.1.2 christos BFD_ASSERT (FALSE);
3626 1.1.1.2 christos }
3627 1.1.1.2 christos
3628 1.1.1.2 christos /* Offset of the GOT entry. */
3629 1.1.1.2 christos outrel.r_offset = (sgot->output_section->vma
3630 1.1.1.2 christos + sgot->output_offset
3631 1.1.1.2 christos + got_entry_offset);
3632 1.1.1.2 christos
3633 1.1.1.2 christos /* Install one of the above relocations. */
3634 1.1.1.2 christos elf_m68k_install_rela (output_bfd, srela, &outrel);
3635 1.1.1.2 christos
3636 1.1.1.2 christos bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset);
3637 1.1 skrll }
3638 1.1 skrll
3639 1.1 skrll /* Relocate an M68K ELF section. */
3640 1.1 skrll
3641 1.1 skrll static bfd_boolean
3642 1.1 skrll elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section,
3643 1.1 skrll contents, relocs, local_syms, local_sections)
3644 1.1 skrll bfd *output_bfd;
3645 1.1 skrll struct bfd_link_info *info;
3646 1.1 skrll bfd *input_bfd;
3647 1.1 skrll asection *input_section;
3648 1.1 skrll bfd_byte *contents;
3649 1.1 skrll Elf_Internal_Rela *relocs;
3650 1.1 skrll Elf_Internal_Sym *local_syms;
3651 1.1 skrll asection **local_sections;
3652 1.1 skrll {
3653 1.1 skrll bfd *dynobj;
3654 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
3655 1.1 skrll struct elf_link_hash_entry **sym_hashes;
3656 1.1 skrll asection *sgot;
3657 1.1.1.2 christos asection *splt;
3658 1.1 skrll asection *sreloc;
3659 1.1 skrll asection *srela;
3660 1.1 skrll struct elf_m68k_got *got;
3661 1.1 skrll Elf_Internal_Rela *rel;
3662 1.1 skrll Elf_Internal_Rela *relend;
3663 1.1 skrll
3664 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
3665 1.1 skrll symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3666 1.1 skrll sym_hashes = elf_sym_hashes (input_bfd);
3667 1.1 skrll
3668 1.1 skrll sgot = NULL;
3669 1.1.1.2 christos splt = NULL;
3670 1.1 skrll sreloc = NULL;
3671 1.1 skrll srela = NULL;
3672 1.1 skrll
3673 1.1 skrll got = NULL;
3674 1.1 skrll
3675 1.1 skrll rel = relocs;
3676 1.1 skrll relend = relocs + input_section->reloc_count;
3677 1.1 skrll for (; rel < relend; rel++)
3678 1.1 skrll {
3679 1.1 skrll int r_type;
3680 1.1 skrll reloc_howto_type *howto;
3681 1.1 skrll unsigned long r_symndx;
3682 1.1 skrll struct elf_link_hash_entry *h;
3683 1.1 skrll Elf_Internal_Sym *sym;
3684 1.1 skrll asection *sec;
3685 1.1 skrll bfd_vma relocation;
3686 1.1 skrll bfd_boolean unresolved_reloc;
3687 1.1 skrll bfd_reloc_status_type r;
3688 1.1 skrll
3689 1.1 skrll r_type = ELF32_R_TYPE (rel->r_info);
3690 1.1 skrll if (r_type < 0 || r_type >= (int) R_68K_max)
3691 1.1 skrll {
3692 1.1 skrll bfd_set_error (bfd_error_bad_value);
3693 1.1 skrll return FALSE;
3694 1.1 skrll }
3695 1.1 skrll howto = howto_table + r_type;
3696 1.1 skrll
3697 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
3698 1.1 skrll
3699 1.1 skrll h = NULL;
3700 1.1 skrll sym = NULL;
3701 1.1 skrll sec = NULL;
3702 1.1 skrll unresolved_reloc = FALSE;
3703 1.1 skrll
3704 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
3705 1.1 skrll {
3706 1.1 skrll sym = local_syms + r_symndx;
3707 1.1 skrll sec = local_sections[r_symndx];
3708 1.1 skrll relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3709 1.1 skrll }
3710 1.1 skrll else
3711 1.1 skrll {
3712 1.1 skrll bfd_boolean warned;
3713 1.1 skrll
3714 1.1 skrll RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3715 1.1 skrll r_symndx, symtab_hdr, sym_hashes,
3716 1.1 skrll h, sec, relocation,
3717 1.1 skrll unresolved_reloc, warned);
3718 1.1 skrll }
3719 1.1.1.2 christos
3720 1.1.1.2 christos if (sec != NULL && elf_discarded_section (sec))
3721 1.1 skrll RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3722 1.1 skrll rel, relend, howto, contents);
3723 1.1 skrll
3724 1.1 skrll if (info->relocatable)
3725 1.1 skrll continue;
3726 1.1 skrll
3727 1.1 skrll switch (r_type)
3728 1.1 skrll {
3729 1.1 skrll case R_68K_GOT8:
3730 1.1 skrll case R_68K_GOT16:
3731 1.1 skrll case R_68K_GOT32:
3732 1.1 skrll /* Relocation is to the address of the entry for this symbol
3733 1.1 skrll in the global offset table. */
3734 1.1 skrll if (h != NULL
3735 1.1 skrll && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3736 1.1 skrll {
3737 1.1 skrll if (elf_m68k_hash_table (info)->local_gp_p)
3738 1.1 skrll {
3739 1.1 skrll bfd_vma sgot_output_offset;
3740 1.1 skrll bfd_vma got_offset;
3741 1.1 skrll
3742 1.1 skrll if (sgot == NULL)
3743 1.1 skrll {
3744 1.1 skrll sgot = bfd_get_section_by_name (dynobj, ".got");
3745 1.1 skrll
3746 1.1 skrll if (sgot != NULL)
3747 1.1 skrll sgot_output_offset = sgot->output_offset;
3748 1.1 skrll else
3749 1.1 skrll /* In this case we have a reference to
3750 1.1 skrll _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3751 1.1 skrll empty.
3752 1.1 skrll ??? Issue a warning? */
3753 1.1 skrll sgot_output_offset = 0;
3754 1.1 skrll }
3755 1.1 skrll else
3756 1.1 skrll sgot_output_offset = sgot->output_offset;
3757 1.1 skrll
3758 1.1 skrll if (got == NULL)
3759 1.1 skrll {
3760 1.1 skrll struct elf_m68k_bfd2got_entry *bfd2got_entry;
3761 1.1 skrll
3762 1.1 skrll bfd2got_entry
3763 1.1 skrll = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3764 1.1 skrll input_bfd, SEARCH, NULL);
3765 1.1 skrll
3766 1.1 skrll if (bfd2got_entry != NULL)
3767 1.1 skrll {
3768 1.1 skrll got = bfd2got_entry->got;
3769 1.1 skrll BFD_ASSERT (got != NULL);
3770 1.1 skrll
3771 1.1 skrll got_offset = got->offset;
3772 1.1 skrll }
3773 1.1 skrll else
3774 1.1 skrll /* In this case we have a reference to
3775 1.1 skrll _GLOBAL_OFFSET_TABLE_, but no other references
3776 1.1 skrll accessing any GOT entries.
3777 1.1 skrll ??? Issue a warning? */
3778 1.1 skrll got_offset = 0;
3779 1.1 skrll }
3780 1.1 skrll else
3781 1.1 skrll got_offset = got->offset;
3782 1.1 skrll
3783 1.1 skrll /* Adjust GOT pointer to point to the GOT
3784 1.1 skrll assigned to input_bfd. */
3785 1.1 skrll rel->r_addend += sgot_output_offset + got_offset;
3786 1.1 skrll }
3787 1.1 skrll else
3788 1.1 skrll BFD_ASSERT (got == NULL || got->offset == 0);
3789 1.1 skrll
3790 1.1 skrll break;
3791 1.1 skrll }
3792 1.1 skrll /* Fall through. */
3793 1.1 skrll case R_68K_GOT8O:
3794 1.1.1.2 christos case R_68K_GOT16O:
3795 1.1.1.2 christos case R_68K_GOT32O:
3796 1.1.1.2 christos
3797 1.1.1.2 christos case R_68K_TLS_LDM32:
3798 1.1.1.2 christos case R_68K_TLS_LDM16:
3799 1.1.1.2 christos case R_68K_TLS_LDM8:
3800 1.1.1.2 christos
3801 1.1.1.2 christos case R_68K_TLS_GD8:
3802 1.1.1.2 christos case R_68K_TLS_GD16:
3803 1.1.1.2 christos case R_68K_TLS_GD32:
3804 1.1.1.2 christos
3805 1.1.1.2 christos case R_68K_TLS_IE8:
3806 1.1.1.2 christos case R_68K_TLS_IE16:
3807 1.1 skrll case R_68K_TLS_IE32:
3808 1.1 skrll
3809 1.1 skrll /* Relocation is the offset of the entry for this symbol in
3810 1.1 skrll the global offset table. */
3811 1.1 skrll
3812 1.1 skrll {
3813 1.1 skrll struct elf_m68k_got_entry_key key_;
3814 1.1 skrll bfd_vma *off_ptr;
3815 1.1 skrll bfd_vma off;
3816 1.1 skrll
3817 1.1 skrll if (sgot == NULL)
3818 1.1 skrll {
3819 1.1 skrll sgot = bfd_get_section_by_name (dynobj, ".got");
3820 1.1 skrll BFD_ASSERT (sgot != NULL);
3821 1.1 skrll }
3822 1.1 skrll
3823 1.1 skrll if (got == NULL)
3824 1.1 skrll {
3825 1.1 skrll got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3826 1.1 skrll input_bfd, MUST_FIND,
3827 1.1 skrll NULL)->got;
3828 1.1 skrll BFD_ASSERT (got != NULL);
3829 1.1 skrll }
3830 1.1.1.2 christos
3831 1.1.1.2 christos /* Get GOT offset for this symbol. */
3832 1.1 skrll elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx,
3833 1.1 skrll r_type);
3834 1.1 skrll off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
3835 1.1 skrll NULL)->u.s2.offset;
3836 1.1.1.2 christos off = *off_ptr;
3837 1.1.1.2 christos
3838 1.1.1.2 christos /* The offset must always be a multiple of 4. We use
3839 1.1.1.2 christos the least significant bit to record whether we have
3840 1.1.1.2 christos already generated the necessary reloc. */
3841 1.1.1.2 christos if ((off & 1) != 0)
3842 1.1 skrll off &= ~1;
3843 1.1.1.2 christos else
3844 1.1.1.2 christos {
3845 1.1.1.2 christos if (h != NULL
3846 1.1.1.2 christos /* @TLSLDM relocations are bounded to the module, in
3847 1.1.1.2 christos which the symbol is defined -- not to the symbol
3848 1.1 skrll itself. */
3849 1.1.1.2 christos && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32)
3850 1.1.1.2 christos {
3851 1.1.1.2 christos bfd_boolean dyn;
3852 1.1.1.2 christos
3853 1.1.1.2 christos dyn = elf_hash_table (info)->dynamic_sections_created;
3854 1.1.1.2 christos if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3855 1.1.1.2 christos || (info->shared
3856 1.1.1.2 christos && SYMBOL_REFERENCES_LOCAL (info, h))
3857 1.1 skrll || (ELF_ST_VISIBILITY (h->other)
3858 1.1.1.2 christos && h->root.type == bfd_link_hash_undefweak))
3859 1.1.1.2 christos {
3860 1.1.1.2 christos /* This is actually a static link, or it is a
3861 1.1.1.2 christos -Bsymbolic link and the symbol is defined
3862 1.1.1.2 christos locally, or the symbol was forced to be local
3863 1.1.1.2 christos because of a version file. We must initialize
3864 1.1.1.2 christos this entry in the global offset table. Since
3865 1.1.1.2 christos the offset must always be a multiple of 4, we
3866 1.1.1.2 christos use the least significant bit to record whether
3867 1.1.1.2 christos we have initialized it already.
3868 1.1.1.2 christos
3869 1.1.1.2 christos When doing a dynamic link, we create a .rela.got
3870 1.1.1.2 christos relocation entry to initialize the value. This
3871 1.1.1.2 christos is done in the finish_dynamic_symbol routine. */
3872 1.1.1.2 christos
3873 1.1.1.2 christos elf_m68k_init_got_entry_static (info,
3874 1.1.1.2 christos output_bfd,
3875 1.1.1.2 christos r_type,
3876 1.1.1.2 christos sgot,
3877 1.1.1.2 christos off,
3878 1.1 skrll relocation);
3879 1.1 skrll
3880 1.1.1.2 christos *off_ptr |= 1;
3881 1.1.1.2 christos }
3882 1.1 skrll else
3883 1.1.1.2 christos unresolved_reloc = FALSE;
3884 1.1.1.2 christos }
3885 1.1 skrll else if (info->shared) /* && h == NULL */
3886 1.1.1.2 christos /* Process local symbol during dynamic link. */
3887 1.1 skrll {
3888 1.1.1.2 christos if (srela == NULL)
3889 1.1.1.2 christos {
3890 1.1 skrll srela = bfd_get_section_by_name (dynobj, ".rela.got");
3891 1.1 skrll BFD_ASSERT (srela != NULL);
3892 1.1.1.2 christos }
3893 1.1.1.2 christos
3894 1.1.1.2 christos elf_m68k_init_got_entry_local_shared (info,
3895 1.1.1.2 christos output_bfd,
3896 1.1.1.2 christos r_type,
3897 1.1.1.2 christos sgot,
3898 1.1.1.2 christos off,
3899 1.1.1.2 christos relocation,
3900 1.1.1.2 christos srela);
3901 1.1.1.2 christos
3902 1.1.1.2 christos *off_ptr |= 1;
3903 1.1.1.2 christos }
3904 1.1.1.2 christos else /* h == NULL && !info->shared */
3905 1.1.1.2 christos {
3906 1.1.1.2 christos elf_m68k_init_got_entry_static (info,
3907 1.1.1.2 christos output_bfd,
3908 1.1.1.2 christos r_type,
3909 1.1.1.2 christos sgot,
3910 1.1.1.2 christos off,
3911 1.1 skrll relocation);
3912 1.1 skrll
3913 1.1 skrll *off_ptr |= 1;
3914 1.1 skrll }
3915 1.1.1.2 christos }
3916 1.1.1.2 christos
3917 1.1.1.2 christos /* We don't use elf_m68k_reloc_got_type in the condition below
3918 1.1.1.2 christos because this is the only place where difference between
3919 1.1 skrll R_68K_GOTx and R_68K_GOTxO relocations matters. */
3920 1.1.1.2 christos if (r_type == R_68K_GOT32O
3921 1.1.1.2 christos || r_type == R_68K_GOT16O
3922 1.1.1.2 christos || r_type == R_68K_GOT8O
3923 1.1.1.2 christos || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32
3924 1.1 skrll || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32
3925 1.1 skrll || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32)
3926 1.1 skrll {
3927 1.1 skrll /* GOT pointer is adjusted to point to the start/middle
3928 1.1 skrll of local GOT. Adjust the offset accordingly. */
3929 1.1 skrll BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
3930 1.1 skrll || off >= got->offset);
3931 1.1 skrll
3932 1.1 skrll if (elf_m68k_hash_table (info)->local_gp_p)
3933 1.1 skrll relocation = off - got->offset;
3934 1.1 skrll else
3935 1.1 skrll {
3936 1.1 skrll BFD_ASSERT (got->offset == 0);
3937 1.1 skrll relocation = sgot->output_offset + off;
3938 1.1 skrll }
3939 1.1 skrll
3940 1.1 skrll /* This relocation does not use the addend. */
3941 1.1 skrll rel->r_addend = 0;
3942 1.1 skrll }
3943 1.1 skrll else
3944 1.1 skrll relocation = (sgot->output_section->vma + sgot->output_offset
3945 1.1 skrll + off);
3946 1.1 skrll }
3947 1.1.1.2 christos break;
3948 1.1.1.2 christos
3949 1.1.1.2 christos case R_68K_TLS_LDO32:
3950 1.1.1.2 christos case R_68K_TLS_LDO16:
3951 1.1.1.2 christos case R_68K_TLS_LDO8:
3952 1.1.1.2 christos relocation -= dtpoff_base (info);
3953 1.1.1.2 christos break;
3954 1.1.1.2 christos
3955 1.1.1.2 christos case R_68K_TLS_LE32:
3956 1.1.1.2 christos case R_68K_TLS_LE16:
3957 1.1.1.2 christos case R_68K_TLS_LE8:
3958 1.1.1.2 christos if (info->shared)
3959 1.1.1.2 christos {
3960 1.1.1.2 christos (*_bfd_error_handler)
3961 1.1.1.2 christos (_("%B(%A+0x%lx): R_68K_TLS_LE32 relocation not permitted "
3962 1.1.1.2 christos "in shared object"),
3963 1.1.1.2 christos input_bfd, input_section, (long) rel->r_offset, howto->name);
3964 1.1.1.2 christos
3965 1.1.1.2 christos return FALSE;
3966 1.1.1.2 christos }
3967 1.1.1.2 christos else
3968 1.1.1.2 christos relocation -= tpoff_base (info);
3969 1.1.1.2 christos
3970 1.1 skrll break;
3971 1.1 skrll
3972 1.1 skrll case R_68K_PLT8:
3973 1.1 skrll case R_68K_PLT16:
3974 1.1 skrll case R_68K_PLT32:
3975 1.1 skrll /* Relocation is to the entry for this symbol in the
3976 1.1 skrll procedure linkage table. */
3977 1.1 skrll
3978 1.1 skrll /* Resolve a PLTxx reloc against a local symbol directly,
3979 1.1 skrll without using the procedure linkage table. */
3980 1.1 skrll if (h == NULL)
3981 1.1 skrll break;
3982 1.1 skrll
3983 1.1 skrll if (h->plt.offset == (bfd_vma) -1
3984 1.1 skrll || !elf_hash_table (info)->dynamic_sections_created)
3985 1.1 skrll {
3986 1.1 skrll /* We didn't make a PLT entry for this symbol. This
3987 1.1 skrll happens when statically linking PIC code, or when
3988 1.1 skrll using -Bsymbolic. */
3989 1.1 skrll break;
3990 1.1 skrll }
3991 1.1 skrll
3992 1.1 skrll if (splt == NULL)
3993 1.1 skrll {
3994 1.1 skrll splt = bfd_get_section_by_name (dynobj, ".plt");
3995 1.1 skrll BFD_ASSERT (splt != NULL);
3996 1.1 skrll }
3997 1.1 skrll
3998 1.1 skrll relocation = (splt->output_section->vma
3999 1.1 skrll + splt->output_offset
4000 1.1 skrll + h->plt.offset);
4001 1.1 skrll unresolved_reloc = FALSE;
4002 1.1 skrll break;
4003 1.1 skrll
4004 1.1 skrll case R_68K_PLT8O:
4005 1.1 skrll case R_68K_PLT16O:
4006 1.1 skrll case R_68K_PLT32O:
4007 1.1 skrll /* Relocation is the offset of the entry for this symbol in
4008 1.1 skrll the procedure linkage table. */
4009 1.1 skrll BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
4010 1.1 skrll
4011 1.1 skrll if (splt == NULL)
4012 1.1 skrll {
4013 1.1 skrll splt = bfd_get_section_by_name (dynobj, ".plt");
4014 1.1 skrll BFD_ASSERT (splt != NULL);
4015 1.1 skrll }
4016 1.1 skrll
4017 1.1 skrll relocation = h->plt.offset;
4018 1.1 skrll unresolved_reloc = FALSE;
4019 1.1 skrll
4020 1.1 skrll /* This relocation does not use the addend. */
4021 1.1 skrll rel->r_addend = 0;
4022 1.1 skrll
4023 1.1 skrll break;
4024 1.1 skrll
4025 1.1 skrll case R_68K_8:
4026 1.1.1.2 christos case R_68K_16:
4027 1.1.1.2 christos case R_68K_32:
4028 1.1.1.2 christos case R_68K_PC8:
4029 1.1 skrll case R_68K_PC16:
4030 1.1.1.2 christos case R_68K_PC32:
4031 1.1 skrll if (info->shared
4032 1.1 skrll && r_symndx != STN_UNDEF
4033 1.1 skrll && (input_section->flags & SEC_ALLOC) != 0
4034 1.1 skrll && (h == NULL
4035 1.1 skrll || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4036 1.1 skrll || h->root.type != bfd_link_hash_undefweak)
4037 1.1 skrll && ((r_type != R_68K_PC8
4038 1.1.1.2 christos && r_type != R_68K_PC16
4039 1.1 skrll && r_type != R_68K_PC32)
4040 1.1 skrll || !SYMBOL_CALLS_LOCAL (info, h)))
4041 1.1 skrll {
4042 1.1 skrll Elf_Internal_Rela outrel;
4043 1.1 skrll bfd_byte *loc;
4044 1.1 skrll bfd_boolean skip, relocate;
4045 1.1 skrll
4046 1.1 skrll /* When generating a shared object, these relocations
4047 1.1 skrll are copied into the output file to be resolved at run
4048 1.1 skrll time. */
4049 1.1 skrll
4050 1.1 skrll skip = FALSE;
4051 1.1 skrll relocate = FALSE;
4052 1.1 skrll
4053 1.1 skrll outrel.r_offset =
4054 1.1 skrll _bfd_elf_section_offset (output_bfd, info, input_section,
4055 1.1 skrll rel->r_offset);
4056 1.1 skrll if (outrel.r_offset == (bfd_vma) -1)
4057 1.1 skrll skip = TRUE;
4058 1.1 skrll else if (outrel.r_offset == (bfd_vma) -2)
4059 1.1 skrll skip = TRUE, relocate = TRUE;
4060 1.1 skrll outrel.r_offset += (input_section->output_section->vma
4061 1.1 skrll + input_section->output_offset);
4062 1.1 skrll
4063 1.1 skrll if (skip)
4064 1.1 skrll memset (&outrel, 0, sizeof outrel);
4065 1.1 skrll else if (h != NULL
4066 1.1 skrll && h->dynindx != -1
4067 1.1 skrll && (r_type == R_68K_PC8
4068 1.1 skrll || r_type == R_68K_PC16
4069 1.1 skrll || r_type == R_68K_PC32
4070 1.1 skrll || !info->shared
4071 1.1 skrll || !info->symbolic
4072 1.1 skrll || !h->def_regular))
4073 1.1 skrll {
4074 1.1 skrll outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4075 1.1 skrll outrel.r_addend = rel->r_addend;
4076 1.1 skrll }
4077 1.1 skrll else
4078 1.1 skrll {
4079 1.1 skrll /* This symbol is local, or marked to become local. */
4080 1.1 skrll outrel.r_addend = relocation + rel->r_addend;
4081 1.1 skrll
4082 1.1 skrll if (r_type == R_68K_32)
4083 1.1 skrll {
4084 1.1 skrll relocate = TRUE;
4085 1.1 skrll outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
4086 1.1 skrll }
4087 1.1 skrll else
4088 1.1 skrll {
4089 1.1 skrll long indx;
4090 1.1 skrll
4091 1.1 skrll if (bfd_is_abs_section (sec))
4092 1.1 skrll indx = 0;
4093 1.1 skrll else if (sec == NULL || sec->owner == NULL)
4094 1.1 skrll {
4095 1.1 skrll bfd_set_error (bfd_error_bad_value);
4096 1.1 skrll return FALSE;
4097 1.1 skrll }
4098 1.1 skrll else
4099 1.1 skrll {
4100 1.1 skrll asection *osec;
4101 1.1 skrll
4102 1.1 skrll /* We are turning this relocation into one
4103 1.1 skrll against a section symbol. It would be
4104 1.1 skrll proper to subtract the symbol's value,
4105 1.1 skrll osec->vma, from the emitted reloc addend,
4106 1.1 skrll but ld.so expects buggy relocs. */
4107 1.1 skrll osec = sec->output_section;
4108 1.1 skrll indx = elf_section_data (osec)->dynindx;
4109 1.1 skrll if (indx == 0)
4110 1.1 skrll {
4111 1.1 skrll struct elf_link_hash_table *htab;
4112 1.1 skrll htab = elf_hash_table (info);
4113 1.1 skrll osec = htab->text_index_section;
4114 1.1 skrll indx = elf_section_data (osec)->dynindx;
4115 1.1 skrll }
4116 1.1 skrll BFD_ASSERT (indx != 0);
4117 1.1 skrll }
4118 1.1 skrll
4119 1.1 skrll outrel.r_info = ELF32_R_INFO (indx, r_type);
4120 1.1 skrll }
4121 1.1 skrll }
4122 1.1 skrll
4123 1.1 skrll sreloc = elf_section_data (input_section)->sreloc;
4124 1.1 skrll if (sreloc == NULL)
4125 1.1 skrll abort ();
4126 1.1 skrll
4127 1.1 skrll loc = sreloc->contents;
4128 1.1 skrll loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4129 1.1 skrll bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4130 1.1 skrll
4131 1.1 skrll /* This reloc will be computed at runtime, so there's no
4132 1.1 skrll need to do anything now, except for R_68K_32
4133 1.1 skrll relocations that have been turned into
4134 1.1 skrll R_68K_RELATIVE. */
4135 1.1 skrll if (!relocate)
4136 1.1 skrll continue;
4137 1.1 skrll }
4138 1.1 skrll
4139 1.1 skrll break;
4140 1.1 skrll
4141 1.1 skrll case R_68K_GNU_VTINHERIT:
4142 1.1 skrll case R_68K_GNU_VTENTRY:
4143 1.1 skrll /* These are no-ops in the end. */
4144 1.1 skrll continue;
4145 1.1 skrll
4146 1.1 skrll default:
4147 1.1 skrll break;
4148 1.1 skrll }
4149 1.1 skrll
4150 1.1 skrll /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4151 1.1 skrll because such sections are not SEC_ALLOC and thus ld.so will
4152 1.1 skrll not process them. */
4153 1.1 skrll if (unresolved_reloc
4154 1.1 skrll && !((input_section->flags & SEC_DEBUGGING) != 0
4155 1.1 skrll && h->def_dynamic))
4156 1.1 skrll {
4157 1.1 skrll (*_bfd_error_handler)
4158 1.1 skrll (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4159 1.1 skrll input_bfd,
4160 1.1 skrll input_section,
4161 1.1 skrll (long) rel->r_offset,
4162 1.1 skrll howto->name,
4163 1.1 skrll h->root.root.string);
4164 1.1 skrll return FALSE;
4165 1.1.1.2 christos }
4166 1.1.1.2 christos
4167 1.1.1.2 christos if (r_symndx != STN_UNDEF
4168 1.1.1.2 christos && r_type != R_68K_NONE
4169 1.1.1.2 christos && (h == NULL
4170 1.1.1.2 christos || h->root.type == bfd_link_hash_defined
4171 1.1.1.2 christos || h->root.type == bfd_link_hash_defweak))
4172 1.1.1.2 christos {
4173 1.1.1.2 christos char sym_type;
4174 1.1.1.2 christos
4175 1.1.1.2 christos sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type;
4176 1.1.1.2 christos
4177 1.1.1.2 christos if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS))
4178 1.1.1.2 christos {
4179 1.1.1.2 christos const char *name;
4180 1.1.1.2 christos
4181 1.1.1.2 christos if (h != NULL)
4182 1.1.1.2 christos name = h->root.root.string;
4183 1.1.1.2 christos else
4184 1.1.1.2 christos {
4185 1.1.1.2 christos name = (bfd_elf_string_from_elf_section
4186 1.1.1.2 christos (input_bfd, symtab_hdr->sh_link, sym->st_name));
4187 1.1.1.2 christos if (name == NULL || *name == '\0')
4188 1.1.1.2 christos name = bfd_section_name (input_bfd, sec);
4189 1.1.1.2 christos }
4190 1.1.1.2 christos
4191 1.1.1.2 christos (*_bfd_error_handler)
4192 1.1.1.2 christos ((sym_type == STT_TLS
4193 1.1.1.2 christos ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4194 1.1.1.2 christos : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4195 1.1.1.2 christos input_bfd,
4196 1.1.1.2 christos input_section,
4197 1.1.1.2 christos (long) rel->r_offset,
4198 1.1.1.2 christos howto->name,
4199 1.1.1.2 christos name);
4200 1.1.1.2 christos }
4201 1.1 skrll }
4202 1.1 skrll
4203 1.1 skrll r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4204 1.1 skrll contents, rel->r_offset,
4205 1.1 skrll relocation, rel->r_addend);
4206 1.1 skrll
4207 1.1 skrll if (r != bfd_reloc_ok)
4208 1.1 skrll {
4209 1.1 skrll const char *name;
4210 1.1 skrll
4211 1.1 skrll if (h != NULL)
4212 1.1 skrll name = h->root.root.string;
4213 1.1 skrll else
4214 1.1 skrll {
4215 1.1 skrll name = bfd_elf_string_from_elf_section (input_bfd,
4216 1.1 skrll symtab_hdr->sh_link,
4217 1.1 skrll sym->st_name);
4218 1.1 skrll if (name == NULL)
4219 1.1 skrll return FALSE;
4220 1.1 skrll if (*name == '\0')
4221 1.1 skrll name = bfd_section_name (input_bfd, sec);
4222 1.1 skrll }
4223 1.1 skrll
4224 1.1 skrll if (r == bfd_reloc_overflow)
4225 1.1 skrll {
4226 1.1 skrll if (!(info->callbacks->reloc_overflow
4227 1.1 skrll (info, (h ? &h->root : NULL), name, howto->name,
4228 1.1 skrll (bfd_vma) 0, input_bfd, input_section,
4229 1.1 skrll rel->r_offset)))
4230 1.1 skrll return FALSE;
4231 1.1 skrll }
4232 1.1 skrll else
4233 1.1 skrll {
4234 1.1 skrll (*_bfd_error_handler)
4235 1.1 skrll (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4236 1.1 skrll input_bfd, input_section,
4237 1.1 skrll (long) rel->r_offset, name, (int) r);
4238 1.1 skrll return FALSE;
4239 1.1 skrll }
4240 1.1 skrll }
4241 1.1 skrll }
4242 1.1 skrll
4243 1.1 skrll return TRUE;
4244 1.1 skrll }
4245 1.1 skrll
4246 1.1 skrll /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4247 1.1 skrll into section SEC. */
4248 1.1 skrll
4249 1.1 skrll static void
4250 1.1 skrll elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
4251 1.1 skrll {
4252 1.1 skrll /* Make VALUE PC-relative. */
4253 1.1 skrll value -= sec->output_section->vma + offset;
4254 1.1 skrll
4255 1.1 skrll /* Apply any in-place addend. */
4256 1.1 skrll value += bfd_get_32 (sec->owner, sec->contents + offset);
4257 1.1 skrll
4258 1.1 skrll bfd_put_32 (sec->owner, value, sec->contents + offset);
4259 1.1 skrll }
4260 1.1 skrll
4261 1.1 skrll /* Finish up dynamic symbol handling. We set the contents of various
4262 1.1 skrll dynamic sections here. */
4263 1.1 skrll
4264 1.1 skrll static bfd_boolean
4265 1.1 skrll elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym)
4266 1.1 skrll bfd *output_bfd;
4267 1.1 skrll struct bfd_link_info *info;
4268 1.1 skrll struct elf_link_hash_entry *h;
4269 1.1 skrll Elf_Internal_Sym *sym;
4270 1.1 skrll {
4271 1.1 skrll bfd *dynobj;
4272 1.1 skrll
4273 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
4274 1.1 skrll
4275 1.1 skrll if (h->plt.offset != (bfd_vma) -1)
4276 1.1 skrll {
4277 1.1 skrll const struct elf_m68k_plt_info *plt_info;
4278 1.1 skrll asection *splt;
4279 1.1 skrll asection *sgot;
4280 1.1 skrll asection *srela;
4281 1.1 skrll bfd_vma plt_index;
4282 1.1 skrll bfd_vma got_offset;
4283 1.1 skrll Elf_Internal_Rela rela;
4284 1.1 skrll bfd_byte *loc;
4285 1.1 skrll
4286 1.1 skrll /* This symbol has an entry in the procedure linkage table. Set
4287 1.1 skrll it up. */
4288 1.1 skrll
4289 1.1 skrll BFD_ASSERT (h->dynindx != -1);
4290 1.1 skrll
4291 1.1 skrll plt_info = elf_m68k_hash_table (info)->plt_info;
4292 1.1 skrll splt = bfd_get_section_by_name (dynobj, ".plt");
4293 1.1 skrll sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4294 1.1 skrll srela = bfd_get_section_by_name (dynobj, ".rela.plt");
4295 1.1 skrll BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
4296 1.1 skrll
4297 1.1 skrll /* Get the index in the procedure linkage table which
4298 1.1 skrll corresponds to this symbol. This is the index of this symbol
4299 1.1 skrll in all the symbols for which we are making plt entries. The
4300 1.1 skrll first entry in the procedure linkage table is reserved. */
4301 1.1 skrll plt_index = (h->plt.offset / plt_info->size) - 1;
4302 1.1 skrll
4303 1.1 skrll /* Get the offset into the .got table of the entry that
4304 1.1 skrll corresponds to this function. Each .got entry is 4 bytes.
4305 1.1 skrll The first three are reserved. */
4306 1.1 skrll got_offset = (plt_index + 3) * 4;
4307 1.1 skrll
4308 1.1 skrll memcpy (splt->contents + h->plt.offset,
4309 1.1 skrll plt_info->symbol_entry,
4310 1.1 skrll plt_info->size);
4311 1.1 skrll
4312 1.1 skrll elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
4313 1.1 skrll (sgot->output_section->vma
4314 1.1 skrll + sgot->output_offset
4315 1.1 skrll + got_offset));
4316 1.1 skrll
4317 1.1 skrll bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4318 1.1 skrll splt->contents
4319 1.1 skrll + h->plt.offset
4320 1.1 skrll + plt_info->symbol_resolve_entry + 2);
4321 1.1 skrll
4322 1.1 skrll elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
4323 1.1 skrll splt->output_section->vma);
4324 1.1 skrll
4325 1.1 skrll /* Fill in the entry in the global offset table. */
4326 1.1 skrll bfd_put_32 (output_bfd,
4327 1.1 skrll (splt->output_section->vma
4328 1.1 skrll + splt->output_offset
4329 1.1 skrll + h->plt.offset
4330 1.1 skrll + plt_info->symbol_resolve_entry),
4331 1.1 skrll sgot->contents + got_offset);
4332 1.1 skrll
4333 1.1 skrll /* Fill in the entry in the .rela.plt section. */
4334 1.1 skrll rela.r_offset = (sgot->output_section->vma
4335 1.1 skrll + sgot->output_offset
4336 1.1 skrll + got_offset);
4337 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
4338 1.1 skrll rela.r_addend = 0;
4339 1.1 skrll loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
4340 1.1 skrll bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4341 1.1 skrll
4342 1.1 skrll if (!h->def_regular)
4343 1.1 skrll {
4344 1.1 skrll /* Mark the symbol as undefined, rather than as defined in
4345 1.1 skrll the .plt section. Leave the value alone. */
4346 1.1 skrll sym->st_shndx = SHN_UNDEF;
4347 1.1 skrll }
4348 1.1 skrll }
4349 1.1 skrll
4350 1.1 skrll if (elf_m68k_hash_entry (h)->glist != NULL)
4351 1.1 skrll {
4352 1.1 skrll asection *sgot;
4353 1.1 skrll asection *srela;
4354 1.1 skrll struct elf_m68k_got_entry *got_entry;
4355 1.1 skrll
4356 1.1 skrll /* This symbol has an entry in the global offset table. Set it
4357 1.1 skrll up. */
4358 1.1 skrll
4359 1.1 skrll sgot = bfd_get_section_by_name (dynobj, ".got");
4360 1.1 skrll srela = bfd_get_section_by_name (dynobj, ".rela.got");
4361 1.1 skrll BFD_ASSERT (sgot != NULL && srela != NULL);
4362 1.1 skrll
4363 1.1 skrll got_entry = elf_m68k_hash_entry (h)->glist;
4364 1.1 skrll
4365 1.1.1.2 christos while (got_entry != NULL)
4366 1.1.1.2 christos {
4367 1.1 skrll enum elf_m68k_reloc_type r_type;
4368 1.1.1.2 christos bfd_vma got_entry_offset;
4369 1.1.1.2 christos
4370 1.1 skrll r_type = got_entry->key_.type;
4371 1.1 skrll got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1;
4372 1.1 skrll
4373 1.1 skrll /* If this is a -Bsymbolic link, and the symbol is defined
4374 1.1.1.2 christos locally, we just want to emit a RELATIVE reloc. Likewise if
4375 1.1 skrll the symbol was forced to be local because of a version file.
4376 1.1 skrll The entry in the global offset table already have been
4377 1.1.1.2 christos initialized in the relocate_section function. */
4378 1.1 skrll if (info->shared
4379 1.1.1.2 christos && SYMBOL_REFERENCES_LOCAL (info, h))
4380 1.1.1.2 christos {
4381 1.1.1.2 christos bfd_vma relocation;
4382 1.1.1.2 christos
4383 1.1.1.2 christos relocation = bfd_get_signed_32 (output_bfd,
4384 1.1.1.2 christos (sgot->contents
4385 1.1.1.2 christos + got_entry_offset));
4386 1.1.1.2 christos
4387 1.1.1.2 christos /* Undo TP bias. */
4388 1.1.1.2 christos switch (elf_m68k_reloc_got_type (r_type))
4389 1.1.1.2 christos {
4390 1.1.1.2 christos case R_68K_GOT32O:
4391 1.1.1.2 christos case R_68K_TLS_LDM32:
4392 1.1.1.2 christos break;
4393 1.1.1.2 christos
4394 1.1.1.2 christos case R_68K_TLS_GD32:
4395 1.1.1.2 christos relocation += dtpoff_base (info);
4396 1.1.1.2 christos break;
4397 1.1.1.2 christos
4398 1.1.1.2 christos case R_68K_TLS_IE32:
4399 1.1.1.2 christos relocation += tpoff_base (info);
4400 1.1.1.2 christos break;
4401 1.1.1.2 christos
4402 1.1.1.2 christos default:
4403 1.1.1.2 christos BFD_ASSERT (FALSE);
4404 1.1.1.2 christos }
4405 1.1.1.2 christos
4406 1.1.1.2 christos elf_m68k_init_got_entry_local_shared (info,
4407 1.1.1.2 christos output_bfd,
4408 1.1.1.2 christos r_type,
4409 1.1.1.2 christos sgot,
4410 1.1.1.2 christos got_entry_offset,
4411 1.1 skrll relocation,
4412 1.1 skrll srela);
4413 1.1 skrll }
4414 1.1.1.2 christos else
4415 1.1.1.2 christos {
4416 1.1.1.2 christos Elf_Internal_Rela rela;
4417 1.1.1.2 christos
4418 1.1.1.2 christos /* Put zeros to GOT slots that will be initialized
4419 1.1.1.2 christos at run-time. */
4420 1.1.1.2 christos {
4421 1.1.1.2 christos bfd_vma n_slots;
4422 1.1.1.2 christos
4423 1.1.1.2 christos n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type);
4424 1.1.1.2 christos while (n_slots--)
4425 1.1.1.2 christos bfd_put_32 (output_bfd, (bfd_vma) 0,
4426 1.1.1.2 christos (sgot->contents + got_entry_offset
4427 1.1.1.2 christos + 4 * n_slots));
4428 1.1 skrll }
4429 1.1.1.2 christos
4430 1.1.1.2 christos rela.r_addend = 0;
4431 1.1.1.2 christos rela.r_offset = (sgot->output_section->vma
4432 1.1 skrll + sgot->output_offset
4433 1.1.1.2 christos + got_entry_offset);
4434 1.1.1.2 christos
4435 1.1.1.2 christos switch (elf_m68k_reloc_got_type (r_type))
4436 1.1.1.2 christos {
4437 1.1.1.2 christos case R_68K_GOT32O:
4438 1.1.1.2 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
4439 1.1.1.2 christos elf_m68k_install_rela (output_bfd, srela, &rela);
4440 1.1.1.2 christos break;
4441 1.1.1.2 christos
4442 1.1.1.2 christos case R_68K_TLS_GD32:
4443 1.1.1.2 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32);
4444 1.1.1.2 christos elf_m68k_install_rela (output_bfd, srela, &rela);
4445 1.1.1.2 christos
4446 1.1.1.2 christos rela.r_offset += 4;
4447 1.1.1.2 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32);
4448 1.1.1.2 christos elf_m68k_install_rela (output_bfd, srela, &rela);
4449 1.1.1.2 christos break;
4450 1.1.1.2 christos
4451 1.1.1.2 christos case R_68K_TLS_IE32:
4452 1.1.1.2 christos rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32);
4453 1.1.1.2 christos elf_m68k_install_rela (output_bfd, srela, &rela);
4454 1.1.1.2 christos break;
4455 1.1.1.2 christos
4456 1.1.1.2 christos default:
4457 1.1.1.2 christos BFD_ASSERT (FALSE);
4458 1.1.1.2 christos break;
4459 1.1 skrll }
4460 1.1 skrll }
4461 1.1 skrll
4462 1.1 skrll got_entry = got_entry->u.s2.next;
4463 1.1 skrll }
4464 1.1 skrll }
4465 1.1 skrll
4466 1.1 skrll if (h->needs_copy)
4467 1.1 skrll {
4468 1.1 skrll asection *s;
4469 1.1 skrll Elf_Internal_Rela rela;
4470 1.1 skrll bfd_byte *loc;
4471 1.1 skrll
4472 1.1 skrll /* This symbol needs a copy reloc. Set it up. */
4473 1.1 skrll
4474 1.1 skrll BFD_ASSERT (h->dynindx != -1
4475 1.1 skrll && (h->root.type == bfd_link_hash_defined
4476 1.1 skrll || h->root.type == bfd_link_hash_defweak));
4477 1.1 skrll
4478 1.1 skrll s = bfd_get_section_by_name (h->root.u.def.section->owner,
4479 1.1 skrll ".rela.bss");
4480 1.1 skrll BFD_ASSERT (s != NULL);
4481 1.1 skrll
4482 1.1 skrll rela.r_offset = (h->root.u.def.value
4483 1.1 skrll + h->root.u.def.section->output_section->vma
4484 1.1 skrll + h->root.u.def.section->output_offset);
4485 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
4486 1.1 skrll rela.r_addend = 0;
4487 1.1 skrll loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4488 1.1 skrll bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4489 1.1 skrll }
4490 1.1 skrll
4491 1.1 skrll /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4492 1.1 skrll if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4493 1.1 skrll || h == elf_hash_table (info)->hgot)
4494 1.1 skrll sym->st_shndx = SHN_ABS;
4495 1.1 skrll
4496 1.1 skrll return TRUE;
4497 1.1 skrll }
4498 1.1 skrll
4499 1.1 skrll /* Finish up the dynamic sections. */
4500 1.1 skrll
4501 1.1 skrll static bfd_boolean
4502 1.1 skrll elf_m68k_finish_dynamic_sections (output_bfd, info)
4503 1.1 skrll bfd *output_bfd;
4504 1.1 skrll struct bfd_link_info *info;
4505 1.1 skrll {
4506 1.1 skrll bfd *dynobj;
4507 1.1 skrll asection *sgot;
4508 1.1 skrll asection *sdyn;
4509 1.1 skrll
4510 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
4511 1.1 skrll
4512 1.1 skrll sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4513 1.1 skrll BFD_ASSERT (sgot != NULL);
4514 1.1 skrll sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4515 1.1 skrll
4516 1.1 skrll if (elf_hash_table (info)->dynamic_sections_created)
4517 1.1 skrll {
4518 1.1 skrll asection *splt;
4519 1.1 skrll Elf32_External_Dyn *dyncon, *dynconend;
4520 1.1 skrll
4521 1.1 skrll splt = bfd_get_section_by_name (dynobj, ".plt");
4522 1.1 skrll BFD_ASSERT (splt != NULL && sdyn != NULL);
4523 1.1 skrll
4524 1.1 skrll dyncon = (Elf32_External_Dyn *) sdyn->contents;
4525 1.1 skrll dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4526 1.1 skrll for (; dyncon < dynconend; dyncon++)
4527 1.1 skrll {
4528 1.1 skrll Elf_Internal_Dyn dyn;
4529 1.1 skrll const char *name;
4530 1.1 skrll asection *s;
4531 1.1 skrll
4532 1.1 skrll bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4533 1.1 skrll
4534 1.1 skrll switch (dyn.d_tag)
4535 1.1 skrll {
4536 1.1 skrll default:
4537 1.1 skrll break;
4538 1.1 skrll
4539 1.1 skrll case DT_PLTGOT:
4540 1.1 skrll name = ".got";
4541 1.1 skrll goto get_vma;
4542 1.1 skrll case DT_JMPREL:
4543 1.1 skrll name = ".rela.plt";
4544 1.1 skrll get_vma:
4545 1.1 skrll s = bfd_get_section_by_name (output_bfd, name);
4546 1.1 skrll BFD_ASSERT (s != NULL);
4547 1.1 skrll dyn.d_un.d_ptr = s->vma;
4548 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4549 1.1 skrll break;
4550 1.1 skrll
4551 1.1 skrll case DT_PLTRELSZ:
4552 1.1 skrll s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4553 1.1 skrll BFD_ASSERT (s != NULL);
4554 1.1 skrll dyn.d_un.d_val = s->size;
4555 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4556 1.1 skrll break;
4557 1.1 skrll
4558 1.1 skrll case DT_RELASZ:
4559 1.1 skrll /* The procedure linkage table relocs (DT_JMPREL) should
4560 1.1 skrll not be included in the overall relocs (DT_RELA).
4561 1.1 skrll Therefore, we override the DT_RELASZ entry here to
4562 1.1 skrll make it not include the JMPREL relocs. Since the
4563 1.1 skrll linker script arranges for .rela.plt to follow all
4564 1.1 skrll other relocation sections, we don't have to worry
4565 1.1 skrll about changing the DT_RELA entry. */
4566 1.1 skrll s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4567 1.1 skrll if (s != NULL)
4568 1.1 skrll dyn.d_un.d_val -= s->size;
4569 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4570 1.1 skrll break;
4571 1.1 skrll }
4572 1.1 skrll }
4573 1.1 skrll
4574 1.1 skrll /* Fill in the first entry in the procedure linkage table. */
4575 1.1 skrll if (splt->size > 0)
4576 1.1 skrll {
4577 1.1 skrll const struct elf_m68k_plt_info *plt_info;
4578 1.1 skrll
4579 1.1 skrll plt_info = elf_m68k_hash_table (info)->plt_info;
4580 1.1 skrll memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
4581 1.1 skrll
4582 1.1 skrll elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
4583 1.1 skrll (sgot->output_section->vma
4584 1.1 skrll + sgot->output_offset
4585 1.1 skrll + 4));
4586 1.1 skrll
4587 1.1 skrll elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
4588 1.1 skrll (sgot->output_section->vma
4589 1.1 skrll + sgot->output_offset
4590 1.1 skrll + 8));
4591 1.1 skrll
4592 1.1 skrll elf_section_data (splt->output_section)->this_hdr.sh_entsize
4593 1.1 skrll = plt_info->size;
4594 1.1 skrll }
4595 1.1 skrll }
4596 1.1 skrll
4597 1.1 skrll /* Fill in the first three entries in the global offset table. */
4598 1.1 skrll if (sgot->size > 0)
4599 1.1 skrll {
4600 1.1 skrll if (sdyn == NULL)
4601 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4602 1.1 skrll else
4603 1.1 skrll bfd_put_32 (output_bfd,
4604 1.1 skrll sdyn->output_section->vma + sdyn->output_offset,
4605 1.1 skrll sgot->contents);
4606 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4607 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4608 1.1 skrll }
4609 1.1 skrll
4610 1.1 skrll elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4611 1.1 skrll
4612 1.1 skrll return TRUE;
4613 1.1 skrll }
4614 1.1 skrll
4615 1.1 skrll /* Given a .data section and a .emreloc in-memory section, store
4616 1.1 skrll relocation information into the .emreloc section which can be
4617 1.1 skrll used at runtime to relocate the section. This is called by the
4618 1.1 skrll linker when the --embedded-relocs switch is used. This is called
4619 1.1 skrll after the add_symbols entry point has been called for all the
4620 1.1 skrll objects, and before the final_link entry point is called. */
4621 1.1 skrll
4622 1.1 skrll bfd_boolean
4623 1.1 skrll bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
4624 1.1 skrll bfd *abfd;
4625 1.1 skrll struct bfd_link_info *info;
4626 1.1 skrll asection *datasec;
4627 1.1 skrll asection *relsec;
4628 1.1 skrll char **errmsg;
4629 1.1 skrll {
4630 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
4631 1.1 skrll Elf_Internal_Sym *isymbuf = NULL;
4632 1.1 skrll Elf_Internal_Rela *internal_relocs = NULL;
4633 1.1 skrll Elf_Internal_Rela *irel, *irelend;
4634 1.1 skrll bfd_byte *p;
4635 1.1 skrll bfd_size_type amt;
4636 1.1 skrll
4637 1.1 skrll BFD_ASSERT (! info->relocatable);
4638 1.1 skrll
4639 1.1 skrll *errmsg = NULL;
4640 1.1 skrll
4641 1.1 skrll if (datasec->reloc_count == 0)
4642 1.1 skrll return TRUE;
4643 1.1 skrll
4644 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4645 1.1 skrll
4646 1.1 skrll /* Get a copy of the native relocations. */
4647 1.1 skrll internal_relocs = (_bfd_elf_link_read_relocs
4648 1.1 skrll (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
4649 1.1 skrll info->keep_memory));
4650 1.1 skrll if (internal_relocs == NULL)
4651 1.1 skrll goto error_return;
4652 1.1 skrll
4653 1.1 skrll amt = (bfd_size_type) datasec->reloc_count * 12;
4654 1.1 skrll relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
4655 1.1 skrll if (relsec->contents == NULL)
4656 1.1 skrll goto error_return;
4657 1.1 skrll
4658 1.1 skrll p = relsec->contents;
4659 1.1 skrll
4660 1.1 skrll irelend = internal_relocs + datasec->reloc_count;
4661 1.1 skrll for (irel = internal_relocs; irel < irelend; irel++, p += 12)
4662 1.1 skrll {
4663 1.1 skrll asection *targetsec;
4664 1.1 skrll
4665 1.1 skrll /* We are going to write a four byte longword into the runtime
4666 1.1 skrll reloc section. The longword will be the address in the data
4667 1.1 skrll section which must be relocated. It is followed by the name
4668 1.1 skrll of the target section NUL-padded or truncated to 8
4669 1.1 skrll characters. */
4670 1.1 skrll
4671 1.1 skrll /* We can only relocate absolute longword relocs at run time. */
4672 1.1 skrll if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
4673 1.1 skrll {
4674 1.1 skrll *errmsg = _("unsupported reloc type");
4675 1.1 skrll bfd_set_error (bfd_error_bad_value);
4676 1.1 skrll goto error_return;
4677 1.1 skrll }
4678 1.1 skrll
4679 1.1 skrll /* Get the target section referred to by the reloc. */
4680 1.1 skrll if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4681 1.1 skrll {
4682 1.1 skrll /* A local symbol. */
4683 1.1 skrll Elf_Internal_Sym *isym;
4684 1.1 skrll
4685 1.1 skrll /* Read this BFD's local symbols if we haven't done so already. */
4686 1.1 skrll if (isymbuf == NULL)
4687 1.1 skrll {
4688 1.1 skrll isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4689 1.1 skrll if (isymbuf == NULL)
4690 1.1 skrll isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4691 1.1 skrll symtab_hdr->sh_info, 0,
4692 1.1 skrll NULL, NULL, NULL);
4693 1.1 skrll if (isymbuf == NULL)
4694 1.1 skrll goto error_return;
4695 1.1 skrll }
4696 1.1 skrll
4697 1.1 skrll isym = isymbuf + ELF32_R_SYM (irel->r_info);
4698 1.1 skrll targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4699 1.1 skrll }
4700 1.1 skrll else
4701 1.1 skrll {
4702 1.1 skrll unsigned long indx;
4703 1.1 skrll struct elf_link_hash_entry *h;
4704 1.1 skrll
4705 1.1 skrll /* An external symbol. */
4706 1.1 skrll indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4707 1.1 skrll h = elf_sym_hashes (abfd)[indx];
4708 1.1 skrll BFD_ASSERT (h != NULL);
4709 1.1 skrll if (h->root.type == bfd_link_hash_defined
4710 1.1 skrll || h->root.type == bfd_link_hash_defweak)
4711 1.1 skrll targetsec = h->root.u.def.section;
4712 1.1 skrll else
4713 1.1 skrll targetsec = NULL;
4714 1.1 skrll }
4715 1.1 skrll
4716 1.1 skrll bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
4717 1.1 skrll memset (p + 4, 0, 8);
4718 1.1 skrll if (targetsec != NULL)
4719 1.1 skrll strncpy ((char *) p + 4, targetsec->output_section->name, 8);
4720 1.1 skrll }
4721 1.1 skrll
4722 1.1 skrll if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4723 1.1 skrll free (isymbuf);
4724 1.1 skrll if (internal_relocs != NULL
4725 1.1 skrll && elf_section_data (datasec)->relocs != internal_relocs)
4726 1.1 skrll free (internal_relocs);
4727 1.1 skrll return TRUE;
4728 1.1 skrll
4729 1.1 skrll error_return:
4730 1.1 skrll if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4731 1.1 skrll free (isymbuf);
4732 1.1 skrll if (internal_relocs != NULL
4733 1.1 skrll && elf_section_data (datasec)->relocs != internal_relocs)
4734 1.1 skrll free (internal_relocs);
4735 1.1 skrll return FALSE;
4736 1.1 skrll }
4737 1.1 skrll
4738 1.1 skrll /* Set target options. */
4739 1.1 skrll
4740 1.1 skrll void
4741 1.1 skrll bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
4742 1.1.1.2 christos {
4743 1.1.1.2 christos struct elf_m68k_link_hash_table *htab;
4744 1.1.1.2 christos bfd_boolean use_neg_got_offsets_p;
4745 1.1 skrll bfd_boolean allow_multigot_p;
4746 1.1 skrll bfd_boolean local_gp_p;
4747 1.1 skrll
4748 1.1 skrll switch (got_handling)
4749 1.1 skrll {
4750 1.1.1.2 christos case 0:
4751 1.1.1.2 christos /* --got=single. */
4752 1.1.1.2 christos local_gp_p = FALSE;
4753 1.1 skrll use_neg_got_offsets_p = FALSE;
4754 1.1 skrll allow_multigot_p = FALSE;
4755 1.1 skrll break;
4756 1.1 skrll
4757 1.1.1.2 christos case 1:
4758 1.1.1.2 christos /* --got=negative. */
4759 1.1.1.2 christos local_gp_p = TRUE;
4760 1.1 skrll use_neg_got_offsets_p = TRUE;
4761 1.1 skrll allow_multigot_p = FALSE;
4762 1.1 skrll break;
4763 1.1 skrll
4764 1.1.1.2 christos case 2:
4765 1.1.1.2 christos /* --got=multigot. */
4766 1.1.1.2 christos local_gp_p = TRUE;
4767 1.1 skrll use_neg_got_offsets_p = TRUE;
4768 1.1 skrll allow_multigot_p = TRUE;
4769 1.1 skrll break;
4770 1.1 skrll
4771 1.1.1.2 christos default:
4772 1.1.1.2 christos BFD_ASSERT (FALSE);
4773 1.1.1.2 christos return;
4774 1.1.1.2 christos }
4775 1.1.1.2 christos
4776 1.1.1.2 christos htab = elf_m68k_hash_table (info);
4777 1.1.1.2 christos if (htab != NULL)
4778 1.1.1.2 christos {
4779 1.1.1.2 christos htab->local_gp_p = local_gp_p;
4780 1.1 skrll htab->use_neg_got_offsets_p = use_neg_got_offsets_p;
4781 1.1 skrll htab->allow_multigot_p = allow_multigot_p;
4782 1.1 skrll }
4783 1.1 skrll }
4784 1.1 skrll
4785 1.1 skrll static enum elf_reloc_type_class
4786 1.1 skrll elf32_m68k_reloc_type_class (rela)
4787 1.1 skrll const Elf_Internal_Rela *rela;
4788 1.1 skrll {
4789 1.1 skrll switch ((int) ELF32_R_TYPE (rela->r_info))
4790 1.1 skrll {
4791 1.1 skrll case R_68K_RELATIVE:
4792 1.1 skrll return reloc_class_relative;
4793 1.1 skrll case R_68K_JMP_SLOT:
4794 1.1 skrll return reloc_class_plt;
4795 1.1 skrll case R_68K_COPY:
4796 1.1 skrll return reloc_class_copy;
4797 1.1 skrll default:
4798 1.1 skrll return reloc_class_normal;
4799 1.1 skrll }
4800 1.1 skrll }
4801 1.1 skrll
4802 1.1 skrll /* Return address for Ith PLT stub in section PLT, for relocation REL
4803 1.1 skrll or (bfd_vma) -1 if it should not be included. */
4804 1.1 skrll
4805 1.1 skrll static bfd_vma
4806 1.1 skrll elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
4807 1.1 skrll const arelent *rel ATTRIBUTE_UNUSED)
4808 1.1 skrll {
4809 1.1 skrll return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
4810 1.1 skrll }
4811 1.1 skrll
4812 1.1 skrll #define TARGET_BIG_SYM bfd_elf32_m68k_vec
4813 1.1 skrll #define TARGET_BIG_NAME "elf32-m68k"
4814 1.1 skrll #define ELF_MACHINE_CODE EM_68K
4815 1.1 skrll #define ELF_MAXPAGESIZE 0x2000
4816 1.1 skrll #define elf_backend_create_dynamic_sections \
4817 1.1 skrll _bfd_elf_create_dynamic_sections
4818 1.1 skrll #define bfd_elf32_bfd_link_hash_table_create \
4819 1.1 skrll elf_m68k_link_hash_table_create
4820 1.1 skrll /* ??? Should it be this macro or bfd_elfNN_bfd_link_hash_table_create? */
4821 1.1 skrll #define bfd_elf32_bfd_link_hash_table_free \
4822 1.1 skrll elf_m68k_link_hash_table_free
4823 1.1 skrll #define bfd_elf32_bfd_final_link bfd_elf_final_link
4824 1.1 skrll
4825 1.1 skrll #define elf_backend_check_relocs elf_m68k_check_relocs
4826 1.1 skrll #define elf_backend_always_size_sections \
4827 1.1 skrll elf_m68k_always_size_sections
4828 1.1 skrll #define elf_backend_adjust_dynamic_symbol \
4829 1.1 skrll elf_m68k_adjust_dynamic_symbol
4830 1.1.1.2 christos #define elf_backend_size_dynamic_sections \
4831 1.1 skrll elf_m68k_size_dynamic_sections
4832 1.1 skrll #define elf_backend_final_write_processing elf_m68k_final_write_processing
4833 1.1 skrll #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4834 1.1 skrll #define elf_backend_relocate_section elf_m68k_relocate_section
4835 1.1 skrll #define elf_backend_finish_dynamic_symbol \
4836 1.1 skrll elf_m68k_finish_dynamic_symbol
4837 1.1 skrll #define elf_backend_finish_dynamic_sections \
4838 1.1 skrll elf_m68k_finish_dynamic_sections
4839 1.1 skrll #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4840 1.1 skrll #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
4841 1.1 skrll #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4842 1.1 skrll #define bfd_elf32_bfd_merge_private_bfd_data \
4843 1.1 skrll elf32_m68k_merge_private_bfd_data
4844 1.1 skrll #define bfd_elf32_bfd_set_private_flags \
4845 1.1 skrll elf32_m68k_set_private_flags
4846 1.1 skrll #define bfd_elf32_bfd_print_private_bfd_data \
4847 1.1 skrll elf32_m68k_print_private_bfd_data
4848 1.1 skrll #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4849 1.1 skrll #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4850 1.1 skrll #define elf_backend_object_p elf32_m68k_object_p
4851 1.1 skrll
4852 1.1 skrll #define elf_backend_can_gc_sections 1
4853 1.1 skrll #define elf_backend_can_refcount 1
4854 1.1 skrll #define elf_backend_want_got_plt 1
4855 1.1 skrll #define elf_backend_plt_readonly 1
4856 1.1 skrll #define elf_backend_want_plt_sym 0
4857 1.1 skrll #define elf_backend_got_header_size 12
4858 1.1 skrll #define elf_backend_rela_normal 1
4859
4860 #include "elf32-target.h"
4861