===================================================================
RCS file: /cvs/src/src/bfd/elf32-avr.c,v
retrieving revision 1.51
retrieving revision 1.51.2.1
diff -u -r1.51 -r1.51.2.1
--- bfd/elf32-avr.c	2011/06/02 13:43:14	1.51
+++ bfd/elf32-avr.c	2012/02/01 17:07:37	1.51.2.1
@@ -1503,11 +1503,18 @@
        bfd_vma symval;
        bfd_vma shrinked_insn_address;
 
+       if (isec->reloc_count == 0)
+	 continue;
+
        shrinked_insn_address = (sec->output_section->vma
                                 + sec->output_offset + addr - count);
 
-       irelend = elf_section_data (isec)->relocs + isec->reloc_count;
-       for (irel = elf_section_data (isec)->relocs;
+       irel = elf_section_data (isec)->relocs;
+       /* PR 12161: Read in the relocs for this section if necessary.  */
+       if (irel == NULL)
+	 irel = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, FALSE);
+
+       for (irelend = irel + isec->reloc_count;
             irel < irelend;
             irel++)
          {
@@ -1564,6 +1571,9 @@
 	   /* else...Reference symbol is extern.  No need for adjusting
 	      the addend.  */
 	 }
+
+       if (elf_section_data (isec)->relocs == NULL)
+	 free (irelend - isec->reloc_count);
      }
   }
 
