File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,12 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
244244# Check whether -fno-lto is supported.
245245check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)
246246
247+ # Check whether -Wl,--as-needed is supported.
248+ check_linker_flag(C "LINKER:--as-needed" LINKER_SUPPORTS_AS_NEEDED)
249+ if (LINKER_SUPPORTS_AS_NEEDED)
250+ set (LINKER_AS_NEEDED_OPT "LINKER:--as-needed" )
251+ endif ()
252+
247253# Different platform may have different name for the POSIX thread library.
248254# For example, libpthread.a on AIX. Search for it as it is needed when
249255# building the shared flang_rt.runtime.so.
Original file line number Diff line number Diff line change @@ -145,6 +145,20 @@ function (add_flangrt_library name)
145145 if (Threads_FOUND)
146146 target_link_libraries (${name_shared} PUBLIC Threads::Threads)
147147 endif ()
148+
149+ # Special dependencies handling for shared libraries only:
150+ #
151+ # flang-rt libraries must not depend on libc++/libstdc++,
152+ # so set the linker language to C to avoid the unnecessary
153+ # library dependence. Note that libc++/libstdc++ may still
154+ # come through CMAKE_CXX_IMPLICIT_LINK_LIBRARIES.
155+ set_target_properties (${name_shared} PROPERTIES LINKER_LANGUAGE C)
156+ # Use --as-needed to avoid unnecessary dependencies.
157+ if (LINKER_AS_NEEDED_OPT)
158+ target_link_options (${name_shared} BEFORE PRIVATE
159+ "${LINKER_AS_NEEDED_OPT} "
160+ )
161+ endif ()
148162 endif ()
149163
150164 if (libtargets)
You can’t perform that action at this time.
0 commit comments