<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - llvm-objcopy does not rip off .bss section"
   href="https://bugs.llvm.org/show_bug.cgi?id=42277">42277</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-objcopy does not rip off .bss section
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llvm-objcopy/strip
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>masahiroy@kernel.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>alexander.v.shaposhnikov@gmail.com, jake.h.ehrlich@gmail.com, jh7370.2008@my.bristol.ac.uk, llvm-bugs@lists.llvm.org, rupprecht@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>objcopy is often used to convert an ELF file into a raw binary.

In my workflow, I build my firmware, covert it into raw binary by the following
command, then burn it into my embedded board. 

$ llvm-objcopy -O binary -R .comment --strip-all my-input.elf my-output.bin

This worked fine until LLVM 8,
and in the same way as GNU toolchain objcopy.

If I use the llvm-objcopy from the latest trunk,
it does not work any more.

The first bad commit is:

commit 2b68379b89263178917e3bd37eaf9154078c2965 (HEAD)
Author: Peter Collingbourne <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>>
Date:   Fri May 24 00:21:46 2019 +0000

    llvm-objcopy: Change sectionWithinSegment() to use virtual addresses
instead of file offsets for SHT_NOBITS sections.

    Without this, sectionWithinSegment() will return the wrong answer for bss
    sections. This doesn't seem to matter now (for non-broken ELF files), but
    it will matter with a change that I'm working on.

    Differential Revision: <a href="https://reviews.llvm.org/D58426">https://reviews.llvm.org/D58426</a>

    git-svn-id: <a href="https://llvm.org/svn/llvm-project/llvm/trunk@361578">https://llvm.org/svn/llvm-project/llvm/trunk@361578</a>
91177308-0d34-0410-b5e6-96231b3b80d8


Since this commit, llvm-objcopy does not drop .bss section.

So, the produced raw binary is bigger than it should be
since it contains the .bss section.


I patched my build script by adding '-R .bss' explcitly.

$ llvm-objcopy -O binary -R .comment --strip-all -R .bss my-input.elf
my-output.bin

However, I do not think this is the right thing to do.

There is no need to load .bss section, nor should it be included in the image.

Moreover, now llvm-objcopy works differently from GNU toolchain objcopy.

Please take a look.

Thanks.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>