Static linking of native libs (#44505)
authorVladimir Sadov <vsadov@microsoft.com>
Mon, 7 Dec 2020 04:08:41 +0000 (20:08 -0800)
committerGitHub <noreply@github.com>
Mon, 7 Dec 2020 04:08:41 +0000 (20:08 -0800)
* from prototype

* fix OSX

* fix for Android

* treat "libSystem.Globalization.Native" as QCall in mono too (for now).

* fix for wasm

* fix pedantic errors on GCC

* delete gPalGlobalizationNative

* pass overrider from the host

* default override

* default PInvoke override runs after optional host-provided overrider.

* Some PR feedback   (mostly related to code, not the CMake stuff).

* more coding PR feedback

* Deleted "libraries-native" folder.

* unifying tryrun.cmake into 1 common file

* factor out adding lib-specific dependencies into one place (per native library)

* cleanup: entirely remove tryrun.cmake propagation in eng, gen-buildsys, build-commons, and build scripts

* remove "clrcompression.dll" and "libSystem.IO.Compression.Native.dylib" from single-file host packaging

* mono: refactor Globalization lookup into `default_resolve_dllimport`.

* set FEATURE_DISTRO_AGNOSTIC_SSL according to __PortableBuild

* CORECLR_CALLING_CONVENTION for the host callback types

* refactor common parts of entrypoints.c into entrypoints.h

* rename OverrideEntry -->  DllImportEntry

* extra libs as CMake functions

* use macros instead of functions in extra_libs.cmake

* mono formatting style in src/mono/mono/metadata/native-library.c

Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
* mono: Remaining stylistic nits.

Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
* do not set DFEATURE_DISTRO_AGNOSTIC_SSL on iOS, Android, tvOS

Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
53 files changed:
eng/native/build-commons.sh
eng/native/configurecompiler.cmake
eng/native/gen-buildsys.sh
eng/native/tryrun.cmake [moved from src/coreclr/tryrun.cmake with 93% similarity]
src/coreclr/CMakeLists.txt
src/coreclr/build-runtime.sh
src/coreclr/src/CMakeLists.txt
src/coreclr/src/dlls/mscoree/unixinterface.cpp
src/coreclr/src/hosts/inc/coreclrhost.h
src/coreclr/src/inc/bundle.h
src/coreclr/src/inc/cor.h
src/coreclr/src/inc/corpriv.h
src/coreclr/src/inc/pinvokeoverride.h [new file with mode: 0644]
src/coreclr/src/libraries-native/CMakeLists.txt [deleted file]
src/coreclr/src/vm/CMakeLists.txt
src/coreclr/src/vm/bundle.cpp
src/coreclr/src/vm/corelib.cpp
src/coreclr/src/vm/dllimport.cpp
src/coreclr/src/vm/ecalllist.h
src/coreclr/src/vm/pinvokeoverride.cpp [new file with mode: 0644]
src/installer/corehost/build.sh
src/installer/corehost/cli/apphost/static/CMakeLists.txt
src/installer/corehost/cli/hostpolicy/coreclr.cpp
src/installer/corehost/cli/hostpolicy/coreclr.h
src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp
src/installer/corehost/tryrun.cmake [deleted file]
src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
src/libraries/Common/src/Interop/Interop.Libraries.cs
src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs
src/libraries/Native/AnyOS/System.IO.Compression.Native/entrypoints.c [new file with mode: 0644]
src/libraries/Native/AnyOS/entrypoints.h [new file with mode: 0644]
src/libraries/Native/Unix/CMakeLists.txt
src/libraries/Native/Unix/System.Globalization.Native/entrypoints.c
src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt
src/libraries/Native/Unix/System.IO.Compression.Native/extra_libs.cmake [new file with mode: 0644]
src/libraries/Native/Unix/System.IO.Ports.Native/CMakeLists.txt
src/libraries/Native/Unix/System.Native/CMakeLists.txt
src/libraries/Native/Unix/System.Native/extra_libs.cmake [new file with mode: 0644]
src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt
src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake [new file with mode: 0644]
src/libraries/Native/Unix/System.Net.Security.Native/pal_gssapi.h
src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/CMakeLists.txt
src/libraries/Native/Unix/System.Security.Cryptography.Native/CMakeLists.txt
src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake [new file with mode: 0644]
src/libraries/Native/Unix/tryrun.cmake [deleted file]
src/libraries/Native/Windows/CMakeLists.txt
src/libraries/Native/Windows/clrcompression/CMakeLists.txt
src/libraries/Native/build-native.sh
src/mono/mono/metadata/native-library-qcall.c
src/mono/mono/metadata/native-library.c
src/mono/mono/metadata/qcall-def.h
src/mono/wasm/wasm.proj
src/tests/build.sh

index 0b2caf9..e77d219 100755 (executable)
@@ -71,10 +71,9 @@ build_native()
     targetOS="$1"
     platformArch="$2"
     cmakeDir="$3"
-    tryrunDir="$4"
-    intermediatesDir="$5"
-    cmakeArgs="$6"
-    message="$7"
+    intermediatesDir="$4"
+    cmakeArgs="$5"
+    message="$6"
 
     # All set to commence the build
     echo "Commencing build of \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"
@@ -146,7 +145,7 @@ EOF
             scan_build=scan-build
         fi
 
-        nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$tryrunDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $cmakeArgs"
+        nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $cmakeArgs"
         echo "Invoking $nextCommand"
         eval $nextCommand
 
@@ -455,6 +454,22 @@ if [[ "$__PortableBuild" == 0 ]]; then
     __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
 fi
 
+if [[ "$__BuildArch" == wasm ]]; then
+    # nothing to do here
+    true
+elif [[ "$__TargetOS" == iOS ]]; then
+    # nothing to do here
+    true
+elif [[ "$__TargetOS" == tvOS ]]; then
+    # nothing to do here
+    true
+elif [[ "$__TargetOS" == Android ]]; then
+    # nothing to do here
+    true
+else
+    __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs"
+fi
+
 # Configure environment if we are doing a cross compile.
 if [[ "$__CrossBuild" == 1 ]]; then
     CROSSCOMPILE=1
index 7adc24d..4daa6fe 100644 (file)
@@ -451,7 +451,6 @@ endif(CLR_CMAKE_HOST_UNIX)
 if (MSVC)
   # Compile options for targeting windows
 
-  add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/TP>) # compile all files as C++
   add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/nologo>) # Suppress Startup Banner
   add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W3>) # set warning level to 3
   add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors
index 6ecc2d8..5588b50 100755 (executable)
@@ -7,10 +7,9 @@ scriptroot="$( cd -P "$( dirname "$0" )" && pwd )"
 
 if [[ "$#" -lt 4 ]]; then
   echo "Usage..."
-  echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to tryrun.cmake directory> <path to intermediate directory> <Architecture> <compiler> <compiler major version> <compiler minor version> [build flavor] [ninja] [scan-build] [cmakeargs]"
+  echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to intermediate directory> <Architecture> <compiler> <compiler major version> <compiler minor version> [build flavor] [ninja] [scan-build] [cmakeargs]"
   echo "Specify the path to the top level CMake file."
   echo "Specify the path that the build system files are generated in."
-  echo "Specify the path to the directory with tryrun.cmake file."
   echo "Specify the target architecture."
   echo "Specify the name of compiler (clang or gcc)."
   echo "Specify the major version of compiler."
@@ -22,11 +21,10 @@ if [[ "$#" -lt 4 ]]; then
   exit 1
 fi
 
-tryrun_dir="$2"
-build_arch="$4"
-compiler="$5"
-majorVersion="$6"
-minorVersion="$7"
+build_arch="$3"
+compiler="$4"
+majorVersion="$5"
+minorVersion="$6"
 
 source "$scriptroot/init-compiler.sh" "$build_arch" "$compiler" "$majorVersion" "$minorVersion"
 
@@ -42,7 +40,7 @@ scan_build=OFF
 generator="Unix Makefiles"
 __UnprocessedCMakeArgs=""
 
-for i in "${@:8}"; do
+for i in "${@:7}"; do
     upperI="$(echo "$i" | awk '{print toupper($0)}')"
     case "$upperI" in
       # Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO.
@@ -73,9 +71,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then
     TARGET_BUILD_ARCH="$build_arch"
     export TARGET_BUILD_ARCH
 
-    if [[ -n "$tryrun_dir" ]]; then
-        cmake_extra_defines="$cmake_extra_defines -C $tryrun_dir/tryrun.cmake"
-    fi
+    cmake_extra_defines="$cmake_extra_defines -C $scriptroot/tryrun.cmake"
 
     if [[ "$platform" == "Darwin" ]]; then
         cmake_extra_defines="$cmake_extra_defines -DCMAKE_SYSTEM_NAME=Darwin"
@@ -99,7 +95,7 @@ if [[ "$build_arch" == "wasm" ]]; then
 fi
 
 # We have to be able to build with CMake 3.6.2, so we can't use the -S or -B options
-pushd "$3"
+pushd "$2"
 
 # Include CMAKE_USER_MAKE_RULES_OVERRIDE as uninitialized since it will hold its value in the CMake cache otherwise can cause issues when branch switching
 $cmake_command \
similarity index 93%
rename from src/coreclr/tryrun.cmake
rename to eng/native/tryrun.cmake
index 4b23122..2cfd798 100644 (file)
@@ -31,6 +31,7 @@ if(DARWIN)
     set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1)
     set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1)
     set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
+    set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
     set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
     set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0)
     set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 0)
@@ -63,6 +64,7 @@ if(DARWIN)
     set_cache_value(SSCANF_CANNOT_HANDLE_MISSING_EXPONENT_EXITCODE 1)
     set_cache_value(SSCANF_SUPPORT_ll_EXITCODE 0)
     set_cache_value(UNGETC_NOT_RETURN_EOF_EXITCODE 1)
+    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 0)
   else()
     message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!")
   endif()
@@ -72,6 +74,7 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$" OR FREEBSD OR ILLUMOS)
   set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 0)
   set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 0)
   set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
+  set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
   set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
   set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 0)
   set_cache_value(HAVE_COMPATIBLE_ASIN_EXITCODE 0)
@@ -100,16 +103,21 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$" OR FREEBSD OR ILLUMOS)
 
 
   if(ALPINE_LINUX)
+    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1)
     set_cache_value(SSCANF_CANNOT_HANDLE_MISSING_EXPONENT_EXITCODE 0)
     set_cache_value(SSCANF_SUPPORT_ll_EXITCODE 1)
     set_cache_value(UNGETC_NOT_RETURN_EOF_EXITCODE 1)
   else()
+    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 0)
     set_cache_value(SSCANF_CANNOT_HANDLE_MISSING_EXPONENT_EXITCODE 1)
     set_cache_value(SSCANF_SUPPORT_ll_EXITCODE 0)
     set_cache_value(UNGETC_NOT_RETURN_EOF_EXITCODE 0)
   endif()
 
   if (FREEBSD)
+    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP 1)
+    set_cache_value(HAVE_CLOCK_MONOTONIC 1)
+    set_cache_value(HAVE_CLOCK_REALTIME 1)
     set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
     set_cache_value(HAVE_PROCFS_MAPS 0)
     set_cache_value(HAVE_PROCFS_STAT 0)
index ddd5734..b7cb9e9 100644 (file)
@@ -52,7 +52,13 @@ include(pgosupport.cmake)
 # Include libraries native shims
 #-------------------------------
 if(NOT CLR_CROSS_COMPONENTS_BUILD AND CLR_CMAKE_BUILD_SUBSET_RUNTIME)
-  add_subdirectory(src/libraries-native)
+    set(STATIC_LIBS_ONLY 1)
+
+    if(CLR_CMAKE_TARGET_WIN32)
+        add_subdirectory(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Windows Native.Windows)
+    else()
+        add_subdirectory(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix Native.Unix)
+    endif()
 endif(NOT CLR_CROSS_COMPONENTS_BUILD AND CLR_CMAKE_BUILD_SUBSET_RUNTIME)
 
 #-----------------------------------------
index 91c0b44..f8129a7 100755 (executable)
@@ -99,7 +99,7 @@ build_cross_architecture_components()
     export __CMakeBinDir CROSSCOMPILE
 
     __CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CROSS_COMPONENTS_BUILD=1 $__CMakeArgs"
-    build_native "$__TargetOS" "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "$__CMakeArgs" "cross-architecture components"
+    build_native "$__TargetOS" "$__CrossArch" "$__ProjectRoot" "$intermediatesForBuild" "$__CMakeArgs" "cross-architecture components"
 
     CROSSCOMPILE=1
     export CROSSCOMPILE
@@ -257,7 +257,7 @@ fi
 if [[ "$__SkipNative" == 1 ]]; then
     echo "Skipping CoreCLR component build."
 else
-    build_native "$__TargetOS" "$__BuildArch" "$__ProjectRoot" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeArgs" "CoreCLR component"
+    build_native "$__TargetOS" "$__BuildArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeArgs" "CoreCLR component"
 
     # Build cross-architecture components
     if [[ "$__SkipCrossArchNative" != 1 ]]; then
index 5f74a58..9285c57 100644 (file)
@@ -7,6 +7,7 @@ include_directories("classlibnative/bcltype")
 include_directories("classlibnative/cryptography")
 include_directories("classlibnative/inc")
 include_directories("${GENERATED_INCLUDE_DIR}")
+include_directories("hosts/inc")
 
 if(CLR_CMAKE_TARGET_WIN32 AND FEATURE_EVENT_TRACE)
     include_directories("${GENERATED_INCLUDE_DIR}/etw")
index fd8cf50..73ed20a 100644 (file)
@@ -18,6 +18,7 @@
 #include "../../vm/gdbjithelpers.h"
 #endif // FEATURE_GDBJIT
 #include "bundle.h"
+#include "pinvokeoverride.h"
 
 #define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS(__FILE__, (expr))
 
@@ -119,7 +120,8 @@ static void ConvertConfigPropertiesToUnicode(
     int propertyCount,
     LPCWSTR** propertyKeysWRef,
     LPCWSTR** propertyValuesWRef,
-    BundleProbe** bundleProbe,
+    BundleProbeFn** bundleProbe,
+    PInvokeOverrideFn** pinvokeOverride,
     bool* hostPolicyEmbedded)
 {
     LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount];
@@ -137,7 +139,13 @@ static void ConvertConfigPropertiesToUnicode(
         {
             // If this application is a single-file bundle, the bundle-probe callback 
             // is passed in as the value of "BUNDLE_PROBE" property (encoded as a string).
-            *bundleProbe = (BundleProbe*)_wcstoui64(propertyValuesW[propertyIndex], nullptr, 0);
+            *bundleProbe = (BundleProbeFn*)_wcstoui64(propertyValuesW[propertyIndex], nullptr, 0);
+        }
+        else if (strcmp(propertyKeys[propertyIndex], "PINVOKE_OVERRIDE") == 0)
+        {
+            // If host provides a PInvoke override (typically in a single-file bundle),
+            // the override callback is passed in as the value of "PINVOKE_OVERRIDE" property (encoded as a string).
+            *pinvokeOverride = (PInvokeOverrideFn*)_wcstoui64(propertyValuesW[propertyIndex], nullptr, 0);
         }
         else if (strcmp(propertyKeys[propertyIndex], "HOSTPOLICY_EMBEDDED") == 0)
         {
@@ -185,8 +193,9 @@ int coreclr_initialize(
 
     LPCWSTR* propertyKeysW;
     LPCWSTR* propertyValuesW;
-    BundleProbe* bundleProbe = nullptr;
+    BundleProbeFn* bundleProbe = nullptr;
     bool hostPolicyEmbedded = false;
+    PInvokeOverrideFn* pinvokeOverride = nullptr;
 
     ConvertConfigPropertiesToUnicode(
         propertyKeys,
@@ -195,6 +204,7 @@ int coreclr_initialize(
         &propertyKeysW,
         &propertyValuesW,
         &bundleProbe,
+        &pinvokeOverride,
         &hostPolicyEmbedded);
 
 #ifdef TARGET_UNIX
@@ -211,6 +221,11 @@ int coreclr_initialize(
 
     g_hostpolicy_embedded = hostPolicyEmbedded;
 
+    if (pinvokeOverride != nullptr)
+    {
+        PInvokeOverride::SetPInvokeOverride(pinvokeOverride);
+    }
+
     ReleaseHolder<ICLRRuntimeHost4> host;
 
     hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host);
index 4cb04b9..f1d6c00 100644 (file)
@@ -14,6 +14,8 @@
 #define CORECLR_CALLING_CONVENTION
 #endif
 
+#include <stdint.h>
+
 // For each hosting API, we define a function prototype and a function pointer
 // The prototype is useful for implicit linking against the dynamic coreclr
 // library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
@@ -121,4 +123,11 @@ CORECLR_HOSTING_API(coreclr_execute_assembly,
 
 #undef CORECLR_HOSTING_API
 
+//
+// Callback types used by the hosts
+//
+typedef bool(CORECLR_CALLING_CONVENTION BundleProbeFn)(const char* path, int64_t* offset, int64_t* size);
+typedef const void* (CORECLR_CALLING_CONVENTION PInvokeOverrideFn)(const char* libraryName, const char* entrypointName);
+
+
 #endif // __CORECLR_HOST_H__
index e6c7a0a..ab3ece2 100644 (file)
@@ -3,7 +3,7 @@
 
 /*****************************************************************************
  **                                                                         **
- ** bundle.h - Information about applications bundled as a single-file  **
+ ** bundle.h - Information about applications bundled as a single-file      **
  **                                                                         **
  *****************************************************************************/
 
@@ -11,6 +11,7 @@
 #define _BUNDLE_H_
 
 #include <sstring.h>
+#include "coreclrhost.h"
 
 class Bundle;
 
@@ -34,12 +35,10 @@ struct BundleFileLocation
     bool IsValid() const { LIMITED_METHOD_CONTRACT; return Offset != 0; }
 };
 
-typedef bool(__stdcall BundleProbe)(LPCSTR, INT64*, INT64*);
-
 class Bundle
 {
 public:
-    Bundle(LPCSTR bundlePath, BundleProbe *probe);
+    Bundle(LPCSTR bundlePath, BundleProbeFn *probe);
     BundleFileLocation Probe(const SString& path, bool pathIsBundleRelative = false) const;
 
     const SString &Path() const { LIMITED_METHOD_CONTRACT; return m_path; }
@@ -52,11 +51,10 @@ public:
 private:
 
     SString m_path; // The path to single-file executable
-    BundleProbe *m_probe;
+    BundleProbeFn *m_probe;
 
     SString m_basePath; // The prefix to denote a path within the bundle
     COUNT_T m_basePathLength;
 };
 
 #endif // _BUNDLE_H_
-// EOF =======================================================================
index 7b9bf9c..9101bcd 100644 (file)
@@ -2388,4 +2388,3 @@ inline ULONG CorSigUncompressPointer(   // return number of bytes of that compre
 #endif  // __cplusplus
 
 #endif // _COR_H_
-// EOF =======================================================================
index 003386c..4905633 100644 (file)
@@ -383,5 +383,4 @@ struct CORCOMPILE_DEPENDENCY;
 typedef GUID CORCOMPILE_NGEN_SIGNATURE;
 
 #endif  // _CORPRIV_H_
-// EOF =======================================================================
 
diff --git a/src/coreclr/src/inc/pinvokeoverride.h b/src/coreclr/src/inc/pinvokeoverride.h
new file mode 100644 (file)
index 0000000..525f976
--- /dev/null
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+/*****************************************************************************
+ **                                                                         **
+ ** pinvokeoverride.h - PInvoke binding override                            **
+ **                                                                         **
+ *****************************************************************************/
+
+#ifndef _PINVOKEOVERRIDE_H_
+#define _PINVOKEOVERRIDE_H_
+
+#include "coreclrhost.h"
+
+class PInvokeOverride
+{
+public:
+    static void SetPInvokeOverride(PInvokeOverrideFn* overrideImpl);
+    static const void* GetMethodImpl(const char* libraryName, const char* entrypointName);
+};
+
+#endif // _PINVOKEOVERRIDE_H_
diff --git a/src/coreclr/src/libraries-native/CMakeLists.txt b/src/coreclr/src/libraries-native/CMakeLists.txt
deleted file mode 100644 (file)
index 65b0d06..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-set(GLOBALIZATION_NATIVE_DIR ${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Globalization.Native)
-
-# Suppress exporting of the PAL APIs
-add_definitions(-DPALEXPORT=EXTERN_C)
-
-include_directories("${GLOBALIZATION_NATIVE_DIR}")
-include_directories("${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/Common")
-
-add_subdirectory(${GLOBALIZATION_NATIVE_DIR} System.Globalization.Native)
-
index 42da88e..3f2600a 100644 (file)
@@ -102,6 +102,7 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON
     perfmap.cpp
     perfinfo.cpp
     pgo.cpp
+    pinvokeoverride.cpp
     precode.cpp
     prestub.cpp
     profilerdiagnosticprotocolhelper.cpp
index 373ab59..64994aa 100644 (file)
@@ -30,7 +30,7 @@ const SString &BundleFileLocation::Path() const
     return Bundle::AppBundle->Path();
 }
 
-Bundle::Bundle(LPCSTR bundlePath, BundleProbe *probe)
+Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe)
 {
     STANDARD_VM_CONTRACT;
 
index 4562e2e..aaf9bc9 100644 (file)
@@ -371,9 +371,6 @@ const USHORT c_nCoreLibFieldDescriptions = NumItems(c_rgCoreLibFieldDescriptions
 // ECalls
 //
 
-// ECalls defined by libraries-native shims
-EXTERN_C const LPVOID gPalGlobalizationNative[];
-
 // When compiling crossgen, we only need the target version of the ecall tables
 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_CORELIB)
 
index d9a003f..4cae383 100644 (file)
@@ -34,6 +34,7 @@
 #include "strongnameholders.h"
 #include "ecall.h"
 #include "fieldmarshaler.h"
+#include "pinvokeoverride.h"
 
 #include <formattype.h>
 #include "../md/compiler/custattr.h"
@@ -4230,7 +4231,7 @@ void NDirect::PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSi
     if (callConv == pmCallConvThiscall)
         ndirectflags |= NDirectMethodDesc::kThisCall;
 
-    if (pNMD->GetLoaderModule()->IsSystem() && strcmp(szLibName, "QCall") == 0)
+    if (pNMD->GetLoaderModule()->IsSystem() && (strcmp(szLibName, "QCall") == 0))
     {
         ndirectflags |= NDirectMethodDesc::kIsQCall;
     }
@@ -6224,7 +6225,6 @@ namespace
             // this matches exactly the names in  Interop.Libraries.cs 
             static const LPCWSTR toRedirect[] = {
                 W("libSystem.Native"),
-                W("libSystem.IO.Compression.Native"),
                 W("libSystem.Net.Security.Native"),
                 W("libSystem.Security.Cryptography.Native.OpenSsl")
             };
@@ -6509,6 +6509,15 @@ VOID NDirect::NDirectLink(NDirectMethodDesc *pMD)
     // Loading unmanaged dlls can trigger dllmains which certainly count as code execution!
     pMD->EnsureActive();
 
+    {
+        LPVOID pvTarget = (LPVOID)PInvokeOverride::GetMethodImpl(pMD->GetLibNameRaw(), pMD->GetEntrypointName());
+        if (pvTarget != NULL)
+        {
+            pMD->SetNDirectTarget(pvTarget);
+            return;
+        }
+    }
+
     LoadLibErrorTracker errorTracker;
 
     BOOL fSuccess = FALSE;
index 1546872..3602c02 100644 (file)
@@ -1139,9 +1139,6 @@ FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs)
 FCClassElement("GC", "System", gGCInterfaceFuncs)
 FCClassElement("GCHandle", "System.Runtime.InteropServices", gGCHandleFuncs)
 FCClassElement("GCSettings", "System.Runtime", gGCSettingsFuncs)
-#ifndef CROSSGEN_COMPILE
-FCClassElement("Globalization", "", gPalGlobalizationNative)
-#endif
 #ifdef FEATURE_COMINTEROP
 FCClassElement("IEnumerable", "System.Collections", gStdMngIEnumerableFuncs)
 FCClassElement("IEnumerator", "System.Collections", gStdMngIEnumeratorFuncs)
diff --git a/src/coreclr/src/vm/pinvokeoverride.cpp b/src/coreclr/src/vm/pinvokeoverride.cpp
new file mode 100644 (file)
index 0000000..07af650
--- /dev/null
@@ -0,0 +1,46 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+//*****************************************************************************
+// pinvokeoverride.cpp
+//
+// Helpers to implement PInvoke overriding
+//
+//*****************************************************************************
+
+#include "common.h"
+#include "pinvokeoverride.h"
+
+extern "C" const void* GlobalizationResolveDllImport(const char* name);
+
+static PInvokeOverrideFn* s_overrideImpl = nullptr;
+
+// here we handle PInvokes whose implementation is always statically linked (even in .so/.dll case)
+static const void* DefaultResolveDllImport(const char* libraryName, const char* entrypointName)
+{
+    if (strcmp(libraryName, "libSystem.Globalization.Native") == 0)
+    {
+        return GlobalizationResolveDllImport(entrypointName);
+    }
+
+    return nullptr;
+}
+
+void PInvokeOverride::SetPInvokeOverride(PInvokeOverrideFn* overrideImpl)
+{
+    s_overrideImpl = overrideImpl;
+}
+
+const void* PInvokeOverride::GetMethodImpl(const char* libraryName, const char* entrypointName)
+{
+    if (s_overrideImpl != nullptr)
+    {
+        const void* result = s_overrideImpl(libraryName, entrypointName);
+        if (result != nullptr)
+        {
+            LOG((LF_INTEROP, LL_INFO1000, "PInvoke overriden for: lib: %s, entry: %s \n", libraryName, entrypointName));
+            return result;
+        }
+    }
+
+    return DefaultResolveDllImport(libraryName, entrypointName);
+}
index 9766753..d807a9c 100755 (executable)
@@ -116,4 +116,4 @@ setup_dirs
 check_prereqs
 
 # Build the installer native components.
-build_native "$__TargetOS" "$__BuildArch" "$__scriptpath" "$__scriptpath" "$__IntermediatesDir" "$__CMakeArgs" "installer component"
+build_native "$__TargetOS" "$__BuildArch" "$__scriptpath" "$__IntermediatesDir" "$__CMakeArgs" "installer component"
index bc91c6f..cf100a7 100644 (file)
@@ -35,6 +35,7 @@ add_definitions(-D_NO_ASYNCRTIMP)
 add_definitions(-D_NO_PPLXIMP)
 add_definitions(-DEXPORT_SHARED_API=1)
 add_definitions(-DHOSTPOLICY_EMBEDDED)
+add_definitions(-DNATIVE_LIBS_EMBEDDED)
 
 
 include(../../fxr/files.cmake)
@@ -106,6 +107,8 @@ if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_AR
     target_link_libraries(singlefilehost Advapi32.lib shell32.lib)
 endif()
 
+set(NATIVE_LIBS_EXTRA)
+
 # Path like: artifacts/bin/coreclr/windows.x64.Release/lib  or
 #            /root/runtime/artifacts/transport/coreclr/lib
 set(CORECLR_STATIC_LIB_LOCATION "${CORECLR_ARTIFACTS}/lib")
@@ -116,6 +119,7 @@ if(CLR_CMAKE_TARGET_WIN32)
     set(CORECLR_LIBRARIES
         ${CORECLR_STATIC_LIB_LOCATION}/coreclr_static.lib
         ${CORECLR_STATIC_LIB_LOCATION}/System.Globalization.Native.lib
+        ${CORECLR_STATIC_LIB_LOCATION}/libclrcompression.lib
         kernel32.lib
         advapi32.lib
         ole32.lib
@@ -131,11 +135,16 @@ else()
     set(CORECLR_LIBRARIES
         ${CORECLR_STATIC_LIB_LOCATION}/libcoreclr_static.a
         ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Globalization.Native.a
+        ${CORECLR_STATIC_LIB_LOCATION}/libSystem.IO.Compression.Native.a
         ${CORECLR_STATIC_LIB_LOCATION}/libpalrt.a
         ${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a
         ${CORECLR_STATIC_LIB_LOCATION}/libeventprovider.a
         ${CORECLR_STATIC_LIB_LOCATION}/libnativeresourcestring.a
     )
+
+    # additional requirements for System.IO.Compression.Native
+    include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.IO.Compression.Native/extra_libs.cmake)
+    append_extra_compression_libs(NATIVE_LIBS_EXTRA)
 endif()
 
 if(CLR_CMAKE_TARGET_OSX)
@@ -179,79 +188,32 @@ endif()
 set(NATIVE_LIBS_LOCATION "${NATIVE_LIBS_ARTIFACTS}")
 message ("Looking for native libs at location: '${NATIVE_LIBS_LOCATION}'.")
 
-if(NOT CLR_CMAKE_TARGET_LINUX)
-    set(NATIVE_LIBS
-        # Native libs linked into singlefilehost is supported only on Linux for now.
-        # if/when BSD and OSX are supported too, consider the commented code sections below.
-    )
-else()
+# These native libs are linked into singlefilehost only on Linux (for now).
+if(CLR_CMAKE_TARGET_LINUX)
     set(NATIVE_LIBS
-      ${NATIVE_LIBS_LOCATION}/libSystem.IO.Compression.Native.a
       ${NATIVE_LIBS_LOCATION}/libSystem.Native.a
       ${NATIVE_LIBS_LOCATION}/libSystem.Net.Security.Native.a
       ${NATIVE_LIBS_LOCATION}/libSystem.Security.Cryptography.Native.OpenSsl.a
     )
 
-    find_package(ZLIB REQUIRED)
-
-    # Additional requirements for System.System.IO.Compression.Native
-    #
-    # if (CLR_CMAKE_TARGET_SUNOS)
-    #     set(ZLIB_LIBRARIES z m)
-    # elseif (CLR_CMAKE_TARGET_UNIX)
-    #     find_package(ZLIB REQUIRED)
-    # endif ()
+    # Additional requirements for System.Native
+    include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Native/extra_libs.cmake)
+    append_extra_system_libs(NATIVE_LIBS_EXTRA)
 
     # Additional requirements for System.Net.Security.Native
-    if (HAVE_GSSFW_HEADERS)
-       find_library(LIBGSS NAMES GSS)
-       if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
-         message(FATAL_ERROR "Cannot find GSS.Framework and System.Net.Security.Native cannot build without it. Try installing GSS.Framework (or the appropriate package for your platform)")
-       endif()
-    elseif(HAVE_HEIMDAL_HEADERS)
-       find_library(LIBGSS NAMES gssapi)
-       if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
-         message(FATAL_ERROR "Cannot find libgssapi and System.Net.Security.Native cannot build without it. Try installing heimdal (or the appropriate package for your platform)")
-       endif()
-    else()
-       find_library(LIBGSS NAMES gssapi_krb5)
-       if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
-         message(FATAL_ERROR "Cannot find libgssapi_krb5 and System.Net.Security.Native cannot build without it. Try installing libkrb5-dev (or the appropriate package for your platform)")
-       endif()
-    endif()
-
-    # Additional requirements for System.Native
-    if (CLR_CMAKE_TARGET_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID)
-        set(NATIVE_LIBS_EXTRA
-          rt
-        )
-    # elseif (CLR_CMAKE_TARGET_FREEBSD)
-    #     set(NATIVE_LIBS_EXTRA
-    #       pthread
-    #     )
-    #     find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib)
-    #     if(NOT (INOTIFY_LIBRARY STREQUAL INOTIFY_LIBRARY-NOTFOUND))
-    #       LIST(APPEND NATIVE_LIBS_EXTRA
-    #         ${INOTIFY_LIBRARY}
-    #       )
-    #     endif ()
-    # elseif (CLR_CMAKE_TARGET_SUNOS)
-    #     set(NATIVE_LIBS_EXTRA
-    #         socket
-    #     )
-    endif ()
+    include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake)
+    append_extra_security_libs(NATIVE_LIBS_EXTRA)
 
     # Additional requirements for System.Security.Cryptography.Native.OpenSsl
-    if(NOT FEATURE_DISTRO_AGNOSTIC_SSL)
-        find_package(OpenSSL)
-    endif()
+    include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake)
+    append_extra_cryptography_libs(NATIVE_LIBS_EXTRA)
+endif()
 
-    if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS)
-        # These options are used to force every object to be included even if it's unused.
-        set(START_WHOLE_ARCHIVE -Wl,--whole-archive)
-        set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive)
-    endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS)
-endif(NOT CLR_CMAKE_TARGET_LINUX)
+if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS)
+    # These options are used to force every object to be included even if it's unused.
+    set(START_WHOLE_ARCHIVE -Wl,--whole-archive)
+    set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive)
+endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS)
 
 set_property(TARGET singlefilehost PROPERTY ENABLE_EXPORTS 1)
 
@@ -262,15 +224,5 @@ target_link_libraries(singlefilehost
     ${NATIVE_LIBS}
     ${END_WHOLE_ARCHIVE}
 
-    ${ZLIB_LIBRARIES}
-    ${LIBGSS}
     ${NATIVE_LIBS_EXTRA}
-
 )
-
-if(NOT FEATURE_DISTRO_AGNOSTIC_SSL)
-    target_link_libraries(singlefilehost
-        ${OPENSSL_CRYPTO_LIBRARY}
-        ${OPENSSL_SSL_LIBRARY}
-    )
-endif()
index d9564ac..0046d66 100644 (file)
@@ -148,7 +148,8 @@ namespace
         _X("APP_NI_PATHS"),
         _X("RUNTIME_IDENTIFIER"),
         _X("BUNDLE_PROBE"),
-        _X("HOSTPOLICY_EMBEDDED")
+        _X("HOSTPOLICY_EMBEDDED"),
+        _X("PINVOKE_OVERRIDE")
     };
 
     static_assert((sizeof(PropertyNameMapping) / sizeof(*PropertyNameMapping)) == static_cast<size_t>(common_property::Last), "Invalid property count");
index c086ba5..72b6742 100644 (file)
@@ -67,6 +67,7 @@ enum class common_property
     RuntimeIdentifier,
     BundleProbe,
     HostPolicyEmbedded,
+    PInvokeOverride,
     // Sentinel value - new values should be defined above
     Last
 };
index 48d7cd3..aba6272 100644 (file)
@@ -42,6 +42,28 @@ namespace
 
         return bundle::runner_t::app()->probe(file_path, offset, size);
     }
+
+#if defined(NATIVE_LIBS_EMBEDDED)
+    extern "C" const void* CompressionResolveDllImport(const char* name);
+
+#if defined(_WIN32)
+#define COMPRESSION_DLL_NAME "clrcompression"
+#else
+#define COMPRESSION_DLL_NAME "libSystem.IO.Compression.Native"
+#endif
+
+    // pinvoke_override:
+    // Check if given function belongs to one of statically linked libraries and return a pointer if found.
+    const void* STDMETHODCALLTYPE pinvoke_override(const char* libraryName, const char* entrypointName)
+    {
+        if (strcmp(libraryName, COMPRESSION_DLL_NAME) == 0)
+        {
+            return CompressionResolveDllImport(entrypointName);
+        }
+
+        return nullptr;
+    }
+#endif
 }
 
 int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const arguments_t &args, bool enable_breadcrumbs)
@@ -241,6 +263,22 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
         }
     }
 
+#if defined(NATIVE_LIBS_EMBEDDED)
+    // PInvoke Override
+    if (bundle::info_t::is_single_file_bundle())
+    {
+        // Encode the pinvoke_override function pointer as a string, and pass it to the runtime.
+        pal::stringstream_t ptr_stream;
+        ptr_stream << "0x" << std::hex << (size_t)(&pinvoke_override);
+
+        if (!coreclr_properties.add(common_property::PInvokeOverride, ptr_stream.str().c_str()))
+        {
+            log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
+            return StatusCode::LibHostDuplicateProperty;
+        }
+    }
+#endif
+
 #if defined(HOSTPOLICY_EMBEDDED)
     if (!coreclr_properties.add(common_property::HostPolicyEmbedded, _X("true")))
     {
diff --git a/src/installer/corehost/tryrun.cmake b/src/installer/corehost/tryrun.cmake
deleted file mode 100644 (file)
index eba94ae..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-set(CROSS_ROOTFS $ENV{ROOTFS_DIR})
-set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH})
-
-macro(set_cache_value)
-  set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE)
-  set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE)
-endmacro()
-
-if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv7-alpine-linux-musleabihf OR
-   EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf OR
-   EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl)
-
-  set(ALPINE_LINUX 1)
-elseif(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version)
-  set(FREEBSD 1)
-  set(CMAKE_SYSTEM_NAME FreeBSD)
-  set(CLR_CMAKE_TARGET_OS FreeBSD)
-elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc)
-  set(ILLUMOS 1)
-endif()
-
-if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$" OR FREEBSD OR ILLUMOS)
-  if(ILLUMOS)
-    set_cache_value(COMPILER_SUPPORTS_W_CLASS_MEMACCESS 0)
-  endif()
-else()
-  message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!")
-endif()
index 7d742fd..036716c 100644 (file)
     <!-- LINUX -->
 
     <!-- OSX -->
-    <SingleFileHostIncludeFilename Include="libSystem.IO.Compression.Native.dylib" />
     <SingleFileHostIncludeFilename Include="libSystem.Native.dylib" />
     <SingleFileHostIncludeFilename Include="libSystem.Net.Security.Native.dylib" />
     <SingleFileHostIncludeFilename Include="libSystem.Security.Cryptography.Native.Apple.dylib" />
     <SingleFileHostIncludeFilename Include="libSystem.Security.Cryptography.Native.OpenSsl.dylib" />
     
     <!-- Windows -->
-    <SingleFileHostIncludeFilename Include="clrcompression.dll" />
     <SingleFileHostIncludeFilename Include="mscordaccore.dll" />
   </ItemGroup>
 
index 2178527..e57d591 100644 (file)
@@ -5,6 +5,6 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
-        internal const string GlobalizationNative = "QCall";
+        internal const string GlobalizationNative = "libSystem.Globalization.Native";
     }
 }
index 6b1006c..4893a28 100644 (file)
@@ -31,7 +31,7 @@ internal static partial class Interop
         internal const string Wldap32 = "wldap32.dll";
         internal const string Ws2_32 = "ws2_32.dll";
         internal const string Wtsapi32 = "wtsapi32.dll";
-        internal const string CompressionNative = "clrcompression.dll";
+        internal const string CompressionNative = "clrcompression";
         internal const string MsQuic = "msquic.dll";
         internal const string HostPolicy = "hostpolicy.dll";
     }
diff --git a/src/libraries/Native/AnyOS/System.IO.Compression.Native/entrypoints.c b/src/libraries/Native/AnyOS/System.IO.Compression.Native/entrypoints.c
new file mode 100644 (file)
index 0000000..b194b97
--- /dev/null
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#include "../../AnyOS/entrypoints.h"
+
+// Include System.IO.Compression.Native headers
+#include "../zlib/pal_zlib.h"
+#include "../brotli/include/brotli/decode.h"
+#include "../brotli/include/brotli/encode.h"
+#include "../brotli/include/brotli/port.h"
+#include "../brotli/include/brotli/types.h"
+
+#include "../../AnyOS/entrypoints.h"
+
+static const Entry s_compressionNative[] =
+{
+    DllImportEntry(BrotliDecoderCreateInstance)
+    DllImportEntry(BrotliDecoderDecompress)
+    DllImportEntry(BrotliDecoderDecompressStream)
+    DllImportEntry(BrotliDecoderDestroyInstance)
+    DllImportEntry(BrotliDecoderIsFinished)
+    DllImportEntry(BrotliEncoderCompress)
+    DllImportEntry(BrotliEncoderCompressStream)
+    DllImportEntry(BrotliEncoderCreateInstance)
+    DllImportEntry(BrotliEncoderDestroyInstance)
+    DllImportEntry(BrotliEncoderHasMoreOutput)
+    DllImportEntry(BrotliEncoderSetParameter)
+    DllImportEntry(CompressionNative_Crc32)
+    DllImportEntry(CompressionNative_Deflate)
+    DllImportEntry(CompressionNative_DeflateEnd)
+    DllImportEntry(CompressionNative_DeflateInit2_)
+    DllImportEntry(CompressionNative_Inflate)
+    DllImportEntry(CompressionNative_InflateEnd)
+    DllImportEntry(CompressionNative_InflateInit2_)
+};
+
+EXTERN_C const void* CompressionResolveDllImport(const char* name);
+
+EXTERN_C const void* CompressionResolveDllImport(const char* name)
+{
+    return ResolveDllImport(s_compressionNative, lengthof(s_compressionNative), name);
+}
diff --git a/src/libraries/Native/AnyOS/entrypoints.h b/src/libraries/Native/AnyOS/entrypoints.h
new file mode 100644 (file)
index 0000000..ce7a7e2
--- /dev/null
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#pragma once
+
+#include <stdint.h>
+#include <string.h>
+
+#ifndef lengthof
+#define lengthof(rg) (sizeof(rg)/sizeof(rg[0]))
+#endif
+
+typedef struct
+{
+    const char* name;
+    const void* method;
+} Entry;
+
+// expands to:      {"impl", (void*)impl},
+#define DllImportEntry(impl) \
+    {#impl, (void*)impl},
+
+static const void* ResolveDllImport(const Entry* resolutionTable, size_t tableLength, const char* name)
+{
+    for (size_t i = 0; i < tableLength; i++)
+    {
+        if (strcmp(name, resolutionTable[i].name) == 0)
+        {
+            return resolutionTable[i].method;
+        }
+    }
+
+    return NULL;
+}
index 3bc41e4..ebc9ff3 100644 (file)
@@ -54,15 +54,27 @@ if (PRERELEASE)
     add_compile_options(-Werror)
 endif()
 
+if(STATIC_LIBS_ONLY)
+    # Suppress exporting of the PAL APIs
+    add_definitions(-DPALEXPORT=EXTERN_C)
+
+    set(STATIC_LIB_DESTINATION lib)
+    set(GEN_SHARED_LIB 0)
+else()
+    set(STATIC_LIB_DESTINATION .)
+    set(GEN_SHARED_LIB 1)
+endif()
+
 if(CLR_CMAKE_TARGET_BROWSER)
     # The emscripten build has additional warnings so -Werror breaks
     add_compile_options(-Wno-unused-parameter)
     add_compile_options(-Wno-unused-function)
     add_compile_options(-Wno-alloca)
     add_compile_options(-Wno-implicit-int-float-conversion)
-else()
-  set(GEN_SHARED_LIB 1)
-endif(CLR_CMAKE_TARGET_BROWSER)
+
+    set(GEN_SHARED_LIB 0)
+    set(STATIC_LIB_DESTINATION .)
+endif()
 
 if (CLR_CMAKE_TARGET_ARCH_AMD64)
     add_definitions(-DTARGET_64BIT=1)
index 7a7f5ea..85a3908 100644 (file)
@@ -1,7 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-#include <stdint.h>
+#include "../../AnyOS/entrypoints.h"
 
 typedef uint16_t UChar;
 
@@ -17,45 +17,47 @@ typedef uint16_t UChar;
 #include "pal_normalization.h"
 #include "pal_timeZoneInfo.h"
 
-#define FCFuncStart(name) EXTERN_C const void* name[]; const void* name[] = {
-#define FCFuncEnd() (void*)0x01 /* FCFuncFlag_EndOfArray */ };
+static const Entry s_globalizationNative[] =
+{
+    DllImportEntry(GlobalizationNative_ChangeCase)
+    DllImportEntry(GlobalizationNative_ChangeCaseInvariant)
+    DllImportEntry(GlobalizationNative_ChangeCaseTurkish)
+    DllImportEntry(GlobalizationNative_CloseSortHandle)
+    DllImportEntry(GlobalizationNative_CompareString)
+    DllImportEntry(GlobalizationNative_EndsWith)
+    DllImportEntry(GlobalizationNative_EnumCalendarInfo)
+    DllImportEntry(GlobalizationNative_GetCalendarInfo)
+    DllImportEntry(GlobalizationNative_GetCalendars)
+    DllImportEntry(GlobalizationNative_GetDefaultLocaleName)
+    DllImportEntry(GlobalizationNative_GetICUVersion)
+    DllImportEntry(GlobalizationNative_GetJapaneseEraStartDate)
+    DllImportEntry(GlobalizationNative_GetLatestJapaneseEra)
+    DllImportEntry(GlobalizationNative_GetLocaleInfoGroupingSizes)
+    DllImportEntry(GlobalizationNative_GetLocaleInfoInt)
+    DllImportEntry(GlobalizationNative_GetLocaleInfoString)
+    DllImportEntry(GlobalizationNative_GetLocaleName)
+    DllImportEntry(GlobalizationNative_GetLocales)
+    DllImportEntry(GlobalizationNative_GetLocaleTimeFormat)
+    DllImportEntry(GlobalizationNative_GetSortHandle)
+    DllImportEntry(GlobalizationNative_GetSortKey)
+    DllImportEntry(GlobalizationNative_GetSortVersion)
+    DllImportEntry(GlobalizationNative_GetTimeZoneDisplayName)
+    DllImportEntry(GlobalizationNative_IndexOf)
+    DllImportEntry(GlobalizationNative_InitICUFunctions)
+    DllImportEntry(GlobalizationNative_InitOrdinalCasingPage)
+    DllImportEntry(GlobalizationNative_IsNormalized)
+    DllImportEntry(GlobalizationNative_IsPredefinedLocale)
+    DllImportEntry(GlobalizationNative_LastIndexOf)
+    DllImportEntry(GlobalizationNative_LoadICU)
+    DllImportEntry(GlobalizationNative_NormalizeString)
+    DllImportEntry(GlobalizationNative_StartsWith)
+    DllImportEntry(GlobalizationNative_ToAscii)
+    DllImportEntry(GlobalizationNative_ToUnicode)
+};
 
-#define QCFuncElement(name,impl) \
-    (void*)0x8 /* FCFuncFlag_QCall */, (void*)(impl), (void*)name,
+EXTERN_C const void* GlobalizationResolveDllImport(const char* name);
 
-FCFuncStart(gPalGlobalizationNative)
-    QCFuncElement("ChangeCase", GlobalizationNative_ChangeCase)
-    QCFuncElement("ChangeCaseInvariant", GlobalizationNative_ChangeCaseInvariant)
-    QCFuncElement("ChangeCaseTurkish", GlobalizationNative_ChangeCaseTurkish)
-    QCFuncElement("CloseSortHandle", GlobalizationNative_CloseSortHandle)
-    QCFuncElement("CompareString", GlobalizationNative_CompareString)
-    QCFuncElement("EndsWith", GlobalizationNative_EndsWith)
-    QCFuncElement("EnumCalendarInfo", GlobalizationNative_EnumCalendarInfo)
-    QCFuncElement("GetCalendarInfo", GlobalizationNative_GetCalendarInfo)
-    QCFuncElement("GetCalendars", GlobalizationNative_GetCalendars)
-    QCFuncElement("GetDefaultLocaleName", GlobalizationNative_GetDefaultLocaleName)
-    QCFuncElement("GetICUVersion", GlobalizationNative_GetICUVersion)
-    QCFuncElement("GetJapaneseEraStartDate", GlobalizationNative_GetJapaneseEraStartDate)
-    QCFuncElement("GetLatestJapaneseEra", GlobalizationNative_GetLatestJapaneseEra)
-    QCFuncElement("GetLocaleInfoGroupingSizes", GlobalizationNative_GetLocaleInfoGroupingSizes)
-    QCFuncElement("GetLocaleInfoInt", GlobalizationNative_GetLocaleInfoInt)
-    QCFuncElement("GetLocaleInfoString", GlobalizationNative_GetLocaleInfoString)
-    QCFuncElement("GetLocaleName", GlobalizationNative_GetLocaleName)
-    QCFuncElement("GetLocales", GlobalizationNative_GetLocales)
-    QCFuncElement("GetLocaleTimeFormat", GlobalizationNative_GetLocaleTimeFormat)
-    QCFuncElement("GetSortHandle", GlobalizationNative_GetSortHandle)
-    QCFuncElement("GetSortKey", GlobalizationNative_GetSortKey)
-    QCFuncElement("GetSortVersion", GlobalizationNative_GetSortVersion)
-    QCFuncElement("GetTimeZoneDisplayName", GlobalizationNative_GetTimeZoneDisplayName)
-    QCFuncElement("IndexOf", GlobalizationNative_IndexOf)
-    QCFuncElement("InitICUFunctions", GlobalizationNative_InitICUFunctions)
-    QCFuncElement("InitOrdinalCasingPage", GlobalizationNative_InitOrdinalCasingPage)
-    QCFuncElement("IsNormalized", GlobalizationNative_IsNormalized)
-    QCFuncElement("IsPredefinedLocale", GlobalizationNative_IsPredefinedLocale)
-    QCFuncElement("LastIndexOf", GlobalizationNative_LastIndexOf)
-    QCFuncElement("LoadICU", GlobalizationNative_LoadICU)
-    QCFuncElement("NormalizeString", GlobalizationNative_NormalizeString)
-    QCFuncElement("StartsWith", GlobalizationNative_StartsWith)
-    QCFuncElement("ToAscii", GlobalizationNative_ToAscii)
-    QCFuncElement("ToUnicode", GlobalizationNative_ToUnicode)
-FCFuncEnd()
+EXTERN_C const void* GlobalizationResolveDllImport(const char* name)
+{
+    return ResolveDllImport(s_globalizationNative, lengthof(s_globalizationNative), name);
+}
index dcd1d87..28f57b4 100644 (file)
@@ -2,14 +2,12 @@ project(System.IO.Compression.Native C)
 
 if (CLR_CMAKE_TARGET_BROWSER)
     add_definitions(-s USE_ZLIB)
-elseif (CLR_CMAKE_TARGET_ANDROID)
-    # need special case here since we want to link against libz.so but find_package() would resolve libz.a
-    set(ZLIB_LIBRARIES z)
-elseif (CLR_CMAKE_TARGET_SUNOS)
-    set(ZLIB_LIBRARIES z m)
-else ()
-    find_package(ZLIB REQUIRED)
-endif ()
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake)
+
+set(NATIVE_LIBS_EXTRA)
+append_extra_compression_libs(NATIVE_LIBS_EXTRA)
 
 set(NATIVECOMPRESSION_SOURCES
     ../../AnyOS/zlib/pal_zlib.c
@@ -52,6 +50,7 @@ if (NOT CLR_CMAKE_TARGET_BROWSER)
         ../../AnyOS/brotli/enc/metablock.c
         ../../AnyOS/brotli/enc/static_dict.c
         ../../AnyOS/brotli/enc/utf8_util.c
+        ../../AnyOS/System.IO.Compression.Native/entrypoints.c
     )
 
     # Disable implicit fallthrough warning for Brotli
@@ -66,7 +65,7 @@ if (GEN_SHARED_LIB)
     )
 
     target_link_libraries(System.IO.Compression.Native
-        ${ZLIB_LIBRARIES}
+        ${NATIVE_LIBS_EXTRA}
     )
     install_with_stripped_symbols (System.IO.Compression.Native PROGRAMS .)
 endif ()
@@ -78,4 +77,4 @@ add_library(System.IO.Compression.Native-Static
 
 set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native  CLEAN_DIRECT_OUTPUT 1)
 
-install (TARGETS System.IO.Compression.Native-Static DESTINATION .)
+install (TARGETS System.IO.Compression.Native-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/libraries/Native/Unix/System.IO.Compression.Native/extra_libs.cmake b/src/libraries/Native/Unix/System.IO.Compression.Native/extra_libs.cmake
new file mode 100644 (file)
index 0000000..f4c7dcd
--- /dev/null
@@ -0,0 +1,14 @@
+
+macro(append_extra_compression_libs NativeLibsExtra)
+  if (CLR_CMAKE_TARGET_BROWSER)
+      # nothing special to link
+  elseif (CLR_CMAKE_TARGET_ANDROID)
+      # need special case here since we want to link against libz.so but find_package() would resolve libz.a
+      set(ZLIB_LIBRARIES z)
+  elseif (CLR_CMAKE_TARGET_SUNOS)
+      set(ZLIB_LIBRARIES z m)
+  else ()
+      find_package(ZLIB REQUIRED)
+  endif ()
+  list(APPEND ${NativeLibsExtra} ${ZLIB_LIBRARIES})
+endmacro()
index 1750a07..ede4480 100644 (file)
@@ -1,11 +1,13 @@
 project(System.IO.Ports.Native C)
 
-add_library(System.IO.Ports.Native
-    SHARED
-    pal_termios.c
-    pal_serial.c
-    ${VERSION_FILE_PATH}
-)
+if (GEN_SHARED_LIB)
+    add_library(System.IO.Ports.Native
+        SHARED
+        pal_termios.c
+        pal_serial.c
+        ${VERSION_FILE_PATH}
+    )
+endif()
 
 add_library(System.IO.Ports.Native-Static
     STATIC
@@ -15,5 +17,8 @@ add_library(System.IO.Ports.Native-Static
 
 set_target_properties(System.IO.Ports.Native-Static PROPERTIES OUTPUT_NAME System.IO.Ports.Native  CLEAN_DIRECT_OUTPUT 1)
 
-install_with_stripped_symbols (System.IO.Ports.Native PROGRAMS .)
-install (TARGETS System.IO.Ports.Native-Static DESTINATION .)
+if (GEN_SHARED_LIB)
+    install_with_stripped_symbols (System.IO.Ports.Native PROGRAMS .)
+endif()
+
+install (TARGETS System.IO.Ports.Native-Static DESTINATION ${STATIC_LIB_DESTINATION})
index 517628d..d41bb80 100644 (file)
@@ -53,23 +53,22 @@ elseif (CLR_CMAKE_TARGET_FREEBSD)
     endif ()
 endif ()
 
+include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake)
+
+set(NATIVE_LIBS_EXTRA)
+append_extra_system_libs(NATIVE_LIBS_EXTRA)
+
 if (GEN_SHARED_LIB)
     add_library(System.Native
         SHARED
         ${NATIVE_SOURCES}
         ${VERSION_FILE_PATH}
     )
-    if (CLR_CMAKE_TARGET_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID)
-        target_link_libraries(System.Native rt)
-    elseif (CLR_CMAKE_TARGET_FREEBSD)
-        target_link_libraries(System.Native pthread)
-        if (HAVE_INOTIFY)
-            find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib)
-            target_link_libraries(System.Native ${INOTIFY_LIBRARY})
-        endif ()
-    elseif (CLR_CMAKE_TARGET_SUNOS)
-        target_link_libraries(System.Native socket)
-    endif ()
+
+    target_link_libraries(System.Native
+        ${NATIVE_LIBS_EXTRA}
+    )
+
     install_with_stripped_symbols (System.Native PROGRAMS .)
 endif ()
 
@@ -78,10 +77,6 @@ add_library(System.Native-Static
     ${NATIVE_SOURCES}
 )
 
-if (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
-    target_link_libraries(System.Native "-framework Foundation")
-endif ()
-
 set_target_properties(System.Native-Static PROPERTIES OUTPUT_NAME System.Native CLEAN_DIRECT_OUTPUT 1)
 
-install (TARGETS System.Native-Static DESTINATION .)
+install (TARGETS System.Native-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/libraries/Native/Unix/System.Native/extra_libs.cmake b/src/libraries/Native/Unix/System.Native/extra_libs.cmake
new file mode 100644 (file)
index 0000000..b0cb4c1
--- /dev/null
@@ -0,0 +1,18 @@
+
+macro(append_extra_system_libs NativeLibsExtra)   
+    if (CLR_CMAKE_TARGET_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID)
+        list(APPEND ${NativeLibsExtra} rt)
+    elseif (CLR_CMAKE_TARGET_FREEBSD)
+        list(APPEND ${NativeLibsExtra} pthread)
+        if (HAVE_INOTIFY)
+            find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib)
+            list(APPEND ${NativeLibsExtra} ${INOTIFY_LIBRARY})
+        endif ()
+    elseif (CLR_CMAKE_TARGET_SUNOS)
+        list(APPEND ${NativeLibsExtra} socket)
+    endif ()
+    
+    if (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
+        list(APPEND ${NativeLibsExtra} "-framework Foundation")
+    endif ()
+endmacro()
index 6514f0e..bdc1678 100644 (file)
@@ -2,34 +2,22 @@ project(System.Net.Security.Native C)
 
 add_compile_options(-Wno-incompatible-pointer-types-discards-qualifiers)
 
-if (HAVE_GSSFW_HEADERS)
-   find_library(LIBGSS NAMES GSS)
-   if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
-      message(FATAL_ERROR "Cannot find GSS.Framework and System.Net.Security.Native cannot build without it. Try installing GSS.Framework (or the appropriate package for your platform)")
-   endif()
-elseif(HAVE_HEIMDAL_HEADERS)
-   find_library(LIBGSS NAMES gssapi)
-   if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
-      message(FATAL_ERROR "Cannot find libgssapi and System.Net.Security.Native cannot build without it. Try installing heimdal (or the appropriate package for your platform)")
-   endif()
-elseif(HeimdalGssApi)
-     message(FATAL_ERROR "HeimdalGssApi option was set but gssapi headers could not be found and System.Net.Security.Native cannot build without the headers. Try installing heimdal (or the appropriate package for your platform)")
-else()
-   find_library(LIBGSS NAMES gssapi_krb5)
-   if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
-      message(FATAL_ERROR "Cannot find libgssapi_krb5 and System.Net.Security.Native cannot build without it. Try installing libkrb5-dev (or the appropriate package for your platform)")
-   endif()
-endif()
+include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake)
+
+set(NATIVE_LIBS_EXTRA)
+append_extra_security_libs(NATIVE_LIBS_EXTRA)
 
 set(NATIVEGSS_SOURCES
     pal_gssapi.c
 )
 
-add_library(System.Net.Security.Native
-    SHARED
-    ${NATIVEGSS_SOURCES}
-    ${VERSION_FILE_PATH}
-)
+if (GEN_SHARED_LIB)
+    add_library(System.Net.Security.Native
+        SHARED
+        ${NATIVEGSS_SOURCES}
+        ${VERSION_FILE_PATH}
+    )
+endif()
 
 add_library(System.Net.Security.Native-Static
     STATIC
@@ -38,9 +26,12 @@ add_library(System.Net.Security.Native-Static
 
 set_target_properties(System.Net.Security.Native-Static PROPERTIES OUTPUT_NAME System.Net.Security.Native CLEAN_DIRECT_OUTPUT 1)
 
-target_link_libraries(System.Net.Security.Native
-    ${LIBGSS}
-)
+if (GEN_SHARED_LIB)
+    target_link_libraries(System.Net.Security.Native
+        ${NATIVE_LIBS_EXTRA}
+    )
+
+    install_with_stripped_symbols (System.Net.Security.Native PROGRAMS .)
+endif()
 
-install_with_stripped_symbols (System.Net.Security.Native PROGRAMS .)
-install (TARGETS System.Net.Security.Native-Static DESTINATION .)
+install (TARGETS System.Net.Security.Native-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake b/src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake
new file mode 100644 (file)
index 0000000..49c6ff4
--- /dev/null
@@ -0,0 +1,23 @@
+
+macro(append_extra_security_libs NativeLibsExtra)
+  if (HAVE_GSSFW_HEADERS)
+     find_library(LIBGSS NAMES GSS)
+     if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
+        message(FATAL_ERROR "Cannot find GSS.Framework and System.Net.Security.Native cannot build without it. Try installing GSS.Framework (or the appropriate package for your platform)")
+     endif()
+  elseif(HAVE_HEIMDAL_HEADERS)
+     find_library(LIBGSS NAMES gssapi)
+     if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
+        message(FATAL_ERROR "Cannot find libgssapi and System.Net.Security.Native cannot build without it. Try installing heimdal (or the appropriate package for your platform)")
+     endif()
+  elseif(HeimdalGssApi)
+       message(FATAL_ERROR "HeimdalGssApi option was set but gssapi headers could not be found and System.Net.Security.Native cannot build without the headers. Try installing heimdal (or the appropriate package for your platform)")
+  else()
+     find_library(LIBGSS NAMES gssapi_krb5)
+     if(LIBGSS STREQUAL LIBGSS-NOTFOUND)
+        message(FATAL_ERROR "Cannot find libgssapi_krb5 and System.Net.Security.Native cannot build without it. Try installing libkrb5-dev (or the appropriate package for your platform)")
+     endif()
+  endif()
+
+  list(APPEND ${NativeLibsExtra} ${LIBGSS})
+endmacro()
index cd7ff85..5c1fe55 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 #pragma once
+#include "pal_config.h"
 #include "pal_compiler.h"
 
 #if HAVE_GSSFW_HEADERS || HAVE_HEIMDAL_HEADERS
index 5a424ab..d8e985d 100644 (file)
@@ -29,11 +29,13 @@ if (CLR_CMAKE_TARGET_TVOS)
     add_definitions(-DTARGET_TVOS)
 endif()
 
-add_library(System.Security.Cryptography.Native.Apple
-    SHARED
-    ${NATIVECRYPTO_SOURCES}
-    ${VERSION_FILE_PATH}
-)
+if (GEN_SHARED_LIB)
+    add_library(System.Security.Cryptography.Native.Apple
+        SHARED
+        ${NATIVECRYPTO_SOURCES}
+        ${VERSION_FILE_PATH}
+    )
+endif()
 
 add_library(System.Security.Cryptography.Native.Apple-Static
     STATIC
@@ -42,10 +44,15 @@ add_library(System.Security.Cryptography.Native.Apple-Static
 
 set_target_properties(System.Security.Cryptography.Native.Apple-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.Apple CLEAN_DIRECT_OUTPUT 1)
 
-target_link_libraries(System.Security.Cryptography.Native.Apple
-    ${COREFOUNDATION_LIBRARY}
-    ${SECURITY_LIBRARY}
-)
+if (GEN_SHARED_LIB)
+    target_link_libraries(System.Security.Cryptography.Native.Apple
+        ${COREFOUNDATION_LIBRARY}
+        ${SECURITY_LIBRARY}
+    )
+endif()
+
+if (GEN_SHARED_LIB)
+    install_with_stripped_symbols (System.Security.Cryptography.Native.Apple PROGRAMS .)
+endif()
 
-install_with_stripped_symbols (System.Security.Cryptography.Native.Apple PROGRAMS .)
-install (TARGETS System.Security.Cryptography.Native.Apple-Static DESTINATION .)
+install (TARGETS System.Security.Cryptography.Native.Apple-Static DESTINATION ${STATIC_LIB_DESTINATION})
index e59120b..2ca4f23 100644 (file)
@@ -8,34 +8,10 @@ add_compile_options(-Wno-used-but-marked-unused)
 
 add_definitions(-DOPENSSL_API_COMPAT=0x10100000L)
 
-if(CMAKE_STATIC_LIB_LINK)
-   set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
-endif(CMAKE_STATIC_LIB_LINK)
-
-if(CLR_CMAKE_TARGET_ANDROID AND NOT CROSS_ROOTFS)
-    # TEMP: consume OpenSSL dependencies from external sources via env. variables
-    set(OPENSSL_FOUND 1)
-    set(OPENSSL_INCLUDE_DIR $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/include)
-    if(CLR_CMAKE_TARGET_ARCH_ARM64)
-        set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.arm64-v8a/libcrypto.so)
-        set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.arm64-v8a/libssl.so)
-    elseif(CLR_CMAKE_TARGET_ARCH_ARM)
-        set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.armeabi-v7a/libcrypto.so)
-        set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.armeabi-v7a/libssl.so)
-    elseif(CLR_CMAKE_TARGET_ARCH_I386)
-        set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.x86/libcrypto.so)
-        set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.x86/libssl.so)
-    else()
-        set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.x86_64/libcrypto.so)
-        set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.x86_64/libssl.so)
-    endif()
-else()
-    find_package(OpenSSL)
-endif()
+include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake)
 
-if(NOT OPENSSL_FOUND)
-    message(FATAL_ERROR "!!! Cannot find libssl and System.Security.Cryptography.Native cannot build without it. Try installing libssl-dev (on Linux, but this may vary by distro) or openssl (on macOS) !!!. See the requirements document for your specific operating system: https://github.com/dotnet/runtime/tree/master/docs/workflow/requirements.")
-endif(NOT OPENSSL_FOUND)
+set(NATIVE_LIBS_EXTRA)
+append_extra_cryptography_libs(NATIVE_LIBS_EXTRA)
 
 include_directories(${OPENSSL_INCLUDE_DIR})
 
@@ -84,10 +60,12 @@ endif()
 
 add_library(objlib OBJECT ${NATIVECRYPTO_SOURCES} ${VERSION_FILE_PATH})
 
-add_library(System.Security.Cryptography.Native.OpenSsl
-    SHARED
-    $<TARGET_OBJECTS:objlib>
-)
+if (GEN_SHARED_LIB)
+    add_library(System.Security.Cryptography.Native.OpenSsl
+        SHARED
+        $<TARGET_OBJECTS:objlib>
+    )
+endif()
 
 add_library(System.Security.Cryptography.Native.OpenSsl-Static
     STATIC
@@ -96,34 +74,33 @@ add_library(System.Security.Cryptography.Native.OpenSsl-Static
 
 set_target_properties(System.Security.Cryptography.Native.OpenSsl-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.OpenSsl CLEAN_DIRECT_OUTPUT 1)
 
-if (FEATURE_DISTRO_AGNOSTIC_SSL)
-    # on macOS the link step fails with undefined symbols, and the script doesn't run.
-    # if the build succeeds, the script would succeed, except it uses a Linux-only command.
-    #
-    # on Linux, the build will succeed with undefined symbols, then the script reports them
-    # and fails the build for us.
-    if (NOT APPLE)
-        add_custom_command(TARGET System.Security.Cryptography.Native.OpenSsl POST_BUILD
-            COMMENT "Verifying System.Security.Cryptography.Native.OpenSsl.so dependencies"
-            COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-so.sh
-                $<TARGET_FILE:System.Security.Cryptography.Native.OpenSsl>
-                "Verification failed. System.Security.Cryptography.Native.OpenSsl.so has undefined dependencies. These are likely OpenSSL APIs that need to be added to opensslshim.h"
-            VERBATIM
-        )
+if (GEN_SHARED_LIB)
+    if (FEATURE_DISTRO_AGNOSTIC_SSL)
+        # on macOS the link step fails with undefined symbols, and the script doesn't run.
+        # if the build succeeds, the script would succeed, except it uses a Linux-only command.
+        #
+        # on Linux, the build will succeed with undefined symbols, then the script reports them
+        # and fails the build for us.
+        if (NOT APPLE)
+            add_custom_command(TARGET System.Security.Cryptography.Native.OpenSsl POST_BUILD
+                COMMENT "Verifying System.Security.Cryptography.Native.OpenSsl.so dependencies"
+                COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-so.sh
+                    $<TARGET_FILE:System.Security.Cryptography.Native.OpenSsl>
+                    "Verification failed. System.Security.Cryptography.Native.OpenSsl.so has undefined dependencies. These are likely OpenSSL APIs that need to be added to opensslshim.h"
+                VERBATIM
+            )
+        endif()
     endif()
 
-    # Link with libdl.so to get the dlopen / dlsym / dlclose
-    target_link_libraries(System.Security.Cryptography.Native.OpenSsl
-      dl
-    )
-else()
     target_link_libraries(System.Security.Cryptography.Native.OpenSsl
-      ${OPENSSL_CRYPTO_LIBRARY}
-      ${OPENSSL_SSL_LIBRARY}
+        ${NATIVE_LIBS_EXTRA}
     )
 endif()
 
 include(configure.cmake)
 
-install_with_stripped_symbols (System.Security.Cryptography.Native.OpenSsl PROGRAMS .)
-install (TARGETS System.Security.Cryptography.Native.OpenSsl-Static DESTINATION .)
+if (GEN_SHARED_LIB)
+    install_with_stripped_symbols (System.Security.Cryptography.Native.OpenSsl PROGRAMS .)
+endif()
+
+install (TARGETS System.Security.Cryptography.Native.OpenSsl-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake b/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake
new file mode 100644 (file)
index 0000000..9d7521f
--- /dev/null
@@ -0,0 +1,39 @@
+
+macro(append_extra_cryptography_libs NativeLibsExtra)
+    if(CMAKE_STATIC_LIB_LINK)
+       set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
+    endif(CMAKE_STATIC_LIB_LINK)
+    
+    if(CLR_CMAKE_TARGET_ANDROID AND NOT CROSS_ROOTFS)
+        # TEMP: consume OpenSSL dependencies from external sources via env. variables
+        set(OPENSSL_FOUND 1)
+        set(OPENSSL_INCLUDE_DIR $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/include)
+        if(CLR_CMAKE_TARGET_ARCH_ARM64)
+            set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.arm64-v8a/libcrypto.so)
+            set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.arm64-v8a/libssl.so)
+        elseif(CLR_CMAKE_TARGET_ARCH_ARM)
+            set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.armeabi-v7a/libcrypto.so)
+            set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.armeabi-v7a/libssl.so)
+        elseif(CLR_CMAKE_TARGET_ARCH_I386)
+            set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.x86/libcrypto.so)
+            set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.x86/libssl.so)
+        else()
+            set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.x86_64/libcrypto.so)
+            set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.x86_64/libssl.so)
+        endif()
+    else()
+        find_package(OpenSSL)
+    endif()
+    
+    if(NOT OPENSSL_FOUND)
+        message(FATAL_ERROR "!!! Cannot find libssl and System.Security.Cryptography.Native cannot build without it. Try installing libssl-dev (on Linux, but this may vary by distro) or openssl (on macOS) !!!. See the requirements document for your specific operating system: https://github.com/dotnet/runtime/tree/master/docs/workflow/requirements.")
+    endif(NOT OPENSSL_FOUND)
+    
+    
+    if (FEATURE_DISTRO_AGNOSTIC_SSL)
+        # Link with libdl.so to get the dlopen / dlsym / dlclose
+        list(APPEND ${NativeLibsExtra} dl)
+    else()
+        list(APPEND ${NativeLibsExtra} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
+    endif()
+endmacro()
diff --git a/src/libraries/Native/Unix/tryrun.cmake b/src/libraries/Native/Unix/tryrun.cmake
deleted file mode 100644 (file)
index adb1862..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH})
-set(CROSS_ROOTFS $ENV{ROOTFS_DIR})
-
-macro(set_cache_value)
-  set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE)
-  set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE)
-endmacro()
-
-if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv7-alpine-linux-musleabihf OR
-   EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf OR
-   EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl)
-
-  set(ALPINE_LINUX 1)
-elseif(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version)
-  set(FREEBSD 1)
-  set(CMAKE_SYSTEM_NAME FreeBSD)
-  set(CLR_CMAKE_TARGET_OS FreeBSD)
-elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc)
-  set(ILLUMOS 1)
-  set(CLR_CMAKE_TARGET_OS SunOS)
-endif()
-
-if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$" OR FREEBSD OR ILLUMOS)
-  set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
-  set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
-
-  if(ALPINE_LINUX)
-    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1)
-  else()
-    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 0)
-  endif()
-
-  if(FREEBSD)
-    set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP 1)
-    set_cache_value(HAVE_CLOCK_MONOTONIC 1)
-    set_cache_value(HAVE_CLOCK_REALTIME 1)
-  elseif(ILLUMOS)
-    set_cache_value(HAVE_SET_MAX_VARIABLE 1)
-  endif()
-else()
-  message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!")
-endif()
index 6343b3f..1f3ac2b 100644 (file)
@@ -23,6 +23,17 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
     message(FATAL_ERROR "Binary directory isn't being correctly set before calling Cmake. Tree must be built in separate directory from source.")
 endif()
 
+if(STATIC_LIBS_ONLY)
+    # Suppress exporting of the PAL APIs
+    add_definitions(-DPALEXPORT=EXTERN_C)
+
+    set(GEN_SHARED_LIB 0)
+    set(STATIC_LIB_DESTINATION lib)
+else()
+    set(GEN_SHARED_LIB 1)
+    set(STATIC_LIB_DESTINATION .)
+endif()
+
 project(CoreFX)
 
 # The following options are set by the razzle build
@@ -113,4 +124,9 @@ endif ()
 # as other asserts should still be included.
 add_compile_definitions($<$<CONFIG:RELEASE>:NDEBUG>)
 
+# we only need to build System.Globalization.Native when building static libs.
+if(STATIC_LIBS_ONLY)
+    add_subdirectory(../Unix/System.Globalization.Native System.Globalization.Native)
+endif()
+
 add_subdirectory(clrcompression)
index 5ac67d5..9566e38 100644 (file)
@@ -5,7 +5,10 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
 endif()
 
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
-include (GenerateExportHeader)
+
+if (GEN_SHARED_LIB)
+    include (GenerateExportHeader)
+endif()
 
 if($ENV{__BuildArch} STREQUAL x86 OR $ENV{__BuildArch} STREQUAL x64)
     set(NATIVECOMPRESSION_SOURCES
@@ -71,18 +74,21 @@ set (NATIVECOMPRESSION_SOURCES
     ../../AnyOS/brotli/enc/metablock.c
     ../../AnyOS/brotli/enc/static_dict.c
     ../../AnyOS/brotli/enc/utf8_util.c
-    clrcompression.def
+    ../../AnyOS/System.IO.Compression.Native/entrypoints.c
 )
 
 #Include Brotli include files
 include_directories("../../AnyOS/brotli/include")
 
-add_library(clrcompression
-    SHARED
-    ${NATIVECOMPRESSION_SOURCES}
-    # This will add versioning to the library
-    ${CMAKE_REPO_ROOT}/artifacts/obj/NativeVersion.rc
-)
+if (GEN_SHARED_LIB)
+    add_library(clrcompression
+        SHARED
+        ${NATIVECOMPRESSION_SOURCES}
+        clrcompression.def
+        # This will add versioning to the library
+        ${CMAKE_REPO_ROOT}/artifacts/obj/NativeVersion.rc
+    )
+endif()
 
 add_library(clrcompression-static
     STATIC
@@ -93,21 +99,28 @@ SET_TARGET_PROPERTIES(clrcompression-static PROPERTIES PREFIX "")
 SET_TARGET_PROPERTIES(clrcompression-static PROPERTIES OUTPUT_NAME libclrcompression)
 
 # Allow specification of arguments that should be passed to the linker
-SET_TARGET_PROPERTIES(clrcompression PROPERTIES LINK_OPTIONS "${__LinkArgs};${__SharedLinkArgs}")
+if (GEN_SHARED_LIB)
+    SET_TARGET_PROPERTIES(clrcompression PROPERTIES LINK_OPTIONS "${__LinkArgs};${__SharedLinkArgs}")
+endif()
 SET_TARGET_PROPERTIES(clrcompression-static PROPERTIES STATIC_LIBRARY_OPTIONS "${__LinkArgs}")
 
 # Allow specification of libraries that should be linked against
-target_link_libraries(clrcompression ${__LinkLibraries})
+if (GEN_SHARED_LIB)
+    target_link_libraries(clrcompression ${__LinkLibraries})
+endif()
 target_link_libraries(clrcompression-static ${__LinkLibraries})
 
-GENERATE_EXPORT_HEADER( clrcompression
-     BASE_NAME clrcompression
-     EXPORT_MACRO_NAME clrcompression_EXPORT
-     EXPORT_FILE_NAME clrcompression_Export.h
-     STATIC_DEFINE clrcompression_BUILT_AS_STATIC
-)
+if (GEN_SHARED_LIB)
+    GENERATE_EXPORT_HEADER( clrcompression
+         BASE_NAME clrcompression
+         EXPORT_MACRO_NAME clrcompression_EXPORT
+         EXPORT_FILE_NAME clrcompression_Export.h
+         STATIC_DEFINE clrcompression_BUILT_AS_STATIC
+    )
+
+    install (TARGETS clrcompression DESTINATION .)
+    install (FILES $<TARGET_PDB_FILE:clrcompression> DESTINATION .)
+endif()
 
-install (TARGETS clrcompression DESTINATION .)
-install (TARGETS clrcompression-static DESTINATION .)
-install (FILES $<TARGET_PDB_FILE:clrcompression> DESTINATION .)
+install (TARGETS clrcompression-static DESTINATION ${STATIC_LIB_DESTINATION})
 
index 2aaa9fe..0dc7c80 100755 (executable)
@@ -157,4 +157,4 @@ setup_dirs
 check_prereqs
 
 # Build the corefx native components.
-build_native "$__TargetOS" "$__BuildArch" "$__nativeroot" "$__nativeroot" "$__IntermediatesDir" "$__CMakeArgs" "native libraries component"
+build_native "$__TargetOS" "$__BuildArch" "$__nativeroot" "$__IntermediatesDir" "$__CMakeArgs" "native libraries component"
index c4e1def..232b2df 100644 (file)
@@ -12,8 +12,6 @@
 #include "mono/utils/mono-path.h"
 #include "mono/metadata/native-library.h"
 
-extern const void* gPalGlobalizationNative[];
-
 enum {
     func_flag_end_of_array = 0x01,
     func_flag_has_signature = 0x02,
@@ -21,10 +19,6 @@ enum {
     func_flag_qcall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
 };
 
-#if defined(NO_GLOBALIZATION_SHIM) || !defined(ENABLE_NETCORE)
-const void* gPalGlobalizationNative[] = { (void*)func_flag_end_of_array };
-#endif
-
 static const MonoQCallDef c_qcalls[] =
 {
 #ifndef DISABLE_QCALLS
index 2176315..0003bcf 100644 (file)
@@ -49,6 +49,10 @@ static GHashTable *native_library_module_map;
 static GHashTable *native_library_module_blocklist;
 #endif
 
+#if defined(ENABLE_NETCORE) && !defined(NO_GLOBALIZATION_SHIM)
+extern const void *GlobalizationResolveDllImport (const char *name);
+#endif
+
 #ifndef DISABLE_DLLMAP
 static MonoDllMap *global_dll_map;
 #endif
@@ -1256,6 +1260,20 @@ legacy_lookup_native_library (MonoImage *image, const char *scope)
 
 #endif // ENABLE_NETCORE
 
+#if defined(ENABLE_NETCORE) && !defined(NO_GLOBALIZATION_SHIM)
+static gpointer
+default_resolve_dllimport (const char *dll, const char *func)
+{
+       if (strcmp (dll, "libSystem.Globalization.Native") == 0) {
+               const void *method_impl = GlobalizationResolveDllImport (func);
+               if (method_impl)
+                       return (gpointer)method_impl;
+       }
+
+       return NULL;
+}
+#endif
+
 gpointer
 lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_out)
 {
@@ -1336,6 +1354,12 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
        }
 #endif
 
+#if defined(ENABLE_NETCORE) && !defined(NO_GLOBALIZATION_SHIM)
+       gpointer default_override = default_resolve_dllimport (new_scope, new_import);
+       if (default_override)
+               return default_override;
+#endif
+
 #ifdef ENABLE_NETCORE
 #ifndef HOST_WIN32
 retry_with_libcoreclr:
index 1e83108..7341edd 100644 (file)
@@ -12,4 +12,4 @@
  * have to end with a func_flag_end_of_array (0x01) entry.
  **/
 
-FCClassElement("Globalization", "", gPalGlobalizationNative)
+FCClassElement("", "", NULL)
index 035c141..896fefd 100644 (file)
@@ -35,7 +35,7 @@
     <ItemGroup>
       <WasmPInvokeModule Include="libSystem.Native" />
       <WasmPInvokeModule Include="libSystem.IO.Compression.Native" />
-      <WasmPInvokeModule Include="QCall" />
+      <WasmPInvokeModule Include="libSystem.Globalization.Native" />
       <WasmPInvokeAssembly Include="@(LibrariesRuntimeFiles)" Condition="'%(Extension)' == '.dll' and '%(IsNative)' != 'true'" />
     </ItemGroup>
 
index a1efe50..0955a4a 100755 (executable)
@@ -279,7 +279,7 @@ build_Tests()
     fi
 
     if [[ "$__SkipNative" != 1 && "$__TargetOS" != "Browser" && "$__TargetOS" != "Android" ]]; then
-        build_native "$__TargetOS" "$__BuildArch" "$__TestDir" "$__TryRunDir" "$__NativeTestIntermediatesDir" "CoreCLR test component"
+        build_native "$__TargetOS" "$__BuildArch" "$__TestDir" "$__NativeTestIntermediatesDir" "CoreCLR test component"
 
         if [[ "$?" -ne 0 ]]; then
             echo "${__ErrMsgPrefix}${__MsgPrefix}Error: native test build failed. Refer to the build log files for details (above)"
@@ -605,7 +605,6 @@ __OSPlatformConfig="$__TargetOS.$__BuildArch.$__BuildType"
 __BinDir="$__RootBinDir/bin/coreclr/$__OSPlatformConfig"
 __PackagesBinDir="$__BinDir/.nuget"
 __TestDir="$__RepoRootDir/src/tests"
-__TryRunDir="$__RepoRootDir/src/coreclr"
 __TestWorkingDir="$__RootBinDir/tests/coreclr/$__OSPlatformConfig"
 __IntermediatesDir="$__RootBinDir/obj/coreclr/$__OSPlatformConfig"
 __TestIntermediatesDir="$__RootBinDir/tests/coreclr/obj/$__OSPlatformConfig"