带有调试选项的 GCC 编译阶段
gcc compile stages with debug options
我正在尝试研究GCC的不同编译阶段。
手动逐阶段编译
$ 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
并完全使用"仅 g++"再次编译
$ g++ -c main.cpp -o main.gcc.o # G1
$ g++ -c main.cpp -o main.gcc.debug.o -ggdb -g3 # G2
在最后
main.as.o 与 main.gcc.o 相同,没有调试信息
但
main.as.debug.o 与 main.gcc.debug.o 非常不同
为什么?我错过了什么吗?
这是工具版本
$ 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
更新
使用 -v 和 -save-temps 选项,此处显示了等效的命令
#####
# $ 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
#####
哎呀,这是我微不足道的失败。
原始帖子
$ 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
我也需要使用调试选项调用 -E 并进入下一阶段......
应该改为...
$ g++ -E main.cpp -o main.debug.i -ggdb -g3 # I2
$ g++ -S main.debug.i -o main.debug.s -ggdb -g3 # S2'
那么以下阶段将生成相同的机器代码...
相关文章:
- 为什么 gcc 编译这个而 msvc 没有
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- GCC,CMake,预编译标头和维护依赖项
- GCC 8.3 无法编译 std::bind_front
- Clang不会编译GCC会编译的模板专业化
- 使用交叉工具ng编译gcc时出错
- 编译 GCC-5.0 OS X 狮子 dyld:找不到符号:__ZNKSt11logic_error4whatEv
- 在类中将不完整类型的unique_ptr初始化为 nullptr 时编译 gcc 错误
- 除了 Linux 上的源代码和编译 (GCC) 之外,有没有办法在 Windows 中托管 IDE
- 在 64 位 debian 上编译 GCC 的代码可视化补丁
- 编译gcc 4.6.4中的boost::move
- 模板编译:gcc vs VS2010
- C++ 使用编译器编译"gcc"简单文件
- 如何从php编译GCC
- 在 Visual Studio 中编译 gcc 代码会导致错误 C3646:"__attribute__":未知的覆盖说明符
- 在windows上编译gcc 4.7
- 在Vortex86DX上从头开始构建和编译GCC 5.2.0时出错
- 在编译GCC时出错部分模板专门化,而不是MSVC
- GLM Math lib 编译 GCC 错误
- Synology交叉编译GCC -std=c++0x