Commit Graph

513 Commits

Author SHA1 Message Date
Guillaume Girol
4faaa99ff9 glibc: enable structuredAttrs (#548500) 2026-08-15 20:05:45 +00:00
John Ericson
83cb487509 gcc/ng: build libgcc twice, once for the libc and once against it
The libc bootstrap had every stage except the last. `gccNoLibgcc` builds
libgcc, `gccWithLibgcc` builds the libc with it — and then nothing goes
back to rebuild libgcc now that the libc exists. So the only libgcc
anyone ever got was the one from before there was a libc, which is
necessarily single-threaded: `gthr-posix.h` includes `<pthread.h>`
unconditionally, and at that point there is no libc to provide it.
`libstdcxx` above it assumed `posix` regardless, so the two disagreed by
construction — the unwinder's registry locking compiled away to nothing
underneath a `libstdc++` handing out `std::thread`.

Add the last stage the way the LLVM package set does with
`compiler-rt-no-libc` and `compiler-rt-libc`: instantiate the same
package twice. `libgcc-no-libc` is the existing one and now feeds only
the three bootstrap compilers. `libgcc-libc` is built after the libc, by
a new `gccWithLibcAndBasicLibgcc` — real libc, bootstrap libgcc — and is
what `libgcc` resolves to for any platform that has a libc.

Nothing is passed to the package to say which of the two it is. The
distinction is the compiler it is handed, exactly as in the LLVM set:
`gccNoLibgcc` is wrapped with `binutilsNoLibc`, whose `libc` is
`preLibcHeaders` -- the header-only stand-in, or nothing at all on
platforms without one -- and `wrapCCWith` defaults a wrapper's `libc` to
its bintools'. So the package reads `stdenv.cc.libc` and needs no
bootstrap flag of its own.

Which threading model is available is a property of the libc, so the libc
declares it as `passthru.threadModel` and `libgcc` reads it from there.
That is what makes the pre-libc build single-threaded without being told
to be: a headers-only package declares no `threadModel`, a real libc
does.
`libstdcxx` in turn takes both the model and the generated
`gthr-default.h` from `libgcc`, replacing a `$CXX -v` probe that asked
the compiler — which in this package set is configured separately from
libgcc and so answers for the wrong component. Platforms that declare
nothing keep the single-threaded model they already had.

The second libgcc is also the first one that can be shared. Previously
only the static library was built, and the compiler was configured
`--disable-shared` for every target, which is compiled into the driver's
specs, so it named bare `-lgcc` and never `-lgcc_s`:

    $ x86_64-unknown-netbsd-g++ -### eh.cc
    collect2 ... -lstdc++ -lm -lgcc -lc -lgcc

Both halves have to move together. Build the shared library without
changing the specs and the unwinder leaves `libgcc.a` while the specs
still name it:

    libgcc.a         _Unwind_RaiseException: absent
    libgcc_eh.a      _Unwind_RaiseException: present
    libgcc_s.so.1    _Unwind_RaiseException: present

so every throwing C++ program fails to link and `rustc` fails on
`-lgcc_s` outright. Either standard arm would do, `-lgcc_s -lgcc` shared
or `-lgcc -lgcc_eh` static; the halves disagreeing is what breaks.

`--disable-shared` was passed to libgcc with the comment "Do not have
dynamic linker without libc". That does not hold: the monolithic build
ships `libgcc_s` even from its *nolibc* cross stage, and the result needs
nothing at run time --

    $ readelf -d .../nolibc-gcc-15.3.0-libgcc/.../libgcc_s.so.1
     0x...0e (SONAME)  Library soname: [libgcc_s.so.1]
    (no NEEDED entries at all)

What genuinely blocks it is libgcc's own makefile: `SHLIB_LC` defaults to
`-lc`, so the `libgcc_s.so` rule links against a libc that does not exist
yet and fails with `cannot find -lc`. The monolithic build clobbers that
variable -- see `common/libgcc-buildstuff.nix` -- so reuse that helper
rather than reinventing it. On the compiler side the flag derives from
`hasSharedLibraries`, as the monolithic build does, so a target genuinely
without shared libraries keeps the old behaviour; it is spelled
`enableTargetShared` there because it describes the target's libgcc
rather than anything about the compiler being built.

Verified on `x86_64-unknown-netbsd`, where `libgcc_s.so.1` and the
`GROUP ( libgcc_s.so.1 -lgcc )` script now appear in the output, and by
building `stdenv.cc` for `aarch64-unknown-linux-gnu` and
`aarch64-unknown-linux-musl`.

Assisted-by: Claude Code (Claude Opus 5)
2026-08-12 16:59:29 -04:00
Stefan Frijters
39953932fe glibc: enable structuredAttrs 2026-08-02 20:18:37 +02:00
Maximilian Bosch
2078e14914 glibc: fix CVE-2026-5435 and CVE-2026-6238 (#537324) 2026-07-11 14:53:58 +00:00
Maximilian Bosch
a6735426ca set default zonedir to match fhs (#491193) 2026-07-04 09:18:03 +00:00
Matthew Donoughe
8746d3caee glibc: set default zonedir to match fhs 2026-07-03 15:01:11 -04:00
Julian Stecklina
8515b91b88 glibc: fix CVE-2026-5435 and CVE-2026-6238
The fixes were backported from glibc master and had some slight
conflicts.
0001-resolv-Check-for-inet_ntop-failure-in-ns_sprintrrf.patch was
backported to avoid having to modify the fix for CVE-2026-6238.
2026-07-01 10:47:23 +02:00
zowoq
bbacb13154 glibc: 2.42-61 -> 2.42-67
(cherry picked from commit 4a8e8392a4)
(cherry picked from commit e0c442323b)
2026-06-22 08:15:14 +02:00
zowoq
4a8e8392a4 glibc: 2.42-61 -> 2.42-67 2026-05-19 16:51:53 +10:00
Maximilian Bosch
c66e479167 glibc: 2.42-58 -> 2.42-61, fixes CVE-2026-4438
Wasn't backported to the 2.42 branch when I bumped for CVE-2026-4437 (#503779).
2026-04-04 08:25:52 +02:00
Jo
651cf04318 glibc,iconv,libc,mtrace: move NIX_NO_SELF_RPATH into env (#502497) 2026-04-01 11:00:39 +00:00
Maximilian Bosch
d8593ca802 glibc: 2.42-51 -> 2.42-58, fix CVE-2026-4437
Closes #502536
2026-03-26 16:54:01 +01:00
Stefan Frijters
95a44252d1 glibc,iconv,libc,mtrace: move NIX_NO_SELF_RPATH into env
glibc/locales.nix and gcc have it in env as well.
2026-03-23 11:07:35 +01:00
nixpkgs-ci[bot]
23ee7d594c Merge master into staging-next 2026-03-14 00:21:49 +00:00
Alexander Bantyev
2839911e81 various: add security-review team as a maintainer
Adds the @NixOS/security-review team as a maintainer to multiple
packages deemed to be important security-wise.

For the motivation of the package list, see:
https://github.com/NixOS/nixpkgs/issues/494349#issuecomment-4005099033
2026-03-05 15:19:44 +01:00
Maximilian Bosch
b8a75f52fa glibc: add gettext to nativeBuildInputs (#493023) 2026-02-28 19:38:52 +00:00
David Wronek
b7e62e3e73 glibc: add gettext to nativeBuildInputs
The `gettext` package is required in order to build and install the libc
message catalogs.

Previously, glibc was falling back to the C locale, even though the
default locale has been changed (e.g. to de_DE.UTF-8):
```
rm: das Entfernen von 'file' ist nicht möglich: No such file or directory
```

With this change, the whole string will be translated to the desired
locale:
```
rm: das Entfernen von 'file' ist nicht möglich: Datei oder Verzeichnis nicht gefunden
```

Signed-off-by: David Wronek <david.wronek@mainlining.org>
2026-02-22 13:59:45 +01:00
Fabián Heredia Montiel
d80b1bccd5 Merge remote-tracking branch 'origin/master' into staging-next 2026-02-17 12:29:41 -06:00
Alexander Bantyev
22ca96f3a9 various: add meta.identifier.cpeParts to a batch of packages
Co-Authored-By: Silvan Mosberger <silvan.mosberger@tweag.io>
2026-02-16 17:11:52 +01:00
K900
0cb3a504cb Merge remote-tracking branch 'origin/staging-next' into staging 2026-02-05 21:26:34 +03:00
Doron Behar
98cb67f886 glibc: Fix _CS_PATH to include default profile (#94937) 2026-01-29 14:26:24 +00:00
Martijn Dekker
260335ada9 glibc: Fix _CS_PATH to include default profile
The string returned by confstr(_CS_PATH)[*1], which is also the
output of the command 'getconf PATH'[*2], contains a default path
that is guaranteed to find (at least) all POSIX standard utilities.
The current value is:

    /run/current-system/sw/bin:/bin:/usr/bin

The default profile binaries directory is not in it. This is a problem
because the default NixOS installation lacks several mandatory standard
POSIX utilities. The command recommended by the system's error message
for a missing command to install a missing package foo is 'nix-env -iA
nixos.foo'. When this is done as root, the corresponding binaries are
installed for all users in /nix/var/nix/profiles/default/bin.

This commit fixes these problems as follows:

pkgs/development/libraries/glibc/fix_path_attribute_in_getconf.patch:
- CS_PATH: Add default profile path '/nix/var/nix/profiles/default/bin'
  at the end.
- Retain /bin:/usr/bin; it is necessary for third-party sytems that use
  nixpkgs, linking against the nixpkgs version of glibc. It is retained
  *before* the profile directory to avoid overriding native system
  utilities on these systems (at least those that in fact store them in
  /bin and /usr/bin).

[*1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/confstr.html
[*2] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/getconf.html

Fixes: https://github.com/NixOS/nixpkgs/issues/65512
2026-01-28 22:21:55 +00:00
Jörg Thalheim
bbffe120eb glibc: fix darwin-cross-build.patch for glibc 2.42
The darwin-cross-build.patch failed to apply when cross-compiling glibc.

Regenerate the patch against glibc 2.42 sources. Also extend the
patch to cover the 'check xcheck test' target which was previously
unpatched but needs the same ulimit and AR fixes for consistency.

Tested: nix build --file . pkgsCross.aarch64-multiplatform.glibc
Tested: nix build --file . pkgsCross.gnu64.glibc
2026-01-26 19:31:47 +01:00
Maximilian Bosch
7ba104638e glibc: 2.42-50 -> 2.42-51, fixes CVE-2025-15281
Closes #482394

Seems like low-severity, given

> There is no known application impact for this CVE, and the
> feature is generally non-functional with the two flags.

(from https://sourceware.org/bugzilla/show_bug.cgi?id=33814)
2026-01-22 09:42:33 +01:00
Maximilian Bosch
809c1fc759 glibc: 2.42-47 -> 2.42-50, fixes CVE-2026-0915, CVE-2026-0861
Closes #480802
2026-01-17 08:00:47 +01:00
K900
055ff17e06 glibc: fix path derp on cross 2026-01-15 11:20:38 +03:00
Maximilian Bosch
6585c8e80a glibc: make it easier to work with a dev shell
Creating the build directory in `..` may be OK in a sandbox, but this
makes it unnecessarily annoying when trying to work with this in a
source-checkout.

Hence, move the `build/` directory into the source tree.
2026-01-03 20:39:43 +01:00
Maximilian Bosch
190f166df8 glibc: 2.40-66 -> 2.42-47
Announcements:
* https://lists.gnu.org/archive/html/info-gnu/2025-01/msg00014.html
* https://lists.gnu.org/archive/html/info-gnu/2025-07/msg00011.html
2025-12-30 14:57:10 +01:00
Ihar Hrachyshka
567e8dfd8e treewide: clean up 'meta = with' pattern
This commit was created by a combination of scripts and tools:
- an ast-grep script to prefix things in meta with `lib.`,
- a modified nixf-diagnose / nixf combination to remove unused `with
lib;`, and
- regular nixfmt.

Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
2025-12-10 18:09:49 +01:00
Luna Nova
e7fbed853b treewide: remove usages of obsolete pie hardening flag 2025-10-09 10:13:03 -07:00
Maximilian Bosch
700d7ec879 glibcLocales: re-enable parallel build
This was originally turned off in #245360 because the approach was
non-reproducible, i.e. all N concurrent jobs were racing to update
`locale-archive`.

glibc's localedef allows to separate the build from the install, i.e.
`localedef --no-archive` allows to only perform the build of the locale
which can be parallelized again. After that, a single process adds all
newly built locales into the archive.

This isn't supported by the Makefiles in upstream glibc yet[1], hence
the additional patches.

For me, this reduces the build-time of `pkgs.glibcLocales` from ~7min to
slightly under 1min.

[1] https://sourceware.org/pipermail/libc-alpha/2025-October/170803.html
2025-10-05 23:00:57 +02:00
Maximilian Bosch
cfb771c8a5 glibcLocales: remove builder
There's no particular reason to have a special builder. Fold all the
changes it made into the derivation.
2025-10-05 23:00:55 +02:00
Maximilian Bosch
bbe152dcfe glibcLocales: use substituteInPlace for Makefile fix
That way we'll notice if the code changes to examine if this either
needs to be updated or removed.
2025-10-05 13:07:29 +02: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
Maximilian Bosch
7c104c9ba3 glibc: 2.40-66 -> 2.40-142, fix CVE-2025-8058
See https://nvd.nist.gov/vuln/detail/CVE-2025-8058

Updating to the latest patch-level of the 2.40 branch to address this.
2025-07-24 20:07:04 +02:00
Wolfgang Walther
90604d95bc Merge branch 'staging-next' into staging 2025-07-24 14:33:09 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Dmitry Bogatov
2a9a83e489 glibc: Fix build with gcc-15 2025-07-19 13:13:31 +00:00
Niklas Hambüchen
fe86ff2cd8 glibc: add comments describing the patches (#421492) 2025-07-01 15:38:04 +02:00
Alexander Bantyev
22e563fc3d glibc: add comments describing the patches
This simply adds some comments describing previously undocumented
patches.
2025-07-01 16:48:42 +04:00
nixpkgs-ci[bot]
6382019211 Merge master into staging-next 2025-06-07 18:05:03 +00:00
Winter
05482c6b79 glibc: allow easier overriding of linux headers package
Before this change, one would have to `callPackage` `common.nix` manually,
but now this can be done via `glibc.override`.
2025-06-04 11:31:43 -04:00
Philip Taron
b76868988b cc-wrapper: add support for strictflexarrays1 & strictflexarrays3 hardening flags (#400408) 2025-05-26 10:46:00 -07:00
Robert Scott
e7faa8bad7 glibc: disable strictflexarrays3 hardening flag 2025-05-24 11:10:22 +01:00
Maximilian Bosch
2f4c74906d glibc: use secure_getenv for loading locale archive
To quote `getenv(3)`:

> The  GNU-specific  secure_getenv()  function  is just like
> getenv() except that it returns NULL in cases where "secure
> execution" is required.

One of these cases is running in setuid mode. In this case, one could
make `sudo` load an arbitrary file as locale archive by modifying the
LOCALE_ARCHIVE env variable accordingly.

After consultation with the security team we came to the conclusion that
this is not exploitable by itself since it'd need another issue that
can be triggered by a maliciously crafted locale archive. Since this is
a valid issue nonetheless[1], I decided to fix it, but go through the
normal PR & staging lifecycle.

This patch also adds another fallback to
`/run/current-system/sw/lib/locale/locale-archive`: otherwise `sudo`
would fail to load any locale archive since that would be in
LOCALE_ARCHIVE/LOCALE_ARCHIVE_2_27 and thus setuid programs would
regress on translated output.

Thank you to Elliot Cameron for reporting this.

[1] glibc's internal environment filtering also prevents setuid
    processes to use certain locale settings from the environment
    such as LOCPATH.
2025-05-17 13:27:31 +02:00
Vladimír Čunát
487243d40a glibc: install C.utf8 into locale dir instead of archive (#382522) 2025-03-03 08:16:45 +01:00
Maximilian Bosch
1158cd5c13 glibc: install C.utf8 into locale dir instead of archive
Addresses further comments in #347965

On a Ubuntu machine with only C.utf-8 installed, you'd still get

    perl: warning: Setting locale failed

since C.utf-8 is installed into `/usr/lib/locale` directly rather than
the archive.

`glibc` will first try to find a locate in the archive[1] and then fall
back to `lib/locale`[2]. This means that Ubuntu applications still find
C.utf-8 since its glibc finds it in `/usr/lib/locale`. However, Nix
built applications don't since they fall back to the system-wide archive
in `/usr/lib/locale/locale-archive`.

This patch changes our glibc to do the same what Ubuntu does: C.utf-8 is
installed into `$out/lib/locale`. If the systemd-wide locale archive
doesn't have C.utf-8, glibc now falls back to looking in
`$out/lib/locale`.

I confirmed on an Ubuntu 24.04 VM with empty locale archive that a
`cowsay` built on this branch falls back to `$out/lib/locale`:

    /* exists, but empty */
    openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
    [...]
    /* fallback */
    openat(AT_FDCWD, "/nix/store/vckzn6k0648yas09c58aq05bav82l46x-glibc-2.40-66/lib/locale/C.utf8/LC_IDENTIFICATION", O_RDONLY|O_CLOEXEC) = 3

I checked that this doesn't have obvious regressions on NixOS by
building the synapse test on this branch since synapse explicitly
depends on C.utf8 in PostgreSQL.

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/findlocale.c;h=e5e2bd3974fe4fd31ae3567d411f1f84dccf8573;hb=HEAD#l152
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/findlocale.c;h=e5e2bd3974fe4fd31ae3567d411f1f84dccf8573;hb=HEAD#l167
2025-03-02 22:39:56 +01:00
Tim
eaee7b7a45 glibc_multi: add output "static"
This change enables static compilation with glibc in a multilib setup. For
building a nix shell the output can now be referenced as follows:

devShells.default = pkgs.mkShell {
    packages = [
        pkgs.glibc_multi.static
    ];
};

In the implementation I was forced to make two design decisions:
1. The directory `$static/lib64` has to be a "real" directory and not a symlink.
   Otherwise, the path to this directory is not added to $NIX_LDFLAGS, which in
   turn causes the files to not be visible to gcc and ld during the build
   process (for details see `pkgs/build-support/bintools-wrapper/setup-hook.sh`
   line 16).
2. The directories `$static/lib` and `$static/lib64` have to contain symlinks
   to both the files used for static and for dynamic linking (i.e. the outputs
   of `static` and `out` of the 32 and 64 bit variant of glibc). Without this,
   dynamic linking still works, however the resulting binaries will segfault.
2025-02-17 12:52:56 +01:00
Thomas Gerbet
ca851b6f12 glibc: 2.40-36 -> 2.40-66
Fixes CVE-2025-0395 / GLIBC-SA-2025-0001
https://sourceware.org/git/?p=glibc.git;a=blob;f=advisories/GLIBC-SA-2025-0001;h=45f8b8f181fa024611452518ca0147ede1b88c47;hb=d9dcfe766eb9adcf9b1143112b569ac34ea9a9e6
https://www.openwall.com/lists/oss-security/2025/01/22/4
2025-01-23 21:23:13 +01:00
Maximilian Bosch
753f9a37bd Merge: glibc: avoid overriding makeFlags (#368865) 2025-01-02 13:01:09 +01:00