<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56270>56270</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
MC: Wasm globals should not be allowed in the text section.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:WebAssembly
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sbc100
</td>
</tr>
</table>
<pre>
See https://github.com/emscripten-core/emscripten/pull/17333.
Currently the following code will work find without `-g` but crash with it:
```
.globaltype my_global, externref
my_global:
.section .text,"",@
foo:
.functype foo () -> ()
end_function
$ clang++ -target wasm32-unknown-emscripten -c -O2 ./test.s -o test.o # works
$ clang++ -target wasm32-unknown-emscripten -c -O2 -g ./test.s -o test.o
clang version 15.0.0 (https://github.com/llvm/llvm-project.git f6f53e990d0ed3ec2162c6f4f7afab2e433eec63)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/google/home/sbc/dev/wasm/emscripten/../llvm-build/bin
(in-process)
"/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/clang-15" -cc1as -triple wasm32-unknown-emscripten -filetype obj -main-file-name test.s -target-cpu generic -fdebug-compilation-dir=/usr/local/google/home/sbc/dev/wasm/emscripten -dwarf-debug-producer "clang version 15.0.0 (https://github.com/llvm/llvm-project.git f6f53e990d0ed3ec2162c6f4f7afab2e433eec63)" -debug-info-kind=constructor -dwarf-version=4 -mrelocation-model static --mrelax-relocations -object-file-name=/usr/local/google/home/sbc/dev/wasm/emscripten/test.o -o test.o ./test.s
clang -cc1as: fatal error: error in backend: section doesn't have defining symbol
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
```
I think both invocations should fail but with a nice error such as ("wasm globals not allowed in text section"). The fix would be to put a `.section` directive before `my_global:`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVktv4zYQ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