]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
toolchain: native GCC/Binutils Canadian cross build support
authorTulio A M Mendes <[email protected]>
Sat, 14 Mar 2026 11:11:46 +0000 (08:11 -0300)
committerTulio A M Mendes <[email protected]>
Sat, 14 Mar 2026 11:11:46 +0000 (08:11 -0300)
- 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)

newlib/libgloss/adros/posix_compat.c
newlib/sysroot_headers/sys/dirent.h
newlib/sysroot_headers/sys/ioctl.h
newlib/sysroot_headers/sys/mman.h
toolchain/build.sh
toolchain/patches/native-toolchain.patch [new file with mode: 0644]

index 5c5c7b5ee2bc1209109229d71650b8ea762db576..8a0f4d8676711acaf670de0ba71121784adabc53 100644 (file)
@@ -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 <dlfcn.h>
+
+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 <stdarg.h>
+int ioctl(int fd, unsigned long request, ...)
+{
+    (void)fd;
+    (void)request;
+    errno = ENOSYS;
+    return -1;
+}
+
+/* ---- ftw / nftw stubs ---- */
+#include <ftw.h>
+
+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;
+}
index 1b57a23f8737bd2ebb7bef212f8b8f9257b78a36..2f92e3b7d97183a5c3805b89e178a5a20259afa6 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <sys/types.h>
 
+#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 */
index 81e8177d083ee5303477f9d7e95c2136b57a3ce1..45cca6f49f773dca3263609d9aeae0b4d796e9cc 100644 (file)
@@ -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 */
index 47b6b969cc3267afe050d8dc6007ca422df013bb..ba7963616031eadc7978022c6ef043ec35e75d93 100644 (file)
@@ -1,6 +1,11 @@
 #ifndef _SYS_MMAN_H
 #define _SYS_MMAN_H
 #include <sys/types.h>
+
+#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
index 76b3ba17f74908fcb443b62bc99d30921aad959e..f61390903b08bc5fd45581698e797e41e27d193f 100755 (executable)
@@ -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 (file)
index 0000000..41127eb
--- /dev/null
@@ -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)
+ {