[lld] r268171 - ELF: --reproduce: Copy files referenced by linker scripts.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 30 15:23:29 PDT 2016


Author: ruiu
Date: Sat Apr 30 17:23:29 2016
New Revision: 268171

URL: http://llvm.org/viewvc/llvm-project?rev=268171&view=rev
Log:
ELF: --reproduce: Copy files referenced by linker scripts.

Previuosly, only files appeared on the command line were copied.

Added:
    lld/trunk/test/ELF/reproduce-linkerscript.s
Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Driver.h
    lld/trunk/ELF/DriverUtils.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=268171&r1=268170&r2=268171&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Apr 30 17:23:29 2016
@@ -109,6 +109,8 @@ void LinkerDriver::addFile(StringRef Pat
   using namespace llvm::sys::fs;
   if (Config->Verbose)
     llvm::outs() << Path << "\n";
+  if (!Config->Reproduce.empty())
+    copyInputFile(Path);
 
   Optional<MemoryBufferRef> Buffer = readFile(Path);
   if (!Buffer.hasValue())
@@ -252,7 +254,7 @@ void LinkerDriver::main(ArrayRef<const c
   initLLVM(Args);
 
   if (!Config->Reproduce.empty())
-    saveLinkerInputs(Args);
+    createResponseFile(Args);
 
   createFiles(Args);
   checkOptions(Args);

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=268171&r1=268170&r2=268171&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Sat Apr 30 17:23:29 2016
@@ -68,7 +68,9 @@ enum {
 void printHelp(const char *Argv0);
 void printVersion();
 
-void saveLinkerInputs(const llvm::opt::InputArgList &Args);
+void createResponseFile(const llvm::opt::InputArgList &Args);
+void copyInputFile(StringRef Path);
+
 std::string findFromSearchPaths(StringRef Path);
 std::string searchLibrary(StringRef Path);
 std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=268171&r1=268170&r2=268171&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Sat Apr 30 17:23:29 2016
@@ -90,7 +90,7 @@ void elf::printVersion() {
 // Makes a given pathname an absolute path first, and then remove
 // beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
 // assuming that the current directory is "/home/john/bar".
-static std::string relative_to_root(StringRef Path) {
+static std::string relativeToRoot(StringRef Path) {
   SmallString<128> Abs = Path;
   if (std::error_code EC = fs::make_absolute(Abs))
     fatal("make_absolute failed: " + EC.message());
@@ -110,20 +110,24 @@ static std::string relative_to_root(Stri
   return Res.str();
 }
 
-// Copies file Src to {Config->Reproduce}/Src.
-// Returns the new path relative to Config->Reproduce.
-static std::string copyFile(StringRef Src) {
-  std::string Relpath = relative_to_root(Src);
+static std::string getDestPath(StringRef Path) {
+  std::string Relpath = relativeToRoot(Path);
   SmallString<128> Dest;
   path::append(Dest, Config->Reproduce, Relpath);
+  return Dest.str();
+}
 
+// Copies file Src to {Config->Reproduce}/Src.
+void elf::copyInputFile(StringRef Src) {
+  std::string Dest = getDestPath(Src);
   SmallString<128> Dir(Dest);
   path::remove_filename(Dir);
-  if (std::error_code EC = sys::fs::create_directories(Dir))
+  if (std::error_code EC = sys::fs::create_directories(Dir)) {
     error(EC, Dir + ": can't create directory");
+    return;
+  }
   if (std::error_code EC = sys::fs::copy_file(Src, Dest))
     error(EC, "failed to copy file: " + Dest);
-  return Relpath;
 }
 
 // Quote a given string if it contains a space character.
@@ -138,7 +142,7 @@ static std::string quote(StringRef S) {
 // the same command with the same inputs just by executing
 // "ld.lld @response.txt". Used by --reproduce. This feature is
 // supposed to be used by users to report an issue to LLD developers.
-void elf::saveLinkerInputs(const llvm::opt::InputArgList &Args) {
+void elf::createResponseFile(const llvm::opt::InputArgList &Args) {
   // Create the output directory.
   if (std::error_code EC = sys::fs::create_directories(
         Config->Reproduce, /*IgnoreExisting=*/false)) {
@@ -165,7 +169,7 @@ void elf::saveLinkerInputs(const llvm::o
     case OPT_INPUT: {
       StringRef Path = Arg->getValue();
       if (fs::exists(Path))
-        OS << quote(copyFile(Path)) << "\n";
+        OS << quote(getDestPath(Path)) << "\n";
       else
         OS << quote(Path) << "\n";
       break;

Added: lld/trunk/test/ELF/reproduce-linkerscript.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/reproduce-linkerscript.s?rev=268171&view=auto
==============================================================================
--- lld/trunk/test/ELF/reproduce-linkerscript.s (added)
+++ lld/trunk/test/ELF/reproduce-linkerscript.s Sat Apr 30 17:23:29 2016
@@ -0,0 +1,16 @@
+# REQUIRES: x86, shell
+
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/build
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.dir/build/foo.o
+# RUN: echo "INPUT(\"%t.dir/build/foo.o\")" > %t.dir/build/foo.script
+# RUN: cd %t.dir
+# RUN: ld.lld build/foo.script -o bar --reproduce repro
+# RUN: diff build/foo.script repro/%:t.dir/build/foo.script
+# RUN: diff build/foo.o repro/%:t.dir/build/foo.o
+
+.globl _start
+_start:
+  mov $60, %rax
+  mov $42, %rdi
+  syscall




More information about the llvm-commits mailing list