chris.bracken.jp

Statically generated site for chris.bracken.jp
git clone https://git.bracken.jp/chris.bracken.jp.git
Log | Files | Refs

index.xml (54212B)


      1 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
      2 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      3   <channel>
      4     <title>Software on Chris Bracken</title>
      5     <link>https://chris.bracken.jp/tags/software/</link>
      6     <description>Recent content in Software on Chris Bracken</description>
      7     <generator>Hugo -- gohugo.io</generator>
      8     <language>en</language>
      9     <managingEditor>chris@bracken.jp (Chris Bracken)</managingEditor>
     10     <webMaster>chris@bracken.jp (Chris Bracken)</webMaster>
     11     <lastBuildDate>Wed, 31 Oct 2018 00:00:00 +0000</lastBuildDate><atom:link href="https://chris.bracken.jp/tags/software/index.xml" rel="self" type="application/rss+xml" />
     12     <item>
     13       <title>Hand-decoding an ELF binary image</title>
     14       <link>https://chris.bracken.jp/2018/10/decoding-an-elf-binary/</link>
     15       <pubDate>Wed, 31 Oct 2018 00:00:00 +0000</pubDate>
     16       <author>chris@bracken.jp (Chris Bracken)</author>
     17       <guid>https://chris.bracken.jp/2018/10/decoding-an-elf-binary/</guid>
     18       <description>&lt;p&gt;While recovering from some dentistry the other day I figured I&amp;rsquo;d have a go at
     19 better understanding the ELF binary format. What better way to do that than to
     20 compile a small program and hand-decode the resulting binary with a hex editor
     21 and whatever ELF format spec I could find.&lt;/p&gt;
     22 &lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
     23 &lt;p&gt;Below, we&amp;rsquo;ll use &lt;code&gt;nasm&lt;/code&gt; to build a small assembly Hello World program to a
     24 64-bit ELF object file, then link that into an ELF executable with GNU &lt;code&gt;ld&lt;/code&gt;.
     25 Finally, we&amp;rsquo;ll run the resulting object file and binary image through &lt;code&gt;xxd&lt;/code&gt; and
     26 hand-decode the resulting hex.&lt;/p&gt;
     27 &lt;p&gt;The code and instructions below work on FreeBSD 11 on x86_64 hardware. For
     28 other operating systems, hardware, and toolchains, you&amp;rsquo;re on your own! I&amp;rsquo;d
     29 imagine this should all work just fine on Linux. If I get bored one day, I may
     30 redo this for Mach-O binaries on macOS.&lt;/p&gt;
     31 &lt;h2 id=&#34;helloasm&#34;&gt;hello.asm&lt;/h2&gt;
     32 &lt;p&gt;First we&amp;rsquo;ll bang up a minimal Hello World program in assembly. In the &lt;code&gt;.data&lt;/code&gt;
     33 section, we add a null-terminated string, &lt;code&gt;hello&lt;/code&gt;, and its length &lt;code&gt;hbytes&lt;/code&gt;. In
     34 the program text, we set up and execute the &lt;code&gt;write(stdout, hello, hbytes)&lt;/code&gt;
     35 syscall, then set up and execute an &lt;code&gt;exit(0)&lt;/code&gt; syscall.&lt;/p&gt;
     36 &lt;p&gt;Note that 64-bit FreeBSD, macOS, and Linux all use the SysV AMD64 calling
     37 convention. For calls against the kernel interface, the syscall number is
     38 stored in &lt;code&gt;rax&lt;/code&gt; and up to six parameters are passed, in order, in &lt;code&gt;rdi&lt;/code&gt;, &lt;code&gt;rsi&lt;/code&gt;,
     39 &lt;code&gt;rdx&lt;/code&gt;, &lt;code&gt;r10&lt;/code&gt;, &lt;code&gt;r8&lt;/code&gt;, &lt;code&gt;r9&lt;/code&gt;. For user calls, replace &lt;code&gt;r10&lt;/code&gt; with &lt;code&gt;rcx&lt;/code&gt; in this
     40 list, and pass further arguments on the stack. In all cases, the return value
     41 is passed through &lt;code&gt;rax&lt;/code&gt;.  More details can be found in section A.2.1 of the
     42 &lt;a href=&#34;https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf&#34;&gt;System V AMD64 ABI Reference&lt;/a&gt;.&lt;/p&gt;
     43 &lt;pre&gt;&lt;code&gt;; hello.asm
     44 
     45 %define stdin       0
     46 %define stdout      1
     47 %define stderr      2
     48 %define SYS_exit    1
     49 %define SYS_write   4
     50 
     51 %macro  system      1
     52         mov         rax, %1
     53         syscall
     54 %endmacro
     55 
     56 %macro  sys.exit    0
     57         system      SYS_exit
     58 %endmacro
     59 
     60 %macro  sys.write   0
     61         system      SYS_write
     62 %endmacro
     63 
     64 section  .data
     65     hello   db      &#39;Hello, World!&#39;, 0Ah
     66     hbytes  equ     $-hello
     67 
     68 section .text
     69 global  _start
     70 _start:
     71     mov         rdi, stdout
     72     mov         rsi, hello
     73     mov         rdx, hbytes
     74     sys.write
     75 
     76     xor         rdi,rdi
     77     sys.exit
     78 &lt;/code&gt;&lt;/pre&gt;
     79 &lt;h2 id=&#34;compile-to-object-code&#34;&gt;Compile to object code&lt;/h2&gt;
     80 &lt;p&gt;Next, we&amp;rsquo;ll compile &lt;code&gt;hello.asm&lt;/code&gt; to a 64-bit ELF object file using &lt;code&gt;nasm&lt;/code&gt;:&lt;/p&gt;
     81 &lt;pre&gt;&lt;code&gt;% nasm -f elf64 hello.asm
     82 &lt;/code&gt;&lt;/pre&gt;
     83 &lt;p&gt;This emits &lt;code&gt;hello.o&lt;/code&gt;, an 880-byte ELF-64 object file. Since we haven&amp;rsquo;t yet run
     84 this through the linker, addresses of global symbols (in this case, &lt;code&gt;hello&lt;/code&gt;)
     85 are not yet known and thus left with address 0x0 placeholders. We can see this
     86 in the &lt;code&gt;movabs&lt;/code&gt; instruction at offset 0x15 of the &lt;code&gt;.text&lt;/code&gt; section below.&lt;/p&gt;
     87 &lt;p&gt;The relocation section (Section 6: &lt;code&gt;.rela.text&lt;/code&gt;) contains an entry for each
     88 symbolic reference that needs to be filled in by the linker. In this case
     89 there&amp;rsquo;s just a single entry for the symbol &lt;code&gt;hello&lt;/code&gt; (which points to our hello
     90 world string). The relocation table entry&amp;rsquo;s &lt;code&gt;r_offset&lt;/code&gt; indicates the address to
     91 replace is at an offset of 0x7 into the section of the associated symbol table
     92 entry. Its &lt;code&gt;r_info&lt;/code&gt; (0x0000000200000001) encodes a relocation type in its lower
     93 4 bytes (0x1: &lt;code&gt;R_AMD64_64&lt;/code&gt;) and the associated symbol table entry in its upper
     94 4 bytes (0x2, which, if we look it up in the symbol table is the &lt;code&gt;.text&lt;/code&gt;
     95 section).  The &lt;code&gt;r_addend&lt;/code&gt; field (0x0) specifies an additional adjustment to the
     96 substituted symbol to be applied at link time; specifically, for the
     97 &lt;code&gt;R_AMD64_64&lt;/code&gt;, the final address is computed as S + A, where S is the
     98 substituted symbol value (in our case, the address of &lt;code&gt;hello&lt;/code&gt;) and A is the
     99 addend (in our case, 0x0).&lt;/p&gt;
    100 &lt;p&gt;Without further ado, let&amp;rsquo;s dump the object file:&lt;/p&gt;
    101 &lt;pre&gt;&lt;code&gt;% xxd hello.o
    102 &lt;/code&gt;&lt;/pre&gt;
    103 &lt;p&gt;With whatever ELF64 &lt;a href=&#34;https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/index.html&#34;&gt;linker &amp;amp; loader guide&lt;/a&gt; we can find at hand,
    104 let&amp;rsquo;s get decoding this thing:&lt;/p&gt;
    105 &lt;h3 id=&#34;elf-header&#34;&gt;ELF Header&lt;/h3&gt;
    106 &lt;pre&gt;&lt;code&gt;|00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000|  .ELF............
    107 |00000010: 0100 3e00 0100 0000 0000 0000 0000 0000|  ..&amp;gt;.............
    108 |00000020: 0000 0000 0000 0000 4000 0000 0000 0000|  ........@.......
    109 |00000030: 0000 0000 4000 0000 0000 4000 0700 0300|  ....@.....@.....
    110 
    111 e_ident[EI_MAG0..EI_MAG3]  0x7f + ELF          Magic
    112 e_ident[EI_CLASS]          0x02                64-bit
    113 e_ident[EI_DATA]           0x01                Little-endian
    114 e_ident[EI_VERSION]        0x01                ELF v1
    115 e_ident[EI_OSABI]          0x00                System V
    116 e_ident[EI_ABIVERSION]     0x00                Unused
    117 e_ident[EI_PAD]            0x00000000000000    7 bytes unused padding
    118 e_type                     0x0001              ET_REL
    119 e_machine                  0x003e              x86_64
    120 e_version                  0x00000001          Version 1
    121 e_entry                    0x0000000000000000  Entrypoint address (none)
    122 e_phoff                    0x0000000000000000  Program header table offset in image
    123 e_shoff                    0x0000000000000040  Section header table offset in image
    124 e_flags                    0x00000000          Architecture-dependent interpretation
    125 e_ehsize                   0x0040              Size of this ELF header (64B)
    126 e_phentsize                0x0000              Size of program header table entry
    127 e_phnum                    0x0000              Number of program header table entries
    128 e_shentsize                0x0040              Size of section header table entry (64B)
    129 e_shnum                    0x0007              Number of section header table entries
    130 e_shstrndx                 0x0003              Index of section header for .shstrtab
    131 &lt;/code&gt;&lt;/pre&gt;
    132 &lt;h3 id=&#34;section-header-table-entry-0-null&#34;&gt;Section header table: Entry 0 (null)&lt;/h3&gt;
    133 &lt;pre&gt;&lt;code&gt;|00000040: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    134 |00000050: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    135 |00000060: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    136 |00000070: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    137 
    138 sh_name                    0x00000000          Offset into .shstrtab
    139 sh_type                    0x00000000          SHT_NULL
    140 sh_flags                   0x0000000000000000  Section attributes
    141 sh_addr                    0x0000000000000000  Virtual address of section in memory
    142 sh_offset                  0x0000000000000000  Offset of section in file image
    143 sh_size                    0x0000000000000000  Size in bytes of section in file image
    144 sh_link                    0x00000000          Section index of associated section
    145 sh_info                    0x00000000          Extra info about section
    146 sh_addralign               0x0000000000000000  Alignment
    147 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    148 &lt;/code&gt;&lt;/pre&gt;
    149 &lt;h3 id=&#34;section-header-table-entry-1-data&#34;&gt;Section header table: Entry 1 (.data)&lt;/h3&gt;
    150 &lt;pre&gt;&lt;code&gt;|00000080: 0100 0000 0100 0000 0300 0000 0000 0000|  ................
    151 |00000090: 0000 0000 0000 0000 0002 0000 0000 0000|  ................
    152 |000000a0: 0e00 0000 0000 0000 0000 0000 0000 0000|  ................
    153 |000000b0: 0400 0000 0000 0000 0000 0000 0000 0000|  ................
    154 
    155 sh_name                    0x00000001          Offset into .shstrtab
    156 sh_type                    0x00000001          SHT_PROGBITS
    157 sh_flags                   0x0000000000000003  SHF_WRITE | SHF_ALLOC
    158 sh_addr                    0x0000000000000000  Virtual address of section in memory
    159 sh_offset                  0x0000000000000200  Offset of section in file image
    160 sh_size                    0x000000000000000e  Size in bytes of section in file image
    161 sh_link                    0x00000000          Section index of associated section
    162 sh_info                    0x00000000          Extra info about section
    163 sh_addralign               0x0000000000000004  Alignment
    164 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    165 &lt;/code&gt;&lt;/pre&gt;
    166 &lt;h3 id=&#34;section-header-table-entry-2-text&#34;&gt;Section header table: Entry 2 (.text)&lt;/h3&gt;
    167 &lt;pre&gt;&lt;code&gt;|000000c0: 0700 0000 0100 0000 0600 0000 0000 0000|  ................
    168 |000000d0: 0000 0000 0000 0000 1002 0000 0000 0000|  ................
    169 |000000e0: 2500 0000 0000 0000 0000 0000 0000 0000|  %...............
    170 |000000f0: 1000 0000 0000 0000 0000 0000 0000 0000|  ................
    171 
    172 sh_name                    0x00000007          Offset into .shstrtab
    173 sh_type                    0x00000001          SHT_PROGBITS
    174 sh_flags                   0x0000000000000006  SHF_ALLOC | SHF_EXECINSTR
    175 sh_addr                    0x0000000000000000  Virtual address of section in memory
    176 sh_offset                  0x0000000000000210  Offset of section in file image
    177 sh_size                    0x0000000000000025  Size in bytes of section in file image
    178 sh_link                    0x00000000          Section index of associated section
    179 sh_info                    0x00000000          Extra info about section
    180 sh_addralign               0x0000000000000001  Alignment
    181 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    182 &lt;/code&gt;&lt;/pre&gt;
    183 &lt;h3 id=&#34;section-header-table-entry-3-shstrtab&#34;&gt;Section header table: Entry 3 (.shstrtab)&lt;/h3&gt;
    184 &lt;pre&gt;&lt;code&gt;|00000100: 0d00 0000 0300 0000 0000 0000 0000 0000|  ................
    185 |00000110: 0000 0000 0000 0000 4002 0000 0000 0000|  ........@.......
    186 |00000120: 3200 0000 0000 0000 0000 0000 0000 0000|  2...............
    187 |00000130: 0100 0000 0000 0000 0000 0000 0000 0000|  ................
    188 
    189 sh_name                    0x0000000d          Offset into .shstrtab
    190 sh_type                    0x00000003          SHT_STRTAB
    191 sh_flags                   0x0000000000000000  Section attributes
    192 sh_addr                    0x0000000000000000  Virtual address of section in memory
    193 sh_offset                  0x0000000000000240  Offset of section in file image
    194 sh_size                    0x0000000000000032  Size in bytes of section in file image
    195 sh_link                    0x00000000          Section index of associated section
    196 sh_info                    0x00000000          Extra info about section
    197 sh_addralign               0x0000000000000001  Alignment
    198 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    199 &lt;/code&gt;&lt;/pre&gt;
    200 &lt;h3 id=&#34;section-header-table-entry-4-symtab&#34;&gt;Section header table: Entry 4 (.symtab)&lt;/h3&gt;
    201 &lt;pre&gt;&lt;code&gt;|00000140: 1700 0000 0200 0000 0000 0000 0000 0000|  ................
    202 |00000150: 0000 0000 0000 0000 8002 0000 0000 0000|  ................
    203 |00000160: a800 0000 0000 0000 0500 0000 0600 0000|  ................
    204 |00000170: 0800 0000 0000 0000 1800 0000 0000 0000|  ................
    205 
    206 sh_name                    0x00000017          Offset into .shstrtab
    207 sh_type                    0x00000002          SHT_SYMTAB
    208 sh_flags                   0x0000000000000000  Section attributes
    209 sh_addr                    0x0000000000000000  Virtual address of section in memory
    210 sh_offset                  0x0000000000000280  Offset of section in file image
    211 sh_size                    0x00000000000000a8  Size in bytes of section in file image
    212 sh_link                    0x00000005          Section index of associated section
    213 sh_info                    0x00000006          Extra info about section
    214 sh_addralign               0x0000000000000008  Alignment
    215 sh_entsize                 0x0000000000000018  Size in bytes of each entry
    216 &lt;/code&gt;&lt;/pre&gt;
    217 &lt;h3 id=&#34;section-header-table-entry-5-strtab&#34;&gt;Section header table: Entry 5 (.strtab)&lt;/h3&gt;
    218 &lt;pre&gt;&lt;code&gt;|00000180: 1f00 0000 0300 0000 0000 0000 0000 0000|  ................
    219 |00000190: 0000 0000 0000 0000 3003 0000 0000 0000|  ........0.......
    220 |000001a0: 1f00 0000 0000 0000 0000 0000 0000 0000|  ................
    221 |000001b0: 0100 0000 0000 0000 0000 0000 0000 0000|  ................
    222 
    223 sh_name                    0x0000001f          Offset into .shstrtab
    224 sh_type                    0x00000003          SHT_STRTAB
    225 sh_flags                   0x0000000000000000  Section attributes
    226 sh_addr                    0x0000000000000000  Virtual address of section in memory
    227 sh_offset                  0x0000000000000330  Offset of section in file image
    228 sh_size                    0x000000000000001f  Size in bytes of section in file image
    229 sh_link                    0x00000000          Section index of associated section
    230 sh_info                    0x00000000          Extra info about section
    231 sh_addralign               0x0000000000000001  Alignment
    232 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    233 &lt;/code&gt;&lt;/pre&gt;
    234 &lt;h3 id=&#34;section-header-table-entry-6-relatext&#34;&gt;Section header table: Entry 6 (.rela.text)&lt;/h3&gt;
    235 &lt;pre&gt;&lt;code&gt;|000001c0: 2700 0000 0400 0000 0000 0000 0000 0000|  &#39;...............
    236 |000001d0: 0000 0000 0000 0000 5003 0000 0000 0000|  ........P.......
    237 |000001e0: 1800 0000 0000 0000 0400 0000 0200 0000|  ................
    238 |000001f0: 0800 0000 0000 0000 1800 0000 0000 0000|  ................
    239 
    240 sh_name                    0x00000027          Offset into .shstrtab
    241 sh_type                    0x00000004          SHT_RELA
    242 sh_flags                   0x0000000000000000  Section attributes
    243 sh_addr                    0x0000000000000000  Virtual address of section in memory
    244 sh_offset                  0x0000000000000350  Offset of section in file image
    245 sh_size                    0x0000000000000018  Size in bytes of section in file image
    246 sh_link                    0x00000004          Section index of associated section
    247 sh_info                    0x00000002          Extra info about section
    248 sh_addralign               0x0000000000000008  Alignment
    249 sh_entsize                 0x0000000000000018  Size in bytes of each entry
    250 &lt;/code&gt;&lt;/pre&gt;
    251 &lt;h3 id=&#34;section-1-data-sht_progbits-shf_write--shf_alloc&#34;&gt;Section 1: .data (SHT_PROGBITS; SHF_WRITE | SHF_ALLOC)&lt;/h3&gt;
    252 &lt;pre&gt;&lt;code&gt;|00000200: 4865 6c6c 6f2c 2057 6f72 6c64 210a 0000|  Hello, World!...
    253 
    254 0x000000  &#39;Hello, World!\n&#39;
    255 Zero-padding (2 bytes starting at 0x20e)
    256 &lt;/code&gt;&lt;/pre&gt;
    257 &lt;h3 id=&#34;section-2-text-sht_progbits-shf_alloc--shf_execinstr&#34;&gt;Section 2: .text (SHT_PROGBITS; SHF_ALLOC | SHF_EXECINSTR)&lt;/h3&gt;
    258 &lt;pre&gt;&lt;code&gt;|00000210: bf01 0000 0048 be00 0000 0000 0000 00ba|  .....H..........
    259 |00000220: 0e00 0000 b804 0000 000f 0548 31ff b801|  ...........H1...
    260 |00000230: 0000 000f 0500 0000 0000 0000 0000 0000|  ................
    261 
    262 0x00000010  mov       edi, 0x1
    263 0x00000015  movabs    rsi, 0x000000 (placeholder for db hello)
    264 0x0000001f  mov       edx, 0xe
    265 0x00000024  mov       eax, 0x4
    266 0x00400029  syscall
    267 0x0040002b  xor       rdi, rdi
    268 0x0040002e  mov       eax, 0x1
    269 0x00400033  syscall
    270 Zero-padding (11 bytes starting at 0x235)
    271 &lt;/code&gt;&lt;/pre&gt;
    272 &lt;h3 id=&#34;section-3-shstrtab-sht_strtab&#34;&gt;Section 3: .shstrtab (SHT_STRTAB;)&lt;/h3&gt;
    273 &lt;pre&gt;&lt;code&gt;|00000240: 002e 6461 7461 002e 7465 7874 002e 7368|  ..data..text..sh
    274 |00000250: 7374 7274 6162 002e 7379 6d74 6162 002e|  strtab..symtab..
    275 |00000260: 7374 7274 6162 002e 7265 6c61 2e74 6578|  strtab..rela.tex
    276 |00000270: 7400 0000 0000 0000 0000 0000 0000 0000|  t...............
    277 
    278 0x00000000: &#39;&#39;
    279 0x00000001: &#39;.data&#39;
    280 0x00000007: &#39;.text&#39;
    281 0x0000000d: &#39;.shstrtab&#39;
    282 0x00000017: &#39;.symtab&#39;
    283 0x0000001f: &#39;.strtab&#39;
    284 0x00000027: &#39;.rela.text&#39;
    285 Zero-padding (14 bytes starting at 0x272)
    286 &lt;/code&gt;&lt;/pre&gt;
    287 &lt;h3 id=&#34;section-4-symtab-sht_symtab&#34;&gt;Section 4: .symtab&amp;rsquo; (SHT_SYMTAB;)&lt;/h3&gt;
    288 &lt;h4 id=&#34;symbol-table-entry-0&#34;&gt;Symbol table entry 0&lt;/h4&gt;
    289 &lt;pre&gt;&lt;code&gt;|00000280: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    290 |00000290: 0000 0000 0000 0000                    |  ........
    291 
    292 st_name                    0x00000000
    293 st_info                    0x00
    294 st_other                   0x00
    295 st_shndx                   0x0000 (SHN_UNDEF)
    296 st_value                   0x0000000000000000
    297 st_size                    0x0000000000000000
    298 &lt;/code&gt;&lt;/pre&gt;
    299 &lt;h4 id=&#34;symbol-table-entry-1-helloasm&#34;&gt;Symbol table entry 1 (hello.asm)&lt;/h4&gt;
    300 &lt;pre&gt;&lt;code&gt;|00000298:                     0100 0000 0400 f1ff|          ........
    301 |000002a0: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    302 
    303 st_name                    0x00000001
    304 st_info                    0x04 (STT_FILE)
    305 st_other                   0x00
    306 st_shndx                   0xfff1 (SHN_ABS)
    307 st_value                   0x0000000000000000
    308 st_size                    0x0000000000000000
    309 &lt;/code&gt;&lt;/pre&gt;
    310 &lt;h4 id=&#34;symbol-table-entry-2&#34;&gt;Symbol table entry 2&lt;/h4&gt;
    311 &lt;pre&gt;&lt;code&gt;|000002b0: 0000 0000 0300 0100 0000 0000 0000 0000|  ................
    312 |000002c0: 0000 0000 0000 0000                    |  ........
    313 
    314 st_name                    0x00000000
    315 st_info                    0x03 (STT_OBJECT | STT_FUNC)
    316 st_other                   0x00
    317 st_shndx                   0x0001 (Section 1: .data)
    318 st_value                   0x0000000000000000
    319 st_size                    0x0000000000000000
    320 &lt;/code&gt;&lt;/pre&gt;
    321 &lt;h4 id=&#34;symbol-table-entry-3&#34;&gt;Symbol table entry 3&lt;/h4&gt;
    322 &lt;pre&gt;&lt;code&gt;|000002c8:                     0000 0000 0300 0200|          ........
    323 |000002d0: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    324 
    325 st_name                    0x00000000
    326 st_info                    0x03 (STT_OBJECT | STT_FUNC)
    327 st_other                   0x00
    328 st_shndx                   0x0002 (Section 2: .text)
    329 st_value                   0x0000000000000000
    330 st_size                    0x0000000000000000
    331 &lt;/code&gt;&lt;/pre&gt;
    332 &lt;h4 id=&#34;symbol-table-entry-4-hello&#34;&gt;Symbol table entry 4 (hello)&lt;/h4&gt;
    333 &lt;pre&gt;&lt;code&gt;|000002e0: 0b00 0000 0000 0100 0000 0000 0000 0000|  ................
    334 |000002f0: 0000 0000 0000 0000                    |  ........
    335 
    336 st_name                    0x0000000b
    337 st_info                    0x00
    338 st_other                   0x00
    339 st_shndx                   0x0001 (Section 1: .data)
    340 st_value                   0x0000000000000000
    341 st_size                    0x0000000000000000
    342 &lt;/code&gt;&lt;/pre&gt;
    343 &lt;h3 id=&#34;symbol-table-entry-5-hbytes&#34;&gt;Symbol table entry 5 (hbytes)&lt;/h3&gt;
    344 &lt;pre&gt;&lt;code&gt;|000002f8:                     1100 0000 0000 f1ff|          ........
    345 |00000300: 0e00 0000 0000 0000 0000 0000 0000 0000|  ................
    346 
    347 st_name                    0x00000011
    348 st_info                    0x00
    349 st_other                   0x00
    350 st_shndx                   0xfff1 (SHN_ABS)
    351 st_value                   0x000000000000000e
    352 st_size                    0x0000000000000000
    353 &lt;/code&gt;&lt;/pre&gt;
    354 &lt;h4 id=&#34;symbol-table-entry-6-_start&#34;&gt;Symbol table entry 6 (_start)&lt;/h4&gt;
    355 &lt;pre&gt;&lt;code&gt;|00000310: 1800 0000 1000 0200 0000 0000 0000 0000|  ................
    356 |00000320: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    357 
    358 st_name                    0x00000018
    359 st_info                    0x01 (STT_OBJECT)
    360 st_other                   0x00
    361 st_shndx                   0x0002 (Section 2: .text)
    362 st_value                   0x0000000000000000
    363 st_size                    0x0000000000000000
    364 Zero-padding (8 bytes starting at 0x328)
    365 &lt;/code&gt;&lt;/pre&gt;
    366 &lt;h3 id=&#34;section-5-strtab-sht_strtab&#34;&gt;Section 5: .strtab (SHT_STRTAB;)&lt;/h3&gt;
    367 &lt;pre&gt;&lt;code&gt;|00000330: 0068 656c 6c6f 2e61 736d 0068 656c 6c6f|  .hello.asm.hello
    368 |00000340: 0068 6279 7465 7300 5f73 7461 7274 0000|  .hbytes._start..
    369 
    370 0x00000000: &#39;&#39;
    371 0x00000001: &#39;hello.asm&#39;
    372 0x0000000b: &#39;hello&#39;
    373 0x00000011: &#39;hbytes&#39;
    374 0x00000018: &#39;_start&#39;
    375 Zero-padding (1 byte starting at 0x34f)
    376 &lt;/code&gt;&lt;/pre&gt;
    377 &lt;h3 id=&#34;section-6-relatext-sht_rela&#34;&gt;Section 6: .rela.text (SHT_RELA;)&lt;/h3&gt;
    378 &lt;pre&gt;&lt;code&gt;|00000350: 0700 0000 0000 0000 0100 0000 0200 0000|  ................
    379 |00000360: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    380 
    381 r_offset                   0x0000000000000007
    382 r_info                     0x0000000200000001 (Symbol table entry 2, type R_AMD64_64)
    383 r_addend                   0x0000000000000000
    384 Zero-padding (8 bytes starting at 0x368)
    385 &lt;/code&gt;&lt;/pre&gt;
    386 &lt;h2 id=&#34;link-to-executable-image&#34;&gt;Link to executable image&lt;/h2&gt;
    387 &lt;p&gt;Next, let&amp;rsquo;s link &lt;code&gt;hello.o&lt;/code&gt; into a 64-bit ELF executable:&lt;/p&gt;
    388 &lt;pre&gt;&lt;code&gt;% ld -o hello hello.o
    389 &lt;/code&gt;&lt;/pre&gt;
    390 &lt;p&gt;This emits &lt;code&gt;hello&lt;/code&gt;, a 951-byte ELF-64 executable image.&lt;/p&gt;
    391 &lt;p&gt;Since the linker has decided which segment each section maps into (if any) and
    392 what the segment addresses are, addresses are now known for all (statically
    393 linked) symbols, and address 0x0 placeholders have been replaced with actual
    394 addresses. We can see this in the &lt;code&gt;mov&lt;/code&gt; instruction at address 0x4000b5, which
    395 now specifies an address of 0x6000d8.&lt;/p&gt;
    396 &lt;p&gt;Running the linked executable image through &lt;code&gt;xxd&lt;/code&gt; as above and picking our
    397 trusty linker &amp;amp; loader guide back up, here we go again:&lt;/p&gt;
    398 &lt;h3 id=&#34;elf-header-1&#34;&gt;ELF Header&lt;/h3&gt;
    399 &lt;pre&gt;&lt;code&gt;|00000000: 7f45 4c46 0201 0109 0000 0000 0000 0000|  .ELF............
    400 |00000010: 0200 3e00 0100 0000 b000 4000 0000 0000|  ..&amp;gt;.......@.....
    401 |00000020: 4000 0000 0000 0000 1001 0000 0000 0000|  @...............
    402 |00000030: 0000 0000 4000 3800 0200 4000 0600 0300|  ....@.8...@.....
    403 
    404 e_ident[EI_MAG0..EI_MAG3]  0x7f + ELF          Magic
    405 e_ident[EI_CLASS]          0x02                64-bit
    406 e_ident[EI_DATA]           0x01                Little-endian
    407 e_ident[EI_VERSION]        0x01                ELF v1
    408 e_ident[EI_OSABI]          0x09                FreeBSD
    409 e_ident[EI_ABIVERSION]     0x00                Unused
    410 e_ident[EI_PAD]            0x0000000000        7 bytes unused padding
    411 e_type                     0x0002              ET_EXEC
    412 e_machine                  0x003e              x86_64
    413 e_version                  0x00000001          Version 1
    414 e_entry                    0x00000000004000b0  Entrypoint addr
    415 e_phoff                    0x0000000000000040  Program header table offset in image
    416 e_shoff                    0x0000000000000110  Section header table offset in image
    417 e_flags                    0x00000000          Architecture-dependent interpretation
    418 e_ehsize                   0x0040              Size of this ELF header
    419 e_phentsize                0x0038              Size of program header table entry
    420 e_phnum                    0x0002              Number of program header table entries
    421 e_shentsize                0x0040              Size of section header table entry
    422 e_shnum                    0x0006              Number of section header table entries
    423 e_shstrndx                 0x0003              Index of section header for .shstrtab
    424 &lt;/code&gt;&lt;/pre&gt;
    425 &lt;h3 id=&#34;program-header-table-entry-0-pf_x--pf_r&#34;&gt;Program header table: Entry 0 (PF_X | PF_R)&lt;/h3&gt;
    426 &lt;pre&gt;&lt;code&gt;|00000040: 0100 0000 0500 0000 0000 0000 0000 0000|  ................
    427 |00000050: 0000 4000 0000 0000 0000 4000 0000 0000|  ..@.......@.....
    428 |00000060: d500 0000 0000 0000 d500 0000 0000 0000|  ................
    429 |00000070: 0000 2000 0000 0000                    |  .. .............
    430 
    431 p_type                     0x00000001          PT_LOAD
    432 p_flags                    0x00000005          PF_X | PF_R
    433 p_offset                   0x00000000          Offset of segment in file image
    434 p_vaddr                    0x0000000000400000  Virtual address of segment in memory
    435 p_paddr                    0x0000000000400000  Physical address of segment
    436 p_filesz                   0x00000000000000d5  Size in bytes of segment in file image
    437 p_memsz                    0x00000000000000d5  Size in bytes of segment in memory
    438 p_align                    0x0000000000200000  Alignment (2MB)
    439 &lt;/code&gt;&lt;/pre&gt;
    440 &lt;h3 id=&#34;program-header-table-entry-1-pf_w--pf_r&#34;&gt;Program header table: Entry 1 (PF_W | PF_R)&lt;/h3&gt;
    441 &lt;pre&gt;&lt;code&gt;|00000078:                     0100 0000 0600 0000|          ........
    442 |00000080: d800 0000 0000 0000 d800 6000 0000 0000|  ..........`.....
    443 |00000090: d800 6000 0000 0000 0e00 0000 0000 0000|  ..`.............
    444 |000000a0: 0e00 0000 0000 0000 0000 2000 0000 0000|  .......... .....
    445 
    446 p_type                     0x00000001          PT_LOAD
    447 p_flags                    0x00000006          PF_W | PF_R
    448 p_offset                   0x00000000000000d8  Offset of segment in file image
    449 p_vaddr                    0x00000000006000d8  Virtual address of segment in memory
    450 p_paddr                    0x00000000006000d8  Physical address of segment
    451 p_filesz                   0x000000000000000e  Size in bytes of segment in file image
    452 p_memsz                    0x000000000000000e  Size in bytes of segment in memory
    453 p_align                    0x0000000000200000  Alignment (2MB)
    454 &lt;/code&gt;&lt;/pre&gt;
    455 &lt;h3 id=&#34;section-1-text-sht_progbits-shf_alloc--shf_execinstr&#34;&gt;Section 1: .text (SHT_PROGBITS; SHF_ALLOC | SHF_EXECINSTR)&lt;/h3&gt;
    456 &lt;pre&gt;&lt;code&gt;|000000b0: bf01 0000 0048 bed8 0060 0000 0000 00ba|  .....H...`......
    457 |000000c0: 0e00 0000 b804 0000 000f 0548 31ff b801|  ...........H1...
    458 |000000d0: 0000 000f 05                           |  .....
    459 
    460 0x4000b0  mov       edi, 0x1
    461 0x4000b5  movabs    rsi, 0x6000d8
    462 0x4000bf  mov       edx, 0xe
    463 0x4000c4  mov       eax, 0x4
    464 0x4000c9  syscall
    465 0x4000cb  xor       rdi, rdi
    466 0x4000ce  mov       eax, 0x1
    467 0x4000d3  syscall
    468 Zero-padding (5 bytes starting at 0x000000d5)
    469 &lt;/code&gt;&lt;/pre&gt;
    470 &lt;h3 id=&#34;section-2-data-sht_progbits-shf_write--shf_alloc&#34;&gt;Section 2: .data (SHT_PROGBITS; SHF_WRITE | SHF_ALLOC)&lt;/h3&gt;
    471 &lt;pre&gt;&lt;code&gt;|000000d8:                     4865 6c6c 6f2c 2057|          Hello, W
    472 |000000e0: 6f72 6c64 210a                         |  orld!.
    473 
    474 0x6000d8  &#39;Hello, World!\n&#39;
    475 &lt;/code&gt;&lt;/pre&gt;
    476 &lt;h3 id=&#34;section-3-shstrtab-sht_strtab-1&#34;&gt;Section 3: .shstrtab (SHT_STRTAB;)&lt;/h3&gt;
    477 &lt;pre&gt;&lt;code&gt;|000000e6:                002e 7379 6d74 6162 002e|        ..symtab..
    478 |000000f0: 7374 7274 6162 002e 7368 7374 7274 6162|  strtab..shstrtab
    479 |00000100: 002e 7465 7874 002e 6461 7461 0000 0000|  ..text..data.
    480 
    481 0x00000000: &#39;&#39;
    482 0x00000001: &#39;.symtab&#39;
    483 0x00000009: &#39;.strtab&#39;
    484 0x00000011: &#39;.shstrtab&#39;
    485 0x0000001b: &#39;.text&#39;
    486 0x00000021: &#39;.data&#39;
    487 Zero-padding (3 bytes starting at 0x0000010d)
    488 &lt;/code&gt;&lt;/pre&gt;
    489 &lt;h3 id=&#34;section-header-table-entry-0-null-1&#34;&gt;Section header table: Entry 0 (null)&lt;/h3&gt;
    490 &lt;pre&gt;&lt;code&gt;|00000110: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    491 |00000120: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    492 |00000130: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    493 |00000140: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    494 
    495 sh_name                    0x00000000          Offset into .shstrtab
    496 sh_type                    0x00000000          SHT_NULL
    497 sh_flags                   0x0000000000000000  Section attributes
    498 sh_addr                    0x0000000000000000  Virtual address of section in memory
    499 sh_offset                  0x0000000000000000  Offset of section in file image
    500 sh_size                    0x0000000000000000  Size in bytes of section in file image
    501 sh_link                    0x00000000          Section index of associated section
    502 sh_info                    0x00000000          Extra info about section
    503 sh_addralign               0x0000000000000000  Alignment
    504 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    505 &lt;/code&gt;&lt;/pre&gt;
    506 &lt;h3 id=&#34;section-header-table-entry-1-text&#34;&gt;Section header table: Entry 1 (.text)&lt;/h3&gt;
    507 &lt;pre&gt;&lt;code&gt;|00000150: 1b00 0000 0100 0000 0600 0000 0000 0000|  ................
    508 |00000160: b000 4000 0000 0000 b000 0000 0000 0000|  ..@.............
    509 |00000170: 2500 0000 0000 0000 0000 0000 0000 0000|  %...............
    510 |00000180: 1000 0000 0000 0000 0000 0000 0000 0000|  ................
    511 
    512 sh_name                    0x0000001b          Offset into .shstrtab
    513 sh_type                    0x00000001          SHT_PROGBITS
    514 sh_flags                   0x00000006          SHF_ALLOC | SHF_EXECINSTR
    515 sh_addr                    0x00000000004000b0  Virtual address of section in memory
    516 sh_offset                  0x00000000000000b0  Offset of section in file image
    517 sh_size                    0x0000000000000025  Size in bytes of section in file image
    518 sh_link                    0x00000000          Section index of associated section
    519 sh_info                    0x00000000          Extra info about section
    520 sh_addralign               0x0000000000000010  Alignment (2B)
    521 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    522 &lt;/code&gt;&lt;/pre&gt;
    523 &lt;h3 id=&#34;section-header-table-entry-2-data&#34;&gt;Section header table: Entry 2 (.data)&lt;/h3&gt;
    524 &lt;pre&gt;&lt;code&gt;|00000190: 2100 0000 0100 0000 0300 0000 0000 0000|  !...............
    525 |000001a0: d800 6000 0000 0000 d800 0000 0000 0000|  ..`.............
    526 |000001b0: 0e00 0000 0000 0000 0000 0000 0000 0000|  ................
    527 |000001c0: 0400 0000 0000 0000 0000 0000 0000 0000|  ................
    528 
    529 sh_name                    0x00000021          Offset into .shstrtab
    530 sh_type                    0x00000001          SHT_PROGBITS
    531 sh_flags                   0x0000000000000003  SHF_WRITE | SHF_ALLOC
    532 sh_addr                    0x00000000006000d8  Virtual address of section in memory
    533 sh_offset                  0x00000000000000d8  Offset of section in file image
    534 sh_size                    0x000000000000000e  Size in bytes of section in file image
    535 sh_link                    0x00000000          Section index of associated section
    536 sh_info                    0x00000000          Extra info about section
    537 sh_addralign               0x0000000000000004  Alignment (4B)
    538 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    539 &lt;/code&gt;&lt;/pre&gt;
    540 &lt;h3 id=&#34;section-header-table-entry-3-shstrtab-1&#34;&gt;Section header table: Entry 3 (.shstrtab)&lt;/h3&gt;
    541 &lt;pre&gt;&lt;code&gt;|000001d0: 1100 0000 0300 0000 0000 0000 0000 0000|  ................
    542 |000001e0: 0000 0000 0000 0000 e600 0000 0000 0000|  ................
    543 |000001f0: 2700 0000 0000 0000 0000 0000 0000 0000|  &#39;...............
    544 |00000200: 0100 0000 0000 0000 0000 0000 0000 0000|  ................
    545 
    546 sh_name                    0x00000011          Offset into .shstrtab
    547 sh_type                    0x00000003          SHT_STRTAB
    548 sh_flags                   0x00000000          No flags
    549 sh_addr                    0x0000000000000000  Virtual address of section in memory
    550 sh_offset                  0x00000000000000e6  Offset of section in file image
    551 sh_size                    0x0000000000000027  Size in bytes of section in file image
    552 sh_link                    0x00000000          Section index of associated section
    553 sh_info                    0x00000000          Extra info about section
    554 sh_addralign               0x0000000000000001  Alignment (1B)
    555 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    556 &lt;/code&gt;&lt;/pre&gt;
    557 &lt;h3 id=&#34;section-header-table-entry-4-symtab-1&#34;&gt;Section header table: Entry 4 (.symtab)&lt;/h3&gt;
    558 &lt;pre&gt;&lt;code&gt;|00000210: 0100 0000 0200 0000 0000 0000 0000 0000|  ................
    559 |00000220: 0000 0000 0000 0000 9002 0000 0000 0000|  ................
    560 |00000230: f000 0000 0000 0000 0500 0000 0600 0000|  ................
    561 |00000240: 0800 0000 0000 0000 1800 0000 0000 0000|  ................
    562 
    563 sh_name                    0x00000001          Offset into .shstrtab
    564 sh_type                    0x00000002          SHT_SYMTAB
    565 sh_flags                   0x00000000          No flags
    566 sh_addr                    0x0000000000000000  Virtual address of section in memory
    567 sh_offset                  0x0000000000000290  Offset of section in file image
    568 sh_size                    0x00000000000000f0  Size in bytes of section in file image
    569 sh_link                    0x00000005          Section index of associated section
    570 sh_info                    0x00000006          Flags
    571 sh_addralign               0x0000000000000008  Alignment (8B)
    572 sh_entsize                 0x0000000000000018  Size in bytes of each entry (24B)
    573 &lt;/code&gt;&lt;/pre&gt;
    574 &lt;h3 id=&#34;section-header-table-entry-5-strtab-1&#34;&gt;Section header table: Entry 5 (.strtab)&lt;/h3&gt;
    575 &lt;pre&gt;&lt;code&gt;|00000250: 0900 0000 0300 0000 0000 0000 0000 0000|  ................
    576 |00000260: 0000 0000 0000 0000 8003 0000 0000 0000|  ................
    577 |00000270: 3700 0000 0000 0000 0000 0000 0000 0000|  7...............
    578 |00000280: 0100 0000 0000 0000 0000 0000 0000 0000|  ................
    579 
    580 sh_name                    0x00000009          Offset into .shstrtab
    581 sh_type                    0x00000003          SHT_STRTAB
    582 sh_flags                   0x0000000000000000  No flags
    583 sh_addr                    0x0000000000000000  Virtual address of section in memory
    584 sh_offset                  0x0000000000000380  Offset of section in file image
    585 sh_size                    0x0000000000000037  Size in bytes of section in file image
    586 sh_link                    0x00000000          Section index of associated section
    587 sh_info                    0x00000000          Extrac info about section
    588 sh_addralign               0x0000000000000001  Alignment (1B)
    589 sh_entsize                 0x0000000000000000  Size in bytes of each entry
    590 &lt;/code&gt;&lt;/pre&gt;
    591 &lt;h3 id=&#34;section-4-symtab-sht_symtab-1&#34;&gt;Section 4: .symtab (SHT_SYMTAB;)&lt;/h3&gt;
    592 &lt;h4 id=&#34;symbol-table-entry-0-1&#34;&gt;Symbol table entry 0&lt;/h4&gt;
    593 &lt;pre&gt;&lt;code&gt;|00000290: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    594 |000002a0: 0000 0000 0000 0000                    |  ........
    595 
    596 st_name                    0x00000000
    597 st_info                    0x00
    598 st_other                   0x00
    599 st_shndx                   0x0000 (SHN_UNDEF)
    600 st_value                   0x0000000000000000
    601 st_size                    0x0000000000000000
    602 &lt;/code&gt;&lt;/pre&gt;
    603 &lt;h4 id=&#34;symbol-table-entry-1&#34;&gt;Symbol table entry 1&lt;/h4&gt;
    604 &lt;pre&gt;&lt;code&gt;|000002a8:                     0000 0000 0300 0100|          ........
    605 |000002b0: b000 4000 0000 0000 0000 0000 0000 0000|  ..@.............
    606 
    607 st_name                    0x00000000
    608 st_info                    0x03 (STT_OBJECT | STT_FUNC)
    609 st_other                   0x00
    610 st_shndx                   0x0001 (Section 1: .text)
    611 st_value                   0x00000000004000b0
    612 st_size                    0x0000000000000000
    613 &lt;/code&gt;&lt;/pre&gt;
    614 &lt;h4 id=&#34;symbol-table-entry-2-1&#34;&gt;Symbol table entry 2&lt;/h4&gt;
    615 &lt;pre&gt;&lt;code&gt;|000002c0: 0000 0000 0300 0200 d800 6000 0000 0000|  ..........`.....
    616 |000002d0: 0000 0000 0000 0000                    |  ........
    617 
    618 st_name                    0x00000000
    619 st_info                    0x03 (STT_OBJECT | STT_FUNC)
    620 st_other                   0x00
    621 st_shndx                   0x0002 (Section 2: .data)
    622 st_value                   0x00000000006000d8
    623 st_size                    0x0000000000000000
    624 &lt;/code&gt;&lt;/pre&gt;
    625 &lt;h4 id=&#34;symbol-table-entry-3-helloasm&#34;&gt;Symbol table entry 3 (hello.asm)&lt;/h4&gt;
    626 &lt;pre&gt;&lt;code&gt;|000002d0:                     0100 0000 0400 f1ff|          ........
    627 |000002e0: 0000 0000 0000 0000 0000 0000 0000 0000|  ................
    628 
    629 st_name                    0x00000001
    630 st_info                    0x04 (STT_FILE)
    631 st_other                   0x00
    632 st_shndx                   0xfff1 (SHN_ABS)
    633 st_value                   0x0000000000000000
    634 st_size                    0x0000000000000000
    635 &lt;/code&gt;&lt;/pre&gt;
    636 &lt;h4 id=&#34;symbol-table-entry-4-hello-1&#34;&gt;Symbol table entry 4 (hello)&lt;/h4&gt;
    637 &lt;pre&gt;&lt;code&gt;|000002f0: 0b00 0000 0000 0200 d800 6000 0000 0000|  ..........`.....
    638 |00000300: 0000 0000 0000 0000                    |  ................
    639 
    640 st_name                    0x0000000b
    641 st_info                    0x00
    642 st_other                   0x00
    643 st_shndx                   0x0002 (Section 2: .data)
    644 st_value                   0x00000000006000d8
    645 st_size                    0x0000000000000000
    646 &lt;/code&gt;&lt;/pre&gt;
    647 &lt;h4 id=&#34;symbol-table-entry-5-hbytes-1&#34;&gt;Symbol table entry 5 (hbytes)&lt;/h4&gt;
    648 &lt;pre&gt;&lt;code&gt;|00000300:                     1100 0000 0000 f1ff|          ........
    649 |00000310: 0e00 0000 0000 0000 0000 0000 0000 0000|  ................
    650 
    651 st_name                    0x00000011
    652 st_info                    0x00
    653 st_other                   0x00
    654 st_shndx                   0xfff1 (SHN_ABS)
    655 st_value                   0x000000000000000e
    656 st_size                    0x0000000000000000
    657 &lt;/code&gt;&lt;/pre&gt;
    658 &lt;h4 id=&#34;symbol-table-entry-6-_start-1&#34;&gt;Symbol table entry 6 (_start)&lt;/h4&gt;
    659 &lt;pre&gt;&lt;code&gt;|00000320: 1800 0000 1000 0100 b000 4000 0000 0000|  ..........@.....
    660 |00000330: 0000 0000 0000 0000                    |  ........
    661 
    662 st_name                    0x00000018
    663 st_info                    0x10 (STB_GLOBAL)
    664 st_other                   0x00
    665 st_shndx                   0x0001 (Section 1: .text)
    666 st_value                   0x00000000004000b0
    667 st_size                    0x0000000000000000
    668 &lt;/code&gt;&lt;/pre&gt;
    669 &lt;h4 id=&#34;symbol-table-entry-7-__bss_start&#34;&gt;Symbol table entry 7 (__bss_start)&lt;/h4&gt;
    670 &lt;pre&gt;&lt;code&gt;|00000330:                     1f00 0000 1000 f1ff|          ........
    671 |00000340: e600 6000 0000 0000 0000 0000 0000 0000|  ..`.............
    672 
    673 st_name                    0x0000001f
    674 st_info                    0x10 (STB_GLOBAL)
    675 st_other                   0x00
    676 st_shndx                   0xfff1 (SHN_ABS)
    677 st_value                   0x00000000006000e6
    678 st_size                    0x0000000000000000
    679 &lt;/code&gt;&lt;/pre&gt;
    680 &lt;h4 id=&#34;symbol-table-entry-8-_edata&#34;&gt;Symbol table entry 8 (_edata)&lt;/h4&gt;
    681 &lt;pre&gt;&lt;code&gt;|00000350: 2b00 0000 1000 f1ff e600 6000 0000 0000|  +.........`.....
    682 |00000360: 0000 0000 0000 0000                    |  ........
    683 
    684 st_name                    0x0000002b
    685 st_info                    0x10 (STB_GLOBAL)
    686 st_other                   0x00
    687 st_shndx                   0xfff1 (SHN_ABS)
    688 st_value                   0x00000000006000e6
    689 st_size                    0x0000000000000000
    690 &lt;/code&gt;&lt;/pre&gt;
    691 &lt;h4 id=&#34;symbol-table-entry-9-_end&#34;&gt;Symbol table entry 9 (_end)&lt;/h4&gt;
    692 &lt;pre&gt;&lt;code&gt;|00000360:                     3200 0000 1000 f1ff|          2.......
    693 |00000370: e800 6000 0000 0000 0000 0000 0000 0000|  ..`.............
    694 
    695 st_name                    0x00000032
    696 st_info                    0x10 (STB_GLOBAL)
    697 st_other                   0x00
    698 st_shndx                   0xfff1 (SHN_ABS)
    699 st_value                   0x00000000006000e8
    700 st_size                    0x0000000000000000
    701 &lt;/code&gt;&lt;/pre&gt;
    702 &lt;h3 id=&#34;section-6-strtab-sht_strtab&#34;&gt;Section 6: .strtab (SHT_STRTAB;)&lt;/h3&gt;
    703 &lt;pre&gt;&lt;code&gt;|00000380: 0068 656c 6c6f 2e61 736d 0068 656c 6c6f|  .hello.asm.hello
    704 |00000390: 0068 6279 7465 7300 5f73 7461 7274 005f|  .hbytes._start._
    705 |000003a0: 5f62 7373 5f73 7461 7274 005f 6564 6174|  _bss_start._edat
    706 |000003b0: 6100 5f65 6e64 00                      |  a._end.
    707 
    708 0x00000000: &#39;&#39;
    709 0x00000001: &#39;hello.asm&#39;
    710 0x0000000b: &#39;hello&#39;
    711 0x00000011: &#39;hbytes&#39;
    712 0x00000018: &#39;_start&#39;
    713 0x0000001f: &#39;__bss_start&#39;
    714 0x0000002b: &#39;_edata&#39;
    715 0x00000032: &#39;_end&#39;
    716 &lt;/code&gt;&lt;/pre&gt;
    717 &lt;h2 id=&#34;effect-of-stripping&#34;&gt;Effect of stripping&lt;/h2&gt;
    718 &lt;p&gt;Running &lt;code&gt;strip&lt;/code&gt; on the binary has the effect of dropping the &lt;code&gt;.symtab&lt;/code&gt; and
    719 &lt;code&gt;.strtab&lt;/code&gt; sections along with their section headers and 16 bytes of data (the
    720 section names &lt;code&gt;.symtab&lt;/code&gt; and &lt;code&gt;.strtab&lt;/code&gt;) from the &lt;code&gt;.shstrtab&lt;/code&gt; section, reducing the
    721 total binary size to 512 bytes.&lt;/p&gt;
    722 &lt;h2 id=&#34;in-memory-process-image&#34;&gt;In-memory process image&lt;/h2&gt;
    723 &lt;p&gt;FreeBSD uses a memory superpage size of 2MB (page size of 4kB) on x86_64. Since
    724 attributes are set at the page level, read+execute program &lt;code&gt;.text&lt;/code&gt; and
    725 read+write &lt;code&gt;.data&lt;/code&gt; are loaded into two separate segments on separate pages, as
    726 laid-out by the linker.&lt;/p&gt;
    727 &lt;p&gt;On launch, the kernel maps the binary image into memory as specified in the
    728 program header table:&lt;/p&gt;
    729 &lt;ul&gt;
    730 &lt;li&gt;PHT Entry 0: The ELF header, program header table, and Section 1 (&lt;code&gt;.text&lt;/code&gt;)
    731 are mapped from offset 0x00 of the binary image (with length 0xd6 bytes)
    732 into Segment 1 (readable, executable) at address 0x400000.&lt;/li&gt;
    733 &lt;li&gt;PHT Entry 1: Section 2 (&lt;code&gt;.data&lt;/code&gt;) at offset 0xd8 of the binary image is
    734 mapped into Segment 2 (readable, writeable) at address 0x6000d8 from offset
    735 0xd8 with length 0x0e bytes.&lt;/li&gt;
    736 &lt;/ul&gt;
    737 &lt;p&gt;The program entrypoint is specified to be 0x4000b0, the start of the &lt;code&gt;.text&lt;/code&gt;
    738 section.&lt;/p&gt;
    739 &lt;p&gt;And that&amp;rsquo;s it! Any corrections or comments are always welcome. Shoot me an
    740 email at &lt;a href=&#34;mailto:chris@bracken.jp&#34;&gt;chris@bracken.jp&lt;/a&gt;.&lt;/p&gt;
    741 </description>
    742     </item>
    743     
    744     <item>
    745       <title>Installing Mozc on Ubuntu</title>
    746       <link>https://chris.bracken.jp/2011/04/installing-mozc-on-ubuntu/</link>
    747       <pubDate>Fri, 22 Apr 2011 00:00:00 +0000</pubDate>
    748       <author>chris@bracken.jp (Chris Bracken)</author>
    749       <guid>https://chris.bracken.jp/2011/04/installing-mozc-on-ubuntu/</guid>
    750       <description>&lt;p&gt;If you&amp;rsquo;re a Japanese speaker, one of the first things you do when you install a
    751 fresh Linux distribution is to install a decent &lt;a href=&#34;https://en.wikipedia.org/wiki/Japanese_IME&#34;&gt;Japanese IME&lt;/a&gt;.
    752 Ubuntu defaults to &lt;a href=&#34;https://sourceforge.jp/projects/anthy/news/&#34;&gt;Anthy&lt;/a&gt;, but I personally prefer &lt;a href=&#34;https://code.google.com/p/mozc/&#34;&gt;Mozc&lt;/a&gt;, and
    753 that&amp;rsquo;s what I&amp;rsquo;m going to show you how to install here.&lt;/p&gt;
    754 &lt;p&gt;&lt;em&gt;Update (2011-05-01):&lt;/em&gt; Found an older &lt;a href=&#34;https://www.youtube.com/watch?v=MfgjTCXZ2-s&#34;&gt;video tutorial&lt;/a&gt; on YouTube
    755 which provides an alternative (and potentially more comprehensive) solution for
    756 Japanese support on 10.10 using ibus instead of uim, which is the better choice
    757 for newer releases.&lt;/p&gt;
    758 &lt;p&gt;&lt;em&gt;Update (2011-10-25):&lt;/em&gt; The software installation part of this process got a
    759 whole lot easier in Ubuntu releases after Natty, and as noted above, I&amp;rsquo;d
    760 recommend sticking with ibus over uim.&lt;/p&gt;
    761 &lt;h3 id=&#34;japanese-input-basics&#34;&gt;Japanese Input Basics&lt;/h3&gt;
    762 &lt;p&gt;Before we get going, let&amp;rsquo;s understand a bit about how Japanese input works on
    763 computers. Japanese comprises three main character sets: the two phonetic
    764 character sets, hiragana and katakana at 50 characters each, plus many
    765 thousands of Kanji, each with multiple readings. Clearly a full keyboard is
    766 impractical, so a mapping is required.&lt;/p&gt;
    767 &lt;p&gt;Input happens in two steps. First, you input the text phonetically, then you
    768 convert it to a mix of kanji and kana.&lt;/p&gt;
    769 &lt;figure&gt;&lt;img src=&#34;https://chris.bracken.jp/post/2011-04-22-henkan.png&#34;
    770     alt=&#34;Japanese IME completion menu&#34;&gt;
    771 &lt;/figure&gt;
    772 
    773 &lt;p&gt;Over the years, two main mechanisms evolved to input kana. The first was common
    774 on old &lt;em&gt;wapuro&lt;/em&gt;, and assigns a kana to each key on the keyboard—e.g. where
    775 the &lt;em&gt;A&lt;/em&gt; key appears on a QWERTY keyboard, you&amp;rsquo;ll find a ち. This is how our
    776 grandparents hacked out articles for the local &lt;em&gt;shinbun&lt;/em&gt;, but I suspect only a
    777 few die-hard traditionalists still do this. The second and more common method
    778 is literal &lt;a href=&#34;https://en.wikipedia.org/wiki/Wapuro&#34;&gt;transliteration of roman characters into kana&lt;/a&gt;. You
    779 type &lt;em&gt;fujisan&lt;/em&gt; and out comes ふじさん.&lt;/p&gt;
    780 &lt;p&gt;Once the phonetic kana have been input, you execute a conversion step wherein
    781 the input is transformed into the appropriate mix of kanji and kana. Given the
    782 large number of homonyms in Japanese, this step often involves disambiguating
    783 your input by selecting the intended kanji. For example, the &lt;em&gt;mita&lt;/em&gt; in &lt;em&gt;eiga wo
    784 mita&lt;/em&gt; (I watched a movie) is properly rendered as 観た whereas the &lt;em&gt;mita&lt;/em&gt; in
    785 &lt;em&gt;kuruma wo mita&lt;/em&gt; (I saw a car) should be 見た, and in neither case is it &lt;em&gt;mita&lt;/em&gt;
    786 as in the place name &lt;em&gt;Mita-bashi&lt;/em&gt; (Mita bridge) which is written 三田.&lt;/p&gt;
    787 &lt;h3 id=&#34;some-implementation-details&#34;&gt;Some Implementation Details&lt;/h3&gt;
    788 &lt;p&gt;Let&amp;rsquo;s look at implementation. There are two main components used in inputting
    789 Japanese text:&lt;/p&gt;
    790 &lt;p&gt;The GUI system (e.g. ibus, uim) is responsible for:&lt;/p&gt;
    791 &lt;ol&gt;
    792 &lt;li&gt;Maintaining and switching the current input mode:
    793 ローマ字、ひらがな、カタカナ、半額カタカナ.&lt;/li&gt;
    794 &lt;li&gt;Transliteration of character input into kana: &lt;em&gt;ku&lt;/em&gt; into く,
    795 &lt;em&gt;nekko&lt;/em&gt; into ねっこ, &lt;em&gt;xtu&lt;/em&gt; into っ.&lt;/li&gt;
    796 &lt;li&gt;Managing the text under edit (the underlined stuff) and the
    797 drop-down list of transliterations.&lt;/li&gt;
    798 &lt;li&gt;Ancillary functions such as supplying a GUI for custom dictionary
    799 management, kanji lookup by radical, etc.&lt;/li&gt;
    800 &lt;/ol&gt;
    801 &lt;p&gt;The transliteration engine (e.g. Anthy, Mozc) is responsible for transforming a
    802 piece of input text, usually in kana form, into kanji: for example みる into
    803 one of: 見る、観る、診る、視る. This involves:&lt;/p&gt;
    804 &lt;ol&gt;
    805 &lt;li&gt;Breaking the input phrase into components.&lt;/li&gt;
    806 &lt;li&gt;Transforming each component into the appropriate best guess based on context
    807 and historical input.&lt;/li&gt;
    808 &lt;li&gt;Supplying alternative transformations in case the best guess was incorrect.&lt;/li&gt;
    809 &lt;/ol&gt;
    810 &lt;h3 id=&#34;why-mozc&#34;&gt;Why Mozc?&lt;/h3&gt;
    811 &lt;p&gt;TL;DR: because it&amp;rsquo;s better. Have a look at the conversion list up at the top of
    812 this post. The input is &lt;em&gt;kinou&lt;/em&gt;, for which there are two main conversion
    813 candidates: 機能 (feature) and 昨日 (yesterday). Notice however, that it also
    814 supplies several conversions for yesterday&amp;rsquo;s date in various formats, including
    815 「平成23年4月21日」 using &lt;a href=&#34;https://en.wikipedia.org/wiki/Japanese_era_name&#34;&gt;Japanese Era Name&lt;/a&gt; rather than the
    816 Western notation 2011. This is just one small improvement among dozens of
    817 clever tricks it performs. If you&amp;rsquo;re thinking this bears an uncanny resemblance
    818 to tricks that &lt;a href=&#34;https://www.google.com/intl/ja/ime/&#34;&gt;Google&amp;rsquo;s Japanese IME&lt;/a&gt; supports, you&amp;rsquo;re right: Mozc
    819 originated from the same codebase.&lt;/p&gt;
    820 &lt;h3 id=&#34;switching-to-mozc&#34;&gt;Switching to Mozc&lt;/h3&gt;
    821 &lt;p&gt;So let&amp;rsquo;s assume you&amp;rsquo;re now convinced to abandon Anthy and switch to Mozc.
    822 You&amp;rsquo;ll need to make some changes. Here are the steps:&lt;/p&gt;
    823 &lt;p&gt;If you haven&amp;rsquo;t yet done so, install some Japanese fonts from either Software
    824 Centre or Synaptic. I&amp;rsquo;d recommend grabbing the &lt;em&gt;ttf-takao&lt;/em&gt; package.&lt;/p&gt;
    825 &lt;p&gt;Next up, we&amp;rsquo;ll install and configure Mozc.&lt;/p&gt;
    826 &lt;ol&gt;
    827 &lt;li&gt;&lt;strong&gt;Install ibus-mozc:&lt;/strong&gt; &lt;code&gt;sudo apt-get install ibus-mozc&lt;/code&gt;&lt;/li&gt;
    828 &lt;li&gt;&lt;strong&gt;Restart the ibus daemon:&lt;/strong&gt; &lt;code&gt;/usr/bin/ibus-daemon --xim -r -d&lt;/code&gt;&lt;/li&gt;
    829 &lt;li&gt;&lt;strong&gt;Set your input method to mozc:&lt;/strong&gt;
    830 &lt;ol&gt;
    831 &lt;li&gt;Open &lt;em&gt;Keyboard Input Methods&lt;/em&gt; settings.&lt;/li&gt;
    832 &lt;li&gt;Select the &lt;em&gt;Input Method&lt;/em&gt; tab.&lt;/li&gt;
    833 &lt;li&gt;From the &lt;em&gt;Select an input method&lt;/em&gt; drop-down, select Japanese, then mozc from
    834 the sub-menu.&lt;/li&gt;
    835 &lt;li&gt;Select &lt;em&gt;Japanese - Anthy&lt;/em&gt; from the list, if it appears there, and click
    836 &lt;em&gt;Remove&lt;/em&gt;.&lt;/li&gt;
    837 &lt;/ol&gt;
    838 &lt;/li&gt;
    839 &lt;li&gt;&lt;strong&gt;Optionally, remove Anthy from your system:&lt;/strong&gt; &lt;code&gt;sudo apt-get autoremove anthy&lt;/code&gt;&lt;/li&gt;
    840 &lt;/ol&gt;
    841 &lt;p&gt;Log out, and back in. You should see an input method menu in the menu
    842 bar at the top of the screen.&lt;/p&gt;
    843 &lt;p&gt;That&amp;rsquo;s it, Mozcを楽しんでください!&lt;/p&gt;
    844 </description>
    845     </item>
    846     
    847     <item>
    848       <title>Google Reader</title>
    849       <link>https://chris.bracken.jp/2007/05/google-reader/</link>
    850       <pubDate>Wed, 30 May 2007 00:00:00 +0000</pubDate>
    851       <author>chris@bracken.jp (Chris Bracken)</author>
    852       <guid>https://chris.bracken.jp/2007/05/google-reader/</guid>
    853       <description>&lt;p&gt;For years, I&amp;rsquo;ve been a fan of &lt;a href=&#34;http://inessential.com/&#34;&gt;Brent Simmons&amp;rsquo;&lt;/a&gt; OS X-based feed
    854 reader, &lt;a href=&#34;http://www.newsgator.com/Individuals/NetNewsWire/&#34;&gt;NetNewsWire&lt;/a&gt;. It&amp;rsquo;s a fantastic application, and I&amp;rsquo;ve definitely
    855 got my money&amp;rsquo;s worth out of it. After partnering with &lt;a href=&#34;http://newsgator.com/&#34;&gt;NewsGator&lt;/a&gt;, I
    856 started using their online feed-reader on and off, with mixed
    857 results. I like that it keeps my feeds in sync between my computers,
    858 and that I can browse articles at lunch, but the interface is still not on par
    859 with NetNewsWire itself.&lt;/p&gt;
    860 &lt;p&gt;While NewsGator&amp;rsquo;s implementation was lacking, I really did like the idea of
    861 dropping the desktop app altogether and going with a fully online solution, so
    862 I started exploring other options. The obvious free alternative is &lt;a href=&#34;http://www.google.com/reader/&#34;&gt;Google
    863 Reader&lt;/a&gt;, and I have to say, I&amp;rsquo;m impressed. While the
    864 presentation isn&amp;rsquo;t as customizable as NetNewsWire, the functionality that I use
    865 is all there, and in fact, it has some extra search features that I miss on the
    866 desktop. It was only when I launched NetNewsWire today and saw 290 unread
    867 items, that it hit me I hadn&amp;rsquo;t used it in almost a month. So while I look
    868 forward to &lt;a href=&#34;http://www.flickr.com/photos/hicksdesign/210309912/&#34;&gt;NetNewsWire 3&lt;/a&gt;, I&amp;rsquo;m sticking to Google Reader for the time
    869 being.&lt;/p&gt;
    870 &lt;figure&gt;&lt;img src=&#34;https://chris.bracken.jp/post/2007-05-30-google-reader.png&#34;
    871     alt=&#34;Google reader graph of usage by hour of day&#34;&gt;
    872 &lt;/figure&gt;
    873 
    874 &lt;p&gt;I also discovered that my prime news reading hours are apparently 6:30am to
    875 7:30am and 9pm to 11pm, with a strange local maximum straggling out around
    876 12:30am. I&amp;rsquo;d be curious to compare this to &lt;em&gt;before&lt;/em&gt; I had a baby that woke me
    877 up around that time.&lt;/p&gt;
    878 &lt;p&gt;&lt;em&gt;Update (2007-06-06):&lt;/em&gt; NetNewsWire 3.0 is now out.&lt;/p&gt;
    879 </description>
    880     </item>
    881     
    882   </channel>
    883 </rss>