Build flang again on arm64.

This requires the use of eg++ to build libpgmath; about a year and a half
ago, building the arm64-specific math routines broke when compiling with
clang (a clang bug) so we switched to the generic math routines only. Now,
build system changes make building generic math routines only impossible,
so we now must build libpgmath on arm64 with eg++. I have gotten tired of
waiting for a potential fix to allow building with clang again.
Thanks to phessler@, who put the diff into a bulk build (and spotted me
fat-fingering the linker invocation).
Flang now again builds and works properly on arm64. No change on amd64.
This commit is contained in:
bcallah 2019-11-24 14:37:25 +00:00
parent 5d3148a3cf
commit 98baeec9ea
5 changed files with 136 additions and 12 deletions

View File

@ -1,4 +1,4 @@
$OpenBSD: patch-runtime_flangrti_aarch64-Linux_dumpregs_c,v 1.2 2019/11/10 16:50:32 bcallah Exp $
$OpenBSD: patch-runtime_flangrti_aarch64-Linux_dumpregs_c,v 1.3 2019/11/24 14:37:25 bcallah Exp $
No ucontext on OpenBSD.
@ -13,7 +13,7 @@ Index: runtime/flangrti/aarch64-Linux/dumpregs.c
#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/dumpregs.c
/*
* 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

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.36 2019/11/10 16:50:32 bcallah Exp $
# $OpenBSD: Makefile,v 1.37 2019/11/24 14:37:25 bcallah Exp $
# Sync version with lang/flang/flang always!
COMMENT = LLVM Fortran math library
@ -12,8 +12,17 @@ GH_COMMIT = cbadb27675c4681c8a77eef73c1fbeafee155602
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 libestdc++ 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
@ -24,12 +33,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
.include <bsd.port.mk>

View File

@ -1,9 +1,18 @@
$OpenBSD: patch-CMakeLists_txt,v 1.5 2019/11/10 16:50:32 bcallah Exp $
$OpenBSD: patch-CMakeLists_txt,v 1.6 2019/11/24 14:37:25 bcallah Exp $
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)

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-lib_common_CMakeLists_txt,v 1.13 2019/11/24 14:37:25 bcallah Exp $
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")

View File

@ -0,0 +1,84 @@
$OpenBSD: patch-lib_common_fltfenv_c,v 1.1 2019/11/24 14:37:25 bcallah Exp $
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