public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@adacore.com>
To: Iain Sandoe <idsandoe@googlemail.com>
Cc: Fangrui Song <maskray@google.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	 Nathan Sidwell <nathan@acm.org>,
	Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH] Introduce -nolibstdc++ option
Date: Thu, 23 Jun 2022 08:27:20 -0300	[thread overview]
Message-ID: <orilor4o2v.fsf@lxoliva.fsfla.org> (raw)
In-Reply-To: <or35fw8eh4.fsf@lxoliva.fsfla.org> (Alexandre Oliva's message of "Wed, 22 Jun 2022 20:28:55 -0300")

On Jun 22, 2022, Alexandre Oliva <oliva@adacore.com> wrote:

> Yeah, I suppose that makes sense, it's beneficial for users to avoid the
> cognitive overload of dealing with equivalent options with different
> spellings.  I'll swallow my dislike for the spelling and change the
> patch to use -nostdlib++.

Here's the patch.  Regstrapped on x86_64-linux-gnu, also tested with a
cross to aarch64-rtems6.  Ok to install?


Introduce -nostdlib++ option

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 -nostdlib++, 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.

Since clang already had an option with this effect, we've adopted the
same spelling.


for  gcc/ChangeLog

	* common.opt (nostdlib++): New.
	* doc/invoke.texi (-nostdlib++): Document it.

for  gcc/cp/ChangeLog

	* g++spec.cc (lang_specific_driver): Implement -nostdlib++.

for  gcc/testsuite/ChangeLog

	* g++.dg/abi/pure-virtual1.C: Use -nostdlib++.
---
 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..0845e083247af 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3459,6 +3459,9 @@ Driver
 nostdlib
 Driver
 
+nostdlib++
+Driver
+
 o
 Common Driver Joined Separate Var(asm_file_name) MissingArgError(missing filename after %qs)
 -o <file>	Place output into <file>.
diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
index 8174d652776b1..b63d8350ba113 100644
--- a/gcc/cp/g++spec.cc
+++ b/gcc/cp/g++spec.cc
@@ -159,6 +159,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
       switch (decoded_options[i].opt_index)
 	{
 	case OPT_nostdlib:
+	case OPT_nostdlib__:
 	case OPT_nodefaultlibs:
 	  library = -1;
 	  break;
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fb506364702b7..a7ab29335c84a 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  -nostdlib  -nostdlib++ @gol
 -e @var{entry}  --entry=@var{entry} @gol
 -pie  -pthread  -r  -rdynamic @gol
 -s  -static  -static-pie  -static-libgcc  -static-libstdc++ @gol
@@ -16822,6 +16822,10 @@ library subroutines.
 constructors are called; @pxref{Collect2,,@code{collect2}, gccint,
 GNU Compiler Collection (GCC) Internals}.)
 
+@item -nostdlib++
+@opindex nostdlib++
+Do not implicitly link with standard C++ libraries.
+
 @item -e @var{entry}
 @itemx --entry=@var{entry}
 @opindex e
diff --git a/gcc/testsuite/g++.dg/abi/pure-virtual1.C b/gcc/testsuite/g++.dg/abi/pure-virtual1.C
index 538e2cb097a0d..59eaf22562049 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 -nostdlib++" }
 // { 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 <https://stallmansupport.org>

  parent reply	other threads:[~2022-06-23 11:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  5:55 Alexandre Oliva
2022-06-21  7:37 ` Richard Biener
2022-06-21  7:53   ` Fangrui Song
2022-06-21  8:03     ` Richard Biener
2022-06-21  8:19       ` Fangrui Song
2022-06-22  0:36     ` Alexandre Oliva
2022-06-22 18:39       ` Iain Sandoe
2022-06-22 23:28         ` Alexandre Oliva
2022-06-22 23:42           ` Fangrui Song
2022-06-23 11:27           ` Alexandre Oliva [this message]
2022-06-24  5:23             ` Alexandre Oliva
2022-09-16 11:52               ` Jason Merrill
2022-09-16 11:53                 ` Jason Merrill
2022-11-28 17:56                 ` Jason Merrill
2023-02-11  9:09             ` Gerald Pfeifer
2023-03-30 11:23               ` Alexandre Oliva
2023-03-30 13:38                 ` Arsen Arsenović
2023-03-30 23:13                 ` Gerald Pfeifer
2023-04-06  1:25                   ` Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=orilor4o2v.fsf@lxoliva.fsfla.org \
    --to=oliva@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=idsandoe@googlemail.com \
    --cc=joseph@codesourcery.com \
    --cc=maskray@google.com \
    --cc=nathan@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).