From be7cacfbbec8aed234a0316d11a9ae0e8cda0286 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 7 May 2019 00:49:49 +0200 Subject: Implement stack probes for x86/x86_64 Enabled on non-Windows systems only since it already requires stack probes. --- src/codegen.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 7dfdf71725..396dfb1f88 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -399,6 +399,15 @@ static void add_uwtable_attr(CodeGen *g, LLVMValueRef fn_val) { } } +static void add_probe_stack_attr(CodeGen *g, LLVMValueRef fn_val) { + // Windows already emits its own stack probes + if (g->zig_target->os != OsWindows && + (g->zig_target->arch == ZigLLVM_x86 || + g->zig_target->arch == ZigLLVM_x86_64)) { + addLLVMFnAttrStr(fn_val, "probe-stack", "__zig_probe_stack"); + } +} + static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) { switch (id) { case GlobalLinkageIdInternal: @@ -587,6 +596,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { addLLVMFnAttr(fn_table_entry->llvm_value, "sspstrong"); addLLVMFnAttrStr(fn_table_entry->llvm_value, "stack-protector-buffer-size", "4"); } + + add_probe_stack_attr(g, fn_table_entry->llvm_value); } } else { maybe_import_dll(g, fn_table_entry->llvm_value, linkage); -- cgit v1.2.3