Re: [PATCH] Introduce -nolibstdc++ option

2023-04-05 Thread Alexandre Oliva via Gcc-patches
On Mar 30, 2023, Gerald Pfeifer  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ć  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?

-- 
Alexandre Oliva, happy hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2023-03-30 Thread Gerald Pfeifer
On Thu, 30 Mar 2023, Alexandre Oliva wrote:
> How about this, does this seem useful?

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

Gerald


Re: [PATCH] Introduce -nolibstdc++ option

2023-03-30 Thread Arsen Arsenović via Gcc-patches
Hi Alexandre,

Alexandre Oliva via Gcc-patches  writes:

> Hello, Gerald,
>
> On Feb 11, 2023, Gerald Pfeifer  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 gcc to link your
  application with only libsupc++.a,
  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.
>The  href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wpessimizing-move;>-Wpessimizing-move
>  and  href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wredundant-move;>-Wredundant-move
>  warnings have been extended to warn in more contexts.
> +  The  href="https://gcc.gnu.org/onlinedocs/gcc/Link_Options.html#index-nostdlib_002b_002b;>-nostdlib++
> +option has been added, to enable linking with g++
> +without implicitly linking in the C++ standard library.
>  
>  
>  Runtime Library (libstdc++)


-- 
Arsen Arsenović


signature.asc
Description: PGP signature


Re: [PATCH] Introduce -nolibstdc++ option

2023-03-30 Thread Alexandre Oliva via Gcc-patches
Hello, Gerald,

On Feb 11, 2023, Gerald Pfeifer  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.
   The https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wpessimizing-move;>-Wpessimizing-move
 and https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wredundant-move;>-Wredundant-move
 warnings have been extended to warn in more contexts.
+  The https://gcc.gnu.org/onlinedocs/gcc/Link_Options.html#index-nostdlib_002b_002b;>-nostdlib++
+option has been added, to enable linking with g++
+without implicitly linking in the C++ standard library.
 
 
 Runtime Library (libstdc++)


-- 
Alexandre Oliva, happy hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2023-02-11 Thread Gerald Pfeifer
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


Re: [PATCH] Introduce -nolibstdc++ option

2022-11-28 Thread Jason Merrill via Gcc-patches

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  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:


From 0e74112cf494c93f170739b87ecc89b2d5d97f92 Mon Sep 17 00:00:00 2001
From: Jason Merrill 
Date: Sun, 27 Nov 2022 14:30:14 -0500
Subject: [PATCH] driver: fix validate_switches logic
To: gcc-patches@gcc.gnu.org

Under the old logic for validate_switches, once suffix or starred got set,
they stayed set for all later switches found in the spec.  So for e.g.

%{g*:%{%:debug-level-gt(0):

Once we see g*, starred is set.  Then we see %:, and it sees that as a
zero-length switch, which because starred is still set, matches any and all
command-line options.  So targets that use such a spec accept all options in
the driver, while ones that don't reject some, such as the recent
-nostdlib++.

This patch fixes the inconsistency, so all targets reject -nostdlib++.

gcc/ChangeLog:

	* gcc.cc (validate_switches): Reset suffix/starred on loop.
---
 gcc/gcc.cc | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index ca1c9e27a94..2278e2b6bb1 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -9299,12 +9299,15 @@ validate_switches (const char *start, bool user_spec, bool braced)
   const char *atom;
   size_t len;
   int i;
-  bool suffix = false;
-  bool starred = false;
+  bool suffix;
+  bool starred;
 
 #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
 
 next_member:
+  suffix = false;
+  starred = false;
+
   SKIP_WHITE ();
 
   if (*p == '!')
-- 
2.31.1



Re: [PATCH] Introduce -nolibstdc++ option

2022-09-16 Thread Jason Merrill via Gcc-patches

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




Re: [PATCH] Introduce -nolibstdc++ option

2022-09-16 Thread Jason Merrill via Gcc-patches

On 6/24/22 01:23, Alexandre Oliva via Gcc-patches wrote:

On Jun 23, 2022, Alexandre Oliva  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?From e648ff579bb4b4a690553d4c6f4a3a1b7ff7a287 Mon Sep 17 00:00:00 2001
From: Jason Merrill 
Date: Fri, 16 Sep 2022 13:51:49 +0200
Subject: [PATCH] c++: fix -nostdlib++
To: gcc-patches@gcc.gnu.org

gcc/cp/ChangeLog:

	* g++spec.cc (lang_specific_driver): Set SKIPOPT on -nostdlib++.
---
 gcc/cp/g++spec.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
index b63d8350ba1..31345f7869e 100644
--- a/gcc/cp/g++spec.cc
+++ b/gcc/cp/g++spec.cc
@@ -158,8 +158,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
 
   switch (decoded_options[i].opt_index)
 	{
-	case OPT_nostdlib:
 	case OPT_nostdlib__:
+	  args[i] |= SKIPOPT;
+	  /* FALLTHRU */
+	case OPT_nostdlib:
 	case OPT_nodefaultlibs:
 	  library = -1;
 	  break;
-- 
2.31.1



Re: [PATCH] Introduce -nolibstdc++ option

2022-06-23 Thread Alexandre Oliva via Gcc-patches
On Jun 23, 2022, Alexandre Oliva  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.

-- 
Alexandre Oliva, happy hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-23 Thread Alexandre Oliva via Gcc-patches
On Jun 22, 2022, Alexandre Oliva  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   Place output into .
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 hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-22 Thread Fangrui Song via Gcc-patches
On Wed, Jun 22, 2022 at 4:29 PM Alexandre Oliva  wrote:
>
> On Jun 22, 2022, Iain Sandoe  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 hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-22 Thread Alexandre Oliva via Gcc-patches
On Jun 22, 2022, Iain Sandoe  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++.

-- 
Alexandre Oliva, happy hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-22 Thread Iain Sandoe via Gcc-patches



> On 22 Jun 2022, at 01:36, Alexandre Oliva via Gcc-patches 
>  wrote:
> 
> On Jun 21, 2022, Fangrui Song  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 hackerhttps://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 



Re: [PATCH] Introduce -nolibstdc++ option

2022-06-21 Thread Alexandre Oliva via Gcc-patches
On Jun 21, 2022, Fangrui Song  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.

-- 
Alexandre Oliva, happy hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-21 Thread Fangrui Song via Gcc-patches

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 hackerhttps://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 

Re: [PATCH] Introduce -nolibstdc++ option

2022-06-21 Thread Richard Biener via Gcc-patches
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.

> > >
> > > 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 hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-21 Thread Fangrui Song via Gcc-patches
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++.

> >
> > 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 hackerhttps://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 


Re: [PATCH] Introduce -nolibstdc++ option

2022-06-21 Thread Richard Biener via Gcc-patches
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.

>
> 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 hackerhttps://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