From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AGHT+IH+JRCoUPr9f96hgnPe+o0TP8ULO52gr2jj0zCAUoyKmKp0Pjb3EdMREDIzaVqAfEqsV6ptmg== 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) Reply-To: iain@sandoe.co.uk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 List-Id: 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]" } } -- 2.39.2 (Apple Git-143)