How to disassemble .elf file to .asm file in riscv

Viewed 1240

I have generated a .elf file by using

riscv64-unknown-elf-gcc -march=rv64imac -mabi=lp64 -Tlinker.ld *.o add.o -o add.elf -static -nostartfiles -lm -lgcc

And now I want to see the stack to check the values assigned to variables used in my add.c. I believe the same can be obtained from a .dasm/.asm file. How can I generate a .asm/.dasm file from an .elf file?

2 Answers

Just as an extension to dratenik's answer.

I am using riscv32-unknown-elf-objdump --disassemble-all NAME.elf > NAME.disasm

This way you don't even have to go over the -S option. And can just disassemble your .elf file.

Again as dratenik noted you need to adjust the prefix of objdump to you toolchain aka. your compiler prefix

You can stop gcc at the assembly stage by adding the -S switch, the file output by -o will then be an asm source file. Or you can let gcc finish and then take the resulting binary apart with objdump -d. Of course you need to run the objdump binary from the same toolchain, not your system one.

Related