Bug 274042 - lang/gcc8 lang/gcc9: fix build with libc++ 17
Summary: lang/gcc8 lang/gcc9: fix build with libc++ 17
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks: 273753
  Show dependency treegraph
 
Reported: 2023-09-23 07:53 UTC by Dimitry Andric
Modified: 2023-10-06 17:56 UTC (History)
4 users (show)

See Also:
salvadore: maintainer-feedback+


Attachments
lang/gcc8: fix build with libc++ 17 (1.34 KB, patch)
2023-09-23 07:57 UTC, Dimitry Andric
no flags Details | Diff
lang/gcc9: fix build with libc++ 17 (1.34 KB, patch)
2023-09-23 07:57 UTC, Dimitry Andric
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2023-09-23 07:53:44 UTC
When building relatively recent gcc ports (with C++ in them) against libc++ 17, you get errors similar to:

In file included from /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/cp/module.cc:208:
In file included from /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/system.h:239:
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 /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/cp/module.cc:208:
In file included from /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/system.h:239:
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
      |                                                ^
/wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/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 gcc/system.h includes safe-ctype.h which redefines ctype macros such as toupper, tolower, etc to "poison" them.

However, it should only include the safe-ctype.h header *after* any C++ headers, such as <list>, <map>, <string>, etc, otherwise these might transitively include internal ctype headers (such as with libc++ 17), causing the above conflicts.

Here is a patch that moves the safe-ctype.h inclusion to later in gcc/system.h, which solves this issue, and makes it possible to build against libc++ 17.
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2023-09-23 07:57:37 UTC
Created attachment 245145 [details]
lang/gcc8: fix build with libc++ 17
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2023-09-23 07:57:53 UTC
Created attachment 245146 [details]
lang/gcc9: fix build with libc++ 17
Comment 3 Mark Millard 2023-09-23 14:57:33 UTC
The summary mentions gcc8 and gcc9 but the description's example is
gcc12?
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2023-09-23 16:10:43 UTC
(In reply to Mark Millard from comment #3)
Yeah sorry, I copy/pasted the same description to a number of different gcc reports, but the error is similar in all those cases. I submitted bugs for each different MAINTAINER field, but ideally I'd have all lumped them together in one huge "fix all gcc's" bug. :)
Comment 5 Lorenzo Salvadore freebsd_committer freebsd_triage 2023-09-25 09:52:38 UTC
Assuming that you have tested those patches, I approve them, but please wait for an additional review from Gerald, past maintainer of the GCC ports. In particular, Gerald, do you think these patches can be easily upstreamed? Would another solution be preferable?

Also please note that both ports are deprecated and will expire in Summer 2024.
Comment 6 Gerald Pfeifer freebsd_committer freebsd_triage 2023-09-26 05:14:57 UTC
See my response in
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274041#c11

Given these two ports are end of life upstream and they aren't really
used any longer in FreeBSD land (except for a stray port or two and 
retro computer maybe), if/as this passes all testing it should be fine.

I just recommend to await a response after the upstream report and
patch submission (for HEAD). Just in case we have been missing something.
Comment 7 commit-hook freebsd_committer freebsd_triage 2023-10-06 17:52:10 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e5019ec343524cf41f4f0c059296036cf228a135

commit e5019ec343524cf41f4f0c059296036cf228a135
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-09-21 19:08:58 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-10-06 17:48:53 +0000

    lang/gcc8 lang/gcc9: fix build with libc++ 17

    When building relatively recent gcc ports (with C++ in them) against
    libc++ 17, you get errors similar to:

      In file included from /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/cp/module.cc:208:
      In file included from /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/system.h:239:
      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 /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/cp/module.cc:208:
      In file included from /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/gcc/system.h:239:
      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
            |                                                ^
      /wrkdirs/usr/ports/lang/gcc12/work/gcc-12.2.0/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 gcc/system.h includes safe-ctype.h which redefines ctype
    macros such as toupper, tolower, etc to "poison" them.

    However, it should only include the safe-ctype.h header *after* any C++
    headers, such as <list>, <map>, <string>, etc, otherwise these might
    transitively include internal ctype headers (such as with libc++ 17),
    causing the above conflicts.

    Fix it by moving the safe-ctype.h inclusion to later in gcc/system.h,
    which solves this issue, and makes it possible to build against libc++
    17.

    See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632

    PR:             274042
    Approved by:    salvadore (maintainer)
    MFH:            2023Q4

 lang/gcc8/files/patch-gcc_system.h (new) | 42 ++++++++++++++++++++++++++++++++
 lang/gcc9/files/patch-gcc_system.h (new) | 42 ++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)