1378 lines · 38.1 KB · Text
RawDownload
\input texinfo @c -*- texinfo -*-@c %**start of header@setfilename tcc-doc.info@settitle Tiny C Compiler Reference Documentation@dircategory Software development@direntry* TCC: (tcc-doc).               The Tiny C Compiler.@end direntry@c %**end of header @include config.texi @iftex@titlepage@afourpaper@sp 7@center @titlefont{Tiny C Compiler Reference Documentation}@sp 3@end titlepage@headings double@end iftex @contents @node Top, Introduction, (dir), (dir)@top Tiny C Compiler Reference Documentation This manual documents version @value{VERSION} of the Tiny C Compiler. @menu* Introduction::                Introduction to tcc.* Invoke::                      Invocation of tcc (command line, options).* Clang::                       ANSI C and extensions.* asm::                         Assembler syntax.* linker::                      Output file generation and supported targets.* Bounds::                      Automatic bounds-checking of C code.* Libtcc::                      The libtcc library.* devel::                       Guide for Developers.@end menu  @node Introduction@chapter Introduction TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other Ccompilers, it is meant to be self-relying: you do not need anexternal assembler or linker because TCC does that for you. TCC compiles so @emph{fast} that even for big projects @code{Makefile}s maynot be necessary. TCC not only supports ANSI C, but also most of the new ISO C99standard and many GNUC extensions including inline assembly. TCC can also be used to make @emph{C scripts}, i.e. pieces of C sourcethat you run as a Perl or Python script. Compilation is so fast thatyour script will be as fast as if it was an executable. TCC can also automatically generate memory and bound checks(@pxref{Bounds}) while allowing all C pointers operations. TCC can dothese checks even if non patched libraries are used. With @code{libtcc}, you can use TCC as a backend for dynamic codegeneration (@pxref{Libtcc}). TCC mainly supports the i386 target on Linux and Windows. There are alphaports for the ARM (@code{arm-tcc}) and the TMS320C67xx targets(@code{c67-tcc}). More information about the ARM port is available at@url{http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html}. For usage on Windows, see also @url{tcc-win32.txt}. @node Invoke@chapter Command line invocation @section Quick start @example@c man begin SYNOPSISusage: tcc [options] [@var{infile1} @var{infile2}@dots{}] [@option{-run} @var{infile} @var{args}@dots{}]@c man end@end example @noindent@c man begin DESCRIPTIONTCC options are a very much like gcc options. The main difference is that TCCcan also execute directly the resulting program and give it runtimearguments. Here are some examples to understand the logic: @table @code@item @samp{tcc -run a.c}Compile @file{a.c} and execute it directly @item @samp{tcc -run a.c arg1}Compile a.c and execute it directly. arg1 is given as first argument tothe @code{main()} of a.c. @item @samp{tcc a.c -run b.c arg1}Compile @file{a.c} and @file{b.c}, link them together and execute them. arg1 is givenas first argument to the @code{main()} of the resulting program. @ignore Because multiple C files are specified, @option{--} are necessary to clearly separate the program arguments from the TCC options.@end ignore @item @samp{tcc -o myprog a.c b.c}Compile @file{a.c} and @file{b.c}, link them and generate the executable @file{myprog}. @item @samp{tcc -o myprog a.o b.o}link @file{a.o} and @file{b.o} together and generate the executable @file{myprog}. @item @samp{tcc -c a.c}Compile @file{a.c} and generate object file @file{a.o}. @item @samp{tcc -c asmfile.S}Preprocess with C preprocess and assemble @file{asmfile.S} and generateobject file @file{asmfile.o}. @item @samp{tcc -c asmfile.s}Assemble (but not preprocess) @file{asmfile.s} and generate object file@file{asmfile.o}. @item @samp{tcc -r -o ab.o a.c b.c}Compile @file{a.c} and @file{b.c}, link them together and generate the object file @file{ab.o}. @end table Scripting: TCC can be invoked from @emph{scripts}, just as shell scripts. You justneed to add @code{#!/usr/local/bin/tcc -run} at the start of your C source: @example#!/usr/local/bin/tcc -run#include <stdio.h> int main() @{    printf("Hello World\n");    return 0;@}@end example TCC can read C source code from @emph{standard input} when @option{-} is used in place of @option{infile}. Example: @exampleecho 'main()@{puts("hello");@}' | tcc -run -@end example@c man end @section Option summary General Options: @c man begin OPTIONS@table @option@item -cGenerate an object file. @item -o outfilePut object file, executable, or dll into output file @file{outfile}. @item -run source [args...]Compile file @var{source} and run it with the command line arguments@var{args}. In order to be able to give more than one argument to ascript, several TCC options can be given @emph{after} the@option{-run} option, separated by spaces:@exampletcc "-run -L/usr/X11R6/lib -lX11" ex4.c@end exampleIn a script, it gives the following header:@example#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11@end example @item -vDisplay TCC version. @item -vvShow included files.  As sole argument, print search dirs.  -vvv shows tries too. @item -benchDisplay compilation statistics. @end table Preprocessor options: @table @option@item -IdirSpecify an additional include path. Include paths are searched in theorder they are specified. System include paths are always searched after. The default systeminclude paths are: @file{/usr/local/include}, @file{/usr/include}and @file{PREFIX/lib/tcc/include}. (@file{PREFIX} is usually@file{/usr} or @file{/usr/local}). @item -Dsym[=val]Define preprocessor symbol @samp{sym} toval. If val is not present, its value is @samp{1}. Function-like macros canalso be defined: @option{-DF(a)=a+1} @item -UsymUndefine preprocessor symbol @samp{sym}. @item -EPreprocess only, to stdout or file (with -o). @end table Compilation flags: Note: each of the following options has a negative form beginning with@option{-fno-}. @table @option@item -funsigned-charLet the @code{char} type be unsigned. @item -fsigned-charLet the @code{char} type be signed. @item -fno-commonDo not generate common symbols for uninitialized data. @item -fleading-underscoreAdd a leading underscore at the beginning of each C symbol. @item -fms-extensionsAllow a MS C compiler extensions to the language. Currently thisassumes a nested named structure declaration without an identifierbehaves like an unnamed one. @item -fdollars-in-identifiersAllow dollar signs in identifiers @end table Warning options: @table @option@item -wDisable all warnings. @end table Note: each of the following warning options has a negative form beginning with@option{-Wno-}. @table @option@item -Wimplicit-function-declarationWarn about implicit function declaration. @item -WunsupportedWarn about unsupported GCC features that are ignored by TCC. @item -Wwrite-stringsMake string constants be of type @code{const char *} instead of @code{char*}. @item -WerrorAbort compilation if warnings are issued. @item -Wall Activate all warnings, except @option{-Werror}, @option{-Wunusupported} and@option{-Wwrite-strings}. @end table Linker options: @table @option@item -LdirSpecify an additional static library path for the @option{-l} option. Thedefault library paths are @file{/usr/local/lib}, @file{/usr/lib} and @file{/lib}. @item -lxxxLink your program with dynamic library libxxx.so or static librarylibxxx.a. The library is searched in the paths specified by the@option{-L} option and @env{LIBRARY_PATH} variable. @item -BdirSet the path where the tcc internal libraries (and include files) can befound (default is @file{PREFIX/lib/tcc}). @item -sharedGenerate a shared library instead of an executable. @item -soname nameset name for shared library to be used at runtime @item -staticGenerate a statically linked executable (default is a shared linkedexecutable). @item -rdynamicExport global symbols to the dynamic linker. It is useful when a libraryopened with @code{dlopen()} needs to access executable symbols. @item -rGenerate an object file combining all input files. @item -Wl,-rpath=pathPut custom search path for dynamic libraries into executable. @item -Wl,--enable-new-dtagsWhen putting a custom search path for dynamic libraries into the executable,create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH. @item -Wl,--oformat=fmtUse @var{fmt} as output format. The supported output formats are:@table @code@item elf32-i386ELF output format (default)@item binaryBinary image (only for executable output)@item coffCOFF output format (only for executable output for TMS320C67xx target)@end table @item -Wl,--export-all-symbols@item -Wl,--export-dynamicExport global symbols to the dynamic linker. It is useful when a libraryopened with @code{dlopen()} needs to access executable symbols. @item -Wl,-subsystem=console/gui/wince/...Set type for PE (Windows) executables. @item -Wl,-[Ttext=# | section-alignment=# | file-alignment=# | image-base=# | stack=#]Modify executable layout. @item -Wl,-BsymbolicSet DT_SYMBOLIC tag. @item -Wl,-(no-)whole-archiveTurn on/off linking of all objects in archives. @end table Debugger options: @table @option@item -gGenerate run time debug information so that you get clear run timeerror messages: @code{ test.c:68: in function 'test5()': dereferencinginvalid pointer} instead of the laconic @code{Segmentationfault}. @item -bGenerate additional support code to check memory allocations and array/pointerbounds (@pxref{Bounds}). @option{-g} is implied. @item -bt[N]Display N callers in stack traces. This is useful with @option{-g} or @option{-b}.With executables, additional support for stack traces is included. A function @code{ int tcc_backtrace(const char *fmt, ...); } is providedto trigger a stack trace with a message on demand. @end table Misc options: @table @option@item -MDGenerate makefile fragment with dependencies. @item -MF depfileUse @file{depfile} as output for -MD. @item -print-search-dirsPrint the configured installation directory and a list of libraryand include directories tcc will search. @item -dumpversionPrint version. @end table Target specific options: @table @option@item -mms-bitfieldsUse an algorithm for bitfield alignment consistent with MSVC. Default isgcc's algorithm. @item -mfloat-abi (ARM only)Select the float ABI. Possible values: @code{softfp} and @code{hard} @item -mno-sseDo not use sse registers on x86_64 @item -m32, -m64Pass command line to the i386/x86_64 cross compiler. @end table Note: GCC options @option{-Ox}, @option{-fx} and @option{-mx} areignored.@c man end @c man begin ENVIRONMENTEnvironment variables that affect how tcc operates. @table @option @item CPATH@item C_INCLUDE_PATHA colon-separated list of directories searched for include files,directories given with @option{-I} are searched first. @item LIBRARY_PATHA colon-separated list of directories searched for libraries for the@option{-l} option, directories given with @option{-L} are searched first. @end table @c man end @ignore @setfilename tcc@settitle Tiny C Compiler @c man begin SEEALSOcpp(1),gcc(1)@c man end @c man begin AUTHORFabrice Bellard@c man end @end ignore @node Clang@chapter C language support @section ANSI C TCC implements all the ANSI C standard, including structure bit fieldsand floating point numbers (@code{long double}, @code{double}, and@code{float} fully supported). @section ISOC99 extensions TCC implements many features of the new C standard: ISO C99. Currentlymissing items are: complex and imaginary numbers. Currently implemented ISOC99 features: @itemize @item variable length arrays. @item 64 bit @code{long long} types are fully supported. @item The boolean type @code{_Bool} is supported. @item @code{__func__} is a string variable containing the currentfunction name. @item Variadic macros: @code{__VA_ARGS__} can be used for   function-like macros:@example    #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)@end example @noindent@code{dprintf} can then be used with a variable number of parameters. @item Declarations can appear anywhere in a block (as in C++). @item Array and struct/union elements can be initialized in any order by  using designators:@example    struct @{ int x, y; @} st[10] = @{ [0].x = 1, [0].y = 2 @};     int tab[10] = @{ 1, 2, [5] = 5, [9] = 9@};@end example    @item Compound initializers are supported:@example    int *p = (int [])@{ 1, 2, 3 @};@end exampleto initialize a pointer pointing to an initialized array. The sameworks for structures and strings. @item Hexadecimal floating point constants are supported:@example          double d = 0x1234p10;@end example @noindentis the same as writing @example

Lines 1–500 of 1378.