authorgravatar for jeremy.linton@arm.comJeremy Linton <jeremy.linton@arm.com> 2026-09-05 12:17:56+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-05 16:29:07+02:00
log1a9bbcce9a1e2df1639ceeb85d05692b5448b67d
tree9ff3582bbdd8ba6dff27c374eed618c48d48e433
parente771c6d66ab52fe7d98676d3592ee2c58242c6aa

llvm: enable bti and pac-ret for aarch64-openbsd

OpenBSD requires the former and strongly encourages the latter. ref https://codeberg.org/ziglang/zig/issues/35570 Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

1 files changed, 31 insertions(+), 1 deletions(-)

src/codegen/llvm.zig+31-1
...@@ -395,7 +395,7 @@ pub const Object = struct {...@@ -395,7 +395,7 @@ pub const Object = struct {
395 }395 }
396396
397 {397 {
398 var module_flags = try std.array_list.Managed(Builder.Metadata).initCapacity(o.gpa, 8);398 var module_flags = try std.array_list.Managed(Builder.Metadata).initCapacity(o.gpa, 11);
399 defer module_flags.deinit();399 defer module_flags.deinit();
400400
401 const behavior_error = try o.builder.metadataConstant(try o.builder.intConst(.i32, 1));401 const behavior_error = try o.builder.metadataConstant(try o.builder.intConst(.i32, 1));
...@@ -492,6 +492,20 @@ pub const Object = struct {...@@ -492,6 +492,20 @@ pub const Object = struct {
492 }));492 }));
493 }493 }
494494
495 // The frontend should eventually offer options to control these.
496 if (target.cpu.arch.isAarch64() and target.os.tag == .openbsd) {
497 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
498 behavior_min,
499 (try o.builder.metadataString("branch-target-enforcement")).toMetadata(),
500 try o.builder.metadataConstant(try o.builder.intConst(.i32, 2)),
501 }));
502 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
503 behavior_min,
504 (try o.builder.metadataString("sign-return-address")).toMetadata(),
505 try o.builder.metadataConstant(try o.builder.intConst(.i32, 2)),
506 }));
507 }
508
495 try o.builder.addNamedMetadata(try o.builder.string("llvm.module.flags"), module_flags.items);509 try o.builder.addNamedMetadata(try o.builder.string("llvm.module.flags"), module_flags.items);
496 }510 }
497511
...@@ -2228,6 +2242,22 @@ pub const Object = struct {...@@ -2228,6 +2242,22 @@ pub const Object = struct {
2228 // above, this should be revisited if `softfp` support is added.2242 // above, this should be revisited if `softfp` support is added.
2229 try attributes.addFnAttr(.noimplicitfloat, &o.builder);2243 try attributes.addFnAttr(.noimplicitfloat, &o.builder);
2230 }2244 }
2245
2246 // The frontend should eventually offer options to control these.
2247 if (target.cpu.arch.isAarch64() and target.os.tag == .openbsd) {
2248 try attributes.addFnAttr(.{ .string = .{
2249 .kind = try o.builder.string("branch-target-enforcement"),
2250 .value = try o.builder.string(""),
2251 } }, &o.builder);
2252 try attributes.addFnAttr(.{ .string = .{
2253 .kind = try o.builder.string("sign-return-address"),
2254 .value = try o.builder.string("non-leaf"),
2255 } }, &o.builder);
2256 try attributes.addFnAttr(.{ .string = .{
2257 .kind = try o.builder.string("sign-return-address-key"),
2258 .value = try o.builder.string("a_key"),
2259 } }, &o.builder);
2260 }
2231 }2261 }
22322262
2233 pub fn addCallingConventionFnAttributes(2263 pub fn addCallingConventionFnAttributes(