Skip to content

Commit

Permalink
Do not prefix static libs from pragma(lib) with -l (#4460)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuukk committed Aug 1, 2023
1 parent 3b7ca36 commit cf32bac
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions gen/declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,24 @@ class CodegenVisitor : public Visitor {
std::string arg = ("/DEFAULTLIB:\"" + name + "\"").str();
gIR->addLinkerOption(llvm::StringRef(arg));
} else {
size_t const n = name.size() + 3;
char *arg = static_cast<char *>(mem.xmalloc(n));
arg[0] = '-';
arg[1] = 'l';
memcpy(arg + 2, name.data(), name.size());
arg[n - 1] = 0;
bool isStaticLib = name.endswith(".a");

size_t const nameLen = name.size();
size_t const n = nameLen + 3;
char *arg = nullptr;

if (isStaticLib == false) {
arg = static_cast<char *>(mem.xmalloc(n));
arg[0] = '-';
arg[1] = 'l';
memcpy(arg + 2, name.data(), name.size());
arg[n - 1] = 0;
} else {
arg = static_cast<char *>((mem.xmalloc(nameLen + 1)));
memcpy(arg, name.data(), nameLen);
arg[nameLen] = 0;
}

global.params.linkswitches.push(arg);

if (triple.isOSBinFormatMachO()) {
Expand Down

0 comments on commit cf32bac

Please sign in to comment.