[lld] 61e0b2b - [LLD] Allow configuring default ld.lld backend

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 23:13:10 PDT 2020


Author: Mateusz Mikuła
Date: 2020-09-15T08:50:02+03:00
New Revision: 61e0b2b4c5fbbea01bb40f28ea0222b87166ccdf

URL: https://github.com/llvm/llvm-project/commit/61e0b2b4c5fbbea01bb40f28ea0222b87166ccdf
DIFF: https://github.com/llvm/llvm-project/commit/61e0b2b4c5fbbea01bb40f28ea0222b87166ccdf.diff

LOG: [LLD] Allow configuring default ld.lld backend

The motivation for this is ld.lld --help targeting MinGW which
currently prints help for the ELF backend unless -m i386pe{,p} is
added. This confuses build systems that grep through linker help to
find supported flags.

This matches LD from Binutils which always prints help for MinGW
when configured to target it.

After this change, the backend can still be overridden to any
supported ELF/MinGW target by using correct -m <arch>.

Differential Revision: https://reviews.llvm.org/D87418

Added: 
    

Modified: 
    lld/CMakeLists.txt
    lld/tools/lld/lld.cpp

Removed: 
    


################################################################################
diff  --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt
index 34a7a68da42c..8b8c7178c616 100644
--- a/lld/CMakeLists.txt
+++ b/lld/CMakeLists.txt
@@ -174,6 +174,12 @@ endif()
 option(LLD_BUILD_TOOLS
   "Build the lld tools. If OFF, just generate build targets." ON)
 
+option(LLD_DEFAULT_LD_LLD_IS_MINGW
+    "Use MinGW as the default backend for ld.lld. If OFF, ELF will be used." OFF)
+if (LLD_DEFAULT_LD_LLD_IS_MINGW)
+  add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
+endif()
+
 if (MSVC)
   add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
   add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.

diff  --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp
index 8a8f8d04bbda..d4e2fbb0309a 100644
--- a/lld/tools/lld/lld.cpp
+++ b/lld/tools/lld/lld.cpp
@@ -92,7 +92,12 @@ static bool isPETarget(std::vector<const char *> &v) {
       continue;
     return isPETargetName(*(it + 1));
   }
+
+#ifdef LLD_DEFAULT_LD_LLD_IS_MINGW
+  return true;
+#else
   return false;
+#endif
 }
 
 static Flavor parseProgname(StringRef progname) {


        


More information about the llvm-commits mailing list