[libclc] add --only-needed to llvm-link when INTERNALIZE flag is set (#130871)

When -internalize flag is passed to llvm-link, we only need to link in
needed symbols. This PR reduces size of linked bitcode, e.g. by removing
following symbols:

    _Z12__clc_sw_fmaDv16_fS_S_
    _Z12__clc_sw_fmaDv2_fS_S_
    _Z12__clc_sw_fmaDv3_fS_S_
    _Z12__clc_sw_fmaDv4_fS_S_
    _Z12__clc_sw_fmaDv8_fS_S_
    _Z12__clc_sw_fmafff
This commit is contained in:
Wenju He 2025-03-20 13:25:55 +00:00 committed by GitHub
parent 345748e027
commit cb1e91c18d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -107,9 +107,13 @@ function(link_bc)
set( LINK_INPUT_ARG "@${RSP_FILE}" )
endif()
if( ARG_INTERNALIZE )
set( link_flags --internalize --only-needed )
endif()
add_custom_command(
OUTPUT ${ARG_TARGET}.bc
COMMAND ${llvm-link_exe} $<$<BOOL:${ARG_INTERNALIZE}>:--internalize> -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
COMMAND ${llvm-link_exe} ${link_flags} -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE}
)