From patchwork Tue Jun 21 05:55:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 55222 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 B6EB4383F952 for ; Tue, 21 Jun 2022 05:56:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6EB4383F952 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655790968; bh=ZWbczYJlwlwuP0/V6qy925owjhHOirFgymLMhkyYekc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=xDvohw3shDJk/Vshn5mUXVsvhvJPyr5/r8S1f3DCvuyK/nf38huNgKX3czwv7EZjP 3GT+GVM7RPgKTH4oQUkPjoCGa56tqnX7tm/o69N/KxQr7j+ApWv3llGqBOOUsx9q4s edRrGSp+PddYjMaqlWvwdsKBAWFYXdc6Zn8JsKeE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id 86517384144C for ; Tue, 21 Jun 2022 05:55:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 86517384144C Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 429ED1160D9; Tue, 21 Jun 2022 01:55:39 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id EDZOqmPm9EC1; Tue, 21 Jun 2022 01:55:39 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id C5B7E1160D8; Tue, 21 Jun 2022 01:55:38 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 25L5tQjW693393 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jun 2022 02:55:26 -0300 To: gcc-patches@gcc.gnu.org Subject: [PATCH] Introduce -nolibstdc++ option Organization: Free thinker, does not speak for AdaCore Date: Tue, 21 Jun 2022 02:55:26 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Cc: Joseph Myers , Nathan Sidwell Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Using g++ to link without libstdc++, as in g++.dg/abi/pure-virtual1.C, is error prone, because there's no way to tell g++ to drop libstdc++ without also dropping libc and any other libraries that the target implicitly links in. This has often led to the need for manual adjustments to this testcase. I figured adding support for -nolibstdc++, even though redundant, makes some sense. One could presumably use gcc rather than g++ for linking, for the same effect, but sometimes changing the link command is harder than adding an option, as in our testsuite. Regstrapped on x86_64-linux-gnu, also tested with a cross to aarch64-rtems6. Ok to install? for gcc/ChangeLog * common.opt (nolibstdc++): New. * doc/invoke.texi (-nolibstdc++): Document it. for gcc/cp/ChangeLog * g++spec.c (lang_specific_driver): Implement -nolibstdc++. for gcc/testsuite/ChangeLog * g++.dg/abi/pure-virtual1.C: Use -nolibstdc++. --- gcc/common.opt | 3 +++ gcc/cp/g++spec.cc | 1 + gcc/doc/invoke.texi | 6 +++++- gcc/testsuite/g++.dg/abi/pure-virtual1.C | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 32917aafcaec1..e00c6fc2fb098 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3456,6 +3456,9 @@ Driver nolibc Driver +nolibstdc++ +Driver + nostdlib Driver diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc index 8174d652776b1..539e6ca089d85 100644 --- a/gcc/cp/g++spec.cc +++ b/gcc/cp/g++spec.cc @@ -160,6 +160,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, { case OPT_nostdlib: case OPT_nodefaultlibs: + case OPT_nolibstdc__: library = -1; break; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 50f57877477bc..469b6d97e0dfa 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -652,7 +652,7 @@ Objective-C and Objective-C++ Dialects}. @item Linker Options @xref{Link Options,,Options for Linking}. @gccoptlist{@var{object-file-name} -fuse-ld=@var{linker} -l@var{library} @gol --nostartfiles -nodefaultlibs -nolibc -nostdlib @gol +-nostartfiles -nodefaultlibs -nolibc -nolibstdc++ -nostdlib @gol -e @var{entry} --entry=@var{entry} @gol -pie -pthread -r -rdynamic @gol -s -static -static-pie -static-libgcc -static-libstdc++ @gol @@ -16787,6 +16787,10 @@ absence of a C library is assumed, for example @option{-lpthread} or @option{-lm} in some configurations. This is intended for bare-board targets when there is indeed no C library available. +@item -nolibstdc++ +@opindex nolibstdc++ +Do not link with standard C++ libraries implicitly. + @item -nostdlib @opindex nostdlib Do not use the standard system startup files or libraries when linking. diff --git a/gcc/testsuite/g++.dg/abi/pure-virtual1.C b/gcc/testsuite/g++.dg/abi/pure-virtual1.C index 538e2cb097a0d..889c33e4952f4 100644 --- a/gcc/testsuite/g++.dg/abi/pure-virtual1.C +++ b/gcc/testsuite/g++.dg/abi/pure-virtual1.C @@ -1,7 +1,7 @@ // Test that we don't need libsupc++ just for __cxa_pure_virtual. // { dg-do link } // { dg-require-weak } -// { dg-additional-options "-fno-rtti -nodefaultlibs -lc" } +// { dg-additional-options "-fno-rtti -nolibstdc++" } // { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } // { dg-xfail-if "AIX weak" { powerpc-ibm-aix* } }