Skip to content

Commit

Permalink
Compile native code with -ffunction-sections (#79322)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Dec 10, 2022
1 parent 05c2288 commit dbb8f3f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ elseif (CLR_CMAKE_HOST_UNIX)
list(JOIN CLR_LINK_SANITIZERS "," CLR_LINK_SANITIZERS_OPTIONS)
list(APPEND CLR_SANITIZE_LINK_OPTIONS "-fsanitize=${CLR_LINK_SANITIZERS_OPTIONS}")

# -fdata-sections -ffunction-sections: each function has own section instead of one per .o file (needed for --gc-sections)
# -O1: optimization level used instead of -O0 to avoid compile error "invalid operand for inline asm constraint"
add_compile_options("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;--ffunction-sections;-O1>")
add_compile_options("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;-O1>")
add_linker_flag("${CLR_SANITIZE_LINK_OPTIONS}" DEBUG CHECKED)
# -Wl and --gc-sections: drop unused sections\functions (similar to Windows /Gy function-level-linking)
add_linker_flag("-Wl,--gc-sections" DEBUG CHECKED)
Expand Down Expand Up @@ -478,6 +477,12 @@ if (CLR_CMAKE_HOST_UNIX)

# We mark the function which needs exporting with DLLEXPORT
add_compile_options(-fvisibility=hidden)

# Separate functions so linker can remove them. But not on tvOS because
# -ffunction-sections is not supported with -fembed-bitcode.
if (NOT CLR_CMAKE_HOST_TVOS)
add_compile_options(-ffunction-sections)
endif()

# Specify the minimum supported version of macOS
# Mac Catalyst needs a special CFLAG, exclusive with mmacosx-version-min
Expand Down

0 comments on commit dbb8f3f

Please sign in to comment.