Commit Graph

63 Commits

Author SHA1 Message Date
Adam Joseph
b81284ec71 gcc: link $lib/lib -> $lib/$targetConfig correctly and consistently
When native-compiling, gcc will install libraries into:

  /nix/store/...-$targetConfig-gcc-$version-lib/lib

When cross-compiling, gcc will install libraries into:

  /nix/store/...-$targetConfig-gcc-$version-lib/$targetConfig

When cross-compiling, we intended to create a link from $lib/lib to
$lib/$targetConfig, so that downstream users can always safely
assume that "${lib.getLib stdenv.cc.cc}/lib" is where the gcc
libraries are, regardless of whether `stdenv.cc.cc` is a cross
compiler or a native compiler.

Unfortunately, there were two problems with how we were trying to
create these links:

1. The link would be created only when `enableLibGccOutput==true`

2. The link was being created from the incorrect source
   `$lib/lib/lib` instead of `$lib/lib`.

Both of these mistakes are my fault.  This commit corrects them by
creating the link using `ln -Ts` (which is more predictable) and by
creating the link from `gcc/common/builder.nix` rather than from
`gcc/common/libgcc.nix`.
2024-03-15 18:18:24 +00:00
Robert Scott
4a91b3e798 cc-wrapper: add trivialautovarinit hardening flag support
this equates to -ftrivial-auto-var-init=pattern

clang has removed support for -ftrivial-auto-var-init=zero and
are unlikely to re-add it, so use -ftrivial-auto-var-init=pattern
on both compilers if only to make behaviour more consistent
between the two.

add to pkgsExtraHardening's defaultHardeningFlags.
2024-02-24 12:00:09 +00:00
Robert Scott
40868719b0 cc-wrapper: add zerocallusedregs hardening flag
this uses the value `used-gpr` which seems to be a commonly
chosen value for general use
2024-01-20 13:48:33 +00:00
Robert Scott
1a5bd697ad mkDerivation, bintools-wrapper: move defaultHardeningFlags determination to bintools-wrapper
this makes it a lot easier to create a modified stdenv with a
different set of defaultHardeningFlags and as a bonus allows us
to inject the correct defaultHardeningFlags into toolchain wrapper
scripts, reducing repetition.

while most hardening flags are arguably more of a compiler thing,
it works better to put them in bintools-wrapper because cc-wrapper
can easily refer to bintools but not vice-versa.

mkDerivation can still easily refer to either when it is constructed.

this also switches fortran-hook.sh to use the same defaults for
NIX_HARDENING_ENABLE as for C. previously NIX_HARDENING_ENABLE
defaults were apparently used to avoid passing problematic flags
to a fortran compiler, but this falls apart as soon as mkDerivation
sets its own NIX_HARDENING_ENABLE - cc.hardeningUnsupportedFlags
is a more appropriate mechanism for this as it actively filters
out flags from being used by the wrapper, so switch to using that
instead.

this is still an imperfect mechanism because it doesn't handle a
compiler which has both langFortran *and* langC very well - applying
the superset of the two's hardeningUnsupportedFlags to either
compiler's invocation. however this is nothing new - cc-wrapper
already poorly handles a langFortran+langC compiler, applying two
setup hooks that have contradictory options.
2023-12-09 16:30:45 +00:00
Emily Trau
f6e48acfa2 gcc8: support avr cross compilation on aarch64-darwin 2023-12-04 06:32:32 +11:00
Randy Eckenrode
f2a7764cab
gcc{6,7,8,9,10,11}: fix cross-compiler build on x86_64-darwin
Building a cross-compiler fails due to register storage class specifier
errors when building with clang 16 due to its defaulting to C++17.
Downgrading the error allows the older cross-compilers to build.
2023-12-02 18:43:00 -05:00
Randy Eckenrode
4a538d6b3d
gcc11: mark as bad on aarch64-darwin when building a cross-compiler 2023-12-02 18:42:00 -05:00
Randy Eckenrode
fe27958aed
gcc{6,7,8,9}: use target bintools on Darwin
Using the host bintools results in evaluation errors when building an
AVR cross-compiler due to trying to build cctools for AVR.
2023-12-02 18:32:15 -05:00
Adam Joseph
62dbf14a30 gcc: put environment variables in drvAttrs.env 2023-12-01 22:03:09 +00:00
github-actions[bot]
d49b3ff9e3
Merge staging-next into staging 2023-11-08 12:02:19 +00:00
Randy Eckenrode
299c06a0f5 gcc{48,49,6,7,8,9,10}: improve cctools-llvm compatibility
darwin.cctools defaults to `llvm-strip` when the version of LLVM in the
stdenv is 12 or newer. This strip implementation does not support the
`-c` flag required by older versions of GCC. Use the cctools-port
version for compatibility when building older versions of GCC.
2023-11-08 10:50:07 +00:00
Randy Eckenrode
b09f87fb0d gcc48: disable on x86_64-darwin
According to Hydra, the last time GCC 4.8 successfully built on Darwin
was October 2014. It is possible to make the first stage build
successfully with clang, but the resulting GCC is not capable of reading
the Darwin SDK headers due to their use of `__can_include`.

It’s been broken for almost a decade, so just disable it.
2023-11-08 07:32:47 +00:00
github-actions[bot]
599850da55
Merge staging-next into staging 2023-11-07 12:01:25 +00:00
Adam Joseph
78706a9184 gcc: move version information to gcc/versions.nix 2023-11-07 09:57:54 +00:00
Adam Joseph
1904125877 gcc: change "-stage-static" to "-nolibc" and "-stage-final" to ""
This commit changes the target suffix for the first-stage cross
compiler from `-stage-static` to `-nolibc`, and eliminates the
target suffix from the final-stage cross compiler (previously
`-stage-final`).

Co-authored-by: Artturi <Artturin@artturin.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
2023-10-26 20:07:18 -07:00
github-actions[bot]
ab895db907
Merge staging-next into staging 2023-09-22 00:02:40 +00:00
Adam Joseph
ea61be413c gcc: set GFORTRAN_FOR_TARGET on cross-built native compilers
For a cross-built native compiler, i.e. build!=(host==target), the
bundled libgfortran needs a gfortran which can run on the
buildPlatform and emit code for the targetPlatform.  The compiler
which is built alongside gfortran in this configuration doesn't meet
that need: it runs on the hostPlatform.

This commit passes the necessary compiler via `GFORTRAN_FOR_TARGET`,
using `pkgsBuildTarget.gfortran`.
2023-09-21 09:24:56 +03:00
Artturi
2e705d027f
Merge pull request #250498 from amjoseph-nixpkgs/gcc/deduplicate/simplify2 2023-09-19 07:47:50 +03:00
John Ericson
e829eca886
Merge pull request #253939 from angerman/angerman/ucrt64
Add ucrt64 mingw toolchain.
2023-09-08 22:40:14 -04:00
Adam Joseph
aafab3b5b6 gcc: for cross compilers, don't build libgcc twice
Cross-compiled binaries currently end up with two different libgcc
outpaths in their closure.  This is harmless, but confusing.

The two libgccs are:

- One of them is the "first" targetPlatform libgcc, which is built
  by the "first" cross-compiler.  This "first libgcc" and "first
  compiler" are used to build the targetPlatform glibc.

- Once glibc is built, we *rebuild* the cross-compiler, since gcc
  can't enable most of its features unless you give it an
  already-compiled targetPlatform glibc.  When this "second"
  compiler is built, it also builds an extra copy of libgcc.

This commit discards the second, extra libgcc, and instead puts a
reference to the first (correct) libgcc into the "second compiler"
`.passthru.libgcc`, so that anybody expecting `stdenv.cc.cc.libgcc`
to exist will still find it there.

Closes #249680
2023-09-08 16:07:50 +03:00
Moritz Angermann
a81e3dcd75 treewide: replace libc == "msvcrt" with isMinGW
msvcrt is only one of the libcs in MinGW. We therefore
replace explictly testing for msvcrt with the isMinGW
predicate. This lays the foundation for ucrt64 support.
2023-09-08 10:56:08 +00:00
Adam Joseph
af319af225 gcc: unescapify backslash 2023-08-23 21:47:12 -07:00
Adam Joseph
80198b835b gcc: remove backticks-used-as-quotes (error prone) 2023-08-23 21:47:12 -07:00
Adam Joseph
040cf4248d gcc: simplify expression by applying workarounds more broadly
This commit simplifies our gcc expression by applying various
workarounds unconditionally, rather than only to exactly the
versions which applied them prior to the deduplication cleanup.

Unlike its predecessors https://github.com/NixOS/nixpkgs/pull/249707
and https://github.com/NixOS/nixpkgs/pull/250489 this commit *does*
affect eval.
2023-08-23 21:47:12 -07:00
Adam Joseph
8f225b515f gcc: match weird whack-a-mole per-version hash algorithm 2023-08-20 23:00:03 -07:00
Adam Joseph
de36365466 gcc: clean up version conditions 2023-08-20 23:00:03 -07:00
Adam Joseph
30171782b7 gcc: move version-map out of all-packages.nix, into pkgs/ 2023-08-20 23:00:02 -07:00
Adam Joseph
911452ccbd gcc: move patches attribute into patches/ subdirectory 2023-08-20 23:00:02 -07:00
Adam Joseph
95475034d5 gcc: if atLeast 4.8, use deduplicated version 2023-08-20 23:00:02 -07:00
Adam Joseph
beeb48d17a gcc: if atLeast 4.9, use deduplicated version 2023-08-20 23:00:02 -07:00
Adam Joseph
920df10ab7 gcc: if atLeast 6, use deduplicated version 2023-08-20 23:00:02 -07:00
Adam Joseph
33f7f2c5aa gcc: if atLeast 7, use deduplicated version 2023-08-20 23:00:01 -07:00
Adam Joseph
e7afebbc4c gcc: if atLeast 8, use deduplicated version 2023-08-20 23:00:01 -07:00
Adam Joseph
4116fc3e6f gcc: if atLeast 9, use deduplicated version 2023-08-20 23:00:01 -07:00
Adam Joseph
10ee71f582 gcc: if atLeast 10, use deduplicated version 2023-08-20 23:00:01 -07:00
Adam Joseph
72fe04286e gcc: if atLeast 11, use deduplicated version 2023-08-20 23:00:00 -07:00
Adam Joseph
e9ece66a80 gcc: if atLeast 12, use deduplicated version 2023-08-20 23:00:00 -07:00
Adam Joseph
9dc9872922 gcc: default.nix: parameterize by version 2023-08-20 23:00:00 -07:00
Adam Joseph
57a2dfe646 gcc: default.nix: replace ../ with ./ 2023-08-20 23:00:00 -07:00
Adam Joseph
671b761d05 gcc: cp ./13/default.nix ./default.nix 2023-08-20 22:59:59 -07:00
Adam Joseph
fa0fc88e0c gcc: match weird whack-a-mole per-version hash algorithm 2023-08-20 22:59:20 -07:00
Adam Joseph
869b639285 gcc: clean up version conditions 2023-08-20 22:59:20 -07:00
Adam Joseph
02198751fa gcc: move version-map out of all-packages.nix, into pkgs/ 2023-08-20 22:59:20 -07:00
Adam Joseph
7367bb691d gcc: move patches attribute into patches/ subdirectory 2023-08-20 22:59:19 -07:00
Adam Joseph
da87387073 gcc: if atLeast 4.8, use deduplicated version 2023-08-20 22:59:16 -07:00
Adam Joseph
8a4148a538 gcc: if atLeast 4.9, use deduplicated version 2023-08-20 22:59:16 -07:00
Adam Joseph
b505fb4711 gcc: if atLeast 6, use deduplicated version 2023-08-20 22:59:16 -07:00
Adam Joseph
b3d07e87d2 gcc: if atLeast 7, use deduplicated version 2023-08-20 22:59:15 -07:00
Adam Joseph
942d7ecf08 gcc: if atLeast 8, use deduplicated version 2023-08-20 22:59:15 -07:00
Adam Joseph
01902c7b45 gcc: if atLeast 9, use deduplicated version 2023-08-20 22:59:15 -07:00