assembly output

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
Posts: 14
Joined: Fri May 19, 2017 8:35 am

Re: assembly output

Post by fotisl » Sun Jul 02, 2017 6:27 am

When you add the -S option, gcc outputs the assembly file instead of the object file. So, the .o files are actually your program's assembly code. When the linker tries to link these, it can't recognize valid object files, so they are interpreted as linker scripts, but they are still invalid.
Objdump is a good solution, but you will lose valuable information, such as labels etc. If you decide to use objdump, remember to use the -d option with the elf file (you can find it at the build directory), or the -D -b binary options with the final firmware.
If I were you I would change the recipe.c.o.pattern and recipe.cpp.o.pattern variables to include 2 commands, one for generating the assembly and one for the object file. I think you can use the '&' symbol to concat to commands in a single line under windows, so I believe you could do something like:

Code: Select all

recipe.cpp.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} ... -o "{object_file}" & "{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -S ... -o "{object_file}.s"
I believe that for a file named hello.cpp this would output a hello.o file in the build directory which would be a valid object file and the linking would continue, and a hello.o.s file which would be the assembly code. I am not 100% sure though since I don't have a windows box to try it.
You can also change the compiler.c.cmd command to point to a batch file which will in turn run gcc with the provided options and produce an object file and it's assembly code.

User avatar
Posts: 1650
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland

Re: assembly output

Post by ahull » Sun Jul 02, 2017 11:53 am

There are a number of other suggestions for command line switches you might like to try here -> ... rce-in-gcc
- Andy Hull -

Post Reply