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

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 05:19:43 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL314789: [ELF] Keep symbols specified by '-u' over LTO. (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D38348?vs=116949&id=117505#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38348

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


Index: lld/trunk/test/ELF/lto/keep-undefined.ll
===================================================================
--- lld/trunk/test/ELF/lto/keep-undefined.ll
+++ lld/trunk/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 | 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: lld/trunk/ELF/SymbolTable.cpp
===================================================================
--- lld/trunk/ELF/SymbolTable.cpp
+++ lld/trunk/ELF/SymbolTable.cpp
@@ -584,9 +584,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.117505.patch
Type: text/x-patch
Size: 1589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171003/77530d87/attachment.bin>


More information about the llvm-commits mailing list