Skip to content

Commit 6176f7e

Browse files
committed
Enable PACBTI on OpenBSD/arm64.
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 43bcf89 commit 6176f7e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Sources/SwiftDriver/Jobs/BackendJob.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ extension Driver {
4141
commandLine.appendFlag("-aarch64-use-tbi")
4242
}
4343

44+
if targetTriple.os == .openbsd && targetTriple.arch == .aarch64 {
45+
commandLine.appendFlag(.Xcc)
46+
commandLine.appendFlag("-Xclang=-msign-return-address=non-leaf")
47+
commandLine.appendFlag(.Xcc)
48+
commandLine.appendFlag("-Xclang=-msign-return-address-key=a_key")
49+
commandLine.appendFlag(.Xcc)
50+
commandLine.appendFlag("-Xclang=-mbranch-target-enforce")
51+
}
52+
4453
// Handle the CPU and its preferences.
4554
try commandLine.appendLast(.targetCpu, from: &parsedOptions)
4655

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)