Skip to content

Commit ad34e18

Browse files
mati865jeremyd2019
authored andcommitted
[LLD][MinGW] Implement --dll-search-prefix option
1 parent 2af06e9 commit ad34e18

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lld/MinGW/Driver.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ static std::optional<std::string> findFile(StringRef path1,
139139
}
140140

141141
// This is for -lfoo. We'll look for libfoo.dll.a or libfoo.a from search paths.
142-
static std::string
143-
searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
142+
static std::string searchLibrary(StringRef name,
143+
ArrayRef<StringRef> searchPaths, bool bStatic,
144+
StringRef dllPrefix = "") {
144145
if (name.starts_with(":")) {
145146
for (StringRef dir : searchPaths)
146147
if (std::optional<std::string> s = findFile(dir, name.substr(1)))
@@ -161,6 +162,11 @@ searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
161162
if (std::optional<std::string> s = findFile(dir, name + ".lib"))
162163
return *s;
163164
if (!bStatic) {
165+
if (!dllPrefix.empty()) {
166+
if (std::optional<std::string> s =
167+
findFile(dir, dllPrefix + name + ".dll"))
168+
return *s;
169+
}
164170
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".dll"))
165171
return *s;
166172
if (std::optional<std::string> s = findFile(dir, name + ".dll"))
@@ -545,6 +551,10 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
545551
add("-libpath:" + StringRef(a->getValue()));
546552
}
547553

554+
StringRef dllPrefix;
555+
if (auto *a = args.getLastArg(OPT_dll_search_prefix))
556+
dllPrefix = a->getValue();
557+
548558
StringRef prefix = "";
549559
bool isStatic = false;
550560
for (auto *a : args) {
@@ -556,7 +566,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
556566
add(prefix + StringRef(a->getValue()));
557567
break;
558568
case OPT_l:
559-
add(prefix + searchLibrary(a->getValue(), searchPaths, isStatic));
569+
add(prefix +
570+
searchLibrary(a->getValue(), searchPaths, isStatic, dllPrefix));
560571
break;
561572
case OPT_whole_archive:
562573
prefix = "-wholearchive:";

lld/MinGW/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def disable_runtime_pseudo_reloc: F<"disable-runtime-pseudo-reloc">,
6565
HelpText<"Don't do automatic imports that require runtime fixups">;
6666
def disable_stdcall_fixup: F<"disable-stdcall-fixup">,
6767
HelpText<"Don't resolve stdcall/fastcall/vectorcall to undecorated symbols">;
68+
defm dll_search_prefix: EEq<"dll-search-prefix",
69+
"Prefer DLL with this prefix if importlib is missing">;
6870
defm dynamicbase: B_disable<"dynamicbase", "Enable ASLR", "Disable ASLR">;
6971
def enable_auto_import: F<"enable-auto-import">,
7072
HelpText<"Automatically import data symbols from other DLLs where needed">;

0 commit comments

Comments
 (0)