[PATCH] D87418: [LLD] Allow configuring default ld.lld backend

Mateusz MikuĊ‚a via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 14:56:46 PDT 2020


mati865 created this revision.
mati865 added a project: lld.
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.
mati865 requested review of this revision.

The motivation for this is `ld.lld --help` targeting MinGW 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>`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87418

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


Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -92,7 +92,8 @@
       continue;
     return isPETargetName(*(it + 1));
   }
-  return false;
+
+  return LLD_DEFAULT_LD_LLD_BACKEND == "MINGW" ? true : false;
 }
 
 static Flavor parseProgname(StringRef progname) {
Index: lld/CMakeLists.txt
===================================================================
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -193,6 +193,15 @@
 option(LLD_BUILD_TOOLS
   "Build the lld tools. If OFF, just generate build targets." ON)
 
+set(LLD_DEFAULT_LD_LLD_BACKEND "ELF"
+    CACHE STRING "Default backend for ld.lld, can be either ELF (default) or MINGW")
+string(TOUPPER "${LLD_DEFAULT_LD_LLD_BACKEND}" uppercase_LLD_DEFAULT_LD_LLD_BACKEND)
+if (uppercase_LLD_DEFAULT_LD_LLD_BACKEND MATCHES "^ELF$|^MINGW$")
+  add_definitions("-DLLD_DEFAULT_LD_LLD_BACKEND=\"${uppercase_LLD_DEFAULT_LD_LLD_BACKEND}\"")
+else()
+  message(FATAL_ERROR "LLD_DEFAULT_LD_LLD_BACKEND can only be either ELF or MINGW")
+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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87418.290828.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200909/c0b7336d/attachment.bin>


More information about the llvm-commits mailing list