Skip to content

Commit

Permalink
Clean up setting up GC sections
Browse files Browse the repository at this point in the history
Summary:
1. Use target_link_options instead of supplying the linker argument as
a dependency
2. Enable GC sections for executables
3. Enable ffunction-sections and fdata-sections
4. Change the setup so it is easier to include other linker flags (like
ICF in the next diff)

Reviewed By: jpporto

Differential Revision: D35347443

fbshipit-source-id: 2c255e584d30f95504c8c9c0142f44561c47be3f
  • Loading branch information
neildhar authored and facebook-github-bot committed Apr 5, 2022
1 parent b372061 commit 359b0ce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ endif()
target_link_libraries(libhermes
jsi
${LIBHERMES_VM_DEP}
# Linker flags
${OPTIONAL_GC_SECTIONS}
)
target_link_options(libhermes PRIVATE ${HERMES_EXTRA_LINKER_FLAGS})

# Export the required header directory
target_include_directories(libhermes PUBLIC ..)
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.8.0)
cmake_minimum_required(VERSION 3.13.0)

# Set the VERSION variables based on the project command
if (POLICY CMP0048)
Expand Down Expand Up @@ -301,9 +301,9 @@ CHECK_CXX_COMPILER_FLAG("" HAVE_GC_SECTIONS)
set(CMAKE_EXE_LINKER_FLAGS "${OLD_CMAKE_EXE_LINKER_FLAGS}")

if(HAVE_GC_SECTIONS)
set(OPTIONAL_GC_SECTIONS "-Wl,--gc-sections")
else()
set(OPTIONAL_GC_SECTIONS "")
add_flag_if_supported("-ffunction-sections" FUNCTION_SECTIONS)
add_flag_if_supported("-fdata-sections" DATA_SECTIONS)
list(APPEND HERMES_EXTRA_LINKER_FLAGS "LINKER:--gc-sections")
endif()

# Make the HERMES_RELEASE_VERSION accessible for version printing in C++.
Expand Down
1 change: 1 addition & 0 deletions cmake/modules/Hermes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function(add_hermes_executable name)
cmake_parse_arguments(ARG "" "" "LINK_LIBS" ${ARGN})
add_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
target_link_libraries(${name} ${ARG_LINK_LIBS} ${HERMES_LINK_COMPONENTS})
target_link_options(${name} PRIVATE ${HERMES_EXTRA_LINKER_FLAGS})
hermes_update_compile_flags(${name})
endfunction(add_hermes_executable)

Expand Down

0 comments on commit 359b0ce

Please sign in to comment.