diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c36c6122fd4a9631c900dfdcf27b74c73030e2a3..b1b7fe742190d6e1d0cad6d384166da582fc105a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2009-01-19  Iain Sandoe  <iain.sandoe@sandoe-acoustics.co.uk>
+
+        * config/darwin.h: Add static-libgfortran to LINK_SPEC.
+
 2009-01-19  Vladimir Makarov  <vmakarov@redhat.com>
 
 	PR c/38869
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 03955c64d0a7423a0d8163d0121a666735e43341..53dab64059416258cd0c52a24a24282a3c2921bd 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -258,6 +258,7 @@ extern GTY(()) int darwin_ms_struct;
 #define LINK_SPEC  \
   "%{static}%{!static:-dynamic} \
    %{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)}\
+   %{static|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
    %{!Zdynamiclib: \
      %{Zforce_cpusubtype_ALL:-arch %(darwin_arch) -force_cpusubtype_ALL} \
      %{!Zforce_cpusubtype_ALL:-arch %(darwin_subarch)} \
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e9bfcd25dea8ddcbd27c7b28c531b0397d36095f..24d647eea676a198498f5aff87bd6c84ddcd8762 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-19  Iain Sandoe  <iain.sandoe@sandoe-acoustics.co.uk>
+
+        * lib/gfortran.exp: Add -B options for targets that use
+	libgfortran.a%s in their specs.
+
 2009-01-19  Jason Merrill  <jason@redhat.com>
 
 	PR c++/23287
diff --git a/gcc/testsuite/lib/gfortran.exp b/gcc/testsuite/lib/gfortran.exp
index b0e66d8d3a81a412ec1dd5b6d77677eff6121543..6d5617f5f5428303bd78a8c8fc22eb47efe669b3 100644
--- a/gcc/testsuite/lib/gfortran.exp
+++ b/gcc/testsuite/lib/gfortran.exp
@@ -88,6 +88,9 @@ proc gfortran_link_flags { paths } {
 
     if { $gccpath != "" } {
       if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
+          # Some targets use libgfortran.a%s in their specs, so they need a -B option
+          # for uninstalled testing.
+          append flags "-B${gccpath}/libgfortran/.libs "
           append flags "-L${gccpath}/libgfortran/.libs "
           append ld_library_path ":${gccpath}/libgfortran/.libs"
       }
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 9428394f629f732ed1f0bf91c9fa0eb901c17016..d23a23342fefb89cf3f5655609f4f81b4f5641ef 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-19  Iain Sandoe  <iain.sandoe@sandoe-acoustics.co.uk>
+
+        * testsuite/lib/libgomp.exp: Add -B option for targets that
+	use libgfortran.a%s in their specs.
+
 2009-01-07  Jakub Jelinek  <jakub@redhat.com>
 
 	PR libgomp/38086
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index 4e2600ec5f742950112b83d8e9c202b49d5aa543..972d4a1fdd3f6124edc9a7d3d8065cc60ab92030 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -171,6 +171,9 @@ proc libgomp_target_compile { source dest type options } {
 
     if { [info exists lang_test_file] } {
         if { $blddir != "" } {
+            # Some targets use libgfortran.a%s in their specs, so they need
+            # a -B option for uninstalled testing.
+            lappend options "additional_flags=-B${blddir}/${lang_library_path}"
             lappend options "ldflags=-L${blddir}/${lang_library_path}"
         }
         lappend options "ldflags=${lang_link_flags}"