Compiler Explorer seems to be able to reliably find the assembly code corresponding to a function. How can I do that myself, assuming a x86_64-unknown-linux-gnu
toolchain, a regular (no attributes) function, and without extra tools like cargo-asm
?
I know that to produce the assembly, I can use rustc's --emit asm
flag. One might think that finding the function is easy as searching for its name in the .s file, but I found that it's not.
For instance, the .s file often doesn't even mention the function name, in which case adding #[inline(never)]
to the function helps. Second, having found the label with the function name, how do you determine where the function ends? In my test crate, I found a second mention of the function name in a .size
directive farther down – does that maybe mark the end of the function? Or is it maybe the first retq
after the function start?
Assuming this goal is achievable, I hope to learn:
- What are the most reliable ways to find the start and end of a function?
- What are the prerequisites for getting suitable assembly files to do that?