Index: test/wasm/relocatable.ll =================================================================== --- test/wasm/relocatable.ll +++ test/wasm/relocatable.ll @@ -62,8 +62,8 @@ ; CHECK-NEXT: - ElemType: ANYFUNC ; CHECK-NEXT: Limits: ; CHECK-NEXT: Flags: [ HAS_MAX ] -; CHECK-NEXT: Initial: 0x00000002 -; CHECK-NEXT: Maximum: 0x00000002 +; CHECK-NEXT: Initial: 0x00000003 +; CHECK-NEXT: Maximum: 0x00000003 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: ; CHECK-NEXT: - Initial: 0x00000001 @@ -129,7 +129,7 @@ ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 0 +; CHECK-NEXT: Value: 1 ; CHECK-NEXT: Functions: [ 3, 1 ] ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: @@ -178,13 +178,13 @@ ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 8 -; CHECK-NEXT: Content: '00000000' +; CHECK-NEXT: Content: '01000000' ; CHECK-NEXT: - SectionOffset: 27 ; CHECK-NEXT: MemoryIndex: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 12 -; CHECK-NEXT: Content: '01000000' +; CHECK-NEXT: Content: '02000000' ; CHECK-NEXT: - SectionOffset: 36 ; CHECK-NEXT: MemoryIndex: 0 ; CHECK-NEXT: Offset: Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -35,6 +35,7 @@ using namespace lld::wasm; static constexpr int kStackAlignment = 16; +static constexpr int kInitialTableOffset = 1; namespace { @@ -108,7 +109,6 @@ uint64_t FileSize = 0; uint32_t DataSize = 0; uint32_t NumMemoryPages = 0; - uint32_t InitialTableOffset = 0; std::vector Types; DenseMap TypeIndices; @@ -245,7 +245,7 @@ // no address-taken function will fail at validation time since it is // a validation error to include a call_indirect instruction if there // is not table. - uint32_t TableSize = InitialTableOffset + IndirectFunctions.size(); + uint32_t TableSize = kInitialTableOffset + IndirectFunctions.size(); SyntheticSection *Section = createSyntheticSection(WASM_SEC_TABLE); raw_ostream &OS = Section->getStream(); @@ -330,11 +330,11 @@ writeUleb128(OS, 0, "table index"); WasmInitExpr InitExpr; InitExpr.Opcode = WASM_OPCODE_I32_CONST; - InitExpr.Value.Int32 = InitialTableOffset; + InitExpr.Value.Int32 = kInitialTableOffset; writeInitExpr(OS, InitExpr); writeUleb128(OS, IndirectFunctions.size(), "elem count"); - uint32_t TableIndex = InitialTableOffset; + uint32_t TableIndex = kInitialTableOffset; for (const Symbol *Sym : IndirectFunctions) { assert(Sym->getTableIndex() == TableIndex); writeUleb128(OS, Sym->getOutputIndex(), "function index"); @@ -635,7 +635,7 @@ if (Config->EmitRelocs) DefinedGlobals.reserve(Symtab->getSymbols().size()); - uint32_t TableIndex = InitialTableOffset; + uint32_t TableIndex = kInitialTableOffset; for (ObjFile *File : Symtab->ObjectFiles) { if (Config->EmitRelocs) { @@ -776,9 +776,6 @@ } void Writer::run() { - if (!Config->Relocatable) - InitialTableOffset = 1; - log("-- calculateTypes"); calculateTypes(); log("-- calculateImports");