Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile the minipal as an object and static library #107889

Merged
merged 20 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ef0a7c2
Compile the repo minipal as an object and static library for usage ac…
jkoritzinsky Sep 16, 2024
5e1a9b6
Don't refer to createdump_static on Windows, it doesn't exist
jkoritzinsky Sep 16, 2024
2bf6f33
Add implementation of the minipal random functions for Windows to get…
jkoritzinsky Sep 17, 2024
6caa935
PR feedback
jkoritzinsky Sep 17, 2024
b8fab9e
Fix defined/undefined 0/1 mismatch
jkoritzinsky Sep 18, 2024
3da565c
Fix return value
jkoritzinsky Sep 18, 2024
a3e8aa3
Try linking in minipal into more places in Mono that need it
jkoritzinsky Sep 18, 2024
f5e87aa
Link static mono runtime against the minipal objects.
jkoritzinsky Sep 19, 2024
4364395
Don't use HOST_WINDOWS check in minipal as Mono's build doesn't set it.
jkoritzinsky Sep 19, 2024
d581118
PR feedback
jkoritzinsky Sep 19, 2024
e14bc45
ifdef/if again
jkoritzinsky Sep 19, 2024
452c747
Add missing include
jkoritzinsky Sep 20, 2024
aca4b18
Install source pdbs for nativeaot
jkoritzinsky Sep 20, 2024
a719a4c
Merge branch 'minipal-objlib' of github.com:jkoritzinsky/runtime into…
jkoritzinsky Sep 20, 2024
1833255
Merge branch 'main' of github.com:dotnet/runtime into minipal-objlib
jkoritzinsky Oct 7, 2024
07acf80
Merge branch 'main' of https://github.com/dotnet/runtime into minipal…
jkoritzinsky Oct 15, 2024
e38dde9
Link System.Native's static lib to the minipal_objects obj library
jkoritzinsky Oct 15, 2024
e4f476d
Reorder libraries on the command line when linking for Unix.
jkoritzinsky Oct 16, 2024
aea3a45
PR feedback
jkoritzinsky Oct 17, 2024
0ab3b83
Exclude minipal_sanitizer_support from all
jkoritzinsky Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ endfunction()
function(add_sanitizer_runtime_support targetName)
# Add sanitizer support functions.
if (CLR_CMAKE_ENABLE_ASAN)
target_sources(${targetName} PRIVATE "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:${CLR_SRC_NATIVE_DIR}/minipal/asansupport.cpp>")
target_link_libraries(${targetName} PRIVATE $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:minipal_sanitizer_support>)
endif()
endfunction()

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -88,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 @@ -104,6 +104,8 @@ endif(CLR_CMAKE_HOST_OSX)

endif(CLR_CMAKE_HOST_WIN32)

target_link_libraries(createdump PRIVATE minipal)

if (CLR_CMAKE_HOST_APPLE)
adhoc_sign_with_entitlements(createdump "${CLR_ENG_NATIVE_DIR}/createdump-entitlements.plist")
endif()
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/minipal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ if (CLR_CMAKE_HOST_UNIX)
else (CLR_CMAKE_HOST_UNIX)
add_subdirectory(Windows)
endif (CLR_CMAKE_HOST_UNIX)

10 changes: 1 addition & 9 deletions src/coreclr/minipal/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 2 additions & 9 deletions src/coreclr/minipal/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

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)
Expand Down Expand Up @@ -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)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

if (CLR_CMAKE_TARGET_ARCH_AMD64)
add_library(Runtime.VxsortEnabled.GuardCF STATIC ${VXSORT_SOURCES})
Expand Down
18 changes: 0 additions & 18 deletions src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/tools/aot/jitinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)
1 change: 1 addition & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions src/mono/mono/eglib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ 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>)
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.
Expand Down
9 changes: 7 additions & 2 deletions src/native/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ include(CheckCCompilerFlag)

project(CoreFX C)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

include(../../../eng/native/configurepaths.cmake)
include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake)
if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
# 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})

Expand Down
15 changes: 1 addition & 14 deletions src/native/libs/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -126,6 +112,7 @@ if (GEN_SHARED_LIB)

target_link_libraries(System.Native
PRIVATE
minipal
${NATIVE_LIBS_EXTRA}
)

Expand Down
19 changes: 19 additions & 0 deletions src/native/minipal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions src/native/minipal/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/native/minipal/minipalconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#cmakedefine01 HAVE_O_CLOEXEC
#cmakedefine01 HAVE_SYSCTLBYNAME
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 BIGENDIAN

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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);
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

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
Expand All @@ -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) {
}
4 changes: 2 additions & 2 deletions src/native/minipal/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/native/minipal/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading