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 OpenBSD as a recognized OS #521

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ if( ${TARGET_OS} STREQUAL "Linux" )
message("Unsupported architecture: ${TARGET_ARCHITECTURE}" )
return()
endif()
elseif( ${TARGET_OS} STREQUAL "OpenBSD")
set(OS "OPENBSD")
set(OSNAME "OpenBSD")
if ( ${TARGET_ARCHITECTURE} STREQUAL "amd64" )
set(ARCHNAME x86-64)
set(ARCH X86)
set(WRDSZ 64)
set(TARGET_ARCHITECTURE x86_64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was playing around with the port, I did the same thing -- set TARGET_ARCHITECTURE to x86_64. I'm wondering if we shouldn't factor our TARGET_ARCHITECTURE to be something like FLANG_TARGET_ARCHITECTURE. The downside is that it might introduce confusion and bugs because people know about TARGET_ARCHITECTURE. This isn't a call to action; just a discussion point that probably better raised in the mailing list :)

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}" )
return()
Expand Down
7 changes: 7 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ add_definitions(
-DPGI_LITTLE_ENDIAN
)

if( ${TARGET_OS} STREQUAL "OpenBSD" )
add_definitions(
-DTARGET_OPENBSD
-DOPENBSD
}
endif()

if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" )
add_definitions(
-DTARGET_X8664
Expand Down
4 changes: 2 additions & 2 deletions runtime/flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand 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"
Expand All @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions runtime/flangrti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ find_library(
HINTS ${CMAKE_BINARY_DIR}/lib)
target_link_libraries(flangrti_shared ${LIBPGMATH})

# BSDs need libexecinfo
if( ${TARGET_OS} STREQUAL "OpenBSD" )
target_link_libraries(flangrti_shared ${FLANG_LIBEXECINFO})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will flang-driver need to add libexecinfo to the linker command line?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; I do a static link of libexecinfo into flangrti.so
I also set up the flang driver to do all the linking magic behind the scenes. Users simply do something like:
$ flang myfile.F95
and everything just works.

See https://github.com/openbsd/ports/blob/master/lang/flang/driver/patches/patch-lib_Driver_ToolChains_OpenBSD_cpp#L54

endif()

if( ${TARGET_ARCHITECTURE} STREQUAL "aarch64" )
target_compile_definitions(flangrti_static PRIVATE TARGET_LINUX_ARM)
target_compile_definitions(flangrti_shared PRIVATE TARGET_LINUX_ARM)
Expand Down
15 changes: 15 additions & 0 deletions runtime/flangrti/aarch64-Linux/dumpregs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

#ifndef TARGET_OPENBSD
#include <sys/ucontext.h>

void
Expand All @@ -29,3 +30,17 @@ getRegs(ucontext_t *u)
return (gregset_t *)0;
}

#else

void
dumpregs(void *regs)
{
}

void *
getRegs(void *u)
{
return (void *)0;
}

#endif
8 changes: 8 additions & 0 deletions runtime/flangrti/dumpregs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
* Declare routines that access the machine registers
*/

#ifndef TARGET_OPENBSD

void dumpregs(gregset_t *regs);
gregset_t *getRegs(ucontext_t *u);

#else

void dumpregs(void *regs);
void *getRegs(ucontext_t *u);

#endif
4 changes: 2 additions & 2 deletions runtime/flangrti/x86_64-Linux/dumpregs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

#if !defined(TARGET_WIN)
#if !defined(TARGET_WIN) && !defined(TARGET_OPENBSD)
#include <sys/ucontext.h>
#endif
#include "stdioInterf.h"
Expand All @@ -40,7 +40,7 @@
#define RSP 15
#define RIP 16

#if defined(TARGET_OSX) || defined(TARGET_WIN)
#if defined(TARGET_OSX) || defined(TARGET_WIN) || defined(TARGET_OPENBSD)
/* no gregs and/or ucontext defined in for OSX or Windows */
void *
getRegs(void *u)
Expand Down
5 changes: 5 additions & 0 deletions tools/flang2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ if( ${TARGET_OS} STREQUAL "Linux" )
set(X86_64 ON)
set(LINUX86 ON)
endif()
if( ${TARGET_OS} STREQUAL "OpenBSD" )
if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" )
set(X86_64 ON)
set(LINUX86 ON)
endif()
endif()

add_subdirectory(include)
Expand Down
8 changes: 7 additions & 1 deletion tools/flang2/flang2exe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ elseif( ${TARGET_ARCHITECTURE} STREQUAL "ppc64le" )
)
endif()

if( ${TARGET_OS} STREQUAL "Linux" )
set(TARGET_CLASS "Linux")
elseif( ${TARGET_OS} STREQUAL "OpenBSD" )
set(TARGET_CLASS "Linux")
endif()


set(SOURCES
${ARCH_DEP_FILES}
Expand Down Expand Up @@ -101,7 +107,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}-${TARGET_CLASS}
${UTILS_SYMTAB_BIN_DIR} # Symbol table headers
${UTILS_ILI_BIN_DIR} # ILI IR headers
${UTILS_ILM_BIN_DIR} # ILM IR headers
Expand Down