Skip to content

Commit 42c7e9a

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 42c7e9a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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/Jobs/FrontendJobHelpers.swift

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

135+
if targetTriple.os == .openbsd && targetTriple.arch == .aarch64 {
136+
commandLine.appendFlag(.Xcc)
137+
commandLine.appendFlag("-Xclang=-msign-return-address=non-leaf")
138+
commandLine.appendFlag(.Xcc)
139+
commandLine.appendFlag("-Xclang=-msign-return-address-key=a_key")
140+
commandLine.appendFlag(.Xcc)
141+
commandLine.appendFlag("-Xclang=-mbranch-target-enforce")
142+
}
143+
135144
let isEmbeddedEnabled = parsedOptions.isEmbeddedEnabled
136145

137146
// Enable or disable ObjC interop appropriately for the platform

0 commit comments

Comments
 (0)