From 7ef548e08ae36dd9b8e67e68903168fc0d80bc3b Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 23 Jul 2020 03:13:44 -0700 Subject: [PATCH] Strip CPPCODEGEN (#21) --- .../src/nativeaot/Bootstrap/CppCodeGen.h | 71 ----- .../src/nativeaot/Bootstrap/common.cpp | 11 - src/coreclr/src/nativeaot/Bootstrap/common.h | 106 ------- src/coreclr/src/nativeaot/Bootstrap/main.cpp | 273 +----------------- 4 files changed, 4 insertions(+), 457 deletions(-) delete mode 100644 src/coreclr/src/nativeaot/Bootstrap/CppCodeGen.h delete mode 100644 src/coreclr/src/nativeaot/Bootstrap/common.cpp delete mode 100644 src/coreclr/src/nativeaot/Bootstrap/common.h diff --git a/src/coreclr/src/nativeaot/Bootstrap/CppCodeGen.h b/src/coreclr/src/nativeaot/Bootstrap/CppCodeGen.h deleted file mode 100644 index 91709981afd8ef..00000000000000 --- a/src/coreclr/src/nativeaot/Bootstrap/CppCodeGen.h +++ /dev/null @@ -1,71 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// CppCodeGen.h : Facilities for the C++ code generation backend - -#ifndef __CPP_CODE_GEN_H -#define __CPP_CODE_GEN_H - -#define _CRT_SECURE_NO_WARNINGS - -#ifdef _MSC_VER -// Warnings disabled for generated cpp code -#pragma warning(disable:4200) // zero-sized array -#pragma warning(disable:4101) // unreferenced local variable -#pragma warning(disable:4102) // unreferenced label -#pragma warning(disable:4244) // possible loss of data -#pragma warning(disable:4717) // recursive on all control paths -#pragma warning(disable:4307) // integral constant overflow -#endif - -#ifdef _MSC_VER -#define INT64VAL(x) (x##i64) -#else -#define INT64VAL(x) (x##LL) -#endif - -#ifdef _MSC_VER -#define CORERT_UNREACHABLE __assume(0) -#else -#define CORERT_UNREACHABLE __builtin_unreachable() -#endif - -#ifdef _MSC_VER -#define CORERT_THREAD __declspec(thread) -#else -#define CORERT_THREAD __thread -#endif - -// Use the bit representation of uint64_t `v` as the bit representation of a double. -inline double __uint64_to_double(uint64_t v) -{ - union - { - uint64_t u64; - double d; - } val; - val.u64 = v; - return val.d; -} - -struct ReversePInvokeFrame -{ - void* m_savedPInvokeTransitionFrame; - void* m_savedThread; -}; - -struct PInvokeTransitionFrame -{ - void* m_RIP; - void* m_pThread; // unused by stack crawler, this is so GetThread is only called once per method - // can be an invalid pointer in universal transition cases (which never need to call GetThread) - uint32_t m_Flags; // PInvokeTransitionFrameFlags -}; - -// Should be synchronized with System.Private.CoreLib/src/System/Runtime/CompilerServices/StaticClassConstructionContext.cs -struct StaticClassConstructionContext -{ - void* m_cctorMethodAddress; - uint32_t m_initialized; -}; -#endif diff --git a/src/coreclr/src/nativeaot/Bootstrap/common.cpp b/src/coreclr/src/nativeaot/Bootstrap/common.cpp deleted file mode 100644 index 9efc4b2ad89b68..00000000000000 --- a/src/coreclr/src/nativeaot/Bootstrap/common.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// common.cpp : source file that includes just the standard includes -// testNative.pch will be the pre-compiled header -// common.obj will contain the pre-compiled type information - -#include "common.h" - -// TODO: reference any additional headers you need in common.H -// and not in this file diff --git a/src/coreclr/src/nativeaot/Bootstrap/common.h b/src/coreclr/src/nativeaot/Bootstrap/common.h deleted file mode 100644 index 697bfb544d404d..00000000000000 --- a/src/coreclr/src/nativeaot/Bootstrap/common.h +++ /dev/null @@ -1,106 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// common.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#ifndef __COMMON_H -#define __COMMON_H - -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifndef _WIN32 -#include -#endif - -using namespace std; - -class MethodTable; -class Object; - -#ifdef _MSC_VER -#define __NORETURN __declspec(noreturn) -#else -#define __NORETURN __attribute((noreturn)) -#endif - -int __initialize_runtime(); -void __shutdown_runtime(); - -extern "C" Object * __allocate_object(MethodTable * pMT); -extern "C" Object * __allocate_array(size_t elements, MethodTable * pMT); -extern "C" Object * __castclass(MethodTable * pMT, void * obj); -extern "C" Object * __isinst(MethodTable * pMT, void * obj); -extern "C" __NORETURN void __throw_exception(void * pEx); -extern "C" void __debug_break(); - -Object * __load_string_literal(const char * string); - -extern "C" void __range_check_fail(); - -inline void __range_check(void * a, size_t elem) -{ - if (elem >= *((size_t*)a + 1)) - __range_check_fail(); -} - -Object * __get_commandline_args(int argc, char * argv[]); - -// POD version of EEType to use for static initialization -struct RawEEType -{ - uint16_t m_componentSize; - uint16_t m_flags; - uint32_t m_baseSize; - MethodTable * m_pBaseType; - uint16_t m_usNumVtableSlots; - uint16_t m_usNumInterfaces; - uint32_t m_uHashCode; -}; - -struct ReversePInvokeFrame; - -void __reverse_pinvoke(ReversePInvokeFrame* pRevFrame); -void __reverse_pinvoke_return(ReversePInvokeFrame* pRevFrame); - -struct PInvokeTransitionFrame; - -void __pinvoke(PInvokeTransitionFrame* pFrame); -void __pinvoke_return(PInvokeTransitionFrame* pFrame); - -typedef size_t UIntNative; - -inline bool IS_ALIGNED(UIntNative val, UIntNative alignment) -{ - //ASSERT(0 == (alignment & (alignment - 1))); - return 0 == (val & (alignment - 1)); -} - -template -inline bool IS_ALIGNED(T* val, UIntNative alignment) -{ - //ASSERT(0 == (alignment & (alignment - 1))); - return IS_ALIGNED(reinterpret_cast(val), alignment); -} - -#define RAW_MIN_OBJECT_SIZE (3*sizeof(void*)) - -#define AlignBaseSize(s) ((s < RAW_MIN_OBJECT_SIZE) ? RAW_MIN_OBJECT_SIZE : ((s + (sizeof(void*)-1) & ~(sizeof(void*)-1)))) - -#define ARRAY_BASE (2*sizeof(void*)) - -#endif // __COMMON_H diff --git a/src/coreclr/src/nativeaot/Bootstrap/main.cpp b/src/coreclr/src/nativeaot/Bootstrap/main.cpp index 00dac83b5775a5..169ee746c085b3 100644 --- a/src/coreclr/src/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/src/nativeaot/Bootstrap/main.cpp @@ -1,16 +1,9 @@ // 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 "sal.h" -#include "gcenv.structs.h" -#include "gcenv.base.h" - +#include #include -#ifndef CPPCODEGEN - // // This is the mechanism whereby multiple linked modules contribute their global data for initialization at // startup of the application. @@ -101,244 +94,11 @@ static char& __unbox_z = __stop___unbox; #endif // _MSC_VER -#endif // !CPPCODEGEN - -// Do not warn that extern C methods throw exceptions. This is temporary -// as long as we have unimplemented/throwing APIs in this file. -#pragma warning(disable:4297) - -#ifdef CPPCODEGEN - -extern "C" Object * RhNewObject(MethodTable * pMT); -extern "C" Object * RhNewArray(MethodTable * pMT, int32_t elements); -extern "C" void * RhTypeCast_IsInstanceOf(MethodTable * pMT, void* pObject); -extern "C" void * RhTypeCast_CheckCast(MethodTable * pMT, void* pObject); -extern "C" void RhpStelemRef(void * pArray, int index, void * pObj); -extern "C" void * RhpLdelemaRef(void * pArray, int index, MethodTable * pMT); -extern "C" __NORETURN void RhpThrowEx(void * pEx); -extern "C" void RhDebugBreak(); - -extern "C" Object * __allocate_object(MethodTable * pMT) -{ - return RhNewObject(pMT); -} - -extern "C" Object * __allocate_array(size_t elements, MethodTable * pMT) -{ - return RhNewArray(pMT, (int32_t)elements); // TODO: type mismatch -} - -extern "C" Object * __castclass(MethodTable * pTargetMT, void* obj) -{ - return (Object *)RhTypeCast_CheckCast(pTargetMT, obj); -} - -extern "C" Object * __isinst(MethodTable * pTargetMT, void* obj) -{ - return (Object *)RhTypeCast_IsInstanceOf(pTargetMT, obj); -} - -extern "C" void __stelem_ref(void * pArray, unsigned idx, void * obj) -{ - RhpStelemRef(pArray, idx, obj); -} - -extern "C" void* __ldelema_ref(void * pArray, unsigned idx, MethodTable * type) -{ - return RhpLdelemaRef(pArray, idx, type); -} - -extern "C" void __throw_exception(void * pEx) -{ - RhpThrowEx(pEx); -} - -extern "C" void __debug_break() -{ - RhDebugBreak(); -} - -void __range_check_fail() -{ - throw "ThrowRangeOverflowException"; -} - -extern "C" void RhpReversePInvoke2(ReversePInvokeFrame* pRevFrame); -extern "C" void RhpReversePInvokeReturn2(ReversePInvokeFrame* pRevFrame); - -void __reverse_pinvoke(ReversePInvokeFrame* pRevFrame) -{ - RhpReversePInvoke2(pRevFrame); -} - -void __reverse_pinvoke_return(ReversePInvokeFrame* pRevFrame) -{ - RhpReversePInvokeReturn2(pRevFrame); -} - -extern "C" void RhpPInvoke2(PInvokeTransitionFrame* pFrame); -extern "C" void RhpPInvokeReturn2(PInvokeTransitionFrame* pFrame); - -void __pinvoke(PInvokeTransitionFrame* pFrame) -{ - RhpPInvoke2(pFrame); -} - -void __pinvoke_return(PInvokeTransitionFrame* pFrame) -{ - RhpPInvokeReturn2(pFrame); -} - -namespace System_Private_CoreLib { namespace System { - - class Object { - public: - MethodTable * get_EEType() { return *(MethodTable **)this; } - }; - - class Array : public Object { - public: - int32_t GetArrayLength() { - return *(int32_t *)((void **)this + 1); - } - void * GetArrayData() { - return (void **)this + 2; - } - }; - - class String : public Object { public: - static MethodTable * __getMethodTable(); - }; - - class String__Array : public Object { public: - static MethodTable * __getMethodTable(); - }; - - class EETypePtr { public: - intptr_t m_value; - }; - -}; }; - -Object * __load_string_literal(const char * string) -{ - // TODO: Cache/intern string literals - // TODO: Unicode string literals - - size_t len = strlen(string); - - Object * pString = RhNewArray(System_Private_CoreLib::System::String::__getMethodTable(), (int32_t)len); - - uint16_t * p = (uint16_t *)((char*)pString + sizeof(intptr_t) + sizeof(int32_t)); - for (size_t i = 0; i < len; i++) - p[i] = string[i]; - return pString; -} - -#if defined(HOST_WASM) -// Exception wrapper type that allows us to differentiate managed and native exceptions -class ManagedExceptionWrapper : exception -{ -public: - ManagedExceptionWrapper(void* pManagedException) - { - m_pManagedException = pManagedException; - } - -public: - void* m_pManagedException; -}; -#endif - -extern "C" void RhpThrowEx(void * pEx) -{ -#if defined(HOST_WASM) - throw ManagedExceptionWrapper(pEx); -#else - throw "RhpThrowEx"; -#endif -} - -extern "C" void RhpThrowHwEx() -{ - throw "RhpThrowHwEx"; -} - -#if defined(HOST_WASM) -// returns the Leave target -extern "C" uint32_t LlvmCatchFunclet(void* pHandlerIP, void* pvRegDisplay); -extern "C" uint32_t RhpCallCatchFunclet(void * exceptionObj, void* pHandlerIP, void* pvRegDisplay, void *exInfo) -{ - return LlvmCatchFunclet(pHandlerIP, pvRegDisplay); -} - -extern "C" uint32_t LlvmFilterFunclet(void* pHandlerIP, void* pvRegDisplay); -extern "C" uint32_t RhpCallFilterFunclet(void* exceptionObj, void * pHandlerIP, void* shadowStack) -{ - return LlvmFilterFunclet(pHandlerIP, shadowStack); -} -#else -extern "C" uint32_t RhpCallCatchFunclet(void *, void*, void*, void*) -{ - throw "RhpCallCatchFunclet"; -} -extern "C" void* RhpCallFilterFunclet(void*, void*, void*) -{ - throw "RhpCallFilterFunclet"; -} -#endif - -#if defined(HOST_WASM) -extern "C" void LlvmFinallyFunclet(void *finallyHandler, void *shadowStack); -extern "C" void RhpCallFinallyFunclet(void *finallyHandler, void *shadowStack) -{ - LlvmFinallyFunclet(finallyHandler, shadowStack); -} -#else -extern "C" void RhpCallFinallyFunclet(void *, void*) -{ - throw "RhpCallFinallyFunclet"; -} -#endif - -extern "C" void RhpUniversalTransition() -{ - throw "RhpUniversalTransition"; -} -extern "C" void RhpUniversalTransition_DebugStepTailCall() -{ - throw "RhpUniversalTransition_DebugStepTailCall"; -} -extern "C" void ConstrainedCallSupport_GetStubs(void*, void*) -{ - throw "ConstrainedCallSupport_GetStubs"; -} - -extern "C" void* RtRHeaderWrapper(); -#endif // CPPCODEGEN - -// This works around System.Private.Interop's references to Interop.Native. -// This won't be needed once we stop dragging in S.P.Interop for basic p/invoke support. -extern "C" void CCWAddRef() -{ - throw "CCWAddRef"; -} - -extern "C" void __fail_fast() -{ - // TODO: FailFast - printf("Call to an unimplemented runtime method; execution cannot continue.\n"); - printf("Method: __fail_fast\n"); - exit(-1); -} - extern "C" bool RhInitialize(); extern "C" void RhpEnableConservativeStackReporting(); extern "C" void RhpShutdown(); extern "C" void RhSetRuntimeInitializationCallback(int (*fPtr)()); -#ifndef CPPCODEGEN - extern "C" bool RhRegisterOSModule(void * pModule, void * pvManagedCodeStartRange, uint32_t cbManagedCodeRange, void * pvUnboxingStubsStartRange, uint32_t cbUnboxingStubsRange, @@ -346,8 +106,6 @@ extern "C" bool RhRegisterOSModule(void * pModule, extern "C" void* PalGetModuleHandleFromPointer(void* pointer); -#endif // !CPPCODEGEN - extern "C" void GetRuntimeException(); extern "C" void FailFast(); extern "C" void AppendExceptionStackFrame(); @@ -387,11 +145,8 @@ static int InitializeRuntime() if (!RhInitialize()) return -1; -#if defined(CPPCODEGEN) || defined(HOST_WASM) - RhpEnableConservativeStackReporting(); -#endif // CPPCODEGEN + // RhpEnableConservativeStackReporting(); -#ifndef CPPCODEGEN void * osModule = PalGetModuleHandleFromPointer((void*)&CORERT_ENTRYPOINT); // TODO: pass struct with parameters instead of the large signature of RhRegisterOSModule @@ -403,15 +158,8 @@ static int InitializeRuntime() { return -1; } -#endif // !CPPCODEGEN -#ifndef CPPCODEGEN InitializeModules(osModule, __modules_a, (int)((__modules_z - __modules_a)), (void **)&c_classlibFunctions, _countof(c_classlibFunctions)); -#elif defined HOST_WASM - InitializeModules(nullptr, (void**)RtRHeaderWrapper(), 1, (void **)&c_classlibFunctions, _countof(c_classlibFunctions)); -#else // !CPPCODEGEN - InitializeModules(nullptr, (void**)RtRHeaderWrapper(), 2, (void **)&c_classlibFunctions, _countof(c_classlibFunctions)); -#endif // !CPPCODEGEN #ifdef CORERT_DLL // Run startup method immediately for a native library @@ -432,21 +180,8 @@ int main(int argc, char* argv[]) if (initval != 0) return initval; - int retval; -#ifdef CPPCODEGEN - try -#endif - { - retval = __managed__Main(argc, argv); - } -#ifdef CPPCODEGEN - catch (const char* &e) - { - printf("Call to an unimplemented runtime method; execution cannot continue.\n"); - printf("Method: %s\n", e); - retval = -1; - } -#endif + int retval = __managed__Main(argc, argv); + RhpShutdown(); return retval;