[PATCH] D124999: ld.lld: Respect -fallback-gnu-driver.
Shea Levy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 03:48:20 PDT 2022
shlevy created this revision.
shlevy added a reviewer: ruiu.
Herald added a subscriber: mstorsjo.
Herald added a project: All.
shlevy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is essentially a run-time version of LLD_DEFAULT_LD_LLD_IS_MINGW.
-fallback-gnu-driver must be the first argument (after -flavor, if it exists).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D124999
Files:
lld/test/MinGW/driver.test
lld/tools/lld/lld.cpp
Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -78,7 +78,33 @@
return s == "i386pe" || s == "i386pep" || s == "thumb2pe" || s == "arm64pe";
}
+enum GnuDriver { MinGWDriver, ELFDriver, InvalidDriver };
+
+static GnuDriver getDriver(StringRef s) {
+ return StringSwitch<GnuDriver>(s)
+ .CaseLower("elf", ELFDriver)
+ .CaseLower("mingw", MinGWDriver)
+ .Default(InvalidDriver);
+}
+
static bool isPETarget(std::vector<const char *> &v) {
+ GnuDriver fallbackDriver =
+#ifdef LLD_DEFAULT_LD_LLD_IS_MINGW
+ MinGWDriver;
+#else
+ ELFDriver;
+#endif
+
+ // Parse -fallback-gnu-driver option.
+ if (v.size() > 1 && v[1] == StringRef("-fallback-gnu-driver")) {
+ if (v.size() <= 2)
+ die("missing arg value for '-fallback-gnu-driver'");
+ fallbackDriver = getDriver(v[2]);
+ if (fallbackDriver == InvalidDriver)
+ die("Unknown fallback gnu driver: " + StringRef(v[2]));
+ v.erase(v.begin() + 1, v.begin() + 3);
+ }
+
for (auto it = v.begin(); it + 1 != v.end(); ++it) {
if (StringRef(*it) != "-m")
continue;
@@ -96,11 +122,7 @@
return isPETargetName(*(it + 1));
}
-#ifdef LLD_DEFAULT_LD_LLD_IS_MINGW
- return true;
-#else
- return false;
-#endif
+ return fallbackDriver == MinGWDriver;
}
static Flavor parseProgname(StringRef progname) {
Index: lld/test/MinGW/driver.test
===================================================================
--- lld/test/MinGW/driver.test
+++ lld/test/MinGW/driver.test
@@ -246,6 +246,7 @@
VERSION: LLD {{.*}} (compatible with GNU linkers)
RUN: ld.lld -m i386pep --help 2>&1 | FileCheck -check-prefix=HELP %s
+RUN: ld.lld -fallback-gnu-driver mingw --help 2>&1 | FileCheck -check-prefix=HELP %s
HELP: USAGE:
HELP: --enable-auto-import
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124999.427260.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220505/3ab177ff/attachment-0001.bin>
More information about the llvm-commits
mailing list