Index: wasm/InputChunks.cpp =================================================================== --- wasm/InputChunks.cpp +++ wasm/InputChunks.cpp @@ -55,7 +55,8 @@ if (Relocations.empty()) return; - DEBUG(dbgs() << "applying relocations: count=" << Relocations.size() << "\n"); + DEBUG(dbgs() << "applying relocations: " << getName() + << " count=" << Relocations.size() << "\n"); int32_t Off = OutputOffset - getInputSectionOffset(); for (const WasmRelocation &Rel : Relocations) { Index: wasm/InputFiles.cpp =================================================================== --- wasm/InputFiles.cpp +++ wasm/InputFiles.cpp @@ -77,7 +77,8 @@ if (Sym.isUndefined()) return 0; const WasmSegment& Segment = WasmObj->dataSegments()[Sym.Info.DataRef.Segment]; - return Segment.Data.Offset.Value.Int32 + Sym.Info.DataRef.Offset; + return Segment.Data.Offset.Value.Int32 + Sym.Info.DataRef.Offset + + Reloc.Addend; } case R_WEBASSEMBLY_TYPE_INDEX_LEB: return Reloc.Index; @@ -102,7 +103,7 @@ case R_WEBASSEMBLY_MEMORY_ADDR_LEB: if (auto *Sym = dyn_cast(getDataSymbol(Reloc.Index))) return Sym->getVirtualAddress() + Reloc.Addend; - return Reloc.Addend; + return 0; case R_WEBASSEMBLY_TYPE_INDEX_LEB: return TypeMap[Reloc.Index]; case R_WEBASSEMBLY_FUNCTION_INDEX_LEB: