Skip to content

[wasm-ld] Inconsistency: combineOutputSegments() merges InputChunks with differing COMDATs, but writeBody() asserts #134809

Open
@anutosh491

Description

@anutosh491

Context

This is a part of the effort on running clang-repl in the browser. Check xeus-cpp-lite

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 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

void Writer::combineOutputSegments() {
// With PIC code we currently only support a single active data segment since
// we only have a single __memory_base to use as our base address. This pass
// combines all data segments into a single .data segment.
// This restriction does not apply when the extended const extension is
// available: https://github.com/WebAssembly/extended-const

But then as we are using --emit-relocs, we end up calling LinkingSection::writeBody() after finalizeSections

And here we have the following

#ifndef NDEBUG
for (const InputChunk *isec : inputSegments)
assert(isec->getComdatName() == comdat);
#endif

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]lld:wasm

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions