<?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; dev</title>
	<atom:link href="http://en.chys.info/tag/dev/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>A hack to strace -f</title>
		<link>http://en.chys.info/2011/03/a-hack-to-strace-f/</link>
		<comments>http://en.chys.info/2011/03/a-hack-to-strace-f/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 13:22:20 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[multithread]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=886</guid>
		<description><![CDATA[I have a multithreaded program which I would like to strace for debugging purpose. My program sometimes calls (fork and exec) an external program, which in turn calls a setuid program. Because my program is multithreaded, I cannot omit the “-f” flag (also trace child threads and processes) when using strace. And because all children, [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I have a multithreaded program which I would like to <a href="http://en.wikipedia.org/wiki/Strace">strace</a> for debugging purpose. My program sometimes calls (fork and exec) an external program, which in turn calls a <a href="http://www.aquaphoenix.com/ref/gnu_c_library/libc_438.html">setuid program</a>.</p>
<p>Because my program is multithreaded, I cannot omit the “<code>-f</code>” flag (also trace child threads and processes) when using strace. And because all children, including the setuid program, are traced, setuid fails. (Yes, I am aware that strace claims it is possible to trace setuid programs, but the trick does not work for me, probably because the setuid program is not directly executed by strace.)</p>
<p>Fortunately, the <code><a href="http://linux.die.net/man/2/clone">clone</a></code> system call has many useful flags. It works fine for me when I substitute calls to <code><a href="http://linux.die.net/man/2/fork">fork()</a></code> with:</p>
<blockquote><p><code>(pid_t) syscall (__NR_clone, CLONE_UNTRACED|SIGCHLD, NULL);<br />
</code></p></blockquote>
<p>(Yes, <code>SIGCHLD</code>, not <code>CLONE_SIGCHLD</code>. It&#8217;s not a typo.)</p>
<p>I guess there may be better solutions, without modifying the program being traced?</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2011/03/a-hack-to-strace-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acquire and Release Semantics</title>
		<link>http://en.chys.info/2010/03/acquire-and-release-semantics/</link>
		<comments>http://en.chys.info/2010/03/acquire-and-release-semantics/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 09:42:40 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[multithread]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=768</guid>
		<description><![CDATA[The concept of acquire and release semantics is important for multi-threaded programs that run on more than one physical core or processor. MSDN has a clear and concise explanation of then. Consider the following code example: a++; b++; c++; From another processor&#8217;s point of view, the preceding operations can appear to occur in any order. [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The concept of acquire and release semantics is important for multi-threaded programs that run on more than one <em>physical</em> core or processor. MSDN has <a href="http://msdn.microsoft.com/en-us/library/aa490209.aspx">a clear and concise explanation</a> of then.</p>
<blockquote><p>Consider the following code example:</p>
<blockquote><p><code>a++;</code><br />
<code>b++;</code><br />
<code>c++;</code></p></blockquote>
<p>From another processor&#8217;s point of view, the preceding operations can appear to occur in any order. For example, the other processor might see the increment of <code>b</code> before the increment of <code>a</code>.</p>
<p>&#8230;</p>
<p>[T]he <code>InterlockedIncrementAcquire</code> routine uses acquire semantics to increment a variable. If you rewrote the preceding code example as follows:</p>
<blockquote><p><code>InterlockedIncrementAcquire(&#038;a);</code><br />
<code>b++;</code><br />
<code>c++;</code></p></blockquote>
<p>other processors would always see the increment of <code>a</code> before the increments of <code>b</code> and <code>c</code>.</p>
<p>Likewise, the <code>InterlockedIncrementRelease</code> routine uses release semantics to increment a variable. If you rewrote the code example once again, as follows:</p>
<blockquote><p><code>a++;</code><br />
<code>b++;</code><br />
<code>InterlockedIncrementRelease(&#038;c);</code></p></blockquote>
<p>other processors would always see the increments of <code>a</code> and <code>b</code> before the increment of <code>c</code>.</p></blockquote>
<p>The operation of acquiring a lock must have acquire semantics; and the operation of releasing a lock must have release semantics. This is probably where they get their names.</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2010/03/acquire-and-release-semantics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Tuesday following the first Monday in November</title>
		<link>http://en.chys.info/2010/02/the-tuesday-following-the-first-monday-in-november/</link>
		<comments>http://en.chys.info/2010/02/the-tuesday-following-the-first-monday-in-november/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 16:12:07 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=744</guid>
		<description><![CDATA[Martin Luther King Day falls the third Monday of January; Daylight Saving Time begins on the second Sunday of March; Father&#8217;s Day falls on the third Sunday in June; &#8230; To represent these dates in a program, the intuitive method is to use tuples (3,1,1), (2,0,3), (3,0,6), respectively. But probably this is not the best [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Martin Luther King Day falls the third Monday of January; Daylight Saving Time begins on the second Sunday of March; Father&#8217;s Day falls on the third Sunday in June; &#8230;</p>
<p>To represent these dates in a program, the intuitive method is to use tuples <code>(3,1,1)</code>, <code>(2,0,3)</code>, <code>(3,0,6)</code>, respectively. But probably this is not the best idea. The number of representable observations is limited. For instance, we cannot represent Election Day (Tuesday following the first Monday of November) or Memorial Day (last Monday of May).</p>
<p>Nevertheless, it is still possible to represent all the above in three small integers, by replacing the first integer in the tuple with <em>the earliest possible day of month</em>. For instance,</p>
<p>Martin Luther King Day = the Monday between January 15 and 21, represented by <code>(15,1,1)</code></p>
<p>Election Day = the Tuesday between November 2 and 8, represented by <code>(2,2,11)</code></p>
<p>Thanksgiving (before 1939) = last Thursday of November = the Thursday between November 24 and 30, represented by <code>(24,4,11)</code></p>
<p>Thanksgiving (modern) = fourth Thursday of November = the Thursday between November 22 and 28, represented by <code>(22,4,11)</code></p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2010/02/the-tuesday-following-the-first-monday-in-november/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDP-endian</title>
		<link>http://en.chys.info/2010/01/pdp-endian/</link>
		<comments>http://en.chys.info/2010/01/pdp-endian/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:33:34 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=731</guid>
		<description><![CDATA[Today I checked &#60;endian.h&#62; and found an unfamiliar line: #define __PDP_ENDIAN 3412 I knew there were little-endian machines (e.g. all Intel CPUs*) and big-endian machines (e.g. PowerPC†), but was really unaware of the so-called PDP-endian. It&#8217;s word-wise big-endian, and within a word‡, little-endian. char c[5] = {}; *(int32_t *)c = 0x61626364; puts (c); ASCII supposed, [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Today I checked <code>&lt;endian.h&gt;</code> and found an unfamiliar line:</p>
<blockquote><p><code>#define __PDP_ENDIAN    3412</code></p></blockquote>
<p>I knew there were little-<a href="http://en.wikipedia.org/wiki/Endianness">endian</a> machines (e.g. all Intel CPUs*) and big-endian machines (e.g. PowerPC†), but was really unaware of the so-called PDP-endian. It&#8217;s word-wise big-endian, and within a word‡, little-endian.</p>
<blockquote><p>
<code>char c[5] = {};</code><br />
<code>*(int32_t *)c = 0x61626364;</code><br />
<code>puts (c);</code>
</p></blockquote>
<p>ASCII supposed, this program segment produces “<code>ABCD</code>” on a big-endian machine, and “<code>DCBA</code>” on a little-endian machine. It seems, on a <a href="http://en.wikipedia.org/wiki/PDP-11">PDP-11</a>, it should output “<code>BADC</code>”.</p>
<p>Little-endian is friendly to programmers (in some sense). Big-endian is intuitive. But what&#8217;s PDP-endian for?</p>
<p>* Itanium supports both little-endian and big-endian. Windows and Linux for Itanium both use little endian.<br />
† PowerPC supports both little-endian and big-endian. Macintosh used big endian.<br />
‡ The term &#8220;word&#8221; here stands for two bytes. This usage is believed to be wrong though used by Intel, but I just don&#8217;t find a good substitute.</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2010/01/pdp-endian/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ack is a good alternative to grep</title>
		<link>http://en.chys.info/2009/09/ack/</link>
		<comments>http://en.chys.info/2009/09/ack/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 08:13:44 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=663</guid>
		<description><![CDATA[When I grep -r something in a Subversion-controlled directory, I get a lot of results under the .svn. In this sense, Git is better than Subversion. (Git creates only one .git directory, and stores data in some compressed format which gets ignored by grep -r.) So I have switched to ack when working with Subversion. [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>When I <code>grep -r</code> something in a <a href="http://subversion.tigris.org/">Subversion</a>-controlled directory, I get a lot of results under the <code>.svn</code>.</p>
<p>In this sense, <a href="http://git-scm.com/">Git</a> is better than Subversion. (Git creates only one <code>.git</code> directory, and stores data in some compressed format which gets ignored by <code>grep -r</code>.)</p>
<p>So I have switched to <a href="http://www.petdance.com/ack/">ack</a> when working with Subversion. Ack is written in Perl, claimed to be &#8220;aimed at programmers with large trees of heterogeneous source code.&#8221;</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/09/ack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To Risk Life or Job</title>
		<link>http://en.chys.info/2009/08/life-or-job/</link>
		<comments>http://en.chys.info/2009/08/life-or-job/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 19:58:58 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[humor]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=644</guid>
		<description><![CDATA[From my[confined]space A comment says: On the other hand, if you make your code confusing as hell, you will have much better job security. I have been assuming some maniac serial killer would be maintaining it while doing my recent (private, but to be public) project, but still find my own codes could be confusing. [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://www.myconfinedspace.com/2007/07/05/always-code-as-if-the-person-who-will-maintain-your-code-is-a-maniac-serial-killer-that-knows-where-you-live/">my[confined]space</a></p>
<p><a href="http://en.chys.info/wp-content/uploads/2009/08/code-killer.jpg"><img src="http://en.chys.info/wp-content/uploads/2009/08/code-killer.jpg" alt="Code" title="Code" width="750" height="578" class="alignnone size-full wp-image-645" border="0" /></a></p>
<p><a href="http://www.myconfinedspace.com/2007/07/05/always-code-as-if-the-person-who-will-maintain-your-code-is-a-maniac-serial-killer-that-knows-where-you-live/#comment-50547">A comment</a> says:</p>
<blockquote><p>On the other hand, if you make your code confusing as hell, you will have much better job security.</p></blockquote>
<hr/>
<p>I have been assuming some maniac serial killer would be maintaining it while doing my recent (private, but to be public) project, but still find my own codes could be confusing.</p>
<p>Anyway, I am glad that this did not happen until it reached about 70 files and 8,000 lines &#8211; the threshold used to be 2 files and 300 lines. The project now has about 110 files and 14,000 lines.</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/08/life-or-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I can&#8217;t PGO compile Firefox</title>
		<link>http://en.chys.info/2009/07/i-cannot-pgo-compile-firefox/</link>
		<comments>http://en.chys.info/2009/07/i-cannot-pgo-compile-firefox/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 20:21:57 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=610</guid>
		<description><![CDATA[A normal build of Firefox for Linux is reportedly even slower than the Win32 binary running under Wine. The reason is reportedly that the pre-compiled binary for Windows uses PGO (profile guided optimization), which is usually not enabled under Linux. Sure, the fact that GCC does not generate as efficient codes as VC may also [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/03/ext4-data-loss/' rel='bookmark' title='Ext4 data loss'>Ext4 data loss</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A normal build of Firefox for Linux is <a href="http://www.reddit.com/r/programming/comments/7x8mz/even_wine_beats_linux_firefox/">reportedly</a> even slower than the Win32 binary running under Wine.</p>
<p>The reason is reportedly that the pre-compiled binary for Windows uses PGO (<a href="http://en.wikipedia.org/wiki/Profile-guided_optimization">profile guided optimization</a>), which is usually not enabled under Linux. Sure, the fact that GCC does not generate as efficient codes as VC may also be a reason.[1]</p>
<p>Firefox also <a href="https://developer.mozilla.org/en/Building_with_Profile-Guided_Optimization">supports</a> PGO in Linux. However, I failed at this (3.5.1). The profile-generating binary always segfaults.</p>
<p><a href="http://bbs.archlinux.org/viewtopic.php?pid=579961">Other people</a> have encountered the same problem, even with the official PKGBUILD from Arch Linux. It is said to be a compiler problem.</p>
<p>Well, gave up. Maybe I&#8217;ll try it again some time later, with a more &#8220;stable&#8221; version of GCC probably.</p>
<p>[1] This statement only applies to the 32-bit platform. It seems GCC does a very good job on x86-64.</p>
<hr/>
<p>Profile-guided optimization is a relatively new feature. GCC began supporting it starting version 4.0; Microsoft VC 2005; and Intel C/C++/Fortran 9 (?).</p>
<p>A typical PGO-enabled building requires three steps:</p>
<p>(1) Build a profile-generating binary;<br />
(2) Run the binary, which automatically collects useful data &#8211; branch probability, etc.<br />
(3) Rebuild the program, using the data (“profile”) from Step 2.</p>
<p>With PGO, Internet Explorer <a href="http://gemal.dk/blog/2008/03/04/firefox_3_with_profileguided_optimization_speeding_ticket/">reportedly</a> gains an improvement of 8%, and Firefox 11% in JavaScript.</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/03/ext4-data-loss/' rel='bookmark' title='Ext4 data loss'>Ext4 data loss</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/07/i-cannot-pgo-compile-firefox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Premature optimization</title>
		<link>http://en.chys.info/2009/05/premature-optimization/</link>
		<comments>http://en.chys.info/2009/05/premature-optimization/#comments</comments>
		<pubDate>Sat, 09 May 2009 23:35:27 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=510</guid>
		<description><![CDATA[is the root of all evil, according to Donald Knuth. Prof. Knuth wrote in his paper Structured Programming with Go To Statements: Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>is the root of all evil, according to <a href="http://www-cs-faculty.stanford.edu/~knuth/">Donald Knuth</a>.</p>
<p>Prof. Knuth wrote in his paper <a href="http://c2.com/cgi/wiki?StructuredProgrammingWithGoToStatements"><em>Structured Programming with Go To Statements</em></a>:</p>
<blockquote><p>Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: <strong>premature optimization is the root of all evil</strong>.</p></blockquote>
<p>From time to time, I knew I should have first used a naïve algorithm, not beginning optimizing until I was sure they worked, but I have always been violating the rule.</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/05/premature-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>liblzmadec sucks</title>
		<link>http://en.chys.info/2009/05/liblzmadec-sucks/</link>
		<comments>http://en.chys.info/2009/05/liblzmadec-sucks/#comments</comments>
		<pubDate>Fri, 01 May 2009 18:38:02 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=485</guid>
		<description><![CDATA[Both the executable lzma and the library liblzmadec are included in the package lzma-utils (in Gentoo). If I compress a file a.txt like this: lzma a.txt then liblzmadec can decompress a.txt.lzma perfectly. However, if I compress it like this: lzma < a.txt > a.txt.lzma Then liblzmadec fails. LZMA is a compression algorithm whose application rate [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/04/logrotating-emergelog/' rel='bookmark' title='[Gentoo] Logrotating emerge.log'>[Gentoo] Logrotating emerge.log</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Both the executable <code>lzma</code> and the library <code>liblzmadec</code> are included in the package <code>lzma-utils</code> (in Gentoo).</p>
<p>If I compress a file <code>a.txt</code> like this:</p>
<blockquote><p><code>lzma a.txt</code></p></blockquote>
<p>then <code>liblzmadec</code> can decompress <code>a.txt.lzma</code> perfectly.</p>
<p>However, if I compress it like this:</p>
<blockquote><p><code>lzma < a.txt > a.txt.lzma</code></p></blockquote>
<p>Then <code>liblzmadec</code> fails.</p>
<hr/>
<p>LZMA is a compression algorithm whose application rate has been rapidly growing in the past year. In most cases, it has significantly better compression ratio compressed to <code>bzip2</code> and <code>gzip</code>, and decompresses significantly faster. However, its compression process is extremely slow (probably 10 times longer the time than <code>bzip2</code>).</p>
<p>One of the algorithms supported by <code><a href="http://www.7-zip.org/">7zip</a></code> is LZMA. In Linux we usually use <a href="http://tukaani.org/lzma/">LZMA Utils</a> instead.</p>
<p>GNU provided the tarball of some versions of <code>coreutils</code> in LZMA (in addition to the traditional GZIP), although they have recently switched to <code><a href="http://tukaani.org/xz/">xz</a></code>.</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/04/logrotating-emergelog/' rel='bookmark' title='[Gentoo] Logrotating emerge.log'>[Gentoo] Logrotating emerge.log</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/05/liblzmadec-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic library symlinks</title>
		<link>http://en.chys.info/2009/04/dynamic-library-symlinks/</link>
		<comments>http://en.chys.info/2009/04/dynamic-library-symlinks/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 23:47:58 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=478</guid>
		<description><![CDATA[Happened to be asked &#8211; so a chance to write it down. Take giflib as an example: It installs three .so files in /usr/lib: libgif.so, libgif.so.4, libgif.so.4.1.6. The third file is the true library, and the first two are both symlinks to the third. It apparently is because that we want to allow multiple versions [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/04/globstar-in-bash-4-follows-symlinks/' rel='bookmark' title='globstar in bash 4 follows directory symlinks'>globstar in bash 4 follows directory symlinks</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Happened to be asked &#8211; so a chance to write it down.</p>
<p>Take <code><a href="http://sourceforge.net/projects/giflib/">giflib</a></code> as an example: It installs three <code>.so</code> files in <code>/usr/lib</code>: <code>libgif.so</code>, <code>libgif.so.4</code>, <code>libgif.so.4.1.6</code>.</p>
<p>The third file is the true library, and the first two are both <acronym title="symbolic links">symlinks</acronym> to the third. It apparently is because that we want to allow multiple versions to coexist in one system that we append the version to the filename.</p>
<p>It is easy to understand why we need <code>libgif.so</code> (otherwise “<code>gcc ... -lgif</code>” is going to fail.)</p>
<p>The number appended to the second symlink, namely 4 here, is the <abbr title="application binary interface">ABI</abbr> version. It does not have to be part of the full version, though it usually is. (<code>glibc</code>, the most important library in a working Linux system, is an exception.)</p>
<p>When linking a program against the library, we specify <code>-lgif</code> in the command line, and the linker would follow the symlink and find <code>libgif.so.4.1.6</code>. However, the library name recorded in the executable is <code>libgifso.4</code> instead. (This name is specified by <code>-Wl,-soname</code> when making the library.) Consequently, if we later make a binary-compatible upgrade to the library and remove the older version, the executable still works. But if the upgrade is a major one (potentially binary-incompatible but still source-level compatible), we must either keep the older library or recompile the executable. If we don&#8217;t make these symlinks and simply use one file <code>libgif.so</code>, we will have hard-to-debug segmentation faults instead of missing-library error messages in such cases.</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/04/globstar-in-bash-4-follows-symlinks/' rel='bookmark' title='globstar in bash 4 follows directory symlinks'>globstar in bash 4 follows directory symlinks</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/04/dynamic-library-symlinks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

