From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 823D7383EC53 for ; Tue, 21 Jun 2022 08:19:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 823D7383EC53 Received: by mail-pg1-x52d.google.com with SMTP id a14so2828956pgh.11 for ; Tue, 21 Jun 2022 01:19:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4W8/sLth/VM8AsMnkv/dNU5Pa5RNrfKDuqw3xYhtN1M=; b=ieIYmO5uLfllGcQZFlgobd9H+jVGD99oWdDj1HyfTdGPeZzVwgcF/EJjD9VN9A2h4r eH4eC0U2NKp+eaHc6nzzelK01zpSyaCBJ7oEiA9SAMqM5inKTKjp2Lbtzk16DzoFgE1R DtAHsSTGwuYzHlIsM6ddS5AJvgdhdVl5c60JqyIET6bTyPHu8/a2w/ifG/oyyxjyxlSu LIuWBp/TKdujPab/POYOJhN8cihwUd1+XKrelfSifO+4NuIXA3aRpwVOiyzWn66SX8Ki Ah/bmc/WTNV0B3/vtYKPEdBGS/wx2aqBcAY0ONrRYGzoGVFUTvbhIG1Steo3KFjTLvua rPMw== X-Gm-Message-State: AJIora8PWcu817r6eV9yG54CCVbegsjZ4y5v57xJ3fhZHUdaRy5rWv0b SHQeKdjsO8vjZ3Fi7xC6mCeZ2Q== X-Google-Smtp-Source: AGRyM1tufWyp+e0zCZM4w59ErvwKKKsy8rurdsbzVx3A0GqS0HAFChQheDeZJRLRopD74XDdAJxxXg== X-Received: by 2002:a63:3308:0:b0:40c:7cb4:fe05 with SMTP id z8-20020a633308000000b0040c7cb4fe05mr14197100pgz.604.1655799555190; Tue, 21 Jun 2022 01:19:15 -0700 (PDT) Received: from google.com ([2620:15c:2ce:200:dadc:57f8:ff13:8776]) by smtp.gmail.com with ESMTPSA id y9-20020a17090abd0900b001ec8c8300f8sm5679964pjr.52.2022.06.21.01.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 01:19:14 -0700 (PDT) Date: Tue, 21 Jun 2022 01:19:11 -0700 From: Fangrui Song To: Richard Biener Cc: Alexandre Oliva , GCC Patches , Nathan Sidwell , Joseph Myers Subject: Re: [PATCH] Introduce -nolibstdc++ option Message-ID: <20220621081911.fvwzqbmprnglnt4y@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-27.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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-List-Received-Date: Tue, 21 Jun 2022 08:19:18 -0000 On 2022-06-21, Richard Biener wrote: >On Tue, Jun 21, 2022 at 9:53 AM Fangrui Song wrote: >> >> On Tue, Jun 21, 2022 at 1:43 AM Richard Biener via Gcc-patches >> wrote: >> > >> > On Tue, Jun 21, 2022 at 7:56 AM Alexandre Oliva via Gcc-patches >> > wrote: >> > > >> > > >> > > 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? >> > >> > OK in case nobody objects in 24h. >> > >> > Richard. >> >> Is this similar to clang -nostdlib++ ? >> When libstdc++ is selected, clang -nostdlib++ removes -lstdc++. > >Probably. Note that we have -static-libstdc++ already so >-nolibstdc++ matches that. We also have -nolibc, not -noclib. > >Richard. I think the relation between -static-foo and -nofoo is not that large. -nostdlib does not have a corresponding -static-stdlib. Note that gcc has supported -stdlib=libc++ since 2020-12, though the usage is a bit tricky. Having a C++ standard library agnostic name helps libc++:) For -lc, clang has -nolibc. >> > > >> > > 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* } } >> > > >> > > >> > > -- >> > > Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ >> > > Free Software Activist GNU Toolchain Engineer >> > > Disinformation flourishes because many people care deeply about injustice >> > > but very few check the facts. Ask me about