diff mbox

[testsuite] : Improve check_effective_target_fsanitize_thread

Message ID CAFULd4Yig7NNEgeBUHe=CnBmdvs+q+eNh6gCzZEv8899A69xdQ@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Feb. 3, 2016, 1:53 p.m. UTC
Hello!

Attached patch improves detection of working -fsanitize=thread option.
Check for working -fsanitize=thread option timeouts with older glibcs,
so tsan_init detects this case and sets default compile flags to
compile.

Recently Eric changed check_effective_target_fsanitize_thread to a
runtime test, and we *again* unnecessarily waste 5 minutes of test
time here, waiting for a test to timeout.

Attached patch moves the detection to
check_effective_target_fsanitize_thread function. Now, the function
first checks if the compiler is able to create executable (and exits
early if not) and later in the function sets what to do by default,
depending on the outcome of the runtime test.

BTW: The dg-do-what-default link was chosen to avoid the testsuite
error due to the usage of additional-sources in some testcases). Also,
we don't need additional compile flags for check_no_compiler_messages
and check_runtime since TEST_ALWAYS_FLAG is always set.

2016-02-03  Uros Bizjak  <ubizjak@gmail.com>

    * lib/tsan-dg.exp (tsan_init): Move check if tsan executable
    works from here ...
    (check_effective_target_fsanitize_thread): ... to here.  Do not
    specify additional compile flags for the test source.
    * lib/asan-dg.exp (check_effective_target_fsanitize_address): Do not
    specify additional compile flags for the test source.

Patch was tested on x86_64-linux-gnu (CentOS 5.11 and Fedora 23).

OK for mainline?

Uros.

Comments

Jakub Jelinek Feb. 3, 2016, 1:59 p.m. UTC | #1
On Wed, Feb 03, 2016 at 02:53:56PM +0100, Uros Bizjak wrote:
> diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
> index 994160e..a1198c0 100644
> --- a/gcc/testsuite/lib/asan-dg.exp
> +++ b/gcc/testsuite/lib/asan-dg.exp
> @@ -20,7 +20,7 @@
>  proc check_effective_target_fsanitize_address {} {
>      return [check_no_compiler_messages fsanitize_address executable {
>  	int main (void) { return 0; }
> -    } "-fsanitize=address"]
> +    }]
>  }
>  

This is just weird.  What if fsanitize_address effective target is used
outside of asan/ (i.e. without asan_init first) ?

	Jakub
Uros Bizjak Feb. 3, 2016, 2:12 p.m. UTC | #2
On Wed, Feb 3, 2016 at 2:59 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Feb 03, 2016 at 02:53:56PM +0100, Uros Bizjak wrote:
>> diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
>> index 994160e..a1198c0 100644
>> --- a/gcc/testsuite/lib/asan-dg.exp
>> +++ b/gcc/testsuite/lib/asan-dg.exp
>> @@ -20,7 +20,7 @@
>>  proc check_effective_target_fsanitize_address {} {
>>      return [check_no_compiler_messages fsanitize_address executable {
>>       int main (void) { return 0; }
>> -    } "-fsanitize=address"]
>> +    }]
>>  }
>>
>
> This is just weird.  What if fsanitize_address effective target is used
> outside of asan/ (i.e. without asan_init first) ?

It won't work, you also need various link flags that are part of
TEST_ALWAYS_FLAGS.

Uros.
Jakub Jelinek Feb. 3, 2016, 2:15 p.m. UTC | #3
On Wed, Feb 03, 2016 at 03:12:27PM +0100, Uros Bizjak wrote:
> On Wed, Feb 3, 2016 at 2:59 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > On Wed, Feb 03, 2016 at 02:53:56PM +0100, Uros Bizjak wrote:
> >> diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
> >> index 994160e..a1198c0 100644
> >> --- a/gcc/testsuite/lib/asan-dg.exp
> >> +++ b/gcc/testsuite/lib/asan-dg.exp
> >> @@ -20,7 +20,7 @@
> >>  proc check_effective_target_fsanitize_address {} {
> >>      return [check_no_compiler_messages fsanitize_address executable {
> >>       int main (void) { return 0; }
> >> -    } "-fsanitize=address"]
> >> +    }]
> >>  }
> >>
> >
> > This is just weird.  What if fsanitize_address effective target is used
> > outside of asan/ (i.e. without asan_init first) ?
> 
> It won't work, you also need various link flags that are part of
> TEST_ALWAYS_FLAGS.

The patch is ok then.

	Jakub
Eric Botcazou Feb. 3, 2016, 2:36 p.m. UTC | #4
> Attached patch improves detection of working -fsanitize=thread option.
> Check for working -fsanitize=thread option timeouts with older glibcs,
> so tsan_init detects this case and sets default compile flags to
> compile.
> 
> Recently Eric changed check_effective_target_fsanitize_thread to a
> runtime test, and we *again* unnecessarily waste 5 minutes of test
> time here, waiting for a test to timeout.

Well, if you don't want someone else to do it again, you'd better adjust the 
comments as well because, as Jakub put it, the whole stuff is rather weird.
Andreas Schwab Feb. 4, 2016, 11:12 a.m. UTC | #5
Uros Bizjak <ubizjak@gmail.com> writes:

> On Wed, Feb 3, 2016 at 2:59 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Wed, Feb 03, 2016 at 02:53:56PM +0100, Uros Bizjak wrote:
>>> diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
>>> index 994160e..a1198c0 100644
>>> --- a/gcc/testsuite/lib/asan-dg.exp
>>> +++ b/gcc/testsuite/lib/asan-dg.exp
>>> @@ -20,7 +20,7 @@
>>>  proc check_effective_target_fsanitize_address {} {
>>>      return [check_no_compiler_messages fsanitize_address executable {
>>>       int main (void) { return 0; }
>>> -    } "-fsanitize=address"]
>>> +    }]
>>>  }
>>>
>>
>> This is just weird.  What if fsanitize_address effective target is used
>> outside of asan/ (i.e. without asan_init first) ?
>
> It won't work, you also need various link flags that are part of
> TEST_ALWAYS_FLAGS.

That breaks gcc.dg/sancov/asan.c.

Running /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/sancov.exp ...
Executing on host: /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ fsanitize_address14637.c     -fno-diagnostics-show-caret -fdiagnostics-color=never   -lm  -o fsanitize_address14637.exe    (timeout = 300)
spawn -ignore SIGHUP /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ fsanitize_address14637.c -fno-diagnostics-show-caret -fdiagnostics-color=never -lm -o fsanitize_address14637.exe.
Executing on host: /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c     -fno-diagnostics-show-caret -fdiagnostics-color=never    -O0  -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s    (timeout = 300)
spawn -ignore SIGHUP /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s.
cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target.
cc1: warning: -fsanitize=address not supported for this target.
output is:
cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target.
cc1: warning: -fsanitize=address not supported for this target.

FAIL: gcc.dg/sancov/asan.c   -O0  (test for excess errors)
Excess errors:
cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target
cc1: warning: -fsanitize=address not supported for this target

FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___sanitizer_cov_trace_pc \\(\\)" 4
FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_load4 \\(" 1
FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_store4 \\(" 1

Andreas.
Uros Bizjak Feb. 4, 2016, 11:56 a.m. UTC | #6
On Thu, Feb 4, 2016 at 12:12 PM, Andreas Schwab <schwab@suse.de> wrote:
> Uros Bizjak <ubizjak@gmail.com> writes:
>
>> On Wed, Feb 3, 2016 at 2:59 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>>> On Wed, Feb 03, 2016 at 02:53:56PM +0100, Uros Bizjak wrote:
>>>> diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
>>>> index 994160e..a1198c0 100644
>>>> --- a/gcc/testsuite/lib/asan-dg.exp
>>>> +++ b/gcc/testsuite/lib/asan-dg.exp
>>>> @@ -20,7 +20,7 @@
>>>>  proc check_effective_target_fsanitize_address {} {
>>>>      return [check_no_compiler_messages fsanitize_address executable {
>>>>       int main (void) { return 0; }
>>>> -    } "-fsanitize=address"]
>>>> +    }]
>>>>  }
>>>>
>>>
>>> This is just weird.  What if fsanitize_address effective target is used
>>> outside of asan/ (i.e. without asan_init first) ?
>>
>> It won't work, you also need various link flags that are part of
>> TEST_ALWAYS_FLAGS.
>
> That breaks gcc.dg/sancov/asan.c.
>
> Running /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/sancov.exp ...
> Executing on host: /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ fsanitize_address14637.c     -fno-diagnostics-show-caret -fdiagnostics-color=never   -lm  -o fsanitize_address14637.exe    (timeout = 300)
> spawn -ignore SIGHUP /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ fsanitize_address14637.c -fno-diagnostics-show-caret -fdiagnostics-color=never -lm -o fsanitize_address14637.exe.
> Executing on host: /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c     -fno-diagnostics-show-caret -fdiagnostics-color=never    -O0  -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s    (timeout = 300)
> spawn -ignore SIGHUP /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s.
> cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target.
> cc1: warning: -fsanitize=address not supported for this target.
> output is:
> cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target.
> cc1: warning: -fsanitize=address not supported for this target.
>
> FAIL: gcc.dg/sancov/asan.c   -O0  (test for excess errors)
> Excess errors:
> cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target
> cc1: warning: -fsanitize=address not supported for this target
>
> FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___sanitizer_cov_trace_pc \\(\\)" 4
> FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_load4 \\(" 1
> FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_store4 \\(" 1

Eh, speaking about sanitizer testsuite weirdness...

Anyway, I'll revert asan-dg.change.

Thanks,
Uros.
Uros Bizjak Feb. 4, 2016, 12:27 p.m. UTC | #7
On Thu, Feb 4, 2016 at 12:56 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Thu, Feb 4, 2016 at 12:12 PM, Andreas Schwab <schwab@suse.de> wrote:
>> Uros Bizjak <ubizjak@gmail.com> writes:
>>
>>> On Wed, Feb 3, 2016 at 2:59 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>> On Wed, Feb 03, 2016 at 02:53:56PM +0100, Uros Bizjak wrote:
>>>>> diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
>>>>> index 994160e..a1198c0 100644
>>>>> --- a/gcc/testsuite/lib/asan-dg.exp
>>>>> +++ b/gcc/testsuite/lib/asan-dg.exp
>>>>> @@ -20,7 +20,7 @@
>>>>>  proc check_effective_target_fsanitize_address {} {
>>>>>      return [check_no_compiler_messages fsanitize_address executable {
>>>>>       int main (void) { return 0; }
>>>>> -    } "-fsanitize=address"]
>>>>> +    }]
>>>>>  }
>>>>>
>>>>
>>>> This is just weird.  What if fsanitize_address effective target is used
>>>> outside of asan/ (i.e. without asan_init first) ?
>>>
>>> It won't work, you also need various link flags that are part of
>>> TEST_ALWAYS_FLAGS.
>>
>> That breaks gcc.dg/sancov/asan.c.
>>
>> Running /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/sancov.exp ...
>> Executing on host: /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ fsanitize_address14637.c     -fno-diagnostics-show-caret -fdiagnostics-color=never   -lm  -o fsanitize_address14637.exe    (timeout = 300)
>> spawn -ignore SIGHUP /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ fsanitize_address14637.c -fno-diagnostics-show-caret -fdiagnostics-color=never -lm -o fsanitize_address14637.exe.
>> Executing on host: /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c     -fno-diagnostics-show-caret -fdiagnostics-color=never    -O0  -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s    (timeout = 300)
>> spawn -ignore SIGHUP /usr/local/gcc/gcc-20160204/Build/gcc/xgcc -B/usr/local/gcc/gcc-20160204/Build/gcc/ /usr/local/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s.
>> cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target.
>> cc1: warning: -fsanitize=address not supported for this target.
>> output is:
>> cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target.
>> cc1: warning: -fsanitize=address not supported for this target.
>>
>> FAIL: gcc.dg/sancov/asan.c   -O0  (test for excess errors)
>> Excess errors:
>> cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target
>> cc1: warning: -fsanitize=address not supported for this target
>>
>> FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___sanitizer_cov_trace_pc \\(\\)" 4
>> FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_load4 \\(" 1
>> FAIL: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_store4 \\(" 1
>
> Eh, speaking about sanitizer testsuite weirdness...
>
> Anyway, I'll revert asan-dg.change.

OTOH, does this testcase even gets a chance to run? fsanitize_address
check builds an executable, so without proper library paths the test
fails.

IMO, we have to move this test to gcc.dg/asan directory.

Uros.
Andreas Schwab Feb. 4, 2016, 12:46 p.m. UTC | #8
Uros Bizjak <ubizjak@gmail.com> writes:

> OTOH, does this testcase even gets a chance to run?

It's not a runtime check.

Running /opt/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/sancov.exp ...
Executing on host: /opt/gcc/gcc-20160204/Build/gcc/xgcc -B/opt/gcc/gcc-20160204/Build/gcc/ fsanitize_address19647.c     -fno-diagnostics-show-caret -fdiagnostics-color=never   -lm  -o fsanitize_address19647.exe    (timeout = 300)
spawn -ignore SIGHUP /opt/gcc/gcc-20160204/Build/gcc/xgcc -B/opt/gcc/gcc-20160204/Build/gcc/ fsanitize_address19647.c -fno-diagnostics-show-caret -fdiagnostics-color=never -lm -o fsanitize_address19647.exe.
Executing on host: /opt/gcc/gcc-20160204/Build/gcc/xgcc -B/opt/gcc/gcc-20160204/Build/gcc/ /opt/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c     -fno-diagnostics-show-caret -fdiagnostics-color=never    -O0  -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s    (timeout = 300)
spawn -ignore SIGHUP /opt/gcc/gcc-20160204/Build/gcc/xgcc -B/opt/gcc/gcc-20160204/Build/gcc/ /opt/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s.
PASS: gcc.dg/sancov/asan.c   -O0  (test for excess errors)
PASS: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___sanitizer_cov_trace_pc \\(\\)" 4
PASS: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_load4 \\(" 1
PASS: gcc.dg/sancov/asan.c   -O0   scan-tree-dump-times optimized "__builtin___asan_report_store4 \\(" 1
Executing on host: /opt/gcc/gcc-20160204/Build/gcc/xgcc -B/opt/gcc/gcc-20160204/Build/gcc/ /opt/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c     -fno-diagnostics-show-caret -fdiagnostics-color=never    -O1  -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s    (timeout = 300)
spawn -ignore SIGHUP /opt/gcc/gcc-20160204/Build/gcc/xgcc -B/opt/gcc/gcc-20160204/Build/gcc/ /opt/gcc/gcc-20160204/gcc/testsuite/gcc.dg/sancov/asan.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O1 -fsanitize-coverage=trace-pc -fsanitize=address -fdump-tree-optimized -S -o asan.s.
PASS: gcc.dg/sancov/asan.c   -O1  (test for excess errors)
PASS: gcc.dg/sancov/asan.c   -O1   scan-tree-dump-times optimized "__builtin___sanitizer_cov_trace_pc \\(\\)" 4
PASS: gcc.dg/sancov/asan.c   -O1   scan-tree-dump-times optimized "__builtin___asan_report_load4 \\(" 1
PASS: gcc.dg/sancov/asan.c   -O1   scan-tree-dump-times optimized "__builtin___asan_report_store4 \\(" 1

Andreas.
Andreas Schwab Feb. 4, 2016, 12:49 p.m. UTC | #9
Andreas Schwab <schwab@suse.de> writes:

> Uros Bizjak <ubizjak@gmail.com> writes:
>
>> OTOH, does this testcase even gets a chance to run?
>
> It's not a runtime check.

But it didn't link until today:

Running /opt/gcc/gcc-20160203/gcc/testsuite/gcc.dg/sancov/sancov.exp ...
Executing on host: /opt/gcc/gcc-20160203/Build/gcc/xgcc -B/opt/gcc/gcc-20160203/Build/gcc/ fsanitize_address29346.c     -fno-diagnostics-show-caret -fdiagnostics-color=never  -fsanitize=address  -lm  -o fsanitize_address29346.exe    (timeout = 300)
spawn -ignore SIGHUP /opt/gcc/gcc-20160203/Build/gcc/xgcc -B/opt/gcc/gcc-20160203/Build/gcc/ fsanitize_address29346.c -fno-diagnostics-show-caret -fdiagnostics-color=never -fsanitize=address -lm -o fsanitize_address29346.exe.
/usr/aarch64-suse-linux/bin/ld: cannot find libasan_preinit.o: No such file or directory.
/usr/aarch64-suse-linux/bin/ld: cannot find -lasan.
collect2: error: ld returned 1 exit status.
compiler exited with status 1
output is:
/usr/aarch64-suse-linux/bin/ld: cannot find libasan_preinit.o: No such file or directory.
/usr/aarch64-suse-linux/bin/ld: cannot find -lasan.
collect2: error: ld returned 1 exit status.

UNSUPPORTED: gcc.dg/sancov/asan.c   -O0 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O1 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O2 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O3 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O0 -g 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O1 -g 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O2 -g 
UNSUPPORTED: gcc.dg/sancov/asan.c   -O3 -g 

Andreas.
diff mbox

Patch

diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
index 994160e..a1198c0 100644
--- a/gcc/testsuite/lib/asan-dg.exp
+++ b/gcc/testsuite/lib/asan-dg.exp
@@ -20,7 +20,7 @@ 
 proc check_effective_target_fsanitize_address {} {
     return [check_no_compiler_messages fsanitize_address executable {
 	int main (void) { return 0; }
-    } "-fsanitize=address"]
+    }]
 }
 
 proc asan_include_flags {} {
diff --git a/gcc/testsuite/lib/tsan-dg.exp b/gcc/testsuite/lib/tsan-dg.exp
index eb1f3a9..5745fe7 100644
--- a/gcc/testsuite/lib/tsan-dg.exp
+++ b/gcc/testsuite/lib/tsan-dg.exp
@@ -15,12 +15,30 @@ 
 # <http://www.gnu.org/licenses/>.
 
 # Return 1 if compilation with -fsanitize=thread is error-free for trivial
-# code, 0 otherwise.
+# code, 0 otherwise.  Also set what to do by default here.
 
 proc check_effective_target_fsanitize_thread {} {
-    return [check_runtime fsanitize_thread {
+    global individual_timeout
+    global dg-do-what-default
+
+    if ![check_no_compiler_messages fsanitize_thread executable {
 	int main (void) { return 0; }
-    } "-fsanitize=thread"]
+    }] {
+        return 0
+    }
+
+    # Lower timeout value in case test does not terminate properly.
+    set individual_timeout 20
+    if [check_runtime_nocache tsan_works {
+	int main () { return 0; }
+    }] {
+	set dg-do-what-default run
+    } else {
+	set dg-do-what-default link
+    }
+    unset individual_timeout
+
+    return 1
 }
 
 #
@@ -101,22 +119,6 @@  proc tsan_init { args } {
 	    set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=thread -g"
 	}
     }
-
-    set dg-do-what-default run
-    if { $link_flags != "" } {
-	global individual_timeout
-
-	# Lower timeout value in case test does not terminate properly.
-	set individual_timeout 20
-	if [check_runtime_nocache tsan_works {
-		int main () { return 0; }
-	    } "-fsanitize=thread -g"] {
-	    set dg-do-what-default run
-	} else {
-	    set dg-do-what-default compile
-	}
-	unset individual_timeout
-    }
 }
 
 #