首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法抑制默认的GCC编译器选项?

有没有办法抑制默认的GCC编译器选项?
EN

Stack Overflow用户
提问于 2016-07-13 16:12:06
回答 1查看 979关注 0票数 2

我只想用我特别提到的编译器选项编译一个C代码。因此,我需要以某种方式禁用所有自动设置的编译器选项。如何禁用在每次编译过程中设置的不可见的默认GCC选项。我所说的是使用以下命令gcc -Q -v example.c可见的编译器选项,这些选项将导致此输出:

代码语言:javascript
复制
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-...的情况下禁用这些选项。有没有一种简单的方法来正确禁用默认的编译器选项?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-13 16:47:49

使用以下脚本生成所有已关闭的-f选项的列表:

代码语言:javascript
复制
gcc -Q --help=optimizers | sed -e '/^[^[]*$/d' -e 's/ *\[.*$//' -e 's/^  -f/ -fno-/'

将结果保存在名为options.txt的文件中,并使用@-语法将其传递给gcc:

代码语言:javascript
复制
gcc @options.txt ...

请注意,这不会“关闭”其他选项,例如-m...选项。它们中的大多数不能被“关闭”,因为它们不是是/否开关,或者因为这样做会改变ABI。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38346069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档