From 7a110f7d09a99cfe3886be262fa24c59b32dbfc6 Mon Sep 17 00:00:00 2001 From: silt Date: Sun, 4 Dec 2022 23:43:05 -0500 Subject: [PATCH] bloat-free true/false and necessary build stuff --- Cargo.toml | 5 ++++- build.rs | 4 ++++ src/bin/false.rs | 22 ++++++++++++++++++++-- src/bin/true.rs | 22 ++++++++++++++++++++-- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index df909f7..9f7b25c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,10 @@ name = "coreutils" version = "0.0.1" edition = "2021" license = "AGPL-3.0-or-later" -authors = [ "Emma Tebibyte " ] +authors = [ + "Emma Tebibyte ", + "silt " +] [dependencies] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..72746a5 --- /dev/null +++ b/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-arg-bin=true=-nostartfiles"); + println!("cargo:rustc-link-arg-bin=false=-nostartfiles"); +} \ No newline at end of file diff --git a/src/bin/false.rs b/src/bin/false.rs index 1470fcc..24f88ec 100644 --- a/src/bin/false.rs +++ b/src/bin/false.rs @@ -1,4 +1,22 @@ -// Copyright (c) 2022 Emma Tebibyte +// Copyright (c) 2022 silt // SPDX-License-Identifier: AGPL-3.0-or-later -fn main() { std::process::exit(1); } +#![feature(lang_items, start)] +#![no_main] +#![no_std] + +use core::panic::PanicInfo; +use core::arch::asm; + +#[lang = "eh_personality"] extern fn rust_eh_personality() {} +#[lang = "panic_impl"] extern fn rust_begin_panic(_: &PanicInfo) -> ! { loop {} } + +#[no_mangle] +pub unsafe fn _start() -> ! { + asm!( + "syscall", + in("rax") 60, // Syscall number + in("rdi") 1, // Exit code + options(noreturn) + ) +} diff --git a/src/bin/true.rs b/src/bin/true.rs index 559b69f..2ce4d35 100644 --- a/src/bin/true.rs +++ b/src/bin/true.rs @@ -1,4 +1,22 @@ -// Copyright (c) 2022 Emma Tebibyte +// Copyright (c) 2022 silt // SPDX-License-Identifier: AGPL-3.0-or-later -fn main() { } +#![feature(lang_items, start)] +#![no_main] +#![no_std] + +use core::panic::PanicInfo; +use core::arch::asm; + +#[lang = "eh_personality"] extern fn rust_eh_personality() {} +#[lang = "panic_impl"] extern fn rust_begin_panic(_: &PanicInfo) -> ! { loop {} } + +#[no_mangle] +pub unsafe fn _start() -> ! { + asm!( + "syscall", + in("rax") 60, // Syscall number + in("rdi") 0, // Exit code + options(noreturn) + ) +}