<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143934>143934</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
WebAssembly tables + global variables + debug info = invalid binaries
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
feedab1e
</td>
</tr>
</table>
<pre>
creating a WebAssembly table and another global variable, then compiling with debug info, yields a binary that cannot be read or linked by any llvm tool ([link](https://gcc.godbolt.org/z/hP5dPq5qx)):
```cpp
// 1.cpp
int a;
inline static __externref_t table[0];
int main() {
__externref_t get();
__builtin_wasm_table_set(table, 0, get());
}
```
if compiled with
```
clang++ -g --target=wasm32 1.cpp -c -o 1.o
```
and used like following:
```
llvm-dwarfdump 1.o
```
will yield
```
error: 1.o: invalid data relocation: _ZL5table
```
The same issue occurs when trying to link:
```
wasm-ld --no-entry 1.o -o 1.wasm
```
yields
```
wasm-ld: error: 1.o: invalid data relocation: _ZL5table
```
Notably, the same issue does not occur when we remove the declaration of `a`:
```
// 1.cpp
inline static __externref_t table[0];
int main() {
__externref_t get();
__builtin_wasm_table_set(table, 0, get());
}
```
links successfully.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VM-vozYQ_mvMZUQEBpJw4JD0Kaeq2kOlSr1EY3sAd42dtU2y9K-vDNm-bd4eV5VQAp6Zz_Pjmw9D0IMl6lhzZs1bhnMcne96IoWipEw4tXTSE0ZtB0D4g8QpBJqEWSCiMARoFaB1cSQPg3ECDdzR62Rj_BeII1mQbrppkxAeOo6gSMwDaNu75LFoMioAgtAW_QJxxAgSrXURBIEnVOA8GG0_kwKxANoFjLlPEJ0zwPiRNedkZc0b48cxxltg1YnxC-OXQcrd4JRwJu6cHxi__M34ZfzUqE9fmi9fGW_TU51YcWL7Ynvk7ZY-13god9unthGQVef11WhLECJGLeF6pa-RvPXUX-PWE9aci5TM6v2MnVDblCpvgR3SOQC8xA4UN48tcHMQszZR2-sDw3Rd0a9h9YvfOlykn_fYb-Hs8PZ9USmN_jkIUuscXszSoB0YPzN-hnyAPI_oE2z1lu6u-NYKyCXkDsqdewlPPJgDKTD6M0HvjHEPbYeX3rLilEaXqwf6Xs3T7QdID23MxooXA3nvPKtOa0x1Am3vaLQChRHBk3ESo3Y2ma5__tpsHfovxO8jQcCJQIcwEzgpZx_gkUga_ZIYGt1KtY95py7kRkGeW5eTjX5JeWzNSLYX943WP8ZIGf6EYlhx-s0lw_LctO9LU44CpB1aa9xKfKR1mtydVmdF0qBfbwHXA9sXmHA_FP5hE34K_f9f7qeRBgizlBRCPxuz7DLVVaqtWsyoKw91e6iPVX3Mxm5P-2PNBbZYNLWS5UEK3pf7hh8P_b4lmemOF7wp9iUvDyXnx115rEWv-nZ_aPpa9MTqgibUZpe4nnQnW2fSlXXVVnVmUJAJq-RybumxTYxxnhTYd-uCiHkIrC6MDjG8w0QdDXUfRDhAWtoX9d0O37UWWPX2L8tWrdUUstmb7kUydRxnsZNuYvySbn7-5Tfv_iIZGb-s-QbGL8-C7h3_JwAA__8Oqe25">