Categories: Assembly, OpenJDK

Selecting the Proper OpenJDK Windows AArch64 Assembler

A few months ago, I was investigating some exception handling OpenJDK bugs on Windows AArch64. One of the bugs was in the safefetch implementation. I needed to switch part of the implementation to assembly language (similar to the Linux and macosx aarch64 safefetch implementations). Compilation failed after I added the new safefetch_windows_aarch64.S assembly source file. The failing command line was in the .cmdline file when the build terminated:

From build\windows-aarch64-server-slowdebug\make-support\failure-logs\hotspot_variant-server_libjvm_objs_safefetch_windows_aarch64.obj.cmdline

/cygdrive/c/java/forks/dups2/openjdk/jdk/build/windows-aarch64-server-slowdebug/fixpath exec /cygdrive/c/progra~1/micros~1/2022/enterprise/vc/tools/msvc/14.44.35207/bin/hostarm64/arm64/ml64.exe -nologo -c -I/cygdrive/c/java/forks/dups2/openjdk/jdk/src/hotspot/os_cpu/windows_aarch64 -I/cygdrive/c/java/forks/dups2/openjdk/jdk/src/hotspot/os/windows -I/cygdrive/c/java/forks/dups2/openjdk/jdk/src/hotspot/os/windows -Fo/cygdrive/c/java/forks/dups2/openjdk/jdk/build/windows-aarch64-server-slowdebug/hotspot/variant-server/libjvm/objs/safefetch_windows_aarch64.obj -Ta /cygdrive/c/java/forks/dups2/openjdk/jdk/src/hotspot/os_cpu/windows_aarch64/safefetch_windows_aarch64.S

I could manually reproduce the failure by running the command in a developer command prompt:

C:\dev\temp> ml64 -nologo -Ta safefetch_windows_aarch64.S
 Assembling: safefetch_windows_aarch64.S
safefetch_windows_aarch64.S(31) : error A2008:syntax error : .
safefetch_windows_aarch64.S(32) : error A2008:syntax error : .
safefetch_windows_aarch64.S(33) : error A2008:syntax error : .type
safefetch_windows_aarch64.S(34) : error A2034:must be in segment block
safefetch_windows_aarch64.S(36) : error A2034:must be in segment block
safefetch_windows_aarch64.S(37) : error A2034:must be in segment block
safefetch_windows_aarch64.S(38) : error A2008:syntax error : ldr
safefetch_windows_aarch64.S(39) : error A2034:must be in segment block
safefetch_windows_aarch64.S(41) : error A2008:syntax error : .
safefetch_windows_aarch64.S(42) : error A2008:syntax error : .
safefetch_windows_aarch64.S(43) : error A2008:syntax error : .type
safefetch_windows_aarch64.S(44) : error A2034:must be in segment block
safefetch_windows_aarch64.S(45) : error A2034:must be in segment block
safefetch_windows_aarch64.S(46) : error A2034:must be in segment block
safefetch_windows_aarch64.S(53) : error A2008:syntax error : .
safefetch_windows_aarch64.S(54) : error A2008:syntax error : .
safefetch_windows_aarch64.S(55) : error A2008:syntax error : .type
safefetch_windows_aarch64.S(56) : error A2034:must be in segment block
safefetch_windows_aarch64.S(58) : error A2008:syntax error : .
safefetch_windows_aarch64.S(59) : error A2008:syntax error : .
safefetch_windows_aarch64.S(60) : error A2008:syntax error : .type
safefetch_windows_aarch64.S(61) : error A2034:must be in segment block
safefetch_windows_aarch64.S(62) : error A2034:must be in segment block
safefetch_windows_aarch64.S(63) : error A2008:syntax error : ldr
safefetch_windows_aarch64.S(64) : error A2034:must be in segment block
safefetch_windows_aarch64.S(66) : error A2008:syntax error : .
safefetch_windows_aarch64.S(67) : error A2008:syntax error : .
safefetch_windows_aarch64.S(68) : error A2008:syntax error : .type
safefetch_windows_aarch64.S(69) : error A2034:must be in segment block
safefetch_windows_aarch64.S(70) : error A2034:must be in segment block
safefetch_windows_aarch64.S(71) : error A2034:must be in segment block
safefetch_windows_aarch64.S(71) : error A2088:END directive required at end of file

As it turns out, ml64.exe is the x64 assembler – see ML and ML64 command-line reference | Microsoft Learn. I switched to armasm64.exe (see ARM Assembler command-line reference | Microsoft Learn) but it failed with identical arguments.

"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\Hostx64\arm64\armasm64.exe" -nologo -c -Ta safefetch_windows_aarch64.S
error A2029: unknown command-line argument or argument value -c

 Usage:      armasm [<options>] sourcefile objectfile
             armasm [<options>] -o objectfile sourcefile
             armasm -h              for help

Removing only -c gives:

error A2029: unknown command-line argument or argument value -Ta

/Ta filenameAssembles source file whose name doesn’t end with the .asm extension.

ML and ML64 command-line reference | Microsoft Learn

/cAssembles only. Does no linking.

ML and ML64 command-line reference | Microsoft Learn

The -Ta flag in the command line comes from jdk/make/common/native/CompileFile.gmk and the -c flag causing an error is from jdk/make/autoconf/flags-other.m4. I first tried moving the -Ta flag but that broke the build:

Command from build\windows-x86_64-server-slowdebug\make-support\failure-logs\support_native_jdk.incubator.vector_libjsvml_jsvml_d_acos_windows_x86.obj.cmdline

/cygdrive/d/java/ms/dups/openjdk-jdk/build/windows-x86_64-server-slowdebug/fixpath exec /cygdrive/c/progra~1/mib055~1/2022/enterprise/vc/tools/msvc/14.44.35207/bin/hostx64/x64/ml64.exe -nologo -c -Ta -Fo/cygdrive/d/java/ms/dups/openjdk-jdk/build/windows-x86_64-server-slowdebug/support/native/jdk.incubator.vector/libjsvml/jsvml_d_acos_windows_x86.obj /cygdrive/d/java/ms/dups/openjdk-jdk/src/jdk.incubator.vector/windows/native/libjsvml/jsvml_d_acos_windows_x86.S

From build\windows-x86_64-server-slowdebug\make-support\failure-logs\support_native_jdk.incubator.vector_libjsvml_jsvml_d_acos_windows_x86.obj.log

 Assembling: -Fod:\java\ms\dups\openjdk-jdk\build\windows-x86_64-server-slowdebug\support\native\jdk.incubator.vector\libjsvml\jsvml_d_acos_windows_x86.obj
MASM : fatal error A1000:cannot open file : -Fod:\java\ms\dups\openjdk-jdk\build\windows-x86_64-server-slowdebug\support\native\jdk.incubator.vector\libjsvml\jsvml_d_acos_windows_x86.obj

I just needed to have a separate else branch to handle setting up armasm64.exe to avoid passing ml64.exe flags to armasm64.exe. This successfully assembled my AArch64 assembly source file. However, the JVM would terminate with an access violation, which clearly isn’t supposed to happen because the fetch is supposed to be safe, by definition! I asked copilot: when would the program counter pointing at this aarch64 instruction result in an access violation? mov x0, x1. One scenario:

The Program Counter (PC) is pointing to an invalid address

  • If the PC is pointing to a location that is not mapped in the process’s address space (e.g., due to corruption, jumping to unmapped memory, or executing data as code), then fetching the instruction itself could trigger an access violation.
  • Example: If the PC points to a region of memory that has been freed or is protected (e.g., read-only or non-executable), the CPU will raise a fault when trying to fetch or decode the instruction.

This gave me a hint that my assembly instructions were probably not in an executable page! I found the AREA directive details at ARM Compiler armasm Reference Guide Version 6.01. It was tricky that the first AREA argument is a name and could therefore be anything. If I recall correctly, I think the access violation was because I didn’t have the CODE attribute on the AREA. With that fixed, I was able to successfully execute the compiled JVM.

I opened 8365579: ml64.exe is not the right assembler for Windows aarch64 by swesonga · Pull Request #26791 · openjdk/jdk to fix this issue. I branched off from openjdk/jdk at b0f98df75aee1e94a8c4b3eb8d0b1f4e715011ae for my changes. I initially removed the -Ta argument because it appeared to be a no-op. Code review feedback indicated that I need the -Ta flag unless I could document that it is a no-op. I discovered that it is essential e.g. if your assembly sources are in a .obj file!

Here are some of my fix attempts. I started with -Tasdf to ensure that I got an error indicating that this argument was being picked up by the build.

diff --git a/make/common/native/CompileFile.gmk b/make/common/native/CompileFile.gmk
index 26472da6d02..4d8aaef4445 100644
--- a/make/common/native/CompileFile.gmk
+++ b/make/common/native/CompileFile.gmk
@@ -234,9 +234,14 @@ define CreateCompiledNativeFileBody
            $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
           else
             # For assembler calls just create empty dependency lists
+            ifeq ($(OPENJDK_TARGET_CPU), aarch64)
+              $1_NON_ASM_EXTENSION_FLAG :=
+            else
+              $1_NON_ASM_EXTENSION_FLAG := "-Tasdf "
+            endif
            $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
                $$($1_COMPILER) $$($1_FLAGS) \
-               $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE))) \
+               $(CC_OUT_OPTION)$$($1_OBJ) $$($1_NON_ASM_EXTENSION_FLAG) $$($1_SRC_FILE))) \
                | $(TR) -d '\r' | $(GREP) -v -e "Assembling:" || test "$$$$?" = "1" ; \
            $(ECHO) > $$($1_DEPS_FILE) ; \
            $(ECHO) > $$($1_DEPS_TARGETS_FILE)

Attempt 2:

diff --git a/make/common/native/CompileFile.gmk b/make/common/native/CompileFile.gmk
index 26472da6d02..697adbb6e26 100644
--- a/make/common/native/CompileFile.gmk
+++ b/make/common/native/CompileFile.gmk
@@ -155,6 +155,12 @@ define CreateCompiledNativeFileBody
         endif
         $1_FLAGS := $$($1_FLAGS) -DASSEMBLY_SRC_FILE='"$$($1_REL_ASM_SRC)"' \
             -include $(TOPDIR)/make/data/autoheaders/assemblyprefix.h
+      else ifeq ($(TOOLCHAIN_TYPE), microsoft)
+        ifeq ($(OPENJDK_TARGET_CPU), aarch64)
+          $1_NON_ASM_EXTENSION_FLAG :=
+        else
+          $1_NON_ASM_EXTENSION_FLAG := "-Tasdf "
+        endif
       endif
     else ifneq ($$(filter %.cpp %.cc %.mm, $$($1_FILENAME)), )
       # Compile as a C++ or Objective-C++ file
@@ -236,7 +242,7 @@ define CreateCompiledNativeFileBody
             # For assembler calls just create empty dependency lists
            $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
                $$($1_COMPILER) $$($1_FLAGS) \
-               $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE))) \
+               $(CC_OUT_OPTION)$$($1_OBJ) $$($1_NON_ASM_EXTENSION_FLAG) $$($1_SRC_FILE))) \
                | $(TR) -d '\r' | $(GREP) -v -e "Assembling:" || test "$$$$?" = "1" ; \
            $(ECHO) > $$($1_DEPS_FILE) ; \
            $(ECHO) > $$($1_DEPS_TARGETS_FILE)

This resulted in this error, which confirmed that it was a valid place to set the flag:

=== Output from failing command(s) repeated here ===
* For target support_native_jdk.incubator.vector_libjsvml_BUILD_LIBJSVML_run_ld:
LINK : fatal error LNK1181: cannot open input file 'd:\java\forks\dups12\openjdk\jdk\build\windows-x86_64-server-slowdebug\support\native\jdk.incubator.vector\libjsvml\jsvml_d_acos_windows_x86.obj'
* For target support_native_jdk.incubator.vector_libjsvml_jsvml_d_acos_windows_x86.obj:
 Assembling: sdf 
MASM : fatal error A1000:cannot open file : sdf 
* For target support_native_jdk.incubator.vector_libjsvml_jsvml_d_asin_windows_x86.obj:
 Assembling: sdf 
MASM : fatal error A1000:cannot open file : sdf 

After Magnus’s feedback on 8/23, I reverted that change and tried this instead:

diff --git a/make/autoconf/flags.m4 b/make/autoconf/flags.m4
index d50538108a4..8ba1a313cb2 100644
--- a/make/autoconf/flags.m4
+++ b/make/autoconf/flags.m4
@@ -320,6 +320,11 @@ AC_DEFUN([FLAGS_SETUP_TOOLCHAIN_CONTROL],
 [
   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
     CC_OUT_OPTION=-Fo
+    if test "x$OPENJDK_TARGET_CPU" = xaarch64; then
+      AS_NON_ASM_EXTENSION_FLAG=
+    else
+      AS_NON_ASM_EXTENSION_FLAG=-Tazzz
+    endif
   else
     # The option used to specify the target .o,.a or .so file.
     # When compiling, how to specify the to be created object file.
diff --git a/make/common/native/CompileFile.gmk b/make/common/native/CompileFile.gmk
index 26472da6d02..7f8e8ffeddc 100644
--- a/make/common/native/CompileFile.gmk
+++ b/make/common/native/CompileFile.gmk
@@ -236,7 +236,7 @@ define CreateCompiledNativeFileBody
             # For assembler calls just create empty dependency lists
            $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
                $$($1_COMPILER) $$($1_FLAGS) \
-               $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE))) \
+               $(CC_OUT_OPTION)$$($1_OBJ) $(AS_NON_ASM_EXTENSION_FLAG) $$($1_SRC_FILE))) \
                | $(TR) -d '\r' | $(GREP) -v -e "Assembling:" || test "$$$$?" = "1" ; \
            $(ECHO) > $$($1_DEPS_FILE) ; \
            $(ECHO) > $$($1_DEPS_TARGETS_FILE)

The configure script failed:

Runnable configure script is not present
Generating runnable configure script at /cygdrive/d/java/forks/dups12/openjdk/jdk/build/.configure-support/generated-configure.sh
Using autoconf at /usr/bin/autoconf [autoconf (GNU Autoconf) 2.72]
-:166141: error: possibly undefined macro: AS_NON_ASM_EXTENSION_FLAG
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure: Configuration created at Sat Aug 23 15:11:36 MDT 2025.

On the prompt " recipe commences before first target" Copilot says:

The error message “recipe commences before first target” in GNU Make typically means that there’s a line in your Makefile that starts with a tab (indicating a recipe), but it appears before any target has been defined. In Makefiles, recipes (commands to execute) must follow a target and its dependencies.

I moved the check further up, which fixed the build. After the PR was closed, I got a comment about the quotes I introduced! They shouldn’t be there :(.

/cygdrive/d/java/forks/dups15/openjdk/jdk/build/windows-x86_64-server-slowdebug/fixpath exec /cygdrive/c/progra~1/mib055~1/2022/enterprise/vc/tools/msvc/14.44.35207/bin/hostx64/x64/ml64.exe -nologo -c -Fo/cygdrive/d/java/forks/dups15/openjdk/jdk/build/windows-x86_64-server-slowdebug/support/native/jdk.incubator.vector/libjsvml/jsvml_d_atan2_windows_x86.obj "-Ta" /cygdrive/d/java/forks/dups15/openjdk/jdk/src/jdk.incubator.vector/windows/native/libjsvml/jsvml_d_atan2_windows_x86.S

Fortunately, the quotes don’t break assembling the source code as demonstrated by the 2 commands below:

copy test_x86_assembler.S test_x86_assembler.lib

"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x86\ml.exe" -nologo -c -Fo test_x86_assembler.obj "-Ta" test_x86_assembler.lib
 Assembling: test_x86_assembler.lib

"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x86\ml.exe" -nologo -c -Fo test_x86_assembler.obj test_x86_assembler.lib
MASM : fatal error A1017:missing source filename

I cleaned this up in 8366195: Remove unnecessary quotes around -Ta ml64 assembler argument by swesonga · Pull Request #27021 · openjdk/jdk, also moving the declaration of the argument to match -Fo as suggested in #26791.

Article info



Leave a Reply

Your email address will not be published. Required fields are marked *