<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 - 0-length section causes assertion failure in llvm-objcopy"
   href="https://bugs.llvm.org/show_bug.cgi?id=45159">45159</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>0-length section causes assertion failure in llvm-objcopy
          </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>normal
          </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>jgravelle@google.com
          </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>Created <span class=""><a href="attachment.cgi?id=23217" name="attach_23217" title="Wasm module with empty custom section that reproduces the assert">attachment 23217</a> <a href="attachment.cgi?id=23217&action=edit" title="Wasm module with empty custom section that reproduces the assert">[details]</a></span>
Wasm module with empty custom section that reproduces the assert

This might be a WebAssembly-only problem, not sure.

Trying to run `llvm-objcopy --dump-section` on a section that exists but is of
length 0 causes an assertion failure that size != 0. It's legal (albeit weird)
in WebAssembly to have a section with no contents, so I'd expect llvm-objcopy
to handle that too.

Attached is nothing.wasm, which has a 0-length custom section named
"interface-types". To reproduce call `llvm-objcopy nothing.wasm
--dump-section=interface-types=nothing.out`

llvm-objcopy:
~/code/wasm/waterfall/src/work/llvm-project/llvm/lib/Support/Unix/Path.inc:776:
std::error_code llvm::sys::fs::mapped_file_region::init(int, uint64_t,
llvm::sys::fs::mapped_file_region::mapmode): Assertion `Size != 0' failed.
Stack dump:
0.  Program arguments: /s/wbin/llvm-objcopy nothing.wasm
--dump-section=interface-types=nothing.out 
 #0 0x00007f323cd56a14 PrintStackTraceSignalHandler(void*)
(~/code/wasm/waterfall/src/work/wasm-install/bin/../lib/libLLVM-11git.so+0x775a14)
 #1 0x00007f323cd5457e llvm::sys::RunSignalHandlers()
(~/code/wasm/waterfall/src/work/wasm-install/bin/../lib/libLLVM-11git.so+0x77357e)
 #2 0x00007f323cd56ccc SignalHandler(int)
(~/code/wasm/waterfall/src/work/wasm-install/bin/../lib/libLLVM-11git.so+0x775ccc)
 #3 0x00007f323c5b3520 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #4 0x00007f323c0e2081 raise
/build/glibc-G5rUEF/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f323c0cd535 abort /build/glibc-G5rUEF/glibc-2.29/stdlib/abort.c:81:7
 #6 0x00007f323c0cd40f _nl_load_domain
/build/glibc-G5rUEF/glibc-2.29/intl/loadmsgcat.c:1177:9
 #7 0x00007f323c0dab92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
 #8 0x00007f323cd4e3df
(~/code/wasm/waterfall/src/work/wasm-install/bin/../lib/libLLVM-11git.so+0x76d3df)
 #9 0x00007f323ccace85 llvm::FileOutputBuffer::create(llvm::StringRef, unsigned
long, unsigned int)
(~/code/wasm/waterfall/src/work/wasm-install/bin/../lib/libLLVM-11git.so+0x6cbe85)
#10 0x00000000004825f4
llvm::objcopy::wasm::executeObjcopyOnBinary(llvm::objcopy::CopyConfig const&,
llvm::object::WasmObjectFile&, llvm::objcopy::Buffer&)
(/s/wbin/llvm-objcopy+0x4825f4)
#11 0x000000000041fee9 executeObjcopyOnBinary(llvm::objcopy::CopyConfig&,
llvm::object::Binary&, llvm::objcopy::Buffer&) (/s/wbin/llvm-objcopy+0x41fee9)
#12 0x000000000041e453 main (/s/wbin/llvm-objcopy+0x41e453)
#13 0x00007f323c0cebbb __libc_start_main
/build/glibc-G5rUEF/glibc-2.29/csu/../csu/libc-start.c:342:3
#14 0x000000000040b0da _start (/s/wbin/llvm-objcopy+0x40b0da)</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>