diff --git a/gcc/testsuite/lib/g++.exp b/gcc/testsuite/lib/g++.exp
index 24ef068b2395361759deb654281e22a9abbf9729..16e61fb4ad49269df779b6ef9e66983a371316f8 100644
--- a/gcc/testsuite/lib/g++.exp
+++ b/gcc/testsuite/lib/g++.exp
@@ -303,11 +303,6 @@ proc g++_target_compile { source dest type options } {
     global flags_to_postpone
     global board_info
 
-    if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
-	lappend options "libs=${gluefile}"
-	lappend options "ldflags=${wrap_flags}"
-    }
-
     global TEST_EXTRA_LIBS
     if [info exists TEST_EXTRA_LIBS] {
 	lappend options "ldflags=$TEST_EXTRA_LIBS"
@@ -333,6 +328,11 @@ proc g++_target_compile { source dest type options } {
 
     set options [dg-additional-files-options $options $source]
 
+    if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
+	lappend options "libs=${gluefile}"
+	lappend options "ldflags=${wrap_flags}"
+    }
+
     set result [target_compile $source $dest $type $options]
 
     if {[board_info $tboard exists multilib_flags]} {
diff --git a/gcc/testsuite/lib/gcc.exp b/gcc/testsuite/lib/gcc.exp
index 1b25ebec4cffcd8032a863a4798afec3ef3f61f8..2f145d0fdf4f35bb0fb603e16e28bbb7b22c74f4 100644
--- a/gcc/testsuite/lib/gcc.exp
+++ b/gcc/testsuite/lib/gcc.exp
@@ -129,16 +129,6 @@ proc gcc_target_compile { source dest type options } {
     global flags_to_postpone
     global board_info
 
-    if {[target_info needs_status_wrapper] != "" && \
-	    [target_info needs_status_wrapper] != "0" && \
-	    [info exists gluefile] } {
-	lappend options "libs=${gluefile}"
-	lappend options "ldflags=$wrap_flags"
-	if { $type == "executable" } {
-	    set options [concat "{additional_flags=-dumpbase \"\"}" $options]
-	}
-    }
-
     global TEST_EXTRA_LIBS
     if [info exists TEST_EXTRA_LIBS] {
 	lappend options "ldflags=$TEST_EXTRA_LIBS"
@@ -170,6 +160,17 @@ proc gcc_target_compile { source dest type options } {
     lappend options "timeout=[timeout_value]"
     lappend options "compiler=$GCC_UNDER_TEST"
     set options [dg-additional-files-options $options $source]
+
+    if {[target_info needs_status_wrapper] != "" && \
+	    [target_info needs_status_wrapper] != "0" && \
+	    [info exists gluefile] } {
+	lappend options "libs=${gluefile}"
+	lappend options "ldflags=$wrap_flags"
+	if { $type == "executable" } {
+	    set options [concat "{additional_flags=-dumpbase \"\"}" $options]
+	}
+    }
+
     set return_val [target_compile $source $dest $type $options]
 
     if {[board_info $tboard exists multilib_flags]} {
diff --git a/gcc/testsuite/lib/wrapper.exp b/gcc/testsuite/lib/wrapper.exp
index 5a601b269daad24d9091e1d9321465f700bec3af..4a7d56941fcdfcf1ba02b126208c5a96d6f46297 100644
--- a/gcc/testsuite/lib/wrapper.exp
+++ b/gcc/testsuite/lib/wrapper.exp
@@ -22,7 +22,7 @@
 # the compiler when compiling FILENAME.
 
 proc ${tool}_maybe_build_wrapper { filename args } {
-    global gluefile wrap_flags
+    global gluefile wrap_flags gcc_adjusted_linker_flags
 
     if { [target_info needs_status_wrapper] != "" \
  	 && [target_info needs_status_wrapper] != "0" \
@@ -43,6 +43,11 @@ proc ${tool}_maybe_build_wrapper { filename args } {
 	if { $result != "" } {
 	    set gluefile [lindex $result 0]
 	    set wrap_flags [lindex $result 1]
+
+	    # Reset the cached state of the adjusted flags
+	    if { [info exists gcc_adjusted_linker_flags] } {
+		set gcc_adjusted_linker_flags 0
+	    }
 	}
     }
 }