public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required.
@ 2024-01-30 10:30 Iain Sandoe
  2024-02-02  0:07 ` Mike Stump
  2024-02-02 14:16 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Iain Sandoe @ 2024-01-30 10:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: ro

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

--- 8< ---

We use the shared asan/hwasan 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-xxxx 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 single 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/asan/asan.exp: Add a parameter to init to say that
	we expect the C++ driver to provide paths for libstdc++.
	* g++.dg/hwasan/hwasan.exp: Likewise
	* gcc.dg/asan/asan.exp: Add a parameter to init to say that
	we need a path added for libstdc++.
	* gcc.dg/hwasan/hwasan.exp: Likewise.
	* gdc.dg/asan/asan.exp: Likewise.
	* gfortran.dg/asan/asan.exp: Likewise.
	* lib/asan-dg.exp: Handle a single parameter to init that
	requests addition of a path to libstdc++ to link flags.
	* lib/hwasan-dg.exp: Likewise.
---
 gcc/testsuite/g++.dg/asan/asan.exp      |  3 ++-
 gcc/testsuite/g++.dg/hwasan/hwasan.exp  |  3 ++-
 gcc/testsuite/gcc.dg/asan/asan.exp      |  3 ++-
 gcc/testsuite/gcc.dg/hwasan/hwasan.exp  |  3 ++-
 gcc/testsuite/gdc.dg/asan/asan.exp      |  3 ++-
 gcc/testsuite/gfortran.dg/asan/asan.exp |  3 ++-
 gcc/testsuite/lib/asan-dg.exp           | 21 ++++++++++++++++-----
 gcc/testsuite/lib/hwasan-dg.exp         |  9 +++++----
 8 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/gcc/testsuite/g++.dg/asan/asan.exp b/gcc/testsuite/g++.dg/asan/asan.exp
index 9297bb55eb1..f078bc37800 100644
--- a/gcc/testsuite/g++.dg/asan/asan.exp
+++ b/gcc/testsuite/g++.dg/asan/asan.exp
@@ -22,7 +22,8 @@ load_lib asan-dg.exp
 
 # Initialize `dg'.
 dg-init
-asan_init
+# libasan uses libstdc++ but we assume that's added by the g++ impl.
+asan_init 0
 
 # Main loop.
 if [check_effective_target_fsanitize_address] {
diff --git a/gcc/testsuite/g++.dg/hwasan/hwasan.exp b/gcc/testsuite/g++.dg/hwasan/hwasan.exp
index 597033e01d5..12a7a3570a0 100644
--- a/gcc/testsuite/g++.dg/hwasan/hwasan.exp
+++ b/gcc/testsuite/g++.dg/hwasan/hwasan.exp
@@ -22,7 +22,8 @@ load_lib hwasan-dg.exp
 
 # Initialize `dg'.
 dg-init
-hwasan_init
+# libhwasan uses libstdc++ but we assume that's added by the g++ impl.
+hwasan_init 0
 
 # Main loop.
 if [check_effective_target_fsanitize_hwaddress] {
diff --git a/gcc/testsuite/gcc.dg/asan/asan.exp b/gcc/testsuite/gcc.dg/asan/asan.exp
index 10c69731fbf..6b8ebf07eae 100644
--- a/gcc/testsuite/gcc.dg/asan/asan.exp
+++ b/gcc/testsuite/gcc.dg/asan/asan.exp
@@ -24,7 +24,8 @@ load_lib asan-dg.exp
 
 # Initialize `dg'.
 dg-init
-asan_init
+# libasan uses libstdc++ so make sure we provide paths for it.
+asan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_address] {
diff --git a/gcc/testsuite/gcc.dg/hwasan/hwasan.exp b/gcc/testsuite/gcc.dg/hwasan/hwasan.exp
index 802f1712296..88327d3b223 100644
--- a/gcc/testsuite/gcc.dg/hwasan/hwasan.exp
+++ b/gcc/testsuite/gcc.dg/hwasan/hwasan.exp
@@ -24,7 +24,8 @@ load_lib hwasan-dg.exp
 
 # Initialize `dg'.
 dg-init
-hwasan_init
+# libhwasan uses libstdc++ so make sure we provide paths for it.
+hwasan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_hwaddress] {
diff --git a/gcc/testsuite/gdc.dg/asan/asan.exp b/gcc/testsuite/gdc.dg/asan/asan.exp
index 72b36696c4d..89c6bf35ae4 100644
--- a/gcc/testsuite/gdc.dg/asan/asan.exp
+++ b/gcc/testsuite/gdc.dg/asan/asan.exp
@@ -20,7 +20,8 @@ load_lib asan-dg.exp
 
 # Initialize `dg'.
 dg-init
-asan_init
+# libasan uses libstdc++ so make sure we provide paths for it.
+asan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_address] {
diff --git a/gcc/testsuite/gfortran.dg/asan/asan.exp b/gcc/testsuite/gfortran.dg/asan/asan.exp
index 25cd19f6133..a1576381e61 100644
--- a/gcc/testsuite/gfortran.dg/asan/asan.exp
+++ b/gcc/testsuite/gfortran.dg/asan/asan.exp
@@ -27,7 +27,8 @@ load_lib asan-dg.exp
 
 # Initialize `dg'.
 dg-init
-asan_init
+# libasan uses libstdc++ so make sure we provide paths for it.
+asan_init 1
 
 # Main loop.
 if [check_effective_target_fsanitize_address] {
diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
index beb49e500eb..6bd3c211611 100644
--- a/gcc/testsuite/lib/asan-dg.exp
+++ b/gcc/testsuite/lib/asan-dg.exp
@@ -61,7 +61,7 @@ proc asan_include_flags {} {
 # (originally from g++.exp)
 #
 
-proc asan_link_flags_1 { paths lib } {
+proc asan_link_flags_1 { paths lib need_stdcxx} {
     global srcdir
     global ld_library_path
     global shlib_ext
@@ -73,6 +73,10 @@ proc asan_link_flags_1 { paths lib } {
     set shlib_ext [get_shlib_extension]
     set ${lib}_saved_library_path $ld_library_path
 
+    # Providing -B instead of -L means that it works for targets that use
+    # spec substitution for handling -static-xxxxx, 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/${lib}/.libs/lib${lib}.a"]
 	   || [file exists "${gccpath}/libsanitizer/${lib}/.libs/lib${lib}.${shlib_ext}"] } {
@@ -81,6 +85,12 @@ proc asan_link_flags_1 { paths lib } {
 	  append flags " -B${gccpath}/libsanitizer/${lib}/.libs "
 	  append ld_library_path ":${gccpath}/libsanitizer/${lib}/.libs"
       }
+      # libasan links to libstdc++, so we must include it for C testcases.
+      if { $need_stdcxx && ( [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"]
+	   || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] ) } {
+	append flags " -B${gccpath}/libstdc++-v3/src/.libs "
+	append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
+      }      
     } else {
       global tool_root_dir
 
@@ -96,8 +106,8 @@ proc asan_link_flags_1 { paths lib } {
     return "$flags"
 }
 
-proc asan_link_flags { paths } {
-    return [asan_link_flags_1 $paths asan]
+proc asan_link_flags { paths need_stdcxx } {
+    return [asan_link_flags_1 $paths asan $need_stdcxx]
 }
 
 #
@@ -113,12 +123,13 @@ proc asan_init { args } {
 
     setenv ASAN_OPTIONS "color=never"
 
+    set needs_cxx [lindex $args 0]
     set link_flags ""
     if ![is_remote host] {
 	if [info exists TOOL_OPTIONS] {
-	    set link_flags "[asan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
+	    set link_flags "[asan_link_flags [get_multilibs ${TOOL_OPTIONS}] $needs_cxx]"
 	} else {
-	    set link_flags "[asan_link_flags [get_multilibs]]"
+	    set link_flags "[asan_link_flags [get_multilibs] $needs_cxx]"
 	}
     }
 
diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp
index 8d66b4db3e3..33c9a7ce274 100644
--- a/gcc/testsuite/lib/hwasan-dg.exp
+++ b/gcc/testsuite/lib/hwasan-dg.exp
@@ -100,8 +100,8 @@ proc hwasan_include_flags {} {
 # (implementation in asan-dg.exp)
 #
 
-proc hwasan_link_flags { paths } {
-    return [asan_link_flags_1 $paths hwasan]
+proc hwasan_link_flags { paths needs_cxx } {
+    return [asan_link_flags_1 $paths hwasan $needs_cxx]
 }
 
 #
@@ -114,6 +114,7 @@ proc hwasan_init { args } {
     global TOOL_OPTIONS
     global hwasan_saved_TEST_ALWAYS_FLAGS
     global hwasan_saved_ALWAYS_CXXFLAGS
+    set needs_cxx [lindex $args 0]
 
     setenv HWASAN_OPTIONS "random_tags=0"
 
@@ -126,9 +127,9 @@ proc hwasan_init { args } {
     set link_flags ""
     if ![is_remote host] {
 	if [info exists TOOL_OPTIONS] {
-	    set link_flags "[hwasan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
+	    set link_flags "[hwasan_link_flags [get_multilibs ${TOOL_OPTIONS}] $needs_cxx]"
 	} else {
-	    set link_flags "[hwasan_link_flags [get_multilibs]]"
+	    set link_flags "[hwasan_link_flags [get_multilibs] $needs_cxx]"
 	}
     }
 
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required.
  2024-01-30 10:30 [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required Iain Sandoe
@ 2024-02-02  0:07 ` Mike Stump
  2024-02-02 14:16 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Stump @ 2024-02-02  0:07 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: gcc-patches, ro@cebitec.uni-bielefeld.de

On Jan 30, 2024, at 2:30 AM, Iain Sandoe <iains.gcc@gmail.com> wrote:
> 
> tested on i686, x86_64 (and aarch64) Darwin, x86_64, aarch64 Linux,
> OK for trunk?

Ok.  If asan people want to chime in...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required.
  2024-01-30 10:30 [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required Iain Sandoe
  2024-02-02  0:07 ` Mike Stump
@ 2024-02-02 14:16 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2024-02-02 14:16 UTC (permalink / raw)
  To: iain, gcc-patches; +Cc: ro



On 1/30/24 03:30, Iain Sandoe wrote:
> tested on i686, x86_64 (and aarch64) Darwin, x86_64, aarch64 Linux,
> OK for trunk?
> thanks
> Iain
> 
> --- 8< ---
> 
> We use the shared asan/hwasan 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-xxxx 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 single 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/asan/asan.exp: Add a parameter to init to say that
> 	we expect the C++ driver to provide paths for libstdc++.
> 	* g++.dg/hwasan/hwasan.exp: Likewise
> 	* gcc.dg/asan/asan.exp: Add a parameter to init to say that
> 	we need a path added for libstdc++.
> 	* gcc.dg/hwasan/hwasan.exp: Likewise.
> 	* gdc.dg/asan/asan.exp: Likewise.
> 	* gfortran.dg/asan/asan.exp: Likewise.
> 	* lib/asan-dg.exp: Handle a single parameter to init that
> 	requests addition of a path to libstdc++ to link flags.
> 	* lib/hwasan-dg.exp: Likewise.
OK.  I don't think we really need to wait for the sanitizer folks to 
chime in.  This is just getting the link bits right, not twiddling the 
sanitizer itself.

jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-02 14:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 10:30 [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required Iain Sandoe
2024-02-02  0:07 ` Mike Stump
2024-02-02 14:16 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).