Repository: spack/spack

Issue:
Installation issue: gcc@9.3.0
### Steps to reproduce the issue

```console
spack -k install gcc@9.2.0
```

### Information on your system

* **Spack:** 0.17.1-780-d4a468c160
* **Python:** 3.7.11
* **Platform:** darwin-bigsur-skylake
* **Concretizer:** clingo

@alalazo 
@michaelkuhn


### Additional information

[spack-build-03-build-out.txt](https://github.com/spack/spack/files/7850862/spack-build-03-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/7850886/spack-build-env.txt)



### General information

- [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:
Similar errors occur with gcc@9.3.0, and gcc@10.3.0

Also noted that https://github.com/spack/spack/pull/27133 may be related too!
The #27133 error is unrelated; the issue is: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92061 . 

This is only a problem with `apple-clang@13` and isn't seen in `apple-clang@12`.

To make the error more searchable, the failing command is:
```
/opt/spack/lib/spack/env/clang/clang++ -std=gnu++98   -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 -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H  -DGENERATOR_FILE -fno-PIE -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/gcc-9.2.0-na4znnp5c7rigll7nx6fe3aolm3hpnf7/lib -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/gcc-9.2.0-na4znnp5c7rigll7nx6fe3aolm3hpnf7/lib64 -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/gmp-6.2.1-hy4uvsghpne2d6ya7mcwxcvxzh4i3bak/lib -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/libiconv-1.16-fu7tfsrqgljwmgqfaf7zfehjbqhbr2vs/lib -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/mpc-1.1.0-yid5rozpdpzphni5lhu2o3bllhsx4jv7/lib -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/mpfr-3.1.6-xgehckfj34ps6awdlywgekmkkmsekeav/lib -Wl,-rpath,/opt/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/zlib-1.2.11-xevvljjwbmyqlp45p465lfqqj7e6kjeg/lib   -no-pie -o build/gencondmd \
	    build/gencondmd.o ../build-x86_64-apple-darwin20.6.0/libiberty/libiberty.a
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
Undefined symbols for architecture x86_64:
  "_cfun", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_epilogue_completed", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_cf_protection", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_finite_math_only", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_fp_int_builtin_inexact", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_peephole2", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_pic", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_rounding_math", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_trapping_math", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_flag_unsafe_math_optimizations", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_insn", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_arch_features", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_cmodel", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_fpmath", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_isa_flags", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_isa_flags2", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_pmode", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_tls_dialect", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_ix86_tune_features", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_operands", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_optimize", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_reload_completed", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_reload_in_progress", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_rtx_class", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_target_flags", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_this_target_flag_state", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
  "_x86_prefetch_sse", referenced from:
      ___cxx_global_var_init.95 in gencondmd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [build/gencondmd] Error 1
rm gcc.pod
make[2]: *** [all-stage1-gcc] Error 2
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2

```

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
@@ -277,6 +277,9 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage):
         patch('darwin/gcc-4.9.patch1', when='@4.9.0:4.9.3')
         patch('darwin/gcc-4.9.patch2', when='@4.9.0:4.9.3')
 
+        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92061
+        patch('darwin/clang13.patch', when='@:11.1 %apple-clang@13')
+
     patch('piclibs.patch', when='+piclibs')
     patch('gcc-backport.patch', when='@4.7:4.9.3,5:5.3')
 


Test patch: