Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Initial Mac OSX Support #117

Merged
merged 9 commits into from
Feb 7, 2015
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,7 @@ Temporary Items
# Ignore folders created by the test build
TestWrappers_x64_debug
TestWrappers_x64_release

Vagrantfile
.vagrant

23 changes: 19 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ project(CoreCLR)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
set(CLR_CMAKE_PLATFORM_LINUX 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
set(CLR_CMAKE_PLATFORM_DARWIN 1)
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> -o <OBJECT> -c <SOURCE>")
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)

# Build a list of compiler definitions by putting -D in front of each define.
function(get_compile_definitions DefinitionName)
# Get the current list of definitions
Expand Down Expand Up @@ -126,7 +134,7 @@ if (WIN32)
endif (CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64)

elseif (CLR_CMAKE_PLATFORM_UNIX)
# Set flag to indicate if this will be a 64bit Linux build
# Set flag to indicate if this will be a 64bit build
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(IS_64BIT_BUILD 1)
endif (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
Expand Down Expand Up @@ -285,17 +293,24 @@ endif (WIN32)

if (CLR_CMAKE_PLATFORM_UNIX)
add_definitions(-DPLATFORM_UNIX=1)
add_definitions(-D__LINUX__=1)
add_definitions(-DFEATURE_PAL_SXS)

if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
message("Detected Linux x86_64")
add_definitions(-DLINUX64)
add_definitions(-DBIT64=1)
add_definitions(-DFEATURE_PAL)
else (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
message(FATAL_ERROR "error: Detected non x86_64 target processor. Not supported!")
endif(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)

if(CLR_CMAKE_PLATFORM_LINUX)
add_definitions(-D__LINUX__=1)
message("Detected Linux x86_64")
add_definitions(-DLINUX64)
endif(CLR_CMAKE_PLATFORM_LINUX)
if(CLR_CMAKE_PLATFORM_DARWIN)
message("Detected OSX x86_64")
add_definitions(-D_XOPEN_SOURCE)
endif(CLR_CMAKE_PLATFORM_DARWIN)
endif(CLR_CMAKE_PLATFORM_UNIX)


Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/hosts/unixcorerun/corerun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#include <set>

// The name of the CoreCLR native runtime DLL.
#if defined(__APPLE__)
static const char * const coreClrDll = "libcoreclr.dylib";
#else
static const char * const coreClrDll = "libcoreclr.so";
#endif

// Windows types used by the ExecuteAssembly function
typedef unsigned int DWORD;
Expand Down
4 changes: 3 additions & 1 deletion src/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ add_subdirectory(daccess)
add_subdirectory(dbgutil)
add_subdirectory(ildbsymlib)
add_subdirectory(ee)
add_subdirectory(di)
if(NOT CLR_CMAKE_PLATFORM_DARWIN)
add_subdirectory(di)
endif(NOT CLR_CMAKE_PLATFORM_DARWIN)
if(WIN32)
add_subdirectory(shim)
endif(WIN32)
2 changes: 1 addition & 1 deletion src/debug/di/amd64/floatconversion.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
LEAF_ENTRY FPFillR8, _TEXT
movdqa xmm0, [rdi]
ret
LEAF_END FPFillR8
LEAF_END FPFillR8, _TEXT
4 changes: 2 additions & 2 deletions src/debug/ee/amd64/dbghelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NESTED_ENTRY FuncEvalHijack, _TEXT, FuncEvalHijackPersonalityRoutine
END_PROLOGUE

mov [rsp], rdi
call FuncEvalHijackWorker
call C_FUNC(FuncEvalHijackWorker)

//
// The following nop is crucial. It is important that the OS *not* recognize
Expand Down Expand Up @@ -67,7 +67,7 @@ NESTED_ENTRY ExceptionHijack, _TEXT, ExceptionHijackPersonalityRoutine
mov [rsp + 18h], rax

// DD Hijack primitive already set the stack. So just make the call now.
call ExceptionHijackWorker
call C_FUNC(ExceptionHijackWorker)

//
// The following nop is crucial. It is important that the OS *not* recognize
Expand Down
4 changes: 3 additions & 1 deletion src/dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if(WIN32)
add_subdirectory(mscorrc)
add_subdirectory(dbgshim)
endif(WIN32)
add_subdirectory(mscordbi)
if(NOT CLR_CMAKE_PLATFORM_DARWIN)
add_subdirectory(mscordbi)
endif(NOT CLR_CMAKE_PLATFORM_DARWIN)
add_subdirectory(mscordac)
add_subdirectory(mscoree)
9 changes: 6 additions & 3 deletions src/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ set(END_LIBRARY_GROUP)
else(WIN32)

add_definitions(-DNO_CRT_INIT)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
# This option is necessary to ensure that the overloaded delete operator defined inside
# of the utilcode will be used instead of the standard library delete operator.
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic-functions")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic-functions")

# The following linked options can be inserted into the linker libraries list to
# ensure proper resolving of circular references between a subset of the libraries.
set(START_LIBRARY_GROUP -Wl,--start-group)
set(END_LIBRARY_GROUP -Wl,--end-group)
set(START_LIBRARY_GROUP -Wl,--start-group)
set(END_LIBRARY_GROUP -Wl,--end-group)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

endif (WIN32)

Expand Down
29 changes: 1 addition & 28 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3280,37 +3280,10 @@ GetModuleFileNameW(
#define GetModuleFileName GetModuleFileNameA
#endif

#ifdef __APPLE__
// Get the base address of a module given an address in that module
PALAPI
LPCVOID
PAL_GetModuleBaseFromAddress(LPCVOID pAddress);

// Retrieve the UUID in the image.
PALAPI
BOOL
PAL_GetUUIDOfImage(LPCVOID pImageBase, BYTE * pUUID);

// Retrieve the version stored in the Info.plist file in the CoreCLR bundle.
PALAPI
DWORD
PAL_GetVersionString(IN WCHAR * pwszCoreClrFullPath,
IN OUT WCHAR * pwszVersionString,
IN DWORD cchVersionStringBuffer,
OUT DWORD *pcchVersionStringBufferRequired);

PALAPI
DWORD
PAL_GetCoreCLRVersionString(
IN OUT WCHAR * pwszVersionString,
IN DWORD cchVersionStringBuffer,
OUT DWORD *pcchVersionStringBufferRequired);
#else // __APPLE__
// Get base address of the coreclr module
PALAPI
LPCVOID
PAL_GetCoreClrModuleBase();
#endif // __APPLE__

PALIMPORT
LPVOID
Expand Down Expand Up @@ -6139,7 +6112,7 @@ PAL_CppRethrow();
//
#ifdef PLATFORM_UNIX
#ifdef __APPLE__
#define MAKEDLLNAME_W(name) L"lib" name L".dylib"
#define MAKEDLLNAME_W(name) u"lib" name u".dylib"
#define MAKEDLLNAME_A(name) "lib" name ".dylib"
#elif defined(_AIX)
#define MAKEDLLNAME_W(name) L"lib" name L".a"
Expand Down
36 changes: 33 additions & 3 deletions src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ include_directories(include)

# Compile options

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_definitions(-D_TARGET_MAC64)
set(PLATFORM_SOURCES
arch/i386/context.S
arch/i386/dispatchexceptionwrapper.S
exception/machexception.cpp
exception/machmessage.cpp
locale/locale.cpp
)
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
add_definitions(-D__LINUX__=1)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

add_definitions(-DPLATFORM_UNIX=1)
add_definitions(-D__LINUX__=1)
add_definitions(-DLP64COMPATIBLE=1)
add_definitions(-DFEATURE_PAL=1)
add_definitions(-DCORECLR=1)
Expand Down Expand Up @@ -128,14 +142,30 @@ set(SOURCES
add_library(CoreClrPal
STATIC
${SOURCES}
${PLATFORM_SOURCES}
)

target_link_libraries(CoreClrPal
pthread
rt
dl
m
)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_link_libraries(CoreClrPal
pthread
rt
)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
find_library(COREFOUNDATION CoreFoundation)
find_library(CORESERVICES CoreServices)
find_library(SECURITY Security)
target_link_libraries(CoreClrPal
${COREFOUNDATION}
${CORESERVICES}
${SECURITY}
)
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)

add_subdirectory(examples)
17 changes: 17 additions & 0 deletions src/pal/src/arch/i386/context.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if defined(_DEBUG)
.text
.globl _DBG_CheckStackAlignment

_DBG_CheckStackAlignment:
// Prolog - at this point we are at aligned - 8 (for the call)
pushq %rbp // aligned -16
movq %rsp, %rbp

testl $0xf,%esp // can get away with esp even on AMD64.
jz .+3
int3

// Epilog
popq %rbp
ret
#endif
41 changes: 1 addition & 40 deletions src/pal/src/arch/i386/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ CONTEXT_SetThreadContextOnPort(
// the xmm values) then we don't have values for the other set. This is a problem since Mach only
// supports setting both groups as a single unit. So in this case we'll need to fetch the current
// values first.
if (lpContext->ContextFlags & CONTEXT_ALL_FLOATING !=
if ((lpContext->ContextFlags & CONTEXT_ALL_FLOATING) !=
CONTEXT_ALL_FLOATING)
{
mach_msg_type_number_t StateCountGet = StateCount;
Expand Down Expand Up @@ -1311,42 +1311,3 @@ DBG_FlushInstructionCache(
// Intel x86 hardware has cache coherency, so nothing needs to be done.
return TRUE;
}

#if _DEBUG && defined(__APPLE__)
/*++
Function:
DBG_CheckStackAlignment

The Apple ABI requires 16-byte alignment on the stack pointer.
This function interrupts otherwise.
--*/
// Bullseye has parsing problems if "asm" comes after VOID
asm VOID
DBG_CheckStackAlignment()
{
#ifndef __llvm__
#ifdef _X86_
// Prolog - at this point we are at aligned - 4 (for the call)
push ebp // aligned - 8
mov ebp, esp
sub esp,STACK_ALIGN_REQ-8 // aligned (or should be)
#elif defined(_AMD64_)
// Prolog - at this point we are at aligned - 8 (for the call)
push rbp // aligned -16
mov rbp, rsp
#else
#error Unexpected architecture.
#endif
#endif // !__llvm__

test esp,STACK_ALIGN_REQ-1 // can get away with esp even on AMD64.
jz .+3
int 3

#ifndef __llvm__
// Epilog
leave
#endif // !__llvm__
}
#endif // DEBUG && APPLE

2 changes: 1 addition & 1 deletion src/pal/src/arch/i386/dispatchexceptionwrapper.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// increase the size of the function to include a call statement,
// even though it will never be executed.

#if defined(_AMD64_)
#if defined(__x86_64__)
#define PAL_DISPATCHEXCEPTION __Z21PAL_DispatchExceptionmmmmmmP8_CONTEXTP17_EXCEPTION_RECORD
#else //!defined(_AMD64_)
#define PAL_DISPATCHEXCEPTION __Z21PAL_DispatchExceptionP8_CONTEXTP17_EXCEPTION_RECORD
Expand Down
Loading