-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.Relevant to the dev-tools subteam, which will review and decide on the PR/issue.
Description
It would be great if there was a set of tools for dumping information about a given .rlib. This could be used to debug linkage and export issues.
Something like nm
and ldd
.
I note that nm
does appear to partly work on a .rlib, but the output is a bit raw.
Where is the best place to start for understanding the .rlib format as it stands? Is it a good idea to build this on rustc::metadata
?
See also http://stackoverflow.com/questions/24603672/rust-library-for-inspecting-rlib-binaries
Mart-Bogdan and stepancheg
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.Relevant to the dev-tools subteam, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
lifthrasiir commentedon May 27, 2015
cc me
For inspecting metadata this tool might be a good starting point. I have a version of that for post-reform metadata, I'll update the script soon.
novocaine commentedon May 27, 2015
👍
alexcrichton commentedon May 27, 2015
All rlibs are actually just static archives (e.g.
*.a
files) so tools likenm
andar
will work on them naturally assuming they ignore the non-object files located within (e.g. metadata and bytecode). As @lifthrasiir mentioned, however, I'd love to have a tool to inspect the metadata in more detail to, for example, dump a module structure, type signatures, etc. The metadata format is a huge black box and is indeed all centralized aroundrustc::metadata
. Note that a tool which does lots and lots with metadata will likely want to be tightly integrated to rustdoc as well as rustdoc already has tons of code to inspect metadata and reconstruct ASTs and/or module hierarchies.novocaine commentedon May 27, 2015
Would you expect ldd to work?
Otool on os x does not
alexcrichton commentedon May 27, 2015
I think that
ldd
andotool
only work on actual elf files like dynamic libraries and executables, so in that sense no I wouldn't expect them to work.novocaine commentedon May 28, 2015
(sorry about the 20 questions, but I can't find any resources on this stuff)
How do .rlibs link against 'normal' dynamic libraries provided to rustc via -l ? Is there an ELF image inside the ar somewhere that's dynamically linked against them? Or does rust embed dynamic loader code e.g dlopen?
alexcrichton commentedon May 28, 2015
That... may be because none exist :(. I'm more than willing to answer questions though!
No actual linkage occurs, the compiler emits information into the rlib metadata saying what dynamic native libraries should be linked in later, but they're not actually linked until the rlib is linked into a dylib or executable. If the rlib is later used to assemble a staticlib the compiler just prints out what native libraries are needed to link everything.
Nah the only ELF file inside rlibs is the object file that the compiler generates (and possibly the object files of native static libraries linked against).
No the compiler doesn't embed any code like this in this respect.
novocaine commentedon May 28, 2015
Thanks, Alex :)
6 remaining items
m4b commentedon Jun 30, 2017
I see. Is this something that's still actively desired, or not really? And what did you mean above about tightly integrated with rustdoc? The tool would use it as a lib to pretty print the metadata, or something else?
alexcrichton commentedon Jun 30, 2017
With not really much activity for >2 years I wouldn't necessarily classify this as "actively desired". The effort required to stabilize something like this seems quite high, but adding debugging utilities on nightly perhaps may not be so hard.
m4b commentedon Jun 30, 2017
Ok.
While you're here, do you know offhand what the contents of
bytecode.deflate
are? I've asked on the channel but no one seems to know, and I can't seem to find it documented anywhere.alexcrichton commentedon Jun 30, 2017
Yes it's just compressed LLVM bytecode. The actual format is a bit wonky with some headers and maybe a footer, you'd have to look around in trans for the exact format.
m4b commentedon Jun 30, 2017
Cool, thanks so much for your time and answers :)
Let me know if there's something similar to this w.r.t. binary formats, etc., that might need some help/tooling, would be interested in helping.
ruuda commentedon Dec 6, 2017
I am trying to obtain the stdlib bitcode, so I can use
llvm-link
to produce a self-contained bitcode program. Being able to extract it from the rlibs would be nice, because those are bundled with Rust, and I wouldn’t have to compile everything from source. However, I have been unable to decompress thebytecode.deflate
file, which makes sense if it contains Rust-specific headers. (It definitely starts withRUST_OBJECT
.) Is there a simple way to strip these headers so I can inflate the data?steveklabnik commentedon Sep 17, 2019
Triage; not aware of anyone having implemented this, which, given the fact that all of this is unstable, isn't that surprising. It would be nice to have, but it's unclear that it's a good idea to keep this issue open.
Mart-Bogdan commentedon Mar 5, 2020
This os really needed feature, as currently IDEs (Idea and rls/rust-analyzer) have to expand all macros and analyze source code of dependecies.
It would be nice if they would be able to extract info about types and signarures from rlib in sone json format.
AFAIK Currently there are no way to provide autocompletion for proc-macro generated code. Only for regular macros, as IDEs are expanding them by themselves, but it looks like overkill for already compiled libraries.
.rlib
archive files llvm/llvm-project#53395bjorn3 commentedon May 15, 2022
Current rustc has
-Zls
which dumps a tiny bit of information:I also wrote https://github.com/bjorn3/rust_read_rlib at some point, but it would need to be updated to latest rustc.
SamB commentedon Sep 15, 2024
It seriously vexes me that things like this can't be allowed on stable because somebody would inevitably come to rely on the exact format of the output. :-(
Specifically, the part where we can't inspect the rust-specific metadata.
The fact that such functionality would be nightly-only probably isn't helping to motivate anyone to implement it.