How to best investigate the mapping from Rust to assembly?


#1

I’d like to investigate what a method actually compiles to. I’d like to get an assembly view of a release-compiled method with some kind of annotation of what source code particular bits of assembly roughly correspond to. (The methods I’m interested in looking at are trying to inline a whole bunch of little methods whose structs I’m hoping to get flattened out.)

Is there a tool for this? (Bonus awesomeness if there’s a tool that integrates with RustDT for Eclipse.)


#2

Have you seen this? https://rust.godbolt.org/


#3

Since the optimizer looks at the whole program, exactly how it inlines things will change with how the methods of the struct are used in the whole program.


#4

Have you seen this? https://rust.godbolt.org/

I hadn’t. Thank you.

The case I want to investigate is spread across multiple source files. Do I need to paste everything together in order to use that tool?

Since the optimizer looks at the whole program, exactly how it inlines things will change with how the methods of the struct are used in the whole program.

Surely LTO doesn’t change things that are strictly crate-internal? In my case, the stuff I’m interested in is completely crate-internal, so I don’t expect the optimization to depend on stuff outside the crate.

Concretely, I’m interested in how the conversion loops in encoding_rs actually compile:


#5

The best approach that I’ve found so far is building as staticlib and doing:

RUSTFLAGS=-g cargo build --release
objdump -C -S target/release/libencoding_rs.a | less

The RUSTFLAGS=-g bit turned out to be important to make objdump -S work.


#6

Related topic Checking how well my programs optimized


#7

Hmm. Actually, the source interleaving produced by objdump -S seems to be completely bogus. :cry: