From b46da5ddb44c49a6986a9a440ffac0b385dc3519 Mon Sep 17 00:00:00 2001 From: Sinan Kaya <41809318+franksinankaya@users.noreply.github.com> Date: Wed, 20 Feb 2019 11:59:22 -0500 Subject: [PATCH] Abstract deprecated and selectany for GCC and remove LLVM'ism where possible (dotnet/coreclr#22662) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Abstract selectany * Fix initializer element is not constant src/corefx/System.Globalization.Native/pal_icushim.c:58:34: error: initializer element is not constant static const int MaxICUVersion = MinICUVersion + 20; * Enable ms extensions * Apply LLVM patterns to GCC * Remove deprecated function * Fix const conversion error src/corefx/System.Globalization.Native/pal_calendarData.c:390:16: warning: passing argument 1 of ‘ures_close_ptr’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] ures_close(erasResBundle); src/corefx/System.Globalization.Native/pal_calendarData.c:419:22: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] char* name = GetCalendarName(calendarId); * Remove old compiler option Commit migrated from https://github.com/dotnet/coreclr/commit/1a1bb292ab53c0c30d35dc396c7089c1da5b3c82 --- src/coreclr/configurecompiler.cmake | 1 + .../System.Globalization.Native/CMakeLists.txt | 1 - .../System.Globalization.Native/pal_calendarData.c | 12 +++++----- .../System.Globalization.Native/pal_icushim.c | 12 +++++----- src/coreclr/src/inc/cor.h | 4 ++++ src/coreclr/src/inc/corinfo.h | 4 ++++ src/coreclr/src/inc/holder.h | 4 ++-- src/coreclr/src/inc/palclr.h | 4 ++++ src/coreclr/src/pal/inc/pal.h | 8 +++---- src/coreclr/src/scripts/genEtwProvider.py | 4 ++-- src/coreclr/src/vm/appdomain.cpp | 26 ---------------------- src/coreclr/src/vm/appdomain.hpp | 3 +-- 12 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/coreclr/configurecompiler.cmake b/src/coreclr/configurecompiler.cmake index dd0ee96..f5eb063 100644 --- a/src/coreclr/configurecompiler.cmake +++ b/src/coreclr/configurecompiler.cmake @@ -477,6 +477,7 @@ if (CLR_CMAKE_PLATFORM_UNIX) else() add_compile_options(-Wno-unused-variable) add_compile_options(-Wno-unused-but-set-variable) + add_compile_options(-fms-extensions) endif() # Some architectures (e.g., ARM) assume char type is unsigned while CoreCLR assumes char is signed diff --git a/src/coreclr/src/corefx/System.Globalization.Native/CMakeLists.txt b/src/coreclr/src/corefx/System.Globalization.Native/CMakeLists.txt index 5e38c6b..3d2518d 100644 --- a/src/coreclr/src/corefx/System.Globalization.Native/CMakeLists.txt +++ b/src/coreclr/src/corefx/System.Globalization.Native/CMakeLists.txt @@ -38,7 +38,6 @@ endif() include(configure.cmake) add_compile_options(-fPIC) -add_compile_options(-Wno-incompatible-pointer-types-discards-qualifiers) set(NATIVEGLOBALIZATION_SOURCES pal_calendarData.c diff --git a/src/coreclr/src/corefx/System.Globalization.Native/pal_calendarData.c b/src/coreclr/src/corefx/System.Globalization.Native/pal_calendarData.c index be0cc9b..07f8a6f 100644 --- a/src/coreclr/src/corefx/System.Globalization.Native/pal_calendarData.c +++ b/src/coreclr/src/corefx/System.Globalization.Native/pal_calendarData.c @@ -377,11 +377,11 @@ static void EnumUResourceBundle(const UResourceBundle* bundle, } } -static void CloseResBundle(const UResourceBundle* rootResBundle, - const UResourceBundle* calResBundle, - const UResourceBundle* targetCalResBundle, - const UResourceBundle* erasColResBundle, - const UResourceBundle* erasResBundle) +static void CloseResBundle(UResourceBundle* rootResBundle, + UResourceBundle* calResBundle, + UResourceBundle* targetCalResBundle, + UResourceBundle* erasColResBundle, + UResourceBundle* erasResBundle) { ures_close(rootResBundle); ures_close(calResBundle); @@ -416,7 +416,7 @@ static int32_t EnumAbbrevEraNames(const char* locale, while (TRUE) { UErrorCode status = U_ZERO_ERROR; - char* name = GetCalendarName(calendarId); + const char* name = GetCalendarName(calendarId); UResourceBundle* rootResBundle = ures_open(NULL, localeNamePtr, &status); UResourceBundle* calResBundle = ures_getByKey(rootResBundle, "calendar", NULL, &status); diff --git a/src/coreclr/src/corefx/System.Globalization.Native/pal_icushim.c b/src/coreclr/src/corefx/System.Globalization.Native/pal_icushim.c index ce42af6..04f7375 100644 --- a/src/coreclr/src/corefx/System.Globalization.Native/pal_icushim.c +++ b/src/coreclr/src/corefx/System.Globalization.Native/pal_icushim.c @@ -54,12 +54,12 @@ static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbol // equal to the version we are built against and less or equal to that version // plus 20 to give us enough headspace. The ICU seems to version about twice // a year. -static const int MinICUVersion = U_ICU_VERSION_MAJOR_NUM; -static const int MaxICUVersion = MinICUVersion + 20; -static const int MinMinorICUVersion = 1; -static const int MaxMinorICUVersion = 5; -static const int MinSubICUVersion = 1; -static const int MaxSubICUVersion = 5; +#define MinICUVersion U_ICU_VERSION_MAJOR_NUM +#define MaxICUVersion (MinICUVersion + 20) +#define MinMinorICUVersion 1 +#define MaxMinorICUVersion 5 +#define MinSubICUVersion 1 +#define MaxSubICUVersion 5 // Get filename of an ICU library with the requested version in the name // There are three possible cases of the version components values: diff --git a/src/coreclr/src/inc/cor.h b/src/coreclr/src/inc/cor.h index 31484f6..85ef14d 100644 --- a/src/coreclr/src/inc/cor.h +++ b/src/coreclr/src/inc/cor.h @@ -2195,8 +2195,12 @@ inline ULONG CorSigUncompressData( // return number of bytes of that compre #if !defined(SELECTANY) +#if defined(__GNUC__) + #define SELECTANY extern __attribute__((weak)) +#else #define SELECTANY extern __declspec(selectany) #endif +#endif SELECTANY const mdToken g_tkCorEncodeToken[4] ={mdtTypeDef, mdtTypeRef, mdtTypeSpec, mdtBaseType}; diff --git a/src/coreclr/src/inc/corinfo.h b/src/coreclr/src/inc/corinfo.h index 412a6ce..ae6ee20 100644 --- a/src/coreclr/src/inc/corinfo.h +++ b/src/coreclr/src/inc/corinfo.h @@ -210,8 +210,12 @@ TODO: Talk about initializing strutures before use ////////////////////////////////////////////////////////////////////////////////////////////////////////// #if !defined(SELECTANY) +#if defined(__GNUC__) + #define SELECTANY extern __attribute__((weak)) +#else #define SELECTANY extern __declspec(selectany) #endif +#endif SELECTANY const GUID JITEEVersionIdentifier = { /* d609bed1-7831-49fc-bd49-b6f054dd4d46 */ 0xd609bed1, diff --git a/src/coreclr/src/inc/holder.h b/src/coreclr/src/inc/holder.h index c346c73..204f807 100644 --- a/src/coreclr/src/inc/holder.h +++ b/src/coreclr/src/inc/holder.h @@ -608,7 +608,7 @@ class BaseWrapper : public BaseHolder { return !!(this->m_value != TYPE(value)); } -#ifdef __llvm__ +#ifdef __GNUC__ // This handles the NULL value that is an int and clang // doesn't want to convert int to a pointer FORCEINLINE bool operator==(int value) const @@ -619,7 +619,7 @@ class BaseWrapper : public BaseHolder { return !!(this->m_value != TYPE((void*)(SIZE_T)value)); } -#endif // __llvm__ +#endif // __GNUC__ FORCEINLINE const TYPE &operator->() const { return this->m_value; diff --git a/src/coreclr/src/inc/palclr.h b/src/coreclr/src/inc/palclr.h index 77b547d..60b9730 100644 --- a/src/coreclr/src/inc/palclr.h +++ b/src/coreclr/src/inc/palclr.h @@ -496,8 +496,12 @@ #if defined(SOURCE_FORMATTING) #define SELECTANY extern #else +#if defined(__GNUC__) +#define SELECTANY extern __attribute__((weak)) +#else #define SELECTANY extern __declspec(selectany) #endif +#endif #if defined(SOURCE_FORMATTING) #define __annotation(x) #endif diff --git a/src/coreclr/src/pal/inc/pal.h b/src/coreclr/src/pal/inc/pal.h index 0422a88..cdb3760 100644 --- a/src/coreclr/src/pal/inc/pal.h +++ b/src/coreclr/src/pal/inc/pal.h @@ -160,7 +160,7 @@ typedef PVOID NATIVE_LIBRARY_HANDLE; #endif // CORECLR #endif // !_MSC_VER -#if defined(_MSC_VER) || defined(__llvm__) +#if defined(_MSC_VER) #define DECLSPEC_ALIGN(x) __declspec(align(x)) #else #define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x))) @@ -612,11 +612,11 @@ MessageBoxW( // From win32.h #ifndef _CRTIMP -#ifdef __llvm__ +#ifdef __GNUC__ #define _CRTIMP -#else // __llvm__ +#else // __GNUC__ #define _CRTIMP __declspec(dllimport) -#endif // __llvm__ +#endif // __GNUC__ #endif // _CRTIMP /******************* winbase.h Entrypoints and defines ************************/ diff --git a/src/coreclr/src/scripts/genEtwProvider.py b/src/coreclr/src/scripts/genEtwProvider.py index 9f012bf..79a286a 100644 --- a/src/coreclr/src/scripts/genEtwProvider.py +++ b/src/coreclr/src/scripts/genEtwProvider.py @@ -234,7 +234,7 @@ def genEtwMacroHeader(manifest, exclusion_filename, intermediate): header_file.write("#define NO_OF_ETW_PROVIDERS " + str(numOfProviders) + "\n") header_file.write("#define MAX_BYTES_PER_ETW_PROVIDER " + str(nMaxEventBytesPerProvider) + "\n") - header_file.write("EXTERN_C __declspec(selectany) const BYTE etwStackSupportedEvents[NO_OF_ETW_PROVIDERS][MAX_BYTES_PER_ETW_PROVIDER] = \n{\n") + header_file.write("EXTERN_C SELECTANY const BYTE etwStackSupportedEvents[NO_OF_ETW_PROVIDERS][MAX_BYTES_PER_ETW_PROVIDER] = \n{\n") for providerNode in tree.getElementsByTagName('provider'): stackSupportedEvents = [0]*nMaxEventBytesPerProvider @@ -318,4 +318,4 @@ def main(argv): if __name__ == '__main__': return_code = main(sys.argv[1:]) - sys.exit(return_code) \ No newline at end of file + sys.exit(return_code) diff --git a/src/coreclr/src/vm/appdomain.cpp b/src/coreclr/src/vm/appdomain.cpp index 42e26c9..6d68dff 100644 --- a/src/coreclr/src/vm/appdomain.cpp +++ b/src/coreclr/src/vm/appdomain.cpp @@ -3120,32 +3120,6 @@ Assembly* SystemDomain::GetCallersAssembly(StackCrawlMark *stackMark, return NULL; } -/*static*/ -Module* SystemDomain::GetCallersModule(int skip) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - GCX_COOP(); - - CallersData cdata; - ZeroMemory(&cdata, sizeof(CallersData)); - cdata.skip = skip; - - StackWalkFunctions(GetThread(), CallersMethodCallback, &cdata); - - if(cdata.pMethod) - return cdata.pMethod->GetModule(); - else - return NULL; -} - /*private static*/ StackWalkAction SystemDomain::CallersMethodCallbackWithStackMark(CrawlFrame* pCf, VOID* data) { diff --git a/src/coreclr/src/vm/appdomain.hpp b/src/coreclr/src/vm/appdomain.hpp index b10ed26..6c88127 100644 --- a/src/coreclr/src/vm/appdomain.hpp +++ b/src/coreclr/src/vm/appdomain.hpp @@ -3441,8 +3441,7 @@ public: //**************************************************************************************** // Methods used to get the callers module and hence assembly and app domain. - __declspec(deprecated("This method is deprecated, use the version that takes a StackCrawlMark instead")) - static Module* GetCallersModule(int skip); + static MethodDesc* GetCallersMethod(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL); static MethodTable* GetCallersType(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL); static Module* GetCallersModule(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL); -- 2.7.4