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

cc-wrapper: Account for NIX_LDFLAGS and NIX_CFLAGS_LINK in linkType #253116

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

pwaller
Copy link
Contributor

@pwaller pwaller commented Sep 3, 2023

Description of changes

Without this, pkgsStatic.pkgsLLVM.hello fails with segfaulting binaries
because of the issue described at [0].

In summary, llvm's linker has a different behaviour to GCC's when
supplied with both -static and -Wl,-dynamic-linker=...; GCC copes with
it, but LLVM produces a binary which segfaults on startup. It appears to
be necessary to omit the dynamic linker in this case.

nixpkgs' static adaptor passes -static via NIX_CFLAGS_LINK which was not
accounted for prior to this commit in the checkLinkType logic. For good
measure I put the other NIX_ flags affecting link in the same logic.

Additionally, $NIX_CFLAGS_LINK_@suffixSalt@ is not available until later
than it was originally set, so set $linkType close to its point of use.
I checked for earlier uses by studying the shell trace output and
couldn't find any.

[0] #111010 (comment)

Signed-off-by: Peter Waller [email protected]

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.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.

Without this, pkgsStatic.pkgsLLVM.hello fails with segfaulting binaries
because of the issue described at [0].

In summary, llvm's linker has a different behaviour to GCC's when
supplied with both -static and -Wl,-dynamic-linker=...; GCC copes with
it, but LLVM produces a binary which segfaults on startup. It appears to
be necessary to omit the dynamic linker in this case.

nixpkgs' static adaptor passes -static via NIX_CFLAGS_LINK which was not
accounted for prior to this commit in the checkLinkType logic. For good
measure I put the other NIX_ flags affecting link in the same logic.

Additionally, $NIX_CFLAGS_LINK_@suffixSalt@ is not available until later
than it was originally set, so set $linkType close to its point of use.
I checked for earlier uses by studying the shell trace output and
couldn't find any.

[0] NixOS#111010 (comment)

Signed-off-by: Peter Waller <[email protected]>
@pwaller pwaller marked this pull request as ready for review September 3, 2023 12:56
@pwaller pwaller requested a review from Ericson2314 as a code owner September 3, 2023 12:56
@pwaller pwaller requested a review from a user September 3, 2023 12:56
@pwaller
Copy link
Contributor Author

pwaller commented Sep 3, 2023

cc @rrbutani for when you're back.

@pwaller
Copy link
Contributor Author

pwaller commented Sep 15, 2023

Ping @rrbutani and others, can we progress this one?

Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

This makes sense to me.

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Sep 16, 2023
Copy link
Member

@Artturin Artturin left a comment

Choose a reason for hiding this comment

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

pkgsStatic.pkgsLLVM.bash built and launched

There were errors like this, but they were there before too so not a regression.

bash> x86_64-unknown-linux-musl-ld: error: undefined symbol: termsig_handler
bash> >>> referenced by head.c:146
bash> >>>               head.o:(head_builtin)
bash> >>> referenced by head.c:82
bash> >>>               head.o:(file_head)
bash> >>> referenced by head.c:88
bash> >>>               head.o:(file_head)
bash> x86_64-unknown-linux-musl-ld: error: undefined symbol: interrupt_state
bash> >>> referenced by head.c:146
bash> >>>               head.o:(head_builtin)
bash> >>> referenced by head.c:0
bash> >>>               head.o:(file_head)
bash> x86_64-unknown-linux-musl-ld: error: undefined symbol: throw_to_top_level
bash> >>> referenced by head.c:146
bash> >>>               head.o:(head_builtin)
bash> >>> referenced by head.c:82
bash> >>>               head.o:(file_head)
bash> >>> referenced by head.c:88
bash> >>>               head.o:(file_head)
bash> x86_64-unknown-linux-musl-ld: error: undefined symbol: builtin_help
bash> >>> referenced by head.c:122
bash> >>>               head.o:(head_builtin)
bash> x86_64-unknown-linux-musl-ld: error: undefined symbol: builtin_usage
bash> >>> referenced by head.c:124
bash> >>>               head.o:(head_builtin)
bash> clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
bash> make[1]: *** [Makefile:169: tty] Error 1
bash> clang-11: make[1]: *** [Makefile:175: tee] Error 1
bash> error: linker command failed with exit code 1 (use -v to see invocation)

Probably something to do with the shared flag

bash> x86_64-unknown-linux-musl-clang -shared -Wl,-soname,head -o head head.o

@Artturin Artturin merged commit f36165c into NixOS:staging Sep 19, 2023
11 checks passed
@pwaller pwaller deleted the fix-static-linktype branch September 19, 2023 17:37
@alyssais
Copy link
Member

In case anybody ends up bisecting to here, your problem might be #269429, which was not caused by this PR, just made more prominent by it.

@rrbutani rrbutani added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label May 28, 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: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 10.rebuild-linux-stdenv This PR causes stdenv to rebuild 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants