<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 - bsymbolic test produces invalid output"
   href="https://bugs.llvm.org/show_bug.cgi?id=49397">49397</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>bsymbolic test produces invalid output
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>wasm
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>wingo@igalia.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, sbc@chromium.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider bsymbolic.s, from lld/test/wasm:

```
.globl foo
foo:
  .functype foo () -> ()
  end_function

.globl get_foo_address
get_foo_address:
  .functype get_foo_address () -> (i32)
  global.get foo@GOT
  end_function

.globl get_bar_address
get_bar_address:
  .functype get_bar_address () -> (i32)
  global.get bar@GOT
  end_function

.globl bar
.section  .data.bar,"",@
bar:
  .int 42
.size bar, 4
```

If you test this file with llvm-lit:

```
bin/llvm-lit -a ../lld/test/wasm/bsymbolic.s
```

Then you try to validate the output file, you get an error:

```
wasm-validate tools/lld/test/wasm/Output/bsymbolic.s.tmp1.so
tools/lld/test/wasm/Output/bsymbolic.s.tmp1.so:00000c3: error: table variable
out of range: 0 (max 0)
```

Indeed there is an elem section that refers to table 0, but there is no
indirect function table in this file.

The reason for this is that no input requires the indirect function table.  The
input file bsymbolic.s.tmp.o has a couple R_WASM_GLOBAL_INDEX_LEB relocs for
foo@GOT and bar@GOT but no function pointer bitcasts (R_WASM_TABLE_INDEX_LEB). 
So the linker populates the elem section with entries for these GOT pointers
but as there is no corresponding table, it's an error.

What's the intention of this mode?  If we go to add an elemSec entry when there
is no indirect function table, should we ensure that the table is present, or
should we not emit elemSec entries?</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>