[PATCH] D35412: [ELF] - Fix incorrect object file use with --reproduce option.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 05:39:55 PDT 2017


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

This patch is mostly for discussion, it is not ideal, but I have no better solution in mind atm.

I observed this issue few times earlier, but last days I am facing it too often when running
other people reproduces.

Problem is next. I can following invocation under ubuntu:
~/LLVM/llvm-build/bin/clang-5.0 -fuse-ld=lld test.c -l stdc++ -o out -v -Wl,--reproduce,out.tar

Result out.tar contains usr\lib64\libc.so which is a linker script and has GROUP command:
`GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )`

Our --reproduce logic correctly includes these 3 files into result tar. Final reproduce file works fine
under the same ubuntu, but if I want to run this reproduce under windows or on system that does not have these
files at absolute path, e.g. there is no file /lib64/libc.so.6, then LLD will fail.

It happens because even running the reproduce, such files from GROUP options are taken 
from outside, what breaks concept of "black box".
It is sure undesirable and incorrect and makes sometimes hard to run wild repro files.

I though about we can rewrite such scripts before including them into Tar, but at the same time
it is probably not too nice to modify original files used for reproduce, so I refused from this idea.

In this patch I added new option --reproduce-use which informs linker that it runs under
debug reproduce environment and should never use absolute pathes, but convert them to relative. 
That fixes issue I am observing.

No testcase included beause would like to discuss possible solutions at first.


https://reviews.llvm.org/D35412

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/DriverUtils.cpp
  ELF/Options.td
  ELF/ScriptParser.cpp


Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -256,7 +256,12 @@
     }
   }
 
+  if (Config->UsingReproduce &&
+      sys::path::is_absolute(S, sys::path::Style::posix))
+    S = sys::path::relative_path(S, sys::path::Style::posix);
+
   if (sys::path::is_absolute(S)) {
+    assert(!Config->UsingReproduce);
     Driver->addFile(S, /*WithLOption=*/false);
   } else if (S.startswith("=")) {
     if (Config->Sysroot.empty())
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -207,6 +207,9 @@
 def reproduce: S<"reproduce">,
   HelpText<"Dump linker invocation and input files for debugging">;
 
+def reproduce_use: F<"reproduce-use">,
+  HelpText<"Informs linker about its running debug reproduce invocation">;
+
 def rpath: S<"rpath">, HelpText<"Add a DT_RUNPATH to the output">;
 
 def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
Index: ELF/DriverUtils.cpp
===================================================================
--- ELF/DriverUtils.cpp
+++ ELF/DriverUtils.cpp
@@ -139,6 +139,9 @@
   SmallString<0> Data;
   raw_svector_ostream OS(Data);
 
+  // Place marker argument informing it is debug invocation.
+  OS << "--reproduce-use\n";
+
   // Copy the command line to the output while rewriting paths.
   for (auto *Arg : Args) {
     switch (Arg->getOption().getID()) {
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -366,6 +366,8 @@
     }
   }
 
+  Config->UsingReproduce = Args.hasArg(OPT_reproduce_use);
+
   readConfigs(Args);
   initLLVM(Args);
   createFiles(Args);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -224,6 +224,9 @@
   // True if we are creating position-independent code.
   bool Pic;
 
+  // True if we are running invocation from reproduce file for debug.
+  bool UsingReproduce;
+
   // 4 for ELF32, 8 for ELF64.
   int Wordsize;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35412.106628.patch
Type: text/x-patch
Size: 2149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170714/dac1d874/attachment.bin>


More information about the llvm-commits mailing list