[PATCH] D38348: [ELF] Keep symbols specified by '-u' over LTO.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 02:44:36 PDT 2017


ikudrin created this revision.
ikudrin added a project: lld.
Herald added subscribers: inglorion, emaste.

See https://reviews.llvm.org/D37332 for the discussion.


Repository:
  rL LLVM

https://reviews.llvm.org/D38348

Files:
  ELF/SymbolTable.cpp
  test/ELF/lto/keep-undefined.ll


Index: test/ELF/lto/keep-undefined.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/keep-undefined.ll
@@ -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 | tee %t.log | 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
+}
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -585,9 +585,14 @@
 // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38348.116949.patch
Type: text/x-patch
Size: 1521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170928/be2483da/attachment.bin>


More information about the llvm-commits mailing list