Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvmPackages_*.stdenv: use top-level libc++ on Darwin #264091

Closed
wants to merge 18 commits into from

Conversation

reckenrode
Copy link
Contributor

@reckenrode reckenrode commented Oct 29, 2023

Description of changes

This PR is an alternative to #263847 to resolve the nodejs_18 crashes in staging-next #263535.

Instead of overriding the version of libc++ used by clang in each derivation, this PR moves that logic to llvmPackages_*.clang. This allows llvmPackages_*.stdenv to build with one version of clang while linking dependencies built with different versions of clang (because they all use the same libc++), which helps avoid crashes at runtime.

This approach is similar to how the llvmPackages_*.stdenv works with Linux, which uses the same libstdc++ regardless of clang version. While libc++ maintains ABI compatibility, newer headers are not compatible with older compilers. This is addressed by using the original headers with the new libc++ (due to libc++’s ABI stability).

This PR was tested with nodejs_14, nodejs_16, nodejs_18, and Swift (which also performed this override). All built successfully. paperless-ngx.frontend was also built successfully to test node. Other packages built successfully include darktable (clang 13), cone (clang 7), and dar (clang 12).

Users who wish to use a specific version of libc++ with clang can continue using llvmPackages_*.libcxxClang and llvmPackages_*.libcxxStdenv.

Closes #263847.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
This change treats the top-level libc++ as the “system” libc++ on
Darwin, matching the way libstdc++ is used on Linux. The approach it
takes is to use the requested version’s libc++ headers while linking
against the top-level library. This is safe to do because libc++ is
built with the stable ABI on Darwin by default.

This change is necessary to support building a package with one version
of clang while linking against libraries that are built with different
versions. Otherwise, if they both use C++, they will link against
different versions of libc++ and (probably) crash at runtime. Examples of
where this is an issue include older versions of nodejs building with
clang 15 and darktable (which is currently built with clang 13).
Trying to backport the fixes from v8 caused crashes with npm when
building other packages, so just build it with clang 15
@reckenrode reckenrode changed the title llvmPackages_*\.stdenv llvmPackages_*.stdenv Oct 29, 2023
@wegank
Copy link
Member

wegank commented Oct 30, 2023

Can confirm that this PR fixes #244319.

@reckenrode reckenrode marked this pull request as draft October 30, 2023 15:55
@reckenrode
Copy link
Contributor Author

Converting this to draft since it missed the deadline for breaking LLVM changes. I’ll pick it back up post-23.11.

@reckenrode reckenrode changed the title llvmPackages_*.stdenv llvmPackages_*.stdenv: use top-level libc++ on Darwin Oct 30, 2023
@vcunat vcunat changed the base branch from staging-next to staging October 30, 2023 16:35
@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Oct 30, 2023
reckenrode added a commit to reckenrode/nixpkgs that referenced this pull request Nov 4, 2023
This was taken from NixOS#264091 to use in the interim before that PR lands
(sometime after the release of 23.11). It allows different versions of
clang to link the same libc++, allowing dependencies to be linked when
they are built with a different version of clang than the stdenv.
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 20, 2024
@rrbutani rrbutani added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label May 27, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@aviallon
Copy link
Contributor

Closed by #346043

@aviallon aviallon closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: darwin Running or building packages on Darwin 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: nodejs 10.rebuild-darwin: 501-1000 10.rebuild-darwin: 501+ 10.rebuild-linux: 501+ 10.rebuild-linux: 1001-2500
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants