621 Commits

Author SHA1 Message Date
Eman Resu c543ac2217 cc-wrapper: Don't force outPath comparisons during metadata evaluation (#539613) 2026-07-15 14:25:23 +00:00
Eelco Dolstra 3dc7da509f cc-wrapper: Don't force outPath comparisons during metadata evaluation
Operations like `nix eval --file '<nixpkgs>' hello.name` are supposed
to be lazy in the sense that they shouldn't cause any derivations to
be instantiated. However, this was not the case anymore, e.g.

  $ time nix eval --file '<nixpkgs>' hello.name -vvvvvvv 2>&1 | grep -c 'copying.*to the store\|^instantiated'
  1145
  real    0m0.359s

In fact, even evaluating `lib.version` triggers 1145 paths to be
copied to the store. (Why `lib` causes a bunch of derivations to be
evaluated is another issue...)

The reason for this is that cc-wrapper has assertions like

  assert libc_bin == bintools.libc_bin

which which Nix implements by comparing their outPaths. Computing an
outPath calls derivationStrict, causing the .drv closure of the
bootstrap libc to be written to the store. Since these asserts ran
whenever a cc-wrapper derivation was forced to WHNF (which the stdenv
bootstrap stage assertions do on every evaluation of the Nixpkgs top
level), merely evaluating e.g. 'hello.name' wrote over a thousand .drv
files.

Now the asserts are (arbitrarily) moved under `unpackPhase`, which is
only forced when the derivation is actually instantiated, so
evaluating metadata attributes stays free of store writes:

  $ time nix eval --file '<nixpkgs>' hello.name -vvvvvvv 2>&1 | grep -c 'copying.*to the store\|^instantiated'
  0
  real    0m0.113s

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 15:35:39 +02:00
Sergei Zimmerman c87a95cbd3 cc-wrapper: enable tlsdesc on i686, x86_64 linux
TLSDESC is a more performant way of doing TLS, since it has a custom
calling convention that does not require the caller (of what's usually
__tls_get_addr) to spill clobbered registers and assumes that the callee
preserves all registers.

This adds corresponding plumbing in the machineFlags in the cc-wrapper
that includes version gates for compilers. TLSDESC needs to be supported
by the bintools and libc, so I've only enabled it for architectures that
our packaged glibc, musl, GNU binutils support (x86, x86_64).
We package a lot of LLVM versions and support for -mtls-dialect in the
Clang driver has only landed in LLVM 19, so a version check is added
there too.

Ideally we'd set the default at GCC build-time, but LLVM lacks such an
option, so we'd have to keep it in the compiler wrapper for now.

Gentoo is already building with it by default [1], as is Fedora [2].

In glibc < 2.40 [3] there existed a bug with not all registers being
preserved, but it has since been resolved. x86 support has existed
since basically forever with LLVM adding support in LLVM >= 19.1.
LoongArch support has been added recently too, but it's only available
since musl 1.2.6 while we are stuck at 1.2.5 for now, so I haven't dug
deeper. Aarch64 uses TLSDESC by default already.

The support status on non-Linux is a bit unclear, so these defaults are
scoped only to linux targets.

Sadly RISC-V support is still cooking apparently [4].

See: https://maskray.me/blog/2021-02-14-all-about-thread-local-storage
See: https://groups.google.com/g/x86-64-abi/c/0tjmaQx6nZ0

[1]: https://github.com/gentoo/gentoo/commit/46191b478ebcb6bc6831627526da44f04dfcd1be
[2]: https://src.fedoraproject.org/rpms/gcc/c/8f8d2ea9c326784bce044ff86547107611dda338?branch=rawhide
[3]: https://sourceware.org/bugzilla/show_bug.cgi?id=31372
[4]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/494
2026-05-28 23:38:43 +03:00
Randy Eckenrode 8ffb17ff46 cc-wrapper, gcc, gnat, gnat-bootstrap: fix GCC 13 and GNAT 13/14/15 builds on darwin (#522847) 2026-05-28 03:39:07 +00:00
nixpkgs-ci[bot] 4e29289792 Merge staging-next into staging 2026-05-28 00:40:40 +00:00
zinzilulo 481208bdff cc-wrapper, gcc, gnat, gnat-bootstrap: fix GCC 13 and GNAT 13/14/15 builds on darwin 2026-05-27 18:35:39 +01:00
Aliaksandr 77d67d4b76 cc-wrapper: replace // optionalAttrs with nullable attr names
Inline optionalAttrs for Go passthru attrs and fallback_sdk.
Replace mapAttrs+optionalString for Darwin env vars with direct
optionalString calls, eliminating intermediate attrset and // merge.
2026-05-18 03:54:26 +03:00
Alyssa Ross d2a5a9c051 flang: update support and add flang-rt (#452306) 2026-05-11 14:28:54 +00:00
Acture 6014579a95 clang, cc-wrapper: make wrapper flang-aware
Build on the initial LLVM Flang wrapper work by exposing the needed clang passthru and teaching cc-wrapper about flang-specific flag handling.

Co-authored-by: stove <stove@rivosinc.com>
Co-authored-by: acture <acture@gmail.com>
Co-authored-by: Emily <hello@emily.moe>
Co-authored-by: Philip Taron <philip.taron@gmail.com>
2026-05-04 18:05:42 +08:00
Rasheeq Azad 29101432aa lib.systems.architectures: add rocketlake 2026-05-02 18:47:17 -04:00
Alyssa Ross 8c8a29182c cc-wrapper: remove some trailing and leading spaces (#485593) 2026-03-12 09:29:01 +00:00
Aliaksandr 37a2b8cacc cc-wrapper: remove trailing and leading spaces from flags 2026-03-02 15:49:14 +02:00
David McFarland f5353dd50e cygwin-dll-link: improve search path order
The search order will now be:

1. link target path
2. output bin paths
3. explicit input paths (e.g. libc)
4. HOST_PATH
2026-02-08 19:47:26 -04:00
David McFarland f2ac4eef52 gcc: move cygwin DLLs to $target/bin 2026-02-08 19:47:26 -04:00
David McFarland f42d59445b cygwin-dll-link: move DLLs to $lib/bin by default
This allows us to remove LINK_DLL_FOLDERS and use HOST_PATH instead.
2026-02-08 19:47:25 -04:00
John Ericson 4f217cb085 {cc,bintools}-wrapper: use executable extension when set (#479741) 2026-01-24 18:02:36 +00:00
David McFarland df12a53d55 {cc,bintools}-wrapper: use executable extension when set
On windows platforms we want links to executables to have the .exe
extension, but wrapper scripts shouldn't.
2026-01-13 12:44:10 -04:00
David McFarland 9bbc709586 cc-wrapper: set gl_cv_clean_version_stddef=yes on cygwin 2026-01-02 10:56:48 -04:00
David McFarland d613d20a13 treewide: fix nix-env eval in cross 2025-12-04 19:44:19 -04:00
Sandro 5d48195eb4 cc-wrapper/add-hardening.sh: fix spelling of stackclashprotection hardening (#446243) 2025-10-23 19:08:06 +00:00
Randy Eckenrode 31cf83ad2c cc-wrapper: always include libc++ in the search path (#445095) 2025-10-09 17:49:18 -04:00
Randy Eckenrode 5c2b79edfa cc-wrapper: make availability warnings into errors (#445119) 2025-10-09 13:19:04 -04:00
Randy Eckenrode 76a8ffa6d8 cc-wrapper: use -cxx-isystem instead of -isystem on Clang
This allows Clang to always look for the libc++ headers when compling
C++ code (regardless of whether it is invoked with `clang` or `clang++`
while not exposing the headers when compiling plain C code.

See https://releases.llvm.org/21.1.0/tools/clang/docs/ClangCommandLineReference.html#cmdoption-clang-cxx-isystem-directory
2025-10-09 07:12:15 -04:00
Randy Eckenrode bd0dd33de1 cc-wrapper: always include libc++ in the search path
The libc++ headers are expected to be found in the sysroot when `clang`
is invoked for C++ code.

Always making them available improves compatibility with build systems
like Bazel and SwiftPM, which try to compile C++ code with `clang`.
2025-10-09 07:12:15 -04:00
Robert Scott 2a45fd1039 cc-wrapper: add support for libcxxhardeningfast/extensive hardening flags
as with glibcxxassertions, we don't yet have a nice mechanism
for deferring support decisions to the c++ library in use, so
for now at least enabling this hardening flag will cause
_LIBCPP_HARDENING_MODE to be defined on all compilers
2025-10-08 18:53:17 +01:00
Philip Taron 33816365de {cc-wrapper,bintools-wrapper}: drop pie hardening flag (#442510) 2025-10-07 11:47:04 -07:00
K900 f8d669f413 Merge remote-tracking branch 'origin/master' into staging-next 2025-10-04 21:10:21 +03:00
NAHO c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
K900 4999ae577c Merge remote-tracking branch 'origin/master' into staging-next 2025-09-30 21:47:55 +03:00
Luna Nova 0b3b48fb5f {cc-wrapper,bintools-wrapper}: drop pie hardening flag
We expect compilers to enable PIE by default via --enable-default-pie
or similar.
2025-09-30 09:21:41 -07:00
Randy Eckenrode 369cc5c66b cc-wrapper: make availability warnings into errors 2025-09-29 21:33:09 -04:00
David McFarland 145d9726f3 cc-wrapper: add cygwin libc to dll path
Co-authored-by: Brian McKenna <brian@brianmckenna.org>
2025-09-27 21:21:48 -03:00
David McFarland cba263139f cc-wrapper: add w32api paths on cygwin
Co-authored-by: Brian McKenna <brian@brianmckenna.org>
2025-09-27 13:33:43 -03:00
Sergei Trofimovich 30a9401ba0 cc-wrapper/add-hardening.sh: fix spelling of stackclashprotection hardening
All hardening options have identical spelling to their names except the
`stack-clash-protection`. As a result just copying it to `hardeningDisable`
from the warning log does not work. Let's fix the discrepancy.
2025-09-26 06:45:10 +01:00
nixpkgs-ci[bot] 43a3453b64 Merge staging-next into staging 2025-09-11 00:16:59 +00:00
Alyssa Ross 32a023ac5f cc-wrapper: Make gccgo look like go (#430137) 2025-09-10 18:33:46 +00:00
OPNA2608 335a0cc646 cc-wrapper: Disable format hardening for Go
go1: warning: command-line option '-Wformat=1' is valid for C/C++/ObjC/ObjC++ but not for Go
go1: warning: command-line option '-Wformat-security' is valid for C/C++/ObjC/ObjC++ but not for Go
go1: warning: '-Werror=' argument '-Werror=format-security' is not valid for Go
2025-09-10 17:38:53 +02:00
OPNA2608 57223198e2 cc-wrapper: Add passthrus that make gccgo compatible with buildGoModules/Go assumptions 2025-09-10 16:57:44 +02:00
Ben Siraphob 010527b7d5 pkgs/build-support: fix typos 2025-09-09 13:15:19 +07:00
Robert Scott 3eec07ec59 cc-wrapper: add glibcxxassertions hardening flag
no platforms "unsupported" because we don't have a nice
mechanism for determining a platform's c++ lib and the flag
should be harmlessly ignored by a other c++ libs
2025-08-24 11:56:04 +01:00
K900 e9a7500b70 Merge remote-tracking branch 'origin/master' into staging-next 2025-08-23 09:24:59 +03:00
Emily b5a4a0a6cc {gdc,gdmd}: drop
GDC 11 was the last version that could bootstrap without a D compiler,
and GDC don’t offer their own binaries any more. GCC 11 is now
end‐of‐life and being removed (as is GCC 12, even).

It’s possible that we could use another distribution’s binary
packages to bootstrap this, or go via our DMD package (it’s
apparently not possible to bootstrap GDC with LDC, but I’m not sure
about DMD), but as nobody has worked on it in the three years since
GCC 12 came out, it seems like interest is limited, and it’s more
of a yak shave than I’m up for right now.

A full from‐source bootstrap chain would of course be nice, but is
more the realm of the minimal bootstrap work than something we’d
want to keep GCC 11 around in the main package set indefinitely for.
2025-08-22 23:01:59 +01:00
Emily 5376784348 cc-wrapper: remove dead code for langJava 2025-08-22 23:01:59 +01:00
Emily feb38c0940 cc-wrapper: use -fmacro-prefix-map to scrub __FILE__ references (#429880) 2025-08-03 20:41:44 +01:00
Florian Klink b7f958d5ab cc-wrapper: Workaround gnuabielfv{1,2} support deficiency on Clang (#297425) 2025-07-30 19:58:16 +02:00
Emily a413c6f5b4 cc-wrapper: use -fmacro-prefix-map to scrub __FILE__ references
This accomplishes the same thing as `sanitiseHeaderPathsHook`, but
applies to every build input and should have fewer side effects.
2025-07-29 18:32:43 +01:00
Sergei Trofimovich c331cfe544 cc-wrapper: don't set -fno-omit-frame-pointer on s390/x390x
Without the change both `s390` and `s390x` `glibc` builds fail as
https://hydra.nixos.org/build/303208799:

    In file included from ../sysdeps/s390/utf16-utf32-z9.c:501,
                     from ../sysdeps/s390/multiarch/utf16-utf32-z9.c:20:
    ../iconv/loop.c: In function '__from_utf16_loop_vx_cu':
    ../iconv/loop.c:274:1: error: %r11 cannot be used in 'asm' here
      274 | }
          | ^

Disable the `-fno-omit-frame-pointer` for now.
2025-07-26 12:49:42 +02:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
John Ericson 424f8f2abb gccNGPackages: Force regular dirs
Because we're building things separately, we don't need the fancy
lib/... namespacing tricks that GCC normally does to squeeze itself in
the FHS. We can just use the normal autotools libdir and include dir,
and the nixpkgs infra will sort everything out.

Where possible I submitted patches to the mailing list, and fetched
those. The ones I am vendoring are the residuals which I don't think are
ready for upstreaming yet. (I can imagine a further reworking upstream
such that we wouldn't need our own patches of that sort, but it would be
good to get the first crop merged first before discussing that.)
2025-07-21 15:40:34 -04:00
OPNA2608 07bce58d9c cc-wrapper: Workaround gnuabielfv{1,2} support deficiency on Clang
Clang cannot handle the gnuabielfv{1,2} ABI specification in the triplet properly. It used to parse it as just "gnu", disregarding the ABI version in it and defaulting to ELFv1. Now, it completely fails to parse such target triplet:

> clang: error: version 'abielfv1' in target triple 'powerpc64-unknown-linux-gnuabielfv1' is invalid

So when it comes time to passing the target triplet to Clang, handle this support deficiency:

1. If the triplet ends in gnuabielfv*, shorten it to just gnu. This makes it get parsed properly.
2. After the above, re-add the ABI via the separate -mabi option. This makes it use the correct ABI for the platform.
2025-07-21 14:06:02 +02:00