From 834073192fcf9673fbd56340210ec7f4deeae5c4 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Thu, 13 Sep 2018 14:45:26 -0400 Subject: [PATCH 01/10] disable stime() on macOS --- runtime/flang/stime3f.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/flang/stime3f.c b/runtime/flang/stime3f.c index d8a58f9ad89..f236640063e 100644 --- a/runtime/flang/stime3f.c +++ b/runtime/flang/stime3f.c @@ -17,6 +17,10 @@ int ENT3F(STIME, stime)(int *tp) { +#ifdef TARGET_OSX + /* stime() doesn't exist on maxOS and is root-only anyway */ + return EPERM; +#else int i; struct timespec ts = {0}; @@ -25,6 +29,7 @@ int ENT3F(STIME, stime)(int *tp) i = __io_errno(); return i; +#endif } #endif /* !WINNT */ From 3c662c3be73805a032bbc85d3b1b4a2796839dd2 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Thu, 13 Sep 2018 15:46:43 -0400 Subject: [PATCH 02/10] user fileno() instead of direct structure access --- runtime/flangrti/dumpregs.h | 8 ++++++-- runtime/flangrti/iostdinit.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/runtime/flangrti/dumpregs.h b/runtime/flangrti/dumpregs.h index 31c07feb51e..77ba95edc86 100644 --- a/runtime/flangrti/dumpregs.h +++ b/runtime/flangrti/dumpregs.h @@ -10,7 +10,11 @@ * \file * Declare routines that access the machine registers */ - +#if defined(TARGET_OSX) || defined(TARGET_WIN) +#define gregset_t void +void dumpregs(void *); +void *getRegs(void *); +#else void dumpregs(gregset_t *regs); gregset_t *getRegs(ucontext_t *u); - +#endif diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index 378ae9a1e59..7c43122b03e 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -153,7 +153,7 @@ __io_ferror(void *p) int __io_getfd(void *fp) { - return (((FILE *)fp)->_fileno); + return fileno((FILE *)fp); } /* is a tty? */ From d632984cd79fe95e6f9bbbf6a71c212906683172 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Thu, 13 Sep 2018 15:48:48 -0400 Subject: [PATCH 03/10] use __fenv_feenableexcept() from flt_env.c instead of feenableexcept() since it doesn't exist on macOS --- runtime/flangrti/ktrap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/flangrti/ktrap.c b/runtime/flangrti/ktrap.c index c28debaef2b..573152d65bf 100644 --- a/runtime/flangrti/ktrap.c +++ b/runtime/flangrti/ktrap.c @@ -50,7 +50,11 @@ __ktrap(void) excepts |= FE_UNDERFLOW; if (bv & 0x100) excepts |= FE_INEXACT; +#ifdef TARGET_OSX + __fenv_feenableexcept(excepts); +#else feenableexcept(excepts); /* glibc 2.2 extension to fenv.h */ +#endif } } } From b6082a688a1ef15938c22be926a5b87af82ed501 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Thu, 13 Sep 2018 15:49:59 -0400 Subject: [PATCH 04/10] remove incorrect declaration of strcpy() -- it's usually a macro --- runtime/flang/global.h | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 3157ce4b442..7f1743229d6 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -76,7 +76,6 @@ typedef char sbool; /* short boolean (for use in large structs) */ #define assert(ex) #endif -extern char *strcpy(); #define STASH(str) (strcpy((char *)malloc(strlen(str) + 1), str)) /* defs used by __fortio_error */ From fac6e62ecaafd00da2a21e1a3ce7d94d4168221b Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Thu, 13 Sep 2018 15:53:36 -0400 Subject: [PATCH 05/10] add support for Darwin/macOS in the CMake files; it's not perfect since a lot is still hard-coded for Linux but at least it works --- CMakeLists.txt | 11 +++++++++++ runtime/CMakeLists.txt | 15 +++++++++++++-- runtime/flang/CMakeLists.txt | 11 ++++++++--- tools/flang2/CMakeLists.txt | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0898222ff81..e5bf28848c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,17 @@ if( ${TARGET_OS} STREQUAL "Linux" ) message("Unsupported architecture: ${TARGET_ARCHITECTURE}" ) return() endif() +elseif( ${TARGET_OS} STREQUAL "Darwin" ) + set(OS "OSX") + set(OSNAME "Darwin") + if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" ) + set(ARCHNAME x86-64) + set(ARCH X86) + set(WRDSZ 64) + else() + message("Unsupported architecture: ${TARGET_ARCHITECTURE}" ) + return() + endif() else() message("Unsupported OS: ${TARGET_OS}" ) return() diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 33dc89b848b..24d809a3382 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -6,13 +6,24 @@ set (RUNTIME_SHARED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shared) +if( ${TARGET_OS} STREQUAL "Darwin" ) + add_definitions( + -DTARGET_OSX + -DTARGET_OSX_X8664 + -DOSX86 + ) +else() + add_definitions( + -DTARGET_LINUX + -DLINUX + ) +endif() + add_definitions( -DMAXCPUS=256 -DMAXCPUSL=8 -DMAXCPUSR=8 - -DTARGET_LINUX -DTARGET_LLVM - -DLINUX -DPGF90 -DPGFLANG -DNATIVE_FPCVT diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 9ea054255e3..021b757f06e 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -500,9 +500,14 @@ set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) # add_dependencies(flang_shared flang_static) -target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.so) -# Resolve symbols against libm and librt -target_link_libraries(flang_shared m rt) +if( ${TARGET_OS} STREQUAL "Darwin" ) + target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.dylib) + target_link_libraries(flang_shared m pgmath omp) +else() + target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.so) + # Resolve symbols against libm and librt + target_link_libraries(flang_shared m rt) +endif() set(SHARED_LIBRARY FALSE) diff --git a/tools/flang2/CMakeLists.txt b/tools/flang2/CMakeLists.txt index 9a2dde76d01..75d99488aa7 100644 --- a/tools/flang2/CMakeLists.txt +++ b/tools/flang2/CMakeLists.txt @@ -23,7 +23,8 @@ set(FLANG2_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) include_directories(${FLANG2_INCLUDE_DIR}) -if( ${TARGET_OS} STREQUAL "Linux" ) +# this is a hack until there is a proper setup +if( ${TARGET_OS} STREQUAL "Linux|Darwin" ) if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" ) set(X86_64 ON) set(LINUX86 ON) From 5754fed4c995344608b5b0c652d1f9ac8ad279f3 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Fri, 14 Sep 2018 21:42:57 -0400 Subject: [PATCH 06/10] add x86_64-Darwin symlink to x86_64-Linux since they use the same code for now --- tools/flang2/flang2exe/x86_64-Darwin | 1 + 1 file changed, 1 insertion(+) create mode 120000 tools/flang2/flang2exe/x86_64-Darwin diff --git a/tools/flang2/flang2exe/x86_64-Darwin b/tools/flang2/flang2exe/x86_64-Darwin new file mode 120000 index 00000000000..8073d31fcf2 --- /dev/null +++ b/tools/flang2/flang2exe/x86_64-Darwin @@ -0,0 +1 @@ +x86_64-Linux \ No newline at end of file From 9c3e4a6ed698972c2bda68c53172d0f370b3b507 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Mon, 15 Feb 2021 13:23:12 +1300 Subject: [PATCH 07/10] use limits.h instead of linux/limits.h on macOS --- runtime/flangrti/trace_lin.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 78b161c4dcd..32d3ce4c4d9 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -15,7 +15,11 @@ #include #include #include +#ifdef TARGET_OSX +#include +#else #include +#endif #include /* codes and strings for signals */ From f26941a15721da3040c7a644a7a54b9e99149bd3 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Mon, 15 Feb 2021 13:23:46 +1300 Subject: [PATCH 08/10] don't declare bzero() as it's likely a macro --- tools/flang1/flang1exe/gbldefs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/flang1/flang1exe/gbldefs.h b/tools/flang1/flang1exe/gbldefs.h index 8b6efe40b96..ccb989b0c44 100644 --- a/tools/flang1/flang1exe/gbldefs.h +++ b/tools/flang1/flang1exe/gbldefs.h @@ -162,7 +162,6 @@ char *mkfname(char *, char *, char *); /* from miscutil.c: */ bool is_xflag_bit(int); void set_xflag(int, INT); void set_yflag(int, INT); -void bzero(void *, size_t); void list_init(FILE *); /* listing.c: */ void list_line(char *); /* listing.c */ void list_page(void); /* listing.c */ From 9038c1866974d62c6a8739ec6358730a85909104 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Mon, 15 Feb 2021 13:25:14 +1300 Subject: [PATCH 09/10] do not append _sse/_avx as it is never declared/used --- runtime/libpgmath/lib/common/dceil.c | 4 ++-- runtime/libpgmath/lib/common/dfloor.c | 4 ++-- runtime/libpgmath/lib/common/floor.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/libpgmath/lib/common/dceil.c b/runtime/libpgmath/lib/common/dceil.c index b1f8675e1d7..028b301ee5a 100644 --- a/runtime/libpgmath/lib/common/dceil.c +++ b/runtime/libpgmath/lib/common/dceil.c @@ -12,13 +12,13 @@ #if defined(__AVX__) double -__mth_i_dceil_avx(double x) +__mth_i_dceil(double x) { return _mm_cvtsd_f64(_mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x))); } #elif defined(__SSE4_1__) double -__mth_i_dceil_sse(double x) +__mth_i_dceil(double x) { return _mm_cvtsd_f64(_mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x))); } diff --git a/runtime/libpgmath/lib/common/dfloor.c b/runtime/libpgmath/lib/common/dfloor.c index db5c54cbe0f..5e78e3d0c05 100644 --- a/runtime/libpgmath/lib/common/dfloor.c +++ b/runtime/libpgmath/lib/common/dfloor.c @@ -12,13 +12,13 @@ #if defined(__AVX__) double -__mth_i_dfloor_avx(double x) +__mth_i_dfloor(double x) { return _mm_cvtsd_f64(_mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x))); } #elif defined(__SSE4_1__) double -__mth_i_dfloor_sse(double x) +__mth_i_dfloor(double x) { return _mm_cvtsd_f64(_mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x))); } diff --git a/runtime/libpgmath/lib/common/floor.c b/runtime/libpgmath/lib/common/floor.c index 6895671951f..1bd55a8d21c 100644 --- a/runtime/libpgmath/lib/common/floor.c +++ b/runtime/libpgmath/lib/common/floor.c @@ -12,13 +12,13 @@ #if defined(__AVX__) float -__mth_i_floor_avx(float x) +__mth_i_floor(float x) { return _mm_cvtss_f32(_mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x))); } #elif defined(__SSE4_1__) float -__mth_i_floor_sse(float x) +__mth_i_floor(float x) { return _mm_cvtss_f32(_mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x))); } From b795ff3c3fbd378f3c081ee9f09e962d03e913f5 Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Sun, 11 Apr 2021 19:54:40 -0400 Subject: [PATCH 10/10] fix dylib suffix for LIBPGMATH and FLANG_LIBOMP --- runtime/flangrti/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 97fe566302c..f21f5ca13b0 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -82,14 +82,14 @@ target_link_libraries(flangrti_shared m) if (NOT DEFINED LIBOMP_EXPORT_DIR) find_library( FLANG_LIBOMP - libomp.so + libomp${CMAKE_SHARED_LIBRARY_SUFFIX} HINTS ${CMAKE_BINARY_DIR}/lib) target_link_libraries(flangrti_shared ${FLANG_LIBOMP}) endif() find_library( LIBPGMATH - libpgmath.so + libpgmath${CMAKE_SHARED_LIBRARY_SUFFIX} HINTS ${CMAKE_BINARY_DIR}/lib) target_link_libraries(flangrti_shared ${LIBPGMATH})