Index: src/bfd/peXXigen.c
===================================================================
--- src.orig/bfd/peXXigen.c	2010-09-14 22:23:20.000000000 +0200
+++ src/bfd/peXXigen.c	2010-09-16 13:17:12.033445400 +0200
@@ -2373,6 +2373,45 @@ _bfd_XXi_final_link_postscript (bfd * ab
 	  result = FALSE;
 	}
     }
+  else
+    {
+      h1 = coff_link_hash_lookup (coff_hash_table (info),
+      				  "__IAT_start__", FALSE, FALSE, TRUE);
+      if (h1 != NULL
+	  && h1->root.u.def.section != NULL
+	  && h1->root.u.def.section->output_section != NULL)
+	{
+	  bfd_vma iat_va;
+
+	  iat_va =
+	    (h1->root.u.def.value
+	     + h1->root.u.def.section->output_section->vma
+	     + h1->root.u.def.section->output_offset);
+
+	  h1 = coff_link_hash_lookup (coff_hash_table (info),
+				      "__IAT_end__", FALSE, FALSE, TRUE);
+	  if (h1 != NULL
+	      && h1->root.u.def.section != NULL
+	      && h1->root.u.def.section->output_section != NULL)
+	    {
+	      pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE].Size =
+		((h1->root.u.def.value
+		  + h1->root.u.def.section->output_section->vma
+		  + h1->root.u.def.section->output_offset)
+		 - iat_va);
+	      if (pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE].Size != 0)
+	        pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE].VirtualAddress =
+		  iat_va - pe_data (abfd)->pe_opthdr.ImageBase;
+	    }
+	  else
+	    {
+	      _bfd_error_handler
+		(_("%B: unable to fill in DataDictionary[PE_IMPORT_ADDRESS_TABLE(12)]"
+		   " because .idata$6 is missing"), abfd);
+	      result = FALSE;
+	    }
+        }
+    }
 
   h1 = coff_link_hash_lookup (coff_hash_table (info),
 			      "__tls_used", FALSE, FALSE, TRUE);
Index: src/ld/emultempl/pe.em
===================================================================
--- src.orig/ld/emultempl/pe.em	2010-07-10 09:23:48.000000000 +0200
+++ src/ld/emultempl/pe.em	2010-09-16 10:51:49.586549900 +0200
@@ -1939,6 +1939,9 @@ gld_${EMULATION_NAME}_place_orphan (asec
 	  { ".text",
 	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
 	    0, 0, 0, 0 },
+	  { ".idata",
+	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
+	    0, 0, 0, 0 },
 	  { ".rdata",
 	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
 	    0, 0, 0, 0 },
@@ -1952,6 +1955,7 @@ gld_${EMULATION_NAME}_place_orphan (asec
       enum orphan_save_index
 	{
 	  orphan_text = 0,
+	  orphan_idata,
 	  orphan_rodata,
 	  orphan_data,
 	  orphan_bss
@@ -1985,7 +1989,12 @@ gld_${EMULATION_NAME}_place_orphan (asec
       else if ((s->flags & SEC_READONLY) == 0)
 	place = &hold[orphan_data];
       else if ((s->flags & SEC_CODE) == 0)
-	place = &hold[orphan_rodata];
+        {
+          if (! strncmp (secname, ".idata\$", 7))
+            place = &hold[orphan_idata];
+          else
+            place = &hold[orphan_rodata];
+	}
       else
 	place = &hold[orphan_text];
 
Index: src/ld/emultempl/pep.em
===================================================================
--- src.orig/ld/emultempl/pep.em	2010-05-25 12:00:49.000000000 +0200
+++ src/ld/emultempl/pep.em	2010-09-16 10:48:59.075797300 +0200
@@ -1677,6 +1677,9 @@ gld_${EMULATION_NAME}_place_orphan (asec
 	  { ".text",
 	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
 	    0, 0, 0, 0 },
+	  { ".idata",
+	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
+	    0, 0, 0, 0 },
 	  { ".rdata",
 	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
 	    0, 0, 0, 0 },
@@ -1690,6 +1693,7 @@ gld_${EMULATION_NAME}_place_orphan (asec
       enum orphan_save_index
 	{
 	  orphan_text = 0,
+	  orphan_idata,
 	  orphan_rodata,
 	  orphan_data,
 	  orphan_bss
@@ -1723,7 +1727,12 @@ gld_${EMULATION_NAME}_place_orphan (asec
       else if ((s->flags & SEC_READONLY) == 0)
 	place = &hold[orphan_data];
       else if ((s->flags & SEC_CODE) == 0)
-	place = &hold[orphan_rodata];
+        {
+          if (! strncmp (secname, ".idata\$", 7))
+            place = &hold[orphan_idata];
+          else
+            place = &hold[orphan_rodata];
+	}
       else
 	place = &hold[orphan_text];
 
Index: src/ld/scripttempl/armcoff.sc
===================================================================
--- src.orig/ld/scripttempl/armcoff.sc	2009-09-09 13:59:14.000000000 +0200
+++ src/ld/scripttempl/armcoff.sc	2010-09-16 10:55:36.798545700 +0200
@@ -17,7 +17,22 @@ DTOR='.dtor : {
     *(SORT(.dtors.*))
     *(.dtor)
   }'
-
+if test "${RELOCATING}"; then
+  R_IDATA234='
+    SORT(*)(.idata$2)
+    SORT(*)(.idata$3)
+    /* These zeroes mark the end of the import list.  */
+    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
+    SORT(*)(.idata$4)'
+  R_IDATA5='SORT(*)(.idata$5)'
+  R_IDATA67='
+    SORT(*)(.idata$6)
+    SORT(*)(.idata$7)'
+else
+  R_IDATA234=
+  R_IDATA5=
+  R_IDATA67=
+fi
 cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", "${LITTLE_OUTPUT_FORMAT}")
 ${LIB_SEARCH_DIRS}
@@ -60,6 +75,16 @@ SECTIONS
   }
   ${CONSTRUCTING+${RELOCATING-$CTOR}}
   ${CONSTRUCTING+${RELOCATING-$DTOR}}
+  .idata ${RELOCATING+BLOCK(__section_alignment__)} :
+  {
+    /* This cannot currently be handled with grouped sections.
+       See pep.em:sort_sections.  */
+       ${R_IDATA234}
+       ${RELOCATING+__IAT_start__ = .;}
+    ${R_IDATA5}
+       ${RELOCATING+__IAT_end__ = .;}
+    ${R_IDATA67}
+  }
   .bss ${RELOCATING+ ALIGN(0x8)} :
   { 					
     ${RELOCATING+ __bss_start__ = . ;}
Index: src/ld/scripttempl/pe.sc
===================================================================
--- src.orig/ld/scripttempl/pe.sc	2009-11-25 07:59:01.000000000 +0100
+++ src/ld/scripttempl/pe.sc	2010-09-16 11:04:26.609849200 +0200
@@ -23,12 +23,14 @@ if test "${RELOCATING}"; then
     R_RDATA='*(.rdata)
              *(SORT(.rdata$*))'
   fi
-  R_IDATA='
+  R_IDATA234='
     SORT(*)(.idata$2)
     SORT(*)(.idata$3)
     /* These zeroes mark the end of the import list.  */
     LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
-    SORT(*)(.idata$4)
+    SORT(*)(.idata$4)'
+  R_IDATA5='SORT(*)(.idata$5)'
+  R_IDATA67='
     SORT(*)(.idata$5)
     SORT(*)(.idata$6)
     SORT(*)(.idata$7)'
@@ -46,7 +48,9 @@ else
   R_TEXT=
   R_DATA=
   R_RDATA='*(.rdata)'
-  R_IDATA=
+  R_IDATA234=
+  R_IDATA5=
+  R_IDATA67=
   R_CRT=
   R_RSRC=
 fi
@@ -147,7 +151,11 @@ SECTIONS
   {
     /* This cannot currently be handled with grouped sections.
 	See pe.em:sort_sections.  */
-    ${R_IDATA}
+    ${R_IDATA234}
+    ${RELOCATING+__IAT_start__ = .;}
+    ${R_IDATA5}
+    ${RELOCATING+__IAT_end__ = .;}
+    ${R_IDATA67}
   }
   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
   { 					
Index: src/ld/scripttempl/pep.sc
===================================================================
--- src.orig/ld/scripttempl/pep.sc	2010-09-15 21:38:46.000000000 +0200
+++ src/ld/scripttempl/pep.sc	2010-09-16 11:01:33.897970600 +0200
@@ -23,13 +23,14 @@ if test "${RELOCATING}"; then
     R_RDATA='*(.rdata)
              *(SORT(.rdata$*))'
   fi
-  R_IDATA='
+  R_IDATA234='
     SORT(*)(.idata$2)
     SORT(*)(.idata$3)
     /* These zeroes mark the end of the import list.  */
     LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
-    SORT(*)(.idata$4)
-    SORT(*)(.idata$5)
+    SORT(*)(.idata$4)'
+  R_IDATA5='SORT(*)(.idata$5)'
+  R_IDATA67='
     SORT(*)(.idata$6)
     SORT(*)(.idata$7)'
   R_CRT_XC='*(SORT(.CRT$XC*))  /* C initialization */'
@@ -46,7 +47,9 @@ else
   R_TEXT=
   R_DATA=
   R_RDATA='*(.rdata)'
-  R_IDATA=
+  R_IDATA234=
+  R_IDATA5=
+  R_IDATA67=
   R_CRT=
   R_RSRC=
 fi
@@ -153,7 +156,11 @@ SECTIONS
   {
     /* This cannot currently be handled with grouped sections.
 	See pep.em:sort_sections.  */
-    ${R_IDATA}
+    ${R_IDATA234}
+    ${RELOCATING+__IAT_start__ = .;}
+    ${R_IDATA5}
+    ${RELOCATING+__IAT_end__ = .;}
+    ${R_IDATA67}
   }
   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
   { 					
