1

I was wondering how to get .s file from .bin compiled with IAR. Trying the gdb and objdump without success.

Looking in IAR project option page, but didn't find nothing consistent to create .s at compilation.

Any idea? Thanks you in advance .

 $ gdb -q ./prj.bin
(gdb) "C:\git\...\EWARM\BUILD\Exe/./prj.bin": not in executable format: File format not recognized
(gdb) Quit (expect signal SIGINT when the program is resumed)

$ objdump -d prj.bin
C:\MinGW\bin\objdump.exe: prj.bin: File format not recognized
  • MinGW `objdump` will be built for x86, not whatever architecture you compiled for with IAR. However, you *can* tell `objdump` to disassemble flat binaries (assuming they're x86) instead of looking for metadata. [Disassembling A Flat Binary File Using objdump](https://stackoverflow.com/q/14290879) Not that `objdump -D -Mintel,x86-64 -b binary -m i386 foo.bin` will help, it will disassemble the bytes of your `.bin` as if they were x86-64 instructions. – Peter Cordes Mar 23 '23 at 14:17
  • As far as I know, IAR doesn't have x86 compiler. It is very unlikely that MinGW tools help at all. – user694733 Mar 23 '23 at 15:15

1 Answers1

1

The IAR compiler has the -l option for generating Assembly files from C sources.

-l[c|C|D|E|a|A|b|B][N][H] file|directory
                Output list file
                   c     C source listing
                   C        with assembly code
                   D        with pure assembly code
                   E        with non-sequential assembly code
                   a     Assembler file
                   A        with C source
                   b     Basic assembler file
                   B        with C source
                   N     Do not include diagnostics
                   H     Include header file source lines

Example for generating file.s from file.c:

iccarm -lb . file.c -o file.o

With only a binary without its sources, you will need a 3rd party utility such as IDA Pro, arm-none-eabi-objdump, or similar.

One example, with arm-none-eabi-objdump:

 arm-none-eabi-objdump -b binary -marm -Mforce-thumb -D <file>.bin

Either way, the binary won't give you symbolic names nor sections as you would be able to dump from an ELF. Moreover you have to inform if the executable was built for targets using thumb instructions (-Mforce-thumb).

In the end, dumping a raw binary will give, in the best case, educated guesses about the raw picture of the entire executable.

Good luck.

sharpgeek
  • 481
  • 2
  • 14