Skip to content

[Flang] Don't use FortranDecimal for runtime #121997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
72e3c5d
[Flang] Introduce FortranSupport
Meinersbur Jan 24, 2025
71015c8
[Flang] Promote FortranEvaluateTesting library
Meinersbur Jan 24, 2025
2e50a1f
[Flang] Don't use FortranDecimal for runtime
Meinersbur Jan 24, 2025
24fb760
Sort files alphabetically
Meinersbur Jan 27, 2025
0810293
Merge branch 'main' into users/meinersbur/flang_runtime_FortranSupport
Meinersbur Jan 27, 2025
a7cd5b2
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Jan 27, 2025
962958a
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Jan 27, 2025
b9ab00d
Move files back to Common
Meinersbur Jan 29, 2025
f3e9c15
add missing includes
Meinersbur Jan 29, 2025
8349624
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Jan 29, 2025
e5f2532
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Jan 29, 2025
6a7bd03
Use C++style comments for header guards
Meinersbur Jan 29, 2025
db749b9
Use C++style comments for header guards II
Meinersbur Jan 29, 2025
d3c1b9a
Merge branch 'main' into users/meinersbur/flang_runtime_FortranSupport
Meinersbur Jan 30, 2025
d9023dd
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Jan 30, 2025
eda88d9
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Jan 30, 2025
7dc5f20
Merge branch 'main' into users/meinersbur/flang_runtime_FortranSupport
Meinersbur Feb 4, 2025
88ecb82
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Feb 4, 2025
993564a
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Feb 4, 2025
0a4dfcc
Merge branch 'main' into users/meinersbur/flang_runtime_FortranSupport
Meinersbur Feb 4, 2025
0a9c5fd
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Feb 4, 2025
d509bef
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Feb 4, 2025
7158e15
Merge remote-tracking branch 'official/main' into users/meinersbur/fl…
Meinersbur Feb 5, 2025
b286a88
clang-format includes
Meinersbur Feb 6, 2025
40b2f71
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Feb 6, 2025
080f30c
Merge commit 'b815a3942a0b0a9e7aab6b269ffdb0e93abc4368' into users/me…
Meinersbur Feb 6, 2025
919919f
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Feb 6, 2025
8096d45
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Feb 6, 2025
778f516
Adapt BSD test
Meinersbur Feb 6, 2025
4c9e378
Merge branch 'main' into users/meinersbur/flang_runtime_FortranSupport
Meinersbur Feb 6, 2025
08a7bbc
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into use…
Meinersbur Feb 6, 2025
3f99cd5
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Feb 6, 2025
f258e0e
Use C++ header guards III
Meinersbur Feb 6, 2025
d222eee
Merge commit '02fa340711d9b990b50a0daf65eb850404884137' into users/me…
Meinersbur Feb 6, 2025
06a81de
Merge branch 'users/meinersbur/flang_runtime_Testing' into users/mein…
Meinersbur Feb 6, 2025
2f30a9a
Merge commit '8fb1b3f4b23ecc2fc39f1a1c07244304565cfb21' into users/me…
Meinersbur Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
/// Add Fortran runtime libs
void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
// Link FortranRuntime and FortranDecimal
// Link FortranRuntime
// These are handled earlier on Windows by telling the frontend driver to
// add the correct libraries to link against as dependents in the object
// file.
Expand All @@ -1338,7 +1338,6 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
}
CmdArgs.push_back("-lFortranRuntime");
CmdArgs.push_back("-lFortranDecimal");
addArchSpecificRPath(TC, Args, CmdArgs);

// needs libexecinfo for backtrace functions
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,29 +365,25 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
CmdArgs.push_back("-D_MT");
CmdArgs.push_back("--dependent-lib=libcmt");
CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
CmdArgs.push_back("--dependent-lib=FortranDecimal.static.lib");
break;
case options::OPT__SLASH_MTd:
CmdArgs.push_back("-D_MT");
CmdArgs.push_back("-D_DEBUG");
CmdArgs.push_back("--dependent-lib=libcmtd");
CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
CmdArgs.push_back("--dependent-lib=FortranDecimal.static_dbg.lib");
break;
case options::OPT__SLASH_MD:
CmdArgs.push_back("-D_MT");
CmdArgs.push_back("-D_DLL");
CmdArgs.push_back("--dependent-lib=msvcrt");
CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic.lib");
break;
case options::OPT__SLASH_MDd:
CmdArgs.push_back("-D_MT");
CmdArgs.push_back("-D_DEBUG");
CmdArgs.push_back("-D_DLL");
CmdArgs.push_back("--dependent-lib=msvcrtd");
CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic_dbg.lib");
break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions flang/docs/FlangDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,18 @@ like this:

```
$ flang -v -o example example.o
"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" "-lFortranDecimal" [...]
"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" [...]
```

The automatically added libraries are:

* `FortranRuntime`: Provides most of the Flang runtime library.
* `FortranDecimal`: Provides operations for decimal numbers.

If the code is C/C++ based and invokes Fortran routines, one can either use Clang
or Flang as the linker driver. If Clang is used, it will automatically all
required runtime libraries needed by C++ (e.g., for STL) to the linker invocation.
In this case, one has to explicitly provide the Fortran runtime libraries
`FortranRuntime` and/or `FortranDecimal`. An alternative is to use Flang to link.
In this case, one has to explicitly provide the Fortran runtime library
`FortranRuntime`. An alternative is to use Flang to link.
In this case, it may be required to explicitly supply C++ runtime libraries.

On Darwin, the logical root where the system libraries are located (sysroot)
Expand Down
84 changes: 1 addition & 83 deletions flang/lib/Decimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,7 @@
#
#===------------------------------------------------------------------------===#

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.20.0)

project(FortranDecimal 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")

# Add path for custom modules
list(INSERT CMAKE_MODULE_PATH 0
"${FLANG_SOURCE_DIR}/cmake"
"${FLANG_SOURCE_DIR}/cmake/modules"
"${LLVM_COMMON_CMAKE_UTILS}"
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
"${LLVM_CMAKE_UTILS}"
"${LLVM_CMAKE_UTILS}/modules"
"${CLANG_CMAKE_UTILS}/modules"
)

include(AddClang)
include(AddLLVM)
include(AddFlang)
include(HandleLLVMOptions)

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 ()
include_directories(BEFORE
${FLANG_SOURCE_DIR}/include)
endif()

check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
append("-fno-lto" CMAKE_CXX_FLAGS)
endif()

# Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to
# avoid an unwanted dependency on libstdc++.so.
add_definitions(-U_GLIBCXX_ASSERTIONS)

set(sources
add_flang_library(FortranDecimal
binary-to-decimal.cpp
decimal-to-binary.cpp
)

include(AddFlangOffloadRuntime)
enable_cuda_compilation(FortranDecimal "${sources}")
enable_omp_offload_compilation("${sources}")

add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN ${sources})

if (DEFINED MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
add_flang_library(FortranDecimal.static INSTALL_WITH_TOOLCHAIN
binary-to-decimal.cpp
decimal-to-binary.cpp
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
add_flang_library(FortranDecimal.dynamic INSTALL_WITH_TOOLCHAIN
binary-to-decimal.cpp
decimal-to-binary.cpp
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
add_flang_library(FortranDecimal.static_dbg INSTALL_WITH_TOOLCHAIN
binary-to-decimal.cpp
decimal-to-binary.cpp
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
add_flang_library(FortranDecimal.dynamic_dbg INSTALL_WITH_TOOLCHAIN
binary-to-decimal.cpp
decimal-to-binary.cpp
)
add_dependencies(FortranDecimal FortranDecimal.static FortranDecimal.dynamic
FortranDecimal.static_dbg FortranDecimal.dynamic_dbg)
endif()
12 changes: 3 additions & 9 deletions flang/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
)
endif()

set(linked_libraries FortranDecimal)
set(linked_libraries "")

# function checks
find_package(Backtrace)
Expand Down Expand Up @@ -116,6 +116,8 @@ add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS)
add_subdirectory(Float128Math)

set(sources
${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp
ISO_Fortran_binding.cpp
allocator-registry.cpp
allocatable.cpp
Expand Down Expand Up @@ -288,26 +290,18 @@ else()
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
add_flang_library(FortranRuntime.static ${sources}
LINK_LIBS
FortranDecimal.static
INSTALL_WITH_TOOLCHAIN)
set_target_properties(FortranRuntime.static PROPERTIES FOLDER "Flang/Runtime Libraries")
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
add_flang_library(FortranRuntime.dynamic ${sources}
LINK_LIBS
FortranDecimal.dynamic
INSTALL_WITH_TOOLCHAIN)
set_target_properties(FortranRuntime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
add_flang_library(FortranRuntime.static_dbg ${sources}
LINK_LIBS
FortranDecimal.static_dbg
INSTALL_WITH_TOOLCHAIN)
set_target_properties(FortranRuntime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
add_flang_library(FortranRuntime.dynamic_dbg ${sources}
LINK_LIBS
FortranDecimal.dynamic_dbg
INSTALL_WITH_TOOLCHAIN)
set_target_properties(FortranRuntime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
add_dependencies(FortranRuntime FortranRuntime.static FortranRuntime.dynamic
Expand Down
7 changes: 2 additions & 5 deletions flang/test/Driver/linker-flags.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,33 @@
! SOLARIS-F128NONE-NOT: FortranFloat128Math
! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
! UNIX-SAME: "-lFortranRuntime" "-lm"
! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"

! BSD-LABEL: "{{.*}}ld{{(\.exe)?}}"
! BSD-SAME: "[[object_file]]"
! BSD-F128NONE-NOT: FortranFloat128Math
! BSD-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! BSD-SAME: -lFortranRuntime
! BSD-SAME: -lFortranDecimal
! BSD-SAME: -lexecinfo

! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
! DARWIN-F128NONE-NOT: FortranFloat128Math
! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! DARWIN-SAME: -lFortranRuntime
! DARWIN-SAME: -lFortranDecimal

! HAIKU-LABEL: "{{.*}}ld{{(\.exe)?}}"
! HAIKU-SAME: "[[object_file]]"
! HAIKU-F128NONE-NOT: FortranFloat128Math
! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! HAIKU-SAME: "-lFortranRuntime" "-lFortranDecimal"
! HAIKU-SAME: "-lFortranRuntime"

! MINGW-LABEL: "{{.*}}ld{{(\.exe)?}}"
! MINGW-SAME: "[[object_file]]"
! MINGW-F128NONE-NOT: FortranFloat128Math
! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! MINGW-SAME: -lFortranRuntime
! MINGW-SAME: -lFortranDecimal

! 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
Expand Down
4 changes: 0 additions & 4 deletions flang/test/Driver/msvc-dependent-lib-flags.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
! MSVC-SAME: -D_MT
! MSVC-SAME: --dependent-lib=libcmt
! MSVC-SAME: --dependent-lib=FortranRuntime.static.lib
! MSVC-SAME: --dependent-lib=FortranDecimal.static.lib

! MSVC-DEBUG: -fc1
! MSVC-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
! MSVC-DEBUG-SAME: -D_MT
! MSVC-DEBUG-SAME: -D_DEBUG
! MSVC-DEBUG-SAME: --dependent-lib=libcmtd
! MSVC-DEBUG-SAME: --dependent-lib=FortranRuntime.static_dbg.lib
! MSVC-DEBUG-SAME: --dependent-lib=FortranDecimal.static_dbg.lib

! MSVC-DLL: -fc1
! MSVC-DLL-SAME: --dependent-lib=clang_rt.builtins.lib
! MSVC-DLL-SAME: -D_MT
! MSVC-DLL-SAME: -D_DLL
! MSVC-DLL-SAME: --dependent-lib=msvcrt
! MSVC-DLL-SAME: --dependent-lib=FortranRuntime.dynamic.lib
! MSVC-DLL-SAME: --dependent-lib=FortranDecimal.dynamic.lib

! MSVC-DLL-DEBUG: -fc1
! MSVC-DLL-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
Expand All @@ -33,4 +30,3 @@
! MSVC-DLL-DEBUG-SAME: -D_DLL
! MSVC-DLL-DEBUG-SAME: --dependent-lib=msvcrtd
! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranRuntime.dynamic_dbg.lib
! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranDecimal.dynamic_dbg.lib
1 change: 0 additions & 1 deletion flang/test/Driver/nostdlib.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
! platform individually.

! CHECK-NOT: "-lFortranRuntime"
! CHECK-NOT: "-lFortranDecimal"
! CHECK-NOT: "-lgcc"
2 changes: 1 addition & 1 deletion flang/test/Runtime/no-cpp-dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ a C compiler.
REQUIRES: c-compiler

RUN: %if system-aix %{ export OBJECT_MODE=64 %}
RUN: %cc -std=c99 %s -I%include %libruntime %libdecimal -lm \
RUN: %cc -std=c99 %s -I%include %libruntime -lm \
RUN: %if system-aix %{-lpthread %}
RUN: rm a.out
*/
Expand Down
3 changes: 0 additions & 3 deletions flang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@
# 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")
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")
Expand All @@ -183,7 +181,6 @@
)
)
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
Expand Down
1 change: 0 additions & 1 deletion lld/COFF/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ AutoExporter::AutoExporter(
"libc++",
"libc++abi",
"libFortranRuntime",
"libFortranDecimal",
"libunwind",
"libmsvcrt",
"libucrtbase",
Expand Down