[ELF, PR27091] - Implemented -t/--trace option
authorGeorge Rimar <grimar@accesssoftek.com>
Tue, 29 Mar 2016 08:45:40 +0000 (08:45 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Tue, 29 Mar 2016 08:45:40 +0000 (08:45 +0000)
-t/--trace
Print the names of the input files as ld processes them.
This fixes https://llvm.org/bugs/show_bug.cgi?id=27091.

Differential revision: http://reviews.llvm.org/D18517

llvm-svn: 264708

lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/test/ELF/trace.s [new file with mode: 0644]

index b75a599..591b625 100644 (file)
@@ -79,6 +79,7 @@ struct Configuration {
   bool StripAll;
   bool SysvHash = true;
   bool Threads;
+  bool Trace;
   bool Verbose;
   bool WarnCommon;
   bool ZExecStack;
index 68dce6f..9ec302e 100644 (file)
@@ -90,7 +90,8 @@ static std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB) {
 // Newly created memory buffers are owned by this driver.
 void LinkerDriver::addFile(StringRef Path) {
   using namespace llvm::sys::fs;
-  log(Path);
+  if (Config->Verbose || Config->Trace)
+    llvm::outs() << Path << "\n";
   auto MBOrErr = MemoryBuffer::getFile(Path);
   if (!MBOrErr) {
     error(MBOrErr, "cannot open " + Path);
@@ -250,6 +251,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
   Config->Shared = Args.hasArg(OPT_shared);
   Config->StripAll = Args.hasArg(OPT_strip_all);
   Config->Threads = Args.hasArg(OPT_threads);
+  Config->Trace = Args.hasArg(OPT_trace);
   Config->Verbose = Args.hasArg(OPT_verbose);
   Config->WarnCommon = Args.hasArg(OPT_warn_common);
 
index 11b7c1f..6b4ead2 100644 (file)
@@ -126,6 +126,9 @@ def sysroot : Joined<["--"], "sysroot=">,
 
 def threads : Joined<["--"], "threads">;
 
+def trace: Flag<["--"], "trace">,
+  HelpText<"Print the names of the input files">;
+
 def undefined : Joined<["--"], "undefined=">,
   HelpText<"Force undefined symbol during linking">;
 
@@ -169,6 +172,7 @@ def alias_shared_Bshareable : Flag<["-"], "Bshareable">, Alias<shared>;
 def alias_soname_h : JoinedOrSeparate<["-"], "h">, Alias<soname>;
 def alias_soname_soname : Separate<["-"], "soname">, Alias<soname>;
 def alias_script_T : JoinedOrSeparate<["-"], "T">, Alias<script>;
+def alias_trace : Flag<["-"], "t">, Alias<trace>;
 def alias_strip_all: Flag<["-"], "s">, Alias<strip_all>;
 def alias_undefined_u : JoinedOrSeparate<["-"], "u">, Alias<undefined>;
 def alias_wrap_wrap : Joined<["--", "-"], "wrap=">, Alias<wrap>;
diff --git a/lld/test/ELF/trace.s b/lld/test/ELF/trace.s
new file mode 100644 (file)
index 0000000..59db2ff
--- /dev/null
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.foo.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.bar.o
+
+## Check -t
+# RUN: ld.lld -shared %t.foo.o -o %t.so -t 2>&1 | FileCheck %s
+# CHECK: {{.*}}.foo.o
+
+## Check --trace alias
+# RUN: ld.lld -shared %t.foo.o -o %t.so -t 2>&1 | FileCheck %s
+
+## Check output messages order (1)
+# RUN: ld.lld -shared %t.foo.o %t1.bar.o -o %t.so -t 2>&1 | FileCheck -check-prefix=ORDER1 %s
+# ORDER1: {{.*}}.foo.o
+# ORDER1: {{.*}}.bar.o
+
+## Check output messages order (2)
+# RUN: ld.lld -shared %t1.bar.o %t.foo.o -o %t.so -t 2>&1 | FileCheck -check-prefix=ORDER2 %s
+# ORDER2: {{.*}}.bar.o
+# ORDER2: {{.*}}.foo.o