Skip to content

Commit

Permalink
NativeAOT build (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Strehovský <[email protected]>
  • Loading branch information
jkotas and MichalStrehovsky authored Jul 30, 2020
1 parent 4796bd4 commit a89d3cb
Show file tree
Hide file tree
Showing 27 changed files with 517 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ if(CLR_CMAKE_HOST_WIN32)
add_compile_options(/Zl) # omit default library name in .OBJ
endif(CLR_CMAKE_HOST_WIN32)

if(NOT CLR_CROSS_COMPONENTS_BUILD)
add_subdirectory(src/nativeaot)
endif(NOT CLR_CROSS_COMPONENTS_BUILD)

#--------------------------------
# Definition directives
# - all clr specific compile definitions should be included in this file
Expand Down
14 changes: 12 additions & 2 deletions src/coreclr/src/inc/gcinfodecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ typedef ArrayDPTR(const uint8_t) PTR_CBYTE;

#define VALIDATE_ROOT(isInterior, hCallBack, pObjRef)

#define _ASSERTE(x) assert(x)

#define UINT32 UInt32
#define INT32 Int32
#define UINT16 UInt16
Expand All @@ -56,6 +54,18 @@ typedef void * OBJECTREF;

#define GET_CALLER_SP(pREGDISPLAY) ((TADDR)0)

struct GCInfoToken
{
PTR_VOID Info;
UINT32 Version;

GCInfoToken(PTR_VOID info)
{
Info = info;
Version = 2;
}
};

#else // FEATURE_REDHAWK

// Stuff from cgencpu.h:
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/nativeaot/Bootstrap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(base)
add_subdirectory(dll)
13 changes: 13 additions & 0 deletions src/coreclr/src/nativeaot/Bootstrap/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
project(bootstrapper)

set(SOURCES
../main.cpp
)

add_library(bootstrapper STATIC ${SOURCES})

# Install the static bootstrapper library
install (TARGETS bootstrapper DESTINATION sdk)
if(WIN32)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrapper.dir/$<CONFIG>/bootstrapper.pdb DESTINATION sdk)
endif()
15 changes: 15 additions & 0 deletions src/coreclr/src/nativeaot/Bootstrap/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project(bootstrapperdll)

add_definitions(-DCORERT_DLL)

set(SOURCES
../main.cpp
)

add_library(bootstrapperdll STATIC ${SOURCES})

# Install the static bootstrapperdll library
install (TARGETS bootstrapperdll DESTINATION sdk)
if(WIN32)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrapperdll.dir/$<CONFIG>/bootstrapperdll.pdb DESTINATION sdk)
endif()
5 changes: 4 additions & 1 deletion src/coreclr/src/nativeaot/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include <stdint.h>
#include <stdlib.h>

//
// This is the mechanism whereby multiple linked modules contribute their global data for initialization at
Expand Down Expand Up @@ -126,6 +125,10 @@ static const pfn c_classlibFunctions[] = {
nullptr, // &DebugFuncEvalAbortHelper,
};

#ifndef _countof
#define _countof(_array) (sizeof(_array)/sizeof(_array[0]))
#endif

extern "C" void InitializeModules(void* osModule, void ** modules, int count, void ** pClasslibFunctions, int nClasslibFunctions);

#ifndef CORERT_DLL
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/src/nativeaot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if(WIN32)
add_definitions(-DUNICODE=1)
endif (WIN32)

if(MSVC)
add_compile_options(/EHa- /EHs) # Native AOT runtime does not use C++ exception handling

add_compile_options(/guard:cf-) # CFG runtime checks in C++ code are unnecessary overhead unless Native AOT compiler produces CFG compliant code as well
# and CFG is enabled in the linker
endif (MSVC)

add_subdirectory(Bootstrap)
add_subdirectory(Runtime)
284 changes: 284 additions & 0 deletions src/coreclr/src/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
set(GC_DIR ../../gc)

set(COMMON_RUNTIME_SOURCES
allocheap.cpp
rhassert.cpp
CachedInterfaceDispatch.cpp
Crst.cpp
DebugEventSource.cpp
DebugFuncEval.cpp
DebuggerHook.cpp
eetype.cpp
EHHelpers.cpp
event.cpp
FinalizerHelpers.cpp
GCHelpers.cpp
gctoclreventsink.cpp
gcheaputilities.cpp
GCMemoryHelpers.cpp
gcrhenv.cpp
gcrhscan.cpp
GcStressControl.cpp
HandleTableHelpers.cpp
MathHelpers.cpp
MiscHelpers.cpp
TypeManager.cpp
ObjectLayout.cpp
OptionalFieldsRuntime.cpp
portable.cpp
profheapwalkhelper.cpp
RestrictedCallouts.cpp
RhConfig.cpp
RuntimeInstance.cpp
RWLock.cpp
sha1.cpp
StackFrameIterator.cpp
startup.cpp
stressLog.cpp
strongname.cpp
SyncClean.cpp
thread.cpp
threadstore.cpp
UniversalTransitionHelpers.cpp
yieldprocessornormalized.cpp

${GC_DIR}/gceventstatus.cpp
${GC_DIR}/gcload.cpp
${GC_DIR}/gcconfig.cpp
${GC_DIR}/gchandletable.cpp
${GC_DIR}/gccommon.cpp
${GC_DIR}/gceewks.cpp
${GC_DIR}/gcwks.cpp
${GC_DIR}/gcscan.cpp
${GC_DIR}/handletable.cpp
${GC_DIR}/handletablecache.cpp
${GC_DIR}/handletablecore.cpp
${GC_DIR}/handletablescan.cpp
${GC_DIR}/objecthandle.cpp
)

set(SERVER_GC_SOURCES
${GC_DIR}/gceesvr.cpp
${GC_DIR}/gcsvr.cpp
)

set(FULL_RUNTIME_SOURCES
AsmOffsetsVerify.cpp
ThunksMapping.cpp
)

set(RUNTIME_SOURCES_ARCH_ASM
)

set(PORTABLE_RUNTIME_SOURCES
)

include_directories(inc)

include_directories(.)
include_directories(${GC_DIR})
include_directories(${GC_DIR}/env)

if (WIN32)
set(GC_HEADERS
${GC_DIR}/env/common.h
${GC_DIR}/env/etmdummy.h
${GC_DIR}/env/gcenv.base.h
${GC_DIR}/env/gcenv.ee.h
${GC_DIR}/env/gcenv.h
${GC_DIR}/env/gcenv.interlocked.h
${GC_DIR}/env/gcenv.interlocked.inl
${GC_DIR}/env/gcenv.object.h
${GC_DIR}/env/gcenv.os.h
${GC_DIR}/env/gcenv.structs.h
${GC_DIR}/env/gcenv.sync.h
${GC_DIR}/env/gcenv.windows.inl
${GC_DIR}/env/volatile.h
${GC_DIR}/gc.h
${GC_DIR}/gcconfig.h
${GC_DIR}/gcdesc.h
${GC_DIR}/gcenv.ee.standalone.inl
${GC_DIR}/gcenv.inl
${GC_DIR}/gcevent_serializers.h
${GC_DIR}/gcevents.h
${GC_DIR}/gceventstatus.h
${GC_DIR}/gchandletableimpl.h
${GC_DIR}/gcimpl.h
${GC_DIR}/gcinterface.dac.h
${GC_DIR}/gcinterface.ee.h
${GC_DIR}/gcinterface.h
${GC_DIR}/gcpriv.h
${GC_DIR}/gcrecord.h
${GC_DIR}/gcscan.h
${GC_DIR}/handletable.h
${GC_DIR}/handletable.inl
${GC_DIR}/handletablepriv.h
${GC_DIR}/objecthandle.h
${GC_DIR}/softwarewritewatch.h)
endif(WIN32)

if(WIN32)

include_directories(windows)

list(APPEND COMMON_RUNTIME_SOURCES
windows/PalRedhawkCommon.cpp
windows/PalRedhawkMinWin.cpp
${GC_DIR}/windows/gcenv.windows.cpp
eventtrace.cpp
rheventtrace.cpp
)

list(APPEND FULL_RUNTIME_SOURCES
windows/CoffNativeCodeManager.cpp
)

set(ASM_SUFFIX asm)

if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
set(ARCH_SOURCES_DIR amd64)
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)
set(ARCH_SOURCES_DIR i386)
endif()

list(APPEND RUNTIME_SOURCES_ARCH_ASM
${ARCH_SOURCES_DIR}/GC.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/GcProbe.${ASM_SUFFIX}
)

else()

include_directories(unix)

include(CheckIncludeFiles)
include(CheckLibraryExists)

include(${GC_DIR}/unix/configure.cmake)

if(NOT CLR_CMAKE_PLATFORM_ARCH_WASM)
include_directories(../libunwind/include)
else()
include_directories($ENV{EMSCRIPTEN/system/lib/libcxxabi/include})
endif()

include_directories(../libunwind/include)
include_directories(../libunwind)

# Disable building _Unwind_XXX style APIs of libunwind, since we don't use them.
add_definitions(-D_LIBUNWIND_DISABLE_ZERO_COST_APIS=1)

# Compile unwinding only for the current compilation target architecture
add_definitions(-D_LIBUNWIND_IS_NATIVE_ONLY)

list(APPEND COMMON_RUNTIME_SOURCES
unix/PalRedhawkUnix.cpp
${GC_DIR}/unix/gcenv.unix.cpp
${GC_DIR}/unix/events.cpp
${GC_DIR}/unix/cgroup.cpp
)

list(APPEND FULL_RUNTIME_SOURCES
unix/HardwareExceptions.cpp
unix/UnixContext.cpp
unix/UnwindHelpers.cpp
unix/UnixNativeCodeManager.cpp
../libunwind/src/Unwind-EHABI.cpp
../libunwind/src/libunwind.cpp
)

if(CLR_CMAKE_PLATFORM_DARWIN)
list(APPEND FULL_RUNTIME_SOURCES
../libunwind/src/Unwind_AppleExtras.cpp
)
endif()

set(ASM_SUFFIX S)
if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
set(ARCH_SOURCES_DIR amd64)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
set(ARCH_SOURCES_DIR arm64)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
set(ARCH_SOURCES_DIR arm)
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)
set(ARCH_SOURCES_DIR i386)
elseif(CLR_CMAKE_PLATFORM_ARCH_WASM)
set(ARCH_SOURCES_DIR wasm)
endif()

list(APPEND RUNTIME_SOURCES_ARCH_ASM
../libunwind/src/UnwindRegistersRestore.S
../libunwind/src/UnwindRegistersSave.S
)
endif()

list(APPEND RUNTIME_SOURCES_ARCH_ASM
${ARCH_SOURCES_DIR}/AllocFast.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/CallDescrWorker.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/CallingConventionConverterHelpers.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/ExceptionHandling.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/Interlocked.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/MiscStubs.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/PInvoke.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/InteropThunksHelpers.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/StubDispatch.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/UniversalTransition.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/WriteBarriers.${ASM_SUFFIX}
)

# Add architecture specific folder for looking up headers.
convert_to_absolute_path(ARCH_SOURCES_DIR ${ARCH_SOURCES_DIR})
include_directories(${ARCH_SOURCES_DIR})

add_definitions(-DFEATURE_BASICFREEZE)
add_definitions(-DFEATURE_CONSERVATIVE_GC)
add_definitions(-DFEATURE_CUSTOM_IMPORTS)
add_definitions(-DFEATURE_DYNAMIC_CODE)
add_compile_options($<$<CONFIG:Debug>:-DFEATURE_GC_STRESS>)
add_definitions(-DFEATURE_REDHAWK)
add_definitions(-DVERIFY_HEAP)
add_definitions(-DCORERT)
add_definitions(-DFEATURE_CACHED_INTERFACE_DISPATCH)
add_definitions(-D_LIB)
add_definitions(-DFEATURE_EMBEDDED_CONFIG)

# there is a problem with undefined symbols when this is set
# add_definitions(-DSTRESS_HEAP)

if(WIN32)
add_definitions(-DFEATURE_ETW)
add_definitions(-DFEATURE_EVENT_TRACE)
else()
add_definitions(-DNO_UI_ASSERT)
include(unix/configure.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
endif()

if (CLR_CMAKE_TARGET_UNIX)

if (CLR_CMAKE_TARGET_ARCH_AMD64)
add_definitions(-DUNIX_AMD64_ABI)
elseif (CLR_CMAKE_TARGET_ARCH_ARM)
add_definitions(-DUNIX_ARM_ABI)
elseif (CLR_CMAKE_TARGET_ARCH_I386)
add_definitions(-DUNIX_X86_ABI)
endif()

endif(CLR_CMAKE_TARGET_UNIX)

set(RUNTIME_DIR ${CMAKE_CURRENT_SOURCE_DIR})

list(APPEND COMMON_RUNTIME_SOURCES ${GC_HEADERS})

convert_to_absolute_path(COMMON_RUNTIME_SOURCES ${COMMON_RUNTIME_SOURCES})

convert_to_absolute_path(FULL_RUNTIME_SOURCES ${FULL_RUNTIME_SOURCES})
convert_to_absolute_path(PORTABLE_RUNTIME_SOURCES ${PORTABLE_RUNTIME_SOURCES})
convert_to_absolute_path(SERVER_GC_SOURCES ${SERVER_GC_SOURCES})

convert_to_absolute_path(RUNTIME_SOURCES_ARCH_ASM ${RUNTIME_SOURCES_ARCH_ASM})

if(NOT CLR_CMAKE_PLATFORM_ARCH_WASM)
add_subdirectory(Full)
endif()

add_subdirectory(Portable)
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "TypeManager.h"
#include "RuntimeInstance.h"
#include "eetype.inl"
#include "CommonMacros.inl"

#include "CachedInterfaceDispatch.h"

Expand Down
Loading

0 comments on commit a89d3cb

Please sign in to comment.