From 602d48500cf4be711d8c7b8beb37a5b4e42ba840 Mon Sep 17 00:00:00 2001 From: Nazim Uddin Bhuiyan Date: Wed, 9 Jan 2019 10:40:40 -0500 Subject: [PATCH 1/6] Update makefiles to use NASM assembler on Windows * Added NASM_ASSEMBLER platform variable for win64 * Updated toolcfg/common.mk and rules/filetypes.mk to handle NASM Signed-off-by: Nazim Uddin Bhuiyan --- .../build/platform/host/amd64-win64-mvs.mk | 3 +- .../build/rules/win-msvc/filetypes.mk | 18 ++++++++- .../compiler/build/toolcfg/win-msvc/common.mk | 38 ++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/runtime/compiler/build/platform/host/amd64-win64-mvs.mk b/runtime/compiler/build/platform/host/amd64-win64-mvs.mk index ffaaf02aa4a..1ff3b27da3e 100644 --- a/runtime/compiler/build/platform/host/amd64-win64-mvs.mk +++ b/runtime/compiler/build/platform/host/amd64-win64-mvs.mk @@ -1,4 +1,4 @@ -# Copyright (c) 2000, 2017 IBM Corp. and others +# Copyright (c) 2000, 2019 IBM Corp. and others # # This program and the accompanying materials are made available under # the terms of the Eclipse Public License 2.0 which accompanies this @@ -23,3 +23,4 @@ HOST_SUBARCH=amd64 HOST_BITS=64 OS=win TOOLCHAIN=win-msvc +NASM_ASSEMBLER=yes diff --git a/runtime/compiler/build/rules/win-msvc/filetypes.mk b/runtime/compiler/build/rules/win-msvc/filetypes.mk index aacb9c4d71b..9065efa2c65 100644 --- a/runtime/compiler/build/rules/win-msvc/filetypes.mk +++ b/runtime/compiler/build/rules/win-msvc/filetypes.mk @@ -1,4 +1,4 @@ -# Copyright (c) 2000, 2017 IBM Corp. and others +# Copyright (c) 2000, 2019 IBM Corp. and others # # This program and the accompanying materials are made available under # the terms of the Eclipse Public License 2.0 which accompanies this @@ -89,6 +89,22 @@ endef # DEF_RULE.pasm RULE.pasm=$(eval $(DEF_RULE.pasm)) +# +# Compile .nasm file into .obj file +# +define DEF_RULE.nasm +$(1): $(2) | jit_createdirs + $$(NASM_CMD) $$(NASM_OBJ_FORMAT) $$(patsubst %,-D%=1,$$(NASM_DEFINES)) $$(patsubst %,-I%/,$$(subst \,/,$$(NASM_INCLUDES))) -o $$(subst \,/,"$$@") $$(subst \,/,"$$<") + +JIT_DIR_LIST+=$(dir $(1)) + +jit_cleanobjs:: + $$(call RM,$(1)) + +endef # DEF_RULE.nasm + +RULE.nasm=$(eval $(DEF_RULE.nasm)) + # # Compile .rc file into .res file # diff --git a/runtime/compiler/build/toolcfg/win-msvc/common.mk b/runtime/compiler/build/toolcfg/win-msvc/common.mk index d84abfe4646..de535367d4f 100644 --- a/runtime/compiler/build/toolcfg/win-msvc/common.mk +++ b/runtime/compiler/build/toolcfg/win-msvc/common.mk @@ -1,4 +1,4 @@ -# Copyright (c) 2000, 2018 IBM Corp. and others +# Copyright (c) 2000, 2019 IBM Corp. and others # # This program and the accompanying materials are made available under # the terms of the Eclipse Public License 2.0 which accompanies this @@ -208,6 +208,42 @@ endif PASM_FLAGS+=$(PASM_FLAGS_EXTRA) +# +# Setup NASM +# + +NASM_CMD?=nasm + +NASM_DEFINES=\ + TR_HOST_X86 \ + TR_TARGET_X86 \ + WINDOWS + +NASM_INCLUDES=\ + ../oti \ + ../compiler \ + ../compiler/x/runtime + +ifeq ($(HOST_BITS),32) + NASM_OBJ_FORMAT=-fwin32 + + NASM_DEFINES+=\ + TR_HOST_32BIT \ + TR_TARGET_32BIT + + NASM_INCLUDES+=\ + ../compiler/x/i386/runtime +else + NASM_OBJ_FORMAT=-fwin64 + + NASM_DEFINES+=\ + TR_HOST_64BIT \ + TR_TARGET_64BIT + + NASM_INCLUDES+=\ + ../compiler/x/amd64/runtime +endif + # # Setup RC # From 17ee5b7c4e34d8f3c6b48c77d246ec90e54a6ac6 Mon Sep 17 00:00:00 2001 From: Nazim Uddin Bhuiyan Date: Wed, 9 Jan 2019 11:18:06 -0500 Subject: [PATCH 2/6] Generate jilconsts.inc in NASM format on Win64 Also, NASM_ASSEMBLER is now defined on win64. Signed-off-by: Nazim Uddin Bhuiyan --- runtime/compiler/runtime/asmprotos.h | 2 +- runtime/jilgen/jilconsts.c | 80 +++++++++++----------------- 2 files changed, 31 insertions(+), 51 deletions(-) diff --git a/runtime/compiler/runtime/asmprotos.h b/runtime/compiler/runtime/asmprotos.h index 185a843a981..7f593ecc08c 100644 --- a/runtime/compiler/runtime/asmprotos.h +++ b/runtime/compiler/runtime/asmprotos.h @@ -64,7 +64,7 @@ extern "C" { * is set for OS variants that currently use NASM and is used to * decide the version of helper names to use. */ -#if defined(OSX) || (defined(LINUX) && defined(TR_HOST_X86) && defined(TR_HOST_64BIT)) +#if defined(TR_HOST_X86) && defined(TR_HOST_64BIT) #define NASM_ASSEMBLER #endif diff --git a/runtime/jilgen/jilconsts.c b/runtime/jilgen/jilconsts.c index 62586afa292..e1701004c37 100644 --- a/runtime/jilgen/jilconsts.c +++ b/runtime/jilgen/jilconsts.c @@ -85,7 +85,11 @@ createConstant(OMRPortLibrary *OMRPORTLIB, char const *name, UDATA value) return omrstr_printf(line, sizeof(line), "%s = %zu\n", name, value); #endif #elif defined(WIN32) /* LINUX */ - return omrstr_printf(line, sizeof(line), "%s equ %zu\n", name, value); + #if defined(J9VM_ENV_DATA64) + return omrstr_printf(line, sizeof(line), "%%define %s %zu\n", name, value); + #else /* J9VM_ENV_DATA64 */ + return omrstr_printf(line, sizeof(line), "%s equ %zu\n", name, value); + #endif #elif defined(J9ZOS390) /* WIN32 */ return omrstr_printf(line, sizeof(line), "%s EQU %zu\n", name, value); #elif defined(OSX) /* J9ZOS390 */ @@ -239,60 +243,36 @@ static char const *macroString = "\n\ #else /* LINUX */ #if defined(J9VM_ENV_DATA64) static char const *macroString = "\n\ -MoveHelper MACRO register,helperName\n\ - mov ®ister,offset &helperName\n\ -ENDM\n\ -\n\ -MoveUnderscoreHelper MACRO register,helperName\n\ - mov ®ister,offset _&helperName\n\ -ENDM\n\ -\n\ -CompareHelper MACRO source,helperName\n\ - cmp &source,offset _&helperName\n\ -ENDM\n\ -\n\ -CompareHelperUseReg MACRO source,helperName,register\n\ - cmp &source,offset _&helperName\n\ -ENDM\n\ -\n\ -CallHelper MACRO helperName\n\ - call &helperName\n\ -ENDM\n\ -\n\ -CallHelperUseReg MACRO helperName,register\n\ - call &helperName\n\ -ENDM\n\ -\n\ -JumpTableHelper MACRO temp,index,table\n\ - lea &temp,[&table]\n\ - jmp qword ptr[&temp& + &index&*8]\n\ -ENDM\n\ +%macro MoveHelper 2 ; register, helperName\n\ + lea %1, [rel %2]\n\ +%endmacro\n\ \n\ -JumpTableStart MACRO table\n\ - _CONST32 SEGMENT PARA 'CONST'\n\ - _CONST32 ends\n\ - _CONST32 SEGMENT PARA 'CONST'\n\ - align 04h\n\ -table&:\n\ -ENDM\n\ +%macro CallHelper 1 ; helperName\n\ + call %1\n\ +%endmacro\n\ \n\ -JumpTableEnd MACRO table\n\ - _CONST32 ends\n\ -ENDM\n\ +%macro CallHelperUseReg 2 ; helperName, register\n\ + call %1\n\ +%endmacro\n\ \n\ -JumpHelper MACRO helperName\n\ - jmp _&helperName\n\ -ENDM\n\ +%macro DECLARE_EXTERN 1 ; helperName\n\ + extern %1\n\ +%endmacro\n\ \n\ -ExternHelper MACRO helperName\n\ - extrn &helperName&:near\n\ -ENDM\n\ +%macro DECLARE_GLOBAL 1 ; helperName\n\ + global %1\n\ +%endmacro\n\ \n\ -GlueHelper MACRO helperName\n\ - test byte ptr[rdi+J9TR_MethodPCStartOffset], J9TR_MethodNotCompiledBit\n\ - jnz &helperName\n\ - jmp mergedStaticGlueCallFixer\n\ -ENDM\n"; +%define _rax rax\n\ +%define _rbx rbx\n\ +%define _rcx rcx\n\ +%define _rdx rdx\n\ +%define _rsi rsi\n\ +%define _rdi rdi\n\ +%define _rsp rsp\n\ +%define _rbp rbp\n\ +%define _rip\n\ +\n"; #else /* J9VM_ENV_DATA64 */ static char const *macroString = "\n\ MoveHelper MACRO register,helperName\n\ From 89a727dc4c8976539510685415f1985e9b5a32b0 Mon Sep 17 00:00:00 2001 From: Nazim Uddin Bhuiyan Date: Wed, 9 Jan 2019 11:55:33 -0500 Subject: [PATCH 3/6] Prepare NASM files to be used on Win64 Contains various minor fixes. Also, file paths need to use backslashes on Windows. This is because NASM does not deal with how OS file paths can differ, and simply tries searching for files to include by prepending the include paths provided in the command line to the file to include until it is found. Signed-off-by: Nazim Uddin Bhuiyan --- .../x/amd64/runtime/AMD64CompressString.nasm | 8 +++++--- runtime/compiler/x/runtime/X86LockReservation.nasm | 6 +++--- runtime/compiler/x/runtime/X86PicBuilder.nasm | 14 ++++++++++++-- runtime/compiler/x/runtime/X86PicBuilder_nasm.inc | 6 +----- runtime/compiler/x/runtime/X86Unresolveds.nasm | 10 ++++++++++ 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/runtime/compiler/x/amd64/runtime/AMD64CompressString.nasm b/runtime/compiler/x/amd64/runtime/AMD64CompressString.nasm index 97ac27ab093..f517c3a7e79 100644 --- a/runtime/compiler/x/amd64/runtime/AMD64CompressString.nasm +++ b/runtime/compiler/x/amd64/runtime/AMD64CompressString.nasm @@ -1,4 +1,4 @@ -; Copyright (c) 2000, 2018 IBM Corp. and others +; Copyright (c) 2000, 2019 IBM Corp. and others ; ; This program and the accompanying materials are made available under ; the terms of the Eclipse Public License 2.0 which accompanies this @@ -21,9 +21,11 @@ %ifdef TR_HOST_64BIT %include "jilconsts.inc" +%ifdef WINDOWS +%include "x\amd64\runtime\AMD64CompressString_nasm.inc" +%else %include "x/amd64/runtime/AMD64CompressString_nasm.inc" - - +%endif J9TR_ObjectColorBlack equ 03h diff --git a/runtime/compiler/x/runtime/X86LockReservation.nasm b/runtime/compiler/x/runtime/X86LockReservation.nasm index cbb53f32f86..12df32ab021 100644 --- a/runtime/compiler/x/runtime/X86LockReservation.nasm +++ b/runtime/compiler/x/runtime/X86LockReservation.nasm @@ -1,4 +1,4 @@ -; Copyright (c) 2000, 2018 IBM Corp. and others +; Copyright (c) 2000, 2019 IBM Corp. and others ; ; This program and the accompanying materials are made available under ; the terms of the Eclipse Public License 2.0 which accompanies this @@ -34,10 +34,10 @@ DECLARE_GLOBAL jitMethodMonitorExitReservedPrimitive %ifdef WINDOWS - UseFastCall equ 1 + %define UseFastCall 1 %else %ifdef TR_HOST_32BIT - UseFastCall equ 1 + %define UseFastCall 1 %endif %endif diff --git a/runtime/compiler/x/runtime/X86PicBuilder.nasm b/runtime/compiler/x/runtime/X86PicBuilder.nasm index 40294729402..b83f73b4889 100644 --- a/runtime/compiler/x/runtime/X86PicBuilder.nasm +++ b/runtime/compiler/x/runtime/X86PicBuilder.nasm @@ -1,4 +1,4 @@ -; Copyright (c) 2000, 2018 IBM Corp. and others +; Copyright (c) 2000, 2019 IBM Corp. and others ; ; This program and the accompanying materials are made available under ; the terms of the Eclipse Public License 2.0 which accompanies this @@ -29,7 +29,12 @@ CPU PPRO %include "jilconsts.inc" + +%ifdef WINDOWS + %include "x\runtime\X86PicBuilder_nasm.inc" +%else %include "x/runtime/X86PicBuilder_nasm.inc" +%endif segment .text @@ -1206,7 +1211,12 @@ ret ; branch will mispredict s ; -------------------------------------------------------------------------------- %include "jilconsts.inc" -%include "x/runtime/X86PicBuilder_nasm.inc" + +%ifdef WINDOWS + %include "x\runtime\X86PicBuilder_nasm.inc" +%else + %include "x/runtime/X86PicBuilder_nasm.inc" +%endif segment .text diff --git a/runtime/compiler/x/runtime/X86PicBuilder_nasm.inc b/runtime/compiler/x/runtime/X86PicBuilder_nasm.inc index a8d26731687..11652abc993 100644 --- a/runtime/compiler/x/runtime/X86PicBuilder_nasm.inc +++ b/runtime/compiler/x/runtime/X86PicBuilder_nasm.inc @@ -1,4 +1,4 @@ -; Copyright (c) 2000, 2018 IBM Corp. and others +; Copyright (c) 2000, 2019 IBM Corp. and others ; ; This program and the accompanying materials are made available under ; the terms of the Eclipse Public License 2.0 which accompanies this @@ -106,11 +106,7 @@ eq_IPicData_j2iThunk equ 22h ; only present if direct invoke is pos ; It's omitted here since it would be unused anyway. %macro LoadHelperIndex 2 ; args: targetReg, helperIndexSym -%ifdef WINDOWS - mov %1, dword [%2] -%else mov %1, dword [rel + %2] -%endif %endmacro diff --git a/runtime/compiler/x/runtime/X86Unresolveds.nasm b/runtime/compiler/x/runtime/X86Unresolveds.nasm index 5762a69d914..cca054ea9f6 100644 --- a/runtime/compiler/x/runtime/X86Unresolveds.nasm +++ b/runtime/compiler/x/runtime/X86Unresolveds.nasm @@ -32,7 +32,12 @@ eq_offsetof_J9Object_clazz equ 8 ; offset of class pointer in a J9Object %include "jilconsts.inc" + +%ifdef WINDOWS + %include "x\runtime\X86PicBuilder_nasm.inc" +%else %include "x/runtime/X86PicBuilder_nasm.inc" +%endif segment .text @@ -1113,7 +1118,12 @@ retn %include "jilconsts.inc" + +%ifdef WINDOWS + %include "x\runtime\X86PicBuilder_nasm.inc" +%else %include "x/runtime/X86PicBuilder_nasm.inc" +%endif %ifdef ASM_J9VM_INTERP_COMPRESSED_OBJECT_HEADER eq_offsetof_J9Object_clazz equ 8 ; offset of class pointer in a J9Object From e1527ceb4cfb925f53d3477a7c769d8afb8d55ad Mon Sep 17 00:00:00 2001 From: Nazim Uddin Bhuiyan Date: Thu, 10 Jan 2019 13:31:47 -0500 Subject: [PATCH 4/6] Update Windows build instructions [skip ci] Specifies NASM v2.13.03 and newer as a requirement for building OpenJ9 on Windows. Signed-off-by: Nazim Uddin Bhuiyan --- doc/build-instructions/Build_Instructions_V10.md | 8 +++++++- doc/build-instructions/Build_Instructions_V11.md | 8 +++++++- doc/build-instructions/Build_Instructions_V8.md | 8 +++++++- doc/build-instructions/Build_Instructions_V9.md | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/doc/build-instructions/Build_Instructions_V10.md b/doc/build-instructions/Build_Instructions_V10.md index c97c017a57c..c7638716705 100644 --- a/doc/build-instructions/Build_Instructions_V10.md +++ b/doc/build-instructions/Build_Instructions_V10.md @@ -1,5 +1,5 @@