Index: lld/test/wasm/data-layout.ll =================================================================== --- lld/test/wasm/data-layout.ll +++ lld/test/wasm/data-layout.ll @@ -52,13 +52,15 @@ ; CHECK-NEXT: - SectionOffset: 7 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST +; CHK32-NEXT: Opcode: I32_CONST +; CHK64-NEXT: Opcode: I64_CONST ; CHECK-NEXT: Value: 1024 ; CHECK-NEXT: Content: 68656C6C6F0A00 ; CHECK-NEXT: - SectionOffset: 20 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST +; CHK32-NEXT: Opcode: I32_CONST +; CHK64-NEXT: Opcode: I64_CONST ; CHECK-NEXT: Value: 1040 Index: lld/test/wasm/data-segments.ll =================================================================== --- lld/test/wasm/data-segments.ll +++ lld/test/wasm/data-segments.ll @@ -1,5 +1,6 @@ ; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.o -mattr=+atomics ; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.bulk-mem.o -mattr=+bulk-memory +; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o %t.bulk-mem64.o -mattr=+bulk-memory ; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem.o -mattr=+atomics,+bulk-memory ; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem64.o -mattr=+atomics,+bulk-memory ; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem.pic.o -relocation-model=pic -mattr=+atomics,+bulk-memory,+mutable-globals @@ -10,13 +11,17 @@ ; bulk memory, unshared memory => active segments ; RUN: wasm-ld -no-gc-sections --no-entry %t.bulk-mem.o -o %t.bulk-mem.wasm -; RUN: obj2yaml %t.bulk-mem.wasm | FileCheck %s --check-prefix ACTIVE +; RUN: obj2yaml %t.bulk-mem.wasm | FileCheck %s --check-prefixes ACTIVE,ACTIVE32 + +; bulk memory, unshared memory, wasm64 => active segments +; RUN: wasm-ld -mwasm64 -no-gc-sections --no-entry %t.bulk-mem64.o -o %t.bulk-mem64.wasm +; RUN: obj2yaml %t.bulk-mem64.wasm | FileCheck %s --check-prefixes ACTIVE,ACTIVE64 ; atomics, bulk memory, shared memory => passive segments ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem.o -o %t.atomics.bulk-mem.wasm ; RUN: obj2yaml %t.atomics.bulk-mem.wasm | FileCheck %s --check-prefixes PASSIVE,PASSIVE32 -; Also test with wasm64 +; atomics, bulk memory, shared memory, wasm64 => passive segments ; RUN: wasm-ld -mwasm64 -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem64.o -o %t.atomics.bulk-mem64.wasm ; RUN: obj2yaml %t.atomics.bulk-mem64.wasm | FileCheck %s --check-prefixes PASSIVE,PASSIVE64 @@ -48,13 +53,15 @@ ; ACTIVE-NEXT: - SectionOffset: 7 ; ACTIVE-NEXT: InitFlags: 0 ; ACTIVE-NEXT: Offset: -; ACTIVE-NEXT: Opcode: I32_CONST +; ACTIVE32-NEXT: Opcode: I32_CONST +; ACTIVE64-NEXT: Opcode: I64_CONST ; ACTIVE-NEXT: Value: 1024 ; ACTIVE-NEXT: Content: 636F6E7374616E74000000002B ; ACTIVE-NEXT: - SectionOffset: 26 ; ACTIVE-NEXT: InitFlags: 0 ; ACTIVE-NEXT: Offset: -; ACTIVE-NEXT: Opcode: I32_CONST +; ACTIVE32-NEXT: Opcode: I32_CONST +; ACTIVE64-NEXT: Opcode: I64_CONST ; ACTIVE-NEXT: Value: 1040 ; ACTIVE-NEXT: Content: 68656C6C6F00676F6F646279650000002A000000 ; ACTIVE-NEXT: - Type: CUSTOM Index: lld/wasm/OutputSections.cpp =================================================================== --- lld/wasm/OutputSections.cpp +++ lld/wasm/OutputSections.cpp @@ -161,10 +161,12 @@ if (config->isPic) { initExpr.Opcode = WASM_OPCODE_GLOBAL_GET; initExpr.Value.Global = WasmSym::memoryBase->getGlobalIndex(); + } else if (config->is64.getValueOr(false)) { + initExpr.Opcode = WASM_OPCODE_I64_CONST; + initExpr.Value.Int64 = static_cast(segment->startVA); } else { - // FIXME(wvo): I64? initExpr.Opcode = WASM_OPCODE_I32_CONST; - initExpr.Value.Int32 = segment->startVA; + initExpr.Value.Int32 = static_cast(segment->startVA); } writeInitExpr(os, initExpr); } Index: llvm/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/lib/MC/WasmObjectWriter.cpp +++ llvm/lib/MC/WasmObjectWriter.cpp @@ -975,8 +975,8 @@ if (Segment.InitFlags & wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX) encodeULEB128(0, W->OS); // memory index if ((Segment.InitFlags & wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) { - W->OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST - : wasm::WASM_OPCODE_I32_CONST); + W->OS << char(is64Bit() ? wasm::WASM_OPCODE_I64_CONST + : wasm::WASM_OPCODE_I32_CONST); encodeSLEB128(Segment.Offset, W->OS); // offset W->OS << char(wasm::WASM_OPCODE_END); } Index: llvm/test/MC/WebAssembly/data-section.s =================================================================== --- llvm/test/MC/WebAssembly/data-section.s +++ llvm/test/MC/WebAssembly/data-section.s @@ -1,6 +1,12 @@ # RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s # Check that it converts to .o without errors: -# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | obj2yaml | FileCheck -check-prefix=BIN %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | obj2yaml | FileCheck -check-prefixes=BIN,BIN32 %s + +# Same again for wasm64 + +# RUN: llvm-mc -triple=wasm64-unknown-unknown -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s +# Check that it converts to .o without errors: +# RUN: llvm-mc -triple=wasm64-unknown-unknown -filetype=obj -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | obj2yaml | FileCheck -check-prefixes=BIN,BIN64 %s # Minimal test for data sections. @@ -44,6 +50,7 @@ # BIN-NEXT: Field: __linear_memory # BIN-NEXT: Kind: MEMORY # BIN-NEXT: Memory: +# BIN64-NEXT: Flags: [ IS_64 ] # BIN-NEXT: Initial: 0x1 # BIN-NEXT: - Type: FUNCTION # BIN-NEXT: FunctionTypes: [ 0 ] @@ -63,7 +70,8 @@ # BIN-NEXT: - SectionOffset: 6 # BIN-NEXT: InitFlags: 0 # BIN-NEXT: Offset: -# BIN-NEXT: Opcode: I32_CONST +# BIN32-NEXT: Opcode: I32_CONST +# BIN64-NEXT: Opcode: I64_CONST # BIN-NEXT: Value: 0 # BIN-NEXT: Content: '64' # BIN-NEXT: - Type: CUSTOM Index: llvm/test/MC/WebAssembly/wasm64.s =================================================================== --- llvm/test/MC/WebAssembly/wasm64.s +++ llvm/test/MC/WebAssembly/wasm64.s @@ -201,7 +201,7 @@ # BIN-NEXT: - SectionOffset: 6 # BIN-NEXT: InitFlags: 0 # BIN-NEXT: Offset: -# BIN-NEXT: Opcode: I32_CONST +# BIN-NEXT: Opcode: I64_CONST # BIN-NEXT: Value: 0 # BIN-NEXT: Content: 48656C6C6F2C20576F726C64212121000000000000000000 # BIN-NEXT: - Type: CUSTOM