<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/65001>65001</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Common symbols cause undefined symbol error in wasm-ld
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          TerrorJack
      </td>
    </tr>
</table>

<pre>
    It seems common symbols still have issues in wasm as of trunk today. For the following c source:

```c
char foo[4];
```

`clang -fcommon` emits:

```
        .hidden foo                             # @foo
        .type   foo,@object
        .comm   foo,4,0
```

Which translates to the following linking section:

```
Custom:
 - name: "linking"
  - symbol table [count=1]
   - 0: D <foo> [ undefined binding=global vis=hidden ]
```

When attempting to link with the following c source:

```c
#include <stdio.h>

extern char foo[4];

int main() {
  foo[0] = '\0';
 puts(foo);
}
```

`wasm-ld` reports `wasm-ld: error: foo.o: undefined symbol: foo`. However, the same compilation/linking flags work for x86_64-linux.

AFAIK the current linking convention does not allow attaching a required buffer length to an undefined data symbol that's supposed to be a common symbol, so they can't be implemented correctly by `wasm-ld` anyway. But still, the link-time error is not quite informative of the status quo, and it would be nice to drop incorrect `.comm` directive support for the wasm assembler, or make the `clang` driver panic loudly for `-fcommon` on wasm targets.

Possibly related: #55270
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU2T8jYM_jXmooExzgdw4LDAy_RtLz10pseOYyvEXcfO2jIs_77jBNiPzu7hZZgkxNKD9Eh6JGM0J4e4ZdWOVYeZTNT5sP0LQ_Dhd6meZ43X1-1PgojYR1C-772DeO0bbyNEMtZCJ88IJsaEEYyDi4w9yAi-BQrJPQN5La8LOPoA1CG03lp_Me4ECqJPQSErnhg_MH6_1nz6qum36mSA1ntW7UpWHVix-2T3yVlZ6U4wb6dgWc0Be0Pxq3-5v9wsOqM1OsY3rffw3YeJAljJc0wPZ7o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