[PATCH] D35517: Add the --chroot option for --reproduce.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 16:34:00 PDT 2017


ruiu created this revision.
Herald added a subscriber: emaste.

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.


https://reviews.llvm.org/D35517

Files:
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/DriverUtils.cpp
  lld/ELF/InputFiles.cpp
  lld/ELF/Options.td
  lld/test/ELF/chroot.s
  lld/test/ELF/reproduce.s


Index: lld/test/ELF/reproduce.s
===================================================================
--- lld/test/ELF/reproduce.s
+++ lld/test/ELF/reproduce.s
@@ -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
Index: lld/test/ELF/chroot.s
===================================================================
--- /dev/null
+++ lld/test/ELF/chroot.s
@@ -0,0 +1,9 @@
+# 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
+
+.globl _start
+_start:
+  ret
Index: lld/ELF/Options.td
===================================================================
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -44,6 +44,9 @@
 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">;
 
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -54,7 +54,16 @@
 }
 
 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() && sys::path::is_absolute(Path)) {
+    SmallString<64> Tmp;
+    sys::path::append(Tmp, Config->Chroot, Path);
+    Path = Saver.save(Tmp.str());
+  }
+
   log(Path);
+
   auto MBOrErr = MemoryBuffer::getFile(Path);
   if (auto EC = MBOrErr.getError()) {
     error("cannot open " + Path + ": " + EC.message());
Index: lld/ELF/DriverUtils.cpp
===================================================================
--- lld/ELF/DriverUtils.cpp
+++ lld/ELF/DriverUtils.cpp
@@ -138,6 +138,7 @@
 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) {
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -619,6 +619,7 @@
   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));
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -82,6 +82,7 @@
   uint8_t OSABI = 0;
   llvm::CachePruningPolicy ThinLTOCachePolicy;
   llvm::StringMap<uint64_t> SectionStartMap;
+  llvm::StringRef Chroot;
   llvm::StringRef DynamicLinker;
   llvm::StringRef Entry;
   llvm::StringRef Emulation;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35517.106976.patch
Type: text/x-patch
Size: 3418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170717/45d0935d/attachment.bin>


More information about the llvm-commits mailing list