elf32-m32r.c revision 1.1.1.8 1 1.1 skrll /* M32R-specific support for 32-bit ELF.
2 1.1.1.8 christos Copyright (C) 1996-2020 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 skrll switch (reloc_entry->howto->size)
225 1.1 skrll {
226 1.1 skrll case 1:
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 skrll case 2:
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.4 christos HOWTO (R_M32R_NONE, /* type */
478 1.1.1.4 christos 0, /* rightshift */
479 1.1 skrll 3, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc, /* special_function */
485 1.1 skrll "R_M32R_NONE", /* name */
486 1.1 skrll FALSE, /* partial_inplace */
487 1.1 skrll 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 skrll HOWTO (R_M32R_16, /* type */
493 1.1 skrll 0, /* rightshift */
494 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll m32r_elf_generic_reloc,/* special_function */
500 1.1 skrll "R_M32R_16", /* name */
501 1.1 skrll TRUE, /* partial_inplace */
502 1.1 skrll 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 skrll HOWTO (R_M32R_32, /* type */
508 1.1 skrll 0, /* rightshift */
509 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll m32r_elf_generic_reloc,/* special_function */
515 1.1 skrll "R_M32R_32", /* name */
516 1.1 skrll TRUE, /* partial_inplace */
517 1.1 skrll 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 skrll HOWTO (R_M32R_24, /* type */
523 1.1 skrll 0, /* rightshift */
524 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll m32r_elf_generic_reloc,/* special_function */
530 1.1 skrll "R_M32R_24", /* name */
531 1.1 skrll TRUE, /* partial_inplace */
532 1.1 skrll 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.6 christos HOWTO (R_M32R_10_PCREL, /* type */
545 1.1.1.6 christos 2, /* rightshift */
546 1.1.1.6 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
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.6 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 skrll 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 skrll HOWTO (R_M32R_18_PCREL, /* type */
560 1.1 skrll 2, /* rightshift */
561 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_26_PCREL, /* type */
579 1.1 skrll 2, /* rightshift */
580 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_HI16_ULO, /* type */
594 1.1 skrll 16, /* rightshift */
595 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_HI16_SLO, /* type */
609 1.1 skrll 16, /* rightshift */
610 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_LO16, /* type */
624 1.1 skrll 0, /* rightshift */
625 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll m32r_elf_lo16_reloc, /* special_function */
631 1.1 skrll "R_M32R_LO16", /* name */
632 1.1 skrll TRUE, /* partial_inplace */
633 1.1 skrll 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 skrll HOWTO (R_M32R_SDA16, /* type */
639 1.1 skrll 0, /* rightshift */
640 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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.6 christos HOWTO (R_M32R_GNU_VTINHERIT, /* type */
654 1.1.1.6 christos 0, /* rightshift */
655 1.1.1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
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.6 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.6 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.6 christos HOWTO (R_M32R_GNU_VTENTRY, /* type */
669 1.1.1.6 christos 0, /* rightshift */
670 1.1.1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
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.6 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.6 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 skrll HOWTO (R_M32R_16_RELA, /* type */
705 1.1 skrll 0, /* rightshift */
706 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_32_RELA, /* type */
720 1.1 skrll 0, /* rightshift */
721 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_24_RELA, /* type */
735 1.1 skrll 0, /* rightshift */
736 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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.6 christos HOWTO (R_M32R_10_PCREL_RELA, /* type */
749 1.1.1.6 christos 2, /* rightshift */
750 1.1.1.6 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
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.6 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 skrll 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 skrll HOWTO (R_M32R_18_PCREL_RELA, /* type */
764 1.1 skrll 2, /* rightshift */
765 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_26_PCREL_RELA, /* type */
779 1.1 skrll 2, /* rightshift */
780 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_HI16_ULO_RELA, /* type */
794 1.1 skrll 16, /* rightshift */
795 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_HI16_SLO_RELA, /* type */
809 1.1 skrll 16, /* rightshift */
810 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_LO16_RELA, /* type */
824 1.1 skrll 0, /* rightshift */
825 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_SDA16_RELA, /* type */
839 1.1 skrll 0, /* rightshift */
840 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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.6 christos HOWTO (R_M32R_RELA_GNU_VTINHERIT, /* type */
854 1.1.1.6 christos 0, /* rightshift */
855 1.1.1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
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.6 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.6 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.6 christos HOWTO (R_M32R_RELA_GNU_VTENTRY, /* type */
869 1.1.1.6 christos 0, /* rightshift */
870 1.1.1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
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.6 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.6 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 skrll HOWTO (R_M32R_REL32, /* type */
884 1.1 skrll 0, /* rightshift */
885 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc,/* special_function */
891 1.1 skrll "R_M32R_REL32", /* name */
892 1.1 skrll FALSE, /* partial_inplace */
893 1.1 skrll 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 skrll HOWTO (R_M32R_GOT24, /* type */
903 1.1 skrll 0, /* rightshift */
904 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc, /* special_function */
910 1.1 skrll "R_M32R_GOT24", /* name */
911 1.1 skrll FALSE, /* partial_inplace */
912 1.1 skrll 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 skrll HOWTO (R_M32R_26_PLTREL, /* type */
919 1.1 skrll 2, /* rightshift */
920 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_COPY, /* type */
938 1.1 skrll 0, /* rightshift */
939 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc, /* special_function */
945 1.1 skrll "R_M32R_COPY", /* name */
946 1.1 skrll FALSE, /* partial_inplace */
947 1.1 skrll 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 skrll HOWTO (R_M32R_GLOB_DAT, /* type */
954 1.1 skrll 0, /* rightshift */
955 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_JMP_SLOT, /* type */
969 1.1 skrll 0, /* rightshift */
970 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_RELATIVE, /* type */
986 1.1 skrll 0, /* rightshift */
987 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc, /* special_function */
993 1.1 skrll "R_M32R_RELATIVE", /* name */
994 1.1 skrll FALSE, /* partial_inplace */
995 1.1 skrll 0xffffffff, /* src_mask */
996 1.1 skrll 0xffffffff, /* dst_mask */
997 1.1 skrll FALSE), /* pcrel_offset */
998 1.1 skrll
999 1.1 skrll HOWTO (R_M32R_GOTOFF, /* type */
1000 1.1 skrll 0, /* rightshift */
1001 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc, /* special_function */
1007 1.1 skrll "R_M32R_GOTOFF", /* name */
1008 1.1 skrll FALSE, /* partial_inplace */
1009 1.1 skrll 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 skrll HOWTO (R_M32R_GOTPC24, /* type */
1016 1.1 skrll 0, /* rightshift */
1017 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll bfd_elf_generic_reloc, /* special_function */
1023 1.1 skrll "R_M32R_GOTPC24", /* name */
1024 1.1 skrll FALSE, /* partial_inplace */
1025 1.1 skrll 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 skrll HOWTO (R_M32R_GOT16_HI_ULO, /* type */
1032 1.1 skrll 16, /* rightshift */
1033 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_GOT16_HI_SLO, /* type */
1048 1.1 skrll 16, /* rightshift */
1049 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_GOT16_LO, /* type */
1064 1.1 skrll 0, /* rightshift */
1065 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_GOTPC_HI_ULO, /* type */
1081 1.1 skrll 16, /* rightshift */
1082 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_GOTPC_HI_SLO, /* type */
1098 1.1 skrll 16, /* rightshift */
1099 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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 skrll HOWTO (R_M32R_GOTPC_LO, /* type */
1115 1.1 skrll 0, /* rightshift */
1116 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 0x0000ffff, /* src_mask */
1125 1.1 skrll 0x0000ffff, /* dst_mask */
1126 1.1 skrll TRUE), /* pcrel_offset */
1127 1.1 skrll
1128 1.1 skrll HOWTO (R_M32R_GOTOFF_HI_ULO, /* type */
1129 1.1 skrll 16, /* rightshift */
1130 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 0x0000ffff, /* src_mask */
1139 1.1 skrll 0x0000ffff, /* dst_mask */
1140 1.1 skrll FALSE), /* pcrel_offset */
1141 1.1 skrll
1142 1.1 skrll HOWTO (R_M32R_GOTOFF_HI_SLO, /* type */
1143 1.1 skrll 16, /* rightshift */
1144 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 0x0000ffff, /* src_mask */
1153 1.1 skrll 0x0000ffff, /* dst_mask */
1154 1.1 skrll FALSE), /* pcrel_offset */
1155 1.1 skrll
1156 1.1 skrll HOWTO (R_M32R_GOTOFF_LO, /* type */
1157 1.1 skrll 0, /* rightshift */
1158 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
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 skrll 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 skrll 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.7 christos /* Set the howto pointer for an M32R ELF reloc. */
1276 1.1 skrll
1277 1.1 skrll static bfd_boolean
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.7 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.7 christos }
1293 1.1 skrll cache_ptr->howto = &m32r_elf_howto_table[r_type];
1294 1.1 skrll return TRUE;
1295 1.1.1.7 christos }
1296 1.1 skrll
1297 1.1 skrll static bfd_boolean
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.7 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.8 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 bfd_boolean
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 skrll if (strcmp (bfd_section_name (sec), ".scommon") == 0)
1329 1.1 skrll {
1330 1.1 skrll *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 skrll _SDA_BASE. This is what we use for the small common section. This
1341 1.1 skrll approach is copied from elf32-mips.c. */
1342 1.1 skrll static asection m32r_elf_scom_section;
1343 1.1 skrll static asymbol m32r_elf_scom_symbol;
1344 1.1 skrll static asymbol *m32r_elf_scom_symbol_ptr;
1345 1.1 skrll
1346 1.1 skrll /* Handle the special M32R section numbers that a symbol may use. */
1347 1.1 skrll
1348 1.1 skrll static void
1349 1.1 skrll _bfd_m32r_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
1350 1.1 skrll {
1351 1.1 skrll elf_symbol_type *elfsym = (elf_symbol_type *) asym;
1352 1.1 skrll
1353 1.1 skrll switch (elfsym->internal_elf_sym.st_shndx)
1354 1.1 skrll {
1355 1.1 skrll case SHN_M32R_SCOMMON:
1356 1.1 skrll if (m32r_elf_scom_section.name == NULL)
1357 1.1 skrll {
1358 1.1 skrll /* Initialize the small common section. */
1359 1.1 skrll m32r_elf_scom_section.name = ".scommon";
1360 1.1 skrll m32r_elf_scom_section.flags = SEC_IS_COMMON;
1361 1.1 skrll m32r_elf_scom_section.output_section = &m32r_elf_scom_section;
1362 1.1 skrll m32r_elf_scom_section.symbol = &m32r_elf_scom_symbol;
1363 1.1 skrll m32r_elf_scom_section.symbol_ptr_ptr = &m32r_elf_scom_symbol_ptr;
1364 1.1 skrll m32r_elf_scom_symbol.name = ".scommon";
1365 1.1 skrll m32r_elf_scom_symbol.flags = BSF_SECTION_SYM;
1366 1.1 skrll m32r_elf_scom_symbol.section = &m32r_elf_scom_section;
1367 1.1 skrll m32r_elf_scom_symbol_ptr = &m32r_elf_scom_symbol;
1368 1.1 skrll }
1369 1.1 skrll asym->section = &m32r_elf_scom_section;
1370 1.1 skrll asym->value = elfsym->internal_elf_sym.st_size;
1371 1.1 skrll break;
1372 1.1 skrll }
1373 1.1 skrll }
1374 1.1 skrll
1375 1.1 skrll /* Hook called by the linker routine which adds symbols from an object
1376 1.1 skrll file. We must handle the special M32R section numbers here.
1377 1.1 skrll We also keep watching for whether we need to create the sdata special
1378 1.1 skrll linker sections. */
1379 1.1 skrll
1380 1.1 skrll static bfd_boolean
1381 1.1 skrll m32r_elf_add_symbol_hook (bfd *abfd,
1382 1.1 skrll struct bfd_link_info *info,
1383 1.1 skrll Elf_Internal_Sym *sym,
1384 1.1 skrll const char **namep,
1385 1.1 skrll flagword *flagsp ATTRIBUTE_UNUSED,
1386 1.1.1.4 christos asection **secp,
1387 1.1 skrll bfd_vma *valp)
1388 1.1 skrll {
1389 1.1 skrll if (! bfd_link_relocatable (info)
1390 1.1 skrll && (*namep)[0] == '_' && (*namep)[1] == 'S'
1391 1.1 skrll && strcmp (*namep, "_SDA_BASE_") == 0
1392 1.1 skrll && is_elf_hash_table (info->hash))
1393 1.1 skrll {
1394 1.1 skrll /* This is simpler than using _bfd_elf_create_linker_section
1395 1.1 skrll (our needs are simpler than ppc's needs). Also
1396 1.1 skrll _bfd_elf_create_linker_section currently has a bug where if a .sdata
1397 1.1 skrll section already exists a new one is created that follows it which
1398 1.1 skrll screws of _SDA_BASE_ address calcs because output_offset != 0. */
1399 1.1 skrll struct elf_link_hash_entry *h;
1400 1.1 skrll struct bfd_link_hash_entry *bh;
1401 1.1 skrll asection *s = bfd_get_section_by_name (abfd, ".sdata");
1402 1.1 skrll
1403 1.1 skrll /* The following code was cobbled from elf32-ppc.c and elflink.c. */
1404 1.1 skrll if (s == NULL)
1405 1.1 skrll {
1406 1.1 skrll flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1407 1.1 skrll | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1408 1.1 skrll
1409 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".sdata",
1410 1.1.1.8 christos flags);
1411 1.1.1.4 christos if (s == NULL)
1412 1.1 skrll return FALSE;
1413 1.1 skrll if (!bfd_set_section_alignment (s, 2))
1414 1.1 skrll return FALSE;
1415 1.1 skrll }
1416 1.1 skrll
1417 1.1 skrll bh = bfd_link_hash_lookup (info->hash, "_SDA_BASE_",
1418 1.1 skrll FALSE, FALSE, FALSE);
1419 1.1 skrll
1420 1.1 skrll if ((bh == NULL || bh->type == bfd_link_hash_undefined)
1421 1.1 skrll && !(_bfd_generic_link_add_one_symbol (info,
1422 1.1 skrll abfd,
1423 1.1 skrll "_SDA_BASE_",
1424 1.1 skrll BSF_GLOBAL,
1425 1.1 skrll s,
1426 1.1 skrll (bfd_vma) 32768,
1427 1.1 skrll NULL,
1428 1.1 skrll FALSE,
1429 1.1 skrll get_elf_backend_data (abfd)->collect,
1430 1.1 skrll &bh)))
1431 1.1 skrll return FALSE;
1432 1.1 skrll h = (struct elf_link_hash_entry *) bh;
1433 1.1 skrll h->type = STT_OBJECT;
1434 1.1 skrll }
1435 1.1 skrll
1436 1.1 skrll switch (sym->st_shndx)
1437 1.1 skrll {
1438 1.1 skrll case SHN_M32R_SCOMMON:
1439 1.1 skrll *secp = bfd_make_section_old_way (abfd, ".scommon");
1440 1.1 skrll (*secp)->flags |= SEC_IS_COMMON;
1441 1.1 skrll *valp = sym->st_size;
1442 1.1 skrll break;
1443 1.1 skrll }
1444 1.1 skrll
1445 1.1 skrll return TRUE;
1446 1.1 skrll }
1447 1.1 skrll
1448 1.1 skrll /* We have to figure out the SDA_BASE value, so that we can adjust the
1449 1.1 skrll symbol value correctly. We look up the symbol _SDA_BASE_ in the output
1450 1.1 skrll BFD. If we can't find it, we're stuck. We cache it in the ELF
1451 1.1 skrll target data. We don't need to adjust the symbol value for an
1452 1.1 skrll external symbol if we are producing relocatable output. */
1453 1.1 skrll
1454 1.1 skrll static bfd_reloc_status_type
1455 1.1 skrll m32r_elf_final_sda_base (bfd *output_bfd,
1456 1.1 skrll struct bfd_link_info *info,
1457 1.1 skrll const char **error_message,
1458 1.1 skrll bfd_vma *psb)
1459 1.1 skrll {
1460 1.1 skrll if (elf_gp (output_bfd) == 0)
1461 1.1 skrll {
1462 1.1 skrll struct bfd_link_hash_entry *h;
1463 1.1 skrll
1464 1.1 skrll h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", FALSE, FALSE, TRUE);
1465 1.1 skrll if (h != NULL && h->type == bfd_link_hash_defined)
1466 1.1 skrll elf_gp (output_bfd) = (h->u.def.value
1467 1.1 skrll + h->u.def.section->output_section->vma
1468 1.1 skrll + h->u.def.section->output_offset);
1469 1.1 skrll else
1470 1.1 skrll {
1471 1.1 skrll /* Only get the error once. */
1472 1.1 skrll *psb = elf_gp (output_bfd) = 4;
1473 1.1 skrll *error_message =
1474 1.1 skrll (const char *) _("SDA relocation when _SDA_BASE_ not defined");
1475 1.1 skrll return bfd_reloc_dangerous;
1476 1.1 skrll }
1477 1.1 skrll }
1478 1.1 skrll *psb = elf_gp (output_bfd);
1479 1.1 skrll return bfd_reloc_ok;
1480 1.1 skrll }
1481 1.1 skrll
1482 1.1 skrll /* Return size of a PLT entry. */
1484 1.1 skrll #define elf_m32r_sizeof_plt(info) PLT_ENTRY_SIZE
1485 1.1 skrll
1486 1.1 skrll /* The m32r linker needs to keep track of the number of relocs that it
1487 1.1 skrll decides to copy in check_relocs for each symbol. This is so that
1488 1.1 skrll it can discard PC relative relocs if it doesn't need them when
1489 1.1 skrll linking with -Bsymbolic. We store the information in a field
1490 1.1 skrll extending the regular ELF linker hash table. */
1491 1.1 skrll
1492 1.1 skrll /* This structure keeps track of the number of PC relative relocs we
1493 1.1 skrll have copied for a given symbol. */
1494 1.1 skrll
1495 1.1 skrll struct elf_m32r_pcrel_relocs_copied
1496 1.1 skrll {
1497 1.1 skrll /* Next section. */
1498 1.1 skrll struct elf_m32r_pcrel_relocs_copied *next;
1499 1.1 skrll /* A section in dynobj. */
1500 1.1 skrll asection *section;
1501 1.1 skrll /* Number of relocs copied in this section. */
1502 1.1 skrll bfd_size_type count;
1503 1.1 skrll };
1504 1.1 skrll
1505 1.1 skrll /* m32r ELF linker hash entry. */
1506 1.1 skrll
1507 1.1 skrll struct elf_m32r_link_hash_entry
1508 1.1.1.6 christos {
1509 1.1 skrll struct elf_link_hash_entry root;
1510 1.1 skrll
1511 1.1 skrll /* Track dynamic relocs copied for this symbol. */
1512 1.1 skrll struct elf_dyn_relocs *dyn_relocs;
1513 1.1 skrll };
1514 1.1 skrll
1515 1.1 skrll /* m32r ELF linker hash table. */
1516 1.1 skrll
1517 1.1 skrll struct elf_m32r_link_hash_table
1518 1.1 skrll {
1519 1.1 skrll struct elf_link_hash_table root;
1520 1.1 skrll
1521 1.1.1.2 christos /* Short-cuts to get to dynamic linker sections. */
1522 1.1.1.2 christos asection *sdynbss;
1523 1.1 skrll asection *srelbss;
1524 1.1 skrll
1525 1.1 skrll /* Small local sym cache. */
1526 1.1 skrll struct sym_cache sym_cache;
1527 1.1 skrll };
1528 1.1 skrll
1529 1.1 skrll /* Traverse an m32r ELF linker hash table. */
1530 1.1 skrll
1531 1.1 skrll #define m32r_elf_link_hash_traverse(table, func, info) \
1532 1.1 skrll (elf_link_hash_traverse \
1533 1.1 skrll (&(table)->root, \
1534 1.1 skrll (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1535 1.1 skrll (info)))
1536 1.1.1.2 christos
1537 1.1.1.2 christos /* Get the m32r ELF linker hash table from a link_info structure. */
1538 1.1 skrll
1539 1.1 skrll #define m32r_elf_hash_table(p) \
1540 1.1 skrll (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1541 1.1 skrll == M32R_ELF_DATA ? ((struct elf_m32r_link_hash_table *) ((p)->hash)) : NULL)
1542 1.1 skrll
1543 1.1 skrll /* Create an entry in an m32r ELF linker hash table. */
1544 1.1 skrll
1545 1.1 skrll static struct bfd_hash_entry *
1546 1.1 skrll m32r_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
1547 1.1 skrll struct bfd_hash_table *table,
1548 1.1 skrll const char *string)
1549 1.1 skrll {
1550 1.1 skrll struct elf_m32r_link_hash_entry *ret =
1551 1.1 skrll (struct elf_m32r_link_hash_entry *) entry;
1552 1.1 skrll
1553 1.1 skrll /* Allocate the structure if it has not already been allocated by a
1554 1.1 skrll subclass. */
1555 1.1 skrll if (ret == NULL)
1556 1.1 skrll ret = bfd_hash_allocate (table,
1557 1.1 skrll sizeof (struct elf_m32r_link_hash_entry));
1558 1.1 skrll if (ret == NULL)
1559 1.1.1.6 christos return NULL;
1560 1.1.1.6 christos
1561 1.1 skrll /* Call the allocation method of the superclass. */
1562 1.1 skrll ret = ((struct elf_m32r_link_hash_entry *)
1563 1.1 skrll _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1564 1.1 skrll table, string));
1565 1.1 skrll if (ret != NULL)
1566 1.1 skrll {
1567 1.1 skrll struct elf_m32r_link_hash_entry *eh;
1568 1.1 skrll
1569 1.1 skrll eh = (struct elf_m32r_link_hash_entry *) ret;
1570 1.1 skrll eh->dyn_relocs = NULL;
1571 1.1 skrll }
1572 1.1 skrll
1573 1.1 skrll return (struct bfd_hash_entry *) ret;
1574 1.1 skrll }
1575 1.1 skrll
1576 1.1 skrll /* Create an m32r ELF linker hash table. */
1577 1.1 skrll
1578 1.1 skrll static struct bfd_link_hash_table *
1579 1.1 skrll m32r_elf_link_hash_table_create (bfd *abfd)
1580 1.1.1.4 christos {
1581 1.1 skrll struct elf_m32r_link_hash_table *ret;
1582 1.1 skrll bfd_size_type amt = sizeof (struct elf_m32r_link_hash_table);
1583 1.1 skrll
1584 1.1 skrll ret = bfd_zmalloc (amt);
1585 1.1 skrll if (ret == NULL)
1586 1.1.1.2 christos return NULL;
1587 1.1.1.2 christos
1588 1.1 skrll if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
1589 1.1 skrll m32r_elf_link_hash_newfunc,
1590 1.1 skrll sizeof (struct elf_m32r_link_hash_entry),
1591 1.1 skrll M32R_ELF_DATA))
1592 1.1 skrll {
1593 1.1 skrll free (ret);
1594 1.1 skrll return NULL;
1595 1.1 skrll }
1596 1.1 skrll
1597 1.1 skrll return &ret->root.root;
1598 1.1 skrll }
1599 1.1 skrll
1600 1.1 skrll /* Create dynamic sections when linking against a dynamic object. */
1601 1.1 skrll
1602 1.1 skrll static bfd_boolean
1603 1.1 skrll m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
1604 1.1 skrll {
1605 1.1 skrll struct elf_m32r_link_hash_table *htab;
1606 1.1 skrll flagword flags, pltflags;
1607 1.1 skrll asection *s;
1608 1.1.1.2 christos const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1609 1.1.1.2 christos int ptralign = 2; /* 32bit */
1610 1.1 skrll
1611 1.1 skrll htab = m32r_elf_hash_table (info);
1612 1.1 skrll if (htab == NULL)
1613 1.1 skrll return FALSE;
1614 1.1.1.6 christos
1615 1.1 skrll /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
1616 1.1 skrll .rel[a].bss sections. */
1617 1.1 skrll flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1618 1.1 skrll | SEC_LINKER_CREATED);
1619 1.1 skrll
1620 1.1 skrll pltflags = flags;
1621 1.1 skrll pltflags |= SEC_CODE;
1622 1.1 skrll if (bed->plt_not_loaded)
1623 1.1.1.3 christos pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
1624 1.1.1.6 christos if (bed->plt_readonly)
1625 1.1 skrll pltflags |= SEC_READONLY;
1626 1.1.1.8 christos
1627 1.1 skrll s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
1628 1.1 skrll htab->root.splt = s;
1629 1.1 skrll if (s == NULL
1630 1.1 skrll || !bfd_set_section_alignment (s, bed->plt_alignment))
1631 1.1 skrll return FALSE;
1632 1.1.1.6 christos
1633 1.1 skrll if (bed->want_plt_sym)
1634 1.1 skrll {
1635 1.1 skrll /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1636 1.1 skrll .plt section. */
1637 1.1.1.6 christos struct bfd_link_hash_entry *bh = NULL;
1638 1.1.1.6 christos struct elf_link_hash_entry *h;
1639 1.1.1.6 christos
1640 1.1.1.6 christos if (! (_bfd_generic_link_add_one_symbol
1641 1.1 skrll (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1642 1.1 skrll (bfd_vma) 0, NULL, FALSE,
1643 1.1 skrll get_elf_backend_data (abfd)->collect, &bh)))
1644 1.1 skrll return FALSE;
1645 1.1 skrll h = (struct elf_link_hash_entry *) bh;
1646 1.1.1.4 christos h->def_regular = 1;
1647 1.1.1.6 christos h->type = STT_OBJECT;
1648 1.1.1.6 christos htab->root.hplt = h;
1649 1.1 skrll
1650 1.1 skrll if (bfd_link_pic (info)
1651 1.1.1.3 christos && ! bfd_elf_link_record_dynamic_symbol (info, h))
1652 1.1.1.3 christos return FALSE;
1653 1.1.1.3 christos }
1654 1.1.1.3 christos
1655 1.1.1.6 christos s = bfd_make_section_anyway_with_flags (abfd,
1656 1.1 skrll bed->default_use_rela_p
1657 1.1.1.8 christos ? ".rela.plt" : ".rel.plt",
1658 1.1 skrll flags | SEC_READONLY);
1659 1.1 skrll htab->root.srelplt = s;
1660 1.1.1.6 christos if (s == NULL
1661 1.1.1.6 christos || !bfd_set_section_alignment (s, ptralign))
1662 1.1 skrll return FALSE;
1663 1.1 skrll
1664 1.1 skrll if (htab->root.sgot == NULL
1665 1.1 skrll && !_bfd_elf_create_got_section (abfd, info))
1666 1.1 skrll return FALSE;
1667 1.1.1.6 christos
1668 1.1.1.6 christos if (bed->want_dynbss)
1669 1.1.1.6 christos {
1670 1.1.1.6 christos /* The .dynbss section is a place to put symbols which are defined
1671 1.1.1.6 christos by dynamic objects, are referenced by regular objects, and are
1672 1.1.1.3 christos not functions. We must allocate space for them in the process
1673 1.1.1.3 christos image and use a R_*_COPY reloc to tell the dynamic linker to
1674 1.1 skrll initialize them at run time. The linker script puts the .dynbss
1675 1.1 skrll section into the .bss section of the final image. */
1676 1.1.1.6 christos s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
1677 1.1 skrll SEC_ALLOC | SEC_LINKER_CREATED);
1678 1.1.1.6 christos htab->sdynbss = s;
1679 1.1.1.6 christos if (s == NULL)
1680 1.1.1.6 christos return FALSE;
1681 1.1.1.6 christos /* The .rel[a].bss section holds copy relocs. This section is not
1682 1.1.1.6 christos normally needed. We need to create it here, though, so that the
1683 1.1.1.6 christos linker will map it to an output section. We can't just create it
1684 1.1.1.6 christos only if we need it, because we will not know whether we need it
1685 1.1.1.6 christos until we have seen all the input files, and the first time the
1686 1.1.1.6 christos main linker code calls BFD after examining all the input files
1687 1.1.1.6 christos (size_dynamic_sections) the input sections have already been
1688 1.1.1.4 christos mapped to the output sections. If the section turns out not to
1689 1.1.1.6 christos be needed, we can discard it later. We will never need this
1690 1.1.1.6 christos section when generating a shared object, since they do not use
1691 1.1.1.3 christos copy relocs. */
1692 1.1.1.3 christos if (! bfd_link_pic (info))
1693 1.1.1.3 christos {
1694 1.1.1.6 christos s = bfd_make_section_anyway_with_flags (abfd,
1695 1.1.1.6 christos (bed->default_use_rela_p
1696 1.1.1.8 christos ? ".rela.bss" : ".rel.bss"),
1697 1.1.1.6 christos flags | SEC_READONLY);
1698 1.1.1.6 christos htab->srelbss = s;
1699 1.1 skrll if (s == NULL
1700 1.1 skrll || !bfd_set_section_alignment (s, ptralign))
1701 1.1 skrll return FALSE;
1702 1.1 skrll }
1703 1.1 skrll }
1704 1.1 skrll
1705 1.1 skrll return TRUE;
1706 1.1 skrll }
1707 1.1 skrll
1708 1.1.1.6 christos /* Copy the extra info we tack onto an elf_link_hash_entry. */
1709 1.1.1.6 christos
1710 1.1 skrll static void
1711 1.1 skrll m32r_elf_copy_indirect_symbol (struct bfd_link_info *info,
1712 1.1 skrll struct elf_link_hash_entry *dir,
1713 1.1 skrll struct elf_link_hash_entry *ind)
1714 1.1 skrll {
1715 1.1 skrll struct elf_m32r_link_hash_entry * edir;
1716 1.1 skrll struct elf_m32r_link_hash_entry * eind;
1717 1.1 skrll
1718 1.1 skrll edir = (struct elf_m32r_link_hash_entry *) dir;
1719 1.1 skrll eind = (struct elf_m32r_link_hash_entry *) ind;
1720 1.1.1.6 christos
1721 1.1.1.6 christos if (eind->dyn_relocs != NULL)
1722 1.1.1.6 christos {
1723 1.1.1.6 christos if (edir->dyn_relocs != NULL)
1724 1.1.1.6 christos {
1725 1.1.1.6 christos struct elf_dyn_relocs **pp;
1726 1.1.1.6 christos struct elf_dyn_relocs *p;
1727 1.1.1.6 christos
1728 1.1.1.6 christos /* Add reloc counts against the indirect sym to the direct sym
1729 1.1.1.6 christos list. Merge any entries against the same section. */
1730 1.1.1.6 christos for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
1731 1.1.1.6 christos {
1732 1.1.1.6 christos struct elf_dyn_relocs *q;
1733 1.1.1.6 christos
1734 1.1.1.6 christos for (q = edir->dyn_relocs; q != NULL; q = q->next)
1735 1.1.1.6 christos if (q->sec == p->sec)
1736 1.1.1.6 christos {
1737 1.1.1.6 christos q->pc_count += p->pc_count;
1738 1.1.1.6 christos q->count += p->count;
1739 1.1.1.6 christos *pp = p->next;
1740 1.1.1.6 christos break;
1741 1.1.1.6 christos }
1742 1.1.1.6 christos if (q == NULL)
1743 1.1 skrll pp = &p->next;
1744 1.1 skrll }
1745 1.1 skrll *pp = edir->dyn_relocs;
1746 1.1 skrll }
1747 1.1 skrll
1748 1.1 skrll edir->dyn_relocs = eind->dyn_relocs;
1749 1.1 skrll eind->dyn_relocs = NULL;
1750 1.1 skrll }
1751 1.1 skrll
1752 1.1.1.6 christos _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1753 1.1.1.6 christos }
1754 1.1.1.6 christos
1755 1.1.1.6 christos
1756 1.1.1.6 christos /* Find dynamic relocs for H that apply to read-only sections. */
1758 1.1.1.6 christos
1759 1.1.1.6 christos static asection *
1760 1.1.1.6 christos readonly_dynrelocs (struct elf_link_hash_entry *h)
1761 1.1.1.6 christos {
1762 1.1.1.6 christos struct elf_dyn_relocs *p;
1763 1.1.1.6 christos struct elf_m32r_link_hash_entry *eh = (struct elf_m32r_link_hash_entry *) h;
1764 1.1.1.6 christos
1765 1.1.1.6 christos for (p = eh->dyn_relocs; p != NULL; p = p->next)
1766 1.1.1.6 christos {
1767 1.1.1.6 christos asection *s = p->sec->output_section;
1768 1.1.1.6 christos
1769 1.1.1.6 christos if (s != NULL && (s->flags & SEC_READONLY) != 0)
1770 1.1 skrll return p->sec;
1771 1.1 skrll }
1772 1.1 skrll return NULL;
1773 1.1 skrll }
1774 1.1 skrll
1775 1.1 skrll /* Adjust a symbol defined by a dynamic object and referenced by a
1776 1.1 skrll regular object. The current definition is in some section of the
1777 1.1 skrll dynamic object, but we're not including those sections. We have to
1778 1.1 skrll change the definition to something the rest of the link can
1779 1.1 skrll understand. */
1780 1.1 skrll
1781 1.1 skrll static bfd_boolean
1782 1.1 skrll m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1783 1.1 skrll struct elf_link_hash_entry *h)
1784 1.1 skrll {
1785 1.1 skrll struct elf_m32r_link_hash_table *htab;
1786 1.1 skrll bfd *dynobj;
1787 1.1 skrll asection *s;
1788 1.1 skrll
1789 1.1 skrll #ifdef DEBUG_PIC
1790 1.1 skrll printf ("m32r_elf_adjust_dynamic_symbol()\n");
1791 1.1 skrll #endif
1792 1.1.1.6 christos
1793 1.1.1.6 christos dynobj = elf_hash_table (info)->dynobj;
1794 1.1.1.6 christos
1795 1.1.1.6 christos /* Make sure we know what is going on here. */
1796 1.1.1.6 christos BFD_ASSERT (dynobj != NULL
1797 1.1 skrll && (h->needs_plt
1798 1.1 skrll || h->is_weakalias
1799 1.1 skrll || (h->def_dynamic
1800 1.1 skrll && h->ref_regular
1801 1.1 skrll && !h->def_regular)));
1802 1.1 skrll
1803 1.1 skrll /* If this is a function, put it in the procedure linkage table. We
1804 1.1.1.4 christos will fill in the contents of the procedure linkage table later,
1805 1.1.1.6 christos when we know the address of the .got section. */
1806 1.1.1.6 christos if (h->type == STT_FUNC
1807 1.1 skrll || h->needs_plt)
1808 1.1 skrll {
1809 1.1.1.6 christos if (! bfd_link_pic (info)
1810 1.1.1.6 christos && !h->def_dynamic
1811 1.1.1.6 christos && !h->ref_dynamic
1812 1.1.1.6 christos && h->root.type != bfd_link_hash_undefweak
1813 1.1.1.6 christos && h->root.type != bfd_link_hash_undefined)
1814 1.1.1.6 christos {
1815 1.1.1.6 christos /* This case can occur if we saw a PLT reloc in an input
1816 1.1.1.6 christos file, but the symbol was never referred to by a dynamic
1817 1.1.1.6 christos object. In such a case, we don't actually need to build
1818 1.1 skrll a procedure linkage table, and we can just do a PCREL
1819 1.1 skrll reloc instead. */
1820 1.1 skrll h->plt.offset = (bfd_vma) -1;
1821 1.1 skrll h->needs_plt = 0;
1822 1.1 skrll }
1823 1.1 skrll
1824 1.1 skrll return TRUE;
1825 1.1 skrll }
1826 1.1 skrll else
1827 1.1.1.6 christos h->plt.offset = (bfd_vma) -1;
1828 1.1 skrll
1829 1.1.1.6 christos /* If this is a weak symbol, and there is a real definition, the
1830 1.1.1.6 christos processor independent code will have arranged for us to see the
1831 1.1.1.6 christos real definition first, and we can just use the same value. */
1832 1.1.1.6 christos if (h->is_weakalias)
1833 1.1 skrll {
1834 1.1 skrll struct elf_link_hash_entry *def = weakdef (h);
1835 1.1 skrll BFD_ASSERT (def->root.type == bfd_link_hash_defined);
1836 1.1 skrll h->root.u.def.section = def->root.u.def.section;
1837 1.1 skrll h->root.u.def.value = def->root.u.def.value;
1838 1.1 skrll return TRUE;
1839 1.1 skrll }
1840 1.1 skrll
1841 1.1 skrll /* This is a reference to a symbol defined by a dynamic object which
1842 1.1 skrll is not a function. */
1843 1.1.1.4 christos
1844 1.1 skrll /* If we are creating a shared library, we must presume that the
1845 1.1 skrll only references to the symbol are via the global offset table.
1846 1.1 skrll For such cases we need not do anything here; the relocations will
1847 1.1 skrll be handled correctly by relocate_section. */
1848 1.1 skrll if (bfd_link_pic (info))
1849 1.1 skrll return TRUE;
1850 1.1 skrll
1851 1.1 skrll /* If there are no references to this symbol that do not use the
1852 1.1.1.6 christos GOT, we don't need to generate a copy reloc. */
1853 1.1 skrll if (!h->non_got_ref)
1854 1.1 skrll return TRUE;
1855 1.1 skrll
1856 1.1 skrll /* If -z nocopyreloc was given, we won't generate them either. */
1857 1.1 skrll if (0 && info->nocopyreloc)
1858 1.1.1.6 christos {
1859 1.1.1.6 christos h->non_got_ref = 0;
1860 1.1.1.6 christos return TRUE;
1861 1.1 skrll }
1862 1.1 skrll
1863 1.1 skrll /* If we don't find any dynamic relocs in read-only sections, then
1864 1.1 skrll we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1865 1.1 skrll if (0 && !readonly_dynrelocs (h))
1866 1.1 skrll {
1867 1.1 skrll h->non_got_ref = 0;
1868 1.1 skrll return TRUE;
1869 1.1 skrll }
1870 1.1 skrll
1871 1.1 skrll /* We must allocate the symbol in our .dynbss section, which will
1872 1.1 skrll become part of the .bss section of the executable. There will be
1873 1.1 skrll an entry for this symbol in the .dynsym section. The dynamic
1874 1.1 skrll object will contain position independent code, so all references
1875 1.1 skrll from the dynamic object to this symbol will go through the global
1876 1.1 skrll offset table. The dynamic linker will use the .dynsym entry to
1877 1.1.1.2 christos determine the address it must put in the global offset table, so
1878 1.1.1.2 christos both the dynamic object and the regular object will refer to the
1879 1.1.1.2 christos same memory location for the variable. */
1880 1.1 skrll
1881 1.1 skrll htab = m32r_elf_hash_table (info);
1882 1.1 skrll if (htab == NULL)
1883 1.1 skrll return FALSE;
1884 1.1 skrll
1885 1.1 skrll s = htab->sdynbss;
1886 1.1 skrll BFD_ASSERT (s != NULL);
1887 1.1.1.3 christos
1888 1.1 skrll /* We must generate a R_M32R_COPY reloc to tell the dynamic linker
1889 1.1 skrll to copy the initial value out of the dynamic object and into the
1890 1.1 skrll runtime process image. We need to remember the offset into the
1891 1.1 skrll .rela.bss section we are going to use. */
1892 1.1 skrll if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
1893 1.1 skrll {
1894 1.1 skrll asection *srel;
1895 1.1 skrll
1896 1.1 skrll srel = htab->srelbss;
1897 1.1.1.4 christos BFD_ASSERT (srel != NULL);
1898 1.1 skrll srel->size += sizeof (Elf32_External_Rela);
1899 1.1 skrll h->needs_copy = 1;
1900 1.1 skrll }
1901 1.1 skrll
1902 1.1 skrll return _bfd_elf_adjust_dynamic_copy (info, h, s);
1903 1.1 skrll }
1904 1.1 skrll
1905 1.1 skrll /* Allocate space in .plt, .got and associated reloc sections for
1906 1.1 skrll dynamic relocs. */
1907 1.1 skrll
1908 1.1 skrll static bfd_boolean
1909 1.1.1.6 christos allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1910 1.1 skrll {
1911 1.1 skrll struct bfd_link_info *info;
1912 1.1 skrll struct elf_m32r_link_hash_table *htab;
1913 1.1 skrll struct elf_m32r_link_hash_entry *eh;
1914 1.1 skrll struct elf_dyn_relocs *p;
1915 1.1 skrll
1916 1.1.1.2 christos if (h->root.type == bfd_link_hash_indirect)
1917 1.1.1.2 christos return TRUE;
1918 1.1 skrll
1919 1.1 skrll info = (struct bfd_link_info *) inf;
1920 1.1 skrll htab = m32r_elf_hash_table (info);
1921 1.1 skrll if (htab == NULL)
1922 1.1 skrll return FALSE;
1923 1.1 skrll
1924 1.1 skrll eh = (struct elf_m32r_link_hash_entry *) h;
1925 1.1.1.6 christos
1926 1.1 skrll if (htab->root.dynamic_sections_created
1927 1.1.1.6 christos && h->plt.refcount > 0)
1928 1.1.1.6 christos {
1929 1.1.1.6 christos /* Make sure this symbol is output as a dynamic symbol.
1930 1.1.1.6 christos Undefined weak syms won't yet be marked as dynamic. */
1931 1.1.1.6 christos if (h->dynindx == -1
1932 1.1 skrll && !h->forced_local)
1933 1.1.1.4 christos {
1934 1.1.1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
1935 1.1.1.6 christos return FALSE;
1936 1.1.1.6 christos }
1937 1.1.1.6 christos
1938 1.1.1.6 christos if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
1939 1.1.1.6 christos {
1940 1.1.1.6 christos asection *s = htab->root.splt;
1941 1.1.1.6 christos
1942 1.1.1.6 christos /* If this is the first .plt entry, make room for the special
1943 1.1.1.6 christos first entry. */
1944 1.1.1.6 christos if (s->size == 0)
1945 1.1.1.6 christos s->size += PLT_ENTRY_SIZE;
1946 1.1.1.6 christos
1947 1.1.1.6 christos h->plt.offset = s->size;
1948 1.1.1.6 christos
1949 1.1.1.6 christos /* If this symbol is not defined in a regular file, and we are
1950 1.1.1.6 christos not generating a shared library, then set the symbol to this
1951 1.1.1.6 christos location in the .plt. This is required to make function
1952 1.1.1.6 christos pointers compare as equal between the normal executable and
1953 1.1.1.6 christos the shared library. */
1954 1.1.1.6 christos if (! bfd_link_pic (info)
1955 1.1.1.6 christos && !h->def_regular)
1956 1.1.1.6 christos {
1957 1.1.1.6 christos h->root.u.def.section = s;
1958 1.1 skrll h->root.u.def.value = h->plt.offset;
1959 1.1.1.6 christos }
1960 1.1.1.6 christos
1961 1.1.1.6 christos /* Make room for this entry. */
1962 1.1.1.6 christos s->size += PLT_ENTRY_SIZE;
1963 1.1.1.6 christos
1964 1.1.1.6 christos /* We also need to make an entry in the .got.plt section, which
1965 1.1.1.6 christos will be placed in the .got section by the linker script. */
1966 1.1 skrll htab->root.sgotplt->size += 4;
1967 1.1.1.6 christos
1968 1.1.1.6 christos /* We also need to make an entry in the .rel.plt section. */
1969 1.1.1.6 christos htab->root.srelplt->size += sizeof (Elf32_External_Rela);
1970 1.1.1.6 christos }
1971 1.1 skrll else
1972 1.1 skrll {
1973 1.1 skrll h->plt.offset = (bfd_vma) -1;
1974 1.1 skrll h->needs_plt = 0;
1975 1.1 skrll }
1976 1.1 skrll }
1977 1.1 skrll else
1978 1.1 skrll {
1979 1.1 skrll h->plt.offset = (bfd_vma) -1;
1980 1.1 skrll h->needs_plt = 0;
1981 1.1 skrll }
1982 1.1 skrll
1983 1.1 skrll if (h->got.refcount > 0)
1984 1.1.1.6 christos {
1985 1.1 skrll asection *s;
1986 1.1.1.6 christos bfd_boolean dyn;
1987 1.1.1.6 christos
1988 1.1.1.6 christos /* Make sure this symbol is output as a dynamic symbol.
1989 1.1.1.6 christos Undefined weak syms won't yet be marked as dynamic. */
1990 1.1.1.6 christos if (h->dynindx == -1
1991 1.1 skrll && !h->forced_local)
1992 1.1.1.6 christos {
1993 1.1 skrll if (! bfd_elf_link_record_dynamic_symbol (info, h))
1994 1.1 skrll return FALSE;
1995 1.1 skrll }
1996 1.1 skrll
1997 1.1.1.4 christos s = htab->root.sgot;
1998 1.1.1.6 christos
1999 1.1 skrll h->got.offset = s->size;
2000 1.1 skrll s->size += 4;
2001 1.1 skrll dyn = htab->root.dynamic_sections_created;
2002 1.1 skrll if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
2003 1.1 skrll htab->root.srelgot->size += sizeof (Elf32_External_Rela);
2004 1.1 skrll }
2005 1.1 skrll else
2006 1.1 skrll h->got.offset = (bfd_vma) -1;
2007 1.1 skrll
2008 1.1 skrll if (eh->dyn_relocs == NULL)
2009 1.1 skrll return TRUE;
2010 1.1 skrll
2011 1.1 skrll /* In the shared -Bsymbolic case, discard space allocated for
2012 1.1.1.4 christos dynamic pc-relative relocs against symbols which turn out to be
2013 1.1 skrll defined in regular objects. For the normal shared case, discard
2014 1.1 skrll space for pc-relative relocs that have become local due to symbol
2015 1.1.1.6 christos visibility changes. */
2016 1.1.1.6 christos
2017 1.1.1.6 christos if (bfd_link_pic (info))
2018 1.1.1.6 christos {
2019 1.1.1.6 christos if (h->def_regular
2020 1.1.1.6 christos && (h->forced_local
2021 1.1.1.6 christos || info->symbolic))
2022 1.1.1.6 christos {
2023 1.1.1.6 christos struct elf_dyn_relocs **pp;
2024 1.1.1.6 christos
2025 1.1.1.6 christos for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
2026 1.1.1.6 christos {
2027 1.1.1.6 christos p->count -= p->pc_count;
2028 1.1.1.6 christos p->pc_count = 0;
2029 1.1.1.6 christos if (p->count == 0)
2030 1.1 skrll *pp = p->next;
2031 1.1 skrll else
2032 1.1 skrll pp = &p->next;
2033 1.1 skrll }
2034 1.1 skrll }
2035 1.1 skrll
2036 1.1 skrll /* Also discard relocs on undefined weak syms with non-default
2037 1.1 skrll visibility. */
2038 1.1 skrll if (eh->dyn_relocs != NULL
2039 1.1 skrll && h->root.type == bfd_link_hash_undefweak)
2040 1.1 skrll {
2041 1.1 skrll if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2042 1.1 skrll eh->dyn_relocs = NULL;
2043 1.1 skrll
2044 1.1 skrll /* Make sure undefined weak symbols are output as a dynamic
2045 1.1 skrll symbol in PIEs. */
2046 1.1 skrll else if (h->dynindx == -1
2047 1.1 skrll && !h->forced_local)
2048 1.1 skrll {
2049 1.1 skrll if (! bfd_elf_link_record_dynamic_symbol (info, h))
2050 1.1 skrll return FALSE;
2051 1.1 skrll }
2052 1.1.1.6 christos }
2053 1.1.1.6 christos }
2054 1.1 skrll else
2055 1.1 skrll {
2056 1.1.1.6 christos /* For the non-shared case, discard space for relocs against
2057 1.1.1.6 christos symbols which turn out to need copy relocs or are not
2058 1.1.1.6 christos dynamic. */
2059 1.1.1.6 christos
2060 1.1.1.6 christos if (!h->non_got_ref
2061 1.1.1.6 christos && ((h->def_dynamic
2062 1.1.1.6 christos && !h->def_regular)
2063 1.1.1.6 christos || (htab->root.dynamic_sections_created
2064 1.1.1.6 christos && (h->root.type == bfd_link_hash_undefweak
2065 1.1.1.6 christos || h->root.type == bfd_link_hash_undefined))))
2066 1.1.1.6 christos {
2067 1.1.1.6 christos /* Make sure this symbol is output as a dynamic symbol.
2068 1.1.1.6 christos Undefined weak syms won't yet be marked as dynamic. */
2069 1.1.1.6 christos if (h->dynindx == -1
2070 1.1.1.6 christos && !h->forced_local)
2071 1.1.1.6 christos {
2072 1.1.1.6 christos if (! bfd_elf_link_record_dynamic_symbol (info, h))
2073 1.1.1.6 christos return FALSE;
2074 1.1.1.6 christos }
2075 1.1.1.6 christos
2076 1.1 skrll /* If that succeeded, we know we'll be keeping all the
2077 1.1 skrll relocs. */
2078 1.1 skrll if (h->dynindx != -1)
2079 1.1 skrll goto keep;
2080 1.1 skrll }
2081 1.1 skrll
2082 1.1 skrll eh->dyn_relocs = NULL;
2083 1.1 skrll
2084 1.1 skrll keep: ;
2085 1.1 skrll }
2086 1.1 skrll
2087 1.1 skrll /* Finally, allocate space. */
2088 1.1 skrll for (p = eh->dyn_relocs; p != NULL; p = p->next)
2089 1.1 skrll {
2090 1.1 skrll asection *sreloc = elf_section_data (p->sec)->sreloc;
2091 1.1 skrll sreloc->size += p->count * sizeof (Elf32_External_Rela);
2092 1.1.1.6 christos }
2093 1.1.1.6 christos
2094 1.1 skrll return TRUE;
2095 1.1 skrll }
2096 1.1.1.6 christos
2097 1.1 skrll /* Set DF_TEXTREL if we find any dynamic relocs that apply to
2098 1.1.1.6 christos read-only sections. */
2099 1.1 skrll
2100 1.1.1.6 christos static bfd_boolean
2101 1.1.1.6 christos maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
2102 1.1 skrll {
2103 1.1.1.6 christos asection *sec;
2104 1.1.1.6 christos
2105 1.1.1.6 christos if (h->root.type == bfd_link_hash_indirect)
2106 1.1.1.6 christos return TRUE;
2107 1.1 skrll
2108 1.1.1.6 christos sec = readonly_dynrelocs (h);
2109 1.1.1.6 christos if (sec != NULL)
2110 1.1.1.7 christos {
2111 1.1.1.6 christos struct bfd_link_info *info = (struct bfd_link_info *) info_p;
2112 1.1 skrll
2113 1.1.1.6 christos info->flags |= DF_TEXTREL;
2114 1.1.1.6 christos info->callbacks->minfo
2115 1.1 skrll (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
2116 1.1 skrll sec->owner, h->root.root.string, sec);
2117 1.1 skrll
2118 1.1 skrll /* Not an error, just cut short the traversal. */
2119 1.1 skrll return FALSE;
2120 1.1 skrll }
2121 1.1 skrll return TRUE;
2122 1.1 skrll }
2123 1.1 skrll
2124 1.1 skrll /* Set the sizes of the dynamic sections. */
2125 1.1 skrll
2126 1.1 skrll static bfd_boolean
2127 1.1 skrll m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2128 1.1 skrll struct bfd_link_info *info)
2129 1.1 skrll {
2130 1.1 skrll struct elf_m32r_link_hash_table *htab;
2131 1.1 skrll bfd *dynobj;
2132 1.1 skrll asection *s;
2133 1.1 skrll bfd_boolean relocs;
2134 1.1 skrll bfd *ibfd;
2135 1.1 skrll
2136 1.1.1.2 christos #ifdef DEBUG_PIC
2137 1.1.1.2 christos printf ("m32r_elf_size_dynamic_sections()\n");
2138 1.1.1.2 christos #endif
2139 1.1 skrll
2140 1.1 skrll htab = m32r_elf_hash_table (info);
2141 1.1 skrll if (htab == NULL)
2142 1.1 skrll return FALSE;
2143 1.1 skrll
2144 1.1 skrll dynobj = htab->root.dynobj;
2145 1.1.1.4 christos BFD_ASSERT (dynobj != NULL);
2146 1.1 skrll
2147 1.1.1.3 christos if (htab->root.dynamic_sections_created)
2148 1.1 skrll {
2149 1.1 skrll /* Set the contents of the .interp section to the interpreter. */
2150 1.1 skrll if (bfd_link_executable (info) && !info->nointerp)
2151 1.1 skrll {
2152 1.1 skrll s = bfd_get_linker_section (dynobj, ".interp");
2153 1.1 skrll BFD_ASSERT (s != NULL);
2154 1.1 skrll s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2155 1.1 skrll s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2156 1.1.1.4 christos }
2157 1.1 skrll }
2158 1.1 skrll
2159 1.1 skrll /* Set up .got offsets for local syms, and space for local dynamic
2160 1.1 skrll relocs. */
2161 1.1 skrll for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2162 1.1 skrll {
2163 1.1 skrll bfd_signed_vma *local_got;
2164 1.1 skrll bfd_signed_vma *end_local_got;
2165 1.1.1.6 christos bfd_size_type locsymcount;
2166 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
2167 1.1 skrll asection *srel;
2168 1.1.1.6 christos
2169 1.1.1.6 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2170 1.1 skrll continue;
2171 1.1.1.6 christos
2172 1.1.1.6 christos for (s = ibfd->sections; s != NULL; s = s->next)
2173 1.1.1.6 christos {
2174 1.1.1.6 christos struct elf_dyn_relocs *p;
2175 1.1.1.6 christos
2176 1.1.1.6 christos for (p = ((struct elf_dyn_relocs *)
2177 1.1.1.6 christos elf_section_data (s)->local_dynrel);
2178 1.1.1.6 christos p != NULL;
2179 1.1.1.6 christos p = p->next)
2180 1.1.1.6 christos {
2181 1.1.1.6 christos if (! bfd_is_abs_section (p->sec)
2182 1.1.1.6 christos && bfd_is_abs_section (p->sec->output_section))
2183 1.1.1.6 christos {
2184 1.1.1.6 christos /* Input section has been discarded, either because
2185 1.1.1.6 christos it is a copy of a linkonce section or due to
2186 1.1.1.6 christos linker script /DISCARD/, so we'll be discarding
2187 1.1.1.6 christos the relocs too. */
2188 1.1.1.6 christos }
2189 1.1.1.6 christos else if (p->count != 0)
2190 1.1.1.6 christos {
2191 1.1.1.6 christos srel = elf_section_data (p->sec)->sreloc;
2192 1.1.1.6 christos srel->size += p->count * sizeof (Elf32_External_Rela);
2193 1.1 skrll if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2194 1.1 skrll info->flags |= DF_TEXTREL;
2195 1.1 skrll }
2196 1.1.1.6 christos }
2197 1.1 skrll }
2198 1.1 skrll
2199 1.1 skrll local_got = elf_local_got_refcounts (ibfd);
2200 1.1 skrll if (!local_got)
2201 1.1.1.6 christos continue;
2202 1.1.1.6 christos
2203 1.1 skrll symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2204 1.1.1.6 christos locsymcount = symtab_hdr->sh_info;
2205 1.1.1.6 christos end_local_got = local_got + locsymcount;
2206 1.1.1.6 christos s = htab->root.sgot;
2207 1.1.1.6 christos srel = htab->root.srelgot;
2208 1.1.1.6 christos for (; local_got < end_local_got; ++local_got)
2209 1.1.1.6 christos {
2210 1.1.1.6 christos if (*local_got > 0)
2211 1.1.1.6 christos {
2212 1.1.1.6 christos *local_got = s->size;
2213 1.1.1.6 christos s->size += 4;
2214 1.1.1.6 christos if (bfd_link_pic (info))
2215 1.1 skrll srel->size += sizeof (Elf32_External_Rela);
2216 1.1 skrll }
2217 1.1 skrll else
2218 1.1 skrll *local_got = (bfd_vma) -1;
2219 1.1 skrll }
2220 1.1 skrll }
2221 1.1 skrll
2222 1.1 skrll /* Allocate global sym .plt and .got entries, and space for global
2223 1.1 skrll sym dynamic relocs. */
2224 1.1 skrll elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
2225 1.1 skrll
2226 1.1 skrll /* We now have determined the sizes of the various dynamic sections.
2227 1.1.1.6 christos Allocate memory for them. */
2228 1.1 skrll relocs = FALSE;
2229 1.1.1.6 christos for (s = dynobj->sections; s != NULL; s = s->next)
2230 1.1.1.6 christos {
2231 1.1.1.6 christos if ((s->flags & SEC_LINKER_CREATED) == 0)
2232 1.1 skrll continue;
2233 1.1.1.6 christos
2234 1.1.1.6 christos if (s == htab->root.splt
2235 1.1.1.6 christos || s == htab->root.sgot
2236 1.1.1.6 christos || s == htab->root.sgotplt
2237 1.1.1.8 christos || s == htab->sdynbss)
2238 1.1.1.6 christos {
2239 1.1.1.6 christos /* Strip this section if we don't need it; see the
2240 1.1.1.6 christos comment below. */
2241 1.1.1.6 christos }
2242 1.1.1.6 christos else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
2243 1.1.1.6 christos {
2244 1.1.1.6 christos if (s->size != 0 && s != htab->root.srelplt)
2245 1.1.1.6 christos relocs = TRUE;
2246 1.1 skrll
2247 1.1 skrll /* We use the reloc_count field as a counter if we need
2248 1.1 skrll to copy relocs into the output file. */
2249 1.1 skrll s->reloc_count = 0;
2250 1.1 skrll }
2251 1.1.1.6 christos else
2252 1.1.1.6 christos /* It's not one of our sections, so don't allocate space. */
2253 1.1.1.6 christos continue;
2254 1.1.1.6 christos
2255 1.1.1.6 christos if (s->size == 0)
2256 1.1.1.6 christos {
2257 1.1.1.6 christos /* If we don't need this section, strip it from the
2258 1.1.1.6 christos output file. This is mostly to handle .rela.bss and
2259 1.1.1.6 christos .rela.plt. We must create both sections in
2260 1.1.1.6 christos create_dynamic_sections, because they must be created
2261 1.1.1.6 christos before the linker maps input sections to output
2262 1.1.1.6 christos sections. The linker does that before
2263 1.1.1.6 christos adjust_dynamic_symbol is called, and it is that
2264 1.1 skrll function which decides whether anything needs to go
2265 1.1 skrll into these sections. */
2266 1.1 skrll s->flags |= SEC_EXCLUDE;
2267 1.1 skrll continue;
2268 1.1 skrll }
2269 1.1.1.6 christos
2270 1.1.1.6 christos if ((s->flags & SEC_HAS_CONTENTS) == 0)
2271 1.1.1.6 christos continue;
2272 1.1.1.6 christos
2273 1.1 skrll /* Allocate memory for the section contents. We use bfd_zalloc
2274 1.1 skrll here in case unused entries are not reclaimed before the
2275 1.1.1.6 christos section's contents are written out. This should not happen,
2276 1.1 skrll but this way if it does, we get a R_M32R_NONE reloc instead
2277 1.1 skrll of garbage. */
2278 1.1 skrll s->contents = bfd_zalloc (dynobj, s->size);
2279 1.1 skrll if (s->contents == NULL)
2280 1.1 skrll return FALSE;
2281 1.1 skrll }
2282 1.1 skrll
2283 1.1 skrll if (htab->root.dynamic_sections_created)
2284 1.1 skrll {
2285 1.1 skrll /* Add some entries to the .dynamic section. We fill in the
2286 1.1 skrll values later, in m32r_elf_finish_dynamic_sections, but we
2287 1.1 skrll must add the entries now so that we get the correct size for
2288 1.1.1.4 christos the .dynamic section. The DT_DEBUG entry is filled in by the
2289 1.1 skrll dynamic linker and used by the debugger. */
2290 1.1 skrll #define add_dynamic_entry(TAG, VAL) \
2291 1.1 skrll _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2292 1.1 skrll
2293 1.1 skrll if (bfd_link_executable (info))
2294 1.1.1.6 christos {
2295 1.1.1.6 christos if (! add_dynamic_entry (DT_DEBUG, 0))
2296 1.1.1.6 christos return FALSE;
2297 1.1.1.6 christos }
2298 1.1.1.6 christos
2299 1.1.1.6 christos if (htab->root.splt->size != 0)
2300 1.1.1.6 christos {
2301 1.1.1.6 christos if (! add_dynamic_entry (DT_PLTGOT, 0)
2302 1.1 skrll || ! add_dynamic_entry (DT_PLTRELSZ, 0)
2303 1.1 skrll || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
2304 1.1.1.6 christos || ! add_dynamic_entry (DT_JMPREL, 0))
2305 1.1.1.6 christos return FALSE;
2306 1.1.1.6 christos }
2307 1.1.1.6 christos
2308 1.1.1.6 christos if (relocs)
2309 1.1.1.6 christos {
2310 1.1.1.6 christos if (! add_dynamic_entry (DT_RELA, 0)
2311 1.1.1.6 christos || ! add_dynamic_entry (DT_RELASZ, 0)
2312 1.1.1.6 christos || ! add_dynamic_entry (DT_RELAENT,
2313 1.1.1.6 christos sizeof (Elf32_External_Rela)))
2314 1.1.1.6 christos return FALSE;
2315 1.1.1.6 christos
2316 1.1.1.6 christos /* If any dynamic relocs apply to a read-only section,
2317 1.1.1.6 christos then we need a DT_TEXTREL entry. */
2318 1.1.1.6 christos if ((info->flags & DF_TEXTREL) == 0)
2319 1.1.1.6 christos elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
2320 1.1.1.6 christos
2321 1.1.1.6 christos if ((info->flags & DF_TEXTREL) != 0)
2322 1.1 skrll {
2323 1.1 skrll if (! add_dynamic_entry (DT_TEXTREL, 0))
2324 1.1 skrll return FALSE;
2325 1.1 skrll }
2326 1.1 skrll }
2327 1.1 skrll }
2328 1.1 skrll #undef add_dynamic_entry
2329 1.1 skrll
2330 1.1 skrll return TRUE;
2331 1.1 skrll }
2332 1.1 skrll
2333 1.1 skrll /* Relocate an M32R/D ELF section.
2334 1.1 skrll There is some attempt to make this function usable for many architectures,
2335 1.1 skrll both for RELA and REL type relocs, if only to serve as a learning tool.
2336 1.1 skrll
2337 1.1 skrll The RELOCATE_SECTION function is called by the new ELF backend linker
2338 1.1 skrll to handle the relocations for a section.
2339 1.1 skrll
2340 1.1 skrll The relocs are always passed as Rela structures; if the section
2341 1.1 skrll actually uses Rel structures, the r_addend field will always be
2342 1.1 skrll zero.
2343 1.1 skrll
2344 1.1 skrll This function is responsible for adjust the section contents as
2345 1.1 skrll necessary, and (if using Rela relocs and generating a
2346 1.1 skrll relocatable output file) adjusting the reloc addend as
2347 1.1 skrll necessary.
2348 1.1 skrll
2349 1.1 skrll This function does not have to worry about setting the reloc
2350 1.1 skrll address or the reloc symbol index.
2351 1.1 skrll
2352 1.1 skrll LOCAL_SYMS is a pointer to the swapped in local symbols.
2353 1.1 skrll
2354 1.1 skrll LOCAL_SECTIONS is an array giving the section in the input file
2355 1.1 skrll corresponding to the st_shndx field of each local symbol.
2356 1.1 skrll
2357 1.1 skrll The global hash table entry for the global symbols can be found
2358 1.1 skrll via elf_sym_hashes (input_bfd).
2359 1.1 skrll
2360 1.1 skrll When generating relocatable output, this function must handle
2361 1.1 skrll STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2362 1.1 skrll going to be the section symbol corresponding to the output
2363 1.1 skrll section, which means that the addend must be adjusted
2364 1.1 skrll accordingly. */
2365 1.1 skrll
2366 1.1 skrll static bfd_boolean
2367 1.1 skrll m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
2368 1.1 skrll struct bfd_link_info *info,
2369 1.1 skrll bfd *input_bfd,
2370 1.1 skrll asection *input_section,
2371 1.1 skrll bfd_byte *contents,
2372 1.1 skrll Elf_Internal_Rela *relocs,
2373 1.1 skrll Elf_Internal_Sym *local_syms,
2374 1.1 skrll asection **local_sections)
2375 1.1 skrll {
2376 1.1 skrll Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2377 1.1 skrll struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2378 1.1 skrll Elf_Internal_Rela *rel, *relend;
2379 1.1 skrll /* Assume success. */
2380 1.1 skrll bfd_boolean ret = TRUE;
2381 1.1.1.2 christos struct elf_m32r_link_hash_table *htab = m32r_elf_hash_table (info);
2382 1.1.1.2 christos bfd_vma *local_got_offsets;
2383 1.1.1.2 christos asection *sgot, *splt, *sreloc;
2384 1.1 skrll bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
2385 1.1 skrll
2386 1.1.1.6 christos if (htab == NULL)
2387 1.1.1.6 christos return FALSE;
2388 1.1 skrll
2389 1.1 skrll local_got_offsets = elf_local_got_offsets (input_bfd);
2390 1.1 skrll
2391 1.1 skrll sgot = htab->root.sgot;
2392 1.1 skrll splt = htab->root.splt;
2393 1.1 skrll sreloc = NULL;
2394 1.1 skrll
2395 1.1 skrll rel = relocs;
2396 1.1 skrll relend = relocs + input_section->reloc_count;
2397 1.1 skrll for (; rel < relend; rel++)
2398 1.1 skrll {
2399 1.1.1.6 christos int r_type;
2400 1.1.1.6 christos reloc_howto_type *howto;
2401 1.1.1.6 christos unsigned long r_symndx;
2402 1.1 skrll struct elf_link_hash_entry *h;
2403 1.1 skrll /* We can't modify r_addend here as elf_link_input_bfd has an assert to
2404 1.1 skrll ensure it's zero (we use REL relocs, not RELA). Therefore this
2405 1.1 skrll should be assigning zero to `addend', but for clarity we use
2406 1.1 skrll `r_addend'. */
2407 1.1 skrll bfd_vma addend = rel->r_addend;
2408 1.1 skrll bfd_vma offset = rel->r_offset;
2409 1.1 skrll bfd_vma relocation;
2410 1.1 skrll Elf_Internal_Sym *sym;
2411 1.1 skrll asection *sec;
2412 1.1 skrll const char *sym_name;
2413 1.1 skrll bfd_reloc_status_type r;
2414 1.1 skrll const char *errmsg = NULL;
2415 1.1 skrll bfd_boolean use_rel = FALSE;
2416 1.1.1.6 christos
2417 1.1.1.7 christos h = NULL;
2418 1.1.1.6 christos r_type = ELF32_R_TYPE (rel->r_info);
2419 1.1 skrll if (r_type < 0 || r_type >= (int) R_M32R_max)
2420 1.1 skrll {
2421 1.1 skrll /* xgettext:c-format */
2422 1.1 skrll _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2423 1.1 skrll input_bfd, (int) r_type);
2424 1.1 skrll bfd_set_error (bfd_error_bad_value);
2425 1.1.1.6 christos ret = FALSE;
2426 1.1.1.6 christos continue;
2427 1.1.1.6 christos }
2428 1.1.1.6 christos
2429 1.1.1.6 christos if ( r_type == R_M32R_GNU_VTENTRY
2430 1.1 skrll || r_type == R_M32R_GNU_VTINHERIT
2431 1.1 skrll || r_type == R_M32R_NONE
2432 1.1.1.6 christos || r_type == R_M32R_RELA_GNU_VTENTRY
2433 1.1 skrll || r_type == R_M32R_RELA_GNU_VTINHERIT)
2434 1.1 skrll continue;
2435 1.1 skrll
2436 1.1 skrll if (r_type <= R_M32R_GNU_VTENTRY)
2437 1.1 skrll use_rel = TRUE;
2438 1.1 skrll
2439 1.1 skrll howto = m32r_elf_howto_table + r_type;
2440 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
2441 1.1 skrll
2442 1.1 skrll sym = NULL;
2443 1.1 skrll sec = NULL;
2444 1.1 skrll h = NULL;
2445 1.1 skrll
2446 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
2447 1.1 skrll {
2448 1.1 skrll /* Local symbol. */
2449 1.1 skrll sym = local_syms + r_symndx;
2450 1.1 skrll sec = local_sections[r_symndx];
2451 1.1 skrll sym_name = "<local symbol>";
2452 1.1 skrll
2453 1.1 skrll if (!use_rel)
2454 1.1 skrll {
2455 1.1 skrll relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2456 1.1 skrll addend = rel->r_addend;
2457 1.1 skrll }
2458 1.1 skrll else
2459 1.1 skrll {
2460 1.1 skrll relocation = (sec->output_section->vma
2461 1.1 skrll + sec->output_offset
2462 1.1 skrll + sym->st_value);
2463 1.1 skrll }
2464 1.1 skrll }
2465 1.1 skrll else
2466 1.1.1.4 christos {
2467 1.1.1.4 christos /* External symbol. */
2468 1.1.1.4 christos relocation = 0;
2469 1.1.1.4 christos
2470 1.1.1.4 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2471 1.1.1.4 christos
2472 1.1 skrll if (info->wrap_hash != NULL
2473 1.1 skrll && (input_section->flags & SEC_DEBUGGING) != 0)
2474 1.1 skrll h = ((struct elf_link_hash_entry *)
2475 1.1 skrll unwrap_hash_lookup (info, input_bfd, &h->root));
2476 1.1 skrll
2477 1.1 skrll while (h->root.type == bfd_link_hash_indirect
2478 1.1 skrll || h->root.type == bfd_link_hash_warning)
2479 1.1 skrll h = (struct elf_link_hash_entry *) h->root.u.i.link;
2480 1.1 skrll sym_name = h->root.root.string;
2481 1.1 skrll
2482 1.1 skrll if (h->root.type == bfd_link_hash_defined
2483 1.1 skrll || h->root.type == bfd_link_hash_defweak)
2484 1.1 skrll {
2485 1.1 skrll bfd_boolean dyn;
2486 1.1 skrll sec = h->root.u.def.section;
2487 1.1 skrll
2488 1.1 skrll dyn = htab->root.dynamic_sections_created;
2489 1.1 skrll sec = h->root.u.def.section;
2490 1.1 skrll if (r_type == R_M32R_GOTPC24
2491 1.1 skrll || (r_type == R_M32R_GOTPC_HI_ULO
2492 1.1 skrll || r_type == R_M32R_GOTPC_HI_SLO
2493 1.1 skrll || r_type == R_M32R_GOTPC_LO)
2494 1.1 skrll || (r_type == R_M32R_26_PLTREL
2495 1.1 skrll && h->plt.offset != (bfd_vma) -1)
2496 1.1.1.4 christos || ((r_type == R_M32R_GOT24
2497 1.1.1.4 christos || r_type == R_M32R_GOT16_HI_ULO
2498 1.1.1.4 christos || r_type == R_M32R_GOT16_HI_SLO
2499 1.1 skrll || r_type == R_M32R_GOT16_LO)
2500 1.1 skrll && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2501 1.1.1.4 christos bfd_link_pic (info),
2502 1.1 skrll h)
2503 1.1 skrll && (! bfd_link_pic (info)
2504 1.1 skrll || (! info->symbolic && h->dynindx != -1)
2505 1.1 skrll || !h->def_regular))
2506 1.1 skrll || (bfd_link_pic (info)
2507 1.1 skrll && ((! info->symbolic && h->dynindx != -1)
2508 1.1 skrll || !h->def_regular)
2509 1.1 skrll && (((r_type == R_M32R_16_RELA
2510 1.1 skrll || r_type == R_M32R_32_RELA
2511 1.1 skrll || r_type == R_M32R_24_RELA
2512 1.1 skrll || r_type == R_M32R_HI16_ULO_RELA
2513 1.1 skrll || r_type == R_M32R_HI16_SLO_RELA
2514 1.1 skrll || r_type == R_M32R_LO16_RELA)
2515 1.1 skrll && !h->forced_local)
2516 1.1 skrll || r_type == R_M32R_REL32
2517 1.1 skrll || r_type == R_M32R_10_PCREL_RELA
2518 1.1 skrll || r_type == R_M32R_18_PCREL_RELA
2519 1.1 skrll || r_type == R_M32R_26_PCREL_RELA)
2520 1.1 skrll && ((input_section->flags & SEC_ALLOC) != 0
2521 1.1 skrll /* DWARF will emit R_M32R_16(24,32) relocations
2522 1.1 skrll in its sections against symbols defined
2523 1.1 skrll externally in shared libraries. We can't do
2524 1.1 skrll anything with them here. */
2525 1.1 skrll || ((input_section->flags & SEC_DEBUGGING) != 0
2526 1.1 skrll && h->def_dynamic))))
2527 1.1 skrll {
2528 1.1 skrll /* In these cases, we don't need the relocation
2529 1.1 skrll value. We check specially because in some
2530 1.1 skrll obscure cases sec->output_section will be NULL. */
2531 1.1.1.4 christos }
2532 1.1.1.3 christos else if (sec->output_section != NULL)
2533 1.1.1.3 christos relocation = (h->root.u.def.value
2534 1.1.1.3 christos + sec->output_section->vma
2535 1.1.1.3 christos + sec->output_offset);
2536 1.1 skrll else if (!bfd_link_relocatable (info)
2537 1.1.1.6 christos && (_bfd_elf_section_offset (output_bfd, info,
2538 1.1.1.6 christos input_section,
2539 1.1.1.7 christos rel->r_offset)
2540 1.1.1.6 christos != (bfd_vma) -1))
2541 1.1 skrll {
2542 1.1 skrll _bfd_error_handler
2543 1.1.1.7 christos /* xgettext:c-format */
2544 1.1 skrll (_("%pB(%pA+%#" PRIx64 "): unresolvable %s relocation "
2545 1.1 skrll "against symbol `%s'"),
2546 1.1 skrll input_bfd,
2547 1.1 skrll input_section,
2548 1.1 skrll (uint64_t) rel->r_offset,
2549 1.1 skrll howto->name,
2550 1.1 skrll h->root.root.string);
2551 1.1 skrll }
2552 1.1 skrll }
2553 1.1.1.4 christos else if (h->root.type == bfd_link_hash_undefweak)
2554 1.1.1.5 christos ;
2555 1.1.1.5 christos else if (info->unresolved_syms_in_objects == RM_IGNORE
2556 1.1.1.5 christos && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
2557 1.1.1.5 christos ;
2558 1.1.1.5 christos else if (!bfd_link_relocatable (info))
2559 1.1 skrll (*info->callbacks->undefined_symbol)
2560 1.1 skrll (info, h->root.root.string, input_bfd,
2561 1.1.1.3 christos input_section, offset,
2562 1.1.1.2 christos (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
2563 1.1.1.3 christos || ELF_ST_VISIBILITY (h->other)));
2564 1.1 skrll }
2565 1.1.1.4 christos
2566 1.1 skrll if (sec != NULL && discarded_section (sec))
2567 1.1 skrll RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2568 1.1 skrll rel, 1, relend, howto, 0, contents);
2569 1.1 skrll
2570 1.1 skrll if (bfd_link_relocatable (info) && !use_rel)
2571 1.1 skrll {
2572 1.1 skrll /* This is a relocatable link. We don't have to change
2573 1.1 skrll anything, unless the reloc is against a section symbol,
2574 1.1 skrll in which case we have to adjust according to where the
2575 1.1 skrll section symbol winds up in the output section. */
2576 1.1.1.4 christos if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2577 1.1 skrll rel->r_addend += sec->output_offset;
2578 1.1 skrll continue;
2579 1.1 skrll }
2580 1.1 skrll
2581 1.1 skrll if (bfd_link_relocatable (info) && use_rel)
2582 1.1 skrll {
2583 1.1 skrll /* This is a relocatable link. We don't have to change
2584 1.1 skrll anything, unless the reloc is against a section symbol,
2585 1.1 skrll in which case we have to adjust according to where the
2586 1.1 skrll section symbol winds up in the output section. */
2587 1.1 skrll if (sym == NULL || ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2588 1.1 skrll continue;
2589 1.1 skrll
2590 1.1 skrll addend += sec->output_offset;
2591 1.1 skrll
2592 1.1 skrll /* If partial_inplace, we need to store any additional addend
2593 1.1 skrll back in the section. */
2594 1.1 skrll if (! howto->partial_inplace)
2595 1.1 skrll continue;
2596 1.1 skrll /* ??? Here is a nice place to call a special_function
2597 1.1 skrll like handler. */
2598 1.1 skrll if (r_type != R_M32R_HI16_SLO && r_type != R_M32R_HI16_ULO)
2599 1.1 skrll r = _bfd_relocate_contents (howto, input_bfd,
2600 1.1 skrll addend, contents + offset);
2601 1.1 skrll else
2602 1.1 skrll {
2603 1.1 skrll Elf_Internal_Rela *lorel;
2604 1.1 skrll
2605 1.1 skrll /* We allow an arbitrary number of HI16 relocs before the
2606 1.1 skrll LO16 reloc. This permits gcc to emit the HI and LO relocs
2607 1.1 skrll itself. */
2608 1.1 skrll for (lorel = rel + 1;
2609 1.1 skrll (lorel < relend
2610 1.1 skrll && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
2611 1.1 skrll || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
2612 1.1 skrll lorel++)
2613 1.1 skrll continue;
2614 1.1 skrll if (lorel < relend
2615 1.1 skrll && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
2616 1.1 skrll {
2617 1.1 skrll m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
2618 1.1 skrll contents, addend);
2619 1.1 skrll r = bfd_reloc_ok;
2620 1.1 skrll }
2621 1.1 skrll else
2622 1.1 skrll r = _bfd_relocate_contents (howto, input_bfd,
2623 1.1 skrll addend, contents + offset);
2624 1.1 skrll }
2625 1.1 skrll }
2626 1.1 skrll else
2627 1.1 skrll {
2628 1.1 skrll /* Sanity check the address. */
2629 1.1 skrll if (offset > high_address)
2630 1.1 skrll {
2631 1.1 skrll r = bfd_reloc_outofrange;
2632 1.1.1.6 christos goto check_reloc;
2633 1.1.1.6 christos }
2634 1.1.1.6 christos
2635 1.1.1.6 christos switch ((int) r_type)
2636 1.1.1.6 christos {
2637 1.1.1.6 christos case R_M32R_GOTOFF:
2638 1.1.1.6 christos /* Relocation is relative to the start of the global offset
2639 1.1.1.6 christos table (for ld24 rx, #uimm24). eg access at label+addend
2640 1.1.1.6 christos
2641 1.1.1.6 christos ld24 rx. #label@GOTOFF + addend
2642 1.1.1.6 christos sub rx, r12. */
2643 1.1.1.6 christos
2644 1.1.1.6 christos BFD_ASSERT (sgot != NULL);
2645 1.1.1.6 christos
2646 1.1.1.6 christos relocation = -(relocation - sgot->output_section->vma);
2647 1.1.1.6 christos rel->r_addend = -rel->r_addend;
2648 1.1 skrll break;
2649 1.1 skrll
2650 1.1 skrll case R_M32R_GOTOFF_HI_ULO:
2651 1.1 skrll case R_M32R_GOTOFF_HI_SLO:
2652 1.1 skrll case R_M32R_GOTOFF_LO:
2653 1.1 skrll BFD_ASSERT (sgot != NULL);
2654 1.1 skrll
2655 1.1 skrll relocation -= sgot->output_section->vma;
2656 1.1 skrll
2657 1.1.1.6 christos if ((r_type == R_M32R_GOTOFF_HI_SLO)
2658 1.1.1.6 christos && ((relocation + rel->r_addend) & 0x8000))
2659 1.1.1.6 christos rel->r_addend += 0x10000;
2660 1.1.1.6 christos break;
2661 1.1.1.6 christos
2662 1.1.1.6 christos case R_M32R_GOTPC24:
2663 1.1.1.6 christos /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2664 1.1.1.6 christos ld24 rx,#_GLOBAL_OFFSET_TABLE_
2665 1.1.1.6 christos */
2666 1.1.1.6 christos relocation = sgot->output_section->vma;
2667 1.1.1.6 christos break;
2668 1.1.1.6 christos
2669 1.1.1.6 christos case R_M32R_GOTPC_HI_ULO:
2670 1.1.1.6 christos case R_M32R_GOTPC_HI_SLO:
2671 1.1.1.6 christos case R_M32R_GOTPC_LO:
2672 1.1.1.6 christos {
2673 1.1.1.6 christos /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2674 1.1.1.6 christos bl .+4
2675 1.1.1.6 christos seth rx,#high(_GLOBAL_OFFSET_TABLE_)
2676 1.1.1.6 christos or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2677 1.1.1.6 christos or
2678 1.1.1.6 christos bl .+4
2679 1.1.1.6 christos seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
2680 1.1.1.6 christos add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2681 1.1.1.6 christos */
2682 1.1.1.6 christos relocation = sgot->output_section->vma;
2683 1.1.1.6 christos relocation -= (input_section->output_section->vma
2684 1.1.1.6 christos + input_section->output_offset
2685 1.1.1.6 christos + rel->r_offset);
2686 1.1.1.6 christos if ((r_type == R_M32R_GOTPC_HI_SLO)
2687 1.1.1.6 christos && ((relocation + rel->r_addend) & 0x8000))
2688 1.1.1.6 christos rel->r_addend += 0x10000;
2689 1.1.1.6 christos
2690 1.1.1.6 christos break;
2691 1.1.1.6 christos }
2692 1.1.1.6 christos case R_M32R_GOT16_HI_ULO:
2693 1.1.1.6 christos case R_M32R_GOT16_HI_SLO:
2694 1.1.1.6 christos case R_M32R_GOT16_LO:
2695 1.1.1.6 christos /* Fall through. */
2696 1.1.1.6 christos case R_M32R_GOT24:
2697 1.1.1.6 christos /* Relocation is to the entry for this symbol in the global
2698 1.1.1.6 christos offset table. */
2699 1.1.1.6 christos BFD_ASSERT (sgot != NULL);
2700 1.1 skrll
2701 1.1.1.6 christos if (h != NULL)
2702 1.1.1.6 christos {
2703 1.1 skrll bfd_boolean dyn;
2704 1.1.1.6 christos bfd_vma off;
2705 1.1.1.6 christos
2706 1.1.1.4 christos off = h->got.offset;
2707 1.1.1.4 christos BFD_ASSERT (off != (bfd_vma) -1);
2708 1.1.1.6 christos
2709 1.1.1.6 christos dyn = htab->root.dynamic_sections_created;
2710 1.1.1.6 christos if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2711 1.1.1.6 christos bfd_link_pic (info),
2712 1.1.1.6 christos h)
2713 1.1.1.6 christos || (bfd_link_pic (info)
2714 1.1.1.6 christos && (info->symbolic
2715 1.1.1.6 christos || h->dynindx == -1
2716 1.1.1.6 christos || h->forced_local)
2717 1.1.1.6 christos && h->def_regular))
2718 1.1.1.6 christos {
2719 1.1.1.6 christos /* This is actually a static link, or it is a
2720 1.1.1.6 christos -Bsymbolic link and the symbol is defined
2721 1.1.1.6 christos locally, or the symbol was forced to be local
2722 1.1.1.6 christos because of a version file. We must initialize
2723 1.1.1.6 christos this entry in the global offset table. Since the
2724 1.1.1.6 christos offset must always be a multiple of 4, we use the
2725 1.1.1.6 christos least significant bit to record whether we have
2726 1.1.1.6 christos initialized it already.
2727 1.1.1.6 christos
2728 1.1.1.6 christos When doing a dynamic link, we create a .rela.got
2729 1.1.1.6 christos relocation entry to initialize the value. This
2730 1.1.1.6 christos is done in the finish_dynamic_symbol routine. */
2731 1.1.1.6 christos if ((off & 1) != 0)
2732 1.1.1.6 christos off &= ~1;
2733 1.1.1.6 christos else
2734 1.1.1.6 christos {
2735 1.1.1.6 christos bfd_put_32 (output_bfd, relocation,
2736 1.1.1.6 christos sgot->contents + off);
2737 1.1.1.6 christos h->got.offset |= 1;
2738 1.1.1.6 christos }
2739 1.1.1.6 christos }
2740 1.1.1.6 christos
2741 1.1.1.6 christos relocation = sgot->output_offset + off;
2742 1.1.1.6 christos }
2743 1.1.1.6 christos else
2744 1.1.1.6 christos {
2745 1.1.1.6 christos bfd_vma off;
2746 1.1.1.6 christos bfd_byte *loc;
2747 1.1.1.6 christos
2748 1.1.1.6 christos BFD_ASSERT (local_got_offsets != NULL
2749 1.1.1.6 christos && local_got_offsets[r_symndx] != (bfd_vma) -1);
2750 1.1.1.6 christos
2751 1.1.1.6 christos off = local_got_offsets[r_symndx];
2752 1.1.1.6 christos
2753 1.1.1.6 christos /* The offset must always be a multiple of 4. We use
2754 1.1.1.6 christos the least significant bit to record whether we have
2755 1.1.1.6 christos already processed this entry. */
2756 1.1.1.6 christos if ((off & 1) != 0)
2757 1.1.1.6 christos off &= ~1;
2758 1.1.1.6 christos else
2759 1.1.1.6 christos {
2760 1.1.1.6 christos bfd_put_32 (output_bfd, relocation, sgot->contents + off);
2761 1.1.1.6 christos
2762 1.1.1.6 christos if (bfd_link_pic (info))
2763 1.1.1.6 christos {
2764 1.1.1.6 christos asection *srelgot;
2765 1.1.1.6 christos Elf_Internal_Rela outrel;
2766 1.1.1.6 christos
2767 1.1.1.6 christos /* We need to generate a R_M32R_RELATIVE reloc
2768 1.1.1.6 christos for the dynamic linker. */
2769 1.1.1.6 christos srelgot = htab->root.srelgot;
2770 1.1.1.6 christos BFD_ASSERT (srelgot != NULL);
2771 1.1.1.6 christos
2772 1.1.1.6 christos outrel.r_offset = (sgot->output_section->vma
2773 1.1.1.6 christos + sgot->output_offset
2774 1.1.1.6 christos + off);
2775 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
2776 1.1.1.6 christos outrel.r_addend = relocation;
2777 1.1.1.6 christos loc = srelgot->contents;
2778 1.1.1.6 christos loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
2779 1.1.1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
2780 1.1.1.6 christos ++srelgot->reloc_count;
2781 1.1.1.6 christos }
2782 1.1.1.6 christos
2783 1.1.1.6 christos local_got_offsets[r_symndx] |= 1;
2784 1.1.1.6 christos }
2785 1.1.1.6 christos
2786 1.1.1.6 christos relocation = sgot->output_offset + off;
2787 1.1.1.6 christos }
2788 1.1 skrll if ((r_type == R_M32R_GOT16_HI_SLO)
2789 1.1.1.6 christos && ((relocation + rel->r_addend) & 0x8000))
2790 1.1.1.6 christos rel->r_addend += 0x10000;
2791 1.1.1.6 christos
2792 1.1.1.6 christos break;
2793 1.1.1.6 christos
2794 1.1.1.6 christos case R_M32R_26_PLTREL:
2795 1.1.1.6 christos /* Relocation is to the entry for this symbol in the
2796 1.1.1.6 christos procedure linkage table. */
2797 1.1.1.6 christos
2798 1.1 skrll /* The native assembler will generate a 26_PLTREL reloc
2799 1.1.1.6 christos for a local symbol if you assemble a call from one
2800 1.1.1.6 christos section to another when using -K pic. */
2801 1.1.1.6 christos if (h == NULL)
2802 1.1.1.6 christos break;
2803 1.1 skrll
2804 1.1 skrll if (h->forced_local)
2805 1.1 skrll break;
2806 1.1 skrll
2807 1.1 skrll if (h->plt.offset == (bfd_vma) -1)
2808 1.1.1.6 christos /* We didn't make a PLT entry for this symbol. This
2809 1.1.1.6 christos happens when statically linking PIC code, or when
2810 1.1.1.6 christos using -Bsymbolic. */
2811 1.1.1.6 christos break;
2812 1.1 skrll
2813 1.1.1.6 christos relocation = (splt->output_section->vma
2814 1.1 skrll + splt->output_offset
2815 1.1 skrll + h->plt.offset);
2816 1.1.1.6 christos break;
2817 1.1 skrll
2818 1.1.1.6 christos case R_M32R_HI16_SLO_RELA:
2819 1.1.1.6 christos if ((relocation + rel->r_addend) & 0x8000)
2820 1.1.1.6 christos rel->r_addend += 0x10000;
2821 1.1.1.6 christos /* Fall through. */
2822 1.1 skrll
2823 1.1.1.6 christos case R_M32R_16_RELA:
2824 1.1.1.6 christos case R_M32R_24_RELA:
2825 1.1.1.6 christos case R_M32R_32_RELA:
2826 1.1.1.6 christos case R_M32R_REL32:
2827 1.1.1.6 christos case R_M32R_10_PCREL_RELA:
2828 1.1.1.6 christos case R_M32R_18_PCREL_RELA:
2829 1.1.1.6 christos case R_M32R_26_PCREL_RELA:
2830 1.1.1.6 christos case R_M32R_HI16_ULO_RELA:
2831 1.1.1.6 christos case R_M32R_LO16_RELA:
2832 1.1.1.6 christos if (bfd_link_pic (info)
2833 1.1.1.6 christos && r_symndx != STN_UNDEF
2834 1.1.1.6 christos && (input_section->flags & SEC_ALLOC) != 0
2835 1.1.1.6 christos && (( r_type != R_M32R_10_PCREL_RELA
2836 1.1.1.6 christos && r_type != R_M32R_18_PCREL_RELA
2837 1.1.1.6 christos && r_type != R_M32R_26_PCREL_RELA
2838 1.1.1.6 christos && r_type != R_M32R_REL32)
2839 1.1.1.6 christos || (h != NULL
2840 1.1.1.6 christos && h->dynindx != -1
2841 1.1.1.6 christos && (! info->symbolic
2842 1.1.1.6 christos || !h->def_regular))))
2843 1.1.1.6 christos {
2844 1.1.1.6 christos Elf_Internal_Rela outrel;
2845 1.1.1.6 christos bfd_boolean skip, relocate;
2846 1.1.1.6 christos bfd_byte *loc;
2847 1.1.1.6 christos
2848 1.1.1.2 christos /* When generating a shared object, these relocations
2849 1.1.1.2 christos are copied into the output file to be resolved at run
2850 1.1.1.2 christos time. */
2851 1.1.1.2 christos if (sreloc == NULL)
2852 1.1.1.6 christos {
2853 1.1 skrll sreloc = _bfd_elf_get_dynamic_reloc_section
2854 1.1.1.6 christos (input_bfd, input_section, /*rela?*/ TRUE);
2855 1.1.1.6 christos if (sreloc == NULL)
2856 1.1 skrll return FALSE;
2857 1.1.1.6 christos }
2858 1.1.1.6 christos
2859 1.1.1.6 christos skip = FALSE;
2860 1.1.1.6 christos relocate = FALSE;
2861 1.1.1.6 christos
2862 1.1.1.6 christos outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2863 1.1.1.6 christos info,
2864 1.1.1.6 christos input_section,
2865 1.1.1.6 christos rel->r_offset);
2866 1.1.1.6 christos if (outrel.r_offset == (bfd_vma) -1)
2867 1.1.1.6 christos skip = TRUE;
2868 1.1.1.6 christos else if (outrel.r_offset == (bfd_vma) -2)
2869 1.1.1.6 christos skip = relocate = TRUE;
2870 1.1.1.6 christos outrel.r_offset += (input_section->output_section->vma
2871 1.1.1.6 christos + input_section->output_offset);
2872 1.1.1.6 christos
2873 1.1.1.6 christos if (skip)
2874 1.1.1.6 christos memset (&outrel, 0, sizeof outrel);
2875 1.1.1.6 christos else if ( r_type == R_M32R_10_PCREL_RELA
2876 1.1.1.6 christos || r_type == R_M32R_18_PCREL_RELA
2877 1.1.1.6 christos || r_type == R_M32R_26_PCREL_RELA
2878 1.1.1.6 christos || r_type == R_M32R_REL32)
2879 1.1.1.6 christos {
2880 1.1.1.6 christos BFD_ASSERT (h != NULL && h->dynindx != -1);
2881 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2882 1.1.1.6 christos outrel.r_addend = rel->r_addend;
2883 1.1.1.6 christos }
2884 1.1.1.6 christos else
2885 1.1.1.6 christos {
2886 1.1.1.6 christos /* h->dynindx may be -1 if this symbol was marked to
2887 1.1.1.6 christos become local. */
2888 1.1.1.6 christos if (h == NULL
2889 1.1.1.6 christos || ((info->symbolic || h->dynindx == -1)
2890 1.1.1.6 christos && h->def_regular))
2891 1.1.1.6 christos {
2892 1.1.1.6 christos relocate = TRUE;
2893 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
2894 1.1.1.6 christos outrel.r_addend = relocation + rel->r_addend;
2895 1.1.1.6 christos }
2896 1.1.1.6 christos else
2897 1.1.1.6 christos {
2898 1.1.1.6 christos BFD_ASSERT (h->dynindx != -1);
2899 1.1.1.6 christos outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2900 1.1.1.6 christos outrel.r_addend = relocation + rel->r_addend;
2901 1.1.1.6 christos }
2902 1.1.1.6 christos }
2903 1.1.1.6 christos
2904 1.1.1.6 christos loc = sreloc->contents;
2905 1.1.1.6 christos loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
2906 1.1.1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
2907 1.1.1.6 christos ++sreloc->reloc_count;
2908 1.1.1.6 christos
2909 1.1.1.6 christos /* If this reloc is against an external symbol, we do
2910 1.1 skrll not want to fiddle with the addend. Otherwise, we
2911 1.1.1.6 christos need to include the symbol value so that it becomes
2912 1.1 skrll an addend for the dynamic reloc. */
2913 1.1 skrll if (! relocate)
2914 1.1 skrll continue;
2915 1.1 skrll break;
2916 1.1 skrll }
2917 1.1 skrll else if (r_type != R_M32R_10_PCREL_RELA)
2918 1.1 skrll break;
2919 1.1 skrll /* Fall through. */
2920 1.1.1.6 christos
2921 1.1 skrll case (int) R_M32R_10_PCREL :
2922 1.1 skrll r = m32r_elf_do_10_pcrel_reloc (input_bfd, howto, input_section,
2923 1.1 skrll contents, offset,
2924 1.1 skrll sec, relocation, addend);
2925 1.1 skrll goto check_reloc;
2926 1.1 skrll
2927 1.1 skrll case (int) R_M32R_HI16_SLO :
2928 1.1 skrll case (int) R_M32R_HI16_ULO :
2929 1.1 skrll {
2930 1.1 skrll Elf_Internal_Rela *lorel;
2931 1.1 skrll
2932 1.1 skrll /* We allow an arbitrary number of HI16 relocs before the
2933 1.1 skrll LO16 reloc. This permits gcc to emit the HI and LO relocs
2934 1.1 skrll itself. */
2935 1.1 skrll for (lorel = rel + 1;
2936 1.1 skrll (lorel < relend
2937 1.1 skrll && (ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_SLO
2938 1.1 skrll || ELF32_R_TYPE (lorel->r_info) == R_M32R_HI16_ULO));
2939 1.1 skrll lorel++)
2940 1.1 skrll continue;
2941 1.1 skrll if (lorel < relend
2942 1.1 skrll && ELF32_R_TYPE (lorel->r_info) == R_M32R_LO16)
2943 1.1 skrll {
2944 1.1 skrll m32r_elf_relocate_hi16 (input_bfd, r_type, rel, lorel,
2945 1.1 skrll contents, relocation + addend);
2946 1.1 skrll r = bfd_reloc_ok;
2947 1.1 skrll }
2948 1.1 skrll else
2949 1.1.1.6 christos r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2950 1.1 skrll contents, offset,
2951 1.1.1.6 christos relocation, addend);
2952 1.1 skrll }
2953 1.1 skrll
2954 1.1 skrll goto check_reloc;
2955 1.1 skrll
2956 1.1 skrll case (int) R_M32R_SDA16_RELA:
2957 1.1.1.8 christos case (int) R_M32R_SDA16 :
2958 1.1 skrll {
2959 1.1 skrll const char *name;
2960 1.1 skrll
2961 1.1 skrll BFD_ASSERT (sec != NULL);
2962 1.1 skrll name = bfd_section_name (sec);
2963 1.1 skrll
2964 1.1 skrll if ( strcmp (name, ".sdata") == 0
2965 1.1 skrll || strcmp (name, ".sbss") == 0
2966 1.1 skrll || strcmp (name, ".scommon") == 0)
2967 1.1 skrll {
2968 1.1 skrll bfd_vma sda_base;
2969 1.1 skrll bfd *out_bfd = sec->output_section->owner;
2970 1.1 skrll
2971 1.1 skrll r = m32r_elf_final_sda_base (out_bfd, info,
2972 1.1 skrll &errmsg,
2973 1.1 skrll &sda_base);
2974 1.1 skrll if (r != bfd_reloc_ok)
2975 1.1 skrll {
2976 1.1 skrll ret = FALSE;
2977 1.1 skrll goto check_reloc;
2978 1.1 skrll }
2979 1.1 skrll
2980 1.1 skrll /* At this point `relocation' contains the object's
2981 1.1 skrll address. */
2982 1.1.1.6 christos relocation -= sda_base;
2983 1.1.1.6 christos /* Now it contains the offset from _SDA_BASE_. */
2984 1.1.1.7 christos }
2985 1.1.1.7 christos else
2986 1.1 skrll {
2987 1.1 skrll _bfd_error_handler
2988 1.1.1.6 christos /* xgettext:c-format */
2989 1.1.1.6 christos (_("%pB: the target (%s) of an %s relocation"
2990 1.1 skrll " is in the wrong section (%pA)"),
2991 1.1 skrll input_bfd,
2992 1.1 skrll sym_name,
2993 1.1 skrll m32r_elf_howto_table[(int) r_type].name,
2994 1.1 skrll sec);
2995 1.1.1.6 christos /*bfd_set_error (bfd_error_bad_value); ??? why? */
2996 1.1 skrll ret = FALSE;
2997 1.1 skrll continue;
2998 1.1 skrll }
2999 1.1 skrll }
3000 1.1 skrll /* Fall through. */
3001 1.1 skrll
3002 1.1 skrll default : /* OLD_M32R_RELOC */
3003 1.1 skrll
3004 1.1 skrll r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3005 1.1.1.6 christos contents, offset,
3006 1.1.1.6 christos relocation, addend);
3007 1.1.1.6 christos goto check_reloc;
3008 1.1 skrll }
3009 1.1 skrll
3010 1.1 skrll r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3011 1.1 skrll contents, rel->r_offset,
3012 1.1 skrll relocation, rel->r_addend);
3013 1.1 skrll
3014 1.1 skrll }
3015 1.1 skrll
3016 1.1 skrll check_reloc:
3017 1.1 skrll
3018 1.1 skrll if (r != bfd_reloc_ok)
3019 1.1 skrll {
3020 1.1 skrll /* FIXME: This should be generic enough to go in a utility. */
3021 1.1 skrll const char *name;
3022 1.1 skrll
3023 1.1 skrll if (h != NULL)
3024 1.1 skrll name = h->root.root.string;
3025 1.1.1.8 christos else
3026 1.1 skrll {
3027 1.1 skrll name = (bfd_elf_string_from_elf_section
3028 1.1 skrll (input_bfd, symtab_hdr->sh_link, sym->st_name));
3029 1.1 skrll if (name == NULL || *name == '\0')
3030 1.1 skrll name = bfd_section_name (sec);
3031 1.1 skrll }
3032 1.1 skrll
3033 1.1 skrll if (errmsg != NULL)
3034 1.1.1.5 christos goto common_error;
3035 1.1.1.5 christos
3036 1.1.1.5 christos switch (r)
3037 1.1 skrll {
3038 1.1 skrll case bfd_reloc_overflow:
3039 1.1 skrll (*info->callbacks->reloc_overflow)
3040 1.1.1.5 christos (info, (h ? &h->root : NULL), name, howto->name,
3041 1.1.1.5 christos (bfd_vma) 0, input_bfd, input_section, offset);
3042 1.1 skrll break;
3043 1.1 skrll
3044 1.1 skrll case bfd_reloc_undefined:
3045 1.1 skrll (*info->callbacks->undefined_symbol)
3046 1.1 skrll (info, name, input_bfd, input_section, offset, TRUE);
3047 1.1 skrll break;
3048 1.1 skrll
3049 1.1 skrll case bfd_reloc_outofrange:
3050 1.1 skrll errmsg = _("internal error: out of range error");
3051 1.1 skrll goto common_error;
3052 1.1 skrll
3053 1.1 skrll case bfd_reloc_notsupported:
3054 1.1 skrll errmsg = _("internal error: unsupported relocation error");
3055 1.1 skrll goto common_error;
3056 1.1 skrll
3057 1.1 skrll case bfd_reloc_dangerous:
3058 1.1 skrll errmsg = _("internal error: dangerous error");
3059 1.1 skrll goto common_error;
3060 1.1 skrll
3061 1.1.1.5 christos default:
3062 1.1.1.5 christos errmsg = _("internal error: unknown error");
3063 1.1 skrll /* fall through */
3064 1.1 skrll
3065 1.1 skrll common_error:
3066 1.1 skrll (*info->callbacks->warning) (info, errmsg, name, input_bfd,
3067 1.1 skrll input_section, offset);
3068 1.1 skrll break;
3069 1.1 skrll }
3070 1.1 skrll }
3071 1.1 skrll }
3072 1.1 skrll
3073 1.1 skrll return ret;
3074 1.1 skrll }
3075 1.1 skrll
3076 1.1 skrll /* Finish up dynamic symbol handling. We set the contents of various
3077 1.1 skrll dynamic sections here. */
3078 1.1 skrll
3079 1.1 skrll static bfd_boolean
3080 1.1 skrll m32r_elf_finish_dynamic_symbol (bfd *output_bfd,
3081 1.1 skrll struct bfd_link_info *info,
3082 1.1 skrll struct elf_link_hash_entry *h,
3083 1.1 skrll Elf_Internal_Sym *sym)
3084 1.1 skrll {
3085 1.1 skrll struct elf_m32r_link_hash_table *htab;
3086 1.1 skrll bfd_byte *loc;
3087 1.1 skrll
3088 1.1.1.2 christos #ifdef DEBUG_PIC
3089 1.1.1.2 christos printf ("m32r_elf_finish_dynamic_symbol()\n");
3090 1.1 skrll #endif
3091 1.1 skrll
3092 1.1 skrll htab = m32r_elf_hash_table (info);
3093 1.1 skrll if (htab == NULL)
3094 1.1 skrll return FALSE;
3095 1.1 skrll
3096 1.1 skrll if (h->plt.offset != (bfd_vma) -1)
3097 1.1 skrll {
3098 1.1 skrll asection *splt;
3099 1.1 skrll asection *sgot;
3100 1.1 skrll asection *srela;
3101 1.1 skrll
3102 1.1.1.6 christos bfd_vma plt_index;
3103 1.1 skrll bfd_vma got_offset;
3104 1.1 skrll Elf_Internal_Rela rela;
3105 1.1 skrll
3106 1.1.1.6 christos /* This symbol has an entry in the procedure linkage table. Set
3107 1.1.1.6 christos it up. */
3108 1.1.1.6 christos
3109 1.1 skrll BFD_ASSERT (h->dynindx != -1);
3110 1.1 skrll
3111 1.1 skrll splt = htab->root.splt;
3112 1.1.1.6 christos sgot = htab->root.sgotplt;
3113 1.1.1.6 christos srela = htab->root.srelplt;
3114 1.1.1.6 christos BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
3115 1.1 skrll
3116 1.1 skrll /* Get the index in the procedure linkage table which
3117 1.1 skrll corresponds to this symbol. This is the index of this symbol
3118 1.1.1.6 christos in all the symbols for which we are making plt entries. The
3119 1.1.1.6 christos first entry in the procedure linkage table is reserved. */
3120 1.1 skrll plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3121 1.1 skrll
3122 1.1 skrll /* Get the offset into the .got table of the entry that
3123 1.1.1.4 christos corresponds to this function. Each .got entry is 4 bytes.
3124 1.1.1.6 christos The first three are reserved. */
3125 1.1.1.6 christos got_offset = (plt_index + 3) * 4;
3126 1.1.1.6 christos
3127 1.1.1.6 christos /* Fill in the entry in the procedure linkage table. */
3128 1.1.1.6 christos if (! bfd_link_pic (info))
3129 1.1.1.6 christos {
3130 1.1.1.6 christos bfd_put_32 (output_bfd,
3131 1.1.1.6 christos (PLT_ENTRY_WORD0b
3132 1.1.1.6 christos + (((sgot->output_section->vma
3133 1.1.1.6 christos + sgot->output_offset
3134 1.1.1.6 christos + got_offset) >> 16) & 0xffff)),
3135 1.1.1.6 christos splt->contents + h->plt.offset);
3136 1.1.1.6 christos bfd_put_32 (output_bfd,
3137 1.1.1.6 christos (PLT_ENTRY_WORD1b
3138 1.1.1.6 christos + ((sgot->output_section->vma
3139 1.1.1.6 christos + sgot->output_offset
3140 1.1.1.6 christos + got_offset) & 0xffff)),
3141 1.1.1.6 christos splt->contents + h->plt.offset + 4);
3142 1.1.1.6 christos bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
3143 1.1.1.6 christos splt->contents + h->plt.offset + 8);
3144 1.1.1.6 christos bfd_put_32 (output_bfd,
3145 1.1.1.6 christos (PLT_ENTRY_WORD3
3146 1.1.1.6 christos + plt_index * sizeof (Elf32_External_Rela)),
3147 1.1.1.6 christos splt->contents + h->plt.offset + 12);
3148 1.1 skrll bfd_put_32 (output_bfd,
3149 1.1.1.6 christos (PLT_ENTRY_WORD4
3150 1.1.1.6 christos + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
3151 1.1.1.6 christos splt->contents + h->plt.offset + 16);
3152 1.1.1.6 christos }
3153 1.1.1.6 christos else
3154 1.1.1.6 christos {
3155 1.1.1.6 christos bfd_put_32 (output_bfd,
3156 1.1.1.6 christos PLT_ENTRY_WORD0 + got_offset,
3157 1.1.1.6 christos splt->contents + h->plt.offset);
3158 1.1.1.6 christos bfd_put_32 (output_bfd, PLT_ENTRY_WORD1,
3159 1.1.1.6 christos splt->contents + h->plt.offset + 4);
3160 1.1.1.6 christos bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
3161 1.1.1.6 christos splt->contents + h->plt.offset + 8);
3162 1.1.1.6 christos bfd_put_32 (output_bfd,
3163 1.1.1.6 christos (PLT_ENTRY_WORD3
3164 1.1.1.6 christos + plt_index * sizeof (Elf32_External_Rela)),
3165 1.1.1.6 christos splt->contents + h->plt.offset + 12);
3166 1.1 skrll bfd_put_32 (output_bfd,
3167 1.1 skrll (PLT_ENTRY_WORD4
3168 1.1 skrll + (((unsigned int) ((- (h->plt.offset + 16)) >> 2)) & 0xffffff)),
3169 1.1.1.6 christos splt->contents + h->plt.offset + 16);
3170 1.1.1.6 christos }
3171 1.1.1.6 christos
3172 1.1.1.6 christos /* Fill in the entry in the global offset table. */
3173 1.1.1.6 christos bfd_put_32 (output_bfd,
3174 1.1 skrll (splt->output_section->vma
3175 1.1 skrll + splt->output_offset
3176 1.1 skrll + h->plt.offset
3177 1.1.1.6 christos + 12), /* same offset */
3178 1.1.1.6 christos sgot->contents + got_offset);
3179 1.1 skrll
3180 1.1 skrll /* Fill in the entry in the .rela.plt section. */
3181 1.1 skrll rela.r_offset = (sgot->output_section->vma
3182 1.1 skrll + sgot->output_offset
3183 1.1 skrll + got_offset);
3184 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_JMP_SLOT);
3185 1.1 skrll rela.r_addend = 0;
3186 1.1.1.6 christos loc = srela->contents;
3187 1.1.1.6 christos loc += plt_index * sizeof (Elf32_External_Rela);
3188 1.1.1.6 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3189 1.1.1.6 christos
3190 1.1.1.6 christos if (!h->def_regular)
3191 1.1 skrll {
3192 1.1 skrll /* Mark the symbol as undefined, rather than as defined in
3193 1.1 skrll the .plt section. Leave the value alone. */
3194 1.1 skrll sym->st_shndx = SHN_UNDEF;
3195 1.1 skrll }
3196 1.1 skrll }
3197 1.1 skrll
3198 1.1 skrll if (h->got.offset != (bfd_vma) -1)
3199 1.1 skrll {
3200 1.1.1.6 christos asection *sgot;
3201 1.1 skrll asection *srela;
3202 1.1.1.6 christos Elf_Internal_Rela rela;
3203 1.1.1.6 christos
3204 1.1 skrll /* This symbol has an entry in the global offset table. Set it
3205 1.1 skrll up. */
3206 1.1 skrll
3207 1.1.1.6 christos sgot = htab->root.sgot;
3208 1.1.1.6 christos srela = htab->root.srelgot;
3209 1.1 skrll BFD_ASSERT (sgot != NULL && srela != NULL);
3210 1.1 skrll
3211 1.1.1.6 christos rela.r_offset = (sgot->output_section->vma
3212 1.1.1.6 christos + sgot->output_offset
3213 1.1.1.6 christos + (h->got.offset &~ 1));
3214 1.1.1.6 christos
3215 1.1.1.4 christos /* If this is a -Bsymbolic link, and the symbol is defined
3216 1.1.1.6 christos locally, we just want to emit a RELATIVE reloc. Likewise if
3217 1.1 skrll the symbol was forced to be local because of a version file.
3218 1.1 skrll The entry in the global offset table will already have been
3219 1.1.1.6 christos initialized in the relocate_section function. */
3220 1.1.1.6 christos if (bfd_link_pic (info)
3221 1.1.1.6 christos && (info->symbolic
3222 1.1.1.6 christos || h->dynindx == -1
3223 1.1.1.6 christos || h->forced_local)
3224 1.1.1.6 christos && h->def_regular)
3225 1.1.1.6 christos {
3226 1.1 skrll rela.r_info = ELF32_R_INFO (0, R_M32R_RELATIVE);
3227 1.1.1.6 christos rela.r_addend = (h->root.u.def.value
3228 1.1 skrll + h->root.u.def.section->output_section->vma
3229 1.1.1.6 christos + h->root.u.def.section->output_offset);
3230 1.1.1.6 christos }
3231 1.1.1.6 christos else
3232 1.1.1.6 christos {
3233 1.1 skrll BFD_ASSERT ((h->got.offset & 1) == 0);
3234 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3235 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_GLOB_DAT);
3236 1.1 skrll rela.r_addend = 0;
3237 1.1 skrll }
3238 1.1 skrll
3239 1.1 skrll loc = srela->contents;
3240 1.1 skrll loc += srela->reloc_count * sizeof (Elf32_External_Rela);
3241 1.1 skrll bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3242 1.1 skrll ++srela->reloc_count;
3243 1.1 skrll }
3244 1.1 skrll
3245 1.1 skrll if (h->needs_copy)
3246 1.1 skrll {
3247 1.1 skrll asection *s;
3248 1.1.1.6 christos Elf_Internal_Rela rela;
3249 1.1.1.6 christos
3250 1.1 skrll /* This symbols needs a copy reloc. Set it up. */
3251 1.1.1.3 christos
3252 1.1 skrll BFD_ASSERT (h->dynindx != -1
3253 1.1 skrll && (h->root.type == bfd_link_hash_defined
3254 1.1 skrll || h->root.type == bfd_link_hash_defweak));
3255 1.1.1.6 christos
3256 1.1.1.6 christos s = bfd_get_linker_section (htab->root.dynobj, ".rela.bss");
3257 1.1 skrll BFD_ASSERT (s != NULL);
3258 1.1 skrll
3259 1.1 skrll rela.r_offset = (h->root.u.def.value
3260 1.1 skrll + h->root.u.def.section->output_section->vma
3261 1.1 skrll + h->root.u.def.section->output_offset);
3262 1.1 skrll rela.r_info = ELF32_R_INFO (h->dynindx, R_M32R_COPY);
3263 1.1 skrll rela.r_addend = 0;
3264 1.1 skrll loc = s->contents;
3265 1.1 skrll loc += s->reloc_count * sizeof (Elf32_External_Rela);
3266 1.1.1.4 christos bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3267 1.1 skrll ++s->reloc_count;
3268 1.1 skrll }
3269 1.1 skrll
3270 1.1 skrll /* Mark some specially defined symbols as absolute. */
3271 1.1 skrll if (h == htab->root.hdynamic || h == htab->root.hgot)
3272 1.1 skrll sym->st_shndx = SHN_ABS;
3273 1.1 skrll
3274 1.1 skrll return TRUE;
3275 1.1 skrll }
3276 1.1 skrll
3277 1.1 skrll
3278 1.1 skrll /* Finish up the dynamic sections. */
3279 1.1 skrll
3280 1.1 skrll static bfd_boolean
3281 1.1 skrll m32r_elf_finish_dynamic_sections (bfd *output_bfd,
3282 1.1 skrll struct bfd_link_info *info)
3283 1.1 skrll {
3284 1.1 skrll struct elf_m32r_link_hash_table *htab;
3285 1.1 skrll bfd *dynobj;
3286 1.1 skrll asection *sdyn;
3287 1.1 skrll asection *sgot;
3288 1.1 skrll
3289 1.1.1.2 christos #ifdef DEBUG_PIC
3290 1.1.1.2 christos printf ("m32r_elf_finish_dynamic_sections()\n");
3291 1.1.1.2 christos #endif
3292 1.1 skrll
3293 1.1 skrll htab = m32r_elf_hash_table (info);
3294 1.1.1.6 christos if (htab == NULL)
3295 1.1.1.3 christos return FALSE;
3296 1.1 skrll
3297 1.1 skrll dynobj = htab->root.dynobj;
3298 1.1 skrll
3299 1.1 skrll sgot = htab->root.sgotplt;
3300 1.1 skrll sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3301 1.1 skrll
3302 1.1 skrll if (htab->root.dynamic_sections_created)
3303 1.1 skrll {
3304 1.1 skrll asection *splt;
3305 1.1 skrll Elf32_External_Dyn *dyncon, *dynconend;
3306 1.1 skrll
3307 1.1 skrll BFD_ASSERT (sgot != NULL && sdyn != NULL);
3308 1.1.1.6 christos
3309 1.1.1.6 christos dyncon = (Elf32_External_Dyn *) sdyn->contents;
3310 1.1.1.6 christos dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3311 1.1 skrll
3312 1.1.1.6 christos for (; dyncon < dynconend; dyncon++)
3313 1.1 skrll {
3314 1.1.1.6 christos Elf_Internal_Dyn dyn;
3315 1.1.1.6 christos asection *s;
3316 1.1.1.6 christos
3317 1.1.1.6 christos bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3318 1.1.1.6 christos
3319 1.1.1.6 christos switch (dyn.d_tag)
3320 1.1.1.6 christos {
3321 1.1.1.6 christos default:
3322 1.1.1.6 christos break;
3323 1.1.1.6 christos
3324 1.1.1.6 christos case DT_PLTGOT:
3325 1.1.1.6 christos s = htab->root.sgotplt;
3326 1.1.1.6 christos goto get_vma;
3327 1.1.1.6 christos case DT_JMPREL:
3328 1.1.1.6 christos s = htab->root.srelplt;
3329 1.1.1.6 christos get_vma:
3330 1.1.1.6 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3331 1.1.1.6 christos bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3332 1.1.1.6 christos break;
3333 1.1.1.6 christos
3334 1.1.1.6 christos case DT_PLTRELSZ:
3335 1.1.1.6 christos s = htab->root.srelplt;
3336 1.1 skrll dyn.d_un.d_val = s->size;
3337 1.1 skrll bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3338 1.1.1.6 christos break;
3339 1.1 skrll }
3340 1.1.1.6 christos }
3341 1.1.1.6 christos
3342 1.1.1.6 christos /* Fill in the first entry in the procedure linkage table. */
3343 1.1.1.6 christos splt = htab->root.splt;
3344 1.1.1.6 christos if (splt && splt->size > 0)
3345 1.1.1.6 christos {
3346 1.1.1.6 christos if (bfd_link_pic (info))
3347 1.1.1.6 christos {
3348 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents);
3349 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4);
3350 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2, splt->contents + 8);
3351 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3, splt->contents + 12);
3352 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4, splt->contents + 16);
3353 1.1.1.6 christos }
3354 1.1.1.6 christos else
3355 1.1 skrll {
3356 1.1 skrll unsigned long addr;
3357 1.1.1.6 christos /* addr = .got + 4 */
3358 1.1 skrll addr = sgot->output_section->vma + sgot->output_offset + 4;
3359 1.1 skrll bfd_put_32 (output_bfd,
3360 1.1.1.6 christos PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
3361 1.1.1.6 christos splt->contents);
3362 1.1.1.6 christos bfd_put_32 (output_bfd,
3363 1.1.1.6 christos PLT0_ENTRY_WORD1 | (addr & 0xffff),
3364 1.1.1.6 christos splt->contents + 4);
3365 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
3366 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
3367 1.1.1.6 christos bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
3368 1.1 skrll }
3369 1.1 skrll
3370 1.1 skrll elf_section_data (splt->output_section)->this_hdr.sh_entsize =
3371 1.1 skrll PLT_ENTRY_SIZE;
3372 1.1 skrll }
3373 1.1 skrll }
3374 1.1.1.6 christos
3375 1.1 skrll /* Fill in the first three entries in the global offset table. */
3376 1.1.1.6 christos if (sgot && sgot->size > 0)
3377 1.1.1.6 christos {
3378 1.1.1.6 christos if (sdyn == NULL)
3379 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3380 1.1 skrll else
3381 1.1 skrll bfd_put_32 (output_bfd,
3382 1.1 skrll sdyn->output_section->vma + sdyn->output_offset,
3383 1.1 skrll sgot->contents);
3384 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
3385 1.1 skrll bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3386 1.1 skrll
3387 1.1 skrll elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
3388 1.1 skrll }
3389 1.1 skrll
3390 1.1 skrll return TRUE;
3391 1.1 skrll }
3392 1.1 skrll
3393 1.1 skrll
3394 1.1 skrll /* Set the right machine number. */
3396 1.1 skrll
3397 1.1 skrll static bfd_boolean
3398 1.1 skrll m32r_elf_object_p (bfd *abfd)
3399 1.1 skrll {
3400 1.1 skrll switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
3401 1.1 skrll {
3402 1.1 skrll default:
3403 1.1 skrll case E_M32R_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r); break;
3404 1.1 skrll case E_M32RX_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;
3405 1.1 skrll case E_M32R2_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r2); break;
3406 1.1.1.8 christos }
3407 1.1.1.8 christos return TRUE;
3408 1.1 skrll }
3409 1.1 skrll
3410 1.1 skrll /* Store the machine number in the flags field. */
3411 1.1 skrll
3412 1.1 skrll static bfd_boolean
3413 1.1 skrll m32r_elf_final_write_processing (bfd *abfd)
3414 1.1 skrll {
3415 1.1 skrll unsigned long val;
3416 1.1 skrll
3417 1.1 skrll switch (bfd_get_mach (abfd))
3418 1.1 skrll {
3419 1.1 skrll default:
3420 1.1 skrll case bfd_mach_m32r: val = E_M32R_ARCH; break;
3421 1.1.1.8 christos case bfd_mach_m32rx: val = E_M32RX_ARCH; break;
3422 1.1 skrll case bfd_mach_m32r2: val = E_M32R2_ARCH; break;
3423 1.1 skrll }
3424 1.1 skrll
3425 1.1 skrll elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;
3426 1.1 skrll elf_elfheader (abfd)->e_flags |= val;
3427 1.1 skrll return _bfd_elf_final_write_processing (abfd);
3428 1.1 skrll }
3429 1.1 skrll
3430 1.1 skrll /* Function to keep M32R specific file flags. */
3431 1.1 skrll
3432 1.1 skrll static bfd_boolean
3433 1.1 skrll m32r_elf_set_private_flags (bfd *abfd, flagword flags)
3434 1.1 skrll {
3435 1.1 skrll BFD_ASSERT (!elf_flags_init (abfd)
3436 1.1 skrll || elf_elfheader (abfd)->e_flags == flags);
3437 1.1 skrll
3438 1.1 skrll elf_elfheader (abfd)->e_flags = flags;
3439 1.1 skrll elf_flags_init (abfd) = TRUE;
3440 1.1 skrll return TRUE;
3441 1.1.1.6 christos }
3442 1.1 skrll
3443 1.1.1.6 christos /* Merge backend specific data from an object file to the output
3444 1.1 skrll object file when linking. */
3445 1.1 skrll
3446 1.1 skrll static bfd_boolean
3447 1.1 skrll m32r_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
3448 1.1 skrll {
3449 1.1 skrll bfd *obfd = info->output_bfd;
3450 1.1 skrll flagword out_flags;
3451 1.1 skrll flagword in_flags;
3452 1.1 skrll
3453 1.1 skrll if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3454 1.1 skrll || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3455 1.1 skrll return TRUE;
3456 1.1 skrll
3457 1.1 skrll in_flags = elf_elfheader (ibfd)->e_flags;
3458 1.1 skrll out_flags = elf_elfheader (obfd)->e_flags;
3459 1.1 skrll
3460 1.1 skrll if (! elf_flags_init (obfd))
3461 1.1 skrll {
3462 1.1 skrll /* If the input is the default architecture then do not
3463 1.1 skrll bother setting the flags for the output architecture,
3464 1.1 skrll instead allow future merges to do this. If no future
3465 1.1 skrll merges ever set these flags then they will retain their
3466 1.1 skrll unitialised values, which surprise surprise, correspond
3467 1.1 skrll to the default values. */
3468 1.1 skrll if (bfd_get_arch_info (ibfd)->the_default)
3469 1.1 skrll return TRUE;
3470 1.1 skrll
3471 1.1 skrll elf_flags_init (obfd) = TRUE;
3472 1.1 skrll elf_elfheader (obfd)->e_flags = in_flags;
3473 1.1 skrll
3474 1.1 skrll if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3475 1.1 skrll && bfd_get_arch_info (obfd)->the_default)
3476 1.1 skrll return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3477 1.1 skrll bfd_get_mach (ibfd));
3478 1.1 skrll
3479 1.1 skrll return TRUE;
3480 1.1 skrll }
3481 1.1 skrll
3482 1.1 skrll /* Check flag compatibility. */
3483 1.1.1.6 christos if (in_flags == out_flags)
3484 1.1.1.6 christos return TRUE;
3485 1.1 skrll
3486 1.1.1.6 christos if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))
3487 1.1.1.7 christos {
3488 1.1 skrll if ( ((in_flags & EF_M32R_ARCH) != E_M32R_ARCH)
3489 1.1 skrll || ((out_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3490 1.1 skrll || ((in_flags & EF_M32R_ARCH) == E_M32R2_ARCH))
3491 1.1 skrll {
3492 1.1 skrll _bfd_error_handler
3493 1.1 skrll (_("%pB: instruction set mismatch with previous modules"), ibfd);
3494 1.1 skrll
3495 1.1 skrll bfd_set_error (bfd_error_bad_value);
3496 1.1 skrll return FALSE;
3497 1.1 skrll }
3498 1.1 skrll }
3499 1.1 skrll
3500 1.1 skrll return TRUE;
3501 1.1 skrll }
3502 1.1 skrll
3503 1.1 skrll /* Display the flags field. */
3504 1.1 skrll
3505 1.1 skrll static bfd_boolean
3506 1.1 skrll m32r_elf_print_private_bfd_data (bfd *abfd, void * ptr)
3507 1.1 skrll {
3508 1.1 skrll FILE * file = (FILE *) ptr;
3509 1.1 skrll
3510 1.1 skrll BFD_ASSERT (abfd != NULL && ptr != NULL);
3511 1.1 skrll
3512 1.1 skrll _bfd_elf_print_private_bfd_data (abfd, ptr);
3513 1.1 skrll
3514 1.1 skrll fprintf (file, _("private flags = %lx"), elf_elfheader (abfd)->e_flags);
3515 1.1 skrll
3516 1.1 skrll switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)
3517 1.1 skrll {
3518 1.1 skrll default:
3519 1.1 skrll case E_M32R_ARCH: fprintf (file, _(": m32r instructions")); break;
3520 1.1 skrll case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;
3521 1.1 skrll case E_M32R2_ARCH: fprintf (file, _(": m32r2 instructions")); break;
3522 1.1 skrll }
3523 1.1 skrll
3524 1.1 skrll fputc ('\n', file);
3525 1.1 skrll
3526 1.1 skrll return TRUE;
3527 1.1 skrll }
3528 1.1 skrll
3529 1.1 skrll static asection *
3530 1.1 skrll m32r_elf_gc_mark_hook (asection *sec,
3531 1.1 skrll struct bfd_link_info *info,
3532 1.1 skrll Elf_Internal_Rela *rel,
3533 1.1 skrll struct elf_link_hash_entry *h,
3534 1.1 skrll Elf_Internal_Sym *sym)
3535 1.1 skrll {
3536 1.1 skrll if (h != NULL)
3537 1.1 skrll switch (ELF32_R_TYPE (rel->r_info))
3538 1.1 skrll {
3539 1.1 skrll case R_M32R_GNU_VTINHERIT:
3540 1.1 skrll case R_M32R_GNU_VTENTRY:
3541 1.1 skrll case R_M32R_RELA_GNU_VTINHERIT:
3542 1.1 skrll case R_M32R_RELA_GNU_VTENTRY:
3543 1.1 skrll return NULL;
3544 1.1 skrll }
3545 1.1 skrll
3546 1.1 skrll return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
3547 1.1 skrll }
3548 1.1 skrll
3549 1.1 skrll /* Look through the relocs for a section during the first phase.
3550 1.1 skrll Since we don't do .gots or .plts, we just need to consider the
3551 1.1 skrll virtual table relocs for gc. */
3552 1.1 skrll
3553 1.1 skrll static bfd_boolean
3554 1.1 skrll m32r_elf_check_relocs (bfd *abfd,
3555 1.1 skrll struct bfd_link_info *info,
3556 1.1 skrll asection *sec,
3557 1.1 skrll const Elf_Internal_Rela *relocs)
3558 1.1 skrll {
3559 1.1.1.2 christos Elf_Internal_Shdr *symtab_hdr;
3560 1.1 skrll struct elf_link_hash_entry **sym_hashes;
3561 1.1.1.4 christos const Elf_Internal_Rela *rel;
3562 1.1 skrll const Elf_Internal_Rela *rel_end;
3563 1.1 skrll struct elf_m32r_link_hash_table *htab;
3564 1.1.1.6 christos bfd *dynobj;
3565 1.1.1.6 christos asection *sreloc;
3566 1.1.1.6 christos
3567 1.1.1.6 christos if (bfd_link_relocatable (info))
3568 1.1.1.6 christos return TRUE;
3569 1.1.1.6 christos
3570 1.1.1.6 christos /* Don't do anything special with non-loaded, non-alloced sections.
3571 1.1.1.6 christos In particular, any relocs in such sections should not affect GOT
3572 1.1.1.6 christos and PLT reference counting (ie. we don't allow them to create GOT
3573 1.1.1.2 christos or PLT entries), there's no possibility or desire to optimize TLS
3574 1.1 skrll relocs, and there's not much point in propagating relocs to shared
3575 1.1 skrll libs that the dynamic linker won't relocate. */
3576 1.1 skrll if ((sec->flags & SEC_ALLOC) == 0)
3577 1.1 skrll return TRUE;
3578 1.1.1.2 christos
3579 1.1.1.2 christos sreloc = NULL;
3580 1.1.1.2 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3581 1.1 skrll sym_hashes = elf_sym_hashes (abfd);
3582 1.1 skrll
3583 1.1 skrll htab = m32r_elf_hash_table (info);
3584 1.1 skrll if (htab == NULL)
3585 1.1 skrll return FALSE;
3586 1.1 skrll
3587 1.1 skrll dynobj = htab->root.dynobj;
3588 1.1 skrll
3589 1.1 skrll rel_end = relocs + sec->reloc_count;
3590 1.1 skrll for (rel = relocs; rel < rel_end; rel++)
3591 1.1 skrll {
3592 1.1 skrll int r_type;
3593 1.1.1.6 christos struct elf_link_hash_entry *h;
3594 1.1 skrll unsigned long r_symndx;
3595 1.1 skrll
3596 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
3597 1.1 skrll r_type = ELF32_R_TYPE (rel->r_info);
3598 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
3599 1.1 skrll h = NULL;
3600 1.1 skrll else
3601 1.1 skrll {
3602 1.1 skrll h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3603 1.1.1.6 christos while (h->root.type == bfd_link_hash_indirect
3604 1.1.1.6 christos || h->root.type == bfd_link_hash_warning)
3605 1.1.1.6 christos h = (struct elf_link_hash_entry *) h->root.u.i.link;
3606 1.1.1.6 christos }
3607 1.1.1.6 christos
3608 1.1.1.6 christos /* Some relocs require a global offset table. */
3609 1.1.1.6 christos if (htab->root.sgot == NULL)
3610 1.1.1.6 christos {
3611 1.1.1.6 christos switch (r_type)
3612 1.1.1.6 christos {
3613 1.1.1.6 christos case R_M32R_GOT16_HI_ULO:
3614 1.1.1.6 christos case R_M32R_GOT16_HI_SLO:
3615 1.1.1.6 christos case R_M32R_GOTOFF:
3616 1.1.1.6 christos case R_M32R_GOTOFF_HI_ULO:
3617 1.1.1.6 christos case R_M32R_GOTOFF_HI_SLO:
3618 1.1.1.6 christos case R_M32R_GOTOFF_LO:
3619 1.1.1.6 christos case R_M32R_GOT16_LO:
3620 1.1.1.6 christos case R_M32R_GOTPC24:
3621 1.1.1.6 christos case R_M32R_GOTPC_HI_ULO:
3622 1.1.1.6 christos case R_M32R_GOTPC_HI_SLO:
3623 1.1.1.6 christos case R_M32R_GOTPC_LO:
3624 1.1.1.6 christos case R_M32R_GOT24:
3625 1.1.1.6 christos if (dynobj == NULL)
3626 1.1.1.6 christos htab->root.dynobj = dynobj = abfd;
3627 1.1.1.6 christos if (!_bfd_elf_create_got_section (dynobj, info))
3628 1.1.1.6 christos return FALSE;
3629 1.1 skrll break;
3630 1.1 skrll
3631 1.1.1.6 christos default:
3632 1.1 skrll break;
3633 1.1 skrll }
3634 1.1 skrll }
3635 1.1.1.6 christos
3636 1.1.1.6 christos switch (r_type)
3637 1.1.1.6 christos {
3638 1.1.1.6 christos case R_M32R_GOT16_HI_ULO:
3639 1.1.1.6 christos case R_M32R_GOT16_HI_SLO:
3640 1.1.1.6 christos case R_M32R_GOT16_LO:
3641 1.1.1.6 christos case R_M32R_GOT24:
3642 1.1 skrll
3643 1.1.1.6 christos if (h != NULL)
3644 1.1.1.6 christos h->got.refcount += 1;
3645 1.1.1.6 christos else
3646 1.1.1.6 christos {
3647 1.1.1.6 christos bfd_signed_vma *local_got_refcounts;
3648 1.1.1.6 christos
3649 1.1.1.6 christos /* This is a global offset table entry for a local
3650 1.1.1.6 christos symbol. */
3651 1.1.1.6 christos local_got_refcounts = elf_local_got_refcounts (abfd);
3652 1.1.1.6 christos if (local_got_refcounts == NULL)
3653 1.1.1.6 christos {
3654 1.1.1.6 christos bfd_size_type size;
3655 1.1.1.6 christos
3656 1.1.1.6 christos size = symtab_hdr->sh_info;
3657 1.1.1.6 christos size *= sizeof (bfd_signed_vma);
3658 1.1.1.6 christos local_got_refcounts = bfd_zalloc (abfd, size);
3659 1.1.1.6 christos if (local_got_refcounts == NULL)
3660 1.1.1.6 christos return FALSE;
3661 1.1.1.6 christos elf_local_got_refcounts (abfd) = local_got_refcounts;
3662 1.1.1.6 christos }
3663 1.1.1.6 christos local_got_refcounts[r_symndx] += 1;
3664 1.1.1.6 christos }
3665 1.1.1.6 christos break;
3666 1.1.1.6 christos
3667 1.1 skrll case R_M32R_26_PLTREL:
3668 1.1 skrll /* This symbol requires a procedure linkage table entry. We
3669 1.1 skrll actually build the entry in adjust_dynamic_symbol,
3670 1.1.1.6 christos because this might be a case of linking PIC code without
3671 1.1.1.6 christos linking in any dynamic objects, in which case we don't
3672 1.1 skrll need to generate a procedure linkage table after all. */
3673 1.1.1.6 christos
3674 1.1.1.6 christos /* If this is a local symbol, we resolve it directly without
3675 1.1 skrll creating a procedure linkage table entry. */
3676 1.1.1.6 christos if (h == NULL)
3677 1.1 skrll continue;
3678 1.1.1.6 christos
3679 1.1 skrll if (h->forced_local)
3680 1.1.1.6 christos break;
3681 1.1.1.6 christos
3682 1.1.1.6 christos h->needs_plt = 1;
3683 1.1.1.6 christos h->plt.refcount += 1;
3684 1.1.1.6 christos break;
3685 1.1.1.6 christos
3686 1.1.1.6 christos case R_M32R_16_RELA:
3687 1.1.1.6 christos case R_M32R_24_RELA:
3688 1.1 skrll case R_M32R_32_RELA:
3689 1.1.1.6 christos case R_M32R_REL32:
3690 1.1.1.6 christos case R_M32R_HI16_ULO_RELA:
3691 1.1.1.6 christos case R_M32R_HI16_SLO_RELA:
3692 1.1.1.6 christos case R_M32R_LO16_RELA:
3693 1.1.1.6 christos case R_M32R_SDA16_RELA:
3694 1.1.1.6 christos case R_M32R_10_PCREL_RELA:
3695 1.1.1.6 christos case R_M32R_18_PCREL_RELA:
3696 1.1.1.6 christos case R_M32R_26_PCREL_RELA:
3697 1.1 skrll
3698 1.1.1.6 christos if (h != NULL && !bfd_link_pic (info))
3699 1.1.1.6 christos {
3700 1.1.1.6 christos h->non_got_ref = 1;
3701 1.1.1.6 christos h->plt.refcount += 1;
3702 1.1.1.6 christos }
3703 1.1.1.6 christos
3704 1.1.1.6 christos /* If we are creating a shared library, and this is a reloc
3705 1.1.1.6 christos against a global symbol, or a non PC relative reloc
3706 1.1.1.6 christos against a local symbol, then we need to copy the reloc
3707 1.1.1.6 christos into the shared library. However, if we are linking with
3708 1.1.1.6 christos -Bsymbolic, we do not need to copy a reloc against a
3709 1.1.1.6 christos global symbol which is defined in an object we are
3710 1.1.1.6 christos including in the link (i.e., DEF_REGULAR is set). At
3711 1.1.1.6 christos this point we have not seen all the input files, so it is
3712 1.1.1.6 christos possible that DEF_REGULAR is not set now but will be set
3713 1.1.1.6 christos later (it is never cleared). We account for that
3714 1.1.1.6 christos possibility below by storing information in the
3715 1.1.1.6 christos dyn_relocs field of the hash table entry. A similar
3716 1.1.1.6 christos situation occurs when creating shared libraries and symbol
3717 1.1.1.6 christos visibility changes render the symbol local.
3718 1.1.1.6 christos
3719 1.1 skrll If on the other hand, we are creating an executable, we
3720 1.1.1.6 christos may need to keep relocations for symbols satisfied by a
3721 1.1.1.6 christos dynamic library if we manage to avoid copy relocs for the
3722 1.1.1.6 christos symbol. */
3723 1.1.1.6 christos if ((bfd_link_pic (info)
3724 1.1 skrll && (sec->flags & SEC_ALLOC) != 0
3725 1.1.1.6 christos && (( r_type != R_M32R_26_PCREL_RELA
3726 1.1.1.6 christos && r_type != R_M32R_18_PCREL_RELA
3727 1.1.1.6 christos && r_type != R_M32R_10_PCREL_RELA
3728 1.1.1.6 christos && r_type != R_M32R_REL32)
3729 1.1.1.6 christos || (h != NULL
3730 1.1.1.6 christos && (! info->symbolic
3731 1.1.1.6 christos || h->root.type == bfd_link_hash_defweak
3732 1.1.1.6 christos || !h->def_regular))))
3733 1.1.1.6 christos || (!bfd_link_pic (info)
3734 1.1.1.6 christos && (sec->flags & SEC_ALLOC) != 0
3735 1.1.1.6 christos && h != NULL
3736 1.1.1.6 christos && (h->root.type == bfd_link_hash_defweak
3737 1.1.1.6 christos || !h->def_regular)))
3738 1.1.1.6 christos {
3739 1.1.1.6 christos struct elf_dyn_relocs *p;
3740 1.1.1.6 christos struct elf_dyn_relocs **head;
3741 1.1.1.6 christos
3742 1.1.1.6 christos if (dynobj == NULL)
3743 1.1.1.6 christos htab->root.dynobj = dynobj = abfd;
3744 1.1.1.2 christos
3745 1.1.1.2 christos /* When creating a shared object, we must copy these
3746 1.1 skrll relocs into the output file. We create a reloc
3747 1.1.1.2 christos section in dynobj and make room for the reloc. */
3748 1.1.1.2 christos if (sreloc == NULL)
3749 1.1.1.6 christos {
3750 1.1 skrll sreloc = _bfd_elf_make_dynamic_reloc_section
3751 1.1.1.6 christos (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
3752 1.1.1.6 christos
3753 1.1.1.6 christos if (sreloc == NULL)
3754 1.1.1.6 christos return FALSE;
3755 1.1.1.6 christos }
3756 1.1.1.6 christos
3757 1.1.1.6 christos /* If this is a global symbol, we count the number of
3758 1.1.1.6 christos relocations we need for this symbol. */
3759 1.1.1.6 christos if (h != NULL)
3760 1.1.1.2 christos head = &((struct elf_m32r_link_hash_entry *) h)->dyn_relocs;
3761 1.1 skrll else
3762 1.1.1.2 christos {
3763 1.1.1.2 christos /* Track dynamic relocs needed for local syms too. */
3764 1.1.1.2 christos asection *s;
3765 1.1.1.2 christos void *vpp;
3766 1.1.1.2 christos Elf_Internal_Sym *isym;
3767 1.1.1.2 christos
3768 1.1.1.2 christos isym = bfd_sym_from_r_symndx (&htab->sym_cache,
3769 1.1.1.2 christos abfd, r_symndx);
3770 1.1 skrll if (isym == NULL)
3771 1.1 skrll return FALSE;
3772 1.1.1.6 christos
3773 1.1.1.6 christos s = bfd_section_from_elf_index (abfd, isym->st_shndx);
3774 1.1 skrll if (s == NULL)
3775 1.1.1.6 christos s = sec;
3776 1.1.1.6 christos
3777 1.1.1.6 christos vpp = &elf_section_data (s)->local_dynrel;
3778 1.1.1.6 christos head = (struct elf_dyn_relocs **) vpp;
3779 1.1.1.6 christos }
3780 1.1.1.6 christos
3781 1.1.1.6 christos p = *head;
3782 1.1.1.6 christos if (p == NULL || p->sec != sec)
3783 1.1.1.6 christos {
3784 1.1.1.6 christos bfd_size_type amt = sizeof (*p);
3785 1.1.1.6 christos
3786 1.1.1.6 christos p = bfd_alloc (dynobj, amt);
3787 1.1.1.6 christos if (p == NULL)
3788 1.1.1.6 christos return FALSE;
3789 1.1.1.6 christos p->next = *head;
3790 1.1.1.6 christos *head = p;
3791 1.1.1.6 christos p->sec = sec;
3792 1.1.1.6 christos p->count = 0;
3793 1.1 skrll p->pc_count = 0;
3794 1.1 skrll }
3795 1.1.1.6 christos
3796 1.1.1.6 christos p->count += 1;
3797 1.1.1.6 christos if ( ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
3798 1.1.1.6 christos || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA
3799 1.1.1.6 christos || ELF32_R_TYPE (rel->r_info) == R_M32R_10_PCREL_RELA
3800 1.1.1.6 christos || ELF32_R_TYPE (rel->r_info) == R_M32R_REL32)
3801 1.1.1.6 christos p->pc_count += 1;
3802 1.1.1.6 christos }
3803 1.1.1.6 christos break;
3804 1.1.1.6 christos
3805 1.1.1.6 christos /* This relocation describes the C++ object vtable hierarchy.
3806 1.1.1.6 christos Reconstruct it for later use during GC. */
3807 1.1.1.6 christos case R_M32R_RELA_GNU_VTINHERIT:
3808 1.1.1.6 christos case R_M32R_GNU_VTINHERIT:
3809 1.1.1.6 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3810 1.1.1.8 christos return FALSE;
3811 1.1.1.6 christos break;
3812 1.1.1.6 christos
3813 1.1.1.6 christos /* This relocation describes which C++ vtable entries are actually
3814 1.1.1.8 christos used. Record for later use during GC. */
3815 1.1.1.6 christos case R_M32R_GNU_VTENTRY:
3816 1.1.1.6 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
3817 1.1.1.6 christos return FALSE;
3818 1.1 skrll break;
3819 1.1 skrll case R_M32R_RELA_GNU_VTENTRY:
3820 1.1 skrll if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3821 1.1 skrll return FALSE;
3822 1.1 skrll break;
3823 1.1 skrll }
3824 1.1 skrll }
3825 1.1.1.6 christos
3826 1.1 skrll return TRUE;
3827 1.1.1.6 christos }
3828 1.1 skrll
3829 1.1 skrll static const struct bfd_elf_special_section m32r_elf_special_sections[] =
3830 1.1 skrll {
3831 1.1.1.4 christos { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
3832 1.1.1.4 christos { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3833 1.1.1.4 christos { NULL, 0, 0, 0, 0 }
3834 1.1 skrll };
3835 1.1 skrll
3836 1.1 skrll static enum elf_reloc_type_class
3837 1.1 skrll m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
3838 1.1 skrll const asection *rel_sec ATTRIBUTE_UNUSED,
3839 1.1 skrll const Elf_Internal_Rela *rela)
3840 1.1.1.6 christos {
3841 1.1 skrll switch ((int) ELF32_R_TYPE (rela->r_info))
3842 1.1 skrll {
3843 1.1 skrll case R_M32R_RELATIVE: return reloc_class_relative;
3844 1.1 skrll case R_M32R_JMP_SLOT: return reloc_class_plt;
3845 1.1.1.2 christos case R_M32R_COPY: return reloc_class_copy;
3846 1.1 skrll default: return reloc_class_normal;
3847 1.1 skrll }
3848 1.1 skrll }
3849 1.1 skrll
3850 1.1.1.6 christos #define ELF_ARCH bfd_arch_m32r
3852 1.1.1.6 christos #define ELF_TARGET_ID M32R_ELF_DATA
3853 1.1.1.6 christos #define ELF_MACHINE_CODE EM_M32R
3854 1.1 skrll #define ELF_MACHINE_ALT1 EM_CYGNUS_M32R
3855 1.1 skrll #define ELF_MAXPAGESIZE 0x1 /* Explicitly requested by Mitsubishi. */
3856 1.1 skrll
3857 1.1 skrll #define TARGET_BIG_SYM m32r_elf32_vec
3858 1.1 skrll #define TARGET_BIG_NAME "elf32-m32r"
3859 1.1 skrll #define TARGET_LITTLE_SYM m32r_elf32_le_vec
3860 1.1 skrll #define TARGET_LITTLE_NAME "elf32-m32rle"
3861 1.1.1.6 christos
3862 1.1.1.6 christos #define elf_info_to_howto m32r_info_to_howto
3863 1.1.1.6 christos #define elf_info_to_howto_rel m32r_info_to_howto_rel
3864 1.1.1.6 christos #define elf_backend_section_from_bfd_section _bfd_m32r_elf_section_from_bfd_section
3865 1.1.1.6 christos #define elf_backend_symbol_processing _bfd_m32r_elf_symbol_processing
3866 1.1.1.6 christos #define elf_backend_add_symbol_hook m32r_elf_add_symbol_hook
3867 1.1.1.7 christos #define elf_backend_relocate_section m32r_elf_relocate_section
3868 1.1.1.6 christos #define elf_backend_gc_mark_hook m32r_elf_gc_mark_hook
3869 1.1.1.6 christos #define elf_backend_check_relocs m32r_elf_check_relocs
3870 1.1.1.6 christos
3871 1.1.1.6 christos #define elf_backend_create_dynamic_sections m32r_elf_create_dynamic_sections
3872 1.1.1.6 christos #define bfd_elf32_bfd_link_hash_table_create m32r_elf_link_hash_table_create
3873 1.1 skrll #define elf_backend_size_dynamic_sections m32r_elf_size_dynamic_sections
3874 1.1.1.6 christos #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
3875 1.1 skrll #define elf_backend_finish_dynamic_sections m32r_elf_finish_dynamic_sections
3876 1.1 skrll #define elf_backend_adjust_dynamic_symbol m32r_elf_adjust_dynamic_symbol
3877 1.1 skrll #define elf_backend_finish_dynamic_symbol m32r_elf_finish_dynamic_symbol
3878 1.1 skrll #define elf_backend_reloc_type_class m32r_elf_reloc_type_class
3879 1.1 skrll #define elf_backend_copy_indirect_symbol m32r_elf_copy_indirect_symbol
3880 1.1 skrll
3881 1.1 skrll #define elf_backend_can_gc_sections 1
3882 1.1 skrll /*#if !USE_REL
3883 1.1.1.6 christos #define elf_backend_rela_normal 1
3884 1.1 skrll #endif*/
3885 1.1.1.6 christos #define elf_backend_can_refcount 1
3886 1.1 skrll #define elf_backend_want_got_plt 1
3887 1.1.1.6 christos #define elf_backend_plt_readonly 1
3888 1.1.1.6 christos #define elf_backend_want_plt_sym 0
3889 1.1 skrll #define elf_backend_got_header_size 12
3890 1.1.1.6 christos #define elf_backend_dtrel_excludes_plt 1
3891 1.1.1.6 christos
3892 1.1 skrll #define elf_backend_may_use_rel_p 1
3893 1.1 skrll #ifdef USE_M32R_OLD_RELOC
3894 1.1 skrll #define elf_backend_default_use_rela_p 0
3895 1.1.1.6 christos #define elf_backend_may_use_rela_p 0
3896 1.1.1.6 christos #else
3897 1.1 skrll #define elf_backend_default_use_rela_p 1
3898 1.1 skrll #define elf_backend_may_use_rela_p 1
3899 1.1 skrll #endif
3900 1.1 skrll
3901 1.1.1.6 christos #define elf_backend_object_p m32r_elf_object_p
3902 1.1.1.6 christos #define elf_backend_final_write_processing m32r_elf_final_write_processing
3903 1.1 skrll #define bfd_elf32_bfd_merge_private_bfd_data m32r_elf_merge_private_bfd_data
3904 1.1 skrll #define bfd_elf32_bfd_set_private_flags m32r_elf_set_private_flags
3905 1.1.1.6 christos #define bfd_elf32_bfd_print_private_bfd_data m32r_elf_print_private_bfd_data
3906 1.1.1.6 christos #define elf_backend_special_sections m32r_elf_special_sections
3907 1.1 skrll
3908 1.1.1.6 christos #define elf_backend_linux_prpsinfo32_ugid16 TRUE
3909 1.1.1.6 christos
3910 1.1.1.6 christos #include "elf32-target.h"
3911 1.1.1.6 christos
3912 1.1.1.6 christos #undef ELF_MAXPAGESIZE
3913 1.1.1.6 christos #define ELF_MAXPAGESIZE 0x1000
3914 1.1.1.6 christos
3915 1.1.1.6 christos #undef TARGET_BIG_SYM
3916 1.1.1.6 christos #define TARGET_BIG_SYM m32r_elf32_linux_vec
3917 1.1.1.6 christos #undef TARGET_BIG_NAME
3918 1.1 skrll #define TARGET_BIG_NAME "elf32-m32r-linux"
3919 1.1 skrll #undef TARGET_LITTLE_SYM
3920 #define TARGET_LITTLE_SYM m32r_elf32_linux_le_vec
3921 #undef TARGET_LITTLE_NAME
3922 #define TARGET_LITTLE_NAME "elf32-m32rle-linux"
3923 #undef elf32_bed
3924 #define elf32_bed elf32_m32r_lin_bed
3925
3926 #include "elf32-target.h"
3927