Skip to content

Commit

Permalink
Merge branch 'minipal-objlib' of github.com:jkoritzinsky/runtime into…
Browse files Browse the repository at this point in the history
… dnmd-in-runtime

# Conflicts:
#	src/native/minipal/CMakeLists.txt
  • Loading branch information
jkoritzinsky committed Sep 20, 2024
2 parents 62efacd + a719a4c commit d5d34df
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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}/$<CONFIG>")
endif (CLR_CMAKE_TARGET_WIN32)

# Get the current list of definitions
Expand Down Expand Up @@ -123,11 +127,12 @@ 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}/$<CONFIG>/minipal.pdb" DESTINATION aotsdk COMPONENT nativeaot)
endif (CLR_CMAKE_TARGET_WIN32)
if (CLR_CMAKE_TARGET_ARCH_AMD64)
install_static_library(Runtime.VxsortEnabled aotsdk nativeaot)
install_static_library(Runtime.VxsortDisabled aotsdk nativeaot)
if (CLR_CMAKE_TARGET_WIN32)
install_static_library(Runtime.VxsortEnabled.GuardCF aotsdk nativeaot)
endif (CLR_CMAKE_TARGET_WIN32)
endif (CLR_CMAKE_TARGET_ARCH_AMD64)
endif (CLR_CMAKE_TARGET_ARCH_AMD64)
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ if(NOT HOST_WIN32)
target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT)
endif()

add_library(monosgen-static STATIC $<TARGET_OBJECTS:eglib_objects> $<TARGET_OBJECTS:utils_objects> $<TARGET_OBJECTS:sgen_objects> $<TARGET_OBJECTS:metadata_objects> $<TARGET_OBJECTS:monosgen-objects>)
add_library(monosgen-static STATIC $<TARGET_OBJECTS:eglib_objects> $<TARGET_OBJECTS:utils_objects> $<TARGET_OBJECTS:sgen_objects> $<TARGET_OBJECTS:metadata_objects> $<TARGET_OBJECTS:monosgen-objects> $<TARGET_OBJECTS:minipal_objects>)
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)

if(DISABLE_COMPONENTS OR AOT_COMPONENTS)
# add component fallback stubs into static mono library when components have been disabled.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 13 additions & 4 deletions src/native/minipal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
include(configure.cmake)

# Provide an object library for scenarios where we ship static libraries
add_library(minipal_objects 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(${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_BINARY_DIR})

target_include_directories(minipal_objects PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_BINARY_DIR})
add_library(minipal_objects OBJECT ${SOURCES})
set_target_properties(minipal_objects 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.
Expand All @@ -17,5 +24,7 @@ target_link_libraries(minipal PRIVATE minipal_objects)

add_library(minipal_sanitizer_support OBJECT
sansupport.c)
set_target_properties(minipal_sanitizer_support PROPERTIES CLR_CONTROL_FLOW_GUARD ON)


add_subdirectory(com)
2 changes: 2 additions & 0 deletions src/native/minipal/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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(
clock_gettime_nsec_np
Expand Down
2 changes: 2 additions & 0 deletions src/native/minipal/minipalconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
#cmakedefine01 HAVE_SYSCTLBYNAME
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 BIGENDIAN
#cmakedefine01 HAVE_BCRYPT_H
#cmakedefine01 HAVE_WINDOWS_H

#endif
20 changes: 16 additions & 4 deletions src/native/minipal/random.c
Original file line number Diff line number Diff line change
@@ -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 <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#if HAVE_BCRYPT_H
#include <windows.h>
#include <bcrypt.h>
#else
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
#if defined(__APPLE__) && __APPLE__
#include <CommonCrypto/CommonRandom.h>
#endif

#include "minipalconfig.h"
#include "random.h"

/*
Expand All @@ -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;
Expand Down Expand Up @@ -86,6 +95,9 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32
{
return 0;
}
#elif HAVE_BCRYPT_H
NTSTATUS status = BCryptGenRandom(NULL, buffer, (ULONG)bufferLength, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
return BCRYPT_SUCCESS(status) ? 0 : -1;
#else

static volatile int rand_des = -1;
Expand Down
9 changes: 5 additions & 4 deletions src/native/minipal/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <assert.h>
#include <minipal/time.h>
#include "minipalconfig.h"

#ifdef HOST_WINDOWS
#if HAVE_WINDOWS_H

#include <Windows.h>

Expand All @@ -22,7 +23,7 @@ int64_t minipal_hires_tick_frequency()
return ts.QuadPart;
}

#else // HOST_WINDOWS
#else // HAVE_WINDOWS_H

#include "minipalconfig.h"

Expand Down Expand Up @@ -74,11 +75,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
#if HAVE_WINDOWS_H
if (usecs > 1000)
{
SleepEx(usecs / 1000, FALSE);
Expand Down

0 comments on commit d5d34df

Please sign in to comment.