diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -107,6 +107,13 @@ for (const WasmRelocation &rel : relocations) { uint8_t *loc = buf + rel.Offset + off; uint32_t value = file->calcNewValue(rel); + + // 'value' can be zero when relocating against non-live symbols. We should + // not generate a range-list terminator in this case. + if (value == 0 && getName() == ".debug_ranges") { + value = rel.Addend; + } + LLVM_DEBUG(dbgs() << "apply reloc: type=" << relocTypeToString(rel.Type)); if (rel.Type != R_WASM_TYPE_INDEX_LEB) LLVM_DEBUG(dbgs() << " sym=" << file->getSymbols()[rel.Index]->getName());