Skip to content

Commit 8883b7e

Browse files
committed
[Windows] Emit dependency to flang_rt.builtins.lib in every flang-compiled object file.
The dependency is already transitive due to flang-rt depending on it, so it shouldn't be necessary. However, CMake may depend on it, and the transsitivity may be ignored in DLLs. To avoid breaking things, keep the original behaviour but remove the redundant condition and update the wrong comment. IMHO this is a bug in LLVM: If clang/clang-cl emits calls not in user-code, the driver should als care about linking the correct library. Even better, do not generate such calls and adhere to the msvc-defined ABI.
1 parent 39d6d96 commit 8883b7e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
291291
assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
292292
"can only add VS runtime library on Windows!");
293293

294+
// Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
295+
// should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt
296+
// functions in some cases like 128-bit integer math (__udivti3, __modti3,
297+
// __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a
298+
// dependency to Compiler-RT's builtin library where these are implemented.
299+
CmdArgs.push_back(Args.MakeArgString(
300+
"--dependent-lib=" + TC.getCompilerRTBasename(Args, "builtins")));
301+
294302
unsigned RTOptionID = options::OPT__SLASH_MT;
295303
if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
296304
RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ function (add_flangrt_library name)
9595

9696
# Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
9797
# should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt
98-
# functions for 128-bit integer math (__udivti3, __modti3, __fixsfti,
99-
# __floattidf, ...) that msvc does not support. We are injecting a dependency
100-
# to Compiler-RT where these are implemented.
98+
# functions in some cases like 128-bit integer math (__udivti3, __modti3,
99+
# __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a
100+
# dependency to Compiler-RT's builtin library where these are implemented.
101101
if (MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") AND FLANG_RT_LIBCALL)
102102
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "--dependent-lib=${FLANG_RT_LIBCALL}")
103103
endif ()

0 commit comments

Comments
 (0)