Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc 13.2 build failing, syntax & redefinition errors, since 2024-04 #267

Closed
apjanke opened this issue Apr 9, 2024 · 7 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@apjanke
Copy link
Contributor

apjanke commented Apr 9, 2024

My GCC builds started failing when I came back early 2024-04 to do an RC build for 8.4.0, at the same time Qt 5.x builds started failing for me. Xcode had update from 15.2 to 15.3 in the mean time, but GCC is still failing with 15.2 and 15.1 for me, too.

This is blocking all Octave.app builds, including getting any 8.x or 9.x releases out.

Happens during the octapp biuld, and also when I do brew reinstall --build-from-source gcc in my regular Homebrew installations.

I'm handling the GCC build failure under this separate ticket here, because the Qt build failure was fixed by rolling back to Xcode 15.2, but the gcc failure wasn't, so may not be the same cause. And this is a complex enough problem, may as well have two focused tickets anyway.

See discussion under the linked Qt 5 build failure under Xcode 15.3 ticket, because there's some gcc-specific discussion in the comments there from before I created this separate gcc-specific ticket.

Symptoms

Results of various build attempts, done 2024-04-07 and later:

  • gcc, Xcode 15.3, Intel (angharad): fail (build logs)
  • gcc, Xcode 15.2, As (buildasaur, eilonwy): fail
  • gcc, Xcode 15.2, Intel (angharad): fail (build logs)
  • gcc, Xcode 15.1, As (eilonwy): fail
  • gcc, Xcode 15.1, Intel (angharad): fail (build logs)
  • gcc, Xcode 15.0.1, Intel (angharad): fail (build logs)

Those are all gcc 13.2.0, using the core Homebrew gcc formula, done with brew reinstall --build-from-source gcc, after using sudo xcode-select -s /Applications/Xcode-<version>.app/Contents/Developer to set the version of Xcode to use.

The errors look like this:

clang++ -std=c++11  -fPIE -c  -DIN_GCC_FRONTEND -g -DIN_GCC   -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wmissing-format-attribute -Wconditionally-supported -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -fPIE -I. -Icp -I../../gcc -I../../gcc/cp -I../../gcc/../include  -I../../gcc/../libcpp/include -I../../gcc/../libcody -I/usr/local/opt/gmp/include -I/usr/local/opt/mpfr/include -I/usr/local/opt/libmpc/include  -I../../gcc/../libdecnumber -I../../gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/../libbacktrace -I/usr/local/opt/isl/include  -o cp/parser.o -MT cp/parser.o -MMD -MP -MF cp/.deps/parser.TPo ../../gcc/cp/parser.cc
In file included from ../../gcc/cp/mapper-client.cc:31:
In file included from ../../gcc/system.h:227:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/map:2529:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/functional:526:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/vector:321:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_integral.h:32:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/locale:202:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__locale:550:5: error: '__abi_tag__' attribute only applies to structs, variables, functions, and namespaces
    _LIBCPP_INLINE_VISIBILITY
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__config:891:37: note: expanded from macro '_LIBCPP_INLINE_VISIBILITY'
#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
                                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__config:870:26: note: expanded from macro '_LIBCPP_HIDE_FROM_ABI'
          __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
                         ^
In file included from ../../gcc/cp/mapper-client.cc:31:
In file included from ../../gcc/system.h:227:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/map:2529:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/functional:526:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/vector:321:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_integral.h:32:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/locale:202:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__locale:551:37: error: expected ';' at end of declaration list
    char_type toupper(char_type __c) const
                                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__locale:557:48: error: too many arguments provided to function-like macro invocation
    const char_type* toupper(char_type* __low, const char_type* __high) const
                                               ^
../../gcc/../include/safe-ctype.h:146:9: note: macro 'toupper' defined here
#define toupper(c) do_not_use_toupper_with_safe_ctype
        ^
[...]
In file included from ../../gcc/cp/module.cc:212:
In file included from ../../gcc/system.h:233:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/vector:321:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_integral.h:32:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/locale:202:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__locale:811:1: error: declaration conflicts with target of using declaration already in scope
iscntrl(_CharT __c, const locale& __loc)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/_ctype.h:230:1: note: target of using declaration
iscntrl(int _c)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/cctype:115:9: note: using declaration
using ::iscntrl _LIBCPP_USING_IF_EXISTS;
        ^
In file included from ../../gcc/cp/module.cc:212:
In file included from ../../gcc/system.h:233:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/vector:321:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__format/formatter_integral.h:32:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/locale:202:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/c++/v1/__locale:813:5: error: expected expression
    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[3]: *** [cp/module.o] Error 1
rm gcc.pod
make[2]: *** [all-stage1-gcc] Error 2
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2

I haven't checked exhaustively to see if they're all the same under the various Xcodes and arches. But they look similar in a brief skim.

Diagnosis

To see which versions of Xcode and Xcode CLT you're running:

xcodebuild -version
echo -n 'Xcode CLT: '; pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | head -2 | tail -1 | sed 's/.* //'
clang --version | head -1

References

UPDATE: Fixed with new gcc, 2024-05

As of the new gcc 14.1.0 package in core Homebrew from mid 2024, this seems fixed. I can now build the gcc package from source without error, using the latest Xcode 15.3 or 15.4 and Xcode CLT 15.3. The workaround of downgrading Xcode seems no longer necessary.

@apjanke apjanke added the bug Something isn't working label Apr 9, 2024
@apjanke apjanke added this to the 8.4.0 milestone Apr 9, 2024
@apjanke apjanke self-assigned this Apr 9, 2024
@apjanke
Copy link
Contributor Author

apjanke commented Apr 9, 2024

On angharad, I'm reinstalling all my brew formulae to make sure I had fresh, official from-bottle installations.

$ brew reinstall `brew ls`

It's going slow, due to breakage or warnings with various deprecated or removed formulae, a bunch of file permission denied errors when reinstalling qt@5, and my terminal hanging.

TODO: Finish this.

@apjanke
Copy link
Contributor Author

apjanke commented Apr 9, 2024

Oho! Look at this GCC bug #111632 "gcc fails to bootstrap when using libc++" on GCC's Bugzilla, from 2023-09. (Following FreeBSD bug 274041.) Looks like it's about this here issue, with the same "do_not_use_toupper_with_safe_ctype" toupper redefinition and __abi_tag__ errors I'm seeing here. From the comments, GCC's safe-ctype.h is doing type "poisoning" that interferes with the standard C++ headers.

[w]hen building gcc's C++ sources against recent libc++ (>= 17), the poisoning of the ctype macros due to including safe-ctype.h before including C++ standard headers such as <list>, <map>, etc, causes many compilation errors, similar to:

[...]

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

And a comment calls out Xcode 15.3 specifically:

Francois-Xavier Coudert 2024-03-06 13:38:30 UTC

Starting with Xcode 15.3 and the SDK for macOS 14.4, this is breaking bootstrap on x86_64-apple-darwin23

The comments seem to say a non-bootstrapped build would work, but is not supported. Or something like that. Or maybe these patches just enable the non-bootstrapped --disable-bootstrap build.

At least one of those patches made it to the patches/gcc-13 branch on 2024-04-03 just a few days ago, so a fix may be forthcoming.

So hmmm, why is it breaking for me even when I used xcode-select to switch back to Xcode 15.2 or older? Maybe this SDK system headers stanza is pulling them in from the main Xcode anyway?

      # System headers may not be in /usr/include
      sdk = MacOS.sdk_path_if_needed
      args << "--with-sysroot=#{sdk}" if sdk

TODO: Try replacing my main /Applications/Xcode.app with a 15.2 version.

UPDATE: Still broke on angharad. I deleted /Applications/Xcode.app (the one I got from the app store) and replaced it with a freshly unzipped Xcode 15.2, and did brew reinstall --build-from-source gcc. It failed with the same-looking errors. I wonder if I still have system headers dropped out from the original Xcode 15.3. I don't know how to uninstall those. Guess i'll try it on a fresh VM.

UPDATE: Tests on other computers:

  • macOS 12.7.4 Intel VM w/ Xcode 14.2 (never higher) "montague" - ok
  • macOS 13.6.5 Intel VM w/ Xcode 14.2 "thirsty" - ok
  • macOS 13.6.5 Intel VM w/ Xcode 15.2 (upgrade from 14.2) "thirsty" - ok

I'm gonna call that a good test and an indication that Xcode 15.3 broke gcc, and I can do a workaround by creating a fresh machine that has never had Xcode 15.3 installed. Gonna do that for a build box.

@apjanke
Copy link
Contributor Author

apjanke commented Apr 10, 2024

Sheesh. Looks like this issue was already reported to upstream Homebrew and the cause diagnosed, but I didn't recognize it because the bug report in the homebrew-core repo was "error in catching C++ exceptions" and didn't look like the same problem; the GCC build failure itself only came up several comments down, and the "brew install gcc fails with CLT 15.3" bug that looks like my exact problem here was in the iains/gcc-13-branch repo of GCC, which I don't watch.

A comment there has instructions on how to successfully downgrade Xcode, including the CLT, which may get the build working on my main machines again. You have to also remove the CLT and reinstall an older version of it from the developer downloads (search "Xcode command line tools 15.1", or maybe this URL here is a direct download); that does not track the version of Xcode itself you have installed. (Do sudo rm -rf /Library/Developer/CommandLineTools to uninstall it.)

Interestingly, the Developer Downloads for "command line tools" has CLT versions 15.1 and 15.3, but no download for a CLT 15.2, even though there's an Xcode 15.2 download. Dunno what's up with that.

I'll try downgrading my CLT to 15.1, and maybe download Xcode to 15.1 to match, and see how that works.

Tests

  • brew reinstall --build-from-source gcc
    • Xcode 15.2 (main install), CLT 15.1, macOS 14.4.1, Intel (angharad) - running
      • (after I downgraded CLT from 15.3 using the above process)

References

TODO

  • See if I can get the versions of both Xcode and the CLT displayed in the bundle_octave_app output, and maybe captured to the build info metadata file that goes in the octapp release.

@apjanke
Copy link
Contributor Author

apjanke commented Apr 11, 2024

Downgrading angharad to Xcode 15.2 and Xcode CLT 15.1 worked! brew reinstall --build-from-source gcc ran without error.

$ brew info gcc
==> gcc: stable 13.2.0 (bottled), HEAD
GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/gcc/13.2.0 (1,590 files, 391MB) *
  Built from source on 2024-04-10 at 20:16:24
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/g/gcc.rb
License: GPL-3.0-or-later with GCC-exception-3.1
[octave-app-bundler] $ xcodebuild -version
Xcode 15.2
Build version 15C500b
[octave-app-bundler] $ clang --version
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
[octave-app-bundler] $ xcode-select -p
/Applications/Xcode.app/Contents/Developer
[octave-app-bundler] $

I think that means I can build all of Octave.app on my main machines again instead of specially-configured VMs.

@apjanke
Copy link
Contributor Author

apjanke commented Apr 11, 2024

Looks like a gotcha with the CLT downgrade: the Software Update in System Settings > General will offer to upgrade the CLT. Dunno if that always happens when it's installed from a package, or just if you had previously done an xcode-select --install on that machine. The way that Software Update GUI is organized, I don't see a way to apply updates selectively. So if a macOS update came out, and I used the GUI, it'd pick up the CLT update too, and I'd have to downgrade it again, I think.

Maybe there's a CLI for software update that allows you to be selective.

@apjanke
Copy link
Contributor Author

apjanke commented Apr 15, 2024

Looks like the downgrade worked. With Xcode 15.2 and Xcode CLT 15.1, I got a successful build on both Intel and AS. I posted that as 8.4.0 beta3.

Considering this closed. Will just continue to use the older Xcode until The core Homebrew builds are fixed.

@apjanke apjanke closed this as completed Apr 15, 2024
@apjanke
Copy link
Contributor Author

apjanke commented May 25, 2024

UPDATE: Fixed with new gcc, 2024-05?

As of the new gcc 14.1.0 package in core Homebrew from mid 2024, this seems fixed. I can now build the gcc package from source without error, using the latest Xcode 15.3 or 15.4 and Xcode CLT 15.3, on both Intel and AS. The workaround of downgrading Xcode seems no longer necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant