From: Tulio A M Mendes Date: Sat, 14 Mar 2026 11:11:46 +0000 (-0300) Subject: toolchain: native GCC/Binutils Canadian cross build support X-Git-Url: https://projects.tadryanom.me/docs/static/git-logo.png?a=commitdiff_plain;h=3b82c29c0f3448fd235119e879ef32ee47637a87;p=AdrOS.git toolchain: native GCC/Binutils Canadian cross build support - posix_compat.c: add ioctl, ftw, nftw, dlopen/dlsym/dlclose/dlerror, pathconf/fpathconf, execv stubs needed by native Binutils and GCC - sysroot headers: add extern "C" guards to sys/mman.h, sys/ioctl.h, sys/dirent.h for C++ compatibility (prevents mangled symbol mismatches) - build.sh: add patches for GCC prerequisites (GMP/MPFR/MPC/ISL config.sub), libcody removal from host_libs, Binutils tc-i386.c uint32_t type fix - toolchain/patches/native-toolchain.patch: document all native build patches Native toolchain produces ELF32 i686 static binaries: Binutils 2.42: ar, as, ld, objdump GCC 13.2.0: xgcc (2.3MB), cc1 (27MB), cpp, gcov, gcov-tool libstdc++: 809 headers + libstdc++.a (built with --with-newlib) --- diff --git a/newlib/libgloss/adros/posix_compat.c b/newlib/libgloss/adros/posix_compat.c index 5c5c7b5..8a0f4d8 100644 --- a/newlib/libgloss/adros/posix_compat.c +++ b/newlib/libgloss/adros/posix_compat.c @@ -548,3 +548,81 @@ uint32_t htonl(uint32_t h) { return __builtin_bswap32(h); } uint16_t htons(uint16_t h) { return __builtin_bswap16(h); } uint32_t ntohl(uint32_t n) { return __builtin_bswap32(n); } uint16_t ntohs(uint16_t n) { return __builtin_bswap16(n); } + +/* ---- execv ---- */ +int execv(const char *path, char *const argv[]) +{ + return execve(path, argv, environ); +} + +/* ---- dlopen/dlsym/dlclose/dlerror stubs ---- */ +#include + +void *dlopen(const char *filename, int flags) +{ + (void)filename; (void)flags; + return NULL; +} + +void *dlsym(void *handle, const char *symbol) +{ + (void)handle; (void)symbol; + return NULL; +} + +int dlclose(void *handle) +{ + (void)handle; + return 0; +} + +char *dlerror(void) +{ + return "dlopen not supported on AdrOS"; +} + +/* ---- pathconf ---- */ +long pathconf(const char *path, int name) +{ + (void)path; + switch (name) { + case 1: return 255; /* _PC_NAME_MAX */ + case 2: return 4096; /* _PC_PATH_MAX */ + case 3: return 4096; /* _PC_PIPE_BUF */ + case 5: return 1; /* _PC_LINK_MAX */ + default: errno = EINVAL; return -1; + } +} + +long fpathconf(int fd, int name) +{ + (void)fd; + return pathconf("/", name); +} + +/* ioctl — minimal stub for terminal queries */ +#include +int ioctl(int fd, unsigned long request, ...) +{ + (void)fd; + (void)request; + errno = ENOSYS; + return -1; +} + +/* ---- ftw / nftw stubs ---- */ +#include + +int ftw(const char *dirpath, int (*fn)(const char *, const struct stat *, int), int nopenfd) +{ + (void)dirpath; (void)fn; (void)nopenfd; + errno = ENOSYS; + return -1; +} + +int nftw(const char *dirpath, int (*fn)(const char *, const struct stat *, int, struct FTW *), int nopenfd, int flags) +{ + (void)dirpath; (void)fn; (void)nopenfd; (void)flags; + errno = ENOSYS; + return -1; +} diff --git a/newlib/sysroot_headers/sys/dirent.h b/newlib/sysroot_headers/sys/dirent.h index 1b57a23..2f92e3b 100644 --- a/newlib/sysroot_headers/sys/dirent.h +++ b/newlib/sysroot_headers/sys/dirent.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define MAXNAMLEN 255 struct dirent { @@ -22,4 +26,8 @@ struct dirent *readdir(DIR *); int closedir(DIR *); void rewinddir(DIR *); +#ifdef __cplusplus +} +#endif + #endif /* _SYS_DIRENT_H */ diff --git a/newlib/sysroot_headers/sys/ioctl.h b/newlib/sysroot_headers/sys/ioctl.h index 81e8177..45cca6f 100644 --- a/newlib/sysroot_headers/sys/ioctl.h +++ b/newlib/sysroot_headers/sys/ioctl.h @@ -1,6 +1,10 @@ #ifndef _SYS_IOCTL_H #define _SYS_IOCTL_H +#ifdef __cplusplus +extern "C" { +#endif + /* Minimal ioctl definitions for AdrOS */ #define TIOCGPGRP 0x540F #define TIOCSPGRP 0x5410 @@ -17,4 +21,8 @@ struct winsize { int ioctl(int fd, unsigned long request, ...); +#ifdef __cplusplus +} +#endif + #endif /* _SYS_IOCTL_H */ diff --git a/newlib/sysroot_headers/sys/mman.h b/newlib/sysroot_headers/sys/mman.h index 47b6b96..ba79636 100644 --- a/newlib/sysroot_headers/sys/mman.h +++ b/newlib/sysroot_headers/sys/mman.h @@ -1,6 +1,11 @@ #ifndef _SYS_MMAN_H #define _SYS_MMAN_H #include + +#ifdef __cplusplus +extern "C" { +#endif + #define PROT_NONE 0 #define PROT_READ 1 #define PROT_WRITE 2 @@ -24,4 +29,9 @@ int madvise(void* addr, size_t length, int advice); int mlock(const void* addr, size_t len); int munlock(const void* addr, size_t len); void* mremap(void* old_addr, size_t old_size, size_t new_size, int flags, ...); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/toolchain/build.sh b/toolchain/build.sh index 76b3ba1..f613909 100755 --- a/toolchain/build.sh +++ b/toolchain/build.sh @@ -154,6 +154,14 @@ i[3-7]86-*-adros*)\ttarg_emul=elf_i386\ step "Patched ld/configure.tgt" fi + # gas/config/tc-i386.c — fix type mismatch (uint32_t vs unsigned int) + # The header declares uint32_t but the source used unsigned int. + if grep -q 'x86_scfi_callee_saved_p (unsigned int' "$d/gas/config/tc-i386.c" 2>/dev/null; then + sed -i 's/x86_scfi_callee_saved_p (unsigned int dw2reg_num)/x86_scfi_callee_saved_p (uint32_t dw2reg_num)/' \ + "$d/gas/config/tc-i386.c" + step "Patched gas/config/tc-i386.c (uint32_t fix)" + fi + touch "$marker" } @@ -235,6 +243,35 @@ i[34567]86-*-adros*)\ step "Patched libgcc/config.host" fi + # GCC prerequisites (GMP, MPFR, MPC, ISL) — patch config.sub for adros + # These are only present if contrib/download_prerequisites was run. + for sub in \ + "$d/gmp/configfsf.sub" \ + "$d/mpfr-*/config.sub" \ + "$d/mpc-*/build-aux/config.sub" \ + "$d/isl-*/config.sub"; do + # Expand glob + for f in $sub; do + [[ -f "$f" ]] || continue + if ! grep -q 'adros' "$f"; then + # GMP uses configfsf.sub with a different format + if [[ "$f" == *"configfsf.sub" ]]; then + sed -i 's/| nsk\* | powerunix\* | genode\* | zvmoe\* | qnx\* | emx\* \\$/\| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* \\\n\t | adros*)/' "$f" + else + sed -i 's/| -midnightbsd\*)/| -midnightbsd* | -adros*)/' "$f" + sed -i 's/| nsk\* | powerunix\*)/| nsk* | powerunix* | adros*)/' "$f" + fi + step "Patched $(echo "$f" | sed "s|$d/||") for adros" + fi + done + done + + # Remove libcody from host_libs (requires C++ host compiler, breaks Canadian cross) + if grep -q 'libcody' "$d/configure" 2>/dev/null; then + sed -i 's/ libcody / /' "$d/configure" + step "Removed libcody from GCC host_libs" + fi + # crti.S and crtn.S for AdrOS if [[ ! -f "$d/libgcc/config/i386/crti-adros.S" ]]; then cat > "$d/libgcc/config/i386/crti-adros.S" <<'EOF' diff --git a/toolchain/patches/native-toolchain.patch b/toolchain/patches/native-toolchain.patch new file mode 100644 index 0000000..41127eb --- /dev/null +++ b/toolchain/patches/native-toolchain.patch @@ -0,0 +1,65 @@ +Native Toolchain Patches for AdrOS +==================================== +These patches are needed when building a native GCC/Binutils toolchain +for AdrOS (Canadian cross: build=x86_64-linux, host=i686-adros, target=i686-adros). + +They are applied automatically by build.sh patch functions. + +1. GMP configfsf.sub — add adros* to recognized OS list +------------------------------------------------------- +--- a/gmp/configfsf.sub ++++ b/gmp/configfsf.sub +@@ -1722,7 +1722,8 @@ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* \ +- ) ++ | adros*) + ;; + +2. MPFR config.sub — add -adros* to recognized OS list +------------------------------------------------------- +--- a/mpfr-4.1.0/config.sub ++++ b/mpfr-4.1.0/config.sub +@@ -1392,7 +1392,7 @@ +- | -midnightbsd*) ++ | -midnightbsd* | -adros*) + +3. MPC config.sub — add adros* to recognized OS list +----------------------------------------------------- +--- a/mpc-1.2.1/build-aux/config.sub ++++ b/mpc-1.2.1/build-aux/config.sub +@@ -1368,7 +1368,7 @@ +- | nsk* | powerunix*) ++ | nsk* | powerunix* | adros*) + +4. ISL config.sub — add -adros* to recognized OS list +------------------------------------------------------ +--- a/isl-0.24/config.sub ++++ b/isl-0.24/config.sub +@@ -1392,7 +1392,7 @@ +- | -midnightbsd*) ++ | -midnightbsd* | -adros*) + +5. GCC configure — remove libcody from host_libs +------------------------------------------------- +libcody requires a C++ compiler for the host, which fails during +Canadian cross compilation. Removing it from host_libs avoids this. + +--- a/configure ++++ b/configure +@@ host_libs line +-host_libs="... libcody ..." ++host_libs="... ..." (libcody removed) + +6. Binutils gas/config/tc-i386.c — fix type mismatch +----------------------------------------------------- +The declaration in tc-i386.h uses uint32_t but the definition +used unsigned int, causing a type mismatch error with strict +cross-compilers. + +--- a/gas/config/tc-i386.c ++++ b/gas/config/tc-i386.c +@@ -5340,7 +5340,7 @@ + bool +-x86_scfi_callee_saved_p (unsigned int dw2reg_num) ++x86_scfi_callee_saved_p (uint32_t dw2reg_num) + {