Implement --noinhibit-exec.
Patch by George Rimar!
llvm-svn: 248605
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 5108a65..b77a2f0 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -24,6 +24,7 @@
bool DiscardLocals = false;
bool DiscardNone = false;
bool ExportDynamic = false;
+ bool NoInhibitExec = false;
};
extern Configuration *Config;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index deafb6a..307bb08 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -94,6 +94,9 @@
if (Args.hasArg(OPT_export_dynamic))
Config->ExportDynamic = true;
+ if (Args.hasArg(OPT_noinhibit_exec))
+ Config->NoInhibitExec = true;
+
// Create a list of input files.
std::vector<MemoryBufferRef> Inputs;
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 237ca59..4ad9bfc 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "InputSection.h"
+#include "Config.h"
#include "Error.h"
#include "InputFiles.h"
#include "OutputSections.h"
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 897fc15..5baa587 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -28,6 +28,10 @@
def alias_discard_locals: Flag<["-"], "X">,
Alias<discard_locals>;
+def noinhibit_exec : Flag<["--"], "noinhibit-exec">,
+ HelpText<"Retain the executable output file whenever"
+ " it is still usable">;
+
def discard_none : Flag<["-"], "discard-none">,
HelpText<"Keep all symbols in the symbol table">;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 61d72b2..464125b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -281,11 +281,14 @@
if (&SymE > Syms.begin() && &SymE < Syms.end())
SymFile = F.get();
}
+
+ std::string Message = "undefined symbol: " + Sym.getName().str();
if (SymFile)
- error(Twine("undefined symbol: ") + Sym.getName() + " in " +
- SymFile->getName());
+ Message += " in " + SymFile->getName().str();
+ if (Config->NoInhibitExec)
+ warning(Message);
else
- error(Twine("undefined symbol: ") + Sym.getName());
+ error(Message);
}
// Create output section objects and add them to OutputSections.
diff --git a/lld/test/elf2/no-inhibit-exec.s b/lld/test/elf2/no-inhibit-exec.s
new file mode 100644
index 0000000..272a8d8
--- /dev/null
+++ b/lld/test/elf2/no-inhibit-exec.s
@@ -0,0 +1,15 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: not lld -flavor gnu2 %t -o %t2
+# RUN: lld -flavor gnu2 %t --noinhibit-exec -o %t2
+# RUN: llvm-objdump -d %t2 | FileCheck %s
+# REQUIRES: x86
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: _start
+# CHECK-NEXT: 11000: e8 fb ef fe ff callq -69637
+
+# next code will not link without noinhibit-exec flag
+# because of undefined symbol _bar
+.globl _start;
+_start:
+ call _bar