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_*.clangUseLLVM: add libunwind to lib search path (#201591) #220520

Merged
merged 1 commit into from
Jan 13, 2024

Conversation

SharzyL
Copy link
Contributor

@SharzyL SharzyL commented Mar 10, 2023

Description of changes

resolves #201591

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • 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.05 Release Notes (or backporting 22.11 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.

@sternenseemann
Copy link
Member

I guess that brings us to the old question of whether clangUseLLVM should be used/usable for anything else but as an implementation detail of how pkgsLLVM.stdenv is bootstrapped. But since it is exposed so prominently it should probably do something, @Ericson2314?

@ehmry
Copy link
Contributor

ehmry commented Mar 11, 2023

Stale but related #207325.

Copy link
Contributor

@pwaller pwaller left a comment

Choose a reason for hiding this comment

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

I think the change is needed to make nix shell nixpkgs#pkgsLLVM.stdenv.cc be a functioning compiler.

On master prior to this patch, clangUseLLVM gives you a functioning compiler if the stdenv is used to build software, but then if you try to use the compiler outside of the stdenv it fails. The reason is that the binutils setup hook propagates libunwind (and other runtimes) into the NIX_LDFLAGS when you're in the stdenv because these packages are specified in extraPackages.

Since -lunwind and friends are a part of the compiler wrapper, it makes sense to me that the -L flags should also be a part of the wrapper, as you have done here.

Just one comment that they'll need conditionalising, I think -L/path/to/unwind should only be added if -lunwind is being added, it might be that the package won't build outside of those scenarios for example.

@@ -155,6 +155,7 @@ let
extraBuildCommands = ''
echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
echo "-L${targetLlvmLibraries.libunwind}/lib" >> $out/nix-support/cc-ldflags
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the library is conditional on !isWasm below and targetPlatform.useLLVM, this should probably be along side that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clang links against libunwind when -unwindlib=libunwind is set. Hence if conditioning on targetPlatform.useLLVM, llvmPackages.clangUseLLVM still cannot find libunwind.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's definitely curious that we gate -lunwind on targetPlatform.useLLVM but not --unwindlib=libunwind.

Tracing back to where the -lunwind was added doesn't reveal any obvious reason for the discrepancy and I'm actually not clear on why the -lunwind was needed in the first place (my understanding is that it's implied). Perhaps there were scenarios where the linker was being invoked directly with the expectation that libunwind would be pulled in?

Regardless, doesn't need to block this PR. Adding this -L in shouldn't hurt.

@pwaller
Copy link
Contributor

pwaller commented Oct 14, 2023

cc @reckenrode are you aware of whether this could cause problems on darwin?

@reckenrode
Copy link
Contributor

cc @reckenrode are you aware of whether this could cause problems on darwin?

I shouldn’t think so. The only risk would be if it could cause an infinite recursion, but the ofborg eval check should catch that.

@SharzyL
Copy link
Contributor Author

SharzyL commented Oct 15, 2023

Rebased the commit and added conditioning on !isWasm now.

Copy link
Contributor

@pwaller pwaller left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, unfortunately I don't have commit rights. @reckenrode ? @RaitoBezarius ?

Copy link
Contributor

@rrbutani rrbutani left a comment

Choose a reason for hiding this comment

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

I think @sternenseemann's question is the right one. It would be nicer to have something other than clangUseLLVM intended for use outside of stdenv but in the interim I think it makes sense to merge this fix.

It would be nice if we could have a test guarding against regressions but that doesn't need to block this PR.

@SharzyL thanks for your patience.

@rrbutani rrbutani added 12.approvals: 2 This PR was reviewed and approved by two reputable people 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package labels Oct 31, 2023
@RaitoBezarius
Copy link
Member

Apologies for the delay, @SharzyL can you rebase for the conflicts and after that we go for the merge IMHO.

@SharzyL
Copy link
Contributor Author

SharzyL commented Jan 13, 2024

Rebase is complete

@RaitoBezarius RaitoBezarius merged commit 81784c6 into NixOS:staging Jan 13, 2024
19 checks passed
@RaitoBezarius
Copy link
Member

This probably should not have targeted staging given the low amount of rebuilds, but well, it can wait staging :).

@wegank
Copy link
Member

wegank commented Mar 12, 2024

Is the exclusion of LLVM 17 intended in this PR?

@SharzyL
Copy link
Contributor Author

SharzyL commented Mar 12, 2024

Probably a omittance during rebase

ghost pushed a commit that referenced this pull request Mar 27, 2024
ghost pushed a commit that referenced this pull request Mar 27, 2024
llvmPackages_17.clangUseLLVM: apply omitted #220520
@rrbutani rrbutani added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label May 27, 2024
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: 1-10 10.rebuild-linux: 11-100 12.approvals: 2 This PR was reviewed and approved by two reputable people 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants