Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Elena on November 17, 2022, 01:27:45 pm

Title: In troubles trying to display the resulting assembly
Post by: Elena on November 17, 2022, 01:27:45 pm
Hi, as a premise I am not expert with GCC technical details, I am using CB with MinGW to develop on Windows.
Often I need to have a look at the resulting assembly but I am having a hard time achieving such a simple task.
Googling around, I noticed I must use the -S option for gcc not to assemble and link the project sources but to rather generate an intermediate assembly file one can inspect.

Unfortunately if I add the "-S" option in the list of Other Compiler options (where all my other options reside and work fine, like -mfma for example) on building I get the following error:

||=== Build: Release in Workbench (compiler: MINGW_x64) ===|
d:\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\12.1.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe:obj\Release\ED_Shared\FastMath32.o|1|syntax error|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 4 warning(s) (0 minute(s), 0 second(s)) ===|



here is the build log:


-------------- Build: Release in Workbench (compiler: MINGW_x64)---------------

g++.exe -Wall -std=c++17 -m64 -O3 -mfma -S -ID:\mingw64 -c E:\SE_SDK\_Workbench\main.cpp -o obj\Release\_Workbench\main.o

g++.exe  -o Workbench.exe obj\Release\ED_Shared\FastMath32.o obj\Release\_Workbench\main.o  -static-libstdc++ -static-libgcc -static -m64 -s  ..\ESD_SDK\libESDToolKit.a -liphlpapi -lgdi32

d:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:obj\Release\ED_Shared\FastMath32.o: file format not recognized; treating as linker script

d:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:obj\Release\ED_Shared\FastMath32.o:1: syntax error

collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 4 warning(s) (0 minute(s), 0 second(s))


What should I do from within C::B to have the resulting assembly file(s) to inspect, without having to issue gcc commands manually in a shell ? Thanks in advance for any relevant support !

Title: Re: In troubles trying to display the resulting assembly
Post by: Miguel Gimenez on November 17, 2022, 05:56:46 pm
The compiler saves the generated assembly in main.o, and the linker tries to interpret it as an object file. See the first answer here (https://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc) for more information.
Title: Re: In troubles trying to display the resulting assembly
Post by: Elena on November 17, 2022, 09:27:09 pm
Geez! I could never have figured out it saved the asm as main.o and not main.s  :o :o I will check the link thx
Title: Re: In troubles trying to display the resulting assembly
Post by: jordi on November 17, 2022, 09:32:40 pm
Try to use -save-temps option which will leave all the temporary files including the .s file
Title: Re: In troubles trying to display the resulting assembly
Post by: Elena on November 17, 2022, 10:45:47 pm
Thank you ALOT Jordi, the -save-temps option does *exactly* what I needed, wow  :D :D :D :D :D :D