Index: lld/wasm/InputChunks.cpp =================================================================== --- lld/wasm/InputChunks.cpp +++ lld/wasm/InputChunks.cpp @@ -43,6 +43,7 @@ case R_WASM_TABLE_INDEX_I64: case R_WASM_FUNCTION_OFFSET_I64: case R_WASM_TABLE_INDEX_REL_SLEB64: + case R_WASM_MEMORY_ADDR_TLS_SLEB64: return true; default: return false; @@ -140,6 +141,7 @@ case R_WASM_TABLE_INDEX_REL_SLEB64: case R_WASM_MEMORY_ADDR_SLEB64: case R_WASM_MEMORY_ADDR_REL_SLEB64: + case R_WASM_MEMORY_ADDR_TLS_SLEB64: encodeSLEB128(static_cast(value), loc, 10); break; case R_WASM_TABLE_INDEX_I32: Index: lld/wasm/InputFiles.cpp =================================================================== --- lld/wasm/InputFiles.cpp +++ lld/wasm/InputFiles.cpp @@ -124,6 +124,7 @@ case R_WASM_MEMORY_ADDR_I32: case R_WASM_MEMORY_ADDR_I64: case R_WASM_MEMORY_ADDR_TLS_SLEB: + case R_WASM_MEMORY_ADDR_TLS_SLEB64: case R_WASM_FUNCTION_OFFSET_I32: case R_WASM_FUNCTION_OFFSET_I64: case R_WASM_MEMORY_ADDR_LOCREL_I32: @@ -196,6 +197,7 @@ return value; } case R_WASM_MEMORY_ADDR_TLS_SLEB: + case R_WASM_MEMORY_ADDR_TLS_SLEB64: if (isa(sym) || sym->isUndefWeak()) return 0; // TLS relocations are relative to the start of the TLS output segment Index: lld/wasm/Relocations.cpp =================================================================== --- lld/wasm/Relocations.cpp +++ lld/wasm/Relocations.cpp @@ -115,6 +115,7 @@ addGOTEntry(sym); break; case R_WASM_MEMORY_ADDR_TLS_SLEB: + case R_WASM_MEMORY_ADDR_TLS_SLEB64: // In single-threaded builds TLS is lowered away and TLS data can be // merged with normal data and allowing TLS relocation in non-TLS // segments. Index: llvm/include/llvm/BinaryFormat/WasmRelocs.def =================================================================== --- llvm/include/llvm/BinaryFormat/WasmRelocs.def +++ llvm/include/llvm/BinaryFormat/WasmRelocs.def @@ -27,3 +27,4 @@ WASM_RELOC(R_WASM_FUNCTION_OFFSET_I64, 22) WASM_RELOC(R_WASM_MEMORY_ADDR_LOCREL_I32, 23) WASM_RELOC(R_WASM_TABLE_INDEX_REL_SLEB64, 24) +WASM_RELOC(R_WASM_MEMORY_ADDR_TLS_SLEB64, 25) Index: llvm/lib/BinaryFormat/Wasm.cpp =================================================================== --- llvm/lib/BinaryFormat/Wasm.cpp +++ llvm/lib/BinaryFormat/Wasm.cpp @@ -49,6 +49,7 @@ case R_WASM_MEMORY_ADDR_I32: case R_WASM_MEMORY_ADDR_I64: case R_WASM_MEMORY_ADDR_TLS_SLEB: + case R_WASM_MEMORY_ADDR_TLS_SLEB64: case R_WASM_FUNCTION_OFFSET_I32: case R_WASM_FUNCTION_OFFSET_I64: case R_WASM_SECTION_OFFSET_I32: Index: llvm/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/lib/MC/WasmObjectWriter.cpp +++ llvm/lib/MC/WasmObjectWriter.cpp @@ -633,6 +633,7 @@ case wasm::R_WASM_MEMORY_ADDR_I32: case wasm::R_WASM_MEMORY_ADDR_I64: case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB: + case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64: case wasm::R_WASM_MEMORY_ADDR_LOCREL_I32: { // Provisional value is address of the global plus the offset // For undefined symbols, use zero @@ -748,6 +749,7 @@ case wasm::R_WASM_TABLE_INDEX_REL_SLEB64: case wasm::R_WASM_MEMORY_ADDR_SLEB64: case wasm::R_WASM_MEMORY_ADDR_REL_SLEB64: + case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64: writePatchableSLEB<10>(Stream, Value, Offset); break; default: Index: llvm/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/lib/Object/WasmObjectFile.cpp +++ llvm/lib/Object/WasmObjectFile.cpp @@ -919,6 +919,7 @@ case wasm::R_WASM_MEMORY_ADDR_SLEB64: case wasm::R_WASM_MEMORY_ADDR_I64: case wasm::R_WASM_MEMORY_ADDR_REL_SLEB64: + case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64: if (!isValidDataSymbol(Reloc.Index)) return make_error("invalid relocation data index", object_error::parse_failed); Index: llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp =================================================================== --- llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -79,7 +79,8 @@ return is64Bit() ? wasm::R_WASM_TABLE_INDEX_REL_SLEB64 : wasm::R_WASM_TABLE_INDEX_REL_SLEB; case MCSymbolRefExpr::VK_WASM_TLSREL: - return wasm::R_WASM_MEMORY_ADDR_TLS_SLEB; + return is64Bit() ? wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64 + : wasm::R_WASM_MEMORY_ADDR_TLS_SLEB; case MCSymbolRefExpr::VK_WASM_MBREL: assert(SymA.isData()); return is64Bit() ? wasm::R_WASM_MEMORY_ADDR_REL_SLEB64 Index: llvm/test/MC/WebAssembly/tls64.s =================================================================== --- /dev/null +++ llvm/test/MC/WebAssembly/tls64.s @@ -0,0 +1,75 @@ +# RUN: llvm-mc -triple=wasm64-unknown-unknown < %s | FileCheck %s +# RUN: llvm-mc -triple=wasm64-unknown-unknown -filetype=obj -o %t.o < %s +# RUN: obj2yaml %t.o | FileCheck %s --check-prefix=CHECK-OBJ --match-full-lines + +.globaltype __tls_base, i64 + +tls_store: + .functype tls_store (i64) -> () + # CHECK: global.get __tls_base + # CHECK-NEXT: i64.const tls1@TLSREL + # CHECK-NEXT: i64.add + # CHECK-NEXT: i64.store 0 + local.get 0 + global.get __tls_base + i64.const tls1@TLSREL + i64.add + i64.store 0 + end_function + +.section .tls.foo,"T",@ +# CHECK: .tls.foo,"T",@ +tls1: + .int32 42 + .size tls1, 4 + +.section custom_tls,"T",@ +# CHECK: custom_tls,"T",@ +tls2: + .int32 43 + .size tls2, 4 + +# CHECK-OBJ: - Type: CODE +# CHECK-OBJ-NEXT: Relocations: +# CHECK-OBJ-NEXT: - Type: R_WASM_GLOBAL_INDEX_LEB +# CHECK-OBJ-NEXT: Index: 1 +# CHECK-OBJ-NEXT: Offset: 0x6 +# CHECK-OBJ-NEXT: - Type: R_WASM_MEMORY_ADDR_TLS_SLEB64 +# CHECK-OBJ-NEXT: Index: 2 +# CHECK-OBJ-NEXT: Offset: 0xC + +# CHECK-OBJ: - Type: CUSTOM +# CHECK-OBJ-NEXT: Name: linking +# CHECK-OBJ-NEXT: Version: 2 +# CHECK-OBJ-NEXT: SymbolTable: +# CHECK-OBJ-NEXT: - Index: 0 +# CHECK-OBJ-NEXT: Kind: FUNCTION +# CHECK-OBJ-NEXT: Name: tls_store +# CHECK-OBJ-NEXT: Flags: [ BINDING_LOCAL ] +# CHECK-OBJ-NEXT: Function: 0 +# CHECK-OBJ-NEXT: - Index: 1 +# CHECK-OBJ-NEXT: Kind: GLOBAL +# CHECK-OBJ-NEXT: Name: __tls_base +# CHECK-OBJ-NEXT: Flags: [ UNDEFINED ] +# CHECK-OBJ-NEXT: Global: 0 +# CHECK-OBJ-NEXT: - Index: 2 +# CHECK-OBJ-NEXT: Kind: DATA +# CHECK-OBJ-NEXT: Name: tls1 +# CHECK-OBJ-NEXT: Flags: [ BINDING_LOCAL ] +# CHECK-OBJ-NEXT: Segment: 0 +# CHECK-OBJ-NEXT: Size: 4 +# CHECK-OBJ-NEXT: - Index: 3 +# CHECK-OBJ-NEXT: Kind: DATA +# CHECK-OBJ-NEXT: Name: tls2 +# CHECK-OBJ-NEXT: Flags: [ BINDING_LOCAL ] +# CHECK-OBJ-NEXT: Segment: 1 +# CHECK-OBJ-NEXT: Size: 4 +# CHECK-OBJ-NEXT: SegmentInfo: +# CHECK-OBJ-NEXT: - Index: 0 +# CHECK-OBJ-NEXT: Name: .tls.foo +# CHECK-OBJ-NEXT: Alignment: 0 +# CHECK-OBJ-NEXT: Flags: [ TLS ] +# CHECK-OBJ-NEXT: - Index: 1 +# CHECK-OBJ-NEXT: Name: custom_tls +# CHECK-OBJ-NEXT: Alignment: 0 +# CHECK-OBJ-NEXT: Flags: [ TLS ]