Skip to content

Add chapter on libs and metadata. #1044

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

Merged
merged 3 commits into from
Feb 4, 2021
Merged

Add chapter on libs and metadata. #1044

merged 3 commits into from
Feb 4, 2021

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Jan 29, 2021

This adds a new chapter on library files and metadata, and how these things interact.

This leans a bit heavy from a Cargo/build-tools perspective, but I think this information is useful. I think it is difficult to hit a good balance of too-much or too-little detail, since things tend to change a lot over time. Not sure if I hit the mark there.

I think this is pretty accurate, but I am not involved with compiler development a lot, so there may be some things that are incomplete or wrong.

Closes #468 (I think?)

@ehuss
Copy link
Contributor Author

ehuss commented Jan 29, 2021

BTW, I had no idea where to stick this in the SUMMARY hierarchy. I think "backend" makes sense, but I'm uncertain (because metadata is used almost everywhere).

@camelid
Copy link
Member

camelid commented Jan 29, 2021

I've wanted to see info about metadata and rustlibs in the dev-guide for a
while, so thank you!

@@ -145,6 +145,7 @@
- [Debugging LLVM](./backend/debugging.md)
- [Backend Agnostic Codegen](./backend/backend-agnostic.md)
- [Implicit Caller Location](./backend/implicit-caller-location.md)
- [Libraries and Metadata](./backend/libs-and-metadata.md)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps instead put this under "High-level compiler architecture"? That's where queries and serialization are discussed, which are somewhat related.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

This is super helpful, thank you!

* Object code, which is the result of code generation. This is used during
regular linking. There is a separate `.o` file for each [codegen unit]. The
codegen step can be skipped with the [`-C
linker-plugin-lto`][linker-plugin-lto] CLI option, which means each `.o`
Copy link
Member

Choose a reason for hiding this comment

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

Why does rustc reuse .o as the extension for bitcode files? I would expect .ll or something.

Copy link
Member

@camelid camelid Feb 4, 2021

Choose a reason for hiding this comment

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

What do you mean? My understanding is this is talking about object code (not LLVM bitcode), so .o is correct.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it confused me that your comment only extended until the line before :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the past, the bitcode was stored as a separate, compressed file in the archive (with the .bc.z extension). This was changed to simplify the implementation and to match the behavior of clang, which always places the bitcode in the .o file.

Copy link
Member

Choose a reason for hiding this comment

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

Kind of like .o for "output" :)

loader will skip any crates that have the wrong SVH.

The SVH is also used for the [incremental compilation] session filename,
though that usage is mostly historic.
Copy link
Member

Choose a reason for hiding this comment

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

What's used instead? I'm not sure what you mean by historic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the past, rustc would use the incremental directories of dependencies for resolving queries, and would use the SVH in the directory name to ensure it was querying the correct dependency. That was removed (it no longer looks for dependencies), and AFAIK it no longer looks at the SVH in the filename. I think it could be replaced with a random number and have the same effect (it uses a random number before it knows the svh, it gets renamed at the end).

The incremental naming convention is described at https://doc.rust-lang.org/nightly/nightly-rustc/rustc_incremental/persist/fs/index.html.

@jyn514 jyn514 merged commit 95c3930 into rust-lang:master Feb 4, 2021
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

Successfully merging this pull request may close these issues.

Introduce something about rmeta and metadata in general
3 participants