Skip to content

cc-wrapper: fix linking against GCC libs for non-GCC#192459

Merged
Artturin merged 1 commit intoNixOS:stagingfrom
danielfullmer:fix-cc-wrapper-libdir
Sep 6, 2023
Merged

cc-wrapper: fix linking against GCC libs for non-GCC#192459
Artturin merged 1 commit intoNixOS:stagingfrom
danielfullmer:fix-cc-wrapper-libdir

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>
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Sep 22, 2022
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

@github-actions
Copy link
Contributor

Successfully created backport PR for staging-23.05:

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

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants