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

Update toolchain, improve linker script, and reduce binary size. #20

Merged
merged 7 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.target]
rustflags = ["-C", "link-arg=-s"]
24 changes: 13 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ dist: xenial
language: rust

rust:
- nightly-2019-05-10
- nightly-2019-11-05
env:
- RUSTFLAGS="-D warnings"

before_script:
addons:
apt:
update: true

install:
- rustup component add clippy
- rustup component add rustfmt
- rustup component add rust-src
- cargo install cargo-xbuild
- sudo apt-get install -y mtools

addons:
apt:
update: true
- wget https://download.clearlinux.org/releases/28660/clear/clear-28660-kvm.img.xz
- unxz clear-28660-kvm.img.xz
- ./make-test-disks.sh

script:
- cargo xbuild --release --target target.json
- cargo xclippy -- -D warnings
- cargo clippy --all-targets --all-features -- -D warnings
- cargo xclippy
- cargo clippy --all-targets --all-features
- cargo fmt --all -- --check
- wget https://download.clearlinux.org/releases/28660/clear/clear-28660-kvm.img.xz
- unxz clear-28660-kvm.img.xz
- ./make-test-disks.sh
- cargo test

deploy:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ edition = "2018"
# the profile used for `cargo build`
[profile.dev]
panic = "abort" # disable stack unwinding on panic
lto = true

# the profile used for `cargo build --release`
[profile.release]
panic = "abort" # disable stack unwinding on panic
lto = true

[dependencies]
cpuio = "*"
Expand Down
53 changes: 30 additions & 23 deletions layout.ld
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
ENTRY(_start)


PHDRS
{
rodata PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
text PT_LOAD ;
}

SECTIONS
{
. = 1M;
start_of_text = . ;
.text : ALIGN(4K)
{
*(.text .text.*)
}
end_of_text = . ;
. = 1M ;
_start_of_file = . ;

start_of_data = . ;
.rodata : ALIGN(4K)
{
*(.rodata .rodata.*)
}

.data : ALIGN(4K)
{
*(.data .data.*)
}
end_of_data = . ;

.bss : ALIGN(4K)
{
/* Mapping in the program headers makes it easier to mmap the whole file. */
. += SIZEOF_HEADERS ;

.rodata : { *(.rodata .rodata.*) } :rodata
.data : { *(.data .data.*) } :data
.bss : { *(.bss .bss.*) } :data
.text : { *(.text .text.*) } :text

_end_of_file = . ;

/* Match edk2's GccBase.lds DISCARD section */
/DISCARD/ : {
*(.note.GNU-stack)
*(.gnu_debuglink)
*(.interp)
*(.dynsym)
*(.dynstr)
*(.dynamic)
*(.hash .gnu.hash)
*(.comment)
*(COMMON)
*(.bss .bss.*)
}
}
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2019-05-10
nightly-2019-11-05
4 changes: 2 additions & 2 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct UsedElem {
#[cfg(not(test))]
/// Device driver for virtio block over any transport
pub struct VirtioBlockDevice<'a> {
transport: &'a mut VirtioTransport,
transport: &'a mut dyn VirtioTransport,
state: RefCell<DriverState>,
}

Expand Down Expand Up @@ -131,7 +131,7 @@ enum RequestType {

#[cfg(not(test))]
impl<'a> VirtioBlockDevice<'a> {
pub fn new(transport: &'a mut VirtioTransport) -> VirtioBlockDevice<'a> {
pub fn new(transport: &'a mut dyn VirtioTransport) -> VirtioBlockDevice<'a> {
VirtioBlockDevice {
transport,
state: RefCell::new(DriverState::default()),
Expand Down
6 changes: 3 additions & 3 deletions src/bzimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct E820Entry {
}

#[cfg(not(test))]
pub fn load_initrd(f: &mut Read) -> Result<(), Error> {
pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
let mut zero_page = crate::mem::MemoryRegion::new(ZERO_PAGE_START as u64, 4096);

let mut max_load_address = u64::from(zero_page.read_u32(0x22c));
Expand Down Expand Up @@ -147,7 +147,7 @@ pub fn append_commandline(addition: &str) -> Result<(), Error> {
}

#[cfg(not(test))]
pub fn load_kernel(f: &mut Read) -> Result<(u64), Error> {
pub fn load_kernel(f: &mut dyn Read) -> Result<u64, Error> {
f.seek(0)?;

let mut buf: [u8; 1024] = [0; 1024];
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn load_kernel(f: &mut Read) -> Result<(u64), Error> {

let setup_bytes = setup_sects * 512; // Use to start reading the main image

let mut load_offset = u64::from(KERNEL_LOCATION);;
let mut load_offset = u64::from(KERNEL_LOCATION);

f.seek(setup_bytes as u32)?;

Expand Down
4 changes: 2 additions & 2 deletions src/fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum FatType {
}

pub struct Filesystem<'a> {
device: &'a SectorRead,
device: &'a dyn SectorRead,
start: u64,
last: u64,
bytes_per_sector: u32,
Expand Down Expand Up @@ -374,7 +374,7 @@ fn compare_name(name: &str, de: &DirectoryEntry) -> bool {
}

impl<'a> Filesystem<'a> {
pub fn new(device: &'a SectorRead, start: u64, last: u64) -> Filesystem {
pub fn new(device: &'a dyn SectorRead, start: u64, last: u64) -> Filesystem {
Filesystem {
device,
start,
Expand Down
2 changes: 1 addition & 1 deletion src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn default_entry_path(fs: &fat::Filesystem) -> Result<[u8; 260], fat::Error> {
}

#[cfg(not(test))]
pub fn load_default_entry(fs: &fat::Filesystem) -> Result<(u64), Error> {
pub fn load_default_entry(fs: &fat::Filesystem) -> Result<u64, Error> {
let default_entry_path = default_entry_path(&fs)?;
let default_entry_path = ascii_strip(&default_entry_path);

Expand Down
4 changes: 2 additions & 2 deletions src/part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum Error {
NoEFIPartition,
}

pub fn get_partitions(r: &SectorRead, parts_out: &mut [PartitionEntry]) -> Result<u32, Error> {
pub fn get_partitions(r: &dyn SectorRead, parts_out: &mut [PartitionEntry]) -> Result<u32, Error> {
let mut data: [u8; 512] = [0; 512];
match r.read(1, &mut data) {
Ok(_) => {}
Expand Down Expand Up @@ -123,7 +123,7 @@ pub fn get_partitions(r: &SectorRead, parts_out: &mut [PartitionEntry]) -> Resul
}

/// Find EFI partition
pub fn find_efi_partition(r: &SectorRead) -> Result<(u64, u64), Error> {
pub fn find_efi_partition(r: &dyn SectorRead) -> Result<(u64, u64), Error> {
// Assume no more than 16 partitions on the disk
let mut parts: [PartitionEntry; 16] = unsafe { core::mem::zeroed() };

Expand Down
5 changes: 2 additions & 3 deletions src/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::mem::MemoryRegion;

pub struct Loader<'a> {
file: &'a mut crate::fat::Read,
file: &'a mut dyn crate::fat::Read,
num_sections: u16,
image_base: u64,
image_size: u32,
Expand All @@ -38,7 +38,7 @@ struct Section {
}

impl<'a> Loader<'a> {
pub fn new(file: &'a mut crate::fat::Read) -> Loader {
pub fn new(file: &'a mut dyn crate::fat::Read) -> Loader {
Loader {
file,
num_sections: 0,
Expand Down Expand Up @@ -236,5 +236,4 @@ mod tests {
assert_eq!(a, fake_mem as u64 + 0x4000);
assert_eq!(size, 110_592);
}

}