[lld] r314789 - [ELF] Keep symbols specified by '-u' over LTO.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 05:17:59 PDT 2017


Author: ikudrin
Date: Tue Oct  3 05:17:59 2017
New Revision: 314789

URL: http://llvm.org/viewvc/llvm-project?rev=314789&view=rev
Log:
[ELF] Keep symbols specified by '-u' over LTO.

Differential Revision: https://reviews.llvm.org/D38348

Added:
    lld/trunk/test/ELF/lto/keep-undefined.ll
Modified:
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=314789&r1=314788&r2=314789&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Oct  3 05:17:59 2017
@@ -584,9 +584,14 @@ void SymbolTable::addLazyObject(StringRe
 // Process undefined (-u) flags by loading lazy symbols named by those flags.
 template <class ELFT> void SymbolTable::scanUndefinedFlags() {
   for (StringRef S : Config->Undefined)
-    if (auto *L = dyn_cast_or_null<Lazy>(find(S)))
-      if (InputFile *File = L->fetch())
-        addFile<ELFT>(File);
+    if (SymbolBody *B = find(S)) {
+      // Mark the symbol not to be eliminated by LTO
+      // even if it is a bitcode symbol.
+      B->symbol()->IsUsedInRegularObj = true;
+      if (auto *L = dyn_cast_or_null<Lazy>(B))
+        if (InputFile *File = L->fetch())
+          addFile<ELFT>(File);
+    }
 }
 
 // This function takes care of the case in which shared libraries depend on

Added: lld/trunk/test/ELF/lto/keep-undefined.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/keep-undefined.ll?rev=314789&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/keep-undefined.ll (added)
+++ lld/trunk/test/ELF/lto/keep-undefined.ll Tue Oct  3 05:17:59 2017
@@ -0,0 +1,20 @@
+; REQUIRES: x86
+; This test checks that symbols which are specified in "-u" switches
+; are kept over LTO if we link an executable.
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o -o %tout -u foo
+; RUN: llvm-nm %tout | FileCheck %s
+
+; CHECK: T foo
+
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo() {
+  ret void
+}
+
+define void @_start() {
+  call void @foo()
+  ret void
+}




More information about the llvm-commits mailing list