[llvm-bugs] [Bug 42277] New: llvm-objcopy does not rip off .bss section

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 14 00:22:43 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42277

            Bug ID: 42277
           Summary: llvm-objcopy does not rip off .bss section
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: llvm-objcopy/strip
          Assignee: unassignedbugs at nondot.org
          Reporter: masahiroy at kernel.org
                CC: alexander.v.shaposhnikov at gmail.com,
                    jake.h.ehrlich at gmail.com,
                    jh7370.2008 at my.bristol.ac.uk,
                    llvm-bugs at lists.llvm.org, rupprecht at google.com

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 <peter at pcc.me.uk>
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: https://reviews.llvm.org/D58426

    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361578
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190614/3c78233a/attachment.html>


More information about the llvm-bugs mailing list