View | Details | Raw Unified | Return to bug 13410
Collapse All | Expand All

(-)bfd/elf32-avr.c (-9 / +23 lines)
Lines 1659-1664 elf32_avr_relax_section (bfd *abfd, Link Here
1659
  Elf_Internal_Sym *isymbuf = NULL;
1659
  Elf_Internal_Sym *isymbuf = NULL;
1660
  struct elf32_avr_link_hash_table *htab;
1660
  struct elf32_avr_link_hash_table *htab;
1661
1661
1662
  /* If 'shrinkable' is FALSE, do not shrink by deleting bytes while
1663
     relaxing. Such shrinking can cause issues for the sections such 
1664
     as .vectors and .jumptables. Instead the unused bytes should be 
1665
     filled with nop instructions */
1666
  bfd_boolean shrinkable = TRUE;
1667
1668
  if (!strcmp (sec->name,".vectors")
1669
      || !strcmp (sec->name,".jumptables"))
1670
    shrinkable = FALSE;
1671
1662
  if (link_info->relocatable)
1672
  if (link_info->relocatable)
1663
    (*link_info->callbacks->einfo)
1673
    (*link_info->callbacks->einfo)
1664
      (_("%P%F: --relax and -r may not be used together\n"));
1674
      (_("%P%F: --relax and -r may not be used together\n"));
Lines 1815-1824 elf32_avr_relax_section (bfd *abfd, Link Here
1815
            /* Compute the distance from this insn to the branch target.  */
1825
            /* Compute the distance from this insn to the branch target.  */
1816
            gap = value - dot;
1826
            gap = value - dot;
1817
1827
1818
            /* If the distance is within -4094..+4098 inclusive, then we can
1828
            /* Check if the gap falls in the range that can be accommodated
1819
               relax this jump/call.  +4098 because the call/jump target
1829
               in 13bits signed (It is 12bits when encoded, as we deal with
1820
               will be closer after the relaxation.  */
1830
               word addressing). */
1821
            if ((int) gap >= -4094 && (int) gap <= 4098)
1831
            if (!shrinkable && ((int) gap >= -4096 && (int) gap <= 4095))
1832
              distance_short_enough = 1;
1833
            /* If shrinkable, then we can check for a range of distance which
1834
               is two bytes farther on both the directions because the call
1835
               or jump target will be closer by two bytes after the 
1836
               relaxation. */
1837
            else if (shrinkable && ((int) gap >= -4094 && (int) gap <= 4097))
1822
              distance_short_enough = 1;
1838
              distance_short_enough = 1;
1823
1839
1824
            /* Here we handle the wrap-around case.  E.g. for a 16k device
1840
            /* Here we handle the wrap-around case.  E.g. for a 16k device
Lines 1892-1902 elf32_avr_relax_section (bfd *abfd, Link Here
1892
                irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1908
                irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1893
                                             R_AVR_13_PCREL);
1909
                                             R_AVR_13_PCREL);
1894
1910
1895
                /* Check for the vector section. There we don't want to
1911
                /* We should not modify the ordering if 'shrinkable' is
1896
                   modify the ordering!  */
1912
                   FALSE */ 
1897
1913
                if (!shrinkable)
1898
                if (!strcmp (sec->name,".vectors")
1899
                    || !strcmp (sec->name,".jumptables"))
1900
                  {
1914
                  {
1901
                    /* Let's insert a nop.  */
1915
                    /* Let's insert a nop.  */
1902
                    bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 2);
1916
                    bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 2);

Return to bug 13410