我希望只使用我特别提到的编译器选项来编译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
这里默认的编译选项可以看作是启用的选项
。我要如何禁用其中大部分选项而不使用-fno-...
等方式?有没有一种简单的方法来正确地禁用默认的编译选项呢?
-f...
选项获得什么?请注意,其中一些选项无法“关闭”,因为它们在两个不同的选择之间进行选择,例如-mlong-double-80
在 128 位和 80 位long double
之间进行选择。 - fuzx<<=y;
而不是要求例如x=(int32)((uint32_t)x)<<y);
,但程序员无法知道下一个gcc版本是否需要额外的-fno-silly-signed-shift
才能使其工作。 - supercat