-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcc-doc.html
executable file
·1809 lines (1256 loc) · 43.1 KB
/
tcc-doc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<HTML>
<HEAD>
<!-- Created by texi2html 1.56k from tcc-doc.texi on 18 June 2005 -->
<TITLE>Tiny C Compiler Reference Documentation</TITLE>
</HEAD>
<BODY>
<H1>Tiny C Compiler Reference Documentation</H1>
<P>
<P><HR><P>
<H1>Table of Contents</H1>
<UL>
<LI><A NAME="TOC1" HREF="tcc-doc.html#SEC1">1. Introduction</A>
<LI><A NAME="TOC2" HREF="tcc-doc.html#SEC2">2. Command line invocation</A>
<UL>
<LI><A NAME="TOC3" HREF="tcc-doc.html#SEC3">2.1 Quick start</A>
<LI><A NAME="TOC4" HREF="tcc-doc.html#SEC4">2.2 Option summary</A>
</UL>
<LI><A NAME="TOC5" HREF="tcc-doc.html#SEC5">3. C language support</A>
<UL>
<LI><A NAME="TOC6" HREF="tcc-doc.html#SEC6">3.1 ANSI C</A>
<LI><A NAME="TOC7" HREF="tcc-doc.html#SEC7">3.2 ISOC99 extensions</A>
<LI><A NAME="TOC8" HREF="tcc-doc.html#SEC8">3.3 GNU C extensions</A>
<LI><A NAME="TOC9" HREF="tcc-doc.html#SEC9">3.4 TinyCC extensions</A>
</UL>
<LI><A NAME="TOC10" HREF="tcc-doc.html#SEC10">4. TinyCC Assembler</A>
<UL>
<LI><A NAME="TOC11" HREF="tcc-doc.html#SEC11">4.1 Syntax</A>
<LI><A NAME="TOC12" HREF="tcc-doc.html#SEC12">4.2 Expressions</A>
<LI><A NAME="TOC13" HREF="tcc-doc.html#SEC13">4.3 Labels</A>
<LI><A NAME="TOC14" HREF="tcc-doc.html#SEC14">4.4 Directives</A>
<LI><A NAME="TOC15" HREF="tcc-doc.html#SEC15">4.5 X86 Assembler</A>
</UL>
<LI><A NAME="TOC16" HREF="tcc-doc.html#SEC16">5. TinyCC Linker</A>
<UL>
<LI><A NAME="TOC17" HREF="tcc-doc.html#SEC17">5.1 ELF file generation</A>
<LI><A NAME="TOC18" HREF="tcc-doc.html#SEC18">5.2 ELF file loader</A>
<LI><A NAME="TOC19" HREF="tcc-doc.html#SEC19">5.3 PE-i386 file generation</A>
<LI><A NAME="TOC20" HREF="tcc-doc.html#SEC20">5.4 GNU Linker Scripts</A>
</UL>
<LI><A NAME="TOC21" HREF="tcc-doc.html#SEC21">6. TinyCC Memory and Bound checks</A>
<LI><A NAME="TOC22" HREF="tcc-doc.html#SEC22">7. The <CODE>libtcc</CODE> library</A>
<LI><A NAME="TOC23" HREF="tcc-doc.html#SEC23">8. Developer's guide</A>
<UL>
<LI><A NAME="TOC24" HREF="tcc-doc.html#SEC24">8.1 File reading</A>
<LI><A NAME="TOC25" HREF="tcc-doc.html#SEC25">8.2 Lexer</A>
<LI><A NAME="TOC26" HREF="tcc-doc.html#SEC26">8.3 Parser</A>
<LI><A NAME="TOC27" HREF="tcc-doc.html#SEC27">8.4 Types</A>
<LI><A NAME="TOC28" HREF="tcc-doc.html#SEC28">8.5 Symbols</A>
<LI><A NAME="TOC29" HREF="tcc-doc.html#SEC29">8.6 Sections</A>
<LI><A NAME="TOC30" HREF="tcc-doc.html#SEC30">8.7 Code generation</A>
<UL>
<LI><A NAME="TOC31" HREF="tcc-doc.html#SEC31">8.7.1 Introduction</A>
<LI><A NAME="TOC32" HREF="tcc-doc.html#SEC32">8.7.2 The value stack</A>
<LI><A NAME="TOC33" HREF="tcc-doc.html#SEC33">8.7.3 Manipulating the value stack</A>
<LI><A NAME="TOC34" HREF="tcc-doc.html#SEC34">8.7.4 CPU dependent code generation</A>
</UL>
<LI><A NAME="TOC35" HREF="tcc-doc.html#SEC35">8.8 Optimizations done</A>
</UL>
<LI><A NAME="TOC36" HREF="tcc-doc.html#SEC36">Concept Index</A>
</UL>
<P><HR><P>
<H1><A NAME="SEC1" HREF="tcc-doc.html#TOC1">1. Introduction</A></H1>
<P>
TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
compilers, it is meant to be self-relying: you do not need an
external assembler or linker because TCC does that for you.
<P>
TCC compiles so <EM>fast</EM> that even for big projects <CODE>Makefile</CODE>s may
not be necessary.
<P>
TCC not only supports ANSI C, but also most of the new ISO C99
standard and many GNUC extensions including inline assembly.
<P>
TCC can also be used to make <EM>C scripts</EM>, i.e. pieces of C source
that you run as a Perl or Python script. Compilation is so fast that
your script will be as fast as if it was an executable.
<P>
TCC can also automatically generate memory and bound checks
(see section <A HREF="tcc-doc.html#SEC21">6. TinyCC Memory and Bound checks</A>) while allowing all C pointers operations. TCC can do
these checks even if non patched libraries are used.
<P>
With <CODE>libtcc</CODE>, you can use TCC as a backend for dynamic code
generation (see section <A HREF="tcc-doc.html#SEC22">7. The <CODE>libtcc</CODE> library</A>).
<P>
TCC mainly supports the i386 target on Linux and Windows. There are alpha
ports for the ARM (<CODE>arm-tcc</CODE>) and the TMS320C67xx targets
(<CODE>c67-tcc</CODE>). More information about the ARM port is available at
<A HREF="http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html">http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html</A>.
<H1><A NAME="SEC2" HREF="tcc-doc.html#TOC2">2. Command line invocation</A></H1>
<P>
[This manual documents version 0.9.23 of the Tiny C Compiler]
<H2><A NAME="SEC3" HREF="tcc-doc.html#TOC3">2.1 Quick start</A></H2>
<PRE>
usage: tcc [options] [<VAR>infile1</VAR> <VAR>infile2</VAR>...] [<SAMP>`-run'</SAMP> <VAR>infile</VAR> <VAR>args</VAR>...]
</PRE>
<P>
TCC options are a very much like gcc options. The main difference is that TCC
can also execute directly the resulting program and give it runtime
arguments.
<P>
Here are some examples to understand the logic:
<DL COMPACT>
<DT><CODE><SAMP>`tcc -run a.c'</SAMP></CODE>
<DD>
Compile <TT>`a.c'</TT> and execute it directly
<DT><CODE><SAMP>`tcc -run a.c arg1'</SAMP></CODE>
<DD>
Compile a.c and execute it directly. arg1 is given as first argument to
the <CODE>main()</CODE> of a.c.
<DT><CODE><SAMP>`tcc a.c -run b.c arg1'</SAMP></CODE>
<DD>
Compile <TT>`a.c'</TT> and <TT>`b.c'</TT>, link them together and execute them. arg1 is given
as first argument to the <CODE>main()</CODE> of the resulting program. Because
multiple C files are specified, <SAMP>`--'</SAMP> are necessary to clearly separate the
program arguments from the TCC options.
<DT><CODE><SAMP>`tcc -o myprog a.c b.c'</SAMP></CODE>
<DD>
Compile <TT>`a.c'</TT> and <TT>`b.c'</TT>, link them and generate the executable <TT>`myprog'</TT>.
<DT><CODE><SAMP>`tcc -o myprog a.o b.o'</SAMP></CODE>
<DD>
link <TT>`a.o'</TT> and <TT>`b.o'</TT> together and generate the executable <TT>`myprog'</TT>.
<DT><CODE><SAMP>`tcc -c a.c'</SAMP></CODE>
<DD>
Compile <TT>`a.c'</TT> and generate object file <TT>`a.o'</TT>.
<DT><CODE><SAMP>`tcc -c asmfile.S'</SAMP></CODE>
<DD>
Preprocess with C preprocess and assemble <TT>`asmfile.S'</TT> and generate
object file <TT>`asmfile.o'</TT>.
<DT><CODE><SAMP>`tcc -c asmfile.s'</SAMP></CODE>
<DD>
Assemble (but not preprocess) <TT>`asmfile.s'</TT> and generate object file
<TT>`asmfile.o'</TT>.
<DT><CODE><SAMP>`tcc -r -o ab.o a.c b.c'</SAMP></CODE>
<DD>
Compile <TT>`a.c'</TT> and <TT>`b.c'</TT>, link them together and generate the object file <TT>`ab.o'</TT>.
</DL>
<P>
Scripting:
<P>
TCC can be invoked from <EM>scripts</EM>, just as shell scripts. You just
need to add <CODE>#!/usr/local/bin/tcc -run</CODE> at the start of your C source:
<PRE>
#!/usr/local/bin/tcc -run
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
</PRE>
<H2><A NAME="SEC4" HREF="tcc-doc.html#TOC4">2.2 Option summary</A></H2>
<P>
General Options:
<DL COMPACT>
<DT><SAMP>`-v'</SAMP>
<DD>
Display current TCC version.
<DT><SAMP>`-c'</SAMP>
<DD>
Generate an object file (<SAMP>`-o'</SAMP> option must also be given).
<DT><SAMP>`-o outfile'</SAMP>
<DD>
Put object file, executable, or dll into output file <TT>`outfile'</TT>.
<DT><SAMP>`-Bdir'</SAMP>
<DD>
Set the path where the tcc internal libraries can be found (default is
<TT>`PREFIX/lib/tcc'</TT>).
<DT><SAMP>`-bench'</SAMP>
<DD>
Output compilation statistics.
<DT><SAMP>`-run source [args...]'</SAMP>
<DD>
Compile file <VAR>source</VAR> and run it with the command line arguments
<VAR>args</VAR>. In order to be able to give more than one argument to a
script, several TCC options can be given <EM>after</EM> the
<SAMP>`-run'</SAMP> option, separated by spaces. Example:
<PRE>
tcc "-run -L/usr/X11R6/lib -lX11" ex4.c
</PRE>
In a script, it gives the following header:
<PRE>
#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11
#include <stdlib.h>
int main(int argc, char **argv)
{
...
}
</PRE>
</DL>
<P>
Preprocessor options:
<DL COMPACT>
<DT><SAMP>`-Idir'</SAMP>
<DD>
Specify an additional include path. Include paths are searched in the
order they are specified.
System include paths are always searched after. The default system
include paths are: <TT>`/usr/local/include'</TT>, <TT>`/usr/include'</TT>
and <TT>`PREFIX/lib/tcc/include'</TT>. (<TT>`PREFIX'</TT> is usually
<TT>`/usr'</TT> or <TT>`/usr/local'</TT>).
<DT><SAMP>`-Dsym[=val]'</SAMP>
<DD>
Define preprocessor symbol <SAMP>`sym'</SAMP> to
val. If val is not present, its value is <SAMP>`1'</SAMP>. Function-like macros can
also be defined: <SAMP>`-DF(a)=a+1'</SAMP>
<DT><SAMP>`-Usym'</SAMP>
<DD>
Undefine preprocessor symbol <SAMP>`sym'</SAMP>.
</DL>
<P>
Compilation flags:
<P>
Note: each of the following warning options has a negative form beginning with
<SAMP>`-fno-'</SAMP>.
<DL COMPACT>
<DT><SAMP>`-funsigned-char'</SAMP>
<DD>
Let the <CODE>char</CODE> type be unsigned.
<DT><SAMP>`-fsigned-char'</SAMP>
<DD>
Let the <CODE>char</CODE> type be signed.
<DT><SAMP>`-fno-common'</SAMP>
<DD>
Do not generate common symbols for uninitialized data.
<DT><SAMP>`-fleading-underscore'</SAMP>
<DD>
Add a leading underscore at the beginning of each C symbol.
</DL>
<P>
Warning options:
<DL COMPACT>
<DT><SAMP>`-w'</SAMP>
<DD>
Disable all warnings.
</DL>
<P>
Note: each of the following warning options has a negative form beginning with
<SAMP>`-Wno-'</SAMP>.
<DL COMPACT>
<DT><SAMP>`-Wimplicit-function-declaration'</SAMP>
<DD>
Warn about implicit function declaration.
<DT><SAMP>`-Wunsupported'</SAMP>
<DD>
Warn about unsupported GCC features that are ignored by TCC.
<DT><SAMP>`-Wwrite-strings'</SAMP>
<DD>
Make string constants be of type <CODE>const char *</CODE> instead of <CODE>char
*</CODE>.
<DT><SAMP>`-Werror'</SAMP>
<DD>
Abort compilation if warnings are issued.
<DT><SAMP>`-Wall'</SAMP>
<DD>
Activate all warnings, except <SAMP>`-Werror'</SAMP>, <SAMP>`-Wunusupported'</SAMP> and
<SAMP>`-Wwrite-strings'</SAMP>.
</DL>
<P>
Linker options:
<DL COMPACT>
<DT><SAMP>`-Ldir'</SAMP>
<DD>
Specify an additional static library path for the <SAMP>`-l'</SAMP> option. The
default library paths are <TT>`/usr/local/lib'</TT>, <TT>`/usr/lib'</TT> and <TT>`/lib'</TT>.
<DT><SAMP>`-lxxx'</SAMP>
<DD>
Link your program with dynamic library libxxx.so or static library
libxxx.a. The library is searched in the paths specified by the
<SAMP>`-L'</SAMP> option.
<DT><SAMP>`-shared'</SAMP>
<DD>
Generate a shared library instead of an executable (<SAMP>`-o'</SAMP> option
must also be given).
<DT><SAMP>`-static'</SAMP>
<DD>
Generate a statically linked executable (default is a shared linked
executable) (<SAMP>`-o'</SAMP> option must also be given).
<DT><SAMP>`-rdynamic'</SAMP>
<DD>
Export global symbols to the dynamic linker. It is useful when a library
opened with <CODE>dlopen()</CODE> needs to access executable symbols.
<DT><SAMP>`-r'</SAMP>
<DD>
Generate an object file combining all input files (<SAMP>`-o'</SAMP> option must
also be given).
<DT><SAMP>`-Wl,-Ttext,address'</SAMP>
<DD>
Set the start of the .text section to <VAR>address</VAR>.
<DT><SAMP>`-Wl,--oformat,fmt'</SAMP>
<DD>
Use <VAR>fmt</VAR> as output format. The supported output formats are:
<DL COMPACT>
<DT><CODE>elf32-i386</CODE>
<DD>
ELF output format (default)
<DT><CODE>binary</CODE>
<DD>
Binary image (only for executable output)
<DT><CODE>coff</CODE>
<DD>
COFF output format (only for executable output for TMS320C67xx target)
</DL>
</DL>
<P>
Debugger options:
<DL COMPACT>
<DT><SAMP>`-g'</SAMP>
<DD>
Generate run time debug information so that you get clear run time
error messages: <CODE> test.c:68: in function 'test5()': dereferencing
invalid pointer</CODE> instead of the laconic <CODE>Segmentation
fault</CODE>.
<DT><SAMP>`-b'</SAMP>
<DD>
Generate additional support code to check
memory allocations and array/pointer bounds. <SAMP>`-g'</SAMP> is implied. Note
that the generated code is slower and bigger in this case.
<DT><SAMP>`-bt N'</SAMP>
<DD>
Display N callers in stack traces. This is useful with <SAMP>`-g'</SAMP> or
<SAMP>`-b'</SAMP>.
</DL>
<P>
Note: GCC options <SAMP>`-Ox'</SAMP>, <SAMP>`-fx'</SAMP> and <SAMP>`-mx'</SAMP> are
ignored.
<H1><A NAME="SEC5" HREF="tcc-doc.html#TOC5">3. C language support</A></H1>
<H2><A NAME="SEC6" HREF="tcc-doc.html#TOC6">3.1 ANSI C</A></H2>
<P>
TCC implements all the ANSI C standard, including structure bit fields
and floating point numbers (<CODE>long double</CODE>, <CODE>double</CODE>, and
<CODE>float</CODE> fully supported).
<H2><A NAME="SEC7" HREF="tcc-doc.html#TOC7">3.2 ISOC99 extensions</A></H2>
<P>
TCC implements many features of the new C standard: ISO C99. Currently
missing items are: complex and imaginary numbers and variable length
arrays.
<P>
Currently implemented ISOC99 features:
<UL>
<LI>64 bit <CODE>long long</CODE> types are fully supported.
<LI>The boolean type <CODE>_Bool</CODE> is supported.
<LI><CODE>__func__</CODE> is a string variable containing the current
function name.
<LI>Variadic macros: <CODE>__VA_ARGS__</CODE> can be used for
function-like macros:
<PRE>
#define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)
</PRE>
<CODE>dprintf</CODE> can then be used with a variable number of parameters.
<LI>Declarations can appear anywhere in a block (as in C++).
<LI>Array and struct/union elements can be initialized in any order by
using designators:
<PRE>
struct { int x, y; } st[10] = { [0].x = 1, [0].y = 2 };
int tab[10] = { 1, 2, [5] = 5, [9] = 9};
</PRE>
<LI>Compound initializers are supported:
<PRE>
int *p = (int []){ 1, 2, 3 };
</PRE>
to initialize a pointer pointing to an initialized array. The same
works for structures and strings.
<LI>Hexadecimal floating point constants are supported:
<PRE>
double d = 0x1234p10;
</PRE>
is the same as writing
<PRE>
double d = 4771840.0;
</PRE>
<LI><CODE>inline</CODE> keyword is ignored.
<LI><CODE>restrict</CODE> keyword is ignored.
</UL>
<H2><A NAME="SEC8" HREF="tcc-doc.html#TOC8">3.3 GNU C extensions</A></H2>
<P>
<A NAME="IDX1"></A>
<A NAME="IDX2"></A>
<A NAME="IDX3"></A>
<A NAME="IDX4"></A>
<A NAME="IDX5"></A>
<A NAME="IDX6"></A>
<A NAME="IDX7"></A>
<P>
TCC implements some GNU C extensions:
<UL>
<LI>array designators can be used without '=':
<PRE>
int a[10] = { [0] 1, [5] 2, 3, 4 };
</PRE>
<LI>Structure field designators can be a label:
<PRE>
struct { int x, y; } st = { x: 1, y: 1};
</PRE>
instead of
<PRE>
struct { int x, y; } st = { .x = 1, .y = 1};
</PRE>
<LI><CODE>\e</CODE> is ASCII character 27.
<LI>case ranges : ranges can be used in <CODE>case</CODE>s:
<PRE>
switch(a) {
case 1 ... 9:
printf("range 1 to 9\n");
break;
default:
printf("unexpected\n");
break;
}
</PRE>
<LI>The keyword <CODE>__attribute__</CODE> is handled to specify variable or
function attributes. The following attributes are supported:
<UL>
<LI><CODE>aligned(n)</CODE>: align a variable or a structure field to n bytes
(must be a power of two).
<LI><CODE>packed</CODE>: force alignment of a variable or a structure field to
1.
<LI><CODE>section(name)</CODE>: generate function or data in assembly section
name (name is a string containing the section name) instead of the default
section.
<LI><CODE>unused</CODE>: specify that the variable or the function is unused.
<LI><CODE>cdecl</CODE>: use standard C calling convention (default).
<LI><CODE>stdcall</CODE>: use Pascal-like calling convention.
<LI><CODE>regparm(n)</CODE>: use fast i386 calling convention. <VAR>n</VAR> must be
between 1 and 3. The first <VAR>n</VAR> function parameters are respectively put in
registers <CODE>%eax</CODE>, <CODE>%edx</CODE> and <CODE>%ecx</CODE>.
</UL>
Here are some examples:
<PRE>
int a __attribute__ ((aligned(8), section(".mysection")));
</PRE>
align variable <CODE>a</CODE> to 8 bytes and put it in section <CODE>.mysection</CODE>.
<PRE>
int my_add(int a, int b) __attribute__ ((section(".mycodesection")))
{
return a + b;
}
</PRE>
generate function <CODE>my_add</CODE> in section <CODE>.mycodesection</CODE>.
<LI>GNU style variadic macros:
<PRE>
#define dprintf(fmt, args...) printf(fmt, ## args)
dprintf("no arg\n");
dprintf("one arg %d\n", 1);
</PRE>
<LI><CODE>__FUNCTION__</CODE> is interpreted as C99 <CODE>__func__</CODE>
(so it has not exactly the same semantics as string literal GNUC
where it is a string literal).
<LI>The <CODE>__alignof__</CODE> keyword can be used as <CODE>sizeof</CODE>
to get the alignment of a type or an expression.
<LI>The <CODE>typeof(x)</CODE> returns the type of <CODE>x</CODE>.
<CODE>x</CODE> is an expression or a type.
<LI>Computed gotos: <CODE>&&label</CODE> returns a pointer of type
<CODE>void *</CODE> on the goto label <CODE>label</CODE>. <CODE>goto *expr</CODE> can be
used to jump on the pointer resulting from <CODE>expr</CODE>.
<LI>Inline assembly with asm instruction:
<A NAME="IDX8"></A>
<A NAME="IDX9"></A>
<A NAME="IDX10"></A>
<PRE>
static 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);
}
</PRE>
<A NAME="IDX11"></A>
TCC includes its own x86 inline assembler with a <CODE>gas</CODE>-like (GNU
assembler) syntax. No intermediate files are generated. GCC 3.x named
operands are supported.
<LI><CODE>__builtin_types_compatible_p()</CODE> and <CODE>__builtin_constant_p()</CODE>
are supported.
<LI><CODE>#pragma pack</CODE> is supported for win32 compatibility.
</UL>
<H2><A NAME="SEC9" HREF="tcc-doc.html#TOC9">3.4 TinyCC extensions</A></H2>
<UL>
<LI><CODE>__TINYC__</CODE> is a predefined macro to <CODE>1</CODE> to
indicate that you use TCC.
<LI><CODE>#!</CODE> at the start of a line is ignored to allow scripting.
<LI>Binary digits can be entered (<CODE>0b101</CODE> instead of
<CODE>5</CODE>).
<LI><CODE>__BOUNDS_CHECKING_ON</CODE> is defined if bound checking is activated.
</UL>
<H1><A NAME="SEC10" HREF="tcc-doc.html#TOC10">4. TinyCC Assembler</A></H1>
<P>
Since version 0.9.16, TinyCC integrates its own assembler. TinyCC
assembler supports a gas-like syntax (GNU assembler). You can
desactivate assembler support if you want a smaller TinyCC executable
(the C compiler does not rely on the assembler).
<P>
TinyCC Assembler is used to handle files with <TT>`.S'</TT> (C
preprocessed assembler) and <TT>`.s'</TT> extensions. It is also used to
handle the GNU inline assembler with the <CODE>asm</CODE> keyword.
<H2><A NAME="SEC11" HREF="tcc-doc.html#TOC11">4.1 Syntax</A></H2>
<P>
TinyCC Assembler supports most of the gas syntax. The tokens are the
same as C.
<UL>
<LI>C and C++ comments are supported.
<LI>Identifiers are the same as C, so you cannot use '.' or '$'.
<LI>Only 32 bit integer numbers are supported.
</UL>
<H2><A NAME="SEC12" HREF="tcc-doc.html#TOC12">4.2 Expressions</A></H2>
<UL>
<LI>Integers in decimal, octal and hexa are supported.
<LI>Unary operators: +, -, ~.
<LI>Binary operators in decreasing priority order:
<OL>
<LI>*, /, %
<LI>&, |, ^
<LI>+, -
</OL>
<LI>A value is either an absolute number or a label plus an offset.
All operators accept absolute values except '+' and '-'. '+' or '-' can be
used to add an offset to a label. '-' supports two labels only if they
are the same or if they are both defined and in the same section.
</UL>
<H2><A NAME="SEC13" HREF="tcc-doc.html#TOC13">4.3 Labels</A></H2>
<UL>
<LI>All labels are considered as local, except undefined ones.
<LI>Numeric labels can be used as local <CODE>gas</CODE>-like labels.
They can be defined several times in the same source. Use 'b'
(backward) or 'f' (forward) as suffix to reference them:
<PRE>
1:
jmp 1b /* jump to '1' label before */
jmp 1f /* jump to '1' label after */
1:
</PRE>
</UL>
<H2><A NAME="SEC14" HREF="tcc-doc.html#TOC14">4.4 Directives</A></H2>
<P>
<A NAME="IDX12"></A>
<A NAME="IDX13"></A>
<A NAME="IDX14"></A>
<A NAME="IDX15"></A>
<A NAME="IDX16"></A>
<A NAME="IDX17"></A>
<A NAME="IDX18"></A>
<A NAME="IDX19"></A>
<A NAME="IDX20"></A>
<A NAME="IDX21"></A>
<A NAME="IDX22"></A>
<A NAME="IDX23"></A>
<A NAME="IDX24"></A>
<A NAME="IDX25"></A>
<A NAME="IDX26"></A>
<A NAME="IDX27"></A>
<A NAME="IDX28"></A>
<A NAME="IDX29"></A>
<A NAME="IDX30"></A>
<A NAME="IDX31"></A>
<A NAME="IDX32"></A>
<A NAME="IDX33"></A>
<A NAME="IDX34"></A>
<P>
All directives are preceeded by a '.'. The following directives are
supported:
<UL>
<LI>.align n[,value]
<LI>.skip n[,value]
<LI>.space n[,value]
<LI>.byte value1[,...]
<LI>.word value1[,...]
<LI>.short value1[,...]
<LI>.int value1[,...]
<LI>.long value1[,...]
<LI>.quad immediate_value1[,...]
<LI>.globl symbol
<LI>.global symbol
<LI>.section section
<LI>.text
<LI>.data
<LI>.bss
<LI>.fill repeat[,size[,value]]
<LI>.org n
<LI>.previous
<LI>.string string[,...]
<LI>.asciz string[,...]
<LI>.ascii string[,...]
</UL>
<H2><A NAME="SEC15" HREF="tcc-doc.html#TOC15">4.5 X86 Assembler</A></H2>
<P>
<A NAME="IDX35"></A>
<P>
All X86 opcodes are supported. Only ATT syntax is supported (source
then destination operand order). If no size suffix is given, TinyCC
tries to guess it from the operand sizes.
<P>
Currently, MMX opcodes are supported but not SSE ones.
<H1><A NAME="SEC16" HREF="tcc-doc.html#TOC16">5. TinyCC Linker</A></H1>
<P>
<A NAME="IDX36"></A>
<H2><A NAME="SEC17" HREF="tcc-doc.html#TOC17">5.1 ELF file generation</A></H2>
<P>
<A NAME="IDX37"></A>
<P>
TCC can directly output relocatable ELF files (object files),
executable ELF files and dynamic ELF libraries without relying on an
external linker.
<P>
Dynamic ELF libraries can be output but the C compiler does not generate
position independent code (PIC). It means that the dynamic library
code generated by TCC cannot be factorized among processes yet.
<P>
TCC linker eliminates unreferenced object code in libraries. A single pass is
done on the object and library list, so the order in which object files and
libraries are specified is important (same constraint as GNU ld). No grouping
options (<SAMP>`--start-group'</SAMP> and <SAMP>`--end-group'</SAMP>) are supported.
<H2><A NAME="SEC18" HREF="tcc-doc.html#TOC18">5.2 ELF file loader</A></H2>
<P>
TCC can load ELF object files, archives (.a files) and dynamic
libraries (.so).
<H2><A NAME="SEC19" HREF="tcc-doc.html#TOC19">5.3 PE-i386 file generation</A></H2>
<P>
<A NAME="IDX38"></A>
<P>
TCC for Windows supports the native Win32 executable file format (PE-i386). It
generates both EXE and DLL files. DLL symbols can be imported thru DEF files
generated with the <CODE>tiny_impdef</CODE> tool.
<P>
Currently TCC for Windows cannot generate nor read PE object files, so ELF
object files are used for that purpose. It can be a problem if
interoperability with MSVC is needed. Moreover, no leading underscore is
currently generated in the ELF symbols.
<H2><A NAME="SEC20" HREF="tcc-doc.html#TOC20">5.4 GNU Linker Scripts</A></H2>
<P>
<A NAME="IDX39"></A>
<A NAME="IDX40"></A>
<A NAME="IDX41"></A>
<A NAME="IDX42"></A>
<A NAME="IDX43"></A>
<A NAME="IDX44"></A>
<P>
Because on many Linux systems some dynamic libraries (such as
<TT>`/usr/lib/libc.so'</TT>) are in fact GNU ld link scripts (horrible!),
the TCC linker also supports a subset of GNU ld scripts.