Re: [PATCH] Fix libcc1plugin and libc1plugin to avoid poisoned identifiers

2024-03-13 Thread Dimitry Andric
On 13 Mar 2024, at 12:30, Iain Sandoe  wrote:
> 
>> On 7 Mar 2024, at 16:48, Dimitry Andric  wrote:
>> 
>> Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632
>> 
>> Use INCLUDE_VECTOR before including system.h, instead of directly
>> including , to avoid running into poisoned identifiers.
> 
> I would say that the patch itself is obvious, but you have not mentioned how
> it was tested?

This was tested by doing a --disable-bootstrap build, on a FreeBSD
system where llvm-project's libc++ is the default C++ library
(specifically 15.0-CURRENT, which has llvm-project 17.0.6), against both
the lang/gcc14-devel port, and against gcc master as of
gcc-14-9346-g74e8cc28eda. This also required gcc-14-9360-g9970b576b7e to
be applied, before it was committed to master.

Note that if you do a fully bootstrapped build, there aren't any compile
errors, since it will compile the plugins against a freshly built
libstdc++: it has already transitively included  via other
standard headers, so the #include  statement after #include
"system.h" effectively does nothing, and won't run into poisoned
identifiers.

You would only get compile errors on those poisoned identifiers with the
non-bootstrapped, single-stage build which compiles everything against
the host system's C++ headers.

-Dimitry



[PATCH] Fix libcc1plugin and libc1plugin to avoid poisoned identifiers

2024-03-07 Thread Dimitry Andric
Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632

Use INCLUDE_VECTOR before including system.h, instead of directly
including , to avoid running into poisoned identifiers.

Signed-off-by: Dimitry Andric 
---
 libcc1/libcc1plugin.cc | 3 +--
 libcc1/libcp1plugin.cc | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index 72d17c3b81c..e64847466f4 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -32,6 +32,7 @@
 #undef PACKAGE_VERSION
 
 #define INCLUDE_MEMORY
+#define INCLUDE_VECTOR
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
@@ -69,8 +70,6 @@
 #include "gcc-c-interface.h"
 #include "context.hh"
 
-#include 
-
 using namespace cc1_plugin;
 
 
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 0eff7c68d29..da68c5d0ac1 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -33,6 +33,7 @@
 #undef PACKAGE_VERSION
 
 #define INCLUDE_MEMORY
+#define INCLUDE_VECTOR
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
@@ -71,8 +72,6 @@
 #include "rpc.hh"
 #include "context.hh"
 
-#include 
-
 using namespace cc1_plugin;
 
 
-- 
2.43.2



Re: [PATCH] Include safe-ctype.h after C++ standard headers, to avoid over-poisoning

2024-03-06 Thread Dimitry Andric
On 6 Mar 2024, at 15:57, FX Coudert  wrote:
> 
>> Hmm I recall trying it and finding a problem - was there some different fix 
>> applied
>> in the end?
> 
> The bug is still open, I don’t think a patch was applied, and I don’t find 
> any email to the list stating what the problem could be.

The original patch (https://gcc.gnu.org/bugzilla/attachment.cgi?id=56010) still 
applies to the master branch. It turned out there is also a related problem in 
libcc1plugin.cc and libcp1plugin.cc <http://libcp1plugin.cc/>, which is fixed 
by https://gcc.gnu.org/bugzilla/attachment.cgi?id=57639 :

commit 49222b98ac8e30a4a042ada0ece3d7df93f049d2
Author: Dimitry Andric 
Date:   2024-03-06T23:46:27+01:00

Fix libcc1plugin and libc1plugin to use INCLUDE_VECTOR before including
system.h, instead of directly including , to avoid running into
poisoned identifiers.

diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index 72d17c3b81c..e64847466f4 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -32,6 +32,7 @@
 #undef PACKAGE_VERSION
 
 #define INCLUDE_MEMORY
+#define INCLUDE_VECTOR
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
@@ -69,8 +70,6 @@
 #include "gcc-c-interface.h"
 #include "context.hh"
 
-#include 
-
 using namespace cc1_plugin;
 
 
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 0eff7c68d29..da68c5d0ac1 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -33,6 +33,7 @@
 #undef PACKAGE_VERSION
 
 #define INCLUDE_MEMORY
+#define INCLUDE_VECTOR
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
@@ -71,8 +72,6 @@
 #include "rpc.hh"
 #include "context.hh"
 
-#include 
-
 using namespace cc1_plugin;
 
 



[PING][PATCH] Include safe-ctype.h after C++ standard headers, to avoid over-poisoning

2023-10-26 Thread Dimitry Andric
Ping. It would be nice to get this QoL fix in.

-Dimitry

> On 28 Sep 2023, at 18:37, Dimitry Andric  wrote:
> 
> Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632
> 
> When building gcc's C++ sources against recent libc++, the poisoning of
> the ctype macros due to including safe-ctype.h before including C++
> standard headers such as , , etc, causes many compilation
> errors, similar to:
> 
> In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
> In file included from /home/dim/src/gcc/master/gcc/system.h:233:
> In file included from /usr/include/c++/v1/vector:321:
> In file included from
> /usr/include/c++/v1/__format/formatter_bool.h:20:
> In file included from
> /usr/include/c++/v1/__format/formatter_integral.h:32:
> In file included from /usr/include/c++/v1/locale:202:
> /usr/include/c++/v1/__locale:546:5: error: '__abi_tag__' attribute
> only applies to structs, variables, functions, and namespaces
>   546 | _LIBCPP_INLINE_VISIBILITY
>   | ^
> /usr/include/c++/v1/__config:813:37: note: expanded from macro
> '_LIBCPP_INLINE_VISIBILITY'
>   813 | #  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
>   | ^
> /usr/include/c++/v1/__config:792:26: note: expanded from macro
> '_LIBCPP_HIDE_FROM_ABI'
>   792 |
>   __attribute__((__abi_tag__(_LIBCPP_TOSTRING(
> _LIBCPP_VERSIONED_IDENTIFIER
>   |  ^
> In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
> In file included from /home/dim/src/gcc/master/gcc/system.h:233:
> In file included from /usr/include/c++/v1/vector:321:
> In file included from
> /usr/include/c++/v1/__format/formatter_bool.h:20:
> In file included from
> /usr/include/c++/v1/__format/formatter_integral.h:32:
> In file included from /usr/include/c++/v1/locale:202:
> /usr/include/c++/v1/__locale:547:37: error: expected ';' at end of
> declaration list
>   547 | char_type toupper(char_type __c) const
>   | ^
> /usr/include/c++/v1/__locale:553:48: error: too many arguments
> provided to function-like macro invocation
>   553 | const char_type* toupper(char_type* __low, const
>   char_type* __high) const
>   |^
> /home/dim/src/gcc/master/gcc/../include/safe-ctype.h:146:9: note:
> macro 'toupper' defined here
>   146 | #define toupper(c) do_not_use_toupper_with_safe_ctype
>   | ^
> 
> This is because libc++ uses different transitive includes than
> libstdc++, and some of those transitive includes pull in various ctype
> declarations (typically via ).
> 
> There was already a special case for including  before
> safe-ctype.h, so move the rest of the C++ standard header includes to
> the same location, to fix the problem.
> 
> Signed-off-by: Dimitry Andric 
> ---
> gcc/system.h | 39 ++-
> 1 file changed, 18 insertions(+), 21 deletions(-)
> 
> diff --git a/gcc/system.h b/gcc/system.h
> index e924152ad4c..7a516b11438 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...);
> #undef fread_unlocked
> #undef fwrite_unlocked
> 
> -/* Include  before "safe-ctype.h" to avoid GCC poisoning
> -   the ctype macros through safe-ctype.h */
> -
> -#ifdef __cplusplus
> -#ifdef INCLUDE_STRING
> -# include 
> -#endif
> -#endif
> -
> -/* There are an extraordinary number of issues with .
> -   The last straw is that it varies with the locale.  Use libiberty's
> -   replacement instead.  */
> -#include "safe-ctype.h"
> -
> -#include 
> -
> -#include 
> -
> -#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
> -extern int errno;
> -#endif
> +/* Include C++ standard headers before "safe-ctype.h" to avoid GCC
> +   poisoning the ctype macros through safe-ctype.h */
> 
> #ifdef __cplusplus
> #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY)
> @@ -229,6 +210,9 @@ extern int errno;
> #ifdef INCLUDE_SET
> # include 
> #endif
> +#ifdef INCLUDE_STRING
> +# include 
> +#endif
> #ifdef INCLUDE_VECTOR
> # include 
> #endif
> @@ -245,6 +229,19 @@ extern int errno;
> # include 
> #endif
> 
> +/* There are an extraordinary number of issues with .
> +   The last straw is that it varies with the locale.  Use libiberty's
> +   replacement instead.  */
> +#include "safe-ctype.h"
> +
> +#include 
> +
> +#include 
> +
> +#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
> +extern int errno;
> +#endif
> +
> /* Some of glibc's string inlines cause warnings.  Plus we'd rather
>   rely on (and therefore test) GCC's string builtins.  */
> #define __NO_STRING_INLINES
> -- 
> 2.42.0
> 



[PATCH] Include safe-ctype.h after C++ standard headers, to avoid over-poisoning

2023-09-28 Thread Dimitry Andric
Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632

When building gcc's C++ sources against recent libc++, the poisoning of
the ctype macros due to including safe-ctype.h before including C++
standard headers such as , , etc, causes many compilation
errors, similar to:

 In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
 In file included from /home/dim/src/gcc/master/gcc/system.h:233:
 In file included from /usr/include/c++/v1/vector:321:
 In file included from
 /usr/include/c++/v1/__format/formatter_bool.h:20:
 In file included from
 /usr/include/c++/v1/__format/formatter_integral.h:32:
 In file included from /usr/include/c++/v1/locale:202:
 /usr/include/c++/v1/__locale:546:5: error: '__abi_tag__' attribute
 only applies to structs, variables, functions, and namespaces
   546 | _LIBCPP_INLINE_VISIBILITY
   | ^
 /usr/include/c++/v1/__config:813:37: note: expanded from macro
 '_LIBCPP_INLINE_VISIBILITY'
   813 | #  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
   | ^
 /usr/include/c++/v1/__config:792:26: note: expanded from macro
 '_LIBCPP_HIDE_FROM_ABI'
   792 |
   __attribute__((__abi_tag__(_LIBCPP_TOSTRING(
 _LIBCPP_VERSIONED_IDENTIFIER
   |  ^
 In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
 In file included from /home/dim/src/gcc/master/gcc/system.h:233:
 In file included from /usr/include/c++/v1/vector:321:
 In file included from
 /usr/include/c++/v1/__format/formatter_bool.h:20:
 In file included from
 /usr/include/c++/v1/__format/formatter_integral.h:32:
 In file included from /usr/include/c++/v1/locale:202:
 /usr/include/c++/v1/__locale:547:37: error: expected ';' at end of
 declaration list
   547 | char_type toupper(char_type __c) const
   | ^
 /usr/include/c++/v1/__locale:553:48: error: too many arguments
 provided to function-like macro invocation
   553 | const char_type* toupper(char_type* __low, const
   char_type* __high) const
   |^
 /home/dim/src/gcc/master/gcc/../include/safe-ctype.h:146:9: note:
 macro 'toupper' defined here
   146 | #define toupper(c) do_not_use_toupper_with_safe_ctype
   | ^

This is because libc++ uses different transitive includes than
libstdc++, and some of those transitive includes pull in various ctype
declarations (typically via ).

There was already a special case for including  before
safe-ctype.h, so move the rest of the C++ standard header includes to
the same location, to fix the problem.

Signed-off-by: Dimitry Andric 
---
gcc/system.h | 39 ++-
1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/gcc/system.h b/gcc/system.h
index e924152ad4c..7a516b11438 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...);
#undef fread_unlocked
#undef fwrite_unlocked

-/* Include  before "safe-ctype.h" to avoid GCC poisoning
-   the ctype macros through safe-ctype.h */
-
-#ifdef __cplusplus
-#ifdef INCLUDE_STRING
-# include 
-#endif
-#endif
-
-/* There are an extraordinary number of issues with .
-   The last straw is that it varies with the locale.  Use libiberty's
-   replacement instead.  */
-#include "safe-ctype.h"
-
-#include 
-
-#include 
-
-#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
-extern int errno;
-#endif
+/* Include C++ standard headers before "safe-ctype.h" to avoid GCC
+   poisoning the ctype macros through safe-ctype.h */

#ifdef __cplusplus
#if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY)
@@ -229,6 +210,9 @@ extern int errno;
#ifdef INCLUDE_SET
# include 
#endif
+#ifdef INCLUDE_STRING
+# include 
+#endif
#ifdef INCLUDE_VECTOR
# include 
#endif
@@ -245,6 +229,19 @@ extern int errno;
# include 
#endif

+/* There are an extraordinary number of issues with .
+   The last straw is that it varies with the locale.  Use libiberty's
+   replacement instead.  */
+#include "safe-ctype.h"
+
+#include 
+
+#include 
+
+#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
+extern int errno;
+#endif
+
/* Some of glibc's string inlines cause warnings.  Plus we'd rather
   rely on (and therefore test) GCC's string builtins.  */
#define __NO_STRING_INLINES
-- 
2.42.0



Re: [PATCH] Fix gcc-5-branch build with libc++

2017-01-31 Thread Dimitry Andric
On 01 Feb 2017, at 01:23, David Edelsohn  wrote:
...
>> In trunk r235362, most gcc C++ sources were updated to define
>> INCLUDE_xxx macros before including gcc/system.h, which fixes the
>> incompatibility with libc++.  However, this revision is most likely too
>> disruptive to backport to the gcc-5-branch.
> 
> As discussed in the thread to define INCLUDE_xxx macros, no headers
> may be included before GCC system.h because it breaks the GCC build on
> some systems.

Ah, sorry about that.  I was completely unaware about this thread.


> Anyone who suggested to the FreeBSD community that it would be
> acceptable to include C++ headers early was severely mistaken.  Sorry.

There was no suggestion, I'm the only one to blame. :)  That said, for
the FreeBSD port this patch doesn't seem to cause any further trouble.
So Gerald has accepted it as a stopgap measure for fixing the port.

-Dimitry



signature.asc
Description: Message signed with OpenPGP using GPGMail


[PATCH] Fix gcc-5-branch build with libc++

2017-01-31 Thread Dimitry Andric
As discussed with the FreeBSD gcc ports maintainer, building the
gcc-5-branch with libc++ requires standard C++ headers to be included
*before* gcc/system.h, otherwise the redefinition of abort() to
fancy_abort() will cause trouble.

In trunk r235362, most gcc C++ sources were updated to define
INCLUDE_xxx macros before including gcc/system.h, which fixes the
incompatibility with libc++.  However, this revision is most likely too
disruptive to backport to the gcc-5-branch.

Attached is the patch which has been used in the FreeBSD gcc5 port (see
also https://bugs.freebsd.org/216266 ).  Proposed ChangeLog entry:

2017-01-31  Dimitry Andric <d...@freebsd.org>

* system.h: For C++, always include .
* graphite-isl-ast-to-gimple.c: Include standard C++ headers before
system.h.
* auto-profile.c: Likewise.  Also remove string.h, since it is already
included in system.h.

-Dimitry


gcc5-cxx-includes-1.diff
Description: Binary data


signature.asc
Description: Message signed with OpenPGP using GPGMail


[PATCH] Use INCLUDE_xxx macros in gcov.c for pulling in standard C++ headers

2017-01-21 Thread Dimitry Andric
As discussed with the FreeBSD gcc ports maintainer [1], building trunk
gcc with libc++ requires standard C++ headers to be included *before*
gcc/system.h, otherwise the redefinition of abort() to fancy_abort()
will cause trouble.

In r235362, most gcc C++ sources were updated to define INCLUDE_xxx
macros before including gcc/system.h, which fixes the incompatibility
with libc++.  However, gcc/gcov.c was apparently missed.  Attached is a
patch to update it.

-Dimitry

[1] https://bugs.freebsd.org/216303


gcc-gcov-std-header-usage-1.diff
Description: Binary data


signature.asc
Description: Message signed with OpenPGP using GPGMail