[PATCH] D13169: [ELF2] - Implemented --allow-multiple-definition flag
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 10:48:15 PDT 2015
grimar created this revision.
grimar added reviewers: ruiu, rui314, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar added a project: lld.
Implementation of --allow-multiple-definition flag
For tests I created 2 functions with the same name but different first instruction. Then checking that order of files in linker cmd line affects on which one is used.
Should anything else be checked ?
http://reviews.llvm.org/D13169
Files:
ELF/Config.h
ELF/Driver.cpp
ELF/Options.td
ELF/SymbolTable.cpp
test/elf2/Inputs/muldefs.s
test/elf2/allow-multiple-definition.s
Index: test/elf2/allow-multiple-definition.s
===================================================================
--- test/elf2/allow-multiple-definition.s
+++ test/elf2/allow-multiple-definition.s
@@ -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/muldefs.s -o %t2
+# RUN: not lld -flavor gnu2 %t %t1 %t2 -o %t3
+# RUN: lld -flavor gnu2 --allow-multiple-definition %t %t1 %t2 -o %t3
+# RUN: lld -flavor gnu2 --allow-multiple-definition %t %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: 11008: b8 01 00 00 00 movl $1, %eax
+
+# REVERT: _bar:
+# REVERT-NEXT: 11008: b8 02 00 00 00 movl $2, %eax
+
+.globl _bar
+.type _bar, @function
+_bar:
+ mov $1, %eax
+
+.globl _start;
+_start:
Index: test/elf2/Inputs/muldefs.s
===================================================================
--- test/elf2/Inputs/muldefs.s
+++ test/elf2/Inputs/muldefs.s
@@ -0,0 +1,4 @@
+.globl _bar
+.type _bar, @function
+_bar:
+ mov $2, %eax
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -137,8 +137,13 @@
NewFile = F.get();
}
- error(Twine("duplicate symbol: ") + Old.getName() + " in " +
- OldFile->getName() + " and " + NewFile->getName());
+ const std::string Message = "duplicate symbol: " + Old.getName().str() +
+ " in " + OldFile->getName().str() + " and " +
+ NewFile->getName().str();
+ if (Config->AllowMultipleDefinition)
+ warning(Message);
+ else
+ error(Message);
}
// This function resolves conflicts if there's an existing symbol with
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -33,3 +33,6 @@
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">;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -94,6 +94,9 @@
if (Args.hasArg(OPT_export_dynamic))
Config->ExportDynamic = true;
+ if (Args.hasArg(OPT_allow_multiple_definition))
+ Config->AllowMultipleDefinition = true;
+
// Create a list of input files.
std::vector<MemoryBufferRef> Inputs;
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -24,6 +24,7 @@
bool DiscardLocals = false;
bool DiscardNone = false;
bool ExportDynamic = false;
+ bool AllowMultipleDefinition = false;
};
extern Configuration *Config;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13169.35735.patch
Type: text/x-patch
Size: 3209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150925/a6ce694c/attachment.bin>
More information about the llvm-commits
mailing list