Skip to content

Enable PACBTI on OpenBSD/arm64. #78394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Conversation

3405691582
Copy link
Member

BTI enforcement is mandatory here, which means if PAC and BTI instructions are not emitted, then the compiled binary gets killed with SIGILL. The 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 Swift however, to achieve the same effect, we would need to add the relevant LLVM module flags in the IRGen process. But, since Swift uses the Clang code generator when doing this, using the same option flag approach will work here as well, and is probably preferable to introducing operating system-dependent logic to the ClangImporter, for example.

Finally, the stdlib needs to be built with PACBTI as well, since the stdlib's global constructors get run when a compiled binary does. Since the Swift build uses the just-built Clang for the stdlib, just embed the necessary options into CMAKE_C_FLAGS and CMAKE_CXX_FLAGS via build-script-impl. This will be redundant with the host compiler, but at least it will be thorough.

@3405691582 3405691582 requested a review from artemcm as a code owner December 31, 2024 16:30
@finagolfin
Copy link
Member

@swift-ci please test

@finagolfin
Copy link
Member

Just submit the swift-driver equivalent and we'll get both pulls in.

3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Feb 3, 2025
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.
@3405691582
Copy link
Member Author

swift-driver equivalent pull request is in (see above).

3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Feb 3, 2025
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.
@finagolfin
Copy link
Member

@swift-ci please test

3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Feb 3, 2025
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.
@finagolfin finagolfin merged commit 610c351 into swiftlang:main Feb 4, 2025
5 checks passed
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 Swift however, to achieve the same effect, we would need to add the
relevant LLVM module flags in the IRGen process. But, since Swift uses
the Clang code generator when doing this, using the same option flag
approach will work here as well, and is probably preferable to
introducing operating system-dependent logic to the ClangImporter, for
example.

Finally, the stdlib needs to be built with PACBTI as well, since the
stdlib's global constructors get run when a compiled binary does. Since
the Swift build uses the just-built Clang for the stdlib, just embed the
necessary options into `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` via
`build-script-impl`. This will be redundant with the host compiler, but
at least it will be thorough.
3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Feb 5, 2025
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.
finagolfin pushed a commit to swiftlang/swift-driver that referenced this pull request Feb 6, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants