-
Notifications
You must be signed in to change notification settings - Fork 704
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
Add MIPS support #1277
Add MIPS support #1277
Conversation
This commit ports the changes from briansmith#1181 into the updated codebase The following command is working: > cross build --target mipsel-unknown-linux-musl But tests are still not working: > cross test --target mipsel-unknown-linux-musl
Cargo.toml
Outdated
@@ -58,6 +58,7 @@ include = [ | |||
"crypto/fipsmodule/bn/asm/x86-mont.pl", | |||
"crypto/fipsmodule/bn/asm/x86_64-mont.pl", | |||
"crypto/fipsmodule/bn/asm/x86_64-mont5.pl", | |||
"crypto/fipsmodule/bn/asm/mips-mont.pl", |
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 understand why you're trying to do it this way, but this is exactly what I'm hoping to avoid. Let's find a way to do it without bringing in any MIPS assembly code. It's just not realistic to maintain the MIPS assembly code given current constraints. I'd rather concentrate on improving the C (in the near future, Rust) code instead.
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'm mostly reverse-engineering the error messages which complained about bn_mul_mont
not existing, and I found this file defines it. I'm ok with removing it if I can figure out another way to overcome the error message.
build.rs
Outdated
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p256.c"), | ||
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p384.c"), | ||
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/p256.c"), | ||
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/crypto.c"), |
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.
crypto.c isn't relevant to MIPS so this should be reverted.
build.rs
Outdated
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/ecp_nistz.c"), | ||
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/gfp_p256.c"), | ||
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/gfp_p384.c"), | ||
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/p256.c"), |
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.
Just use &[]
for all of these. An empty list means "every platform."
build.rs
Outdated
@@ -200,6 +204,20 @@ const ASM_TARGETS: &[AsmTarget] = &[ | |||
asm_extension: "S", | |||
preassemble: false, | |||
}, | |||
AsmTarget { |
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.
Let's remove the AsmTarget
stuff for MIPS since my goal is to not have any assembly code for MIPS.
build.rs
Outdated
@@ -322,6 +341,7 @@ fn ring_build_rs_main() { | |||
|
|||
let target = Target { | |||
arch, | |||
endian, |
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.
No need to store endian in the target since no big-endian targets are supported.
build.rs
Outdated
@@ -391,6 +412,10 @@ fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path, ring_cor | |||
} | |||
} | |||
|
|||
if target.arch == "mips" && target.endian == "big" { |
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.
No need for target.arch == "mips"
because no big-endian targets are supported yet.
build.rs
Outdated
@@ -391,6 +412,10 @@ fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path, ring_cor | |||
} | |||
} | |||
|
|||
if target.arch == "mips" && target.endian == "big" { | |||
panic!("MIPS Big-Endian detected. Stoping compilation as BoringSSL code are not available for this platform"); |
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 would just write "Big-endian targets are not supported yet."
include/ring-core/mips_arch.h
Outdated
* this file except in compliance with the License. You can obtain a copy | ||
* in the file LICENSE in the source distribution or at | ||
* https://www.openssl.org/source/license.html | ||
*/ |
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 think (hope) we can avoid adding this file.
src/arithmetic/bigint.rs
Outdated
target_arch = "x86" | ||
target_arch = "x86", | ||
target_arch = "mips", | ||
target_arch = "mips64", |
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.
Everywhere in this file, I would expect no conditional logic for MIPS because there is a default implementation for platforms for which we don't have assembly. If those default implementations are not working for MIPS, let's investigate together why not.
As is, the linker fails to find the
Running
The output folder also contains fils for
I'm not sure how to further figure out the missing link |
@briansmith I'm not sure how we'll make certain C files compile wihout adding the assembly definition for
|
OK, I see the problem. I was mistaken about The best thing to do is make a separate PR that transliterates those C functions to the Rust equivalent. Note that those functions are very simple. The Rust implementations of those functions should use the Rust function Then, we can rebase this PR on top of that PR and everything should work. |
Note that in order for the MIPS assembly to work, we'd need to also bring in the MIPS perlasm translator, and then also patch it with whatever patches would be needed. That's pretty error-prone and I'd rather focus on replacing gfp_p256.c and gfp_p384.c with Rust code, which will solve the problem with less assembly and less C and less Perl. |
Does it mean to keep I can attempt it later on the weekend to replace the functions with Rust functions. |
Understandable. These functions don't implement any tricky crypto, however I understand that if you're not familiar with the code then it is going to be hard. I will try to find some time on the weekend to do it. |
Any news? I would like to cross compile a project for a mipsel device that is using rust-lts.
target: |
Also encountering this issue with mipsel-unknown-linux-uclibc |
@bltavares Can you rebase this on top of #1558. Considering the ideas in #1555 and the work in #1297, I think the main thing to take from this PR is the changes to the scripts in |
Thanks for your help. MIPS support was added in another PR and then temporarily removed in PR #1637; see #562 (comment) for what needs to be done to add it back. Closing this due to inactivity. |
Built on top of #1120
This commit ports the changes from #1181 into the updated codebase
The following command is working:
But tests are still not working: