From patchwork Tue Jan 30 10:30:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 193972 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1121902dyb; Tue, 30 Jan 2024 02:31:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRob+Tb+vfe4FHWxYcM5PJljFyRbeciV0xA/4RgGs0HJJa+HlTuGfpvKiULKxSm425Ugmu X-Received: by 2002:a05:622a:610:b0:42a:9bc9:b8f2 with SMTP id z16-20020a05622a061000b0042a9bc9b8f2mr7251874qta.115.1706610674138; Tue, 30 Jan 2024 02:31:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706610674; cv=pass; d=google.com; s=arc-20160816; b=VqMmZYcjFF8nDS1ApGNawQUnpcnt+5JpcS7wJvMJ5bBbl/J2ICJmtLyb+y7TN4Sssi Ss9NUd10r55DfxOfDXU3Q9gU71Vn2cYFw9a3Kg0x56QfQWnQz6qRTwlJnxOo+28Nmtli oEI623ftvWSBEf1MloMOds7tjDIY9ABlmS6r+5CI1NNBQo6Zai64rLzJyv5CWxyfdINa oLo9oAX9i8uJ/FA3XZMnGnoMlFXkf1mgr+9dAOp/7Dw7e64kFYQILKNNrmpNDjUUhYjB b+qqtswPkgpruKmhewkHpAQzfMP7d1M+eEr/wRulm7NkyARrSE9jr+sXp6eSh3px64PQ rrww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=IqnBiQFpO4ct3dLSVnKGXBz/3E0M4yqjcwPMTe3uwWQ=; fh=HpGyPhETBvl4zejgufl7c2nTNpZufIxjdWMis6jurMQ=; b=LhOn5Oj8OOEMVLDba5XKQMJszG1wUoqroE6QsX/h+IFqzwrG7Eva5UklYndeDd9NCe UGvQ2X65N40UclX7xnQSROyA0YdXDZ1+3cle7TN+5oBTFyk3mw8rRDVcogasSEIAcqhB pQZ7f0JsYsp4gouzI2lO/4ZljgHd+pfzuKy+iaSTUut/kHmTMf86G3ByZA11k8mg0O2L M34XZ/gHYopFzKuzfroozXpmIyALX9WbIhgBJ4yRbeyESUtsJDaE7AcWdHcJDWldcwvS Kxgg6Ag6vCAqLcCLDgDbSREJPqbrTOdIJu62R9Au7AsjdIjH0oNW47Fghn5pbdmzRs3K 8z7A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ONKKBrPJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k15-20020a05622a03cf00b0042a1115649dsi9695887qtx.211.2024.01.30.02.31.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:31:14 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ONKKBrPJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1E563858295 for ; Tue, 30 Jan 2024 10:31:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id A82E1385801A for ; Tue, 30 Jan 2024 10:30:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A82E1385801A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A82E1385801A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706610621; cv=none; b=MJcN73wQH8y6UJfHIqSUadL1vO6r7yHKnEjFVbOJvtGacUKNQM9U/YRuvDlXIPd/o7dX1ywnHfY1CbjcFVP/7PGJu/PqYLy3nZ1hlSK0dZikAXIKiUd3alSAJroZUWcXUWdfa3EJLyZGE/1UqjVMJ+fbS/fjInTlViECJ5fBfpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706610621; c=relaxed/simple; bh=0c8AwlF1zp+dIcYcbsjCe/BiJFCakeDbTnmwYmag9cg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ZwCekjA4tnVqMNuqeVBeRB+iypVSMefCXOo1yAt4C0mpxMfT0OANvclpu55F881x8m69ljTN0zPIegG5XRNHUO2l+X0hwWgazaQjdbwYK0qt0wnmWW3kjqYCDLhzra6wpsAr+P7HZOtGbYmiOUvgbN8tHTCKsJfoxO0qpMqYnfU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-50eac018059so4392089e87.0 for ; Tue, 30 Jan 2024 02:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706610617; x=1707215417; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=IqnBiQFpO4ct3dLSVnKGXBz/3E0M4yqjcwPMTe3uwWQ=; b=ONKKBrPJANp9Dfy/KLO68nPxSUHd+zftOviKmdnPChgUjXZHen28h+uvNHE0m9kpGz RW9W+EPgRKB04kcVE8+i4J1lNem2vV6EAVEvcdQqphQA61GV4wXzGDCUb6yjDXttTPmh 2ihdqouyLPAhWfj5Pb+XFjqo84r61r+HrKmQkxeeqHB6yT1vZfILucAUwku5i+h8G1oc pFqJDyf3qvUyEa+4KlE/N8VqinicC/mNpezdGP3Cxulfs4ao3wZtnOSAc7dix7eTmPDM lMHPu/d3KthTpJ+DpWbY09hvqPlNBYQVZZvYvVVFipkf2IzTcnTm/SogGMUMqrpcPJNp +0Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706610617; x=1707215417; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IqnBiQFpO4ct3dLSVnKGXBz/3E0M4yqjcwPMTe3uwWQ=; b=pmrbL+vl8/NYnnZxBuxvUP14NRecxBwV9cYxu70tMMO+aDTttXRTqmnxJU7C5rfu7k 0xc6e6y9AQ9honBw4pw6FOAeJ1BAW3Nsr7dP2hWNIJqRwoc992tFqfki+tRon2r6Oe0K 0Lbu1yuKsN4+mqQXw6t0xHK2tz3MCxsQ9r6tM154zMcXdn2Vu0E1S350hyZE9wQbiVlw DC3zYME+5MjFaZ673yYSA7e4XJ9GOzHmdFR8ceEGycly7dIBZqBe8GysQ4cl/dZQ4D3c 816858M5yZbTMeCLfO04FoEdHKC74g8zyc3sdpML1PzpNeE/8bbO2AqL92Aa2eU55LFX YwRg== X-Gm-Message-State: AOJu0Yx+sXc/wjbLK0VSo9V4HyrftYJTqHWnBrhry6syqaqFSP8aChVh lOf2byhzr+tD16cXj93WdFoIQs7m3bj32uuvCwRcKgvh85R6OdrraoP1c5ZJ X-Received: by 2002:a05:6512:4010:b0:511:f2c:a63f with SMTP id br16-20020a056512401000b005110f2ca63fmr4837585lfb.26.1706610616726; Tue, 30 Jan 2024 02:30:16 -0800 (PST) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id k26-20020a05600c1c9a00b0040ef79b2fa6sm5049711wms.33.2024.01.30.02.30.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 30 Jan 2024 02:30:16 -0800 (PST) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: ro@CeBiTec.Uni-Bielefeld.DE Subject: [PATCH] testsuite, asan, hwsan: Add libstdc++ deps where required. Date: Tue, 30 Jan 2024 10:30:15 +0000 Message-Id: <20240130103015.1845-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789510994278206892 X-GMAIL-MSGID: 1789510994278206892 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]" } }