authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-26 20:05:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-26 20:05:06-07:00
log0bc4726e00e794be9848b4b42dba43a0c7f4558e
tree2f82f16f880dbadd5daa13b763c6c4e0ead783e0
parenta127693f950e1abb1b2b31f5bb74d1ba2b0fa532

LLVM: add probe-stack function attribute


1 files changed, 15 insertions(+), 4 deletions(-)

src/codegen/llvm.zig+15-4
......@@ -673,6 +673,7 @@ pub const Object = struct {
673673 ) !void {
674674 const decl_index = func.owner_decl;
675675 const decl = module.declPtr(decl_index);
676 const target = module.getTarget();
676677
677678 var dg: DeclGen = .{
678679 .context = o.context,
......@@ -706,6 +707,17 @@ pub const Object = struct {
706707 DeclGen.removeFnAttr(llvm_func, "noinline");
707708 }
708709
710 // TODO: port these over from stage1
711 // addLLVMFnAttr(llvm_fn, "sspstrong");
712 // addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4");
713
714 // TODO: disable this if safety is off for the function scope
715 if (module.comp.bin_file.options.stack_check) {
716 dg.addFnAttrString(llvm_func, "probe-stack", "__zig_probe_stack");
717 } else if (target.os.tag == .uefi) {
718 dg.addFnAttrString(llvm_func, "no-stack-arg-probe", "");
719 }
720
709721 // Remove all the basic blocks of a function in order to start over, generating
710722 // LLVM IR from an empty function body.
711723 while (llvm_func.getFirstBasicBlock()) |bb| {
......@@ -719,7 +731,6 @@ pub const Object = struct {
719731
720732 // This gets the LLVM values from the function and stores them in `dg.args`.
721733 const fn_info = decl.ty.fnInfo();
722 const target = dg.module.getTarget();
723734 const sret = firstParamSRet(fn_info, target);
724735 const ret_ptr = if (sret) llvm_func.getParam(0) else null;
725736 const gpa = dg.gpa;
......@@ -730,7 +741,7 @@ pub const Object = struct {
730741 };
731742
732743 const err_return_tracing = fn_info.return_type.isError() and
733 dg.module.comp.bin_file.options.error_return_tracing;
744 module.comp.bin_file.options.error_return_tracing;
734745
735746 const err_ret_trace = if (err_return_tracing)
736747 llvm_func.getParam(@boolToInt(ret_ptr != null))
......@@ -920,7 +931,7 @@ pub const Object = struct {
920931
921932 const line_number = decl.src_line + 1;
922933 const is_internal_linkage = decl.val.tag() != .extern_fn and
923 !dg.module.decl_exports.contains(decl_index);
934 !module.decl_exports.contains(decl_index);
924935 const noret_bit: c_uint = if (fn_info.return_type.isNoReturn())
925936 llvm.DIFlags.NoReturn
926937 else
......@@ -936,7 +947,7 @@ pub const Object = struct {
936947 true, // is definition
937948 line_number + func.lbrace_line, // scope line
938949 llvm.DIFlags.StaticMember | noret_bit,
939 dg.module.comp.bin_file.options.optimize_mode != .Debug,
950 module.comp.bin_file.options.optimize_mode != .Debug,
940951 null, // decl_subprogram
941952 );
942953 try dg.object.di_map.put(gpa, decl, subprogram.toNode());