authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-03 03:22:02+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-03 03:29:20+02:00
log91fa2c61aacd002228c37cb651fa0a350bd7ac59
tree75efed76fbc47b7383e2fb50137bab00f962707f
parentbc4da9a90743c11c7c0b3e485f46d365d57d87b7
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: control the s390x backchain feature through the frame pointer option

This is a little different from how C/C++ compilers do this, but I think it's justified because it's what users actually *mean* when the use frame pointer options. This is another one of those LLVM "CPU" features that have nothing to do with CPU at all and should really be a TargetMachine option or something. One day we'll figure out a better way of dealing with these...

2 files changed, 10 insertions(+), 3 deletions(-)

src/Compilation.zig+6-2
...@@ -7193,6 +7193,9 @@ pub fn addCCArgs(...@@ -7193,6 +7193,9 @@ pub fn addCCArgs(
7193 }7193 }
71947194
7195 try argv.append(if (mod.omit_frame_pointer) "-fomit-frame-pointer" else "-fno-omit-frame-pointer");7195 try argv.append(if (mod.omit_frame_pointer) "-fomit-frame-pointer" else "-fno-omit-frame-pointer");
7196 if (target.cpu.arch == .s390x) {
7197 try argv.append(if (mod.omit_frame_pointer) "-mbackchain" else "-mno-backchain");
7198 }
71967199
7197 const ssp_buf_size = mod.stack_protector;7200 const ssp_buf_size = mod.stack_protector;
7198 if (ssp_buf_size != 0) {7201 if (ssp_buf_size != 0) {
...@@ -7258,9 +7261,10 @@ pub fn addCCArgs(...@@ -7258,9 +7261,10 @@ pub fn addCCArgs(
7258 const is_enabled = target.cpu.features.isEnabled(index);7261 const is_enabled = target.cpu.features.isEnabled(index);
72597262
7260 if (feature.llvm_name) |llvm_name| {7263 if (feature.llvm_name) |llvm_name| {
7261 // We communicate float ABI to Clang through the dedicated options.7264 // We communicate these to Clang through the dedicated options.
7262 if (std.mem.startsWith(u8, llvm_name, "soft-float") or7265 if (std.mem.startsWith(u8, llvm_name, "soft-float") or
7263 std.mem.startsWith(u8, llvm_name, "hard-float"))7266 std.mem.startsWith(u8, llvm_name, "hard-float") or
7267 (target.cpu.arch == .s390x and std.mem.eql(u8, llvm_name, "backchain")))
7264 continue;7268 continue;
72657269
7266 // Ignore these until we figure out how to handle the concept of omitting features.7270 // Ignore these until we figure out how to handle the concept of omitting features.
src/Package/Module.zig+4-1
...@@ -343,7 +343,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -343,7 +343,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
343 // See https://github.com/ziglang/zig/issues/23539343 // See https://github.com/ziglang/zig/issues/23539
344 if (target_util.isDynamicAMDGCNFeature(target, feature)) continue;344 if (target_util.isDynamicAMDGCNFeature(target, feature)) continue;
345345
346 const is_enabled = target.cpu.features.isEnabled(feature.index);346 var is_enabled = target.cpu.features.isEnabled(feature.index);
347 if (target.cpu.arch == .s390x and @as(std.Target.s390x.Feature, @enumFromInt(feature.index)) == .backchain) {
348 is_enabled = !omit_frame_pointer;
349 }
347350
348 if (is_enabled) {351 if (is_enabled) {
349 try buf.ensureUnusedCapacity(2 + llvm_name.len);352 try buf.ensureUnusedCapacity(2 + llvm_name.len);