【发布时间】:2016-07-13 08:12:05
【问题描述】:
我想只使用我特别提到的编译器选项来编译 C 代码。因此,我需要以某种方式禁用所有自动设置的编译器选项。如何禁用在每次编译期间设置且不可见的默认 GCC 选项。我说的是使用以下命令gcc -Q -v example.c 导致此输出可见的编译器选项:
GNU C (Ubuntu 4.8.4-2ubuntu1~14.04.3) version 4.8.4 (x86_64-linux-gnu)
compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
options passed: -v -imultiarch x86_64-linux-gnu example.c -mtune=generic
-march=x86-64 -fstack-protector -Wformat -Wformat-security
options enabled: -faggressive-loop-optimizations
-fasynchronous-unwind-tables -fauto-inc-dec -fbranch-count-reg -fcommon
-fdelete-null-pointer-checks -fdwarf2-cfi-asm -fearly-inlining
-feliminate-unused-debug-types -ffunction-cse -fgcse-lm -fgnu-runtime
-fgnu-unique -fident -finline-atomics -fira-hoist-pressure
-fira-share-save-slots -fira-share-spill-slots -fivopts
-fkeep-static-consts -fleading-underscore -fmath-errno
-fmerge-debug-strings -fmove-loop-invariants -fpeephole
-fprefetch-loop-arrays -freg-struct-return -fsched-critical-path-heuristic
-fsched-dep-count-heuristic -fsched-group-heuristic -fsched-interblock
-fsched-last-insn-heuristic -fsched-rank-heuristic -fsched-spec
-fsched-spec-insn-heuristic -fsched-stalled-insns-dep -fshow-column
-fsigned-zeros -fsplit-ivs-in-unroller -fstack-protector
-fstrict-volatile-bitfields -fsync-libcalls -ftrapping-math
-ftree-coalesce-vars -ftree-cselim -ftree-forwprop -ftree-loop-if-convert
-ftree-loop-im -ftree-loop-ivcanon -ftree-loop-optimize
-ftree-parallelize-loops= -ftree-phiprop -ftree-pta -ftree-reassoc
-ftree-scev-cprop -ftree-slp-vectorize -ftree-vect-loop-version
-funit-at-a-time -funwind-tables -fvar-tracking -fvar-tracking-assignments
-fzero-initialized-in-bss -m128bit-long-double -m64 -m80387
-maccumulate-outgoing-args -malign-stringops -mfancy-math-387
-mfp-ret-in-387 -mfxsr -mglibc -mieee-fp -mlong-double-80 -mmmx -mno-sse4
-mpush-args -mred-zone -msse -msse2 -mtls-direct-seg-refs
Compiler executable checksum: a0a649d344b1ed798e33d30772d46437
这里默认的编译器选项可以看成options enabled。如何在不使用例如的情况下禁用这些选项-fno-... 对于他们中的大多数人。有没有一种简单的方法可以正确禁用默认编译器选项?
【问题讨论】:
-
关闭所有
-f...选项后您希望获得什么?请注意,其中一些选项不能“关闭”,因为它们在两个不同的选项之间进行选择,例如-mlong-double-80在 128 位和 80 位long double之间进行选择。 -
我想关闭我知道的所有默认编译器选项。之后,我只想设置我主动设置的编译器选项。这对于真正了解激活了哪些编译器选项来编译特定代码是必要的。
-
@FUZxxl:在禁用所有选项的情况下,gcc 处理的方言类似于 1990 年代流行的方言,其中包括许多有用的特性和保证,这些特性和保证从标准中省略,因为存在或可能已经存在平台成本将超过他们的收益。例如,如果代码需要将有符号值按正整数缩放,我认为 gcc 目前将支持
x<<=y;而不需要例如x=(int32)((uint32_t)x)<<y);,但程序员无法知道下一个 gcc 版本是否需要额外的-fno-silly-signed-shift才能使其工作。
标签: c gcc compilation compiler-optimization default-value