[lld] r230157 - [ELF] Teach GNU Driver about --stats.

Davide Italiano davide at freebsd.org
Sat Feb 21 19:12:21 PST 2015


Author: davide
Date: Sat Feb 21 21:12:21 2015
New Revision: 230157

URL: http://llvm.org/viewvc/llvm-project?rev=230157&view=rev
Log:
[ELF] Teach GNU Driver about --stats.

This is mainly for back-compatibility with GNU ld.
Ideally --stats should be a general option in LinkingContext, providing
individual stats for every pass in the linking process.
In the GNU driver, a better wording could be used, but there's no need
to change it for now.

Differential Revision:	D7657
Reviewed by:	ruiu

Modified:
    lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/lib/Driver/GnuLdOptions.td
    lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp

Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=230157&r1=230156&r2=230157&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Sat Feb 21 21:12:21 2015
@@ -291,6 +291,10 @@ public:
   bool stripSymbols() const { return _stripSymbols; }
   void setStripSymbols(bool strip) { _stripSymbols = strip; }
 
+  /// \brief Collect statistics.
+  bool collectStats() const { return _collectStats; }
+  void setCollectStats(bool s) { _collectStats = s; }
+
   // We can parse several linker scripts via command line whose ASTs are stored
   // in the current linking context via addLinkerScript().
   void addLinkerScript(std::unique_ptr<script::Parser> script) {
@@ -329,6 +333,7 @@ protected:
   bool _stripSymbols;
   bool _alignSegments;
   bool _nostdlib;
+  bool _collectStats;
   llvm::Optional<uint64_t> _maxPageSize;
 
   OutputMagic _outputMagic;

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=230157&r1=230156&r2=230157&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Sat Feb 21 21:12:21 2015
@@ -32,6 +32,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstring>
 #include <tuple>
@@ -171,7 +172,15 @@ bool GnuLdDriver::linkELF(int argc, cons
     return false;
   if (!options)
     return true;
-  return link(*options, diag);
+  bool linked = link(*options, diag);
+
+  // Handle --stats.
+  if (options->collectStats()) {
+    llvm::TimeRecord t = llvm::TimeRecord::getCurrentTime(true);
+    diag << "total time in link " << t.getProcessTime() << "\n";
+    diag << "data size " << t.getMemUsed() << "\n";
+  }
+  return linked;
 }
 
 static llvm::Optional<llvm::Triple::ArchType>
@@ -445,6 +454,11 @@ bool GnuLdDriver::parse(int argc, const
     ctx->setAllowRemainingUndefines(true);
   }
 
+  // Handle --stats.
+  if (parsedArgs->hasArg(OPT_stats)) {
+    ctx->setCollectStats(true);
+  }
+
   // Figure out if the output type is nmagic/omagic
   if (auto *arg = parsedArgs->getLastArg(
         OPT_nmagic, OPT_omagic, OPT_no_omagic)) {

Modified: lld/trunk/lib/Driver/GnuLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdOptions.td?rev=230157&r1=230156&r2=230157&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdOptions.td (original)
+++ lld/trunk/lib/Driver/GnuLdOptions.td Sat Feb 21 21:12:21 2015
@@ -277,6 +277,8 @@ def grp_tracingopts : OptionGroup<"opts"
 def t : Flag<["-"], "t">,
      HelpText<"Print the names of the input files as ld processes them">,
      Group<grp_tracingopts>;
+def stats : Flag<["--"], "stats">,
+     HelpText<"Print time and memory usage stats">, Group<grp_tracingopts>;
 
 //===----------------------------------------------------------------------===//
 /// Extensions

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=230157&r1=230156&r2=230157&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Sat Feb 21 21:12:21 2015
@@ -60,7 +60,7 @@ ELFLinkingContext::ELFLinkingContext(
       _mergeCommonStrings(false), _useShlibUndefines(true),
       _dynamicLinkerArg(false), _noAllowDynamicLibraries(false),
       _mergeRODataToTextSegment(true), _demangle(true),
-      _stripSymbols(false), _alignSegments(true),
+      _stripSymbols(false), _alignSegments(true), _collectStats(false),
       _outputMagic(OutputMagic::DEFAULT), _initFunction("_init"),
       _finiFunction("_fini"), _sysrootPath("") {}
 





More information about the llvm-commits mailing list