Page 1 of 1

How do you get assembler output from GCC in SGDK

Posted: Wed Nov 16, 2016 8:06 pm
by astrofra
Dear all,

I'm trying to obtain the assembler code generated out of my .C files by GCC.
The aim is to understand how my C code is translated into ASM and maybe find some way to optimize certain critical parts of my code.

The "stackoverflow" thread here mentions the -S option, that works when used in a single command line.
However, I'd like to use it on my whole project, when it is built by the SGDK's makefile.

I tried this compilation flags in 'makefile.gen' :

Code: Select all

release: FLAGS= $(DEFAULT_FLAGS) -S -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer
but it fails during the compilation :

Code: Select all

D:/apps/dev/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/apps/dev/sgdk/inc -ID:/apps/dev/sgdk/res -BD:/apps/dev/sgdk/bin -S -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -c src/boot/rom_head.c -o out/rom_head.o
D:/apps/dev/sgdk/bin/ld -T D:/apps/dev/sgdk/md.ld -nostdlib --oformat binary -o out/rom_head.bin out/rom_head.o
out/rom_head.o: file not recognized: File format not recognized
make: *** [out/rom_head.bin] Error 1
Any idea? :')
I'm probably doing something stupid...

Re: How do you get assembler output from GCC in SGDK

Posted: Wed Nov 16, 2016 10:21 pm
by Stef
In fact it does work: the .o file contains the assembly output instead of binary code, it's why it can't complete the linking process...
But at least you have your assembly code :)

Re: How do you get assembler output from GCC in SGDK

Posted: Thu Nov 17, 2016 6:37 pm
by Miquel
This is how I do it:

Code: Select all

$(CC) -c -g -Wa,-a,-ad $(FLAGS) $< > $@
It not only outputs asm code, but everything else.

Re: How do you get assembler output from GCC in SGDK

Posted: Mon Nov 21, 2016 9:10 pm
by astrofra
Thanks dudes.
Alas, none of the above seems to work on my SGDK version. Probably, I'm not using these option the proper way.
I finally find a working alternative here :
http://www.systutorials.com/240/generat ... using-gcc/

I dump all the ASM source code directly from the console, using '> asm_src.txt'

Thanks for your help, anyway :)