[lld] r249036 - [ELF2] Implement --allow-shlib-undefined as default behavior.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 10:24:24 PDT 2015
Author: grimar
Date: Thu Oct 1 12:24:24 2015
New Revision: 249036
URL: http://llvm.org/viewvc/llvm-project?rev=249036&view=rev
Log:
[ELF2] Implement --allow-shlib-undefined as default behavior.
We ignore --{no,}allow-shlib-undefined options and always allow undefined
symbols if we are building a DSO.
Added:
lld/trunk/test/elf2/Inputs/allow-shlib-undefined.s
lld/trunk/test/elf2/allow-shlib-undefined.s
Modified:
lld/trunk/ELF/Options.td
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=249036&r1=249035&r2=249036&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Oct 1 12:24:24 2015
@@ -48,6 +48,12 @@ def shared : Flag<["-"], "shared">,
def sysroot : Joined<["--"], "sysroot=">,
HelpText<"Set the system root">;
+def no_allow_shlib_undefined
+ : Flag<["--"], "no-allow-shlib-undefined">;
+
+def allow_shlib_undefined
+ : Flag<["--"], "allow-shlib-undefined">;
+
// Aliases
def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;
def alias_Bdynamic_dy: Flag<["-"], "dy">, Alias<Bdynamic>;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=249036&r1=249035&r2=249036&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Oct 1 12:24:24 2015
@@ -271,6 +271,9 @@ static void reportUndefined(const Symbol
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range;
+ if (Config->Shared)
+ return;
+
const Elf_Sym &SymE = cast<ELFSymbolBody<ELFT>>(Sym).Sym;
ELFFileBase *SymFile = nullptr;
Added: lld/trunk/test/elf2/Inputs/allow-shlib-undefined.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/Inputs/allow-shlib-undefined.s?rev=249036&view=auto
==============================================================================
--- lld/trunk/test/elf2/Inputs/allow-shlib-undefined.s (added)
+++ lld/trunk/test/elf2/Inputs/allow-shlib-undefined.s Thu Oct 1 12:24:24 2015
@@ -0,0 +1,3 @@
+.globl _shared
+_shared:
+ call _unresolved
Added: lld/trunk/test/elf2/allow-shlib-undefined.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/allow-shlib-undefined.s?rev=249036&view=auto
==============================================================================
--- lld/trunk/test/elf2/allow-shlib-undefined.s (added)
+++ lld/trunk/test/elf2/allow-shlib-undefined.s Thu Oct 1 12:24:24 2015
@@ -0,0 +1,25 @@
+# --allow-shlib-undefined and --no-allow-shlib-undefined are fully
+# ignored in linker implementation.
+# --allow-shlib-undefined is set by default
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
+# RUN: %p/Inputs/allow-shlib-undefined.s -o %t
+# RUN: lld -shared -flavor gnu2 %t -o %t.so
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
+
+# Executable: should link with DSO containing undefined symbols in any case.
+# RUN: lld -flavor gnu2 %t1 %t.so -o %t2
+# RUN: lld -flavor gnu2 --no-allow-shlib-undefined %t1 %t.so -o %t2
+# RUN: lld -flavor gnu2 --allow-shlib-undefined %t1 %t.so -o %t2
+
+# DSO with undefines:
+# should link with or without any of these options.
+# RUN: lld -shared -flavor gnu2 %t -o %t.so
+# RUN: lld -shared --allow-shlib-undefined -flavor gnu2 %t -o %t.so
+# RUN: lld -shared --no-allow-shlib-undefined -flavor gnu2 %t -o %t.so
+
+# Executable still should not link when have undefines inside.
+# RUN: not lld -flavor gnu2 %t -o %t.so
+
+.globl _start
+_start:
+ call _shared
More information about the llvm-commits
mailing list