<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>coding &#187; gcc</title>
	<atom:link href="http://www.coding.com.br/tag/gcc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coding.com.br</link>
	<description>have you coded today?</description>
	<lastBuildDate>Thu, 18 Aug 2011 17:29:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Building GCC [4.6] on MacOSX</title>
		<link>http://www.coding.com.br/mac/building-gcc-4-6-on-macosx/</link>
		<comments>http://www.coding.com.br/mac/building-gcc-4-6-on-macosx/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 18:38:33 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=880</guid>
		<description><![CDATA[The objective here is describe a didactic way to build GNU GCC on MacOSX.  In order to compile GCC you need three libraries: GMP, MPFR and MPC. To organize I usually create folders for each purpose. In this case, three, respectively: source, build and install. [It's not a rule].  My original enviroment is MacOSX 10.6.4 and gcc [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">The objective here is describe a didactic way to build GNU GCC on MacOSX.  In order to compile GCC you need three libraries: GMP, MPFR and MPC. To organize I usually create folders for each purpose. In this case, three, respectively: <em>source</em>, <em>build</em> and <em>install</em>. [It's not a rule].  My original enviroment is MacOSX 10.6.4 and gcc version 4.2.1 (Apple Inc. build 5659). All files will be on GCC folder, the description below shows:</p>
<p style="padding-left: 30px;">$ mkdir ~/Projects/GCC # <em>compiler + libs</em><br />
$ mkdir ~/Projects/GCC/libs # <em>gmp, mpfr and mp</em>c<br />
$ mkdir ~/Projects/GCC/libs/files <em># downloaded files</em><br />
$ mkdir ~/Projects/GCC/libs/install <em># store libs objects and include</em></p>
<p><strong>Step #1 &#8211; Download</strong></p>
<p style="padding-left: 30px;">$ cd ~/Projects/GCC/libs/files<br />
$ wget ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.bz2<br />
$ wget http://www.mpfr.org/mpfr-current/mpfr-3.0.0.tar.bz2<br />
$ wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz</p>
<p><strong>Step #2 &#8211; Unpack </strong></p>
<p style="padding-left: 30px;">$ cd ~/Projects/GCC/libs/<br />
$ tar jxvf files/gmp-5.0.1.tar.bz2<br />
$ tar jxvf files/mpfr-3.0.0.tar.bz2<br />
$ tar zxvf files/mpc-0.8.2.tar.gz</p>
<p><strong>Step #3 &#8211; Build: GMP</strong></p>
<p style="padding-left: 30px;">$ cd ~/Projects/GCC/libs/</p>
<p style="padding-left: 30px;">$ mkdir gmp-build<br />
$ cd gmp-build<br />
$ ../gmp-5.0.1/configure &#8211;prefix=$(cd ../install &amp;&amp; pwd)<br />
$ make install</p>
<p><em>Note 1: I&#8217;m using with ABI=64</em><br />
<em>Note 2 : Maybe you&#8217;ll get some unresolved symbols to GMP and MPFR on linking time, never mind. </em></p>
<p><em></em><strong>Step #4 &#8211; Build: MPFR</strong></p>
<p style="padding-left: 30px;">$ cd ~/Projects/GCC/libs/</p>
<p style="padding-left: 30px;">$ mkdir mpfr-build<br />
$ cd mpfr-build<br />
$ ../mpfr-3.0.0/configure &#8211;prefix=$(cd ../install &amp;&amp; pwd) &#8211;with-gmp=~/Projects/GCC/libs/install<br />
$ make install</p>
<p><em>Note: Before prefix and with-xxx there are two hyphen (not one as showed). It&#8217;s an Wordpress issue, I don&#8217;t know how to avoid concatenation. </em></p>
<p><strong>Step #5 &#8211; Build: MPC</strong></p>
<p style="padding-left: 30px;">$ cd ~/Projects/GCC/libs/</p>
<p style="padding-left: 30px;">$ mkdir mpc-build<br />
$ cd mpc-build<br />
$ ../mpc-0.8.2/configure &#8211;prefix=$(cd ../install &amp;&amp; pwd) &#8211;with-gmp=~/Projects/GCC/libs/install &#8211;with-mprf=~/Projects/GCC/libs/install<br />
$ make install</p>
<p style="padding-left: 30px;">Problems? If something goes wrong&#8230;</p>
<p style="padding-left: 30px;"><em>../../mpc-0.8.2/src/mpc.h:25:17: error: gmp.h: No such file or directory<br />
../../mpc-0.8.2/src/mpc.h:26:18: error: mpfr.h: No such file or directory</em></p>
<p style="padding-left: 30px;">I fixed by adding symbolic links:</p>
<p style="padding-left: 30px;">$ cd  ~/Projects/GCC/libs/mpc-0.8.2/src/<br />
$ ln -s ../../install/include/mpf2mpfr.h .<br />
$ ln -s ../../install/include/mpfr.h .<br />
$ ln -s ../../install/include/gmp.h .</p>
<p><strong>Step #6 &#8211; Download &amp; Build GCC (~4.6)</strong></p>
<p style="text-align: justify;">I used GCC from git (fda0037801fb258a2191aba59e1e9f0df019e3b6) and I don&#8217;t know if it will work on newer versions. You&#8217;ll have to try. Sorry. [Howto: <a href="http://gcc.gnu.org/wiki/GitMirror" target="_blank">GitMirror</a>]. Use <em>git checkout </em>to specify one commit.</p>
<p style="padding-left: 30px;">$ cd ~/Projects/GCC/</p>
<p style="padding-left: 30px;">$ git clone git://gcc.gnu.org/git/gcc.git</p>
<p style="padding-left: 30px;">$ mkdir build<br />
$ mkdir install</p>
<p style="padding-left: 30px;">$ cd build<br />
$ ../gcc/configure &#8211;prefix=$(cd ../install/ &amp;&amp; pwd) &#8211;with-gmp=/Users/maluta/Projects/GCC/libs/install &#8211;with-mpfr=/Users/maluta/Projects/GCC/libs/install &#8211;with-mpc=/Users/maluta/Projects/GCC/libs/install &#8211;disable-checking  &#8211;enable-werror &#8211;enable-languages=c</p>
<p style="padding-left: 30px;">$ make<br />
$ make install</p>
<p><strong>Step #7 &#8211; Test</strong></p>
<p>The binary files will be placed in ~/Projects/GCC/install/bin</p>
<p style="padding-left: 30px;">$  ~/Projects/GCC/install/bin<br />
$  ./gcc -v</p>
<p style="padding-left: 30px;">Using built-in specs.<br />
COLLECT_GCC=./gcc<br />
COLLECT_LTO_WRAPPER=/Users/maluta/Projects/GCC/install/libexec/gcc/x86_64-apple-darwin10.4.0/4.6.0/lto-wrapper<br />
Target: x86_64-apple-darwin10.4.0<br />
Configured with: ../gcc/configure &#8211;prefix=/Users/maluta/Projects/GCC/install &#8211;with-gmp=/Users/maluta/Projects/GCC/libs/install &#8211;with-mpfr=/Users/maluta/Projects/GCC/libs/install &#8211;with-mpc=/Users/maluta/Projects/GCC/libs/install &#8211;disable-checking &#8211;enable-werror &#8211;enable-languages=c<br />
Thread model: posix<br />
gcc version 4.6.0 20100508 (experimental) (GCC)</p>
<p style="text-align: justify;">Although I focused on OSX build/installation the steps described are the same to any architecture. Build an compiler &#8211; especially a cross-compiler (no that case) &#8211; demands time and patience to understand many particularities.</p>
<p style="padding-left: 30px;">Enjoy <img src='http://www.coding.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/mac/building-gcc-4-6-on-macosx/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Opcode stats</title>
		<link>http://www.coding.com.br/embarcado/opcode-stats/</link>
		<comments>http://www.coding.com.br/embarcado/opcode-stats/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 00:09:50 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[embarcado]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1128</guid>
		<description><![CDATA[I was trying some GCC options and decided see how they affect assembly code generated. I&#8217;ve created a simple Python script that parses .s output and put in a human readable way. Suppose the classical Hello World program. The output will be something like:
$ python stats_opcodes.py file
For Cortex-m3 (check previous post):

At my laptop (x86):

 

Download the script here.
]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I was trying some GCC options and decided see how they affect assembly code generated. I&#8217;ve created a simple Python script that parses <em>.s</em> output and put in a human readable way. Suppose the classical <em>Hello World </em>program. The output will be something like:</p>
<p style="padding-left: 30px;">$ python stats_opcodes.py file</p>
<p>For Cortex-m3 (check <a href="http://www.coding.com.br/embarcado/cortex-m3-and-qemu/" target="_blank">previous</a> post):</p>
<p style="padding-left: 30px;"><img class="aligncenter size-full wp-image-1136" title="opcode-arm" src="http://www.coding.com.br/wp-content/uploads/2010/06/opcode-arm.png" alt="" width="304" height="194" /></p>
<p>At my laptop (x86):</p>
<p style="padding-left: 30px;"><img class="aligncenter size-full wp-image-1133" title="output" src="http://www.coding.com.br/wp-content/uploads/2010/06/opcodes1.png" alt="" width="306" height="194" /></p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: small;"><span style="line-height: 18px; white-space: pre;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: 19px; white-space: normal;"> </span></span></span></span></p>
<p style="text-align: center;">
<p>Download the script <a href="http://gist.github.com/raw/452170/db097f735c52ffd733d2060603c203982d53b79f/stats_opcode.py" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/embarcado/opcode-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assembly inline</title>
		<link>http://www.coding.com.br/programacao/assembly-inline/</link>
		<comments>http://www.coding.com.br/programacao/assembly-inline/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 02:20:11 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[programação]]></category>
		<category><![CDATA[asm]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=444</guid>
		<description><![CDATA[I&#8217;ve made some code snippets about assembly inline with GCC. A quick search points to a lot of good documentation.

IBM DeveloperWorks about Inline asssembly for x86 in Linux
Linux Documentation Project HOWTO describing GCC Inline Assembly 

The syntax may be confusing, if you don&#8217;t understand read the documentation available. Each example are an C function with [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I&#8217;ve made some code snippets about assembly inline with <a href="http://gcc.gnu.org/">GCC</a>. A <a href="http://www.google.com.br/search?sourceid=chrome&amp;ie=UTF-8&amp;q=assembly+inline+gcc">quick search</a> points to a lot of good documentation.</p>
<ul>
<li>IBM DeveloperWorks about <em><a href="http://www.ibm.com/developerworks/linux/library/l-ia.html" target="_blank">Inline asssembly for x86 in Linux</a></em></li>
<li>Linux Documentation Project HOWTO describin<em>g <a href="http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html">GCC Inline Assembly</a> </em></li>
</ul>
<p style="text-align: justify;">The syntax may be confusing, if you don&#8217;t understand read the documentation available. Each example are an C function with the special construct &#8220;asm&#8221; for inline assembly code. Examples:</p>
<p>Increment an value:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> inc<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    asm <span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;incl %0&quot;</span>
         <span style="color: #339933;">:</span><span style="color: #ff0000;">&quot;=a&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>value<span style="color: #009900;">&#41;</span>
         <span style="color: #339933;">:</span><span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>value<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Exchange to numbers:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> swap<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>x<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    asm<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span>
        <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;=a&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;=b&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>x<span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;b&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>y<span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Copy an vector:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> vector_copy<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>v_src<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>v_dst<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    asm<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;up: lodsl;&quot;</span>
	<span style="color: #ff0000;">&quot;    stosl;&quot;</span>
	<span style="color: #ff0000;">&quot;loop up;  &quot;</span>
	<span style="color: #339933;">:</span>
	<span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;S&quot;</span><span style="color: #009900;">&#40;</span>v_src<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;D&quot;</span><span style="color: #009900;">&#40;</span>v_dst<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;c&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>count<span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;%eax&quot;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A simple copy:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> copy<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>from<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>to<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
     asm <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;movl %1, %%eax;&quot;</span>
          <span style="color: #ff0000;">&quot;movl %%eax, %0;&quot;</span>
          <span style="color: #339933;">:</span><span style="color: #ff0000;">&quot;=&amp;amp;r&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>to<span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">:</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>from<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A very simple implementation for strncpy:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> _strncpy<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>src<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>dst<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    asm<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;cld;&quot;</span>
        <span style="color: #ff0000;">&quot;rep movsb;&quot;</span>
        <span style="color: #339933;">:</span>
        <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;S&quot;</span><span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// 'S' == %esi</span>
	  <span style="color: #ff0000;">&quot;D&quot;</span><span style="color: #009900;">&#40;</span>dst<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// 'D' == %edi</span>
	  <span style="color: #ff0000;">&quot;c&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 'c' == %ecx</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you like to try check this <a href="http://github.com/maluta/junk/blob/master/asm-inline.c">example</a>:</p>
<pre style="padding-left: 30px;">wget http://github.com/maluta/junk/raw/master/asm-inline.c
gcc -Wall -ggdb asm-inline.c -o asm-inline
./asm-inline</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/programacao/assembly-inline/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
