GCC User Guide and gcc best compilation Parameters

Source: Internet
Author: User
GCC User Guide and gcc best compilation parameters-general Linux technology-Linux programming and kernel information. The following is a detailed description. GCC User Guide

Syntax:
Gcc [option | filename]...
G ++ [option | filename]...

Where option is the option used for gcc (which will be detailed later ),
Filename is the object to be processed with gcc.

Note:
This C and C ++ compiler have integrated the related programs that generate new programs. Production
A new program requires four stages: preprocessing, compilation, assembly, and linking.
Compilers can process input files in different stages. Although the extension of the original program is
It is used to distinguish the language used to write the original program code, but different compiler, its preset Processing
Different programs:

Gcc presets files that have been preprocessed (with the extension. I) to C language, and
The connection phase is processed in C connection mode.

G ++ defaults that files that have been preprocessed (with the extension. I) are in the C ++ language.
The sequential connection phase is processed in the C ++ connection mode.

The extension of the original code indicates the language used for programming and the corresponding
Management Method:

Original. c program; preprocessing, compilation, and assembly
Original. C ++ program; preprocessing, compilation, and assembly
. Cc C ++ original program; preprocessing, compilation, and assembly
. Cxx C ++ original program; preprocessing, compilation, and assembly
. M Objective-C original program; preprocessing, compilation, assembly
. I original C program that has been preprocessed; compilation and assembly
. Ii Original C ++ program that has been preprocessed; compilation and assembly
Original program of. s combination language; Assembly
Original program of. S combination language; preprocessing and compilation
. H pre-processing file (header file); (not frequently displayed in the command line)

Files with other extensions are processed by the link program, usually including:
. O Object file
. A Archive file

Unless an error occurs during the compilation process, the "Link" must be the most
Later Stage. However, you can also set the entire process from
Phase. In the connection phase, all
. O files, libraries, and other files that cannot identify attributes from the file name (including files that do not use. o
Object file with the extension and archive file with the extension.)
It is handled by the link program (the files in the command line are passed as parameters of the link Program
Link program ).

Option:

Different options must be separated. For example, the '-write' option is larger than the'-d-R' option.
Different.
Most of the '-F' and'-W' options have two forms:-fname and
-Fno-name (or-Wname and-Wno-name ). Only the non-preset ones are listed below
Format.
The following is a summary of all options. In the form. The meaning of the option will be explained in another section.
Ming.

General (rough, common) Options
-C-S-E-o file-pipe-v-x language

Program language options
-Ansi-fall-virtual-fcond-mismatch
-Fdollars-in-identifiers-fenum-int-equiv
-Fexternal-templates-fno-asm-fno-builtin
-Fno-strict-prototype-fsigned-bitfields
-Fsigned-char-fthis-is-variable
-Funsigned-bitfields-funsigned-char
-Fwritable-strings-traditional-cpp
-Trigraphs

Warning options during compilation
-Fsyntax-only-pedantic-errors-w-W
-Wall-Waggregate-return-Wcast-align-Wcast-qual
-Wchar-subscript-Wcomment-Wconversion
-Wenum-clash-Werror-Wformat-Wid-clash-len
-Wimplicit-Winline-Wmissing-prototypes
-Wmissing-declarations-Wnested-externs-Wno-import
-Wparentheses-Wpointer-arith-Wredundant-decls
-Wreturn-type-Wshadow-Wstrict-prototypes-Wswitch
-Wtemplate-debugging-Wtraditional-Wtrigraphs
-Wuninitialized-Wunused-Wwrite-strings

Debugging options
-A-dletters-fpretend-float-g-glevel-gcoff
-Gxcoff +-gdwarf +-gstabs +
-Ggdb-p-pg-save-temps-print-file-name = library
-Print-libgcc-file-name-print-prog-name = program

Optimization Options
-Fcaller-saves-fcse-follow-jumps-fcse-skip-blocks
-Fdelayed-branch-felide-constructors
-Fexpensive-optimizations-ffast-math-ffloat-store
-Fforce-addr-fforce-mem-finline-functions
-Fkeep-inline-functions-fmemoize-lookups
-Fno-default-inline-fno-defer-pop
-Fno-function-cse-fno-inline-fno-peephole
-Fomit-frame-pointer-frerun-cse-after-loop
-Fschedule-insns-fschedule-insns2
-Fstrength-reduce-fthread-jumps-funroll-all-loops
-Funroll-loops-O-O2

Preprocessing options
-Aassertion-C-dD-dM-dN-Dmacro [= defn]-E-H
-Idirafter dir-include file-imacros file-iprefix
File-iwithprefix dir-M-MD-MM-MMD-nostdinc-P
-Umacro-undef

Assembler options
-Wa, option
Link Program Options
-Llibrary-nostartfiles-nostdlib-static-shared
-Symbolic-Xlinker option-Wl, option-u symbol

DIRECTORY Options
-Bprefix-Idir-I-Ldir

Target Options
-B machine-V version

Machine (Platform) related options
M680x0 Options
-M68000-m68020-m68020-40-m68030-m68040-m68881
-Mbitfield-mc68000-mc68020-mfpa-mnobitfield
-Mrtd-mshort-msoft-float

VAX Options
-Mg-mgnu-munix

Iscsi Options
-Mepilogue-mfpu-mhard-float-mno-fpu
-Mno-epilogue-msoft-float-msparclite-mv8
-Msupernames-mcypress

Convex Options
-Margcount-mc1-mc2-mnoargcount

AMD29K Options
-M29000-m29050-mbw-mdw-mkernel-registers
-Mlarge-mnbw-mnodw-msmall-mstack-check
-Muser-registers

M88K Options
-M88000-m88100-m88110-mbig-pic
-Mcheck-zero-division-mhandle-large-shift
-Midentify-revision-mno-check-zero-division
-Mno-ocs-debug-info-mno-ocs-frame-position
-Mno-optimize-arg-area-mno-serialize-volatile
-Mno-underscores-mocs-debug-info
-Mocs-frame-position-moptimize-arg-area
-Mserialize-volatile-mshort-data-num-msvr3-msvr4
-Mtrap-large-shift-muse-div-instruction
-Mversion-03.00-mwarn-passed-structs

RS6000 Options
-Mfp-in-toc-mno-fop-in-toc

RT Options
-Mcall-lib-mul-mfp-arg-in-fpregs-mfp-arg-in-gregs
-Mfull-fp-blocks-mhc-struct-return-min-line-mul
-Mminimum-fp-blocks-mnohc-struct-return

MIPS Options
-Mcpu = cpu type-mips2-mips3-mint64-mlong64
-Mlonglong128-mmips-as-mgas-mrnames-mno-rnames
-Mgpopt-mno-gpopt-mstats-mno-stats-mmemcpy
-Mno-memcpy-mno-mips-tfile-mmips-tfile
-Msoft-float-mhard-float-mabicils-mno-abicils
-Mhalf-pic-mno-half-pic-G num-nocpp

I386 Options
-Mbench-mno-486-msoft-float-mno-fp-ret-in-387

HPPA Options
-Mpa-risc-1-0-mpa-risc-1-1-mkernel-mshared-libs
-Mno-shared-libs-mlong-CILS-mdisable-fpregs
-Mdisable-indexing-mtrailing-colon

I960 Options
-Mcpu-type-mnumerics-msoft-float
-Mleaf-procedures-mno-leaf-procedures-mtail-call
-Mno-tail-call-mcomplex-addr-mno-complex-addr
-Mcode-align-mno-code-align-mic-compat
-Mic2.0-compat-mic3.0-compat-masm-compat
-Mintel-asm-mstrict-align-mno-strict-align
-Mold-align-mno-old-align

DEC Alpha Options
-Mfp-regs-mno-fp-regs-mno-soft-float-msoft-float

System V Options
-G-Qy-Qn-YP, paths-Ym, dir

Code Generation Options
-Fcall-saved-reg-fcall-used-reg-ffixed-reg
-Finhibit-size-directive-fnonnull-objects
-Fno-common-fno-ident-fno-gnu-linker
-Fpcc-struct-return-fpic-fPIC
-Freg-struct-returno-fshared-data-fshort-enums
-Fshort-double-fvolatile-global
-Fverbose-asm

PRAGMAS
Two '# pragma' ctictives are supported for gnu c ++,
Permit using the same header file for two purposes: as
Definition of interfaces to a given object class, and
The full definition of the contents of that object class.

# Pragma interface
(C ++ only.) Use this directive in header files
That define object classes, to save space in most
Of the object files that use those classes. Nor-
Mally, local copies of certain information (backup
Copies of inline member functions, debugging infor-
Mation, and the internal tables that implement vir-
Tual functions) must be kept in each object file
That includes des class definitions. You can use this
Pragma to avoid such duplication. When a header
File ining '# pragma interface' is supported in
A compilation, this auxiliary information will not
Be generated (unless the main input source file it-
Self uses '# pragma implementation'). Instead,
Object files will contain in references to be resolved
At link time.

# Pragma implementation

# Pragma implementation "objects. h"
(C ++ only.) Use this pragma in a main input file,
When you want full output from included header
Files to be generated (and made globally visible ).
The encoded header file, in turn, shocould use
'# Pragma interface'. Backup copies of inline mem-
Ber functions, debugging information, and the in-
Ternal tables used to implement virtual functions
Are all generated in implementation files.

If you use '# pragma implementation' with no argu-
Ment, it applies to an include file with the same
Basename as your source file; for example, in
'Allclass. CC', '# pragma implementation' by itself
Is equivalent to '# pragma implementation
"Allclass. h" '. Use the string argument if you want
A single implementation file to include code from
Multiple header files.

There is no way to split up the contents of a sin-
Gle header file into multiple implementation files.

File description
File. c C source file
File. h C header (preprocessor) file
File. I pre-processed C source file
File. C ++ source file
File. cc C ++ source file
File. cxx C ++ source file
File. m Objective-C source file
File. s assembly language file
File. o object file
A. out link edited output
TMPDIR/cc * temporary files
LIBDIR/cpp preprocessor
LIBDIR/PC3 compiler for C
LIBDIR/cc1plus compiler for C ++
LIBDIR/collect linker front end needed on some machines
LIBDIR/libgcc. a GCC subroutine library
/Lib/crt [01n]. o start-up routine
LIBDIR/ccrt0 additional start-up routine for C ++
/Lib/libc. a standard C library, see man page intro (3)
/Usr/include standard directory for # include files
LIBDIR/include standard gcc directory for # include files
LIBDIR/g ++-include additional g ++ directory for # include

LIBDIR is usually/usr/local/lib/machine/version.
TMPDIR comes from the environment variable TMPDIR (default
/Usr/tmp if available, else/tmp ).

Gcc best compilation Parameters

This article focuses on the parameters specified for GCC in different hardware environments for optimal performance. This article is separated from a programming instruction manual named Gentoo Linux, which is helpful for compiling programs.

--------------------------------------------------------------------------------
I. version 1.2 (gcc 2.9.x)
I386 (Intel), do you really want to install gentoo on that? CHOST = "i386-pc-linux-gnu" CFLAGS = "-march = i386-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = i386-O3-pipe-fomit-frame-pointer"
Isung (Intel), do you really want to install gentoo on that? CHOST = "i486-pc-linux-gnu" CFLAGS = "-march = isung-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = isung-O3-pipe-fomit-frame-pointer"
Pentium, Pentium MMX +, celeon (Mendocino) (Intel) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = pentium-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium-O3-pipe-fomit-frame-pointer"
Pentium Pro/II/III/4, celon (Coppermine), celon (Willamette ?) (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = i686-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = i686-O3-pipe-fomit-frame-pointer"
Eden C3/Ezra () CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = i586-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = i586-O3-pipe-fomit-frame-pointer"
Quote: I did the original gentoo install using 1.2, with gcc 2.95 using-march = i586. i686 won't work.
K6 or beyond (AMD) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = k6-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = k6-O3-pipe-fomit-frame-pointer"
(A Duron will report "Athlon" in its/proc/cpuinfo)
Athlon (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = k6-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = k6-O3-pipe-fomit-frame-pointer"
For the following, I don't know of any flag that enhance has ces..., do you?
PowerPC CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-O3-pipe-fomit-frame-pointer"
Iscsi CHOST = "iSCSI-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-O3-pipe-fomit-frame-pointer"
64 CHOST = "sparc64-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-O3-pipe-fomit-frame-pointer"

Ii. Version 1.4 (gcc 3.x ):
I386 (Intel), do you really want to install gentoo on that? CHOST = "i386-pc-linux-gnu" CFLAGS = "-march = i386-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = i386-O3-pipe-fomit-frame-pointer"
Isung (Intel), do you really want to install gentoo on that? CHOST = "i486-pc-linux-gnu" CFLAGS = "-march = isung-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = isung-O3-pipe-fomit-frame-pointer"
Pentium 1 (Intel) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = pentium-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium-O3-pipe-fomit-frame-pointer"
Pentium MMX (Intel) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = pentium-mmx-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium-mmx-O3-pipe-fomit -frame-pointer"
Pentium PRO (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentiumpro-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentiumpro-O3-pipe-fomit-frame-pointer"
Pentium II (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentium2-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium2-O3-pipe-fomit-frame-pointer"
Celon (Mendocino), aka Celeron1 (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentium2-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium2-O3-pipe-fomit-frame-pointer"
Pentium III (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentium3-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium3-O3-pipe-fomit-frame-pointer"
Celon (Coppermine) aka Celeron2 (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentium3-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium3-O3-pipe-fomit-frame-pointer"
Celon (Willamette ?) (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentium4-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium4-O3-pipe-fomit-frame-pointer"
Pentium 4 (Intel) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = pentium4-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = pentium4-O3-pipe-fomit-frame-pointer"
Eden C3/Ezra () CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = i586-m3dnow-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = i586-m3dnow-O3-pipe-fomit -frame-pointer"
Quote: the ezra doesn't have any special instructions that you cocould optimize for, just consider is a K6-3... basically a p2 with 3 dnow
K6 (AMD) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = k6-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = k6-O3-pipe-fomit-frame-pointer"
AMD (K6-2) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = k6-2-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = k6-2-O3-pipe-fomit-frame-pointer"
AMD (K6-3) CHOST = "i586-pc-linux-gnu" CFLAGS = "-march = k6-3-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = k6-3-O3-pipe-fomit-frame-pointer"
Athlon (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = athlon-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = athlon-O3-pipe-fomit-frame-pointer"
Athlon-tbird, aka K7 (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = athlon-tbird-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = athlon-tbird-O3-pipe-fomit -frame-pointer"
Athlon-tbird XP (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = athlon-xp-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = athlon-xp-O3-pipe-fomit -frame-pointer"
Athlon 4 (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = athlon-4-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = athlon-4-O3-pipe-fomit-frame-pointer"
Athlon XP (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = athlon-xp-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = athlon-xp-O3-pipe-fomit -frame-pointer"
Athlon MP (AMD) CHOST = "i686-pc-linux-gnu" CFLAGS = "-march = athlon-mp-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-march = athlon-mp-O3-pipe-fomit -frame-pointer"
603 (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer-fsigned-char" CXXFLAGS = "-O3-pipe-fomit-frame -pointer-fsigned-char"
603e (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer-fsigned-char" CXXFLAGS = "-O3-pipe-fomit-frame -pointer-fsigned-char"
604 (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer-fsigned-char" CXXFLAGS = "-O3-pipe-fomit-frame -pointer-fsigned-char"
604e (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer-fsigned-char" CXXFLAGS = "-O3-pipe-fomit-frame -pointer-fsigned-char"
750 aka as G3 (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-mcpu = 750-O3-pipe-fomit-frame-pointer-fsigned-char" CXXFLAGS = "-mcpu = 750 -O3-pipe-fomit-frame-pointer-fsigned-char"
Note: do not use-march =
7400, aka G4 (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-mcpu = 7400-O3-pipe-fomit-frame-pointer-fsigned-char-maltivec" CXXFLAGS = "-mcpu = 7400-O3-pipe-fomit-frame-pointer-fsigned-char-maltivec"
Note: do not use-march =
7450, aka G4 second generation (PowerPC) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-mcpu = 7450-O3-pipe-fomit-frame-pointer-fsigned-char-maltivec" CXXFLAGS = "-mcpu = 7450-O3-pipe-fomit-frame-pointer-fsigned-char-maltivec"
Note: do not use-march =
PowerPC (If you don't know which one) CHOST = "powerpc-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer-fsigned-char" CXXFLAGS = "-O3-pipe-fomit-frame -pointer-fsigned-char"
Iscsi CHOST = "iSCSI-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-O3-pipe-fomit-frame-pointer"
64 CHOST = "sparc64-unknown-linux-gnu" CFLAGS = "-O3-pipe-fomit-frame-pointer" CXXFLAGS = "-O3-pipe-fomit-frame-pointer" GCC user guide for GCC use guide GCC User Guide
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.