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

Redesign the interface to the unikernel HermitCore #65167

Merged
merged 15 commits into from
Oct 26, 2019

Conversation

stlankes
Copy link
Contributor

@stlankes stlankes commented Oct 6, 2019

We are developing the unikernel HermitCore, where the kernel is written in Rust and is already part of the Rust Standard Library. The interface between the standard library and the kernel based on a small C library. With this pull request, we remove completely the dependency to C and use lld as linker. Currently, the kernel will be linked to the application as static library, which is published at https:/hermitcore/libhermit-rs.

We don’t longer support the C interface to the kernel. Consequently, we remove this part from the Rust Standard Library.

- the old interface between HermitCore and the Rust Standard Library
  based on a small C library (newlib)
- remove this interface and call directly the unikernel
- remove the dependency to the HermitCore linker
- use rust-lld as linker
@jonas-schievink jonas-schievink added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 6, 2019
@JohnCSimon
Copy link
Member

Ping from triage
@varkor @withoutboats Can you please review this PR?
thanks.

@varkor
Copy link
Member

varkor commented Oct 12, 2019

r? @alexcrichton

@alexcrichton
Copy link
Member

Thanks for the PR @stlankes! This is quite a large amount of code coming in, but it looks like it's all in the src/libstd/sys/hermit directory which is typically ok for the standard library since we don't do much scrutiny of non-supported-platforms code.

Can you speak a little about this target, why it's being included in libstd, why it has a new directory for support, and what its maintenance story will look like going forward?

@stlankes
Copy link
Contributor Author

stlankes commented Oct 15, 2019

@alexcrichton, you are right. Maybe I should explain our motivation. I am part of a research group for system software at a german university and use Rust in my operating system classes. We want to maintain and extend this part of libstd.

The unikernel HermitCore is one of our projects. Unikernels are specialized, single-address-space machine images. Such kernels are typically used in the area of cloud computing. They shrink the attack surface and resource footprint of cloud services. The best known unikernel is maybe MirageOS. We already developed a version of HermitCore, which is part of libstd. However, it is mixture of C and Rust. Our objective is to remove C completely from our toolchain. C is in our opinion not valid to develop secure applications.

The current version is only working within our hypervisor uhyve. A prototype is already working with @phil-opp bootimage, which converts a kernel into a valid boot image. Consequently, it runs on common hypervisors like qemu. A network is currently missing. We have also a prototype, which uses smoltcp as network stack. But it isn’t in a state to publish it.

So, we have something in our pipeline. The current patch is already huge. This is our motivation to publish the current version and smaller extensions later.

I hope that I have explained our motivation well.

@alexcrichton
Copy link
Member

Ok thanks for the info!

As I mentioned before we don't really have strict policies right now one way or another about how to organize libstd. It's generally left up to the reviewer and a few defacto ways that we manage a separate target in libstd. For example:

  • You'll be the owner of this directory. You'll be cc'd if something looks wonky or if assistance is needed.
  • No code review is guaranteed to happen for any code within this hermit-specific directory. Integration points with the rest of libstd will be reviewed, but hermit-specific code is not guaranteed to receive review (e.g. I wouldn't review anything platform-specific in this PR).
  • Changes to libstd will not be gated on the hermit target, so this will likely break over time as libstd is refactored, tweaked, updated, etc. You won't always get warning to this happening as well, it'll just break in nightlies.
  • We're in the works of developing a more fleshed out policy for target support, and that may change the calculus here, although it's unknown by how much. Just want to make sure you're aware!

If that all sounds good, I'll review the integration points here and can r+

@stlankes
Copy link
Contributor Author

stlankes commented Oct 18, 2019

It is fine for me! Thanks for the support!

src/libstd/rt.rs Outdated Show resolved Hide resolved
src/libunwind/build.rs Outdated Show resolved Hide resolved
__variant1,
#[doc(hidden)]
__variant2,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to move these implementations to libc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already in libc. I forgot only to remove my workaround. I will fix it.

@stlankes
Copy link
Contributor Author

@alexcrichton I follow your suggestions and revise my code.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-18T21:50:13.8096711Z ##[command]git remote add origin https:/rust-lang/rust
2019-10-18T21:50:13.8306663Z ##[command]git config gc.auto 0
2019-10-18T21:50:13.8365003Z ##[command]git config --get-all http.https:/rust-lang/rust.extraheader
2019-10-18T21:50:13.8440158Z ##[command]git config --get-all http.proxy
2019-10-18T21:50:13.8577981Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65167/merge:refs/remotes/pull/65167/merge
---
2019-10-18T21:53:49.6158540Z 
2019-10-18T21:53:49.6158831Z ######################################################################## 100.0%
2019-10-18T21:53:49.6528366Z extracting /checkout/obj/build/cache/2019-09-25/cargo-beta-x86_64-unknown-linux-gnu.tar.gz
2019-10-18T21:53:49.7342213Z     Updating crates.io index
2019-10-18T21:53:53.3652051Z error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
2019-10-18T21:53:53.3686137Z failed to run: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /checkout/src/bootstrap/Cargo.toml --locked
2019-10-18T21:53:53.3740899Z Makefile:67: recipe for target 'prepare' failed
2019-10-18T21:53:53.3741710Z make: *** [prepare] Error 1
2019-10-18T21:53:54.3764940Z Command failed. Attempt 2/5:
2019-10-18T21:53:54.5035964Z     Updating crates.io index
2019-10-18T21:53:54.5035964Z     Updating crates.io index
2019-10-18T21:53:54.8418412Z error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
2019-10-18T21:53:54.8442993Z failed to run: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /checkout/src/bootstrap/Cargo.toml --locked
2019-10-18T21:53:54.8488461Z make: *** [prepare] Error 1
2019-10-18T21:53:54.8494064Z Makefile:67: recipe for target 'prepare' failed
2019-10-18T21:53:56.8507380Z Command failed. Attempt 3/5:
2019-10-18T21:53:56.9782982Z     Updating crates.io index
2019-10-18T21:53:56.9782982Z     Updating crates.io index
2019-10-18T21:53:57.3160424Z error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
2019-10-18T21:53:57.3188398Z failed to run: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /checkout/src/bootstrap/Cargo.toml --locked
2019-10-18T21:53:57.3239636Z Makefile:67: recipe for target 'prepare' failed
2019-10-18T21:53:57.3243468Z make: *** [prepare] Error 1
2019-10-18T21:54:00.3265328Z Command failed. Attempt 4/5:
2019-10-18T21:54:00.4538330Z     Updating crates.io index
2019-10-18T21:54:00.4538330Z     Updating crates.io index
2019-10-18T21:54:00.7882051Z error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
2019-10-18T21:54:00.7937952Z failed to run: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /checkout/src/bootstrap/Cargo.toml --locked
2019-10-18T21:54:00.7952969Z Makefile:67: recipe for target 'prepare' failed
2019-10-18T21:54:00.7953413Z make: *** [prepare] Error 1
2019-10-18T21:54:04.7966503Z Command failed. Attempt 5/5:
2019-10-18T21:54:04.9265721Z     Updating crates.io index
2019-10-18T21:54:04.9265721Z     Updating crates.io index
2019-10-18T21:54:05.2724038Z error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
2019-10-18T21:54:05.2750883Z failed to run: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /checkout/src/bootstrap/Cargo.toml --locked
2019-10-18T21:54:05.2802482Z make: *** [prepare] Error 1
2019-10-18T21:54:05.2806721Z Makefile:67: recipe for target 'prepare' failed
2019-10-18T21:54:05.2813084Z The command has failed after 5 attempts.
2019-10-18T21:54:05.2816179Z == clock drift check ==
2019-10-18T21:54:05.2816179Z == clock drift check ==
2019-10-18T21:54:05.2828634Z   local time: Fri Oct 18 21:54:05 UTC 2019
2019-10-18T21:54:05.3067985Z   network time: Fri, 18 Oct 2019 21:54:05 GMT
2019-10-18T21:54:05.3068450Z == end clock drift check ==
2019-10-18T21:54:11.6540753Z 
2019-10-18T21:54:11.6653382Z ##[error]Bash exited with code '1'.
2019-10-18T21:54:11.6691284Z ##[section]Starting: Checkout
2019-10-18T21:54:11.6693369Z ==============================================================================
2019-10-18T21:54:11.6693498Z Task         : Get sources
2019-10-18T21:54:11.6693554Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@stlankes
Copy link
Contributor Author

@alexcrichton Okay, I guess I was naive. I moved the C interface to special crate to simplify the maintenance. The crate isn't part of the whitelist. Do you add it on the whitelist or should I revert the last commit?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-20T08:49:37.4591515Z ##[command]git remote add origin https:/rust-lang/rust
2019-10-20T08:49:37.4868050Z ##[command]git config gc.auto 0
2019-10-20T08:49:37.4946551Z ##[command]git config --get-all http.https:/rust-lang/rust.extraheader
2019-10-20T08:49:37.5013996Z ##[command]git config --get-all http.proxy
2019-10-20T08:49:37.5170256Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65167/merge:refs/remotes/pull/65167/merge
---
2019-10-20T08:56:18.2109570Z Done!
2019-10-20T08:56:18.2109707Z some tidy checks failed
2019-10-20T08:56:18.2109744Z 
2019-10-20T08:56:18.2109812Z 
2019-10-20T08:56:18.2112398Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-10-20T08:56:18.2113250Z 
2019-10-20T08:56:18.2113303Z 
2019-10-20T08:56:18.2119358Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-10-20T08:56:18.2119553Z Build completed unsuccessfully in 0:01:34
2019-10-20T08:56:18.2119553Z Build completed unsuccessfully in 0:01:34
2019-10-20T08:56:18.2172158Z == clock drift check ==
2019-10-20T08:56:18.2202837Z   local time: Sun Oct 20 08:56:18 UTC 2019
2019-10-20T08:56:18.3682553Z   network time: Sun, 20 Oct 2019 08:56:18 GMT
2019-10-20T08:56:18.3683413Z == end clock drift check ==
2019-10-20T08:56:20.4939706Z 
2019-10-20T08:56:20.5084194Z ##[error]Bash exited with code '1'.
2019-10-20T08:56:20.5124806Z ##[section]Starting: Checkout
2019-10-20T08:56:20.5126991Z ==============================================================================
2019-10-20T08:56:20.5127056Z Task         : Get sources
2019-10-20T08:56:20.5127131Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@alexcrichton
Copy link
Member

Yes adding that to the whitelist should be fine, most new targets in Rust nowadays end up taking this strategy of moving the very low-level support to a separate crate that libstd then uses.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-21T17:44:48.4470306Z ##[command]git remote add origin https:/rust-lang/rust
2019-10-21T17:44:48.4666896Z ##[command]git config gc.auto 0
2019-10-21T17:44:48.4749753Z ##[command]git config --get-all http.https:/rust-lang/rust.extraheader
2019-10-21T17:44:48.4799467Z ##[command]git config --get-all http.proxy
2019-10-21T17:44:48.4949782Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65167/merge:refs/remotes/pull/65167/merge
---
2019-10-21T17:51:24.3249900Z Done!
2019-10-21T17:51:24.3249942Z some tidy checks failed
2019-10-21T17:51:24.3260482Z 
2019-10-21T17:51:24.3260563Z 
2019-10-21T17:51:24.3262459Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-10-21T17:51:24.3262629Z 
2019-10-21T17:51:24.3262655Z 
2019-10-21T17:51:24.3262702Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-10-21T17:51:24.3262813Z Build completed unsuccessfully in 0:01:33
2019-10-21T17:51:24.3262813Z Build completed unsuccessfully in 0:01:33
2019-10-21T17:51:24.3317100Z == clock drift check ==
2019-10-21T17:51:24.3336326Z   local time: Mon Oct 21 17:51:24 UTC 2019
2019-10-21T17:51:24.4120624Z   network time: Mon, 21 Oct 2019 17:51:24 GMT
2019-10-21T17:51:24.4122939Z == end clock drift check ==
2019-10-21T17:51:25.7133376Z 
2019-10-21T17:51:25.7235074Z ##[error]Bash exited with code '1'.
2019-10-21T17:51:25.7269424Z ##[section]Starting: Checkout
2019-10-21T17:51:25.7271220Z ==============================================================================
2019-10-21T17:51:25.7271293Z Task         : Get sources
2019-10-21T17:51:25.7271340Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2019
@bors
Copy link
Contributor

bors commented Oct 26, 2019

⌛ Testing commit 805a330 with merge 5fa0e21b87fc68617b3bb0abd9288deef1b7e632...

@rust-highfive
Copy link
Collaborator

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-26T03:56:11.0497355Z do so (now or later) by using -b with the checkout command again. Example:
2019-10-26T03:56:11.0497581Z 
2019-10-26T03:56:11.0497746Z   git checkout -b <new-branch-name>
2019-10-26T03:56:11.0497861Z 
2019-10-26T03:56:11.0498031Z HEAD is now at 5fa0e21b8 Auto merge of #65167 - hermitcore:rusty-hermit, r=alexcrichton
2019-10-26T03:56:11.0913583Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-10-26T03:56:11.1024042Z ==============================================================================
2019-10-26T03:56:11.1024140Z Task         : Bash
2019-10-26T03:56:11.1024222Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-10-26T03:57:46.8170327Z Chocolatey installed 0/1 packages. 1 packages failed.
2019-10-26T03:57:46.8170789Z  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2019-10-26T03:57:46.8174514Z 
2019-10-26T03:57:46.8179381Z Failures
2019-10-26T03:57:46.8186383Z  - msys2 (exited 1) - msys2 not installed. An error occurred during installation:
2019-10-26T03:57:46.8186877Z  The remote server returned an error: (503) Server Unavailable. Service Unavailable
2019-10-26T03:57:47.7846462Z 
2019-10-26T03:57:47.7921255Z ##[error]Bash exited with code '1'.
2019-10-26T03:57:47.8124985Z ##[section]Starting: Upload CPU usage statistics
2019-10-26T03:57:47.8233174Z ==============================================================================
2019-10-26T03:57:47.8233448Z Task         : Bash
2019-10-26T03:57:47.8233514Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-10-26T03:57:48.1203151Z ========================== Starting Command Output ===========================
2019-10-26T03:57:48.1208447Z [command]"C:\Program Files\Git\bin\bash.exe" --noprofile --norc /d/a/_temp/cd96e239-20e8-4d66-9fcc-8ca1acb68e44.sh
2019-10-26T03:57:48.1632835Z /d/a/_temp/cd96e239-20e8-4d66-9fcc-8ca1acb68e44.sh: line 1: aws: command not found
2019-10-26T03:57:48.1664611Z 
2019-10-26T03:57:48.1683372Z ##[error]Bash exited with code '127'.
2019-10-26T03:57:48.1758216Z ##[section]Starting: Checkout
2019-10-26T03:57:48.1860806Z ==============================================================================
2019-10-26T03:57:48.1880077Z Task         : Get sources
2019-10-26T03:57:48.1880189Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Oct 26, 2019

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 26, 2019
@stlankes
Copy link
Contributor Author

stlankes commented Oct 26, 2019

@alexcrichton What does the test failed?

@JohnTitor
Copy link
Member

It's a network error.
@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2019
@bors
Copy link
Contributor

bors commented Oct 26, 2019

⌛ Testing commit 805a330 with merge fae75cd...

bors added a commit that referenced this pull request Oct 26, 2019
Redesign the interface to the unikernel HermitCore

We are developing the unikernel HermitCore, where the kernel is written in Rust and is already part of the Rust Standard Library. The interface between the standard library and the kernel based on a small C library. With this pull request, we remove completely the dependency to C and use lld as linker. Currently, the kernel will be linked to the application as static library, which is published at https:/hermitcore/libhermit-rs.

We don’t longer support the C interface to the kernel. Consequently, we remove this part from the Rust Standard Library.
@bors
Copy link
Contributor

bors commented Oct 26, 2019

☀️ Test successful - checks-azure
Approved by: alexcrichton
Pushing fae75cd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 26, 2019
@bors bors merged commit 805a330 into rust-lang:master Oct 26, 2019
tmandry added a commit to tmandry/rust that referenced this pull request Oct 29, 2019
add basic HermitCore support within libtest

This an extension to rust-lang#65167. The current pull request extend libtest to support HermitCore as target OS.
@stlankes
Copy link
Contributor Author

@alexcrichton Naive question. I need for my toolchain llvm-tools-preview (e,g. llvm-objcopy). I set in config.toml the variable llvm-tools to true. After building the toolchain, I do not find llvm-objcopy. Do you have a hint for me?

@alexcrichton
Copy link
Member

Ah sorry, I'm not quite sure, I haven't used that config option much myself.

@stlankes
Copy link
Contributor Author

@alexcrichton No problem!

@stlankes
Copy link
Contributor Author

@alexcrichton I have a version of RustyHermit, where I include my libos as crate instead of a static library. In this case, I am able to call directly Rust code from my kernel (e.g https:/hermitcore/rust/blob/with-hermit/src/libstd/sys/hermit/mutex.rs#L12).

However, I have to modify a few helper creates (log, rust-x86, rust-cupid,...). For instance, I modified log. Do you think that this a good idea? Can this be part of libstd?

@alexcrichton
Copy link
Member

I think we'll want to continue to be pretty conservative with dependencies of the standard library, so we don't have a great way of adding new dependencies to libstd for third-party targets at this time unfortunately.

@stlankes
Copy link
Contributor Author

No problem. I was expecting the answer....

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 13, 2023
Hermit: Remove floor symbol

This symbol should be provided by Hermit.

It was introduced in 2019 (rust-lang#65167). Since 2020, Hermit provides these math functions on its own (hermit-os/hermit-rs#37). I think moving this to Hermit was merely an oversight.

Related:
* hermit-os/kernel#654
* hermit-os/hermit-rs#406

CC: `@stlankes`
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request May 31, 2023
Hermit: Remove floor symbol

This symbol should be provided by Hermit.

It was introduced in 2019 (rust-lang/rust#65167). Since 2020, Hermit provides these math functions on its own (hermit-os/hermit-rs#37). I think moving this to Hermit was merely an oversight.

Related:
* hermit-os/kernel#654
* hermit-os/hermit-rs#406

CC: `@stlankes`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants