Hi ports --

The attached diff allows lang/flang to build and run on arm64. The entire NIST 
Fortran 77 test suite passes on arm64 with this. My Raspberry Pi 3B+ is happy 
with this.

Does anyone want to try it out before I commit?

Apologies to the arm64 package builders; this took quite a while to build on my 
RPi 3B+.

OK?

~Brian

Index: Makefile.inc
===================================================================
RCS file: /cvs/ports/lang/flang/Makefile.inc,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile.inc
--- Makefile.inc	9 May 2018 22:27:41 -0000	1.2
+++ Makefile.inc	24 Jun 2018 23:31:00 -0000
@@ -1,7 +1,7 @@
 # $OpenBSD: Makefile.inc,v 1.2 2018/05/09 22:27:41 bcallah Exp $
 
 # Also ppc64le
-ONLY_FOR_ARCHS =	amd64 #arm64
+ONLY_FOR_ARCHS =	amd64 arm64
 
 CATEGORIES ?=	lang
 
Index: flang/Makefile
===================================================================
RCS file: /cvs/ports/lang/flang/flang/Makefile,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile
--- flang/Makefile	23 Jun 2018 01:10:35 -0000	1.13
+++ flang/Makefile	24 Jun 2018 23:31:00 -0000
@@ -2,6 +2,7 @@
 
 COMMENT =	LLVM Fortran compiler passes and runtime library
 DISTNAME =	flang-6.0.0.20180621
+REVISION =	0
 
 SHARED_LIBS +=	flang                     1.1 # 6.0
 SHARED_LIBS +=	flangrti                  1.0 # 6.0
@@ -33,9 +34,5 @@ CONFIGURE_ARGS =	-DCMAKE_Fortran_COMPILE
 			-DFLANG_LIBOMP="${WRKBUILD}/lib/libompstub.a" \
 			-DLIBPGMATH="${LOCALBASE}/lib/libpgmath.a" \
 			-DWITH_WERROR=OFF
-
-post-patch:
-	@cp -R ${WRKSRC}/tools/flang2/flang2exe/x86_64-Linux \
-		${WRKSRC}/tools/flang2/flang2exe/x86_64-OpenBSD
 
 .include <bsd.port.mk>
Index: flang/patches/patch-CMakeLists_txt
===================================================================
RCS file: /cvs/ports/lang/flang/flang/patches/patch-CMakeLists_txt,v
retrieving revision 1.2
diff -u -p -r1.2 patch-CMakeLists_txt
--- flang/patches/patch-CMakeLists_txt	9 May 2018 22:27:41 -0000	1.2
+++ flang/patches/patch-CMakeLists_txt	24 Jun 2018 23:31:00 -0000
@@ -1,11 +1,11 @@
 $OpenBSD: patch-CMakeLists_txt,v 1.2 2018/05/09 22:27:41 bcallah Exp $
 
-Add OpenBSD/amd64
+Add OpenBSD/amd64 and OpenBSD/arm64
 
 Index: CMakeLists.txt
 --- CMakeLists.txt.orig
 +++ CMakeLists.txt
-@@ -49,6 +49,15 @@ if( ${TARGET_OS} STREQUAL "Linux" )
+@@ -49,6 +49,20 @@ if( ${TARGET_OS} STREQUAL "Linux" )
      message("Unsupported architecture: ${TARGET_ARCHITECTURE}" )
      return()
    endif()
@@ -17,6 +17,11 @@ Index: CMakeLists.txt
 +    set(ARCH X86)
 +    set(WRDSZ 64)
 +    set(TARGET_ARCHITECTURE x86_64)
++  elseif( ${TARGET_ARCHITECTURE} STREQUAL "arm64" )
++    set(ARCHNAME aarch64)
++    set(ARCH ARM)
++    set(WRDSZ 64)
++    set(TARGET_ARCHITECTURE aarch64)
 +  endif()
  else()
    message("Unsupported OS: ${TARGET_OS}" )
Index: flang/patches/patch-runtime_flang_CMakeLists_txt
===================================================================
RCS file: /cvs/ports/lang/flang/flang/patches/patch-runtime_flang_CMakeLists_txt,v
retrieving revision 1.3
diff -u -p -r1.3 patch-runtime_flang_CMakeLists_txt
--- flang/patches/patch-runtime_flang_CMakeLists_txt	16 Jun 2018 20:08:28 -0000	1.3
+++ flang/patches/patch-runtime_flang_CMakeLists_txt	24 Jun 2018 23:31:00 -0000
@@ -2,6 +2,7 @@ $OpenBSD: patch-runtime_flang_CMakeLists
 
 No -lrt
 Appease lld
+Work around standalone preprocessing of F95 files with C compiler
 
 Index: runtime/flang/CMakeLists.txt
 --- runtime/flang/CMakeLists.txt.orig
@@ -15,6 +16,24 @@ Index: runtime/flang/CMakeLists.txt
  
  # We are using Fortran driver to build this library with fresh compiler
  # components, so point its binary directory to the build directory to pick up
+@@ -420,7 +420,7 @@ set(I8_FILES_DIR I8_sources)
+ # Fortran files with macros as module names need to be preprocessed. 
+ add_custom_command(
+   OUTPUT "${I8_FILES_DIR}/ieee_arithmetic.F95"
+-  COMMAND "${CMAKE_C_COMPILER}" -E 
++  COMMAND "${CMAKE_C_COMPILER}" -E -x c 
+   "${CMAKE_CURRENT_SOURCE_DIR}/ieee_arithmetic.F95" -DDESC_I8 
+   > "${I8_FILES_DIR}/ieee_arithmetic.F95"
+   COMMENT "Preprocessing ieee_arithmetic.F95"
+@@ -429,7 +429,7 @@ add_custom_command(
+ 
+ add_custom_command(
+   OUTPUT "${I8_FILES_DIR}/ieee_exceptions.F95"
+-  COMMAND "${CMAKE_C_COMPILER}" -E 
++  COMMAND "${CMAKE_C_COMPILER}" -E -x c 
+   "${CMAKE_CURRENT_SOURCE_DIR}/ieee_exceptions.F95" -DDESC_I8 
+   > "${I8_FILES_DIR}/ieee_exceptions.F95"
+   COMMENT "Preprocessing ieee_exceptions.F95"
 @@ -479,7 +479,7 @@ add_flang_library(flang_shared
  set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang)
  target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.so)
Index: flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c
===================================================================
RCS file: flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c
diff -N flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c	24 Jun 2018 23:31:00 -0000
@@ -0,0 +1,34 @@
+$OpenBSD$
+
+No ucontext on OpenBSD.
+
+Index: runtime/flangrti/aarch64-Linux/dumpregs.c
+--- runtime/flangrti/aarch64-Linux/dumpregs.c.orig
++++ runtime/flangrti/aarch64-Linux/dumpregs.c
+@@ -15,6 +15,7 @@
+  *
+  */
+ 
++#ifndef __OpenBSD__
+ #include <sys/ucontext.h>
+ 
+ void
+@@ -29,3 +30,18 @@ getRegs(ucontext_t *u)
+   return (gregset_t *)0;
+ } 
+ 
++#else
++
++void
++dumpregs(void *regs)
++{
++}
++  
++
++void *
++getRegs(void *u)
++{ 
++  return (void *)0;
++} 
++
++#endif
Index: flang/patches/patch-runtime_flangrti_aarch64-Linux_flt_env_c
===================================================================
RCS file: flang/patches/patch-runtime_flangrti_aarch64-Linux_flt_env_c
diff -N flang/patches/patch-runtime_flangrti_aarch64-Linux_flt_env_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flang/patches/patch-runtime_flangrti_aarch64-Linux_flt_env_c	24 Jun 2018 23:31:00 -0000
@@ -0,0 +1,85 @@
+$OpenBSD$
+
+Workaround glibc nonsense
+
+Index: runtime/flangrti/aarch64-Linux/flt_env.c
+--- runtime/flangrti/aarch64-Linux/flt_env.c.orig
++++ runtime/flangrti/aarch64-Linux/flt_env.c
+@@ -21,7 +21,6 @@
+ 
+ #include <stdint.h>
+ #include <fenv.h>
+-#include <fpu_control.h>
+ 
+ int
+ __fenv_fegetround(void)
+@@ -115,14 +114,14 @@ __fenv_feupdateenv(fenv_t *env)
+ int
+ __fenv_fesetzerodenorm(int uflow)
+ {
+-  uint64_t cw;
++  fenv_t fenv;
+ 
+-  _FPU_GETCW(cw);
++  fegetenv(&fenv);
+   if (uflow)
+-    cw |= (1ULL << 24);
++    fenv |= (1ULL << 24);
+   else
+-    cw &= ~(1ULL << 24);
+-  _FPU_SETCW(cw);
++    fenv &= ~(1ULL << 24);
++  fesetenv(&fenv);
+   return 0;
+ }
+ 
+@@ -133,10 +132,10 @@ __fenv_fesetzerodenorm(int uflow)
+ int
+ __fenv_fegetzerodenorm(void)
+ {
+-  uint64_t cw;
++  fenv_t fenv;
+ 
+-  _FPU_GETCW(cw);
+-  return (cw & (1ULL << 24)) ? 1 : 0;
++  fegetenv(&fenv);
++  return (fenv & (1ULL << 24)) ? 1 : 0;
+ }
+ 
+ /** \brief
+@@ -150,16 +149,16 @@ __fenv_fegetzerodenorm(void)
+ void
+ __fenv_mask_fz(int mask, int *psv)
+ {
+-  uint64_t tmp;
++  fenv_t tmp;
+ 
+-  _FPU_GETCW(tmp);
++  fegetenv(&tmp);
+   if (psv)
+     *psv = ((tmp & (1ULL << 24)) ? 1 : 0);
+   if (mask)
+     tmp |= (1ULL << 24);
+   else
+     tmp &= ~(1ULL << 24);
+-  _FPU_SETCW(tmp);
++  fesetenv(&tmp);
+ }
+ 
+ /** \brief
+@@ -168,12 +167,12 @@ __fenv_mask_fz(int mask, int *psv)
+ void
+ __fenv_restore_fz(int sv)
+ {
+-  uint64_t tmp;
++  fenv_t tmp;
+ 
+-  _FPU_GETCW(tmp);
++  fegetenv(&tmp);
+   if (sv)
+     tmp |= (1ULL << 24);
+   else
+     tmp &= ~(1ULL << 24);
+-  _FPU_SETCW(tmp);
++  fesetenv(&tmp);
+ }
Index: flang/patches/patch-tools_flang2_CMakeLists_txt
===================================================================
RCS file: flang/patches/patch-tools_flang2_CMakeLists_txt
diff -N flang/patches/patch-tools_flang2_CMakeLists_txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flang/patches/patch-tools_flang2_CMakeLists_txt	24 Jun 2018 23:31:00 -0000
@@ -0,0 +1,18 @@
+$OpenBSD$
+
+We should do this too.
+
+Index: tools/flang2/CMakeLists.txt
+--- tools/flang2/CMakeLists.txt.orig
++++ tools/flang2/CMakeLists.txt
+@@ -33,8 +33,8 @@ set(FLANG2_INCLUDE_DIR    ${CMAKE_CURRENT_BINARY_DIR}/
+ 
+ include_directories(${FLANG2_INCLUDE_DIR})
+ 
+-if( ${TARGET_OS} STREQUAL "Linux" )
+-  if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" )
++if( ${TARGET_OS} STREQUAL "Linux|OpenBSD" )
++  if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64|amd64" )
+     set(X86_64 ON)
+     set(LINUX86 ON)
+   endif()
Index: flang/patches/patch-tools_flang2_flang2exe_CMakeLists_txt
===================================================================
RCS file: flang/patches/patch-tools_flang2_flang2exe_CMakeLists_txt
diff -N flang/patches/patch-tools_flang2_flang2exe_CMakeLists_txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flang/patches/patch-tools_flang2_flang2exe_CMakeLists_txt	24 Jun 2018 23:31:00 -0000
@@ -0,0 +1,16 @@
+$OpenBSD$
+
+Eliminate the need for a post-patch copy.
+
+Index: tools/flang2/flang2exe/CMakeLists.txt
+--- tools/flang2/flang2exe/CMakeLists.txt.orig
++++ tools/flang2/flang2exe/CMakeLists.txt
+@@ -101,7 +101,7 @@ set(INCLUDE_DIRS
+   ${FLANG_SOURCE_DIR}/lib/scutil
+   ${CMAKE_CURRENT_SOURCE_DIR}
+   ${CMAKE_CURRENT_BINARY_DIR}
+-  ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_ARCHITECTURE}-${TARGET_OS}
++  ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_ARCHITECTURE}-Linux
+   ${UTILS_SYMTAB_BIN_DIR}        # Symbol table headers
+   ${UTILS_ILI_BIN_DIR}           # ILI IR headers
+   ${UTILS_ILM_BIN_DIR}           # ILM IR headers
Index: flang/pkg/PLIST
===================================================================
RCS file: /cvs/ports/lang/flang/flang/pkg/PLIST,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 PLIST
--- flang/pkg/PLIST	31 Dec 2017 18:06:38 -0000	1.1.1.1
+++ flang/pkg/PLIST	24 Jun 2018 23:31:00 -0000
@@ -2,7 +2,9 @@
 @bin bin/flang1
 @bin bin/flang2
 include/ieee_arithmetic.mod
+include/ieee_arithmetic_la.mod
 include/ieee_exceptions.mod
+include/ieee_exceptions_la.mod
 include/ieee_features.mod
 include/iso_c_binding.mod
 include/iso_fortran_env.mod
Index: libpgmath/Makefile
===================================================================
RCS file: /cvs/ports/lang/flang/libpgmath/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- libpgmath/Makefile	23 Jun 2018 01:10:35 -0000	1.3
+++ libpgmath/Makefile	24 Jun 2018 23:31:00 -0000
@@ -4,6 +4,7 @@
 COMMENT =	LLVM Fortran math library
 DISTNAME =	flang-6.0.0.20180621
 PKGNAME =	${DISTNAME:S/flang/libpgmath/}
+REVISION =	0
 
 SHARED_LIBS +=	pgmath                    1.0 # 6.0
 
Index: libpgmath/patches/patch-lib_CMakeLists_txt
===================================================================
RCS file: /cvs/ports/lang/flang/libpgmath/patches/patch-lib_CMakeLists_txt,v
retrieving revision 1.2
diff -u -p -r1.2 patch-lib_CMakeLists_txt
--- libpgmath/patches/patch-lib_CMakeLists_txt	16 Jun 2018 20:08:28 -0000	1.2
+++ libpgmath/patches/patch-lib_CMakeLists_txt	24 Jun 2018 23:31:00 -0000
@@ -41,6 +41,21 @@ Index: lib/CMakeLists.txt
  
      # common
      # Definitions and compiler flags for level 1 directories
+@@ -151,12 +154,12 @@ else()
+   set(DEFINITIONS_L1 HOST_LINUX MAXCPUS=256 MAXCPUSL=8 MAXCPUSR=8 TARGET_LINUX
+     TARGET_LINUX_64 TARGET_LLVM TARGET_LLVM_64 TARGET_LLVM_LINUX64
+     TARGET_LINUX_GENERIC TARGET_64 PG_PIC)
+-  set(FLAGS_L1 "-O3 -mfma -ffp-contract=fast ")
++  set(FLAGS_L1 " ")
+ 
+   set(DEFINITIONS_L2 HOST_LINUX MAXCPUS=256 MAXCPUSL=8 MAXCPUSR=8 TARGET_LINUX
+     TARGET_LINUX_64 TARGET_LLVM TARGET_LLVM_64 TARGET_LLVM_LINUX64
+     TARGET_LINUX_GENERIC TARGET_64 PG_PIC)
+-  set(FLAGS_L2 "-O3 -mfma -ffp-contract=fast ")
++  set(FLAGS_L2 " ")
+ 
+   # common
+   # Definitions and compiler flags for level 1 directories
 @@ -180,7 +183,7 @@ else()
  endif()
  

Reply via email to