<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 - WASM backend fails on aliased symbols"
   href="https://bugs.llvm.org/show_bug.cgi?id=35383">35383</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>WASM backend fails on aliased symbols
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Backend: WebAssembly
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ncw@realvnc.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When creating aliased symbols, the WASM backend seems to get mixed up -
possibly by assuming that each function maps 1-to-1 to a symbol?

Full testcase:

####### test.c #######
static void dummy(void) {}
extern void __attribute__((weak, alias("dummy"))) __dothing(void);
void testFunc(void) { __dothing(); }

####### Commandline #######
<span class="quote">> $LLVM/clang --version</span >
clang version 6.0.0 (trunk 318652)
Target: wasm32-unknown-unknown-wasm
Thread model: posix
<span class="quote">> $LLVM/clang -Oz -c -o test.o test.c</span >

####### Output #######
<span class="quote">> $WABT/wasm2wat test.o</span >
(module
  (type (;0;) (func))
  (func $dummy (type 0))
  (func $testFunc (type 0)
    call $dummy)
  (table (;0;) 0 anyfunc)
  (memory (;0;) 0)
  (export "dummy" (func $dummy)) ; marked as "local" for lld
  (export "testFunc" (func $testFunc))
  (export "__dothing" (func $dummy))) ; marked as "weak" for lld


The problem is that the definition of "$testFunc" has been linked against the
symbol "$dummy" directly, rather than to the weak exported symbol "$__dothing".

This style of programming seems to be common in systems applications, such as
Musl libc (which I have distilled this test case from).  The local function
should link against the weak symbol, which will be resolved according to
whichever object exports that symbol most strongly. (In this case, the WASM
file that clang outputs has correctly-annotated the "export" entries using its
custom "linking" section.)</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>