From ef0a7c2240c659c911697b294ee2c9beb6ed5e96 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 16 Sep 2024 20:52:13 +0000 Subject: [PATCH 01/13] Compile the repo minipal as an object and static library for usage across the product as a single unit instead of separate source files. --- eng/native/configurecompiler.cmake | 4 ---- eng/native/functions.cmake | 2 +- src/coreclr/CMakeLists.txt | 1 + src/coreclr/debug/createdump/CMakeLists.txt | 4 +++- src/coreclr/minipal/CMakeLists.txt | 1 - src/coreclr/minipal/Unix/CMakeLists.txt | 10 +--------- src/coreclr/minipal/Windows/CMakeLists.txt | 11 ++--------- src/coreclr/nativeaot/Bootstrap/main.cpp | 2 +- src/coreclr/nativeaot/Runtime/CMakeLists.txt | 4 ---- .../nativeaot/Runtime/Full/CMakeLists.txt | 3 +++ .../Runtime/eventpipe/CMakeLists.txt | 18 ------------------ src/coreclr/pal/src/CMakeLists.txt | 5 +++-- .../tools/aot/jitinterface/CMakeLists.txt | 7 ++----- src/mono/CMakeLists.txt | 1 + src/mono/mono/eglib/CMakeLists.txt | 8 ++------ src/mono/mono/mini/CMakeLists.txt | 2 +- src/native/libs/CMakeLists.txt | 9 +++++++-- src/native/libs/System.Native/CMakeLists.txt | 15 +-------------- src/native/minipal/CMakeLists.txt | 19 +++++++++++++++++++ src/native/minipal/configure.cmake | 4 ++++ src/native/minipal/minipalconfig.h.in | 1 + .../minipal/{asansupport.cpp => sansupport.c} | 8 ++++++-- src/native/minipal/time.c | 4 ++-- src/native/minipal/time.h | 4 ++-- 24 files changed, 63 insertions(+), 84 deletions(-) create mode 100644 src/native/minipal/CMakeLists.txt rename src/native/minipal/{asansupport.cpp => sansupport.c} (79%) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 48972cc67af02..c5fa2f7db8830 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -1,7 +1,3 @@ -# Due to how we build the libraries native build as part of the CoreCLR build as well as standalone, -# we can end up coming to this file twice. Only run it once to simplify our build. -include_guard() - include(${CMAKE_CURRENT_LIST_DIR}/configuretools.cmake) # Set initial flags for each configuration diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index b1cb09d662043..337538a6ba163 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -637,7 +637,7 @@ endfunction() function(add_sanitizer_runtime_support targetName) # Add sanitizer support functions. if (CLR_CMAKE_ENABLE_ASAN) - target_sources(${targetName} PRIVATE "$<$,EXECUTABLE>:${CLR_SRC_NATIVE_DIR}/minipal/asansupport.cpp>") + target_link_libraries(${targetName} PRIVATE $<$,EXECUTABLE>:minipal_sanitizer_support>) endif() endfunction() diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 2e9a6c76743e5..732c3b765379e 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -127,6 +127,7 @@ include (${CLR_SRC_NATIVE_DIR}/eventpipe/configure.cmake) add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers) add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe) +add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal) if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) add_subdirectory(debug/debug-pal) diff --git a/src/coreclr/debug/createdump/CMakeLists.txt b/src/coreclr/debug/createdump/CMakeLists.txt index 3c72b8a0fa42b..aa609967f55b0 100644 --- a/src/coreclr/debug/createdump/CMakeLists.txt +++ b/src/coreclr/debug/createdump/CMakeLists.txt @@ -68,7 +68,6 @@ else(CLR_CMAKE_HOST_WIN32) datatarget.cpp dumpwriter.cpp crashreportwriter.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c ) if(CLR_CMAKE_HOST_OSX) @@ -104,6 +103,9 @@ endif(CLR_CMAKE_HOST_OSX) endif(CLR_CMAKE_HOST_WIN32) +target_link_libraries(createdump_static PRIVATE minipal) +target_link_libraries(createdump PRIVATE minipal) + if (CLR_CMAKE_HOST_APPLE) adhoc_sign_with_entitlements(createdump "${CLR_ENG_NATIVE_DIR}/createdump-entitlements.plist") endif() diff --git a/src/coreclr/minipal/CMakeLists.txt b/src/coreclr/minipal/CMakeLists.txt index 78a1726af3e81..298e1d6fba381 100644 --- a/src/coreclr/minipal/CMakeLists.txt +++ b/src/coreclr/minipal/CMakeLists.txt @@ -5,4 +5,3 @@ if (CLR_CMAKE_HOST_UNIX) else (CLR_CMAKE_HOST_UNIX) add_subdirectory(Windows) endif (CLR_CMAKE_HOST_UNIX) - diff --git a/src/coreclr/minipal/Unix/CMakeLists.txt b/src/coreclr/minipal/Unix/CMakeLists.txt index 6cb70d1e34469..aa4ea90d5e270 100644 --- a/src/coreclr/minipal/Unix/CMakeLists.txt +++ b/src/coreclr/minipal/Unix/CMakeLists.txt @@ -1,19 +1,11 @@ set(SOURCES doublemapping.cpp dn-u16.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/time.c ) -if(NOT CLR_CROSS_COMPONENTS_BUILD) - list(APPEND SOURCES - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c - ) -endif() - add_library(coreclrminipal STATIC ${SOURCES} ) -include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(coreclrminipal PRIVATE minipal) diff --git a/src/coreclr/minipal/Windows/CMakeLists.txt b/src/coreclr/minipal/Windows/CMakeLists.txt index b1f1cb88a3e6a..90ed6ddf4ea95 100644 --- a/src/coreclr/minipal/Windows/CMakeLists.txt +++ b/src/coreclr/minipal/Windows/CMakeLists.txt @@ -1,17 +1,10 @@ set(SOURCES doublemapping.cpp dn-u16.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c - ${CLR_SRC_NATIVE_DIR}/minipal/time.c ) - -if(NOT CLR_CROSS_COMPONENTS_BUILD) - list(APPEND SOURCES - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c - ) -endif() - add_library(coreclrminipal STATIC ${SOURCES} ) + +target_link_libraries(coreclrminipal PRIVATE minipal) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index 16ffe8f9dbcb0..2e1cfdb063e30 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -230,7 +230,7 @@ int main(int argc, char* argv[]) // the linker can detect that we have ASAN components early enough in the build. // Include our asan support sources for executable projects here to ensure they // are compiled into the bootstrapper object. -#include "minipal/asansupport.cpp" +#include "minipal/sansupport.c" #endif // HAS_ADDRESS_SANITIZER #endif // !NATIVEAOT_DLL diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index b763e76af80e9..d723c9aa9145b 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -49,9 +49,6 @@ set(COMMON_RUNTIME_SOURCES ${GC_DIR}/handletablescan.cpp ${GC_DIR}/objecthandle.cpp ${GC_DIR}/softwarewritewatch.cpp - - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c - ${CLR_SRC_NATIVE_DIR}/minipal/time.c ) set(SERVER_GC_SOURCES @@ -276,7 +273,6 @@ else() add_definitions(-DFEATURE_READONLY_GS_COOKIE) endif() include(unix/configure.cmake) - include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) include_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() diff --git a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt index f9b390e18d117..25516e5d46130 100644 --- a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt @@ -28,9 +28,11 @@ endif (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.WorkstationGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${RUNTIME_ARCH_ASM_OBJECTS}) add_dependencies(Runtime.WorkstationGC aot_eventing_headers) +target_link_libraries(Runtime.WorkstationGC PRIVATE minipal_objects) add_library(Runtime.ServerGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) add_dependencies(Runtime.ServerGC aot_eventing_headers) +target_link_libraries(Runtime.ServerGC PRIVATE minipal_objects) add_library(standalonegc-disabled STATIC ${STANDALONEGC_DISABLED_SOURCES}) add_dependencies(standalonegc-disabled aot_eventing_headers) @@ -60,6 +62,7 @@ if (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.ServerGC.GuardCF STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) target_compile_definitions(Runtime.ServerGC.GuardCF PRIVATE -DFEATURE_SVR_GC) set_target_properties(Runtime.ServerGC.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) + target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects) if (CLR_CMAKE_TARGET_ARCH_AMD64) add_library(Runtime.VxsortEnabled.GuardCF STATIC ${VXSORT_SOURCES}) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index 537e2f5f2b5f4..333180b43eb2d 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -106,25 +106,8 @@ endif() set(AOT_EVENTPIPE_SHIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set (MINIPAL_SOURCES "") set (EVENTPIPE_SOURCES "") -set (SHARED_MINIPAL_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/minipal") - -list(APPEND MINIPAL_SOURCES - utf8.c -) - -if(CLR_CMAKE_HOST_UNIX) - include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) - list(APPEND MINIPAL_SOURCES - random.c - ) - -endif(CLR_CMAKE_HOST_UNIX) - -addprefix(MINIPAL_SOURCES ${SHARED_MINIPAL_SOURCE_PATH} "${MINIPAL_SOURCES}") - list(APPEND AOT_EVENTPIPE_SHIM_SOURCES ${AOT_EVENTPIPE_SHIM_DIR}/ep-rt-aot.cpp ${AOT_EVENTPIPE_SHIM_DIR}/ds-rt-aot.cpp @@ -218,7 +201,6 @@ list(APPEND EVENTPIPE_SOURCES ${AOT_EVENTTRACE_SOURCES} ${GEN_EVENTPIPE_PROVIDER_SOURCES} ${GEN_EVENTPIPE_PLAT_AGNOSTIC_SOURCES} - ${MINIPAL_SOURCES} ) list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index cc301eb275731..db5d430ed011b 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -149,8 +149,6 @@ set(SOURCES init/sxs.cpp loader/module.cpp locale/unicode.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c - ${CLR_SRC_NATIVE_DIR}/minipal/unicodedata.c map/common.cpp map/map.cpp map/virtual.cpp @@ -338,6 +336,9 @@ if(CLR_CMAKE_TARGET_SUNOS) ) endif(CLR_CMAKE_TARGET_SUNOS) +target_link_libraries(coreclrpal + PRIVATE minipal) + if(FEATURE_EVENT_TRACE) add_subdirectory(eventprovider) endif(FEATURE_EVENT_TRACE) diff --git a/src/coreclr/tools/aot/jitinterface/CMakeLists.txt b/src/coreclr/tools/aot/jitinterface/CMakeLists.txt index 6a612e1486985..6c2512a0ca848 100644 --- a/src/coreclr/tools/aot/jitinterface/CMakeLists.txt +++ b/src/coreclr/tools/aot/jitinterface/CMakeLists.txt @@ -5,15 +5,10 @@ set(NATIVE_SOURCES jitinterface.cpp jitwrapper.cpp corinfoexception.cpp - - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c ) if(CLR_CMAKE_TARGET_WIN32) set(JITINTERFACE_RESOURCES Native.rc) -else() - include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() add_library_clr(jitinterface_${ARCH_HOST_NAME} @@ -22,5 +17,7 @@ add_library_clr(jitinterface_${ARCH_HOST_NAME} ${JITINTERFACE_RESOURCES} ) +target_link_libraries(jitinterface_${ARCH_HOST_NAME} PRIVATE minipal) + install_clr(TARGETS jitinterface_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT jit) install_clr(TARGETS jitinterface_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT alljits) diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 7078eb1230631..51af329391dea 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -886,6 +886,7 @@ endif() ### End of OS specific checks include_directories("${CLR_SRC_NATIVE_DIR}") +add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal) if(NOT DISABLE_LIBS) set(INSTALL_MONO_API 1) diff --git a/src/mono/mono/eglib/CMakeLists.txt b/src/mono/mono/eglib/CMakeLists.txt index 951c098de72da..f4d6b31ab0142 100644 --- a/src/mono/mono/eglib/CMakeLists.txt +++ b/src/mono/mono/eglib/CMakeLists.txt @@ -38,12 +38,7 @@ set(eglib_common_sources gpath.c gfile.c gfile-posix.c - gutf8.c - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c) - -if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN") - set_source_files_properties("${CLR_SRC_NATIVE_DIR}/minipal/utf8.c" PROPERTIES COMPILE_FLAGS "-DBIGENDIAN=1") -endif() + gutf8.c) set(eglib_headers glib.h @@ -67,3 +62,4 @@ target_include_directories(eglib_objects PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}) target_link_libraries (eglib_objects PUBLIC eglib_api) +target_link_libraries(eglib_objects PUBLIC minipal) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index af9987869f5ac..8567ca7003b90 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -337,7 +337,7 @@ endif() add_library(monosgen-static STATIC $ $ $ $ $) set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME}) -target_link_libraries(monosgen-static PRIVATE dn-containers) +target_link_libraries(monosgen-static PRIVATE dn-containers minipal) if(DISABLE_COMPONENTS OR AOT_COMPONENTS) # add component fallback stubs into static mono library when components have been disabled. diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index f25e639fb7fda..e374b1ce2edf2 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -4,8 +4,13 @@ include(CheckCCompilerFlag) project(CoreFX C) -include(../../../eng/native/configurepaths.cmake) -include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) +if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + # This is our root CMakeList.txt, so we need to set up some global settings and include the minipal here. + include(../../../eng/native/configurepaths.cmake) + include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) + + add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal) +endif() include_directories(${CLR_SRC_NATIVE_DIR}) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 7e00e0ed0a271..ea059b923e057 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -8,16 +8,6 @@ if (CLR_CMAKE_TARGET_OSX) add_definitions(-D_DARWIN_C_SOURCE) endif () -set (MINIPAL_SOURCES "") -set (SHARED_MINIPAL_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/minipal") - -include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) -list(APPEND MINIPAL_SOURCES - random.c -) - -addprefix(MINIPAL_SOURCES ${SHARED_MINIPAL_SOURCE_PATH} "${MINIPAL_SOURCES}") - set(NATIVE_SOURCES pal_errno.c pal_interfaceaddresses.c @@ -35,10 +25,6 @@ set(NATIVE_SOURCES pal_sysctl.c ) -list(APPEND NATIVE_SOURCES - ${MINIPAL_SOURCES} -) - if (NOT CLR_CMAKE_TARGET_WASI) list (APPEND NATIVE_SOURCES pal_dynamicload.c @@ -126,6 +112,7 @@ if (GEN_SHARED_LIB) target_link_libraries(System.Native PRIVATE + minipal ${NATIVE_LIBS_EXTRA} ) diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt new file mode 100644 index 0000000000000..38ec063bd5da1 --- /dev/null +++ b/src/native/minipal/CMakeLists.txt @@ -0,0 +1,19 @@ +include(configure.cmake) + +# Provide an object library for scenarios where we ship static libraries +add_library(minipal_objects OBJECT + cpufeatures.c + random.c + time.c + unicodedata.c + utf8.c) + +target_include_directories(minipal_objects PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +# Provide a static library for our shared library and executable scenarios +# for easier usability. +add_library(minipal STATIC) +target_link_libraries(minipal PRIVATE minipal_objects) + +add_library(minipal_sanitizer_support OBJECT + sansupport.c) \ No newline at end of file diff --git a/src/native/minipal/configure.cmake b/src/native/minipal/configure.cmake index 5394fb8774b9c..cb9e22b3c9230 100644 --- a/src/native/minipal/configure.cmake +++ b/src/native/minipal/configure.cmake @@ -13,4 +13,8 @@ check_symbol_exists( time.h HAVE_CLOCK_GETTIME_NSEC_NP) +if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN") + set(BIGENDIAN 1) +endif() + configure_file(${CMAKE_CURRENT_LIST_DIR}/minipalconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/minipalconfig.h) diff --git a/src/native/minipal/minipalconfig.h.in b/src/native/minipal/minipalconfig.h.in index d51f47de26103..727197cf5ee75 100644 --- a/src/native/minipal/minipalconfig.h.in +++ b/src/native/minipal/minipalconfig.h.in @@ -6,5 +6,6 @@ #cmakedefine01 HAVE_O_CLOEXEC #cmakedefine01 HAVE_SYSCTLBYNAME #cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP +#cmakedefine01 BIGENDIAN #endif diff --git a/src/native/minipal/asansupport.cpp b/src/native/minipal/sansupport.c similarity index 79% rename from src/native/minipal/asansupport.cpp rename to src/native/minipal/sansupport.c index b5873cd95b6de..d9891e1bc8557 100644 --- a/src/native/minipal/asansupport.cpp +++ b/src/native/minipal/sansupport.c @@ -4,7 +4,10 @@ // Use a typedef here as __declspec + pointer return type causes a parse error in MSVC typedef const char* charptr_t; -extern "C" charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options() { + +charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options(void); + +charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options(void) { // symbolize=1 to get symbolized stack traces // use_sigaltstack=0 as coreclr uses own alternate stack for signal handlers // detect_leaks=0 as coreclr intentionally doesn't clean up all memory on exit @@ -15,5 +18,6 @@ extern "C" charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options() { return "symbolize=1 use_sigaltstack=0 detect_leaks=0 handle_segv=0 allocator_may_return_null=1"; } -extern "C" void SANITIZER_CALLBACK_CALLCONV __asan_on_error() { +void SANITIZER_CALLBACK_CALLCONV __asan_on_error(void); +void SANITIZER_CALLBACK_CALLCONV __asan_on_error(void) { } diff --git a/src/native/minipal/time.c b/src/native/minipal/time.c index 0a76df5d45342..043373747f8ef 100644 --- a/src/native/minipal/time.c +++ b/src/native/minipal/time.c @@ -53,12 +53,12 @@ inline static void YieldProcessor() } #define tccSecondsToNanoSeconds 1000000000 // 10^9 -int64_t minipal_hires_tick_frequency() +int64_t minipal_hires_tick_frequency(void) { return tccSecondsToNanoSeconds; } -int64_t minipal_hires_ticks() +int64_t minipal_hires_ticks(void) { #if HAVE_CLOCK_GETTIME_NSEC_NP return (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW); diff --git a/src/native/minipal/time.h b/src/native/minipal/time.h index 313aeb695607c..27359aa407c75 100644 --- a/src/native/minipal/time.h +++ b/src/native/minipal/time.h @@ -12,10 +12,10 @@ extern "C" #endif // __cplusplus // Returns current count of high resolution monotonically increasing timer ticks - int64_t minipal_hires_ticks(); + int64_t minipal_hires_ticks(void); // Returns the frequency of high resolution timer ticks in Hz - int64_t minipal_hires_tick_frequency(); + int64_t minipal_hires_tick_frequency(void); // Delays execution of current thread by `usecs` microseconds. // The delay is best-effort and may take longer than desired. From 5e1a9b69b5eaa37c81db3af5eaf93b729aac792b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 16 Sep 2024 21:36:27 +0000 Subject: [PATCH 02/13] Don't refer to createdump_static on Windows, it doesn't exist --- src/coreclr/debug/createdump/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/debug/createdump/CMakeLists.txt b/src/coreclr/debug/createdump/CMakeLists.txt index aa609967f55b0..bdd648c2670c3 100644 --- a/src/coreclr/debug/createdump/CMakeLists.txt +++ b/src/coreclr/debug/createdump/CMakeLists.txt @@ -87,6 +87,7 @@ else() ${CREATEDUMP_SOURCES} ) endif(CLR_CMAKE_HOST_OSX) +target_link_libraries(createdump_static PRIVATE minipal) add_executable_clr(createdump main.cpp @@ -103,7 +104,6 @@ endif(CLR_CMAKE_HOST_OSX) endif(CLR_CMAKE_HOST_WIN32) -target_link_libraries(createdump_static PRIVATE minipal) target_link_libraries(createdump PRIVATE minipal) if (CLR_CMAKE_HOST_APPLE) From 2bf6f3387cff9da273e6e81644fddf078d0b5d34 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 17 Sep 2024 11:37:07 -0700 Subject: [PATCH 03/13] Add implementation of the minipal random functions for Windows to get the full minipal building on Windows --- src/native/minipal/configure.cmake | 1 + src/native/minipal/minipalconfig.h.in | 1 + src/native/minipal/random.c | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/native/minipal/configure.cmake b/src/native/minipal/configure.cmake index cb9e22b3c9230..666490b273f74 100644 --- a/src/native/minipal/configure.cmake +++ b/src/native/minipal/configure.cmake @@ -7,6 +7,7 @@ check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME) check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF) check_symbol_exists(O_CLOEXEC fcntl.h HAVE_O_CLOEXEC) +check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) check_symbol_exists( clock_gettime_nsec_np diff --git a/src/native/minipal/minipalconfig.h.in b/src/native/minipal/minipalconfig.h.in index 727197cf5ee75..d550d2e3d286a 100644 --- a/src/native/minipal/minipalconfig.h.in +++ b/src/native/minipal/minipalconfig.h.in @@ -7,5 +7,6 @@ #cmakedefine01 HAVE_SYSCTLBYNAME #cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP #cmakedefine01 BIGENDIAN +#cmakedefine01 HAVE_BCRYPT_H #endif diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index 20fcc07802e65..fa4b306898eaf 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -1,20 +1,26 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#include "minipalconfig.h" + #include #include #include -#include -#include #include -#include #include #include +#if HAVE_BCRYPT_H +#include +#include +#else +#include +#include +#include +#endif #if defined(__APPLE__) && __APPLE__ #include #endif -#include "minipalconfig.h" #include "random.h" /* @@ -29,6 +35,9 @@ void minipal_get_non_cryptographically_secure_random_bytes(uint8_t* buffer, int3 #if HAVE_ARC4RANDOM_BUF arc4random_buf(buffer, (size_t)bufferLength); +#elif HAVE_BCRYPT_H + // Fall back to the secure version + minipal_get_cryptographically_secure_random_bytes(buffer, bufferLength); #else long num = 0; static bool sInitializedMRand; @@ -86,6 +95,9 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 { return 0; } +#elif defined(HAVE_BCRYPT_H) + NTSTATUS status = BCryptGenRandom(NULL, buffer, (ULONG)bufferLength, BCRYPT_USE_SYSTEM_PREFERRED_RNG); + return BCRYPT_SUCCESS(status) ? 1 : 0; #else static volatile int rand_des = -1; From 6caa935cb08a5e781b7575daacc90b12762b9fa6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 17 Sep 2024 11:39:45 -0700 Subject: [PATCH 04/13] PR feedback --- src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt | 4 ++-- .../nativeaot/Runtime/Portable/CMakeLists.txt | 1 + src/native/libs/CMakeLists.txt | 2 +- src/native/minipal/CMakeLists.txt | 15 +++++++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt index 25516e5d46130..936ee522ac417 100644 --- a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt @@ -62,7 +62,7 @@ if (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.ServerGC.GuardCF STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) target_compile_definitions(Runtime.ServerGC.GuardCF PRIVATE -DFEATURE_SVR_GC) set_target_properties(Runtime.ServerGC.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) - target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects) + target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects.GuardCF) if (CLR_CMAKE_TARGET_ARCH_AMD64) add_library(Runtime.VxsortEnabled.GuardCF STATIC ${VXSORT_SOURCES}) @@ -130,4 +130,4 @@ if (CLR_CMAKE_TARGET_ARCH_AMD64) if (CLR_CMAKE_TARGET_WIN32) install_static_library(Runtime.VxsortEnabled.GuardCF aotsdk nativeaot) endif (CLR_CMAKE_TARGET_WIN32) -endif (CLR_CMAKE_TARGET_ARCH_AMD64) \ No newline at end of file +endif (CLR_CMAKE_TARGET_ARCH_AMD64) diff --git a/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt index b9d2c3f5c3c14..e6738df3e4200 100644 --- a/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt @@ -6,6 +6,7 @@ project(PortableRuntime) add_definitions(-DUSE_PORTABLE_HELPERS) add_library(PortableRuntime STATIC ${COMMON_RUNTIME_SOURCES} ${PORTABLE_RUNTIME_SOURCES}) +target_link_libraries(PortableRuntime PRIVATE minipal_objects) # Get the current list of definitions get_compile_definitions(DEFINITIONS) diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index e374b1ce2edf2..7503fd76d4487 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20) include(CheckCCompilerFlag) -project(CoreFX C) +project(LibsNative C) if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") # This is our root CMakeList.txt, so we need to set up some global settings and include the minipal here. diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index 38ec063bd5da1..e244ac80bb37e 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -2,6 +2,13 @@ include(configure.cmake) # Provide an object library for scenarios where we ship static libraries add_library(minipal_objects OBJECT +cpufeatures.c +random.c +time.c +unicodedata.c +utf8.c) + +add_library(minipal_objects.GuardCF OBJECT cpufeatures.c random.c time.c @@ -9,11 +16,15 @@ add_library(minipal_objects OBJECT utf8.c) target_include_directories(minipal_objects PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(minipal_objects.GuardCF PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +set_target_properties(minipal_objects.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) # Provide a static library for our shared library and executable scenarios # for easier usability. add_library(minipal STATIC) -target_link_libraries(minipal PRIVATE minipal_objects) +target_link_libraries(minipal PRIVATE minipal_objects.GuardCF) +set_target_properties(minipal PROPERTIES CLR_CONTROL_FLOW_GUARD ON) add_library(minipal_sanitizer_support OBJECT - sansupport.c) \ No newline at end of file + sansupport.c) +set_target_properties(minipal_sanitizer_support PROPERTIES CLR_CONTROL_FLOW_GUARD ON) From b8fab9e22aca8456a26411ce7ebb33071d7399ec Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 18 Sep 2024 11:43:42 -0700 Subject: [PATCH 05/13] Fix defined/undefined 0/1 mismatch --- src/native/minipal/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index fa4b306898eaf..38f2105509552 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -95,7 +95,7 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 { return 0; } -#elif defined(HAVE_BCRYPT_H) +#elif HAVE_BCRYPT_H NTSTATUS status = BCryptGenRandom(NULL, buffer, (ULONG)bufferLength, BCRYPT_USE_SYSTEM_PREFERRED_RNG); return BCRYPT_SUCCESS(status) ? 1 : 0; #else From 3da565cb9c6a4b7ced399146f5a51d9bde415c60 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 18 Sep 2024 16:13:27 -0700 Subject: [PATCH 06/13] Fix return value --- src/native/minipal/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index 38f2105509552..3c2b33ac7463b 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -97,7 +97,7 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 } #elif HAVE_BCRYPT_H NTSTATUS status = BCryptGenRandom(NULL, buffer, (ULONG)bufferLength, BCRYPT_USE_SYSTEM_PREFERRED_RNG); - return BCRYPT_SUCCESS(status) ? 1 : 0; + return BCRYPT_SUCCESS(status) ? 0 : -1; #else static volatile int rand_des = -1; From a3e8aa349c4d0269165b193f13f3c0dac9e79bf3 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 18 Sep 2024 16:16:08 -0700 Subject: [PATCH 07/13] Try linking in minipal into more places in Mono that need it --- src/mono/mono/mini/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 8567ca7003b90..aeac00399e94e 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -369,10 +369,10 @@ if(NOT DISABLE_SHARED_LIBS) list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) endif() if(HOST_WIN32) - list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared minipal) target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) else() - list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects minipal) target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) endif() target_include_directories (monosgen-shared PRIVATE monoapi) @@ -436,7 +436,7 @@ if(NOT DISABLE_SHARED_LIBS) 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) + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers minipal) if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS zlib) endif() From f5e87aaacd5c9a66b16d33051486b6125f15542e Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 19 Sep 2024 18:14:39 +0000 Subject: [PATCH 08/13] Link static mono runtime against the minipal objects. --- src/mono/mono/mini/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index aeac00399e94e..8a594cb1c0bbd 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -337,7 +337,7 @@ endif() add_library(monosgen-static STATIC $ $ $ $ $) set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME}) -target_link_libraries(monosgen-static PRIVATE dn-containers minipal) +target_link_libraries(monosgen-static PRIVATE dn-containers minipal_objects) if(DISABLE_COMPONENTS OR AOT_COMPONENTS) # add component fallback stubs into static mono library when components have been disabled. From 4364395ad09317b2ee191fc4b4e61b8c76280fcb Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 19 Sep 2024 22:52:10 +0000 Subject: [PATCH 09/13] Don't use HOST_WINDOWS check in minipal as Mono's build doesn't set it. --- src/native/minipal/configure.cmake | 1 + src/native/minipal/minipalconfig.h.in | 1 + src/native/minipal/time.c | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/native/minipal/configure.cmake b/src/native/minipal/configure.cmake index 666490b273f74..8a5dd2346a0e0 100644 --- a/src/native/minipal/configure.cmake +++ b/src/native/minipal/configure.cmake @@ -7,6 +7,7 @@ check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME) check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF) check_symbol_exists(O_CLOEXEC fcntl.h HAVE_O_CLOEXEC) +check_include_files("windows.h" HAVE_WINDOWS_H) check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) check_symbol_exists( diff --git a/src/native/minipal/minipalconfig.h.in b/src/native/minipal/minipalconfig.h.in index d550d2e3d286a..00764722ef1b8 100644 --- a/src/native/minipal/minipalconfig.h.in +++ b/src/native/minipal/minipalconfig.h.in @@ -8,5 +8,6 @@ #cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP #cmakedefine01 BIGENDIAN #cmakedefine01 HAVE_BCRYPT_H +#cmakedefine01 HAVE_WINDOWS_H #endif diff --git a/src/native/minipal/time.c b/src/native/minipal/time.c index 043373747f8ef..ac4eabc8c02ad 100644 --- a/src/native/minipal/time.c +++ b/src/native/minipal/time.c @@ -4,7 +4,7 @@ #include #include -#ifdef HOST_WINDOWS +#ifdef HAVE_WINDOWS_H #include @@ -22,7 +22,7 @@ int64_t minipal_hires_tick_frequency() return ts.QuadPart; } -#else // HOST_WINDOWS +#else // HAVE_WINDOWS_H #include "minipalconfig.h" @@ -74,11 +74,11 @@ int64_t minipal_hires_ticks(void) #endif } -#endif // !HOST_WINDOWS +#endif // !HAVE_WINDOWS_H void minipal_microdelay(uint32_t usecs, uint32_t* usecsSinceYield) { -#ifdef HOST_WINDOWS +#ifdef HAVE_WINDOWS_H if (usecs > 1000) { SleepEx(usecs / 1000, FALSE); From d581118f5818b001ff4726f5fff5aaa846190a31 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 19 Sep 2024 22:53:22 +0000 Subject: [PATCH 10/13] PR feedback --- src/mono/mono/mini/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 8a594cb1c0bbd..35f3fdbb1cfcd 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -335,9 +335,9 @@ if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() -add_library(monosgen-static STATIC $ $ $ $ $) +add_library(monosgen-static STATIC $ $ $ $ $ $) set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME}) -target_link_libraries(monosgen-static PRIVATE dn-containers minipal_objects) +target_link_libraries(monosgen-static PRIVATE dn-containers) if(DISABLE_COMPONENTS OR AOT_COMPONENTS) # add component fallback stubs into static mono library when components have been disabled. From e14bc45695eaa4e1b6ebe89442f04d5b9ea1e002 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 19 Sep 2024 23:22:33 +0000 Subject: [PATCH 11/13] ifdef/if again --- src/native/minipal/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/minipal/time.c b/src/native/minipal/time.c index ac4eabc8c02ad..a8c3d13370e1b 100644 --- a/src/native/minipal/time.c +++ b/src/native/minipal/time.c @@ -4,7 +4,7 @@ #include #include -#ifdef HAVE_WINDOWS_H +#if HAVE_WINDOWS_H #include @@ -78,7 +78,7 @@ int64_t minipal_hires_ticks(void) void minipal_microdelay(uint32_t usecs, uint32_t* usecsSinceYield) { -#ifdef HAVE_WINDOWS_H +#if HAVE_WINDOWS_H if (usecs > 1000) { SleepEx(usecs / 1000, FALSE); From 452c747136ad4f364521c15fe417ecde957f9034 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 20 Sep 2024 01:10:11 +0000 Subject: [PATCH 12/13] Add missing include --- src/native/minipal/time.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/native/minipal/time.c b/src/native/minipal/time.c index a8c3d13370e1b..8051731b7d13b 100644 --- a/src/native/minipal/time.c +++ b/src/native/minipal/time.c @@ -3,6 +3,7 @@ #include #include +#include "minipalconfig.h" #if HAVE_WINDOWS_H From aca4b1815269af51342ec6b29f0508fab1860443 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 20 Sep 2024 11:05:46 -0700 Subject: [PATCH 13/13] Install source pdbs for nativeaot --- .../nativeaot/Runtime/Full/CMakeLists.txt | 11 +++++--- src/native/minipal/CMakeLists.txt | 27 +++++++++---------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt index 936ee522ac417..9f569c5078fdc 100644 --- a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt @@ -28,11 +28,11 @@ endif (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.WorkstationGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${RUNTIME_ARCH_ASM_OBJECTS}) add_dependencies(Runtime.WorkstationGC aot_eventing_headers) -target_link_libraries(Runtime.WorkstationGC PRIVATE minipal_objects) +target_link_libraries(Runtime.WorkstationGC PRIVATE minipal_objects_no_lto) add_library(Runtime.ServerGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) add_dependencies(Runtime.ServerGC aot_eventing_headers) -target_link_libraries(Runtime.ServerGC PRIVATE minipal_objects) +target_link_libraries(Runtime.ServerGC PRIVATE minipal_objects_no_lto) add_library(standalonegc-disabled STATIC ${STANDALONEGC_DISABLED_SOURCES}) add_dependencies(standalonegc-disabled aot_eventing_headers) @@ -62,12 +62,16 @@ if (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.ServerGC.GuardCF STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) target_compile_definitions(Runtime.ServerGC.GuardCF PRIVATE -DFEATURE_SVR_GC) set_target_properties(Runtime.ServerGC.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) - target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects.GuardCF) + target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects_no_lto) if (CLR_CMAKE_TARGET_ARCH_AMD64) add_library(Runtime.VxsortEnabled.GuardCF STATIC ${VXSORT_SOURCES}) set_target_properties(Runtime.VxsortEnabled.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) endif (CLR_CMAKE_TARGET_ARCH_AMD64) + + set_target_properties(minipal_objects_no_lto PROPERTIES + COMPILE_PDB_NAME "minipal" + COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$") endif (CLR_CMAKE_TARGET_WIN32) # Get the current list of definitions @@ -123,6 +127,7 @@ if (CLR_CMAKE_TARGET_WIN32) add_dependencies(Runtime.ServerGC.GuardCF aot_eventing_headers) install_static_library(standalonegc-disabled.GuardCF aotsdk nativeaot) install_static_library(standalonegc-enabled.GuardCF aotsdk nativeaot) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$/minipal.pdb" DESTINATION aotsdk COMPONENT nativeaot) endif (CLR_CMAKE_TARGET_WIN32) if (CLR_CMAKE_TARGET_ARCH_AMD64) install_static_library(Runtime.VxsortEnabled aotsdk nativeaot) diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index e244ac80bb37e..3636298716f4d 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -1,29 +1,26 @@ include(configure.cmake) -# Provide an object library for scenarios where we ship static libraries -add_library(minipal_objects OBJECT -cpufeatures.c -random.c -time.c -unicodedata.c -utf8.c) - -add_library(minipal_objects.GuardCF OBJECT +set(SOURCES cpufeatures.c random.c time.c unicodedata.c - utf8.c) + utf8.c +) + +# Provide an object library for scenarios where we ship static libraries +include_directories(${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +add_library(minipal_objects OBJECT ${SOURCES}) +set_target_properties(minipal_objects PROPERTIES CLR_CONTROL_FLOW_GUARD ON) -target_include_directories(minipal_objects PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -target_include_directories(minipal_objects.GuardCF PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -set_target_properties(minipal_objects.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) +add_library(minipal_objects_no_lto OBJECT ${SOURCES}) +set_target_properties(minipal_objects_no_lto PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF CLR_CONTROL_FLOW_GUARD ON) # Provide a static library for our shared library and executable scenarios # for easier usability. add_library(minipal STATIC) -target_link_libraries(minipal PRIVATE minipal_objects.GuardCF) -set_target_properties(minipal PROPERTIES CLR_CONTROL_FLOW_GUARD ON) +target_link_libraries(minipal PRIVATE minipal_objects) add_library(minipal_sanitizer_support OBJECT sansupport.c)