From 9c3cb28acccb9af24a2aea77858475823e20ec05 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 3 Jul 2024 20:15:59 -0700 Subject: [PATCH] Revert "Migrate to zlib-ng, part 2: consume it in runtime (#102403)" This reverts commit f5c9a5e8f5ab28c1e3e49c4ecc047b4368a63d27. --- Directory.Build.props | 1 - eng/native/configurecompiler.cmake | 9 +-- eng/native/configureplatform.cmake | 6 -- eng/native/functions.cmake | 4 +- .../Microsoft.NETCore.Native.Unix.targets | 4 +- .../Microsoft.NETCore.Native.Windows.targets | 1 - .../Directory.Build.props | 2 - src/mono/CMakeLists.txt | 23 +++--- src/mono/browser/browser.proj | 1 - src/mono/browser/runtime/CMakeLists.txt | 1 - src/mono/cmake/config.h.in | 3 + src/mono/mono.proj | 3 - src/mono/mono/eventpipe/test/CMakeLists.txt | 11 +-- src/mono/mono/metadata/CMakeLists.txt | 18 +---- src/mono/mono/metadata/debug-mono-ppdb.c | 6 +- src/mono/mono/mini/CMakeLists.txt | 77 ++++--------------- src/mono/mono/profiler/CMakeLists.txt | 10 +-- src/mono/mono/profiler/log.c | 6 +- src/mono/mono/profiler/mprof-report.c | 6 +- .../msbuild/apple/build/AppleBuild.targets | 3 +- src/mono/wasi/runtime/CMakeLists.txt | 1 - src/mono/wasi/wasi.proj | 1 - src/native/external/zlib-intel.cmake | 29 +++++++ src/native/external/zlib-ng.cmake | 33 -------- src/native/external/zlib.cmake | 41 ++++++++++ src/native/libs/Common/pal_utilities.h | 6 +- .../CMakeLists.txt | 60 +++++---------- .../extra_libs.cmake | 15 ++-- .../System.IO.Compression.Native/pal_zlib.c | 19 ++--- .../System.IO.Compression.Native/pal_zlib.h | 18 ++--- .../zlib_allocator.h | 8 -- .../zlib_allocator_unix.c | 11 +-- .../zlib_allocator_win.c | 13 ++-- 33 files changed, 183 insertions(+), 267 deletions(-) create mode 100644 src/native/external/zlib-intel.cmake delete mode 100644 src/native/external/zlib-ng.cmake create mode 100644 src/native/external/zlib.cmake delete mode 100644 src/native/libs/System.IO.Compression.Native/zlib_allocator.h diff --git a/Directory.Build.props b/Directory.Build.props index 61edda987ed6d..3e494e19c3d9e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -324,7 +324,6 @@ 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 aedc482527300..76c441de6f2f5 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -12,11 +12,6 @@ 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) @@ -63,7 +58,6 @@ 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) @@ -785,8 +779,7 @@ if (MSVC) # [[! Microsoft.Security.SystemsADM.10086 !]] - SDL required warnings # set default warning level to 4 but allow targets to override it. - set_property(GLOBAL PROPERTY MSVC_WARNING_LEVEL 4) - add_compile_options($<$:/W$>) + add_compile_options($<$:/W$>,$,4>>>) 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 1dfc2458d11e8..20851f8617423 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -500,9 +500,3 @@ 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 b1cb09d662043..6629e926afacf 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 "$" + COMPILE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" ) 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 3ff044e94d9d2..d3dc85e04f82e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -24,7 +24,6 @@ The .NET Foundation licenses this file to you under the MIT license. lld bfd 1572864 - true @@ -130,7 +129,6 @@ The .NET Foundation licenses this file to you under the MIT license. - @@ -190,7 +188,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 7be88b5fde991..8035484bf04a5 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -46,7 +46,6 @@ 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 70c526efac38c..0de334e7ff211 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -277,8 +277,6 @@ - - diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index fac1d9fb0e33c..ba41fa4d9a489 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -249,6 +249,7 @@ 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) @@ -260,6 +261,7 @@ 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") @@ -268,6 +270,7 @@ 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 @@ -508,15 +511,16 @@ if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64)) set(TARGET_APPLE_MOBILE 1) endif() -# Decide if we need zlib-ng. +# Decide if we need zlib, and if so whether we want the system zlib or the in-tree copy. if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ) - if (CLR_CMAKE_USE_SYSTEM_ZLIB) - # if we're not on a platform where we use the in-tree zlib-ng, require system zlib + 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 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() @@ -660,17 +664,12 @@ if(LLVM_PREFIX) endif() set(llvm_includedir "${LLVM_PREFIX}/include") - set(llvm_system_libs "") if(HOST_LINUX) # llvm-config --system-libs - list(APPEND llvm_system_libs ${MONO_cxx_lib} "-lrt" "-ldl" "-lpthread" "-lm") + set(llvm_system_libs ${MONO_cxx_lib} "-lz" "-lrt" "-ldl" "-lpthread" "-lm") elseif(HOST_OSX) # llvm-config --system-libs - 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") + set(llvm_system_libs "-lz" "-lm") endif() # llvm-config --libs analysis core bitwriter mcjit orcjit diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 47a351fb53b41..81768d43e6a53 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -63,7 +63,6 @@ - diff --git a/src/mono/browser/runtime/CMakeLists.txt b/src/mono/browser/runtime/CMakeLists.txt index f707431fc38d5..8b7939330f8c3 100644 --- a/src/mono/browser/runtime/CMakeLists.txt +++ b/src/mono/browser/runtime/CMakeLists.txt @@ -28,7 +28,6 @@ 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 8ac0c0f7c3c29..e972500d1cd81 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -168,6 +168,9 @@ /* 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 ceb783599086e..14056eb3a7e24 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -1189,9 +1189,6 @@ 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 92ddfb3ce17f9..d313e630adaab 100644 --- a/src/mono/mono/eventpipe/test/CMakeLists.txt +++ b/src/mono/mono/eventpipe/test/CMakeLists.txt @@ -39,16 +39,7 @@ 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}") - - 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}) - + target_link_libraries(ep-test PRIVATE eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS} monoapi) 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 e3463b514d0c0..773381d6c1c9a 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -200,14 +200,7 @@ 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}) - - 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}) - + target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared) # 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) @@ -219,14 +212,7 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) - -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}) - +target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects) # 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 3ed40e9243dad..bcbbb4c7f2be0 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -30,8 +30,12 @@ #include #ifndef DISABLE_EMBEDDED_PDB +#ifdef INTERNAL_ZLIB +#include +#else #include -#endif // DISABLE_EMBEDDED_PDB +#endif +#endif #include "debug-mono-ppdb.h" diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index af9987869f5ac..93ff6c431ef03 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -314,7 +314,10 @@ 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(monosgen-sources "${mini_sources}") +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}") if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(monosgen-objects_shared OBJECT "${monosgen-sources}") @@ -323,14 +326,7 @@ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) endif() add_library(monosgen-objects OBJECT "${monosgen-sources}") - -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}) - +target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() @@ -357,23 +353,15 @@ 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() + endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) 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) - list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared) - target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers) else() - list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects) - target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) endif() target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) @@ -381,16 +369,11 @@ 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() - - 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}) + 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}) else() - list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS zlib) + target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) 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() @@ -434,22 +417,8 @@ if(NOT DISABLE_SHARED_LIBS) endif() add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) - - 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}) + 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_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}") @@ -565,27 +534,11 @@ if(NOT DISABLE_EXECUTABLES) set_target_properties(mono-sgen PROPERTIES INSTALL_RPATH "$ORIGIN") endif() endif() - - 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}) - + target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers) if (HOST_WASM) target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) endif() - - 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}) - + target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) # 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 e172774a6ebc5..511c19dbe5a32 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -12,7 +12,9 @@ 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 - add_library(mono-profiler-log SHARED helper.c log.c log-args.c) + 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}) 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) @@ -26,11 +28,7 @@ if(NOT DISABLE_LIBS) install(TARGETS mono-profiler-log-static LIBRARY) if(NOT DISABLE_LOG_PROFILER_GZ) - 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() + target_link_libraries(mono-profiler-log PRIVATE ${Z_LIBS}) endif() endif() diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index abe5f3f479f57..9d4304faae3ec 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -72,8 +72,12 @@ #include #endif #ifndef DISABLE_LOG_PROFILER_GZ +#ifdef INTERNAL_ZLIB +#include +#else #include -#endif // DISABLE_LOG_PROFILER_GZ +#endif +#endif #ifdef HOST_WIN32 #include diff --git a/src/mono/mono/profiler/mprof-report.c b/src/mono/mono/profiler/mprof-report.c index 5e2cc5ad7a20e..35c88fe0a2fd9 100644 --- a/src/mono/mono/profiler/mprof-report.c +++ b/src/mono/mono/profiler/mprof-report.c @@ -23,8 +23,12 @@ #endif #include #ifndef DISABLE_LOG_PROFILER_GZ +#ifdef INTERNAL_ZLIB +#include +#else #include -#endif // DISABLE_LOG_PROFILER_GZ +#endif +#endif #include #include #include diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 483ae04924a72..35d0f16c35b4b 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -6,7 +6,6 @@ false <_ProcessRuntimeComponentsForLibraryMode Condition="'$(_IsLibraryMode)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">_ProcessRuntimeComponentsForLibraryMode false - true - <_CommonLinkerArgs Include="-lz" Condition="'$(UseSystemZlib)' == 'true'" /> + <_CommonLinkerArgs Include="-lz" /> <_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 ec45f3aa2e488..1d2a220494779 100644 --- a/src/mono/wasi/runtime/CMakeLists.txt +++ b/src/mono/wasi/runtime/CMakeLists.txt @@ -27,7 +27,6 @@ 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 99bf8a6ee54f8..9c386481a26e1 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -49,7 +49,6 @@ - diff --git a/src/native/external/zlib-intel.cmake b/src/native/external/zlib-intel.cmake new file mode 100644 index 0000000000000..a664f154dbef0 --- /dev/null +++ b/src/native/external/zlib-intel.cmake @@ -0,0 +1,29 @@ +# 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 deleted file mode 100644 index 3f005eaa54f3d..0000000000000 --- a/src/native/external/zlib-ng.cmake +++ /dev/null @@ -1,33 +0,0 @@ -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 new file mode 100644 index 0000000000000..498ec977960e0 --- /dev/null +++ b/src/native/external/zlib.cmake @@ -0,0 +1,41 @@ +# 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 a1a57c8ed0e8c..7b5fa63b6cac0 100644 --- a/src/native/libs/Common/pal_utilities.h +++ b/src/native/libs/Common/pal_utilities.h @@ -12,9 +12,7 @@ #include #include #include -#ifndef _WIN32 - #include -#endif +#include #include #include @@ -71,7 +69,6 @@ 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. @@ -89,7 +86,6 @@ 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 69d333ae53f9c..089363cf5554e 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -2,24 +2,10 @@ 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) @@ -43,6 +29,14 @@ 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) @@ -102,16 +96,24 @@ 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 @@ -120,10 +122,6 @@ 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) @@ -135,20 +133,11 @@ 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) @@ -156,11 +145,6 @@ 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() @@ -183,8 +167,4 @@ 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 6ad60233fce3f..78530ae98e8ff 100644 --- a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake +++ b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake @@ -1,19 +1,16 @@ + 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 - 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) + set(ZLIB_LIBRARIES z) + elseif (CLR_CMAKE_TARGET_SUNOS OR HOST_SOLARIS) + set(ZLIB_LIBRARIES z m) + else () find_package(ZLIB REQUIRED) - list(APPEND ZLIB_LIBRARIES m) - else() - list(APPEND ZLIB_LIBRARIES zlib) + set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} m) 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 87b7043ea20ff..bed37d1955f48 100644 --- a/src/native/libs/System.IO.Compression.Native/pal_zlib.c +++ b/src/native/libs/System.IO.Compression.Native/pal_zlib.c @@ -5,14 +5,19 @@ #include #include "pal_zlib.h" -#ifdef _WIN32 - #define c_static_assert(e) static_assert((e),"") - #include "../Common/pal_utilities.h" +#ifdef INTERNAL_ZLIB + #ifdef _WIN32 + #define c_static_assert(e) static_assert((e),"") + #endif + #ifdef INTERNAL_ZLIB_INTEL + #include + #else + #include + #endif #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); @@ -39,10 +44,6 @@ 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 efb090b0631ae..b317091b843f6 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 FUNCTIONCALLINGCONVENTION WINAPI + #define FUNCTIONCALLINGCONVENCTION WINAPI #else #include "pal_types.h" #include "pal_compiler.h" #define FUNCTIONEXPORT PALEXPORT - #define FUNCTIONCALLINGCONVENTION + #define FUNCTIONCALLINGCONVENCTION #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 FUNCTIONCALLINGCONVENTION CompressionNative_DeflateInit2_( +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION 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 FUNCTIONCALLINGCONVENTION CompressionNative_Deflate(PAL_ZStream* stream, int32_t flush); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION 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 FUNCTIONCALLINGCONVENTION CompressionNative_DeflateEnd(PAL_ZStream* stream); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION 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 FUNCTIONCALLINGCONVENTION CompressionNative_InflateInit2_(PAL_ZStream* stream, int32_t windowBits); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION 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 FUNCTIONCALLINGCONVENTION CompressionNative_Inflate(PAL_ZStream* stream, int32_t flush); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION 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 FUNCTIONCALLINGCONVENTION CompressionNative_InflateEnd(PAL_ZStream* stream); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION 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 FUNCTIONCALLINGCONVENTION CompressionNative_Crc32(uint32_t crc, uint8_t* buffer, int32_t len); +FUNCTIONEXPORT uint32_t FUNCTIONCALLINGCONVENCTION 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 deleted file mode 100644 index cadd00bb5879c..0000000000000 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h +++ /dev/null @@ -1,8 +0,0 @@ -// 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 b2c898f70a4e3..9eb4bbf267105 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,10 +3,7 @@ #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) @@ -73,7 +70,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 z_custom_calloc(opaque, items, size) +voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) voidpf opaque; unsigned items; unsigned size; @@ -82,7 +79,7 @@ voidpf z_custom_calloc(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)) { @@ -122,7 +119,7 @@ static void zcfree_trash_cookie(void* pCookie) memset(pCookie, 0, sizeof(DOTNET_ALLOC_COOKIE)); } -void z_custom_cfree(opaque, ptr) +void ZLIB_INTERNAL zcfree(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 fefba550c16ed..9bdf694495e68 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,10 +7,11 @@ #include #include /* _ASSERTE */ -#include -#include -#include -#include +#ifdef INTERNAL_ZLIB_INTEL +#include +#else +#include +#endif /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. * (Windows-specific version) @@ -91,7 +92,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 z_custom_calloc(opaque, items, size) +voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) voidpf opaque; unsigned items; unsigned size; @@ -149,7 +150,7 @@ void zcfree_cookie_check_failed() __fastfail(FAST_FAIL_HEAP_METADATA_CORRUPTION); } -void z_custom_cfree(opaque, ptr) +void ZLIB_INTERNAL zcfree(opaque, ptr) voidpf opaque; voidpf ptr; {