<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>THE Blog</title>
    <link>https://xiexun.org/</link>
    <description>Recent content on THE Blog</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 08 Mar 2020 22:42:22 +0000</lastBuildDate>
    <atom:link href="https://xiexun.org/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Generate Linux Kernel LLVM Bitcode with Custom Optimization</title>
      <link>https://xiexun.org/linux-bc-custom-opt.html/</link>
      <pubDate>Sun, 08 Mar 2020 22:42:22 +0000</pubDate>
      <guid>https://xiexun.org/linux-bc-custom-opt.html/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;https://xiexun.org/compile-linux-llvm.html&#34;&gt;Compile Linux Kernel to LLVM Bitcode&lt;/a&gt; we use wllvm to generate the LLVM bitcode of Linux kernel. when analyzing the kernel, we sometimes need to disable some optimization passes. However, it&amp;rsquo;s hard to do with clang. First compiling it to &lt;code&gt;-O0&lt;/code&gt; IR and then applying some optimization passes on it seems easier.&lt;/p&gt;&#xA;&lt;p&gt;The optimization level of the LLVM IR is &lt;code&gt;-O2&lt;/code&gt; by default. If we need an &lt;code&gt;-O0&lt;/code&gt; LLVM IR, we need to modify the kernel compilation flag.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Compile Linux Kernel to LLVM Bitcode</title>
      <link>https://xiexun.org/compile-linux-llvm.html/</link>
      <pubDate>Fri, 27 Dec 2019 18:32:22 +0000</pubDate>
      <guid>https://xiexun.org/compile-linux-llvm.html/</guid>
      <description>&lt;h1 id=&#34;tools&#34;&gt;Tools&lt;/h1&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/SRI-CSL/whole-program-llvm&#34;&gt;wllvm&lt;/a&gt; 1.2.7&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://clang.llvm.org/&#34;&gt;clang&lt;/a&gt; 9.0.1&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://llvm.org/&#34;&gt;LLVM&lt;/a&gt; 9.0.1&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.3.6.tar.gz&#34;&gt;linux 5.3.6&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h1 id=&#34;compile-kernel-with-wllvm&#34;&gt;Compile Kernel with WLLVM&lt;/h1&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;make CC&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;wllvm defconfig&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;make CC&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;wllvm -j&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;nproc&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;extract-bitcode&#34;&gt;Extract Bitcode&lt;/h1&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;extract-bc vmlinux&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then vmlinux.bc is the bitcode.&lt;/p&gt;&#xA;&lt;h1 id=&#34;cross-compile&#34;&gt;Cross-compile&lt;/h1&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;BINUTILS_TARGET_PREFIX&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;aarch64-linux-gnu make ARCH&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;arm64 CROSS_COMPILE&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;aarch64-linux-gnu- HOSTCC&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;clang CC&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;wllvm defconfig&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;BINUTILS_TARGET_PREFIX&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;aarch64-linux-gnu make ARCH&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;arm64 CROSS_COMPILE&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;aarch64-linux-gnu- HOSTCC&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;clang CC&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;wllvm -j&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;nproc&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, extract bitcode from &lt;code&gt;vmlinux&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;extract-bc vmlinux&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;problems&#34;&gt;Problems&lt;/h1&gt;&#xA;&lt;h2 id=&#34;symbol-multiply-defined-during-bitcode-extraction&#34;&gt;symbol multiply defined during bitcode extraction&lt;/h2&gt;&#xA;&lt;p&gt;When extracting bitcode from vmlinux (arm64), an error occurs:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;error: Linking globals named &amp;lsquo;sort&amp;rsquo;: symbol multiply defined!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Minix IPC</title>
      <link>https://xiexun.org/minix-ipc.html/</link>
      <pubDate>Mon, 09 Dec 2019 14:16:22 +0000</pubDate>
      <guid>https://xiexun.org/minix-ipc.html/</guid>
      <description>&lt;h1 id=&#34;minix-kernel-services-and-user-tasks&#34;&gt;Minix kernel, services and user tasks&lt;/h1&gt;&#xA;&lt;p&gt;Minix services:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;rs: Reincarnation Server&lt;/li&gt;&#xA;&lt;li&gt;ds: Data Store&lt;/li&gt;&#xA;&lt;li&gt;ipc: shared memory and semaphore&lt;/li&gt;&#xA;&lt;li&gt;sched: scheduler&lt;/li&gt;&#xA;&lt;li&gt;vfs: Virtual File Systems&lt;/li&gt;&#xA;&lt;li&gt;vm: Virtual Memory&lt;/li&gt;&#xA;&lt;li&gt;is: System Information Service&lt;/li&gt;&#xA;&lt;li&gt;mib: Manage Information Base&lt;/li&gt;&#xA;&lt;li&gt;pm: Process Manager&lt;/li&gt;&#xA;&lt;li&gt;drivers, filesystems, &amp;hellip;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://xiexun.org/img/minix_procs.svg&#34; alt=&#34;minix-procs&#34;&gt;&lt;/p&gt;&#xA;&lt;h1 id=&#34;kernel-ipc&#34;&gt;kernel IPC&lt;/h1&gt;&#xA;&lt;p&gt;Minix kernel provides interface for IPC and kernel call. System services can do kernel IPC and kernel calls, but user process can only do kernel IPC.&#xA;Kernel IPC delivers 64 bytes message between processes.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
