stage2: implement stack protectors

This is one of the final remaining TODOs for the LLVM backend.
This commit is contained in:
Andrew Kelley
2022-08-17 18:42:39 -07:00
parent 2ccaa5414b
commit c0b7f20893
13 changed files with 184 additions and 53 deletions

View File

@@ -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) {