Commit Graph

219 Commits

Author SHA1 Message Date
K900
17c01aad84 gcc: explicitly disallow cross + multilib, extract targetLibDir to variable 2025-02-08 12:07:15 +03:00
K900
536c98cb32 Revert "gcc: rework, clean up, and document the cursed symlink hack" 2025-02-08 11:54:21 +03:00
K900
97a3367a33 Revert "gcc: disable symlink checks on cross + nolibc for now"
This reverts commit 3fd43d5d74.

The proper fix is now in.
2025-02-02 22:12:49 +03:00
K900
c1907fbbf0 gcc: rework, clean up, and document the cursed symlink hack
Fixes dangling symlinks.

Also flips the direction of symlinks on cross
from $lib/$target/lib -> $lib/lib to $lib/lib -> $lib/$target/lib
2025-02-02 22:12:49 +03:00
K900
3fd43d5d74 gcc: disable symlink checks on cross + nolibc for now
This is a hack, but a proper fix requires an stdenv rebuild,
so it will have to go to staging.
2025-02-02 09:47:58 +03:00
Silvan Mosberger
84d4f874c2 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev 78e9caf153
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:23:58 +01:00
Wolfgang Walther
d86588d230 treewide: improve prepending and appending derivation arguments in bash code
Those would be problematic with __structuredAttrs turned on, because
they'd turn those nice bash arrays back into strings - and potentially
lose some of the values on the way.
2024-11-25 09:09:23 +01:00
Emily
937529bb51 gcc: remove code for macOS < 11 2024-11-18 00:14:00 +00:00
Randy Eckenrode
e50074418d gcc: set up sysroot for the Darwin SDK
The GCC bootstrap builds each stage with an unwrapped GCC, which needs
to correctly handle looking for libraries and headers in sysroot.
Setting the native header folder to `/usr/include` will actually cause
GCC to search `<sysroot>/usr/include`, which is the SDKROOT in nixpkgs.
2024-10-10 17:04:36 -04:00
Randy Eckenrode
a77d0eb819 gcc: fix extraLDFlags logic after undoing staging-next workaroud
The original logic was prepending to the array, but this one prepends
the array to itself, which breaks the x86_64-linux stdenv bootstrap. The
correct thing to do is build up the arguments in a temporary array and
prepend it like the original code was doing.
2024-10-10 17:04:36 -04:00
Randy Eckenrode
ac31fb7505 gcc: remove staging-next workaround 2024-10-10 01:07:29 -04:00
K900
5a9d1835e1 glibc: 2.39-52 -> 2.40-36 (#342073) 2024-09-20 19:42:37 +03:00
Maximilian Bosch
35d12c9cfc gcc: remove "fixed" pthread.h
Fixes

    /nix/store/8pq96x5qsczrmc926795lf7j4dzy2c8q-binutils-patchelfed-ld-2.43.1/bin/ld: ../../src/liblzma/.libs/liblzma.so: undefined reference to `__pthread_cond_timedwait64'
    collect2: error: ld returned 1 exit status

while building `xz` for `stdenv`. The root cause is that glibc replaced
`__USE_TIME_BITS64` with `__USE_TIME64_REDIRECTS`[1]. However, the
stage3 GCC seems to use the bootstrap headers from glibc for
`fixincludes`, i.e. headers w/o this change. Because of that, the xz
build with stage3 stdenv gets a header that looks like this:

    # ifndef __USE_TIME_BITS64
    /* ... */
    # else
    #  ifdef __REDIRECT
    /* ... */
    #  else
    #   define pthread_cond_timedwait __pthread_cond_timedwait64
    #  endif
    # endif

Since __USE_TIME_BITS64 doesn't exist anymore because a new glibc is used
for building, the preprocessor ends up in the condition defining
`__pthread_cond_timedwait64` even though it's not supposed to end up
there since __pthread_cond_timedwait64 doesn't exist on x86_64[2].

I decided to just kill the header here since GCC claims that all the
`pthread.h` only very old glibc versions or platform-specific libcs we
don't use[3].

[1] https://sourceware.org/git/?p=glibc.git%3Ba%3Dcommit%3Bh%3Ddd535f4f19ef2b5c367a362af445ecadcf45401e
[2] https://inbox.sourceware.org/libc-stable/50c0269d-b73c-4e8a-9816-65f72d6082c0@linaro.org/
[3] https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.2.0/fixincludes/inclhack.def
2024-09-15 15:36:48 +02:00
Emily
de4388c609 {cc-wrapper,gcc}: drop unused logic and patches 2024-09-15 02:45:00 +01:00
Daniel Nagy
4f85840d25 gcc: provide build support for gccrs
Patches from the gccrs project are being upstreamed into gcc. With
these changes we are now able to build a gcc with rust support like
this:

```nix
wrapCC (gcc14.cc.override {
  langRust = true;
});
```

More info:

https://rust-gcc.github.io/

https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608387.html
2024-08-06 20:26:34 +02:00
Randy Eckenrode
ea889da7e6 gcc: drop rpath from build on platforms that don’t set rpaths
Darwin uses absolute path install names, so setting rpaths is unnecessary. This fixes breakage on older versions of GCC that try to set a deployment target that does not support rpaths.
2024-07-22 12:17:05 -04:00
Atemu
dd83e3e407 Merge pull request #316334 from trofi/gcc-libgcc-musl-strip
gcc: provide a $libgcc/$target/lib -> $libgcc/lib symlink
2024-06-30 22:41:10 +02:00
Alyssa Ross
0a71bbb64a gcc: fix building with gcc.cpu on some platforms
This fixes, for example, cross compiling to
{ system = "riscv64-linux"; gcc.cpu = "sifive-u74"; }.
2024-06-15 08:03:18 +02:00
Sergei Trofimovich
c682f2b491 gcc: provide a $libgcc/$target/lib -> $libgcc/lib symlink
The primary reason for the layout change is for `gcc.libgcc` to match
closer `gcc.lib` layout. That way we allow `$STRIP_FOR_TARGET` to strip
`libgcc_s.so.1` file moved to $libgcc output. Otherwise `$STRIP` (for
host) fails to do it and leaves debug strings like references to headers
in it and bloats HOST closure with BUILD inputs.

The change shrinks `aarch64-multiplatform-musl.coreutils` closure from
50MB down to 10MB:

Before:

    $ nix path-info -rsSh $(nix-build -A pkgs.pkgsCross.aarch64-multiplatform-musl.coreutils) |& unnix
    /<<NIX>>/xgcc-13.2.0-libgcc                              155.8K  155.8K
    /<<NIX>>/musl-aarch64-unknown-linux-musl-1.2.3             3.8M    3.8M
    /<<NIX>>/libunistring-1.1                                  1.7M    1.7M
    /<<NIX>>/libidn2-2.3.7                                   352.7K    2.1M
    /<<NIX>>/glibc-2.39-52                                    28.7M   31.0M
    /<<NIX>>/bash-5.2p26                                       1.5M   32.5M
    /<<NIX>>/musl-aarch64-unknown-linux-musl-1.2.3-bin        69.4K    3.8M
    /<<NIX>>/linux-headers-6.7                                 6.2M    6.2M
    /<<NIX>>/musl-aarch64-unknown-linux-musl-1.2.3-dev       550.2K   43.1M
    /<<NIX>>/aarch64-unknown-linux-musl-gcc-13.2.0-libgcc    579.7K   43.6M
    /<<NIX>>/aarch64-unknown-linux-musl-gcc-13.2.0-lib         3.8M   47.4M
    /<<NIX>>/gmp-with-cxx-aarch64-unknown-linux-musl-6.3.0   653.4K   48.1M
    /<<NIX>>/attr-aarch64-unknown-linux-musl-2.5.2            73.8K    3.8M
    /<<NIX>>/acl-aarch64-unknown-linux-musl-2.3.2            156.4K    4.0M
    /<<NIX>>/coreutils-aarch64-unknown-linux-musl-9.5          1.6M   49.9M

After:

    $ nix path-info -rsSh $(nix-build -A pkgs.pkgsCross.aarch64-multiplatform-musl.coreutils) |& unnix
    /<<NIX>>/musl-aarch64-unknown-linux-musl-1.2.3             3.8M    3.8M
    /<<NIX>>/aarch64-unknown-linux-musl-gcc-13.2.0-libgcc    147.9K  147.9K
    /<<NIX>>/aarch64-unknown-linux-musl-gcc-13.2.0-lib         3.8M    7.7M
    /<<NIX>>/gmp-with-cxx-aarch64-unknown-linux-musl-6.3.0   653.4K    8.4M
    /<<NIX>>/attr-aarch64-unknown-linux-musl-2.5.2            73.8K    3.8M
    /<<NIX>>/acl-aarch64-unknown-linux-musl-2.3.2            156.4K    4.0M
    /<<NIX>>/coreutils-aarch64-unknown-linux-musl-9.5          1.6M   10.1M
2024-06-01 05:59:59 +01:00
Weijia Wang
d851de2647 gcc14: add aarch64-darwin support 2024-05-21 12:08:26 +02:00
Randy Eckenrode
dbe34b193d gnat{11,12,13}: fix build on x86_64-darwin
- gnat11: make sure to use the gnat-bootstrap gcc in the stdenv; and
- Drop the dual assemblers. x86_64-darwin uses the clang assembler by
  default, so it no longer needs the workaround for the GNU assembler.
2024-05-09 17:35:07 -04:00
Philip Taron
8616de2279 Avoid top-level with ...; in pkgs/development/compilers/gcc/common/meta.nix 2024-03-28 03:04:49 +01:00
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
K900
967d49b8a8 Merge remote-tracking branch 'origin/staging-next' into staging 2024-01-18 19:15:32 +03:00
Uri Baghin
1cf2d7357c gcc: fix c++ headers when same triplet cross compiling
When build platform and host platform differ, but have the same
triple, the code in nixpkgs will consider it a cross compilation,
but gcc won't. This will lead some derivations to look for c++
headers in the wrong place. To solve this always output the headers
in the non-cross location, like we do for the other gcc headers
already.
2024-01-18 09:01:04 +00:00
Sergei Trofimovich
d0fe73a2d5 gcc: extend crtn workaround to alpha target
Without the change `alpha-unknown-linux-gnu` target is failing to build
`gcc`:

```
$ NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix build -f ./. re2c --arg crossSystem '{ config = "alpha-unknown-linux-gnu"; }'
...
make[1]: *** No rule to make target '../../../gcc-12.3.0/libgcc/config/alpha/crti.S', needed by 'crti.o'.  Stop.
...
cc1: error: fp software completion requires '-mtrap-precision=i' [-Werror]
```

After the change it is able to produce working binaries:

```
$ NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix build -f ./. re2c --arg crossSystem '{ config = "alpha-unknown-linux-gnu"; }'
...
$ qemu-alpha ./result/bin/re2c --version
re2c 3.1

$ file result/bin/re2c
result/bin/re2c: ELF 64-bit LSB executable, Alpha (unofficial), version 1 (SYSV), dynamically linked, interpreter ...-glibc-alpha-unknown-linux-gnu-2.38-27/lib/ld-linux.so.2, for GNU/Linux 3.10.0, not stripped
```
2024-01-18 08:30:39 +00:00
Adam Joseph
36f5b2e42b gcc.libgcc: compare host and target platforms, rathern than their triples
The rest of our gcc expression prepends "${targetPlatform.config}-"
to paths and binaries if `hostPlatform!=targetPlatform`.  The
`libgcc.nix` expression was using
'hostPlatform.config!=targetPlatform.config`, which caused it to
look in the wrong place when moving files.  This commit corrects that.
2023-11-04 05:58:23 +00:00
Adam Joseph
425cac96bf gcc: create dummy crtstuff on S390 as well
This commit replicates the fix in
https://github.com/NixOS/nixpkgs/pull/258032 for S390 as well.

Co-authored-by: Artturi <Artturin@artturin.com>
2023-10-25 08:36:22 +00:00
Weijia Wang
0a8e3e0748 gcc: create dummy crtstuff on loongarch64 2023-10-22 09:48:16 +00:00
Alyssa Ross
69b9532a74 gcc: always inhibit libc in cross with same configs
It's not just gcc->clang cross compilation that produces different
platforms with equal configs — dynamic->static cross compilation can
have the same result (e.g. pkgsMusl.pkgsStatic).  So, remove the check
for LLVM, but keep the check that the configs match.

This fixes pkgsMusl.nix on x86_64-linux, which depends on
pkgsMusl.pkgsStatic.buildPackages.gccWithoutTargetLibc.cc.

Fixes: 926c920c12 ("gcc: tighten condition for inhibit_libc=true")
2023-10-10 10:58:44 +00:00
Artturin
fa54cb146a gcc: add fallback to condition
```
> pkgsMusl.nix
error: attribute 'useLLVM' missing

$ nix eval -f . pkgsMusl.pkgsStatic.stdenv.targetPlatform.useLLVM
error: attribute 'useLLVM' in selection path 'pkgsMusl.pkgsStatic.stdenv.targetPlatform.useLLVM' not found
```
2023-10-07 18:26:49 +03:00
Artturi
c748544b2f Merge pull request #241206 from amjoseph-nixpkgs/tighten-inhibit_libc-condition 2023-10-05 04:43:53 +03: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
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
Artturin
3d4e0708a0 gcc: move dll.a in lib64 to lib output too
same as c304c1e7d0
2023-08-29 01:04:15 +03:00
marius david
2eeb227d77 gcc: move dll to output 2023-08-27 21:40:34 +03:00
Adam Joseph
6c8b8bc2f1 gcc: limit gcc12 isMips --disable-libsanitizer to abi=="gnu" 2023-08-23 14:32:50 -07:00
Sergei Trofimovich
a62c92ab9b gcc12: disable libsanitizer for mips64
Without the change build on mips64-unknown-linux-gnu fails as:

        $ nix-build -A buildPackages.gcc12 --argstr crossSystem mips64-linux

        In file included from ...-glibc-mips64-unknown-linux-gnu-2.37-8-dev/include/bits/stat.h:25,
                         from ...-glibc-mips64-unknown-linux-gnu-2.37-8-dev/include/fcntl.h:78,
                         from ../../../../gcc-12.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:55:
        ...-glibc-mips64-unknown-linux-gnu-2.37-8-dev/include/bits/struct_stat.h:190:8: error: redefinition of 'struct stat64'
          190 | struct stat64
              |        ^~~~~~
2023-08-23 14:30:54 -07:00
Adam Joseph
92186a49bf gcc: factor out forceLibgccToBuildCrtStuff 2023-08-14 15:08:28 -07:00
Sergei Trofimovich
3d66844c2d gcc: revert "do not install sys-include headers for cross-compilers."
The change reverts commit 7df4387ebd

A few reasons to revert the commit:
1. The change was not enough to restore `-idirafter` override semantic
   to match unwrapped compiler.
2. The change broke override semantics for cross-compilers
3. The change made override semantics different between cross-compiler
   and native compiler

All of three have some overlap between, but I think it's important
to call all of them out.

The main fallout is the uboot builds, reported by cynerd.

Used the following test to check the override recovery:

    $ nix shell github:NixOS/nixpkgs/release-22.05#pkgsCross.aarch64-multiplatform.stdenv.cc
    $$ cat stdio.h
    # empty
    $$ printf "#include <stdio.h>" | aarch64-unknown-linux-gnu-gcc -E - -o - -idirafter . >/dev/null; echo $?
    0

It failed before the change and succeded after.
2023-07-26 16:40:42 +01:00
Adam Joseph
7621636030 gcc: use Nix instead of bash for conditional
Now that we use the standard builder, the commands produced by
pre-configure.nix are wrapped in a bash function.  Inside of a bash
function, `export foo=` will still add `foo` to the environment of
any child processes forked after that point, but those variables
will *not* be visible to bash code which is outside of the
function-scope in which the `export` occurs.

Weird crap like this is yet another reason why we need to move away
from using bash for logic.  Let's switch.
2023-07-07 05:56:46 -07:00
Adam Joseph
5eaf17927e gcc: add -g to declare
The bash `declare` builtin works differently when it occurs inside
function, as it now does due to breaking up the monolithic
`builder.sh` into separate phases.  We have to add `-g` in order to
get the outside-of-a-bash-function behavior when using `declare`
within a bash function.
2023-07-07 05:56:46 -07:00
Adam Joseph
67da7b9a1f gcc: remove builder.sh 2023-07-07 05:56:44 -07:00
Adam Joseph
1157e1d856 gcc: add args to common/builder.nix, split up script into phases
This commit adds arguments to `builder.nix`, making it a callable
function, and splits up the single massive shell script into
separate attributes for each phase.  It also drops the first two
lines and the last line because these are part of the default
builder.

All script lines which were not part of a phase function have been
moved into `preUnpack` since this is the first phase that runs.
Subsequent commits will move parts of this to more sensible
locations.
2023-07-07 05:55:15 -07:00
Adam Joseph
72284b0d40 gcc: make common/builder.nix into valid Nix syntax
This commit performs two search-and-replace operations:

- replace all `${` with `''${`
- replace `''` with `""` in shell scripts

This commit is left unsquashed to make review of the subsequent
commits easier.
2023-07-07 05:55:15 -07:00
Adam Joseph
caf22a33eb gcc: copy gcc/builder.sh to gcc/common/builder.nix
This commit is left unsquashed to make review of the subsequent
commits easier.
2023-07-07 05:55:15 -07:00
Adam Joseph
926c920c12 gcc: tighten condition for inhibit_libc=true
The situation described in the comment preceding `export
inhibit_libc=true` does not match the conditional which follows it.
Specifically, the comment says that this line is meant for "clang
builds gcc" situations, yet it is enabled even when
`!stdenv.cc.isClang`.

This commit tightens the conditional to make it match the situation
described in the comment.
2023-07-07 03:02:47 -07:00
Adam Joseph
424952b7b4 gccWithoutTargetLibc: link libgcc_s.so using -mnewlib if isPower
Closes #244405

Also adds considerably more commenting to document what is going on.
2023-07-06 05:50:26 -07:00