Introduce -nolibstdc++ option

Message ID orpmj2d0hd.fsf@lxoliva.fsfla.org
State Committed
Headers
Series Introduce -nolibstdc++ option |

Commit Message

Alexandre Oliva June 21, 2022, 5:55 a.m. UTC
  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(-)
  

Comments

Richard Biener June 21, 2022, 7:37 a.m. UTC | #1
On Tue, Jun 21, 2022 at 7:56 AM Alexandre Oliva via Gcc-patches
<gcc-patches@gcc.gnu.org> 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.

>
> 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 <https://stallmansupport.org>
  
Fangrui Song June 21, 2022, 7:53 a.m. UTC | #2
On Tue, Jun 21, 2022 at 1:43 AM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Tue, Jun 21, 2022 at 7:56 AM Alexandre Oliva via Gcc-patches
> <gcc-patches@gcc.gnu.org> 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++.

> >
> > 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 <https://stallmansupport.org>
  
Richard Biener June 21, 2022, 8:03 a.m. UTC | #3
On Tue, Jun 21, 2022 at 9:53 AM Fangrui Song <maskray@google.com> wrote:
>
> On Tue, Jun 21, 2022 at 1:43 AM Richard Biener via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > On Tue, Jun 21, 2022 at 7:56 AM Alexandre Oliva via Gcc-patches
> > <gcc-patches@gcc.gnu.org> 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.

> > >
> > > 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 <https://stallmansupport.org>
  
Fangrui Song June 21, 2022, 8:19 a.m. UTC | #4
On 2022-06-21, Richard Biener wrote:
>On Tue, Jun 21, 2022 at 9:53 AM Fangrui Song <maskray@google.com> wrote:
>>
>> On Tue, Jun 21, 2022 at 1:43 AM Richard Biener via Gcc-patches
>> <gcc-patches@gcc.gnu.org> wrote:
>> >
>> > On Tue, Jun 21, 2022 at 7:56 AM Alexandre Oliva via Gcc-patches
>> > <gcc-patches@gcc.gnu.org> 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 <https://stallmansupport.org>
  
Alexandre Oliva June 22, 2022, 12:36 a.m. UTC | #5
On Jun 21, 2022, Fangrui Song <maskray@google.com> wrote:

> Is this similar to clang -nostdlib++ ?
> When libstdc++ is selected, clang -nostdlib++ removes -lstdc++.

Sounds like they're the same indeed, but the clang option you mention
makes little sense to me, so I'd rather to introduce the one that does.
If someone feels offering this option with the same spelling as clang,
it's easy enough to add a synonym.  Now, if others feel we'd be better
off following clang's practices, I don't mind adjusting the patch to use
the same spelling.  It's not like this option is going to have much use
one way or another, aside from this testcase.
  
Iain Sandoe June 22, 2022, 6:39 p.m. UTC | #6
> On 22 Jun 2022, at 01:36, Alexandre Oliva via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> On Jun 21, 2022, Fangrui Song <maskray@google.com> wrote:
> 
>> Is this similar to clang -nostdlib++ ?
>> When libstdc++ is selected, clang -nostdlib++ removes -lstdc++.
> 
> Sounds like they're the same indeed, but the clang option you mention
> makes little sense to me, so I'd rather to introduce the one that does.
> If someone feels offering this option with the same spelling as clang,
> it's easy enough to add a synonym.  Now, if others feel we'd be better
> off following clang's practices, I don't mind adjusting the patch to use
> the same spelling.  It's not like this option is going to have much use
> one way or another, aside from this testcase.

we have nostdlib, nodefaultlibs (which also omit the C++ libs)

It makes some sense to have the option named -nostdlib++ if a target
might add multiple libs (and/or make other changes) for linking C++.

(so, fo example, if libstdc++ were separate from libsupc++ I would
 expect your use-case to wish to exclude both, not just libstdc++)?

From the PoV of users and build systems, it’s also helpful to avoid
proliferating option names unless there’s some clear distinction in function
between compilers - if GCC already has an option spelling, usually
clang would follow that - it does not seem unreasonable to reciprocate.

0.02GBP only, of course,
Iain

> 
> -- 
> 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>
  
Alexandre Oliva June 22, 2022, 11:28 p.m. UTC | #7
On Jun 22, 2022, Iain Sandoe <idsandoe@googlemail.com> wrote:

> It makes some sense to have the option named -nostdlib++ if a target
> might add multiple libs (and/or make other changes) for linking C++.

if it was nostdlibc++, I'd agree.  lib++ is not something that brings
C++ to (my) mind.

> (so, fo example, if libstdc++ were separate from libsupc++ I would
>  expect your use-case to wish to exclude both, not just libstdc++)?

That's what the testcase requires, yes.  IIRC there's another that would
benefit from the ability to link with libsupc++, but not with libstdc++.

> if GCC already has an option spelling, usually clang would follow that
> - it does not seem unreasonable to reciprocate.

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++.
  
Fangrui Song June 22, 2022, 11:42 p.m. UTC | #8
On Wed, Jun 22, 2022 at 4:29 PM Alexandre Oliva <oliva@adacore.com> wrote:
>
> On Jun 22, 2022, Iain Sandoe <idsandoe@googlemail.com> wrote:
>
> > It makes some sense to have the option named -nostdlib++ if a target
> > might add multiple libs (and/or make other changes) for linking C++.
>
> if it was nostdlibc++, I'd agree.  lib++ is not something that brings
> C++ to (my) mind.

Agree that clang --stdlib= and -nostdlib++ probably should be better
named. There are many
standard libraries and "stdlib" as a name isn't tied to C++ much.
That said, --stdlib= has a very long history and seems not so
necessary to change now.
For new Clang driver options (I subscribe to clang/lib/Driver files to
try catching up the change),
I try to keep an eye on and for something useful which may be matched by GCC,
I'll notify some GCC folks I know (e.g. Nathan, Martin).

> > (so, fo example, if libstdc++ were separate from libsupc++ I would
> >  expect your use-case to wish to exclude both, not just libstdc++)?
>
> That's what the testcase requires, yes.  IIRC there's another that would
> benefit from the ability to link with libsupc++, but not with libstdc++.
>
> > if GCC already has an option spelling, usually clang would follow that
> > - it does not seem unreasonable to reciprocate.

Thanks.

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

Thanks:)

BTW: even if -static-libstdc++ is a bit of misnomer when a clang user
uses libc++,
since -static-libc++ or -static-stdlib does not exist, they are still
using -static-libstdc++.

> --
> 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>
  
Alexandre Oliva June 23, 2022, 11:27 a.m. UTC | #9
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 June 24, 2022, 5:23 a.m. UTC | #10
On Jun 23, 2022, Alexandre Oliva <oliva@adacore.com> wrote:

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

> Introduce -nostdlib++ option

Uhh, I went ahead and installed this.  The earlier patch was approved if
nobody objected, and so, having overcome the objection to the option
spelling, it ended up in my "approved" patchset.

In case there are objections to it, please let me know, and I'll revert
it promptly, but I guess it makes little sense to revert it on the odd
change that someone does.  Thanks for your understanding.
  
Jason Merrill Sept. 16, 2022, 11:52 a.m. UTC | #11
On 6/24/22 01:23, Alexandre Oliva via Gcc-patches wrote:
> On Jun 23, 2022, Alexandre Oliva <oliva@adacore.com> wrote:
> 
>> Here's the patch.  Regstrapped on x86_64-linux-gnu, also tested with a
>> cross to aarch64-rtems6.  Ok to install?
> 
>> Introduce -nostdlib++ option
> 
> Uhh, I went ahead and installed this.  The earlier patch was approved if
> nobody objected, and so, having overcome the objection to the option
> spelling, it ended up in my "approved" patchset.
> 
> In case there are objections to it, please let me know, and I'll revert
> it promptly, but I guess it makes little sense to revert it on the odd
> change that someone does.  Thanks for your understanding.

I'm getting failures from pure-virtual1.C with

xg++: error: unrecognized command-line option '-nostdlib++'

I guess that's because it isn't handled by the specs in the way nostdlib 
and nodefautlibs are.  Maybe the solution is to set SKIPOPT in the driver?

Are you not seeing this problem?
  
Jason Merrill Sept. 16, 2022, 11:53 a.m. UTC | #12
On 9/16/22 07:52, Jason Merrill wrote:
> On 6/24/22 01:23, Alexandre Oliva via Gcc-patches wrote:
>> On Jun 23, 2022, Alexandre Oliva <oliva@adacore.com> wrote:
>>
>>> Here's the patch.  Regstrapped on x86_64-linux-gnu, also tested with a
>>> cross to aarch64-rtems6.  Ok to install?
>>
>>> Introduce -nostdlib++ option
>>
>> Uhh, I went ahead and installed this.  The earlier patch was approved if
>> nobody objected, and so, having overcome the objection to the option
>> spelling, it ended up in my "approved" patchset.
>>
>> In case there are objections to it, please let me know, and I'll revert
>> it promptly, but I guess it makes little sense to revert it on the odd
>> change that someone does.  Thanks for your understanding.
> 
> I'm getting failures from pure-virtual1.C with
> 
> xg++: error: unrecognized command-line option '-nostdlib++'
> 
> I guess that's because it isn't handled by the specs in the way nostdlib 
> and nodefautlibs are.  Maybe the solution is to set SKIPOPT in the driver?
> 
> Are you not seeing this problem?

Now of course I notice that it's been months since you installed the 
patch, I wonder what broke it...
  
Jason Merrill Nov. 28, 2022, 5:56 p.m. UTC | #13
On 9/16/22 07:52, Jason Merrill wrote:
> On 6/24/22 01:23, Alexandre Oliva via Gcc-patches wrote:
>> On Jun 23, 2022, Alexandre Oliva <oliva@adacore.com> wrote:
>>
>>> Here's the patch.  Regstrapped on x86_64-linux-gnu, also tested with a
>>> cross to aarch64-rtems6.  Ok to install?
>>
>>> Introduce -nostdlib++ option
>>
>> Uhh, I went ahead and installed this.  The earlier patch was approved if
>> nobody objected, and so, having overcome the objection to the option
>> spelling, it ended up in my "approved" patchset.
>>
>> In case there are objections to it, please let me know, and I'll revert
>> it promptly, but I guess it makes little sense to revert it on the odd
>> change that someone does.  Thanks for your understanding.
> 
> I'm getting failures from pure-virtual1.C with
> 
> xg++: error: unrecognized command-line option '-nostdlib++'
> 
> I guess that's because it isn't handled by the specs in the way nostdlib 
> and nodefautlibs are.  Maybe the solution is to set SKIPOPT in the driver?
> 
> Are you not seeing this problem?

I started seeing this again and decided to track it down more.  It seems 
to be dependent on specs, as explained in this commit message:
  
Gerald Pfeifer Feb. 11, 2023, 9:09 a.m. UTC | #14
On Thu, 23 Jun 2022, Alexandre Oliva via Gcc-patches wrote:
> 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.

% grep -r nostdlib $WWWDOCS
%

Should this be documented in gcc-13/changes.html? Would you mind proposing 
a snippet (or going ahead and pushing it)?

Gerald
  
Alexandre Oliva March 30, 2023, 11:23 a.m. UTC | #15
Hello, Gerald,

On Feb 11, 2023, Gerald Pfeifer <gerald@pfeifer.com> wrote:

> On Thu, 23 Jun 2022, Alexandre Oliva via Gcc-patches wrote:
>> 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.

> % grep -r nostdlib $WWWDOCS
> %

> Should this be documented in gcc-13/changes.html? Would you mind proposing 
> a snippet (or going ahead and pushing it)?

I can't make my mind up about this.

At first, the goal of adding the option was just to aid this specific
test.  But then, it transpired that other compilers offered a similar
option, with the spelling that we ended up using, so perhaps it would
make sense to document it, after all.

How about this, does this seem useful?

diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
index ff70d2eefecec..c1bbbfa28e18e 100644
--- a/htdocs/gcc-13/changes.html
+++ b/htdocs/gcc-13/changes.html
@@ -333,6 +333,9 @@ a work-in-progress.</p>
   <li>The <a href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wpessimizing-move"><code>-Wpessimizing-move</code></a>
     and <a href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wredundant-move"><code>-Wredundant-move</code></a>
     warnings have been extended to warn in more contexts.</li>
+  <li>The <a href="https://gcc.gnu.org/onlinedocs/gcc/Link_Options.html#index-nostdlib_002b_002b"><code>-nostdlib++</code></a>
+    option has been added, to enable linking with <code>g++</code>
+    without implicitly linking in the C++ standard library.</li>
 </ul>
 
 <h4 id="libstdcxx">Runtime Library (libstdc++)</h4>
  
Arsen Arsenović March 30, 2023, 1:38 p.m. UTC | #16
Hi Alexandre,

Alexandre Oliva via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

> Hello, Gerald,
>
> On Feb 11, 2023, Gerald Pfeifer <gerald@pfeifer.com> wrote:
>
>> On Thu, 23 Jun 2022, Alexandre Oliva via Gcc-patches wrote:
>>> 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.
>
>> % grep -r nostdlib $WWWDOCS
>> %
>
>> Should this be documented in gcc-13/changes.html? Would you mind proposing 
>> a snippet (or going ahead and pushing it)?
>
> I can't make my mind up about this.
>
> At first, the goal of adding the option was just to aid this specific
> test.  But then, it transpired that other compilers offered a similar
> option, with the spelling that we ended up using, so perhaps it would
> make sense to document it, after all.

IMO, yes - in fact, the libstdc++ manual even has a use-case for this
(freestanding when the compiler is *not* built with libstdc++ in
freestanding mode) and documents using the gcc driver rather than the
g++ one.  See libstdc++-v3/doc/xml/manual/using.xml:

  If you're using a libstdc++ configured for hosted environments, and
  would like to not involve the libraries libstdc++ would depend on in
  your programs, you will need to use <command>gcc</command> to link your
  application with only <filename class="libraryfile">libsupc++.a</filename>,
  like so:

If you think the flag you added fits here, would you mind also including
this file in your patch?

Note that this flag is only applicable here if MATH_LIBRARY is omitted
but libsupc++.a is kept on the linker command line (apologies for
not checking ahead of writing this email - I'm not currently in a
convenient spot to do so).

Thanks in advance, have a lovely day.

> How about this, does this seem useful?
>
> diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
> index ff70d2eefecec..c1bbbfa28e18e 100644
> --- a/htdocs/gcc-13/changes.html
> +++ b/htdocs/gcc-13/changes.html
> @@ -333,6 +333,9 @@ a work-in-progress.</p>
>    <li>The <a href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wpessimizing-move"><code>-Wpessimizing-move</code></a>
>      and <a href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wredundant-move"><code>-Wredundant-move</code></a>
>      warnings have been extended to warn in more contexts.</li>
> +  <li>The <a href="https://gcc.gnu.org/onlinedocs/gcc/Link_Options.html#index-nostdlib_002b_002b"><code>-nostdlib++</code></a>
> +    option has been added, to enable linking with <code>g++</code>
> +    without implicitly linking in the C++ standard library.</li>
>  </ul>
>  
>  <h4 id="libstdcxx">Runtime Library (libstdc++)</h4>
  
Gerald Pfeifer March 30, 2023, 11:13 p.m. UTC | #17
On Thu, 30 Mar 2023, Alexandre Oliva wrote:
> How about this, does this seem useful?

I like it - helpful and easy to understand. :-)

Gerald
  
Alexandre Oliva April 6, 2023, 1:25 a.m. UTC | #18
On Mar 30, 2023, Gerald Pfeifer <gerald@pfeifer.com> wrote:

> On Thu, 30 Mar 2023, Alexandre Oliva wrote:
>> How about this, does this seem useful?

> I like it - helpful and easy to understand. :-)

'k, I'm putting it in, thanks


On Mar 30, 2023, Arsen Arsenović <arsen@aarsen.me> wrote:

> IMO, yes - in fact, the libstdc++ manual even has a use-case for this

Yeah, and it also had the means to accomplish that already.  -nostdlib++
was for the testsuite, that always uses g++ for linking C++ tests.

I suppose libstdc++ now has an alternative it might consider switching
to, namely using g++ -nostdlib++ rather than gcc to link itself, but
should it?  I don't see the upside.  Its build process is not broken,
it's not even inconvenient, so what's the expected benefit that the
change would bring about?  As for downsides, I perceive risks of build
scripts (e.g. libtool)'s not yet having support for -nostdlib++, and
thus trying to use the flag could break rather than improve the state of
affairs.  It feels like inviting trouble to me.

> If you think the flag you added fits here, would you mind also including
> this file in your patch?

The patch was for the online release documentation, it's not even the
same repository as libstdc++, so there's no way to add it to the same
patch.

Given that, and since I'm not so sure I understand what change you're
suggesting to libstdc++'s manual or build procedures, how about you
give it a shot yourself?
  

Patch

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* } }