Implement --allow-multiple-definition.

Patch by George Rimar!

llvm-svn: 248733
This commit is contained in:
Rafael Espindola 2015-09-28 20:30:11 +00:00
parent 5c692009bc
commit 4b2ca85c1a
6 changed files with 47 additions and 2 deletions

View File

@ -29,6 +29,7 @@ struct Configuration {
bool DiscardNone = false;
bool ExportDynamic = false;
bool NoInhibitExec = false;
bool AllowMultipleDefinition = false;
};
extern Configuration *Config;

View File

@ -139,6 +139,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
if (Args.hasArg(OPT_noinhibit_exec))
Config->NoInhibitExec = true;
if (Args.hasArg(OPT_allow_multiple_definition))
Config->AllowMultipleDefinition = true;
// Create a list of input files.
std::vector<MemoryBufferRef> Inputs;

View File

@ -38,6 +38,9 @@ def discard_none : Flag<["-"], "discard-none">,
def export_dynamic : Flag<["--"], "export-dynamic">,
HelpText<"Put symbols in the dynamic symbol table">;
def allow_multiple_definition: Flag<["--"], "allow-multiple-definition">,
HelpText<"Allow multiple definitions">;
def L : Joined<["-"], "L">, MetaVarName<"<dir>">,
HelpText<"Directory to search for libraries">;

View File

@ -150,8 +150,13 @@ void SymbolTable::dupError(const SymbolBody &Old, const SymbolBody &New) {
NewFile = F.get();
}
error(Twine("duplicate symbol: ") + Old.getName() + " in " +
OldFile->getName() + " and " + NewFile->getName());
std::string Msg = (Twine("duplicate symbol: ") + Old.getName() + " in " +
OldFile->getName() + " and " + NewFile->getName())
.str();
if (Config->AllowMultipleDefinition)
warning(Msg);
else
error(Msg);
}
// This function resolves conflicts if there's an existing symbol with

View File

@ -0,0 +1,4 @@
.globl _bar
.type _bar, @function
_bar:
mov $2, %eax

View File

@ -0,0 +1,29 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/allow-multiple-definition.s -o %t2
# RUN: not lld -flavor gnu2 %t1 %t2 -o %t3
# RUN: lld -flavor gnu2 --allow-multiple-definition %t1 %t2 -o %t3
# RUN: lld -flavor gnu2 --allow-multiple-definition %t2 %t1 -o %t4
# RUN: llvm-objdump -d %t3 | FileCheck %s
# RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s
# inputs contain different constants for instuction movl.
# Tests below checks that order of files in command line
# affects on what symbol will be used.
# If flag allow-multiple-definition is enabled the first
# meet symbol should be used.
# CHECK: _bar:
# CHECK-NEXT: 11000: b8 01 00 00 00 movl $1, %eax
# REVERT: _bar:
# REVERT-NEXT: 11000: b8 02 00 00 00 movl $2, %eax
.globl _bar
.type _bar, @function
_bar:
mov $1, %eax
.globl _start
_start: