authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-17 18:10:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-18 17:46:29-04:00
logf9a34131128dffaeac7561afe34956ec2ee17fef
tree05a82dd2fe7865e0f5a93946be1765c767130893
parentedcb17daf8c24565ace4ca98a1c0a23a40bb5f0a

compiler: better default for valgrind

* Default to off when strip=true * Report an error when explicitly enabled but not supported for the target

1 files changed, 9 insertions(+), 6 deletions(-)

src/Compilation.zig+9-6
...@@ -1111,12 +1111,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1111,12 +1111,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1111 return error.StackProtectorUnavailableWithoutLibC;1111 return error.StackProtectorUnavailableWithoutLibC;
1112 }1112 }
11131113
1114 const valgrind: bool = b: {
1115 if (!target_util.hasValgrindSupport(options.target))
1116 break :b false;
1117 break :b options.want_valgrind orelse (options.optimize_mode == .Debug);
1118 };
1119
1120 const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols;1114 const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols;
11211115
1122 const must_single_thread = target_util.isSingleThreaded(options.target);1116 const must_single_thread = target_util.isSingleThreaded(options.target);
...@@ -1159,6 +1153,15 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1159,6 +1153,15 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1159 }1153 }
11601154
1161 const strip = options.strip orelse !target_util.hasDebugInfo(options.target);1155 const strip = options.strip orelse !target_util.hasDebugInfo(options.target);
1156 const valgrind: bool = b: {
1157 if (!target_util.hasValgrindSupport(options.target)) break :b false;
1158 if (options.want_valgrind) |explicit| break :b explicit;
1159 if (strip) break :b false;
1160 break :b options.optimize_mode == .Debug;
1161 };
1162 if (!valgrind and options.want_valgrind == true)
1163 return error.ValgrindUnsupportedOnTarget;
1164
1162 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);1165 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
1163 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);1166 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
1164 const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {1167 const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {