[PATCH] [ELF] Add --allow-multiple-definition option.
Rui Ueyama
ruiu at google.com
Thu Mar 27 21:42:11 PDT 2014
Hi Bigcheese,
If --allow-multiple-definition option is given, LLD does not treat duplicate
symbol error as a fatal error. GNU LD supports this option.
http://llvm-reviews.chandlerc.com/D3211
Files:
include/lld/Core/LinkingContext.h
lib/Core/LinkingContext.cpp
lib/Core/SymbolTable.cpp
lib/Driver/GnuLdDriver.cpp
lib/Driver/GnuLdOptions.td
test/elf/allowduplicates.objtxt
Index: include/lld/Core/LinkingContext.h
===================================================================
--- include/lld/Core/LinkingContext.h
+++ include/lld/Core/LinkingContext.h
@@ -190,6 +190,7 @@
}
void setDeadStripping(bool enable) { _deadStrip = enable; }
+ void setAllowDuplicates(bool enable) { _allowDuplicates = enable; }
void setGlobalsAreDeadStripRoots(bool v) { _globalsAreDeadStripRoots = v; }
void setSearchArchivesToOverrideTentativeDefinitions(bool search) {
_searchArchivesToOverrideTentativeDefinitions = search;
@@ -212,6 +213,10 @@
void setAllowShlibUndefines(bool allow) { _allowShlibUndefines = allow; }
void setLogInputFiles(bool log) { _logInputFiles = log; }
+ // Returns true if multiple definitions should not be treated as a
+ // fatal error.
+ bool getAllowDuplicates() const { return _allowDuplicates; }
+
void appendLLVMOption(const char *opt) { _llvmOptions.push_back(opt); }
virtual void setInputGraph(std::unique_ptr<InputGraph> inputGraph) {
_inputGraph = std::move(inputGraph);
@@ -332,6 +337,7 @@
StringRef _outputPath;
StringRef _entrySymbolName;
bool _deadStrip;
+ bool _allowDuplicates;
bool _globalsAreDeadStripRoots;
bool _searchArchivesToOverrideTentativeDefinitions;
bool _searchSharedLibrariesToOverrideTentativeDefinitions;
Index: lib/Core/LinkingContext.cpp
===================================================================
--- lib/Core/LinkingContext.cpp
+++ lib/Core/LinkingContext.cpp
@@ -17,7 +17,8 @@
namespace lld {
LinkingContext::LinkingContext()
- : _deadStrip(false), _globalsAreDeadStripRoots(false),
+ : _deadStrip(false), _allowDuplicates(false),
+ _globalsAreDeadStripRoots(false),
_searchArchivesToOverrideTentativeDefinitions(false),
_searchSharedLibrariesToOverrideTentativeDefinitions(false),
_warnIfCoalesableAtomsHaveDifferentCanBeNull(false),
Index: lib/Core/SymbolTable.cpp
===================================================================
--- lib/Core/SymbolTable.cpp
+++ lib/Core/SymbolTable.cpp
@@ -217,7 +217,9 @@
<< ":"
<< newAtom.file().path()
<< "\n";
- llvm::report_fatal_error("duplicate symbol error");
+ if (!_context.getAllowDuplicates())
+ llvm::report_fatal_error("duplicate symbol error");
+ useNew = false;
break;
}
break;
Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -323,6 +323,10 @@
ctx->setUseShlibUndefines(true);
break;
+ case OPT_allow_multiple_definition:
+ ctx->setAllowDuplicates(true);
+ break;
+
case OPT_dynamic_linker:
ctx->setInterpreter(inputArg->getValue());
break;
Index: lib/Driver/GnuLdOptions.td
===================================================================
--- lib/Driver/GnuLdOptions.td
+++ lib/Driver/GnuLdOptions.td
@@ -187,6 +187,9 @@
def use_shlib_undefs: Flag<["--"], "use-shlib-undefines">,
HelpText<"Resolve undefined symbols from dynamic libraries">,
Group<grp_resolveropt>;
+def allow_multiple_definition: Flag<["--"], "allow-multiple-definition">,
+ HelpText<"Allow multiple definitions">,
+ Group<grp_resolveropt>;
//===----------------------------------------------------------------------===//
/// Custom Options
Index: test/elf/allowduplicates.objtxt
===================================================================
--- /dev/null
+++ test/elf/allowduplicates.objtxt
@@ -0,0 +1,48 @@
+# RUN: lld -flavor gnu -target x86_64 --allow-multiple-definition -r %s \
+# RUN: --output-filetype=yaml | FileCheck %s
+#
+# RUN: not lld -flavor gnu -target x86_64 -r %s --output-filetype=yaml 2>&1 \
+# RUN: | FileCheck -check-prefix=ERROR %s
+
+---
+defined-atoms:
+ - name: .text
+ alignment: 2^4
+ section-choice: custom-required
+ section-name: .text
+ - name: main
+ scope: global
+ content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00,
+ 00, C3 ]
+ alignment: 2^4
+ section-choice: custom-required
+ section-name: .text
+---
+defined-atoms:
+ - name: .text
+ alignment: 2^4
+ section-choice: custom-required
+ section-name: .text
+ - name: main
+ scope: global
+ content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00,
+ 00, C3 ]
+ alignment: 2^4
+ section-choice: custom-required
+ section-name: .text
+---
+
+# CHECK: defined-atoms:
+# CHECK: - name: .text
+# CHECK: alignment: 2^4
+# CHECK: section-choice: custom-required
+# CHECK: section-name: .text
+# CHECK: - name: main
+# CHECK: scope: global
+# CHECK: content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00,
+# CHECK: 00, C3 ]
+# CHECK: alignment: 2^4
+# CHECK: section-choice: custom-required
+# CHECK: section-name: .text
+
+# ERROR: duplicate symbol error
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3211.1.patch
Type: text/x-patch
Size: 5192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140327/e2540efc/attachment.bin>
More information about the llvm-commits
mailing list