diff --git a/.circleci/config.yml b/.circleci/config.yml index b21df673b30..b976ac94312 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -143,7 +143,7 @@ jobs: name: Build Hermes for Linux command: | cd "$HERMES_WS_DIR" - cmake -S hermes -B build_release -G Ninja -DHERMES_STATIC_LINK=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-s -DCMAKE_C_FLAGS=-s + cmake -S hermes -B build_release -G Ninja -DHERMES_STATIC_LINK=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True -DCMAKE_CXX_FLAGS=-s -DCMAKE_C_FLAGS=-s cd build_release ninja github-cli-release - run: @@ -399,7 +399,7 @@ jobs: $Env:PATH += ";$Env:CMAKE_DIR;$Env:MSBUILD_DIR" $Env:ICU_ROOT = "$Env:HERMES_WS_DIR\icu" cd $Env:HERMES_WS_DIR - cmake -S hermes -B build_release -G 'Visual Studio 16 2019' -Ax64 -DCMAKE_BUILD_TYPE=Release -DHERMES_ENABLE_WIN10_ICU_FALLBACK=OFF -DHERMES_GITHUB_RESOURCE_DIR="$Env:HERMES_WS_DIR\deps" + cmake -S hermes -B build_release -G 'Visual Studio 16 2019' -Ax64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True -DHERMES_ENABLE_WIN10_ICU_FALLBACK=OFF -DHERMES_GITHUB_RESOURCE_DIR="$Env:HERMES_WS_DIR\deps" if (-not $?) { throw "Failed to configure Hermes" } cd build_release cmake --build . --target github-cli-release --config Release diff --git a/CMakeLists.txt b/CMakeLists.txt index 8007b243d7b..0e7a421180e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,12 +292,15 @@ if (HERMES_STATIC_LINK) set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() -# Check if the linker supports --gc-sections +# Check if the linker supports --gc-sections and ICF. # We can't simply CHECK_CXX_COMPILER_FLAG("-Wl,--gc-sections" ..) because CMake # will compile and link separately and only passes the flag during compilation. +# TODO: Use check_linker_flag once we have CMake 3.18. set(OLD_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections") +set(CMAKE_EXE_LINKER_FLAGS "${OLD_CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") CHECK_CXX_COMPILER_FLAG("" HAVE_GC_SECTIONS) +set(CMAKE_EXE_LINKER_FLAGS "${OLD_CMAKE_EXE_LINKER_FLAGS} -Wl,--icf=safe") +CHECK_CXX_COMPILER_FLAG("" HAVE_ICF) set(CMAKE_EXE_LINKER_FLAGS "${OLD_CMAKE_EXE_LINKER_FLAGS}") if(HAVE_GC_SECTIONS) @@ -306,6 +309,11 @@ if(HAVE_GC_SECTIONS) list(APPEND HERMES_EXTRA_LINKER_FLAGS "LINKER:--gc-sections") endif() +if(HAVE_ICF) + add_flag_if_supported("-faddrsig" ADDRSIG) + list(APPEND HERMES_EXTRA_LINKER_FLAGS "LINKER:--icf=safe") +endif() + # Make the HERMES_RELEASE_VERSION accessible for version printing in C++. add_definitions(-DHERMES_RELEASE_VERSION="${HERMES_RELEASE_VERSION}") @@ -423,13 +431,6 @@ else() set(HERMES_ASSUMED_BUILD_MODE_IN_LIT_TEST "opt") endif() -if (NOT (GENERATOR_IS_MULTI_CONFIG OR CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_COMPILER_IS_GNUCXX)) - # Enable LTO if we are not multi config generator and not a DEBUG build - # and not GCC - # GCC currently fails to link Hermes with LTO (see t16557748) - option(HERMES_ENABLE_LTO "Build Hermes with LTO" ON) -endif() - if (GCC_COMPATIBLE) # Don't export symbols unless we explicitly say so set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") diff --git a/android/hermes/build.gradle b/android/hermes/build.gradle index 23aed786a1f..34d89fdbc97 100644 --- a/android/hermes/build.gradle +++ b/android/hermes/build.gradle @@ -22,6 +22,7 @@ android { arguments "-DHERMES_FACEBOOK_BUILD=${rootProject.ext.facebookBuild}" arguments "-DANDROID_STL=c++_shared" arguments "-DANDROID_PIE=True" + arguments "-DANDROID_LD=lld" arguments "-DIMPORT_HERMESC=${rootProject.ext.hermesC}" arguments "-DFBSOURCE_DIR=${rootProject.ext.fbsource}" arguments "-DHERMES_SLOW_DEBUG=False"