Skip to content
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

investigate a solution not use prelude #3

Open
jyao1 opened this issue Sep 29, 2021 · 3 comments
Open

investigate a solution not use prelude #3

jyao1 opened this issue Sep 29, 2021 · 3 comments
Assignees

Comments

@jyao1
Copy link
Owner

jyao1 commented Sep 29, 2021

use target.json to indicate a std lib ?

REF: https://zhuanlan.zhihu.com/p/406785047

@xiaoyuxlu
Copy link
Collaborator

xiaoyuxlu commented Nov 2, 2021

Problem

Our target x86_64-unknown-uefi doesn't support std library.So we must use #![no_std] to build for that target. Here is platform-support list.

the following questions is for those not support std target.

A. No panic_handler
B. No heap alloc
C. A lot of crates in crate.io do not support no_std (eg. rustls).

A and B easy to solve.
For A we can simply add #[panic_handler]
For B we can reuse alloc crate and provide a #[global_allocator] and a alloc_error_handler. This also need enable unstable features #![feature(alloc_error_handler)]

But for C eh... Modifying the crate's source code might be work #![no_std]. (use prelude or add support no_std). But there is a lot of maintenance work and upstream work.

So we need a way to add std support for C.

Here are discussions in the rust community https://github.com/rust-lang/wg-cargo-std-aware

One way (case 2 or 3) is use build-std feature. see: https://github.com/rust-lang/wg-cargo-std-aware#mvp-implementation

Another way (case 1) is add modify rust source code and add support for x86_64-unknown-uefi target

Results

  1. rustls (unmodified) build with host target, into host exe -- success
    basic feature that we need guarantee.

  2. rustls (unmodified) build with modified rust (add uefi support for library/std), build with cargo-build -- success
    build modified rust https://github.com/xiaoyuxlu/rust/tree/b/uefi_std
    and build payload(https://github.com/jyao1/rust-td/tree/master/rust-rustls-payload) with unmodified rustls

./x.py build -i
./x.py install -i
./x.py install -i --target x86_64-unknown-uefi library/std --stage 2 -v
## change dir to rust-rustls-payload
cargo build --target x86_64-unknown-uefi --release
  1. rustls ( + std::prelude): build with cargo-xbuild / cargo build -Zbuild-std -- success
    ref: https://github.com/jyao1/rust-uefi-std-stub
    ref: https://github.com/jyao1/rustls/tree/uefi_support

  2. rustls (unmodified): build with __CARGO_TESTS_ONLY_SRC_ROOT=<modified rust source code tree path> cargo build -Z build-std -- success
    ref: https://github.com/jyao1/rust-td/tree/master/rust-rustls-payload

cargo build -Zbuild-std=core,std,compiler_builtins,alloc,panic_abort -Zbuild-std-features=compiler-builtins-mem,panic_immediate_abort --target x86_64-unknown-uefi --release

If we use rust_std (in 1 and 3), we need resolve problem (similar to no_std in 2):
A. rust_std panic for UEFI
B. rust_std alloc for UEFI

Question for 1 and 3:
A: Payload can register a customer panic_handler by using std::panic::set_hook.
B: Payload can use #[global_allocator] to specify a allocator.

Summary

Case Rustls modification Rust modification Rebuild rust Target Build method Status(rustls-payload with std) (if use #![no_std] NO else YES)
0 NO NO NO host cargo build YES
1 NO YES YES x86_64-unknown-uefi cargo build YES
2 YES with std_stub NO NO x86_64-unknown-uefi cargo build -Zbuild-std NO
3 NO YES NO x86_64-unknown-uefi __CARGO_TESTS_ONLY_SRC_ROOT=[path-to-rust-src]/rust cargo build -Zbuild-std YES

@xiaoyuxlu
Copy link
Collaborator

SGX std support

sgx need add extern sgx_tstd as std in bottom of crate. and add use std::prelude::v1::*

need maintain another crate branch for sgx

https://github.com/mesalock-linux/

@xiaoyuxlu
Copy link
Collaborator

https://github.com/rust-lang/wg-cargo-std-aware/issues/3

@xiaoyuxlu xiaoyuxlu changed the title investigate a solution not use preclude investigate a solution not use prelude Nov 3, 2021
@jyao1 jyao1 closed this as completed Nov 18, 2021
@jyao1 jyao1 reopened this Nov 18, 2021
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

No branches or pull requests

2 participants