]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix: build system cleanup — replace non-freestanding <string.h> with utils.h, paramet...
authorTulio A M Mendes <[email protected]>
Fri, 13 Mar 2026 23:45:00 +0000 (20:45 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Mar 2026 23:45:00 +0000 (20:45 -0300)
- Kernel: replace #include <string.h> (not freestanding) with #include "utils.h"
  in src/arch/x86/fpu.c, src/kernel/fpu.c, src/rump/rumpuser_adros.c
- Makefile: define USER_CC/USER_LD/USER_AR variables for userspace cross-compilation,
  replacing all hardcoded i686-elf-gcc/ld references in FULLTEST, DYN_CC, DYN_LD,
  LDSO, PIE_SO, PIE_ELF rules
- Makefile: pass USER_CC/USER_LD/USER_AR to ulibc sub-make for consistent toolchain
- Makefile: add missing .PHONY targets (test-battery, run-arm, run-riscv, run-mips)
- ulibc Makefile: use ?= for CC/AS/AR/LD so parent can override
- doom Makefile: use ?= for CC/LD so parent can override
- ulibc: remove duplicate stat/fstat declarations from unistd.h (conflicted with
  sys/stat.h when both included); proper declarations remain in sys/stat.h per POSIX

Makefile
src/arch/x86/fpu.c
src/kernel/fpu.c
src/rump/rumpuser_adros.c
user/doom/Makefile
user/ulibc/Makefile
user/ulibc/include/unistd.h

index 60b72bb701f827cb9c769ee2e03179c6dc19fd6b..02f123e25a8e747838ed05429553af877e1b8517 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -73,6 +73,11 @@ ifeq ($(ARCH),x86)
     ASM_SOURCES := $(wildcard $(SRC_DIR)/arch/x86/*.S)
     C_SOURCES += $(wildcard $(SRC_DIR)/arch/x86/*.c)
 
+    # Userspace cross-compiler (always i686-elf, even when kernel CC differs)
+    USER_CC  ?= i686-elf-gcc
+    USER_LD  ?= i686-elf-ld
+    USER_AR  ?= i686-elf-ar
+
     FULLTEST_ELF := user/fulltest.elf
     ECHO_ELF := user/echo.elf
     SH_ELF := user/sh.elf
@@ -213,18 +218,18 @@ ULIBC_DIR := user/ulibc
 ULIBC_LIB := $(ULIBC_DIR)/libulibc.a
 
 $(ULIBC_LIB):
-       @$(MAKE) -C $(ULIBC_DIR) --no-print-directory
+       @$(MAKE) -C $(ULIBC_DIR) CC="$(USER_CC)" AS="$(USER_CC:gcc=as)" AR="$(USER_AR)" LD="$(USER_LD)" --no-print-directory
 
 $(ULIBC_SO):
-       @$(MAKE) -C $(ULIBC_DIR) libc.so --no-print-directory
+       @$(MAKE) -C $(ULIBC_DIR) CC="$(USER_CC)" AS="$(USER_CC:gcc=as)" AR="$(USER_AR)" LD="$(USER_LD)" libc.so --no-print-directory
 
 $(FULLTEST_ELF): user/fulltest.c user/linker.ld
-       @i686-elf-gcc -m32 -I include -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/linker.ld -o $(FULLTEST_ELF) user/fulltest.c user/errno.c
+       @$(USER_CC) -m32 -I include -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/linker.ld -o $(FULLTEST_ELF) user/fulltest.c user/errno.c
 
 # --- Dynamic linking helper: compile .c to PIC .o, link as PIE with crt0 + libc.so ---
 ULIBC_CRT0 := $(ULIBC_DIR)/src/crt0.o
-DYN_CC := i686-elf-gcc -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -fPIC -fno-plt -I$(ULIBC_DIR)/include
-DYN_LD := i686-elf-ld -m elf_i386 --dynamic-linker=/lib/ld.so -T user/dyn_linker.ld -L$(ULIBC_DIR) -rpath /lib
+DYN_CC := $(USER_CC) -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -fPIC -fno-plt -I$(ULIBC_DIR)/include
+DYN_LD := $(USER_LD) -m elf_i386 --dynamic-linker=/lib/ld.so -T user/dyn_linker.ld -L$(ULIBC_DIR) -rpath /lib
 
 $(ECHO_ELF): user/echo.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB)
        @$(DYN_CC) -c user/echo.c -o user/echo.o
@@ -435,15 +440,15 @@ $(WHICH_ELF): user/which.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB)
        @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/which.o -lc
 
 $(LDSO_ELF): user/ldso.c user/ldso_linker.ld
-       @i686-elf-gcc -m32 -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/ldso_linker.ld -o $(LDSO_ELF) user/ldso.c
+       @$(USER_CC) -m32 -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/ldso_linker.ld -o $(LDSO_ELF) user/ldso.c
 
 $(PIE_SO): user/pie_func.c
-       @i686-elf-gcc -m32 -fPIC -fno-plt -c user/pie_func.c -o user/pie_func.o
-       @i686-elf-ld -m elf_i386 -shared -soname libpietest.so -o $(PIE_SO) user/pie_func.o
+       @$(USER_CC) -m32 -fPIC -fno-plt -c user/pie_func.c -o user/pie_func.o
+       @$(USER_LD) -m elf_i386 -shared -soname libpietest.so -o $(PIE_SO) user/pie_func.o
 
 $(PIE_ELF): user/pie_main.c user/pie_linker.ld $(PIE_SO)
-       @i686-elf-gcc -m32 -fPIC -c user/pie_main.c -o user/pie_main.o
-       @i686-elf-ld -m elf_i386 -pie --dynamic-linker=/lib/ld.so -T user/pie_linker.ld -o $(PIE_ELF) user/pie_main.o $(PIE_SO) -rpath /lib
+       @$(USER_CC) -m32 -fPIC -c user/pie_main.c -o user/pie_main.o
+       @$(USER_LD) -m elf_i386 -pie --dynamic-linker=/lib/ld.so -T user/pie_linker.ld -o $(PIE_ELF) user/pie_main.o $(PIE_SO) -rpath /lib
 
 # All dynamically-linked user commands
 USER_CMDS := $(ECHO_ELF) $(SH_ELF) $(CAT_ELF) $(LS_ELF) $(MKDIR_ELF) $(RM_ELF) \
@@ -634,4 +639,4 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.S
 clean:
        rm -rf build $(KERNEL_NAME)
 
-.PHONY: all clean iso run cppcheck sparse analyzer check test test-1cpu test-host test-gdb test-all scan-build mkinitrd-asan
+.PHONY: all clean iso run run-arm run-riscv run-mips cppcheck sparse analyzer check test test-1cpu test-battery test-host test-gdb test-all scan-build mkinitrd-asan
index 0d8ee55928c40082912d091e7ae40765f3bc7c4a..a74b16fcd490dfc0603f6ea9518d36865e1f3ad8 100644 (file)
@@ -3,7 +3,7 @@
 #include "hal/cpu_features.h"
 
 #include <stdint.h>
-#include <string.h>
+#include "utils.h"
 
 /* CR0 bits */
 #define CR0_EM  (1U << 2)   /* Emulate coprocessor (must be CLEAR for real FPU) */
index 0796b11506edaab8fb3f5b6cc89ba2bacd5b5a4a..c673728baaaf149209f8a7be9cef352707194467 100644 (file)
@@ -1,6 +1,6 @@
 #include "arch_fpu.h"
 #include "console.h"
-#include <string.h>
+#include "utils.h"
 
 __attribute__((weak))
 void arch_fpu_init(void) {
index f5122bc7b7c23ca998e951e3ae08ba6f42d9703a..aa22e9c3f121d04dc07d792b51de1fdcbd6779fd 100644 (file)
@@ -22,8 +22,7 @@
 #include "process.h"
 #include "sync.h"
 #include "hal/cpu.h"
-
-#include <string.h>
+#include "utils.h"
 
 /* ------------------------------------------------------------------ */
 /* Rump hypercall version                                              */
index ab51cd28116ee02c4359956ef7a40a5159fa6f88..ba56605070c2b8bf86165d4f07845df60c3733b9 100644 (file)
@@ -8,8 +8,8 @@
 #
 # The output is doom.elf which gets packaged into the AdrOS initrd.
 
-CC := i686-elf-gcc
-LD := i686-elf-ld
+CC  ?= i686-elf-gcc
+LD  ?= i686-elf-ld
 
 ULIBC_DIR := ../ulibc
 ULIBC_INC := $(ULIBC_DIR)/include
index a8203a34c5545bc2733f9324f4596c79564ef950..844ea414bc61d97768557d15343eac445dcf760b 100644 (file)
@@ -1,8 +1,8 @@
 # ulibc — Minimal C library for AdrOS userspace
-CC := i686-elf-gcc
-AS := i686-elf-as
-AR := i686-elf-ar
-LD := i686-elf-ld
+CC  ?= i686-elf-gcc
+AS  ?= i686-elf-as
+AR  ?= i686-elf-ar
+LD  ?= i686-elf-ld
 
 CFLAGS := -m32 -ffreestanding -fno-pie -no-pie -nostdlib -O2 -Wall -Wextra -Iinclude
 CFLAGS_PIC := -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -Iinclude -fPIC -fno-plt
index 41f486742b2db03c4ad1a3d2bb43a4bd477c5c7d..085b7be5022abf4800e855cdb3308c9073863384 100644 (file)
@@ -59,8 +59,6 @@ void*   brk(void* addr);
 
 int     waitpid(int pid, int* status, int options);
 int     getdents(int fd, void* buf, size_t count);
-int     stat(const char* path, void* buf);  /* use sys/stat.h for typed version */
-int     fstat(int fd, void* buf);              /* use sys/stat.h for typed version */
 int     chmod(const char* path, int mode);
 int     chown(const char* path, int owner, int group);
 int     link(const char* oldpath, const char* newpath);