Skip to content

Remove dependency formats from crate metadata #96708

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

Open
bjorn3 opened this issue May 4, 2022 · 7 comments
Open

Remove dependency formats from crate metadata #96708

bjorn3 opened this issue May 4, 2022 · 7 comments
Labels
A-metadata Area: Crate metadata C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@bjorn3
Copy link
Member

bjorn3 commented May 4, 2022

It only really needs to be stored for dylibs and only the dependency format for said dylib and not for any other crate types also used. It can be stored in a separate section for dylibs. For example .rsdpfmt (needs to stay within the 8 char limit for COFF section names). Furthermore omitting it from the crate metadata is necessary for implementing bazelbuild/rules_rust#228 (comment) as otherwise the dependency formats included in the crate metadata of the first compilation wouldn't match the second compilation due to dylibs not being available yet. Not encoding it in the crate metadata may also improve performance a tiny bit although rlib only crates already encode an empty list anyway.

@bjorn3 bjorn3 added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-metadata Area: Crate metadata labels May 4, 2022
@davidbarsky
Copy link
Contributor

I was talking to @jsgf about this issue, but I had two questions:

To summarize/get everyone on the same page, the reason that @jsgf took the "hollow .rlib" approach (as described in bazelbuild/rules_rust#228 (comment)) was that BuckV2's rules allows for reusing the generated .rlib across the equivalent of Buck's cargo check and cargo build flavors (Jeremy allude to that in the comment, but I didn't pick up on that until he made it explicit to me).

(On an aside, I've noticed that the approach that Jeremy took incurs about 20-30% more overhead compared to emitting plain metadata, so maybe resolving this issue can hopefully reduce that discrepancy.)

@bjorn3
Copy link
Member Author

bjorn3 commented Sep 21, 2022

Currently the crate metadata is shared between all crate types. For dylibs we still need to store the dylib dependency formats. I think the best way is to store it in an additional section of the dylib and then remove it from the main crate metadata. I don't think this interacts with MIR-only rlibs at all.

@jsgf
Copy link
Contributor

jsgf commented Sep 21, 2022

Just to make sure we're all talking about the same thing, "dependency format" just means this right?

That's only linkages and crate types, so there's no hashes or any other identifiers of specific crates. So @davidbarsky I don't think this is relevant to any of the things we're talking about.

@bjorn3
Copy link
Member Author

bjorn3 commented Sep 21, 2022

Just to make sure we're all talking about the same thing, "dependency format" just means this right?

Correct.

@mati865
Copy link
Member

mati865 commented May 31, 2025

For example .rsdpfmt (needs to stay within the 8 char limit for COFF section names).

If this is only for dylibs then longer names for COFF are doable. You can put the actual long name into the string table and then call the section /<offset>, where the offset is the offset of the string in the table in decimal ASCII form.

@bjorn3
Copy link
Member Author

bjorn3 commented May 31, 2025

According to

// Historical note:
//
// When using link.exe it was seen that the section name `.note.rustc`
// was getting shortened to `.note.ru`, and according to the PE and COFF
// specification:
//
// > Executable images do not use a string table and do not support
// > section names longer than 8 characters
//
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
//
// As a result, we choose a slightly shorter name! As to why
// `.note.rustc` works on MinGW, see
// https://github.com/llvm/llvm-project/blob/llvmorg-12.0.0/lld/COFF/Writer.cpp#L1190-L1197
the linker will truncate the section name.

@mati865
Copy link
Member

mati865 commented May 31, 2025

It will for executables, but is metadata even useful for them? For dylibs it does truncate names unless you put them into the string table and use the offset.

fmease added a commit to fmease/rust that referenced this issue Jun 14, 2025
…ork, r=workingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of rust-lang#96708.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 15, 2025
…ork, r=workingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of rust-lang#96708.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 15, 2025
…ork, r=workingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of rust-lang#96708.
fmease added a commit to fmease/rust that referenced this issue Jun 15, 2025
…ork, r=workingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of rust-lang#96708.
fmease added a commit to fmease/rust that referenced this issue Jun 15, 2025
…ork, r=workingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of rust-lang#96708.
rust-timer added a commit that referenced this issue Jun 16, 2025
Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of #96708.
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this issue Jun 17, 2025
…rkingjubilee,saethlin

Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of rust-lang/rust#96708.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-metadata Area: Crate metadata C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants