3 @@ -357,6 +357,12 @@ DESCRIPTION
4 .#define bfd_mach_avr5 5
5 .#define bfd_mach_avr51 51
6 .#define bfd_mach_avr6 6
7 +. bfd_arch_avr32, {* Atmel AVR32 *}
8 +.#define bfd_mach_avr32_ap 7000
9 +.#define bfd_mach_avr32_uc 3000
10 +.#define bfd_mach_avr32_ucr1 3001
11 +.#define bfd_mach_avr32_ucr2 3002
12 +.#define bfd_mach_avr32_ucr3 3003
13 . bfd_arch_bfin, {* ADI Blackfin *}
14 .#define bfd_mach_bfin 1
15 . bfd_arch_cr16, {* National Semiconductor CompactRISC (ie CR16). *}
16 @@ -454,6 +460,7 @@ extern const bfd_arch_info_type bfd_alph
17 extern const bfd_arch_info_type bfd_arc_arch;
18 extern const bfd_arch_info_type bfd_arm_arch;
19 extern const bfd_arch_info_type bfd_avr_arch;
20 +extern const bfd_arch_info_type bfd_avr32_arch;
21 extern const bfd_arch_info_type bfd_bfin_arch;
22 extern const bfd_arch_info_type bfd_cr16_arch;
23 extern const bfd_arch_info_type bfd_cr16c_arch;
24 @@ -526,6 +533,7 @@ static const bfd_arch_info_type * const
34 @@ -1979,6 +1979,12 @@ enum bfd_architecture
35 #define bfd_mach_avr5 5
36 #define bfd_mach_avr51 51
37 #define bfd_mach_avr6 6
38 + bfd_arch_avr32, /* Atmel AVR32 */
39 +#define bfd_mach_avr32_ap 7000
40 +#define bfd_mach_avr32_uc 3000
41 +#define bfd_mach_avr32_ucr1 3001
42 +#define bfd_mach_avr32_ucr2 3002
43 +#define bfd_mach_avr32_ucr3 3003
44 bfd_arch_bfin, /* ADI Blackfin */
45 #define bfd_mach_bfin 1
46 bfd_arch_cr16, /* National Semiconductor CompactRISC (ie CR16). */
47 @@ -3748,6 +3754,88 @@ instructions */
51 +/* Difference between two labels: L2 - L1. The value of L1 is encoded
52 +as sym + addend, while the initial difference after assembly is
53 +inserted into the object file by the assembler. */
54 + BFD_RELOC_AVR32_DIFF32,
55 + BFD_RELOC_AVR32_DIFF16,
56 + BFD_RELOC_AVR32_DIFF8,
58 +/* Reference to a symbol through the Global Offset Table. The linker
59 +will allocate an entry for symbol in the GOT and insert the offset
60 +of this entry as the relocation value. */
61 + BFD_RELOC_AVR32_GOT32,
62 + BFD_RELOC_AVR32_GOT16,
63 + BFD_RELOC_AVR32_GOT8,
65 +/* Normal (non-pc-relative) code relocations. Alignment and signedness
66 +is indicated by the suffixes. S means signed, U means unsigned. W
67 +means word-aligned, H means halfword-aligned, neither means
68 +byte-aligned (no alignment.) SUB5 is the same relocation as 16S. */
69 + BFD_RELOC_AVR32_21S,
70 + BFD_RELOC_AVR32_16U,
71 + BFD_RELOC_AVR32_16S,
72 + BFD_RELOC_AVR32_SUB5,
73 + BFD_RELOC_AVR32_8S_EXT,
75 + BFD_RELOC_AVR32_15S,
77 +/* PC-relative relocations are signed if neither 'U' nor 'S' is
78 +specified. However, we explicitly tack on a 'B' to indicate no
79 +alignment, to avoid confusion with data relocs. All of these resolve
80 +to sym + addend - offset, except the one with 'N' (negated) suffix.
81 +This particular one resolves to offset - sym - addend. */
82 + BFD_RELOC_AVR32_22H_PCREL,
83 + BFD_RELOC_AVR32_18W_PCREL,
84 + BFD_RELOC_AVR32_16B_PCREL,
85 + BFD_RELOC_AVR32_16N_PCREL,
86 + BFD_RELOC_AVR32_14UW_PCREL,
87 + BFD_RELOC_AVR32_11H_PCREL,
88 + BFD_RELOC_AVR32_10UW_PCREL,
89 + BFD_RELOC_AVR32_9H_PCREL,
90 + BFD_RELOC_AVR32_9UW_PCREL,
92 +/* Subtract the link-time address of the GOT from (symbol + addend)
93 +and insert the result. */
94 + BFD_RELOC_AVR32_GOTPC,
96 +/* Reference to a symbol through the GOT. The linker will allocate an
97 +entry for symbol in the GOT and insert the offset of this entry as
98 +the relocation value. addend must be zero. As usual, 'S' means
99 +signed, 'W' means word-aligned, etc. */
100 + BFD_RELOC_AVR32_GOTCALL,
101 + BFD_RELOC_AVR32_LDA_GOT,
102 + BFD_RELOC_AVR32_GOT21S,
103 + BFD_RELOC_AVR32_GOT18SW,
104 + BFD_RELOC_AVR32_GOT16S,
106 +/* 32-bit constant pool entry. I don't think 8- and 16-bit entries make
107 +a whole lot of sense. */
108 + BFD_RELOC_AVR32_32_CPENT,
110 +/* Constant pool references. Some of these relocations are signed,
111 +others are unsigned. It doesn't really matter, since the constant
112 +pool always comes after the code that references it. */
113 + BFD_RELOC_AVR32_CPCALL,
114 + BFD_RELOC_AVR32_16_CP,
115 + BFD_RELOC_AVR32_9W_CP,
117 +/* sym must be the absolute symbol. The addend specifies the alignment
118 +order, e.g. if addend is 2, the linker must add padding so that the
119 +next address is aligned to a 4-byte boundary. */
120 + BFD_RELOC_AVR32_ALIGN,
122 +/* Code relocations that will never make it to the output file. */
123 + BFD_RELOC_AVR32_14UW,
124 + BFD_RELOC_AVR32_10UW,
125 + BFD_RELOC_AVR32_10SW,
126 + BFD_RELOC_AVR32_STHH_W,
127 + BFD_RELOC_AVR32_7UW,
128 + BFD_RELOC_AVR32_6S,
129 + BFD_RELOC_AVR32_6UW,
130 + BFD_RELOC_AVR32_4UH,
131 + BFD_RELOC_AVR32_3U,
138 @@ -336,6 +336,10 @@ case "${targ}" in
143 + targ_defvec=bfd_elf32_avr32_vec
146 c30-*-*aout* | tic30-*-*aout*)
147 targ_defvec=tic30_aout_vec
151 @@ -19639,6 +19639,7 @@ do
152 bfd_efi_rtdrv_ia64_vec) tb="$tb efi-rtdrv-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
153 bfd_elf32_am33lin_vec) tb="$tb elf32-am33lin.lo elf32.lo $elf" ;;
154 bfd_elf32_avr_vec) tb="$tb elf32-avr.lo elf32.lo $elf" ;;
155 + bfd_elf32_avr32_vec) tb="$tb elf32-avr32.lo elf32.lo $elf" ;;
156 bfd_elf32_bfin_vec) tb="$tb elf32-bfin.lo elf32.lo $elf" ;;
157 bfd_elf32_bfinfdpic_vec) tb="$tb elf32-bfin.lo elf32.lo $elf" ;;
158 bfd_elf32_big_generic_vec) tb="$tb elf32-gen.lo elf32.lo $elf" ;;
159 --- a/bfd/configure.in
160 +++ b/bfd/configure.in
161 @@ -632,6 +632,7 @@ do
162 bfd_efi_rtdrv_ia64_vec) tb="$tb efi-rtdrv-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
163 bfd_elf32_am33lin_vec) tb="$tb elf32-am33lin.lo elf32.lo $elf" ;;
164 bfd_elf32_avr_vec) tb="$tb elf32-avr.lo elf32.lo $elf" ;;
165 + bfd_elf32_avr32_vec) tb="$tb elf32-avr32.lo elf32.lo $elf" ;;
166 bfd_elf32_bfin_vec) tb="$tb elf32-bfin.lo elf32.lo $elf" ;;
167 bfd_elf32_bfinfdpic_vec) tb="$tb elf32-bfin.lo elf32.lo $elf" ;;
168 bfd_elf32_big_generic_vec) tb="$tb elf32-gen.lo elf32.lo $elf" ;;
169 --- a/bfd/cpu-avr32.c
170 +++ b/bfd/cpu-avr32.c
172 +/* BFD library support routines for AVR32.
173 + Copyright 2003,2004,2005,2006,2007,2008,2009 Atmel Corporation.
175 + Written by Haavard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
177 + This is part of BFD, the Binary File Descriptor library.
179 + This program is free software; you can redistribute it and/or modify
180 + it under the terms of the GNU General Public License as published by
181 + the Free Software Foundation; either version 2 of the License, or
182 + (at your option) any later version.
184 + This program is distributed in the hope that it will be useful,
185 + but WITHOUT ANY WARRANTY; without even the implied warranty of
186 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187 + GNU General Public License for more details.
189 + You should have received a copy of the GNU General Public License
190 + along with this program; if not, write to the Free Software
191 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
197 +#define N(machine, print, default, next) \
199 + 32, /* 32 bits in a word */ \
200 + 32, /* 32 bits in an address */ \
201 + 8, /* 8 bits in a byte */ \
202 + bfd_arch_avr32, /* architecture */ \
203 + machine, /* machine */ \
204 + "avr32", /* arch name */ \
205 + print, /* printable name */ \
206 + 1, /* section align power */ \
207 + default, /* the default machine? */ \
208 + bfd_default_compatible, \
209 + bfd_default_scan, \
213 +static const bfd_arch_info_type cpu_info[] =
215 + N(bfd_mach_avr32_ap, "avr32:ap", FALSE, &cpu_info[1]),
216 + N(bfd_mach_avr32_uc, "avr32:uc", FALSE, &cpu_info[2]),
217 + N(bfd_mach_avr32_ucr1, "avr32:ucr1", FALSE, &cpu_info[3]),
218 + N(bfd_mach_avr32_ucr2, "avr32:ucr2", FALSE, &cpu_info[4]),
219 + N(bfd_mach_avr32_ucr3, "avr32:ucr3", FALSE, NULL),
222 +const bfd_arch_info_type bfd_avr32_arch =
223 + N(bfd_mach_avr32_ap, "avr32", TRUE, &cpu_info[0]);
224 --- a/bfd/elf32-avr32.c
225 +++ b/bfd/elf32-avr32.c
227 +/* AVR32-specific support for 32-bit ELF.
228 + Copyright 2003,2004,2005,2006,2007,2008,2009 Atmel Corporation.
230 + Written by Haavard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
232 + This file is part of BFD, the Binary File Descriptor library.
234 + This program is free software; you can redistribute it and/or modify
235 + it under the terms of the GNU General Public License as published by
236 + the Free Software Foundation; either version 2 of the License, or
237 + (at your option) any later version.
239 + This program is distributed in the hope that it will be useful,
240 + but WITHOUT ANY WARRANTY; without even the implied warranty of
241 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
242 + GNU General Public License for more details.
244 + You should have received a copy of the GNU General Public License
245 + along with this program; if not, write to the Free Software
246 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
250 +#include "bfdlink.h"
252 +#include "elf-bfd.h"
253 +#include "elf/avr32.h"
254 +#include "elf32-avr32.h"
257 +#define xRELAX_DEBUG
260 +# define pr_debug(fmt, args...) fprintf(stderr, fmt, ##args)
262 +# define pr_debug(fmt, args...) do { } while (0)
266 +# define RDBG(fmt, args...) fprintf(stderr, fmt, ##args)
268 +# define RDBG(fmt, args...) do { } while (0)
271 +/* When things go wrong, we want it to blow up, damnit! */
274 +#define BFD_ASSERT(expr) \
279 + bfd_assert(__FILE__, __LINE__); \
285 +/* The name of the dynamic interpreter. This is put in the .interp section. */
286 +#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
288 +#define AVR32_GOT_HEADER_SIZE 8
289 +#define AVR32_FUNCTION_STUB_SIZE 8
291 +#define ELF_R_INFO(x, y) ELF32_R_INFO(x, y)
292 +#define ELF_R_TYPE(x) ELF32_R_TYPE(x)
293 +#define ELF_R_SYM(x) ELF32_R_SYM(x)
295 +#define NOP_OPCODE 0xd703
298 +/* Mapping between BFD relocations and ELF relocations */
300 +static reloc_howto_type *
301 +bfd_elf32_bfd_reloc_type_lookup(bfd *abfd, bfd_reloc_code_real_type code);
303 +static reloc_howto_type *
304 +bfd_elf32_bfd_reloc_name_lookup(bfd *abfd, const char *r_name);
307 +avr32_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst);
310 +#define GENH(name, align, size, bitsize, pcrel, bitpos, complain, mask) \
311 + HOWTO(name, align, size, bitsize, pcrel, bitpos, \
312 + complain_overflow_##complain, bfd_elf_generic_reloc, #name, \
313 + FALSE, 0, mask, pcrel)
315 +static reloc_howto_type elf_avr32_howto_table[] = {
316 + /* NAME ALN SZ BSZ PCREL BP COMPLAIN MASK */
317 + GENH(R_AVR32_NONE, 0, 0, 0, FALSE, 0, dont, 0x00000000),
319 + GENH(R_AVR32_32, 0, 2, 32, FALSE, 0, dont, 0xffffffff),
320 + GENH(R_AVR32_16, 0, 1, 16, FALSE, 0, bitfield, 0x0000ffff),
321 + GENH(R_AVR32_8, 0, 0, 8, FALSE, 0, bitfield, 0x000000ff),
322 + GENH(R_AVR32_32_PCREL, 0, 2, 32, TRUE, 0, signed, 0xffffffff),
323 + GENH(R_AVR32_16_PCREL, 0, 1, 16, TRUE, 0, signed, 0x0000ffff),
324 + GENH(R_AVR32_8_PCREL, 0, 0, 8, TRUE, 0, signed, 0x000000ff),
326 + /* Difference between two symbol (sym2 - sym1). The reloc encodes
327 + the value of sym1. The field contains the difference before any
328 + relaxing is done. */
329 + GENH(R_AVR32_DIFF32, 0, 2, 32, FALSE, 0, dont, 0xffffffff),
330 + GENH(R_AVR32_DIFF16, 0, 1, 16, FALSE, 0, signed, 0x0000ffff),
331 + GENH(R_AVR32_DIFF8, 0, 0, 8, FALSE, 0, signed, 0x000000ff),
333 + GENH(R_AVR32_GOT32, 0, 2, 32, FALSE, 0, signed, 0xffffffff),
334 + GENH(R_AVR32_GOT16, 0, 1, 16, FALSE, 0, signed, 0x0000ffff),
335 + GENH(R_AVR32_GOT8, 0, 0, 8, FALSE, 0, signed, 0x000000ff),
337 + GENH(R_AVR32_21S, 0, 2, 21, FALSE, 0, signed, 0x1e10ffff),
338 + GENH(R_AVR32_16U, 0, 2, 16, FALSE, 0, unsigned, 0x0000ffff),
339 + GENH(R_AVR32_16S, 0, 2, 16, FALSE, 0, signed, 0x0000ffff),
340 + GENH(R_AVR32_8S, 0, 1, 8, FALSE, 4, signed, 0x00000ff0),
341 + GENH(R_AVR32_8S_EXT, 0, 2, 8, FALSE, 0, signed, 0x000000ff),
343 + GENH(R_AVR32_22H_PCREL, 1, 2, 21, TRUE, 0, signed, 0x1e10ffff),
344 + GENH(R_AVR32_18W_PCREL, 2, 2, 16, TRUE, 0, signed, 0x0000ffff),
345 + GENH(R_AVR32_16B_PCREL, 0, 2, 16, TRUE, 0, signed, 0x0000ffff),
346 + GENH(R_AVR32_16N_PCREL, 0, 2, 16, TRUE, 0, signed, 0x0000ffff),
347 + GENH(R_AVR32_14UW_PCREL, 2, 2, 12, TRUE, 0, unsigned, 0x0000f0ff),
348 + GENH(R_AVR32_11H_PCREL, 1, 1, 10, TRUE, 4, signed, 0x00000ff3),
349 + GENH(R_AVR32_10UW_PCREL, 2, 2, 8, TRUE, 0, unsigned, 0x000000ff),
350 + GENH(R_AVR32_9H_PCREL, 1, 1, 8, TRUE, 4, signed, 0x00000ff0),
351 + GENH(R_AVR32_9UW_PCREL, 2, 1, 7, TRUE, 4, unsigned, 0x000007f0),
353 + GENH(R_AVR32_HI16, 16, 2, 16, FALSE, 0, dont, 0x0000ffff),
354 + GENH(R_AVR32_LO16, 0, 2, 16, FALSE, 0, dont, 0x0000ffff),
356 + GENH(R_AVR32_GOTPC, 0, 2, 32, FALSE, 0, dont, 0xffffffff),
357 + GENH(R_AVR32_GOTCALL, 2, 2, 21, FALSE, 0, signed, 0x1e10ffff),
358 + GENH(R_AVR32_LDA_GOT, 2, 2, 21, FALSE, 0, signed, 0x1e10ffff),
359 + GENH(R_AVR32_GOT21S, 0, 2, 21, FALSE, 0, signed, 0x1e10ffff),
360 + GENH(R_AVR32_GOT18SW, 2, 2, 16, FALSE, 0, signed, 0x0000ffff),
361 + GENH(R_AVR32_GOT16S, 0, 2, 16, FALSE, 0, signed, 0x0000ffff),
362 + GENH(R_AVR32_GOT7UW, 2, 1, 5, FALSE, 4, unsigned, 0x000001f0),
364 + GENH(R_AVR32_32_CPENT, 0, 2, 32, FALSE, 0, dont, 0xffffffff),
365 + GENH(R_AVR32_CPCALL, 2, 2, 16, TRUE, 0, signed, 0x0000ffff),
366 + GENH(R_AVR32_16_CP, 0, 2, 16, TRUE, 0, signed, 0x0000ffff),
367 + GENH(R_AVR32_9W_CP, 2, 1, 7, TRUE, 4, unsigned, 0x000007f0),
369 + GENH(R_AVR32_RELATIVE, 0, 2, 32, FALSE, 0, signed, 0xffffffff),
370 + GENH(R_AVR32_GLOB_DAT, 0, 2, 32, FALSE, 0, dont, 0xffffffff),
371 + GENH(R_AVR32_JMP_SLOT, 0, 2, 32, FALSE, 0, dont, 0xffffffff),
373 + GENH(R_AVR32_ALIGN, 0, 1, 0, FALSE, 0, unsigned, 0x00000000),
375 + GENH(R_AVR32_15S, 2, 2, 15, FALSE, 0, signed, 0x00007fff),
378 +struct elf_reloc_map
380 + bfd_reloc_code_real_type bfd_reloc_val;
381 + unsigned char elf_reloc_val;
384 +static const struct elf_reloc_map avr32_reloc_map[] =
386 + { BFD_RELOC_NONE, R_AVR32_NONE },
388 + { BFD_RELOC_32, R_AVR32_32 },
389 + { BFD_RELOC_16, R_AVR32_16 },
390 + { BFD_RELOC_8, R_AVR32_8 },
391 + { BFD_RELOC_32_PCREL, R_AVR32_32_PCREL },
392 + { BFD_RELOC_16_PCREL, R_AVR32_16_PCREL },
393 + { BFD_RELOC_8_PCREL, R_AVR32_8_PCREL },
394 + { BFD_RELOC_AVR32_DIFF32, R_AVR32_DIFF32 },
395 + { BFD_RELOC_AVR32_DIFF16, R_AVR32_DIFF16 },
396 + { BFD_RELOC_AVR32_DIFF8, R_AVR32_DIFF8 },
397 + { BFD_RELOC_AVR32_GOT32, R_AVR32_GOT32 },
398 + { BFD_RELOC_AVR32_GOT16, R_AVR32_GOT16 },
399 + { BFD_RELOC_AVR32_GOT8, R_AVR32_GOT8 },
401 + { BFD_RELOC_AVR32_21S, R_AVR32_21S },
402 + { BFD_RELOC_AVR32_16U, R_AVR32_16U },
403 + { BFD_RELOC_AVR32_16S, R_AVR32_16S },
404 + { BFD_RELOC_AVR32_SUB5, R_AVR32_16S },
405 + { BFD_RELOC_AVR32_8S_EXT, R_AVR32_8S_EXT },
406 + { BFD_RELOC_AVR32_8S, R_AVR32_8S },
408 + { BFD_RELOC_AVR32_22H_PCREL, R_AVR32_22H_PCREL },
409 + { BFD_RELOC_AVR32_18W_PCREL, R_AVR32_18W_PCREL },
410 + { BFD_RELOC_AVR32_16B_PCREL, R_AVR32_16B_PCREL },
411 + { BFD_RELOC_AVR32_16N_PCREL, R_AVR32_16N_PCREL },
412 + { BFD_RELOC_AVR32_11H_PCREL, R_AVR32_11H_PCREL },
413 + { BFD_RELOC_AVR32_10UW_PCREL, R_AVR32_10UW_PCREL },
414 + { BFD_RELOC_AVR32_9H_PCREL, R_AVR32_9H_PCREL },
415 + { BFD_RELOC_AVR32_9UW_PCREL, R_AVR32_9UW_PCREL },
417 + { BFD_RELOC_HI16, R_AVR32_HI16 },
418 + { BFD_RELOC_LO16, R_AVR32_LO16 },
420 + { BFD_RELOC_AVR32_GOTPC, R_AVR32_GOTPC },
421 + { BFD_RELOC_AVR32_GOTCALL, R_AVR32_GOTCALL },
422 + { BFD_RELOC_AVR32_LDA_GOT, R_AVR32_LDA_GOT },
423 + { BFD_RELOC_AVR32_GOT21S, R_AVR32_GOT21S },
424 + { BFD_RELOC_AVR32_GOT18SW, R_AVR32_GOT18SW },
425 + { BFD_RELOC_AVR32_GOT16S, R_AVR32_GOT16S },
426 + /* GOT7UW should never be generated by the assembler */
428 + { BFD_RELOC_AVR32_32_CPENT, R_AVR32_32_CPENT },
429 + { BFD_RELOC_AVR32_CPCALL, R_AVR32_CPCALL },
430 + { BFD_RELOC_AVR32_16_CP, R_AVR32_16_CP },
431 + { BFD_RELOC_AVR32_9W_CP, R_AVR32_9W_CP },
433 + { BFD_RELOC_AVR32_ALIGN, R_AVR32_ALIGN },
435 + { BFD_RELOC_AVR32_15S, R_AVR32_15S },
438 +static reloc_howto_type *
439 +bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
440 + bfd_reloc_code_real_type code)
444 + for (i = 0; i < sizeof(avr32_reloc_map) / sizeof(struct elf_reloc_map); i++)
446 + if (avr32_reloc_map[i].bfd_reloc_val == code)
447 + return &elf_avr32_howto_table[avr32_reloc_map[i].elf_reloc_val];
453 +static reloc_howto_type *
454 +bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
455 + const char *r_name)
460 + i < sizeof (elf_avr32_howto_table) / sizeof (elf_avr32_howto_table[0]);
462 + if (elf_avr32_howto_table[i].name != NULL
463 + && strcasecmp (elf_avr32_howto_table[i].name, r_name) == 0)
464 + return &elf_avr32_howto_table[i];
469 +/* Set the howto pointer for an AVR32 ELF reloc. */
471 +avr32_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
472 + arelent *cache_ptr,
473 + Elf_Internal_Rela *dst)
475 + unsigned int r_type;
477 + r_type = ELF32_R_TYPE (dst->r_info);
478 + BFD_ASSERT (r_type < (unsigned int) R_AVR32_max);
479 + cache_ptr->howto = &elf_avr32_howto_table[r_type];
483 +/* AVR32 ELF linker hash table and associated hash entries. */
485 +static struct bfd_hash_entry *
486 +avr32_elf_link_hash_newfunc(struct bfd_hash_entry *entry,
487 + struct bfd_hash_table *table,
488 + const char *string);
490 +avr32_elf_copy_indirect_symbol(struct bfd_link_info *info,
491 + struct elf_link_hash_entry *dir,
492 + struct elf_link_hash_entry *ind);
493 +static struct bfd_link_hash_table *
494 +avr32_elf_link_hash_table_create(bfd *abfd);
497 + Try to limit memory usage to something reasonable when sorting the
498 + GOT. If just a couple of entries end up getting more references
499 + than this, it won't affect performance at all, but if there are many
500 + of them, we could end up with the wrong symbols being assigned the
503 +#define MAX_NR_GOT_HOLES 2048
506 + AVR32 GOT entry. We need to keep track of refcounts and offsets
507 + simultaneously, since we need the offsets during relaxation, and we
508 + also want to be able to drop GOT entries during relaxation. In
509 + addition to this, we want to keep the list of GOT entries sorted so
510 + that we can keep the most-used entries at the lowest offsets.
514 + struct got_entry *next;
515 + struct got_entry **pprev;
517 + bfd_signed_vma offset;
520 +struct elf_avr32_link_hash_entry
522 + struct elf_link_hash_entry root;
524 + /* Number of runtime relocations against this symbol. */
525 + unsigned int possibly_dynamic_relocs;
527 + /* If there are anything but R_AVR32_GOT18 relocations against this
528 + symbol, it means that someone may be taking the address of the
529 + function, and we should therefore not create a stub. */
530 + bfd_boolean no_fn_stub;
532 + /* If there is a R_AVR32_32 relocation in a read-only section
533 + against this symbol, we could be in trouble. If we're linking a
534 + shared library or this symbol is defined in one, it means we must
535 + emit a run-time reloc for it and that's not allowed in read-only
537 + asection *readonly_reloc_sec;
538 + bfd_vma readonly_reloc_offset;
540 + /* Record which frag (if any) contains the symbol. This is used
541 + during relaxation in order to avoid having to update all symbols
542 + whenever we move something. For local symbols, this information
543 + is in the local_sym_frag member of struct elf_obj_tdata. */
544 + struct fragment *sym_frag;
546 +#define avr32_elf_hash_entry(ent) ((struct elf_avr32_link_hash_entry *)(ent))
548 +struct elf_avr32_link_hash_table
550 + struct elf_link_hash_table root;
552 + /* Shortcuts to get to dynamic linker sections. */
557 + /* We use a variation of Pigeonhole Sort to sort the GOT. After the
558 + initial refcounts have been determined, we initialize
559 + nr_got_holes to the highest refcount ever seen and allocate an
560 + array of nr_got_holes entries for got_hole. Each GOT entry is
561 + then stored in this array at the index given by its refcount.
563 + When a GOT entry has its refcount decremented during relaxation,
564 + it is moved to a lower index in the got_hole array.
566 + struct got_entry **got_hole;
569 + /* Dynamic relocations to local symbols. Only used when linking a
570 + shared library and -Bsymbolic is not given. */
571 + unsigned int local_dynamic_relocs;
573 + bfd_boolean relocations_analyzed;
574 + bfd_boolean symbols_adjusted;
575 + bfd_boolean repeat_pass;
576 + bfd_boolean direct_data_refs;
577 + unsigned int relax_iteration;
578 + unsigned int relax_pass;
580 +#define avr32_elf_hash_table(p) \
581 + ((struct elf_avr32_link_hash_table *)((p)->hash))
583 +static struct bfd_hash_entry *
584 +avr32_elf_link_hash_newfunc(struct bfd_hash_entry *entry,
585 + struct bfd_hash_table *table,
586 + const char *string)
588 + struct elf_avr32_link_hash_entry *ret = avr32_elf_hash_entry(entry);
590 + /* Allocate the structure if it hasn't already been allocated by a
593 + ret = (struct elf_avr32_link_hash_entry *)
594 + bfd_hash_allocate(table, sizeof(struct elf_avr32_link_hash_entry));
599 + memset(ret, 0, sizeof(struct elf_avr32_link_hash_entry));
601 + /* Give the superclass a chance */
602 + ret = (struct elf_avr32_link_hash_entry *)
603 + _bfd_elf_link_hash_newfunc((struct bfd_hash_entry *)ret, table, string);
605 + return (struct bfd_hash_entry *)ret;
608 +/* Copy data from an indirect symbol to its direct symbol, hiding the
609 + old indirect symbol. Process additional relocation information.
610 + Also called for weakdefs, in which case we just let
611 + _bfd_elf_link_hash_copy_indirect copy the flags for us. */
614 +avr32_elf_copy_indirect_symbol(struct bfd_link_info *info,
615 + struct elf_link_hash_entry *dir,
616 + struct elf_link_hash_entry *ind)
618 + struct elf_avr32_link_hash_entry *edir, *eind;
620 + _bfd_elf_link_hash_copy_indirect (info, dir, ind);
622 + if (ind->root.type != bfd_link_hash_indirect)
625 + edir = (struct elf_avr32_link_hash_entry *)dir;
626 + eind = (struct elf_avr32_link_hash_entry *)ind;
628 + edir->possibly_dynamic_relocs += eind->possibly_dynamic_relocs;
629 + edir->no_fn_stub = edir->no_fn_stub || eind->no_fn_stub;
632 +static struct bfd_link_hash_table *
633 +avr32_elf_link_hash_table_create(bfd *abfd)
635 + struct elf_avr32_link_hash_table *ret;
637 + ret = bfd_zmalloc(sizeof(*ret));
641 + if (! _bfd_elf_link_hash_table_init(&ret->root, abfd,
642 + avr32_elf_link_hash_newfunc,
643 + sizeof (struct elf_avr32_link_hash_entry)))
649 + /* Prevent the BFD core from creating bogus got_entry pointers */
650 + ret->root.init_got_refcount.glist = NULL;
651 + ret->root.init_plt_refcount.glist = NULL;
652 + ret->root.init_got_offset.glist = NULL;
653 + ret->root.init_plt_offset.glist = NULL;
655 + return &ret->root.root;
659 +/* Initial analysis and creation of dynamic sections and symbols */
662 +create_dynamic_section(bfd *dynobj, const char *name, flagword flags,
663 + unsigned int align_power);
664 +static struct elf_link_hash_entry *
665 +create_dynamic_symbol(bfd *dynobj, struct bfd_link_info *info,
666 + const char *name, asection *sec,
669 +avr32_elf_create_got_section (bfd *dynobj, struct bfd_link_info *info);
671 +avr32_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info);
673 +avr32_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
674 + const Elf_Internal_Rela *relocs);
676 +avr32_elf_adjust_dynamic_symbol(struct bfd_link_info *info,
677 + struct elf_link_hash_entry *h);
680 +create_dynamic_section(bfd *dynobj, const char *name, flagword flags,
681 + unsigned int align_power)
685 + sec = bfd_make_section(dynobj, name);
687 + || !bfd_set_section_flags(dynobj, sec, flags)
688 + || !bfd_set_section_alignment(dynobj, sec, align_power))
694 +static struct elf_link_hash_entry *
695 +create_dynamic_symbol(bfd *dynobj, struct bfd_link_info *info,
696 + const char *name, asection *sec,
699 + struct bfd_link_hash_entry *bh = NULL;
700 + struct elf_link_hash_entry *h;
701 + const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
703 + if (!(_bfd_generic_link_add_one_symbol
704 + (info, dynobj, name, BSF_GLOBAL, sec, offset, NULL, FALSE,
705 + bed->collect, &bh)))
708 + h = (struct elf_link_hash_entry *)bh;
709 + h->def_regular = 1;
710 + h->type = STT_OBJECT;
711 + h->other = STV_HIDDEN;
717 +avr32_elf_create_got_section (bfd *dynobj, struct bfd_link_info *info)
719 + struct elf_avr32_link_hash_table *htab;
721 + const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
723 + htab = avr32_elf_hash_table(info);
724 + flags = bed->dynamic_sec_flags;
729 + htab->sgot = create_dynamic_section(dynobj, ".got", flags, 2);
730 + if (!htab->srelgot)
731 + htab->srelgot = create_dynamic_section(dynobj, ".rela.got",
732 + flags | SEC_READONLY, 2);
734 + if (!htab->sgot || !htab->srelgot)
737 + htab->root.hgot = create_dynamic_symbol(dynobj, info, "_GLOBAL_OFFSET_TABLE_",
739 + if (!htab->root.hgot)
742 + /* Make room for the GOT header */
743 + htab->sgot->size += bed->got_header_size;
748 +/* (1) Create all dynamic (i.e. linker generated) sections that we may
749 + need during the link */
752 +avr32_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
754 + struct elf_avr32_link_hash_table *htab;
756 + const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
758 + pr_debug("(1) create dynamic sections\n");
760 + htab = avr32_elf_hash_table(info);
761 + flags = bed->dynamic_sec_flags;
763 + if (!avr32_elf_create_got_section (dynobj, info))
767 + htab->sstub = create_dynamic_section(dynobj, ".stub",
768 + flags | SEC_READONLY | SEC_CODE, 2);
776 +/* (2) Go through all the relocs and count any potential GOT- or
777 + PLT-references to each symbol */
780 +avr32_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
781 + const Elf_Internal_Rela *relocs)
783 + Elf_Internal_Shdr *symtab_hdr;
784 + struct elf_avr32_link_hash_table *htab;
785 + struct elf_link_hash_entry **sym_hashes;
786 + const Elf_Internal_Rela *rel, *rel_end;
787 + struct got_entry **local_got_ents;
788 + struct got_entry *got;
789 + const struct elf_backend_data *bed = get_elf_backend_data (abfd);
793 + pr_debug("(2) check relocs for %s:<%s> (size 0x%lx)\n",
794 + abfd->filename, sec->name, sec->size);
796 + if (info->relocatable)
799 + dynobj = elf_hash_table(info)->dynobj;
800 + symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
801 + sym_hashes = elf_sym_hashes(abfd);
802 + htab = avr32_elf_hash_table(info);
803 + local_got_ents = elf_local_got_ents(abfd);
806 + rel_end = relocs + sec->reloc_count;
807 + for (rel = relocs; rel < rel_end; rel++)
809 + unsigned long r_symndx, r_type;
810 + struct elf_avr32_link_hash_entry *h;
812 + r_symndx = ELF32_R_SYM(rel->r_info);
813 + r_type = ELF32_R_TYPE(rel->r_info);
815 + /* Local symbols use local_got_ents, while others store the same
816 + information in the hash entry */
817 + if (r_symndx < symtab_hdr->sh_info)
819 + pr_debug(" (2a) processing local symbol %lu\n", r_symndx);
824 + h = (struct elf_avr32_link_hash_entry *)
825 + sym_hashes[r_symndx - symtab_hdr->sh_info];
826 + while (h->root.type == bfd_link_hash_indirect
827 + || h->root.type == bfd_link_hash_warning)
828 + h = (struct elf_avr32_link_hash_entry *)h->root.root.u.i.link;
829 + pr_debug(" (2a) processing symbol %s\n", h->root.root.root.string);
832 + /* Some relocs require special sections to be created. */
835 + case R_AVR32_GOT32:
836 + case R_AVR32_GOT16:
838 + case R_AVR32_GOT21S:
839 + case R_AVR32_GOT18SW:
840 + case R_AVR32_GOT16S:
841 + case R_AVR32_GOT7UW:
842 + case R_AVR32_LDA_GOT:
843 + case R_AVR32_GOTCALL:
846 + if (info->callbacks->reloc_dangerous
847 + (info, _("Non-zero addend on GOT-relative relocation"),
848 + abfd, sec, rel->r_offset) == FALSE)
852 + case R_AVR32_GOTPC:
853 + if (dynobj == NULL)
854 + elf_hash_table(info)->dynobj = dynobj = abfd;
855 + if (sgot == NULL && !avr32_elf_create_got_section(dynobj, info))
859 + /* We may need to create .rela.dyn later on. */
861 + && (info->shared || h != NULL)
862 + && (sec->flags & SEC_ALLOC))
863 + elf_hash_table(info)->dynobj = dynobj = abfd;
867 + if (h != NULL && r_type != R_AVR32_GOT18SW)
868 + h->no_fn_stub = TRUE;
872 + case R_AVR32_GOT32:
873 + case R_AVR32_GOT16:
875 + case R_AVR32_GOT21S:
876 + case R_AVR32_GOT18SW:
877 + case R_AVR32_GOT16S:
878 + case R_AVR32_GOT7UW:
879 + case R_AVR32_LDA_GOT:
880 + case R_AVR32_GOTCALL:
883 + got = h->root.got.glist;
886 + got = bfd_zalloc(abfd, sizeof(struct got_entry));
889 + h->root.got.glist = got;
894 + if (!local_got_ents)
896 + bfd_size_type size;
898 + struct got_entry *tmp_entry;
900 + size = symtab_hdr->sh_info;
901 + size *= sizeof(struct got_entry *) + sizeof(struct got_entry);
902 + local_got_ents = bfd_zalloc(abfd, size);
903 + if (!local_got_ents)
906 + elf_local_got_ents(abfd) = local_got_ents;
908 + tmp_entry = (struct got_entry *)(local_got_ents
909 + + symtab_hdr->sh_info);
910 + for (i = 0; i < symtab_hdr->sh_info; i++)
911 + local_got_ents[i] = &tmp_entry[i];
914 + got = local_got_ents[r_symndx];
918 + if (got->refcount > htab->nr_got_holes)
919 + htab->nr_got_holes = got->refcount;
923 + if ((info->shared || h != NULL)
924 + && (sec->flags & SEC_ALLOC))
926 + if (htab->srelgot == NULL)
928 + htab->srelgot = create_dynamic_section(dynobj, ".rela.got",
929 + bed->dynamic_sec_flags
930 + | SEC_READONLY, 2);
931 + if (htab->srelgot == NULL)
935 + if (sec->flags & SEC_READONLY
936 + && !h->readonly_reloc_sec)
938 + h->readonly_reloc_sec = sec;
939 + h->readonly_reloc_offset = rel->r_offset;
944 + pr_debug("Non-GOT reference to symbol %s\n",
945 + h->root.root.root.string);
946 + h->possibly_dynamic_relocs++;
950 + pr_debug("Non-GOT reference to local symbol %lu\n",
952 + htab->local_dynamic_relocs++;
958 + /* TODO: GNU_VTINHERIT and GNU_VTENTRY */
965 +/* (3) Adjust a symbol defined by a dynamic object and referenced by a
966 + regular object. The current definition is in some section of the
967 + dynamic object, but we're not including those sections. We have to
968 + change the definition to something the rest of the link can
972 +avr32_elf_adjust_dynamic_symbol(struct bfd_link_info *info,
973 + struct elf_link_hash_entry *h)
975 + struct elf_avr32_link_hash_table *htab;
976 + struct elf_avr32_link_hash_entry *havr;
979 + pr_debug("(3) adjust dynamic symbol %s\n", h->root.root.string);
981 + htab = avr32_elf_hash_table(info);
982 + havr = (struct elf_avr32_link_hash_entry *)h;
983 + dynobj = elf_hash_table(info)->dynobj;
985 + /* Make sure we know what is going on here. */
986 + BFD_ASSERT (dynobj != NULL
987 + && (h->u.weakdef != NULL
990 + && !h->def_regular)));
992 + /* We don't want dynamic relocations in read-only sections. */
993 + if (havr->readonly_reloc_sec)
995 + if (info->callbacks->reloc_dangerous
996 + (info, _("dynamic relocation in read-only section"),
997 + havr->readonly_reloc_sec->owner, havr->readonly_reloc_sec,
998 + havr->readonly_reloc_offset) == FALSE)
1002 + /* If this is a function, create a stub if possible and set the
1003 + symbol to the stub location. */
1004 + if (0 && !havr->no_fn_stub)
1006 + if (!h->def_regular)
1008 + asection *s = htab->sstub;
1010 + BFD_ASSERT(s != NULL);
1012 + h->root.u.def.section = s;
1013 + h->root.u.def.value = s->size;
1014 + h->plt.offset = s->size;
1015 + s->size += AVR32_FUNCTION_STUB_SIZE;
1020 + else if (h->type == STT_FUNC)
1022 + /* This will set the entry for this symbol in the GOT to 0, and
1023 + the dynamic linker will take care of this. */
1024 + h->root.u.def.value = 0;
1028 + /* If this is a weak symbol, and there is a real definition, the
1029 + processor independent code will have arranged for us to see the
1030 + real definition first, and we can just use the same value. */
1031 + if (h->u.weakdef != NULL)
1033 + BFD_ASSERT(h->u.weakdef->root.type == bfd_link_hash_defined
1034 + || h->u.weakdef->root.type == bfd_link_hash_defweak);
1035 + h->root.u.def.section = h->u.weakdef->root.u.def.section;
1036 + h->root.u.def.value = h->u.weakdef->root.u.def.value;
1040 + /* This is a reference to a symbol defined by a dynamic object which
1041 + is not a function. */
1047 +/* Garbage-collection of unused sections */
1050 +avr32_elf_gc_mark_hook(asection *sec,
1051 + struct bfd_link_info *info ATTRIBUTE_UNUSED,
1052 + Elf_Internal_Rela *rel,
1053 + struct elf_link_hash_entry *h,
1054 + Elf_Internal_Sym *sym)
1058 + switch (ELF32_R_TYPE(rel->r_info))
1060 + /* TODO: VTINHERIT/VTENTRY */
1062 + switch (h->root.type)
1064 + case bfd_link_hash_defined:
1065 + case bfd_link_hash_defweak:
1066 + return h->root.u.def.section;
1068 + case bfd_link_hash_common:
1069 + return h->root.u.c.p->section;
1077 + return bfd_section_from_elf_index(sec->owner, sym->st_shndx);
1082 +/* Update the GOT entry reference counts for the section being removed. */
1084 +avr32_elf_gc_sweep_hook(bfd *abfd,
1085 + struct bfd_link_info *info ATTRIBUTE_UNUSED,
1087 + const Elf_Internal_Rela *relocs)
1089 + Elf_Internal_Shdr *symtab_hdr;
1090 + struct elf_avr32_link_hash_entry **sym_hashes;
1091 + struct got_entry **local_got_ents;
1092 + const Elf_Internal_Rela *rel, *relend;
1094 + if (!(sec->flags & SEC_ALLOC))
1097 + symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
1098 + sym_hashes = (struct elf_avr32_link_hash_entry **)elf_sym_hashes(abfd);
1099 + local_got_ents = elf_local_got_ents(abfd);
1101 + relend = relocs + sec->reloc_count;
1102 + for (rel = relocs; rel < relend; rel++)
1104 + unsigned long r_symndx;
1105 + unsigned int r_type;
1106 + struct elf_avr32_link_hash_entry *h = NULL;
1108 + r_symndx = ELF32_R_SYM(rel->r_info);
1109 + if (r_symndx >= symtab_hdr->sh_info)
1111 + h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1112 + while (h->root.root.type == bfd_link_hash_indirect
1113 + || h->root.root.type == bfd_link_hash_warning)
1114 + h = (struct elf_avr32_link_hash_entry *)h->root.root.u.i.link;
1117 + r_type = ELF32_R_TYPE(rel->r_info);
1121 + case R_AVR32_GOT32:
1122 + case R_AVR32_GOT16:
1123 + case R_AVR32_GOT8:
1124 + case R_AVR32_GOT21S:
1125 + case R_AVR32_GOT18SW:
1126 + case R_AVR32_GOT16S:
1127 + case R_AVR32_GOT7UW:
1128 + case R_AVR32_LDA_GOT:
1129 + case R_AVR32_GOTCALL:
1131 + h->root.got.glist->refcount--;
1133 + local_got_ents[r_symndx]->refcount--;
1137 + if (info->shared || h)
1140 + h->possibly_dynamic_relocs--;
1142 + avr32_elf_hash_table(info)->local_dynamic_relocs--;
1153 +/* Sizing and refcounting of dynamic sections */
1156 +insert_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got);
1158 +unref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got);
1160 +ref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got);
1162 +assign_got_offsets(struct elf_avr32_link_hash_table *htab);
1164 +allocate_dynrelocs(struct elf_link_hash_entry *h, void *_info);
1166 +avr32_elf_size_dynamic_sections (bfd *output_bfd,
1167 + struct bfd_link_info *info);
1170 +insert_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got)
1172 + /* Any entries with got_refcount > htab->nr_got_holes end up in the
1173 + * last pigeonhole without any sorting. We expect the number of such
1174 + * entries to be small, so it is very unlikely to affect
1176 + int entry = got->refcount;
1178 + if (entry > htab->nr_got_holes)
1179 + entry = htab->nr_got_holes;
1181 + got->pprev = &htab->got_hole[entry];
1182 + got->next = htab->got_hole[entry];
1185 + got->next->pprev = &got->next;
1187 + htab->got_hole[entry] = got;
1190 +/* Decrement the refcount of a GOT entry and update its position in
1191 + the pigeonhole array. */
1193 +unref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got)
1195 + BFD_ASSERT(got->refcount > 0);
1198 + got->next->pprev = got->pprev;
1200 + *(got->pprev) = got->next;
1202 + insert_got_entry(htab, got);
1206 +ref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got)
1209 + got->next->pprev = got->pprev;
1211 + *(got->pprev) = got->next;
1213 + insert_got_entry(htab, got);
1215 + BFD_ASSERT(got->refcount > 0);
1218 +/* Assign offsets to all GOT entries we intend to keep. The entries
1219 + that are referenced most often are placed at low offsets so that we
1220 + can use compact instructions as much as possible.
1222 + Returns TRUE if any offsets or the total size of the GOT changed. */
1225 +assign_got_offsets(struct elf_avr32_link_hash_table *htab)
1227 + struct got_entry *got;
1228 + bfd_size_type got_size = 0;
1229 + bfd_boolean changed = FALSE;
1230 + bfd_signed_vma offset;
1233 + /* The GOT header provides the address of the DYNAMIC segment, so
1234 + we need that even if the GOT is otherwise empty. */
1235 + if (htab->root.dynamic_sections_created)
1236 + got_size = AVR32_GOT_HEADER_SIZE;
1238 + for (i = htab->nr_got_holes; i > 0; i--)
1240 + got = htab->got_hole[i];
1243 + if (got->refcount > 0)
1245 + offset = got_size;
1246 + if (got->offset != offset)
1248 + RDBG("GOT offset changed: %ld -> %ld\n",
1249 + got->offset, offset);
1252 + got->offset = offset;
1259 + if (htab->sgot->size != got_size)
1261 + RDBG("GOT size changed: %lu -> %lu\n", htab->sgot->size,
1265 + htab->sgot->size = got_size;
1267 + RDBG("assign_got_offsets: total size %lu (%s)\n",
1268 + got_size, changed ? "changed" : "no change");
1274 +allocate_dynrelocs(struct elf_link_hash_entry *h, void *_info)
1276 + struct bfd_link_info *info = _info;
1277 + struct elf_avr32_link_hash_table *htab;
1278 + struct elf_avr32_link_hash_entry *havr;
1279 + struct got_entry *got;
1281 + pr_debug(" (4b) allocate_dynrelocs: %s\n", h->root.root.string);
1283 + if (h->root.type == bfd_link_hash_indirect)
1286 + if (h->root.type == bfd_link_hash_warning)
1287 + /* When warning symbols are created, they **replace** the "real"
1288 + entry in the hash table, thus we never get to see the real
1289 + symbol in a hash traversal. So look at it now. */
1290 + h = (struct elf_link_hash_entry *) h->root.u.i.link;
1292 + htab = avr32_elf_hash_table(info);
1293 + havr = (struct elf_avr32_link_hash_entry *)h;
1295 + got = h->got.glist;
1297 + /* If got is NULL, the symbol is never referenced through the GOT */
1298 + if (got && got->refcount > 0)
1300 + insert_got_entry(htab, got);
1302 + /* Shared libraries need relocs for all GOT entries unless the
1303 + symbol is forced local or -Bsymbolic is used. Others need
1304 + relocs for everything that is not guaranteed to be defined in
1305 + a regular object. */
1307 + && !info->symbolic
1308 + && h->dynindx != -1)
1309 + || (htab->root.dynamic_sections_created
1311 + && !h->def_regular))
1312 + htab->srelgot->size += sizeof(Elf32_External_Rela);
1315 + if (havr->possibly_dynamic_relocs
1317 + || (elf_hash_table(info)->dynamic_sections_created
1319 + && !h->def_regular)))
1321 + pr_debug("Allocating %d dynamic reloc against symbol %s...\n",
1322 + havr->possibly_dynamic_relocs, h->root.root.string);
1323 + htab->srelgot->size += (havr->possibly_dynamic_relocs
1324 + * sizeof(Elf32_External_Rela));
1330 +/* (4) Calculate the sizes of the linker-generated sections and
1331 + allocate memory for them. */
1334 +avr32_elf_size_dynamic_sections (bfd *output_bfd,
1335 + struct bfd_link_info *info)
1337 + struct elf_avr32_link_hash_table *htab;
1341 + bfd_boolean relocs;
1343 + pr_debug("(4) size dynamic sections\n");
1345 + htab = avr32_elf_hash_table(info);
1346 + dynobj = htab->root.dynobj;
1347 + BFD_ASSERT(dynobj != NULL);
1349 + if (htab->root.dynamic_sections_created)
1351 + /* Initialize the contents of the .interp section to the name of
1352 + the dynamic loader */
1353 + if (info->executable)
1355 + s = bfd_get_section_by_name(dynobj, ".interp");
1356 + BFD_ASSERT(s != NULL);
1357 + s->size = sizeof(ELF_DYNAMIC_INTERPRETER);
1358 + s->contents = (unsigned char *)ELF_DYNAMIC_INTERPRETER;
1362 + if (htab->nr_got_holes > 0)
1364 + /* Allocate holes for the pigeonhole sort algorithm */
1365 + pr_debug("Highest GOT refcount: %d\n", htab->nr_got_holes);
1367 + /* Limit the memory usage by clipping the number of pigeonholes
1368 + * at a predefined maximum. All entries with a higher refcount
1369 + * will end up in the last pigeonhole. */
1370 + if (htab->nr_got_holes >= MAX_NR_GOT_HOLES)
1372 + htab->nr_got_holes = MAX_NR_GOT_HOLES - 1;
1374 + pr_debug("Limiting maximum number of GOT pigeonholes to %u\n",
1375 + htab->nr_got_holes);
1377 + htab->got_hole = bfd_zalloc(output_bfd,
1378 + sizeof(struct got_entry *)
1379 + * (htab->nr_got_holes + 1));
1380 + if (!htab->got_hole)
1383 + /* Set up .got offsets for local syms. */
1384 + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1386 + struct got_entry **local_got;
1387 + struct got_entry **end_local_got;
1388 + Elf_Internal_Shdr *symtab_hdr;
1389 + bfd_size_type locsymcount;
1391 + pr_debug(" (4a) processing file %s...\n", ibfd->filename);
1393 + BFD_ASSERT(bfd_get_flavour(ibfd) == bfd_target_elf_flavour);
1395 + local_got = elf_local_got_ents(ibfd);
1399 + symtab_hdr = &elf_tdata(ibfd)->symtab_hdr;
1400 + locsymcount = symtab_hdr->sh_info;
1401 + end_local_got = local_got + locsymcount;
1403 + for (; local_got < end_local_got; ++local_got)
1404 + insert_got_entry(htab, *local_got);
1408 + /* Allocate global sym .got entries and space for global sym
1410 + elf_link_hash_traverse(&htab->root, allocate_dynrelocs, info);
1412 + /* Now that we have sorted the GOT entries, we are ready to
1413 + assign offsets and determine the initial size of the GOT. */
1415 + assign_got_offsets(htab);
1417 + /* Allocate space for local sym dynamic relocs */
1418 + BFD_ASSERT(htab->local_dynamic_relocs == 0 || info->shared);
1419 + if (htab->local_dynamic_relocs)
1420 + htab->srelgot->size += (htab->local_dynamic_relocs
1421 + * sizeof(Elf32_External_Rela));
1423 + /* We now have determined the sizes of the various dynamic
1424 + sections. Allocate memory for them. */
1426 + for (s = dynobj->sections; s; s = s->next)
1428 + if ((s->flags & SEC_LINKER_CREATED) == 0)
1431 + if (s == htab->sgot
1432 + || s == htab->sstub)
1434 + /* Strip this section if we don't need it */
1436 + else if (strncmp (bfd_get_section_name(dynobj, s), ".rela", 5) == 0)
1441 + s->reloc_count = 0;
1445 + /* It's not one of our sections */
1451 + /* Strip unneeded sections */
1452 + pr_debug("Stripping section %s from output...\n", s->name);
1453 + /* deleted function in 2.17
1454 + _bfd_strip_section_from_output(info, s);
1459 + s->contents = bfd_zalloc(dynobj, s->size);
1460 + if (s->contents == NULL)
1464 + if (htab->root.dynamic_sections_created)
1466 + /* Add some entries to the .dynamic section. We fill in the
1467 + values later, in sh_elf_finish_dynamic_sections, but we
1468 + must add the entries now so that we get the correct size for
1469 + the .dynamic section. The DT_DEBUG entry is filled in by the
1470 + dynamic linker and used by the debugger. */
1471 +#define add_dynamic_entry(TAG, VAL) _bfd_elf_add_dynamic_entry(info, TAG, VAL)
1473 + if (!add_dynamic_entry(DT_PLTGOT, 0))
1475 + if (!add_dynamic_entry(DT_AVR32_GOTSZ, 0))
1478 + if (info->executable)
1480 + if (!add_dynamic_entry(DT_DEBUG, 0))
1485 + if (!add_dynamic_entry(DT_RELA, 0)
1486 + || !add_dynamic_entry(DT_RELASZ, 0)
1487 + || !add_dynamic_entry(DT_RELAENT,
1488 + sizeof(Elf32_External_Rela)))
1492 +#undef add_dynamic_entry
1498 +/* Access to internal relocations, section contents and symbols.
1499 + (stolen from the xtensa port) */
1501 +static Elf_Internal_Rela *
1502 +retrieve_internal_relocs (bfd *abfd, asection *sec, bfd_boolean keep_memory);
1504 +pin_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs);
1506 +release_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs);
1508 +retrieve_contents (bfd *abfd, asection *sec, bfd_boolean keep_memory);
1511 +pin_contents (asection *sec, bfd_byte *contents);
1514 +release_contents (asection *sec, bfd_byte *contents);
1515 +static Elf_Internal_Sym *
1516 +retrieve_local_syms (bfd *input_bfd, bfd_boolean keep_memory);
1519 +pin_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf);
1522 +release_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf);
1524 +/* During relaxation, we need to modify relocations, section contents,
1525 + and symbol definitions, and we need to keep the original values from
1526 + being reloaded from the input files, i.e., we need to "pin" the
1527 + modified values in memory. We also want to continue to observe the
1528 + setting of the "keep-memory" flag. The following functions wrap the
1529 + standard BFD functions to take care of this for us. */
1531 +static Elf_Internal_Rela *
1532 +retrieve_internal_relocs (bfd *abfd, asection *sec, bfd_boolean keep_memory)
1534 + /* _bfd_elf_link_read_relocs knows about caching, so no need for us
1535 + to be clever here. */
1536 + return _bfd_elf_link_read_relocs(abfd, sec, NULL, NULL, keep_memory);
1540 +pin_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs)
1542 + elf_section_data (sec)->relocs = internal_relocs;
1546 +release_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs)
1548 + if (internal_relocs
1549 + && elf_section_data (sec)->relocs != internal_relocs)
1550 + free (internal_relocs);
1554 +retrieve_contents (bfd *abfd, asection *sec, bfd_boolean keep_memory)
1556 + bfd_byte *contents;
1557 + bfd_size_type sec_size;
1559 + sec_size = bfd_get_section_limit (abfd, sec);
1560 + contents = elf_section_data (sec)->this_hdr.contents;
1562 + if (contents == NULL && sec_size != 0)
1564 + if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1571 + elf_section_data (sec)->this_hdr.contents = contents;
1578 +pin_contents (asection *sec, bfd_byte *contents)
1580 + elf_section_data (sec)->this_hdr.contents = contents;
1584 +release_contents (asection *sec, bfd_byte *contents)
1586 + if (contents && elf_section_data (sec)->this_hdr.contents != contents)
1590 +static Elf_Internal_Sym *
1591 +retrieve_local_syms (bfd *input_bfd, bfd_boolean keep_memory)
1593 + Elf_Internal_Shdr *symtab_hdr;
1594 + Elf_Internal_Sym *isymbuf;
1595 + size_t locsymcount;
1597 + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1598 + locsymcount = symtab_hdr->sh_info;
1600 + isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1601 + if (isymbuf == NULL && locsymcount != 0)
1603 + isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
1604 + NULL, NULL, NULL);
1605 + if (isymbuf && keep_memory)
1606 + symtab_hdr->contents = (unsigned char *) isymbuf;
1614 +pin_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf)
1616 + elf_tdata (input_bfd)->symtab_hdr.contents = (unsigned char *)isymbuf;
1621 +release_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf)
1623 + if (isymbuf && (elf_tdata (input_bfd)->symtab_hdr.contents
1624 + != (unsigned char *)isymbuf))
1628 +
\f/* Data structures used during relaxation. */
1630 +enum relax_state_id {
1660 +enum reference_type {
1670 + enum relax_state_id id;
1671 + enum relax_state_id direct;
1672 + enum relax_state_id next;
1673 + enum relax_state_id prev;
1675 + enum reference_type reftype;
1677 + unsigned int r_type;
1680 + bfd_vma opcode_mask;
1682 + bfd_signed_vma range_min;
1683 + bfd_signed_vma range_max;
1685 + bfd_size_type size;
1689 + * This is for relocs that
1690 + * a) has an addend or is of type R_AVR32_DIFF32, and
1691 + * b) references a different section than it's in, and
1692 + * c) references a section that is relaxable
1694 + * as well as relocs that references the constant pool, in which case
1695 + * the add_frag member points to the frag containing the constant pool
1698 + * Such relocs must be fixed up whenever we delete any code. Sections
1699 + * that don't have any relocs with all of the above properties don't
1700 + * have any additional reloc data, but sections that do will have
1701 + * additional data for all its relocs.
1703 +struct avr32_reloc_data
1705 + struct fragment *add_frag;
1706 + struct fragment *sub_frag;
1710 + * A 'fragment' is a relaxable entity, that is, code may be added or
1711 + * deleted at the end of a fragment. When this happens, all subsequent
1712 + * fragments in the list will have their offsets updated.
1716 + enum relax_state_id state;
1717 + enum relax_state_id initial_state;
1719 + Elf_Internal_Rela *rela;
1720 + bfd_size_type size;
1723 + int offset_adjust;
1724 + bfd_boolean has_grown;
1726 + /* Only used by constant pool entries. When this drops to zero, the
1727 + frag is discarded (i.e. size_adjust is set to -4.) */
1731 +struct avr32_relax_data
1733 + unsigned int frag_count;
1734 + struct fragment *frag;
1735 + struct avr32_reloc_data *reloc_data;
1737 + /* TRUE if this section has one or more relaxable relocations */
1738 + bfd_boolean is_relaxable;
1739 + unsigned int iteration;
1742 +struct avr32_section_data
1744 + struct bfd_elf_section_data elf;
1745 + struct avr32_relax_data relax_data;
1748 +
\f/* Relax state definitions */
1750 +#define PIC_MOV2_OPCODE 0xe0600000
1751 +#define PIC_MOV2_MASK 0xe1e00000
1752 +#define PIC_MOV2_RANGE_MIN (-1048576 * 4)
1753 +#define PIC_MOV2_RANGE_MAX (1048575 * 4)
1754 +#define PIC_MCALL_OPCODE 0xf0160000
1755 +#define PIC_MCALL_MASK 0xffff0000
1756 +#define PIC_MCALL_RANGE_MIN (-131072)
1757 +#define PIC_MCALL_RANGE_MAX (131068)
1758 +#define RCALL2_OPCODE 0xe0a00000
1759 +#define RCALL2_MASK 0xe1ef0000
1760 +#define RCALL2_RANGE_MIN (-2097152)
1761 +#define RCALL2_RANGE_MAX (2097150)
1762 +#define RCALL1_OPCODE 0xc00c0000
1763 +#define RCALL1_MASK 0xf00c0000
1764 +#define RCALL1_RANGE_MIN (-1024)
1765 +#define RCALL1_RANGE_MAX (1022)
1766 +#define PIC_LDW4_OPCODE 0xecf00000
1767 +#define PIC_LDW4_MASK 0xfff00000
1768 +#define PIC_LDW4_RANGE_MIN (-32768)
1769 +#define PIC_LDW4_RANGE_MAX (32767)
1770 +#define PIC_LDW3_OPCODE 0x6c000000
1771 +#define PIC_LDW3_MASK 0xfe000000
1772 +#define PIC_LDW3_RANGE_MIN (0)
1773 +#define PIC_LDW3_RANGE_MAX (124)
1774 +#define SUB5_PC_OPCODE 0xfec00000
1775 +#define SUB5_PC_MASK 0xfff00000
1776 +#define SUB5_PC_RANGE_MIN (-32768)
1777 +#define SUB5_PC_RANGE_MAX (32767)
1778 +#define NOPIC_MCALL_OPCODE 0xf01f0000
1779 +#define NOPIC_MCALL_MASK 0xffff0000
1780 +#define NOPIC_MCALL_RANGE_MIN PIC_MCALL_RANGE_MIN
1781 +#define NOPIC_MCALL_RANGE_MAX PIC_MCALL_RANGE_MAX
1782 +#define NOPIC_LDW4_OPCODE 0xfef00000
1783 +#define NOPIC_LDW4_MASK 0xfff00000
1784 +#define NOPIC_LDW4_RANGE_MIN PIC_LDW4_RANGE_MIN
1785 +#define NOPIC_LDW4_RANGE_MAX PIC_LDW4_RANGE_MAX
1786 +#define LDDPC_OPCODE 0x48000000
1787 +#define LDDPC_MASK 0xf8000000
1788 +#define LDDPC_RANGE_MIN 0
1789 +#define LDDPC_RANGE_MAX 508
1791 +#define NOPIC_MOV2_OPCODE 0xe0600000
1792 +#define NOPIC_MOV2_MASK 0xe1e00000
1793 +#define NOPIC_MOV2_RANGE_MIN (-1048576)
1794 +#define NOPIC_MOV2_RANGE_MAX (1048575)
1795 +#define NOPIC_MOV1_OPCODE 0x30000000
1796 +#define NOPIC_MOV1_MASK 0xf0000000
1797 +#define NOPIC_MOV1_RANGE_MIN (-128)
1798 +#define NOPIC_MOV1_RANGE_MAX (127)
1800 +/* Only brc2 variants with cond[3] == 0 is considered, since the
1801 + others are not relaxable. bral is a special case and is handled
1803 +#define BRC2_OPCODE 0xe0800000
1804 +#define BRC2_MASK 0xe1e80000
1805 +#define BRC2_RANGE_MIN (-2097152)
1806 +#define BRC2_RANGE_MAX (2097150)
1807 +#define BRC1_OPCODE 0xc0000000
1808 +#define BRC1_MASK 0xf0080000
1809 +#define BRC1_RANGE_MIN (-256)
1810 +#define BRC1_RANGE_MAX (254)
1811 +#define BRAL_OPCODE 0xe08f0000
1812 +#define BRAL_MASK 0xe1ef0000
1813 +#define BRAL_RANGE_MIN BRC2_RANGE_MIN
1814 +#define BRAL_RANGE_MAX BRC2_RANGE_MAX
1815 +#define RJMP_OPCODE 0xc0080000
1816 +#define RJMP_MASK 0xf00c0000
1817 +#define RJMP_RANGE_MIN (-1024)
1818 +#define RJMP_RANGE_MAX (1022)
1820 +/* Define a relax state using the GOT */
1821 +#define RG(id, dir, next, prev, r_type, opc, size) \
1822 + { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_GOT, \
1823 + R_AVR32_##r_type, opc##_OPCODE, opc##_MASK, \
1824 + opc##_RANGE_MIN, opc##_RANGE_MAX, size }
1825 +/* Define a relax state using the Constant Pool */
1826 +#define RC(id, dir, next, prev, r_type, opc, size) \
1827 + { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_CPOOL, \
1828 + R_AVR32_##r_type, opc##_OPCODE, opc##_MASK, \
1829 + opc##_RANGE_MIN, opc##_RANGE_MAX, size }
1831 +/* Define a relax state using pc-relative direct reference */
1832 +#define RP(id, dir, next, prev, r_type, opc, size) \
1833 + { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_PCREL, \
1834 + R_AVR32_##r_type, opc##_OPCODE, opc##_MASK, \
1835 + opc##_RANGE_MIN, opc##_RANGE_MAX, size }
1837 +/* Define a relax state using non-pc-relative direct reference */
1838 +#define RD(id, dir, next, prev, r_type, opc, size) \
1839 + { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_ABSOLUTE, \
1840 + R_AVR32_##r_type, opc##_OPCODE, opc##_MASK, \
1841 + opc##_RANGE_MIN, opc##_RANGE_MAX, size }
1843 +/* Define a relax state that will be handled specially */
1844 +#define RS(id, r_type, size) \
1845 + { "RS_"#id, RS_##id, RS_NONE, RS_NONE, RS_NONE, REF_ABSOLUTE, \
1846 + R_AVR32_##r_type, 0, 0, 0, 0, size }
1848 +const struct relax_state relax_state[RS_MAX] = {
1849 + RS(NONE, NONE, 0),
1850 + RS(ALIGN, ALIGN, 0),
1851 + RS(CPENT, 32_CPENT, 4),
1853 + RG(PIC_CALL, PIC_RCALL1, PIC_MCALL, NONE, GOTCALL, PIC_MOV2, 10),
1854 + RG(PIC_MCALL, PIC_RCALL1, NONE, PIC_CALL, GOT18SW, PIC_MCALL, 4),
1855 + RP(PIC_RCALL2, NONE, PIC_RCALL1, PIC_MCALL, 22H_PCREL, RCALL2, 4),
1856 + RP(PIC_RCALL1, NONE, NONE, PIC_RCALL2, 11H_PCREL, RCALL1, 2),
1858 + RG(PIC_LDA, PIC_SUB5, PIC_LDW4, NONE, LDA_GOT, PIC_MOV2, 8),
1859 + RG(PIC_LDW4, PIC_SUB5, PIC_LDW3, PIC_LDA, GOT16S, PIC_LDW4, 4),
1860 + RG(PIC_LDW3, PIC_SUB5, NONE, PIC_LDW4, GOT7UW, PIC_LDW3, 2),
1861 + RP(PIC_SUB5, NONE, NONE, PIC_LDW3, 16N_PCREL, SUB5_PC, 4),
1863 + RC(NOPIC_MCALL, NOPIC_RCALL1, NONE, NONE, CPCALL, NOPIC_MCALL, 4),
1864 + RP(NOPIC_RCALL2, NONE, NOPIC_RCALL1, NOPIC_MCALL, 22H_PCREL, RCALL2, 4),
1865 + RP(NOPIC_RCALL1, NONE, NONE, NOPIC_RCALL2, 11H_PCREL, RCALL1, 2),
1867 + RC(NOPIC_LDW4, NOPIC_MOV1, NOPIC_LDDPC, NONE, 16_CP, NOPIC_LDW4, 4),
1868 + RC(NOPIC_LDDPC, NOPIC_MOV1, NONE, NOPIC_LDW4, 9W_CP, LDDPC, 2),
1869 + RP(NOPIC_SUB5, NOPIC_MOV1, NONE, NOPIC_LDDPC, 16N_PCREL, SUB5_PC, 4),
1870 + RD(NOPIC_MOV2, NONE, NOPIC_MOV1, NOPIC_SUB5, 21S, NOPIC_MOV2, 4),
1871 + RD(NOPIC_MOV1, NONE, NONE, NOPIC_MOV2, 8S, NOPIC_MOV1, 2),
1873 + RP(RCALL2, NONE, RCALL1, NONE, 22H_PCREL, RCALL2, 4),
1874 + RP(RCALL1, NONE, NONE, RCALL2, 11H_PCREL, RCALL1, 2),
1875 + RP(BRC2, NONE, BRC1, NONE, 22H_PCREL, BRC2, 4),
1876 + RP(BRC1, NONE, NONE, BRC2, 9H_PCREL, BRC1, 2),
1877 + RP(BRAL, NONE, RJMP, NONE, 22H_PCREL, BRAL, 4),
1878 + RP(RJMP, NONE, NONE, BRAL, 11H_PCREL, RJMP, 2),
1882 +avr32_elf_new_section_hook(bfd *abfd, asection *sec)
1884 + struct avr32_section_data *sdata;
1886 + sdata = bfd_zalloc(abfd, sizeof(struct avr32_section_data));
1890 + sec->used_by_bfd = sdata;
1891 + return _bfd_elf_new_section_hook(abfd, sec);
1894 +static struct avr32_relax_data *
1895 +avr32_relax_data(asection *sec)
1897 + struct avr32_section_data *sdata;
1899 + BFD_ASSERT(sec->used_by_bfd);
1901 + sdata = (struct avr32_section_data *)elf_section_data(sec);
1902 + return &sdata->relax_data;
1905 +
\f/* Link-time relaxation */
1908 +avr32_elf_relax_section(bfd *abfd, asection *sec,
1909 + struct bfd_link_info *info, bfd_boolean *again);
1911 +enum relax_pass_id {
1912 + RELAX_PASS_SIZE_FRAGS,
1913 + RELAX_PASS_MOVE_DATA,
1916 +/* Stolen from the xtensa port */
1918 +internal_reloc_compare (const void *ap, const void *bp)
1920 + const Elf_Internal_Rela *a = (const Elf_Internal_Rela *) ap;
1921 + const Elf_Internal_Rela *b = (const Elf_Internal_Rela *) bp;
1923 + if (a->r_offset != b->r_offset)
1924 + return (a->r_offset - b->r_offset);
1926 + /* We don't need to sort on these criteria for correctness,
1927 + but enforcing a more strict ordering prevents unstable qsort
1928 + from behaving differently with different implementations.
1929 + Without the code below we get correct but different results
1930 + on Solaris 2.7 and 2.8. We would like to always produce the
1931 + same results no matter the host. */
1933 + if (a->r_info != b->r_info)
1934 + return (a->r_info - b->r_info);
1936 + return (a->r_addend - b->r_addend);
1939 +static enum relax_state_id
1940 +get_pcrel22_relax_state(bfd *abfd, asection *sec, struct bfd_link_info *info,
1941 + const Elf_Internal_Rela *rela)
1943 + bfd_byte *contents;
1945 + enum relax_state_id rs = RS_NONE;
1947 + contents = retrieve_contents(abfd, sec, info->keep_memory);
1951 + insn = bfd_get_32(abfd, contents + rela->r_offset);
1952 + if ((insn & RCALL2_MASK) == RCALL2_OPCODE)
1954 + else if ((insn & BRAL_MASK) == BRAL_OPCODE)
1955 + /* Optimizing bral -> rjmp gets us into all kinds of
1956 + trouble with jump tables. Better not do it. */
1958 + else if ((insn & BRC2_MASK) == BRC2_OPCODE)
1961 + release_contents(sec, contents);
1966 +static enum relax_state_id
1967 +get_initial_relax_state(bfd *abfd, asection *sec, struct bfd_link_info *info,
1968 + const Elf_Internal_Rela *rela)
1970 + switch (ELF_R_TYPE(rela->r_info))
1972 + case R_AVR32_GOTCALL:
1973 + return RS_PIC_CALL;
1974 + case R_AVR32_GOT18SW:
1975 + return RS_PIC_MCALL;
1976 + case R_AVR32_LDA_GOT:
1977 + return RS_PIC_LDA;
1978 + case R_AVR32_GOT16S:
1979 + return RS_PIC_LDW4;
1980 + case R_AVR32_CPCALL:
1981 + return RS_NOPIC_MCALL;
1982 + case R_AVR32_16_CP:
1983 + return RS_NOPIC_LDW4;
1984 + case R_AVR32_9W_CP:
1985 + return RS_NOPIC_LDDPC;
1986 + case R_AVR32_ALIGN:
1988 + case R_AVR32_32_CPENT:
1990 + case R_AVR32_22H_PCREL:
1991 + return get_pcrel22_relax_state(abfd, sec, info, rela);
1992 + case R_AVR32_9H_PCREL:
2000 +reloc_is_cpool_ref(const Elf_Internal_Rela *rela)
2002 + switch (ELF_R_TYPE(rela->r_info))
2004 + case R_AVR32_CPCALL:
2005 + case R_AVR32_16_CP:
2006 + case R_AVR32_9W_CP:
2013 +static struct fragment *
2014 +new_frag(bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
2015 + struct avr32_relax_data *rd, enum relax_state_id state,
2016 + Elf_Internal_Rela *rela)
2018 + struct fragment *frag;
2019 + bfd_size_type r_size;
2021 + unsigned int i = rd->frag_count;
2023 + BFD_ASSERT(state >= RS_NONE && state < RS_MAX);
2026 + frag = bfd_realloc(rd->frag, sizeof(struct fragment) * rd->frag_count);
2032 + memset(frag, 0, sizeof(struct fragment));
2034 + if (state == RS_ALIGN)
2035 + r_size = (((rela->r_offset + (1 << rela->r_addend) - 1)
2036 + & ~((1 << rela->r_addend) - 1)) - rela->r_offset);
2038 + r_size = relax_state[state].size;
2041 + r_offset = rela->r_offset;
2043 + r_offset = sec->size;
2048 + frag->size = r_offset + r_size;
2052 + frag->offset = rd->frag[i - 1].offset + rd->frag[i - 1].size;
2053 + frag->size = r_offset + r_size - frag->offset;
2056 + if (state != RS_CPENT)
2057 + /* Make sure we don't discard this frag */
2058 + frag->refcount = 1;
2060 + frag->initial_state = frag->state = state;
2061 + frag->rela = rela;
2066 +static struct fragment *
2067 +find_frag(asection *sec, bfd_vma offset)
2069 + struct fragment *first, *last;
2070 + struct avr32_relax_data *rd = avr32_relax_data(sec);
2072 + if (rd->frag_count == 0)
2075 + first = &rd->frag[0];
2076 + last = &rd->frag[rd->frag_count - 1];
2078 + /* This may be a reloc referencing the end of a section. The last
2079 + frag will never have a reloc associated with it, so its size will
2080 + never change, thus the offset adjustment of the last frag will
2081 + always be the same as the offset adjustment of the end of the
2083 + if (offset == sec->size)
2085 + BFD_ASSERT(last->offset + last->size == sec->size);
2086 + BFD_ASSERT(!last->rela);
2090 + while (first <= last)
2092 + struct fragment *mid;
2094 + mid = (last - first) / 2 + first;
2095 + if ((mid->offset + mid->size) <= offset)
2097 + else if (mid->offset > offset)
2106 +/* Look through all relocs in a section and determine if any relocs
2107 + may be affected by relaxation in other sections. If so, allocate
2108 + an array of additional relocation data which links the affected
2109 + relocations to the frag(s) where the relaxation may occur.
2111 + This function also links cpool references to cpool entries and
2112 + increments the refcount of the latter when this happens. */
2115 +allocate_reloc_data(bfd *abfd, asection *sec, Elf_Internal_Rela *relocs,
2116 + struct bfd_link_info *info)
2118 + Elf_Internal_Shdr *symtab_hdr;
2119 + Elf_Internal_Sym *isymbuf = NULL;
2120 + struct avr32_relax_data *rd;
2122 + bfd_boolean ret = FALSE;
2124 + symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2125 + rd = avr32_relax_data(sec);
2127 + RDBG("%s<%s>: allocate_reloc_data\n", abfd->filename, sec->name);
2129 + for (i = 0; i < sec->reloc_count; i++)
2131 + Elf_Internal_Rela *rel = &relocs[i];
2132 + asection *sym_sec;
2133 + unsigned long r_symndx;
2134 + bfd_vma sym_value;
2136 + if (!rel->r_addend && ELF_R_TYPE(rel->r_info) != R_AVR32_DIFF32
2137 + && !reloc_is_cpool_ref(rel))
2140 + r_symndx = ELF_R_SYM(rel->r_info);
2142 + if (r_symndx < symtab_hdr->sh_info)
2144 + Elf_Internal_Sym *isym;
2147 + isymbuf = retrieve_local_syms(abfd, info->keep_memory);
2151 + isym = &isymbuf[r_symndx];
2152 + sym_sec = bfd_section_from_elf_index(abfd, isym->st_shndx);
2153 + sym_value = isym->st_value;
2157 + struct elf_link_hash_entry *h;
2159 + h = elf_sym_hashes(abfd)[r_symndx - symtab_hdr->sh_info];
2161 + while (h->root.type == bfd_link_hash_indirect
2162 + || h->root.type == bfd_link_hash_warning)
2163 + h = (struct elf_link_hash_entry *)h->root.u.i.link;
2165 + if (h->root.type != bfd_link_hash_defined
2166 + && h->root.type != bfd_link_hash_defweak)
2169 + sym_sec = h->root.u.def.section;
2170 + sym_value = h->root.u.def.value;
2173 + if (sym_sec && avr32_relax_data(sym_sec)->is_relaxable)
2175 + bfd_size_type size;
2176 + struct fragment *frag;
2178 + if (!rd->reloc_data)
2180 + size = sizeof(struct avr32_reloc_data) * sec->reloc_count;
2181 + rd->reloc_data = bfd_zalloc(abfd, size);
2182 + if (!rd->reloc_data)
2186 + RDBG("[%3d] 0x%04lx: target: 0x%lx + 0x%lx",
2187 + i, rel->r_offset, sym_value, rel->r_addend);
2189 + frag = find_frag(sym_sec, sym_value + rel->r_addend);
2191 + rd->reloc_data[i].add_frag = frag;
2193 + RDBG(" -> %s<%s>:%04lx\n", sym_sec->owner->filename, sym_sec->name,
2194 + frag->rela ? frag->rela->r_offset : sym_sec->size);
2196 + if (reloc_is_cpool_ref(rel))
2198 + BFD_ASSERT(ELF_R_TYPE(frag->rela->r_info) == R_AVR32_32_CPENT);
2202 + if (ELF_R_TYPE(rel->r_info) == R_AVR32_DIFF32)
2204 + bfd_byte *contents;
2205 + bfd_signed_vma diff;
2207 + contents = retrieve_contents(abfd, sec, info->keep_memory);
2211 + diff = bfd_get_signed_32(abfd, contents + rel->r_offset);
2212 + frag = find_frag(sym_sec, sym_value + rel->r_addend + diff);
2214 + rd->reloc_data[i].sub_frag = frag;
2216 + release_contents(sec, contents);
2224 + release_local_syms(abfd, isymbuf);
2229 +global_sym_set_frag(struct elf_avr32_link_hash_entry *havr,
2230 + struct bfd_link_info *info ATTRIBUTE_UNUSED)
2232 + struct fragment *frag;
2235 + if (havr->root.root.type != bfd_link_hash_defined
2236 + && havr->root.root.type != bfd_link_hash_defweak)
2239 + sec = havr->root.root.u.def.section;
2240 + if (bfd_is_const_section(sec)
2241 + || !avr32_relax_data(sec)->is_relaxable)
2244 + frag = find_frag(sec, havr->root.root.u.def.value);
2248 + struct avr32_relax_data *rd = avr32_relax_data(sec);
2250 + RDBG("In %s: No frag for %s <%s+%lu> (limit %lu)\n",
2251 + sec->owner->filename, havr->root.root.root.string,
2252 + sec->name, havr->root.root.u.def.value, sec->size);
2253 + for (i = 0; i < rd->frag_count; i++)
2254 + RDBG(" %8lu - %8lu\n", rd->frag[i].offset,
2255 + rd->frag[i].offset + rd->frag[i].size);
2259 + havr->sym_frag = frag;
2264 +analyze_relocations(struct bfd_link_info *info)
2269 + /* Divide all relaxable sections into fragments */
2270 + for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
2272 + if (!(elf_elfheader(abfd)->e_flags & EF_AVR32_LINKRELAX))
2274 + if (!(*info->callbacks->warning)
2275 + (info, _("input is not relaxable"), NULL, abfd, NULL, 0))
2280 + for (sec = abfd->sections; sec; sec = sec->next)
2282 + struct avr32_relax_data *rd;
2283 + struct fragment *frag;
2284 + Elf_Internal_Rela *relocs;
2286 + bfd_boolean ret = TRUE;
2288 + if (!(sec->flags & SEC_RELOC) || sec->reloc_count == 0)
2291 + rd = avr32_relax_data(sec);
2293 + relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
2297 + qsort(relocs, sec->reloc_count, sizeof(Elf_Internal_Rela),
2298 + internal_reloc_compare);
2300 + for (i = 0; i < sec->reloc_count; i++)
2302 + enum relax_state_id state;
2305 + state = get_initial_relax_state(abfd, sec, info, &relocs[i]);
2306 + if (state == RS_ERROR)
2311 + frag = new_frag(abfd, sec, rd, state, &relocs[i]);
2315 + pin_internal_relocs(sec, relocs);
2316 + rd->is_relaxable = TRUE;
2322 + release_internal_relocs(sec, relocs);
2326 + if (rd->is_relaxable)
2328 + frag = new_frag(abfd, sec, rd, RS_NONE, NULL);
2335 + /* Link each global symbol to the fragment where it's defined. */
2336 + elf_link_hash_traverse(elf_hash_table(info), global_sym_set_frag, info);
2338 + /* Do the same for local symbols. */
2339 + for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
2341 + Elf_Internal_Sym *isymbuf, *isym;
2342 + struct fragment **local_sym_frag;
2343 + unsigned int i, sym_count;
2345 + sym_count = elf_tdata(abfd)->symtab_hdr.sh_info;
2346 + if (sym_count == 0)
2349 + local_sym_frag = bfd_zalloc(abfd, sym_count * sizeof(struct fragment *));
2350 + if (!local_sym_frag)
2352 + elf_tdata(abfd)->local_sym_frag = local_sym_frag;
2354 + isymbuf = retrieve_local_syms(abfd, info->keep_memory);
2358 + for (i = 0; i < sym_count; i++)
2360 + struct avr32_relax_data *rd;
2361 + struct fragment *frag;
2364 + isym = &isymbuf[i];
2366 + sec = bfd_section_from_elf_index(abfd, isym->st_shndx);
2370 + rd = avr32_relax_data(sec);
2371 + if (!rd->is_relaxable)
2374 + frag = find_frag(sec, isym->st_value);
2377 + local_sym_frag[i] = frag;
2380 + release_local_syms(abfd, isymbuf);
2383 + /* And again for relocs with addends and constant pool references */
2384 + for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
2385 + for (sec = abfd->sections; sec; sec = sec->next)
2387 + Elf_Internal_Rela *relocs;
2390 + if (!(sec->flags & SEC_RELOC) || sec->reloc_count == 0)
2393 + relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
2397 + ret = allocate_reloc_data(abfd, sec, relocs, info);
2399 + release_internal_relocs(sec, relocs);
2408 +rs_is_good_enough(const struct relax_state *rs, struct fragment *frag,
2409 + bfd_vma symval, bfd_vma addr, struct got_entry *got,
2410 + struct avr32_reloc_data *ind_data,
2411 + bfd_signed_vma offset_adjust)
2413 + bfd_signed_vma target = 0;
2415 + switch (rs->reftype)
2417 + case REF_ABSOLUTE:
2421 + target = symval - addr;
2424 + /* cpool frags are always in the same section and always after
2425 + all frags referring to it. So it's always correct to add in
2426 + offset_adjust here. */
2427 + target = (ind_data->add_frag->offset + ind_data->add_frag->offset_adjust
2428 + + offset_adjust - frag->offset - frag->offset_adjust);
2431 + target = got->offset;
2437 + if (target >= rs->range_min && target <= rs->range_max)
2444 +avr32_size_frags(bfd *abfd, asection *sec, struct bfd_link_info *info)
2446 + struct elf_avr32_link_hash_table *htab;
2447 + struct avr32_relax_data *rd;
2448 + Elf_Internal_Shdr *symtab_hdr;
2449 + Elf_Internal_Rela *relocs = NULL;
2450 + Elf_Internal_Sym *isymbuf = NULL;
2451 + struct got_entry **local_got_ents;
2452 + struct fragment **local_sym_frag;
2453 + bfd_boolean ret = FALSE;
2454 + bfd_signed_vma delta = 0;
2457 + htab = avr32_elf_hash_table(info);
2458 + rd = avr32_relax_data(sec);
2460 + if (sec == htab->sgot)
2462 + RDBG("Relaxing GOT section (vma: 0x%lx)\n",
2463 + sec->output_section->vma + sec->output_offset);
2464 + if (assign_got_offsets(htab))
2465 + htab->repeat_pass = TRUE;
2469 + if (!rd->is_relaxable)
2472 + if (!sec->rawsize)
2473 + sec->rawsize = sec->size;
2475 + symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2476 + relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
2480 + isymbuf = retrieve_local_syms(abfd, info->keep_memory);
2484 + local_got_ents = elf_local_got_ents(abfd);
2485 + local_sym_frag = elf_tdata(abfd)->local_sym_frag;
2487 + RDBG("size_frags: %s<%s>\n vma: 0x%08lx, size: 0x%08lx\n",
2488 + abfd->filename, sec->name,
2489 + sec->output_section->vma + sec->output_offset, sec->size);
2491 + for (i = 0; i < rd->frag_count; i++)
2493 + struct fragment *frag = &rd->frag[i];
2494 + struct avr32_reloc_data *r_data = NULL, *ind_data = NULL;
2495 + const struct relax_state *state, *next_state;
2496 + struct fragment *target_frag = NULL;
2497 + asection *sym_sec = NULL;
2498 + Elf_Internal_Rela *rela;
2499 + struct got_entry *got;
2500 + bfd_vma symval, r_offset, addend, addr;
2501 + bfd_signed_vma size_adjust = 0, distance;
2502 + unsigned long r_symndx;
2503 + bfd_boolean defined = TRUE, dynamic = FALSE;
2504 + unsigned char sym_type;
2506 + frag->offset_adjust += delta;
2507 + state = next_state = &relax_state[frag->state];
2508 + rela = frag->rela;
2510 + BFD_ASSERT(state->id == frag->state);
2512 + RDBG(" 0x%04lx%c%d: %s [size %ld]", rela ? rela->r_offset : sec->rawsize,
2513 + (frag->offset_adjust < 0)?'-':'+',
2514 + abs(frag->offset_adjust), state->name, state->size);
2518 + RDBG(": no reloc, ignoring\n");
2522 + BFD_ASSERT((unsigned int)(rela - relocs) < sec->reloc_count);
2523 + BFD_ASSERT(state != RS_NONE);
2525 + r_offset = rela->r_offset + frag->offset_adjust;
2526 + addr = sec->output_section->vma + sec->output_offset + r_offset;
2528 + switch (frag->state)
2531 + size_adjust = ((addr + (1 << rela->r_addend) - 1)
2532 + & ~((1 << rela->r_addend) - 1));
2533 + size_adjust -= (sec->output_section->vma + sec->output_offset
2534 + + frag->offset + frag->offset_adjust
2535 + + frag->size + frag->size_adjust);
2537 + RDBG(": adjusting size %lu -> %lu\n", frag->size + frag->size_adjust,
2538 + frag->size + frag->size_adjust + size_adjust);
2542 + if (frag->refcount == 0 && frag->size_adjust == 0)
2544 + RDBG(": discarding frag\n");
2547 + else if (frag->refcount > 0 && frag->size_adjust < 0)
2549 + RDBG(": un-discarding frag\n");
2555 + if (rd->reloc_data)
2556 + r_data = &rd->reloc_data[frag->rela - relocs];
2558 + /* If this is a cpool reference, we want the symbol that the
2559 + cpool entry refers to, not the symbol for the cpool entry
2560 + itself, as we already know what frag it's in. */
2561 + if (relax_state[frag->initial_state].reftype == REF_CPOOL)
2563 + Elf_Internal_Rela *irela = r_data->add_frag->rela;
2565 + r_symndx = ELF_R_SYM(irela->r_info);
2566 + addend = irela->r_addend;
2568 + /* The constant pool must be in the same section as the
2569 + reloc referring to it. */
2570 + BFD_ASSERT((unsigned long)(irela - relocs) < sec->reloc_count);
2572 + ind_data = r_data;
2573 + r_data = &rd->reloc_data[irela - relocs];
2577 + r_symndx = ELF_R_SYM(rela->r_info);
2578 + addend = rela->r_addend;
2581 + /* Get the value of the symbol referred to by the reloc. */
2582 + if (r_symndx < symtab_hdr->sh_info)
2584 + Elf_Internal_Sym *isym;
2586 + isym = isymbuf + r_symndx;
2589 + RDBG(" local sym %lu: ", r_symndx);
2591 + if (isym->st_shndx == SHN_UNDEF)
2593 + else if (isym->st_shndx == SHN_ABS)
2594 + sym_sec = bfd_abs_section_ptr;
2595 + else if (isym->st_shndx == SHN_COMMON)
2596 + sym_sec = bfd_com_section_ptr;
2598 + sym_sec = bfd_section_from_elf_index(abfd, isym->st_shndx);
2600 + symval = isym->st_value;
2601 + sym_type = ELF_ST_TYPE(isym->st_info);
2602 + target_frag = local_sym_frag[r_symndx];
2604 + if (local_got_ents)
2605 + got = local_got_ents[r_symndx];
2611 + /* Global symbol */
2612 + unsigned long index;
2613 + struct elf_link_hash_entry *h;
2614 + struct elf_avr32_link_hash_entry *havr;
2616 + index = r_symndx - symtab_hdr->sh_info;
2617 + h = elf_sym_hashes(abfd)[index];
2618 + BFD_ASSERT(h != NULL);
2620 + while (h->root.type == bfd_link_hash_indirect
2621 + || h->root.type == bfd_link_hash_warning)
2622 + h = (struct elf_link_hash_entry *)h->root.u.i.link;
2624 + havr = (struct elf_avr32_link_hash_entry *)h;
2625 + got = h->got.glist;
2629 + RDBG(" %s: ", h->root.root.string);
2631 + if (h->root.type != bfd_link_hash_defined
2632 + && h->root.type != bfd_link_hash_defweak)
2637 + else if ((info->shared && !info->symbolic && h->dynindx != -1)
2638 + || (htab->root.dynamic_sections_created
2639 + && h->def_dynamic && !h->def_regular))
2641 + RDBG("(dynamic)");
2643 + sym_sec = h->root.u.def.section;
2647 + sym_sec = h->root.u.def.section;
2648 + symval = h->root.u.def.value;
2649 + target_frag = havr->sym_frag;
2652 + sym_type = h->type;
2655 + /* Thanks to elf32-ppc for this one. */
2656 + if (sym_sec && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
2658 + /* At this stage in linking, no SEC_MERGE symbol has been
2659 + adjusted, so all references to such symbols need to be
2660 + passed through _bfd_merged_section_offset. (Later, in
2661 + relocate_section, all SEC_MERGE symbols *except* for
2662 + section symbols have been adjusted.)
2664 + SEC_MERGE sections are not relaxed by us, as they
2665 + shouldn't contain any code. */
2667 + BFD_ASSERT(!target_frag && !(r_data && r_data->add_frag));
2669 + /* gas may reduce relocations against symbols in SEC_MERGE
2670 + sections to a relocation against the section symbol when
2671 + the original addend was zero. When the reloc is against
2672 + a section symbol we should include the addend in the
2673 + offset passed to _bfd_merged_section_offset, since the
2674 + location of interest is the original symbol. On the
2675 + other hand, an access to "sym+addend" where "sym" is not
2676 + a section symbol should not include the addend; Such an
2677 + access is presumed to be an offset from "sym"; The
2678 + location of interest is just "sym". */
2679 + RDBG("\n MERGE: %s: 0x%lx+0x%lx+0x%lx -> ",
2680 + (sym_type == STT_SECTION)?"section":"not section",
2681 + sym_sec->output_section->vma + sym_sec->output_offset,
2684 + if (sym_type == STT_SECTION)
2687 + symval = (_bfd_merged_section_offset
2689 + elf_section_data(sym_sec)->sec_info, symval));
2691 + if (sym_type != STT_SECTION)
2697 + if (defined && !dynamic)
2699 + RDBG("0x%lx+0x%lx",
2700 + sym_sec->output_section->vma + sym_sec->output_offset,
2702 + symval += sym_sec->output_section->vma + sym_sec->output_offset;
2705 + if (r_data && r_data->add_frag)
2706 + /* If the add_frag pointer is set, it means that this reloc
2707 + has an addend that may be affected by relaxation. */
2708 + target_frag = r_data->add_frag;
2712 + symval += target_frag->offset_adjust;
2714 + /* If target_frag comes after this frag in the same
2715 + section, we should assume that it will be moved by
2716 + the same amount we are. */
2717 + if ((target_frag - rd->frag) < (int)rd->frag_count
2718 + && target_frag > frag)
2722 + distance = symval - addr;
2724 + /* First, try to make a direct reference. If the symbol is
2725 + dynamic or undefined, we must take care not to change its
2726 + reference type, that is, we can't make it direct.
2728 + Also, it seems like some sections may actually be resized
2729 + after the relaxation code is done, so we can't really
2730 + trust that our "distance" is correct. There's really no
2731 + easy solution to this problem, so we'll just disallow
2732 + direct references to SEC_DATA sections.
2734 + Oh, and .bss isn't actually SEC_DATA, so we disallow
2735 + !SEC_HAS_CONTENTS as well. */
2736 + if (!dynamic && defined
2737 + && (htab->direct_data_refs
2738 + || (!(sym_sec->flags & SEC_DATA)
2739 + && (sym_sec->flags & SEC_HAS_CONTENTS)))
2740 + && next_state->direct)
2742 + next_state = &relax_state[next_state->direct];
2743 + RDBG(" D-> %s", next_state->name);
2746 + /* Iterate backwards until we find a state that fits. */
2747 + while (next_state->prev
2748 + && !rs_is_good_enough(next_state, frag, symval, addr,
2749 + got, ind_data, delta))
2751 + next_state = &relax_state[next_state->prev];
2752 + RDBG(" P-> %s", next_state->name);
2755 + /* Then try to find the best possible state. */
2756 + while (next_state->next)
2758 + const struct relax_state *candidate;
2760 + candidate = &relax_state[next_state->next];
2761 + if (!rs_is_good_enough(candidate, frag, symval, addr, got,
2765 + next_state = candidate;
2766 + RDBG(" N-> %s", next_state->name);
2769 + RDBG(" [size %ld]\n", next_state->size);
2771 + BFD_ASSERT(next_state->id);
2772 + BFD_ASSERT(!dynamic || next_state->reftype == REF_GOT);
2774 + size_adjust = next_state->size - state->size;
2776 + /* There's a theoretical possibility that shrinking one frag
2777 + may cause another to grow, which may cause the first one to
2778 + grow as well, and we're back where we started. Avoid this
2779 + scenario by disallowing a frag that has grown to ever
2781 + if (state->reftype == REF_GOT && next_state->reftype != REF_GOT)
2783 + if (frag->has_grown)
2784 + next_state = state;
2786 + unref_got_entry(htab, got);
2788 + else if (state->reftype != REF_GOT && next_state->reftype == REF_GOT)
2790 + ref_got_entry(htab, got);
2791 + frag->has_grown = TRUE;
2793 + else if (state->reftype == REF_CPOOL
2794 + && next_state->reftype != REF_CPOOL)
2796 + if (frag->has_grown)
2797 + next_state = state;
2799 + ind_data->add_frag->refcount--;
2801 + else if (state->reftype != REF_CPOOL
2802 + && next_state->reftype == REF_CPOOL)
2804 + ind_data->add_frag->refcount++;
2805 + frag->has_grown = TRUE;
2809 + if (frag->has_grown && size_adjust < 0)
2810 + next_state = state;
2811 + else if (size_adjust > 0)
2812 + frag->has_grown = TRUE;
2815 + size_adjust = next_state->size - state->size;
2816 + frag->state = next_state->id;
2822 + htab->repeat_pass = TRUE;
2824 + frag->size_adjust += size_adjust;
2825 + sec->size += size_adjust;
2826 + delta += size_adjust;
2828 + BFD_ASSERT((frag->offset + frag->offset_adjust
2829 + + frag->size + frag->size_adjust)
2830 + == (frag[1].offset + frag[1].offset_adjust + delta));
2836 + release_local_syms(abfd, isymbuf);
2837 + release_internal_relocs(sec, relocs);
2842 +adjust_global_symbol(struct elf_avr32_link_hash_entry *havr,
2843 + struct bfd_link_info *info ATTRIBUTE_UNUSED)
2845 + struct elf_link_hash_entry *h = &havr->root;
2847 + if (havr->sym_frag && (h->root.type == bfd_link_hash_defined
2848 + || h->root.type == bfd_link_hash_defweak))
2850 + RDBG("adjust_global_symbol: %s 0x%08lx -> 0x%08lx\n",
2851 + h->root.root.string, h->root.u.def.value,
2852 + h->root.u.def.value + havr->sym_frag->offset_adjust);
2853 + h->root.u.def.value += havr->sym_frag->offset_adjust;
2859 +adjust_syms(struct bfd_link_info *info)
2861 + struct elf_avr32_link_hash_table *htab;
2864 + htab = avr32_elf_hash_table(info);
2865 + elf_link_hash_traverse(&htab->root, adjust_global_symbol, info);
2867 + for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
2869 + Elf_Internal_Sym *isymbuf;
2870 + struct fragment **local_sym_frag, *frag;
2871 + unsigned int i, sym_count;
2873 + sym_count = elf_tdata(abfd)->symtab_hdr.sh_info;
2874 + if (sym_count == 0)
2877 + isymbuf = retrieve_local_syms(abfd, info->keep_memory);
2881 + local_sym_frag = elf_tdata(abfd)->local_sym_frag;
2883 + for (i = 0; i < sym_count; i++)
2885 + frag = local_sym_frag[i];
2888 + RDBG("adjust_local_symbol: %s[%u] 0x%08lx -> 0x%08lx\n",
2889 + abfd->filename, i, isymbuf[i].st_value,
2890 + isymbuf[i].st_value + frag->offset_adjust);
2891 + isymbuf[i].st_value += frag->offset_adjust;
2895 + release_local_syms(abfd, isymbuf);
2898 + htab->symbols_adjusted = TRUE;
2903 +adjust_relocs(bfd *abfd, asection *sec, struct bfd_link_info *info)
2905 + struct avr32_relax_data *rd;
2906 + Elf_Internal_Rela *relocs;
2907 + Elf_Internal_Shdr *symtab_hdr;
2909 + bfd_boolean ret = FALSE;
2911 + rd = avr32_relax_data(sec);
2912 + if (!rd->reloc_data)
2915 + RDBG("adjust_relocs: %s<%s> (count: %u)\n", abfd->filename, sec->name,
2916 + sec->reloc_count);
2918 + relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
2922 + symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2924 + for (i = 0; i < sec->reloc_count; i++)
2926 + Elf_Internal_Rela *rela = &relocs[i];
2927 + struct avr32_reloc_data *r_data = &rd->reloc_data[i];
2928 + struct fragment *sym_frag;
2929 + unsigned long r_symndx;
2931 + if (r_data->add_frag)
2933 + r_symndx = ELF_R_SYM(rela->r_info);
2935 + if (r_symndx < symtab_hdr->sh_info)
2936 + sym_frag = elf_tdata(abfd)->local_sym_frag[r_symndx];
2939 + struct elf_link_hash_entry *h;
2941 + h = elf_sym_hashes(abfd)[r_symndx - symtab_hdr->sh_info];
2943 + while (h->root.type == bfd_link_hash_indirect
2944 + || h->root.type == bfd_link_hash_warning)
2945 + h = (struct elf_link_hash_entry *)h->root.u.i.link;
2947 + BFD_ASSERT(h->root.type == bfd_link_hash_defined
2948 + || h->root.type == bfd_link_hash_defweak);
2950 + sym_frag = ((struct elf_avr32_link_hash_entry *)h)->sym_frag;
2953 + RDBG(" addend: 0x%08lx -> 0x%08lx\n",
2955 + rela->r_addend + r_data->add_frag->offset_adjust
2956 + - (sym_frag ? sym_frag->offset_adjust : 0));
2958 + /* If this is against a section symbol, we won't find any
2959 + sym_frag, so we'll just adjust the addend. */
2960 + rela->r_addend += r_data->add_frag->offset_adjust;
2962 + rela->r_addend -= sym_frag->offset_adjust;
2964 + if (r_data->sub_frag)
2966 + bfd_byte *contents;
2967 + bfd_signed_vma diff;
2969 + contents = retrieve_contents(abfd, sec, info->keep_memory);
2973 + /* I realize now that sub_frag is misnamed. It's
2974 + actually add_frag which is subtracted in this
2976 + diff = bfd_get_signed_32(abfd, contents + rela->r_offset);
2977 + diff += (r_data->sub_frag->offset_adjust
2978 + - r_data->add_frag->offset_adjust);
2979 + bfd_put_32(abfd, diff, contents + rela->r_offset);
2981 + RDBG(" 0x%lx: DIFF32 updated: 0x%lx\n", rela->r_offset, diff);
2983 + release_contents(sec, contents);
2987 + BFD_ASSERT(!r_data->sub_frag);
2993 + release_internal_relocs(sec, relocs);
2998 +avr32_move_data(bfd *abfd, asection *sec, struct bfd_link_info *info)
3000 + struct elf_avr32_link_hash_table *htab;
3001 + struct avr32_relax_data *rd;
3002 + struct fragment *frag, *fragend;
3003 + Elf_Internal_Rela *relocs = NULL;
3004 + bfd_byte *contents = NULL;
3006 + bfd_boolean ret = FALSE;
3008 + htab = avr32_elf_hash_table(info);
3009 + rd = avr32_relax_data(sec);
3011 + if (!htab->symbols_adjusted)
3012 + if (!adjust_syms(info))
3015 + if (rd->is_relaxable)
3017 + /* Resize the section first, so that we can be sure that enough
3018 + memory is allocated in case the section has grown. */
3019 + if (sec->size > sec->rawsize
3020 + && elf_section_data(sec)->this_hdr.contents)
3022 + /* We must not use cached data if the section has grown. */
3023 + free(elf_section_data(sec)->this_hdr.contents);
3024 + elf_section_data(sec)->this_hdr.contents = NULL;
3027 + relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
3030 + contents = retrieve_contents(abfd, sec, info->keep_memory);
3034 + fragend = rd->frag + rd->frag_count;
3036 + RDBG("move_data: %s<%s>: relocs=%p, contents=%p\n",
3037 + abfd->filename, sec->name, relocs, contents);
3039 + /* First, move the data into place. We must take care to move
3040 + frags in the right order so that we don't accidentally
3041 + overwrite parts of the next frag. */
3042 + for (frag = rd->frag; frag < fragend; frag++)
3044 + RDBG(" 0x%08lx%c0x%x: size 0x%lx%c0x%x\n",
3045 + frag->offset, frag->offset_adjust >= 0 ? '+' : '-',
3046 + abs(frag->offset_adjust),
3047 + frag->size, frag->size_adjust >= 0 ? '+' : '-',
3048 + abs(frag->size_adjust));
3049 + if (frag->offset_adjust > 0)
3051 + struct fragment *prev = frag - 1;
3052 + struct fragment *last;
3054 + for (last = frag; last < fragend && last->offset_adjust > 0;
3057 + if (last == fragend)
3060 + for (frag = last; frag != prev; frag--)
3062 + if (frag->offset_adjust
3063 + && frag->size + frag->size_adjust > 0)
3065 + RDBG("memmove 0x%lx -> 0x%lx (size %lu)\n",
3066 + frag->offset, frag->offset + frag->offset_adjust,
3067 + frag->size + frag->size_adjust);
3068 + memmove(contents + frag->offset + frag->offset_adjust,
3069 + contents + frag->offset,
3070 + frag->size + frag->size_adjust);
3075 + else if (frag->offset_adjust && frag->size + frag->size_adjust > 0)
3077 + RDBG("memmove 0x%lx -> 0x%lx (size %lu)\n",
3078 + frag->offset, frag->offset + frag->offset_adjust,
3079 + frag->size + frag->size_adjust);
3080 + memmove(contents + frag->offset + frag->offset_adjust,
3081 + contents + frag->offset,
3082 + frag->size + frag->size_adjust);
3088 + for (frag = rd->frag; frag < fragend; frag++)
3090 + const struct relax_state *state, *istate;
3091 + struct avr32_reloc_data *r_data = NULL;
3093 + istate = &relax_state[frag->initial_state];
3094 + state = &relax_state[frag->state];
3096 + if (rd->reloc_data)
3097 + r_data = &rd->reloc_data[frag->rela - relocs];
3099 + BFD_ASSERT((long)(frag->size + frag->size_adjust) >= 0);
3100 + BFD_ASSERT(state->reftype != REF_CPOOL
3101 + || r_data->add_frag->refcount > 0);
3103 + if (istate->reftype == REF_CPOOL && state->reftype != REF_CPOOL)
3105 + struct fragment *ifrag;
3107 + /* An indirect reference through the cpool has been
3108 + converted to a direct reference. We must update the
3109 + reloc to point to the symbol itself instead of the
3110 + constant pool entry. The reloc type will be updated
3112 + ifrag = r_data->add_frag;
3113 + frag->rela->r_info = ifrag->rela->r_info;
3114 + frag->rela->r_addend = ifrag->rela->r_addend;
3116 + /* Copy the reloc data so the addend will be adjusted
3117 + correctly later. */
3118 + *r_data = rd->reloc_data[ifrag->rela - relocs];
3121 + /* Move all relocs covered by this frag. */
3123 + BFD_ASSERT(&relocs[i] <= frag->rela);
3125 + BFD_ASSERT((frag + 1) == fragend && frag->state == RS_NONE);
3127 + if (frag == rd->frag)
3128 + BFD_ASSERT(i == 0);
3130 + BFD_ASSERT(&relocs[i] > frag[-1].rela);
3132 + /* If non-null, frag->rela is the last relocation in the
3133 + fragment. frag->rela can only be null in the last
3134 + fragment, so in that case, we'll just do the rest. */
3135 + for (; (i < sec->reloc_count
3136 + && (!frag->rela || &relocs[i] <= frag->rela)); i++)
3138 + RDBG("[%4u] r_offset 0x%08lx -> 0x%08lx\n", i, relocs[i].r_offset,
3139 + relocs[i].r_offset + frag->offset_adjust);
3140 + relocs[i].r_offset += frag->offset_adjust;
3143 + if (frag->refcount == 0)
3145 + /* If this frag is to be discarded, make sure we won't
3146 + relocate it later on. */
3147 + BFD_ASSERT(frag->state == RS_CPENT);
3148 + frag->rela->r_info = ELF_R_INFO(ELF_R_SYM(frag->rela->r_info),
3151 + else if (frag->state == RS_ALIGN)
3153 + bfd_vma addr, addr_end;
3155 + addr = frag->rela->r_offset;
3156 + addr_end = (frag->offset + frag->offset_adjust
3157 + + frag->size + frag->size_adjust);
3159 + /* If the section is executable, insert NOPs.
3160 + Otherwise, insert zeroes. */
3161 + if (sec->flags & SEC_CODE)
3165 + bfd_put_8(abfd, 0, contents + addr);
3169 + BFD_ASSERT(!((addr_end - addr) & 1));
3171 + while (addr < addr_end)
3173 + bfd_put_16(abfd, NOP_OPCODE, contents + addr);
3178 + memset(contents + addr, 0, addr_end - addr);
3180 + else if (state->opcode_mask)
3184 + /* Update the opcode and the relocation type unless it's a
3185 + "special" relax state (i.e. RS_NONE, RS_ALIGN or
3186 + RS_CPENT.), in which case the opcode mask is zero. */
3187 + insn = bfd_get_32(abfd, contents + frag->rela->r_offset);
3188 + insn &= ~state->opcode_mask;
3189 + insn |= state->opcode;
3190 + RDBG(" 0x%lx: inserting insn %08lx\n",
3191 + frag->rela->r_offset, insn);
3192 + bfd_put_32(abfd, insn, contents + frag->rela->r_offset);
3194 + frag->rela->r_info = ELF_R_INFO(ELF_R_SYM(frag->rela->r_info),
3198 + if ((frag + 1) == fragend)
3199 + BFD_ASSERT((frag->offset + frag->size + frag->offset_adjust
3200 + + frag->size_adjust) == sec->size);
3202 + BFD_ASSERT((frag->offset + frag->size + frag->offset_adjust
3203 + + frag->size_adjust)
3204 + == (frag[1].offset + frag[1].offset_adjust));
3208 + /* Adjust reloc addends and DIFF32 differences */
3209 + if (!adjust_relocs(abfd, sec, info))
3215 + release_contents(sec, contents);
3216 + release_internal_relocs(sec, relocs);
3221 +avr32_elf_relax_section(bfd *abfd, asection *sec,
3222 + struct bfd_link_info *info, bfd_boolean *again)
3224 + struct elf_avr32_link_hash_table *htab;
3225 + struct avr32_relax_data *rd;
3228 + if (info->relocatable)
3231 + htab = avr32_elf_hash_table(info);
3232 + if ((!(sec->flags & SEC_RELOC) || sec->reloc_count == 0)
3233 + && sec != htab->sgot)
3236 + if (!htab->relocations_analyzed)
3238 + if (!analyze_relocations(info))
3240 + htab->relocations_analyzed = TRUE;
3243 + rd = avr32_relax_data(sec);
3245 + if (rd->iteration != htab->relax_iteration)
3247 + if (!htab->repeat_pass)
3248 + htab->relax_pass++;
3249 + htab->relax_iteration++;
3250 + htab->repeat_pass = FALSE;
3255 + switch (htab->relax_pass)
3257 + case RELAX_PASS_SIZE_FRAGS:
3258 + if (!avr32_size_frags(abfd, sec, info))
3262 + case RELAX_PASS_MOVE_DATA:
3263 + if (!avr32_move_data(abfd, sec, info))
3274 +static bfd_reloc_status_type
3275 +avr32_check_reloc_value(asection *sec, Elf_Internal_Rela *rela,
3276 + bfd_signed_vma relocation, reloc_howto_type *howto);
3277 +static bfd_reloc_status_type
3278 +avr32_final_link_relocate(reloc_howto_type *howto, bfd *input_bfd,
3279 + asection *input_section, bfd_byte *contents,
3280 + Elf_Internal_Rela *rel, bfd_vma value);
3282 +avr32_elf_relocate_section(bfd *output_bfd, struct bfd_link_info *info,
3283 + bfd *input_bfd, asection *input_section,
3284 + bfd_byte *contents, Elf_Internal_Rela *relocs,
3285 + Elf_Internal_Sym *local_syms,
3286 + asection **local_sections);
3289 +#define symbol_address(symbol) \
3290 + symbol->value + symbol->section->output_section->vma \
3291 + + symbol->section->output_offset
3293 +#define avr32_elf_insert_field(size, field, abfd, reloc_entry, data) \
3296 + unsigned long x; \
3297 + x = bfd_get_##size (abfd, data + reloc_entry->address); \
3298 + x &= ~reloc_entry->howto->dst_mask; \
3299 + x |= field & reloc_entry->howto->dst_mask; \
3300 + bfd_put_##size (abfd, (bfd_vma) x, data + reloc_entry->address); \
3304 +static bfd_reloc_status_type
3305 +avr32_check_reloc_value(asection *sec ATTRIBUTE_UNUSED,
3306 + Elf_Internal_Rela *rela ATTRIBUTE_UNUSED,
3307 + bfd_signed_vma relocation,
3308 + reloc_howto_type *howto)
3312 + /* We take "complain_overflow_dont" to mean "don't complain on
3313 + alignment either". This way, we don't have to special-case
3315 + if (howto->complain_on_overflow == complain_overflow_dont)
3316 + return bfd_reloc_ok;
3318 + /* Check if the value is correctly aligned */
3319 + if (relocation & ((1 << howto->rightshift) - 1))
3321 + RDBG("misaligned: %s<%s+%lx>: %s: 0x%lx (align %u)\n",
3322 + sec->owner->filename, sec->name, rela->r_offset,
3323 + howto->name, relocation, howto->rightshift);
3324 + return bfd_reloc_overflow;
3327 + /* Now, get rid of the unnecessary bits */
3328 + relocation >>= howto->rightshift;
3329 + reloc_u = (bfd_vma)relocation;
3331 + switch (howto->complain_on_overflow)
3333 + case complain_overflow_unsigned:
3334 + case complain_overflow_bitfield:
3335 + if (reloc_u > (unsigned long)((1 << howto->bitsize) - 1))
3337 + RDBG("unsigned overflow: %s<%s+%lx>: %s: 0x%lx (size %u)\n",
3338 + sec->owner->filename, sec->name, rela->r_offset,
3339 + howto->name, reloc_u, howto->bitsize);
3340 + RDBG("reloc vma: 0x%lx\n",
3341 + sec->output_section->vma + sec->output_offset + rela->r_offset);
3343 + return bfd_reloc_overflow;
3346 + case complain_overflow_signed:
3347 + if (relocation > (1 << (howto->bitsize - 1)) - 1)
3349 + RDBG("signed overflow: %s<%s+%lx>: %s: 0x%lx (size %u)\n",
3350 + sec->owner->filename, sec->name, rela->r_offset,
3351 + howto->name, reloc_u, howto->bitsize);
3352 + RDBG("reloc vma: 0x%lx\n",
3353 + sec->output_section->vma + sec->output_offset + rela->r_offset);
3355 + return bfd_reloc_overflow;
3357 + if (relocation < -(1 << (howto->bitsize - 1)))
3359 + RDBG("signed overflow: %s<%s+%lx>: %s: -0x%lx (size %u)\n",
3360 + sec->owner->filename, sec->name, rela->r_offset,
3361 + howto->name, -relocation, howto->bitsize);
3362 + RDBG("reloc vma: 0x%lx\n",
3363 + sec->output_section->vma + sec->output_offset + rela->r_offset);
3365 + return bfd_reloc_overflow;
3372 + return bfd_reloc_ok;
3376 +static bfd_reloc_status_type
3377 +avr32_final_link_relocate(reloc_howto_type *howto,
3379 + asection *input_section,
3380 + bfd_byte *contents,
3381 + Elf_Internal_Rela *rel,
3385 + bfd_vma relocation;
3386 + bfd_reloc_status_type status;
3387 + bfd_byte *p = contents + rel->r_offset;
3390 + pr_debug(" (6b) final link relocate\n");
3392 + /* Sanity check the address */
3393 + if (rel->r_offset > input_section->size)
3395 + (*_bfd_error_handler)
3396 + ("%B: %A+0x%lx: offset out of range (section size: 0x%lx)",
3397 + input_bfd, input_section, rel->r_offset, input_section->size);
3398 + return bfd_reloc_outofrange;
3401 + relocation = value + rel->r_addend;
3403 + if (howto->pc_relative)
3407 + addr = input_section->output_section->vma
3408 + + input_section->output_offset + rel->r_offset;
3409 + addr &= ~0UL << howto->rightshift;
3410 + relocation -= addr;
3413 + switch (ELF32_R_TYPE(rel->r_info))
3415 + case R_AVR32_16N_PCREL:
3416 + /* sub reg, pc, . - (sym + addend) */
3417 + relocation = -relocation;
3421 + status = avr32_check_reloc_value(input_section, rel, relocation, howto);
3423 + relocation >>= howto->rightshift;
3424 + if (howto->bitsize == 21)
3425 + field = (relocation & 0xffff)
3426 + | ((relocation & 0x10000) << 4)
3427 + | ((relocation & 0x1e0000) << 8);
3428 + else if (howto->bitsize == 12)
3429 + field = (relocation & 0xff) | ((relocation & 0xf00) << 4);
3430 + else if (howto->bitsize == 10)
3431 + field = ((relocation & 0xff) << 4)
3432 + | ((relocation & 0x300) >> 8);
3434 + field = relocation << howto->bitpos;
3436 + switch (howto->size)
3439 + x = bfd_get_8 (input_bfd, p);
3440 + x &= ~howto->dst_mask;
3441 + x |= field & howto->dst_mask;
3442 + bfd_put_8 (input_bfd, (bfd_vma) x, p);
3445 + x = bfd_get_16 (input_bfd, p);
3446 + x &= ~howto->dst_mask;
3447 + x |= field & howto->dst_mask;
3448 + bfd_put_16 (input_bfd, (bfd_vma) x, p);
3451 + x = bfd_get_32 (input_bfd, p);
3452 + x &= ~howto->dst_mask;
3453 + x |= field & howto->dst_mask;
3454 + bfd_put_32 (input_bfd, (bfd_vma) x, p);
3463 +/* (6) Apply relocations to the normal (non-dynamic) sections */
3466 +avr32_elf_relocate_section(bfd *output_bfd, struct bfd_link_info *info,
3467 + bfd *input_bfd, asection *input_section,
3468 + bfd_byte *contents, Elf_Internal_Rela *relocs,
3469 + Elf_Internal_Sym *local_syms,
3470 + asection **local_sections)
3472 + struct elf_avr32_link_hash_table *htab;
3473 + Elf_Internal_Shdr *symtab_hdr;
3474 + Elf_Internal_Rela *rel, *relend;
3475 + struct elf_link_hash_entry **sym_hashes;
3476 + struct got_entry **local_got_ents;
3478 + asection *srelgot;
3480 + pr_debug("(6) relocate section %s:<%s> (size 0x%lx)\n",
3481 + input_bfd->filename, input_section->name, input_section->size);
3483 + /* If we're doing a partial link, we don't have to do anything since
3484 + we're using RELA relocations */
3485 + if (info->relocatable)
3488 + htab = avr32_elf_hash_table(info);
3489 + symtab_hdr = &elf_tdata(input_bfd)->symtab_hdr;
3490 + sym_hashes = elf_sym_hashes(input_bfd);
3491 + local_got_ents = elf_local_got_ents(input_bfd);
3492 + sgot = htab->sgot;
3493 + srelgot = htab->srelgot;
3495 + relend = relocs + input_section->reloc_count;
3496 + for (rel = relocs; rel < relend; rel++)
3498 + unsigned long r_type, r_symndx;
3499 + reloc_howto_type *howto;
3500 + Elf_Internal_Sym *sym = NULL;
3501 + struct elf_link_hash_entry *h = NULL;
3502 + asection *sec = NULL;
3505 + bfd_reloc_status_type status;
3507 + r_type = ELF32_R_TYPE(rel->r_info);
3508 + r_symndx = ELF32_R_SYM(rel->r_info);
3510 + if (r_type == R_AVR32_NONE
3511 + || r_type == R_AVR32_ALIGN
3512 + || r_type == R_AVR32_DIFF32
3513 + || r_type == R_AVR32_DIFF16
3514 + || r_type == R_AVR32_DIFF8)
3517 + /* Sanity check */
3518 + if (r_type > R_AVR32_max)
3520 + bfd_set_error(bfd_error_bad_value);
3524 + howto = &elf_avr32_howto_table[r_type];
3526 + if (r_symndx < symtab_hdr->sh_info)
3528 + sym = local_syms + r_symndx;
3529 + sec = local_sections[r_symndx];
3531 + pr_debug(" (6a) processing %s against local symbol %lu\n",
3532 + howto->name, r_symndx);
3534 + /* The following function changes rel->r_addend behind our back. */
3535 + value = _bfd_elf_rela_local_sym(output_bfd, sym, &sec, rel);
3536 + pr_debug(" => value: %lx, addend: %lx\n", value, rel->r_addend);
3540 + if (sym_hashes == NULL)
3543 + h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3544 + while (h->root.type == bfd_link_hash_indirect
3545 + || h->root.type == bfd_link_hash_warning)
3546 + h = (struct elf_link_hash_entry *)h->root.u.i.link;
3548 + pr_debug(" (6a) processing %s against symbol %s\n",
3549 + howto->name, h->root.root.string);
3551 + if (h->root.type == bfd_link_hash_defined
3552 + || h->root.type == bfd_link_hash_defweak)
3556 + dyn = htab->root.dynamic_sections_created;
3557 + sec = h->root.u.def.section;
3559 + if (sec->output_section)
3560 + value = (h->root.u.def.value
3561 + + sec->output_section->vma
3562 + + sec->output_offset);
3564 + value = h->root.u.def.value;
3566 + else if (h->root.type == bfd_link_hash_undefweak)
3568 + else if (info->unresolved_syms_in_objects == RM_IGNORE
3569 + && ELF_ST_VISIBILITY(h->other) == STV_DEFAULT)
3574 + err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
3575 + || ELF_ST_VISIBILITY(h->other) != STV_DEFAULT);
3576 + if (!info->callbacks->undefined_symbol
3577 + (info, h->root.root.string, input_bfd,
3578 + input_section, rel->r_offset, err))
3583 + pr_debug(" => value: %lx, addend: %lx\n", value, rel->r_addend);
3588 + case R_AVR32_GOT32:
3589 + case R_AVR32_GOT16:
3590 + case R_AVR32_GOT8:
3591 + case R_AVR32_GOT21S:
3592 + case R_AVR32_GOT18SW:
3593 + case R_AVR32_GOT16S:
3594 + case R_AVR32_GOT7UW:
3595 + case R_AVR32_LDA_GOT:
3596 + case R_AVR32_GOTCALL:
3597 + BFD_ASSERT(sgot != NULL);
3601 + BFD_ASSERT(h->got.glist->refcount > 0);
3602 + offset = h->got.glist->offset;
3604 + BFD_ASSERT(offset < sgot->size);
3605 + if (!elf_hash_table(info)->dynamic_sections_created
3606 + || (h->def_regular
3609 + || h->dynindx == -1)))
3611 + /* This is actually a static link, or it is a
3612 + -Bsymbolic link and the symbol is defined
3613 + locally, or the symbol was forced to be local. */
3614 + bfd_put_32(output_bfd, value, sgot->contents + offset);
3619 + BFD_ASSERT(local_got_ents &&
3620 + local_got_ents[r_symndx]->refcount > 0);
3621 + offset = local_got_ents[r_symndx]->offset;
3623 + /* Local GOT entries don't have relocs. If this is a
3624 + shared library, the dynamic linker will add the load
3625 + address to the initial value at startup. */
3626 + BFD_ASSERT(offset < sgot->size);
3627 + pr_debug("Initializing GOT entry at offset %lu: 0x%lx\n",
3629 + bfd_put_32 (output_bfd, value, sgot->contents + offset);
3632 + value = sgot->output_offset + offset;
3633 + pr_debug("GOT reference: New value %lx\n", value);
3636 + case R_AVR32_GOTPC:
3637 + /* This relocation type is for constant pool entries used in
3638 + the calculation "Rd = PC - (PC - GOT)", where the
3639 + constant pool supplies the constant (PC - GOT)
3640 + offset. The symbol value + addend indicates where the
3641 + value of PC is taken. */
3642 + value -= sgot->output_section->vma;
3645 + case R_AVR32_32_PCREL:
3646 + /* We must adjust r_offset to account for discarded data in
3647 + the .eh_frame section. This is probably not the right
3648 + way to do this, since AFAICS all other architectures do
3649 + it some other way. I just can't figure out how... */
3653 + r_offset = _bfd_elf_section_offset(output_bfd, info,
3656 + if (r_offset == (bfd_vma)-1
3657 + || r_offset == (bfd_vma)-2)
3659 + rel->r_offset = r_offset;
3664 + /* We need to emit a run-time relocation in the following cases:
3665 + - we're creating a shared library
3666 + - the symbol is not defined in any regular objects
3668 + Of course, sections that aren't going to be part of the
3669 + run-time image will not get any relocs, and undefined
3670 + symbols won't have any either (only weak undefined
3671 + symbols should get this far). */
3673 + || (elf_hash_table(info)->dynamic_sections_created
3676 + && !h->def_regular))
3678 + && (input_section->flags & SEC_ALLOC))
3680 + Elf_Internal_Rela outrel;
3682 + bfd_boolean skip, relocate;
3683 + struct elf_avr32_link_hash_entry *avrh;
3685 + pr_debug("Going to generate dynamic reloc...\n");
3690 + outrel.r_offset = _bfd_elf_section_offset(output_bfd, info,
3693 + if (outrel.r_offset == (bfd_vma)-1)
3695 + else if (outrel.r_offset == (bfd_vma)-2)
3696 + skip = TRUE, relocate = TRUE;
3698 + outrel.r_offset += (input_section->output_section->vma
3699 + + input_section->output_offset);
3701 + pr_debug(" ... offset %lx, dynindx %ld\n",
3702 + outrel.r_offset, h ? h->dynindx : -1);
3705 + memset(&outrel, 0, sizeof(outrel));
3708 + avrh = (struct elf_avr32_link_hash_entry *)h;
3709 + /* h->dynindx may be -1 if this symbol was marked to
3712 + || ((info->symbolic || h->dynindx == -1)
3713 + && h->def_regular))
3716 + outrel.r_info = ELF32_R_INFO(0, R_AVR32_RELATIVE);
3717 + outrel.r_addend = value + rel->r_addend;
3718 + pr_debug(" ... R_AVR32_RELATIVE\n");
3722 + BFD_ASSERT(h->dynindx != -1);
3724 + outrel.r_info = ELF32_R_INFO(h->dynindx, R_AVR32_GLOB_DAT);
3725 + outrel.r_addend = rel->r_addend;
3726 + pr_debug(" ... R_AVR32_GLOB_DAT\n");
3730 + pr_debug("srelgot reloc_count: %d, size %lu\n",
3731 + srelgot->reloc_count, srelgot->size);
3733 + loc = srelgot->contents;
3734 + loc += srelgot->reloc_count++ * sizeof(Elf32_External_Rela);
3735 + bfd_elf32_swap_reloca_out(output_bfd, &outrel, loc);
3737 + BFD_ASSERT(srelgot->reloc_count * sizeof(Elf32_External_Rela)
3738 + <= srelgot->size);
3746 + status = avr32_final_link_relocate(howto, input_bfd, input_section,
3747 + contents, rel, value);
3751 + case bfd_reloc_ok:
3754 + case bfd_reloc_overflow:
3759 + name = h->root.root.string;
3762 + name = bfd_elf_string_from_elf_section(input_bfd,
3763 + symtab_hdr->sh_link,
3767 + if (*name == '\0')
3768 + name = bfd_section_name(input_bfd, sec);
3770 + if (!((*info->callbacks->reloc_overflow)
3771 + (info, (h ? &h->root : NULL), name, howto->name,
3772 + rel->r_addend, input_bfd, input_section, rel->r_offset)))
3777 + case bfd_reloc_outofrange:
3787 +/* Additional processing of dynamic sections after relocation */
3790 +avr32_elf_finish_dynamic_symbol(bfd *output_bfd, struct bfd_link_info *info,
3791 + struct elf_link_hash_entry *h,
3792 + Elf_Internal_Sym *sym);
3794 +avr32_elf_finish_dynamic_sections(bfd *output_bfd, struct bfd_link_info *info);
3797 +/* (7) Initialize the contents of a dynamic symbol and/or emit
3798 + relocations for it */
3801 +avr32_elf_finish_dynamic_symbol(bfd *output_bfd, struct bfd_link_info *info,
3802 + struct elf_link_hash_entry *h,
3803 + Elf_Internal_Sym *sym)
3805 + struct elf_avr32_link_hash_table *htab;
3806 + struct got_entry *got;
3808 + pr_debug("(7) finish dynamic symbol: %s\n", h->root.root.string);
3810 + htab = avr32_elf_hash_table(info);
3811 + got = h->got.glist;
3813 + if (got && got->refcount > 0)
3816 + asection *srelgot;
3817 + Elf_Internal_Rela rel;
3820 + /* This symbol has an entry in the GOT. Set it up. */
3821 + sgot = htab->sgot;
3822 + srelgot = htab->srelgot;
3823 + BFD_ASSERT(sgot && srelgot);
3825 + rel.r_offset = (sgot->output_section->vma
3826 + + sgot->output_offset
3829 + /* If this is a static link, or it is a -Bsymbolic link and the
3830 + symbol is defined locally or was forced to be local because
3831 + of a version file, we just want to emit a RELATIVE reloc. The
3832 + entry in the global offset table will already have been
3833 + initialized in the relocate_section function. */
3835 + && !info->symbolic
3836 + && h->dynindx != -1)
3837 + || (htab->root.dynamic_sections_created
3839 + && !h->def_regular))
3841 + bfd_put_32(output_bfd, 0, sgot->contents + got->offset);
3842 + rel.r_info = ELF32_R_INFO(h->dynindx, R_AVR32_GLOB_DAT);
3845 + pr_debug("GOT reloc R_AVR32_GLOB_DAT, dynindx: %ld\n", h->dynindx);
3846 + pr_debug(" srelgot reloc_count: %d, size: %lu\n",
3847 + srelgot->reloc_count, srelgot->size);
3849 + loc = (srelgot->contents
3850 + + srelgot->reloc_count++ * sizeof(Elf32_External_Rela));
3851 + bfd_elf32_swap_reloca_out(output_bfd, &rel, loc);
3853 + BFD_ASSERT(srelgot->reloc_count * sizeof(Elf32_External_Rela)
3854 + <= srelgot->size);
3858 + /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute */
3859 + if (strcmp(h->root.root.string, "_DYNAMIC") == 0
3860 + || strcmp(h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3861 + sym->st_shndx = SHN_ABS;
3866 +/* (8) Do any remaining initialization of the dynamic sections */
3869 +avr32_elf_finish_dynamic_sections(bfd *output_bfd, struct bfd_link_info *info)
3871 + struct elf_avr32_link_hash_table *htab;
3872 + asection *sgot, *sdyn;
3874 + pr_debug("(8) finish dynamic sections\n");
3876 + htab = avr32_elf_hash_table(info);
3877 + sgot = htab->sgot;
3878 + sdyn = bfd_get_section_by_name(htab->root.dynobj, ".dynamic");
3880 + if (htab->root.dynamic_sections_created)
3882 + Elf32_External_Dyn *dyncon, *dynconend;
3884 + BFD_ASSERT(sdyn && sgot && sgot->size >= AVR32_GOT_HEADER_SIZE);
3886 + dyncon = (Elf32_External_Dyn *)sdyn->contents;
3887 + dynconend = (Elf32_External_Dyn *)(sdyn->contents + sdyn->size);
3888 + for (; dyncon < dynconend; dyncon++)
3890 + Elf_Internal_Dyn dyn;
3893 + bfd_elf32_swap_dyn_in(htab->root.dynobj, dyncon, &dyn);
3895 + switch (dyn.d_tag)
3901 + s = sgot->output_section;
3902 + BFD_ASSERT(s != NULL);
3903 + dyn.d_un.d_ptr = s->vma;
3904 + bfd_elf32_swap_dyn_out(output_bfd, &dyn, dyncon);
3907 + case DT_AVR32_GOTSZ:
3908 + s = sgot->output_section;
3909 + BFD_ASSERT(s != NULL);
3910 + dyn.d_un.d_val = s->size;
3911 + bfd_elf32_swap_dyn_out(output_bfd, &dyn, dyncon);
3916 + /* Fill in the first two entries in the global offset table */
3917 + bfd_put_32(output_bfd,
3918 + sdyn->output_section->vma + sdyn->output_offset,
3921 + /* The runtime linker will fill this one in with the address of
3922 + the run-time link map */
3923 + bfd_put_32(output_bfd, 0, sgot->contents + 4);
3927 + elf_section_data(sgot->output_section)->this_hdr.sh_entsize = 4;
3933 +/* AVR32-specific private ELF data */
3936 +avr32_elf_set_private_flags(bfd *abfd, flagword flags);
3938 +avr32_elf_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
3940 +avr32_elf_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
3942 +avr32_elf_print_private_bfd_data(bfd *abfd, void *ptr);
3945 +avr32_elf_set_private_flags(bfd *abfd, flagword flags)
3947 + elf_elfheader(abfd)->e_flags = flags;
3948 + elf_flags_init(abfd) = TRUE;
3953 +/* Copy backend specific data from one object module to another. */
3956 +avr32_elf_copy_private_bfd_data(bfd *ibfd, bfd *obfd)
3958 + elf_elfheader(obfd)->e_flags = elf_elfheader(ibfd)->e_flags;
3962 +/* Merge backend specific data from an object file to the output
3963 + object file when linking. */
3966 +avr32_elf_merge_private_bfd_data(bfd *ibfd, bfd *obfd)
3968 + flagword out_flags, in_flags;
3970 + pr_debug("(0) merge_private_bfd_data: %s -> %s\n",
3971 + ibfd->filename, obfd->filename);
3973 + in_flags = elf_elfheader(ibfd)->e_flags;
3974 + out_flags = elf_elfheader(obfd)->e_flags;
3976 + if (elf_flags_init(obfd))
3978 + /* If one of the inputs are non-PIC, the output must be
3979 + considered non-PIC. The same applies to linkrelax. */
3980 + if (!(in_flags & EF_AVR32_PIC))
3981 + out_flags &= ~EF_AVR32_PIC;
3982 + if (!(in_flags & EF_AVR32_LINKRELAX))
3983 + out_flags &= ~EF_AVR32_LINKRELAX;
3987 + elf_flags_init(obfd) = TRUE;
3988 + out_flags = in_flags;
3991 + elf_elfheader(obfd)->e_flags = out_flags;
3997 +avr32_elf_print_private_bfd_data(bfd *abfd, void *ptr)
3999 + FILE *file = (FILE *)ptr;
4000 + unsigned long flags;
4002 + BFD_ASSERT(abfd != NULL && ptr != NULL);
4004 + _bfd_elf_print_private_bfd_data(abfd, ptr);
4006 + flags = elf_elfheader(abfd)->e_flags;
4008 + fprintf(file, _("private flags = %lx:"), elf_elfheader(abfd)->e_flags);
4010 + if (flags & EF_AVR32_PIC)
4011 + fprintf(file, " [PIC]");
4012 + if (flags & EF_AVR32_LINKRELAX)
4013 + fprintf(file, " [linker relaxable]");
4015 + flags &= ~(EF_AVR32_PIC | EF_AVR32_LINKRELAX);
4018 + fprintf(file, _("<Unrecognized flag bits set>"));
4020 + fputc('\n', file);
4025 +/* Set avr32-specific linker options. */
4026 +void bfd_elf32_avr32_set_options(struct bfd_link_info *info,
4027 + int direct_data_refs)
4029 + struct elf_avr32_link_hash_table *htab;
4031 + htab = avr32_elf_hash_table (info);
4032 + htab->direct_data_refs = !!direct_data_refs;
4037 +/* Understanding core dumps */
4040 +avr32_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note);
4042 +avr32_elf_grok_psinfo(bfd *abfd, Elf_Internal_Note *note);
4045 +avr32_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note)
4047 + /* Linux/AVR32B elf_prstatus */
4048 + if (note->descsz != 148)
4052 + elf_tdata(abfd)->core_signal = bfd_get_16(abfd, note->descdata + 12);
4055 + elf_tdata(abfd)->core_pid = bfd_get_32(abfd, note->descdata + 24);
4057 + /* Make a ".reg/999" section for pr_reg. The size is for 16
4058 + general-purpose registers, SR and r12_orig (18 * 4 = 72). */
4059 + return _bfd_elfcore_make_pseudosection(abfd, ".reg", 72,
4060 + note->descpos + 72);
4064 +avr32_elf_grok_psinfo(bfd *abfd, Elf_Internal_Note *note)
4066 + /* Linux/AVR32B elf_prpsinfo */
4067 + if (note->descsz != 128)
4070 + elf_tdata(abfd)->core_program
4071 + = _bfd_elfcore_strndup(abfd, note->descdata + 32, 16);
4072 + elf_tdata(abfd)->core_command
4073 + = _bfd_elfcore_strndup(abfd, note->descdata + 48, 80);
4075 + /* Note that for some reason, a spurious space is tacked
4076 + onto the end of the args in some (at least one anyway)
4077 + implementations, so strip it off if it exists. */
4080 + char *command = elf_tdata (abfd)->core_command;
4081 + int n = strlen (command);
4083 + if (0 < n && command[n - 1] == ' ')
4084 + command[n - 1] = '\0';
4091 +#define ELF_ARCH bfd_arch_avr32
4092 +#define ELF_MACHINE_CODE EM_AVR32
4093 +#define ELF_MAXPAGESIZE 1024
4095 +#define TARGET_BIG_SYM bfd_elf32_avr32_vec
4096 +#define TARGET_BIG_NAME "elf32-avr32"
4098 +#define elf_backend_grok_prstatus avr32_elf_grok_prstatus
4099 +#define elf_backend_grok_psinfo avr32_elf_grok_psinfo
4101 +/* Only RELA relocations are used */
4102 +#define elf_backend_may_use_rel_p 0
4103 +#define elf_backend_may_use_rela_p 1
4104 +#define elf_backend_default_use_rela_p 1
4105 +#define elf_backend_rela_normal 1
4106 +#define elf_info_to_howto_rel NULL
4107 +#define elf_info_to_howto avr32_info_to_howto
4109 +#define bfd_elf32_bfd_copy_private_bfd_data avr32_elf_copy_private_bfd_data
4110 +#define bfd_elf32_bfd_merge_private_bfd_data avr32_elf_merge_private_bfd_data
4111 +#define bfd_elf32_bfd_set_private_flags avr32_elf_set_private_flags
4112 +#define bfd_elf32_bfd_print_private_bfd_data avr32_elf_print_private_bfd_data
4113 +#define bfd_elf32_new_section_hook avr32_elf_new_section_hook
4115 +#define elf_backend_gc_mark_hook avr32_elf_gc_mark_hook
4116 +#define elf_backend_gc_sweep_hook avr32_elf_gc_sweep_hook
4117 +#define elf_backend_relocate_section avr32_elf_relocate_section
4118 +#define elf_backend_copy_indirect_symbol avr32_elf_copy_indirect_symbol
4119 +#define elf_backend_create_dynamic_sections avr32_elf_create_dynamic_sections
4120 +#define bfd_elf32_bfd_link_hash_table_create avr32_elf_link_hash_table_create
4121 +#define elf_backend_adjust_dynamic_symbol avr32_elf_adjust_dynamic_symbol
4122 +#define elf_backend_size_dynamic_sections avr32_elf_size_dynamic_sections
4123 +#define elf_backend_finish_dynamic_symbol avr32_elf_finish_dynamic_symbol
4124 +#define elf_backend_finish_dynamic_sections avr32_elf_finish_dynamic_sections
4126 +#define bfd_elf32_bfd_relax_section avr32_elf_relax_section
4128 +/* Find out which symbols need an entry in .got. */
4129 +#define elf_backend_check_relocs avr32_check_relocs
4130 +#define elf_backend_can_refcount 1
4131 +#define elf_backend_can_gc_sections 1
4132 +#define elf_backend_plt_readonly 1
4133 +#define elf_backend_plt_not_loaded 1
4134 +#define elf_backend_want_plt_sym 0
4135 +#define elf_backend_plt_alignment 2
4136 +#define elf_backend_want_dynbss 0
4137 +#define elf_backend_want_got_plt 0
4138 +#define elf_backend_want_got_sym 1
4139 +#define elf_backend_got_header_size AVR32_GOT_HEADER_SIZE
4141 +#include "elf32-target.h"
4142 --- a/bfd/elf32-avr32.h
4143 +++ b/bfd/elf32-avr32.h
4145 +/* AVR32-specific support for 32-bit ELF.
4146 + Copyright 2007,2008,2009 Atmel Corporation.
4148 + Written by Haavard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
4150 + This file is part of BFD, the Binary File Descriptor library.
4152 + This program is free software; you can redistribute it and/or modify
4153 + it under the terms of the GNU General Public License as published by
4154 + the Free Software Foundation; either version 2 of the License, or
4155 + (at your option) any later version.
4157 + This program is distributed in the hope that it will be useful,
4158 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4159 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4160 + GNU General Public License for more details.
4162 + You should have received a copy of the GNU General Public License
4163 + along with this program; if not, write to the Free Software
4164 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
4166 +void bfd_elf32_avr32_set_options(struct bfd_link_info *info,
4167 + int direct_data_refs);
4170 @@ -1498,6 +1498,10 @@ struct elf_obj_tdata
4171 find_nearest_line. */
4172 struct mips_elf_find_line *find_line_info;
4174 + /* Used by AVR32 ELF relaxation code. Contains an array of pointers
4175 + for each local symbol to the fragment where it is defined. */
4176 + struct fragment **local_sym_frag;
4178 /* A place to stash dwarf1 info for this bfd. */
4179 struct dwarf1_debug *dwarf1_find_line_info;
4183 @@ -1614,6 +1614,48 @@ static const char *const bfd_reloc_code_
4184 "BFD_RELOC_AVR_LDI",
4186 "BFD_RELOC_AVR_6_ADIW",
4187 + "BFD_RELOC_AVR32_DIFF32",
4188 + "BFD_RELOC_AVR32_DIFF16",
4189 + "BFD_RELOC_AVR32_DIFF8",
4190 + "BFD_RELOC_AVR32_GOT32",
4191 + "BFD_RELOC_AVR32_GOT16",
4192 + "BFD_RELOC_AVR32_GOT8",
4193 + "BFD_RELOC_AVR32_21S",
4194 + "BFD_RELOC_AVR32_16U",
4195 + "BFD_RELOC_AVR32_16S",
4196 + "BFD_RELOC_AVR32_SUB5",
4197 + "BFD_RELOC_AVR32_8S_EXT",
4198 + "BFD_RELOC_AVR32_8S",
4199 + "BFD_RELOC_AVR32_15S",
4200 + "BFD_RELOC_AVR32_22H_PCREL",
4201 + "BFD_RELOC_AVR32_18W_PCREL",
4202 + "BFD_RELOC_AVR32_16B_PCREL",
4203 + "BFD_RELOC_AVR32_16N_PCREL",
4204 + "BFD_RELOC_AVR32_14UW_PCREL",
4205 + "BFD_RELOC_AVR32_11H_PCREL",
4206 + "BFD_RELOC_AVR32_10UW_PCREL",
4207 + "BFD_RELOC_AVR32_9H_PCREL",
4208 + "BFD_RELOC_AVR32_9UW_PCREL",
4209 + "BFD_RELOC_AVR32_GOTPC",
4210 + "BFD_RELOC_AVR32_GOTCALL",
4211 + "BFD_RELOC_AVR32_LDA_GOT",
4212 + "BFD_RELOC_AVR32_GOT21S",
4213 + "BFD_RELOC_AVR32_GOT18SW",
4214 + "BFD_RELOC_AVR32_GOT16S",
4215 + "BFD_RELOC_AVR32_32_CPENT",
4216 + "BFD_RELOC_AVR32_CPCALL",
4217 + "BFD_RELOC_AVR32_16_CP",
4218 + "BFD_RELOC_AVR32_9W_CP",
4219 + "BFD_RELOC_AVR32_ALIGN",
4220 + "BFD_RELOC_AVR32_14UW",
4221 + "BFD_RELOC_AVR32_10UW",
4222 + "BFD_RELOC_AVR32_10SW",
4223 + "BFD_RELOC_AVR32_STHH_W",
4224 + "BFD_RELOC_AVR32_7UW",
4225 + "BFD_RELOC_AVR32_6S",
4226 + "BFD_RELOC_AVR32_6UW",
4227 + "BFD_RELOC_AVR32_4UH",
4228 + "BFD_RELOC_AVR32_3U",
4230 "BFD_RELOC_390_GOT12",
4231 "BFD_RELOC_390_PLT32",
4232 --- a/bfd/Makefile.am
4233 +++ b/bfd/Makefile.am
4234 @@ -63,6 +63,7 @@ ALL_MACHINES = \
4242 @@ -247,6 +248,7 @@ BFD32_BACKENDS = \
4250 @@ -1355,6 +1357,10 @@ elf32-cr16.lo: elf32-cr16.c $(INCDIR)/fi
4251 $(INCDIR)/hashtab.h $(INCDIR)/libiberty.h elf-bfd.h \
4252 $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
4253 $(INCDIR)/elf/cr16.h $(INCDIR)/elf/reloc-macros.h elf32-target.h
4254 +elf32-avr32.lo: elf32-avr32.c $(INCDIR)/filenames.h elf-bfd.h \