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

glibc_multi: add output "static" #380756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tim-Wsm
Copy link
Contributor

@Tim-Wsm Tim-Wsm commented Feb 9, 2025

This change enables static compilation with glibc in a multilib setup. For building a nix shell the output can now be referenced as follows:

devShells.default = pkgs.mkShell {
    packages = [
        pkgs.glibc_multi.static
    ];
};

In the implementation I was forced to make two design decisions:

  1. The directory $static/lib64 has to be a "real" directory and not a symlink. Otherwise, the path to this directory is not added to $NIX_LDFLAGS, which in turn causes the files to not be visible to gcc and ld during the build process (for details see pkgs/build-support/bintools-wrapper/setup-hook.sh line 16).
  2. The directories $static/lib and $static/lib64 have to contain symlinks to both the files used for static and for dynamic linking (i.e. the outputs of static and out of the 32 and 64 bit variant of glibc). Without this, dynamic linking still works, however the resulting binaries will segfault.

(not part of the commit message)

I'm unsure why I've had to add the files for dynamic linking into the output for static linking to prevent the resulting binaries to segfault. However, since this solution works and does not modify/impact any other modules/packages, I'm satisfied with it.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

Open issues related to this pull request

This is my second attempt at this pr. I've deleted my first attempt, because the test tests.cc-multilib-clang failed while running nixpkgs-review. However, I'm now confident, that this test does not fail due to any of the changes in this pr and have reported this as a separate issue in #380752.

Snippets for manual testing

I tested the changes manually using the following setup:

hello-world.c

#include <stdio.h>

int main() {
    printf("Hello World!\n");
    return 0;
}

flake.nix

{
  description = "Flake for testing";
  inputs = {
    nixpkgs.url = "path:/home/tim/repos/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = {
    nixpkgs,
    flake-utils,
    ...
  }:
    flake-utils.lib.eachDefaultSystem
    (
      system: let
        pkgs = nixpkgs.legacyPackages.${system};
      in {
        devShells.default = pkgs.mkShell {
          packages = [
            pkgs.gcc_multi
            pkgs.clang_multi
            pkgs.glibc_multi
            pkgs.glibc_multi.static
          ];
        };
      }
    );
}

Then I've used the following commands for testing.

# enter the development shell
$ nix develop .
# compile all variants of hello world
$ gcc hello-world.c -o hello-world-64bit-dynamic-gcc
$ gcc -static hello-world.c -o hello-world-64bit-static-gcc
$ gcc -m32 hello-world.c -o hello-world-32bit-dynamic-gcc
$ gcc -static -m32 hello-world.c -o hello-world-32bit-static-gcc
$ clang hello-world.c -o hello-world-64bit-dynamic-clang
$ clang -static hello-world.c -o hello-world-64bit-static-clang
$ clang -m32 hello-world.c -o hello-world-32bit-dynamic-clang
$ clang -static -m32 hello-world.c -o hello-world-32bit-static-clang
# run all binaries
$ ./hello-world-64bit-dynamic-gcc; ./hello-world-64bit-static-gcc; ./hello-world-32bit-dynamic-gcc; ./hello-world-32bit-static-gcc; ./hello-world-64bit-dynamic-clang ; ./hello-world-64bit-static-clang; ./hello-world-32bit-dynamic-clang; ./hello-world-32bit-static-clang

Add a 👍 reaction to pull requests you find important.

This change enables static compilation with glibc in a multilib setup. For
building a nix shell the output can now be referenced as follows:

devShells.default = pkgs.mkShell {
    packages = [
        pkgs.glibc_multi.static
    ];
};

In the implementation I was forced to make two design decisions:
1. The directory `$static/lib64` has to be a "real" directory and not a symlink.
   Otherwise, the path to this directory is not added to $NIX_LDFLAGS, which in
   turn causes the files to not be visible to gcc and ld during the build
   process (for details see `pkgs/build-support/bintools-wrapper/setup-hook.sh`
   line 16).
2. The directories `$static/lib` and `$static/lib64` have to contain symlinks
   to both the files used for static and for dynamic linking (i.e. the outputs
   of `static` and `out` of the 32 and 64 bit variant of glibc). Without this,
   dynamic linking still works, however the resulting binaries will segfault.
@Tim-Wsm Tim-Wsm force-pushed the glibc-multilib-static branch from 58c5376 to e7413df Compare February 10, 2025 06:38
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 101-500 labels Feb 10, 2025
@Tim-Wsm
Copy link
Contributor Author

Tim-Wsm commented Feb 10, 2025

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 380756


x86_64-linux

⏩ 2 packages marked as broken and skipped:
  • grub4dos
  • linuxKernel.packages.linux_5_4_hardened.virtualbox
❌ 1 package failed to build:
  • airwave
✅ 89 packages built:
  • am2rlauncher
  • bottles
  • clangMultiStdenv
  • clang_multi
  • davinci-resolve
  • davinci-resolve-studio
  • game-rs
  • stdenv_32bit (gccMultiStdenv)
  • gcc_multi
  • gcc_multi.info
  • gcc_multi.man
  • glibc_multi
  • glibc_multi.bin
  • glibc_multi.dev
  • glibc_multi.static
  • hax11
  • hax11.doc
  • heroic
  • immersed
  • itch
  • kodiPackages.steam-launcher
  • libstrangle
  • linuxKernel.packages.linux_5_10.virtualbox
  • linuxKernel.packages.linux_5_10_hardened.virtualbox
  • linuxKernel.packages.linux_5_15.virtualbox
  • linuxKernel.packages.linux_5_15_hardened.virtualbox
  • linuxKernel.packages.linux_5_4.virtualbox
  • linuxKernel.packages.linux_6_1.virtualbox
  • linuxKernel.packages.linux_6_11.virtualbox
  • linuxKernel.packages.linux_6_11_hardened.virtualbox
  • linuxKernel.packages.linux_6_12.virtualbox
  • linuxKernel.packages.linux_hardened.virtualbox (linuxKernel.packages.linux_6_12_hardened.virtualbox)
  • linuxKernel.packages.linux_6_13.virtualbox
  • linuxKernel.packages.linux_6_1_hardened.virtualbox
  • linuxKernel.packages.linux_6_6.virtualbox
  • linuxKernel.packages.linux_6_6_hardened.virtualbox
  • linuxKernel.packages.linux_latest_libre.virtualbox
  • linuxKernel.packages.linux_libre.virtualbox
  • linuxKernel.packages.linux_lqx.virtualbox
  • linuxKernel.packages.linux_xanmod.virtualbox
  • linuxKernel.packages.linux_xanmod_latest.virtualbox (linuxKernel.packages.linux_xanmod_stable.virtualbox)
  • linuxKernel.packages.linux_zen.virtualbox
  • loadlibrary
  • lutris
  • lutris-free
  • lutris-unwrapped
  • lutris-unwrapped.dist
  • minigalaxy
  • minigalaxy.dist
  • mumble_overlay
  • opentrack
  • pipelight
  • playonlinux
  • protontricks
  • protontricks.dist
  • quartus-prime-lite
  • red
  • statifier
  • steam
  • steam-fhsenv-without-steam
  • steam-run
  • steam-run-free
  • steam-tui
  • steamcmd
  • synthesia
  • umu-launcher
  • virtualbox
  • virtualbox.modsrc
  • virtualboxHardened
  • virtualboxHardened.modsrc
  • virtualboxHeadless
  • virtualboxHeadless.modsrc
  • virtualboxKvm
  • virtualboxWithExtpack
  • virtualboxWithExtpack.modsrc
  • vtfedit
  • winbox
  • wineWowPackages.base (wineWowPackages.stable, wineWowPackages.unstable)
  • wineWowPackages.full (wineWowPackages.stableFull)
  • wineWowPackages.minimal
  • wineWowPackages.staging
  • wineWowPackages.stagingFull
  • wineWowPackages.unstableFull
  • wineWowPackages.wayland
  • wineWowPackages.waylandFull
  • wineasio
  • xivlauncher
  • yabridge
  • yabridgectl

@Tim-Wsm
Copy link
Contributor Author

Tim-Wsm commented Feb 10, 2025

The failing package airwave seems to be broken with and without the changes of this pr.

@Tim-Wsm
Copy link
Contributor Author

Tim-Wsm commented Feb 10, 2025

Since glibc_multi is a simple wrapper of the glibc package, I would like to kindly request a review by one of the maintainers.

@Ma27
@ConnorBaker

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: 101-500
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant