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

[WIP] FreeBSD support #7008

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ else(NOT CHAKRACORE_BUILD_SH)
endif(NOT CHAKRACORE_BUILD_SH)

if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
set(CC_TARGETS_AMD64_SH 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(CC_TARGETS_ARM_SH 1)
Expand Down Expand Up @@ -121,6 +122,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CC_TARGET_OS_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CC_TARGET_OS_OSX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(CC_TARGET_OS_FREEBSD 1)
endif()

if (ENABLE_CC_XPLAT_TRACE_SH)
Expand Down Expand Up @@ -331,6 +334,11 @@ elseif(CC_TARGET_OS_OSX)
message(WARNING "-- !! macOS Deployment Target was set to $ENV{MACOSX_DEPLOYMENT_TARGET}. Using it as is.")
endif()
endif()
elseif(CC_TARGET_OS_FREEBSD)
add_definitions(
-DPLATFORM_UNIX
)
# TODO
else()
message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
endif()
Expand Down
9 changes: 8 additions & 1 deletion lib/Common/Common/ByteSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ RtlUlonglongByteSwap(
#define RtlUlongByteSwap(_x) __bswap_32((_x))
#define RtlUlonglongByteSwap(_x) __bswap_64((_x))

#elif defined(__FreeBSD__)
#include <byteswap.h>
/* FreeBSD 13+, also above definitions would work
* TODO replace with "has byteswap.h" check? */
#define RtlUshortByteSwap(_x) bswap_16((_x))
#define RtlUlongByteSwap(_x) bswap_32((_x))
#define RtlUlonglongByteSwap(_x) bswap_64((_x))

#else
// TODO: include endian.h for BSD?
#error "ByteSwap.h: Not implemented for this platform"
#endif
4 changes: 2 additions & 2 deletions lib/Common/Core/SysInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <VersionHelpers.h>
#ifdef __APPLE__
#include <sys/sysctl.h> // sysctl*
#elif defined(__linux__)
#elif defined(__linux__) || defined(__FreeBSD__)
#include <unistd.h> // sysconf
#endif
// Initialization order
Expand Down Expand Up @@ -194,7 +194,7 @@ AutoSystemInfo::InitPhysicalProcessorCount()
countPhysicalProcessor = 1;
}
}
#elif defined(__linux__)
#elif defined(__linux__) || defined(__FreeBSD__)
countPhysicalProcessor = sysconf(_SC_NPROCESSORS_ONLN);
#else
// implementation for __linux__ should work for some others.
Expand Down
5 changes: 5 additions & 0 deletions pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ extern "C" {
#endif
#endif

#ifndef __FreeBSD__
#define PAL_GLOBAL __attribute__((init_priority(200)))
#else
/* TODO above macro expansion fails to compile on FreeBSD */
#define PAL_GLOBAL
#endif
/******************* PAL-Specific Entrypoints *****************************/

#define IsDebuggerPresent PAL_IsDebuggerPresent
Expand Down
1 change: 1 addition & 0 deletions pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#cmakedefine01 ERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS
#cmakedefine01 HAS_FTRUNCATE_LENGTH_ISSUE
#cmakedefine FREEBSD_LIBC "@FREEBSD_LIBC@"
#cmakedefine BSD_REGS_STYLE(reg, RR, rr) @BSD_REGS_STYLE@

#cmakedefine JA_JP_LOCALE_NAME "@JA_JP_LOCALE_NAME@"
#cmakedefine KO_KR_LOCALE_NAME "@KO_KR_LOCALE_NAME@"
Expand Down
7 changes: 7 additions & 0 deletions pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(KO_KR_LOCALE_NAME ko_KR_LOCALE_NOT_FOUND)
set(ZH_TW_LOCALE_NAME zh_TW_LOCALE_NOT_FOUND)
set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
set(BSD_REGS_STYLE "((reg).r_##rr)")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(BSD_REGS_STYLE "((reg).rr)")
else()
message(FATAL_ERROR "Unsupported FreeBSD architecture")
endif()

if(EXISTS "/lib/libc.so.7")
set(FREEBSD_LIBC "/lib/libc.so.7")
Expand Down
3 changes: 3 additions & 0 deletions pal/src/include/pal/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ extern "C"
* platforms and another type elsewhere. */
#if HAVE_UCONTEXT_T
#include <ucontext.h>
#ifdef __FreeBSD__
#include <machine/fpu.h>
#endif

typedef ucontext_t native_context_t;
#else // HAVE_UCONTEXT_T
Expand Down
Loading