Unified · Split
| @@ -1,16 +1,48 @@ | ||
| 1 | 1 | \input texinfo @c -*- texinfo -*- |
| 2 | − | |
| 2 | +@c %**start of header | |
| 3 | +@setfilename tcc-doc.info | |
| 3 | 4 | @settitle Tiny C Compiler Reference Documentation |
| 5 | +@c %**end of header | |
| 6 | + | |
| 7 | +@include version.texi | |
| 8 | + | |
| 9 | +@ifinfo | |
| 10 | +Bla bla bla | |
| 11 | +@end ifinfo | |
| 12 | + | |
| 13 | +@iftex | |
| 4 | 14 | @titlepage |
| 15 | +@afourpaper | |
| 5 | 16 | @sp 7 |
| 6 | 17 | @center @titlefont{Tiny C Compiler Reference Documentation} |
| 7 | 18 | @sp 3 |
| 8 | 19 | @end titlepage |
| 20 | +@headings double | |
| 21 | +@end iftex | |
| 22 | + | |
| 23 | +@ifnothtml | |
| 24 | +@contents | |
| 25 | +@end ifnothtml | |
| 26 | + | |
| 27 | +@ifnottex | |
| 28 | +@node Top, Introduction, (dir), (dir) | |
| 29 | +@top Tiny C Compiler Reference Documentation | |
| 30 | + | |
| 31 | +This manual documents version @value{VERSION} of the Tiny C Compiler. | |
| 9 | 32 | |
| 33 | +@menu | |
| 34 | +* Introduction:: Introduction to tcc. | |
| 35 | +* Invoke:: Invocation of tcc (command line, options). | |
| 36 | +* Bounds:: Automatic bounds-checking of C code. | |
| 37 | +* Libtcc:: bla bla bla. | |
| 38 | +@end menu | |
| 39 | +@end ifnottex | |
| 40 | + | |
| 41 | +@node Introduction | |
| 10 | 42 | @chapter Introduction |
| 11 | 43 | |
| 12 | 44 | TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C |
| 13 | −compilers, it is meant to be self-suffisant: you do not need an | |
| 45 | +compilers, it is meant to be self-relying: you do not need an | |
| 14 | 46 | external assembler or linker because TCC does that for you. |
| 15 | 47 | |
| 16 | 48 | TCC compiles so @emph{fast} that even for big projects @code{Makefile}s may |
| @@ -24,13 +56,13 @@ that you run as a Perl or Python script. Compilation is so fast that · 7 unmodified lines | ||
| 24 | 56 | your script will be as fast as if it was an executable. |
| 25 | 57 | |
| 26 | 58 | TCC can also automatically generate memory and bound checks |
| 27 | −(@xref{bounds}) while allowing all C pointers operations. TCC can do | |
| 59 | +(@pxref{Bounds}) while allowing all C pointers operations. TCC can do | |
| 28 | 60 | these checks even if non patched libraries are used. |
| 29 | 61 | |
| 30 | 62 | With @code{libtcc}, you can use TCC as a backend for dynamic code |
| 31 | −generation (@xref{libtcc}). | |
| 63 | +generation (@pxref{Libtcc}). | |
| 32 | 64 | |
| 33 | −@node invoke | |
| 65 | +@node Invoke | |
| 34 | 66 | @chapter Command line invocation |
| 35 | 67 | |
| 36 | 68 | @section Quick start |
| @@ -41,45 +73,46 @@ usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym] · 4 unmodified lines | ||
| 41 | 73 | [--] infile1 [infile2... --] [infile_args...] |
| 42 | 74 | @end example |
| 43 | 75 | |
| 44 | −TCC options are a very much like gcc. The main difference is that TCC | |
| 76 | +@noindent | |
| 77 | +TCC options are a very much like gcc options. The main difference is that TCC | |
| 45 | 78 | can also execute directly the resulting program and give it runtime |
| 46 | 79 | arguments. |
| 47 | 80 | |
| 48 | 81 | Here are some examples to understand the logic: |
| 49 | 82 | |
| 50 | 83 | @table @code |
| 51 | −@item tcc a.c | |
| 52 | −Compile a.c and execute it directly | |
| 84 | +@item @samp{tcc a.c} | |
| 85 | +Compile @file{a.c} and execute it directly | |
| 53 | 86 | |
| 54 | −@item tcc a.c arg1 | |
| 87 | +@item @samp{tcc a.c arg1} | |
| 55 | 88 | Compile a.c and execute it directly. arg1 is given as first argument to |
| 56 | 89 | the @code{main()} of a.c. |
| 57 | 90 | |
| 58 | −@item tcc -- a.c b.c -- arg1 | |
| 59 | −Compile a.c and b.c, link them together and execute them. arg1 is given | |
| 91 | +@item @samp{tcc -- a.c b.c -- arg1} | |
| 92 | +Compile @file{a.c} and @file{b.c}, link them together and execute them. arg1 is given | |
| 60 | 93 | as first argument to the @code{main()} of the resulting program. Because |
| 61 | −multiple C files are specified, @code{--} are necessary to clearly separate the | |
| 94 | +multiple C files are specified, @option{--} are necessary to clearly separate the | |
| 62 | 95 | program arguments from the TCC options. |
| 63 | 96 | |
| 64 | −@item tcc -o myprog a.c b.c | |
| 65 | −Compile a.c and b.c, link them and generate the executable myprog. | |
| 97 | +@item @samp{tcc -o myprog a.c b.c} | |
| 98 | +Compile @file{a.c} and @file{b.c}, link them and generate the executable @file{myprog}. | |
| 66 | 99 | |
| 67 | −@item tcc -o myprog a.o b.o | |
| 68 | −link a.o and b.o together and generate the executable myprog. | |
| 100 | +@item @samp{tcc -o myprog a.o b.o} | |
| 101 | +link @file{a.o} and @file{b.o} together and generate the executable @file{myprog}. | |
| 69 | 102 | |
| 70 | −@item tcc -c a.c | |
| 71 | −Compile a.c and generate object file a.o | |
| 103 | +@item @samp{tcc -c a.c} | |
| 104 | +Compile @file{a.c} and generate object file @file{a.o}. | |
| 72 | 105 | |
| 73 | −@item tcc -c asmfile.S | |
| 74 | −Preprocess with C preprocess and assemble asmfile.S and generate | |
| 75 | −object file asmfile.o. | |
| 106 | +@item @samp{tcc -c asmfile.S} | |
| 107 | +Preprocess with C preprocess and assemble @file{asmfile.S} and generate | |
| 108 | +object file @file{asmfile.o}. | |
| 76 | 109 | |
| 77 | −@item tcc -c asmfile.s | |
| 78 | −Assemble (but not preprocess) asmfile.s and generate object file | |
| 79 | −asmfile.o. | |
| 110 | +@item @samp{tcc -c asmfile.s} | |
| 111 | +Assemble (but not preprocess) @file{asmfile.s} and generate object file | |
| 112 | +@file{asmfile.o}. | |
| 80 | 113 | |
| 81 | −@item tcc -r -o ab.o a.c b.c | |
| 82 | −Compile a.c and b.c, link them together and generate the object file ab.o. | |
| 114 | +@item @samp{tcc -r -o ab.o a.c b.c} | |
| 115 | +Compile @file{a.c} and @file{b.c}, link them together and generate the object file @file{ab.o}. | |
| 83 | 116 | |
| 84 | 117 | @end table |
| 85 | 118 | |
| @@ -93,19 +126,19 @@ need to add @code{#!/usr/local/bin/tcc} at the start of your C source: · 7 unmodified lines | ||
| 93 | 126 | #include <stdio.h> |
| 94 | 127 | |
| 95 | 128 | int main() |
| 96 | −{ | |
| 129 | +@{ | |
| 97 | 130 | printf("Hello World\n"); |
| 98 | 131 | return 0; |
| 99 | −} | |
| 132 | +@} | |
| 100 | 133 | @end example |
| 101 | 134 | |
| 102 | 135 | @section Option summary |
| 103 | 136 | |
| 104 | 137 | General Options: |
| 105 | 138 | |
| 106 | −@table @samp | |
| 139 | +@table @option | |
| 107 | 140 | @item -c |
| 108 | −Generate an object file (@samp{-o} option must also be given). | |
| 141 | +Generate an object file (@option{-o} option must also be given). | |
| 109 | 142 | |
| 110 | 143 | @item -o outfile |
| 111 | 144 | Put object file, executable, or dll into output file @file{outfile}. |
| @@ -120,54 +153,54 @@ Output compilation statistics. · 8 unmodified lines | ||
| 120 | 153 | |
| 121 | 154 | Preprocessor options: |
| 122 | 155 | |
| 123 | −@table @samp | |
| 156 | +@table @option | |
| 124 | 157 | @item -Idir |
| 125 | −Specify an additionnal include path. Include paths are searched in the | |
| 158 | +Specify an additional include path. Include paths are searched in the | |
| 126 | 159 | order they are specified. |
| 127 | 160 | |
| 128 | 161 | System include paths are always searched after. The default system |
| 129 | 162 | include paths are: @file{/usr/local/include}, @file{/usr/include} |
| 130 | −and @file{PREFIX/lib/tcc/include}. (@code{PREFIX} is usually | |
| 163 | +and @file{PREFIX/lib/tcc/include}. (@file{PREFIX} is usually | |
| 131 | 164 | @file{/usr} or @file{/usr/local}). |
| 132 | 165 | |
| 133 | 166 | @item -Dsym[=val] |
| 134 | −Define preprocessor symbol 'sym' to | |
| 135 | −val. If val is not present, its value is '1'. Function-like macros can | |
| 136 | −also be defined: @code{'-DF(a)=a+1'} | |
| 167 | +Define preprocessor symbol @samp{sym} to | |
| 168 | +val. If val is not present, its value is @samp{1}. Function-like macros can | |
| 169 | +also be defined: @option{-DF(a)=a+1} | |
| 137 | 170 | |
| 138 | 171 | @item -Usym |
| 139 | −Undefine preprocessor symbol 'sym'. | |
| 172 | +Undefine preprocessor symbol @samp{sym}. | |
| 140 | 173 | @end table |
| 141 | 174 | |
| 142 | 175 | Linker options: |
| 143 | 176 | |
| 144 | −@table @samp | |
| 177 | +@table @option | |
| 145 | 178 | @item -Ldir |
| 146 | −Specify an additionnal static library path for the @samp{-l} option. The | |
| 179 | +Specify an additional static library path for the @option{-l} option. The | |
| 147 | 180 | default library paths are @file{/usr/local/lib}, @file{/usr/lib} and @file{/lib}. |
| 148 | 181 | |
| 149 | 182 | @item -lxxx |
| 150 | 183 | Link your program with dynamic library libxxx.so or static library |
| 151 | 184 | libxxx.a. The library is searched in the paths specified by the |
| 152 | −@samp{-L} option. | |
| 185 | +@option{-L} option. | |
| 153 | 186 | |
| 154 | 187 | @item -shared |
| 155 | −Generate a shared library instead of an executable (@samp{-o} option | |
| 188 | +Generate a shared library instead of an executable (@option{-o} option | |
| 156 | 189 | must also be given). |
| 157 | 190 | |
| 158 | 191 | @item -static |
| 159 | 192 | Generate a statically linked executable (default is a shared linked |
| 160 | −executable) (@samp{-o} option must also be given). | |
| 193 | +executable) (@option{-o} option must also be given). | |
| 161 | 194 | |
| 162 | 195 | @item -r |
| 163 | −Generate an object file combining all input files (@samp{-o} option must | |
| 196 | +Generate an object file combining all input files (@option{-o} option must | |
| 164 | 197 | also be given). |
| 165 | 198 | |
| 166 | 199 | @end table |
| 167 | 200 | |
| 168 | 201 | Debugger options: |
| 169 | 202 | |
| 170 | −@table @samp | |
| 203 | +@table @option | |
| 171 | 204 | @item -g |
| 172 | 205 | Generate run time debug information so that you get clear run time |
| 173 | 206 | error messages: @code{ test.c:68: in function 'test5()': dereferencing |
| @@ -175,17 +208,17 @@ invalid pointer} instead of the laconic @code{Segmentation · 1 unmodified line | ||
| 175 | 208 | fault}. |
| 176 | 209 | |
| 177 | 210 | @item -b |
| 178 | −Generate additionnal support code to check | |
| 179 | −memory allocations and array/pointer bounds. @samp{-g} is implied. Note | |
| 211 | +Generate additional support code to check | |
| 212 | +memory allocations and array/pointer bounds. @option{-g} is implied. Note | |
| 180 | 213 | that the generated code is slower and bigger in this case. |
| 181 | 214 | |
| 182 | 215 | @item -bt N |
| 183 | −Display N callers in stack traces. This is useful with @samp{-g} or | |
| 184 | −@samp{-b}. | |
| 216 | +Display N callers in stack traces. This is useful with @option{-g} or | |
| 217 | +@option{-b}. | |
| 185 | 218 | |
| 186 | 219 | @end table |
| 187 | 220 | |
| 188 | −Note: GCC options @samp{-Ox}, @samp{-Wx}, @samp{-fx} and @samp{-mx} are | |
| 221 | +Note: GCC options @option{-Ox}, @option{-Wx}, @option{-fx} and @option{-mx} are | |
| 189 | 222 | ignored. |
| 190 | 223 | |
| 191 | 224 | @chapter C language support |
| @@ -206,11 +239,11 @@ Currently implemented ISOC99 features: · 14 unmodified lines | ||
| 206 | 239 | |
| 207 | 240 | @itemize |
| 208 | 241 | |
| 209 | −@item 64 bit @code{'long long'} types are fully supported. | |
| 242 | +@item 64 bit @code{long long} types are fully supported. | |
| 210 | 243 | |
| 211 | −@item The boolean type @code{'_Bool'} is supported. | |
| 244 | +@item The boolean type @code{_Bool} is supported. | |
| 212 | 245 | |
| 213 | −@item @code{'__func__'} is a string variable containing the current | |
| 246 | +@item @code{__func__} is a string variable containing the current | |
| 214 | 247 | function name. |
| 215 | 248 | |
| 216 | 249 | @item Variadic macros: @code{__VA_ARGS__} can be used for |
| @@ -218,6 +251,8 @@ function name. · 1 unmodified line | ||
| 218 | 251 | @example |
| 219 | 252 | #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__) |
| 220 | 253 | @end example |
| 254 | + | |
| 255 | +@noindent | |
| 221 | 256 | @code{dprintf} can then be used with a variable number of parameters. |
| 222 | 257 | |
| 223 | 258 | @item Declarations can appear anywhere in a block (as in C++). |
| @@ -225,14 +260,14 @@ function name. · 1 unmodified line | ||
| 225 | 260 | @item Array and struct/union elements can be initialized in any order by |
| 226 | 261 | using designators: |
| 227 | 262 | @example |
| 228 | − struct { int x, y; } st[10] = { [0].x = 1, [0].y = 2 }; | |
| 263 | + struct @{ int x, y; @} st[10] = @{ [0].x = 1, [0].y = 2 @}; | |
| 229 | 264 | |
| 230 | − int tab[10] = { 1, 2, [5] = 5, [9] = 9}; | |
| 265 | + int tab[10] = @{ 1, 2, [5] = 5, [9] = 9@}; | |
| 231 | 266 | @end example |
| 232 | 267 | |
| 233 | 268 | @item Compound initializers are supported: |
| 234 | 269 | @example |
| 235 | − int *p = (int []){ 1, 2, 3 }; | |
| 270 | + int *p = (int [])@{ 1, 2, 3 @}; | |
| 236 | 271 | @end example |
| 237 | 272 | to initialize a pointer pointing to an initialized array. The same |
| 238 | 273 | works for structures and strings. |
| @@ -241,14 +276,16 @@ works for structures and strings. · 2 unmodified lines | ||
| 241 | 276 | @example |
| 242 | 277 | double d = 0x1234p10; |
| 243 | 278 | @end example |
| 279 | + | |
| 280 | +@noindent | |
| 244 | 281 | is the same as writing |
| 245 | 282 | @example |
| 246 | 283 | double d = 4771840.0; |
| 247 | 284 | @end example |
| 248 | 285 | |
| 249 | −@item @code{'inline'} keyword is ignored. | |
| 286 | +@item @code{inline} keyword is ignored. | |
| 250 | 287 | |
| 251 | −@item @code{'restrict'} keyword is ignored. | |
| 288 | +@item @code{restrict} keyword is ignored. | |
| 252 | 289 | @end itemize |
| 253 | 290 | |
| 254 | 291 | @section GNU C extensions |
| @@ -259,30 +296,30 @@ TCC implements some GNU C extensions: · 4 unmodified lines | ||
| 259 | 296 | |
| 260 | 297 | @item array designators can be used without '=': |
| 261 | 298 | @example |
| 262 | − int a[10] = { [0] 1, [5] 2, 3, 4 }; | |
| 299 | + int a[10] = @{ [0] 1, [5] 2, 3, 4 @}; | |
| 263 | 300 | @end example |
| 264 | 301 | |
| 265 | 302 | @item Structure field designators can be a label: |
| 266 | 303 | @example |
| 267 | − struct { int x, y; } st = { x: 1, y: 1}; | |
| 304 | + struct @{ int x, y; @} st = @{ x: 1, y: 1@}; | |
| 268 | 305 | @end example |
| 269 | 306 | instead of |
| 270 | 307 | @example |
| 271 | − struct { int x, y; } st = { .x = 1, .y = 1}; | |
| 308 | + struct @{ int x, y; @} st = @{ .x = 1, .y = 1@}; | |
| 272 | 309 | @end example |
| 273 | 310 | |
| 274 | −@item @code{'\e'} is ASCII character 27. | |
| 311 | +@item @code{\e} is ASCII character 27. | |
| 275 | 312 | |
| 276 | 313 | @item case ranges : ranges can be used in @code{case}s: |
| 277 | 314 | @example |
| 278 | − switch(a) { | |
| 279 | − case 1 ... 9: | |
| 315 | + switch(a) @{ | |
| 316 | + case 1 @dots{} 9: | |
| 280 | 317 | printf("range 1 to 9\n"); |
| 281 | 318 | break; |
| 282 | 319 | default: |
| 283 | 320 | printf("unexpected\n"); |
| 284 | 321 | break; |
| 285 | − } | |
| 322 | + @} | |
| 286 | 323 | @end example |
| 287 | 324 | |
| 288 | 325 | @item The keyword @code{__attribute__} is handled to specify variable or |
| @@ -307,20 +344,22 @@ Here are some examples: · 18 unmodified lines | ||
| 307 | 344 | int a __attribute__ ((aligned(8), section(".mysection"))); |
| 308 | 345 | @end example |
| 309 | 346 | |
| 310 | −align variable @code{'a'} to 8 bytes and put it in section @code{.mysection}. | |
| 347 | +@noindent | |
| 348 | +align variable @code{a} to 8 bytes and put it in section @code{.mysection}. | |
| 311 | 349 | |
| 312 | 350 | @example |
| 313 | 351 | int my_add(int a, int b) __attribute__ ((section(".mycodesection"))) |
| 314 | − { | |
| 352 | + @{ | |
| 315 | 353 | return a + b; |
| 316 | − } | |
| 354 | + @} | |
| 317 | 355 | @end example |
| 318 | 356 | |
| 319 | −generate function @code{'my_add'} in section @code{.mycodesection}. | |
| 357 | +@noindent | |
| 358 | +generate function @code{my_add} in section @code{.mycodesection}. | |
| 320 | 359 | |
| 321 | 360 | @item GNU style variadic macros: |
| 322 | 361 | @example |
| 323 | − #define dprintf(fmt, args...) printf(fmt, ## args) | |
| 362 | + #define dprintf(fmt, args@dots{}) printf(fmt, ## args) | |
| 324 | 363 | |
| 325 | 364 | dprintf("no arg\n"); |
| 326 | 365 | dprintf("one arg %d\n", 1); |
| @@ -341,26 +380,31 @@ to get the alignment of a type or an expression. · 14 unmodified lines | ||
| 341 | 380 | used to jump on the pointer resulting from @code{expr}. |
| 342 | 381 | |
| 343 | 382 | @item Inline assembly with asm instruction: |
| 383 | +@cindex inline assembly | |
| 384 | +@cindex assembly, inline | |
| 385 | +@cindex __asm__ | |
| 344 | 386 | @example |
| 345 | 387 | static inline void * my_memcpy(void * to, const void * from, size_t n) |
| 346 | −{ | |
| 388 | +@{ | |
| 347 | 389 | int d0, d1, d2; |
| 348 | 390 | __asm__ __volatile__( |
| 349 | − "rep ; movsl\n\t" | |
| 350 | − "testb $2,%b4\n\t" | |
| 351 | − "je 1f\n\t" | |
| 352 | − "movsw\n" | |
| 353 | − "1:\ttestb $1,%b4\n\t" | |
| 354 | − "je 2f\n\t" | |
| 355 | − "movsb\n" | |
| 356 | − "2:" | |
| 357 | − : "=&c" (d0), "=&D" (d1), "=&S" (d2) | |
| 358 | − :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) | |
| 359 | − : "memory"); | |
| 391 | + "rep ; movsl\n\t" | |
| 392 | + "testb $2,%b4\n\t" | |
| 393 | + "je 1f\n\t" | |
| 394 | + "movsw\n" | |
| 395 | + "1:\ttestb $1,%b4\n\t" | |
| 396 | + "je 2f\n\t" | |
| 397 | + "movsb\n" | |
| 398 | + "2:" | |
| 399 | + : "=&c" (d0), "=&D" (d1), "=&S" (d2) | |
| 400 | + :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) | |
| 401 | + : "memory"); | |
| 360 | 402 | return (to); |
| 361 | −} | |
| 403 | +@} | |
| 362 | 404 | @end example |
| 363 | 405 | |
| 406 | +@noindent | |
| 407 | +@cindex gas | |
| 364 | 408 | TCC includes its own x86 inline assembler with a @code{gas}-like (GNU |
| 365 | 409 | assembler) syntax. No intermediate files are generated. GCC 3.x named |
| 366 | 410 | operands are supported. |
| @@ -371,13 +415,13 @@ operands are supported. · 4 unmodified lines | ||
| 371 | 415 | |
| 372 | 416 | @itemize |
| 373 | 417 | |
| 374 | −@item @code{__TINYC__} is a predefined macro to @code{'1'} to | |
| 418 | +@item @code{__TINYC__} is a predefined macro to @code{1} to | |
| 375 | 419 | indicate that you use TCC. |
| 376 | 420 | |
| 377 | −@item @code{'#!'} at the start of a line is ignored to allow scripting. | |
| 421 | +@item @code{#!} at the start of a line is ignored to allow scripting. | |
| 378 | 422 | |
| 379 | −@item Binary digits can be entered (@code{'0b101'} instead of | |
| 380 | −@code{'5'}). | |
| 423 | +@item Binary digits can be entered (@code{0b101} instead of | |
| 424 | +@code{5}). | |
| 381 | 425 | |
| 382 | 426 | @item @code{__BOUNDS_CHECKING_ON} is defined if bound checking is activated. |
| 383 | 427 | |
| @@ -452,6 +496,16 @@ They can be defined several times in the same source. Use 'b' · 68 unmodified lines | ||
| 452 | 496 | @end itemize |
| 453 | 497 | |
| 454 | 498 | @section Directives |
| 499 | +@cindex assembler directives | |
| 500 | +@cindex directives, assembler | |
| 501 | +@cindex .align | |
| 502 | +@cindex .skip | |
| 503 | +@cindex .space | |
| 504 | +@cindex .byte | |
| 505 | +@cindex .word | |
| 506 | +@cindex .short | |
| 507 | +@cindex .int | |
| 508 | +@cindex .long | |
| 455 | 509 | |
| 456 | 510 | All directives are preceeded by a '.'. The following directives are |
| 457 | 511 | supported: |
| @@ -468,6 +522,7 @@ supported: · 10 unmodified lines | ||
| 468 | 522 | @end itemize |
| 469 | 523 | |
| 470 | 524 | @section X86 Assembler |
| 525 | +@cindex assembler | |
| 471 | 526 | |
| 472 | 527 | All X86 opcodes are supported. Only ATT syntax is supported (source |
| 473 | 528 | then destination operand order). If no size suffix is given, TinyCC |
| @@ -476,20 +531,22 @@ tries to guess it from the operand sizes. · 2 unmodified lines | ||
| 476 | 531 | Currently, MMX opcodes are supported but not SSE ones. |
| 477 | 532 | |
| 478 | 533 | @chapter TinyCC Linker |
| 534 | +@cindex linker | |
| 479 | 535 | |
| 480 | 536 | @section ELF file generation |
| 537 | +@cindex ELF | |
| 481 | 538 | |
| 482 | 539 | TCC can directly output relocatable ELF files (object files), |
| 483 | 540 | executable ELF files and dynamic ELF libraries without relying on an |
| 484 | 541 | external linker. |
| 485 | 542 | |
| 486 | 543 | Dynamic ELF libraries can be output but the C compiler does not generate |
| 487 | −position independant code (PIC) code. It means that the dynamic librairy | |
| 544 | +position independent code (PIC). It means that the dynamic librairy | |
| 488 | 545 | code generated by TCC cannot be factorized among processes yet. |
| 489 | 546 | |
| 490 | −TCC linker cannot currently suppress unused object code. But TCC | |
| 547 | +TCC linker cannot currently eliminate unused object code. But TCC | |
| 491 | 548 | will soon integrate a novel feature not found in GNU tools: unused code |
| 492 | −will be suppressed at the function or variable level, provided you only | |
| 549 | +will be eliminated at the function or variable level, provided you only | |
| 493 | 550 | use TCC to compile your files. |
| 494 | 551 | |
| 495 | 552 | @section ELF file loader |
| @@ -498,10 +555,14 @@ TCC can load ELF object files, archives (.a files) and dynamic · 2 unmodified lines | ||
| 498 | 555 | libraries (.so). |
| 499 | 556 | |
| 500 | 557 | @section GNU Linker Scripts |
| 558 | +@cindex scripts, linker | |
| 559 | +@cindex linker scripts | |
| 560 | +@cindex GROUP, linker command | |
| 561 | +@cindex FILE, linker command | |
| 501 | 562 | |
| 502 | 563 | Because on many Linux systems some dynamic libraries (such as |
| 503 | 564 | @file{/usr/lib/libc.so}) are in fact GNU ld link scripts (horrible!), |
| 504 | −TCC linker also support a subset of GNU ld scripts. | |
| 565 | +the TCC linker also supports a subset of GNU ld scripts. | |
| 505 | 566 | |
| 506 | 567 | The @code{GROUP} and @code{FILE} commands are supported. |
| 507 | 568 | |
| @@ -513,78 +574,80 @@ Example from @file{/usr/lib/libc.so}: · 5 unmodified lines | ||
| 513 | 574 | GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a ) |
| 514 | 575 | @end example |
| 515 | 576 | |
| 516 | −@node bounds | |
| 577 | +@node Bounds | |
| 517 | 578 | @chapter TinyCC Memory and Bound checks |
| 579 | +@cindex bound checks | |
| 580 | +@cindex memory checks | |
| 518 | 581 | |
| 519 | −This feature is activated with the @code{'-b'} (@xref{invoke}). | |
| 582 | +This feature is activated with the @option{-b} (@pxref{Invoke}). | |
| 520 | 583 | |
| 521 | 584 | Note that pointer size is @emph{unchanged} and that code generated |
| 522 | 585 | with bound checks is @emph{fully compatible} with unchecked |
| 523 | 586 | code. When a pointer comes from unchecked code, it is assumed to be |
| 524 | 587 | valid. Even very obscure C code with casts should work correctly. |
| 525 | 588 | |
| 526 | −To have more information about the ideas behind this method, check at | |
| 589 | +For more information about the ideas behind this method, see | |
| 527 | 590 | @url{http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html}. |
| 528 | 591 | |
| 529 | −Here are some examples of catched errors: | |
| 592 | +Here are some examples of caught errors: | |
| 530 | 593 | |
| 531 | 594 | @table @asis |
| 532 | 595 | |
| 533 | 596 | @item Invalid range with standard string function: |
| 534 | 597 | @example |
| 535 | −{ | |
| 598 | +@{ | |
| 536 | 599 | char tab[10]; |
| 537 | 600 | memset(tab, 0, 11); |
| 538 | −} | |
| 601 | +@} | |
| 539 | 602 | @end example |
| 540 | 603 | |
| 541 | −@item Bound error in global or local arrays: | |
| 604 | +@item Out of bounds-error in global or local arrays: | |
| 542 | 605 | @example |
| 543 | −{ | |
| 606 | +@{ | |
| 544 | 607 | int tab[10]; |
| 545 | − for(i=0;i<11;i++) { | |
| 608 | + for(i=0;i<11;i++) @{ | |
| 546 | 609 | sum += tab[i]; |
| 547 | − } | |
| 548 | −} | |
| 610 | + @} | |
| 611 | +@} | |
| 549 | 612 | @end example |
| 550 | 613 | |
| 551 | −@item Bound error in allocated data: | |
| 614 | +@item Out of bounds-error in malloc'ed data: | |
| 552 | 615 | @example |
| 553 | −{ | |
| 616 | +@{ | |
| 554 | 617 | int *tab; |
| 555 | 618 | tab = malloc(20 * sizeof(int)); |
| 556 | − for(i=0;i<21;i++) { | |
| 619 | + for(i=0;i<21;i++) @{ | |
| 557 | 620 | sum += tab4[i]; |
| 558 | − } | |
| 621 | + @} | |
| 559 | 622 | free(tab); |
| 560 | −} | |
| 623 | +@} | |
| 561 | 624 | @end example |
| 562 | 625 | |
| 563 | −@item Access to a freed region: | |
| 626 | +@item Access of freed memory: | |
| 564 | 627 | @example |
| 565 | −{ | |
| 628 | +@{ | |
| 566 | 629 | int *tab; |
| 567 | 630 | tab = malloc(20 * sizeof(int)); |
| 568 | 631 | free(tab); |
| 569 | − for(i=0;i<20;i++) { | |
| 632 | + for(i=0;i<20;i++) @{ | |
| 570 | 633 | sum += tab4[i]; |
| 571 | − } | |
| 572 | −} | |
| 634 | + @} | |
| 635 | +@} | |
| 573 | 636 | @end example |
| 574 | 637 | |
| 575 | −@item Freeing an already freed region: | |
| 638 | +@item Double free: | |
| 576 | 639 | @example |
| 577 | −{ | |
| 640 | +@{ | |
| 578 | 641 | int *tab; |
| 579 | 642 | tab = malloc(20 * sizeof(int)); |
| 580 | 643 | free(tab); |
| 581 | 644 | free(tab); |
| 582 | −} | |
| 645 | +@} | |
| 583 | 646 | @end example |
| 584 | 647 | |
| 585 | 648 | @end table |
| 586 | 649 | |
| 587 | −@node libtcc | |
| 650 | +@node Libtcc | |
| 588 | 651 | @chapter The @code{libtcc} library |
| 589 | 652 | |
| 590 | 653 | The @code{libtcc} library enables you to use TCC as a backend for |
| @@ -597,7 +660,7 @@ The idea consists in giving a C string containing the program you want · 6 unmodified lines | ||
| 597 | 660 | to compile directly to @code{libtcc}. Then you can access to any global |
| 598 | 661 | symbol (function or variable) defined. |
| 599 | 662 | |
| 600 | −@chapter Developper's guide | |
| 663 | +@chapter Developer's guide | |
| 601 | 664 | |
| 602 | 665 | This chapter gives some hints to understand how TCC works. You can skip |
| 603 | 666 | it if you do not intend to modify the TCC code. |
| @@ -617,7 +680,7 @@ expansion. · 13 unmodified lines | ||
| 617 | 680 | |
| 618 | 681 | @code{tok} contains the current token (see @code{TOK_xxx}) |
| 619 | 682 | constants. Identifiers and keywords are also keywords. @code{tokc} |
| 620 | −contains additionnal infos about the token (for example a constant value | |
| 683 | +contains additional infos about the token (for example a constant value | |
| 621 | 684 | if number or string token). |
| 622 | 685 | |
| 623 | 686 | @section Parser |
| @@ -771,22 +834,24 @@ contain the exported symbols (currently only used for debugging). · 147 unmodified lines | ||
| 771 | 834 | @end table |
| 772 | 835 | |
| 773 | 836 | @section Code generation |
| 837 | +@cindex code generation | |
| 774 | 838 | |
| 775 | 839 | @subsection Introduction |
| 776 | 840 | |
| 777 | 841 | The TCC code generator directly generates linked binary code in one |
| 778 | 842 | pass. It is rather unusual these days (see gcc for example which |
| 779 | −generates text assembly), but it allows to be very fast and surprisingly | |
| 780 | −not so complicated. | |
| 843 | +generates text assembly), but it can be very fast and surprisingly | |
| 844 | +little complicated. | |
| 781 | 845 | |
| 782 | 846 | The TCC code generator is register based. Optimization is only done at |
| 783 | 847 | the expression level. No intermediate representation of expression is |
| 784 | 848 | kept except the current values stored in the @emph{value stack}. |
| 785 | 849 | |
| 786 | 850 | On x86, three temporary registers are used. When more registers are |
| 787 | −needed, one register is flushed in a new local variable. | |
| 851 | +needed, one register is spilled into a new temporary variable on the stack. | |
| 788 | 852 | |
| 789 | 853 | @subsection The value stack |
| 854 | +@cindex value stack, introduction | |
| 790 | 855 | |
| 791 | 856 | When an expression is parsed, its value is pushed on the value stack |
| 792 | 857 | (@var{vstack}). The top of the value stack is @var{vtop}. Each value |
| @@ -794,7 +859,7 @@ stack entry is the structure @code{SValue}. · 1 unmodified line | ||
| 794 | 859 | |
| 795 | 860 | @code{SValue.t} is the type. @code{SValue.r} indicates how the value is |
| 796 | 861 | currently stored in the generated code. It is usually a CPU register |
| 797 | −index (@code{REG_xxx} constants), but additionnal values and flags are | |
| 862 | +index (@code{REG_xxx} constants), but additional values and flags are | |
| 798 | 863 | defined: |
| 799 | 864 | |
| 800 | 865 | @example |
| @@ -835,8 +900,8 @@ put in a normal register. · 34 unmodified lines | ||
| 835 | 900 | |
| 836 | 901 | @item VT_JMP |
| 837 | 902 | @itemx VT_JMPI |
| 838 | −indicates that the value is the consequence of a jmp. For VT_JMP, it is | |
| 839 | −1 if the jump is taken, 0 otherwise. For VT_JMPI it is inverted. | |
| 903 | +indicates that the value is the consequence of a conditional jump. For VT_JMP, | |
| 904 | +it is 1 if the jump is taken, 0 otherwise. For VT_JMPI it is inverted. | |
| 840 | 905 | |
| 841 | 906 | These values are used to compile the @code{||} and @code{&&} logical |
| 842 | 907 | operators. |
| @@ -857,10 +922,10 @@ understand how TCC works. · 14 unmodified lines | ||
| 857 | 922 | @itemx VT_LVAL_SHORT |
| 858 | 923 | @itemx VT_LVAL_UNSIGNED |
| 859 | 924 | if the lvalue has an integer type, then these flags give its real |
| 860 | −type. The type alone is not suffisant in case of cast optimisations. | |
| 925 | +type. The type alone is not enough in case of cast optimisations. | |
| 861 | 926 | |
| 862 | 927 | @item VT_LLOCAL |
| 863 | −is a saved lvalue on the stack. @code{VT_LLOCAL} should be suppressed | |
| 928 | +is a saved lvalue on the stack. @code{VT_LLOCAL} should be eliminated | |
| 864 | 929 | ASAP because its semantics are rather complicated. |
| 865 | 930 | |
| 866 | 931 | @item VT_MUSTCAST |
| @@ -877,17 +942,18 @@ are only used for optional bound checking. · 10 unmodified lines | ||
| 877 | 942 | @end table |
| 878 | 943 | |
| 879 | 944 | @subsection Manipulating the value stack |
| 945 | +@cindex value stack | |
| 880 | 946 | |
| 881 | 947 | @code{vsetc()} and @code{vset()} pushes a new value on the value |
| 882 | −stack. If the previous @code{vtop} was stored in a very unsafe place(for | |
| 948 | +stack. If the previous @var{vtop} was stored in a very unsafe place(for | |
| 883 | 949 | example in the CPU flags), then some code is generated to put the |
| 884 | −previous @code{vtop} in a safe storage. | |
| 950 | +previous @var{vtop} in a safe storage. | |
| 885 | 951 | |
| 886 | −@code{vpop()} pops @code{vtop}. In some cases, it also generates cleanup | |
| 952 | +@code{vpop()} pops @var{vtop}. In some cases, it also generates cleanup | |
| 887 | 953 | code (for example if stacked floating point registers are used as on |
| 888 | 954 | x86). |
| 889 | 955 | |
| 890 | −The @code{gv(rc)} function generates code to evaluate @code{vtop} (the | |
| 956 | +The @code{gv(rc)} function generates code to evaluate @var{vtop} (the | |
| 891 | 957 | top value of the stack) into registers. @var{rc} selects in which |
| 892 | 958 | register class the value should be put. @code{gv()} is the @emph{most |
| 893 | 959 | important function} of the code generator. |
| @@ -896,7 +962,7 @@ important function} of the code generator. · 2 unmodified lines | ||
| 896 | 962 | entries. |
| 897 | 963 | |
| 898 | 964 | @subsection CPU dependent code generation |
| 899 | − | |
| 965 | +@cindex CPU dependent | |
| 900 | 966 | See the @file{i386-gen.c} file to have an example. |
| 901 | 967 | |
| 902 | 968 | @table @code |
| @@ -939,12 +1005,18 @@ floating point to floating point of different size conversion. · 36 unmodified lines | ||
| 939 | 1005 | |
| 940 | 1006 | @item gen_bounded_ptr_add() |
| 941 | 1007 | @item gen_bounded_ptr_deref() |
| 942 | −are only used for bound checking. | |
| 1008 | +are only used for bounds checking. | |
| 943 | 1009 | |
| 944 | 1010 | @end table |
| 945 | 1011 | |
| 946 | 1012 | @section Optimizations done |
| 947 | − | |
| 1013 | +@cindex optimizations | |
| 1014 | +@cindex constant propagation | |
| 1015 | +@cindex strength reduction | |
| 1016 | +@cindex comparison operators | |
| 1017 | +@cindex caching processor flags | |
| 1018 | +@cindex flags, caching | |
| 1019 | +@cindex jump optimization | |
| 948 | 1020 | Constant propagation is done for all operations. Multiplications and |
| 949 | 1021 | divisions are optimized to shifts when appropriate. Comparison |
| 950 | 1022 | operators are optimized by maintaining a special cache for the |
| @@ -952,3 +1024,12 @@ processor flags. &&, || and ! are optimized by maintaining a special · 1 unmodified line | ||
| 952 | 1024 | 'jump target' value. No other jump optimization is currently performed |
| 953 | 1025 | because it would require to store the code in a more abstract fashion. |
| 954 | 1026 | |
| 1027 | +@unnumbered Concept Index | |
| 1028 | +@printindex cp | |
| 1029 | + | |
| 1030 | +@bye | |
| 1031 | + | |
| 1032 | +@c Local variables: | |
| 1033 | +@c fill-column: 78 | |
| 1034 | +@c texinfo-column-for-description: 32 | |
| 1035 | +@c End: | |