]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Introduce -nostdlib++ option
authorAlexandre Oliva <oliva@adacore.com>
Fri, 24 Jun 2022 02:20:48 +0000 (23:20 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 24 Jun 2022 02:25:52 +0000 (23:25 -0300)
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
gcc/cp/g++spec.cc
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/abi/pure-virtual1.C

index ed50f77848ddda18bad13a37543bf7370f130522..e7a51e882bade3bbf7681d0448c75fb1a3d4ba05 100644 (file)
@@ -3467,6 +3467,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>.
index 8174d652776b1913a5ff661996796b786a910eb7..b63d8350ba113d7eec4b10cb0847a84dcbc73a48 100644 (file)
@@ -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;
index 07a1bf40ad942ddd9dcd973c3eb052931391ca9e..f794edd49e11f03ebfa89cda2bcc13943f42756b 100644 (file)
@@ -653,7 +653,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
@@ -16846,6 +16846,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
index 538e2cb097a0db871b95fc1d1a0b8ac38aef32b1..59eaf22562049e9bed90e68dd4c3ac41f23ccf6d 100644 (file)
@@ -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* } }