[lld] r205015 - [ELF] Add --allow-multiple-definition option.
Rui Ueyama
ruiu at google.com
Fri Mar 28 09:26:38 PDT 2014
Author: ruiu
Date: Fri Mar 28 11:26:38 2014
New Revision: 205015
URL: http://llvm.org/viewvc/llvm-project?rev=205015&view=rev
Log:
[ELF] Add --allow-multiple-definition option.
If --allow-multiple-definition option is given, LLD does not treat duplicate
symbol error as a fatal error. GNU LD supports this option.
Differential Revision: http://llvm-reviews.chandlerc.com/D3211
Added:
lld/trunk/test/elf/allowduplicates.objtxt
Modified:
lld/trunk/include/lld/Core/LinkingContext.h
lld/trunk/lib/Core/LinkingContext.cpp
lld/trunk/lib/Core/SymbolTable.cpp
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/lib/Driver/GnuLdOptions.td
Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=205015&r1=205014&r2=205015&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Fri Mar 28 11:26:38 2014
@@ -190,6 +190,7 @@ public:
}
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 @@ public:
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 @@ protected:
StringRef _outputPath;
StringRef _entrySymbolName;
bool _deadStrip;
+ bool _allowDuplicates;
bool _globalsAreDeadStripRoots;
bool _searchArchivesToOverrideTentativeDefinitions;
bool _searchSharedLibrariesToOverrideTentativeDefinitions;
Modified: lld/trunk/lib/Core/LinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/LinkingContext.cpp?rev=205015&r1=205014&r2=205015&view=diff
==============================================================================
--- lld/trunk/lib/Core/LinkingContext.cpp (original)
+++ lld/trunk/lib/Core/LinkingContext.cpp Fri Mar 28 11:26:38 2014
@@ -17,7 +17,8 @@
namespace lld {
LinkingContext::LinkingContext()
- : _deadStrip(false), _globalsAreDeadStripRoots(false),
+ : _deadStrip(false), _allowDuplicates(false),
+ _globalsAreDeadStripRoots(false),
_searchArchivesToOverrideTentativeDefinitions(false),
_searchSharedLibrariesToOverrideTentativeDefinitions(false),
_warnIfCoalesableAtomsHaveDifferentCanBeNull(false),
Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=205015&r1=205014&r2=205015&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Fri Mar 28 11:26:38 2014
@@ -208,16 +208,19 @@ void SymbolTable::addByName(const Atom &
// fallthrough
}
case MCR_Error:
- llvm::errs() << "Duplicate symbols: "
- << existing->name()
- << ":"
- << existing->file().path()
- << " and "
- << newAtom.name()
- << ":"
- << newAtom.file().path()
- << "\n";
- llvm::report_fatal_error("duplicate symbol error");
+ if (!_context.getAllowDuplicates()) {
+ llvm::errs() << "Duplicate symbols: "
+ << existing->name()
+ << ":"
+ << existing->file().path()
+ << " and "
+ << newAtom.name()
+ << ":"
+ << newAtom.file().path()
+ << "\n";
+ llvm::report_fatal_error("duplicate symbol error");
+ }
+ useNew = false;
break;
}
break;
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=205015&r1=205014&r2=205015&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Fri Mar 28 11:26:38 2014
@@ -323,6 +323,10 @@ bool GnuLdDriver::parse(int argc, const
ctx->setUseShlibUndefines(true);
break;
+ case OPT_allow_multiple_definition:
+ ctx->setAllowDuplicates(true);
+ break;
+
case OPT_dynamic_linker:
ctx->setInterpreter(inputArg->getValue());
break;
Modified: lld/trunk/lib/Driver/GnuLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdOptions.td?rev=205015&r1=205014&r2=205015&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdOptions.td (original)
+++ lld/trunk/lib/Driver/GnuLdOptions.td Fri Mar 28 11:26:38 2014
@@ -187,6 +187,9 @@ def allow_shlib_undefs : Flag<["--"], "a
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
Added: lld/trunk/test/elf/allowduplicates.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/allowduplicates.objtxt?rev=205015&view=auto
==============================================================================
--- lld/trunk/test/elf/allowduplicates.objtxt (added)
+++ lld/trunk/test/elf/allowduplicates.objtxt Fri Mar 28 11:26:38 2014
@@ -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
More information about the llvm-commits
mailing list