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

Add support for --build-id #15

Open
davidlattimore opened this issue Jul 4, 2024 · 1 comment
Open

Add support for --build-id #15

davidlattimore opened this issue Jul 4, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@davidlattimore
Copy link
Owner

Right now the --build-id flag is ignored (see args.rs). It'd be nice if we can support it without significantly slowing down the linker. The good news is that the linker has complete flexibility over how it generates the build-id. i.e. it doesn't need to be computed the same way as other linkers compute it. All that matters is:

  • It needs to change when any part of the output binary changes
  • It needs to be deterministic - i.e. it shouldn't be randomly generated

Whether it changes if one of the input files changes, but in a way that doesn't affect the output is an open question. My feeling is that it's probably OK if it does change. That would allow hashing the input files plus the arguments. The alternative is hashing the output, but that means we need to wait until we've finished writing the output, which gives us somewhat limited scope for parallelism.

Depending on how fast hashing is, hashing the output might still be OK if it can be done in parallel with closing all the input files (which is surprisingly slow - run the linker with --time to see).

The first thing that's needed is to add the .note.gnu.build-id to the output sections that the linker is aware of. This currently requires changing a bunch of places. I'll appologise now that there are so many places to change. It's something I'd like to refactor at some point, while keeping an eye to make sure performance doesn't regress. Fortunately the tests will guide you if you miss any of those places.

Next, you'll need to decide which "file" is responsible for owning the build-id. Mostly likely either Internal (which should probably at some point be renamed to Prelude) or Epologue.

If the flag is set, allocate the required space to the .note.gnu.build-id section in layout.rs.

Lastly write the build-id into the allocated space in elf_writer.rs.

@davidlattimore davidlattimore added the good first issue Good for newcomers label Jul 4, 2024
@VorpalBlade
Copy link

Depending on how fast hashing is, hashing the output might still be OK if it can be done in parallel with closing all the input files (which is surprisingly slow - run the linker with --time to see).

Unrelated to this issue, but have you considered any of:

  • Using io-uring to close files async?
  • Closing them concurrently from a thread pool?
  • What if we leave them open and let the OS clean up on process exit?
  • In the readme you also mention mold actually does work in a forked background process to avoid cleanup blocking the user, this could also be used by wild to deal with this i presume.

(Sorry to hijack the issue, but those ideas just came up as solutions to that subproblem.)

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

No branches or pull requests

2 participants