Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Enable LTO when building corebundle (#26697)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung committed Sep 18, 2019
1 parent 27ab2bd commit fa42bdf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions configureoptimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ elseif(CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-fno-unroll-loops)
add_compile_options(-fno-asynchronous-unwind-tables)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
if (HAVE_LTO)
# Set properties instead of using add_compile_options to allow overriding
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
endif()
else()
add_compile_options($<$<CONFIG:Release>:-O3>)
endif()
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/hosts/unixcorebundle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ _add_executable(corebundle

set_property(TARGET corebundle APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--export-dynamic") # Necessary to get symbols exported from executable

if (HAVE_LTO)
target_compile_options(corebundle PRIVATE -flto)
set_property(TARGET corebundle APPEND_STRING PROPERTY LINK_FLAGS " -flto")
endif()

# The following linked options can be inserted into the linker libraries list to
# ensure proper resolving of circular references between a subset of the libraries.
set(START_LIBRARY_GROUP -Wl,--start-group)
Expand Down
3 changes: 3 additions & 0 deletions src/debug/ee/dactable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ extern DWORD gAppDomainTLSIndex;
extern BOOL g_fAppX;
#endif // FEATURE_APPX

#ifdef PLATFORM_UNIX
__attribute__((used))
#endif // PLATFORM_UNIX
DacGlobals g_dacTable;

// DAC global pointer table initialization
Expand Down
3 changes: 3 additions & 0 deletions src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
set(LIBUNWIND_OBJECTS $<TARGET_OBJECTS:libunwind>)
endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)

# Disable LTO in this project, as it results in a size increase
string(REPLACE "-flto" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

add_library(coreclrpal
STATIC
${SOURCES}
Expand Down
5 changes: 4 additions & 1 deletion src/pal/tools/gen-buildsys-clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ then
echo "Specify the clang version to use, split into major and minor version"
echo "Specify the target architecture."
echo "Specify the script directory."
echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG."
echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG."
echo "Optionally specify 'coverage' to enable code coverage build."
echo "Optionally specify 'scan-build' to enable build with clang static analyzer."
echo "Target ninja instead of make. ninja must be on the PATH."
Expand Down Expand Up @@ -108,6 +108,8 @@ llvm_link="$(locate_llvm_exec link)"
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-link"; exit 1; }
llvm_nm="$(locate_llvm_exec nm)"
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-nm"; exit 1; }
llvm_ranlib="$(locate_llvm_exec ranlib)"
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-ranlib"; exit 1; }
if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" -o $OS = "SunOS" ]; then
llvm_objdump="$(locate_llvm_exec objdump)"
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-objdump"; exit 1; }
Expand Down Expand Up @@ -164,6 +166,7 @@ $cmake_command \
"-DCMAKE_AR=$llvm_ar" \
"-DCMAKE_LINKER=$llvm_link" \
"-DCMAKE_NM=$llvm_nm" \
"-DCMAKE_RANLIB=$llvm_ranlib" \
"-DCMAKE_OBJDUMP=$llvm_objdump" \
"-DCMAKE_BUILD_TYPE=$buildtype" \
"-DCLR_CMAKE_ENABLE_CODE_COVERAGE=$code_coverage" \
Expand Down

0 comments on commit fa42bdf

Please sign in to comment.