diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2024-01-26 15:22:44 +0000 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2024-02-02 15:45:47 +0000 |
commit | a6afa0d06b0559b22be829ff197495d5c8653b96 (patch) | |
tree | 850654223600448d4ded5d453b15d3b638b2cef2 /gcc | |
parent | 2c27aa8d75113f404bf9cd39364611af386d9719 (diff) | |
download | gcc-a6afa0d06b0559b22be829ff197495d5c8653b96.zip gcc-a6afa0d06b0559b22be829ff197495d5c8653b96.tar.gz gcc-a6afa0d06b0559b22be829ff197495d5c8653b96.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/g++.dg/asan/asan.exp | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/hwasan/hwasan.exp | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/asan.exp | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/hwasan/hwasan.exp | 3 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/asan/asan.exp | 3 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/asan/asan.exp | 3 | ||||
-rw-r--r-- | gcc/testsuite/lib/asan-dg.exp | 21 | ||||
-rw-r--r-- | 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 9297bb5..f078bc3 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 597033e..12a7a35 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 10c6973..6b8ebf0 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 802f171..88327d3 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 72b3669..89c6bf3 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 25cd19f..a157638 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 beb49e5..6bd3c21 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 8d66b4d..33c9a7c 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]" } } |