pscoro updated this revision to Diff 541544.
pscoro marked an inline comment as done.
pscoro added a comment.
Removed support for "fully standalone" Flang-rt builds (ie CMake builds
targeting llvm-project/flang-rt).
Flang-rt is now buildable via the `llvm` target or the `runtimes` target. See
documentation for more
information.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154869/new/
https://reviews.llvm.org/D154869
Files:
clang/lib/Driver/ToolChains/CommonArgs.cpp
flang-rt/CMakeLists.txt
flang/CMakeLists.txt
flang/cmake/modules/AddFlang.cmake
flang/docs/Flang-rt.md
flang/lib/Decimal/CMakeLists.txt
flang/runtime/CMakeLists.txt
flang/test/CMakeLists.txt
flang/test/Driver/linker-flags.f90
flang/test/lit.cfg.py
flang/tools/flang-driver/CMakeLists.txt
lld/COFF/MinGW.cpp
llvm/CMakeLists.txt
llvm/projects/CMakeLists.txt
runtimes/CMakeLists.txt
Index: runtimes/CMakeLists.txt
===================================================================
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -19,7 +19,7 @@
# We order libraries to mirror roughly how they are layered, except that compiler-rt can depend
# on libc++, so we put it after.
-set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp")
+set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;flang-rt")
set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc")
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
"Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
Index: llvm/projects/CMakeLists.txt
===================================================================
--- llvm/projects/CMakeLists.txt
+++ llvm/projects/CMakeLists.txt
@@ -6,6 +6,7 @@
if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
if((NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/dragonegg) AND
+ (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/flang-rt) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxx) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxxabi) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libunwind) AND
@@ -42,6 +43,8 @@
add_llvm_external_project(dragonegg)
add_llvm_external_project(openmp)
+add_llvm_external_project(flang-rt)
+
if(LLVM_INCLUDE_TESTS)
add_llvm_external_project(cross-project-tests)
endif()
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -149,7 +149,10 @@
# As we migrate runtimes to using the bootstrapping build, the set of default runtimes
# should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
-set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc")
+if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
+ set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind;flang-rt")
+endif()
+set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;flang-rt")
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
"Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
if(LLVM_ENABLE_RUNTIMES STREQUAL "all")
@@ -171,6 +174,11 @@
endif()
endif()
+if ("flang" IN_LIST LLVM_ENABLE_PROJECTS AND NOT "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+ message(STATUS "Enabling flang-rt to be built with the flang project")
+ list(APPEND LLVM_ENABLE_RUNTIMES "flang-rt")
+endif()
+
# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
# `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for
# several reasons:
Index: lld/COFF/MinGW.cpp
===================================================================
--- lld/COFF/MinGW.cpp
+++ lld/COFF/MinGW.cpp
@@ -50,8 +50,7 @@
"libc++",
"libc++abi",
"libFortran_main",
- "libFortranRuntime",
- "libFortranDecimal",
+ "libflang-rt",
"libunwind",
"libmsvcrt",
"libucrtbase",
Index: flang/tools/flang-driver/CMakeLists.txt
===================================================================
--- flang/tools/flang-driver/CMakeLists.txt
+++ flang/tools/flang-driver/CMakeLists.txt
@@ -19,8 +19,7 @@
# These libraries are used in the linker invocation generated by the driver
# (i.e. when constructing the linker job). Without them the driver would be
# unable to generate executables.
- FortranRuntime
- FortranDecimal
+ flang-rt
Fortran_main
)
Index: flang/test/lit.cfg.py
===================================================================
--- flang/test/lit.cfg.py
+++ flang/test/lit.cfg.py
@@ -153,19 +153,16 @@
# the C++ runtime libraries. For this we need a C compiler. If for some reason
# we don't have one, we can just disable the test.
if config.cc:
- libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
- libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a")
+ libruntime = os.path.join(config.flang_lib_dir, "libflang-rt.a")
include = os.path.join(config.flang_src_dir, "include")
if (
os.path.isfile(libruntime)
- and os.path.isfile(libdecimal)
and os.path.isdir(include)
):
config.available_features.add("c-compiler")
tools.append(ToolSubst("%cc", command=config.cc, unresolved="fatal"))
tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
- tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal"))
tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
# Add all the tools and their substitutions (if applicable). Use the search paths provided for
Index: flang/test/Driver/linker-flags.f90
===================================================================
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -24,21 +24,18 @@
! GNU-LABEL: "{{.*}}ld{{(\.exe)?}}"
! GNU-SAME: "[[object_file]]"
! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
+! GNU-SAME: -lflang-rt
! GNU-SAME: -lm
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
! DARWIN-SAME: -lFortran_main
-! DARWIN-SAME: -lFortranRuntime
-! DARWIN-SAME: -lFortranDecimal
+! DARWIN-SAME: -lflang-rt
! MINGW-LABEL: "{{.*}}ld{{(\.exe)?}}"
! MINGW-SAME: "[[object_file]]"
! MINGW-SAME: -lFortran_main
-! MINGW-SAME: -lFortranRuntime
-! MINGW-SAME: -lFortranDecimal
+! MINGW-SAME: -lflang-rt
! NOTE: This also matches lld-link (when CLANG_DEFAULT_LINKER=lld) and
! any .exe suffix that is added when resolving to the full path of
@@ -46,7 +43,6 @@
! when the executable is not found or on non-Windows platforms.
! MSVC-LABEL: link
! MSVC-SAME: Fortran_main.lib
-! MSVC-SAME: FortranRuntime.lib
-! MSVC-SAME: FortranDecimal.lib
+! MSVC-SAME: flang-rt.lib
! MSVC-SAME: /subsystem:console
! MSVC-SAME: "[[object_file]]"
Index: flang/test/CMakeLists.txt
===================================================================
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -61,9 +61,8 @@
llvm-objdump
llvm-readobj
split-file
- FortranRuntime
+ flang-rt
Fortran_main
- FortranDecimal
)
if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
list(APPEND FLANG_TEST_DEPENDS Bye)
Index: flang/runtime/CMakeLists.txt
===================================================================
--- flang/runtime/CMakeLists.txt
+++ flang/runtime/CMakeLists.txt
@@ -5,17 +5,17 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===------------------------------------------------------------------------===#
+set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.20.0)
- project(FlangRuntime C CXX)
+ project(FortranRuntime C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
- set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
@@ -44,9 +44,9 @@
else ()
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
endif ()
- include_directories(BEFORE
- ${FLANG_SOURCE_DIR}/include)
endif()
+include_directories(BEFORE
+ ${FLANG_SOURCE_DIR}/include)
include(CheckCXXSymbolExists)
include(CheckCXXSourceCompiles)
@@ -246,10 +246,15 @@
add_compile_definitions(OMP_OFFLOAD_BUILD)
endif()
-add_flang_library(FortranRuntime
- ${sources}
- LINK_LIBS
- FortranDecimal
+add_compile_options(-fPIC)
- INSTALL_WITH_TOOLCHAIN
-)
+if (DEFINED LLVM_ENABLE_RUNTIMES AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+ add_flang_library(FortranRuntime STATIC
+ ${sources}
+ LINK_LIBS
+ FortranDecimalRT
+
+ INSTALL_WITH_TOOLCHAIN
+ PIC
+ )
+endif()
Index: flang/lib/Decimal/CMakeLists.txt
===================================================================
--- flang/lib/Decimal/CMakeLists.txt
+++ flang/lib/Decimal/CMakeLists.txt
@@ -1,14 +1,14 @@
+set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.20.0)
project(FortranDecimal C CXX)
+ project(FortranDecimalRT C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
- set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
-
set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
set(CLANG_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../clang/cmake")
@@ -36,9 +36,9 @@
else ()
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
endif ()
- include_directories(BEFORE
- ${FLANG_SOURCE_DIR}/include)
endif()
+include_directories(BEFORE
+ ${FLANG_SOURCE_DIR}/include)
check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
@@ -49,7 +49,18 @@
# avoid an unwanted dependency on libstdc++.so.
add_definitions(-U_GLIBCXX_ASSERTIONS)
-add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN
- binary-to-decimal.cpp
- decimal-to-binary.cpp
-)
+add_compile_options(-fPIC)
+
+if (DEFINED LLVM_ENABLE_PROJECTS AND "flang" IN_LIST LLVM_ENABLE_PROJECTS)
+ add_flang_library(FortranDecimal
+ binary-to-decimal.cpp
+ decimal-to-binary.cpp
+ )
+endif()
+
+if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES OR FLANG_RT_STANDALONE_BUILD)
+ add_flang_library(FortranDecimalRT STATIC INSTALL_WITH_TOOLCHAIN PIC
+ binary-to-decimal.cpp
+ decimal-to-binary.cpp
+ )
+endif()
Index: flang/docs/Flang-rt.md
===================================================================
--- /dev/null
+++ flang/docs/Flang-rt.md
@@ -0,0 +1,104 @@
+<!--===- docs/Flang-rt.md
+
+ Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ See https://llvm.org/LICENSE.txt for license information.
+ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+-->
+
+# Flang-rt Runtime Library
+
+```eval_rst
+.. contents::
+ :local:
+```
+## What is Flang-rt
+Flang-rt is the runtime library for flang. The flang driver requires the
+Fortran_main.a and Flang-rt libraries at runtime in order to generate
+user executables. Flang-rt is comprised of the FortranRuntime and
+FortranDecimal libraries.
+
+## Beneficial Features
+The implementation of the Flang-rt library introduced some useful benefits to
+the Flang project:
+- The runtime can now be built independently (as a standalone project), meaning
+there is no need to rebuild the whole compiler when wanting to rebuild the
+runtime.
+- The CMake infrastructure for the runtime is now consistent to the
+infrastructure that exists for all the other supported runtimes in the
+LLVM project.
+- Flang-rt conveniently wraps 2 libraries into 1, reducing the number of
+dependencies that the end user needs to keep track of.
+- Enabled configuration of the runtime build independent from the configuration
+of the compiler, making it easy to build both static and shared Flang-rt (to
+enable supporting for e.g. `-static` in the driver).
+
+## Fortran_main
+Fortran_main is left out of Flang-rt because it is required to be linked
+statically. The link type of Flang-rt can be configured with a CMake option.
+Fortran_main implements the main entry point into Fortran's `PROGRAM` in Flang
+by being the bridge between object files generated by Flang and
+the C runtime that takes care of program set-up at system-level. For
+every Fortran `PROGRAM`, Flang generates the `_QQmain` function.
+Fortran_main implements the C `main` function that simply calls
+`_QQmain`.
+
+## FortranDecimalRT
+In order to decouple the common dependency between compiler and runtime,
+[FortranDecimal's sources](../lib/Decimal/CMakeLists.txt) get built a second
+time into a library target named FortranDecimalRT. FortranDecimal is built for
+the compiler and FortranDecimalRT is built for the Flang-rt runtime.
+
+## Building Flang-rt
+The two supported ways of building Flang-rt are with the compiler or standalone.
+#### With The Compiler
+When configuring CMake with the `llvm` target, if flang is an enabled project,
+Flang-rt will be added to the list of runtimes to also build.
+```
+$ cmake ../llvm-project/llvm -DLLVM_ENABLE_PROJECTS=flang
+```
+You can also manually specify to build Flang-rt with the
+`LLVM_ENABLE_RUNTIMES=flang-rt` CMake option.
+#### Standalone
+LLVM has a runtimes target that can be used for building runtime libraries
+standalone from the compiler.
+```
+$ cmake ../llvm-project/runtimes -DLLVM_ENABLE_RUNTIMES=flang-rt
+```
+
+## Library locations
+When building the llvm target with flang as an enabled project, the Flang-rt
+library will be built to `<driver-path>/../runtimes/runtimes-bins/lib`. When
+building the runtimes target with flang-rt as an enabled runtime, the Flang-rt
+library will be built to `<driver-path>/../lib`. In either configuration, the
+Fortran_main library will be built to `<driver-path>/../lib`.
+
+## Using Flang-rt
+The two build paths mentioned above get implicitly added as library paths at the
+invocation of the driver. If Flang-rt is a shared library, you must make the
+dynamic linker aware of where to look. One method to do so is to set the
+environment variable `LD_LIBRARY_PATH` include the path to Flang-rt's directory.
+
+## Options
+Flang-rt introduces 2 CMake options used to configure the library's link type:
+```
+option(FLANG_RT_ENABLE_SHARED "Build flang-rt as a shared library." OFF)
+option(FLANG_RT_ENABLE_STATIC "Build flang-rt as a static library." OFF)
+```
+
+## Example
+```
+# Example of how to build and use Flang with a shared Flang-rt runtime.
+# Flang-rt is built implicitly with Flang in the llvm target
+# Flang-rt is built statically by default, but for this example we built shared
+$ cmake ../llvm-project/llvm -DLLVM_ENABLE_PROJECTS=flang -DFLANG_RT_ENABLE_SHARED=On
+$ cmake --build .
+...
+# Example of using Flang with the shared Flang-rt runtime
+# First we need to explicitly tell the dynamic linker where to find Flang-rt
+# since it was built as shared.
+$ $ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/flang/driver/../runtimes/runtimes-bins/lib"
+# Warning: Currently, executable generation is considered experimental and is
+# guarded by a flag
+$ flang-new -flang-experimental-exec hello.f95
+```
Index: flang/cmake/modules/AddFlang.cmake
===================================================================
--- flang/cmake/modules/AddFlang.cmake
+++ flang/cmake/modules/AddFlang.cmake
@@ -17,7 +17,7 @@
endmacro()
function(add_flang_library name)
- set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN)
+ set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN PIC)
set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS)
cmake_parse_arguments(ARG
"${options}"
@@ -65,6 +65,9 @@
endif()
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+ if (ARG_PIC)
+ set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
+ endif()
clang_target_link_libraries(${name} PRIVATE ${ARG_CLANG_LIBS})
Index: flang/CMakeLists.txt
===================================================================
--- flang/CMakeLists.txt
+++ flang/CMakeLists.txt
@@ -186,9 +186,9 @@
endif()
endif()
if (FLANG_GTEST_AVAIL)
- add_custom_target(check-all DEPENDS check-flang FlangUnitTests)
+ add_custom_target(check-all DEPENDS flang-rt check-flang FlangUnitTests)
else()
- add_custom_target(check-all DEPENDS check-flang )
+ add_custom_target(check-all DEPENDS flang-rt check-flang)
endif()
if (LLVM_BUILD_DOCS)
add_custom_target(doxygen ALL)
Index: flang-rt/CMakeLists.txt
===================================================================
--- /dev/null
+++ flang-rt/CMakeLists.txt
@@ -0,0 +1,82 @@
+# CMake build for the Flang runtime libraries
+# The source for the flang runtime libraries (FortranDecimalRT, FortranRuntime)
+# exist in the flang top-level directory.
+# Flang-rt is only scaffolding and does not provide any additional source files.
+
+cmake_minimum_required(VERSION 3.20.0)
+
+#===============================================================================
+# Configure CMake
+#===============================================================================
+set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+ NO_POLICY_SCOPE)
+
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
+
+set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang")
+set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
+set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
+set(CLANG_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../clang/cmake")
+
+# Add path for custom modules
+list(INSERT CMAKE_MODULE_PATH 0
+ "${FLANG_SOURCE_DIR}/cmake"
+ "${FLANG_SOURCE_DIR}/cmake/modules"
+ "${CLANG_CMAKE_UTILS}/modules"
+)
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
+ ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+ ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
+
+include(AddClang)
+include(AddFlang)
+include(TestBigEndian)
+test_big_endian(IS_BIGENDIAN)
+if (IS_BIGENDIAN)
+ add_compile_definitions(FLANG_BIG_ENDIAN=1)
+else ()
+ add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
+endif ()
+
+#===============================================================================
+# Setup CMake Options
+#===============================================================================
+option(FLANG_RT_ENABLE_SHARED "Build flang-rt as a shared library." OFF)
+option(FLANG_RT_ENABLE_STATIC "Build flang-rt as a static library." OFF)
+
+#===============================================================================
+# Find Flang Libraries
+#===============================================================================
+set(FORTRAN_DECIMAL_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../flang/lib/Decimal")
+set(FORTRAN_RUNTIME_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../flang/runtime")
+
+add_subdirectory(${FORTRAN_DECIMAL_SRC} FortranDecimalRT)
+add_subdirectory(${FORTRAN_RUNTIME_SRC} FortranRuntime)
+
+#===============================================================================
+# Create Flang-rt wrapper library
+#===============================================================================
+# Build as shared by default if no linkage type option set.
+if (NOT FLANG_RT_ENABLE_SHARED AND NOT FLANG_RT_ENABLE_STATIC)
+ add_library(flang-rt SHARED $<TARGET_OBJECTS:obj.FortranDecimalRT>
+ $<TARGET_OBJECTS:obj.FortranRuntime>)
+endif()
+if (FLANG_RT_ENABLE_SHARED)
+ add_library(flang-rt SHARED $<TARGET_OBJECTS:obj.FortranDecimalRT>
+ $<TARGET_OBJECTS:obj.FortranRuntime>)
+endif()
+if (FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
+ add_library(flang-rt STATIC $<TARGET_OBJECTS:obj.FortranDecimalRT>
+ $<TARGET_OBJECTS:obj.FortranRuntime>)
+endif()
+# When building both static and shared, we need to append _static to the name
+# to avoid naming conflicts.
+if (FLANG_RT_ENABLE_STATIC AND FLANG_RT_ENABLE_SHARED)
+ add_library(flang-rt_static STATIC $<TARGET_OBJECTS:obj.FortranDecimalRT>
+ $<TARGET_OBJECTS:obj.FortranRuntime>)
+endif()
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -921,29 +921,36 @@
llvm::opt::ArgStringList &CmdArgs) {
if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
CmdArgs.push_back("Fortran_main.lib");
- CmdArgs.push_back("FortranRuntime.lib");
- CmdArgs.push_back("FortranDecimal.lib");
+ CmdArgs.push_back("flang-rt.lib");
} else {
CmdArgs.push_back("-lFortran_main");
- CmdArgs.push_back("-lFortranRuntime");
- CmdArgs.push_back("-lFortranDecimal");
+ CmdArgs.push_back("-lflang-rt");
}
}
void tools::addFortranRuntimeLibraryPath(const ToolChain &TC,
const llvm::opt::ArgList &Args,
ArgStringList &CmdArgs) {
- // Default to the <driver-path>/../lib directory. This works fine on the
- // platforms that we have tested so far. We will probably have to re-fine
- // this in the future. In particular, on some platforms, we may need to use
- // lib64 instead of lib.
- SmallString<256> DefaultLibPath =
+ // Default to the <driver-path>/../lib and
+ // <driver-path>/../runtimes/runtimes-bins/lib directories. This works fine
+ // on the platforms that we have tested so far. We will probably have to
+ // re-fine this in the future. In particular, on some platforms, we may need
+ // to use lib64 instead of lib.
+ SmallString<256> BuildLibPath =
llvm::sys::path::parent_path(TC.getDriver().Dir);
- llvm::sys::path::append(DefaultLibPath, "lib");
- if (TC.getTriple().isKnownWindowsMSVCEnvironment())
- CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
- else
- CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+ SmallString<256> RuntimesLibPath =
+ llvm::sys::path::parent_path(TC.getDriver().Dir);
+ // Search path for Fortran_main and Flang-rt libraries.
+ llvm::sys::path::append(BuildLibPath, "lib");
+ // Search path for Flang-rt library when building the llvm target.
+ llvm::sys::path::append(RuntimesLibPath, "runtimes/runtimes-bins/lib");
+ if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+ CmdArgs.push_back(Args.MakeArgString("-libpath:" + BuildLibPath));
+ CmdArgs.push_back(Args.MakeArgString("-libpath:" + RuntimesLibPath));
+ } else {
+ CmdArgs.push_back(Args.MakeArgString("-L" + BuildLibPath));
+ CmdArgs.push_back(Args.MakeArgString("-L" + RuntimesLibPath));
+ }
}
static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args,
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits