[flang-commits] [flang] 1b6c828 - [flang][driver] Don't use -whole-archive on Darwin (#75393)

via flang-commits flang-commits at lists.llvm.org
Thu Dec 14 13:11:30 PST 2023


Author: Andrzej WarzyƄski
Date: 2023-12-14T21:11:25Z
New Revision: 1b6c8280b9a672a9c6f5c22d18b1cdaa2320d4ed

URL: https://github.com/llvm/llvm-project/commit/1b6c8280b9a672a9c6f5c22d18b1cdaa2320d4ed
DIFF: https://github.com/llvm/llvm-project/commit/1b6c8280b9a672a9c6f5c22d18b1cdaa2320d4ed.diff

LOG: [flang][driver] Don't use -whole-archive on Darwin (#75393)

Direct follow-up of #73124 - the linker on Darwin does not support
`-whole-archive`, so that needs to be removed from the linker
invocation.

For context:
  * https://github.com/llvm/llvm-project/pull/73124

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/CommonArgs.cpp
    flang/test/Driver/no-duplicate-main.f90

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 01fb0718b4079d..3d1df58190ce05 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1132,24 +1132,30 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
       // --whole-archive flag to the link line.  If it's not, add a proper
       // --whole-archive/--no-whole-archive bracket to the link line.
       bool WholeArchiveActive = false;
-      for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
-        if (Arg)
+      for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) {
+        if (Arg) {
           for (StringRef ArgValue : Arg->getValues()) {
             if (ArgValue == "--whole-archive")
               WholeArchiveActive = true;
             if (ArgValue == "--no-whole-archive")
               WholeArchiveActive = false;
           }
+        }
+      }
 
-      if (!WholeArchiveActive)
+      // TODO: Find an equivalent of `--whole-archive` for Darwin.
+      if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) {
         CmdArgs.push_back("--whole-archive");
-      CmdArgs.push_back("-lFortran_main");
-      if (!WholeArchiveActive)
+        CmdArgs.push_back("-lFortran_main");
         CmdArgs.push_back("--no-whole-archive");
+      } else {
+        CmdArgs.push_back("-lFortran_main");
+      }
+
+      // Perform regular linkage of the remaining runtime libraries.
+      CmdArgs.push_back("-lFortranRuntime");
+      CmdArgs.push_back("-lFortranDecimal");
     }
-    // Perform regular linkage of the remaining runtime libraries.
-    CmdArgs.push_back("-lFortranRuntime");
-    CmdArgs.push_back("-lFortranDecimal");
   } else {
     if (LinkFortranMain) {
       unsigned RTOptionID = options::OPT__SLASH_MT;

diff  --git a/flang/test/Driver/no-duplicate-main.f90 b/flang/test/Driver/no-duplicate-main.f90
index 12d5e46247bad2..b884e7ecd7f12a 100644
--- a/flang/test/Driver/no-duplicate-main.f90
+++ b/flang/test/Driver/no-duplicate-main.f90
@@ -1,4 +1,4 @@
-! UNSUPPORTED: system-windows
+! UNSUPPORTED: system-windows, system-darwin
 
 ! RUN: %flang -x ir -o %t.c-object -c %S/Inputs/no_duplicate_main.ll
 ! RUN: %flang -o %t -c %s


        


More information about the flang-commits mailing list