From d7fe0a5548413fedb2c23d8b7d9864c99350e226 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 2 Apr 2023 05:10:51 -0700 Subject: make-bootstrap-tools.nix: use a patchelf built with -static-{libgcc,libstdc++} Our bootstrap-files unpacker has always relied on a lot of unstated assumptions, one of them being that every library has a DT_NEEDED for librt.so, so patchelf'ing something into the RUNPATH into librt.so means that it will be searched for every library load in all of the bootstrap-files. Unfortunately that assumption is not true for libgcc. This causes problems, because patchelf links against libgcc (and against libstdc++, which links against libgcc). So we can't use patchelf on libgcc, because it needs libgcc, so patchelf doesn't work until libgcc is patchelfed. The robust solution here is to use static linking for the copy of patchelf that is shipped with the bootstrap-files. We don't have to go all the way to a statically linked libc; just -static-libgcc and -static-libstdc++ are enough to break the circular dependency. --- pkgs/stdenv/linux/make-bootstrap-tools.nix | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pkgs/stdenv') diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix index 107e4c43a9fa0..091130ebf93a8 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix @@ -2,6 +2,10 @@ let libc = pkgs.stdenv.cc.libc; + patchelf = pkgs.patchelf.overrideAttrs(previousAttrs: { + NIX_CFLAGS_COMPILE = (previousAttrs.NIX_CFLAGS_COMPILE or []) ++ [ "-static-libgcc" "-static-libstdc++" ]; + NIX_CFLAGS_LINK = (previousAttrs.NIX_CFLAGS_LINK or []) ++ [ "-static-libgcc" "-static-libstdc++" ]; + }); in with pkgs; rec { -- cgit 1.4.1