From C to assembly

how can I get the assembly code from program C, I used this recommendation and I use something like this -c -fmessage-length=0 -O2 -S in Eclipse, but I have an error, thanks in advance for any help

now i have this error

  atam.c:11: error: conflicting types for 'select' /usr/include/sys/select.h:112: error: previous declaration of 'select' was here atam.c:11: error: conflicting types for 'select' /usr/include/sys/select.h:112: error: previous declaration of 'select' was here 

this is my function

 int select(int board[],int length,int search){ int left=0, right=length-1; while(1){ int pivot_index=(right+left)/2; int ordered_pivot=partition(board,left,right,pivot_index); if(ordered_pivot==search){ return board[ordered_pivot]; } else if(search<ordered_pivot){ right=ordered_pivot-1; } else{ left=ordered_pivot+1; } } } 
+4
source share
3 answers

Eclipse still treats output as an object file

 gcc -O0 -g3 -Wall -c -fmessage-length=0 -O2 -S -oatam.o ..\atam.c 

generates the assembly as you want, but embarrassingly storing it in atam.o due to -oatam.o passed to GCC (usually you will store the assembly in atam.s ). Next command:

 gcc -oatam.exe atam.o 

Trying to link atam.o and generate an executable, but atam.o is the source of the assembly, not the object file, so the linker does not work. You need to tell eclipse not to run the second command (and you probably want to change the output file name for the first)

+5
source

The error occurs because select is a Unix system call, and your definition encounters a declaration in the corresponding system header. You need to rename your function.

+2
source

-S instructs the compiler not to execute the actual compilation and linking step and stop after emitting the assembly. On the other hand, you also tell the compiler to compile the file on the same line (in addition to other conflicting settings).

Try the following:

 gcc -O0 -S ../atam.c 

Optimization will result in an assembly file that is remote from the source code, so I instructed gcc to disable the optimization. Also do not start the linker.

+1
source

Source: https://habr.com/ru/post/1310629/


All Articles