Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for macOS #592

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions runtime/flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion runtime/flang/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions runtime/flang/stime3f.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -25,6 +29,7 @@ int ENT3F(STIME, stime)(int *tp)
i = __io_errno();

return i;
#endif
}

#endif /* !WINNT */
4 changes: 2 additions & 2 deletions runtime/flangrti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
8 changes: 6 additions & 2 deletions runtime/flangrti/dumpregs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion runtime/flangrti/iostdinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ __io_ferror(void *p)
int
__io_getfd(void *fp)
{
return (((FILE *)fp)->_fileno);
return fileno((FILE *)fp);
kiranchandramohan marked this conversation as resolved.
Show resolved Hide resolved
}

/* is a tty? */
Expand Down
4 changes: 4 additions & 0 deletions runtime/flangrti/ktrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions runtime/flangrti/trace_lin.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef TARGET_OSX
#include <limits.h>
#else
#include <linux/limits.h>
#endif
#include <inttypes.h>

/* codes and strings for signals */
Expand Down
4 changes: 2 additions & 2 deletions runtime/libpgmath/lib/common/dceil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/libpgmath/lib/common/dfloor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/libpgmath/lib/common/floor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
1 change: 0 additions & 1 deletion tools/flang1/flang1exe/gbldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion tools/flang2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/flang2/flang2exe/x86_64-Darwin