Hi ports --

Without rehashing too much, flang broke libpgmath compilation with clang in its aarch64-specific math routines a bit over a year ago. I reported it then. It was found to be a bug in clang itself, which has not been fixed. The code to work around the clang problems was extremely invasive, and subsequently never committed to the flang repo. The work around I used in the flang package for aarch64 was to use only the generic math routines and not the aarch64-specific math routines on aarch64.

More recently, the flang people broke generic math routine only builds of libpgmath, breaking the aarch64 build of libpgmath. I've given up hope that libpgmath will build on aarch64 with clang in the short or medium term. So let's switch to building libpgmath (and only libpgmath) with egcc on aarch64. Not ideal, but it does work. Passes the NIST Fortran-95 suite.

No change at all on amd64.

Diff here works on my RPi3B+. Any concerns I'm missing?

~Brian

Index: flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c
===================================================================
RCS file: /cvs/ports/lang/flang/flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c,v
retrieving revision 1.2
diff -u -p -r1.2 patch-runtime_flangrti_aarch64-Linux_dumpregs_c
--- flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c	10 Nov 2019 16:50:32 -0000	1.2
+++ flang/patches/patch-runtime_flangrti_aarch64-Linux_dumpregs_c	13 Nov 2019 22:39:24 -0000
@@ -13,7 +13,7 @@ Index: runtime/flangrti/aarch64-Linux/du
  #include <sys/ucontext.h>
  #include <stddef.h>
  #include <stdioInterf.h>
-@@ -29,6 +30,21 @@ typedef struct {
+@@ -29,12 +30,28 @@ typedef struct {
  } xregs_t;
  
  
@@ -35,3 +35,15 @@ Index: runtime/flangrti/aarch64-Linux/du
  /*
   * The way the structure below is organized, the X registers are all
   * sequential with no gaps - the structure is probably overkill - but
+  * allows for some flexibility.
+  */
+ 
++#ifndef __OpenBSD__
+ xregs_t xregs[] = {
+     { offsetof(mcontext_t, regs[0])/sizeof(uint64_t), "x0" },
+     { offsetof(mcontext_t, regs[1])/sizeof(uint64_t), "x1" },
+@@ -121,3 +138,4 @@ getRegs(ucontext_t *u)
+   mcontext_t *mc = &u->uc_mcontext;
+   return (uint64_t *)mc;
+ }
++#endif
Index: libpgmath/Makefile
===================================================================
RCS file: /cvs/ports/lang/flang/libpgmath/Makefile,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile
--- libpgmath/Makefile	10 Nov 2019 16:50:32 -0000	1.36
+++ libpgmath/Makefile	13 Nov 2019 22:39:24 -0000
@@ -12,8 +12,17 @@ GH_COMMIT =	cbadb27675c4681c8a77eef73c1f
 
 WANTLIB += ${COMPILER_LIBCXX} m
 
-# REQUIRES a compiler that understands AVX-512F
+# Clang on amd64; gcc on aarch64 (XXX: monitor aarch64 situation)
+.if ${MACHINE_ARCH:Mamd64}
 COMPILER =	base-clang ports-clang
+.else
+COMPILER =	ports-gcc
+
+# Attempt to prevent libstdc++ and libc++ symbol conflicts in the edge case
+# where you're on aarch64 and you are linking together both Fortran and C++
+# code into a single object.
+CONFIGURE_ARGS += -DCMAKE_SHARED_LINKER_FLAGS='-static-libstdc++ static-libgcc'
+.endif
 
 MODULES =	devel/cmake \
 		lang/python
@@ -23,12 +32,6 @@ BUILD_DEPENDS =	devel/llvm
 
 # If you delete flang, this should go too.
 RUN_DEPENDS =	lang/flang/driver
-
-# arm64-specific routines don't build with clang
-# (known upstream) so use the generic routines for now.
-.if ${MACHINE_ARCH:Maarch64}
-CONFIGURE_ARGS +=	-DLIBPGMATH_WITH_GENERIC=On
-.endif
 
 WRKDIST =	${WRKDIR}/flang-${GH_COMMIT}/runtime/libpgmath
 
Index: libpgmath/patches/patch-CMakeLists_txt
===================================================================
RCS file: /cvs/ports/lang/flang/libpgmath/patches/patch-CMakeLists_txt,v
retrieving revision 1.5
diff -u -p -r1.5 patch-CMakeLists_txt
--- libpgmath/patches/patch-CMakeLists_txt	10 Nov 2019 16:50:32 -0000	1.5
+++ libpgmath/patches/patch-CMakeLists_txt	13 Nov 2019 22:39:24 -0000
@@ -3,7 +3,16 @@ $OpenBSD: patch-CMakeLists_txt,v 1.5 201
 Index: CMakeLists.txt
 --- CMakeLists.txt.orig
 +++ CMakeLists.txt
-@@ -112,7 +112,7 @@ set(LIBPGMATH_TOOLS_DIR ${LIBPGMATH_BASE_DIR}/tools)
+@@ -86,8 +86,6 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${LIBPGMATH_
+ endif()
+ 
+ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "aarch64")
+-  string(REPLACE "-O2" "-O3 -finline-functions -funroll-loops" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+-  string(REPLACE "-O2" "-O3 -finline-functions -funroll-loops" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+   string(REPLACE "-std=c++11" "-std=gnu++11" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+   string(REPLACE "-fno-tree-vectorize" "-ftree-vectorize" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+   string(REPLACE "-fno-tree-vectorize" "-ftree-vectorize" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+@@ -112,7 +110,7 @@ set(LIBPGMATH_TOOLS_DIR ${LIBPGMATH_BASE_DIR}/tools)
  set(LIBPGMATH_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
  set(LIBPGMATH_RUNTIME_PATH ${CMAKE_BINARY_DIR}/lib)
  set(LIBPGMATH_LIBRARY_NAME pgmath)
Index: libpgmath/patches/patch-lib_common_CMakeLists_txt
===================================================================
RCS file: libpgmath/patches/patch-lib_common_CMakeLists_txt
diff -N libpgmath/patches/patch-lib_common_CMakeLists_txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libpgmath/patches/patch-lib_common_CMakeLists_txt	13 Nov 2019 22:39:24 -0000
@@ -0,0 +1,16 @@
+$OpenBSD$
+
+Don't compile with -mcpu=native on aarch64
+
+Index: lib/common/CMakeLists.txt
+--- lib/common/CMakeLists.txt.orig
++++ lib/common/CMakeLists.txt
+@@ -142,8 +142,6 @@ elseif(${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "ppc64le"
+     sincosf.c)
+ elseif(${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "aarch64")
+   set_property(SOURCE dispatch.c APPEND_STRING PROPERTY COMPILE_FLAGS "-fno-builtin")
+-  set_property(SOURCE mth_xintrinsics.c APPEND_STRING PROPERTY COMPILE_FLAGS "-mcpu=${LLVM_FLANG_CPU_TARGET} ")
+-  set_property(SOURCE mth_128defs.c mth_128defs_init.c mth_128defs_stats.c APPEND_STRING PROPERTY COMPILE_FLAGS "-mcpu=${LLVM_FLANG_CPU_TARGET} ")
+   set_property(SOURCE mth_128defs_init.c APPEND PROPERTY COMPILE_DEFINITIONS MTH_I_INTRIN_INIT)
+   set_property(SOURCE mth_128defs_stats.c APPEND PROPERTY COMPILE_DEFINITIONS MTH_I_INTRIN_STATS)
+   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z -Wl,combreloc")
Index: libpgmath/patches/patch-lib_common_fltfenv_c
===================================================================
RCS file: libpgmath/patches/patch-lib_common_fltfenv_c
diff -N libpgmath/patches/patch-lib_common_fltfenv_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libpgmath/patches/patch-lib_common_fltfenv_c	13 Nov 2019 22:39:24 -0000
@@ -0,0 +1,84 @@
+$OpenBSD$
+
+Work around glibc stuff (use standard functions for this stuff)
+
+Index: lib/common/fltfenv.c
+--- lib/common/fltfenv.c.orig
++++ lib/common/fltfenv.c
+@@ -570,7 +570,7 @@ __fenv_feupdateenv(fenv_t *env)
+  * __fenv_mask_fz() and __fenv_restore_fz().
+  */
+ 
+-#include <fpu_control.h>
++#include <fenv.h>
+ 
+ /** \brief Set (flush to zero) underflow mode
+  *
+@@ -580,14 +580,14 @@ __fenv_feupdateenv(fenv_t *env)
+ int
+ __fenv_fesetzerodenorm(int uflow)
+ {
+-  uint64_t cw;
++  fenv_t cw;
+ 
+-  _FPU_GETCW(cw);
++  fegetenv(&cw);
+   if (uflow)
+     cw |= (1ULL << 24);
+   else
+     cw &= ~(1ULL << 24);
+-  _FPU_SETCW(cw);
++  fesetenv(&cw);
+   return 0;
+ }
+ 
+@@ -598,9 +598,9 @@ __fenv_fesetzerodenorm(int uflow)
+ int
+ __fenv_fegetzerodenorm(void)
+ {
+-  uint64_t cw;
++  fenv_t cw;
+ 
+-  _FPU_GETCW(cw);
++  fegetenv(&cw);
+   return (cw & (1ULL << 24)) ? 1 : 0;
+ }
+ 
+@@ -615,16 +615,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
+@@ -633,14 +633,14 @@ __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);
+ }
+ 
+ #else

Reply via email to