Repository: spack/spack

Issue:
Installation issue: gcc
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install gcc @10.3.0 +graphite %apple-clang @12.0.5
```

This builds GCC with the Apple Clang compiler shipped with macOS 11.3. The previous version was 12.0.0, which worked fine for building GCC.

### Information on your system

<!-- Please include the output of `spack debug report` -->

```
$ spack debug report
* **Spack:** 0.16.1-2404-303e506f2b
* **Python:** 3.8.5
* **Platform:** darwin-bigsur-skylake
* **Concretizer:** original
```

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->
* [spack-build-out.txt.gz](https://github.com/spack/spack/files/6387605/spack-build-out.txt.gz)
* [spack-build-env.txt](https://github.com/spack/spack/files/6387598/spack-build-env.txt)

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

@michaelkuhn

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [x] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:
The issue persists for `gcc @11.1.0`.
The error is a bootstrap comparison failure:
```
Comparing stages 2 and 3
Bootstrap comparison failure!
gcc/tree-ssa-operands.o differs
gcc/tree-ssanames.o differs
gcc/ipa-inline.o differs
[...]
```
More than 700 files differ. I assume the differences all have the same cause and are not due to a compiler error.
I see that the variant `bootstrap` is off by default, and Spack passes `--enable-bootstrap` to enable bootstrapping. However, GCC bootstraps by default, and requires `--disable-bootstrap` to disable it.

When I make this change, then (a) GCC builds much faster, and (b) the error goes away; GCC builds successfully.

Maybe this https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100347 is related? If GCC mis-detects the architecture, all created files would differ.
Closed by #23360 
The GCC build still fails if you enable bootstrapping. The GCC developers recommend always using bootstrapping.

I also find that older GCC versions (that used to work) now also fail with bootstrapping. The difference is that I've switched to macOS 11.3, which uses a newer version of Apple Clang (12.0.5). Can you re-open this issue?

I hear this is an XCode 12.5 issue; see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100340 .

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -226,8 +226,14 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage):
     # Binutils can't build ld on macOS
     conflicts('+binutils', when='platform=darwin')
 
+    # Bootstrap comparison failure:
+    #   see https://github.com/spack/spack/issues/23296
+    #   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100340
+    #   on XCode 12.5
+    conflicts('+bootstrap', when='@:11.1 %apple-clang@12.0.5')
+
     # aarch64/M1 is supported in GCC 12+
-    conflicts('@:11.99', when='target=aarch64: platform=darwin',
+    conflicts('@:11', when='target=aarch64: platform=darwin',
               msg='Only GCC 12 and newer support macOS M1 (aarch64)')
 
     # Newer binutils than RHEL's is required to run `as` on some instructions
@@ -252,7 +258,7 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage):
             # https://github.com/Homebrew/homebrew-core/pull/39041
             patch('https://raw.githubusercontent.com/Homebrew/formula-patches/master/gcc/8.3.0-xcode-bug-_Atomic-fix.patch',
                   sha256='33ee92bf678586357ee8ab9d2faddf807e671ad37b97afdd102d5d153d03ca84',
-                  when='@6:8')
+                  when='@6:8.3')
         if macos_version() >= Version('10.15'):
             # Fix system headers for Catalina SDK
             # (otherwise __OSX_AVAILABLE_STARTING ends up undefined)


Test patch: