Understanding Stable ABI Problem

In trying to understand some of the complications in doing full Rust inside precompiled dynamic libraries, I decided to do some experiments: write test code, compile it, then look at the disassembly.

When I look at output from my run of objdump -D -S […] (a rather big file) I see my source code, I see source code from other other crates I call, but I don't see sources for things in std. Why not? (Don't tell me std is precompiled…)

Thanks,

-kb

It generally is. Perhaps here is a good jumping-off point.

3 Likes

My puzzlement is how can std managed to be precompiled? Or is it only somewhat precompiled, if I call a generic function with some new type the generic still gets compiled for my type?

-kb

For any library crate, standard library or not, rustc takes the source code and produces an .rlib file which contains machine code for non-generic functions and MIR for generic or inlinable functions.

The difference between std and other libraries is that std is compiled as part of the Rust release and delivered to you, but other libraries are compiled on demand by Cargo. But even for those, the compilation process still proceeds unidirectionally — if crate foo uses generic functions from crate bar, then the applicable machine code for bar's generic functions is generated as part of compiling foo, not by going back and saying “compile bar again with these instantiations!”.

As a consequence of this, the std source code does not need to be present — and is not by default, but you can install it with rustup component add rust-src. I'm not sure whether that will automatically enable your objdump to find it.

3 Likes

Ah, cool. That makes sense.

And I do already have rust-src installed, which is why I can see inside std with gdb. There must be a way to get objdump to find them, but I don't immediately find it, and I don't have a specific need at the moment.

Interesting, thanks.

-kb

P.S. And I realize an extremely heavy weight (and fragile) way to do dynamic libraries would be to "just" use .rlib files!