Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,24 @@ function(link_natvis_sources_for_target targetName linkKind)
endforeach()
endfunction()

# Enable linker dead code elimination for the given target in CHECKED/RELEASE/RELWITHDEBINFO
function(enable_dead_code_elimination targetName)
set(dce_configs "$<OR:$<CONFIG:Checked>,$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>")

if (MSVC)
target_link_options(${targetName} PRIVATE $<${dce_configs}:/OPT:REF>)
return()
endif()

target_compile_options(${targetName} PRIVATE $<${dce_configs}:-fdata-sections>)

if (CLR_CMAKE_HOST_APPLE)
target_link_options(${targetName} PRIVATE $<${dce_configs}:LINKER:-dead_strip>)
else()
target_link_options(${targetName} PRIVATE $<${dce_configs}:LINKER:--gc-sections>)
endif()
endfunction()

# Add sanitizer runtime support code to the target.
function(add_sanitizer_runtime_support targetName)
# Add sanitizer support functions.
Expand Down
1 change: 1 addition & 0 deletions src/native/corehost/apphost/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_executable(apphost ${SOURCES} ${RESOURCES})
target_link_libraries(apphost PRIVATE hostmisc fxr_resolver)

add_sanitizer_runtime_support(apphost)
enable_dead_code_elimination(apphost)

if(NOT CLR_CMAKE_TARGET_WIN32)
disable_pax_mprotect(apphost)
Expand Down
1 change: 1 addition & 0 deletions src/native/corehost/dotnet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_executable(dotnet ${SOURCES})
target_link_libraries(dotnet PRIVATE hostmisc fxr_resolver)

add_sanitizer_runtime_support(dotnet)
enable_dead_code_elimination(dotnet)

if(NOT CLR_CMAKE_TARGET_WIN32)
disable_pax_mprotect(dotnet)
Expand Down
2 changes: 2 additions & 0 deletions src/native/corehost/nethost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ target_link_libraries(libnethost PRIVATE hostmisc::public fxr_resolver)
target_compile_definitions(nethost PRIVATE FEATURE_LIBHOST NETHOST_EXPORT)
target_compile_definitions(libnethost PRIVATE FEATURE_LIBHOST NETHOST_EXPORT)

enable_dead_code_elimination(nethost)

set_target_properties(nethost PROPERTIES MACOSX_RPATH TRUE)
set_target_properties(libnethost PROPERTIES MACOSX_RPATH TRUE)
set_target_properties(libnethost PROPERTIES PREFIX "")
Expand Down
Loading