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

Reduce stub-ld build time closure #373776

Open
Atemu opened this issue Jan 14, 2025 · 5 comments
Open

Reduce stub-ld build time closure #373776

Atemu opened this issue Jan 14, 2025 · 5 comments

Comments

@Atemu
Copy link
Member

Atemu commented Jan 14, 2025

@vcunat pointed out in #269551 that due to stub-ld's build-time dependency on pkgsStatic for both 64bit and 32bit, there is a large build-time closure for NixOS tests which is painful for bisecting NixOS tests in staging.

stub-ld is a very simple c-program whose entire purpose it is to print a user-friendly error message when the global dynamic is attempted to be invoked.

I see a few options:

  1. Don't use a stdenv. The program is so simple that we could conceivably just invoke the compile and link commands manually.
  2. Use nolibc instead of musl as @Mic92 recommended. We only need it to do a print.
  3. Build it against the regular stdenv. I'm not quite sure why it's pkgsStatic actually. (cc @tejing1)

Regardless of these closure minimisations, we should look into disabling stub-ld for every NixOS test but the one which tests stub-ld itself. This really doesn't need to be tested in those as this is only ever invoked with binaries that assume a FHS which you should never find inside a NixOS test and even if you do, this is just a nicer error message.

@Atemu Atemu mentioned this issue Jan 14, 2025
13 tasks
@tejing1
Copy link
Contributor

tejing1 commented Jan 14, 2025

There's no particularly compelling reason why it's pkgsStatic. I needed the result to be statically linked, and that was how I knew to do it. Nothing more. No doubt there are much better ways to do it, and I really wasn't considering build closure size when I implemented it.

I agree that for this, it makes sense to do something more basic to reduce the build closure, but it's outside my expertise to do so.

@Mic92
Copy link
Member

Mic92 commented Jan 14, 2025

Old version of nix-ld where using nolibc before it was switch to the rust code base, if you need inspiration. glibcStatic might produce a bigger binary also not quite sure if it would be truly static after that (i.e. there glibc likes to load nss modules in some cases).

@Atemu
Copy link
Member Author

Atemu commented Jan 14, 2025

What is the reason for needing it to be statically linked actually?

@tejing1
Copy link
Contributor

tejing1 commented Jan 14, 2025

Seems like the kernel (I think it's the kernel? My understanding of the roles in this space is hazy) doesn't support chaining ELF interpreters, from what I could tell. I did test if you could use a dynamic binary pointing at a loader in the store, and it didn't work.

@Mic92
Copy link
Member

Mic92 commented Jan 14, 2025

What is the reason for needing it to be statically linked actually?

They also need to be relocatable on top of statically linked because the actual elf binary is already mapped when the link-loader is executed. Chaining elf interpreter would be quite difficult to implement since it's unclear what state the first link-loader would left behind before entering the second one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants