diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 0d60cf16fc10..c61db9b42504 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -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 diff --git a/src/coreclr/src/inc/gcinfodecoder.h b/src/coreclr/src/inc/gcinfodecoder.h index 3eeeb005b1bd..576b5201623d 100644 --- a/src/coreclr/src/inc/gcinfodecoder.h +++ b/src/coreclr/src/inc/gcinfodecoder.h @@ -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 @@ -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: diff --git a/src/coreclr/src/nativeaot/Bootstrap/CMakeLists.txt b/src/coreclr/src/nativeaot/Bootstrap/CMakeLists.txt new file mode 100644 index 000000000000..02fb30aad9f0 --- /dev/null +++ b/src/coreclr/src/nativeaot/Bootstrap/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(base) +add_subdirectory(dll) diff --git a/src/coreclr/src/nativeaot/Bootstrap/base/CMakeLists.txt b/src/coreclr/src/nativeaot/Bootstrap/base/CMakeLists.txt new file mode 100644 index 000000000000..2b9d9b4e3d0f --- /dev/null +++ b/src/coreclr/src/nativeaot/Bootstrap/base/CMakeLists.txt @@ -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/$/bootstrapper.pdb DESTINATION sdk) +endif() diff --git a/src/coreclr/src/nativeaot/Bootstrap/dll/CMakeLists.txt b/src/coreclr/src/nativeaot/Bootstrap/dll/CMakeLists.txt new file mode 100644 index 000000000000..39823ac2d19b --- /dev/null +++ b/src/coreclr/src/nativeaot/Bootstrap/dll/CMakeLists.txt @@ -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/$/bootstrapperdll.pdb DESTINATION sdk) +endif() diff --git a/src/coreclr/src/nativeaot/Bootstrap/main.cpp b/src/coreclr/src/nativeaot/Bootstrap/main.cpp index 169ee746c085..d1847eb01310 100644 --- a/src/coreclr/src/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/src/nativeaot/Bootstrap/main.cpp @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. #include -#include // // This is the mechanism whereby multiple linked modules contribute their global data for initialization at @@ -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 diff --git a/src/coreclr/src/nativeaot/CMakeLists.txt b/src/coreclr/src/nativeaot/CMakeLists.txt new file mode 100644 index 000000000000..196587775bfa --- /dev/null +++ b/src/coreclr/src/nativeaot/CMakeLists.txt @@ -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) diff --git a/src/coreclr/src/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/src/nativeaot/Runtime/CMakeLists.txt new file mode 100644 index 000000000000..6cce2159e837 --- /dev/null +++ b/src/coreclr/src/nativeaot/Runtime/CMakeLists.txt @@ -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($<$:-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) diff --git a/src/coreclr/src/nativeaot/Runtime/CachedInterfaceDispatch.cpp b/src/coreclr/src/nativeaot/Runtime/CachedInterfaceDispatch.cpp index 1a9a15aafda8..b40dab1f729b 100644 --- a/src/coreclr/src/nativeaot/Runtime/CachedInterfaceDispatch.cpp +++ b/src/coreclr/src/nativeaot/Runtime/CachedInterfaceDispatch.cpp @@ -32,6 +32,7 @@ #include "TypeManager.h" #include "RuntimeInstance.h" #include "eetype.inl" +#include "CommonMacros.inl" #include "CachedInterfaceDispatch.h" diff --git a/src/coreclr/src/nativeaot/Runtime/CommonMacros.h b/src/coreclr/src/nativeaot/Runtime/CommonMacros.h index 54cb099bb2f8..f4e1f736a2c0 100644 --- a/src/coreclr/src/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/src/nativeaot/Runtime/CommonMacros.h @@ -7,10 +7,17 @@ #include "rhassert.h" #define EXTERN_C extern "C" + +#if defined(HOST_X86) && !defined(HOST_UNIX) #define FASTCALL __fastcall #define STDCALL __stdcall +#else +#define FASTCALL +#define STDCALL +#endif + #define REDHAWK_API -#define REDHAWK_CALLCONV __fastcall +#define REDHAWK_CALLCONV FASTCALL #ifdef _MSC_VER @@ -164,7 +171,7 @@ inline bool IS_ALIGNED(T* val, UIntNative alignment); // Define an unmanaged function called from managed code that needs to execute in co-operative GC mode. (There // should be very few of these, most such functions will be simply p/invoked). // -#define COOP_PINVOKE_HELPER(_rettype, _method, _args) EXTERN_C REDHAWK_API _rettype __fastcall _method _args +#define COOP_PINVOKE_HELPER(_rettype, _method, _args) EXTERN_C REDHAWK_API _rettype REDHAWK_CALLCONV _method _args #ifdef HOST_X86 // We have helpers that act like memcpy and memset from the CRT, so they need to be __cdecl. #define COOP_PINVOKE_CDECL_HELPER(_rettype, _method, _args) EXTERN_C REDHAWK_API _rettype __cdecl _method _args diff --git a/src/coreclr/src/nativeaot/Runtime/EHHelpers.cpp b/src/coreclr/src/nativeaot/Runtime/EHHelpers.cpp index 3df7fcecb196..8623ca5cd10a 100644 --- a/src/coreclr/src/nativeaot/Runtime/EHHelpers.cpp +++ b/src/coreclr/src/nativeaot/Runtime/EHHelpers.cpp @@ -250,7 +250,7 @@ EXTERN_C Int32 RhpPInvokeExceptionGuard() #endif #if defined(HOST_AMD64) || defined(HOST_ARM) || defined(HOST_X86) || defined(HOST_ARM64) || defined(HOST_WASM) -EXTERN_C REDHAWK_API void __fastcall RhpThrowHwEx(); +EXTERN_C REDHAWK_API void REDHAWK_CALLCONV RhpThrowHwEx(); #else COOP_PINVOKE_HELPER(void, RhpThrowHwEx, ()) { diff --git a/src/coreclr/src/nativeaot/Runtime/Full/CMakeLists.txt b/src/coreclr/src/nativeaot/Runtime/Full/CMakeLists.txt new file mode 100644 index 000000000000..d82b6905f1c8 --- /dev/null +++ b/src/coreclr/src/nativeaot/Runtime/Full/CMakeLists.txt @@ -0,0 +1,83 @@ +project(Runtime) + +# Full version of the runtime is required by the JIT CodeGen. +# The low-level helpers can be implemented in assembly code. + +# Include auto-generated files on include path +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_definitions(-DFEATURE_RX_THUNKS) + +add_library(Runtime STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM}) + +add_library(Runtime.ServerGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES}) + +target_compile_definitions(Runtime.ServerGC PRIVATE -DFEATURE_SVR_GC) + + +# Get the current list of definitions +get_compile_definitions(DEFINITIONS) + +set(ASM_OFFSETS_CSPP ${RUNTIME_DIR}/../../Runtime.Base/src/AsmOffsets.cspp) + +if(WIN32) + set(COMPILER_LANGUAGE "") + set(PREPROCESSOR_FLAGS -EP) + set(ASM_OFFSETS_CPP ${RUNTIME_DIR}/windows/AsmOffsets.cpp) +else() + set(COMPILER_LANGUAGE -x c++) + set(PREPROCESSOR_FLAGS -E -P) + set(ASM_OFFSETS_CPP ${RUNTIME_DIR}/unix/AsmOffsets.cpp) +endif() + +#add_custom_command( +# # The AsmOffsets.cs is consumed later by the managed build +# TARGET Runtime +# COMMAND ${CMAKE_CXX_COMPILER} ${COMPILER_LANGUAGE} ${DEFINITIONS} ${PREPROCESSOR_FLAGS} -I"${ARCH_SOURCES_DIR}" "${ASM_OFFSETS_CSPP}" >"${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.cs" +# DEPENDS "${RUNTIME_DIR}/AsmOffsets.cpp" "${RUNTIME_DIR}/AsmOffsets.h" +#) + +add_custom_command( + COMMAND ${CMAKE_CXX_COMPILER} ${DEFINITIONS} ${PREPROCESSOR_FLAGS} -I"${RUNTIME_DIR}" -I"${ARCH_SOURCES_DIR}" "${ASM_OFFSETS_CPP}" >"${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc" + DEPENDS "${ASM_OFFSETS_CPP}" "${RUNTIME_DIR}/AsmOffsets.h" + COMMENT "Generating AsmOffsets.inc" +) + +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc" PROPERTIES GENERATED TRUE) + +add_custom_target( + AsmOffsets + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc" +) + +# The AsmOffsets.inc will be built as a dependency of the Runtime +add_dependencies(Runtime AsmOffsets) + +# Extract the definitions for the ASM code. Since there is a bug in the cmake that prevents us from +# using the generator expressions, we split the definitions into lists based on the configuration. +foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST) + if (${DEFINITION} MATCHES "^\\$<\\$]+)>:([^>]+)>$") + # The entry contains generator expression, so insert the definition into a definitions list + # corresponding to the config + string(TOUPPER ${CMAKE_MATCH_1} CONFIG) + set(ASM_DEFINITIONS_${CONFIG} ${ASM_DEFINITIONS_${CONFIG}} ${CMAKE_MATCH_2}) + else() + list(APPEND ASM_DEFINITIONS ${DEFINITION}) + endif() +endforeach() + +# Add defines for the ASM. Unfortunately setting it on the target is ignored for asm by the cmake, so we have +# to set it on the sources. +set_property(SOURCE ${RUNTIME_SOURCES_ARCH_ASM} PROPERTY COMPILE_DEFINITIONS ${ASM_DEFINITIONS}) +foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES) + string(TOUPPER ${CONFIG} CONFIG) + set_property(SOURCE ${RUNTIME_SOURCES_ARCH_ASM} PROPERTY COMPILE_DEFINITIONS_${CONFIG} ${ASM_DEFINITIONS_${CONFIG}}) +endforeach() + +# Install the static Runtime library +install (TARGETS Runtime Runtime.ServerGC DESTINATION sdk) +if(WIN32) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Runtime.dir/$/Runtime.pdb DESTINATION sdk) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ServerGC.dir/$/Runtime.ServerGC.pdb DESTINATION sdk) +endif() diff --git a/src/coreclr/src/nativeaot/Runtime/ObjectLayout.cpp b/src/coreclr/src/nativeaot/Runtime/ObjectLayout.cpp index ce3328c52c9d..d99f790cd9c4 100644 --- a/src/coreclr/src/nativeaot/Runtime/ObjectLayout.cpp +++ b/src/coreclr/src/nativeaot/Runtime/ObjectLayout.cpp @@ -15,6 +15,7 @@ #include "TargetPtrs.h" #include "eetype.h" #include "ObjectLayout.h" +#include "eetype.inl" #ifndef DACCESS_COMPILE void Object::InitEEType(EEType * pEEType) diff --git a/src/coreclr/src/nativeaot/Runtime/OptionalFieldsRuntime.cpp b/src/coreclr/src/nativeaot/Runtime/OptionalFieldsRuntime.cpp index d8b10a35fea2..1bcdcc357ea4 100644 --- a/src/coreclr/src/nativeaot/Runtime/OptionalFieldsRuntime.cpp +++ b/src/coreclr/src/nativeaot/Runtime/OptionalFieldsRuntime.cpp @@ -15,6 +15,7 @@ #include "eetype.h" #include "ObjectLayout.h" #include "varint.h" +#include "eetype.inl" // Reads the field type from the current byte of the stream and indicates whether this represents the last // field. diff --git a/src/coreclr/src/nativeaot/Runtime/PalRedhawk.h b/src/coreclr/src/nativeaot/Runtime/PalRedhawk.h index 7789c05346bf..a1baa6a658b0 100644 --- a/src/coreclr/src/nativeaot/Runtime/PalRedhawk.h +++ b/src/coreclr/src/nativeaot/Runtime/PalRedhawk.h @@ -43,6 +43,10 @@ typedef void * HINSTANCE; typedef void * LPSECURITY_ATTRIBUTES; typedef void * LPOVERLAPPED; +#ifdef TARGET_UNIX +#define __stdcall +#endif + #ifndef __GCENV_BASE_INCLUDED__ #define CALLBACK __stdcall #define WINAPI __stdcall diff --git a/src/coreclr/src/nativeaot/Runtime/PalRedhawkCommon.h b/src/coreclr/src/nativeaot/Runtime/PalRedhawkCommon.h index d1933865af2a..727f50222e91 100644 --- a/src/coreclr/src/nativeaot/Runtime/PalRedhawkCommon.h +++ b/src/coreclr/src/nativeaot/Runtime/PalRedhawkCommon.h @@ -162,7 +162,7 @@ struct PAL_LIMITED_CONTEXT void RuntimeThreadShutdown(void* thread); #ifdef TARGET_UNIX -typedef void (__fastcall * ThreadExitCallback)(); +typedef void (*ThreadExitCallback)(); extern ThreadExitCallback g_threadExitCallback; diff --git a/src/coreclr/src/nativeaot/Runtime/Portable/CMakeLists.txt b/src/coreclr/src/nativeaot/Runtime/Portable/CMakeLists.txt new file mode 100644 index 000000000000..582e83166cd1 --- /dev/null +++ b/src/coreclr/src/nativeaot/Runtime/Portable/CMakeLists.txt @@ -0,0 +1,36 @@ +project(PortableRuntime) + +# Portable version of the runtime is designed to be used with CppCodeGen or WASM. +# It should be written in pure C/C++, with no assembly code. + +add_definitions(-DUSE_PORTABLE_HELPERS) + +add_library(PortableRuntime STATIC ${COMMON_RUNTIME_SOURCES} ${PORTABLE_RUNTIME_SOURCES}) + +# Get the current list of definitions +get_compile_definitions(DEFINITIONS) +set(ASM_OFFSETS_CSPP ${RUNTIME_DIR}/../../Runtime.Base/src/AsmOffsets.cspp) + +if(WIN32) + set(COMPILER_LANGUAGE "") + set(PREPROCESSOR_FLAGS -EP) + set(ASM_OFFSETS_CPP ${RUNTIME_DIR}/windows/AsmOffsets.cpp) +else() + set(COMPILER_LANGUAGE -x c++) + set(PREPROCESSOR_FLAGS -E -P) + set(ASM_OFFSETS_CPP ${RUNTIME_DIR}/unix/AsmOffsets.cpp) +endif() + +#add_custom_command( +# # The AsmOffsetsPortable.cs is consumed later by the managed build +# TARGET PortableRuntime +# COMMAND ${CMAKE_CXX_COMPILER} ${COMPILER_LANGUAGE} ${DEFINITIONS} ${PREPROCESSOR_FLAGS} -I"${ARCH_SOURCES_DIR}" "${ASM_OFFSETS_CSPP}" >"${CMAKE_CURRENT_BINARY_DIR}/AsmOffsetsPortable.cs" +# DEPENDS "${RUNTIME_DIR}/AsmOffsets.cpp" "${RUNTIME_DIR}/AsmOffsets.h" +#) + +# Install the static Runtime library +install (TARGETS PortableRuntime DESTINATION sdk) + +if(WIN32) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/PortableRuntime.dir/$/PortableRuntime.pdb DESTINATION sdk) +endif() diff --git a/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.cpp b/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.cpp index b7a8ce134b67..3341ba2c367a 100644 --- a/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.cpp +++ b/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.cpp @@ -31,6 +31,7 @@ #include "threadstore.h" #include "threadstore.inl" #include "RestrictedCallouts.h" +#include "eetype.inl" // The head of the chains of GC callouts, one per callout type. RestrictedCallouts::GcRestrictedCallout * RestrictedCallouts::s_rgGcRestrictedCallouts[GCRC_Count] = { 0 }; diff --git a/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.h b/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.h index 384e2fcd9c8a..933244a10f9a 100644 --- a/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.h +++ b/src/coreclr/src/nativeaot/Runtime/RestrictedCallouts.h @@ -97,6 +97,6 @@ class RestrictedCallouts static CrstStatic s_sLock; // Prototypes for the callouts. - typedef void (__fastcall * GcRestrictedCallbackFunction)(UInt32 uiCondemnedGeneration); - typedef Boolean (__fastcall * HandleTableRestrictedCallbackFunction)(Object * pObject); + typedef void (REDHAWK_CALLCONV * GcRestrictedCallbackFunction)(UInt32 uiCondemnedGeneration); + typedef Boolean (REDHAWK_CALLCONV * HandleTableRestrictedCallbackFunction)(Object * pObject); }; diff --git a/src/coreclr/src/nativeaot/Runtime/eetype.cpp b/src/coreclr/src/nativeaot/Runtime/eetype.cpp index d18de90b889f..55484fa4bffb 100644 --- a/src/coreclr/src/nativeaot/Runtime/eetype.cpp +++ b/src/coreclr/src/nativeaot/Runtime/eetype.cpp @@ -11,6 +11,7 @@ #include "PalRedhawk.h" #include "CommonMacros.inl" +#include "eetype.inl" #pragma warning(disable:4127) // C4127: conditional expression is constant diff --git a/src/coreclr/src/nativeaot/Runtime/gcinfodecoder.cpp b/src/coreclr/src/nativeaot/Runtime/gcinfodecoder.cpp new file mode 100644 index 000000000000..0d50d12abe96 --- /dev/null +++ b/src/coreclr/src/nativeaot/Runtime/gcinfodecoder.cpp @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#define _common_h_ + +#include "../../vm/gcinfodecoder.cpp" diff --git a/src/coreclr/src/nativeaot/Runtime/gcinfodecoder.h b/src/coreclr/src/nativeaot/Runtime/gcinfodecoder.h new file mode 100644 index 000000000000..4e1de4ce1949 --- /dev/null +++ b/src/coreclr/src/nativeaot/Runtime/gcinfodecoder.h @@ -0,0 +1,4 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "../../inc/gcinfodecoder.h" diff --git a/src/coreclr/src/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp b/src/coreclr/src/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp index e03a85e32058..1d8b134fc730 100644 --- a/src/coreclr/src/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp +++ b/src/coreclr/src/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp @@ -15,7 +15,7 @@ #include "CommonMacros.inl" #define GCINFODECODER_NO_EE -#include "coreclr/gcinfodecoder.cpp" +#include "gcinfodecoder.cpp" #include "UnixContext.h" @@ -444,9 +444,9 @@ PTR_VOID UnixNativeCodeManager::GetAssociatedData(PTR_VOID ControlPC) return dac_cast(p + *dac_cast(p)); } -extern "C" bool __stdcall RegisterCodeManager(ICodeManager * pCodeManager, PTR_VOID pvStartRange, UInt32 cbRange); -extern "C" void __stdcall UnregisterCodeManager(ICodeManager * pCodeManager); -extern "C" bool __stdcall RegisterUnboxingStubs(PTR_VOID pvStartRange, UInt32 cbRange); +extern "C" bool RegisterCodeManager(ICodeManager * pCodeManager, PTR_VOID pvStartRange, UInt32 cbRange); +extern "C" void UnregisterCodeManager(ICodeManager * pCodeManager); +extern "C" bool RegisterUnboxingStubs(PTR_VOID pvStartRange, UInt32 cbRange); extern "C" bool RhRegisterOSModule(void * pModule, diff --git a/src/coreclr/src/nativeaot/Runtime/unix/sal.h b/src/coreclr/src/nativeaot/Runtime/unix/sal.h index e65137891282..f361511dc955 100644 --- a/src/coreclr/src/nativeaot/Runtime/unix/sal.h +++ b/src/coreclr/src/nativeaot/Runtime/unix/sal.h @@ -2407,11 +2407,9 @@ extern "C" { in the negated form __notnull or the possibly null form __maybenull. */ -#ifndef PAL_STDCPP_COMPAT #define __null _Null_impl_ #define __notnull _Notnull_impl_ #define __maybenull _Maybenull_impl_ -#endif // !PAL_STDCPP_COMPAT /* __readonly l @@ -2600,10 +2598,11 @@ extern "C" { #else // ][ -#ifndef PAL_STDCPP_COMPAT +#if 0 // Collides with clang intrinsics #define __null #define __notnull -#endif // !PAL_STDCPP_COMPAT + #define __deref +#endif #define __maybenull #define __readonly #define __notreadonly @@ -2617,7 +2616,6 @@ extern "C" { #define __writableTo(size) #define __elem_writableTo(size) #define __byte_writableTo(size) - #define __deref #define __pre #define __post #define __precond(expr) diff --git a/src/coreclr/src/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp b/src/coreclr/src/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp index c42dff7b72c4..c9cd387a8550 100644 --- a/src/coreclr/src/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp +++ b/src/coreclr/src/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp @@ -17,7 +17,7 @@ #include "CommonMacros.inl" #define GCINFODECODER_NO_EE -#include "coreclr/gcinfodecoder.cpp" +#include "gcinfodecoder.cpp" #define UBF_FUNC_KIND_MASK 0x03 #define UBF_FUNC_KIND_ROOT 0x00 diff --git a/src/coreclr/src/nativeaot/libunwind/src/libunwind.cpp b/src/coreclr/src/nativeaot/libunwind/src/libunwind.cpp index bc68033cd415..e030fe9d5c32 100644 --- a/src/coreclr/src/nativeaot/libunwind/src/libunwind.cpp +++ b/src/coreclr/src/nativeaot/libunwind/src/libunwind.cpp @@ -93,7 +93,7 @@ _LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum, unw_word_t value, unw_word_t *pos) { _LIBUNWIND_TRACE_API("__unw_set_reg(cursor=%p, regNum=%d, value=0x%" PRIxPTR ")", - static_cast(cursor), regNum, (long long)value); + static_cast(cursor), regNum, (unsigned long)value); typedef LocalAddressSpace::pint_t pint_t; AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; if (co->validReg(regNum)) { diff --git a/src/coreclr/src/vm/gcinfodecoder.cpp b/src/coreclr/src/vm/gcinfodecoder.cpp index ac28d049891e..2c515fb4f74b 100644 --- a/src/coreclr/src/vm/gcinfodecoder.cpp +++ b/src/coreclr/src/vm/gcinfodecoder.cpp @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - #include "common.h" #include "gcinfodecoder.h" @@ -158,7 +157,7 @@ GcInfoDecoder::GcInfoDecoder( if (hasGSCookie) { // Note that normalization as a code offset can be different than - // normalization as code legnth + // normalization as code length UINT32 normCodeLength = NORMALIZE_CODE_OFFSET(m_CodeLength); // Decode prolog/epilog information @@ -275,7 +274,7 @@ GcInfoDecoder::GcInfoDecoder( if (hasReversePInvokeFrame) { - m_ReversePInvokeFrameStackSlot = (INT32)m_Reader.DecodeVarLengthSigned(REVERSE_PINVOKE_FRAME_ENCBASE); + m_ReversePInvokeFrameStackSlot = (INT32)DENORMALIZE_STACK_SLOT(m_Reader.DecodeVarLengthSigned(REVERSE_PINVOKE_FRAME_ENCBASE)); } else { @@ -322,7 +321,7 @@ GcInfoDecoder::GcInfoDecoder( else if(flags & DECODE_FOR_RANGES_CALLBACK) { // Note that normalization as a code offset can be different than - // normalization as code legnth + // normalization as code length UINT32 normCodeLength = NORMALIZE_CODE_OFFSET(m_CodeLength); UINT32 numBitsPerOffset = CeilOfLog2(normCodeLength); @@ -445,7 +444,7 @@ void GcInfoDecoder::EnumerateInterruptibleRanges ( EnumerateInterruptibleRangesCallback *pCallback, void * hCallback) { - // If no info is found for the call site, we default to fully-interruptbile + // If no info is found for the call site, we default to fully-interruptible LOG((LF_GCROOTS, LL_INFO1000000, "No GC info found for call site at offset %x. Defaulting to fully-interruptible information.\n", (int) m_InstructionOffset)); UINT32 lastInterruptibleRangeStopOffsetNormalized = 0; @@ -804,7 +803,7 @@ bool GcInfoDecoder::EnumerateLiveSlots( _ASSERTE(m_NumInterruptibleRanges); _ASSERTE(numInterruptibleLength); - // If no info is found for the call site, we default to fully-interruptbile + // If no info is found for the call site, we default to fully-interruptible LOG((LF_GCROOTS, LL_INFO1000000, "No GC info found for call site at offset %x. Defaulting to fully-interruptible information.\n", (int) m_InstructionOffset)); UINT32 numChunks = (numInterruptibleLength + NUM_NORM_CODE_OFFSETS_PER_CHUNK - 1) / NUM_NORM_CODE_OFFSETS_PER_CHUNK; @@ -1365,7 +1364,7 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot( return (OBJECTREF*)*(ppRax + regNum); } -#ifdef TARGET_UNIX +#if defined(TARGET_UNIX) && !defined(FEATURE_REDHAWK) OBJECTREF* GcInfoDecoder::GetCapturedRegister( int regNum, PREGDISPLAY pRD @@ -1381,7 +1380,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister( return (OBJECTREF*)(pRax + regNum); } -#endif // TARGET_UNIX +#endif // TARGET_UNIX && !FEATURE_REDHAWK bool GcInfoDecoder::IsScratchRegister(int regNum, PREGDISPLAY pRD) { @@ -1435,7 +1434,7 @@ void GcInfoDecoder::ReportRegisterToGC( // AMD64 LOG((LF_GCROOTS, LL_INFO1000, "Reporting " FMT_REG, regNum )); OBJECTREF* pObjRef = GetRegisterSlot( regNum, pRD ); -#if defined(TARGET_UNIX) && !defined(SOS_TARGET_AMD64) +#if defined(TARGET_UNIX) && !defined(FEATURE_REDHAWK) && !defined(SOS_TARGET_AMD64) // On PAL, we don't always have the context pointers available due to // a limitation of an unwinding library. In such case, the context // pointers for some nonvolatile registers are NULL. @@ -1455,7 +1454,7 @@ void GcInfoDecoder::ReportRegisterToGC( // AMD64 gcFlags |= GC_CALL_PINNED; } -#endif // TARGET_UNIX && !SOS_TARGET_AMD64 +#endif // TARGET_UNIX && !FEATURE_REDHAWK && !SOS_TARGET_AMD64 #ifdef _DEBUG if(IsScratchRegister(regNum, pRD)) @@ -1810,7 +1809,7 @@ void GcInfoDecoder::ReportStackSlotToGC( GCINFODECODER_CONTRACT; OBJECTREF* pObjRef = GetStackSlot(spOffset, spBase, pRD); - _ASSERTE( IS_ALIGNED( pObjRef, sizeof( Object* ) ) ); + _ASSERTE(IS_ALIGNED(pObjRef, sizeof(OBJECTREF*))); #ifdef _DEBUG LOG((LF_GCROOTS, LL_INFO1000, /* Part One */