File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -245,6 +245,12 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
245245# Check whether -fno-lto is supported.
246246check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)
247247
248+ # Check whether -Wl,--as-needed is supported.
249+ check_linker_flag(C "-Wl,--as-needed" LINKER_SUPPORTS_AS_NEEDED)
250+ if (LINKER_SUPPORTS_AS_NEEDED)
251+ set (LINKER_AS_NEEDED_OPT "-Wl,--as-needed" )
252+ endif ()
253+
248254# Different platform may have different name for the POSIX thread library.
249255# For example, libpthread.a on AIX. Search for it as it is needed when
250256# building the shared flang_rt.runtime.so.
@@ -295,7 +301,6 @@ elseif (FLANG_RT_GCC_RESOURCE_DIR)
295301endif ()
296302
297303
298-
299304#####################
300305# Build Preparation #
301306#####################
Original file line number Diff line number Diff line change @@ -186,6 +186,17 @@ function (add_flangrt_library name)
186186 else ()
187187 set_target_properties (${tgtname} PROPERTIES FOLDER "Flang-RT/Libraries" )
188188 endif ()
189+
190+ # flang-rt libraries must not depend on libc++/libstdc++,
191+ # so set the linker language to C to avoid the unnecessary
192+ # library dependence. Note that libc++/libstdc++ may still
193+ # come through CMAKE_CXX_IMPLICIT_LINK_LIBRARIES.
194+ set_target_properties (${tgtname} PROPERTIES LINKER_LANGUAGE C)
195+ # Use --as-needed to avoid unnecessary dependencies.
196+ if (LINKER_AS_NEEDED_OPT)
197+ set_property (TARGET ${tgtname} APPEND_STRING PROPERTY
198+ LINK_FLAGS "${LINKER_AS_NEEDED_OPT} " )
199+ endif ()
189200 endforeach ()
190201
191202 # Define how to compile and link the library.
You can’t perform that action at this time.
0 commit comments