@@ -96,8 +96,8 @@ if (LLVM_TREE_AVAILABLE)
9696 # Despite Clang in the name, get_clang_resource_dir does not depend on Clang
9797 # being added to the build. Flang uses the same resource dir as clang.
9898 include (GetClangResourceDir)
99- get_clang_resource_dir(FLANG_RT_OUTPUT_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR} /.." )
100- get_clang_resource_dir(FLANG_RT_INSTALL_PATH )
99+ get_clang_resource_dir(FLANG_RT_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR} /.." )
100+ get_clang_resource_dir(FLANG_RT_INSTALL_RESOURCE_PATH )
101101else ()
102102 # In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be
103103 # read-only and/or shared by multiple runtimes with different build
@@ -106,29 +106,27 @@ else ()
106106 # For the install prefix, still use the resource dir assuming that Flang will
107107 # be installed there using the same prefix. This is to not have a difference
108108 # between bootstrap and standalone runtimes builds.
109- set (FLANG_RT_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR} " )
110- set (FLANG_RT_INSTALL_PATH "${CMAKE_INSTALL_LIBDIR} /clang/${LLVM_VERSION_MAJOR} " )
109+ set (FLANG_RT_OUTPUT_RESOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR} " )
110+ set (FLANG_RT_INSTALL_RESOURCE_PATH "${CMAKE_INSTALL_LIBDIR} /clang/${LLVM_VERSION_MAJOR} " )
111111endif ()
112- cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_DIR )
113- cmake_path(NORMAL_PATH FLANG_RT_INSTALL_PATH )
112+ cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR )
113+ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH )
114114
115115# Determine subdirectories for build output and install destinations.
116+ # FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
117+ # destination because it is not a ld.so default search path.
118+ # The machine where the executable is eventually executed may not be the
119+ # machine where the Flang compiler and its resource dir is installed, so
120+ # setting RPath by the driver is not an solution. It should belong into
121+ # /usr/lib/<triple>/libflang_rt.so, like e.g. libgcc_s.so.
122+ # But the linker as invoked by the Flang driver also requires
123+ # libflang_rt.so to be found when linking and the resource lib dir is
124+ # the only reliable location.
116125get_toolchain_library_subdir(toolchain_lib_subdir)
117- get_system_library_subdir(arch_lib_subdir)
118- extend_path(FLANG_RT_BUILD_TOOLCHAIN_LIB_DIR "${FLANG_RT_OUTPUT_DIR} " "${toolchain_lib_subdir} " )
119- if (LLVM_TREE_AVAILABLE)
120- extend_path(FLANG_RT_BUILD_LIB_DIR "${FLANG_RT_OUTPUT_DIR} " "${arch_lib_subdir} " )
121- else ()
122- # Only building for a single target, so no need to write into a arch-specific subirectory.
123- extend_path(FLANG_RT_BUILD_LIB_DIR "${FLANG_RT_OUTPUT_DIR} " "${CMAKE_INSTALL_LIBDIR} " )
124- endif ()
125- extend_path(FLANG_RT_INSTALL_TOOLCHAIN_LIB_DIR "${FLANG_RT_INSTALL_PATH} " "${toolchain_lib_subdir} " )
126- extend_path(FLANG_RT_INSTALL_LIB_DIR "${FLANG_RT_INSTALL_PATH} " "${arch_lib_subdir} " )
127-
128- cmake_path(NORMAL_PATH FLANG_RT_BUILD_TOOLCHAIN_LIB_DIR)
129- cmake_path(NORMAL_PATH FLANG_RT_BUILD_LIB_DIR)
130- cmake_path(NORMAL_PATH FLANG_RT_INSTALL_TOOLCHAIN_LIB_DIR)
131- cmake_path(NORMAL_PATH FLANG_RT_INSTALL_LIB_DIR)
126+ extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR} " "${toolchain_lib_subdir} " )
127+ extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH} " "${toolchain_lib_subdir} " )
128+ cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR)
129+ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
132130
133131
134132#################
@@ -146,7 +144,13 @@ if (WIN32)
146144 # Windows DLL currently not implemented.
147145 set (FLANG_RT_ENABLE_SHARED OFF )
148146else ()
149- option (FLANG_RT_ENABLE_SHARED "Build Flang-RT as a shared library." ON )
147+ # TODO: Enable by default to increase test coverage, and which version of the
148+ # library should be the user's choice anyway.
149+ # Currently, the Flang driver adds `-L"libdir" -lflang_rt` as linker
150+ # argument, which leaves the choice which library to use to the linker.
151+ # Since most linkers prefer the shared library, this would constitute a
152+ # breaking change unless the driver is changed.
153+ option (FLANG_RT_ENABLE_SHARED "Build Flang-RT as a shared library." OFF )
150154endif ()
151155if (NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
152156 message (FATAL_ERROR "
0 commit comments