[PATCH] D18517: [ELF, PR27091] - Implemented -t/--trace option

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 11:13:57 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

-t
--trace
Print the names of the input files as ld processes them.
This fixes https://llvm.org/bugs/show_bug.cgi?id=27091.

At first when I saw that Config->Verbose already can be used to print input file list,
I thought that there is no need to add new option, but then realized that
1) Users does not wan't to see all what Verbose prints when they want to see input files only.
2) That is consistent with gold and can be already used by someone.

So that is good option to have I think.

http://reviews.llvm.org/D18517

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Options.td
  test/ELF/trace.s

Index: test/ELF/trace.s
===================================================================
--- test/ELF/trace.s
+++ test/ELF/trace.s
@@ -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
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -126,6 +126,9 @@
 
 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_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>;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -90,7 +90,8 @@
 // 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 @@
   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: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -79,6 +79,7 @@
   bool StripAll;
   bool SysvHash = true;
   bool Threads;
+  bool Trace;
   bool Verbose;
   bool WarnCommon;
   bool ZExecStack;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18517.51807.patch
Type: text/x-patch
Size: 2792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160328/2c85825a/attachment.bin>


More information about the llvm-commits mailing list