Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit c783eb2

Browse files
committed
LibDriver: Fix output path inference.
The inferred output file name is based on the first input file, not the first one with extension .obj. The output file was also being written to the wrong directory; it needs to be written to whichever directory on the libpath it was found in. This change fixes both issues. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241710 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b089d62 commit c783eb2

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/LibDriver/LibDriver.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ class LibOptTable : public llvm::opt::OptTable {
5656

5757
}
5858

59-
static std::string getOutputPath(llvm::opt::InputArgList *Args) {
59+
static std::string getOutputPath(llvm::opt::InputArgList *Args,
60+
const llvm::NewArchiveIterator &FirstMember) {
6061
if (auto *Arg = Args->getLastArg(OPT_out))
6162
return Arg->getValue();
62-
for (auto *Arg : Args->filtered(OPT_INPUT)) {
63-
if (!StringRef(Arg->getValue()).endswith_lower(".obj"))
64-
continue;
65-
SmallString<128> Val = StringRef(Arg->getValue());
66-
llvm::sys::path::replace_extension(Val, ".lib");
67-
return Val.str();
68-
}
69-
llvm_unreachable("internal error");
63+
SmallString<128> Val = FirstMember.getNew();
64+
llvm::sys::path::replace_extension(Val, ".lib");
65+
return Val.str();
7066
}
7167

7268
static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
@@ -143,8 +139,8 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
143139
llvm::sys::path::filename(Arg->getValue()));
144140
}
145141

146-
std::pair<StringRef, std::error_code> Result =
147-
llvm::writeArchive(getOutputPath(&Args), Members, /*WriteSymtab=*/true);
142+
std::pair<StringRef, std::error_code> Result = llvm::writeArchive(
143+
getOutputPath(&Args, Members[0]), Members, /*WriteSymtab=*/true);
148144
if (Result.second) {
149145
if (Result.first.empty())
150146
Result.first = ArgsArr[0];

test/LibDriver/infer-output-path.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/a.obj %S/Inputs/a.s
2+
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/b.o %S/Inputs/b.s
3+
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/c %S/Inputs/b.s
4+
5+
RUN: rm -f %T/a.lib
6+
RUN: llvm-lib %T/a.obj
7+
RUN: test -e %T/a.lib
8+
9+
RUN: rm -f %T/b.lib
10+
RUN: llvm-lib /libpath:%T b.o
11+
RUN: test -e %T/b.lib
12+
13+
RUN: rm -f %T/c.lib
14+
RUN: llvm-lib /libpath:%T c
15+
RUN: test -e %T/c.lib

0 commit comments

Comments
 (0)