rnd_nr_gen
rnd_nr_gen

Reputation: 2281

gcc compile stages with debug options

I am trying to study different compilation stage from GCC.

Compile stage by stage manually

$ g++ -E main.cpp -o main.i                  # I1

$ g++ -S main.i -o main.s                    # S1
$ g++ -S main.i -o main.debug.s -ggdb -g3    # S2

$ as main.s       -o main.as.o               # O1
$ as main.debug.s -o main.as.debug.o         # O2

And compile again with "g++ only" completely

$ g++ -c main.cpp -o main.gcc.o                  # G1
$ g++ -c main.cpp -o main.gcc.debug.o -ggdb -g3  # G2

At the end

main.as.o is identical with main.gcc.o without debug info

but

main.as.debug.o is very different from main.gcc.debug.o

Why? do I miss anything?

here is the tool version

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++-7
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/7.2.0/libexec/gcc/x86_64-apple-darwin13.4.0/7.2.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../configure --build=x86_64-apple-darwin13.4.0 --prefix=/usr/local/Cellar/gcc/7.2.0 --libdir=/usr/local/Cellar/gcc/7.2.0/lib/gcc/7 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-7 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC 7.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls
Thread model: posix
gcc version 7.2.0 (Homebrew GCC 7.2.0)

$ as -v
Apple Inc version cctools-862, GNU assembler version 1.38

UPDATE

with -v and -save-temps options here shows the equivalent commands

#####

# $ g++ -E main.cpp -o main.i                # I1
$ cc1plus -E -quiet -v -D__DYNAMIC__ main.cpp -o main.i -fPIC -mmacosx-version-min=10.9.4 -mtune=core2

#####

# $ g++ -S main.i -o main.s                  # S1
$ cc1plus -fpreprocessed main.i -fPIC -quiet -dumpbase main.i -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase-strip main.s -version -fdump-tree-all-graph -o main.s

#####

# $ g++ -S main.i -o main.debug.s -ggdb -g3  # S2
$ cc1plus -fpreprocessed main.i -fPIC -quiet -dumpbase maini -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase-strip main.debug.s -ggdb -g3 -version -o main.debug.s

#####

$ as main.s       -o main.as.o               # O1
$ as main.debug.s -o main.as.debug.o         # O2

#####

# g++ -c main.cpp -o main.gcc.o                  # G1

$ cc1plus -E -quiet -v -D__DYNAMIC__ main.cpp -fPIC -mmacosx-version-min=10.9.4 -mtune=core2 -fpch-preprocess -o main.ii

$ cc1plus -fpreprocessed main.ii -fPIC -quiet -dumpbase main.cpp -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase-strip main.gcc.o -version -o main.s

$ as -arch x86_64 -v -force_cpusubtype_ALL -o main.gcc.o main.s

#####

# g++ -c main.cpp -o main.gcc.debug.o -ggdb -g3  # G2

$ cc1plus -E -quiet -v -dD -D__DYNAMIC__ main.cpp -fPIC -mmacosx-version-min=10.9.4 -mtune=core2 -ggdb -g3 -fworking-directory -fpch-preprocess -o main.ii

$ cc1plus -fpreprocessed main.ii -fPIC -quiet -dumpbase main.cpp -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase-strip main.gcc.debug.o -ggdb -g3 -version -o main.s

$ as -arch x86_64 -v -force_cpusubtype_ALL -o main.gcc.debug.o main.s

#####

Upvotes: 3

Views: 1192

Answers (1)

rnd_nr_gen
rnd_nr_gen

Reputation: 2281

Oooops, it is trivial failure by me.

Original post

$ g++ -E main.cpp -o main.i                  # I1

$ g++ -S main.i -o main.s                    # S1
$ g++ -S main.i -o main.debug.s -ggdb -g3    # S2

I need to call -E also with debug options and serve to the next stage....

Should change to...

$ g++ -E main.cpp -o main.debug.i  -ggdb -g3       # I2

$ g++ -S main.debug.i -o main.debug.s -ggdb -g3    # S2'

then the following stages will generate same machine code...

Upvotes: 1

Related Questions