-
Notifications
You must be signed in to change notification settings - Fork 708
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
Improve conditional compilation around PerlAsm #1937
base: main
Are you sure you want to change the base?
Improve conditional compilation around PerlAsm #1937
Conversation
5412e5f
to
f57c2d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this. I am sorry about all the changes that were merged recently that created conflicts for this PR.
I think this is a good step towards what we need.
crypto/fipsmodule/ec/p256_shared.h
Outdated
@@ -24,7 +24,7 @@ | |||
#include "../bn/internal.h" | |||
|
|||
#if !defined(OPENSSL_NO_ASM) && \ | |||
(defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)) && \ | |||
defined(RING_HAVE_PERLASM) && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we set OPENSSL_NO_ASM
instead of RING_HAVE_PERLASM
to better align with upstream BoringSSL and OpenSSL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
build.rs
Outdated
@@ -433,7 +435,9 @@ fn build_c_code( | |||
|
|||
generate_prefix_symbols_asm_headers(out_dir, ring_core_prefix).unwrap(); | |||
|
|||
let (asm_srcs, obj_srcs) = if let Some(asm_target) = asm_target { | |||
let (asm_srcs, obj_srcs) = if let Some(asm_target) = find_asm_target(target) { | |||
println!("cargo:rustc-cfg=have_perlasm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we name it just perlasm
.
I am worried about the risk for users of non-Cargo build systems. I suggest when we do not set perlasm
, we set no_perlasm
. Then we should add a check like this to lib.rs to ensure that the such users have addressed this:
const PERLASM_CONFIGURED: () = assert!((cfg!(perlasm) && !cfg!(no_perlasm)) || (!cfg!(perlasm) && cfg!(no_perlasm)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've implemented this.
f57c2d7
to
e949d34
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1937 +/- ##
==========================================
+ Coverage 96.26% 96.30% +0.03%
==========================================
Files 140 140
Lines 20401 20855 +454
Branches 226 226
==========================================
+ Hits 19639 20084 +445
- Misses 728 737 +9
Partials 34 34 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deny
job failure is fixed in PR #2012, so just ignore that.
When building without perlasm, there will be a lot of dead code. We should probably do something like:
#![cfg_attr(all(no_perlasm, any(target_arch = "aarch64", ....)),allow(dead_code)]
in lib.rs to deal with this, at least temporarily.
We should also add a build-only job to CI for target aarch64-unknown-none
or similar that ensures the build succeeds.
src/lib.rs
Outdated
@@ -142,3 +142,6 @@ mod sealed { | |||
// ``` | |||
pub trait Sealed {} | |||
} | |||
|
|||
const PERLASM_CONFIGURED: () = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be named _PERLASM_CONFIGURED
to pass the clippy
job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion fails when running the package
job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be named
_PERLASM_CONFIGURED
to pass theclippy
job.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion fails when running the
package
job.
See below.
build.rs
Outdated
@@ -419,6 +423,8 @@ fn build_c_code( | |||
core_name_and_version: &str, | |||
) { | |||
let (asm_srcs, obj_srcs) = if let Some(asm_target) = asm_target { | |||
println!("cargo:rustc-cfg=perlasm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the cargo:rustc-cfg
directives need to be emitted from generate_sources_and_preassemble
instead so that the package
job (mk/package.sh) succeeds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that wouldn't cover the case where RING_PREGENERATE_ASM != 1 && !is_git
. I've moved these println!()
statements into main()
itself, which covers all cases.
60a2951
to
0e644b7
Compare
build.rs determines whether the target platform is supported by PerlAsm using both target_arch and target_os. Instances of conditional compilation in both src/ and crypto/ were using just target_arch to determine whether PerlAsm symbols are present, resulting in link-time build failures for certain targets, including, for example, aarch64-unknown-none. This commit fixes those instances of conditional compilation to align with the build script. I agree to license my contributions to each file under the terms given at the top of each file I changed.
0e644b7
to
31b9789
Compare
@briansmith I just now rebased again. Are there any more changes you'd like me to make to this PR? |
build.rs
determines whether the target platform is supported by PerlAsm using bothtarget_arch
andtarget_os
. Instances of conditional compilation in bothsrc/
andcrypto/
were using justtarget_arch
to determine whether PerlAsm symbols are present, resulting in link-time build failures for certain targets, including, for example,aarch64-unknown-none
.This commit fixes those instances of conditional compilation to align with the build script.
I've made the most conservative possible modifications to these
cfg
conditions, so some of them may contain redundancy. In particular, those that wereany(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64", target_arch = "x86")
are nowall(have_perlasm, any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64", target_arch = "x86"))
, but it may be the case that some of these ought to just behave_perlasm
.This PR addresses #1793. As discussed in that issue, the conditions in
build.rs
for PerlAsm support may be overly conservative, but expanding the set of targets which are deemed to be supported by PerlAsm will be trickier. This PR is just a bug fix that enables platforms such asaarch64-unknown-none
to use the fallbacks rather than failing to build at link-time.