| 1 Nov 2021 |
@AleXoundOS:matrix.org | In reply to @sternenseemann:systemli.org you may want to use nix-store --query --references <store path> for this purpose which shows you which nix store paths are referenced by the build result The thing is that having full contents of outputs is a unaffordable luxury on embedded device with 16 MiB of disk space. So after nix has built the outputs I have to keep only needed files. | 20:48:08 |
sterni | hmmm, right | 20:48:36 |
@AleXoundOS:matrix.org | In reply to @sternenseemann:systemli.org hm seems like glibc does weird stuff with ldd i. e. the installed ldd always runs on the build platform? Yeah, ldd needs to be run on the target system. | 20:48:43 |
sterni | I mean closure size reduction is done to some level but many packages have multiple libs in their lib output, right | 20:48:58 |
@AleXoundOS:matrix.org | If it's difficult to get ldd, I will stick to readelf then. | 20:49:00 |
sterni | patchelf --print-needed is also kind of convenient | 20:49:14 |
@AleXoundOS:matrix.org | In reply to @sternenseemann:systemli.org you may want to use nix-store --query --references <store path> for this purpose which shows you which nix store paths are referenced by the build result * The thing is that having full contents of outputs is an unaffordable luxury on embedded device with 16 MiB of disk space. So after nix has built the outputs I have to keep only needed files. | 20:51:24 |
@AleXoundOS:matrix.org | In reply to @sternenseemann:systemli.org
patchelf --print-needed is also kind of convenient Thank you. This worked to some extent - it doesn't print absolute paths though (I would like to get size of .so files). | 20:54:43 |
sterni | right yeah it doesn't put rpath and needed libs together | 20:55:31 |
trofi | There is also a scanelf package that has an lddtree tool with dependent library copying features. I never tried it on nix system and only used on gentoo to create minimal chroots. | 21:08:10 |
@AleXoundOS:matrix.org | Hm, couldn't find scanelf nor lddtree in nixpkgs. Currently, I used while read line; do find . -name "$line"; done < /tmp/libs | xargs readlink -f | tar cf /tmp/libs.tar -T - where /tmp/libs is the patchelf --print-needed output. | 21:11:17 |
trofi | Sorry. The package is called pax-utils. | 21:12:22 |
trofi | Script from the past life:
exes_to_copy=(
/bin/bash
/bin/ls
/bin/busybox
)
for l in "${libs_to_copy[@]}"; do
basename_l=$(basename "${l}")
resolved_l=$(readlink -f "${l}")
cp -v "${resolved_l}" root/lib64/"${basename_l}"
done
lddtree "${exes_to_copy[@]}" \
--copy-to-tree root/ --bindir=/bin --libdir=/lib64
| 21:16:26 |
@AleXoundOS:matrix.org | In reply to @trofi:matrix.org Sorry. The package is called pax-utils. Hah, lddtree requires bash which I haven't brought to the device yet. scanelf runs but it's not clear if it can mimic ldd. | 21:18:24 |
@AleXoundOS:matrix.org | But, generally readelf is the proper way because it runs on the build platform too so removing unneeded files can be automated. @sterni's patchelf suggestion gave me rough estimation of the current size of minimal closure for my application. | 21:23:16 |
trofi | lddtree should be ran on build as well. | 21:23:54 |
trofi | But I think it relies on ld.so.cache to resolve library names to full paths. Nix does not maintain ld.so.cache. | 21:25:06 |
@AleXoundOS:matrix.org | Btw, currently I'm at the point when most of gstreamer libraries are built for mips32r2. gstreamer plugins remain to be built which should load during runtime. | 21:25:59 |
@AleXoundOS:matrix.org | In reply to @trofi:matrix.org lddtree should be ran on build as well. Wow, cool. Indeed it works on the build machine. Thank you:) | 21:26:16 |
@AleXoundOS:matrix.org | In reply to @trofi:matrix.org lddtree should be ran on build as well. * Wow, cool. Indeed, it works on the build machine. Thank you:) | 21:26:30 |
sterni | I think it should be possible to make a more convenient tool to do an aggressive closure size reduction like this | 21:26:53 |
sterni | should be a somewhat reasonably complicated script, but would be nice if it was possible in a derivation as well… | 21:27:32 |
@AleXoundOS:matrix.org | I'm not sure it can be universal. Libraries are easy (at least which are linked). But more sophisticated software may need miscellaneous files at runtime that difficult to trace without running it. | 21:28:32 |
sterni | indeed | 21:29:03 |
trofi | * Script from the past life:
exes_to_copy=(
/bin/bash
/bin/ls
/bin/busybox
)
lddtree "${exes_to_copy[@]}" \
--copy-to-tree root/ --bindir=/bin --libdir=/lib64
| 21:31:32 |
| 3 Nov 2021 |
@AleXoundOS:matrix.org | In reply to @trofi:matrix.org This passes through a configure flag (I overrode wrapCC): nix-build -E 'with import ./. { overlays = [ (self: super: { wrapCC = cc: super.wrapCC (cc.overrideAttrs (def: { configureFlags = super.lib.trace (def.configureFlags) (def.configureFlags ++ [ "--disable-libsanitizer" ]); })); }) ]; }; pkgsCross.fuloongminipc.hello'. Waiting if it succeeds. Thank you, this works. But has a drawback that native gcc gets rebuilt too (for no good). Do you think it's possible to avoid this? | 19:52:34 |
@AleXoundOS:matrix.org | I tried to use condition super.stdenv.buildPlatform != super.stdenv.hostPlatform in various levels of expressions after wrapCC =, but buildPlatform always equals hostPlatform there. | 19:54:40 |
@AleXoundOS:matrix.org | Also, "Cross-compilation infrastructure" section of nixpkgs gives no clear insight on how to handle this. | 19:57:39 |
@AleXoundOS:matrix.org | * Also, "Cross-compilation infrastructure" section of nixpkgs manual gives no clear insight on how to handle this. | 19:57:49 |
symphorien | it might be a case of trading build time for sanity. | 20:01:11 |