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: fix linking against GCC libs for non-GCC #192459

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

danielfullmer
Copy link
Contributor

@danielfullmer danielfullmer commented Sep 22, 2022

Currently, clang++ statically links against libstdc++ instead of dynamically links, because the -L path included in the cc-wrapper is incorrect. The gccForLibs.lib output only contains the architecture subdirectory if the target and host platform are not the same. (See targetConfig set in gcc//default.nix and the gcc/builder.nix)

This fixes the incorrect linking by using the correct path for both the cross and native cases. This also matches the cc_solib set above in cc-wrapper/default.nix

Tested by compiling a simple cpp binary and noting that it now correctly dynamically links against libstdc++, natively on x86_64 and arm64, as well as x86_64 -> arm64 cross compilation.

Co-Authored-By: Sebastian Ullrich <sebasti@nullri.ch>


This is based on #133512 (Closes #133512) (thanks @Kha), except it also works correctly in the cross-compilation case. That PR had been left unreviewed for a while, and this issue ought to get fixed, since it is currently incorrect for a central usage of clang in nixpkgs (dynamically linking against libstdc++). CC @Ericson2314 @dtzWill @primeos

Description of changes
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/)
  • 22.11 Release Notes (or backporting 22.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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.
Currently, clang++ statically links against libstdc++ instead of
dynamically links, because the -L path included in the cc-wrapper is
incorrect. The gccForLibs.lib output only contains the architecture
subdirectory if the target and host platform are not the same. (See
targetConfig set in gcc/<version>/default.nix and the gcc/builder.nix)

This fixes the incorrect linking by using the correct path for both the
cross and native cases. This also matches the cc_solib set above in
cc-wrapper/default.nix

Tested by compiling a simple cpp binary and noting that it now correctly
dynamically links against libstdc++, natively on x86_64 and arm64, as
well as x86_64 -> arm64 cross compilation.

Co-Authored-By: Sebastian Ullrich <sebasti@nullri.ch>
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.

$ nix shell .#clang -c c++ foo.cpp && ldd a.out | grep libstd
	libstdc++.so.6 => /nix/store/5xprvzsxa8b1qlzy4yc9kgws1zwrnqjq-gcc-12.3.0-lib/lib/libstdc++.so.6 (0x00007ff21e896000)
@Artturin
Copy link
Member

Artturin commented Sep 6, 2023

nix shell .#pkgsCross.aarch64-multiplatform.buildPackages.clang -c aarch64-unknown-linux-gnu-c++ foo.cpp && , objdump -p a.out

RUNPATH              /nix/store/n5x54i1rjr3iv6pz0qpqhdf0dz81kcsm-glibc-aarch64-unknown-linux-gnu-2.37-8/lib:/nix/store/5xidnp2v3gah5ignsf0indwzdb9a0v4f-aarch64-unknown-
linux-gnu-stage-final-gcc-12.3.0-lib/aarch64-unknown-linux-gnu/lib:/nix/store/xvfrqbh785vzxmvgwly8qlkc4glld9id-aarch64-unknown-linux-gnu-stage-final-gcc-12.3.0-libgcc/lib
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment