summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-03-28 16:26:38 +0000
committerRui Ueyama <ruiu@google.com>2014-03-28 16:26:38 +0000
commita9a5129ec13911abd3a38fb3d2c6118fe0041a6b (patch)
tree783fec7da9d73164ae7b8c71576ecbc45f582138
parentd7610a5d6721fe412d5af8018fe13fb8f3c3aed6 (diff)
downloadbcm5719-llvm-a9a5129ec13911abd3a38fb3d2c6118fe0041a6b.tar.gz
bcm5719-llvm-a9a5129ec13911abd3a38fb3d2c6118fe0041a6b.zip
[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 llvm-svn: 205015
-rw-r--r--lld/include/lld/Core/LinkingContext.h6
-rw-r--r--lld/lib/Core/LinkingContext.cpp3
-rw-r--r--lld/lib/Core/SymbolTable.cpp23
-rw-r--r--lld/lib/Driver/GnuLdDriver.cpp4
-rw-r--r--lld/lib/Driver/GnuLdOptions.td3
-rw-r--r--lld/test/elf/allowduplicates.objtxt48
6 files changed, 76 insertions, 11 deletions
diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h
index 3d7c45ec0fe..f2b00a69066 100644
--- a/lld/include/lld/Core/LinkingContext.h
+++ b/lld/include/lld/Core/LinkingContext.h
@@ -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;
diff --git a/lld/lib/Core/LinkingContext.cpp b/lld/lib/Core/LinkingContext.cpp
index 3be27cb98ec..361bff22555 100644
--- a/lld/lib/Core/LinkingContext.cpp
+++ b/lld/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),
diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp
index 7fdecaf9dae..11c9e06a41e 100644
--- a/lld/lib/Core/SymbolTable.cpp
+++ b/lld/lib/Core/SymbolTable.cpp
@@ -208,16 +208,19 @@ void SymbolTable::addByName(const Atom &newAtom) {
// 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;
diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp
index e6eacbf0f0a..1631c82304e 100644
--- a/lld/lib/Driver/GnuLdDriver.cpp
+++ b/lld/lib/Driver/GnuLdDriver.cpp
@@ -323,6 +323,10 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
ctx->setUseShlibUndefines(true);
break;
+ case OPT_allow_multiple_definition:
+ ctx->setAllowDuplicates(true);
+ break;
+
case OPT_dynamic_linker:
ctx->setInterpreter(inputArg->getValue());
break;
diff --git a/lld/lib/Driver/GnuLdOptions.td b/lld/lib/Driver/GnuLdOptions.td
index 57f38518f98..81f26b58433 100644
--- a/lld/lib/Driver/GnuLdOptions.td
+++ b/lld/lib/Driver/GnuLdOptions.td
@@ -187,6 +187,9 @@ def allow_shlib_undefs : Flag<["--"], "allow-shlib-undefined">,
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
diff --git a/lld/test/elf/allowduplicates.objtxt b/lld/test/elf/allowduplicates.objtxt
new file mode 100644
index 00000000000..bb0d485b6bb
--- /dev/null
+++ b/lld/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
OpenPOWER on IntegriCloud