[lld] r308646 - Add the --chroot option for --reproduce.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 11:17:55 PDT 2017


Author: ruiu
Date: Thu Jul 20 11:17:55 2017
New Revision: 308646

URL: http://llvm.org/viewvc/llvm-project?rev=308646&view=rev
Log:
Add the --chroot option for --reproduce.

Summary:
If the linker is invoked with `--chroot /foo` and `/bar/baz.o`, it
tries to read the file from `/foo/bar/baz.o`. This feature is useful
when you are dealing with files created by the --reproduce option.

Reviewers: grimar

Subscribers: llvm-commits, emaste

Differential Revision: https://reviews.llvm.org/D35517

Added:
    lld/trunk/test/ELF/chroot.s
Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/Options.td
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/reproduce.s

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Jul 20 11:17:55 2017
@@ -82,6 +82,7 @@ struct Configuration {
   uint8_t OSABI = 0;
   llvm::CachePruningPolicy ThinLTOCachePolicy;
   llvm::StringMap<uint64_t> SectionStartMap;
+  llvm::StringRef Chroot;
   llvm::StringRef DynamicLinker;
   llvm::StringRef Entry;
   llvm::StringRef Emulation;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Jul 20 11:17:55 2017
@@ -619,6 +619,7 @@ void LinkerDriver::readConfigs(opt::Inpu
   Config->AuxiliaryList = getArgs(Args, OPT_auxiliary);
   Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
   Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);
+  Config->Chroot = Args.getLastArgValue(OPT_chroot);
   Config->CompressDebugSections = getCompressDebugSections(Args);
   Config->DefineCommon = getArg(Args, OPT_define_common, OPT_no_define_common,
                                 !Args.hasArg(OPT_relocatable));

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Thu Jul 20 11:17:55 2017
@@ -138,6 +138,7 @@ void elf::printHelp(const char *Argv0) {
 std::string elf::createResponseFile(const opt::InputArgList &Args) {
   SmallString<0> Data;
   raw_svector_ostream OS(Data);
+  OS << "--chroot .\n";
 
   // Copy the command line to the output while rewriting paths.
   for (auto *Arg : Args) {

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Jul 20 11:17:55 2017
@@ -40,7 +40,13 @@ TarWriter *elf::Tar;
 InputFile::InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
 
 Optional<MemoryBufferRef> elf::readFile(StringRef Path) {
+  // The --chroot option changes our virtual root directory.
+  // This is useful when you are dealing with files created by --reproduce.
+  if (!Config->Chroot.empty() && Path.startswith("/"))
+    Path = Saver.save(Config->Chroot + Path);
+
   log(Path);
+
   auto MBOrErr = MemoryBuffer::getFile(Path);
   if (auto EC = MBOrErr.getError()) {
     error("cannot open " + Path + ": " + EC.message());

Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Jul 20 11:17:55 2017
@@ -44,6 +44,9 @@ def allow_multiple_definition: F<"allow-
 def as_needed: F<"as-needed">,
   HelpText<"Only set DT_NEEDED for shared libraries if used">;
 
+// -chroot doesn't have a help text because it is an internal option.
+def chroot: S<"chroot">;
+
 def color_diagnostics: F<"color-diagnostics">,
   HelpText<"Use colors in diagnostics">;
 

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Jul 20 11:17:55 2017
@@ -256,7 +256,7 @@ void ScriptParser::addFile(StringRef S)
     }
   }
 
-  if (sys::path::is_absolute(S)) {
+  if (S.startswith("/")) {
     Driver->addFile(S, /*WithLOption=*/false);
   } else if (S.startswith("=")) {
     if (Config->Sysroot.empty())

Added: lld/trunk/test/ELF/chroot.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/chroot.s?rev=308646&view=auto
==============================================================================
--- lld/trunk/test/ELF/chroot.s (added)
+++ lld/trunk/test/ELF/chroot.s Thu Jul 20 11:17:55 2017
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: rm -rf %t.dir
+# RUN: mkdir %t.dir
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.dir/chroot.o
+# RUN: ld.lld --chroot %t.dir -o %t.exe /chroot.o
+
+# RUN: echo 'INPUT(/chroot.o)' > %t.dir/scr
+# RUN: ld.lld --chroot %t.dir -o %t.exe /scr
+
+.globl _start
+_start:
+  ret

Modified: lld/trunk/test/ELF/reproduce.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/reproduce.s?rev=308646&r1=308645&r2=308646&view=diff
==============================================================================
--- lld/trunk/test/ELF/reproduce.s (original)
+++ lld/trunk/test/ELF/reproduce.s Thu Jul 20 11:17:55 2017
@@ -39,6 +39,7 @@
 # RUN:   --dynamic-linker "some unusual/path" -soname 'foo bar' -soname='foo bar'
 # RUN: tar xf repro2.tar
 # RUN: FileCheck %s --check-prefix=RSP2 < repro2/response.txt
+# RSP2:      --chroot .
 # RSP2:      "{{.*}}foo bar"
 # RSP2-NEXT: -L "{{.*}}foo bar"
 # RSP2-NEXT: -L {{.+}}file




More information about the llvm-commits mailing list