Using and Porting the GNU Compiler Collection
Total Page:16
File Type:pdf, Size:1020Kb
Using and Porting the GNU Compiler Collection Richard M. Stallman Last updated 28 July 1999 for gcc-2.95 Copyright c 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1998, 1999 Free Software Foundation, Inc. For GCC Version 2.95 Published by the Free Software Foundation 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA Last printed April, 1998. Printed copies are available for $50 each. ISBN 1-882114-37-X Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the sections entitled \GNU General Public License" and \Funding for Free Software" are included exactly as in the original, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another lan- guage, under the above conditions for modified versions, except that the sections entitled \GNU General Public License" and \Funding for Free Software", and this permission no- tice, may be included in translations approved by the Free Software Foundation instead of in the original English. Chapter 1: Compile C, C++, Objective C, or Fortran 1 1 Compile C, C++, Objective C, or Fortran The C, C++, and Objective C, and Fortran versions of the compiler are integrated; this is why we use the name \GNU Compiler Collection". GCC can compile programs written in C, C++, Objective C, or Fortran. The Fortran compiler is described in a separate manual. \GCC" is a common shorthand term for the GNU Compiler Collection. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs (as the abbreviation formerly stood for \GNU C Compiler"). When referring to C++ compilation, it is usual to call the compiler \G++". Since there is only one compiler, it is also accurate to call it \GCC" no matter what the language context; however, the term \G++" is more useful when the emphasis is on compiling C++ programs. We use the name \GCC" to refer to the compilation system as a whole, and more specifically to the language-independent part of the compiler. For example, we refer to the optimization options as affecting the behavior of \GCC" or sometimes just \the compiler". Front ends for other languages, such as Ada 9X, Fortran, Modula-3, and Pascal, are under development. These front-ends, like that for C++, are built in subdirectories of GCC and link to it. The result is an integrated compiler that can compile programs written in C, C++, Objective C, or any of the languages for which you have installed front ends. In this manual, we only discuss the options for the C, Objective-C, and C++ compilers and those of the GCC core. Consult the documentation of the other front ends for the options to use when compiling programs written in other languages. G++ is a compiler, not merely a preprocessor. G++ builds object code directly from your C++ program source. There is no intermediate C version of the program. (By contrast, for example, some other implementations use a program that generates a C program from your C++ source.) Avoiding an intermediate C representation of the program means that you get better object code, and better debugging information. The GNU debugger, GDB, works with this information in the object code to give you comprehensive C++ source-level editing capabilities (see section \C and C++" in Debugging with GDB). 2 Using and Porting the GNU Compiler Collection (GCC) Chapter 2: GCC Command Options 3 2 GCC Command Options When you invoke GCC, it normally does preprocessing, compilation, assembly and link- ing. The \overall options" allow you to stop this process at an intermediate stage. For example, the `-c' option says not to run the linker. Then the output consists of object files output by the assembler. Other options are passed on to one stage of processing. Some options control the pre- processor and others the compiler itself. Yet other options control the assembler and linker; most of these are not documented here, since you rarely need to use any of them. Most of the command line options that you can use with GCC are useful for C programs; when an option is only useful with another language (usually C++), the explanation says so explicitly. If the description for a particular option does not mention a source language, you can use that option with all supported languages. See Section 2.3 [Compiling C++ Programs], page 11, for a summary of special options for compiling C++ programs. The gcc program accepts options and file names as operands. Many options have mul- tiletter names; therefore multiple single-letter options may not be grouped: `-dr' is very different from `-d -r'. You can mix options and other arguments. For the most part, the order you use doesn't matter. Order does matter when you use several options of the same kind; for example, if you specify `-L' more than once, the directories are searched in the order specified. Many options have long names starting with `-f' or with `-W'|for example, `-fforce-mem', `-fstrength-reduce', `-Wformat' and so on. Most of these have both positive and negative forms; the negative form of `-ffoo' would be `-fno-foo'. This manual documents only one of these two forms, whichever one is not the default. 2.1 Option Summary Here is a summary of all the options, grouped by type. Explanations are in the following sections. Overall Options See Section 2.2 [Options Controlling the Kind of Output], page 10. -c -S -E -o file -pipe -v --help -x language C Language Options See Section 2.4 [Options Controlling C Dialect], page 12. -ansi -fstd -fallow-single-precision -fcond-mismatch -fno-asm -fno-builtin -ffreestanding -fhosted -fsigned-bitfields -fsigned-char -funsigned-bitfields -funsigned-char -fwritable-strings -traditional -traditional-cpp -trigraphs C++ Language Options See Section 2.5 [Options Controlling C++ Dialect], page 16. -fno-access-control -fcheck-new -fconserve-space -fdollars-in-identifiers -fno-elide-constructors -fexternal-templates -ffor-scope -fno-for-scope -fno-gnu-keywords -fguiding-decls -fhandle-signatures 4 Using and Porting the GNU Compiler Collection (GCC) -fhonor-std -fhuge-objects -fno-implicit-templates -finit-priority -fno-implement-inlines -fname-mangling-version-n -fno-default-inline -foperator-names -fno-optional-diags -fpermissive -frepo -fstrict-prototype -fsquangle -ftemplate-depth-n -fthis-is-variable -fvtable-thunks -nostdinc++ -Wctor-dtor-privacy -Wno-deprecated -Weffc++ -Wno-non-template-friend -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wno-pmf-conversions -Wreorder -Wsign-promo -Wsynth Warning Options See Section 2.6 [Options to Request or Suppress Warnings], page 22. -fsyntax-only -pedantic -pedantic-errors -w -W -Wall -Waggregate-return -Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Werror -Wformat -Wid-clash-len -Wimplicit -Wimplicit-int -Wimplicit-function-declaration -Wimport -Werror-implicit-function-declaration -Winline -Wlarger-than-len -Wlong-long -Wmain -Wmissing-declarations -Wmissing-noreturn -Wmissing-prototypes -Wmultichar -Wnested-externs -Wno-import -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare -Wstrict-prototypes -Wswitch -Wtraditional -Wtrigraphs -Wundef -Wuninitialized -Wunused -Wwrite-strings -Wunknown-pragmas Debugging Options See Section 2.7 [Options for Debugging Your Program or GCC], page 29. -a -ax -dletters -fdump-unnumbered -fpretend-float -fprofile-arcs -ftest-coverage -g -glevel -gcoff -gdwarf -gdwarf-1 -gdwarf-1+ -gdwarf-2 -ggdb -gstabs -gstabs+ -gxcoff -gxcoff+ -p -pg -print-file-name=library -print-libgcc-file-name -print-prog-name=program -print-search-dirs -save-temps Optimization Options See Section 2.8 [Options that Control Optimization], page 35. -fbranch-probabilities -foptimize-register-moves -fcaller-saves -fcse-follow-jumps -fcse-skip-blocks -fdelayed-branch -fexpensive-optimizations -ffast-math -ffloat-store -fforce-addr -fforce-mem -fdata-sections -ffunction-sections -fgcse -finline-functions -finline-limit-n -fkeep-inline-functions -fno-default-inline -fno-defer-pop -fno-function-cse -fno-inline -fno-peephole -fomit-frame-pointer -fregmove -frerun-cse-after-loop -frerun-loop-opt -fschedule-insns -fschedule-insns2 -fstrength-reduce -fthread-jumps -funroll-all-loops -funroll-loops -fmove-all-movables -freduce-all-givs -fstrict-aliasing Chapter 2: GCC Command Options 5 -O -O0 -O1 -O2 -O3 -Os Preprocessor Options See Section 2.9 [Options Controlling the Preprocessor], page 41. -Aquestion(answer) -C -dD -dM -dN -Dmacro[=defn] -E -H -idirafter dir -include file -imacros file -iprefix file -iwithprefix dir -iwithprefixbefore dir -isystem dir -isystem-c++ dir -M -MD -MM -MMD -MG -nostdinc -P -trigraphs -undef -Umacro -Wp,option Assembler Option See Section 2.10 [Passing Options to the Assembler], page 44. -Wa,option Linker Options See Section 2.11 [Options for Linking], page 44. object-file-name -llibrary -nostartfiles -nodefaultlibs -nostdlib -s -static -shared -symbolic -Wl,option -Xlinker option -u symbol Directory Options See Section 2.12 [Options for Directory Search], page 46. -Bprefix -Idir -I- -Ldir -specs=file Target Options See Section 2.13 [Target Options], page 47. -b machine -V version Machine Dependent Options See Section 2.14 [Hardware Models