]> 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 1e9b1b77d245e0e88f12f53c7a72b7407b9c2efd..796bf54db69965d9f9d8bb0216a7683e309b6a4d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,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
@@ -222,18 +227,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
@@ -444,15 +449,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) \
@@ -643,4 +648,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 bb44403812f8a061be51b8bfb7ccf5effb1f4e36..45980ced668531b13ace59ce1c9a6b2b27cdcbd2 100644 (file)
@@ -12,7 +12,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 0e16bb415e6fe63445c8824c24df9c3bf361c342..4efbd96adab749983ce7ab835c4459e3f854fcb3 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "arch_fpu.h"
 #include "console.h"
-#include <string.h>
+#include "utils.h"
 
 __attribute__((weak))
 void arch_fpu_init(void) {
index add7d3d53e5d0eea817b66d99cb9758e2fd8b41d..7c74776b523cf72824fa46d1f2b1528d15ad8c7e 100644 (file)
@@ -31,8 +31,7 @@
 #include "process.h"
 #include "sync.h"
 #include "hal/cpu.h"
-
-#include <string.h>
+#include "utils.h"
 
 /* ------------------------------------------------------------------ */
 /* Rump hypercall version                                              */
index 2b48a00357add16afc5cf58411fefb92ced84b26..7fefe9751eabb1d1c1c3579281fe9cbfabfa0107 100644 (file)
@@ -17,8 +17,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 8d304d6dde689c26e95d8c4f6062a58a5c69f887..b78c42f5d756f4ead1df508361e5b0cdb7cacb87 100644 (file)
@@ -8,10 +8,10 @@
 #
 
 # 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 564854755c48143dda8a60ff6f2a864815605b7f..1cef18521f5c8cd55f39be916d7e5f8e85adc088 100644 (file)
@@ -68,8 +68,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);