From patchwork Tue Jan 30 10:31:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 193973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1122532dyb; Tue, 30 Jan 2024 02:32:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfU3jeZuhw4gjBPsZ2MNn6gpwDZ7K+wwAYg5upQK8rzrqtzikEu1MNgYp3xRHqHkbXy/9W X-Received: by 2002:a05:6122:251b:b0:4bd:6e14:f1fd with SMTP id cl27-20020a056122251b00b004bd6e14f1fdmr4067229vkb.13.1706610769285; Tue, 30 Jan 2024 02:32:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706610769; cv=pass; d=google.com; s=arc-20160816; b=OGdE4v4FAc49CgNCc863hug7rvAD3AXAGeZdJRu65E3HvTrv/FRqWxOX0KsKCz0pFu z83QMZDgBAv519EZQxtehW2PSLVyVXWGyOY1O7d4VTiBvLn0EwICabNYLju3J6aEL1Gj /zUOdXneNJZ27UAfPIcxvfFUpl7uCqx5yWlFVrSoiWxTuVqplti9Bt/1ufwI/9mxdn6S yDQHUD6agdoYjCRfL2x/PIY7DI1DBxts4VHrLr1kPZEff7Po4oNlLLoITuqQvJVY6tUj FugmRznGB8zxd3GhUf9CIFFn9JRi+2GzOJs9K38duvNUq7XYBhDOTMpG4i+zWCUer/Dl s+6w== 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=rL7J/tNvjTk05v4wHZy0qYw6tlAGUSyxd6dFwo59hd8=; fh=HpGyPhETBvl4zejgufl7c2nTNpZufIxjdWMis6jurMQ=; b=JkmEdnQPfdgMeUGyBv5EqvIv3pgjGDyPeH1M8eDJQuhm6Z49qVevQWdREdi1tFHDkI +x5jersCDDCvlKG2HmBj5O0+LPHXhZ9HfMe8r2peBKIDN47zOsyMqpMf5fKMX/oF/zrP Ns2aK1aY6PTHWqoTQh3E3Udmtf1FJ2q+rsvqj62h5RoRiFakJs2xG/dlqetMqEB/9igs ItuCLaATqV50VA8SqASHqyB1/5ipCJddaCM8yda5PeMxzOrtBl0QDGRU+j4NziYwSgns ahjq4OhYlKUzJ1nsaU9u9s4bYljNCVOWaHfHRsT04yKrNDq+OeuckPNgllR78tcbvBT3 8iQw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CnXf+Tld; 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 ge9-20020a05621427c900b00681935c784asi9491526qvb.606.2024.01.30.02.32.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:32:49 -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=CnXf+Tld; 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 055373858296 for ; Tue, 30 Jan 2024 10:32:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id EF9BA3858437 for ; Tue, 30 Jan 2024 10:31:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF9BA3858437 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 EF9BA3858437 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706610700; cv=none; b=LDtBv0qnuOPCihZ3SXtHWivb7dvmRjR1JgMIOaCch5PfcI7WvFpuNaAvS6kG3T74xU9A4ziW5JlaKgDfACqgEUUhiDo/N3muvJXxOnhWXxxZXzETf0hyUKF7hwaZoPNsivUQjHHstNPn3i2O1cEvhnht0ji0XA4JIWJfi3w2EM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706610700; c=relaxed/simple; bh=3infbgx4LoOF1KFd5R6/gsnrfHyCYResQQW9MdPteC8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=rGmqYiYO6xhvlia2fxQpFlwELODmo5m44QescdASolwz6UXAzY/1uC9Edzz/r84q54Jb2bjwou3E8EfMaXP+Q2MIB9URSfaXJc3o0h02DB13H+um6+Od8cmXs9SIFI/54VjfzDn/uI77TbAEVp1P24IqJE+q3WUer9GssJKReTg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40f02b8d150so3505965e9.2 for ; Tue, 30 Jan 2024 02:31:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706610696; x=1707215496; 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=rL7J/tNvjTk05v4wHZy0qYw6tlAGUSyxd6dFwo59hd8=; b=CnXf+TldPChQu/NrYEqsQOKQPyae1+8MsDzSyLoEMjqVwZknucWGCXl8DwuF43dBPp vLVAxVgVsODejB/Ja8+BcD87o0qhv8M9F/hxTmfDDva7poP3v8c4PL21qPqPkghgEdOk XWKPZjpgcYGWj+wzDmfAKWCZTBno0vLpbUNnyLZiE1i1SmEHsM+yx4PKffMCKBL8OdFb aWuX73TOofR5wlCut992J5mzn7eH93Niqr28aYutRLSZQcwiRnXuaI5wy6Z1RBs755mn sLEdR9J/VhHwgoKpQr+PqhuxgR0xyVisteDvIeypfNWNWcFFZphhWkl4d9Yt/PJMtpwV 4BRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706610696; x=1707215496; 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=rL7J/tNvjTk05v4wHZy0qYw6tlAGUSyxd6dFwo59hd8=; b=nSvXyR6d/x+4PuUFm6STMLcxmZOyB9/fvtO3iq+k5VRz6TVYcszJ2kRefJ9PWeRTwQ S0KD3hhA99HpK1Ruo3qpHOOhE/7Wi3Fxwebn4xzPeiXgJ9lO4w9WFKQdflgbfmpc21ZH asnAnTRsldd7REGCqhhIBJnfZmHr7dO5hwlUbsjSu3LxF8ihbBnRYgvv6VJziKDoKU9b zuzcPtYcTUUOVXehQXnhWlYxvLE3Uw8nsWrzIk/IlmgNSAgb4RzLuFzTDhQ1spK2bF1E kvgIqtpZW3uQi8OnJJf2sAGMA7rK/kvb1DIL/ldEF3G6ACLDUdsTosx6REVbzJZ1Qdq6 3GnQ== X-Gm-Message-State: AOJu0YzJtODwHCqahhLHQclPzcbD09HHb1dXxBNG+5HoDOHeM0qalwrs Wiwvdm7ie3CdKhWr7G9Ik6vLNPnCEbocDPH4gp/MBYWMcurOlAH/BkuOLZMr X-Received: by 2002:a05:600c:1c14:b0:40e:fa4b:d567 with SMTP id j20-20020a05600c1c1400b0040efa4bd567mr2968979wms.37.1706610696391; Tue, 30 Jan 2024 02:31:36 -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 o4-20020a05600c510400b0040ef7186b7esm5470790wms.29.2024.01.30.02.31.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 30 Jan 2024 02:31:36 -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, ubsan: Add libstdc++ deps where required. Date: Tue, 30 Jan 2024 10:31:35 +0000 Message-Id: <20240130103135.2005-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: 1789511094028508416 X-GMAIL-MSGID: 1789511094028508416 tested on i686, x86_64 (and aarch64) Darwin, x86_64, aarch64 Linux, OK for trunk? thanks Iain --- 8< --- We use the ubsan tests 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 sigle 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/ubsan/ubsan.exp:Add a parameter to init to say that we expect the C++ driver to provide paths for libstdc++. * gcc.dg/ubsan/ubsan.exp: Add a parameter to init to say that we need a path added for libstdc++. * gdc.dg/ubsan/ubsan.exp: Likewise. * gfortran.dg/ubsan/ubsan.exp: Likewise. * lib/ubsan-dg.exp: Handle a single parameter to init that requests addition of a path to libstdc++ to link flags. --- gcc/testsuite/g++.dg/ubsan/ubsan.exp | 3 ++- gcc/testsuite/gcc.dg/ubsan/ubsan.exp | 3 ++- gcc/testsuite/gdc.dg/ubsan/ubsan.exp | 3 ++- gcc/testsuite/gfortran.dg/ubsan/ubsan.exp | 4 ++-- gcc/testsuite/lib/ubsan-dg.exp | 20 +++++++++++++++----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/g++.dg/ubsan/ubsan.exp b/gcc/testsuite/g++.dg/ubsan/ubsan.exp index d7197070a92..4bab1b83de9 100644 --- a/gcc/testsuite/g++.dg/ubsan/ubsan.exp +++ b/gcc/testsuite/g++.dg/ubsan/ubsan.exp @@ -22,7 +22,8 @@ load_lib ubsan-dg.exp # Initialize `dg'. dg-init -ubsan_init +# libubsan uses libstdc++ but we assume that's added by the g++ impl. +ubsan_init 0 # Main loop. if [check_effective_target_fsanitize_undefined] { diff --git a/gcc/testsuite/gcc.dg/ubsan/ubsan.exp b/gcc/testsuite/gcc.dg/ubsan/ubsan.exp index 84170495e28..560e5843be6 100644 --- a/gcc/testsuite/gcc.dg/ubsan/ubsan.exp +++ b/gcc/testsuite/gcc.dg/ubsan/ubsan.exp @@ -24,7 +24,8 @@ load_lib ubsan-dg.exp # Initialize `dg'. dg-init -ubsan_init +# libubsan uses libstdc++ so make sure we provide paths for it. +ubsan_init 1 # Main loop. if [check_effective_target_fsanitize_undefined] { diff --git a/gcc/testsuite/gdc.dg/ubsan/ubsan.exp b/gcc/testsuite/gdc.dg/ubsan/ubsan.exp index 6ad665a1a8d..7613a3b487c 100644 --- a/gcc/testsuite/gdc.dg/ubsan/ubsan.exp +++ b/gcc/testsuite/gdc.dg/ubsan/ubsan.exp @@ -20,7 +20,8 @@ load_lib ubsan-dg.exp # Initialize `dg'. dg-init -ubsan_init +# libubsan uses libstdc++ so make sure we provide paths for it. +ubsan_init 1 # Main loop. if [check_effective_target_fsanitize_undefined] { diff --git a/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp b/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp index 0c61153e68b..b2360785e6c 100644 --- a/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp +++ b/gcc/testsuite/gfortran.dg/ubsan/ubsan.exp @@ -22,10 +22,10 @@ load_lib gfortran-dg.exp load_lib ubsan-dg.exp - # Initialize `dg'. dg-init -ubsan_init +# libubsan uses libstdc++ so make sure we provide paths for it. +ubsan_init 1 # Main loop. if [check_effective_target_fsanitize_undefined] { diff --git a/gcc/testsuite/lib/ubsan-dg.exp b/gcc/testsuite/lib/ubsan-dg.exp index 108b9980cac..860e78f3975 100644 --- a/gcc/testsuite/lib/ubsan-dg.exp +++ b/gcc/testsuite/lib/ubsan-dg.exp @@ -31,7 +31,7 @@ proc check_effective_target_fsanitize_undefined {} { # (originally from g++.exp) # -proc ubsan_link_flags { paths } { +proc ubsan_link_flags { paths needs_cxx } { global srcdir global ld_library_path global shlib_ext @@ -43,15 +43,24 @@ proc ubsan_link_flags { paths } { set shlib_ext [get_shlib_extension] set ubsan_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/ubsan/.libs/libubsan.a"] || [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } { append flags " -B${gccpath}/libsanitizer/ " append flags " -B${gccpath}/libsanitizer/ubsan/ " - append flags " -L${gccpath}/libsanitizer/ubsan/.libs" + append flags " -B${gccpath}/libsanitizer/ubsan/.libs" append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs" - append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs" } + # libasan links to libstdc++, so we must include it for C testcases. + if { $needs_cxx && ( [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 @@ -79,6 +88,7 @@ proc ubsan_init { args } { global ubsan_saved_ALWAYS_CXXFLAGS global orig_ubsan_options_saved global orig_ubsan_options + set needs_cxx [lindex $args 0] if { $orig_ubsan_options_saved == 0 } { # Save the original environment. @@ -92,9 +102,9 @@ proc ubsan_init { args } { set link_flags "" if ![is_remote host] { if [info exists TOOL_OPTIONS] { - set link_flags "[ubsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]" + set link_flags "[ubsan_link_flags [get_multilibs ${TOOL_OPTIONS}] $needs_cxx]" } else { - set link_flags "[ubsan_link_flags [get_multilibs]]" + set link_flags "[ubsan_link_flags [get_multilibs] $needs_cxx]" } }