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;
+}
#include <sys/types.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define MAXNAMLEN 255
struct dirent {
int closedir(DIR *);
void rewinddir(DIR *);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _SYS_DIRENT_H */
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* Minimal ioctl definitions for AdrOS */
#define TIOCGPGRP 0x540F
#define TIOCSPGRP 0x5410
int ioctl(int fd, unsigned long request, ...);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _SYS_IOCTL_H */
#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
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
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"
}
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'
--- /dev/null
+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)
+ {