Skip to content

Commit

Permalink
fix: fix undefined reference to `memset'
Browse files Browse the repository at this point in the history
  • Loading branch information
imlk0 authored and oxr463 committed Aug 20, 2021
1 parent fd39e38 commit 7e76aa9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@ members = [

[profile.release]
strip = true

[profile.dev.package.loader-shim]
opt-level = 1

[profile.release.package.loader-shim]
opt-level = "s"
17 changes: 16 additions & 1 deletion loader-shim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
// system standard libraries.
// See https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
//
// Since _start is defined in the system startup files, with this option
// The `-nostdlib` flag is much like a combination of `-nostartfiles` and
// `-nodefaultlibs`.
//
// Since `_start` is defined in the system startup files, with this option
// we can use our own `_start` function to override the program entry point.
#[link_args = "-nostdlib"]
#[link_args = "-ffreestanding"]
Expand All @@ -28,6 +31,18 @@
#[cfg_attr(target_arch = "aarch64", link_args = "-Wl,-Ttext=0x2000000000")]
extern "C" {}

// The compiler may emit a call to the `memset()` function even if there is
// no such call in our code. However, since we use `-nostdlib` or
// `-nodefaultlibs`, this means we will not link to libc, which provides the
// implementation of `memset()`.
//
// In this case, we will get an `undefined reference to \`memset'` error.
// Fortunately, the crate `rlibc` provides an unoptimized implementation of
// `memset()`.
//
// See `-nodefaultlibs` at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
extern crate rlibc;

mod script;

use core::{fmt::Write, panic::PanicInfo};
Expand Down

0 comments on commit 7e76aa9

Please sign in to comment.