From c0b7f20893ea5ca42e0d02b59db6f459c2f80ca1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 17 Aug 2022 18:42:39 -0700 Subject: stage2: implement stack protectors This is one of the final remaining TODOs for the LLVM backend. --- src/codegen/llvm.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 8c84f61a81..0898c8fe87 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -711,9 +711,14 @@ pub const Object = struct { DeclGen.removeFnAttr(llvm_func, "noinline"); } - // TODO: port these over from stage1 - // addLLVMFnAttr(llvm_fn, "sspstrong"); - // addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4"); + // TODO: disable this if safety is off for the function scope + const ssp_buf_size = module.comp.bin_file.options.stack_protector; + if (ssp_buf_size != 0) { + var buf: [12]u8 = undefined; + const arg = std.fmt.bufPrintZ(&buf, "{d}", .{ssp_buf_size}) catch unreachable; + dg.addFnAttr(llvm_func, "sspstrong"); + dg.addFnAttrString(llvm_func, "stack-protector-buffer-size", arg); + } // TODO: disable this if safety is off for the function scope if (module.comp.bin_file.options.stack_check) { -- cgit v1.2.3