<?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>chys&#039;s random notes &#187; segfault</title>
	<atom:link href="http://en.chys.info/tag/segfault/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.chys.info</link>
	<description>Study more problems; Talk less of isms.</description>
	<lastBuildDate>Tue, 27 Dec 2011 11:56:38 +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>Unaligned access</title>
		<link>http://en.chys.info/2009/12/unaligned-access/</link>
		<comments>http://en.chys.info/2009/12/unaligned-access/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 07:10:24 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[segfault]]></category>
		<category><![CDATA[x86-64]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=717</guid>
		<description><![CDATA[Misalignment is not an error (only incurs a performance penalty) on x86 processors except for a few new instructions added in recent years. MOVDQA, for example, is an SSE2 instruction requiring alignment on 16-byte boundaries. Textbooks have normally taught us we get a bus error if a CPU which disallows unaligned access actually encounters one. [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Data_structure_alignment">Misalignment</a> is not an error (only incurs a performance penalty) on x86 processors except for a few new instructions added in recent years. <a href="http://www.sesp.cse.clrc.ac.uk/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc183.htm">MOVDQA</a>, for example, is an SSE2 instruction requiring alignment on 16-byte boundaries.</p>
<p>Textbooks have normally taught us we get a <a href="http://en.wikipedia.org/wiki/Bus_error">bus error</a> if a CPU which disallows unaligned access actually encounters one.</p>
<p>But we observe a Linux process passing misaligned addresses to MOVDQA receives <code>SIGSEGV</code> (segmentation fault) instead of <code>SIGBUS</code> (bus error), on both ia32 and x86-64.</p>
<blockquote><pre>
<font color="blue">laptop /tmp $</font> cat a.c
int main ()
{
    char X[32];
    asm ("pxor %%xmm0,%%xmm0; movdqa %%xmm0,%0" : "=m"(X[1]) :: "xmm0");
    return 0;
}
<font color="blue">laptop /tmp $</font> gcc -msse2 a.c
<font color="blue">laptop /tmp $</font> ./a.out
Segmentation fault
<font color="blue">laptop /tmp $</font> kill -l $?
SEGV
</pre>
</blockquote>
<p>x86-64 (and ia32 beginning 80486SX) supports disallowing any misaligned access*. In that case, a normal instruction raises <code>SIGBUS</code>, but instructions which inherently requires alignment (e.g. <code>MOVDQA</code>) still raises <code>SIGSEGV</code>. It&#8217;s not so consistent.</p>
<p>* It is normally disabled. To enable it, set the AC bit in <a href="http://en.wikipedia.org/wiki/FLAGS_register_%28computing%29">FLAGS</a>:</p>
<blockquote><p><code>pushf</code><br />
<code>or $0x40000,(%esp)</code> (or <code>%rsp</code> on x86-64)<br />
<code>popf</code></p></blockquote>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/12/unaligned-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Rvalue Reference Issue</title>
		<link>http://en.chys.info/2009/11/an-rvalue-reference-issue/</link>
		<comments>http://en.chys.info/2009/11/an-rvalue-reference-issue/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 18:52:47 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++0x]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[segfault]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=698</guid>
		<description><![CDATA[I&#8217;m now convinced it was way too premature to try to take advantage of C++0x features (r-value references, etc.) in tiary (if the compiler supports). With GCC 4.3.4, even the following innocent function leads to segmentation fault: #include &#60;string&#62; #include &#60;utility&#62; std::string &#038;&#038; my_move (std::string &#038;str) { std::string &#038;&#038; tmp = std::move (str); return tmp; [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/06/rvalue-reference/' rel='bookmark' title='Rvalue reference'>Rvalue reference</a></li>
<li><a href='http://en.chys.info/2009/10/stdhashstdstring/' rel='bookmark' title='std::hash&lt;std::string&gt;'>std::hash&lt;std::string&gt;</a></li>
<li><a href='http://en.chys.info/2009/05/cpp0x-in-icc11/' rel='bookmark' title='C++0x in ICC 11'>C++0x in ICC 11</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m now convinced it was way too premature to try to take advantage of C++0x features (<a href="http://www.artima.com/cppsource/rvalue.html">r-value references</a>, etc.) in <a href="http://code.google.com/p/tiary/">tiary</a> (if the compiler supports).</p>
<p>With GCC 4.3.4, even the following innocent function leads to segmentation fault:</p>
<blockquote><pre>
#include &lt;string&gt;
#include &lt;utility&gt;

std::string &#038;&#038; my_move (std::string &#038;str)
{
    std::string &#038;&#038; tmp = std::move (str);
    return tmp;
}</pre>
</blockquote>
<p>In GCC 4.4, this function simply casts the non-const lvalue-reference parameter to an r-value reference and returns it, which I think is correct. In 4.3, however, <code>tmp</code> refers to a temporary object on stack, <a href="http://msdn.microsoft.com/en-us/library/dd293665%28VS.100%29.aspx">move-constructed</a> from <code>str</code>.</p>
<p>Then I replaced <code>std::string</code> with <code>std::list&lt;int&gt;</code> and tried again. This time, GCC (4.3.4) itself <a href="http://en.wikipedia.org/wiki/Segmentation_fault">segfaults</a>. Ooops..</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/06/rvalue-reference/' rel='bookmark' title='Rvalue reference'>Rvalue reference</a></li>
<li><a href='http://en.chys.info/2009/10/stdhashstdstring/' rel='bookmark' title='std::hash&lt;std::string&gt;'>std::hash&lt;std::string&gt;</a></li>
<li><a href='http://en.chys.info/2009/05/cpp0x-in-icc11/' rel='bookmark' title='C++0x in ICC 11'>C++0x in ICC 11</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/11/an-rvalue-reference-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>luit -encoding gbk Segmentation Fault</title>
		<link>http://en.chys.info/2009/04/luit-encoding-gbk-segmentation-fault/</link>
		<comments>http://en.chys.info/2009/04/luit-encoding-gbk-segmentation-fault/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 05:04:01 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CJK]]></category>
		<category><![CDATA[luit]]></category>
		<category><![CDATA[segfault]]></category>
		<category><![CDATA[X11]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=483</guid>
		<description><![CDATA[Chinese users have been encountering segmentation faults when they use luit with GBK in for a long time. (It worked perfectly in the good old days.) This is caused by a bug in X. A simple workaround is as follows: Open file /usr/share/fonts/encodings/encodings.dir and exchange the following two lines: gbk-0 large/gbk-0.enc gbk-0 large/gbk-0.enc.gz For more [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2008/10/yuking-resumes-fcitx-development/' rel='bookmark' title='Yuking resumes FCITX development'>Yuking resumes FCITX development</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Chinese users have been encountering segmentation faults when they use <code>luit</code> with GBK in for a long time. (It worked perfectly in the good old days.) This is caused by a bug in X.</p>
<p>A simple workaround is as follows:</p>
<p>Open file <code>/usr/share/fonts/encodings/encodings.dir</code> and exchange the following two lines:</p>
<blockquote><p><code>gbk-0 large/gbk-0.enc</code><br />
<code>gbk-0 large/gbk-0.enc.gz</code></p></blockquote>
<p>For more details, refer to <a href="http://li2z.cn/2008/10/15/luit_ok/trackback/">li2z&#8217;s post</a>.<br />
(I believe anybody interested in this problem should be able to read Chinese:) )</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2008/10/yuking-resumes-fcitx-development/' rel='bookmark' title='Yuking resumes FCITX development'>Yuking resumes FCITX development</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/04/luit-encoding-gbk-segmentation-fault/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

