title: How to extract all of the sections in an obj file
body: <p>I'm working on an X86_64 Ubuntu machine. I know that we can use the command to extract some sections from an obj file.</p>
  
  <p>Saying that I have an obj file, named <code>main.o</code>, now I can do things below:</p>
  
  <pre><code>me@my-machine:~/tmp$ readelf -S main.o
  
  There are 13 section headers, starting at offset 0x428:
  
  Section Headers:
    [Nr] Name              Type             Address           Offset
         Size              EntSize          Flags  Link  Info  Align
    [ 0]                   NULL             0000000000000000  00000000
         0000000000000000  0000000000000000           0     0     0
    [ 1] .text             PROGBITS         0000000000000000  00000040
         0000000000000055  0000000000000000  AX       0     0     1
    [ 2] .rela.text        RELA             0000000000000000  00000318
         0000000000000078  0000000000000018   I      11     1     8
    [ 3] .data             PROGBITS         0000000000000000  00000098
         0000000000000008  0000000000000000  WA       0     0     4
    [ 4] .bss              NOBITS           0000000000000000  000000a0
         0000000000000004  0000000000000000  WA       0     0     4
    [ 5] .rodata           PROGBITS         0000000000000000  000000a0
         0000000000000004  0000000000000000   A       0     0     1
    [ 6] .comment          PROGBITS         0000000000000000  000000a4
         0000000000000036  0000000000000001  MS       0     0     1
    [ 7] .note.GNU-stack   PROGBITS         0000000000000000  000000da
         0000000000000000  0000000000000000           0     0     1
    [ 8] .eh_frame         PROGBITS         0000000000000000  000000e0
         0000000000000058  0000000000000000   A       0     0     8
    [ 9] .rela.eh_frame    RELA             0000000000000000  00000390
         0000000000000030  0000000000000018   I      11     8     8
    [10] .shstrtab         STRTAB           0000000000000000  000003c0
         0000000000000061  0000000000000000           0     0     1
    [11] .symtab           SYMTAB           0000000000000000  00000138
         0000000000000180  0000000000000018          12    11     8
    [12] .strtab           STRTAB           0000000000000000  000002b8
         000000000000005d  0000000000000000           0     0     1
  Key to Flags:
    W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
    I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
    O (extra OS processing required) o (OS specific), p (processor specific)
  </code></pre>
  
  <p>Then I can extract some sections with the help of the command <code>objdump</code>, for example,</p>
  
  <pre><code>me@my-machine:~/tmp$ objdump -s -j .data main.o
  
  main.o:     file format elf64-x86-64
  
  Contents of section .data:
   0000 54000000 55000000                    T...U...
  </code></pre>
  
  <p>As we can see, I extract the section <code>.data</code> here.</p>
  
  <p>However, if I try to extract another section, it doesn't seem to work as expected.</p>
  
  <pre><code>me@my-machine:~/tmp$ objdump -s -j .strtab main.o
  
  main.o:     file format elf64-x86-64
  
  objdump: section '.strtab' mentioned in a -j option, but not found in any input file
  </code></pre>
  
  <p>Why can't the section <code>.strtab</code> be extracted? How can I extract this section?</p>