[lld] r285224 - Call _exit.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 26 11:59:01 PDT 2016
Author: rafael
Date: Wed Oct 26 13:59:00 2016
New Revision: 285224
URL: http://llvm.org/viewvc/llvm-project?rev=285224&view=rev
Log:
Call _exit.
As the state of lld gets more complicated, shutting down gets more
expensive.
In a normal lld run we can just call _exit immediately after renaming
the temporary output file. We still want the ability to run a full
shutdown since that is useful for detecting memory leaks.
This patch adds a --full-shutdown flag and changes lit to use it.
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Driver.h
lld/trunk/ELF/Options.td
lld/trunk/ELF/Writer.cpp
lld/trunk/include/lld/Driver/Driver.h
lld/trunk/test/ELF/amdgpu-globals.s
lld/trunk/test/lit.cfg
lld/trunk/tools/lld/lld.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Oct 26 13:59:00 2016
@@ -128,6 +128,7 @@ struct Configuration {
bool ZNow;
bool ZOrigin;
bool ZRelro;
+ bool ExitEarly;
bool ZWxneeded;
DiscardPolicy Discard;
SortSectionPolicy SortSection;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Oct 26 13:59:00 2016
@@ -39,7 +39,8 @@ using namespace lld::elf;
Configuration *elf::Config;
LinkerDriver *elf::Driver;
-bool elf::link(ArrayRef<const char *> Args, raw_ostream &Error) {
+bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly,
+ raw_ostream &Error) {
HasError = false;
ErrorOS = &Error;
Argv0 = Args[0];
@@ -51,7 +52,7 @@ bool elf::link(ArrayRef<const char *> Ar
Driver = &D;
ScriptConfig = &SC;
- Driver->main(Args);
+ Driver->main(Args, CanExitEarly);
InputFile::freePool();
return !HasError;
}
@@ -281,7 +282,7 @@ static uint64_t getZOptionValue(opt::Inp
return Default;
}
-void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
+void LinkerDriver::main(ArrayRef<const char *> ArgsArr, bool CanExitEarly) {
ELFOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
if (Args.hasArg(OPT_help)) {
@@ -290,6 +291,7 @@ void LinkerDriver::main(ArrayRef<const c
}
if (Args.hasArg(OPT_version))
outs() << getLLDVersion() << "\n";
+ Config->ExitEarly = CanExitEarly && !Args.hasArg(OPT_full_shutdown);
if (const char *Path = getReproduceOption(Args)) {
// Note that --reproduce is a debug option so you can ignore it
Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Wed Oct 26 13:59:00 2016
@@ -27,7 +27,7 @@ extern class LinkerDriver *Driver;
class LinkerDriver {
public:
- void main(ArrayRef<const char *> Args);
+ void main(ArrayRef<const char *> Args, bool CanExitEarly);
void addFile(StringRef Path);
void addLibrary(StringRef Name);
llvm::LLVMContext Context; // to parse bitcode files
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Wed Oct 26 13:59:00 2016
@@ -80,6 +80,9 @@ def fatal_warnings: F<"fatal-warnings">,
def fini: S<"fini">, MetaVarName<"<symbol>">,
HelpText<"Specify a finalizer function">;
+def full_shutdown : F<"full-shutdown">,
+ HelpText<"Perform a full shutdown instead of calling _exit">;
+
def format: J<"format=">, MetaVarName<"<input-format>">,
HelpText<"Change the input format of the inputs following this option">;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Oct 26 13:59:00 2016
@@ -23,6 +23,10 @@
#include "llvm/Support/raw_ostream.h"
#include <climits>
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
+#include <unistd.h>
+#endif
+
using namespace llvm;
using namespace llvm::ELF;
using namespace llvm::object;
@@ -316,6 +320,14 @@ template <class ELFT> void Writer<ELFT>:
return;
if (auto EC = Buffer->commit())
error(EC, "failed to write to the output file");
+ if (Config->ExitEarly) {
+ // Flush the output streams and exit immediately. A full shutdown is a good
+ // test that we are keeping track of all allocated memory, but actually
+ // freeing it is a wast of time in a regular linker run.
+ outs().flush();
+ errs().flush();
+ _exit(0);
+ }
}
template <class ELFT>
Modified: lld/trunk/include/lld/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/Driver.h?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/Driver.h (original)
+++ lld/trunk/include/lld/Driver/Driver.h Wed Oct 26 13:59:00 2016
@@ -19,7 +19,7 @@ bool link(llvm::ArrayRef<const char *> A
}
namespace elf {
-bool link(llvm::ArrayRef<const char *> Args,
+bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly,
llvm::raw_ostream &Diag = llvm::errs());
}
Modified: lld/trunk/test/ELF/amdgpu-globals.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/amdgpu-globals.s?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/test/ELF/amdgpu-globals.s (original)
+++ lld/trunk/test/ELF/amdgpu-globals.s Wed Oct 26 13:59:00 2016
@@ -1,5 +1,5 @@
# RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri %s -o %t.o
-# RUN: lld -flavor gnu %t.o -o %t
+# RUN: ld.lld %t.o -o %t
# RUN: llvm-readobj -sections -symbols -program-headers %t | FileCheck %s
# REQUIRES: amdgpu
Modified: lld/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.cfg?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/test/lit.cfg (original)
+++ lld/trunk/test/lit.cfg Wed Oct 26 13:59:00 2016
@@ -150,6 +150,8 @@ if config.test_exec_root is None:
NoPreJunk = r"(?<!(-|\.|/))"
NoPostJunk = r"(?!(-|\.))"
+config.substitutions.append( (r"\bld.lld\b", 'ld.lld --full-shutdown') )
+
tool_patterns = [r"\bFileCheck\b",
r"\bnot\b",
NoPreJunk + r"\blld\b" + NoPostJunk,
Modified: lld/trunk/tools/lld/lld.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld/lld.cpp?rev=285224&r1=285223&r2=285224&view=diff
==============================================================================
--- lld/trunk/tools/lld/lld.cpp (original)
+++ lld/trunk/tools/lld/lld.cpp Wed Oct 26 13:59:00 2016
@@ -101,7 +101,7 @@ int main(int Argc, const char **Argv) {
std::vector<const char *> Args(Argv, Argv + Argc);
switch (parseFlavor(Args)) {
case Gnu:
- return !elf::link(Args);
+ return !elf::link(Args, true);
case WinLink:
return !coff::link(Args);
case Darwin:
More information about the llvm-commits
mailing list