From 3e0a443203acb5c70c4d4686360da4c5820ff8b4 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Tue, 24 Apr 2018 19:09:21 -0500 Subject: [PATCH 1/6] musl: provide 'iconv' utility occasionally expected as part of libiconv --- pkgs/os-specific/linux/musl/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix index 4d1c2cad2e33..a3d09127c085 100644 --- a/pkgs/os-specific/linux/musl/default.nix +++ b/pkgs/os-specific/linux/musl/default.nix @@ -17,6 +17,13 @@ let sha256 = "14igk6k00bnpfw660qhswagyhvr0gfqg4q55dxvaaq7ikfkrir71"; }; + # iconv tool, implemented by musl author: + iconv_c = fetchurl { + name = "iconv.c"; + url = "http://git.etalabs.net/cgit/noxcuse/plain/src/iconv.c?id=02d288d89683e99fd18fe9f54d4e731a6c474a4f"; + sha256 = "1yafz6y509zxpa1i830p5463p91g0y70q60z8q054078qrpln8hp"; + }; + in stdenv.mkDerivation rec { name = "musl-${version}"; @@ -77,6 +84,9 @@ stdenv.mkDerivation rec { moveToOutput lib/musl-gcc.specs $dev substituteInPlace $dev/bin/musl-gcc \ --replace $out/lib/musl-gcc.specs $dev/lib/musl-gcc.specs + + # provide 'iconv' utility + $CC ${iconv_c} -o $out/bin/iconv '' + lib.optionalString useBSDCompatHeaders '' install -D ${queue_h} $dev/include/sys/queue.h install -D ${cdefs_h} $dev/include/sys/cdefs.h From de00c0d7fbdbc27fd4a7a5addf5d42d3a90e3181 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Tue, 24 Apr 2018 19:31:56 -0500 Subject: [PATCH 2/6] musl/iconv: use copy from Alpine for minor touchups to error messages --- pkgs/os-specific/linux/musl/default.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix index a3d09127c085..0912f427430b 100644 --- a/pkgs/os-specific/linux/musl/default.nix +++ b/pkgs/os-specific/linux/musl/default.nix @@ -17,11 +17,14 @@ let sha256 = "14igk6k00bnpfw660qhswagyhvr0gfqg4q55dxvaaq7ikfkrir71"; }; - # iconv tool, implemented by musl author: + # iconv tool, implemented by musl author. + # Original: http://git.etalabs.net/cgit/noxcuse/plain/src/iconv.c?id=02d288d89683e99fd18fe9f54d4e731a6c474a4f + # We use copy from Alpine which fixes error messages, see: + # https://git.alpinelinux.org/cgit/aports/commit/main/musl/iconv.c?id=a3d97e95f766c9c378194ee49361b375f093b26f iconv_c = fetchurl { name = "iconv.c"; - url = "http://git.etalabs.net/cgit/noxcuse/plain/src/iconv.c?id=02d288d89683e99fd18fe9f54d4e731a6c474a4f"; - sha256 = "1yafz6y509zxpa1i830p5463p91g0y70q60z8q054078qrpln8hp"; + url = "https://git.alpinelinux.org/cgit/aports/plain/main/musl/iconv.c?id=a3d97e95f766c9c378194ee49361b375f093b26f"; + sha256 = "1mzxnc2ncq8lw9x6n7p00fvfklc9p3wfv28m68j0dfz5l8q2k6pp"; }; in From 791b5bbbf4d7ec7de8c1a5df0ee3be08ae8670c9 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Tue, 24 Apr 2018 21:22:52 -0500 Subject: [PATCH 3/6] musl bootstrap: remove libiconv --- .../bootstrap-tools-musl/scripts/unpack-bootstrap-tools.sh | 2 +- pkgs/stdenv/linux/make-bootstrap-tools.nix | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/stdenv/linux/bootstrap-tools-musl/scripts/unpack-bootstrap-tools.sh b/pkgs/stdenv/linux/bootstrap-tools-musl/scripts/unpack-bootstrap-tools.sh index 8b5070dc6d6f..b160a748d8dc 100644 --- a/pkgs/stdenv/linux/bootstrap-tools-musl/scripts/unpack-bootstrap-tools.sh +++ b/pkgs/stdenv/linux/bootstrap-tools-musl/scripts/unpack-bootstrap-tools.sh @@ -26,7 +26,7 @@ for i in $out/bin/* $out/libexec/gcc/*/*/*; do ./patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath "$i" done -for i in $out/lib/libiconv*.so $out/lib/libpcre* $out/lib/libc.so; do +for i in $out/lib/libpcre* $out/lib/libc.so; do if [ -L "$i" ]; then continue; fi echo patching "$i" $out/bin/patchelf --set-rpath $out/lib --force-rpath "$i" diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix index 5522bc5dea25..4fc9999b538c 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix @@ -136,8 +136,6 @@ in with pkgs; rec { cp -d ${libmpc.out}/lib/libmpc*.so* $out/lib cp -d ${zlib.out}/lib/libz.so* $out/lib cp -d ${libelf}/lib/libelf.so* $out/lib - '' + lib.optionalString (hostPlatform.libc == "musl") '' - cp -d ${libiconv.out}/lib/libiconv*.so* $out/lib '' + lib.optionalString (hostPlatform != buildPlatform) '' # These needed for cross but not native tools because the stdenv From 97698b0d6d644cc6d59495e339f6fbf44ff8ac64 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Wed, 25 Apr 2018 08:08:47 -0500 Subject: [PATCH 4/6] musl-stdenv: don't add special allowance for libiconv --- pkgs/stdenv/linux/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 2eb55ae439b5..92da0d7873d0 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -362,7 +362,6 @@ in ++ [ /*propagated from .dev*/ linuxHeaders binutils gcc gcc.cc gcc.cc.lib gcc.expand-response-params ] - ++ lib.optional (localSystem.libc == "musl") libiconv ++ lib.optionals localSystem.isAarch64 [ prevStage.updateAutotoolsGnuConfigScriptsHook prevStage.gnu-config ]; From 2d54f8f915166dbdc93ed9497f622799e930bf9b Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Wed, 25 Apr 2018 08:09:56 -0500 Subject: [PATCH 5/6] musl: build iconv using just-built pieces This is a bit unusual for a package, but not libc's as they should stand alone. --- pkgs/os-specific/linux/musl/default.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix index 0912f427430b..cd102cca00f1 100644 --- a/pkgs/os-specific/linux/musl/default.nix +++ b/pkgs/os-specific/linux/musl/default.nix @@ -68,6 +68,8 @@ stdenv.mkDerivation rec { dontDisableStatic = true; separateDebugInfo = true; + NIX_DONT_SET_RPATH = true; + postInstall = '' # Not sure why, but link in all but scsi directory as that's what uclibc/glibc do. # Apparently glibc provides scsi itself? @@ -88,8 +90,13 @@ stdenv.mkDerivation rec { substituteInPlace $dev/bin/musl-gcc \ --replace $out/lib/musl-gcc.specs $dev/lib/musl-gcc.specs - # provide 'iconv' utility - $CC ${iconv_c} -o $out/bin/iconv + # provide 'iconv' utility, using just-built headers, libc/ldso + $CC ${iconv_c} -o $out/bin/iconv \ + -I$dev/include \ + -L$out/lib -Wl,-rpath=$out/lib \ + -lc \ + -B $out/lib \ + -Wl,-dynamic-linker=$(ls $out/lib/ld-*) '' + lib.optionalString useBSDCompatHeaders '' install -D ${queue_h} $dev/include/sys/queue.h install -D ${cdefs_h} $dev/include/sys/cdefs.h From 558f7424f26076e1bb2260f13c04a9eb88127f97 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sun, 11 Mar 2018 21:00:19 -0500 Subject: [PATCH 6/6] musl: make libc -> {ldso,ldd} symlinks relative Minor touchup while rebuilding things anyway. --- pkgs/os-specific/linux/musl/default.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix index cd102cca00f1..3d515f7b762f 100644 --- a/pkgs/os-specific/linux/musl/default.nix +++ b/pkgs/os-specific/linux/musl/default.nix @@ -51,6 +51,13 @@ stdenv.mkDerivation rec { --replace -fno-asynchronous-unwind-tables "" ''; + patches = [ + # Minor touchup to build system making dynamic linker symlink relative + (fetchurl { + url = https://raw.githubusercontent.com/openwrt/openwrt/87606e25afac6776d1bbc67ed284434ec5a832b4/toolchain/musl/patches/300-relative.patch; + sha256 = "0hfadrycb60sm6hb6by4ycgaqc9sgrhh42k39v8xpmcvdzxrsq2n"; + }) + ]; preConfigure = '' configureFlagsArray+=("--syslibdir=$out/lib") ''; @@ -80,7 +87,7 @@ stdenv.mkDerivation rec { mkdir -p $out/bin # Create 'ldd' symlink, builtin - ln -s $out/lib/libc.so $out/bin/ldd + ln -rs $out/lib/libc.so $out/bin/ldd # (impure) cc wrapper around musl for interactive usuage for i in musl-gcc musl-clang ld.musl-clang; do