[PATCH] D66992: [ELF] Set `referenced` bit of Undefined created by BitcodeFile

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 23:42:30 PDT 2019


MaskRay created this revision.
MaskRay added reviewers: grimar, peter.smith, ruiu, tejohnson.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

D64136 <https://reviews.llvm.org/D64136> and D65584 <https://reviews.llvm.org/D65584>, while fixing STB_WEAK issues and improving our
compatibility with ld.bfd, can cause another STB_WEAK problem related to
LTO:

If %tundef.o has an undefined reference on f,
and %tweakundef.o has a weak undefined reference on f,
%tdef.o has a definition of f

  ld.lld %tundef.o %tweakundef.o --start-lib %tdef.o --end-lib

can cause the lazy `%tdef.o` not fetched.

Fix this by setting `referenced` bit of Undefined created by bitcode
files.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D66992

Files:
  ELF/InputFiles.cpp
  test/ELF/lto/Inputs/undef.ll
  test/ELF/lto/undef-weak-lazy.ll


Index: test/ELF/lto/undef-weak-lazy.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/undef-weak-lazy.ll
@@ -0,0 +1,24 @@
+; REQUIRES: x86
+; RUN: llvm-as %S/Inputs/undef.ll -o %tundef.o
+; RUN: llvm-as %s -o %tweakundef.o
+; RUN: llvm-as %S/Inputs/archive.ll -o %tdef.o
+
+; RUN: ld.lld %tundef.o %tweakundef.o --start-lib %tdef.o --end-lib -shared -o %t.so
+; RUN: llvm-nm %t.so | FileCheck %s
+
+; RUN: ld.lld --start-lib %tdef.o --end-lib %tundef.o %tweakundef.o -shared -o %t.so
+; RUN: llvm-nm %t.so | FileCheck %s
+
+;; Test that the lazy bitcode %tdef.o is fetched.
+
+; CHECK: T f
+; CHECK: T foo
+
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+declare extern_weak void @f()
+define void @foo() {
+  call void @f()
+  ret void
+}
Index: test/ELF/lto/Inputs/undef.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/Inputs/undef.ll
@@ -0,0 +1,4 @@
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+declare void @f()
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -1478,7 +1478,9 @@
     Undefined newSym(&f, name, binding, visibility, type);
     if (canOmitFromDynSym)
       newSym.exportDynamic = false;
-    return symtab->addSymbol(newSym);
+    Symbol *ret = symtab->addSymbol(newSym);
+    ret->referenced = true;
+    return ret;
   }
 
   if (objSym.isCommon())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66992.218026.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190830/f392c364/attachment.bin>


More information about the llvm-commits mailing list