From 2a5b0409a9cca55aa54f6412458773f4b6429aaf Mon Sep 17 00:00:00 2001 From: John Hodge <tpg@mutabah.net> Date: Sat, 16 Mar 2019 17:56:56 +0800 Subject: [PATCH] Usermode - Compilation fixes, and work on using Xargo (not yet ready) --- Usermode/Makefile | 38 ++++++++++++++-------- Usermode/Xargo.toml | 4 --- Usermode/filebrowser/Cargo.toml | 3 +- Usermode/libmacros/Cargo.toml | 1 - Usermode/libstd_rt/Cargo.toml | 1 - Usermode/link-amd64.ld | 1 + Usermode/loader/Cargo.toml | 17 ---------- Usermode/loader/bin/Cargo.toml | 13 ++++++++ Usermode/loader/{ => bin}/lib.S | 0 Usermode/loader/{ => bin}/link.ld | 0 Usermode/loader/{ => bin}/src/elf/mod.rs | 0 Usermode/loader/{ => bin}/src/interface.rs | 0 Usermode/loader/{ => bin}/src/load/mod.rs | 0 Usermode/loader/{ => bin}/src/main.rs | 5 +++ Usermode/loader/{ => bin}/start.S | 2 +- Usermode/loader/lib/Cargo.toml | 12 +++++++ Usermode/loader/{ => lib}/lib.rs | 2 +- common.mk | 5 +++ 18 files changed, 65 insertions(+), 39 deletions(-) delete mode 100644 Usermode/loader/Cargo.toml create mode 100644 Usermode/loader/bin/Cargo.toml rename Usermode/loader/{ => bin}/lib.S (100%) rename Usermode/loader/{ => bin}/link.ld (100%) rename Usermode/loader/{ => bin}/src/elf/mod.rs (100%) rename Usermode/loader/{ => bin}/src/interface.rs (100%) rename Usermode/loader/{ => bin}/src/load/mod.rs (100%) rename Usermode/loader/{ => bin}/src/main.rs (99%) rename Usermode/loader/{ => bin}/start.S (99%) create mode 100644 Usermode/loader/lib/Cargo.toml rename Usermode/loader/{ => lib}/lib.rs (98%) diff --git a/Usermode/Makefile b/Usermode/Makefile index 8da9b005..a2f0eb6d 100644 --- a/Usermode/Makefile +++ b/Usermode/Makefile @@ -30,7 +30,15 @@ RUST_COMMON_FLAGS := --target=$(TARGET_SPEC) --cfg 'arch="$(ARCH)"' --cfg nightl RUST_COMMON_FLAGS += -L $(LIBDIR) XARGO := RUST_TARGET_PATH=$(dir $(abspath $(TARGET_SPEC))) $(XARGO) -XARGO_FLAGS := --target target-$(ARCH) +XARGO_TARGET := target-$(ARCH) +XARGO_PROFILE := release +XARGO_FLAGS := --target $(XARGO_TARGET) +ifeq ($(XARGO_PROFILE),debug) +else ifeq ($(XARGO_PROFILE),release) + XARGO_FLAGS += --release +else + $(error Unknown xargo profile $(XARGO_PROFILE)) +endif RUSTFLAGS := $(RUST_COMMON_FLAGS) RUSTFLAGS += -O @@ -47,6 +55,7 @@ BIN_RUSTFLAGS := #BIN_RUSTFLAGS += -C lto RUSTFLAGS_compiler_builtins = --cfg feature=\"compiler-builtins\" --cfg stage0 +RUSTFLAGS_alloc = --edition 2018 # - List non-file targets .PHONY: all clean @@ -75,30 +84,33 @@ docs: $(patsubst lib%/,.docs/%/index.html,$(wildcard lib*/)) @echo "[RUSTDOC] -o $@" $V$(RUSTDOC) -o .docs $< --crate-name $* $(RUST_COMMON_FLAGS) -LOADER_DEPS := $(patsubst %,$(LIBDIR)lib%.rlib,$(call fn_getdeps,loader/src/main.rs) std std_io core std_rt compiler_builtins) +LOADER_DEPS := $(patsubst %,$(LIBDIR)lib%.rlib,$(call fn_getdeps,loader/bin/src/main.rs) std std_io core std_rt compiler_builtins) # Most binary targets have simple templates, but loader and libcore are special # loader: Requires an assembly stub # > Linking is done in two steps so that --gc-sections works -#$(BINDIR)loader: loader/link.ld $(OBJDIR)loader/start.ao $(OBJDIR)loader/src/main.o -$(BINDIR)loader: loader/link.ld $(OBJDIR)loader/start.ao $(OBJDIR)loader/src/main.o $(LOADER_DEPS) +#$(BINDIR)loader: loader/bin/link.ld $(OBJDIR)loader/bin/start.ao $(OBJDIR)loader/bin/src/main.o +$(BINDIR)loader: loader/bin/link.ld $(OBJDIR)loader/bin/start.ao $(OBJDIR)loader/bin/src/main.o $(LOADER_DEPS) @mkdir -p $(dir $@) @echo [LD] $@ - $V$(LD) -r --gc-sections --undefined image_header --entry start -o $(OBJDIR)loader.o $(OBJDIR)loader/start.ao $(OBJDIR)loader/src/main.o $(LOADER_DEPS) - $V$(LD) -o $(OBJDIR)loader.elf -T loader/link.ld $(OBJDIR)loader.o -Map $(OBJDIR)loader_map.txt + $V$(LD) -r --gc-sections --undefined image_header --entry start -o $(OBJDIR)loader.o $(OBJDIR)loader/bin/start.ao $(OBJDIR)loader/bin/src/main.o $(LOADER_DEPS) + $V$(LD) -o $(OBJDIR)loader.elf -T loader/bin/link.ld $(OBJDIR)loader.o -Map $(OBJDIR)loader_map.txt $V$(OBJCOPY) $(OBJDIR)loader.elf -O binary $@ $V$(OBJDUMP) -CS $(OBJDIR)loader.elf > $(OBJDIR)loader.dsm -$(OBJDIR)loader/src/main.o: $(LOADER_DEPS) -#$(OBJDIR)loader/src/main.o: +$(OBJDIR)loader/bin/src/main.o: $(LOADER_DEPS) +#$(OBJDIR)loader/bin/src/main.o: # $(XARGO) build $(XARGO_FLAGS) --manifest-path loader/Cargo.toml .PHONY: xargo -xargo: +xargo: $(LIBDIR)libloader_dyn.so $(OBJDIR)loader/bin/start.ao # Referenced by link-$(TARGET).ld + $(XARGO) build $(XARGO_FLAGS) --manifest-path libstd/Cargo.toml + $(XARGO) build $(XARGO_FLAGS) --manifest-path loader/bin/Cargo.toml + cp target/$(XARGO_TARGET)/$(XARGO_PROFILE)/libstd.rlib ../.prefix/xargo/lib/rustlib/$(XARGO_TARGET)/lib/ $(XARGO) build $(XARGO_FLAGS) # Low-level loader dummy dynamic library # - Used to tell ld that `loader`'s exported symbols actually exist -$(LIBDIR)libloader_dyn.so: loader/lib.S $(makefile_deps) +$(LIBDIR)libloader_dyn.so: loader/bin/lib.S $(makefile_deps) @mkdir -p $(dir $@) @echo [CC] $@ $V$(CC) -o $@.o -c $< -fPIC -D ARCH_$(ARCH) @@ -158,7 +170,7 @@ $(OBJDIR)lib%.rlib: $(RUSTUP_SRC_DIR)lib%/src/lib.rs $(OBJDIR)libcore.rlib $(TAR @mv $(OBJDIR)$*.d $(OBJDIR)lib$*.d # - Loader's interface library, lives in the loader directory -$(OBJDIR)libloader.rlib: loader/lib.rs $(TARGET_SPEC) $(makefile_deps) $(patsubst %,$(LIBDIR)lib%.rlib,$(call fn_getdeps,loader/lib.rs)) +$(OBJDIR)libloader.rlib: loader/lib/lib.rs $(TARGET_SPEC) $(makefile_deps) $(patsubst %,$(LIBDIR)lib%.rlib,$(call fn_getdeps,loader/lib/lib.rs)) @mkdir -p $(dir $@) @echo [RUSTC] $@ $V$(RUSTC) $(RUSTFLAGS) --emit=link,dep-info --out-dir $(OBJDIR) $< --crate-type=rlib @@ -181,7 +193,7 @@ $(OBJDIR)%.o: %.rs $(TARGET_SPEC) $(makefile_deps) @mkdir -p $(dir $@) @echo [RUSTC] $@ $V$(RUSTC) $(RUSTFLAGS) $< --out-dir=$(dir $@) --emit=obj,dep-info --include $(OBJDIR)loader/src/main.d +-include $(OBJDIR)loader/bin/src/main.d # - Assembly objects (loader) $(OBJDIR)%.ao: %.S $(makefile_deps) @@ -207,7 +219,7 @@ ALL_PRESENT_BINS := $(patsubst %/src/main.rs,%, $(wildcard */src/main.rs)) DEPFILES := $(patsubst %,$(OBJDIR)lib%.d, $(ALL_USED_LIBS)) DEPFILES += $(patsubst %,$(OBJDIR)%.d, $(ALL_PRESENT_BINS)) -DEPFILES += $(OBJDIR)loader/start.ao.d $(OBJDIR)rustrt0.o.d +DEPFILES += $(OBJDIR)loader/bin/start.ao.d $(OBJDIR)rustrt0.o.d -include $(DEPFILES) # Official library dependency tree diff --git a/Usermode/Xargo.toml b/Usermode/Xargo.toml index a8ecde9e..775329b1 100644 --- a/Usermode/Xargo.toml +++ b/Usermode/Xargo.toml @@ -1,6 +1,2 @@ [dependencies.alloc] stage = 0 - -#[dependencies.std] -#path = "libstd" -#stage = 2 diff --git a/Usermode/filebrowser/Cargo.toml b/Usermode/filebrowser/Cargo.toml index dfef6ed7..abc74a0e 100644 --- a/Usermode/filebrowser/Cargo.toml +++ b/Usermode/filebrowser/Cargo.toml @@ -3,7 +3,8 @@ name = "filebrowser" version = "0.0.1" [dependencies] +#std = { path = "../libstd" } wtk = { path = "../libwtk" } vec_ring = { path = "../libvec_ring" } syscalls = { path = "../libsyscalls" } -loader = { path = "../loader" } +loader = { path = "../loader/lib" } diff --git a/Usermode/libmacros/Cargo.toml b/Usermode/libmacros/Cargo.toml index 47dc8084..eea72cc7 100644 --- a/Usermode/libmacros/Cargo.toml +++ b/Usermode/libmacros/Cargo.toml @@ -1,5 +1,4 @@ [package] -crate-type = "lib" name = "macros" version = "0.0.1" diff --git a/Usermode/libstd_rt/Cargo.toml b/Usermode/libstd_rt/Cargo.toml index 8f1df4be..d9f2887c 100644 --- a/Usermode/libstd_rt/Cargo.toml +++ b/Usermode/libstd_rt/Cargo.toml @@ -1,5 +1,4 @@ [package] -crate-type = "lib" name = "std_rt" version = "0.0.1" diff --git a/Usermode/link-amd64.ld b/Usermode/link-amd64.ld index acba19ec..d20cecf2 100644 --- a/Usermode/link-amd64.ld +++ b/Usermode/link-amd64.ld @@ -1,5 +1,6 @@ ENTRY(start) +SEARCH_DIR( .ojs/amd64/libs ) STARTUP( .objs/amd64/rustrt0.o ) PHDRS { diff --git a/Usermode/loader/Cargo.toml b/Usermode/loader/Cargo.toml deleted file mode 100644 index 1abf89e3..00000000 --- a/Usermode/loader/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "loader" -version = "0.0.1" - -[[bin]] -name = "loader" -path = "src/main.rs" - -[lib] -path = "lib.rs" - -[dependencies] -std = { path = "../libstd" } -std_rt = { path = "../libstd_rt" } -syscalls = { path = "../libsyscalls" } -byteorder = { path = "../libbyteorder" } -cmdline_words_parser = { path = "../../externals/crates.io/cmdline_words_parser" } diff --git a/Usermode/loader/bin/Cargo.toml b/Usermode/loader/bin/Cargo.toml new file mode 100644 index 00000000..ed015e4b --- /dev/null +++ b/Usermode/loader/bin/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "loader-binary" +version = "0.0.0" + +[lib] +path = "src/main.rs" + +[dependencies] +loader = { path = "../lib" } +syscalls = { path = "../../libsyscalls" } +byteorder = { path = "../../libbyteorder" } +macros = { path = "../../libmacros" } +cmdline_words_parser = { path = "../../../externals/crates.io/cmdline_words_parser" } diff --git a/Usermode/loader/lib.S b/Usermode/loader/bin/lib.S similarity index 100% rename from Usermode/loader/lib.S rename to Usermode/loader/bin/lib.S diff --git a/Usermode/loader/link.ld b/Usermode/loader/bin/link.ld similarity index 100% rename from Usermode/loader/link.ld rename to Usermode/loader/bin/link.ld diff --git a/Usermode/loader/src/elf/mod.rs b/Usermode/loader/bin/src/elf/mod.rs similarity index 100% rename from Usermode/loader/src/elf/mod.rs rename to Usermode/loader/bin/src/elf/mod.rs diff --git a/Usermode/loader/src/interface.rs b/Usermode/loader/bin/src/interface.rs similarity index 100% rename from Usermode/loader/src/interface.rs rename to Usermode/loader/bin/src/interface.rs diff --git a/Usermode/loader/src/load/mod.rs b/Usermode/loader/bin/src/load/mod.rs similarity index 100% rename from Usermode/loader/src/load/mod.rs rename to Usermode/loader/bin/src/load/mod.rs diff --git a/Usermode/loader/src/main.rs b/Usermode/loader/bin/src/main.rs similarity index 99% rename from Usermode/loader/src/main.rs rename to Usermode/loader/bin/src/main.rs index cb2192d1..ac3afc93 100644 --- a/Usermode/loader/src/main.rs +++ b/Usermode/loader/bin/src/main.rs @@ -4,11 +4,16 @@ // This program is both the initial entrypoint for the userland, and the default dynamic linker. #![feature(const_fn)] #![crate_type="lib"] +#![no_main] use cmdline_words_parser::StrExt as CmdlineStrExt; use load::SegmentIterator; +#[link(name="loader_start")] +extern "C" { +} + #[macro_use] extern crate syscalls; diff --git a/Usermode/loader/start.S b/Usermode/loader/bin/start.S similarity index 99% rename from Usermode/loader/start.S rename to Usermode/loader/bin/start.S index 426b531d..8d732591 100644 --- a/Usermode/loader/start.S +++ b/Usermode/loader/bin/start.S @@ -13,7 +13,7 @@ .globl LIMIT .globl PAGE_SIZE -#include "../rustrt0/common.S" +#include "../../rustrt0/common.S" #ifdef ARCH_amd64 # define DEFPTR .quad diff --git a/Usermode/loader/lib/Cargo.toml b/Usermode/loader/lib/Cargo.toml new file mode 100644 index 00000000..d0f1730b --- /dev/null +++ b/Usermode/loader/lib/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "loader" +version = "0.0.1" + +[lib] +path = "lib.rs" + +[dependencies] +syscalls = { path = "../../libsyscalls" } +#byteorder = { path = "../libbyteorder" } +#macros = { path = "../libmacros" } +#cmdline_words_parser = { path = "../../externals/crates.io/cmdline_words_parser" } diff --git a/Usermode/loader/lib.rs b/Usermode/loader/lib/lib.rs similarity index 98% rename from Usermode/loader/lib.rs rename to Usermode/loader/lib/lib.rs index e87ff708..7c984386 100644 --- a/Usermode/loader/lib.rs +++ b/Usermode/loader/lib/lib.rs @@ -6,7 +6,7 @@ #![crate_type="dylib"] #![crate_name="loader"] -extern crate std_rt; +//extern crate std_rt; extern crate syscalls; use core::result::Result; diff --git a/common.mk b/common.mk index b12df468..04cc052c 100644 --- a/common.mk +++ b/common.mk @@ -2,6 +2,10 @@ .PHONY: default default: all +nop := +space := $(nop) $(nop) +comma := , + ARCH ?= amd64 ifeq ($(ARCH),amd64) @@ -42,6 +46,7 @@ RUSTDOC := $(call fn_rustcmd,rustdoc) CARGO := $(call fn_rustcmd,cargo) XARGO := XARGO_HOME=$(abspath $(PREFIX)xargo) $(call fn_rustcmd,xargo) +# NOTE: rustc-src doesn't contain compiler_builtins (which is a crates.io package) #RUSTUP_SRC_DIR = $(firstword $(wildcard $(PREFIX)toolchains/nightly-*/lib/rustlib/src/rust/src))/ RUSTUP_SRC_DIR := $(abspath $(ROOTDIR)/rustc-nightly-src/src)/ $(warning $(RUSTUP_SRC_DIR)) -- GitLab