aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-08-17 18:42:39 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-08-19 03:41:13 -0700
commitc0b7f20893ea5ca42e0d02b59db6f459c2f80ca1 (patch)
tree6fea31632a6d8803b0689081b7f16e74cf0660ff /src/codegen/llvm.zig
parent2ccaa5414b904edb2f4af293291f5401d106f277 (diff)
downloadzig-c0b7f20893ea5ca42e0d02b59db6f459c2f80ca1.tar.gz
zig-c0b7f20893ea5ca42e0d02b59db6f459c2f80ca1.zip
stage2: implement stack protectors
This is one of the final remaining TODOs for the LLVM backend.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig11
1 files changed, 8 insertions, 3 deletions
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) {