[llvm] 530aa7e - [Linker] Import GlobalIFunc when importing symbols from another module

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 14 22:01:16 PDT 2021


Author: Itay Bookstein
Date: 2021-08-14T22:01:11-07:00
New Revision: 530aa7e4da14fb22493ab7e175f8c34dd10333d3

URL: https://github.com/llvm/llvm-project/commit/530aa7e4da14fb22493ab7e175f8c34dd10333d3
DIFF: https://github.com/llvm/llvm-project/commit/530aa7e4da14fb22493ab7e175f8c34dd10333d3.diff

LOG: [Linker] Import GlobalIFunc when importing symbols from another module

Reviewed By: MaskRay

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

Added: 
    llvm/test/Linker/ifunc.ll

Modified: 
    llvm/lib/Linker/LinkModules.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 97d6f8cd80755..971d3f0b21683 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -526,6 +526,10 @@ bool ModuleLinker::run() {
     if (linkIfNeeded(GA))
       return true;
 
+  for (GlobalIFunc &GI : SrcM->ifuncs())
+    if (linkIfNeeded(GI))
+      return true;
+
   for (unsigned I = 0; I < ValuesToLink.size(); ++I) {
     GlobalValue *GV = ValuesToLink[I];
     const Comdat *SC = GV->getComdat();

diff  --git a/llvm/test/Linker/ifunc.ll b/llvm/test/Linker/ifunc.ll
new file mode 100644
index 0000000000000..1e5396ed5fed6
--- /dev/null
+++ b/llvm/test/Linker/ifunc.ll
@@ -0,0 +1,25 @@
+; RUN: split-file %s %t
+; RUN: llvm-link %t/a.ll %t/b.ll -S -o - | FileCheck %s
+
+;; Check that ifuncs are linked in properly.
+
+; CHECK-DAG: @foo = ifunc void (), bitcast (void ()* ()* @foo_resolve to void ()*)
+; CHECK-DAG: define internal void ()* @foo_resolve() {
+
+; CHECK-DAG: @bar = ifunc void (), bitcast (void ()* ()* @bar_resolve to void ()*)
+; CHECK-DAG: define internal void ()* @bar_resolve() {
+
+;--- a.ll
+declare void @bar()
+
+;--- b.ll
+ at foo = ifunc void (), bitcast (void ()* ()* @foo_resolve to void ()*)
+ at bar = ifunc void (), bitcast (void ()* ()* @bar_resolve to void ()*)
+
+define internal void ()* @foo_resolve() {
+  ret void ()* null
+}
+
+define internal void ()* @bar_resolve() {
+  ret void ()* null
+}


        


More information about the llvm-commits mailing list