Sigrid Solveig Haflínudóttirget rid of trailing whitespacebbe192110 months agoHistory
1470 lines · 40.8 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 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.@ignoreBecause multiple C files are specified, @option{--} are necessary to clearlyseparate 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 inplace 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 -isystem dirSpecify a system include path to be added to the defaults. @item -nostdincDo not search the default system include paths; only search include pathsprovided on the command line. @item -include fileInclude @option{file} above each input file. @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). @item -PDo not output @code{#line} directives. @item -P1Output alternative @code{#line} directives. @item -dD, -dMOutput @code{#define} directives. @item -Wp,-optSame as @option{-opt}. @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 @item -freverse-funcargsEvaluate function arguments right to left. @item -fgnu89-inline@code{extern inline} is like @code{static inline}. @item -fasynchronous-unwind-tablesCreate eh_frame section [on] @item -ftest-coverageCreate code coverage code. After running the resulting code an executable.tcovor sofile.tcov file is generated with code coverage. @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 (missing prototype). @item -Wdiscarded-qualifiersWarn when const is dropped. @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 a warning is issued. Can be given an option to enablethe specified warning and turn it into an error, for example@option{-Werror=unsupported}. @item -WallActivate some useful warnings (@option{-Wimplicit-function-declaration},@option{-Wdiscard-qualifiers}). @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 -nostdlibDon't implicitly link with libc, the C runtime files, and libtcc1. @item -Wl,-nostdlibDon't search the default paths for libraries (@file{/usr/local/lib},@file{/usr/lib} and @file{/lib}). Only the paths specified with @option{-L}and @env{LIBRARY_PATH} are searched. @item -Wl,-rpath=pathPut custom search path for dynamic libraries into executable. @item -Wl,-Ipath@item -Wl,--dynamic-linker=pathSet the ELF interpreter (dynamic linker). This defaults to the value of theenvironment variable @env{LD_SO} if set, or a compiled-in default. @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,-(no-|disable-)[dynamicbase | nxcompat | high-entropy-va | tsaware]Set or clear PE (Windows) executable header hardening flags.  The@option{-Wl,-high-entropy-va} option is supported on x86-64 and ARM64 PEtargets and implies @option{-Wl,-dynamicbase}.  Clearing dynamicbase alsoclears high-entropy-va.  When @option{-Wl,-dynamicbase} is used for anexecutable, TCC also enables base relocation emission for Windows ASLR. @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 stab 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 -gdwarf[-x]Generate run time dwarf debug information instead of stab debug information. @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}.When activated, @code{__TCC_BACKTRACE__} is defined. With executables, additional support for stack traces is included. A function    @code{ int tcc_backtrace(const char *fmt, ...); }is provided to trigger a stack trace with a message on demand. @end table Misc options: @table @option @item -std=versionDefine @code{__STDC_VERSION__}: @code{201112} if @option{version} is c11 orgnu11; @code{199901} otherwise. @item -x[c|a|b|n]Specify content of next input file: respectively C, assembly, binary, or none. @item -O[n]Same as @option{-D__OPTIMIZE__} except for -O0. @item -pthreadPreprocess with @option{-D_REENTRANT}, link with @option{-lpthread}. @item -MJust output makefile fragment with dependencies @item -MMLike -M except mention only user header files, not system header files. @item -MDGenerate makefile fragment with dependencies. @item -MMDLike -MD except mention only user header files, not system header files. @item -MF depfileUse @file{depfile} as output for -MD. @item -MPMention all dependencies as targets too. @item -print-search-dirsPrint the configured installation directory and a list of libraryand include directories tcc will search. @item -dumpversionPrint version. @item -dtWith @option{-run}/@option{-E}: auto-define 'test_...' macros @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{-fx} and @option{-mx} are ignored.@c man end @c man begin ENVIRONMENTEnvironment variables that affect how tcc operates. 

Lines 1–500 of 1470.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t