public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8754] testsuite, asan, hwsan: Add libstdc++ deps where required.
@ 2024-02-02 15:45 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2024-02-02 15:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a6afa0d06b0559b22be829ff197495d5c8653b96

commit r14-8754-ga6afa0d06b0559b22be829ff197495d5c8653b96
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Jan 26 15:22:44 2024 +0000

    testsuite, asan, hwsan: Add libstdc++ deps where required.
    
    We use the shared asan/hwasan rom 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.

Diff:
---
 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 9297bb55eb1b..f078bc378009 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 597033e01d57..12a7a3570a06 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 10c69731fbf8..6b8ebf07eaef 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 802f17122962..88327d3b223c 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 72b36696c4de..89c6bf35ae4f 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 25cd19f61338..a1576381e614 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 beb49e500eb9..6bd3c211611a 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 8d66b4db3e39..33c9a7ce2745 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]"
 	}
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-02 15:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 15:45 [gcc r14-8754] testsuite, asan, hwsan: Add libstdc++ deps where required Iain D Sandoe

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).