elf32-m32r.c revision 1.1.1.9 1 1.1 skrll /* M32R-specific support for 32-bit ELF.
2 1.1.1.9 christos Copyright (C) 1996-2022 Free Software Foundation, Inc.
3 1.1 skrll
4 1.1 skrll This file is part of BFD, the Binary File Descriptor library.
5 1.1 skrll
6 1.1 skrll This program is free software; you can redistribute it and/or modify
7 1.1 skrll it under the terms of the GNU General Public License as published by
8 1.1 skrll the Free Software Foundation; either version 3 of the License, or
9 1.1 skrll (at your option) any later version.
10 1.1 skrll
11 1.1 skrll This program is distributed in the hope that it will be useful,
12 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 skrll GNU General Public License for more details.
15 1.1 skrll
16 1.1 skrll You should have received a copy of the GNU General Public License
17 1.1 skrll along with this program; if not, write to the Free Software
18 1.1 skrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 1.1 skrll MA 02110-1301, USA. */
20 1.1 skrll
21 1.1 skrll #include "sysdep.h"
22 1.1 skrll #include "bfd.h"
23 1.1 skrll #include "libbfd.h"
24 1.1 skrll #include "elf-bfd.h"
25 1.1 skrll #include "elf/m32r.h"
26 1.1 skrll
27 1.1 skrll #define NOP_INSN 0x7000
28 1.1 skrll #define MAKE_PARALLEL(insn) ((insn) | 0x8000)
29 1.1 skrll
30 1.1 skrll /* Use REL instead of RELA to save space.
31 1.1 skrll This only saves space in libraries and object files, but perhaps
32 1.1 skrll relocs will be put in ROM? All in all though, REL relocs are a pain
33 1.1 skrll to work with. */
34 1.1 skrll /* #define USE_REL 1
35 1.1 skrll
36 1.1 skrll #ifndef USE_REL
37 1.1 skrll #define USE_REL 0
38 1.1 skrll #endif */
39 1.1 skrll /* Use RELA. But use REL to link old objects for backwords compatibility. */
40 1.1 skrll
41 1.1 skrll /* Functions for the M32R ELF linker. */
42 1.1 skrll
43 1.1 skrll /* The name of the dynamic interpreter. This is put in the .interp
44 1.1 skrll section. */
45 1.1 skrll
46 1.1 skrll #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
47 1.1 skrll
48 1.1 skrll /* The nop opcode we use. */
49 1.1 skrll
50 1.1 skrll #define M32R_NOP 0x7000f000
51 1.1 skrll
52 1.1 skrll #define PLT_EMPTY 0x10101010 /* RIE -> RIE */
53 1.1 skrll
54 1.1 skrll /* The size in bytes of an entry in the procedure linkage table. */
55 1.1 skrll
56 1.1 skrll #define PLT_ENTRY_SIZE 20
57 1.1 skrll #define PLT_HEADER_SIZE 20
58 1.1 skrll
59 1.1 skrll /* The first one entries in a procedure linkage table are reserved,
60 1.1 skrll and the initial contents are unimportant (we zero them out).
61 1.1 skrll Subsequent entries look like this. */
62 1.1 skrll
63 1.1.1.6 christos #define PLT0_ENTRY_WORD0 0xd6c00000 /* seth r6, #high(.got+4) */
64 1.1.1.6 christos #define PLT0_ENTRY_WORD1 0x86e60000 /* or3 r6, r6, #low(.got)+4) */
65 1.1.1.6 christos #define PLT0_ENTRY_WORD2 0x24e626c6 /* ld r4, @r6+ -> ld r6, @r6 */
66 1.1.1.6 christos #define PLT0_ENTRY_WORD3 0x1fc6f000 /* jmp r6 || pnop */
67 1.1.1.6 christos #define PLT0_ENTRY_WORD4 PLT_EMPTY /* RIE -> RIE */
68 1.1.1.6 christos
69 1.1.1.6 christos #define PLT0_PIC_ENTRY_WORD0 0xa4cc0004 /* ld r4, @(4,r12) */
70 1.1.1.6 christos #define PLT0_PIC_ENTRY_WORD1 0xa6cc0008 /* ld r6, @(8,r12) */
71 1.1.1.6 christos #define PLT0_PIC_ENTRY_WORD2 0x1fc6f000 /* jmp r6 || nop */
72 1.1.1.6 christos #define PLT0_PIC_ENTRY_WORD3 PLT_EMPTY /* RIE -> RIE */
73 1.1.1.6 christos #define PLT0_PIC_ENTRY_WORD4 PLT_EMPTY /* RIE -> RIE */
74 1.1.1.6 christos
75 1.1.1.6 christos #define PLT_ENTRY_WORD0 0xe6000000 /* ld24 r6, .name_in_GOT */
76 1.1.1.6 christos #define PLT_ENTRY_WORD1 0x06acf000 /* add r6, r12 || nop */
77 1.1.1.6 christos #define PLT_ENTRY_WORD0b 0xd6c00000 /* seth r6, #high(.name_in_GOT) */
78 1.1.1.6 christos #define PLT_ENTRY_WORD1b 0x86e60000 /* or3 r6, r6, #low(.name_in_GOT) */
79 1.1.1.6 christos #define PLT_ENTRY_WORD2 0x26c61fc6 /* ld r6, @r6 -> jmp r6 */
80 1.1.1.6 christos #define PLT_ENTRY_WORD3 0xe5000000 /* ld24 r5, $offset */
81 1.1.1.6 christos #define PLT_ENTRY_WORD4 0xff000000 /* bra .plt0. */
82 1.1 skrll
83 1.1 skrll
84 1.1 skrll /* Utility to actually perform an R_M32R_10_PCREL reloc. */
85 1.1 skrll
86 1.1 skrll static bfd_reloc_status_type
87 1.1 skrll m32r_elf_do_10_pcrel_reloc (bfd *abfd,
88 1.1 skrll reloc_howto_type *howto,
89 1.1 skrll asection *input_section,
90 1.1 skrll bfd_byte *data,
91 1.1 skrll bfd_vma offset,
92 1.1 skrll asection *symbol_section ATTRIBUTE_UNUSED,
93 1.1 skrll bfd_vma symbol_value,
94 1.1 skrll bfd_vma addend)
95 1.1 skrll {
96 1.1 skrll bfd_signed_vma relocation;
97 1.1 skrll unsigned long x;
98 1.1 skrll bfd_reloc_status_type status;
99 1.1 skrll
100 1.1 skrll /* Sanity check the address (offset in section). */
101 1.1 skrll if (offset > bfd_get_section_limit (abfd, input_section))
102 1.1 skrll return bfd_reloc_outofrange;
103 1.1 skrll
104 1.1 skrll relocation = symbol_value + addend;
105 1.1 skrll /* Make it pc relative. */
106 1.1 skrll relocation -= (input_section->output_section->vma
107 1.1 skrll + input_section->output_offset);
108 1.1 skrll /* These jumps mask off the lower two bits of the current address
109 1.1 skrll before doing pcrel calculations. */
110 1.1 skrll relocation -= (offset & -(bfd_vma) 4);
111 1.1 skrll
112 1.1 skrll if (relocation < -0x200 || relocation > 0x1ff)
113 1.1 skrll status = bfd_reloc_overflow;
114 1.1 skrll else
115 1.1 skrll status = bfd_reloc_ok;
116 1.1 skrll
117 1.1 skrll x = bfd_get_16 (abfd, data + offset);
118 1.1 skrll relocation >>= howto->rightshift;
119 1.1 skrll relocation <<= howto->bitpos;
120 1.1 skrll x = (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask);
121 1.1 skrll bfd_put_16 (abfd, (bfd_vma) x, data + offset);
122 1.1 skrll
123 1.1 skrll return status;
124 1.1 skrll }
125 1.1 skrll
126 1.1 skrll /* Handle the R_M32R_10_PCREL reloc. */
127 1.1 skrll
128 1.1 skrll static bfd_reloc_status_type
129 1.1 skrll m32r_elf_10_pcrel_reloc (bfd * abfd,
130 1.1 skrll arelent * reloc_entry,
131 1.1 skrll asymbol * symbol,
132 1.1 skrll void * data,
133 1.1 skrll asection * input_section,
134 1.1 skrll bfd * output_bfd,
135 1.1 skrll char ** error_message ATTRIBUTE_UNUSED)
136 1.1 skrll {
137 1.1 skrll /* This part is from bfd_elf_generic_reloc. */
138 1.1 skrll if (output_bfd != NULL
139 1.1 skrll && (symbol->flags & BSF_SECTION_SYM) == 0
140 1.1 skrll && (! reloc_entry->howto->partial_inplace
141 1.1 skrll || reloc_entry->addend == 0))
142 1.1 skrll {
143 1.1 skrll reloc_entry->address += input_section->output_offset;
144 1.1 skrll return bfd_reloc_ok;
145 1.1 skrll }
146 1.1 skrll
147 1.1 skrll if (output_bfd != NULL)
148 1.1 skrll /* FIXME: See bfd_perform_relocation. Is this right? */
149 1.1 skrll return bfd_reloc_continue;
150 1.1 skrll
151 1.1 skrll return m32r_elf_do_10_pcrel_reloc (abfd, reloc_entry->howto,
152 1.1 skrll input_section,
153 1.1 skrll data, reloc_entry->address,
154 1.1 skrll symbol->section,
155 1.1 skrll (symbol->value
156 1.1 skrll + symbol->section->output_section->vma
157 1.1 skrll + symbol->section->output_offset),
158 1.1 skrll reloc_entry->addend);
159 1.1 skrll }
160 1.1 skrll
161 1.1 skrll /* Do generic partial_inplace relocation.
162 1.1 skrll This is a local replacement for bfd_elf_generic_reloc. */
163 1.1 skrll
164 1.1 skrll static bfd_reloc_status_type
165 1.1 skrll m32r_elf_generic_reloc (bfd *input_bfd,
166 1.1 skrll arelent *reloc_entry,
167 1.1 skrll asymbol *symbol,
168 1.1 skrll void * data,
169 1.1 skrll asection *input_section,
170 1.1 skrll bfd *output_bfd,
171 1.1 skrll char **error_message ATTRIBUTE_UNUSED)
172 1.1 skrll {
173 1.1 skrll bfd_reloc_status_type ret;
174 1.1 skrll bfd_vma relocation;
175 1.1 skrll bfd_byte *inplace_address;
176 1.1 skrll
177 1.1 skrll /* This part is from bfd_elf_generic_reloc.
178 1.1 skrll If we're relocating, and this an external symbol, we don't want
179 1.1 skrll to change anything. */
180 1.1 skrll if (output_bfd != NULL
181 1.1 skrll && (symbol->flags & BSF_SECTION_SYM) == 0
182 1.1 skrll && reloc_entry->addend == 0)
183 1.1 skrll {
184 1.1 skrll reloc_entry->address += input_section->output_offset;
185 1.1 skrll return bfd_reloc_ok;
186 1.1 skrll }
187 1.1 skrll
188 1.1 skrll /* Now do the reloc in the usual way.
189 1.1 skrll ??? It would be nice to call bfd_elf_generic_reloc here,
190 1.1 skrll but we have partial_inplace set. bfd_elf_generic_reloc will
191 1.1 skrll pass the handling back to bfd_install_relocation which will install
192 1.1 skrll a section relative addend which is wrong. */
193 1.1 skrll
194 1.1 skrll /* Sanity check the address (offset in section). */
195 1.1 skrll if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
196 1.1 skrll return bfd_reloc_outofrange;
197 1.1 skrll
198 1.1 skrll ret = bfd_reloc_ok;
199 1.1 skrll if (bfd_is_und_section (symbol->section)
200 1.1 skrll && output_bfd == NULL)
201 1.1 skrll ret = bfd_reloc_undefined;
202 1.1 skrll
203 1.1 skrll if (bfd_is_com_section (symbol->section)
204 1.1 skrll || output_bfd != NULL)
205 1.1 skrll relocation = 0;
206 1.1 skrll else
207 1.1 skrll relocation = symbol->value;
208 1.1 skrll
209 1.1 skrll /* Only do this for a final link. */
210 1.1 skrll if (output_bfd == NULL)
211 1.1 skrll {
212 1.1 skrll relocation += symbol->section->output_section->vma;
213 1.1 skrll relocation += symbol->section->output_offset;
214 1.1 skrll }
215 1.1 skrll
216 1.1 skrll relocation += reloc_entry->addend;
217 1.1 skrll inplace_address = (bfd_byte *) data + reloc_entry->address;
218 1.1 skrll
219 1.1.1.6 christos #define DOIT(x) \
220 1.1.1.6 christos x = ( (x & ~reloc_entry->howto->dst_mask) | \
221 1.1 skrll (((x & reloc_entry->howto->src_mask) + relocation) & \
222 1.1 skrll reloc_entry->howto->dst_mask))
223 1.1 skrll
224 1.1.1.9 christos switch (bfd_get_reloc_size (reloc_entry->howto))
225 1.1 skrll {
226 1.1.1.9 christos case 2:
227 1.1 skrll {
228 1.1 skrll short x = bfd_get_16 (input_bfd, inplace_address);
229 1.1 skrll DOIT (x);
230 1.1.1.6 christos bfd_put_16 (input_bfd, (bfd_vma) x, inplace_address);
231 1.1 skrll }
232 1.1 skrll break;
233 1.1.1.9 christos case 4:
234 1.1 skrll {
235 1.1 skrll unsigned long x = bfd_get_32 (input_bfd, inplace_address);
236 1.1 skrll DOIT (x);
237 1.1.1.6 christos bfd_put_32 (input_bfd, (bfd_vma)x , inplace_address);
238 1.1 skrll }
239 1.1 skrll break;
240 1.1 skrll default:
241 1.1 skrll BFD_ASSERT (0);
242 1.1 skrll }
243 1.1 skrll
244 1.1 skrll if (output_bfd != NULL)
245 1.1 skrll reloc_entry->address += input_section->output_offset;
246 1.1 skrll
247 1.1 skrll return ret;
248 1.1 skrll }
249 1.1 skrll
250 1.1 skrll /* Handle the R_M32R_SDA16 reloc.
251 1.1 skrll This reloc is used to compute the address of objects in the small data area
252 1.1 skrll and to perform loads and stores from that area.
253 1.1 skrll The lower 16 bits are sign extended and added to the register specified
254 1.1 skrll in the instruction, which is assumed to point to _SDA_BASE_. */
255 1.1 skrll
256 1.1 skrll static bfd_reloc_status_type
257 1.1 skrll m32r_elf_sda16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
258 1.1 skrll arelent *reloc_entry,
259 1.1 skrll asymbol *symbol,
260 1.1 skrll void * data ATTRIBUTE_UNUSED,
261 1.1 skrll asection *input_section,
262 1.1 skrll bfd *output_bfd,
263 1.1 skrll char **error_message ATTRIBUTE_UNUSED)
264 1.1 skrll {
265 1.1 skrll /* This part is from bfd_elf_generic_reloc. */
266 1.1 skrll if (output_bfd != NULL
267 1.1 skrll && (symbol->flags & BSF_SECTION_SYM) == 0
268 1.1 skrll && (! reloc_entry->howto->partial_inplace
269 1.1 skrll || reloc_entry->addend == 0))
270 1.1 skrll {
271 1.1 skrll reloc_entry->address += input_section->output_offset;
272 1.1 skrll return bfd_reloc_ok;
273 1.1 skrll }
274 1.1 skrll
275 1.1 skrll if (output_bfd != NULL)
276 1.1 skrll /* FIXME: See bfd_perform_relocation. Is this right? */
277 1.1 skrll return bfd_reloc_continue;
278 1.1 skrll
279 1.1 skrll /* FIXME: not sure what to do here yet. But then again, the linker
280 1.1 skrll may never call us. */
281 1.1 skrll abort ();
282 1.1 skrll }
283 1.1 skrll
284 1.1 skrll
285 1.1 skrll /* Handle the R_M32R_HI16_[SU]LO relocs.
287 1.1 skrll HI16_SLO is for the add3 and load/store with displacement instructions.
288 1.1 skrll HI16_ULO is for the or3 instruction.
289 1.1 skrll For R_M32R_HI16_SLO, the lower 16 bits are sign extended when added to
290 1.1 skrll the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
291 1.1 skrll we must add one to the high 16 bytes (which will get subtracted off when
292 1.1 skrll the low 16 bits are added).
293 1.1 skrll These relocs have to be done in combination with an R_M32R_LO16 reloc
294 1.1 skrll because there is a carry from the LO16 to the HI16. Here we just save
295 1.1 skrll the information we need; we do the actual relocation when we see the LO16.
296 1.1 skrll This code is copied from the elf32-mips.c. We also support an arbitrary
297 1.1 skrll number of HI16 relocs to be associated with a single LO16 reloc. The
298 1.1 skrll assembler sorts the relocs to ensure each HI16 immediately precedes its
299 1.1 skrll LO16. However if there are multiple copies, the assembler may not find
300 1.1 skrll the real LO16 so it picks the first one it finds. */
301 1.1 skrll
302 1.1 skrll struct m32r_hi16
303 1.1 skrll {
304 1.1 skrll struct m32r_hi16 *next;
305 1.1 skrll bfd_byte *addr;
306 1.1 skrll bfd_vma addend;
307 1.1 skrll };
308 1.1 skrll
309 1.1 skrll /* FIXME: This should not be a static variable. */
310 1.1 skrll
311 1.1 skrll static struct m32r_hi16 *m32r_hi16_list;
312 1.1 skrll
313 1.1 skrll static bfd_reloc_status_type
314 1.1 skrll m32r_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
315 1.1 skrll arelent *reloc_entry,
316 1.1 skrll asymbol *symbol,
317 1.1 skrll void * data,
318 1.1 skrll asection *input_section,
319 1.1 skrll bfd *output_bfd,
320 1.1 skrll char **error_message ATTRIBUTE_UNUSED)
321 1.1 skrll {
322 1.1 skrll bfd_reloc_status_type ret;
323 1.1 skrll bfd_vma relocation;
324 1.1 skrll struct m32r_hi16 *n;
325 1.1 skrll
326 1.1 skrll /* This part is from bfd_elf_generic_reloc.
327 1.1 skrll If we're relocating, and this an external symbol, we don't want
328 1.1 skrll to change anything. */
329 1.1 skrll if (output_bfd != NULL
330 1.1 skrll && (symbol->flags & BSF_SECTION_SYM) == 0
331 1.1 skrll && reloc_entry->addend == 0)
332 1.1 skrll {
333 1.1 skrll reloc_entry->address += input_section->output_offset;
334 1.1 skrll return bfd_reloc_ok;
335 1.1 skrll }
336 1.1 skrll
337 1.1 skrll /* Sanity check the address (offset in section). */
338 1.1 skrll if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
339 1.1 skrll return bfd_reloc_outofrange;
340 1.1 skrll
341 1.1 skrll ret = bfd_reloc_ok;
342 1.1 skrll if (bfd_is_und_section (symbol->section)
343 1.1 skrll && output_bfd == NULL)
344 1.1 skrll ret = bfd_reloc_undefined;
345 1.1 skrll
346 1.1 skrll if (bfd_is_com_section (symbol->section))
347 1.1 skrll relocation = 0;
348 1.1 skrll else
349 1.1 skrll relocation = symbol->value;
350 1.1 skrll
351 1.1 skrll relocation += symbol->section->output_section->vma;
352 1.1 skrll relocation += symbol->section->output_offset;
353 1.1 skrll relocation += reloc_entry->addend;
354 1.1 skrll
355 1.1 skrll /* Save the information, and let LO16 do the actual relocation. */
356 1.1 skrll n = bfd_malloc ((bfd_size_type) sizeof *n);
357 1.1 skrll if (n == NULL)
358 1.1 skrll return bfd_reloc_outofrange;
359 1.1 skrll n->addr = (bfd_byte *) data + reloc_entry->address;
360 1.1 skrll n->addend = relocation;
361 1.1 skrll n->next = m32r_hi16_list;
362 1.1 skrll m32r_hi16_list = n;
363 1.1 skrll
364 1.1 skrll if (output_bfd != NULL)
365 1.1 skrll reloc_entry->address += input_section->output_offset;
366 1.1 skrll
367 1.1 skrll return ret;
368 1.1 skrll }
369 1.1 skrll
370 1.1 skrll /* Handle an M32R ELF HI16 reloc. */
371 1.1 skrll
372 1.1 skrll static void
373 1.1 skrll m32r_elf_relocate_hi16 (bfd *input_bfd,
374 1.1 skrll int type,
375 1.1 skrll Elf_Internal_Rela *relhi,
376 1.1 skrll Elf_Internal_Rela *rello,
377 1.1 skrll bfd_byte *contents,
378 1.1 skrll bfd_vma addend)
379 1.1 skrll {
380 1.1 skrll unsigned long insn;
381 1.1 skrll bfd_vma addlo;
382 1.1 skrll
383 1.1 skrll insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
384 1.1 skrll
385 1.1 skrll addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
386 1.1 skrll if (type == R_M32R_HI16_SLO)
387 1.1 skrll addlo = ((addlo & 0xffff) ^ 0x8000) - 0x8000;
388 1.1 skrll else
389 1.1 skrll addlo &= 0xffff;
390 1.1 skrll
391 1.1 skrll addend += ((insn & 0xffff) << 16) + addlo;
392 1.1 skrll
393 1.1 skrll /* Reaccount for sign extension of low part. */
394 1.1 skrll if (type == R_M32R_HI16_SLO
395 1.1 skrll && (addend & 0x8000) != 0)
396 1.1 skrll addend += 0x10000;
397 1.1 skrll
398 1.1 skrll bfd_put_32 (input_bfd,
399 1.1 skrll (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
400 1.1 skrll contents + relhi->r_offset);
401 1.1 skrll }
402 1.1 skrll
403 1.1 skrll /* Do an R_M32R_LO16 relocation. This is a straightforward 16 bit
404 1.1 skrll inplace relocation; this function exists in order to do the
405 1.1 skrll R_M32R_HI16_[SU]LO relocation described above. */
406 1.1 skrll
407 1.1 skrll static bfd_reloc_status_type
408 1.1 skrll m32r_elf_lo16_reloc (bfd *input_bfd,
409 1.1 skrll arelent *reloc_entry,
410 1.1 skrll asymbol *symbol,
411 1.1 skrll void * data,
412 1.1 skrll asection *input_section,
413 1.1 skrll bfd *output_bfd,
414 1.1 skrll char **error_message)
415 1.1 skrll {
416 1.1 skrll /* This part is from bfd_elf_generic_reloc.
417 1.1 skrll If we're relocating, and this an external symbol, we don't want
418 1.1 skrll to change anything. */
419 1.1 skrll if (output_bfd != NULL
420 1.1 skrll && (symbol->flags & BSF_SECTION_SYM) == 0
421 1.1 skrll && reloc_entry->addend == 0)
422 1.1 skrll {
423 1.1 skrll reloc_entry->address += input_section->output_offset;
424 1.1 skrll return bfd_reloc_ok;
425 1.1 skrll }
426 1.1 skrll
427 1.1 skrll if (m32r_hi16_list != NULL)
428 1.1 skrll {
429 1.1 skrll struct m32r_hi16 *l;
430 1.1 skrll
431 1.1 skrll l = m32r_hi16_list;
432 1.1 skrll while (l != NULL)
433 1.1 skrll {
434 1.1 skrll unsigned long insn;
435 1.1 skrll unsigned long val;
436 1.1 skrll unsigned long vallo;
437 1.1 skrll struct m32r_hi16 *next;
438 1.1 skrll
439 1.1 skrll /* Do the HI16 relocation. Note that we actually don't need
440 1.1 skrll to know anything about the LO16 itself, except where to
441 1.1 skrll find the low 16 bits of the addend needed by the LO16. */
442 1.1 skrll insn = bfd_get_32 (input_bfd, l->addr);
443 1.1 skrll vallo = ((bfd_get_32 (input_bfd, (bfd_byte *) data + reloc_entry->address)
444 1.1 skrll & 0xffff) ^ 0x8000) - 0x8000;
445 1.1 skrll val = ((insn & 0xffff) << 16) + vallo;
446 1.1 skrll val += l->addend;
447 1.1 skrll
448 1.1 skrll /* Reaccount for sign extension of low part. */
449 1.1 skrll if ((val & 0x8000) != 0)
450 1.1 skrll val += 0x10000;
451 1.1 skrll
452 1.1 skrll insn = (insn &~ (bfd_vma) 0xffff) | ((val >> 16) & 0xffff);
453 1.1 skrll bfd_put_32 (input_bfd, (bfd_vma) insn, l->addr);
454 1.1 skrll
455 1.1 skrll next = l->next;
456 1.1 skrll free (l);
457 1.1 skrll l = next;
458 1.1 skrll }
459 1.1 skrll
460 1.1 skrll m32r_hi16_list = NULL;
461 1.1 skrll }
462 1.1 skrll
463 1.1 skrll /* Now do the LO16 reloc in the usual way.
464 1.1 skrll ??? It would be nice to call bfd_elf_generic_reloc here,
465 1.1 skrll but we have partial_inplace set. bfd_elf_generic_reloc will
466 1.1 skrll pass the handling back to bfd_install_relocation which will install
467 1.1 skrll a section relative addend which is wrong. */
468 1.1 skrll return m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
469 1.1 skrll input_section, output_bfd, error_message);
470 1.1 skrll }
471 1.1 skrll
472 1.1 skrll
473 1.1 skrll static reloc_howto_type m32r_elf_howto_table[] =
475 1.1 skrll {
476 1.1 skrll /* This reloc does nothing. */
477 1.1.1.9 christos HOWTO (R_M32R_NONE, /* type */
478 1.1.1.4 christos 0, /* rightshift */
479 1.1.1.9 christos 0, /* size */
480 1.1 skrll 0, /* bitsize */
481 1.1.1.4 christos false, /* pc_relative */
482 1.1 skrll 0, /* bitpos */
483 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
484 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
485 1.1 skrll "R_M32R_NONE", /* name */
486 1.1 skrll false, /* partial_inplace */
487 1.1.1.9 christos 0, /* src_mask */
488 1.1 skrll 0, /* dst_mask */
489 1.1 skrll false), /* pcrel_offset */
490 1.1 skrll
491 1.1 skrll /* A 16 bit absolute relocation. */
492 1.1.1.9 christos HOWTO (R_M32R_16, /* type */
493 1.1 skrll 0, /* rightshift */
494 1.1.1.9 christos 2, /* size */
495 1.1 skrll 16, /* bitsize */
496 1.1 skrll false, /* pc_relative */
497 1.1 skrll 0, /* bitpos */
498 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
499 1.1.1.9 christos m32r_elf_generic_reloc,/* special_function */
500 1.1 skrll "R_M32R_16", /* name */
501 1.1 skrll true, /* partial_inplace */
502 1.1.1.9 christos 0xffff, /* src_mask */
503 1.1 skrll 0xffff, /* dst_mask */
504 1.1 skrll false), /* pcrel_offset */
505 1.1 skrll
506 1.1 skrll /* A 32 bit absolute relocation. */
507 1.1.1.9 christos HOWTO (R_M32R_32, /* type */
508 1.1 skrll 0, /* rightshift */
509 1.1.1.9 christos 4, /* size */
510 1.1 skrll 32, /* bitsize */
511 1.1 skrll false, /* pc_relative */
512 1.1 skrll 0, /* bitpos */
513 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
514 1.1.1.9 christos m32r_elf_generic_reloc,/* special_function */
515 1.1 skrll "R_M32R_32", /* name */
516 1.1 skrll true, /* partial_inplace */
517 1.1.1.9 christos 0xffffffff, /* src_mask */
518 1.1 skrll 0xffffffff, /* dst_mask */
519 1.1 skrll false), /* pcrel_offset */
520 1.1 skrll
521 1.1 skrll /* A 24 bit address. */
522 1.1.1.9 christos HOWTO (R_M32R_24, /* type */
523 1.1 skrll 0, /* rightshift */
524 1.1.1.9 christos 4, /* size */
525 1.1 skrll 24, /* bitsize */
526 1.1 skrll false, /* pc_relative */
527 1.1 skrll 0, /* bitpos */
528 1.1 skrll complain_overflow_unsigned, /* complain_on_overflow */
529 1.1.1.9 christos m32r_elf_generic_reloc,/* special_function */
530 1.1 skrll "R_M32R_24", /* name */
531 1.1 skrll true, /* partial_inplace */
532 1.1.1.9 christos 0xffffff, /* src_mask */
533 1.1 skrll 0xffffff, /* dst_mask */
534 1.1 skrll false), /* pcrel_offset */
535 1.1 skrll
536 1.1 skrll /* An PC Relative 10-bit relocation, shifted by 2.
537 1.1 skrll This reloc is complicated because relocations are relative to pc & -4.
538 1.1 skrll i.e. branches in the right insn slot use the address of the left insn
539 1.1 skrll slot for pc. */
540 1.1 skrll /* ??? It's not clear whether this should have partial_inplace set or not.
541 1.1 skrll Branch relaxing in the assembler can store the addend in the insn,
542 1.1 skrll and if bfd_install_relocation gets called the addend may get added
543 1.1.1.6 christos again. */
544 1.1.1.9 christos HOWTO (R_M32R_10_PCREL, /* type */
545 1.1.1.6 christos 2, /* rightshift */
546 1.1.1.9 christos 2, /* size */
547 1.1.1.6 christos 10, /* bitsize */
548 1.1 skrll true, /* pc_relative */
549 1.1 skrll 0, /* bitpos */
550 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
551 1.1.1.9 christos m32r_elf_10_pcrel_reloc, /* special_function */
552 1.1.1.6 christos "R_M32R_10_PCREL", /* name */
553 1.1.1.6 christos false, /* partial_inplace */
554 1.1.1.9 christos 0xff, /* src_mask */
555 1.1 skrll 0xff, /* dst_mask */
556 1.1 skrll true), /* pcrel_offset */
557 1.1 skrll
558 1.1 skrll /* A relative 18 bit relocation, right shifted by 2. */
559 1.1.1.9 christos HOWTO (R_M32R_18_PCREL, /* type */
560 1.1 skrll 2, /* rightshift */
561 1.1.1.9 christos 4, /* size */
562 1.1 skrll 16, /* bitsize */
563 1.1 skrll true, /* pc_relative */
564 1.1 skrll 0, /* bitpos */
565 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
566 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
567 1.1 skrll "R_M32R_18_PCREL", /* name */
568 1.1 skrll false, /* partial_inplace */
569 1.1.1.9 christos 0xffff, /* src_mask */
570 1.1 skrll 0xffff, /* dst_mask */
571 1.1 skrll true), /* pcrel_offset */
572 1.1 skrll
573 1.1 skrll /* A relative 26 bit relocation, right shifted by 2. */
574 1.1 skrll /* ??? It's not clear whether this should have partial_inplace set or not.
575 1.1 skrll Branch relaxing in the assembler can store the addend in the insn,
576 1.1 skrll and if bfd_install_relocation gets called the addend may get added
577 1.1 skrll again. */
578 1.1.1.9 christos HOWTO (R_M32R_26_PCREL, /* type */
579 1.1 skrll 2, /* rightshift */
580 1.1.1.9 christos 4, /* size */
581 1.1 skrll 26, /* bitsize */
582 1.1 skrll true, /* pc_relative */
583 1.1 skrll 0, /* bitpos */
584 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
585 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
586 1.1 skrll "R_M32R_26_PCREL", /* name */
587 1.1 skrll false, /* partial_inplace */
588 1.1.1.9 christos 0xffffff, /* src_mask */
589 1.1 skrll 0xffffff, /* dst_mask */
590 1.1 skrll true), /* pcrel_offset */
591 1.1 skrll
592 1.1 skrll /* High 16 bits of address when lower 16 is or'd in. */
593 1.1.1.9 christos HOWTO (R_M32R_HI16_ULO, /* type */
594 1.1 skrll 16, /* rightshift */
595 1.1.1.9 christos 4, /* size */
596 1.1 skrll 16, /* bitsize */
597 1.1 skrll false, /* pc_relative */
598 1.1 skrll 0, /* bitpos */
599 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
600 1.1.1.9 christos m32r_elf_hi16_reloc, /* special_function */
601 1.1 skrll "R_M32R_HI16_ULO", /* name */
602 1.1 skrll true, /* partial_inplace */
603 1.1.1.9 christos 0x0000ffff, /* src_mask */
604 1.1 skrll 0x0000ffff, /* dst_mask */
605 1.1 skrll false), /* pcrel_offset */
606 1.1 skrll
607 1.1 skrll /* High 16 bits of address when lower 16 is added in. */
608 1.1.1.9 christos HOWTO (R_M32R_HI16_SLO, /* type */
609 1.1 skrll 16, /* rightshift */
610 1.1.1.9 christos 4, /* size */
611 1.1 skrll 16, /* bitsize */
612 1.1 skrll false, /* pc_relative */
613 1.1 skrll 0, /* bitpos */
614 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
615 1.1.1.9 christos m32r_elf_hi16_reloc, /* special_function */
616 1.1 skrll "R_M32R_HI16_SLO", /* name */
617 1.1 skrll true, /* partial_inplace */
618 1.1.1.9 christos 0x0000ffff, /* src_mask */
619 1.1 skrll 0x0000ffff, /* dst_mask */
620 1.1 skrll false), /* pcrel_offset */
621 1.1 skrll
622 1.1 skrll /* Lower 16 bits of address. */
623 1.1.1.9 christos HOWTO (R_M32R_LO16, /* type */
624 1.1 skrll 0, /* rightshift */
625 1.1.1.9 christos 4, /* size */
626 1.1 skrll 16, /* bitsize */
627 1.1 skrll false, /* pc_relative */
628 1.1 skrll 0, /* bitpos */
629 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
630 1.1.1.9 christos m32r_elf_lo16_reloc, /* special_function */
631 1.1 skrll "R_M32R_LO16", /* name */
632 1.1 skrll true, /* partial_inplace */
633 1.1.1.9 christos 0x0000ffff, /* src_mask */
634 1.1 skrll 0x0000ffff, /* dst_mask */
635 1.1 skrll false), /* pcrel_offset */
636 1.1 skrll
637 1.1 skrll /* Small data area 16 bits offset. */
638 1.1.1.9 christos HOWTO (R_M32R_SDA16, /* type */
639 1.1 skrll 0, /* rightshift */
640 1.1.1.9 christos 4, /* size */
641 1.1 skrll 16, /* bitsize */
642 1.1 skrll false, /* pc_relative */
643 1.1 skrll 0, /* bitpos */
644 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
645 1.1.1.9 christos m32r_elf_sda16_reloc, /* special_function */
646 1.1 skrll "R_M32R_SDA16", /* name */
647 1.1 skrll true, /* partial_inplace */ /* FIXME: correct? */
648 1.1.1.9 christos 0x0000ffff, /* src_mask */
649 1.1 skrll 0x0000ffff, /* dst_mask */
650 1.1 skrll false), /* pcrel_offset */
651 1.1 skrll
652 1.1.1.6 christos /* GNU extension to record C++ vtable hierarchy. */
653 1.1.1.9 christos HOWTO (R_M32R_GNU_VTINHERIT, /* type */
654 1.1.1.6 christos 0, /* rightshift */
655 1.1.1.9 christos 4, /* size */
656 1.1.1.6 christos 0, /* bitsize */
657 1.1.1.6 christos false, /* pc_relative */
658 1.1.1.6 christos 0, /* bitpos */
659 1.1.1.6 christos complain_overflow_dont, /* complain_on_overflow */
660 1.1.1.9 christos NULL, /* special_function */
661 1.1.1.6 christos "R_M32R_GNU_VTINHERIT", /* name */
662 1.1.1.6 christos false, /* partial_inplace */
663 1.1.1.9 christos 0, /* src_mask */
664 1.1 skrll 0, /* dst_mask */
665 1.1 skrll false), /* pcrel_offset */
666 1.1.1.6 christos
667 1.1.1.6 christos /* GNU extension to record C++ vtable member usage. */
668 1.1.1.9 christos HOWTO (R_M32R_GNU_VTENTRY, /* type */
669 1.1.1.6 christos 0, /* rightshift */
670 1.1.1.9 christos 4, /* size */
671 1.1.1.6 christos 0, /* bitsize */
672 1.1.1.6 christos false, /* pc_relative */
673 1.1.1.6 christos 0, /* bitpos */
674 1.1.1.6 christos complain_overflow_dont, /* complain_on_overflow */
675 1.1.1.9 christos _bfd_elf_rel_vtable_reloc_fn, /* special_function */
676 1.1.1.6 christos "R_M32R_GNU_VTENTRY", /* name */
677 1.1.1.6 christos false, /* partial_inplace */
678 1.1.1.9 christos 0, /* src_mask */
679 1.1 skrll 0, /* dst_mask */
680 1.1 skrll false), /* pcrel_offset */
681 1.1 skrll
682 1.1 skrll EMPTY_HOWTO (13),
683 1.1 skrll EMPTY_HOWTO (14),
684 1.1 skrll EMPTY_HOWTO (15),
685 1.1 skrll EMPTY_HOWTO (16),
686 1.1 skrll EMPTY_HOWTO (17),
687 1.1 skrll EMPTY_HOWTO (18),
688 1.1 skrll EMPTY_HOWTO (19),
689 1.1 skrll EMPTY_HOWTO (20),
690 1.1 skrll EMPTY_HOWTO (21),
691 1.1 skrll EMPTY_HOWTO (22),
692 1.1 skrll EMPTY_HOWTO (23),
693 1.1 skrll EMPTY_HOWTO (24),
694 1.1 skrll EMPTY_HOWTO (25),
695 1.1 skrll EMPTY_HOWTO (26),
696 1.1 skrll EMPTY_HOWTO (27),
697 1.1 skrll EMPTY_HOWTO (28),
698 1.1 skrll EMPTY_HOWTO (29),
699 1.1 skrll EMPTY_HOWTO (30),
700 1.1 skrll EMPTY_HOWTO (31),
701 1.1 skrll EMPTY_HOWTO (32),
702 1.1 skrll
703 1.1 skrll /* A 16 bit absolute relocation. */
704 1.1.1.9 christos HOWTO (R_M32R_16_RELA, /* type */
705 1.1 skrll 0, /* rightshift */
706 1.1.1.9 christos 2, /* size */
707 1.1 skrll 16, /* bitsize */
708 1.1 skrll false, /* pc_relative */
709 1.1 skrll 0, /* bitpos */
710 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
711 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
712 1.1 skrll "R_M32R_16_RELA", /* name */
713 1.1 skrll false, /* partial_inplace */
714 1.1.1.9 christos 0xffff, /* src_mask */
715 1.1 skrll 0xffff, /* dst_mask */
716 1.1 skrll false), /* pcrel_offset */
717 1.1 skrll
718 1.1 skrll /* A 32 bit absolute relocation. */
719 1.1.1.9 christos HOWTO (R_M32R_32_RELA, /* type */
720 1.1 skrll 0, /* rightshift */
721 1.1.1.9 christos 4, /* size */
722 1.1 skrll 32, /* bitsize */
723 1.1 skrll false, /* pc_relative */
724 1.1 skrll 0, /* bitpos */
725 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
726 1.1.1.9 christos bfd_elf_generic_reloc,/* special_function */
727 1.1 skrll "R_M32R_32_RELA", /* name */
728 1.1 skrll false, /* partial_inplace */
729 1.1.1.9 christos 0xffffffff, /* src_mask */
730 1.1 skrll 0xffffffff, /* dst_mask */
731 1.1 skrll false), /* pcrel_offset */
732 1.1 skrll
733 1.1 skrll /* A 24 bit address. */
734 1.1.1.9 christos HOWTO (R_M32R_24_RELA, /* type */
735 1.1 skrll 0, /* rightshift */
736 1.1.1.9 christos 4, /* size */
737 1.1 skrll 24, /* bitsize */
738 1.1 skrll false, /* pc_relative */
739 1.1 skrll 0, /* bitpos */
740 1.1 skrll complain_overflow_unsigned, /* complain_on_overflow */
741 1.1.1.9 christos bfd_elf_generic_reloc,/* special_function */
742 1.1 skrll "R_M32R_24_RELA", /* name */
743 1.1 skrll false, /* partial_inplace */
744 1.1.1.9 christos 0xffffff, /* src_mask */
745 1.1 skrll 0xffffff, /* dst_mask */
746 1.1 skrll false), /* pcrel_offset */
747 1.1.1.6 christos
748 1.1.1.9 christos HOWTO (R_M32R_10_PCREL_RELA, /* type */
749 1.1.1.6 christos 2, /* rightshift */
750 1.1.1.9 christos 2, /* size */
751 1.1.1.6 christos 10, /* bitsize */
752 1.1 skrll true, /* pc_relative */
753 1.1 skrll 0, /* bitpos */
754 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
755 1.1.1.9 christos m32r_elf_10_pcrel_reloc, /* special_function */
756 1.1.1.6 christos "R_M32R_10_PCREL_RELA",/* name */
757 1.1.1.6 christos false, /* partial_inplace */
758 1.1.1.9 christos 0xff, /* src_mask */
759 1.1 skrll 0xff, /* dst_mask */
760 1.1 skrll true), /* pcrel_offset */
761 1.1 skrll
762 1.1 skrll /* A relative 18 bit relocation, right shifted by 2. */
763 1.1.1.9 christos HOWTO (R_M32R_18_PCREL_RELA, /* type */
764 1.1 skrll 2, /* rightshift */
765 1.1.1.9 christos 4, /* size */
766 1.1 skrll 16, /* bitsize */
767 1.1 skrll true, /* pc_relative */
768 1.1 skrll 0, /* bitpos */
769 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
770 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
771 1.1 skrll "R_M32R_18_PCREL_RELA",/* name */
772 1.1 skrll false, /* partial_inplace */
773 1.1.1.9 christos 0xffff, /* src_mask */
774 1.1 skrll 0xffff, /* dst_mask */
775 1.1 skrll true), /* pcrel_offset */
776 1.1 skrll
777 1.1 skrll /* A relative 26 bit relocation, right shifted by 2. */
778 1.1.1.9 christos HOWTO (R_M32R_26_PCREL_RELA, /* type */
779 1.1 skrll 2, /* rightshift */
780 1.1.1.9 christos 4, /* size */
781 1.1 skrll 26, /* bitsize */
782 1.1 skrll true, /* pc_relative */
783 1.1 skrll 0, /* bitpos */
784 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
785 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
786 1.1 skrll "R_M32R_26_PCREL_RELA",/* name */
787 1.1 skrll false, /* partial_inplace */
788 1.1.1.9 christos 0xffffff, /* src_mask */
789 1.1 skrll 0xffffff, /* dst_mask */
790 1.1 skrll true), /* pcrel_offset */
791 1.1 skrll
792 1.1 skrll /* High 16 bits of address when lower 16 is or'd in. */
793 1.1.1.9 christos HOWTO (R_M32R_HI16_ULO_RELA, /* type */
794 1.1 skrll 16, /* rightshift */
795 1.1.1.9 christos 4, /* size */
796 1.1 skrll 16, /* bitsize */
797 1.1 skrll false, /* pc_relative */
798 1.1 skrll 0, /* bitpos */
799 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
800 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
801 1.1 skrll "R_M32R_HI16_ULO_RELA",/* name */
802 1.1 skrll false, /* partial_inplace */
803 1.1.1.9 christos 0x0000ffff, /* src_mask */
804 1.1 skrll 0x0000ffff, /* dst_mask */
805 1.1 skrll false), /* pcrel_offset */
806 1.1 skrll
807 1.1 skrll /* High 16 bits of address when lower 16 is added in. */
808 1.1.1.9 christos HOWTO (R_M32R_HI16_SLO_RELA, /* type */
809 1.1 skrll 16, /* rightshift */
810 1.1.1.9 christos 4, /* size */
811 1.1 skrll 16, /* bitsize */
812 1.1 skrll false, /* pc_relative */
813 1.1 skrll 0, /* bitpos */
814 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
815 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
816 1.1 skrll "R_M32R_HI16_SLO_RELA",/* name */
817 1.1 skrll false, /* partial_inplace */
818 1.1.1.9 christos 0x0000ffff, /* src_mask */
819 1.1 skrll 0x0000ffff, /* dst_mask */
820 1.1 skrll false), /* pcrel_offset */
821 1.1 skrll
822 1.1 skrll /* Lower 16 bits of address. */
823 1.1.1.9 christos HOWTO (R_M32R_LO16_RELA, /* type */
824 1.1 skrll 0, /* rightshift */
825 1.1.1.9 christos 4, /* size */
826 1.1 skrll 16, /* bitsize */
827 1.1 skrll false, /* pc_relative */
828 1.1 skrll 0, /* bitpos */
829 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
830 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
831 1.1 skrll "R_M32R_LO16_RELA", /* name */
832 1.1 skrll false, /* partial_inplace */
833 1.1.1.9 christos 0x0000ffff, /* src_mask */
834 1.1 skrll 0x0000ffff, /* dst_mask */
835 1.1 skrll false), /* pcrel_offset */
836 1.1 skrll
837 1.1 skrll /* Small data area 16 bits offset. */
838 1.1.1.9 christos HOWTO (R_M32R_SDA16_RELA, /* type */
839 1.1 skrll 0, /* rightshift */
840 1.1.1.9 christos 4, /* size */
841 1.1 skrll 16, /* bitsize */
842 1.1 skrll false, /* pc_relative */
843 1.1 skrll 0, /* bitpos */
844 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
845 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
846 1.1 skrll "R_M32R_SDA16_RELA", /* name */
847 1.1 skrll true, /* partial_inplace */ /* FIXME: correct? */
848 1.1.1.9 christos 0x0000ffff, /* src_mask */
849 1.1 skrll 0x0000ffff, /* dst_mask */
850 1.1 skrll false), /* pcrel_offset */
851 1.1 skrll
852 1.1.1.6 christos /* GNU extension to record C++ vtable hierarchy. */
853 1.1.1.9 christos HOWTO (R_M32R_RELA_GNU_VTINHERIT, /* type */
854 1.1.1.6 christos 0, /* rightshift */
855 1.1.1.9 christos 4, /* size */
856 1.1.1.6 christos 0, /* bitsize */
857 1.1.1.6 christos false, /* pc_relative */
858 1.1.1.6 christos 0, /* bitpos */
859 1.1.1.6 christos complain_overflow_dont, /* complain_on_overflow */
860 1.1.1.9 christos NULL, /* special_function */
861 1.1.1.6 christos "R_M32R_RELA_GNU_VTINHERIT", /* name */
862 1.1.1.6 christos false, /* partial_inplace */
863 1.1.1.9 christos 0, /* src_mask */
864 1.1 skrll 0, /* dst_mask */
865 1.1 skrll false), /* pcrel_offset */
866 1.1 skrll
867 1.1.1.6 christos /* GNU extension to record C++ vtable member usage. */
868 1.1.1.9 christos HOWTO (R_M32R_RELA_GNU_VTENTRY, /* type */
869 1.1.1.6 christos 0, /* rightshift */
870 1.1.1.9 christos 4, /* size */
871 1.1.1.6 christos 0, /* bitsize */
872 1.1.1.6 christos false, /* pc_relative */
873 1.1.1.6 christos 0, /* bitpos */
874 1.1.1.6 christos complain_overflow_dont, /* complain_on_overflow */
875 1.1.1.9 christos _bfd_elf_rel_vtable_reloc_fn, /* special_function */
876 1.1.1.6 christos "R_M32R_RELA_GNU_VTENTRY", /* name */
877 1.1.1.6 christos false, /* partial_inplace */
878 1.1.1.9 christos 0, /* src_mask */
879 1.1 skrll 0, /* dst_mask */
880 1.1 skrll false), /* pcrel_offset */
881 1.1 skrll
882 1.1 skrll /* A 32 bit PC relative relocation. */
883 1.1.1.9 christos HOWTO (R_M32R_REL32, /* type */
884 1.1 skrll 0, /* rightshift */
885 1.1.1.9 christos 4, /* size */
886 1.1 skrll 32, /* bitsize */
887 1.1 skrll true, /* pc_relative */
888 1.1 skrll 0, /* bitpos */
889 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
890 1.1.1.9 christos bfd_elf_generic_reloc,/* special_function */
891 1.1 skrll "R_M32R_REL32", /* name */
892 1.1 skrll false, /* partial_inplace */
893 1.1.1.9 christos 0xffffffff, /* src_mask */
894 1.1 skrll 0xffffffff, /* dst_mask */
895 1.1 skrll true), /* pcrel_offset */
896 1.1 skrll
897 1.1 skrll EMPTY_HOWTO (46),
898 1.1 skrll EMPTY_HOWTO (47),
899 1.1 skrll
900 1.1 skrll /* Like R_M32R_24, but referring to the GOT table entry for
901 1.1 skrll the symbol. */
902 1.1.1.9 christos HOWTO (R_M32R_GOT24, /* type */
903 1.1 skrll 0, /* rightshift */
904 1.1.1.9 christos 4, /* size */
905 1.1 skrll 24, /* bitsize */
906 1.1 skrll false, /* pc_relative */
907 1.1 skrll 0, /* bitpos */
908 1.1 skrll complain_overflow_unsigned, /* complain_on_overflow */
909 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
910 1.1 skrll "R_M32R_GOT24", /* name */
911 1.1 skrll false, /* partial_inplace */
912 1.1.1.9 christos 0xffffff, /* src_mask */
913 1.1 skrll 0xffffff, /* dst_mask */
914 1.1 skrll false), /* pcrel_offset */
915 1.1 skrll
916 1.1 skrll /* Like R_M32R_PCREL, but referring to the procedure linkage table
917 1.1 skrll entry for the symbol. */
918 1.1.1.9 christos HOWTO (R_M32R_26_PLTREL, /* type */
919 1.1 skrll 2, /* rightshift */
920 1.1.1.9 christos 4, /* size */
921 1.1 skrll 24, /* bitsize */
922 1.1 skrll true, /* pc_relative */
923 1.1 skrll 0, /* bitpos */
924 1.1 skrll complain_overflow_signed, /* complain_on_overflow */
925 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
926 1.1 skrll "R_M32R_26_PLTREL", /* name */
927 1.1 skrll false, /* partial_inplace */
928 1.1.1.9 christos 0xffffff, /* src_mask */
929 1.1 skrll 0xffffff, /* dst_mask */
930 1.1 skrll true), /* pcrel_offset */
931 1.1 skrll
932 1.1 skrll /* This is used only by the dynamic linker. The symbol should exist
933 1.1 skrll both in the object being run and in some shared library. The
934 1.1 skrll dynamic linker copies the data addressed by the symbol from the
935 1.1 skrll shared library into the object, because the object being
936 1.1 skrll run has to have the data at some particular address. */
937 1.1.1.9 christos HOWTO (R_M32R_COPY, /* type */
938 1.1 skrll 0, /* rightshift */
939 1.1.1.9 christos 4, /* size */
940 1.1 skrll 32, /* bitsize */
941 1.1 skrll false, /* pc_relative */
942 1.1 skrll 0, /* bitpos */
943 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
944 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
945 1.1 skrll "R_M32R_COPY", /* name */
946 1.1 skrll false, /* partial_inplace */
947 1.1.1.9 christos 0xffffffff, /* src_mask */
948 1.1 skrll 0xffffffff, /* dst_mask */
949 1.1 skrll false), /* pcrel_offset */
950 1.1 skrll
951 1.1 skrll /* Like R_M32R_24, but used when setting global offset table
952 1.1 skrll entries. */
953 1.1.1.9 christos HOWTO (R_M32R_GLOB_DAT, /* type */
954 1.1 skrll 0, /* rightshift */
955 1.1.1.9 christos 4, /* size */
956 1.1 skrll 32, /* bitsize */
957 1.1 skrll false, /* pc_relative */
958 1.1 skrll 0, /* bitpos */
959 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
960 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
961 1.1 skrll "R_M32R_GLOB_DAT", /* name */
962 1.1 skrll false, /* partial_inplace */
963 1.1.1.9 christos 0xffffffff, /* src_mask */
964 1.1 skrll 0xffffffff, /* dst_mask */
965 1.1 skrll false), /* pcrel_offset */
966 1.1 skrll
967 1.1 skrll /* Marks a procedure linkage table entry for a symbol. */
968 1.1.1.9 christos HOWTO (R_M32R_JMP_SLOT, /* type */
969 1.1 skrll 0, /* rightshift */
970 1.1.1.9 christos 4, /* size */
971 1.1 skrll 32, /* bitsize */
972 1.1 skrll false, /* pc_relative */
973 1.1 skrll 0, /* bitpos */
974 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
975 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
976 1.1 skrll "R_M32R_JMP_SLOT", /* name */
977 1.1 skrll false, /* partial_inplace */
978 1.1.1.9 christos 0xffffffff, /* src_mask */
979 1.1 skrll 0xffffffff, /* dst_mask */
980 1.1 skrll false), /* pcrel_offset */
981 1.1 skrll
982 1.1 skrll /* Used only by the dynamic linker. When the object is run, this
983 1.1 skrll longword is set to the load address of the object, plus the
984 1.1 skrll addend. */
985 1.1.1.9 christos HOWTO (R_M32R_RELATIVE, /* type */
986 1.1 skrll 0, /* rightshift */
987 1.1.1.9 christos 4, /* size */
988 1.1 skrll 32, /* bitsize */
989 1.1 skrll false, /* pc_relative */
990 1.1 skrll 0, /* bitpos */
991 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
992 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
993 1.1 skrll "R_M32R_RELATIVE", /* name */
994 1.1 skrll false, /* partial_inplace */
995 1.1.1.9 christos 0xffffffff, /* src_mask */
996 1.1 skrll 0xffffffff, /* dst_mask */
997 1.1 skrll false), /* pcrel_offset */
998 1.1 skrll
999 1.1.1.9 christos HOWTO (R_M32R_GOTOFF, /* type */
1000 1.1 skrll 0, /* rightshift */
1001 1.1.1.9 christos 4, /* size */
1002 1.1 skrll 24, /* bitsize */
1003 1.1 skrll false, /* pc_relative */
1004 1.1 skrll 0, /* bitpos */
1005 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
1006 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1007 1.1 skrll "R_M32R_GOTOFF", /* name */
1008 1.1 skrll false, /* partial_inplace */
1009 1.1.1.9 christos 0xffffff, /* src_mask */
1010 1.1 skrll 0xffffff, /* dst_mask */
1011 1.1 skrll false), /* pcrel_offset */
1012 1.1 skrll
1013 1.1 skrll /* An PC Relative 24-bit relocation used when setting PIC offset
1014 1.1 skrll table register. */
1015 1.1.1.9 christos HOWTO (R_M32R_GOTPC24, /* type */
1016 1.1 skrll 0, /* rightshift */
1017 1.1.1.9 christos 4, /* size */
1018 1.1 skrll 24, /* bitsize */
1019 1.1 skrll true, /* pc_relative */
1020 1.1 skrll 0, /* bitpos */
1021 1.1 skrll complain_overflow_unsigned, /* complain_on_overflow */
1022 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1023 1.1 skrll "R_M32R_GOTPC24", /* name */
1024 1.1 skrll false, /* partial_inplace */
1025 1.1.1.9 christos 0xffffff, /* src_mask */
1026 1.1 skrll 0xffffff, /* dst_mask */
1027 1.1 skrll true), /* pcrel_offset */
1028 1.1 skrll
1029 1.1 skrll /* Like R_M32R_HI16_ULO, but referring to the GOT table entry for
1030 1.1 skrll the symbol. */
1031 1.1.1.9 christos HOWTO (R_M32R_GOT16_HI_ULO, /* type */
1032 1.1 skrll 16, /* rightshift */
1033 1.1.1.9 christos 4, /* size */
1034 1.1 skrll 16, /* bitsize */
1035 1.1 skrll false, /* pc_relative */
1036 1.1 skrll 0, /* bitpos */
1037 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1038 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1039 1.1 skrll "R_M32R_GOT16_HI_ULO", /* name */
1040 1.1 skrll false, /* partial_inplace */
1041 1.1.1.9 christos 0x0000ffff, /* src_mask */
1042 1.1 skrll 0x0000ffff, /* dst_mask */
1043 1.1 skrll false), /* pcrel_offset */
1044 1.1 skrll
1045 1.1 skrll /* Like R_M32R_HI16_SLO, but referring to the GOT table entry for
1046 1.1 skrll the symbol. */
1047 1.1.1.9 christos HOWTO (R_M32R_GOT16_HI_SLO, /* type */
1048 1.1 skrll 16, /* rightshift */
1049 1.1.1.9 christos 4, /* size */
1050 1.1 skrll 16, /* bitsize */
1051 1.1 skrll false, /* pc_relative */
1052 1.1 skrll 0, /* bitpos */
1053 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1054 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1055 1.1 skrll "R_M32R_GOT16_HI_SLO", /* name */
1056 1.1 skrll false, /* partial_inplace */
1057 1.1.1.9 christos 0x0000ffff, /* src_mask */
1058 1.1 skrll 0x0000ffff, /* dst_mask */
1059 1.1 skrll false), /* pcrel_offset */
1060 1.1 skrll
1061 1.1 skrll /* Like R_M32R_LO16, but referring to the GOT table entry for
1062 1.1 skrll the symbol. */
1063 1.1.1.9 christos HOWTO (R_M32R_GOT16_LO, /* type */
1064 1.1 skrll 0, /* rightshift */
1065 1.1.1.9 christos 4, /* size */
1066 1.1 skrll 16, /* bitsize */
1067 1.1 skrll false, /* pc_relative */
1068 1.1 skrll 0, /* bitpos */
1069 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1070 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1071 1.1 skrll "R_M32R_GOT16_LO", /* name */
1072 1.1 skrll false, /* partial_inplace */
1073 1.1.1.9 christos 0x0000ffff, /* src_mask */
1074 1.1 skrll 0x0000ffff, /* dst_mask */
1075 1.1 skrll false), /* pcrel_offset */
1076 1.1 skrll
1077 1.1 skrll /* An PC Relative relocation used when setting PIC offset table register.
1078 1.1 skrll Like R_M32R_HI16_ULO, but referring to the GOT table entry for
1079 1.1 skrll the symbol. */
1080 1.1.1.9 christos HOWTO (R_M32R_GOTPC_HI_ULO, /* type */
1081 1.1 skrll 16, /* rightshift */
1082 1.1.1.9 christos 4, /* size */
1083 1.1 skrll 16, /* bitsize */
1084 1.1 skrll false, /* pc_relative */
1085 1.1 skrll 0, /* bitpos */
1086 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1087 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1088 1.1 skrll "R_M32R_GOTPC_HI_ULO", /* name */
1089 1.1 skrll false, /* partial_inplace */
1090 1.1.1.9 christos 0x0000ffff, /* src_mask */
1091 1.1 skrll 0x0000ffff, /* dst_mask */
1092 1.1 skrll true), /* pcrel_offset */
1093 1.1 skrll
1094 1.1 skrll /* An PC Relative relocation used when setting PIC offset table register.
1095 1.1 skrll Like R_M32R_HI16_SLO, but referring to the GOT table entry for
1096 1.1 skrll the symbol. */
1097 1.1.1.9 christos HOWTO (R_M32R_GOTPC_HI_SLO, /* type */
1098 1.1 skrll 16, /* rightshift */
1099 1.1.1.9 christos 4, /* size */
1100 1.1 skrll 16, /* bitsize */
1101 1.1 skrll false, /* pc_relative */
1102 1.1 skrll 0, /* bitpos */
1103 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1104 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1105 1.1 skrll "R_M32R_GOTPC_HI_SLO", /* name */
1106 1.1 skrll false, /* partial_inplace */
1107 1.1.1.9 christos 0x0000ffff, /* src_mask */
1108 1.1 skrll 0x0000ffff, /* dst_mask */
1109 1.1 skrll true), /* pcrel_offset */
1110 1.1 skrll
1111 1.1 skrll /* An PC Relative relocation used when setting PIC offset table register.
1112 1.1 skrll Like R_M32R_LO16, but referring to the GOT table entry for
1113 1.1 skrll the symbol. */
1114 1.1.1.9 christos HOWTO (R_M32R_GOTPC_LO, /* type */
1115 1.1 skrll 0, /* rightshift */
1116 1.1.1.9 christos 4, /* size */
1117 1.1 skrll 16, /* bitsize */
1118 1.1 skrll false, /* pc_relative */
1119 1.1 skrll 0, /* bitpos */
1120 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1121 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1122 1.1 skrll "R_M32R_GOTPC_LO", /* name */
1123 1.1 skrll false, /* partial_inplace */
1124 1.1.1.9 christos 0x0000ffff, /* src_mask */
1125 1.1 skrll 0x0000ffff, /* dst_mask */
1126 1.1 skrll true), /* pcrel_offset */
1127 1.1 skrll
1128 1.1.1.9 christos HOWTO (R_M32R_GOTOFF_HI_ULO, /* type */
1129 1.1 skrll 16, /* rightshift */
1130 1.1.1.9 christos 4, /* size */
1131 1.1 skrll 16, /* bitsize */
1132 1.1 skrll false, /* pc_relative */
1133 1.1 skrll 0, /* bitpos */
1134 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1135 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1136 1.1 skrll "R_M32R_GOTOFF_HI_ULO",/* name */
1137 1.1 skrll false, /* partial_inplace */
1138 1.1.1.9 christos 0x0000ffff, /* src_mask */
1139 1.1 skrll 0x0000ffff, /* dst_mask */
1140 1.1 skrll false), /* pcrel_offset */
1141 1.1 skrll
1142 1.1.1.9 christos HOWTO (R_M32R_GOTOFF_HI_SLO, /* type */
1143 1.1 skrll 16, /* rightshift */
1144 1.1.1.9 christos 4, /* size */
1145 1.1 skrll 16, /* bitsize */
1146 1.1 skrll false, /* pc_relative */
1147 1.1 skrll 0, /* bitpos */
1148 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1149 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1150 1.1 skrll "R_M32R_GOTOFF_HI_SLO",/* name */
1151 1.1 skrll false, /* partial_inplace */
1152 1.1.1.9 christos 0x0000ffff, /* src_mask */
1153 1.1 skrll 0x0000ffff, /* dst_mask */
1154 1.1 skrll false), /* pcrel_offset */
1155 1.1 skrll
1156 1.1.1.9 christos HOWTO (R_M32R_GOTOFF_LO, /* type */
1157 1.1 skrll 0, /* rightshift */
1158 1.1.1.9 christos 4, /* size */
1159 1.1 skrll 16, /* bitsize */
1160 1.1 skrll false, /* pc_relative */
1161 1.1 skrll 0, /* bitpos */
1162 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
1163 1.1.1.9 christos bfd_elf_generic_reloc, /* special_function */
1164 1.1 skrll "R_M32R_GOTOFF_LO", /* name */
1165 1.1 skrll false, /* partial_inplace */
1166 1.1.1.9 christos 0x0000ffff, /* src_mask */
1167 1.1 skrll 0x0000ffff, /* dst_mask */
1168 1.1 skrll false), /* pcrel_offset */
1169 1.1 skrll };
1170 1.1 skrll
1171 1.1 skrll /* Map BFD reloc types to M32R ELF reloc types. */
1172 1.1 skrll
1173 1.1 skrll struct m32r_reloc_map
1174 1.1 skrll {
1175 1.1 skrll bfd_reloc_code_real_type bfd_reloc_val;
1176 1.1 skrll unsigned char elf_reloc_val;
1177 1.1 skrll };
1178 1.1 skrll
1179 1.1 skrll #ifdef USE_M32R_OLD_RELOC
1180 1.1 skrll static const struct m32r_reloc_map m32r_reloc_map_old[] =
1181 1.1 skrll {
1182 1.1 skrll { BFD_RELOC_NONE, R_M32R_NONE },
1183 1.1 skrll { BFD_RELOC_16, R_M32R_16 },
1184 1.1 skrll { BFD_RELOC_32, R_M32R_32 },
1185 1.1 skrll { BFD_RELOC_M32R_24, R_M32R_24 },
1186 1.1 skrll { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL },
1187 1.1 skrll { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL },
1188 1.1 skrll { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL },
1189 1.1 skrll { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO },
1190 1.1 skrll { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO },
1191 1.1 skrll { BFD_RELOC_M32R_LO16, R_M32R_LO16 },
1192 1.1 skrll { BFD_RELOC_M32R_SDA16, R_M32R_SDA16 },
1193 1.1 skrll { BFD_RELOC_VTABLE_INHERIT, R_M32R_GNU_VTINHERIT },
1194 1.1 skrll { BFD_RELOC_VTABLE_ENTRY, R_M32R_GNU_VTENTRY },
1195 1.1 skrll };
1196 1.1 skrll #else
1197 1.1 skrll static const struct m32r_reloc_map m32r_reloc_map[] =
1198 1.1 skrll {
1199 1.1 skrll { BFD_RELOC_NONE, R_M32R_NONE },
1200 1.1 skrll { BFD_RELOC_16, R_M32R_16_RELA },
1201 1.1 skrll { BFD_RELOC_32, R_M32R_32_RELA },
1202 1.1 skrll { BFD_RELOC_M32R_24, R_M32R_24_RELA },
1203 1.1 skrll { BFD_RELOC_M32R_10_PCREL, R_M32R_10_PCREL_RELA },
1204 1.1 skrll { BFD_RELOC_M32R_18_PCREL, R_M32R_18_PCREL_RELA },
1205 1.1 skrll { BFD_RELOC_M32R_26_PCREL, R_M32R_26_PCREL_RELA },
1206 1.1 skrll { BFD_RELOC_M32R_HI16_ULO, R_M32R_HI16_ULO_RELA },
1207 1.1 skrll { BFD_RELOC_M32R_HI16_SLO, R_M32R_HI16_SLO_RELA },
1208 1.1 skrll { BFD_RELOC_M32R_LO16, R_M32R_LO16_RELA },
1209 1.1 skrll { BFD_RELOC_M32R_SDA16, R_M32R_SDA16_RELA },
1210 1.1 skrll { BFD_RELOC_VTABLE_INHERIT, R_M32R_RELA_GNU_VTINHERIT },
1211 1.1 skrll { BFD_RELOC_VTABLE_ENTRY, R_M32R_RELA_GNU_VTENTRY },
1212 1.1 skrll { BFD_RELOC_32_PCREL, R_M32R_REL32 },
1213 1.1 skrll
1214 1.1 skrll { BFD_RELOC_M32R_GOT24, R_M32R_GOT24 },
1215 1.1 skrll { BFD_RELOC_M32R_26_PLTREL, R_M32R_26_PLTREL },
1216 1.1 skrll { BFD_RELOC_M32R_COPY, R_M32R_COPY },
1217 1.1 skrll { BFD_RELOC_M32R_GLOB_DAT, R_M32R_GLOB_DAT },
1218 1.1 skrll { BFD_RELOC_M32R_JMP_SLOT, R_M32R_JMP_SLOT },
1219 1.1 skrll { BFD_RELOC_M32R_RELATIVE, R_M32R_RELATIVE },
1220 1.1 skrll { BFD_RELOC_M32R_GOTOFF, R_M32R_GOTOFF },
1221 1.1 skrll { BFD_RELOC_M32R_GOTPC24, R_M32R_GOTPC24 },
1222 1.1 skrll { BFD_RELOC_M32R_GOT16_HI_ULO, R_M32R_GOT16_HI_ULO },
1223 1.1 skrll { BFD_RELOC_M32R_GOT16_HI_SLO, R_M32R_GOT16_HI_SLO },
1224 1.1 skrll { BFD_RELOC_M32R_GOT16_LO, R_M32R_GOT16_LO },
1225 1.1 skrll { BFD_RELOC_M32R_GOTPC_HI_ULO, R_M32R_GOTPC_HI_ULO },
1226 1.1 skrll { BFD_RELOC_M32R_GOTPC_HI_SLO, R_M32R_GOTPC_HI_SLO },
1227 1.1 skrll { BFD_RELOC_M32R_GOTPC_LO, R_M32R_GOTPC_LO },
1228 1.1 skrll { BFD_RELOC_M32R_GOTOFF_HI_ULO, R_M32R_GOTOFF_HI_ULO },
1229 1.1 skrll { BFD_RELOC_M32R_GOTOFF_HI_SLO, R_M32R_GOTOFF_HI_SLO },
1230 1.1 skrll { BFD_RELOC_M32R_GOTOFF_LO, R_M32R_GOTOFF_LO },
1231 1.1 skrll };
1232 1.1 skrll #endif
1233 1.1 skrll
1234 1.1 skrll static reloc_howto_type *
1235 1.1 skrll bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1236 1.1 skrll bfd_reloc_code_real_type code)
1237 1.1 skrll {
1238 1.1 skrll unsigned int i;
1239 1.1 skrll
1240 1.1 skrll #ifdef USE_M32R_OLD_RELOC
1241 1.1 skrll for (i = 0;
1242 1.1 skrll i < sizeof (m32r_reloc_map_old) / sizeof (struct m32r_reloc_map);
1243 1.1 skrll i++)
1244 1.1 skrll if (m32r_reloc_map_old[i].bfd_reloc_val == code)
1245 1.1 skrll return &m32r_elf_howto_table[m32r_reloc_map_old[i].elf_reloc_val];
1246 1.1 skrll
1247 1.1 skrll #else /* ! USE_M32R_OLD_RELOC */
1248 1.1 skrll
1249 1.1 skrll for (i = 0;
1250 1.1 skrll i < sizeof (m32r_reloc_map) / sizeof (struct m32r_reloc_map);
1251 1.1 skrll i++)
1252 1.1 skrll if (m32r_reloc_map[i].bfd_reloc_val == code)
1253 1.1 skrll return &m32r_elf_howto_table[m32r_reloc_map[i].elf_reloc_val];
1254 1.1 skrll #endif
1255 1.1 skrll
1256 1.1 skrll return NULL;
1257 1.1 skrll }
1258 1.1 skrll
1259 1.1 skrll static reloc_howto_type *
1260 1.1 skrll bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1261 1.1 skrll const char *r_name)
1262 1.1 skrll {
1263 1.1 skrll unsigned int i;
1264 1.1 skrll
1265 1.1 skrll for (i = 0;
1266 1.1 skrll i < sizeof (m32r_elf_howto_table) / sizeof (m32r_elf_howto_table[0]);
1267 1.1 skrll i++)
1268 1.1 skrll if (m32r_elf_howto_table[i].name != NULL
1269 1.1 skrll && strcasecmp (m32r_elf_howto_table[i].name, r_name) == 0)
1270 1.1 skrll return &m32r_elf_howto_table[i];
1271 1.1 skrll
1272 1.1 skrll return NULL;
1273 1.1 skrll }
1274 1.1 skrll
1275 1.1.1.9 christos /* Set the howto pointer for an M32R ELF reloc. */
1276 1.1 skrll
1277 1.1 skrll static bool
1278 1.1 skrll m32r_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1279 1.1 skrll arelent *cache_ptr,
1280 1.1 skrll Elf_Internal_Rela *dst)
1281 1.1 skrll {
1282 1.1 skrll unsigned int r_type;
1283 1.1.1.4 christos
1284 1.1.1.4 christos r_type = ELF32_R_TYPE (dst->r_info);
1285 1.1.1.6 christos if (r_type > (unsigned int) R_M32R_GNU_VTENTRY)
1286 1.1.1.7 christos {
1287 1.1.1.7 christos /* xgettext:c-format */
1288 1.1.1.7 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1289 1.1.1.9 christos abfd, r_type);
1290 1.1.1.4 christos bfd_set_error (bfd_error_bad_value);
1291 1.1 skrll return false;
1292 1.1.1.9 christos }
1293 1.1 skrll cache_ptr->howto = &m32r_elf_howto_table[r_type];
1294 1.1 skrll return true;
1295 1.1.1.9 christos }
1296 1.1 skrll
1297 1.1 skrll static bool
1298 1.1 skrll m32r_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
1299 1.1 skrll arelent *cache_ptr,
1300 1.1.1.7 christos Elf_Internal_Rela *dst)
1301 1.1.1.7 christos {
1302 1.1.1.7 christos unsigned int r_type = ELF32_R_TYPE (dst->r_info);
1303 1.1.1.7 christos
1304 1.1.1.7 christos if (r_type == (unsigned int) R_M32R_NONE
1305 1.1.1.7 christos || ((r_type > (unsigned int) R_M32R_GNU_VTENTRY)
1306 1.1.1.7 christos && (r_type < (unsigned int) R_M32R_max)))
1307 1.1.1.9 christos {
1308 1.1.1.7 christos cache_ptr->howto = &m32r_elf_howto_table[r_type];
1309 1.1.1.7 christos return true;
1310 1.1.1.7 christos }
1311 1.1.1.7 christos
1312 1.1.1.7 christos /* xgettext:c-format */
1313 1.1.1.9 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
1314 1.1 skrll bfd_set_error (bfd_error_bad_value);
1315 1.1 skrll return false;
1316 1.1 skrll }
1317 1.1 skrll
1318 1.1 skrll
1319 1.1 skrll /* Given a BFD section, try to locate the corresponding ELF section
1321 1.1 skrll index. */
1322 1.1 skrll
1323 1.1 skrll static bool
1324 1.1 skrll _bfd_m32r_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
1325 1.1.1.8 christos asection *sec,
1326 1.1 skrll int *retval)
1327 1.1 skrll {
1328 1.1.1.9 christos if (strcmp (bfd_section_name (sec), ".scommon") == 0)
1329 1.1 skrll {
1330 1.1.1.9 christos *retval = SHN_M32R_SCOMMON;
1331 1.1 skrll return true;
1332 1.1 skrll }
1333 1.1 skrll return false;
1334 1.1 skrll }
1335 1.1 skrll
1336 1.1 skrll /* M32R ELF uses two common sections. One is the usual one, and the other
1337 1.1 skrll is for small objects. All the small objects are kept together, and then
1338 1.1 skrll referenced via one register, which yields faster assembler code. It is
1339 1.1 skrll up to the compiler to emit an instruction to load the register with
1340 1.1.1.9 christos _SDA_BASE. This is what we use for the small common section. This
1341 1.1.1.9 christos approach is copied from elf32-mips.c. */
1342 1.1.1.9 christos static asection m32r_elf_scom_section;
1343 1.1.1.9 christos static const asymbol m32r_elf_scom_symbol =
1344 1.1.1.9 christos GLOBAL_SYM_INIT (".scommon", &m32r_elf_scom_section);
1345 1.1 skrll static asection m32r_elf_scom_section =
1346 1.1 skrll BFD_FAKE_SECTION (m32r_elf_scom_section, &m32r_elf_scom_symbol,
1347 1.1 skrll ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
1348 1.1 skrll
1349 1.1 skrll /* Handle the special M32R section numbers that a symbol may use. */
1350 1.1 skrll
1351 1.1 skrll static void
1352 1.1 skrll _bfd_m32r_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
1353 1.1 skrll {
1354 1.1 skrll elf_symbol_type *elfsym = (elf_symbol_type *) asym;
1355 1.1 skrll
1356 1.1 skrll switch (elfsym->internal_elf_sym.st_shndx)
1357 1.1 skrll {
1358 1.1 skrll case SHN_M32R_SCOMMON:
1359 1.1 skrll asym->section = &m32r_elf_scom_section;
1360 1.1 skrll asym->value = elfsym->internal_elf_sym.st_size;
1361 1.1 skrll break;
1362 1.1 skrll }
1363 1.1 skrll }
1364 1.1 skrll
1365 1.1 skrll /* Hook called by the linker routine which adds symbols from an object
1366 1.1 skrll file. We must handle the special M32R section numbers here.
1367 1.1.1.9 christos We also keep watching for whether we need to create the sdata special
1368 1.1 skrll linker sections. */
1369 1.1 skrll
1370 1.1 skrll static bool
1371 1.1 skrll m32r_elf_add_symbol_hook (bfd *abfd,
1372 1.1 skrll struct bfd_link_info *info,
1373 1.1 skrll Elf_Internal_Sym *sym,
1374 1.1 skrll const char **namep,
1375 1.1 skrll flagword *flagsp ATTRIBUTE_UNUSED,
1376 1.1.1.4 christos asection **secp,
1377 1.1 skrll bfd_vma *valp)
1378 1.1 skrll {
1379 1.1 skrll if (! bfd_link_relocatable (info)
1380 1.1 skrll && (*namep)[0] == '_' && (*namep)[1] == 'S'
1381 1.1 skrll && strcmp (*namep, "_SDA_BASE_") == 0
1382 1.1 skrll && is_elf_hash_table (info->hash))
1383 1.1 skrll {
1384 1.1 skrll /* This is simpler than using _bfd_elf_create_linker_section
1385 1.1 skrll (our needs are simpler than ppc's needs). Also
1386 1.1 skrll _bfd_elf_create_linker_section currently has a bug where if a .sdata
1387 1.1 skrll section already exists a new one is created that follows it which
1388 1.1 skrll screws of _SDA_BASE_ address calcs because output_offset != 0. */
1389 1.1 skrll struct elf_link_hash_entry *h;
1390 1.1 skrll struct bfd_link_hash_entry *bh;
1391 1.1 skrll asection *s = bfd_get_section_by_name (abfd, ".sdata");
1392 1.1 skrll
1393 1.1 skrll /* The following code was cobbled from elf32-ppc.c and elflink.c. */
1394 1.1 skrll if (s == NULL)
1395 1.1 skrll {
1396 1.1 skrll flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1397 1.1 skrll | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1398 1.1 skrll
1399 1.1.1.9 christos s = bfd_make_section_anyway_with_flags (abfd, ".sdata",
1400 1.1.1.8 christos flags);
1401 1.1.1.9 christos if (s == NULL)
1402 1.1 skrll return false;
1403 1.1 skrll if (!bfd_set_section_alignment (s, 2))
1404 1.1 skrll return false;
1405 1.1.1.9 christos }
1406 1.1 skrll
1407 1.1 skrll bh = bfd_link_hash_lookup (info->hash, "_SDA_BASE_",
1408 1.1 skrll false, false, false);
1409 1.1 skrll
1410 1.1 skrll if ((bh == NULL || bh->type == bfd_link_hash_undefined)
1411 1.1 skrll && !(_bfd_generic_link_add_one_symbol (info,
1412 1.1 skrll abfd,
1413 1.1 skrll "_SDA_BASE_",
1414 1.1 skrll BSF_GLOBAL,
1415 1.1.1.9 christos s,
1416 1.1 skrll (bfd_vma) 32768,
1417 1.1 skrll NULL,
1418 1.1.1.9 christos false,
1419 1.1 skrll get_elf_backend_data (abfd)->collect,
1420 1.1 skrll &bh)))
1421 1.1 skrll return false;
1422 1.1 skrll h = (struct elf_link_hash_entry *) bh;
1423 1.1 skrll h->type = STT_OBJECT;
1424 1.1 skrll }
1425 1.1 skrll
1426 1.1 skrll switch (sym->st_shndx)
1427 1.1.1.9 christos {
1428 1.1 skrll case SHN_M32R_SCOMMON:
1429 1.1 skrll *secp = bfd_make_section_old_way (abfd, ".scommon");
1430 1.1 skrll (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
1431 1.1 skrll *valp = sym->st_size;
1432 1.1.1.9 christos break;
1433 1.1 skrll }
1434 1.1 skrll
1435 1.1 skrll return true;
1436 1.1 skrll }
1437 1.1 skrll
1438 1.1 skrll /* We have to figure out the SDA_BASE value, so that we can adjust the
1439 1.1 skrll symbol value correctly. We look up the symbol _SDA_BASE_ in the output
1440 1.1 skrll BFD. If we can't find it, we're stuck. We cache it in the ELF
1441 1.1 skrll target data. We don't need to adjust the symbol value for an
1442 1.1 skrll external symbol if we are producing relocatable output. */
1443 1.1 skrll
1444 1.1 skrll static bfd_reloc_status_type
1445 1.1 skrll m32r_elf_final_sda_base (bfd *output_bfd,
1446 1.1 skrll struct bfd_link_info *info,
1447 1.1 skrll const char **error_message,
1448 1.1 skrll bfd_vma *psb)
1449 1.1 skrll {
1450 1.1 skrll if (elf_gp (output_bfd) == 0)
1451 1.1.1.9 christos {
1452 1.1 skrll struct bfd_link_hash_entry *h;
1453 1.1 skrll
1454 1.1 skrll h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", false, false, true);
1455 1.1 skrll if (h != NULL && h->type == bfd_link_hash_defined)
1456 1.1 skrll elf_gp (output_bfd) = (h->u.def.value
1457 1.1 skrll + h->u.def.section->output_section->vma
1458 1.1 skrll + h->u.def.section->output_offset);
1459 1.1 skrll else
1460 1.1 skrll {
1461 1.1 skrll /* Only get the error once. */
1462 1.1 skrll *psb = elf_gp (output_bfd) = 4;
1463 1.1 skrll *error_message =
1464 1.1 skrll (const char *) _("SDA relocation when _SDA_BASE_ not defined");
1465 1.1 skrll return bfd_reloc_dangerous;
1466 1.1 skrll }
1467 1.1 skrll }
1468 1.1 skrll *psb = elf_gp (output_bfd);
1469 1.1 skrll return bfd_reloc_ok;
1470 1.1 skrll }
1471 1.1 skrll
1472 1.1 skrll /* Return size of a PLT entry. */
1474 1.1 skrll #define elf_m32r_sizeof_plt(info) PLT_ENTRY_SIZE
1475 1.1 skrll
1476 1.1 skrll /* The m32r linker needs to keep track of the number of relocs that it
1477 1.1 skrll decides to copy in check_relocs for each symbol. This is so that
1478 1.1 skrll it can discard PC relative relocs if it doesn't need them when
1479 1.1 skrll linking with -Bsymbolic. We store the information in a field
1480 1.1 skrll extending the regular ELF linker hash table. */
1481 1.1 skrll
1482 1.1 skrll /* This structure keeps track of the number of PC relative relocs we
1483 1.1 skrll have copied for a given symbol. */
1484 1.1 skrll
1485 1.1 skrll struct elf_m32r_pcrel_relocs_copied
1486 1.1 skrll {
1487 1.1 skrll /* Next section. */
1488 1.1 skrll struct elf_m32r_pcrel_relocs_copied *next;
1489 1.1 skrll /* A section in dynobj. */
1490 1.1 skrll asection *section;
1491 1.1 skrll /* Number of relocs copied in this section. */
1492 1.1 skrll bfd_size_type count;
1493 1.1 skrll };
1494 1.1 skrll
1495 1.1 skrll /* Traverse an m32r ELF linker hash table. */
1496 1.1.1.9 christos
1497 1.1 skrll #define m32r_elf_link_hash_traverse(table, func, info) \
1498 1.1 skrll (elf_link_hash_traverse \
1499 1.1 skrll (&(table)->root, \
1500 1.1 skrll (bool (*) (struct elf_link_hash_entry *, void *)) (func), \
1501 1.1 skrll (info)))
1502 1.1.1.9 christos
1503 1.1.1.9 christos /* Get the m32r ELF linker hash table from a link_info structure. */
1504 1.1.1.9 christos
1505 1.1 skrll #define m32r_elf_hash_table(p) \
1506 1.1 skrll ((is_elf_hash_table ((p)->hash) \
1507 1.1 skrll && elf_hash_table_id (elf_hash_table (p)) == M32R_ELF_DATA) \
1508 1.1 skrll ? (struct elf_link_hash_table *) (p)->hash : NULL)
1509 1.1 skrll
1510 1.1 skrll /* Create an m32r ELF linker hash table. */
1511 1.1.1.9 christos
1512 1.1.1.9 christos static struct bfd_link_hash_table *
1513 1.1 skrll m32r_elf_link_hash_table_create (bfd *abfd)
1514 1.1.1.4 christos {
1515 1.1 skrll struct elf_link_hash_table *ret;
1516 1.1 skrll size_t amt = sizeof (struct elf_link_hash_table);
1517 1.1 skrll
1518 1.1.1.9 christos ret = bfd_zmalloc (amt);
1519 1.1.1.9 christos if (ret == NULL)
1520 1.1.1.9 christos return NULL;
1521 1.1.1.2 christos
1522 1.1 skrll if (!_bfd_elf_link_hash_table_init (ret, abfd,
1523 1.1 skrll _bfd_elf_link_hash_newfunc,
1524 1.1 skrll sizeof (struct elf_link_hash_entry),
1525 1.1 skrll M32R_ELF_DATA))
1526 1.1 skrll {
1527 1.1.1.9 christos free (ret);
1528 1.1 skrll return NULL;
1529 1.1 skrll }
1530 1.1 skrll
1531 1.1 skrll return &ret->root;
1532 1.1.1.9 christos }
1533 1.1 skrll
1534 1.1 skrll /* Create dynamic sections when linking against a dynamic object. */
1535 1.1.1.9 christos
1536 1.1 skrll static bool
1537 1.1 skrll m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
1538 1.1 skrll {
1539 1.1 skrll struct elf_link_hash_table *htab;
1540 1.1 skrll flagword flags, pltflags;
1541 1.1 skrll asection *s;
1542 1.1.1.2 christos const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1543 1.1.1.9 christos int ptralign = 2; /* 32bit */
1544 1.1 skrll
1545 1.1 skrll htab = m32r_elf_hash_table (info);
1546 1.1 skrll if (htab == NULL)
1547 1.1 skrll return false;
1548 1.1.1.6 christos
1549 1.1 skrll /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
1550 1.1 skrll .rel[a].bss sections. */
1551 1.1 skrll flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1552 1.1 skrll | SEC_LINKER_CREATED);
1553 1.1 skrll
1554 1.1 skrll pltflags = flags;
1555 1.1 skrll pltflags |= SEC_CODE;
1556 1.1 skrll if (bed->plt_not_loaded)
1557 1.1.1.3 christos pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
1558 1.1.1.9 christos if (bed->plt_readonly)
1559 1.1 skrll pltflags |= SEC_READONLY;
1560 1.1.1.8 christos
1561 1.1.1.9 christos s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
1562 1.1 skrll htab->splt = s;
1563 1.1 skrll if (s == NULL
1564 1.1 skrll || !bfd_set_section_alignment (s, bed->plt_alignment))
1565 1.1 skrll return false;
1566 1.1.1.6 christos
1567 1.1 skrll if (bed->want_plt_sym)
1568 1.1 skrll {
1569 1.1 skrll /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1570 1.1 skrll .plt section. */
1571 1.1.1.6 christos struct bfd_link_hash_entry *bh = NULL;
1572 1.1.1.9 christos struct elf_link_hash_entry *h;
1573 1.1.1.6 christos
1574 1.1.1.9 christos if (! (_bfd_generic_link_add_one_symbol
1575 1.1 skrll (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1576 1.1 skrll (bfd_vma) 0, NULL, false,
1577 1.1 skrll get_elf_backend_data (abfd)->collect, &bh)))
1578 1.1.1.9 christos return false;
1579 1.1 skrll h = (struct elf_link_hash_entry *) bh;
1580 1.1.1.4 christos h->def_regular = 1;
1581 1.1.1.6 christos h->type = STT_OBJECT;
1582 1.1.1.9 christos htab->hplt = h;
1583 1.1 skrll
1584 1.1 skrll if (bfd_link_pic (info)
1585 1.1.1.3 christos && ! bfd_elf_link_record_dynamic_symbol (info, h))
1586 1.1.1.3 christos return false;
1587 1.1.1.3 christos }
1588 1.1.1.3 christos
1589 1.1.1.9 christos s = bfd_make_section_anyway_with_flags (abfd,
1590 1.1 skrll bed->default_use_rela_p
1591 1.1.1.8 christos ? ".rela.plt" : ".rel.plt",
1592 1.1.1.9 christos flags | SEC_READONLY);
1593 1.1 skrll htab->srelplt = s;
1594 1.1.1.9 christos if (s == NULL
1595 1.1.1.6 christos || !bfd_set_section_alignment (s, ptralign))
1596 1.1.1.9 christos return false;
1597 1.1 skrll
1598 1.1 skrll if (htab->sgot == NULL
1599 1.1 skrll && !_bfd_elf_create_got_section (abfd, info))
1600 1.1 skrll return false;
1601 1.1.1.6 christos
1602 1.1.1.6 christos if (bed->want_dynbss)
1603 1.1.1.6 christos {
1604 1.1.1.6 christos /* The .dynbss section is a place to put symbols which are defined
1605 1.1.1.6 christos by dynamic objects, are referenced by regular objects, and are
1606 1.1.1.3 christos not functions. We must allocate space for them in the process
1607 1.1.1.3 christos image and use a R_*_COPY reloc to tell the dynamic linker to
1608 1.1 skrll initialize them at run time. The linker script puts the .dynbss
1609 1.1 skrll section into the .bss section of the final image. */
1610 1.1.1.9 christos s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
1611 1.1 skrll SEC_ALLOC | SEC_LINKER_CREATED);
1612 1.1.1.6 christos htab->sdynbss = s;
1613 1.1.1.6 christos if (s == NULL)
1614 1.1.1.6 christos return false;
1615 1.1.1.6 christos /* The .rel[a].bss section holds copy relocs. This section is not
1616 1.1.1.6 christos normally needed. We need to create it here, though, so that the
1617 1.1.1.6 christos linker will map it to an output section. We can't just create it
1618 1.1.1.6 christos only if we need it, because we will not know whether we need it
1619 1.1.1.6 christos until we have seen all the input files, and the first time the
1620 1.1.1.6 christos main linker code calls BFD after examining all the input files
1621 1.1.1.6 christos (size_dynamic_sections) the input sections have already been
1622 1.1.1.4 christos mapped to the output sections. If the section turns out not to
1623 1.1.1.6 christos be needed, we can discard it later. We will never need this
1624 1.1.1.6 christos section when generating a shared object, since they do not use
1625 1.1.1.3 christos copy relocs. */
1626 1.1.1.3 christos if (! bfd_link_pic (info))
1627 1.1.1.3 christos {
1628 1.1.1.6 christos s = bfd_make_section_anyway_with_flags (abfd,
1629 1.1.1.6 christos (bed->default_use_rela_p
1630 1.1.1.8 christos ? ".rela.bss" : ".rel.bss"),
1631 1.1.1.9 christos flags | SEC_READONLY);
1632 1.1.1.6 christos htab->srelbss = s;
1633 1.1 skrll if (s == NULL
1634 1.1 skrll || !bfd_set_section_alignment (s, ptralign))
1635 1.1.1.9 christos return false;
1636 1.1 skrll }
1637 1.1 skrll }
1638 1.1 skrll
1639 1.1 skrll return true;
1640 1.1 skrll }
1641 1.1 skrll
1642 1.1 skrll
1643 1.1 skrll /* Adjust a symbol defined by a dynamic object and referenced by a
1645 1.1.1.9 christos regular object. The current definition is in some section of the
1646 1.1 skrll dynamic object, but we're not including those sections. We have to
1647 1.1 skrll change the definition to something the rest of the link can
1648 1.1 skrll understand. */
1649 1.1.1.9 christos
1650 1.1 skrll static bool
1651 1.1 skrll m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1652 1.1 skrll struct elf_link_hash_entry *h)
1653 1.1 skrll {
1654 1.1 skrll struct elf_link_hash_table *htab;
1655 1.1 skrll bfd *dynobj;
1656 1.1 skrll asection *s;
1657 1.1 skrll
1658 1.1 skrll #ifdef DEBUG_PIC
1659 1.1 skrll printf ("m32r_elf_adjust_dynamic_symbol()\n");
1660 1.1 skrll #endif
1661 1.1.1.6 christos
1662 1.1.1.6 christos dynobj = elf_hash_table (info)->dynobj;
1663 1.1.1.6 christos
1664 1.1.1.6 christos /* Make sure we know what is going on here. */
1665 1.1.1.6 christos BFD_ASSERT (dynobj != NULL
1666 1.1 skrll && (h->needs_plt
1667 1.1 skrll || h->is_weakalias
1668 1.1 skrll || (h->def_dynamic
1669 1.1 skrll && h->ref_regular
1670 1.1 skrll && !h->def_regular)));
1671 1.1 skrll
1672 1.1 skrll /* If this is a function, put it in the procedure linkage table. We
1673 1.1.1.4 christos will fill in the contents of the procedure linkage table later,
1674 1.1.1.6 christos when we know the address of the .got section. */
1675 1.1.1.6 christos if (h->type == STT_FUNC
1676 1.1 skrll || h->needs_plt)
1677 1.1 skrll {
1678 1.1.1.6 christos if (! bfd_link_pic (info)
1679 1.1.1.6 christos && !h->def_dynamic
1680 1.1.1.6 christos && !h->ref_dynamic
1681 1.1.1.6 christos && h->root.type != bfd_link_hash_undefweak
1682 1.1.1.6 christos && h->root.type != bfd_link_hash_undefined)
1683 1.1.1.6 christos {
1684 1.1.1.6 christos /* This case can occur if we saw a PLT reloc in an input
1685 1.1.1.6 christos file, but the symbol was never referred to by a dynamic
1686 1.1.1.6 christos object. In such a case, we don't actually need to build
1687 1.1 skrll a procedure linkage table, and we can just do a PCREL
1688 1.1.1.9 christos reloc instead. */
1689 1.1 skrll h->plt.offset = (bfd_vma) -1;
1690 1.1 skrll h->needs_plt = 0;
1691 1.1 skrll }
1692 1.1 skrll
1693 1.1 skrll return true;
1694 1.1 skrll }
1695 1.1 skrll else
1696 1.1.1.6 christos h->plt.offset = (bfd_vma) -1;
1697 1.1 skrll
1698 1.1.1.6 christos /* If this is a weak symbol, and there is a real definition, the
1699 1.1.1.6 christos processor independent code will have arranged for us to see the
1700 1.1.1.6 christos real definition first, and we can just use the same value. */
1701 1.1.1.6 christos if (h->is_weakalias)
1702 1.1.1.9 christos {
1703 1.1 skrll struct elf_link_hash_entry *def = weakdef (h);
1704 1.1 skrll BFD_ASSERT (def->root.type == bfd_link_hash_defined);
1705 1.1 skrll h->root.u.def.section = def->root.u.def.section;
1706 1.1 skrll h->root.u.def.value = def->root.u.def.value;
1707 1.1 skrll return true;
1708 1.1 skrll }
1709 1.1 skrll
1710 1.1 skrll /* This is a reference to a symbol defined by a dynamic object which
1711 1.1 skrll is not a function. */
1712 1.1.1.4 christos
1713 1.1.1.9 christos /* If we are creating a shared library, we must presume that the
1714 1.1 skrll only references to the symbol are via the global offset table.
1715 1.1 skrll For such cases we need not do anything here; the relocations will
1716 1.1 skrll be handled correctly by relocate_section. */
1717 1.1 skrll if (bfd_link_pic (info))
1718 1.1.1.9 christos return true;
1719 1.1 skrll
1720 1.1 skrll /* If there are no references to this symbol that do not use the
1721 1.1.1.6 christos GOT, we don't need to generate a copy reloc. */
1722 1.1 skrll if (!h->non_got_ref)
1723 1.1 skrll return true;
1724 1.1.1.9 christos
1725 1.1 skrll /* If -z nocopyreloc was given, we won't generate them either. */
1726 1.1 skrll if (0 && info->nocopyreloc)
1727 1.1.1.6 christos {
1728 1.1.1.6 christos h->non_got_ref = 0;
1729 1.1.1.9 christos return true;
1730 1.1 skrll }
1731 1.1 skrll
1732 1.1.1.9 christos /* If we don't find any dynamic relocs in read-only sections, then
1733 1.1 skrll we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1734 1.1 skrll if (0 && !_bfd_elf_readonly_dynrelocs (h))
1735 1.1 skrll {
1736 1.1 skrll h->non_got_ref = 0;
1737 1.1 skrll return true;
1738 1.1 skrll }
1739 1.1 skrll
1740 1.1 skrll /* We must allocate the symbol in our .dynbss section, which will
1741 1.1 skrll become part of the .bss section of the executable. There will be
1742 1.1 skrll an entry for this symbol in the .dynsym section. The dynamic
1743 1.1 skrll object will contain position independent code, so all references
1744 1.1 skrll from the dynamic object to this symbol will go through the global
1745 1.1 skrll offset table. The dynamic linker will use the .dynsym entry to
1746 1.1.1.2 christos determine the address it must put in the global offset table, so
1747 1.1.1.9 christos both the dynamic object and the regular object will refer to the
1748 1.1.1.2 christos same memory location for the variable. */
1749 1.1 skrll
1750 1.1 skrll htab = m32r_elf_hash_table (info);
1751 1.1 skrll if (htab == NULL)
1752 1.1 skrll return false;
1753 1.1 skrll
1754 1.1 skrll s = htab->sdynbss;
1755 1.1 skrll BFD_ASSERT (s != NULL);
1756 1.1.1.3 christos
1757 1.1 skrll /* We must generate a R_M32R_COPY reloc to tell the dynamic linker
1758 1.1 skrll to copy the initial value out of the dynamic object and into the
1759 1.1 skrll runtime process image. We need to remember the offset into the
1760 1.1 skrll .rela.bss section we are going to use. */
1761 1.1 skrll if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
1762 1.1 skrll {
1763 1.1 skrll asection *srel;
1764 1.1 skrll
1765 1.1 skrll srel = htab->srelbss;
1766 1.1.1.4 christos BFD_ASSERT (srel != NULL);
1767 1.1 skrll srel->size += sizeof (Elf32_External_Rela);
1768 1.1 skrll h->needs_copy = 1;
1769 1.1 skrll }
1770 1.1 skrll
1771 1.1 skrll return _bfd_elf_adjust_dynamic_copy (info, h, s);
1772 1.1.1.9 christos }
1773 1.1 skrll
1774 1.1 skrll /* Allocate space in .plt, .got and associated reloc sections for
1775 1.1 skrll dynamic relocs. */
1776 1.1.1.9 christos
1777 1.1.1.6 christos static bool
1778 1.1 skrll allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1779 1.1 skrll {
1780 1.1.1.9 christos struct bfd_link_info *info;
1781 1.1 skrll struct elf_link_hash_table *htab;
1782 1.1 skrll struct elf_dyn_relocs *p;
1783 1.1 skrll
1784 1.1.1.2 christos if (h->root.type == bfd_link_hash_indirect)
1785 1.1.1.9 christos return true;
1786 1.1 skrll
1787 1.1.1.9 christos info = (struct bfd_link_info *) inf;
1788 1.1 skrll htab = m32r_elf_hash_table (info);
1789 1.1 skrll if (htab == NULL)
1790 1.1 skrll return false;
1791 1.1.1.6 christos
1792 1.1 skrll if (htab->dynamic_sections_created
1793 1.1.1.6 christos && h->plt.refcount > 0)
1794 1.1.1.6 christos {
1795 1.1.1.6 christos /* Make sure this symbol is output as a dynamic symbol.
1796 1.1.1.9 christos Undefined weak syms won't yet be marked as dynamic. */
1797 1.1.1.6 christos if (h->dynindx == -1
1798 1.1 skrll && !h->forced_local)
1799 1.1.1.4 christos {
1800 1.1.1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
1801 1.1.1.9 christos return false;
1802 1.1.1.6 christos }
1803 1.1.1.6 christos
1804 1.1.1.6 christos if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
1805 1.1.1.6 christos {
1806 1.1.1.6 christos asection *s = htab->splt;
1807 1.1.1.6 christos
1808 1.1.1.6 christos /* If this is the first .plt entry, make room for the special
1809 1.1.1.6 christos first entry. */
1810 1.1.1.6 christos if (s->size == 0)
1811 1.1.1.6 christos s->size += PLT_ENTRY_SIZE;
1812 1.1.1.6 christos
1813 1.1.1.6 christos h->plt.offset = s->size;
1814 1.1.1.6 christos
1815 1.1.1.6 christos /* If this symbol is not defined in a regular file, and we are
1816 1.1.1.6 christos not generating a shared library, then set the symbol to this
1817 1.1.1.6 christos location in the .plt. This is required to make function
1818 1.1.1.6 christos pointers compare as equal between the normal executable and
1819 1.1.1.6 christos the shared library. */
1820 1.1.1.6 christos if (! bfd_link_pic (info)
1821 1.1.1.6 christos && !h->def_regular)
1822 1.1.1.6 christos {
1823 1.1.1.6 christos h->root.u.def.section = s;
1824 1.1 skrll h->root.u.def.value = h->plt.offset;
1825 1.1.1.6 christos }
1826 1.1.1.6 christos
1827 1.1.1.9 christos /* Make room for this entry. */
1828 1.1.1.6 christos s->size += PLT_ENTRY_SIZE;
1829 1.1.1.6 christos
1830 1.1.1.9 christos /* We also need to make an entry in the .got.plt section, which
1831 1.1.1.6 christos will be placed in the .got section by the linker script. */
1832 1.1 skrll htab->sgotplt->size += 4;
1833 1.1.1.6 christos
1834 1.1.1.6 christos /* We also need to make an entry in the .rel.plt section. */
1835 1.1.1.6 christos htab->srelplt->size += sizeof (Elf32_External_Rela);
1836 1.1.1.6 christos }
1837 1.1 skrll else
1838 1.1 skrll {
1839 1.1 skrll h->plt.offset = (bfd_vma) -1;
1840 1.1 skrll h->needs_plt = 0;
1841 1.1 skrll }
1842 1.1 skrll }
1843 1.1 skrll else
1844 1.1 skrll {
1845 1.1 skrll h->plt.offset = (bfd_vma) -1;
1846 1.1 skrll h->needs_plt = 0;
1847 1.1.1.9 christos }
1848 1.1 skrll
1849 1.1 skrll if (h->got.refcount > 0)
1850 1.1.1.6 christos {
1851 1.1 skrll asection *s;
1852 1.1.1.6 christos bool dyn;
1853 1.1.1.6 christos
1854 1.1.1.6 christos /* Make sure this symbol is output as a dynamic symbol.
1855 1.1.1.9 christos Undefined weak syms won't yet be marked as dynamic. */
1856 1.1.1.6 christos if (h->dynindx == -1
1857 1.1 skrll && !h->forced_local)
1858 1.1.1.9 christos {
1859 1.1 skrll if (! bfd_elf_link_record_dynamic_symbol (info, h))
1860 1.1 skrll return false;
1861 1.1 skrll }
1862 1.1.1.9 christos
1863 1.1.1.4 christos s = htab->sgot;
1864 1.1.1.9 christos
1865 1.1 skrll h->got.offset = s->size;
1866 1.1 skrll s->size += 4;
1867 1.1 skrll dyn = htab->dynamic_sections_created;
1868 1.1 skrll if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
1869 1.1.1.9 christos htab->srelgot->size += sizeof (Elf32_External_Rela);
1870 1.1.1.9 christos }
1871 1.1 skrll else
1872 1.1 skrll h->got.offset = (bfd_vma) -1;
1873 1.1 skrll
1874 1.1 skrll if (h->dyn_relocs == NULL)
1875 1.1 skrll return true;
1876 1.1 skrll
1877 1.1 skrll /* In the shared -Bsymbolic case, discard space allocated for
1878 1.1.1.4 christos dynamic pc-relative relocs against symbols which turn out to be
1879 1.1 skrll defined in regular objects. For the normal shared case, discard
1880 1.1 skrll space for pc-relative relocs that have become local due to symbol
1881 1.1.1.6 christos visibility changes. */
1882 1.1.1.6 christos
1883 1.1.1.6 christos if (bfd_link_pic (info))
1884 1.1.1.6 christos {
1885 1.1.1.6 christos if (h->def_regular
1886 1.1.1.9 christos && (h->forced_local
1887 1.1.1.6 christos || info->symbolic))
1888 1.1.1.6 christos {
1889 1.1.1.6 christos struct elf_dyn_relocs **pp;
1890 1.1.1.6 christos
1891 1.1.1.6 christos for (pp = &h->dyn_relocs; (p = *pp) != NULL;)
1892 1.1.1.6 christos {
1893 1.1.1.6 christos p->count -= p->pc_count;
1894 1.1.1.6 christos p->pc_count = 0;
1895 1.1.1.6 christos if (p->count == 0)
1896 1.1 skrll *pp = p->next;
1897 1.1 skrll else
1898 1.1 skrll pp = &p->next;
1899 1.1.1.9 christos }
1900 1.1 skrll }
1901 1.1 skrll
1902 1.1 skrll /* Also discard relocs on undefined weak syms with non-default
1903 1.1.1.9 christos visibility. */
1904 1.1 skrll if (h->dyn_relocs != NULL
1905 1.1 skrll && h->root.type == bfd_link_hash_undefweak)
1906 1.1 skrll {
1907 1.1 skrll if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1908 1.1 skrll h->dyn_relocs = NULL;
1909 1.1 skrll
1910 1.1 skrll /* Make sure undefined weak symbols are output as a dynamic
1911 1.1.1.9 christos symbol in PIEs. */
1912 1.1 skrll else if (h->dynindx == -1
1913 1.1 skrll && !h->forced_local)
1914 1.1 skrll {
1915 1.1 skrll if (! bfd_elf_link_record_dynamic_symbol (info, h))
1916 1.1 skrll return false;
1917 1.1 skrll }
1918 1.1.1.6 christos }
1919 1.1.1.6 christos }
1920 1.1 skrll else
1921 1.1 skrll {
1922 1.1.1.6 christos /* For the non-shared case, discard space for relocs against
1923 1.1.1.6 christos symbols which turn out to need copy relocs or are not
1924 1.1.1.9 christos dynamic. */
1925 1.1.1.6 christos
1926 1.1.1.6 christos if (!h->non_got_ref
1927 1.1.1.6 christos && ((h->def_dynamic
1928 1.1.1.6 christos && !h->def_regular)
1929 1.1.1.6 christos || (htab->dynamic_sections_created
1930 1.1.1.6 christos && (h->root.type == bfd_link_hash_undefweak
1931 1.1.1.6 christos || h->root.type == bfd_link_hash_undefined))))
1932 1.1.1.6 christos {
1933 1.1.1.6 christos /* Make sure this symbol is output as a dynamic symbol.
1934 1.1.1.9 christos Undefined weak syms won't yet be marked as dynamic. */
1935 1.1.1.6 christos if (h->dynindx == -1
1936 1.1.1.6 christos && !h->forced_local)
1937 1.1.1.6 christos {
1938 1.1.1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
1939 1.1.1.6 christos return false;
1940 1.1.1.6 christos }
1941 1.1.1.6 christos
1942 1.1 skrll /* If that succeeded, we know we'll be keeping all the
1943 1.1.1.9 christos relocs. */
1944 1.1 skrll if (h->dynindx != -1)
1945 1.1 skrll goto keep;
1946 1.1 skrll }
1947 1.1 skrll
1948 1.1 skrll h->dyn_relocs = NULL;
1949 1.1.1.9 christos
1950 1.1 skrll keep: ;
1951 1.1 skrll }
1952 1.1 skrll
1953 1.1 skrll /* Finally, allocate space. */
1954 1.1 skrll for (p = h->dyn_relocs; p != NULL; p = p->next)
1955 1.1.1.9 christos {
1956 1.1 skrll asection *sreloc = elf_section_data (p->sec)->sreloc;
1957 1.1 skrll sreloc->size += p->count * sizeof (Elf32_External_Rela);
1958 1.1 skrll }
1959 1.1 skrll
1960 1.1.1.9 christos return true;
1961 1.1 skrll }
1962 1.1 skrll
1963 1.1 skrll /* Set the sizes of the dynamic sections. */
1964 1.1.1.9 christos
1965 1.1 skrll static bool
1966 1.1 skrll m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
1967 1.1.1.9 christos struct bfd_link_info *info)
1968 1.1 skrll {
1969 1.1 skrll struct elf_link_hash_table *htab;
1970 1.1 skrll bfd *dynobj;
1971 1.1 skrll asection *s;
1972 1.1 skrll bool relocs;
1973 1.1 skrll bfd *ibfd;
1974 1.1 skrll
1975 1.1.1.2 christos #ifdef DEBUG_PIC
1976 1.1.1.9 christos printf ("m32r_elf_size_dynamic_sections()\n");
1977 1.1.1.2 christos #endif
1978 1.1.1.9 christos
1979 1.1 skrll htab = m32r_elf_hash_table (info);
1980 1.1 skrll if (htab == NULL)
1981 1.1.1.9 christos return false;
1982 1.1 skrll
1983 1.1 skrll dynobj = htab->dynobj;
1984 1.1.1.4 christos BFD_ASSERT (dynobj != NULL);
1985 1.1 skrll
1986 1.1.1.3 christos if (htab->dynamic_sections_created)
1987 1.1 skrll {
1988 1.1 skrll /* Set the contents of the .interp section to the interpreter. */
1989 1.1 skrll if (bfd_link_executable (info) && !info->nointerp)
1990 1.1 skrll {
1991 1.1 skrll s = bfd_get_linker_section (dynobj, ".interp");
1992 1.1 skrll BFD_ASSERT (s != NULL);
1993 1.1 skrll s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1994 1.1 skrll s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1995 1.1.1.4 christos }
1996 1.1 skrll }
1997 1.1 skrll
1998 1.1 skrll /* Set up .got offsets for local syms, and space for local dynamic
1999 1.1 skrll relocs. */
2000 1.1 skrll for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2001 1.1 skrll {
2002 1.1 skrll bfd_signed_vma *local_got;
2003 1.1 skrll bfd_signed_vma *end_local_got;
2004 1.1.1.6 christos bfd_size_type locsymcount;
2005 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
2006 1.1 skrll asection *srel;
2007 1.1.1.6 christos
2008 1.1.1.6 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2009 1.1 skrll continue;
2010 1.1.1.6 christos
2011 1.1.1.6 christos for (s = ibfd->sections; s != NULL; s = s->next)
2012 1.1.1.6 christos {
2013 1.1.1.6 christos struct elf_dyn_relocs *p;
2014 1.1.1.6 christos
2015 1.1.1.6 christos for (p = ((struct elf_dyn_relocs *)
2016 1.1.1.6 christos elf_section_data (s)->local_dynrel);
2017 1.1.1.6 christos p != NULL;
2018 1.1.1.6 christos p = p->next)
2019 1.1.1.6 christos {
2020 1.1.1.6 christos if (! bfd_is_abs_section (p->sec)
2021 1.1.1.6 christos && bfd_is_abs_section (p->sec->output_section))
2022 1.1.1.6 christos {
2023 1.1.1.6 christos /* Input section has been discarded, either because
2024 1.1.1.6 christos it is a copy of a linkonce section or due to
2025 1.1.1.6 christos linker script /DISCARD/, so we'll be discarding
2026 1.1.1.6 christos the relocs too. */
2027 1.1.1.6 christos }
2028 1.1.1.6 christos else if (p->count != 0)
2029 1.1.1.6 christos {
2030 1.1.1.6 christos srel = elf_section_data (p->sec)->sreloc;
2031 1.1.1.6 christos srel->size += p->count * sizeof (Elf32_External_Rela);
2032 1.1 skrll if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2033 1.1 skrll info->flags |= DF_TEXTREL;
2034 1.1 skrll }
2035 1.1.1.6 christos }
2036 1.1 skrll }
2037 1.1 skrll
2038 1.1 skrll local_got = elf_local_got_refcounts (ibfd);
2039 1.1 skrll if (!local_got)
2040 1.1.1.9 christos continue;
2041 1.1.1.9 christos
2042 1.1 skrll symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2043 1.1.1.6 christos locsymcount = symtab_hdr->sh_info;
2044 1.1.1.6 christos end_local_got = local_got + locsymcount;
2045 1.1.1.6 christos s = htab->sgot;
2046 1.1.1.6 christos srel = htab->srelgot;
2047 1.1.1.6 christos for (; local_got < end_local_got; ++local_got)
2048 1.1.1.6 christos {
2049 1.1.1.6 christos if (*local_got > 0)
2050 1.1.1.6 christos {
2051 1.1.1.6 christos *local_got = s->size;
2052 1.1.1.6 christos s->size += 4;
2053 1.1.1.6 christos if (bfd_link_pic (info))
2054 1.1 skrll srel->size += sizeof (Elf32_External_Rela);
2055 1.1 skrll }
2056 1.1 skrll else
2057 1.1 skrll *local_got = (bfd_vma) -1;
2058 1.1.1.9 christos }
2059 1.1 skrll }
2060 1.1 skrll
2061 1.1 skrll /* Allocate global sym .plt and .got entries, and space for global
2062 1.1.1.9 christos sym dynamic relocs. */
2063 1.1 skrll elf_link_hash_traverse (htab, allocate_dynrelocs, info);
2064 1.1 skrll
2065 1.1 skrll /* We now have determined the sizes of the various dynamic sections.
2066 1.1.1.6 christos Allocate memory for them. */
2067 1.1 skrll relocs = false;
2068 1.1.1.9 christos for (s = dynobj->sections; s != NULL; s = s->next)
2069 1.1.1.9 christos {
2070 1.1.1.9 christos if ((s->flags & SEC_LINKER_CREATED) == 0)
2071 1.1 skrll continue;
2072 1.1.1.6 christos
2073 1.1.1.6 christos if (s == htab->splt
2074 1.1.1.6 christos || s == htab->sgot
2075 1.1.1.6 christos || s == htab->sgotplt
2076 1.1.1.9 christos || s == htab->sdynbss)
2077 1.1.1.6 christos {
2078 1.1.1.9 christos /* Strip this section if we don't need it; see the
2079 1.1.1.9 christos comment below. */
2080 1.1.1.6 christos }
2081 1.1.1.6 christos else if (startswith (bfd_section_name (s), ".rela"))
2082 1.1.1.6 christos {
2083 1.1.1.6 christos if (s->size != 0 && s != htab->srelplt)
2084 1.1.1.6 christos relocs = true;
2085 1.1 skrll
2086 1.1 skrll /* We use the reloc_count field as a counter if we need
2087 1.1 skrll to copy relocs into the output file. */
2088 1.1 skrll s->reloc_count = 0;
2089 1.1 skrll }
2090 1.1.1.6 christos else
2091 1.1.1.6 christos /* It's not one of our sections, so don't allocate space. */
2092 1.1.1.6 christos continue;
2093 1.1.1.6 christos
2094 1.1.1.6 christos if (s->size == 0)
2095 1.1.1.6 christos {
2096 1.1.1.6 christos /* If we don't need this section, strip it from the
2097 1.1.1.6 christos output file. This is mostly to handle .rela.bss and
2098 1.1.1.6 christos .rela.plt. We must create both sections in
2099 1.1.1.6 christos create_dynamic_sections, because they must be created
2100 1.1.1.6 christos before the linker maps input sections to output
2101 1.1.1.6 christos sections. The linker does that before
2102 1.1.1.6 christos adjust_dynamic_symbol is called, and it is that
2103 1.1 skrll function which decides whether anything needs to go
2104 1.1 skrll into these sections. */
2105 1.1 skrll s->flags |= SEC_EXCLUDE;
2106 1.1 skrll continue;
2107 1.1 skrll }
2108 1.1.1.6 christos
2109 1.1.1.6 christos if ((s->flags & SEC_HAS_CONTENTS) == 0)
2110 1.1.1.6 christos continue;
2111 1.1.1.6 christos
2112 1.1 skrll /* Allocate memory for the section contents. We use bfd_zalloc
2113 1.1 skrll here in case unused entries are not reclaimed before the
2114 1.1.1.9 christos section's contents are written out. This should not happen,
2115 1.1 skrll but this way if it does, we get a R_M32R_NONE reloc instead
2116 1.1 skrll of garbage. */
2117 1.1.1.9 christos s->contents = bfd_zalloc (dynobj, s->size);
2118 1.1 skrll if (s->contents == NULL)
2119 1.1 skrll return false;
2120 1.1 skrll }
2121 1.1 skrll
2122 1.1 skrll return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
2123 1.1 skrll }
2124 1.1 skrll
2125 1.1 skrll /* Relocate an M32R/D ELF section.
2126 1.1 skrll There is some attempt to make this function usable for many architectures,
2127 1.1 skrll both for RELA and REL type relocs, if only to serve as a learning tool.
2128 1.1 skrll
2129 1.1 skrll The RELOCATE_SECTION function is called by the new ELF backend linker
2130 1.1 skrll to handle the relocations for a section.
2131 1.1 skrll
2132 1.1 skrll The relocs are always passed as Rela structures; if the section
2133 1.1 skrll actually uses Rel structures, the r_addend field will always be
2134 1.1 skrll zero.
2135 1.1 skrll
2136 1.1 skrll This function is responsible for adjust the section contents as
2137 1.1 skrll necessary, and (if using Rela relocs and generating a
2138 1.1 skrll relocatable output file) adjusting the reloc addend as
2139 1.1 skrll necessary.
2140 1.1 skrll
2141 1.1 skrll This function does not have to worry about setting the reloc
2142 1.1 skrll address or the reloc symbol index.
2143 1.1 skrll
2144 1.1 skrll LOCAL_SYMS is a pointer to the swapped in local symbols.
2145 1.1 skrll
2146 1.1 skrll LOCAL_SECTIONS is an array giving the section in the input file
2147 1.1 skrll corresponding to the st_shndx field of each local symbol.
2148 1.1 skrll
2149 1.1 skrll The global hash table entry for the global symbols can be found
2150 1.1 skrll via elf_sym_hashes (input_bfd).
2151 1.1 skrll
2152 1.1 skrll When generating relocatable output, this function must handle
2153 1.1.1.9 christos STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2154 1.1 skrll going to be the section symbol corresponding to the output
2155 1.1 skrll section, which means that the addend must be adjusted
2156 1.1 skrll accordingly. */
2157 1.1 skrll
2158 1.1 skrll static int
2159 1.1 skrll m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
2160 1.1 skrll struct bfd_link_info *info,
2161 1.1 skrll bfd *input_bfd,
2162 1.1 skrll asection *input_section,
2163 1.1 skrll bfd_byte *contents,
2164 1.1 skrll Elf_Internal_Rela *relocs,
2165 1.1 skrll Elf_Internal_Sym *local_syms,
2166 1.1 skrll asection **local_sections)
2167 1.1.1.9 christos {
2168 1.1.1.9 christos Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2169 1.1 skrll struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2170 1.1 skrll Elf_Internal_Rela *rel, *relend;
2171 1.1 skrll /* Assume success. */
2172 1.1 skrll bool ret = true;
2173 1.1.1.2 christos struct elf_link_hash_table *htab = m32r_elf_hash_table (info);
2174 1.1.1.9 christos bfd_vma *local_got_offsets;
2175 1.1.1.2 christos asection *sgot, *splt, *sreloc;
2176 1.1 skrll bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
2177 1.1 skrll
2178 1.1.1.9 christos if (htab == NULL)
2179 1.1.1.9 christos return false;
2180 1.1 skrll
2181 1.1 skrll local_got_offsets = elf_local_got_offsets (input_bfd);
2182 1.1 skrll
2183 1.1 skrll sgot = htab->sgot;
2184 1.1 skrll splt = htab->splt;
2185 1.1 skrll sreloc = NULL;
2186 1.1 skrll
2187 1.1 skrll rel = relocs;
2188 1.1 skrll relend = relocs + input_section->reloc_count;
2189 1.1 skrll for (; rel < relend; rel++)
2190 1.1 skrll {
2191 1.1.1.6 christos int r_type;
2192 1.1.1.6 christos reloc_howto_type *howto;
2193 1.1.1.6 christos unsigned long r_symndx;
2194 1.1 skrll struct elf_link_hash_entry *h;
2195 1.1 skrll /* We can't modify r_addend here as elf_link_input_bfd has an assert to
2196 1.1 skrll ensure it's zero (we use REL relocs, not RELA). Therefore this
2197 1.1 skrll should be assigning zero to `addend', but for clarity we use
2198 1.1 skrll `r_addend'. */
2199 1.1 skrll bfd_vma addend = rel->r_addend;
2200 1.1 skrll bfd_vma offset = rel->r_offset;
2201 1.1 skrll bfd_vma relocation;
2202 1.1.1.9 christos Elf_Internal_Sym *sym;
2203 1.1 skrll asection *sec;
2204 1.1 skrll const char *sym_name;
2205 1.1 skrll bfd_reloc_status_type r;
2206 1.1 skrll const char *errmsg = NULL;
2207 1.1 skrll bool use_rel = false;
2208 1.1.1.6 christos
2209 1.1.1.7 christos h = NULL;
2210 1.1.1.6 christos r_type = ELF32_R_TYPE (rel->r_info);
2211 1.1 skrll if (r_type < 0 || r_type >= (int) R_M32R_max)
2212 1.1.1.9 christos {
2213 1.1 skrll /* xgettext:c-format */
2214 1.1 skrll _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2215 1.1 skrll input_bfd, (int) r_type);
2216 1.1 skrll bfd_set_error (bfd_error_bad_value);
2217 1.1.1.6 christos ret = false;
2218 1.1.1.6 christos continue;
2219 1.1.1.6 christos }
2220 1.1.1.6 christos
2221 1.1.1.6 christos if ( r_type == R_M32R_GNU_VTENTRY
2222 1.1 skrll || r_type == R_M32R_GNU_VTINHERIT
2223 1.1 skrll || r_type == R_M32R_NONE
2224 1.1.1.9 christos || r_type == R_M32R_RELA_GNU_VTENTRY
2225 1.1 skrll || r_type == R_M32R_RELA_GNU_VTINHERIT)
2226 1.1 skrll continue;
2227 1.1 skrll
2228 1.1 skrll if (r_type <= R_M32R_GNU_VTENTRY)
2229 1.1 skrll use_rel = true;
2230 1.1 skrll
2231 1.1 skrll howto = m32r_elf_howto_table + r_type;
2232 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
2233 1.1 skrll
2234 1.1 skrll sym = NULL;
2235 1.1 skrll sec = NULL;
2236 1.1 skrll h = NULL;
2237 1.1 skrll
2238 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
2239 1.1 skrll {
2240 1.1 skrll /* Local symbol. */
2241 1.1 skrll sym = local_syms + r_symndx;
2242 1.1 skrll sec = local_sections[r_symndx];
2243 1.1 skrll sym_name = "<local symbol>";
2244 1.1 skrll
2245 1.1 skrll if (!use_rel)
2246 1.1 skrll {
2247 1.1 skrll relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2248 1.1 skrll addend = rel->r_addend;
2249 1.1 skrll }
2250 1.1 skrll else
2251 1.1 skrll {
2252 1.1 skrll relocation = (sec->output_section->vma
2253 1.1 skrll + sec->output_offset
2254 1.1 skrll + sym->st_value);
2255 1.1 skrll }
2256 1.1 skrll }
2257 1.1 skrll else
2258 1.1.1.4 christos {
2259 1.1.1.4 christos /* External symbol. */
2260 1.1.1.4 christos relocation = 0;
2261 1.1.1.4 christos
2262 1.1.1.4 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2263 1.1.1.4 christos
2264 1.1 skrll if (info->wrap_hash != NULL
2265 1.1 skrll && (input_section->flags & SEC_DEBUGGING) != 0)
2266 1.1 skrll h = ((struct elf_link_hash_entry *)
2267 1.1 skrll unwrap_hash_lookup (info, input_bfd, &h->root));
2268 1.1 skrll
2269 1.1 skrll while (h->root.type == bfd_link_hash_indirect
2270 1.1 skrll || h->root.type == bfd_link_hash_warning)
2271 1.1 skrll h = (struct elf_link_hash_entry *) h->root.u.i.link;
2272 1.1.1.9 christos sym_name = h->root.root.string;
2273 1.1 skrll
2274 1.1 skrll if (h->root.type == bfd_link_hash_defined
2275 1.1.1.9 christos || h->root.type == bfd_link_hash_defweak)
2276 1.1 skrll {
2277 1.1 skrll bool dyn;
2278 1.1 skrll sec = h->root.u.def.section;
2279 1.1 skrll
2280 1.1 skrll dyn = htab->dynamic_sections_created;
2281 1.1 skrll sec = h->root.u.def.section;
2282 1.1 skrll if (r_type == R_M32R_GOTPC24
2283 1.1 skrll || (r_type == R_M32R_GOTPC_HI_ULO
2284 1.1 skrll || r_type == R_M32R_GOTPC_HI_SLO
2285 1.1 skrll || r_type == R_M32R_GOTPC_LO)
2286 1.1 skrll || (r_type == R_M32R_26_PLTREL
2287 1.1 skrll && h->plt.offset != (bfd_vma) -1)
2288 1.1.1.4 christos || ((r_type == R_M32R_GOT24
2289 1.1.1.4 christos || r_type == R_M32R_GOT16_HI_ULO
2290 1.1.1.4 christos || r_type == R_M32R_GOT16_HI_SLO
2291 1.1 skrll || r_type == R_M32R_GOT16_LO)
2292 1.1 skrll && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2293 1.1.1.4 christos bfd_link_pic (info),
2294 1.1 skrll h)
2295 1.1 skrll && (! bfd_link_pic (info)
2296 1.1 skrll || (! info->symbolic && h->dynindx != -1)
2297 1.1 skrll || !h->def_regular))
2298 1.1 skrll || (bfd_link_pic (info)
2299 1.1 skrll && ((! info->symbolic && h->dynindx != -1)
2300 1.1 skrll || !h->def_regular)
2301 1.1 skrll && (((r_type == R_M32R_16_RELA
2302 1.1 skrll || r_type == R_M32R_32_RELA
2303 1.1 skrll || r_type == R_M32R_24_RELA
2304 1.1 skrll || r_type == R_M32R_HI16_ULO_RELA
2305 1.1 skrll || r_type == R_M32R_HI16_SLO_RELA
2306 1.1 skrll || r_type == R_M32R_LO16_RELA)
2307 1.1 skrll && !h->forced_local)
2308 1.1 skrll || r_type == R_M32R_REL32
2309 1.1 skrll || r_type == R_M32R_10_PCREL_RELA
2310 1.1 skrll || r_type == R_M32R_18_PCREL_RELA
2311 1.1 skrll || r_type == R_M32R_26_PCREL_RELA)
2312 1.1 skrll && ((input_section->flags & SEC_ALLOC) != 0
2313 1.1 skrll /* DWARF will emit R_M32R_16(24,32) relocations
2314 1.1 skrll in its sections against symbols defined
2315 1.1 skrll externally in shared libraries. We can't do
2316 1.1 skrll anything with them here. */
2317 1.1 skrll || ((input_section->flags & SEC_DEBUGGING) != 0
2318 1.1 skrll && h->def_dynamic))))
2319 1.1 skrll {
2320 1.1 skrll /* In these cases, we don't need the relocation
2321 1.1 skrll value. We check specially because in some
2322 1.1 skrll obscure cases sec->output_section will be NULL. */
2323 1.1.1.4 christos }
2324 1.1.1.3 christos else if (sec->output_section != NULL)
2325 1.1.1.3 christos relocation = (h->root.u.def.value
2326 1.1.1.3 christos + sec->output_section->vma
2327 1.1.1.3 christos + sec->output_offset);
2328 1.1 skrll else if (!bfd_link_relocatable (info)
2329 1.1.1.6 christos && (_bfd_elf_section_offset (output_bfd, info,
2330 1.1.1.6 christos input_section,
2331 1.1.1.7 christos rel->r_offset)
2332 1.1.1.6 christos != (bfd_vma) -1))
2333 1.1 skrll {
2334 1.1 skrll _bfd_error_handler
2335 1.1.1.7 christos /* xgettext:c-format */
2336 1.1 skrll (_("%pB(%pA+%#" PRIx64 "): unresolvable %s relocation "
2337 1.1 skrll "against symbol `%s'"),
2338 1.1 skrll input_bfd,
2339 1.1 skrll input_section,
2340 1.1 skrll (uint64_t) rel->r_offset,
2341 1.1 skrll howto->name,
2342 1.1 skrll h->root.root.string);
2343 1.1 skrll }
2344 1.1 skrll }
2345 1.1.1.4 christos else if (h->root.type == bfd_link_hash_undefweak)
2346 1.1.1.9 christos ;
2347 1.1.1.9 christos else if (info->unresolved_syms_in_objects == RM_IGNORE
2348 1.1.1.9 christos && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
2349 1.1.1.9 christos ;
2350 1.1.1.9 christos else if (!bfd_link_relocatable (info))
2351 1.1.1.9 christos info->callbacks->undefined_symbol
2352 1.1 skrll (info, h->root.root.string, input_bfd, input_section, offset,
2353 1.1.1.3 christos (info->unresolved_syms_in_objects == RM_DIAGNOSE
2354 1.1.1.2 christos && !info->warn_unresolved_syms)
2355 1.1.1.3 christos || ELF_ST_VISIBILITY (h->other));
2356 1.1 skrll }
2357 1.1.1.4 christos
2358 1.1 skrll if (sec != NULL && discarded_section (sec))
2359 1.1 skrll RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2360 1.1 skrll rel, 1, relend, howto, 0, contents);
2361 1.1 skrll
2362 1.1 skrll if (bfd_link_relocatable (info) && !use_rel)
2363 1.1 skrll {
2364 1.1 skrll /* This is a relocatable link. We don't have to change
2365 1.1 skrll anything, unless the reloc is against a section symbol,
2366 1.1 skrll in which case we have to adjust according to where the
2367 1.1 skrll section symbol winds up in the output section. */
2368 1.1.1.4 christos if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2369 1.1 skrll rel->r_addend += sec->output_offset;
2370 1.1 skrll continue;
2371 1.1 skrll }
2372 1.1 skrll
2373 1.1 skrll if (bfd_link_relocatable (info) && use_rel)
2374 1.1 skrll {
2375 1.1 skrll /* This is a relocatable link. We don't have to change
2376 1.1 skrll anything, unless the reloc is against a section symbol,
2377 1.1 skrll in which case we have to adjust according to where the
2378 1.1 skrll section symbol winds up in the output section. */
2379 1.1 skrll if (sym == NULL || ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2380 1.1 skrll continue;
2381 1.1 skrll
2382 1.1 skrll addend += sec->output_offset;
2383 1.1 skrll
2384 1.1 skrll /* If partial_inplace, we need to store any additional addend
2385 1.1 skrll back in the section. */
2386 1.1 skrll if (! howto->partial_inplace)
2387 1.1 skrll continue;
2388 1.1 skrll /* ??? Here is a nice place to call a special_function
2389 1.1 skrll like handler. */
2390 1.1 skrll if (r_type != R_M32R_HI16_SLO && r_type != R_M32R_HI16_ULO)
2391 1.1 skrll r = _bfd_relocate_contents (howto, input_bfd,
2392 1.1 skrll addend, contents + offset);
2393 1.1 skrll else
2394 1.1 skrll {
2395 1.1 skrll Elf_Internal_Rela *lorel;
2396 1.1 skrll
2397 1.1 skrll /* We allow an arbitrary number of HI16 relocs before the
2398 1.1 skrll LO16 reloc. This permits gcc to emit the HI and LO relocs
2399 1.1 skrll itself. */
2400 1.1 skrll for (lorel = rel + 1;
2401 1.1 skrll (lorel < relend
2402 1.1 skrll && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
2403 1.1 skrll || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
2404 1.1 skrll lorel++)
2405 1.1 skrll continue;
2406 1.1 skrll if (lorel < relend
2407 1.1 skrll && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
2408 1.1 skrll {
2409 1.1 skrll m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
2410 1.1 skrll contents, addend);
2411 1.1 skrll r = bfd_reloc_ok;
2412 1.1 skrll }
2413 1.1 skrll else
2414 1.1 skrll r = _bfd_relocate_contents (howto, input_bfd,
2415 1.1 skrll addend, contents + offset);
2416 1.1 skrll }
2417 1.1 skrll }
2418 1.1 skrll else
2419 1.1 skrll {
2420 1.1 skrll /* Sanity check the address. */
2421 1.1 skrll if (offset > high_address)
2422 1.1 skrll {
2423 1.1 skrll r = bfd_reloc_outofrange;
2424 1.1.1.6 christos goto check_reloc;
2425 1.1.1.6 christos }
2426 1.1.1.6 christos
2427 1.1.1.6 christos switch ((int) r_type)
2428 1.1.1.6 christos {
2429 1.1.1.6 christos case R_M32R_GOTOFF:
2430 1.1.1.6 christos /* Relocation is relative to the start of the global offset
2431 1.1.1.6 christos table (for ld24 rx, #uimm24). eg access at label+addend
2432 1.1.1.6 christos
2433 1.1.1.6 christos ld24 rx. #label@GOTOFF + addend
2434 1.1.1.6 christos sub rx, r12. */
2435 1.1.1.6 christos
2436 1.1.1.6 christos BFD_ASSERT (sgot != NULL);
2437 1.1.1.6 christos
2438 1.1.1.6 christos relocation = -(relocation - sgot->output_section->vma);
2439 1.1.1.6 christos rel->r_addend = -rel->r_addend;
2440 1.1 skrll break;
2441 1.1 skrll
2442 1.1 skrll case R_M32R_GOTOFF_HI_ULO:
2443 1.1 skrll case R_M32R_GOTOFF_HI_SLO:
2444 1.1 skrll case R_M32R_GOTOFF_LO:
2445 1.1 skrll BFD_ASSERT (sgot != NULL);
2446 1.1 skrll
2447 1.1 skrll relocation -= sgot->output_section->vma;
2448 1.1 skrll
2449 1.1.1.6 christos if ((r_type == R_M32R_GOTOFF_HI_SLO)
2450 1.1.1.6 christos && ((relocation + rel->r_addend) & 0x8000))
2451 1.1.1.6 christos rel->r_addend += 0x10000;
2452 1.1.1.6 christos break;
2453 1.1.1.6 christos
2454 1.1.1.6 christos case R_M32R_GOTPC24:
2455 1.1.1.6 christos /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2456 1.1.1.6 christos ld24 rx,#_GLOBAL_OFFSET_TABLE_
2457 1.1.1.6 christos */
2458 1.1.1.6 christos relocation = sgot->output_section->vma;
2459 1.1.1.6 christos break;
2460 1.1.1.6 christos
2461 1.1.1.6 christos case R_M32R_GOTPC_HI_ULO:
2462 1.1.1.6 christos case R_M32R_GOTPC_HI_SLO:
2463 1.1.1.6 christos case R_M32R_GOTPC_LO:
2464 1.1.1.6 christos {
2465 1.1.1.6 christos /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2466 1.1.1.6 christos bl .+4
2467 1.1.1.6 christos seth rx,#high(_GLOBAL_OFFSET_TABLE_)
2468 1.1.1.6 christos or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2469 1.1.1.6 christos or
2470 1.1.1.6 christos bl .+4
2471 1.1.1.6 christos seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
2472 1.1.1.6 christos add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2473 1.1.1.6 christos */
2474 1.1.1.6 christos relocation = sgot->output_section->vma;
2475 1.1.1.6 christos relocation -= (input_section->output_section->vma
2476 1.1.1.6 christos + input_section->output_offset
2477 1.1.1.6 christos + rel->r_offset);
2478 1.1.1.6 christos if ((r_type == R_M32R_GOTPC_HI_SLO)
2479 1.1.1.6 christos && ((relocation + rel->r_addend) & 0x8000))
2480 1.1.1.6 christos rel->r_addend += 0x10000;
2481 1.1.1.6 christos
2482 1.1.1.6 christos break;
2483 1.1.1.6 christos }
2484 1.1.1.6 christos case R_M32R_GOT16_HI_ULO:
2485 1.1.1.6 christos case R_M32R_GOT16_HI_SLO:
2486 1.1.1.6 christos case R_M32R_GOT16_LO:
2487 1.1.1.6 christos /* Fall through. */
2488 1.1.1.6 christos case R_M32R_GOT24:
2489 1.1.1.6 christos /* Relocation is to the entry for this symbol in the global
2490 1.1.1.9 christos offset table. */
2491 1.1.1.6 christos BFD_ASSERT (sgot != NULL);
2492 1.1 skrll
2493 1.1.1.6 christos if (h != NULL)
2494 1.1.1.6 christos {
2495 1.1 skrll bool dyn;
2496 1.1.1.9 christos bfd_vma off;
2497 1.1.1.6 christos
2498 1.1.1.4 christos off = h->got.offset;
2499 1.1.1.4 christos BFD_ASSERT (off != (bfd_vma) -1);
2500 1.1.1.6 christos
2501 1.1.1.6 christos dyn = htab->dynamic_sections_created;
2502 1.1.1.6 christos if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2503 1.1.1.6 christos bfd_link_pic (info),
2504 1.1.1.6 christos h)
2505 1.1.1.6 christos || (bfd_link_pic (info)
2506 1.1.1.6 christos && (info->symbolic
2507 1.1.1.6 christos || h->dynindx == -1
2508 1.1.1.6 christos || h->forced_local)
2509 1.1.1.6 christos && h->def_regular))
2510 1.1.1.6 christos {
2511 1.1.1.6 christos /* This is actually a static link, or it is a
2512 1.1.1.6 christos -Bsymbolic link and the symbol is defined
2513 1.1.1.6 christos locally, or the symbol was forced to be local
2514 1.1.1.6 christos because of a version file. We must initialize
2515 1.1.1.6 christos this entry in the global offset table. Since the
2516 1.1.1.6 christos offset must always be a multiple of 4, we use the
2517 1.1.1.6 christos least significant bit to record whether we have
2518 1.1.1.6 christos initialized it already.
2519 1.1.1.6 christos
2520 1.1.1.6 christos When doing a dynamic link, we create a .rela.got
2521 1.1.1.6 christos relocation entry to initialize the value. This
2522 1.1.1.6 christos is done in the finish_dynamic_symbol routine. */
2523 1.1.1.6 christos if ((off & 1) != 0)
2524 1.1.1.6 christos off &= ~1;
2525 1.1.1.6 christos else
2526 1.1.1.6 christos {
2527 1.1.1.6 christos bfd_put_32 (output_bfd, relocation,
2528 1.1.1.6 christos sgot->contents + off);
2529 1.1.1.6 christos h->got.offset |= 1;
2530 1.1.1.6 christos }
2531 1.1.1.6 christos }
2532 1.1.1.6 christos
2533 1.1.1.6 christos relocation = sgot->output_offset + off;
2534 1.1.1.6 christos }
2535 1.1.1.6 christos else
2536 1.1.1.6 christos {
2537 1.1.1.6 christos bfd_vma off;
2538 1.1.1.6 christos bfd_byte *loc;
2539 1.1.1.6 christos
2540 1.1.1.6 christos BFD_ASSERT (local_got_offsets != NULL
2541 1.1.1.6 christos && local_got_offsets[r_symndx] != (bfd_vma) -1);
2542 1.1.1.6 christos
2543 1.1.1.6 christos off = local_got_offsets[r_symndx];
2544 1.1.1.6 christos
2545 1.1.1.6 christos /* The offset must always be a multiple of 4. We use
2546 1.1.1.6 christos the least significant bit to record whether we have
2547 1.1.1.6 christos already processed this entry. */
2548 1.1.1.6 christos if ((off & 1) != 0)
2549 1.1.1.6 christos off &= ~1;
2550 1.1.1.6 christos else
2551 1.1.1.6 christos {
2552 1.1.1.6 christos bfd_put_32 (output_bfd, relocation, sgot->contents + off);
2553 1.1.1.6 christos
2554 1.1.1.6 christos if (bfd_link_pic (info))
2555 1.1.1.6 christos {
2556 1.1.1.9 christos asection *srelgot;
2557 1.1.1.6 christos Elf_Internal_Rela outrel;
2558 1.1.1.6 christos
2559 1.1.1.6 christos /* We need to generate a R_M32R_RELATIVE reloc
2560 1.1.1.6 christos for the dynamic linker. */
2561 1.1.1.6 christos srelgot = htab->srelgot;
2562 1.1.1.6 christos BFD_ASSERT (srelgot != NULL);
2563 1.1.1.6 christos
2564 1.1.1.6 christos outrel.r_offset = (sgot->output_section->vma
2565 1.1.1.6 christos + sgot->output_offset
2566 1.1.1.6 christos + off);
2567 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
2568 1.1.1.6 christos outrel.r_addend = relocation;
2569 1.1.1.6 christos loc = srelgot->contents;
2570 1.1.1.6 christos loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
2571 1.1.1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
2572 1.1.1.6 christos ++srelgot->reloc_count;
2573 1.1.1.6 christos }
2574 1.1.1.6 christos
2575 1.1.1.6 christos local_got_offsets[r_symndx] |= 1;
2576 1.1.1.6 christos }
2577 1.1.1.6 christos
2578 1.1.1.6 christos relocation = sgot->output_offset + off;
2579 1.1.1.6 christos }
2580 1.1 skrll if ((r_type == R_M32R_GOT16_HI_SLO)
2581 1.1.1.6 christos && ((relocation + rel->r_addend) & 0x8000))
2582 1.1.1.6 christos rel->r_addend += 0x10000;
2583 1.1.1.6 christos
2584 1.1.1.6 christos break;
2585 1.1.1.6 christos
2586 1.1.1.6 christos case R_M32R_26_PLTREL:
2587 1.1.1.6 christos /* Relocation is to the entry for this symbol in the
2588 1.1.1.6 christos procedure linkage table. */
2589 1.1.1.6 christos
2590 1.1 skrll /* The native assembler will generate a 26_PLTREL reloc
2591 1.1.1.6 christos for a local symbol if you assemble a call from one
2592 1.1.1.6 christos section to another when using -K pic. */
2593 1.1.1.6 christos if (h == NULL)
2594 1.1.1.6 christos break;
2595 1.1 skrll
2596 1.1 skrll if (h->forced_local)
2597 1.1 skrll break;
2598 1.1 skrll
2599 1.1 skrll if (h->plt.offset == (bfd_vma) -1)
2600 1.1.1.6 christos /* We didn't make a PLT entry for this symbol. This
2601 1.1.1.6 christos happens when statically linking PIC code, or when
2602 1.1.1.6 christos using -Bsymbolic. */
2603 1.1.1.6 christos break;
2604 1.1 skrll
2605 1.1.1.6 christos relocation = (splt->output_section->vma
2606 1.1 skrll + splt->output_offset
2607 1.1 skrll + h->plt.offset);
2608 1.1.1.6 christos break;
2609 1.1 skrll
2610 1.1.1.6 christos case R_M32R_HI16_SLO_RELA:
2611 1.1.1.6 christos if ((relocation + rel->r_addend) & 0x8000)
2612 1.1.1.6 christos rel->r_addend += 0x10000;
2613 1.1.1.6 christos /* Fall through. */
2614 1.1 skrll
2615 1.1.1.6 christos case R_M32R_16_RELA:
2616 1.1.1.6 christos case R_M32R_24_RELA:
2617 1.1.1.6 christos case R_M32R_32_RELA:
2618 1.1.1.6 christos case R_M32R_REL32:
2619 1.1.1.6 christos case R_M32R_10_PCREL_RELA:
2620 1.1.1.6 christos case R_M32R_18_PCREL_RELA:
2621 1.1.1.6 christos case R_M32R_26_PCREL_RELA:
2622 1.1.1.6 christos case R_M32R_HI16_ULO_RELA:
2623 1.1.1.6 christos case R_M32R_LO16_RELA:
2624 1.1.1.6 christos if (bfd_link_pic (info)
2625 1.1.1.6 christos && r_symndx != STN_UNDEF
2626 1.1.1.6 christos && (input_section->flags & SEC_ALLOC) != 0
2627 1.1.1.6 christos && (( r_type != R_M32R_10_PCREL_RELA
2628 1.1.1.6 christos && r_type != R_M32R_18_PCREL_RELA
2629 1.1.1.6 christos && r_type != R_M32R_26_PCREL_RELA
2630 1.1.1.6 christos && r_type != R_M32R_REL32)
2631 1.1.1.6 christos || (h != NULL
2632 1.1.1.9 christos && h->dynindx != -1
2633 1.1.1.6 christos && (! info->symbolic
2634 1.1.1.6 christos || !h->def_regular))))
2635 1.1.1.6 christos {
2636 1.1.1.6 christos Elf_Internal_Rela outrel;
2637 1.1.1.6 christos bool skip, relocate;
2638 1.1.1.6 christos bfd_byte *loc;
2639 1.1.1.6 christos
2640 1.1.1.2 christos /* When generating a shared object, these relocations
2641 1.1.1.9 christos are copied into the output file to be resolved at run
2642 1.1.1.2 christos time. */
2643 1.1.1.9 christos if (sreloc == NULL)
2644 1.1.1.6 christos {
2645 1.1 skrll sreloc = _bfd_elf_get_dynamic_reloc_section
2646 1.1.1.9 christos (input_bfd, input_section, /*rela?*/ true);
2647 1.1.1.9 christos if (sreloc == NULL)
2648 1.1 skrll return false;
2649 1.1.1.6 christos }
2650 1.1.1.6 christos
2651 1.1.1.6 christos skip = false;
2652 1.1.1.6 christos relocate = false;
2653 1.1.1.6 christos
2654 1.1.1.9 christos outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2655 1.1.1.6 christos info,
2656 1.1.1.9 christos input_section,
2657 1.1.1.6 christos rel->r_offset);
2658 1.1.1.6 christos if (outrel.r_offset == (bfd_vma) -1)
2659 1.1.1.6 christos skip = true;
2660 1.1.1.6 christos else if (outrel.r_offset == (bfd_vma) -2)
2661 1.1.1.6 christos skip = relocate = true;
2662 1.1.1.6 christos outrel.r_offset += (input_section->output_section->vma
2663 1.1.1.6 christos + input_section->output_offset);
2664 1.1.1.6 christos
2665 1.1.1.6 christos if (skip)
2666 1.1.1.6 christos memset (&outrel, 0, sizeof outrel);
2667 1.1.1.6 christos else if ( r_type == R_M32R_10_PCREL_RELA
2668 1.1.1.6 christos || r_type == R_M32R_18_PCREL_RELA
2669 1.1.1.6 christos || r_type == R_M32R_26_PCREL_RELA
2670 1.1.1.6 christos || r_type == R_M32R_REL32)
2671 1.1.1.6 christos {
2672 1.1.1.6 christos BFD_ASSERT (h != NULL && h->dynindx != -1);
2673 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2674 1.1.1.6 christos outrel.r_addend = rel->r_addend;
2675 1.1.1.6 christos }
2676 1.1.1.6 christos else
2677 1.1.1.6 christos {
2678 1.1.1.6 christos /* h->dynindx may be -1 if this symbol was marked to
2679 1.1.1.9 christos become local. */
2680 1.1.1.6 christos if (h == NULL
2681 1.1.1.6 christos || ((info->symbolic || h->dynindx == -1)
2682 1.1.1.6 christos && h->def_regular))
2683 1.1.1.6 christos {
2684 1.1.1.6 christos relocate = true;
2685 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
2686 1.1.1.6 christos outrel.r_addend = relocation + rel->r_addend;
2687 1.1.1.6 christos }
2688 1.1.1.6 christos else
2689 1.1.1.6 christos {
2690 1.1.1.6 christos BFD_ASSERT (h->dynindx != -1);
2691 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2692 1.1.1.6 christos outrel.r_addend = relocation + rel->r_addend;
2693 1.1.1.6 christos }
2694 1.1.1.6 christos }
2695 1.1.1.6 christos
2696 1.1.1.6 christos loc = sreloc->contents;
2697 1.1.1.6 christos loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
2698 1.1.1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
2699 1.1.1.6 christos ++sreloc->reloc_count;
2700 1.1.1.6 christos
2701 1.1.1.6 christos /* If this reloc is against an external symbol, we do
2702 1.1 skrll not want to fiddle with the addend. Otherwise, we
2703 1.1.1.6 christos need to include the symbol value so that it becomes
2704 1.1 skrll an addend for the dynamic reloc. */
2705 1.1 skrll if (! relocate)
2706 1.1 skrll continue;
2707 1.1 skrll break;
2708 1.1 skrll }
2709 1.1 skrll else if (r_type != R_M32R_10_PCREL_RELA)
2710 1.1 skrll break;
2711 1.1 skrll /* Fall through. */
2712 1.1.1.6 christos
2713 1.1 skrll case (int) R_M32R_10_PCREL :
2714 1.1 skrll r = m32r_elf_do_10_pcrel_reloc (input_bfd, howto, input_section,
2715 1.1 skrll contents, offset,
2716 1.1 skrll sec, relocation, addend);
2717 1.1 skrll goto check_reloc;
2718 1.1 skrll
2719 1.1 skrll case (int) R_M32R_HI16_SLO :
2720 1.1 skrll case (int) R_M32R_HI16_ULO :
2721 1.1 skrll {
2722 1.1 skrll Elf_Internal_Rela *lorel;
2723 1.1 skrll
2724 1.1 skrll /* We allow an arbitrary number of HI16 relocs before the
2725 1.1 skrll LO16 reloc. This permits gcc to emit the HI and LO relocs
2726 1.1 skrll itself. */
2727 1.1 skrll for (lorel = rel + 1;
2728 1.1 skrll (lorel < relend
2729 1.1 skrll && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
2730 1.1 skrll || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
2731 1.1 skrll lorel++)
2732 1.1 skrll continue;
2733 1.1 skrll if (lorel < relend
2734 1.1 skrll && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
2735 1.1 skrll {
2736 1.1 skrll m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
2737 1.1 skrll contents, relocation + addend);
2738 1.1 skrll r = bfd_reloc_ok;
2739 1.1 skrll }
2740 1.1 skrll else
2741 1.1.1.6 christos r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2742 1.1 skrll contents, offset,
2743 1.1.1.6 christos relocation, addend);
2744 1.1 skrll }
2745 1.1 skrll
2746 1.1 skrll goto check_reloc;
2747 1.1 skrll
2748 1.1 skrll case (int) R_M32R_SDA16_RELA:
2749 1.1.1.8 christos case (int) R_M32R_SDA16 :
2750 1.1 skrll {
2751 1.1 skrll const char *name;
2752 1.1 skrll
2753 1.1 skrll BFD_ASSERT (sec != NULL);
2754 1.1 skrll name = bfd_section_name (sec);
2755 1.1 skrll
2756 1.1 skrll if ( strcmp (name, ".sdata") == 0
2757 1.1 skrll || strcmp (name, ".sbss") == 0
2758 1.1 skrll || strcmp (name, ".scommon") == 0)
2759 1.1 skrll {
2760 1.1 skrll bfd_vma sda_base;
2761 1.1 skrll bfd *out_bfd = sec->output_section->owner;
2762 1.1 skrll
2763 1.1.1.9 christos r = m32r_elf_final_sda_base (out_bfd, info,
2764 1.1 skrll &errmsg,
2765 1.1 skrll &sda_base);
2766 1.1 skrll if (r != bfd_reloc_ok)
2767 1.1 skrll {
2768 1.1 skrll ret = false;
2769 1.1 skrll goto check_reloc;
2770 1.1 skrll }
2771 1.1 skrll
2772 1.1 skrll /* At this point `relocation' contains the object's
2773 1.1 skrll address. */
2774 1.1.1.6 christos relocation -= sda_base;
2775 1.1.1.6 christos /* Now it contains the offset from _SDA_BASE_. */
2776 1.1.1.7 christos }
2777 1.1.1.7 christos else
2778 1.1 skrll {
2779 1.1 skrll _bfd_error_handler
2780 1.1.1.6 christos /* xgettext:c-format */
2781 1.1.1.6 christos (_("%pB: the target (%s) of an %s relocation"
2782 1.1 skrll " is in the wrong section (%pA)"),
2783 1.1.1.9 christos input_bfd,
2784 1.1 skrll sym_name,
2785 1.1 skrll m32r_elf_howto_table[(int) r_type].name,
2786 1.1 skrll sec);
2787 1.1.1.6 christos /*bfd_set_error (bfd_error_bad_value); ??? why? */
2788 1.1 skrll ret = false;
2789 1.1 skrll continue;
2790 1.1 skrll }
2791 1.1 skrll }
2792 1.1 skrll /* Fall through. */
2793 1.1 skrll
2794 1.1 skrll default : /* OLD_M32R_RELOC */
2795 1.1 skrll
2796 1.1 skrll r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2797 1.1.1.6 christos contents, offset,
2798 1.1.1.6 christos relocation, addend);
2799 1.1.1.6 christos goto check_reloc;
2800 1.1 skrll }
2801 1.1 skrll
2802 1.1 skrll r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2803 1.1 skrll contents, rel->r_offset,
2804 1.1 skrll relocation, rel->r_addend);
2805 1.1 skrll
2806 1.1 skrll }
2807 1.1 skrll
2808 1.1 skrll check_reloc:
2809 1.1 skrll
2810 1.1 skrll if (r != bfd_reloc_ok)
2811 1.1 skrll {
2812 1.1 skrll /* FIXME: This should be generic enough to go in a utility. */
2813 1.1 skrll const char *name;
2814 1.1 skrll
2815 1.1 skrll if (h != NULL)
2816 1.1 skrll name = h->root.root.string;
2817 1.1.1.8 christos else
2818 1.1 skrll {
2819 1.1 skrll name = (bfd_elf_string_from_elf_section
2820 1.1 skrll (input_bfd, symtab_hdr->sh_link, sym->st_name));
2821 1.1 skrll if (name == NULL || *name == '\0')
2822 1.1 skrll name = bfd_section_name (sec);
2823 1.1 skrll }
2824 1.1 skrll
2825 1.1 skrll if (errmsg != NULL)
2826 1.1.1.5 christos goto common_error;
2827 1.1.1.5 christos
2828 1.1.1.5 christos switch (r)
2829 1.1 skrll {
2830 1.1 skrll case bfd_reloc_overflow:
2831 1.1 skrll (*info->callbacks->reloc_overflow)
2832 1.1.1.5 christos (info, (h ? &h->root : NULL), name, howto->name,
2833 1.1.1.9 christos (bfd_vma) 0, input_bfd, input_section, offset);
2834 1.1 skrll break;
2835 1.1 skrll
2836 1.1 skrll case bfd_reloc_undefined:
2837 1.1 skrll (*info->callbacks->undefined_symbol)
2838 1.1 skrll (info, name, input_bfd, input_section, offset, true);
2839 1.1 skrll break;
2840 1.1 skrll
2841 1.1 skrll case bfd_reloc_outofrange:
2842 1.1 skrll errmsg = _("internal error: out of range error");
2843 1.1 skrll goto common_error;
2844 1.1 skrll
2845 1.1 skrll case bfd_reloc_notsupported:
2846 1.1 skrll errmsg = _("internal error: unsupported relocation error");
2847 1.1 skrll goto common_error;
2848 1.1 skrll
2849 1.1 skrll case bfd_reloc_dangerous:
2850 1.1 skrll errmsg = _("internal error: dangerous error");
2851 1.1 skrll goto common_error;
2852 1.1 skrll
2853 1.1.1.5 christos default:
2854 1.1.1.5 christos errmsg = _("internal error: unknown error");
2855 1.1 skrll /* fall through */
2856 1.1 skrll
2857 1.1 skrll common_error:
2858 1.1 skrll (*info->callbacks->warning) (info, errmsg, name, input_bfd,
2859 1.1 skrll input_section, offset);
2860 1.1 skrll break;
2861 1.1 skrll }
2862 1.1 skrll }
2863 1.1 skrll }
2864 1.1 skrll
2865 1.1 skrll return ret;
2866 1.1.1.9 christos }
2867 1.1 skrll
2868 1.1 skrll /* Finish up dynamic symbol handling. We set the contents of various
2869 1.1 skrll dynamic sections here. */
2870 1.1 skrll
2871 1.1 skrll static bool
2872 1.1.1.9 christos m32r_elf_finish_dynamic_symbol (bfd *output_bfd,
2873 1.1 skrll struct bfd_link_info *info,
2874 1.1 skrll struct elf_link_hash_entry *h,
2875 1.1 skrll Elf_Internal_Sym *sym)
2876 1.1 skrll {
2877 1.1 skrll struct elf_link_hash_table *htab;
2878 1.1 skrll bfd_byte *loc;
2879 1.1 skrll
2880 1.1.1.2 christos #ifdef DEBUG_PIC
2881 1.1.1.9 christos printf ("m32r_elf_finish_dynamic_symbol()\n");
2882 1.1 skrll #endif
2883 1.1 skrll
2884 1.1 skrll htab = m32r_elf_hash_table (info);
2885 1.1 skrll if (htab == NULL)
2886 1.1 skrll return false;
2887 1.1 skrll
2888 1.1 skrll if (h->plt.offset != (bfd_vma) -1)
2889 1.1 skrll {
2890 1.1 skrll asection *splt;
2891 1.1 skrll asection *sgot;
2892 1.1 skrll asection *srela;
2893 1.1 skrll
2894 1.1.1.6 christos bfd_vma plt_index;
2895 1.1 skrll bfd_vma got_offset;
2896 1.1 skrll Elf_Internal_Rela rela;
2897 1.1 skrll
2898 1.1.1.9 christos /* This symbol has an entry in the procedure linkage table. Set
2899 1.1.1.9 christos it up. */
2900 1.1.1.9 christos
2901 1.1 skrll BFD_ASSERT (h->dynindx != -1);
2902 1.1 skrll
2903 1.1 skrll splt = htab->splt;
2904 1.1.1.6 christos sgot = htab->sgotplt;
2905 1.1.1.6 christos srela = htab->srelplt;
2906 1.1.1.6 christos BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
2907 1.1 skrll
2908 1.1 skrll /* Get the index in the procedure linkage table which
2909 1.1 skrll corresponds to this symbol. This is the index of this symbol
2910 1.1.1.6 christos in all the symbols for which we are making plt entries. The
2911 1.1.1.6 christos first entry in the procedure linkage table is reserved. */
2912 1.1 skrll plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2913 1.1 skrll
2914 1.1 skrll /* Get the offset into the .got table of the entry that
2915 1.1.1.4 christos corresponds to this function. Each .got entry is 4 bytes.
2916 1.1.1.6 christos The first three are reserved. */
2917 1.1.1.6 christos got_offset = (plt_index + 3) * 4;
2918 1.1.1.6 christos
2919 1.1.1.6 christos /* Fill in the entry in the procedure linkage table. */
2920 1.1.1.6 christos if (! bfd_link_pic (info))
2921 1.1.1.6 christos {
2922 1.1.1.6 christos bfd_put_32 (output_bfd,
2923 1.1.1.6 christos (PLT_ENTRY_WORD0b
2924 1.1.1.6 christos + (((sgot->output_section->vma
2925 1.1.1.6 christos + sgot->output_offset
2926 1.1.1.6 christos + got_offset) >> 16) & 0xffff)),
2927 1.1.1.6 christos splt->contents + h->plt.offset);
2928 1.1.1.6 christos bfd_put_32 (output_bfd,
2929 1.1.1.6 christos (PLT_ENTRY_WORD1b
2930 1.1.1.6 christos + ((sgot->output_section->vma
2931 1.1.1.6 christos + sgot->output_offset
2932 1.1.1.6 christos + got_offset) & 0xffff)),
2933 1.1.1.6 christos splt->contents + h->plt.offset + 4);
2934 1.1.1.6 christos bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
2935 1.1.1.6 christos splt->contents + h->plt.offset + 8);
2936 1.1.1.6 christos bfd_put_32 (output_bfd,
2937 1.1.1.6 christos (PLT_ENTRY_WORD3
2938 1.1.1.6 christos + plt_index * sizeof (Elf32_External_Rela)),
2939 1.1.1.6 christos splt->contents + h->plt.offset + 12);
2940 1.1 skrll bfd_put_32 (output_bfd,
2941 1.1.1.6 christos (PLT_ENTRY_WORD4
2942 1.1.1.6 christos + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
2943 1.1.1.6 christos splt->contents + h->plt.offset + 16);
2944 1.1.1.6 christos }
2945 1.1.1.6 christos else
2946 1.1.1.6 christos {
2947 1.1.1.6 christos bfd_put_32 (output_bfd,
2948 1.1.1.6 christos PLT_ENTRY_WORD0 + got_offset,
2949 1.1.1.6 christos splt->contents + h->plt.offset);
2950 1.1.1.6 christos bfd_put_32 (output_bfd, PLT_ENTRY_WORD1,
2951 1.1.1.6 christos splt->contents + h->plt.offset + 4);
2952 1.1.1.6 christos bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
2953 1.1.1.6 christos splt->contents + h->plt.offset + 8);
2954 1.1.1.6 christos bfd_put_32 (output_bfd,
2955 1.1.1.6 christos (PLT_ENTRY_WORD3
2956 1.1.1.6 christos + plt_index * sizeof (Elf32_External_Rela)),
2957 1.1.1.6 christos splt->contents + h->plt.offset + 12);
2958 1.1 skrll bfd_put_32 (output_bfd,
2959 1.1 skrll (PLT_ENTRY_WORD4
2960 1.1 skrll + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
2961 1.1.1.6 christos splt->contents + h->plt.offset + 16);
2962 1.1.1.6 christos }
2963 1.1.1.6 christos
2964 1.1.1.6 christos /* Fill in the entry in the global offset table. */
2965 1.1.1.6 christos bfd_put_32 (output_bfd,
2966 1.1 skrll (splt->output_section->vma
2967 1.1 skrll + splt->output_offset
2968 1.1 skrll + h->plt.offset
2969 1.1.1.6 christos + 12), /* same offset */
2970 1.1.1.6 christos sgot->contents + got_offset);
2971 1.1 skrll
2972 1.1 skrll /* Fill in the entry in the .rela.plt section. */
2973 1.1 skrll rela.r_offset = (sgot->output_section->vma
2974 1.1 skrll + sgot->output_offset
2975 1.1 skrll + got_offset);
2976 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_JMP_SLOT);
2977 1.1 skrll rela.r_addend = 0;
2978 1.1.1.6 christos loc = srela->contents;
2979 1.1.1.6 christos loc += plt_index * sizeof (Elf32_External_Rela);
2980 1.1.1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2981 1.1.1.6 christos
2982 1.1.1.6 christos if (!h->def_regular)
2983 1.1 skrll {
2984 1.1 skrll /* Mark the symbol as undefined, rather than as defined in
2985 1.1 skrll the .plt section. Leave the value alone. */
2986 1.1 skrll sym->st_shndx = SHN_UNDEF;
2987 1.1 skrll }
2988 1.1 skrll }
2989 1.1 skrll
2990 1.1 skrll if (h->got.offset != (bfd_vma) -1)
2991 1.1 skrll {
2992 1.1.1.6 christos asection *sgot;
2993 1.1 skrll asection *srela;
2994 1.1.1.9 christos Elf_Internal_Rela rela;
2995 1.1.1.9 christos
2996 1.1 skrll /* This symbol has an entry in the global offset table. Set it
2997 1.1 skrll up. */
2998 1.1 skrll
2999 1.1.1.6 christos sgot = htab->sgot;
3000 1.1.1.6 christos srela = htab->srelgot;
3001 1.1 skrll BFD_ASSERT (sgot != NULL && srela != NULL);
3002 1.1 skrll
3003 1.1.1.6 christos rela.r_offset = (sgot->output_section->vma
3004 1.1.1.6 christos + sgot->output_offset
3005 1.1.1.6 christos + (h->got.offset &~ 1));
3006 1.1.1.6 christos
3007 1.1.1.4 christos /* If this is a -Bsymbolic link, and the symbol is defined
3008 1.1.1.6 christos locally, we just want to emit a RELATIVE reloc. Likewise if
3009 1.1 skrll the symbol was forced to be local because of a version file.
3010 1.1 skrll The entry in the global offset table will already have been
3011 1.1.1.6 christos initialized in the relocate_section function. */
3012 1.1.1.6 christos if (bfd_link_pic (info)
3013 1.1.1.6 christos && (info->symbolic
3014 1.1.1.6 christos || h->dynindx == -1
3015 1.1.1.6 christos || h->forced_local)
3016 1.1.1.6 christos && h->def_regular)
3017 1.1.1.6 christos {
3018 1.1 skrll rela.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
3019 1.1.1.6 christos rela.r_addend = (h->root.u.def.value
3020 1.1 skrll + h->root.u.def.section->output_section->vma
3021 1.1.1.6 christos + h->root.u.def.section->output_offset);
3022 1.1.1.6 christos }
3023 1.1.1.6 christos else
3024 1.1.1.6 christos {
3025 1.1 skrll BFD_ASSERT ((h->got.offset & 1) == 0);
3026 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3027 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_GLOB_DAT);
3028 1.1 skrll rela.r_addend = 0;
3029 1.1 skrll }
3030 1.1 skrll
3031 1.1 skrll loc = srela->contents;
3032 1.1 skrll loc += srela->reloc_count * sizeof (Elf32_External_Rela);
3033 1.1 skrll bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3034 1.1 skrll ++srela->reloc_count;
3035 1.1 skrll }
3036 1.1 skrll
3037 1.1 skrll if (h->needs_copy)
3038 1.1 skrll {
3039 1.1 skrll asection *s;
3040 1.1.1.6 christos Elf_Internal_Rela rela;
3041 1.1.1.6 christos
3042 1.1 skrll /* This symbols needs a copy reloc. Set it up. */
3043 1.1.1.9 christos
3044 1.1 skrll BFD_ASSERT (h->dynindx != -1
3045 1.1 skrll && (h->root.type == bfd_link_hash_defined
3046 1.1 skrll || h->root.type == bfd_link_hash_defweak));
3047 1.1.1.6 christos
3048 1.1.1.6 christos s = bfd_get_linker_section (htab->dynobj, ".rela.bss");
3049 1.1 skrll BFD_ASSERT (s != NULL);
3050 1.1 skrll
3051 1.1 skrll rela.r_offset = (h->root.u.def.value
3052 1.1 skrll + h->root.u.def.section->output_section->vma
3053 1.1 skrll + h->root.u.def.section->output_offset);
3054 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_COPY);
3055 1.1 skrll rela.r_addend = 0;
3056 1.1 skrll loc = s->contents;
3057 1.1 skrll loc += s->reloc_count * sizeof (Elf32_External_Rela);
3058 1.1.1.9 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3059 1.1 skrll ++s->reloc_count;
3060 1.1 skrll }
3061 1.1.1.9 christos
3062 1.1 skrll /* Mark some specially defined symbols as absolute. */
3063 1.1 skrll if (h == htab->hdynamic || h == htab->hgot)
3064 1.1 skrll sym->st_shndx = SHN_ABS;
3065 1.1 skrll
3066 1.1 skrll return true;
3067 1.1.1.9 christos }
3068 1.1 skrll
3069 1.1 skrll
3070 1.1 skrll /* Finish up the dynamic sections. */
3071 1.1.1.9 christos
3072 1.1 skrll static bool
3073 1.1 skrll m32r_elf_finish_dynamic_sections (bfd *output_bfd,
3074 1.1 skrll struct bfd_link_info *info)
3075 1.1 skrll {
3076 1.1 skrll struct elf_link_hash_table *htab;
3077 1.1 skrll bfd *dynobj;
3078 1.1 skrll asection *sdyn;
3079 1.1 skrll asection *sgot;
3080 1.1 skrll
3081 1.1.1.2 christos #ifdef DEBUG_PIC
3082 1.1.1.9 christos printf ("m32r_elf_finish_dynamic_sections()\n");
3083 1.1.1.2 christos #endif
3084 1.1.1.9 christos
3085 1.1 skrll htab = m32r_elf_hash_table (info);
3086 1.1.1.9 christos if (htab == NULL)
3087 1.1.1.3 christos return false;
3088 1.1 skrll
3089 1.1.1.9 christos dynobj = htab->dynobj;
3090 1.1 skrll
3091 1.1 skrll sgot = htab->sgotplt;
3092 1.1 skrll sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3093 1.1 skrll
3094 1.1 skrll if (htab->dynamic_sections_created)
3095 1.1 skrll {
3096 1.1 skrll asection *splt;
3097 1.1 skrll Elf32_External_Dyn *dyncon, *dynconend;
3098 1.1 skrll
3099 1.1 skrll BFD_ASSERT (sgot != NULL && sdyn != NULL);
3100 1.1.1.6 christos
3101 1.1.1.6 christos dyncon = (Elf32_External_Dyn *) sdyn->contents;
3102 1.1.1.6 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3103 1.1 skrll
3104 1.1.1.6 christos for (; dyncon < dynconend; dyncon++)
3105 1.1 skrll {
3106 1.1.1.6 christos Elf_Internal_Dyn dyn;
3107 1.1.1.6 christos asection *s;
3108 1.1.1.6 christos
3109 1.1.1.6 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3110 1.1.1.6 christos
3111 1.1.1.6 christos switch (dyn.d_tag)
3112 1.1.1.9 christos {
3113 1.1.1.6 christos default:
3114 1.1.1.6 christos break;
3115 1.1.1.9 christos
3116 1.1.1.6 christos case DT_PLTGOT:
3117 1.1.1.6 christos s = htab->sgotplt;
3118 1.1.1.6 christos goto get_vma;
3119 1.1.1.6 christos case DT_JMPREL:
3120 1.1.1.6 christos s = htab->srelplt;
3121 1.1.1.6 christos get_vma:
3122 1.1.1.9 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3123 1.1.1.6 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3124 1.1.1.6 christos break;
3125 1.1.1.6 christos
3126 1.1.1.6 christos case DT_PLTRELSZ:
3127 1.1.1.6 christos s = htab->srelplt;
3128 1.1 skrll dyn.d_un.d_val = s->size;
3129 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3130 1.1.1.9 christos break;
3131 1.1 skrll }
3132 1.1.1.6 christos }
3133 1.1.1.6 christos
3134 1.1.1.6 christos /* Fill in the first entry in the procedure linkage table. */
3135 1.1.1.6 christos splt = htab->splt;
3136 1.1.1.6 christos if (splt && splt->size > 0)
3137 1.1.1.6 christos {
3138 1.1.1.6 christos if (bfd_link_pic (info))
3139 1.1.1.6 christos {
3140 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents);
3141 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4);
3142 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2, splt->contents + 8);
3143 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3, splt->contents + 12);
3144 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4, splt->contents + 16);
3145 1.1.1.6 christos }
3146 1.1.1.6 christos else
3147 1.1 skrll {
3148 1.1 skrll unsigned long addr;
3149 1.1.1.6 christos /* addr = .got + 4 */
3150 1.1 skrll addr = sgot->output_section->vma + sgot->output_offset + 4;
3151 1.1 skrll bfd_put_32 (output_bfd,
3152 1.1.1.6 christos PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
3153 1.1.1.6 christos splt->contents);
3154 1.1.1.6 christos bfd_put_32 (output_bfd,
3155 1.1.1.6 christos PLT0_ENTRY_WORD1 | (addr & 0xffff),
3156 1.1.1.6 christos splt->contents + 4);
3157 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
3158 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
3159 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
3160 1.1 skrll }
3161 1.1 skrll
3162 1.1 skrll elf_section_data (splt->output_section)->this_hdr.sh_entsize =
3163 1.1 skrll PLT_ENTRY_SIZE;
3164 1.1 skrll }
3165 1.1 skrll }
3166 1.1.1.6 christos
3167 1.1 skrll /* Fill in the first three entries in the global offset table. */
3168 1.1.1.6 christos if (sgot && sgot->size > 0)
3169 1.1.1.6 christos {
3170 1.1.1.6 christos if (sdyn == NULL)
3171 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3172 1.1 skrll else
3173 1.1 skrll bfd_put_32 (output_bfd,
3174 1.1 skrll sdyn->output_section->vma + sdyn->output_offset,
3175 1.1 skrll sgot->contents);
3176 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
3177 1.1.1.9 christos bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3178 1.1 skrll
3179 1.1 skrll elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
3180 1.1 skrll }
3181 1.1 skrll
3182 1.1 skrll return true;
3183 1.1.1.9 christos }
3184 1.1 skrll
3185 1.1 skrll
3186 1.1 skrll /* Set the right machine number. */
3188 1.1 skrll
3189 1.1 skrll static bool
3190 1.1 skrll m32r_elf_object_p (bfd *abfd)
3191 1.1 skrll {
3192 1.1 skrll switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
3193 1.1.1.9 christos {
3194 1.1 skrll default:
3195 1.1 skrll case E_M32R_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r); break;
3196 1.1 skrll case E_M32RX_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;
3197 1.1 skrll case E_M32R2_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r2); break;
3198 1.1.1.9 christos }
3199 1.1.1.8 christos return true;
3200 1.1 skrll }
3201 1.1 skrll
3202 1.1 skrll /* Store the machine number in the flags field. */
3203 1.1 skrll
3204 1.1 skrll static bool
3205 1.1 skrll m32r_elf_final_write_processing (bfd *abfd)
3206 1.1 skrll {
3207 1.1 skrll unsigned long val;
3208 1.1 skrll
3209 1.1 skrll switch (bfd_get_mach (abfd))
3210 1.1 skrll {
3211 1.1 skrll default:
3212 1.1 skrll case bfd_mach_m32r: val = E_M32R_ARCH; break;
3213 1.1.1.8 christos case bfd_mach_m32rx: val = E_M32RX_ARCH; break;
3214 1.1 skrll case bfd_mach_m32r2: val = E_M32R2_ARCH; break;
3215 1.1 skrll }
3216 1.1 skrll
3217 1.1 skrll elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;
3218 1.1.1.9 christos elf_elfheader (abfd)->e_flags |= val;
3219 1.1 skrll return _bfd_elf_final_write_processing (abfd);
3220 1.1 skrll }
3221 1.1 skrll
3222 1.1 skrll /* Function to keep M32R specific file flags. */
3223 1.1 skrll
3224 1.1 skrll static bool
3225 1.1.1.9 christos m32r_elf_set_private_flags (bfd *abfd, flagword flags)
3226 1.1.1.9 christos {
3227 1.1 skrll BFD_ASSERT (!elf_flags_init (abfd)
3228 1.1 skrll || elf_elfheader (abfd)->e_flags == flags);
3229 1.1 skrll
3230 1.1 skrll elf_elfheader (abfd)->e_flags = flags;
3231 1.1 skrll elf_flags_init (abfd) = true;
3232 1.1.1.9 christos return true;
3233 1.1.1.6 christos }
3234 1.1 skrll
3235 1.1.1.6 christos /* Merge backend specific data from an object file to the output
3236 1.1 skrll object file when linking. */
3237 1.1 skrll
3238 1.1 skrll static bool
3239 1.1 skrll m32r_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
3240 1.1 skrll {
3241 1.1.1.9 christos bfd *obfd = info->output_bfd;
3242 1.1 skrll flagword out_flags;
3243 1.1 skrll flagword in_flags;
3244 1.1 skrll
3245 1.1 skrll if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3246 1.1 skrll || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3247 1.1 skrll return true;
3248 1.1 skrll
3249 1.1 skrll in_flags = elf_elfheader (ibfd)->e_flags;
3250 1.1 skrll out_flags = elf_elfheader (obfd)->e_flags;
3251 1.1 skrll
3252 1.1 skrll if (! elf_flags_init (obfd))
3253 1.1 skrll {
3254 1.1 skrll /* If the input is the default architecture then do not
3255 1.1.1.9 christos bother setting the flags for the output architecture,
3256 1.1 skrll instead allow future merges to do this. If no future
3257 1.1.1.9 christos merges ever set these flags then they will retain their
3258 1.1 skrll unitialised values, which surprise surprise, correspond
3259 1.1 skrll to the default values. */
3260 1.1 skrll if (bfd_get_arch_info (ibfd)->the_default)
3261 1.1 skrll return true;
3262 1.1 skrll
3263 1.1 skrll elf_flags_init (obfd) = true;
3264 1.1 skrll elf_elfheader (obfd)->e_flags = in_flags;
3265 1.1.1.9 christos
3266 1.1 skrll if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3267 1.1 skrll && bfd_get_arch_info (obfd)->the_default)
3268 1.1 skrll return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3269 1.1 skrll bfd_get_mach (ibfd));
3270 1.1.1.9 christos
3271 1.1 skrll return true;
3272 1.1 skrll }
3273 1.1 skrll
3274 1.1 skrll /* Check flag compatibility. */
3275 1.1.1.6 christos if (in_flags == out_flags)
3276 1.1.1.6 christos return true;
3277 1.1 skrll
3278 1.1.1.6 christos if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))
3279 1.1.1.7 christos {
3280 1.1 skrll if ( ((in_flags & EF_M32R_ARCH) != E_M32R_ARCH)
3281 1.1 skrll || ((out_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3282 1.1.1.9 christos || ((in_flags & EF_M32R_ARCH) == E_M32R2_ARCH))
3283 1.1 skrll {
3284 1.1 skrll _bfd_error_handler
3285 1.1 skrll (_("%pB: instruction set mismatch with previous modules"), ibfd);
3286 1.1.1.9 christos
3287 1.1 skrll bfd_set_error (bfd_error_bad_value);
3288 1.1 skrll return false;
3289 1.1 skrll }
3290 1.1 skrll }
3291 1.1.1.9 christos
3292 1.1 skrll return true;
3293 1.1 skrll }
3294 1.1 skrll
3295 1.1 skrll /* Display the flags field. */
3296 1.1 skrll
3297 1.1 skrll static bool
3298 1.1 skrll m32r_elf_print_private_bfd_data (bfd *abfd, void * ptr)
3299 1.1 skrll {
3300 1.1 skrll FILE * file = (FILE *) ptr;
3301 1.1 skrll
3302 1.1 skrll BFD_ASSERT (abfd != NULL && ptr != NULL);
3303 1.1 skrll
3304 1.1 skrll _bfd_elf_print_private_bfd_data (abfd, ptr);
3305 1.1 skrll
3306 1.1 skrll fprintf (file, _("private flags = %lx"), elf_elfheader (abfd)->e_flags);
3307 1.1 skrll
3308 1.1 skrll switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
3309 1.1 skrll {
3310 1.1 skrll default:
3311 1.1 skrll case E_M32R_ARCH: fprintf (file, _(": m32r instructions")); break;
3312 1.1.1.9 christos case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;
3313 1.1 skrll case E_M32R2_ARCH: fprintf (file, _(": m32r2 instructions")); break;
3314 1.1 skrll }
3315 1.1 skrll
3316 1.1 skrll fputc ('\n', file);
3317 1.1 skrll
3318 1.1 skrll return true;
3319 1.1 skrll }
3320 1.1 skrll
3321 1.1 skrll static asection *
3322 1.1 skrll m32r_elf_gc_mark_hook (asection *sec,
3323 1.1 skrll struct bfd_link_info *info,
3324 1.1 skrll Elf_Internal_Rela *rel,
3325 1.1 skrll struct elf_link_hash_entry *h,
3326 1.1 skrll Elf_Internal_Sym *sym)
3327 1.1 skrll {
3328 1.1 skrll if (h != NULL)
3329 1.1 skrll switch (ELF32_R_TYPE (rel->r_info))
3330 1.1 skrll {
3331 1.1 skrll case R_M32R_GNU_VTINHERIT:
3332 1.1 skrll case R_M32R_GNU_VTENTRY:
3333 1.1 skrll case R_M32R_RELA_GNU_VTINHERIT:
3334 1.1 skrll case R_M32R_RELA_GNU_VTENTRY:
3335 1.1 skrll return NULL;
3336 1.1 skrll }
3337 1.1 skrll
3338 1.1 skrll return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
3339 1.1.1.9 christos }
3340 1.1 skrll
3341 1.1 skrll /* Look through the relocs for a section during the first phase.
3342 1.1 skrll Since we don't do .gots or .plts, we just need to consider the
3343 1.1 skrll virtual table relocs for gc. */
3344 1.1 skrll
3345 1.1 skrll static bool
3346 1.1 skrll m32r_elf_check_relocs (bfd *abfd,
3347 1.1 skrll struct bfd_link_info *info,
3348 1.1 skrll asection *sec,
3349 1.1.1.9 christos const Elf_Internal_Rela *relocs)
3350 1.1 skrll {
3351 1.1.1.2 christos Elf_Internal_Shdr *symtab_hdr;
3352 1.1 skrll struct elf_link_hash_entry **sym_hashes;
3353 1.1.1.4 christos const Elf_Internal_Rela *rel;
3354 1.1.1.9 christos const Elf_Internal_Rela *rel_end;
3355 1.1.1.6 christos struct elf_link_hash_table *htab;
3356 1.1.1.2 christos bfd *dynobj;
3357 1.1 skrll asection *sreloc;
3358 1.1 skrll
3359 1.1 skrll if (bfd_link_relocatable (info))
3360 1.1 skrll return true;
3361 1.1.1.2 christos
3362 1.1.1.9 christos sreloc = NULL;
3363 1.1.1.2 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3364 1.1.1.9 christos sym_hashes = elf_sym_hashes (abfd);
3365 1.1 skrll
3366 1.1 skrll htab = m32r_elf_hash_table (info);
3367 1.1 skrll if (htab == NULL)
3368 1.1 skrll return false;
3369 1.1 skrll
3370 1.1 skrll dynobj = htab->dynobj;
3371 1.1 skrll
3372 1.1 skrll rel_end = relocs + sec->reloc_count;
3373 1.1 skrll for (rel = relocs; rel < rel_end; rel++)
3374 1.1 skrll {
3375 1.1 skrll int r_type;
3376 1.1.1.6 christos struct elf_link_hash_entry *h;
3377 1.1 skrll unsigned long r_symndx;
3378 1.1 skrll
3379 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
3380 1.1 skrll r_type = ELF32_R_TYPE (rel->r_info);
3381 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
3382 1.1 skrll h = NULL;
3383 1.1 skrll else
3384 1.1 skrll {
3385 1.1 skrll h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3386 1.1.1.9 christos while (h->root.type == bfd_link_hash_indirect
3387 1.1.1.6 christos || h->root.type == bfd_link_hash_warning)
3388 1.1.1.6 christos h = (struct elf_link_hash_entry *) h->root.u.i.link;
3389 1.1.1.6 christos }
3390 1.1.1.6 christos
3391 1.1.1.6 christos /* Some relocs require a global offset table. */
3392 1.1.1.6 christos if (htab->sgot == NULL)
3393 1.1.1.6 christos {
3394 1.1.1.6 christos switch (r_type)
3395 1.1.1.6 christos {
3396 1.1.1.6 christos case R_M32R_GOT16_HI_ULO:
3397 1.1.1.6 christos case R_M32R_GOT16_HI_SLO:
3398 1.1.1.6 christos case R_M32R_GOTOFF:
3399 1.1.1.6 christos case R_M32R_GOTOFF_HI_ULO:
3400 1.1.1.6 christos case R_M32R_GOTOFF_HI_SLO:
3401 1.1.1.6 christos case R_M32R_GOTOFF_LO:
3402 1.1.1.6 christos case R_M32R_GOT16_LO:
3403 1.1.1.9 christos case R_M32R_GOTPC24:
3404 1.1.1.6 christos case R_M32R_GOTPC_HI_ULO:
3405 1.1.1.9 christos case R_M32R_GOTPC_HI_SLO:
3406 1.1.1.6 christos case R_M32R_GOTPC_LO:
3407 1.1.1.6 christos case R_M32R_GOT24:
3408 1.1.1.6 christos if (dynobj == NULL)
3409 1.1.1.6 christos htab->dynobj = dynobj = abfd;
3410 1.1.1.6 christos if (!_bfd_elf_create_got_section (dynobj, info))
3411 1.1.1.6 christos return false;
3412 1.1 skrll break;
3413 1.1 skrll
3414 1.1.1.6 christos default:
3415 1.1 skrll break;
3416 1.1 skrll }
3417 1.1 skrll }
3418 1.1.1.6 christos
3419 1.1.1.6 christos switch (r_type)
3420 1.1.1.6 christos {
3421 1.1.1.6 christos case R_M32R_GOT16_HI_ULO:
3422 1.1.1.6 christos case R_M32R_GOT16_HI_SLO:
3423 1.1.1.6 christos case R_M32R_GOT16_LO:
3424 1.1.1.6 christos case R_M32R_GOT24:
3425 1.1 skrll
3426 1.1.1.6 christos if (h != NULL)
3427 1.1.1.6 christos h->got.refcount += 1;
3428 1.1.1.6 christos else
3429 1.1.1.6 christos {
3430 1.1.1.6 christos bfd_signed_vma *local_got_refcounts;
3431 1.1.1.6 christos
3432 1.1.1.6 christos /* This is a global offset table entry for a local
3433 1.1.1.6 christos symbol. */
3434 1.1.1.6 christos local_got_refcounts = elf_local_got_refcounts (abfd);
3435 1.1.1.6 christos if (local_got_refcounts == NULL)
3436 1.1.1.6 christos {
3437 1.1.1.9 christos bfd_size_type size;
3438 1.1.1.6 christos
3439 1.1.1.6 christos size = symtab_hdr->sh_info;
3440 1.1.1.6 christos size *= sizeof (bfd_signed_vma);
3441 1.1.1.6 christos local_got_refcounts = bfd_zalloc (abfd, size);
3442 1.1.1.6 christos if (local_got_refcounts == NULL)
3443 1.1.1.6 christos return false;
3444 1.1.1.6 christos elf_local_got_refcounts (abfd) = local_got_refcounts;
3445 1.1.1.6 christos }
3446 1.1.1.6 christos local_got_refcounts[r_symndx] += 1;
3447 1.1.1.6 christos }
3448 1.1.1.6 christos break;
3449 1.1.1.6 christos
3450 1.1 skrll case R_M32R_26_PLTREL:
3451 1.1 skrll /* This symbol requires a procedure linkage table entry. We
3452 1.1 skrll actually build the entry in adjust_dynamic_symbol,
3453 1.1.1.6 christos because this might be a case of linking PIC code without
3454 1.1.1.6 christos linking in any dynamic objects, in which case we don't
3455 1.1 skrll need to generate a procedure linkage table after all. */
3456 1.1.1.6 christos
3457 1.1.1.6 christos /* If this is a local symbol, we resolve it directly without
3458 1.1 skrll creating a procedure linkage table entry. */
3459 1.1.1.6 christos if (h == NULL)
3460 1.1 skrll continue;
3461 1.1.1.6 christos
3462 1.1 skrll if (h->forced_local)
3463 1.1.1.6 christos break;
3464 1.1.1.6 christos
3465 1.1.1.6 christos h->needs_plt = 1;
3466 1.1.1.6 christos h->plt.refcount += 1;
3467 1.1.1.6 christos break;
3468 1.1.1.6 christos
3469 1.1.1.6 christos case R_M32R_16_RELA:
3470 1.1.1.6 christos case R_M32R_24_RELA:
3471 1.1 skrll case R_M32R_32_RELA:
3472 1.1.1.6 christos case R_M32R_REL32:
3473 1.1.1.6 christos case R_M32R_HI16_ULO_RELA:
3474 1.1.1.6 christos case R_M32R_HI16_SLO_RELA:
3475 1.1.1.6 christos case R_M32R_LO16_RELA:
3476 1.1.1.6 christos case R_M32R_SDA16_RELA:
3477 1.1.1.6 christos case R_M32R_10_PCREL_RELA:
3478 1.1.1.6 christos case R_M32R_18_PCREL_RELA:
3479 1.1.1.6 christos case R_M32R_26_PCREL_RELA:
3480 1.1 skrll
3481 1.1.1.6 christos if (h != NULL && !bfd_link_pic (info))
3482 1.1.1.6 christos {
3483 1.1.1.6 christos h->non_got_ref = 1;
3484 1.1.1.6 christos h->plt.refcount += 1;
3485 1.1.1.6 christos }
3486 1.1.1.6 christos
3487 1.1.1.6 christos /* If we are creating a shared library, and this is a reloc
3488 1.1.1.6 christos against a global symbol, or a non PC relative reloc
3489 1.1.1.6 christos against a local symbol, then we need to copy the reloc
3490 1.1.1.6 christos into the shared library. However, if we are linking with
3491 1.1.1.6 christos -Bsymbolic, we do not need to copy a reloc against a
3492 1.1.1.6 christos global symbol which is defined in an object we are
3493 1.1.1.6 christos including in the link (i.e., DEF_REGULAR is set). At
3494 1.1.1.6 christos this point we have not seen all the input files, so it is
3495 1.1.1.6 christos possible that DEF_REGULAR is not set now but will be set
3496 1.1.1.6 christos later (it is never cleared). We account for that
3497 1.1.1.6 christos possibility below by storing information in the
3498 1.1.1.6 christos dyn_relocs field of the hash table entry. A similar
3499 1.1.1.6 christos situation occurs when creating shared libraries and symbol
3500 1.1.1.6 christos visibility changes render the symbol local.
3501 1.1.1.6 christos
3502 1.1 skrll If on the other hand, we are creating an executable, we
3503 1.1.1.6 christos may need to keep relocations for symbols satisfied by a
3504 1.1.1.6 christos dynamic library if we manage to avoid copy relocs for the
3505 1.1.1.6 christos symbol. */
3506 1.1.1.6 christos if ((bfd_link_pic (info)
3507 1.1 skrll && (sec->flags & SEC_ALLOC) != 0
3508 1.1.1.6 christos && (( r_type != R_M32R_26_PCREL_RELA
3509 1.1.1.6 christos && r_type != R_M32R_18_PCREL_RELA
3510 1.1.1.6 christos && r_type != R_M32R_10_PCREL_RELA
3511 1.1.1.6 christos && r_type != R_M32R_REL32)
3512 1.1.1.6 christos || (h != NULL
3513 1.1.1.6 christos && (! info->symbolic
3514 1.1.1.6 christos || h->root.type == bfd_link_hash_defweak
3515 1.1.1.6 christos || !h->def_regular))))
3516 1.1.1.6 christos || (!bfd_link_pic (info)
3517 1.1.1.6 christos && (sec->flags & SEC_ALLOC) != 0
3518 1.1.1.6 christos && h != NULL
3519 1.1.1.6 christos && (h->root.type == bfd_link_hash_defweak
3520 1.1.1.9 christos || !h->def_regular)))
3521 1.1.1.6 christos {
3522 1.1.1.6 christos struct elf_dyn_relocs *p;
3523 1.1.1.6 christos struct elf_dyn_relocs **head;
3524 1.1.1.6 christos
3525 1.1.1.6 christos if (dynobj == NULL)
3526 1.1.1.6 christos htab->dynobj = dynobj = abfd;
3527 1.1.1.2 christos
3528 1.1.1.9 christos /* When creating a shared object, we must copy these
3529 1.1 skrll relocs into the output file. We create a reloc
3530 1.1.1.2 christos section in dynobj and make room for the reloc. */
3531 1.1.1.9 christos if (sreloc == NULL)
3532 1.1.1.6 christos {
3533 1.1 skrll sreloc = _bfd_elf_make_dynamic_reloc_section
3534 1.1.1.6 christos (sec, dynobj, 2, abfd, /*rela?*/ true);
3535 1.1.1.6 christos
3536 1.1.1.6 christos if (sreloc == NULL)
3537 1.1.1.9 christos return false;
3538 1.1.1.6 christos }
3539 1.1.1.6 christos
3540 1.1.1.6 christos /* If this is a global symbol, we count the number of
3541 1.1.1.6 christos relocations we need for this symbol. */
3542 1.1.1.6 christos if (h != NULL)
3543 1.1.1.2 christos head = &h->dyn_relocs;
3544 1.1 skrll else
3545 1.1.1.2 christos {
3546 1.1.1.2 christos /* Track dynamic relocs needed for local syms too. */
3547 1.1.1.2 christos asection *s;
3548 1.1.1.9 christos void *vpp;
3549 1.1.1.2 christos Elf_Internal_Sym *isym;
3550 1.1.1.2 christos
3551 1.1.1.2 christos isym = bfd_sym_from_r_symndx (&htab->sym_cache,
3552 1.1.1.2 christos abfd, r_symndx);
3553 1.1 skrll if (isym == NULL)
3554 1.1 skrll return false;
3555 1.1.1.6 christos
3556 1.1.1.6 christos s = bfd_section_from_elf_index (abfd, isym->st_shndx);
3557 1.1 skrll if (s == NULL)
3558 1.1.1.6 christos s = sec;
3559 1.1.1.6 christos
3560 1.1.1.6 christos vpp = &elf_section_data (s)->local_dynrel;
3561 1.1.1.9 christos head = (struct elf_dyn_relocs **) vpp;
3562 1.1.1.6 christos }
3563 1.1.1.6 christos
3564 1.1.1.6 christos p = *head;
3565 1.1.1.9 christos if (p == NULL || p->sec != sec)
3566 1.1.1.6 christos {
3567 1.1.1.6 christos size_t amt = sizeof (*p);
3568 1.1.1.6 christos
3569 1.1.1.6 christos p = bfd_alloc (dynobj, amt);
3570 1.1.1.6 christos if (p == NULL)
3571 1.1.1.6 christos return false;
3572 1.1.1.6 christos p->next = *head;
3573 1.1.1.6 christos *head = p;
3574 1.1.1.6 christos p->sec = sec;
3575 1.1.1.6 christos p->count = 0;
3576 1.1 skrll p->pc_count = 0;
3577 1.1 skrll }
3578 1.1.1.6 christos
3579 1.1.1.6 christos p->count += 1;
3580 1.1.1.6 christos if ( ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
3581 1.1.1.6 christos || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA
3582 1.1.1.6 christos || ELF32_R_TYPE (rel->r_info) == R_M32R_10_PCREL_RELA
3583 1.1.1.6 christos || ELF32_R_TYPE (rel->r_info) == R_M32R_REL32)
3584 1.1.1.6 christos p->pc_count += 1;
3585 1.1.1.6 christos }
3586 1.1.1.6 christos break;
3587 1.1.1.9 christos
3588 1.1.1.6 christos /* This relocation describes the C++ object vtable hierarchy.
3589 1.1.1.6 christos Reconstruct it for later use during GC. */
3590 1.1.1.6 christos case R_M32R_RELA_GNU_VTINHERIT:
3591 1.1.1.6 christos case R_M32R_GNU_VTINHERIT:
3592 1.1.1.6 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3593 1.1.1.8 christos return false;
3594 1.1.1.9 christos break;
3595 1.1.1.6 christos
3596 1.1.1.6 christos /* This relocation describes which C++ vtable entries are actually
3597 1.1.1.8 christos used. Record for later use during GC. */
3598 1.1.1.9 christos case R_M32R_GNU_VTENTRY:
3599 1.1.1.6 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
3600 1.1.1.6 christos return false;
3601 1.1 skrll break;
3602 1.1 skrll case R_M32R_RELA_GNU_VTENTRY:
3603 1.1.1.9 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3604 1.1 skrll return false;
3605 1.1 skrll break;
3606 1.1 skrll }
3607 1.1 skrll }
3608 1.1.1.6 christos
3609 1.1 skrll return true;
3610 1.1.1.6 christos }
3611 1.1 skrll
3612 1.1 skrll static const struct bfd_elf_special_section m32r_elf_special_sections[] =
3613 1.1.1.9 christos {
3614 1.1.1.9 christos { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
3615 1.1.1.9 christos { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3616 1.1.1.9 christos { NULL, 0, 0, 0, 0 }
3617 1.1.1.9 christos };
3618 1.1.1.9 christos
3619 1.1.1.9 christos static bool
3620 1.1.1.9 christos m32r_elf_section_flags (const Elf_Internal_Shdr *hdr)
3621 1.1.1.9 christos {
3622 1.1.1.9 christos const char *name = hdr->bfd_section->name;
3623 1.1.1.9 christos
3624 1.1.1.9 christos if (startswith (name, ".sbss")
3625 1.1 skrll || startswith (name, ".sdata"))
3626 1.1.1.4 christos hdr->bfd_section->flags |= SEC_SMALL_DATA;
3627 1.1.1.4 christos
3628 1.1.1.4 christos return true;
3629 1.1 skrll }
3630 1.1 skrll
3631 1.1 skrll static enum elf_reloc_type_class
3632 1.1 skrll m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
3633 1.1 skrll const asection *rel_sec ATTRIBUTE_UNUSED,
3634 1.1 skrll const Elf_Internal_Rela *rela)
3635 1.1.1.6 christos {
3636 1.1 skrll switch ((int) ELF32_R_TYPE (rela->r_info))
3637 1.1 skrll {
3638 1.1 skrll case R_M32R_RELATIVE: return reloc_class_relative;
3639 1.1 skrll case R_M32R_JMP_SLOT: return reloc_class_plt;
3640 1.1.1.2 christos case R_M32R_COPY: return reloc_class_copy;
3641 1.1 skrll default: return reloc_class_normal;
3642 1.1 skrll }
3643 1.1 skrll }
3644 1.1 skrll
3645 1.1.1.6 christos #define ELF_ARCH bfd_arch_m32r
3647 1.1.1.6 christos #define ELF_TARGET_ID M32R_ELF_DATA
3648 1.1.1.6 christos #define ELF_MACHINE_CODE EM_M32R
3649 1.1 skrll #define ELF_MACHINE_ALT1 EM_CYGNUS_M32R
3650 1.1 skrll #define ELF_MAXPAGESIZE 0x1 /* Explicitly requested by Mitsubishi. */
3651 1.1 skrll
3652 1.1 skrll #define TARGET_BIG_SYM m32r_elf32_vec
3653 1.1 skrll #define TARGET_BIG_NAME "elf32-m32r"
3654 1.1 skrll #define TARGET_LITTLE_SYM m32r_elf32_le_vec
3655 1.1 skrll #define TARGET_LITTLE_NAME "elf32-m32rle"
3656 1.1.1.6 christos
3657 1.1.1.6 christos #define elf_info_to_howto m32r_info_to_howto
3658 1.1.1.6 christos #define elf_info_to_howto_rel m32r_info_to_howto_rel
3659 1.1.1.6 christos #define elf_backend_section_from_bfd_section _bfd_m32r_elf_section_from_bfd_section
3660 1.1.1.6 christos #define elf_backend_symbol_processing _bfd_m32r_elf_symbol_processing
3661 1.1.1.6 christos #define elf_backend_add_symbol_hook m32r_elf_add_symbol_hook
3662 1.1.1.7 christos #define elf_backend_relocate_section m32r_elf_relocate_section
3663 1.1.1.6 christos #define elf_backend_gc_mark_hook m32r_elf_gc_mark_hook
3664 1.1.1.6 christos #define elf_backend_check_relocs m32r_elf_check_relocs
3665 1.1.1.6 christos
3666 1.1.1.6 christos #define elf_backend_create_dynamic_sections m32r_elf_create_dynamic_sections
3667 1.1 skrll #define bfd_elf32_bfd_link_hash_table_create m32r_elf_link_hash_table_create
3668 1.1.1.6 christos #define elf_backend_size_dynamic_sections m32r_elf_size_dynamic_sections
3669 1.1 skrll #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
3670 1.1 skrll #define elf_backend_finish_dynamic_sections m32r_elf_finish_dynamic_sections
3671 1.1 skrll #define elf_backend_adjust_dynamic_symbol m32r_elf_adjust_dynamic_symbol
3672 1.1 skrll #define elf_backend_finish_dynamic_symbol m32r_elf_finish_dynamic_symbol
3673 1.1 skrll #define elf_backend_reloc_type_class m32r_elf_reloc_type_class
3674 1.1 skrll
3675 1.1 skrll #define elf_backend_can_gc_sections 1
3676 1.1 skrll /*#if !USE_REL
3677 1.1.1.6 christos #define elf_backend_rela_normal 1
3678 1.1 skrll #endif*/
3679 1.1.1.6 christos #define elf_backend_can_refcount 1
3680 1.1 skrll #define elf_backend_want_got_plt 1
3681 1.1.1.6 christos #define elf_backend_plt_readonly 1
3682 1.1.1.6 christos #define elf_backend_want_plt_sym 0
3683 1.1 skrll #define elf_backend_got_header_size 12
3684 1.1.1.6 christos #define elf_backend_dtrel_excludes_plt 1
3685 1.1.1.6 christos
3686 1.1 skrll #define elf_backend_may_use_rel_p 1
3687 1.1 skrll #ifdef USE_M32R_OLD_RELOC
3688 1.1 skrll #define elf_backend_default_use_rela_p 0
3689 1.1.1.6 christos #define elf_backend_may_use_rela_p 0
3690 1.1.1.6 christos #else
3691 1.1 skrll #define elf_backend_default_use_rela_p 1
3692 1.1 skrll #define elf_backend_may_use_rela_p 1
3693 1.1 skrll #endif
3694 1.1.1.9 christos
3695 1.1 skrll #define elf_backend_object_p m32r_elf_object_p
3696 1.1.1.9 christos #define elf_backend_final_write_processing m32r_elf_final_write_processing
3697 1.1.1.6 christos #define bfd_elf32_bfd_merge_private_bfd_data m32r_elf_merge_private_bfd_data
3698 1.1 skrll #define bfd_elf32_bfd_set_private_flags m32r_elf_set_private_flags
3699 1.1 skrll #define bfd_elf32_bfd_print_private_bfd_data m32r_elf_print_private_bfd_data
3700 1.1.1.6 christos #define elf_backend_special_sections m32r_elf_special_sections
3701 1.1.1.6 christos #define elf_backend_section_flags m32r_elf_section_flags
3702 1.1 skrll
3703 1.1.1.6 christos #define elf_backend_linux_prpsinfo32_ugid16 true
3704 1.1.1.6 christos
3705 1.1.1.6 christos #include "elf32-target.h"
3706 1.1.1.6 christos
3707 1.1.1.6 christos #undef ELF_MAXPAGESIZE
3708 1.1.1.6 christos #define ELF_MAXPAGESIZE 0x1000
3709 1.1.1.6 christos
3710 1.1.1.6 christos #undef TARGET_BIG_SYM
3711 1.1.1.6 christos #define TARGET_BIG_SYM m32r_elf32_linux_vec
3712 1.1.1.6 christos #undef TARGET_BIG_NAME
3713 1.1 skrll #define TARGET_BIG_NAME "elf32-m32r-linux"
3714 1.1 skrll #undef TARGET_LITTLE_SYM
3715 #define TARGET_LITTLE_SYM m32r_elf32_linux_le_vec
3716 #undef TARGET_LITTLE_NAME
3717 #define TARGET_LITTLE_NAME "elf32-m32rle-linux"
3718 #undef elf32_bed
3719 #define elf32_bed elf32_m32r_lin_bed
3720
3721 #include "elf32-target.h"
3722