History

update

bellard committed 24 years ago

Commit ebe9e871 parent fd20e743 files · +199 −64Browse files

Unified · Split

3 files
  1. README +12 −24
  2. TODO +10 −8
  3. tcc-doc.texi +177 −32
README+12−24
@@ -15,6 +15,9 @@ Features: · 14 unmodified lines
1515 heading torward full ISOC99 compliance. TCC can of course compile
1616 itself.
1717
18+- SAFE! tcc includes an optional memory and bound checker. Bound
19+ checked code can be mixed freely with standard code.
20+
1821 - Compile and execute C source directly. No linking or assembly
1922 necessary. Full C preprocessor included.
2023
@@ -27,7 +30,7 @@ Documentation: · 6 unmodified lines
2730
2831 1) Installation
2932
30−***TCC currently only works on Linux x86***.
33+*** TCC currently only works on Linux x86 with glibc >= 2.1 ***.
3134
3235 Type 'make install' to compile and install tcc in /usr/local/bin and
3336 /usr/local/lib/tcc.
@@ -49,21 +52,7 @@ launch the C code as a shell or perl script :-) The command line · 15 unmodified lines
4952 arguments are put in 'argc' and 'argv' of the main functions, as in
5053 ANSI C.
5154
52−3) Invokation
53−
54−'-Idir' : specify an additionnal include path. The
55−default ones are: /usr/include, /usr/lib/tcc, /usr/local/lib/tcc.
56−
57−'-Dsym' : define preprocessor symbol 'sym' to 1.
58−
59−'-lxxx' : dynamically link your program with library
60−libxxx.so. Standard library paths are checked, including those
61−specificed with LD_LIBRARY_PATH.
62−
63−'-i file' : compile C source 'file' before main C source. With this
64−command, multiple C files can be compiled and linked together.
65−
66−4) Examples
55+3) Examples
6756
6857 ex1.c: simplest example (hello world). Can also be launched directly
6958 as a script: './ex1.c'.
@@ -84,7 +73,7 @@ generator. · 14 unmodified lines
8473 prog.c: auto test for TCC which tests many subtle possible bugs. Used
8574 when doing 'make test'.
8675
87−5) Full Documentation
76+4) Full Documentation
8877
8978 Please read tcc-doc.html to have all the features of TCC.
9079
@@ -105,7 +94,7 @@ assembly), but it allows to be very fast and surprisingly not so · 14 unmodified lines
10594 complicated.
10695
10796 The TCC code generator is register based. It means that it could even
108−generate good code for RISC processors. On x86, three temporary
97+generate not so bad code for RISC processors. On x86, three temporary
10998 registers are used. When more registers are needed, one register is
11099 flushed in a new local variable.
111100
@@ -113,13 +102,12 @@ Constant propagation is done for all operations. Multiplications and · 1 unmodified line
113102 divisions are optimized to shifts when appropriate. Comparison
114103 operators are optimized by maintaining a special cache for the
115104 processor flags. &&, || and ! are optimized by maintaining a special
116−'jmp target' value. No other jmp optimization is currently performed
105+'jump target' value. No other jump optimization is currently performed
117106 because it would require to store the code in a more abstract fashion.
118107
119−The types and values descriptions are stored in a single 'int'
120−variable (see VT_xxx constants). It was choosen in the first stages of
121−development when tcc was much simpler. Now, it may not be the best
122−solution.
108+The types are stored in a single 'int' variable (see VT_xxx
109+constants). It was choosen in the first stages of development when tcc
110+was much simpler. Now, it may not be the best solution.
123111
124112 License:
125113 -------
@@ -130,4 +118,4 @@ file). · 4 unmodified lines
130118 I accept only patches where you give your copyright explicitely to me
131119 to simplify licensing issues.
132120
133−Fabrice Bellard - Nov 17, 2001.
121+Fabrice Bellard.
TODO+10−8
@@ -1,25 +1,27 @@
11 TODO list:
22
33 Critical:
4−- finish float/double support. add function type convertion.
5−- section generation and GNUC __attributte__ handling.
6−- D option with '=' handling
7−- 0 is pointer - fix type compare
4+- optimize slightly bound checking when doing addition + dereference.
5+- better section generator (suppress some mmaps).
6+- To check: bound checking and float/long long/struct copy code
87 - To check: 'sizeof' may not work if too complex expression is given.
9−- fix 'char' and 'short' casts (only in function parameters and in
10− assignment).
8+- fix bound check code with '&' on local variables (currently done
9+ only for local arrays).
1110
1211 Not critical:
1312
14−- interactive mode
13+- add PowerPC or ARM code generator and improve codegen for RISC (need
14+ to suppress VT_LOCAL and use a base register instead).
15+- interactive mode / integrated debugger
1516 - fix multiple compound literals inits in blocks (ISOC99 normative
1617 example - only relevant when using gotos! -> must add boolean
1718 variable to tell if compound literal was already initialized).
19+- add more bounds checked functions (strcpy, ...)
1820 - fix L"\x1234" wide string case (need to store them as utf8 ?)
1921 - fix preprocessor symbol redefinition
2022 - better constant opt (&&, ||, ?:)
2123 - add ELF executable and shared library output option (would be needed
2224 for completness!).
23−- add PowerPC code generator.
25+- D option with all #define cases (needs C parser)
2426 - add portable byte code generator and interpreter for other
2527 unsupported architectures.
tcc-doc.texi+177−32
@@ -14,49 +14,51 @@ Tiny C Compiler Reference Documentation · 13 unmodified lines
1414
1515 <h2>Introduction</h2>
1616
17−TinyCC (aka TCC) is a small but very fast C compiler. Unlike other C
17+TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
1818 compilers, it is meant to be self-suffisant: you do not need an
1919 external assembler or linker because TCC does that for you.
2020 <P>
21−
22−TCC compiles so fast that even for big projects <tt>Makefile</tt>s may
21+TCC compiles so <em>fast</em> that even for big projects <tt>Makefile</tt>s may
2322 not be necessary.
2423 <P>
24+TCC not only supports ANSI C, but also most of the new ISO C99
25+standard and many GNUC extensions.
26+<P>
2527 TCC can also be used to make <I>C scripts</I>,
2628 i.e. pieces of C source that you run as a Perl or Python
2729 script. Compilation is so fast that your script will be as fast as if
2830 it was an executable.
31+<P>
32+TCC can also automatically generate <A HREF="#bounds">memory and bound
33+checks</A> while allowing all C pointers operations. TCC can do these
34+checks even if non patched libraries are used.
35+</P>
2936
30−<h2>Exact differences with ANSI C</h2>
37+<h2>Full ANSI C support</h2>
3138
32−TCC implements almost all the ANSI C standard, except floating points
33−numbers.
39+TCC implements all the ANSI C standard, including structure bit fields
40+and floating point numbers (<tt>long double</tt>, <tt>double</tt>, and
41+<tt>float</tt> fully supported). The following limitations are known:
3442
3543 <ul>
3644 <li> The preprocessor tokens are the same as C. It means that in some
3745 rare cases, preprocessed numbers are not handled exactly as in ANSI
3846 C. This approach has the advantage of being simpler and FAST!
39−
40− <li> Floating point numbers are not fully supported yet (some
41− implicit casts are missing).
42−
43− <li> Some typing errors are not signaled.
4447 </ul>
4548
4649 <h2>ISOC99 extensions</h2>
4750
4851 TCC implements many features of the new C standard: ISO C99. Currently
49−missing items are: complex and imaginary numbers (will come with ANSI
50−C floating point numbers), <tt>long long</tt>s and variable length
52+missing items are: complex and imaginary numbers and variable length
5153 arrays.
5254
5355 Currently implemented ISOC99 features:
5456
5557 <ul>
5658
57−<li> <tt>'inline'</tt> keyword is ignored.
59+<li> 64 bit <tt>'long long'</tt> types are fully supported.
5860
59−<li> <tt>'restrict'</tt> keyword is ignored.
61+<li> The boolean type <tt>'_Bool'</tt> is supported.
6062
6163 <li> <tt>'__func__'</tt> is a string variable containing the current
6264 function name.
@@ -68,7 +70,7 @@ function name. · 5 unmodified lines
6870 </PRE>
6971 <tt>dprintf</tt> can then be used with a variable number of parameters.
7072
71−<li> Declarations can appear anywhere in a block as in C++.
73+<li> Declarations can appear anywhere in a block (as in C++).
7274
7375 <li> Array and struct/union elements can be initialized in any order by
7476 using designators:
@@ -85,11 +87,6 @@ function name. · 10 unmodified lines
8587 to initialize a pointer pointing to an initialized array. The same
8688 works for structures and strings.
8789
88−<li> The boolean type <tt>'_Bool'</tt> is supported.
89−
90−<li> <tt>'long long'</tt> types not supported yet, except in type
91− definition or <tt>'sizeof'</tt>.
92−
9390 <li> Hexadecimal floating point constants are supported:
9491 <PRE>
9592 double d = 0x1234p10;
@@ -98,11 +95,15 @@ is the same as writing · 2 unmodified lines
9895 <PRE>
9996 double d = 4771840.0;
10097 </PRE>
98+
99+<li> <tt>'inline'</tt> keyword is ignored.
100+
101+<li> <tt>'restrict'</tt> keyword is ignored.
101102 </ul>
102103
103104 <h2>GNU C extensions</h2>
104105
105−TCC implements some GNU C extensions which are found in many C sources:
106+TCC implements some GNU C extensions:
106107
107108 <ul>
108109
@@ -122,6 +123,45 @@ instead of · 13 unmodified lines
122123
123124 <li> <tt>'\e'</tt> is ASCII character 27.
124125
126+<li> case ranges : ranges can be used in <tt>case</tt>s:
127+<PRE>
128+ switch(a) {
129+ case 1 ... 9:
130+ printf("range 1 to 9\n");
131+ break;
132+ default:
133+ printf("unexpected\n");
134+ break;
135+ }
136+</PRE>
137+
138+<li> The keyword <tt>__attribute__</tt> is handled to specify variable or
139+function attributes. The following attributes are supported:
140+ <ul>
141+ <li> <tt>aligned(n)</tt>: align data to n bytes (must be a power of two).
142+
143+ <li> <tt>section(name)</tt>: generate function or data in assembly
144+ section name (name is a string containing the section name) instead
145+ of the default section.
146+
147+ <li> <tt>unused</tt>: specify that the variable or the function is unused.
148+ </ul>
149+<BR>
150+Here are some examples:
151+<PRE>
152+ int a __attribute__ ((aligned(8), section(".mysection")));
153+</PRE>
154+<BR>
155+align variable <tt>'a'</tt> to 8 bytes and put it in section <tt>.mysection</tt>.
156+
157+<PRE>
158+ int my_add(int a, int b) __attribute__ ((section(".mycodesection")))
159+ {
160+ return a + b;
161+ }
162+</PRE>
163+<BR>
164+generate function <tt>'my_add'</tt> in section <tt>.mycodesection</tt>.
125165 </ul>
126166
127167 <h2>TinyCC extensions</h2>
@@ -138,35 +178,140 @@ indicate that you use TCC. · 10 unmodified lines
138178 <li> Binary digits can be entered (<tt>'0b101'</tt> instead of
139179 <tt>'5'</tt>).
140180
181+<li> <tt>__BOUNDS_CHECKING_ON</tt> is defined if bound checking is activated.
182+
141183 </ul>
142184
143−<h2> Command line invokation </h2>
185+<h2>TinyCC Memory and Bound checks</h2>
186+<A NAME="bounds"></a>
187+
188+This feature is activated with the <A HREF="#invoke"><tt>'-b'</tt>
189+option</A>.
190+<P>
191+Note that pointer size is <em>unchanged</em> and that code generated
192+with bound checks is <em>fully compatible</em> with unchecked
193+code. When a pointer comes from unchecked code, it is assumed to be
194+valid. Even very obscure C code with casts should work correctly.
195+</P>
196+<P> To have more information about the ideas behind this method, <A
197+HREF="http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html">check
198+here</A>.
199+</P>
200+<P>
201+Here are some examples of catched errors:
202+</P>
203+<TABLE BORDER=1>
204+<TR>
205+<TD>
206+<PRE>
207+{
208+ char tab[10];
209+ memset(tab, 0, 11);
210+}
211+</PRE>
212+</TD><TD VALIGN=TOP>Invalid range with standard string function</TD>
213+
214+<TR>
215+<TD>
216+<PRE>
217+{
218+ int tab[10];
219+ for(i=0;i<11;i++) {
220+ sum += tab[i];
221+ }
222+}
223+</PRE>
224+</TD><TD VALIGN=TOP>Bound error in global or local arrays</TD>
225+
226+<TR>
227+<TD>
228+<PRE>
229+{
230+ int *tab;
231+ tab = malloc(20 * sizeof(int));
232+ for(i=0;i<21;i++) {
233+ sum += tab4[i];
234+ }
235+ free(tab);
236+}
237+</PRE>
238+</TD><TD VALIGN=TOP>Bound error in allocated data</TD>
239+
240+<TR>
241+<TD>
242+<PRE>
243+{
244+ int *tab;
245+ tab = malloc(20 * sizeof(int));
246+ free(tab);
247+ for(i=0;i<20;i++) {
248+ sum += tab4[i];
249+ }
250+}
251+</PRE>
252+</TD><TD VALIGN=TOP>Access to a freed region</TD>
253+
254+<TR>
255+<TD>
256+<PRE>
257+{
258+ int *tab;
259+ tab = malloc(20 * sizeof(int));
260+ free(tab);
261+ free(tab);
262+}
263+</PRE>
264+</TD><TD VALIGN=TOP>Freeing an already freed region</TD>
265+
266+</TABLE>
267+
268+<h2> Command line invocation </h2>
269+<A NAME="invoke"></a>
144270
145271 <PRE>
146−usage: tcc [-Idir] [-Dsym] [-llib] [-i infile] infile [infile_args...]
272+usage: tcc [-Idir] [-Dsym[=val]] [-Usym] [-llib] [-g] [-b]
273+ [-i infile] infile [infile_args...]
147274 </PRE>
148275
149276 <table>
150277 <tr><td>'-Idir'</td>
151−<td>specify an additionnal include path. The default ones are:
278+<td>Specify an additionnal include path. The default ones are:
152279 /usr/include, /usr/lib/tcc, /usr/local/lib/tcc.</td>
153280
154−<tr><td>'-Dsym'</td>
155−<td>define preprocessor symbol 'sym' to 1.</td>
281+<tr><td>'-Dsym[=val]'</td> <td>Define preprocessor symbol 'sym' to
282+val. If val is not present, its value is '1'. NOTE: currently, only
283+integer and strings are supported as values</td>
284+
285+<tr><td>'-Usym'</td> <td>Undefine preprocessor symbol 'sym'.</td>
156286
157287 <tr><td>'-lxxx'</td>
158−<td>dynamically link your program with library
288+<td>Dynamically link your program with library
159289 libxxx.so. Standard library paths are checked, including those
160−specificed with LD_LIBRARY_PATH.</td>
290+specified with LD_LIBRARY_PATH.</td>
291+
292+<tr><td>'-g'</td>
293+<td>Generate run time debug information so that you get clear run time
294+error messages: <tt> test.c:68: in function 'test5()': dereferencing
295+invalid pointer</tt> instead of the laconic <tt>Segmentation
296+fault</tt>.
297+</td>
298+
299+<tr><td>'-b'</td> <td>Generate additionnal support code to check
300+memory allocations and array/pointer bounds. '-g' is implied. Note
301+that the generated code is slower and bigger in this case.
302+</td>
161303
162304 <tr><td>'-i file'</td>
163−<td>compile C source 'file' before main C source. With this
305+<td>Compile C source 'file' before main C source. With this
164306 command, multiple C files can be compiled and linked together.</td>
165307 </table>
308+<br>
309+Note: the <tt>'-o file'</tt> option to generate an ELF executable is
310+currently unsupported.
166311
167312 <hr>
168−Copyright (c) 2001 Fabrice Bellard <hr>
169−Fabrice Bellard - <em> fabrice.bellard at free.fr </em> - <A HREF="http://fabrice.bellard.free.fr/"> http://fabrice.bellard.free.fr/ </A> - <A HREF="http://www.tinycc.org/"> http://www.tinycc.org/ </A>
313+Copyright (c) 2001, 2002 Fabrice Bellard <hr>
314+Fabrice Bellard - <em> fabrice.bellard at free.fr </em> - <A HREF="http://bellard.org/"> http://bellard.org/ </A> - <A HREF="http://www.tinycc.org/"> http://www.tinycc.org/ </A>
170315
171316 </body>
172317 </html>

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