]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite, asan, hwsan: Add libstdc++ deps where required.
authorIain Sandoe <iain@sandoe.co.uk>
Fri, 26 Jan 2024 15:22:44 +0000 (15:22 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 2 Feb 2024 15:45:47 +0000 (15:45 +0000)
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.

gcc/testsuite/g++.dg/asan/asan.exp
gcc/testsuite/g++.dg/hwasan/hwasan.exp
gcc/testsuite/gcc.dg/asan/asan.exp
gcc/testsuite/gcc.dg/hwasan/hwasan.exp
gcc/testsuite/gdc.dg/asan/asan.exp
gcc/testsuite/gfortran.dg/asan/asan.exp
gcc/testsuite/lib/asan-dg.exp
gcc/testsuite/lib/hwasan-dg.exp

index 9297bb55eb1bdc4a224fcfe00daad5a9c74c4334..f078bc3780097377b9773ffbc6efa1ed9dd93d73 100644 (file)
@@ -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] {
index 597033e01d5793a6916b03de180b754bd11fae6c..12a7a3570a0607b538477d513570ae0630e31fa4 100644 (file)
@@ -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] {
index 10c69731fbf8480c307da4b81f006e1008e83ceb..6b8ebf07eaef917d050bba6f5d1476734ae7bbfc 100644 (file)
@@ -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] {
index 802f17122962a2361ca456d49a6f79e744fba2c1..88327d3b223c2f50a1b5974ff7acebbee512ded2 100644 (file)
@@ -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] {
index 72b36696c4de0238b7501bae6b41859fefdc37f8..89c6bf35ae4f7254e56cef4cd255c8bcf624fbe8 100644 (file)
@@ -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] {
index 25cd19f613389a08d5f781434162543f315a9491..a1576381e614675e8ac54fb1844190664c7d094e 100644 (file)
@@ -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] {
index beb49e500eb96b76a20fc953c77a32b75603e773..6bd3c211611a2f40b50ec733fa38e342f5096d26 100644 (file)
@@ -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]"
        }
     }
 
index 8d66b4db3e39b0047d0e68383b5dc0b6dc0d1766..33c9a7ce2745d9e1949c922af8d6df9e38831ce9 100644 (file)
@@ -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]"
        }
     }