<?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; glibc</title>
	<atom:link href="http://www.lingcc.com/tag/glibc/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>字符串基本操作集锦</title>
		<link>http://www.lingcc.com/2010/12/23/11440/</link>
		<comments>http://www.lingcc.com/2010/12/23/11440/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 05:03:10 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[程序语言库]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[phd]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[标准库]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/2010/12/23/11440/</guid>
		<description><![CDATA[字符串基本操作集锦 所有C语言标准库支持的字符串操作都在string.h中，这个文件在/usr/include/下。确切的说，这个文件还包含对数组的访问。所包含的函数分为以下几类：复制、连接、比较、查找等。 Table of Contents 1 复制 2 连接 3 比较 4 查找 5 其他函数 6 strtok函数的实现 1 复制 void * memcpy ( void * destination, const void * source, size_t num ); void * memmove ( void * destination, const void * source, size_t num ); char * strcpy ( char * destination, const <a href='http://www.lingcc.com/2010/12/23/11440/'>[...]</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%2F05%2F25%2F10951%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F13%2F11330%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F03%2F08%2F10709%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F2011%2F01%2F05%2F11499%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F08%2F27%2F9982%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zz Linux下的段错误的原因及调试</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/2011/12/23/11907/' rel='bookmark' title='使用ld的wrap选项替换已有库函数'>使用ld的wrap选项替换已有库函数</a></li>
<li><a href='http://www.lingcc.com/2009/12/20/10372/' rel='bookmark' title='Expected unqualified-id before﻿ 查错'>Expected unqualified-id before﻿ 查错</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/07/12/11066/' rel='bookmark' title='Open64中的自动向量化支持'>Open64中的自动向量化支持</a></li>
<li><a href='http://www.lingcc.com/2011/11/28/11851/' rel='bookmark' title='Illegal Instruction 错误初窥'>Illegal Instruction 错误初窥</a></li>
<li><a href='http://www.lingcc.com/2010/03/25/10717/' rel='bookmark' title='为龙芯电脑安装操作系统常见问题'>为龙芯电脑安装操作系统常见问题</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<h1 class="title">字符串基本操作集锦</h1>
<p>所有C语言标准库支持的字符串操作都在string.h中，这个文件在/usr/include/下。确切的说，这个文件还包含对数组的访问。所包含的函数分为以下几类：复制、连接、比较、查找等。</p>
<p><span id="more-11440"></span></p>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 复制 </a></li>
<li><a href="#sec-2">2 连接 </a></li>
<li><a href="#sec-3">3 比较 </a></li>
<li><a href="#sec-4">4 查找 </a></li>
<li><a href="#sec-5">5 其他函数 </a></li>
<li><a href="#sec-6">6 strtok函数的实现 </a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">1 复制</h2>
<div id="text-1">
<pre class="src src-c++"><span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #7fffd4; font-weight: bold;">memcpy</span> ( <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">source</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );
<span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #7fffd4; font-weight: bold;">memmove</span> ( <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">source</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );
<span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strcpy</span> ( <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">source</span> );
<span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strncpy</span> ( <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">source</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );</pre>
<ul>
<li> memcpy:从source处拷贝num字节的数据到destination。</li>
<li> memmove: 和memcpy一样。但当source和destination出现内存区域重叠时，也能正确处理。</li>
<li> strcpy: 从source处将字符串拷贝到destination处，拷贝过程一直持续到source中null字符为止。</li>
<li> strncpy: 从source处拷贝num个字符到destination处。若在拷贝过程中source中有null字符，destination使用0补齐到num个字符处。</li>
</ul>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">2 连接</h2>
<div id="text-2">
<pre class="src src-c++"><span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strcat</span> ( <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">source</span> );
<span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strncat</span> ( <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">source</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );</pre>
<ul>
<li> strcat:  把source传复制并连接到destination后，destination串结尾处的null字符将被source的第一个字符覆盖。source串的某尾处将被添加新的null字符。返回destiination串的指针。</li>
<li> strncat: 把source的前num个字符复制禀连接到destination后，关于null的操作和strcat相同。</li>
</ul>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">3 比较</h2>
<div id="text-3">
<pre class="src src-c++"><span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #7fffd4; font-weight: bold;">memcmp</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">ptr1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">ptr2</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );
<span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #7fffd4; font-weight: bold;">strcmp</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span> );
<span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #7fffd4; font-weight: bold;">strcoll</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span> );
<span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #7fffd4; font-weight: bold;">strncmp</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );
<span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #7fffd4; font-weight: bold;">strxfrm</span> ( <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">destination</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">source</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );</pre>
<ul>
<li> memcmp:比较ptr1和ptr2的前num个字节。若二者相等，返回0；否则返回ptr1和ptr2中第一个不相等字节的比较结果。</li>
<li> strcmp：比较字符串ptr1和ptr2。若二者长度和字符都相等，返回0；否则返回ptr1和ptr2中第一个不相等字符的比较结果。</li>
<li> strcoll: 根据LC<sub>COLLATE指定的文字排序规则次序比较str1和str2，在LC</sub><sub>COLLATE为“POSIX”或“C”时，strcoll和strcmp作用完全相同</sub></li>
<li> strncmp:比较ptr1和ptr2的前num个字符。若二者相等，返回0；否则返回ptr1和ptr2中第一个不相等字符的比较结果。</li>
<li> strxfrm:字符串转换。从source中转换num个字符到destination中，使得strxfrm()转换后，strcmp的结果和直接使用strcoll的结果相同。</li>
</ul>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4">4 查找</h2>
<div id="text-4">
<pre class="src src-c++"><span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #7fffd4; font-weight: bold;">memchr</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">ptr</span>, <span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #40e0d0; font-weight: bold;">value</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );
<span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strchr</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str</span>, <span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #40e0d0; font-weight: bold;">character</span> );
<span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #7fffd4; font-weight: bold;">strcspn</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span> );
<span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strpbrk</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span> );
<span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strrchr</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str</span>, <span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #40e0d0; font-weight: bold;">character</span> );
<span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #7fffd4; font-weight: bold;">strspn</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span> );
<span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strstr</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str1</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str2</span> );
<span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strtok</span> ( <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str</span>, <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">delimiters</span> );</pre>
<ul>
<li> memchr: 在ptr指向的num个存储空间内查找第一个值为value的字节，并返回指向它的指针。</li>
<li> strchr: 查找str指向字符串中第一个字符为character的位置，返回指向该位置的指针。</li>
<li> strcspn: 扫描str1字符串，找到首次出现任意str2中字符的位置，返回str1中这个位置前的字符个数。</li>
<li> strpbrk： 扫描str1字符串，找到首次出现任意str2中字符的位置，返回指向该位置的指针，如找不到，返回NULL。</li>
<li> strrchr：查找str指向字符串中最后一个字符为character的位置，返回指向该位置的指针。</li>
<li> strspn： 找出str1中从第一次出现str2中字符开始，连续出现str2中字符的长度，返回该长度。</li>
<li> strstr： 找出str2中第一次出现str1的位置，返回指向该为止的指针，若不含有，返回NULL。</li>
<li> strtok: 用法很诡异的一个函数。如下例子。这个函数用于分割字符串，需要循环调用完成分割。循环调用时，传入的字符串为NULL。很好奇这个函数如何实现的：）
<pre class="src src-c"><span style="color: #add8e6;">/* </span><span style="color: #add8e6;">strtok example </span><span style="color: #add8e6;">*/</span>
<span style="color: #7fffd4;">#include</span> <span style="color: #87cefa;">&lt;stdio.h&gt;</span>
<span style="color: #7fffd4;">#include</span> <span style="color: #87cefa;">&lt;string.h&gt;</span>
<span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #7fffd4; font-weight: bold;">main</span> ()
{
  <span style="color: #87ceeb; font-weight: bold;">char</span> <span style="color: #40e0d0; font-weight: bold;">str</span>[] =<span style="color: #87cefa;">"- This, a sample string."</span>;
  <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">pch</span>;
  printf (<span style="color: #87cefa;">"Splitting string \"%s\" into tokens:\n"</span>,str);
  pch = strtok (str,<span style="color: #87cefa;">" ,.-"</span>);
  <span style="color: #afeeee; font-weight: bold;">while</span> (pch != <span style="color: #98fb98;">NULL</span>)
  {
    printf (<span style="color: #87cefa;">"%s\n"</span>,pch);
    pch = strtok (<span style="color: #98fb98;">NULL</span>, <span style="color: #87cefa;">" ,.-"</span>);
  }
  <span style="color: #afeeee; font-weight: bold;">return</span> 0;
}</pre>
</li>
</ul>
</div>
</div>
<div id="outline-container-5" class="outline-2">
<h2 id="sec-5">5 其他函数</h2>
<div id="text-5">
<pre class="src src-c"><span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #7fffd4; font-weight: bold;">memset</span> ( <span style="color: #87ceeb; font-weight: bold;">void</span> * <span style="color: #40e0d0; font-weight: bold;">ptr</span>, <span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #40e0d0; font-weight: bold;">value</span>, <span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #40e0d0; font-weight: bold;">num</span> );
<span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #7fffd4; font-weight: bold;">strerror</span> ( <span style="color: #87ceeb; font-weight: bold;">int</span> <span style="color: #40e0d0; font-weight: bold;">errnum</span> );
<span style="color: #87ceeb; font-weight: bold;">size_t</span> <span style="color: #7fffd4; font-weight: bold;">strlen</span> ( <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> * <span style="color: #40e0d0; font-weight: bold;">str</span> );</pre>
<ul>
<li> memset：从ptr开始，把连续num个字节的内存设置为值value，返回ptr</li>
<li> strerror： 根据errum，返回一个静态的字符串，这个字符串可以是一些错误提示，都是字符串常量。</li>
<li> strlen： 返回字符串str的长度。长度通过NULL字符来定位。</li>
</ul>
</div>
</div>
<div id="outline-container-6" class="outline-2">
<h2 id="sec-6">6 strtok函数的实现</h2>
<div id="text-6">
<p>函数strtok很有趣，通过上面的例子可以看到这个函数自身会记录一些变量信息，供下次被调用时使用。记录在哪里？怎么就记录了呢？下面是在glibc中strtok最简单的实现方式.原来只是个全局变量而已：） 有意思。</p>
<pre class="src src-c"><span style="color: #afeeee; font-weight: bold;">static</span> <span style="color: #87ceeb; font-weight: bold;">char</span> *<span style="color: #40e0d0; font-weight: bold;">olds</span>;

<span style="color: #add8e6;">/* </span><span style="color: #add8e6;">Parse S into tokens separated by characters in DELIM.
   If S is NULL, the last string strtok() was called with is
   used.  For example:
        char s[] = "-abc-=-def";
        x = strtok(s, "-");             // x = "abc"
        x = strtok(NULL, "-=");         // x = "def"
        x = strtok(NULL, "=");          // x = NULL
                // s = "abc\0=-def\0"
</span><span style="color: #add8e6;">*/</span>
<span style="color: #87ceeb; font-weight: bold;">char</span> *
<span style="color: #7fffd4; font-weight: bold;">strtok</span> (s, delim)
     <span style="color: #87ceeb; font-weight: bold;">char</span> *<span style="color: #40e0d0; font-weight: bold;">s</span>;
     <span style="color: #afeeee; font-weight: bold;">const</span> <span style="color: #87ceeb; font-weight: bold;">char</span> *<span style="color: #40e0d0; font-weight: bold;">delim</span>;
{
  <span style="color: #87ceeb; font-weight: bold;">char</span> *<span style="color: #40e0d0; font-weight: bold;">token</span>;

  <span style="color: #afeeee; font-weight: bold;">if</span> (s == <span style="color: #98fb98;">NULL</span>)
    s = olds;

  <span style="color: #add8e6;">/* </span><span style="color: #add8e6;">Scan leading delimiters.  </span><span style="color: #add8e6;">*/</span>
  s += strspn (s, delim);
  <span style="color: #afeeee; font-weight: bold;">if</span> (*s == <span style="color: #87cefa;">'\0'</span>)
    {
      olds = s;
      <span style="color: #afeeee; font-weight: bold;">return</span> <span style="color: #98fb98;">NULL</span>;
    }

  <span style="color: #add8e6;">/* </span><span style="color: #add8e6;">Find the end of the token.  </span><span style="color: #add8e6;">*/</span>
  token = s;
  s = strpbrk (token, delim);
  <span style="color: #afeeee; font-weight: bold;">if</span> (s == <span style="color: #98fb98;">NULL</span>)
    <span style="color: #add8e6;">/* </span><span style="color: #add8e6;">This token finishes the string.  </span><span style="color: #add8e6;">*/</span>
    olds = __rawmemchr (token, <span style="color: #87cefa;">'\0'</span>);
  <span style="color: #afeeee; font-weight: bold;">else</span>
    {
      <span style="color: #add8e6;">/* </span><span style="color: #add8e6;">Terminate the token and make OLDS point past it.  </span><span style="color: #add8e6;">*/</span>
      *s = <span style="color: #87cefa;">'\0'</span>;
      olds = s + 1;
    }
  <span style="color: #afeeee; font-weight: bold;">return</span> token;
}</pre>
</div>
</div>
<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%2F05%2F25%2F10951%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F13%2F11330%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F03%2F08%2F10709%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F2011%2F01%2F05%2F11499%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%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%2F08%2F27%2F9982%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F23%2F11440%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zz Linux下的段错误的原因及调试</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/2011/12/23/11907/' rel='bookmark' title='使用ld的wrap选项替换已有库函数'>使用ld的wrap选项替换已有库函数</a></li>
<li><a href='http://www.lingcc.com/2009/12/20/10372/' rel='bookmark' title='Expected unqualified-id before﻿ 查错'>Expected unqualified-id before﻿ 查错</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/07/12/11066/' rel='bookmark' title='Open64中的自动向量化支持'>Open64中的自动向量化支持</a></li>
<li><a href='http://www.lingcc.com/2011/11/28/11851/' rel='bookmark' title='Illegal Instruction 错误初窥'>Illegal Instruction 错误初窥</a></li>
<li><a href='http://www.lingcc.com/2010/03/25/10717/' rel='bookmark' title='为龙芯电脑安装操作系统常见问题'>为龙芯电脑安装操作系统常见问题</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/12/23/11440/feed/</wfw:commentRss>
		<slash:comments>0</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%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%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%2F2008%2F03%2F10%2F9937%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;">百度Hi策略的猜想</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%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%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%2F2008%2F03%2F10%2F9937%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;">百度Hi策略的猜想</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>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%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%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%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%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%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%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>WebKit和Firefox的JavaScript性能对比</title>
		<link>http://www.lingcc.com/2010/01/22/10668/</link>
		<comments>http://www.lingcc.com/2010/01/22/10668/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 14:37:22 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[nanojit]]></category>
		<category><![CDATA[spec]]></category>
		<category><![CDATA[TraceMonkey]]></category>
		<category><![CDATA[WebKit]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[开源]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[运行时技术]]></category>
		<category><![CDATA[链接]]></category>
		<category><![CDATA[龙芯]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10668</guid>
		<description><![CDATA[严格的说WebKit仅仅是个浏览器核心，采用该核心的浏览器很多，如国内的搜狗浏览器，遨游浏览器。其他的如google的chrome(Windows平台，linux平台下为chromium),epiphany(linux平台下，gnome2.28版本之后),苹果的Safari 都采用了webkit的内核。Firefox则是采用Gecko的内核，这是NetScape公司开发的内核，后来开源，mozilla继续开发。另外，现在还有另外两种常见的浏览器内核，Trident主要用在IE系列上，Presto主要用在Opera上。 这篇文章仅仅针对浏览器处理JavaScript的性能作比较，主要在X86平台和龙芯平台。先来解释一下JavaScript，JavaScript是互联网内较为常用的脚本语言，面向对象，主要在浏览器内解释执行，用于生成动态网页，因为很多语言特性受Java影响，所以叫JavaScript。通过JavaScript，浏览器可以运行服务器想要在访问者终端上运行的一些计算程序，以达到更好的浏览体验。 再说说浏览器内核和JavaScript的关系，其实JavaScrip脚本的执行仅仅是浏览器内核的一部分，其他的还有Html语言的解释执行，网页的呈现等等也是内核要做的。之所以这么关心浏览器核心对JavaScript脚本的处理情况，是因为现在的很多应用不再是简单的网页浏览，如gmail，google reader，gooe wave还有一些网页3D特效等等都需要在客户机上作计算，这就需要JavaScript大显身手了。而且越来越多的应用依赖JavaScript，所以现在浏览器对JavaScript的处理速度直接影响着用户体验。目前WebKit的JavaScript引擎SquirrelFish，JavaScript的引擎是SpiderMonkey 目前JavaScript在大多数平台上的处理是靠解释执行的，又因为是动态类型，面向对象。。。，决定了JavaScript执行效率低，所以就诞生了各种针对JavaScript的优化，也有了测试JavaScipt解释器性能的BenchMark，目前常用的是Sunspider和google V8，这篇文章中的对比针对Sunspider测试集。 另外还要说说JIT，Just In time，转换，将部分程序代码直接转换成机器码执行，这种技术在运行时优化中比较常用，JavaScript是解释器，所以JIT在解释器中也是很重要的优化手段。目前X86的webkit和Firefox默认就有JIT支持，但龙芯平台上还没有，本博也是最早对龙芯2F平台有JIT支持的Webkit和firefox  JavaScript引擎作对比的，目前这两个JIT都还没有进入官方的代码库中，感兴趣的朋友可以在下面的前两个链接中找到相关源码。其中webkit的补丁还要做些宏的修改，改动不大。这两个都是从官方源码库checkout出来并修改之后的。其中firefox的JIT部分是由ZSC大牛写出来的，详细的讨论贴和测试结果可以在龙芯论坛看到，见下面的第三个链接。 x86下epiphany(webkit内核)和firefox开了jit之后的性能，如下 webkit Total: 833.6ms +/- 2.1% firefox Total: 1774.4ms +/- 2.7% （测试环境是我的笔记本 intel Pentium t2390,开了频率调节，所以波动较大)、两个差距： TEST COMPARISON FROM TO DETAILS ============================================================================= ** TOTAL **: 2.13x as fast 1774.4ms +/- 2.7% 833.6ms +/- 2.1% significant ============================================================================= 3d: 2.96x as fast 257.2ms +/- 2.1% 87.0ms <a href='http://www.lingcc.com/2010/01/22/10668/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="webkit-龙小组成立" style="text-decoration: none !important; cursor: pointer !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%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">webkit-龙小组成立</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="zzMozilla的疯狂构想 Firefox 4将开拓浏览器新疆界" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F31%2F9966%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/05/11067795.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">zzMozilla的疯狂构想 Firefox 4将开拓浏览器新疆界</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="龙芯N32系统上的Squirrelfish性能" style="text-decoration: none !important; cursor: pointer !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%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="JIT Compiler and Virtual Machine SW Engineer for Web Browsers in Qualcomm" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F10%2F09%2F11773%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">JIT Compiler and Virtual Machine SW Engineer for Web Browsers in Qualcomm</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="擦亮眼睛 “百度Hi”用户协议有猫腻" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F06%2F9928%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7115378.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">擦亮眼睛 “百度Hi”用户协议有猫腻</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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/24/10451/' rel='bookmark' title='拥有Nanojit龙芯后端的firefox发布(10年1月14日更新)'>拥有Nanojit龙芯后端的firefox发布(10年1月14日更新)</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/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/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/06/28/10983/' rel='bookmark' title='龙芯N32系统上的Squirrelfish性能'>龙芯N32系统上的Squirrelfish性能</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>严格的说WebKit仅仅是个浏览器核心，采用该核心的浏览器很多，如国内的搜狗浏览器，遨游浏览器。其他的如google的chrome(Windows平台，linux平台下为chromium),epiphany(linux平台下，gnome2.28版本之后),苹果的Safari 都采用了webkit的内核。Firefox则是采用Gecko的内核，这是NetScape公司开发的内核，后来开源，mozilla继续开发。另外，现在还有另外两种常见的浏览器内核，Trident主要用在IE系列上，Presto主要用在Opera上。</p>
<p>这篇文章仅仅针对浏览器处理JavaScript的性能作比较，主要在X86平台和龙芯平台。先来解释一下JavaScript，JavaScript是互联网内较为常用的脚本语言，面向对象，主要在浏览器内解释执行，用于生成动态网页，因为很多语言特性受Java影响，所以叫JavaScript。通过JavaScript，浏览器可以运行服务器想要在访问者终端上运行的一些计算程序，以达到更好的浏览体验。<span id="more-10668"></span></p>
<p>再说说浏览器内核和JavaScript的关系，其实JavaScrip脚本的执行仅仅是浏览器内核的一部分，其他的还有Html语言的解释执行，网页的呈现等等也是内核要做的。之所以这么关心浏览器核心对JavaScript脚本的处理情况，是因为现在的很多应用不再是简单的网页浏览，如gmail，google reader，gooe wave还有一些网页3D特效等等都需要在客户机上作计算，这就需要JavaScript大显身手了。而且越来越多的应用依赖JavaScript，所以现在浏览器对JavaScript的处理速度直接影响着用户体验。目前WebKit的JavaScript引擎SquirrelFish，JavaScript的引擎是SpiderMonkey</p>
<p>目前JavaScript在大多数平台上的处理是靠解释执行的，又因为是动态类型，面向对象。。。，决定了JavaScript执行效率低，所以就诞生了各种针对JavaScript的优化，也有了测试JavaScipt解释器性能的BenchMark，目前常用的是Sunspider和google V8，这篇文章中的对比针对Sunspider测试集。</p>
<p>另外还要说说JIT，Just In time，转换，将部分程序代码直接转换成机器码执行，这种技术在运行时优化中比较常用，JavaScript是解释器，所以JIT在解释器中也是很重要的优化手段。目前X86的webkit和Firefox默认就有JIT支持，但龙芯平台上还没有，本博也是最早对龙芯2F平台有JIT支持的Webkit和firefox  JavaScript引擎作对比的，目前这两个JIT都还没有进入官方的代码库中，感兴趣的朋友可以在下面的前两个链接中找到相关源码。其中webkit的补丁还要做些宏的修改，改动不大。这两个都是从官方源码库checkout出来并修改之后的。其中firefox的JIT部分是由ZSC大牛写出来的，详细的讨论贴和测试结果可以在龙芯论坛看到，见下面的第三个链接。<br />
x86下epiphany(webkit内核)和firefox开了jit之后的性能，如下</p>
<pre id="comment_text_6">
webkit Total:                  833.6ms +/- 2.1%
firefox Total:                 1774.4ms +/- 2.7%</pre>
<p>（测试环境是我的笔记本 intel Pentium t2390,开了频率调节，所以波动较大)、两个差距：</p>
<pre id="console">TEST                   COMPARISON            FROM                 TO             DETAILS

=============================================================================

** TOTAL **:           2.13x as fast     1774.4ms +/- 2.7%   833.6ms +/- 2.1%     significant

=============================================================================

  3d:                  2.96x as fast      257.2ms +/- 2.1%    87.0ms +/- 1.0%     significant
    cube:              3.36x as fast       79.2ms +/- 1.7%    23.6ms +/- 2.9%     significant
    morph:             1.52x as fast       50.4ms +/- 1.4%    33.2ms +/- 3.1%     significant
    raytrace:          4.23x as fast      127.6ms +/- 3.0%    30.2ms +/- 3.4%     significant

  access:              3.26x as fast      237.0ms +/- 4.7%    72.8ms +/- 2.8%     significant
    binary-trees:      8.82x as fast       67.0ms +/- 4.4%     7.6ms +/- 9.0%     significant
    fannkuch:          3.48x as fast       98.2ms +/- 0.6%    28.2ms +/- 3.7%     significant
    nbody:             2.50x as fast       51.4ms +/- 10.3%    20.6ms +/- 3.3%     significant
    nsieve:            -                   20.4ms +/- 56.6%    16.4ms +/- 4.2% 

  bitops:              1.42x as fast       53.8ms +/- 1.9%    38.0ms +/- 0.0%     significant
    3bit-bits-in-byte: *3.10x as slow*      2.0ms +/- 0.0%     6.2ms +/- 9.0%     significant
    bits-in-byte:      -                   11.0ms +/- 8.0%    10.4ms +/- 6.5%
    bitwise-and:       *2.33x as slow*      3.0ms +/- 0.0%     7.0ms +/- 0.0%     significant
    nsieve-bits:       2.62x as fast       37.8ms +/- 1.5%    14.4ms +/- 4.7%     significant

  controlflow:         8.76x as fast       50.8ms +/- 2.0%     5.8ms +/- 9.6%     significant
    recursive:         8.76x as fast       50.8ms +/- 2.0%     5.8ms +/- 9.6%     significant

  crypto:              2.34x as fast       93.8ms +/- 1.7%    40.0ms +/- 2.2%     significant
    aes:               2.57x as fast       54.0ms +/- 3.6%    21.0ms +/- 4.2%     significant
    md5:               2.62x as fast       26.2ms +/- 2.1%    10.0ms +/- 0.0%     significant
    sha1:              1.51x as fast       13.6ms +/- 5.0%     9.0ms +/- 0.0%     significant

  date:                1.87x as fast      275.2ms +/- 2.0%   147.0ms +/- 1.0%     significant
    format-tofte:      2.75x as fast      149.0ms +/- 1.0%    54.2ms +/- 1.0%     significant
    format-xparb:      1.36x as fast      126.2ms +/- 4.0%    92.8ms +/- 1.7%     significant

  math:                1.12x as fast       89.8ms +/- 1.8%    80.2ms +/- 21.7%     significant
    cordic:            2.13x as fast       43.4ms +/- 3.3%    20.4ms +/- 9.2%     significant
    partial-sums:      *1.41x as slow*     34.4ms +/- 2.0%    48.6ms +/- 38.2%     significant
    spectral-norm:     1.07x as fast       12.0ms +/- 0.0%    11.2ms +/- 12.2%     significant

  regexp:              3.73x as fast      125.4ms +/- 15.5%    33.6ms +/- 2.0%     significant
    dna:               3.73x as fast      125.4ms +/- 15.5%    33.6ms +/- 2.0%     significant

  string:              1.80x as fast      591.4ms +/- 3.3%   329.2ms +/- 1.6%     significant
    base64:            *1.24x as slow*     28.4ms +/- 2.4%    35.2ms +/- 1.6%     significant
    fasta:             1.71x as fast      133.0ms +/- 2.3%    78.0ms +/- 4.6%     significant
    tagcloud:          2.81x as fast      169.4ms +/- 3.8%    60.2ms +/- 8.2%     significant
    unpack-code:       1.91x as fast      193.8ms +/- 4.4%   101.6ms +/- 2.7%     significant
    validate-input:    1.23x as fast       66.8ms +/- 5.8%    54.2ms +/- 6.4%     significant</pre>
<p>龙芯上的JIT具体对比数据不便透漏，可以从下面第三个链接中找到第一版发布时的测试数据。这里仅仅给出一个对比。webkit之所以with GUI是使用编译出的迷你小浏览器中测试结果，no GUI是使用测试脚本跑出来的结果。</p>
<pre id="comment_text_4"> Webkit with GUI Total:                  6723.4ms +/- 0.5%
        no GUI   Total:                  6355.8ms +/- 0.5%
 Firfox Total 7000 ms 左右。</pre>
<p>注： 龙芯中的JIT现在还不够成熟，其中Webkit的JIT仅是针对MIPS III做的，没有针对龙芯的特殊优化。</p>
<p>另外，X86中firefox的版本是3.5.7，龙芯中firefox的版本是3.7pre1.WebKit在X86中版本是epiphany的2.28中的版本，龙芯中为SVN中的2010-01-12 r53114。X86运行环境为Gentoo，Gcc4.4.2,Glibc2.11,龙芯运行环境是玲珑一体机，GCC4.3(龙梦修改版）,Glibc2.10。</p>
<p>对比结果可见：X86中WebKit浏览器的性能要明显优于Firefox，达到两倍之多。龙芯相比起来还有些差距，不过相信优化后龙芯的性能会更好。</p>
<p><strong>参考</strong></p>
<p>https://bugs.webkit.org/show_bug.cgi?id=30144</p>
<p>http://dev.lemote.com/code/firefox-3.7-loongson-jit</p>
<p>http://lemote.com/bbs/viewthread.php?tid=26687&#038;extra=page%3D1</p>
<p>http://en.wikipedia.org/wiki/Google_Chrome</p>
<p>http://ineolee.com/pc/several-browser-core-introduction/</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="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="webkit-龙小组成立" style="text-decoration: none !important; cursor: pointer !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%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">webkit-龙小组成立</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="zzMozilla的疯狂构想 Firefox 4将开拓浏览器新疆界" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F31%2F9966%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/05/11067795.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">zzMozilla的疯狂构想 Firefox 4将开拓浏览器新疆界</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="龙芯N32系统上的Squirrelfish性能" style="text-decoration: none !important; cursor: pointer !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%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="JIT Compiler and Virtual Machine SW Engineer for Web Browsers in Qualcomm" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F10%2F09%2F11773%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">JIT Compiler and Virtual Machine SW Engineer for Web Browsers in Qualcomm</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="擦亮眼睛 “百度Hi”用户协议有猫腻" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F06%2F9928%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F22%2F10668%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7115378.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">擦亮眼睛 “百度Hi”用户协议有猫腻</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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/24/10451/' rel='bookmark' title='拥有Nanojit龙芯后端的firefox发布(10年1月14日更新)'>拥有Nanojit龙芯后端的firefox发布(10年1月14日更新)</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/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/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/06/28/10983/' rel='bookmark' title='龙芯N32系统上的Squirrelfish性能'>龙芯N32系统上的Squirrelfish性能</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/01/22/10668/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>暴力了一把</title>
		<link>http://www.lingcc.com/2010/01/12/10645/</link>
		<comments>http://www.lingcc.com/2010/01/12/10645/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 15:13:31 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[IT生活]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[source.list]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[USE]]></category>
		<category><![CDATA[龙芯]]></category>
		<category><![CDATA[龙芯源]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10645</guid>
		<description><![CDATA[要在玲珑电脑上安装qtcreator，发现默认的源，同创的完全连不上，龙梦的没有想要的东西。又从盒子里拷了rays的源还是没有qtcreator。。。。。。 龙芯的源太混乱了，大家都在维护自己的，倒不如都按照debian的标准来做，画地为牢太劳民伤财了，一起努力做好一个源就不错了。 推荐一个现在在用的源，unstable的： deb ftp://210.51.187.182/loongson2f/sid/ ./ deb-src ftp://210.51.187.182/loongson2f/sid/ ./ deb ftp://210.51.187.182/debian sid main non-free contrib deb-src ftp://210.51.187.182/debian sid main non-free contrib 想要test或者stable的请直接将sid替换即可。 再记录一下debian下目前发行名称和稳定程度的对应关系,直接用stable,testing和unstable吧，比较容易记，要不然太乱了。 lenny ==stable squeeze== testing sid == unstable 言归正传： 之所以暴力了一把，是因为换了几次源，运行了几次apt-get update之后，终于install了qtcreator，但是却要更新glibc,结果更新了半天，重启，发现xserver-xorg不见了。于是安装，就开始报版本冲突： xserver-xorg: Depends: xserver-xorg-core (&#62;= 2:1.7) but 2:1.6.5-1 is to be installed 折腾了好久都不行，一怒之下，从别的玲珑上直接拷来了/usr/bin和lib下的X文件，呵呵，居然能用了。但是也仅仅限于启动了kdm，接下来登录就开始报 X: unable to open wrapper config file /etc/X11/Xwrapper.config X: user <a href='http://www.lingcc.com/2010/01/12/10645/'>[...]</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%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</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%2F05%2F10894%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%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%2F01%2F23%2F9890%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zzzz龙芯之火，可以燎原（下）</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%2F01%2F23%2F9889%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zz 龙芯之火，可以燎原（上）</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%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</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/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</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/05/19/10892/' rel='bookmark' title='走进Debian和Gentoo中的系统初始化过程'>走进Debian和Gentoo中的系统初始化过程</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/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/05/05/10894/' rel='bookmark' title='龙芯电脑常见问题'>龙芯电脑常见问题</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>要在玲珑电脑上安装qtcreator，发现默认的源，同创的完全连不上，龙梦的没有想要的东西。又从盒子里拷了rays的源还是没有qtcreator。。。。。。<br />
龙芯的源太混乱了，大家都在维护自己的，倒不如都按照debian的标准来做，画地为牢太劳民伤财了，一起努力做好一个源就不错了。<br />
推荐一个现在在用的源，unstable的：<code><br />
deb ftp://210.51.187.182/loongson2f/sid/ ./<br />
deb-src ftp://210.51.187.182/loongson2f/sid/ ./<br />
deb ftp://210.51.187.182/debian sid main non-free contrib<br />
deb-src ftp://210.51.187.182/debian sid main non-free contrib</code><span id="more-10645"></span><br />
想要test或者stable的请直接将sid替换即可。<br />
再记录一下debian下目前发行名称和稳定程度的对应关系,直接用stable,testing和unstable吧，比较容易记，要不然太乱了。<br />
lenny ==stable<br />
squeeze== testing<br />
sid == unstable</p>
<p>言归正传：<br />
之所以暴力了一把，是因为换了几次源，运行了几次apt-get update之后，终于install了qtcreator，但是却要更新glibc,结果更新了半天，重启，发现xserver-xorg不见了。于是安装，就开始报版本冲突：<br />
<code>xserver-xorg: Depends: xserver-xorg-core (&gt;= 2:1.7) but 2:1.6.5-1 is to be installed </code><br />
折腾了好久都不行，一怒之下，从别的玲珑上直接拷来了/usr/bin和lib下的X文件，呵呵，居然能用了。但是也仅仅限于启动了kdm，接下来登录就开始报<br />
<code>X: unable to open wrapper config file /etc/X11/Xwrapper.config<br />
X: user not authorized to run the X server, aborting.</code><br />
身心俱疲了，改天再搞，先ssh -Y用着吧。改天写个总结。</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%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</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%2F05%2F10894%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%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%2F01%2F23%2F9890%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zzzz龙芯之火，可以燎原（下）</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%2F01%2F23%2F9889%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">zz 龙芯之火，可以燎原（上）</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%2F12%2F10645%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</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/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</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/05/19/10892/' rel='bookmark' title='走进Debian和Gentoo中的系统初始化过程'>走进Debian和Gentoo中的系统初始化过程</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/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2010/05/05/10894/' rel='bookmark' title='龙芯电脑常见问题'>龙芯电脑常见问题</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/01/12/10645/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GCC中的pie和fpie选项</title>
		<link>http://www.lingcc.com/2010/01/08/10609/</link>
		<comments>http://www.lingcc.com/2010/01/08/10609/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 21:40:19 +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[intel]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[N64]]></category>
		<category><![CDATA[Open64]]></category>
		<category><![CDATA[USE]]></category>
		<category><![CDATA[系统安全]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[选项学习]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10609</guid>
		<description><![CDATA[Position-Independent-Executable是Binutils,glibc和gcc的一个功能，能用来创建介于共享库和通常可执行代码之间的代码&#8211;能像共享库一样可重分配地址的程序，这种程序必须连接到Scrt1.o。标准的可执行程序需要固定的地址，并且只有被装载到这个地址时，程序才能正确执行。PIE能使程序像共享库一样在主存任何位置装载，这需要将程序编译成位置无关，并链接为ELF共享对象。 引入PIE的原因是让程序能装载在随机的地址，通常情况下，内核都在固定的地址运行，如果能改用位置无关，那攻击者就很难借助系统中的可执行码实施攻击了。类似缓冲区溢出之类的攻击将无法实施。而且这种安全提升的代价很小 谈到PIE就不得不说说Pax和Grsec内核。这两个东西都是为了构建坚不可摧到安全系统而准备的。PaX是Linux内核安全增强补丁，它能在两方面保证安全性，一是ASLR(Address Space Layout Randomization,地址空间分布随机化)，这是一种将所有数据装载到内存时都随机化地址的方式，当使用PIE选项编译应用时，PaX能将应用的地址做随机加法；二是能提供不可执行的内存空间，这样就能使得攻击者放入内存中的恶意代码不可执行。不过PaX官网上能支持的最新内核是2.6.27，已经是一年前的更新了。Grsec也时类似的内核补丁，更新较为频繁能支持最新的2.6.32内核。这两种方式都能将内核完全位置无关，除了Grub和Glibc中无法位置无关的汇编码。 PIE最早由RedHat的人实现，他在连接起上增加了-pie选项，这样使用-fPIE编译的对象就能通过连接器得到位置无关可执行程序。fPIE和fPIC有些不同。可以参考Gcc和Open64中的-fPIC选项. gcc中的-fpic选项，使用于在目标机支持时，编译共享库时使用。编译出的代码将通过全局偏移表(Global Offset Table)中的常数地址访存，动态装载器将在程序开始执行时解析GOT表项(注意，动态装载器操作系统的一部分，连接器是GCC的一部分).而gcc中的-fPIC选项则是针对某些特殊机型做了特殊处理，比如适合动态链接并能避免超出GOT大小限制之类的错误。而Open64仅仅支持不会导致GOT表溢出的PIC编译。 gcc中的-fpie和-fPIE选项和fpic及fPIC很相似，但不同的是，除了生成为位置无关代码外，还能假定代码是属于本程序。通常这些选项会和GCC链接时的-pie选项一起使用。fPIE选项仅能在编译可执行码时用，不能用于编译库。所以，如果想要PIE的程序，需要你除了在gcc增加-fPIE选项外，还需要在ld时增加-pie选项才能产生这种代码。即gcc -fpie -pie来编译程序。单独使用哪一个都无法达到效果。 你可以使用file命令来查看当前的可执行文件是不是PIE的。 下面是本博编译helloword的显示。可以看出，可执行文件属性从executable变成了shared object. $ gcc  helloworld.c $ file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped $ gcc -fpie -pie helloworld.c $ file a.out a.out: ELF 32-bit LSB shared <a href='http://www.lingcc.com/2010/01/08/10609/'>[...]</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%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%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%2F2009%2F12%2F27%2F10464%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64课程–付诸实践(Practical Matters)</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%2F14%2F10295%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">open64课程–过程间分析优化(IPA)</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%2F25%2F10418%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%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%2F13%2F10273%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64 课程–全局标量优化(WOPT II)</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/05/25/10951/' rel='bookmark' title='认识静态链接库'>认识静态链接库</a></li>
<li><a href='http://www.lingcc.com/2010/03/08/10709/' rel='bookmark' title='GNU工具链学习笔记'>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/2009/11/20/10065/' rel='bookmark' title='Gcc和Open64中的-fPIC选项'>Gcc和Open64中的-fPIC选项</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>Position-Independent-Executable是Binutils,glibc和gcc的一个功能，能用来创建介于共享库和通常可执行代码之间的代码&#8211;能像共享库一样可重分配地址的程序，这种程序必须连接到Scrt1.o。标准的可执行程序需要固定的地址，并且只有被装载到这个地址时，程序才能正确执行。PIE能使程序像共享库一样在主存任何位置装载，这需要将程序编译成位置无关，并链接为ELF共享对象。</p>
<p>引入PIE的原因是让程序能装载在随机的地址，通常情况下，内核都在固定的地址运行，如果能改用位置无关，那攻击者就很难借助系统中的可执行码实施攻击了。类似缓冲区溢出之类的攻击将无法实施。而且这种安全提升的代价很小<br />
<span id="more-10609"></span><br />
谈到PIE就不得不说说Pax和Grsec内核。这两个东西都是为了构建坚不可摧到安全系统而准备的。PaX是Linux内核安全增强补丁，它能在两方面保证安全性，一是ASLR(Address Space Layout Randomization,地址空间分布随机化)，这是一种将所有数据装载到内存时都随机化地址的方式，当使用PIE选项编译应用时，PaX能将应用的地址做随机加法；二是能提供不可执行的内存空间，这样就能使得攻击者放入内存中的恶意代码不可执行。不过PaX官网上能支持的最新内核是2.6.27，已经是一年前的更新了。Grsec也时类似的内核补丁，更新较为频繁能支持最新的2.6.32内核。这两种方式都能将内核完全位置无关，除了Grub和Glibc中无法位置无关的汇编码。</p>
<p>PIE最早由RedHat的人实现，他在连接起上增加了-pie选项，这样使用-fPIE编译的对象就能通过连接器得到位置无关可执行程序。fPIE和fPIC有些不同。可以参考<a title="Permanent Link: Gcc和Open64中的-fPIC选项" rel="bookmark" href="../2009/11/20/10065/">Gcc和Open64中的-fPIC选项</a>.</p>
<p>gcc中的-fpic选项，使用于在目标机支持时，编译共享库时使用。编译出的代码将通过全局偏移表(Global Offset Table)中的常数地址访存，动态装载器将在程序开始执行时解析GOT表项(注意，动态装载器操作系统的一部分，连接器是GCC的一部分).而gcc中的-fPIC选项则是针对某些特殊机型做了特殊处理，比如适合动态链接并能避免超出GOT大小限制之类的错误。而Open64仅仅支持不会导致GOT表溢出的PIC编译。<br />
gcc中的-fpie和-fPIE选项和fpic及fPIC很相似，但不同的是，除了生成为位置无关代码外，还能假定代码是属于本程序。通常这些选项会和GCC链接时的-pie选项一起使用。fPIE选项仅能在编译可执行码时用，不能用于编译库。所以，如果想要PIE的程序，需要你除了在gcc增加-fPIE选项外，还需要在ld时增加-pie选项才能产生这种代码。即gcc -fpie -pie来编译程序。单独使用哪一个都无法达到效果。<br />
你可以使用file命令来查看当前的可执行文件是不是PIE的。</p>
<p>下面是本博编译helloword的显示。可以看出，可执行文件属性从executable变成了shared object.<br />
<code>$ gcc  helloworld.c<br />
$ file a.out<br />
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped<br />
$ gcc -fpie -pie helloworld.c<br />
$ file a.out<br />
a.out: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped</code><br />
接下来，我们就能实验了，使用strace命令来查看这两个a.out执行情况了。关于strace命令，可以参考<a href="../../../../2010/01/04/10582/">strace命令介绍</a><br />
在博主电脑上，有PIE时，执行第一个brk(0)系统调用时，返回的地址一直是变化的。而无PIE时，brk(O)系统调用返回地址一直不变。内容太多，不再贴出。</p>
<p>注：<br />
linux系统调用brk()：<br />
linux系统内部分配内存的系统调用，malloc()其实也是调用的brk().直接修改堆的大小，返回新内存区域的结束地址。</p>
<p>参考：<br />
<a href="http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html"> http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html</a></p>
<p>http://www.linuxfromscratch.org/hlfs/view/unstable/glibc-2.6/chapter02/pie.html</p>
<p><a href="http://www.gentoo.org/proj/en/hardened/hardened-toolchain.xml"> http://www.gentoo.org/proj/en/hardened/hardened-toolchain.xml</a><br />
<a href="http://www.gentoo.org/proj/en/hardened/pax-quickstart.xml"> http://www.gentoo.org/proj/en/hardened/pax-quickstart.xml</a><br />
<a href="http://www.kernel.org/doc/man-pages/online/pages/man2/brk.2.html"> http://www.kernel.org/doc/man-pages/online/pages/man2/brk.2.html</a><br />
&lt;Understanding Linux Kernel&gt; 3rd Edition Page32 , Page395</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%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%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%2F2009%2F12%2F27%2F10464%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64课程–付诸实践(Practical Matters)</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%2F14%2F10295%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">open64课程–过程间分析优化(IPA)</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%2F25%2F10418%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%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%2F13%2F10273%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64 课程–全局标量优化(WOPT II)</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/05/25/10951/' rel='bookmark' title='认识静态链接库'>认识静态链接库</a></li>
<li><a href='http://www.lingcc.com/2010/03/08/10709/' rel='bookmark' title='GNU工具链学习笔记'>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/2009/11/20/10065/' rel='bookmark' title='Gcc和Open64中的-fPIC选项'>Gcc和Open64中的-fPIC选项</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/01/08/10609/feed/</wfw:commentRss>
		<slash:comments>1</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%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%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%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%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%2F2008%2F03%2F17%2F9957%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;">胡伟武：龙芯5年内改变全球CPU格局</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%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%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%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%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%2F2008%2F03%2F17%2F9957%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;">胡伟武：龙芯5年内改变全球CPU格局</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%2F2008%2F03%2F17%2F9957%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;">胡伟武：龙芯5年内改变全球CPU格局</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%2F2008%2F03%2F17%2F9957%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;">胡伟武：龙芯5年内改变全球CPU格局</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>
	</channel>
</rss>

