有什么做糕点的视频网站,怎么把视频制作成链接,西安大雁塔附近酒店推荐,推广方式英文目录
1. 获取 GCC 编译器预定义的宏
2. 列出依赖的头文件
3. 保存预处理结果到文件#xff08;展开define, 展开include header#xff09;
4. 写回调跟踪记录函数运行 -finstrument-functions
5. -fdump-rtl-expand 画函数调用关系图 GCC#xff0c;全称GNU Compiler …目录
1. 获取 GCC 编译器预定义的宏
2. 列出依赖的头文件
3. 保存预处理结果到文件展开define, 展开include header
4. 写回调跟踪记录函数运行 -finstrument-functions
5. -fdump-rtl-expand 画函数调用关系图 GCC全称GNU Compiler Collection是一套功能强大的开源编译器支持多种编程语言如C、C、Fortran、Objective-C、Ada等。GCC的灵活性和可移植性使得它在各种系统和项目中都有广泛的应用。然而要充分利用GCC的全部潜力需要熟悉一些高级特性和使用技巧。在本文中我们将探讨一些GCC的进阶用法帮助开发者优化代码、提高编译效率并减少潜在错误。
1. 获取 GCC 编译器预定义的宏
-E: 只运行预处理器。这意味着编译器将只处理源文件中的预处理器指令例如 #include、#define 等然后输出预处理后的代码。-dM: 输出所有的宏定义。当与 -E 一起使用时这将输出编译器预定义的所有宏。
]# gcc -E -dM -/dev/null
#define __DBL_MIN_EXP__ (-1021)
#define __FLT32X_MAX_EXP__ 1024
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
#define __FLT128_MAX_10_EXP__ 4932
#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F
#define __GCC_IEC_559_COMPLEX 2
#define __UINT_LEAST8_TYPE__ unsigned char
#define __SIZEOF_FLOAT80__ 16
#define __INTMAX_C(c) c ## L
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 0xff
#define __WINT_MAX__ 0xffffffffU
#define __FLT32_MIN_EXP__ (-125)
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 0xffffffffffffffffUL
#define __WCHAR_MAX__ 0x7fffffff
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __DBL_DENORM_MIN__ ((double)4.94065645841246544176568792868221372e-324L)
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
#define __GCC_IEC_559 22. 列出依赖的头文件
用于生成文件的依赖关系。这个选项对于大型项目特别有用因为它可以帮助你跟踪哪些头文件被哪个源文件包含以及当头文件更改时哪些源文件需要重新编译。
当你使用 gcc -M 选项时GCC 会输出一个规则集这个规则集描述了源文件和目标文件之间的依赖关系。输出的规则可以直接被 make 工具使用从而自动化构建过程。
$ gcc -M sizeofstruct.csizeofstruct.o: sizeofstruct.c /usr/include/stdc-predef.h \/usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \/usr/include/gnu/stubs-64.h \/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stddef.h \/usr/include/bits/types.h /usr/include/bits/typesizes.h \/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdarg.h \/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h3. 保存预处理结果到文件展开define, 展开include header
# cat test_e.c
#includeunistd.hint main(int argc, char** argv){printf(Hello world);return 0;
}# gcc -E test_e.c -o test_e.i[rootjun cprogram]# more test_e.i
# 1 test_e.c
# 1 built-in
# 1 command-line
# 31 command-line
# 1 /usr/include/stdc-predef.h 1 3 4
# 32 command-line 2
# 1 test_e.c
# 1 /usr/include/unistd.h 1 3 4
# 25 /usr/include/unistd.h 3 4
# 1 /usr/include/features.h 1 3 4
# 428 /usr/include/features.h 3 4
# 1 /usr/include/sys/cdefs.h 1 3 4
# 442 /usr/include/sys/cdefs.h 3 4
# 1 /usr/include/bits/wordsize.h 1 3 4
# 443 /usr/include/sys/cdefs.h 2 3 4
# 1 /usr/include/bits/long-double.h 1 3 4
# 444 /usr/include/sys/cdefs.h 2 3 4
# 429 /usr/include/features.h 2 3 4
# 452 /usr/include/features.h 3 4
# 1 /usr/include/gnu/stubs.h 1 3 4
# 10 /usr/include/gnu/stubs.h 3 4
# 1 /usr/include/gnu/stubs-64.h 1 3 4
# 11 /usr/include/gnu/stubs.h 2 3 4
# 453 /usr/include/features.h 2 3 4
# 26 /usr/include/unistd.h 2 3 4# 202 /usr/include/unistd.h 3 4
# 1 /usr/include/bits/posix_opt.h 1 3 4
# 203 /usr/include/unistd.h 2 3 4# 1 /usr/include/bits/environments.h 1 3 4
...# wc test_e.i1416 2357 24475 test_e.i
4. 写回调跟踪记录函数运行 -finstrument-functions
具体见老外写的一篇blog
我们组曾经用此跟踪过一个很棘手的问题。细节先不谈。
5. -fdump-rtl-expand 画函数调用关系图
用于在编译过程中输出 RTLRegister Transfer Language扩展阶段的中间表示。
当使用这个选项时GCC 会在编译过程中生成一个包含 RTL 扩展阶段信息的文本文件。这个文件以源文件的扩展名为基础添加了 .rtl-expand 后缀。例如如果你正在编译名为 foo.c 的源文件生成的 RTL 扩展文件将会是 foo.c.rtl-expand。
RTL 是 GCC 内部表示的一种中间语言用于在编译过程中的不同阶段之间传递信息。RTL 扩展阶段是 RTL 转换过程的一部分其中将高级 RTL 指令转换为更低级别的 RTL 指令以便后续的机器代码生成阶段。
我曾经用过此编译选项来结合Egypt来画函数调用关系图直接引用egypt给的一个例子