Hi!

On 2021-09-21T09:37:15+0200, Eric Botcazou <[email protected]> wrote:
> The implementation of the no_fsanitize_address effective target was copied 
> from asan-dg.exp without realizing that it does not work outside of this 
> context (there is a comment explaining why).  As a consequence, it always 
> returns 0, so for example the directive in gnat.dg/asan1.adb:
>
> { dg-skip-if "no address sanitizer" { no_fsanitize_address } }
>
> does not work.  [...], thus disabling them 
> everywhere instead of just for the problematic targets.
>
> The attached patch cleans up the mess, [...]

> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp

> -# Return 1 if target is not support address sanitize, 1 otherwise.
> +# Return 1 if the target does not support address sanitizer, 0 otherwise
>  
>  proc check_effective_target_no_fsanitize_address {} {
>      if ![check_no_compiler_messages fsanitize_address executable {
>       int main (void) { return 0; }
> -    }] {
> +    } "-fsanitize=address" ] {
>       return 1;
>      }
> +
>      return 0;
>  }

Turns out, that's still not sufficient.  ;-)

I've pushed to trunk commit de1f7025fab32bc823a56a596a368e2e73eb2437
"Further fix up effective-target 'no_fsanitize_address' check", see
attached.


Grüße
 Thomas


>From 8eb03ad712bdbd31f9a1c84b72bcbf0c5ef1b722 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <[email protected]>
Date: Thu, 19 Feb 2026 11:29:42 +0100
Subject: [PATCH] Further fix up effective-target 'no_fsanitize_address' check

That got added with commit r11-4762-g65e82636bcdb72a878c2e53943e71b15dd9fb22d
"PR target/96307: Fix KASAN option checking", and already fixed up in
commit r12-3723-g6e6bf4cd21af39a7923bae007517ab43a4c3b36a
"Fix no_fsanitize_address effective target", but I just realized that on, for
example, standard x86_64-pc-linux-gnu, I'm unexpectedly seeing test cases
UNSUPPORTED, due to the effective-target 'no_fsanitize_address' check failing
with:

    Executing on host: [...]/build-gcc/gcc/xgcc -B[...]/build-gcc/gcc/  fsanitize_address3454287.c    -fdiagnostics-plain-output  -fsanitize=address -Wno-complain-wrong-lang  -lm  -o fsanitize_address3454287.exe    (timeout = 300)
    spawn [...]
    /usr/bin/ld: cannot find libasan_preinit.o: No such file or directory
    /usr/bin/ld: cannot find -lasan: No such file or directory
    collect2: error: ld returned 1 exit status
    compiler exited with status 1

Notice no setup for paths to build-tree libsanitizer.  Need to use a proper
'asan.exp' file with 'asan_init'/'asan_finish' calls to set up linker paths,
etc. -- however, all test cases using effective-target 'no_fsanitize_address'
are compilation test cases, so let's just reflect that in the effective-target
'no_fsanitize_address' check.  With that, I then get the desired:

    -UNSUPPORTED: gcc.dg/pr91441.c
    +PASS: gcc.dg/pr91441.c (test for excess errors)

    -UNSUPPORTED: gcc.dg/pr96260.c
    +PASS: gcc.dg/pr96260.c (test for excess errors)

    -UNSUPPORTED: gcc.dg/pr96307.c
    +PASS: gcc.dg/pr96307.c (test for excess errors)

    -UNSUPPORTED: gcc.dg/uninit-pr93100.c
    +PASS: gcc.dg/uninit-pr93100.c  (test for warnings, line 16)
    +PASS: gcc.dg/uninit-pr93100.c  (test for warnings, line 26)
    +PASS: gcc.dg/uninit-pr93100.c  (test for warnings, line 38)
    +PASS: gcc.dg/uninit-pr93100.c  (test for warnings, line 48)
    +PASS: gcc.dg/uninit-pr93100.c  (test for warnings, line 61)
    +PASS: gcc.dg/uninit-pr93100.c  (test for warnings, line 71)
    +PASS: gcc.dg/uninit-pr93100.c (test for excess errors)

    -UNSUPPORTED: g++.dg/warn/uninit-pr93100.C  -std=gnu++20
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20  (test for warnings, line 13)
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20  (test for warnings, line 20)
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20  (test for warnings, line 31)
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20  (test for warnings, line 38)
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20  (test for warnings, line 49)
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20  (test for warnings, line 56)
    +PASS: g++.dg/warn/uninit-pr93100.C  -std=gnu++20 (test for excess errors)
    [Etc.]

    -UNSUPPORTED: g++.dg/warn/uninit-pr95825-1.C  -std=gnu++20
    +PASS: g++.dg/warn/uninit-pr95825-1.C  -std=gnu++20  (test for bogus messages, line 17)
    +PASS: g++.dg/warn/uninit-pr95825-1.C  -std=gnu++20 (test for excess errors)
    [Etc.]

    -UNSUPPORTED: gnat.dg/asan1.adb
    +PASS: gnat.dg/asan1.adb (test for excess errors)

..., while these remain UNSUPPORTED for targets that don't support
'-fsanitize=address'.

	gcc/testsuite/
	* lib/target-supports.exp
	(check_effective_target_no_fsanitize_address): Check 'assembly'
	instead of 'executable'.
---
 gcc/testsuite/lib/target-supports.exp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index ba91c95b348..855bdbcf55a 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -14144,10 +14144,13 @@ proc check_effective_target_movdir { } {
     } "-mmovdiri -mmovdir64b" ]
 }
 
-# Return 1 if the target does not support address sanitizer, 0 otherwise
+# Return 1 if the target does not support address sanitizer, 0 otherwise.
+# Note that this is usable only for compilation test cases.  (Otherwise, use a
+# proper 'asan.exp' file with 'asan_init'/'asan_finish' calls to set up linker
+# paths, etc.)
 
 proc check_effective_target_no_fsanitize_address {} {
-    if ![check_no_compiler_messages fsanitize_address executable {
+    if ![check_no_compiler_messages fsanitize_address assembly {
 	int main (void) { return 0; }
     } "-fsanitize=address" ] {
 	return 1;
-- 
2.34.1

Reply via email to