From patchwork Sun Dec 4 16:30:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 61464 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A3CB38493E5 for ; Sun, 4 Dec 2022 16:31:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A3CB38493E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670171483; bh=XA/ZF2qWQAHMVsv52shXUcAJ434RLGclW/UsTNl9XMk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Y2HznjskvwJ3QHxIZMtzgr6F2GRMiHx6lRKgBg06x3Ch+CC59iwjBhuVrYR3NLAcU 18qKjcJnta8/R+VfhvF1WmC01kWysrU7GuSTrkcgzcAvDO56OVlZ0/vZWNd4I7/6I/ XMkyNuzjdBiXgR1FrIDkJyW/cd5o1wmvXZkXLsB8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id B3AB838493E6 for ; Sun, 4 Dec 2022 16:30:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B3AB838493E6 Received: by mail-wm1-x335.google.com with SMTP id ay27-20020a05600c1e1b00b003d070f4060bso8250289wmb.2 for ; Sun, 04 Dec 2022 08:30:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=XA/ZF2qWQAHMVsv52shXUcAJ434RLGclW/UsTNl9XMk=; b=LWnkde8ouVV8DZCk/tEcuky+aCM4Vo+Bq871eUAzq3U2HUVS6inZ5KxVlTbKsdawFR BEQDhEiDf6JWbVUk0tG1LZtQzbWEapbTnYkYb5Tmjt/7iNEv2CvGahxt98PLaeYwENay nX/mrbkqW/3SIJK8E5WKAjJTXnZE0rn4SWVdsWKccnlImuO96GEH2CDIm4WIoTJ+6x05 5XXJT/e/nQQYM4ecaBsVnHaon0jpnE7trwOswsEqtPjBkTkFAJi61aSi97TQXpVL7QDs apBkK3pk24ARlLF8Is18dIf4UOem4E6ZV8xBbj4jhRi518itIp/WTLo2czH5cNZ8FGQA Byhg== X-Gm-Message-State: ANoB5pnRAgVLe6VqJziKZuMlWW+srteO7AoVBV68DjtHxBlrajrAmQPf PyjGPdX7WT7/gLl05T5KI6DOw+Rs3+8= X-Google-Smtp-Source: AA0mqf7Tu/nnDE7+BWI/lq5eLdsdM7clHl6is1PaBIouqQ89ywZYYa9CYEKKLHg0dpfOMSAO8mOFNw== X-Received: by 2002:a05:600c:3b0c:b0:3cf:8df2:63b7 with SMTP id m12-20020a05600c3b0c00b003cf8df263b7mr43460134wms.11.1670171448452; Sun, 04 Dec 2022 08:30:48 -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 p15-20020a05600c358f00b003c6b874a0dfsm20664558wmq.14.2022.12.04.08.30.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 04 Dec 2022 08:30:48 -0800 (PST) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic. Date: Sun, 4 Dec 2022 16:30:47 +0000 Message-Id: <20221204163047.72124-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 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 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , jason@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This fixes a long-standing problem on Darwin where we cannot independently set -static-libstdc++ because the flag gets stripped by the g++ driver. This patch is essentially the same as the one used for the 'D' driver and has been in local use for some time. It has also been tested on Linux. OK for master? backports? thanks Iain -- >8 -- The current implementation for swapping between the static and shared c++ runtimes relies on the static linker supporting Bstatic/dynamic which is not available for every target (Darwin's linker does not support this). Specs substitution (%s) is an alternative solution for this (which is what Darwin uses for Fortran, D and Objective-C). However, specs substitution requires that the '-static-libstdc++' be preserved in the driver's command line. The patch here arranges for this to be done when the configuration determines that linker support for Bstatic/dynamic is missing. Signed-off-by: Iain Sandoe gcc/cp/ChangeLog: * g++spec.cc (lang_specific_driver): Preserve -static-libstdc++ in the driver command line for targets without -Bstatic/dynamic support in their static linker. --- gcc/cp/g++spec.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc index 3d3b042dd56..f95d7965355 100644 --- a/gcc/cp/g++spec.cc +++ b/gcc/cp/g++spec.cc @@ -234,7 +234,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, case OPT_static_libstdc__: library = library >= 0 ? 2 : library; +#ifdef HAVE_LD_STATIC_DYNAMIC + /* Remove -static-libstdc++ from the command only if target supports + LD_STATIC_DYNAMIC. When not supported, it is left in so that a + back-end target can use outfile substitution. */ args[i] |= SKIPOPT; +#endif break; case OPT_stdlib_: