Browse Source

Combine all libraries into libc.a, call pthread_init and pthread_terminate in libc

Jeremy Soller 6 years ago
parent
commit
0c5abf0361
5 changed files with 27 additions and 4 deletions
  1. 1 1
      Cargo.toml
  2. 19 2
      Makefile
  3. 1 1
      pthreads-emb
  4. 3 0
      src/header/stdlib/mod.rs
  5. 3 0
      src/start.rs

+ 1 - 1
Cargo.toml

@@ -4,7 +4,7 @@ version = "0.1.0"
 authors = ["Jeremy Soller <[email protected]>"]
 
 [lib]
-name = "c"
+name = "relibc"
 crate-type = ["staticlib"]
 
 [workspace]

+ 19 - 2
Makefile

@@ -76,7 +76,16 @@ sysroot: all
 test: sysroot
 	make -C tests run
 
-$(BUILD)/debug/libc.a: $(SRC)
+$(BUILD)/release/libc.a: $(BUILD)/release/librelibc.a $(BUILD)/pthreads-emb/libpthread.a $(BUILD)/openlibm/libopenlibm.a
+	echo "create $@" > "[email protected]"
+	for lib in $^; do\
+		echo "addlib $$lib" >> "[email protected]"; \
+	done
+	echo "save" >> "[email protected]"
+	echo "end" >> "[email protected]"
+	ar -M < "[email protected]"
+
+$(BUILD)/debug/librelibc.a: $(SRC)
 	$(CARGO) rustc $(CARGOFLAGS) -- $(RUSTCFLAGS)
 	touch $@
 
@@ -84,7 +93,15 @@ $(BUILD)/debug/crt0.o: $(SRC)
 	CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
 	touch $@
 
-$(BUILD)/release/libc.a: $(SRC)
+$(BUILD)/debug/crti.o: $(SRC)
+	CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
+	touch $@
+
+$(BUILD)/debug/crtn.o: $(SRC)
+	CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
+	touch $@
+
+$(BUILD)/release/librelibc.a: $(SRC)
 	$(CARGO) rustc --release $(CARGOFLAGS) -- $(RUSTCFLAGS)
 	touch $@
 

+ 1 - 1
pthreads-emb

@@ -1 +1 @@
-Subproject commit a12978ccca4c576f02971f5cfc2cbefe23e4daba
+Subproject commit 91f0dd6e3f9c8ee81508f3a32e1d6f3e97e35726

+ 3 - 0
src/header/stdlib/mod.rs

@@ -233,6 +233,7 @@ pub unsafe extern "C" fn exit(status: c_int) {
         static __fini_array_start: extern "C" fn();
         static __fini_array_end: extern "C" fn();
 
+        fn pthread_terminate();
         fn _fini();
     }
 
@@ -251,6 +252,8 @@ pub unsafe extern "C" fn exit(status: c_int) {
 
     _fini();
 
+    pthread_terminate();
+
     Sys::exit(status);
 }
 

+ 3 - 0
src/start.rs

@@ -53,6 +53,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
         static __init_array_start: extern "C" fn();
         static __init_array_end: extern "C" fn();
 
+        fn pthread_init();
         fn _init();
         fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int;
     }
@@ -77,6 +78,8 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
     stdio::stdout = stdio::default_stdout.get();
     stdio::stderr = stdio::default_stderr.get();
 
+    pthread_init();
+
     // Run preinit array
     {
         let mut f = &__preinit_array_start as *const _;