From 9d347c0acbeddaf349857384701975e997ffc583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Barto=C5=88?= Date: Mon, 18 Mar 2024 23:04:37 +0100 Subject: [PATCH] Add `aarch64-pc-cygwin` target to `advanced.yml` --- .github/scripts/binutils/build.sh | 13 +- .github/scripts/binutils/patch-cygwin.sh | 6 + .github/scripts/config.sh | 6 +- .github/scripts/install-dependencies.sh | 2 +- .github/scripts/tests/build.sh | 4 +- .github/scripts/toolchain/build-mingw-crt.sh | 2 + .github/scripts/toolchain/patch-cygwin.sh | 30 +- .github/workflows/advanced.yml | 5 +- .github/workflows/variants.yml | 2 - patches/binutils/0001-aarch64-cygwin.patch | 160 ++ patches/cygwin/0001-before-autogen.patch | 4 +- patches/cygwin/0002-after-autogen.patch | 2 +- patches/cygwin/0004-aarch64-cygwin.patch | 2617 ++++++++++++++++++ patches/gcc/0001-aarch64-cygwin.patch | 455 +++ patches/gcc/0002-cygming-extern.patch | 125 + patches/mingw/0001-aarch64-cygwin.patch | 26 + return-zero/.gitignore | 6 + return-zero/build.sh | 29 + return-zero/return-zero.c | 3 + scripts/find_symbol.py | 58 + update.sh | 50 + 21 files changed, 3588 insertions(+), 17 deletions(-) create mode 100644 patches/binutils/0001-aarch64-cygwin.patch create mode 100644 patches/cygwin/0004-aarch64-cygwin.patch create mode 100644 patches/gcc/0001-aarch64-cygwin.patch create mode 100644 patches/gcc/0002-cygming-extern.patch create mode 100644 patches/mingw/0001-aarch64-cygwin.patch create mode 100644 return-zero/.gitignore create mode 100755 return-zero/build.sh create mode 100644 return-zero/return-zero.c create mode 100755 scripts/find_symbol.py create mode 100755 update.sh diff --git a/.github/scripts/binutils/build.sh b/.github/scripts/binutils/build.sh index 42e28442c..9d0411925 100755 --- a/.github/scripts/binutils/build.sh +++ b/.github/scripts/binutils/build.sh @@ -25,7 +25,6 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$BINUTILS_BUILD_PATH/Makefile" ] ; then --enable-host-shared \ --enable-64-bit-bfd \ --enable-install-libiberty \ - --enable-targets=x86_64-pep \ --with-sysroot=$TOOLCHAIN_PATH \ --with-build-sysroot=$TOOLCHAIN_PATH \ --with-system-zlib \ @@ -42,6 +41,18 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$BINUTILS_BUILD_PATH/Makefile" ] ; then ;; esac + case "$ARCH-$PLATFORM" in + x86_64-*cygwin*) + TARGET_OPTIONS="$TARGET_OPTIONS \ + --enable-targets=x86_64-pep" + ;; + aarch64-*cygwin*) + TARGET_OPTIONS="$TARGET_OPTIONS \ + --enable-targets=aarch64-pep \ + --disable-sim" + ;; + esac + $SOURCE_PATH/$BINUTILS_VERSION/configure \ --prefix=$TOOLCHAIN_PATH \ --build=$BUILD \ diff --git a/.github/scripts/binutils/patch-cygwin.sh b/.github/scripts/binutils/patch-cygwin.sh index 35cf15db6..e751b5b2b 100755 --- a/.github/scripts/binutils/patch-cygwin.sh +++ b/.github/scripts/binutils/patch-cygwin.sh @@ -13,6 +13,12 @@ echo "::group::Patch Cygwin binutils" patch -p2 -i $PATCH_DIR/binutils-2.42-cygwin-config-rpath.patch patch -p2 -i $PATCH_DIR/binutils-2.42-cygwin-pep-dll-double-definition.patch + + case "$ARCH" in + aarch64) + patch -p1 -i $PATCHES_PATH/binutils/0001-aarch64-cygwin.patch + ;; + esac echo "::endgroup::" echo 'Success!' diff --git a/.github/scripts/config.sh b/.github/scripts/config.sh index 67da28024..b08d2b703 100644 --- a/.github/scripts/config.sh +++ b/.github/scripts/config.sh @@ -17,14 +17,14 @@ LIBJPEG_TURBO_VERSION=${LIBJPEG_TURBO_VERSION:-libjpeg-turbo-main} FFMPEG_VERSION=${FFMPEG_VERSION:-ffmpeg-master} ARCH=${ARCH:-aarch64} -PLATFORM=${PLATFORM:-w64-mingw32} +PLATFORM=${PLATFORM:-pc-cygwin} if [[ "$PLATFORM" =~ (mingw|cygwin) ]]; then CRT=${CRT:-msvcrt} else CRT=${CRT:-libc} fi -BUILD=x86_64-pc-linux-gnu -HOST=x86_64-pc-linux-gnu +BUILD=`gcc -dumpmachine` +HOST=`gcc -dumpmachine` TARGET=$ARCH-$PLATFORM TOOLCHAIN_NAME=${TOOLCHAIN_NAME:-$ARCH-$PLATFORM-$CRT} diff --git a/.github/scripts/install-dependencies.sh b/.github/scripts/install-dependencies.sh index 6d9541d33..26bb32737 100755 --- a/.github/scripts/install-dependencies.sh +++ b/.github/scripts/install-dependencies.sh @@ -4,7 +4,7 @@ source `dirname ${BASH_SOURCE[0]}`/config.sh echo "::group::Install Dependencies" sudo apt update - sudo apt install -y build-essential binutils-for-build texinfo bison flex ccache docbook2x xmlto zlib1g-dev libgmp-dev libmpc-dev libc6-dev-arm64-cross libc6-dev-amd64-cross libisl-dev dejagnu + sudo apt install -y autoconf automake build-essential binutils-for-build texinfo bison flex ccache docbook2x xmlto zlib1g-dev libgmp-dev libmpc-dev libc6-dev-arm64-cross libc6-dev-amd64-cross libisl-dev dejagnu echo "::endgroup::" echo 'Success!' diff --git a/.github/scripts/tests/build.sh b/.github/scripts/tests/build.sh index a5a228f36..f5880f951 100755 --- a/.github/scripts/tests/build.sh +++ b/.github/scripts/tests/build.sh @@ -15,7 +15,7 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f build/CMakeCache.txt ] ; then fi echo "::group::Build tests" - cmake --build build + cmake --build build ${BUILD_MAKE_OPTIONS//V=1/-v} case "$PLATFORM" in w64-mingw32) @@ -24,7 +24,7 @@ echo "::group::Build tests" pc-cygwin) cp $TOOLCHAIN_PATH/bin/cygwin1.dll build/bin cp $TOOLCHAIN_PATH/lib/gcc/$TARGET/cyggcc_s-seh-1.dll build/bin - cp $TOOLCHAIN_PATH/lib/gcc/$TARGET/14/cyggomp-1.dll build/bin + cp $TOOLCHAIN_PATH/lib/gcc/$TARGET/14/cyggomp-1.dll build/bin && true ;; esac echo "::endgroup::" diff --git a/.github/scripts/toolchain/build-mingw-crt.sh b/.github/scripts/toolchain/build-mingw-crt.sh index ec9a76951..25c7862b5 100755 --- a/.github/scripts/toolchain/build-mingw-crt.sh +++ b/.github/scripts/toolchain/build-mingw-crt.sh @@ -91,6 +91,8 @@ if [ "$RUN_INSTALL" = 1 ] ; then ln -fs w32api/libuserenv.a . ln -fs w32api/libnetapi32.a . ln -fs w32api/libdbghelp.a . + ln -fs w32api/libonecore.a . + ln -fs w32api/libpdh.a . popd ;; esac diff --git a/.github/scripts/toolchain/patch-cygwin.sh b/.github/scripts/toolchain/patch-cygwin.sh index a5ebf7c6e..37fb38eab 100755 --- a/.github/scripts/toolchain/patch-cygwin.sh +++ b/.github/scripts/toolchain/patch-cygwin.sh @@ -23,6 +23,26 @@ echo "::group::Patch Cygwin GCC" patch -p1 -i $PATCH_DIR/0011-Cygwin-define-STD_UNIX.patch patch -p1 -i $PATCH_DIR/0101-Cygwin-enable-libgccjit-not-just-for-MingW.patch patch -p1 -i $PATCH_DIR/0102-Cygwin-testsuite-fixes-for-libgccjit.patch + + case "$ARCH" in + aarch64) + patch -p1 -i $PATCHES_PATH/gcc/0001-aarch64-cygwin.patch + patch -p1 -i $PATCHES_PATH/gcc/0002-cygming-extern.patch + ;; + esac +echo "::endgroup::" + +echo echo "::group::Patch MinGW" + cd $SOURCE_PATH/$MINGW_VERSION + + git reset --hard + git clean -fdx + + case "$ARCH" in + aarch64) + patch -p1 -i $PATCHES_PATH/mingw/0001-aarch64-cygwin.patch + ;; + esac echo "::endgroup::" echo "::group::Patch Cygwin" @@ -36,13 +56,19 @@ echo "::group::Patch Cygwin" patch -p1 -i $PATCH_DIR/0001-before-autogen.patch fi + patch -p1 -i $PATCHES_PATH/cygwin/0003-master.patch + + case "$ARCH" in + aarch64) + patch -p1 -i $PATCHES_PATH/cygwin/0004-aarch64-cygwin.patch + ;; + esac + (cd winsup && ./autogen.sh) if [ "$STAGE" = "1" ]; then patch -p1 -i $PATCH_DIR/0002-after-autogen.patch fi - - patch -p1 -i $PATCHES_PATH/cygwin/0003-master.patch echo "::endgroup::" echo 'Success!' diff --git a/.github/workflows/advanced.yml b/.github/workflows/advanced.yml index e384d96da..698bed537 100644 --- a/.github/workflows/advanced.yml +++ b/.github/workflows/advanced.yml @@ -91,13 +91,12 @@ env: TOOLCHAIN_PATH: ${{ github.workspace }}/cross TOOLCHAIN_NAME: ${{ inputs.arch }}-${{ inputs.platform }}-${{ inputs.crt }} TOOLCHAIN_PACKAGE_NAME: ${{ inputs.arch }}-${{ inputs.platform }}-${{ inputs.crt }}-toolchain.tar.gz - - TESTS_PACKAGE_NAME: ${{ inputs.arch }}-${{ inputs.crt }}-tests.tar.gz + TESTS_PACKAGE_NAME: ${{ inputs.arch }}-${{ inputs.platform }}-${{ inputs.crt }}-tests.tar.gz SOURCE_PATH: ${{ github.workspace }}/code ARTIFACT_PATH: ${{ github.workspace }}/artifact - TEST_TOOLCHAIN: ${{ (inputs.arch == 'aarch64' && inputs.platform == 'w64-mingw32' && inputs.crt == 'msvcrt') || (inputs.arch == 'x86_64' && inputs.platform == 'pc-cygwin') }} + TEST_TOOLCHAIN: ${{ (inputs.arch == 'aarch64' && inputs.platform == 'w64-mingw32' && inputs.crt == 'msvcrt') || inputs.platform == 'pc-cygwin' }} TEST_PACKAGES: ${{ inputs.arch == 'aarch64' && inputs.platform == 'w64-mingw32' && inputs.crt == 'msvcrt' }} jobs: diff --git a/.github/workflows/variants.yml b/.github/workflows/variants.yml index ecfe7a70b..a3ec28727 100644 --- a/.github/workflows/variants.yml +++ b/.github/workflows/variants.yml @@ -77,8 +77,6 @@ jobs: crt: ucrt - platform: pc-cygwin crt: libc - - platform: pc-cygwin - arch: aarch64 uses: ./.github/workflows/advanced.yml with: diff --git a/patches/binutils/0001-aarch64-cygwin.patch b/patches/binutils/0001-aarch64-cygwin.patch new file mode 100644 index 000000000..d521e7a03 --- /dev/null +++ b/patches/binutils/0001-aarch64-cygwin.patch @@ -0,0 +1,160 @@ +diff --git a/bfd/config.bfd b/bfd/config.bfd +index 6553aac1e99d..c3be7e0fe585 100644 +--- a/bfd/config.bfd ++++ b/bfd/config.bfd +@@ -248,7 +248,7 @@ case "${targ}" in + targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec aarch64_pei_le_vec aarch64_pe_le_vec" + want64=true + ;; +- aarch64-*-pe* | aarch64-*-mingw*) ++ aarch64-*-pe* | aarch64-*-mingw* | aarch64-*-cygwin*) + targ_defvec=aarch64_pe_le_vec + targ_selvecs="aarch64_pe_le_vec aarch64_pei_le_vec aarch64_elf64_le_vec aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec pdb_vec" + want64=true +diff --git a/binutils/configure b/binutils/configure +index 2b9f52720c3e..654476cd2e1d 100755 +--- a/binutils/configure ++++ b/binutils/configure +@@ -16426,7 +16426,7 @@ do + esac + + case $targ in +- aarch64-*-mingw*) ++ aarch64-*-mingw* | aarch64-*-cygwin*) + BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)' + if test -z "$DLLTOOL_DEFAULT"; then + DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_AARCH64" +diff --git a/binutils/configure.ac b/binutils/configure.ac +index dac72c1bdd4d..28a51bdd7e93 100644 +--- a/binutils/configure.ac ++++ b/binutils/configure.ac +@@ -369,7 +369,7 @@ changequote([,])dnl + esac + + case $targ in +- aarch64-*-mingw*) ++ aarch64-*-mingw*| aarch64-*-cygwin* ) + BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)' + if test -z "$DLLTOOL_DEFAULT"; then + DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_AARCH64" +diff --git a/config.guess b/config.guess +index cdfc4392047c..91a44145ed1a 100755 +--- a/config.guess ++++ b/config.guess +@@ -951,6 +951,9 @@ EOF + i*:UWIN*:*) + GUESS=$UNAME_MACHINE-pc-uwin + ;; ++ aarch64:CYGWIN*:*:*) ++ GUESS=aarch64-pc-cygwin ++ ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + GUESS=x86_64-pc-cygwin + ;; +diff --git a/gas/configure.tgt b/gas/configure.tgt +index 7c66734e362b..94fa2407f416 100644 +--- a/gas/configure.tgt ++++ b/gas/configure.tgt +@@ -138,7 +138,7 @@ case ${generic_target} in + aarch64*-*-netbsd*) fmt=elf em=nbsd;; + aarch64*-*-nto*) fmt=elf;; + aarch64*-*-openbsd*) fmt=elf;; +- aarch64*-*-pe* | aarch64*-*-mingw*) fmt=coff em=pepaarch64 ;; ++ aarch64*-*-pe* | aarch64*-*-mingw* | aarch64*-*-cygwin*) fmt=coff em=pepaarch64 ;; + alpha-*-*vms*) fmt=evax ;; + alpha-*-osf*) fmt=ecoff ;; + alpha-*-linux*ecoff*) fmt=ecoff ;; +diff --git a/gdb/configure.host b/gdb/configure.host +index da71675b201b..05debc74ab3c 100644 +--- a/gdb/configure.host ++++ b/gdb/configure.host +@@ -81,6 +81,7 @@ case "${host}" in + + aarch64*-*-linux*) gdb_host=linux ;; + aarch64*-*-freebsd*) gdb_host=fbsd ;; ++aarch64*-*-cygwin*) gdb_host=cygwin64 ;; + + alpha*-*-linux*) gdb_host=alpha-linux ;; + alpha*-*-netbsdaout* | alpha*-*-knetbsdaout*-gnu) +diff --git a/gdbserver/configure.srv b/gdbserver/configure.srv +index 9e861a75088a..c986da39f051 100644 +--- a/gdbserver/configure.srv ++++ b/gdbserver/configure.srv +@@ -66,6 +66,13 @@ case "${gdbserver_host}" in + srv_tgtobj="${srv_tgtobj} nat/netbsd-nat.o" + srv_tgtobj="${srv_tgtobj} arch/aarch64-insn.o arch/aarch64.o" + ;; ++ aarch64-*-cygwin*) srv_regobj="" ++ srv_tgtobj="aarch64-low.o nat/aarch64-dregs.o" ++ srv_tgtobj="${srv_tgtobj} nat/aarch64-xstate.o aarch64-fp.o" ++ srv_tgtobj="${srv_tgtobj} win32-low.o win32-aarch64-low.o" ++ srv_tgtobj="${srv_tgtobj} nat/windows-nat.o" ++ srv_tgtobj="${srv_tgtobj} arch/aarch64.o" ++ ;; + arc*-*-linux*) + srv_regobj="" + srv_tgtobj="linux-arc-low.o arch/arc.o $srv_linux_obj" +diff --git a/ld/configure.tgt b/ld/configure.tgt +index 27b63e5112ad..f6a5d0feab9e 100644 +--- a/ld/configure.tgt ++++ b/ld/configure.tgt +@@ -127,7 +127,7 @@ aarch64-*-haiku*) targ_emul=aarch64haiku + aarch64-*-nto*) targ_emul=aarch64nto + targ_extra_emuls="aarch64elf aarch64elf32 aarch64elf32b aarch64elfb armelf armelfb" + ;; +-aarch64-*-pe* | aarch64-*-mingw*) ++aarch64-*-pe* | aarch64-*-mingw* | aarch64-*-cygwin*) + targ_emul=aarch64pe + targ_extra_emuls=arm64pe + targ_extra_ofiles="deffilep.o pep-dll-aarch64.o pe-dll.o pdb.o" +@@ -1145,7 +1145,7 @@ spu-*-elf*) + NATIVE_LIB_DIRS='/lib' + ;; + +-i[03-9x]86-*-cygwin* | x86_64-*-cygwin*) ++aarch64-*-cygwin* | i[03-9x]86-*-cygwin* | x86_64-*-cygwin*) + NATIVE_LIB_DIRS='/usr/lib /usr/lib/w32api' + ;; + +diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em +index 9ab5e6ef481c..0a2ff3f7fb48 100644 +--- a/ld/emultempl/pe.em ++++ b/ld/emultempl/pe.em +@@ -69,6 +69,7 @@ fragment < /* floating point macros */ + #include /* POSIX defs */ + +-#ifdef __aarch64__ +-#define MALLOC_ALIGNMENT 16 +-#endif +- + #ifdef __AMDGCN__ + #define __DYNAMIC_REENT__ + #endif +diff --git a/newlib/libc/machine/aarch64/asmdefs.h b/newlib/libc/machine/aarch64/asmdefs.h +index 131b95e1f..da1df3da6 100644 +--- a/newlib/libc/machine/aarch64/asmdefs.h ++++ b/newlib/libc/machine/aarch64/asmdefs.h +@@ -59,9 +59,19 @@ + GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC) + #endif + ++#ifdef __ELF__ ++#define HIDDEN(name) .hidden name ++#define SYMBOL_SIZE(name) .size name, .-name ++#define SYMBOL_TYPE(name, _type) .type name, _type ++#else ++#define HIDDEN(name) ++#define SYMBOL_SIZE(name) ++#define SYMBOL_TYPE(name, _type) ++#endif ++ + #define ENTRY_ALIGN(name, alignment) \ + .global name; \ +- .type name,%function; \ ++ SYMBOL_TYPE(name, %function); \ + .align alignment; \ + name: \ + .cfi_startproc; \ +@@ -70,13 +80,13 @@ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC) + #define ENTRY(name) ENTRY_ALIGN(name, 6) + + #define ENTRY_ALIAS(name) \ +- .global name; \ +- .type name,%function; \ ++ .global name; \ ++ SYMBOL_TYPE(name, %function); \ + name: + + #define END(name) \ + .cfi_endproc; \ +- .size name, .-name; ++ SYMBOL_SIZE(name); + + #define L(l) .L ## l + +diff --git a/newlib/libc/machine/aarch64/machine/fenv-fp.h b/newlib/libc/machine/aarch64/machine/fenv-fp.h +index d8ec3fc76..6404351cd 100644 +--- a/newlib/libc/machine/aarch64/machine/fenv-fp.h ++++ b/newlib/libc/machine/aarch64/machine/fenv-fp.h +@@ -26,6 +26,36 @@ + * $FreeBSD$ + */ + ++__fenv_static __inline int ++fedisableexcept(int __mask) ++{ ++ fenv_t __old_r, __new_r; ++ ++ __mrs_fpcr(__old_r); ++ __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); ++ __msr_fpcr(__new_r); ++ return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); ++} ++ ++__fenv_static __inline int ++feenableexcept(int __mask) ++{ ++ fenv_t __old_r, __new_r; ++ ++ __mrs_fpcr(__old_r); ++ __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); ++ __msr_fpcr(__new_r); ++ return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); ++} ++ ++__fenv_static __inline int ++fegetexcept(void) ++{ ++ fenv_t __r; ++ ++ __mrs_fpcr(__r); ++ return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT); ++} + + __fenv_static __inline int + feclearexcept(int __excepts) +diff --git a/newlib/libc/machine/aarch64/rawmemchr.S b/newlib/libc/machine/aarch64/rawmemchr.S +index 26da81005..97374282e 100644 +--- a/newlib/libc/machine/aarch64/rawmemchr.S ++++ b/newlib/libc/machine/aarch64/rawmemchr.S +@@ -34,13 +34,15 @@ + /* See rawmemchr-stub.c. */ + #else + ++#include "asmdefs.h" ++ + #define L(l) .L ## l + + .macro def_fn f p2align=0 + .text + .p2align \p2align + .global \f +- .type \f, %function ++ SYMBOL_TYPE(\f, %function) + \f: + .endm + +@@ -63,6 +65,6 @@ L(do_strlen): + ret x15 + .cfi_endproc + +- .size rawmemchr, . - rawmemchr ++ SYMBOL_SIZE(rawmemchr) + #endif + +diff --git a/newlib/libc/machine/aarch64/setjmp.S b/newlib/libc/machine/aarch64/setjmp.S +index 0856145bf..bba8d668a 100644 +--- a/newlib/libc/machine/aarch64/setjmp.S ++++ b/newlib/libc/machine/aarch64/setjmp.S +@@ -26,6 +26,8 @@ + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + ++#include "asmdefs.h" ++ + #define GPR_LAYOUT \ + REG_PAIR (x19, x20, 0); \ + REG_PAIR (x21, x22, 16); \ +@@ -43,7 +45,7 @@ + + // int setjmp (jmp_buf) + .global setjmp +- .type setjmp, %function ++ SYMBOL_TYPE(setjmp, %function) + setjmp: + mov x16, sp + #define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS] +@@ -54,11 +56,11 @@ setjmp: + #undef REG_ONE + mov w0, #0 + ret +- .size setjmp, .-setjmp ++ SYMBOL_SIZE(setjmp) + + // void longjmp (jmp_buf, int) __attribute__ ((noreturn)) + .global longjmp +- .type longjmp, %function ++ SYMBOL_TYPE(longjmp, %function) + longjmp: + #define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS] + #define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS] +@@ -71,4 +73,4 @@ longjmp: + cinc w0, w1, eq + // use br not ret, as ret is guaranteed to mispredict + br x30 +- .size longjmp, .-longjmp ++ SYMBOL_SIZE(longjmp) +diff --git a/newlib/libc/machine/aarch64/sys/fenv.h b/newlib/libc/machine/aarch64/sys/fenv.h +index 6b0879269..793b88b52 100644 +--- a/newlib/libc/machine/aarch64/sys/fenv.h ++++ b/newlib/libc/machine/aarch64/sys/fenv.h +@@ -61,7 +61,14 @@ typedef __uint64_t fexcept_t; + FE_UPWARD | FE_TOWARDZERO) + #define _ROUND_SHIFT 22 + +- ++/* Only Solaris and QNX implement fegetprec/fesetprec. As Solaris, use the ++ values defined by http://www.open-std.org/jtc1/sc22//WG14/www/docs/n752.htm ++ QNX defines different values. */ ++#if __MISC_VISIBLE ++#define FE_FLTPREC (0) ++#define FE_DBLPREC (2) ++#define FE_LDBLPREC (3) ++#endif + + /* Default floating-point environment */ + extern const fenv_t *_fe_dfl_env; +@@ -77,44 +84,18 @@ extern const fenv_t *_fe_dfl_env; + #define __mrs_fpsr(__r) __asm __volatile("mrs %0, fpsr" : "=r" (__r)) + #define __msr_fpsr(__r) __asm __volatile("msr fpsr, %0" : : "r" (__r)) + +- +-#if __BSD_VISIBLE +- +-/* We currently provide no external definitions of the functions below. */ +- +-static inline int +-feenableexcept(int __mask) +-{ +- fenv_t __old_r, __new_r; +- +- __mrs_fpcr(__old_r); +- __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); +- __msr_fpcr(__new_r); +- return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +-} +- +-static inline int +-fedisableexcept(int __mask) +-{ +- fenv_t __old_r, __new_r; +- +- __mrs_fpcr(__old_r); +- __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); +- __msr_fpcr(__new_r); +- return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +-} +- +-static inline int +-fegetexcept(void) +-{ +- fenv_t __r; +- +- __mrs_fpcr(__r); +- return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT); +-} +- +-#endif /* __BSD_VISIBLE */ +- +- ++#if __GNU_VISIBLE ++/* If possible, the GNU C Library defines a macro FE_NOMASK_ENV which ++ represents an environment where every exception raised causes a trap ++ to occur. You can test for this macro using #ifdef. It is only defined ++ if _GNU_SOURCE is defined. */ ++extern const fenv_t *_fe_nomask_env; ++#define FE_NOMASK_ENV (_fe_nomask_env) ++ ++/* These are GNU extensions defined in glibc. */ ++int feenableexcept (int __excepts); ++int fedisableexcept (int __excepts); ++int fegetexcept (void); ++#endif /* __GNU_VISIBLE */ + + #endif /* !_FENV_H_ */ +diff --git a/newlib/libm/machine/aarch64/fenv.c b/newlib/libm/machine/aarch64/fenv.c +index 3ffe23441..8c883e32d 100644 +--- a/newlib/libm/machine/aarch64/fenv.c ++++ b/newlib/libm/machine/aarch64/fenv.c +@@ -55,3 +55,68 @@ extern inline int feupdateenv(const fenv_t *__envp); + extern inline int feenableexcept(int __mask); + extern inline int fedisableexcept(int __mask); + extern inline int fegetexcept(void); ++ ++/* These are writable so we can initialise them at startup. */ ++static fenv_t fe_nomask_env; ++ ++/* These pointers provide the outside world with read-only access to them. */ ++const fenv_t *_fe_nomask_env = &fe_nomask_env; ++ ++/* Mask and shift amount for precision bits. */ ++#define FE_CW_PREC_MASK (0x0300) ++#define FE_CW_PREC_SHIFT (8) ++ ++/* Returns the currently selected precision, represented by one of the ++ values of the defined precision macros. */ ++int ++fegetprec (void) ++{ ++ unsigned short cw; ++ ++ /* Get control word. */ ++ // TODO ++ //__asm__ volatile ("fnstcw %0" : "=m" (cw) : ); ++ ++ return (cw & FE_CW_PREC_MASK) >> FE_CW_PREC_SHIFT; ++} ++ ++/* http://www.open-std.org/jtc1/sc22//WG14/www/docs/n752.htm: ++ ++ The fesetprec function establishes the precision represented by its ++ argument prec. If the argument does not match a precision macro, the ++ precision is not changed. ++ ++ The fesetprec function returns a nonzero value if and only if the ++ argument matches a precision macro (that is, if and only if the requested ++ precision can be established). */ ++int ++fesetprec (int prec) ++{ ++ unsigned short cw; ++ ++ /* Will succeed for any valid value of the input parameter. */ ++ switch (prec) ++ { ++ case FE_FLTPREC: ++ case FE_DBLPREC: ++ case FE_LDBLPREC: ++ break; ++ default: ++ return 0; ++ } ++ ++ /* Get control word. */ ++ // TODO ++ //__asm__ volatile ("fnstcw %0" : "=m" (cw) : ); ++ ++ /* Twiddle bits. */ ++ cw &= ~FE_CW_PREC_MASK; ++ cw |= (prec << FE_CW_PREC_SHIFT); ++ ++ /* Set back into FPU state. */ ++ // TODO ++ //__asm__ volatile ("fldcw %0" :: "m" (cw)); ++ ++ /* Indicate success. */ ++ return 1; ++} +diff --git a/winsup/configure.ac b/winsup/configure.ac +index 9b9b59dbc..18adf3d97 100644 +--- a/winsup/configure.ac ++++ b/winsup/configure.ac +@@ -69,12 +69,14 @@ DLL_ENTRY="dll_entry" + + case "$target_cpu" in + x86_64) ;; ++ aarch64) ;; + *) AC_MSG_ERROR([Invalid target processor "$target_cpu"]) ;; + esac + + AC_SUBST(DLL_ENTRY) + + AM_CONDITIONAL(TARGET_X86_64, [test $target_cpu = "x86_64"]) ++AM_CONDITIONAL(TARGET_AARCH64, [test $target_cpu = "aarch64"]) + + AC_ARG_ENABLE(doc, + [AS_HELP_STRING([--disable-doc], [do not build documentation])],, +diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am +index 376c79fc3..6c696e2d6 100644 +--- a/winsup/cygwin/Makefile.am ++++ b/winsup/cygwin/Makefile.am +@@ -16,6 +16,9 @@ COMMON_CFLAGS=-Wimplicit-fallthrough=5 -Werror -fmerge-constants -ftracer + if TARGET_X86_64 + COMMON_CFLAGS+=-mcmodel=small + endif ++if TARGET_AARCH64 ++COMMON_CFLAGS+=-mcmodel=small ++endif + + AM_CFLAGS=$(cflags_common) $(COMMON_CFLAGS) + AM_CXXFLAGS=$(cxxflags_common) $(COMMON_CFLAGS) -fno-threadsafe-statics +@@ -63,6 +66,20 @@ TARGET_FILES= \ + x86_64/wmempcpy.S + endif + ++if TARGET_AARCH64 ++TARGET_FILES= \ ++ aarch64/bcopy.S \ ++ aarch64/memchr.S \ ++ aarch64/memcpy.S \ ++ aarch64/memmove.S \ ++ aarch64/mempcpy.S \ ++ aarch64/memset.S \ ++ aarch64/swab.S \ ++ aarch64/wmemcpy.S \ ++ aarch64/wmemmove.S \ ++ aarch64/wmempcpy.S ++endif ++ + LIB_FILES= \ + lib/_cygwin_crt0_common.cc \ + lib/atexit.c \ +@@ -598,7 +615,6 @@ $(LDSCRIPT): $(LDSCRIPT).in + $(NEW_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\ + $(newlib_build)/libm.a $(newlib_build)/libc.a + $(AM_V_CXXLD)$(CXX) $(CXXFLAGS) \ +- -mno-use-libstdc-wrappers \ + -Wl,--gc-sections -nostdlib -Wl,-T$(LDSCRIPT) \ + -Wl,--dynamicbase -static \ + $${SOURCE_DATE_EPOCH:+-Wl,--no-insert-timestamp} \ +@@ -609,7 +625,7 @@ $(NEW_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\ + $(LIBSERVER) \ + $(newlib_build)/libm.a \ + $(newlib_build)/libc.a \ +- -lgcc -lkernel32 -lntdll -Wl,-Map,cygwin.map ++ -lgcc -luser32 -lkernel32 -lonecore -lpdh -lntdll -Wl,-Map,cygwin.map + @$(MKDIR_P) ${target_builddir}/winsup/testsuite/testinst/bin/ + $(AM_V_at)$(INSTALL_PROGRAM) $(NEW_DLL_NAME) ${target_builddir}/winsup/testsuite/testinst/bin/$(DLL_NAME) + +diff --git a/winsup/cygwin/aarch64/bcopy.S b/winsup/cygwin/aarch64/bcopy.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/memchr.S b/winsup/cygwin/aarch64/memchr.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/memcpy.S b/winsup/cygwin/aarch64/memcpy.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/memmove.S b/winsup/cygwin/aarch64/memmove.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/mempcpy.S b/winsup/cygwin/aarch64/mempcpy.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/memset.S b/winsup/cygwin/aarch64/memset.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/swab.S b/winsup/cygwin/aarch64/swab.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/wmemcpy.S b/winsup/cygwin/aarch64/wmemcpy.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/wmemmove.S b/winsup/cygwin/aarch64/wmemmove.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/aarch64/wmempcpy.S b/winsup/cygwin/aarch64/wmempcpy.S +new file mode 100644 +index 000000000..e69de29bb +diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc +index c262c7efb..b5bdbaa18 100644 +--- a/winsup/cygwin/autoload.cc ++++ b/winsup/cygwin/autoload.cc +@@ -67,7 +67,7 @@ bool NO_COPY wsock_started; + /* LoadDLLprime is used to prime the DLL info information, providing an + additional initialization routine to call prior to calling the first + function. */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) + #define LoadDLLprime(dllname, init_also, no_resolve_on_fork) __asm__ (" \n\ + .ifndef " #dllname "_primed \n\ + .section .data_cygwin_nocopy,\"w\" \n\ +@@ -83,6 +83,9 @@ bool NO_COPY wsock_started; + .set " #dllname "_primed, 1 \n\ + .endif \n\ + "); ++#elif defined(__aarch64__) ++ // TODO ++ #define LoadDLLprime(dllname, init_also, no_resolve_on_fork) __asm__ (""); + #else + #error unimplemented for this target + #endif +@@ -97,7 +100,7 @@ bool NO_COPY wsock_started; + LoadDLLfuncEx3(name, dllname, notimp, err, 0) + + /* Main DLL setup stuff. */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) + #define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \ + LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) \ + __asm__ (" \n\ +@@ -123,6 +126,10 @@ _win32_" #name ": \n\ + .asciz \"" #name "\" \n\ + .text \n\ + "); ++#elif defined(__aarch64__) ++#define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \ ++ // TODO ++ LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) __asm__ (""); + #else + #error unimplemented for this target + #endif +@@ -141,7 +148,7 @@ extern "C" void dll_chain () __asm__ ("dll_chain"); + + extern "C" { + +-#ifdef __x86_64__ ++#if defined(__x86_64__) + __asm__ (" \n\ + .section .rdata,\"r\" \n\ + msg1: \n\ +@@ -203,6 +210,8 @@ dll_chain: \n\ + push %rax # Restore 'return address' \n\ + jmp *%rdx # Jump to next init function \n\ + "); ++#elif defined(__aarch64__) ++ // TODO + #else + #error unimplemented for this target + #endif +@@ -260,7 +269,7 @@ dll_load (HANDLE& handle, PWCHAR name) + #define RETRY_COUNT 10 + + /* The standard DLL initialization routine. */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) + + /* On x86_64, we need assembler wrappers for std_dll_init and wsock_init. + In the x86_64 ABI it's no safe bet that frame[1] (aka 8(%rbp)) contains +@@ -300,6 +309,13 @@ _" #func ": \n\ + + INIT_WRAPPER (std_dll_init) + ++#elif defined(__aarch64__) ++ ++// TODO ++#define INIT_WRAPPER(func) __asm__ (""); ++ ++INIT_WRAPPER (std_dll_init) ++ + #else + #error unimplemented for this target + #endif +@@ -360,7 +376,7 @@ std_dll_init (struct func_info *func) + + /* Initialization function for winsock stuff. */ + +-#ifdef __x86_64__ ++#if defined(__x86_64__) || defined(__aarch64__) + /* See above comment preceeding std_dll_init. */ + INIT_WRAPPER (wsock_init) + #else +diff --git a/winsup/cygwin/create_posix_thread.cc b/winsup/cygwin/create_posix_thread.cc +index 8e06099e4..5ff5ad01b 100644 +--- a/winsup/cygwin/create_posix_thread.cc ++++ b/winsup/cygwin/create_posix_thread.cc +@@ -75,7 +75,7 @@ pthread_wrapper (PVOID arg) + /* Initialize new _cygtls. */ + _my_tls.init_thread (wrapper_arg.stackbase - __CYGTLS_PADSIZE__, + (DWORD (*)(void*, void*)) wrapper_arg.func); +-#ifdef __x86_64__ ++#if defined(__x86_64__) + __asm__ ("\n\ + leaq %[WRAPPER_ARG], %%rbx # Load &wrapper_arg into rbx \n\ + movq (%%rbx), %%r12 # Load thread func into r12 \n\ +@@ -99,6 +99,8 @@ pthread_wrapper (PVOID arg) + call *%%r12 # Call thread func \n" + : : [WRAPPER_ARG] "o" (wrapper_arg), + [CYGTLS] "i" (__CYGTLS_PADSIZE__)); ++#elif defined(__aarch64__) ++ // TODO + #else + #error unimplemented for this target + #endif +@@ -206,7 +208,7 @@ class thread_allocator + public: + thread_allocator () : current (THREAD_STORAGE_HIGH) + { +- alloc_func = wincap.has_extended_mem_api () ? &_alloc : &_alloc_old; ++ alloc_func = wincap.has_extended_mem_api () ? &thread_allocator::_alloc : &thread_allocator::_alloc_old; + } + PVOID alloc (SIZE_T size) + { +diff --git a/winsup/cygwin/cygwin.sc.in b/winsup/cygwin/cygwin.sc.in +index 69526f5d8..c7e36f34a 100644 +--- a/winsup/cygwin/cygwin.sc.in ++++ b/winsup/cygwin/cygwin.sc.in +@@ -1,6 +1,9 @@ + #ifdef __x86_64__ + OUTPUT_FORMAT(pei-x86-64) + SEARCH_DIR("/usr/x86_64-pc-cygwin/lib/w32api"); SEARCH_DIR("=/usr/lib/w32api"); ++#elif __aarch64__ ++OUTPUT_FORMAT(pei-aarch64-little) ++SEARCH_DIR("/usr/aarch64-pc-cygwin/lib/w32api"); SEARCH_DIR("=/usr/lib/w32api"); + #else + #error unimplemented for this target + #endif +diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc +index 7229377eb..8219a5dae 100644 +--- a/winsup/cygwin/dcrt0.cc ++++ b/winsup/cygwin/dcrt0.cc +@@ -1029,7 +1029,7 @@ _dll_crt0 () + PVOID stackaddr = create_new_main_thread_stack (allocationbase); + if (stackaddr) + { +-#ifdef __x86_64__ ++#if defined(__x86_64__) + /* Set stack pointer to new address. Set frame pointer to + stack pointer and subtract 32 bytes for shadow space. */ + __asm__ ("\n\ +@@ -1037,6 +1037,8 @@ _dll_crt0 () + movq %%rsp, %%rbp \n\ + subq $32,%%rsp \n" + : : [ADDR] "r" (stackaddr)); ++#elif defined(__aarch64__) ++ // TODO + #else + #error unimplemented for this target + #endif +diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc +index a2a6f9d4c..b0feecbf1 100644 +--- a/winsup/cygwin/exceptions.cc ++++ b/winsup/cygwin/exceptions.cc +@@ -28,25 +28,9 @@ details. */ + #include "ntdll.h" + #include "exception.h" + #include "posix_timer.h" ++#include "register.h" + #include "gcc_seh.h" + +-/* Define macros for CPU-agnostic register access. The _CX_foo +- macros are for access into CONTEXT, the _MC_foo ones for access into +- mcontext. The idea is to access the registers in terms of their job, +- not in terms of their name on the given target. */ +-#ifdef __x86_64__ +-#define _CX_instPtr Rip +-#define _CX_stackPtr Rsp +-#define _CX_framePtr Rbp +-/* For special register access inside mcontext. */ +-#define _MC_retReg rax +-#define _MC_instPtr rip +-#define _MC_stackPtr rsp +-#define _MC_uclinkReg rbx /* MUST be callee-saved reg */ +-#else +-#error unimplemented for this target +-#endif +- + #define CALL_HANDLER_RETRY_OUTER 10 + #define CALL_HANDLER_RETRY_INNER 10 + #define DUMPSTACK_FRAME_LIMIT 32 +@@ -230,7 +214,7 @@ cygwin_exception::dump_exception () + } + } + +-#ifdef __x86_64__ ++#if defined(__x86_64__) + if (exception_name) + small_printf ("Exception: %s at rip=%012X\r\n", exception_name, ctx->Rip); + else +@@ -250,6 +234,10 @@ cygwin_exception::dump_exception () + small_printf ("cs=%04x ds=%04x es=%04x fs=%04x gs=%04x ss=%04x\r\n", + ctx->SegCs, ctx->SegDs, ctx->SegEs, ctx->SegFs, + ctx->SegGs, ctx->SegSs); ++#elif defined(__aarch64__) ++ // TODO ++ if (exception_name) ++ small_printf ("Exception: %s at pc=%012X\r\n", exception_name, ctx->Pc); + #else + #error unimplemented for this target + #endif +@@ -1614,6 +1602,7 @@ done: + + } + ++#if defined(__x86_64__) + static void + altstack_wrapper (int sig, siginfo_t *siginfo, ucontext_t *sigctx, + void (*handler) (int, siginfo_t *, void *)) +@@ -1664,6 +1653,7 @@ altstack_wrapper (int sig, siginfo_t *siginfo, ucontext_t *sigctx, + teb->Tib.StackLimit = old_limit; + } + } ++#endif + + int + _cygtls::call_signal_handler () +@@ -1721,7 +1711,7 @@ _cygtls::call_signal_handler () + __unwind_single_frame ((PCONTEXT) &context.uc_mcontext); + if (stackptr > stack) + { +-#ifdef __x86_64__ ++#if defined(__x86_64__) || defined(__aarch64__) + context.uc_mcontext.rip = retaddr (); + #else + #error unimplemented for this target +@@ -1785,14 +1775,13 @@ _cygtls::call_signal_handler () + + If the current code does not work as expected in the "usual" + POSIX circumstances, this problem must be revisited. */ +- ++#if defined(__x86_64__) + /* Compute new stackbase. We start from the high address, aligned + to 16 byte. */ + uintptr_t new_sp = ((uintptr_t) _my_tls.altstack.ss_sp + + _my_tls.altstack.ss_size) & ~0xf; + /* In assembler: Save regs on new stack, move to alternate stack, + call thisfunc, revert stack regs. */ +-#ifdef __x86_64__ + /* Clobbered regs: rcx, rdx, r8, r9, r10, r11, rbp, rsp */ + __asm__ ("\n\ + movq %[NEW_SP], %%rax # Load alt stack into rax \n\ +@@ -1830,6 +1819,8 @@ _cygtls::call_signal_handler () + [FUNC] "o" (thisfunc), + [WRAPPER] "o" (altstack_wrapper) + : "memory"); ++#elif defined(__aarch64__) ++ // TODO + #else + #error unimplemented for this target + #endif +@@ -1936,7 +1927,7 @@ swapcontext (ucontext_t *oucp, const ucontext_t *ucp) + /* Trampoline function to set the context to uc_link. The pointer to the + address of uc_link is stored in a callee-saved register, referenced by + _MC_uclinkReg from the C code. If uc_link is NULL, call exit. */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) + /* _MC_uclinkReg == %rbx */ + __asm__ (" \n\ + .global __cont_link_context \n\ +@@ -1957,7 +1948,15 @@ __cont_link_context: \n\ + nop \n\ + .seh_endproc \n\ + "); +- ++#elif defined(__aarch64__) ++ // TODO ++ __asm__ (" \n\ ++ .global __cont_link_context \n\ ++ .seh_proc __cont_link_context \n\ ++__cont_link_context: \n\ ++ .seh_endprologue \n\ ++ .seh_endproc \n\ ++ "); + #else + #error unimplemented for this target + #endif +@@ -2004,7 +2003,7 @@ makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) + providing pointer values to func without additional porting effort. */ + va_start (ap, argc); + for (int i = 0; i < argc; ++i) +-#ifdef __x86_64__ ++#if defined(__x86_64__) + switch (i) + { + case 0: +@@ -2023,6 +2022,8 @@ makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) + sp[i + 1] = va_arg (ap, uintptr_t); + break; + } ++#elif defined(__aarch64__) ++ // TODO + #else + #error unimplemented for this target + #endif +diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc +index ae43cbc00..cfd664ef9 100644 +--- a/winsup/cygwin/fhandler/pipe.cc ++++ b/winsup/cygwin/fhandler/pipe.cc +@@ -64,7 +64,7 @@ fhandler_pipe::set_pipe_non_blocking (bool nonblocking) + } + + int +-fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id) ++fhandler_pipe::init2 (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id) + { + /* FIXME: Have to clean this up someday + FIXME: Do we have to check for both !get_win32_name() and +@@ -195,7 +195,7 @@ fhandler_pipe::open (int flags, mode_t mode) + __seterrno (); + goto out; + } +- init (nio_hdl, fh->get_access (), mode & O_TEXT ?: O_BINARY, ++ init2 (nio_hdl, fh->get_access (), mode & O_TEXT ?: O_BINARY, + fh->get_plain_ino ()); + cfree (fh); + CloseHandle (proc); +@@ -892,8 +892,8 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode) + if ((fhs[1] = (fhandler_pipe *) build_fh_dev (*pipew_dev)) == NULL) + goto err_delete_fhs0; + mode |= mode & O_TEXT ?: O_BINARY; +- fhs[0]->init (r, FILE_CREATE_PIPE_INSTANCE | GENERIC_READ, mode, unique_id); +- fhs[1]->init (w, FILE_CREATE_PIPE_INSTANCE | GENERIC_WRITE, mode, unique_id); ++ fhs[0]->init2 (r, FILE_CREATE_PIPE_INSTANCE | GENERIC_READ, mode, unique_id); ++ fhs[1]->init2 (w, FILE_CREATE_PIPE_INSTANCE | GENERIC_WRITE, mode, unique_id); + + /* For the read side of the pipe, add a mutex. See raw_read for the + usage. */ +diff --git a/winsup/cygwin/fhandler/proc.cc b/winsup/cygwin/fhandler/proc.cc +index a508d4b14..24accb2f6 100644 +--- a/winsup/cygwin/fhandler/proc.cc ++++ b/winsup/cygwin/fhandler/proc.cc +@@ -2179,8 +2179,7 @@ format_proc_locale_proc (LPWSTR win_locale, DWORD info, LPARAM param) + if (!(cp2 = wcschr (cp + 2, L'-'))) + return TRUE; + /* Otherwise, store in iso15924 */ +- if (iso15924) +- wcpcpy (wcpncpy (iso15924, cp, cp2 - cp), L";"); ++ wcpcpy (wcpncpy (iso15924, cp, cp2 - cp), L";"); + } + cp = wcsrchr (win_locale, L'-'); + if (cp) +diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/termios.cc +index d106955dc..0478936e0 100644 +--- a/winsup/cygwin/fhandler/termios.cc ++++ b/winsup/cygwin/fhandler/termios.cc +@@ -722,7 +722,7 @@ is_console_app (const WCHAR *filename) + } + + int +-fhandler_termios::ioctl (int cmd, void *varg) ++fhandler_termios::ioctl (unsigned int cmd, void *varg) + { + if (cmd != TIOCSCTTY) + return 1; /* Not handled by this function */ +diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc +index 0742ab363..2b884c182 100644 +--- a/winsup/cygwin/fork.cc ++++ b/winsup/cygwin/fork.cc +@@ -628,9 +628,10 @@ dofork (void **proc, bool *with_forkables) + ischild = !!setjmp (grouped.ch.jmp); + + volatile char * volatile stackp; +-#ifdef __x86_64__ ++#if defined(__x86_64__) + __asm__ volatile ("movq %%rsp,%0": "=r" (stackp)); +-#else ++#elif defined(__aarhc64__) ++ // TODO + #error unimplemented for this target + #endif + +diff --git a/winsup/cygwin/include/cygwin/config.h b/winsup/cygwin/include/cygwin/config.h +index 2a7083278..2abc58d38 100644 +--- a/winsup/cygwin/include/cygwin/config.h ++++ b/winsup/cygwin/include/cygwin/config.h +@@ -36,8 +36,11 @@ __attribute__((__gnu_inline__)) + extern inline struct _reent *__getreent (void) + { + register char *ret; +-#ifdef __x86_64__ ++#if defined(__x86_64__) + __asm __volatile__ ("movq %%gs:8,%0" : "=r" (ret)); ++#elif defined(__aarch64__) ++ // TODO ++ ret = 0; + #else + #error unimplemented for this target + #endif +diff --git a/winsup/cygwin/include/cygwin/signal.h b/winsup/cygwin/include/cygwin/signal.h +index de728bede..c93b47545 100644 +--- a/winsup/cygwin/include/cygwin/signal.h ++++ b/winsup/cygwin/include/cygwin/signal.h +@@ -19,7 +19,7 @@ extern "C" { + Define a struct __mcontext, which should be identical in layout to the Win32 + API type CONTEXT with the addition of oldmask and cr2 fields at the end. + */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) || defined(__aarch64__) + + struct _uc_fpxreg { + __uint16_t significand[4]; +diff --git a/winsup/cygwin/include/machine/_endian.h b/winsup/cygwin/include/machine/_endian.h +index dbd4429b8..2f77f90db 100644 +--- a/winsup/cygwin/include/machine/_endian.h ++++ b/winsup/cygwin/include/machine/_endian.h +@@ -26,16 +26,24 @@ _ELIDABLE_INLINE __uint16_t __ntohs(__uint16_t); + _ELIDABLE_INLINE __uint32_t + __ntohl(__uint32_t _x) + { ++#if defined(__x86_64__) + __asm__("bswap %0" : "=r" (_x) : "0" (_x)); ++#elif defined(__aarch64__) ++ // TODO ++#endif + return _x; + } + + _ELIDABLE_INLINE __uint16_t + __ntohs(__uint16_t _x) + { ++#if defined(__x86_64__) + __asm__("xchgb %b0,%h0" /* swap bytes */ + : "=Q" (_x) + : "0" (_x)); ++#elif defined(__aarch64__) ++ // TODO ++#endif + return _x; + } + +diff --git a/winsup/cygwin/include/register.h b/winsup/cygwin/include/register.h +new file mode 100644 +index 000000000..90beff992 +--- /dev/null ++++ b/winsup/cygwin/include/register.h +@@ -0,0 +1,26 @@ ++/* Define macros for CPU-agnostic register access. The _CX_foo ++ macros are for access into CONTEXT, the _MC_foo ones for access into ++ mcontext. The idea is to access the registers in terms of their job, ++ not in terms of their name on the given target. */ ++#if defined(__x86_64__) ++#define _CX_instPtr Rip ++#define _CX_stackPtr Rsp ++#define _CX_framePtr Rbp ++/* For special register access inside mcontext. */ ++#define _MC_retReg rax ++#define _MC_instPtr rip ++#define _MC_stackPtr rsp ++#define _MC_uclinkReg rbx /* MUST be callee-saved reg */ ++#elif defined(__aarch64__) ++#define _CX_instPtr Pc ++#define _CX_stackPtr Sp ++#define _CX_framePtr Fp ++/* For special register access inside mcontext. */ ++// TODO ++#define _MC_retReg rax ++#define _MC_instPtr rip ++#define _MC_stackPtr rsp ++#define _MC_uclinkReg rbx /* MUST be callee-saved reg */ ++#else ++#error unimplemented for this target ++#endif +diff --git a/winsup/cygwin/local_includes/cpuid.h b/winsup/cygwin/local_includes/cpuid.h +index 6dbb1bddf..238c88777 100644 +--- a/winsup/cygwin/local_includes/cpuid.h ++++ b/winsup/cygwin/local_includes/cpuid.h +@@ -13,17 +13,23 @@ static inline void __attribute ((always_inline)) + cpuid (uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t ain, + uint32_t cin = 0) + { ++#if defined(__x86_64__) + asm volatile ("cpuid" + : "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) + : "a" (ain), "c" (cin)); ++#elif defined(__aarch64__) ++ // TODO ++ *a = *b = *c = *d = 0; ++#endif + } + +-#ifdef __x86_64__ ++#if defined(__x86_64__) || defined(__aarch64__) + static inline bool __attribute ((always_inline)) + can_set_flag (uint32_t long flag) + { + uint32_t long r1, r2; + ++#if defined(__x86_64__) + asm volatile ("pushfq\n" + "popq %0\n" + "movq %0, %1\n" +@@ -37,6 +43,9 @@ can_set_flag (uint32_t long flag) + : "=&r" (r1), "=&r" (r2) + : "ir" (flag) + ); ++#elif defined(__aarch64__) ++ // TODO ++#endif + return ((r1 ^ r2) & flag) != 0; + } + #else +diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h +index f67e9136c..866c26cf2 100644 +--- a/winsup/cygwin/local_includes/cygtls.h ++++ b/winsup/cygwin/local_includes/cygtls.h +@@ -295,7 +295,11 @@ public: + address of the _except block to restore the context correctly. + See comment preceeding myfault_altstack_handler in exception.cc. */ + ret = (DWORD64) _ret; ++#if defined(__x86_64__) + __asm__ volatile ("movq %%rsp,%0": "=o" (frame)); ++#elif defined(__aarch64__) ++ // TODO ++#endif + } + ~san () __attribute__ ((always_inline)) + { +diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h +index bd684a6ea..8268054a1 100644 +--- a/winsup/cygwin/local_includes/fhandler.h ++++ b/winsup/cygwin/local_includes/fhandler.h +@@ -1245,7 +1245,7 @@ public: + int fstatvfs (struct statvfs *buf); + int fadvise (off_t, off_t, int); + int fallocate (int, off_t, off_t); +- int init (HANDLE, DWORD, mode_t, int64_t); ++ int init2 (HANDLE, DWORD, mode_t, int64_t); + static int create (fhandler_pipe *[2], unsigned, int); + static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD, + const char *, DWORD, int64_t *unique_id = NULL); +@@ -1732,9 +1732,9 @@ class fhandler_disk_file: public fhandler_base + uint64_t fs_ioc_getflags (); + int fs_ioc_setflags (uint64_t); + +- falloc_allocate (int, off_t, off_t); +- falloc_punch_hole (off_t, off_t); +- falloc_zero_range (int, off_t, off_t); ++ int falloc_allocate (int, off_t, off_t); ++ int falloc_punch_hole (off_t, off_t); ++ int falloc_zero_range (int, off_t, off_t); + + public: + fhandler_disk_file (); +@@ -1959,7 +1959,7 @@ class fhandler_termios: public fhandler_base + protected: + virtual void doecho (const void *, DWORD) {}; + virtual int accept_input () {return 1;}; +- int ioctl (int, void *); ++ int ioctl (unsigned int, void *); + tty_min *_tc; + tty *get_ttyp () {return (tty *) tc ();} + int eat_readahead (int n); +@@ -2302,7 +2302,7 @@ private: + int tcgetattr (struct termios *t); + + int ioctl (unsigned int cmd, void *); +- int init (HANDLE, DWORD, mode_t); ++ int init (HANDLE, DWORD, mode_t) override; + bool mouse_aware (MOUSE_EVENT_RECORD& mouse_event); + bool focus_aware () {return shared_console_info[unit]->con.use_focus;} + bool get_cons_readahead_valid () +@@ -2486,7 +2486,7 @@ class fhandler_pty_slave: public fhandler_pty_common + bool open_setup (int flags); + ssize_t write (const void *ptr, size_t len); + void read (void *ptr, size_t& len); +- int init (HANDLE, DWORD, mode_t); ++ int init (HANDLE, DWORD, mode_t) override; + + int tcsetattr (int a, const struct termios *t); + int tcgetattr (struct termios *t); +diff --git a/winsup/cygwin/local_includes/pathfinder.h b/winsup/cygwin/local_includes/pathfinder.h +index c3066044b..61b0ce020 100644 +--- a/winsup/cygwin/local_includes/pathfinder.h ++++ b/winsup/cygwin/local_includes/pathfinder.h +@@ -85,7 +85,7 @@ public: + { + virtual char const * name () const { return NULL; } + +- virtual bool test (searchdirlist::iterator dir, ++ virtual bool test2 (searchdirlist::iterator dir, + basenamelist::iterator name) const = 0; + }; + +@@ -95,7 +95,7 @@ public: + class simple_criterion_interface + : public criterion_interface + { +- virtual bool test (searchdirlist::iterator dir, ++ virtual bool test2 (searchdirlist::iterator dir, + basenamelist::iterator name) const + { + /* Complete the filename path to search for within dir, +@@ -188,7 +188,7 @@ public: + for (basenamelist::iterator name = basenames_.begin (); + name != basenames_.end (); + ++name) +- if (criterion.test (dir, name)) ++ if (criterion.test2 (dir, name)) + { + debug_printf ("(%s), take %s%s", critname, + dir->string(), name->string ()); +diff --git a/winsup/cygwin/math/acosl.c b/winsup/cygwin/math/acosl.c +index 553d06f75..3cf0f87cf 100644 +--- a/winsup/cygwin/math/acosl.c ++++ b/winsup/cygwin/math/acosl.c +@@ -3,6 +3,11 @@ + * This file is part of the mingw-w64 runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ ++ ++#if defined(__aarch64__) ++#include ++#endif ++ + long double acosl (long double x); + + long double acosl (long double x) +@@ -10,6 +15,7 @@ long double acosl (long double x) + long double res = 0.0L; + + /* acosl = atanl (sqrtl(1 - x^2) / x) */ ++#if defined(__x86_64__) + asm volatile ( + "fld %%st\n\t" + "fmul %%st(0)\n\t" /* x^2 */ +@@ -19,5 +25,9 @@ long double acosl (long double x) + "fxch %%st(1)\n\t" + "fpatan" + : "=t" (res) : "0" (x) : "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = atanl (sqrtl(1 - x*x) / x); ++#endif + return res; + } +diff --git a/winsup/cygwin/math/asinl.c b/winsup/cygwin/math/asinl.c +index 35df3b5dd..f9199eaee 100644 +--- a/winsup/cygwin/math/asinl.c ++++ b/winsup/cygwin/math/asinl.c +@@ -16,6 +16,7 @@ long double asinl (long double x) + { + long double res = 0.0L; + ++#if defined(__x86_64__) + asm volatile ( + "fld %%st\n\t" + "fmul %%st(0)\n\t" /* x^2 */ +@@ -24,5 +25,9 @@ long double asinl (long double x) + "fsqrt\n\t" /* sqrt (1 - x^2) */ + "fpatan" + : "=t" (res) : "0" (x) : "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } +diff --git a/winsup/cygwin/math/atan2l.c b/winsup/cygwin/math/atan2l.c +index a4300cbf4..e47a8e77c 100644 +--- a/winsup/cygwin/math/atan2l.c ++++ b/winsup/cygwin/math/atan2l.c +@@ -9,6 +9,11 @@ long double + atan2l (long double y, long double x) + { + long double res = 0.0L; ++#if defined(__x86_64__) + asm volatile ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } +diff --git a/winsup/cygwin/math/atanl.c b/winsup/cygwin/math/atanl.c +index d289ef08c..3a6b65b18 100644 +--- a/winsup/cygwin/math/atanl.c ++++ b/winsup/cygwin/math/atanl.c +@@ -9,10 +9,14 @@ long double + atanl (long double x) + { + long double res = 0.0L; +- ++#if defined(__x86_64__) + asm volatile ( + "fld1\n\t" + "fpatan" + : "=t" (res) : "0" (x)); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } +diff --git a/winsup/cygwin/math/cosl_internal.S b/winsup/cygwin/math/cosl_internal.S +index 3c8f60d14..edadee21b 100644 +--- a/winsup/cygwin/math/cosl_internal.S ++++ b/winsup/cygwin/math/cosl_internal.S +@@ -34,7 +34,7 @@ __MINGW_USYMBOL(__cosl_internal): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif __i386__ + fldt 4(%esp) + fcos + fnstsw %ax +@@ -51,5 +51,7 @@ __MINGW_USYMBOL(__cosl_internal): + fstp %st(1) + fcos + ret ++#else ++ // TODO + #endif + +diff --git a/winsup/cygwin/math/cossin.c b/winsup/cygwin/math/cossin.c +index 0095daa66..d4945e280 100644 +--- a/winsup/cygwin/math/cossin.c ++++ b/winsup/cygwin/math/cossin.c +@@ -12,6 +12,7 @@ void sincos (double __x, double *p_sin, double *p_cos) + { + long double c, s; + ++#if defined(__x86_64__) + __asm__ __volatile__ ("fsincos\n\t" + "fnstsw %%ax\n\t" + "testl $0x400, %%eax\n\t" +@@ -26,6 +27,11 @@ void sincos (double __x, double *p_sin, double *p_cos) + "fstp %%st(1)\n\t" + "fsincos\n\t" + "1:" : "=t" (c), "=u" (s) : "0" (__x)); ++#elif defined(__aarch64__) ++ // TODO ++ c = 0.0; ++ s = 0.0; ++#endif + *p_sin = (double) s; + *p_cos = (double) c; + } +@@ -34,6 +40,7 @@ void sincosf (float __x, float *p_sin, float *p_cos) + { + long double c, s; + ++#if defined(__x86_64__) + __asm__ __volatile__ ("fsincos\n\t" + "fnstsw %%ax\n\t" + "testl $0x400, %%eax\n\t" +@@ -48,6 +55,11 @@ void sincosf (float __x, float *p_sin, float *p_cos) + "fstp %%st(1)\n\t" + "fsincos\n\t" + "1:" : "=t" (c), "=u" (s) : "0" (__x)); ++#elif defined(__aarch64__) ++ // TODO ++ c = 0.0; ++ s = 0.0; ++#endif + *p_sin = (float) s; + *p_cos = (float) c; + } +@@ -56,6 +68,7 @@ void sincosl (long double __x, long double *p_sin, long double *p_cos) + { + long double c, s; + ++#if defined(__x86_64__) + __asm__ __volatile__ ("fsincos\n\t" + "fnstsw %%ax\n\t" + "testl $0x400, %%eax\n\t" +@@ -70,6 +83,11 @@ void sincosl (long double __x, long double *p_sin, long double *p_cos) + "fstp %%st(1)\n\t" + "fsincos\n\t" + "1:" : "=t" (c), "=u" (s) : "0" (__x)); ++#elif defined(__aarch64__) ++ // TODO ++ c = 0.0; ++ s = 0.0; ++#endif + *p_sin = s; + *p_cos = c; + } +diff --git a/winsup/cygwin/math/exp.def.h b/winsup/cygwin/math/exp.def.h +index 3066b745d..9907ddd45 100644 +--- a/winsup/cygwin/math/exp.def.h ++++ b/winsup/cygwin/math/exp.def.h +@@ -52,11 +52,12 @@ static long double + __expl_internal (long double x) + { + long double res = 0.0L; ++#if defined(__x86_64__) || defined(__i386__) + asm volatile ( + "fldl2e\n\t" /* 1 log2(e) */ + "fmul %%st(1),%%st\n\t" /* 1 x log2(e) */ + +-#ifdef __x86_64__ ++#if defined(__x86_64__) + "subq $8, %%rsp\n" + "fnstcw 4(%%rsp)\n" + "movzwl 4(%%rsp), %%eax\n" +@@ -101,6 +102,10 @@ __expl_internal (long double x) + "fstp %%st(1)\n\t" /* 1 */ + "fstp %%st(1)\n\t" /* 0 */ + : "=t" (res) : "0" (x), "m" (c0), "m" (c1) : "ax", "dx"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0 * c0 * c1; ++#endif + return res; + } + +diff --git a/winsup/cygwin/math/exp2l.S b/winsup/cygwin/math/exp2l.S +index b08d8e40a..a404eecd4 100644 +--- a/winsup/cygwin/math/exp2l.S ++++ b/winsup/cygwin/math/exp2l.S +@@ -53,7 +53,7 @@ __MINGW_USYMBOL(exp2l): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif __i386__ + fldt 4(%esp) + /* I added the following ugly construct because exp(+-Inf) resulted + in NaN. The ugliness results from the bright minds at Intel. +@@ -89,4 +89,6 @@ __MINGW_USYMBOL(exp2l): + fstp %st + fldz /* Set result to 0. */ + 2: ret ++#else ++ // TODO + #endif +diff --git a/winsup/cygwin/math/expm1.def.h b/winsup/cygwin/math/expm1.def.h +index 028211f91..0ad04e110 100644 +--- a/winsup/cygwin/math/expm1.def.h ++++ b/winsup/cygwin/math/expm1.def.h +@@ -65,7 +65,12 @@ __FLT_ABI(expm1) (__FLT_TYPE x) + if (__FLT_ABI (fabs) (x) < __FLT_LOGE2) + { + x /= __FLT_LOGE2; ++#if defined(_x86_64__) + __asm__ __volatile__ ("f2xm1" : "=t" (x) : "0" (x)); ++#elif defined(__aarch64__) ++ // TODO ++ x = 0.0; ++#endif + return x; + } + return __FLT_ABI (exp) (x) - __FLT_CST (1.0); +diff --git a/winsup/cygwin/math/fabsl.c b/winsup/cygwin/math/fabsl.c +index f3864ea13..931962711 100644 +--- a/winsup/cygwin/math/fabsl.c ++++ b/winsup/cygwin/math/fabsl.c +@@ -12,7 +12,7 @@ fabsl (long double x) + long double res = 0.0L; + asm volatile ("fabs;" : "=t" (res) : "0" (x)); + return res; +-#elif defined(__arm__) || defined(_ARM_) ++#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) + return __builtin_fabsl (x); + #endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || defined(_X86_) */ + } +diff --git a/winsup/cygwin/math/fastmath.h b/winsup/cygwin/math/fastmath.h +index eb1846cb3..edd349a70 100644 +--- a/winsup/cygwin/math/fastmath.h ++++ b/winsup/cygwin/math/fastmath.h +@@ -18,7 +18,7 @@ + + static __inline__ double __fast_sqrt (double x) + { +- double res; ++ double res; + asm __volatile__ ("fsqrt" : "=t" (res) : "0" (x)); + return res; + } +@@ -26,7 +26,12 @@ static __inline__ double __fast_sqrt (double x) + static __inline__ long double __fast_sqrtl (long double x) + { + long double res; ++#if defined(__x86_64__) + asm __volatile__ ("fsqrt" : "=t" (res) : "0" (x)); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } + +@@ -41,22 +46,32 @@ static __inline__ float __fast_sqrtf (float x) + static __inline__ double __fast_log (double x) + { + double res; ++#if defined(__x86_64__) + asm __volatile__ + ("fldln2\n\t" + "fxch\n\t" + "fyl2x" + : "=t" (res) : "0" (x) : "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } + + static __inline__ long double __fast_logl (long double x) + { + long double res; +- asm __volatile__ +- ("fldln2\n\t" +- "fxch\n\t" +- "fyl2x" +- : "=t" (res) : "0" (x) : "st(1)"); ++#if defined(__x86_64__) ++ asm __volatile__ ++ ("fldln2\n\t" ++ "fxch\n\t" ++ "fyl2x" ++ : "=t" (res) : "0" (x) : "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } + +@@ -93,12 +108,18 @@ static __inline__ long double __fast_log1pl (long double x) + /* fyl2xp1 accurate only for |x| <= 1.0 - 0.5 * sqrt (2.0) */ + if (fabsl (x) >= 1.0L - 0.5L * 1.41421356237309504880L) + res = __fast_logl (1.0L + x); +- else ++ else { ++#if defined(__x86_64__) + asm __volatile__ + ("fldln2\n\t" + "fxch\n\t" + "fyl2xp1" + : "=t" (res) : "0" (x) : "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif ++ } + return res; + } + +diff --git a/winsup/cygwin/math/fmodl.c b/winsup/cygwin/math/fmodl.c +index 462b6fa79..21a3fa0f7 100644 +--- a/winsup/cygwin/math/fmodl.c ++++ b/winsup/cygwin/math/fmodl.c +@@ -10,6 +10,7 @@ fmodl (long double x, long double y) + { + long double res = 0.0L; + ++#if defined(__x86_64__) + asm volatile ( + "1:\tfprem\n\t" + "fstsw %%ax\n\t" +@@ -17,5 +18,9 @@ fmodl (long double x, long double y) + "jp 1b\n\t" + "fstp %%st(1)" + : "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)"); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0; ++#endif + return res; + } +diff --git a/winsup/cygwin/math/frexpl.S b/winsup/cygwin/math/frexpl.S +index 12782c29e..dcc288b95 100644 +--- a/winsup/cygwin/math/frexpl.S ++++ b/winsup/cygwin/math/frexpl.S +@@ -10,14 +10,14 @@ + * It returns an integer power of two to expnt and the significand + * between 0.5 and 1 to y. Thus x = y * 2**expn. + */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 2 + #endif + .globl __MINGW_USYMBOL(frexpl) + __MINGW_USYMBOL(frexpl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + pushq %rbp + movq %rsp,%rbp + subq $48,%rsp +@@ -72,7 +72,7 @@ L24: + fstpt (%r9) + leave + ret +-#else ++#elif defined(__i386__) + pushl %ebp + movl %esp,%ebp + subl $24,%esp +@@ -127,4 +127,8 @@ L24: + popl %esi + leave + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/ilogbl.S b/winsup/cygwin/math/ilogbl.S +index c75a7d0fd..cc8aaf02a 100644 +--- a/winsup/cygwin/math/ilogbl.S ++++ b/winsup/cygwin/math/ilogbl.S +@@ -7,15 +7,15 @@ + + .file "ilogbl.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(ilogbl) + .def __MINGW_USYMBOL(ilogbl); .scl 2; .type 32; .endef + __MINGW_USYMBOL(ilogbl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldt (%rcx) + fxam /* Is NaN or +-Inf? */ + fstsw %ax +@@ -44,7 +44,7 @@ __MINGW_USYMBOL(ilogbl): + 2: fstp %st + movl $0x80000001, %eax /* FP_ILOGB0 */ + ret +-#else ++#elif defined(__i386__) + fldt 4(%esp) + /* I added the following ugly construct because ilogb(+-Inf) is + required to return INT_MAX in ISO C99. +@@ -76,4 +76,8 @@ __MINGW_USYMBOL(ilogbl): + 2: fstp %st + movl $0x80000001, %eax /* FP_ILOGB0 */ + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/internal_logl.S b/winsup/cygwin/math/internal_logl.S +index f8a075774..da98f4cf2 100644 +--- a/winsup/cygwin/math/internal_logl.S ++++ b/winsup/cygwin/math/internal_logl.S +@@ -7,9 +7,9 @@ + + .file "internal_logl.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + one: .double 1.0 +@@ -21,7 +21,7 @@ limit: .double 0.29 + .globl __MINGW_USYMBOL(__logl_internal) + .def __MINGW_USYMBOL(__logl_internal); .scl 2; .type 32; .endef + __MINGW_USYMBOL(__logl_internal): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldln2 // log(2) + fldt (%rdx) // x : log(2) + fld %st // x : x : log(2) +@@ -45,7 +45,7 @@ __MINGW_USYMBOL(__logl_internal): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldln2 // log(2) + fldt 4(%esp) // x : log(2) + fld %st // x : x : log(2) +@@ -63,4 +63,8 @@ __MINGW_USYMBOL(__logl_internal): + 2: fstp %st(0) // x : log(2) + fyl2x // log(x) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/ldexpl.c b/winsup/cygwin/math/ldexpl.c +index 2438617c3..9d5255c7a 100644 +--- a/winsup/cygwin/math/ldexpl.c ++++ b/winsup/cygwin/math/ldexpl.c +@@ -12,9 +12,14 @@ long double ldexpl(long double x, int expn) + if (!isfinite (x) || x == 0.0L) + return x; + ++#if defined(__x86_64__) || defined(__i386__) + __asm__ __volatile__ ("fscale" + : "=t" (res) + : "0" (x), "u" ((long double) expn)); ++#elif defined(__aarch64__) ++ // TODO ++ res = 0.0L; ++#endif + + if (!isfinite (res) || res == 0.0L) + errno = ERANGE; +diff --git a/winsup/cygwin/math/log10l.S b/winsup/cygwin/math/log10l.S +index 33d45a3a8..2ec1108cc 100644 +--- a/winsup/cygwin/math/log10l.S ++++ b/winsup/cygwin/math/log10l.S +@@ -7,9 +7,9 @@ + + .file "log10l.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + one: .double 1.0 +@@ -19,15 +19,15 @@ one: .double 1.0 + limit: .double 0.29 + + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(log10l) + .def __MINGW_USYMBOL(log10l); .scl 2; .type 32; .endef + __MINGW_USYMBOL(log10l): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldlg2 // log10(2) + fldt (%rdx) // x : log10(2) + fxam +@@ -63,7 +63,7 @@ __MINGW_USYMBOL(log10l): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldlg2 // log10(2) + fldt 4(%esp) // x : log10(2) + fxam +@@ -90,4 +90,8 @@ __MINGW_USYMBOL(log10l): + fstp %st(1) + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/log1pl.S b/winsup/cygwin/math/log1pl.S +index a56bcf4ec..b6b443860 100644 +--- a/winsup/cygwin/math/log1pl.S ++++ b/winsup/cygwin/math/log1pl.S +@@ -12,18 +12,20 @@ + 0.29 is a safe value. + */ + ++#if defined(__x86_64__) || defined(__i386__) + /* Only gcc understands the .tfloat type + The series of .long below represents + limit: .tfloat 0.29 + */ + .align 16 ++#endif + limit: + .long 2920577761 + .long 2491081031 + .long 16381 +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + /* Please note: we use a double value here. Since 1.0 has +@@ -38,7 +40,7 @@ one: .double 1.0 + .globl __MINGW_USYMBOL(log1pl) + .def __MINGW_USYMBOL(log1pl); .scl 2; .type 32; .endef + __MINGW_USYMBOL(log1pl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldln2 + fldt (%rdx) + fxam +@@ -73,7 +75,7 @@ __MINGW_USYMBOL(log1pl): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldln2 + fldt 4(%esp) + fxam +@@ -99,4 +101,8 @@ __MINGW_USYMBOL(log1pl): + fstp %st(1) + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/log2l.S b/winsup/cygwin/math/log2l.S +index 771cd8ae4..204b1b70d 100644 +--- a/winsup/cygwin/math/log2l.S ++++ b/winsup/cygwin/math/log2l.S +@@ -7,9 +7,9 @@ + + .file "log2l.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + one: .double 1.0 +@@ -21,7 +21,7 @@ limit: .double 0.29 + .globl __MINGW_USYMBOL(log2l) + .def __MINGW_USYMBOL(log2l); .scl 2; .type 32; .endef + __MINGW_USYMBOL(log2l): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldl one(%rip) + fldt (%rdx) // x : 1 + fxam +@@ -57,7 +57,7 @@ __MINGW_USYMBOL(log2l): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldl one + fldt 4(%esp) // x : 1 + fxam +@@ -84,4 +84,8 @@ __MINGW_USYMBOL(log2l): + fstp %st(1) + fstp %st(1) + ret ++#elif (__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/logbl.c b/winsup/cygwin/math/logbl.c +index 5e533c07c..cdce28d22 100644 +--- a/winsup/cygwin/math/logbl.c ++++ b/winsup/cygwin/math/logbl.c +@@ -16,8 +16,12 @@ logbl (long double x) + { + long double res = 0.0L; + ++#if defined(__x86_64__) || defined(__i386__) + asm volatile ( + "fxtract\n\t" + "fstp %%st" : "=t" (res) : "0" (x)); ++#elif defined(__aarch64__) ++ res = 0.0; ++#endif + return res; + } +diff --git a/winsup/cygwin/math/pow.def.h b/winsup/cygwin/math/pow.def.h +index 2ea825720..2d9dee40a 100644 +--- a/winsup/cygwin/math/pow.def.h ++++ b/winsup/cygwin/math/pow.def.h +@@ -81,7 +81,7 @@ internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr) + __FLT_TYPE int_part = (__FLT_TYPE) 0.0; + /* truncate */ + /* truncate */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) + asm volatile ("pushq %%rax\n\tsubq $8, %%rsp\n" + "fnstcw 4(%%rsp)\n" + "movzwl 4(%%rsp), %%eax\n" +@@ -91,7 +91,7 @@ internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr) + "frndint\n" + "fldcw 4(%%rsp)\n" + "addq $8, %%rsp\npopq %%rax" : "=t" (int_part) : "0" (value)); /* round */ +-#else ++#elif defined(__i386__) + asm volatile ("push %%eax\n\tsubl $8, %%esp\n" + "fnstcw 4(%%esp)\n" + "movzwl 4(%%esp), %%eax\n" +@@ -101,6 +101,8 @@ internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr) + "frndint\n" + "fldcw 4(%%esp)\n" + "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value)); /* round */ ++#elif defined(__aarch64__) ++ // TODO + #endif + if (iptr) + *iptr = int_part; +@@ -204,7 +206,12 @@ __FLT_ABI(pow) (__FLT_TYPE x, __FLT_TYPE y) + } + if (y == __FLT_CST(0.5)) + { ++#if defined(__x86_64__) || defined(__i386__) + asm volatile ("fsqrt" : "=t" (rslt) : "0" (x)); ++#elif defined(__aarch64__) ++ // TODO ++ rslt = 0.0; ++#endif + return rslt; + } + } +diff --git a/winsup/cygwin/math/remainder.S b/winsup/cygwin/math/remainder.S +index 5a713f904..5e115b8bf 100644 +--- a/winsup/cygwin/math/remainder.S ++++ b/winsup/cygwin/math/remainder.S +@@ -7,15 +7,15 @@ + + .file "remainder.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(remainder) + .def __MINGW_USYMBOL(remainder); .scl 2; .type 32; .endef + __MINGW_USYMBOL(remainder): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + movsd %xmm0,-16(%rsp) + movsd %xmm1,-32(%rsp) + fldl -32(%rsp) +@@ -28,7 +28,7 @@ __MINGW_USYMBOL(remainder): + fstpl -16(%rsp) + movsd -16(%rsp),%xmm0 + ret +-#else ++#elif defined(__i386__) + fldl 12(%esp) + fldl 4(%esp) + 1: fprem1 +@@ -37,4 +37,8 @@ __MINGW_USYMBOL(remainder): + jp 1b + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/remainderf.S b/winsup/cygwin/math/remainderf.S +index c3a3a3dc5..a2b8fb45b 100644 +--- a/winsup/cygwin/math/remainderf.S ++++ b/winsup/cygwin/math/remainderf.S +@@ -7,15 +7,15 @@ + + .file "remainderf.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(remainder) + .def __MINGW_USYMBOL(remainderf); .scl 2; .type 32; .endef + __MINGW_USYMBOL(remainderf): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + movss %xmm1,-12(%rsp) + flds -12(%rsp) + movss %xmm0,-12(%rsp) +@@ -28,7 +28,7 @@ __MINGW_USYMBOL(remainderf): + fstps -12(%rsp) + movss -12(%rsp),%xmm0 + ret +-#else ++#elif defined(__i386__) + flds 8(%esp) + flds 4(%esp) + 1: fprem1 +@@ -37,4 +37,8 @@ __MINGW_USYMBOL(remainderf): + jp 1b + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/remainderl.S b/winsup/cygwin/math/remainderl.S +index a69e38296..3ca354ff0 100644 +--- a/winsup/cygwin/math/remainderl.S ++++ b/winsup/cygwin/math/remainderl.S +@@ -7,15 +7,15 @@ + + .file "remainderl.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(remainderl) + .def __MINGW_USYMBOL(remainderl); .scl 2; .type 32; .endef + __MINGW_USYMBOL(remainderl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldt (%r8) + fldt (%rdx) + 1: fprem1 +@@ -27,7 +27,7 @@ __MINGW_USYMBOL(remainderl): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldt 16(%esp) + fldt 4(%esp) + 1: fprem1 +@@ -36,4 +36,8 @@ __MINGW_USYMBOL(remainderl): + jp 1b + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/remquol.S b/winsup/cygwin/math/remquol.S +index e16df8ad2..2a067f5aa 100644 +--- a/winsup/cygwin/math/remquol.S ++++ b/winsup/cygwin/math/remquol.S +@@ -7,14 +7,14 @@ + + .file "remquol.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(remquol) + __MINGW_USYMBOL(remquol): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + pushq %rcx + fldt (%r8) + fldt (%rdx) +@@ -45,7 +45,7 @@ __MINGW_USYMBOL(remquol): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldt 4 +12(%esp) + fldt 4(%esp) + 1: fprem1 +@@ -72,4 +72,8 @@ __MINGW_USYMBOL(remquol): + 1: movl %eax, (%ecx) + + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/scalbl.S b/winsup/cygwin/math/scalbl.S +index f9675ac4b..376cd921e 100644 +--- a/winsup/cygwin/math/scalbl.S ++++ b/winsup/cygwin/math/scalbl.S +@@ -7,15 +7,15 @@ + + .file "scalbl.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(scalbl) + .def __MINGW_USYMBOL(scalbl); .scl 2; .type 32; .endef + __MINGW_USYMBOL(scalbl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + subq $24, %rsp + fldt (%r8) + fldt (%rdx) +@@ -26,10 +26,14 @@ __MINGW_USYMBOL(scalbl): + fstpt (%rcx) + addq $24, %rsp + ret +-#else ++#elif defined(__i386__) + fildl 16(%esp) + fldt 4(%esp) + fscale + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/scalbnl.S b/winsup/cygwin/math/scalbnl.S +index 5ff0a68f3..430fe7ea7 100644 +--- a/winsup/cygwin/math/scalbnl.S ++++ b/winsup/cygwin/math/scalbnl.S +@@ -7,15 +7,15 @@ + + .file "scalbnl.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(scalbnl) + .def __MINGW_USYMBOL(scalbnl); .scl 2; .type 32; .endef + __MINGW_USYMBOL(scalbnl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + subq $24, %rsp + andl $-1, %r8d + movq %r8, (%rsp) +@@ -28,14 +28,17 @@ __MINGW_USYMBOL(scalbnl): + fstpt (%rcx) + addq $24, %rsp + ret +-#else ++#elif defined(__i386__) + fildl 16(%esp) + fldt 4(%esp) + fscale + fstp %st(1) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif + + .globl __MINGW_USYMBOL(scalblnl) + .set __MINGW_USYMBOL(scalblnl),__MINGW_USYMBOL(scalbnl) +- +diff --git a/winsup/cygwin/math/sinl_internal.S b/winsup/cygwin/math/sinl_internal.S +index 6d766b098..30f528f0a 100644 +--- a/winsup/cygwin/math/sinl_internal.S ++++ b/winsup/cygwin/math/sinl_internal.S +@@ -7,15 +7,15 @@ + + .file "sinl_internal.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(__sinl_internal) + .def __MINGW_USYMBOL(__sinl_internal); .scl 2; .type 32; .endef + __MINGW_USYMBOL(__sinl_internal): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldt (%rdx) + fsin + fnstsw %ax +@@ -38,7 +38,7 @@ __MINGW_USYMBOL(__sinl_internal): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldt 4(%esp) + fsin + fnstsw %ax +@@ -55,4 +55,8 @@ __MINGW_USYMBOL(__sinl_internal): + fstp %st(1) + fsin + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/sqrt.def.h b/winsup/cygwin/math/sqrt.def.h +index 3d1a00908..ea0e43e92 100644 +--- a/winsup/cygwin/math/sqrt.def.h ++++ b/winsup/cygwin/math/sqrt.def.h +@@ -89,6 +89,8 @@ __FLT_ABI (sqrt) (__FLT_TYPE x) + __fsqrt_internal(x); + #elif defined(_X86_) || defined(__i386__) || defined(_AMD64_) || defined(__x86_64__) + asm volatile ("fsqrt" : "=t" (res) : "0" (x)); ++#elif defined(__aarch64__) ++ // TODO + #else + #error Not supported on your platform yet + #endif +diff --git a/winsup/cygwin/math/tanl.S b/winsup/cygwin/math/tanl.S +index f11b53920..4102d3bc1 100644 +--- a/winsup/cygwin/math/tanl.S ++++ b/winsup/cygwin/math/tanl.S +@@ -7,15 +7,15 @@ + + .file "tanl.S" + .text +-#ifdef __x86_64__ ++#if defined(__x86_64__) + .align 8 +-#else ++#elif defined(__i386__) + .align 4 + #endif + .globl __MINGW_USYMBOL(tanl) + .def __MINGW_USYMBOL(tanl); .scl 2; .type 32; .endef + __MINGW_USYMBOL(tanl): +-#ifdef __x86_64__ ++#if defined(__x86_64__) + fldt (%rdx) + fptan + fnstsw %ax +@@ -40,7 +40,7 @@ __MINGW_USYMBOL(tanl): + movq $0,8(%rcx) + fstpt (%rcx) + ret +-#else ++#elif defined(__i386__) + fldt 4(%esp) + fptan + fnstsw %ax +@@ -59,4 +59,8 @@ __MINGW_USYMBOL(tanl): + fptan + fstp %st(0) + ret ++#elif defined(__aarch64__) ++ // TODO ++#else ++ .error "Not supported on your platform yet" + #endif +diff --git a/winsup/cygwin/math/truncl.c b/winsup/cygwin/math/truncl.c +index 9380f9571..c64a20fb5 100644 +--- a/winsup/cygwin/math/truncl.c ++++ b/winsup/cygwin/math/truncl.c +@@ -13,7 +13,7 @@ + long double + truncl (long double _x) + { +-#if defined(_ARM_) || defined(__arm__) ++#if defined(_ARM_) || defined(__arm__) || defined(__aarch64__) + return trunc(_x); + #else + long double retval = 0.0L; +@@ -26,5 +26,5 @@ truncl (long double _x) + __asm__ __volatile__ ("frndint;" : "=t" (retval) : "0" (_x)); /* round towards zero */ + __asm__ __volatile__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */ + return retval; +-#endif /* defined(_ARM_) || defined(__arm__) */ ++#endif /* defined(_ARM_) || defined(__arm__) || defined(__aarch64__) */ + } +diff --git a/winsup/cygwin/profil.c b/winsup/cygwin/profil.c +index 30b37244a..9578ab1df 100644 +--- a/winsup/cygwin/profil.c ++++ b/winsup/cygwin/profil.c +@@ -21,6 +21,7 @@ + #include + #include + #include "profil.h" ++#include "register.h" + + #define SLEEPTIME (1000 / PROF_HZ) + +@@ -42,11 +43,7 @@ get_thrpc (HANDLE thr) + ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; + pc = (size_t) - 1; + if (GetThreadContext (thr, &ctx)) { +-#ifdef __x86_64__ +- pc = ctx.Rip; +-#else +-#error unimplemented for this target +-#endif ++ pc = ctx._CX_instPtr; + } + ResumeThread (thr); + return pc; +diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef +index 3b1f8b9da..734c4d5a3 100755 +--- a/winsup/cygwin/scripts/gendef ++++ b/winsup/cygwin/scripts/gendef +@@ -21,6 +21,7 @@ if (!defined($cpu) || !defined($output_def)) { + die "$0: missing required option\n"; + } + ++my $is_aarch64 = $cpu eq 'aarch64'; + my $is_x86_64 = $cpu eq 'x86_64'; + # FIXME? Do other (non-32 bit) arches on Windows still use symbol prefixes? + my $sym_prefix = ''; +@@ -89,7 +90,7 @@ sub fefunc { + my $func = $sym_prefix . shift; + my $fe = $sym_prefix . shift; + my $sigfe_func; +- if ($is_x86_64) { ++ if ($is_x86_64 || $is_aarch64) { + $sigfe_func = ($fe =~ /^(.*)_${func}$/)[0]; + } + my $extra; +@@ -109,6 +110,18 @@ $fe: + + EOF + } ++ # TODO ++ if ($is_aarch64) { ++ $res = < 0) { + if (varname == "start_offset") { + print $2; +@@ -85,7 +85,7 @@ gawk -v start_offset="$start_offset" '\ + varname = ""; + } + } +- /\s*\.long\s+/ { ++ /\s*\.word\s+/ { + if (length (varname) > 0) { + if (varname == "start_offset") { + printf (".equ _cygtls.%s, -%u\n", varname, start_offset); +diff --git a/winsup/cygwin/scripts/mkimport b/winsup/cygwin/scripts/mkimport +index 9517c4e9e..03841dbbd 100755 +--- a/winsup/cygwin/scripts/mkimport ++++ b/winsup/cygwin/scripts/mkimport +@@ -24,6 +24,7 @@ my %import = (); + my %symfile = (); + + my $is_x86_64 = ($cpu eq 'x86_64' ? 1 : 0); ++my $is_aarch64 = ($cpu eq 'aarch64' ? 1 : 0); + # FIXME? Do other (non-32 bit) arches on Windows still use symbol prefixes? + my $sym_prefix = ''; + +@@ -65,6 +66,17 @@ for my $f (keys %text) { + .global $glob_sym + $glob_sym: + jmp *$imp_sym(%rip) ++EOF ++ } elsif ($is_aarch64) { ++ # TODO ++ print $as_fd <find_tls (cygtls); + if (!cygtls->inside_kernel (&context)) + { +- context.Rip = (ULONG_PTR) pthread::static_cancel_self; ++ context._CX_instPtr = (ULONG_PTR) pthread::static_cancel_self; + SetThreadContext (win32_obj_id, &context); + } + cygheap->unlock_tls (tl_entry); +@@ -1946,7 +1947,11 @@ pthread_spinlock::lock () + else if (spins < FAST_SPINS_LIMIT) + { + ++spins; ++#if defined(__x86_64__) + __asm__ volatile ("pause":::); ++#elif defined(__aarch64__) ++ // TODO ++#endif + } + else + { +diff --git a/winsup/utils/profiler.cc b/winsup/utils/profiler.cc +index b5ce16cf2..04c6b3ed3 100644 +--- a/winsup/utils/profiler.cc ++++ b/winsup/utils/profiler.cc +@@ -33,6 +33,7 @@ typedef uint16_t u_int16_t; // Non-standard sized type needed by ancient gmon.h + #define NO_GLOBALS_H + #include "gmon.h" + #include "path.h" ++#include "register.h" + + /* Undo this #define from winsup.h. */ + #ifdef ExitThread +@@ -193,11 +194,7 @@ sample (CONTEXT *context, HANDLE h) + return 0ULL; + } + else +-#ifdef __x86_64__ +- return context->Rip; +-#else +-#error unimplemented for this target +-#endif ++ return context->_CX_instPtr; + } + + void +@@ -503,8 +500,10 @@ find_text_section (LPVOID base, HANDLE h) + + read_child ((void *) &machine, sizeof (machine), + &inth->FileHeader.Machine, h); +-#ifdef __x86_64__ ++#if defined(__x86_64__) + if (machine != IMAGE_FILE_MACHINE_AMD64) ++#elif defined(__aarch64__) ++ if (machine != IMAGE_FILE_MACHINE_ARM64) + #else + #error unimplemented for this target + #endif +diff --git a/winsup/utils/ssp.c b/winsup/utils/ssp.c +index 96a90a1d9..9ab9d1e05 100644 +--- a/winsup/utils/ssp.c ++++ b/winsup/utils/ssp.c +@@ -41,13 +41,21 @@ static struct option longopts[] = + + static char opts[] = "+cdehlstvV"; + +-#ifdef __x86_64__ ++#if defined(__x86_64__) + #define KERNEL_ADDR 0x00007FF000000000 + #define CONTEXT_SP Rsp + #define CONTEXT_IP Rip + typedef DWORD64 CONTEXT_REG; + #define CONTEXT_REG_FMT "%016llx" + #define ADDR_SSCANF_FMT "%lli" ++#elif defined(__aarch64__) ++// TODO ++#define KERNEL_ADDR 0x00007FF000000000 ++#define CONTEXT_SP Sp ++#define CONTEXT_IP Pc ++typedef DWORD64 CONTEXT_REG; ++#define CONTEXT_REG_FMT "%016llx" ++#define ADDR_SSCANF_FMT "%lli" + #else + #error unimplemented for this target + #endif +@@ -200,10 +208,16 @@ set_step_threads (int threadId, int trace) + if (rv != -1) + { + thread_step_flags[tix] = trace; ++#if defined(__i386__) || defined(__x86_64__) + if (trace) + context.EFlags |= 0x100; /* TRAP (single step) flag */ + else + context.EFlags &= ~0x100; /* TRAP (single step) flag */ ++#elif defined(__aarch64__) ++ // TODO ++#else ++#error unimplemented for this target ++#endif + SetThreadContext (thread, &context); + } + } +@@ -215,7 +229,14 @@ set_steps () + for (i=0; i + #ifdef __MINGW32__ +diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h +index 1af5bc380a5..779d06beede 100644 +--- a/gcc/config/i386/cygming.h ++++ b/gcc/config/i386/cygming.h +@@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see + : (dwarf_debuginfo_p () \ + ? svr4_debugger_register_map[n] : debugger_register_map[n])) + ++#if !defined(__aarch64__) + /* Map gcc register number to DWARF 2 CFA column number. For 32 bit + target, always use the svr4_debugger_register_map for DWARF .eh_frame + even if we don't use DWARF .debug_frame. */ +@@ -85,6 +86,7 @@ along with GCC; see the file COPYING3. If not see + #define DWARF_FRAME_REGNUM(n) \ + (TARGET_64BIT ? debugger64_register_map[(n)] \ + : svr4_debugger_register_map[(n)]) ++#endif + + /* The 64-bit MS_ABI changes the set of call-used registers. */ + #undef DWARF_FRAME_REGISTERS +diff --git a/gcc/config/i386/cygwin-w64.h b/gcc/config/i386/cygwin-w64.h +index 8dac104cb43..ee9cce3fa9c 100644 +--- a/gcc/config/i386/cygwin-w64.h ++++ b/gcc/config/i386/cygwin-w64.h +@@ -50,7 +50,11 @@ along with GCC; see the file COPYING3. If not see + + #undef SUB_LINK_SPEC + #undef SUB_LINK_ENTRY ++#if defined(TARGET_AARCH64) ++#define SUB_LINK_SPEC "-m aarch64pe" ++#else + #define SUB_LINK_SPEC "%{" SPEC_64 ":-m i386pep} %{" SPEC_32 ":-m i386pe}" ++#endif + #define SUB_LINK_ENTRY "%{" SPEC_64 ":" SUB_LINK_ENTRY64 "} %{" SPEC_32 ":" SUB_LINK_ENTRY32 "}" + + #undef MULTILIB_DEFAULTS +diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h +index 529edff93a4..5c2adc5c894 100644 +--- a/gcc/config/i386/i386.h ++++ b/gcc/config/i386/i386.h +@@ -266,7 +266,7 @@ extern const struct processor_costs ix86_size_cost; + compile-time constant. */ + #ifdef IN_LIBGCC2 + #undef TARGET_64BIT +-#ifdef __x86_64__ ++#if defined(__x86_64__) || defined(__aarch64__) + #define TARGET_64BIT 1 + #else + #define TARGET_64BIT 0 +diff --git a/gcc/configure b/gcc/configure +index 266ab8f84b2..a064d6045b5 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -29026,7 +29026,7 @@ fi + + ;; + +- i[34567]86-*-* | x86_64-*-*) ++ i[34567]86-*-* | x86_64-*-* | aarch64-*-*) + case $target_os in + cygwin*) + # Full C++ conformance when using a shared libstdc++-v3 requires some +diff --git a/gcc/configure.ac b/gcc/configure.ac +index a5aec1bc967..5db76d3b63c 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -4793,7 +4793,7 @@ foo: + ;; + + changequote(,)dnl +- i[34567]86-*-* | x86_64-*-*) ++ i[34567]86-*-* | x86_64-*-* | aarch64-*-*) + changequote([,])dnl + case $target_os in + cygwin*) +diff --git a/libgcc/config.host b/libgcc/config.host +index 68a8b679f52..0fd33db2f47 100644 +--- a/libgcc/config.host ++++ b/libgcc/config.host +@@ -856,6 +856,32 @@ i[34567]86-*-solaris2* | x86_64-*-solaris2*) + ;; + i[4567]86-wrs-vxworks*|x86_64-wrs-vxworks*) + ;; ++aarch64-*-cygwin*) ++ extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" ++ if test x$enable_vtable_verify = xyes; then ++ extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" ++ fi ++ # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h ++ if test x$ac_cv_sjlj_exceptions = xyes; then ++ tmake_eh_file="i386/t-sjlj-eh" ++ elif test "${host_address}" = 32; then ++ # biarch -m32 with --disable-sjlj-exceptions ++ tmake_eh_file="i386/t-dw2-eh" ++ else ++ tmake_eh_file="i386/t-seh-eh" ++ fi ++ # Shared libgcc DLL install dir depends on cross/native build. ++ if test x${build} = x${host} ; then ++ tmake_dlldir_file="i386/t-dlldir" ++ else ++ tmake_dlldir_file="i386/t-dlldir-x" ++ fi ++ # FIXME - dj - t-chkstk used to be in here, need a 64-bit version of that ++ tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-cygming i386/t-cygwin i386/t-chkstk t-dfprules" ++ tmake_file="${tmake_file} ${cpu_type}/t-aarch64" ++ tmake_file="${tmake_file} ${cpu_type}/t-lse" ++ tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" ++ ;; + i[34567]86-*-cygwin*) + extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then +diff --git a/libgcc/config/aarch64/aarch64-asm.h b/libgcc/config/aarch64/aarch64-asm.h +index 83c2e5944b3..1d6dbaa3407 100644 +--- a/libgcc/config/aarch64/aarch64-asm.h ++++ b/libgcc/config/aarch64/aarch64-asm.h +@@ -24,7 +24,13 @@ + + #include "auto-target.h" + +-#define L(label) .L ## label ++#ifdef __GCC_HAVE_DWARF2_CFI_ASM ++# define cfi_startproc() .cfi_startproc ++# define cfi_endproc() .cfi_endproc ++#else ++# define cfi_startproc() ++# define cfi_endproc() ++#endif + + /* Marking variant PCS symbol references is important for PLT calls + otherwise it is for documenting the PCS in the symbol table. */ +diff --git a/libgcc/config/i386/cygwin.S b/libgcc/config/i386/cygwin.S +index 8da25778079..31dc9dd6160 100644 +--- a/libgcc/config/i386/cygwin.S ++++ b/libgcc/config/i386/cygwin.S +@@ -23,7 +23,11 @@ + * . + */ + ++#if defined(__i386__) || defined(__x86_64__) + #include "i386-asm.h" ++#elif defined(__aarch64__) ++#include "../aarch64/aarch64-asm.h" ++#endif + + #ifdef HAVE_AS_CFI_SECTIONS + .cfi_sections .debug_frame +@@ -37,7 +41,7 @@ + + .global ___chkstk + .global __alloca +-#ifdef __x86_64__ ++#if defined(__x86_64__) + /* __alloca is a normal function call, which uses %rcx as the argument. */ + cfi_startproc() + __alloca: +@@ -74,7 +78,7 @@ ___chkstk: + pushq %r11 + ret + cfi_endproc() +-#else ++#elif defined(__i386__) + cfi_startproc() + ___chkstk: + __alloca: +@@ -103,6 +107,14 @@ __alloca: + pushl 4(%eax) + ret + cfi_endproc() ++#elif defined(__aarch64__) ++ cfi_startproc() ++___chkstk: ++__alloca: ++ // TODO ++ cfi_endproc() ++#else ++ #error "Unsupported architecture" + #endif /* __x86_64__ */ + #endif /* L_chkstk */ + +@@ -111,7 +123,7 @@ __alloca: + We avoid clobbering any registers. Unlike ___chkstk, it just probes the + stack and does no stack allocation. */ + .global ___chkstk_ms +-#ifdef __x86_64__ ++#if defined(__x86_64__) + cfi_startproc() + ___chkstk_ms: + pushq %rcx /* save temps */ +@@ -137,7 +149,7 @@ ___chkstk_ms: + cfi_pop(%rcx) + ret + cfi_endproc() +-#else ++#elif defined(__i386__) + cfi_startproc() + ___chkstk_ms: + pushl %ecx /* save temp */ +@@ -163,5 +175,12 @@ ___chkstk_ms: + cfi_pop(%ecx) + ret + cfi_endproc() ++#elif defined(__aarch64__) ++ cfi_startproc() ++___chkstk_ms: ++ // TODO ++ cfi_endproc() ++#else ++ #error "Unsupported architecture" + #endif /* __x86_64__ */ + #endif /* L_chkstk_ms */ +diff --git a/libgcc/unwind-seh.c b/libgcc/unwind-seh.c +index 34b662b8eaf..d31f0984f28 100644 +--- a/libgcc/unwind-seh.c ++++ b/libgcc/unwind-seh.c +@@ -147,7 +147,7 @@ void * + _Unwind_FindEnclosingFunction (void *pc) + { + PRUNTIME_FUNCTION entry; +- ULONG64 ImageBase; ++ DWORD_PTR ImageBase; + + entry = RtlLookupFunctionEntry ((ULONG64)pc, &ImageBase, NULL); + +diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc +index 890a4c53e2d..622dd354574 100644 +--- a/libstdc++-v3/src/c++20/tzdb.cc ++++ b/libstdc++-v3/src/c++20/tzdb.cc +@@ -70,7 +70,7 @@ namespace __gnu_cxx + #else + [[gnu::weak]] const char* zoneinfo_dir_override(); + +-#if defined(__APPLE__) || defined(__hpux__) ++#if defined(__APPLE__) || defined(__hpux__) || defined(__aarch64__) + // Need a weak definition for Mach-O. + [[gnu::weak]] const char* zoneinfo_dir_override() + { diff --git a/patches/gcc/0002-cygming-extern.patch b/patches/gcc/0002-cygming-extern.patch new file mode 100644 index 000000000..5679e1d8c --- /dev/null +++ b/patches/gcc/0002-cygming-extern.patch @@ -0,0 +1,125 @@ +diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h +index 20992ef4312..31d87f23d01 100644 +--- a/gcc/config/aarch64/cygming.h ++++ b/gcc/config/aarch64/cygming.h +@@ -67,65 +67,26 @@ along with GCC; see the file COPYING3. If not see + #define LPREFIX (TARGET_64BIT ? ".L" : "L") + + #include +-#ifdef __MINGW32__ +-#include +-#endif + + #undef TARGET_SEH + #define TARGET_SEH 1 + + #define TARGET_ASM_NAMED_SECTION aarch64_pe_asm_named_section + +-/* SEH support */ +-extern void aarch64_pe_seh_init (FILE *); +-extern void aarch64_pe_seh_end_prologue (FILE *); +-extern void aarch64_pe_seh_function_prologue (FILE *); +-extern void aarch64_pe_seh_cold_init (FILE *, const char *); +-extern void aarch64_pe_seh_unwind_emit (FILE *, rtx_insn *); +-extern void aarch64_pe_seh_emit_except_personality (rtx); +-extern void aarch64_pe_seh_init_sections (void); +-extern void aarch64_pe_seh_asm_final_postscan_insn (FILE *stream, rtx_insn *insn, rtx*, int); +- +-/* In aarch64_c */ +-extern void aarch64_pe_asm_named_section (const char *, unsigned int, tree); +-extern bool aarch64_pe_valid_dllimport_attribute_p (const_tree); +-extern void aarch64_pe_maybe_record_exported_symbol (tree, const char *, int); +- +-/* In winnt */ +-extern void aarch64_print_reg (rtx, int, FILE*); +-extern void aarch64_pe_end_function (FILE *f, const char *, tree); +-extern void aarch64_pe_end_cold_function (FILE *f, const char *, tree); +-extern void aarch64_pe_end_epilogue (FILE *file); +-extern void aarch64_pe_begin_epilogue (FILE *file); +-extern void aarch64_pe_file_end (void); +-extern void aarch64_pe_declare_function_type (FILE *file, const char *name, int pub); +-extern void aarch64_pe_record_external_function (tree decl, const char *name); +-extern void aarch64_pe_record_stub (const char *name); +- + #define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P aarch64_pe_valid_dllimport_attribute_p + + #define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1 + +-#define TARGET_OS_CPP_BUILTINS() \ +- do \ +- { \ +- builtin_define ("__MSVCRT__"); \ +- builtin_define ("__MINGW32__"); \ +- builtin_define ("_WIN32"); \ +- builtin_define ("__SEH__"); \ +- builtin_define_std ("WIN32"); \ +- builtin_define_std ("WINNT"); \ +- builtin_define_with_int_value ("_INTEGRAL_MAX_BITS", \ +- TYPE_PRECISION (intmax_type_node));\ +- builtin_define ("__MINGW64__"); \ +- builtin_define_std ("WIN64"); \ +- builtin_define ("_WIN64"); \ +- builtin_define ("__stdcall=__attribute__((__stdcall__))"); \ +- builtin_define ("__fastcall=__attribute__((__fastcall__))"); \ +- builtin_define ("__thiscall=__attribute__((__thiscall__))"); \ +- builtin_define ("__cdecl=__attribute__((__cdecl__))"); \ +- } \ +- while (0) ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ if (TARGET_SEH) \ ++ builtin_define ("__SEH__"); \ ++ builtin_define ("__stdcall=__attribute__((__stdcall__))"); \ ++ builtin_define ("__fastcall=__attribute__((__fastcall__))"); \ ++ builtin_define ("__thiscall=__attribute__((__thiscall__))"); \ ++ builtin_define ("__cdecl=__attribute__((__cdecl__))"); \ ++ EXTRA_OS_CPP_BUILTINS (); \ ++ } while (0) + + /* Windows64 continues to use a 32-bit long type. */ + #undef LONG_TYPE_SIZE +--- a/gcc/config/aarch64/aarch64-protos.h ++++ b/gcc/config/aarch64/aarch64-protos.h +@@ -744,6 +745,32 @@ private: + bool m_old_general_regs_only; + }; + ++/* SEH support */ ++extern void aarch64_pe_seh_init (FILE *); ++extern void aarch64_pe_seh_end_prologue (FILE *); ++extern void aarch64_pe_seh_function_prologue (FILE *); ++extern void aarch64_pe_seh_cold_init (FILE *, const char *); ++extern void aarch64_pe_seh_unwind_emit (FILE *, rtx_insn *); ++extern void aarch64_pe_seh_emit_except_personality (rtx); ++extern void aarch64_pe_seh_init_sections (void); ++extern void aarch64_pe_seh_asm_final_postscan_insn (FILE *stream, rtx_insn *insn, rtx*, int); ++ ++/* In aarch64_c */ ++extern void aarch64_pe_asm_named_section (const char *, unsigned int, tree); ++extern bool aarch64_pe_valid_dllimport_attribute_p (const_tree); ++extern void aarch64_pe_maybe_record_exported_symbol (tree, const char *, int); ++ ++/* In winnt */ ++extern void aarch64_print_reg (rtx, int, FILE*); ++extern void aarch64_pe_end_function (FILE *f, const char *, tree); ++extern void aarch64_pe_end_cold_function (FILE *f, const char *, tree); ++extern void aarch64_pe_end_epilogue (FILE *file); ++extern void aarch64_pe_begin_epilogue (FILE *file); ++extern void aarch64_pe_file_end (void); ++extern void aarch64_pe_declare_function_type (FILE *file, const char *name, int pub); ++extern void aarch64_pe_record_external_function (tree decl, const char *name); ++extern void aarch64_pe_record_stub (const char *name); ++ + void aarch64_post_cfi_startproc (void); + poly_int64 aarch64_initial_elimination_offset (unsigned, unsigned); + int aarch64_get_condition_code (rtx); +--- a/gcc/config/aarch64/winnt.cc ++++ b/gcc/config/aarch64/winnt.cc +@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see + #include "options.h" + #include "memmodel.h" + #include "emit-rtl.h" ++#include "aarch64-protos.h" + + #define TARGET_SEH 1 + diff --git a/patches/mingw/0001-aarch64-cygwin.patch b/patches/mingw/0001-aarch64-cygwin.patch new file mode 100644 index 000000000..bf961698d --- /dev/null +++ b/patches/mingw/0001-aarch64-cygwin.patch @@ -0,0 +1,26 @@ +diff --git a/mingw-w64-headers/crt/_cygwin.h b/mingw-w64-headers/crt/_cygwin.h +index 78452cf2b..9f6a312a7 100644 +--- a/mingw-w64-headers/crt/_cygwin.h ++++ b/mingw-w64-headers/crt/_cygwin.h +@@ -29,7 +29,7 @@ + The Cygwin-targeting gcc does not define it by default, same as + with _WIN32. Therefore we set it here. The result is that _WIN64 + is only defined if Windows headers are included. */ +-#ifdef __x86_64__ ++#if defined(__x86_64__) || defined(__aarch64__) + #define _WIN64 + #endif + +diff --git a/mingw-w64-headers/crt/corecrt.h b/mingw-w64-headers/crt/corecrt.h +index abb720885..37957d75a 100644 +--- a/mingw-w64-headers/crt/corecrt.h ++++ b/mingw-w64-headers/crt/corecrt.h +@@ -41,7 +41,7 @@ typedef unsigned int size_t; + #ifndef _SSIZE_T_DEFINED + #define _SSIZE_T_DEFINED + #undef ssize_t +-#ifdef _WIN64 ++#if defined(_WIN64) && !defined(__aarch64__) + __MINGW_EXTENSION typedef __int64 ssize_t; + #else + typedef int ssize_t; diff --git a/return-zero/.gitignore b/return-zero/.gitignore new file mode 100644 index 000000000..9934fc8f1 --- /dev/null +++ b/return-zero/.gitignore @@ -0,0 +1,6 @@ +*.exe +*.dll +*.o +*.S +*.objdump +*.dumpbin \ No newline at end of file diff --git a/return-zero/build.sh b/return-zero/build.sh new file mode 100755 index 000000000..646b412de --- /dev/null +++ b/return-zero/build.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +OLD_PATH=$PATH + +PATH="/home/blackhex/cross-x86_64-pc-cygwin-msvcrt/bin:$OLD_PATH" + +x86_64-pc-cygwin-gcc return-zero.c -g -O0 -c -o return-zero-x86_64-cygwin.o +x86_64-pc-cygwin-gcc return-zero.c -g -O0 -S -o return-zero-x86_64-cygwin.S +x86_64-pc-cygwin-gcc return-zero-x86_64-cygwin.o -g -O0 -o return-zero-x86_64-cygwin.exe +x86_64-pc-cygwin-objdump -S -d return-zero-x86_64-cygwin.exe > return-zero-x86_64-cygwin.objdump +dumpbin.exe /ALL return-zero-x86_64-cygwin.exe > return-zero-x86_64-cygwin.dumpbin +dumpbin.exe /ALL cygwin1-x86_64-cygwin.dll > cygwin1-x86_64-cygwin.dumpbin + +PATH="/home/blackhex/cross-aarch64-pc-cygwin-msvcrt/bin:$OLD_PATH" + +aarch64-pc-cygwin-gcc return-zero.c -g -O0 -c -o return-zero-aarch64-cygwin.o +aarch64-pc-cygwin-gcc return-zero.c -g -O0 -S -o return-zero-aarch64-cygwin.S +aarch64-pc-cygwin-gcc return-zero-aarch64-cygwin.o -Wl,--dynamicbase -Wl,--high-entropy-va -g -O0 -o return-zero-aarch64-cygwin.exe +aarch64-pc-cygwin-objdump -S -d return-zero-aarch64-cygwin.exe > return-zero-aarch64-cygwin.objdump +dumpbin.exe /ALL return-zero-aarch64-cygwin.exe > return-zero-aarch64-cygwin.dumpbin +dumpbin.exe /ALL cygwin1-aarch64-cygwin.dll > cygwin1-aarch64-cygwin.dumpbin + +PATH="/home/blackhex/cross-aarch64-w64-mingw32-msvcrt/bin:$OLD_PATH" + +aarch64-w64-mingw32-gcc return-zero.c -g -O0 -c -o return-zero-aarch64-mingw.o +aarch64-w64-mingw32-gcc return-zero.c -g -O0 -S -o return-zero-aarch64-mingw.S +aarch64-w64-mingw32-gcc return-zero-aarch64-mingw.o -g -O0 -o return-zero-aarch64-mingw.exe +aarch64-w64-mingw32-objdump -S -d return-zero-aarch64-mingw.exe > return-zero-aarch64-mingw.objdump +dumpbin.exe /ALL return-zero-aarch64-mingw.exe > return-zero-aarch64-mingw.dumpbin diff --git a/return-zero/return-zero.c b/return-zero/return-zero.c new file mode 100644 index 000000000..0fb4389f7 --- /dev/null +++ b/return-zero/return-zero.c @@ -0,0 +1,3 @@ +int main(int argc, char *argv[]) { + return 0; +} diff --git a/scripts/find_symbol.py b/scripts/find_symbol.py new file mode 100755 index 000000000..075175bb1 --- /dev/null +++ b/scripts/find_symbol.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys +import getopt + + +def find_symbol(target, directory, symbol): + for root, _, files in os.walk(directory): + for file in files: + if file.endswith(".o") or file.endswith(".a"): + file_path = os.path.join(root, file) + try: + output = subprocess.check_output( + [f"{target}-gcc-nm", file_path], universal_newlines=True + ) + if symbol in output: + print(f"Symbol {symbol} found in {file_path}") + print("\t" + "\n\t".join(filter(lambda line: symbol in line, output.split("\n")))) + except subprocess.CalledProcessError: + print(f"Error processing {file_path}", file=sys.stderr) + + +def help(): + print("find_symbol.py -t -d -s ") + print("\tA\tThe symbol’s value is absolute, and will not be changed by further linking.") + print("\ttT\tThe symbol is in the text (code) section.") + print("\trR\tThe symbol is in a read only data section.") + print("\tI\tThe symbol is an indirect reference to another symbol.") + print("\twW\tThe symbol is a weak symbol that has not been specifically tagged as a weak object symbol.") + print("\tU\tThe symbol is undefined.") + + +def main(argv): + target = "aarch64-pc-cygwin" + directory = "." + symbol = "" + try: + opts, _ = getopt.getopt(argv, "ht:d:s:", ["directory=", "symbol=", "target="]) + except getopt.GetoptError: + help() + sys.exit(2) + for opt, arg in opts: + if opt == "-h": + help() + sys.exit() + elif opt in ("-t", "--target"): + target = arg + elif opt in ("-d", "--directory"): + directory = arg + elif opt in ("-s", "--symbol"): + symbol = arg + find_symbol(target, directory, symbol) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/update.sh b/update.sh new file mode 100755 index 000000000..749d75528 --- /dev/null +++ b/update.sh @@ -0,0 +1,50 @@ +BINUTILS_BRANCH=woarm64 +GCC_BRANCH=woarm64 +MINGW_BRANCH=woarm64 +CYGWIN_BRANCH=main +COCOM_BRANCH=master + +pushd code/binutils-master + git fetch --all + git reset --hard + git switch $BINUTILS_BRANCH + git branch + git pull origin $BINUTILS_BRANCH +popd + +pushd code/gcc-master + git fetch --all + git reset --hard + git switch $GCC_BRANCH + git branch + git pull origin $GCC_BRANCH +popd + +pushd code/mingw-w64-master + git fetch --all + git reset --hard + git switch $MINGW_BRANCH + git branch + git pull origin $MINGW_BRANCH +popd + +pushd code/cocom-master + git fetch --all + git reset --hard + git switch $COCOM_BRANCH + git branch + git pull origin $COCOM_BRANCH +popd + +pushd code/cygwin-master + git fetch --all + git reset --hard + git switch $CYGWIN_BRANCH + git branch + git pull origin $CYGWIN_BRANCH +popd + +pushd code/cygwin-packages + git submodule init + git submodule update --recursive --remote +popd