⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcc-doc.texi

📁 Tiny C&C++,看看吧,也许用的着
💻 TEXI
📖 第 1 页 / 共 3 页
字号:
@noindentis the same as writing @example          double d = 4771840.0;@end example@item @code{inline} keyword is ignored.@item @code{restrict} keyword is ignored.@end itemize@section GNU C extensionsTCC implements some GNU C extensions:@itemize@item array designators can be used without '=': @example    int a[10] = @{ [0] 1, [5] 2, 3, 4 @};@end example@item Structure field designators can be a label: @example    struct @{ int x, y; @} st = @{ x: 1, y: 1@};@end exampleinstead of@example    struct @{ int x, y; @} st = @{ .x = 1, .y = 1@};@end example@item @code{\e} is ASCII character 27.@item case ranges : ranges can be used in @code{case}s:@example    switch(a) @{    case 1 @dots{} 9:          printf("range 1 to 9\n");          break;    default:          printf("unexpected\n");          break;    @}@end example@item The keyword @code{__attribute__} is handled to specify variable orfunction attributes. The following attributes are supported:  @itemize  @item @code{aligned(n)}: align data to n bytes (must be a power of two).  @item @code{section(name)}: generate function or data in assembly  section name (name is a string containing the section name) instead  of the default section.  @item @code{unused}: specify that the variable or the function is unused.  @item @code{cdecl}: use standard C calling convention.  @item @code{stdcall}: use Pascal-like calling convention.  @end itemizeHere are some examples:@example    int a __attribute__ ((aligned(8), section(".mysection")));@end example@noindentalign variable @code{a} to 8 bytes and put it in section @code{.mysection}.@example    int my_add(int a, int b) __attribute__ ((section(".mycodesection")))     @{        return a + b;    @}@end example@noindentgenerate function @code{my_add} in section @code{.mycodesection}.@item GNU style variadic macros:@example    #define dprintf(fmt, args@dots{}) printf(fmt, ## args)    dprintf("no arg\n");    dprintf("one arg %d\n", 1);@end example@item @code{__FUNCTION__} is interpreted as C99 @code{__func__} (so it has not exactly the same semantics as string literal GNUCwhere it is a string literal).@item The @code{__alignof__} keyword can be used as @code{sizeof} to get the alignment of a type or an expression.@item The @code{typeof(x)} returns the type of @code{x}. @code{x} is an expression or a type.@item Computed gotos: @code{&&label} returns a pointer of type @code{void *} on the goto label @code{label}. @code{goto *expr} can beused to jump on the pointer resulting from @code{expr}.@item Inline assembly with asm instruction:@cindex inline assembly@cindex assembly, inline@cindex __asm__@examplestatic inline void * my_memcpy(void * to, const void * from, size_t n)@{int d0, d1, d2;__asm__ __volatile__(        "rep ; movsl\n\t"        "testb $2,%b4\n\t"        "je 1f\n\t"        "movsw\n"        "1:\ttestb $1,%b4\n\t"        "je 2f\n\t"        "movsb\n"        "2:"        : "=&c" (d0), "=&D" (d1), "=&S" (d2)        :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)        : "memory");return (to);@}@end example@noindent@cindex gasTCC includes its own x86 inline assembler with a @code{gas}-like (GNUassembler) syntax. No intermediate files are generated. GCC 3.x namedoperands are supported.@item @code{__builtin_types_compatible_p()} and @code{__builtin_constant_p()} are supported.@end itemize@section TinyCC extensions@itemize@item @code{__TINYC__} is a predefined macro to @code{1} toindicate that you use TCC.@item @code{#!} at the start of a line is ignored to allow scripting.@item Binary digits can be entered (@code{0b101} instead of@code{5}).@item @code{__BOUNDS_CHECKING_ON} is defined if bound checking is activated.@end itemize@chapter TinyCC AssemblerSince version 0.9.16, TinyCC integrates its own assembler. TinyCCassembler supports a gas-like syntax (GNU assembler). You candesactivate assembler support if you want a smaller TinyCC executable(the C compiler does not rely on the assembler).TinyCC Assembler is used to handle files with @file{.S} (Cpreprocessed assembler) and @file{.s} extensions. It is also used tohandle the GNU inline assembler with the @code{asm} keyword.@section SyntaxTinyCC Assembler supports most of the gas syntax. The tokens are thesame as C.@itemize@item C and C++ comments are supported.@item Identifiers are the same as C, so you cannot use '.' or '$'.@item Only 32 bit integer numbers are supported.@end itemize@section Expressions@itemize@item Integers in decimal, octal and hexa are supported.@item Unary operators: +, -, ~.@item Binary operators in decreasing priority order:@enumerate@item *, /, %@item &, |, ^@item +, -@end enumerate@item A value is either an absolute number or a label plus an offset. All operators accept absolute values except '+' and '-'. '+' or '-' can beused to add an offset to a label. '-' supports two labels only if theyare the same or if they are both defined and in the same section.@end itemize@section Labels@itemize@item All labels are considered as local, except undefined ones.@item Numeric labels can be used as local @code{gas}-like labels. They can be defined several times in the same source. Use 'b'(backward) or 'f' (forward) as suffix to reference them:@example 1:      jmp 1b /* jump to '1' label before */      jmp 1f /* jump to '1' label after */ 1:@end example@end itemize@section Directives@cindex assembler directives@cindex directives, assembler@cindex .align@cindex .skip@cindex .space@cindex .byte@cindex .word@cindex .short@cindex .int@cindex .long@cindex .string@cindex .globl@cindex .global@cindex .section@cindex .text@cindex .data@cindex .bssAll directives are preceeded by a '.'. The following directives aresupported:@itemize@item .align n[,value]@item .skip n[,value]@item .space n[,value]@item .byte value1[,value2...]@item .word value1[,value2...]@item .short value1[,value2...]@item .int value1[,value2...]@item .long value1[,value2...]@item .string string@item .globl symbol@item .global symbol@item .section section@item .text@item .data@item .bss@item .fill repeat[,size[,value]]@item .org n@item .previous@item .string string[,...]@item .asciz string[,...]@item .ascii string[,...]@end itemize@section X86 Assembler@cindex assemblerAll X86 opcodes are supported. Only ATT syntax is supported (sourcethen destination operand order). If no size suffix is given, TinyCCtries to guess it from the operand sizes.Currently, MMX opcodes are supported but not SSE ones.@chapter TinyCC Linker@cindex linker@section ELF file generation@cindex ELFTCC can directly output relocatable ELF files (object files),executable ELF files and dynamic ELF libraries without relying on anexternal linker.Dynamic ELF libraries can be output but the C compiler does not generateposition independent code (PIC). It means that the dynamic librarycode generated by TCC cannot be factorized among processes yet.TCC linker eliminates unreferenced object code in libraries. A single pass isdone on the object and library list, so the order in which object files andlibraries are specified is important (same constraint as GNU ld). No groupingoptions (@option{--start-group} and @option{--end-group}) are supported.@section ELF file loaderTCC can load ELF object files, archives (.a files) and dynamiclibraries (.so).@section GNU Linker Scripts@cindex scripts, linker@cindex linker scripts@cindex GROUP, linker command@cindex FILE, linker command@cindex OUTPUT_FORMAT, linker command@cindex TARGET, linker commandBecause on many Linux systems some dynamic libraries (such as@file{/usr/lib/libc.so}) are in fact GNU ld link scripts (horrible!),the TCC linker also supports a subset of GNU ld scripts.The @code{GROUP} and @code{FILE} commands are supported. @code{OUTPUT_FORMAT}and @code{TARGET} are ignored.Example from @file{/usr/lib/libc.so}:@example/* GNU ld script   Use the shared library, but some functions are only in   the static library, so try that secondarily.  */GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )@end example@node Bounds@chapter TinyCC Memory and Bound checks@cindex bound checks@cindex memory checksThis feature is activated with the @option{-b} (@pxref{Invoke}).Note that pointer size is @emph{unchanged} and that code generatedwith bound checks is @emph{fully compatible} with uncheckedcode. When a pointer comes from unchecked code, it is assumed to bevalid. Even very obscure C code with casts should work correctly.For more information about the ideas behind this method, see@url{http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html}.Here are some examples of caught errors:@table @asis@item Invalid range with standard string function:@example@{    char tab[10];    memset(tab, 0, 11);@}@end example@item Out of bounds-error in global or local arrays:@example@{    int tab[10];    for(i=0;i<11;i++) @{        sum += tab[i];    @}@}@end example@item Out of bounds-error in malloc'ed data:@example@{    int *tab;    tab = malloc(20 * sizeof(int));    for(i=0;i<21;i++) @{        sum += tab4[i];    @}    free(tab);@}@end example@item Access of freed memory:@example@{    int *tab;    tab = malloc(20 * sizeof(int));    free(tab);    for(i=0;i<20;i++) @{        sum += tab4[i];    @}@}@end example@item Double free:@example@{    int *tab;    tab = malloc(20 * sizeof(int));    free(tab);    free(tab);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -