Re: [PATCH] testsuite, ubsan: Add libstdc++ deps where required.

2024-02-02 Thread Jeff Law




On 1/30/24 03:31, Iain Sandoe wrote:

tested on i686, x86_64 (and aarch64) Darwin, x86_64, aarch64 Linux,
OK for trunk?
thanks
Iain

--- 8< ---

We use the ubsan tests from both C, C++, D and Fortran.
the sanitizer libraries link to libstdc++.

When we are using the C/gdc/gfortran driver, and the target might
require a path to the libstdc++ (e.g. for handing -static- or
for embedded runpaths), we need to add a suitable option (or we get
fails at execution time because of the missing paths).

Conversely, we do not want to add multiple instances of these
paths (since that leads to failures on tools that report warnings
for duplicate runpaths).

This patch modifies the _init function to allow a sigle parameter
that determines whether the *asan_init should add a path for
libstdc++ (yes for C driver, no for C++ driver).
gcc/testsuite/ChangeLog:

* g++.dg/ubsan/ubsan.exp:Add a parameter to init to say that
we expect the C++ driver to provide paths for libstdc++.
* gcc.dg/ubsan/ubsan.exp: Add a parameter to init to say that
we need a path added for libstdc++.
* gdc.dg/ubsan/ubsan.exp: Likewise.
* gfortran.dg/ubsan/ubsan.exp: Likewise.
* lib/ubsan-dg.exp: Handle a single parameter to init that
requests addition of a path to libstdc++ to link flags.

Also OK.
jeff


Re: [PATCH] testsuite, ubsan: Add libstdc++ deps where required.

2024-02-01 Thread Mike Stump
On Jan 30, 2024, at 2:31 AM, Iain Sandoe  wrote:
> 
> tested on i686, x86_64 (and aarch64) Darwin, x86_64, aarch64 Linux,
> OK for trunk?

Ok. If the ubsan people want to review this, certainly, happy to have them 
chime in.

[PATCH] testsuite, ubsan: Add libstdc++ deps where required.

2024-01-30 Thread Iain Sandoe
tested on i686, x86_64 (and aarch64) Darwin, x86_64, aarch64 Linux,
OK for trunk?
thanks
Iain

--- 8< ---

We use the ubsan tests from both C, C++, D and Fortran.
the sanitizer libraries link to libstdc++.

When we are using the C/gdc/gfortran driver, and the target might
require a path to the libstdc++ (e.g. for handing -static- or
for embedded runpaths), we need to add a suitable option (or we get
fails at execution time because of the missing paths).

Conversely, we do not want to add multiple instances of these
paths (since that leads to failures on tools that report warnings
for duplicate runpaths).

This patch modifies the _init function to allow a sigle parameter
that determines whether the *asan_init should add a path for
libstdc++ (yes for C driver, no for C++ driver).
gcc/testsuite/ChangeLog:

* g++.dg/ubsan/ubsan.exp:Add a parameter to init to say that
we expect the C++ driver to provide paths for libstdc++.
* gcc.dg/ubsan/ubsan.exp: Add a parameter to init to say that
we need a path added for libstdc++.
* gdc.dg/ubsan/ubsan.exp: Likewise.
* gfortran.dg/ubsan/ubsan.exp: Likewise.
* lib/ubsan-dg.exp: Handle a single parameter to init that
requests addition of a path to libstdc++ to link flags.
---
 gcc/testsuite/g++.dg/ubsan/ubsan.exp  |  3 ++-
 gcc/testsuite/gcc.dg/ubsan/ubsan.exp  |  3 ++-
 gcc/testsuite/gdc.dg/ubsan/ubsan.exp  |  3 ++-
 gcc/testsuite/gfortran.dg/ubsan/ubsan.exp |  4 ++--
 gcc/testsuite/lib/ubsan-dg.exp| 20 +++-
 5 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/g++.dg/ubsan/ubsan.exp 
b/gcc/testsuite/g++.dg/ubsan/ubsan.exp
index d7197070a92..4bab1b83de9 100644
--- a/gcc/testsuite/g++.dg/ubsan/ubsan.exp
+++ b/gcc/testsuite/g++.dg/ubsan/ubsan.exp
@@ -22,7 +22,8 @@ load_lib ubsan-dg.exp
 
 # Initialize `dg'.
 dg-init
-ubsan_init
+# libubsan uses libstdc++ but we assume that's added by the g++ impl.
+ubsan_init 0
 
 # Main loop.
 if [check_effective_target_fsanitize_undefined] {
diff --git a/gcc/testsuite/gcc.dg/ubsan/ubsan.exp 
b/gcc/testsuite/gcc.dg/ubsan/ubsan.exp
index 84170495e28..560e5843be6 100644
--- a/gcc/testsuite/gcc.dg/ubsan/ubsan.exp
+++ b/gcc/testsuite/gcc.dg/ubsan/ubsan.exp
@@ -24,7 +24,8 @@ load_lib ubsan-dg.exp
 
 # Initialize `dg'.
 dg-init
-ubsan_init
+# libubsan uses libstdc++ so make sure we provide paths for it.
+ubsan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_undefined] {
diff --git a/gcc/testsuite/gdc.dg/ubsan/ubsan.exp 
b/gcc/testsuite/gdc.dg/ubsan/ubsan.exp
index 6ad665a1a8d..7613a3b487c 100644
--- a/gcc/testsuite/gdc.dg/ubsan/ubsan.exp
+++ b/gcc/testsuite/gdc.dg/ubsan/ubsan.exp
@@ -20,7 +20,8 @@ load_lib ubsan-dg.exp
 
 # Initialize `dg'.
 dg-init
-ubsan_init
+# libubsan uses libstdc++ so make sure we provide paths for it.
+ubsan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_undefined] {
diff --git a/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp 
b/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp
index 0c61153e68b..b2360785e6c 100644
--- a/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp
+++ b/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp
@@ -22,10 +22,10 @@
 load_lib gfortran-dg.exp
 load_lib ubsan-dg.exp
 
-
 # Initialize `dg'.
 dg-init
-ubsan_init
+# libubsan uses libstdc++ so make sure we provide paths for it.
+ubsan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_undefined] {
diff --git a/gcc/testsuite/lib/ubsan-dg.exp b/gcc/testsuite/lib/ubsan-dg.exp
index 108b9980cac..860e78f3975 100644
--- a/gcc/testsuite/lib/ubsan-dg.exp
+++ b/gcc/testsuite/lib/ubsan-dg.exp
@@ -31,7 +31,7 @@ proc check_effective_target_fsanitize_undefined {} {
 # (originally from g++.exp)
 #
 
-proc ubsan_link_flags { paths } {
+proc ubsan_link_flags { paths needs_cxx } {
 global srcdir
 global ld_library_path
 global shlib_ext
@@ -43,15 +43,24 @@ proc ubsan_link_flags { paths } {
 set shlib_ext [get_shlib_extension]
 set ubsan_saved_library_path $ld_library_path
 
+# Providing -B instead of -L means that it works for targets that use
+# spec substitution for handling -static-x, it also works for targets
+# the use the startfile paths to provide a runpath for uninstalled test.
+# Each -B option will produce a -L on the link line (for paths that exist).
 if { $gccpath != "" } {
   if { [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.a"]
   || [file exists 
"${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } {
  append flags " -B${gccpath}/libsanitizer/ "
  append flags " -B${gccpath}/libsanitizer/ubsan/ "
- append flags " -L${gccpath}/libsanitizer/ubsan/.libs"
+ append flags " -B${gccpath}/libsanitizer/ubsan/.libs"
  append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs"
- append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
   }
+  # libasan links to libstdc++, so we must in