Let’s start with some GCC commands as shown below.
[terminal]
[root@humbles-lap gcc]# gcc -S -c program.c
[root@humbles-lap gcc]# ls
program.c program.s
[root@humbles-lap gcc]# file program.s
program.s: ASCII assembler program text
[root@humbles-lap gcc]# cat program.s |head -n 5
.file “program.c”
.section .rodata
.align 8
.LC0:
.string “\n I am always an example program”
[/terminal]
How-ever it won’t give you all the resulted files in each stage, for ex: preprocessor files. For that, I use below GCC option to generate different output files of my source.
[terminal]
#man gcc
-save-temps
-save-temps=cwd
Store the usual “temporary” intermediate files permanently; place them in the current directory and name them based on
the source file. Thus, compiling foo.c with -c -save-temps would produce files foo.i and foo.s, as well as foo.o.
This creates a preprocessed foo.i output file even though the compiler now normally uses an integrated preprocessor.
When used in combination with the -x command line option, -save-temps is sensible enough to avoid over writing an input
source file with the same extension as an intermediate file. The corresponding intermediate file may be obtained by
renaming the source file before using -save-temps.
If you invoke GCC in parallel, compiling several different source files that share a common base name in different
subdirectories or the same source file compiled for multiple output destinations, it is likely that the different
parallel compilers will interfere with each other, and overwrite the temporary files. For instance:
gcc -save-temps -o outdir1/foo.o indir1/foo.c&
gcc -save-temps -o outdir2/foo.o indir2/foo.c&
may result in foo.i and foo.o being written to simultaneously by both compilers.
[/terminal]
As mentioned in “man’ page it will generate “.i”, “s”, “.o” files ..
Ex:
[terminal]
[root@humbles-lap gcc]# ls
program.c
[root@humbles-lap gcc]# gcc -o program program.c –save-temps
[root@humbles-lap gcc]# ls
program program.c program.i program.o program.s
[root@humbles-lap gcc]# file program.i
program.i: ASCII C program text
[root@humbles-lap gcc]# file program.s
program.s: ASCII assembler program text
[root@humbles-lap gcc]# file program.o
program.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
[root@humbles-lap gcc]# file program
program: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped
[/terminal]
#Examine those “intermediate files” and try to make sense out of it.. it is funny. I will write more about each stage in another blog.
Copyright secured by Digiprove © 2020 Humble Chirammal
Informative post.. Thanks for it..
Really informative idea.