Summary:
Add `__builtin_wasm_tls_base` so that LeakSanitizer can find the thread-local
block and scan through it for memory leaks.
Reviewers: tlively, aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D64900
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366475
91177308-0d34-0410-b5e6-
96231b3b80d8
[],
[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_tls_base :
+ Intrinsic<[llvm_ptr_ty],
+ [],
+ [IntrReadMem]>;
+
} // TargetPrefix = "wasm"
}
break;
}
+ case ISD::INTRINSIC_W_CHAIN: {
+ unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
+ switch (IntNo) {
+ case Intrinsic::wasm_tls_base: {
+ MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
+ assert(PtrVT == MVT::i32 && "only wasm32 is supported for now");
+
+ MachineSDNode *TLSBase = CurDAG->getMachineNode(
+ WebAssembly::GLOBAL_GET_I32, DL, MVT::i32,
+ CurDAG->getTargetExternalSymbol("__tls_base", PtrVT),
+ Node->getOperand(0));
+ ReplaceNode(Node, TLSBase);
+ return;
+ }
+ }
+ break;
+ }
default:
break;
ret i32 %1
}
+; CHECK-LABEL: tls_base:
+; CHECK-NEXT: .functype tls_base () -> (i32)
+define i8* @tls_base() {
+; CHECK-NEXT: global.get __tls_base
+; CHECK-NEXT: return
+ %1 = call i8* @llvm.wasm.tls.base()
+ ret i8* %1
+}
+
; CHECK: .type tls,@object
; TLS-NEXT: .section .tbss.tls,"",@
; NO-TLS-NEXT: .section .bss.tls,"",@
@tls = internal thread_local global i32 0
declare i32 @llvm.wasm.tls.size.i32()
+declare i8* @llvm.wasm.tls.base()