From 70889544d13c3156b4c6486c86721d4a2b9dec84 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 4 Mar 2018 23:32:57 +0100 Subject: [PATCH] Add rlibc dependency in minimal rust kernel post --- .../posts/02-minimal-rust-kernel/index.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md b/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md index 261bd430..3cfa8c48 100644 --- a/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md +++ b/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md @@ -317,9 +317,25 @@ So we want to minimize the use of `unsafe` as much as possible. Rust gives us th [memory safety]: https://en.wikipedia.org/wiki/Memory_safety -We now have a simple “Hello World!” kernel. It should be noted though that a more advanced kernel might still produce linker faults because the compiler tries to use some function normally provided by `libc`. For this case, there are two crates you should keep in mind: [`rlibc`] and [`compiler_builtins`]. The former provides implementations for `memcpy`, `memclear`, etc. and the latter provides various other builtin functions. +We now have a simple “Hello World!” kernel. However, a more advanced kernel will still produce linker faults because the compiler tries to use some function normally provided by `libc`, most commonly `memcpy` and `memset`. To prevent these faults, we add an dependency on the [`rlibc`] crate, which provides implementations for the common `mem*` functions: [`rlibc`]: https://docs.rs/crate/rlibc + +```toml +# in Cargo.toml + +[dependencies] +rlibc = "1.0" +``` + +```rust +// in src/main.rs + +extern crate rlibc; +``` + +There is also the [`compiler_builtins`] crate that you should keep in mind. It provides Rust implementations for various other builtin functions, such as special floating point intrinsics. + [`compiler_builtins`]: https://docs.rs/crate/compiler-builtins-snapshot ### Creating a Bootimage