<?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>编译点滴 &#187; 工具链</title>
	<atom:link href="http://www.lingcc.com/tag/%e5%b7%a5%e5%85%b7%e9%93%be/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lingcc.com</link>
	<description>编译器、虚拟机、程序设计语言、体系结构、软件调试、操作系统等等</description>
	<lastBuildDate>Sat, 04 Feb 2012 06:56:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>《多核技术讲习班》记&#8211;讨论会</title>
		<link>http://www.lingcc.com/2010/07/07/11010/</link>
		<comments>http://www.lingcc.com/2010/07/07/11010/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 10:59:40 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[编译前沿]]></category>
		<category><![CDATA[编译器相关招聘信息]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[Godson-T]]></category>
		<category><![CDATA[华为]]></category>
		<category><![CDATA[多核]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[并行]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[编译器]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=11010</guid>
		<description><![CDATA[此次讲习班，因为没有资助，没钱参加。所以本博只厚着脸皮蹭了最后的讨论会。会上，来自全国不少地方的学生、老师都在，踊跃发言提问。Godson-T是热点，但因为本博做编译，呵呵，所以当时记录时，着眼这方面的较多。各位看官谅解。 问：一个好的串行算法很可能无法被充分并行化，怎么看这个问题？好的串行算法，为了获得高性能，会根据串行的特点，CPU的特点，编译器都特点和应用的特点设计，但并行是换了一个思路来跑程序， 丁：比较成功的经验是采用演进式的方法，在串行程序中寻找可能的并行机会，将其并行。实现逐渐将串行程序并行化。重要的是如何给程序员提供一个界面，找到并呈现程序中潜在的可能并行机会，引导程序员将程序并行化。换一个角度去向这个问题的话，写程序不一定是符合人类思维模式的方式。人脑在思考如何解决一个问题的时候，并不是采用写程序式的思维模式，人脑在思考问题时，是并行着想问题的。 胡：高老师的学生曾经对SPEC CPU 标准测试程序中的例子做过分析，分析过程中发现绝大部分例子，即使是串行程序，都存在很大的并行潜力，只是程序员在写程序的过程中，并没有完全考虑到而已。 陈：渐进式的并行化方式，曾经自己项目组都学生做过，性能提升很有限。和线程级投机、事务内存能带来的性能提升很有限一样。在四核的机器上，能有30%的加速，已经是非常理想的结果了。如果只有一两倍的性能提升，没有人愿意改写现有的软件代码，因为成本太高。 范：Godson-T的情况，基本都是在模拟器上做。计划最近做出实际的芯片来。16核以上时，模拟器性能太有限。《多核编译技术研讨会》记一中提到的Intel玩具级CPU，其实仅仅提供了20多条指令。用来演示的系统，主机箱还没有机器背后的冷却器大。2D的芯片设计因为片子越来越大，已经很难继续，3D的散热则是很大的问题，还有准确性问题。不过目前美国已经有技术能让冷却水进入3D器件内部。 问：体系结构的发展趋势是要走向和应用领域结合，但这样就陷入了矛盾。要在片子中加入很多应用领域相关的加速，就意味着片子的商业化和销量受到极大的制约，而且流片的成本也越来越高。但通用些的话性能又很难上去，怎么看？ 范：从做芯片的人的角度出发，觉得未来是要越通用越好，因为这样片子适合更多的人，才能卖出去。否则成本降不下来，没人再愿意做。 胡：从应用领域的人来讲，是要专一些，但不能太专。专一些，可以把针对某些特殊处理的应用速度提上去。华为曾经做过一些集成FFT的片子，虽然能带来不小的加速，但因为通信标准经常会变动，一变就意味着重新设计片子，成本太大。所以后来放弃这种形式。而且片子太专的话，软件迁移的成本也越来越高。现在的趋势，应该是针对比如网络应用中的特殊处理加入一些硬件优化，这种优化要尽量通用一些。 Open64对于OpenMP的支持如何？ 陈：Open64已经能支持OpenMP 2.0标准。对OpenMP 3.0的标准开发缓慢。原因是OpenMP 3.0的标准过于复杂，难以实现。而且很容易出错。没有人愿意那样用它。现在OpenMP虽然有官方的委员会和学术交流，但也基本是OpenMP 委员会那帮人在自娱自乐。前途渺茫。 PS 1：写这篇文章时，丁晨老师和我直线距离5米内。唉，只是俺这个粉丝没啥能向这位名师请教的，层次问题！层次问题！ PS 2：华为的编译团队，目前主要分布在美国、北京和杭州三块。美国有不到十个人，负责前沿性质的项目预研。国内北京有十几个人，负责网络平台的编译优化；杭州有三十多人，负责华为内部的开发工具链的维护和优化。华为内部的编译器有两个，一个GCC，一个商用编译器。 华为，这么多年，低调的做公司做技术，网罗了一大批顶尖的通信、电子、计算机领域的华人。技术当家的通信领域，相信华为会越走越好，祝华为的编译团队越来越壮大。 相关文章： 好消息：GodSon-T第一款芯片已经流片归来，正在测试 多面体模型是编译器循环优化的未来吗？ 《多核技术讲习班》记&#8211;牛人们 关于并行貌似正确的废话&#8211;串行已经尽力了 探秘CPU性能测试：Spec CPU2000之整点篇 前瞻-全时优化和LLVM-1<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F06%2F11003%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《多核技术讲习班》记–牛人们</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F19%2F9986%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-引言</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F12%2F9985%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-摘要</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F04%2F10224%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《多核编译技术研讨会》记一</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F21%2F11371%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">好消息：GodSon-T第一款芯片已经流片归来，正在测试</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/10/21/11371/' rel='bookmark' title='好消息：GodSon-T第一款芯片已经流片归来，正在测试'>好消息：GodSon-T第一款芯片已经流片归来，正在测试</a></li>
<li><a href='http://www.lingcc.com/2010/07/16/11081/' rel='bookmark' title='多面体模型是编译器循环优化的未来吗？'>多面体模型是编译器循环优化的未来吗？</a></li>
<li><a href='http://www.lingcc.com/2010/07/06/11003/' rel='bookmark' title='《多核技术讲习班》记&#8211;牛人们'>《多核技术讲习班》记&#8211;牛人们</a></li>
<li><a href='http://www.lingcc.com/2010/06/12/10969/' rel='bookmark' title='关于并行貌似正确的废话&#8211;串行已经尽力了'>关于并行貌似正确的废话&#8211;串行已经尽力了</a></li>
<li><a href='http://www.lingcc.com/2010/04/14/10736/' rel='bookmark' title='探秘CPU性能测试：Spec CPU2000之整点篇'>探秘CPU性能测试：Spec CPU2000之整点篇</a></li>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>此次讲习班，因为没有资助，没钱参加。所以本博只厚着脸皮蹭了最后的讨论会。会上，来自全国不少地方的学生、老师都在，踊跃发言提问。Godson-T是热点，但因为本博做编译，呵呵，所以当时记录时，着眼这方面的较多。各位看官谅解。<span id="more-11010"></span></p>
<ul>
<li>问：一个好的串行算法很可能无法被充分并行化，怎么看这个问题？好的串行算法，为了获得高性能，会根据串行的特点，CPU的特点，编译器都特点和应用的特点设计，但并行是换了一个思路来跑程序，
<ul>
<li>丁：比较成功的经验是采用演进式的方法，在串行程序中寻找可能的并行机会，将其并行。实现逐渐将串行程序并行化。重要的是如何给程序员提供一个界面，找到并呈现程序中潜在的可能并行机会，引导程序员将程序并行化。换一个角度去向这个问题的话，写程序不一定是符合人类思维模式的方式。人脑在思考如何解决一个问题的时候，并不是采用写程序式的思维模式，人脑在思考问题时，是并行着想问题的。</li>
<li>胡：高老师的学生曾经对SPEC CPU 标准测试程序中的例子做过分析，分析过程中发现绝大部分例子，即使是串行程序，都存在很大的并行潜力，只是程序员在写程序的过程中，并没有完全考虑到而已。</li>
<li>陈：渐进式的并行化方式，曾经自己项目组都学生做过，性能提升很有限。和线程级投机、事务内存能带来的性能提升很有限一样。在四核的机器上，能有30%的加速，已经是非常理想的结果了。如果只有一两倍的性能提升，没有人愿意改写现有的软件代码，因为成本太高。</li>
</ul>
</li>
<li>范：Godson-T的情况，基本都是在模拟器上做。计划最近做出实际的芯片来。16核以上时，模拟器性能太有限。<a href="http://www.lingcc.com/2009/12/04/10224/" target="_blank">《多核编译技术研讨会》记一</a>中提到的Intel玩具级CPU，其实仅仅提供了20多条指令。用来演示的系统，主机箱还没有机器背后的冷却器大。2D的芯片设计因为片子越来越大，已经很难继续，3D的散热则是很大的问题，还有准确性问题。不过目前美国已经有技术能让冷却水进入3D器件内部。</li>
<li>问：体系结构的发展趋势是要走向和应用领域结合，但这样就陷入了矛盾。要在片子中加入很多应用领域相关的加速，就意味着片子的商业化和销量受到极大的制约，而且流片的成本也越来越高。但通用些的话性能又很难上去，怎么看？
<ul>
<li>范：从做芯片的人的角度出发，觉得未来是要越通用越好，因为这样片子适合更多的人，才能卖出去。否则成本降不下来，没人再愿意做。</li>
<li>胡：从应用领域的人来讲，是要专一些，但不能太专。专一些，可以把针对某些特殊处理的应用速度提上去。华为曾经做过一些集成FFT的片子，虽然能带来不小的加速，但因为通信标准经常会变动，一变就意味着重新设计片子，成本太大。所以后来放弃这种形式。而且片子太专的话，软件迁移的成本也越来越高。现在的趋势，应该是针对比如网络应用中的特殊处理加入一些硬件优化，这种优化要尽量通用一些。</li>
</ul>
</li>
<li>Open64对于OpenMP的支持如何？
<ul>
<li>陈：Open64已经能支持OpenMP 2.0标准。对OpenMP 3.0的标准开发缓慢。原因是OpenMP 3.0的标准过于复杂，难以实现。而且很容易出错。没有人愿意那样用它。现在OpenMP虽然有官方的委员会和学术交流，但也基本是OpenMP 委员会那帮人在自娱自乐。前途渺茫。</li>
</ul>
</li>
</ul>
<p>PS 1：写这篇文章时，丁晨老师和我直线距离5米内。唉，只是俺这个粉丝没啥能向这位名师请教的，层次问题！层次问题！</p>
<p>PS 2：华为的编译团队，目前主要分布在美国、北京和杭州三块。美国有不到十个人，负责前沿性质的项目预研。国内北京有十几个人，负责网络平台的编译优化；杭州有三十多人，负责华为内部的开发工具链的维护和优化。华为内部的编译器有两个，一个GCC，一个商用编译器。</p>
<p>华为，这么多年，低调的做公司做技术，网罗了一大批顶尖的通信、电子、计算机领域的华人。技术当家的通信领域，相信华为会越走越好，祝华为的编译团队越来越壮大。</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F06%2F11003%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《多核技术讲习班》记–牛人们</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F19%2F9986%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-引言</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F12%2F9985%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-摘要</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F04%2F10224%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《多核编译技术研讨会》记一</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F21%2F11371%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F07%2F11010%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">好消息：GodSon-T第一款芯片已经流片归来，正在测试</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/10/21/11371/' rel='bookmark' title='好消息：GodSon-T第一款芯片已经流片归来，正在测试'>好消息：GodSon-T第一款芯片已经流片归来，正在测试</a></li>
<li><a href='http://www.lingcc.com/2010/07/16/11081/' rel='bookmark' title='多面体模型是编译器循环优化的未来吗？'>多面体模型是编译器循环优化的未来吗？</a></li>
<li><a href='http://www.lingcc.com/2010/07/06/11003/' rel='bookmark' title='《多核技术讲习班》记&#8211;牛人们'>《多核技术讲习班》记&#8211;牛人们</a></li>
<li><a href='http://www.lingcc.com/2010/06/12/10969/' rel='bookmark' title='关于并行貌似正确的废话&#8211;串行已经尽力了'>关于并行貌似正确的废话&#8211;串行已经尽力了</a></li>
<li><a href='http://www.lingcc.com/2010/04/14/10736/' rel='bookmark' title='探秘CPU性能测试：Spec CPU2000之整点篇'>探秘CPU性能测试：Spec CPU2000之整点篇</a></li>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/07/07/11010/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>认识静态链接库</title>
		<link>http://www.lingcc.com/2010/05/25/10951/</link>
		<comments>http://www.lingcc.com/2010/05/25/10951/#comments</comments>
		<pubDate>Tue, 25 May 2010 13:33:01 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[系统软件及库]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[compiler infrastructure]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[操作系统 Operating system]]></category>
		<category><![CDATA[系统健壮性]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[编译器开发]]></category>
		<category><![CDATA[运行时技术]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10951</guid>
		<description><![CDATA[介绍静态链接库是什么，为何要有静态链接库，动态链接库和共享库，如何使用，创建，编辑静态练级库。<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GNU工具链学习笔记</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC中的pie和fpie选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F11%2F11300%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">软链接和硬链接</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F19%2F9897%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">经验之谈:做好预防措施,保护好自己的电脑的13个Tips</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/07/10916/' rel='bookmark' title='期待未来-一张趣图'>期待未来-一张趣图</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/07/16/11081/' rel='bookmark' title='多面体模型是编译器循环优化的未来吗？'>多面体模型是编译器循环优化的未来吗？</a></li>
<li><a href='http://www.lingcc.com/2008/08/27/9982/' rel='bookmark' title='zz Linux下的段错误的原因及调试'>zz Linux下的段错误的原因及调试</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<h4>什么是静态链接库？</h4>
<p>静态链接库，即static library或 statically-linked library。和动态链接库，即dynamic library 或dynamicly-linked library相对，是Windows和Linux系统中比较常用的库文件。Windows中分别用SLL和DLL文件表示，Linux中分别是.a和.so文件.</p>
<p>静态链接库实际是一些object files(.o文件)和头文件的压缩包，通过GNU工具链中的ar(archiver)程序创建。</p>
<h5>静态链接库、动态链接库和共享库</h5>
<p>那为何还要有动态链接库呢？静态练级库虽然能很好的节省编译时间。对于一个简单的ls程序，我们需要有屏幕输出，有字符串和格式操作，有文件系统访问等等函数，都要在一个程序中。此时，这个程序会很大。一个小小的ls可能都会有好几兆。如果还有个rm程序，同样也需要屏幕输出，文件系统访问。那么这两个东西，我们可以放到两个库文件里，在执行ls，或者rm的时候，用到屏幕输出操作，就将相应的函数对应的机器码载入内存中，执行。然后再从内存中释放。接着载入文件系统访问的相关函数。这样我们的程序就能变小很多。这种可以动态装载到内存中的库文件就是动态链接库了。Windows下的DLL文件就是动态链接库。</p>
<p><span id="more-10951"></span></p>
<p>还有个问题，其实ls和rm使用的屏幕输出函数是一样的。内存很小的时候，同时执行ls和rm，有必要同时载入两份相同的代码到内存中吗？于是就有了共享库，不同的程序可以共享相同的代码。都可以访问，执行。于是就有了共享库的概念。Linux下的.so文件就是共享库。</p>
<p>这时候又有个问题，程序执行时，访存，跳转的地址是一定的，那两个程序又如何共享相同的库代码呢？这就靠位置无关的代码生成了。本博曾经写过文章介绍它们，请参考<a href="http://www.lingcc.com/2009/11/20/10065/" target="_blank">Gcc和Open64中的-fPIC选项</a> 和<a href="http://www.lingcc.com/2010/01/08/10609/" target="_blank">GCC中的pie和fpie选项</a>两篇文章。</p>
<p>下图是关于共享库和静态链接库的示意图，可以简单看出些区别。</p>
<div id="attachment_10952" class="wp-caption alignnone" style="width: 351px"><a href="http://www.lingcc.com/wp-content/uploads/2010/05/figure2.gif"><img class="size-full wp-image-10952" title="静态链接库和共享库" src="http://www.lingcc.com/wp-content/uploads/2010/05/figure2.gif" alt="" width="341" height="265" /></a><p class="wp-caption-text">静态链接库和共享库</p></div>
<h4>为什么要有静态链接库？</h4>
<p>首先，随着程序规模的增加，有些常用函数可能不需要每次都编译，于是就可以把它们作为库的方式来存放。这样用户就能很方便的链接生成最后的程序，不用一遍遍的重新编译某些常用程序文件。必须内核，硬件驱动，文件系统，glibc等等库文件，一些基本函数都采用了这种形式。</p>
<p>其次，一些闭源代码，可以通过库的方式来发布，这样可以保证代码不公开。</p>
<p>再次，相比动态链接的程序，或者共享库程序，连接到静态库的程序会快1%-5%左右。</p>
<p>另外，有些特殊环境，必须使用静态链接库。比如在Linux系统，需要chroot到另一个系统环境中时，动态链接库就不再起作用，因为那些是在原来系统的文件树下，如/usr/lib.但在chroot的环境中，无法访问。</p>
<h4>怎么用静态链接库？</h4>
<p>既然静态链接库的出现，是为了缩短编译时间。而普通可执行程序又可以分为静态链和动态链两种形式。因此我们就分开介绍之，原因无他，只是想顺便介绍一下动态链可执行程序和静态链可执行程序在运行时的一些区别。</p>
<p>对于静态链接库的应用，加上-lname，就会链接libname.a这个静态链接库文件。一般静态链接库文件的搜索路径为系统默认的路径，如/usr/lib/和当前路径。你也可以用过-L选项，指定GCC搜索某个特定文件夹。注意-l和-L的参数要加载待编译源码文件之后。</p>
<p>静态链接库既可以在编译时用于生成单个可执行文件，也可以在运行时根据编译或者连接时确定的静态偏移量载入内存中。</p>
<h5>编译静态链接可执行程序</h5>
<p>编译静态链可执行程序,对于gcc，只要加上-static即可。</p>
<p>编译时，程序中若有对库函数的调用，编译器或者连接器就会将库中相应的代码拷贝到目标文件中，生成一个独立的可执行文件。</p>
<h5>编译动态链接可执行程序</h5>
<p>不加-static编译生成的可执行程序都是动态链接的，编译时所做工作很少，仅仅记录了该程序需要什么库函数，以及该库函数在库中到索引。</p>
<p>但对于动态链接程序，在系统启动该可执行程序时，装载器loader必须能找到相应的共享库文件.so文件或者静态链接库文件.a(已经很少使用这种形式了)，并将其载入内存中，一般的，有两种途径可以指定链接库文件的位置，</p>
<ul>
<li>编译动态链接可执行程序时，通过rpath指定，这个可以在编译时增加选项-Wl,-rpath=DIRS.这种方式不需要在运行时做任何修改，该选项会在连接时，写入可执行程序中。</li>
<li>运行时由ld.so指定。默认共享库搜索路径是/usr/local/lib，/usr/lib以及当前目录，你可以通过修改$LD_LIBRARY_PATH变量修改。系统管理员也可以在/etc/profile中修改，以便对所有用户有效。当然修改/etc/ld.so.conf也行，这样所有的程序都将更改寻找链接库文件的路径。</li>
</ul>
<div id="attachment_10953" class="wp-caption alignnone" style="width: 487px"><a href="http://www.lingcc.com/wp-content/uploads/2010/05/confused.jpg"><img class="size-full wp-image-10953" title="很晕吧" src="http://www.lingcc.com/wp-content/uploads/2010/05/confused.jpg" alt="" width="477" height="358" /></a><p class="wp-caption-text">很晕吧</p></div>
<h4>静态链接库的常用操作</h4>
<h5>制作静态链接库</h5>
<p><code>$ar rcs liba.a a.o b.o c.o a_header.h b_header.h</code></p>
<p>上面命令，将a.o, b.o, c.o, a_header.h, b_header.h作成静态链接库liba.a.</p>
<ul>
<li>选项r：将 .o , .h文件插入到liba.a文件中</li>
<li>c:创建一个压缩文件。</li>
<li>s：将.o文件的索引信息写入压缩文件中，或者升级已有索引。这和执行 ranlib liba.a的效果过一样。索引信息会存在压缩包的一个符号文件夹内，连接器可以通过名称找到位置，这样可以加速连接时间。</li>
</ul>
<h5>解压静态链接库</h5>
<p><code>$ar xv liba.a</code></p>
<p>该命令会把liba.a中所有的文件解压缩到当前目录下。</p>
<ul>
<li>x：解压缩该压缩包</li>
<li>v：可视化，解压缩同时输出到屏幕</li>
</ul>
<h5>查看内容</h5>
<p><code>$nm --print-armap liba.a</code></p>
<p>该命令查看liba.a中包含哪些文件，每个文件中包含哪些函数。</p>
<ul>
<li>在列出压缩包中所有文件中的符号，同时包含索引：每个元素到符号的映射</li>
</ul>
<h5>实践：</h5>
<p>本文不再给出具体实践，可以参考<a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html" target="_blank">An Introduction to GCC &#8211; Shared libraries and static libraries</a></p>
<h4>参考：</h4>
<ol>
<li><a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html">http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html</a></li>
<li><a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html"></a><a href="http://en.wikipedia.org/wiki/Static_library">http://en.wikipedia.org/wiki/Static_library</a></li>
<li><a href="http://cpp.codenewbie.com/articles/cpp/1444/Static_Link_Librarys-Page_1.html">http://cpp.codenewbie.com/articles/cpp/1444/Static_Link_Librarys-Page_1.html</a></li>
<li><a href="http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html">http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html</a></li>
<li><a href="http://www.faqs.org/docs/linux_scratch/chapter05/whystatic.html">http://www.faqs.org/docs/linux_scratch/chapter05/whystatic.html</a></li>
<li><a href="http://en.wikipedia.org/wiki/Dynamic-link_library">http://en.wikipedia.org/wiki/Dynamic-link_library</a></li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-dynamic-libraries/index.html" target="_blank">http://www.ibm.com/developerworks/linux/library/l-dynamic-libraries/index.html</a></li>
</ol>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GNU工具链学习笔记</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC中的pie和fpie选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F11%2F11300%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">软链接和硬链接</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F19%2F9897%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">经验之谈:做好预防措施,保护好自己的电脑的13个Tips</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/07/10916/' rel='bookmark' title='期待未来-一张趣图'>期待未来-一张趣图</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/07/16/11081/' rel='bookmark' title='多面体模型是编译器循环优化的未来吗？'>多面体模型是编译器循环优化的未来吗？</a></li>
<li><a href='http://www.lingcc.com/2008/08/27/9982/' rel='bookmark' title='zz Linux下的段错误的原因及调试'>zz Linux下的段错误的原因及调试</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/05/25/10951/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于《编译点滴》的定位和未来</title>
		<link>http://www.lingcc.com/2010/04/27/10782/</link>
		<comments>http://www.lingcc.com/2010/04/27/10782/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 04:42:58 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[程序员生活]]></category>
		<category><![CDATA[blog心得]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[LLVM]]></category>
		<category><![CDATA[N64]]></category>
		<category><![CDATA[Open64]]></category>
		<category><![CDATA[个人建站]]></category>
		<category><![CDATA[后端]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[并行]]></category>
		<category><![CDATA[并行计算]]></category>
		<category><![CDATA[编译器]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10782</guid>
		<description><![CDATA[独立博客该有点什么，该写点什么，在编译点滴建站接近半年的后，忽然间有点迷茫。编译点滴该放点什么东西，博客该记录点什么，什么是该记录的，什么不该记录。虽然概括之就是自己觉得好的都能往上放。 看看现在博客里的文档，太散太杂。虽然刚刚建博的时候，很是花了一些心思写文章，找主题。但到博客的界面主题倒是换了不少，但内容实在是有点对不起观众。高达70%的跳出率说明了一切：） 幸好无意中看到了一个博客，观摩了半天后，对《编译点滴》的未来有了些想法。顺便推荐这个博客《我爱自然语言处理》。作者很用心的写了很多和自然语言处理相关的文章。博客文章很系统，自成体系。 《编译点滴》以后将逐渐对内容分类做出调整。分类目录中，对科技-专业细分为： 1，编译理论实践和应用：包括前端，中端和后端的各种分析处理；介绍编译器，解释器实现技术等内容；介绍编译技术在其他领域内的应用。 2，编译前沿：介绍最新提出的一些编译技术，思想和方法。包括与此相关的语言扩展及分析处理。 3，Open64：介绍Open64编译器相关内容和最新进展. 4，LLVM：介绍LLVM编译器相关内容和最新进展。 5，GCC：介绍GCC编译器及GNU工具链相关内容 6，算法和计算理论：讨论算法，并行计算和其他计算理论相关内容及实践 7，程序开发相关：讨论日常工作中遇到的实际问题及解决方法和经验积累。 日后，编译点滴将添加更多和编译器构建，原理相关的内容，资料和实践。力图做成每个编译爱好者都想订阅的站点：） 任重道远！ 相关文章： 推荐文章(未完成) 前瞻-全时优化和LLVM-1 前瞻-LLVM大事记(2004-2010) GCC初窥 Open64课程&#8211;OpenMp和自动并行化 Open64课程-结语<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F25%2F10418%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64课程–OpenMp和自动并行化</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F03%2F10204%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">最近Open64动作不小</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F12%2F9984%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-译者注</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F12%2F9985%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-摘要</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/com-lib/compiler-articles/' rel='bookmark' title='推荐文章(未完成)'>推荐文章(未完成)</a></li>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/25/10418/' rel='bookmark' title='Open64课程&#8211;OpenMp和自动并行化'>Open64课程&#8211;OpenMp和自动并行化</a></li>
<li><a href='http://www.lingcc.com/2009/12/28/10469/' rel='bookmark' title='Open64课程-结语'>Open64课程-结语</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>独立博客该有点什么，该写点什么，在编译点滴建站接近半年的后，忽然间有点迷茫。编译点滴该放点什么东西，博客该记录点什么，什么是该记录的，什么不该记录。虽然概括之就是自己觉得好的都能往上放。<br />
看看现在博客里的文档，太散太杂。虽然刚刚建博的时候，很是花了一些心思写文章，找主题。但到博客的界面主题倒是换了不少，但内容实在是有点对不起观众。高达70%的跳出率说明了一切：）<br />
幸好无意中看到了一个博客，观摩了半天后，对《编译点滴》的未来有了些想法。顺便推荐这个博客<a href="http://www.52nlp.cn/">《我爱自然语言处理》</a>。作者很用心的写了很多和自然语言处理相关的文章。博客文章很系统，自成体系。<br />
<span id="more-10782"></span><br />
《编译点滴》以后将逐渐对内容分类做出调整。分类目录中，对科技-专业细分为：<br />
1，编译理论实践和应用：包括前端，中端和后端的各种分析处理；介绍编译器，解释器实现技术等内容；介绍编译技术在其他领域内的应用。<br />
2，编译前沿：介绍最新提出的一些编译技术，思想和方法。包括与此相关的语言扩展及分析处理。<br />
3，Open64：介绍Open64编译器相关内容和最新进展.<br />
4，LLVM：介绍LLVM编译器相关内容和最新进展。<br />
5，GCC：介绍GCC编译器及GNU工具链相关内容<br />
6，算法和计算理论：讨论算法，并行计算和其他计算理论相关内容及实践<br />
7，程序开发相关：讨论日常工作中遇到的实际问题及解决方法和经验积累。</p>
<p>日后，编译点滴将添加更多和编译器构建，原理相关的内容，资料和实践。力图做成每个编译爱好者都想订阅的站点：）<br />
任重道远！</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F25%2F10418%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64课程–OpenMp和自动并行化</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F03%2F10204%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">最近Open64动作不小</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F12%2F9984%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-译者注</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F04%2F12%2F9985%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">并行计算前景-摘要</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F27%2F10782%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/com-lib/compiler-articles/' rel='bookmark' title='推荐文章(未完成)'>推荐文章(未完成)</a></li>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/25/10418/' rel='bookmark' title='Open64课程&#8211;OpenMp和自动并行化'>Open64课程&#8211;OpenMp和自动并行化</a></li>
<li><a href='http://www.lingcc.com/2009/12/28/10469/' rel='bookmark' title='Open64课程-结语'>Open64课程-结语</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/04/27/10782/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>前瞻-全时优化和LLVM-1</title>
		<link>http://www.lingcc.com/2010/04/07/10721/</link>
		<comments>http://www.lingcc.com/2010/04/07/10721/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 14:30:56 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[LLVM]]></category>
		<category><![CDATA[编译前沿]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[编译理论实践和应用]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[N64]]></category>
		<category><![CDATA[Open64]]></category>
		<category><![CDATA[SSA]]></category>
		<category><![CDATA[中间表示]]></category>
		<category><![CDATA[全时优化]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[空闲时优化]]></category>
		<category><![CDATA[编程技术]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[编译器设计]]></category>
		<category><![CDATA[虚拟机]]></category>
		<category><![CDATA[过程间优化]]></category>
		<category><![CDATA[运行时技术]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10721</guid>
		<description><![CDATA[读论文&#60;LLVM: A Compilation Framework for Lifelong Program Analysis &#38; Transformation&#62; CGO 04 1，写在前面的话 全时优化(LifeLong Optimization)对于每个编译爱好者来说，太有魅力了。我在起初也是被这个题目所吸引打算一探究竟。本文是04年LLVM的最早两位开发者Chris Lattner和Vikram Adve所写，发表在04年的CGO上， 先来说说LLVM的历史。2000年LLVM开始开发，2005年Apple雇了Chris Lattner，LLVM也相当于成了Apple的官方支持的编译器。Apple已经将它用在OpenCL的流水线优化，Xcode已经能使用llvm-gcc编译代码。可以说05年之前LLVM一直都是学术界的东西，05年之后用于工业界.而这篇文章写在04年.本博最近听过一个关于LLVM的讨论会，会中有资深人士提到LLVM现在越来越像一个普通的编译器。说这番话的意思是，我们可以从这篇文章里找到LLVM的架构设计和早期的一些实现思想，但请不要迷信LLVM现在有多么神奇，每个架构都会有它的优缺点。 这篇文章，我现在已经读完了理论和介绍部分，性能评测部分还没有读。所以标题里面加了个1，因为接下来，还想作几件事，一是读完文章，二是跟踪一下Chris Lattner最近几年的文章，三是尝试将Open64和LLVM做个对比，最后看看代码。所以敬请期待之后的系列文章。 2.总览 先来解释Lifetime:文中分为编译时，链接时，安装时，运行时，空闲时五个阶段。这五个阶段都存在着优化机会：编译时的普通静态优化；链接时的过程间优化；安装时的目标机相关优化；运行时的动态优化和空闲时的profile制导优化。LLVM最早的设计就是针对以上几种优化进行的。 既然需要运行时和空闲时优化，就必须有必要的运行时环境和profile插装方式。因此注定LLVM的中间表示将占据非常重要的位置。编译和链接是为了生成中间表示，运行和空闲时则需要对中间表示的解释和执行。因此LLVM用上了目前编译所开发的所有技术:静态编译优化，JIT，虚拟机，解释器，运行时技术等等。也注定了LLVM要有一整套的工具链和环境来完成上述工作。 作者给出了LLVM架构设计中由于支持全时优化的五个特性，并支持现阶段，并无任何一种系统能同时具备这五个特性，不管是编译器，虚拟机还是其他系统。这五个特性是： 保持程序信息不变 离线本地代码生成 基于用户的profile和优化 透明的运行时模型 统一的全程序编译。 作者从两个角度来论述LLVM对全时优化的支持，一是LLVM的中间表示设计；二是LLVM的整体架构设计。 3.中间表示 LLVM的中间表示采取类RISC指令集，但包含关键的高层类型信息，精确控制流图和数据流图。LLVM的中间表示的几个特性：低层，语言无关的类型系 统；提供保存类型信息又能做类型转换和底层地址运算的指令；两个底层例外处理指令。LLVM中间表示之所以能做到与源程序独立，是因为它使用了比汇编稍大 的底层指令级及存储模型但并不暴露任何实际运行时需求和源程序语义需求。这种中间表示也决定了LLVM的局限性，对于源源转换之类的优化，LLVM就无法 直接在中间表示发力。 作者主要从五个方面介绍了LLVM中间表示的特点：指令集、语言无关的类型信息、存储模型、例外处理截止和三种中间表示形式相互透明(普通文本，二进制和内存中) 指令集： LLVM的中间表示采用原始处理器中的关键操作，回避物理寄存器、流水线、底层调用转换等细节，但为虚拟寄存器提供了集中类型(布尔型、整型、浮点型、指针),这些虚拟寄存器都采用SSA的形式。LLVM中有31个指令，多数采用了类型重载，且多为三地址形式.LLVM的每个虚拟寄存器都使用SSA的形式，而存储位置则不是SSA，这是因为存储可能存在别名。虚拟寄存器采用SSA能带来精确的定义-使用关系。另外LLVM也简化了控制流图，每个函数都转化为基本块的集合。每个基本块都有LLVM指令序列组成，结束基本块都有一个退出指令，如return，unwind，invoke。 语言无关的类型信息： LLVM中每个SSA 虚拟寄存器和存储对象都有和其关联的类型，所有的操作也都有严格的类型规则。LLVM的类型系统包括了如下类型:void,bool, signed/unsigned int(8bit to 64bit),single float,double float和四种衍生类型：pointer,array,structure和function。作者认为很多高层的类型都能使用这些类型表示。如C++中的类继承就能使用structure,function和function pointer array 来表示；而且作者也认为以上这些类型基本胜任经典的语言无关的程序分析和优化。因为LLVM的中间表示层次低，就需要支持弱类型语言，因此为提高在LLVM程序中声明类型的可靠性，LLVM使用一些指针分析算法来来判断所访问的内存与指针的类型是否可以可靠的相互转换。LLVM的类型转换仅能通过cast指令从一种类型转换为另一种类型。LLVM的指针算术运算通过getelementptr来实现，该指令力保在做地址运算时指令安全。load和store指令则只负责取和存。 精确存储分配和统一存储模型： LLVM通过三个指令实现存储操作：malloc，free和alloca。malloc负责在堆上分配带类型的存储位置；free负责释放malloc分配的存储空间；alloca和malloc相似，它分配的是在当前栈帧內分配存储而非堆，该内存将在函数返回时自动收回。LLVM中所有地址对象都被精确分配地址。全局变量和函数定义都被分配一个对象地址。这使得一个 统一的存储模型被建立。 函数调用和例外处理： <a href='http://www.lingcc.com/2010/04/07/10721/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM 2.7 发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F12%2F08%2F11882%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">你好，LLVM 3.0</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/04/29/10728/' rel='bookmark' title='前瞻-全时优化和LLVM-2'>前瞻-全时优化和LLVM-2</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2009/11/19/10024/' rel='bookmark' title='Open64课程-编译过程'>Open64课程-编译过程</a></li>
<li><a href='http://www.lingcc.com/2009/12/14/10295/' rel='bookmark' title='open64课程&#8211;过程间分析优化(IPA)'>open64课程&#8211;过程间分析优化(IPA)</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>读论文&lt;<a href="http://llvm.org/pubs/2004-01-30-CGO-LLVM.html" target="_blank">LLVM: A Compilation Framework for Lifelong Program Analysis &amp; Transformation</a>&gt; CGO 04</p>
<h3>1，写在前面的话</h3>
<p>全时优化(LifeLong Optimization)对于每个编译爱好者来说，太有魅力了。我在起初也是被这个题目所吸引打算一探究竟。本文是04年LLVM的最早两位开发者Chris Lattner和Vikram Adve所写，发表在04年的CGO上，</p>
<p>先来说说LLVM的历史。2000年LLVM开始开发，2005年Apple雇了Chris Lattner，LLVM也相当于成了Apple的官方支持的编译器。Apple已经将它用在OpenCL的流水线优化，Xcode已经能使用llvm-gcc编译代码。可以说05年之前LLVM一直都是学术界的东西，05年之后用于工业界.而这篇文章写在04年.本博最近听过一个关于LLVM的讨论会，会中有资深人士提到LLVM现在越来越像一个普通的编译器。说这番话的意思是，我们可以从这篇文章里找到LLVM的架构设计和早期的一些实现思想，但请不要迷信LLVM现在有多么神奇，每个架构都会有它的优缺点。</p>
<p>这篇文章，我现在已经读完了理论和介绍部分，性能评测部分还没有读。所以标题里面加了个1，因为接下来，还想作几件事，一是读完文章，二是跟踪一下Chris Lattner最近几年的文章，三是尝试将Open64和LLVM做个对比，最后看看代码。所以敬请期待之后的系列文章。<br />
<span id="more-10721"></span></p>
<h3>2.总览</h3>
<p>先来解释Lifetime:文中分为编译时，链接时，安装时，运行时，空闲时五个阶段。这五个阶段都存在着优化机会：编译时的普通静态优化；链接时的过程间优化；安装时的目标机相关优化；运行时的动态优化和空闲时的profile制导优化。LLVM最早的设计就是针对以上几种优化进行的。</p>
<p>既然需要运行时和空闲时优化，就必须有必要的运行时环境和profile插装方式。因此注定LLVM的中间表示将占据非常重要的位置。编译和链接是为了生成中间表示，运行和空闲时则需要对中间表示的解释和执行。因此LLVM用上了目前编译所开发的所有技术:静态编译优化，JIT，虚拟机，解释器，运行时技术等等。也注定了LLVM要有一整套的工具链和环境来完成上述工作。</p>
<p>作者给出了LLVM架构设计中由于支持全时优化的五个特性，并支持现阶段，并无任何一种系统能同时具备这五个特性，不管是编译器，虚拟机还是其他系统。这五个特性是：</p>
<ol>
<li>保持程序信息不变</li>
<li>离线本地代码生成</li>
<li>基于用户的profile和优化</li>
<li>透明的运行时模型</li>
<li>统一的全程序编译。</li>
</ol>
<p>作者从两个角度来论述LLVM对全时优化的支持，一是LLVM的中间表示设计；二是LLVM的整体架构设计。</p>
<h3>3.中间表示</h3>
<p>LLVM的中间表示采取类RISC指令集，但包含关键的高层类型信息，精确控制流图和数据流图。LLVM的中间表示的几个特性：低层，语言无关的类型系 统；提供保存类型信息又能做类型转换和底层地址运算的指令；两个底层例外处理指令。LLVM中间表示之所以能做到与源程序独立，是因为它使用了比汇编稍大 的底层指令级及存储模型但并不暴露任何实际运行时需求和源程序语义需求。这种中间表示也决定了LLVM的局限性，对于源源转换之类的优化，LLVM就无法 直接在中间表示发力。</p>
<p>作者主要从五个方面介绍了LLVM中间表示的特点：指令集、语言无关的类型信息、存储模型、例外处理截止和三种中间表示形式相互透明(普通文本，二进制和内存中)</p>
<h4>指令集：</h4>
<p>LLVM的中间表示采用原始处理器中的关键操作，回避物理寄存器、流水线、底层调用转换等细节，但为虚拟寄存器提供了集中类型(布尔型、整型、浮点型、指针),这些虚拟寄存器都采用SSA的形式。LLVM中有31个指令，多数采用了类型重载，且多为三地址形式.LLVM的每个虚拟寄存器都使用SSA的形式，而存储位置则不是SSA，这是因为存储可能存在别名。虚拟寄存器采用SSA能带来精确的定义-使用关系。另外LLVM也简化了控制流图，每个函数都转化为基本块的集合。每个基本块都有LLVM指令序列组成，结束基本块都有一个退出指令，如return，unwind，invoke。</p>
<h4>语言无关的类型信息：</h4>
<p>LLVM中每个SSA 虚拟寄存器和存储对象都有和其关联的类型，所有的操作也都有严格的类型规则。LLVM的类型系统包括了如下类型:void,bool, signed/unsigned int(8bit to 64bit),single float,double float和四种衍生类型：pointer,array,structure和function。作者认为很多高层的类型都能使用这些类型表示。如C++中的类继承就能使用structure,function和function pointer array 来表示；而且作者也认为以上这些类型基本胜任经典的语言无关的程序分析和优化。因为LLVM的中间表示层次低，就需要支持弱类型语言，因此为提高在LLVM程序中声明类型的可靠性，LLVM使用一些指针分析算法来来判断所访问的内存与指针的类型是否可以可靠的相互转换。LLVM的类型转换仅能通过cast指令从一种类型转换为另一种类型。LLVM的指针算术运算通过getelementptr来实现，该指令力保在做地址运算时指令安全。load和store指令则只负责取和存。</p>
<h4>精确存储分配和统一存储模型：</h4>
<p>LLVM通过三个指令实现存储操作：malloc，free和alloca。malloc负责在堆上分配带类型的存储位置；free负责释放malloc分配的存储空间；alloca和malloc相似，它分配的是在当前栈帧內分配存储而非堆，该内存将在函数返回时自动收回。LLVM中所有地址对象都被精确分配地址。全局变量和函数定义都被分配一个对象地址。这使得一个 统一的存储模型被建立。</p>
<h4>函数调用和例外处理：</h4>
<p>对于普通的函数调用，LLVM提供了一个带类型的call指令。LLVM有个与众不同的特性使得低级中间表示能处理高级程序例外，这种特性基于invoke和unwind两个指令实现。这两个指令共同支持了基于栈弹出的抽象例外处理模型。详细的机制论述请参考论文，作者用了将近一页的篇幅来论述。</p>
<h4>普通文本、二进制和内存中的表示形式：</h4>
<p>LLVM的中间表示是首个能同时等价的在二进制，普通文本和内存中(如编译器内部)表示的。指令集最初的设计就考虑到要能高效的即可作为一个中间表示，又能作为离线代码表示和编译器内部表示，并且在三者之间转换时无需任何语义变化。这三者之间的等价转换使得LLVM调试很方便。</p>
<p><em><span style="color: #000000;"><strong>正所谓，中间表示很重要，编译架构也得牛，眼高手低要不得，关键还得看评测。敬请关注下文 LLVM的架构介绍及整体评测。</strong></span></em></p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM 2.7 发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F12%2F08%2F11882%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">你好，LLVM 3.0</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/04/29/10728/' rel='bookmark' title='前瞻-全时优化和LLVM-2'>前瞻-全时优化和LLVM-2</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2009/11/19/10024/' rel='bookmark' title='Open64课程-编译过程'>Open64课程-编译过程</a></li>
<li><a href='http://www.lingcc.com/2009/12/14/10295/' rel='bookmark' title='open64课程&#8211;过程间分析优化(IPA)'>open64课程&#8211;过程间分析优化(IPA)</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/04/07/10721/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GNU工具链学习笔记</title>
		<link>http://www.lingcc.com/2010/03/08/10709/</link>
		<comments>http://www.lingcc.com/2010/03/08/10709/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:43:40 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[GCC]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[编译理论实践和应用]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[objdump]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10709</guid>
		<description><![CDATA[1..so为动态链接库，.a为静态连接库。他们在Linux下按照ELF格式存储。ELF有四种文件类型。可重定位文件(Relocatable file,*.o，*.a),包含代码和数据，可用来连接成可执行文件或共享目标文件;可执行文件(Executable File),ELF可执行文件；共享目标文件(Shared Object File,*.so),包含代码和数据；核心转储文件(Core Dump File),进程意外终止时，系统将该进程的地址空间内容和其他信息保存到该文件中。 file命令可以查看。 2，Objdump程序，来自binutils，可以查看Object file内的结构。-h：打印各个段基本信息；-s所有段内容以16进制打印;-d:将所有包含指令的段反汇编。 3, ar -t libc.a；查看libc.a压缩了那些.o文件。 4, collect2 是ld连接器的包装，它调用ld链接目标文件，并对结果做处理，包括收集所有与程序初始化相关的信息并构造初始化结构。 5，readelf：查看ELF文件。 -s:打印符号信息； 6, size *.o : 用于查看ELF文件代码段，数据段和BSS(Block Started by Symbol,为未初始化的全局变量和局部静态变量预留位置)段的长度。 7, nm：查看目标文件的符号信息。 8，C运行时库GlibC,由两部分组成，头文件和二进制库，前者多在/usr/include下，后者主要是C语言的标准库，有静态(/usr/lib/libc.a)和动态(/lib/libc.so.6)两个.另外还有/usr/lib/crt1.o(含程序入口函数_start,负责初始化libc和调用main),/usr/lib/crti.o(负责main函数执行前全局和静态对象的构造)和/usr/lib/crtn.o(负责main函数执行后，全局和静态对象的析构)三个辅助程序运行的库。链接器会收集所有输入目标文件中对全局和静态对象的构造/析构操作，合并到输出文件的构造和析构操作中。 9.GCC中的几个库文件，这些库文件都在GCC的安装目录下，Gentoo系统中的目录为/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/。crtbeginT.o和crtend.o,负责C++全局构造和析构的目标文件，因为glibc只是C语言运行库，GCC实现C++语言，所以C++中构造和析构需要glibc中的C语言构造/析构和GCC中相应的构造/析构。libgcc.a用来对付GCC在多平台上运行时的差异问题；libgcc_eh.a包含了支持C++异常处理的平台相关函数。libgcc_s.so是libgcc.a的动态链接版本。 10.ldd 打印共享库依赖关系。 以上内容摘抄自《程序员的自我修养 &#8211;链接，装载与库》 相关文章： GCC初窥 GCC中的pie和fpie选项 Gentoo中的交叉编译利器&#8211;crossdev zz Linux下的段错误的原因及调试 使用crossdev安装龙芯的O32 gnu交叉工具链 用crossdev装龙芯的n32 gnu交叉工具链<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC中的pie和fpie选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F08%2F27%2F9982%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zz Linux下的段错误的原因及调试</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">认识静态链接库</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">走进Debian和Gentoo中的系统初始化过程</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/08/10609/' rel='bookmark' title='GCC中的pie和fpie选项'>GCC中的pie和fpie选项</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2008/08/27/9982/' rel='bookmark' title='zz Linux下的段错误的原因及调试'>zz Linux下的段错误的原因及调试</a></li>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>1..so为动态链接库，.a为静态连接库。他们在Linux下按照ELF格式存储。ELF有四种文件类型。可重定位文件(Relocatable file,*.o，*.a),包含代码和数据，可用来连接成可执行文件或共享目标文件;可执行文件(Executable File),ELF可执行文件；共享目标文件(Shared Object File,*.so),包含代码和数据；核心转储文件(Core Dump File),进程意外终止时，系统将该进程的地址空间内容和其他信息保存到该文件中。<br />
file命令可以查看。<br />
2，Objdump程序，来自binutils，可以查看Object file内的结构。-h：打印各个段基本信息；-s所有段内容以16进制打印;-d:将所有包含指令的段反汇编。<br />
3, ar -t libc.a；查看libc.a压缩了那些.o文件。<br />
4, collect2 是ld连接器的包装，它调用ld链接目标文件，并对结果做处理，包括收集所有与程序初始化相关的信息并构造初始化结构。<br />
5，readelf：查看ELF文件。 -s:打印符号信息；<br />
<span id="more-10709"></span><br />
6, size *.o : 用于查看ELF文件代码段，数据段和BSS(Block Started by Symbol,为未初始化的全局变量和局部静态变量预留位置)段的长度。<br />
7, nm：查看目标文件的符号信息。<br />
8，C运行时库GlibC,由两部分组成，头文件和二进制库，前者多在/usr/include下，后者主要是C语言的标准库，有静态(/usr/lib/libc.a)和动态(/lib/libc.so.6)两个.另外还有/usr/lib/crt1.o(含程序入口函数_start,负责初始化libc和调用main),/usr/lib/crti.o(负责main函数执行前全局和静态对象的构造)和/usr/lib/crtn.o(负责main函数执行后，全局和静态对象的析构)三个辅助程序运行的库。链接器会收集所有输入目标文件中对全局和静态对象的构造/析构操作，合并到输出文件的构造和析构操作中。<br />
9.GCC中的几个库文件，这些库文件都在GCC的安装目录下，Gentoo系统中的目录为/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/。crtbeginT.o和crtend.o,负责C++全局构造和析构的目标文件，因为glibc只是C语言运行库，GCC实现C++语言，所以C++中构造和析构需要glibc中的C语言构造/析构和GCC中相应的构造/析构。libgcc.a用来对付GCC在多平台上运行时的差异问题；libgcc_eh.a包含了支持C++异常处理的平台相关函数。libgcc_s.so是libgcc.a的动态链接版本。<br />
10.ldd 打印共享库依赖关系。</p>
<p>以上内容摘抄自《程序员的自我修养 &#8211;链接，装载与库》</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC中的pie和fpie选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F08%2F27%2F9982%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zz Linux下的段错误的原因及调试</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">认识静态链接库</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">走进Debian和Gentoo中的系统初始化过程</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/08/10609/' rel='bookmark' title='GCC中的pie和fpie选项'>GCC中的pie和fpie选项</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2008/08/27/9982/' rel='bookmark' title='zz Linux下的段错误的原因及调试'>zz Linux下的段错误的原因及调试</a></li>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/03/08/10709/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>使用crossdev安装龙芯的O32 gnu交叉工具链</title>
		<link>http://www.lingcc.com/2010/01/07/10594/</link>
		<comments>http://www.lingcc.com/2010/01/07/10594/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 21:30:43 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[crossdev]]></category>
		<category><![CDATA[ebuild]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[make.conf]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[N32]]></category>
		<category><![CDATA[O32]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[交叉编译 cross compile]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[龙芯]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10594</guid>
		<description><![CDATA[先来介绍一下n32和O32是啥，N32和O32就是MIPS系统上不同的ABI，即Application Binary Interface。MIPS体系结构最早只有o32的系统，但后来改进了寄存器的功能和分配方式，于是就又有了N32，相对于O32，N32的速度更快些。但二者目前在龙芯系统上还无法兼容。因为龙芯目前官方只支持O32，而N32有只有zhllg的overlay中有，所以使用gentoo来安装O32的工具链需要额外解决些问题，所以才有了这篇文章，之所以之前又写了N32的安装方法，是因为有zhllg大牛的技术支持，使得能直接安装N32的工具链。 言归正转，开始安装我们的O32工具链，因为使用crossdev(如果你还不知道什么是crossdev，请参考Gentoo中的交叉编译利器–crossdev)，我们仍旧需要配置龙芯的overlay。详细的配置过程参见用crossdev装龙芯的n32 gnu交叉工具链，我这里只简单列出命令： cd /root git clone git://www.gentoo-cn.org/var/git/loongson.git cd /usr/local/portage/ mkdir loongson cd loongson ln -s /root/loongson-overlay/sys-libs/ sys-libs ##glibc指向overlay中的glibc ln -s /root/loongson-overlay/sys-devel/ sys-devel ##将gcc指向overlay中的gcc 接下来修改make.conf，确保/usr/local/portage/loongson在你所有overlay查找的最前面： PORTDIR_OVERLAY="/usr/local/portage/loongson $PORTDIR_OVERLAY" 这样做是为了确保使用龙芯overlay中的gcc和binutils。 下面还不能直接执行 crossdev -t mipsel-unknown-linux-gnu 因为现在overlay还不支持O32的工具链，需要我们做些修改，这些修改是我安装的时候google并参考zhllg在n32工具链的bugfix做的，目前能正常安装并能编译运行helloworld，应该没有任何问题:) 在目录/usr/local/portage/loongson/sys-libs/glibc下，做如下修改 files/eblits/src_compile.eblit 160a161,167 + if [[ ${CTARGET} == "mipsel-unknown-linux-gnu" ]] ; then + # remove "-32" gcc switch, since gcc <a href='http://www.lingcc.com/2010/01/07/10594/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F28%2F10983%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">用crossdev装龙芯的n32 gnu交叉工具链</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F08%2F15%2F11127%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F10%2F11060%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">webkit-龙小组成立</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F09%2F11055%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯中科公司招聘JAVA虚拟机开发工程师</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/01/02/10570/' rel='bookmark' title='Ebuild and emerge'>Ebuild and emerge</a></li>
<li><a href='http://www.lingcc.com/2008/03/28/9963/' rel='bookmark' title='gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir'>gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</a></li>
<li><a href='http://www.lingcc.com/2010/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>先来介绍一下n32和O32是啥，N32和O32就是MIPS系统上不同的ABI，即Application Binary Interface。MIPS体系结构最早只有o32的系统，但后来改进了寄存器的功能和分配方式，于是就又有了N32，相对于O32，N32的速度更快些。但二者目前在龙芯系统上还无法兼容。因为龙芯目前官方只支持O32，而N32有只有zhllg的overlay中有，所以使用gentoo来安装O32的工具链需要额外解决些问题，所以才有了这篇文章，之所以之前又写了<a href="../../../../2010/01/05/10588/">N32的安装方法</a>，是因为有zhllg大牛的技术支持，使得能直接安装N32的工具链。<span id="more-10594"></span></p>
<p>言归正转，开始安装我们的O32工具链，因为使用crossdev(如果你还不知道什么是crossdev，请参考<a href="../../../../2009/12/31/10534/">Gentoo中的交叉编译利器–crossdev</a>)，我们仍旧需要配置龙芯的overlay。详细的配置过程参见<a href="../../../../2010/01/05/10588/">用crossdev装龙芯的n32 gnu交叉工具链</a>，我这里只简单列出命令：<code><br />
cd /root<br />
git clone git://www.gentoo-cn.org/var/git/loongson.git<br />
cd /usr/local/portage/<br />
mkdir loongson<br />
cd loongson<br />
ln -s /root/loongson-overlay/sys-libs/  sys-libs    ##glibc指向overlay中的glibc<br />
ln -s /root/loongson-overlay/sys-devel/  sys-devel  ##将gcc指向overlay中的gcc<br />
</code><br />
接下来修改make.conf，确保/usr/local/portage/loongson在你所有overlay查找的最前面：<code><br />
PORTDIR_OVERLAY="/usr/local/portage/loongson $PORTDIR_OVERLAY"</code><br />
这样做是为了确保使用龙芯overlay中的gcc和binutils。</p>
<p>下面还不能直接执行<br />
<code>crossdev -t mipsel-unknown-linux-gnu</code><br />
因为现在overlay还不支持O32的工具链，需要我们做些修改，这些修改是我安装的时候google并参考zhllg在n32工具链的bugfix做的，目前能正常安装并能编译运行helloworld，应该没有任何问题:)</p>
<p>在目录/usr/local/portage/loongson/sys-libs/glibc下，做如下修改<br />
<code>files/eblits/src_compile.eblit<br />
160a161,167<br />
+     if [[ ${CTARGET} == "mipsel-unknown-linux-gnu" ]] ; then<br />
+         # remove "-32" gcc switch, since gcc for other arch don't have this<br />
+         sed -i '2 s/-mabi=32//g' "${S}"/ports/sysdeps/mips/mips32/Makefile<br />
+         # fix stdio_lim.h missing problem<br />
+         sed -i 's/_MIPS_SZPTR/32/' "${S}"/ports/sysdeps/mips/bits/wordsize.h<br />
+<br />
+     fi<br />
files/eblits/src_install.eblit<br />
203a204,207<br />
+     if [[ ${CTARGET} == "mipsel-unknown-linux-gnu" ]] ; then<br />
+         sed -i 's/\(__WORDSIZE.\+\)\(32\|64\)$/\1_MIPS_SZPTR/' \<br />
+             "${D}"/$(alt_headers)/bits/wordsize.h || die "restore wordsize.h failed"<br />
+     fi</code><br />
上面修改共三处，第一处解决emerge glibc-header时报的 gcc doesn&#8217;t support -mabi=32 错。修改方式是直接删除此选项，因为我们使用x86上的gcc而这个选项是支持O32的gcc才能接受的选项。<br />
第二，三处修改解决同一个问题，Emerging cross-gcc-stage1时出错/usr/mipsel-unknown-linux-gnu/sys-include/stdio.h  error: bits/stdio_lim.h: No such file or directory。 对于这个错误，你有两种修改方式，可以直接touch stdio_lim.h这个文件，这是很多手工编译工具链时给的建议。这里我们使用另一种方法，阻止该文件被include到stdio.h中，这是zhllg在N32工具链中使用的方式。</p>
<p>修改完了之后别忘了重新生成ebuild校验。<br />
<code>ebuild glibc-2.10.1.ebuild manifest<br />
ebuild glibc-2.9_p20081201-r2.ebuild manifest</code></p>
<p>bug修改完成，接下来，你就可以直接使用crossdev安装了。<br />
<code>crossdev -t mipsel-unknown-linux-gnu</code></p>
<p>Enjoy it！</p>
<p>PS：</p>
<ol>
<li>这是自己第一次修改ebuild，呵呵其实很简单，但自己一直都把自己当成用户，没有做过这种事，不敢做，所以浪费了很多时间，看着自己改出来的bug，心情很不一样哈。</li>
<li>我已经将上面的修改提交给了zhllg，等他做了相应的修改，就可以直接crossdev安装了。请关注此文。</li>
</ol>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F28%2F10983%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">用crossdev装龙芯的n32 gnu交叉工具链</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F08%2F15%2F11127%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F10%2F11060%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">webkit-龙小组成立</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F09%2F11055%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯中科公司招聘JAVA虚拟机开发工程师</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/01/02/10570/' rel='bookmark' title='Ebuild and emerge'>Ebuild and emerge</a></li>
<li><a href='http://www.lingcc.com/2008/03/28/9963/' rel='bookmark' title='gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir'>gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</a></li>
<li><a href='http://www.lingcc.com/2010/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/01/07/10594/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>用crossdev装龙芯的n32 gnu交叉工具链</title>
		<link>http://www.lingcc.com/2010/01/05/10588/</link>
		<comments>http://www.lingcc.com/2010/01/05/10588/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 13:51:08 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[crossdev]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[make.conf]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[N32]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[USE]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[交叉编译 cross compile]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[开源]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[链接]]></category>
		<category><![CDATA[龙芯]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10588</guid>
		<description><![CDATA[不管怎样，龙芯是咱们应该骄傲的，但是用它来编译东西确实很慢，我们很需要一个交叉编译器，能够在性能稍好的平台上为龙芯平台编译程序，x86是目前比较常见的平台，本博在实际工作中，需要在gentoo系统上安装支持龙芯n32的交叉编译器，下面分享一下本博的安装过程。
crossdev是gentoo系统下很方便的交叉编译环境安装和卸载工具，想进一步了解可以参考本博的这篇文章，这里只讨论有了crossdev之后的安装过程。
首先，我们需要支持n32的gcc,glibc，linux-header,insight和binutils.其中，gcc,gdb,insight和 linux-header都已经有了官方支持，我们还需要glibc的一些patch。头疼打patch这种繁重的劳动？别急，已经有国内的开源爱好者们做好了这些，我们仅仅需要几个附加步骤即可。<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F28%2F10983%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F10%2F11060%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">webkit-龙小组成立</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">使用crossdev安装龙芯的O32 gnu交叉工具链</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F08%2F15%2F11127%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/01/02/10570/' rel='bookmark' title='Ebuild and emerge'>Ebuild and emerge</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/08/10609/' rel='bookmark' title='GCC中的pie和fpie选项'>GCC中的pie和fpie选项</a></li>
<li><a href='http://www.lingcc.com/2008/03/28/9963/' rel='bookmark' title='gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir'>gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>不管怎样，龙芯是咱们应该骄傲的，但是用它来编译东西确实很慢，我们很需要一个交叉编译器，能够在性能稍好的平台上为龙芯平台编译程序，x86是目前比较常见的平台，本博在实际工作中，需要在gentoo系统上安装支持龙芯n32的交叉编译器，下面分享一下本博的安装过程。<br />
crossdev是gentoo系统下很方便的交叉编译环境安装和卸载工具，想进一步了解可以参考本博的这篇文章<a href="../../../../2009/12/31/10534/">Gentoo中的交叉编译利器–crossdev</a>，这里只讨论有了crossdev之后的安装过程。<br />
首先，我们需要支持n32的gcc,glibc，linux-header,insight和binutils.其中，gcc,gdb,insight和linux-header都已经有了官方支持，我们还需要glibc的一些patch。头疼打patch这种繁重的劳动？别急，已经有国内的开源爱好者们做好了这些，我们仅仅需要几个附加步骤即可。<span id="more-10588"></span></p>
<p>我们需要首先有gentoo的龙芯overlay，这个overlay是gentoo开发者zhllg维护的龙芯gentoo n32系统的overlay，因为我们需要n32的glibc，所以就需要这个overlay。虽然你可以直接只下载glibc的相关文件，但是推荐你直接clone整个overlay，这样的话，以后你就可以直接用git工具和zhllg的overlay更新了。如果不懂什么是overlay，可以参考这个链接<a href="http://www.gentoo.org/proj/en/overlays/userguide.xml">Gentoo Overlays: Users&#8217; Guide</a>。你需要一个位置存放overlay的内容，因为我们只需要glibc，所以你最好放在/usr/local/portage/以外的地方，然后在/usr/local/portage/做glibc的链接到龙芯的overlay里，这样能避免安装其他软件中的龙芯支持，搞乱你自己的x86系统。假定你在/root下存放overlay。你需要执行以下命令:<code><br />
cd /root<br />
git clone git://www.gentoo-cn.org/var/git/loongson.git<br />
cd /usr/local/portage/<br />
mkdir loongson<br />
cd loongson<br />
ln -s /root/loongson-overlay/sys-libs/  sys-libs    ##glibc指向overlay中的glibc<br />
ln -s /root/loongson-overlay/sys-devel/  sys-devel  ##将gcc指向overlay中的gcc</code><br />
至于为啥要把gcc也做软链接到龙芯的overlay，其实是因为历史遗留问题，原来的gcc4不支持，需要打补丁，现在不需要了，不过以后可能还需要，所以就做了这个软链接，不过你到overlay里，ls -l一下可以看到其实overlay里gcc也是链接，指向/usr/portage/下的gcc。</p>
<p>接下来就要告诉emerge，从overlay中找工具链中的gcc/binutils/glibc。我们要编辑/etc/make.conf文件，添加本地龙芯的portage，这里要注意，之所以我在/usr/local/portage下又创建文件夹是因为我有layman。另外你需要确保/usr/local/portage/loongson在你所有overlay查找的最前面：<code><br />
PORTDIR_OVERLAY="/usr/local/portage/loongson $PORTDIR_OVERLAY"</code><br />
这样做是为了确保使用龙芯overlay中的gcc和binutils。</p>
<p>接下来就能直接安装了：<code><br />
crossdev -t mips64el-unknown-linux-gnu</code></p>
<p>之后你就能享受交叉编译了，mipsel-unknown-linux-gnu-gcc 编译个helloword试试吧:)</p>
<p>龙芯是咱们自己的东西，大家一起努力才能让龙芯走向世界！</p>
<p>这里要注意几个问题：<br />
1，如果你是新安装的glibc，龙芯overlay中的glibc是2.10的，你gentoo系统的glibc的版本不能比这个低才行，不然会有冲突，具体的错误提示我忘记了。<br />
2，一定要让龙芯overlay在PORTDIR_OVERLAY的最前面。<br />
3，具体安装以下内容<br />
linux-headers-2.6.27-r2 from portage.<br />
binutils-2.19.1-r1 from loongson overlay.<br />
gcc-4.4.2 from portage. The gcc in loongson overlay currently is just a symlink to portage gcc.<br />
glibc-2.10.1  from loongson overlay.</p>
<p>参考</p>
<p>http://r0bertz.blogspot.com.sixxs.org/2009/11/update-on-building-mips64el-cross.html</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F28%2F10983%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F10%2F11060%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">webkit-龙小组成立</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F07%2F10594%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">使用crossdev安装龙芯的O32 gnu交叉工具链</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F08%2F15%2F11127%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F05%2F10588%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/01/02/10570/' rel='bookmark' title='Ebuild and emerge'>Ebuild and emerge</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/08/10609/' rel='bookmark' title='GCC中的pie和fpie选项'>GCC中的pie和fpie选项</a></li>
<li><a href='http://www.lingcc.com/2008/03/28/9963/' rel='bookmark' title='gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir'>gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/01/05/10588/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Gentoo中的交叉编译利器&#8211;crossdev</title>
		<link>http://www.lingcc.com/2009/12/31/10534/</link>
		<comments>http://www.lingcc.com/2009/12/31/10534/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 14:03:21 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[crossdev]]></category>
		<category><![CDATA[ebuild]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[make.conf]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[spec]]></category>
		<category><![CDATA[USE]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[交叉编译 cross compile]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10534</guid>
		<description><![CDATA[本文介绍使用gentoo 上的crossdev 交叉编译环境构建工具便捷高效构建交叉编译器的过程<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F28%2F9963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F21%2F10761%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gentoo安装texlive2009–字体</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F27%2F9904%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo的相关配置-make.conf</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">走进Debian和Gentoo中的系统初始化过程</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F09%2F10732%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gentoo上安装Texlive2009</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/01/02/10570/' rel='bookmark' title='Ebuild and emerge'>Ebuild and emerge</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2008/03/28/9963/' rel='bookmark' title='gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir'>gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</a></li>
<li><a href='http://www.lingcc.com/2010/03/08/10709/' rel='bookmark' title='GNU工具链学习笔记'>GNU工具链学习笔记</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<li>什么是Crossdev[I]</li>
<p><code>sys-devel/crossdev<br />
Available versions:  0.9.18-r10 ~0.9.19 **99999999<br />
Installed versions:  0.9.18-r10(03:44:50 PM 11/29/2009)<br />
Homepage:            http://www.gentoo.org/<br />
Description:         Gentoo Cross-toolchain generator</code><br />
交叉编译时很多嵌入式开发必须的工具，因为资料太少，遇到的问题又很难解决，所以交叉的开发环境一直让很多程序员头疼。我们就来了解一下gentoo下如何构建交叉编译环境。<br />
先说说工具链，工具链是用来组建一个系统的工具包集合，因为它们使用输入和输出连接在一起，所以称为链。通常工具链包括以下几部分：<span id="more-10534"></span></p>
<ul> binutils&#8211;用来生成二进制的基本工具(包括汇编器和连接起)</ul>
<ul> gcc&#8211;GNU编译器集(C和C++编译器)</ul>
<ul> glibc/uclibc/newlib&#8211;系统C语言库</ul>
<ul> linux-headers&#8211;系统文件库需要的内核头文件</ul>
<ul> gdb&#8211;GNU调试工具</ul>
<p>一般的Gentoo系统都将工具链作为基础系统的一部分，并且将工具链配置为能生成本机的二进制文件。为了能编译其他平台上的二进制文件，就需要交叉工具链，Gentoo提供了一个简单但很强大的工具CrossDev来管理工具链，它可以编译安装任意GCC支持的交叉工具链，因为Gentoo将工具链的文件安装在平台特定的目录下，所以Crossdev得到的交叉工具链不会干扰到本地的工具链。手工编造一个交叉工具链太痛苦了。。。。<!--more--></p>
<li>工具链使用的环境变量</li>
<p>工具链的环境变量总是让人很头疼，下面我们做个详细的介绍<br />
变量名&#8212;生成交叉工具链时的含义&#8212;生成目标平台二进制文件时的含义<br />
CBUILD&#8211;编译交叉工具链的平台&#8212;编译程序的平台<br />
CHOST&#8211;交叉工具链运行的平台&#8212;使用交叉工具链生成的二进制文件将运行的平台<br />
CTARGET&#8211;使用交叉工具链生成的二进制文件将运行的平台&#8211;使用交叉工具链生成的二进制文件将运行的平台(内容虽然重复，但设置它没有坏处，有些二进制包需要它)<br />
ROOT&#8211;将要安装的虚/路径<br />
PORTAGE_CONFIGROOT&#8211;portage能找到配置文件的虚/路径(如/etc/make.conf)<br />
若我们有个AMD64的gentoo机器，和一个想要开发程序的ARM PDA。那上面的变量可以设置如下：<br />
CBUILD&#8211;x86_64-pc-linux-gnu&#8211;x86_64-pc-linux-gnu<br />
CHOST&#8211;x86_64-pc-linux-gnu&#8211;arm-unknown-linux-gnu<br />
CTARGET&#8211;arm-unknown-linux-gnu&#8211;not set<br />
ROOT&#8212;[not set -- defaults to /]&#8212;[/path/where/you/install]<br />
PORTAGE_CONFIGROOT&#8212;[not set -- defaults to /]&#8212;-[/path/where/your/portage/env/for/arm/pda/is]</p>
<li>一些术语</li>
<p>cross-compiler	CHOST！=CTARGET的工具链<br />
canadian cross	加拿大式交叉编译CBUILD != CHOST &amp;&amp; CHOST != CTARGET的工具链<br />
CBUILD	build system 编译二进制文件所使用平台<br />
CHOST	host system 运行二进制文件所使用平台<br />
CTARGET	target system 编译得到的二进制文件将要运行的平台<br />
sysroot	system root 编译器用来查找它的标准头文件和库的根目录<br />
hardfloat	系统用来处理浮点数学运算的硬件浮点单元(FPU)<br />
softfloat	若系统没有硬件FPU,就需要所有的浮点数使用定点数学运算近似<br />
PIE		位置无关的执行(-fPIE -pie)<br />
PIC		位置无关代码(-fPIC)<br />
CRT		C语言运行时</p>
<li>系统元组</li>
<p>系统元组标记整个系统的特征，具体的内容由GNU config项目规定。具体的模式是机器(machine)-类型(vendor)-内核(kernel)-操作系统(operating system)。比如，博主我的电脑上就是i686-pc-linux-gnu.下表是一些比较常见的配置</p>
<table style="height: 258px;" width="513">
<tbody>
<tr>
<td><strong>机器</strong></td>
<td>类型</td>
<td><strong>内核</strong></td>
<td>操作系统</td>
</tr>
<tr>
<td>alpha<br />
arm / armeb<br />
avr / avr32<br />
bfin<br />
cris<br />
hppa / hppa1.1 / hppa2.0 / hppa64<br />
ia64<br />
i386 / i486 / i586 / i686<br />
m68k<br />
mips / mipsel / mips64 / mips64el<br />
nios / nios2<br />
powerpc / powerpc64<br />
sparc / sparcv8 / sparcv9 / sparc64<br />
s390 / s390x<br />
sh / sh3 / sh4 / sheb / sh3eb / sh4eb / sh64<br />
vax<br />
x86_64</td>
<td>gentoo<br />
pc<br />
softfloat [1]<br />
unknown</td>
<td>elf [2]<br />
freebsd6.2<br />
linux<br />
mingw32 / mingw64<br />
uclinux [3]</td>
<td>gnu [4]<br />
gnueabi [5]<br />
uclibc [6]<br />
uclibceabi</td>
</tr>
</tbody>
</table>
<p>来说说这其中几个比较有趣的：</p>
<ul> 类型那部分几乎可以随便设置，</ul>
<ul> 当操作系统指定为elf时，你就可以不用操作系统，而是直接把编译出的代码放到硬件上运行。</ul>
<ul>uclinux编译出的FLAT二进制文件，能在MMU不可用的Linux上运行</ul>
<ul> 操作系统中指定gnu表明系统库为libc</ul>
<li>言归正传，装我们的交叉编译器</li>
<p>我们的第一步当然是<code><br />
emerge -av crossdev</code><br />
这个命令会安装所有交叉编译相关的包。在博主的电脑上，就需要安装以下包<code><br />
emerge -pv crossdev</code></p>
<p>These are the packages that would be merged, in order:</p>
<p>Calculating dependencies&#8230; done!<br />
[ebuild  N    ] dev-util/unifdef-1.20  65 kB<br />
[ebuild  N    ] sys-devel/crossdev-0.9.18-r10  0 kB</p>
<p>Total: 2 packages (2 new), Size of downloads: 65 kB</p>
<p>注意，crossdev只是一个工具，我们的最终目的是使用crossdev编译一个交叉工具链出来，有必要先看看帮助，直接运行crossdev命令<br />
<code><br />
# crossdev<br />
Usage: crossdev [options] --target TARGET<br />
Options:<br />
--b, --binutils ver   Specify version of binutils to use<br />
--g, --gcc ver        Specify version of gcc to use<br />
--k, --kernel ver     Specify version of kernel headers to use<br />
--l, --libc ver       Specify version of libc to use<br />
-S, --stable          Use latest stable versions as default<br />
-C, --clean target    Uninstall specified target<br />
-P, --portage opts    Options to pass to emerge (see emerge(1))<br />
--with[out]-headers   Build C library headers before C compiler?<br />
Stage Options:<br />
-s0, --stage0         Build just binutils<br />
-s1, --stage1         Also build a C compiler (no libc/C++)<br />
-s2, --stage2         Also build kernel headers<br />
-s3, --stage3         Also build the C library (no C++)<br />
-s4, --stage4         Also build a C++ compiler [default]<br />
Extra Fun (must be run after above stages):<br />
--ex-only             Skip the stage steps above<br />
--ex-gcc              Build extra gcc targets (gcj/ada/etc...)<br />
--ex-gdb              Build a cross gdb<br />
--ex-insight          Build a cross insight<br />
Target (-t) takes a tuple ARCH-VENDOR-OS-LIBC; see 'crossdev -t help'</code><br />
上面可以看到，我们能用crossdev指定binutils gcc kernel和libc的版本，还有不同的编译stage来指定不同规模的工具链。甚至在Extra Fun中包含了gdb，扩展的gcc等支持，insight是gdb的图形化接口，博主没有用过，所以不知道。<br />
再来看看crossdev支持的系统元组们<br />
<code><br />
# crossdev -t help<br />
Supported Architectures:<br />
- alpha                                     - arm / armeb<br />
- hppa (parisc)                             - ia64<br />
- i386 / i486 / i586 / i686 (x86)           - m68k<br />
- mips / mipsel / mips64 / mips64el<br />
- powerpc (ppc) / powerpc64 (ppc64)<br />
- sparc / sparc64                           - s390 / s390x<br />
- sh / sh[1-5] / sh64                       - x86_64 (amd64)<br />
Supported C Libraries:<br />
- glibc (gnu)<br />
- klibc       [prob wont work]<br />
- newlib      [bare metal/no operating system]<br />
- uclibc      [not all arches are ported]<br />
Special Targets:<br />
- avr      http://www.nongnu.org/avr-libc/<br />
- bfin     http://blackfin.uclinux.org/<br />
- h8300    http://h8300-hms.sourceforge.net/<br />
- mingw32  http://www.mingw.org/<br />
- msp430   http://mspgcc.sourceforge.net/<br />
- nios2    http://www.altera.com/products/ip/processors/nios2/ni2-index.html<br />
- xc16x    http://www.infineon.com/<br />
- ee / iop / dvp (ps2) [Playstation 2 targets]<br />
- ppu / spu (cell) [Cell/Playstation 3 targets]<br />
Softfloat toolchains:<br />
Include 'softfloat' in the 'vendor' field<br />
e.g. armeb-softfloat-linux-uclibc  powerpc-booya_softfloat-linux-gnu<br />
</code><br />
不懂的话您就看看上面关于系统元组的介绍，具体我就不解释了，好了，现在看是安装。开动拉。。。。。因为博主要安装mips64el-unknown-linux-gnu的编译器，就直接运行了<br />
<code><br />
# crossdev --target mips64el-st-linux-gnu<br />
-------------------------------------------------------------------------------------------------------------------------------------------------------------<br />
* Host Portage ARCH:     x86<br />
* Target Portage ARCH:   mips<br />
* Target System:         mips64el-st-linux-gnu<br />
* Stage:                 4 (C/C++ compiler)</code></p>
<p>* binutils:              binutils-[latest]<br />
* gcc:                   gcc-[latest]<br />
* headers:               linux-headers-[latest]<br />
* libc:                  glibc-[latest]</p>
<p>* PORTDIR_OVERLAY:       /usr/local/portage/layman/gentoo-china<br />
* PORT_LOGDIR:           /var/log/portage<br />
* PKGDIR:                /usr/portage/packages/cross/mips64el-st-linux-gnu<br />
* PORTAGE_TMPDIR:        /var/tmp/cross/mips64el-st-linux-gnu<br />
_  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  &#8211;  _  &#8211;  ~  -<br />
* Forcing the latest versions of {binutils,gcc}-config/gnuconfig &#8230;                                                                                  [ ok ]<br />
* Log: /var/log/portage/cross-mips64el-st-linux-gnu-binutils.log<br />
* Emerging cross-binutils &#8230;<br />
这是个非常漫长的过程。。。。。。。。。因为是mips64el的，遇到了glibc checkfail的问题。这个问题正在解决中，以后再汇报。<br />
下面假设你安装的是arm的<br />
＃crossdev -t arm-unknown-linux-gnu</p>
<p>最后，再说说<br />
mips64el-unknown-linux-gnu 和mips64el-st-linux-gnu。其实没有区别，你可以简单的理解为是谁制作了这个工具链，比如st就代表这个工具链是ST作的，比如，我曾经使用的一个mips64el-st-linux-gnu就是曾经从意法半导体的网站上下载的，不过现在好像链接已经没有了。而mips64el-unknown-linux-gnu是上面crossdev自己编译出来的，在gentoo的overlay中，使用的就是unknown，所以就沿用了unknown</p>
<p>你可以参考下面几个链接<br />
<a href="http://www.gentoo.org/proj/en/base/embedded/handbook">http://www.gentoo.org/proj/en/base/embedded/handbook</a></p>
<p>http://psas.pdx.edu/GentooCrossCompilerHowto/</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F28%2F9963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F21%2F10761%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gentoo安装texlive2009–字体</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F27%2F9904%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo的相关配置-make.conf</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">走进Debian和Gentoo中的系统初始化过程</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F09%2F10732%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F31%2F10534%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gentoo上安装Texlive2009</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/01/02/10570/' rel='bookmark' title='Ebuild and emerge'>Ebuild and emerge</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2008/03/28/9963/' rel='bookmark' title='gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir'>gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</a></li>
<li><a href='http://www.lingcc.com/2010/03/08/10709/' rel='bookmark' title='GNU工具链学习笔记'>GNU工具链学习笔记</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2009/12/31/10534/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

