tcc-doc.html 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
  2. <html>
  3. <!-- Created on May, 18 2009 by texi2html 1.78 -->
  4. <!--
  5. Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
  6. Karl Berry <karl@freefriends.org>
  7. Olaf Bachmann <obachman@mathematik.uni-kl.de>
  8. and many others.
  9. Maintained by: Many creative people.
  10. Send bugs and suggestions to <texi2html-bug@nongnu.org>
  11. -->
  12. <head>
  13. <title>Tiny C Compiler Reference Documentation</title>
  14. <meta name="description" content="Tiny C Compiler Reference Documentation">
  15. <meta name="keywords" content="Tiny C Compiler Reference Documentation">
  16. <meta name="resource-type" content="document">
  17. <meta name="distribution" content="global">
  18. <meta name="Generator" content="texi2html 1.78">
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <style type="text/css">
  21. <!--
  22. a.summary-letter {text-decoration: none}
  23. pre.display {font-family: serif}
  24. pre.format {font-family: serif}
  25. pre.menu-comment {font-family: serif}
  26. pre.menu-preformatted {font-family: serif}
  27. pre.smalldisplay {font-family: serif; font-size: smaller}
  28. pre.smallexample {font-size: smaller}
  29. pre.smallformat {font-family: serif; font-size: smaller}
  30. pre.smalllisp {font-size: smaller}
  31. span.roman {font-family:serif; font-weight:normal;}
  32. span.sansserif {font-family:sans-serif; font-weight:normal;}
  33. ul.toc {list-style: none}
  34. -->
  35. </style>
  36. </head>
  37. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  38. <a name="Top"></a>
  39. <a name="SEC_Top"></a>
  40. <table cellpadding="1" cellspacing="1" border="0">
  41. <tr><td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  42. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  43. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  44. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  45. </tr></table>
  46. <h1 class="settitle">Tiny C Compiler Reference Documentation</h1>
  47. <p>This manual documents version of the Tiny C Compiler.
  48. </p>
  49. <table class="menu" border="0" cellspacing="0">
  50. <tr><td align="left" valign="top"><a href="#SEC1">1. Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Introduction to tcc.
  51. </td></tr>
  52. <tr><td align="left" valign="top"><a href="#SEC2">2. Command line invocation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Invocation of tcc (command line, options).
  53. </td></tr>
  54. <tr><td align="left" valign="top"><a href="#SEC5">3. C language support</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> ANSI C and extensions.
  55. </td></tr>
  56. <tr><td align="left" valign="top"><a href="#SEC10">4. TinyCC Assembler</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Assembler syntax.
  57. </td></tr>
  58. <tr><td align="left" valign="top"><a href="#SEC16">5. TinyCC Linker</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Output file generation and supported targets.
  59. </td></tr>
  60. <tr><td align="left" valign="top"><a href="#SEC21">6. TinyCC Memory and Bound checks</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Automatic bounds-checking of C code.
  61. </td></tr>
  62. <tr><td align="left" valign="top"><a href="#SEC22">7. The <code>libtcc</code> library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The libtcc library.
  63. </td></tr>
  64. <tr><td align="left" valign="top"><a href="#SEC23">8. Developer's guide</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Guide for Developers.
  65. </td></tr>
  66. </table>
  67. <hr size="1">
  68. <a name="Introduction"></a>
  69. <a name="SEC1"></a>
  70. <table cellpadding="1" cellspacing="1" border="0">
  71. <tr><td valign="middle" align="left">[<a href="#SEC_Top" title="Previous section in reading order"> &lt; </a>]</td>
  72. <td valign="middle" align="left">[<a href="#SEC2" title="Next section in reading order"> &gt; </a>]</td>
  73. <td valign="middle" align="left"> &nbsp; </td>
  74. <td valign="middle" align="left">[ &lt;&lt; ]</td>
  75. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  76. <td valign="middle" align="left">[<a href="#SEC2" title="Next chapter"> &gt;&gt; </a>]</td>
  77. <td valign="middle" align="left"> &nbsp; </td>
  78. <td valign="middle" align="left"> &nbsp; </td>
  79. <td valign="middle" align="left"> &nbsp; </td>
  80. <td valign="middle" align="left"> &nbsp; </td>
  81. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  82. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  83. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  84. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  85. </tr></table>
  86. <h1 class="chapter"> 1. Introduction </h1>
  87. <p>TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
  88. compilers, it is meant to be self-relying: you do not need an
  89. external assembler or linker because TCC does that for you.
  90. </p>
  91. <p>TCC compiles so <em>fast</em> that even for big projects <code>Makefile</code>s may
  92. not be necessary.
  93. </p>
  94. <p>TCC not only supports ANSI C, but also most of the new ISO C99
  95. standard and many GNUC extensions including inline assembly.
  96. </p>
  97. <p>TCC can also be used to make <em>C scripts</em>, i.e. pieces of C source
  98. that you run as a Perl or Python script. Compilation is so fast that
  99. your script will be as fast as if it was an executable.
  100. </p>
  101. <p>TCC can also automatically generate memory and bound checks
  102. (see section <a href="#SEC21">TinyCC Memory and Bound checks</a>) while allowing all C pointers operations. TCC can do
  103. these checks even if non patched libraries are used.
  104. </p>
  105. <p>With <code>libtcc</code>, you can use TCC as a backend for dynamic code
  106. generation (see section <a href="#SEC22">The <code>libtcc</code> library</a>).
  107. </p>
  108. <p>TCC mainly supports the i386 target on Linux and Windows. There are alpha
  109. ports for the ARM (<code>arm-tcc</code>) and the TMS320C67xx targets
  110. (<code>c67-tcc</code>). More information about the ARM port is available at
  111. <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>.
  112. </p>
  113. <p>For usage on Windows, see also tcc-win32.txt.
  114. </p>
  115. <hr size="6">
  116. <a name="Invoke"></a>
  117. <a name="SEC2"></a>
  118. <table cellpadding="1" cellspacing="1" border="0">
  119. <tr><td valign="middle" align="left">[<a href="#SEC1" title="Previous section in reading order"> &lt; </a>]</td>
  120. <td valign="middle" align="left">[<a href="#SEC3" title="Next section in reading order"> &gt; </a>]</td>
  121. <td valign="middle" align="left"> &nbsp; </td>
  122. <td valign="middle" align="left">[<a href="#SEC1" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  123. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  124. <td valign="middle" align="left">[<a href="#SEC5" title="Next chapter"> &gt;&gt; </a>]</td>
  125. <td valign="middle" align="left"> &nbsp; </td>
  126. <td valign="middle" align="left"> &nbsp; </td>
  127. <td valign="middle" align="left"> &nbsp; </td>
  128. <td valign="middle" align="left"> &nbsp; </td>
  129. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  130. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  131. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  132. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  133. </tr></table>
  134. <h1 class="chapter"> 2. Command line invocation </h1>
  135. <hr size="6">
  136. <a name="SEC3"></a>
  137. <table cellpadding="1" cellspacing="1" border="0">
  138. <tr><td valign="middle" align="left">[<a href="#SEC2" title="Previous section in reading order"> &lt; </a>]</td>
  139. <td valign="middle" align="left">[<a href="#SEC4" title="Next section in reading order"> &gt; </a>]</td>
  140. <td valign="middle" align="left"> &nbsp; </td>
  141. <td valign="middle" align="left">[<a href="#SEC2" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  142. <td valign="middle" align="left">[<a href="#SEC2" title="Up section"> Up </a>]</td>
  143. <td valign="middle" align="left">[<a href="#SEC5" title="Next chapter"> &gt;&gt; </a>]</td>
  144. <td valign="middle" align="left"> &nbsp; </td>
  145. <td valign="middle" align="left"> &nbsp; </td>
  146. <td valign="middle" align="left"> &nbsp; </td>
  147. <td valign="middle" align="left"> &nbsp; </td>
  148. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  149. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  150. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  151. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  152. </tr></table>
  153. <h2 class="section"> 2.1 Quick start </h2>
  154. <table><tr><td>&nbsp;</td><td><pre class="example">usage: tcc [options] [<var>infile1</var> <var>infile2</var>&hellip;] [&lsquo;<samp>-run</samp>&rsquo; <var>infile</var> <var>args</var>&hellip;]
  155. </pre></td></tr></table>
  156. <p>TCC options are a very much like gcc options. The main difference is that TCC
  157. can also execute directly the resulting program and give it runtime
  158. arguments.
  159. </p>
  160. <p>Here are some examples to understand the logic:
  161. </p>
  162. <dl compact="compact">
  163. <dt> <code>&lsquo;<samp>tcc -run a.c</samp>&rsquo;</code></dt>
  164. <dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and execute it directly
  165. </p>
  166. </dd>
  167. <dt> <code>&lsquo;<samp>tcc -run a.c arg1</samp>&rsquo;</code></dt>
  168. <dd><p>Compile a.c and execute it directly. arg1 is given as first argument to
  169. the <code>main()</code> of a.c.
  170. </p>
  171. </dd>
  172. <dt> <code>&lsquo;<samp>tcc a.c -run b.c arg1</samp>&rsquo;</code></dt>
  173. <dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and &lsquo;<tt>b.c</tt>&rsquo;, link them together and execute them. arg1 is given
  174. as first argument to the <code>main()</code> of the resulting program.
  175. </p>
  176. </dd>
  177. <dt> <code>&lsquo;<samp>tcc -o myprog a.c b.c</samp>&rsquo;</code></dt>
  178. <dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and &lsquo;<tt>b.c</tt>&rsquo;, link them and generate the executable &lsquo;<tt>myprog</tt>&rsquo;.
  179. </p>
  180. </dd>
  181. <dt> <code>&lsquo;<samp>tcc -o myprog a.o b.o</samp>&rsquo;</code></dt>
  182. <dd><p>link &lsquo;<tt>a.o</tt>&rsquo; and &lsquo;<tt>b.o</tt>&rsquo; together and generate the executable &lsquo;<tt>myprog</tt>&rsquo;.
  183. </p>
  184. </dd>
  185. <dt> <code>&lsquo;<samp>tcc -c a.c</samp>&rsquo;</code></dt>
  186. <dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and generate object file &lsquo;<tt>a.o</tt>&rsquo;.
  187. </p>
  188. </dd>
  189. <dt> <code>&lsquo;<samp>tcc -c asmfile.S</samp>&rsquo;</code></dt>
  190. <dd><p>Preprocess with C preprocess and assemble &lsquo;<tt>asmfile.S</tt>&rsquo; and generate
  191. object file &lsquo;<tt>asmfile.o</tt>&rsquo;.
  192. </p>
  193. </dd>
  194. <dt> <code>&lsquo;<samp>tcc -c asmfile.s</samp>&rsquo;</code></dt>
  195. <dd><p>Assemble (but not preprocess) &lsquo;<tt>asmfile.s</tt>&rsquo; and generate object file
  196. &lsquo;<tt>asmfile.o</tt>&rsquo;.
  197. </p>
  198. </dd>
  199. <dt> <code>&lsquo;<samp>tcc -r -o ab.o a.c b.c</samp>&rsquo;</code></dt>
  200. <dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and &lsquo;<tt>b.c</tt>&rsquo;, link them together and generate the object file &lsquo;<tt>ab.o</tt>&rsquo;.
  201. </p>
  202. </dd>
  203. </dl>
  204. <p>Scripting:
  205. </p>
  206. <p>TCC can be invoked from <em>scripts</em>, just as shell scripts. You just
  207. need to add <code>#!/usr/local/bin/tcc -run</code> at the start of your C source:
  208. </p>
  209. <table><tr><td>&nbsp;</td><td><pre class="example">#!/usr/local/bin/tcc -run
  210. #include &lt;stdio.h&gt;
  211. int main()
  212. {
  213. printf(&quot;Hello World\n&quot;);
  214. return 0;
  215. }
  216. </pre></td></tr></table>
  217. <p>TCC can read C source code from <em>standard input</em> when &lsquo;<samp>-</samp>&rsquo; is used in
  218. place of &lsquo;<samp>infile</samp>&rsquo;. Example:
  219. </p>
  220. <table><tr><td>&nbsp;</td><td><pre class="example">echo 'main(){puts(&quot;hello&quot;);}' | tcc -run -
  221. </pre></td></tr></table>
  222. <hr size="6">
  223. <a name="SEC4"></a>
  224. <table cellpadding="1" cellspacing="1" border="0">
  225. <tr><td valign="middle" align="left">[<a href="#SEC3" title="Previous section in reading order"> &lt; </a>]</td>
  226. <td valign="middle" align="left">[<a href="#SEC5" title="Next section in reading order"> &gt; </a>]</td>
  227. <td valign="middle" align="left"> &nbsp; </td>
  228. <td valign="middle" align="left">[<a href="#SEC2" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  229. <td valign="middle" align="left">[<a href="#SEC2" title="Up section"> Up </a>]</td>
  230. <td valign="middle" align="left">[<a href="#SEC5" title="Next chapter"> &gt;&gt; </a>]</td>
  231. <td valign="middle" align="left"> &nbsp; </td>
  232. <td valign="middle" align="left"> &nbsp; </td>
  233. <td valign="middle" align="left"> &nbsp; </td>
  234. <td valign="middle" align="left"> &nbsp; </td>
  235. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  236. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  237. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  238. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  239. </tr></table>
  240. <h2 class="section"> 2.2 Option summary </h2>
  241. <p>General Options:
  242. </p>
  243. <dl compact="compact">
  244. <dt> &lsquo;<samp>-v</samp>&rsquo;</dt>
  245. <dd><p>Display current TCC version, increase verbosity.
  246. </p>
  247. </dd>
  248. <dt> &lsquo;<samp>-c</samp>&rsquo;</dt>
  249. <dd><p>Generate an object file (&lsquo;<samp>-o</samp>&rsquo; option must also be given).
  250. </p>
  251. </dd>
  252. <dt> &lsquo;<samp>-o outfile</samp>&rsquo;</dt>
  253. <dd><p>Put object file, executable, or dll into output file &lsquo;<tt>outfile</tt>&rsquo;.
  254. </p>
  255. </dd>
  256. <dt> &lsquo;<samp>-Bdir</samp>&rsquo;</dt>
  257. <dd><p>Set the path where the tcc internal libraries can be found (default is
  258. &lsquo;<tt>PREFIX/lib/tcc</tt>&rsquo;).
  259. </p>
  260. </dd>
  261. <dt> &lsquo;<samp>-bench</samp>&rsquo;</dt>
  262. <dd><p>Output compilation statistics.
  263. </p>
  264. </dd>
  265. <dt> &lsquo;<samp>-run source [args...]</samp>&rsquo;</dt>
  266. <dd><p>Compile file <var>source</var> and run it with the command line arguments
  267. <var>args</var>. In order to be able to give more than one argument to a
  268. script, several TCC options can be given <em>after</em> the
  269. &lsquo;<samp>-run</samp>&rsquo; option, separated by spaces. Example:
  270. </p>
  271. <table><tr><td>&nbsp;</td><td><pre class="example">tcc &quot;-run -L/usr/X11R6/lib -lX11&quot; ex4.c
  272. </pre></td></tr></table>
  273. <p>In a script, it gives the following header:
  274. </p>
  275. <table><tr><td>&nbsp;</td><td><pre class="example">#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11
  276. #include &lt;stdlib.h&gt;
  277. int main(int argc, char **argv)
  278. {
  279. ...
  280. }
  281. </pre></td></tr></table>
  282. </dd>
  283. </dl>
  284. <p>Preprocessor options:
  285. </p>
  286. <dl compact="compact">
  287. <dt> &lsquo;<samp>-Idir</samp>&rsquo;</dt>
  288. <dd><p>Specify an additional include path. Include paths are searched in the
  289. order they are specified.
  290. </p>
  291. <p>System include paths are always searched after. The default system
  292. include paths are: &lsquo;<tt>/usr/local/include</tt>&rsquo;, &lsquo;<tt>/usr/include</tt>&rsquo;
  293. and &lsquo;<tt>PREFIX/lib/tcc/include</tt>&rsquo;. (&lsquo;<tt>PREFIX</tt>&rsquo; is usually
  294. &lsquo;<tt>/usr</tt>&rsquo; or &lsquo;<tt>/usr/local</tt>&rsquo;).
  295. </p>
  296. </dd>
  297. <dt> &lsquo;<samp>-Dsym[=val]</samp>&rsquo;</dt>
  298. <dd><p>Define preprocessor symbol &lsquo;<samp>sym</samp>&rsquo; to
  299. val. If val is not present, its value is &lsquo;<samp>1</samp>&rsquo;. Function-like macros can
  300. also be defined: &lsquo;<samp>-DF(a)=a+1</samp>&rsquo;
  301. </p>
  302. </dd>
  303. <dt> &lsquo;<samp>-Usym</samp>&rsquo;</dt>
  304. <dd><p>Undefine preprocessor symbol &lsquo;<samp>sym</samp>&rsquo;.
  305. </p></dd>
  306. </dl>
  307. <p>Compilation flags:
  308. </p>
  309. <p>Note: each of the following warning options has a negative form beginning with
  310. &lsquo;<samp>-fno-</samp>&rsquo;.
  311. </p>
  312. <dl compact="compact">
  313. <dt> &lsquo;<samp>-funsigned-char</samp>&rsquo;</dt>
  314. <dd><p>Let the <code>char</code> type be unsigned.
  315. </p>
  316. </dd>
  317. <dt> &lsquo;<samp>-fsigned-char</samp>&rsquo;</dt>
  318. <dd><p>Let the <code>char</code> type be signed.
  319. </p>
  320. </dd>
  321. <dt> &lsquo;<samp>-fno-common</samp>&rsquo;</dt>
  322. <dd><p>Do not generate common symbols for uninitialized data.
  323. </p>
  324. </dd>
  325. <dt> &lsquo;<samp>-fleading-underscore</samp>&rsquo;</dt>
  326. <dd><p>Add a leading underscore at the beginning of each C symbol.
  327. </p>
  328. </dd>
  329. </dl>
  330. <p>Warning options:
  331. </p>
  332. <dl compact="compact">
  333. <dt> &lsquo;<samp>-w</samp>&rsquo;</dt>
  334. <dd><p>Disable all warnings.
  335. </p>
  336. </dd>
  337. </dl>
  338. <p>Note: each of the following warning options has a negative form beginning with
  339. &lsquo;<samp>-Wno-</samp>&rsquo;.
  340. </p>
  341. <dl compact="compact">
  342. <dt> &lsquo;<samp>-Wimplicit-function-declaration</samp>&rsquo;</dt>
  343. <dd><p>Warn about implicit function declaration.
  344. </p>
  345. </dd>
  346. <dt> &lsquo;<samp>-Wunsupported</samp>&rsquo;</dt>
  347. <dd><p>Warn about unsupported GCC features that are ignored by TCC.
  348. </p>
  349. </dd>
  350. <dt> &lsquo;<samp>-Wwrite-strings</samp>&rsquo;</dt>
  351. <dd><p>Make string constants be of type <code>const char *</code> instead of <code>char
  352. *</code>.
  353. </p>
  354. </dd>
  355. <dt> &lsquo;<samp>-Werror</samp>&rsquo;</dt>
  356. <dd><p>Abort compilation if warnings are issued.
  357. </p>
  358. </dd>
  359. <dt> &lsquo;<samp>-Wall</samp>&rsquo; </dt>
  360. <dd><p>Activate all warnings, except &lsquo;<samp>-Werror</samp>&rsquo;, &lsquo;<samp>-Wunusupported</samp>&rsquo; and
  361. &lsquo;<samp>-Wwrite-strings</samp>&rsquo;.
  362. </p>
  363. </dd>
  364. </dl>
  365. <p>Linker options:
  366. </p>
  367. <dl compact="compact">
  368. <dt> &lsquo;<samp>-Ldir</samp>&rsquo;</dt>
  369. <dd><p>Specify an additional static library path for the &lsquo;<samp>-l</samp>&rsquo; option. The
  370. default library paths are &lsquo;<tt>/usr/local/lib</tt>&rsquo;, &lsquo;<tt>/usr/lib</tt>&rsquo; and &lsquo;<tt>/lib</tt>&rsquo;.
  371. </p>
  372. </dd>
  373. <dt> &lsquo;<samp>-lxxx</samp>&rsquo;</dt>
  374. <dd><p>Link your program with dynamic library libxxx.so or static library
  375. libxxx.a. The library is searched in the paths specified by the
  376. &lsquo;<samp>-L</samp>&rsquo; option.
  377. </p>
  378. </dd>
  379. <dt> &lsquo;<samp>-shared</samp>&rsquo;</dt>
  380. <dd><p>Generate a shared library instead of an executable (&lsquo;<samp>-o</samp>&rsquo; option
  381. must also be given).
  382. </p>
  383. </dd>
  384. <dt> &lsquo;<samp>-static</samp>&rsquo;</dt>
  385. <dd><p>Generate a statically linked executable (default is a shared linked
  386. executable) (&lsquo;<samp>-o</samp>&rsquo; option must also be given).
  387. </p>
  388. </dd>
  389. <dt> &lsquo;<samp>-rdynamic</samp>&rsquo;</dt>
  390. <dd><p>Export global symbols to the dynamic linker. It is useful when a library
  391. opened with <code>dlopen()</code> needs to access executable symbols.
  392. </p>
  393. </dd>
  394. <dt> &lsquo;<samp>-r</samp>&rsquo;</dt>
  395. <dd><p>Generate an object file combining all input files (&lsquo;<samp>-o</samp>&rsquo; option must
  396. also be given).
  397. </p>
  398. </dd>
  399. <dt> &lsquo;<samp>-Wl,-Ttext,address</samp>&rsquo;</dt>
  400. <dd><p>Set the start of the .text section to <var>address</var>.
  401. </p>
  402. </dd>
  403. <dt> &lsquo;<samp>-Wl,--oformat,fmt</samp>&rsquo;</dt>
  404. <dd><p>Use <var>fmt</var> as output format. The supported output formats are:
  405. </p><dl compact="compact">
  406. <dt> <code>elf32-i386</code></dt>
  407. <dd><p>ELF output format (default)
  408. </p></dd>
  409. <dt> <code>binary</code></dt>
  410. <dd><p>Binary image (only for executable output)
  411. </p></dd>
  412. <dt> <code>coff</code></dt>
  413. <dd><p>COFF output format (only for executable output for TMS320C67xx target)
  414. </p></dd>
  415. </dl>
  416. </dd>
  417. </dl>
  418. <p>Debugger options:
  419. </p>
  420. <dl compact="compact">
  421. <dt> &lsquo;<samp>-g</samp>&rsquo;</dt>
  422. <dd><p>Generate run time debug information so that you get clear run time
  423. error messages: <code> test.c:68: in function 'test5()': dereferencing
  424. invalid pointer</code> instead of the laconic <code>Segmentation
  425. fault</code>.
  426. </p>
  427. </dd>
  428. <dt> &lsquo;<samp>-b</samp>&rsquo;</dt>
  429. <dd><p>Generate additional support code to check
  430. memory allocations and array/pointer bounds. &lsquo;<samp>-g</samp>&rsquo; is implied. Note
  431. that the generated code is slower and bigger in this case.
  432. </p>
  433. </dd>
  434. <dt> &lsquo;<samp>-bt N</samp>&rsquo;</dt>
  435. <dd><p>Display N callers in stack traces. This is useful with &lsquo;<samp>-g</samp>&rsquo; or
  436. &lsquo;<samp>-b</samp>&rsquo;.
  437. </p>
  438. </dd>
  439. </dl>
  440. <p>Note: GCC options &lsquo;<samp>-Ox</samp>&rsquo;, &lsquo;<samp>-fx</samp>&rsquo; and &lsquo;<samp>-mx</samp>&rsquo; are
  441. ignored.
  442. </p>
  443. <hr size="6">
  444. <a name="Clang"></a>
  445. <a name="SEC5"></a>
  446. <table cellpadding="1" cellspacing="1" border="0">
  447. <tr><td valign="middle" align="left">[<a href="#SEC4" title="Previous section in reading order"> &lt; </a>]</td>
  448. <td valign="middle" align="left">[<a href="#SEC6" title="Next section in reading order"> &gt; </a>]</td>
  449. <td valign="middle" align="left"> &nbsp; </td>
  450. <td valign="middle" align="left">[<a href="#SEC2" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  451. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  452. <td valign="middle" align="left">[<a href="#SEC10" title="Next chapter"> &gt;&gt; </a>]</td>
  453. <td valign="middle" align="left"> &nbsp; </td>
  454. <td valign="middle" align="left"> &nbsp; </td>
  455. <td valign="middle" align="left"> &nbsp; </td>
  456. <td valign="middle" align="left"> &nbsp; </td>
  457. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  458. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  459. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  460. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  461. </tr></table>
  462. <h1 class="chapter"> 3. C language support </h1>
  463. <hr size="6">
  464. <a name="SEC6"></a>
  465. <table cellpadding="1" cellspacing="1" border="0">
  466. <tr><td valign="middle" align="left">[<a href="#SEC5" title="Previous section in reading order"> &lt; </a>]</td>
  467. <td valign="middle" align="left">[<a href="#SEC7" title="Next section in reading order"> &gt; </a>]</td>
  468. <td valign="middle" align="left"> &nbsp; </td>
  469. <td valign="middle" align="left">[<a href="#SEC5" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  470. <td valign="middle" align="left">[<a href="#SEC5" title="Up section"> Up </a>]</td>
  471. <td valign="middle" align="left">[<a href="#SEC10" title="Next chapter"> &gt;&gt; </a>]</td>
  472. <td valign="middle" align="left"> &nbsp; </td>
  473. <td valign="middle" align="left"> &nbsp; </td>
  474. <td valign="middle" align="left"> &nbsp; </td>
  475. <td valign="middle" align="left"> &nbsp; </td>
  476. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  477. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  478. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  479. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  480. </tr></table>
  481. <h2 class="section"> 3.1 ANSI C </h2>
  482. <p>TCC implements all the ANSI C standard, including structure bit fields
  483. and floating point numbers (<code>long double</code>, <code>double</code>, and
  484. <code>float</code> fully supported).
  485. </p>
  486. <hr size="6">
  487. <a name="SEC7"></a>
  488. <table cellpadding="1" cellspacing="1" border="0">
  489. <tr><td valign="middle" align="left">[<a href="#SEC6" title="Previous section in reading order"> &lt; </a>]</td>
  490. <td valign="middle" align="left">[<a href="#SEC8" title="Next section in reading order"> &gt; </a>]</td>
  491. <td valign="middle" align="left"> &nbsp; </td>
  492. <td valign="middle" align="left">[<a href="#SEC5" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  493. <td valign="middle" align="left">[<a href="#SEC5" title="Up section"> Up </a>]</td>
  494. <td valign="middle" align="left">[<a href="#SEC10" title="Next chapter"> &gt;&gt; </a>]</td>
  495. <td valign="middle" align="left"> &nbsp; </td>
  496. <td valign="middle" align="left"> &nbsp; </td>
  497. <td valign="middle" align="left"> &nbsp; </td>
  498. <td valign="middle" align="left"> &nbsp; </td>
  499. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  500. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  501. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  502. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  503. </tr></table>
  504. <h2 class="section"> 3.2 ISOC99 extensions </h2>
  505. <p>TCC implements many features of the new C standard: ISO C99. Currently
  506. missing items are: complex and imaginary numbers and variable length
  507. arrays.
  508. </p>
  509. <p>Currently implemented ISOC99 features:
  510. </p>
  511. <ul class="toc">
  512. <li> 64 bit <code>long long</code> types are fully supported.
  513. </li><li> The boolean type <code>_Bool</code> is supported.
  514. </li><li> <code>__func__</code> is a string variable containing the current
  515. function name.
  516. </li><li> Variadic macros: <code>__VA_ARGS__</code> can be used for
  517. function-like macros:
  518. <table><tr><td>&nbsp;</td><td><pre class="example"> #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)
  519. </pre></td></tr></table>
  520. <p><code>dprintf</code> can then be used with a variable number of parameters.
  521. </p>
  522. </li><li> Declarations can appear anywhere in a block (as in C++).
  523. </li><li> Array and struct/union elements can be initialized in any order by
  524. using designators:
  525. <table><tr><td>&nbsp;</td><td><pre class="example"> struct { int x, y; } st[10] = { [0].x = 1, [0].y = 2 };
  526. int tab[10] = { 1, 2, [5] = 5, [9] = 9};
  527. </pre></td></tr></table>
  528. </li><li> Compound initializers are supported:
  529. <table><tr><td>&nbsp;</td><td><pre class="example"> int *p = (int []){ 1, 2, 3 };
  530. </pre></td></tr></table>
  531. <p>to initialize a pointer pointing to an initialized array. The same
  532. works for structures and strings.
  533. </p>
  534. </li><li> Hexadecimal floating point constants are supported:
  535. <table><tr><td>&nbsp;</td><td><pre class="example"> double d = 0x1234p10;
  536. </pre></td></tr></table>
  537. <p>is the same as writing
  538. </p><table><tr><td>&nbsp;</td><td><pre class="example"> double d = 4771840.0;
  539. </pre></td></tr></table>
  540. </li><li> <code>inline</code> keyword is ignored.
  541. </li><li> <code>restrict</code> keyword is ignored.
  542. </li></ul>
  543. <hr size="6">
  544. <a name="SEC8"></a>
  545. <table cellpadding="1" cellspacing="1" border="0">
  546. <tr><td valign="middle" align="left">[<a href="#SEC7" title="Previous section in reading order"> &lt; </a>]</td>
  547. <td valign="middle" align="left">[<a href="#SEC9" title="Next section in reading order"> &gt; </a>]</td>
  548. <td valign="middle" align="left"> &nbsp; </td>
  549. <td valign="middle" align="left">[<a href="#SEC5" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  550. <td valign="middle" align="left">[<a href="#SEC5" title="Up section"> Up </a>]</td>
  551. <td valign="middle" align="left">[<a href="#SEC10" title="Next chapter"> &gt;&gt; </a>]</td>
  552. <td valign="middle" align="left"> &nbsp; </td>
  553. <td valign="middle" align="left"> &nbsp; </td>
  554. <td valign="middle" align="left"> &nbsp; </td>
  555. <td valign="middle" align="left"> &nbsp; </td>
  556. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  557. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  558. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  559. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  560. </tr></table>
  561. <h2 class="section"> 3.3 GNU C extensions </h2>
  562. <p>TCC implements some GNU C extensions:
  563. </p>
  564. <ul class="toc">
  565. <li> array designators can be used without '=':
  566. <table><tr><td>&nbsp;</td><td><pre class="example"> int a[10] = { [0] 1, [5] 2, 3, 4 };
  567. </pre></td></tr></table>
  568. </li><li> Structure field designators can be a label:
  569. <table><tr><td>&nbsp;</td><td><pre class="example"> struct { int x, y; } st = { x: 1, y: 1};
  570. </pre></td></tr></table>
  571. <p>instead of
  572. </p><table><tr><td>&nbsp;</td><td><pre class="example"> struct { int x, y; } st = { .x = 1, .y = 1};
  573. </pre></td></tr></table>
  574. </li><li> <code>\e</code> is ASCII character 27.
  575. </li><li> case ranges : ranges can be used in <code>case</code>s:
  576. <table><tr><td>&nbsp;</td><td><pre class="example"> switch(a) {
  577. case 1 &hellip; 9:
  578. printf(&quot;range 1 to 9\n&quot;);
  579. break;
  580. default:
  581. printf(&quot;unexpected\n&quot;);
  582. break;
  583. }
  584. </pre></td></tr></table>
  585. <a name="IDX1"></a>
  586. <a name="IDX2"></a>
  587. <a name="IDX3"></a>
  588. <a name="IDX4"></a>
  589. <a name="IDX5"></a>
  590. <a name="IDX6"></a>
  591. <a name="IDX7"></a>
  592. <a name="IDX8"></a>
  593. </li><li> The keyword <code>__attribute__</code> is handled to specify variable or
  594. function attributes. The following attributes are supported:
  595. <ul class="toc">
  596. <li> <code>aligned(n)</code>: align a variable or a structure field to n bytes
  597. (must be a power of two).
  598. </li><li> <code>packed</code>: force alignment of a variable or a structure field to
  599. 1.
  600. </li><li> <code>section(name)</code>: generate function or data in assembly section
  601. name (name is a string containing the section name) instead of the default
  602. section.
  603. </li><li> <code>unused</code>: specify that the variable or the function is unused.
  604. </li><li> <code>cdecl</code>: use standard C calling convention (default).
  605. </li><li> <code>stdcall</code>: use Pascal-like calling convention.
  606. </li><li> <code>regparm(n)</code>: use fast i386 calling convention. <var>n</var> must be
  607. between 1 and 3. The first <var>n</var> function parameters are respectively put in
  608. registers <code>%eax</code>, <code>%edx</code> and <code>%ecx</code>.
  609. </li><li> <code>dllexport</code>: export function from dll/executable (win32 only)
  610. </li></ul>
  611. <p>Here are some examples:
  612. </p><table><tr><td>&nbsp;</td><td><pre class="example"> int a __attribute__ ((aligned(8), section(&quot;.mysection&quot;)));
  613. </pre></td></tr></table>
  614. <p>align variable <code>a</code> to 8 bytes and put it in section <code>.mysection</code>.
  615. </p>
  616. <table><tr><td>&nbsp;</td><td><pre class="example"> int my_add(int a, int b) __attribute__ ((section(&quot;.mycodesection&quot;)))
  617. {
  618. return a + b;
  619. }
  620. </pre></td></tr></table>
  621. <p>generate function <code>my_add</code> in section <code>.mycodesection</code>.
  622. </p>
  623. </li><li> GNU style variadic macros:
  624. <table><tr><td>&nbsp;</td><td><pre class="example"> #define dprintf(fmt, args&hellip;) printf(fmt, ## args)
  625. dprintf(&quot;no arg\n&quot;);
  626. dprintf(&quot;one arg %d\n&quot;, 1);
  627. </pre></td></tr></table>
  628. </li><li> <code>__FUNCTION__</code> is interpreted as C99 <code>__func__</code>
  629. (so it has not exactly the same semantics as string literal GNUC
  630. where it is a string literal).
  631. </li><li> The <code>__alignof__</code> keyword can be used as <code>sizeof</code>
  632. to get the alignment of a type or an expression.
  633. </li><li> The <code>typeof(x)</code> returns the type of <code>x</code>.
  634. <code>x</code> is an expression or a type.
  635. </li><li> Computed gotos: <code>&amp;&amp;label</code> returns a pointer of type
  636. <code>void *</code> on the goto label <code>label</code>. <code>goto *expr</code> can be
  637. used to jump on the pointer resulting from <code>expr</code>.
  638. </li><li> Inline assembly with asm instruction:
  639. <a name="IDX9"></a>
  640. <a name="IDX10"></a>
  641. <a name="IDX11"></a>
  642. <table><tr><td>&nbsp;</td><td><pre class="example">static inline void * my_memcpy(void * to, const void * from, size_t n)
  643. {
  644. int d0, d1, d2;
  645. __asm__ __volatile__(
  646. &quot;rep ; movsl\n\t&quot;
  647. &quot;testb $2,%b4\n\t&quot;
  648. &quot;je 1f\n\t&quot;
  649. &quot;movsw\n&quot;
  650. &quot;1:\ttestb $1,%b4\n\t&quot;
  651. &quot;je 2f\n\t&quot;
  652. &quot;movsb\n&quot;
  653. &quot;2:&quot;
  654. : &quot;=&amp;c&quot; (d0), &quot;=&amp;D&quot; (d1), &quot;=&amp;S&quot; (d2)
  655. :&quot;0&quot; (n/4), &quot;q&quot; (n),&quot;1&quot; ((long) to),&quot;2&quot; ((long) from)
  656. : &quot;memory&quot;);
  657. return (to);
  658. }
  659. </pre></td></tr></table>
  660. <a name="IDX12"></a>
  661. <p>TCC includes its own x86 inline assembler with a <code>gas</code>-like (GNU
  662. assembler) syntax. No intermediate files are generated. GCC 3.x named
  663. operands are supported.
  664. </p>
  665. </li><li> <code>__builtin_types_compatible_p()</code> and <code>__builtin_constant_p()</code>
  666. are supported.
  667. </li><li> <code>#pragma pack</code> is supported for win32 compatibility.
  668. </li></ul>
  669. <hr size="6">
  670. <a name="SEC9"></a>
  671. <table cellpadding="1" cellspacing="1" border="0">
  672. <tr><td valign="middle" align="left">[<a href="#SEC8" title="Previous section in reading order"> &lt; </a>]</td>
  673. <td valign="middle" align="left">[<a href="#SEC10" title="Next section in reading order"> &gt; </a>]</td>
  674. <td valign="middle" align="left"> &nbsp; </td>
  675. <td valign="middle" align="left">[<a href="#SEC5" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  676. <td valign="middle" align="left">[<a href="#SEC5" title="Up section"> Up </a>]</td>
  677. <td valign="middle" align="left">[<a href="#SEC10" title="Next chapter"> &gt;&gt; </a>]</td>
  678. <td valign="middle" align="left"> &nbsp; </td>
  679. <td valign="middle" align="left"> &nbsp; </td>
  680. <td valign="middle" align="left"> &nbsp; </td>
  681. <td valign="middle" align="left"> &nbsp; </td>
  682. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  683. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  684. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  685. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  686. </tr></table>
  687. <h2 class="section"> 3.4 TinyCC extensions </h2>
  688. <ul class="toc">
  689. <li> <code>__TINYC__</code> is a predefined macro to <code>1</code> to
  690. indicate that you use TCC.
  691. </li><li> <code>#!</code> at the start of a line is ignored to allow scripting.
  692. </li><li> Binary digits can be entered (<code>0b101</code> instead of
  693. <code>5</code>).
  694. </li><li> <code>__BOUNDS_CHECKING_ON</code> is defined if bound checking is activated.
  695. </li></ul>
  696. <hr size="6">
  697. <a name="asm"></a>
  698. <a name="SEC10"></a>
  699. <table cellpadding="1" cellspacing="1" border="0">
  700. <tr><td valign="middle" align="left">[<a href="#SEC9" title="Previous section in reading order"> &lt; </a>]</td>
  701. <td valign="middle" align="left">[<a href="#SEC11" title="Next section in reading order"> &gt; </a>]</td>
  702. <td valign="middle" align="left"> &nbsp; </td>
  703. <td valign="middle" align="left">[<a href="#SEC5" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  704. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  705. <td valign="middle" align="left">[<a href="#SEC16" title="Next chapter"> &gt;&gt; </a>]</td>
  706. <td valign="middle" align="left"> &nbsp; </td>
  707. <td valign="middle" align="left"> &nbsp; </td>
  708. <td valign="middle" align="left"> &nbsp; </td>
  709. <td valign="middle" align="left"> &nbsp; </td>
  710. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  711. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  712. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  713. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  714. </tr></table>
  715. <h1 class="chapter"> 4. TinyCC Assembler </h1>
  716. <p>Since version 0.9.16, TinyCC integrates its own assembler. TinyCC
  717. assembler supports a gas-like syntax (GNU assembler). You can
  718. desactivate assembler support if you want a smaller TinyCC executable
  719. (the C compiler does not rely on the assembler).
  720. </p>
  721. <p>TinyCC Assembler is used to handle files with &lsquo;<tt>.S</tt>&rsquo; (C
  722. preprocessed assembler) and &lsquo;<tt>.s</tt>&rsquo; extensions. It is also used to
  723. handle the GNU inline assembler with the <code>asm</code> keyword.
  724. </p>
  725. <hr size="6">
  726. <a name="SEC11"></a>
  727. <table cellpadding="1" cellspacing="1" border="0">
  728. <tr><td valign="middle" align="left">[<a href="#SEC10" title="Previous section in reading order"> &lt; </a>]</td>
  729. <td valign="middle" align="left">[<a href="#SEC12" title="Next section in reading order"> &gt; </a>]</td>
  730. <td valign="middle" align="left"> &nbsp; </td>
  731. <td valign="middle" align="left">[<a href="#SEC10" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  732. <td valign="middle" align="left">[<a href="#SEC10" title="Up section"> Up </a>]</td>
  733. <td valign="middle" align="left">[<a href="#SEC16" title="Next chapter"> &gt;&gt; </a>]</td>
  734. <td valign="middle" align="left"> &nbsp; </td>
  735. <td valign="middle" align="left"> &nbsp; </td>
  736. <td valign="middle" align="left"> &nbsp; </td>
  737. <td valign="middle" align="left"> &nbsp; </td>
  738. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  739. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  740. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  741. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  742. </tr></table>
  743. <h2 class="section"> 4.1 Syntax </h2>
  744. <p>TinyCC Assembler supports most of the gas syntax. The tokens are the
  745. same as C.
  746. </p>
  747. <ul class="toc">
  748. <li> C and C++ comments are supported.
  749. </li><li> Identifiers are the same as C, so you cannot use '.' or '$'.
  750. </li><li> Only 32 bit integer numbers are supported.
  751. </li></ul>
  752. <hr size="6">
  753. <a name="SEC12"></a>
  754. <table cellpadding="1" cellspacing="1" border="0">
  755. <tr><td valign="middle" align="left">[<a href="#SEC11" title="Previous section in reading order"> &lt; </a>]</td>
  756. <td valign="middle" align="left">[<a href="#SEC13" title="Next section in reading order"> &gt; </a>]</td>
  757. <td valign="middle" align="left"> &nbsp; </td>
  758. <td valign="middle" align="left">[<a href="#SEC10" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  759. <td valign="middle" align="left">[<a href="#SEC10" title="Up section"> Up </a>]</td>
  760. <td valign="middle" align="left">[<a href="#SEC16" title="Next chapter"> &gt;&gt; </a>]</td>
  761. <td valign="middle" align="left"> &nbsp; </td>
  762. <td valign="middle" align="left"> &nbsp; </td>
  763. <td valign="middle" align="left"> &nbsp; </td>
  764. <td valign="middle" align="left"> &nbsp; </td>
  765. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  766. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  767. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  768. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  769. </tr></table>
  770. <h2 class="section"> 4.2 Expressions </h2>
  771. <ul class="toc">
  772. <li> Integers in decimal, octal and hexa are supported.
  773. </li><li> Unary operators: +, -, ~.
  774. </li><li> Binary operators in decreasing priority order:
  775. <ol>
  776. <li> *, /, %
  777. </li><li> &amp;, |, ^
  778. </li><li> +, -
  779. </li></ol>
  780. </li><li> A value is either an absolute number or a label plus an offset.
  781. All operators accept absolute values except '+' and '-'. '+' or '-' can be
  782. used to add an offset to a label. '-' supports two labels only if they
  783. are the same or if they are both defined and in the same section.
  784. </li></ul>
  785. <hr size="6">
  786. <a name="SEC13"></a>
  787. <table cellpadding="1" cellspacing="1" border="0">
  788. <tr><td valign="middle" align="left">[<a href="#SEC12" title="Previous section in reading order"> &lt; </a>]</td>
  789. <td valign="middle" align="left">[<a href="#SEC14" title="Next section in reading order"> &gt; </a>]</td>
  790. <td valign="middle" align="left"> &nbsp; </td>
  791. <td valign="middle" align="left">[<a href="#SEC10" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  792. <td valign="middle" align="left">[<a href="#SEC10" title="Up section"> Up </a>]</td>
  793. <td valign="middle" align="left">[<a href="#SEC16" title="Next chapter"> &gt;&gt; </a>]</td>
  794. <td valign="middle" align="left"> &nbsp; </td>
  795. <td valign="middle" align="left"> &nbsp; </td>
  796. <td valign="middle" align="left"> &nbsp; </td>
  797. <td valign="middle" align="left"> &nbsp; </td>
  798. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  799. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  800. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  801. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  802. </tr></table>
  803. <h2 class="section"> 4.3 Labels </h2>
  804. <ul class="toc">
  805. <li> All labels are considered as local, except undefined ones.
  806. </li><li> Numeric labels can be used as local <code>gas</code>-like labels.
  807. They can be defined several times in the same source. Use 'b'
  808. (backward) or 'f' (forward) as suffix to reference them:
  809. <table><tr><td>&nbsp;</td><td><pre class="example"> 1:
  810. jmp 1b /* jump to '1' label before */
  811. jmp 1f /* jump to '1' label after */
  812. 1:
  813. </pre></td></tr></table>
  814. </li></ul>
  815. <hr size="6">
  816. <a name="SEC14"></a>
  817. <table cellpadding="1" cellspacing="1" border="0">
  818. <tr><td valign="middle" align="left">[<a href="#SEC13" title="Previous section in reading order"> &lt; </a>]</td>
  819. <td valign="middle" align="left">[<a href="#SEC15" title="Next section in reading order"> &gt; </a>]</td>
  820. <td valign="middle" align="left"> &nbsp; </td>
  821. <td valign="middle" align="left">[<a href="#SEC10" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  822. <td valign="middle" align="left">[<a href="#SEC10" title="Up section"> Up </a>]</td>
  823. <td valign="middle" align="left">[<a href="#SEC16" title="Next chapter"> &gt;&gt; </a>]</td>
  824. <td valign="middle" align="left"> &nbsp; </td>
  825. <td valign="middle" align="left"> &nbsp; </td>
  826. <td valign="middle" align="left"> &nbsp; </td>
  827. <td valign="middle" align="left"> &nbsp; </td>
  828. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  829. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  830. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  831. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  832. </tr></table>
  833. <h2 class="section"> 4.4 Directives </h2>
  834. <p>All directives are preceded by a '.'. The following directives are
  835. supported:
  836. </p>
  837. <ul class="toc">
  838. <li> .align n[,value]
  839. </li><li> .skip n[,value]
  840. </li><li> .space n[,value]
  841. </li><li> .byte value1[,...]
  842. </li><li> .word value1[,...]
  843. </li><li> .short value1[,...]
  844. </li><li> .int value1[,...]
  845. </li><li> .long value1[,...]
  846. </li><li> .quad immediate_value1[,...]
  847. </li><li> .globl symbol
  848. </li><li> .global symbol
  849. </li><li> .section section
  850. </li><li> .text
  851. </li><li> .data
  852. </li><li> .bss
  853. </li><li> .fill repeat[,size[,value]]
  854. </li><li> .org n
  855. </li><li> .previous
  856. </li><li> .string string[,...]
  857. </li><li> .asciz string[,...]
  858. </li><li> .ascii string[,...]
  859. </li></ul>
  860. <hr size="6">
  861. <a name="SEC15"></a>
  862. <table cellpadding="1" cellspacing="1" border="0">
  863. <tr><td valign="middle" align="left">[<a href="#SEC14" title="Previous section in reading order"> &lt; </a>]</td>
  864. <td valign="middle" align="left">[<a href="#SEC16" title="Next section in reading order"> &gt; </a>]</td>
  865. <td valign="middle" align="left"> &nbsp; </td>
  866. <td valign="middle" align="left">[<a href="#SEC10" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  867. <td valign="middle" align="left">[<a href="#SEC10" title="Up section"> Up </a>]</td>
  868. <td valign="middle" align="left">[<a href="#SEC16" title="Next chapter"> &gt;&gt; </a>]</td>
  869. <td valign="middle" align="left"> &nbsp; </td>
  870. <td valign="middle" align="left"> &nbsp; </td>
  871. <td valign="middle" align="left"> &nbsp; </td>
  872. <td valign="middle" align="left"> &nbsp; </td>
  873. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  874. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  875. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  876. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  877. </tr></table>
  878. <h2 class="section"> 4.5 X86 Assembler </h2>
  879. <p>All X86 opcodes are supported. Only ATT syntax is supported (source
  880. then destination operand order). If no size suffix is given, TinyCC
  881. tries to guess it from the operand sizes.
  882. </p>
  883. <p>Currently, MMX opcodes are supported but not SSE ones.
  884. </p>
  885. <hr size="6">
  886. <a name="linker"></a>
  887. <a name="SEC16"></a>
  888. <table cellpadding="1" cellspacing="1" border="0">
  889. <tr><td valign="middle" align="left">[<a href="#SEC15" title="Previous section in reading order"> &lt; </a>]</td>
  890. <td valign="middle" align="left">[<a href="#SEC17" title="Next section in reading order"> &gt; </a>]</td>
  891. <td valign="middle" align="left"> &nbsp; </td>
  892. <td valign="middle" align="left">[<a href="#SEC10" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  893. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  894. <td valign="middle" align="left">[<a href="#SEC21" title="Next chapter"> &gt;&gt; </a>]</td>
  895. <td valign="middle" align="left"> &nbsp; </td>
  896. <td valign="middle" align="left"> &nbsp; </td>
  897. <td valign="middle" align="left"> &nbsp; </td>
  898. <td valign="middle" align="left"> &nbsp; </td>
  899. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  900. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  901. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  902. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  903. </tr></table>
  904. <h1 class="chapter"> 5. TinyCC Linker </h1>
  905. <hr size="6">
  906. <a name="SEC17"></a>
  907. <table cellpadding="1" cellspacing="1" border="0">
  908. <tr><td valign="middle" align="left">[<a href="#SEC16" title="Previous section in reading order"> &lt; </a>]</td>
  909. <td valign="middle" align="left">[<a href="#SEC18" title="Next section in reading order"> &gt; </a>]</td>
  910. <td valign="middle" align="left"> &nbsp; </td>
  911. <td valign="middle" align="left">[<a href="#SEC16" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  912. <td valign="middle" align="left">[<a href="#SEC16" title="Up section"> Up </a>]</td>
  913. <td valign="middle" align="left">[<a href="#SEC21" title="Next chapter"> &gt;&gt; </a>]</td>
  914. <td valign="middle" align="left"> &nbsp; </td>
  915. <td valign="middle" align="left"> &nbsp; </td>
  916. <td valign="middle" align="left"> &nbsp; </td>
  917. <td valign="middle" align="left"> &nbsp; </td>
  918. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  919. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  920. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  921. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  922. </tr></table>
  923. <h2 class="section"> 5.1 ELF file generation </h2>
  924. <p>TCC can directly output relocatable ELF files (object files),
  925. executable ELF files and dynamic ELF libraries without relying on an
  926. external linker.
  927. </p>
  928. <p>Dynamic ELF libraries can be output but the C compiler does not generate
  929. position independent code (PIC). It means that the dynamic library
  930. code generated by TCC cannot be factorized among processes yet.
  931. </p>
  932. <p>TCC linker eliminates unreferenced object code in libraries. A single pass is
  933. done on the object and library list, so the order in which object files and
  934. libraries are specified is important (same constraint as GNU ld). No grouping
  935. options (&lsquo;<samp>--start-group</samp>&rsquo; and &lsquo;<samp>--end-group</samp>&rsquo;) are supported.
  936. </p>
  937. <hr size="6">
  938. <a name="SEC18"></a>
  939. <table cellpadding="1" cellspacing="1" border="0">
  940. <tr><td valign="middle" align="left">[<a href="#SEC17" title="Previous section in reading order"> &lt; </a>]</td>
  941. <td valign="middle" align="left">[<a href="#SEC19" title="Next section in reading order"> &gt; </a>]</td>
  942. <td valign="middle" align="left"> &nbsp; </td>
  943. <td valign="middle" align="left">[<a href="#SEC16" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  944. <td valign="middle" align="left">[<a href="#SEC16" title="Up section"> Up </a>]</td>
  945. <td valign="middle" align="left">[<a href="#SEC21" title="Next chapter"> &gt;&gt; </a>]</td>
  946. <td valign="middle" align="left"> &nbsp; </td>
  947. <td valign="middle" align="left"> &nbsp; </td>
  948. <td valign="middle" align="left"> &nbsp; </td>
  949. <td valign="middle" align="left"> &nbsp; </td>
  950. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  951. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  952. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  953. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  954. </tr></table>
  955. <h2 class="section"> 5.2 ELF file loader </h2>
  956. <p>TCC can load ELF object files, archives (.a files) and dynamic
  957. libraries (.so).
  958. </p>
  959. <hr size="6">
  960. <a name="SEC19"></a>
  961. <table cellpadding="1" cellspacing="1" border="0">
  962. <tr><td valign="middle" align="left">[<a href="#SEC18" title="Previous section in reading order"> &lt; </a>]</td>
  963. <td valign="middle" align="left">[<a href="#SEC20" title="Next section in reading order"> &gt; </a>]</td>
  964. <td valign="middle" align="left"> &nbsp; </td>
  965. <td valign="middle" align="left">[<a href="#SEC16" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  966. <td valign="middle" align="left">[<a href="#SEC16" title="Up section"> Up </a>]</td>
  967. <td valign="middle" align="left">[<a href="#SEC21" title="Next chapter"> &gt;&gt; </a>]</td>
  968. <td valign="middle" align="left"> &nbsp; </td>
  969. <td valign="middle" align="left"> &nbsp; </td>
  970. <td valign="middle" align="left"> &nbsp; </td>
  971. <td valign="middle" align="left"> &nbsp; </td>
  972. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  973. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  974. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  975. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  976. </tr></table>
  977. <h2 class="section"> 5.3 PE-i386 file generation </h2>
  978. <p>TCC for Windows supports the native Win32 executable file format (PE-i386). It
  979. generates EXE files (console and gui) and DLL files.
  980. </p>
  981. <p>For usage on Windows, see also tcc-win32.txt.
  982. </p>
  983. <hr size="6">
  984. <a name="SEC20"></a>
  985. <table cellpadding="1" cellspacing="1" border="0">
  986. <tr><td valign="middle" align="left">[<a href="#SEC19" title="Previous section in reading order"> &lt; </a>]</td>
  987. <td valign="middle" align="left">[<a href="#SEC21" title="Next section in reading order"> &gt; </a>]</td>
  988. <td valign="middle" align="left"> &nbsp; </td>
  989. <td valign="middle" align="left">[<a href="#SEC16" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  990. <td valign="middle" align="left">[<a href="#SEC16" title="Up section"> Up </a>]</td>
  991. <td valign="middle" align="left">[<a href="#SEC21" title="Next chapter"> &gt;&gt; </a>]</td>
  992. <td valign="middle" align="left"> &nbsp; </td>
  993. <td valign="middle" align="left"> &nbsp; </td>
  994. <td valign="middle" align="left"> &nbsp; </td>
  995. <td valign="middle" align="left"> &nbsp; </td>
  996. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  997. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  998. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  999. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1000. </tr></table>
  1001. <h2 class="section"> 5.4 GNU Linker Scripts </h2>
  1002. <p>Because on many Linux systems some dynamic libraries (such as
  1003. &lsquo;<tt>/usr/lib/libc.so</tt>&rsquo;) are in fact GNU ld link scripts (horrible!),
  1004. the TCC linker also supports a subset of GNU ld scripts.
  1005. </p>
  1006. <p>The <code>GROUP</code> and <code>FILE</code> commands are supported. <code>OUTPUT_FORMAT</code>
  1007. and <code>TARGET</code> are ignored.
  1008. </p>
  1009. <p>Example from &lsquo;<tt>/usr/lib/libc.so</tt>&rsquo;:
  1010. </p><table><tr><td>&nbsp;</td><td><pre class="example">/* GNU ld script
  1011. Use the shared library, but some functions are only in
  1012. the static library, so try that secondarily. */
  1013. GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )
  1014. </pre></td></tr></table>
  1015. <hr size="6">
  1016. <a name="Bounds"></a>
  1017. <a name="SEC21"></a>
  1018. <table cellpadding="1" cellspacing="1" border="0">
  1019. <tr><td valign="middle" align="left">[<a href="#SEC20" title="Previous section in reading order"> &lt; </a>]</td>
  1020. <td valign="middle" align="left">[<a href="#SEC22" title="Next section in reading order"> &gt; </a>]</td>
  1021. <td valign="middle" align="left"> &nbsp; </td>
  1022. <td valign="middle" align="left">[<a href="#SEC16" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1023. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  1024. <td valign="middle" align="left">[<a href="#SEC22" title="Next chapter"> &gt;&gt; </a>]</td>
  1025. <td valign="middle" align="left"> &nbsp; </td>
  1026. <td valign="middle" align="left"> &nbsp; </td>
  1027. <td valign="middle" align="left"> &nbsp; </td>
  1028. <td valign="middle" align="left"> &nbsp; </td>
  1029. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1030. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1031. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1032. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1033. </tr></table>
  1034. <h1 class="chapter"> 6. TinyCC Memory and Bound checks </h1>
  1035. <p>This feature is activated with the &lsquo;<samp>-b</samp>&rsquo; (see section <a href="#SEC2">Command line invocation</a>).
  1036. </p>
  1037. <p>Note that pointer size is <em>unchanged</em> and that code generated
  1038. with bound checks is <em>fully compatible</em> with unchecked
  1039. code. When a pointer comes from unchecked code, it is assumed to be
  1040. valid. Even very obscure C code with casts should work correctly.
  1041. </p>
  1042. <p>For more information about the ideas behind this method, see
  1043. <a href="http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html">http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html</a>.
  1044. </p>
  1045. <p>Here are some examples of caught errors:
  1046. </p>
  1047. <dl compact="compact">
  1048. <dt> Invalid range with standard string function:</dt>
  1049. <dd><table><tr><td>&nbsp;</td><td><pre class="example">{
  1050. char tab[10];
  1051. memset(tab, 0, 11);
  1052. }
  1053. </pre></td></tr></table>
  1054. </dd>
  1055. <dt> Out of bounds-error in global or local arrays:</dt>
  1056. <dd><table><tr><td>&nbsp;</td><td><pre class="example">{
  1057. int tab[10];
  1058. for(i=0;i&lt;11;i++) {
  1059. sum += tab[i];
  1060. }
  1061. }
  1062. </pre></td></tr></table>
  1063. </dd>
  1064. <dt> Out of bounds-error in malloc'ed data:</dt>
  1065. <dd><table><tr><td>&nbsp;</td><td><pre class="example">{
  1066. int *tab;
  1067. tab = malloc(20 * sizeof(int));
  1068. for(i=0;i&lt;21;i++) {
  1069. sum += tab4[i];
  1070. }
  1071. free(tab);
  1072. }
  1073. </pre></td></tr></table>
  1074. </dd>
  1075. <dt> Access of freed memory:</dt>
  1076. <dd><table><tr><td>&nbsp;</td><td><pre class="example">{
  1077. int *tab;
  1078. tab = malloc(20 * sizeof(int));
  1079. free(tab);
  1080. for(i=0;i&lt;20;i++) {
  1081. sum += tab4[i];
  1082. }
  1083. }
  1084. </pre></td></tr></table>
  1085. </dd>
  1086. <dt> Double free:</dt>
  1087. <dd><table><tr><td>&nbsp;</td><td><pre class="example">{
  1088. int *tab;
  1089. tab = malloc(20 * sizeof(int));
  1090. free(tab);
  1091. free(tab);
  1092. }
  1093. </pre></td></tr></table>
  1094. </dd>
  1095. </dl>
  1096. <hr size="6">
  1097. <a name="Libtcc"></a>
  1098. <a name="SEC22"></a>
  1099. <table cellpadding="1" cellspacing="1" border="0">
  1100. <tr><td valign="middle" align="left">[<a href="#SEC21" title="Previous section in reading order"> &lt; </a>]</td>
  1101. <td valign="middle" align="left">[<a href="#SEC23" title="Next section in reading order"> &gt; </a>]</td>
  1102. <td valign="middle" align="left"> &nbsp; </td>
  1103. <td valign="middle" align="left">[<a href="#SEC21" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1104. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  1105. <td valign="middle" align="left">[<a href="#SEC23" title="Next chapter"> &gt;&gt; </a>]</td>
  1106. <td valign="middle" align="left"> &nbsp; </td>
  1107. <td valign="middle" align="left"> &nbsp; </td>
  1108. <td valign="middle" align="left"> &nbsp; </td>
  1109. <td valign="middle" align="left"> &nbsp; </td>
  1110. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1111. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1112. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1113. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1114. </tr></table>
  1115. <h1 class="chapter"> 7. The <code>libtcc</code> library </h1>
  1116. <p>The <code>libtcc</code> library enables you to use TCC as a backend for
  1117. dynamic code generation.
  1118. </p>
  1119. <p>Read the &lsquo;<tt>libtcc.h</tt>&rsquo; to have an overview of the API. Read
  1120. &lsquo;<tt>libtcc_test.c</tt>&rsquo; to have a very simple example.
  1121. </p>
  1122. <p>The idea consists in giving a C string containing the program you want
  1123. to compile directly to <code>libtcc</code>. Then you can access to any global
  1124. symbol (function or variable) defined.
  1125. </p>
  1126. <hr size="6">
  1127. <a name="devel"></a>
  1128. <a name="SEC23"></a>
  1129. <table cellpadding="1" cellspacing="1" border="0">
  1130. <tr><td valign="middle" align="left">[<a href="#SEC22" title="Previous section in reading order"> &lt; </a>]</td>
  1131. <td valign="middle" align="left">[<a href="#SEC24" title="Next section in reading order"> &gt; </a>]</td>
  1132. <td valign="middle" align="left"> &nbsp; </td>
  1133. <td valign="middle" align="left">[<a href="#SEC22" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1134. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  1135. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1136. <td valign="middle" align="left"> &nbsp; </td>
  1137. <td valign="middle" align="left"> &nbsp; </td>
  1138. <td valign="middle" align="left"> &nbsp; </td>
  1139. <td valign="middle" align="left"> &nbsp; </td>
  1140. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1141. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1142. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1143. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1144. </tr></table>
  1145. <h1 class="chapter"> 8. Developer's guide </h1>
  1146. <p>This chapter gives some hints to understand how TCC works. You can skip
  1147. it if you do not intend to modify the TCC code.
  1148. </p>
  1149. <hr size="6">
  1150. <a name="SEC24"></a>
  1151. <table cellpadding="1" cellspacing="1" border="0">
  1152. <tr><td valign="middle" align="left">[<a href="#SEC23" title="Previous section in reading order"> &lt; </a>]</td>
  1153. <td valign="middle" align="left">[<a href="#SEC25" title="Next section in reading order"> &gt; </a>]</td>
  1154. <td valign="middle" align="left"> &nbsp; </td>
  1155. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1156. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1157. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1158. <td valign="middle" align="left"> &nbsp; </td>
  1159. <td valign="middle" align="left"> &nbsp; </td>
  1160. <td valign="middle" align="left"> &nbsp; </td>
  1161. <td valign="middle" align="left"> &nbsp; </td>
  1162. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1163. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1164. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1165. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1166. </tr></table>
  1167. <h2 class="section"> 8.1 File reading </h2>
  1168. <p>The <code>BufferedFile</code> structure contains the context needed to read a
  1169. file, including the current line number. <code>tcc_open()</code> opens a new
  1170. file and <code>tcc_close()</code> closes it. <code>inp()</code> returns the next
  1171. character.
  1172. </p>
  1173. <hr size="6">
  1174. <a name="SEC25"></a>
  1175. <table cellpadding="1" cellspacing="1" border="0">
  1176. <tr><td valign="middle" align="left">[<a href="#SEC24" title="Previous section in reading order"> &lt; </a>]</td>
  1177. <td valign="middle" align="left">[<a href="#SEC26" title="Next section in reading order"> &gt; </a>]</td>
  1178. <td valign="middle" align="left"> &nbsp; </td>
  1179. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1180. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1181. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1182. <td valign="middle" align="left"> &nbsp; </td>
  1183. <td valign="middle" align="left"> &nbsp; </td>
  1184. <td valign="middle" align="left"> &nbsp; </td>
  1185. <td valign="middle" align="left"> &nbsp; </td>
  1186. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1187. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1188. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1189. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1190. </tr></table>
  1191. <h2 class="section"> 8.2 Lexer </h2>
  1192. <p><code>next()</code> reads the next token in the current
  1193. file. <code>next_nomacro()</code> reads the next token without macro
  1194. expansion.
  1195. </p>
  1196. <p><code>tok</code> contains the current token (see <code>TOK_xxx</code>)
  1197. constants. Identifiers and keywords are also keywords. <code>tokc</code>
  1198. contains additional infos about the token (for example a constant value
  1199. if number or string token).
  1200. </p>
  1201. <hr size="6">
  1202. <a name="SEC26"></a>
  1203. <table cellpadding="1" cellspacing="1" border="0">
  1204. <tr><td valign="middle" align="left">[<a href="#SEC25" title="Previous section in reading order"> &lt; </a>]</td>
  1205. <td valign="middle" align="left">[<a href="#SEC27" title="Next section in reading order"> &gt; </a>]</td>
  1206. <td valign="middle" align="left"> &nbsp; </td>
  1207. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1208. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1209. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1210. <td valign="middle" align="left"> &nbsp; </td>
  1211. <td valign="middle" align="left"> &nbsp; </td>
  1212. <td valign="middle" align="left"> &nbsp; </td>
  1213. <td valign="middle" align="left"> &nbsp; </td>
  1214. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1215. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1216. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1217. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1218. </tr></table>
  1219. <h2 class="section"> 8.3 Parser </h2>
  1220. <p>The parser is hardcoded (yacc is not necessary). It does only one pass,
  1221. except:
  1222. </p>
  1223. <ul class="toc">
  1224. <li> For initialized arrays with unknown size, a first pass
  1225. is done to count the number of elements.
  1226. </li><li> For architectures where arguments are evaluated in
  1227. reverse order, a first pass is done to reverse the argument order.
  1228. </li></ul>
  1229. <hr size="6">
  1230. <a name="SEC27"></a>
  1231. <table cellpadding="1" cellspacing="1" border="0">
  1232. <tr><td valign="middle" align="left">[<a href="#SEC26" title="Previous section in reading order"> &lt; </a>]</td>
  1233. <td valign="middle" align="left">[<a href="#SEC28" title="Next section in reading order"> &gt; </a>]</td>
  1234. <td valign="middle" align="left"> &nbsp; </td>
  1235. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1236. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1237. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1238. <td valign="middle" align="left"> &nbsp; </td>
  1239. <td valign="middle" align="left"> &nbsp; </td>
  1240. <td valign="middle" align="left"> &nbsp; </td>
  1241. <td valign="middle" align="left"> &nbsp; </td>
  1242. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1243. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1244. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1245. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1246. </tr></table>
  1247. <h2 class="section"> 8.4 Types </h2>
  1248. <p>The types are stored in a single 'int' variable. It was chosen in the
  1249. first stages of development when tcc was much simpler. Now, it may not
  1250. be the best solution.
  1251. </p>
  1252. <table><tr><td>&nbsp;</td><td><pre class="example">#define VT_INT 0 /* integer type */
  1253. #define VT_BYTE 1 /* signed byte type */
  1254. #define VT_SHORT 2 /* short type */
  1255. #define VT_VOID 3 /* void type */
  1256. #define VT_PTR 4 /* pointer */
  1257. #define VT_ENUM 5 /* enum definition */
  1258. #define VT_FUNC 6 /* function type */
  1259. #define VT_STRUCT 7 /* struct/union definition */
  1260. #define VT_FLOAT 8 /* IEEE float */
  1261. #define VT_DOUBLE 9 /* IEEE double */
  1262. #define VT_LDOUBLE 10 /* IEEE long double */
  1263. #define VT_BOOL 11 /* ISOC99 boolean type */
  1264. #define VT_LLONG 12 /* 64 bit integer */
  1265. #define VT_LONG 13 /* long integer (NEVER USED as type, only
  1266. during parsing) */
  1267. #define VT_BTYPE 0x000f /* mask for basic type */
  1268. #define VT_UNSIGNED 0x0010 /* unsigned type */
  1269. #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
  1270. #define VT_BITFIELD 0x0040 /* bitfield modifier */
  1271. #define VT_STRUCT_SHIFT 16 /* structure/enum name shift (16 bits left) */
  1272. </pre></td></tr></table>
  1273. <p>When a reference to another type is needed (for pointers, functions and
  1274. structures), the <code>32 - VT_STRUCT_SHIFT</code> high order bits are used to
  1275. store an identifier reference.
  1276. </p>
  1277. <p>The <code>VT_UNSIGNED</code> flag can be set for chars, shorts, ints and long
  1278. longs.
  1279. </p>
  1280. <p>Arrays are considered as pointers <code>VT_PTR</code> with the flag
  1281. <code>VT_ARRAY</code> set.
  1282. </p>
  1283. <p>The <code>VT_BITFIELD</code> flag can be set for chars, shorts, ints and long
  1284. longs. If it is set, then the bitfield position is stored from bits
  1285. VT_STRUCT_SHIFT to VT_STRUCT_SHIFT + 5 and the bit field size is stored
  1286. from bits VT_STRUCT_SHIFT + 6 to VT_STRUCT_SHIFT + 11.
  1287. </p>
  1288. <p><code>VT_LONG</code> is never used except during parsing.
  1289. </p>
  1290. <p>During parsing, the storage of an object is also stored in the type
  1291. integer:
  1292. </p>
  1293. <table><tr><td>&nbsp;</td><td><pre class="example">#define VT_EXTERN 0x00000080 /* extern definition */
  1294. #define VT_STATIC 0x00000100 /* static variable */
  1295. #define VT_TYPEDEF 0x00000200 /* typedef definition */
  1296. </pre></td></tr></table>
  1297. <hr size="6">
  1298. <a name="SEC28"></a>
  1299. <table cellpadding="1" cellspacing="1" border="0">
  1300. <tr><td valign="middle" align="left">[<a href="#SEC27" title="Previous section in reading order"> &lt; </a>]</td>
  1301. <td valign="middle" align="left">[<a href="#SEC29" title="Next section in reading order"> &gt; </a>]</td>
  1302. <td valign="middle" align="left"> &nbsp; </td>
  1303. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1304. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1305. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1306. <td valign="middle" align="left"> &nbsp; </td>
  1307. <td valign="middle" align="left"> &nbsp; </td>
  1308. <td valign="middle" align="left"> &nbsp; </td>
  1309. <td valign="middle" align="left"> &nbsp; </td>
  1310. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1311. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1312. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1313. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1314. </tr></table>
  1315. <h2 class="section"> 8.5 Symbols </h2>
  1316. <p>All symbols are stored in hashed symbol stacks. Each symbol stack
  1317. contains <code>Sym</code> structures.
  1318. </p>
  1319. <p><code>Sym.v</code> contains the symbol name (remember
  1320. an idenfier is also a token, so a string is never necessary to store
  1321. it). <code>Sym.t</code> gives the type of the symbol. <code>Sym.r</code> is usually
  1322. the register in which the corresponding variable is stored. <code>Sym.c</code> is
  1323. usually a constant associated to the symbol.
  1324. </p>
  1325. <p>Four main symbol stacks are defined:
  1326. </p>
  1327. <dl compact="compact">
  1328. <dt> <code>define_stack</code></dt>
  1329. <dd><p>for the macros (<code>#define</code>s).
  1330. </p>
  1331. </dd>
  1332. <dt> <code>global_stack</code></dt>
  1333. <dd><p>for the global variables, functions and types.
  1334. </p>
  1335. </dd>
  1336. <dt> <code>local_stack</code></dt>
  1337. <dd><p>for the local variables, functions and types.
  1338. </p>
  1339. </dd>
  1340. <dt> <code>global_label_stack</code></dt>
  1341. <dd><p>for the local labels (for <code>goto</code>).
  1342. </p>
  1343. </dd>
  1344. <dt> <code>label_stack</code></dt>
  1345. <dd><p>for GCC block local labels (see the <code>__label__</code> keyword).
  1346. </p>
  1347. </dd>
  1348. </dl>
  1349. <p><code>sym_push()</code> is used to add a new symbol in the local symbol
  1350. stack. If no local symbol stack is active, it is added in the global
  1351. symbol stack.
  1352. </p>
  1353. <p><code>sym_pop(st,b)</code> pops symbols from the symbol stack <var>st</var> until
  1354. the symbol <var>b</var> is on the top of stack. If <var>b</var> is NULL, the stack
  1355. is emptied.
  1356. </p>
  1357. <p><code>sym_find(v)</code> return the symbol associated to the identifier
  1358. <var>v</var>. The local stack is searched first from top to bottom, then the
  1359. global stack.
  1360. </p>
  1361. <hr size="6">
  1362. <a name="SEC29"></a>
  1363. <table cellpadding="1" cellspacing="1" border="0">
  1364. <tr><td valign="middle" align="left">[<a href="#SEC28" title="Previous section in reading order"> &lt; </a>]</td>
  1365. <td valign="middle" align="left">[<a href="#SEC30" title="Next section in reading order"> &gt; </a>]</td>
  1366. <td valign="middle" align="left"> &nbsp; </td>
  1367. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1368. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1369. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1370. <td valign="middle" align="left"> &nbsp; </td>
  1371. <td valign="middle" align="left"> &nbsp; </td>
  1372. <td valign="middle" align="left"> &nbsp; </td>
  1373. <td valign="middle" align="left"> &nbsp; </td>
  1374. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1375. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1376. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1377. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1378. </tr></table>
  1379. <h2 class="section"> 8.6 Sections </h2>
  1380. <p>The generated code and datas are written in sections. The structure
  1381. <code>Section</code> contains all the necessary information for a given
  1382. section. <code>new_section()</code> creates a new section. ELF file semantics
  1383. is assumed for each section.
  1384. </p>
  1385. <p>The following sections are predefined:
  1386. </p>
  1387. <dl compact="compact">
  1388. <dt> <code>text_section</code></dt>
  1389. <dd><p>is the section containing the generated code. <var>ind</var> contains the
  1390. current position in the code section.
  1391. </p>
  1392. </dd>
  1393. <dt> <code>data_section</code></dt>
  1394. <dd><p>contains initialized data
  1395. </p>
  1396. </dd>
  1397. <dt> <code>bss_section</code></dt>
  1398. <dd><p>contains uninitialized data
  1399. </p>
  1400. </dd>
  1401. <dt> <code>bounds_section</code></dt>
  1402. <dt> <code>lbounds_section</code></dt>
  1403. <dd><p>are used when bound checking is activated
  1404. </p>
  1405. </dd>
  1406. <dt> <code>stab_section</code></dt>
  1407. <dt> <code>stabstr_section</code></dt>
  1408. <dd><p>are used when debugging is activated to store debug information
  1409. </p>
  1410. </dd>
  1411. <dt> <code>symtab_section</code></dt>
  1412. <dt> <code>strtab_section</code></dt>
  1413. <dd><p>contain the exported symbols (currently only used for debugging).
  1414. </p>
  1415. </dd>
  1416. </dl>
  1417. <hr size="6">
  1418. <a name="SEC30"></a>
  1419. <table cellpadding="1" cellspacing="1" border="0">
  1420. <tr><td valign="middle" align="left">[<a href="#SEC29" title="Previous section in reading order"> &lt; </a>]</td>
  1421. <td valign="middle" align="left">[<a href="#SEC31" title="Next section in reading order"> &gt; </a>]</td>
  1422. <td valign="middle" align="left"> &nbsp; </td>
  1423. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1424. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1425. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1426. <td valign="middle" align="left"> &nbsp; </td>
  1427. <td valign="middle" align="left"> &nbsp; </td>
  1428. <td valign="middle" align="left"> &nbsp; </td>
  1429. <td valign="middle" align="left"> &nbsp; </td>
  1430. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1431. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1432. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1433. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1434. </tr></table>
  1435. <h2 class="section"> 8.7 Code generation </h2>
  1436. <hr size="6">
  1437. <a name="SEC31"></a>
  1438. <table cellpadding="1" cellspacing="1" border="0">
  1439. <tr><td valign="middle" align="left">[<a href="#SEC30" title="Previous section in reading order"> &lt; </a>]</td>
  1440. <td valign="middle" align="left">[<a href="#SEC32" title="Next section in reading order"> &gt; </a>]</td>
  1441. <td valign="middle" align="left"> &nbsp; </td>
  1442. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1443. <td valign="middle" align="left">[<a href="#SEC30" title="Up section"> Up </a>]</td>
  1444. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1445. <td valign="middle" align="left"> &nbsp; </td>
  1446. <td valign="middle" align="left"> &nbsp; </td>
  1447. <td valign="middle" align="left"> &nbsp; </td>
  1448. <td valign="middle" align="left"> &nbsp; </td>
  1449. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1450. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1451. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1452. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1453. </tr></table>
  1454. <h3 class="subsection"> 8.7.1 Introduction </h3>
  1455. <p>The TCC code generator directly generates linked binary code in one
  1456. pass. It is rather unusual these days (see gcc for example which
  1457. generates text assembly), but it can be very fast and surprisingly
  1458. little complicated.
  1459. </p>
  1460. <p>The TCC code generator is register based. Optimization is only done at
  1461. the expression level. No intermediate representation of expression is
  1462. kept except the current values stored in the <em>value stack</em>.
  1463. </p>
  1464. <p>On x86, three temporary registers are used. When more registers are
  1465. needed, one register is spilled into a new temporary variable on the stack.
  1466. </p>
  1467. <hr size="6">
  1468. <a name="SEC32"></a>
  1469. <table cellpadding="1" cellspacing="1" border="0">
  1470. <tr><td valign="middle" align="left">[<a href="#SEC31" title="Previous section in reading order"> &lt; </a>]</td>
  1471. <td valign="middle" align="left">[<a href="#SEC33" title="Next section in reading order"> &gt; </a>]</td>
  1472. <td valign="middle" align="left"> &nbsp; </td>
  1473. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1474. <td valign="middle" align="left">[<a href="#SEC30" title="Up section"> Up </a>]</td>
  1475. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1476. <td valign="middle" align="left"> &nbsp; </td>
  1477. <td valign="middle" align="left"> &nbsp; </td>
  1478. <td valign="middle" align="left"> &nbsp; </td>
  1479. <td valign="middle" align="left"> &nbsp; </td>
  1480. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1481. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1482. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1483. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1484. </tr></table>
  1485. <h3 class="subsection"> 8.7.2 The value stack </h3>
  1486. <p>When an expression is parsed, its value is pushed on the value stack
  1487. (<var>vstack</var>). The top of the value stack is <var>vtop</var>. Each value
  1488. stack entry is the structure <code>SValue</code>.
  1489. </p>
  1490. <p><code>SValue.t</code> is the type. <code>SValue.r</code> indicates how the value is
  1491. currently stored in the generated code. It is usually a CPU register
  1492. index (<code>REG_xxx</code> constants), but additional values and flags are
  1493. defined:
  1494. </p>
  1495. <table><tr><td>&nbsp;</td><td><pre class="example">#define VT_CONST 0x00f0
  1496. #define VT_LLOCAL 0x00f1
  1497. #define VT_LOCAL 0x00f2
  1498. #define VT_CMP 0x00f3
  1499. #define VT_JMP 0x00f4
  1500. #define VT_JMPI 0x00f5
  1501. #define VT_LVAL 0x0100
  1502. #define VT_SYM 0x0200
  1503. #define VT_MUSTCAST 0x0400
  1504. #define VT_MUSTBOUND 0x0800
  1505. #define VT_BOUNDED 0x8000
  1506. #define VT_LVAL_BYTE 0x1000
  1507. #define VT_LVAL_SHORT 0x2000
  1508. #define VT_LVAL_UNSIGNED 0x4000
  1509. #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
  1510. </pre></td></tr></table>
  1511. <dl compact="compact">
  1512. <dt> <code>VT_CONST</code></dt>
  1513. <dd><p>indicates that the value is a constant. It is stored in the union
  1514. <code>SValue.c</code>, depending on its type.
  1515. </p>
  1516. </dd>
  1517. <dt> <code>VT_LOCAL</code></dt>
  1518. <dd><p>indicates a local variable pointer at offset <code>SValue.c.i</code> in the
  1519. stack.
  1520. </p>
  1521. </dd>
  1522. <dt> <code>VT_CMP</code></dt>
  1523. <dd><p>indicates that the value is actually stored in the CPU flags (i.e. the
  1524. value is the consequence of a test). The value is either 0 or 1. The
  1525. actual CPU flags used is indicated in <code>SValue.c.i</code>.
  1526. </p>
  1527. <p>If any code is generated which destroys the CPU flags, this value MUST be
  1528. put in a normal register.
  1529. </p>
  1530. </dd>
  1531. <dt> <code>VT_JMP</code></dt>
  1532. <dt> <code>VT_JMPI</code></dt>
  1533. <dd><p>indicates that the value is the consequence of a conditional jump. For VT_JMP,
  1534. it is 1 if the jump is taken, 0 otherwise. For VT_JMPI it is inverted.
  1535. </p>
  1536. <p>These values are used to compile the <code>||</code> and <code>&amp;&amp;</code> logical
  1537. operators.
  1538. </p>
  1539. <p>If any code is generated, this value MUST be put in a normal
  1540. register. Otherwise, the generated code won't be executed if the jump is
  1541. taken.
  1542. </p>
  1543. </dd>
  1544. <dt> <code>VT_LVAL</code></dt>
  1545. <dd><p>is a flag indicating that the value is actually an lvalue (left value of
  1546. an assignment). It means that the value stored is actually a pointer to
  1547. the wanted value.
  1548. </p>
  1549. <p>Understanding the use <code>VT_LVAL</code> is very important if you want to
  1550. understand how TCC works.
  1551. </p>
  1552. </dd>
  1553. <dt> <code>VT_LVAL_BYTE</code></dt>
  1554. <dt> <code>VT_LVAL_SHORT</code></dt>
  1555. <dt> <code>VT_LVAL_UNSIGNED</code></dt>
  1556. <dd><p>if the lvalue has an integer type, then these flags give its real
  1557. type. The type alone is not enough in case of cast optimisations.
  1558. </p>
  1559. </dd>
  1560. <dt> <code>VT_LLOCAL</code></dt>
  1561. <dd><p>is a saved lvalue on the stack. <code>VT_LLOCAL</code> should be eliminated
  1562. ASAP because its semantics are rather complicated.
  1563. </p>
  1564. </dd>
  1565. <dt> <code>VT_MUSTCAST</code></dt>
  1566. <dd><p>indicates that a cast to the value type must be performed if the value
  1567. is used (lazy casting).
  1568. </p>
  1569. </dd>
  1570. <dt> <code>VT_SYM</code></dt>
  1571. <dd><p>indicates that the symbol <code>SValue.sym</code> must be added to the constant.
  1572. </p>
  1573. </dd>
  1574. <dt> <code>VT_MUSTBOUND</code></dt>
  1575. <dt> <code>VT_BOUNDED</code></dt>
  1576. <dd><p>are only used for optional bound checking.
  1577. </p>
  1578. </dd>
  1579. </dl>
  1580. <hr size="6">
  1581. <a name="SEC33"></a>
  1582. <table cellpadding="1" cellspacing="1" border="0">
  1583. <tr><td valign="middle" align="left">[<a href="#SEC32" title="Previous section in reading order"> &lt; </a>]</td>
  1584. <td valign="middle" align="left">[<a href="#SEC34" title="Next section in reading order"> &gt; </a>]</td>
  1585. <td valign="middle" align="left"> &nbsp; </td>
  1586. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1587. <td valign="middle" align="left">[<a href="#SEC30" title="Up section"> Up </a>]</td>
  1588. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1589. <td valign="middle" align="left"> &nbsp; </td>
  1590. <td valign="middle" align="left"> &nbsp; </td>
  1591. <td valign="middle" align="left"> &nbsp; </td>
  1592. <td valign="middle" align="left"> &nbsp; </td>
  1593. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1594. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1595. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1596. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1597. </tr></table>
  1598. <h3 class="subsection"> 8.7.3 Manipulating the value stack </h3>
  1599. <p><code>vsetc()</code> and <code>vset()</code> pushes a new value on the value
  1600. stack. If the previous <var>vtop</var> was stored in a very unsafe place(for
  1601. example in the CPU flags), then some code is generated to put the
  1602. previous <var>vtop</var> in a safe storage.
  1603. </p>
  1604. <p><code>vpop()</code> pops <var>vtop</var>. In some cases, it also generates cleanup
  1605. code (for example if stacked floating point registers are used as on
  1606. x86).
  1607. </p>
  1608. <p>The <code>gv(rc)</code> function generates code to evaluate <var>vtop</var> (the
  1609. top value of the stack) into registers. <var>rc</var> selects in which
  1610. register class the value should be put. <code>gv()</code> is the <em>most
  1611. important function</em> of the code generator.
  1612. </p>
  1613. <p><code>gv2()</code> is the same as <code>gv()</code> but for the top two stack
  1614. entries.
  1615. </p>
  1616. <hr size="6">
  1617. <a name="SEC34"></a>
  1618. <table cellpadding="1" cellspacing="1" border="0">
  1619. <tr><td valign="middle" align="left">[<a href="#SEC33" title="Previous section in reading order"> &lt; </a>]</td>
  1620. <td valign="middle" align="left">[<a href="#SEC35" title="Next section in reading order"> &gt; </a>]</td>
  1621. <td valign="middle" align="left"> &nbsp; </td>
  1622. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1623. <td valign="middle" align="left">[<a href="#SEC30" title="Up section"> Up </a>]</td>
  1624. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1625. <td valign="middle" align="left"> &nbsp; </td>
  1626. <td valign="middle" align="left"> &nbsp; </td>
  1627. <td valign="middle" align="left"> &nbsp; </td>
  1628. <td valign="middle" align="left"> &nbsp; </td>
  1629. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1630. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1631. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1632. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1633. </tr></table>
  1634. <h3 class="subsection"> 8.7.4 CPU dependent code generation </h3>
  1635. <p>See the &lsquo;<tt>i386-gen.c</tt>&rsquo; file to have an example.
  1636. </p>
  1637. <dl compact="compact">
  1638. <dt> <code>load()</code></dt>
  1639. <dd><p>must generate the code needed to load a stack value into a register.
  1640. </p>
  1641. </dd>
  1642. <dt> <code>store()</code></dt>
  1643. <dd><p>must generate the code needed to store a register into a stack value
  1644. lvalue.
  1645. </p>
  1646. </dd>
  1647. <dt> <code>gfunc_start()</code></dt>
  1648. <dt> <code>gfunc_param()</code></dt>
  1649. <dt> <code>gfunc_call()</code></dt>
  1650. <dd><p>should generate a function call
  1651. </p>
  1652. </dd>
  1653. <dt> <code>gfunc_prolog()</code></dt>
  1654. <dt> <code>gfunc_epilog()</code></dt>
  1655. <dd><p>should generate a function prolog/epilog.
  1656. </p>
  1657. </dd>
  1658. <dt> <code>gen_opi(op)</code></dt>
  1659. <dd><p>must generate the binary integer operation <var>op</var> on the two top
  1660. entries of the stack which are guaranted to contain integer types.
  1661. </p>
  1662. <p>The result value should be put on the stack.
  1663. </p>
  1664. </dd>
  1665. <dt> <code>gen_opf(op)</code></dt>
  1666. <dd><p>same as <code>gen_opi()</code> for floating point operations. The two top
  1667. entries of the stack are guaranted to contain floating point values of
  1668. same types.
  1669. </p>
  1670. </dd>
  1671. <dt> <code>gen_cvt_itof()</code></dt>
  1672. <dd><p>integer to floating point conversion.
  1673. </p>
  1674. </dd>
  1675. <dt> <code>gen_cvt_ftoi()</code></dt>
  1676. <dd><p>floating point to integer conversion.
  1677. </p>
  1678. </dd>
  1679. <dt> <code>gen_cvt_ftof()</code></dt>
  1680. <dd><p>floating point to floating point of different size conversion.
  1681. </p>
  1682. </dd>
  1683. <dt> <code>gen_bounded_ptr_add()</code></dt>
  1684. <dt> <code>gen_bounded_ptr_deref()</code></dt>
  1685. <dd><p>are only used for bounds checking.
  1686. </p>
  1687. </dd>
  1688. </dl>
  1689. <hr size="6">
  1690. <a name="SEC35"></a>
  1691. <table cellpadding="1" cellspacing="1" border="0">
  1692. <tr><td valign="middle" align="left">[<a href="#SEC34" title="Previous section in reading order"> &lt; </a>]</td>
  1693. <td valign="middle" align="left">[<a href="#SEC36" title="Next section in reading order"> &gt; </a>]</td>
  1694. <td valign="middle" align="left"> &nbsp; </td>
  1695. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1696. <td valign="middle" align="left">[<a href="#SEC23" title="Up section"> Up </a>]</td>
  1697. <td valign="middle" align="left">[<a href="#SEC36" title="Next chapter"> &gt;&gt; </a>]</td>
  1698. <td valign="middle" align="left"> &nbsp; </td>
  1699. <td valign="middle" align="left"> &nbsp; </td>
  1700. <td valign="middle" align="left"> &nbsp; </td>
  1701. <td valign="middle" align="left"> &nbsp; </td>
  1702. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1703. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1704. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1705. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1706. </tr></table>
  1707. <h2 class="section"> 8.8 Optimizations done </h2>
  1708. <p>Constant propagation is done for all operations. Multiplications and
  1709. divisions are optimized to shifts when appropriate. Comparison
  1710. operators are optimized by maintaining a special cache for the
  1711. processor flags. &amp;&amp;, || and ! are optimized by maintaining a special
  1712. 'jump target' value. No other jump optimization is currently performed
  1713. because it would require to store the code in a more abstract fashion.
  1714. </p>
  1715. <hr size="6">
  1716. <a name="SEC36"></a>
  1717. <table cellpadding="1" cellspacing="1" border="0">
  1718. <tr><td valign="middle" align="left">[<a href="#SEC35" title="Previous section in reading order"> &lt; </a>]</td>
  1719. <td valign="middle" align="left">[ &gt; ]</td>
  1720. <td valign="middle" align="left"> &nbsp; </td>
  1721. <td valign="middle" align="left">[<a href="#SEC23" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  1722. <td valign="middle" align="left">[<a href="#SEC_Top" title="Up section"> Up </a>]</td>
  1723. <td valign="middle" align="left">[ &gt;&gt; ]</td>
  1724. <td valign="middle" align="left"> &nbsp; </td>
  1725. <td valign="middle" align="left"> &nbsp; </td>
  1726. <td valign="middle" align="left"> &nbsp; </td>
  1727. <td valign="middle" align="left"> &nbsp; </td>
  1728. <td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1729. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1730. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1731. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1732. </tr></table>
  1733. <h1 class="unnumbered"> Concept Index </h1>
  1734. <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#SEC36_0" class="summary-letter"><b>_</b></a>
  1735. &nbsp;
  1736. <br>
  1737. <a href="#SEC36_1" class="summary-letter"><b>A</b></a>
  1738. &nbsp;
  1739. <a href="#SEC36_2" class="summary-letter"><b>B</b></a>
  1740. &nbsp;
  1741. <a href="#SEC36_3" class="summary-letter"><b>C</b></a>
  1742. &nbsp;
  1743. <a href="#SEC36_4" class="summary-letter"><b>D</b></a>
  1744. &nbsp;
  1745. <a href="#SEC36_5" class="summary-letter"><b>E</b></a>
  1746. &nbsp;
  1747. <a href="#SEC36_6" class="summary-letter"><b>F</b></a>
  1748. &nbsp;
  1749. <a href="#SEC36_7" class="summary-letter"><b>G</b></a>
  1750. &nbsp;
  1751. <a href="#SEC36_8" class="summary-letter"><b>I</b></a>
  1752. &nbsp;
  1753. <a href="#SEC36_9" class="summary-letter"><b>J</b></a>
  1754. &nbsp;
  1755. <a href="#SEC36_10" class="summary-letter"><b>L</b></a>
  1756. &nbsp;
  1757. <a href="#SEC36_11" class="summary-letter"><b>M</b></a>
  1758. &nbsp;
  1759. <a href="#SEC36_12" class="summary-letter"><b>O</b></a>
  1760. &nbsp;
  1761. <a href="#SEC36_13" class="summary-letter"><b>P</b></a>
  1762. &nbsp;
  1763. <a href="#SEC36_14" class="summary-letter"><b>Q</b></a>
  1764. &nbsp;
  1765. <a href="#SEC36_15" class="summary-letter"><b>R</b></a>
  1766. &nbsp;
  1767. <a href="#SEC36_16" class="summary-letter"><b>S</b></a>
  1768. &nbsp;
  1769. <a href="#SEC36_17" class="summary-letter"><b>T</b></a>
  1770. &nbsp;
  1771. <a href="#SEC36_18" class="summary-letter"><b>U</b></a>
  1772. &nbsp;
  1773. <a href="#SEC36_19" class="summary-letter"><b>V</b></a>
  1774. &nbsp;
  1775. <a href="#SEC36_20" class="summary-letter"><b>W</b></a>
  1776. &nbsp;
  1777. </td></tr></table>
  1778. <table border="0" class="index-cp">
  1779. <tr><td></td><th align="left">Index Entry</th><th align="left"> Section</th></tr>
  1780. <tr><td colspan="3"> <hr></td></tr>
  1781. <tr><th><a name="SEC36_0">_</a></th><td></td><td></td></tr>
  1782. <tr><td></td><td valign="top"><a href="#IDX11">__asm__</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1783. <tr><td colspan="3"> <hr></td></tr>
  1784. <tr><th><a name="SEC36_1">A</a></th><td></td><td></td></tr>
  1785. <tr><td></td><td valign="top"><a href="#SEC14">align directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1786. <tr><td></td><td valign="top"><a href="#IDX1">aligned attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1787. <tr><td></td><td valign="top"><a href="#SEC14">ascii directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1788. <tr><td></td><td valign="top"><a href="#SEC14">asciz directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1789. <tr><td></td><td valign="top"><a href="#SEC15">assembler</a></td><td valign="top"><a href="#SEC15">4.5 X86 Assembler</a></td></tr>
  1790. <tr><td></td><td valign="top"><a href="#SEC14">assembler directives</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1791. <tr><td></td><td valign="top"><a href="#IDX10">assembly, inline</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1792. <tr><td colspan="3"> <hr></td></tr>
  1793. <tr><th><a name="SEC36_2">B</a></th><td></td><td></td></tr>
  1794. <tr><td></td><td valign="top"><a href="#SEC21">bound checks</a></td><td valign="top"><a href="#SEC21">6. TinyCC Memory and Bound checks</a></td></tr>
  1795. <tr><td></td><td valign="top"><a href="#SEC14">bss directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1796. <tr><td></td><td valign="top"><a href="#SEC14">byte directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1797. <tr><td colspan="3"> <hr></td></tr>
  1798. <tr><th><a name="SEC36_3">C</a></th><td></td><td></td></tr>
  1799. <tr><td></td><td valign="top"><a href="#SEC35">caching processor flags</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1800. <tr><td></td><td valign="top"><a href="#IDX5">cdecl attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1801. <tr><td></td><td valign="top"><a href="#SEC30">code generation</a></td><td valign="top"><a href="#SEC30">8.7 Code generation</a></td></tr>
  1802. <tr><td></td><td valign="top"><a href="#SEC35">comparison operators</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1803. <tr><td></td><td valign="top"><a href="#SEC35">constant propagation</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1804. <tr><td></td><td valign="top"><a href="#SEC34">CPU dependent</a></td><td valign="top"><a href="#SEC34">8.7.4 CPU dependent code generation</a></td></tr>
  1805. <tr><td colspan="3"> <hr></td></tr>
  1806. <tr><th><a name="SEC36_4">D</a></th><td></td><td></td></tr>
  1807. <tr><td></td><td valign="top"><a href="#SEC14">data directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1808. <tr><td></td><td valign="top"><a href="#SEC14">directives, assembler</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1809. <tr><td></td><td valign="top"><a href="#IDX8">dllexport attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1810. <tr><td colspan="3"> <hr></td></tr>
  1811. <tr><th><a name="SEC36_5">E</a></th><td></td><td></td></tr>
  1812. <tr><td></td><td valign="top"><a href="#SEC17">ELF</a></td><td valign="top"><a href="#SEC17">5.1 ELF file generation</a></td></tr>
  1813. <tr><td colspan="3"> <hr></td></tr>
  1814. <tr><th><a name="SEC36_6">F</a></th><td></td><td></td></tr>
  1815. <tr><td></td><td valign="top"><a href="#SEC20">FILE, linker command</a></td><td valign="top"><a href="#SEC20">5.4 GNU Linker Scripts</a></td></tr>
  1816. <tr><td></td><td valign="top"><a href="#SEC14">fill directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1817. <tr><td></td><td valign="top"><a href="#SEC35">flags, caching</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1818. <tr><td colspan="3"> <hr></td></tr>
  1819. <tr><th><a name="SEC36_7">G</a></th><td></td><td></td></tr>
  1820. <tr><td></td><td valign="top"><a href="#IDX12">gas</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1821. <tr><td></td><td valign="top"><a href="#SEC14">global directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1822. <tr><td></td><td valign="top"><a href="#SEC14">globl directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1823. <tr><td></td><td valign="top"><a href="#SEC20">GROUP, linker command</a></td><td valign="top"><a href="#SEC20">5.4 GNU Linker Scripts</a></td></tr>
  1824. <tr><td colspan="3"> <hr></td></tr>
  1825. <tr><th><a name="SEC36_8">I</a></th><td></td><td></td></tr>
  1826. <tr><td></td><td valign="top"><a href="#IDX9">inline assembly</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1827. <tr><td></td><td valign="top"><a href="#SEC14">int directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1828. <tr><td colspan="3"> <hr></td></tr>
  1829. <tr><th><a name="SEC36_9">J</a></th><td></td><td></td></tr>
  1830. <tr><td></td><td valign="top"><a href="#SEC35">jump optimization</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1831. <tr><td colspan="3"> <hr></td></tr>
  1832. <tr><th><a name="SEC36_10">L</a></th><td></td><td></td></tr>
  1833. <tr><td></td><td valign="top"><a href="#SEC16">linker</a></td><td valign="top"><a href="#SEC16">5. TinyCC Linker</a></td></tr>
  1834. <tr><td></td><td valign="top"><a href="#SEC20">linker scripts</a></td><td valign="top"><a href="#SEC20">5.4 GNU Linker Scripts</a></td></tr>
  1835. <tr><td></td><td valign="top"><a href="#SEC14">long directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1836. <tr><td colspan="3"> <hr></td></tr>
  1837. <tr><th><a name="SEC36_11">M</a></th><td></td><td></td></tr>
  1838. <tr><td></td><td valign="top"><a href="#SEC21">memory checks</a></td><td valign="top"><a href="#SEC21">6. TinyCC Memory and Bound checks</a></td></tr>
  1839. <tr><td colspan="3"> <hr></td></tr>
  1840. <tr><th><a name="SEC36_12">O</a></th><td></td><td></td></tr>
  1841. <tr><td></td><td valign="top"><a href="#SEC35">optimizations</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1842. <tr><td></td><td valign="top"><a href="#SEC14">org directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1843. <tr><td></td><td valign="top"><a href="#SEC20">OUTPUT_FORMAT, linker command</a></td><td valign="top"><a href="#SEC20">5.4 GNU Linker Scripts</a></td></tr>
  1844. <tr><td colspan="3"> <hr></td></tr>
  1845. <tr><th><a name="SEC36_13">P</a></th><td></td><td></td></tr>
  1846. <tr><td></td><td valign="top"><a href="#IDX2">packed attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1847. <tr><td></td><td valign="top"><a href="#SEC19">PE-i386</a></td><td valign="top"><a href="#SEC19">5.3 PE-i386 file generation</a></td></tr>
  1848. <tr><td></td><td valign="top"><a href="#SEC14">previous directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1849. <tr><td colspan="3"> <hr></td></tr>
  1850. <tr><th><a name="SEC36_14">Q</a></th><td></td><td></td></tr>
  1851. <tr><td></td><td valign="top"><a href="#SEC14">quad directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1852. <tr><td colspan="3"> <hr></td></tr>
  1853. <tr><th><a name="SEC36_15">R</a></th><td></td><td></td></tr>
  1854. <tr><td></td><td valign="top"><a href="#IDX7">regparm attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1855. <tr><td colspan="3"> <hr></td></tr>
  1856. <tr><th><a name="SEC36_16">S</a></th><td></td><td></td></tr>
  1857. <tr><td></td><td valign="top"><a href="#SEC20">scripts, linker</a></td><td valign="top"><a href="#SEC20">5.4 GNU Linker Scripts</a></td></tr>
  1858. <tr><td></td><td valign="top"><a href="#IDX3">section attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1859. <tr><td></td><td valign="top"><a href="#SEC14">section directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1860. <tr><td></td><td valign="top"><a href="#SEC14">short directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1861. <tr><td></td><td valign="top"><a href="#SEC14">skip directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1862. <tr><td></td><td valign="top"><a href="#SEC14">space directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1863. <tr><td></td><td valign="top"><a href="#IDX6">stdcall attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1864. <tr><td></td><td valign="top"><a href="#SEC35">strength reduction</a></td><td valign="top"><a href="#SEC35">8.8 Optimizations done</a></td></tr>
  1865. <tr><td></td><td valign="top"><a href="#SEC14">string directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1866. <tr><td colspan="3"> <hr></td></tr>
  1867. <tr><th><a name="SEC36_17">T</a></th><td></td><td></td></tr>
  1868. <tr><td></td><td valign="top"><a href="#SEC20">TARGET, linker command</a></td><td valign="top"><a href="#SEC20">5.4 GNU Linker Scripts</a></td></tr>
  1869. <tr><td></td><td valign="top"><a href="#SEC14">text directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1870. <tr><td colspan="3"> <hr></td></tr>
  1871. <tr><th><a name="SEC36_18">U</a></th><td></td><td></td></tr>
  1872. <tr><td></td><td valign="top"><a href="#IDX4">unused attribute</a></td><td valign="top"><a href="#SEC8">3.3 GNU C extensions</a></td></tr>
  1873. <tr><td colspan="3"> <hr></td></tr>
  1874. <tr><th><a name="SEC36_19">V</a></th><td></td><td></td></tr>
  1875. <tr><td></td><td valign="top"><a href="#SEC33">value stack</a></td><td valign="top"><a href="#SEC33">8.7.3 Manipulating the value stack</a></td></tr>
  1876. <tr><td></td><td valign="top"><a href="#SEC32">value stack, introduction</a></td><td valign="top"><a href="#SEC32">8.7.2 The value stack</a></td></tr>
  1877. <tr><td colspan="3"> <hr></td></tr>
  1878. <tr><th><a name="SEC36_20">W</a></th><td></td><td></td></tr>
  1879. <tr><td></td><td valign="top"><a href="#SEC14">word directive</a></td><td valign="top"><a href="#SEC14">4.4 Directives</a></td></tr>
  1880. <tr><td colspan="3"> <hr></td></tr>
  1881. </table>
  1882. <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#SEC36_0" class="summary-letter"><b>_</b></a>
  1883. &nbsp;
  1884. <br>
  1885. <a href="#SEC36_1" class="summary-letter"><b>A</b></a>
  1886. &nbsp;
  1887. <a href="#SEC36_2" class="summary-letter"><b>B</b></a>
  1888. &nbsp;
  1889. <a href="#SEC36_3" class="summary-letter"><b>C</b></a>
  1890. &nbsp;
  1891. <a href="#SEC36_4" class="summary-letter"><b>D</b></a>
  1892. &nbsp;
  1893. <a href="#SEC36_5" class="summary-letter"><b>E</b></a>
  1894. &nbsp;
  1895. <a href="#SEC36_6" class="summary-letter"><b>F</b></a>
  1896. &nbsp;
  1897. <a href="#SEC36_7" class="summary-letter"><b>G</b></a>
  1898. &nbsp;
  1899. <a href="#SEC36_8" class="summary-letter"><b>I</b></a>
  1900. &nbsp;
  1901. <a href="#SEC36_9" class="summary-letter"><b>J</b></a>
  1902. &nbsp;
  1903. <a href="#SEC36_10" class="summary-letter"><b>L</b></a>
  1904. &nbsp;
  1905. <a href="#SEC36_11" class="summary-letter"><b>M</b></a>
  1906. &nbsp;
  1907. <a href="#SEC36_12" class="summary-letter"><b>O</b></a>
  1908. &nbsp;
  1909. <a href="#SEC36_13" class="summary-letter"><b>P</b></a>
  1910. &nbsp;
  1911. <a href="#SEC36_14" class="summary-letter"><b>Q</b></a>
  1912. &nbsp;
  1913. <a href="#SEC36_15" class="summary-letter"><b>R</b></a>
  1914. &nbsp;
  1915. <a href="#SEC36_16" class="summary-letter"><b>S</b></a>
  1916. &nbsp;
  1917. <a href="#SEC36_17" class="summary-letter"><b>T</b></a>
  1918. &nbsp;
  1919. <a href="#SEC36_18" class="summary-letter"><b>U</b></a>
  1920. &nbsp;
  1921. <a href="#SEC36_19" class="summary-letter"><b>V</b></a>
  1922. &nbsp;
  1923. <a href="#SEC36_20" class="summary-letter"><b>W</b></a>
  1924. &nbsp;
  1925. </td></tr></table>
  1926. <hr size="6">
  1927. <a name="SEC_Contents"></a>
  1928. <table cellpadding="1" cellspacing="1" border="0">
  1929. <tr><td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1930. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1931. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1932. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1933. </tr></table>
  1934. <h1>Table of Contents</h1>
  1935. <div class="contents">
  1936. <ul class="toc">
  1937. <li><a name="TOC1" href="#SEC1">1. Introduction</a></li>
  1938. <li><a name="TOC2" href="#SEC2">2. Command line invocation</a>
  1939. <ul class="toc">
  1940. <li><a name="TOC3" href="#SEC3">2.1 Quick start</a></li>
  1941. <li><a name="TOC4" href="#SEC4">2.2 Option summary</a></li>
  1942. </ul></li>
  1943. <li><a name="TOC5" href="#SEC5">3. C language support</a>
  1944. <ul class="toc">
  1945. <li><a name="TOC6" href="#SEC6">3.1 ANSI C</a></li>
  1946. <li><a name="TOC7" href="#SEC7">3.2 ISOC99 extensions</a></li>
  1947. <li><a name="TOC8" href="#SEC8">3.3 GNU C extensions</a></li>
  1948. <li><a name="TOC9" href="#SEC9">3.4 TinyCC extensions</a></li>
  1949. </ul></li>
  1950. <li><a name="TOC10" href="#SEC10">4. TinyCC Assembler</a>
  1951. <ul class="toc">
  1952. <li><a name="TOC11" href="#SEC11">4.1 Syntax</a></li>
  1953. <li><a name="TOC12" href="#SEC12">4.2 Expressions</a></li>
  1954. <li><a name="TOC13" href="#SEC13">4.3 Labels</a></li>
  1955. <li><a name="TOC14" href="#SEC14">4.4 Directives</a></li>
  1956. <li><a name="TOC15" href="#SEC15">4.5 X86 Assembler</a></li>
  1957. </ul></li>
  1958. <li><a name="TOC16" href="#SEC16">5. TinyCC Linker</a>
  1959. <ul class="toc">
  1960. <li><a name="TOC17" href="#SEC17">5.1 ELF file generation</a></li>
  1961. <li><a name="TOC18" href="#SEC18">5.2 ELF file loader</a></li>
  1962. <li><a name="TOC19" href="#SEC19">5.3 PE-i386 file generation</a></li>
  1963. <li><a name="TOC20" href="#SEC20">5.4 GNU Linker Scripts</a></li>
  1964. </ul></li>
  1965. <li><a name="TOC21" href="#SEC21">6. TinyCC Memory and Bound checks</a></li>
  1966. <li><a name="TOC22" href="#SEC22">7. The <code>libtcc</code> library</a></li>
  1967. <li><a name="TOC23" href="#SEC23">8. Developer's guide</a>
  1968. <ul class="toc">
  1969. <li><a name="TOC24" href="#SEC24">8.1 File reading</a></li>
  1970. <li><a name="TOC25" href="#SEC25">8.2 Lexer</a></li>
  1971. <li><a name="TOC26" href="#SEC26">8.3 Parser</a></li>
  1972. <li><a name="TOC27" href="#SEC27">8.4 Types</a></li>
  1973. <li><a name="TOC28" href="#SEC28">8.5 Symbols</a></li>
  1974. <li><a name="TOC29" href="#SEC29">8.6 Sections</a></li>
  1975. <li><a name="TOC30" href="#SEC30">8.7 Code generation</a>
  1976. <ul class="toc">
  1977. <li><a name="TOC31" href="#SEC31">8.7.1 Introduction</a></li>
  1978. <li><a name="TOC32" href="#SEC32">8.7.2 The value stack</a></li>
  1979. <li><a name="TOC33" href="#SEC33">8.7.3 Manipulating the value stack</a></li>
  1980. <li><a name="TOC34" href="#SEC34">8.7.4 CPU dependent code generation</a></li>
  1981. </ul></li>
  1982. <li><a name="TOC35" href="#SEC35">8.8 Optimizations done</a></li>
  1983. </ul></li>
  1984. <li><a name="TOC36" href="#SEC36">Concept Index</a></li>
  1985. </ul>
  1986. </div>
  1987. <hr size="1">
  1988. <a name="SEC_About"></a>
  1989. <table cellpadding="1" cellspacing="1" border="0">
  1990. <tr><td valign="middle" align="left">[<a href="#SEC_Top" title="Cover (top) of document">Top</a>]</td>
  1991. <td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
  1992. <td valign="middle" align="left">[<a href="#SEC36" title="Index">Index</a>]</td>
  1993. <td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
  1994. </tr></table>
  1995. <h1>About This Document</h1>
  1996. <p>
  1997. This document was generated by <em>gr</em> on <em>May, 18 2009</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.78</em></a>.
  1998. </p>
  1999. <p>
  2000. The buttons in the navigation panels have the following meaning:
  2001. </p>
  2002. <table border="1">
  2003. <tr>
  2004. <th> Button </th>
  2005. <th> Name </th>
  2006. <th> Go to </th>
  2007. <th> From 1.2.3 go to</th>
  2008. </tr>
  2009. <tr>
  2010. <td align="center"> [ &lt; ] </td>
  2011. <td align="center">Back</td>
  2012. <td>Previous section in reading order</td>
  2013. <td>1.2.2</td>
  2014. </tr>
  2015. <tr>
  2016. <td align="center"> [ &gt; ] </td>
  2017. <td align="center">Forward</td>
  2018. <td>Next section in reading order</td>
  2019. <td>1.2.4</td>
  2020. </tr>
  2021. <tr>
  2022. <td align="center"> [ &lt;&lt; ] </td>
  2023. <td align="center">FastBack</td>
  2024. <td>Beginning of this chapter or previous chapter</td>
  2025. <td>1</td>
  2026. </tr>
  2027. <tr>
  2028. <td align="center"> [ Up ] </td>
  2029. <td align="center">Up</td>
  2030. <td>Up section</td>
  2031. <td>1.2</td>
  2032. </tr>
  2033. <tr>
  2034. <td align="center"> [ &gt;&gt; ] </td>
  2035. <td align="center">FastForward</td>
  2036. <td>Next chapter</td>
  2037. <td>2</td>
  2038. </tr>
  2039. <tr>
  2040. <td align="center"> [Top] </td>
  2041. <td align="center">Top</td>
  2042. <td>Cover (top) of document</td>
  2043. <td> &nbsp; </td>
  2044. </tr>
  2045. <tr>
  2046. <td align="center"> [Contents] </td>
  2047. <td align="center">Contents</td>
  2048. <td>Table of contents</td>
  2049. <td> &nbsp; </td>
  2050. </tr>
  2051. <tr>
  2052. <td align="center"> [Index] </td>
  2053. <td align="center">Index</td>
  2054. <td>Index</td>
  2055. <td> &nbsp; </td>
  2056. </tr>
  2057. <tr>
  2058. <td align="center"> [ ? ] </td>
  2059. <td align="center">About</td>
  2060. <td>About (help)</td>
  2061. <td> &nbsp; </td>
  2062. </tr>
  2063. </table>
  2064. <p>
  2065. where the <strong> Example </strong> assumes that the current position is at <strong> Subsubsection One-Two-Three </strong> of a document of the following structure:
  2066. </p>
  2067. <ul>
  2068. <li> 1. Section One
  2069. <ul>
  2070. <li>1.1 Subsection One-One
  2071. <ul>
  2072. <li>...</li>
  2073. </ul>
  2074. </li>
  2075. <li>1.2 Subsection One-Two
  2076. <ul>
  2077. <li>1.2.1 Subsubsection One-Two-One</li>
  2078. <li>1.2.2 Subsubsection One-Two-Two</li>
  2079. <li>1.2.3 Subsubsection One-Two-Three &nbsp; &nbsp;
  2080. <strong>&lt;== Current Position </strong></li>
  2081. <li>1.2.4 Subsubsection One-Two-Four</li>
  2082. </ul>
  2083. </li>
  2084. <li>1.3 Subsection One-Three
  2085. <ul>
  2086. <li>...</li>
  2087. </ul>
  2088. </li>
  2089. <li>1.4 Subsection One-Four</li>
  2090. </ul>
  2091. </li>
  2092. </ul>
  2093. <hr size="1">
  2094. <p>
  2095. <font size="-1">
  2096. This document was generated by <em>gr</em> on <em>May, 18 2009</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.78</em></a>.
  2097. </font>
  2098. <br>
  2099. </p>
  2100. </body>
  2101. </html>