Index: lld/trunk/include/lld/Core/LinkingContext.h =================================================================== --- lld/trunk/include/lld/Core/LinkingContext.h +++ lld/trunk/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 = std::move(inputGraph); @@ -332,6 +337,7 @@ StringRef _outputPath; StringRef _entrySymbolName; bool _deadStrip; + bool _allowDuplicates; bool _globalsAreDeadStripRoots; bool _searchArchivesToOverrideTentativeDefinitions; bool _searchSharedLibrariesToOverrideTentativeDefinitions; Index: lld/trunk/lib/Core/LinkingContext.cpp =================================================================== --- lld/trunk/lib/Core/LinkingContext.cpp +++ lld/trunk/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: lld/trunk/lib/Core/SymbolTable.cpp =================================================================== --- lld/trunk/lib/Core/SymbolTable.cpp +++ lld/trunk/lib/Core/SymbolTable.cpp @@ -208,16 +208,19 @@ // 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; Index: lld/trunk/lib/Driver/GnuLdDriver.cpp =================================================================== --- lld/trunk/lib/Driver/GnuLdDriver.cpp +++ lld/trunk/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: lld/trunk/lib/Driver/GnuLdOptions.td =================================================================== --- lld/trunk/lib/Driver/GnuLdOptions.td +++ lld/trunk/lib/Driver/GnuLdOptions.td @@ -187,6 +187,9 @@ def use_shlib_undefs: Flag<["--"], "use-shlib-undefines">, HelpText<"Resolve undefined symbols from dynamic libraries">, Group; +def allow_multiple_definition: Flag<["--"], "allow-multiple-definition">, + HelpText<"Allow multiple definitions">, + Group; //===----------------------------------------------------------------------===// /// Custom Options Index: lld/trunk/test/elf/allowduplicates.objtxt =================================================================== --- lld/trunk/test/elf/allowduplicates.objtxt +++ lld/trunk/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