Skip to content

llvmPackages.libunwind: condition doFakeLibgcc on !stdenv.hostPlatform.isStatic#417354

Merged
alyssais merged 1 commit intoNixOS:masterfrom
pwaller:fix-libunwind
Sep 30, 2025
Merged

llvmPackages.libunwind: condition doFakeLibgcc on !stdenv.hostPlatform.isStatic#417354
alyssais merged 1 commit intoNixOS:masterfrom
pwaller:fix-libunwind

Conversation

@pwaller
Copy link
Copy Markdown
Contributor

@pwaller pwaller commented Jun 16, 2025

Since #380683, broken symlinks prevent the package from building on pkgsStatic.pkgsLLVM.

So far as I know, isStatic builds don't have shared objects, so don't emit these broken symlinks for them.

Closes #431439

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/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (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, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

…m.isStatic

Since NixOS#380683, broken symlinks prevent the package from building on
pkgsStatic.pkgsLLVM.

So far as I know, isStatic builds don't have shared objects, so don't
emit these broken symlinks for them.

Signed-off-by: Peter Waller <p@pwaller.net>
libcxx,
enableShared ? !stdenv.hostPlatform.isStatic,
doFakeLibgcc ? stdenv.hostPlatform.useLLVM,
doFakeLibgcc ? stdenv.hostPlatform.useLLVM && !stdenv.hostPlatform.isStatic,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right, we can easily fix the error by referring to the library extension in hostPlatform.

library = if final.isStatic then final.extensions.staticLibrary else final.extensions.sharedLibrary;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more complicated than this because:

  1. I don't think we should be making libgcc available if we're stdenv.hostPlatform.useLLVM and it's static. (At least, if we do, I'm unaware of a use case, because this never worked before, so I'm unaware of an obvious test case for this)
  2. libgcc_s is the shared version, I think the static version is a combination of libgcc.a and libgcc_eh.a, or something like this.

See for example: #177129

One possibility here is to provide a libgcc_eh.a in this case, which I think would provide a workaround the above bug. One way to provide libgcc_eh.a is just to do touch libgcc_eh.a, which provides a valid empty ar file. I believe there is nothing provided by libgcc_eh which isn't provided by libunwind in nixpkgs' typical scenarios with useLLVM && isStatic.

IIUC, the problem is rooted in GCC providing different libraries depending on whether it was compiled with --enable-shared, and clang doesn't know about this (or at least didn't, last time I checked), so it always requests libgcc_eh even though sometimes it doesn't exist. I'm currently thinking there must be another workaround for this somewhere because it has been a while since I hit it.

So, I might propose to touch libgcc_eh in this case, and mark this as fixing #177129 too. Thoughts?

@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Jun 16, 2025
@pwaller
Copy link
Copy Markdown
Contributor Author

pwaller commented Jul 4, 2025

Ping @RossComputerGuy

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/build-error-llvmpackages-libunwind/66874/3

@sukhmel
Copy link
Copy Markdown

sukhmel commented Jul 18, 2025

how is it possible to check if the build is still broken?

nix build ".#pkgsCross.musl64.pkgsStatic.pkgsLLVM.libunwind" seems to not build while nix build ".#pkgsCross.musl64.pkgsStatic.llvmPackages.libunwind" builds, is that expected?

sukhmel pushed a commit to sukhmel/nixpkgs-cross-overlay that referenced this pull request Jul 18, 2025
…rom `nixos-24.11`

libunwind is broken in "nixpkgs#pkgsCross.musl64.pkgsStatic.pkgsLLVM.libunwind", see NixOS/nixpkgs#417354

This hack is not the best solution, but it's the only one I was able to hack together. I think it would be better to override `libunwind` in `stdenv`, but I wasn't able to do that.
@RossComputerGuy
Copy link
Copy Markdown
Member

pkgsCross.musl64.pkgsStatic.pkgsLLVM.libunwind is not LLVM's libunwind.

@sukhmel
Copy link
Copy Markdown

sukhmel commented Jul 18, 2025

@RossComputerGuy okay, but what is? What is the derivation that is being fixed by this PR?

@RossComputerGuy
Copy link
Copy Markdown
Member

pkgsStatic.llvmPackages.libunwind

@pwaller
Copy link
Copy Markdown
Contributor Author

pwaller commented Jul 18, 2025

@RossComputerGuy do you have any thoughts on my comment above? Is this actionable or dead? Can we move this forward in that it improves upon the status quo?

@sukhmel
Copy link
Copy Markdown

sukhmel commented Jul 19, 2025

pkgsCross.musl64.pkgsStatic.pkgsLLVM.libunwind is not LLVM's libunwind.
pkgsStatic.llvmPackages.libunwind

I'm not sure this is really what I have a problem with. Here's a command that fails for me in the first place, and the relevant output:

$ nix-shell -p llvmPackages.libunwind --arg crossSystem "{ config = \"x86_64-unknown-linux-musl\"; useLLVM = true; isStatic = true; }"
error: builder for '/nix/store/37c7kf9nxrp464jqnfgj3qs82x77m7cf-libunwind-static-x86_64-unknown-linux-musl-19.1.7.drv' failed with exit code 1;
error: build of '/nix/store/37c7kf9nxrp464jqnfgj3qs82x77m7cf-libunwind-static-x86_64-unknown-linux-musl-19.1.7.drv', '/nix/store/x5lg2794qwshhf2wn7x1xjs7w3lm4jqy-stdenv-darwin.drv' failed

Here's output for the package I found to be broken:

$ nix build "nixpkgs#pkgsCross.musl64.pkgsStatic.pkgsLLVM.libunwind"
error: builder for '/nix/store/37c7kf9nxrp464jqnfgj3qs82x77m7cf-libunwind-static-x86_64-unknown-linux-musl-19.1.7.drv' failed with exit code 1;
error: 1 dependencies of derivation '/nix/store/0lwi60brs5hh3ra6kx6mvxx6r2k3pcjq-x86_64-unknown-linux-musl-clang-wrapper-19.1.7.drv' failed to build
error: 1 dependencies of derivation '/nix/store/x5lg2794qwshhf2wn7x1xjs7w3lm4jqy-stdenv-darwin.drv' failed to build
error: 1 dependencies of derivation '/nix/store/bww0w4qvmqc6mqsz2v46vyk78ibdv2if-libunwind-static-x86_64-unknown-linux-musl-1.8.1.drv' failed to build

Here's the output for llvmPackages substituted:

$ nix build "nixpkgs#pkgsCross.musl64.pkgsStatic.llvmPackages.libunwind"
$ readlink result                                                
/nix/store/5q7hm778z78kg0dzsgzk16p66rargvqn-libunwind-static-x86_64-unknown-linux-musl-19.1.7
$ ls -la result/lib
.r--r--r-- 136k root  1 Jan  1970 result/lib/libunwind.a

So to summarise:

  1. the command works with pkgsCross.musl64.pkgsStatic.llvmPackages.libunwind,
  2. fails on the same file with pkgsCross.musl64.pkgsStatic.pkgsLLVM.libunwind and nix-shell -p llvmPackages.libunwind --arg crossSystem "{ config = \"x86_64-unknown-linux-musl\"; useLLVM = true; isStatic = true; }"
  3. but it fails directly in case of nix-shell, and in dependencies in case of a nix build, so it must be a wrong package still

Upd: just to be sure, I tried building a failing package in pwaller/nixpkgs/fix-libunwind and it build without issues

@RossComputerGuy
Copy link
Copy Markdown
Member

We don't support this on Darwin, please use a Linux system.

@RossComputerGuy
Copy link
Copy Markdown
Member

do you have any thoughts on my comment above? Is this actionable or dead? Can we move this forward in that it improves upon the status quo?

I think it's good.

@sukhmel
Copy link
Copy Markdown

sukhmel commented Jul 19, 2025

We don't support this on Darwin, please use a Linux system.

this doesn't work on my linux CI either, but it takes forever to push to CI and wait for it to break, trying to guess what is the correct package name to try building. On Linux, we still run a cross compilation build, because it's set up that way and I am not really up to changing this.

Upd: this is the output of the initial whole broken build on Linux machine:

ERROR: noBrokenSymlinks: the symlink /nix/store/3lybj15xkhmnwijflvyfahki2y8ckica-libunwind-static-x86_64-unknown-linux-musl-19.1.7/lib/libgcc_s.so points to a missing target: /nix/store/3lybj15xkhmnwijflvyfahki2y8ckica-libunwind-static-x86_64-unknown-linux-musl-19.1.7/lib/libunwind.so
ERROR: noBrokenSymlinks: the symlink /nix/store/3lybj15xkhmnwijflvyfahki2y8ckica-libunwind-static-x86_64-unknown-linux-musl-19.1.7/lib/libgcc_s.so.1 points to a missing target: /nix/store/3lybj15xkhmnwijflvyfahki2y8ckica-libunwind-static-x86_64-unknown-linux-musl-19.1.7/lib/libunwind.so
ERROR: noBrokenSymlinks: found 2 dangling symlinks, 0 reflexive symlinks and 0 unreadable symlinks
error: builder for '/nix/store/r51r87qla7afsk1qlml8iz7zzmk716qw-libunwind-static-x86_64-unknown-linux-musl-19.1.7.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/2y2qvjgmq3js76mhijh4nnixdxa51qqd-x86_64-unknown-linux-musl-clang-wrapper-19.1.7.drv' failed to build
error: 1 dependencies of derivation '/nix/store/shwq2yrnzr02dz3fxid7rjl2qsksa4rp-rust-default-1.88.0.drv' failed to build
error: build of '/nix/store/jb8v8041cbrwhyxqv86flkklz3bzrzhb-docker-27.5.1.drv', '/nix/store/mvcsvkk35r1pm2zw2hl26zcfkj2m5c0l-stdenv-linux.drv', '/nix/store/shwq2yrnzr02dz3fxid7rjl2qsksa4rp-rust-default-1.88.0.drv' failed

@RossComputerGuy
Copy link
Copy Markdown
Member

Hmm, I'll give it a try after work tonight.

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-modify-cmakeflags-in-a-library-in-llvmpackages-in-a-cross-compile-flake/69644/1

@alyssais alyssais disabled auto-merge September 30, 2025 15:18
@alyssais alyssais closed this Sep 30, 2025
@alyssais alyssais reopened this Sep 30, 2025
@alyssais alyssais enabled auto-merge September 30, 2025 15:26
@alyssais alyssais added this pull request to the merge queue Sep 30, 2025
@nix-owners nix-owners bot requested a review from emilazy September 30, 2025 15:31
Merged via the queue into NixOS:master with commit 05a384c Sep 30, 2025
40 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure: pkgsStatic.pkgsLLVM.llvmPackages.libunwind

5 participants