From 77ecb9a49bb1640684c37f80ffe56bc54dae6502 Mon Sep 17 00:00:00 2001 From: David Truby Date: Wed, 15 Nov 2023 15:26:43 +0000 Subject: [flang] Add dependent-lib option to flang -fc1 on Windows (#72121) This patch adds a --dependent-lib option to flang -fc1 on Windows to embed library link options into the object file. This is needed to properly select the Windows CRT to link against. --- flang/lib/Frontend/CompilerInvocation.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 334da3a..cb4f2d6 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -1054,6 +1054,27 @@ static bool parseVScaleArgs(CompilerInvocation &invoc, llvm::opt::ArgList &args, return true; } +static bool parseLinkerOptionsArgs(CompilerInvocation &invoc, + llvm::opt::ArgList &args, + clang::DiagnosticsEngine &diags) { + llvm::Triple triple = llvm::Triple(invoc.getTargetOpts().triple); + + // TODO: support --dependent-lib on other platforms when MLIR supports + // !llvm.dependent.lib + if (args.hasArg(clang::driver::options::OPT_dependent_lib) && + !triple.isOSWindows()) { + const unsigned diagID = + diags.getCustomDiagID(clang::DiagnosticsEngine::Error, + "--dependent-lib is only supported on Windows"); + diags.Report(diagID); + return false; + } + + invoc.getCodeGenOpts().DependentLibs = + args.getAllArgValues(clang::driver::options::OPT_dependent_lib); + return true; +} + bool CompilerInvocation::createFromArgs( CompilerInvocation &res, llvm::ArrayRef commandLineArgs, clang::DiagnosticsEngine &diags, const char *argv0) { @@ -1163,6 +1184,8 @@ bool CompilerInvocation::createFromArgs( success &= parseVScaleArgs(res, args, diags); + success &= parseLinkerOptionsArgs(res, args, diags); + // Set the string to be used as the return value of the COMPILER_OPTIONS // intrinsic of iso_fortran_env. This is either passed in from the parent // compiler driver invocation with an environment variable, or failing that -- cgit v1.1