From bbb3403b5dff854b01989882a539b29a9e33d732 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 16 Dec 2020 15:45:32 -0700 Subject: [PATCH] stage1: apply LLVM ssp attributes globally instead of per-function. Otherwise LLVM asserts with: "stack protected callee but caller requested no stack protector" --- src/stage1/codegen.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index ab80149a53..9928a37f9d 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -492,14 +492,12 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { if (fn->body_node != nullptr) { maybe_export_dll(g, llvm_fn, linkage); - bool want_fn_safety = g->build_mode != BuildModeFastRelease && + bool want_ssp_attrs = g->build_mode != BuildModeFastRelease && g->build_mode != BuildModeSmallRelease && - !fn->def_scope->safety_off; - if (want_fn_safety) { - if (g->link_libc) { - addLLVMFnAttr(llvm_fn, "sspstrong"); - addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4"); - } + g->link_libc; + if (want_ssp_attrs) { + addLLVMFnAttr(llvm_fn, "sspstrong"); + addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4"); } if (g->have_stack_probing && !fn->def_scope->safety_off) { addLLVMFnAttrStr(llvm_fn, "probe-stack", "__zig_probe_stack");