ELF: --reproduce: quote pathnames for -L and other options.

Previously, arguments for options that take pathnames were not rewritten.

llvm-svn: 268172
This commit is contained in:
Rui Ueyama 2016-04-30 22:46:47 +00:00
parent 9aea957f6d
commit 2796ae3f69
2 changed files with 24 additions and 15 deletions

View File

@ -137,6 +137,12 @@ static std::string quote(StringRef S) {
return ("\"" + S + "\"").str();
}
static std::string rewritePath(StringRef S) {
if (fs::exists(S))
return getDestPath(S);
return S;
}
// Copies all input files to Config->Reproduce directory and
// create a response file as "response.txt", so that you can re-run
// the same command with the same inputs just by executing
@ -157,25 +163,25 @@ void elf::createResponseFile(const llvm::opt::InputArgList &Args) {
raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None);
check(EC);
// Dump the command line to response.txt while copying files
// and rewriting paths.
// Copy the command line to response.txt while rewriting paths.
for (auto *Arg : Args) {
switch (Arg->getOption().getID()) {
case OPT_reproduce:
break;
case OPT_script:
OS << "--script ";
// fallthrough
case OPT_INPUT: {
StringRef Path = Arg->getValue();
if (fs::exists(Path))
OS << quote(getDestPath(Path)) << "\n";
else
OS << quote(Path) << "\n";
case OPT_INPUT:
OS << quote(rewritePath(Arg->getValue())) << "\n";
break;
case OPT_L:
case OPT_dynamic_list:
case OPT_export_dynamic_symbol:
case OPT_rpath:
case OPT_script:
case OPT_version_script:
OS << Arg->getSpelling() << " "
<< quote(rewritePath(Arg->getValue())) << "\n";
break;
}
default:
OS << Arg->getAsString(Args) << "\n";
OS << quote(Arg->getAsString(Args)) << "\n";
}
}
}

View File

@ -19,10 +19,13 @@
# RUN: ld.lld ./../../../foo.o -o bar -shared --as-needed --reproduce repro
# RUN: diff %t.dir/build2/foo.o repro/%:t.dir/build2/foo.o
# RUN: not ld.lld build1/foo.o --reproduce repro2 'foo bar' -soname=foo
# RUN: touch file
# RUN: not ld.lld --reproduce repro2 'foo bar' -L"foo bar" -Lfile -version-script file
# RUN: FileCheck %s --check-prefix=RSP2 < repro2/response.txt
# RSP2: "foo bar"
# RSP2-NEXT: -soname=foo
# RSP2-NEXT: -L "foo bar"
# RSP2-NEXT: -L {{.+}}file
# RSP2-NEXT: -version-script {{.+}}file
# RUN: not ld.lld build1/foo.o -o bar -shared --as-needed --reproduce . 2>&1 \
# RUN: | FileCheck --check-prefix=ERROR %s