- HOWTO (R_AVR_LO8_LDI_GS, /* type */
- 1, /* rightshift */
- 1, /* size (0 = byte, 1 = short, 2 = long) */
- 8, /* bitsize */
- FALSE, /* pc_relative */
- 0, /* bitpos */
- complain_overflow_dont, /* complain_on_overflow */
- bfd_elf_generic_reloc, /* special_function */
- "R_AVR_LO8_LDI_GS", /* name */
- FALSE, /* partial_inplace */
- 0xffff, /* src_mask */
- 0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ HOWTO (R_AVR_LO8_LDI_GS, /* type */
+ 1, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 8, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_AVR_LO8_LDI_GS", /* name */
+ FALSE, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
- HOWTO (R_AVR_HI8_LDI_GS, /* type */
- 9, /* rightshift */
- 1, /* size (0 = byte, 1 = short, 2 = long) */
- 8, /* bitsize */
- FALSE, /* pc_relative */
- 0, /* bitpos */
- complain_overflow_dont, /* complain_on_overflow */
- bfd_elf_generic_reloc, /* special_function */
- "R_AVR_HI8_LDI_GS", /* name */
- FALSE, /* partial_inplace */
- 0xffff, /* src_mask */
- 0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ HOWTO (R_AVR_HI8_LDI_GS, /* type */
+ 9, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 8, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_AVR_HI8_LDI_GS", /* name */
+ FALSE, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
- "R_AVR_DIFF16", /* name */
- FALSE, /* partial_inplace */
- 0, /* src_mask */
- 0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
- HOWTO (R_AVR_DIFF32, /* type */
- 0, /* rightshift */
- 2, /* size (0 = byte, 1 = short, 2 = long) */
- 32, /* bitsize */
- FALSE, /* pc_relative */
- 0, /* bitpos */
+ "R_AVR_DIFF16", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+ HOWTO (R_AVR_DIFF32, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
- { BFD_RELOC_NONE, R_AVR_NONE },
- { BFD_RELOC_32, R_AVR_32 },
- { BFD_RELOC_AVR_7_PCREL, R_AVR_7_PCREL },
- { BFD_RELOC_AVR_13_PCREL, R_AVR_13_PCREL },
- { BFD_RELOC_16, R_AVR_16 },
- { BFD_RELOC_AVR_16_PM, R_AVR_16_PM },
- { BFD_RELOC_AVR_LO8_LDI, R_AVR_LO8_LDI},
- { BFD_RELOC_AVR_HI8_LDI, R_AVR_HI8_LDI },
- { BFD_RELOC_AVR_HH8_LDI, R_AVR_HH8_LDI },
- { BFD_RELOC_AVR_MS8_LDI, R_AVR_MS8_LDI },
- { BFD_RELOC_AVR_LO8_LDI_NEG, R_AVR_LO8_LDI_NEG },
- { BFD_RELOC_AVR_HI8_LDI_NEG, R_AVR_HI8_LDI_NEG },
- { BFD_RELOC_AVR_HH8_LDI_NEG, R_AVR_HH8_LDI_NEG },
- { BFD_RELOC_AVR_MS8_LDI_NEG, R_AVR_MS8_LDI_NEG },
- { BFD_RELOC_AVR_LO8_LDI_PM, R_AVR_LO8_LDI_PM },
- { BFD_RELOC_AVR_LO8_LDI_GS, R_AVR_LO8_LDI_GS },
- { BFD_RELOC_AVR_HI8_LDI_PM, R_AVR_HI8_LDI_PM },
- { BFD_RELOC_AVR_HI8_LDI_GS, R_AVR_HI8_LDI_GS },
- { BFD_RELOC_AVR_HH8_LDI_PM, R_AVR_HH8_LDI_PM },
+ { BFD_RELOC_NONE, R_AVR_NONE },
+ { BFD_RELOC_32, R_AVR_32 },
+ { BFD_RELOC_AVR_7_PCREL, R_AVR_7_PCREL },
+ { BFD_RELOC_AVR_13_PCREL, R_AVR_13_PCREL },
+ { BFD_RELOC_16, R_AVR_16 },
+ { BFD_RELOC_AVR_16_PM, R_AVR_16_PM },
+ { BFD_RELOC_AVR_LO8_LDI, R_AVR_LO8_LDI},
+ { BFD_RELOC_AVR_HI8_LDI, R_AVR_HI8_LDI },
+ { BFD_RELOC_AVR_HH8_LDI, R_AVR_HH8_LDI },
+ { BFD_RELOC_AVR_MS8_LDI, R_AVR_MS8_LDI },
+ { BFD_RELOC_AVR_LO8_LDI_NEG, R_AVR_LO8_LDI_NEG },
+ { BFD_RELOC_AVR_HI8_LDI_NEG, R_AVR_HI8_LDI_NEG },
+ { BFD_RELOC_AVR_HH8_LDI_NEG, R_AVR_HH8_LDI_NEG },
+ { BFD_RELOC_AVR_MS8_LDI_NEG, R_AVR_MS8_LDI_NEG },
+ { BFD_RELOC_AVR_LO8_LDI_PM, R_AVR_LO8_LDI_PM },
+ { BFD_RELOC_AVR_LO8_LDI_GS, R_AVR_LO8_LDI_GS },
+ { BFD_RELOC_AVR_HI8_LDI_PM, R_AVR_HI8_LDI_PM },
+ { BFD_RELOC_AVR_HI8_LDI_GS, R_AVR_HI8_LDI_GS },
+ { BFD_RELOC_AVR_HH8_LDI_PM, R_AVR_HH8_LDI_PM },
- { BFD_RELOC_AVR_CALL, R_AVR_CALL },
- { BFD_RELOC_AVR_LDI, R_AVR_LDI },
- { BFD_RELOC_AVR_6, R_AVR_6 },
- { BFD_RELOC_AVR_6_ADIW, R_AVR_6_ADIW },
- { BFD_RELOC_8, R_AVR_8 },
- { BFD_RELOC_AVR_8_LO, R_AVR_8_LO8 },
- { BFD_RELOC_AVR_8_HI, R_AVR_8_HI8 },
- { BFD_RELOC_AVR_8_HLO, R_AVR_8_HLO8 },
- { BFD_RELOC_AVR_DIFF8, R_AVR_DIFF8 },
- { BFD_RELOC_AVR_DIFF16, R_AVR_DIFF16 },
- { BFD_RELOC_AVR_DIFF32, R_AVR_DIFF32 },
- { BFD_RELOC_AVR_LDS_STS_16, R_AVR_LDS_STS_16},
- { BFD_RELOC_AVR_PORT6, R_AVR_PORT6},
- { BFD_RELOC_AVR_PORT5, R_AVR_PORT5},
- { BFD_RELOC_32_PCREL, R_AVR_32_PCREL}
+ { BFD_RELOC_AVR_CALL, R_AVR_CALL },
+ { BFD_RELOC_AVR_LDI, R_AVR_LDI },
+ { BFD_RELOC_AVR_6, R_AVR_6 },
+ { BFD_RELOC_AVR_6_ADIW, R_AVR_6_ADIW },
+ { BFD_RELOC_8, R_AVR_8 },
+ { BFD_RELOC_AVR_8_LO, R_AVR_8_LO8 },
+ { BFD_RELOC_AVR_8_HI, R_AVR_8_HI8 },
+ { BFD_RELOC_AVR_8_HLO, R_AVR_8_HLO8 },
+ { BFD_RELOC_AVR_DIFF8, R_AVR_DIFF8 },
+ { BFD_RELOC_AVR_DIFF16, R_AVR_DIFF16 },
+ { BFD_RELOC_AVR_DIFF32, R_AVR_DIFF32 },
+ { BFD_RELOC_AVR_LDS_STS_16, R_AVR_LDS_STS_16},
+ { BFD_RELOC_AVR_PORT6, R_AVR_PORT6},
+ { BFD_RELOC_AVR_PORT5, R_AVR_PORT5},
+ { BFD_RELOC_32_PCREL, R_AVR_32_PCREL}
+};
+
+static const struct bfd_elf_special_section elf_avr_special_sections[] =
+{
+ { STRING_COMMA_LEN (".noinit"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
+ { NULL, 0, 0, 0, 0 }
- && avr_stub_is_required_for_16_bit_reloc (srel - base_addr))
- {
- bfd_vma old_srel = srel;
-
- /* We need to use the address of the stub instead. */
- srel = avr_get_stub_addr (srel, htab);
- if (debug_stubs)
- printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for "
- "reloc at address 0x%x.\n",
- (unsigned int) srel,
- (unsigned int) old_srel,
- (unsigned int) reloc_addr);
+ && avr_stub_is_required_for_16_bit_reloc (srel - base_addr))
+ {
+ bfd_vma old_srel = srel;
+
+ /* We need to use the address of the stub instead. */
+ srel = avr_get_stub_addr (srel, htab);
+ if (debug_stubs)
+ printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for "
+ "reloc at address 0x%x.\n",
+ (unsigned int) srel,
+ (unsigned int) old_srel,
+ (unsigned int) reloc_addr);
- && avr_stub_is_required_for_16_bit_reloc (srel - base_addr))
- {
- bfd_vma old_srel = srel;
-
- /* We need to use the address of the stub instead. */
- srel = avr_get_stub_addr (srel, htab);
- if (debug_stubs)
- printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for "
- "reloc at address 0x%x.\n",
- (unsigned int) srel,
- (unsigned int) old_srel,
- (unsigned int) reloc_addr);
+ && avr_stub_is_required_for_16_bit_reloc (srel - base_addr))
+ {
+ bfd_vma old_srel = srel;
+
+ /* We need to use the address of the stub instead. */
+ srel = avr_get_stub_addr (srel, htab);
+ if (debug_stubs)
+ printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for "
+ "reloc at address 0x%x.\n",
+ (unsigned int) srel,
+ (unsigned int) old_srel,
+ (unsigned int) reloc_addr);
- && avr_stub_is_required_for_16_bit_reloc (srel - base_addr))
- {
- bfd_vma old_srel = srel;
-
- /* We need to use the address of the stub instead. */
- srel = avr_get_stub_addr (srel,htab);
- if (debug_stubs)
- printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for "
- "reloc at address 0x%x.\n",
- (unsigned int) srel,
- (unsigned int) old_srel,
- (unsigned int) reloc_addr);
+ && avr_stub_is_required_for_16_bit_reloc (srel - base_addr))
+ {
+ bfd_vma old_srel = srel;
+
+ /* We need to use the address of the stub instead. */
+ srel = avr_get_stub_addr (srel,htab);
+ if (debug_stubs)
+ printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for "
+ "reloc at address 0x%x.\n",
+ (unsigned int) srel,
+ (unsigned int) old_srel,
+ (unsigned int) reloc_addr);
- /* We need to look at all relocs with offsets less than toaddr. prop
- records handling adjusts toaddr downwards to avoid moving syms at the
- address of the property record, but all relocs with offsets between addr
- and the current value of toaddr need to have their offsets adjusted.
- Assume addr = 0, toaddr = 4 and count = 2. After prop records handling,
- toaddr becomes 2, but relocs with offsets 2 and 3 still need to be
- adjusted (to 0 and 1 respectively), as the first 2 bytes are now gone.
- So record the current value of toaddr here, and use it when adjusting
- reloc offsets. */
- reloc_toaddr = toaddr;
+ BFD_ASSERT (offset <= addr || offset >= (addr + count));
+ if (offset >= (addr + count))
+ {
+ prop_record = &relax_info->records.items [i];
+ toaddr = offset;
+ break;
+ }
+ }
+ }
- && irel->r_offset < reloc_toaddr))
- {
- if (debug_relax)
- printf ("Relocation at address 0x%x needs to be moved.\n"
- "Old section offset: 0x%x, New section offset: 0x%x \n",
- (unsigned int) old_reloc_address,
- (unsigned int) irel->r_offset,
- (unsigned int) ((irel->r_offset) - count));
-
- irel->r_offset -= count;
- }
+ && irel->r_offset < toaddr))
+ {
+ if (debug_relax)
+ printf ("Relocation at address 0x%x needs to be moved.\n"
+ "Old section offset: 0x%x, New section offset: 0x%x \n",
+ (unsigned int) old_reloc_address,
+ (unsigned int) irel->r_offset,
+ (unsigned int) ((irel->r_offset) - count));
+
+ irel->r_offset -= count;
+ }
- irel < irelend;
- irel++)
- {
- /* Read this BFD's local symbols if we haven't done
- so already. */
- if (isymbuf == NULL && symtab_hdr->sh_info != 0)
- {
- isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
- if (isymbuf == NULL)
- isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- symtab_hdr->sh_info, 0,
- NULL, NULL, NULL);
- if (isymbuf == NULL)
- return FALSE;
- }
-
- /* Get the value of the symbol referred to by the reloc. */
- if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
- {
- /* A local symbol. */
- asection *sym_sec;
-
- isym = isymbuf + ELF32_R_SYM (irel->r_info);
- sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
- symval = isym->st_value;
- /* If the reloc is absolute, it will not have
- a symbol or section associated with it. */
- if (sym_sec == sec)
- {
- /* If there is an alignment boundary, we only need to
- adjust addends that end up below the boundary. */
- bfd_vma shrink_boundary = (reloc_toaddr
- + sec->output_section->vma
- + sec->output_offset);
-
- symval += sym_sec->output_section->vma
- + sym_sec->output_offset;
-
- if (debug_relax)
- printf ("Checking if the relocation's "
- "addend needs corrections.\n"
- "Address of anchor symbol: 0x%x \n"
- "Address of relocation target: 0x%x \n"
- "Address of relaxed insn: 0x%x \n",
- (unsigned int) symval,
- (unsigned int) (symval + irel->r_addend),
- (unsigned int) shrinked_insn_address);
-
- elf32_avr_adjust_reloc_if_spans_insn (abfd, isec, irel,
- symval,
- shrinked_insn_address,
- shrink_boundary,
- count);
- }
+ irel < irelend;
+ irel++)
+ {
+ /* Read this BFD's local symbols if we haven't done
+ so already. */
+ if (isymbuf == NULL && symtab_hdr->sh_info != 0)
+ {
+ isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+ if (isymbuf == NULL)
+ isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ symtab_hdr->sh_info, 0,
+ NULL, NULL, NULL);
+ if (isymbuf == NULL)
+ return FALSE;
+ }
+
+ /* Get the value of the symbol referred to by the reloc. */
+ if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
+ {
+ /* A local symbol. */
+ asection *sym_sec;
+
+ isym = isymbuf + ELF32_R_SYM (irel->r_info);
+ sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ symval = isym->st_value;
+ /* If the reloc is absolute, it will not have
+ a symbol or section associated with it. */
+ if (sym_sec == sec)
+ {
+ /* If there is an alignment boundary, we only need to
+ adjust addends that end up below the boundary. */
+ bfd_vma shrink_boundary = (toaddr
+ + sec->output_section->vma
+ + sec->output_offset);
+
+ symval += sym_sec->output_section->vma
+ + sym_sec->output_offset;
+
+ if (debug_relax)
+ printf ("Checking if the relocation's "
+ "addend needs corrections.\n"
+ "Address of anchor symbol: 0x%x \n"
+ "Address of relocation target: 0x%x \n"
+ "Address of relaxed insn: 0x%x \n",
+ (unsigned int) symval,
+ (unsigned int) (symval + irel->r_addend),
+ (unsigned int) shrinked_insn_address);
+
+ elf32_avr_adjust_reloc_if_spans_insn (abfd, isec, irel,
+ symval,
+ shrinked_insn_address,
+ shrink_boundary,
+ count);
+ }
- {
- if (isym->st_value > addr
- && isym->st_value <= toaddr)
- isym->st_value -= count;
-
- if (isym->st_value <= addr
- && isym->st_value + isym->st_size > addr)
- {
- /* If this assert fires then we have a symbol that ends
- part way through an instruction. Does that make
- sense? */
- BFD_ASSERT (isym->st_value + isym->st_size >= addr + count);
- isym->st_size -= count;
- }
- }
+ {
+ symvalue symval = isym->st_value;
+ symvalue symend = symval + isym->st_size;
+ if (avr_should_reduce_sym_size (symval, symend,
+ addr, toaddr, did_pad))
+ {
+ /* If this assert fires then we have a symbol that ends
+ part way through an instruction. Does that make
+ sense? */
+ BFD_ASSERT (isym->st_value + isym->st_size >= addr + count);
+ isym->st_size -= count;
+ }
+ else if (avr_should_increase_sym_size (symval, symend,
+ addr, toaddr, did_pad))
+ isym->st_size += count;
+
+ if (avr_should_move_sym (symval, addr, toaddr, did_pad))
+ isym->st_value -= count;
+ }
- || sym_hash->root.type == bfd_link_hash_defweak)
- && sym_hash->root.u.def.section == sec)
- {
- if (sym_hash->root.u.def.value > addr
- && sym_hash->root.u.def.value <= toaddr)
- sym_hash->root.u.def.value -= count;
-
- if (sym_hash->root.u.def.value <= addr
- && (sym_hash->root.u.def.value + sym_hash->size > addr))
- {
- /* If this assert fires then we have a symbol that ends
- part way through an instruction. Does that make
- sense? */
- BFD_ASSERT (sym_hash->root.u.def.value + sym_hash->size
- >= addr + count);
- sym_hash->size -= count;
- }
- }
+ || sym_hash->root.type == bfd_link_hash_defweak)
+ && sym_hash->root.u.def.section == sec)
+ {
+ symvalue symval = sym_hash->root.u.def.value;
+ symvalue symend = symval + sym_hash->size;
+
+ if (avr_should_reduce_sym_size (symval, symend,
+ addr, toaddr, did_pad))
+ {
+ /* If this assert fires then we have a symbol that ends
+ part way through an instruction. Does that make
+ sense? */
+ BFD_ASSERT (symend >= addr + count);
+ sym_hash->size -= count;
+ }
+ else if (avr_should_increase_sym_size (symval, symend,
+ addr, toaddr, did_pad))
+ sym_hash->size += count;
+
+ if (avr_should_move_sym (symval, addr, toaddr, did_pad))
+ sym_hash->root.u.def.value -= count;
+ }
- == relax_info->records.allocated)
- {
- /* Allocate more space. */
- bfd_size_type size;
-
- relax_info->records.allocated += 10;
- size = (sizeof (struct avr_property_record)
- * relax_info->records.allocated);
- relax_info->records.items
- = bfd_realloc (relax_info->records.items, size);
- }
+ == relax_info->records.allocated)
+ {
+ /* Allocate more space. */
+ bfd_size_type size;
+
+ relax_info->records.allocated += 10;
+ size = (sizeof (struct avr_property_record)
+ * relax_info->records.allocated);
+ relax_info->records.items
+ = bfd_realloc (relax_info->records.items, size);
+ }
- struct avr_relax_info *relax_info = get_avr_relax_info (sec);
- if (relax_info && relax_info->records.count > 0)
- {
- unsigned int i;
-
- qsort (relax_info->records.items,
- relax_info->records.count,
- sizeof (struct avr_property_record),
- avr_property_record_compare);
-
- /* For debug purposes, list all the descriptors. */
- for (i = 0; i < relax_info->records.count; ++i)
- {
- switch (relax_info->records.items [i].type)
- {
- case RECORD_ORG:
- break;
- case RECORD_ORG_AND_FILL:
- break;
- case RECORD_ALIGN:
- break;
- case RECORD_ALIGN_AND_FILL:
- break;
- };
- }
- }
+ struct avr_relax_info *relax_info = get_avr_relax_info (sec);
+ if (relax_info && relax_info->records.count > 0)
+ {
+ unsigned int i;
+
+ qsort (relax_info->records.items,
+ relax_info->records.count,
+ sizeof (struct avr_property_record),
+ avr_property_record_compare);
+
+ /* For debug purposes, list all the descriptors. */
+ for (i = 0; i < relax_info->records.count; ++i)
+ {
+ switch (relax_info->records.items [i].type)
+ {
+ case RECORD_ORG:
+ break;
+ case RECORD_ORG_AND_FILL:
+ break;
+ case RECORD_ALIGN:
+ break;
+ case RECORD_ALIGN_AND_FILL:
+ break;
+ };
+ }
+ }
- {
- /* A local symbol. */
- Elf_Internal_Sym *isym;
- asection *sym_sec;
-
- isym = isymbuf + ELF32_R_SYM (irel->r_info);
- sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
- symval = isym->st_value;
- /* If the reloc is absolute, it will not have
- a symbol or section associated with it. */
- if (sym_sec)
- symval += sym_sec->output_section->vma
- + sym_sec->output_offset;
- }
+ {
+ /* A local symbol. */
+ Elf_Internal_Sym *isym;
+ asection *sym_sec;
+
+ isym = isymbuf + ELF32_R_SYM (irel->r_info);
+ sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ symval = isym->st_value;
+ /* If the reloc is absolute, it will not have
+ a symbol or section associated with it. */
+ if (sym_sec)
+ symval += sym_sec->output_section->vma
+ + sym_sec->output_offset;
+ }
- contents, the section relocs, and the BFD symbol table. We
- must tell the rest of the code not to free up this
- information. It would be possible to instead create a table
- of changes which have to be made, as is done in coff-mips.c;
- that would be more work, but would require less memory when
- the linker is run. */
+ contents, the section relocs, and the BFD symbol table. We
+ must tell the rest of the code not to free up this
+ information. It would be possible to instead create a table
+ of changes which have to be made, as is done in coff-mips.c;
+ that would be more work, but would require less memory when
+ the linker is run. */
- {
- bfd_vma value = symval + irel->r_addend;
- bfd_vma dot, gap;
- int distance_short_enough = 0;
-
- /* Get the address of this instruction. */
- dot = (sec->output_section->vma
- + sec->output_offset + irel->r_offset);
-
- /* Compute the distance from this insn to the branch target. */
- gap = value - dot;
-
- /* Check if the gap falls in the range that can be accommodated
- in 13bits signed (It is 12bits when encoded, as we deal with
- word addressing). */
- if (!shrinkable && ((int) gap >= -4096 && (int) gap <= 4095))
- distance_short_enough = 1;
- /* If shrinkable, then we can check for a range of distance which
- is two bytes farther on both the directions because the call
- or jump target will be closer by two bytes after the
- relaxation. */
- else if (shrinkable && ((int) gap >= -4094 && (int) gap <= 4097))
- distance_short_enough = 1;
-
- /* Here we handle the wrap-around case. E.g. for a 16k device
- we could use a rjmp to jump from address 0x100 to 0x3d00!
- In order to make this work properly, we need to fill the
- vaiable avr_pc_wrap_around with the appropriate value.
- I.e. 0x4000 for a 16k device. */
- {
+ {
+ bfd_vma value = symval + irel->r_addend;
+ bfd_vma dot, gap;
+ int distance_short_enough = 0;
+
+ /* Get the address of this instruction. */
+ dot = (sec->output_section->vma
+ + sec->output_offset + irel->r_offset);
+
+ /* Compute the distance from this insn to the branch target. */
+ gap = value - dot;
+
+ /* The ISA manual states that addressable range is PC - 2k + 1 to
+ PC + 2k. In bytes, that would be -4094 <= PC <= 4096. The range
+ is shifted one word to the right, because pc-relative instructions
+ implicitly add one word i.e. rjmp 0 jumps to next insn, not the
+ current one.
+ Therefore, for the !shrinkable case, the range is as above.
+ If shrinkable, then the current code only deletes bytes 3 and
+ 4 of the absolute call/jmp, so the forward jump range increases
+ by 2 bytes, but the backward (negative) jump range remains
+ the same. */
+
+
+ /* Check if the gap falls in the range that can be accommodated
+ in 13bits signed (It is 12bits when encoded, as we deal with
+ word addressing). */
+ if (!shrinkable && ((int) gap >= -4094 && (int) gap <= 4096))
+ distance_short_enough = 1;
+ /* If shrinkable, then we can check for a range of distance which
+ is two bytes farther on the positive direction because the call
+ or jump target will be closer by two bytes after the
+ relaxation. */
+ else if (shrinkable && ((int) gap >= -4094 && (int) gap <= 4098))
+ distance_short_enough = 1;
+
+ /* Here we handle the wrap-around case. E.g. for a 16k device
+ we could use a rjmp to jump from address 0x100 to 0x3d00!
+ In order to make this work properly, we need to fill the
+ vaiable avr_pc_wrap_around with the appropriate value.
+ I.e. 0x4000 for a 16k device. */
+ {
- }
-
- if (distance_short_enough)
- {
- unsigned char code_msb;
- unsigned char code_lsb;
-
- if (debug_relax)
- printf ("shrinking jump/call instruction at address 0x%x"
- " in section %s\n\n",
- (int) dot, sec->name);
-
- /* Note that we've changed the relocs, section contents,
- etc. */
- elf_section_data (sec)->relocs = internal_relocs;
- elf_section_data (sec)->this_hdr.contents = contents;
- symtab_hdr->contents = (unsigned char *) isymbuf;
-
- /* Get the instruction code for relaxing. */
- code_lsb = bfd_get_8 (abfd, contents + irel->r_offset);
- code_msb = bfd_get_8 (abfd, contents + irel->r_offset + 1);
-
- /* Mask out the relocation bits. */
- code_msb &= 0x94;
- code_lsb &= 0x0E;
- if (code_msb == 0x94 && code_lsb == 0x0E)
- {
- /* we are changing call -> rcall . */
- bfd_put_8 (abfd, 0x00, contents + irel->r_offset);
- bfd_put_8 (abfd, 0xD0, contents + irel->r_offset + 1);
- }
- else if (code_msb == 0x94 && code_lsb == 0x0C)
- {
- /* we are changeing jump -> rjmp. */
- bfd_put_8 (abfd, 0x00, contents + irel->r_offset);
- bfd_put_8 (abfd, 0xC0, contents + irel->r_offset + 1);
- }
- else
- abort ();
-
- /* Fix the relocation's type. */
- irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
- R_AVR_13_PCREL);
-
- /* We should not modify the ordering if 'shrinkable' is
- FALSE. */
- if (!shrinkable)
- {
- /* Let's insert a nop. */
- bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 2);
- bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 3);
- }
- else
- {
- /* Delete two bytes of data. */
- if (!elf32_avr_relax_delete_bytes (abfd, sec,
- irel->r_offset + 2, 2,
- TRUE))
- goto error_return;
-
- /* That will change things, so, we should relax again.
- Note that this is not required, and it may be slow. */
- *again = TRUE;
- }
- }
- }
+ }
+
+ if (distance_short_enough)
+ {
+ unsigned char code_msb;
+ unsigned char code_lsb;
+
+ if (debug_relax)
+ printf ("shrinking jump/call instruction at address 0x%x"
+ " in section %s\n\n",
+ (int) dot, sec->name);
+
+ /* Note that we've changed the relocs, section contents,
+ etc. */
+ elf_section_data (sec)->relocs = internal_relocs;
+ elf_section_data (sec)->this_hdr.contents = contents;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
+
+ /* Get the instruction code for relaxing. */
+ code_lsb = bfd_get_8 (abfd, contents + irel->r_offset);
+ code_msb = bfd_get_8 (abfd, contents + irel->r_offset + 1);
+
+ /* Mask out the relocation bits. */
+ code_msb &= 0x94;
+ code_lsb &= 0x0E;
+ if (code_msb == 0x94 && code_lsb == 0x0E)
+ {
+ /* we are changing call -> rcall . */
+ bfd_put_8 (abfd, 0x00, contents + irel->r_offset);
+ bfd_put_8 (abfd, 0xD0, contents + irel->r_offset + 1);
+ }
+ else if (code_msb == 0x94 && code_lsb == 0x0C)
+ {
+ /* we are changeing jump -> rjmp. */
+ bfd_put_8 (abfd, 0x00, contents + irel->r_offset);
+ bfd_put_8 (abfd, 0xC0, contents + irel->r_offset + 1);
+ }
+ else
+ abort ();
+
+ /* Fix the relocation's type. */
+ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
+ R_AVR_13_PCREL);
+
+ /* We should not modify the ordering if 'shrinkable' is
+ FALSE. */
+ if (!shrinkable)
+ {
+ /* Let's insert a nop. */
+ bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 2);
+ bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 3);
+ }
+ else
+ {
+ /* Delete two bytes of data. */
+ if (!elf32_avr_relax_delete_bytes (abfd, sec,
+ irel->r_offset + 2, 2,
+ TRUE))
+ goto error_return;
+
+ /* That will change things, so, we should relax again.
+ Note that this is not required, and it may be slow. */
+ *again = TRUE;
+ }
+ }
+ }
- default:
- {
- unsigned char code_msb;
- unsigned char code_lsb;
- bfd_vma dot;
-
- code_msb = bfd_get_8 (abfd, contents + irel->r_offset + 1);
- code_lsb = bfd_get_8 (abfd, contents + irel->r_offset + 0);
-
- /* Get the address of this instruction. */
- dot = (sec->output_section->vma
- + sec->output_offset + irel->r_offset);
-
- /* Here we look for rcall/ret or call/ret sequences that could be
- safely replaced by rjmp/ret or jmp/ret. */
- if (((code_msb & 0xf0) == 0xd0)
- && avr_replace_call_ret_sequences)
- {
- /* This insn is a rcall. */
- unsigned char next_insn_msb = 0;
- unsigned char next_insn_lsb = 0;
-
- if (irel->r_offset + 3 < sec->size)
- {
- next_insn_msb =
+ default:
+ {
+ unsigned char code_msb;
+ unsigned char code_lsb;
+ bfd_vma dot;
+
+ code_msb = bfd_get_8 (abfd, contents + irel->r_offset + 1);
+ code_lsb = bfd_get_8 (abfd, contents + irel->r_offset + 0);
+
+ /* Get the address of this instruction. */
+ dot = (sec->output_section->vma
+ + sec->output_offset + irel->r_offset);
+
+ /* Here we look for rcall/ret or call/ret sequences that could be
+ safely replaced by rjmp/ret or jmp/ret. */
+ if (((code_msb & 0xf0) == 0xd0)
+ && avr_replace_call_ret_sequences)
+ {
+ /* This insn is a rcall. */
+ unsigned char next_insn_msb = 0;
+ unsigned char next_insn_lsb = 0;
+
+ if (irel->r_offset + 3 < sec->size)
+ {
+ next_insn_msb =
- {
- /* The next insn is a ret. We now convert the rcall insn
- into a rjmp instruction. */
- code_msb &= 0xef;
- bfd_put_8 (abfd, code_msb, contents + irel->r_offset + 1);
- if (debug_relax)
- printf ("converted rcall/ret sequence at address 0x%x"
- " into rjmp/ret sequence. Section is %s\n\n",
- (int) dot, sec->name);
- *again = TRUE;
- break;
- }
- }
- else if ((0x94 == (code_msb & 0xfe))
+ {
+ /* The next insn is a ret. We now convert the rcall insn
+ into a rjmp instruction. */
+ code_msb &= 0xef;
+ bfd_put_8 (abfd, code_msb, contents + irel->r_offset + 1);
+ if (debug_relax)
+ printf ("converted rcall/ret sequence at address 0x%x"
+ " into rjmp/ret sequence. Section is %s\n\n",
+ (int) dot, sec->name);
+ *again = TRUE;
+ break;
+ }
+ }
+ else if ((0x94 == (code_msb & 0xfe))
- }
-
- if ((0x95 == next_insn_msb) && (0x08 == next_insn_lsb))
- {
- /* The next insn is a ret. We now convert the call insn
- into a jmp instruction. */
-
- code_lsb &= 0xfd;
- bfd_put_8 (abfd, code_lsb, contents + irel->r_offset);
- if (debug_relax)
- printf ("converted call/ret sequence at address 0x%x"
- " into jmp/ret sequence. Section is %s\n\n",
- (int) dot, sec->name);
- *again = TRUE;
- break;
- }
- }
- else if ((0xc0 == (code_msb & 0xf0))
- || ((0x94 == (code_msb & 0xfe))
- && (0x0c == (code_lsb & 0x0e))))
- {
- /* This insn is a rjmp or a jmp. */
- unsigned char next_insn_msb = 0;
- unsigned char next_insn_lsb = 0;
- int insn_size;
-
- if (0xc0 == (code_msb & 0xf0))
- insn_size = 2; /* rjmp insn */
- else
- insn_size = 4; /* jmp insn */
-
- if (irel->r_offset + insn_size + 1 < sec->size)
- {
- next_insn_msb =
+ }
+
+ if ((0x95 == next_insn_msb) && (0x08 == next_insn_lsb))
+ {
+ /* The next insn is a ret. We now convert the call insn
+ into a jmp instruction. */
+
+ code_lsb &= 0xfd;
+ bfd_put_8 (abfd, code_lsb, contents + irel->r_offset);
+ if (debug_relax)
+ printf ("converted call/ret sequence at address 0x%x"
+ " into jmp/ret sequence. Section is %s\n\n",
+ (int) dot, sec->name);
+ *again = TRUE;
+ break;
+ }
+ }
+ else if ((0xc0 == (code_msb & 0xf0))
+ || ((0x94 == (code_msb & 0xfe))
+ && (0x0c == (code_lsb & 0x0e))))
+ {
+ /* This insn is a rjmp or a jmp. */
+ unsigned char next_insn_msb = 0;
+ unsigned char next_insn_lsb = 0;
+ int insn_size;
+
+ if (0xc0 == (code_msb & 0xf0))
+ insn_size = 2; /* rjmp insn */
+ else
+ insn_size = 4; /* jmp insn */
+
+ if (irel->r_offset + insn_size + 1 < sec->size)
+ {
+ next_insn_msb =
- address_of_ret = dot + insn_size;
-
- if (debug_relax && (insn_size == 2))
- printf ("found rjmp / ret sequence at address 0x%x\n",
- (int) dot);
- if (debug_relax && (insn_size == 4))
- printf ("found jmp / ret sequence at address 0x%x\n",
- (int) dot);
-
- /* We have to make sure that there is a preceding insn. */
- if (irel->r_offset >= 2)
- {
- unsigned char preceding_msb;
- unsigned char preceding_lsb;
-
- preceding_msb =
+ if ((0x95 == next_insn_msb) && (0x08 == next_insn_lsb))
+ {
+ /* The next insn is a ret. We possibly could delete
+ this ret. First we need to check for preceding
+ sbis/sbic/sbrs or cpse "skip" instructions. */
+
+ int there_is_preceding_non_skip_insn = 1;
+ bfd_vma address_of_ret;
+
+ address_of_ret = dot + insn_size;
+
+ if (debug_relax && (insn_size == 2))
+ printf ("found rjmp / ret sequence at address 0x%x\n",
+ (int) dot);
+ if (debug_relax && (insn_size == 4))
+ printf ("found jmp / ret sequence at address 0x%x\n",
+ (int) dot);
+
+ /* We have to make sure that there is a preceding insn. */
+ if (irel->r_offset >= 2)
+ {
+ unsigned char preceding_msb;
+ unsigned char preceding_lsb;
+
+ preceding_msb =
- there_is_preceding_non_skip_insn = 0;
-
- /* cpse */
- if (0x10 == (preceding_msb & 0xfc))
- there_is_preceding_non_skip_insn = 0;
-
- if (there_is_preceding_non_skip_insn == 0)
- if (debug_relax)
- printf ("preceding skip insn prevents deletion of"
- " ret insn at Addy 0x%x in section %s\n",
- (int) dot + 2, sec->name);
- }
- else
- {
- /* There is no previous instruction. */
- there_is_preceding_non_skip_insn = 0;
- }
-
- if (there_is_preceding_non_skip_insn)
- {
- /* We now only have to make sure that there is no
- local label defined at the address of the ret
- instruction and that there is no local relocation
- in this section pointing to the ret. */
-
- int deleting_ret_is_safe = 1;
- unsigned int section_offset_of_ret_insn =
+ there_is_preceding_non_skip_insn = 0;
+
+ /* cpse */
+ if (0x10 == (preceding_msb & 0xfc))
+ there_is_preceding_non_skip_insn = 0;
+
+ if (there_is_preceding_non_skip_insn == 0)
+ if (debug_relax)
+ printf ("preceding skip insn prevents deletion of"
+ " ret insn at Addy 0x%x in section %s\n",
+ (int) dot + 2, sec->name);
+ }
+ else
+ {
+ /* There is no previous instruction. */
+ there_is_preceding_non_skip_insn = 0;
+ }
+
+ if (there_is_preceding_non_skip_insn)
+ {
+ /* We now only have to make sure that there is no
+ local label defined at the address of the ret
+ instruction and that there is no local relocation
+ in this section pointing to the ret. */
+
+ int deleting_ret_is_safe = 1;
+ unsigned int section_offset_of_ret_insn =
- {
- unsigned int i;
-
- for (i = 0; i < relax_info->records.count; ++i)
- {
- switch (relax_info->records.items [i].type)
- {
- case RECORD_ORG:
- case RECORD_ORG_AND_FILL:
- break;
- case RECORD_ALIGN:
- case RECORD_ALIGN_AND_FILL:
- {
- struct avr_property_record *record;
- unsigned long bytes_to_align;
- int count = 0;
-
- /* Look for alignment directives that have had enough
- bytes deleted before them, such that the directive
- can be moved backwards and still maintain the
- required alignment. */
- record = &relax_info->records.items [i];
- bytes_to_align
- = (unsigned long) (1 << record->data.align.bytes);
- while (record->data.align.preceding_deleted >=
- bytes_to_align)
- {
- record->data.align.preceding_deleted
- -= bytes_to_align;
- count += bytes_to_align;
- }
-
- if (count > 0)
- {
- bfd_vma addr = record->offset;
-
- /* We can delete COUNT bytes and this alignment
- directive will still be correctly aligned.
- First move the alignment directive, then delete
- the bytes. */
- record->offset -= count;
- elf32_avr_relax_delete_bytes (abfd, sec,
- addr - count,
- count, FALSE);
- *again = TRUE;
- }
- }
- break;
- }
- }
- }
+ {
+ unsigned int i;
+
+ for (i = 0; i < relax_info->records.count; ++i)
+ {
+ switch (relax_info->records.items [i].type)
+ {
+ case RECORD_ORG:
+ case RECORD_ORG_AND_FILL:
+ break;
+ case RECORD_ALIGN:
+ case RECORD_ALIGN_AND_FILL:
+ {
+ struct avr_property_record *record;
+ unsigned long bytes_to_align;
+ int count = 0;
+
+ /* Look for alignment directives that have had enough
+ bytes deleted before them, such that the directive
+ can be moved backwards and still maintain the
+ required alignment. */
+ record = &relax_info->records.items [i];
+ bytes_to_align
+ = (unsigned long) (1 << record->data.align.bytes);
+ while (record->data.align.preceding_deleted >=
+ bytes_to_align)
+ {
+ record->data.align.preceding_deleted
+ -= bytes_to_align;
+ count += bytes_to_align;
+ }
+
+ if (count > 0)
+ {
+ bfd_vma addr = record->offset;
+
+ /* We can delete COUNT bytes and this alignment
+ directive will still be correctly aligned.
+ First move the alignment directive, then delete
+ the bytes. */
+ record->offset -= count;
+ elf32_avr_relax_delete_bytes (abfd, sec,
+ addr - count,
+ count, FALSE);
+ *again = TRUE;
+ }
+ }
+ break;
+ }
+ }
+ }
- {
- asection *isec;
-
- if (isym->st_shndx == SHN_UNDEF)
- isec = bfd_und_section_ptr;
- else if (isym->st_shndx == SHN_ABS)
- isec = bfd_abs_section_ptr;
- else if (isym->st_shndx == SHN_COMMON)
- isec = bfd_com_section_ptr;
- else
- isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
-
- *secpp = isec;
- }
+ {
+ asection *isec;
+
+ if (isym->st_shndx == SHN_UNDEF)
+ isec = bfd_und_section_ptr;
+ else if (isym->st_shndx == SHN_ABS)
+ isec = bfd_abs_section_ptr;
+ else if (isym->st_shndx == SHN_COMMON)
+ isec = bfd_com_section_ptr;
+ else
+ isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
+
+ *secpp = isec;
+ }
- input_bfd != NULL;
- input_bfd = input_bfd->link.next, bfd_indx++)
- {
- Elf_Internal_Shdr *symtab_hdr;
- asection *section;
- Elf_Internal_Sym *local_syms;
-
- /* We'll need the symbol table in a second. */
- symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
- if (symtab_hdr->sh_info == 0)
- continue;
-
- local_syms = htab->all_local_syms[bfd_indx];
-
- /* Walk over each section attached to the input bfd. */
- for (section = input_bfd->sections;
- section != NULL;
- section = section->next)
- {
- Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
-
- /* If there aren't any relocs, then there's nothing more
- to do. */
- if ((section->flags & SEC_RELOC) == 0
- || section->reloc_count == 0)
- continue;
-
- /* If this section is a link-once section that will be
- discarded, then don't create any stubs. */
- if (section->output_section == NULL
- || section->output_section->owner != output_bfd)
- continue;
-
- /* Get the relocs. */
- internal_relocs
- = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
- info->keep_memory);
- if (internal_relocs == NULL)
- goto error_ret_free_local;
-
- /* Now examine each relocation. */
- irela = internal_relocs;
- irelaend = irela + section->reloc_count;
- for (; irela < irelaend; irela++)
- {
- unsigned int r_type, r_indx;
- struct elf32_avr_stub_hash_entry *hsh;
- asection *sym_sec;
- bfd_vma sym_value;
- bfd_vma destination;
- struct elf_link_hash_entry *hh;
- char *stub_name;
-
- r_type = ELF32_R_TYPE (irela->r_info);
- r_indx = ELF32_R_SYM (irela->r_info);
-
- /* Only look for 16 bit GS relocs. No other reloc will need a
- stub. */
- if (!((r_type == R_AVR_16_PM)
- || (r_type == R_AVR_LO8_LDI_GS)
- || (r_type == R_AVR_HI8_LDI_GS)))
- continue;
-
- /* Now determine the call target, its name, value,
- section. */
- sym_sec = NULL;
- sym_value = 0;
- destination = 0;
- hh = NULL;
- if (r_indx < symtab_hdr->sh_info)
- {
- /* It's a local symbol. */
- Elf_Internal_Sym *sym;
- Elf_Internal_Shdr *hdr;
+ input_bfd != NULL;
+ input_bfd = input_bfd->link.next, bfd_indx++)
+ {
+ Elf_Internal_Shdr *symtab_hdr;
+ asection *section;
+ Elf_Internal_Sym *local_syms;
+
+ /* We'll need the symbol table in a second. */
+ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+ if (symtab_hdr->sh_info == 0)
+ continue;
+
+ local_syms = htab->all_local_syms[bfd_indx];
+
+ /* Walk over each section attached to the input bfd. */
+ for (section = input_bfd->sections;
+ section != NULL;
+ section = section->next)
+ {
+ Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
+
+ /* If there aren't any relocs, then there's nothing more
+ to do. */
+ if ((section->flags & SEC_RELOC) == 0
+ || section->reloc_count == 0)
+ continue;
+
+ /* If this section is a link-once section that will be
+ discarded, then don't create any stubs. */
+ if (section->output_section == NULL
+ || section->output_section->owner != output_bfd)
+ continue;
+
+ /* Get the relocs. */
+ internal_relocs
+ = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
+ info->keep_memory);
+ if (internal_relocs == NULL)
+ goto error_ret_free_local;
+
+ /* Now examine each relocation. */
+ irela = internal_relocs;
+ irelaend = irela + section->reloc_count;
+ for (; irela < irelaend; irela++)
+ {
+ unsigned int r_type, r_indx;
+ struct elf32_avr_stub_hash_entry *hsh;
+ asection *sym_sec;
+ bfd_vma sym_value;
+ bfd_vma destination;
+ struct elf_link_hash_entry *hh;
+ char *stub_name;
+
+ r_type = ELF32_R_TYPE (irela->r_info);
+ r_indx = ELF32_R_SYM (irela->r_info);
+
+ /* Only look for 16 bit GS relocs. No other reloc will need a
+ stub. */
+ if (!((r_type == R_AVR_16_PM)
+ || (r_type == R_AVR_LO8_LDI_GS)
+ || (r_type == R_AVR_HI8_LDI_GS)))
+ continue;
+
+ /* Now determine the call target, its name, value,
+ section. */
+ sym_sec = NULL;
+ sym_value = 0;
+ destination = 0;
+ hh = NULL;
+ if (r_indx < symtab_hdr->sh_info)
+ {
+ /* It's a local symbol. */
+ Elf_Internal_Sym *sym;
+ Elf_Internal_Shdr *hdr;
- }
- else
- {
- /* It's an external symbol. */
- int e_indx;
-
- e_indx = r_indx - symtab_hdr->sh_info;
- hh = elf_sym_hashes (input_bfd)[e_indx];
-
- while (hh->root.type == bfd_link_hash_indirect
- || hh->root.type == bfd_link_hash_warning)
- hh = (struct elf_link_hash_entry *)
- (hh->root.u.i.link);
-
- if (hh->root.type == bfd_link_hash_defined
- || hh->root.type == bfd_link_hash_defweak)
- {
- sym_sec = hh->root.u.def.section;
- sym_value = hh->root.u.def.value;
- if (sym_sec->output_section != NULL)
- destination = (sym_value + irela->r_addend
- + sym_sec->output_offset
- + sym_sec->output_section->vma);
- }
- else if (hh->root.type == bfd_link_hash_undefweak)
- {
- if (! bfd_link_pic (info))
- continue;
- }
- else if (hh->root.type == bfd_link_hash_undefined)
- {
- if (! (info->unresolved_syms_in_objects == RM_IGNORE
- && (ELF_ST_VISIBILITY (hh->other)
- == STV_DEFAULT)))
- continue;
- }
- else
- {
- bfd_set_error (bfd_error_bad_value);
-
- error_ret_free_internal:
- if (elf_section_data (section)->relocs == NULL)
- free (internal_relocs);
- goto error_ret_free_local;
- }
- }
-
- if (! avr_stub_is_required_for_16_bit_reloc
+ }
+ else
+ {
+ /* It's an external symbol. */
+ int e_indx;
+
+ e_indx = r_indx - symtab_hdr->sh_info;
+ hh = elf_sym_hashes (input_bfd)[e_indx];
+
+ while (hh->root.type == bfd_link_hash_indirect
+ || hh->root.type == bfd_link_hash_warning)
+ hh = (struct elf_link_hash_entry *)
+ (hh->root.u.i.link);
+
+ if (hh->root.type == bfd_link_hash_defined
+ || hh->root.type == bfd_link_hash_defweak)
+ {
+ sym_sec = hh->root.u.def.section;
+ sym_value = hh->root.u.def.value;
+ if (sym_sec->output_section != NULL)
+ destination = (sym_value + irela->r_addend
+ + sym_sec->output_offset
+ + sym_sec->output_section->vma);
+ }
+ else if (hh->root.type == bfd_link_hash_undefweak)
+ {
+ if (! bfd_link_pic (info))
+ continue;
+ }
+ else if (hh->root.type == bfd_link_hash_undefined)
+ {
+ if (! (info->unresolved_syms_in_objects == RM_IGNORE
+ && (ELF_ST_VISIBILITY (hh->other)
+ == STV_DEFAULT)))
+ continue;
+ }
+ else
+ {
+ bfd_set_error (bfd_error_bad_value);
+
+ error_ret_free_internal:
+ if (elf_section_data (section)->relocs == NULL)
+ free (internal_relocs);
+ goto error_ret_free_local;
+ }
+ }
+
+ if (! avr_stub_is_required_for_16_bit_reloc
- }
-
- /* Get the name of this stub. */
- stub_name = avr_stub_name (sym_sec, sym_value, irela);
-
- if (!stub_name)
- goto error_ret_free_internal;
-
-
- hsh = avr_stub_hash_lookup (&htab->bstab,
- stub_name,
- FALSE, FALSE);
- if (hsh != NULL)
- {
- /* The proper stub has already been created. Mark it
- to be used and write the possibly changed destination
- value. */
- hsh->is_actually_needed = TRUE;
- hsh->target_value = destination;
- free (stub_name);
- continue;
- }
-
- hsh = avr_add_stub (stub_name, htab);
- if (hsh == NULL)
- {
- free (stub_name);
- goto error_ret_free_internal;
- }
-
- hsh->is_actually_needed = TRUE;
- hsh->target_value = destination;
-
- if (debug_stubs)
- printf ("Adding stub with destination 0x%x to the"
- " hash table.\n", (unsigned int) destination);
- if (debug_stubs)
- printf ("(Pre-Alloc run: %i)\n", is_prealloc_run);
-
- stub_changed = TRUE;
- }
-
- /* We're done with the internal relocs, free them. */
- if (elf_section_data (section)->relocs == NULL)
- free (internal_relocs);
- }
- }
+ }
+
+ /* Get the name of this stub. */
+ stub_name = avr_stub_name (sym_sec, sym_value, irela);
+
+ if (!stub_name)
+ goto error_ret_free_internal;
+
+
+ hsh = avr_stub_hash_lookup (&htab->bstab,
+ stub_name,
+ FALSE, FALSE);
+ if (hsh != NULL)
+ {
+ /* The proper stub has already been created. Mark it
+ to be used and write the possibly changed destination
+ value. */
+ hsh->is_actually_needed = TRUE;
+ hsh->target_value = destination;
+ free (stub_name);
+ continue;
+ }
+
+ hsh = avr_add_stub (stub_name, htab);
+ if (hsh == NULL)
+ {
+ free (stub_name);
+ goto error_ret_free_internal;
+ }
+
+ hsh->is_actually_needed = TRUE;
+ hsh->target_value = destination;
+
+ if (debug_stubs)
+ printf ("Adding stub with destination 0x%x to the"
+ " hash table.\n", (unsigned int) destination);
+ if (debug_stubs)
+ printf ("(Pre-Alloc run: %i)\n", is_prealloc_run);
+
+ stub_changed = TRUE;
+ }
+
+ /* We're done with the internal relocs, free them. */
+ if (elf_section_data (section)->relocs == NULL)
+ free (internal_relocs);
+ }
+ }
- {
- /* Try to find section and offset from address. */
- if (fs_data.section != NULL
- && !avr_is_section_for_address (abfd, fs_data.section,
- address))
- fs_data.section = NULL;
-
- if (fs_data.section == NULL)
- {
- fs_data.address = address;
- bfd_map_over_sections (abfd, avr_find_section_for_address,
- &fs_data);
- }
-
- if (fs_data.section == NULL)
- {
- fprintf (stderr, "Failed to find matching section.\n");
- goto load_failed;
- }
-
- r_list->records [i].section = fs_data.section;
- r_list->records [i].offset
- = address - bfd_get_section_vma (abfd, fs_data.section);
- }
+ {
+ /* Try to find section and offset from address. */
+ if (fs_data.section != NULL
+ && !avr_is_section_for_address (fs_data.section, address))
+ fs_data.section = NULL;
+
+ if (fs_data.section == NULL)
+ {
+ fs_data.address = address;
+ bfd_map_over_sections (abfd, avr_find_section_for_address,
+ &fs_data);
+ }
+
+ if (fs_data.section == NULL)
+ {
+ fprintf (stderr, "Failed to find matching section.\n");
+ goto load_failed;
+ }
+
+ r_list->records [i].section = fs_data.section;
+ r_list->records [i].offset
+ = address - bfd_section_vma (fs_data.section);
+ }
- {
- case RECORD_ORG:
- /* Nothing else to load. */
- break;
- case RECORD_ORG_AND_FILL:
- /* Just a 4-byte fill to load. */
- if (size < 4)
- goto load_failed;
- r_list->records [i].data.org.fill = *((uint32_t *) ptr);
- ptr += 4;
- size -= 4;
- break;
- case RECORD_ALIGN:
- /* Just a 4-byte alignment to load. */
- if (size < 4)
- goto load_failed;
- r_list->records [i].data.align.bytes = *((uint32_t *) ptr);
- ptr += 4;
- size -= 4;
- /* Just initialise PRECEDING_DELETED field, this field is
- used during linker relaxation. */
- r_list->records [i].data.align.preceding_deleted = 0;
- break;
- case RECORD_ALIGN_AND_FILL:
- /* A 4-byte alignment, and a 4-byte fill to load. */
- if (size < 8)
- goto load_failed;
- r_list->records [i].data.align.bytes = *((uint32_t *) ptr);
- ptr += 4;
- r_list->records [i].data.align.fill = *((uint32_t *) ptr);
- ptr += 4;
- size -= 8;
- /* Just initialise PRECEDING_DELETED field, this field is
- used during linker relaxation. */
- r_list->records [i].data.align.preceding_deleted = 0;
- break;
- default:
- goto load_failed;
- }
+ {
+ case RECORD_ORG:
+ /* Nothing else to load. */
+ break;
+ case RECORD_ORG_AND_FILL:
+ /* Just a 4-byte fill to load. */
+ if (size < 4)
+ goto load_failed;
+ r_list->records [i].data.org.fill = *((uint32_t *) ptr);
+ ptr += 4;
+ size -= 4;
+ break;
+ case RECORD_ALIGN:
+ /* Just a 4-byte alignment to load. */
+ if (size < 4)
+ goto load_failed;
+ r_list->records [i].data.align.bytes = *((uint32_t *) ptr);
+ ptr += 4;
+ size -= 4;
+ /* Just initialise PRECEDING_DELETED field, this field is
+ used during linker relaxation. */
+ r_list->records [i].data.align.preceding_deleted = 0;
+ break;
+ case RECORD_ALIGN_AND_FILL:
+ /* A 4-byte alignment, and a 4-byte fill to load. */
+ if (size < 8)
+ goto load_failed;
+ r_list->records [i].data.align.bytes = *((uint32_t *) ptr);
+ ptr += 4;
+ r_list->records [i].data.align.fill = *((uint32_t *) ptr);
+ ptr += 4;
+ size -= 8;
+ /* Just initialise PRECEDING_DELETED field, this field is
+ used during linker relaxation. */
+ r_list->records [i].data.align.preceding_deleted = 0;
+ break;
+ default:
+ goto load_failed;
+ }