Skip to content

bcc: remove refs to LLVM static libs that bloated closure - #562660

Merged
winterqt merged 1 commit into
NixOS:masterfrom
LunNova:lunnova/bcc-debloat
Sep 28, 2026
Merged

winterqt merged 1 commit into
NixOS:masterfrom
LunNova:lunnova/bcc-debloat

Conversation

@LunNova

@LunNova LunNova commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Reduces closure from ~1.7G to ~300M

Things done

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. labels Sep 12, 2026
@LunNova LunNova changed the title bcc: remove refs to LLVM static libs that bloated closure by 2G bcc: remove refs to LLVM static libs that bloated closure Sep 12, 2026
@LunNova
LunNova marked this pull request as ready for review September 12, 2026 18:27
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". label Sep 12, 2026
@LunNova

LunNova commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 562660
Commit: bfe0e82aa5eb7ead34b81cf7136e2ad62834eecf


x86_64-linux

✅ 10 packages built:
  • bcc (linuxKernel.packages.linux_5_10.bcc, linuxKernel.packages.linux_5_15.bcc, linuxKernel.packages.linux_6_1.bcc, linuxKernel.packages.linux_6_12.bcc, linuxKernel.packages.linux_6_18.bcc, linuxKernel.packages.linux_6_6.bcc, linuxKernel.packages.linux_7_2.bcc, linuxKernel.packages.linux_xanmod.bcc, linuxKernel.packages.linux_xanmod_latest.bcc, linuxKernel.packages.linux_xanmod_stable.bcc, linuxKernel.packages.linux_zen.bcc, linuxPackages.bcc, linuxPackages_latest.bcc, linuxPackages_xanmod.bcc, linuxPackages_xanmod_latest.bcc, linuxPackages_xanmod_stable.bcc, linuxPackages_zen.bcc, python314Packages.bcc)
  • bpftrace (linuxKernel.packages.linux_5_10.bpftrace, linuxKernel.packages.linux_5_15.bpftrace, linuxKernel.packages.linux_6_1.bpftrace, linuxKernel.packages.linux_6_12.bpftrace, linuxKernel.packages.linux_6_18.bpftrace, linuxKernel.packages.linux_6_6.bpftrace, linuxKernel.packages.linux_7_2.bpftrace, linuxKernel.packages.linux_xanmod.bpftrace, linuxKernel.packages.linux_xanmod_latest.bpftrace, linuxKernel.packages.linux_xanmod_stable.bpftrace, linuxKernel.packages.linux_zen.bpftrace, linuxPackages.bpftrace, linuxPackages_latest.bpftrace, linuxPackages_xanmod.bpftrace, linuxPackages_xanmod_latest.bpftrace, linuxPackages_xanmod_stable.bpftrace, linuxPackages_zen.bpftrace)
  • ebpf-usb
  • fence
  • oci-seccomp-bpf-hook (linuxPackages.oci-seccomp-bpf-hook)
  • python313Packages.bcc
  • python313Packages.proton-vpn-daemon
  • python314Packages.proton-vpn-daemon
  • sockdump
  • system76-scheduler

@LunNova

LunNova commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

nixosTests.bpf is still happy.

@martinetd

Copy link
Copy Markdown
Member

Oh I see, bcc links with clang/llvm static libraries hmm...

Technically I'd rather go the other way around: keep the large closure but set ENABLE_LLVM_SHARED=ON so the code isn't duplicated, which would save space on systems that pull in clang anyway (albeit much less impressive than your ~1.7G to ~300M (398.8MB locally) -- it only reduces bcc itself from 160M to 18M), but I can see your point and some "production" environments could want bcc without the huge llvm libs...

Would it perhaps make sense to do both? e.g. make bcc shared but add a new bcc-staticllvm subpackage (through an option to the bcc package.nix) that links statically as currently with your remove-references-to added?

Either way if we keep remove-references-to I'd rather add a check that llvm is statically linked (e.g. ldd lib/libbcc.so doesn't list clang) and that llvm/clang derivations don't appear anywhere else in $out as it might creep back in on major upgrades

@LunNova

LunNova commented Sep 13, 2026 •

Copy link
Copy Markdown
Member Author

I don't want to split into shared/static. Shared would be better, (with pkgsStatic.bcc still being static) but LLVM needs its static libs to live in .dev and not .lib or that leaves us with the large closure size this tries to fix.
Will add disallowedReferences.

@LunNova
LunNova force-pushed the lunnova/bcc-debloat branch from bfe0e82 to 2d7031a Compare September 13, 2026 21:00
@LunNova

LunNova commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

added disallowedReferences

@martinetd

Copy link
Copy Markdown
Member

I don't want to split into shared/static. Shared would be better, (with pkgsStatic.bcc still being static) but LLVM needs its static libs to live in .dev and not .lib or that leaves us with the large closure size this tries to fix.

Right, perhaps llvm closures can be reworked somehow but that does sound like more work...

I think at this point prioritizing this closure size or prioritizing the whole store size with llvm installed is more of a project decision than a maintainer decision, so happy to defer to whoever knows about it -- would you be kind enough to bring it up on discourse or somewhere it can get attention perhaps?

Ideally I'd see something like:

  • this patch as a stopgap (it's definitely not worse than what we currently have, so I have no reason to block it)
  • fiddle with llvm until everyone's happy
  • remove this patch and switch to dynamic linking
    as a way forward, but that implies someone has time to work on llvm, and I sure don't...

(BTW moving the .a out would only reduce the closure size by about 350MB (so 1.7GB -> 1.55GB from dynamic linking bcc -> 1.2GB from not keeping llvm .a around), I'm not sure this is good enough for you)

added disallowedReferences

Thanks

@LunNova

LunNova commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

Sadly I don't have the time to try to rework anything in the LLVM package set at the moment. There's a discussion somewhere in matrix about trying to fix the .a files not to get pulled in for LLVM, not going to try to permalink to it because I can never get matrix search to work.

@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/7569

@winterqt winterqt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted a bunch in-person about this. I think this is a fine stopgap to avoid bloating closure size.

@winterqt
winterqt added this pull request to the merge queue Sep 28, 2026
Merged via the queue into NixOS:master with commit 2afe94d Sep 28, 2026
27 checks passed
@LunNova
LunNova deleted the lunnova/bcc-debloat branch September 28, 2026 12:54
@martinetd

Copy link
Copy Markdown
Member

Thanks for merging.

As said above I'm fine with this as a stopgap, but I'd like to switch to dynamic linking once the llvm situation improved (or provide two bcc variants if there are strong reasons to want to make the bcc closure smaller, but tbh bcc is a dev tool and I don't see the point of optimizing too hard for this specific closure size over the full system closure size, for production you'd be better served with the libbpf-tools binaries (WIP #488231 - I believe these would be small and not depend on llvm at all))

I searched open issues but couldn't find anything, is there somewhere I could watch?

@LunNova

LunNova commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

I don't think nuking unwanted refs to a store path like this is a stopgap - this is done frequently in nixpkgs - and don't see how it's related to deciding whether to have dynamically or statically linked bcc.

Don't afaik think anyone is working on fixing the .dev / .lib split for static and shared libs properly. Until that's fixed, dynamic linking against LLVM will still result in huge static libs in the closure.

@martinetd

Copy link
Copy Markdown
Member

Well, your reason to do this was to reduce the closure size, so unless llvm .dev/.lib gets split that means you'd rather not do dynamic linking?

My systems that have bcc also have bpftrace which is already dynamically linked to llvm, so from my (user) point of view switching to dynamic linking would reduce my system's closure size (by about 140MB), but I can understand that someone who's not already bringing in llvm would prefer bloating bcc itself by doing static linking...

Anyway, ok for nobody working on it, I've run out of time for today but I'll open an issue later just to track the issue

@LunNova

LunNova commented Oct 4, 2026 •

Copy link
Copy Markdown
Member Author

@martinetd

Copy link
Copy Markdown
Member

Thanks for all the links!

I've glanced over the issues/reverted PR and while a generic solution isn't in sight it looks like something for llvm might be possible if we can fiddle a bit with the cmake rules to install in separate directories (as that'll make llvm-config automagically work), with the additional load of checking nixpkgs for people pointing at .a directly from llvm.lib...
It doesn't look impossible but certainly not a 5 minutes fix, I'll let dragons lie a bit longer... :)

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

Labels

2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants