[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

llvm-svn: 230157
This commit is contained in:
Davide Italiano 2015-02-22 03:12:21 +00:00
parent 429fa1220d
commit 9483dc21be
4 changed files with 23 additions and 2 deletions

View File

@ -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;

View File

@ -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, const char *argv[], raw_ostream &diag) {
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 char *argv[],
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)) {

View File

@ -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

View File

@ -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("") {}