Skip to content

Commit cf32bac

Browse files
authored
Do not prefix static libs from pragma(lib) with -l (#4460)
1 parent 3b7ca36 commit cf32bac

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

gen/declarations.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,24 @@ class CodegenVisitor : public Visitor {
419419
std::string arg = ("/DEFAULTLIB:\"" + name + "\"").str();
420420
gIR->addLinkerOption(llvm::StringRef(arg));
421421
} else {
422-
size_t const n = name.size() + 3;
423-
char *arg = static_cast<char *>(mem.xmalloc(n));
424-
arg[0] = '-';
425-
arg[1] = 'l';
426-
memcpy(arg + 2, name.data(), name.size());
427-
arg[n - 1] = 0;
422+
bool isStaticLib = name.endswith(".a");
423+
424+
size_t const nameLen = name.size();
425+
size_t const n = nameLen + 3;
426+
char *arg = nullptr;
427+
428+
if (isStaticLib == false) {
429+
arg = static_cast<char *>(mem.xmalloc(n));
430+
arg[0] = '-';
431+
arg[1] = 'l';
432+
memcpy(arg + 2, name.data(), name.size());
433+
arg[n - 1] = 0;
434+
} else {
435+
arg = static_cast<char *>((mem.xmalloc(nameLen + 1)));
436+
memcpy(arg, name.data(), nameLen);
437+
arg[nameLen] = 0;
438+
}
439+
428440
global.params.linkswitches.push(arg);
429441

430442
if (triple.isOSBinFormatMachO()) {

0 commit comments

Comments
 (0)