Skip to content

Commit ad97b40

Browse files
authored
Enable PACBTI on OpenBSD/arm64. (#1792)
BTI enforcement is mandatory, which means if PAC and BTI instructions are not emitted, then the compiled binary gets killed with SIGILL. The platform default compiler achieves enabling PAC and BTI by embedding the relevant enabled Clang compilation option flags into the local platform toolchain, which affects C/C++ code generation. For bootstrapping purposes, we need to make this change in the legacy C++ driver in swiftlang/swift#78394; this is the equivalent change for the new driver. It's not quite clear whether the flags need to be introduced in BackendJob.swift as well as FrontendJobHelpers.swift; just in case, add them in both locations.
1 parent b5e4bd5 commit ad97b40

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,15 @@ public final class GenericUnixToolchain: Toolchain {
161161
try commandLine.appendPath(VirtualPath(path: sysroot.pathString))
162162
}
163163
}
164+
165+
166+
if driver.targetTriple.os == .openbsd && driver.targetTriple.arch == .aarch64 {
167+
commandLine.appendFlag(.Xcc)
168+
commandLine.appendFlag("-Xclang=-msign-return-address=non-leaf")
169+
commandLine.appendFlag(.Xcc)
170+
commandLine.appendFlag("-Xclang=-msign-return-address-key=a_key")
171+
commandLine.appendFlag(.Xcc)
172+
commandLine.appendFlag("-Xclang=-mbranch-target-enforce")
173+
}
164174
}
165175
}

0 commit comments

Comments
 (0)