The x86_64-darwin build fails with the following symbol errors when
building gencondmd:
Undefined symbols for architecture x86_64:
"_ix86_excess_precision", referenced from:
___cxx_global_var_init.101 in gencondmd.o
"_ix86_fpmath", referenced from:
___cxx_global_var_init.101 in gencondmd.o
"_ix86_isa_flags", referenced from:
___cxx_global_var_init.101 in gencondmd.o
"_ix86_unsafe_math_optimizations", referenced from:
___cxx_global_var_init.101 in gencondmd.o
"_target_flags", referenced from:
___cxx_global_var_init.101 in gencondmd.o
This commit applies a workaround posted to the GCC BugZilla.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92061.
Darwin uses the clang integrated assembler, which does not support
`--gstabs`. While the `configure` script detects whether the assembler
supports it, Darwin passes `--gstabs` unconditionally. This patch is
backported to make the bootstrap only use it when supported.
Older versions of GCC use `-pipe` on Darwin due to compatibility
problems with older cctools assemblers. Darwin now uses the clang
integrated assembler. While it is possible to pipe input into it, the
wrapper used in nixpkgs is not set up for it.
Fixing the wrapper would cause all of Darwin to rebuild, which is not
desirable, so just disable `-pipe` in the bootstrap configuration. The
clang integrated assembler doesn’t have the bug anyway.
The libgcc configure script was middetecting aarch64-darwin and trying
to use a deployment target of 10.5, which is not valid for that
platform. The build was failing because the linker was looking for stubs
that don’t exist (neither as part of the source releases nor as part of
the official SDK from Apple).
Backporting the `config.host` check and `t-darwin-rpath` from GCC 12
allows GCC 11 to build again on aarch64-darwin.
Without the change `__FILE__` used in static inline functions in headers
embed paths to header files into executable images. For local headers
it's not a problem, but for headers in `/nix/store` this causes `-dev`
inputs to be retained in runtime closure.
Typical examples are `nix` -> `nlonhmann_json` and `pipewire` ->
`lttng-ust.dev`.
Ideally we would like to use `-fmacro-prefix-map=` feature of `gcc` as:
-fmacro-prefix-map=/nix/store/$hash1-nlohmann-json-ver=/nix/store/eeee.eee-nlohmann-json-ver
-fmacro-prefix-map=/nix/...
In practice it quickly exhausts argument lengtth limit due to `gcc`
deficiency: https://gcc.gnu.org/PR111527
Until it;s fixed let's hardcode header mangling if $NIX_STORE variable
is present in the environment.
Tested as:
$ printf "# 0 \"/nix/store/01234567890123456789012345678901-pppppp-vvvvvvv\" \nconst char * f(void) { return __FILE__; }" | NIX_STORE=/nix/store ./gcc/xgcc -Bgcc -x c - -S -o -
...
.string "/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-pppppp-vvvvvvv"
...
Mangled successfully.
This PR sorts the huge pile of patches and deduplicates it. Unlike
its predecessors https://github.com/NixOS/nixpkgs/pull/249707 and
https://github.com/NixOS/nixpkgs/pull/250489 this commit *does*
affect eval.
Patches below are organized into three general categories:
1. Patches relevant to gcc>=12 on every platform
2. Patches relevant to gcc>=12 on specific platforms
3. Patches relevant only to gcc<12, sorted by the newest version to
which they might be relevant