Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for ARM64 Windows #8142

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1ee5dfd
added aarch64 target support for wsl_tools
cocoa-xu Feb 17, 2024
f4eb21e
added aarch64 target support
cocoa-xu Feb 19, 2024
554b2e3
added config cache files for aarch64 windows target
cocoa-xu Feb 17, 2024
53c2f2e
added installation guide for aarch64 windows
cocoa-xu Feb 17, 2024
af26c84
arm64 jit now works on windows
cocoa-xu Feb 17, 2024
e820d26
fix cross-compile on x86_64 for aarch64
cocoa-xu Feb 18, 2024
52b7d79
[WIP] updated find_redist
cocoa-xu Feb 19, 2024
4d00bfc
fix i_perf_counter on aarch64 windows
cocoa-xu Feb 19, 2024
51be569
fix typo in wsl_tools reg_query.sh
cocoa-xu Feb 19, 2024
945c8a1
Update configure scripts
cocoa-xu Feb 19, 2024
b5f6d21
set linker opt `/MACHINE` for all `$CONFIG_SUBTYPE`
cocoa-xu Feb 19, 2024
021c2d1
updated emu_cc.sh
cocoa-xu Feb 19, 2024
d97c4bc
clang-format
cocoa-xu Feb 19, 2024
ede4e58
updated otp_build
cocoa-xu Feb 19, 2024
0f5b5b9
use simple list initializers instead of designated initializers
cocoa-xu Feb 19, 2024
6bf0b6e
added back base case local-*-windows
cocoa-xu Feb 19, 2024
30f9c35
format
cocoa-xu Feb 19, 2024
5726b54
only set VEREDIST var for arm64
cocoa-xu Feb 19, 2024
a7ac04d
updated installation guide for using wxWidgets
cocoa-xu Feb 19, 2024
27d808c
updated nsis script
cocoa-xu Feb 19, 2024
db43638
check newer vcredist.exe filenames
cocoa-xu Feb 19, 2024
576dcb0
fix a typo
cocoa-xu Feb 19, 2024
747e27a
updated nsis script
cocoa-xu Feb 19, 2024
7a719a0
Update erts/etc/win32/nsis/find_redist.sh
cocoa-xu Feb 20, 2024
551751f
fix typo in nsis script
cocoa-xu Feb 20, 2024
2d79abb
use fwrite in `display_string_2` for windows
cocoa-xu Feb 23, 2024
892019a
handle nanosecond in erlang code
cocoa-xu Feb 24, 2024
0641273
fix display_string_2
cocoa-xu Mar 9, 2024
f61d617
Merge branch 'master' into cx/windows-arm64
cocoa-xu May 20, 2024
88a1244
Merge branch 'master' into cx/windows-arm64
cocoa-xu Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
521 changes: 521 additions & 0 deletions HOWTO/INSTALL-WIN32-ARM64.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions HOWTO/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ Operating system

[$ERL_TOP/HOWTO/INSTALL-CROSS.md]: INSTALL-CROSS.md
[$ERL_TOP/HOWTO/INSTALL-WIN32.md]: INSTALL-WIN32.md
[$ERL_TOP/HOWTO/INSTALL-WIN32-ARM64.md]: INSTALL-WIN32-ARM64.md
[DESTDIR]: http://www.gnu.org/prep/standards/html_node/DESTDIR.html
[Building in Git]: #advanced-configuration-and-build-of-erlang-otp_Building_Within-Git
[Advanced Configure]: #advanced-configuration-and-build-of-erlang-otp_Configuring
Expand Down
80 changes: 72 additions & 8 deletions erts/configure
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,27 @@ test -n "$target_alias" &&

# Adjust for local legacy windows hack...
case $host in #(
local-aarch64-*-windows) :

host=win32
host_os=win32
host_vendor=
host_cpu=aarch64
;; #(
local-x86_64-*-windows) :

host=win32
host_os=win32
host_vendor=
host_cpu=x86_64
;; #(
local-i686-*-windows) :

host=win32
host_os=win32
host_vendor=
host_cpu=i686
;; #(
local-*-windows) :

host=win32
Expand All @@ -3808,6 +3829,27 @@ esac

# Adjust for local legacy windows hack...
case $build in #(
local-aarch64-*-windows) :

build=win32
build_os=win32
build_vendor=
build_cpu=aarch64
;; #(
local-x86_64-*-windows) :

build=win32
build_os=win32
build_vendor=
build_cpu=x86_64
;; #(
local-i686-*-windows) :

build=win32
build_os=win32
build_vendor=
build_cpu=i686
;; #(
local-*-windows) :

build=win32
Expand All @@ -3822,6 +3864,27 @@ esac

# Adjust for local legacy windows hack...
case $target in #(
local-aarch64-*-windows) :

target=win32
target_os=win32
target_vendor=
target_cpu=aarch64
;; #(
local-x86_64-*-windows) :

target=win32
target_os=win32
target_vendor=
target_cpu=x86_64
;; #(
local-i686-*-windows) :

target=win32
target_os=win32
target_vendor=
target_cpu=i686
;; #(
local-*-windows) :

target=win32
Expand All @@ -3833,18 +3896,19 @@ esac
;;
esac

if test "$cross_compiling" = "yes" -a "$build" = "$host"
if test "$cross_compiling" = "yes" -a "$build" = "$host" -a "$build_cpu" = "$host_cpu"
then :
as_fn_error $? "
Cross compiling with the same canonicalized 'host' value
as the canonicalized 'build' value.
Cross compiling with the same canonicalized 'host' and 'host_cpu'
values as the canonicalized 'build' and 'build_cpu' values

We are cross compiling since the '--host=$host_alias'
and the '--build=$build_alias' arguments differ. When
cross compiling Erlang/OTP, also the canonicalized values of
the '--build' and the '--host' arguments *must* differ. The
canonicalized values of these arguments however both equals:
$host
host = build = $host,
host_cpu = build_cpu = $host_cpu

You can check the canonical value by passing a value as
argument to the 'make/autoconf/config.sub' script.
Expand Down Expand Up @@ -6402,11 +6466,11 @@ if test x$ac_prog_cxx_stdcxx = xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5
printf %s "checking for $CXX option to enable C++11 features... " >&6; }
if test ${ac_cv_prog_cxx_cxx11+y}
if test ${ac_cv_prog_cxx_11+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_cv_prog_cxx_cxx11=no
ac_cv_prog_cxx_11=no
ac_save_CXX=$CXX
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
Expand Down Expand Up @@ -6448,11 +6512,11 @@ if test x$ac_prog_cxx_stdcxx = xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5
printf %s "checking for $CXX option to enable C++98 features... " >&6; }
if test ${ac_cv_prog_cxx_cxx98+y}
if test ${ac_cv_prog_cxx_98+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_cv_prog_cxx_cxx98=no
ac_cv_prog_cxx_98=no
ac_save_CXX=$CXX
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
Expand Down
7 changes: 4 additions & 3 deletions erts/emulator/beam/jit/arm/beam_asm_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ BeamGlobalAssembler::BeamGlobalAssembler(JitAllocator *allocator)
stop = (ErtsCodePtr)((char *)getBaseAddress() + code.codeSize());
}

ranges.push_back({.start = start,
.stop = stop,
.name = code.labelEntry(labels[val.first])->name()});
ranges.push_back(AsmRange{start,
stop,
code.labelEntry(labels[val.first])->name(),
{}});
}

(void)beamasm_metadata_insert("global",
Expand Down
18 changes: 6 additions & 12 deletions erts/emulator/beam/jit/arm/beam_asm_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,7 @@ const Label &BeamModuleAssembler::resolve_label(const Label &target,
anchor = a.newNamedLabel(name.str().c_str());
}

auto it = _veneers.emplace(target.id(),
Veneer{.latestOffset = maxOffset,
.anchor = anchor,
.target = target});
auto it = _veneers.emplace(target.id(), Veneer{maxOffset, anchor, target});

const Veneer &veneer = it->second;
_pending_veneers.emplace(veneer);
Expand Down Expand Up @@ -589,10 +586,8 @@ arm::Mem BeamModuleAssembler::embed_constant(const ArgVal &value,
}
}

auto it = _constants.emplace(value,
Constant{.latestOffset = maxOffset,
.anchor = a.newLabel(),
.value = value});
auto it =
_constants.emplace(value, Constant{maxOffset, a.newLabel(), value});
const Constant &constant = it->second;
_pending_constants.emplace(constant);

Expand All @@ -607,10 +602,9 @@ arm::Mem BeamModuleAssembler::embed_label(const Label &label,

ASSERT(disp >= dispMin && disp <= dispMax);

auto it = _embedded_labels.emplace(label.id(),
EmbeddedLabel{.latestOffset = maxOffset,
.anchor = a.newLabel(),
.label = label});
auto it = _embedded_labels.emplace(
label.id(),
EmbeddedLabel{maxOffset, a.newLabel(), label});
ASSERT(it.second);
const EmbeddedLabel &embedded_label = it.first->second;
_pending_labels.emplace(embedded_label);
Expand Down
5 changes: 5 additions & 0 deletions erts/emulator/beam/jit/arm/instr_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3082,7 +3082,12 @@ void BeamModuleAssembler::emit_i_perf_counter() {
Label next = a.newLabel(), small = a.newLabel();

emit_enter_runtime_frame();
#ifdef WIN32
/* Call the function pointer used by erts_sys_perf_counter */
runtime_call<0>(erts_sys_time_data__.r.o.sys_hrtime);
#else
runtime_call<0>(erts_sys_time_data__.r.o.perf_counter);
#endif
emit_leave_runtime_frame();

a.asr(TMP1, ARG1, imm(SMALL_BITS - 1));
Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/jit/beam_jit_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ struct BeamModuleAssemblerCommon {
}

/* Helpers */
const auto &getTypeEntry(const ArgSource &arg) const {
const BeamArgType &getTypeEntry(const ArgSource &arg) const {
auto typeIndex =
arg.isRegister() ? arg.as<ArgRegister>().typeIndex() : 0;
ASSERT(typeIndex < beam->types.count);
return static_cast<BeamArgType &>(beam->types.entries[typeIndex]);
}

auto getTypeUnion(const ArgSource &arg) const {
BeamTypeId getTypeUnion(const ArgSource &arg) const {
if (arg.isRegister()) {
return getTypeEntry(arg).type();
}
Expand Down
6 changes: 6 additions & 0 deletions erts/etc/win32/nsis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ WTARGET_DIR=$(shell (w32_path.sh -d "$(TARGET_DIR)"))
ifeq ($(CONFIG_SUBTYPE),win64)
WINTYPE=win64
REDIST_TARGET=vcredist_x64.exe
else ifeq ($(CONFIG_SUBTYPE),arm64)
WINTYPE=arm64
REDIST_TARGET=vcredist_arm64.exe
else ifeq ($(CONFIG_SUBTYPE),x64_arm64)
WINTYPE=arm64
REDIST_TARGET=vcredist_arm64.exe
else
WINTYPE=win32
REDIST_TARGET=vcredist_x86.exe
Expand Down
16 changes: 12 additions & 4 deletions erts/etc/win32/nsis/erlang20.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Var STARTMENU_FOLDER

;Folder selection page
!if ${WINTYPE} == "win64"
InstallDir "$PROGRAMFILES64\Erlang OTP"
InstallDir "$PROGRAMFILES64\Erlang OTP"
!else
InstallDir "$PROGRAMFILES\Erlang OTP"
InstallDir "$PROGRAMFILES\Erlang OTP"
!endif
;Remember install folder
InstallDirRegKey HKLM "SOFTWARE\Ericsson\Erlang\${ERTS_VERSION}" ""
Expand All @@ -68,7 +68,11 @@ Var STARTMENU_FOLDER
!if ${WINTYPE} == "win64"
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${OTP_PRODUCT} ${OTP_RELEASE} (x64)"
!else
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${OTP_PRODUCT} ${OTP_RELEASE} (i386)"
!if ${WINTYPE} == "arm64"
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${OTP_PRODUCT} ${OTP_RELEASE} (arm64)"
!else
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${OTP_PRODUCT} ${OTP_RELEASE} (x64)"
!endif
cocoa-xu marked this conversation as resolved.
Show resolved Hide resolved
!endif

;--------------------------------
Expand Down Expand Up @@ -104,7 +108,7 @@ Var STARTMENU_FOLDER

VIProductVersion "${OTP_VERSION_LONG}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "Ericsson AB"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${OTP_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${OTP_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Erlang/OTP installer"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright Ericsson AB 2010-${YEAR}. All Rights Reserved."
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "Erlang/OTP"
Expand Down Expand Up @@ -385,6 +389,10 @@ Function .onInit
StrCmpS ${WINTYPE} "win64" +1 +4
StrCpy $archprefix "amd64"
StrCpy $sysnativedir "$WINDIR\sysnative"
Goto +4
StrCmpS ${WINTYPE} "arm64" +1 +6
StrCpy $archprefix "arm64"
StrCpy $sysnativedir "$WINDIR\sysnative"
Goto +3
StrCpy $archprefix "x86"
StrCpy $sysnativedir $SYSDIR
Expand Down
15 changes: 13 additions & 2 deletions erts/etc/win32/nsis/find_redist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,19 @@ add_path_element()
if [ "$1" = "win64" ]; then
AMD64DIR=true
VCREDIST=vcredist_x64
VCREDIST2=vcredist.x64
COMPONENTS="cl amd64 bin vc"
elif [ "$1" = "win32" ]; then
AMD64DIR=false
VCREDIST=vcredist_x86
VCREDIST2=vcredist.x86
COMPONENTS="cl bin vc"
elif [ "$1" = "arm64" ]; then
AMD64DIR=false
VCREDIST=vcredist_arm64
VCREDIST2=vcredist.arm64
else
echo "TARGET argument should win32 or win64"
echo "TARGET argument should win32, win64 or arm64"
exit 2
fi

Expand All @@ -101,11 +107,16 @@ if [ x"$VCToolsRedistDir" != x"" ]; then
echo "$File"
exit 0
fi
File="$VCToolsRedistDir/$VCREDIST2.exe"
if [ -r "$File" ]; then
echo "$File"
exit 0
fi
fi

CLPATH=`lookup_prog_in_path cl`
if [ -z "$CLPATH" ]; then
echo "Can not locate cl.exe and vcredist_x86/x64.exe - OK if using mingw" >&2
echo "Can not locate cl.exe and vcredist_x86/x64/arm64.exe - OK if using mingw" >&2
cocoa-xu marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi

Expand Down
12 changes: 10 additions & 2 deletions erts/etc/win32/wsl_tools/SetupWSLcross.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
rem Setup MCL and echo the environment
rem Usage: eval `cmd.exe /c SetupWSLcross.bat x64`

set MACHINE="%~1"
IF "%~1"=="x86" GOTO search
IF "%~1"=="x64" GOTO search
IF "%~1"=="arm64" GOTO search
IF "%~1"=="amd64_arm64" GOTO search

GOTO badarg

Expand Down Expand Up @@ -67,7 +70,12 @@ GOTO no_vcvars

:continue

FOR /F "delims==" %%F IN ('where cl.exe') DO SET _cl_exec_=%%F
FOR /F "delims==" %%F IN ('where cl.exe') DO (
SET _cl_exec_=%%F
goto set_cl_path
)

:set_cl_path
FOR %%F IN ("%_cl_exec_%") DO SET CL_PATH=%%~dpF

FOR /F "delims==" %%F IN ('where rc.exe') DO SET _rc_exec_=%%F
Expand All @@ -87,7 +95,7 @@ wsl.exe echo "# Eval this file eval \`cmd.exe /c SetupWSLcross.bat\`"
exit

:badarg
echo "Bad TARGET or not specified: %~1 expected x86 or x64"
echo "Bad TARGET or not specified: %~1 expected x86, x64, arm64 or x64_arm64"
exit

:no_vcvars
Expand Down
2 changes: 2 additions & 0 deletions erts/etc/win32/wsl_tools/reg_query.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ BACKED=`echo "$1" | sed 's,/,\\\\,g'`

if [ $CONFIG_SUBTYPE = "win64" ]; then
REG_OPT=" /reg:64"
elif [ X"$CONFIG_SUBTYPE" = X"arm64" -o X"$CONFIG_SUBTYPE" = X"x64_arm64" ]; then
REG_OPT=" /reg:64"
else
REG_OPT=" /reg:32"
fi
Expand Down
11 changes: 10 additions & 1 deletion erts/etc/win32/wsl_tools/vc/cc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ SAVE="$@"
# Constants
COMMON_CFLAGS="-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT -D_CRT_SECURE_NO_DEPRECATE"

if [ "$CONFIG_SUBTYPE" = "x64_arm64" -o "$CONFIG_SUBTYPE" = "arm64" ]; then
MACHINE="ARM64"
COMMON_CFLAGS="${COMMON_CFLAGS} -D__aarch64__"
elif [ "$CONFIG_SUBTYPE" = "win64" ]; then
MACHINE="x64"
else
MACHINE="x86"
fi

# Variables
# The stdout and stderr for the compiler
MSG_FILE=/tmp/cl.exe.$$.1
Expand Down Expand Up @@ -64,7 +73,7 @@ CMD=""
# All the c source files, in unix style
SOURCES=""
# All the options to pass to the linker, kept in Unix style
LINKCMD=""
LINKCMD="-MACHINE:${MACHINE}"

cocoa-xu marked this conversation as resolved.
Show resolved Hide resolved

# Loop through the parameters and set the above variables accordingly
Expand Down
Loading
Loading