<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/134809>134809</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[wasm-ld] Inconsistency: combineOutputSegments() merges InputChunks with differing COMDATs, but writeBody() asserts
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
anutosh491
</td>
</tr>
</table>
<pre>
**Context**
This is a part of the effort on running clang-repl in the browser. Check [xeus-cpp-lite](https://compiler-research.org/xeus-cpp/lab/index.html)
In a cell block, I am trying to process multiple c++ definitions
```
const int var0 = 0; // generates .rodata._ZL4var0
const C cvar0{0}; // generates .rodata._ZL5cvar0, in a different COMDAT
```
As a final part we have a [linking step](https://github.com/llvm/llvm-project/blob/main/clang/lib/Interpreter/Wasm.cpp#L114) that produces the side module (incr_module_xx.wasm for each cell that is processed)
**Problem :**
Basically I end up with a situation where we're using wasm-ld to execute a linking process (with `--emit-relocs` being provided as a flag)
Now what I see is when `createOutputSegments` is run we end up with inputchunks with 3 different comdats (`_ZL4var0`, `_ZL5cvar0` or `empty`)
And when we run CombineOutputSegments, I see segments having inputchunks with different comdats being combined without any assert or error raised
I am guessing this is justified because
https://github.com/llvm/llvm-project/blob/e7365d3143d762c290c426b172f588756b6f1ef8/lld/wasm/Writer.cpp#L1075-L1080
But then as we are using --emit-relocs, we end up calling `LinkingSection::writeBody()` after `finalizeSections`
And here we have the following
https://github.com/llvm/llvm-project/blob/f0bdeb4b6aa1ee0653aed8323a5a7485fb930a05/lld/wasm/SyntheticSections.cpp#L738-L741
Hence I end up with this error
```
Aborted(Assertion failed: isec->getComdatName() == comdat, at: /Users/anutosh491/work/llvm-project/lld/wasm/SyntheticSections.cpp,747,writeBody)
```
while trying to run expressions with `const` in xeus-cpp-lite
**Disclaimer**
i) I see this happens only when we have `#ifndef NDEBUG` and I'm building llvm with `MinSizeRel`. Probably I wouldn't have encountered this with `Release`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVl1v6zYS_TX0y8CGRH36wQ-2U-8GSG8XvS0W2JcLihxZbChSIKk47q9fDGUnaW6x2DYQEIgejmbOOXNIEYI-W8Qdqw6seliJOQ7O74SdowtDuc1XnVPXHeN7xvdHZyO-xuWFZfT8MugAOoCASfgIroc4IGDfO3qz4GdrtT2DNMKe1x4nA9qmmM67S0C_geOA8hlYdXjFOazlNK2NjsiqB8bbIcYpsGLP-Inxk3TjpA36tceAwsth4_yZ8dN9I-MnIzrGT9oqfN0McTSMb5dCHy0IkGgMdMbJZ8aP8AhihOivVF90MHknMQQYZxP1ZBAk4wfGD6Cw11ZH7WygXHV2e7K9dDZE0DbCi_AZsOIBMlYcgP6WkuGMFr2IGGDjnRJRbL7956mk8Lf9R5DpvTlkrHm47__fGaplCz8SnAKU7nv0aCMcf_rxYf_LpzpZtt8TR722wixMXRAG8YIgCHmj7TOhECJOfwb8Wcdh7jbSjQSxebn_W0_e_YYyMn7qjCPkR6EtMUV0U5CmxUcb0U8eI3rGT_8WYdwktoqnPC8Z30IcRCT81SwxJHUErRBGp2aDwHirrfTfltdvr6-biwgj9M4DCjksrKYUOtxZRPXG_CLXf3nXGRwh9fSu34MIWgpjrvAIaBXME1x0HEBA0HEWRDpcBvQIF2S88QhzIKSogrVRpBt8RTlHQvIO411JjLcpGauz9RpHHdcejZOB1Rl0eIt80QoViESPEef3srP9F3eBC_X1CAGRursMaCmd9Cgi_jTHaY5f8TyijSmrDjRxRO7HZrSd5iiH2T6HZaH4IBjpRiViKpbV2Zs46ySuZeUmtjoD52kJxyleU8St1r1VS2kXTN8_urHT9nN9aeSokXBbIQUSCt_V9311C1xyyatSlJsjCHsFEQKS2XhA750HL3RABbexpxk_zxgSa_HmVr_NIepeo4IOpZgDUvTflTw2RV2pIi8L1dRc8m0mS153ecP7qm2bqu7qPse-TQkU4yfSDs2B1xH92yRkTbV-yrP2Nq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