diff --git a/Directory.Build.props b/Directory.Build.props index 3e494e19c3d9e..61edda987ed6d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -324,6 +324,7 @@ true ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;ClrDebugSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs;CxxStandardLibrary;CxxStandardLibraryStatic;CxxAbiLibrary + true diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 76c441de6f2f5..aedc482527300 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -12,6 +12,11 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# We need to set this to Release as there's no way to intercept configuration-specific linker flags +# for try_compile-style tests (like check_c_source_compiles) and some of the default Debug flags +# (ie. /INCREMENTAL) conflict with our own flags. +set(CMAKE_TRY_COMPILE_CONFIGURATION Release) + include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckLinkerFlag) @@ -58,6 +63,7 @@ if (MSVC) define_property(TARGET PROPERTY CLR_CONTROL_FLOW_GUARD INHERITED BRIEF_DOCS "Controls the /guard:cf flag presence" FULL_DOCS "Set this property to ON or OFF to indicate if the /guard:cf compiler and linker flag should be present") define_property(TARGET PROPERTY CLR_EH_CONTINUATION INHERITED BRIEF_DOCS "Controls the /guard:ehcont flag presence" FULL_DOCS "Set this property to ON or OFF to indicate if the /guard:ehcont compiler flag should be present") define_property(TARGET PROPERTY CLR_EH_OPTION INHERITED BRIEF_DOCS "Defines the value of the /EH option" FULL_DOCS "Set this property to one of the valid /EHxx options (/EHa, /EHsc, /EHa-, ...)") + define_property(TARGET PROPERTY MSVC_WARNING_LEVEL INHERITED BRIEF_DOCS "Define the warning level for the /Wn option" FULL_DOCS "Set this property to one of the valid /Wn options (/W0, /W1, /W2, /W3, /W4)") set_property(GLOBAL PROPERTY CLR_CONTROL_FLOW_GUARD ON) @@ -779,7 +785,8 @@ if (MSVC) # [[! Microsoft.Security.SystemsADM.10086 !]] - SDL required warnings # set default warning level to 4 but allow targets to override it. - add_compile_options($<$:/W$>,$,4>>>) + set_property(GLOBAL PROPERTY MSVC_WARNING_LEVEL 4) + add_compile_options($<$:/W$>) add_compile_options($<$:/WX>) # treat warnings as errors add_compile_options($<$:/Oi>) # enable intrinsics add_compile_options($<$:/Oy->) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 20851f8617423..1dfc2458d11e8 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -500,3 +500,9 @@ if(LOWERCASE_CMAKE_BUILD_TYPE STREQUAL debug) string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") endif() + +if (CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_HOST_ARCH_ARMV6) + # Our zlib-ng copy should only be used in non-mobile platforms only. + # In mobile platforms we should use the zlib package provided by the system. + set(CLR_CMAKE_USE_SYSTEM_ZLIB 1) +endif() diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 6629e926afacf..b1cb09d662043 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -221,7 +221,7 @@ function(preprocess_file inputFilename outputFilename) get_compile_definitions(PREPROCESS_DEFINITIONS) get_include_directories(PREPROCESS_INCLUDE_DIRECTORIES) get_source_file_property(SOURCE_FILE_DEFINITIONS ${inputFilename} COMPILE_DEFINITIONS) - + foreach(DEFINITION IN LISTS SOURCE_FILE_DEFINITIONS) list(APPEND PREPROCESS_DEFINITIONS -D${DEFINITION}) endforeach() @@ -508,7 +508,7 @@ function(install_static_library targetName destination component) if (WIN32) set_target_properties(${targetName} PROPERTIES COMPILE_PDB_NAME "${targetName}" - COMPILE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" + COMPILE_PDB_OUTPUT_DIRECTORY "$" ) install (FILES "$/${targetName}.pdb" DESTINATION ${destination} COMPONENT ${component}) endif() diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index d3dc85e04f82e..3ff044e94d9d2 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -24,6 +24,7 @@ The .NET Foundation licenses this file to you under the MIT license. lld bfd 1572864 + true @@ -129,6 +130,7 @@ The .NET Foundation licenses this file to you under the MIT license. + @@ -188,7 +190,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index 18c3c1f017a9f..603a255fc0ca0 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -46,6 +46,7 @@ The .NET Foundation licenses this file to you under the MIT license. + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 0de334e7ff211..70c526efac38c 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -277,6 +277,8 @@ + + diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index ba41fa4d9a489..fac1d9fb0e33c 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -249,7 +249,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "emscripten") set(DISABLE_SHARED_LIBS 1) # sys/random.h exists, but its not found set(HAVE_SYS_RANDOM_H 1) - set(INTERNAL_ZLIB 1) elseif(CLR_CMAKE_HOST_OS STREQUAL "wasi") set(HOST_WASI 1) add_definitions(-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -DHOST_WASI) @@ -261,7 +260,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "wasi") add_compile_options(-Wno-unused-but-set-variable) set(ENABLE_PERFTRACING 0) set(DISABLE_SHARED_LIBS 1) - set(INTERNAL_ZLIB 1) set(DISABLE_EXECUTABLES 1) set(STATIC_COMPONENTS 1) elseif(CLR_CMAKE_HOST_OS STREQUAL "windows") @@ -270,7 +268,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "windows") set(HOST_NO_SYMLINKS 1) set(MONO_KEYWORD_THREAD "__declspec (thread)") set(MONO_ZERO_LEN_ARRAY 1) - set(INTERNAL_ZLIB 1) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # statically link VC runtime library add_compile_options($<$:/W4>) # set warning level 4 add_compile_options($<$:/WX>) # treat warnings as errors @@ -511,16 +508,15 @@ if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64)) set(TARGET_APPLE_MOBILE 1) endif() -# Decide if we need zlib, and if so whether we want the system zlib or the in-tree copy. +# Decide if we need zlib-ng. if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ) - if(INTERNAL_ZLIB) - # defines ZLIB_SOURCES - include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake) - else() - # if we're not on a platform where we use the in-tree zlib, require system zlib + if (CLR_CMAKE_USE_SYSTEM_ZLIB) + # if we're not on a platform where we use the in-tree zlib-ng, require system zlib include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) set(Z_LIBS) append_extra_compression_libs(Z_LIBS) + else() + include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) endif() endif() @@ -664,12 +660,17 @@ if(LLVM_PREFIX) endif() set(llvm_includedir "${LLVM_PREFIX}/include") + set(llvm_system_libs "") if(HOST_LINUX) # llvm-config --system-libs - set(llvm_system_libs ${MONO_cxx_lib} "-lz" "-lrt" "-ldl" "-lpthread" "-lm") + list(APPEND llvm_system_libs ${MONO_cxx_lib} "-lrt" "-ldl" "-lpthread" "-lm") elseif(HOST_OSX) # llvm-config --system-libs - set(llvm_system_libs "-lz" "-lm") + list(APPEND llvm_system_libs "-lm") + endif() + + if (CLR_CMAKE_USE_SYSTEM_ZLIB AND (HOST_LINUX OR HOST_OSX)) + list(APPEND llvm_system_libs "-lz") endif() # llvm-config --libs analysis core bitwriter mcjit orcjit diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 81768d43e6a53..47a351fb53b41 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -63,6 +63,7 @@ + diff --git a/src/mono/browser/runtime/CMakeLists.txt b/src/mono/browser/runtime/CMakeLists.txt index 8b7939330f8c3..f707431fc38d5 100644 --- a/src/mono/browser/runtime/CMakeLists.txt +++ b/src/mono/browser/runtime/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries(dotnet.native ${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-aot.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-browser.a + ${MONO_ARTIFACTS_DIR}/libz.a ${NATIVE_BIN_DIR}/wasm-bundled-timezones.a ${NATIVE_BIN_DIR}/libSystem.Native.a ${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index e972500d1cd81..8ac0c0f7c3c29 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -168,9 +168,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UNWIND_H 1 -/* Use in-tree zlib */ -#cmakedefine INTERNAL_ZLIB 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_POLL_H 1 diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 14056eb3a7e24..ceb783599086e 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -1189,6 +1189,9 @@ JS_ENGINES = [NODE_JS] <_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-nosimd.a"> $(RuntimeBinDir)libmono-wasm-nosimd.a + <_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)_deps\fetchzlibng-build\libz.a"> + $(RuntimeBinDir)libz.a + <_MonoICorDebugArtifacts Condition="'$(MonoMsCorDbi)' == 'true'" Include="$(MonoObjDir)out\lib\$(LibPrefix)mscordbi$(LibSuffix)"> $(RuntimeBinDir)$(LibPrefix)mscordbi$(LibSuffix) diff --git a/src/mono/mono/eventpipe/test/CMakeLists.txt b/src/mono/mono/eventpipe/test/CMakeLists.txt index d313e630adaab..92ddfb3ce17f9 100644 --- a/src/mono/mono/eventpipe/test/CMakeLists.txt +++ b/src/mono/mono/eventpipe/test/CMakeLists.txt @@ -39,7 +39,16 @@ if(ENABLE_PERFTRACING) set(CMAKE_SKIP_RPATH 1) add_executable(ep-test ${EVENTPIPE_TEST_SOURCES} ${EVENTPIPE_TEST_HEADERS}) target_sources(ep-test PRIVATE "${mono-components-objects}") - target_link_libraries(ep-test PRIVATE eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS} monoapi) + + set(EPTEST_LINKABLE_LIBS "") + list(APPEND EPTEST_LINKABLE_LIBS eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} monoapi) + if (CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} ${Z_LIBS}) + else() + list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} zlib) + endif() + target_link_libraries(ep-test PRIVATE ${EPTEST_LINKABLE_LIBS}) + install_with_stripped_symbols(ep-test TARGETS bin) else(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES)) message(VERBOSE "Skip building native EventPipe library test runner.") diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 773381d6c1c9a..e3463b514d0c0 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -200,7 +200,14 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(metadata_objects_shared OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions}) - target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared) + + set(METADATAOBJECTSSHARED_LINKABLE_LIBS "") + list(APPEND METADATAOBJECTSSHARED_LINKABLE_LIBS monoapi eglib_api utils_objects_shared) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND METADATAOBJECTSSHARED_LINKABLE_LIBS zlib) + endif() + target_link_libraries(metadata_objects_shared PRIVATE ${METADATAOBJECTSSHARED_LINKABLE_LIBS}) + # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared) @@ -212,7 +219,14 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) -target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects) + +set(METADATAOBJECTS_LINKABLE_LIBS "") +list(APPEND METADATAOBJECTS_LINKABLE_LIBS monoapi eglib_api utils_objects) +if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND METADATAOBJECTS_LINKABLE_LIBS zlib) +endif() +target_link_libraries(metadata_objects PRIVATE ${METADATAOBJECTS_LINKABLE_LIBS}) + # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm target_link_libraries(metadata_objects PRIVATE sgen_objects) diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index bcbbb4c7f2be0..3ed40e9243dad 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -30,12 +30,8 @@ #include #ifndef DISABLE_EMBEDDED_PDB -#ifdef INTERNAL_ZLIB -#include -#else #include -#endif -#endif +#endif // DISABLE_EMBEDDED_PDB #include "debug-mono-ppdb.h" diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 93ff6c431ef03..af9987869f5ac 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -314,10 +314,7 @@ elseif(NOT HOST_BROWSER AND NOT HOST_WASI) set(mini_sources "${mini_sources};${VERSION_FILE_PATH}") # this is generated by GenerateNativeVersionFile in Arcade endif() -set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") -set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - -set(monosgen-sources "${mini_sources};${ZLIB_SOURCES}") +set(monosgen-sources "${mini_sources}") if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(monosgen-objects_shared OBJECT "${monosgen-sources}") @@ -326,7 +323,14 @@ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) endif() add_library(monosgen-objects OBJECT "${monosgen-sources}") -target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) + +set(MONOSGEN_OBJECTS_LINKABLE_LIBS "") +list(APPEND MONOSGEN_OBJECTS_LINKABLE_LIBS monoapi eglib_api utils_objects sgen_objects metadata_objects) +if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND MONOSGEN_OBJECTS_LINKABLE_LIBS zlib) +endif() +target_link_libraries (monosgen-objects PRIVATE ${MONOSGEN_OBJECTS_LINKABLE_LIBS}) + if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() @@ -353,15 +357,23 @@ if(NOT DISABLE_SHARED_LIBS) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) target_link_libraries(monosgen-shared PRIVATE ucontext) - endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) + endif() set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}) if(MONO_SET_RPATH_ORIGIN) set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN") endif() + + set(MONOSGENSHARED_LINKABLE_LIBS "") + list(APPEND MONOSGENSHARED_LINKABLE_LIBS monoapi eglib_objects dn-containers) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) + endif() if(HOST_WIN32) - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared) + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) else() - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects) + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) endif() target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) @@ -369,11 +381,16 @@ if(NOT DISABLE_SHARED_LIBS) # to avoid a conflict we rename the import library with the .import.lib suffix set_target_properties(monosgen-shared PROPERTIES IMPORT_SUFFIX ".import.lib") endif() - if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + + set(MONOSGENSHARED_LINKABLE_EXTRALIBS "") + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) + if (CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS ${Z_LIBS}) else() - target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS zlib) endif() + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_EXTRALIBS}) + if(TARGET_DARWIN) set_property(TARGET monosgen-shared APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") endif() @@ -417,8 +434,22 @@ if(NOT DISABLE_SHARED_LIBS) endif() add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) - target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + + set(FRAMEWORKCONFIG_LINKABLE_LIBS "") + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS zlib) + endif() + target_link_libraries(${frameworkconfig} PRIVATE ${FRAMEWORKCONFIG_LINKABLE_LIBS}) + + set(FRAMEWORKCONFIG_LINKABLE_EXTRALIBS "") + list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS zlib) + else() + list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS ${Z_LIBS}) + endif() + target_link_libraries(${frameworkconfig} PRIVATE ${FRAMEWORKCONFIG_LINKABLE_EXTRALIBS}) set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") string(REPLACE "*" ";" componentsobjects-whitespace "${componentsobjects}") @@ -534,11 +565,27 @@ if(NOT DISABLE_EXECUTABLES) set_target_properties(mono-sgen PROPERTIES INSTALL_RPATH "$ORIGIN") endif() endif() - target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers) + + set(MONOSGEN_LINKABLE_LIBS "") + list(APPEND MONOSGEN_LINKABLE_LIBS monoapi eglib_api monosgen-static dn-containers) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND MONOSGEN_LINKABLE_LIBS zlib) + endif() + target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_LIBS}) + if (HOST_WASM) target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) endif() - target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + + set(MONOSGEN_LINKABLE_EXTRALIBS "") + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) + if (CLR_CMAKE_USE_SYSTEM_ZLIB) + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS ${Z_LIBS}) + else() + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS zlib) + endif() + target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_EXTRALIBS}) + # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) target_link_libraries(mono-sgen PRIVATE ucontext) diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 511c19dbe5a32..e172774a6ebc5 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -12,9 +12,7 @@ include_directories( if(NOT DISABLE_LIBS) if(HOST_ANDROID OR HOST_IOS OR HOST_TVOS OR HOST_S390X) # Build the logging profiler only for certain platforms - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - add_library(mono-profiler-log SHARED helper.c log.c log-args.c ${ZLIB_SOURCES}) + add_library(mono-profiler-log SHARED helper.c log.c log-args.c) target_compile_definitions(mono-profiler-log PRIVATE -DMONO_DLL_EXPORT) target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects) if(HOST_ANDROID) @@ -28,7 +26,11 @@ if(NOT DISABLE_LIBS) install(TARGETS mono-profiler-log-static LIBRARY) if(NOT DISABLE_LOG_PROFILER_GZ) - target_link_libraries(mono-profiler-log PRIVATE ${Z_LIBS}) + if (CLR_CMAKE_USE_SYSTEM_ZLIB) + target_link_libraries(mono-profiler-log PRIVATE ${Z_LIBS}) + else() + target_link_libraries(mono-profiler-log PRIVATE zlib) + endif() endif() endif() diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index 9d4304faae3ec..abe5f3f479f57 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -72,12 +72,8 @@ #include #endif #ifndef DISABLE_LOG_PROFILER_GZ -#ifdef INTERNAL_ZLIB -#include -#else #include -#endif -#endif +#endif // DISABLE_LOG_PROFILER_GZ #ifdef HOST_WIN32 #include diff --git a/src/mono/mono/profiler/mprof-report.c b/src/mono/mono/profiler/mprof-report.c index 35c88fe0a2fd9..5e2cc5ad7a20e 100644 --- a/src/mono/mono/profiler/mprof-report.c +++ b/src/mono/mono/profiler/mprof-report.c @@ -23,12 +23,8 @@ #endif #include #ifndef DISABLE_LOG_PROFILER_GZ -#ifdef INTERNAL_ZLIB -#include -#else #include -#endif -#endif +#endif // DISABLE_LOG_PROFILER_GZ #include #include #include diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 35d0f16c35b4b..483ae04924a72 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -6,6 +6,7 @@ false <_ProcessRuntimeComponentsForLibraryMode Condition="'$(_IsLibraryMode)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">_ProcessRuntimeComponentsForLibraryMode false + true - <_CommonLinkerArgs Include="-lz" /> + <_CommonLinkerArgs Include="-lz" Condition="'$(UseSystemZlib)' == 'true'" /> <_CommonLinkerArgs Include="-lc++" /> <_CommonLinkerArgs Include="-liconv" /> <_CommonLinkerArgs Include="-licucore" /> diff --git a/src/mono/wasi/runtime/CMakeLists.txt b/src/mono/wasi/runtime/CMakeLists.txt index 1d2a220494779..ec45f3aa2e488 100644 --- a/src/mono/wasi/runtime/CMakeLists.txt +++ b/src/mono/wasi/runtime/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries(dotnet ${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a ${MONO_ARTIFACTS_DIR}/libmono-icall-table.a ${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a + ${MONO_ARTIFACTS_DIR}/libz.a ${NATIVE_BIN_DIR}/wasm-bundled-timezones.a ${NATIVE_BIN_DIR}/libSystem.Native.a ${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj index 9c386481a26e1..99bf8a6ee54f8 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -49,6 +49,7 @@ + diff --git a/src/native/external/zlib-intel.cmake b/src/native/external/zlib-intel.cmake deleted file mode 100644 index a664f154dbef0..0000000000000 --- a/src/native/external/zlib-intel.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects - -set(ZLIB_SOURCES_BASE - adler32.c - compress.c - crc_folding.c - crc32.c - deflate_medium.c - deflate_quick.c - deflate.c - inffast.c - inflate.c - inftrees.c - match.c - slide_sse.c - trees.c - x86.c - zutil.c - ../../libs/System.IO.Compression.Native/zlib_allocator_win.c -) - -addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib-intel" "${ZLIB_SOURCES_BASE}") - -# enable custom zlib allocator -set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") - -if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) - set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") -endif() diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake new file mode 100644 index 0000000000000..3f005eaa54f3d --- /dev/null +++ b/src/native/external/zlib-ng.cmake @@ -0,0 +1,33 @@ +include(FetchContent) + +FetchContent_Declare( + fetchzlibng + SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/zlib-ng") + +set(ZLIB_COMPAT ON) +set(ZLIB_ENABLE_TESTS OFF) +set(ZLIBNG_ENABLE_TESTS OFF) +set(Z_PREFIX ON) + +add_compile_options($<$:-Wno-unused-command-line-argument>) # clang : error : argument unused during compilation: '-fno-semantic-interposition' +add_compile_options($<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning +add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant +add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files +add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files + +# 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt. +if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) + set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE) +endif() + +set(BUILD_SHARED_LIBS OFF) # Shared libraries aren't supported in wasm +set(SKIP_INSTALL_ALL ON) +FetchContent_MakeAvailable(fetchzlibng) +set(SKIP_INSTALL_ALL OFF) + +set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/zlib-ng PROPERTY MSVC_WARNING_LEVEL 3) # Set the MSVC warning level for all zlib-ng targets to 3. +target_compile_options(zlib PRIVATE $<$:-Wno-unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments +target_compile_options(zlib PRIVATE $<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning +target_compile_options(zlib PRIVATE $<$:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors. + +set_target_properties(zlib PROPERTIES DEBUG_POSTFIX "") # Workaround: zlib's debug lib name is zlibd.lib diff --git a/src/native/external/zlib.cmake b/src/native/external/zlib.cmake deleted file mode 100644 index 498ec977960e0..0000000000000 --- a/src/native/external/zlib.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects - -set(ZLIB_SOURCES_BASE - adler32.c - compress.c - crc32.c - uncompr.c - deflate.c - gzguts.h - trees.c - zutil.c - inflate.c - infback.c - inftrees.c - inffast.c - crc32.h - deflate.h - inffast.h - inffixed.h - inflate.h - inftrees.h - trees.h - zconf.h - zlib.h - zutil.h -) - -if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) - set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_win.c) -else() - set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_unix.c) -endif() - -addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib" "${ZLIB_SOURCES_BASE}") - -# enable custom zlib allocator -set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") - -if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) - set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") -endif() diff --git a/src/native/libs/Common/pal_utilities.h b/src/native/libs/Common/pal_utilities.h index 7b5fa63b6cac0..a1a57c8ed0e8c 100644 --- a/src/native/libs/Common/pal_utilities.h +++ b/src/native/libs/Common/pal_utilities.h @@ -12,7 +12,9 @@ #include #include #include -#include +#ifndef _WIN32 + #include +#endif #include #include @@ -69,6 +71,7 @@ inline static int ToFileDescriptorUnchecked(intptr_t fd) return (int)fd; } +#ifndef _WIN32 /** * Converts an intptr_t to a file descriptor. * intptr_t is the type used to marshal file descriptors so we can use SafeHandles effectively. @@ -86,6 +89,7 @@ static inline bool CheckInterrupted(ssize_t result) { return result < 0 && errno == EINTR; } +#endif inline static uint32_t Int32ToUint32(int32_t value) { diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index 089363cf5554e..69d333ae53f9c 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -2,10 +2,24 @@ project(System.IO.Compression.Native C) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) +if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) +endif() + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../Common/pal_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/pal_config.h) + set(NATIVECOMPRESSION_SOURCES pal_zlib.c ) +if (HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) + list(APPEND NATIVECOMPRESSION_SOURCES "zlib_allocator_win.c") +else() + list(APPEND NATIVECOMPRESSION_SOURCES "zlib_allocator_unix.c") +endif() + if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) if (CLR_CMAKE_USE_SYSTEM_BROTLI) @@ -29,14 +43,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) set(NATIVE_LIBS_EXTRA) append_extra_compression_libs(NATIVE_LIBS_EXTRA) - if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) - include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake) - add_definitions(-DINTERNAL_ZLIB) - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - set(NATIVECOMPRESSION_SOURCES ${ZLIB_SOURCES} ${NATIVECOMPRESSION_SOURCES}) - endif() - # Disable implicit fallthrough warning for Zlib and Brotli set(FLAGS -Wno-implicit-fallthrough) @@ -96,24 +102,16 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) ${NATIVECOMPRESSION_SOURCES} ) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + target_link_libraries(System.IO.Compression.Native-Static PRIVATE zlibstatic) + endif() + set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native CLEAN_DIRECT_OUTPUT 1) else () if (GEN_SHARED_LIB) include (GenerateExportHeader) endif () - if (CLR_CMAKE_HOST_ARCH_I386 OR CLR_CMAKE_HOST_ARCH_AMD64) - include(${CLR_SRC_NATIVE_DIR}/external/zlib-intel.cmake) - add_definitions(-DINTERNAL_ZLIB_INTEL) - else () - include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake) - endif () - - add_definitions(-DINTERNAL_ZLIB) - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - set(NATIVECOMPRESSION_SOURCES ${ZLIB_SOURCES} ${NATIVECOMPRESSION_SOURCES}) - if (GEN_SHARED_LIB) add_definitions(-DVER_FILEDESCRIPTION_STR="System.IO.Compression.Native") add_library(System.IO.Compression.Native @@ -122,6 +120,10 @@ else () System.IO.Compression.Native.def ${VERSION_FILE_RC_PATH} ) + + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + target_link_libraries(System.IO.Compression.Native PRIVATE zlib) + endif() endif () if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) @@ -133,11 +135,20 @@ else () ${NATIVECOMPRESSION_SOURCES} ) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + target_link_libraries(System.IO.Compression.Native-Static PRIVATE zlibstatic) + endif() + if(STATIC_LIBS_ONLY) add_library(System.IO.Compression.Native.Aot STATIC ${NATIVECOMPRESSION_SOURCES} ) + + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + target_link_libraries(System.IO.Compression.Native.Aot PRIVATE zlibstatic) + endif() + set_target_properties(System.IO.Compression.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) set_target_properties(System.IO.Compression.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) @@ -145,6 +156,11 @@ else () STATIC ${NATIVECOMPRESSION_SOURCES} ) + + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + target_link_libraries(System.IO.Compression.Native.Aot.GuardCF PRIVATE zlibstatic) + endif() + set_target_properties(System.IO.Compression.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) endif() @@ -167,4 +183,8 @@ else () endif () +if((NOT CLR_CMAKE_USE_SYSTEM_ZLIB) AND STATIC_LIBS_ONLY) + install_static_library(zlib aotsdk nativeaot) +endif() + install (TARGETS System.IO.Compression.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) diff --git a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake index 78530ae98e8ff..6ad60233fce3f 100644 --- a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake +++ b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake @@ -1,16 +1,19 @@ - macro(append_extra_compression_libs NativeLibsExtra) + set(ZLIB_LIBRARIES "") # TODO: remove the mono-style HOST_ variable checks once Mono is using eng/native/configureplatform.cmake to define the CLR_CMAKE_TARGET_ defines if (CLR_CMAKE_TARGET_BROWSER OR HOST_BROWSER OR CLR_CMAKE_TARGET_WASI OR HOST_WASI) # nothing special to link elseif (CLR_CMAKE_TARGET_ANDROID OR HOST_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 OR HOST_SOLARIS) - set(ZLIB_LIBRARIES z m) - else () + list(APPEND ZLIB_LIBRARIES z) + elseif (CLR_CMAKE_HOST_ARCH_ARMV6) + find_package(ZLIB REQUIRED) + list(APPEND ZLIB_LIBRARIES z) + elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) find_package(ZLIB REQUIRED) - set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} m) + list(APPEND ZLIB_LIBRARIES m) + else() + list(APPEND ZLIB_LIBRARIES zlib) endif () list(APPEND ${NativeLibsExtra} ${ZLIB_LIBRARIES}) diff --git a/src/native/libs/System.IO.Compression.Native/pal_zlib.c b/src/native/libs/System.IO.Compression.Native/pal_zlib.c index bed37d1955f48..87b7043ea20ff 100644 --- a/src/native/libs/System.IO.Compression.Native/pal_zlib.c +++ b/src/native/libs/System.IO.Compression.Native/pal_zlib.c @@ -5,19 +5,14 @@ #include #include "pal_zlib.h" -#ifdef INTERNAL_ZLIB - #ifdef _WIN32 - #define c_static_assert(e) static_assert((e),"") - #endif - #ifdef INTERNAL_ZLIB_INTEL - #include - #else - #include - #endif +#ifdef _WIN32 + #define c_static_assert(e) static_assert((e),"") + #include "../Common/pal_utilities.h" #else #include "pal_utilities.h" - #include #endif +#include +#include c_static_assert(PAL_Z_NOFLUSH == Z_NO_FLUSH); c_static_assert(PAL_Z_FINISH == Z_FINISH); @@ -44,6 +39,10 @@ Initializes the PAL_ZStream by creating and setting its underlying z_stream. static int32_t Init(PAL_ZStream* stream) { z_stream* zStream = (z_stream*)calloc(1, sizeof(z_stream)); + + zStream->zalloc = z_custom_calloc; + zStream->zfree = z_custom_cfree; + stream->internalState = zStream; if (zStream != NULL) diff --git a/src/native/libs/System.IO.Compression.Native/pal_zlib.h b/src/native/libs/System.IO.Compression.Native/pal_zlib.h index b317091b843f6..efb090b0631ae 100644 --- a/src/native/libs/System.IO.Compression.Native/pal_zlib.h +++ b/src/native/libs/System.IO.Compression.Native/pal_zlib.h @@ -5,12 +5,12 @@ #include #include #define FUNCTIONEXPORT - #define FUNCTIONCALLINGCONVENCTION WINAPI + #define FUNCTIONCALLINGCONVENTION WINAPI #else #include "pal_types.h" #include "pal_compiler.h" #define FUNCTIONEXPORT PALEXPORT - #define FUNCTIONCALLINGCONVENCTION + #define FUNCTIONCALLINGCONVENTION #endif /* @@ -84,7 +84,7 @@ Initializes the PAL_ZStream so the Deflate function can be invoked on it. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_DeflateInit2_( +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_DeflateInit2_( PAL_ZStream* stream, int32_t level, int32_t method, int32_t windowBits, int32_t memLevel, int32_t strategy); /* @@ -93,21 +93,21 @@ compressed bytes in nextOut. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_Deflate(PAL_ZStream* stream, int32_t flush); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_Deflate(PAL_ZStream* stream, int32_t flush); /* All dynamically allocated data structures for this stream are freed. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_DeflateEnd(PAL_ZStream* stream); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_DeflateEnd(PAL_ZStream* stream); /* Initializes the PAL_ZStream so the Inflate function can be invoked on it. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_InflateInit2_(PAL_ZStream* stream, int32_t windowBits); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_InflateInit2_(PAL_ZStream* stream, int32_t windowBits); /* Inflates (uncompresses) the bytes in the PAL_ZStream's nextIn buffer and puts the @@ -115,14 +115,14 @@ uncompressed bytes in nextOut. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_Inflate(PAL_ZStream* stream, int32_t flush); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_Inflate(PAL_ZStream* stream, int32_t flush); /* All dynamically allocated data structures for this stream are freed. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_InflateEnd(PAL_ZStream* stream); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_InflateEnd(PAL_ZStream* stream); /* Update a running CRC-32 with the bytes buffer[0..len-1] and return the @@ -130,4 +130,4 @@ updated CRC-32. Returns the updated CRC-32. */ -FUNCTIONEXPORT uint32_t FUNCTIONCALLINGCONVENCTION CompressionNative_Crc32(uint32_t crc, uint8_t* buffer, int32_t len); +FUNCTIONEXPORT uint32_t FUNCTIONCALLINGCONVENTION CompressionNative_Crc32(uint32_t crc, uint8_t* buffer, int32_t len); diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h new file mode 100644 index 0000000000000..cadd00bb5879c --- /dev/null +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include // voidpf + +voidpf z_custom_calloc(voidpf opaque, unsigned items, unsigned size); + +void z_custom_cfree(voidpf opaque, voidpf ptr); diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c index 9eb4bbf267105..b2c898f70a4e3 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c @@ -3,7 +3,10 @@ #include #include -#include +#include +#include +#include +#include /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. * (non-Windows version) @@ -70,7 +73,7 @@ static void WriteAllocCookieUnaligned(void* pDest, DOTNET_ALLOC_COOKIE vCookie) const size_t DOTNET_ALLOC_HEADER_COOKIE_SIZE_WITH_PADDING = (sizeof(DOTNET_ALLOC_COOKIE) + MEMORY_ALLOCATION_ALIGNMENT - 1) & ~((size_t)MEMORY_ALLOCATION_ALIGNMENT - 1); const size_t DOTNET_ALLOC_TRAILER_COOKIE_SIZE = sizeof(DOTNET_ALLOC_COOKIE); -voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) +voidpf z_custom_calloc(opaque, items, size) voidpf opaque; unsigned items; unsigned size; @@ -79,7 +82,7 @@ voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) // If initializing a fixed-size structure, zero the memory. bool fZeroMemory = (items == 1); - + size_t cbRequested; if (sizeof(items) + sizeof(size) <= sizeof(cbRequested)) { @@ -119,7 +122,7 @@ static void zcfree_trash_cookie(void* pCookie) memset(pCookie, 0, sizeof(DOTNET_ALLOC_COOKIE)); } -void ZLIB_INTERNAL zcfree(opaque, ptr) +void z_custom_cfree(opaque, ptr) voidpf opaque; voidpf ptr; { diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c index 9bdf694495e68..fefba550c16ed 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c @@ -7,11 +7,10 @@ #include #include /* _ASSERTE */ -#ifdef INTERNAL_ZLIB_INTEL -#include -#else -#include -#endif +#include +#include +#include +#include /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. * (Windows-specific version) @@ -92,7 +91,7 @@ typedef struct _DOTNET_ALLOC_COOKIE const SIZE_T DOTNET_ALLOC_HEADER_COOKIE_SIZE_WITH_PADDING = (sizeof(DOTNET_ALLOC_COOKIE) + MEMORY_ALLOCATION_ALIGNMENT - 1) & ~((SIZE_T)MEMORY_ALLOCATION_ALIGNMENT - 1); const SIZE_T DOTNET_ALLOC_TRAILER_COOKIE_SIZE = sizeof(DOTNET_ALLOC_COOKIE); -voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) +voidpf z_custom_calloc(opaque, items, size) voidpf opaque; unsigned items; unsigned size; @@ -150,7 +149,7 @@ void zcfree_cookie_check_failed() __fastfail(FAST_FAIL_HEAP_METADATA_CORRUPTION); } -void ZLIB_INTERNAL zcfree(opaque, ptr) +void z_custom_cfree(opaque, ptr) voidpf opaque; voidpf ptr; {